@node-projects/web-component-designer-zpl 0.1.0

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.
Files changed (34) hide show
  1. package/README.md +15 -0
  2. package/dist/extensions/ZplLayoutResizeExtensionProvider.d.ts +4 -0
  3. package/dist/extensions/ZplLayoutResizeExtensionProvider.js +16 -0
  4. package/dist/index.d.ts +15 -0
  5. package/dist/index.js +15 -0
  6. package/dist/jsBarcodeOptions.d.ts +27 -0
  7. package/dist/jsBarcodeOptions.js +14 -0
  8. package/dist/qr.d.ts +11 -0
  9. package/dist/qr.js +759 -0
  10. package/dist/services/ZplImageDrop.d.ts +10 -0
  11. package/dist/services/ZplImageDrop.js +220 -0
  12. package/dist/services/ZplLayoutCopyPasteService.d.ts +6 -0
  13. package/dist/services/ZplLayoutCopyPasteService.js +19 -0
  14. package/dist/services/ZplLayoutPlacementService.d.ts +10 -0
  15. package/dist/services/ZplLayoutPlacementService.js +25 -0
  16. package/dist/services/ZplParserService.d.ts +6 -0
  17. package/dist/services/ZplParserService.js +213 -0
  18. package/dist/setupZplServiceContainer.d.ts +2 -0
  19. package/dist/setupZplServiceContainer.js +66 -0
  20. package/dist/widgets/zpl-barcode.d.ts +25 -0
  21. package/dist/widgets/zpl-barcode.js +92 -0
  22. package/dist/widgets/zpl-graphic-box.d.ts +25 -0
  23. package/dist/widgets/zpl-graphic-box.js +89 -0
  24. package/dist/widgets/zpl-graphic-circle.d.ts +23 -0
  25. package/dist/widgets/zpl-graphic-circle.js +71 -0
  26. package/dist/widgets/zpl-graphic-diagonal-line.d.ts +29 -0
  27. package/dist/widgets/zpl-graphic-diagonal-line.js +87 -0
  28. package/dist/widgets/zpl-image.d.ts +27 -0
  29. package/dist/widgets/zpl-image.js +120 -0
  30. package/dist/widgets/zpl-text.d.ts +25 -0
  31. package/dist/widgets/zpl-text.js +69 -0
  32. package/dist/zplHelper.d.ts +1 -0
  33. package/dist/zplHelper.js +5 -0
  34. package/package.json +23 -0
@@ -0,0 +1,92 @@
1
+ import { BaseCustomWebComponentConstructorAppend, LazyLoader, css, html } from "@node-projects/base-custom-webcomponent";
2
+ import { BarcodeFormat } from "../jsBarcodeOptions.js";
3
+ import { getZplCoordinates } from "../zplHelper.js";
4
+ import QRCode from "../qr.js";
5
+ export class ZplBarcode extends BaseCustomWebComponentConstructorAppend {
6
+ static style = css ` *{
7
+ box-sizing: border-box;
8
+ }
9
+ `;
10
+ static template = html `
11
+ <div id="barcode-div" style="width: 100%; height: 100%;">
12
+ </div>
13
+ `;
14
+ static is = 'zpl-barcode';
15
+ content;
16
+ type;
17
+ width;
18
+ ratio;
19
+ height;
20
+ _barcode;
21
+ _barcodeOptions;
22
+ static properties = {
23
+ content: String,
24
+ type: BarcodeFormat,
25
+ width: Number,
26
+ ratio: Number,
27
+ height: Number,
28
+ };
29
+ constructor() {
30
+ super();
31
+ this._restoreCachedInititalValues();
32
+ this._barcode = this._getDomElement("barcode-div");
33
+ }
34
+ async ready() {
35
+ this._parseAttributesToProperties();
36
+ if (this.width > 10)
37
+ this.width = 10;
38
+ if (this.width < 1)
39
+ this.width = 1;
40
+ if (this.ratio > 3.0)
41
+ this.ratio = 3.0;
42
+ if (this.ratio < 2.0)
43
+ this.ratio = 2.0;
44
+ if (this.type == BarcodeFormat.QR) {
45
+ const svg = QRCode.generateSVG(this.content, {
46
+ modulesize: this.height,
47
+ margin: 0,
48
+ background: 'transparent'
49
+ });
50
+ this._barcode.appendChild(svg);
51
+ this._barcode.style.marginTop = "10px";
52
+ }
53
+ else {
54
+ await LazyLoader.LoadJavascript("/node_modules/jsbarcode/dist/JsBarcode.all.js");
55
+ let svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
56
+ this._barcode.appendChild(svg);
57
+ this._barcode.style.marginTop = "";
58
+ this._createOptions();
59
+ //@ts-ignore
60
+ JsBarcode(svg, this.content, this._barcodeOptions);
61
+ }
62
+ }
63
+ _createOptions() {
64
+ this._barcodeOptions = {};
65
+ this._barcodeOptions.format = this.type;
66
+ this._barcodeOptions.width = this.width;
67
+ this._barcodeOptions.height = this.height;
68
+ this._barcodeOptions.margin = 0;
69
+ this._barcodeOptions.background = 'transparent';
70
+ }
71
+ createZpl() {
72
+ let zpl = "";
73
+ zpl += getZplCoordinates(this, 0);
74
+ if (this.type != BarcodeFormat.QR)
75
+ zpl += "^BY" + this.width + "," + this.ratio;
76
+ switch (this.type) {
77
+ case BarcodeFormat.CODE128:
78
+ zpl += "^BCN," + this.height + ",Y,N,Y,N";
79
+ break;
80
+ case BarcodeFormat.EAN13:
81
+ zpl += "^BCN," + this.height + ",Y,N";
82
+ break;
83
+ case BarcodeFormat.QR:
84
+ zpl += "^BQN,2," + this.height + "";
85
+ break;
86
+ }
87
+ zpl += "^FD" + this.content;
88
+ zpl += "^FS";
89
+ return zpl;
90
+ }
91
+ }
92
+ customElements.define(ZplBarcode.is, ZplBarcode);
@@ -0,0 +1,25 @@
1
+ import { BaseCustomWebComponentConstructorAppend } from "@node-projects/base-custom-webcomponent";
2
+ declare enum StrokeColor {
3
+ black = "black",
4
+ white = "white"
5
+ }
6
+ export declare class ZplGraphicBox extends BaseCustomWebComponentConstructorAppend {
7
+ static readonly style: CSSStyleSheet;
8
+ static readonly template: HTMLTemplateElement;
9
+ static readonly is = "zpl-graphic-box";
10
+ strokeWidth: number;
11
+ strokeColor: string;
12
+ cornerRounding: number;
13
+ private _box;
14
+ private _observer;
15
+ static readonly properties: {
16
+ strokeWidth: NumberConstructor;
17
+ strokeColor: typeof StrokeColor;
18
+ cornerRounding: NumberConstructor;
19
+ };
20
+ constructor();
21
+ ready(): Promise<void>;
22
+ private _drawSvg;
23
+ createZpl(): string;
24
+ }
25
+ export {};
@@ -0,0 +1,89 @@
1
+ import { BaseCustomWebComponentConstructorAppend, css, html } from "@node-projects/base-custom-webcomponent";
2
+ import { getZplCoordinates } from "../zplHelper.js";
3
+ var StrokeColor;
4
+ (function (StrokeColor) {
5
+ StrokeColor["black"] = "black";
6
+ StrokeColor["white"] = "white";
7
+ })(StrokeColor || (StrokeColor = {}));
8
+ export class ZplGraphicBox extends BaseCustomWebComponentConstructorAppend {
9
+ static style = css ` *{
10
+ box-sizing: border-box;
11
+ }
12
+ `;
13
+ static template = html `
14
+ <div id="box-div" style="width: 100%; height: 100%; overflow: hidden">
15
+ </div>
16
+ `;
17
+ static is = 'zpl-graphic-box';
18
+ strokeWidth = 1;
19
+ strokeColor = 'black';
20
+ cornerRounding;
21
+ _box;
22
+ _observer;
23
+ static properties = {
24
+ strokeWidth: Number,
25
+ strokeColor: StrokeColor,
26
+ cornerRounding: Number,
27
+ };
28
+ constructor() {
29
+ super();
30
+ this._restoreCachedInititalValues();
31
+ this._box = this._getDomElement("box-div");
32
+ this._observer = new ResizeObserver(() => this._drawSvg());
33
+ this._observer.observe(this);
34
+ }
35
+ async ready() {
36
+ this._parseAttributesToProperties();
37
+ if (this.cornerRounding > 8)
38
+ this.cornerRounding = 8;
39
+ if (this.cornerRounding < 0)
40
+ this.cornerRounding = 0;
41
+ this._drawSvg();
42
+ }
43
+ _drawSvg() {
44
+ let x = this.strokeWidth / 2;
45
+ let width = parseInt(this.style.width.replace("px", "")) - this.strokeWidth;
46
+ if (width < this.strokeWidth)
47
+ width = this.strokeWidth;
48
+ let height = parseInt(this.style.height.replace("px", "")) - this.strokeWidth;
49
+ if (height < this.strokeWidth)
50
+ height = this.strokeWidth;
51
+ let smallerLength = width;
52
+ if (smallerLength > height)
53
+ smallerLength = height;
54
+ let radius = (1 / 8) * this.cornerRounding * smallerLength / 2;
55
+ let svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
56
+ let rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
57
+ if (this.strokeColor == StrokeColor.black)
58
+ rect.setAttribute("stroke", "black");
59
+ else
60
+ rect.setAttribute("stroke", "white");
61
+ rect.setAttribute("fill", "white");
62
+ rect.setAttribute("fill-opacity", "0.0");
63
+ rect.setAttribute("stroke-width", this.strokeWidth.toString());
64
+ rect.setAttribute("x", x.toString());
65
+ rect.setAttribute("y", x.toString());
66
+ rect.setAttribute("rx", radius.toString());
67
+ rect.setAttribute("ry", radius.toString());
68
+ rect.setAttribute("width", width.toString());
69
+ rect.setAttribute("height", height.toString());
70
+ svg.style.overflow = "visible";
71
+ if (this._box.childElementCount > 0)
72
+ this._box.removeChild(this._box.children[0]);
73
+ svg.appendChild(rect);
74
+ this._box.appendChild(svg);
75
+ }
76
+ createZpl() {
77
+ let zpl = "";
78
+ zpl += getZplCoordinates(this, 0);
79
+ zpl += "^GB"
80
+ + this.style.width.replace("px", "") + ","
81
+ + this.style.height.replace("px", "") + ","
82
+ + this.strokeWidth + ","
83
+ + (this.strokeColor == StrokeColor.black ? "B" : "W") + ","
84
+ + this.cornerRounding;
85
+ zpl += "^FS";
86
+ return zpl;
87
+ }
88
+ }
89
+ customElements.define(ZplGraphicBox.is, ZplGraphicBox);
@@ -0,0 +1,23 @@
1
+ import { BaseCustomWebComponentConstructorAppend } from "@node-projects/base-custom-webcomponent";
2
+ declare enum StrokeColor {
3
+ black = "black",
4
+ white = "white"
5
+ }
6
+ export declare class ZplGraphicCircle extends BaseCustomWebComponentConstructorAppend {
7
+ static readonly style: CSSStyleSheet;
8
+ static readonly template: HTMLTemplateElement;
9
+ static readonly is = "zpl-graphic-circle";
10
+ strokeWidth: number;
11
+ strokeColor: string;
12
+ private _circle;
13
+ private _observer;
14
+ static readonly properties: {
15
+ strokeWidth: NumberConstructor;
16
+ strokeColor: typeof StrokeColor;
17
+ };
18
+ constructor();
19
+ ready(): Promise<void>;
20
+ private _drawSvg;
21
+ createZpl(): string;
22
+ }
23
+ export {};
@@ -0,0 +1,71 @@
1
+ import { BaseCustomWebComponentConstructorAppend, css, html } from "@node-projects/base-custom-webcomponent";
2
+ import { getZplCoordinates } from "../zplHelper.js";
3
+ var StrokeColor;
4
+ (function (StrokeColor) {
5
+ StrokeColor["black"] = "black";
6
+ StrokeColor["white"] = "white";
7
+ })(StrokeColor || (StrokeColor = {}));
8
+ export class ZplGraphicCircle extends BaseCustomWebComponentConstructorAppend {
9
+ static style = css ` *{
10
+ box-sizing: border-box;
11
+ }
12
+ `;
13
+ static template = html `
14
+ <div id="circle-div" style="width: 100%; height: 100%;">
15
+ </div>
16
+ `;
17
+ static is = 'zpl-graphic-circle';
18
+ strokeWidth = 1;
19
+ strokeColor = 'black';
20
+ _circle;
21
+ _observer;
22
+ static properties = {
23
+ strokeWidth: Number,
24
+ strokeColor: StrokeColor,
25
+ };
26
+ constructor() {
27
+ super();
28
+ this._restoreCachedInititalValues();
29
+ this._circle = this._getDomElement("circle-div");
30
+ this._observer = new ResizeObserver(() => this._drawSvg());
31
+ this._observer.observe(this);
32
+ }
33
+ async ready() {
34
+ this._parseAttributesToProperties();
35
+ this._drawSvg();
36
+ }
37
+ _drawSvg() {
38
+ let w = parseInt(this.style.width.replace("px", ""));
39
+ let h = parseInt(this.style.height.replace("px", ""));
40
+ let svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
41
+ let circle = document.createElementNS('http://www.w3.org/2000/svg', 'ellipse');
42
+ if (this.strokeColor == StrokeColor.black)
43
+ circle.setAttribute("stroke", "black");
44
+ else
45
+ circle.setAttribute("stroke", "white");
46
+ circle.setAttribute("fill", "white");
47
+ circle.setAttribute("fill-opacity", "0.0");
48
+ circle.setAttribute("stroke-width", this.strokeWidth.toString());
49
+ circle.setAttribute("cx", (w / 2).toString());
50
+ circle.setAttribute("cy", (h / 2).toString());
51
+ circle.setAttribute("rx", ((w / 2) - this.strokeWidth / 2).toString());
52
+ circle.setAttribute("ry", ((h / 2) - this.strokeWidth / 2).toString());
53
+ if (this._circle.childElementCount > 0)
54
+ this._circle.removeChild(this._circle.children[0]);
55
+ svg.appendChild(circle);
56
+ svg.style.overflow = "visible";
57
+ this._circle.appendChild(svg);
58
+ }
59
+ createZpl() {
60
+ let zpl = "";
61
+ zpl += getZplCoordinates(this, 0);
62
+ zpl += "^GE"
63
+ + this.style.width.replace("px", "") + ","
64
+ + this.style.height.replace("px", "") + ","
65
+ + this.strokeWidth + ","
66
+ + (this.strokeColor == StrokeColor.black ? "B" : "W");
67
+ zpl += "^FS";
68
+ return zpl;
69
+ }
70
+ }
71
+ customElements.define(ZplGraphicCircle.is, ZplGraphicCircle);
@@ -0,0 +1,29 @@
1
+ import { BaseCustomWebComponentConstructorAppend } from "@node-projects/base-custom-webcomponent";
2
+ declare enum StrokeColor {
3
+ black = "black",
4
+ white = "white"
5
+ }
6
+ declare enum Orientation {
7
+ L = "L",
8
+ R = "R"
9
+ }
10
+ export declare class ZplGraphicDiagonalLine extends BaseCustomWebComponentConstructorAppend {
11
+ static readonly style: CSSStyleSheet;
12
+ static readonly template: HTMLTemplateElement;
13
+ static readonly is = "zpl-graphic-diagonal-line";
14
+ strokeWidth: number;
15
+ strokeColor: string;
16
+ orientation: string;
17
+ private _line;
18
+ private _observer;
19
+ static readonly properties: {
20
+ strokeWidth: NumberConstructor;
21
+ strokeColor: typeof StrokeColor;
22
+ orientation: typeof Orientation;
23
+ };
24
+ constructor();
25
+ ready(): Promise<void>;
26
+ private _drawSvg;
27
+ createZpl(): string;
28
+ }
29
+ export {};
@@ -0,0 +1,87 @@
1
+ import { BaseCustomWebComponentConstructorAppend, css, html } from "@node-projects/base-custom-webcomponent";
2
+ import { getZplCoordinates } from "../zplHelper.js";
3
+ var StrokeColor;
4
+ (function (StrokeColor) {
5
+ StrokeColor["black"] = "black";
6
+ StrokeColor["white"] = "white";
7
+ })(StrokeColor || (StrokeColor = {}));
8
+ var Orientation;
9
+ (function (Orientation) {
10
+ Orientation["L"] = "L";
11
+ Orientation["R"] = "R";
12
+ })(Orientation || (Orientation = {}));
13
+ export class ZplGraphicDiagonalLine extends BaseCustomWebComponentConstructorAppend {
14
+ static style = css ` *{
15
+ box-sizing: border-box;
16
+ }
17
+ `;
18
+ static template = html `
19
+ <div id="box-div" style="width: 100%; height: 100%;">
20
+ </div>
21
+ `;
22
+ static is = 'zpl-graphic-diagonal-line';
23
+ strokeWidth = 1;
24
+ strokeColor = "black";
25
+ orientation;
26
+ _line;
27
+ _observer;
28
+ static properties = {
29
+ strokeWidth: Number,
30
+ strokeColor: StrokeColor,
31
+ orientation: Orientation,
32
+ };
33
+ constructor() {
34
+ super();
35
+ this._restoreCachedInititalValues();
36
+ this._line = this._getDomElement("box-div");
37
+ this._observer = new ResizeObserver(() => this._drawSvg());
38
+ this._observer.observe(this);
39
+ }
40
+ async ready() {
41
+ this._parseAttributesToProperties();
42
+ this._drawSvg();
43
+ }
44
+ _drawSvg() {
45
+ let w = parseInt(this.style.width.replace("px", ""));
46
+ let h = parseInt(this.style.height.replace("px", "")) - this.strokeWidth;
47
+ let svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
48
+ let line = document.createElementNS('http://www.w3.org/2000/svg', 'line');
49
+ if (this.strokeColor == StrokeColor.black)
50
+ line.setAttribute("stroke", "black");
51
+ else
52
+ line.setAttribute("stroke", "white");
53
+ line.setAttribute("fill", "white");
54
+ line.setAttribute("fill-opacity", "0.0");
55
+ line.setAttribute("stroke-width", this.strokeWidth.toString());
56
+ if (this.orientation == Orientation.L) {
57
+ line.setAttribute("x1", "0");
58
+ line.setAttribute("y1", "0");
59
+ line.setAttribute("x2", w.toString());
60
+ line.setAttribute("y2", h.toString());
61
+ }
62
+ else {
63
+ line.setAttribute("x1", "0");
64
+ line.setAttribute("y1", h.toString());
65
+ line.setAttribute("x2", w.toString());
66
+ line.setAttribute("y2", "0");
67
+ }
68
+ svg.style.overflow = "visible";
69
+ if (this._line.childElementCount > 0)
70
+ this._line.removeChild(this._line.children[0]);
71
+ svg.appendChild(line);
72
+ this._line.appendChild(svg);
73
+ }
74
+ createZpl() {
75
+ let zpl = "";
76
+ zpl += getZplCoordinates(this, 0);
77
+ zpl += "^GD"
78
+ + this.style.width.replace("px", "") + ","
79
+ + this.style.height.replace("px", "") + ","
80
+ + this.strokeWidth + ","
81
+ + (this.strokeColor == StrokeColor.black ? "B" : "W") + ","
82
+ + this.orientation;
83
+ zpl += "^FS";
84
+ return zpl;
85
+ }
86
+ }
87
+ customElements.define(ZplGraphicDiagonalLine.is, ZplGraphicDiagonalLine);
@@ -0,0 +1,27 @@
1
+ import { BaseCustomWebComponentConstructorAppend } from "@node-projects/base-custom-webcomponent";
2
+ export declare class ZplImage extends BaseCustomWebComponentConstructorAppend {
3
+ static readonly style: CSSStyleSheet;
4
+ static readonly template: HTMLTemplateElement;
5
+ static readonly is = "zpl-image";
6
+ private _image;
7
+ private _wrapper;
8
+ totalBytes: number;
9
+ bytesPerRow: number;
10
+ imageName: string;
11
+ hexImage: string;
12
+ scaleX: number;
13
+ scaleY: number;
14
+ static readonly properties: {
15
+ totalBytes: NumberConstructor;
16
+ bytesPerRow: NumberConstructor;
17
+ imageName: StringConstructor;
18
+ hexImage: StringConstructor;
19
+ scaleX: NumberConstructor;
20
+ scaleY: NumberConstructor;
21
+ };
22
+ constructor();
23
+ ready(): Promise<void>;
24
+ createZplImage(): string;
25
+ createZpl(): string;
26
+ private acsToCanvas;
27
+ }
@@ -0,0 +1,120 @@
1
+ import { BaseCustomWebComponentConstructorAppend, css, html } from "@node-projects/base-custom-webcomponent";
2
+ import { getZplCoordinates } from "../zplHelper.js";
3
+ import { requestAnimationFramePromise } from "@node-projects/web-component-designer";
4
+ export class ZplImage extends BaseCustomWebComponentConstructorAppend {
5
+ static style = css ` *{
6
+ box-sizing: border-box;
7
+ }
8
+ `;
9
+ static template = html `
10
+ <div id="wrapper">
11
+ <canvas id="image-div">
12
+ </canvas>
13
+ </div>
14
+ `;
15
+ static is = 'zpl-image';
16
+ _image;
17
+ _wrapper;
18
+ totalBytes;
19
+ bytesPerRow;
20
+ imageName;
21
+ hexImage;
22
+ scaleX;
23
+ scaleY;
24
+ static properties = {
25
+ totalBytes: Number,
26
+ bytesPerRow: Number,
27
+ imageName: String,
28
+ hexImage: String,
29
+ scaleX: Number,
30
+ scaleY: Number,
31
+ };
32
+ constructor() {
33
+ super();
34
+ this._restoreCachedInititalValues();
35
+ this._image = this._getDomElement("image-div");
36
+ this._wrapper = this._getDomElement("wrapper");
37
+ }
38
+ async ready() {
39
+ this._parseAttributesToProperties();
40
+ if (this.scaleX < 1)
41
+ this.scaleX = 1;
42
+ if (this.scaleY < 1)
43
+ this.scaleY = 1;
44
+ if (this.scaleX > 10)
45
+ this.scaleX = 10;
46
+ if (this.scaleX > 10)
47
+ this.scaleX = 10;
48
+ if (this.hexImage && this.bytesPerRow)
49
+ this.acsToCanvas(this.hexImage, this.bytesPerRow);
50
+ // this._image.style.width = 100 * this.scaleX + "%";
51
+ // this._image.style.aspectRatio = (this.scaleX / this.scaleY).toString();
52
+ this._image.style.transformOrigin = "0 0";
53
+ this._image.style.transform = "scaleX(" + this.scaleX + ") " + "scaleY(" + this.scaleY + ")";
54
+ await requestAnimationFramePromise();
55
+ let rect = this._image.getBoundingClientRect();
56
+ this._wrapper.style.width = rect.width + "px";
57
+ this._wrapper.style.height = rect.height + "px";
58
+ }
59
+ createZplImage() {
60
+ let zpl = "";
61
+ zpl += "~DG" + this.imageName + ",";
62
+ zpl += this.totalBytes + ",";
63
+ zpl += this.bytesPerRow + ",";
64
+ zpl += this.hexImage;
65
+ zpl = zpl.replaceAll("\n", "");
66
+ return zpl;
67
+ }
68
+ createZpl() {
69
+ let zpl = "";
70
+ zpl += getZplCoordinates(this, 0);
71
+ zpl += "^XG" + "R:" + this.imageName + "," + this.scaleX + "," + this.scaleY;
72
+ zpl += "^FS";
73
+ return zpl;
74
+ }
75
+ acsToCanvas(imageData, bytesPerRow) {
76
+ let hex = imageData.replaceAll(" ", "").replaceAll("\n", "").replaceAll("\r", "");
77
+ hex = hex.replace(/[g-zG-Y]+([0-9a-fA-F])/g, ($0, $1) => {
78
+ let rep = 0;
79
+ for (let i = 0, l = $0.length - 1; i < l; i++) {
80
+ let cd = $0.charCodeAt(i);
81
+ if (cd < 90) { // 'Z'
82
+ rep += cd - 70;
83
+ }
84
+ else {
85
+ rep += (cd - 102) * 20;
86
+ }
87
+ }
88
+ return $1.repeat(rep);
89
+ });
90
+ let bytes = Array(hex.length / 2);
91
+ for (let i = 0, l = hex.length; i < l; i += 2) {
92
+ bytes[i >> 1] = parseInt(hex.substr(i, 2), 16);
93
+ }
94
+ let l = bytes.length;
95
+ let w = bytesPerRow * 8; // rowl is in bytes
96
+ let h = ~~(l / bytesPerRow);
97
+ // Render the GRF to a canvas
98
+ let cvs = this._image;
99
+ cvs.width = w;
100
+ cvs.height = h;
101
+ let ctx = cvs.getContext('2d');
102
+ let bmap = ctx.getImageData(0, 0, w, h);
103
+ let data = bmap.data;
104
+ let offs = 0;
105
+ for (let i = 0; i < l; i++) {
106
+ let byte = bytes[i];
107
+ for (let bit = 0x80; bit; bit = bit >>> 1, offs += 4) {
108
+ if (bit & byte) {
109
+ data[offs] = 0;
110
+ data[offs + 1] = 0;
111
+ data[offs + 2] = 0;
112
+ data[offs + 3] = 255; // Fully opaque
113
+ }
114
+ }
115
+ }
116
+ ctx.putImageData(bmap, 0, 0);
117
+ return cvs;
118
+ }
119
+ }
120
+ customElements.define(ZplImage.is, ZplImage);
@@ -0,0 +1,25 @@
1
+ import { BaseCustomWebComponentConstructorAppend } from "@node-projects/base-custom-webcomponent";
2
+ declare enum FontNames {
3
+ Font_0 = "0",
4
+ Font_A = "A"
5
+ }
6
+ export declare class ZplText extends BaseCustomWebComponentConstructorAppend {
7
+ static readonly style: CSSStyleSheet;
8
+ static readonly template: HTMLTemplateElement;
9
+ static readonly is = "zpl-text";
10
+ content: string;
11
+ fontName: string;
12
+ fontHeight: number;
13
+ fontWidth: number;
14
+ private _text;
15
+ static readonly properties: {
16
+ content: StringConstructor;
17
+ fontName: typeof FontNames;
18
+ fontHeight: NumberConstructor;
19
+ fontWidth: NumberConstructor;
20
+ };
21
+ constructor();
22
+ ready(): Promise<void>;
23
+ createZpl(): string;
24
+ }
25
+ export {};
@@ -0,0 +1,69 @@
1
+ import { BaseCustomWebComponentConstructorAppend, css, html } from "@node-projects/base-custom-webcomponent";
2
+ import { getZplCoordinates } from "../zplHelper.js";
3
+ var FontNames;
4
+ (function (FontNames) {
5
+ FontNames["Font_0"] = "0";
6
+ FontNames["Font_A"] = "A";
7
+ })(FontNames || (FontNames = {}));
8
+ export class ZplText extends BaseCustomWebComponentConstructorAppend {
9
+ static style = css `
10
+ *{
11
+ box-sizing: border-box;
12
+ }
13
+ `;
14
+ static template = html `
15
+ <div id="text-div" style="width: 100%; height: 100%; pointer-events: none">
16
+ </div>
17
+ `;
18
+ static is = 'zpl-text';
19
+ content;
20
+ fontName;
21
+ fontHeight;
22
+ fontWidth;
23
+ _text;
24
+ static properties = {
25
+ content: String,
26
+ fontName: FontNames,
27
+ fontHeight: Number,
28
+ fontWidth: Number
29
+ };
30
+ constructor() {
31
+ super();
32
+ this._restoreCachedInititalValues();
33
+ this._text = this._getDomElement("text-div");
34
+ }
35
+ async ready() {
36
+ this._parseAttributesToProperties();
37
+ this._text.innerHTML = this.content;
38
+ this._text.style.transformOrigin = "0 0";
39
+ switch (this.fontName) {
40
+ case FontNames.Font_0:
41
+ this._text.style.fontSize = "9px";
42
+ this._text.style.fontFamily = "RobotoCn, Verdana";
43
+ this._text.style.fontKerning = "none";
44
+ this._text.style.transform = "scaleX(" + this.fontWidth / 9 + ") scaleY(" + this.fontHeight / 9 + ") translate(0px, -3px)";
45
+ break;
46
+ case FontNames.Font_A:
47
+ this._text.style.fontSize = "9px";
48
+ this._text.style.fontFamily = "monospace";
49
+ this._text.style.transform = "scaleX(" + this.fontWidth / 5 + ") scaleY(" + this.fontHeight / 8 + ") translate(0px, -3px)";
50
+ break;
51
+ }
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
+ }
60
+ createZpl() {
61
+ let zpl = "";
62
+ zpl += getZplCoordinates(this, 0);
63
+ zpl += "^CF" + this.fontName + "," + this.fontHeight + "," + this.fontWidth;
64
+ zpl += "^FD" + this.content;
65
+ zpl += "^FS";
66
+ return zpl;
67
+ }
68
+ }
69
+ customElements.define(ZplText.is, ZplText);
@@ -0,0 +1 @@
1
+ export declare function getZplCoordinates(obj: any, alignment: 0 | 1 | 2): string;
@@ -0,0 +1,5 @@
1
+ export function getZplCoordinates(obj, alignment) {
2
+ let x = obj.style.left.replace("px", "");
3
+ let y = obj.style.top.replace("px", "");
4
+ return "^FO" + x + "," + y + "," + alignment;
5
+ }