ice-render 1.0.3 → 1.0.5
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 +0 -0
- package/README.md +229 -139
- package/dist/THIRD-PARTY-NOTICES.txt +32 -0
- package/dist/index.cjs +30 -0
- package/dist/index.mjs +30 -0
- package/dist/index.umd.js +6 -1
- package/dist/types/FrameManager.d.mts +26 -0
- package/dist/types/FrameManager.d.ts +26 -24
- package/dist/types/ICE.d.mts +369 -0
- package/dist/types/ICE.d.ts +369 -109
- package/dist/types/a11y/accessibility.d.mts +46 -0
- package/dist/types/a11y/accessibility.d.ts +46 -0
- package/dist/types/animation/AnimationManager.d.mts +96 -0
- package/dist/types/animation/AnimationManager.d.ts +96 -25
- package/dist/types/animation/Easing.d.mts +33 -0
- package/dist/types/animation/Easing.d.ts +33 -32
- package/dist/types/consts/BIG_ZINDEX_NUMBER.d.mts +14 -0
- package/dist/types/consts/BIG_ZINDEX_NUMBER.d.ts +14 -14
- package/dist/types/consts/COMPONENT_TYPE_MAPPING.d.mts +45 -0
- package/dist/types/consts/COMPONENT_TYPE_MAPPING.d.ts +45 -36
- package/dist/types/consts/DOM_EVENT_MAPPING_CONSTS.d.mts +37 -0
- package/dist/types/consts/DOM_EVENT_MAPPING_CONSTS.d.ts +37 -19
- package/dist/types/consts/ICE_EVENT_NAME_CONSTS.d.mts +27 -0
- package/dist/types/consts/ICE_EVENT_NAME_CONSTS.d.ts +27 -20
- package/dist/types/control-panel/AlignmentGuideManager.d.mts +92 -0
- package/dist/types/control-panel/AlignmentGuideManager.d.ts +92 -0
- package/dist/types/control-panel/ICEControlPanel.d.mts +37 -0
- package/dist/types/control-panel/ICEControlPanel.d.ts +37 -37
- package/dist/types/control-panel/ICEControlPanelManager.d.mts +25 -0
- package/dist/types/control-panel/ICEControlPanelManager.d.ts +25 -23
- package/dist/types/control-panel/link-controls/LineControlPanel.d.mts +39 -0
- package/dist/types/control-panel/link-controls/LineControlPanel.d.ts +39 -39
- package/dist/types/control-panel/transform-controls/ResizeControl.d.mts +38 -0
- package/dist/types/control-panel/transform-controls/ResizeControl.d.ts +38 -34
- package/dist/types/control-panel/transform-controls/RotateControl.d.mts +12 -0
- package/dist/types/control-panel/transform-controls/RotateControl.d.ts +12 -16
- package/dist/types/control-panel/transform-controls/TransformControlPanel.d.mts +83 -0
- package/dist/types/control-panel/transform-controls/TransformControlPanel.d.ts +83 -74
- package/dist/types/control-panel/transform-controls/constraints.d.mts +24 -0
- package/dist/types/control-panel/transform-controls/constraints.d.ts +24 -0
- package/dist/types/cross-platform/PolyfillPath2D.d.mts +31 -0
- package/dist/types/cross-platform/PolyfillPath2D.d.ts +31 -0
- package/dist/types/cross-platform/root.d.mts +7 -0
- package/dist/types/cross-platform/root.d.ts +7 -2
- package/dist/types/event/DOMEventDispatcher.d.mts +68 -0
- package/dist/types/event/DOMEventDispatcher.d.ts +68 -29
- package/dist/types/event/DOMEventInterceptor.d.mts +36 -0
- package/dist/types/event/DOMEventInterceptor.d.ts +36 -7
- package/dist/types/event/EventBus.d.mts +27 -0
- package/dist/types/event/EventBus.d.ts +27 -27
- package/dist/types/event/ICEEvent.d.mts +46 -0
- package/dist/types/event/ICEEvent.d.ts +46 -46
- package/dist/types/event/ICEEventTarget.d.mts +106 -0
- package/dist/types/event/ICEEventTarget.d.ts +106 -106
- package/dist/types/event/input-normalize.d.mts +75 -0
- package/dist/types/event/input-normalize.d.ts +75 -0
- package/dist/types/geometry/GeoLine.d.mts +24 -0
- package/dist/types/geometry/GeoLine.d.ts +24 -23
- package/dist/types/geometry/GeoPoint.d.mts +53 -0
- package/dist/types/geometry/GeoPoint.d.ts +53 -66
- package/dist/types/geometry/GeoUtil.d.mts +73 -0
- package/dist/types/geometry/GeoUtil.d.ts +73 -37
- package/dist/types/geometry/ICEBoundingBox.d.mts +81 -0
- package/dist/types/geometry/ICEBoundingBox.d.ts +81 -81
- package/dist/types/graphic/ICEComponent.d.mts +436 -0
- package/dist/types/graphic/ICEComponent.d.ts +436 -264
- package/dist/types/graphic/ICEDotPath.d.mts +99 -0
- package/dist/types/graphic/ICEDotPath.d.ts +99 -63
- package/dist/types/graphic/ICEImage.d.mts +17 -0
- package/dist/types/graphic/ICEImage.d.ts +17 -17
- package/dist/types/graphic/ICEPath.d.mts +39 -0
- package/dist/types/graphic/ICEPath.d.ts +39 -39
- package/dist/types/graphic/container/ICEGroup.d.mts +101 -0
- package/dist/types/graphic/container/ICEGroup.d.ts +101 -54
- package/dist/types/graphic/link/ICEBezier.d.mts +23 -0
- package/dist/types/graphic/link/ICEBezier.d.ts +23 -15
- package/dist/types/graphic/link/ICELinkHook.d.mts +52 -0
- package/dist/types/graphic/link/ICELinkHook.d.ts +52 -52
- package/dist/types/graphic/link/ICELinkSlot.d.mts +54 -0
- package/dist/types/graphic/link/ICELinkSlot.d.ts +54 -46
- package/dist/types/graphic/link/ICELinkSlotManager.d.mts +28 -0
- package/dist/types/graphic/link/ICELinkSlotManager.d.ts +28 -28
- package/dist/types/graphic/link/ICEPolyLine.d.mts +292 -0
- package/dist/types/graphic/link/ICEPolyLine.d.ts +292 -219
- package/dist/types/graphic/link/ICEVisioLink.d.mts +163 -0
- package/dist/types/graphic/link/ICEVisioLink.d.ts +163 -129
- package/dist/types/graphic/shape/ICECircle.d.mts +19 -0
- package/dist/types/graphic/shape/ICECircle.d.ts +19 -19
- package/dist/types/graphic/shape/ICEEllipse.d.mts +29 -0
- package/dist/types/graphic/shape/ICEEllipse.d.ts +29 -26
- package/dist/types/graphic/shape/ICEIsogon.d.mts +52 -0
- package/dist/types/graphic/shape/ICEIsogon.d.ts +52 -54
- package/dist/types/graphic/shape/ICERect.d.mts +10 -0
- package/dist/types/graphic/shape/ICERect.d.ts +10 -17
- package/dist/types/graphic/shape/ICERose.d.mts +41 -0
- package/dist/types/graphic/shape/ICERose.d.ts +41 -41
- package/dist/types/graphic/shape/ICEStar.d.mts +45 -0
- package/dist/types/graphic/shape/ICEStar.d.ts +45 -48
- package/dist/types/graphic/text/ICEText.d.mts +137 -0
- package/dist/types/graphic/text/ICEText.d.ts +137 -64
- package/dist/types/index.d.mts +55 -0
- package/dist/types/index.d.ts +55 -41
- package/dist/types/layout/ICEBorderLayout.d.mts +34 -0
- package/dist/types/layout/ICEBorderLayout.d.ts +34 -0
- package/dist/types/layout/ICEBoxLayout.d.mts +30 -0
- package/dist/types/layout/ICEBoxLayout.d.ts +30 -0
- package/dist/types/layout/ICECardLayout.d.mts +36 -0
- package/dist/types/layout/ICECardLayout.d.ts +36 -0
- package/dist/types/layout/ICEFlowLayout.d.mts +31 -0
- package/dist/types/layout/ICEFlowLayout.d.ts +31 -0
- package/dist/types/layout/ICEGridLayout.d.mts +33 -0
- package/dist/types/layout/ICEGridLayout.d.ts +33 -0
- package/dist/types/layout/ICELayeredLayout.d.mts +49 -0
- package/dist/types/layout/ICELayeredLayout.d.ts +49 -0
- package/dist/types/layout/ICELayoutManager.d.mts +33 -0
- package/dist/types/layout/ICELayoutManager.d.ts +33 -0
- package/dist/types/layout/ICEOverlayLayout.d.mts +25 -0
- package/dist/types/layout/ICEOverlayLayout.d.ts +25 -0
- package/dist/types/persistence/Deserializer.d.mts +43 -0
- package/dist/types/persistence/Deserializer.d.ts +43 -14
- package/dist/types/persistence/Serializer.d.mts +35 -0
- package/dist/types/persistence/Serializer.d.ts +35 -26
- package/dist/types/plugin/PluginHost.d.mts +86 -0
- package/dist/types/plugin/PluginHost.d.ts +86 -0
- package/dist/types/renderer/CanvasRenderer.d.mts +150 -0
- package/dist/types/renderer/CanvasRenderer.d.ts +150 -24
- package/dist/types/renderer/ObjectCache.d.mts +79 -0
- package/dist/types/renderer/ObjectCache.d.ts +79 -0
- package/dist/types/renderer/dirty-rect-util.d.mts +86 -0
- package/dist/types/renderer/dirty-rect-util.d.ts +86 -0
- package/dist/types/theme/ICETheme.d.mts +382 -0
- package/dist/types/theme/ICETheme.d.ts +382 -0
- package/dist/types/util/ImageCache.d.mts +19 -0
- package/dist/types/util/ImageCache.d.ts +19 -17
- package/dist/types/util/data-util.d.mts +43 -0
- package/dist/types/util/data-util.d.ts +43 -19
- package/dist/types/util/gl-matrix-skew.d.mts +14 -0
- package/dist/types/util/gl-matrix-skew.d.ts +14 -14
- package/dist/types/util/lang.d.mts +28 -0
- package/dist/types/util/lang.d.ts +28 -0
- package/dist/types/util/uuid.d.mts +1 -0
- package/dist/types/util/uuid.d.ts +1 -1
- package/package.json +119 -81
- package/dist/index.cjs.js +0 -25
- package/dist/index.js +0 -25
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
@@ -1,139 +1,229 @@
|
|
|
1
|
-
<p align="center">
|
|
2
|
-
<img width="150" src="./
|
|
3
|
-
</p>
|
|
4
|
-
|
|
5
|
-
<h1 align="center">ICERender
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
ice
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img width="150" src="./examples/assets/ice-render.png" alt="ICERender logo">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">ICERender · 雪花渲染器</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://www.npmjs.com/package/ice-render"><img src="https://img.shields.io/npm/v/ice-render" alt="npm version"></a>
|
|
9
|
+
<a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="license"></a>
|
|
10
|
+
<a href="https://gitee.com/ice-render/ice-render"><img src="https://img.shields.io/badge/repo-gitee-c71d23.svg" alt="gitee repository"></a>
|
|
11
|
+
<img src="https://img.shields.io/badge/TypeScript-100%25-3178c6.svg" alt="TypeScript">
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
ICERender 是一款 **Canvas 2D 交互图形渲染引擎**,面向 ER 图 / 流程图 / 拓扑图等图表编辑场景。它借鉴 React 的组件模型与 W3C 的事件模型,提供嵌套坐标系、序列化、动画、Visio 风格连接线等能力,同时以「极简依赖 + 多运行时兼容 + 高性能」为设计约束。
|
|
15
|
+
|
|
16
|
+
> 概要介绍视频:<https://www.bilibili.com/video/BV1hT4y1v7G5>
|
|
17
|
+
|
|
18
|
+
## ⭐ 差异化能力
|
|
19
|
+
|
|
20
|
+
以下三点是本引擎在同类 Canvas 图形引擎中较少同时具备的能力,且都有回归测试或基准数据支撑。
|
|
21
|
+
|
|
22
|
+
**1. 极端规模下的内存与构建效率**
|
|
23
|
+
|
|
24
|
+
- **默认配置不复制** —— 所有实例原型继承同一份默认 `props` / `state`,只有显式传入的字段才落到实例上;嵌套对象在合并时才做写时复制。
|
|
25
|
+
- **挂载去重为 O(1)** —— 用 `WeakSet`,批量挂载不再有 `indexOf` 的 O(n²) 放大。
|
|
26
|
+
- **实测**:**100 万个最小矩形的堆增量约 0.87GB**(朴素实现约 2.0GB);**100 万图元构建约 6s**。
|
|
27
|
+
- **回归**:`tests/graphic/ICEComponent.props-sharing.test.ts`、`tests/ICE.add-child.test.ts`;微基准见 `bench/micro/`。
|
|
28
|
+
|
|
29
|
+
**2. 局部重绘是一条可证明的像素契约**
|
|
30
|
+
|
|
31
|
+
- 默认渲染路径为**脏矩形局部重绘**,不满足局部条件时自动回退全量;`ICE.init(ctx, { renderMode: 'full' })` 可强制全量。
|
|
32
|
+
- 为保证两条路径**逐像素一致**,每个组件在 `render()` 末尾把自身污染过的 `ctx` 全局状态(阴影 / `globalAlpha` / 合成模式 / 虚线等)归位,使组件渲染自包含。
|
|
33
|
+
- 用 golden image 做像素一致性回归(`e2e/visual/dirty-rect-pixel.spec.ts`),覆盖文本、参数化图元、半透明落墨等场景。
|
|
34
|
+
- 配套优化:组件级离屏缓存(含纯平移复用位图)、渲染队列缓存、矩阵零分配。
|
|
35
|
+
**性能数字请以本机 `npm run bench 5000` 的输出为准**(引擎 JS 逻辑开销,不含光栅化):
|
|
36
|
+
2026-09-11 在 Apple Silicon 开发机上实测 **约 2.2ms/帧**(场景 A 静态重绘,5000 图元、多层嵌套)。
|
|
37
|
+
这里刻意不再写一个固定数字 —— 这类数字跨机器可差数倍,写死就会像本文旧版本那样变成不可复现的宣称。
|
|
38
|
+
|
|
39
|
+
**3. 小程序是一等公民**
|
|
40
|
+
|
|
41
|
+
- 一套代码同时面向 **Web 浏览器**与**各类小程序**:所有全局对象访问收敛到 `cross-platform/root` 适配层。
|
|
42
|
+
- **无全局 `Path2D` 的运行时自动降级**:`PolyfillPath2D` 记录路径命令、渲染时重放,与原生 `Path2D` 逐像素一致(老版本小程序基础库可用)。
|
|
43
|
+
- 字体、图片、离屏画布、像素比全部有平台适配(`FontFace` / 小程序 `loadFont`、`Image` / 小程序 `createImage`、`document.createElement('canvas')` / 小程序 `createOffscreenCanvas`、`devicePixelRatio` / 小程序系统信息)。
|
|
44
|
+
- `ICE.init(ctx)` 支持直接传入 Canvas 上下文,完全绕开 DOM。
|
|
45
|
+
|
|
46
|
+
## ✨ 核心特性
|
|
47
|
+
|
|
48
|
+
**架构与组件模型**
|
|
49
|
+
|
|
50
|
+
- **声明式渐变(可序列化)** —— `style.fillGradient` / `style.strokeGradient` 用纯对象描述
|
|
51
|
+
`linear` / `radial` / `conic` 渐变(`{ type, from/to | center/radius | startAngle, stops }`),
|
|
52
|
+
渲染时构造 `CanvasGradient` 并按描述对象引用缓存。与手搓 `CanvasGradient` 的关键差别是
|
|
53
|
+
**能进 JSON**(存盘不丢)且**能写进主题 preset**(随 `setTheme` 重新展开)。
|
|
54
|
+
- **`display: false` 是整棵子树隐藏** —— 隐藏父容器后子组件不再被绘制、也不参与命中
|
|
55
|
+
(判定收敛在 `isEffectivelyVisible()`,渲染/命中/a11y/离屏缓存共用)。
|
|
56
|
+
- **变换手柄支持修改键约束** —— `Shift` 拖角手柄保持宽高比、`Shift` 拖旋转手柄吸附 15°。
|
|
57
|
+
输入层会把 DOM 事件的修饰键显式透传到组件事件(`shiftKey` 是原型上的不可枚举 getter,
|
|
58
|
+
默认拷贝带不过来)。
|
|
59
|
+
- **脏矩形局部重绘在缩放/平移与高分屏下同样生效** —— 脏区按「世界坐标收集、渲染坐标裁剪」
|
|
60
|
+
(`dpr · viewport` 一次换算),并把分散脏区聚合成多块裁剪区,而不是并成一个把干净区域也圈进去的大盒。
|
|
61
|
+
- **零运行时依赖** —— `gl-matrix` 在构建时被**内联**进产物(它只列在 devDependencies,产物里没有任何 `import`/`require`),安装后开箱即用,不需要额外装包。内联的第三方代码保留其许可声明,见 `dist/THIRD-PARTY-NOTICES.txt`。
|
|
62
|
+
- **纯 TypeScript** —— 100% TS 源码,产出完整的 `.d.ts` 类型声明,`tsc --noEmit` 零错误。
|
|
63
|
+
- **React 式组件模型** —— `props`(不可变构造入参)/ `state`(可变运行时状态)分离,`render()` 模板方法 + 清晰的类继承体系。
|
|
64
|
+
- **无限嵌套容器** —— `ICEGroup` 可任意嵌套,形成组件树。
|
|
65
|
+
|
|
66
|
+
**坐标系与变换**
|
|
67
|
+
|
|
68
|
+
- **完整仿射变换** —— 平移 / 缩放 / 旋转 / 错切(skew),基于 `gl-matrix` 的列向量 `mat2d` 约定。
|
|
69
|
+
- **嵌套坐标系** —— 子组件自动复合祖先变换,`localToGlobal` / `globalToLocal` 双向换算;支持在嵌套场景下做全局位移与旋转。
|
|
70
|
+
- **HiDPI** —— `ICE.init(el, { dpr })` 把 backing store 放大到内容盒尺寸 × dpr(默认 1,行为与旧版一致)。
|
|
71
|
+
|
|
72
|
+
**交互与连接线**
|
|
73
|
+
|
|
74
|
+
- **统一输入层** —— 鼠标 / 触控 / 触控笔 / 滚轮收敛到 Pointer 事件族(无 `PointerEvent` 的运行时自动回退 `mouse* + touch*`);完整事件系统(`on/off/once/trigger` 及 W3C 别名),支持拖拽与方向键微调。
|
|
75
|
+
- **变换控制面板** —— 选中组件后出现旋转 / 缩放手柄。
|
|
76
|
+
- **连接线形态可切换** —— 同一套「插槽吸附」之上可选 **Visio 正交折线**(默认)或**普通贝塞尔曲线**
|
|
77
|
+
(`linkShape: 'visio' | 'bezier'`):贝塞尔沿插槽法线出/入,控制点长度随两端距离自适应。
|
|
78
|
+
- **Visio 风格连接线** —— 端点插槽吸附(上 / 右 / 下 / 左 / 中心五个方向),建立组件间的连线关系;
|
|
79
|
+
端点箭头**默认实心**(用线色填充),`arrowStyle: 'hollow'` 可切回空心描边。
|
|
80
|
+
- **视口缩放 / 平移** —— `setViewport()` 与锚点缩放 `zoomAt(screenX, screenY, factor)`;「视图缩放」与「图元缩放」严格分离。
|
|
81
|
+
- **对齐吸附** —— 边缘 / 中心 / 等间距吸附与提示线,默认关闭、按需 `enable()`(零开销)。
|
|
82
|
+
|
|
83
|
+
**扩展与可访问性**
|
|
84
|
+
|
|
85
|
+
- **插件机制** —— `ICE.use(plugin)` 开放三层注册点:自定义图元类型(自动获得 typeId 反查,因此可序列化)、每帧渲染回调、自定义交互工具。
|
|
86
|
+
- **无障碍原语** —— `getAccessibilityTree()` 产出可访问节点快照(角色 / 可读名称 / 屏幕坐标盒 / tab 顺序),`setFocusedComponent()` 让键盘事件派发给焦点组件。**引擎不自建 DOM 镜像层**:镜像结构、ARIA 与文案由应用层决定(参考实现见 `examples/a11y/`)。
|
|
87
|
+
|
|
88
|
+
**序列化与动画**
|
|
89
|
+
|
|
90
|
+
- **整图序列化** —— 组件树可序列化为 JSON 字符串并无损反序列化;类型键用**稳定 typeId**(由构造函数反查注册名,与类的 JS 名解耦,压缩改名不影响已存数据),带 `version` 字段与可扩展迁移表;未注册类型跳过并记录而不是整份数据打不开。自定义组件通过 `registerType()` 注册即可持久化。
|
|
91
|
+
- **关键帧动画** —— 动画配置类似 CSS `keyframes`:单段 `{ from, to, duration }` 或
|
|
92
|
+
多段 `{ keyframes: [{ offset, value, easing? }], duration }`(`easing` 写在段起始帧上,只作用于该段;
|
|
93
|
+
`offset` 缺省按顺序均分、超界夹紧)。内置线性 / 缓入 / 缓出等缓动函数与**弹簧类缓动**
|
|
94
|
+
(`spring` / `springSoft` / `springSnappy`,自带过冲);支持 `delay`、`loop`、`iterationCount`、
|
|
95
|
+
`round`;动画键可为 `'transform.rotate'` 这类**点路径**,取值可为**数组**(`transform.scale` 等逐元素补间)。
|
|
96
|
+
|
|
97
|
+
**性能与工程质量**
|
|
98
|
+
|
|
99
|
+
- **高性能** —— 脏标记 + **脏矩形局部重绘**(默认,不满足局部条件时自动回退全量),配合组件级离屏缓存、渲染队列缓存与矩阵零分配。性能数字以本机 `npm run bench 5000` 为准(2026-09-11 实测约 2.2ms/帧,见上文「性能实测」段)。
|
|
100
|
+
- **完整工程化** —— **80 个测试文件 / 654 个用例**(jest,带「只许上调」的覆盖率门槛)、Playwright 可视化回归(golden-image + 脏矩形像素一致性 + 视口/对齐/交互)、发布包完整性门禁(`publint` + `attw`)、eslint、架构设计文档。
|
|
101
|
+
|
|
102
|
+
## 🚀 快速开始
|
|
103
|
+
|
|
104
|
+
### 浏览器(UMD)
|
|
105
|
+
|
|
106
|
+
```html
|
|
107
|
+
<script src="https://unpkg.com/ice-render/dist/index.umd.js"></script>
|
|
108
|
+
<canvas id="canvas-1" width="1024" height="768"></canvas>
|
|
109
|
+
<script>
|
|
110
|
+
const ice = new ICE.ICE().init('canvas-1');
|
|
111
|
+
|
|
112
|
+
const rect = new ICE.ICERect({
|
|
113
|
+
left: 100, top: 100, width: 50, height: 50,
|
|
114
|
+
style: { strokeStyle: '#ff3300', fillStyle: '#00ff00' },
|
|
115
|
+
});
|
|
116
|
+
ice.addChild(rect);
|
|
117
|
+
</script>
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### npm 安装
|
|
121
|
+
|
|
122
|
+
```shell
|
|
123
|
+
npm i ice-render --save
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
```javascript
|
|
127
|
+
import { ICE, ICERect, ICEGroup } from 'ice-render';
|
|
128
|
+
|
|
129
|
+
const ice = new ICE().init('canvas-1');
|
|
130
|
+
ice.addChild(new ICERect({ width: 100, height: 50 }));
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
发布包提供 **ESM(`dist/index.mjs`)/ CJS(`dist/index.cjs`)/ UMD(`dist/index.umd.js`)** 三种格式。
|
|
134
|
+
|
|
135
|
+
## 📚 文档
|
|
136
|
+
|
|
137
|
+
- **架构设计文档** —— [`docs/architecture/`](./docs/architecture/README.md):运行时链路 / 组件模型 / 坐标系与矩阵 / 渲染性能 / 事件 / 序列化 / 交互动画 / 多运行时兼容。
|
|
138
|
+
- **示例** —— [`examples/`](./examples/index.html) 目录提供 **87 个**可直接在浏览器运行的示例(图形、容器、事件、拖拽、连接线、动画、布局、文本、视口、对齐、插件、无障碍、性能基准等)。
|
|
139
|
+
|
|
140
|
+
## 🧪 工程化
|
|
141
|
+
|
|
142
|
+
| 命令 | 说明 |
|
|
143
|
+
|---|---|
|
|
144
|
+
| `npm test` | 单元测试(jest,镜像 src/ 结构,见 `tests/`) |
|
|
145
|
+
| `npm run test:visual` | Playwright:golden 可视化回归 + 脏矩形局部重绘像素一致性(`dirty-rect-pixel.spec.ts`)+ 真实画布/worker 性能采集 |
|
|
146
|
+
| `npm run lint` / `npm run lint:fix` | 代码检查 / 自动修复 |
|
|
147
|
+
| `npm run types:check` | TypeScript 类型检查 |
|
|
148
|
+
| `npm run bench` | 场景基准(stub ctx,`bench/render.cjs`,改 `src/` 后先 `npm run build`) |
|
|
149
|
+
| `npm run bench:micro` | 微基准(mitata,`bench/micro/`,逐个测矩阵/渲染/命中/状态热函数,防 DCE,需先 `npm run build`) |
|
|
150
|
+
| `npm run pkg:check` | 发布包完整性门禁:`publint`(exports/types/files 契约)+ `attw`(各解析模式下的类型是否正确) |
|
|
151
|
+
| `npm run test:visual:ci` | CI 用的可视化回归子集(示例冒烟 + 交互 + 像素一致性),刻意不含跨平台会漂移的 golden 比对 |
|
|
152
|
+
| `npm run build` | 构建(类型声明 + rollup) |
|
|
153
|
+
|
|
154
|
+
提交前会自动执行 lint-staged(husky);CI 配置在 [`.github/workflows/ci.yml`](./.github/workflows/ci.yml),依次跑 lint + 类型检查 + 单测(含覆盖率门槛)+ 构建 + 包完整性 + 可视化回归。
|
|
155
|
+
|
|
156
|
+
> **主仓在 Gitee**(`https://gitee.com/ice-render/ice-render`,`package.json` 的 `repository` 字段亦然),GitHub 是镜像。徽章不再声称 CI 状态——真正运行 CI 需要有对应的 runner。
|
|
157
|
+
|
|
158
|
+
## 🔧 二次开发
|
|
159
|
+
|
|
160
|
+
基于引擎的类接口即可扩展自定义图元。以 `ice-entity-designer` 中的连线组件为例:
|
|
161
|
+
|
|
162
|
+
```javascript
|
|
163
|
+
import { ICEVisioLink } from 'ice-render';
|
|
164
|
+
|
|
165
|
+
export default class Relation extends ICEVisioLink {
|
|
166
|
+
constructor(props) {
|
|
167
|
+
super({ title: 'Relation', relationType: 'one-to-one', referencedColumnName: 'id', ...props });
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
toEntityObject() {
|
|
171
|
+
const { title, relationType, referencedColumnName } = this.state;
|
|
172
|
+
const resolveEndpoint = (linkKey, prefix) => {
|
|
173
|
+
const id = this.state.links?.[linkKey]?.id;
|
|
174
|
+
if (!id) return {};
|
|
175
|
+
return { [prefix + 'Id']: id, [prefix + 'Name']: this.ice.findComponent(id).state.entityName };
|
|
176
|
+
};
|
|
177
|
+
return {
|
|
178
|
+
title,
|
|
179
|
+
relationType,
|
|
180
|
+
referencedColumnName,
|
|
181
|
+
...resolveEndpoint('start', 'from'),
|
|
182
|
+
...resolveEndpoint('end', 'to'),
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
> [`ice-entity-designer`](https://gitee.com/ice-render/ice-entity-designer) 是一款基于 ICERender 开发的 ER 图设计器,完整示范了引擎的二次开发方式;它已应用于 [`craft-codeless-designer`](https://github.com/craft-codeless-designer) 低代码项目。
|
|
189
|
+
|
|
190
|
+
## 📸 截图
|
|
191
|
+
|
|
192
|
+
> 截图由 `examples/` 下的示例页直接采集(Playwright、2× 像素比、**按内容包围盒裁切**,不含浏览器外壳与页面留白)。
|
|
193
|
+
> 全部 87 个示例都可以在 [`examples/index.html`](./examples/index.html) 里点开运行。
|
|
194
|
+
|
|
195
|
+
**图元与样式** —— 形状库、渐变、阴影、虚线等(`examples/shapes/shapes-basic.html`)
|
|
196
|
+
|
|
197
|
+
<img src="./examples/assets/shot-shapes-basic.png" alt="图元与样式">
|
|
198
|
+
|
|
199
|
+
**卡片 / 网格布局** —— 容器嵌套 + 布局引擎(`examples/layout/dashboard.html`)
|
|
200
|
+
|
|
201
|
+
<img src="./examples/assets/shot-layout-dashboard.png" alt="卡片与网格布局">
|
|
202
|
+
|
|
203
|
+
**Visio 风格连线** —— 端点插槽吸附 + 连线标签(`examples/line-and-link/link-label.html`)
|
|
204
|
+
|
|
205
|
+
<img src="./examples/assets/shot-visio-link-label.png" alt="Visio 风格连线与标签">
|
|
206
|
+
|
|
207
|
+
**嵌套容器** —— `ICEGroup` 任意层级嵌套与坐标复合(`examples/group/group-basic.html`)
|
|
208
|
+
|
|
209
|
+
<img src="./examples/assets/shot-container-nesting.jpg" alt="嵌套容器">
|
|
210
|
+
|
|
211
|
+
**视口缩放 / 平移** —— 视图缩放与图元缩放分离(`examples/viewport/viewport-zoom.html`)
|
|
212
|
+
|
|
213
|
+
<img src="./examples/assets/shot-viewport-zoom.png" alt="视口缩放与平移">
|
|
214
|
+
|
|
215
|
+
**实例级主题** —— 同一页面两套主题互不污染(`examples/theme/theme-multi-instance.html`)
|
|
216
|
+
|
|
217
|
+
<img src="./examples/assets/shot-theme-isolation.png" alt="实例级主题隔离">
|
|
218
|
+
|
|
219
|
+
**插件机制** —— `ICE.use()` 三层注册点(`examples/plugin/plugin-basic.html`)
|
|
220
|
+
|
|
221
|
+
<img src="./examples/assets/shot-plugin.png" alt="插件三层注册点">
|
|
222
|
+
|
|
223
|
+
**极端规模** —— 密集小图元铺满画布;100 万图元构建约 6s、稳态整帧约 1.2s(`examples/performance/max-elements.html`)
|
|
224
|
+
|
|
225
|
+
<img src="./examples/assets/shot-max-elements.jpg" alt="极端规模下的图元密度">
|
|
226
|
+
|
|
227
|
+
## 📄 License
|
|
228
|
+
|
|
229
|
+
[MIT](./LICENSE) © 大漠穷秋
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Name: gl-matrix
|
|
2
|
+
Version: 3.4.3
|
|
3
|
+
License: MIT
|
|
4
|
+
Private: false
|
|
5
|
+
Description: Javascript Matrix and Vector library for High Performance WebGL apps
|
|
6
|
+
Repository: https://github.com/toji/gl-matrix.git
|
|
7
|
+
Homepage: http://glmatrix.net
|
|
8
|
+
Contributors:
|
|
9
|
+
Brandon Jones <tojiro@gmail.com>
|
|
10
|
+
Colin MacKenzie IV <sinisterchipmunk@gmail.com>
|
|
11
|
+
License Copyright:
|
|
12
|
+
===
|
|
13
|
+
|
|
14
|
+
Copyright (c) 2015-2021, Brandon Jones, Colin MacKenzie IV.
|
|
15
|
+
|
|
16
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
17
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
18
|
+
in the Software without restriction, including without limitation the rights
|
|
19
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
20
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
21
|
+
furnished to do so, subject to the following conditions:
|
|
22
|
+
|
|
23
|
+
The above copyright notice and this permission notice shall be included in
|
|
24
|
+
all copies or substantial portions of the Software.
|
|
25
|
+
|
|
26
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
27
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
28
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
29
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
30
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
31
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
32
|
+
THE SOFTWARE.
|