ice-render 1.4.1 → 1.4.3
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 +39 -0
- package/dist/index.cjs +3 -3
- package/dist/index.mjs +3 -3
- package/dist/index.umd.js +3 -3
- package/dist/types/ICE.d.mts +36 -0
- package/dist/types/ICE.d.ts +36 -0
- package/dist/types/cross-platform/Path2DRecorder.d.mts +76 -0
- package/dist/types/cross-platform/Path2DRecorder.d.ts +76 -0
- package/dist/types/cross-platform/PolyfillPath2D.d.mts +8 -18
- package/dist/types/cross-platform/PolyfillPath2D.d.ts +8 -18
- package/dist/types/export/SvgExporter.d.mts +54 -0
- package/dist/types/export/SvgExporter.d.ts +54 -0
- package/dist/types/graphic/ICEComponent.d.mts +31 -1
- package/dist/types/graphic/ICEComponent.d.ts +31 -1
- package/dist/types/graphic/ICEPath.d.mts +7 -0
- package/dist/types/graphic/ICEPath.d.ts +7 -0
- package/dist/types/graphic/text/ICEText.d.mts +21 -0
- package/dist/types/graphic/text/ICEText.d.ts +21 -0
- package/dist/types/index.d.mts +2 -0
- package/dist/types/index.d.ts +2 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -135,6 +135,45 @@ ice.addChild(new ICERect({ width: 100, height: 50 }));
|
|
|
135
135
|
|
|
136
136
|
发布包提供 **ESM(`dist/index.mjs`)/ CJS(`dist/index.cjs`)/ UMD(`dist/index.umd.js`)** 三种格式。
|
|
137
137
|
|
|
138
|
+
### 导出 SVG(矢量,不依赖 canvas)
|
|
139
|
+
|
|
140
|
+
画布的 `toDataURL()` / `toBlob()` 是**光栅快照**(分辨率写死、放大就糊)。引擎的路径对象是
|
|
141
|
+
`Path2DRecorder`:一边把命令写给原生 Path2D 上屏、一边留下**命令流**,所以同一份场景可以再生成
|
|
142
|
+
一份**矢量描述**——任意放大、进 Illustrator/Figma、走打印/PDF 流程,或者在 Node 里出图(不需要 canvas)。
|
|
143
|
+
|
|
144
|
+
```javascript
|
|
145
|
+
const svg = ice.toSvg(); // 内容自适应 + 透明背景
|
|
146
|
+
const svg = ice.toSvg({ background: '#ffffff', padding: 16 }); // 白底 + 留白
|
|
147
|
+
const svg = ice.toSvg({ area: 'viewport' }); // 当前视口所见即所得
|
|
148
|
+
const { svg, width, height } = ice.toSvgResult({ scale: 2 }); // 需要宽高(写文件/排版预览)
|
|
149
|
+
|
|
150
|
+
// 不在浏览器里也能用:Node 侧同样导出(路径命令流不依赖 canvas)
|
|
151
|
+
const svg = exportSvg(ice); // 或 exportSvg(任意组件) 导出子树
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
导出**镜像渲染口径**而不是另起一套:绘制顺序(z 序稳定排序、工具层默认排除)、每个组件的
|
|
155
|
+
`composeMatrix()` 世界矩阵、`props.style`/`state.style` 的合并顺序、有效透明度(自身 × 祖先)、
|
|
156
|
+
祖先 `clipChildren` 裁剪、阴影预设(`sm`/`md`/`lg`)、线性/径向渐变、虚线都按同一份口径落到 SVG。
|
|
157
|
+
|
|
158
|
+
限制(都会明确写进 JSDoc):阴影用 `feDropShadow` 近似(`stdDeviation = shadowBlur / 2`,模糊观感
|
|
159
|
+
与 canvas 不会逐像素一致);雪碧图切图(`sx/sy/sw/sh`)暂不支持;文本导出的是**静态瞬间**,
|
|
160
|
+
且 SVG 与 canvas 的字形度量/基线定义不同,因此导出的文字位置是「对齐口径一致、逐像素允许微差」。
|
|
161
|
+
|
|
162
|
+
可运行示例:`examples/export/svg-export.html`(画布与 SVG 并排对比,可调背景/留白/倍数、勾选是否
|
|
163
|
+
包含工具层),以及 `examples/node/export.mjs`(**服务端出图**:`ICE.headless()` 建树 → `toSvg()`
|
|
164
|
+
落盘,装了 `@resvg/resvg-js` 时再转一张 2× PNG)。
|
|
165
|
+
|
|
166
|
+
```js
|
|
167
|
+
// 服务端(Node,没有 document / canvas)
|
|
168
|
+
const { ICE, ICERect } = require('ice-render');
|
|
169
|
+
const ice = ICE.headless();
|
|
170
|
+
ice.addChild(new ICERect({ width: 240, height: 120, radius: 12, style: { fillStyle: '#4f46e5' } }));
|
|
171
|
+
const svg = ice.toSvg({ padding: 16, background: '#ffffff' });
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
PNG / PDF 不内置依赖:SVG 是通用中间格式,`resvg`、`sharp`、`rsvg-convert`、headless Chrome
|
|
175
|
+
打印都能接着走 —— 引擎保持零运行时依赖。
|
|
176
|
+
|
|
138
177
|
## 📚 文档
|
|
139
178
|
|
|
140
179
|
- **架构设计文档** —— [`docs/architecture/`](./docs/architecture/README.md):运行时链路 / 组件模型 / 坐标系与矩阵 / 渲染性能 / 事件 / 序列化 / 交互动画 / 多运行时兼容。
|