@worm-print-platform/echarts 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 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,119 @@
1
- # Temporary Holding Version
1
+ <p align="center">
2
+ <strong>@worm-print-platform/echarts</strong><br>
3
+ <em>打印模板 ECharts 图表元素可选包</em>
4
+ </p>
2
5
 
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.
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
+ </p>
10
+
11
+ > monorepo 根:[worm-print-platform](https://github.com/worm-longliu/worm-print-platform)
12
+
13
+ 一个插件注册十个图表元素:提供 ECharts SSR SVG 渲染器、页面执行器、设计器画布 / 图形化属性面板与共享数据契约。主包 `@worm-print-platform/core` 与 `@worm-print-platform/canvas` **不依赖任何图表库**,只有本包引入 `echarts`(Apache-2.0)。
14
+
15
+ **「import 即注册」**:宿主不需要写任何注册代码,也不需要手写渲染器传参。
16
+
17
+ ## 安装
18
+
19
+ ```bash
20
+ npm i @worm-print-platform/echarts
21
+ ```
22
+
23
+ 依赖:`echarts`(^6.1.0)、`@worm-print-platform/core`、`@worm-print-platform/plugin-kit`
24
+
25
+ ## 十个元素
26
+
27
+ | type | 元素 | 默认尺寸 | 数据映射要点 |
28
+ | --- | --- | --- | --- |
29
+ | `barChart` | 柱状图 | 100×60mm | 类目 + 多数值字段(多值多系列) |
30
+ | `barHChart` | 条形图(横向) | 100×60mm | 类目写 yAxis,xAxis 为数值 |
31
+ | `lineChart` | 折线图 | 100×60mm | 同柱状图,series 为 line |
32
+ | `areaChart` | 面积图 | 100×60mm | 折线 + areaStyle |
33
+ | `pieChart` | 饼图 | 60×60mm | 类目 + 首数值 → `{ name, value }` |
34
+ | `doughnutChart` | 环形图 | 60×60mm | 饼图 + 可配内径 |
35
+ | `scatterChart` | 散点图 | 80×60mm | 类目作 x、首数值作 y;`chartBubble` 开启时第二数值作点大小 |
36
+ | `radarChart` | 雷达图 | 70×60mm | 数值字段 = 维度,每行一个系列 |
37
+ | `funnelChart` | 漏斗图 | 60×60mm | 类目 + 首数值,按数值降序 |
38
+ | `gaugeChart` | 仪表盘 | 60×60mm | 取首行首值;min/max 面板可配 |
39
+
40
+ 所有元素共用同一份数据契约:`chartOption` + `chartDataSource` / `chartCategoryField` / `chartValueFields` / `chartSeriesField`。模板只存 option 模板与字段映射,真实数据由 core 绑定阶段注入。
41
+
42
+ ## 用法
43
+
44
+ ### 设计器 / 浏览器宿主
45
+
46
+ ```ts
47
+ // 一行副作用 import:素材卡、画布、属性面板、校验、绑定、出图全部生效
48
+ import '@worm-print-platform/echarts'
49
+ ```
50
+
51
+ ### 服务端 PDF / Electron 主进程
52
+
53
+ ```ts
54
+ // ① 部署白名单:显式 import 才允许该插件进入注册表
55
+ import '@worm-print-platform/echarts/node'
56
+
57
+ // ② runtime 装配:执行器由注册表自动收集,新增插件无需改这行
58
+ import { collectExecutorBundles, createDomHostRuntime } from '@worm-print-platform/core'
59
+ createDomHostRuntime(factory, loadExecutorBundle(), collectExecutorBundles())
60
+ ```
61
+
62
+ ### 零框架宿主 / 自建设计器 UI(`/kit`)
63
+
64
+ `/kit` 是**框架无关的纯 TS 出口**:不包含任何 `.vue` 组件、不读磁盘,import 即把十个 kind 注册到 core 插件注册表,但**不**注册设计器组件与执行器产物。
65
+
66
+ ```ts
67
+ import {
68
+ CHART_KIND_DEFINITIONS, createDefaultChartOption, normalizeChartOption,
69
+ previewChartOption, renderChartToSvg,
70
+ } from '@worm-print-platform/echarts/kit'
71
+ ```
72
+
73
+ ## 配置
74
+
75
+ ```ts
76
+ import { configureChartPlugin } from '@worm-print-platform/echarts'
77
+
78
+ configureChartPlugin({
79
+ defaultWidth: 120, // 新建图表元素的全局默认尺寸
80
+ defaultHeight: 70,
81
+ palettes: {
82
+ default: { label: '企业蓝', colors: ['#165DFF', '#36B37E'] },
83
+ brand: { label: '品牌色', colors: ['#F2704E', '#F7A35C'] },
84
+ },
85
+ sampleCategories: ['一季度', '二季度', '三季度'],
86
+ components: [GaugeChart], // 追加 echarts.use 的图表/组件构造器
87
+ })
88
+ ```
89
+
90
+ 配置是**惰性**的:可在注册前调用、按键合并,不需要注销重注册。
91
+
92
+ ## 导出
93
+
94
+ | 子路径 | 内容 |
95
+ | --- | --- |
96
+ | `.` | `CHART_PLUGIN` / `CHART_KIND_DEFINITIONS` / `createDefaultChartOption` / `renderChartToSvg` / `configureChartPlugin` 等(注册副作用 + 纯 TS 能力) |
97
+ | `/kit` | 框架无关纯 TS 出口(无 Vue、无 `node:fs`) |
98
+ | `/node` | 注册副作用 + `render.executorBundle()`(惰性读取 IIFE 产物,服务端装配用) |
99
+ | `/ui` | plugin-kit 设计器 UI(静态 SVG 画布 + 原生 DOM 属性面板) |
100
+ | `/browser` | UMD bundle(`dist/echarts.js`) |
101
+
102
+ `type-augmentation.ts` 用声明合并把十个图表类型与 `chartOption` 等专属字段注入 core 的类型扩展点。
103
+
104
+ ## 开发
105
+
106
+ ```bash
107
+ npm run build # vite + tsc + tsup
108
+ npm test # vitest
109
+ ```
110
+
111
+ ## 相关链接
112
+
113
+ - [根 README](https://github.com/worm-longliu/worm-print-platform/blob/main/README.md)
114
+ - [插件化自定义元素章节](https://github.com/worm-longliu/worm-print-platform/blob/main/README.md#插件化自定义元素)
115
+ - [plugin-kit 契约](../plugin-kit/README.md)
116
+
117
+ ## License
118
+
119
+ [MIT](../../LICENSE)
package/dist/bind.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /*!
2
+ * @worm-print-platform/echarts 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
+ /**
8
+ * 绑定入口:返回要合并进元素 options 的补丁(`_chartOption`)。
9
+ * 没有可绑定数据、没有数值字段、或 option 里没有 `$data` 占位时原样保留(手写固定数据不被覆盖)。
10
+ */
11
+ export declare function bindChartData(type: string, options: Record<string, unknown>, data: Record<string, unknown>): Record<string, unknown>;
@@ -0,0 +1,19 @@
1
+ /*!
2
+ * @worm-print-platform/echarts 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 { CHART_EXECUTOR_VERSION } from '../version.js';
8
+ /**
9
+ * 批量渲染规格 → `key → SVG` 映射(core 执行器协议:无首参、同步返回普通对象)。
10
+ * 单个规格失败只跳过该 key:core 侧对未命中的 key 会明确报「缺少扩展元素执行器产物」。
11
+ */
12
+ export declare function renderAssets(specs: Array<Record<string, unknown>>): Record<string, string>;
13
+ type ExecutorHolder = Record<string, unknown>;
14
+ /**
15
+ * 挂载到 globalThis.__wormDom:core 的 DOM 执行器注入在前、本执行器注入在后,
16
+ * 两者共用同一个全局对象;只新增 renderAssets,不覆盖 core 已有方法。
17
+ */
18
+ export declare function installChartExecutor(target?: Record<string, unknown>): ExecutorHolder;
19
+ export { CHART_EXECUTOR_VERSION };
@@ -0,0 +1,8 @@
1
+ /*!
2
+ * @worm-print-platform/echarts 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 './ui';
8
+ export * from './index';
@@ -0,0 +1,36 @@
1
+ /*!
2
+ * @worm-print-platform/echarts 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
+ export interface ChartPaletteDefinition {
8
+ label?: string;
9
+ colors: readonly string[];
10
+ }
11
+ /** 可通过 configureChartPlugin() 写入的全部配置键(均可选,缺省走出厂默认) */
12
+ export interface ChartPluginConfig {
13
+ /** 新建图表元素的默认宽度(mm);kind 自带默认尺寸,配置优先 */
14
+ defaultWidth?: number;
15
+ /** 新建图表元素的默认高度(mm) */
16
+ defaultHeight?: number;
17
+ /** 覆盖同名预设配色或新增配色:key → { label, colors } */
18
+ palettes?: Readonly<Record<string, ChartPaletteDefinition>>;
19
+ /** 追加的 ECharts 图表/组件构造器,交给 echarts.use(如 GaugeChart、MarkLineComponent) */
20
+ components?: readonly unknown[];
21
+ /** 设计态示例类目(模板态 $data 占位在无绑定数据时的替换值) */
22
+ sampleCategories?: readonly string[];
23
+ }
24
+ export declare function configureChartPlugin(config: ChartPluginConfig): void;
25
+ export declare function getChartPluginConfig(): ChartPluginConfig;
26
+ export interface ChartPalette {
27
+ key: string;
28
+ label: string;
29
+ colors: readonly string[];
30
+ }
31
+ /** 预设配色 ∪ 自定义配色:同名以自定义为准,新增 key 追加在末尾 */
32
+ export declare function getChartPalettes(): ChartPalette[];
33
+ /** 设计态示例类目;未配置时与 P0 行为一致 */
34
+ export declare function getSampleCategories(): readonly string[];
35
+ /** 某 kind 的元素出厂默认选项:core 元素工厂与 canvas 素材卡共用同一份 */
36
+ export declare function chartFactoryDefaults(type: string, partial?: Record<string, unknown>): Record<string, unknown>;
@@ -0,0 +1,60 @@
1
+ /*!
2
+ * @worm-print-platform/echarts 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
+ /** 插件 id:写入模板顶层 plugins 清单,也是 configurePlugin / 注册表查询的键 */
8
+ export declare const CHART_PLUGIN_ID = "@worm-print-platform/echarts";
9
+ /** 图形化面板可选配色(落 chartOption.color,ECharts 按系列循环取色) */
10
+ export declare const CHART_PALETTES: readonly [{
11
+ readonly key: "default";
12
+ readonly label: "默认蓝";
13
+ readonly colors: readonly ["#5470c6", "#91cc75", "#fac858", "#ee6666", "#73c0de"];
14
+ }, {
15
+ readonly key: "fresh";
16
+ readonly label: "清新绿";
17
+ readonly colors: readonly ["#2f9e6e", "#5cc9a7", "#9ad6c1", "#f2c94c", "#4a90e2"];
18
+ }, {
19
+ readonly key: "warm";
20
+ readonly label: "暖橙红";
21
+ readonly colors: readonly ["#f2704e", "#f7a35c", "#f7d56d", "#c54e3f", "#8f5a4a"];
22
+ }, {
23
+ readonly key: "purple";
24
+ readonly label: "紫灰";
25
+ readonly colors: readonly ["#7b61ff", "#9b8cff", "#c3baff", "#596275", "#8d99ae"];
26
+ }];
27
+ export type ChartPaletteKey = (typeof CHART_PALETTES)[number]['key'];
28
+ /** 设计态示例类目(模板态 $data 占位在无绑定数据时的替换值) */
29
+ export declare const FALLBACK_SAMPLE_CATEGORIES: readonly string[];
30
+ /**
31
+ * 漏斗图出厂内边距(%):ECharts 内置默认是 px(left/right 80、top 60、bottom 65),
32
+ * 小尺寸打印框里会把图形压到一半都不到。右侧留 25% 给外置标签与引导线,其余三边压到 5~6% 铺满。
33
+ */
34
+ export declare const FUNNEL_PADDING_DEFAULTS: {
35
+ readonly top: 6;
36
+ readonly right: 25;
37
+ readonly bottom: 6;
38
+ readonly left: 5;
39
+ };
40
+ /** 漏斗图四边内边距(%),对应 ECharts funnel series 的 top/right/bottom/left */
41
+ export interface FunnelPadding {
42
+ top: number;
43
+ right: number;
44
+ bottom: number;
45
+ left: number;
46
+ }
47
+ /**
48
+ * 雷达图出厂半径(%):ECharts 6 把 radar.radius 的默认值从 5.x 的 75% 调到 50%,
49
+ * 70×60mm 的元素框里图形直径只剩短边一半,四周空得厉害;回到 75% 与 5.x 观感一致。
50
+ */
51
+ export declare const RADAR_RADIUS_DEFAULT = 75;
52
+ /** ECharts 内置雷达半径默认值(%),存量模板没写 radius 时面板按它回读 */
53
+ export declare const ECHARTS_RADAR_RADIUS_DEFAULT = 50;
54
+ /** ECharts 内置漏斗内边距默认值(px),存量模板没写时面板按当前元素框折算成百分比回读 */
55
+ export declare const ECHARTS_FUNNEL_PADDING_PX: {
56
+ readonly top: 60;
57
+ readonly right: 80;
58
+ readonly bottom: 65;
59
+ readonly left: 80;
60
+ };
@@ -0,0 +1,8 @@
1
+ /*!
2
+ * @worm-print-platform/echarts 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
+ /** 按 kind 生成出厂 option;series.type 与 kind 语义一致(折线图不会落成柱状图) */
8
+ export declare function createDefaultChartOption(type: string): Record<string, unknown>;
@@ -0,0 +1,14 @@
1
+ /*!
2
+ * @worm-print-platform/echarts 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 * as echarts from 'echarts/core';
8
+ /**
9
+ * 追加 configureChartPlugin({ components }) 声明的图表/组件构造器(P5)。
10
+ * 惰性且幂等:未配置时零开销;改配置后下一次出图自动生效,无需重新注册插件。
11
+ */
12
+ export declare function applyExtraComponents(): void;
13
+ export { echarts };
14
+ export type EChartsType = echarts.EChartsType;