vue-print-designer 0.9.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/LICENSE ADDED
@@ -0,0 +1,187 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+
135
+ 6. Trademarks. This License does not grant permission to use the trade
136
+ names, trademarks, service marks, or product names of the Licensor,
137
+ except as required for reasonable and customary use in describing the
138
+ origin of the Work and reproducing the content of the NOTICE file.
139
+
140
+ 7. Disclaimer of Warranty. Unless required by applicable law or
141
+ agreed to in writing, Licensor provides the Work (and each
142
+ Contributor provides its Contributions) on an "AS IS" BASIS,
143
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
144
+ implied, including, without limitation, any warranties or conditions
145
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
146
+ PARTICULAR PURPOSE. You are solely responsible for determining the
147
+ appropriateness of using or redistributing the Work and assume any
148
+ risks associated with Your exercise of permissions under this License.
149
+
150
+ 8. Limitation of Liability. In no event and under no legal theory,
151
+ whether in tort (including negligence), contract, or otherwise,
152
+ unless required by applicable law (such as deliberate and grossly
153
+ negligent acts) or agreed to in writing, shall any Contributor be
154
+ liable to You for damages, including any direct, indirect, special,
155
+ incidental, or consequential damages of any character arising as a
156
+ result of this License or out of the use or inability to use the
157
+ Work (including but not limited to damages for loss of goodwill,
158
+ work stoppage, computer failure or malfunction, or any and all
159
+ other commercial damages or losses), even if such Contributor
160
+ has been advised of the possibility of such damages.
161
+
162
+ 9. Accepting Warranty or Additional Liability. While redistributing
163
+ the Work or Derivative Works thereof, You may choose to offer,
164
+ and charge a fee for, acceptance of support, warranty, indemnity,
165
+ or other liability obligations and/or rights consistent with this
166
+ License. However, in accepting such obligations, You may act only
167
+ on Your own behalf and on Your sole responsibility, not on behalf
168
+ of any other Contributor, and only if You agree to indemnify,
169
+ defend, and hold each Contributor harmless for any liability
170
+ incurred by, or claims asserted against, such Contributor by reason
171
+ of your accepting any such warranty or additional liability.
172
+
173
+ END OF TERMS AND CONDITIONS
174
+
175
+ Copyright 2026 Xiang DeZhi 上海未来申创智能科技有限公司
176
+
177
+ Licensed under the Apache License, Version 2.0 (the "License");
178
+ you may not use this file except in compliance with the License.
179
+ You may obtain a copy of the License at
180
+
181
+ http://www.apache.org/licenses/LICENSE-2.0
182
+
183
+ Unless required by applicable law or agreed to in writing, software
184
+ distributed under the License is distributed on an "AS IS" BASIS,
185
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
186
+ See the License for the specific language governing permissions and
187
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,168 @@
1
+ <p align="center">
2
+ <img src="./src/assets/logo.png" alt="Vue Print Designer" width="96" height="96" />
3
+ </p>
4
+
5
+ <h1 align="center">Vue Print Designer</h1>
6
+
7
+ <p align="center">
8
+ 中文 | <a href="./README_EN.md">English</a>
9
+ </p>
10
+
11
+ Vue Print Designer 是一款可视化打印设计器,面向业务表单、标签、票据、快递单等场景,支持模板化、变量化,并提供静默打印与云打印能力,同时兼容多种导出/打印方式。
12
+
13
+ ## 我们解决了什么问题
14
+
15
+ - 设计与打印链路割裂,模板无法复用,改一个字段要改一堆代码
16
+ - 复杂分页(尤其是表格)需要大量手写逻辑
17
+ - 业务系统与打印插件的集成成本高、接口不统一、跨框架兼容性差
18
+
19
+ ## 为什么比同类更好用
20
+
21
+ 很多同类插件要么强耦合框架、要么只提供“导出图片/打印”而缺少工程化能力。我们的优势是:
22
+
23
+ - **完整设计器**:元素、属性、分页、预览、模板管理一体化
24
+ - **可扩展**:模板与自定义元素可以走本地存储,也能接入你的 API
25
+ - **跨框架**:Web Components 方式适配 Vue/React/Angular/纯 HTML
26
+ - **工程化**:导出 PDF/图片/Blob、打印参数、静默打印、连接配置都可控
27
+ - **可维护**:代码结构清晰,便于二次开发与业务定制
28
+
29
+ ## 功能亮点
30
+
31
+ - 拖拽式页面编辑,支持文本、图片、条码、二维码、表格、形状
32
+ - 表格自动分页(支持表头/表尾重复)
33
+ - 多页面布局、网格/标尺、缩放与对齐工具
34
+ - 导出 PDF/图片/Blob,支持拼接/分片
35
+ - 打印参数配置:打印机、份数、页范围、单双面、纸张等
36
+ - **静默打印**:支持本地客户端直打,无需人工确认
37
+ - **云打印**:支持远程客户端接入与云端下发打印任务
38
+
39
+ ## 界面预览
40
+
41
+ | | |
42
+ | --- | --- |
43
+ | **设计器主界面与画布视图**<br>![设计器主界面](docs/images/1.png) | **打印预览**<br>![打印预览](docs/images/2.png) |
44
+ | **打印参数配置**<br>![打印参数](docs/images/3.png) | **系统设置与偏好**<br>![系统设置](docs/images/4.png) |
45
+ | **快捷键说明**<br>![快捷键](docs/images/5.png) | **高级表格编辑**<br>![高级表格](docs/images/6.png) |
46
+
47
+ ## 引入方式一:下载源码自行改造与集成 API
48
+
49
+ 适合有深度定制需求的团队。
50
+
51
+ ```bash
52
+ npm install
53
+ npm run dev
54
+ ```
55
+
56
+ 建议接入点:
57
+
58
+ - 模板 CRUD:`useTemplateStore`(可替换为接口读写)
59
+ - 自定义元素 CRUD:`useDesignerStore` 中的 `customElements`
60
+ - 变量与模板数据:组件实例方法 `setVariables` / `loadTemplateData`
61
+
62
+ 自定义元素扩展请看: [docs/zh/guide/custom-element.md](docs/zh/guide/custom-element.md)
63
+
64
+ 构建:
65
+
66
+ ```bash
67
+ npm run build
68
+ ```
69
+
70
+ ## 引入方式二:npm 组件(Web Components)
71
+
72
+ 适合任何技术栈(Vue/React/Angular/原生)。
73
+
74
+ 说明:Web Components 方式**支持 Vue 2**(作为自定义元素使用),无需 Vue 2 组件适配。
75
+
76
+ 详细参数、CRUD 与 JSON 示例请看: [docs/zh/guide/web-components-guide.md](docs/zh/guide/web-components-guide.md)
77
+
78
+ ```bash
79
+ npm install @your-scope/print-designer
80
+ ```
81
+
82
+ ### 1) 使用组件(Vue 3 / Vite)
83
+
84
+ 在入口文件中引入:
85
+
86
+ ```ts
87
+ // main.ts
88
+ import '@your-scope/print-designer';
89
+ import '@your-scope/print-designer/style.css';
90
+ ```
91
+
92
+ 然后在页面里直接使用自定义元素:
93
+
94
+ ```vue
95
+ <template>
96
+ <print-designer id="designer"></print-designer>
97
+ </template>
98
+ ```
99
+
100
+ ### 2) Vue 3 选项式 API:初始化与调用分离
101
+
102
+ **设计器页(初始化与编辑)**
103
+
104
+ ```vue
105
+ <script lang="ts">
106
+ export default {
107
+ mounted() {
108
+ const el = this.$refs.designerRef as any;
109
+ // 初始化品牌与主题
110
+ el.setBranding({ title: '业务打印设计器', showLogo: true });
111
+ el.setTheme('light');
112
+ // 初始化模板或变量
113
+ el.loadTemplateData(/* 从你的 API 获取的数据 */);
114
+ el.setVariables({ orderNo: 'A001' }, { merge: true });
115
+ }
116
+ };
117
+ </script>
118
+
119
+ <template>
120
+ <print-designer ref="designerRef"></print-designer>
121
+ </template>
122
+ ```
123
+
124
+ **业务页面(随处调用打印/导出)**
125
+
126
+ ```ts
127
+ // 任何页面中只要能拿到元素实例即可
128
+ const el = document.querySelector('print-designer') as any;
129
+
130
+ // 打印
131
+ await el.print({ mode: 'browser' });
132
+
133
+ // 导出 PDF / 图片 / Blob
134
+ await el.export({ type: 'pdf', filename: 'order-20240223.pdf' });
135
+ const pdfBlob = await el.export({ type: 'pdfBlob' });
136
+ ```
137
+
138
+ ### 3) 事件回调
139
+
140
+ ```ts
141
+ el.addEventListener('ready', () => {});
142
+ el.addEventListener('printed', (e) => {});
143
+ el.addEventListener('exported', (e) => {
144
+ const blob = e.detail?.blob;
145
+ });
146
+ el.addEventListener('error', (e) => {
147
+ console.error(e.detail?.scope, e.detail?.error);
148
+ });
149
+ ```
150
+
151
+ ## 构建 Web Components 包
152
+
153
+ ```bash
154
+ npm run build:wc
155
+ ```
156
+
157
+ 产物:
158
+
159
+ - `dist/print-designer.es.js`
160
+ - `dist/print-designer.umd.js`
161
+ - `dist/print-designer.css`
162
+ - `dist/web-component.d.ts`
163
+
164
+ ## License
165
+
166
+ Apache-2.0
167
+
168
+ 品牌与 Logo 使用请遵循 [TRADEMARKS.md](TRADEMARKS.md)。如需移除或替换品牌标识,请参考 [COMMERCIAL_LICENSE.md](COMMERCIAL_LICENSE.md)。