@tidaltolabs/markdown-echarts 0.0.0-stage → 0.1.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 (61) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +30 -0
  3. package/README.md +413 -2
  4. package/dist/browser/engine.d.ts +3 -0
  5. package/dist/browser/engine.d.ts.map +1 -0
  6. package/dist/browser/engine.js +49 -0
  7. package/dist/browser/engine.js.map +1 -0
  8. package/dist/browser/freeze-svg.d.ts +3 -0
  9. package/dist/browser/freeze-svg.d.ts.map +1 -0
  10. package/dist/browser/freeze-svg.js +27 -0
  11. package/dist/browser/freeze-svg.js.map +1 -0
  12. package/dist/browser/render-blocks.d.ts +4 -0
  13. package/dist/browser/render-blocks.d.ts.map +1 -0
  14. package/dist/browser/render-blocks.js +32 -0
  15. package/dist/browser/render-blocks.js.map +1 -0
  16. package/dist/browser/render-chart.d.ts +4 -0
  17. package/dist/browser/render-chart.d.ts.map +1 -0
  18. package/dist/browser/render-chart.js +258 -0
  19. package/dist/browser/render-chart.js.map +1 -0
  20. package/dist/browser/resource-policy.d.ts +2 -0
  21. package/dist/browser/resource-policy.d.ts.map +1 -0
  22. package/dist/browser/resource-policy.js +48 -0
  23. package/dist/browser/resource-policy.js.map +1 -0
  24. package/dist/browser/types.d.ts +40 -0
  25. package/dist/browser/types.d.ts.map +1 -0
  26. package/dist/browser/types.js +2 -0
  27. package/dist/browser/types.js.map +1 -0
  28. package/dist/browser.d.ts +7 -0
  29. package/dist/browser.d.ts.map +1 -0
  30. package/dist/browser.js +7 -0
  31. package/dist/browser.js.map +1 -0
  32. package/dist/dom-contract.d.ts +9 -0
  33. package/dist/dom-contract.d.ts.map +1 -0
  34. package/dist/dom-contract.js +9 -0
  35. package/dist/dom-contract.js.map +1 -0
  36. package/dist/index.d.ts +7 -0
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/index.js +7 -0
  39. package/dist/index.js.map +1 -0
  40. package/dist/markdown-it-plugin.d.ts +14 -0
  41. package/dist/markdown-it-plugin.d.ts.map +1 -0
  42. package/dist/markdown-it-plugin.js +57 -0
  43. package/dist/markdown-it-plugin.js.map +1 -0
  44. package/dist/parse-yaml.d.ts +9 -0
  45. package/dist/parse-yaml.d.ts.map +1 -0
  46. package/dist/parse-yaml.js +94 -0
  47. package/dist/parse-yaml.js.map +1 -0
  48. package/dist/protocol.d.ts +42 -0
  49. package/dist/protocol.d.ts.map +1 -0
  50. package/dist/protocol.js +61 -0
  51. package/dist/protocol.js.map +1 -0
  52. package/dist/security-policy.d.ts +15 -0
  53. package/dist/security-policy.d.ts.map +1 -0
  54. package/dist/security-policy.js +264 -0
  55. package/dist/security-policy.js.map +1 -0
  56. package/dist/semantic-validator.d.ts +13 -0
  57. package/dist/semantic-validator.d.ts.map +1 -0
  58. package/dist/semantic-validator.js +428 -0
  59. package/dist/semantic-validator.js.map +1 -0
  60. package/package.json +72 -4
  61. package/styles/echarts.css +35 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
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
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 TidaltoLabs
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,30 @@
1
+ @tidaltolabs/markdown-echarts
2
+ Copyright 2026 TidaltoLabs
3
+
4
+ This product includes software developed by TidaltoLabs and contributors.
5
+
6
+ The original project code and documentation are licensed under the Apache
7
+ License, Version 2.0 (see LICENSE).
8
+
9
+ ## 第三方依赖
10
+
11
+ 本包不打包任何第三方代码。以下依赖由 npm 单独安装,各自按其许可证分发:
12
+
13
+ 运行时依赖(dependencies):
14
+
15
+ - yaml — ISC License
16
+ - zod — MIT License
17
+
18
+ 同伴依赖(peerDependencies,由宿主安装):
19
+
20
+ - echarts — Apache License 2.0
21
+ - markdown-it — MIT License
22
+
23
+ 开发依赖(devDependencies,不进入发布产物):
24
+
25
+ - @types/markdown-it — MIT License
26
+ - happy-dom — MIT License
27
+ - typescript — Apache License 2.0
28
+ - vitest — MIT License
29
+
30
+ 具体版本以 package.json 与 pnpm-lock.yaml 为准。
package/README.md CHANGED
@@ -1,3 +1,414 @@
1
- # Temporary Holding Version
1
+ # @tidaltolabs/markdown-echarts
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 version](https://img.shields.io/npm/v/@tidaltolabs/markdown-echarts.svg)](https://www.npmjs.com/package/@tidaltolabs/markdown-echarts)
4
+ [![license](https://img.shields.io/badge/license-Apache%202.0-green.svg)](LICENSE)
5
+ [![CI](https://github.com/TidaltoLabs/markdown-echarts/actions/workflows/ci.yml/badge.svg)](https://github.com/TidaltoLabs/markdown-echarts/actions/workflows/ci.yml)
6
+
7
+ 为 Markdown 增加安全、可验证、可复用的 ECharts YAML 围栏,并在浏览器中渲染为 SVG。
8
+
9
+ [安装](#安装) · [快速开始](#快速开始) · [围栏语法](#基本语法) · [使用指南](docs/USAGE.md) · [安全边界](#安全边界)
10
+
11
+ ## 为什么需要它
12
+
13
+ 在 Markdown 里画图表通常有两种做法:内嵌 HTML 或脚本(不安全、无法校验),或者插入图片(不可编辑、无法与文档同源渲染)。本包提供第三条路:
14
+
15
+ - **安全优先**:YAML 先转换为纯数据对象,默认拒绝函数、外部资源、HTML formatter、原型污染属性与超限配置,适合处理不受信任的 Markdown。
16
+ - **可验证**:协议校验加系列语义校验,错误消息带配置路径;配置错误只变成局部错误占位,不会中断整篇文档。
17
+ - **宿主无关**:不依赖 React、Paged.js 或特定 PDF 引擎。生成的 HTML 可直接用于网页预览,也可以在图表渲染完成后交给 Chromium 输出 PDF。
18
+ - **打印友好**:浏览器运行时强制关闭全局与系列动画,静态 SVG 不会停在动画中间帧。
19
+ - **类型完整**:TypeScript 类型与多入口导出(Markdown 侧、浏览器侧、样式)。
20
+
21
+ ## 安装
22
+
23
+ ```bash
24
+ npm install @tidaltolabs/markdown-echarts echarts markdown-it
25
+ ```
26
+
27
+ ```bash
28
+ pnpm add @tidaltolabs/markdown-echarts echarts markdown-it
29
+ ```
30
+
31
+ `echarts`(`^6.1.0`)与 `markdown-it`(`^14.3.0`)是同伴依赖,由宿主安装,本包不打包它们。要求 Node.js 22 或更高版本。
32
+
33
+ ## 快速开始
34
+
35
+ ### 1. Markdown 侧:把围栏变成安全 HTML
36
+
37
+ ```ts
38
+ import MarkdownIt from "markdown-it";
39
+ import { markdownItECharts } from "@tidaltolabs/markdown-echarts";
40
+
41
+ const markdown = new MarkdownIt().use(markdownItECharts);
42
+ const html = markdown.render(source);
43
+ ```
44
+
45
+ ### 2. 浏览器侧:把占位渲染成图表
46
+
47
+ ```ts
48
+ import { renderEChartsBlocks } from "@tidaltolabs/markdown-echarts/browser";
49
+ import "@tidaltolabs/markdown-echarts/styles.css";
50
+
51
+ const outcomes = await renderEChartsBlocks(document, {
52
+ outputMode: "inline-svg",
53
+ concurrency: 2,
54
+ timeoutMs: 5000
55
+ });
56
+ ```
57
+
58
+ ### 3. 在 Markdown 中写一个围栏
59
+
60
+ ````markdown
61
+ ```echarts
62
+ height: 80mm
63
+ caption: 年度收入
64
+ option:
65
+ xAxis:
66
+ type: category
67
+ data: [2023, 2024]
68
+ yAxis:
69
+ type: value
70
+ series:
71
+ - type: bar
72
+ data: [120, 180]
73
+ ```
74
+ ````
75
+
76
+ 完整流程、字段说明与排错见[使用指南](docs/USAGE.md)。
77
+
78
+ ## 目录结构
79
+
80
+ ```text
81
+ src/
82
+ markdown-it-plugin.ts ECharts YAML 围栏与错误占位
83
+ parse-yaml.ts 受限 YAML 解析
84
+ protocol.ts 围栏协议与基础校验
85
+ security-policy.ts URL、函数、原型和规模安全策略
86
+ semantic-validator.ts 系列数据与坐标系语义校验
87
+ dom-contract.ts 宿主与浏览器运行时共用的 DOM 协议
88
+ browser.ts 浏览器入口
89
+ browser/ ECharts 按需加载、渲染和 SVG 冻结
90
+ index.ts Markdown 侧公共导出
91
+ styles/
92
+ echarts.css 图表、标题和错误占位样式
93
+ tests/ 解析、安全、语义、插件和真实 SVG 测试
94
+ ```
95
+
96
+ ## 基本语法
97
+
98
+ ````markdown
99
+ ```echarts
100
+ height: 80mm
101
+ caption: 年度收入
102
+ option:
103
+ xAxis:
104
+ type: category
105
+ data: [2023, 2024]
106
+ yAxis:
107
+ type: value
108
+ series:
109
+ - type: bar
110
+ data: [120, 180]
111
+ ```
112
+ ````
113
+
114
+ 围栏内容必须使用 YAML,并包含一个 ECharts `option` 对象。YAML
115
+ 会先转换为安全的纯数据对象,再交给 ECharts;不能使用函数、
116
+ YAML 锚点、别名或自定义标签。
117
+
118
+ ## 围栏字段
119
+
120
+ | 字段 | 类型 | 默认值 | 说明 |
121
+ | --- | --- | --- | --- |
122
+ | `version` | `1` | `1` | 围栏协议版本 |
123
+ | `height` | CSS 长度 | `80mm` | 支持 `mm`、`cm`、`in`、`px` |
124
+ | `aspectRatio` | 正数 | 无 | 与 `height` 二选一;指定后不补默认高度 |
125
+ | `theme` | `document`、`light`、`dark` | `document` | ECharts 主题 |
126
+ | `caption` | 字符串 | 无 | 图表标题说明 |
127
+ | `option` | 对象 | 必填 | 经过安全和语义验证的 ECharts 配置 |
128
+
129
+ ## 数据来源
130
+
131
+ 每个系列必须从以下任一位置获得有效数据:
132
+
133
+ - 非空的 `series[].data`;
134
+ - 非空的 `dataset.source`;
135
+ - 引用具有有效上游数据源的内置 `filter` 或 `sort` transform。
136
+
137
+ 只有表头的二维数组、所有列均为空的对象以及空数组不属于有效
138
+ 数据。使用 `dataset` 时保留 ECharts 的默认维度映射,也可以通过
139
+ `series.encode` 显式声明映射。
140
+
141
+ ```yaml
142
+ option:
143
+ dataset:
144
+ source:
145
+ - [year, sales]
146
+ - [2025, 120]
147
+ - [2026, 180]
148
+ series:
149
+ - type: line
150
+ encode:
151
+ x: year
152
+ y: sales
153
+ ```
154
+
155
+ ## 系列验证规则
156
+
157
+ 当前支持以下系列:
158
+
159
+ | 系列 | 主要规则 |
160
+ | --- | --- |
161
+ | `line` | 需要有效数据;支持直角坐标系和极坐标系 |
162
+ | `bar` | 需要有效数据;支持直角坐标系和极坐标系 |
163
+ | `scatter` | 直接数据至少包含两个坐标值 |
164
+ | `pie` | 直接数据项的 `value` 必须是有限数值 |
165
+ | `radar` | 必须提供非空 `radar.indicator`;数据维数不得少于指标数 |
166
+ | `heatmap` | 直角坐标数据为 `[x, y, value]`;日历数据为 `[date, value]` |
167
+ | `boxplot` | 直接数据为 `[min, Q1, median, Q3, max]` |
168
+ | `candlestick` | 直接数据为 `[open, close, lowest, highest]` |
169
+ | `tree` | 必须提供非空层级 `data`;递归校验 `children` |
170
+ | `treemap` | 必须提供非空层级 `data`;叶节点必须具有有限数值 |
171
+ | `sunburst` | 必须提供非空层级 `data`;叶节点必须具有有限数值 |
172
+ | `graph` | 必须提供 `data` 或 `nodes`;校验边引用;缺少坐标时默认 `force` 布局 |
173
+ | `sankey` | 必须提供节点和关系边;边权重必须是非负有限数值 |
174
+ | `chord` | 使用 ECharts 6 和弦图;必须提供节点、关系边和非负权重 |
175
+ | `funnel` | 数据项必须是有限数值,或使用有效 `dataset` |
176
+ | `gauge` | 数据项必须是有限数值,或使用有效 `dataset` |
177
+ | `pictorialBar` | 需要有效数据和直角坐标系;允许安全的 `path://` 内嵌矢量符号 |
178
+
179
+ 直角坐标系列缺少 `xAxis` 或 `yAxis` 时会补充空对象,让 ECharts
180
+ 使用自身的轴默认值。极坐标、雷达和日历坐标系表达了明确语义,
181
+ 因此不会猜测配置,缺少对应组件时会报告错误。
182
+
183
+ 使用 `dataset` 时,验证器只验证数据源是否存在,不重复实现
184
+ ECharts 的维度推断和 `encode` 映射规则。
185
+
186
+ ## 第二阶段系列示例
187
+
188
+ ### 层级图
189
+
190
+ ```yaml
191
+ height: 60mm
192
+ option:
193
+ series:
194
+ - type: treemap
195
+ nodeClick: false
196
+ breadcrumb:
197
+ show: false
198
+ label:
199
+ show: true
200
+ formatter: "{b}"
201
+ color: "#1f2937"
202
+ fontWeight: bold
203
+ backgroundColor: "rgba(255, 255, 255, 0.88)"
204
+ borderRadius: 3
205
+ padding: [3, 6]
206
+ itemStyle:
207
+ borderColor: "#ffffff"
208
+ borderWidth: 2
209
+ gapWidth: 2
210
+ levels:
211
+ - itemStyle:
212
+ borderWidth: 0
213
+ gapWidth: 2
214
+ - upperLabel:
215
+ show: true
216
+ height: 28
217
+ color: "#1f2937"
218
+ fontWeight: bold
219
+ backgroundColor: "rgba(255, 255, 255, 0.88)"
220
+ padding: [3, 6]
221
+ itemStyle:
222
+ borderColor: "#ffffff"
223
+ borderWidth: 2
224
+ gapWidth: 2
225
+ - label:
226
+ show: true
227
+ formatter: "{b}"
228
+ color: "#1f2937"
229
+ fontWeight: bold
230
+ backgroundColor: "rgba(255, 255, 255, 0.88)"
231
+ borderRadius: 3
232
+ padding: [3, 6]
233
+ itemStyle:
234
+ borderColor: "#ffffff"
235
+ borderWidth: 2
236
+ gapWidth: 2
237
+ data:
238
+ - name: 渲染
239
+ children:
240
+ - { name: Markdown, value: 32 }
241
+ - { name: ECharts, value: 24 }
242
+ - name: 导出
243
+ children:
244
+ - { name: PDF, value: 28 }
245
+ ```
246
+
247
+ `tree`、`treemap` 和 `sunburst` 共用递归 `children` 结构。
248
+ `treemap` 与 `sunburst` 的叶节点需要数值;父节点可以省略数值,
249
+ 由 ECharts 根据子节点汇总。
250
+
251
+ ### 关系图
252
+
253
+ ```yaml
254
+ height: 60mm
255
+ option:
256
+ series:
257
+ - type: sankey
258
+ data:
259
+ - { name: Markdown }
260
+ - { name: HTML }
261
+ - { name: PDF }
262
+ links:
263
+ - { source: Markdown, target: HTML, value: 100 }
264
+ - { source: HTML, target: PDF, value: 40 }
265
+ ```
266
+
267
+ `graph` 的关系边可以省略;`sankey` 和 ECharts 6 `chord` 必须
268
+ 具有非空 `links` 或 `edges`。`source`、`target` 必须引用节点
269
+ 名称、ID 或数组索引。
270
+
271
+ ### 业务图表
272
+
273
+ ```yaml
274
+ height: 60mm
275
+ option:
276
+ series:
277
+ - type: gauge
278
+ min: 0
279
+ max: 100
280
+ progress:
281
+ show: true
282
+ detail:
283
+ formatter: "{value}%"
284
+ data:
285
+ - { name: 完成率, value: 78 }
286
+ ```
287
+
288
+ `funnel` 和 `gauge` 使用有限数值数据;`pictorialBar` 复用柱图
289
+ 坐标系和数据规则,并允许不加载外部资源的 `path://` SVG 路径。
290
+
291
+ ## 错误行为
292
+
293
+ 配置错误不会中断整篇 Markdown。对应围栏会变成局部错误占位:
294
+
295
+ ```html
296
+ <div class="md-echarts-error" role="alert">
297
+ ECharts 图表配置无效:option.series.0.data 必须是非空数组……
298
+ </div>
299
+ ```
300
+
301
+ 错误消息包含配置路径,便于用户或 AI Agent 定位并修正 YAML。
302
+ 宿主还可以通过 `onError` 收集结构化错误。
303
+
304
+ ```ts
305
+ markdown.use(markdownItECharts, {
306
+ onError(error, context) {
307
+ console.warn(error.code, error.message, context.tokenIndex);
308
+ }
309
+ });
310
+ ```
311
+
312
+ ## Markdown-it 接入
313
+
314
+ ```ts
315
+ import MarkdownIt from "markdown-it";
316
+ import {
317
+ markdownItECharts
318
+ } from "@tidaltolabs/markdown-echarts";
319
+
320
+ const markdown = new MarkdownIt().use(markdownItECharts);
321
+ const html = markdown.render(source);
322
+ ```
323
+
324
+ 如果宿主还会对 HTML 做安全过滤,需要保留包生成的 `figure`、
325
+ `figcaption`、隐藏配置节点及 `data-echarts-*` 属性。
326
+
327
+ ## 浏览器渲染
328
+
329
+ ```ts
330
+ import {
331
+ renderEChartsBlocks
332
+ } from "@tidaltolabs/markdown-echarts/browser";
333
+ import "@tidaltolabs/markdown-echarts/styles.css";
334
+
335
+ const outcomes = await renderEChartsBlocks(document, {
336
+ outputMode: "inline-svg",
337
+ concurrency: 2,
338
+ timeoutMs: 5000
339
+ });
340
+ ```
341
+
342
+ 输出模式:
343
+
344
+ - `interactive`:保留 ECharts 实例和响应式尺寸监听;
345
+ - `inline-svg`:冻结为内联 SVG,适合打印和 PDF;
346
+ - `svg-image`:冻结为 SVG Data URL 图片。
347
+
348
+ PDF 输出前应等待所有图表、字体和图片完成,再开始分页或调用
349
+ Chromium `page.pdf()`。
350
+
351
+ 浏览器引擎会强制关闭全局及各系列动画,Markdown 中的动画参数不会改变
352
+ 静态 SVG、快速预览、精确预览或 PDF,避免输出停留在动画中间帧。
353
+ ECharts 围栏使用专用 `figure.md-echarts` DOM,不会套用普通代码围栏的
354
+ `pre.md-fences` 样式。
355
+
356
+ ## 安全边界
357
+
358
+ 默认策略会拒绝:
359
+
360
+ - `custom` 系列及 `renderItem`;
361
+ - JavaScript、HTTP、文件和 Data URL 外部资源;
362
+ - HTML formatter;
363
+ - 原型污染属性;
364
+ - 未允许的 toolbox 功能;
365
+ - 非内置数据转换;
366
+ - 超过节点数、深度、字符串、数组、系列、层级节点或关系边数量
367
+ 上限的配置。
368
+
369
+ 这些限制适用于不受信任的 Markdown。宿主如需扩大能力,应在明确
370
+ 风险后扩展验证器,而不是直接执行 YAML 中的 JavaScript。
371
+
372
+ ## 扩展系列验证
373
+
374
+ 各系列规则注册在 `echartsSeriesValidators`。新增图形时需要同步:
375
+
376
+ 1. 将系列类型加入协议支持列表;
377
+ 2. 在浏览器引擎中注册对应 ECharts Chart;
378
+ 3. 注册该系列的语义验证器;
379
+ 4. 增加有效、缺少数据、错误数据结构和真实 SVG 渲染测试。
380
+
381
+
382
+ ## 在 MorphDoc 中的使用
383
+
384
+ 本包最初为 [MorphDoc(墨呈)](https://github.com/TidaltoLabs/MorphDoc) 编写,目前仍由该项目通过 git submodule 引用:
385
+
386
+ - `@tidaltolabs/morphdoc-renderer` 接入围栏插件;
387
+ - `@tidaltolabs/morphdoc-preview-engine` 统一完成连续预览、分页适配与 SVG 冻结。
388
+
389
+ 在 MorphDoc 之外使用时不需要这些包,本包自身不依赖它们。
390
+
391
+ ## 开发与验证
392
+
393
+ ```bash
394
+ pnpm install
395
+ pnpm run typecheck
396
+ pnpm run test
397
+ pnpm run build
398
+ ```
399
+
400
+ `pnpm run dev` 以监听模式编译 `src`。Node.js 版本以 `.nvmrc` 为准。
401
+
402
+ 参考:
403
+
404
+ - [ECharts 配置参考](https://echarts.apache.org/en/option.html)
405
+ - [ECharts Dataset](https://echarts.apache.org/handbook/en/concepts/dataset/)
406
+ - [ECharts Data Transform](https://echarts.apache.org/handbook/en/concepts/data-transform/)
407
+
408
+ ## 许可证
409
+
410
+ Apache License 2.0,见 [LICENSE](LICENSE)。第三方依赖的许可证见 [NOTICE](NOTICE)。
411
+
412
+ ## 安全问题
413
+
414
+ 如果发现安全漏洞,请通过仓库的 Issue 或安全公告渠道私下报告,不要在公开 Issue 中披露细节。
@@ -0,0 +1,3 @@
1
+ import type { EChartsEngine } from "./types.js";
2
+ export declare const defaultEChartsEngine: EChartsEngine;
3
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/browser/engine.ts"],"names":[],"mappings":"AAyCA,OAAO,KAAK,EACV,aAAa,EAEd,MAAM,YAAY,CAAC;AAyCpB,eAAO,MAAM,oBAAoB,EAAE,aAQlC,CAAC"}