@node-projects/web-component-designer-zpl 0.2.1 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/README.md +16 -2
  2. package/THIRD-PARTY-LICENSES.md +432 -0
  3. package/dist/assets/fonts/LICENSE-APACHE-2.0.txt +202 -0
  4. package/dist/assets/fonts/NOTICE.md +27 -0
  5. package/dist/assets/fonts/OCRA-NOTICE.md +27 -0
  6. package/dist/assets/fonts/OCRA.ttf +0 -0
  7. package/dist/assets/fonts/OCRB-NOTICE.md +21 -0
  8. package/dist/assets/fonts/OCRB.ttf +0 -0
  9. package/dist/assets/fonts/PrintLabMono-NOTICE.md +24 -0
  10. package/dist/assets/fonts/PrintLabMono.ttf +0 -0
  11. package/dist/assets/fonts/PrintLabZPL-Bold.ttf +0 -0
  12. package/dist/assets/fonts/PrintLabZPL-Bold.woff2 +0 -0
  13. package/dist/assets/fonts/VeraMono-Bold.ttf +0 -0
  14. package/dist/assets/fonts/VeraMono-NOTICE.md +57 -0
  15. package/dist/assets/fonts/VeraMono.ttf +0 -0
  16. package/dist/assets/licenses/BWIP-JS-LICENSE.txt +23 -0
  17. package/dist/assets/licenses/ZPLab-LICENSE.txt +21 -0
  18. package/dist/barcodes/barcodeRegistry.d.ts +124 -0
  19. package/dist/barcodes/barcodeRegistry.js +357 -0
  20. package/dist/barcodes/bwipRenderer.d.ts +70 -0
  21. package/dist/barcodes/bwipRenderer.js +552 -0
  22. package/dist/fonts/zplFonts.d.ts +27 -0
  23. package/dist/fonts/zplFonts.js +85 -0
  24. package/dist/index.d.ts +10 -3
  25. package/dist/index.js +10 -3
  26. package/dist/services/ZplBarcodeElementsService.d.ts +5 -0
  27. package/dist/services/ZplBarcodeElementsService.js +16 -0
  28. package/dist/services/ZplBarcodePropertiesService.d.ts +10 -0
  29. package/dist/services/ZplBarcodePropertiesService.js +59 -0
  30. package/dist/services/ZplDiagonalLineExtension.d.ts +46 -0
  31. package/dist/services/ZplDiagonalLineExtension.js +255 -0
  32. package/dist/services/ZplElementResizeStrategy.d.ts +20 -0
  33. package/dist/services/ZplElementResizeStrategy.js +182 -0
  34. package/dist/services/ZplGraphicResizeStrategy.d.ts +18 -0
  35. package/dist/services/ZplGraphicResizeStrategy.js +81 -0
  36. package/dist/services/ZplIncludeInOutputPropertiesService.d.ts +12 -0
  37. package/dist/services/ZplIncludeInOutputPropertiesService.js +50 -0
  38. package/dist/services/ZplParserService.d.ts +7 -4
  39. package/dist/services/ZplParserService.js +214 -249
  40. package/dist/services/ZplSelectionExtensionProvider.d.ts +9 -0
  41. package/dist/services/ZplSelectionExtensionProvider.js +15 -0
  42. package/dist/services/ZplTextEditExtension.d.ts +20 -0
  43. package/dist/services/ZplTextEditExtension.js +80 -0
  44. package/dist/services/ZplTextPropertiesService.d.ts +8 -0
  45. package/dist/services/ZplTextPropertiesService.js +24 -0
  46. package/dist/services/hiddenMetadata.d.ts +17 -0
  47. package/dist/services/hiddenMetadata.js +95 -0
  48. package/dist/services/zplResizeGeometry.d.ts +6 -0
  49. package/dist/services/zplResizeGeometry.js +8 -0
  50. package/dist/setupZplServiceContainer.js +22 -4
  51. package/dist/widgets/elements.json +0 -24
  52. package/dist/widgets/views/zpl-demo-view.js +2 -1
  53. package/dist/widgets/zpl-barcode.d.ts +68 -14
  54. package/dist/widgets/zpl-barcode.js +162 -74
  55. package/dist/widgets/zpl-comment.d.ts +2 -0
  56. package/dist/widgets/zpl-comment.js +6 -3
  57. package/dist/widgets/zpl-graphic-box.d.ts +12 -0
  58. package/dist/widgets/zpl-graphic-box.js +49 -13
  59. package/dist/widgets/zpl-graphic-circle.d.ts +2 -0
  60. package/dist/widgets/zpl-graphic-circle.js +7 -0
  61. package/dist/widgets/zpl-graphic-diagonal-line.d.ts +2 -0
  62. package/dist/widgets/zpl-graphic-diagonal-line.js +7 -0
  63. package/dist/widgets/zpl-image.d.ts +4 -1
  64. package/dist/widgets/zpl-image.js +17 -14
  65. package/dist/widgets/zpl-text.d.ts +38 -8
  66. package/dist/widgets/zpl-text.js +183 -49
  67. package/dist/zplHelper.d.ts +1 -1
  68. package/dist/zplHelper.js +5 -1
  69. package/package.json +9 -4
  70. package/dist/extensions/ZplLayoutResizeExtensionProvider.d.ts +0 -4
  71. package/dist/extensions/ZplLayoutResizeExtensionProvider.js +0 -16
  72. package/dist/jsBarcodeOptions.d.ts +0 -27
  73. package/dist/jsBarcodeOptions.js +0 -14
  74. package/dist/qr.d.ts +0 -11
  75. package/dist/qr.js +0 -759
package/dist/index.d.ts CHANGED
@@ -5,12 +5,19 @@ export * from "./widgets/zpl-graphic-diagonal-line.js";
5
5
  export * from "./widgets/zpl-image.js";
6
6
  export * from "./widgets/zpl-text.js";
7
7
  export * from "./monaco/ZplLanguage.js";
8
- export * from "./extensions/ZplLayoutResizeExtensionProvider.js";
9
8
  export * from "./services/ZplImageDrop.js";
10
9
  export * from "./services/ZplLayoutCopyPasteService.js";
11
10
  export * from "./services/ZplLayoutPlacementService.js";
12
11
  export * from "./services/ZplParserService.js";
13
- export * from "./jsBarcodeOptions.js";
14
- export * from "./qr.js";
12
+ export * from "./services/ZplBarcodePropertiesService.js";
13
+ export * from "./services/ZplIncludeInOutputPropertiesService.js";
14
+ export * from "./services/ZplBarcodeElementsService.js";
15
+ export * from "./services/ZplElementResizeStrategy.js";
16
+ export * from "./services/ZplTextPropertiesService.js";
17
+ export * from "./services/ZplDiagonalLineExtension.js";
18
+ export * from "./services/ZplTextEditExtension.js";
19
+ export * from "./barcodes/barcodeRegistry.js";
20
+ export * from "./barcodes/bwipRenderer.js";
21
+ export * from "./fonts/zplFonts.js";
15
22
  export * from "./setupZplServiceContainer.js";
16
23
  export * from "./zplHelper.js";
package/dist/index.js CHANGED
@@ -5,12 +5,19 @@ export * from "./widgets/zpl-graphic-diagonal-line.js";
5
5
  export * from "./widgets/zpl-image.js";
6
6
  export * from "./widgets/zpl-text.js";
7
7
  export * from "./monaco/ZplLanguage.js";
8
- export * from "./extensions/ZplLayoutResizeExtensionProvider.js";
9
8
  export * from "./services/ZplImageDrop.js";
10
9
  export * from "./services/ZplLayoutCopyPasteService.js";
11
10
  export * from "./services/ZplLayoutPlacementService.js";
12
11
  export * from "./services/ZplParserService.js";
13
- export * from "./jsBarcodeOptions.js";
14
- export * from "./qr.js";
12
+ export * from "./services/ZplBarcodePropertiesService.js";
13
+ export * from "./services/ZplIncludeInOutputPropertiesService.js";
14
+ export * from "./services/ZplBarcodeElementsService.js";
15
+ export * from "./services/ZplElementResizeStrategy.js";
16
+ export * from "./services/ZplTextPropertiesService.js";
17
+ export * from "./services/ZplDiagonalLineExtension.js";
18
+ export * from "./services/ZplTextEditExtension.js";
19
+ export * from "./barcodes/barcodeRegistry.js";
20
+ export * from "./barcodes/bwipRenderer.js";
21
+ export * from "./fonts/zplFonts.js";
15
22
  export * from "./setupZplServiceContainer.js";
16
23
  export * from "./zplHelper.js";
@@ -0,0 +1,5 @@
1
+ import { IElementDefinition, IElementsService } from '@node-projects/web-component-designer';
2
+ export declare class ZplBarcodeElementsService implements IElementsService {
3
+ readonly name = "zpl barcodes";
4
+ getElements(): Promise<IElementDefinition[]>;
5
+ }
@@ -0,0 +1,16 @@
1
+ import { attributesForBarcode, barcodeRegistry, barcodeTypes } from '../barcodes/barcodeRegistry.js';
2
+ export class ZplBarcodeElementsService {
3
+ name = 'zpl barcodes';
4
+ async getElements() {
5
+ return barcodeTypes.map(type => {
6
+ const definition = barcodeRegistry[type];
7
+ return {
8
+ name: definition.label,
9
+ description: `ZPL ^${definition.command} ${definition.label}`,
10
+ tag: 'zpl-barcode',
11
+ type: 'webcomponent',
12
+ defaultAttributes: attributesForBarcode(type)
13
+ };
14
+ });
15
+ }
16
+ }
@@ -0,0 +1,10 @@
1
+ import { AbstractPropertiesService, IDesignItem, IProperty, RefreshMode } from '@node-projects/web-component-designer';
2
+ export declare class ZplBarcodePropertiesService extends AbstractPropertiesService {
3
+ name: string;
4
+ getRefreshMode(): RefreshMode;
5
+ isHandledElement(designItem: IDesignItem): boolean;
6
+ protected _notifyChangedProperty(designItem: IDesignItem): void;
7
+ getProperties(designItem: IDesignItem): Promise<IProperty[]>;
8
+ getValue(designItems: IDesignItem[], property: IProperty): any;
9
+ setValue(designItems: IDesignItem[], property: IProperty, value: any): Promise<void>;
10
+ }
@@ -0,0 +1,59 @@
1
+ import { AbstractPropertiesService, PropertyType, RefreshMode } from '@node-projects/web-component-designer';
2
+ import { getBarcodeDefinition } from '../barcodes/barcodeRegistry.js';
3
+ import { ZplBarcode } from '../widgets/zpl-barcode.js';
4
+ export class ZplBarcodePropertiesService extends AbstractPropertiesService {
5
+ name = 'zplBarcode';
6
+ getRefreshMode() {
7
+ return RefreshMode.fullOnValueChange;
8
+ }
9
+ isHandledElement(designItem) {
10
+ return designItem.element instanceof ZplBarcode;
11
+ }
12
+ _notifyChangedProperty(designItem) {
13
+ designItem.element.refreshFromAttributes();
14
+ }
15
+ async getProperties(designItem) {
16
+ const definition = getBarcodeDefinition(designItem.getAttribute('type'));
17
+ return definition.properties.map(property => ({
18
+ name: property.name,
19
+ displayName: property.name.replace(/[A-Z]/g, value => ` ${value.toLowerCase()}`),
20
+ attributeName: property.attributeName,
21
+ type: property.type === 'enum' ? 'enum' : property.type,
22
+ min: property.min,
23
+ max: property.max,
24
+ step: property.step,
25
+ enumValues: property.values?.map(value => [value, value]),
26
+ defaultValue: definition.defaults[property.name],
27
+ service: this,
28
+ propertyType: PropertyType.attribute
29
+ }));
30
+ }
31
+ getValue(designItems, property) {
32
+ if (property.type !== 'boolean')
33
+ return super.getValue(designItems, property);
34
+ const value = designItems[0]?.getAttribute(property.attributeName ?? property.name);
35
+ if (value == null)
36
+ return property.defaultValue ?? false;
37
+ return value === '' || value === 'true' || value === 'Y';
38
+ }
39
+ async setValue(designItems, property, value) {
40
+ if (property.type !== 'boolean')
41
+ return super.setValue(designItems, property, value);
42
+ if (designItems.length === 0)
43
+ return;
44
+ const group = designItems[0].openGroup(`property changed: ${property.name} to ${value}`);
45
+ try {
46
+ for (const designItem of designItems) {
47
+ if (this.isHandledElement(designItem)) {
48
+ designItem.setAttribute(property.attributeName ?? property.name, value ? 'true' : 'false');
49
+ this._notifyChangedProperty(designItem);
50
+ }
51
+ }
52
+ group.commit();
53
+ }
54
+ catch (error) {
55
+ group.abort();
56
+ throw error;
57
+ }
58
+ }
59
+ }
@@ -0,0 +1,46 @@
1
+ import { AbstractExtension, IDesignItem, IDesignerCanvas, IDesignerExtension, IDesignerExtensionProvider, IExtensionManager, IPoint } from '@node-projects/web-component-designer';
2
+ export type ZplDiagonalOrientation = 'L' | 'R';
3
+ export interface ZplDiagonalEndpoints {
4
+ first: IPoint;
5
+ second: IPoint;
6
+ }
7
+ export interface ZplDiagonalResizeResult {
8
+ endpoints: ZplDiagonalEndpoints;
9
+ left: number;
10
+ top: number;
11
+ width: number;
12
+ height: number;
13
+ orientation: ZplDiagonalOrientation;
14
+ }
15
+ export declare function getZplDiagonalVisibleHeight(elementHeight: number, lineStrokeWidth: number): number;
16
+ export declare function getZplDiagonalElementHeight(visibleHeight: number, lineStrokeWidth: number): number;
17
+ export declare function getZplDiagonalEndpoints(left: number, top: number, width: number, height: number, orientation: ZplDiagonalOrientation): ZplDiagonalEndpoints;
18
+ /**
19
+ * Moves one line endpoint by a gesture delta. The other endpoint is copied
20
+ * unchanged; bounds and ZPL orientation are derived from the resulting line.
21
+ */
22
+ export declare function resizeZplDiagonalEndpoint(original: ZplDiagonalEndpoints, draggedEndpoint: 0 | 1, delta: IPoint, fallbackOrientation: ZplDiagonalOrientation): ZplDiagonalResizeResult;
23
+ export declare class ZplDiagonalLineExtension extends AbstractExtension {
24
+ private _firstHandle?;
25
+ private _secondHandle?;
26
+ private _dragState?;
27
+ private readonly _eventCleanups;
28
+ constructor(extensionManager: IExtensionManager, designerCanvas: IDesignerCanvas, extendedItem: IDesignItem);
29
+ extend(): void;
30
+ refresh(): void;
31
+ dispose(): void;
32
+ private _drawHandle;
33
+ private _pointerDown;
34
+ private _pointerMove;
35
+ private _pointerUp;
36
+ private _pointerCancel;
37
+ private _commit;
38
+ private _restore;
39
+ private _readCssEndpoints;
40
+ private _readOverlayEndpoints;
41
+ }
42
+ export declare class ZplDiagonalLineExtensionProvider implements IDesignerExtensionProvider {
43
+ shouldExtend(_extensionManager: IExtensionManager, designerCanvas: IDesignerCanvas, designItem: IDesignItem): boolean;
44
+ getExtension(extensionManager: IExtensionManager, designerCanvas: IDesignerCanvas, designItem: IDesignItem): IDesignerExtension;
45
+ readonly style: CSSStyleSheet;
46
+ }
@@ -0,0 +1,255 @@
1
+ import { css } from '@node-projects/base-custom-webcomponent';
2
+ import { AbstractExtension, EventNames, OverlayLayer } from '@node-projects/web-component-designer';
3
+ import { ZplGraphicDiagonalLine } from '../widgets/zpl-graphic-diagonal-line.js';
4
+ export function getZplDiagonalVisibleHeight(elementHeight, lineStrokeWidth) {
5
+ return Math.max(0, elementHeight - Math.max(0, lineStrokeWidth));
6
+ }
7
+ export function getZplDiagonalElementHeight(visibleHeight, lineStrokeWidth) {
8
+ return Math.max(0, visibleHeight) + Math.max(0, lineStrokeWidth);
9
+ }
10
+ function orientationForEndpoints(endpoints, fallback) {
11
+ const dx = endpoints.second.x - endpoints.first.x;
12
+ const dy = endpoints.second.y - endpoints.first.y;
13
+ if (dx === 0 || dy === 0)
14
+ return fallback;
15
+ return dx * dy > 0 ? 'L' : 'R';
16
+ }
17
+ export function getZplDiagonalEndpoints(left, top, width, height, orientation) {
18
+ return orientation === 'R'
19
+ ? { first: { x: left, y: top + height }, second: { x: left + width, y: top } }
20
+ : { first: { x: left, y: top }, second: { x: left + width, y: top + height } };
21
+ }
22
+ /**
23
+ * Moves one line endpoint by a gesture delta. The other endpoint is copied
24
+ * unchanged; bounds and ZPL orientation are derived from the resulting line.
25
+ */
26
+ export function resizeZplDiagonalEndpoint(original, draggedEndpoint, delta, fallbackOrientation) {
27
+ const endpoints = {
28
+ first: { ...original.first },
29
+ second: { ...original.second }
30
+ };
31
+ const dragged = draggedEndpoint === 0 ? endpoints.first : endpoints.second;
32
+ const originalDragged = draggedEndpoint === 0 ? original.first : original.second;
33
+ dragged.x = originalDragged.x + delta.x;
34
+ dragged.y = originalDragged.y + delta.y;
35
+ const left = Math.min(endpoints.first.x, endpoints.second.x);
36
+ const top = Math.min(endpoints.first.y, endpoints.second.y);
37
+ return {
38
+ endpoints,
39
+ left,
40
+ top,
41
+ width: Math.abs(endpoints.second.x - endpoints.first.x),
42
+ height: Math.abs(endpoints.second.y - endpoints.first.y),
43
+ orientation: orientationForEndpoints(endpoints, fallbackOrientation)
44
+ };
45
+ }
46
+ function numericStyle(element, name) {
47
+ const inline = parseFloat(element.style.getPropertyValue(name));
48
+ if (Number.isFinite(inline))
49
+ return inline;
50
+ const computed = parseFloat(getComputedStyle(element).getPropertyValue(name));
51
+ return Number.isFinite(computed) ? computed : 0;
52
+ }
53
+ function strokeWidth(element) {
54
+ const value = Number(element.getAttribute('stroke-width'));
55
+ return Number.isFinite(value) ? Math.max(0, value) : 1;
56
+ }
57
+ function px(value) {
58
+ return `${Math.round(value)}px`;
59
+ }
60
+ export class ZplDiagonalLineExtension extends AbstractExtension {
61
+ _firstHandle;
62
+ _secondHandle;
63
+ _dragState;
64
+ _eventCleanups = [];
65
+ constructor(extensionManager, designerCanvas, extendedItem) {
66
+ super(extensionManager, designerCanvas, extendedItem);
67
+ }
68
+ extend() {
69
+ this.refresh();
70
+ }
71
+ refresh() {
72
+ const endpoints = this._dragState?.overlayEndpoints ?? this._readOverlayEndpoints();
73
+ const radius = 5 / this.designerCanvas.scaleFactor;
74
+ this._firstHandle = this._drawHandle(endpoints.first, 0, radius, this._firstHandle);
75
+ this._secondHandle = this._drawHandle(endpoints.second, 1, radius, this._secondHandle);
76
+ }
77
+ dispose() {
78
+ for (const cleanup of this._eventCleanups)
79
+ cleanup();
80
+ this._eventCleanups.length = 0;
81
+ this._removeAllOverlays();
82
+ this._firstHandle = undefined;
83
+ this._secondHandle = undefined;
84
+ this._dragState = undefined;
85
+ }
86
+ _drawHandle(point, endpoint, radius, oldHandle) {
87
+ const handle = this._drawCircle(point.x, point.y, radius, 'svg-zpl-line-endpoint', oldHandle, OverlayLayer.Foreground);
88
+ handle.style.strokeWidth = `${1 / this.designerCanvas.zoomFactor}`;
89
+ handle.style.cursor = 'move';
90
+ if (!oldHandle) {
91
+ const down = (event) => this._pointerDown(event, handle, endpoint);
92
+ const move = (event) => this._pointerMove(event, endpoint);
93
+ const up = (event) => this._pointerUp(event);
94
+ const cancel = (event) => this._pointerCancel(event);
95
+ handle.addEventListener(EventNames.PointerDown, down);
96
+ handle.addEventListener(EventNames.PointerMove, move);
97
+ handle.addEventListener(EventNames.PointerUp, up);
98
+ handle.addEventListener('pointercancel', cancel);
99
+ this._eventCleanups.push(() => handle.removeEventListener(EventNames.PointerDown, down), () => handle.removeEventListener(EventNames.PointerMove, move), () => handle.removeEventListener(EventNames.PointerUp, up), () => handle.removeEventListener('pointercancel', cancel));
100
+ }
101
+ return handle;
102
+ }
103
+ _pointerDown(event, handle, endpoint) {
104
+ event.stopPropagation();
105
+ event.preventDefault();
106
+ handle.setPointerCapture(event.pointerId);
107
+ const element = this.extendedItem.element;
108
+ this._dragState = {
109
+ draggedEndpoint: endpoint,
110
+ startPointer: this.designerCanvas.getNormalizedEventCoordinates(event),
111
+ originalCssEndpoints: this._readCssEndpoints(),
112
+ originalOverlayEndpoints: this._readOverlayEndpoints(),
113
+ overlayEndpoints: this._readOverlayEndpoints(),
114
+ originalStyles: {
115
+ left: element.style.left,
116
+ top: element.style.top,
117
+ right: element.style.right,
118
+ bottom: element.style.bottom,
119
+ width: element.style.width,
120
+ height: element.style.height
121
+ },
122
+ originalOrientation: element.getAttribute('orientation'),
123
+ changed: false
124
+ };
125
+ }
126
+ _pointerMove(event, endpoint) {
127
+ event.stopPropagation();
128
+ event.preventDefault();
129
+ const state = this._dragState;
130
+ if (!state || state.draggedEndpoint !== endpoint || event.buttons === 0)
131
+ return;
132
+ const current = this.designerCanvas.getNormalizedEventCoordinates(event);
133
+ const delta = { x: current.x - state.startPointer.x, y: current.y - state.startPointer.y };
134
+ if (event.shiftKey) {
135
+ if (Math.abs(delta.x) >= Math.abs(delta.y))
136
+ delta.y = 0;
137
+ else
138
+ delta.x = 0;
139
+ }
140
+ const orientation = state.originalOrientation === 'R' ? 'R' : 'L';
141
+ const result = resizeZplDiagonalEndpoint(state.originalCssEndpoints, endpoint, delta, orientation);
142
+ const roundedDelta = {
143
+ x: Math.round((endpoint === 0 ? result.endpoints.first : result.endpoints.second).x)
144
+ - (endpoint === 0 ? state.originalCssEndpoints.first.x : state.originalCssEndpoints.second.x),
145
+ y: Math.round((endpoint === 0 ? result.endpoints.first : result.endpoints.second).y)
146
+ - (endpoint === 0 ? state.originalCssEndpoints.first.y : state.originalCssEndpoints.second.y)
147
+ };
148
+ state.overlayEndpoints = {
149
+ first: { ...state.originalOverlayEndpoints.first },
150
+ second: { ...state.originalOverlayEndpoints.second }
151
+ };
152
+ const overlayDragged = endpoint === 0 ? state.overlayEndpoints.first : state.overlayEndpoints.second;
153
+ const originalOverlayDragged = endpoint === 0 ? state.originalOverlayEndpoints.first : state.originalOverlayEndpoints.second;
154
+ overlayDragged.x = originalOverlayDragged.x + roundedDelta.x;
155
+ overlayDragged.y = originalOverlayDragged.y + roundedDelta.y;
156
+ const element = this.extendedItem.element;
157
+ element.style.removeProperty('right');
158
+ element.style.removeProperty('bottom');
159
+ element.style.left = px(result.left);
160
+ element.style.top = px(result.top);
161
+ element.style.width = px(result.width);
162
+ // ZplGraphicDiagonalLine keeps its stroke inside the host by drawing
163
+ // the lower SVG endpoint at `height - strokeWidth`.
164
+ element.style.height = px(getZplDiagonalElementHeight(result.height, strokeWidth(element)));
165
+ element.setAttribute('orientation', result.orientation);
166
+ state.changed = true;
167
+ this.refresh();
168
+ this.extensionManager.refreshAllExtensions([this.extendedItem, this.extendedItem.parent], this);
169
+ this.designerCanvas.raiseDesignItemsChanged([this.extendedItem], 'resize', false);
170
+ }
171
+ _pointerUp(event) {
172
+ event.stopPropagation();
173
+ event.target.releasePointerCapture(event.pointerId);
174
+ const state = this._dragState;
175
+ if (!state)
176
+ return;
177
+ if (state.changed)
178
+ this._commit(state);
179
+ this._dragState = undefined;
180
+ this.refresh();
181
+ }
182
+ _pointerCancel(event) {
183
+ event.stopPropagation();
184
+ if (!this._dragState)
185
+ return;
186
+ this._restore(this._dragState);
187
+ this._dragState = undefined;
188
+ this.refresh();
189
+ this.extensionManager.refreshAllExtensions([this.extendedItem, this.extendedItem.parent], this);
190
+ }
191
+ _commit(state) {
192
+ const element = this.extendedItem.element;
193
+ const finalStyles = {
194
+ left: element.style.left,
195
+ top: element.style.top,
196
+ width: element.style.width === '0px' ? '1px' : element.style.width,
197
+ height: element.style.height === '0px' ? '1px' : element.style.height
198
+ };
199
+ const finalOrientation = element.getAttribute('orientation') ?? 'L';
200
+ this._restore(state);
201
+ const group = this.extendedItem.openGroup('Resize ZPL diagonal line');
202
+ try {
203
+ this.extendedItem.setStyle('right', null);
204
+ this.extendedItem.setStyle('bottom', null);
205
+ this.extendedItem.setStyle('left', finalStyles.left);
206
+ this.extendedItem.setStyle('top', finalStyles.top);
207
+ this.extendedItem.setStyle('width', finalStyles.width);
208
+ this.extendedItem.setStyle('height', finalStyles.height);
209
+ this.extendedItem.setAttribute('orientation', finalOrientation);
210
+ group.commit();
211
+ this.designerCanvas.raiseDesignItemsChanged([this.extendedItem], 'resize', true);
212
+ }
213
+ catch (error) {
214
+ group.abort();
215
+ throw error;
216
+ }
217
+ }
218
+ _restore(state) {
219
+ const element = this.extendedItem.element;
220
+ for (const [name, value] of Object.entries(state.originalStyles)) {
221
+ if (value)
222
+ element.style.setProperty(name, value);
223
+ else
224
+ element.style.removeProperty(name);
225
+ }
226
+ if (state.originalOrientation == null)
227
+ element.removeAttribute('orientation');
228
+ else
229
+ element.setAttribute('orientation', state.originalOrientation);
230
+ }
231
+ _readCssEndpoints() {
232
+ const element = this.extendedItem.element;
233
+ return getZplDiagonalEndpoints(numericStyle(element, 'left'), numericStyle(element, 'top'), numericStyle(element, 'width'), getZplDiagonalVisibleHeight(numericStyle(element, 'height'), strokeWidth(element)), element.getAttribute('orientation') === 'R' ? 'R' : 'L');
234
+ }
235
+ _readOverlayEndpoints() {
236
+ const element = this.extendedItem.element;
237
+ const rect = this.designerCanvas.getNormalizedElementCoordinates(this.extendedItem.element);
238
+ return getZplDiagonalEndpoints(rect.x, rect.y, rect.width, getZplDiagonalVisibleHeight(rect.height, strokeWidth(element)), this.extendedItem.getAttribute('orientation') === 'R' ? 'R' : 'L');
239
+ }
240
+ }
241
+ export class ZplDiagonalLineExtensionProvider {
242
+ shouldExtend(_extensionManager, designerCanvas, designItem) {
243
+ return !designerCanvas.readOnly && designItem.element.localName === ZplGraphicDiagonalLine.is;
244
+ }
245
+ getExtension(extensionManager, designerCanvas, designItem) {
246
+ return new ZplDiagonalLineExtension(extensionManager, designerCanvas, designItem);
247
+ }
248
+ style = css `
249
+ .svg-zpl-line-endpoint {
250
+ stroke: #3899ec;
251
+ fill: white;
252
+ pointer-events: auto;
253
+ }
254
+ `;
255
+ }
@@ -0,0 +1,20 @@
1
+ import { ElementResizeContext, IDesignItem, IElementResizeStrategy, ISize, ResizeHandle } from '@node-projects/web-component-designer';
2
+ export { quantizeZplValue, zplAxisScales } from './zplResizeGeometry.js';
3
+ interface ResizeState {
4
+ originalAttributes: Map<string, string | null>;
5
+ previewAttributes: Map<string, string>;
6
+ originalWidth: string;
7
+ originalHeight: string;
8
+ }
9
+ export declare class ZplElementResizeStrategy implements IElementResizeStrategy {
10
+ isHandledElement(designItem: IDesignItem): boolean;
11
+ getEnabledHandles(designItem: IDesignItem): readonly ResizeHandle[];
12
+ begin(context: ElementResizeContext): ResizeState;
13
+ preview(context: ElementResizeContext, rawState: unknown): ISize;
14
+ commit(context: ElementResizeContext, rawState: unknown): void;
15
+ cancel(context: ElementResizeContext, rawState: unknown): void;
16
+ private _restoreRaw;
17
+ private _initialNumber;
18
+ private _textAttributes;
19
+ private _barcodeAttributes;
20
+ }
@@ -0,0 +1,182 @@
1
+ import { getBarcodeDefinition } from '../barcodes/barcodeRegistry.js';
2
+ import { ZplBarcode } from '../widgets/zpl-barcode.js';
3
+ import { ZplText } from '../widgets/zpl-text.js';
4
+ import { getDeviceFontMagnification } from '../fonts/zplFonts.js';
5
+ import { quantizeZplValue, zplAxisScales } from './zplResizeGeometry.js';
6
+ export { quantizeZplValue, zplAxisScales } from './zplResizeGeometry.js';
7
+ const allHandles = ['nw-resize', 'n-resize', 'ne-resize', 'w-resize', 'sw-resize', 's-resize', 'e-resize', 'se-resize'];
8
+ const edgeHandles = ['n-resize', 'w-resize', 's-resize', 'e-resize'];
9
+ const cornerHandles = ['nw-resize', 'ne-resize', 'sw-resize', 'se-resize'];
10
+ const clamp = quantizeZplValue;
11
+ export class ZplElementResizeStrategy {
12
+ isHandledElement(designItem) {
13
+ return designItem.element instanceof ZplText || designItem.element instanceof ZplBarcode;
14
+ }
15
+ getEnabledHandles(designItem) {
16
+ if (designItem.element instanceof ZplText)
17
+ return allHandles;
18
+ const definition = getBarcodeDefinition(designItem.getAttribute('type'));
19
+ if (definition.resizeKind === 'intrinsic')
20
+ return [];
21
+ if (definition.resizeKind === 'uniform-2d')
22
+ return cornerHandles;
23
+ if (definition.resizeKind === 'linear')
24
+ return edgeHandles;
25
+ return allHandles;
26
+ }
27
+ begin(context) {
28
+ const element = context.designItem.element;
29
+ return {
30
+ originalAttributes: new Map(),
31
+ previewAttributes: new Map(),
32
+ originalWidth: element.style.width,
33
+ originalHeight: element.style.height
34
+ };
35
+ }
36
+ preview(context, rawState) {
37
+ const state = rawState;
38
+ const element = context.designItem.element;
39
+ const attributes = element instanceof ZplText
40
+ ? this._textAttributes(element, context, state)
41
+ : this._barcodeAttributes(element, context, state);
42
+ for (const [name, value] of Object.entries(attributes)) {
43
+ if (!state.originalAttributes.has(name))
44
+ state.originalAttributes.set(name, element.getAttribute(name));
45
+ state.previewAttributes.set(name, value);
46
+ element.setAttribute(name, value);
47
+ }
48
+ // ResizeExtension writes a temporary CSS box before invoking the ZPL
49
+ // strategy. When quantization keeps every attribute unchanged, native
50
+ // attribute callbacks do not fire and that temporary box would survive
51
+ // until the next device-font/barcode threshold, causing a large jump.
52
+ if (element instanceof ZplText)
53
+ element.renderText();
54
+ else
55
+ element.renderBarcode();
56
+ const bounds = element.getBoundingClientRect();
57
+ return { width: bounds.width, height: bounds.height };
58
+ }
59
+ commit(context, rawState) {
60
+ const state = rawState;
61
+ const element = context.designItem.element;
62
+ this._restoreRaw(element, state);
63
+ for (const [name, value] of state.previewAttributes)
64
+ context.designItem.setAttribute(name, value);
65
+ }
66
+ cancel(context, rawState) {
67
+ this._restoreRaw(context.designItem.element, rawState);
68
+ }
69
+ _restoreRaw(element, state) {
70
+ for (const [name, value] of state.originalAttributes) {
71
+ if (value == null)
72
+ element.removeAttribute(name);
73
+ else
74
+ element.setAttribute(name, value);
75
+ }
76
+ element.style.width = state.originalWidth;
77
+ element.style.height = state.originalHeight;
78
+ if (element instanceof ZplBarcode)
79
+ element.renderBarcode();
80
+ else if (element instanceof ZplText)
81
+ element.renderText();
82
+ }
83
+ _initialNumber(state, element, name, fallback) {
84
+ if (!state.originalAttributes.has(name))
85
+ state.originalAttributes.set(name, element.getAttribute(name));
86
+ const value = Number(state.originalAttributes.get(name));
87
+ return Number.isFinite(value) && value > 0 ? value : fallback;
88
+ }
89
+ _textAttributes(element, context, state) {
90
+ const scales = zplAxisScales(element.getAttribute('rotation'), context.initialSize, context.currentSize);
91
+ const fontWidthScale = scales.width;
92
+ const fontHeightScale = scales.height;
93
+ if (!state.originalAttributes.has('font-width'))
94
+ state.originalAttributes.set('font-width', element.getAttribute('font-width'));
95
+ const originalWidth = Number(state.originalAttributes.get('font-width'));
96
+ const originalHeight = this._initialNumber(state, element, 'font-height', 30);
97
+ const font = (element.getAttribute('font-name') || '0');
98
+ const deviceFont = getDeviceFontMagnification(font, originalHeight, originalWidth);
99
+ if (deviceFont) {
100
+ // Bitmap fonts A-H can only change in integer cell
101
+ // magnifications. Scale the magnification visible at gesture start,
102
+ // not the raw requested dot value: e.g. Font A height 30 renders at
103
+ // 3x and must not jump to 4x after a two-dot drag.
104
+ const heightMagnification = clamp(deviceFont.height * fontHeightScale, 1, 10);
105
+ const widthMagnification = clamp(deviceFont.width * fontWidthScale, 1, 10);
106
+ const fontHeight = heightMagnification === deviceFont.height
107
+ ? originalHeight
108
+ : heightMagnification * deviceFont.heightStep;
109
+ let fontWidth;
110
+ if (!(originalWidth > 0) && widthMagnification === heightMagnification) {
111
+ fontWidth = 0;
112
+ }
113
+ else if (originalWidth > 0 && widthMagnification === deviceFont.width) {
114
+ fontWidth = originalWidth;
115
+ }
116
+ else {
117
+ fontWidth = widthMagnification * deviceFont.widthStep;
118
+ }
119
+ return {
120
+ 'font-width': String(fontWidth),
121
+ 'font-height': String(fontHeight)
122
+ };
123
+ }
124
+ const fontHeight = clamp(originalHeight * fontHeightScale, 1, 32000);
125
+ let fontWidth;
126
+ if (Number.isFinite(originalWidth) && originalWidth > 0) {
127
+ fontWidth = clamp(originalWidth * fontWidthScale, 1, 32000);
128
+ }
129
+ else if (Math.abs(fontWidthScale - fontHeightScale) < .01) {
130
+ // A proportional resize keeps Zebra's automatic-width semantics.
131
+ fontWidth = 0;
132
+ }
133
+ else {
134
+ const residualScale = fontWidthScale / Math.max(.01, fontHeightScale);
135
+ fontWidth = clamp(fontHeight * residualScale, 1, 32000);
136
+ }
137
+ return {
138
+ 'font-width': String(fontWidth),
139
+ 'font-height': String(fontHeight)
140
+ };
141
+ }
142
+ _barcodeAttributes(element, context, state) {
143
+ const definition = getBarcodeDefinition(element.getAttribute('type'));
144
+ const defaults = definition.defaults;
145
+ const screenWidthScale = context.currentSize.width / Math.max(1, context.initialSize.width);
146
+ const screenHeightScale = context.currentSize.height / Math.max(1, context.initialSize.height);
147
+ const scales = zplAxisScales(element.getAttribute('rotation'), context.initialSize, context.currentSize);
148
+ const widthScale = scales.width;
149
+ const heightScale = scales.height;
150
+ if (definition.resizeKind === 'uniform-2d') {
151
+ const scale = Math.min(screenWidthScale, screenHeightScale);
152
+ const attribute = definition.type === 'datamatrix' ? 'dimension' : 'magnification';
153
+ return { [attribute]: String(clamp(this._initialNumber(state, element, attribute, Number(defaults[attribute] ?? 4)) * scale, 1, definition.type === 'datamatrix' ? 12 : 10)) };
154
+ }
155
+ if (definition.resizeKind === 'stacked-2d') {
156
+ return {
157
+ 'module-width': String(clamp(this._initialNumber(state, element, 'module-width', Number(defaults.moduleWidth ?? 2)) * widthScale, definition.type === 'codablock' || definition.type === 'pdf417' ? 2 : 1, 10)),
158
+ 'row-height': String(clamp(this._initialNumber(state, element, 'row-height', Number(defaults.rowHeight ?? 2)) * heightScale, 1, 9999))
159
+ };
160
+ }
161
+ if (definition.resizeKind === 'tlc39') {
162
+ return {
163
+ 'module-width': String(clamp(this._initialNumber(state, element, 'module-width', Number(defaults.moduleWidth ?? 2)) * widthScale, 1, 10)),
164
+ 'bar-height': String(clamp(this._initialNumber(state, element, 'bar-height', Number(defaults.barHeight ?? 40)) * heightScale, 1, 32000)),
165
+ 'micro-pdf-module-width': String(clamp(this._initialNumber(state, element, 'micro-pdf-module-width', Number(defaults.microPdfModuleWidth ?? 2)) * widthScale, 1, 10)),
166
+ 'micro-pdf-row-height': String(clamp(this._initialNumber(state, element, 'micro-pdf-row-height', Number(defaults.microPdfRowHeight ?? 4)) * heightScale, 1, 9999))
167
+ };
168
+ }
169
+ const initialModuleWidth = this._initialNumber(state, element, 'module-width', Number(defaults.moduleWidth ?? 2));
170
+ const moduleWidth = clamp(initialModuleWidth * widthScale, 1, 10);
171
+ let barHeight = clamp(this._initialNumber(state, element, 'bar-height', Number(defaults.barHeight ?? 100)) * heightScale, 1, 32000);
172
+ if (definition.type === 'code49')
173
+ barHeight = clamp(barHeight, moduleWidth * 8, moduleWidth * 50);
174
+ const attributes = { 'module-width': String(moduleWidth), 'bar-height': String(barHeight) };
175
+ if (definition.properties.some(property => property.attributeName === 'wide-ratio')) {
176
+ const residualScale = widthScale / Math.max(.1, moduleWidth / initialModuleWidth);
177
+ const wideRatio = Math.max(2, Math.min(3, Math.round(this._initialNumber(state, element, 'wide-ratio', Number(defaults.wideRatio ?? 3)) * residualScale * 10) / 10));
178
+ return { ...attributes, 'wide-ratio': String(wideRatio) };
179
+ }
180
+ return attributes;
181
+ }
182
+ }
@@ -0,0 +1,18 @@
1
+ import { ElementResizeContext, ElementResizePreview, IDesignItem, IElementResizeStrategy, ResizeHandle } from '@node-projects/web-component-designer';
2
+ interface GraphicResizeState {
3
+ originalWidth: string;
4
+ originalHeight: string;
5
+ originalLeft: string;
6
+ originalTop: string;
7
+ originalRight: string;
8
+ originalBottom: string;
9
+ }
10
+ export declare class ZplGraphicResizeStrategy implements IElementResizeStrategy {
11
+ isHandledElement(designItem: IDesignItem): boolean;
12
+ getEnabledHandles(designItem: IDesignItem): readonly ResizeHandle[];
13
+ begin(context: ElementResizeContext): GraphicResizeState;
14
+ preview(context: ElementResizeContext, rawState: unknown): ElementResizePreview;
15
+ commit(context: ElementResizeContext, rawState: unknown): void;
16
+ cancel(context: ElementResizeContext, rawState: unknown): void;
17
+ }
18
+ export {};