@sythos/js_barcode_universal 1.5.13 → 1.5.15
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 +22 -4
- package/NOTICE.md +10 -1
- package/README.md +416 -22
- package/bundle/sythos-barcode.esm.js +22176 -11991
- package/bundle/sythos-barcode.js +22059 -11991
- package/licenses/README.md +12 -1
- package/licenses/codablockf.license +51 -0
- package/licenses/code16k.license +52 -0
- package/licenses/code25.license +58 -0
- package/licenses/code32.license +51 -0
- package/licenses/dotcode.license +66 -0
- package/licenses/gs1-composite.license +106 -0
- package/licenses/gs1-databar.license +21 -14
- package/licenses/hanxin.license +95 -0
- package/licenses/maxicode.license +62 -0
- package/licenses/postal.license +61 -0
- package/licenses/pzn.license +53 -0
- package/licenses/telepen.license +73 -0
- package/llms.txt +62 -6
- package/package.json +47 -3
- package/src/index.d.ts +111 -6
- package/src/index.js +362 -13
- package/src/js/codablockf/decoder.js +198 -0
- package/src/js/codablockf/encoder.js +97 -0
- package/src/js/codablockf/index.js +3 -0
- package/src/js/code16k/decoder.js +303 -0
- package/src/js/code16k/detector.js +187 -0
- package/src/js/code16k/encoder.js +153 -0
- package/src/js/code16k/index.js +14 -0
- package/src/js/code16k/tables.js +152 -0
- package/src/js/composite/index.js +570 -0
- package/src/js/core/detection-contract.js +185 -0
- package/src/js/core/symbol-layout.js +155 -0
- package/src/js/databar/expanded.js +968 -0
- package/src/js/databar/index.js +4 -0
- package/src/js/databar/layout.js +192 -0
- package/src/js/databar/limited.js +533 -0
- package/src/js/databar/stacked-omnidirectional.js +548 -0
- package/src/js/databar/stacked.js +528 -0
- package/src/js/dotcode/decoder.js +548 -0
- package/src/js/dotcode/detector.js +251 -0
- package/src/js/dotcode/encoder.js +453 -0
- package/src/js/dotcode/index.js +34 -0
- package/src/js/dotcode/tables.js +168 -0
- package/src/js/hanxin/decoder.js +299 -0
- package/src/js/hanxin/detector.js +122 -0
- package/src/js/hanxin/encoder.js +259 -0
- package/src/js/hanxin/index.js +16 -0
- package/src/js/hanxin/tables.js +316 -0
- package/src/js/image/height-coded.js +164 -0
- package/src/js/maxicode/decoder.js +275 -0
- package/src/js/maxicode/detector.js +118 -0
- package/src/js/maxicode/encoder.js +438 -0
- package/src/js/maxicode/index.js +34 -0
- package/src/js/maxicode/tables.js +132 -0
- package/src/js/oned/code25.js +148 -0
- package/src/js/oned/index.js +21 -3
- package/src/js/oned/postal.js +889 -0
- package/src/js/oned/reader.js +272 -7
- package/src/js/oned/telepen.js +361 -0
- package/src/js/oned/writers.js +186 -12
- package/src/js/stacked128/common.js +208 -0
- package/src/ts/codablockf/decoder.ts +212 -0
- package/src/ts/codablockf/encoder.ts +128 -0
- package/src/ts/codablockf/index.d.ts +31 -0
- package/src/ts/codablockf/index.ts +6 -0
- package/src/ts/code16k/decoder.d.ts +25 -0
- package/src/ts/code16k/decoder.ts +313 -0
- package/src/ts/code16k/detector.d.ts +21 -0
- package/src/ts/code16k/detector.ts +203 -0
- package/src/ts/code16k/encoder.d.ts +26 -0
- package/src/ts/code16k/encoder.ts +198 -0
- package/src/ts/code16k/index.d.ts +10 -0
- package/src/ts/code16k/index.ts +47 -0
- package/src/ts/code16k/tables.d.ts +54 -0
- package/src/ts/code16k/tables.ts +195 -0
- package/src/ts/composite/index.d.ts +74 -0
- package/src/ts/composite/index.ts +547 -0
- package/src/ts/core/detection-contract.d.ts +119 -0
- package/src/ts/core/detection-contract.ts +267 -0
- package/src/ts/core/symbol-layout.d.ts +108 -0
- package/src/ts/core/symbol-layout.ts +236 -0
- package/src/ts/databar/expanded.d.ts +40 -0
- package/src/ts/databar/expanded.ts +948 -0
- package/src/ts/databar/index.d.ts +48 -0
- package/src/ts/databar/index.ts +48 -0
- package/src/ts/databar/layout.d.ts +122 -0
- package/src/ts/databar/layout.ts +275 -0
- package/src/ts/databar/limited.d.ts +85 -0
- package/src/ts/databar/limited.ts +553 -0
- package/src/ts/databar/stacked-omnidirectional.d.ts +128 -0
- package/src/ts/databar/stacked-omnidirectional.ts +559 -0
- package/src/ts/databar/stacked.d.ts +96 -0
- package/src/ts/databar/stacked.ts +549 -0
- package/src/ts/dotcode/decoder.d.ts +58 -0
- package/src/ts/dotcode/decoder.ts +467 -0
- package/src/ts/dotcode/detector.d.ts +63 -0
- package/src/ts/dotcode/detector.ts +263 -0
- package/src/ts/dotcode/encoder.d.ts +69 -0
- package/src/ts/dotcode/encoder.ts +427 -0
- package/src/ts/dotcode/index.d.ts +37 -0
- package/src/ts/dotcode/index.ts +72 -0
- package/src/ts/dotcode/tables.d.ts +74 -0
- package/src/ts/dotcode/tables.ts +174 -0
- package/src/ts/hanxin/decoder.d.ts +48 -0
- package/src/ts/hanxin/decoder.ts +314 -0
- package/src/ts/hanxin/detector.d.ts +45 -0
- package/src/ts/hanxin/detector.ts +124 -0
- package/src/ts/hanxin/encoder.d.ts +41 -0
- package/src/ts/hanxin/encoder.ts +290 -0
- package/src/ts/hanxin/index.d.ts +16 -0
- package/src/ts/hanxin/index.ts +18 -0
- package/src/ts/hanxin/tables.d.ts +80 -0
- package/src/ts/hanxin/tables.ts +348 -0
- package/src/ts/image/height-coded.d.ts +101 -0
- package/src/ts/image/height-coded.ts +227 -0
- package/src/ts/index.d.ts +46 -2
- package/src/ts/index.ts +380 -13
- package/src/ts/maxicode/decoder.ts +265 -0
- package/src/ts/maxicode/detector.ts +109 -0
- package/src/ts/maxicode/encoder.ts +414 -0
- package/src/ts/maxicode/index.d.ts +96 -0
- package/src/ts/maxicode/index.ts +44 -0
- package/src/ts/maxicode/tables.ts +136 -0
- package/src/ts/oned/code25.d.ts +42 -0
- package/src/ts/oned/code25.ts +170 -0
- package/src/ts/oned/index.d.ts +7 -2
- package/src/ts/oned/index.ts +45 -3
- package/src/ts/oned/postal.d.ts +44 -0
- package/src/ts/oned/postal.ts +819 -0
- package/src/ts/oned/reader.d.ts +35 -0
- package/src/ts/oned/reader.ts +261 -7
- package/src/ts/oned/telepen.d.ts +65 -0
- package/src/ts/oned/telepen.ts +368 -0
- package/src/ts/oned/writers.d.ts +32 -0
- package/src/ts/oned/writers.ts +184 -13
- package/src/ts/stacked128/common.ts +225 -0
|
@@ -34,4 +34,52 @@ export { GS1_SEPARATOR, decodeGS1ElementString, encodeGS1ElementString, formatGS
|
|
|
34
34
|
export { DATABAR14_VARIANTS, DATABAR_LIMITED_VARIANT, dataBar14GroupFor, validateDataBarTables, } from './tables.js';
|
|
35
35
|
export { encodeDataBar14 } from './encoder.js';
|
|
36
36
|
export { decodeDataBar14, decodeDataBar14Scanline } from './decoder.js';
|
|
37
|
+
export {
|
|
38
|
+
encodeDataBarLimited,
|
|
39
|
+
decodeDataBarLimited,
|
|
40
|
+
detectDataBarLimited,
|
|
41
|
+
detectAndDecodeDataBarLimited,
|
|
42
|
+
decodeDataBarLimitedScanline,
|
|
43
|
+
} from './limited.js';
|
|
44
|
+
export {
|
|
45
|
+
encodeDataBarExpanded,
|
|
46
|
+
decodeDataBarExpanded,
|
|
47
|
+
detectDataBarExpanded,
|
|
48
|
+
detectAndDecodeDataBarExpanded,
|
|
49
|
+
decodeDataBarExpandedScanline,
|
|
50
|
+
encodeGS1DataBarExpanded,
|
|
51
|
+
decodeGS1DataBarExpanded,
|
|
52
|
+
detectGS1DataBarExpanded,
|
|
53
|
+
detectAndDecodeGS1DataBarExpanded,
|
|
54
|
+
} from './expanded.js';
|
|
55
|
+
export {
|
|
56
|
+
encodeDataBar14Stacked,
|
|
57
|
+
decodeDataBar14Stacked,
|
|
58
|
+
detectDataBar14Stacked,
|
|
59
|
+
detectAndDecodeDataBar14Stacked,
|
|
60
|
+
encodeDataBarStacked,
|
|
61
|
+
decodeDataBarStacked,
|
|
62
|
+
detectDataBarStacked,
|
|
63
|
+
detectAndDecodeDataBarStacked,
|
|
64
|
+
encodeGS1DataBarStacked,
|
|
65
|
+
decodeGS1DataBarStacked,
|
|
66
|
+
detectGS1DataBarStacked,
|
|
67
|
+
detectAndDecodeGS1DataBarStacked,
|
|
68
|
+
} from './stacked.js';
|
|
69
|
+
export {
|
|
70
|
+
encodeDataBarStackedOmnidirectional,
|
|
71
|
+
decodeDataBarStackedOmnidirectional,
|
|
72
|
+
detectDataBarStackedOmnidirectional,
|
|
73
|
+
detectAndDecodeDataBarStackedOmnidirectional,
|
|
74
|
+
encodeDataBarStackedOmni,
|
|
75
|
+
decodeDataBarStackedOmni,
|
|
76
|
+
detectDataBarStackedOmni,
|
|
77
|
+
detectAndDecodeDataBarStackedOmni,
|
|
78
|
+
encodeDataBar14StackedOmnidirectional,
|
|
79
|
+
decodeDataBar14StackedOmnidirectional,
|
|
80
|
+
detectDataBar14StackedOmnidirectional,
|
|
81
|
+
encodeDataBar14StackedOmni,
|
|
82
|
+
decodeDataBar14StackedOmni,
|
|
83
|
+
detectDataBar14StackedOmni,
|
|
84
|
+
} from './stacked-omnidirectional.js';
|
|
37
85
|
export { DATABAR14_CHECKSUM_WEIGHTS, DATABAR14_FINDERS, dataBar14CharacterWidths, dataBar14ValueForWidths, dataBarWidths, } from './patterns.js';
|
package/src/ts/databar/index.ts
CHANGED
|
@@ -59,6 +59,54 @@ export {
|
|
|
59
59
|
|
|
60
60
|
export { encodeDataBar14 } from './encoder.js';
|
|
61
61
|
export { decodeDataBar14, decodeDataBar14Scanline } from './decoder.js';
|
|
62
|
+
export {
|
|
63
|
+
encodeDataBarLimited,
|
|
64
|
+
decodeDataBarLimited,
|
|
65
|
+
detectDataBarLimited,
|
|
66
|
+
detectAndDecodeDataBarLimited,
|
|
67
|
+
decodeDataBarLimitedScanline,
|
|
68
|
+
} from './limited.js';
|
|
69
|
+
export {
|
|
70
|
+
encodeDataBarExpanded,
|
|
71
|
+
decodeDataBarExpanded,
|
|
72
|
+
detectDataBarExpanded,
|
|
73
|
+
detectAndDecodeDataBarExpanded,
|
|
74
|
+
decodeDataBarExpandedScanline,
|
|
75
|
+
encodeGS1DataBarExpanded,
|
|
76
|
+
decodeGS1DataBarExpanded,
|
|
77
|
+
detectGS1DataBarExpanded,
|
|
78
|
+
detectAndDecodeGS1DataBarExpanded,
|
|
79
|
+
} from './expanded.js';
|
|
80
|
+
export {
|
|
81
|
+
encodeDataBar14Stacked,
|
|
82
|
+
decodeDataBar14Stacked,
|
|
83
|
+
detectDataBar14Stacked,
|
|
84
|
+
detectAndDecodeDataBar14Stacked,
|
|
85
|
+
encodeDataBarStacked,
|
|
86
|
+
decodeDataBarStacked,
|
|
87
|
+
detectDataBarStacked,
|
|
88
|
+
detectAndDecodeDataBarStacked,
|
|
89
|
+
encodeGS1DataBarStacked,
|
|
90
|
+
decodeGS1DataBarStacked,
|
|
91
|
+
detectGS1DataBarStacked,
|
|
92
|
+
detectAndDecodeGS1DataBarStacked,
|
|
93
|
+
} from './stacked.js';
|
|
94
|
+
export {
|
|
95
|
+
encodeDataBarStackedOmnidirectional,
|
|
96
|
+
decodeDataBarStackedOmnidirectional,
|
|
97
|
+
detectDataBarStackedOmnidirectional,
|
|
98
|
+
detectAndDecodeDataBarStackedOmnidirectional,
|
|
99
|
+
encodeDataBarStackedOmni,
|
|
100
|
+
decodeDataBarStackedOmni,
|
|
101
|
+
detectDataBarStackedOmni,
|
|
102
|
+
detectAndDecodeDataBarStackedOmni,
|
|
103
|
+
encodeDataBar14StackedOmnidirectional,
|
|
104
|
+
decodeDataBar14StackedOmnidirectional,
|
|
105
|
+
detectDataBar14StackedOmnidirectional,
|
|
106
|
+
encodeDataBar14StackedOmni,
|
|
107
|
+
decodeDataBar14StackedOmni,
|
|
108
|
+
detectDataBar14StackedOmni,
|
|
109
|
+
} from './stacked-omnidirectional.js';
|
|
62
110
|
export {
|
|
63
111
|
DATABAR14_CHECKSUM_WEIGHTS,
|
|
64
112
|
DATABAR14_FINDERS,
|
|
@@ -0,0 +1,122 @@
|
|
|
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-License-Identifier: MIT
|
|
27
|
+
*
|
|
28
|
+
* Original work. No code from any other barcode implementation.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Structural descriptions for GS1 DataBar physical layouts.
|
|
33
|
+
*
|
|
34
|
+
* This module deliberately describes geometry only. It does not encode GTINs,
|
|
35
|
+
* construct finder patterns, or claim an interoperable writer for any DataBar
|
|
36
|
+
* variant. A later encoder can use the descriptor while keeping its payload
|
|
37
|
+
* and symbol-character rules in the codec layer.
|
|
38
|
+
*
|
|
39
|
+
* @module databar/layout
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* DataBar layout identifiers represented by this descriptor.
|
|
44
|
+
*
|
|
45
|
+
* `omnidirectional` and `stacked-omnidirectional` are retained as aliases for
|
|
46
|
+
* the longer names used by the existing DataBar-14 API. They describe the same
|
|
47
|
+
* structural family as `omni` and `stacked-omni`; no encoding is implied.
|
|
48
|
+
*/
|
|
49
|
+
export type DataBarLayoutId =
|
|
50
|
+
| 'omni'
|
|
51
|
+
| 'truncated'
|
|
52
|
+
| 'limited'
|
|
53
|
+
| 'stacked'
|
|
54
|
+
| 'stacked-omni'
|
|
55
|
+
| 'expanded'
|
|
56
|
+
| 'expanded-stacked'
|
|
57
|
+
| 'omnidirectional'
|
|
58
|
+
| 'stacked-omnidirectional';
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The immutable physical geometry and checksum metadata for one DataBar
|
|
62
|
+
* variant.
|
|
63
|
+
*
|
|
64
|
+
* `modulesPerRow` is the active symbol width. `rowHeight` is the active module
|
|
65
|
+
* height of each row, and `separatorModules` is the vertical gap between
|
|
66
|
+
* adjacent rows. `quietZone` is the margin on each outer side and is excluded
|
|
67
|
+
* from {@link dataBarTotalModules}; it is nevertheless included in the safe
|
|
68
|
+
* footprint checks. A one-row layout has no separator and therefore requires
|
|
69
|
+
* `separatorModules` to be zero.
|
|
70
|
+
*/
|
|
71
|
+
export interface DataBarLayout {
|
|
72
|
+
readonly id: DataBarLayoutId;
|
|
73
|
+
readonly rows: number;
|
|
74
|
+
readonly modulesPerRow: number;
|
|
75
|
+
readonly rowHeight: number;
|
|
76
|
+
readonly separatorModules: number;
|
|
77
|
+
readonly quietZone: number;
|
|
78
|
+
readonly linkage: boolean;
|
|
79
|
+
readonly checksumModulus: number;
|
|
80
|
+
readonly stacked: boolean;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Input accepted by {@link createDataBarLayout}. */
|
|
84
|
+
export type DataBarLayoutOptions = DataBarLayout;
|
|
85
|
+
|
|
86
|
+
/** Alias for callers that use input-oriented naming. */
|
|
87
|
+
export type DataBarLayoutInput = DataBarLayoutOptions;
|
|
88
|
+
|
|
89
|
+
/** Alias for code that calls the value a descriptor. */
|
|
90
|
+
export type DataBarLayoutDescriptor = DataBarLayout;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Return whether an unknown value is a valid DataBar physical layout.
|
|
94
|
+
*
|
|
95
|
+
* Validation is side-effect free and performs no matrix allocation. A value
|
|
96
|
+
* supplied by a caller may remain mutable; use {@link createDataBarLayout}
|
|
97
|
+
* when an immutable descriptor is required.
|
|
98
|
+
*/
|
|
99
|
+
export declare function validateDataBarLayout(value: unknown): value is DataBarLayout;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Create a validated, shallowly immutable DataBar layout descriptor.
|
|
103
|
+
*
|
|
104
|
+
* Only documented fields are copied. Unknown input properties are ignored so
|
|
105
|
+
* format-specific metadata cannot leak mutable state into the shared layout.
|
|
106
|
+
* This factory describes future physical variants but intentionally does not
|
|
107
|
+
* encode any payload.
|
|
108
|
+
*
|
|
109
|
+
* @throws {TypeError} If `options` is not an object.
|
|
110
|
+
* @throws {RangeError} If a field is invalid or the physical footprint exceeds
|
|
111
|
+
* the safe geometry budget.
|
|
112
|
+
*/
|
|
113
|
+
export declare function createDataBarLayout(options: DataBarLayoutOptions): DataBarLayout;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Count active module cells in all rows, including row separators and excluding
|
|
117
|
+
* the outer quiet zone. `rowHeight` is the number of module rows occupied by
|
|
118
|
+
* each active DataBar row.
|
|
119
|
+
*
|
|
120
|
+
* @throws {TypeError} If `layout` is not a valid descriptor.
|
|
121
|
+
*/
|
|
122
|
+
export declare function dataBarTotalModules(layout: DataBarLayout): number;
|
|
@@ -0,0 +1,275 @@
|
|
|
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-License-Identifier: MIT
|
|
27
|
+
*
|
|
28
|
+
* Original work. No code from any other barcode implementation.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Structural descriptions for GS1 DataBar physical layouts.
|
|
33
|
+
*
|
|
34
|
+
* This module deliberately describes geometry only. It does not encode GTINs,
|
|
35
|
+
* construct finder patterns, or claim an interoperable writer for any DataBar
|
|
36
|
+
* variant. A later encoder can use the descriptor while keeping its payload
|
|
37
|
+
* and symbol-character rules in the codec layer.
|
|
38
|
+
*
|
|
39
|
+
* @module databar/layout
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* DataBar layout identifiers represented by this descriptor.
|
|
44
|
+
*
|
|
45
|
+
* `omnidirectional` and `stacked-omnidirectional` are retained as aliases for
|
|
46
|
+
* the longer names used by the existing DataBar-14 API. They describe the same
|
|
47
|
+
* structural family as `omni` and `stacked-omni`; no encoding is implied.
|
|
48
|
+
*/
|
|
49
|
+
export type DataBarLayoutId =
|
|
50
|
+
| 'omni'
|
|
51
|
+
| 'truncated'
|
|
52
|
+
| 'limited'
|
|
53
|
+
| 'stacked'
|
|
54
|
+
| 'stacked-omni'
|
|
55
|
+
| 'expanded'
|
|
56
|
+
| 'expanded-stacked'
|
|
57
|
+
| 'omnidirectional'
|
|
58
|
+
| 'stacked-omnidirectional';
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The immutable physical geometry and checksum metadata for one DataBar
|
|
62
|
+
* variant.
|
|
63
|
+
*
|
|
64
|
+
* `modulesPerRow` is the active symbol width. `rowHeight` is the active module
|
|
65
|
+
* height of each row, and `separatorModules` is the vertical gap between
|
|
66
|
+
* adjacent rows. `quietZone` is the margin on each outer side and is excluded
|
|
67
|
+
* from {@link dataBarTotalModules}; it is nevertheless included in the safe
|
|
68
|
+
* footprint checks. A one-row layout has no separator and therefore requires
|
|
69
|
+
* `separatorModules` to be zero.
|
|
70
|
+
*/
|
|
71
|
+
export interface DataBarLayout {
|
|
72
|
+
readonly id: DataBarLayoutId;
|
|
73
|
+
readonly rows: number;
|
|
74
|
+
readonly modulesPerRow: number;
|
|
75
|
+
readonly rowHeight: number;
|
|
76
|
+
readonly separatorModules: number;
|
|
77
|
+
readonly quietZone: number;
|
|
78
|
+
readonly linkage: boolean;
|
|
79
|
+
readonly checksumModulus: number;
|
|
80
|
+
readonly stacked: boolean;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Input accepted by {@link createDataBarLayout}. */
|
|
84
|
+
export type DataBarLayoutOptions = DataBarLayout;
|
|
85
|
+
|
|
86
|
+
/** Alias for callers that use input-oriented naming. */
|
|
87
|
+
export type DataBarLayoutInput = DataBarLayoutOptions;
|
|
88
|
+
|
|
89
|
+
/** Alias for code that calls the value a descriptor. */
|
|
90
|
+
export type DataBarLayoutDescriptor = DataBarLayout;
|
|
91
|
+
|
|
92
|
+
/*
|
|
93
|
+
* These limits are intentionally conservative. They keep a future renderer
|
|
94
|
+
* from receiving dimensions that are technically safe JavaScript integers but
|
|
95
|
+
* impractical to materialise. No matrix is allocated by this module.
|
|
96
|
+
*/
|
|
97
|
+
const MAX_LAYOUT_DIMENSION = 32_768;
|
|
98
|
+
const MAX_LAYOUT_MODULES = 16_777_216;
|
|
99
|
+
|
|
100
|
+
const DATA_BAR_LAYOUT_IDS: readonly DataBarLayoutId[] = Object.freeze([
|
|
101
|
+
'omni',
|
|
102
|
+
'truncated',
|
|
103
|
+
'limited',
|
|
104
|
+
'stacked',
|
|
105
|
+
'stacked-omni',
|
|
106
|
+
'expanded',
|
|
107
|
+
'expanded-stacked',
|
|
108
|
+
'omnidirectional',
|
|
109
|
+
'stacked-omnidirectional',
|
|
110
|
+
]);
|
|
111
|
+
|
|
112
|
+
const STACKED_LAYOUT_IDS: readonly DataBarLayoutId[] = Object.freeze([
|
|
113
|
+
'stacked',
|
|
114
|
+
'stacked-omni',
|
|
115
|
+
'expanded-stacked',
|
|
116
|
+
'stacked-omnidirectional',
|
|
117
|
+
]);
|
|
118
|
+
|
|
119
|
+
const hasOwn = (value: object, property: string): boolean =>
|
|
120
|
+
Object.prototype.hasOwnProperty.call(value, property);
|
|
121
|
+
|
|
122
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
123
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function isBoundedPositiveInteger(value: unknown): value is number {
|
|
127
|
+
return typeof value === 'number'
|
|
128
|
+
&& Number.isSafeInteger(value)
|
|
129
|
+
&& value > 0
|
|
130
|
+
&& value <= MAX_LAYOUT_DIMENSION;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function isBoundedNonNegativeInteger(value: unknown): value is number {
|
|
134
|
+
return typeof value === 'number'
|
|
135
|
+
&& Number.isSafeInteger(value)
|
|
136
|
+
&& value >= 0
|
|
137
|
+
&& value <= MAX_LAYOUT_DIMENSION;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function isLayoutId(value: unknown): value is DataBarLayoutId {
|
|
141
|
+
return typeof value === 'string'
|
|
142
|
+
&& (DATA_BAR_LAYOUT_IDS as readonly string[]).includes(value);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function isStackedId(id: DataBarLayoutId): boolean {
|
|
146
|
+
return (STACKED_LAYOUT_IDS as readonly string[]).includes(id);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Calculate the active (quiet-zone-free) matrix dimensions for a descriptor.
|
|
151
|
+
* The result is safe because callers first pass the descriptor through the
|
|
152
|
+
* bounded validation checks.
|
|
153
|
+
*/
|
|
154
|
+
function activeHeight(layout: Pick<DataBarLayout, 'rows' | 'rowHeight' | 'separatorModules'>): number {
|
|
155
|
+
return layout.rows * layout.rowHeight
|
|
156
|
+
+ (layout.rows - 1) * layout.separatorModules;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Check that the descriptor can be materialised by a future renderer without
|
|
161
|
+
* exceeding the shared geometry budget.
|
|
162
|
+
*/
|
|
163
|
+
function isWithinModuleBudget(layout: Pick<
|
|
164
|
+
DataBarLayout,
|
|
165
|
+
'rows' | 'modulesPerRow' | 'rowHeight' | 'separatorModules' | 'quietZone'
|
|
166
|
+
>): boolean {
|
|
167
|
+
const height = activeHeight(layout);
|
|
168
|
+
const footprintWidth = layout.modulesPerRow + layout.quietZone * 2;
|
|
169
|
+
const footprintHeight = height + layout.quietZone * 2;
|
|
170
|
+
|
|
171
|
+
if (footprintWidth > MAX_LAYOUT_DIMENSION || footprintHeight > MAX_LAYOUT_DIMENSION) {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (footprintWidth > MAX_LAYOUT_MODULES / footprintHeight) return false;
|
|
176
|
+
return footprintWidth * footprintHeight <= MAX_LAYOUT_MODULES;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Return whether an unknown value is a valid DataBar physical layout.
|
|
181
|
+
*
|
|
182
|
+
* Validation is side-effect free and performs no matrix allocation. A value
|
|
183
|
+
* supplied by a caller may remain mutable; use {@link createDataBarLayout}
|
|
184
|
+
* when an immutable descriptor is required.
|
|
185
|
+
*/
|
|
186
|
+
export function validateDataBarLayout(value: unknown): value is DataBarLayout {
|
|
187
|
+
if (!isRecord(value)) return false;
|
|
188
|
+
|
|
189
|
+
if (!hasOwn(value, 'id') || !isLayoutId(value.id)) return false;
|
|
190
|
+
if (!hasOwn(value, 'rows') || !isBoundedPositiveInteger(value.rows)) return false;
|
|
191
|
+
if (!hasOwn(value, 'modulesPerRow') || !isBoundedPositiveInteger(value.modulesPerRow)) return false;
|
|
192
|
+
if (!hasOwn(value, 'rowHeight') || !isBoundedPositiveInteger(value.rowHeight)) return false;
|
|
193
|
+
if (!hasOwn(value, 'separatorModules') || !isBoundedNonNegativeInteger(value.separatorModules)) return false;
|
|
194
|
+
if (!hasOwn(value, 'quietZone') || !isBoundedPositiveInteger(value.quietZone)) return false;
|
|
195
|
+
if (!hasOwn(value, 'linkage') || typeof value.linkage !== 'boolean') return false;
|
|
196
|
+
if (!hasOwn(value, 'checksumModulus')
|
|
197
|
+
|| !isBoundedPositiveInteger(value.checksumModulus)
|
|
198
|
+
|| value.checksumModulus < 2) return false;
|
|
199
|
+
if (!hasOwn(value, 'stacked') || typeof value.stacked !== 'boolean') return false;
|
|
200
|
+
|
|
201
|
+
const rowsAreStacked = value.rows > 1;
|
|
202
|
+
if (value.stacked !== rowsAreStacked) return false;
|
|
203
|
+
if (isStackedId(value.id) !== value.stacked) return false;
|
|
204
|
+
if (!value.stacked && value.separatorModules !== 0) return false;
|
|
205
|
+
if (value.stacked && value.separatorModules < 1) return false;
|
|
206
|
+
|
|
207
|
+
return isWithinModuleBudget({
|
|
208
|
+
rows: value.rows,
|
|
209
|
+
modulesPerRow: value.modulesPerRow,
|
|
210
|
+
rowHeight: value.rowHeight,
|
|
211
|
+
separatorModules: value.separatorModules,
|
|
212
|
+
quietZone: value.quietZone,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Create a validated, shallowly immutable DataBar layout descriptor.
|
|
218
|
+
*
|
|
219
|
+
* Only documented fields are copied. Unknown input properties are ignored so
|
|
220
|
+
* format-specific metadata cannot leak mutable state into the shared layout.
|
|
221
|
+
* This factory describes future physical variants but intentionally does not
|
|
222
|
+
* encode any payload.
|
|
223
|
+
*
|
|
224
|
+
* @throws {TypeError} If `options` is not an object.
|
|
225
|
+
* @throws {RangeError} If a field is invalid or the physical footprint exceeds
|
|
226
|
+
* the safe geometry budget.
|
|
227
|
+
*/
|
|
228
|
+
export function createDataBarLayout(options: DataBarLayoutOptions): DataBarLayout {
|
|
229
|
+
if (!isRecord(options)) {
|
|
230
|
+
throw new TypeError('GS1 DataBar layout options must be an object');
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const descriptor: {
|
|
234
|
+
id: DataBarLayoutId;
|
|
235
|
+
rows: number;
|
|
236
|
+
modulesPerRow: number;
|
|
237
|
+
rowHeight: number;
|
|
238
|
+
separatorModules: number;
|
|
239
|
+
quietZone: number;
|
|
240
|
+
linkage: boolean;
|
|
241
|
+
checksumModulus: number;
|
|
242
|
+
stacked: boolean;
|
|
243
|
+
} = {
|
|
244
|
+
id: options.id as DataBarLayoutId,
|
|
245
|
+
rows: options.rows as number,
|
|
246
|
+
modulesPerRow: options.modulesPerRow as number,
|
|
247
|
+
rowHeight: options.rowHeight as number,
|
|
248
|
+
separatorModules: options.separatorModules as number,
|
|
249
|
+
quietZone: options.quietZone as number,
|
|
250
|
+
linkage: options.linkage as boolean,
|
|
251
|
+
checksumModulus: options.checksumModulus as number,
|
|
252
|
+
stacked: options.stacked as boolean,
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
if (!validateDataBarLayout(descriptor)) {
|
|
256
|
+
throw new RangeError('Invalid GS1 DataBar layout descriptor');
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return Object.freeze(descriptor);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Count active module cells in all rows, including row separators and excluding
|
|
264
|
+
* the outer quiet zone. `rowHeight` is the number of module rows occupied by
|
|
265
|
+
* each active DataBar row.
|
|
266
|
+
*
|
|
267
|
+
* @throws {TypeError} If `layout` is not a valid descriptor.
|
|
268
|
+
*/
|
|
269
|
+
export function dataBarTotalModules(layout: DataBarLayout): number {
|
|
270
|
+
if (!validateDataBarLayout(layout)) {
|
|
271
|
+
throw new TypeError('Cannot count modules for an invalid GS1 DataBar layout');
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return layout.modulesPerRow * activeHeight(layout);
|
|
275
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Sythos Barcode Suite
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2026 Sythos
|
|
7
|
+
* SPDX-FileCopyrightText: 2026 Sythos (https://www.sythos.net)
|
|
8
|
+
* SPDX-License-Identifier: MIT
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { BitMatrix } from '../core/bit-matrix.js';
|
|
12
|
+
|
|
13
|
+
export interface DataBarLimitedEncodeOptions {
|
|
14
|
+
linkage?: boolean;
|
|
15
|
+
/** Integer module scale; `scale` is accepted as an alias. */
|
|
16
|
+
moduleScale?: number;
|
|
17
|
+
scale?: number;
|
|
18
|
+
/** Output height in modules; the minimum is ten modules per row. */
|
|
19
|
+
height?: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface DataBarLimitedElement {
|
|
23
|
+
readonly ai: '01';
|
|
24
|
+
readonly value: string;
|
|
25
|
+
readonly fixed: true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface DataBarLimitedDecodeResult {
|
|
29
|
+
readonly format: 'databar-limited';
|
|
30
|
+
readonly variant: 'limited';
|
|
31
|
+
readonly text: string;
|
|
32
|
+
readonly gtin: string;
|
|
33
|
+
readonly gs1: true;
|
|
34
|
+
readonly linkage: boolean;
|
|
35
|
+
readonly checksum: number;
|
|
36
|
+
readonly checksumValid: true;
|
|
37
|
+
readonly moduleScale: number;
|
|
38
|
+
readonly height: number;
|
|
39
|
+
readonly symbologyIdentifier: ']e0';
|
|
40
|
+
readonly elements: readonly [DataBarLimitedElement];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface DataBarLimitedDetection extends DataBarLimitedDecodeResult {
|
|
44
|
+
readonly result: DataBarLimitedDecodeResult;
|
|
45
|
+
readonly matrix: BitMatrix;
|
|
46
|
+
readonly corners: readonly [
|
|
47
|
+
{ readonly x: number; readonly y: number },
|
|
48
|
+
{ readonly x: number; readonly y: number },
|
|
49
|
+
{ readonly x: number; readonly y: number },
|
|
50
|
+
{ readonly x: number; readonly y: number },
|
|
51
|
+
];
|
|
52
|
+
readonly rotation: 0 | 90 | 180 | 270;
|
|
53
|
+
readonly moduleSize: number;
|
|
54
|
+
readonly confidence: 1;
|
|
55
|
+
readonly quality: {
|
|
56
|
+
readonly quietZone: boolean;
|
|
57
|
+
readonly checksum: true;
|
|
58
|
+
readonly rows: 1;
|
|
59
|
+
readonly consistency: 1;
|
|
60
|
+
};
|
|
61
|
+
readonly score: 1;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Encode a checked GTIN as GS1 DataBar Limited. */
|
|
65
|
+
export declare function encodeDataBarLimited(
|
|
66
|
+
value: string | number,
|
|
67
|
+
options?: DataBarLimitedEncodeOptions,
|
|
68
|
+
): BitMatrix;
|
|
69
|
+
|
|
70
|
+
/** Decode a complete, clean or integer-scaled Limited symbol. */
|
|
71
|
+
export declare function decodeDataBarLimited(matrix: BitMatrix): DataBarLimitedDecodeResult;
|
|
72
|
+
|
|
73
|
+
/** Detect one complete Limited symbol in a binary raster. */
|
|
74
|
+
export declare function detectDataBarLimited(
|
|
75
|
+
binaryImage: BitMatrix,
|
|
76
|
+
options?: object,
|
|
77
|
+
): DataBarLimitedDetection | null;
|
|
78
|
+
|
|
79
|
+
/** Detect and decode one Limited symbol, or return null. */
|
|
80
|
+
export declare const detectAndDecodeDataBarLimited: typeof detectDataBarLimited;
|
|
81
|
+
|
|
82
|
+
/** Decode a complete 79-module scanline, or return null for invalid input. */
|
|
83
|
+
export declare function decodeDataBarLimitedScanline(
|
|
84
|
+
row: ArrayLike<number | boolean>,
|
|
85
|
+
): DataBarLimitedDecodeResult | null;
|