@worm-vue3-print/core 1.2.0 → 1.2.2
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 +97 -0
- package/dist/browser/index.cjs +1920 -0
- package/dist/browser/index.d.cts +23 -0
- package/dist/browser/index.d.ts +23 -0
- package/dist/browser/index.js +170 -0
- package/dist/chunk-HLCZHPUF.js +31 -0
- package/dist/chunk-JZIVNXZ7.js +1777 -0
- package/dist/designer/index.cjs +2419 -0
- package/dist/designer/index.d.cts +652 -0
- package/dist/designer/index.d.ts +652 -0
- package/dist/designer/index.js +1620 -0
- package/dist/index.d.cts +4 -184
- package/dist/index.d.ts +4 -184
- package/dist/index.js +36 -1764
- package/dist/types-BGBAbQD5.d.cts +184 -0
- package/dist/types-BGBAbQD5.d.ts +184 -0
- package/package.json +21 -4
package/README.md
CHANGED
|
@@ -14,11 +14,26 @@ print-core/
|
|
|
14
14
|
css-builder.ts # mm 单位布局 → CSS
|
|
15
15
|
expression-eval.ts # 表达式安全求值(safelist)
|
|
16
16
|
types.ts # 模板/请求类型(JSON 可序列化)
|
|
17
|
+
designer/ # 框架无关的设计器内核(无 Vue/React 依赖)
|
|
18
|
+
types.ts # 设计器完整模板模型(TemplateData/RuntimeElement 等)
|
|
19
|
+
utils/ # 元素工厂/表格矩阵/单位换算/迁移/吸附参考线等通用工具
|
|
20
|
+
interactions/ # 对齐/分组/缩放/键盘/吸附等纯交互逻辑
|
|
21
|
+
browser/ # 渲染管线浏览器适配器(iframe 两遍分页、jsbarcode/qrcode)
|
|
17
22
|
```
|
|
18
23
|
|
|
19
24
|
`core` 无 Vue、无宿主依赖,可在 Node 服务端(`@worm-vue3-print/render`)与浏览器端(`@worm-vue3-print/canvas`)共用,
|
|
20
25
|
保证「浏览器预览」与「服务端 PDF」结果一致。
|
|
21
26
|
|
|
27
|
+
### 子路径导出
|
|
28
|
+
|
|
29
|
+
| 子路径 | 内容 | 运行环境 |
|
|
30
|
+
| --- | --- | --- |
|
|
31
|
+
| `@worm-vue3-print/core` | 表达式引擎 + 同构渲染管线(零运行时依赖) | Node / 浏览器 |
|
|
32
|
+
| `@worm-vue3-print/core/designer` | 设计器模型类型、通用工具、纯交互逻辑 | 任意(交互中的 DOM 事件绑定需浏览器) |
|
|
33
|
+
| `@worm-vue3-print/core/browser` | 浏览器分页渲染(`renderHtmlPages`)、条形码/二维码渲染器 | 仅浏览器 |
|
|
34
|
+
|
|
35
|
+
> 注意:`/designer` 子路径的 `TemplateData` 等类型是设计器完整模型,与主入口渲染管线的简化同名类型有意分离,因此不从主入口转出。
|
|
36
|
+
|
|
22
37
|
## 使用
|
|
23
38
|
|
|
24
39
|
```ts
|
|
@@ -29,6 +44,88 @@ const pages = paginate(bound, measured, options)
|
|
|
29
44
|
const html = generateHtml(pages)
|
|
30
45
|
```
|
|
31
46
|
|
|
47
|
+
## 在 Vue 3 项目中使用(与 `@worm-vue3-print/canvas` 配合)
|
|
48
|
+
|
|
49
|
+
`core` 的同构渲染管线由 `@worm-vue3-print/canvas` 的 `PrintHtmlPreview` 组件内部调用,
|
|
50
|
+
浏览器端接入无需直接调用 `core` API。以下配置与仓库 `demo/App.vue` 保持一致:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { PrintDesigner, PrintHtmlPreview, createDefaultTemplate } from '@worm-vue3-print/canvas'
|
|
54
|
+
import type { PrintBusinessField, TemplateData } from '@worm-vue3-print/canvas'
|
|
55
|
+
// 设计器内部控件基于原生样式,需全局引入一次
|
|
56
|
+
import '@worm-vue3-print/canvas/native-controls.css'
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
```vue
|
|
60
|
+
<template>
|
|
61
|
+
<PrintDesigner
|
|
62
|
+
ref="designerRef"
|
|
63
|
+
:initial-template="templateData"
|
|
64
|
+
:fields="fields"
|
|
65
|
+
:is-edit="true"
|
|
66
|
+
:load-default-template="loadDefaultTemplate"
|
|
67
|
+
:show-help="true"
|
|
68
|
+
@preview="onPreview"
|
|
69
|
+
@save="onSave"
|
|
70
|
+
/>
|
|
71
|
+
|
|
72
|
+
<!-- 浏览器端免保存预览:直接使用当前画布 JSON + 业务数据 -->
|
|
73
|
+
<Teleport to="body">
|
|
74
|
+
<PrintHtmlPreview
|
|
75
|
+
v-if="previewVisible"
|
|
76
|
+
ref="htmlPreviewRef"
|
|
77
|
+
:template-json="previewTemplateJson"
|
|
78
|
+
:print-data="printData"
|
|
79
|
+
@rendered="(n) => previewPages = n"
|
|
80
|
+
/>
|
|
81
|
+
</Teleport>
|
|
82
|
+
</template>
|
|
83
|
+
|
|
84
|
+
<script setup lang="ts">
|
|
85
|
+
import { ref } from 'vue'
|
|
86
|
+
|
|
87
|
+
const templateData = ref<TemplateData>(/* 初始模板 TemplateData */)
|
|
88
|
+
const fields = ref<PrintBusinessField[]>(/* 业务字段 PrintBusinessField[] */)
|
|
89
|
+
const designerRef = ref<InstanceType<typeof PrintDesigner> | null>(null)
|
|
90
|
+
const previewTemplateJson = ref<Record<string, any> | null>(null)
|
|
91
|
+
|
|
92
|
+
function onPreview() {
|
|
93
|
+
const json = designerRef.value?.getTemplateJson?.()
|
|
94
|
+
if (!json) return
|
|
95
|
+
previewTemplateJson.value = json
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function onSave(json: string) {
|
|
99
|
+
// 宿主持久化模板 JSON
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function loadDefaultTemplate() {
|
|
103
|
+
return createDefaultTemplate()
|
|
104
|
+
}
|
|
105
|
+
</script>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
关键 props / 事件 / 方法:
|
|
109
|
+
|
|
110
|
+
- `initial-template`:初始模板 `TemplateData`;`fields`:业务字段 `PrintBusinessField[]`;`is-edit`:是否编辑态。
|
|
111
|
+
- `load-default-template()`:可选。「加载默认布局」回调(支持异步,返回 null/undefined 视为无
|
|
112
|
+
默认布局);未注入时工具栏不展示该按钮。
|
|
113
|
+
- `show-help`:帮助入口开关,默认开启,传入 `false` 可关闭帮助按钮与帮助弹框。
|
|
114
|
+
- `getTemplateJson()`:通过 `ref` 获取当前画布模板 JSON,用于预览 / 保存。
|
|
115
|
+
- `@preview` / `@save`:预览与保存事件,具体业务(字段查询、持久化)由宿主实现。
|
|
116
|
+
- 需要服务端 / Node 输出时,直接调用 `core` 的 `bindData` / `paginate` / `generateHtml` 即可。
|
|
117
|
+
|
|
118
|
+
## 相关链接
|
|
119
|
+
|
|
120
|
+
- Gitee:https://gitee.com/liulong_oschina/worm-vue3-print
|
|
121
|
+
- GitHub:https://github.com/worm-longliu/worm-vue3-print
|
|
122
|
+
|
|
123
|
+
抖音码:
|
|
124
|
+
|
|
125
|
+
<p align="center">
|
|
126
|
+
<img src="../../douyin.png" width="180" alt="抖音码" />
|
|
127
|
+
</p>
|
|
128
|
+
|
|
32
129
|
## 开发
|
|
33
130
|
|
|
34
131
|
```bash
|