@sythos/js_barcode_universal 1.5.8 → 1.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +5 -4
- package/NOTICE.md +2 -2
- package/README.md +61 -13
- package/bundle/sythos-barcode.esm.js +11658 -11244
- package/bundle/sythos-barcode.js +11658 -11244
- package/package.json +10 -3
- package/src/index.d.ts +1 -1
- package/src/index.js +508 -516
- package/src/js/aztec/decoder.js +208 -199
- package/src/js/aztec/detector.js +153 -126
- package/src/js/aztec/encoder.js +172 -153
- package/src/js/aztec/high-level.js +106 -101
- package/src/js/aztec/index.js +1 -12
- package/src/js/aztec/tables.js +106 -120
- package/src/js/aztecrune/decoder.js +76 -85
- package/src/js/aztecrune/detector.js +107 -93
- package/src/js/aztecrune/encoder.js +50 -68
- package/src/js/aztecrune/index.js +1 -16
- package/src/js/aztecrune/tables.js +59 -54
- package/src/js/compactpdf417/decoder.js +69 -74
- package/src/js/compactpdf417/detector.js +74 -75
- package/src/js/compactpdf417/encoder.js +68 -81
- package/src/js/compactpdf417/index.js +1 -13
- package/src/js/compactpdf417/tables.js +71 -80
- package/src/js/core/bit-buffer.js +106 -122
- package/src/js/core/bit-matrix.js +196 -194
- package/src/js/core/errors.js +13 -15
- package/src/js/core/galois-field.js +119 -133
- package/src/js/core/index.js +2 -19
- package/src/js/core/reed-solomon.js +195 -204
- package/src/js/databar/codec.js +93 -108
- package/src/js/databar/decoder.js +149 -140
- package/src/js/databar/encoder.js +47 -55
- package/src/js/databar/gs1.js +122 -123
- package/src/js/databar/index.js +4 -36
- package/src/js/databar/patterns.js +81 -85
- package/src/js/databar/tables.js +51 -52
- package/src/js/datamatrix/decoder.js +216 -182
- package/src/js/datamatrix/detector.js +161 -132
- package/src/js/datamatrix/encoder.js +192 -133
- package/src/js/datamatrix/index.js +1 -9
- package/src/js/datamatrix/tables.js +68 -69
- package/src/js/frameqr/decoder.js +102 -125
- package/src/js/frameqr/detector.js +101 -94
- package/src/js/frameqr/encoder.js +67 -80
- package/src/js/frameqr/index.js +1 -10
- package/src/js/frameqr/tables.js +145 -163
- package/src/js/image/binarizer.js +146 -162
- package/src/js/image/grid-sampler.js +63 -79
- package/src/js/image/index.js +0 -2
- package/src/js/image/luminance.js +129 -140
- package/src/js/image/perspective.js +112 -149
- package/src/js/micropdf417/compaction.js +64 -65
- package/src/js/micropdf417/decoder.js +106 -109
- package/src/js/micropdf417/detector.js +73 -70
- package/src/js/micropdf417/encoder.js +129 -154
- package/src/js/micropdf417/error-correction.js +6 -11
- package/src/js/micropdf417/index.js +2 -16
- package/src/js/micropdf417/tables.js +112 -99
- package/src/js/microqr/decoder.js +177 -182
- package/src/js/microqr/detector.js +240 -256
- package/src/js/microqr/encoder.js +239 -194
- package/src/js/microqr/index.js +0 -2
- package/src/js/microqr/tables.js +208 -200
- package/src/js/oned/addons.js +167 -191
- package/src/js/oned/index.js +27 -58
- package/src/js/oned/patterns.js +194 -213
- package/src/js/oned/reader.js +1003 -984
- package/src/js/oned/writers.js +411 -466
- package/src/js/pdf417/compaction.js +315 -222
- package/src/js/pdf417/decoder.js +71 -36
- package/src/js/pdf417/detector.js +377 -361
- package/src/js/pdf417/encoder.js +57 -46
- package/src/js/pdf417/error-correction.js +5 -8
- package/src/js/pdf417/tables.js +248 -250
- package/src/js/qr/decoder.js +311 -347
- package/src/js/qr/detector.js +378 -395
- package/src/js/qr/encoder.js +514 -599
- package/src/js/qr/index.js +0 -2
- package/src/js/qr/tables.js +375 -422
- package/src/js/render/image-data.js +57 -62
- package/src/js/render/index.js +21 -23
- package/src/js/render/options.js +82 -90
- package/src/js/render/png.js +144 -169
- package/src/js/render/svg.js +41 -44
- package/src/js/render/webgl.js +103 -109
- package/src/js/render/webgpu.js +205 -217
- package/src/js/rmqr/decoder.js +161 -53
- package/src/js/rmqr/detector.js +73 -41
- package/src/js/rmqr/encoder.js +253 -104
- package/src/js/rmqr/index.js +1 -5
- package/src/js/rmqr/tables.js +108 -85
- package/src/ts/aztec/decoder.ts +317 -0
- package/src/ts/aztec/detector.ts +224 -0
- package/src/ts/aztec/encoder.ts +257 -0
- package/src/ts/aztec/high-level.ts +211 -0
- package/src/ts/aztec/index.ts +45 -0
- package/src/ts/aztec/tables.ts +210 -0
- package/src/ts/aztecrune/decoder.ts +155 -0
- package/src/ts/aztecrune/detector.ts +166 -0
- package/src/ts/aztecrune/encoder.ts +121 -0
- package/src/ts/aztecrune/index.ts +49 -0
- package/src/ts/aztecrune/tables.ts +137 -0
- package/src/ts/compactpdf417/decoder.ts +128 -0
- package/src/ts/compactpdf417/detector.ts +139 -0
- package/src/ts/compactpdf417/encoder.ts +140 -0
- package/src/ts/compactpdf417/index.ts +17 -0
- package/src/ts/compactpdf417/tables.ts +173 -0
- package/src/ts/core/bit-buffer.ts +174 -0
- package/src/ts/core/bit-matrix.ts +241 -0
- package/src/ts/core/errors.ts +61 -0
- package/src/ts/core/galois-field.ts +207 -0
- package/src/ts/core/index.ts +56 -0
- package/src/ts/core/reed-solomon.ts +327 -0
- package/src/ts/databar/codec.ts +181 -0
- package/src/ts/databar/decoder.ts +215 -0
- package/src/ts/databar/encoder.ts +96 -0
- package/src/ts/databar/gs1.ts +177 -0
- package/src/ts/databar/index.ts +68 -0
- package/src/ts/databar/patterns.ts +143 -0
- package/src/ts/databar/tables.ts +124 -0
- package/src/ts/datamatrix/decoder.ts +262 -0
- package/src/ts/datamatrix/detector.ts +225 -0
- package/src/ts/datamatrix/encoder.ts +191 -0
- package/src/ts/datamatrix/index.ts +42 -0
- package/src/ts/datamatrix/tables.ts +123 -0
- package/src/ts/frameqr/decoder.ts +239 -0
- package/src/ts/frameqr/detector.ts +192 -0
- package/src/ts/frameqr/encoder.ts +156 -0
- package/src/ts/frameqr/index.ts +42 -0
- package/src/ts/frameqr/tables.ts +270 -0
- package/src/ts/image/binarizer.ts +270 -0
- package/src/ts/image/grid-sampler.ts +164 -0
- package/src/ts/image/index.ts +40 -0
- package/src/ts/image/luminance.ts +196 -0
- package/src/ts/image/perspective.ts +195 -0
- package/src/ts/index.d.ts +1 -1
- package/src/ts/index.ts +790 -0
- package/src/ts/micropdf417/compaction.ts +116 -0
- package/src/ts/micropdf417/decoder.ts +183 -0
- package/src/ts/micropdf417/detector.ts +149 -0
- package/src/ts/micropdf417/encoder.ts +209 -0
- package/src/ts/micropdf417/error-correction.ts +55 -0
- package/src/ts/micropdf417/index.ts +49 -0
- package/src/ts/micropdf417/tables.ts +184 -0
- package/src/ts/microqr/decoder.ts +245 -0
- package/src/ts/microqr/detector.ts +355 -0
- package/src/ts/microqr/encoder.ts +269 -0
- package/src/ts/microqr/index.ts +36 -0
- package/src/ts/microqr/tables.ts +316 -0
- package/src/ts/oned/addons.ts +420 -0
- package/src/ts/oned/index.ts +106 -0
- package/src/ts/oned/patterns.ts +384 -0
- package/src/ts/oned/reader.ts +1364 -0
- package/src/ts/oned/writers.ts +746 -0
- package/src/ts/pdf417/compaction.ts +298 -0
- package/src/ts/pdf417/decoder.ts +75 -0
- package/src/ts/pdf417/detector.ts +468 -0
- package/src/ts/pdf417/encoder.ts +91 -0
- package/src/ts/pdf417/error-correction.ts +47 -0
- package/src/ts/pdf417/index.ts +6 -0
- package/src/ts/pdf417/tables.ts +317 -0
- package/src/ts/qr/decoder.ts +575 -0
- package/src/ts/qr/detector.ts +630 -0
- package/src/ts/qr/encoder.ts +958 -0
- package/src/ts/qr/index.ts +44 -0
- package/src/ts/qr/tables.ts +737 -0
- package/src/ts/render/image-data.ts +125 -0
- package/src/ts/render/index.ts +130 -0
- package/src/ts/render/options.ts +160 -0
- package/src/ts/render/png.ts +295 -0
- package/src/ts/render/svg.ts +120 -0
- package/src/ts/render/webgl.ts +206 -0
- package/src/ts/render/webgpu.ts +369 -0
- package/src/ts/rmqr/decoder.ts +101 -0
- package/src/ts/rmqr/detector.ts +90 -0
- package/src/ts/rmqr/encoder.ts +172 -0
- package/src/ts/rmqr/index.ts +37 -0
- package/src/ts/rmqr/tables.ts +154 -0
|
@@ -27,15 +27,12 @@
|
|
|
27
27
|
*
|
|
28
28
|
* Original work. No code from any other barcode implementation.
|
|
29
29
|
*/
|
|
30
|
-
|
|
31
30
|
/**
|
|
32
31
|
* Raster output as ImageData, and 2D-canvas drawing.
|
|
33
32
|
*
|
|
34
33
|
* @module render/image-data
|
|
35
34
|
*/
|
|
36
|
-
|
|
37
35
|
import { normalizeOptions, parseColor } from './options.js';
|
|
38
|
-
|
|
39
36
|
/**
|
|
40
37
|
* Render to an `ImageData`-shaped object.
|
|
41
38
|
*
|
|
@@ -48,37 +45,32 @@ import { normalizeOptions, parseColor } from './options.js';
|
|
|
48
45
|
* @returns {{data: Uint8ClampedArray, width: number, height: number}}
|
|
49
46
|
*/
|
|
50
47
|
export function toImageData(matrix, options = {}) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
48
|
+
const opts = normalizeOptions(matrix, options);
|
|
49
|
+
const { scale, source, pixelWidth, pixelHeight } = opts;
|
|
50
|
+
const dark = parseColor(opts.dark);
|
|
51
|
+
const light = parseColor(opts.light);
|
|
52
|
+
const data = new Uint8ClampedArray(pixelWidth * pixelHeight * 4);
|
|
53
|
+
// Fill one scanline per module row, then copy it `scale` times. Barcodes are
|
|
54
|
+
// wide and repetitive, so this is markedly faster than a per-pixel loop.
|
|
55
|
+
const line = new Uint8ClampedArray(pixelWidth * 4);
|
|
56
|
+
for (let my = 0; my < source.height; my++) {
|
|
57
|
+
for (let mx = 0; mx < source.width; mx++) {
|
|
58
|
+
const colour = source.get(mx, my) ? dark : light;
|
|
59
|
+
const start = mx * scale * 4;
|
|
60
|
+
for (let px = 0; px < scale; px++) {
|
|
61
|
+
const p = start + px * 4;
|
|
62
|
+
line[p] = colour[0];
|
|
63
|
+
line[p + 1] = colour[1];
|
|
64
|
+
line[p + 2] = colour[2];
|
|
65
|
+
line[p + 3] = colour[3];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
for (let py = 0; py < scale; py++) {
|
|
69
|
+
data.set(line, ((my * scale + py) * pixelWidth) * 4);
|
|
70
|
+
}
|
|
73
71
|
}
|
|
74
|
-
|
|
75
|
-
data.set(line, ((my * scale + py) * pixelWidth) * 4);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return { data, width: pixelWidth, height: pixelHeight };
|
|
72
|
+
return { data, width: pixelWidth, height: pixelHeight };
|
|
80
73
|
}
|
|
81
|
-
|
|
82
74
|
/**
|
|
83
75
|
* Draw into a canvas using its 2D context.
|
|
84
76
|
*
|
|
@@ -91,35 +83,38 @@ export function toImageData(matrix, options = {}) {
|
|
|
91
83
|
* @returns {boolean} True when it drew.
|
|
92
84
|
*/
|
|
93
85
|
export function toCanvas(matrix, canvas, options = {}) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
86
|
+
const opts = normalizeOptions(matrix, options);
|
|
87
|
+
const ctx = canvas.getContext('2d');
|
|
88
|
+
if (!ctx)
|
|
89
|
+
return false;
|
|
90
|
+
canvas.width = opts.pixelWidth;
|
|
91
|
+
canvas.height = opts.pixelHeight;
|
|
92
|
+
// Draw with fillRect rather than putImageData: it respects the canvas's
|
|
93
|
+
// alpha compositing, so a transparent `light` leaves the page showing
|
|
94
|
+
// through instead of punching a hole.
|
|
95
|
+
const [, , , lightAlpha] = parseColor(opts.light);
|
|
96
|
+
if (lightAlpha > 0) {
|
|
97
|
+
ctx.fillStyle = opts.light;
|
|
98
|
+
ctx.fillRect(0, 0, opts.pixelWidth, opts.pixelHeight);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
ctx.clearRect(0, 0, opts.pixelWidth, opts.pixelHeight);
|
|
102
|
+
}
|
|
103
|
+
ctx.fillStyle = opts.dark;
|
|
104
|
+
const { source, scale } = opts;
|
|
105
|
+
for (let y = 0; y < source.height; y++) {
|
|
106
|
+
let x = 0;
|
|
107
|
+
while (x < source.width) {
|
|
108
|
+
if (!source.get(x, y)) {
|
|
109
|
+
x++;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
let run = 1;
|
|
113
|
+
while (x + run < source.width && source.get(x + run, y))
|
|
114
|
+
run++;
|
|
115
|
+
ctx.fillRect(x * scale, y * scale, run * scale, scale);
|
|
116
|
+
x += run;
|
|
117
|
+
}
|
|
122
118
|
}
|
|
123
|
-
|
|
124
|
-
return true;
|
|
119
|
+
return true;
|
|
125
120
|
}
|
package/src/js/render/index.js
CHANGED
|
@@ -27,7 +27,6 @@
|
|
|
27
27
|
*
|
|
28
28
|
* Original work. No code from any other barcode implementation.
|
|
29
29
|
*/
|
|
30
|
-
|
|
31
30
|
/**
|
|
32
31
|
* Output backends.
|
|
33
32
|
*
|
|
@@ -57,18 +56,15 @@
|
|
|
57
56
|
*
|
|
58
57
|
* @module render
|
|
59
58
|
*/
|
|
60
|
-
|
|
61
59
|
export { toSVG, toSVGDataURI } from './svg.js';
|
|
62
60
|
export { toImageData, toCanvas } from './image-data.js';
|
|
63
61
|
export { toPNG, toPNGDataURI, deflateStored } from './png.js';
|
|
64
62
|
export { isWebGL2Available, renderToCanvasWebGL } from './webgl.js';
|
|
65
63
|
export { isWebGPUAvailable, renderToCanvasWebGPU } from './webgpu.js';
|
|
66
64
|
export { normalizeOptions, parseColor } from './options.js';
|
|
67
|
-
|
|
68
65
|
import { toCanvas } from './image-data.js';
|
|
69
66
|
import { isWebGL2Available, renderToCanvasWebGL } from './webgl.js';
|
|
70
67
|
import { isWebGPUAvailable, renderToCanvasWebGPU } from './webgpu.js';
|
|
71
|
-
|
|
72
68
|
/**
|
|
73
69
|
* Draw into a canvas using the best backend available.
|
|
74
70
|
*
|
|
@@ -88,15 +84,15 @@ import { isWebGPUAvailable, renderToCanvasWebGPU } from './webgpu.js';
|
|
|
88
84
|
* @returns {{backend: 'webgl2' | '2d' | 'none'}}
|
|
89
85
|
*/
|
|
90
86
|
export function renderToCanvasAuto(matrix, canvas, options = {}) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
87
|
+
const preferred = options.backend ?? 'auto';
|
|
88
|
+
if ((preferred === 'auto' || preferred === 'webgl2') && isWebGL2Available()) {
|
|
89
|
+
if (renderToCanvasWebGL(matrix, canvas, options))
|
|
90
|
+
return { backend: 'webgl2' };
|
|
91
|
+
}
|
|
92
|
+
if (toCanvas(matrix, canvas, options))
|
|
93
|
+
return { backend: '2d' };
|
|
94
|
+
return { backend: 'none' };
|
|
98
95
|
}
|
|
99
|
-
|
|
100
96
|
/**
|
|
101
97
|
* Draw into a canvas using the best backend available, including WebGPU.
|
|
102
98
|
*
|
|
@@ -115,16 +111,18 @@ export function renderToCanvasAuto(matrix, canvas, options = {}) {
|
|
|
115
111
|
* @returns {Promise<{backend: 'webgpu' | 'webgl2' | '2d' | 'none'}>}
|
|
116
112
|
*/
|
|
117
113
|
export async function renderToCanvasAutoAsync(matrix, canvas, options = {}) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
114
|
+
const preferred = options.backend ?? 'auto';
|
|
115
|
+
if (preferred === 'auto' || preferred === 'webgpu') {
|
|
116
|
+
if (await isWebGPUAvailable()) {
|
|
117
|
+
if (await renderToCanvasWebGPU(matrix, canvas, options))
|
|
118
|
+
return { backend: 'webgpu' };
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if ((preferred === 'auto' || preferred === 'webgl2') && isWebGL2Available()) {
|
|
122
|
+
if (renderToCanvasWebGL(matrix, canvas, options))
|
|
123
|
+
return { backend: 'webgl2' };
|
|
123
124
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
if (toCanvas(matrix, canvas, options)) return { backend: '2d' };
|
|
129
|
-
return { backend: 'none' };
|
|
125
|
+
if (toCanvas(matrix, canvas, options))
|
|
126
|
+
return { backend: '2d' };
|
|
127
|
+
return { backend: 'none' };
|
|
130
128
|
}
|
package/src/js/render/options.js
CHANGED
|
@@ -27,15 +27,12 @@
|
|
|
27
27
|
*
|
|
28
28
|
* Original work. No code from any other barcode implementation.
|
|
29
29
|
*/
|
|
30
|
-
|
|
31
30
|
/**
|
|
32
31
|
* Shared render options, normalised once so every backend agrees.
|
|
33
32
|
*
|
|
34
33
|
* @module render/options
|
|
35
34
|
*/
|
|
36
|
-
|
|
37
35
|
import { BitMatrix } from '../core/bit-matrix.js';
|
|
38
|
-
|
|
39
36
|
/**
|
|
40
37
|
* @typedef {object} RenderOptions
|
|
41
38
|
* @property {number} [scale] Pixels per module. Default 8.
|
|
@@ -44,7 +41,6 @@ import { BitMatrix } from '../core/bit-matrix.js';
|
|
|
44
41
|
* @property {string} [light] Colour of clear modules, or 'none' for transparent.
|
|
45
42
|
* @property {number} [barHeight] For 1D symbols: total bar height in pixels.
|
|
46
43
|
*/
|
|
47
|
-
|
|
48
44
|
/**
|
|
49
45
|
* Expand and pad the matrix, and resolve every dimension.
|
|
50
46
|
*
|
|
@@ -57,42 +53,39 @@ import { BitMatrix } from '../core/bit-matrix.js';
|
|
|
57
53
|
* @param {RenderOptions} options
|
|
58
54
|
*/
|
|
59
55
|
export function normalizeOptions(matrix, options = {}) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
56
|
+
const scale = Math.max(1, Math.floor(options.scale ?? 8));
|
|
57
|
+
const margin = Math.max(0, Math.floor(options.margin ?? 4));
|
|
58
|
+
const dark = options.dark ?? '#000000';
|
|
59
|
+
const light = options.light ?? '#ffffff';
|
|
60
|
+
const barHeight = options.barHeight ?? null;
|
|
61
|
+
let base = matrix;
|
|
62
|
+
const is1D = matrix.height === 1;
|
|
63
|
+
if (is1D) {
|
|
64
|
+
// Default to a bar height that stays scannable: tall enough that a laser
|
|
65
|
+
// crossing at a slight angle still passes through the whole symbol.
|
|
66
|
+
const targetPixels = barHeight ?? Math.max(40, Math.round(matrix.width * scale * 0.15));
|
|
67
|
+
const rows = Math.max(1, Math.round(targetPixels / scale));
|
|
68
|
+
base = new BitMatrix(matrix.width, rows);
|
|
69
|
+
for (let x = 0; x < matrix.width; x++) {
|
|
70
|
+
if (!matrix.get(x, 0))
|
|
71
|
+
continue;
|
|
72
|
+
for (let y = 0; y < rows; y++)
|
|
73
|
+
base.set(x, y);
|
|
74
|
+
}
|
|
78
75
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
pixelWidth: source.width * scale,
|
|
92
|
-
pixelHeight: source.height * scale,
|
|
93
|
-
};
|
|
76
|
+
const source = margin > 0 ? base.withMargin(margin) : base;
|
|
77
|
+
return {
|
|
78
|
+
scale,
|
|
79
|
+
margin,
|
|
80
|
+
dark,
|
|
81
|
+
light,
|
|
82
|
+
is1D,
|
|
83
|
+
source,
|
|
84
|
+
rowHeight: scale,
|
|
85
|
+
pixelWidth: source.width * scale,
|
|
86
|
+
pixelHeight: source.height * scale,
|
|
87
|
+
};
|
|
94
88
|
}
|
|
95
|
-
|
|
96
89
|
/**
|
|
97
90
|
* Parse a CSS colour into RGBA bytes.
|
|
98
91
|
*
|
|
@@ -103,58 +96,57 @@ export function normalizeOptions(matrix, options = {}) {
|
|
|
103
96
|
* @returns {[number, number, number, number]}
|
|
104
97
|
*/
|
|
105
98
|
export function parseColor(colour) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
99
|
+
const value = String(colour).trim().toLowerCase();
|
|
100
|
+
if (value === 'none' || value === 'transparent')
|
|
101
|
+
return [0, 0, 0, 0];
|
|
102
|
+
if (value === 'white')
|
|
103
|
+
return [255, 255, 255, 255];
|
|
104
|
+
if (value === 'black')
|
|
105
|
+
return [0, 0, 0, 255];
|
|
106
|
+
if (value[0] === '#') {
|
|
107
|
+
const hex = value.slice(1);
|
|
108
|
+
const expand = (c) => parseInt(c + c, 16);
|
|
109
|
+
if (hex.length === 3) {
|
|
110
|
+
return [expand(hex[0]), expand(hex[1]), expand(hex[2]), 255];
|
|
111
|
+
}
|
|
112
|
+
if (hex.length === 4) {
|
|
113
|
+
return [expand(hex[0]), expand(hex[1]), expand(hex[2]), expand(hex[3])];
|
|
114
|
+
}
|
|
115
|
+
if (hex.length === 6) {
|
|
116
|
+
return [
|
|
117
|
+
parseInt(hex.slice(0, 2), 16),
|
|
118
|
+
parseInt(hex.slice(2, 4), 16),
|
|
119
|
+
parseInt(hex.slice(4, 6), 16),
|
|
120
|
+
255,
|
|
121
|
+
];
|
|
122
|
+
}
|
|
123
|
+
if (hex.length === 8) {
|
|
124
|
+
return [
|
|
125
|
+
parseInt(hex.slice(0, 2), 16),
|
|
126
|
+
parseInt(hex.slice(2, 4), 16),
|
|
127
|
+
parseInt(hex.slice(4, 6), 16),
|
|
128
|
+
parseInt(hex.slice(6, 8), 16),
|
|
129
|
+
];
|
|
130
|
+
}
|
|
117
131
|
}
|
|
118
|
-
|
|
119
|
-
|
|
132
|
+
const fn = value.match(/^rgba?\(([^)]+)\)$/);
|
|
133
|
+
if (fn) {
|
|
134
|
+
const parts = fn[1].split(/[,/\s]+/).filter(Boolean);
|
|
135
|
+
const channel = (s) => (s.endsWith('%')
|
|
136
|
+
? Math.round((parseFloat(s) / 100) * 255)
|
|
137
|
+
: Math.round(parseFloat(s)));
|
|
138
|
+
const r = channel(parts[0]);
|
|
139
|
+
const g = channel(parts[1]);
|
|
140
|
+
const b = channel(parts[2]);
|
|
141
|
+
let a = 255;
|
|
142
|
+
if (parts.length > 3) {
|
|
143
|
+
a = parts[3].endsWith('%')
|
|
144
|
+
? Math.round((parseFloat(parts[3]) / 100) * 255)
|
|
145
|
+
: Math.round(parseFloat(parts[3]) * 255);
|
|
146
|
+
}
|
|
147
|
+
return [r, g, b, a];
|
|
120
148
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
parseInt(hex.slice(2, 4), 16),
|
|
125
|
-
parseInt(hex.slice(4, 6), 16),
|
|
126
|
-
255,
|
|
127
|
-
];
|
|
128
|
-
}
|
|
129
|
-
if (hex.length === 8) {
|
|
130
|
-
return [
|
|
131
|
-
parseInt(hex.slice(0, 2), 16),
|
|
132
|
-
parseInt(hex.slice(2, 4), 16),
|
|
133
|
-
parseInt(hex.slice(4, 6), 16),
|
|
134
|
-
parseInt(hex.slice(6, 8), 16),
|
|
135
|
-
];
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const fn = value.match(/^rgba?\(([^)]+)\)$/);
|
|
140
|
-
if (fn) {
|
|
141
|
-
const parts = fn[1].split(/[,/\s]+/).filter(Boolean);
|
|
142
|
-
const channel = (s) => (s.endsWith('%')
|
|
143
|
-
? Math.round((parseFloat(s) / 100) * 255)
|
|
144
|
-
: Math.round(parseFloat(s)));
|
|
145
|
-
const r = channel(parts[0]);
|
|
146
|
-
const g = channel(parts[1]);
|
|
147
|
-
const b = channel(parts[2]);
|
|
148
|
-
let a = 255;
|
|
149
|
-
if (parts.length > 3) {
|
|
150
|
-
a = parts[3].endsWith('%')
|
|
151
|
-
? Math.round((parseFloat(parts[3]) / 100) * 255)
|
|
152
|
-
: Math.round(parseFloat(parts[3]) * 255);
|
|
153
|
-
}
|
|
154
|
-
return [r, g, b, a];
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Unrecognised: fall back to opaque black rather than throwing, so an
|
|
158
|
-
// unusual colour never costs someone a barcode.
|
|
159
|
-
return [0, 0, 0, 255];
|
|
149
|
+
// Unrecognised: fall back to opaque black rather than throwing, so an
|
|
150
|
+
// unusual colour never costs someone a barcode.
|
|
151
|
+
return [0, 0, 0, 255];
|
|
160
152
|
}
|