@worm-print-platform/canvas 1.5.2 → 1.5.3

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 (57) hide show
  1. package/README.md +20 -4
  2. package/dist/browser-bundle.d.ts +1 -1
  3. package/dist/canvas.css +2 -2
  4. package/dist/canvas.js +71 -36
  5. package/dist/core/default-template.d.ts +1 -1
  6. package/dist/core/element-definitions.d.ts +1 -1
  7. package/dist/core/format.d.ts +1 -1
  8. package/dist/core/h.d.ts +1 -1
  9. package/dist/core/icons.d.ts +1 -1
  10. package/dist/core/plugin.d.ts +1 -1
  11. package/dist/core/store.d.ts +1 -1
  12. package/dist/host-contract.d.ts +19 -7
  13. package/dist/index.cjs +45 -10
  14. package/dist/index.d.ts +2 -2
  15. package/dist/index.js +1151 -958
  16. package/dist/print-designer.d.ts +27 -4
  17. package/dist/shell/binding.d.ts +1 -1
  18. package/dist/shell/canvas.d.ts +1 -1
  19. package/dist/shell/code.d.ts +1 -1
  20. package/dist/shell/color-picker.d.ts +1 -1
  21. package/dist/shell/controls.d.ts +1 -1
  22. package/dist/shell/crop-anchor.d.ts +1 -1
  23. package/dist/shell/elements.d.ts +1 -1
  24. package/dist/shell/expression-editor.d.ts +1 -1
  25. package/dist/shell/flow-list.d.ts +1 -1
  26. package/dist/shell/font-select.d.ts +1 -1
  27. package/dist/shell/format-bar.d.ts +1 -1
  28. package/dist/shell/help-content/advanced-settings.d.ts +1 -1
  29. package/dist/shell/help-content/changelog.d.ts +1 -1
  30. package/dist/shell/help-content/faq.d.ts +1 -1
  31. package/dist/shell/help-content/features.d.ts +1 -1
  32. package/dist/shell/help-content/getting-started.d.ts +1 -1
  33. package/dist/shell/help-content/index.d.ts +1 -1
  34. package/dist/shell/help-content/shortcuts.d.ts +1 -1
  35. package/dist/shell/help-modal.d.ts +1 -1
  36. package/dist/shell/page-extras.d.ts +1 -1
  37. package/dist/shell/panels.d.ts +1 -1
  38. package/dist/shell/plugin-ui.d.ts +1 -1
  39. package/dist/shell/prop-group.d.ts +1 -1
  40. package/dist/shell/property-panel.d.ts +1 -1
  41. package/dist/shell/property-search.d.ts +1 -1
  42. package/dist/shell/ruler.d.ts +1 -1
  43. package/dist/shell/table-props.d.ts +1 -1
  44. package/dist/shell/table.d.ts +1 -1
  45. package/dist/shell/toolbar-overflow.d.ts +1 -1
  46. package/dist/shell/toolbar.d.ts +1 -1
  47. package/dist/shell/watermark.d.ts +1 -1
  48. package/dist/theme-tokens.d.ts +21 -0
  49. package/dist/version.d.ts +8 -0
  50. package/dist/vue3/PrintDesigner.d.ts +24 -1
  51. package/dist/vue3/PrintHtmlPreview.d.ts +1 -1
  52. package/dist/vue3/index.cjs +2 -2
  53. package/dist/vue3/index.d.ts +1 -1
  54. package/dist/vue3/index.js +70 -60
  55. package/dist/vue3/previewStyle.d.ts +1 -1
  56. package/dist/vue3/toolbarOverflow.d.ts +1 -1
  57. package/package.json +4 -4
@@ -1,12 +1,12 @@
1
- import { defineComponent as B, ref as y, onMounted as L, onBeforeUnmount as H, watch as w, h as g, computed as D, shallowRef as C, reactive as F, onUnmounted as _, provide as j, inject as V, nextTick as U } from "vue";
1
+ import { defineComponent as B, ref as y, onMounted as C, onBeforeUnmount as L, watch as c, h as g, computed as D, shallowRef as M, reactive as F, onUnmounted as _, provide as j, inject as V, nextTick as U } from "vue";
2
2
  import { definePrintDesigner as Z } from "@worm-print-platform/canvas";
3
3
  import { createDefaultTemplate as Pe, toRuntimePool as Re } from "@worm-print-platform/canvas";
4
4
  import { collectLayoutWarnings as G } from "@worm-print-platform/core";
5
5
  import { renderHtmlPages as K, browserCodeRenderer as N } from "@worm-print-platform/core/browser";
6
6
  import { browserCodeRenderer as Se, renderHtmlPages as Ie } from "@worm-print-platform/core/browser";
7
- import { resolvePrinterDpi as $, zoomPresets as q, paperWidthPx as Y, defaultZoomKey as Q, zoomValueOf as X, viewZoomHint as ee, applyPreviewViewZoom as te, resolveZoomKey as ne, resolveToolbarOverflow as oe } from "@worm-print-platform/core/designer";
7
+ import { resolvePrinterDpi as $, zoomPresets as q, paperWidthPx as Y, defaultZoomKey as Q, zoomValueOf as X, viewZoomHint as ee, applyPreviewViewZoom as te, resolveZoomKey as ne, resolveToolbarOverflow as ie } from "@worm-print-platform/core/designer";
8
8
  import { DEFAULT_DEMO_DATA as We, getDemoData as Ae } from "@worm-print-platform/core/designer";
9
- import { TOOLBAR_OVERFLOW_KEY as ie } from "@worm-print-platform/plugin-kit";
9
+ import { TOOLBAR_OVERFLOW_KEY as oe } from "@worm-print-platform/plugin-kit";
10
10
  function re(e, a) {
11
11
  const v = a.map((s) => ({
12
12
  ...s,
@@ -59,7 +59,11 @@ const ae = B({
59
59
  designData: {
60
60
  type: [Object, Array],
61
61
  default: void 0
62
- }
62
+ },
63
+ /** 主题预设:auto(默认)跟随系统 prefers-color-scheme,light/dark 强制 */
64
+ theme: { type: String, default: void 0 },
65
+ /** 主题色值覆盖:传参优先于预设、系统与 CSS 令牌;只影响外壳,画布纸张不受影响 */
66
+ themeConfig: { type: Object, default: void 0 }
63
67
  },
64
68
  emits: {
65
69
  preview: () => !0,
@@ -69,58 +73,64 @@ const ae = B({
69
73
  const i = y(null);
70
74
  let s = null, r = null;
71
75
  typeof customElements < "u" && Z();
72
- function c(t) {
76
+ function f(t) {
73
77
  if (e.initialTemplate !== void 0) {
74
78
  t.template = e.initialTemplate;
75
79
  return;
76
80
  }
77
81
  if (e.initialElements === void 0) return;
78
- const n = t.getTemplateJson(), f = JSON.parse(n);
79
- t.template = re(f, e.initialElements);
82
+ const n = t.getTemplateJson(), m = JSON.parse(n);
83
+ t.template = re(m, e.initialElements);
80
84
  }
81
85
  function x() {
82
86
  const t = i.value;
83
- t && (c(t), e.fields !== void 0 && (t.fields = e.fields), e.fonts !== void 0 && (t.fonts = e.fonts), e.designData !== void 0 && (t.designData = e.designData), t.uploadImage = e.uploadImage, t.uploadDesignBackground = e.uploadDesignBackground, e.isEdit !== void 0 && (t.isEdit = e.isEdit), e.showHelp !== void 0 && (t.showHelp = e.showHelp), e.showPreview !== void 0 && (t.showPreview = e.showPreview), e.showSave !== void 0 && (t.showSave = e.showSave));
87
+ t && (f(t), e.fields !== void 0 && (t.fields = e.fields), e.fonts !== void 0 && (t.fonts = e.fonts), e.designData !== void 0 && (t.designData = e.designData), t.uploadImage = e.uploadImage, t.uploadDesignBackground = e.uploadDesignBackground, e.isEdit !== void 0 && (t.isEdit = e.isEdit), e.showHelp !== void 0 && (t.showHelp = e.showHelp), e.showPreview !== void 0 && (t.showPreview = e.showPreview), e.showSave !== void 0 && (t.showSave = e.showSave), e.theme !== void 0 && (t.theme = e.theme), e.themeConfig !== void 0 && (t.themeConfig = e.themeConfig));
84
88
  }
85
- return L(() => {
89
+ return C(() => {
86
90
  const t = i.value;
87
91
  t && (s = (n) => a("save", n.detail), r = () => a("preview"), t.addEventListener("save", s), t.addEventListener("preview", r), x());
88
- }), H(() => {
92
+ }), L(() => {
89
93
  const t = i.value;
90
94
  s && t?.removeEventListener("save", s), r && t?.removeEventListener("preview", r), s = null, r = null;
91
- }), w(() => e.initialTemplate, () => {
95
+ }), c(() => e.initialTemplate, () => {
92
96
  const t = i.value;
93
- t && c(t);
94
- }), w(() => e.initialElements, () => {
97
+ t && f(t);
98
+ }), c(() => e.initialElements, () => {
95
99
  const t = i.value;
96
- t && c(t);
97
- }), w(() => e.fields, (t) => {
100
+ t && f(t);
101
+ }), c(() => e.fields, (t) => {
98
102
  const n = i.value;
99
103
  n && (n.fields = t ?? []);
100
- }), w(() => e.fonts, (t) => {
104
+ }), c(() => e.fonts, (t) => {
101
105
  const n = i.value;
102
106
  n && (n.fonts = t);
103
- }), w(() => e.designData, (t) => {
107
+ }), c(() => e.designData, (t) => {
104
108
  const n = i.value;
105
109
  n && (n.designData = t);
106
- }), w(() => e.uploadImage, (t) => {
110
+ }), c(() => e.uploadImage, (t) => {
107
111
  const n = i.value;
108
112
  n && (n.uploadImage = t);
109
- }), w(() => e.uploadDesignBackground, (t) => {
113
+ }), c(() => e.uploadDesignBackground, (t) => {
110
114
  const n = i.value;
111
115
  n && (n.uploadDesignBackground = t);
112
- }), w(() => e.isEdit, (t) => {
116
+ }), c(() => e.isEdit, (t) => {
113
117
  const n = i.value;
114
118
  n && t !== void 0 && (n.isEdit = t);
115
- }), w(() => e.showHelp, (t) => {
119
+ }), c(() => e.showHelp, (t) => {
116
120
  const n = i.value;
117
121
  n && t !== void 0 && (n.showHelp = t);
118
- }), w(() => e.showPreview, (t) => {
122
+ }), c(() => e.showPreview, (t) => {
119
123
  const n = i.value;
120
124
  n && t !== void 0 && (n.showPreview = t);
121
- }), w(() => e.showSave, (t) => {
125
+ }), c(() => e.showSave, (t) => {
122
126
  const n = i.value;
123
127
  n && t !== void 0 && (n.showSave = t);
128
+ }), c(() => e.theme, (t) => {
129
+ const n = i.value;
130
+ n && t !== void 0 && (n.theme = t);
131
+ }), c(() => e.themeConfig, (t) => {
132
+ const n = i.value;
133
+ n && t !== void 0 && (n.themeConfig = t);
124
134
  }), v({
125
135
  getTemplateJson() {
126
136
  const t = i.value?.getTemplateJson();
@@ -249,16 +259,16 @@ const ue = B({
249
259
  error: (e) => typeof e == "string"
250
260
  },
251
261
  setup(e, { emit: a, expose: v }) {
252
- const i = y(), s = y(), r = y(!1), c = y(""), x = y([]);
262
+ const i = y(), s = y(), r = y(!1), f = y(""), x = y([]);
253
263
  let E = 0;
254
- const t = D(() => $(e.templateJson)), n = y(0), f = D(
264
+ const t = D(() => $(e.templateJson)), n = y(0), m = D(
255
265
  () => q(t.value, n.value, Y(e.templateJson))
256
- ), p = y(Q(t.value)), k = D(() => X(f.value, p.value)), T = D(() => ee(t.value, p.value));
266
+ ), p = y(Q(t.value)), k = D(() => X(m.value, p.value)), T = D(() => ee(t.value, p.value));
257
267
  function O() {
258
268
  n.value = s.value?.clientWidth ?? 0;
259
269
  }
260
270
  function S() {
261
- p.value = ne(f.value, p.value, t.value);
271
+ p.value = ne(m.value, p.value, t.value);
262
272
  }
263
273
  function P() {
264
274
  te(i.value?.contentWindow?.document, k.value);
@@ -268,11 +278,11 @@ const ue = B({
268
278
  }
269
279
  async function o() {
270
280
  if (!e.templateJson) {
271
- c.value = "", r.value = !1;
281
+ f.value = "", r.value = !1;
272
282
  return;
273
283
  }
274
284
  const l = ++E;
275
- r.value = !0, c.value = "", x.value = [];
285
+ r.value = !0, f.value = "", x.value = [];
276
286
  try {
277
287
  const { html: u, pageCount: b, copies: d, pageLayouts: R } = await K(
278
288
  e.templateJson,
@@ -287,32 +297,32 @@ const ue = B({
287
297
  h && (h.open(), h.write(u), h.close()), O(), S(), P(), a("rendered", b, d);
288
298
  } catch (u) {
289
299
  if (l !== E) return;
290
- c.value = u instanceof Error ? u.message : "未知错误", a("error", c.value);
300
+ f.value = u instanceof Error ? u.message : "未知错误", a("error", f.value);
291
301
  } finally {
292
302
  l === E && (r.value = !1);
293
303
  }
294
304
  }
295
- function m() {
305
+ function w() {
296
306
  const l = i.value?.contentWindow;
297
307
  l && (l.focus(), l.print());
298
308
  }
299
309
  function z(l) {
300
- f.value.some((u) => u.key === l) && (p.value = l);
310
+ m.value.some((u) => u.key === l) && (p.value = l);
301
311
  }
302
- return w(
312
+ return c(
303
313
  () => [e.templateJson, e.printData, e.baseUrl, e.fontBaseUrl, e.renderers],
304
314
  () => {
305
315
  o();
306
316
  },
307
317
  { deep: !0 }
308
- ), w(k, () => P()), L(() => {
318
+ ), c(k, () => P()), C(() => {
309
319
  se(), O(), S(), window.addEventListener("resize", I), o();
310
- }), H(() => {
320
+ }), L(() => {
311
321
  E++, window.removeEventListener("resize", I);
312
- }), v({ print: m, rerender: o, setViewZoom: z, zoomKey: p, presets: f, viewHint: T }), () => {
313
- const l = r.value || !!c.value, u = [];
314
- if (c.value ? u.push(g("div", { key: "error", class: "print-html-preview-error" }, [
315
- g("span", null, `预览渲染失败:${c.value}`)
322
+ }), v({ print: w, rerender: o, setViewZoom: z, zoomKey: p, presets: m, viewHint: T }), () => {
323
+ const l = r.value || !!f.value, u = [];
324
+ if (f.value ? u.push(g("div", { key: "error", class: "print-html-preview-error" }, [
325
+ g("span", null, `预览渲染失败:${f.value}`)
316
326
  ])) : r.value && u.push(g("div", { key: "loading", class: "print-html-preview-loading" }, "预览渲染中…")), u.push(g("iframe", {
317
327
  key: "iframe",
318
328
  ref: i,
@@ -322,7 +332,7 @@ const ue = B({
322
332
  })), x.value.length && !l && u.push(g("div", { key: "warn", class: "print-html-preview-warn", role: "status" }, [
323
333
  g("span", null, `出纸提示:${x.value.join(";")}`)
324
334
  ])), e.templateJson && !l) {
325
- const b = f.value.map((d) => g("button", {
335
+ const b = m.value.map((d) => g("button", {
326
336
  key: d.key,
327
337
  type: "button",
328
338
  class: {
@@ -346,19 +356,19 @@ const ue = B({
346
356
  function be(e) {
347
357
  return `tb-more-slot-${e}`;
348
358
  }
349
- const J = ie, W = 2, de = 74;
359
+ const H = oe, W = 2, de = 74;
350
360
  function ve() {
351
- const e = C(null), a = /* @__PURE__ */ new Map(), v = F(/* @__PURE__ */ new Map()), i = /* @__PURE__ */ new Map();
361
+ const e = M(null), a = /* @__PURE__ */ new Map(), v = F(/* @__PURE__ */ new Map()), i = /* @__PURE__ */ new Map();
352
362
  let s = 0;
353
- const r = y(/* @__PURE__ */ new Set()), c = y(!1), x = D(() => [...v.values()].sort((o, m) => o.order - m.order)), E = D(() => r.value.size > 0);
363
+ const r = y(/* @__PURE__ */ new Set()), f = y(!1), x = D(() => [...v.values()].sort((o, w) => o.order - w.order)), E = D(() => r.value.size > 0);
354
364
  function t() {
355
- for (const [o, m] of a) {
356
- const z = m.offsetWidth;
365
+ for (const [o, w] of a) {
366
+ const z = w.offsetWidth;
357
367
  z > 0 && i.set(o, z);
358
368
  }
359
369
  }
360
370
  function n(o) {
361
- const m = getComputedStyle(o), z = Number.parseFloat(m.gap) || W, l = Number.parseFloat(m.paddingLeft) || 0, u = Number.parseFloat(m.paddingRight) || 0;
371
+ const w = getComputedStyle(o), z = Number.parseFloat(w.gap) || W, l = Number.parseFloat(w.paddingLeft) || 0, u = Number.parseFloat(w.paddingRight) || 0;
362
372
  let b = 0;
363
373
  for (const d of Array.from(o.children)) {
364
374
  if (d.hasAttribute("data-overflow-more") || d.hasAttribute("data-overflow-spacer")) continue;
@@ -367,33 +377,33 @@ function ve() {
367
377
  }
368
378
  return { available: o.clientWidth - l - u, natural: b };
369
379
  }
370
- function f() {
380
+ function m() {
371
381
  const o = e.value;
372
382
  if (!o) return;
373
- const { available: m, natural: z } = n(o), l = r.value.size > 0;
383
+ const { available: w, natural: z } = n(o), l = r.value.size > 0;
374
384
  l || (s = z, t());
375
385
  const u = x.value.map((h) => ({
376
386
  id: h.id,
377
387
  order: h.order,
378
388
  width: i.get(h.id) ?? 0
379
- })), b = u.reduce((h, M) => h - M.width - W, s), d = oe({
380
- available: m,
389
+ })), b = u.reduce((h, J) => h - J.width - W, s), d = ie({
390
+ available: w,
381
391
  pinned: b,
382
392
  moreTriggerWidth: de,
383
393
  gap: W,
384
394
  units: u
385
395
  });
386
- d.movedIds.length === r.value.size && d.movedIds.every((h) => r.value.has(h)) || (r.value = new Set(d.movedIds)), c.value = d.overflowRemains, l && r.value.size === 0 && U(f);
396
+ d.movedIds.length === r.value.size && d.movedIds.every((h) => r.value.has(h)) || (r.value = new Set(d.movedIds)), f.value = d.overflowRemains, l && r.value.size === 0 && U(m);
387
397
  }
388
398
  let p = null;
389
399
  function k(o) {
390
- o !== e.value && (p?.disconnect(), e.value = o, o && typeof ResizeObserver < "u" && (p = new ResizeObserver(() => f()), p.observe(o)), U(f));
400
+ o !== e.value && (p?.disconnect(), e.value = o, o && typeof ResizeObserver < "u" && (p = new ResizeObserver(() => m()), p.observe(o)), U(m));
391
401
  }
392
- function T(o, m) {
393
- v.set(o.id, o), a.set(o.id, m), U(f);
402
+ function T(o, w) {
403
+ v.set(o.id, o), a.set(o.id, w), U(m);
394
404
  }
395
405
  function O(o) {
396
- a.delete(o), v.delete(o), i.delete(o), U(f);
406
+ a.delete(o), v.delete(o), i.delete(o), U(m);
397
407
  }
398
408
  const S = document.createElement("div");
399
409
  function P(o) {
@@ -406,9 +416,9 @@ function ve() {
406
416
  attachRoot: k,
407
417
  registerUnit: T,
408
418
  unregisterUnit: O,
409
- refresh: f,
419
+ refresh: m,
410
420
  movedIds: r,
411
- overflowRemains: c,
421
+ overflowRemains: f,
412
422
  hasMoved: E,
413
423
  chain: x,
414
424
  moved: P,
@@ -417,10 +427,10 @@ function ve() {
417
427
  }
418
428
  function xe() {
419
429
  const e = ve();
420
- return j(J, e), e;
430
+ return j(H, e), e;
421
431
  }
422
432
  function Ee() {
423
- return V(J, null);
433
+ return V(H, null);
424
434
  }
425
435
  function ze() {
426
436
  const e = y(/* @__PURE__ */ new Set()), a = document.createElement("div");
@@ -455,7 +465,7 @@ export {
455
465
  We as DEFAULT_DEMO_DATA,
456
466
  ge as PrintDesigner,
457
467
  ye as PrintHtmlPreview,
458
- J as TOOLBAR_OVERFLOW,
468
+ H as TOOLBAR_OVERFLOW,
459
469
  Se as browserCodeRenderer,
460
470
  Pe as createDefaultTemplate,
461
471
  De as createOverflowUnitDirective,
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @worm-print-platform/canvas v1.5.2
2
+ * @worm-print-platform/canvas v1.5.3
3
3
  * Copyright (c) 2026 worm <liu_long_qqcom@qq.com>
4
4
  * SPDX-FileCopyrightText: 2026 worm <liu_long_qqcom@qq.com>
5
5
  * SPDX-License-Identifier: MIT
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @worm-print-platform/canvas v1.5.2
2
+ * @worm-print-platform/canvas v1.5.3
3
3
  * Copyright (c) 2026 worm <liu_long_qqcom@qq.com>
4
4
  * SPDX-FileCopyrightText: 2026 worm <liu_long_qqcom@qq.com>
5
5
  * SPDX-License-Identifier: MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@worm-print-platform/canvas",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -46,7 +46,7 @@
46
46
  "framework-agnostic"
47
47
  ],
48
48
  "scripts": {
49
- "styles": "node scripts/gen-styles.mjs && node scripts/gen-icons.mjs",
49
+ "styles": "node scripts/gen-styles.mjs && node scripts/gen-icons.mjs && node scripts/gen-version.mjs",
50
50
  "build": "npm run styles && vite build && vite build -c vite.bundle.config.ts && vite build -c vite.vue3.config.ts && tsc -p tsconfig.build.json && node ../../scripts/inject-license-banner.mjs dist",
51
51
  "dev": "npm run styles && vite build --watch",
52
52
  "typecheck": "npm run styles && tsc -p tsconfig.json --noEmit",
@@ -54,8 +54,8 @@
54
54
  "pretest": "npm run typecheck"
55
55
  },
56
56
  "dependencies": {
57
- "@worm-print-platform/core": "^1.5.2",
58
- "@worm-print-platform/plugin-kit": "^1.5.2",
57
+ "@worm-print-platform/core": "^1.5.3",
58
+ "@worm-print-platform/plugin-kit": "^1.5.3",
59
59
  "dompurify": "^3.4.12",
60
60
  "jsbarcode": "^3.12.3",
61
61
  "qrcode": "^1.5.4"