@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
|
@@ -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,33 +51,49 @@ 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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
+
const width = filled ? elementWidth : Math.max(0, elementWidth - this.strokeWidth);
|
|
71
|
+
const height = filled ? elementHeight : Math.max(0, elementHeight - this.strokeWidth);
|
|
51
72
|
let smallerLength = width;
|
|
52
73
|
if (smallerLength > height)
|
|
53
74
|
smallerLength = height;
|
|
54
75
|
let radius = (1 / 8) * this.cornerRounding * smallerLength / 2;
|
|
55
76
|
let svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
56
77
|
let rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
78
|
+
const paint = reverse || this.strokeColor == StrokeColor.white ? 'white' : 'black';
|
|
79
|
+
// Opposing strokes overlap when twice the thickness reaches the short
|
|
80
|
+
// side (for example ^GB300,7,5). Zebra therefore paints a solid rule.
|
|
81
|
+
// Back it with the same paint so a sub-line-height SVG cannot vanish
|
|
82
|
+
// when clipped by the designer, without changing the stored thickness.
|
|
83
|
+
const overlappingStroke = 2 * this.strokeWidth >= Math.min(elementWidth, elementHeight);
|
|
84
|
+
this._box.style.backgroundColor = filled || overlappingStroke ? paint : 'transparent';
|
|
85
|
+
rect.setAttribute("stroke", filled ? "none" : paint);
|
|
86
|
+
rect.setAttribute("fill", filled ? paint : "none");
|
|
87
|
+
rect.setAttribute("stroke-width", filled ? "0" : this.strokeWidth.toString());
|
|
64
88
|
rect.setAttribute("x", x.toString());
|
|
65
89
|
rect.setAttribute("y", x.toString());
|
|
66
90
|
rect.setAttribute("rx", radius.toString());
|
|
67
91
|
rect.setAttribute("ry", radius.toString());
|
|
68
92
|
rect.setAttribute("width", width.toString());
|
|
69
93
|
rect.setAttribute("height", height.toString());
|
|
94
|
+
svg.setAttribute("width", "100%");
|
|
95
|
+
svg.setAttribute("height", "100%");
|
|
96
|
+
svg.style.display = "block";
|
|
70
97
|
svg.style.overflow = "visible";
|
|
71
98
|
if (this._box.childElementCount > 0)
|
|
72
99
|
this._box.removeChild(this._box.children[0]);
|
|
@@ -74,12 +101,19 @@ export class ZplGraphicBox extends BaseCustomWebComponentConstructorAppend {
|
|
|
74
101
|
this._box.appendChild(svg);
|
|
75
102
|
}
|
|
76
103
|
createZpl() {
|
|
104
|
+
const width = Number(this.style.width.replace("px", ""));
|
|
105
|
+
const height = Number(this.style.height.replace("px", ""));
|
|
106
|
+
const thickness = this.hasAttribute('filled')
|
|
107
|
+
? Math.max(this.strokeWidth, Math.min(width, height))
|
|
108
|
+
: this.strokeWidth;
|
|
77
109
|
let zpl = "";
|
|
78
110
|
zpl += getZplCoordinates(this, 0);
|
|
111
|
+
if (this.hasAttribute('reverse'))
|
|
112
|
+
zpl += "^FR";
|
|
79
113
|
zpl += "^GB"
|
|
80
114
|
+ this.style.width.replace("px", "") + ","
|
|
81
115
|
+ this.style.height.replace("px", "") + ","
|
|
82
|
-
+
|
|
116
|
+
+ thickness + ","
|
|
83
117
|
+ (this.strokeColor == StrokeColor.black ? "B" : "W") + ","
|
|
84
118
|
+ this.cornerRounding;
|
|
85
119
|
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 = "";
|
|
@@ -1,25 +1,55 @@
|
|
|
1
|
-
import { BaseCustomWebComponentConstructorAppend } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { BaseCustomWebComponentConstructorAppend } from '@node-projects/base-custom-webcomponent';
|
|
2
|
+
import { ZplFontName } from '../fonts/zplFonts.js';
|
|
3
|
+
type ZplRotation = 'N' | 'R' | 'I' | 'B';
|
|
4
|
+
/** Compensate for the printer font origin without moving preview ink outside its design box. */
|
|
5
|
+
export declare const zplTextOutputOriginCorrection = 3;
|
|
6
|
+
export declare function getZplTextOutputOffset(rotation: ZplRotation): {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
};
|
|
6
10
|
export declare class ZplText extends BaseCustomWebComponentConstructorAppend {
|
|
7
11
|
static readonly style: CSSStyleSheet;
|
|
8
12
|
static readonly template: HTMLTemplateElement;
|
|
9
13
|
static readonly is = "zpl-text";
|
|
14
|
+
static get observedAttributes(): string[];
|
|
10
15
|
content: string;
|
|
11
|
-
fontName:
|
|
16
|
+
fontName: ZplFontName;
|
|
12
17
|
fontHeight: number;
|
|
13
18
|
fontWidth: number;
|
|
19
|
+
rotation: ZplRotation;
|
|
14
20
|
private _text;
|
|
21
|
+
private _frame;
|
|
22
|
+
private _fontLoadStarted;
|
|
23
|
+
private _widgetReady;
|
|
24
|
+
private _inlineEditing;
|
|
15
25
|
static readonly properties: {
|
|
16
26
|
content: StringConstructor;
|
|
17
|
-
fontName:
|
|
27
|
+
fontName: StringConstructor;
|
|
18
28
|
fontHeight: NumberConstructor;
|
|
19
29
|
fontWidth: NumberConstructor;
|
|
30
|
+
rotation: StringConstructor;
|
|
20
31
|
};
|
|
21
32
|
constructor();
|
|
22
|
-
ready():
|
|
33
|
+
ready(): void;
|
|
34
|
+
attributeChangedCallback(_name: string, oldValue: string | null, newValue: string | null): void;
|
|
35
|
+
/** Called by the property service as well as native attribute callbacks. */
|
|
36
|
+
refreshFromAttributes(): void;
|
|
37
|
+
renderText(): void;
|
|
38
|
+
/**
|
|
39
|
+
* Text elements can temporarily have no layout box while the designer
|
|
40
|
+
* switches views. Canvas measurement keeps scalable Font 0 selectable in
|
|
41
|
+
* that state; the final approximation is only for DOM implementations
|
|
42
|
+
* without canvas support (notably unit-test DOMs).
|
|
43
|
+
*/
|
|
44
|
+
private _measureTextWithoutLayout;
|
|
45
|
+
/** Starts plain-text editing inside the widget's shadow DOM. */
|
|
46
|
+
beginInlineEdit(): void;
|
|
47
|
+
refreshInlineEditBounds(): void;
|
|
48
|
+
get inlineEditElement(): HTMLDivElement;
|
|
49
|
+
get inlineEditContent(): string;
|
|
50
|
+
finishInlineEdit(): void;
|
|
51
|
+
private _ensureFontsLoaded;
|
|
52
|
+
private _setRotatedBounds;
|
|
23
53
|
createZpl(): string;
|
|
24
54
|
}
|
|
25
55
|
export {};
|
package/dist/widgets/zpl-text.js
CHANGED
|
@@ -1,69 +1,203 @@
|
|
|
1
|
-
import { BaseCustomWebComponentConstructorAppend, css, html } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { BaseCustomWebComponentConstructorAppend, css, html } from '@node-projects/base-custom-webcomponent';
|
|
2
|
+
import { applyDeviceFontCase, getDeviceFontMetrics, loadZplFonts, zplFontFamilies } from '../fonts/zplFonts.js';
|
|
3
|
+
import { getZplCoordinates } from '../zplHelper.js';
|
|
4
|
+
/** Compensate for the printer font origin without moving preview ink outside its design box. */
|
|
5
|
+
export const zplTextOutputOriginCorrection = 3;
|
|
6
|
+
export function getZplTextOutputOffset(rotation) {
|
|
7
|
+
switch (rotation) {
|
|
8
|
+
case 'R': return { x: -zplTextOutputOriginCorrection, y: 0 };
|
|
9
|
+
case 'I': return { x: 0, y: -zplTextOutputOriginCorrection };
|
|
10
|
+
case 'B': return { x: zplTextOutputOriginCorrection, y: 0 };
|
|
11
|
+
default: return { x: 0, y: zplTextOutputOriginCorrection };
|
|
12
|
+
}
|
|
13
|
+
}
|
|
8
14
|
export class ZplText extends BaseCustomWebComponentConstructorAppend {
|
|
9
15
|
static style = css `
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
`;
|
|
14
|
-
static template = html `
|
|
15
|
-
<div id="text-div" style="width: 100%; height: 100%; pointer-events: none">
|
|
16
|
-
</div>
|
|
16
|
+
:host { display: block; min-width: 1px; min-height: 1px; }
|
|
17
|
+
#text-frame { position: relative; transform-origin: 0 0; width: max-content; height: max-content; }
|
|
18
|
+
#text-div { display: inline-block; white-space: pre; transform-origin: 0 0; line-height: 1; }
|
|
17
19
|
`;
|
|
20
|
+
static template = html `<div id="text-frame"><div id="text-div"></div></div>`;
|
|
18
21
|
static is = 'zpl-text';
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
static get observedAttributes() {
|
|
23
|
+
return ['content', 'font-name', 'font-height', 'font-width', 'rotation'];
|
|
24
|
+
}
|
|
25
|
+
content = '';
|
|
26
|
+
fontName = '0';
|
|
27
|
+
fontHeight = 30;
|
|
28
|
+
fontWidth = 0;
|
|
29
|
+
rotation = 'N';
|
|
23
30
|
_text;
|
|
31
|
+
_frame;
|
|
32
|
+
_fontLoadStarted = false;
|
|
33
|
+
_widgetReady = false;
|
|
34
|
+
_inlineEditing = false;
|
|
24
35
|
static properties = {
|
|
25
|
-
content: String,
|
|
26
|
-
fontName: FontNames,
|
|
27
|
-
fontHeight: Number,
|
|
28
|
-
fontWidth: Number
|
|
36
|
+
content: String, fontName: String, fontHeight: Number, fontWidth: Number, rotation: String
|
|
29
37
|
};
|
|
30
38
|
constructor() {
|
|
31
39
|
super();
|
|
32
40
|
this._restoreCachedInititalValues();
|
|
33
|
-
this._text = this._getDomElement(
|
|
41
|
+
this._text = this._getDomElement('text-div');
|
|
42
|
+
this._frame = this._getDomElement('text-frame');
|
|
34
43
|
}
|
|
35
|
-
|
|
44
|
+
ready() {
|
|
45
|
+
this._widgetReady = true;
|
|
46
|
+
this.refreshFromAttributes();
|
|
47
|
+
this._ensureFontsLoaded();
|
|
48
|
+
}
|
|
49
|
+
attributeChangedCallback(_name, oldValue, newValue) {
|
|
50
|
+
if (oldValue === newValue || !this._widgetReady)
|
|
51
|
+
return;
|
|
52
|
+
this.refreshFromAttributes();
|
|
53
|
+
}
|
|
54
|
+
/** Called by the property service as well as native attribute callbacks. */
|
|
55
|
+
refreshFromAttributes() {
|
|
36
56
|
this._parseAttributesToProperties();
|
|
37
|
-
this.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
57
|
+
this.renderText();
|
|
58
|
+
}
|
|
59
|
+
renderText() {
|
|
60
|
+
const font = /^[0A-H]$/.test(this.fontName) ? this.fontName : '0';
|
|
61
|
+
const metrics = getDeviceFontMetrics(font, this.fontHeight, this.fontWidth);
|
|
62
|
+
const fontSize = metrics?.fontSize ?? Math.max(1, this.fontHeight);
|
|
63
|
+
const scaleX = metrics?.scaleX ?? (this.fontWidth > 0 ? this.fontWidth / this.fontHeight : 1);
|
|
64
|
+
// PrintLab's browser line box drifts progressively below Zebra Font 0
|
|
65
|
+
// as the requested em grows. This curve is calibrated against one
|
|
66
|
+
// batched 15..240-dot printer fixture and keeps the visible ink inside
|
|
67
|
+
// the ZPL-origin selection frame (rather than moving the element).
|
|
68
|
+
const scalableFontYOffset = font === '0'
|
|
69
|
+
? -Math.max(0, Math.round((this.fontHeight - 60) * .12))
|
|
70
|
+
: 0;
|
|
71
|
+
const displayedContent = applyDeviceFontCase(font, this.content ?? '');
|
|
72
|
+
if (!this._inlineEditing)
|
|
73
|
+
this._text.textContent = displayedContent;
|
|
74
|
+
this._text.style.fontFamily = `"${zplFontFamilies[font]}", monospace`;
|
|
75
|
+
this._text.style.fontSize = `${fontSize}px`;
|
|
76
|
+
this._text.style.fontWeight = font === '0' ? 'bold' : 'normal';
|
|
77
|
+
this._text.style.letterSpacing = `${metrics?.letterSpacing ?? 0}px`;
|
|
78
|
+
this._text.style.transform = `translate(${metrics?.xOffset ?? 0}px, ${(metrics?.yOffset ?? 0) + scalableFontYOffset}px) scaleX(${scaleX})`;
|
|
79
|
+
// Force layout here. Resize strategies need the quantized bounds in the
|
|
80
|
+
// same pointer event, rather than one animation frame later.
|
|
81
|
+
const layoutWidth = this._text.scrollWidth;
|
|
82
|
+
const rawWidth = Math.max(1, layoutWidth || this._measureTextWithoutLayout(displayedContent, fontSize, font));
|
|
83
|
+
// Device fonts are fixed-cell bitmap fonts, so their printed advance is
|
|
84
|
+
// deterministic. Do not depend on scrollWidth: it is zero while the
|
|
85
|
+
// designer is hidden or being moved into split view, which previously
|
|
86
|
+
// collapsed the host selection box while its glyphs overflowed it.
|
|
87
|
+
const width = metrics
|
|
88
|
+
? Math.max(1, [...displayedContent].length * metrics.characterAdvance + Math.abs(metrics.xOffset))
|
|
89
|
+
: Math.max(1, rawWidth * scaleX);
|
|
90
|
+
const height = Math.max(1, fontSize + Math.abs(metrics?.yOffset ?? 0));
|
|
91
|
+
this._setRotatedBounds(width, height, this.rotation);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Text elements can temporarily have no layout box while the designer
|
|
95
|
+
* switches views. Canvas measurement keeps scalable Font 0 selectable in
|
|
96
|
+
* that state; the final approximation is only for DOM implementations
|
|
97
|
+
* without canvas support (notably unit-test DOMs).
|
|
98
|
+
*/
|
|
99
|
+
_measureTextWithoutLayout(content, fontSize, font) {
|
|
100
|
+
try {
|
|
101
|
+
if (!this.ownerDocument.defaultView?.navigator.userAgent.includes('jsdom')) {
|
|
102
|
+
const canvas = this.ownerDocument.createElement('canvas');
|
|
103
|
+
const context = canvas.getContext('2d');
|
|
104
|
+
if (context) {
|
|
105
|
+
context.font = `${font === '0' ? 'bold ' : ''}${fontSize}px "${zplFontFamilies[font]}", monospace`;
|
|
106
|
+
return context.measureText(content).width;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch { /* use deterministic fallback */ }
|
|
111
|
+
return [...content].length * fontSize * .6;
|
|
112
|
+
}
|
|
113
|
+
/** Starts plain-text editing inside the widget's shadow DOM. */
|
|
114
|
+
beginInlineEdit() {
|
|
115
|
+
if (this._inlineEditing)
|
|
116
|
+
return;
|
|
117
|
+
this._inlineEditing = true;
|
|
118
|
+
this._text.textContent = this.content ?? '';
|
|
119
|
+
this._text.setAttribute('contenteditable', 'plaintext-only');
|
|
120
|
+
this._text.spellcheck = false;
|
|
121
|
+
this._text.style.cursor = 'text';
|
|
122
|
+
this._text.style.userSelect = 'text';
|
|
123
|
+
this._text.style.outline = 'none';
|
|
124
|
+
this.refreshInlineEditBounds();
|
|
125
|
+
this._text.focus({ preventScroll: true });
|
|
126
|
+
const selection = this.ownerDocument.getSelection();
|
|
127
|
+
if (selection) {
|
|
128
|
+
const range = this.ownerDocument.createRange();
|
|
129
|
+
range.selectNodeContents(this._text);
|
|
130
|
+
range.collapse(false);
|
|
131
|
+
selection.removeAllRanges();
|
|
132
|
+
selection.addRange(range);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
refreshInlineEditBounds() {
|
|
136
|
+
if (!this._inlineEditing)
|
|
137
|
+
return;
|
|
138
|
+
const value = this.inlineEditContent;
|
|
139
|
+
const font = /^[0A-H]$/.test(this.fontName) ? this.fontName : '0';
|
|
140
|
+
const metrics = getDeviceFontMetrics(font, this.fontHeight, this.fontWidth);
|
|
141
|
+
const fontSize = metrics?.fontSize ?? Math.max(1, this.fontHeight);
|
|
142
|
+
const scaleX = metrics?.scaleX ?? (this.fontWidth > 0 ? this.fontWidth / this.fontHeight : 1);
|
|
143
|
+
const layoutWidth = this._text.scrollWidth;
|
|
144
|
+
const width = metrics
|
|
145
|
+
? Math.max(1, [...value].length * metrics.characterAdvance + Math.abs(metrics.xOffset))
|
|
146
|
+
: Math.max(1, (layoutWidth || this._measureTextWithoutLayout(value, fontSize, font)) * scaleX);
|
|
147
|
+
const height = Math.max(1, fontSize + Math.abs(metrics?.yOffset ?? 0));
|
|
148
|
+
this._setRotatedBounds(width, height, this.rotation);
|
|
149
|
+
}
|
|
150
|
+
get inlineEditElement() { return this._text; }
|
|
151
|
+
get inlineEditContent() {
|
|
152
|
+
return (this._text.textContent ?? '').replace(/[\r\n]+/g, ' ');
|
|
153
|
+
}
|
|
154
|
+
finishInlineEdit() {
|
|
155
|
+
if (!this._inlineEditing)
|
|
156
|
+
return;
|
|
157
|
+
this._inlineEditing = false;
|
|
158
|
+
this._text.removeAttribute('contenteditable');
|
|
159
|
+
this._text.spellcheck = true;
|
|
160
|
+
this._text.style.cursor = '';
|
|
161
|
+
this._text.style.userSelect = '';
|
|
162
|
+
this._text.style.outline = '';
|
|
163
|
+
this.renderText();
|
|
164
|
+
}
|
|
165
|
+
_ensureFontsLoaded() {
|
|
166
|
+
if (this._fontLoadStarted)
|
|
167
|
+
return;
|
|
168
|
+
this._fontLoadStarted = true;
|
|
169
|
+
void loadZplFonts(this.ownerDocument)
|
|
170
|
+
.then(() => this.renderText())
|
|
171
|
+
.catch(() => { });
|
|
172
|
+
}
|
|
173
|
+
_setRotatedBounds(width, height, rotation) {
|
|
174
|
+
this._frame.style.width = `${width}px`;
|
|
175
|
+
this._frame.style.height = `${height}px`;
|
|
176
|
+
this._frame.style.transform = '';
|
|
177
|
+
switch (rotation) {
|
|
178
|
+
case 'R':
|
|
179
|
+
this._frame.style.transform = `translateX(${height}px) rotate(90deg)`;
|
|
180
|
+
this.style.width = `${height}px`;
|
|
181
|
+
this.style.height = `${width}px`;
|
|
182
|
+
break;
|
|
183
|
+
case 'I':
|
|
184
|
+
this._frame.style.transform = `translate(${width}px, ${height}px) rotate(180deg)`;
|
|
185
|
+
this.style.width = `${width}px`;
|
|
186
|
+
this.style.height = `${height}px`;
|
|
45
187
|
break;
|
|
46
|
-
case
|
|
47
|
-
this.
|
|
48
|
-
this.
|
|
49
|
-
this.
|
|
188
|
+
case 'B':
|
|
189
|
+
this._frame.style.transform = `translateY(${width}px) rotate(270deg)`;
|
|
190
|
+
this.style.width = `${height}px`;
|
|
191
|
+
this.style.height = `${width}px`;
|
|
50
192
|
break;
|
|
193
|
+
default:
|
|
194
|
+
this.style.width = `${width}px`;
|
|
195
|
+
this.style.height = `${height}px`;
|
|
51
196
|
}
|
|
52
|
-
this.style.width = '';
|
|
53
|
-
this.style.height = '';
|
|
54
|
-
requestAnimationFrame(() => {
|
|
55
|
-
let rect = this._text.getBoundingClientRect();
|
|
56
|
-
this.style.width = rect.width + 'px';
|
|
57
|
-
this.style.height = rect.height / 2 + 'px';
|
|
58
|
-
});
|
|
59
197
|
}
|
|
60
198
|
createZpl() {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
zpl += "^CF" + this.fontName + "," + this.fontHeight + "," + this.fontWidth;
|
|
64
|
-
zpl += "^FD" + this.content;
|
|
65
|
-
zpl += "^FS";
|
|
66
|
-
return zpl;
|
|
199
|
+
const offset = getZplTextOutputOffset(this.rotation);
|
|
200
|
+
return `${getZplCoordinates(this, 0, offset.x, offset.y)}^A${this.fontName}${this.rotation},${this.fontHeight},${this.fontWidth}^FD${this.content}^FS`;
|
|
67
201
|
}
|
|
68
202
|
}
|
|
69
203
|
customElements.define(ZplText.is, ZplText);
|
package/dist/zplHelper.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getZplCoordinates(obj: any, alignment: 0 | 1 | 2): string;
|
|
1
|
+
export declare function getZplCoordinates(obj: any, alignment: 0 | 1 | 2, xOffset?: number, yOffset?: number): string;
|