@node-projects/web-component-designer-zpl 0.3.3 → 0.3.5

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.
@@ -0,0 +1,10 @@
1
+ /** Directory holding this package's runtime files: widgets/elements.json and
2
+ * assets/fonts. Both must be published by the host application. */
3
+ export declare var zplBasePath: string;
4
+ /** Overrides where the ZPL add-on loads its element definitions and printer
5
+ * fonts from. Prefer setting globalThis.webComponentDesignerZplBasePath before
6
+ * importing the add-on, so nothing reads the value before it is configured. */
7
+ export declare function setZplBasePath(path: string): void;
8
+ /** Resolves a package relative file against the configured base path, so a
9
+ * document relative default still produces an absolute URL. */
10
+ export declare function zplPackageUrl(relativePath: string): URL;
@@ -0,0 +1,35 @@
1
+ /** Used when the module URL cannot locate the package files and the host
2
+ * configured nothing. Document relative, so it follows a <base href>. */
3
+ const fallbackBasePath = 'assets/web-component-designer-zpl/';
4
+ function resolveBasePath() {
5
+ const configured = globalThis.webComponentDesignerZplBasePath;
6
+ if (configured)
7
+ return configured.endsWith('/') ? configured : configured + '/';
8
+ // Bundlers that do not rewrite import.meta.url replace it with the build
9
+ // machine's file:// path, which the browser cannot fetch. Only a real URL
10
+ // locates widgets/elements.json and assets/fonts next to this module.
11
+ try {
12
+ const moduleUrl = new URL(import.meta.url);
13
+ if (moduleUrl.protocol === 'http:' || moduleUrl.protocol === 'https:')
14
+ return moduleUrl.origin + moduleUrl.pathname.split('/').slice(0, -1).join('/') + '/';
15
+ }
16
+ catch {
17
+ // import.meta.url unavailable or unparsable, fall through
18
+ }
19
+ return fallbackBasePath;
20
+ }
21
+ /** Directory holding this package's runtime files: widgets/elements.json and
22
+ * assets/fonts. Both must be published by the host application. */
23
+ export var zplBasePath = resolveBasePath();
24
+ /** Overrides where the ZPL add-on loads its element definitions and printer
25
+ * fonts from. Prefer setting globalThis.webComponentDesignerZplBasePath before
26
+ * importing the add-on, so nothing reads the value before it is configured. */
27
+ export function setZplBasePath(path) {
28
+ zplBasePath = path.endsWith('/') ? path : path + '/';
29
+ }
30
+ /** Resolves a package relative file against the configured base path, so a
31
+ * document relative default still produces an absolute URL. */
32
+ export function zplPackageUrl(relativePath) {
33
+ const base = typeof document === 'undefined' ? undefined : document.baseURI;
34
+ return new URL(zplBasePath + relativePath, base);
35
+ }
@@ -1,3 +1,4 @@
1
+ import { zplPackageUrl } from '../Constants.js';
1
2
  const deviceFonts = {
2
3
  A: { magStep: 9, magWidthStep: 5, advancePerMag: 6, capInkPerMag: 7.125, capPerEm: .757, advancePerEm: .602, yOffsetEm: .096, xOffsetEm: -.032, widthCorrection: .964, letterSpacingEm: .021 },
3
4
  B: { magStep: 11, magWidthStep: 7, advancePerMag: 9, capInkPerMag: 11.5, capPerEm: .762, advancePerEm: .602, xOffsetEm: -.040 },
@@ -41,7 +42,7 @@ export async function loadZplFonts(document) {
41
42
  ['ZplOCRA', 'OCRA.ttf']
42
43
  ];
43
44
  loading = Promise.all(sources.map(async ([family, file]) => {
44
- const url = new URL(`../assets/fonts/${file}`, import.meta.url);
45
+ const url = zplPackageUrl(`assets/fonts/${file}`);
45
46
  const face = new FontFace(family, `url(${url})`);
46
47
  await face.load();
47
48
  document.fonts.add(face);
package/dist/index.d.ts CHANGED
@@ -21,3 +21,4 @@ export * from "./barcodes/bwipRenderer.js";
21
21
  export * from "./fonts/zplFonts.js";
22
22
  export * from "./setupZplServiceContainer.js";
23
23
  export * from "./zplHelper.js";
24
+ export * from "./Constants.js";
package/dist/index.js CHANGED
@@ -21,3 +21,4 @@ export * from "./barcodes/bwipRenderer.js";
21
21
  export * from "./fonts/zplFonts.js";
22
22
  export * from "./setupZplServiceContainer.js";
23
23
  export * from "./zplHelper.js";
24
+ export * from "./Constants.js";
@@ -1,4 +1,5 @@
1
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
+ import { zplPackageUrl } from './Constants.js';
2
3
  import { ZplLayoutPlacementService } from './services/ZplLayoutPlacementService.js';
3
4
  import { ZplParserService } from './services/ZplParserService.js';
4
5
  import { ZplImageDrop } from './services/ZplImageDrop.js';
@@ -37,9 +38,9 @@ export function createZplDesignerServiceContainer() {
37
38
  serviceContainer.register("elementResizeStrategy", new ZplGraphicResizeStrategy());
38
39
  serviceContainer.register("designItemService", new DesignItemService());
39
40
  serviceContainer.register("deletionService", new DeletionService());
40
- serviceContainer.register("undoService", (designerCanvas) => new UndoService(designerCanvas));
41
- serviceContainer.register("selectionService", (designerCanvas) => new SelectionService(designerCanvas, false));
42
- serviceContainer.register("designItemDocumentPositionService", (designerCanvas) => new DesignItemDocumentPositionService(designerCanvas));
41
+ serviceContainer.registerDocumentService("undoService", container => new UndoService(container));
42
+ serviceContainer.registerDocumentService("selectionService", container => new SelectionService(container, false));
43
+ serviceContainer.registerDocumentService("designItemDocumentPositionService", () => new DesignItemDocumentPositionService());
43
44
  serviceContainer.designerExtensions.set(ExtensionType.Permanent, []);
44
45
  serviceContainer.designerExtensions.set(ExtensionType.PrimarySelection, [
45
46
  new ElementDragTitleExtensionProvider(),
@@ -81,7 +82,7 @@ export function createZplDesignerServiceContainer() {
81
82
  ];
82
83
  serviceContainer.designViewToolbarButtons.push(new PointerToolButtonProvider(), new SeperatorToolProvider(22), new SelectorToolButtonProvider(), new SeperatorToolProvider(22), new ZoomToolButtonProvider(), new SeperatorToolProvider(22), new TransformToolButtonProvider());
83
84
  serviceContainer.config.demoViewWidget = ZplDemoView;
84
- serviceContainer.register('elementsService', new JsonFileElementsService('zpl', new URL("./widgets/elements.json", import.meta.url)));
85
+ serviceContainer.register('elementsService', new JsonFileElementsService('zpl', zplPackageUrl('widgets/elements.json')));
85
86
  serviceContainer.register('elementsService', new ZplBarcodeElementsService());
86
87
  return serviceContainer;
87
88
  }
@@ -1,6 +1,6 @@
1
1
  import { BaseCustomWebComponentConstructorAppend } from '@node-projects/base-custom-webcomponent';
2
2
  import { IUiCommand, InstanceServiceContainer, ServiceContainer } from '@node-projects/web-component-designer';
3
- import { IDemoView } from '@node-projects/web-component-designer/src/elements/widgets/demoView/IDemoView.js';
3
+ import { IDemoView } from '@node-projects/web-component-designer';
4
4
  export declare class ZplDemoView extends BaseCustomWebComponentConstructorAppend implements IDemoView {
5
5
  static readonly template: HTMLTemplateElement;
6
6
  static readonly style: CSSStyleSheet;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "description": "web-component-designer addon: Widgets and Services for creating a ZPL Designer",
3
3
  "name": "@node-projects/web-component-designer-zpl",
4
- "version": "0.3.3",
4
+ "version": "0.3.5",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "author": "jochen.kuehner@gmx.de",
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "@node-projects/base-custom-webcomponent": ">=0.27.8",
22
- "@node-projects/web-component-designer": ">=0.2.0",
22
+ "@node-projects/web-component-designer": ">=0.3.0",
23
23
  "@bwip-js/browser": "4.11.2"
24
24
  },
25
25
  "repository": {