@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,28 +1,16 @@
|
|
|
1
1
|
import { RECT_ANCHORS } from "../geometry/rect.js";
|
|
2
2
|
//#region src/compile/parseTarget.ts
|
|
3
3
|
/**
|
|
4
|
-
* 节点 ref
|
|
5
|
-
*
|
|
6
|
-
* `'A'` → 节点 A,由 path 自动 boundary clip(auto 模式)
|
|
7
|
-
* `'A.<name>'` → 节点 A 的命名 anchor(center/north/south/east/west/north-east/...)
|
|
8
|
-
* `'A.<deg>'` → 节点 A 在 degree 角度方向上的边界点(同 PolarPosition 角度约定)
|
|
9
|
-
*
|
|
10
|
-
* id 约束:`[A-Za-z_][\w-]*`——禁数字开头、禁含 `.`(与 anchor 分隔符冲突);
|
|
11
|
-
* anchor 名只接受 alpha.1 首批 9 个 RECT_ANCHORS(其余如 'text' / 'base' / 'mid'
|
|
12
|
-
* 留 alpha.2 + 字体改造时再支持);角度纯数字(含可选 `.`/`-`)。
|
|
4
|
+
* 节点 ref 字符串扩展语法
|
|
5
|
+
* @description `'A'`→节点(auto boundary clip);`'A.<name>'`→命名 anchor(center/north/.../north-east);`'A.<deg>'`→角度方向边界点(同 PolarPosition 约定)。id 约束 `[A-Za-z_][\w-]*` 禁数字开头与 `.`;角度纯数字含可选 `.`/`-`
|
|
13
6
|
*/
|
|
14
|
-
/**
|
|
7
|
+
/** RECT_ANCHORS 的 9 个 anchor 名 */
|
|
15
8
|
var ANCHOR_NAMES = new Set(Object.values(RECT_ANCHORS));
|
|
16
|
-
/**
|
|
9
|
+
/** 纯数字识别 `A.30` / `A.-45` / `A.180.5` */
|
|
17
10
|
var ANGLE_RE = /^-?\d+(\.\d+)?$/;
|
|
18
11
|
/**
|
|
19
|
-
* 解析节点 ref
|
|
20
|
-
*
|
|
21
|
-
* - 不带 `.`:node(auto-clip)
|
|
22
|
-
* - 带 `.` 后纯数字:angle(toward 方向上的边界点,与 PolarPosition 同角度约定)
|
|
23
|
-
* - 带 `.` 后字母 / 连字符:anchor(命中 ANCHOR_NAMES 才合法,否则抛错)
|
|
24
|
-
*
|
|
25
|
-
* 抛错路径:未知 anchor 名(避免静默吞掉拼写错误)。
|
|
12
|
+
* 解析节点 ref 字符串
|
|
13
|
+
* @description 不带 `.`→node(auto-clip);带 `.` 后纯数字→angle;带 `.` 后字母/连字符→anchor(不命中 ANCHOR_NAMES 抛错避免静默吞拼写错误)
|
|
26
14
|
*/
|
|
27
15
|
var parseNodeRef = (s) => {
|
|
28
16
|
const dot = s.indexOf(".");
|
|
@@ -37,7 +25,7 @@ var parseNodeRef = (s) => {
|
|
|
37
25
|
id,
|
|
38
26
|
angle: Number(tail)
|
|
39
27
|
};
|
|
40
|
-
if (!ANCHOR_NAMES.has(tail)) throw new Error(`parseNodeRef: unknown anchor '${tail}' in '${s}' (
|
|
28
|
+
if (!ANCHOR_NAMES.has(tail)) throw new Error(`parseNodeRef: unknown anchor '${tail}' in '${s}' (supports: ${[...ANCHOR_NAMES].join(", ")})`);
|
|
41
29
|
return {
|
|
42
30
|
kind: "anchor",
|
|
43
31
|
id,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IRPosition, IRTarget } from '../../ir';
|
|
2
|
+
import { NodeLayout } from '../node';
|
|
3
|
+
/**
|
|
4
|
+
* 求 step.to 的参考点(给 boundary clip 算方向 / 折角 corner 用)
|
|
5
|
+
* @description 三态:`'A'`(auto) 节点中心;`'A.<anchor>'`/`'A.<deg>'` 显式锚点 refPoint=endpoint 位置不随邻居变。直接坐标/极坐标解析为笛卡尔
|
|
6
|
+
*/
|
|
7
|
+
export declare const refPointOfTarget: (target: IRTarget, nodeIndex: Map<string, NodeLayout>) => IRPosition | null;
|
|
8
|
+
/** 折角中间点:`-|` → (curr.x, prev.y);`|-` → (prev.x, curr.y) */
|
|
9
|
+
export declare const cornerOf: (prev: IRPosition, curr: IRPosition, via: "-|" | "|-") => IRPosition;
|
|
10
|
+
/**
|
|
11
|
+
* 在 toward 方向算 step.to 的实际绘制端点
|
|
12
|
+
* @description 节点 auto `'A'`:按 shape 走 boundaryPointOf 求中心→toward 射线交点;命名 anchor/角度:位置已定不受 toward 影响;直接坐标/极坐标:解析后返回;失败返回 null
|
|
13
|
+
*/
|
|
14
|
+
export declare const clipForTarget: (target: IRTarget, toward: IRPosition, nodeIndex: Map<string, NodeLayout>) => IRPosition | null;
|
|
15
|
+
/** 两个 IRPosition 两分量精确相等(未 round) */
|
|
16
|
+
export declare const samePoint: (a: IRPosition | null, b: IRPosition | null) => boolean;
|
|
17
|
+
/** 把 p 朝 target 方向移动 dist */
|
|
18
|
+
export declare const shiftToward: (p: IRPosition, target: IRPosition, dist: number) => IRPosition;
|
|
19
|
+
//# sourceMappingURL=anchor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anchor.d.ts","sourceRoot":"","sources":["../../../../src/compile/path/anchor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,KAAK,UAAU,EAA8C,MAAM,SAAS,CAAC;AAItF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAC3B,QAAQ,QAAQ,EAChB,WAAW,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,KACjC,UAAU,GAAG,IAmBf,CAAC;AAEF,4DAA4D;AAC5D,eAAO,MAAM,QAAQ,GACnB,MAAM,UAAU,EAChB,MAAM,UAAU,EAChB,KAAK,IAAI,GAAG,IAAI,KACf,UACqD,CAAC;AAEzD;;;GAGG;AACH,eAAO,MAAM,aAAa,GACxB,QAAQ,QAAQ,EAChB,QAAQ,UAAU,EAClB,WAAW,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,KACjC,UAAU,GAAG,IAmBf,CAAC;AAEF,qCAAqC;AACrC,eAAO,MAAM,SAAS,GAAI,GAAG,UAAU,GAAG,IAAI,EAAE,GAAG,UAAU,GAAG,IAAI,KAAG,OACzB,CAAC;AAE/C,6BAA6B;AAC7B,eAAO,MAAM,WAAW,GAAI,GAAG,UAAU,EAAE,QAAQ,UAAU,EAAE,MAAM,MAAM,KAAG,UAM7E,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { resolvePosition } from "../position.js";
|
|
2
|
+
import { anchorOf, angleBoundaryOf, boundaryPointOf } from "../node.js";
|
|
3
|
+
import { parseNodeRef } from "../parseTarget.js";
|
|
4
|
+
//#region src/compile/path/anchor.ts
|
|
5
|
+
/**
|
|
6
|
+
* 求 step.to 的参考点(给 boundary clip 算方向 / 折角 corner 用)
|
|
7
|
+
* @description 三态:`'A'`(auto) 节点中心;`'A.<anchor>'`/`'A.<deg>'` 显式锚点 refPoint=endpoint 位置不随邻居变。直接坐标/极坐标解析为笛卡尔
|
|
8
|
+
*/
|
|
9
|
+
var refPointOfTarget = (target, nodeIndex) => {
|
|
10
|
+
if (typeof target === "string") {
|
|
11
|
+
const ref = parseNodeRef(target);
|
|
12
|
+
const node = nodeIndex.get(ref.id);
|
|
13
|
+
if (!node) return null;
|
|
14
|
+
switch (ref.kind) {
|
|
15
|
+
case "node": return [node.rect.x, node.rect.y];
|
|
16
|
+
case "anchor": return anchorOf(node, ref.anchor);
|
|
17
|
+
case "angle": return angleBoundaryOf(node, ref.angle);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (typeof target === "object" && !Array.isArray(target) && ("relative" in target || "relativeAccumulate" in target)) return null;
|
|
21
|
+
return resolvePosition(target, nodeIndex);
|
|
22
|
+
};
|
|
23
|
+
/** 折角中间点:`-|` → (curr.x, prev.y);`|-` → (prev.x, curr.y) */
|
|
24
|
+
var cornerOf = (prev, curr, via) => via === "-|" ? [curr[0], prev[1]] : [prev[0], curr[1]];
|
|
25
|
+
/**
|
|
26
|
+
* 在 toward 方向算 step.to 的实际绘制端点
|
|
27
|
+
* @description 节点 auto `'A'`:按 shape 走 boundaryPointOf 求中心→toward 射线交点;命名 anchor/角度:位置已定不受 toward 影响;直接坐标/极坐标:解析后返回;失败返回 null
|
|
28
|
+
*/
|
|
29
|
+
var clipForTarget = (target, toward, nodeIndex) => {
|
|
30
|
+
if (typeof target === "string") {
|
|
31
|
+
const ref = parseNodeRef(target);
|
|
32
|
+
const node = nodeIndex.get(ref.id);
|
|
33
|
+
if (!node) return null;
|
|
34
|
+
switch (ref.kind) {
|
|
35
|
+
case "node": return boundaryPointOf(node, toward);
|
|
36
|
+
case "anchor": return anchorOf(node, ref.anchor);
|
|
37
|
+
case "angle": return angleBoundaryOf(node, ref.angle);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (typeof target === "object" && !Array.isArray(target) && ("relative" in target || "relativeAccumulate" in target)) return null;
|
|
41
|
+
return resolvePosition(target, nodeIndex);
|
|
42
|
+
};
|
|
43
|
+
/** 两个 IRPosition 两分量精确相等(未 round) */
|
|
44
|
+
var samePoint = (a, b) => !!a && !!b && a[0] === b[0] && a[1] === b[1];
|
|
45
|
+
/** 把 p 朝 target 方向移动 dist */
|
|
46
|
+
var shiftToward = (p, target, dist) => {
|
|
47
|
+
const dx = target[0] - p[0];
|
|
48
|
+
const dy = target[1] - p[1];
|
|
49
|
+
const len = Math.sqrt(dx * dx + dy * dy);
|
|
50
|
+
if (len === 0 || dist === 0) return p;
|
|
51
|
+
return [p[0] + dx / len * dist, p[1] + dy / len * dist];
|
|
52
|
+
};
|
|
53
|
+
//#endregion
|
|
54
|
+
export { clipForTarget, cornerOf, refPointOfTarget, samePoint, shiftToward };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IRPath, IRPosition } from '../../ir';
|
|
2
|
+
import { ScenePrimitive } from '../../primitive';
|
|
3
|
+
import { NodeLayout } from '../node';
|
|
4
|
+
import { TextMeasurer } from '../text-metrics';
|
|
5
|
+
/** emitPathPrimitive 可选 warn 钩子 */
|
|
6
|
+
export type EmitPathWarnHook = {
|
|
7
|
+
/** 警告收集器(由 compileToScene 传入) */
|
|
8
|
+
onWarn?: (warning: {
|
|
9
|
+
code: string;
|
|
10
|
+
message: string;
|
|
11
|
+
path: string;
|
|
12
|
+
}) => void;
|
|
13
|
+
/** 当前 path 在 IR 中的 locator 前缀(如 `'children[3].path'`) */
|
|
14
|
+
irPath?: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* IR Path → PathPrim
|
|
18
|
+
* @description 每个绘制段独立用节点中心算两端 boundary clip——中段节点的入/出 boundary 点通常不同,path 在该节点可见"断开"(与 TikZ `\draw (A)--(B)--(C);` 段独立 clip 一致)。仍产一个 PathPrim:commands 用多组 move/line 表达 sub-path;段起点等于上段终点时复用 cursor 省 move。cycle 段闭回最近 move 起点,起点==lastEnd && 终点==subPathStart 时输出 close,否则显式画段 line。引用未定义节点/解析失败返回 null,并通过 `warnHook.onWarn` 同步触发 warning
|
|
19
|
+
*/
|
|
20
|
+
export declare const emitPathPrimitive: (path: IRPath, nodeIndex: Map<string, NodeLayout>, round: (n: number) => number, measureText?: TextMeasurer, warnHook?: EmitPathWarnHook) => {
|
|
21
|
+
primitives: Array<ScenePrimitive>;
|
|
22
|
+
points: Array<IRPosition>;
|
|
23
|
+
} | null;
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/compile/path/index.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACV,MAAM,EACN,UAAU,EAGX,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAEV,cAAc,EACf,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,KAAK,YAAY,EAAoB,MAAM,iBAAiB,CAAC;AA8BtE,mCAAmC;AACnC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,iCAAiC;IACjC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;KACd,KAAK,IAAI,CAAC;IACX,yDAAyD;IACzD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,MAAM,EACZ,WAAW,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,EAClC,OAAO,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,EAC5B,cAAa,YAA+B,EAC5C,WAAU,gBAAqB,KAC9B;IAAE,UAAU,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IAAC,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC,CAAA;CAAE,GAAG,IA0XrE,CAAC"}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { arcBoundingPoints, arcEndPoint } from "../../geometry/arc.js";
|
|
2
|
+
import { bendControlPoints } from "../../geometry/bend.js";
|
|
3
|
+
import { arcSegmentSample, circleSegmentSample, cubicSegmentSample, ellipseSegmentSample, foldSegmentSample, lineSegmentSample, quadSegmentSample } from "../../geometry/segment.js";
|
|
4
|
+
import { fallbackMeasurer } from "../text-metrics.js";
|
|
5
|
+
import { clipForTarget, cornerOf, refPointOfTarget, samePoint } from "./anchor.js";
|
|
6
|
+
import { emitLabelPrimitive, tForLabelPosition } from "./label.js";
|
|
7
|
+
import { normalizeRelativeTargets } from "./relative.js";
|
|
8
|
+
import { applyArrowShrinks, arrowMarkers, computeShrink } from "./shrink.js";
|
|
9
|
+
import { splitSubPathsForMarkers } from "./split.js";
|
|
10
|
+
//#region src/compile/path/index.ts
|
|
11
|
+
/**
|
|
12
|
+
* 语义 stroke 档位 → 数值(user units)
|
|
13
|
+
* @description 对齐 TikZ 比例(thin=0.4pt→1=默认 strokeWidth):ultraThin 0.25、veryThin 0.5、thin 1、semithick 1.5、thick 2、veryThick 3、ultraThick 4。显式 strokeWidth 覆盖 thickness。
|
|
14
|
+
* `as const satisfies` + `AssertEqual` 双约束:加 IRPath['thickness'] 档位时漏写 TS 报错(字段表互锁,同 ADR-06 主题)
|
|
15
|
+
*/
|
|
16
|
+
var THICKNESS_TO_WIDTH = {
|
|
17
|
+
ultraThin: .25,
|
|
18
|
+
veryThin: .5,
|
|
19
|
+
thin: 1,
|
|
20
|
+
semithick: 1.5,
|
|
21
|
+
thick: 2,
|
|
22
|
+
veryThick: 3,
|
|
23
|
+
ultraThick: 4
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* IR Path → PathPrim
|
|
27
|
+
* @description 每个绘制段独立用节点中心算两端 boundary clip——中段节点的入/出 boundary 点通常不同,path 在该节点可见"断开"(与 TikZ `\draw (A)--(B)--(C);` 段独立 clip 一致)。仍产一个 PathPrim:commands 用多组 move/line 表达 sub-path;段起点等于上段终点时复用 cursor 省 move。cycle 段闭回最近 move 起点,起点==lastEnd && 终点==subPathStart 时输出 close,否则显式画段 line。引用未定义节点/解析失败返回 null,并通过 `warnHook.onWarn` 同步触发 warning
|
|
28
|
+
*/
|
|
29
|
+
var emitPathPrimitive = (path, nodeIndex, round, measureText = fallbackMeasurer, warnHook = {}) => {
|
|
30
|
+
const irPath = warnHook.irPath ?? "path";
|
|
31
|
+
const warn = (code, message, subPath = "") => {
|
|
32
|
+
warnHook.onWarn?.({
|
|
33
|
+
code,
|
|
34
|
+
message,
|
|
35
|
+
path: subPath ? `${irPath}.${subPath}` : irPath
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
const steps = normalizeRelativeTargets(path.children, nodeIndex);
|
|
39
|
+
if (steps.length < 2) {
|
|
40
|
+
warn("PATH_TOO_SHORT", `Path requires at least 2 steps (got ${steps.length}); the entire path is skipped`, "children");
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
/** 每段 step.label 翻译出的 TextPrim(或 sloped 旋转的 group),与 path 主体同级返回 */
|
|
44
|
+
const labelPrims = [];
|
|
45
|
+
/** 算 sample 后 emitLabelPrimitive,结果累积到 labelPrims/points */
|
|
46
|
+
const collectLabel = (step, sampleAt) => {
|
|
47
|
+
if (step.kind === "move" || step.kind === "cycle" || !("label" in step) || !step.label) return;
|
|
48
|
+
const sample = sampleAt(tForLabelPosition(step.label.position));
|
|
49
|
+
const r = emitLabelPrimitive(step.label, sample, measureText, round);
|
|
50
|
+
labelPrims.push(r.primitive);
|
|
51
|
+
for (const p of r.points) points.push(p);
|
|
52
|
+
};
|
|
53
|
+
const hasTo = (s) => s.kind !== "cycle" && s.kind !== "arc" && s.kind !== "circlePath" && s.kind !== "ellipsePath";
|
|
54
|
+
const anchors = steps.map((s, idx) => {
|
|
55
|
+
if (!hasTo(s)) return null;
|
|
56
|
+
const ref = refPointOfTarget(s.to, nodeIndex);
|
|
57
|
+
if (!ref && typeof s.to === "string") warn("UNRESOLVED_NODE_REFERENCE", `Step.to references undefined node id '${s.to}'; the entire path is skipped`, `children[${idx}].to`);
|
|
58
|
+
return ref;
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* 单调指针:最近一个 hasTo step 的索引;主循环开头根据上一 step 推进;O(1) 读
|
|
62
|
+
* @description 旧实现 findPrev(i) 反向扫 anchors 数组每步 O(i)、整 path O(n²);改为只在 step `i-1` 是 hasTo 时推进。anchor 失效"中毒"判断保留:lastHasToIdx 指向的 anchor 为 null 时 findPrev 返回 null,与旧"扫到第一个 hasTo 步若 anchor=null 返回 null"语义等价
|
|
63
|
+
*/
|
|
64
|
+
let lastHasToIdx = -1;
|
|
65
|
+
/** 同步维护:最近一个 move 步的 `to`,给 cycle 闭合用;旧 findRecentMoveTo 反向扫 → O(1) */
|
|
66
|
+
let lastMoveTo = null;
|
|
67
|
+
/** 找最近一个"有 to 字段的 step" 及其 anchor;O(1) 读 lastHasToIdx */
|
|
68
|
+
const findPrev = () => {
|
|
69
|
+
if (lastHasToIdx === -1) return null;
|
|
70
|
+
const s = steps[lastHasToIdx];
|
|
71
|
+
if (!hasTo(s)) return null;
|
|
72
|
+
const a = anchors[lastHasToIdx];
|
|
73
|
+
if (!a) return null;
|
|
74
|
+
return {
|
|
75
|
+
step: s,
|
|
76
|
+
anchor: a
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
const commands = [];
|
|
80
|
+
const points = [];
|
|
81
|
+
let lastEnd = null;
|
|
82
|
+
let subPathStart = null;
|
|
83
|
+
/**
|
|
84
|
+
* 笔位覆盖:arc/circlePath/ellipsePath 无 `to` 字段不能用 prev.step.to 重算起点
|
|
85
|
+
* @description 设置 penOverride 让下个绘制段直接用此点当 fromClip 后清空。arc=弧终点;circlePath/ellipsePath=center("画完留在圆心")
|
|
86
|
+
*/
|
|
87
|
+
let penOverride = null;
|
|
88
|
+
const roundPoint = (p) => [round(p[0]), round(p[1])];
|
|
89
|
+
const emitMove = (p) => {
|
|
90
|
+
const rp = roundPoint(p);
|
|
91
|
+
commands.push({
|
|
92
|
+
kind: "move",
|
|
93
|
+
to: [rp[0], rp[1]]
|
|
94
|
+
});
|
|
95
|
+
points.push(p);
|
|
96
|
+
subPathStart = p;
|
|
97
|
+
lastEnd = p;
|
|
98
|
+
};
|
|
99
|
+
const emitLine = (p) => {
|
|
100
|
+
const rp = roundPoint(p);
|
|
101
|
+
commands.push({
|
|
102
|
+
kind: "line",
|
|
103
|
+
to: [rp[0], rp[1]]
|
|
104
|
+
});
|
|
105
|
+
points.push(p);
|
|
106
|
+
lastEnd = p;
|
|
107
|
+
};
|
|
108
|
+
const emitClose = () => {
|
|
109
|
+
commands.push({ kind: "close" });
|
|
110
|
+
lastEnd = subPathStart;
|
|
111
|
+
};
|
|
112
|
+
const emitQuad = (control, p) => {
|
|
113
|
+
const rc = roundPoint(control);
|
|
114
|
+
const rp = roundPoint(p);
|
|
115
|
+
commands.push({
|
|
116
|
+
kind: "quad",
|
|
117
|
+
control: [rc[0], rc[1]],
|
|
118
|
+
to: [rp[0], rp[1]]
|
|
119
|
+
});
|
|
120
|
+
points.push(control);
|
|
121
|
+
points.push(p);
|
|
122
|
+
lastEnd = p;
|
|
123
|
+
};
|
|
124
|
+
const emitCubic = (c1, c2, p) => {
|
|
125
|
+
const rc1 = roundPoint(c1);
|
|
126
|
+
const rc2 = roundPoint(c2);
|
|
127
|
+
const rp = roundPoint(p);
|
|
128
|
+
commands.push({
|
|
129
|
+
kind: "cubic",
|
|
130
|
+
control1: [rc1[0], rc1[1]],
|
|
131
|
+
control2: [rc2[0], rc2[1]],
|
|
132
|
+
to: [rp[0], rp[1]]
|
|
133
|
+
});
|
|
134
|
+
points.push(c1);
|
|
135
|
+
points.push(c2);
|
|
136
|
+
points.push(p);
|
|
137
|
+
lastEnd = p;
|
|
138
|
+
};
|
|
139
|
+
const emitArc = (center, radius, startAngle, endAngle) => {
|
|
140
|
+
const rc = roundPoint(center);
|
|
141
|
+
commands.push({
|
|
142
|
+
kind: "arc",
|
|
143
|
+
center: [rc[0], rc[1]],
|
|
144
|
+
radius: round(radius),
|
|
145
|
+
startAngle,
|
|
146
|
+
endAngle
|
|
147
|
+
});
|
|
148
|
+
points.push(arcEndPoint(center, radius, endAngle));
|
|
149
|
+
lastEnd = arcEndPoint(center, radius, endAngle);
|
|
150
|
+
};
|
|
151
|
+
const emitEllipseArc = (center, radiusX, radiusY, startAngle, endAngle) => {
|
|
152
|
+
const rc = roundPoint(center);
|
|
153
|
+
commands.push({
|
|
154
|
+
kind: "ellipseArc",
|
|
155
|
+
center: [rc[0], rc[1]],
|
|
156
|
+
radiusX: round(radiusX),
|
|
157
|
+
radiusY: round(radiusY),
|
|
158
|
+
startAngle,
|
|
159
|
+
endAngle
|
|
160
|
+
});
|
|
161
|
+
const endPt = [center[0] + Math.cos(endAngle * Math.PI / 180) * radiusX, center[1] + Math.sin(endAngle * Math.PI / 180) * radiusY];
|
|
162
|
+
points.push(endPt);
|
|
163
|
+
lastEnd = endPt;
|
|
164
|
+
};
|
|
165
|
+
/** 段起点:与 lastEnd 相同则复用 cursor(省 move),否则发 move */
|
|
166
|
+
const startSegment = (p) => {
|
|
167
|
+
if (samePoint(p, lastEnd)) return;
|
|
168
|
+
emitMove(p);
|
|
169
|
+
};
|
|
170
|
+
for (let i = 0; i < steps.length; i++) {
|
|
171
|
+
if (i > 0) {
|
|
172
|
+
const prevStep = steps[i - 1];
|
|
173
|
+
if (hasTo(prevStep)) lastHasToIdx = i - 1;
|
|
174
|
+
if (prevStep.kind === "move") lastMoveTo = prevStep.to;
|
|
175
|
+
}
|
|
176
|
+
const step = steps[i];
|
|
177
|
+
if (step.kind === "move") continue;
|
|
178
|
+
if (step.kind === "cycle") {
|
|
179
|
+
const moveTo = lastMoveTo;
|
|
180
|
+
const prev = findPrev();
|
|
181
|
+
if (!moveTo || !prev) continue;
|
|
182
|
+
const moveAnchor = refPointOfTarget(moveTo, nodeIndex);
|
|
183
|
+
if (!moveAnchor) return null;
|
|
184
|
+
const fromClip = clipForTarget(prev.step.to, moveAnchor, nodeIndex);
|
|
185
|
+
const toClip = clipForTarget(moveTo, prev.anchor, nodeIndex);
|
|
186
|
+
if (!fromClip || !toClip) return null;
|
|
187
|
+
if (samePoint(fromClip, lastEnd) && samePoint(toClip, subPathStart)) {
|
|
188
|
+
emitClose();
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
startSegment(fromClip);
|
|
192
|
+
emitLine(toClip);
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
const prev = findPrev();
|
|
196
|
+
if (!prev) return null;
|
|
197
|
+
if (step.kind === "arc") {
|
|
198
|
+
const center = prev.anchor;
|
|
199
|
+
const startPt = arcEndPoint(center, step.radius, step.startAngle);
|
|
200
|
+
const endPt = arcEndPoint(center, step.radius, step.endAngle);
|
|
201
|
+
startSegment(startPt);
|
|
202
|
+
emitArc(center, step.radius, step.startAngle, step.endAngle);
|
|
203
|
+
for (const p of arcBoundingPoints(center, step.radius, step.startAngle, step.endAngle)) points.push(p);
|
|
204
|
+
collectLabel(step, (t) => arcSegmentSample(center, step.radius, step.startAngle, step.endAngle, t));
|
|
205
|
+
penOverride = endPt;
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
if (step.kind === "circlePath") {
|
|
209
|
+
const center = prev.anchor;
|
|
210
|
+
const r = step.radius;
|
|
211
|
+
startSegment([center[0] + r, center[1]]);
|
|
212
|
+
emitEllipseArc(center, r, r, 0, 360);
|
|
213
|
+
points.push([center[0] + r, center[1]]);
|
|
214
|
+
points.push([center[0] - r, center[1]]);
|
|
215
|
+
points.push([center[0], center[1] + r]);
|
|
216
|
+
points.push([center[0], center[1] - r]);
|
|
217
|
+
collectLabel(step, (t) => circleSegmentSample(center, r, t));
|
|
218
|
+
penOverride = center;
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
if (step.kind === "ellipsePath") {
|
|
222
|
+
const center = prev.anchor;
|
|
223
|
+
const rx = step.radiusX;
|
|
224
|
+
const ry = step.radiusY;
|
|
225
|
+
startSegment([center[0] + rx, center[1]]);
|
|
226
|
+
emitEllipseArc(center, rx, ry, 0, 360);
|
|
227
|
+
points.push([center[0] + rx, center[1]]);
|
|
228
|
+
points.push([center[0] - rx, center[1]]);
|
|
229
|
+
points.push([center[0], center[1] + ry]);
|
|
230
|
+
points.push([center[0], center[1] - ry]);
|
|
231
|
+
collectLabel(step, (t) => ellipseSegmentSample(center, rx, ry, t));
|
|
232
|
+
penOverride = center;
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
const currAnchor = anchors[i];
|
|
236
|
+
if (!currAnchor) return null;
|
|
237
|
+
const usedOverride = penOverride;
|
|
238
|
+
penOverride = null;
|
|
239
|
+
if (step.kind === "line") {
|
|
240
|
+
const fromClip = usedOverride ?? clipForTarget(prev.step.to, currAnchor, nodeIndex);
|
|
241
|
+
const toClip = clipForTarget(step.to, prev.anchor, nodeIndex);
|
|
242
|
+
if (!fromClip || !toClip) return null;
|
|
243
|
+
startSegment(fromClip);
|
|
244
|
+
emitLine(toClip);
|
|
245
|
+
collectLabel(step, (t) => lineSegmentSample(fromClip, toClip, t));
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
if (step.kind === "curve") {
|
|
249
|
+
const fromClip = usedOverride ?? clipForTarget(prev.step.to, step.control, nodeIndex);
|
|
250
|
+
const toClip = clipForTarget(step.to, step.control, nodeIndex);
|
|
251
|
+
if (!fromClip || !toClip) return null;
|
|
252
|
+
startSegment(fromClip);
|
|
253
|
+
emitQuad(step.control, toClip);
|
|
254
|
+
collectLabel(step, (t) => quadSegmentSample(fromClip, step.control, toClip, t));
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
if (step.kind === "cubic") {
|
|
258
|
+
const fromClip = usedOverride ?? clipForTarget(prev.step.to, step.control1, nodeIndex);
|
|
259
|
+
const toClip = clipForTarget(step.to, step.control2, nodeIndex);
|
|
260
|
+
if (!fromClip || !toClip) return null;
|
|
261
|
+
startSegment(fromClip);
|
|
262
|
+
emitCubic(step.control1, step.control2, toClip);
|
|
263
|
+
collectLabel(step, (t) => cubicSegmentSample(fromClip, step.control1, step.control2, toClip, t));
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
if (step.kind === "bend") {
|
|
267
|
+
const angle = step.bendAngle ?? 30;
|
|
268
|
+
const [c1, c2] = bendControlPoints(prev.anchor, currAnchor, step.bendDirection, angle);
|
|
269
|
+
const fromClip = usedOverride ?? clipForTarget(prev.step.to, c1, nodeIndex);
|
|
270
|
+
const toClip = clipForTarget(step.to, c2, nodeIndex);
|
|
271
|
+
if (!fromClip || !toClip) return null;
|
|
272
|
+
startSegment(fromClip);
|
|
273
|
+
emitCubic(c1, c2, toClip);
|
|
274
|
+
collectLabel(step, (t) => cubicSegmentSample(fromClip, c1, c2, toClip, t));
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
const corner = cornerOf(prev.anchor, currAnchor, step.via);
|
|
278
|
+
const fromClip = usedOverride ?? clipForTarget(prev.step.to, corner, nodeIndex);
|
|
279
|
+
const toClip = clipForTarget(step.to, corner, nodeIndex);
|
|
280
|
+
if (!fromClip || !toClip) return null;
|
|
281
|
+
startSegment(fromClip);
|
|
282
|
+
emitLine(corner);
|
|
283
|
+
emitLine(toClip);
|
|
284
|
+
collectLabel(step, (t) => foldSegmentSample(fromClip, corner, toClip, t));
|
|
285
|
+
}
|
|
286
|
+
const strokeWidth = path.strokeWidth ?? (path.thickness ? THICKNESS_TO_WIDTH[path.thickness] : 1);
|
|
287
|
+
const baseProps = {
|
|
288
|
+
stroke: path.stroke ?? "currentColor",
|
|
289
|
+
strokeWidth,
|
|
290
|
+
fill: path.fill ?? "none",
|
|
291
|
+
fillRule: path.fillRule,
|
|
292
|
+
strokeDasharray: path.strokeDasharray,
|
|
293
|
+
strokeLinecap: path.lineCap,
|
|
294
|
+
strokeLinejoin: path.lineJoin,
|
|
295
|
+
opacity: path.opacity,
|
|
296
|
+
fillOpacity: path.fillOpacity,
|
|
297
|
+
strokeOpacity: path.drawOpacity
|
|
298
|
+
};
|
|
299
|
+
const markers = arrowMarkers(path.arrow, path.arrowDetail);
|
|
300
|
+
applyArrowShrinks(commands, markers.arrowStart ? computeShrink(markers.arrowStart) : 0, markers.arrowEnd ? computeShrink(markers.arrowEnd) : 0, strokeWidth, round);
|
|
301
|
+
const { primitive } = splitSubPathsForMarkers(commands, baseProps, markers);
|
|
302
|
+
return {
|
|
303
|
+
primitives: [primitive, ...labelPrims],
|
|
304
|
+
points
|
|
305
|
+
};
|
|
306
|
+
};
|
|
307
|
+
//#endregion
|
|
308
|
+
export { emitPathPrimitive };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SegmentSample } from '../../geometry/segment';
|
|
2
|
+
import { IRPosition, IRStepLabel } from '../../ir';
|
|
3
|
+
import { ScenePrimitive } from '../../primitive';
|
|
4
|
+
import { TextMeasurer } from '../text-metrics';
|
|
5
|
+
/**
|
|
6
|
+
* label.position → 段参数 t∈[0,1]
|
|
7
|
+
* @description 数值原样返回(schema 已 clamp 0..1);keyword 走 KEYWORD_TO_T 映射;undefined 退默认 midway (0.5)
|
|
8
|
+
*/
|
|
9
|
+
export declare const tForLabelPosition: (pos: IRStepLabel["position"]) => number;
|
|
10
|
+
/**
|
|
11
|
+
* step.label + 段采样 → TextPrim(sloped 时裹一层 group 旋转)
|
|
12
|
+
* @description 默认 side='above'/position='midway':above/below 锚点 y±offset、align=middle、baseline=bottom/top;left/right x±offset、align=end/start、baseline=middle;sloped 不偏移裹 group rotate(angle, cx, cy) 由切线 atan2 算(SVG y-down CW 正)。返回 primitive + viewBox 外接点
|
|
13
|
+
*/
|
|
14
|
+
export declare const emitLabelPrimitive: (label: IRStepLabel, sample: SegmentSample, measureText: TextMeasurer, round: (n: number) => number) => {
|
|
15
|
+
primitive: ScenePrimitive;
|
|
16
|
+
points: Array<IRPosition>;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=label.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"label.d.ts","sourceRoot":"","sources":["../../../../src/compile/path/label.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAY,MAAM,iBAAiB,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAmBpD;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAAI,KAAK,WAAW,CAAC,UAAU,CAAC,KAAG,MAIhE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAC7B,OAAO,WAAW,EAClB,QAAQ,aAAa,EACrB,aAAa,YAAY,EACzB,OAAO,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,KAC3B;IAAE,SAAS,EAAE,cAAc,CAAC;IAAC,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC,CAAA;CA8ExD,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
//#region src/compile/path/label.ts
|
|
2
|
+
/** 边标注默认字号 / 偏移量 */
|
|
3
|
+
var LABEL_FONT_SIZE = 14;
|
|
4
|
+
var LABEL_LINE_HEIGHT_FACTOR = 1.2;
|
|
5
|
+
var LABEL_SIDE_OFFSET = 4;
|
|
6
|
+
var RAD_TO_DEG = 180 / Math.PI;
|
|
7
|
+
/** keyword → t 数值映射;含旧 3 keyword(midway/near-start/near-end)+ 新 4 keyword */
|
|
8
|
+
var KEYWORD_TO_T = {
|
|
9
|
+
"at-start": 0,
|
|
10
|
+
"very-near-start": .125,
|
|
11
|
+
"near-start": .25,
|
|
12
|
+
midway: .5,
|
|
13
|
+
"near-end": .75,
|
|
14
|
+
"very-near-end": .875,
|
|
15
|
+
"at-end": 1
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* label.position → 段参数 t∈[0,1]
|
|
19
|
+
* @description 数值原样返回(schema 已 clamp 0..1);keyword 走 KEYWORD_TO_T 映射;undefined 退默认 midway (0.5)
|
|
20
|
+
*/
|
|
21
|
+
var tForLabelPosition = (pos) => {
|
|
22
|
+
if (typeof pos === "number") return pos;
|
|
23
|
+
if (typeof pos === "string" && pos in KEYWORD_TO_T) return KEYWORD_TO_T[pos];
|
|
24
|
+
return .5;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* step.label + 段采样 → TextPrim(sloped 时裹一层 group 旋转)
|
|
28
|
+
* @description 默认 side='above'/position='midway':above/below 锚点 y±offset、align=middle、baseline=bottom/top;left/right x±offset、align=end/start、baseline=middle;sloped 不偏移裹 group rotate(angle, cx, cy) 由切线 atan2 算(SVG y-down CW 正)。返回 primitive + viewBox 外接点
|
|
29
|
+
*/
|
|
30
|
+
var emitLabelPrimitive = (label, sample, measureText, round) => {
|
|
31
|
+
const fontSize = LABEL_FONT_SIZE;
|
|
32
|
+
const lineHeight = fontSize * LABEL_LINE_HEIGHT_FACTOR;
|
|
33
|
+
const m = measureText(label.text, { size: fontSize });
|
|
34
|
+
const measuredWidth = m.width;
|
|
35
|
+
const measuredHeight = m.height || lineHeight;
|
|
36
|
+
const side = label.side ?? "above";
|
|
37
|
+
let x = sample.point[0];
|
|
38
|
+
let y = sample.point[1];
|
|
39
|
+
let align = "middle";
|
|
40
|
+
let baseline = "middle";
|
|
41
|
+
if (side === "above") {
|
|
42
|
+
y -= LABEL_SIDE_OFFSET;
|
|
43
|
+
baseline = "bottom";
|
|
44
|
+
} else if (side === "below") {
|
|
45
|
+
y += LABEL_SIDE_OFFSET;
|
|
46
|
+
baseline = "top";
|
|
47
|
+
} else if (side === "left") {
|
|
48
|
+
x -= LABEL_SIDE_OFFSET;
|
|
49
|
+
align = "end";
|
|
50
|
+
} else if (side === "right") {
|
|
51
|
+
x += LABEL_SIDE_OFFSET;
|
|
52
|
+
align = "start";
|
|
53
|
+
} else baseline = "bottom";
|
|
54
|
+
const text = {
|
|
55
|
+
type: "text",
|
|
56
|
+
x: round(x),
|
|
57
|
+
y: round(y),
|
|
58
|
+
lines: [{ text: label.text }],
|
|
59
|
+
fontSize,
|
|
60
|
+
align,
|
|
61
|
+
baseline,
|
|
62
|
+
lineHeight: round(lineHeight),
|
|
63
|
+
measuredWidth: round(measuredWidth),
|
|
64
|
+
measuredHeight: round(measuredHeight),
|
|
65
|
+
fill: "currentColor"
|
|
66
|
+
};
|
|
67
|
+
if (side === "sloped") {
|
|
68
|
+
const groupPrim = {
|
|
69
|
+
type: "group",
|
|
70
|
+
transforms: [{
|
|
71
|
+
kind: "rotate",
|
|
72
|
+
degrees: round(Math.atan2(sample.tangent[1], sample.tangent[0]) * RAD_TO_DEG),
|
|
73
|
+
cx: round(x),
|
|
74
|
+
cy: round(y)
|
|
75
|
+
}],
|
|
76
|
+
children: [text]
|
|
77
|
+
};
|
|
78
|
+
const r = Math.max(measuredWidth / 2, measuredHeight / 2);
|
|
79
|
+
return {
|
|
80
|
+
primitive: groupPrim,
|
|
81
|
+
points: [
|
|
82
|
+
[x - r, y - r],
|
|
83
|
+
[x + r, y - r],
|
|
84
|
+
[x - r, y + r],
|
|
85
|
+
[x + r, y + r]
|
|
86
|
+
]
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
const halfW = measuredWidth / 2;
|
|
90
|
+
const halfH = measuredHeight / 2;
|
|
91
|
+
return {
|
|
92
|
+
primitive: text,
|
|
93
|
+
points: [
|
|
94
|
+
[x - halfW, y - halfH],
|
|
95
|
+
[x + halfW, y - halfH],
|
|
96
|
+
[x - halfW, y + halfH],
|
|
97
|
+
[x + halfW, y + halfH]
|
|
98
|
+
]
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
//#endregion
|
|
102
|
+
export { emitLabelPrimitive, tForLabelPosition };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IRStep } from '../../ir';
|
|
2
|
+
import { NodeLayout } from '../node';
|
|
3
|
+
/**
|
|
4
|
+
* relative/relativeAccumulate 目标解析为绝对 Position(step kind 不变,to 全为绝对坐标)
|
|
5
|
+
* @description relative 不更新 prevEnd(TikZ `+`),relativeAccumulate 更新(TikZ `++`)。prevEnd 推进:有 to 的 kind 用 refPointOfTarget(to);arc 用 arcEndPoint;circlePath/ellipsePath/cycle 不变。首步 relative 时 prevEnd 回退 [0,0];解析失败保持原 step
|
|
6
|
+
*/
|
|
7
|
+
export declare const normalizeRelativeTargets: (steps: ReadonlyArray<IRStep>, nodeIndex: Map<string, NodeLayout>) => Array<IRStep>;
|
|
8
|
+
//# sourceMappingURL=relative.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relative.d.ts","sourceRoot":"","sources":["../../../../src/compile/path/relative.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAc,MAAM,EAAY,MAAM,UAAU,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAG1C;;;GAGG;AACH,eAAO,MAAM,wBAAwB,GACnC,OAAO,aAAa,CAAC,MAAM,CAAC,EAC5B,WAAW,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,KACjC,KAAK,CAAC,MAAM,CA0Dd,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { arcEndPoint } from "../../geometry/arc.js";
|
|
2
|
+
import { refPointOfTarget } from "./anchor.js";
|
|
3
|
+
//#region src/compile/path/relative.ts
|
|
4
|
+
/**
|
|
5
|
+
* relative/relativeAccumulate 目标解析为绝对 Position(step kind 不变,to 全为绝对坐标)
|
|
6
|
+
* @description relative 不更新 prevEnd(TikZ `+`),relativeAccumulate 更新(TikZ `++`)。prevEnd 推进:有 to 的 kind 用 refPointOfTarget(to);arc 用 arcEndPoint;circlePath/ellipsePath/cycle 不变。首步 relative 时 prevEnd 回退 [0,0];解析失败保持原 step
|
|
7
|
+
*/
|
|
8
|
+
var normalizeRelativeTargets = (steps, nodeIndex) => {
|
|
9
|
+
let prevEnd = null;
|
|
10
|
+
const out = [];
|
|
11
|
+
for (const step of steps) {
|
|
12
|
+
if (step.kind === "cycle") {
|
|
13
|
+
out.push(step);
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (step.kind === "circlePath" || step.kind === "ellipsePath") {
|
|
17
|
+
out.push(step);
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (step.kind === "arc") {
|
|
21
|
+
out.push(step);
|
|
22
|
+
if (prevEnd) prevEnd = arcEndPoint(prevEnd, step.radius, step.endAngle);
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
const original = step.to;
|
|
26
|
+
let resolvedTo = original;
|
|
27
|
+
let updatePrevEnd = true;
|
|
28
|
+
if (typeof original === "object" && !Array.isArray(original) && "relative" in original) {
|
|
29
|
+
const ref = prevEnd ?? [0, 0];
|
|
30
|
+
resolvedTo = [ref[0] + original.relative[0], ref[1] + original.relative[1]];
|
|
31
|
+
updatePrevEnd = false;
|
|
32
|
+
} else if (typeof original === "object" && !Array.isArray(original) && "relativeAccumulate" in original) {
|
|
33
|
+
const ref = prevEnd ?? [0, 0];
|
|
34
|
+
resolvedTo = [ref[0] + original.relativeAccumulate[0], ref[1] + original.relativeAccumulate[1]];
|
|
35
|
+
}
|
|
36
|
+
out.push({
|
|
37
|
+
...step,
|
|
38
|
+
to: resolvedTo
|
|
39
|
+
});
|
|
40
|
+
if (updatePrevEnd) {
|
|
41
|
+
const pos = refPointOfTarget(resolvedTo, nodeIndex);
|
|
42
|
+
if (pos) prevEnd = pos;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return out;
|
|
46
|
+
};
|
|
47
|
+
//#endregion
|
|
48
|
+
export { normalizeRelativeTargets };
|