@node-projects/web-component-designer-zpl 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +70 -0
- package/dist/barcodes/bwipRenderer.js +552 -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 +2 -1
- package/dist/widgets/zpl-barcode.d.ts +68 -14
- package/dist/widgets/zpl-barcode.js +162 -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 -13
- 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,96 +1,184 @@
|
|
|
1
|
-
import { BaseCustomWebComponentConstructorAppend,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
1
|
+
import { BaseCustomWebComponentConstructorAppend, css, html } from '@node-projects/base-custom-webcomponent';
|
|
2
|
+
import { getZplCoordinates } from '../zplHelper.js';
|
|
3
|
+
import { barcodeObservedAttributes, getBarcodeDefinition, getBarcodeFieldOriginOffset, readBarcodeProps } from '../barcodes/barcodeRegistry.js';
|
|
4
|
+
import { barcodeFieldOriginAboveOffset, barcodeHorizontalInsets, barcodeShowsInterpretation, barcodeTextAbove, barcodeTextZoneDots, renderBarcode } from '../barcodes/bwipRenderer.js';
|
|
5
5
|
export class ZplBarcode extends BaseCustomWebComponentConstructorAppend {
|
|
6
|
-
static style = css `
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
static style = css `
|
|
7
|
+
:host { display: block; min-width: 1px; min-height: 1px; }
|
|
8
|
+
* { box-sizing: border-box; }
|
|
9
|
+
#barcode-frame { position: relative; transform-origin: 0 0; }
|
|
10
|
+
canvas { display: block; image-rendering: pixelated; }
|
|
11
|
+
#hri { position: absolute; left: 0; width: 100%; text-align: center; color: black;
|
|
12
|
+
font-family: "ZplVeraMono", monospace; white-space: nowrap; }
|
|
13
|
+
#error { width: 160px; min-height: 48px; padding: 6px; border: 1px dashed #c62828;
|
|
14
|
+
color: #8e0000; background: #fff4f4; font: 11px sans-serif; overflow: hidden; }
|
|
9
15
|
`;
|
|
10
16
|
static template = html `
|
|
11
|
-
|
|
12
|
-
</div>
|
|
17
|
+
<div id="barcode-frame"><div id="barcode-surface"></div><div id="hri"></div><div id="error" hidden></div></div>
|
|
13
18
|
`;
|
|
14
19
|
static is = 'zpl-barcode';
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
static get observedAttributes() { return barcodeObservedAttributes; }
|
|
21
|
+
content = '';
|
|
22
|
+
type = 'code128';
|
|
23
|
+
rotation = 'N';
|
|
24
|
+
moduleWidth = 2;
|
|
25
|
+
wideRatio = 3;
|
|
26
|
+
barHeight = 100;
|
|
27
|
+
printInterpretation = true;
|
|
28
|
+
printInterpretationAbove = false;
|
|
29
|
+
checkDigit = false;
|
|
30
|
+
magnification = 4;
|
|
31
|
+
dimension = 5;
|
|
32
|
+
rowHeight = 2;
|
|
33
|
+
columns = 0;
|
|
34
|
+
rows = 0;
|
|
35
|
+
mode = 0;
|
|
36
|
+
securityLevel = 0;
|
|
37
|
+
errorCorrection = 'Q';
|
|
38
|
+
quality = 200;
|
|
39
|
+
gs1 = false;
|
|
40
|
+
aspectRatio = 1;
|
|
41
|
+
symbology = 1;
|
|
42
|
+
segments = 22;
|
|
43
|
+
ecLevel = 0;
|
|
44
|
+
model = 2;
|
|
45
|
+
symbolNumber = 1;
|
|
46
|
+
symbolTotal = 1;
|
|
47
|
+
microPdfModuleWidth = 2;
|
|
48
|
+
microPdfRowHeight = 4;
|
|
22
49
|
static properties = {
|
|
23
|
-
content: String,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
50
|
+
content: String, type: String, rotation: String, moduleWidth: Number, wideRatio: Number,
|
|
51
|
+
barHeight: Number, printInterpretation: Boolean, printInterpretationAbove: Boolean,
|
|
52
|
+
checkDigit: Boolean, magnification: Number, dimension: Number, rowHeight: Number,
|
|
53
|
+
columns: Number, rows: Number, mode: String, securityLevel: String,
|
|
54
|
+
errorCorrection: String, quality: Number, gs1: Boolean, aspectRatio: Number,
|
|
55
|
+
symbology: Number, segments: Number, ecLevel: Number, model: Number,
|
|
56
|
+
symbolNumber: Number, symbolTotal: Number, microPdfModuleWidth: Number,
|
|
57
|
+
microPdfRowHeight: Number
|
|
28
58
|
};
|
|
59
|
+
_surface;
|
|
60
|
+
_frame;
|
|
61
|
+
_hri;
|
|
62
|
+
_error;
|
|
63
|
+
_widgetReady = false;
|
|
29
64
|
constructor() {
|
|
30
65
|
super();
|
|
31
66
|
this._restoreCachedInititalValues();
|
|
32
|
-
this.
|
|
67
|
+
this._surface = this._getDomElement('barcode-surface');
|
|
68
|
+
this._frame = this._getDomElement('barcode-frame');
|
|
69
|
+
this._hri = this._getDomElement('hri');
|
|
70
|
+
this._error = this._getDomElement('error');
|
|
71
|
+
}
|
|
72
|
+
ready() {
|
|
73
|
+
this._widgetReady = true;
|
|
74
|
+
this.refreshFromAttributes();
|
|
33
75
|
}
|
|
34
|
-
|
|
76
|
+
refreshFromAttributes() {
|
|
35
77
|
this._parseAttributesToProperties();
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
78
|
+
this.renderBarcode();
|
|
79
|
+
}
|
|
80
|
+
attributeChangedCallback(_name, oldValue, newValue) {
|
|
81
|
+
if (oldValue === newValue || !this._widgetReady)
|
|
82
|
+
return;
|
|
83
|
+
this.refreshFromAttributes();
|
|
84
|
+
}
|
|
85
|
+
get barcodeProps() {
|
|
86
|
+
return readBarcodeProps(this);
|
|
87
|
+
}
|
|
88
|
+
renderBarcode() {
|
|
89
|
+
const props = this.barcodeProps;
|
|
90
|
+
const definition = getBarcodeDefinition(props.type);
|
|
91
|
+
const result = renderBarcode(props);
|
|
92
|
+
this._surface.replaceChildren();
|
|
93
|
+
this._hri.hidden = true;
|
|
94
|
+
this._error.hidden = true;
|
|
95
|
+
this._frame.style.transform = '';
|
|
96
|
+
this._frame.style.width = '';
|
|
97
|
+
this._frame.style.height = '';
|
|
98
|
+
this._surface.style.position = '';
|
|
99
|
+
this._surface.style.left = '';
|
|
100
|
+
this._surface.style.top = '';
|
|
101
|
+
if (!result.canvas) {
|
|
102
|
+
this._error.textContent = `${definition.label}: ${result.error ?? 'cannot render this value'}`;
|
|
103
|
+
this._error.hidden = false;
|
|
104
|
+
this._setRotatedBounds(160, 48, props.rotation);
|
|
105
|
+
return;
|
|
52
106
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
107
|
+
const canvas = result.canvas;
|
|
108
|
+
const uprightWidth = result.width;
|
|
109
|
+
const horizontalInsets = barcodeHorizontalInsets(props);
|
|
110
|
+
let uprightHeight = result.height;
|
|
111
|
+
if (definition.resizeKind === 'linear') {
|
|
112
|
+
const linear = props;
|
|
113
|
+
canvas.style.width = `${uprightWidth - horizontalInsets.left - horizontalInsets.right}px`;
|
|
114
|
+
canvas.style.height = `${linear.barHeight}px`;
|
|
115
|
+
uprightHeight = linear.barHeight;
|
|
116
|
+
const showHri = barcodeShowsInterpretation(props);
|
|
117
|
+
const textZone = barcodeTextZoneDots(props);
|
|
118
|
+
const textAbove = barcodeTextAbove(props);
|
|
119
|
+
if (textAbove && textZone > 0) {
|
|
120
|
+
this._surface.style.position = 'absolute';
|
|
121
|
+
this._surface.style.left = `${horizontalInsets.left}px`;
|
|
122
|
+
this._surface.style.top = `${textZone}px`;
|
|
123
|
+
}
|
|
124
|
+
else if (horizontalInsets.left > 0) {
|
|
125
|
+
this._surface.style.position = 'absolute';
|
|
126
|
+
this._surface.style.left = `${horizontalInsets.left}px`;
|
|
127
|
+
this._surface.style.top = '0';
|
|
128
|
+
}
|
|
129
|
+
if (showHri) {
|
|
130
|
+
const genericHri = ['code128', 'code39', 'code93', 'code11', 'interleaved2of5',
|
|
131
|
+
'standard2of5', 'industrial2of5', 'codabar', 'msi'].includes(props.type);
|
|
132
|
+
const hriFontSize = genericHri ? 9.7 * Math.max(1, Math.round(linear.moduleWidth)) : 12;
|
|
133
|
+
this._hri.textContent = linear.content;
|
|
134
|
+
this._hri.style.height = `${textZone}px`;
|
|
135
|
+
this._hri.style.fontSize = `${hriFontSize}px`;
|
|
136
|
+
this._hri.style.lineHeight = `${hriFontSize}px`;
|
|
137
|
+
this._hri.style.letterSpacing = genericHri ? '.6px' : 'normal';
|
|
138
|
+
this._hri.style.transform = genericHri ? 'translateX(-3px)' : '';
|
|
139
|
+
// Zebra keeps a roughly five-dot bar-to-cap gap. Vera Mono's
|
|
140
|
+
// cap top sits about .14em below its line-box top. The DOM
|
|
141
|
+
// rasterizer needs three extra dots to match the printer cap.
|
|
142
|
+
const belowTop = uprightHeight + 8 - hriFontSize * .14;
|
|
143
|
+
this._hri.style.top = textAbove ? '0' : `${belowTop}px`;
|
|
144
|
+
this._hri.hidden = false;
|
|
145
|
+
}
|
|
146
|
+
uprightHeight += textZone;
|
|
62
147
|
}
|
|
148
|
+
this._surface.appendChild(canvas);
|
|
149
|
+
this._setRotatedBounds(uprightWidth, uprightHeight, props.rotation);
|
|
63
150
|
}
|
|
64
|
-
|
|
65
|
-
this.
|
|
66
|
-
this.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
createZpl() {
|
|
73
|
-
let zpl = "";
|
|
74
|
-
zpl += getZplCoordinates(this, 0);
|
|
75
|
-
if (this.type != BarcodeFormat.QR)
|
|
76
|
-
zpl += "^BY" + this.width + "," + this.ratio;
|
|
77
|
-
switch (this.type) {
|
|
78
|
-
case BarcodeFormat.CODE128:
|
|
79
|
-
zpl += "^BCN," + this.height + ",Y,N,Y,N";
|
|
151
|
+
_setRotatedBounds(width, height, rotation) {
|
|
152
|
+
this._frame.style.width = `${width}px`;
|
|
153
|
+
this._frame.style.height = `${height}px`;
|
|
154
|
+
switch (rotation) {
|
|
155
|
+
case 'R':
|
|
156
|
+
this._frame.style.transform = `translateX(${height}px) rotate(90deg)`;
|
|
157
|
+
this.style.width = `${height}px`;
|
|
158
|
+
this.style.height = `${width}px`;
|
|
80
159
|
break;
|
|
81
|
-
case
|
|
82
|
-
|
|
160
|
+
case 'I':
|
|
161
|
+
this._frame.style.transform = `translate(${width}px, ${height}px) rotate(180deg)`;
|
|
162
|
+
this.style.width = `${width}px`;
|
|
163
|
+
this.style.height = `${height}px`;
|
|
83
164
|
break;
|
|
84
|
-
case
|
|
85
|
-
|
|
165
|
+
case 'B':
|
|
166
|
+
this._frame.style.transform = `translateY(${width}px) rotate(270deg)`;
|
|
167
|
+
this.style.width = `${height}px`;
|
|
168
|
+
this.style.height = `${width}px`;
|
|
86
169
|
break;
|
|
170
|
+
default:
|
|
171
|
+
this.style.width = `${width}px`;
|
|
172
|
+
this.style.height = `${height}px`;
|
|
87
173
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
174
|
+
}
|
|
175
|
+
createZpl() {
|
|
176
|
+
const props = this.barcodeProps;
|
|
177
|
+
const emitted = getBarcodeDefinition(props.type).emit(props);
|
|
178
|
+
const offset = getBarcodeFieldOriginOffset(props.type, props.rotation);
|
|
179
|
+
const aboveOffset = props.rotation === 'N' ? barcodeFieldOriginAboveOffset(props) : 0;
|
|
180
|
+
const horizontalOffset = props.rotation === 'N' ? barcodeHorizontalInsets(props).left : 0;
|
|
181
|
+
return `${getZplCoordinates(this, 0, offset.x + horizontalOffset, offset.y + aboveOffset)}${emitted.by ?? ''}${emitted.command}^FD${emitted.fieldData}^FS`;
|
|
94
182
|
}
|
|
95
183
|
}
|
|
96
184
|
customElements.define(ZplBarcode.is, ZplBarcode);
|
|
@@ -3,11 +3,13 @@ export declare class ZplComment extends BaseCustomWebComponentConstructorAppend
|
|
|
3
3
|
static readonly style: CSSStyleSheet;
|
|
4
4
|
static readonly template: HTMLTemplateElement;
|
|
5
5
|
static readonly is = "zpl-comment";
|
|
6
|
+
static get observedAttributes(): string[];
|
|
6
7
|
content: string;
|
|
7
8
|
static readonly properties: {
|
|
8
9
|
content: StringConstructor;
|
|
9
10
|
};
|
|
10
11
|
constructor();
|
|
11
12
|
ready(): Promise<void>;
|
|
13
|
+
attributeChangedCallback(_name: string, oldValue: string | null, newValue: string | null): void;
|
|
12
14
|
createZpl(): string;
|
|
13
15
|
}
|
|
@@ -6,6 +6,7 @@ export class ZplComment extends BaseCustomWebComponentConstructorAppend {
|
|
|
6
6
|
}`;
|
|
7
7
|
static template = html ``;
|
|
8
8
|
static is = 'zpl-comment';
|
|
9
|
+
static get observedAttributes() { return ['content']; }
|
|
9
10
|
content;
|
|
10
11
|
static properties = {
|
|
11
12
|
content: String
|
|
@@ -17,10 +18,12 @@ export class ZplComment extends BaseCustomWebComponentConstructorAppend {
|
|
|
17
18
|
async ready() {
|
|
18
19
|
this._parseAttributesToProperties();
|
|
19
20
|
}
|
|
21
|
+
attributeChangedCallback(_name, oldValue, newValue) {
|
|
22
|
+
if (oldValue !== newValue)
|
|
23
|
+
this._parseAttributesToProperties();
|
|
24
|
+
}
|
|
20
25
|
createZpl() {
|
|
21
|
-
|
|
22
|
-
zpl += "^FX" + this.content;
|
|
23
|
-
return zpl;
|
|
26
|
+
return "^FX" + this.content + "^FS";
|
|
24
27
|
}
|
|
25
28
|
}
|
|
26
29
|
customElements.define(ZplComment.is, ZplComment);
|
|
@@ -7,18 +7,30 @@ export declare class ZplGraphicBox extends BaseCustomWebComponentConstructorAppe
|
|
|
7
7
|
static readonly style: CSSStyleSheet;
|
|
8
8
|
static readonly template: HTMLTemplateElement;
|
|
9
9
|
static readonly is = "zpl-graphic-box";
|
|
10
|
+
static get observedAttributes(): string[];
|
|
10
11
|
strokeWidth: number;
|
|
11
12
|
strokeColor: string;
|
|
12
13
|
cornerRounding: number;
|
|
14
|
+
filled: boolean;
|
|
15
|
+
reverse: boolean;
|
|
13
16
|
private _box;
|
|
14
17
|
private _observer;
|
|
15
18
|
static readonly properties: {
|
|
16
19
|
strokeWidth: NumberConstructor;
|
|
17
20
|
strokeColor: typeof StrokeColor;
|
|
18
21
|
cornerRounding: NumberConstructor;
|
|
22
|
+
filled: {
|
|
23
|
+
type: BooleanConstructor;
|
|
24
|
+
description: string;
|
|
25
|
+
};
|
|
26
|
+
reverse: {
|
|
27
|
+
type: BooleanConstructor;
|
|
28
|
+
description: string;
|
|
29
|
+
};
|
|
19
30
|
};
|
|
20
31
|
constructor();
|
|
21
32
|
ready(): Promise<void>;
|
|
33
|
+
attributeChangedCallback(_name: string, oldValue: string | null, newValue: string | null): void;
|
|
22
34
|
private _drawSvg;
|
|
23
35
|
createZpl(): string;
|
|
24
36
|
}
|
|
@@ -15,15 +15,26 @@ export class ZplGraphicBox extends BaseCustomWebComponentConstructorAppend {
|
|
|
15
15
|
</div>
|
|
16
16
|
`;
|
|
17
17
|
static is = 'zpl-graphic-box';
|
|
18
|
+
static get observedAttributes() { return ['stroke-width', 'stroke-color', 'corner-rounding', 'filled', 'reverse']; }
|
|
18
19
|
strokeWidth = 1;
|
|
19
20
|
strokeColor = 'black';
|
|
20
21
|
cornerRounding;
|
|
22
|
+
filled = false;
|
|
23
|
+
reverse = false;
|
|
21
24
|
_box;
|
|
22
25
|
_observer;
|
|
23
26
|
static properties = {
|
|
24
27
|
strokeWidth: Number,
|
|
25
28
|
strokeColor: StrokeColor,
|
|
26
29
|
cornerRounding: Number,
|
|
30
|
+
filled: {
|
|
31
|
+
type: Boolean,
|
|
32
|
+
description: 'Fill the complete box. ZPL encodes this by using at least the shorter side as ^GB thickness.'
|
|
33
|
+
},
|
|
34
|
+
reverse: {
|
|
35
|
+
type: Boolean,
|
|
36
|
+
description: 'Invert this graphic field against objects printed before it (^FR).'
|
|
37
|
+
},
|
|
27
38
|
};
|
|
28
39
|
constructor() {
|
|
29
40
|
super();
|
|
@@ -40,13 +51,27 @@ export class ZplGraphicBox extends BaseCustomWebComponentConstructorAppend {
|
|
|
40
51
|
this.cornerRounding = 0;
|
|
41
52
|
this._drawSvg();
|
|
42
53
|
}
|
|
54
|
+
attributeChangedCallback(_name, oldValue, newValue) {
|
|
55
|
+
if (oldValue === newValue || !this._box)
|
|
56
|
+
return;
|
|
57
|
+
this._parseAttributesToProperties();
|
|
58
|
+
this._drawSvg();
|
|
59
|
+
}
|
|
43
60
|
_drawSvg() {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
61
|
+
const filled = this.hasAttribute('filled');
|
|
62
|
+
const reverse = this.hasAttribute('reverse');
|
|
63
|
+
// A white shape using difference compositing is the browser equivalent
|
|
64
|
+
// of ZPL's reverse-field knockout: white label pixels become black and
|
|
65
|
+
// black pixels from earlier fields become white.
|
|
66
|
+
this.style.mixBlendMode = reverse ? 'difference' : '';
|
|
67
|
+
const elementWidth = parseInt(this.style.width.replace("px", "")) || this.clientWidth || 1;
|
|
68
|
+
const elementHeight = parseInt(this.style.height.replace("px", "")) || this.clientHeight || 1;
|
|
69
|
+
const x = filled ? 0 : this.strokeWidth / 2;
|
|
70
|
+
let width = filled ? elementWidth : elementWidth - this.strokeWidth;
|
|
71
|
+
if (!filled && width < this.strokeWidth)
|
|
47
72
|
width = this.strokeWidth;
|
|
48
|
-
let height =
|
|
49
|
-
if (height < this.strokeWidth)
|
|
73
|
+
let height = filled ? elementHeight : elementHeight - this.strokeWidth;
|
|
74
|
+
if (!filled && height < this.strokeWidth)
|
|
50
75
|
height = this.strokeWidth;
|
|
51
76
|
let smallerLength = width;
|
|
52
77
|
if (smallerLength > height)
|
|
@@ -54,19 +79,23 @@ export class ZplGraphicBox extends BaseCustomWebComponentConstructorAppend {
|
|
|
54
79
|
let radius = (1 / 8) * this.cornerRounding * smallerLength / 2;
|
|
55
80
|
let svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
56
81
|
let rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
rect.setAttribute("stroke
|
|
82
|
+
const paint = reverse || this.strokeColor == StrokeColor.white ? 'white' : 'black';
|
|
83
|
+
// Very thin filled ^GB fields (for example 700x3 with thickness 3)
|
|
84
|
+
// can lose their SVG paint when the browser clips the inline SVG line
|
|
85
|
+
// box. Paint the backing div too so horizontal/vertical rules remain
|
|
86
|
+
// visible at their exact ZPL dimensions.
|
|
87
|
+
this._box.style.backgroundColor = filled ? paint : 'transparent';
|
|
88
|
+
rect.setAttribute("stroke", filled ? "none" : paint);
|
|
89
|
+
rect.setAttribute("fill", filled ? paint : "none");
|
|
90
|
+
rect.setAttribute("stroke-width", filled ? "0" : this.strokeWidth.toString());
|
|
64
91
|
rect.setAttribute("x", x.toString());
|
|
65
92
|
rect.setAttribute("y", x.toString());
|
|
66
93
|
rect.setAttribute("rx", radius.toString());
|
|
67
94
|
rect.setAttribute("ry", radius.toString());
|
|
68
95
|
rect.setAttribute("width", width.toString());
|
|
69
96
|
rect.setAttribute("height", height.toString());
|
|
97
|
+
svg.setAttribute("width", "100%");
|
|
98
|
+
svg.setAttribute("height", "100%");
|
|
70
99
|
svg.style.overflow = "visible";
|
|
71
100
|
if (this._box.childElementCount > 0)
|
|
72
101
|
this._box.removeChild(this._box.children[0]);
|
|
@@ -74,12 +103,19 @@ export class ZplGraphicBox extends BaseCustomWebComponentConstructorAppend {
|
|
|
74
103
|
this._box.appendChild(svg);
|
|
75
104
|
}
|
|
76
105
|
createZpl() {
|
|
106
|
+
const width = Number(this.style.width.replace("px", ""));
|
|
107
|
+
const height = Number(this.style.height.replace("px", ""));
|
|
108
|
+
const thickness = this.hasAttribute('filled')
|
|
109
|
+
? Math.max(this.strokeWidth, Math.min(width, height))
|
|
110
|
+
: this.strokeWidth;
|
|
77
111
|
let zpl = "";
|
|
78
112
|
zpl += getZplCoordinates(this, 0);
|
|
113
|
+
if (this.hasAttribute('reverse'))
|
|
114
|
+
zpl += "^FR";
|
|
79
115
|
zpl += "^GB"
|
|
80
116
|
+ this.style.width.replace("px", "") + ","
|
|
81
117
|
+ this.style.height.replace("px", "") + ","
|
|
82
|
-
+
|
|
118
|
+
+ thickness + ","
|
|
83
119
|
+ (this.strokeColor == StrokeColor.black ? "B" : "W") + ","
|
|
84
120
|
+ this.cornerRounding;
|
|
85
121
|
zpl += "^FS";
|
|
@@ -7,6 +7,7 @@ export declare class ZplGraphicCircle extends BaseCustomWebComponentConstructorA
|
|
|
7
7
|
static readonly style: CSSStyleSheet;
|
|
8
8
|
static readonly template: HTMLTemplateElement;
|
|
9
9
|
static readonly is = "zpl-graphic-circle";
|
|
10
|
+
static get observedAttributes(): string[];
|
|
10
11
|
strokeWidth: number;
|
|
11
12
|
strokeColor: string;
|
|
12
13
|
private _circle;
|
|
@@ -17,6 +18,7 @@ export declare class ZplGraphicCircle extends BaseCustomWebComponentConstructorA
|
|
|
17
18
|
};
|
|
18
19
|
constructor();
|
|
19
20
|
ready(): Promise<void>;
|
|
21
|
+
attributeChangedCallback(_name: string, oldValue: string | null, newValue: string | null): void;
|
|
20
22
|
private _drawSvg;
|
|
21
23
|
createZpl(): string;
|
|
22
24
|
}
|
|
@@ -15,6 +15,7 @@ export class ZplGraphicCircle extends BaseCustomWebComponentConstructorAppend {
|
|
|
15
15
|
</div>
|
|
16
16
|
`;
|
|
17
17
|
static is = 'zpl-graphic-circle';
|
|
18
|
+
static get observedAttributes() { return ['stroke-width', 'stroke-color']; }
|
|
18
19
|
strokeWidth = 1;
|
|
19
20
|
strokeColor = 'black';
|
|
20
21
|
_circle;
|
|
@@ -34,6 +35,12 @@ export class ZplGraphicCircle extends BaseCustomWebComponentConstructorAppend {
|
|
|
34
35
|
this._parseAttributesToProperties();
|
|
35
36
|
this._drawSvg();
|
|
36
37
|
}
|
|
38
|
+
attributeChangedCallback(_name, oldValue, newValue) {
|
|
39
|
+
if (oldValue === newValue || !this._circle)
|
|
40
|
+
return;
|
|
41
|
+
this._parseAttributesToProperties();
|
|
42
|
+
this._drawSvg();
|
|
43
|
+
}
|
|
37
44
|
_drawSvg() {
|
|
38
45
|
let w = parseInt(this.style.width.replace("px", ""));
|
|
39
46
|
let h = parseInt(this.style.height.replace("px", ""));
|
|
@@ -11,6 +11,7 @@ export declare class ZplGraphicDiagonalLine extends BaseCustomWebComponentConstr
|
|
|
11
11
|
static readonly style: CSSStyleSheet;
|
|
12
12
|
static readonly template: HTMLTemplateElement;
|
|
13
13
|
static readonly is = "zpl-graphic-diagonal-line";
|
|
14
|
+
static get observedAttributes(): string[];
|
|
14
15
|
strokeWidth: number;
|
|
15
16
|
strokeColor: string;
|
|
16
17
|
orientation: string;
|
|
@@ -23,6 +24,7 @@ export declare class ZplGraphicDiagonalLine extends BaseCustomWebComponentConstr
|
|
|
23
24
|
};
|
|
24
25
|
constructor();
|
|
25
26
|
ready(): Promise<void>;
|
|
27
|
+
attributeChangedCallback(_name: string, oldValue: string | null, newValue: string | null): void;
|
|
26
28
|
private _drawSvg;
|
|
27
29
|
createZpl(): string;
|
|
28
30
|
}
|
|
@@ -20,6 +20,7 @@ export class ZplGraphicDiagonalLine extends BaseCustomWebComponentConstructorApp
|
|
|
20
20
|
</div>
|
|
21
21
|
`;
|
|
22
22
|
static is = 'zpl-graphic-diagonal-line';
|
|
23
|
+
static get observedAttributes() { return ['stroke-width', 'stroke-color', 'orientation']; }
|
|
23
24
|
strokeWidth = 1;
|
|
24
25
|
strokeColor = "black";
|
|
25
26
|
orientation;
|
|
@@ -41,6 +42,12 @@ export class ZplGraphicDiagonalLine extends BaseCustomWebComponentConstructorApp
|
|
|
41
42
|
this._parseAttributesToProperties();
|
|
42
43
|
this._drawSvg();
|
|
43
44
|
}
|
|
45
|
+
attributeChangedCallback(_name, oldValue, newValue) {
|
|
46
|
+
if (oldValue === newValue || !this._line)
|
|
47
|
+
return;
|
|
48
|
+
this._parseAttributesToProperties();
|
|
49
|
+
this._drawSvg();
|
|
50
|
+
}
|
|
44
51
|
_drawSvg() {
|
|
45
52
|
let w = parseInt(this.style.width.replace("px", ""));
|
|
46
53
|
let h = parseInt(this.style.height.replace("px", "")) - this.strokeWidth;
|
|
@@ -3,6 +3,7 @@ export declare class ZplImage extends BaseCustomWebComponentConstructorAppend {
|
|
|
3
3
|
static readonly style: CSSStyleSheet;
|
|
4
4
|
static readonly template: HTMLTemplateElement;
|
|
5
5
|
static readonly is = "zpl-image";
|
|
6
|
+
static get observedAttributes(): string[];
|
|
6
7
|
private _image;
|
|
7
8
|
private _wrapper;
|
|
8
9
|
totalBytes: number;
|
|
@@ -20,7 +21,9 @@ export declare class ZplImage extends BaseCustomWebComponentConstructorAppend {
|
|
|
20
21
|
scaleY: NumberConstructor;
|
|
21
22
|
};
|
|
22
23
|
constructor();
|
|
23
|
-
ready():
|
|
24
|
+
ready(): void;
|
|
25
|
+
attributeChangedCallback(_name: string, oldValue: string | null, newValue: string | null): void;
|
|
26
|
+
private _renderImage;
|
|
24
27
|
createZplImage(): string;
|
|
25
28
|
createZpl(): string;
|
|
26
29
|
private acsToCanvas;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { BaseCustomWebComponentConstructorAppend, css, html } from "@node-projects/base-custom-webcomponent";
|
|
2
|
-
import { requestAnimationFramePromise } from "@node-projects/web-component-designer";
|
|
3
2
|
import { getZplCoordinates } from "../zplHelper.js";
|
|
4
3
|
export class ZplImage extends BaseCustomWebComponentConstructorAppend {
|
|
5
4
|
static style = css ` *{
|
|
@@ -13,6 +12,9 @@ export class ZplImage extends BaseCustomWebComponentConstructorAppend {
|
|
|
13
12
|
</div>
|
|
14
13
|
`;
|
|
15
14
|
static is = 'zpl-image';
|
|
15
|
+
static get observedAttributes() {
|
|
16
|
+
return ['total-bytes', 'bytes-per-row', 'image-name', 'hex-image', 'scale-x', 'scale-y'];
|
|
17
|
+
}
|
|
16
18
|
_image;
|
|
17
19
|
_wrapper;
|
|
18
20
|
totalBytes;
|
|
@@ -35,26 +37,27 @@ export class ZplImage extends BaseCustomWebComponentConstructorAppend {
|
|
|
35
37
|
this._image = this._getDomElement("image-div");
|
|
36
38
|
this._wrapper = this._getDomElement("wrapper");
|
|
37
39
|
}
|
|
38
|
-
|
|
40
|
+
ready() {
|
|
41
|
+
this._parseAttributesToProperties();
|
|
42
|
+
this._renderImage();
|
|
43
|
+
}
|
|
44
|
+
attributeChangedCallback(_name, oldValue, newValue) {
|
|
45
|
+
if (oldValue === newValue || !this._image)
|
|
46
|
+
return;
|
|
39
47
|
this._parseAttributesToProperties();
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
this.scaleX = 10;
|
|
46
|
-
if (this.scaleX > 10)
|
|
47
|
-
this.scaleX = 10;
|
|
48
|
+
this._renderImage();
|
|
49
|
+
}
|
|
50
|
+
_renderImage() {
|
|
51
|
+
this.scaleX = Math.max(1, Math.min(10, Number(this.scaleX) || 1));
|
|
52
|
+
this.scaleY = Math.max(1, Math.min(10, Number(this.scaleY) || 1));
|
|
48
53
|
if (this.hexImage && this.bytesPerRow)
|
|
49
54
|
this.acsToCanvas(this.hexImage, this.bytesPerRow);
|
|
50
55
|
// this._image.style.width = 100 * this.scaleX + "%";
|
|
51
56
|
// this._image.style.aspectRatio = (this.scaleX / this.scaleY).toString();
|
|
52
57
|
this._image.style.transformOrigin = "0 0";
|
|
53
58
|
this._image.style.transform = "scaleX(" + this.scaleX + ") " + "scaleY(" + this.scaleY + ")";
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
this._wrapper.style.width = rect.width + "px";
|
|
57
|
-
this._wrapper.style.height = rect.height + "px";
|
|
59
|
+
this._wrapper.style.width = this._image.width * this.scaleX + "px";
|
|
60
|
+
this._wrapper.style.height = this._image.height * this.scaleY + "px";
|
|
58
61
|
}
|
|
59
62
|
createZplImage() {
|
|
60
63
|
let zpl = "";
|