@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.
- package/README.md +20 -4
- package/dist/browser-bundle.d.ts +1 -1
- package/dist/canvas.css +2 -2
- package/dist/canvas.js +71 -36
- 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 +1 -1
- package/dist/core/store.d.ts +1 -1
- package/dist/host-contract.d.ts +19 -7
- package/dist/index.cjs +45 -10
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1151 -958
- package/dist/print-designer.d.ts +27 -4
- 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 +1 -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 -1
- 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 +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 +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 +1 -1
- package/dist/shell/toolbar.d.ts +1 -1
- 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/print-designer.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @worm-print-platform/canvas v1.5.
|
|
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
|
|
6
6
|
*/
|
|
7
7
|
import type { UploadDesignBackgroundFn, UploadImageFn } from '@worm-print-platform/core/designer';
|
|
8
8
|
import type { PrintFontDeclaration } from '@worm-print-platform/core';
|
|
9
|
-
import type { PrintDesignerHostContract } from './host-contract';
|
|
9
|
+
import type { PrintDesignerHostContract, PrintDesignerThemeConfig, PrintDesignerThemeMode } from './host-contract';
|
|
10
10
|
/**
|
|
11
11
|
* 插件 UI 的设计态示例数据统一成「数组信封」(data[0] 即数据根对象)。
|
|
12
12
|
* 宿主可传单个业务对象、对象数组或 JSON 字符串;非法/缺省值返回 undefined,
|
|
@@ -62,6 +62,14 @@ export declare class PrintDesignerElement extends HTMLElement {
|
|
|
62
62
|
private raf;
|
|
63
63
|
private lastSelKey;
|
|
64
64
|
private chromeKey;
|
|
65
|
+
/** 主题:预设 + 参数覆盖。参数 > 显式预设 > 系统偏好 > CSS 令牌 */
|
|
66
|
+
private _theme;
|
|
67
|
+
private _themeConfig?;
|
|
68
|
+
private systemDark;
|
|
69
|
+
private themeMedia;
|
|
70
|
+
private readonly onThemeMediaChange;
|
|
71
|
+
/** applyTheme 写入的行内变量键:精确清理,不碰宿主/插件写的其他行内样式 */
|
|
72
|
+
private appliedThemeTokens;
|
|
65
73
|
/** 宿主注入:图片上传,返回可访问 URL 或 data URL(对应 Vue 3 轨 的 UPLOAD_IMAGE_KEY) */
|
|
66
74
|
uploadImage?: UploadImageFn;
|
|
67
75
|
/** 宿主注入:设计背景图上传,返回可直接 <img src> 的完整路径(对应 Vue 3 轨 的 UPLOAD_DESIGN_BACKGROUND_KEY) */
|
|
@@ -92,18 +100,33 @@ export declare class PrintDesignerElement extends HTMLElement {
|
|
|
92
100
|
set showPreview(v: boolean);
|
|
93
101
|
/** 工具栏「保存」按钮显隐;默认显示,隐藏只影响按钮出图,save() 与 save 事件不受影响 */
|
|
94
102
|
set showSave(v: boolean);
|
|
103
|
+
/** 主题预设:auto(默认)跟随系统 prefers-color-scheme,light/dark 强制 */
|
|
104
|
+
set theme(v: PrintDesignerThemeMode | undefined);
|
|
105
|
+
get theme(): PrintDesignerThemeMode;
|
|
106
|
+
/** 主题色值覆盖:传参优先于预设、系统与 CSS 令牌;只作用于外壳,画布纸张与元素不受影响 */
|
|
107
|
+
set themeConfig(v: PrintDesignerThemeConfig | string | undefined);
|
|
108
|
+
get themeConfig(): PrintDesignerThemeConfig | undefined;
|
|
95
109
|
/**
|
|
96
110
|
* 宿主契约版本(机器可读);宿主可在挂载前用 `PrintDesignerElement.contractVersion`
|
|
97
111
|
* 判断是否需要降级或提示升级,避免把版本号埋在文档里。
|
|
98
112
|
*/
|
|
99
|
-
static readonly contractVersion = "1.
|
|
113
|
+
static readonly contractVersion = "1.2.0";
|
|
100
114
|
/** 返回完整契约快照(attributes / properties / methods / 事件 / parts / 主题令牌) */
|
|
101
115
|
static getHostContract(): PrintDesignerHostContract;
|
|
102
116
|
/** 实例侧同款读取入口,便于 `document.querySelector('print-designer').getHostContract()` */
|
|
103
117
|
getHostContract(): PrintDesignerHostContract;
|
|
104
|
-
static get observedAttributes(): ("template" | "fields" | "name" | "fonts" | "design-data")[];
|
|
118
|
+
static get observedAttributes(): ("template" | "fields" | "name" | "fonts" | "design-data" | "theme" | "theme-config")[];
|
|
105
119
|
attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
|
|
106
120
|
connectedCallback(): void;
|
|
121
|
+
/** 仅 auto 模式需要监听系统深浅色;matchMedia 缺失的环境(部分测试宿主)保持浅色 */
|
|
122
|
+
private attachThemeMedia;
|
|
123
|
+
private detachThemeMedia;
|
|
124
|
+
/**
|
|
125
|
+
* 主题落到内部 .designer-container 的行内 CSS 变量:行内声明优先级高于
|
|
126
|
+
* Shadow DOM 内 `.designer-container{--pd-*:浅色}` 规则,是唯一切实生效的通道。
|
|
127
|
+
* paint() 只 clear(shell) 清子节点,容器常驻,写入的变量不会被重绘冲掉。
|
|
128
|
+
*/
|
|
129
|
+
private applyTheme;
|
|
107
130
|
/** 面板折叠态:与 Vue 3 轨的 useStudioChrome 共用 localStorage 键,同一浏览器里两边偏好互通 */
|
|
108
131
|
private readChrome;
|
|
109
132
|
private persistChrome;
|
package/dist/shell/binding.d.ts
CHANGED
package/dist/shell/canvas.d.ts
CHANGED
package/dist/shell/code.d.ts
CHANGED
package/dist/shell/controls.d.ts
CHANGED
package/dist/shell/elements.d.ts
CHANGED
package/dist/shell/panels.d.ts
CHANGED
package/dist/shell/ruler.d.ts
CHANGED
package/dist/shell/table.d.ts
CHANGED
package/dist/shell/toolbar.d.ts
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @worm-print-platform/canvas v1.5.3
|
|
3
|
+
* Copyright (c) 2026 worm <liu_long_qqcom@qq.com>
|
|
4
|
+
* SPDX-FileCopyrightText: 2026 worm <liu_long_qqcom@qq.com>
|
|
5
|
+
* SPDX-License-Identifier: MIT
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* 内置主题预设的色值表,与 core/styles/theme.css 的浅色令牌一一对应。
|
|
9
|
+
*
|
|
10
|
+
* 只服务于 <print-designer> 的 theme 参数通道:applyTheme() 把这些值写成
|
|
11
|
+
* 内部 .designer-container 的行内 CSS 变量,优先级高于 Shadow DOM 内的令牌声明。
|
|
12
|
+
*
|
|
13
|
+
* 画布保持现状:纸张、画布背景、标尺、手柄与纸张阴影的令牌一律不进暗色表,
|
|
14
|
+
* 换肤只影响设计器外壳,预览所见即所得不失真。宿主如需调整画布外围背景,
|
|
15
|
+
* 可用 theme-config 显式覆盖 --pd-canvas-bg。
|
|
16
|
+
*/
|
|
17
|
+
import type { PrintDesignerThemeToken } from './host-contract';
|
|
18
|
+
/** 暗色模式下保持浅色原值的令牌(画布区 / 非颜色项),刻意不写入行内覆盖 */
|
|
19
|
+
export declare const CANVAS_UNCHANGED_TOKENS: readonly ["--pd-canvas-bg", "--pd-paper", "--pd-handle", "--pd-ruler", "--pd-ruler-bg", "--pd-ruler-cursor", "--pd-shadow-paper", "--pd-radius"];
|
|
20
|
+
/** 暗色外壳预设:47 项 = 55 项完整清单 - 8 项画布/非颜色令牌 */
|
|
21
|
+
export declare const DARK_THEME_TOKENS: Partial<Record<PrintDesignerThemeToken, string>>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @worm-print-platform/canvas v1.5.3
|
|
3
|
+
* Copyright (c) 2026 worm <liu_long_qqcom@qq.com>
|
|
4
|
+
* SPDX-FileCopyrightText: 2026 worm <liu_long_qqcom@qq.com>
|
|
5
|
+
* SPDX-License-Identifier: MIT
|
|
6
|
+
*/
|
|
7
|
+
/** 设计器(@worm-print-platform/canvas)当前版本,用于状态栏等 UI 展示 */
|
|
8
|
+
export declare const CANVAS_VERSION = "1.5.3";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @worm-print-platform/canvas v1.5.
|
|
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
|
|
@@ -8,6 +8,7 @@ import type { PropType } from 'vue';
|
|
|
8
8
|
import type { PrintFontDeclaration } from '@worm-print-platform/core';
|
|
9
9
|
import type { MultiPageTemplateData, PrintBusinessField, RuntimeElement, TemplateData, UploadDesignBackgroundFn, UploadImageFn } from '@worm-print-platform/core/designer';
|
|
10
10
|
import type { PrintDesignerElement } from '../print-designer';
|
|
11
|
+
import type { PrintDesignerThemeConfig, PrintDesignerThemeMode } from '../host-contract';
|
|
11
12
|
/** 与 Vue 3 轨的 expose 同形:getTemplateJson 返回对象而非 JSON 字符串 */
|
|
12
13
|
export interface PrintDesignerExpose {
|
|
13
14
|
getTemplateJson(): TemplateData | MultiPageTemplateData | undefined;
|
|
@@ -66,6 +67,16 @@ declare const component: import("vue").DefineComponent<import("vue").ExtractProp
|
|
|
66
67
|
type: PropType<Record<string, unknown> | readonly Record<string, unknown>[]>;
|
|
67
68
|
default: undefined;
|
|
68
69
|
};
|
|
70
|
+
/** 主题预设:auto(默认)跟随系统 prefers-color-scheme,light/dark 强制 */
|
|
71
|
+
theme: {
|
|
72
|
+
type: PropType<PrintDesignerThemeMode>;
|
|
73
|
+
default: undefined;
|
|
74
|
+
};
|
|
75
|
+
/** 主题色值覆盖:传参优先于预设、系统与 CSS 令牌;只影响外壳,画布纸张不受影响 */
|
|
76
|
+
themeConfig: {
|
|
77
|
+
type: PropType<PrintDesignerThemeConfig>;
|
|
78
|
+
default: undefined;
|
|
79
|
+
};
|
|
69
80
|
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
70
81
|
[key: string]: any;
|
|
71
82
|
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
@@ -123,6 +134,16 @@ declare const component: import("vue").DefineComponent<import("vue").ExtractProp
|
|
|
123
134
|
type: PropType<Record<string, unknown> | readonly Record<string, unknown>[]>;
|
|
124
135
|
default: undefined;
|
|
125
136
|
};
|
|
137
|
+
/** 主题预设:auto(默认)跟随系统 prefers-color-scheme,light/dark 强制 */
|
|
138
|
+
theme: {
|
|
139
|
+
type: PropType<PrintDesignerThemeMode>;
|
|
140
|
+
default: undefined;
|
|
141
|
+
};
|
|
142
|
+
/** 主题色值覆盖:传参优先于预设、系统与 CSS 令牌;只影响外壳,画布纸张不受影响 */
|
|
143
|
+
themeConfig: {
|
|
144
|
+
type: PropType<PrintDesignerThemeConfig>;
|
|
145
|
+
default: undefined;
|
|
146
|
+
};
|
|
126
147
|
}>> & Readonly<{
|
|
127
148
|
onSave?: ((json: string) => any) | undefined;
|
|
128
149
|
onPreview?: (() => any) | undefined;
|
|
@@ -130,10 +151,12 @@ declare const component: import("vue").DefineComponent<import("vue").ExtractProp
|
|
|
130
151
|
fields: PrintBusinessField[];
|
|
131
152
|
fonts: readonly PrintFontDeclaration[];
|
|
132
153
|
designData: Record<string, unknown> | readonly Record<string, unknown>[];
|
|
154
|
+
theme: PrintDesignerThemeMode;
|
|
133
155
|
isEdit: boolean;
|
|
134
156
|
showHelp: boolean;
|
|
135
157
|
showPreview: boolean;
|
|
136
158
|
showSave: boolean;
|
|
159
|
+
themeConfig: PrintDesignerThemeConfig;
|
|
137
160
|
uploadImage: UploadImageFn;
|
|
138
161
|
uploadDesignBackground: UploadDesignBackgroundFn;
|
|
139
162
|
initialTemplate: TemplateData | MultiPageTemplateData;
|
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