@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
|
@@ -1,266 +1,231 @@
|
|
|
1
|
-
import { DesignItem } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { DesignItem, hideAtRunTimeAttributeName } from '@node-projects/web-component-designer';
|
|
2
|
+
import { attributesForBarcode, barcodeCommandRegistry, getBarcodeFieldOriginOffset, readBarcodeProps } from '../barcodes/barcodeRegistry.js';
|
|
3
|
+
import { barcodeFieldOriginAboveOffset, barcodeHorizontalInsets } from '../barcodes/bwipRenderer.js';
|
|
4
|
+
import { ZplBarcode } from '../widgets/zpl-barcode.js';
|
|
5
|
+
import { ZplComment } from '../widgets/zpl-comment.js';
|
|
6
|
+
import { ZplGraphicBox } from '../widgets/zpl-graphic-box.js';
|
|
7
|
+
import { ZplGraphicCircle } from '../widgets/zpl-graphic-circle.js';
|
|
8
|
+
import { ZplGraphicDiagonalLine } from '../widgets/zpl-graphic-diagonal-line.js';
|
|
9
|
+
import { ZplImage } from '../widgets/zpl-image.js';
|
|
10
|
+
import { getZplTextOutputOffset, ZplText } from '../widgets/zpl-text.js';
|
|
11
|
+
import { createHiddenZplComments, hiddenPayloads, tokenizeZpl } from './hiddenMetadata.js';
|
|
12
|
+
export { createHiddenZplComments, decodeHiddenZplComments, tokenizeZpl } from './hiddenMetadata.js';
|
|
13
|
+
const first = (...values) => values.find(value => value !== '' && value != null && value !== 'NaN');
|
|
14
|
+
/** Zebra uses zero/omitted width as the natural aspect ratio. */
|
|
15
|
+
export const parseZplFontWidth = (value) => Number(first(value, 0));
|
|
16
|
+
function setPosition(element, x, y) {
|
|
17
|
+
element.style.position = 'absolute';
|
|
18
|
+
element.style.left = `${Number.isFinite(x) ? x : 0}px`;
|
|
19
|
+
element.style.top = `${Number.isFinite(y) ? y : 0}px`;
|
|
20
|
+
}
|
|
21
|
+
function designItem(element, serviceContainer, instanceServiceContainer) {
|
|
22
|
+
return DesignItem.createDesignItemFromInstance(element, serviceContainer, instanceServiceContainer);
|
|
13
23
|
}
|
|
14
24
|
export class ZplParserService {
|
|
15
25
|
options = {};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
case 'R':
|
|
19
|
-
{
|
|
20
|
-
el.style.transform = 'rotate(90deg) translateY(-100%)';
|
|
21
|
-
el.style.transformOrigin = '0% 0%';
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
;
|
|
25
|
-
case 'I': {
|
|
26
|
-
el.style.transform = 'rotate(180deg)';
|
|
27
|
-
el.style.transformOrigin = '50% 50%';
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
case 'B':
|
|
31
|
-
{
|
|
32
|
-
el.style.transform = 'rotate(270deg)';
|
|
33
|
-
el.style.transformOrigin = '100% 100%';
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
;
|
|
37
|
-
}
|
|
38
|
-
return;
|
|
26
|
+
async parse(source, serviceContainer, instanceServiceContainer, _parseSnippet) {
|
|
27
|
+
return this._parse(source, serviceContainer, instanceServiceContainer, true);
|
|
39
28
|
}
|
|
40
|
-
async
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
29
|
+
async _parse(source, serviceContainer, instanceServiceContainer, includeHidden) {
|
|
30
|
+
const tokens = tokenizeZpl(source);
|
|
31
|
+
const hidden = includeHidden ? hiddenPayloads(tokens) : [];
|
|
32
|
+
const validMetadataComments = new Set(hidden.flatMap(payload => [...payload.comments]));
|
|
33
|
+
const graphics = new Map();
|
|
34
|
+
const result = [];
|
|
35
|
+
let x = 0;
|
|
36
|
+
let y = 0;
|
|
37
|
+
let fontName = '0';
|
|
38
|
+
let fontHeight = 30;
|
|
39
|
+
let fontWidth = 0;
|
|
40
|
+
let fontRotation = 'N';
|
|
41
|
+
let by = { moduleWidth: 2, wideRatio: 3, barHeight: 100 };
|
|
42
|
+
let labelReverse = false;
|
|
43
|
+
let fieldReverse = false;
|
|
44
|
+
let pendingBarcode = null;
|
|
45
|
+
for (const token of tokens) {
|
|
46
|
+
const fields = token.data.split(',');
|
|
47
|
+
if (token.prefix === '~' && token.command === 'DG') {
|
|
48
|
+
const name = fields[0].replace(/^[A-Z]:/i, '');
|
|
49
|
+
graphics.set(name, { name, totalBytes: Number(fields[1]), bytesPerRow: Number(fields[2]), hexData: fields.slice(3).join(',') });
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (token.prefix !== '^')
|
|
53
|
+
continue;
|
|
54
|
+
if (token.command === 'FO') {
|
|
55
|
+
// ^FR is scoped to one field and a new origin starts a new one.
|
|
56
|
+
fieldReverse = false;
|
|
57
|
+
x = Number(fields[0]) || 0;
|
|
58
|
+
y = Number(fields[1]) || 0;
|
|
59
|
+
}
|
|
60
|
+
else if (token.command === 'LR') {
|
|
61
|
+
labelReverse = token.data.toUpperCase().startsWith('Y');
|
|
62
|
+
}
|
|
63
|
+
else if (token.command === 'FR') {
|
|
64
|
+
fieldReverse = true;
|
|
65
|
+
}
|
|
66
|
+
else if (token.command === 'FS') {
|
|
67
|
+
fieldReverse = false;
|
|
68
|
+
}
|
|
69
|
+
else if (token.command === 'CF') {
|
|
70
|
+
fontName = fields[0] || '0';
|
|
71
|
+
fontHeight = Number(first(fields[1], 30));
|
|
72
|
+
// An omitted width means the font's natural aspect ratio. For
|
|
73
|
+
// bitmap fonts A-H this also means "use the height
|
|
74
|
+
// magnification"; substituting the numeric height would pick
|
|
75
|
+
// a different (usually much wider) cell magnification.
|
|
76
|
+
fontWidth = parseZplFontWidth(fields[2]);
|
|
77
|
+
fontRotation = 'N';
|
|
78
|
+
}
|
|
79
|
+
else if (token.command[0] === 'A' && /^[0A-H]$/.test(token.command[1])) {
|
|
80
|
+
fontName = token.command[1];
|
|
81
|
+
fontRotation = fields[0] || 'N';
|
|
82
|
+
fontHeight = Number(first(fields[1], fontHeight, 30));
|
|
83
|
+
fontWidth = parseZplFontWidth(fields[2]);
|
|
84
|
+
}
|
|
85
|
+
else if (token.command === 'BY') {
|
|
86
|
+
by = {
|
|
87
|
+
moduleWidth: Number(first(fields[0], by.moduleWidth, 2)),
|
|
88
|
+
wideRatio: Number(first(fields[1], by.wideRatio, 3)),
|
|
89
|
+
barHeight: Number(first(fields[2], by.barHeight, 100))
|
|
54
90
|
};
|
|
55
91
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
p = p.replaceAll("\n", "");
|
|
74
|
-
p = p.replaceAll("\r", "");
|
|
75
|
-
let command = p.substring(0, 2);
|
|
76
|
-
let fieldString = p.substring(2);
|
|
77
|
-
let fields = fieldString.split(",");
|
|
78
|
-
switch (command) {
|
|
79
|
-
case "XA":
|
|
80
|
-
case "XZ":
|
|
81
|
-
break;
|
|
82
|
-
case "FX":
|
|
83
|
-
let comment = new ZplComment();
|
|
84
|
-
comment.style.position = "absolute";
|
|
85
|
-
comment.style.left = x + "px";
|
|
86
|
-
comment.style.top = y + "px";
|
|
87
|
-
comment.setAttribute("content", fieldString);
|
|
88
|
-
designItems.push(DesignItem.createDesignItemFromInstance(comment, serviceContainer, instanceServiceContainer));
|
|
89
|
-
break;
|
|
90
|
-
case "AA": //Ax x=fontname
|
|
91
|
-
case "A0": {
|
|
92
|
-
fontName = command[1];
|
|
93
|
-
rotation = getSetValue(fields[0], 'N');
|
|
94
|
-
let defaultFontWidth = 15;
|
|
95
|
-
switch (fontName) {
|
|
96
|
-
case "A":
|
|
97
|
-
defaultFontWidth = 15;
|
|
98
|
-
break;
|
|
99
|
-
case "0":
|
|
100
|
-
defaultFontWidth = fontHeight;
|
|
101
|
-
}
|
|
102
|
-
fontHeight = parseInt(getSetValue(fields[1], defaultFontWidth));
|
|
103
|
-
fontWidth = parseInt(getSetValue(fields[2], defaultFontWidth));
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
case "CF": //we should switch to use A, CF is default font
|
|
107
|
-
rotation = 'N';
|
|
108
|
-
fontName = fields[0];
|
|
109
|
-
fontHeight = parseInt(fields[1]);
|
|
110
|
-
let defaultFontWidth = 15;
|
|
111
|
-
switch (fontName) {
|
|
112
|
-
case "A":
|
|
113
|
-
defaultFontWidth = 15;
|
|
114
|
-
break;
|
|
115
|
-
case "0":
|
|
116
|
-
defaultFontWidth = fontHeight;
|
|
117
|
-
}
|
|
118
|
-
fontWidth = parseInt(getSetValue(fields[2], defaultFontWidth));
|
|
119
|
-
break;
|
|
120
|
-
case "FO":
|
|
121
|
-
x = parseInt(fields[0]);
|
|
122
|
-
y = parseInt(fields[1]);
|
|
123
|
-
//a = parseInt(fields[2]);
|
|
124
|
-
break;
|
|
125
|
-
case "GB":
|
|
126
|
-
let rect = new ZplGraphicBox();
|
|
127
|
-
rect.style.position = "absolute";
|
|
128
|
-
rect.style.left = x + "px";
|
|
129
|
-
rect.style.top = y + "px";
|
|
130
|
-
rect.style.width = getSetValue(fields[0], fields[2], '1') + "px";
|
|
131
|
-
rect.style.height = getSetValue(fields[1], fields[2], '1') + "px";
|
|
132
|
-
rect.setAttribute("stroke-width", getSetValue(fields[2], '1'));
|
|
133
|
-
rect.setAttribute("stroke-color", getSetValue(fields[3], 'B') == "B" ? "black" : "white");
|
|
134
|
-
rect.setAttribute("corner-rounding", getSetValue(fields[4], '0'));
|
|
135
|
-
designItems.push(DesignItem.createDesignItemFromInstance(rect, serviceContainer, instanceServiceContainer));
|
|
136
|
-
break;
|
|
137
|
-
case "GD":
|
|
138
|
-
let line = new ZplGraphicDiagonalLine();
|
|
139
|
-
line.style.position = "absolute";
|
|
140
|
-
line.style.left = x + "px";
|
|
141
|
-
line.style.top = y + "px";
|
|
142
|
-
line.style.width = getSetValue(fields[0], fields[2], '1') + "px";
|
|
143
|
-
line.style.height = getSetValue(fields[1], fields[2], '1') + "px";
|
|
144
|
-
line.setAttribute("stroke-width", getSetValue(fields[2], '1'));
|
|
145
|
-
line.setAttribute("stroke-color", getSetValue(fields[3], 'B') == "B" ? "black" : "white");
|
|
146
|
-
line.setAttribute("orientation", getSetValue(fields[4], 'R'));
|
|
147
|
-
designItems.push(DesignItem.createDesignItemFromInstance(line, serviceContainer, instanceServiceContainer));
|
|
148
|
-
break;
|
|
149
|
-
case "GE":
|
|
150
|
-
let circle = new ZplGraphicCircle();
|
|
151
|
-
circle.style.position = "absolute";
|
|
152
|
-
circle.style.left = x + "px";
|
|
153
|
-
circle.style.top = y + "px";
|
|
154
|
-
circle.style.width = getSetValue(fields[0], fields[2], '1') + "px";
|
|
155
|
-
circle.style.height = getSetValue(fields[1], fields[2], '1') + "px";
|
|
156
|
-
circle.setAttribute("stroke-width", getSetValue(fields[2], '1'));
|
|
157
|
-
circle.setAttribute("stroke-color", getSetValue(fields[3], 'B') == "B" ? "black" : "white");
|
|
158
|
-
designItems.push(DesignItem.createDesignItemFromInstance(circle, serviceContainer, instanceServiceContainer));
|
|
159
|
-
break;
|
|
160
|
-
case "BY":
|
|
161
|
-
bw = parseInt(getSetValue(fields[0], "2"));
|
|
162
|
-
br = parseFloat(getSetValue(fields[1], "3"));
|
|
163
|
-
bh = parseInt(getSetValue(fields[2], "10"));
|
|
164
|
-
break;
|
|
165
|
-
case "BC":
|
|
166
|
-
bc = true;
|
|
167
|
-
// bo = getSetValue(fields[0], 'N');
|
|
168
|
-
barcode = new ZplBarcode();
|
|
169
|
-
barcode.style.position = "absolute";
|
|
170
|
-
barcode.style.left = x + "px";
|
|
171
|
-
barcode.style.top = y + "px";
|
|
172
|
-
barcode.setAttribute("type", "CODE128");
|
|
173
|
-
if (bw)
|
|
174
|
-
barcode.setAttribute("width", bw.toString());
|
|
175
|
-
if (br)
|
|
176
|
-
barcode.setAttribute("ratio", br.toString());
|
|
177
|
-
barcode.setAttribute("height", getSetValue(fields[1], bh).toString());
|
|
178
|
-
break;
|
|
179
|
-
case "BQ":
|
|
180
|
-
qr = true;
|
|
181
|
-
bc = true;
|
|
182
|
-
// bo = getSetValue(fields[0], 'N');
|
|
183
|
-
barcode = new ZplBarcode();
|
|
184
|
-
barcode.style.position = "absolute";
|
|
185
|
-
barcode.style.left = x + "px";
|
|
186
|
-
barcode.style.top = y + "px";
|
|
187
|
-
barcode.setAttribute("type", "QR");
|
|
188
|
-
if (bw)
|
|
189
|
-
barcode.setAttribute("width", bw.toString());
|
|
190
|
-
if (br)
|
|
191
|
-
barcode.setAttribute("ratio", br.toString());
|
|
192
|
-
barcode.setAttribute("height", getSetValue(fields[2], bh).toString());
|
|
193
|
-
break;
|
|
194
|
-
case "FD":
|
|
195
|
-
if (bc) {
|
|
196
|
-
if (qr)
|
|
197
|
-
barcode.setAttribute("content", fieldString.substring(3));
|
|
198
|
-
else
|
|
199
|
-
barcode.setAttribute("content", fieldString);
|
|
200
|
-
designItems.push(DesignItem.createDesignItemFromInstance(barcode, serviceContainer, instanceServiceContainer));
|
|
201
|
-
bc = false;
|
|
202
|
-
qr = false;
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
let text = new ZplText();
|
|
206
|
-
text.style.position = "absolute";
|
|
207
|
-
text.style.left = x + "px";
|
|
208
|
-
text.style.top = y + "px";
|
|
209
|
-
text.setAttribute("font-name", fontName);
|
|
210
|
-
text.setAttribute("font-height", fontHeight.toString());
|
|
211
|
-
text.setAttribute("font-width", fontWidth.toString());
|
|
212
|
-
text.setAttribute("content", fieldString);
|
|
213
|
-
if (rotation) {
|
|
214
|
-
this.createTransform(rotation, text);
|
|
92
|
+
else if (barcodeCommandRegistry[token.command]) {
|
|
93
|
+
const definition = barcodeCommandRegistry[token.command];
|
|
94
|
+
const element = new ZplBarcode();
|
|
95
|
+
const values = definition.parse(fields, by);
|
|
96
|
+
const attributes = attributesForBarcode(definition.type, values);
|
|
97
|
+
for (const [name, value] of Object.entries(attributes))
|
|
98
|
+
element.setAttribute(name, value);
|
|
99
|
+
pendingBarcode = { element, definition, outputX: x, outputY: y };
|
|
100
|
+
}
|
|
101
|
+
else if (token.command === 'FD') {
|
|
102
|
+
if (pendingBarcode) {
|
|
103
|
+
let content = token.data;
|
|
104
|
+
if (pendingBarcode.definition.type === 'qrcode') {
|
|
105
|
+
const prefix = content.match(/^([HQML])A,/);
|
|
106
|
+
if (prefix) {
|
|
107
|
+
pendingBarcode.element.setAttribute('error-correction', prefix[1]);
|
|
108
|
+
content = content.slice(prefix[0].length);
|
|
215
109
|
}
|
|
216
|
-
designItems.push(DesignItem.createDesignItemFromInstance(text, serviceContainer, instanceServiceContainer));
|
|
217
110
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
111
|
+
pendingBarcode.element.setAttribute('content', content);
|
|
112
|
+
const props = readBarcodeProps(pendingBarcode.element);
|
|
113
|
+
const offset = getBarcodeFieldOriginOffset(props.type, props.rotation);
|
|
114
|
+
const aboveOffset = props.rotation === 'N' ? barcodeFieldOriginAboveOffset(props) : 0;
|
|
115
|
+
const horizontalOffset = props.rotation === 'N' ? barcodeHorizontalInsets(props).left : 0;
|
|
116
|
+
setPosition(pendingBarcode.element, pendingBarcode.outputX - offset.x - horizontalOffset, pendingBarcode.outputY - offset.y - aboveOffset);
|
|
117
|
+
result.push(designItem(pendingBarcode.element, serviceContainer, instanceServiceContainer));
|
|
118
|
+
pendingBarcode = null;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
const element = new ZplText();
|
|
122
|
+
const offset = getZplTextOutputOffset(fontRotation);
|
|
123
|
+
setPosition(element, x - offset.x, y - offset.y);
|
|
124
|
+
element.setAttribute('font-name', fontName);
|
|
125
|
+
element.setAttribute('font-height', String(fontHeight));
|
|
126
|
+
element.setAttribute('font-width', String(fontWidth));
|
|
127
|
+
element.setAttribute('rotation', fontRotation);
|
|
128
|
+
element.setAttribute('content', token.data);
|
|
129
|
+
result.push(designItem(element, serviceContainer, instanceServiceContainer));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else if (token.command === 'GB') {
|
|
133
|
+
const element = new ZplGraphicBox();
|
|
134
|
+
setPosition(element, x, y);
|
|
135
|
+
const width = Number(first(fields[0], fields[2], 1));
|
|
136
|
+
const height = Number(first(fields[1], fields[2], 1));
|
|
137
|
+
const thickness = Number(first(fields[2], 1));
|
|
138
|
+
element.style.width = `${width}px`;
|
|
139
|
+
element.style.height = `${height}px`;
|
|
140
|
+
element.setAttribute('stroke-width', String(thickness));
|
|
141
|
+
element.setAttribute('stroke-color', fields[3] === 'W' ? 'white' : 'black');
|
|
142
|
+
element.setAttribute('corner-rounding', String(first(fields[4], 0)));
|
|
143
|
+
if (thickness >= Math.min(width, height))
|
|
144
|
+
element.setAttribute('filled', '');
|
|
145
|
+
if (labelReverse || fieldReverse)
|
|
146
|
+
element.setAttribute('reverse', '');
|
|
147
|
+
result.push(designItem(element, serviceContainer, instanceServiceContainer));
|
|
148
|
+
}
|
|
149
|
+
else if (token.command === 'GD') {
|
|
150
|
+
const element = new ZplGraphicDiagonalLine();
|
|
151
|
+
setPosition(element, x, y);
|
|
152
|
+
element.style.width = `${Number(first(fields[0], fields[2], 1))}px`;
|
|
153
|
+
element.style.height = `${Number(first(fields[1], fields[2], 1))}px`;
|
|
154
|
+
element.setAttribute('stroke-width', String(first(fields[2], 1)));
|
|
155
|
+
element.setAttribute('stroke-color', fields[3] === 'W' ? 'white' : 'black');
|
|
156
|
+
element.setAttribute('orientation', String(first(fields[4], 'R')));
|
|
157
|
+
result.push(designItem(element, serviceContainer, instanceServiceContainer));
|
|
158
|
+
}
|
|
159
|
+
else if (token.command === 'GE') {
|
|
160
|
+
const element = new ZplGraphicCircle();
|
|
161
|
+
setPosition(element, x, y);
|
|
162
|
+
element.style.width = `${Number(first(fields[0], fields[2], 1))}px`;
|
|
163
|
+
element.style.height = `${Number(first(fields[1], fields[2], 1))}px`;
|
|
164
|
+
element.setAttribute('stroke-width', String(first(fields[2], 1)));
|
|
165
|
+
element.setAttribute('stroke-color', fields[3] === 'W' ? 'white' : 'black');
|
|
166
|
+
result.push(designItem(element, serviceContainer, instanceServiceContainer));
|
|
233
167
|
}
|
|
168
|
+
else if (token.command === 'XG') {
|
|
169
|
+
const name = fields[0].replace(/^[A-Z]:/i, '');
|
|
170
|
+
const graphic = graphics.get(name);
|
|
171
|
+
if (!graphic)
|
|
172
|
+
continue;
|
|
173
|
+
const element = new ZplImage();
|
|
174
|
+
setPosition(element, x, y);
|
|
175
|
+
element.setAttribute('total-bytes', String(graphic.totalBytes));
|
|
176
|
+
element.setAttribute('bytes-per-row', String(graphic.bytesPerRow));
|
|
177
|
+
element.setAttribute('image-name', name);
|
|
178
|
+
element.setAttribute('hex-image', graphic.hexData);
|
|
179
|
+
element.setAttribute('scale-x', String(first(fields[1], 1)));
|
|
180
|
+
element.setAttribute('scale-y', String(first(fields[2], 1)));
|
|
181
|
+
result.push(designItem(element, serviceContainer, instanceServiceContainer));
|
|
182
|
+
}
|
|
183
|
+
else if (token.command === 'FX' && !validMetadataComments.has(token.data)) {
|
|
184
|
+
const element = new ZplComment();
|
|
185
|
+
setPosition(element, x, y);
|
|
186
|
+
element.setAttribute('content', token.data);
|
|
187
|
+
result.push(designItem(element, serviceContainer, instanceServiceContainer));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
for (const payload of hidden) {
|
|
191
|
+
const hiddenItems = await this._parse(payload.zpl, serviceContainer, instanceServiceContainer, false);
|
|
192
|
+
for (const item of hiddenItems)
|
|
193
|
+
item._withoutUndoSetAttribute(hideAtRunTimeAttributeName, '');
|
|
194
|
+
result.splice(Math.min(payload.index, result.length), 0, ...hiddenItems);
|
|
234
195
|
}
|
|
235
|
-
return
|
|
196
|
+
return result;
|
|
236
197
|
}
|
|
237
|
-
write(textWriter, designItems,
|
|
238
|
-
|
|
239
|
-
for (
|
|
240
|
-
if (
|
|
241
|
-
|
|
242
|
-
textWriter.writeLine(d.element.createZplImage());
|
|
243
|
-
//@ts-ignore
|
|
244
|
-
tx += d.element.createZplImage() + '\n';
|
|
198
|
+
write(textWriter, designItems, _rootContainerKeepInline, updatePositions) {
|
|
199
|
+
textWriter.writeLine('^XA');
|
|
200
|
+
for (const designItem of designItems) {
|
|
201
|
+
if (!designItem.hideAtRunTime && designItem.element instanceof ZplImage) {
|
|
202
|
+
textWriter.writeLine(designItem.element.createZplImage());
|
|
245
203
|
}
|
|
246
204
|
}
|
|
247
|
-
for (let
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
205
|
+
for (let index = 0; index < designItems.length; index++) {
|
|
206
|
+
const designItem = designItems[index];
|
|
207
|
+
const start = textWriter.position;
|
|
208
|
+
if (designItem.hideAtRunTime) {
|
|
209
|
+
const miniLines = ['^XA'];
|
|
210
|
+
if (designItem.element instanceof ZplImage)
|
|
211
|
+
miniLines.push(designItem.element.createZplImage());
|
|
212
|
+
const createZpl = designItem.element.createZpl;
|
|
213
|
+
if (createZpl)
|
|
214
|
+
miniLines.push(createZpl.call(designItem.element));
|
|
215
|
+
miniLines.push('^XZ');
|
|
216
|
+
for (const comment of createHiddenZplComments(index, miniLines.join('\n')))
|
|
217
|
+
textWriter.writeLine(comment);
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
const createZpl = designItem.element.createZpl;
|
|
221
|
+
if (createZpl)
|
|
222
|
+
textWriter.writeLine(createZpl.call(designItem.element));
|
|
223
|
+
}
|
|
224
|
+
const end = textWriter.position;
|
|
225
|
+
if (updatePositions && designItem.instanceServiceContainer.designItemDocumentPositionService) {
|
|
226
|
+
designItem.instanceServiceContainer.designItemDocumentPositionService.setPosition(designItem, { start, length: end - start });
|
|
262
227
|
}
|
|
263
228
|
}
|
|
264
|
-
textWriter.writeLine(
|
|
229
|
+
textWriter.writeLine('^XZ');
|
|
265
230
|
}
|
|
266
231
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IDesignItem, IDesignerCanvas, IExtensionManager, SelectionDefaultExtensionProvider } from '@node-projects/web-component-designer';
|
|
2
|
+
/**
|
|
3
|
+
* Graphic circles and diagonal lines already describe their complete visual
|
|
4
|
+
* boundary. A rectangular selection outline obscures that geometry, so those
|
|
5
|
+
* widgets use resize handles without the generic selection rectangle.
|
|
6
|
+
*/
|
|
7
|
+
export declare class ZplSelectionExtensionProvider extends SelectionDefaultExtensionProvider {
|
|
8
|
+
shouldExtend(extensionManager: IExtensionManager, designerCanvas: IDesignerCanvas, designItem: IDesignItem): boolean;
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SelectionDefaultExtensionProvider } from '@node-projects/web-component-designer';
|
|
2
|
+
import { ZplGraphicCircle } from '../widgets/zpl-graphic-circle.js';
|
|
3
|
+
import { ZplGraphicDiagonalLine } from '../widgets/zpl-graphic-diagonal-line.js';
|
|
4
|
+
/**
|
|
5
|
+
* Graphic circles and diagonal lines already describe their complete visual
|
|
6
|
+
* boundary. A rectangular selection outline obscures that geometry, so those
|
|
7
|
+
* widgets use resize handles without the generic selection rectangle.
|
|
8
|
+
*/
|
|
9
|
+
export class ZplSelectionExtensionProvider extends SelectionDefaultExtensionProvider {
|
|
10
|
+
shouldExtend(extensionManager, designerCanvas, designItem) {
|
|
11
|
+
if (designItem.element instanceof ZplGraphicCircle || designItem.element instanceof ZplGraphicDiagonalLine)
|
|
12
|
+
return false;
|
|
13
|
+
return super.shouldExtend(extensionManager, designerCanvas, designItem);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AbstractExtension, IDesignItem, IDesignerCanvas, IDesignerExtensionProvider, IExtensionManager } from '@node-projects/web-component-designer';
|
|
2
|
+
/** In-place plain-text editor for the shadow-DOM based ZPL text widget. */
|
|
3
|
+
export declare class ZplTextEditExtension extends AbstractExtension {
|
|
4
|
+
private _selectionChangedListener?;
|
|
5
|
+
private _finished;
|
|
6
|
+
private _originalContent;
|
|
7
|
+
private _previousClickOverlayPointerEvents;
|
|
8
|
+
constructor(extensionManager: IExtensionManager, designerCanvas: IDesignerCanvas, extendedItem: IDesignItem);
|
|
9
|
+
extend(): void;
|
|
10
|
+
refresh(): void;
|
|
11
|
+
dispose(): void;
|
|
12
|
+
private _onInput;
|
|
13
|
+
private _onKeyDown;
|
|
14
|
+
private _onDocumentPointerDown;
|
|
15
|
+
private _finish;
|
|
16
|
+
}
|
|
17
|
+
export declare class ZplTextEditExtensionProvider implements IDesignerExtensionProvider {
|
|
18
|
+
shouldExtend(_extensionManager: IExtensionManager, designerCanvas: IDesignerCanvas, designItem: IDesignItem): boolean;
|
|
19
|
+
getExtension(extensionManager: IExtensionManager, designerCanvas: IDesignerCanvas, designItem: IDesignItem): ZplTextEditExtension;
|
|
20
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { AbstractExtension } from '@node-projects/web-component-designer';
|
|
2
|
+
import { ZplText } from '../widgets/zpl-text.js';
|
|
3
|
+
/** In-place plain-text editor for the shadow-DOM based ZPL text widget. */
|
|
4
|
+
export class ZplTextEditExtension extends AbstractExtension {
|
|
5
|
+
_selectionChangedListener;
|
|
6
|
+
_finished = false;
|
|
7
|
+
_originalContent = '';
|
|
8
|
+
_previousClickOverlayPointerEvents = '';
|
|
9
|
+
constructor(extensionManager, designerCanvas, extendedItem) {
|
|
10
|
+
super(extensionManager, designerCanvas, extendedItem);
|
|
11
|
+
this._onKeyDown = this._onKeyDown.bind(this);
|
|
12
|
+
this._onInput = this._onInput.bind(this);
|
|
13
|
+
this._onDocumentPointerDown = this._onDocumentPointerDown.bind(this);
|
|
14
|
+
}
|
|
15
|
+
extend() {
|
|
16
|
+
const element = this.extendedItem.element;
|
|
17
|
+
this._originalContent = this.extendedItem.getAttribute('content') ?? '';
|
|
18
|
+
// Clearing the selection removes resize/position overlays while the
|
|
19
|
+
// caret is active. Subscribe afterwards so this initial clear does not
|
|
20
|
+
// immediately close the editor.
|
|
21
|
+
this.extendedItem.instanceServiceContainer.selectionService.clearSelectedElements();
|
|
22
|
+
this._selectionChangedListener = this.extendedItem.instanceServiceContainer.selectionService.onSelectionChanged.on(() => this._finish(true));
|
|
23
|
+
this._previousClickOverlayPointerEvents = this.designerCanvas.clickOverlay.style.pointerEvents;
|
|
24
|
+
this.designerCanvas.clickOverlay.style.pointerEvents = 'none';
|
|
25
|
+
element.beginInlineEdit();
|
|
26
|
+
element.inlineEditElement.addEventListener('keydown', this._onKeyDown, true);
|
|
27
|
+
element.inlineEditElement.addEventListener('input', this._onInput);
|
|
28
|
+
element.ownerDocument.addEventListener('pointerdown', this._onDocumentPointerDown, true);
|
|
29
|
+
}
|
|
30
|
+
refresh() { }
|
|
31
|
+
dispose() {
|
|
32
|
+
const element = this.extendedItem.element;
|
|
33
|
+
element.inlineEditElement.removeEventListener('keydown', this._onKeyDown, true);
|
|
34
|
+
element.inlineEditElement.removeEventListener('input', this._onInput);
|
|
35
|
+
element.ownerDocument.removeEventListener('pointerdown', this._onDocumentPointerDown, true);
|
|
36
|
+
this._selectionChangedListener?.dispose();
|
|
37
|
+
this.designerCanvas.clickOverlay.style.pointerEvents = this._previousClickOverlayPointerEvents;
|
|
38
|
+
element.finishInlineEdit();
|
|
39
|
+
}
|
|
40
|
+
_onInput(event) {
|
|
41
|
+
event.stopPropagation();
|
|
42
|
+
this.extendedItem.element.refreshInlineEditBounds();
|
|
43
|
+
}
|
|
44
|
+
_onKeyDown(event) {
|
|
45
|
+
event.stopPropagation();
|
|
46
|
+
if (event.key === 'Enter') {
|
|
47
|
+
event.preventDefault();
|
|
48
|
+
this._finish(true);
|
|
49
|
+
}
|
|
50
|
+
else if (event.key === 'Escape') {
|
|
51
|
+
event.preventDefault();
|
|
52
|
+
this._finish(false);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
_onDocumentPointerDown(event) {
|
|
56
|
+
const editor = this.extendedItem.element.inlineEditElement;
|
|
57
|
+
if (event.composedPath().includes(editor))
|
|
58
|
+
return;
|
|
59
|
+
this._finish(true);
|
|
60
|
+
}
|
|
61
|
+
_finish(commit) {
|
|
62
|
+
if (this._finished)
|
|
63
|
+
return;
|
|
64
|
+
this._finished = true;
|
|
65
|
+
const element = this.extendedItem.element;
|
|
66
|
+
const newContent = element.inlineEditContent;
|
|
67
|
+
element.finishInlineEdit();
|
|
68
|
+
if (commit && newContent !== this._originalContent)
|
|
69
|
+
this.extendedItem.setAttribute('content', newContent);
|
|
70
|
+
this.extensionManager.removeExtensionInstance(this.extendedItem, this);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export class ZplTextEditExtensionProvider {
|
|
74
|
+
shouldExtend(_extensionManager, designerCanvas, designItem) {
|
|
75
|
+
return !designerCanvas.readOnly && designItem.element instanceof ZplText;
|
|
76
|
+
}
|
|
77
|
+
getExtension(extensionManager, designerCanvas, designItem) {
|
|
78
|
+
return new ZplTextEditExtension(extensionManager, designerCanvas, designItem);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AbstractPropertiesService, IDesignItem, IProperty, RefreshMode } from '@node-projects/web-component-designer';
|
|
2
|
+
export declare class ZplTextPropertiesService extends AbstractPropertiesService {
|
|
3
|
+
name: string;
|
|
4
|
+
getRefreshMode(): RefreshMode;
|
|
5
|
+
isHandledElement(designItem: IDesignItem): boolean;
|
|
6
|
+
protected _notifyChangedProperty(designItem: IDesignItem): void;
|
|
7
|
+
getProperties(): Promise<IProperty[]>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AbstractPropertiesService, PropertyType, RefreshMode } from '@node-projects/web-component-designer';
|
|
2
|
+
import { ZplText } from '../widgets/zpl-text.js';
|
|
3
|
+
export class ZplTextPropertiesService extends AbstractPropertiesService {
|
|
4
|
+
name = 'zplText';
|
|
5
|
+
getRefreshMode() {
|
|
6
|
+
return RefreshMode.fullOnValueChange;
|
|
7
|
+
}
|
|
8
|
+
isHandledElement(designItem) {
|
|
9
|
+
return designItem.element instanceof ZplText;
|
|
10
|
+
}
|
|
11
|
+
_notifyChangedProperty(designItem) {
|
|
12
|
+
designItem.element.refreshFromAttributes();
|
|
13
|
+
}
|
|
14
|
+
async getProperties() {
|
|
15
|
+
const definitions = [
|
|
16
|
+
{ name: 'content', type: 'string', attributeName: 'content' },
|
|
17
|
+
{ name: 'fontName', displayName: 'font', type: 'enum', attributeName: 'font-name', enumValues: [...'0ABCDEFGH'].map(value => [value, value]) },
|
|
18
|
+
{ name: 'fontHeight', displayName: 'font height', type: 'number', attributeName: 'font-height', min: 1, max: 32000, step: 1 },
|
|
19
|
+
{ name: 'fontWidth', displayName: 'font width (0 = automatic)', description: 'Zero is Zebra automatic width; the selection rectangle still uses the measured printed width.', type: 'number', attributeName: 'font-width', min: 0, max: 32000, step: 1 },
|
|
20
|
+
{ name: 'rotation', type: 'enum', attributeName: 'rotation', enumValues: ['N', 'R', 'I', 'B'].map(value => [value, value]) }
|
|
21
|
+
];
|
|
22
|
+
return definitions.map(property => ({ ...property, service: this, propertyType: PropertyType.attribute }));
|
|
23
|
+
}
|
|
24
|
+
}
|