@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.
- package/README.md +15 -0
- package/dist/extensions/ZplLayoutResizeExtensionProvider.d.ts +4 -0
- package/dist/extensions/ZplLayoutResizeExtensionProvider.js +16 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +15 -0
- package/dist/jsBarcodeOptions.d.ts +27 -0
- package/dist/jsBarcodeOptions.js +14 -0
- package/dist/qr.d.ts +11 -0
- package/dist/qr.js +759 -0
- package/dist/services/ZplImageDrop.d.ts +10 -0
- package/dist/services/ZplImageDrop.js +220 -0
- package/dist/services/ZplLayoutCopyPasteService.d.ts +6 -0
- package/dist/services/ZplLayoutCopyPasteService.js +19 -0
- package/dist/services/ZplLayoutPlacementService.d.ts +10 -0
- package/dist/services/ZplLayoutPlacementService.js +25 -0
- package/dist/services/ZplParserService.d.ts +6 -0
- package/dist/services/ZplParserService.js +213 -0
- package/dist/setupZplServiceContainer.d.ts +2 -0
- package/dist/setupZplServiceContainer.js +66 -0
- package/dist/widgets/zpl-barcode.d.ts +25 -0
- package/dist/widgets/zpl-barcode.js +92 -0
- package/dist/widgets/zpl-graphic-box.d.ts +25 -0
- package/dist/widgets/zpl-graphic-box.js +89 -0
- package/dist/widgets/zpl-graphic-circle.d.ts +23 -0
- package/dist/widgets/zpl-graphic-circle.js +71 -0
- package/dist/widgets/zpl-graphic-diagonal-line.d.ts +29 -0
- package/dist/widgets/zpl-graphic-diagonal-line.js +87 -0
- package/dist/widgets/zpl-image.d.ts +27 -0
- package/dist/widgets/zpl-image.js +120 -0
- package/dist/widgets/zpl-text.d.ts +25 -0
- package/dist/widgets/zpl-text.js +69 -0
- package/dist/zplHelper.d.ts +1 -0
- package/dist/zplHelper.js +5 -0
- package/package.json +23 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IDesignerCanvas, IExternalDragDropService } from "@node-projects/web-component-designer";
|
|
2
|
+
export declare class ZplImageDrop implements IExternalDragDropService {
|
|
3
|
+
dragOver(event: DragEvent): 'none' | 'copy' | 'link' | 'move';
|
|
4
|
+
drop(designerView: IDesignerCanvas, event: DragEvent): void;
|
|
5
|
+
private _convertImage;
|
|
6
|
+
private _imageToACS;
|
|
7
|
+
private _rgbaToACS;
|
|
8
|
+
private _monochrome;
|
|
9
|
+
private _normal;
|
|
10
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { DesignItem, InsertAction } from "@node-projects/web-component-designer";
|
|
2
|
+
import { ZplImage } from "../widgets/zpl-image.js";
|
|
3
|
+
export class ZplImageDrop {
|
|
4
|
+
dragOver(event) {
|
|
5
|
+
if (event.dataTransfer.items[0].type.startsWith('image/'))
|
|
6
|
+
return 'copy';
|
|
7
|
+
return 'none';
|
|
8
|
+
}
|
|
9
|
+
drop(designerView, event) {
|
|
10
|
+
if (event.dataTransfer.files[0].type.startsWith('image/')) {
|
|
11
|
+
let name = event.dataTransfer.files[0].name;
|
|
12
|
+
let reader = new FileReader();
|
|
13
|
+
reader.onloadend = () => {
|
|
14
|
+
const img = document.createElement('img');
|
|
15
|
+
img.src = reader.result;
|
|
16
|
+
img.onload = () => {
|
|
17
|
+
let zplImage = new ZplImage();
|
|
18
|
+
let zpl = this._convertImage(img, name);
|
|
19
|
+
const targetRect = event.target.getBoundingClientRect();
|
|
20
|
+
let x = event.offsetX + targetRect.left - designerView.containerBoundingRect.x + 'px';
|
|
21
|
+
let y = event.offsetY + targetRect.top - designerView.containerBoundingRect.y + 'px';
|
|
22
|
+
zplImage.style.position = "absolute";
|
|
23
|
+
zplImage.style.left = x;
|
|
24
|
+
zplImage.style.top = y;
|
|
25
|
+
zplImage.setAttribute("total-bytes", zpl.totalBytes.toString());
|
|
26
|
+
zplImage.setAttribute("bytes-per-row", zpl.bytesPerRow.toString());
|
|
27
|
+
zplImage.setAttribute("image-name", zpl.name);
|
|
28
|
+
zplImage.setAttribute("hex-image", zpl.hexData);
|
|
29
|
+
zplImage.setAttribute("scale-x", "1");
|
|
30
|
+
zplImage.setAttribute("scale-y", "1");
|
|
31
|
+
const di = DesignItem.createDesignItemFromInstance(zplImage, designerView.serviceContainer, designerView.instanceServiceContainer);
|
|
32
|
+
let grp = di.openGroup("Insert of <img>");
|
|
33
|
+
designerView.instanceServiceContainer.undoService.execute(new InsertAction(designerView.rootDesignItem, designerView.rootDesignItem.childCount, di));
|
|
34
|
+
grp.commit();
|
|
35
|
+
requestAnimationFrame(() => designerView.instanceServiceContainer.selectionService.setSelectedElements([di]));
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
reader.readAsDataURL(event.dataTransfer.files[0]);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
_convertImage(img, name) {
|
|
42
|
+
let black = 50;
|
|
43
|
+
let rot = 'N';
|
|
44
|
+
let notrim = true;
|
|
45
|
+
// Get the image and convert to Z64
|
|
46
|
+
let res;
|
|
47
|
+
res = this._imageToACS(img, { black: black, rotate: rot, notrim: notrim });
|
|
48
|
+
let imgName = name.split('.')[0].substring(0, 8);
|
|
49
|
+
let bytesPerRow = res.rowlen;
|
|
50
|
+
let totalBytes = res.length;
|
|
51
|
+
return {
|
|
52
|
+
name: imgName,
|
|
53
|
+
totalBytes,
|
|
54
|
+
bytesPerRow,
|
|
55
|
+
hexData: res.acs
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
_imageToACS(img, opts) {
|
|
59
|
+
// Draw the image to a temp canvas so we can access its RGBA data
|
|
60
|
+
let cvs = document.createElement('canvas');
|
|
61
|
+
let ctx = cvs.getContext('2d');
|
|
62
|
+
cvs.width = +img.width || img.offsetWidth;
|
|
63
|
+
cvs.height = +img.height || img.offsetHeight;
|
|
64
|
+
ctx.imageSmoothingQuality = 'high'; // in case canvas needs to scale image
|
|
65
|
+
ctx.drawImage(img, 0, 0, cvs.width, cvs.height);
|
|
66
|
+
let pixels = ctx.getImageData(0, 0, cvs.width, cvs.height);
|
|
67
|
+
return this._rgbaToACS(pixels.data, pixels.width, opts);
|
|
68
|
+
}
|
|
69
|
+
_rgbaToACS(rgba, width, opts) {
|
|
70
|
+
const hexmap = (() => {
|
|
71
|
+
let arr = Array(256);
|
|
72
|
+
for (let i = 0; i < 16; i++) {
|
|
73
|
+
arr[i] = '0' + i.toString(16);
|
|
74
|
+
}
|
|
75
|
+
for (let i = 16; i < 256; i++) {
|
|
76
|
+
arr[i] = i.toString(16);
|
|
77
|
+
}
|
|
78
|
+
return arr;
|
|
79
|
+
})();
|
|
80
|
+
opts = opts || {};
|
|
81
|
+
width = width | 0;
|
|
82
|
+
if (!width || width < 0) {
|
|
83
|
+
throw new Error('Invalid width');
|
|
84
|
+
}
|
|
85
|
+
let height = ~~(rgba.length / width / 4);
|
|
86
|
+
// Create a monochome image, cropped to remove padding.
|
|
87
|
+
// The return is a Uint8Array with extra properties width and height.
|
|
88
|
+
let mono = this._monochrome(rgba, width, height, +opts.black || 50, opts.notrim);
|
|
89
|
+
let buf = this._normal(mono);
|
|
90
|
+
// Encode in hex and apply the "Alternative Data Compression Scheme"
|
|
91
|
+
//
|
|
92
|
+
// G H I J K L M N O P Q R S T U V W X Y
|
|
93
|
+
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
|
94
|
+
//
|
|
95
|
+
// g h i j k l m n o p q r s t u v w x y z
|
|
96
|
+
// 20 40 60 80 100 120 140 160 180 200 220 240 260 280 300 320 340 360 380 400
|
|
97
|
+
//
|
|
98
|
+
let imgw = buf.width;
|
|
99
|
+
let imgh = buf.height;
|
|
100
|
+
let rowl = ~~((imgw + 7) / 8);
|
|
101
|
+
let hex = '';
|
|
102
|
+
for (let i = 0, l = buf.length; i < l; i++) {
|
|
103
|
+
hex += hexmap[buf[i]];
|
|
104
|
+
}
|
|
105
|
+
let acs = '';
|
|
106
|
+
let re = /([0-9a-fA-F])\1{2,}/g;
|
|
107
|
+
let match = re.exec(hex);
|
|
108
|
+
let offset = 0;
|
|
109
|
+
while (match) {
|
|
110
|
+
acs += hex.substring(offset, match.index);
|
|
111
|
+
let l = match[0].length;
|
|
112
|
+
while (l >= 400) {
|
|
113
|
+
acs += 'z';
|
|
114
|
+
l -= 400;
|
|
115
|
+
}
|
|
116
|
+
if (l >= 20) {
|
|
117
|
+
acs += '_ghijklmnopqrstuvwxy'[((l / 20) | 0)];
|
|
118
|
+
l = l % 20;
|
|
119
|
+
}
|
|
120
|
+
if (l) {
|
|
121
|
+
acs += '_GHIJKLMNOPQRSTUVWXY'[l];
|
|
122
|
+
}
|
|
123
|
+
acs += match[1];
|
|
124
|
+
offset = re.lastIndex;
|
|
125
|
+
match = re.exec(hex);
|
|
126
|
+
}
|
|
127
|
+
acs += hex.substr(offset);
|
|
128
|
+
// Example usage of the return value `rv`:
|
|
129
|
+
// '^GFA,' + rv.length + ',' + rv.length + ',' + rv.rowlen + ',' + rv.acs
|
|
130
|
+
return {
|
|
131
|
+
length: buf.length, // uncompressed number of bytes
|
|
132
|
+
rowlen: rowl, // number of packed bytes per row
|
|
133
|
+
width: imgw, // rotated image width in pixels
|
|
134
|
+
height: imgh, // rotated image height in pixels
|
|
135
|
+
acs: acs,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
_monochrome(rgba, width, height, black, notrim) {
|
|
139
|
+
// Convert black from percent to 0..255 value
|
|
140
|
+
black = 255 * black / 100;
|
|
141
|
+
let minx, maxx, miny, maxy;
|
|
142
|
+
if (notrim) {
|
|
143
|
+
minx = miny = 0;
|
|
144
|
+
maxx = width - 1;
|
|
145
|
+
maxy = height - 1;
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
// Run through the image and determine bounding box
|
|
149
|
+
maxx = maxy = 0;
|
|
150
|
+
minx = width;
|
|
151
|
+
miny = height;
|
|
152
|
+
let x = 0, y = 0;
|
|
153
|
+
for (let i = 0, n = width * height * 4; i < n; i += 4) {
|
|
154
|
+
// Alpha blend with white.
|
|
155
|
+
let a = rgba[i + 3] / 255;
|
|
156
|
+
let r = rgba[i] * .3 * a + 255 * (1 - a);
|
|
157
|
+
let g = rgba[i + 1] * .59 * a + 255 * (1 - a);
|
|
158
|
+
let b = rgba[i + 2] * .11 * a + 255 * (1 - a);
|
|
159
|
+
let gray = r + g + b;
|
|
160
|
+
if (gray <= black) {
|
|
161
|
+
if (minx > x)
|
|
162
|
+
minx = x;
|
|
163
|
+
if (miny > y)
|
|
164
|
+
miny = y;
|
|
165
|
+
if (maxx < x)
|
|
166
|
+
maxx = x;
|
|
167
|
+
if (maxy < y)
|
|
168
|
+
maxy = y;
|
|
169
|
+
}
|
|
170
|
+
if (++x == width) {
|
|
171
|
+
x = 0;
|
|
172
|
+
y++;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
// One more time through the data, this time we create the cropped image.
|
|
177
|
+
let cx = maxx - minx + 1;
|
|
178
|
+
let cy = maxy - miny + 1;
|
|
179
|
+
let buf = new Uint8Array(cx * cy);
|
|
180
|
+
let idx = 0;
|
|
181
|
+
for (let y = miny; y <= maxy; y++) {
|
|
182
|
+
let i = (y * width + minx) * 4;
|
|
183
|
+
for (let x = minx; x <= maxx; x++) {
|
|
184
|
+
// Alpha blend with white.
|
|
185
|
+
let a = rgba[i + 3] / 255;
|
|
186
|
+
let r = rgba[i] * .3 * a + 255 * (1 - a);
|
|
187
|
+
let g = rgba[i + 1] * .59 * a + 255 * (1 - a);
|
|
188
|
+
let b = rgba[i + 2] * .11 * a + 255 * (1 - a);
|
|
189
|
+
let gray = r + g + b;
|
|
190
|
+
buf[idx++] = gray <= black ? 1 : 0;
|
|
191
|
+
i += 4;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// Return the monochrome image
|
|
195
|
+
buf.width = cx;
|
|
196
|
+
buf.height = cy;
|
|
197
|
+
return buf;
|
|
198
|
+
}
|
|
199
|
+
_normal(mono) {
|
|
200
|
+
let width = mono.width;
|
|
201
|
+
let height = mono.height;
|
|
202
|
+
let buf = new Uint8Array(~~((width + 7) / 8) * height);
|
|
203
|
+
let idx = 0; // index into buf
|
|
204
|
+
let byte = 0; // current byte of image data
|
|
205
|
+
let bitx = 0; // bit index
|
|
206
|
+
for (let i = 0, n = mono.length; i < n; i++) {
|
|
207
|
+
byte |= mono[i] << (7 - (bitx++ & 7));
|
|
208
|
+
if (bitx == width || !(bitx & 7)) {
|
|
209
|
+
buf[idx++] = byte;
|
|
210
|
+
byte = 0;
|
|
211
|
+
if (bitx == width) {
|
|
212
|
+
bitx = 0;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
buf.width = width;
|
|
217
|
+
buf.height = height;
|
|
218
|
+
return buf;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ICopyPasteService, IDesignItem, InstanceServiceContainer, ServiceContainer, IRect } from '@node-projects/web-component-designer';
|
|
2
|
+
export declare class ZplLayoutCopyPasteService implements ICopyPasteService {
|
|
3
|
+
constructor();
|
|
4
|
+
copyItems(designItems: IDesignItem[]): Promise<void>;
|
|
5
|
+
getPasteItems(serviceContainer: ServiceContainer, instanceServiceContainer: InstanceServiceContainer): Promise<[designItems: IDesignItem[], positions?: IRect[]]>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { getTextFromClipboard, copyTextToClipboard, DefaultHtmlParserService } from '@node-projects/web-component-designer';
|
|
2
|
+
export class ZplLayoutCopyPasteService {
|
|
3
|
+
constructor() {
|
|
4
|
+
}
|
|
5
|
+
async copyItems(designItems) {
|
|
6
|
+
let savedata = "";
|
|
7
|
+
for (let d of designItems) {
|
|
8
|
+
savedata += d.element.outerHTML;
|
|
9
|
+
}
|
|
10
|
+
await copyTextToClipboard(savedata);
|
|
11
|
+
}
|
|
12
|
+
async getPasteItems(serviceContainer, instanceServiceContainer) {
|
|
13
|
+
let result = [];
|
|
14
|
+
const text = await getTextFromClipboard();
|
|
15
|
+
let htmlParser = new DefaultHtmlParserService();
|
|
16
|
+
result = await htmlParser.parse(text, serviceContainer, instanceServiceContainer, true);
|
|
17
|
+
return [result, null];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DefaultPlacementService, IDesignItem, IPoint } from '@node-projects/web-component-designer';
|
|
2
|
+
import { IPlacementView } from '@node-projects/web-component-designer/dist/elements/widgets/designerView/IPlacementView';
|
|
3
|
+
export declare class ZplLayoutPlacementService extends DefaultPlacementService {
|
|
4
|
+
constructor();
|
|
5
|
+
serviceForContainer(container: IDesignItem): boolean;
|
|
6
|
+
canEnter(container: IDesignItem, items: IDesignItem[]): boolean;
|
|
7
|
+
enterContainer(container: IDesignItem, items: IDesignItem[]): void;
|
|
8
|
+
leaveContainer(container: IDesignItem, items: IDesignItem[]): void;
|
|
9
|
+
finishPlace(event: MouseEvent, placementView: IPlacementView, container: IDesignItem, startPoint: IPoint, offsetInControl: IPoint, newPoint: IPoint, items: IDesignItem[]): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DefaultPlacementService, filterChildPlaceItems } from '@node-projects/web-component-designer';
|
|
2
|
+
export class ZplLayoutPlacementService extends DefaultPlacementService {
|
|
3
|
+
constructor() {
|
|
4
|
+
super();
|
|
5
|
+
}
|
|
6
|
+
serviceForContainer(container) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
canEnter(container, items) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
enterContainer(container, items) {
|
|
13
|
+
let filterdItems = filterChildPlaceItems(items);
|
|
14
|
+
for (let i of filterdItems) {
|
|
15
|
+
container.insertChild(i);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
leaveContainer(container, items) {
|
|
19
|
+
}
|
|
20
|
+
finishPlace(event, placementView, container, startPoint, offsetInControl, newPoint, items) {
|
|
21
|
+
{
|
|
22
|
+
super.finishPlace(event, placementView, container, startPoint, offsetInControl, newPoint, items);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ITextWriter, IDesignItem, IHtmlParserService, IHtmlWriterOptions, IHtmlWriterService, InstanceServiceContainer, ServiceContainer } from "@node-projects/web-component-designer";
|
|
2
|
+
export declare class ZplParserService implements IHtmlParserService, IHtmlWriterService {
|
|
3
|
+
options: IHtmlWriterOptions;
|
|
4
|
+
parse(html: string, serviceContainer: ServiceContainer, instanceServiceContainer: InstanceServiceContainer, parseSnippet: boolean): Promise<IDesignItem[]>;
|
|
5
|
+
write(textWriter: ITextWriter, designItems: IDesignItem[], rootContainerKeepInline: boolean, updatePositions?: boolean): void;
|
|
6
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { DesignItem } from "@node-projects/web-component-designer";
|
|
2
|
+
import { ZplBarcode } from "../widgets/zpl-barcode.js";
|
|
3
|
+
import { ZplGraphicBox } from "../widgets/zpl-graphic-box.js";
|
|
4
|
+
import { ZplGraphicDiagonalLine } from "../widgets/zpl-graphic-diagonal-line.js";
|
|
5
|
+
import { ZplGraphicCircle } from "../widgets/zpl-graphic-circle.js";
|
|
6
|
+
import { ZplText } from "../widgets/zpl-text.js";
|
|
7
|
+
import { ZplImage } from "../widgets/zpl-image.js";
|
|
8
|
+
function getSetValue(...args) {
|
|
9
|
+
for (let a of args)
|
|
10
|
+
if (a != '' && a != null && a != "NaN")
|
|
11
|
+
return a;
|
|
12
|
+
}
|
|
13
|
+
export class ZplParserService {
|
|
14
|
+
options = {};
|
|
15
|
+
async parse(html, serviceContainer, instanceServiceContainer, parseSnippet) {
|
|
16
|
+
let parts = html.split("^");
|
|
17
|
+
let images = {};
|
|
18
|
+
if (parts[0][0] == "~") {
|
|
19
|
+
let imgStrings = parts[0].split("~");
|
|
20
|
+
for (let img of imgStrings) {
|
|
21
|
+
if (img == "")
|
|
22
|
+
continue;
|
|
23
|
+
let imgParts = img.split(",");
|
|
24
|
+
images[imgParts[0].substring(2)] = {
|
|
25
|
+
name: imgParts[0].substring(2),
|
|
26
|
+
totalBytes: parseInt(imgParts[1]),
|
|
27
|
+
bytesPerRow: parseInt(imgParts[2]),
|
|
28
|
+
hexData: imgParts[3]
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
let designItems = [];
|
|
33
|
+
let fontName;
|
|
34
|
+
let fontHeight;
|
|
35
|
+
let fontWidth;
|
|
36
|
+
let x;
|
|
37
|
+
let y;
|
|
38
|
+
let bc;
|
|
39
|
+
let qr;
|
|
40
|
+
let bw;
|
|
41
|
+
let bh;
|
|
42
|
+
let br;
|
|
43
|
+
// let bo: string;
|
|
44
|
+
let barcode;
|
|
45
|
+
//let a: number;
|
|
46
|
+
for (let p of parts) {
|
|
47
|
+
p = p.replaceAll("\n", "");
|
|
48
|
+
p = p.replaceAll("\r", "");
|
|
49
|
+
let command = p.substring(0, 2);
|
|
50
|
+
let fields = p.substring(2).split(",");
|
|
51
|
+
switch (command) {
|
|
52
|
+
case "XA":
|
|
53
|
+
case "XZ":
|
|
54
|
+
case "FX":
|
|
55
|
+
break;
|
|
56
|
+
case "CF":
|
|
57
|
+
fontName = fields[0];
|
|
58
|
+
fontHeight = parseInt(fields[1]);
|
|
59
|
+
let defultFontWidth = 15;
|
|
60
|
+
switch (fontName) {
|
|
61
|
+
case "A":
|
|
62
|
+
defultFontWidth = 15;
|
|
63
|
+
break;
|
|
64
|
+
case "0":
|
|
65
|
+
defultFontWidth = fontHeight;
|
|
66
|
+
}
|
|
67
|
+
fontWidth = parseInt(getSetValue(fields[2], defultFontWidth));
|
|
68
|
+
break;
|
|
69
|
+
case "FO":
|
|
70
|
+
x = parseInt(fields[0]);
|
|
71
|
+
y = parseInt(fields[1]);
|
|
72
|
+
//a = parseInt(fields[2]);
|
|
73
|
+
break;
|
|
74
|
+
case "GB":
|
|
75
|
+
let rect = new ZplGraphicBox();
|
|
76
|
+
rect.style.position = "absolute";
|
|
77
|
+
rect.style.left = x + "px";
|
|
78
|
+
rect.style.top = y + "px";
|
|
79
|
+
rect.style.width = getSetValue(fields[0], fields[2], '1') + "px";
|
|
80
|
+
rect.style.height = getSetValue(fields[1], fields[2], '1') + "px";
|
|
81
|
+
rect.setAttribute("stroke-width", getSetValue(fields[2], '1'));
|
|
82
|
+
rect.setAttribute("stroke-color", getSetValue(fields[3], 'B') == "B" ? "black" : "white");
|
|
83
|
+
rect.setAttribute("corner-rounding", getSetValue(fields[4], '0'));
|
|
84
|
+
designItems.push(DesignItem.createDesignItemFromInstance(rect, serviceContainer, instanceServiceContainer));
|
|
85
|
+
break;
|
|
86
|
+
case "GD":
|
|
87
|
+
let line = new ZplGraphicDiagonalLine();
|
|
88
|
+
line.style.position = "absolute";
|
|
89
|
+
line.style.left = x + "px";
|
|
90
|
+
line.style.top = y + "px";
|
|
91
|
+
line.style.width = getSetValue(fields[0], fields[2], '1') + "px";
|
|
92
|
+
line.style.height = getSetValue(fields[1], fields[2], '1') + "px";
|
|
93
|
+
line.setAttribute("stroke-width", getSetValue(fields[2], '1'));
|
|
94
|
+
line.setAttribute("stroke-color", getSetValue(fields[3], 'B') == "B" ? "black" : "white");
|
|
95
|
+
line.setAttribute("orientation", getSetValue(fields[4], 'R'));
|
|
96
|
+
designItems.push(DesignItem.createDesignItemFromInstance(line, serviceContainer, instanceServiceContainer));
|
|
97
|
+
break;
|
|
98
|
+
case "GE":
|
|
99
|
+
let circle = new ZplGraphicCircle();
|
|
100
|
+
circle.style.position = "absolute";
|
|
101
|
+
circle.style.left = x + "px";
|
|
102
|
+
circle.style.top = y + "px";
|
|
103
|
+
circle.style.width = getSetValue(fields[0], fields[2], '1') + "px";
|
|
104
|
+
circle.style.height = getSetValue(fields[1], fields[2], '1') + "px";
|
|
105
|
+
circle.setAttribute("stroke-width", getSetValue(fields[2], '1'));
|
|
106
|
+
circle.setAttribute("stroke-color", getSetValue(fields[3], 'B') == "B" ? "black" : "white");
|
|
107
|
+
designItems.push(DesignItem.createDesignItemFromInstance(circle, serviceContainer, instanceServiceContainer));
|
|
108
|
+
break;
|
|
109
|
+
case "BY":
|
|
110
|
+
bw = parseInt(getSetValue(fields[0], "2"));
|
|
111
|
+
br = parseFloat(getSetValue(fields[1], "3"));
|
|
112
|
+
bh = parseInt(getSetValue(fields[2], "10"));
|
|
113
|
+
break;
|
|
114
|
+
case "BC":
|
|
115
|
+
bc = true;
|
|
116
|
+
// bo = getSetValue(fields[0], 'N');
|
|
117
|
+
barcode = new ZplBarcode();
|
|
118
|
+
barcode.style.position = "absolute";
|
|
119
|
+
barcode.style.left = x + "px";
|
|
120
|
+
barcode.style.top = y + "px";
|
|
121
|
+
barcode.setAttribute("type", "CODE128");
|
|
122
|
+
if (bw)
|
|
123
|
+
barcode.setAttribute("width", bw.toString());
|
|
124
|
+
if (br)
|
|
125
|
+
barcode.setAttribute("ratio", br.toString());
|
|
126
|
+
barcode.setAttribute("height", getSetValue(fields[1], bh).toString());
|
|
127
|
+
break;
|
|
128
|
+
case "BQ":
|
|
129
|
+
qr = true;
|
|
130
|
+
bc = true;
|
|
131
|
+
// bo = getSetValue(fields[0], 'N');
|
|
132
|
+
barcode = new ZplBarcode();
|
|
133
|
+
barcode.style.position = "absolute";
|
|
134
|
+
barcode.style.left = x + "px";
|
|
135
|
+
barcode.style.top = y + "px";
|
|
136
|
+
barcode.setAttribute("type", "QR");
|
|
137
|
+
if (bw)
|
|
138
|
+
barcode.setAttribute("width", bw.toString());
|
|
139
|
+
if (br)
|
|
140
|
+
barcode.setAttribute("ratio", br.toString());
|
|
141
|
+
barcode.setAttribute("height", getSetValue(fields[2], bh).toString());
|
|
142
|
+
break;
|
|
143
|
+
case "FD":
|
|
144
|
+
if (bc) {
|
|
145
|
+
if (qr)
|
|
146
|
+
barcode.setAttribute("content", fields[0].substring(3));
|
|
147
|
+
else
|
|
148
|
+
barcode.setAttribute("content", fields[0]);
|
|
149
|
+
designItems.push(DesignItem.createDesignItemFromInstance(barcode, serviceContainer, instanceServiceContainer));
|
|
150
|
+
bc = false;
|
|
151
|
+
qr = false;
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
let text = new ZplText();
|
|
155
|
+
text.style.position = "absolute";
|
|
156
|
+
text.style.left = x + "px";
|
|
157
|
+
text.style.top = y + "px";
|
|
158
|
+
text.setAttribute("font-name", fontName);
|
|
159
|
+
text.setAttribute("font-height", fontHeight.toString());
|
|
160
|
+
text.setAttribute("font-width", fontWidth.toString());
|
|
161
|
+
text.setAttribute("content", fields[0]);
|
|
162
|
+
designItems.push(DesignItem.createDesignItemFromInstance(text, serviceContainer, instanceServiceContainer));
|
|
163
|
+
}
|
|
164
|
+
break;
|
|
165
|
+
case "XG":
|
|
166
|
+
let image = new ZplImage();
|
|
167
|
+
let nm = fields[0].substring(2);
|
|
168
|
+
image.style.position = "absolute";
|
|
169
|
+
image.style.left = x + "px";
|
|
170
|
+
image.style.top = y + "px";
|
|
171
|
+
image.setAttribute("total-bytes", images[nm].totalBytes.toString());
|
|
172
|
+
image.setAttribute("bytes-per-row", images[nm].bytesPerRow.toString());
|
|
173
|
+
image.setAttribute("image-name", nm);
|
|
174
|
+
image.setAttribute("hex-image", images[nm].hexData);
|
|
175
|
+
image.setAttribute("scale-x", getSetValue(fields[1], "1"));
|
|
176
|
+
image.setAttribute("scale-y", getSetValue(fields[2], "1"));
|
|
177
|
+
designItems.push(DesignItem.createDesignItemFromInstance(image, serviceContainer, instanceServiceContainer));
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return designItems;
|
|
182
|
+
}
|
|
183
|
+
write(textWriter, designItems, rootContainerKeepInline, updatePositions) {
|
|
184
|
+
let tx = "^XA\n";
|
|
185
|
+
for (let d of designItems) {
|
|
186
|
+
if (d.element.nodeName == "ZPL-IMAGE") {
|
|
187
|
+
//@ts-ignore
|
|
188
|
+
textWriter.writeLine(d.element.createZplImage());
|
|
189
|
+
//@ts-ignore
|
|
190
|
+
tx += d.element.createZplImage() + '\n';
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
for (let d of designItems) {
|
|
194
|
+
//@ts-ignore
|
|
195
|
+
tx += d.element.createZpl();
|
|
196
|
+
+'\n';
|
|
197
|
+
}
|
|
198
|
+
tx += "^XZ";
|
|
199
|
+
textWriter.writeLine("^XA");
|
|
200
|
+
textWriter.writeLine("^FX Comment for printersettings");
|
|
201
|
+
textWriter.writeLine("^FX For better view visit http://labelary.com/viewer.html?zpl=" + encodeURIComponent(tx));
|
|
202
|
+
for (let d of designItems) {
|
|
203
|
+
let start = textWriter.position;
|
|
204
|
+
//@ts-ignore
|
|
205
|
+
textWriter.writeLine(d.element.createZpl());
|
|
206
|
+
let end = textWriter.position;
|
|
207
|
+
if (updatePositions && d.instanceServiceContainer.designItemDocumentPositionService) {
|
|
208
|
+
d.instanceServiceContainer.designItemDocumentPositionService.setPosition(d, { start: start, length: end - start });
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
textWriter.writeLine("^XZ");
|
|
212
|
+
}
|
|
213
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { ExtensionType, DefaultModelCommandService, DefaultHtmlParserService, JsonFileElementsService, ServiceContainer, CanvasExtensionProvider, PositionExtensionProvider, SelectionDefaultExtensionProvider, GrayOutExtensionProvider, AltToEnterContainerExtensionProvider, NamedTools, PointerTool, RectangleSelectorTool, ZoomTool, PanTool, MagicWandSelectorTool, ZMoveContextMenu, CopyPasteContextMenu, MultipleItemsSelectedContextMenu, ItemsBelowContextMenu, ElementDragTitleExtensionProvider, PointerToolButtonProvider, SeperatorToolProvider, SelectorToolButtonProvider, ZoomToolButtonProvider, HighlightElementExtensionProvider, ContentService, SelectionService, UndoService, GrayOutDragOverContainerExtensionProvider, ElementAtPointService, SnaplinesProviderService, DefaultInstanceService, PropertyGroupsService, DesignItemDocumentPositionService, DragDropService } from '@node-projects/web-component-designer';
|
|
2
|
+
import { CodeViewMonaco } from '@node-projects/web-component-designer-codeview-monaco';
|
|
3
|
+
import { ZplLayoutPlacementService } from './services/ZplLayoutPlacementService.js';
|
|
4
|
+
import { ZplParserService } from './services/ZplParserService.js';
|
|
5
|
+
import { ZplImageDrop } from './services/ZplImageDrop';
|
|
6
|
+
import { ZplLayoutCopyPasteService } from './services/ZplLayoutCopyPasteService.js';
|
|
7
|
+
import { ZplLayoutResizeExtensionProvider } from './extensions/ZplLayoutResizeExtensionProvider.js';
|
|
8
|
+
export function createZplDesignerServiceContainer() {
|
|
9
|
+
let serviceContainer = new ServiceContainer();
|
|
10
|
+
serviceContainer.register("instanceService", new DefaultInstanceService());
|
|
11
|
+
serviceContainer.register("containerService", new ZplLayoutPlacementService());
|
|
12
|
+
serviceContainer.register("snaplinesProviderService", new SnaplinesProviderService());
|
|
13
|
+
serviceContainer.register("htmlParserService", new DefaultHtmlParserService());
|
|
14
|
+
serviceContainer.register("htmlParserService", new ZplParserService());
|
|
15
|
+
serviceContainer.register("htmlWriterService", new ZplParserService());
|
|
16
|
+
serviceContainer.register("elementAtPointService", new ElementAtPointService());
|
|
17
|
+
serviceContainer.register("externalDragDropService", new ZplImageDrop());
|
|
18
|
+
serviceContainer.register("dragDropService", new DragDropService());
|
|
19
|
+
serviceContainer.register("copyPasteService", new ZplLayoutCopyPasteService());
|
|
20
|
+
serviceContainer.register("modelCommandService", new DefaultModelCommandService());
|
|
21
|
+
serviceContainer.register("propertyGroupsService", new PropertyGroupsService());
|
|
22
|
+
serviceContainer.register("undoService", (designerCanvas) => new UndoService(designerCanvas));
|
|
23
|
+
serviceContainer.register("selectionService", (designerCanvas) => new SelectionService(designerCanvas, false));
|
|
24
|
+
serviceContainer.register("contentService", (designerCanvas) => new ContentService(designerCanvas.rootDesignItem));
|
|
25
|
+
serviceContainer.register("designItemDocumentPositionService", (designerCanvas) => new DesignItemDocumentPositionService(designerCanvas));
|
|
26
|
+
serviceContainer.config.codeViewWidget = CodeViewMonaco;
|
|
27
|
+
serviceContainer.designerExtensions.set(ExtensionType.Permanent, []);
|
|
28
|
+
serviceContainer.designerExtensions.set(ExtensionType.PrimarySelection, [
|
|
29
|
+
new ElementDragTitleExtensionProvider(),
|
|
30
|
+
new CanvasExtensionProvider(),
|
|
31
|
+
new PositionExtensionProvider(),
|
|
32
|
+
new ZplLayoutResizeExtensionProvider(true)
|
|
33
|
+
]);
|
|
34
|
+
serviceContainer.designerExtensions.set(ExtensionType.Selection, [
|
|
35
|
+
new SelectionDefaultExtensionProvider()
|
|
36
|
+
]);
|
|
37
|
+
serviceContainer.designerExtensions.set(ExtensionType.PrimarySelectionContainer, []);
|
|
38
|
+
serviceContainer.designerExtensions.set(ExtensionType.MouseOver, [
|
|
39
|
+
new HighlightElementExtensionProvider()
|
|
40
|
+
]);
|
|
41
|
+
serviceContainer.designerExtensions.set(ExtensionType.ContainerDrag, [
|
|
42
|
+
new GrayOutExtensionProvider()
|
|
43
|
+
]);
|
|
44
|
+
serviceContainer.designerExtensions.set(ExtensionType.ContainerDragOverAndCanBeEntered, [
|
|
45
|
+
new AltToEnterContainerExtensionProvider(),
|
|
46
|
+
new GrayOutDragOverContainerExtensionProvider(),
|
|
47
|
+
]);
|
|
48
|
+
serviceContainer.designerExtensions.set(ExtensionType.ContainerExternalDragOverAndCanBeEntered, [
|
|
49
|
+
new GrayOutDragOverContainerExtensionProvider(),
|
|
50
|
+
]);
|
|
51
|
+
serviceContainer.designerTools.set(NamedTools.Pointer, new PointerTool());
|
|
52
|
+
serviceContainer.designerTools.set(NamedTools.DrawSelection, new RectangleSelectorTool());
|
|
53
|
+
serviceContainer.designerTools.set(NamedTools.Zoom, new ZoomTool());
|
|
54
|
+
serviceContainer.designerTools.set(NamedTools.Pan, new PanTool());
|
|
55
|
+
serviceContainer.designerTools.set(NamedTools.RectangleSelector, new RectangleSelectorTool());
|
|
56
|
+
serviceContainer.designerTools.set(NamedTools.MagicWandSelector, new MagicWandSelectorTool());
|
|
57
|
+
serviceContainer.designerContextMenuExtensions = [
|
|
58
|
+
new CopyPasteContextMenu(),
|
|
59
|
+
new ZMoveContextMenu(),
|
|
60
|
+
new MultipleItemsSelectedContextMenu(),
|
|
61
|
+
new ItemsBelowContextMenu()
|
|
62
|
+
];
|
|
63
|
+
serviceContainer.designViewToolbarButtons.push(new PointerToolButtonProvider(), new SeperatorToolProvider(22), new SelectorToolButtonProvider(), new SeperatorToolProvider(22), new ZoomToolButtonProvider());
|
|
64
|
+
serviceContainer.register('elementsService', new JsonFileElementsService('zpl', '/dist/widgets/elements.json'));
|
|
65
|
+
return serviceContainer;
|
|
66
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BaseCustomWebComponentConstructorAppend } from "@node-projects/base-custom-webcomponent";
|
|
2
|
+
import { BarcodeFormat } from "../jsBarcodeOptions.js";
|
|
3
|
+
export declare class ZplBarcode extends BaseCustomWebComponentConstructorAppend {
|
|
4
|
+
static readonly style: CSSStyleSheet;
|
|
5
|
+
static readonly template: HTMLTemplateElement;
|
|
6
|
+
static readonly is = "zpl-barcode";
|
|
7
|
+
content: string;
|
|
8
|
+
type: BarcodeFormat;
|
|
9
|
+
width: number;
|
|
10
|
+
ratio: number;
|
|
11
|
+
height: number;
|
|
12
|
+
private _barcode;
|
|
13
|
+
private _barcodeOptions;
|
|
14
|
+
static readonly properties: {
|
|
15
|
+
content: StringConstructor;
|
|
16
|
+
type: typeof BarcodeFormat;
|
|
17
|
+
width: NumberConstructor;
|
|
18
|
+
ratio: NumberConstructor;
|
|
19
|
+
height: NumberConstructor;
|
|
20
|
+
};
|
|
21
|
+
constructor();
|
|
22
|
+
ready(): Promise<void>;
|
|
23
|
+
private _createOptions;
|
|
24
|
+
createZpl(): string;
|
|
25
|
+
}
|