@worm-print-platform/canvas 0.0.0-stage → 1.5.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/LICENSE +21 -0
- package/README.md +180 -2
- package/dist/browser-bundle.d.ts +14 -0
- package/dist/canvas.css +526 -0
- package/dist/canvas.js +1166 -0
- package/dist/core/default-template.d.ts +9 -0
- package/dist/core/element-definitions.d.ts +74 -0
- package/dist/core/format.d.ts +122 -0
- package/dist/core/h.d.ts +22 -0
- package/dist/core/icons.d.ts +10 -0
- package/dist/core/plugin.d.ts +40 -0
- package/dist/core/store.d.ts +163 -0
- package/dist/host-contract.d.ts +124 -0
- package/dist/index.cjs +897 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +9222 -0
- package/dist/print-designer.d.ts +255 -0
- package/dist/shell/binding.d.ts +21 -0
- package/dist/shell/canvas.d.ts +61 -0
- package/dist/shell/code.d.ts +11 -0
- package/dist/shell/color-picker.d.ts +44 -0
- package/dist/shell/controls.d.ts +149 -0
- package/dist/shell/crop-anchor.d.ts +29 -0
- package/dist/shell/elements.d.ts +30 -0
- package/dist/shell/expression-editor.d.ts +33 -0
- package/dist/shell/flow-list.d.ts +12 -0
- package/dist/shell/font-select.d.ts +24 -0
- package/dist/shell/format-bar.d.ts +15 -0
- package/dist/shell/help-content/advanced-settings.d.ts +12 -0
- package/dist/shell/help-content/changelog.d.ts +12 -0
- package/dist/shell/help-content/faq.d.ts +12 -0
- package/dist/shell/help-content/features.d.ts +12 -0
- package/dist/shell/help-content/getting-started.d.ts +12 -0
- package/dist/shell/help-content/index.d.ts +13 -0
- package/dist/shell/help-content/shortcuts.d.ts +12 -0
- package/dist/shell/help-modal.d.ts +19 -0
- package/dist/shell/page-extras.d.ts +11 -0
- package/dist/shell/panels.d.ts +20 -0
- package/dist/shell/plugin-ui.d.ts +13 -0
- package/dist/shell/prop-group.d.ts +11 -0
- package/dist/shell/property-panel.d.ts +15 -0
- package/dist/shell/property-search.d.ts +32 -0
- package/dist/shell/ruler.d.ts +29 -0
- package/dist/shell/table-props.d.ts +17 -0
- package/dist/shell/table.d.ts +22 -0
- package/dist/shell/toolbar-overflow.d.ts +28 -0
- package/dist/shell/toolbar.d.ts +8 -0
- package/dist/shell/watermark.d.ts +11 -0
- package/dist/vue3/PrintDesigner.d.ts +149 -0
- package/dist/vue3/PrintHtmlPreview.d.ts +89 -0
- package/dist/vue3/index.cjs +82 -0
- package/dist/vue3/index.d.ts +29 -0
- package/dist/vue3/index.js +470 -0
- package/dist/vue3/previewStyle.d.ts +8 -0
- package/dist/vue3/toolbarOverflow.d.ts +51 -0
- package/package.json +78 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 worm <liu_long_qqcom@qq.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,181 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<strong>@worm-print-platform/canvas</strong><br>
|
|
3
|
+
<em>打印模板设计器权威实现(零框架 Custom Elements)</em>
|
|
4
|
+
</p>
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
<p align="center">
|
|
7
|
+
<img src="https://img.shields.io/badge/npm-v1.5.2-384BFF" alt="npm">
|
|
8
|
+
<img src="https://img.shields.io/badge/license-MIT-9A9A9A" alt="license">
|
|
9
|
+
<a href="/vue3">
|
|
10
|
+
<img src="https://img.shields.io/badge/vue-optional%20peer-42b883" alt="vue peer">
|
|
11
|
+
</a>
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
> monorepo 根:[worm-print-platform](https://github.com/worm-longliu/worm-print-platform) · 在线示例:[GitHub Pages](https://worm-longliu.github.io/worm-print-platform/) · 设计器能力验收清单:[PARITY.md](./PARITY.md)
|
|
15
|
+
|
|
16
|
+
打印模板可视化设计器的**权威实现**:原生 Custom Element + Shadow DOM,**不依赖 Vue / React 等任何框架运行时**。Vue 3 / Vue 2.7 / React / jQuery / 原生 JS 等任意宿主统一消费本包,样式 / 图标 / 主题令牌从 `@worm-print-platform/core/src/styles` 共享源派生,元素能力与定义走统一注册表(内置 11 类与第三方插件同权)。
|
|
17
|
+
|
|
18
|
+
- 运行时体积:`dist/index.js` 约 368 kB(gzip 106 kB),零框架依赖
|
|
19
|
+
- 浏览器直挂形态:`dist/canvas.js`(UMD,core + 码制库内联)+ `dist/canvas.css`
|
|
20
|
+
- `vue` 是可选 peer,不用 `/vue3` 时主入口零 Vue 依赖
|
|
21
|
+
|
|
22
|
+
## 安装
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# NPM 宿主
|
|
26
|
+
npm i @worm-print-platform/canvas @worm-print-platform/core
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
宿主框架依赖(主入口零框架运行时,宿主框架按需装):
|
|
30
|
+
|
|
31
|
+
| 宿主 | 安装 |
|
|
32
|
+
| --- | --- |
|
|
33
|
+
| Vue 3 | `npm i @worm-print-platform/canvas @worm-print-platform/core vue`(可选 `/vue3` 门面) |
|
|
34
|
+
| Vue 2.7 | `npm i @worm-print-platform/canvas @worm-print-platform/core vue@2.7` |
|
|
35
|
+
| React 18 | `npm i @worm-print-platform/canvas @worm-print-platform/core react react-dom` |
|
|
36
|
+
| jQuery / 无打包器 | 取 `dist/canvas.js` + `dist/canvas.css` 直挂(见下节) |
|
|
37
|
+
|
|
38
|
+
## 快速示例(原生 Custom Element)
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
import { registerAll } from '@worm-print-platform/canvas'
|
|
42
|
+
registerAll() // 注册 <print-designer>,不自动污染全局
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```html
|
|
46
|
+
<print-designer id="d" style="display:block;height:100%"></print-designer>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
const el = document.getElementById('d')
|
|
51
|
+
el.fields = [{ fieldKey: 'orderNo', fieldLabel: '单号' }]
|
|
52
|
+
el.template = templateJson
|
|
53
|
+
el.uploadImage = file => uploadToServer(file)
|
|
54
|
+
el.addEventListener('save', e => persist(e.detail))
|
|
55
|
+
el.addEventListener('preview', e => preview(e.detail))
|
|
56
|
+
el.getTemplateJson() // 返回 JSON 字符串
|
|
57
|
+
el.validateTemplate() // 拼版/多页配置校验,保存前必须调
|
|
58
|
+
el.loadTemplate(json)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
> 完整宿主接入代码见根 README「快速开始」章节与各框架文档:[docs/vue3.md](../../docs/vue3.md) · [docs/vue2.md](../../docs/vue2.md) · [docs/react.md](../../docs/react.md) · [docs/jquery.md](../../docs/jquery.md)。可运行工程:`demos/apps/{vue3,vue2,react,jquery}`。
|
|
62
|
+
|
|
63
|
+
## /vue3 兼容门面
|
|
64
|
+
|
|
65
|
+
Vue 3 宿主用 `/vue3` 门面即可沿用组件写法(props / 事件 / `ref`),底层复用零框架的本包,模板、事件回调、`ref` 方法调用一行不动。原本消费 `@worm-vue3-print/canvas` 的项目只需改依赖名:
|
|
66
|
+
|
|
67
|
+
```diff
|
|
68
|
+
- "@worm-vue3-print/canvas": "..."
|
|
69
|
+
+ "@worm-print-platform/canvas": "..."
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { PrintDesigner, PrintHtmlPreview } from '@worm-print-platform/canvas/vue3'
|
|
74
|
+
import type { TemplateData } from '@worm-print-platform/canvas/vue3'
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
门面负责的契约转换:
|
|
78
|
+
|
|
79
|
+
| Vue 组件侧 | Custom Element 侧 | 门面动作 |
|
|
80
|
+
| --- | --- | --- |
|
|
81
|
+
| `:initial-template` / `:fields` / 函数型 `:upload-image` | `el.template` / `el.fields` / `el.uploadImage` | 显式赋 property,绕开 attribute 字符串化 |
|
|
82
|
+
| `@save="onSave"` 首参是 JSON 字符串 | `CustomEvent('save')`,json 在 `detail` | 解 `detail` 再 emit |
|
|
83
|
+
| `ref.getTemplateJson()` 返回对象 | 返回 JSON 字符串 | `JSON.parse` |
|
|
84
|
+
|
|
85
|
+
详细迁移说明见 [docs/migration-worm-vue3-print.md](../../docs/migration-worm-vue3-print.md)。
|
|
86
|
+
|
|
87
|
+
## 浏览器直挂(jQuery / 无打包器宿主)
|
|
88
|
+
|
|
89
|
+
`vite.bundle.config.ts` 产出 UMD bundle(`@worm-print-platform/canvas/browser` 子路径):
|
|
90
|
+
|
|
91
|
+
```html
|
|
92
|
+
<link rel="stylesheet" href="/vendor/worm-print-canvas.css" />
|
|
93
|
+
<script src="/vendor/worm-print-canvas.js"></script>
|
|
94
|
+
<script>
|
|
95
|
+
WormPrintCanvas.registerAll()
|
|
96
|
+
const el = document.querySelector('print-designer')
|
|
97
|
+
el.fields = fields
|
|
98
|
+
el.template = templateJson
|
|
99
|
+
el.addEventListener('save', e => persist(e.detail))
|
|
100
|
+
</script>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
两个硬约束:自定义元素默认 `display:inline`,宿主必须给它块级宽高;`fields` 只有 setter,读回看 `el.store.fields`。
|
|
104
|
+
|
|
105
|
+
## 宿主契约
|
|
106
|
+
|
|
107
|
+
`<print-designer>` 的接入面是**版本化**的,定义在 `src/host-contract.ts`:
|
|
108
|
+
|
|
109
|
+
| 面 | 内容 |
|
|
110
|
+
| --- | --- |
|
|
111
|
+
| attribute | `template` · `fields` · `name` · `fonts` · `design-data`(另 `is-edit` / `show-help` / `show-preview` / `show-save` 四个布尔开关) |
|
|
112
|
+
| property | `template` · `fields` · `fonts` · `designData` · `isEdit` · `showHelp` · `showPreview` · `showSave` · `uploadImage` · `uploadDesignBackground` |
|
|
113
|
+
| 方法 | `getTemplateJson()` · `loadTemplate()` · `save()` · `validateTemplate()` · `getGeometryWarnings()` |
|
|
114
|
+
| 事件(`bubbles + composed`) | `save` / `preview` → 模板 JSON 字符串;`help` → 无载荷;`dblclick-element` → 元素 id;`dblclick-cell` → `{ elementId, r, c, cellId? }` |
|
|
115
|
+
|
|
116
|
+
自定义外观:外壳 8 个 `::part` 挂钩 + 52 个 `--pd-*` 主题令牌(权威定义在 `@worm-print-platform/core/styles/theme.css`)。契约版本遵守语义化,`src/__tests__/host-contract.spec.ts` 做漂移检测。
|
|
117
|
+
|
|
118
|
+
`showPreview` / `showSave` 控制工具栏「预览 / 保存」按钮显隐,默认显示,置 `false` 隐藏(Vue 3 门面同名 props)。隐藏只影响按钮出图:`save()` 方法、`save` / `preview` 事件照常可用,宿主可接管打印与预览业务逻辑。
|
|
119
|
+
|
|
120
|
+
## 统一元素注册表
|
|
121
|
+
|
|
122
|
+
内置元素与第三方插件**同权**:
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
import { registerElementDefinition, registerElementRenderer } from '@worm-print-platform/canvas'
|
|
126
|
+
|
|
127
|
+
const release = registerElementDefinition({
|
|
128
|
+
type: 'signature', label: '手写签名', icon: 'PenLine',
|
|
129
|
+
material: true, propertyGroup: 'general', dblEditableField: 'src', group: '扩展',
|
|
130
|
+
})
|
|
131
|
+
registerElementRenderer('signature', (el) => { /* 返回 HTML 字符串或 Node */ })
|
|
132
|
+
// release() 后回到内置基线
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## 自定义元素插件(图表等)
|
|
136
|
+
|
|
137
|
+
设计器只保留通用机制,具体元素由插件包提供:
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
import { registerAll } from '@worm-print-platform/canvas'
|
|
141
|
+
import '@worm-print-platform/echarts/ui' // 官方图表插件;换自定义插件同理
|
|
142
|
+
registerAll()
|
|
143
|
+
|
|
144
|
+
const el = document.querySelector('print-designer')
|
|
145
|
+
el.fields = [{ fieldKey: 'trend', fieldLabel: '趋势数据', fieldType: 'list' }]
|
|
146
|
+
el.designData = { trend: [{ name: '一月', value: 12 }, { name: '二月', value: 28 }] }
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
插件写自己的元素见 [`@worm-print-platform/plugin-kit`](../plugin-kit/README.md)。
|
|
150
|
+
|
|
151
|
+
## 两种接入形态的边界
|
|
152
|
+
|
|
153
|
+
| | `/vue3` 门面 | 本包主入口 |
|
|
154
|
+
| --- | --- | --- |
|
|
155
|
+
| 运行时 | Vue 3(可选 peer) | 无框架 |
|
|
156
|
+
| 宿主注入 | props / 事件 / `ref` | element property / attribute + CustomEvent |
|
|
157
|
+
| 样式 | 门面幂等注入,无需引样式文件 | 内置 Shadow DOM(`?inline`);light DOM 形态引 `@worm-print-platform/canvas/style.css` |
|
|
158
|
+
| 适用 | 沿用组件写法的 Vue 3 项目 | Vue 3 / Vue 2 / React / jQuery / 原生 |
|
|
159
|
+
|
|
160
|
+
## 样式生成
|
|
161
|
+
|
|
162
|
+
样式 / 图标 / 主题令牌的单一来源在 `core/src/styles`,本包从共享源派生(`gen-styles.mjs` 剥 `[data-v-*]` 后补主题令牌,`gen-icons.mjs` 读共享 `icon-manifest.json`);`gen-styles.mjs --check` 做漂移检测,不要手改派生产物。
|
|
163
|
+
|
|
164
|
+
## 开发
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
npm run build # styles + vite build + tsc
|
|
168
|
+
npm test # vitest(含 host-contract 漂移检测)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## 相关链接
|
|
172
|
+
|
|
173
|
+
- [根 README 架构分层](https://github.com/worm-longliu/worm-print-platform/blob/main/README.md#架构与分层)
|
|
174
|
+
- [设计器内核(core)](../core/README.md)
|
|
175
|
+
- [插件 UI 契约(plugin-kit)](../plugin-kit/README.md)
|
|
176
|
+
- [ECharts 图表插件](../echarts/README.md)
|
|
177
|
+
- [宿主契约源码](src/host-contract.ts) · [验收清单](PARITY.md)
|
|
178
|
+
|
|
179
|
+
## License
|
|
180
|
+
|
|
181
|
+
[MIT](../../LICENSE)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @worm-print-platform/canvas v1.5.2
|
|
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
|
+
import { getPaperDimensions, isContinuousPaperSize, getByPath } from '@worm-print-platform/core';
|
|
8
|
+
import { applyPreviewViewZoom, defaultZoomKey, paperWidthPx, resolvePrinterDpi, resolveToolbarOverflow, resolveZoomKey, viewZoomHint, zoomPresets, zoomValueOf } from '@worm-print-platform/core/designer';
|
|
9
|
+
import { renderHtmlPages, browserCodeRenderer } from '@worm-print-platform/core/browser';
|
|
10
|
+
import { PrintClient, WormPrintError } from '@worm-print-platform/core/client';
|
|
11
|
+
export * from './index';
|
|
12
|
+
export { renderHtmlPages, browserCodeRenderer, PrintClient, WormPrintError };
|
|
13
|
+
export { getPaperDimensions, isContinuousPaperSize, getByPath };
|
|
14
|
+
export { applyPreviewViewZoom, defaultZoomKey, paperWidthPx, resolvePrinterDpi, resolveToolbarOverflow, resolveZoomKey, viewZoomHint, zoomPresets, zoomValueOf, };
|