@retikz/core 0.1.0-alpha.5 → 0.1.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.
Files changed (231) hide show
  1. package/dist/es/compile/compile.d.ts +20 -3
  2. package/dist/es/compile/compile.d.ts.map +1 -1
  3. package/dist/es/compile/compile.js +44 -19
  4. package/dist/es/compile/index.d.ts +2 -2
  5. package/dist/es/compile/index.d.ts.map +1 -1
  6. package/dist/es/compile/layout.d.ts +5 -0
  7. package/dist/es/compile/layout.d.ts.map +1 -0
  8. package/dist/es/compile/{view-box.js → layout.js} +4 -4
  9. package/dist/es/compile/node.d.ts +4 -4
  10. package/dist/es/compile/node.d.ts.map +1 -1
  11. package/dist/es/compile/node.js +7 -7
  12. package/dist/es/compile/path/anchor.d.ts +19 -0
  13. package/dist/es/compile/path/anchor.d.ts.map +1 -0
  14. package/dist/es/compile/path/anchor.js +54 -0
  15. package/dist/es/compile/path/arrow-geometry.d.ts +22 -0
  16. package/dist/es/compile/path/arrow-geometry.d.ts.map +1 -0
  17. package/dist/es/compile/path/arrow-geometry.js +40 -0
  18. package/dist/es/compile/{path.d.ts → path/index.d.ts} +18 -7
  19. package/dist/es/compile/path/index.d.ts.map +1 -0
  20. package/dist/es/compile/path/index.js +308 -0
  21. package/dist/es/compile/path/label.d.ts +18 -0
  22. package/dist/es/compile/path/label.d.ts.map +1 -0
  23. package/dist/es/compile/path/label.js +102 -0
  24. package/dist/es/compile/path/relative.d.ts +8 -0
  25. package/dist/es/compile/path/relative.d.ts.map +1 -0
  26. package/dist/es/compile/path/relative.js +48 -0
  27. package/dist/es/compile/path/shrink.d.ts +18 -0
  28. package/dist/es/compile/path/shrink.d.ts.map +1 -0
  29. package/dist/es/compile/path/shrink.js +126 -0
  30. package/dist/es/compile/path/split.d.ts +15 -0
  31. package/dist/es/compile/path/split.d.ts.map +1 -0
  32. package/dist/es/compile/path/split.js +46 -0
  33. package/dist/es/compile/text-metrics.d.ts +4 -1
  34. package/dist/es/compile/text-metrics.d.ts.map +1 -1
  35. package/dist/es/compile/text-metrics.js +11 -5
  36. package/dist/es/geometry/_transform.d.ts +21 -0
  37. package/dist/es/geometry/_transform.d.ts.map +1 -0
  38. package/dist/es/geometry/_transform.js +27 -0
  39. package/dist/es/geometry/bend.d.ts +1 -1
  40. package/dist/es/geometry/bend.js +1 -1
  41. package/dist/es/geometry/circle.d.ts +2 -3
  42. package/dist/es/geometry/circle.d.ts.map +1 -1
  43. package/dist/es/geometry/circle.js +1 -16
  44. package/dist/es/geometry/diamond.d.ts +2 -3
  45. package/dist/es/geometry/diamond.d.ts.map +1 -1
  46. package/dist/es/geometry/diamond.js +1 -16
  47. package/dist/es/geometry/ellipse.d.ts +2 -3
  48. package/dist/es/geometry/ellipse.d.ts.map +1 -1
  49. package/dist/es/geometry/ellipse.js +1 -16
  50. package/dist/es/geometry/polar.d.ts +2 -2
  51. package/dist/es/geometry/polar.d.ts.map +1 -1
  52. package/dist/es/geometry/polar.js +2 -6
  53. package/dist/es/geometry/rect.d.ts.map +1 -1
  54. package/dist/es/geometry/rect.js +1 -18
  55. package/dist/es/geometry/segment.d.ts +5 -1
  56. package/dist/es/geometry/segment.d.ts.map +1 -1
  57. package/dist/es/index.d.ts +11 -7
  58. package/dist/es/index.d.ts.map +1 -1
  59. package/dist/es/index.js +5 -2
  60. package/dist/es/ir/coordinate.d.ts +1 -1
  61. package/dist/es/ir/coordinate.js +1 -1
  62. package/dist/es/ir/font.d.ts +21 -0
  63. package/dist/es/ir/font.d.ts.map +1 -0
  64. package/dist/es/ir/font.js +15 -0
  65. package/dist/es/ir/index.d.ts +2 -0
  66. package/dist/es/ir/index.d.ts.map +1 -1
  67. package/dist/es/ir/node.d.ts +32 -143
  68. package/dist/es/ir/node.d.ts.map +1 -1
  69. package/dist/es/ir/node.js +7 -31
  70. package/dist/es/ir/path/arrow.d.ts +14 -14
  71. package/dist/es/ir/path/arrow.d.ts.map +1 -1
  72. package/dist/es/ir/path/arrow.js +5 -5
  73. package/dist/es/ir/path/path.d.ts +19 -19
  74. package/dist/es/ir/path/path.d.ts.map +1 -1
  75. package/dist/es/ir/path/path.js +4 -4
  76. package/dist/es/ir/path/step.d.ts +1 -1
  77. package/dist/es/ir/path/step.d.ts.map +1 -1
  78. package/dist/es/ir/path/step.js +8 -8
  79. package/dist/es/ir/position/at-position.js +1 -1
  80. package/dist/es/ir/position/offset-position.js +1 -1
  81. package/dist/es/ir/position/polar-position.d.ts.map +1 -1
  82. package/dist/es/ir/position/polar-position.js +2 -2
  83. package/dist/es/ir/position/position.d.ts.map +1 -1
  84. package/dist/es/ir/position/position.js +1 -1
  85. package/dist/es/ir/scene.d.ts +128 -128
  86. package/dist/es/ir/text.d.ts +96 -0
  87. package/dist/es/ir/text.d.ts.map +1 -0
  88. package/dist/es/ir/text.js +20 -0
  89. package/dist/es/parsers/parseTargetSugar.d.ts +4 -0
  90. package/dist/es/parsers/parseTargetSugar.d.ts.map +1 -1
  91. package/dist/es/parsers/parseTargetSugar.js +3 -2
  92. package/dist/es/primitive/ellipse.d.ts +3 -3
  93. package/dist/es/primitive/ellipse.d.ts.map +1 -1
  94. package/dist/es/primitive/group.d.ts +23 -7
  95. package/dist/es/primitive/group.d.ts.map +1 -1
  96. package/dist/es/primitive/index.d.ts +1 -1
  97. package/dist/es/primitive/index.d.ts.map +1 -1
  98. package/dist/es/primitive/layout.d.ts +12 -0
  99. package/dist/es/primitive/layout.d.ts.map +1 -0
  100. package/dist/es/primitive/path.d.ts +55 -15
  101. package/dist/es/primitive/path.d.ts.map +1 -1
  102. package/dist/es/primitive/rect.d.ts +3 -3
  103. package/dist/es/primitive/rect.d.ts.map +1 -1
  104. package/dist/es/primitive/scene.d.ts +4 -4
  105. package/dist/es/primitive/scene.d.ts.map +1 -1
  106. package/dist/es/primitive/text.d.ts +10 -3
  107. package/dist/es/primitive/text.d.ts.map +1 -1
  108. package/dist/es/types.d.ts +8 -0
  109. package/dist/es/types.d.ts.map +1 -1
  110. package/dist/lib/compile/compile.cjs +44 -19
  111. package/dist/lib/compile/compile.d.ts +20 -3
  112. package/dist/lib/compile/compile.d.ts.map +1 -1
  113. package/dist/lib/compile/index.d.ts +2 -2
  114. package/dist/lib/compile/index.d.ts.map +1 -1
  115. package/dist/lib/compile/{view-box.cjs → layout.cjs} +4 -4
  116. package/dist/lib/compile/layout.d.ts +5 -0
  117. package/dist/lib/compile/layout.d.ts.map +1 -0
  118. package/dist/lib/compile/node.cjs +7 -7
  119. package/dist/lib/compile/node.d.ts +4 -4
  120. package/dist/lib/compile/node.d.ts.map +1 -1
  121. package/dist/lib/compile/path/anchor.cjs +58 -0
  122. package/dist/lib/compile/path/anchor.d.ts +19 -0
  123. package/dist/lib/compile/path/anchor.d.ts.map +1 -0
  124. package/dist/lib/compile/path/arrow-geometry.cjs +41 -0
  125. package/dist/lib/compile/path/arrow-geometry.d.ts +22 -0
  126. package/dist/lib/compile/path/arrow-geometry.d.ts.map +1 -0
  127. package/dist/lib/compile/path/index.cjs +308 -0
  128. package/dist/lib/compile/{path.d.ts → path/index.d.ts} +18 -7
  129. package/dist/lib/compile/path/index.d.ts.map +1 -0
  130. package/dist/lib/compile/path/label.cjs +103 -0
  131. package/dist/lib/compile/path/label.d.ts +18 -0
  132. package/dist/lib/compile/path/label.d.ts.map +1 -0
  133. package/dist/lib/compile/path/relative.cjs +48 -0
  134. package/dist/lib/compile/path/relative.d.ts +8 -0
  135. package/dist/lib/compile/path/relative.d.ts.map +1 -0
  136. package/dist/lib/compile/path/shrink.cjs +128 -0
  137. package/dist/lib/compile/path/shrink.d.ts +18 -0
  138. package/dist/lib/compile/path/shrink.d.ts.map +1 -0
  139. package/dist/lib/compile/path/split.cjs +46 -0
  140. package/dist/lib/compile/path/split.d.ts +15 -0
  141. package/dist/lib/compile/path/split.d.ts.map +1 -0
  142. package/dist/lib/compile/text-metrics.cjs +11 -5
  143. package/dist/lib/compile/text-metrics.d.ts +4 -1
  144. package/dist/lib/compile/text-metrics.d.ts.map +1 -1
  145. package/dist/lib/geometry/_transform.cjs +28 -0
  146. package/dist/lib/geometry/_transform.d.ts +21 -0
  147. package/dist/lib/geometry/_transform.d.ts.map +1 -0
  148. package/dist/lib/geometry/bend.cjs +1 -1
  149. package/dist/lib/geometry/bend.d.ts +1 -1
  150. package/dist/lib/geometry/circle.cjs +5 -20
  151. package/dist/lib/geometry/circle.d.ts +2 -3
  152. package/dist/lib/geometry/circle.d.ts.map +1 -1
  153. package/dist/lib/geometry/diamond.cjs +5 -20
  154. package/dist/lib/geometry/diamond.d.ts +2 -3
  155. package/dist/lib/geometry/diamond.d.ts.map +1 -1
  156. package/dist/lib/geometry/ellipse.cjs +5 -20
  157. package/dist/lib/geometry/ellipse.d.ts +2 -3
  158. package/dist/lib/geometry/ellipse.d.ts.map +1 -1
  159. package/dist/lib/geometry/polar.cjs +2 -6
  160. package/dist/lib/geometry/polar.d.ts +2 -2
  161. package/dist/lib/geometry/polar.d.ts.map +1 -1
  162. package/dist/lib/geometry/rect.cjs +5 -22
  163. package/dist/lib/geometry/rect.d.ts.map +1 -1
  164. package/dist/lib/geometry/segment.d.ts +5 -1
  165. package/dist/lib/geometry/segment.d.ts.map +1 -1
  166. package/dist/lib/index.cjs +7 -3
  167. package/dist/lib/index.d.ts +11 -7
  168. package/dist/lib/index.d.ts.map +1 -1
  169. package/dist/lib/ir/coordinate.cjs +1 -1
  170. package/dist/lib/ir/coordinate.d.ts +1 -1
  171. package/dist/lib/ir/font.cjs +15 -0
  172. package/dist/lib/ir/font.d.ts +21 -0
  173. package/dist/lib/ir/font.d.ts.map +1 -0
  174. package/dist/lib/ir/index.d.ts +2 -0
  175. package/dist/lib/ir/index.d.ts.map +1 -1
  176. package/dist/lib/ir/node.cjs +8 -35
  177. package/dist/lib/ir/node.d.ts +32 -143
  178. package/dist/lib/ir/node.d.ts.map +1 -1
  179. package/dist/lib/ir/path/arrow.cjs +5 -5
  180. package/dist/lib/ir/path/arrow.d.ts +14 -14
  181. package/dist/lib/ir/path/arrow.d.ts.map +1 -1
  182. package/dist/lib/ir/path/path.cjs +4 -4
  183. package/dist/lib/ir/path/path.d.ts +19 -19
  184. package/dist/lib/ir/path/path.d.ts.map +1 -1
  185. package/dist/lib/ir/path/step.cjs +8 -8
  186. package/dist/lib/ir/path/step.d.ts +1 -1
  187. package/dist/lib/ir/path/step.d.ts.map +1 -1
  188. package/dist/lib/ir/position/at-position.cjs +1 -1
  189. package/dist/lib/ir/position/offset-position.cjs +1 -1
  190. package/dist/lib/ir/position/polar-position.cjs +2 -2
  191. package/dist/lib/ir/position/polar-position.d.ts.map +1 -1
  192. package/dist/lib/ir/position/position.cjs +1 -1
  193. package/dist/lib/ir/position/position.d.ts.map +1 -1
  194. package/dist/lib/ir/scene.d.ts +128 -128
  195. package/dist/lib/ir/text.cjs +21 -0
  196. package/dist/lib/ir/text.d.ts +96 -0
  197. package/dist/lib/ir/text.d.ts.map +1 -0
  198. package/dist/lib/parsers/parseTargetSugar.cjs +3 -2
  199. package/dist/lib/parsers/parseTargetSugar.d.ts +4 -0
  200. package/dist/lib/parsers/parseTargetSugar.d.ts.map +1 -1
  201. package/dist/lib/primitive/ellipse.d.ts +3 -3
  202. package/dist/lib/primitive/ellipse.d.ts.map +1 -1
  203. package/dist/lib/primitive/group.d.ts +23 -7
  204. package/dist/lib/primitive/group.d.ts.map +1 -1
  205. package/dist/lib/primitive/index.d.ts +1 -1
  206. package/dist/lib/primitive/index.d.ts.map +1 -1
  207. package/dist/lib/primitive/layout.d.ts +12 -0
  208. package/dist/lib/primitive/layout.d.ts.map +1 -0
  209. package/dist/lib/primitive/path.d.ts +55 -15
  210. package/dist/lib/primitive/path.d.ts.map +1 -1
  211. package/dist/lib/primitive/rect.d.ts +3 -3
  212. package/dist/lib/primitive/rect.d.ts.map +1 -1
  213. package/dist/lib/primitive/scene.d.ts +4 -4
  214. package/dist/lib/primitive/scene.d.ts.map +1 -1
  215. package/dist/lib/primitive/text.d.ts +10 -3
  216. package/dist/lib/primitive/text.d.ts.map +1 -1
  217. package/dist/lib/types.d.ts +8 -0
  218. package/dist/lib/types.d.ts.map +1 -1
  219. package/package.json +12 -4
  220. package/dist/es/compile/path.d.ts.map +0 -1
  221. package/dist/es/compile/path.js +0 -636
  222. package/dist/es/compile/view-box.d.ts +0 -5
  223. package/dist/es/compile/view-box.d.ts.map +0 -1
  224. package/dist/es/primitive/view-box.d.ts +0 -12
  225. package/dist/es/primitive/view-box.d.ts.map +0 -1
  226. package/dist/lib/compile/path.cjs +0 -636
  227. package/dist/lib/compile/path.d.ts.map +0 -1
  228. package/dist/lib/compile/view-box.d.ts +0 -5
  229. package/dist/lib/compile/view-box.d.ts.map +0 -1
  230. package/dist/lib/primitive/view-box.d.ts +0 -12
  231. package/dist/lib/primitive/view-box.d.ts.map +0 -1
@@ -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, computeShrink, endpointArrows } from "./shrink.js";
9
+ import { splitSubPathsForEndpointArrows } 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
+ dashPattern: path.dashPattern,
293
+ strokeLinecap: path.lineCap,
294
+ strokeLinejoin: path.lineJoin,
295
+ opacity: path.opacity,
296
+ fillOpacity: path.fillOpacity,
297
+ strokeOpacity: path.drawOpacity
298
+ };
299
+ const arrows = endpointArrows(path.arrow, path.arrowDetail);
300
+ applyArrowShrinks(commands, arrows.arrowStart ? computeShrink(arrows.arrowStart) : 0, arrows.arrowEnd ? computeShrink(arrows.arrowEnd) : 0, strokeWidth, round);
301
+ const { primitive } = splitSubPathsForEndpointArrows(commands, baseProps, arrows);
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 + layout 外接点
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 + layout 外接点
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 };
@@ -0,0 +1,18 @@
1
+ import { IRArrowDetail } from '../../ir';
2
+ import { ArrowEndSpec, PathCommand } from '../../primitive';
3
+ /** IR path-level `arrow` + `arrowDetail` → PathPrim 起末端点箭头规格 */
4
+ export declare const endpointArrows: (arrow: "none" | "->" | "<-" | "<->" | undefined, detail: IRArrowDetail | undefined) => {
5
+ arrowStart?: ArrowEndSpec;
6
+ arrowEnd?: ArrowEndSpec;
7
+ };
8
+ /**
9
+ * 端点级 shrink(strokeWidth 倍):line 末端朝起点缩这么多,让箭头尖端落回原 target
10
+ * @description 不分实心 / 空心:路径端点接在箭头尾部或凹口,箭头尖端仍贴原 target。低 opacity 下不会再透出 line。
11
+ */
12
+ export declare const computeShrink: (spec: ArrowEndSpec) => number;
13
+ /**
14
+ * 按 shape + spec(length / scale / lineWidth)把首/末段端点向内缩短
15
+ * @description 让 line 端点接在 hollow arrow 尾部外缘、不贯穿 back outline;shrink=0 的实心 shape 跳过。in-place 改写 commands 数组
16
+ */
17
+ export declare const applyArrowShrinks: (commands: Array<PathCommand>, shrinkStart: number, shrinkEnd: number, strokeWidth: number, round: (n: number) => number) => void;
18
+ //# sourceMappingURL=shrink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shrink.d.ts","sourceRoot":"","sources":["../../../../src/compile/path/shrink.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAgC,MAAM,UAAU,CAAC;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAmCjE,gEAAgE;AAChE,eAAO,MAAM,cAAc,GACzB,OAAO,MAAM,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,GAAG,SAAS,EAC/C,QAAQ,aAAa,GAAG,SAAS,KAChC;IAAE,UAAU,CAAC,EAAE,YAAY,CAAC;IAAC,QAAQ,CAAC,EAAE,YAAY,CAAA;CAatD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,YAAY,KAAG,MAIlD,CAAC;AAiDF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAC5B,UAAU,KAAK,CAAC,WAAW,CAAC,EAC5B,aAAa,MAAM,EACnB,WAAW,MAAM,EACjB,aAAa,MAAM,EACnB,OAAO,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,KAC3B,IA4CF,CAAC"}
@@ -0,0 +1,126 @@
1
+ import { shiftToward } from "./anchor.js";
2
+ import { isHollowArrowShape, resolveArrowShapeGeometry } from "./arrow-geometry.js";
3
+ //#region src/compile/path/shrink.ts
4
+ /**
5
+ * 端点级 spec:顶层默认 ⊕ end-side override(逐字段 merge)
6
+ * @description 缺省字段继承顶层(不是"完全替换");空心 shape 上 fill 字段被丢(silent no-op)
7
+ */
8
+ var resolveArrowEndSpec = (topLevel, endSide) => {
9
+ const baseShape = endSide?.shape ?? topLevel.shape ?? "normal";
10
+ const out = { shape: baseShape };
11
+ const scale = endSide?.scale ?? topLevel.scale;
12
+ if (scale !== void 0) out.scale = scale;
13
+ const length = endSide?.length ?? topLevel.length;
14
+ if (length !== void 0) out.length = length;
15
+ const width = endSide?.width ?? topLevel.width;
16
+ if (width !== void 0) out.width = width;
17
+ const color = endSide?.color ?? topLevel.color;
18
+ if (color !== void 0) out.color = color;
19
+ const opacity = endSide?.opacity ?? topLevel.opacity;
20
+ if (opacity !== void 0) out.opacity = opacity;
21
+ const lineWidth = endSide?.lineWidth ?? topLevel.lineWidth;
22
+ if (lineWidth !== void 0) out.lineWidth = lineWidth;
23
+ if (!isHollowArrowShape(baseShape)) {
24
+ const fill = endSide?.fill ?? topLevel.fill;
25
+ if (fill !== void 0) out.fill = fill;
26
+ }
27
+ return out;
28
+ };
29
+ /** IR path-level `arrow` + `arrowDetail` → PathPrim 起末端点箭头规格 */
30
+ var endpointArrows = (arrow, detail) => {
31
+ if (!arrow || arrow === "none") return {};
32
+ const top = detail ?? {};
33
+ const startSpec = resolveArrowEndSpec(top, top.start);
34
+ const endSpec = resolveArrowEndSpec(top, top.end);
35
+ switch (arrow) {
36
+ case "->": return { arrowEnd: endSpec };
37
+ case "<-": return { arrowStart: startSpec };
38
+ case "<->": return {
39
+ arrowStart: startSpec,
40
+ arrowEnd: endSpec
41
+ };
42
+ }
43
+ };
44
+ /**
45
+ * 端点级 shrink(strokeWidth 倍):line 末端朝起点缩这么多,让箭头尖端落回原 target
46
+ * @description 不分实心 / 空心:路径端点接在箭头尾部或凹口,箭头尖端仍贴原 target。低 opacity 下不会再透出 line。
47
+ */
48
+ var computeShrink = (spec) => {
49
+ const geometry = resolveArrowShapeGeometry(spec);
50
+ const length = (spec.length ?? geometry.defaultLength) * (spec.scale ?? 1);
51
+ return (geometry.tipX - geometry.lineContactX) * length / geometry.baseSize;
52
+ };
53
+ /** 取一个 PathCommand 末端 endpoint(move/line/quad/cubic → to;arc/ellipseArc → polar(end);close 无端点) */
54
+ var endpointOf = (cmd) => {
55
+ switch (cmd.kind) {
56
+ case "move":
57
+ case "line":
58
+ case "quad":
59
+ case "cubic": return [cmd.to[0], cmd.to[1]];
60
+ case "arc": {
61
+ const rad = cmd.endAngle * Math.PI / 180;
62
+ return [cmd.center[0] + Math.cos(rad) * cmd.radius, cmd.center[1] + Math.sin(rad) * cmd.radius];
63
+ }
64
+ case "ellipseArc": {
65
+ const rad = cmd.endAngle * Math.PI / 180;
66
+ return [cmd.center[0] + Math.cos(rad) * cmd.radiusX, cmd.center[1] + Math.sin(rad) * cmd.radiusY];
67
+ }
68
+ case "close": return null;
69
+ }
70
+ };
71
+ /** 改写一个 PathCommand 的 endpoint(用于 shrink) */
72
+ var setEndpoint = (commands, idx, newPt, round) => {
73
+ const cmd = commands[idx];
74
+ if (cmd.kind === "close") return;
75
+ const rp = [round(newPt[0]), round(newPt[1])];
76
+ if (cmd.kind === "move" || cmd.kind === "line") commands[idx] = {
77
+ ...cmd,
78
+ to: rp
79
+ };
80
+ else if (cmd.kind === "quad") commands[idx] = {
81
+ ...cmd,
82
+ to: rp
83
+ };
84
+ else if (cmd.kind === "cubic") commands[idx] = {
85
+ ...cmd,
86
+ to: rp
87
+ };
88
+ };
89
+ /**
90
+ * 按 shape + spec(length / scale / lineWidth)把首/末段端点向内缩短
91
+ * @description 让 line 端点接在 hollow arrow 尾部外缘、不贯穿 back outline;shrink=0 的实心 shape 跳过。in-place 改写 commands 数组
92
+ */
93
+ var applyArrowShrinks = (commands, shrinkStart, shrinkEnd, strokeWidth, round) => {
94
+ if (shrinkStart > 0) {
95
+ const firstIdx = commands.findIndex((o) => o.kind === "move");
96
+ if (firstIdx >= 0) {
97
+ const cur = commands[firstIdx];
98
+ const nextIdx = commands.findIndex((o, idx) => idx > firstIdx && o.kind !== "close");
99
+ if (cur.kind === "move" && nextIdx >= 0) {
100
+ const nextPt = endpointOf(commands[nextIdx]);
101
+ if (nextPt) setEndpoint(commands, firstIdx, shiftToward([cur.to[0], cur.to[1]], nextPt, shrinkStart * strokeWidth), round);
102
+ }
103
+ }
104
+ }
105
+ if (shrinkEnd > 0) {
106
+ let lastIdx = -1;
107
+ for (let i = commands.length - 1; i >= 0; i--) if (commands[i].kind !== "close") {
108
+ lastIdx = i;
109
+ break;
110
+ }
111
+ if (lastIdx > 0) {
112
+ let prevIdx = lastIdx - 1;
113
+ while (prevIdx >= 0 && commands[prevIdx].kind === "close") prevIdx--;
114
+ if (prevIdx >= 0) {
115
+ const curPt = endpointOf(commands[lastIdx]);
116
+ const prevPt = endpointOf(commands[prevIdx]);
117
+ if (curPt && prevPt) {
118
+ const shifted = shiftToward(curPt, prevPt, shrinkEnd * strokeWidth);
119
+ setEndpoint(commands, lastIdx, shifted, round);
120
+ }
121
+ }
122
+ }
123
+ }
124
+ };
125
+ //#endregion
126
+ export { applyArrowShrinks, computeShrink, endpointArrows };
@@ -0,0 +1,15 @@
1
+ import { ArrowEndSpec, PathCommand, PathPrim, ScenePrimitive } from '../../primitive';
2
+ /** baseProps:除 commands / endpoint arrows 外 PathPrim 公共属性集合(多 sub-path 复用) */
3
+ export type PathBaseProps = Omit<PathPrim, 'type' | 'commands' | 'arrowStart' | 'arrowEnd'>;
4
+ /**
5
+ * 多 sub-path + 有端点箭头:按 sub-path split 成多个 PathPrim
6
+ * @description 端点箭头只属于整条 path 的首端和末端;单 sub-path 或无箭头时直接产一个 PathPrim。
7
+ */
8
+ export declare const splitSubPathsForEndpointArrows: (commands: Array<PathCommand>, baseProps: PathBaseProps, endpointArrows: {
9
+ arrowStart?: ArrowEndSpec;
10
+ arrowEnd?: ArrowEndSpec;
11
+ }) => {
12
+ primitive: ScenePrimitive;
13
+ isGrouped: boolean;
14
+ };
15
+ //# sourceMappingURL=split.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"split.d.ts","sourceRoot":"","sources":["../../../../src/compile/path/split.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAE3F,8EAA8E;AAC9E,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,GAAG,YAAY,GAAG,UAAU,CAAC,CAAC;AAE5F;;;GAGG;AACH,eAAO,MAAM,8BAA8B,GACzC,UAAU,KAAK,CAAC,WAAW,CAAC,EAC5B,WAAW,aAAa,EACxB,gBAAgB;IAAE,UAAU,CAAC,EAAE,YAAY,CAAC;IAAC,QAAQ,CAAC,EAAE,YAAY,CAAA;CAAE,KACrE;IAAE,SAAS,EAAE,cAAc,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CA2CjD,CAAC"}