@node-projects/web-component-designer-zpl 0.3.3 → 0.3.4
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/dist/Constants.d.ts +10 -0
- package/dist/Constants.js +35 -0
- package/dist/fonts/zplFonts.js +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/setupZplServiceContainer.js +2 -1
- package/package.json +1 -1
|
@@ -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
|
+
}
|
package/dist/fonts/zplFonts.js
CHANGED
|
@@ -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 =
|
|
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
package/dist/index.js
CHANGED
|
@@ -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';
|
|
@@ -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',
|
|
85
|
+
serviceContainer.register('elementsService', new JsonFileElementsService('zpl', zplPackageUrl('widgets/elements.json')));
|
|
85
86
|
serviceContainer.register('elementsService', new ZplBarcodeElementsService());
|
|
86
87
|
return serviceContainer;
|
|
87
88
|
}
|
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.
|
|
4
|
+
"version": "0.3.4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"author": "jochen.kuehner@gmx.de",
|