@retikz/core 0.1.0-alpha.4 → 0.1.0-beta.1
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/compile/compile.d.ts +23 -13
- package/dist/es/compile/compile.d.ts.map +1 -1
- package/dist/es/compile/compile.js +44 -25
- package/dist/es/compile/index.d.ts +1 -1
- package/dist/es/compile/index.d.ts.map +1 -1
- package/dist/es/compile/node.d.ts +40 -59
- package/dist/es/compile/node.d.ts.map +1 -1
- package/dist/es/compile/node.js +51 -43
- package/dist/es/compile/parseTarget.d.ts +3 -8
- package/dist/es/compile/parseTarget.d.ts.map +1 -1
- package/dist/es/compile/parseTarget.js +7 -19
- package/dist/es/compile/path/anchor.d.ts +19 -0
- package/dist/es/compile/path/anchor.d.ts.map +1 -0
- package/dist/es/compile/path/anchor.js +54 -0
- package/dist/es/compile/path/index.d.ts +24 -0
- package/dist/es/compile/path/index.d.ts.map +1 -0
- package/dist/es/compile/path/index.js +308 -0
- package/dist/es/compile/path/label.d.ts +18 -0
- package/dist/es/compile/path/label.d.ts.map +1 -0
- package/dist/es/compile/path/label.js +102 -0
- package/dist/es/compile/path/relative.d.ts +8 -0
- package/dist/es/compile/path/relative.d.ts.map +1 -0
- package/dist/es/compile/path/relative.js +48 -0
- package/dist/es/compile/path/shrink.d.ts +24 -0
- package/dist/es/compile/path/shrink.d.ts.map +1 -0
- package/dist/es/compile/path/shrink.js +136 -0
- package/dist/es/compile/path/split.d.ts +15 -0
- package/dist/es/compile/path/split.d.ts.map +1 -0
- package/dist/es/compile/path/split.js +46 -0
- package/dist/es/compile/position.d.ts +4 -8
- package/dist/es/compile/position.d.ts.map +1 -1
- package/dist/es/compile/position.js +10 -10
- package/dist/es/compile/text-metrics.d.ts +6 -5
- package/dist/es/compile/text-metrics.d.ts.map +1 -1
- package/dist/es/compile/text-metrics.js +11 -5
- package/dist/es/compile/view-box.d.ts +1 -4
- package/dist/es/compile/view-box.d.ts.map +1 -1
- package/dist/es/compile/view-box.js +1 -4
- package/dist/es/geometry/_transform.d.ts +21 -0
- package/dist/es/geometry/_transform.d.ts.map +1 -0
- package/dist/es/geometry/_transform.js +27 -0
- package/dist/es/geometry/arc.d.ts +3 -28
- package/dist/es/geometry/arc.d.ts.map +1 -1
- package/dist/es/geometry/arc.js +4 -31
- package/dist/es/geometry/bend.d.ts +2 -13
- package/dist/es/geometry/bend.d.ts.map +1 -1
- package/dist/es/geometry/bend.js +2 -13
- package/dist/es/geometry/circle.d.ts +6 -15
- package/dist/es/geometry/circle.d.ts.map +1 -1
- package/dist/es/geometry/circle.js +2 -20
- package/dist/es/geometry/diamond.d.ts +10 -26
- package/dist/es/geometry/diamond.d.ts.map +1 -1
- package/dist/es/geometry/diamond.js +5 -30
- package/dist/es/geometry/ellipse.d.ts +10 -17
- package/dist/es/geometry/ellipse.d.ts.map +1 -1
- package/dist/es/geometry/ellipse.js +5 -24
- package/dist/es/geometry/point.d.ts +8 -9
- package/dist/es/geometry/point.d.ts.map +1 -1
- package/dist/es/geometry/point.js +8 -9
- package/dist/es/geometry/polar.d.ts +12 -21
- package/dist/es/geometry/polar.d.ts.map +1 -1
- package/dist/es/geometry/polar.js +8 -19
- package/dist/es/geometry/rect.d.ts +8 -32
- package/dist/es/geometry/rect.d.ts.map +1 -1
- package/dist/es/geometry/rect.js +6 -49
- package/dist/es/geometry/segment.d.ts +15 -18
- package/dist/es/geometry/segment.d.ts.map +1 -1
- package/dist/es/geometry/segment.js +9 -16
- package/dist/es/index.d.ts +13 -13
- package/dist/es/index.d.ts.map +1 -1
- package/dist/es/index.js +7 -4
- package/dist/es/ir/coordinate.d.ts +18 -10
- package/dist/es/ir/coordinate.d.ts.map +1 -1
- package/dist/es/ir/coordinate.js +6 -11
- package/dist/es/ir/font.d.ts +21 -0
- package/dist/es/ir/font.d.ts.map +1 -0
- package/dist/es/ir/font.js +15 -0
- package/dist/es/ir/index.d.ts +2 -0
- package/dist/es/ir/index.d.ts.map +1 -1
- package/dist/es/ir/node.d.ts +51 -181
- package/dist/es/ir/node.d.ts.map +1 -1
- package/dist/es/ir/node.js +15 -70
- package/dist/es/ir/path/arrow.d.ts +210 -12
- package/dist/es/ir/path/arrow.d.ts.map +1 -1
- package/dist/es/ir/path/arrow.js +39 -12
- package/dist/es/ir/path/path.d.ts +477 -153
- package/dist/es/ir/path/path.d.ts.map +1 -1
- package/dist/es/ir/path/path.js +6 -6
- package/dist/es/ir/path/step.d.ts +395 -223
- package/dist/es/ir/path/step.d.ts.map +1 -1
- package/dist/es/ir/path/step.js +21 -22
- package/dist/es/ir/path/target.d.ts +25 -16
- package/dist/es/ir/path/target.d.ts.map +1 -1
- package/dist/es/ir/path/target.js +8 -6
- package/dist/es/ir/position/at-position.d.ts +4 -11
- package/dist/es/ir/position/at-position.d.ts.map +1 -1
- package/dist/es/ir/position/at-position.js +2 -9
- package/dist/es/ir/position/index.d.ts +1 -0
- package/dist/es/ir/position/index.d.ts.map +1 -1
- package/dist/es/ir/position/offset-position.d.ts +14 -0
- package/dist/es/ir/position/offset-position.d.ts.map +1 -0
- package/dist/es/ir/position/offset-position.js +14 -0
- package/dist/es/ir/position/polar-position.d.ts +1 -4
- package/dist/es/ir/position/polar-position.d.ts.map +1 -1
- package/dist/es/ir/position/polar-position.js +3 -6
- package/dist/es/ir/position/position.d.ts.map +1 -1
- package/dist/es/ir/position/position.js +1 -1
- package/dist/es/ir/scene.d.ts +1236 -422
- package/dist/es/ir/scene.d.ts.map +1 -1
- package/dist/es/ir/text.d.ts +96 -0
- package/dist/es/ir/text.d.ts.map +1 -0
- package/dist/es/ir/text.js +20 -0
- package/dist/es/parsers/parseTargetSugar.d.ts +4 -0
- package/dist/es/parsers/parseTargetSugar.d.ts.map +1 -1
- package/dist/es/parsers/parseTargetSugar.js +7 -19
- package/dist/es/parsers/parseWay.d.ts +26 -118
- package/dist/es/parsers/parseWay.d.ts.map +1 -1
- package/dist/es/parsers/parseWay.js +19 -61
- package/dist/es/primitive/ellipse.d.ts +4 -14
- package/dist/es/primitive/ellipse.d.ts.map +1 -1
- package/dist/es/primitive/group.d.ts +37 -3
- package/dist/es/primitive/group.d.ts.map +1 -1
- package/dist/es/primitive/path.d.ts +107 -7
- package/dist/es/primitive/path.d.ts.map +1 -1
- package/dist/es/primitive/rect.d.ts +2 -2
- package/dist/es/primitive/rect.d.ts.map +1 -1
- package/dist/es/primitive/scene.d.ts +2 -4
- package/dist/es/primitive/scene.d.ts.map +1 -1
- package/dist/es/primitive/text.d.ts +16 -32
- package/dist/es/primitive/text.d.ts.map +1 -1
- package/dist/es/primitive/view-box.d.ts +1 -1
- package/dist/es/primitive/view-box.d.ts.map +1 -1
- package/dist/es/types.d.ts +8 -0
- package/dist/es/types.d.ts.map +1 -1
- package/dist/lib/compile/compile.cjs +44 -25
- package/dist/lib/compile/compile.d.ts +23 -13
- package/dist/lib/compile/compile.d.ts.map +1 -1
- package/dist/lib/compile/index.d.ts +1 -1
- package/dist/lib/compile/index.d.ts.map +1 -1
- package/dist/lib/compile/node.cjs +51 -43
- package/dist/lib/compile/node.d.ts +40 -59
- package/dist/lib/compile/node.d.ts.map +1 -1
- package/dist/lib/compile/parseTarget.cjs +7 -19
- package/dist/lib/compile/parseTarget.d.ts +3 -8
- package/dist/lib/compile/parseTarget.d.ts.map +1 -1
- package/dist/lib/compile/path/anchor.cjs +58 -0
- package/dist/lib/compile/path/anchor.d.ts +19 -0
- package/dist/lib/compile/path/anchor.d.ts.map +1 -0
- package/dist/lib/compile/path/index.cjs +308 -0
- package/dist/lib/compile/path/index.d.ts +24 -0
- package/dist/lib/compile/path/index.d.ts.map +1 -0
- package/dist/lib/compile/path/label.cjs +103 -0
- package/dist/lib/compile/path/label.d.ts +18 -0
- package/dist/lib/compile/path/label.d.ts.map +1 -0
- package/dist/lib/compile/path/relative.cjs +48 -0
- package/dist/lib/compile/path/relative.d.ts +8 -0
- package/dist/lib/compile/path/relative.d.ts.map +1 -0
- package/dist/lib/compile/path/shrink.cjs +138 -0
- package/dist/lib/compile/path/shrink.d.ts +24 -0
- package/dist/lib/compile/path/shrink.d.ts.map +1 -0
- package/dist/lib/compile/path/split.cjs +46 -0
- package/dist/lib/compile/path/split.d.ts +15 -0
- package/dist/lib/compile/path/split.d.ts.map +1 -0
- package/dist/lib/compile/position.cjs +10 -10
- package/dist/lib/compile/position.d.ts +4 -8
- package/dist/lib/compile/position.d.ts.map +1 -1
- package/dist/lib/compile/text-metrics.cjs +11 -5
- package/dist/lib/compile/text-metrics.d.ts +6 -5
- package/dist/lib/compile/text-metrics.d.ts.map +1 -1
- package/dist/lib/compile/view-box.cjs +1 -4
- package/dist/lib/compile/view-box.d.ts +1 -4
- package/dist/lib/compile/view-box.d.ts.map +1 -1
- package/dist/lib/geometry/_transform.cjs +28 -0
- package/dist/lib/geometry/_transform.d.ts +21 -0
- package/dist/lib/geometry/_transform.d.ts.map +1 -0
- package/dist/lib/geometry/arc.cjs +3 -31
- package/dist/lib/geometry/arc.d.ts +3 -28
- package/dist/lib/geometry/arc.d.ts.map +1 -1
- package/dist/lib/geometry/bend.cjs +2 -13
- package/dist/lib/geometry/bend.d.ts +2 -13
- package/dist/lib/geometry/bend.d.ts.map +1 -1
- package/dist/lib/geometry/circle.cjs +6 -24
- package/dist/lib/geometry/circle.d.ts +6 -15
- package/dist/lib/geometry/circle.d.ts.map +1 -1
- package/dist/lib/geometry/diamond.cjs +9 -34
- package/dist/lib/geometry/diamond.d.ts +10 -26
- package/dist/lib/geometry/diamond.d.ts.map +1 -1
- package/dist/lib/geometry/ellipse.cjs +9 -28
- package/dist/lib/geometry/ellipse.d.ts +10 -17
- package/dist/lib/geometry/ellipse.d.ts.map +1 -1
- package/dist/lib/geometry/point.cjs +8 -9
- package/dist/lib/geometry/point.d.ts +8 -9
- package/dist/lib/geometry/point.d.ts.map +1 -1
- package/dist/lib/geometry/polar.cjs +8 -19
- package/dist/lib/geometry/polar.d.ts +12 -21
- package/dist/lib/geometry/polar.d.ts.map +1 -1
- package/dist/lib/geometry/rect.cjs +10 -53
- package/dist/lib/geometry/rect.d.ts +8 -32
- package/dist/lib/geometry/rect.d.ts.map +1 -1
- package/dist/lib/geometry/segment.cjs +9 -16
- package/dist/lib/geometry/segment.d.ts +15 -18
- package/dist/lib/geometry/segment.d.ts.map +1 -1
- package/dist/lib/index.cjs +14 -5
- package/dist/lib/index.d.ts +13 -13
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/ir/coordinate.cjs +6 -11
- package/dist/lib/ir/coordinate.d.ts +18 -10
- package/dist/lib/ir/coordinate.d.ts.map +1 -1
- package/dist/lib/ir/font.cjs +15 -0
- package/dist/lib/ir/font.d.ts +21 -0
- package/dist/lib/ir/font.d.ts.map +1 -0
- package/dist/lib/ir/index.d.ts +2 -0
- package/dist/lib/ir/index.d.ts.map +1 -1
- package/dist/lib/ir/node.cjs +16 -74
- package/dist/lib/ir/node.d.ts +51 -181
- package/dist/lib/ir/node.d.ts.map +1 -1
- package/dist/lib/ir/path/arrow.cjs +43 -11
- package/dist/lib/ir/path/arrow.d.ts +210 -12
- package/dist/lib/ir/path/arrow.d.ts.map +1 -1
- package/dist/lib/ir/path/path.cjs +5 -5
- package/dist/lib/ir/path/path.d.ts +477 -153
- package/dist/lib/ir/path/path.d.ts.map +1 -1
- package/dist/lib/ir/path/step.cjs +21 -22
- package/dist/lib/ir/path/step.d.ts +395 -223
- package/dist/lib/ir/path/step.d.ts.map +1 -1
- package/dist/lib/ir/path/target.cjs +9 -7
- package/dist/lib/ir/path/target.d.ts +25 -16
- package/dist/lib/ir/path/target.d.ts.map +1 -1
- package/dist/lib/ir/position/at-position.cjs +2 -9
- package/dist/lib/ir/position/at-position.d.ts +4 -11
- package/dist/lib/ir/position/at-position.d.ts.map +1 -1
- package/dist/lib/ir/position/index.d.ts +1 -0
- package/dist/lib/ir/position/index.d.ts.map +1 -1
- package/dist/lib/ir/position/offset-position.cjs +14 -0
- package/dist/lib/ir/position/offset-position.d.ts +14 -0
- package/dist/lib/ir/position/offset-position.d.ts.map +1 -0
- package/dist/lib/ir/position/polar-position.cjs +3 -6
- package/dist/lib/ir/position/polar-position.d.ts +1 -4
- package/dist/lib/ir/position/polar-position.d.ts.map +1 -1
- package/dist/lib/ir/position/position.cjs +1 -1
- package/dist/lib/ir/position/position.d.ts.map +1 -1
- package/dist/lib/ir/scene.d.ts +1236 -422
- package/dist/lib/ir/scene.d.ts.map +1 -1
- package/dist/lib/ir/text.cjs +21 -0
- package/dist/lib/ir/text.d.ts +96 -0
- package/dist/lib/ir/text.d.ts.map +1 -0
- package/dist/lib/parsers/parseTargetSugar.cjs +7 -19
- package/dist/lib/parsers/parseTargetSugar.d.ts +4 -0
- package/dist/lib/parsers/parseTargetSugar.d.ts.map +1 -1
- package/dist/lib/parsers/parseWay.cjs +19 -61
- package/dist/lib/parsers/parseWay.d.ts +26 -118
- package/dist/lib/parsers/parseWay.d.ts.map +1 -1
- package/dist/lib/primitive/ellipse.d.ts +4 -14
- package/dist/lib/primitive/ellipse.d.ts.map +1 -1
- package/dist/lib/primitive/group.d.ts +37 -3
- package/dist/lib/primitive/group.d.ts.map +1 -1
- package/dist/lib/primitive/path.d.ts +107 -7
- package/dist/lib/primitive/path.d.ts.map +1 -1
- package/dist/lib/primitive/rect.d.ts +2 -2
- package/dist/lib/primitive/rect.d.ts.map +1 -1
- package/dist/lib/primitive/scene.d.ts +2 -4
- package/dist/lib/primitive/scene.d.ts.map +1 -1
- package/dist/lib/primitive/text.d.ts +16 -32
- package/dist/lib/primitive/text.d.ts.map +1 -1
- package/dist/lib/primitive/view-box.d.ts +1 -1
- package/dist/lib/primitive/view-box.d.ts.map +1 -1
- package/dist/lib/types.d.ts +8 -0
- package/dist/lib/types.d.ts.map +1 -1
- package/package.json +13 -4
- package/dist/es/compile/path.d.ts +0 -30
- package/dist/es/compile/path.d.ts.map +0 -1
- package/dist/es/compile/path.js +0 -617
- package/dist/lib/compile/path.cjs +0 -617
- package/dist/lib/compile/path.d.ts +0 -30
- package/dist/lib/compile/path.d.ts.map +0 -1
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import { IR } from '../ir';
|
|
2
2
|
import { Scene } from '../primitive';
|
|
3
3
|
import { TextMeasurer } from './text-metrics';
|
|
4
|
+
/** 编译期警告:path / position 解析失败时通过 `CompileOptions.onWarn` 发出,不影响编译产物 */
|
|
5
|
+
export type CompileWarning = {
|
|
6
|
+
/**
|
|
7
|
+
* 警告类型代码(机器可读)
|
|
8
|
+
* @description 用户可按 code 分支处理;未来 alpha 加新 code 不破坏调用方
|
|
9
|
+
*/
|
|
10
|
+
code: 'UNRESOLVED_NODE_REFERENCE' | 'PATH_TOO_SHORT' | 'ANCHOR_RESOLUTION_FAILED' | 'OFFSET_BASE_UNRESOLVED' | 'POLAR_ORIGIN_UNRESOLVED' | 'AT_TARGET_UNRESOLVED' | 'RELATIVE_INITIAL_NO_PREV_END' | 'BBOX_EXTREME_INPUT' | (string & {});
|
|
11
|
+
/** 人类可读消息(英文) */
|
|
12
|
+
message: string;
|
|
13
|
+
/** IR locator 路径(jq-like,如 `'children[3].path.children[1].to'`) */
|
|
14
|
+
path: string;
|
|
15
|
+
};
|
|
4
16
|
/** compileToScene 的可选参数 */
|
|
5
17
|
export type CompileOptions = {
|
|
6
18
|
/** 注入文字度量函数;不传则用 fallback(不准但可跑) */
|
|
@@ -8,26 +20,24 @@ export type CompileOptions = {
|
|
|
8
20
|
/** viewBox 周围的留白(user units),默认 10 */
|
|
9
21
|
padding?: number;
|
|
10
22
|
/**
|
|
11
|
-
* 输出坐标的小数位精度;默认 2
|
|
12
|
-
*
|
|
13
|
-
* 内部几何计算保持完整 double 精度,避免误差累积。
|
|
23
|
+
* 输出坐标的小数位精度;默认 2
|
|
24
|
+
* @description 仅作用于 Scene primitive / path d / viewBox;内部几何计算保持完整 double 精度
|
|
14
25
|
*/
|
|
15
26
|
precision?: number;
|
|
16
27
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* 未配则回退到 1。
|
|
28
|
+
* 相对定位的默认距离(对应 TikZ `node distance`,user units)
|
|
29
|
+
* @description `Node.position` 为 `{ direction, of }` 且未自带 `distance` 时取此值;未配回退到 1
|
|
20
30
|
*/
|
|
21
31
|
nodeDistance?: number;
|
|
32
|
+
/**
|
|
33
|
+
* 编译期警告收集器
|
|
34
|
+
* @description path / position 解析失败时按 IR locator + code + message 同步触发;不传时 dev 模式(`process.env.NODE_ENV !== 'production'`)默认 `console.warn`、生产静默
|
|
35
|
+
*/
|
|
36
|
+
onWarn?: (warning: CompileWarning) => void;
|
|
22
37
|
};
|
|
23
38
|
/**
|
|
24
|
-
* IR → Scene
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* 流程:
|
|
28
|
-
* 1. Pass 1:按 IR children 源码顺序处理 Node——计算 layout、注册 nodeIndex、发出 RectPrim/TextPrim、累积 bbox 角点
|
|
29
|
-
* 2. Pass 2:处理 Path——解析每个 step 端点(节点 ref 走 boundaryPoint,其他走 resolvePosition),写 d 字符串
|
|
30
|
-
* 3. 末端用 computeViewBox 折算最终 viewBox(按 precision 四舍五入)
|
|
39
|
+
* IR → Scene 纯函数转换,所有 adapter 共享
|
|
40
|
+
* @description Pass 1 处理 Node/coordinate 并注册 nodeIndex、发 primitive、累积 bbox;Pass 2 解析 Path 端点写 d 字符串;末端按 precision 折算 viewBox
|
|
31
41
|
*/
|
|
32
42
|
export declare const compileToScene: (ir: IR, options?: CompileOptions) => Scene;
|
|
33
43
|
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../../src/compile/compile.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAc,MAAM,OAAO,CAAC;AAC5C,OAAO,KAAK,EAAE,KAAK,EAAkB,MAAM,cAAc,CAAC;AAK1D,OAAO,EAAE,KAAK,YAAY,EAAoB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../../src/compile/compile.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAc,MAAM,OAAO,CAAC;AAC5C,OAAO,KAAK,EAAE,KAAK,EAAkB,MAAM,cAAc,CAAC;AAK1D,OAAO,EAAE,KAAK,YAAY,EAAoB,MAAM,gBAAgB,CAAC;AAuBrE,uEAAuE;AACvE,MAAM,MAAM,cAAc,GAAG;IAC3B;;;OAGG;IACH,IAAI,EACA,2BAA2B,GAC3B,gBAAgB,GAChB,0BAA0B,GAC1B,wBAAwB,GACxB,yBAAyB,GACzB,sBAAsB,GACtB,8BAA8B,GAC9B,oBAAoB,GACpB,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;IAClB,iBAAiB;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,2BAA2B;AAC3B,MAAM,MAAM,cAAc,GAAG;IAC3B,oCAAoC;IACpC,WAAW,CAAC,EAAE,YAAY,CAAC;IAC3B,sCAAsC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;CAC5C,CAAC;AAWF;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,IAAI,EAAE,EAAE,UAAS,cAAmB,KAAG,KAkErE,CAAC"}
|
|
@@ -2,14 +2,13 @@ import { rect } from "../geometry/rect.js";
|
|
|
2
2
|
import { resolvePosition } from "./position.js";
|
|
3
3
|
import { emitNodePrimitives, layoutNode } from "./node.js";
|
|
4
4
|
import { fallbackMeasurer } from "./text-metrics.js";
|
|
5
|
-
import { emitPathPrimitive } from "./path.js";
|
|
5
|
+
import { emitPathPrimitive } from "./path/index.js";
|
|
6
6
|
import { makeRound } from "./precision.js";
|
|
7
7
|
import { computeViewBox } from "./view-box.js";
|
|
8
8
|
//#region src/compile/compile.ts
|
|
9
9
|
/**
|
|
10
|
-
* 把 coordinate
|
|
11
|
-
*
|
|
12
|
-
* 的 boundaryPoint 始终返回中心,符合"占位无形状边界"语义)。
|
|
10
|
+
* 把 coordinate 注册成 0×0 NodeLayout
|
|
11
|
+
* @description 让后续 path target / `at.of` 引用时 boundaryPoint 命中中心,符合"占位无形状边界"语义
|
|
13
12
|
*/
|
|
14
13
|
var coordinateAsLayout = (id, center) => ({
|
|
15
14
|
id,
|
|
@@ -30,37 +29,57 @@ var coordinateAsLayout = (id, center) => ({
|
|
|
30
29
|
fontSize: 0
|
|
31
30
|
});
|
|
32
31
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
* 默认 warn dispatcher:dev 模式 console.warn、生产静默
|
|
33
|
+
* @description 用户传 onWarn 时使用用户的;不传走此 fallback
|
|
34
|
+
*/
|
|
35
|
+
var defaultWarnDispatcher = (warning) => {
|
|
36
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV === "production") return;
|
|
37
|
+
console.warn(`[retikz] ${warning.code} at ${warning.path}: ${warning.message}`);
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* IR → Scene 纯函数转换,所有 adapter 共享
|
|
41
|
+
* @description Pass 1 处理 Node/coordinate 并注册 nodeIndex、发 primitive、累积 bbox;Pass 2 解析 Path 端点写 d 字符串;末端按 precision 折算 viewBox
|
|
40
42
|
*/
|
|
41
43
|
var compileToScene = (ir, options = {}) => {
|
|
42
44
|
const measureText = options.measureText ?? fallbackMeasurer;
|
|
43
45
|
const viewBoxPadding = options.padding ?? 10;
|
|
44
46
|
const round = makeRound(options.precision ?? 2);
|
|
45
47
|
const nodeDistance = options.nodeDistance;
|
|
48
|
+
const onWarn = options.onWarn ?? defaultWarnDispatcher;
|
|
46
49
|
const primitives = [];
|
|
47
50
|
const nodeIndex = /* @__PURE__ */ new Map();
|
|
48
51
|
const allPoints = [];
|
|
49
|
-
for (
|
|
50
|
-
const
|
|
51
|
-
if (child.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
for (let i = 0; i < ir.children.length; i++) {
|
|
53
|
+
const child = ir.children[i];
|
|
54
|
+
if (child.type === "node") {
|
|
55
|
+
const layout = layoutNode(child, measureText, nodeIndex, nodeDistance);
|
|
56
|
+
if (child.id) nodeIndex.set(child.id, layout);
|
|
57
|
+
for (const prim of emitNodePrimitives(layout, round)) primitives.push(prim);
|
|
58
|
+
allPoints.push(rect.anchor(layout.rect, "north-west"), rect.anchor(layout.rect, "north-east"), rect.anchor(layout.rect, "south-west"), rect.anchor(layout.rect, "south-east"));
|
|
59
|
+
} else if (child.type === "coordinate") {
|
|
60
|
+
const center = resolvePosition(child.position, nodeIndex, nodeDistance);
|
|
61
|
+
if (!center) {
|
|
62
|
+
onWarn({
|
|
63
|
+
code: "POLAR_ORIGIN_UNRESOLVED",
|
|
64
|
+
message: `Cannot resolve position for coordinate '${child.id}'; polar.origin or at.of may reference an undefined node`,
|
|
65
|
+
path: `children[${i}].coordinate.position`
|
|
66
|
+
});
|
|
67
|
+
throw new Error(`Cannot resolve position for coordinate ${child.id}; polar.origin or at.of may reference an undefined node`);
|
|
68
|
+
}
|
|
69
|
+
nodeIndex.set(child.id, coordinateAsLayout(child.id, center));
|
|
70
|
+
}
|
|
58
71
|
}
|
|
59
|
-
for (
|
|
60
|
-
const
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
72
|
+
for (let i = 0; i < ir.children.length; i++) {
|
|
73
|
+
const child = ir.children[i];
|
|
74
|
+
if (child.type === "path") {
|
|
75
|
+
const result = emitPathPrimitive(child, nodeIndex, round, measureText, {
|
|
76
|
+
onWarn,
|
|
77
|
+
irPath: `children[${i}].path`
|
|
78
|
+
});
|
|
79
|
+
if (result) {
|
|
80
|
+
for (const prim of result.primitives) primitives.push(prim);
|
|
81
|
+
for (const p of result.points) allPoints.push(p);
|
|
82
|
+
}
|
|
64
83
|
}
|
|
65
84
|
}
|
|
66
85
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/compile/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC;AAC9B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/compile/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC"}
|
|
@@ -4,78 +4,70 @@ import { AtDirection, IRNode, NodeShape } from '../ir';
|
|
|
4
4
|
import { ScenePrimitive, TextLine } from '../primitive';
|
|
5
5
|
import { TextMeasurer } from './text-metrics';
|
|
6
6
|
export type NodeLayout = {
|
|
7
|
-
/** 节点 id
|
|
7
|
+
/** 节点 id(其他位置可引用) */
|
|
8
8
|
id?: string;
|
|
9
|
-
/**
|
|
9
|
+
/** 节点形状,所有几何 / boundaryPoint 按 shape 多态 */
|
|
10
10
|
shape: NodeShape;
|
|
11
11
|
/**
|
|
12
|
-
* 节点视觉边界框(所有 shape
|
|
13
|
-
*
|
|
14
|
-
* - circle: rect.width = rect.height = 2 × radius(外接正方形)
|
|
15
|
-
* - ellipse: rect.width = 2 × rx,rect.height = 2 × ry(外接矩形)
|
|
16
|
-
* - diamond: rect.width = 2 × halfA,rect.height = 2 × halfB(外接矩形)
|
|
17
|
-
*
|
|
18
|
-
* x, y 是几何中心;rotate 是弧度(与 packages/core/AGENTS.md 对齐)。
|
|
12
|
+
* 节点视觉边界框(所有 shape 共享语义)
|
|
13
|
+
* @description rectangle: rect 本身;circle: width=height=2×radius;ellipse: 2×rx,2×ry;diamond: 2×halfA,2×halfB。x,y 是几何中心,rotate 弧度
|
|
19
14
|
*/
|
|
20
15
|
rect: Rect;
|
|
21
|
-
/** IR
|
|
16
|
+
/** IR 原始旋转角(度数),供 emit 阶段写入 GroupPrim 的 rotate transform */
|
|
22
17
|
rotateDeg: number;
|
|
23
|
-
/**
|
|
18
|
+
/** 外边距(≥ 0),path 附着到外扩 margin 的虚拟边界 */
|
|
24
19
|
margin: number;
|
|
25
20
|
/**
|
|
26
|
-
*
|
|
27
|
-
* 每行可带覆盖样式(fill
|
|
28
|
-
* 未覆盖的字段在 emit 阶段不写出,由下游走 TextPrim 块级默认。
|
|
21
|
+
* 节点文本行(undefined 表示无文本,否则非空数组)
|
|
22
|
+
* @description 每行可带覆盖样式(fill/opacity/fontSize/fontFamily/fontWeight/fontStyle),未覆盖字段 emit 阶段不写出由下游走块级默认
|
|
29
23
|
*/
|
|
30
24
|
lines?: Array<TextLine>;
|
|
31
|
-
/**
|
|
25
|
+
/** 文本块宽度 = max(per-line measureText.width) */
|
|
32
26
|
textWidth: number;
|
|
33
|
-
/**
|
|
27
|
+
/** 文本块高度 ≈ lines × lineHeight */
|
|
34
28
|
textHeight: number;
|
|
35
|
-
/**
|
|
29
|
+
/** 文本对齐(start / middle / end 三态) */
|
|
36
30
|
align: 'start' | 'middle' | 'end';
|
|
37
|
-
/**
|
|
31
|
+
/** 行高(已应用默认值) */
|
|
38
32
|
lineHeight: number;
|
|
39
|
-
/**
|
|
33
|
+
/** 文本字号(已应用默认值) */
|
|
40
34
|
fontSize: number;
|
|
41
|
-
/**
|
|
35
|
+
/** 字体族(CSS font-family) */
|
|
42
36
|
fontFamily?: string;
|
|
43
|
-
/**
|
|
37
|
+
/** 字重 */
|
|
44
38
|
fontWeight?: string | number;
|
|
45
|
-
/**
|
|
39
|
+
/** 字形 */
|
|
46
40
|
fontStyle?: 'normal' | 'italic' | 'oblique';
|
|
47
|
-
/** 节点背景色,
|
|
41
|
+
/** 节点背景色,emit 时 'transparent' 兜底 */
|
|
48
42
|
fill?: string;
|
|
49
|
-
/**
|
|
43
|
+
/** 填充透明度 0~1 */
|
|
50
44
|
fillOpacity?: number;
|
|
51
|
-
/** 节点边框色,
|
|
45
|
+
/** 节点边框色,emit 时 'currentColor' 兜底 */
|
|
52
46
|
stroke?: string;
|
|
53
|
-
/**
|
|
47
|
+
/** 描边透明度 0~1(TikZ `draw opacity`) */
|
|
54
48
|
strokeOpacity?: number;
|
|
55
|
-
/**
|
|
49
|
+
/** 边框宽度,emit 时 1 兜底 */
|
|
56
50
|
strokeWidth?: number;
|
|
57
|
-
/** SVG stroke-dasharray
|
|
51
|
+
/** 描边 dash 模式(与 SVG/CSS `stroke-dasharray` 同格式),已把 dashed/dotted 预设解析为具体 pattern */
|
|
58
52
|
strokeDasharray?: string;
|
|
59
|
-
/** rectangle
|
|
53
|
+
/** rectangle 圆角半径(非 rect shape 无效) */
|
|
60
54
|
roundedCorners?: number;
|
|
61
|
-
/**
|
|
55
|
+
/** 文字颜色,emit 时 'currentColor' 兜底 */
|
|
62
56
|
textColor?: string;
|
|
63
|
-
/** 整节点透明度 0~1
|
|
57
|
+
/** 整节点透明度 0~1(同时挂 shape 与 text primitive) */
|
|
64
58
|
opacity?: number;
|
|
65
59
|
/**
|
|
66
|
-
* 已解析的 label
|
|
67
|
-
*
|
|
68
|
-
* - distance 默认 DEFAULT_LABEL_DISTANCE
|
|
69
|
-
* - font 字段从 Node 继承(family / size / weight / style 任一未填则取 Node 块级值)
|
|
60
|
+
* 已解析的 label 列表
|
|
61
|
+
* @description IR 层 `Node.label` 标准化:position 默认 'above'、distance 默认 DEFAULT_LABEL_DISTANCE、font 从 Node 继承
|
|
70
62
|
*/
|
|
71
63
|
labels?: Array<NodeLabelLayout>;
|
|
72
64
|
};
|
|
73
|
-
/**
|
|
65
|
+
/** 节点附属标签 layout(layoutNode 已合并默认值与样式继承) */
|
|
74
66
|
export type NodeLabelLayout = {
|
|
75
67
|
text: string;
|
|
76
|
-
/** 8
|
|
68
|
+
/** 8 方向枚举或数字角度 */
|
|
77
69
|
position: AtDirection | number;
|
|
78
|
-
/**
|
|
70
|
+
/** 已应用默认值 */
|
|
79
71
|
distance: number;
|
|
80
72
|
textColor?: string;
|
|
81
73
|
opacity?: number;
|
|
@@ -85,39 +77,28 @@ export type NodeLabelLayout = {
|
|
|
85
77
|
fontStyle?: 'normal' | 'italic' | 'oblique';
|
|
86
78
|
};
|
|
87
79
|
/**
|
|
88
|
-
* 取节点 shape 在 toward
|
|
89
|
-
* 按 shape
|
|
90
|
-
* margin > 0 时形状先外扩,让 path 在 border 外停 margin 个 user units。
|
|
80
|
+
* 取节点 shape 在 toward 方向的附着点(path 端点贴边用)
|
|
81
|
+
* @description 按 shape 多态调用各自 boundaryPoint;margin > 0 时形状先外扩,让 path 在 border 外停 margin
|
|
91
82
|
*/
|
|
92
83
|
export declare const boundaryPointOf: (layout: NodeLayout, toward: Position) => Position;
|
|
93
84
|
/**
|
|
94
|
-
* 取节点 shape
|
|
95
|
-
*
|
|
96
|
-
* 用于 `'A.north'` 这种语法落点。
|
|
85
|
+
* 取节点 shape 命名 anchor(center / north / east / north-east 等 9 个)
|
|
86
|
+
* @description 不应用 margin——TikZ 语义中 explicit anchor 取视觉边界点不涉及 outer sep;用于 `'A.north'` 落点
|
|
97
87
|
*/
|
|
98
88
|
export declare const anchorOf: (layout: NodeLayout, name: RectAnchor) => Position;
|
|
99
89
|
/**
|
|
100
|
-
* 取节点 shape
|
|
101
|
-
*
|
|
102
|
-
* **不应用 margin**——同 anchorOf。用于 `'A.30'` 这种语法落点。
|
|
90
|
+
* 取节点 shape 在指定角度方向的边界点
|
|
91
|
+
* @description 角度约定与 PolarPosition 一致(度数:0°=+x,90°=+y 即 screen 下方);不应用 margin(同 anchorOf);用于 `'A.30'` 落点
|
|
103
92
|
*/
|
|
104
93
|
export declare const angleBoundaryOf: (layout: NodeLayout, angleDeg: number) => Position;
|
|
105
94
|
/**
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* - 按 shape 决定外接边界尺寸(circle 取半对角线、ellipse 各 ×√2、diamond 各 ×2)
|
|
109
|
-
* - 解析 position(笛卡尔或极坐标)为几何中心
|
|
110
|
-
* - IR 的 rotate(度数)转弧度存进 Rect.rotate
|
|
111
|
-
* - 透传 margin / 样式属性
|
|
95
|
+
* IR Node → 内部 NodeLayout
|
|
96
|
+
* @description 文本度量 + padding 推内框半轴;按 shape 算外接边界(circle 取半对角线、ellipse ×√2、diamond ×2);解析 position 为几何中心;rotate 度数转弧度
|
|
112
97
|
*/
|
|
113
98
|
export declare const layoutNode: (node: IRNode, measureText: TextMeasurer, nodeIndex: Map<string, NodeLayout>, nodeDistance?: number) => NodeLayout;
|
|
114
99
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* - text(如有内容):始终走 TextPrim
|
|
118
|
-
* - 若有旋转:外面套一层 GroupPrim 用 SVG `rotate(deg cx cy)` 实现
|
|
119
|
-
* (PathPrim 的 diamond 顶点已自带旋转坐标,但 text 需要 group 旋转,
|
|
120
|
-
* 所以仍统一用 group 包裹)
|
|
100
|
+
* NodeLayout → Scene primitives
|
|
101
|
+
* @description shape 主体按 shape 分发(rect/ellipse/path);text 始终走 TextPrim;有旋转时外层 GroupPrim 用 `rotate(deg cx cy)` 统一包裹(text 必须靠 group 旋转)
|
|
121
102
|
*/
|
|
122
103
|
export declare const emitNodePrimitives: (layout: NodeLayout, round: (n: number) => number) => Array<ScenePrimitive>;
|
|
123
104
|
//# sourceMappingURL=node.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../src/compile/node.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAAO,KAAK,EAAE,WAAW,EAAc,MAAM,EAAe,SAAS,EAAE,MAAM,OAAO,CAAC;AACrF,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAgCnD,MAAM,MAAM,UAAU,GAAG;IACvB,
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../src/compile/node.ts"],"names":[],"mappings":"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"}
|
package/dist/es/compile/node.js
CHANGED
|
@@ -8,22 +8,22 @@ var DEFAULT_FONT_SIZE = 14;
|
|
|
8
8
|
var DEFAULT_PADDING = 8;
|
|
9
9
|
var DEFAULT_LINE_HEIGHT_FACTOR = 1.2;
|
|
10
10
|
var DEG_TO_RAD = Math.PI / 180;
|
|
11
|
-
/** Node label 与 node
|
|
11
|
+
/** Node label 与 node 边界默认距离(TikZ 默认 0pt 视觉太贴) */
|
|
12
12
|
var DEFAULT_LABEL_DISTANCE = 4;
|
|
13
13
|
var SQRT2 = Math.SQRT2;
|
|
14
|
-
/** dashed 预设:
|
|
14
|
+
/** dashed 预设:4 px 实线 + 2 px 间隙循环 */
|
|
15
15
|
var DASHED_PATTERN = "4 2";
|
|
16
|
-
/** dotted 预设:
|
|
16
|
+
/** dotted 预设:1 px 圆点 + 2 px 间隙 */
|
|
17
17
|
var DOTTED_PATTERN = "1 2";
|
|
18
|
-
/**
|
|
18
|
+
/** dashed / dotted / dashArray 优先级:dashArray > dashed > dotted */
|
|
19
19
|
var resolveDashArray = (dashArray, dashed, dotted) => {
|
|
20
20
|
if (dashArray !== void 0) return dashArray;
|
|
21
21
|
if (dashed) return DASHED_PATTERN;
|
|
22
22
|
if (dotted) return DOTTED_PATTERN;
|
|
23
23
|
};
|
|
24
|
-
/** IR
|
|
24
|
+
/** IR align → 文字对齐锚点(start / middle / end) */
|
|
25
25
|
var alignToTextAnchor = (a) => a === "left" ? "start" : a === "right" ? "end" : "middle";
|
|
26
|
-
/**
|
|
26
|
+
/** 从 layout 构造 Rect(带 margin 扩张) */
|
|
27
27
|
var rectOf = (layout, marginAdd) => ({
|
|
28
28
|
x: layout.rect.x,
|
|
29
29
|
y: layout.rect.y,
|
|
@@ -31,14 +31,14 @@ var rectOf = (layout, marginAdd) => ({
|
|
|
31
31
|
height: layout.rect.height + 2 * marginAdd,
|
|
32
32
|
rotate: layout.rect.rotate
|
|
33
33
|
});
|
|
34
|
-
/**
|
|
34
|
+
/** 从 layout 构造 Circle(radius=外接框边长/2 + margin) */
|
|
35
35
|
var circleOf = (layout, marginAdd) => ({
|
|
36
36
|
x: layout.rect.x,
|
|
37
37
|
y: layout.rect.y,
|
|
38
38
|
radius: layout.rect.width / 2 + marginAdd,
|
|
39
39
|
rotate: layout.rect.rotate
|
|
40
40
|
});
|
|
41
|
-
/**
|
|
41
|
+
/** 从 layout 构造 Ellipse(rx/ry 各加 margin) */
|
|
42
42
|
var ellipseOf = (layout, marginAdd) => ({
|
|
43
43
|
x: layout.rect.x,
|
|
44
44
|
y: layout.rect.y,
|
|
@@ -46,7 +46,7 @@ var ellipseOf = (layout, marginAdd) => ({
|
|
|
46
46
|
ry: layout.rect.height / 2 + marginAdd,
|
|
47
47
|
rotate: layout.rect.rotate
|
|
48
48
|
});
|
|
49
|
-
/**
|
|
49
|
+
/** 从 layout 构造 Diamond(halfA/halfB 各加 margin) */
|
|
50
50
|
var diamondOf = (layout, marginAdd) => ({
|
|
51
51
|
x: layout.rect.x,
|
|
52
52
|
y: layout.rect.y,
|
|
@@ -55,9 +55,8 @@ var diamondOf = (layout, marginAdd) => ({
|
|
|
55
55
|
rotate: layout.rect.rotate
|
|
56
56
|
});
|
|
57
57
|
/**
|
|
58
|
-
* 取节点 shape 在 toward
|
|
59
|
-
* 按 shape
|
|
60
|
-
* margin > 0 时形状先外扩,让 path 在 border 外停 margin 个 user units。
|
|
58
|
+
* 取节点 shape 在 toward 方向的附着点(path 端点贴边用)
|
|
59
|
+
* @description 按 shape 多态调用各自 boundaryPoint;margin > 0 时形状先外扩,让 path 在 border 外停 margin
|
|
61
60
|
*/
|
|
62
61
|
var boundaryPointOf = (layout, toward) => {
|
|
63
62
|
const m = layout.margin;
|
|
@@ -69,9 +68,8 @@ var boundaryPointOf = (layout, toward) => {
|
|
|
69
68
|
}
|
|
70
69
|
};
|
|
71
70
|
/**
|
|
72
|
-
* 取节点 shape
|
|
73
|
-
*
|
|
74
|
-
* 用于 `'A.north'` 这种语法落点。
|
|
71
|
+
* 取节点 shape 命名 anchor(center / north / east / north-east 等 9 个)
|
|
72
|
+
* @description 不应用 margin——TikZ 语义中 explicit anchor 取视觉边界点不涉及 outer sep;用于 `'A.north'` 落点
|
|
75
73
|
*/
|
|
76
74
|
var anchorOf = (layout, name) => {
|
|
77
75
|
switch (layout.shape) {
|
|
@@ -81,10 +79,7 @@ var anchorOf = (layout, name) => {
|
|
|
81
79
|
case "diamond": return diamond.anchor(diamondOf(layout, 0), name);
|
|
82
80
|
}
|
|
83
81
|
};
|
|
84
|
-
/**
|
|
85
|
-
* 8 方向 label position → (anchorName, 单位向量) 映射。
|
|
86
|
-
* 视觉语义与 `at.direction` 一致——above 是视觉上方(y 减小)。
|
|
87
|
-
*/
|
|
82
|
+
/** 8 方向 label position → (anchorName, 单位向量);above 视觉上方即 y 减小 */
|
|
88
83
|
var LABEL_DIRECTION_MAP = {
|
|
89
84
|
above: {
|
|
90
85
|
anchor: "north",
|
|
@@ -120,9 +115,8 @@ var LABEL_DIRECTION_MAP = {
|
|
|
120
115
|
}
|
|
121
116
|
};
|
|
122
117
|
/**
|
|
123
|
-
* 算 label
|
|
124
|
-
*
|
|
125
|
-
* - 数字角度:先取 angleBoundary 边界点,再沿 (cos, sin) 单位向量 × distance 外推
|
|
118
|
+
* 算 label 中心点
|
|
119
|
+
* @description 8 方向:节点对应 anchor 出发按单位向量 × distance 外推;数字角度:先取 angleBoundary 边界点再沿 (cos,sin) × distance 外推
|
|
126
120
|
*/
|
|
127
121
|
var labelCenter = (layout, label) => {
|
|
128
122
|
if (typeof label.position === "number") {
|
|
@@ -135,9 +129,8 @@ var labelCenter = (layout, label) => {
|
|
|
135
129
|
return [bx + vec[0] * label.distance, by + vec[1] * label.distance];
|
|
136
130
|
};
|
|
137
131
|
/**
|
|
138
|
-
* 取节点 shape
|
|
139
|
-
*
|
|
140
|
-
* **不应用 margin**——同 anchorOf。用于 `'A.30'` 这种语法落点。
|
|
132
|
+
* 取节点 shape 在指定角度方向的边界点
|
|
133
|
+
* @description 角度约定与 PolarPosition 一致(度数:0°=+x,90°=+y 即 screen 下方);不应用 margin(同 anchorOf);用于 `'A.30'` 落点
|
|
141
134
|
*/
|
|
142
135
|
var angleBoundaryOf = (layout, angleDeg) => {
|
|
143
136
|
const rad = angleDeg * Math.PI / 180;
|
|
@@ -150,12 +143,8 @@ var angleBoundaryOf = (layout, angleDeg) => {
|
|
|
150
143
|
}
|
|
151
144
|
};
|
|
152
145
|
/**
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
* - 按 shape 决定外接边界尺寸(circle 取半对角线、ellipse 各 ×√2、diamond 各 ×2)
|
|
156
|
-
* - 解析 position(笛卡尔或极坐标)为几何中心
|
|
157
|
-
* - IR 的 rotate(度数)转弧度存进 Rect.rotate
|
|
158
|
-
* - 透传 margin / 样式属性
|
|
146
|
+
* IR Node → 内部 NodeLayout
|
|
147
|
+
* @description 文本度量 + padding 推内框半轴;按 shape 算外接边界(circle 取半对角线、ellipse ×√2、diamond ×2);解析 position 为几何中心;rotate 度数转弧度
|
|
159
148
|
*/
|
|
160
149
|
var layoutNode = (node, measureText, nodeIndex, nodeDistance) => {
|
|
161
150
|
const sx = node.xScale ?? node.scale ?? 1;
|
|
@@ -277,7 +266,7 @@ var layoutNode = (node, measureText, nodeIndex, nodeDistance) => {
|
|
|
277
266
|
labels
|
|
278
267
|
};
|
|
279
268
|
};
|
|
280
|
-
/** rectangle
|
|
269
|
+
/** rectangle → RectPrim */
|
|
281
270
|
var emitRectShape = (layout, round) => {
|
|
282
271
|
const halfW = layout.rect.width / 2;
|
|
283
272
|
const halfH = layout.rect.height / 2;
|
|
@@ -297,7 +286,7 @@ var emitRectShape = (layout, round) => {
|
|
|
297
286
|
opacity: layout.opacity
|
|
298
287
|
};
|
|
299
288
|
};
|
|
300
|
-
/** circle
|
|
289
|
+
/** circle/ellipse → EllipsePrim(圆形 rx=ry) */
|
|
301
290
|
var emitEllipseShape = (layout, round) => ({
|
|
302
291
|
type: "ellipse",
|
|
303
292
|
cx: round(layout.rect.x),
|
|
@@ -312,7 +301,7 @@ var emitEllipseShape = (layout, round) => ({
|
|
|
312
301
|
strokeDasharray: layout.strokeDasharray,
|
|
313
302
|
opacity: layout.opacity
|
|
314
303
|
});
|
|
315
|
-
/** diamond
|
|
304
|
+
/** diamond → PathPrim(4 顶点 + close 闭合) */
|
|
316
305
|
var emitDiamondShape = (layout, round) => {
|
|
317
306
|
const diam = diamondOf(layout, 0);
|
|
318
307
|
const e = diamond.anchor(diam, "east");
|
|
@@ -321,7 +310,25 @@ var emitDiamondShape = (layout, round) => {
|
|
|
321
310
|
const s = diamond.anchor(diam, "south");
|
|
322
311
|
return {
|
|
323
312
|
type: "path",
|
|
324
|
-
|
|
313
|
+
commands: [
|
|
314
|
+
{
|
|
315
|
+
kind: "move",
|
|
316
|
+
to: [round(e[0]), round(e[1])]
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
kind: "line",
|
|
320
|
+
to: [round(n[0]), round(n[1])]
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
kind: "line",
|
|
324
|
+
to: [round(w[0]), round(w[1])]
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
kind: "line",
|
|
328
|
+
to: [round(s[0]), round(s[1])]
|
|
329
|
+
},
|
|
330
|
+
{ kind: "close" }
|
|
331
|
+
],
|
|
325
332
|
fill: layout.fill ?? "transparent",
|
|
326
333
|
fillOpacity: layout.fillOpacity,
|
|
327
334
|
stroke: layout.stroke ?? "currentColor",
|
|
@@ -332,12 +339,8 @@ var emitDiamondShape = (layout, round) => {
|
|
|
332
339
|
};
|
|
333
340
|
};
|
|
334
341
|
/**
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
* - text(如有内容):始终走 TextPrim
|
|
338
|
-
* - 若有旋转:外面套一层 GroupPrim 用 SVG `rotate(deg cx cy)` 实现
|
|
339
|
-
* (PathPrim 的 diamond 顶点已自带旋转坐标,但 text 需要 group 旋转,
|
|
340
|
-
* 所以仍统一用 group 包裹)
|
|
342
|
+
* NodeLayout → Scene primitives
|
|
343
|
+
* @description shape 主体按 shape 分发(rect/ellipse/path);text 始终走 TextPrim;有旋转时外层 GroupPrim 用 `rotate(deg cx cy)` 统一包裹(text 必须靠 group 旋转)
|
|
341
344
|
*/
|
|
342
345
|
var emitNodePrimitives = (layout, round) => {
|
|
343
346
|
let shapePrim;
|
|
@@ -398,11 +401,16 @@ var emitNodePrimitives = (layout, round) => {
|
|
|
398
401
|
if (layout.rotateDeg === 0) return inner;
|
|
399
402
|
return [{
|
|
400
403
|
type: "group",
|
|
401
|
-
|
|
404
|
+
transforms: [{
|
|
405
|
+
kind: "rotate",
|
|
406
|
+
degrees: round(layout.rotateDeg),
|
|
407
|
+
cx: round(layout.rect.x),
|
|
408
|
+
cy: round(layout.rect.y)
|
|
409
|
+
}],
|
|
402
410
|
children: inner
|
|
403
411
|
}];
|
|
404
412
|
};
|
|
405
|
-
/**
|
|
413
|
+
/** layout 的"未旋转"副本,让 diamond 顶点先按未旋转算,外层 group 统一旋转 */
|
|
406
414
|
var unrotated = (layout) => ({
|
|
407
415
|
...layout,
|
|
408
416
|
rect: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RectAnchor } from '../geometry/rect';
|
|
2
|
-
/**
|
|
2
|
+
/** 节点 ref 解析后三态 */
|
|
3
3
|
export type ParsedNodeRef = {
|
|
4
4
|
kind: 'node';
|
|
5
5
|
id: string;
|
|
@@ -13,13 +13,8 @@ export type ParsedNodeRef = {
|
|
|
13
13
|
angle: number;
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
|
-
* 解析节点 ref
|
|
17
|
-
*
|
|
18
|
-
* - 不带 `.`:node(auto-clip)
|
|
19
|
-
* - 带 `.` 后纯数字:angle(toward 方向上的边界点,与 PolarPosition 同角度约定)
|
|
20
|
-
* - 带 `.` 后字母 / 连字符:anchor(命中 ANCHOR_NAMES 才合法,否则抛错)
|
|
21
|
-
*
|
|
22
|
-
* 抛错路径:未知 anchor 名(避免静默吞掉拼写错误)。
|
|
16
|
+
* 解析节点 ref 字符串
|
|
17
|
+
* @description 不带 `.`→node(auto-clip);带 `.` 后纯数字→angle;带 `.` 后字母/连字符→anchor(不命中 ANCHOR_NAMES 抛错避免静默吞拼写错误)
|
|
23
18
|
*/
|
|
24
19
|
export declare const parseNodeRef: (s: string) => ParsedNodeRef;
|
|
25
20
|
//# sourceMappingURL=parseTarget.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseTarget.d.ts","sourceRoot":"","sources":["../../../src/compile/parseTarget.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"parseTarget.d.ts","sourceRoot":"","sources":["../../../src/compile/parseTarget.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAQjE,mBAAmB;AACnB,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAC5B;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,UAAU,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjD;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,GAAG,MAAM,KAAG,aAcxC,CAAC"}
|