@worm-print-platform/canvas 1.6.0 → 1.6.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.
- package/README.md +4 -2
- package/dist/browser-bundle.d.ts +1 -1
- package/dist/canvas.css +5 -0
- package/dist/canvas.js +1162 -120
- 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 +1 -1
- package/dist/core/icons.d.ts +1 -1
- package/dist/core/plugin.d.ts +4 -3
- package/dist/core/store.d.ts +3 -2
- package/dist/host-contract.d.ts +10 -3
- package/dist/index.cjs +1031 -13
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6403 -5185
- package/dist/print-designer.d.ts +18 -3
- package/dist/shell/binding.d.ts +1 -1
- package/dist/shell/canvas.d.ts +1 -1
- package/dist/shell/code.d.ts +1 -1
- package/dist/shell/color-picker.d.ts +1 -1
- package/dist/shell/controls.d.ts +16 -1
- package/dist/shell/crop-anchor.d.ts +1 -1
- package/dist/shell/elements.d.ts +1 -1
- package/dist/shell/expression-editor.d.ts +1 -1
- package/dist/shell/flow-list.d.ts +1 -3
- package/dist/shell/font-select.d.ts +1 -1
- package/dist/shell/format-bar.d.ts +1 -1
- package/dist/shell/help-content/{advanced-settings.d.ts → en-US/advanced-settings.d.ts} +1 -1
- package/dist/shell/help-content/{changelog.d.ts → en-US/changelog.d.ts} +1 -1
- package/dist/shell/help-content/{faq.d.ts → en-US/faq.d.ts} +1 -1
- package/dist/shell/help-content/{features.d.ts → en-US/features.d.ts} +1 -1
- package/dist/shell/help-content/{getting-started.d.ts → en-US/getting-started.d.ts} +1 -1
- package/dist/shell/help-content/{shortcuts.d.ts → en-US/shortcuts.d.ts} +1 -1
- package/dist/shell/help-content/index.d.ts +4 -1
- package/dist/shell/help-content/th-TH/advanced-settings.d.ts +12 -0
- package/dist/shell/help-content/th-TH/changelog.d.ts +12 -0
- package/dist/shell/help-content/th-TH/faq.d.ts +12 -0
- package/dist/shell/help-content/th-TH/features.d.ts +12 -0
- package/dist/shell/help-content/th-TH/getting-started.d.ts +12 -0
- package/dist/shell/help-content/th-TH/shortcuts.d.ts +12 -0
- package/dist/shell/help-content/zh-CN/advanced-settings.d.ts +12 -0
- package/dist/shell/help-content/zh-CN/changelog.d.ts +12 -0
- package/dist/shell/help-content/zh-CN/faq.d.ts +12 -0
- package/dist/shell/help-content/zh-CN/features.d.ts +12 -0
- package/dist/shell/help-content/zh-CN/getting-started.d.ts +12 -0
- package/dist/shell/help-content/zh-CN/shortcuts.d.ts +12 -0
- package/dist/shell/help-modal.d.ts +6 -1
- package/dist/shell/page-extras.d.ts +1 -1
- package/dist/shell/panels.d.ts +1 -1
- 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 +3 -3
- package/dist/shell/toolbar.d.ts +1 -1
- package/dist/shell/watermark.d.ts +1 -1
- package/dist/test-setup.d.ts +7 -0
- package/dist/theme-tokens.d.ts +1 -1
- package/dist/version.d.ts +2 -2
- 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 +85 -75
- package/dist/vue3/previewStyle.d.ts +1 -1
- package/dist/vue3/toolbarOverflow.d.ts +1 -1
- package/package.json +3 -3
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"),C=require("@worm-print-platform/core"),
|
|
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"),k=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}})),o=e.pages;return Array.isArray(o)?{...e,pages:o.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},lang:{type:String,default:void 0},messages:{type:Object,default:void 0}},emits:{preview:()=>!0,save:e=>typeof e=="string"},setup(e,{emit:l,expose:v}){const o=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 i=t.getTemplateJson(),m=JSON.parse(i);t.template=H(m,e.initialElements)}function y(){const t=o.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),e.lang!==void 0&&(t.lang=e.lang),e.messages!==void 0&&(t.messages=e.messages))}return n.onMounted(()=>{const t=o.value;t&&(u=i=>l("save",i.detail),a=()=>l("preview"),t.addEventListener("save",u),t.addEventListener("preview",a),y())}),n.onBeforeUnmount(()=>{const t=o.value;u&&t?.removeEventListener("save",u),a&&t?.removeEventListener("preview",a),u=null,a=null}),n.watch(()=>e.initialTemplate,()=>{const t=o.value;t&&f(t)}),n.watch(()=>e.initialElements,()=>{const t=o.value;t&&f(t)}),n.watch(()=>e.fields,t=>{const i=o.value;i&&(i.fields=t??[])}),n.watch(()=>e.fonts,t=>{const i=o.value;i&&(i.fonts=t)}),n.watch(()=>e.designData,t=>{const i=o.value;i&&(i.designData=t)}),n.watch(()=>e.uploadImage,t=>{const i=o.value;i&&(i.uploadImage=t)}),n.watch(()=>e.uploadDesignBackground,t=>{const i=o.value;i&&(i.uploadDesignBackground=t)}),n.watch(()=>e.isEdit,t=>{const i=o.value;i&&t!==void 0&&(i.isEdit=t)}),n.watch(()=>e.showHelp,t=>{const i=o.value;i&&t!==void 0&&(i.showHelp=t)}),n.watch(()=>e.showPreview,t=>{const i=o.value;i&&t!==void 0&&(i.showPreview=t)}),n.watch(()=>e.showSave,t=>{const i=o.value;i&&t!==void 0&&(i.showSave=t)}),n.watch(()=>e.theme,t=>{const i=o.value;i&&t!==void 0&&(i.theme=t)}),n.watch(()=>e.themeConfig,t=>{const i=o.value;i&&t!==void 0&&(i.themeConfig=t)}),n.watch(()=>e.lang,t=>{const i=o.value;i&&t!==void 0&&(i.lang=t)}),n.watch(()=>e.messages,t=>{const i=o.value;i&&t!==void 0&&(i.messages=t)}),v({getTemplateJson(){const t=o.value?.getTemplateJson();return t?JSON.parse(t):void 0},validateTemplate(){return o.value?.validateTemplate()??[]},getGeometryWarnings(){return o.value?.getGeometryWarnings()??[]}}),()=>n.h("print-designer",{ref:o})}}),_=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 o=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)),i=n.ref(0),m=n.computed(()=>g.zoomPresets(t.value,i.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(){i.value=u.value?.clientWidth??0}function R(){p.value=g.resolveZoomKey(m.value,p.value,t.value)}function D(){g.applyPreviewViewZoom(o.value?.contentWindow?.document,z.value)}function S(){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 k.renderHtmlPages(e.templateJson,e.printData,e.baseUrl,k.browserCodeRenderer,{fontBaseUrl:e.fontBaseUrl,renderers:e.renderers});if(s!==O)return;y.value=C.collectLayoutWarnings(P??[]);const h=o.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=o.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",S),r()}),n.onBeforeUnmount(()=>{O++,window.removeEventListener("resize",S)}),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:o,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),o=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&&o.set(r,E)}}function i(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}=i(r),s=a.value.size>0;s||(u=E,t());const d=y.value.map(h=>({id:h.id,order:h.order,width:o.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),o.delete(r),n.nextTick(m)}const R=document.createElement("div");function D(r){return a.value.has(r)}function S(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:S}}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:()=>k.browserCodeRenderer});Object.defineProperty(exports,"renderHtmlPages",{enumerable:!0,get:()=>k.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,24 +1,24 @@
|
|
|
1
|
-
import { defineComponent as B, ref as y, onMounted as C, onBeforeUnmount as L, watch as
|
|
1
|
+
import { defineComponent as B, ref as y, onMounted as C, onBeforeUnmount as L, watch as v, h as g, computed as D, shallowRef as M, reactive as j, onUnmounted as F, provide as _, 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
|
-
import { browserCodeRenderer as
|
|
6
|
+
import { browserCodeRenderer as ke, renderHtmlPages as Ie } from "@worm-print-platform/core/browser";
|
|
7
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
9
|
import { TOOLBAR_OVERFLOW_KEY as oe } from "@worm-print-platform/plugin-kit";
|
|
10
|
-
function
|
|
11
|
-
const
|
|
10
|
+
function ae(e, r) {
|
|
11
|
+
const c = r.map((s) => ({
|
|
12
12
|
...s,
|
|
13
13
|
options: { ...s.options },
|
|
14
14
|
printElementType: { ...s.printElementType }
|
|
15
15
|
})), i = e.pages;
|
|
16
16
|
return Array.isArray(i) ? {
|
|
17
17
|
...e,
|
|
18
|
-
pages: i.map((s,
|
|
19
|
-
} : { ...e, elements:
|
|
18
|
+
pages: i.map((s, a) => a === 0 ? { ...s, elements: c } : s)
|
|
19
|
+
} : { ...e, elements: c };
|
|
20
20
|
}
|
|
21
|
-
const
|
|
21
|
+
const re = B({
|
|
22
22
|
name: "PrintDesigner",
|
|
23
23
|
props: {
|
|
24
24
|
initialTemplate: {
|
|
@@ -63,15 +63,19 @@ const ae = B({
|
|
|
63
63
|
/** 主题预设:auto(默认)跟随系统 prefers-color-scheme,light/dark 强制 */
|
|
64
64
|
theme: { type: String, default: void 0 },
|
|
65
65
|
/** 主题色值覆盖:传参优先于预设、系统与 CSS 令牌;只影响外壳,画布纸张不受影响 */
|
|
66
|
-
themeConfig: { type: Object, default: void 0 }
|
|
66
|
+
themeConfig: { type: Object, default: void 0 },
|
|
67
|
+
/** 界面语言(BCP47,如 en-US);未传时跟随全局 locale */
|
|
68
|
+
lang: { type: String, default: void 0 },
|
|
69
|
+
/** 自定义语言包(对象注入),覆盖内置与插件译文 */
|
|
70
|
+
messages: { type: Object, default: void 0 }
|
|
67
71
|
},
|
|
68
72
|
emits: {
|
|
69
73
|
preview: () => !0,
|
|
70
74
|
save: (e) => typeof e == "string"
|
|
71
75
|
},
|
|
72
|
-
setup(e, { emit:
|
|
76
|
+
setup(e, { emit: r, expose: c }) {
|
|
73
77
|
const i = y(null);
|
|
74
|
-
let s = null,
|
|
78
|
+
let s = null, a = null;
|
|
75
79
|
typeof customElements < "u" && Z();
|
|
76
80
|
function f(t) {
|
|
77
81
|
if (e.initialTemplate !== void 0) {
|
|
@@ -80,58 +84,64 @@ const ae = B({
|
|
|
80
84
|
}
|
|
81
85
|
if (e.initialElements === void 0) return;
|
|
82
86
|
const n = t.getTemplateJson(), m = JSON.parse(n);
|
|
83
|
-
t.template =
|
|
87
|
+
t.template = ae(m, e.initialElements);
|
|
84
88
|
}
|
|
85
89
|
function x() {
|
|
86
90
|
const t = i.value;
|
|
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));
|
|
91
|
+
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), e.lang !== void 0 && (t.lang = e.lang), e.messages !== void 0 && (t.messages = e.messages));
|
|
88
92
|
}
|
|
89
93
|
return C(() => {
|
|
90
94
|
const t = i.value;
|
|
91
|
-
t && (s = (n) =>
|
|
95
|
+
t && (s = (n) => r("save", n.detail), a = () => r("preview"), t.addEventListener("save", s), t.addEventListener("preview", a), x());
|
|
92
96
|
}), L(() => {
|
|
93
97
|
const t = i.value;
|
|
94
|
-
s && t?.removeEventListener("save", s),
|
|
95
|
-
}),
|
|
98
|
+
s && t?.removeEventListener("save", s), a && t?.removeEventListener("preview", a), s = null, a = null;
|
|
99
|
+
}), v(() => e.initialTemplate, () => {
|
|
96
100
|
const t = i.value;
|
|
97
101
|
t && f(t);
|
|
98
|
-
}),
|
|
102
|
+
}), v(() => e.initialElements, () => {
|
|
99
103
|
const t = i.value;
|
|
100
104
|
t && f(t);
|
|
101
|
-
}),
|
|
105
|
+
}), v(() => e.fields, (t) => {
|
|
102
106
|
const n = i.value;
|
|
103
107
|
n && (n.fields = t ?? []);
|
|
104
|
-
}),
|
|
108
|
+
}), v(() => e.fonts, (t) => {
|
|
105
109
|
const n = i.value;
|
|
106
110
|
n && (n.fonts = t);
|
|
107
|
-
}),
|
|
111
|
+
}), v(() => e.designData, (t) => {
|
|
108
112
|
const n = i.value;
|
|
109
113
|
n && (n.designData = t);
|
|
110
|
-
}),
|
|
114
|
+
}), v(() => e.uploadImage, (t) => {
|
|
111
115
|
const n = i.value;
|
|
112
116
|
n && (n.uploadImage = t);
|
|
113
|
-
}),
|
|
117
|
+
}), v(() => e.uploadDesignBackground, (t) => {
|
|
114
118
|
const n = i.value;
|
|
115
119
|
n && (n.uploadDesignBackground = t);
|
|
116
|
-
}),
|
|
120
|
+
}), v(() => e.isEdit, (t) => {
|
|
117
121
|
const n = i.value;
|
|
118
122
|
n && t !== void 0 && (n.isEdit = t);
|
|
119
|
-
}),
|
|
123
|
+
}), v(() => e.showHelp, (t) => {
|
|
120
124
|
const n = i.value;
|
|
121
125
|
n && t !== void 0 && (n.showHelp = t);
|
|
122
|
-
}),
|
|
126
|
+
}), v(() => e.showPreview, (t) => {
|
|
123
127
|
const n = i.value;
|
|
124
128
|
n && t !== void 0 && (n.showPreview = t);
|
|
125
|
-
}),
|
|
129
|
+
}), v(() => e.showSave, (t) => {
|
|
126
130
|
const n = i.value;
|
|
127
131
|
n && t !== void 0 && (n.showSave = t);
|
|
128
|
-
}),
|
|
132
|
+
}), v(() => e.theme, (t) => {
|
|
129
133
|
const n = i.value;
|
|
130
134
|
n && t !== void 0 && (n.theme = t);
|
|
131
|
-
}),
|
|
135
|
+
}), v(() => e.themeConfig, (t) => {
|
|
132
136
|
const n = i.value;
|
|
133
137
|
n && t !== void 0 && (n.themeConfig = t);
|
|
134
|
-
}), v({
|
|
138
|
+
}), v(() => e.lang, (t) => {
|
|
139
|
+
const n = i.value;
|
|
140
|
+
n && t !== void 0 && (n.lang = t);
|
|
141
|
+
}), v(() => e.messages, (t) => {
|
|
142
|
+
const n = i.value;
|
|
143
|
+
n && t !== void 0 && (n.messages = t);
|
|
144
|
+
}), c({
|
|
135
145
|
getTemplateJson() {
|
|
136
146
|
const t = i.value?.getTemplateJson();
|
|
137
147
|
return t ? JSON.parse(t) : void 0;
|
|
@@ -144,7 +154,7 @@ const ae = B({
|
|
|
144
154
|
}
|
|
145
155
|
}), () => g("print-designer", { ref: i });
|
|
146
156
|
}
|
|
147
|
-
}), ge =
|
|
157
|
+
}), ge = re, A = "worm-print-canvas-vue3-preview", le = `
|
|
148
158
|
.pcv3-preview.print-html-preview {
|
|
149
159
|
width: 100%;
|
|
150
160
|
height: 100%;
|
|
@@ -255,34 +265,34 @@ const ue = B({
|
|
|
255
265
|
}
|
|
256
266
|
},
|
|
257
267
|
emits: {
|
|
258
|
-
rendered: (e,
|
|
268
|
+
rendered: (e, r) => typeof e == "number" && typeof r == "number",
|
|
259
269
|
error: (e) => typeof e == "string"
|
|
260
270
|
},
|
|
261
|
-
setup(e, { emit:
|
|
262
|
-
const i = y(), s = y(),
|
|
271
|
+
setup(e, { emit: r, expose: c }) {
|
|
272
|
+
const i = y(), s = y(), a = y(!1), f = y(""), x = y([]);
|
|
263
273
|
let E = 0;
|
|
264
274
|
const t = D(() => $(e.templateJson)), n = y(0), m = D(
|
|
265
275
|
() => q(t.value, n.value, Y(e.templateJson))
|
|
266
|
-
), p = y(Q(t.value)),
|
|
267
|
-
function
|
|
276
|
+
), p = y(Q(t.value)), S = D(() => X(m.value, p.value)), O = D(() => ee(t.value, p.value));
|
|
277
|
+
function T() {
|
|
268
278
|
n.value = s.value?.clientWidth ?? 0;
|
|
269
279
|
}
|
|
270
|
-
function
|
|
280
|
+
function k() {
|
|
271
281
|
p.value = ne(m.value, p.value, t.value);
|
|
272
282
|
}
|
|
273
283
|
function P() {
|
|
274
|
-
te(i.value?.contentWindow?.document,
|
|
284
|
+
te(i.value?.contentWindow?.document, S.value);
|
|
275
285
|
}
|
|
276
286
|
function I() {
|
|
277
|
-
|
|
287
|
+
T(), P();
|
|
278
288
|
}
|
|
279
289
|
async function o() {
|
|
280
290
|
if (!e.templateJson) {
|
|
281
|
-
f.value = "",
|
|
291
|
+
f.value = "", a.value = !1;
|
|
282
292
|
return;
|
|
283
293
|
}
|
|
284
294
|
const l = ++E;
|
|
285
|
-
|
|
295
|
+
a.value = !0, f.value = "", x.value = [];
|
|
286
296
|
try {
|
|
287
297
|
const { html: u, pageCount: b, copies: d, pageLayouts: R } = await K(
|
|
288
298
|
e.templateJson,
|
|
@@ -294,12 +304,12 @@ const ue = B({
|
|
|
294
304
|
if (l !== E) return;
|
|
295
305
|
x.value = G(R ?? []);
|
|
296
306
|
const h = i.value?.contentWindow?.document;
|
|
297
|
-
h && (h.open(), h.write(u), h.close()),
|
|
307
|
+
h && (h.open(), h.write(u), h.close()), T(), k(), P(), r("rendered", b, d);
|
|
298
308
|
} catch (u) {
|
|
299
309
|
if (l !== E) return;
|
|
300
|
-
f.value = u instanceof Error ? u.message : "未知错误",
|
|
310
|
+
f.value = u instanceof Error ? u.message : "未知错误", r("error", f.value);
|
|
301
311
|
} finally {
|
|
302
|
-
l === E && (
|
|
312
|
+
l === E && (a.value = !1);
|
|
303
313
|
}
|
|
304
314
|
}
|
|
305
315
|
function w() {
|
|
@@ -309,21 +319,21 @@ const ue = B({
|
|
|
309
319
|
function z(l) {
|
|
310
320
|
m.value.some((u) => u.key === l) && (p.value = l);
|
|
311
321
|
}
|
|
312
|
-
return
|
|
322
|
+
return v(
|
|
313
323
|
() => [e.templateJson, e.printData, e.baseUrl, e.fontBaseUrl, e.renderers],
|
|
314
324
|
() => {
|
|
315
325
|
o();
|
|
316
326
|
},
|
|
317
327
|
{ deep: !0 }
|
|
318
|
-
),
|
|
319
|
-
se(),
|
|
328
|
+
), v(S, () => P()), C(() => {
|
|
329
|
+
se(), T(), k(), window.addEventListener("resize", I), o();
|
|
320
330
|
}), L(() => {
|
|
321
331
|
E++, window.removeEventListener("resize", I);
|
|
322
|
-
}),
|
|
323
|
-
const l =
|
|
332
|
+
}), c({ print: w, rerender: o, setViewZoom: z, zoomKey: p, presets: m, viewHint: O }), () => {
|
|
333
|
+
const l = a.value || !!f.value, u = [];
|
|
324
334
|
if (f.value ? u.push(g("div", { key: "error", class: "print-html-preview-error" }, [
|
|
325
335
|
g("span", null, `预览渲染失败:${f.value}`)
|
|
326
|
-
])) :
|
|
336
|
+
])) : a.value && u.push(g("div", { key: "loading", class: "print-html-preview-loading" }, "预览渲染中…")), u.push(g("iframe", {
|
|
327
337
|
key: "iframe",
|
|
328
338
|
ref: i,
|
|
329
339
|
class: "print-html-preview-iframe",
|
|
@@ -344,7 +354,7 @@ const ue = B({
|
|
|
344
354
|
p.value = d.key;
|
|
345
355
|
}
|
|
346
356
|
}, d.label));
|
|
347
|
-
|
|
357
|
+
O.value && b.push(g("span", { class: "print-html-preview-zoom-hint" }, O.value)), b.push(g("span", { class: "print-html-preview-zoom-note" }, "仅屏幕缩放,打印不受影响")), u.push(g("div", { key: "zoom", class: "print-html-preview-zoom" }, b));
|
|
348
358
|
}
|
|
349
359
|
return g("div", {
|
|
350
360
|
ref: s,
|
|
@@ -358,11 +368,11 @@ function be(e) {
|
|
|
358
368
|
}
|
|
359
369
|
const H = oe, W = 2, de = 74;
|
|
360
370
|
function ve() {
|
|
361
|
-
const e = M(null),
|
|
371
|
+
const e = M(null), r = /* @__PURE__ */ new Map(), c = j(/* @__PURE__ */ new Map()), i = /* @__PURE__ */ new Map();
|
|
362
372
|
let s = 0;
|
|
363
|
-
const
|
|
373
|
+
const a = y(/* @__PURE__ */ new Set()), f = y(!1), x = D(() => [...c.values()].sort((o, w) => o.order - w.order)), E = D(() => a.value.size > 0);
|
|
364
374
|
function t() {
|
|
365
|
-
for (const [o, w] of
|
|
375
|
+
for (const [o, w] of r) {
|
|
366
376
|
const z = w.offsetWidth;
|
|
367
377
|
z > 0 && i.set(o, z);
|
|
368
378
|
}
|
|
@@ -380,7 +390,7 @@ function ve() {
|
|
|
380
390
|
function m() {
|
|
381
391
|
const o = e.value;
|
|
382
392
|
if (!o) return;
|
|
383
|
-
const { available: w, natural: z } = n(o), l =
|
|
393
|
+
const { available: w, natural: z } = n(o), l = a.value.size > 0;
|
|
384
394
|
l || (s = z, t());
|
|
385
395
|
const u = x.value.map((h) => ({
|
|
386
396
|
id: h.id,
|
|
@@ -393,31 +403,31 @@ function ve() {
|
|
|
393
403
|
gap: W,
|
|
394
404
|
units: u
|
|
395
405
|
});
|
|
396
|
-
d.movedIds.length ===
|
|
406
|
+
d.movedIds.length === a.value.size && d.movedIds.every((h) => a.value.has(h)) || (a.value = new Set(d.movedIds)), f.value = d.overflowRemains, l && a.value.size === 0 && U(m);
|
|
397
407
|
}
|
|
398
408
|
let p = null;
|
|
399
|
-
function
|
|
409
|
+
function S(o) {
|
|
400
410
|
o !== e.value && (p?.disconnect(), e.value = o, o && typeof ResizeObserver < "u" && (p = new ResizeObserver(() => m()), p.observe(o)), U(m));
|
|
401
411
|
}
|
|
402
|
-
function
|
|
403
|
-
|
|
412
|
+
function O(o, w) {
|
|
413
|
+
c.set(o.id, o), r.set(o.id, w), U(m);
|
|
404
414
|
}
|
|
405
|
-
function
|
|
406
|
-
|
|
415
|
+
function T(o) {
|
|
416
|
+
r.delete(o), c.delete(o), i.delete(o), U(m);
|
|
407
417
|
}
|
|
408
|
-
const
|
|
418
|
+
const k = document.createElement("div");
|
|
409
419
|
function P(o) {
|
|
410
|
-
return
|
|
420
|
+
return a.value.has(o);
|
|
411
421
|
}
|
|
412
422
|
function I(o) {
|
|
413
|
-
return
|
|
423
|
+
return a.value, e.value?.querySelector(`[data-overflow-slot="${o}"]`) ?? k;
|
|
414
424
|
}
|
|
415
|
-
return
|
|
416
|
-
attachRoot:
|
|
417
|
-
registerUnit:
|
|
418
|
-
unregisterUnit:
|
|
425
|
+
return F(() => p?.disconnect()), {
|
|
426
|
+
attachRoot: S,
|
|
427
|
+
registerUnit: O,
|
|
428
|
+
unregisterUnit: T,
|
|
419
429
|
refresh: m,
|
|
420
|
-
movedIds:
|
|
430
|
+
movedIds: a,
|
|
421
431
|
overflowRemains: f,
|
|
422
432
|
hasMoved: E,
|
|
423
433
|
chain: x,
|
|
@@ -427,13 +437,13 @@ function ve() {
|
|
|
427
437
|
}
|
|
428
438
|
function xe() {
|
|
429
439
|
const e = ve();
|
|
430
|
-
return
|
|
440
|
+
return _(H, e), e;
|
|
431
441
|
}
|
|
432
442
|
function Ee() {
|
|
433
443
|
return V(H, null);
|
|
434
444
|
}
|
|
435
445
|
function ze() {
|
|
436
|
-
const e = y(/* @__PURE__ */ new Set()),
|
|
446
|
+
const e = y(/* @__PURE__ */ new Set()), r = document.createElement("div");
|
|
437
447
|
return {
|
|
438
448
|
attachRoot: () => {
|
|
439
449
|
},
|
|
@@ -448,16 +458,16 @@ function ze() {
|
|
|
448
458
|
hasMoved: D(() => !1),
|
|
449
459
|
chain: D(() => []),
|
|
450
460
|
moved: () => !1,
|
|
451
|
-
slotEl: () =>
|
|
461
|
+
slotEl: () => r
|
|
452
462
|
};
|
|
453
463
|
}
|
|
454
464
|
function De(e) {
|
|
455
465
|
return {
|
|
456
|
-
mounted(
|
|
457
|
-
|
|
466
|
+
mounted(r, c) {
|
|
467
|
+
r.dataset.unit = c.value.id, e.registerUnit(c.value, r);
|
|
458
468
|
},
|
|
459
|
-
unmounted(
|
|
460
|
-
e.unregisterUnit(
|
|
469
|
+
unmounted(r, c) {
|
|
470
|
+
e.unregisterUnit(c.value.id);
|
|
461
471
|
}
|
|
462
472
|
};
|
|
463
473
|
}
|
|
@@ -466,7 +476,7 @@ export {
|
|
|
466
476
|
ge as PrintDesigner,
|
|
467
477
|
ye as PrintHtmlPreview,
|
|
468
478
|
H as TOOLBAR_OVERFLOW,
|
|
469
|
-
|
|
479
|
+
ke as browserCodeRenderer,
|
|
470
480
|
Pe as createDefaultTemplate,
|
|
471
481
|
De as createOverflowUnitDirective,
|
|
472
482
|
ve as createToolbarOverflow,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@worm-print-platform/canvas",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"pretest": "npm run typecheck"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@worm-print-platform/core": "^1.6.
|
|
58
|
-
"@worm-print-platform/plugin-kit": "^1.6.
|
|
57
|
+
"@worm-print-platform/core": "^1.6.1",
|
|
58
|
+
"@worm-print-platform/plugin-kit": "^1.6.1",
|
|
59
59
|
"dompurify": "^3.4.12",
|
|
60
60
|
"jsbarcode": "^3.12.3",
|
|
61
61
|
"qrcode": "^1.5.4"
|