@@ -168,7 +168,7 @@ class QrCode {
168
168
* The smallest possible QR Code version is automatically chosen for the output.
169
169
* The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version.
170
170
*/
171
- static from ( content : string | URL | Uint8Array , { output = "array" , border = 4 , light = "white" , dark = "black" , ecl = "MEDIUM" } : { output ?: string } & options = { } ) {
171
+ static from ( content : string | URL | Uint8Array , { output = "array" , border = 2 , light = "white" , dark = "black" , ecl = "MEDIUM" } : { output ?: string } & options = { } ) {
172
172
border = Math . max ( 0 , border )
173
173
const qr = QrCode . #encode( Segment . from ( content instanceof URL ? content . href : content ) , { ecl } )
174
174
const size = qr . size + border * 2
@@ -178,29 +178,29 @@ class QrCode {
178
178
for ( let y = 0 ; y < qr . size ; y ++ ) {
179
179
for ( let x = 0 ; x < qr . size ; x ++ ) {
180
180
if ( qr . get ( { x, y } ) ) {
181
- paths . push ( `M${ x + border } ,${ y + border } h1v1h-1z` )
181
+ paths . push ( `M${ x + border * 2 } ,${ y + border * 2 } h1v1h-1z` )
182
182
}
183
183
}
184
184
}
185
185
return `<?xml version="1.0" encoding="UTF-8"?><svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 ${ size } ${ size } " stroke="none"><rect width="100%" height="100%" fill="${ light } "/><path d="${ paths . join ( " " ) } " fill="${ dark } "/></svg>`
186
186
}
187
187
case "console" : {
188
- for ( let y = 0 ; y < qr . size ; y ++ ) {
189
- const line = "%c\u2588\u2588" . repeat ( qr . size )
188
+ for ( let y = 0 ; y < size ; y ++ ) {
189
+ const line = "%c\u2588\u2588" . repeat ( size )
190
190
const colors = [ ] as string [ ]
191
- for ( let x = 0 ; x < qr . size ; x ++ ) {
192
- colors . push ( `color: ${ qr . get ( { x, y } ) ? dark : light } ` )
191
+ for ( let x = 0 ; x < size ; x ++ ) {
192
+ colors . push ( `color: ${ qr . get ( { x : x - border , y : y - border } ) ? dark : light } ` )
193
193
}
194
194
console . log ( line , ...colors )
195
195
}
196
196
return
197
197
}
198
198
default : {
199
199
const data = [ ] as boolean [ ] [ ]
200
- for ( let y = 0 ; y < qr . size ; y ++ ) {
201
- data [ y ] = new Array ( qr . size ) . fill ( false )
202
- for ( let x = 0 ; x < qr . size ; x ++ ) {
203
- data [ y ] [ x ] = qr . get ( { x, y } )
200
+ for ( let y = 0 ; y < size ; y ++ ) {
201
+ data [ y ] = new Array ( size ) . fill ( false )
202
+ for ( let x = 0 ; x < size ; x ++ ) {
203
+ data [ y ] [ x ] = qr . get ( { x : x - border , y : y - border } )
204
204
}
205
205
}
206
206
return data
0 commit comments