@retikz/core 0.2.0-alpha.6 → 0.2.0-alpha.8

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 (171) hide show
  1. package/dist/es/arrows/index.d.ts +13 -0
  2. package/dist/es/arrows/index.d.ts.map +1 -0
  3. package/dist/es/arrows/index.js +118 -0
  4. package/dist/es/arrows/types.d.ts +43 -0
  5. package/dist/es/arrows/types.d.ts.map +1 -0
  6. package/dist/es/compile/compile.d.ts +26 -1
  7. package/dist/es/compile/compile.d.ts.map +1 -1
  8. package/dist/es/compile/compile.js +37 -4
  9. package/dist/es/compile/marker-prim.d.ts +22 -0
  10. package/dist/es/compile/marker-prim.d.ts.map +1 -0
  11. package/dist/es/compile/marker-prim.js +63 -0
  12. package/dist/es/compile/node.d.ts +19 -4
  13. package/dist/es/compile/node.d.ts.map +1 -1
  14. package/dist/es/compile/node.js +159 -29
  15. package/dist/es/compile/paint.d.ts +21 -0
  16. package/dist/es/compile/paint.d.ts.map +1 -0
  17. package/dist/es/compile/paint.js +94 -0
  18. package/dist/es/compile/path/index.d.ts +18 -0
  19. package/dist/es/compile/path/index.d.ts.map +1 -1
  20. package/dist/es/compile/path/index.js +260 -11
  21. package/dist/es/compile/path/relative.d.ts.map +1 -1
  22. package/dist/es/compile/path/relative.js +8 -0
  23. package/dist/es/compile/path/shrink.d.ts +19 -6
  24. package/dist/es/compile/path/shrink.d.ts.map +1 -1
  25. package/dist/es/compile/path/shrink.js +147 -25
  26. package/dist/es/geometry/bend.d.ts +7 -0
  27. package/dist/es/geometry/bend.d.ts.map +1 -1
  28. package/dist/es/geometry/bend.js +26 -1
  29. package/dist/es/index.d.ts +14 -4
  30. package/dist/es/index.d.ts.map +1 -1
  31. package/dist/es/index.js +7 -2
  32. package/dist/es/ir/index.d.ts +2 -0
  33. package/dist/es/ir/index.d.ts.map +1 -1
  34. package/dist/es/ir/json.d.ts +22 -0
  35. package/dist/es/ir/json.d.ts.map +1 -0
  36. package/dist/es/ir/json.js +25 -0
  37. package/dist/es/ir/node.d.ts +262 -9
  38. package/dist/es/ir/node.d.ts.map +1 -1
  39. package/dist/es/ir/node.js +9 -2
  40. package/dist/es/ir/paint.d.ts +154 -0
  41. package/dist/es/ir/paint.d.ts.map +1 -0
  42. package/dist/es/ir/paint.js +59 -0
  43. package/dist/es/ir/path/arrow.d.ts +52 -72
  44. package/dist/es/ir/path/arrow.d.ts.map +1 -1
  45. package/dist/es/ir/path/arrow.js +5 -5
  46. package/dist/es/ir/path/path.d.ts +637 -87
  47. package/dist/es/ir/path/path.d.ts.map +1 -1
  48. package/dist/es/ir/path/path.js +23 -2
  49. package/dist/es/ir/path/step.d.ts +363 -8
  50. package/dist/es/ir/path/step.d.ts.map +1 -1
  51. package/dist/es/ir/path/step.js +17 -4
  52. package/dist/es/ir/scope.d.ts +1874 -338
  53. package/dist/es/ir/scope.d.ts.map +1 -1
  54. package/dist/es/ir/scope.js +2 -1
  55. package/dist/es/pathGenerators/define.d.ts +16 -0
  56. package/dist/es/pathGenerators/define.d.ts.map +1 -0
  57. package/dist/es/pathGenerators/define.js +23 -0
  58. package/dist/es/pathGenerators/index.d.ts +9 -0
  59. package/dist/es/pathGenerators/index.d.ts.map +1 -0
  60. package/dist/es/pathGenerators/types.d.ts +45 -0
  61. package/dist/es/pathGenerators/types.d.ts.map +1 -0
  62. package/dist/es/patterns/index.d.ts +10 -0
  63. package/dist/es/patterns/index.d.ts.map +1 -0
  64. package/dist/es/patterns/index.js +83 -0
  65. package/dist/es/patterns/types.d.ts +38 -0
  66. package/dist/es/patterns/types.d.ts.map +1 -0
  67. package/dist/es/primitive/ellipse.d.ts +3 -5
  68. package/dist/es/primitive/ellipse.d.ts.map +1 -1
  69. package/dist/es/primitive/index.d.ts +1 -0
  70. package/dist/es/primitive/index.d.ts.map +1 -1
  71. package/dist/es/primitive/marker.d.ts +160 -0
  72. package/dist/es/primitive/marker.d.ts.map +1 -0
  73. package/dist/es/primitive/paint.d.ts +46 -0
  74. package/dist/es/primitive/paint.d.ts.map +1 -0
  75. package/dist/es/primitive/path.d.ts +25 -20
  76. package/dist/es/primitive/path.d.ts.map +1 -1
  77. package/dist/es/primitive/rect.d.ts +3 -2
  78. package/dist/es/primitive/rect.d.ts.map +1 -1
  79. package/dist/es/primitive/scene.d.ts +4 -0
  80. package/dist/es/primitive/scene.d.ts.map +1 -1
  81. package/dist/es/shapes/types.d.ts +2 -2
  82. package/dist/es/shapes/types.d.ts.map +1 -1
  83. package/dist/lib/arrows/index.cjs +118 -0
  84. package/dist/lib/arrows/index.d.ts +13 -0
  85. package/dist/lib/arrows/index.d.ts.map +1 -0
  86. package/dist/lib/arrows/types.d.ts +43 -0
  87. package/dist/lib/arrows/types.d.ts.map +1 -0
  88. package/dist/lib/compile/compile.cjs +38 -5
  89. package/dist/lib/compile/compile.d.ts +26 -1
  90. package/dist/lib/compile/compile.d.ts.map +1 -1
  91. package/dist/lib/compile/marker-prim.cjs +63 -0
  92. package/dist/lib/compile/marker-prim.d.ts +22 -0
  93. package/dist/lib/compile/marker-prim.d.ts.map +1 -0
  94. package/dist/lib/compile/node.cjs +159 -28
  95. package/dist/lib/compile/node.d.ts +19 -4
  96. package/dist/lib/compile/node.d.ts.map +1 -1
  97. package/dist/lib/compile/paint.cjs +94 -0
  98. package/dist/lib/compile/paint.d.ts +21 -0
  99. package/dist/lib/compile/paint.d.ts.map +1 -0
  100. package/dist/lib/compile/path/index.cjs +258 -9
  101. package/dist/lib/compile/path/index.d.ts +18 -0
  102. package/dist/lib/compile/path/index.d.ts.map +1 -1
  103. package/dist/lib/compile/path/relative.cjs +8 -0
  104. package/dist/lib/compile/path/relative.d.ts.map +1 -1
  105. package/dist/lib/compile/path/shrink.cjs +147 -25
  106. package/dist/lib/compile/path/shrink.d.ts +19 -6
  107. package/dist/lib/compile/path/shrink.d.ts.map +1 -1
  108. package/dist/lib/geometry/bend.cjs +26 -0
  109. package/dist/lib/geometry/bend.d.ts +7 -0
  110. package/dist/lib/geometry/bend.d.ts.map +1 -1
  111. package/dist/lib/index.cjs +14 -0
  112. package/dist/lib/index.d.ts +14 -4
  113. package/dist/lib/index.d.ts.map +1 -1
  114. package/dist/lib/ir/index.d.ts +2 -0
  115. package/dist/lib/ir/index.d.ts.map +1 -1
  116. package/dist/lib/ir/json.cjs +26 -0
  117. package/dist/lib/ir/json.d.ts +22 -0
  118. package/dist/lib/ir/json.d.ts.map +1 -0
  119. package/dist/lib/ir/node.cjs +9 -2
  120. package/dist/lib/ir/node.d.ts +262 -9
  121. package/dist/lib/ir/node.d.ts.map +1 -1
  122. package/dist/lib/ir/paint.cjs +61 -0
  123. package/dist/lib/ir/paint.d.ts +154 -0
  124. package/dist/lib/ir/paint.d.ts.map +1 -0
  125. package/dist/lib/ir/path/arrow.cjs +5 -5
  126. package/dist/lib/ir/path/arrow.d.ts +52 -72
  127. package/dist/lib/ir/path/arrow.d.ts.map +1 -1
  128. package/dist/lib/ir/path/path.cjs +22 -1
  129. package/dist/lib/ir/path/path.d.ts +637 -87
  130. package/dist/lib/ir/path/path.d.ts.map +1 -1
  131. package/dist/lib/ir/path/step.cjs +17 -3
  132. package/dist/lib/ir/path/step.d.ts +363 -8
  133. package/dist/lib/ir/path/step.d.ts.map +1 -1
  134. package/dist/lib/ir/scope.cjs +2 -1
  135. package/dist/lib/ir/scope.d.ts +1874 -338
  136. package/dist/lib/ir/scope.d.ts.map +1 -1
  137. package/dist/lib/pathGenerators/define.cjs +23 -0
  138. package/dist/lib/pathGenerators/define.d.ts +16 -0
  139. package/dist/lib/pathGenerators/define.d.ts.map +1 -0
  140. package/dist/lib/pathGenerators/index.d.ts +9 -0
  141. package/dist/lib/pathGenerators/index.d.ts.map +1 -0
  142. package/dist/lib/pathGenerators/types.d.ts +45 -0
  143. package/dist/lib/pathGenerators/types.d.ts.map +1 -0
  144. package/dist/lib/patterns/index.cjs +83 -0
  145. package/dist/lib/patterns/index.d.ts +10 -0
  146. package/dist/lib/patterns/index.d.ts.map +1 -0
  147. package/dist/lib/patterns/types.d.ts +38 -0
  148. package/dist/lib/patterns/types.d.ts.map +1 -0
  149. package/dist/lib/primitive/ellipse.d.ts +3 -5
  150. package/dist/lib/primitive/ellipse.d.ts.map +1 -1
  151. package/dist/lib/primitive/index.d.ts +1 -0
  152. package/dist/lib/primitive/index.d.ts.map +1 -1
  153. package/dist/lib/primitive/marker.d.ts +160 -0
  154. package/dist/lib/primitive/marker.d.ts.map +1 -0
  155. package/dist/lib/primitive/paint.d.ts +46 -0
  156. package/dist/lib/primitive/paint.d.ts.map +1 -0
  157. package/dist/lib/primitive/path.d.ts +25 -20
  158. package/dist/lib/primitive/path.d.ts.map +1 -1
  159. package/dist/lib/primitive/rect.d.ts +3 -2
  160. package/dist/lib/primitive/rect.d.ts.map +1 -1
  161. package/dist/lib/primitive/scene.d.ts +4 -0
  162. package/dist/lib/primitive/scene.d.ts.map +1 -1
  163. package/dist/lib/shapes/types.d.ts +2 -2
  164. package/dist/lib/shapes/types.d.ts.map +1 -1
  165. package/package.json +1 -1
  166. package/dist/es/compile/path/arrow-geometry.d.ts +0 -22
  167. package/dist/es/compile/path/arrow-geometry.d.ts.map +0 -1
  168. package/dist/es/compile/path/arrow-geometry.js +0 -40
  169. package/dist/lib/compile/path/arrow-geometry.cjs +0 -41
  170. package/dist/lib/compile/path/arrow-geometry.d.ts +0 -22
  171. package/dist/lib/compile/path/arrow-geometry.d.ts.map +0 -1
@@ -5,6 +5,49 @@ var DEFAULT_FONT_SIZE = 14;
5
5
  var DEFAULT_PADDING = 8;
6
6
  var DEFAULT_LINE_HEIGHT_FACTOR = 1.2;
7
7
  var DEG_TO_RAD = Math.PI / 180;
8
+ /** CJK / fullwidth ranges: break per-character (no whitespace needed) */
9
+ var isCjk = (ch) => {
10
+ const c = ch.codePointAt(0) ?? 0;
11
+ return c >= 12288 && c <= 12351 || c >= 12352 && c <= 12543 || c >= 13312 && c <= 19903 || c >= 19968 && c <= 40959 || c >= 63744 && c <= 64255 || c >= 65280 && c <= 65519;
12
+ };
13
+ /**
14
+ * 按 maxWidth 贪心折行:西文按词(空白分割)、CJK 按字;长不可断 token 溢出不硬断
15
+ * @description 用注入的 measureText 度量;连续空白归一为单空格分隔。空文本返回 [''].
16
+ */
17
+ var wrapText = (text, font, maxWidth, measure) => {
18
+ const units = [];
19
+ for (const seg of text.split(/(\s+)/)) {
20
+ if (seg === "") continue;
21
+ if (/^\s+$/.test(seg)) {
22
+ units.push(" ");
23
+ continue;
24
+ }
25
+ let run = "";
26
+ for (const ch of seg) if (isCjk(ch)) {
27
+ if (run) {
28
+ units.push(run);
29
+ run = "";
30
+ }
31
+ units.push(ch);
32
+ } else run += ch;
33
+ if (run) units.push(run);
34
+ }
35
+ const lines = [];
36
+ let cur = "";
37
+ for (const u of units) {
38
+ if (u === " ") {
39
+ if (cur !== "") cur += " ";
40
+ continue;
41
+ }
42
+ const candidate = cur === "" ? u : cur + u;
43
+ if (cur !== "" && measure(candidate, font).width > maxWidth) {
44
+ lines.push(cur.trimEnd());
45
+ cur = u;
46
+ } else cur = candidate;
47
+ }
48
+ if (cur.trimEnd() !== "") lines.push(cur.trimEnd());
49
+ return lines.length > 0 ? lines : [""];
50
+ };
8
51
  /** Node label 与 node 边界默认距离(TikZ 默认 0pt 视觉太贴) */
9
52
  var DEFAULT_LABEL_DISTANCE = 12;
10
53
  /** dashed 预设:4 px 实线 + 2 px 间隙循环 */
@@ -84,7 +127,8 @@ var LABEL_DIRECTION_MAP = {
84
127
  * 若用带 rotate 的 rect,label 位置会被 anchorOf / angleBoundaryOf 旋转一次、再被外层 group 旋转一次(双重旋转)。
85
128
  * anchorOf / angleBoundaryOf 本身不改(path anchor `'A.north'` / `'A.30'` 仍需带 rotate 的 rect)。
86
129
  */
87
- var labelCenter = (layout, label) => {
130
+ /** label node 边界上的附着点(未旋转局部系;pin 引线起点 = 此点) */
131
+ var labelBorderPoint = (layout, label) => {
88
132
  const aaLayout = {
89
133
  ...layout,
90
134
  rect: {
@@ -92,15 +136,32 @@ var labelCenter = (layout, label) => {
92
136
  rotate: 0
93
137
  }
94
138
  };
139
+ if (typeof label.position === "number") return angleBoundaryOf(aaLayout, label.position);
140
+ const { anchor } = LABEL_DIRECTION_MAP[label.position];
141
+ return anchorOf(aaLayout, anchor);
142
+ };
143
+ var labelCenter = (layout, label) => {
144
+ const [bx, by] = labelBorderPoint(layout, label);
95
145
  if (typeof label.position === "number") {
96
146
  const rad = label.position * Math.PI / 180;
97
- const [bx, by] = angleBoundaryOf(aaLayout, label.position);
98
147
  return [bx + Math.cos(rad) * label.distance, by + Math.sin(rad) * label.distance];
99
148
  }
100
- const { anchor, vec } = LABEL_DIRECTION_MAP[label.position];
101
- const [bx, by] = anchorOf(aaLayout, anchor);
149
+ const { vec } = LABEL_DIRECTION_MAP[label.position];
102
150
  return [bx + vec[0] * label.distance, by + vec[1] * label.distance];
103
151
  };
152
+ /** 从 label 中心朝 border 方向,求 label 框(halfW×halfH)边界交点(pin 引线终点 = label 框近 node 边) */
153
+ var labelBoxEdgeToward = (center, border, halfW, halfH) => {
154
+ const dx = border[0] - center[0];
155
+ const dy = border[1] - center[1];
156
+ const len = Math.hypot(dx, dy);
157
+ if (len < 1e-9) return center;
158
+ const ux = dx / len;
159
+ const uy = dy / len;
160
+ const sx = Math.abs(ux) > 1e-9 ? halfW / Math.abs(ux) : Number.POSITIVE_INFINITY;
161
+ const sy = Math.abs(uy) > 1e-9 ? halfH / Math.abs(uy) : Number.POSITIVE_INFINITY;
162
+ const s = Math.min(sx, sy, len);
163
+ return [center[0] + ux * s, center[1] + uy * s];
164
+ };
104
165
  /** 角度换算常量(弧度 → 度) */
105
166
  var RAD_TO_DEG = 180 / Math.PI;
106
167
  /**
@@ -162,32 +223,38 @@ var layoutNode = (node, measureText, nameStack, nodeDistance, scopeChain = [], l
162
223
  const lineHeight = (node.lineHeight ?? baseFontSize * DEFAULT_LINE_HEIGHT_FACTOR) * sy;
163
224
  const align = alignToTextAnchor(node.align ?? "center");
164
225
  const rawLines = node.text === void 0 ? void 0 : typeof node.text === "string" ? [node.text] : node.text;
226
+ const maxTextWidth = node.maxTextWidth !== void 0 ? node.maxTextWidth * sx : void 0;
165
227
  let textWidth = 0;
166
228
  let textHeight = 0;
167
229
  let lines;
168
230
  if (rawLines) {
169
- lines = rawLines.map((spec) => {
231
+ lines = [];
232
+ for (const spec of rawLines) {
170
233
  const isObj = typeof spec !== "string";
171
234
  const text = isObj ? spec.text : spec;
172
235
  const lineFont = isObj ? spec.font : void 0;
173
- const m = measureText(text, {
236
+ const font = {
174
237
  size: lineFont?.size ?? fontSize,
175
238
  family: lineFont?.family ?? fontFamily,
176
239
  weight: lineFont?.weight ?? fontWeight,
177
240
  style: lineFont?.style ?? fontStyle
178
- });
179
- if (m.width > textWidth) textWidth = m.width;
180
- const out = { text };
181
- if (isObj) {
182
- if (spec.fill !== void 0) out.fill = spec.fill;
183
- if (spec.opacity !== void 0) out.opacity = spec.opacity;
184
- if (lineFont?.size !== void 0) out.fontSize = lineFont.size;
185
- if (lineFont?.family !== void 0) out.fontFamily = lineFont.family;
186
- if (lineFont?.weight !== void 0) out.fontWeight = lineFont.weight;
187
- if (lineFont?.style !== void 0) out.fontStyle = lineFont.style;
241
+ };
242
+ const physical = maxTextWidth !== void 0 ? wrapText(text, font, maxTextWidth, measureText) : [text];
243
+ for (const ptext of physical) {
244
+ const m = measureText(ptext, font);
245
+ if (m.width > textWidth) textWidth = m.width;
246
+ const out = { text: ptext };
247
+ if (isObj) {
248
+ if (spec.fill !== void 0) out.fill = spec.fill;
249
+ if (spec.opacity !== void 0) out.opacity = spec.opacity;
250
+ if (lineFont?.size !== void 0) out.fontSize = lineFont.size;
251
+ if (lineFont?.family !== void 0) out.fontFamily = lineFont.family;
252
+ if (lineFont?.weight !== void 0) out.fontWeight = lineFont.weight;
253
+ if (lineFont?.style !== void 0) out.fontStyle = lineFont.style;
254
+ }
255
+ lines.push(out);
188
256
  }
189
- return out;
190
- });
257
+ }
191
258
  textHeight = lines.length * lineHeight;
192
259
  }
193
260
  const minW = node.minimumWidth ?? node.minimumSize ?? 0;
@@ -200,18 +267,29 @@ var layoutNode = (node, measureText, nameStack, nodeDistance, scopeChain = [], l
200
267
  if (!center) throw new Error(`Cannot resolve position for node ${node.id ?? "(unnamed)"}; polar.origin or at.of may reference an undefined node`);
201
268
  const labels = (node.label === void 0 ? void 0 : Array.isArray(node.label) ? node.label : [node.label])?.map((lab) => {
202
269
  const labFont = lab.font;
270
+ const labFontSize = (labFont?.size ?? labelDefault?.font?.size ?? baseFontSize) * fontScale;
271
+ const labFamily = labFont?.family ?? labelDefault?.font?.family ?? fontFamily;
272
+ const labWeight = labFont?.weight ?? labelDefault?.font?.weight ?? fontWeight;
273
+ const labStyle = labFont?.style ?? labelDefault?.font?.style ?? fontStyle;
203
274
  return {
204
275
  text: lab.text,
205
276
  position: lab.position ?? "above",
206
277
  distance: lab.distance ?? DEFAULT_LABEL_DISTANCE,
207
278
  textColor: lab.textColor ?? labelDefault?.textColor ?? labelDefault?.color ?? node.textColor,
208
279
  opacity: lab.opacity ?? labelDefault?.opacity,
209
- fontSize: (labFont?.size ?? labelDefault?.font?.size ?? baseFontSize) * fontScale,
210
- fontFamily: labFont?.family ?? labelDefault?.font?.family ?? fontFamily,
211
- fontWeight: labFont?.weight ?? labelDefault?.font?.weight ?? fontWeight,
212
- fontStyle: labFont?.style ?? labelDefault?.font?.style ?? fontStyle,
280
+ fontSize: labFontSize,
281
+ fontFamily: labFamily,
282
+ fontWeight: labWeight,
283
+ fontStyle: labStyle,
213
284
  rotate: lab.rotate,
214
- keepUpright: lab.keepUpright
285
+ keepUpright: lab.keepUpright,
286
+ measuredWidth: measureText(lab.text, {
287
+ size: labFontSize,
288
+ family: labFamily,
289
+ weight: labWeight,
290
+ style: labStyle
291
+ }).width,
292
+ pin: lab.pin
215
293
  };
216
294
  });
217
295
  return {
@@ -248,9 +326,9 @@ var layoutNode = (node, measureText, nameStack, nodeDistance, scopeChain = [], l
248
326
  labels
249
327
  };
250
328
  };
251
- /** 从 NodeLayout 收敛 emit 所需的视觉样式子集(ShapeStyle,不含几何 / 文本) */
252
- var toShapeStyle = (layout) => ({
253
- fill: layout.fill,
329
+ /** 从 NodeLayout 收敛 emit 所需的视觉样式子集(ShapeStyle,不含几何 / 文本);fill 经 resolveFill 转 PaintValue */
330
+ var toShapeStyle = (layout, resolveFill) => ({
331
+ fill: resolveFill(layout.fill),
254
332
  fillOpacity: layout.fillOpacity,
255
333
  stroke: layout.stroke,
256
334
  strokeOpacity: layout.strokeOpacity,
@@ -264,12 +342,44 @@ var toShapeStyle = (layout) => ({
264
342
  * @description shape 主体走 `shapeDef.emit`(收轴对齐 rect、可出多 primitive);text 始终走 TextPrim;
265
343
  * 有旋转时外层 GroupPrim 用 `rotate(deg cx cy)` 统一包裹 shape + text(diamond 顶点 / text 都靠 group 旋转)
266
344
  */
267
- var emitNodePrimitives = (layout, round) => {
345
+ /**
346
+ * 节点 label 的外接点(供顶层 bbox / viewBox 计算,让 label 不被裁——与 step.label 进 bbox 一致)
347
+ * @description 每个 label 取其文本框四角;label 中心走 labelCenter(轴对齐系),node 自身 rotate 时绕 node 中心旋转
348
+ * (与 emit 的 group rotate 同步)。pin 引线起点在 node 边界内、已被 node 四角覆盖,无需额外。
349
+ */
350
+ var labelExtentPoints = (layout) => {
351
+ if (!layout.labels || layout.labels.length === 0) return [];
352
+ const cx = layout.rect.x;
353
+ const cy = layout.rect.y;
354
+ const rad = layout.rotateDeg * Math.PI / 180;
355
+ const cos = Math.cos(rad);
356
+ const sin = Math.sin(rad);
357
+ const pts = [];
358
+ for (const lab of layout.labels) {
359
+ const [lx, ly] = labelCenter(layout, lab);
360
+ const halfW = lab.measuredWidth / 2;
361
+ const halfH = lab.fontSize / 2;
362
+ const corners = [
363
+ [lx - halfW, ly - halfH],
364
+ [lx + halfW, ly - halfH],
365
+ [lx - halfW, ly + halfH],
366
+ [lx + halfW, ly + halfH]
367
+ ];
368
+ for (const [px, py] of corners) if (layout.rotateDeg === 0) pts.push([px, py]);
369
+ else {
370
+ const dx = px - cx;
371
+ const dy = py - cy;
372
+ pts.push([cx + dx * cos - dy * sin, cy + dx * sin + dy * cos]);
373
+ }
374
+ }
375
+ return pts;
376
+ };
377
+ var emitNodePrimitives = (layout, round, resolveFill) => {
268
378
  const axisAlignedRect = {
269
379
  ...layout.rect,
270
380
  rotate: 0
271
381
  };
272
- const inner = [...layout.shapeDef.emit(axisAlignedRect, toShapeStyle(layout), round)];
382
+ const inner = [...layout.shapeDef.emit(axisAlignedRect, toShapeStyle(layout, resolveFill), round)];
273
383
  if (layout.lines) {
274
384
  const halfBlockW = layout.textWidth / 2;
275
385
  const xOffset = layout.align === "start" ? -halfBlockW : layout.align === "end" ? halfBlockW : 0;
@@ -296,6 +406,26 @@ var emitNodePrimitives = (layout, round) => {
296
406
  const cy = layout.rect.y;
297
407
  for (const lab of layout.labels) {
298
408
  const [lx, ly] = labelCenter(layout, lab);
409
+ if (lab.pin) {
410
+ const style = typeof lab.pin === "object" ? lab.pin : void 0;
411
+ const [bx, by] = labelBorderPoint(layout, lab);
412
+ const pad = 2;
413
+ const [nx, ny] = labelBoxEdgeToward([lx, ly], [bx, by], lab.measuredWidth / 2 + pad, lab.fontSize / 2 + pad);
414
+ inner.push({
415
+ type: "path",
416
+ commands: [{
417
+ kind: "move",
418
+ to: [round(bx), round(by)]
419
+ }, {
420
+ kind: "line",
421
+ to: [round(nx), round(ny)]
422
+ }],
423
+ stroke: style?.stroke ?? lab.textColor ?? "currentColor",
424
+ strokeWidth: style?.strokeWidth ?? 1,
425
+ dashPattern: style?.dashPattern,
426
+ opacity: lab.opacity ?? layout.opacity
427
+ });
428
+ }
299
429
  const textPrim = {
300
430
  type: "text",
301
431
  x: round(lx),
@@ -341,4 +471,4 @@ var emitNodePrimitives = (layout, round) => {
341
471
  return [group];
342
472
  };
343
473
  //#endregion
344
- export { anchorOf, angleBoundaryOf, boundaryPointOf, emitNodePrimitives, layoutNode };
474
+ export { anchorOf, angleBoundaryOf, boundaryPointOf, emitNodePrimitives, labelExtentPoints, layoutNode };
@@ -0,0 +1,21 @@
1
+ import { IRPaintSpec } from '../ir';
2
+ import { PatternDefinition } from '../patterns';
3
+ import { PaintValue, SceneResource } from '../primitive';
4
+ /** fill 解析器:纯色 string 原样返回;PaintSpec 去重 + 派稳定 id → `{ kind:'resourceRef', id }`;undefined 透传 */
5
+ export type PaintResolver = (fill: string | IRPaintSpec | undefined) => PaintValue | undefined;
6
+ /** paint 资源登记表:编译期收集 PaintSpec、去重派 id,最后产出 Scene.resources */
7
+ export type PaintRegistry = {
8
+ resolve: PaintResolver;
9
+ resources: () => Array<SceneResource>;
10
+ };
11
+ /**
12
+ * 建一个 paint 登记表
13
+ * @description resolve 对相同 PaintSpec(结构化 JSON 深比较)合并为一个资源、派稳定 id(`paint-1` / `paint-2`…,首见序)。
14
+ * 同一份 IR 编译两次 → 同 id(快照稳定、SSR / CSR 一致)。SVG id 跨实例唯一性由 react adapter 加 useId 前缀解决。
15
+ * pattern 资源额外查 `effectivePatterns` + 调 `PatternDefinition.emit` 产 tile 写进 `SceneResource.tile`
16
+ * (未注册名 throw、含可用名);gradient / image 资源只 spec。
17
+ * @param effectivePatterns 有效 pattern 表(内置 + 注入),供 pattern 资源查表 + emit
18
+ * @param round 精度取整(与 compile / render 同一 round,保 tile 几何一致)
19
+ */
20
+ export declare const createPaintRegistry: (effectivePatterns: Record<string, PatternDefinition>, round: (n: number) => number) => PaintRegistry;
21
+ //# sourceMappingURL=paint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paint.d.ts","sourceRoot":"","sources":["../../../src/compile/paint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACzC,OAAO,KAAK,EAAE,iBAAiB,EAAsB,MAAM,aAAa,CAAC;AACzE,OAAO,KAAK,EAAmB,UAAU,EAAuB,aAAa,EAAE,MAAM,cAAc,CAAC;AAGpG,gGAAgG;AAChG,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,KAAK,UAAU,GAAG,SAAS,CAAC;AAE/F,8DAA8D;AAC9D,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,aAAa,CAAC;IACvB,SAAS,EAAE,MAAM,KAAK,CAAC,aAAa,CAAC,CAAC;CACvC,CAAC;AA+EF;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,GAC9B,mBAAmB,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,EACpD,OAAO,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,KAC3B,aAuBF,CAAC"}
@@ -0,0 +1,94 @@
1
+ import { validateMarkerPrimitives } from "./marker-prim.js";
2
+ //#region src/compile/paint.ts
3
+ /** 内置 / 注入都缺 defaultSize 时的 tile 周期兜底(user units) */
4
+ var FALLBACK_PATTERN_SIZE = 8;
5
+ /** motif 缺省主色:CSS `currentColor`(继承 svg color,主题反应天然) */
6
+ var DEFAULT_MOTIF_COLOR = "currentColor";
7
+ /**
8
+ * 查有效 pattern 表取 def;未注册名编译期 throw(消息含字母序可用名列表)
9
+ * @description 仿 arrow / shape 的未注册 throw 风格——错误带可用名便于第三方 / LLM 自修。
10
+ */
11
+ var lookupPatternDef = (shape, effective) => {
12
+ if (Object.prototype.hasOwnProperty.call(effective, shape)) return effective[shape];
13
+ const available = Object.keys(effective).sort().join(", ");
14
+ throw new Error(`Unknown pattern shape '${shape}'; available: ${available}`);
15
+ };
16
+ /**
17
+ * 对一个 pattern spec 查表 + 调 `def.emit` 产已解析 tile
18
+ * @description 构 `PatternEmitContext`(size = spec.size ?? def.defaultSize ?? 8;color = spec.color ??
19
+ * currentColor;background 透传;lineWidth 仅 spec 显式给值时存在——让 dots 缺省半径 size/5、lines/grid
20
+ * 缺省描边 1)→ 调 emit 收 `MarkerPrimitive[]` → 跑共享窄子集 + JSON-safe 校验 → 组装 `ResolvedPatternTile`。
21
+ * emit 抛错 / 产非法原语都包成含 shape 名的清晰错(带 cause)。
22
+ */
23
+ var resolvePatternTile = (spec, effectivePatterns, round) => {
24
+ const def = lookupPatternDef(spec.shape, effectivePatterns);
25
+ const rawSize = spec.size ?? def.defaultSize ?? FALLBACK_PATTERN_SIZE;
26
+ if (!Number.isFinite(rawSize) || rawSize <= 0) throw new Error(`Pattern '${spec.shape}' has an invalid size (${String(rawSize)}); it must be a finite number greater than 0.`);
27
+ if (spec.lineWidth !== void 0 && (!Number.isFinite(spec.lineWidth) || spec.lineWidth <= 0)) throw new Error(`Pattern '${spec.shape}' has an invalid lineWidth (${String(spec.lineWidth)}); it must be a finite number greater than 0.`);
28
+ if (spec.rotation !== void 0 && !Number.isFinite(spec.rotation)) throw new Error(`Pattern '${spec.shape}' has a non-finite rotation (${String(spec.rotation)}); it must be a finite number.`);
29
+ const size = round(rawSize);
30
+ const ctx = {
31
+ size,
32
+ color: spec.color ?? DEFAULT_MOTIF_COLOR,
33
+ round
34
+ };
35
+ if (spec.background !== void 0) ctx.background = spec.background;
36
+ if (spec.lineWidth !== void 0) ctx.lineWidth = spec.lineWidth;
37
+ if (typeof def.emit !== "function") throw new Error(`Pattern '${spec.shape}' is missing an emit function (PatternDefinition.emit is required).`);
38
+ let motif;
39
+ try {
40
+ motif = [...def.emit(ctx)];
41
+ } catch (e) {
42
+ throw new Error(`Pattern '${spec.shape}' emit failed: ${e instanceof Error ? e.message : String(e)}`, { cause: e });
43
+ }
44
+ validateMarkerPrimitives(`Pattern '${spec.shape}'`, motif);
45
+ const tile = {
46
+ size,
47
+ motif
48
+ };
49
+ if (spec.background !== void 0) tile.background = spec.background;
50
+ if (spec.rotation !== void 0) tile.rotation = spec.rotation;
51
+ return tile;
52
+ };
53
+ /**
54
+ * 建一个 paint 登记表
55
+ * @description resolve 对相同 PaintSpec(结构化 JSON 深比较)合并为一个资源、派稳定 id(`paint-1` / `paint-2`…,首见序)。
56
+ * 同一份 IR 编译两次 → 同 id(快照稳定、SSR / CSR 一致)。SVG id 跨实例唯一性由 react adapter 加 useId 前缀解决。
57
+ * pattern 资源额外查 `effectivePatterns` + 调 `PatternDefinition.emit` 产 tile 写进 `SceneResource.tile`
58
+ * (未注册名 throw、含可用名);gradient / image 资源只 spec。
59
+ * @param effectivePatterns 有效 pattern 表(内置 + 注入),供 pattern 资源查表 + emit
60
+ * @param round 精度取整(与 compile / render 同一 round,保 tile 几何一致)
61
+ */
62
+ var createPaintRegistry = (effectivePatterns, round) => {
63
+ const idByKey = /* @__PURE__ */ new Map();
64
+ const list = [];
65
+ let counter = 0;
66
+ const resolve = (fill) => {
67
+ if (fill === void 0) return void 0;
68
+ if (typeof fill === "string") return fill;
69
+ const key = JSON.stringify(fill);
70
+ let id = idByKey.get(key);
71
+ if (id === void 0) {
72
+ counter += 1;
73
+ id = `paint-${counter}`;
74
+ idByKey.set(key, id);
75
+ const resource = {
76
+ kind: "paint",
77
+ id,
78
+ spec: fill
79
+ };
80
+ if (fill.type === "pattern") resource.tile = resolvePatternTile(fill, effectivePatterns, round);
81
+ list.push(resource);
82
+ }
83
+ return {
84
+ kind: "resourceRef",
85
+ id
86
+ };
87
+ };
88
+ return {
89
+ resolve,
90
+ resources: () => list
91
+ };
92
+ };
93
+ //#endregion
94
+ export { createPaintRegistry };
@@ -1,7 +1,10 @@
1
+ import { PaintResolver } from '../paint';
1
2
  import { IRPath, IRPosition } from '../../ir';
2
3
  import { ScenePrimitive, Transform } from '../../primitive';
4
+ import { PathGeneratorDefinition } from '../../pathGenerators';
3
5
  import { NameStack } from '../name-stack';
4
6
  import { TextMeasurer } from '../text-metrics';
7
+ import { EffectiveArrows } from './shrink';
5
8
  /** emitPathPrimitive 可选 warn 钩子 */
6
9
  export type EmitPathWarnHook = {
7
10
  /** 警告收集器(由 compileToScene 传入) */
@@ -18,6 +21,21 @@ export type EmitPathWarnHook = {
18
21
  * 投影回全局;顶层 path / 无 scope chain 时为 `[]`(恒等,等价 v0.1 行为)
19
22
  */
20
23
  scopeChain?: ReadonlyArray<Transform>;
24
+ /** fill 解析器(PaintSpec → resourceRef + 登记资源);缺省时纯色透传、PaintSpec 退化为无填充 */
25
+ resolveFill?: PaintResolver;
26
+ /**
27
+ * 有效 arrow 表(内置 7 + 注入);缺省 = 仅内置 7
28
+ * @description compileToScene 合并 `{ ...BUILTIN_ARROWS, ...options.arrows }` 传入;
29
+ * endpointArrows 据此查表算 shrink / 调 def.emit;未注册名编译期 throw
30
+ */
31
+ effectiveArrows?: EffectiveArrows;
32
+ /**
33
+ * 有效 path generator 表(注入即全部,core 无内置);缺省 = 空表
34
+ * @description compileToScene 传 `options.pathGenerators ?? {}`;generator step 据此查表(未注册名
35
+ * 编译期 throw,错误列出可用名)→ 双 parse 护栏 → targetParams resolve → 调 generate splice 命令。
36
+ * 解析逻辑由后续实现落地(此处仅声明 hook 入口)。
37
+ */
38
+ effectivePathGenerators?: Record<string, PathGeneratorDefinition>;
21
39
  };
22
40
  /**
23
41
  * IR Path → PathPrim
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/compile/path/index.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EACV,MAAM,EACN,UAAU,EAGX,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAEV,cAAc,EACd,SAAS,EACV,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,KAAK,YAAY,EAAoB,MAAM,iBAAiB,CAAC;AAkCtE,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;IAChB;;;;OAIG;IACH,UAAU,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;CACvC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,MAAM,EACZ,WAAW,SAAS,EACpB,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,IAkhBrE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/compile/path/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAY9C,OAAO,KAAK,EACV,MAAM,EAEN,UAAU,EAGX,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAIV,cAAc,EACd,SAAS,EACV,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,KAAK,YAAY,EAAoB,MAAM,iBAAiB,CAAC;AAKtE,OAAO,EAAE,KAAK,eAAe,EAA2D,MAAM,UAAU,CAAC;AAsFzG,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;IAChB;;;;OAIG;IACH,UAAU,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;IACtC,wEAAwE;IACxE,WAAW,CAAC,EAAE,aAAa,CAAC;IAC5B;;;;OAIG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC;;;;;OAKG;IACH,uBAAuB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC;CACnE,CAAC;AA0EF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,MAAM,EACZ,WAAW,SAAS,EACpB,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,IA0tBrE,CAAC"}