@worm-print-platform/canvas 1.5.2 → 1.6.0
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 +26 -4
- package/dist/browser-bundle.d.ts +1 -1
- package/dist/canvas.css +2 -2
- package/dist/canvas.js +111 -64
- package/dist/core/default-template.d.ts +1 -1
- package/dist/core/element-definitions.d.ts +1 -1
- package/dist/core/format.d.ts +1 -1
- package/dist/core/h.d.ts +3 -17
- package/dist/core/icons.d.ts +1 -1
- package/dist/core/plugin.d.ts +1 -1
- package/dist/core/store.d.ts +1 -1
- package/dist/host-contract.d.ts +25 -7
- package/dist/index.cjs +57 -10
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1906 -1667
- package/dist/print-designer.d.ts +31 -4
- package/dist/shell/binding.d.ts +2 -2
- package/dist/shell/canvas.d.ts +2 -2
- package/dist/shell/code.d.ts +3 -3
- package/dist/shell/color-picker.d.ts +3 -39
- package/dist/shell/controls.d.ts +14 -11
- package/dist/shell/crop-anchor.d.ts +2 -2
- package/dist/shell/elements.d.ts +2 -2
- package/dist/shell/expression-editor.d.ts +3 -28
- package/dist/shell/flow-list.d.ts +2 -2
- package/dist/shell/font-select.d.ts +1 -1
- package/dist/shell/format-bar.d.ts +2 -2
- package/dist/shell/help-content/advanced-settings.d.ts +1 -1
- package/dist/shell/help-content/changelog.d.ts +1 -1
- package/dist/shell/help-content/faq.d.ts +1 -1
- package/dist/shell/help-content/features.d.ts +1 -1
- package/dist/shell/help-content/getting-started.d.ts +1 -1
- package/dist/shell/help-content/index.d.ts +1 -1
- package/dist/shell/help-content/shortcuts.d.ts +1 -1
- package/dist/shell/help-modal.d.ts +1 -1
- package/dist/shell/page-extras.d.ts +1 -1
- package/dist/shell/panels.d.ts +4 -4
- package/dist/shell/plugin-ui.d.ts +1 -1
- package/dist/shell/prop-group.d.ts +1 -1
- package/dist/shell/property-panel.d.ts +1 -1
- package/dist/shell/property-search.d.ts +1 -1
- package/dist/shell/ruler.d.ts +1 -1
- package/dist/shell/table-props.d.ts +1 -1
- package/dist/shell/table.d.ts +1 -1
- package/dist/shell/toolbar-overflow.d.ts +2 -2
- package/dist/shell/toolbar.d.ts +2 -2
- package/dist/shell/watermark.d.ts +1 -1
- package/dist/theme-tokens.d.ts +21 -0
- package/dist/version.d.ts +8 -0
- package/dist/vue3/PrintDesigner.d.ts +24 -1
- package/dist/vue3/PrintHtmlPreview.d.ts +1 -1
- package/dist/vue3/index.cjs +2 -2
- package/dist/vue3/index.d.ts +1 -1
- package/dist/vue3/index.js +70 -60
- package/dist/vue3/previewStyle.d.ts +1 -1
- package/dist/vue3/toolbarOverflow.d.ts +1 -1
- package/package.json +4 -4
package/dist/vue3/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("vue"),U=require("@worm-print-platform/canvas"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("vue"),U=require("@worm-print-platform/canvas"),C=require("@worm-print-platform/core"),S=require("@worm-print-platform/core/browser"),g=require("@worm-print-platform/core/designer"),j=require("@worm-print-platform/plugin-kit");function H(e,l){const v=l.map(u=>({...u,options:{...u.options},printElementType:{...u.printElementType}})),i=e.pages;return Array.isArray(i)?{...e,pages:i.map((u,a)=>a===0?{...u,elements:v}:u)}:{...e,elements:v}}const M=n.defineComponent({name:"PrintDesigner",props:{initialTemplate:{type:Object,default:void 0},initialElements:{type:Array,default:void 0},fields:{type:Array,default:void 0},isEdit:{type:Boolean,default:void 0},uploadImage:{type:Function,default:void 0},uploadDesignBackground:{type:Function,default:void 0},showHelp:{type:Boolean,default:void 0},showPreview:{type:Boolean,default:void 0},showSave:{type:Boolean,default:void 0},fonts:{type:Array,default:void 0},designData:{type:[Object,Array],default:void 0},theme:{type:String,default:void 0},themeConfig:{type:Object,default:void 0}},emits:{preview:()=>!0,save:e=>typeof e=="string"},setup(e,{emit:l,expose:v}){const i=n.ref(null);let u=null,a=null;typeof customElements<"u"&&U.definePrintDesigner();function f(t){if(e.initialTemplate!==void 0){t.template=e.initialTemplate;return}if(e.initialElements===void 0)return;const o=t.getTemplateJson(),m=JSON.parse(o);t.template=H(m,e.initialElements)}function y(){const t=i.value;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))}return n.onMounted(()=>{const t=i.value;t&&(u=o=>l("save",o.detail),a=()=>l("preview"),t.addEventListener("save",u),t.addEventListener("preview",a),y())}),n.onBeforeUnmount(()=>{const t=i.value;u&&t?.removeEventListener("save",u),a&&t?.removeEventListener("preview",a),u=null,a=null}),n.watch(()=>e.initialTemplate,()=>{const t=i.value;t&&f(t)}),n.watch(()=>e.initialElements,()=>{const t=i.value;t&&f(t)}),n.watch(()=>e.fields,t=>{const o=i.value;o&&(o.fields=t??[])}),n.watch(()=>e.fonts,t=>{const o=i.value;o&&(o.fonts=t)}),n.watch(()=>e.designData,t=>{const o=i.value;o&&(o.designData=t)}),n.watch(()=>e.uploadImage,t=>{const o=i.value;o&&(o.uploadImage=t)}),n.watch(()=>e.uploadDesignBackground,t=>{const o=i.value;o&&(o.uploadDesignBackground=t)}),n.watch(()=>e.isEdit,t=>{const o=i.value;o&&t!==void 0&&(o.isEdit=t)}),n.watch(()=>e.showHelp,t=>{const o=i.value;o&&t!==void 0&&(o.showHelp=t)}),n.watch(()=>e.showPreview,t=>{const o=i.value;o&&t!==void 0&&(o.showPreview=t)}),n.watch(()=>e.showSave,t=>{const o=i.value;o&&t!==void 0&&(o.showSave=t)}),n.watch(()=>e.theme,t=>{const o=i.value;o&&t!==void 0&&(o.theme=t)}),n.watch(()=>e.themeConfig,t=>{const o=i.value;o&&t!==void 0&&(o.themeConfig=t)}),v({getTemplateJson(){const t=i.value?.getTemplateJson();return t?JSON.parse(t):void 0},validateTemplate(){return i.value?.validateTemplate()??[]},getGeometryWarnings(){return i.value?.getGeometryWarnings()??[]}}),()=>n.h("print-designer",{ref:i})}}),_=M,I="worm-print-canvas-vue3-preview",F=`
|
|
2
2
|
.pcv3-preview.print-html-preview {
|
|
3
3
|
width: 100%;
|
|
4
4
|
height: 100%;
|
|
@@ -79,4 +79,4 @@
|
|
|
79
79
|
color: #b88230;
|
|
80
80
|
font-size: 11px;
|
|
81
81
|
}
|
|
82
|
-
`;function J(){if(typeof document>"u"||document.getElementById(I))return;const e=document.createElement("style");e.id=I,e.textContent=F,document.head.appendChild(e)}const q=n.defineComponent({name:"PrintHtmlPreview",props:{templateJson:{type:Object,default:void 0},printData:{type:[Object,Array],default:void 0},baseUrl:{type:String,default:void 0},fontBaseUrl:{type:String,default:void 0},renderers:{type:Object,default:void 0}},emits:{rendered:(e,l)=>typeof e=="number"&&typeof l=="number",error:e=>typeof e=="string"},setup(e,{emit:l,expose:v}){const
|
|
82
|
+
`;function J(){if(typeof document>"u"||document.getElementById(I))return;const e=document.createElement("style");e.id=I,e.textContent=F,document.head.appendChild(e)}const q=n.defineComponent({name:"PrintHtmlPreview",props:{templateJson:{type:Object,default:void 0},printData:{type:[Object,Array],default:void 0},baseUrl:{type:String,default:void 0},fontBaseUrl:{type:String,default:void 0},renderers:{type:Object,default:void 0}},emits:{rendered:(e,l)=>typeof e=="number"&&typeof l=="number",error:e=>typeof e=="string"},setup(e,{emit:l,expose:v}){const i=n.ref(),u=n.ref(),a=n.ref(!1),f=n.ref(""),y=n.ref([]);let O=0;const t=n.computed(()=>g.resolvePrinterDpi(e.templateJson)),o=n.ref(0),m=n.computed(()=>g.zoomPresets(t.value,o.value,g.paperWidthPx(e.templateJson))),p=n.ref(g.defaultZoomKey(t.value)),z=n.computed(()=>g.zoomValueOf(m.value,p.value)),T=n.computed(()=>g.viewZoomHint(t.value,p.value));function x(){o.value=u.value?.clientWidth??0}function R(){p.value=g.resolveZoomKey(m.value,p.value,t.value)}function D(){g.applyPreviewViewZoom(i.value?.contentWindow?.document,z.value)}function k(){x(),D()}async function r(){if(!e.templateJson){f.value="",a.value=!1;return}const s=++O;a.value=!0,f.value="",y.value=[];try{const{html:d,pageCount:b,copies:c,pageLayouts:P}=await S.renderHtmlPages(e.templateJson,e.printData,e.baseUrl,S.browserCodeRenderer,{fontBaseUrl:e.fontBaseUrl,renderers:e.renderers});if(s!==O)return;y.value=C.collectLayoutWarnings(P??[]);const h=i.value?.contentWindow?.document;h&&(h.open(),h.write(d),h.close()),x(),R(),D(),l("rendered",b,c)}catch(d){if(s!==O)return;f.value=d instanceof Error?d.message:"未知错误",l("error",f.value)}finally{s===O&&(a.value=!1)}}function w(){const s=i.value?.contentWindow;s&&(s.focus(),s.print())}function E(s){m.value.some(d=>d.key===s)&&(p.value=s)}return n.watch(()=>[e.templateJson,e.printData,e.baseUrl,e.fontBaseUrl,e.renderers],()=>{r()},{deep:!0}),n.watch(z,()=>D()),n.onMounted(()=>{J(),x(),R(),window.addEventListener("resize",k),r()}),n.onBeforeUnmount(()=>{O++,window.removeEventListener("resize",k)}),v({print:w,rerender:r,setViewZoom:E,zoomKey:p,presets:m,viewHint:T}),()=>{const s=a.value||!!f.value,d=[];if(f.value?d.push(n.h("div",{key:"error",class:"print-html-preview-error"},[n.h("span",null,`预览渲染失败:${f.value}`)])):a.value&&d.push(n.h("div",{key:"loading",class:"print-html-preview-loading"},"预览渲染中…")),d.push(n.h("iframe",{key:"iframe",ref:i,class:"print-html-preview-iframe",title:"打印预览",style:{display:s?"none":""}})),y.value.length&&!s&&d.push(n.h("div",{key:"warn",class:"print-html-preview-warn",role:"status"},[n.h("span",null,`出纸提示:${y.value.join(";")}`)])),e.templateJson&&!s){const b=m.value.map(c=>n.h("button",{key:c.key,type:"button",class:{"print-html-preview-zoom-btn":!0,active:c.key===p.value},title:c.tip,onClick:()=>{p.value=c.key}},c.label));T.value&&b.push(n.h("span",{class:"print-html-preview-zoom-hint"},T.value)),b.push(n.h("span",{class:"print-html-preview-zoom-note"},"仅屏幕缩放,打印不受影响")),d.push(n.h("div",{key:"zoom",class:"print-html-preview-zoom"},b))}return n.h("div",{ref:u,class:"print-html-preview pcv3-preview"},d)}}}),V=q;function Z(e){return`tb-more-slot-${e}`}const B=j.TOOLBAR_OVERFLOW_KEY,A=2,K=74;function L(){const e=n.shallowRef(null),l=new Map,v=n.reactive(new Map),i=new Map;let u=0;const a=n.ref(new Set),f=n.ref(!1),y=n.computed(()=>[...v.values()].sort((r,w)=>r.order-w.order)),O=n.computed(()=>a.value.size>0);function t(){for(const[r,w]of l){const E=w.offsetWidth;E>0&&i.set(r,E)}}function o(r){const w=getComputedStyle(r),E=Number.parseFloat(w.gap)||A,s=Number.parseFloat(w.paddingLeft)||0,d=Number.parseFloat(w.paddingRight)||0;let b=0;for(const c of Array.from(r.children)){if(c.hasAttribute("data-overflow-more")||c.hasAttribute("data-overflow-spacer"))continue;const P=Math.max(c.offsetWidth,c.scrollWidth);P<=0||(b+=P+E)}return{available:r.clientWidth-s-d,natural:b}}function m(){const r=e.value;if(!r)return;const{available:w,natural:E}=o(r),s=a.value.size>0;s||(u=E,t());const d=y.value.map(h=>({id:h.id,order:h.order,width:i.get(h.id)??0})),b=d.reduce((h,W)=>h-W.width-A,u),c=g.resolveToolbarOverflow({available:w,pinned:b,moreTriggerWidth:K,gap:A,units:d});c.movedIds.length===a.value.size&&c.movedIds.every(h=>a.value.has(h))||(a.value=new Set(c.movedIds)),f.value=c.overflowRemains,s&&a.value.size===0&&n.nextTick(m)}let p=null;function z(r){r!==e.value&&(p?.disconnect(),e.value=r,r&&typeof ResizeObserver<"u"&&(p=new ResizeObserver(()=>m()),p.observe(r)),n.nextTick(m))}function T(r,w){v.set(r.id,r),l.set(r.id,w),n.nextTick(m)}function x(r){l.delete(r),v.delete(r),i.delete(r),n.nextTick(m)}const R=document.createElement("div");function D(r){return a.value.has(r)}function k(r){return a.value,e.value?.querySelector(`[data-overflow-slot="${r}"]`)??R}return n.onUnmounted(()=>p?.disconnect()),{attachRoot:z,registerUnit:T,unregisterUnit:x,refresh:m,movedIds:a,overflowRemains:f,hasMoved:O,chain:y,moved:D,slotEl:k}}function G(){const e=L();return n.provide(B,e),e}function N(){return n.inject(B,null)}function $(){const e=n.ref(new Set),l=document.createElement("div");return{attachRoot:()=>{},registerUnit:()=>{},unregisterUnit:()=>{},refresh:()=>{},movedIds:e,overflowRemains:n.ref(!1),hasMoved:n.computed(()=>!1),chain:n.computed(()=>[]),moved:()=>!1,slotEl:()=>l}}function Y(e){return{mounted(l,v){l.dataset.unit=v.value.id,e.registerUnit(v.value,l)},unmounted(l,v){e.unregisterUnit(v.value.id)}}}Object.defineProperty(exports,"createDefaultTemplate",{enumerable:!0,get:()=>U.createDefaultTemplate});Object.defineProperty(exports,"toRuntimePool",{enumerable:!0,get:()=>U.toRuntimePool});Object.defineProperty(exports,"browserCodeRenderer",{enumerable:!0,get:()=>S.browserCodeRenderer});Object.defineProperty(exports,"renderHtmlPages",{enumerable:!0,get:()=>S.renderHtmlPages});Object.defineProperty(exports,"DEFAULT_DEMO_DATA",{enumerable:!0,get:()=>g.DEFAULT_DEMO_DATA});Object.defineProperty(exports,"getDemoData",{enumerable:!0,get:()=>g.getDemoData});exports.PrintDesigner=_;exports.PrintHtmlPreview=V;exports.TOOLBAR_OVERFLOW=B;exports.createOverflowUnitDirective=Y;exports.createToolbarOverflow=L;exports.emptyToolbarOverflow=$;exports.moreSlotId=Z;exports.provideToolbarOverflow=G;exports.useToolbarOverflow=N;
|
package/dist/vue3/index.d.ts
CHANGED
package/dist/vue3/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { defineComponent as B, ref as y, onMounted as
|
|
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
|
|
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
|
|
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
|
|
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(),
|
|
79
|
-
t.template = re(
|
|
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 && (
|
|
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
|
|
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
|
-
}),
|
|
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
|
-
}),
|
|
95
|
+
}), c(() => e.initialTemplate, () => {
|
|
92
96
|
const t = i.value;
|
|
93
|
-
t &&
|
|
94
|
-
}),
|
|
97
|
+
t && f(t);
|
|
98
|
+
}), c(() => e.initialElements, () => {
|
|
95
99
|
const t = i.value;
|
|
96
|
-
t &&
|
|
97
|
-
}),
|
|
100
|
+
t && f(t);
|
|
101
|
+
}), c(() => e.fields, (t) => {
|
|
98
102
|
const n = i.value;
|
|
99
103
|
n && (n.fields = t ?? []);
|
|
100
|
-
}),
|
|
104
|
+
}), c(() => e.fonts, (t) => {
|
|
101
105
|
const n = i.value;
|
|
102
106
|
n && (n.fonts = t);
|
|
103
|
-
}),
|
|
107
|
+
}), c(() => e.designData, (t) => {
|
|
104
108
|
const n = i.value;
|
|
105
109
|
n && (n.designData = t);
|
|
106
|
-
}),
|
|
110
|
+
}), c(() => e.uploadImage, (t) => {
|
|
107
111
|
const n = i.value;
|
|
108
112
|
n && (n.uploadImage = t);
|
|
109
|
-
}),
|
|
113
|
+
}), c(() => e.uploadDesignBackground, (t) => {
|
|
110
114
|
const n = i.value;
|
|
111
115
|
n && (n.uploadDesignBackground = t);
|
|
112
|
-
}),
|
|
116
|
+
}), c(() => e.isEdit, (t) => {
|
|
113
117
|
const n = i.value;
|
|
114
118
|
n && t !== void 0 && (n.isEdit = t);
|
|
115
|
-
}),
|
|
119
|
+
}), c(() => e.showHelp, (t) => {
|
|
116
120
|
const n = i.value;
|
|
117
121
|
n && t !== void 0 && (n.showHelp = t);
|
|
118
|
-
}),
|
|
122
|
+
}), c(() => e.showPreview, (t) => {
|
|
119
123
|
const n = i.value;
|
|
120
124
|
n && t !== void 0 && (n.showPreview = t);
|
|
121
|
-
}),
|
|
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),
|
|
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),
|
|
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(
|
|
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(
|
|
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
|
-
|
|
281
|
+
f.value = "", r.value = !1;
|
|
272
282
|
return;
|
|
273
283
|
}
|
|
274
284
|
const l = ++E;
|
|
275
|
-
r.value = !0,
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
310
|
+
m.value.some((u) => u.key === l) && (p.value = l);
|
|
301
311
|
}
|
|
302
|
-
return
|
|
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
|
-
),
|
|
318
|
+
), c(k, () => P()), C(() => {
|
|
309
319
|
se(), O(), S(), window.addEventListener("resize", I), o();
|
|
310
|
-
}),
|
|
320
|
+
}), L(() => {
|
|
311
321
|
E++, window.removeEventListener("resize", I);
|
|
312
|
-
}), v({ print:
|
|
313
|
-
const l = r.value || !!
|
|
314
|
-
if (
|
|
315
|
-
g("span", null, `预览渲染失败:${
|
|
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 =
|
|
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
|
|
359
|
+
const H = oe, W = 2, de = 74;
|
|
350
360
|
function ve() {
|
|
351
|
-
const e =
|
|
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()),
|
|
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,
|
|
356
|
-
const z =
|
|
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
|
|
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
|
|
380
|
+
function m() {
|
|
371
381
|
const o = e.value;
|
|
372
382
|
if (!o) return;
|
|
373
|
-
const { available:
|
|
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,
|
|
380
|
-
available:
|
|
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)),
|
|
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(() =>
|
|
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,
|
|
393
|
-
v.set(o.id, o), a.set(o.id,
|
|
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(
|
|
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:
|
|
419
|
+
refresh: m,
|
|
410
420
|
movedIds: r,
|
|
411
|
-
overflowRemains:
|
|
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(
|
|
430
|
+
return j(H, e), e;
|
|
421
431
|
}
|
|
422
432
|
function Ee() {
|
|
423
|
-
return V(
|
|
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
|
-
|
|
468
|
+
H as TOOLBAR_OVERFLOW,
|
|
459
469
|
Se as browserCodeRenderer,
|
|
460
470
|
Pe as createDefaultTemplate,
|
|
461
471
|
De as createOverflowUnitDirective,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@worm-print-platform/canvas",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
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.
|
|
58
|
-
"@worm-print-platform/plugin-kit": "^1.
|
|
57
|
+
"@worm-print-platform/core": "^1.6.0",
|
|
58
|
+
"@worm-print-platform/plugin-kit": "^1.6.0",
|
|
59
59
|
"dompurify": "^3.4.12",
|
|
60
60
|
"jsbarcode": "^3.12.3",
|
|
61
61
|
"qrcode": "^1.5.4"
|