@worm-vue3-print/common 0.0.0-stage → 1.3.7-beta.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.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +99 -2
  3. package/dist/browser-bundle.d.ts +12 -0
  4. package/dist/common.css +462 -0
  5. package/dist/common.js +910 -0
  6. package/dist/core/default-template.d.ts +9 -0
  7. package/dist/core/font-catalog.d.ts +30 -0
  8. package/dist/core/format.d.ts +102 -0
  9. package/dist/core/h.d.ts +22 -0
  10. package/dist/core/icons.d.ts +10 -0
  11. package/dist/core/store.d.ts +163 -0
  12. package/dist/index.cjs +657 -0
  13. package/dist/index.d.ts +13 -0
  14. package/dist/index.js +7058 -0
  15. package/dist/print-designer.d.ts +182 -0
  16. package/dist/shell/binding.d.ts +21 -0
  17. package/dist/shell/canvas.d.ts +59 -0
  18. package/dist/shell/code.d.ts +11 -0
  19. package/dist/shell/color-picker.d.ts +44 -0
  20. package/dist/shell/controls.d.ts +101 -0
  21. package/dist/shell/elements.d.ts +27 -0
  22. package/dist/shell/expression-editor.d.ts +33 -0
  23. package/dist/shell/font-select.d.ts +24 -0
  24. package/dist/shell/format-bar.d.ts +15 -0
  25. package/dist/shell/help-content/changelog.d.ts +12 -0
  26. package/dist/shell/help-content/faq.d.ts +12 -0
  27. package/dist/shell/help-content/features.d.ts +12 -0
  28. package/dist/shell/help-content/getting-started.d.ts +12 -0
  29. package/dist/shell/help-content/index.d.ts +13 -0
  30. package/dist/shell/help-content/shortcuts.d.ts +12 -0
  31. package/dist/shell/help-modal.d.ts +19 -0
  32. package/dist/shell/page-extras.d.ts +10 -0
  33. package/dist/shell/panels.d.ts +17 -0
  34. package/dist/shell/prop-group.d.ts +11 -0
  35. package/dist/shell/property-panel.d.ts +14 -0
  36. package/dist/shell/property-search.d.ts +32 -0
  37. package/dist/shell/ruler.d.ts +29 -0
  38. package/dist/shell/table-props.d.ts +17 -0
  39. package/dist/shell/table.d.ts +22 -0
  40. package/dist/shell/toolbar-overflow.d.ts +28 -0
  41. package/dist/shell/toolbar.d.ts +8 -0
  42. package/dist/shell/watermark.d.ts +10 -0
  43. package/package.json +57 -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,100 @@
1
- # Temporary Holding Version
1
+ # @worm-vue3-print/common
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > ⚠️ **实验性质 · 以预览版发布到 npm**:dist-tag 为 `next`,安装必须写 `@worm-vue3-print/common@next`;
4
+ > 版本号形如 `1.3.7-beta.N`(与主线同号 + 预发布后缀)。npm 上还没有 `latest`,转正时才发 stable。
5
+ > 本包尚未定版,接口与产物形态仍可能调整,**不建议应用到生产环境**;
6
+ > Vue 3 项目请使用成熟方案 `@worm-vue3-print/canvas`,本包目前仅供评估与非生产环境的集成验证。
7
+
8
+ 打印模板可视化设计器的 **通用宿主适配形态**:任意框架、或完全没有框架的宿主都能直接接入,
9
+ 实现为零框架原生 Custom Element + Shadow DOM,**不依赖 Vue / React 等任何框架运行时**,
10
+ 用于把 `@worm-vue3-print/canvas`(Vue 3 版设计器)的能力带给 Vue 2、React、jQuery 及任意非 Vue3 宿主。
11
+
12
+ - 功能与布局与 Vue 3 版对齐,逐项状态见 [PARITY.md](./PARITY.md)
13
+ - 样式与图标从 canvas 构建产物**派生**(`scripts/gen-styles.mjs` 剥离 `[data-v-*]`、
14
+ `scripts/gen-icons.mjs` 抽取 lucide 图标),因此 canvas 改版后重新构建即自动跟随
15
+ - 运行时体积:`dist/index.js` 348.14 kB(gzip 99.99 kB),零框架依赖
16
+ - 浏览器直挂形态:`dist/common.js`(UMD,core 与码制库已内联)+ `dist/common.css`,见下节
17
+
18
+ ## 安装
19
+
20
+ ```bash
21
+ npm i @worm-vue3-print/common@next @worm-vue3-print/core
22
+ ```
23
+
24
+ `@next` 是预览版的 dist-tag,省略会报 `No matching version found`(stable 还没发,npm 上不存在 `latest`)。
25
+ `core` 装正式版即可(本包依赖 `^1.3.7`),出纸链路也要直接用它。
26
+
27
+ ## 浏览器直挂(jQuery / 无打包器宿主)
28
+
29
+ `vite.bundle.config.ts` 额外产出两个文件,子路径 `@worm-vue3-print/common/browser` 指向它们:
30
+
31
+ - `dist/common.js`(474.96 kB / gzip 145.34 kB):UMD,把 `@worm-vue3-print/core` 与条形码、二维码库
32
+ 全部内联,并挂出全局 `window.WormPrintCommon`。除了本包 `index` 的那套 API
33
+ (`registerAll` / `createDefaultTemplate` / `DesignerStore` / `PrintDesignerElement`),
34
+ 还一并挂出出纸要用的 `renderHtmlPages` / `browserCodeRenderer` / `PrintClient` / `WormPrintError`,
35
+ 以及宿主自绘模板缩略图所需的纸张几何工具 `getPaperDimensions` / `isContinuousPaperSize` / `getByPath`
36
+ —— 直挂宿主拿不到裸包名 `@worm-vue3-print/core`,没有这些入口就无法在同一个 `<script>` 里
37
+ 完成「浏览器渲染 → 打印 / 静默打印」
38
+ - `dist/common.css`:即 `src/styles/designer.css`(由 `gen-styles.mjs` 从 canvas 派生,含 `:host` 块级基线)。
39
+ Shadow DOM 形态用不到它——样式由组件内联注入;只有把设计器渲染进 **light DOM** 时才需要引它,
40
+ 公开子路径为 `@worm-vue3-print/common/style.css`(打包器 `import '@worm-vue3-print/common/style.css'`,
41
+ 无打包器则复制成文件后 `<link>`),不要深路径引 `dist/`
42
+
43
+ ```html
44
+ <link rel="stylesheet" href="/vendor/worm-print-common.css" />
45
+ <script src="/vendor/worm-print-common.js"></script>
46
+ <script>
47
+ WormPrintCommon.registerAll()
48
+ const el = document.querySelector('print-designer')
49
+ el.fields = fields // 数组/对象只能赋 property
50
+ el.template = templateJson
51
+ el.uploadImage = file => uploadToServer(file)
52
+ el.addEventListener('save', e => persist(e.detail))
53
+ const out = await WormPrintCommon.renderHtmlPages(
54
+ JSON.parse(el.getTemplateJson()), data, location.origin, WormPrintCommon.browserCodeRenderer)
55
+ </script>
56
+ ```
57
+
58
+ 两个硬约束:自定义元素默认 `display:inline`,宿主必须给它块级宽高,否则设计器整体塌陷;
59
+ `fields` 没有 getter,读回要看 `el.store.fields`。
60
+
61
+ 完整可运行的直挂宿主示例见 `demo-common/apps/jquery`(含 `sync-assets.mjs` 如何从包 dist 取这两个文件、
62
+ 以及 `/render-api` 透传的 40 行静态服务器);Vue3 / Vue2 / React 三种 NPM 接入形态见
63
+ `demo-common/apps/vue3`、`demo-common/apps/vue2`、`demo-common/apps/react`。
64
+
65
+ ## 使用
66
+
67
+ ```js
68
+ import { registerAll } from '@worm-vue3-print/common'
69
+ registerAll() // 注册 <print-designer>,按需调用,不自动污染全局
70
+ ```
71
+
72
+ ```html
73
+ <print-designer id="d" style="height:100%"></print-designer>
74
+ ```
75
+
76
+ ```js
77
+ const d = document.getElementById('d')
78
+ d.fields = [{ fieldKey: 'orderNo', fieldLabel: '单号' }] // 也接受 JSON 字符串
79
+ d.template = templateJson
80
+ d.addEventListener('save', e => save(e.detail)) // e.detail 为模板 JSON
81
+ d.addEventListener('preview', e => preview(e.detail))
82
+ d.getTemplateJson()
83
+ d.validateTemplate() // 拼版/多页配置校验,宿主旁路导出前调用
84
+ d.loadTemplate(json)
85
+ d.save()
86
+ ```
87
+
88
+ 出纸链路不需要设计器,直接走 `@worm-vue3-print/core`(浏览器渲染 / print-render 服务端 /
89
+ 桌面静默打印),与 canvas(Vue 3)宿主完全一致。
90
+
91
+ ## 与 canvas 版的边界
92
+
93
+ | | canvas(Vue 3) | common(本包) |
94
+ |---|---|---|
95
+ | 运行时 | Vue 3.5 | 无框架 |
96
+ | 宿主注入 | `provide/inject`、props | element property / attribute + CustomEvent |
97
+ | 样式 | `@worm-vue3-print/canvas/style.css` | 内置 Shadow DOM(`?inline`),无需引样式文件;light DOM 形态引 `@worm-vue3-print/common/style.css` |
98
+ | 适用 | Vue 3 项目 | React / Vue 2 / jQuery / 原生 |
99
+
100
+ Vue 3 项目应继续用 `@worm-vue3-print/canvas`,功能面更全;本包面向非 Vue3 宿主。
@@ -0,0 +1,12 @@
1
+ /*!
2
+ * @worm-vue3-print/common v1.3.7-beta.0
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-vue3-print/core';
8
+ import { renderHtmlPages, browserCodeRenderer } from '@worm-vue3-print/core/browser';
9
+ import { PrintClient, WormPrintError } from '@worm-vue3-print/core/client';
10
+ export * from './index';
11
+ export { renderHtmlPages, browserCodeRenderer, PrintClient, WormPrintError };
12
+ export { getPaperDimensions, isContinuousPaperSize, getByPath };