@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
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface ZplToken {
|
|
2
|
+
prefix: '^' | '~';
|
|
3
|
+
command: string;
|
|
4
|
+
data: string;
|
|
5
|
+
}
|
|
6
|
+
export interface HiddenPayload {
|
|
7
|
+
index: number;
|
|
8
|
+
zpl: string;
|
|
9
|
+
comments: Set<string>;
|
|
10
|
+
}
|
|
11
|
+
export declare function tokenizeZpl(source: string): ZplToken[];
|
|
12
|
+
export declare function createHiddenZplComments(index: number, miniZpl: string): string[];
|
|
13
|
+
export declare function hiddenPayloads(tokens: ZplToken[]): HiddenPayload[];
|
|
14
|
+
export declare function decodeHiddenZplComments(source: string): {
|
|
15
|
+
index: number;
|
|
16
|
+
zpl: string;
|
|
17
|
+
}[];
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const hiddenPrefix = 'NODEPROJECTS-HIDDEN-V1:';
|
|
2
|
+
const hiddenChunkSize = 1024;
|
|
3
|
+
function findCommandStart(source, from, includeTilde = true) {
|
|
4
|
+
for (let index = from; index + 2 < source.length; index++) {
|
|
5
|
+
const prefix = source[index];
|
|
6
|
+
if (prefix !== '^' && (!includeTilde || prefix !== '~'))
|
|
7
|
+
continue;
|
|
8
|
+
if (/^[A-Za-z0-9]{2}$/.test(source.slice(index + 1, index + 3)))
|
|
9
|
+
return index;
|
|
10
|
+
}
|
|
11
|
+
return -1;
|
|
12
|
+
}
|
|
13
|
+
export function tokenizeZpl(source) {
|
|
14
|
+
const tokens = [];
|
|
15
|
+
let index = 0;
|
|
16
|
+
while (index < source.length) {
|
|
17
|
+
const start = findCommandStart(source, index);
|
|
18
|
+
if (start < 0 || start + 2 >= source.length)
|
|
19
|
+
break;
|
|
20
|
+
const prefix = source[start];
|
|
21
|
+
const command = source.slice(start + 1, start + 3).toUpperCase();
|
|
22
|
+
// Tilde sequences such as ~1 and ~d029 are field data for ^FD, not
|
|
23
|
+
// immediate ZPL commands. Outside a field, ~DG and peers remain tokens.
|
|
24
|
+
const end = findCommandStart(source, start + 3, !(prefix === '^' && command === 'FD'));
|
|
25
|
+
const tokenEnd = end < 0 ? source.length : end;
|
|
26
|
+
tokens.push({ prefix, command, data: source.slice(start + 3, tokenEnd).replace(/[\r\n]/g, '') });
|
|
27
|
+
index = end < 0 ? source.length : end;
|
|
28
|
+
}
|
|
29
|
+
return tokens;
|
|
30
|
+
}
|
|
31
|
+
function encodeBase64Url(value) {
|
|
32
|
+
const bytes = new TextEncoder().encode(value);
|
|
33
|
+
let binary = '';
|
|
34
|
+
for (let offset = 0; offset < bytes.length; offset += 0x8000) {
|
|
35
|
+
binary += String.fromCharCode(...bytes.subarray(offset, offset + 0x8000));
|
|
36
|
+
}
|
|
37
|
+
return btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/g, '');
|
|
38
|
+
}
|
|
39
|
+
function decodeBase64Url(value) {
|
|
40
|
+
const base64 = value.replace(/-/g, '+').replace(/_/g, '/').padEnd(Math.ceil(value.length / 4) * 4, '=');
|
|
41
|
+
const binary = atob(base64);
|
|
42
|
+
const bytes = Uint8Array.from(binary, character => character.charCodeAt(0));
|
|
43
|
+
return new TextDecoder().decode(bytes);
|
|
44
|
+
}
|
|
45
|
+
export function createHiddenZplComments(index, miniZpl) {
|
|
46
|
+
const payload = encodeBase64Url(miniZpl);
|
|
47
|
+
const total = Math.max(1, Math.ceil(payload.length / hiddenChunkSize));
|
|
48
|
+
const comments = [];
|
|
49
|
+
for (let part = 0; part < total; part++) {
|
|
50
|
+
comments.push(`^FX${hiddenPrefix}${index}:${part + 1}/${total}:${payload.slice(part * hiddenChunkSize, (part + 1) * hiddenChunkSize)}^FS`);
|
|
51
|
+
}
|
|
52
|
+
return comments;
|
|
53
|
+
}
|
|
54
|
+
export function hiddenPayloads(tokens) {
|
|
55
|
+
const regex = /^NODEPROJECTS-HIDDEN-V1:(\d+):(\d+)\/(\d+):([A-Za-z0-9_-]+)$/;
|
|
56
|
+
const groups = new Map();
|
|
57
|
+
for (const token of tokens) {
|
|
58
|
+
if (token.prefix !== '^' || token.command !== 'FX')
|
|
59
|
+
continue;
|
|
60
|
+
const match = token.data.match(regex);
|
|
61
|
+
if (!match)
|
|
62
|
+
continue;
|
|
63
|
+
const index = Number(match[1]);
|
|
64
|
+
const part = Number(match[2]);
|
|
65
|
+
const total = Number(match[3]);
|
|
66
|
+
if (!Number.isInteger(index) || part < 1 || total < 1 || part > total)
|
|
67
|
+
continue;
|
|
68
|
+
const group = groups.get(index) ?? { total, parts: new Map(), comments: new Set(), invalid: false };
|
|
69
|
+
if (group.total !== total || group.parts.has(part)) {
|
|
70
|
+
group.invalid = true;
|
|
71
|
+
groups.set(index, group);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
group.parts.set(part, match[4]);
|
|
75
|
+
group.comments.add(token.data);
|
|
76
|
+
groups.set(index, group);
|
|
77
|
+
}
|
|
78
|
+
const result = [];
|
|
79
|
+
for (const [index, group] of groups) {
|
|
80
|
+
if (group.invalid || group.parts.size !== group.total)
|
|
81
|
+
continue;
|
|
82
|
+
try {
|
|
83
|
+
const encoded = Array.from({ length: group.total }, (_, part) => group.parts.get(part + 1) ?? '').join('');
|
|
84
|
+
const zpl = decodeBase64Url(encoded);
|
|
85
|
+
if (!zpl.includes('^XA') || !zpl.includes('^XZ'))
|
|
86
|
+
continue;
|
|
87
|
+
result.push({ index, zpl, comments: group.comments });
|
|
88
|
+
}
|
|
89
|
+
catch { /* malformed metadata remains an ordinary comment */ }
|
|
90
|
+
}
|
|
91
|
+
return result.sort((a, b) => a.index - b.index);
|
|
92
|
+
}
|
|
93
|
+
export function decodeHiddenZplComments(source) {
|
|
94
|
+
return hiddenPayloads(tokenizeZpl(source)).map(({ index, zpl }) => ({ index, zpl }));
|
|
95
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ISize } from '@node-projects/web-component-designer';
|
|
2
|
+
export declare const quantizeZplValue: (value: number, min: number, max: number) => number;
|
|
3
|
+
export declare const zplAxisScales: (rotation: string | null, initial: ISize, current: ISize) => {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const quantizeZplValue = (value, min, max) => Math.max(min, Math.min(max, Math.round(value)));
|
|
2
|
+
export const zplAxisScales = (rotation, initial, current) => {
|
|
3
|
+
const screenWidth = current.width / Math.max(1, initial.width);
|
|
4
|
+
const screenHeight = current.height / Math.max(1, initial.height);
|
|
5
|
+
return ['R', 'B'].includes(rotation ?? 'N')
|
|
6
|
+
? { width: screenHeight, height: screenWidth }
|
|
7
|
+
: { width: screenWidth, height: screenHeight };
|
|
8
|
+
};
|
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
import { DefaultPropertyEditorTypesService, DefaultEditorTypeService, ExtensionType, DefaultModelCommandService, DefaultHtmlParserService, JsonFileElementsService, ServiceContainer, PositionExtensionProvider,
|
|
1
|
+
import { DefaultPropertyEditorTypesService, DefaultEditorTypeService, ExtensionType, DefaultModelCommandService, DefaultHtmlParserService, JsonFileElementsService, ServiceContainer, PositionExtensionProvider, GrayOutExtensionProvider, AltToEnterContainerExtensionProvider, NamedTools, PointerTool, RectangleSelectorTool, ZoomTool, PanTool, MagicWandSelectorTool, ZMoveContextMenu, CopyPasteContextMenu, MultipleItemsSelectedContextMenu, ItemsBelowContextMenu, ElementDragTitleExtensionProvider, PointerToolButtonProvider, SeperatorToolProvider, SelectorToolButtonProvider, ZoomToolButtonProvider, HighlightElementExtensionProvider, SelectionService, UndoService, GrayOutDragOverContainerExtensionProvider, ElementAtPointService, SnaplinesProviderService, DefaultInstanceService, PropertyGroupsService, DesignItemDocumentPositionService, DragDropService, BaseCustomWebComponentPropertiesService, TransformToolButtonProvider, DesignItemService, DeletionService, ResizeExtensionProvider } from '@node-projects/web-component-designer';
|
|
2
2
|
import { ZplLayoutPlacementService } from './services/ZplLayoutPlacementService.js';
|
|
3
3
|
import { ZplParserService } from './services/ZplParserService.js';
|
|
4
4
|
import { ZplImageDrop } from './services/ZplImageDrop.js';
|
|
5
5
|
import { ZplLayoutCopyPasteService } from './services/ZplLayoutCopyPasteService.js';
|
|
6
|
-
import { ZplLayoutResizeExtensionProvider } from './extensions/ZplLayoutResizeExtensionProvider.js';
|
|
7
6
|
import { ZplDemoView } from './widgets/views/zpl-demo-view.js';
|
|
7
|
+
import { ZplBarcodePropertiesService } from './services/ZplBarcodePropertiesService.js';
|
|
8
|
+
import { ZplIncludeInOutputPropertiesService } from './services/ZplIncludeInOutputPropertiesService.js';
|
|
9
|
+
import { ZplBarcodeElementsService } from './services/ZplBarcodeElementsService.js';
|
|
10
|
+
import { ZplElementResizeStrategy } from './services/ZplElementResizeStrategy.js';
|
|
11
|
+
import { ZplTextPropertiesService } from './services/ZplTextPropertiesService.js';
|
|
12
|
+
import { ZplGraphicResizeStrategy } from './services/ZplGraphicResizeStrategy.js';
|
|
13
|
+
import { ZplSelectionExtensionProvider } from './services/ZplSelectionExtensionProvider.js';
|
|
14
|
+
import { ZplDiagonalLineExtensionProvider } from './services/ZplDiagonalLineExtension.js';
|
|
15
|
+
import { ZplTextEditExtensionProvider } from './services/ZplTextEditExtension.js';
|
|
8
16
|
export function createZplDesignerServiceContainer() {
|
|
9
17
|
let serviceContainer = new ServiceContainer();
|
|
10
18
|
serviceContainer.register("instanceService", new DefaultInstanceService());
|
|
@@ -22,6 +30,11 @@ export function createZplDesignerServiceContainer() {
|
|
|
22
30
|
serviceContainer.register("propertyEditorTypesService", new DefaultPropertyEditorTypesService());
|
|
23
31
|
serviceContainer.register("propertyGroupsService", new PropertyGroupsService());
|
|
24
32
|
serviceContainer.register("propertyService", new BaseCustomWebComponentPropertiesService(true));
|
|
33
|
+
serviceContainer.register("propertyService", new ZplBarcodePropertiesService());
|
|
34
|
+
serviceContainer.register("propertyService", new ZplTextPropertiesService());
|
|
35
|
+
serviceContainer.register("attachedPropertyService", new ZplIncludeInOutputPropertiesService());
|
|
36
|
+
serviceContainer.register("elementResizeStrategy", new ZplElementResizeStrategy());
|
|
37
|
+
serviceContainer.register("elementResizeStrategy", new ZplGraphicResizeStrategy());
|
|
25
38
|
serviceContainer.register("designItemService", new DesignItemService());
|
|
26
39
|
serviceContainer.register("deletionService", new DeletionService());
|
|
27
40
|
serviceContainer.register("undoService", (designerCanvas) => new UndoService(designerCanvas));
|
|
@@ -31,15 +44,19 @@ export function createZplDesignerServiceContainer() {
|
|
|
31
44
|
serviceContainer.designerExtensions.set(ExtensionType.PrimarySelection, [
|
|
32
45
|
new ElementDragTitleExtensionProvider(),
|
|
33
46
|
new PositionExtensionProvider(),
|
|
34
|
-
new
|
|
47
|
+
new ZplDiagonalLineExtensionProvider(),
|
|
48
|
+
new ResizeExtensionProvider(false)
|
|
35
49
|
]);
|
|
36
50
|
serviceContainer.designerExtensions.set(ExtensionType.Selection, [
|
|
37
|
-
new
|
|
51
|
+
new ZplSelectionExtensionProvider()
|
|
38
52
|
]);
|
|
39
53
|
serviceContainer.designerExtensions.set(ExtensionType.PrimarySelectionContainer, []);
|
|
40
54
|
serviceContainer.designerExtensions.set(ExtensionType.MouseOver, [
|
|
41
55
|
new HighlightElementExtensionProvider()
|
|
42
56
|
]);
|
|
57
|
+
serviceContainer.designerExtensions.set(ExtensionType.Doubleclick, [
|
|
58
|
+
new ZplTextEditExtensionProvider()
|
|
59
|
+
]);
|
|
43
60
|
serviceContainer.designerExtensions.set(ExtensionType.ContainerDrag, [
|
|
44
61
|
new GrayOutExtensionProvider()
|
|
45
62
|
]);
|
|
@@ -65,5 +82,6 @@ export function createZplDesignerServiceContainer() {
|
|
|
65
82
|
serviceContainer.designViewToolbarButtons.push(new PointerToolButtonProvider(), new SeperatorToolProvider(22), new SelectorToolButtonProvider(), new SeperatorToolProvider(22), new ZoomToolButtonProvider(), new SeperatorToolProvider(22), new TransformToolButtonProvider());
|
|
66
83
|
serviceContainer.config.demoViewWidget = ZplDemoView;
|
|
67
84
|
serviceContainer.register('elementsService', new JsonFileElementsService('zpl', new URL("./widgets/elements.json", import.meta.url)));
|
|
85
|
+
serviceContainer.register('elementsService', new ZplBarcodeElementsService());
|
|
68
86
|
return serviceContainer;
|
|
69
87
|
}
|
|
@@ -1,29 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"elements": [
|
|
3
|
-
{
|
|
4
|
-
"name": "barcode",
|
|
5
|
-
"tag": "zpl-barcode",
|
|
6
|
-
"type": "polymer",
|
|
7
|
-
"defaultAttributes": {
|
|
8
|
-
"content": "barcode",
|
|
9
|
-
"type": "CODE128",
|
|
10
|
-
"width": "2",
|
|
11
|
-
"ratio": "20",
|
|
12
|
-
"height": "200"
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"name": "qr-code",
|
|
17
|
-
"tag": "zpl-barcode",
|
|
18
|
-
"type": "polymer",
|
|
19
|
-
"defaultAttributes": {
|
|
20
|
-
"content": "barcode",
|
|
21
|
-
"type": "QR",
|
|
22
|
-
"width": "0",
|
|
23
|
-
"ratio": "0",
|
|
24
|
-
"height": "5"
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
3
|
{
|
|
28
4
|
"name": "graphic box",
|
|
29
5
|
"tag": "zpl-graphic-box",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BaseCustomWebComponentConstructorAppend, css, html } from '@node-projects/base-custom-webcomponent';
|
|
2
|
+
import { zplPreviewDpmm } from '../../barcodes/bwipRenderer.js';
|
|
2
3
|
export class ZplDemoView extends BaseCustomWebComponentConstructorAppend {
|
|
3
|
-
static template = html `<
|
|
4
|
+
static template = html `<div id="side"><span>Label generated via http://api.labelary.com/</span></div><img id="image">`;
|
|
4
5
|
static style = css `
|
|
5
6
|
:host {
|
|
6
7
|
display: block;
|
|
@@ -10,8 +11,32 @@ export class ZplDemoView extends BaseCustomWebComponentConstructorAppend {
|
|
|
10
11
|
width: 100%;
|
|
11
12
|
position: relative;
|
|
12
13
|
}
|
|
14
|
+
#side {
|
|
15
|
+
position: absolute;
|
|
16
|
+
left: 0;
|
|
17
|
+
top: 0;
|
|
18
|
+
height: 100%;
|
|
19
|
+
width: 24px;
|
|
20
|
+
background: var(--wcd-demo-view-toolbar-background, black);
|
|
21
|
+
}
|
|
22
|
+
#side > span {
|
|
23
|
+
color: var(--wcd-color-text, white);
|
|
24
|
+
rotate: 270deg;
|
|
25
|
+
display: block;
|
|
26
|
+
position: absolute;
|
|
27
|
+
top: 304px;
|
|
28
|
+
left: -305px;
|
|
29
|
+
font-weight: 600;
|
|
30
|
+
font-family: monospace;
|
|
31
|
+
font-size: 24px;
|
|
32
|
+
white-space: nowrap;
|
|
33
|
+
}
|
|
13
34
|
#image {
|
|
14
35
|
border: solid 1px black;
|
|
36
|
+
position: absolute;
|
|
37
|
+
top: 0;
|
|
38
|
+
left: 24px;
|
|
39
|
+
border: 0;
|
|
15
40
|
}`;
|
|
16
41
|
constructor() {
|
|
17
42
|
super();
|
|
@@ -22,7 +47,7 @@ export class ZplDemoView extends BaseCustomWebComponentConstructorAppend {
|
|
|
22
47
|
async display(serviceContainer, instanceServiceContainer, code, style) {
|
|
23
48
|
const width = 4;
|
|
24
49
|
const height = 6;
|
|
25
|
-
const dpmm =
|
|
50
|
+
const dpmm = `${zplPreviewDpmm}dpmm`;
|
|
26
51
|
const response = await fetch(`https://api.labelary.com/v1/printers/${dpmm}/labels/${width}x${height}/${0}`, {
|
|
27
52
|
method: "POST",
|
|
28
53
|
body: code,
|
|
@@ -1,25 +1,79 @@
|
|
|
1
|
-
import { BaseCustomWebComponentConstructorAppend } from
|
|
2
|
-
import {
|
|
1
|
+
import { BaseCustomWebComponentConstructorAppend } from '@node-projects/base-custom-webcomponent';
|
|
2
|
+
import { BarcodeProps, BarcodeRotation, BarcodeType } from '../barcodes/barcodeRegistry.js';
|
|
3
3
|
export declare class ZplBarcode extends BaseCustomWebComponentConstructorAppend {
|
|
4
4
|
static readonly style: CSSStyleSheet;
|
|
5
5
|
static readonly template: HTMLTemplateElement;
|
|
6
6
|
static readonly is = "zpl-barcode";
|
|
7
|
+
static get observedAttributes(): readonly string[];
|
|
7
8
|
content: string;
|
|
8
|
-
type:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
type: BarcodeType;
|
|
10
|
+
rotation: BarcodeRotation;
|
|
11
|
+
moduleWidth: number;
|
|
12
|
+
wideRatio: number;
|
|
13
|
+
barHeight: number;
|
|
14
|
+
printInterpretation: boolean;
|
|
15
|
+
printInterpretationAbove: boolean;
|
|
16
|
+
checkDigit: boolean;
|
|
17
|
+
magnification: number;
|
|
18
|
+
dimension: number;
|
|
19
|
+
rowHeight: number;
|
|
20
|
+
columns: number;
|
|
21
|
+
rows: number;
|
|
22
|
+
mode: string | number;
|
|
23
|
+
securityLevel: string | number;
|
|
24
|
+
errorCorrection: string;
|
|
25
|
+
quality: number;
|
|
26
|
+
gs1: boolean;
|
|
27
|
+
aspectRatio: number;
|
|
28
|
+
symbology: number;
|
|
29
|
+
segments: number;
|
|
30
|
+
ecLevel: number;
|
|
31
|
+
model: number;
|
|
32
|
+
symbolNumber: number;
|
|
33
|
+
symbolTotal: number;
|
|
34
|
+
microPdfModuleWidth: number;
|
|
35
|
+
microPdfRowHeight: number;
|
|
14
36
|
static readonly properties: {
|
|
15
37
|
content: StringConstructor;
|
|
16
|
-
type:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
38
|
+
type: StringConstructor;
|
|
39
|
+
rotation: StringConstructor;
|
|
40
|
+
moduleWidth: NumberConstructor;
|
|
41
|
+
wideRatio: NumberConstructor;
|
|
42
|
+
barHeight: NumberConstructor;
|
|
43
|
+
printInterpretation: BooleanConstructor;
|
|
44
|
+
printInterpretationAbove: BooleanConstructor;
|
|
45
|
+
checkDigit: BooleanConstructor;
|
|
46
|
+
magnification: NumberConstructor;
|
|
47
|
+
dimension: NumberConstructor;
|
|
48
|
+
rowHeight: NumberConstructor;
|
|
49
|
+
columns: NumberConstructor;
|
|
50
|
+
rows: NumberConstructor;
|
|
51
|
+
mode: StringConstructor;
|
|
52
|
+
securityLevel: StringConstructor;
|
|
53
|
+
errorCorrection: StringConstructor;
|
|
54
|
+
quality: NumberConstructor;
|
|
55
|
+
gs1: BooleanConstructor;
|
|
56
|
+
aspectRatio: NumberConstructor;
|
|
57
|
+
symbology: NumberConstructor;
|
|
58
|
+
segments: NumberConstructor;
|
|
59
|
+
ecLevel: NumberConstructor;
|
|
60
|
+
model: NumberConstructor;
|
|
61
|
+
symbolNumber: NumberConstructor;
|
|
62
|
+
symbolTotal: NumberConstructor;
|
|
63
|
+
microPdfModuleWidth: NumberConstructor;
|
|
64
|
+
microPdfRowHeight: NumberConstructor;
|
|
20
65
|
};
|
|
66
|
+
private _surface;
|
|
67
|
+
private _frame;
|
|
68
|
+
private _hri;
|
|
69
|
+
private _error;
|
|
70
|
+
private _widgetReady;
|
|
21
71
|
constructor();
|
|
22
|
-
ready():
|
|
23
|
-
|
|
72
|
+
ready(): void;
|
|
73
|
+
refreshFromAttributes(): void;
|
|
74
|
+
attributeChangedCallback(_name: string, oldValue: string | null, newValue: string | null): void;
|
|
75
|
+
get barcodeProps(): BarcodeProps;
|
|
76
|
+
renderBarcode(): void;
|
|
77
|
+
private _setRotatedBounds;
|
|
24
78
|
createZpl(): string;
|
|
25
79
|
}
|
|
@@ -1,96 +1,211 @@
|
|
|
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, barcodeInterpretationText, barcodeShowsInterpretation, barcodeTextAbove, barcodeTextZoneDots, eanUpcTypes, getEanUpcHriFragments, getEanUpcHriStyle, 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
|
+
#hri.ean-upc { text-align: left; overflow: visible; }
|
|
14
|
+
#hri.ean-upc > span { position: absolute; top: 0; text-align: center; }
|
|
15
|
+
#error { width: 160px; min-height: 48px; padding: 6px; border: 1px dashed #c62828;
|
|
16
|
+
color: #8e0000; background: #fff4f4; font: 11px sans-serif; overflow: hidden; }
|
|
9
17
|
`;
|
|
10
18
|
static template = html `
|
|
11
|
-
|
|
12
|
-
</div>
|
|
19
|
+
<div id="barcode-frame"><div id="barcode-surface"></div><div id="hri"></div><div id="error" hidden></div></div>
|
|
13
20
|
`;
|
|
14
21
|
static is = 'zpl-barcode';
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
static get observedAttributes() { return barcodeObservedAttributes; }
|
|
23
|
+
content = '';
|
|
24
|
+
type = 'code128';
|
|
25
|
+
rotation = 'N';
|
|
26
|
+
moduleWidth = 2;
|
|
27
|
+
wideRatio = 3;
|
|
28
|
+
barHeight = 100;
|
|
29
|
+
printInterpretation = true;
|
|
30
|
+
printInterpretationAbove = false;
|
|
31
|
+
checkDigit = false;
|
|
32
|
+
magnification = 4;
|
|
33
|
+
dimension = 5;
|
|
34
|
+
rowHeight = 2;
|
|
35
|
+
columns = 0;
|
|
36
|
+
rows = 0;
|
|
37
|
+
mode = 0;
|
|
38
|
+
securityLevel = 0;
|
|
39
|
+
errorCorrection = 'Q';
|
|
40
|
+
quality = 200;
|
|
41
|
+
gs1 = false;
|
|
42
|
+
aspectRatio = 1;
|
|
43
|
+
symbology = 1;
|
|
44
|
+
segments = 22;
|
|
45
|
+
ecLevel = 0;
|
|
46
|
+
model = 2;
|
|
47
|
+
symbolNumber = 1;
|
|
48
|
+
symbolTotal = 1;
|
|
49
|
+
microPdfModuleWidth = 2;
|
|
50
|
+
microPdfRowHeight = 4;
|
|
22
51
|
static properties = {
|
|
23
|
-
content: String,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
52
|
+
content: String, type: String, rotation: String, moduleWidth: Number, wideRatio: Number,
|
|
53
|
+
barHeight: Number, printInterpretation: Boolean, printInterpretationAbove: Boolean,
|
|
54
|
+
checkDigit: Boolean, magnification: Number, dimension: Number, rowHeight: Number,
|
|
55
|
+
columns: Number, rows: Number, mode: String, securityLevel: String,
|
|
56
|
+
errorCorrection: String, quality: Number, gs1: Boolean, aspectRatio: Number,
|
|
57
|
+
symbology: Number, segments: Number, ecLevel: Number, model: Number,
|
|
58
|
+
symbolNumber: Number, symbolTotal: Number, microPdfModuleWidth: Number,
|
|
59
|
+
microPdfRowHeight: Number
|
|
28
60
|
};
|
|
61
|
+
_surface;
|
|
62
|
+
_frame;
|
|
63
|
+
_hri;
|
|
64
|
+
_error;
|
|
65
|
+
_widgetReady = false;
|
|
29
66
|
constructor() {
|
|
30
67
|
super();
|
|
31
68
|
this._restoreCachedInititalValues();
|
|
32
|
-
this.
|
|
69
|
+
this._surface = this._getDomElement('barcode-surface');
|
|
70
|
+
this._frame = this._getDomElement('barcode-frame');
|
|
71
|
+
this._hri = this._getDomElement('hri');
|
|
72
|
+
this._error = this._getDomElement('error');
|
|
73
|
+
}
|
|
74
|
+
ready() {
|
|
75
|
+
this._widgetReady = true;
|
|
76
|
+
this.refreshFromAttributes();
|
|
33
77
|
}
|
|
34
|
-
|
|
78
|
+
refreshFromAttributes() {
|
|
35
79
|
this._parseAttributesToProperties();
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
80
|
+
this.renderBarcode();
|
|
81
|
+
}
|
|
82
|
+
attributeChangedCallback(_name, oldValue, newValue) {
|
|
83
|
+
if (oldValue === newValue || !this._widgetReady)
|
|
84
|
+
return;
|
|
85
|
+
this.refreshFromAttributes();
|
|
86
|
+
}
|
|
87
|
+
get barcodeProps() {
|
|
88
|
+
return readBarcodeProps(this);
|
|
89
|
+
}
|
|
90
|
+
renderBarcode() {
|
|
91
|
+
const props = this.barcodeProps;
|
|
92
|
+
const definition = getBarcodeDefinition(props.type);
|
|
93
|
+
const result = renderBarcode(props);
|
|
94
|
+
this._surface.replaceChildren();
|
|
95
|
+
this._hri.replaceChildren();
|
|
96
|
+
this._hri.hidden = true;
|
|
97
|
+
this._hri.className = '';
|
|
98
|
+
this._hri.style.left = '';
|
|
99
|
+
this._hri.style.width = '';
|
|
100
|
+
this._hri.style.fontFamily = '';
|
|
101
|
+
this._hri.style.textAlign = '';
|
|
102
|
+
this._error.hidden = true;
|
|
103
|
+
this._frame.style.transform = '';
|
|
104
|
+
this._frame.style.width = '';
|
|
105
|
+
this._frame.style.height = '';
|
|
106
|
+
this._surface.style.position = '';
|
|
107
|
+
this._surface.style.left = '';
|
|
108
|
+
this._surface.style.top = '';
|
|
109
|
+
if (!result.canvas) {
|
|
110
|
+
this._error.textContent = `${definition.label}: ${result.error ?? 'cannot render this value'}`;
|
|
111
|
+
this._error.hidden = false;
|
|
112
|
+
this._setRotatedBounds(160, 48, props.rotation);
|
|
113
|
+
return;
|
|
52
114
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
115
|
+
const canvas = result.canvas;
|
|
116
|
+
const uprightWidth = result.width;
|
|
117
|
+
const horizontalInsets = barcodeHorizontalInsets(props);
|
|
118
|
+
let uprightHeight = result.height;
|
|
119
|
+
if (definition.resizeKind === 'linear') {
|
|
120
|
+
const linear = props;
|
|
121
|
+
const isEanUpc = eanUpcTypes.has(props.type);
|
|
122
|
+
canvas.style.width = `${uprightWidth - horizontalInsets.left - horizontalInsets.right}px`;
|
|
123
|
+
canvas.style.height = `${linear.barHeight + (isEanUpc ? 13 : 0)}px`;
|
|
124
|
+
uprightHeight = linear.barHeight;
|
|
125
|
+
const showHri = barcodeShowsInterpretation(props);
|
|
126
|
+
const textZone = barcodeTextZoneDots(props);
|
|
127
|
+
const textAbove = barcodeTextAbove(props);
|
|
128
|
+
if (textAbove && textZone > 0) {
|
|
129
|
+
this._surface.style.position = 'absolute';
|
|
130
|
+
this._surface.style.left = `${horizontalInsets.left}px`;
|
|
131
|
+
this._surface.style.top = `${textZone}px`;
|
|
132
|
+
}
|
|
133
|
+
else if (horizontalInsets.left > 0) {
|
|
134
|
+
this._surface.style.position = 'absolute';
|
|
135
|
+
this._surface.style.left = `${horizontalInsets.left}px`;
|
|
136
|
+
this._surface.style.top = '0';
|
|
137
|
+
}
|
|
138
|
+
if (showHri) {
|
|
139
|
+
const genericHri = ['code128', 'code39', 'code93', 'code11', 'interleaved2of5',
|
|
140
|
+
'standard2of5', 'industrial2of5', 'codabar', 'msi'].includes(props.type);
|
|
141
|
+
const eanStyle = isEanUpc ? getEanUpcHriStyle(linear.moduleWidth) : null;
|
|
142
|
+
const hriFontSize = eanStyle?.fontSize ?? (genericHri ? 9.7 * Math.max(1, Math.round(linear.moduleWidth)) : 12);
|
|
143
|
+
this._hri.style.height = `${textZone}px`;
|
|
144
|
+
this._hri.style.fontSize = `${hriFontSize}px`;
|
|
145
|
+
this._hri.style.lineHeight = `${hriFontSize}px`;
|
|
146
|
+
this._hri.style.fontFamily = eanStyle ? eanStyle.fontFamily : '';
|
|
147
|
+
this._hri.style.letterSpacing = genericHri ? '.6px' : 'normal';
|
|
148
|
+
this._hri.style.transform = genericHri ? 'translateX(-3px)' : '';
|
|
149
|
+
if (isEanUpc && !textAbove && eanStyle) {
|
|
150
|
+
const barWidth = uprightWidth - horizontalInsets.left - horizontalInsets.right;
|
|
151
|
+
this._hri.className = 'ean-upc';
|
|
152
|
+
this._hri.style.left = `${horizontalInsets.left}px`;
|
|
153
|
+
this._hri.style.width = `${barWidth}px`;
|
|
154
|
+
this._hri.style.top = `${uprightHeight + eanStyle.gap}px`;
|
|
155
|
+
for (const fragment of getEanUpcHriFragments(props)) {
|
|
156
|
+
const digit = document.createElement('span');
|
|
157
|
+
digit.textContent = fragment.char;
|
|
158
|
+
digit.style.left = `${(fragment.xModule - 1) * linear.moduleWidth - hriFontSize / 2}px`;
|
|
159
|
+
digit.style.width = `${hriFontSize}px`;
|
|
160
|
+
this._hri.appendChild(digit);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
this._hri.textContent = barcodeInterpretationText(props);
|
|
165
|
+
// Zebra keeps a roughly five-dot bar-to-cap gap. Vera Mono's
|
|
166
|
+
// cap top sits about .14em below its line-box top. The DOM
|
|
167
|
+
// rasterizer needs three extra dots to match the printer cap.
|
|
168
|
+
const belowTop = uprightHeight + 8 - hriFontSize * .14;
|
|
169
|
+
this._hri.style.top = textAbove ? '0' : `${belowTop}px`;
|
|
170
|
+
}
|
|
171
|
+
this._hri.hidden = false;
|
|
172
|
+
}
|
|
173
|
+
uprightHeight += textZone;
|
|
62
174
|
}
|
|
175
|
+
this._surface.appendChild(canvas);
|
|
176
|
+
this._setRotatedBounds(uprightWidth, uprightHeight, props.rotation);
|
|
63
177
|
}
|
|
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";
|
|
178
|
+
_setRotatedBounds(width, height, rotation) {
|
|
179
|
+
this._frame.style.width = `${width}px`;
|
|
180
|
+
this._frame.style.height = `${height}px`;
|
|
181
|
+
switch (rotation) {
|
|
182
|
+
case 'R':
|
|
183
|
+
this._frame.style.transform = `translateX(${height}px) rotate(90deg)`;
|
|
184
|
+
this.style.width = `${height}px`;
|
|
185
|
+
this.style.height = `${width}px`;
|
|
80
186
|
break;
|
|
81
|
-
case
|
|
82
|
-
|
|
187
|
+
case 'I':
|
|
188
|
+
this._frame.style.transform = `translate(${width}px, ${height}px) rotate(180deg)`;
|
|
189
|
+
this.style.width = `${width}px`;
|
|
190
|
+
this.style.height = `${height}px`;
|
|
83
191
|
break;
|
|
84
|
-
case
|
|
85
|
-
|
|
192
|
+
case 'B':
|
|
193
|
+
this._frame.style.transform = `translateY(${width}px) rotate(270deg)`;
|
|
194
|
+
this.style.width = `${height}px`;
|
|
195
|
+
this.style.height = `${width}px`;
|
|
86
196
|
break;
|
|
197
|
+
default:
|
|
198
|
+
this.style.width = `${width}px`;
|
|
199
|
+
this.style.height = `${height}px`;
|
|
87
200
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
201
|
+
}
|
|
202
|
+
createZpl() {
|
|
203
|
+
const props = this.barcodeProps;
|
|
204
|
+
const emitted = getBarcodeDefinition(props.type).emit(props);
|
|
205
|
+
const offset = getBarcodeFieldOriginOffset(props.type, props.rotation);
|
|
206
|
+
const aboveOffset = props.rotation === 'N' ? barcodeFieldOriginAboveOffset(props) : 0;
|
|
207
|
+
const horizontalOffset = props.rotation === 'N' ? barcodeHorizontalInsets(props).left : 0;
|
|
208
|
+
return `${getZplCoordinates(this, 0, offset.x + horizontalOffset, offset.y + aboveOffset)}${emitted.by ?? ''}${emitted.command}^FD${emitted.fieldData}^FS`;
|
|
94
209
|
}
|
|
95
210
|
}
|
|
96
211
|
customElements.define(ZplBarcode.is, ZplBarcode);
|