@sythos/js_barcode_universal 1.3.1 → 1.4.1
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/AI_USAGE.md +33 -0
- package/LICENSE +4 -2
- package/NOTICE.md +8 -5
- package/README.md +74 -23
- package/bundle/sythos-barcode.esm.js +2313 -92
- package/bundle/sythos-barcode.js +2229 -88
- package/examples/create.html +2 -1
- package/examples/read.html +1 -0
- package/licenses/README.md +6 -1
- package/licenses/aztec-rune.license +76 -0
- package/licenses/compact-pdf417.license +76 -0
- package/licenses/ean-2.license +74 -0
- package/licenses/ean-5.license +74 -0
- package/licenses/frameqr.license +6 -6
- package/licenses/gs1-databar.license +81 -0
- package/package.json +16 -4
- package/src/aztec/decoder.js +1 -0
- package/src/aztec/detector.js +1 -0
- package/src/aztec/encoder.js +1 -0
- package/src/aztec/high-level.js +1 -0
- package/src/aztec/index.js +1 -0
- package/src/aztec/tables.js +1 -0
- package/src/aztecrune/decoder.js +156 -0
- package/src/aztecrune/detector.js +167 -0
- package/src/aztecrune/encoder.js +122 -0
- package/src/aztecrune/index.js +50 -0
- package/src/aztecrune/tables.js +138 -0
- package/src/compactpdf417/decoder.js +129 -0
- package/src/compactpdf417/detector.js +140 -0
- package/src/compactpdf417/encoder.js +141 -0
- package/src/compactpdf417/index.js +22 -0
- package/src/compactpdf417/tables.js +174 -0
- package/src/core/bit-buffer.js +1 -0
- package/src/core/bit-matrix.js +1 -0
- package/src/core/errors.js +1 -0
- package/src/core/galois-field.js +1 -0
- package/src/core/index.js +1 -0
- package/src/core/reed-solomon.js +1 -0
- package/src/databar/codec.js +182 -0
- package/src/databar/decoder.js +115 -0
- package/src/databar/encoder.js +97 -0
- package/src/databar/gs1.js +178 -0
- package/src/databar/index.js +69 -0
- package/src/databar/patterns.js +144 -0
- package/src/databar/tables.js +125 -0
- package/src/datamatrix/decoder.js +1 -0
- package/src/datamatrix/detector.js +1 -0
- package/src/datamatrix/encoder.js +1 -0
- package/src/datamatrix/index.js +1 -0
- package/src/datamatrix/tables.js +1 -0
- package/src/frameqr/decoder.js +16 -15
- package/src/frameqr/detector.js +3 -2
- package/src/frameqr/encoder.js +8 -7
- package/src/frameqr/index.js +1 -0
- package/src/frameqr/tables.js +11 -10
- package/src/image/binarizer.js +1 -0
- package/src/image/grid-sampler.js +1 -0
- package/src/image/index.js +1 -0
- package/src/image/luminance.js +1 -0
- package/src/image/perspective.js +1 -0
- package/src/index.js +72 -8
- package/src/micropdf417/compaction.js +1 -0
- package/src/micropdf417/decoder.js +1 -0
- package/src/micropdf417/detector.js +1 -0
- package/src/micropdf417/encoder.js +1 -0
- package/src/micropdf417/error-correction.js +1 -0
- package/src/micropdf417/index.js +1 -0
- package/src/micropdf417/tables.js +1 -0
- package/src/microqr/decoder.js +1 -0
- package/src/microqr/detector.js +1 -0
- package/src/microqr/encoder.js +1 -0
- package/src/microqr/index.js +1 -0
- package/src/microqr/tables.js +1 -0
- package/src/oned/addons.js +421 -0
- package/src/oned/index.js +18 -0
- package/src/oned/patterns.js +1 -0
- package/src/oned/reader.js +1 -0
- package/src/oned/writers.js +1 -0
- package/src/pdf417/compaction.js +1 -0
- package/src/pdf417/decoder.js +1 -0
- package/src/pdf417/detector.js +1 -0
- package/src/pdf417/encoder.js +1 -0
- package/src/pdf417/error-correction.js +1 -0
- package/src/pdf417/index.js +5 -0
- package/src/pdf417/tables.js +1 -0
- package/src/qr/decoder.js +1 -0
- package/src/qr/detector.js +1 -0
- package/src/qr/encoder.js +1 -0
- package/src/qr/index.js +1 -0
- package/src/qr/tables.js +1 -0
- package/src/render/image-data.js +1 -0
- package/src/render/index.js +1 -0
- package/src/render/options.js +1 -0
- package/src/render/png.js +1 -0
- package/src/render/svg.js +1 -0
- package/src/render/webgl.js +1 -0
- package/src/render/webgpu.js +1 -0
- package/src/rmqr/decoder.js +1 -0
- package/src/rmqr/detector.js +1 -0
- package/src/rmqr/encoder.js +1 -0
- package/src/rmqr/index.js +1 -0
- package/src/rmqr/tables.js +1 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Sythos Barcode Suite
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2026 Sythos
|
|
7
|
+
*
|
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
* furnished to do so, subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
* copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
* SOFTWARE.
|
|
25
|
+
*
|
|
26
|
+
* SPDX-FileCopyrightText: 2026 Sythos (https://www.sythos.net)
|
|
27
|
+
* SPDX-License-Identifier: MIT
|
|
28
|
+
*
|
|
29
|
+
* Original work. No code from any other barcode implementation.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/** Mathematical width construction for GS1 DataBar characters. @module databar/patterns */
|
|
33
|
+
|
|
34
|
+
import { dataBar14GroupFor } from './tables.js';
|
|
35
|
+
|
|
36
|
+
function combinations(n, r) {
|
|
37
|
+
if (n < r || r < 0) return 0;
|
|
38
|
+
if (r === 0 || n === r) return 1;
|
|
39
|
+
let result = 1;
|
|
40
|
+
const k = Math.min(r, n - r);
|
|
41
|
+
for (let i = 1; i <= k; i++) result = result * (n - k + i) / i;
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Unrank one constrained positive composition.
|
|
47
|
+
*
|
|
48
|
+
* The rank is the GS1 DataBar symbol-character value inside its group. This
|
|
49
|
+
* implementation follows the combinatorial definition directly: it counts
|
|
50
|
+
* every remaining admissible suffix rather than storing third-party patterns.
|
|
51
|
+
*/
|
|
52
|
+
export function dataBarWidths(rank, modules, elements, maximumWidth, noNarrow) {
|
|
53
|
+
if (!Number.isInteger(rank) || rank < 0) throw new RangeError('GS1 DataBar width rank must be non-negative');
|
|
54
|
+
const widths = new Array(elements).fill(0);
|
|
55
|
+
let remaining = modules;
|
|
56
|
+
let narrowMask = 0;
|
|
57
|
+
|
|
58
|
+
for (let bar = 0; bar < elements - 1; bar++) {
|
|
59
|
+
let count = 0;
|
|
60
|
+
for (let width = 1; ; width++) {
|
|
61
|
+
narrowMask |= width === 1 ? 1 << bar : 0;
|
|
62
|
+
count = combinations(remaining - width - 1, elements - bar - 2);
|
|
63
|
+
|
|
64
|
+
if (noNarrow && narrowMask === 0 && remaining - width - (elements - bar - 1) >= elements - bar - 1) {
|
|
65
|
+
count -= combinations(remaining - width - (elements - bar), elements - bar - 2);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (elements - bar - 1 > 1) {
|
|
69
|
+
let tooWide = 0;
|
|
70
|
+
for (let last = remaining - width - (elements - bar - 2); last > maximumWidth; last--) {
|
|
71
|
+
tooWide += combinations(remaining - width - last - 1, elements - bar - 3);
|
|
72
|
+
}
|
|
73
|
+
count -= tooWide * (elements - 1 - bar);
|
|
74
|
+
} else if (remaining - width > maximumWidth) {
|
|
75
|
+
count--;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (rank < count) {
|
|
79
|
+
widths[bar] = width;
|
|
80
|
+
remaining -= width;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
rank -= count;
|
|
84
|
+
narrowMask &= ~(1 << bar);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
widths[elements - 1] = remaining;
|
|
88
|
+
if (rank !== 0 || widths.some((width) => width < 1 || width > maximumWidth)) {
|
|
89
|
+
throw new RangeError('GS1 DataBar width rank exceeds its character group');
|
|
90
|
+
}
|
|
91
|
+
return widths;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Convert one DataBar-14 character value into its eight alternating widths. */
|
|
95
|
+
export function dataBar14CharacterWidths(value, kind) {
|
|
96
|
+
const group = dataBar14GroupFor(value, kind);
|
|
97
|
+
const offset = value - group.gsum;
|
|
98
|
+
const outside = kind === 'outside';
|
|
99
|
+
const oddRank = outside ? Math.floor(offset / group.evenTotal) : offset % group.oddTotal;
|
|
100
|
+
const evenRank = outside ? offset % group.evenTotal : Math.floor(offset / group.oddTotal);
|
|
101
|
+
const odd = dataBarWidths(oddRank, group.oddModules, 4, group.oddWidest, !outside);
|
|
102
|
+
const even = dataBarWidths(evenRank, group.evenModules, 4, group.evenWidest, outside);
|
|
103
|
+
const result = [];
|
|
104
|
+
for (let i = 0; i < 4; i++) result.push(odd[i], even[i]);
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const inverseCharacterMaps = new Map();
|
|
109
|
+
|
|
110
|
+
/** Recover a character value from its canonical eight-width representation. */
|
|
111
|
+
export function dataBar14ValueForWidths(widths, kind) {
|
|
112
|
+
if (!Array.isArray(widths) || widths.length !== 8 || widths.some((width) => !Number.isInteger(width) || width < 1)) {
|
|
113
|
+
throw new TypeError('GS1 DataBar character widths must contain eight positive integers');
|
|
114
|
+
}
|
|
115
|
+
if (kind !== 'outside' && kind !== 'inside') throw new RangeError(`Unknown GS1 DataBar character kind "${kind}"`);
|
|
116
|
+
let inverse = inverseCharacterMaps.get(kind);
|
|
117
|
+
if (!inverse) {
|
|
118
|
+
inverse = new Map();
|
|
119
|
+
const maximum = kind === 'outside' ? 2840 : 1596;
|
|
120
|
+
for (let value = 0; value <= maximum; value++) {
|
|
121
|
+
inverse.set(dataBar14CharacterWidths(value, kind).join(','), value);
|
|
122
|
+
}
|
|
123
|
+
inverseCharacterMaps.set(kind, inverse);
|
|
124
|
+
}
|
|
125
|
+
const value = inverse.get(widths.join(','));
|
|
126
|
+
if (value === undefined) throw new RangeError(`Invalid GS1 DataBar ${kind} character widths`);
|
|
127
|
+
return value;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Nine finder patterns, expressed as normative five-element widths. */
|
|
131
|
+
export const DATABAR14_FINDERS = Object.freeze([
|
|
132
|
+
Object.freeze([3, 8, 2, 1, 1]), Object.freeze([3, 5, 5, 1, 1]),
|
|
133
|
+
Object.freeze([3, 3, 7, 1, 1]), Object.freeze([3, 1, 9, 1, 1]),
|
|
134
|
+
Object.freeze([2, 7, 4, 1, 1]), Object.freeze([2, 5, 6, 1, 1]),
|
|
135
|
+
Object.freeze([2, 3, 8, 1, 1]), Object.freeze([1, 5, 7, 1, 1]),
|
|
136
|
+
Object.freeze([1, 3, 9, 1, 1]),
|
|
137
|
+
]);
|
|
138
|
+
|
|
139
|
+
/** Weight sequence generated as powers of three modulo 79. */
|
|
140
|
+
export const DATABAR14_CHECKSUM_WEIGHTS = Object.freeze(Array.from({ length: 32 }, (_, index) => {
|
|
141
|
+
let value = 1;
|
|
142
|
+
for (let i = 0; i < index; i++) value = (value * 3) % 79;
|
|
143
|
+
return value;
|
|
144
|
+
}));
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Sythos Barcode Suite
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2026 Sythos
|
|
7
|
+
*
|
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
* furnished to do so, subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
* copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
* SOFTWARE.
|
|
25
|
+
*
|
|
26
|
+
* SPDX-FileCopyrightText: 2026 Sythos (https://www.sythos.net)
|
|
27
|
+
* SPDX-License-Identifier: MIT
|
|
28
|
+
*
|
|
29
|
+
* Original work. No code from any other barcode implementation.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Static GS1 DataBar facts used by the GTIN compaction codec.
|
|
34
|
+
*
|
|
35
|
+
* The numbers in the DataBar-14 group tables are the public tables in
|
|
36
|
+
* ISO/IEC 24724:2011, clauses 5.2.2 and 5.2.3. They describe values, not a
|
|
37
|
+
* third-party implementation. Pattern construction deliberately belongs in
|
|
38
|
+
* the renderer/encoder layer so this module stays a small, auditable contract.
|
|
39
|
+
*
|
|
40
|
+
* @module databar/tables
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
const group = (first, last, gsum, oddModules, evenModules, oddWidest, evenWidest, oddTotal, evenTotal) => Object.freeze({
|
|
44
|
+
first, last, gsum, oddModules, evenModules, oddWidest, evenWidest, oddTotal, evenTotal,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
/** The four GTIN-only layouts sharing the DataBar-14 compaction rules. */
|
|
48
|
+
export const DATABAR14_VARIANTS = Object.freeze({
|
|
49
|
+
omnidirectional: Object.freeze({ id: 'omnidirectional', rows: 1, modules: 96, checksumModulus: 79, pointOfSale: true }),
|
|
50
|
+
truncated: Object.freeze({ id: 'truncated', rows: 1, modules: 96, checksumModulus: 79, pointOfSale: false }),
|
|
51
|
+
stacked: Object.freeze({ id: 'stacked', rows: 2, modules: 50, checksumModulus: 79, pointOfSale: false }),
|
|
52
|
+
'stacked-omnidirectional': Object.freeze({ id: 'stacked-omnidirectional', rows: 2, modules: 50, checksumModulus: 79, pointOfSale: true }),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
/** GS1 DataBar Limited is a distinct two-character symbology. */
|
|
56
|
+
export const DATABAR_LIMITED_VARIANT = Object.freeze({
|
|
57
|
+
id: 'limited', rows: 1, checksumModulus: 89, pointOfSale: false,
|
|
58
|
+
permittedIndicatorDigits: Object.freeze([0, 1]),
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
/** (16,4) outside character groups, ISO/IEC 24724:2011 Table 1. */
|
|
62
|
+
export const DATABAR14_OUTSIDE_GROUPS = Object.freeze([
|
|
63
|
+
group(0, 160, 0, 12, 4, 8, 1, 161, 1),
|
|
64
|
+
group(161, 960, 161, 10, 6, 6, 3, 80, 10),
|
|
65
|
+
group(961, 2014, 961, 8, 8, 4, 5, 31, 34),
|
|
66
|
+
group(2015, 2714, 2015, 6, 10, 3, 6, 10, 70),
|
|
67
|
+
group(2715, 2840, 2715, 4, 12, 1, 8, 1, 126),
|
|
68
|
+
]);
|
|
69
|
+
|
|
70
|
+
/** (15,4) inside character groups, ISO/IEC 24724:2011 Table 2. */
|
|
71
|
+
export const DATABAR14_INSIDE_GROUPS = Object.freeze([
|
|
72
|
+
group(0, 335, 0, 5, 10, 2, 7, 4, 84),
|
|
73
|
+
group(336, 1035, 336, 7, 8, 4, 5, 20, 35),
|
|
74
|
+
group(1036, 1515, 1036, 9, 6, 6, 3, 48, 10),
|
|
75
|
+
group(1516, 1596, 1516, 11, 4, 8, 1, 81, 1),
|
|
76
|
+
]);
|
|
77
|
+
|
|
78
|
+
/** Number of values carried by an inside (15,4) character. */
|
|
79
|
+
export const DATABAR14_INSIDE_RADIX = 1597;
|
|
80
|
+
/** Number of values carried by one outside/inside character pair. */
|
|
81
|
+
export const DATABAR14_PAIR_RADIX = 4537077;
|
|
82
|
+
/** Stand-alone and composite DataBar-14 payload domain, including linkage. */
|
|
83
|
+
export const DATABAR14_SYMBOL_LIMIT = 20000000000000n;
|
|
84
|
+
|
|
85
|
+
/** GS1 DataBar Limited divides its 13 data digits into two character values. */
|
|
86
|
+
export const DATABAR_LIMITED_PAIR_RADIX = 2013571;
|
|
87
|
+
/** Offset that switches a DataBar Limited value from stand-alone to composite. */
|
|
88
|
+
export const DATABAR_LIMITED_LINKAGE_OFFSET = 2015133531096n;
|
|
89
|
+
/** DataBar Limited carries GTIN values whose first digit is zero or one. */
|
|
90
|
+
export const DATABAR_LIMITED_DATA_LIMIT = 2000000000000n;
|
|
91
|
+
|
|
92
|
+
/** Locate the value group that an outside or inside character belongs to. */
|
|
93
|
+
export function dataBar14GroupFor(value, kind) {
|
|
94
|
+
if (!Number.isInteger(value)) throw new TypeError('GS1 DataBar character value must be an integer');
|
|
95
|
+
const groups = kind === 'outside' ? DATABAR14_OUTSIDE_GROUPS
|
|
96
|
+
: kind === 'inside' ? DATABAR14_INSIDE_GROUPS : null;
|
|
97
|
+
if (!groups) throw new RangeError(`Unknown GS1 DataBar character kind "${kind}"`);
|
|
98
|
+
const found = groups.find((entry) => value >= entry.first && value <= entry.last);
|
|
99
|
+
if (!found) throw new RangeError(`GS1 DataBar ${kind} character value ${value} is out of range`);
|
|
100
|
+
return found;
|
|
101
|
+
}
|
|
102
|
+
/** Check the independently represented table identities. */
|
|
103
|
+
export function validateDataBarTables() {
|
|
104
|
+
const problems = [];
|
|
105
|
+
const validateGroups = (name, groups, expectedLast) => {
|
|
106
|
+
let next = 0;
|
|
107
|
+
for (const entry of groups) {
|
|
108
|
+
if (entry.first !== next) problems.push(`${name}: gap before ${entry.first}`);
|
|
109
|
+
if (entry.last < entry.first) problems.push(`${name}: inverted range ${entry.first}-${entry.last}`);
|
|
110
|
+
if (entry.oddTotal * entry.evenTotal !== entry.last - entry.first + 1) {
|
|
111
|
+
problems.push(`${name}: combination count mismatch at ${entry.first}`);
|
|
112
|
+
}
|
|
113
|
+
next = entry.last + 1;
|
|
114
|
+
}
|
|
115
|
+
if (next - 1 !== expectedLast) problems.push(`${name}: final value is ${next - 1}, expected ${expectedLast}`);
|
|
116
|
+
};
|
|
117
|
+
validateGroups('outside', DATABAR14_OUTSIDE_GROUPS, 2840);
|
|
118
|
+
validateGroups('inside', DATABAR14_INSIDE_GROUPS, 1596);
|
|
119
|
+
if (DATABAR14_PAIR_RADIX !== 2841 * DATABAR14_INSIDE_RADIX) problems.push('pair radix mismatch');
|
|
120
|
+
if (DATABAR14_SYMBOL_LIMIT !== 2n * 10000000000000n) problems.push('symbol limit mismatch');
|
|
121
|
+
if (DATABAR_LIMITED_LINKAGE_OFFSET !== BigInt(DATABAR_LIMITED_PAIR_RADIX) * 1000776n) {
|
|
122
|
+
problems.push('limited linkage offset mismatch');
|
|
123
|
+
}
|
|
124
|
+
return problems;
|
|
125
|
+
}
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
24
|
* SOFTWARE.
|
|
25
25
|
*
|
|
26
|
+
* SPDX-FileCopyrightText: 2026 Sythos (https://www.sythos.net)
|
|
26
27
|
* SPDX-License-Identifier: MIT
|
|
27
28
|
*
|
|
28
29
|
* Original work. No code from any other barcode implementation.
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
24
|
* SOFTWARE.
|
|
25
25
|
*
|
|
26
|
+
* SPDX-FileCopyrightText: 2026 Sythos (https://www.sythos.net)
|
|
26
27
|
* SPDX-License-Identifier: MIT
|
|
27
28
|
*
|
|
28
29
|
* Original work. No code from any other barcode implementation.
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
24
|
* SOFTWARE.
|
|
25
25
|
*
|
|
26
|
+
* SPDX-FileCopyrightText: 2026 Sythos (https://www.sythos.net)
|
|
26
27
|
* SPDX-License-Identifier: MIT
|
|
27
28
|
*
|
|
28
29
|
* Original work. No code from any other barcode implementation.
|
package/src/datamatrix/index.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
24
|
* SOFTWARE.
|
|
25
25
|
*
|
|
26
|
+
* SPDX-FileCopyrightText: 2026 Sythos (https://www.sythos.net)
|
|
26
27
|
* SPDX-License-Identifier: MIT
|
|
27
28
|
*
|
|
28
29
|
* Original work. No code from any other barcode implementation.
|
package/src/datamatrix/tables.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
24
|
* SOFTWARE.
|
|
25
25
|
*
|
|
26
|
+
* SPDX-FileCopyrightText: 2026 Sythos (https://www.sythos.net)
|
|
26
27
|
* SPDX-License-Identifier: MIT
|
|
27
28
|
*
|
|
28
29
|
* Original work. No code from any other barcode implementation.
|
package/src/frameqr/decoder.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* MIT License
|
|
5
5
|
*
|
|
6
6
|
* Copyright (c) 2026 Sythos
|
|
7
|
+
* SPDX-FileCopyrightText: 2026 Sythos (https://www.sythos.net)
|
|
7
8
|
*
|
|
8
9
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
10
|
* of this software and associated documentation files (the "Software"), to deal
|
|
@@ -29,7 +30,7 @@
|
|
|
29
30
|
*/
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
|
-
* Decoder for
|
|
33
|
+
* Decoder for FrameQR Code.
|
|
33
34
|
*
|
|
34
35
|
* This is intentionally not a DENSO FrameQR decoder. The profile is a QR
|
|
35
36
|
* symbol with a bounded artwork reservation and an explicit `frameqr` marker.
|
|
@@ -87,7 +88,7 @@ function isExpectedProfile(profile) {
|
|
|
87
88
|
* @returns {{canvas: object, damage: object}}
|
|
88
89
|
*/
|
|
89
90
|
function validateCanvas(symbolSize, version, canvas) {
|
|
90
|
-
if (!isObject(canvas)) throw new FormatError('
|
|
91
|
+
if (!isObject(canvas)) throw new FormatError('FrameQR Code: canvas metadata is missing');
|
|
91
92
|
|
|
92
93
|
let normalized;
|
|
93
94
|
try {
|
|
@@ -103,14 +104,14 @@ function validateCanvas(symbolSize, version, canvas) {
|
|
|
103
104
|
}
|
|
104
105
|
} catch (error) {
|
|
105
106
|
if (error instanceof FormatError) throw error;
|
|
106
|
-
throw new FormatError(`
|
|
107
|
+
throw new FormatError(`FrameQR Code: invalid canvas metadata: ${error.message}`);
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
let damage;
|
|
110
111
|
try {
|
|
111
112
|
damage = analyzeCanvasDamage(version, normalized);
|
|
112
113
|
} catch (error) {
|
|
113
|
-
throw new FormatError(`
|
|
114
|
+
throw new FormatError(`FrameQR Code: cannot analyse canvas damage: ${error.message}`);
|
|
114
115
|
}
|
|
115
116
|
return { canvas: normalized, damage };
|
|
116
117
|
}
|
|
@@ -135,24 +136,24 @@ function resolveProfile(matrix, options) {
|
|
|
135
136
|
const markerId = isObject(markerProfile) ? markerProfile.id : markerProfile;
|
|
136
137
|
const suppliedId = isObject(suppliedProfile) ? suppliedProfile.id : suppliedProfile;
|
|
137
138
|
if (markerId !== suppliedId) {
|
|
138
|
-
throw new FormatError('
|
|
139
|
+
throw new FormatError('FrameQR Code: matrix and requested profile markers disagree');
|
|
139
140
|
}
|
|
140
141
|
}
|
|
141
142
|
const profile = markerProfile ?? suppliedProfile;
|
|
142
143
|
|
|
143
144
|
if (!isExpectedProfile(profile)) {
|
|
144
145
|
throw new FormatError(
|
|
145
|
-
'
|
|
146
|
+
'FrameQR Code: profile marker is missing or is not a FrameQR Code symbol'
|
|
146
147
|
);
|
|
147
148
|
}
|
|
148
149
|
if (marker && marker.certified === true) {
|
|
149
150
|
throw new FormatError(
|
|
150
|
-
'
|
|
151
|
+
'FrameQR Code: certified FrameQR input is not supported by this profile decoder'
|
|
151
152
|
);
|
|
152
153
|
}
|
|
153
154
|
if (!marker && !options.allowUnmarked) {
|
|
154
155
|
throw new FormatError(
|
|
155
|
-
'
|
|
156
|
+
'FrameQR Code: unmarked QR matrix rejected; provide a verified profile marker'
|
|
156
157
|
);
|
|
157
158
|
}
|
|
158
159
|
|
|
@@ -160,7 +161,7 @@ function resolveProfile(matrix, options) {
|
|
|
160
161
|
const canvas = options.canvas ?? markerCanvas;
|
|
161
162
|
const version = (matrix.width - 17) / 4;
|
|
162
163
|
if (!Number.isInteger(version) || version < 1 || version > 40) {
|
|
163
|
-
throw new FormatError(`
|
|
164
|
+
throw new FormatError(`FrameQR Code: invalid QR symbol size ${matrix.width}`);
|
|
164
165
|
}
|
|
165
166
|
const checked = validateCanvas(matrix.width, version, canvas);
|
|
166
167
|
if (markerCanvas && options.canvas) {
|
|
@@ -168,11 +169,11 @@ function resolveProfile(matrix, options) {
|
|
|
168
169
|
try {
|
|
169
170
|
marked = normalizeCanvasSpec(matrix.width, markerCanvas);
|
|
170
171
|
} catch (error) {
|
|
171
|
-
throw new FormatError(`
|
|
172
|
+
throw new FormatError(`FrameQR Code: invalid marker canvas: ${error.message}`);
|
|
172
173
|
}
|
|
173
174
|
const fields = ['shape', 'centerX', 'centerY', 'width', 'height', 'angle'];
|
|
174
175
|
if (fields.some((field) => marked[field] !== checked.canvas[field])) {
|
|
175
|
-
throw new FormatError('
|
|
176
|
+
throw new FormatError('FrameQR Code: matrix and requested canvas metadata disagree');
|
|
176
177
|
}
|
|
177
178
|
}
|
|
178
179
|
return {
|
|
@@ -184,7 +185,7 @@ function resolveProfile(matrix, options) {
|
|
|
184
185
|
}
|
|
185
186
|
|
|
186
187
|
/**
|
|
187
|
-
* Decode a
|
|
188
|
+
* Decode a FrameQR Code matrix.
|
|
188
189
|
*
|
|
189
190
|
* @param {import('../core/bit-matrix.js').BitMatrix} matrix
|
|
190
191
|
* Square QR modules, normally returned by `encodeFrameQR` or a FrameQR
|
|
@@ -204,11 +205,11 @@ function resolveProfile(matrix, options) {
|
|
|
204
205
|
*/
|
|
205
206
|
export function decodeFrameQR(matrix, options = {}) {
|
|
206
207
|
if (!matrix || !Number.isInteger(matrix.width) || !Number.isInteger(matrix.height)) {
|
|
207
|
-
throw new FormatError('
|
|
208
|
+
throw new FormatError('FrameQR Code: no matrix supplied');
|
|
208
209
|
}
|
|
209
210
|
if (matrix.width !== matrix.height) {
|
|
210
211
|
throw new FormatError(
|
|
211
|
-
`
|
|
212
|
+
`FrameQR Code: symbol must be square, got ${matrix.width}x${matrix.height}`
|
|
212
213
|
);
|
|
213
214
|
}
|
|
214
215
|
|
|
@@ -220,7 +221,7 @@ export function decodeFrameQR(matrix, options = {}) {
|
|
|
220
221
|
// Preserve the original QR/RS error when possible, but give callers a
|
|
221
222
|
// profile-specific context without exposing implementation details.
|
|
222
223
|
if (error instanceof FormatError) {
|
|
223
|
-
throw new FormatError(`
|
|
224
|
+
throw new FormatError(`FrameQR Code: payload is not recoverable: ${error.message}`);
|
|
224
225
|
}
|
|
225
226
|
throw error;
|
|
226
227
|
}
|
package/src/frameqr/detector.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* MIT License
|
|
5
5
|
*
|
|
6
6
|
* Copyright (c) 2026 Sythos
|
|
7
|
+
* SPDX-FileCopyrightText: 2026 Sythos (https://www.sythos.net)
|
|
7
8
|
*
|
|
8
9
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
10
|
* of this software and associated documentation files (the "Software"), to deal
|
|
@@ -29,7 +30,7 @@
|
|
|
29
30
|
*/
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
|
-
* Detector for the non-certified
|
|
33
|
+
* Detector for the non-certified FrameQR Code profile.
|
|
33
34
|
*
|
|
34
35
|
* The profile deliberately reuses QR Model 2 geometry. Finder localisation and
|
|
35
36
|
* projective sampling therefore use the QR detector; the additional profile
|
|
@@ -98,7 +99,7 @@ function sameCandidate(left, right) {
|
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
/**
|
|
101
|
-
* Detect
|
|
102
|
+
* Detect FrameQR Code symbols in a binarized raster.
|
|
102
103
|
*
|
|
103
104
|
* @param {import('../core/bit-matrix.js').BitMatrix} binaryImage Set bit = dark.
|
|
104
105
|
* @param {object} [options]
|
package/src/frameqr/encoder.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* MIT License
|
|
5
5
|
*
|
|
6
6
|
* Copyright (c) 2026 Sythos
|
|
7
|
+
* SPDX-FileCopyrightText: 2026 Sythos (https://www.sythos.net)
|
|
7
8
|
*
|
|
8
9
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
10
|
* of this software and associated documentation files (the "Software"), to deal
|
|
@@ -29,7 +30,7 @@
|
|
|
29
30
|
*/
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
|
-
*
|
|
33
|
+
* FrameQR Code encoder.
|
|
33
34
|
*
|
|
34
35
|
* This encoder deliberately builds on this project's QR Code implementation
|
|
35
36
|
* and then removes a conservatively bounded set of data modules for artwork.
|
|
@@ -68,7 +69,7 @@ function clearCanvas(matrix, modules) {
|
|
|
68
69
|
|
|
69
70
|
/**
|
|
70
71
|
* Encode a QR Code with a conservative artwork canvas according to the
|
|
71
|
-
* non-certified
|
|
72
|
+
* non-certified FrameQR Code profile.
|
|
72
73
|
*
|
|
73
74
|
* The profile forces QR H error correction and rejects a canvas whenever its
|
|
74
75
|
* known codeword damage exceeds the per-block correction budget. When a
|
|
@@ -84,10 +85,10 @@ function clearCanvas(matrix, modules) {
|
|
|
84
85
|
*/
|
|
85
86
|
export function encodeFrameQR(text, options = {}) {
|
|
86
87
|
if (typeof text !== 'string') {
|
|
87
|
-
throw new EncodeError('
|
|
88
|
+
throw new EncodeError('FrameQR Code: text must be a string');
|
|
88
89
|
}
|
|
89
90
|
if (options.ecc !== undefined && options.ecc !== 'H') {
|
|
90
|
-
throw new EncodeError('
|
|
91
|
+
throw new EncodeError('FrameQR Code: ecc is fixed to H for this profile');
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
const qrOptions = {
|
|
@@ -123,7 +124,7 @@ export function encodeFrameQR(text, options = {}) {
|
|
|
123
124
|
analysis = validateCanvasSpec(versionFor(matrix), canvas);
|
|
124
125
|
} catch (error) {
|
|
125
126
|
if (error instanceof EncodeError) throw error;
|
|
126
|
-
throw new EncodeError(`
|
|
127
|
+
throw new EncodeError(`FrameQR Code: invalid canvas: ${error.message}`);
|
|
127
128
|
}
|
|
128
129
|
if (!analysis.safe) {
|
|
129
130
|
unsafeAnalysis = analysis;
|
|
@@ -136,13 +137,13 @@ export function encodeFrameQR(text, options = {}) {
|
|
|
136
137
|
if (!selected) {
|
|
137
138
|
if (unsafeAnalysis) {
|
|
138
139
|
throw new EncodeError(
|
|
139
|
-
'
|
|
140
|
+
'FrameQR Code: canvas is not safe for the selected QR version; ' +
|
|
140
141
|
`it touches ${unsafeAnalysis.touchedCodewordCount} codewords and has ` +
|
|
141
142
|
`a per-block correction budget of ${unsafeAnalysis.correctionBudgetPerBlock}`
|
|
142
143
|
);
|
|
143
144
|
}
|
|
144
145
|
if (capacityError) throw capacityError;
|
|
145
|
-
throw new EncodeError('
|
|
146
|
+
throw new EncodeError('FrameQR Code: unable to select a QR version');
|
|
146
147
|
}
|
|
147
148
|
|
|
148
149
|
const { matrix, canvas } = selected;
|
package/src/frameqr/index.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* MIT License
|
|
5
5
|
*
|
|
6
6
|
* Copyright (c) 2026 Sythos
|
|
7
|
+
* SPDX-FileCopyrightText: 2026 Sythos (https://www.sythos.net)
|
|
7
8
|
*
|
|
8
9
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
10
|
* of this software and associated documentation files (the "Software"), to deal
|
package/src/frameqr/tables.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* MIT License
|
|
5
5
|
*
|
|
6
6
|
* Copyright (c) 2026 Sythos
|
|
7
|
+
* SPDX-FileCopyrightText: 2026 Sythos (https://www.sythos.net)
|
|
7
8
|
*
|
|
8
9
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
10
|
* of this software and associated documentation files (the "Software"), to deal
|
|
@@ -29,7 +30,7 @@
|
|
|
29
30
|
*/
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
|
-
* Structural contract for
|
|
33
|
+
* Structural contract for FrameQR Code.
|
|
33
34
|
*
|
|
34
35
|
* DENSO WAVE's public material describes FrameQR(R) as a proprietary symbol
|
|
35
36
|
* with a freely shaped canvas, dedicated generation/reading software and no
|
|
@@ -41,7 +42,7 @@
|
|
|
41
42
|
* symbol at level H and clears a bounded group of data modules. Its worst-case
|
|
42
43
|
* damage is calculated per Reed-Solomon block and must remain within the
|
|
43
44
|
* standard QR correction radius. Function modules are never canvas modules.
|
|
44
|
-
* This provides a deterministic, independently testable
|
|
45
|
+
* This provides a deterministic, independently testable FrameQR Code profile, but
|
|
45
46
|
* it is explicitly non-certified and not a substitute for proprietary FrameQR
|
|
46
47
|
* generation or validation software.
|
|
47
48
|
*
|
|
@@ -58,7 +59,7 @@ import {
|
|
|
58
59
|
/** Public identity and compatibility boundary of the implementable profile. */
|
|
59
60
|
export const FRAMEQR_PROFILE = Object.freeze({
|
|
60
61
|
id: 'sythos-canvas-qr/1',
|
|
61
|
-
name: '
|
|
62
|
+
name: 'FrameQR Code',
|
|
62
63
|
certified: false,
|
|
63
64
|
densoFrameQrCompatible: false,
|
|
64
65
|
baseSymbology: 'QR Code Model 2',
|
|
@@ -77,7 +78,7 @@ function oddAtMost(value, maximum) {
|
|
|
77
78
|
|
|
78
79
|
function assertSymbolSize(symbolSize) {
|
|
79
80
|
if (!Number.isInteger(symbolSize) || symbolSize < 21 || symbolSize > 177 || (symbolSize - 17) % 4 !== 0) {
|
|
80
|
-
throw new RangeError(`
|
|
81
|
+
throw new RangeError(`FrameQR Code: ${symbolSize} is not a QR Model 2 symbol size`);
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
|
|
@@ -95,12 +96,12 @@ function assertSymbolSize(symbolSize) {
|
|
|
95
96
|
export function normalizeCanvasSpec(symbolSize, canvas = {}) {
|
|
96
97
|
assertSymbolSize(symbolSize);
|
|
97
98
|
if (canvas === null || typeof canvas !== 'object' || Array.isArray(canvas)) {
|
|
98
|
-
throw new TypeError('
|
|
99
|
+
throw new TypeError('FrameQR Code: canvas must be an object');
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
const shape = String(canvas.shape ?? 'square').toLowerCase();
|
|
102
103
|
if (!FRAMEQR_CANVAS_SHAPES.includes(shape)) {
|
|
103
|
-
throw new RangeError(`
|
|
104
|
+
throw new RangeError(`FrameQR Code: unsupported canvas shape "${shape}"`);
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
const defaultSize = oddAtMost(Math.max(3, Math.round(symbolSize * 0.17)), symbolSize - 16);
|
|
@@ -111,7 +112,7 @@ export function normalizeCanvasSpec(symbolSize, canvas = {}) {
|
|
|
111
112
|
for (const [name, value] of [['width', requestedWidth], ['height', requestedHeight]]) {
|
|
112
113
|
if (!Number.isFinite(Number(value)) || Number(value) < 1 || Number(value) > maximumDimension) {
|
|
113
114
|
throw new RangeError(
|
|
114
|
-
`
|
|
115
|
+
`FrameQR Code: canvas ${name} must be between 1 and ${maximumDimension} modules`
|
|
115
116
|
);
|
|
116
117
|
}
|
|
117
118
|
}
|
|
@@ -122,10 +123,10 @@ export function normalizeCanvasSpec(symbolSize, canvas = {}) {
|
|
|
122
123
|
const angle = ((Number(canvas.angle ?? 0) % 360) + 360) % 360;
|
|
123
124
|
|
|
124
125
|
if (![0, 90, 180, 270].includes(angle)) {
|
|
125
|
-
throw new RangeError('
|
|
126
|
+
throw new RangeError('FrameQR Code: angle must be 0, 90, 180 or 270 degrees');
|
|
126
127
|
}
|
|
127
128
|
if (centerX < 8 || centerY < 8 || centerX >= symbolSize - 8 || centerY >= symbolSize - 8) {
|
|
128
|
-
throw new RangeError('
|
|
129
|
+
throw new RangeError('FrameQR Code: canvas centre must remain inside the finder-pattern boundary');
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
return { shape, centerX, centerY, width, height, angle };
|
|
@@ -196,7 +197,7 @@ function codewordBlockMap(layout) {
|
|
|
196
197
|
*/
|
|
197
198
|
export function analyzeCanvasDamage(version, canvas = {}) {
|
|
198
199
|
if (!Number.isInteger(version) || version < 1 || version > 40) {
|
|
199
|
-
throw new RangeError(`
|
|
200
|
+
throw new RangeError(`FrameQR Code: version must be an integer 1-40, got ${version}`);
|
|
200
201
|
}
|
|
201
202
|
const symbolSize = versionSize(version);
|
|
202
203
|
const spec = normalizeCanvasSpec(symbolSize, canvas);
|
package/src/image/binarizer.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
24
|
* SOFTWARE.
|
|
25
25
|
*
|
|
26
|
+
* SPDX-FileCopyrightText: 2026 Sythos (https://www.sythos.net)
|
|
26
27
|
* SPDX-License-Identifier: MIT
|
|
27
28
|
*
|
|
28
29
|
* Original work. No code from any other barcode implementation.
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
24
|
* SOFTWARE.
|
|
25
25
|
*
|
|
26
|
+
* SPDX-FileCopyrightText: 2026 Sythos (https://www.sythos.net)
|
|
26
27
|
* SPDX-License-Identifier: MIT
|
|
27
28
|
*
|
|
28
29
|
* Original work. No code from any other barcode implementation.
|
package/src/image/index.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
24
|
* SOFTWARE.
|
|
25
25
|
*
|
|
26
|
+
* SPDX-FileCopyrightText: 2026 Sythos (https://www.sythos.net)
|
|
26
27
|
* SPDX-License-Identifier: MIT
|
|
27
28
|
*
|
|
28
29
|
* Original work. No code from any other barcode implementation.
|
package/src/image/luminance.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
24
|
* SOFTWARE.
|
|
25
25
|
*
|
|
26
|
+
* SPDX-FileCopyrightText: 2026 Sythos (https://www.sythos.net)
|
|
26
27
|
* SPDX-License-Identifier: MIT
|
|
27
28
|
*
|
|
28
29
|
* Original work. No code from any other barcode implementation.
|