@retikz/core 0.3.0-alpha.3 → 0.3.0-alpha.5

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 (242) hide show
  1. package/README.md +41 -41
  2. package/dist/es/compile/anchor-cache.d.ts +5 -3
  3. package/dist/es/compile/anchor-cache.d.ts.map +1 -1
  4. package/dist/es/compile/anchor-cache.js +14 -10
  5. package/dist/es/compile/boundary.d.ts +19 -0
  6. package/dist/es/compile/boundary.d.ts.map +1 -0
  7. package/dist/es/compile/boundary.js +64 -0
  8. package/dist/es/compile/compile.d.ts +1 -1
  9. package/dist/es/compile/compile.d.ts.map +1 -1
  10. package/dist/es/compile/compile.js +49 -5
  11. package/dist/es/compile/node.d.ts +26 -8
  12. package/dist/es/compile/node.d.ts.map +1 -1
  13. package/dist/es/compile/node.js +103 -16
  14. package/dist/es/compile/path/anchor.d.ts.map +1 -1
  15. package/dist/es/compile/path/anchor.js +7 -6
  16. package/dist/es/compile/path/index.d.ts.map +1 -1
  17. package/dist/es/compile/path/index.js +7 -3
  18. package/dist/es/compile/path/relative.js +1 -1
  19. package/dist/es/compile/scope.d.ts.map +1 -1
  20. package/dist/es/compile/scope.js +2 -1
  21. package/dist/es/geometry/arc.d.ts +14 -0
  22. package/dist/es/geometry/arc.d.ts.map +1 -1
  23. package/dist/es/geometry/arc.js +65 -9
  24. package/dist/es/geometry/index.d.ts +1 -0
  25. package/dist/es/geometry/index.d.ts.map +1 -1
  26. package/dist/es/geometry/rect.d.ts +2 -2
  27. package/dist/es/geometry/rect.d.ts.map +1 -1
  28. package/dist/es/geometry/rect.js +3 -3
  29. package/dist/es/geometry/roundedContour.d.ts +88 -0
  30. package/dist/es/geometry/roundedContour.d.ts.map +1 -0
  31. package/dist/es/geometry/roundedContour.js +417 -0
  32. package/dist/es/index.d.ts +9 -5
  33. package/dist/es/index.d.ts.map +1 -1
  34. package/dist/es/index.js +11 -6
  35. package/dist/es/ir/animation.d.ts +218 -0
  36. package/dist/es/ir/animation.d.ts.map +1 -0
  37. package/dist/es/ir/animation.js +118 -0
  38. package/dist/es/ir/boundary.d.ts +25 -0
  39. package/dist/es/ir/boundary.d.ts.map +1 -0
  40. package/dist/es/ir/boundary.js +14 -0
  41. package/dist/es/ir/index.d.ts +3 -0
  42. package/dist/es/ir/index.d.ts.map +1 -1
  43. package/dist/es/ir/node.d.ts +219 -27
  44. package/dist/es/ir/node.d.ts.map +1 -1
  45. package/dist/es/ir/node.js +10 -3
  46. package/dist/es/ir/path/arrow.d.ts +36 -36
  47. package/dist/es/ir/path/path.d.ts +702 -203
  48. package/dist/es/ir/path/path.d.ts.map +1 -1
  49. package/dist/es/ir/path/path.js +4 -0
  50. package/dist/es/ir/path/step.d.ts +674 -154
  51. package/dist/es/ir/path/step.d.ts.map +1 -1
  52. package/dist/es/ir/path/step.js +2 -2
  53. package/dist/es/ir/path/target.d.ts +43 -8
  54. package/dist/es/ir/path/target.d.ts.map +1 -1
  55. package/dist/es/ir/path/target.js +4 -5
  56. package/dist/es/ir/scene.d.ts +156 -0
  57. package/dist/es/ir/scene.d.ts.map +1 -1
  58. package/dist/es/ir/scene.js +3 -1
  59. package/dist/es/ir/scope.d.ts +1671 -424
  60. package/dist/es/ir/scope.d.ts.map +1 -1
  61. package/dist/es/ir/scope.js +10 -2
  62. package/dist/es/ir/shape.d.ts +14 -0
  63. package/dist/es/ir/shape.d.ts.map +1 -0
  64. package/dist/es/ir/shape.js +9 -0
  65. package/dist/es/parsers/parseNodeTarget.d.ts.map +1 -1
  66. package/dist/es/parsers/parseNodeTarget.js +4 -2
  67. package/dist/es/presets/animation.d.ts +123 -0
  68. package/dist/es/presets/animation.d.ts.map +1 -0
  69. package/dist/es/presets/animation.js +272 -0
  70. package/dist/es/presets/index.d.ts +3 -0
  71. package/dist/es/presets/index.d.ts.map +1 -0
  72. package/dist/es/primitive/ellipse.d.ts +6 -0
  73. package/dist/es/primitive/ellipse.d.ts.map +1 -1
  74. package/dist/es/primitive/group.d.ts +6 -0
  75. package/dist/es/primitive/group.d.ts.map +1 -1
  76. package/dist/es/primitive/path.d.ts +6 -0
  77. package/dist/es/primitive/path.d.ts.map +1 -1
  78. package/dist/es/primitive/rect.d.ts +6 -0
  79. package/dist/es/primitive/rect.d.ts.map +1 -1
  80. package/dist/es/primitive/scene.d.ts +3 -0
  81. package/dist/es/primitive/scene.d.ts.map +1 -1
  82. package/dist/es/primitive/text.d.ts +6 -0
  83. package/dist/es/primitive/text.d.ts.map +1 -1
  84. package/dist/es/shapes/_contour.d.ts +19 -0
  85. package/dist/es/shapes/_contour.d.ts.map +1 -0
  86. package/dist/es/shapes/_contour.js +60 -0
  87. package/dist/es/shapes/_shared.d.ts +54 -0
  88. package/dist/es/shapes/_shared.d.ts.map +1 -1
  89. package/dist/es/shapes/_shared.js +68 -1
  90. package/dist/es/shapes/arc.d.ts +8 -0
  91. package/dist/es/shapes/arc.d.ts.map +1 -0
  92. package/dist/es/shapes/arc.js +104 -0
  93. package/dist/es/shapes/define.d.ts +13 -0
  94. package/dist/es/shapes/define.d.ts.map +1 -0
  95. package/dist/es/shapes/define.js +13 -0
  96. package/dist/es/shapes/ellipse.d.ts +5 -4
  97. package/dist/es/shapes/ellipse.d.ts.map +1 -1
  98. package/dist/es/shapes/ellipse.js +15 -7
  99. package/dist/es/shapes/index.d.ts +9 -6
  100. package/dist/es/shapes/index.d.ts.map +1 -1
  101. package/dist/es/shapes/index.js +10 -5
  102. package/dist/es/shapes/polygon.d.ts +13 -0
  103. package/dist/es/shapes/polygon.d.ts.map +1 -0
  104. package/dist/es/shapes/polygon.js +104 -0
  105. package/dist/es/shapes/rectangle.d.ts +7 -5
  106. package/dist/es/shapes/rectangle.d.ts.map +1 -1
  107. package/dist/es/shapes/rectangle.js +37 -8
  108. package/dist/es/shapes/sector.d.ts +9 -0
  109. package/dist/es/shapes/sector.d.ts.map +1 -0
  110. package/dist/es/shapes/sector.js +143 -0
  111. package/dist/es/shapes/star.d.ts +15 -0
  112. package/dist/es/shapes/star.d.ts.map +1 -0
  113. package/dist/es/shapes/star.js +113 -0
  114. package/dist/es/shapes/types.d.ts +47 -14
  115. package/dist/es/shapes/types.d.ts.map +1 -1
  116. package/dist/lib/compile/anchor-cache.cjs +14 -10
  117. package/dist/lib/compile/anchor-cache.d.ts +5 -3
  118. package/dist/lib/compile/anchor-cache.d.ts.map +1 -1
  119. package/dist/lib/compile/boundary.cjs +65 -0
  120. package/dist/lib/compile/boundary.d.ts +19 -0
  121. package/dist/lib/compile/boundary.d.ts.map +1 -0
  122. package/dist/lib/compile/compile.cjs +49 -5
  123. package/dist/lib/compile/compile.d.ts +1 -1
  124. package/dist/lib/compile/compile.d.ts.map +1 -1
  125. package/dist/lib/compile/node.cjs +103 -16
  126. package/dist/lib/compile/node.d.ts +26 -8
  127. package/dist/lib/compile/node.d.ts.map +1 -1
  128. package/dist/lib/compile/path/anchor.cjs +7 -6
  129. package/dist/lib/compile/path/anchor.d.ts.map +1 -1
  130. package/dist/lib/compile/path/index.cjs +7 -3
  131. package/dist/lib/compile/path/index.d.ts.map +1 -1
  132. package/dist/lib/compile/path/relative.cjs +1 -1
  133. package/dist/lib/compile/scope.cjs +2 -1
  134. package/dist/lib/compile/scope.d.ts.map +1 -1
  135. package/dist/lib/geometry/arc.cjs +66 -8
  136. package/dist/lib/geometry/arc.d.ts +14 -0
  137. package/dist/lib/geometry/arc.d.ts.map +1 -1
  138. package/dist/lib/geometry/index.d.ts +1 -0
  139. package/dist/lib/geometry/index.d.ts.map +1 -1
  140. package/dist/lib/geometry/rect.cjs +3 -3
  141. package/dist/lib/geometry/rect.d.ts +2 -2
  142. package/dist/lib/geometry/rect.d.ts.map +1 -1
  143. package/dist/lib/geometry/roundedContour.cjs +418 -0
  144. package/dist/lib/geometry/roundedContour.d.ts +88 -0
  145. package/dist/lib/geometry/roundedContour.d.ts.map +1 -0
  146. package/dist/lib/index.cjs +41 -7
  147. package/dist/lib/index.d.ts +9 -5
  148. package/dist/lib/index.d.ts.map +1 -1
  149. package/dist/lib/ir/animation.cjs +127 -0
  150. package/dist/lib/ir/animation.d.ts +218 -0
  151. package/dist/lib/ir/animation.d.ts.map +1 -0
  152. package/dist/lib/ir/boundary.cjs +15 -0
  153. package/dist/lib/ir/boundary.d.ts +25 -0
  154. package/dist/lib/ir/boundary.d.ts.map +1 -0
  155. package/dist/lib/ir/index.d.ts +3 -0
  156. package/dist/lib/ir/index.d.ts.map +1 -1
  157. package/dist/lib/ir/node.cjs +10 -3
  158. package/dist/lib/ir/node.d.ts +219 -27
  159. package/dist/lib/ir/node.d.ts.map +1 -1
  160. package/dist/lib/ir/path/arrow.d.ts +36 -36
  161. package/dist/lib/ir/path/path.cjs +4 -0
  162. package/dist/lib/ir/path/path.d.ts +702 -203
  163. package/dist/lib/ir/path/path.d.ts.map +1 -1
  164. package/dist/lib/ir/path/step.cjs +2 -2
  165. package/dist/lib/ir/path/step.d.ts +674 -154
  166. package/dist/lib/ir/path/step.d.ts.map +1 -1
  167. package/dist/lib/ir/path/target.cjs +4 -5
  168. package/dist/lib/ir/path/target.d.ts +43 -8
  169. package/dist/lib/ir/path/target.d.ts.map +1 -1
  170. package/dist/lib/ir/scene.cjs +3 -1
  171. package/dist/lib/ir/scene.d.ts +156 -0
  172. package/dist/lib/ir/scene.d.ts.map +1 -1
  173. package/dist/lib/ir/scope.cjs +10 -2
  174. package/dist/lib/ir/scope.d.ts +1671 -424
  175. package/dist/lib/ir/scope.d.ts.map +1 -1
  176. package/dist/lib/ir/shape.cjs +9 -0
  177. package/dist/lib/ir/shape.d.ts +14 -0
  178. package/dist/lib/ir/shape.d.ts.map +1 -0
  179. package/dist/lib/parsers/parseNodeTarget.cjs +4 -2
  180. package/dist/lib/parsers/parseNodeTarget.d.ts.map +1 -1
  181. package/dist/lib/presets/animation.cjs +286 -0
  182. package/dist/lib/presets/animation.d.ts +123 -0
  183. package/dist/lib/presets/animation.d.ts.map +1 -0
  184. package/dist/lib/presets/index.d.ts +3 -0
  185. package/dist/lib/presets/index.d.ts.map +1 -0
  186. package/dist/lib/primitive/ellipse.d.ts +6 -0
  187. package/dist/lib/primitive/ellipse.d.ts.map +1 -1
  188. package/dist/lib/primitive/group.d.ts +6 -0
  189. package/dist/lib/primitive/group.d.ts.map +1 -1
  190. package/dist/lib/primitive/path.d.ts +6 -0
  191. package/dist/lib/primitive/path.d.ts.map +1 -1
  192. package/dist/lib/primitive/rect.d.ts +6 -0
  193. package/dist/lib/primitive/rect.d.ts.map +1 -1
  194. package/dist/lib/primitive/scene.d.ts +3 -0
  195. package/dist/lib/primitive/scene.d.ts.map +1 -1
  196. package/dist/lib/primitive/text.d.ts +6 -0
  197. package/dist/lib/primitive/text.d.ts.map +1 -1
  198. package/dist/lib/shapes/_contour.cjs +61 -0
  199. package/dist/lib/shapes/_contour.d.ts +19 -0
  200. package/dist/lib/shapes/_contour.d.ts.map +1 -0
  201. package/dist/lib/shapes/_shared.cjs +70 -0
  202. package/dist/lib/shapes/_shared.d.ts +54 -0
  203. package/dist/lib/shapes/_shared.d.ts.map +1 -1
  204. package/dist/lib/shapes/arc.cjs +104 -0
  205. package/dist/lib/shapes/arc.d.ts +8 -0
  206. package/dist/lib/shapes/arc.d.ts.map +1 -0
  207. package/dist/lib/shapes/define.cjs +13 -0
  208. package/dist/lib/shapes/define.d.ts +13 -0
  209. package/dist/lib/shapes/define.d.ts.map +1 -0
  210. package/dist/lib/shapes/ellipse.cjs +15 -7
  211. package/dist/lib/shapes/ellipse.d.ts +5 -4
  212. package/dist/lib/shapes/ellipse.d.ts.map +1 -1
  213. package/dist/lib/shapes/index.cjs +12 -6
  214. package/dist/lib/shapes/index.d.ts +9 -6
  215. package/dist/lib/shapes/index.d.ts.map +1 -1
  216. package/dist/lib/shapes/polygon.cjs +104 -0
  217. package/dist/lib/shapes/polygon.d.ts +13 -0
  218. package/dist/lib/shapes/polygon.d.ts.map +1 -0
  219. package/dist/lib/shapes/rectangle.cjs +37 -8
  220. package/dist/lib/shapes/rectangle.d.ts +7 -5
  221. package/dist/lib/shapes/rectangle.d.ts.map +1 -1
  222. package/dist/lib/shapes/sector.cjs +143 -0
  223. package/dist/lib/shapes/sector.d.ts +9 -0
  224. package/dist/lib/shapes/sector.d.ts.map +1 -0
  225. package/dist/lib/shapes/star.cjs +113 -0
  226. package/dist/lib/shapes/star.d.ts +15 -0
  227. package/dist/lib/shapes/star.d.ts.map +1 -0
  228. package/dist/lib/shapes/types.d.ts +47 -14
  229. package/dist/lib/shapes/types.d.ts.map +1 -1
  230. package/package.json +2 -2
  231. package/dist/es/shapes/circle.d.ts +0 -8
  232. package/dist/es/shapes/circle.d.ts.map +0 -1
  233. package/dist/es/shapes/circle.js +0 -34
  234. package/dist/es/shapes/diamond.d.ts +0 -8
  235. package/dist/es/shapes/diamond.d.ts.map +0 -1
  236. package/dist/es/shapes/diamond.js +0 -66
  237. package/dist/lib/shapes/circle.cjs +0 -34
  238. package/dist/lib/shapes/circle.d.ts +0 -8
  239. package/dist/lib/shapes/circle.d.ts.map +0 -1
  240. package/dist/lib/shapes/diamond.cjs +0 -66
  241. package/dist/lib/shapes/diamond.d.ts +0 -8
  242. package/dist/lib/shapes/diamond.d.ts.map +0 -1
@@ -0,0 +1,104 @@
1
+ const require__transform = require("../geometry/_transform.cjs");
2
+ const require_rect = require("../geometry/rect.cjs");
3
+ const require_define = require("./define.cjs");
4
+ const require__shared = require("./_shared.cjs");
5
+ const require_roundedContour = require("../geometry/roundedContour.cjs");
6
+ const require__contour = require("./_contour.cjs");
7
+ let zod = require("zod");
8
+ //#region src/shapes/polygon.ts
9
+ var DEG_TO_RAD = Math.PI / 180;
10
+ /** 顶点角集合(度):第 k 个顶点角 = rotate + k·(360/sides) */
11
+ var vertexAngles = (params) => {
12
+ const startDeg = params.rotate ?? 0;
13
+ const stepDeg = 360 / params.sides;
14
+ const out = [];
15
+ for (let k = 0; k < params.sides; k++) out.push(startDeg + k * stepDeg);
16
+ return out;
17
+ };
18
+ /** 顶点角的 |cos| 最大值(恒 >0,sides≥3 时至少一个顶点不在 ±y 轴上);用于由 AABB 半宽反推外接半径 */
19
+ var maxAbsCos = (params) => Math.max(...vertexAngles(params).map((a) => Math.abs(Math.cos(a * DEG_TO_RAD))));
20
+ /**
21
+ * 能容纳内框(半轴 hw/hh)的正 sides 边形外接圆半径
22
+ * @description rectangle / polygon 是文本容器——尺寸由内框(text + padding)驱动,circumscribe 从内框推外接。
23
+ * 正多边形 = 各边内法向投影 ≤ 内切半径(apothem) 的半平面交;apothem = R·cos(π/sides)。内框 4 角
24
+ * (±hw,±hh) 全在多边形内 ⇔ 对每条边法向 φ_j,max 角投影 hw·|cosφ_j|+hh·|sinφ_j| ≤ apothem。
25
+ * 取使等号成立的最小 R = max_j(hw·|cosφ_j|+hh·|sinφ_j|) / cos(π/sides),φ_j = rotate+(j+0.5)·(360/sides)。
26
+ */
27
+ var circumradiusFor = (hw, hh, params) => {
28
+ const { sides } = params;
29
+ const startDeg = params.rotate ?? 0;
30
+ const stepDeg = 360 / sides;
31
+ const apothemFactor = Math.cos(Math.PI / sides);
32
+ let maxSupport = 0;
33
+ for (let j = 0; j < sides; j++) {
34
+ const phi = (startDeg + (j + .5) * stepDeg) * DEG_TO_RAD;
35
+ const support = hw * Math.abs(Math.cos(phi)) + hh * Math.abs(Math.sin(phi));
36
+ if (support > maxSupport) maxSupport = support;
37
+ }
38
+ return maxSupport / apothemFactor;
39
+ };
40
+ /** 由外接 AABB(emit / boundaryPoint 收到的 rect)反推外接圆半径:R = halfWidth / max|cosθ_k| */
41
+ var circumradiusFromRect = (rect, params) => rect.width / 2 / maxAbsCos(params);
42
+ /**
43
+ * 正多边形 `sides` 个顶点的世界坐标(外接圆半径 radius、起始角 rotate、绕 rect 中心)
44
+ * @description 顶点均布外接圆:第 k 个顶点角 = rotate + k·(360/sides);点在 rect 局部系算后经 localToWorld 投世界。
45
+ * emit / boundaryPoint / anchor 共用此真源。
46
+ */
47
+ var polygonVertices = (rect, radius, params) => vertexAngles(params).map((deg) => {
48
+ const a = deg * DEG_TO_RAD;
49
+ return require__transform.localToWorld(rect, [radius * Math.cos(a), radius * Math.sin(a)]);
50
+ });
51
+ /**
52
+ * polygon 注册项:正多边形(sides 顶点均布外接圆,rotate 定起始角,cornerRadius 顶点倒角)
53
+ * @description 文本容器形状——circumscribe 从内框 `innerHalfWidth/Height` 推能容纳内框的外接圆、再取其 AABB 半轴,
54
+ * 尺寸仍由内框 + minimumSize 驱动(区别于 sector / star 的 params-半径驱动)。emit / boundaryPoint 把顶点环构造成
55
+ * `sides` 条折线段,委托 rounded-contour 模块:cornerRadius 省略 / 0 出原尖角轮廓、>0 在每个顶点插逐角夹紧的
56
+ * fillet 弧。emit 收轴对齐 rect(旋转由外层 group 施加)、boundaryPoint 收带 rotate 的 rect 且 rayOrigin = 几何中心
57
+ * (多边形关于中心对称,AABB 中心 = 形心 = node position)。命名 anchor 走外接 AABB 的 9 名 rect anchor(不随
58
+ * cornerRadius 移);self-rotate(params.rotate)与 Node.rotate 叠加。scaleParams:cornerRadius 是长度随 scale
59
+ * 缩(几何均值因子),sides 计数 / rotate 角度不缩。
60
+ * diamond ≡ `{ type: 'polygon', params: { sides: 4, rotate: 45 } }`,由 compile 规范化。
61
+ */
62
+ var polygon = require_define.defineShape({
63
+ paramsSchema: zod.z.strictObject({
64
+ sides: zod.z.number().int().min(3).describe("Number of sides of the regular polygon (>= 3)."),
65
+ rotate: zod.z.number().finite().optional().describe("Shape self-rotation in degrees (vertex start direction); default 0. Composes with Node.rotate."),
66
+ cornerRadius: zod.z.number().finite().nonnegative().optional().describe("Corner radius in user units; 0 / omitted = sharp corners. Clamped per corner to the largest non-self-intersecting fillet.")
67
+ }),
68
+ circumscribe: (hw, hh, params) => {
69
+ const radius = circumradiusFor(hw, hh, params);
70
+ const angles = vertexAngles(params);
71
+ return {
72
+ halfWidth: Math.max(...angles.map((a) => Math.abs(radius * Math.cos(a * DEG_TO_RAD)))),
73
+ halfHeight: Math.max(...angles.map((a) => Math.abs(radius * Math.sin(a * DEG_TO_RAD))))
74
+ };
75
+ },
76
+ boundaryPoint: (rect, toward, params) => {
77
+ const segments = require__contour.verticesToSegments(polygonVertices(rect, circumradiusFromRect(rect, params), params));
78
+ const center = [rect.x, rect.y];
79
+ return require_roundedContour.boundaryFromContour(segments, params.cornerRadius, center, toward) ?? center;
80
+ },
81
+ anchor: (rect$1, name, params) => {
82
+ const a = require__shared.asRectAnchor(name);
83
+ return a ? require_rect.rect.anchor(rect$1, a) : void 0;
84
+ },
85
+ *emit(rect, style, round, params) {
86
+ yield {
87
+ type: "path",
88
+ commands: require__contour.contourToPathCommands(require_roundedContour.contourCommands(require__contour.verticesToSegments(polygonVertices(rect, circumradiusFromRect(rect, params), params)), params.cornerRadius), round),
89
+ fill: style.fill ?? "transparent",
90
+ fillOpacity: style.fillOpacity,
91
+ stroke: style.stroke ?? "currentColor",
92
+ strokeOpacity: style.strokeOpacity,
93
+ strokeWidth: style.strokeWidth ?? 1,
94
+ dashPattern: style.dashPattern,
95
+ opacity: style.opacity
96
+ };
97
+ },
98
+ scaleParams: (params, sx, sy) => params.cornerRadius === void 0 ? params : {
99
+ ...params,
100
+ cornerRadius: params.cornerRadius * Math.sqrt(sx * sy)
101
+ }
102
+ });
103
+ //#endregion
104
+ exports.polygon = polygon;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * polygon 注册项:正多边形(sides 顶点均布外接圆,rotate 定起始角,cornerRadius 顶点倒角)
3
+ * @description 文本容器形状——circumscribe 从内框 `innerHalfWidth/Height` 推能容纳内框的外接圆、再取其 AABB 半轴,
4
+ * 尺寸仍由内框 + minimumSize 驱动(区别于 sector / star 的 params-半径驱动)。emit / boundaryPoint 把顶点环构造成
5
+ * `sides` 条折线段,委托 rounded-contour 模块:cornerRadius 省略 / 0 出原尖角轮廓、>0 在每个顶点插逐角夹紧的
6
+ * fillet 弧。emit 收轴对齐 rect(旋转由外层 group 施加)、boundaryPoint 收带 rotate 的 rect 且 rayOrigin = 几何中心
7
+ * (多边形关于中心对称,AABB 中心 = 形心 = node position)。命名 anchor 走外接 AABB 的 9 名 rect anchor(不随
8
+ * cornerRadius 移);self-rotate(params.rotate)与 Node.rotate 叠加。scaleParams:cornerRadius 是长度随 scale
9
+ * 缩(几何均值因子),sides 计数 / rotate 角度不缩。
10
+ * diamond ≡ `{ type: 'polygon', params: { sides: 4, rotate: 45 } }`,由 compile 规范化。
11
+ */
12
+ export declare const polygon: import('./types').ShapeDefinition;
13
+ //# sourceMappingURL=polygon.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polygon.d.ts","sourceRoot":"","sources":["../../../src/shapes/polygon.ts"],"names":[],"mappings":"AA8EA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,OAAO,mCAiElB,CAAC"}
@@ -1,25 +1,50 @@
1
+ const require__transform = require("../geometry/_transform.cjs");
1
2
  const require_rect = require("../geometry/rect.cjs");
3
+ const require_define = require("./define.cjs");
2
4
  const require__shared = require("./_shared.cjs");
5
+ const require_roundedContour = require("../geometry/roundedContour.cjs");
6
+ const require__contour = require("./_contour.cjs");
7
+ let zod = require("zod");
3
8
  //#region src/shapes/rectangle.ts
9
+ /** 轴对齐 / 旋转矩形的 4 个角(CW 绕向:左上 → 右上 → 右下 → 左下),局部系经 localToWorld 投世界 */
10
+ var rectVertices = (rect) => {
11
+ const halfW = rect.width / 2;
12
+ const halfH = rect.height / 2;
13
+ return [
14
+ require__transform.localToWorld(rect, [-halfW, -halfH]),
15
+ require__transform.localToWorld(rect, [halfW, -halfH]),
16
+ require__transform.localToWorld(rect, [halfW, halfH]),
17
+ require__transform.localToWorld(rect, [-halfW, halfH])
18
+ ];
19
+ };
4
20
  /**
5
- * rectangle 注册项
6
- * @description circumscribe = identity(视觉边界 = 内框);boundaryPoint / anchor 直接走 rect 数学层;
7
- * emit RectPrim(圆角走 cornerRadius),与旧 `emitRectShape` 逐字段等价
21
+ * rectangle 注册项(文本容器形状,尺寸由内框 + minimumSize 驱动)
22
+ * @description circumscribe = identity(视觉边界 = 内框);anchor / edgePoint 直接走 rect 数学层;
23
+ * boundaryPoint 把矩形 4 角构造成 4 条折线段、委托 rounded-contour 模块(cornerRadius 省略 / 0 出原尖角
24
+ * 求交、>0 在每个角插逐角夹紧的 fillet 弧,连接感知倒角),rayOrigin = 矩形中心(= node position)。
25
+ * emit 仍出 RectPrim,圆角半径优先取 `params.cornerRadius`、回退到 `style.cornerRadius`(顶层迁移期兼容)。
26
+ * scaleParams:cornerRadius 是长度,随 node scale 用 uniform 几何均值因子协同缩放(边数 / 角度类参数才不缩)。
8
27
  */
9
- var rectangle = {
28
+ var rectangle = require_define.defineShape({
29
+ paramsSchema: zod.z.strictObject({ cornerRadius: zod.z.number().finite().nonnegative().optional().describe("Corner radius in user units; 0 / omitted = sharp corners. Clamped per corner to the largest non-self-intersecting fillet.") }),
10
30
  circumscribe: (hw, hh) => ({
11
31
  halfWidth: hw,
12
32
  halfHeight: hh
13
33
  }),
14
- boundaryPoint: (r, toward) => require_rect.rect.boundaryPoint(r, toward),
34
+ boundaryPoint: (rect, toward, params) => {
35
+ const segments = require__contour.verticesToSegments(rectVertices(rect));
36
+ const center = [rect.x, rect.y];
37
+ return require_roundedContour.boundaryFromContour(segments, params.cornerRadius, center, toward) ?? center;
38
+ },
15
39
  anchor: (r, name) => {
16
40
  const a = require__shared.asRectAnchor(name);
17
41
  return a ? require_rect.rect.anchor(r, a) : void 0;
18
42
  },
19
43
  edgePoint: (r, side, t) => require_rect.rect.edgePoint(r, side, t),
20
- *emit(r, style, round) {
44
+ *emit(r, style, round, params) {
21
45
  const halfW = r.width / 2;
22
46
  const halfH = r.height / 2;
47
+ const cornerRadius = params.cornerRadius ?? style.cornerRadius;
23
48
  yield {
24
49
  type: "rect",
25
50
  x: round(r.x - halfW),
@@ -32,10 +57,14 @@ var rectangle = {
32
57
  strokeOpacity: style.strokeOpacity,
33
58
  strokeWidth: style.strokeWidth ?? 1,
34
59
  dashPattern: style.dashPattern,
35
- cornerRadius: style.roundedCorners,
60
+ cornerRadius: cornerRadius !== void 0 ? round(cornerRadius) : void 0,
36
61
  opacity: style.opacity
37
62
  };
63
+ },
64
+ scaleParams: (params, sx, sy) => params.cornerRadius === void 0 ? params : {
65
+ ...params,
66
+ cornerRadius: params.cornerRadius * Math.sqrt(sx * sy)
38
67
  }
39
- };
68
+ });
40
69
  //#endregion
41
70
  exports.rectangle = rectangle;
@@ -1,8 +1,10 @@
1
- import { ShapeDefinition } from './types';
2
1
  /**
3
- * rectangle 注册项
4
- * @description circumscribe = identity(视觉边界 = 内框);boundaryPoint / anchor 直接走 rect 数学层;
5
- * emit RectPrim(圆角走 cornerRadius),与旧 `emitRectShape` 逐字段等价
2
+ * rectangle 注册项(文本容器形状,尺寸由内框 + minimumSize 驱动)
3
+ * @description circumscribe = identity(视觉边界 = 内框);anchor / edgePoint 直接走 rect 数学层;
4
+ * boundaryPoint 把矩形 4 角构造成 4 条折线段、委托 rounded-contour 模块(cornerRadius 省略 / 0 出原尖角
5
+ * 求交、>0 在每个角插逐角夹紧的 fillet 弧,连接感知倒角),rayOrigin = 矩形中心(= node position)。
6
+ * emit 仍出 RectPrim,圆角半径优先取 `params.cornerRadius`、回退到 `style.cornerRadius`(顶层迁移期兼容)。
7
+ * scaleParams:cornerRadius 是长度,随 node scale 用 uniform 几何均值因子协同缩放(边数 / 角度类参数才不缩)。
6
8
  */
7
- export declare const rectangle: ShapeDefinition;
9
+ export declare const rectangle: import('./types').ShapeDefinition;
8
10
  //# sourceMappingURL=rectangle.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rectangle.d.ts","sourceRoot":"","sources":["../../../src/shapes/rectangle.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C;;;;GAIG;AACH,eAAO,MAAM,SAAS,EAAE,eA2BvB,CAAC"}
1
+ {"version":3,"file":"rectangle.d.ts","sourceRoot":"","sources":["../../../src/shapes/rectangle.ts"],"names":[],"mappings":"AAgCA;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,mCAiDpB,CAAC"}
@@ -0,0 +1,143 @@
1
+ const require__transform = require("../geometry/_transform.cjs");
2
+ const require_define = require("./define.cjs");
3
+ const require__shared = require("./_shared.cjs");
4
+ const require_roundedContour = require("../geometry/roundedContour.cjs");
5
+ const require__contour = require("./_contour.cjs");
6
+ let zod = require("zod");
7
+ //#region src/shapes/sector.ts
8
+ /** sector 局部 AABB 系点(圆心为原点偏移后)→ 世界系(含 rect 旋转 / 平移) */
9
+ var toWorld = (rect, geo, localFromApex) => {
10
+ return require__transform.localToWorld(rect, [localFromApex[0] + geo.apexOffset[0], localFromApex[1] + geo.apexOffset[1]]);
11
+ };
12
+ /**
13
+ * 构造 sector 闭合轮廓的有序段序列(line + arc),段序与现状 emit 完全一致
14
+ * @description 环楔(innerRadius>0)4 段闭环:radial Line(inner-start→outer-start) → outer Arc(start→end, CW)
15
+ * → radial Line(outer-end→inner-end) → inner Arc(end→start, CCW)。pie(innerRadius=0)3 段闭环:
16
+ * radial Line(apex→outer-start) → outer Arc(start→end, CW) → radial Line(outer-end→apex),apex 处为 line-line 接缝。
17
+ * Arc 圆心 = apex 世界坐标、半径 = inner/outer radius、起止角与现状 emit 同(度,CW 即 counterClockwise=false)。
18
+ * emit / boundaryPoint 共用此真源;emit 收轴对齐 rect、boundaryPoint 收带 rotate 的 rect,rect 不同自然投不同世界系。
19
+ */
20
+ var sectorSegments = (rect, geo, params) => {
21
+ const { innerRadius, outerRadius } = params;
22
+ const { start, end } = geo.range;
23
+ const apex = toWorld(rect, geo, [0, 0]);
24
+ const rotateDeg = (rect.rotate ?? 0) * 180 / Math.PI;
25
+ const sa = start + rotateDeg;
26
+ const ea = end + rotateDeg;
27
+ const outerStart = toWorld(rect, geo, require__shared.sectorPolarPoint(outerRadius, start));
28
+ if (innerRadius > 0) {
29
+ const innerStart = toWorld(rect, geo, require__shared.sectorPolarPoint(innerRadius, start));
30
+ const innerEnd = toWorld(rect, geo, require__shared.sectorPolarPoint(innerRadius, end));
31
+ return [
32
+ {
33
+ kind: "line",
34
+ from: innerStart,
35
+ to: outerStart
36
+ },
37
+ {
38
+ kind: "arc",
39
+ center: apex,
40
+ radius: outerRadius,
41
+ startAngle: sa,
42
+ endAngle: ea
43
+ },
44
+ {
45
+ kind: "line",
46
+ from: toWorld(rect, geo, require__shared.sectorPolarPoint(outerRadius, end)),
47
+ to: innerEnd
48
+ },
49
+ {
50
+ kind: "arc",
51
+ center: apex,
52
+ radius: innerRadius,
53
+ startAngle: ea,
54
+ endAngle: sa,
55
+ counterClockwise: true
56
+ }
57
+ ];
58
+ }
59
+ return [
60
+ {
61
+ kind: "line",
62
+ from: apex,
63
+ to: outerStart
64
+ },
65
+ {
66
+ kind: "arc",
67
+ center: apex,
68
+ radius: outerRadius,
69
+ startAngle: sa,
70
+ endAngle: ea
71
+ },
72
+ {
73
+ kind: "line",
74
+ from: toWorld(rect, geo, require__shared.sectorPolarPoint(outerRadius, end)),
75
+ to: apex
76
+ }
77
+ ];
78
+ };
79
+ /**
80
+ * sector 注册项:环楔(内外半径 + 起止角围成的可填充 2D 区域)
81
+ * @description 四何函数共用 `sectorGeometry`(单一真源):circumscribe 返回含圆心 + 内外弧的精确 AABB 半轴
82
+ * (含弧跨过 90°·k 轴向的 outerRadius 极值点),node position = AABB 中心;anchor 含 apex(圆心)/ centroid /
83
+ * inner-arc-mid / outer-arc-mid / start-edge-mid / end-edge-mid + 角度边界点;emit 出外弧 + 两径向边 + 内弧
84
+ * 闭合 path(innerRadius=0 时径向边交于圆心、无内弧)。scaleParams 只缩半径、不缩角度。
85
+ */
86
+ var sector = require_define.defineShape({
87
+ paramsSchema: zod.z.strictObject({
88
+ innerRadius: zod.z.number().finite().nonnegative().describe("Inner radius (user units); 0 = solid pie slice."),
89
+ outerRadius: zod.z.number().finite().positive().describe("Outer radius (user units); must be > innerRadius."),
90
+ startAngle: zod.z.number().finite().describe("Start angle in degrees; polar convention 0°=+x, 90°=+y (screen y-down), matching core polar."),
91
+ endAngle: zod.z.number().finite().describe("End angle in degrees; swept counterclockwise in screen space from startAngle."),
92
+ cornerRadius: zod.z.number().finite().nonnegative().optional().describe("Corner radius in user units; 0 / omitted = sharp corners. Clamped per corner to the largest non-self-intersecting fillet.")
93
+ }).refine((p) => p.outerRadius > p.innerRadius, { message: "outerRadius must be greater than innerRadius" }),
94
+ circumscribe: (_hw, _hh, params) => require__shared.sectorGeometry(params).aabbHalfAxes,
95
+ circumscribeOffset: (params) => {
96
+ const { apexOffset } = require__shared.sectorGeometry(params);
97
+ return [-apexOffset[0], -apexOffset[1]];
98
+ },
99
+ boundaryPoint: (rect, toward, params) => {
100
+ const geo = require__shared.sectorGeometry(params);
101
+ const centroidWorld = require__transform.localToWorld(rect, geo.centroidOffset);
102
+ return require_roundedContour.boundaryFromContour(sectorSegments(rect, geo, params), params.cornerRadius, centroidWorld, toward) ?? centroidWorld;
103
+ },
104
+ anchor: (rect, name, params) => {
105
+ const geo = require__shared.sectorGeometry(params);
106
+ const { innerRadius, outerRadius } = params;
107
+ const { start, end, mid } = geo.range;
108
+ switch (name) {
109
+ case "apex":
110
+ case "center": return toWorld(rect, geo, [0, 0]);
111
+ case "centroid": return require__transform.localToWorld(rect, geo.centroidOffset);
112
+ case "outer-arc-mid": return toWorld(rect, geo, require__shared.sectorPolarPoint(outerRadius, mid));
113
+ case "inner-arc-mid": return toWorld(rect, geo, require__shared.sectorPolarPoint(innerRadius, mid));
114
+ case "start-edge-mid": return toWorld(rect, geo, require__shared.sectorPolarPoint((innerRadius + outerRadius) / 2, start));
115
+ case "end-edge-mid": return toWorld(rect, geo, require__shared.sectorPolarPoint((innerRadius + outerRadius) / 2, end));
116
+ default: return;
117
+ }
118
+ },
119
+ *emit(rect, style, round, params) {
120
+ yield {
121
+ type: "path",
122
+ commands: require__contour.contourToPathCommands(require_roundedContour.contourCommands(sectorSegments(rect, require__shared.sectorGeometry(params), params), params.cornerRadius), round),
123
+ fill: style.fill ?? "transparent",
124
+ fillOpacity: style.fillOpacity,
125
+ stroke: style.stroke ?? "currentColor",
126
+ strokeOpacity: style.strokeOpacity,
127
+ strokeWidth: style.strokeWidth ?? 1,
128
+ dashPattern: style.dashPattern,
129
+ opacity: style.opacity
130
+ };
131
+ },
132
+ scaleParams: (params, sx, sy) => {
133
+ const factor = Math.sqrt(sx * sy);
134
+ return {
135
+ ...params,
136
+ innerRadius: params.innerRadius * factor,
137
+ outerRadius: params.outerRadius * factor,
138
+ ...params.cornerRadius === void 0 ? {} : { cornerRadius: params.cornerRadius * factor }
139
+ };
140
+ }
141
+ });
142
+ //#endregion
143
+ exports.sector = sector;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * sector 注册项:环楔(内外半径 + 起止角围成的可填充 2D 区域)
3
+ * @description 四何函数共用 `sectorGeometry`(单一真源):circumscribe 返回含圆心 + 内外弧的精确 AABB 半轴
4
+ * (含弧跨过 90°·k 轴向的 outerRadius 极值点),node position = AABB 中心;anchor 含 apex(圆心)/ centroid /
5
+ * inner-arc-mid / outer-arc-mid / start-edge-mid / end-edge-mid + 角度边界点;emit 出外弧 + 两径向边 + 内弧
6
+ * 闭合 path(innerRadius=0 时径向边交于圆心、无内弧)。scaleParams 只缩半径、不缩角度。
7
+ */
8
+ export declare const sector: import('./types').ShapeDefinition;
9
+ //# sourceMappingURL=sector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sector.d.ts","sourceRoot":"","sources":["../../../src/shapes/sector.ts"],"names":[],"mappings":"AA0EA;;;;;;GAMG;AACH,eAAO,MAAM,MAAM,mCAgGjB,CAAC"}
@@ -0,0 +1,113 @@
1
+ const require__transform = require("../geometry/_transform.cjs");
2
+ const require_define = require("./define.cjs");
3
+ const require_roundedContour = require("../geometry/roundedContour.cjs");
4
+ const require__contour = require("./_contour.cjs");
5
+ let zod = require("zod");
6
+ //#region src/shapes/star.ts
7
+ var DEG_TO_RAD = Math.PI / 180;
8
+ /**
9
+ * 计算 star 单一真源几何
10
+ * @description 局部系以中心为原点:顶点 k 角 = (rotate ?? 0) + k·(180/points) − 90,半径偶 outer / 奇 inner,
11
+ * point = [r·cosθ, r·sinθ](0°=+x,90°=+y screen y-down)。−90 基准使默认第一尖角朝上(−y)。
12
+ * AABB 半轴 = 各顶点 |x| / |y| 的最大值(对称 → 中心即原点)。
13
+ */
14
+ var starGeometry = (params) => {
15
+ const { points, innerRadius, outerRadius } = params;
16
+ const rotate = params.rotate ?? 0;
17
+ const step = 180 / points;
18
+ const vertices = [];
19
+ let maxAbsX = 0;
20
+ let maxAbsY = 0;
21
+ for (let k = 0; k < 2 * points; k++) {
22
+ const angle = (rotate + k * step - 90) * DEG_TO_RAD;
23
+ const radius = k % 2 === 0 ? outerRadius : innerRadius;
24
+ const x = radius * Math.cos(angle);
25
+ const y = radius * Math.sin(angle);
26
+ vertices.push([x, y]);
27
+ if (Math.abs(x) > maxAbsX) maxAbsX = Math.abs(x);
28
+ if (Math.abs(y) > maxAbsY) maxAbsY = Math.abs(y);
29
+ }
30
+ return {
31
+ vertices,
32
+ aabbHalfAxes: {
33
+ halfWidth: maxAbsX,
34
+ halfHeight: maxAbsY
35
+ }
36
+ };
37
+ };
38
+ /** 局部顶点(中心为原点)→ 世界系(经 rect 旋转 / 平移) */
39
+ var toWorld = (rect, local) => require__transform.localToWorld(rect, local);
40
+ /**
41
+ * 世界系顶点环(局部 2×points 顶点逐个经 rect 投世界)
42
+ * @description emit 收轴对齐 rect(rotate=0)、boundaryPoint 收带 rotate 的 rect,二者共用此构造;
43
+ * 绕向 = starGeometry 顶点顺序(偶尖 / 奇凹交替),供 verticesToSegments → rounded-contour 模块倒角。
44
+ */
45
+ var worldVertices = (rect, geo) => geo.vertices.map((v) => toWorld(rect, v));
46
+ /**
47
+ * star 注册项:星形(外径尖角 / 内径凹角交替的 2×points 顶点闭合多边形)
48
+ * @description params-半径驱动的纯几何形状(像 sector,尺寸由 outerRadius 定、忽略文本内框):四何函数共用
49
+ * `starGeometry`(单一真源)。circumscribe 返回含全部尖角的精确 AABB 半轴(随 rotate 变,不随 cornerRadius 变);
50
+ * 星形关于中心对称 → AABB 中心 = 星形中心 = node position,无需 circumscribeOffset。emit / boundaryPoint 把
51
+ * `2×points` 顶点环构造成折线段,委托 rounded-contour 模块:cornerRadius 省略 / 0 出原尖角轮廓、>0 在每个顶点
52
+ * 插逐角夹紧的 fillet 弧——凸尖与凹角(notch)由模块按接缝转向叉积统一处理(凹角弧 sweep 反向、圆心在凸侧),
53
+ * emit 与 boundaryPoint 共用同一份 fillet 结果。emit 收轴对齐 rect(旋转由外层 group 施加)、boundaryPoint
54
+ * 收带 rotate 的 rect 且 rayOrigin = 星形几何中心(关于中心对称,AABB 中心 = 形心 = node position)。
55
+ * anchor 含 center / tip-N(第 N 尖角)/ notch-N(第 N 凹角)——恒在原尖角 / 凹角逻辑顶点,不随 cornerRadius 移;
56
+ * self-rotate(params.rotate)与 Node.rotate 叠加。scaleParams 只缩 inner/outerRadius / cornerRadius(长度)、
57
+ * 不缩 points(计数)/ rotate(角度)。
58
+ */
59
+ var star = require_define.defineShape({
60
+ paramsSchema: zod.z.strictObject({
61
+ points: zod.z.number().int().min(3).describe("Number of star points (>= 3)."),
62
+ innerRadius: zod.z.number().finite().positive().describe("Inner (notch) radius in user units."),
63
+ outerRadius: zod.z.number().finite().positive().describe("Outer (tip) radius in user units; must be > innerRadius."),
64
+ rotate: zod.z.number().finite().optional().describe("Shape self-rotation in degrees; default 0 = first tip points up (screen -y / top); positive rotates clockwise (screen). Composes with Node.rotate."),
65
+ cornerRadius: zod.z.number().finite().nonnegative().optional().describe("Corner radius in user units; 0 / omitted = sharp corners. Clamped per corner to the largest non-self-intersecting fillet.")
66
+ }).refine((p) => p.outerRadius > p.innerRadius, { message: "outerRadius must be greater than innerRadius" }),
67
+ circumscribe: (_hw, _hh, params) => starGeometry(params).aabbHalfAxes,
68
+ boundaryPoint: (rect, toward, params) => {
69
+ const segments = require__contour.verticesToSegments(worldVertices(rect, starGeometry(params)));
70
+ const center = toWorld(rect, [0, 0]);
71
+ return require_roundedContour.boundaryFromContour(segments, params.cornerRadius, center, toward) ?? center;
72
+ },
73
+ anchor: (rect, name, params) => {
74
+ const geo = starGeometry(params);
75
+ if (name === "center") return toWorld(rect, [0, 0]);
76
+ const tip = /^tip-(\d+)$/.exec(name);
77
+ if (tip) {
78
+ const index = 2 * Number(tip[1]);
79
+ if (index >= geo.vertices.length) return void 0;
80
+ return toWorld(rect, geo.vertices[index]);
81
+ }
82
+ const notch = /^notch-(\d+)$/.exec(name);
83
+ if (notch) {
84
+ const index = 2 * Number(notch[1]) + 1;
85
+ if (index >= geo.vertices.length) return void 0;
86
+ return toWorld(rect, geo.vertices[index]);
87
+ }
88
+ },
89
+ *emit(rect, style, round, params) {
90
+ yield {
91
+ type: "path",
92
+ commands: require__contour.contourToPathCommands(require_roundedContour.contourCommands(require__contour.verticesToSegments(worldVertices(rect, starGeometry(params))), params.cornerRadius), round),
93
+ fill: style.fill ?? "transparent",
94
+ fillOpacity: style.fillOpacity,
95
+ stroke: style.stroke ?? "currentColor",
96
+ strokeOpacity: style.strokeOpacity,
97
+ strokeWidth: style.strokeWidth ?? 1,
98
+ dashPattern: style.dashPattern,
99
+ opacity: style.opacity
100
+ };
101
+ },
102
+ scaleParams: (params, sx, sy) => {
103
+ const factor = Math.sqrt(sx * sy);
104
+ return {
105
+ ...params,
106
+ innerRadius: params.innerRadius * factor,
107
+ outerRadius: params.outerRadius * factor,
108
+ ...params.cornerRadius === void 0 ? {} : { cornerRadius: params.cornerRadius * factor }
109
+ };
110
+ }
111
+ });
112
+ //#endregion
113
+ exports.star = star;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * star 注册项:星形(外径尖角 / 内径凹角交替的 2×points 顶点闭合多边形)
3
+ * @description params-半径驱动的纯几何形状(像 sector,尺寸由 outerRadius 定、忽略文本内框):四何函数共用
4
+ * `starGeometry`(单一真源)。circumscribe 返回含全部尖角的精确 AABB 半轴(随 rotate 变,不随 cornerRadius 变);
5
+ * 星形关于中心对称 → AABB 中心 = 星形中心 = node position,无需 circumscribeOffset。emit / boundaryPoint 把
6
+ * `2×points` 顶点环构造成折线段,委托 rounded-contour 模块:cornerRadius 省略 / 0 出原尖角轮廓、>0 在每个顶点
7
+ * 插逐角夹紧的 fillet 弧——凸尖与凹角(notch)由模块按接缝转向叉积统一处理(凹角弧 sweep 反向、圆心在凸侧),
8
+ * emit 与 boundaryPoint 共用同一份 fillet 结果。emit 收轴对齐 rect(旋转由外层 group 施加)、boundaryPoint
9
+ * 收带 rotate 的 rect 且 rayOrigin = 星形几何中心(关于中心对称,AABB 中心 = 形心 = node position)。
10
+ * anchor 含 center / tip-N(第 N 尖角)/ notch-N(第 N 凹角)——恒在原尖角 / 凹角逻辑顶点,不随 cornerRadius 移;
11
+ * self-rotate(params.rotate)与 Node.rotate 叠加。scaleParams 只缩 inner/outerRadius / cornerRadius(长度)、
12
+ * 不缩 points(计数)/ rotate(角度)。
13
+ */
14
+ export declare const star: import('./types').ShapeDefinition;
15
+ //# sourceMappingURL=star.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"star.d.ts","sourceRoot":"","sources":["../../../src/shapes/star.ts"],"names":[],"mappings":"AAsFA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,IAAI,mCA2Ff,CAAC"}
@@ -1,5 +1,7 @@
1
+ import { z } from 'zod';
1
2
  import { Position } from '../geometry/point';
2
3
  import { Rect } from '../geometry/rect';
4
+ import { IRJsonObject } from '../ir/json';
3
5
  import { PaintValue, ScenePrimitive } from '../primitive';
4
6
  /**
5
7
  * emit 需要的视觉样式子集
@@ -13,38 +15,69 @@ export type ShapeStyle = {
13
15
  strokeOpacity?: number;
14
16
  strokeWidth?: number;
15
17
  dashPattern?: Array<number>;
16
- roundedCorners?: number;
18
+ cornerRadius?: number;
17
19
  opacity?: number;
18
20
  };
19
21
  /**
20
- * 一个 shape 的可注册定义:外接 / 边界 / anchor / emit 四件事
21
- * @description plain object(factory 友好:`createPolygonShape(6)` 这类普通函数返回它即可);含函数、
22
- * **不进 IR**,走 `CompileOptions.shapes` 运行时注入。内置 4 shape 也是注册项(无内置特权)。
22
+ * 一个 shape 的参数化可注册定义(定义点 typed 形态)
23
+ * @description plain object(factory 友好:`createPolygonShape(6)` 这类普通函数返回它即可);含函数与
24
+ * `paramsSchema`,**不进 IR**,走 `CompileOptions.shapes` 运行时注入。内置 4 shape 也是注册项(无内置特权)。
25
+ * 每个计算函数末位收 per-instance `params`(类型由 `paramsSchema.parse` 在编译期保证),无参形状用
26
+ * `z.strictObject({})` 并忽略 `params`。
27
+ *
28
+ * - `paramsSchema`:类型约束输出 JSON-safe(`z.ZodType<TParams>`)。这是类型层约束,不是运行时唯一保证——
29
+ * compile 在 `paramsSchema.parse(params)` 之后还会对结果跑一次 `JsonObjectSchema.parse`,拦下宽松
30
+ * schema 放过的非 JSON 输出(function / undefined 等)。
23
31
  *
24
32
  * 坐标语义两套,第三方最易写错:
25
33
  * - `boundaryPoint` / `anchor` 收**带 `rotate` 的 Rect**——用 re-export 的 `worldToLocal` / `localToWorld` 写局部系几何。
26
34
  * - `emit` 收**轴对齐 Rect(rotate=0)**——旋转由编译器在外层 `GroupPrim` 统一施加。
27
35
  */
28
- export type ShapeDefinition = {
36
+ export type ShapeDefinitionInput<TParams extends IRJsonObject> = {
37
+ /** params 的 zod schema;类型约束输出 JSON-safe(运行时双 parse 才是真正护栏,见编译期桥接) */
38
+ paramsSchema: z.ZodType<TParams>;
29
39
  /**
30
- * 外接:内容半轴(text + padding)→ 外接框半轴。
31
- * @description rectangle: identity;circle: √(hw²+hh²) 两轴相等;ellipse: ×√2;diamond: ×2。
40
+ * 外接:内容半轴(text + padding)+ params → 外接框半轴。
41
+ * @description 必返回**包含完整 shape 的精确 AABB 半轴**(compile 的 viewBox / scope bbox 只累积该 AABB
42
+ * 四角)。rectangle: identity;circle: √(hw²+hh²) 两轴相等;ellipse: ×√2;diamond: ×2;参数化形状据 params 算。
32
43
  */
33
- circumscribe: (innerHalfWidth: number, innerHalfHeight: number) => {
44
+ circumscribe: (innerHalfWidth: number, innerHalfHeight: number, params: TParams) => {
34
45
  halfWidth: number;
35
46
  halfHeight: number;
36
47
  };
37
- /** 中心 → toward 射线 ∩ 边界(rect 带 rotate)。 */
38
- boundaryPoint: (rect: Rect, toward: Position) => Position;
48
+ /**
49
+ * AABB 中心相对 node `position` 的偏移(可选;缺省 `[0, 0]` = AABB 中心即 position)。
50
+ * @description 多数 shape 的视觉 AABB 以 position 为中心(rectangle / ellipse / diamond);但 sector 等
51
+ * 形状的语义锚点(圆心 apex)才是 position,其外接 AABB 中心偏在一侧——此 hook 让 compile 把
52
+ * `rect.center` 放到 `position + offset`,使 bbox / viewBox 罩住完整形状、anchor 以 AABB 中心 rect 计算时
53
+ * apex 落回 position。返回**未旋转**局部偏移(compile 在施加 node rotate 前用于定位 rect 中心)。
54
+ */
55
+ circumscribeOffset?: (params: TParams) => Position;
56
+ /** 中心 → toward 射线 ∩ 边界(rect 带 rotate);params 喂参数化边界。 */
57
+ boundaryPoint: (rect: Rect, toward: Position, params: TParams) => Position;
39
58
  /** 命名 anchor 世界坐标;shape 不认识的名字返回 `undefined`(调用方据此抛清晰错误)。 */
40
- anchor: (rect: Rect, name: string) => Position | undefined;
59
+ anchor: (rect: Rect, name: string, params: TParams) => Position | undefined;
41
60
  /**
42
61
  * 边上比例点:side 真实边界从约定起点起 t∈[0,1] 处(轴对齐空间求出后由 layout 投回世界系)。
43
62
  * @description 可选——内置 4 shape 必实现,不实现的 shape 收到 `{ side, t }` 时编译期(resolveEdgePoint)抛明确错。
44
63
  * 与 `anchor` 同坐标语义:收**带 rotate 的 Rect**,自行用 worldToLocal/localToWorld 处理旋转。
45
64
  */
46
- edgePoint?: (rect: Rect, side: 'north' | 'south' | 'east' | 'west', t: number) => Position;
47
- /** 视觉 primitive,**轴对齐空间**(rotate 由编译器外层 GroupPrim 统一施加)。 */
48
- emit: (rect: Rect, style: ShapeStyle, round: (n: number) => number) => Iterable<ScenePrimitive>;
65
+ edgePoint?: (rect: Rect, side: 'north' | 'south' | 'east' | 'west', t: number, params: TParams) => Position;
66
+ /** 视觉 primitive,**轴对齐空间**(rotate 由编译器外层 GroupPrim 统一施加);params 喂参数化几何。 */
67
+ emit: (rect: Rect, style: ShapeStyle, round: (n: number) => number, params: TParams) => Iterable<ScenePrimitive>;
68
+ /**
69
+ * node scale 作用于 params 的方式(可选)。
70
+ * @description 给定原始 params 与水平 / 垂直缩放因子 `sx` / `sy`,返回缩放后的 params。
71
+ * 缺省时编译器沿用默认行为——深度缩放 params 里所有数值叶子(uniform 几何均值因子)。
72
+ * 适用于 params 含「非长度」语义字段(如角度)的形状:sector / arc 只缩半径、不缩角度,
73
+ * 通过本 hook 把 startAngle / endAngle 排除在缩放外。不缩放任何 params 的形状不必实现。
74
+ */
75
+ scaleParams?: (params: TParams, sx: number, sy: number) => TParams;
49
76
  };
77
+ /**
78
+ * shape 定义的擦除形态:registry 存这个
79
+ * @description 所有函数收 `IRJsonObject`(实际类型由 `paramsSchema.parse` 在编译期保证);registry 同构
80
+ * `Record<string, ShapeDefinition>`、不泛型化(避免逆变 / 落 any)。定义点用 `defineShape<TParams>` 拿类型安全。
81
+ */
82
+ export type ShapeDefinition = ShapeDefinitionInput<IRJsonObject>;
50
83
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/shapes/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE/D;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B;;;OAGG;IACH,YAAY,EAAE,CACZ,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,MAAM,KACpB;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/C,0CAA0C;IAC1C,aAAa,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,KAAK,QAAQ,CAAC;IAC1D,6DAA6D;IAC7D,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,KAAK,QAAQ,GAAG,SAAS,CAAC;IAC3D;;;;OAIG;IACH,SAAS,CAAC,EAAE,CACV,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,EACzC,CAAC,EAAE,MAAM,KACN,QAAQ,CAAC;IACd,4DAA4D;IAC5D,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,KAAK,QAAQ,CAAC,cAAc,CAAC,CAAC;CACjG,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/shapes/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE/D;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,oBAAoB,CAAC,OAAO,SAAS,YAAY,IAAI;IAC/D,qEAAqE;IACrE,YAAY,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACjC;;;;OAIG;IACH,YAAY,EAAE,CACZ,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,MAAM,EACvB,MAAM,EAAE,OAAO,KACZ;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/C;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,QAAQ,CAAC;IACnD,wDAAwD;IACxD,aAAa,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,KAAK,QAAQ,CAAC;IAC3E,6DAA6D;IAC7D,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,KAAK,QAAQ,GAAG,SAAS,CAAC;IAC5E;;;;OAIG;IACH,SAAS,CAAC,EAAE,CACV,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,EACzC,CAAC,EAAE,MAAM,EACT,MAAM,EAAE,OAAO,KACZ,QAAQ,CAAC;IACd,0EAA0E;IAC1E,IAAI,EAAE,CACJ,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,UAAU,EACjB,KAAK,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,EAC5B,MAAM,EAAE,OAAO,KACZ,QAAQ,CAAC,cAAc,CAAC,CAAC;IAC9B;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC;CACpE,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,oBAAoB,CAAC,YAAY,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retikz/core",
3
- "version": "0.3.0-alpha.3",
3
+ "version": "0.3.0-alpha.5",
4
4
  "description": "retikz v0.1 core: framework-agnostic IR, scene compiler, and pure parsers.",
5
5
  "type": "module",
6
6
  "author": "Pionpill",
@@ -14,7 +14,7 @@
14
14
  "repository": {
15
15
  "type": "git",
16
16
  "url": "git+https://github.com/Pionpill/retikz.git",
17
- "directory": "packages/core"
17
+ "directory": "packages/core/core"
18
18
  },
19
19
  "bugs": {
20
20
  "url": "https://github.com/Pionpill/retikz/issues"
@@ -1,8 +0,0 @@
1
- import { ShapeDefinition } from './types';
2
- /**
3
- * circle 注册项
4
- * @description circumscribe = 内框对角线/2(两轴相等);几何走 circle 数学层;
5
- * emit 复用 `ellipse.emit`(circle = rx=ry 的 ellipse),与旧 circle→`emitEllipseShape` 等价
6
- */
7
- export declare const circle: ShapeDefinition;
8
- //# sourceMappingURL=circle.d.ts.map