@node-projects/web-component-designer-zpl 0.2.1 → 0.3.2
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/README.md +16 -2
- package/THIRD-PARTY-LICENSES.md +432 -0
- package/dist/assets/fonts/LICENSE-APACHE-2.0.txt +202 -0
- package/dist/assets/fonts/NOTICE.md +27 -0
- package/dist/assets/fonts/OCRA-NOTICE.md +27 -0
- package/dist/assets/fonts/OCRA.ttf +0 -0
- package/dist/assets/fonts/OCRB-NOTICE.md +21 -0
- package/dist/assets/fonts/OCRB.ttf +0 -0
- package/dist/assets/fonts/PrintLabMono-NOTICE.md +24 -0
- package/dist/assets/fonts/PrintLabMono.ttf +0 -0
- package/dist/assets/fonts/PrintLabZPL-Bold.ttf +0 -0
- package/dist/assets/fonts/PrintLabZPL-Bold.woff2 +0 -0
- package/dist/assets/fonts/VeraMono-Bold.ttf +0 -0
- package/dist/assets/fonts/VeraMono-NOTICE.md +57 -0
- package/dist/assets/fonts/VeraMono.ttf +0 -0
- package/dist/assets/licenses/BWIP-JS-LICENSE.txt +23 -0
- package/dist/assets/licenses/ZPLab-LICENSE.txt +21 -0
- package/dist/barcodes/barcodeRegistry.d.ts +124 -0
- package/dist/barcodes/barcodeRegistry.js +357 -0
- package/dist/barcodes/bwipRenderer.d.ts +90 -0
- package/dist/barcodes/bwipRenderer.js +630 -0
- package/dist/fonts/zplFonts.d.ts +27 -0
- package/dist/fonts/zplFonts.js +85 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.js +10 -3
- package/dist/services/ZplBarcodeElementsService.d.ts +5 -0
- package/dist/services/ZplBarcodeElementsService.js +16 -0
- package/dist/services/ZplBarcodePropertiesService.d.ts +10 -0
- package/dist/services/ZplBarcodePropertiesService.js +59 -0
- package/dist/services/ZplDiagonalLineExtension.d.ts +46 -0
- package/dist/services/ZplDiagonalLineExtension.js +255 -0
- package/dist/services/ZplElementResizeStrategy.d.ts +20 -0
- package/dist/services/ZplElementResizeStrategy.js +182 -0
- package/dist/services/ZplGraphicResizeStrategy.d.ts +18 -0
- package/dist/services/ZplGraphicResizeStrategy.js +81 -0
- package/dist/services/ZplIncludeInOutputPropertiesService.d.ts +12 -0
- package/dist/services/ZplIncludeInOutputPropertiesService.js +50 -0
- package/dist/services/ZplParserService.d.ts +7 -4
- package/dist/services/ZplParserService.js +214 -249
- package/dist/services/ZplSelectionExtensionProvider.d.ts +9 -0
- package/dist/services/ZplSelectionExtensionProvider.js +15 -0
- package/dist/services/ZplTextEditExtension.d.ts +20 -0
- package/dist/services/ZplTextEditExtension.js +80 -0
- package/dist/services/ZplTextPropertiesService.d.ts +8 -0
- package/dist/services/ZplTextPropertiesService.js +24 -0
- package/dist/services/hiddenMetadata.d.ts +17 -0
- package/dist/services/hiddenMetadata.js +95 -0
- package/dist/services/zplResizeGeometry.d.ts +6 -0
- package/dist/services/zplResizeGeometry.js +8 -0
- package/dist/setupZplServiceContainer.js +22 -4
- package/dist/widgets/elements.json +0 -24
- package/dist/widgets/views/zpl-demo-view.js +27 -2
- package/dist/widgets/zpl-barcode.d.ts +68 -14
- package/dist/widgets/zpl-barcode.js +189 -74
- package/dist/widgets/zpl-comment.d.ts +2 -0
- package/dist/widgets/zpl-comment.js +6 -3
- package/dist/widgets/zpl-graphic-box.d.ts +12 -0
- package/dist/widgets/zpl-graphic-box.js +49 -15
- package/dist/widgets/zpl-graphic-circle.d.ts +2 -0
- package/dist/widgets/zpl-graphic-circle.js +7 -0
- package/dist/widgets/zpl-graphic-diagonal-line.d.ts +2 -0
- package/dist/widgets/zpl-graphic-diagonal-line.js +7 -0
- package/dist/widgets/zpl-image.d.ts +4 -1
- package/dist/widgets/zpl-image.js +17 -14
- package/dist/widgets/zpl-text.d.ts +38 -8
- package/dist/widgets/zpl-text.js +183 -49
- package/dist/zplHelper.d.ts +1 -1
- package/dist/zplHelper.js +5 -1
- package/package.json +9 -4
- package/dist/extensions/ZplLayoutResizeExtensionProvider.d.ts +0 -4
- package/dist/extensions/ZplLayoutResizeExtensionProvider.js +0 -16
- package/dist/jsBarcodeOptions.d.ts +0 -27
- package/dist/jsBarcodeOptions.js +0 -14
- package/dist/qr.d.ts +0 -11
- package/dist/qr.js +0 -759
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
export const barcodeTypes = [
|
|
2
|
+
'code128', 'code39', 'code93', 'code11', 'interleaved2of5', 'standard2of5',
|
|
3
|
+
'industrial2of5', 'codabar', 'logmars', 'msi', 'plessey', 'gs1databar',
|
|
4
|
+
'planet', 'postnet', 'ean13', 'ean8', 'upca', 'upce', 'upceanextension',
|
|
5
|
+
'code49', 'qrcode', 'datamatrix', 'pdf417', 'micropdf417', 'aztec',
|
|
6
|
+
'codablock', 'maxicode', 'tlc39'
|
|
7
|
+
];
|
|
8
|
+
export const dataMatrixSquareSizes = Object.freeze([
|
|
9
|
+
10, 12, 14, 16, 18, 20, 22, 24, 26, 32, 36, 40, 44, 48, 52,
|
|
10
|
+
64, 72, 80, 88, 96, 104, 120, 132, 144
|
|
11
|
+
]);
|
|
12
|
+
export const dataMatrixRectangularSizes = Object.freeze([
|
|
13
|
+
[8, 18], [8, 32], [12, 26], [12, 36], [16, 36], [16, 48]
|
|
14
|
+
]);
|
|
15
|
+
export function isDataMatrixRectangular(props) {
|
|
16
|
+
return props.quality === 200 && props.aspectRatio === 2;
|
|
17
|
+
}
|
|
18
|
+
/** Returns a BWIP version only for a symbol size Zebra accepts for ECC 200. */
|
|
19
|
+
export function getDataMatrixVersion(props) {
|
|
20
|
+
if (props.quality !== 200 || !props.columns || !props.rows)
|
|
21
|
+
return undefined;
|
|
22
|
+
const valid = isDataMatrixRectangular(props)
|
|
23
|
+
? dataMatrixRectangularSizes.some(([rows, columns]) => rows === props.rows && columns === props.columns)
|
|
24
|
+
: props.rows === props.columns && dataMatrixSquareSizes.includes(props.rows);
|
|
25
|
+
return valid ? `${props.rows}x${props.columns}` : undefined;
|
|
26
|
+
}
|
|
27
|
+
const p = {
|
|
28
|
+
content: { name: 'content', attributeName: 'content', type: 'string' },
|
|
29
|
+
rotation: { name: 'rotation', attributeName: 'rotation', type: 'enum', values: ['N', 'R', 'I', 'B'] },
|
|
30
|
+
moduleWidth: { name: 'moduleWidth', attributeName: 'module-width', type: 'number', min: 1, max: 10, step: 1 },
|
|
31
|
+
wideRatio: { name: 'wideRatio', attributeName: 'wide-ratio', type: 'number', min: 2, max: 3, step: 0.1 },
|
|
32
|
+
barHeight: { name: 'barHeight', attributeName: 'bar-height', type: 'number', min: 1, max: 32000, step: 1 },
|
|
33
|
+
printInterpretation: { name: 'printInterpretation', attributeName: 'print-interpretation', type: 'boolean' },
|
|
34
|
+
printInterpretationAbove: { name: 'printInterpretationAbove', attributeName: 'print-interpretation-above', type: 'boolean' },
|
|
35
|
+
checkDigit: { name: 'checkDigit', attributeName: 'check-digit', type: 'boolean' },
|
|
36
|
+
magnification: { name: 'magnification', attributeName: 'magnification', type: 'number', min: 1, max: 10, step: 1 },
|
|
37
|
+
rowHeight: { name: 'rowHeight', attributeName: 'row-height', type: 'number', min: 1, max: 9999, step: 1 },
|
|
38
|
+
columns: { name: 'columns', attributeName: 'columns', type: 'number', min: 0, max: 62, step: 1 },
|
|
39
|
+
mode: { name: 'mode', attributeName: 'mode', type: 'number', min: 0, max: 300, step: 1 },
|
|
40
|
+
};
|
|
41
|
+
const bool = (value) => value ? 'Y' : 'N';
|
|
42
|
+
const number = (value, fallback) => {
|
|
43
|
+
const parsed = Number(value);
|
|
44
|
+
return Number.isFinite(parsed) ? parsed : fallback;
|
|
45
|
+
};
|
|
46
|
+
const rotation = (value) => value === 'R' || value === 'I' || value === 'B' ? value : 'N';
|
|
47
|
+
const yes = (value, fallback = false) => value == null || value === '' ? fallback : value === 'Y';
|
|
48
|
+
const commonLinearDefaults = {
|
|
49
|
+
moduleWidth: 2, wideRatio: 3, barHeight: 100, printInterpretation: true,
|
|
50
|
+
printInterpretationAbove: false, checkDigit: false, mode: 'A', gs1: false
|
|
51
|
+
};
|
|
52
|
+
const linearGeometryProperties = [p.content, p.rotation, p.moduleWidth, p.wideRatio, p.barHeight];
|
|
53
|
+
const linearHriProperties = [...linearGeometryProperties,
|
|
54
|
+
p.printInterpretation, p.printInterpretationAbove];
|
|
55
|
+
const linearProperties = [...linearHriProperties,
|
|
56
|
+
p.checkDigit];
|
|
57
|
+
function validateProps(props) {
|
|
58
|
+
const definition = getBarcodeDefinition(props.type);
|
|
59
|
+
if (!String(props.content ?? '').length)
|
|
60
|
+
return 'content is required';
|
|
61
|
+
for (const property of definition.properties) {
|
|
62
|
+
if (property.type !== 'number')
|
|
63
|
+
continue;
|
|
64
|
+
const value = Number(props[property.name]);
|
|
65
|
+
if (!Number.isFinite(value))
|
|
66
|
+
return `${property.name} must be a number`;
|
|
67
|
+
if (property.min != null && value < property.min)
|
|
68
|
+
return `${property.name} must be at least ${property.min}`;
|
|
69
|
+
if (property.max != null && value > property.max)
|
|
70
|
+
return `${property.name} must be at most ${property.max}`;
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
function validatePostnet(props) {
|
|
75
|
+
const common = validateProps(props);
|
|
76
|
+
if (common)
|
|
77
|
+
return common;
|
|
78
|
+
return /^\d+$/.test(props.content) ? null : 'POSTNET content must contain digits only';
|
|
79
|
+
}
|
|
80
|
+
function validateDataMatrix(props) {
|
|
81
|
+
const common = validateProps(props);
|
|
82
|
+
if (common)
|
|
83
|
+
return common;
|
|
84
|
+
const value = props;
|
|
85
|
+
if (![0, 50, 80, 100, 140, 200].includes(value.quality))
|
|
86
|
+
return 'quality is not supported';
|
|
87
|
+
if ((value.columns === 0) !== (value.rows === 0))
|
|
88
|
+
return 'rows and columns must both be zero or both be set';
|
|
89
|
+
if (value.columns > 0 && value.quality === 200 && !getDataMatrixVersion(value))
|
|
90
|
+
return `rows and columns are not a valid ${isDataMatrixRectangular(value) ? 'rectangular' : 'square'} ECC 200 size`;
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
function validateTlc39(props) {
|
|
94
|
+
const common = validateProps(props);
|
|
95
|
+
if (common)
|
|
96
|
+
return common;
|
|
97
|
+
const [eci, serial = ''] = props.content.split(',', 2);
|
|
98
|
+
if (!/^\d{6}$/.test(eci))
|
|
99
|
+
return 'TLC39 ECI must contain exactly six digits';
|
|
100
|
+
if (!/^[0-9A-Z ]{0,25}$/i.test(serial))
|
|
101
|
+
return 'TLC39 serial must contain at most 25 alphanumeric characters';
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
function linearDefinition(type, label, command, bcid, defaultContent, syntax = 'height', overrides = {}, fixedByRatio) {
|
|
105
|
+
const emit = (props) => {
|
|
106
|
+
const v = props;
|
|
107
|
+
let params;
|
|
108
|
+
switch (syntax) {
|
|
109
|
+
case 'check-first':
|
|
110
|
+
params = `${v.rotation},${bool(v.checkDigit)},${v.barHeight},${bool(v.printInterpretation)},${bool(v.printInterpretationAbove)}`;
|
|
111
|
+
break;
|
|
112
|
+
case 'height-check-last':
|
|
113
|
+
params = `${v.rotation},${v.barHeight},${bool(v.printInterpretation)},${bool(v.printInterpretationAbove)},${bool(v.checkDigit)}`;
|
|
114
|
+
break;
|
|
115
|
+
case 'logmars':
|
|
116
|
+
params = `${v.rotation},${v.barHeight},${bool(v.printInterpretation)}`;
|
|
117
|
+
break;
|
|
118
|
+
case 'msi':
|
|
119
|
+
params = `${v.rotation},${v.checkDigit ? (['B', 'C', 'D'].includes(v.mode) ? v.mode : 'B') : 'A'},${v.barHeight},${bool(v.printInterpretation)},${bool(v.printInterpretationAbove)}`;
|
|
120
|
+
break;
|
|
121
|
+
case 'code49':
|
|
122
|
+
params = `${v.rotation},${v.barHeight},${bool(v.printInterpretation)},${v.mode || 'A'}`;
|
|
123
|
+
break;
|
|
124
|
+
case 'code128':
|
|
125
|
+
params = `${v.rotation},${v.barHeight},${bool(v.printInterpretation)},${bool(v.printInterpretationAbove)},${bool(v.checkDigit)}${v.gs1 ? ',D' : ''}`;
|
|
126
|
+
break;
|
|
127
|
+
case 'upca':
|
|
128
|
+
params = `${v.rotation},${v.barHeight},${bool(v.printInterpretation)},${bool(v.printInterpretationAbove)},Y`;
|
|
129
|
+
break;
|
|
130
|
+
default:
|
|
131
|
+
params = `${v.rotation},${v.barHeight},${bool(v.printInterpretation)},${bool(v.printInterpretationAbove)}`;
|
|
132
|
+
}
|
|
133
|
+
const by = fixedByRatio === null ? `^BY${v.moduleWidth}` : `^BY${v.moduleWidth},${fixedByRatio ?? v.wideRatio}`;
|
|
134
|
+
return { by, command: `^${command}${params}`, fieldData: v.content };
|
|
135
|
+
};
|
|
136
|
+
const parse = (fields, by) => {
|
|
137
|
+
const result = { ...commonLinearDefaults, moduleWidth: by.moduleWidth, wideRatio: fixedByRatio ?? by.wideRatio };
|
|
138
|
+
if (syntax === 'check-first') {
|
|
139
|
+
Object.assign(result, { rotation: rotation(fields[0]), checkDigit: yes(fields[1]), barHeight: number(fields[2], by.barHeight), printInterpretation: yes(fields[3], true), printInterpretationAbove: yes(fields[4]) });
|
|
140
|
+
}
|
|
141
|
+
else if (syntax === 'height-check-last') {
|
|
142
|
+
Object.assign(result, { rotation: rotation(fields[0]), barHeight: number(fields[1], by.barHeight), printInterpretation: yes(fields[2], true), printInterpretationAbove: yes(fields[3]), checkDigit: yes(fields[4]) });
|
|
143
|
+
}
|
|
144
|
+
else if (syntax === 'msi') {
|
|
145
|
+
Object.assign(result, { rotation: rotation(fields[0]), checkDigit: fields[1] !== 'A', mode: fields[1] || 'A', barHeight: number(fields[2], by.barHeight), printInterpretation: yes(fields[3], true), printInterpretationAbove: yes(fields[4]) });
|
|
146
|
+
}
|
|
147
|
+
else if (syntax === 'code49') {
|
|
148
|
+
Object.assign(result, { rotation: rotation(fields[0]), barHeight: number(fields[1], 20), printInterpretation: yes(fields[2], true), mode: fields[3] || 'A' });
|
|
149
|
+
}
|
|
150
|
+
else if (syntax === 'code128') {
|
|
151
|
+
Object.assign(result, { rotation: rotation(fields[0]), barHeight: number(fields[1], by.barHeight), printInterpretation: yes(fields[2], true), printInterpretationAbove: yes(fields[3]), checkDigit: yes(fields[4]), gs1: fields[5] === 'D' });
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
Object.assign(result, { rotation: rotation(fields[0]), barHeight: number(fields[1], by.barHeight), printInterpretation: yes(fields[2], true), printInterpretationAbove: yes(fields[3]) });
|
|
155
|
+
}
|
|
156
|
+
return result;
|
|
157
|
+
};
|
|
158
|
+
return {
|
|
159
|
+
type, label, command, bcid, resizeKind: 'linear', defaultContent,
|
|
160
|
+
defaults: { ...commonLinearDefaults }, properties: linearProperties, validate: validateProps, emit, parse,
|
|
161
|
+
...overrides
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
const definitions = [
|
|
165
|
+
linearDefinition('code128', 'Code 128', 'BC', 'code128', 'CODE128', 'code128', {
|
|
166
|
+
properties: [...linearProperties, { name: 'gs1', attributeName: 'gs1', type: 'boolean' }]
|
|
167
|
+
}),
|
|
168
|
+
linearDefinition('code39', 'Code 39', 'B3', 'code39', 'CODE39', 'check-first'),
|
|
169
|
+
linearDefinition('code93', 'Code 93', 'BA', 'code93', 'CODE93', 'height-check-last'),
|
|
170
|
+
linearDefinition('code11', 'Code 11', 'B1', 'code11', '12345', 'check-first'),
|
|
171
|
+
linearDefinition('interleaved2of5', 'Interleaved 2 of 5', 'B2', 'interleaved2of5', '12345678', 'height-check-last'),
|
|
172
|
+
linearDefinition('standard2of5', 'Standard 2 of 5', 'BJ', 'iata2of5', '12345678', 'height', { properties: linearHriProperties }),
|
|
173
|
+
linearDefinition('industrial2of5', 'Industrial 2 of 5', 'BI', 'industrial2of5', '12345678', 'height', { properties: linearHriProperties }),
|
|
174
|
+
linearDefinition('codabar', 'Codabar', 'BK', 'rationalizedCodabar', 'A12345A', 'check-first'),
|
|
175
|
+
linearDefinition('logmars', 'LOGMARS', 'BL', 'code39', 'LOGMARS1', 'logmars', {
|
|
176
|
+
properties: [...linearGeometryProperties, p.printInterpretation]
|
|
177
|
+
}),
|
|
178
|
+
linearDefinition('msi', 'MSI', 'BM', 'msi', '12345678', 'msi', {
|
|
179
|
+
defaults: { ...commonLinearDefaults, wideRatio: 2 },
|
|
180
|
+
properties: [p.content, p.rotation, p.moduleWidth, p.barHeight, p.printInterpretation,
|
|
181
|
+
p.printInterpretationAbove, p.checkDigit,
|
|
182
|
+
{ name: 'mode', attributeName: 'mode', type: 'enum', values: ['B', 'C', 'D'] }]
|
|
183
|
+
}, 2),
|
|
184
|
+
linearDefinition('plessey', 'Plessey', 'BP', 'plessey', '12345678', 'check-first', {
|
|
185
|
+
defaults: { ...commonLinearDefaults, wideRatio: 2 },
|
|
186
|
+
properties: [p.content, p.rotation, p.moduleWidth, p.barHeight,
|
|
187
|
+
p.printInterpretation, p.printInterpretationAbove, p.checkDigit]
|
|
188
|
+
}, 2),
|
|
189
|
+
{
|
|
190
|
+
type: 'gs1databar', label: 'GS1 DataBar', command: 'BR', bcid: 'databaromni', resizeKind: 'intrinsic', defaultContent: '0112345678901',
|
|
191
|
+
defaults: { magnification: 2, symbology: 1, segments: 22 },
|
|
192
|
+
properties: [p.content, p.rotation, p.magnification,
|
|
193
|
+
{ name: 'symbology', attributeName: 'symbology', type: 'number', min: 1, max: 7, step: 1 },
|
|
194
|
+
{ name: 'segments', attributeName: 'segments', type: 'number', min: 2, max: 22, step: 2 }],
|
|
195
|
+
validate: validateProps,
|
|
196
|
+
fieldOriginOffset: rotation => rotation === 'N' ? { x: -2, y: 0 }
|
|
197
|
+
: rotation === 'R' ? { x: 0, y: -2 }
|
|
198
|
+
: rotation === 'I' ? { x: 2, y: 0 } : { x: 0, y: 2 },
|
|
199
|
+
emit: props => { const v = props; return { by: `^BY${v.magnification}`, command: `^BR${v.rotation},${v.symbology},${v.magnification},2,100${v.symbology === 7 ? `,${v.segments}` : ''}`, fieldData: v.content }; },
|
|
200
|
+
parse: (f, by) => ({ rotation: rotation(f[0]), symbology: number(f[1], 1), magnification: number(f[2], by.moduleWidth), segments: number(f[5], 22) })
|
|
201
|
+
},
|
|
202
|
+
linearDefinition('planet', 'Planet Code', 'B5', 'planet', '12345678901', 'height', { properties: linearHriProperties }),
|
|
203
|
+
linearDefinition('postnet', 'POSTNET', 'BZ', 'postnet', '12345', 'height', {
|
|
204
|
+
properties: [p.content, p.rotation, p.moduleWidth, p.barHeight,
|
|
205
|
+
p.printInterpretation, p.printInterpretationAbove],
|
|
206
|
+
validate: validatePostnet
|
|
207
|
+
}, null),
|
|
208
|
+
linearDefinition('ean13', 'EAN-13', 'BE', 'ean13', '590123412345', 'height', { properties: linearHriProperties }),
|
|
209
|
+
linearDefinition('ean8', 'EAN-8', 'B8', 'ean8', '1234567', 'height', { properties: linearHriProperties }),
|
|
210
|
+
linearDefinition('upca', 'UPC-A', 'BU', 'upca', '01234567890', 'upca', { properties: linearHriProperties }),
|
|
211
|
+
linearDefinition('upce', 'UPC-E', 'B9', 'upce', '012345', 'height', { properties: linearHriProperties }),
|
|
212
|
+
linearDefinition('upceanextension', 'UPC/EAN supplement', 'BS', 'ean5', '51999', 'logmars', {
|
|
213
|
+
properties: [...linearGeometryProperties, p.printInterpretation]
|
|
214
|
+
}),
|
|
215
|
+
linearDefinition('code49', 'Code 49', 'B4', 'code49', 'CODE49', 'code49', {
|
|
216
|
+
defaults: { ...commonLinearDefaults, barHeight: 20, mode: 'A' },
|
|
217
|
+
properties: [p.content, p.rotation, p.moduleWidth, p.barHeight, p.printInterpretation,
|
|
218
|
+
{ name: 'mode', attributeName: 'mode', type: 'enum', values: ['A', '0', '1', '2', '3', '4', '5'] }]
|
|
219
|
+
}, null),
|
|
220
|
+
{
|
|
221
|
+
type: 'qrcode', label: 'QR Code', command: 'BQ', bcid: 'qrcode', resizeKind: 'uniform-2d', defaultContent: 'https://example.com',
|
|
222
|
+
defaults: { magnification: 4, errorCorrection: 'Q', model: 2 },
|
|
223
|
+
properties: [p.content, p.rotation, p.magnification,
|
|
224
|
+
{ name: 'errorCorrection', attributeName: 'error-correction', type: 'enum', values: ['H', 'Q', 'M', 'L'] },
|
|
225
|
+
{ name: 'model', attributeName: 'model', type: 'number', min: 1, max: 2, step: 1 }],
|
|
226
|
+
validate: validateProps,
|
|
227
|
+
// Zebra-compatible renderers place QR ink ten dots below ^FO for N and
|
|
228
|
+
// ten dots right of ^FO for B. Compensate in output so designer bounds
|
|
229
|
+
// continue to describe the visible symbol.
|
|
230
|
+
fieldOriginOffset: rotation => rotation === 'N' ? { x: 0, y: -10 }
|
|
231
|
+
: rotation === 'B' ? { x: -10, y: 0 } : { x: 0, y: 0 },
|
|
232
|
+
emit: props => { const v = props; return { command: `^BQ${v.rotation},${v.model},${v.magnification}`, fieldData: `${v.errorCorrection}A,${v.content}` }; },
|
|
233
|
+
parse: f => ({ rotation: rotation(f[0]), model: number(f[1], 2), magnification: number(f[2], 4) })
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
type: 'datamatrix', label: 'DataMatrix', command: 'BX', bcid: 'datamatrix', resizeKind: 'uniform-2d', defaultContent: '1234567890',
|
|
237
|
+
defaults: { dimension: 5, quality: 200, columns: 0, rows: 0, gs1: false, aspectRatio: 1 },
|
|
238
|
+
properties: [p.content, p.rotation, { name: 'dimension', attributeName: 'dimension', type: 'number', min: 1, max: 12, step: 1 },
|
|
239
|
+
{ name: 'quality', attributeName: 'quality', type: 'enum', values: ['0', '50', '80', '100', '140', '200'] }, p.columns,
|
|
240
|
+
{ name: 'rows', attributeName: 'rows', type: 'number', min: 0, max: 144, step: 1 },
|
|
241
|
+
{ name: 'gs1', attributeName: 'gs1', type: 'boolean' },
|
|
242
|
+
{ name: 'aspectRatio', attributeName: 'aspect-ratio', type: 'number', min: 1, max: 2, step: 1 }],
|
|
243
|
+
validate: validateDataMatrix,
|
|
244
|
+
emit: props => { const v = props; const args = [v.rotation, v.dimension, v.quality, v.columns || '', v.rows || '', '', v.gs1 ? '_' : '', isDataMatrixRectangular(v) ? 2 : '']; while (args.at(-1) === '')
|
|
245
|
+
args.pop(); return { command: `^BX${args.join(',')}`, fieldData: v.content }; },
|
|
246
|
+
parse: f => ({ rotation: rotation(f[0]), dimension: number(f[1], 5), quality: number(f[2], 200), columns: number(f[3], 0), rows: number(f[4], 0), gs1: !!f[6], aspectRatio: number(f[7], 1) })
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
type: 'pdf417', label: 'PDF417', command: 'B7', bcid: 'pdf417', resizeKind: 'stacked-2d', defaultContent: '1234567890',
|
|
250
|
+
defaults: { moduleWidth: 2, rowHeight: 2, securityLevel: 0, columns: 0, mode: 0 },
|
|
251
|
+
properties: [p.content, p.rotation, { ...p.moduleWidth, min: 2 }, p.rowHeight,
|
|
252
|
+
{ name: 'securityLevel', attributeName: 'security-level', type: 'number', min: 0, max: 8, step: 1 },
|
|
253
|
+
{ ...p.columns, max: 30 }],
|
|
254
|
+
validate: validateProps,
|
|
255
|
+
emit: props => { const v = props; return { by: `^BY${v.moduleWidth}`, command: `^B7${v.rotation},${v.rowHeight},${v.securityLevel},${v.columns},,,`, fieldData: v.content }; },
|
|
256
|
+
parse: (f, by) => ({ rotation: rotation(f[0]), moduleWidth: by.moduleWidth, rowHeight: number(f[1], 2), securityLevel: number(f[2], 0), columns: number(f[3], 0) })
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
type: 'micropdf417', label: 'MicroPDF417', command: 'BF', bcid: 'micropdf417', resizeKind: 'stacked-2d', defaultContent: '1234',
|
|
260
|
+
defaults: { moduleWidth: 2, rowHeight: 2, securityLevel: 0, columns: 0, mode: 0 },
|
|
261
|
+
properties: [p.content, p.rotation, p.moduleWidth, p.rowHeight, { ...p.mode, max: 33 }],
|
|
262
|
+
validate: validateProps,
|
|
263
|
+
emit: props => { const v = props; return { by: `^BY${v.moduleWidth}`, command: `^BF${v.rotation},${v.rowHeight},${v.mode}`, fieldData: v.content }; },
|
|
264
|
+
parse: (f, by) => ({ rotation: rotation(f[0]), moduleWidth: by.moduleWidth, rowHeight: number(f[1], 2), mode: number(f[2], 0) })
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
type: 'aztec', label: 'Aztec', command: 'B0', bcid: 'azteccodecompact', resizeKind: 'uniform-2d', defaultContent: '1234567890',
|
|
268
|
+
defaults: { magnification: 4, ecLevel: 0 }, properties: [p.content, p.rotation, p.magnification,
|
|
269
|
+
{ name: 'ecLevel', attributeName: 'ec-level', type: 'number', min: 0, max: 300, step: 1 }],
|
|
270
|
+
validate: validateProps,
|
|
271
|
+
emit: props => { const v = props; return { command: `^B0${v.rotation},${v.magnification},N,${v.ecLevel}`, fieldData: v.content }; },
|
|
272
|
+
parse: f => ({ rotation: rotation(f[0]), magnification: number(f[1], 4), ecLevel: number(f[3], 0) })
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
type: 'codablock', label: 'CODABLOCK', command: 'BB', bcid: 'codablockf', resizeKind: 'stacked-2d', defaultContent: 'CODABLOCK',
|
|
276
|
+
defaults: { moduleWidth: 2, rowHeight: 2, securityLevel: 'Y', columns: 6, mode: 0 },
|
|
277
|
+
properties: [p.content, p.rotation, { ...p.moduleWidth, min: 2 }, p.rowHeight,
|
|
278
|
+
{ name: 'securityLevel', attributeName: 'security-level', type: 'enum', values: ['Y', 'N'] },
|
|
279
|
+
{ ...p.columns, min: 2, max: 62 }],
|
|
280
|
+
validate: validateProps,
|
|
281
|
+
emit: props => { const v = props; return { by: `^BY${v.moduleWidth}`, command: `^BB${v.rotation},${v.rowHeight},${v.securityLevel},${v.columns},,F`, fieldData: v.content }; },
|
|
282
|
+
parse: (f, by) => ({ rotation: rotation(f[0]), moduleWidth: by.moduleWidth, rowHeight: number(f[1], 2), securityLevel: f[2] || 'Y', columns: number(f[3], 6) })
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
type: 'maxicode', label: 'MaxiCode', command: 'BD', bcid: 'maxicode', resizeKind: 'intrinsic', defaultContent: '1234567890',
|
|
286
|
+
defaults: { mode: 4, symbolNumber: 1, symbolTotal: 1 }, properties: [p.content,
|
|
287
|
+
{ name: 'mode', attributeName: 'mode', type: 'enum', values: ['2', '3', '4', '5', '6'] },
|
|
288
|
+
{ name: 'symbolNumber', attributeName: 'symbol-number', type: 'number', min: 1, max: 8, step: 1 },
|
|
289
|
+
{ name: 'symbolTotal', attributeName: 'symbol-total', type: 'number', min: 1, max: 8, step: 1 }],
|
|
290
|
+
validate: validateProps,
|
|
291
|
+
emit: props => { const v = props; return { command: `^BD${v.mode},${v.symbolNumber},${v.symbolTotal}`, fieldData: v.content }; },
|
|
292
|
+
parse: f => ({ mode: number(f[0], 2), symbolNumber: number(f[1], 1), symbolTotal: number(f[2], 1) })
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
type: 'tlc39', label: 'TLC39', command: 'BT', bcid: 'code39', resizeKind: 'tlc39', defaultContent: '123456,SERIAL',
|
|
296
|
+
defaults: { moduleWidth: 2, wideRatio: 2, barHeight: 40, microPdfModuleWidth: 2, microPdfRowHeight: 4 },
|
|
297
|
+
properties: [p.content, p.rotation, p.moduleWidth, p.wideRatio, p.barHeight,
|
|
298
|
+
{ name: 'microPdfModuleWidth', attributeName: 'micro-pdf-module-width', type: 'number', min: 1, max: 10, step: 1 },
|
|
299
|
+
{ name: 'microPdfRowHeight', attributeName: 'micro-pdf-row-height', type: 'number', min: 1, max: 9999, step: 1 }],
|
|
300
|
+
validate: validateTlc39,
|
|
301
|
+
emit: props => { const v = props; return { by: `^BY${v.moduleWidth}`, command: `^BT${v.rotation},${v.moduleWidth},${v.wideRatio},${v.barHeight},${v.microPdfModuleWidth},${v.microPdfRowHeight}`, fieldData: v.content }; },
|
|
302
|
+
parse: (f, by) => ({ rotation: rotation(f[0]), moduleWidth: number(f[1], by.moduleWidth), wideRatio: number(f[2], by.wideRatio), barHeight: number(f[3], by.barHeight), microPdfModuleWidth: number(f[4], 2), microPdfRowHeight: number(f[5], 4) })
|
|
303
|
+
}
|
|
304
|
+
];
|
|
305
|
+
export const barcodeRegistry = Object.freeze(Object.fromEntries(definitions.map(definition => [definition.type, Object.freeze(definition)])));
|
|
306
|
+
export const barcodeCommandRegistry = Object.freeze(Object.fromEntries(definitions.map(definition => [definition.command, definition])));
|
|
307
|
+
export function getBarcodeFieldOriginOffset(type, rotation) {
|
|
308
|
+
return barcodeRegistry[type].fieldOriginOffset?.(rotation) ?? { x: 0, y: 0 };
|
|
309
|
+
}
|
|
310
|
+
/** Every attribute that can affect a barcode preview. Keeping this list
|
|
311
|
+
* registry-derived makes custom-element reactivity follow the property grid. */
|
|
312
|
+
export const barcodeObservedAttributes = Object.freeze([
|
|
313
|
+
'type',
|
|
314
|
+
...new Set(definitions.flatMap(definition => definition.properties.map(property => property.attributeName)))
|
|
315
|
+
]);
|
|
316
|
+
export function getBarcodeDefinition(type) {
|
|
317
|
+
return barcodeRegistry[(type || 'code128').toLowerCase()] ?? barcodeRegistry.code128;
|
|
318
|
+
}
|
|
319
|
+
export function readBarcodeProps(element) {
|
|
320
|
+
const definition = getBarcodeDefinition(element.getAttribute('type'));
|
|
321
|
+
const result = {
|
|
322
|
+
type: definition.type,
|
|
323
|
+
content: element.getAttribute('content') ?? definition.defaultContent,
|
|
324
|
+
rotation: rotation(element.getAttribute('rotation') ?? undefined),
|
|
325
|
+
...definition.defaults
|
|
326
|
+
};
|
|
327
|
+
for (const property of definition.properties) {
|
|
328
|
+
if (property.name === 'content' || property.name === 'rotation')
|
|
329
|
+
continue;
|
|
330
|
+
const raw = element.getAttribute(property.attributeName);
|
|
331
|
+
if (raw == null)
|
|
332
|
+
continue;
|
|
333
|
+
if (property.type === 'boolean')
|
|
334
|
+
result[property.name] = raw === '' || raw === 'true' || raw === 'Y';
|
|
335
|
+
else if (property.type === 'number' || (property.type === 'enum' && typeof definition.defaults[property.name] === 'number'))
|
|
336
|
+
result[property.name] = number(raw, Number(definition.defaults[property.name] ?? 0));
|
|
337
|
+
else
|
|
338
|
+
result[property.name] = raw;
|
|
339
|
+
}
|
|
340
|
+
return result;
|
|
341
|
+
}
|
|
342
|
+
export function attributesForBarcode(type, values = {}) {
|
|
343
|
+
const definition = barcodeRegistry[type];
|
|
344
|
+
const attributes = { type, content: definition.defaultContent, rotation: 'N' };
|
|
345
|
+
for (const property of definition.properties) {
|
|
346
|
+
const value = values[property.name] ?? definition.defaults[property.name];
|
|
347
|
+
if (value == null || property.name === 'type')
|
|
348
|
+
continue;
|
|
349
|
+
if (property.type === 'boolean') {
|
|
350
|
+
attributes[property.attributeName] = value ? 'true' : 'false';
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
attributes[property.attributeName] = String(value);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return attributes;
|
|
357
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { BarcodeProps, BarcodeType, LinearBarcodeProps, Tlc39BarcodeProps } from './barcodeRegistry.js';
|
|
2
|
+
export interface BarcodeRenderResult {
|
|
3
|
+
canvas: HTMLCanvasElement | null;
|
|
4
|
+
error: string | null;
|
|
5
|
+
/** Preview bounds in ZPL dots. The canvas may have a larger backing store. */
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
}
|
|
9
|
+
export interface BarcodeModuleGeometry {
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
}
|
|
13
|
+
export interface BarcodeBarRectangle {
|
|
14
|
+
readonly x: number;
|
|
15
|
+
readonly y: number;
|
|
16
|
+
readonly width: number;
|
|
17
|
+
readonly height: number;
|
|
18
|
+
}
|
|
19
|
+
export type EanUpcType = 'ean13' | 'ean8' | 'upca' | 'upce';
|
|
20
|
+
export interface EanUpcHriFragment {
|
|
21
|
+
readonly char: string;
|
|
22
|
+
/** Horizontal digit centre in unscaled barcode modules. */
|
|
23
|
+
readonly xModule: number;
|
|
24
|
+
}
|
|
25
|
+
export declare const eanUpcTypes: ReadonlySet<BarcodeType>;
|
|
26
|
+
/** The add-on preview and its Labelary demo use the same printer density. */
|
|
27
|
+
export declare const zplPreviewDpmm = 24;
|
|
28
|
+
/** Firmware-visible HRI/guard zone in dots, used by both widget and tests. */
|
|
29
|
+
export declare function barcodeTextZoneDots(props: BarcodeProps): number;
|
|
30
|
+
export declare function barcodeTextAbove(props: BarcodeProps): boolean;
|
|
31
|
+
/** LOGMARS always prints its interpretation; its boolean selects above/below. */
|
|
32
|
+
export declare function barcodeShowsInterpretation(props: BarcodeProps): boolean;
|
|
33
|
+
/** Text printed beneath/above the bars by Zebra firmware. Code 39 start and
|
|
34
|
+
* stop characters are generated by the printer and are visible in its HRI,
|
|
35
|
+
* but must not be added to ^FD or encoded as data. */
|
|
36
|
+
export declare function barcodeInterpretationText(props: BarcodeProps): string;
|
|
37
|
+
/** Amount by which visible HRI extends above the ZPL ^FO anchor. */
|
|
38
|
+
export declare function barcodeFieldOriginAboveOffset(props: BarcodeProps): number;
|
|
39
|
+
/** Visible EAN/UPC digits extend beyond the guard bars on Zebra output. */
|
|
40
|
+
export declare function barcodeHorizontalInsets(props: BarcodeProps): Readonly<{
|
|
41
|
+
left: number;
|
|
42
|
+
right: number;
|
|
43
|
+
}>;
|
|
44
|
+
/** Zebra-compatible system/data/check digit positions. BWIP exposes these as
|
|
45
|
+
* raw module coordinates, including the floated UPC/EAN digits. */
|
|
46
|
+
export declare function getEanUpcHriFragments(props: BarcodeProps): readonly EanUpcHriFragment[];
|
|
47
|
+
/** EAN/UPC HRI uses the same discrete firmware font sizes as ZPLab/Labelary. */
|
|
48
|
+
export declare function getEanUpcHriStyle(moduleWidth: number): {
|
|
49
|
+
readonly fontSize: 28 | 18 | 8 | 56;
|
|
50
|
+
readonly gap: 4 | 5 | 7;
|
|
51
|
+
readonly fontFamily: "ZplVeraMono" | "ZplOCRB";
|
|
52
|
+
};
|
|
53
|
+
export declare function buildBwipOptions(props: BarcodeProps): Record<string, unknown>;
|
|
54
|
+
/** Returns the encoder's unscaled module bounds without a canvas or network. */
|
|
55
|
+
export declare function measureBarcodeModules(props: BarcodeProps): BarcodeModuleGeometry;
|
|
56
|
+
/**
|
|
57
|
+
* Returns the preview bounds in ZPL dots.
|
|
58
|
+
*
|
|
59
|
+
* BWIP-JS deliberately renders QR, DataMatrix, and Aztec modules as two canvas
|
|
60
|
+
* pixels at scale 1. Keeping that larger bitmap is useful on HiDPI displays,
|
|
61
|
+
* but its backing-store dimensions must not become the designer dimensions.
|
|
62
|
+
*/
|
|
63
|
+
export declare function measureBarcodePreview(props: BarcodeProps, fallback: BarcodeModuleGeometry): BarcodeModuleGeometry;
|
|
64
|
+
/** Zebra-width bar geometry shared by the renderer and offline regression tests. */
|
|
65
|
+
export declare function getZebraWidthBarGeometry(props: LinearBarcodeProps): {
|
|
66
|
+
readonly rects: readonly BarcodeBarRectangle[];
|
|
67
|
+
readonly width: number;
|
|
68
|
+
readonly height: number;
|
|
69
|
+
} | null;
|
|
70
|
+
interface Tlc39Geometry {
|
|
71
|
+
readonly runs: readonly number[];
|
|
72
|
+
readonly tallFromModule: number | null;
|
|
73
|
+
readonly width: number;
|
|
74
|
+
readonly height: number;
|
|
75
|
+
readonly code39Y: number;
|
|
76
|
+
readonly stopOverhang: number;
|
|
77
|
+
readonly microPdf: null | {
|
|
78
|
+
readonly x: number;
|
|
79
|
+
readonly y: number;
|
|
80
|
+
readonly width: number;
|
|
81
|
+
readonly height: number;
|
|
82
|
+
readonly rows: number;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** Composite TLC39 footprint adapted from ZPLab's ZD230-measured layout. */
|
|
86
|
+
export declare function getTlc39Geometry(props: Tlc39BarcodeProps): Tlc39Geometry;
|
|
87
|
+
/** Headless preview footprint used by the widget and regression fixtures. */
|
|
88
|
+
export declare function measureBarcodeBounds(props: BarcodeProps): BarcodeModuleGeometry;
|
|
89
|
+
export declare function renderBarcode(props: BarcodeProps): BarcodeRenderResult;
|
|
90
|
+
export {};
|