@retikz/vanilla 0.3.0-alpha.5 → 0.3.0-beta.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/dist/es/builder/{isFigure.d.ts → is-figure.d.ts} +1 -1
- package/dist/es/builder/is-figure.d.ts.map +1 -0
- package/dist/es/builder/{isFigure.js → is-figure.js} +1 -1
- package/dist/es/builder/scope.d.ts +1 -1
- package/dist/es/builder/scope.d.ts.map +1 -1
- package/dist/es/builder/scope.js +2 -2
- package/dist/es/builder/types.d.ts +18 -5
- package/dist/es/builder/types.d.ts.map +1 -1
- package/dist/es/builder/types.js +17 -0
- package/dist/es/constants.d.ts +3 -0
- package/dist/es/constants.d.ts.map +1 -0
- package/dist/es/figure.d.ts +6 -4
- package/dist/es/figure.d.ts.map +1 -1
- package/dist/es/figure.js +43 -9
- package/dist/es/index.d.ts +11 -5
- package/dist/es/index.d.ts.map +1 -1
- package/dist/es/index.js +5 -5
- package/dist/{lib/mountCanvas.d.ts → es/mount-canvas.d.ts} +3 -2
- package/dist/es/mount-canvas.d.ts.map +1 -0
- package/dist/es/{mountCanvas.js → mount-canvas.js} +103 -26
- package/dist/es/{mountSvg.d.ts → mount-svg.d.ts} +1 -1
- package/dist/es/mount-svg.d.ts.map +1 -0
- package/dist/es/{mountSvg.js → mount-svg.js} +20 -17
- package/dist/{lib/renderToSvgString.d.ts → es/render-to-svg-string.d.ts} +3 -2
- package/dist/es/render-to-svg-string.d.ts.map +1 -0
- package/dist/es/render-to-svg-string.js +23 -0
- package/dist/es/{svgNodeToDom.d.ts → svg-node-to-dom.d.ts} +1 -1
- package/dist/es/svg-node-to-dom.d.ts.map +1 -0
- package/dist/es/{svgNodeToDom.js → svg-node-to-dom.js} +1 -1
- package/dist/es/{toScene.d.ts → to-scene.d.ts} +1 -1
- package/dist/es/to-scene.d.ts.map +1 -0
- package/dist/es/{toScene.js → to-scene.js} +1 -1
- package/dist/es/types.d.ts +2 -2
- package/dist/es/types.d.ts.map +1 -1
- package/dist/lib/builder/{isFigure.cjs → is-figure.cjs} +1 -1
- package/dist/lib/builder/{isFigure.d.ts → is-figure.d.ts} +1 -1
- package/dist/lib/builder/is-figure.d.ts.map +1 -0
- package/dist/lib/builder/scope.cjs +2 -2
- package/dist/lib/builder/scope.d.ts +1 -1
- package/dist/lib/builder/scope.d.ts.map +1 -1
- package/dist/lib/builder/types.cjs +17 -0
- package/dist/lib/builder/types.d.ts +18 -5
- package/dist/lib/builder/types.d.ts.map +1 -1
- package/dist/lib/constants.d.ts +3 -0
- package/dist/lib/constants.d.ts.map +1 -0
- package/dist/lib/figure.cjs +47 -13
- package/dist/lib/figure.d.ts +6 -4
- package/dist/lib/figure.d.ts.map +1 -1
- package/dist/lib/index.cjs +30 -6
- package/dist/lib/index.d.ts +11 -5
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/{mountCanvas.cjs → mount-canvas.cjs} +104 -27
- package/dist/{es/mountCanvas.d.ts → lib/mount-canvas.d.ts} +3 -2
- package/dist/lib/mount-canvas.d.ts.map +1 -0
- package/dist/lib/{mountSvg.cjs → mount-svg.cjs} +24 -21
- package/dist/lib/{mountSvg.d.ts → mount-svg.d.ts} +1 -1
- package/dist/lib/mount-svg.d.ts.map +1 -0
- package/dist/lib/render-to-svg-string.cjs +23 -0
- package/dist/{es/renderToSvgString.d.ts → lib/render-to-svg-string.d.ts} +3 -2
- package/dist/lib/render-to-svg-string.d.ts.map +1 -0
- package/dist/lib/{svgNodeToDom.cjs → svg-node-to-dom.cjs} +1 -1
- package/dist/lib/{svgNodeToDom.d.ts → svg-node-to-dom.d.ts} +1 -1
- package/dist/lib/svg-node-to-dom.d.ts.map +1 -0
- package/dist/lib/{toScene.cjs → to-scene.cjs} +1 -1
- package/dist/lib/{toScene.d.ts → to-scene.d.ts} +1 -1
- package/dist/lib/to-scene.d.ts.map +1 -0
- package/dist/lib/types.d.ts +2 -2
- package/dist/lib/types.d.ts.map +1 -1
- package/package.json +5 -6
- package/dist/es/builder/isFigure.d.ts.map +0 -1
- package/dist/es/mountCanvas.d.ts.map +0 -1
- package/dist/es/mountSvg.d.ts.map +0 -1
- package/dist/es/renderToSvgString.d.ts.map +0 -1
- package/dist/es/renderToSvgString.js +0 -28
- package/dist/es/svgNodeToDom.d.ts.map +0 -1
- package/dist/es/toScene.d.ts.map +0 -1
- package/dist/lib/builder/isFigure.d.ts.map +0 -1
- package/dist/lib/mountCanvas.d.ts.map +0 -1
- package/dist/lib/mountSvg.d.ts.map +0 -1
- package/dist/lib/renderToSvgString.cjs +0 -28
- package/dist/lib/renderToSvgString.d.ts.map +0 -1
- package/dist/lib/svgNodeToDom.d.ts.map +0 -1
- package/dist/lib/toScene.d.ts.map +0 -1
|
@@ -3,4 +3,4 @@ import { Figure } from '../figure';
|
|
|
3
3
|
export declare const FIGURE_BRAND: unique symbol;
|
|
4
4
|
/** 运行时判断一个值是不是 Figure(带 brand);纯结构检查、零内部 import → 不与 mountSvg/Figure 形成运行时环 */
|
|
5
5
|
export declare const isFigure: (value: unknown) => value is Figure;
|
|
6
|
-
//# sourceMappingURL=
|
|
6
|
+
//# sourceMappingURL=is-figure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-figure.d.ts","sourceRoot":"","sources":["../../../src/builder/is-figure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAExC,oGAAoG;AACpG,eAAO,MAAM,YAAY,EAAE,OAAO,MAA4C,CAAC;AAE/E,+EAA+E;AAC/E,eAAO,MAAM,QAAQ,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MACuD,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region src/builder/
|
|
1
|
+
//#region src/builder/is-figure.ts
|
|
2
2
|
/** Figure 品牌标记(Symbol.for 跨包/重复 import 仍同一);标准 mountSvg/renderToSvgString 用它区分 Figure 与 IR/Scene */
|
|
3
3
|
var FIGURE_BRAND = Symbol.for("retikz.vanilla.figure");
|
|
4
4
|
/** 运行时判断一个值是不是 Figure(带 brand);纯结构检查、零内部 import → 不与 mountSvg/Figure 形成运行时环 */
|
|
@@ -11,7 +11,7 @@ export type ScopeBuilder = {
|
|
|
11
11
|
node: (...args: Parameters<typeof node>) => ScopeBuilder;
|
|
12
12
|
draw: (...args: Parameters<typeof draw>) => ScopeBuilder;
|
|
13
13
|
coordinate: (...args: Parameters<typeof coordinate>) => ScopeBuilder;
|
|
14
|
-
scope: (config: ScopeConfig,
|
|
14
|
+
scope: (config: ScopeConfig, arg: Array<Child> | ((s: ScopeBuilder) => void)) => ScopeBuilder;
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
17
|
* 构造一个 scope IR 子节点(分组容器 + 样式默认 + transforms)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../../src/builder/scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAElD;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,IAAI,CAAC,KAAK,YAAY,CAAC;IACzD,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,IAAI,CAAC,KAAK,YAAY,CAAC;IACzD,UAAU,EAAE,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,KAAK,YAAY,CAAC;IACrE,KAAK,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../../src/builder/scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAElD;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,IAAI,CAAC,KAAK,YAAY,CAAC;IACzD,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,IAAI,CAAC,KAAK,YAAY,CAAC;IACzD,UAAU,EAAE,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,KAAK,YAAY,CAAC;IACrE,KAAK,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,YAAY,KAAK,IAAI,CAAC,KAAK,YAAY,CAAC;CAC/F,CAAC;AAwBF;;;;;GAKG;AACH,eAAO,MAAM,KAAK,GAAI,QAAQ,WAAW,EAAE,KAAK,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,YAAY,KAAK,IAAI,CAAC,KAAG,KAS5F,CAAC"}
|
package/dist/es/builder/scope.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CompileOptions, IRChild, IRCoordinate, IRNode, IRPath, IRScope, IRViewBox, WayDSL } from '@retikz/core';
|
|
1
|
+
import { CompileOptions, IRAnimationTrack, IRChild, IRCoordinate, IRNode, IRPath, IRScope, IRViewBox, WayDSL } from '@retikz/core';
|
|
2
2
|
/** builder 函数返回的 IR 子节点(node / draw / coordinate / scope 的产物) */
|
|
3
3
|
export type Child = IRChild;
|
|
4
4
|
/** node 的 config:从 IRNode 派生,剔除判别符 type 与提为 positional 的 id */
|
|
@@ -11,16 +11,29 @@ export type CoordinateConfig = Omit<IRCoordinate, 'type' | 'id'>;
|
|
|
11
11
|
export type ScopeConfig = Omit<IRScope, 'type' | 'children'>;
|
|
12
12
|
/** draw 的 way:直接复用 core 的 way DSL 全集(id 串 / 坐标 / Cycle / 折角 / 相对 / 曲线 / 弧 …) */
|
|
13
13
|
export type Way = WayDSL;
|
|
14
|
+
/**
|
|
15
|
+
* figure 根级级联样式默认(与 React `<Layout>` 顶层样式 props 对齐)
|
|
16
|
+
* @description 取 `IRScope` 的级联样式通道(graphic state + 四通道 every-X),**不含**容器 / 命名空间 / 变换 /
|
|
17
|
+
* 屏障 / 栈序 / 裁剪字段(那些挂在 figure 根上语义易混)。组 IR 时若任一字段携带样式指令,把根 children 包进
|
|
18
|
+
* 一层合成根 `<Scope>`,等价于用户手写一层根 scope;全缺省时不包,IR 形态逐字保持。
|
|
19
|
+
*/
|
|
20
|
+
export type FigureRootStyle = Pick<IRScope, 'color' | 'stroke' | 'fill' | 'strokeWidth' | 'opacity' | 'fillOpacity' | 'drawOpacity' | 'nodeDefault' | 'pathDefault' | 'labelDefault' | 'arrowDefault'>;
|
|
21
|
+
/** {@link FigureRootStyle} 的字段表——`figure.ts` 组 IR 时拣根样式 + 从 render options 剔除(IR-only 字段不下发) */
|
|
22
|
+
export declare const FIGURE_ROOT_STYLE_FIELDS: readonly ["color", "stroke", "fill", "strokeWidth", "opacity", "fillOpacity", "drawOpacity", "nodeDefault", "pathDefault", "labelDefault", "arrowDefault"];
|
|
14
23
|
/**
|
|
15
24
|
* figure 的 config
|
|
16
|
-
* @description `viewBox` → IR.viewBox(内容坐标系);`
|
|
17
|
-
* `idPrefix` → SVG 资源 id
|
|
18
|
-
*
|
|
25
|
+
* @description `viewBox` → IR.viewBox(内容坐标系);`animations` → IR 根 `animations`(镜头时间轴,配 cameraTo
|
|
26
|
+
* preset);`width`/`height` → 根 `<svg>` 显示尺寸(adapter 职责);`idPrefix` → SVG 资源 id 前缀;根级级联样式
|
|
27
|
+
* (color / nodeDefault / pathDefault / labelDefault / arrowDefault 等)按需包合成根 `<Scope>`;其余(measureText /
|
|
28
|
+
* shapes / arrows / patterns / pathGenerators / padding / precision / nodeDistance / onWarn)派生自 core
|
|
29
|
+
* `CompileOptions`、原样喂 compileToScene。
|
|
19
30
|
*/
|
|
20
31
|
export type FigureConfig = {
|
|
21
32
|
width?: number;
|
|
22
33
|
height?: number;
|
|
23
34
|
viewBox?: IRViewBox;
|
|
24
35
|
idPrefix?: string;
|
|
25
|
-
|
|
36
|
+
/** scene 根(镜头)时间轴动画 tracks(`viewBox` property,配 `cameraTo()` preset);注入 IR 根 `animations` */
|
|
37
|
+
animations?: Array<IRAnimationTrack>;
|
|
38
|
+
} & FigureRootStyle & CompileOptions;
|
|
26
39
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/builder/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,OAAO,EACP,YAAY,EACZ,MAAM,EACN,MAAM,EACN,OAAO,EACP,SAAS,EACT,MAAM,EACP,MAAM,cAAc,CAAC;AAEtB,iEAAiE;AACjE,MAAM,MAAM,KAAK,GAAG,OAAO,CAAC;AAE5B,+DAA+D;AAC/D,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;AAErD,mEAAmE;AACnE,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC;AAE3D,qFAAqF;AACrF,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;AAEjE,8EAA8E;AAC9E,MAAM,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,EAAE,MA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ChG,eAAO,MAAM,wBAAwB,4JAYoB,CAAC;AAE1D;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6FAA6F;IAC7F,UAAU,CAAC,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC;CACtC,GAAG,eAAe,GACjB,cAAc,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/builder/types.ts
|
|
2
|
+
/** {@link FigureRootStyle} 的字段表——`figure.ts` 组 IR 时拣根样式 + 从 render options 剔除(IR-only 字段不下发) */
|
|
3
|
+
var FIGURE_ROOT_STYLE_FIELDS = [
|
|
4
|
+
"color",
|
|
5
|
+
"stroke",
|
|
6
|
+
"fill",
|
|
7
|
+
"strokeWidth",
|
|
8
|
+
"opacity",
|
|
9
|
+
"fillOpacity",
|
|
10
|
+
"drawOpacity",
|
|
11
|
+
"nodeDefault",
|
|
12
|
+
"pathDefault",
|
|
13
|
+
"labelDefault",
|
|
14
|
+
"arrowDefault"
|
|
15
|
+
];
|
|
16
|
+
//#endregion
|
|
17
|
+
export { FIGURE_ROOT_STYLE_FIELDS };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,4HAA4H;AAC5H,eAAO,MAAM,iBAAiB,MAAM,CAAC"}
|
package/dist/es/figure.d.ts
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
import { IR } from '@retikz/core';
|
|
2
2
|
import { RenderOptions } from '@retikz/render/canvas';
|
|
3
|
-
import { FIGURE_BRAND } from './builder/
|
|
3
|
+
import { FIGURE_BRAND } from './builder/is-figure';
|
|
4
4
|
import { node } from './builder/node';
|
|
5
5
|
import { ScopeBuilder } from './builder/scope';
|
|
6
6
|
import { Child, CoordinateConfig, DrawConfig, FigureConfig, ScopeConfig, Way } from './builder/types';
|
|
7
|
-
import { MountOptions, RenderToStringOptions, VanillaView } from './types';
|
|
7
|
+
import { CanvasView, MountCanvasOptions, MountOptions, RenderToStringOptions, VanillaView } from './types';
|
|
8
8
|
/**
|
|
9
9
|
* 命令式 builder 的装配产物 —— 唯一返回类型
|
|
10
10
|
* @description hyperscript(`figure(config, children)`)与 fluent(`figure(config).node(...)`)都产它、可混用、`.ir` 一致。
|
|
11
|
-
* `.mount`/`.toSvgString`/`.toCanvas
|
|
11
|
+
* `.mount`/`.mountCanvas`(交互式挂载)/`.toSvgString`/`.toCanvas`(一次性产出)把 `this.ir`(IR,非 Figure)交底层
|
|
12
|
+
* renderer;fluent 方法往内部 children 追加、链式返回 this。
|
|
12
13
|
*/
|
|
13
14
|
export type Figure = {
|
|
14
15
|
readonly [FIGURE_BRAND]: true;
|
|
15
16
|
readonly ir: IR;
|
|
16
17
|
mount: (container: Element, options?: MountOptions) => VanillaView;
|
|
18
|
+
mountCanvas: (container: Element, options?: MountCanvasOptions) => CanvasView;
|
|
17
19
|
toSvgString: (options?: RenderToStringOptions) => string;
|
|
18
20
|
toCanvas: (canvas: HTMLCanvasElement, options?: RenderOptions) => void;
|
|
19
21
|
node: (...args: Parameters<typeof node>) => Figure;
|
|
20
22
|
draw: (way: Way, config?: DrawConfig) => Figure;
|
|
21
23
|
coordinate: (id: string, config: CoordinateConfig) => Figure;
|
|
22
|
-
scope: (config: ScopeConfig,
|
|
24
|
+
scope: (config: ScopeConfig, arg: Array<Child> | ((s: ScopeBuilder) => void)) => Figure;
|
|
23
25
|
};
|
|
24
26
|
/** figure() 的内部入口:装配 Figure(持 config + children,方法闭包其上) */
|
|
25
27
|
export declare const createFigure: (config: FigureConfig, children: Array<Child>) => Figure;
|
package/dist/es/figure.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fig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AO,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;IACvE,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,IAAI,CAAC,KAAK,MAAM,CAAC;IACnD,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,UAAU,KAAK,MAAM,CAAC;IAChD,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,KAAK,MAAM,CAAC;IAC7D,KAAK,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,YAAY,KAAK,IAAI,CAAC,KAAK,MAAM,CAAC;CACzF,CAAC;AAoBF,2DAA2D;AAC3D,eAAO,MAAM,YAAY,GAAI,QAAQ,YAAY,EAAE,UAAU,KAAK,CAAC,KAAK,CAAC,KAAG,MAoE3E,CAAC"}
|
package/dist/es/figure.js
CHANGED
|
@@ -1,37 +1,69 @@
|
|
|
1
|
-
import { FIGURE_BRAND } from "./builder/
|
|
2
|
-
import { toScene } from "./
|
|
3
|
-
import { renderToSvgString } from "./
|
|
4
|
-
import { mountSvg } from "./
|
|
1
|
+
import { FIGURE_BRAND } from "./builder/is-figure.js";
|
|
2
|
+
import { toScene } from "./to-scene.js";
|
|
3
|
+
import { renderToSvgString } from "./render-to-svg-string.js";
|
|
4
|
+
import { mountSvg } from "./mount-svg.js";
|
|
5
|
+
import { mountCanvas } from "./mount-canvas.js";
|
|
5
6
|
import { coordinate } from "./builder/coordinate.js";
|
|
6
7
|
import { draw } from "./builder/draw.js";
|
|
7
8
|
import { node } from "./builder/node.js";
|
|
8
9
|
import { scope } from "./builder/scope.js";
|
|
10
|
+
import { FIGURE_ROOT_STYLE_FIELDS } from "./builder/types.js";
|
|
9
11
|
import { renderToCanvas } from "@retikz/render/canvas";
|
|
10
12
|
//#region src/figure.ts
|
|
13
|
+
/**
|
|
14
|
+
* 拣出真正携带样式指令的根样式字段
|
|
15
|
+
* @description 在「取 defined」基础上剔除空对象的四通道 default(`nodeDefault: {}` 等)——空 default 无样式指令,
|
|
16
|
+
* 留着只会让 figure 无谓包一层空合成根 `<Scope>`、改变 IR / Scene 拓扑却无视觉差异。标量通道的 falsy-但-defined
|
|
17
|
+
* 值(`strokeWidth: 0` / `opacity: 0`)是有意义样式、保留(镜像 react `pickScopeStyle`)。
|
|
18
|
+
*/
|
|
19
|
+
var pickRootStyle = (config) => {
|
|
20
|
+
const picked = {};
|
|
21
|
+
for (const key of FIGURE_ROOT_STYLE_FIELDS) {
|
|
22
|
+
const value = config[key];
|
|
23
|
+
if (value === void 0) continue;
|
|
24
|
+
if (typeof value === "object" && Object.keys(value).length === 0) continue;
|
|
25
|
+
Object.assign(picked, { [key]: value });
|
|
26
|
+
}
|
|
27
|
+
return picked;
|
|
28
|
+
};
|
|
11
29
|
/** figure() 的内部入口:装配 Figure(持 config + children,方法闭包其上) */
|
|
12
30
|
var createFigure = (config, children) => {
|
|
13
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* call-site options 覆盖 figure 存的 config(call-site wins):viewBox / animations / 根样式已并进 ir,
|
|
33
|
+
* 这些 IR-only 字段从下发的 render options 剔除;其余(width/height/idPrefix + 全套 CompileOptions)全透传。
|
|
34
|
+
*/
|
|
14
35
|
const renderOptions = (callSite) => {
|
|
15
36
|
const merged = {
|
|
16
37
|
...config,
|
|
17
38
|
...callSite
|
|
18
39
|
};
|
|
19
40
|
delete merged.viewBox;
|
|
41
|
+
delete merged.animations;
|
|
42
|
+
for (const key of FIGURE_ROOT_STYLE_FIELDS) delete merged[key];
|
|
20
43
|
return merged;
|
|
21
44
|
};
|
|
22
45
|
const fig = {
|
|
23
46
|
[FIGURE_BRAND]: true,
|
|
24
47
|
get ir() {
|
|
48
|
+
const rootStyle = pickRootStyle(config);
|
|
25
49
|
return {
|
|
26
50
|
version: 1,
|
|
27
51
|
type: "scene",
|
|
28
|
-
children
|
|
29
|
-
|
|
52
|
+
children: Object.keys(rootStyle).length > 0 ? [{
|
|
53
|
+
type: "scope",
|
|
54
|
+
...rootStyle,
|
|
55
|
+
children
|
|
56
|
+
}] : children,
|
|
57
|
+
...config.viewBox ? { viewBox: config.viewBox } : {},
|
|
58
|
+
...config.animations ? { animations: config.animations } : {}
|
|
30
59
|
};
|
|
31
60
|
},
|
|
32
61
|
mount(container, options) {
|
|
33
62
|
return mountSvg(container, fig.ir, renderOptions(options));
|
|
34
63
|
},
|
|
64
|
+
mountCanvas(container, options) {
|
|
65
|
+
return mountCanvas(container, fig.ir, renderOptions(options));
|
|
66
|
+
},
|
|
35
67
|
toSvgString(options) {
|
|
36
68
|
return renderToSvgString(fig.ir, renderOptions(options));
|
|
37
69
|
},
|
|
@@ -41,6 +73,8 @@ var createFigure = (config, children) => {
|
|
|
41
73
|
delete compile.idPrefix;
|
|
42
74
|
delete compile.width;
|
|
43
75
|
delete compile.height;
|
|
76
|
+
delete compile.animations;
|
|
77
|
+
for (const key of FIGURE_ROOT_STYLE_FIELDS) delete compile[key];
|
|
44
78
|
renderToCanvas(canvas, toScene(fig.ir, compile), options ?? {});
|
|
45
79
|
},
|
|
46
80
|
node(...args) {
|
|
@@ -55,8 +89,8 @@ var createFigure = (config, children) => {
|
|
|
55
89
|
children.push(coordinate(id, coordConfig));
|
|
56
90
|
return fig;
|
|
57
91
|
},
|
|
58
|
-
scope(scopeConfig,
|
|
59
|
-
children.push(scope(scopeConfig,
|
|
92
|
+
scope(scopeConfig, arg) {
|
|
93
|
+
children.push(scope(scopeConfig, arg));
|
|
60
94
|
return fig;
|
|
61
95
|
}
|
|
62
96
|
};
|
package/dist/es/index.d.ts
CHANGED
|
@@ -6,13 +6,19 @@
|
|
|
6
6
|
* `figure`/`node`/`draw`/`coordinate`/`scope` 是命令式 builder:用具名图元 + 自定义 shape 构图、产同一份 IR。
|
|
7
7
|
* 模块顶层不触碰任何 DOM 全局——`import` 在纯 Node 下安全。
|
|
8
8
|
*/
|
|
9
|
-
export { renderToSvgString } from './
|
|
10
|
-
export { mountSvg } from './
|
|
9
|
+
export { renderToSvgString } from './render-to-svg-string';
|
|
10
|
+
export { mountSvg } from './mount-svg';
|
|
11
11
|
export { hydrate } from './hydrate';
|
|
12
|
-
export { mountCanvas } from './
|
|
13
|
-
export type {
|
|
12
|
+
export { mountCanvas } from './mount-canvas';
|
|
13
|
+
export type { RetikzEventValue, HydrationHandlers, HydrationHandler, HydrationContext, HydrationAnimationControls, HydrationGeometry, } from '@retikz/render/hydration';
|
|
14
14
|
export { fadeIn, drawOn, scaleIn, grow, growUp, slideIn, colorShift, cameraTo, pulse, spin, loop, flash, blink, wiggle, stagger, } from '@retikz/core';
|
|
15
15
|
export type { AnimationPresetOptions, ScaleInOptions, GrowUpOptions, SlideInOptions, ColorShiftOptions, CameraToOptions, PulseOptions, SpinOptions, LoopOptions, FlashOptions, BlinkOptions, WiggleOptions, } from '@retikz/core';
|
|
16
|
+
export { DrawWay } from '@retikz/core';
|
|
17
|
+
export type { WayItem, WayDSL, WayCycle, WayVia, WayRelativeItem, WayLabel, WayLabelOp, } from '@retikz/core';
|
|
18
|
+
export type { IRNodeTarget, IRAnchorRef } from '@retikz/core';
|
|
19
|
+
export { defineArrow, definePattern, definePathGenerator } from '@retikz/core';
|
|
20
|
+
export type { ArrowDefinition, ArrowEmitContext, PatternDefinition, PatternEmitContext, MarkerPrimitive, MarkerFill, PathGeneratorDefinition, PathGeneratorContext, IRJsonObject, } from '@retikz/core';
|
|
21
|
+
export type { AnimationPropertyDefinition, AnimationPropertyRegistry, CubicBezier, EasingFn, EasingRegistry, } from '@retikz/render/animation';
|
|
16
22
|
export { figure } from './builder/figure';
|
|
17
23
|
export { node } from './builder/node';
|
|
18
24
|
export { draw } from './builder/draw';
|
|
@@ -20,6 +26,6 @@ export { coordinate } from './builder/coordinate';
|
|
|
20
26
|
export { scope } from './builder/scope';
|
|
21
27
|
export type { Figure } from './figure';
|
|
22
28
|
export type { ScopeBuilder } from './builder/scope';
|
|
23
|
-
export type { Child, NodeConfig, DrawConfig, CoordinateConfig, ScopeConfig, FigureConfig, Way, } from './builder/types';
|
|
29
|
+
export type { Child, NodeConfig, DrawConfig, CoordinateConfig, ScopeConfig, FigureConfig, FigureRootStyle, Way, } from './builder/types';
|
|
24
30
|
export type { RenderInput, CommonOptions, MountOptions, RenderToStringOptions, VanillaView, CanvasView, MountCanvasOptions, HydrateOptions, HydrationHandle, ScenePoint, AnimationControls, } from './types';
|
|
25
31
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/es/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,YAAY,EACV,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,0BAA0B,EAC1B,iBAAiB,GAClB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,MAAM,EACN,MAAM,EACN,OAAO,EACP,IAAI,EACJ,MAAM,EACN,OAAO,EACP,UAAU,EACV,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,KAAK,EACL,MAAM,EACN,OAAO,GACR,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,sBAAsB,EACtB,cAAc,EACd,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,eAAe,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c,EACd,eAAe,EACf,UAAU,EACV,iBAAiB,GAClB,MAAM,SAAS,CAAC"}
|
package/dist/es/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { renderToSvgString } from "./
|
|
2
|
-
import { mountSvg } from "./
|
|
1
|
+
import { renderToSvgString } from "./render-to-svg-string.js";
|
|
2
|
+
import { mountSvg } from "./mount-svg.js";
|
|
3
3
|
import { hydrate } from "./hydrate.js";
|
|
4
|
-
import { mountCanvas } from "./
|
|
4
|
+
import { mountCanvas } from "./mount-canvas.js";
|
|
5
5
|
import { coordinate } from "./builder/coordinate.js";
|
|
6
6
|
import { draw } from "./builder/draw.js";
|
|
7
7
|
import { node } from "./builder/node.js";
|
|
8
8
|
import { scope } from "./builder/scope.js";
|
|
9
9
|
import { figure } from "./builder/figure.js";
|
|
10
|
-
import { blink, cameraTo, colorShift, drawOn, fadeIn, flash, grow, growUp, loop, pulse, scaleIn, slideIn, spin, stagger, wiggle } from "@retikz/core";
|
|
11
|
-
export { blink, cameraTo, colorShift, coordinate, draw, drawOn, fadeIn, figure, flash, grow, growUp, hydrate, loop, mountCanvas, mountSvg, node, pulse, renderToSvgString, scaleIn, scope, slideIn, spin, stagger, wiggle };
|
|
10
|
+
import { DrawWay, blink, cameraTo, colorShift, defineArrow, definePathGenerator, definePattern, drawOn, fadeIn, flash, grow, growUp, loop, pulse, scaleIn, slideIn, spin, stagger, wiggle } from "@retikz/core";
|
|
11
|
+
export { DrawWay, blink, cameraTo, colorShift, coordinate, defineArrow, definePathGenerator, definePattern, draw, drawOn, fadeIn, figure, flash, grow, growUp, hydrate, loop, mountCanvas, mountSvg, node, pulse, renderToSvgString, scaleIn, scope, slideIn, spin, stagger, wiggle };
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { CanvasView, MountCanvasOptions, RenderInput } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* 把 IR / Scene / Figure 挂成真实 `<canvas>` DOM(无框架浏览器 runtime,对齐 `mountSvg`)
|
|
4
|
-
* @description 收
|
|
4
|
+
* @description 收 `Figure` 时 delegate 给 `figure.mountCanvas`(与 mountSvg→`figure.mount` 对称)。收 IR 时
|
|
5
|
+
* `toScene` compile、收 Scene 直用。位图按「名义显示尺寸」
|
|
5
6
|
* `width`/`height`(均为有限数值时)× dpr 开、否则回退内容边界;`renderToCanvas` 再把 Scene 内容 meet-fit
|
|
6
7
|
* 进去(镜像 SVG `preserveAspectRatio=meet` + CanvasHost)。返回的 `CanvasView` 暴露 `hydrate`(hitTest 定位)
|
|
7
8
|
* 与 `clientToScene`(逆 meet-fit 坐标映射)。DOM 仅在调用时惰性触碰,`import` 本模块不碰 DOM——守 SSR 导入安全。
|
|
8
9
|
*/
|
|
9
10
|
export declare const mountCanvas: (container: Element, input: RenderInput, options?: MountCanvasOptions) => CanvasView;
|
|
10
|
-
//# sourceMappingURL=
|
|
11
|
+
//# sourceMappingURL=mount-canvas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mount-canvas.d.ts","sourceRoot":"","sources":["../../src/mount-canvas.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,UAAU,EAAkB,kBAAkB,EAAE,WAAW,EAAc,MAAM,SAAS,CAAC;AASvG;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,GACtB,WAAW,OAAO,EAClB,OAAO,WAAW,EAClB,UAAS,kBAAuB,KAC/B,UA4PF,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { isFigure } from "./builder/
|
|
2
|
-
import { toScene } from "./
|
|
1
|
+
import { isFigure } from "./builder/is-figure.js";
|
|
2
|
+
import { toScene } from "./to-scene.js";
|
|
3
3
|
import { createClock, createIdClockRegistry, prefersReducedMotion, sceneAnimationDurationMs, sceneHasAnimations, sceneHasAutoplayTrigger } from "@retikz/render/animation";
|
|
4
|
-
import { createCanvasIdAnimationControls, createHydrationController,
|
|
4
|
+
import { collectCanvasVisibleAnimationIds, createCanvasIdAnimationControls, createContextBuilder, createHydrationController, isCanvasAnimationIdVisible, withCanvasAnimationEventHandlers } from "@retikz/render/hydration";
|
|
5
5
|
import { hitTest, renderToCanvas } from "@retikz/render/canvas";
|
|
6
|
-
//#region src/
|
|
6
|
+
//#region src/mount-canvas.ts
|
|
7
7
|
/** 设备像素比:取有限正数、否则回退 1(镜像 react CanvasHost) */
|
|
8
8
|
var resolveDevicePixelRatio = (override) => {
|
|
9
9
|
if (typeof override === "number" && Number.isFinite(override) && override > 0) return override;
|
|
@@ -12,19 +12,24 @@ var resolveDevicePixelRatio = (override) => {
|
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
14
|
* 把 IR / Scene / Figure 挂成真实 `<canvas>` DOM(无框架浏览器 runtime,对齐 `mountSvg`)
|
|
15
|
-
* @description 收
|
|
15
|
+
* @description 收 `Figure` 时 delegate 给 `figure.mountCanvas`(与 mountSvg→`figure.mount` 对称)。收 IR 时
|
|
16
|
+
* `toScene` compile、收 Scene 直用。位图按「名义显示尺寸」
|
|
16
17
|
* `width`/`height`(均为有限数值时)× dpr 开、否则回退内容边界;`renderToCanvas` 再把 Scene 内容 meet-fit
|
|
17
18
|
* 进去(镜像 SVG `preserveAspectRatio=meet` + CanvasHost)。返回的 `CanvasView` 暴露 `hydrate`(hitTest 定位)
|
|
18
19
|
* 与 `clientToScene`(逆 meet-fit 坐标映射)。DOM 仅在调用时惰性触碰,`import` 本模块不碰 DOM——守 SSR 导入安全。
|
|
19
20
|
*/
|
|
20
21
|
var mountCanvas = (container, input, options = {}) => {
|
|
22
|
+
if (isFigure(input)) return input.mountCanvas(container, options);
|
|
21
23
|
if (typeof Element === "undefined" || !(container instanceof Element)) throw new Error("mountCanvas: container must be a DOM Element.");
|
|
22
24
|
const canvas = document.createElement("canvas");
|
|
23
25
|
const ratio = resolveDevicePixelRatio(options.devicePixelRatio);
|
|
24
26
|
const animate = options.animate !== false && !prefersReducedMotion();
|
|
25
27
|
let clock;
|
|
26
28
|
const registry = createIdClockRegistry();
|
|
29
|
+
let visibleActivated = /* @__PURE__ */ new Set();
|
|
30
|
+
let visibleTeardown;
|
|
27
31
|
let currentScene;
|
|
32
|
+
const liveHydrations = /* @__PURE__ */ new Set();
|
|
28
33
|
/** 把全局帧时刻折算成单个 prim 的动画解析(per-id):stop→渲染 base;否则按有效时刻 + 是否含非自动播 track */
|
|
29
34
|
const resolvePrim = (id, globalTime) => id !== void 0 && registry.isStopped(id) ? { mode: "skip" } : {
|
|
30
35
|
mode: "at",
|
|
@@ -42,6 +47,49 @@ var mountCanvas = (container, input, options = {}) => {
|
|
|
42
47
|
resolvePrimAnimation: (id) => resolvePrim(id, time)
|
|
43
48
|
});
|
|
44
49
|
};
|
|
50
|
+
const ensureClockPlaying = () => {
|
|
51
|
+
clock?.play();
|
|
52
|
+
};
|
|
53
|
+
/** Canvas visible trigger:按 canvas client rect 与 id 聚合 bbox 相交激活一次 */
|
|
54
|
+
const activateVisibleTracks = () => {
|
|
55
|
+
const ids = collectCanvasVisibleAnimationIds(currentScene);
|
|
56
|
+
if (ids.size === 0) return;
|
|
57
|
+
let changed = false;
|
|
58
|
+
for (const id of ids) {
|
|
59
|
+
if (visibleActivated.has(id)) continue;
|
|
60
|
+
if (!isCanvasAnimationIdVisible(canvas, currentScene, id)) continue;
|
|
61
|
+
registry.restart(id, clock?.time ?? 0);
|
|
62
|
+
visibleActivated.add(id);
|
|
63
|
+
changed = true;
|
|
64
|
+
}
|
|
65
|
+
if (!changed) return;
|
|
66
|
+
ensureClockPlaying();
|
|
67
|
+
renderFrame();
|
|
68
|
+
};
|
|
69
|
+
const resetVisibleBridge = () => {
|
|
70
|
+
visibleActivated = /* @__PURE__ */ new Set();
|
|
71
|
+
visibleTeardown?.();
|
|
72
|
+
visibleTeardown = void 0;
|
|
73
|
+
if (!animate || !sceneHasAnimations(currentScene)) return;
|
|
74
|
+
if (collectCanvasVisibleAnimationIds(currentScene).size === 0 || typeof window === "undefined") return;
|
|
75
|
+
let scheduledRaf;
|
|
76
|
+
const runScheduled = () => {
|
|
77
|
+
scheduledRaf = void 0;
|
|
78
|
+
activateVisibleTracks();
|
|
79
|
+
};
|
|
80
|
+
const schedule = () => {
|
|
81
|
+
if (scheduledRaf !== void 0) return;
|
|
82
|
+
scheduledRaf = window.requestAnimationFrame(runScheduled);
|
|
83
|
+
};
|
|
84
|
+
window.addEventListener("scroll", schedule, true);
|
|
85
|
+
window.addEventListener("resize", schedule);
|
|
86
|
+
schedule();
|
|
87
|
+
visibleTeardown = () => {
|
|
88
|
+
window.removeEventListener("scroll", schedule, true);
|
|
89
|
+
window.removeEventListener("resize", schedule);
|
|
90
|
+
if (scheduledRaf !== void 0) window.cancelAnimationFrame(scheduledRaf);
|
|
91
|
+
};
|
|
92
|
+
};
|
|
45
93
|
const renderInto = (next) => {
|
|
46
94
|
if (isFigure(next)) throw new Error("mountCanvas: view.update does not accept a Figure; pass figure.ir instead.");
|
|
47
95
|
const scene = toScene(next, options);
|
|
@@ -54,6 +102,15 @@ var mountCanvas = (container, input, options = {}) => {
|
|
|
54
102
|
if (options.width !== void 0) canvas.style.width = `${options.width}px`;
|
|
55
103
|
if (options.height !== void 0) canvas.style.height = `${options.height}px`;
|
|
56
104
|
canvas.style.objectFit = "contain";
|
|
105
|
+
if (options.snapshotAt !== void 0) {
|
|
106
|
+
renderToCanvas(canvas, scene, {
|
|
107
|
+
devicePixelRatio: ratio,
|
|
108
|
+
time: options.snapshotAt,
|
|
109
|
+
easings: options.easings,
|
|
110
|
+
animationProperties: options.animationProperties
|
|
111
|
+
});
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
57
114
|
renderToCanvas(canvas, scene, { devicePixelRatio: ratio });
|
|
58
115
|
clock?.dispose();
|
|
59
116
|
clock = void 0;
|
|
@@ -70,8 +127,9 @@ var mountCanvas = (container, input, options = {}) => {
|
|
|
70
127
|
});
|
|
71
128
|
if (sceneHasAutoplayTrigger(scene)) clock.play();
|
|
72
129
|
}
|
|
130
|
+
resetVisibleBridge();
|
|
73
131
|
};
|
|
74
|
-
renderInto(
|
|
132
|
+
renderInto(input);
|
|
75
133
|
container.appendChild(canvas);
|
|
76
134
|
/**
|
|
77
135
|
* 把指针的 client 像素坐标逆 meet-fit 映射成 Scene user units
|
|
@@ -109,38 +167,57 @@ var mountCanvas = (container, input, options = {}) => {
|
|
|
109
167
|
context2d?.setTransform(1, 0, 0, 1, 0, 0);
|
|
110
168
|
return hitTest(currentScene, scenePoint, { context2d });
|
|
111
169
|
};
|
|
112
|
-
const buildContext = (
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
170
|
+
const buildContext = createContextBuilder({
|
|
171
|
+
renderer: "canvas",
|
|
172
|
+
root: canvas,
|
|
173
|
+
scene: () => currentScene,
|
|
174
|
+
resolveElement: () => null,
|
|
175
|
+
resolvePoint: (event) => {
|
|
176
|
+
const mouse = event;
|
|
177
|
+
return typeof mouse.clientX === "number" ? clientToScene(mouse.clientX, mouse.clientY) : null;
|
|
178
|
+
},
|
|
179
|
+
makeAnimation: (id) => createCanvasIdAnimationControls({
|
|
180
|
+
registry,
|
|
181
|
+
clockTime: () => clock?.time ?? 0,
|
|
182
|
+
ensurePlaying: () => clock?.play(),
|
|
183
|
+
renderFrame,
|
|
184
|
+
defaultId: id
|
|
185
|
+
})
|
|
186
|
+
});
|
|
187
|
+
const userHandlers = hydrateOptions.handlers;
|
|
188
|
+
const bind = () => createHydrationController(canvas, withCanvasAnimationEventHandlers(currentScene, userHandlers), locate, buildContext);
|
|
189
|
+
let controller = bind();
|
|
190
|
+
const live = {
|
|
191
|
+
rebind: () => {
|
|
192
|
+
controller.dispose();
|
|
193
|
+
controller = bind();
|
|
194
|
+
},
|
|
195
|
+
unbind: () => controller.dispose()
|
|
131
196
|
};
|
|
132
|
-
|
|
197
|
+
liveHydrations.add(live);
|
|
198
|
+
return { dispose: () => {
|
|
199
|
+
live.unbind();
|
|
200
|
+
liveHydrations.delete(live);
|
|
201
|
+
} };
|
|
202
|
+
};
|
|
203
|
+
/** update 换 scene 后按新 scene 重建存活水合的 onEvent 动画 handler 表(新增 / 移除的 onEvent track 即时反映) */
|
|
204
|
+
const rebindHydrations = () => {
|
|
205
|
+
for (const live of liveHydrations) live.rebind();
|
|
133
206
|
};
|
|
134
207
|
return {
|
|
135
208
|
root: canvas,
|
|
136
209
|
update(next) {
|
|
137
210
|
if (disposed) throw new Error("mountCanvas: view already disposed.");
|
|
138
211
|
renderInto(next);
|
|
212
|
+
rebindHydrations();
|
|
139
213
|
},
|
|
140
214
|
dispose() {
|
|
141
215
|
if (disposed) return;
|
|
142
216
|
disposed = true;
|
|
217
|
+
visibleTeardown?.();
|
|
143
218
|
clock?.dispose();
|
|
219
|
+
for (const live of liveHydrations) live.unbind();
|
|
220
|
+
liveHydrations.clear();
|
|
144
221
|
canvas.remove();
|
|
145
222
|
},
|
|
146
223
|
hydrate,
|
|
@@ -7,4 +7,4 @@ import { MountOptions, RenderInput, VanillaView } from './types';
|
|
|
7
7
|
* 原地重渲染、root 元素 identity 跨 update 不变、不失效。DOM 仅在调用时惰性触碰,`import` 本模块不碰 DOM——守 SSR 导入安全。
|
|
8
8
|
*/
|
|
9
9
|
export declare const mountSvg: (container: Element, input: RenderInput, options?: MountOptions) => VanillaView;
|
|
10
|
-
//# sourceMappingURL=
|
|
10
|
+
//# sourceMappingURL=mount-svg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mount-svg.d.ts","sourceRoot":"","sources":["../../src/mount-svg.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAmC,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAIvG;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,WAAW,OAAO,EAAE,OAAO,WAAW,EAAE,UAAS,YAAiB,KAAG,WAkF7F,CAAC"}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { isFigure } from "./builder/
|
|
2
|
-
import { toScene } from "./
|
|
3
|
-
import { applyAttrs, svgNodeToDom } from "./
|
|
1
|
+
import { isFigure } from "./builder/is-figure.js";
|
|
2
|
+
import { toScene } from "./to-scene.js";
|
|
3
|
+
import { applyAttrs, svgNodeToDom } from "./svg-node-to-dom.js";
|
|
4
4
|
import { buildSvgDocument } from "@retikz/render/svg";
|
|
5
5
|
import { bindWaapiDescriptors, prefersReducedMotion, sceneHasAnimations } from "@retikz/render/animation";
|
|
6
|
-
import { createHydrationController, createSvgAnimationControls,
|
|
7
|
-
//#region src/
|
|
6
|
+
import { createContextBuilder, createHydrationController, createSvgAnimationControls, locateSvg, resolvePointViaLayout, resolveSvgElement } from "@retikz/render/hydration";
|
|
7
|
+
//#region src/mount-svg.ts
|
|
8
8
|
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
9
|
-
/** 默认资源 id 前缀(确定性);多实例同页须经 `options.idPrefix` 显式区分 */
|
|
10
|
-
var DEFAULT_ID_PREFIX = "r";
|
|
11
9
|
/**
|
|
12
10
|
* 把 IR / Scene / Figure 挂成真实 SVG DOM(无框架浏览器 runtime)
|
|
13
11
|
* @description 收 `Figure` 时 delegate 给 `figure.mount`(Figure 自持 config,call-site options 覆盖)。收
|
|
@@ -18,11 +16,12 @@ var DEFAULT_ID_PREFIX = "r";
|
|
|
18
16
|
var mountSvg = (container, input, options = {}) => {
|
|
19
17
|
if (isFigure(input)) return input.mount(container, options);
|
|
20
18
|
if (typeof Element === "undefined" || !(container instanceof Element)) throw new Error("mountSvg: container must be a DOM Element.");
|
|
21
|
-
const idPrefix = options.idPrefix ??
|
|
19
|
+
const idPrefix = options.idPrefix ?? "r";
|
|
22
20
|
const root = document.createElementNS(SVG_NS, "svg");
|
|
23
21
|
const animate = options.animate !== false && !prefersReducedMotion();
|
|
24
22
|
let animationControls;
|
|
25
23
|
let currentScene;
|
|
24
|
+
const liveHydrationDisposers = /* @__PURE__ */ new Set();
|
|
26
25
|
const renderInto = (next) => {
|
|
27
26
|
if (isFigure(next)) throw new Error("mountSvg: view.update does not accept a Figure; pass figure.ir instead.");
|
|
28
27
|
const scene = toScene(next, options);
|
|
@@ -51,18 +50,21 @@ var mountSvg = (container, input, options = {}) => {
|
|
|
51
50
|
* `data-retikz-animation-owner` 双查 `getAnimations()` per-id 控制。
|
|
52
51
|
*/
|
|
53
52
|
const hydrate = (hydrateOptions) => {
|
|
54
|
-
const buildContext = (
|
|
55
|
-
id,
|
|
56
|
-
meta: metaOf(currentScene, id),
|
|
53
|
+
const buildContext = createContextBuilder({
|
|
57
54
|
renderer: "svg",
|
|
58
|
-
element: resolveSvgElement(event),
|
|
59
55
|
root,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
56
|
+
scene: () => currentScene,
|
|
57
|
+
resolveElement: resolveSvgElement,
|
|
58
|
+
resolvePoint: (event) => resolvePointViaLayout(root, currentScene.layout)(event),
|
|
59
|
+
makeAnimation: (id) => createSvgAnimationControls(root, id)
|
|
64
60
|
});
|
|
65
|
-
|
|
61
|
+
const controller = createHydrationController(root, hydrateOptions.handlers, locateSvg, buildContext);
|
|
62
|
+
const dispose = () => {
|
|
63
|
+
controller.dispose();
|
|
64
|
+
liveHydrationDisposers.delete(dispose);
|
|
65
|
+
};
|
|
66
|
+
liveHydrationDisposers.add(dispose);
|
|
67
|
+
return { dispose };
|
|
66
68
|
};
|
|
67
69
|
let disposed = false;
|
|
68
70
|
return {
|
|
@@ -75,6 +77,7 @@ var mountSvg = (container, input, options = {}) => {
|
|
|
75
77
|
dispose() {
|
|
76
78
|
if (disposed) return;
|
|
77
79
|
disposed = true;
|
|
80
|
+
for (const disposeHydration of [...liveHydrationDisposers]) disposeHydration();
|
|
78
81
|
animationControls?.dispose();
|
|
79
82
|
root.remove();
|
|
80
83
|
},
|