@retikz/core 0.2.0-alpha.7 → 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 (147) 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 +29 -2
  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/paint.d.ts +6 -1
  13. package/dist/es/compile/paint.d.ts.map +1 -1
  14. package/dist/es/compile/paint.js +60 -3
  15. package/dist/es/compile/path/index.d.ts +15 -0
  16. package/dist/es/compile/path/index.d.ts.map +1 -1
  17. package/dist/es/compile/path/index.js +258 -10
  18. package/dist/es/compile/path/relative.d.ts.map +1 -1
  19. package/dist/es/compile/path/relative.js +8 -0
  20. package/dist/es/compile/path/shrink.d.ts +19 -6
  21. package/dist/es/compile/path/shrink.d.ts.map +1 -1
  22. package/dist/es/compile/path/shrink.js +147 -25
  23. package/dist/es/geometry/bend.d.ts +7 -0
  24. package/dist/es/geometry/bend.d.ts.map +1 -1
  25. package/dist/es/geometry/bend.js +26 -1
  26. package/dist/es/index.d.ts +14 -4
  27. package/dist/es/index.d.ts.map +1 -1
  28. package/dist/es/index.js +7 -3
  29. package/dist/es/ir/index.d.ts +1 -0
  30. package/dist/es/ir/index.d.ts.map +1 -1
  31. package/dist/es/ir/json.d.ts +22 -0
  32. package/dist/es/ir/json.d.ts.map +1 -0
  33. package/dist/es/ir/json.js +25 -0
  34. package/dist/es/ir/node.d.ts +5 -5
  35. package/dist/es/ir/paint.d.ts +25 -3
  36. package/dist/es/ir/paint.d.ts.map +1 -1
  37. package/dist/es/ir/paint.js +12 -6
  38. package/dist/es/ir/path/arrow.d.ts +28 -48
  39. package/dist/es/ir/path/arrow.d.ts.map +1 -1
  40. package/dist/es/ir/path/arrow.js +5 -5
  41. package/dist/es/ir/path/path.d.ts +444 -55
  42. package/dist/es/ir/path/path.d.ts.map +1 -1
  43. package/dist/es/ir/path/path.js +21 -1
  44. package/dist/es/ir/path/step.d.ts +363 -8
  45. package/dist/es/ir/path/step.d.ts.map +1 -1
  46. package/dist/es/ir/path/step.js +17 -4
  47. package/dist/es/ir/scope.d.ts +703 -189
  48. package/dist/es/ir/scope.d.ts.map +1 -1
  49. package/dist/es/pathGenerators/define.d.ts +16 -0
  50. package/dist/es/pathGenerators/define.d.ts.map +1 -0
  51. package/dist/es/pathGenerators/define.js +23 -0
  52. package/dist/es/pathGenerators/index.d.ts +9 -0
  53. package/dist/es/pathGenerators/index.d.ts.map +1 -0
  54. package/dist/es/pathGenerators/types.d.ts +45 -0
  55. package/dist/es/pathGenerators/types.d.ts.map +1 -0
  56. package/dist/es/patterns/index.d.ts +10 -0
  57. package/dist/es/patterns/index.d.ts.map +1 -0
  58. package/dist/es/patterns/index.js +83 -0
  59. package/dist/es/patterns/types.d.ts +38 -0
  60. package/dist/es/patterns/types.d.ts.map +1 -0
  61. package/dist/es/primitive/index.d.ts +1 -0
  62. package/dist/es/primitive/index.d.ts.map +1 -1
  63. package/dist/es/primitive/marker.d.ts +160 -0
  64. package/dist/es/primitive/marker.d.ts.map +1 -0
  65. package/dist/es/primitive/paint.d.ts +24 -2
  66. package/dist/es/primitive/paint.d.ts.map +1 -1
  67. package/dist/es/primitive/path.d.ts +22 -18
  68. package/dist/es/primitive/path.d.ts.map +1 -1
  69. package/dist/es/primitive/scene.d.ts +1 -1
  70. package/dist/es/primitive/scene.d.ts.map +1 -1
  71. package/dist/lib/arrows/index.cjs +118 -0
  72. package/dist/lib/arrows/index.d.ts +13 -0
  73. package/dist/lib/arrows/index.d.ts.map +1 -0
  74. package/dist/lib/arrows/types.d.ts +43 -0
  75. package/dist/lib/arrows/types.d.ts.map +1 -0
  76. package/dist/lib/compile/compile.cjs +31 -4
  77. package/dist/lib/compile/compile.d.ts +26 -1
  78. package/dist/lib/compile/compile.d.ts.map +1 -1
  79. package/dist/lib/compile/marker-prim.cjs +63 -0
  80. package/dist/lib/compile/marker-prim.d.ts +22 -0
  81. package/dist/lib/compile/marker-prim.d.ts.map +1 -0
  82. package/dist/lib/compile/paint.cjs +60 -3
  83. package/dist/lib/compile/paint.d.ts +6 -1
  84. package/dist/lib/compile/paint.d.ts.map +1 -1
  85. package/dist/lib/compile/path/index.cjs +256 -8
  86. package/dist/lib/compile/path/index.d.ts +15 -0
  87. package/dist/lib/compile/path/index.d.ts.map +1 -1
  88. package/dist/lib/compile/path/relative.cjs +8 -0
  89. package/dist/lib/compile/path/relative.d.ts.map +1 -1
  90. package/dist/lib/compile/path/shrink.cjs +147 -25
  91. package/dist/lib/compile/path/shrink.d.ts +19 -6
  92. package/dist/lib/compile/path/shrink.d.ts.map +1 -1
  93. package/dist/lib/geometry/bend.cjs +26 -0
  94. package/dist/lib/geometry/bend.d.ts +7 -0
  95. package/dist/lib/geometry/bend.d.ts.map +1 -1
  96. package/dist/lib/index.cjs +11 -0
  97. package/dist/lib/index.d.ts +14 -4
  98. package/dist/lib/index.d.ts.map +1 -1
  99. package/dist/lib/ir/index.d.ts +1 -0
  100. package/dist/lib/ir/index.d.ts.map +1 -1
  101. package/dist/lib/ir/json.cjs +26 -0
  102. package/dist/lib/ir/json.d.ts +22 -0
  103. package/dist/lib/ir/json.d.ts.map +1 -0
  104. package/dist/lib/ir/node.d.ts +5 -5
  105. package/dist/lib/ir/paint.cjs +12 -5
  106. package/dist/lib/ir/paint.d.ts +25 -3
  107. package/dist/lib/ir/paint.d.ts.map +1 -1
  108. package/dist/lib/ir/path/arrow.cjs +5 -5
  109. package/dist/lib/ir/path/arrow.d.ts +28 -48
  110. package/dist/lib/ir/path/arrow.d.ts.map +1 -1
  111. package/dist/lib/ir/path/path.cjs +20 -0
  112. package/dist/lib/ir/path/path.d.ts +444 -55
  113. package/dist/lib/ir/path/path.d.ts.map +1 -1
  114. package/dist/lib/ir/path/step.cjs +17 -3
  115. package/dist/lib/ir/path/step.d.ts +363 -8
  116. package/dist/lib/ir/path/step.d.ts.map +1 -1
  117. package/dist/lib/ir/scope.d.ts +703 -189
  118. package/dist/lib/ir/scope.d.ts.map +1 -1
  119. package/dist/lib/pathGenerators/define.cjs +23 -0
  120. package/dist/lib/pathGenerators/define.d.ts +16 -0
  121. package/dist/lib/pathGenerators/define.d.ts.map +1 -0
  122. package/dist/lib/pathGenerators/index.d.ts +9 -0
  123. package/dist/lib/pathGenerators/index.d.ts.map +1 -0
  124. package/dist/lib/pathGenerators/types.d.ts +45 -0
  125. package/dist/lib/pathGenerators/types.d.ts.map +1 -0
  126. package/dist/lib/patterns/index.cjs +83 -0
  127. package/dist/lib/patterns/index.d.ts +10 -0
  128. package/dist/lib/patterns/index.d.ts.map +1 -0
  129. package/dist/lib/patterns/types.d.ts +38 -0
  130. package/dist/lib/patterns/types.d.ts.map +1 -0
  131. package/dist/lib/primitive/index.d.ts +1 -0
  132. package/dist/lib/primitive/index.d.ts.map +1 -1
  133. package/dist/lib/primitive/marker.d.ts +160 -0
  134. package/dist/lib/primitive/marker.d.ts.map +1 -0
  135. package/dist/lib/primitive/paint.d.ts +24 -2
  136. package/dist/lib/primitive/paint.d.ts.map +1 -1
  137. package/dist/lib/primitive/path.d.ts +22 -18
  138. package/dist/lib/primitive/path.d.ts.map +1 -1
  139. package/dist/lib/primitive/scene.d.ts +1 -1
  140. package/dist/lib/primitive/scene.d.ts.map +1 -1
  141. package/package.json +1 -1
  142. package/dist/es/compile/path/arrow-geometry.d.ts +0 -22
  143. package/dist/es/compile/path/arrow-geometry.d.ts.map +0 -1
  144. package/dist/es/compile/path/arrow-geometry.js +0 -40
  145. package/dist/lib/compile/path/arrow-geometry.cjs +0 -41
  146. package/dist/lib/compile/path/arrow-geometry.d.ts +0 -22
  147. package/dist/lib/compile/path/arrow-geometry.d.ts.map +0 -1
@@ -0,0 +1,13 @@
1
+ import { BuiltinArrowName } from '../ir/path/arrow';
2
+ import { ArrowDefinition } from './types';
3
+ /**
4
+ * 内置 7 arrow 注册项;与 `CompileOptions.arrows` 合并时被同名注入覆盖
5
+ * @description 几何字段(lineContactX 静态 base / tipX / hollow):
6
+ * 实心 normal/diamond/circle lineContactX=0;stealth=3;open/openDiamond base=1 + tipX=9 + hollow;
7
+ * openCircle base=0.75 + hollow。baseSize / defaultLength / defaultWidth 走类型缺省(10 / 6 / 6)。
8
+ * framework 对 hollow def 统一把 lineContactX 减 lineWidth/2 得实际 refX / shrink 接触点。
9
+ * emit 几何在局部 baseSize=10 坐标系,等价历史 SVG。
10
+ */
11
+ export declare const BUILTIN_ARROWS: Record<BuiltinArrowName, ArrowDefinition>;
12
+ export type { ArrowDefinition, ArrowEmitContext } from './types';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/arrows/index.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAoB,MAAM,SAAS,CAAC;AAiCjE;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,gBAAgB,EAAE,eAAe,CAqDpE,CAAC;AAEF,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC"}
@@ -0,0 +1,118 @@
1
+ //#region src/arrows/index.ts
2
+ /** 实心闭合三角 / 菱形 / V 形的 path 工厂:填充走 ctx.fill(无 override = contextStroke) */
3
+ var filledPath = (ctx, points) => ({
4
+ type: "path",
5
+ commands: [
6
+ {
7
+ kind: "move",
8
+ to: points[0]
9
+ },
10
+ ...points.slice(1).map((p) => ({
11
+ kind: "line",
12
+ to: p
13
+ })),
14
+ { kind: "close" }
15
+ ],
16
+ fill: typeof ctx.fill === "string" ? ctx.fill : { kind: "contextStroke" }
17
+ });
18
+ /** 空心闭合 path 工厂:无 fill、描边走 ctx.stroke / ctx.lineWidth(contextStroke 由 adapter 映射) */
19
+ var hollowPath = (ctx, points, strokeLinejoin) => ({
20
+ type: "path",
21
+ commands: [
22
+ {
23
+ kind: "move",
24
+ to: points[0]
25
+ },
26
+ ...points.slice(1).map((p) => ({
27
+ kind: "line",
28
+ to: p
29
+ })),
30
+ { kind: "close" }
31
+ ],
32
+ stroke: typeof ctx.stroke === "string" ? ctx.stroke : "context-stroke",
33
+ strokeWidth: ctx.lineWidth,
34
+ ...strokeLinejoin ? { strokeLinejoin } : {}
35
+ });
36
+ /**
37
+ * 内置 7 arrow 注册项;与 `CompileOptions.arrows` 合并时被同名注入覆盖
38
+ * @description 几何字段(lineContactX 静态 base / tipX / hollow):
39
+ * 实心 normal/diamond/circle lineContactX=0;stealth=3;open/openDiamond base=1 + tipX=9 + hollow;
40
+ * openCircle base=0.75 + hollow。baseSize / defaultLength / defaultWidth 走类型缺省(10 / 6 / 6)。
41
+ * framework 对 hollow def 统一把 lineContactX 减 lineWidth/2 得实际 refX / shrink 接触点。
42
+ * emit 几何在局部 baseSize=10 坐标系,等价历史 SVG。
43
+ */
44
+ var BUILTIN_ARROWS = {
45
+ normal: {
46
+ lineContactX: 0,
47
+ emit: (ctx) => [filledPath(ctx, [
48
+ [0, 0],
49
+ [10, 5],
50
+ [0, 10]
51
+ ])]
52
+ },
53
+ open: {
54
+ hollow: true,
55
+ lineContactX: 1,
56
+ tipX: 9,
57
+ emit: (ctx) => [hollowPath(ctx, [
58
+ [1, 1],
59
+ [9, 5],
60
+ [1, 9]
61
+ ])]
62
+ },
63
+ stealth: {
64
+ lineContactX: 3,
65
+ emit: (ctx) => [filledPath(ctx, [
66
+ [0, 0],
67
+ [10, 5],
68
+ [0, 10],
69
+ [3, 5]
70
+ ])]
71
+ },
72
+ diamond: {
73
+ lineContactX: 0,
74
+ emit: (ctx) => [filledPath(ctx, [
75
+ [0, 5],
76
+ [5, 0],
77
+ [10, 5],
78
+ [5, 10]
79
+ ])]
80
+ },
81
+ openDiamond: {
82
+ hollow: true,
83
+ lineContactX: 1,
84
+ tipX: 9,
85
+ emit: (ctx) => [hollowPath(ctx, [
86
+ [1, 5],
87
+ [5, 1],
88
+ [9, 5],
89
+ [5, 9]
90
+ ], "round")]
91
+ },
92
+ circle: {
93
+ lineContactX: 0,
94
+ emit: (ctx) => [{
95
+ type: "ellipse",
96
+ cx: 5,
97
+ cy: 5,
98
+ rx: 5,
99
+ ry: 5,
100
+ fill: typeof ctx.fill === "string" ? ctx.fill : { kind: "contextStroke" }
101
+ }]
102
+ },
103
+ openCircle: {
104
+ hollow: true,
105
+ lineContactX: .75,
106
+ emit: (ctx) => [{
107
+ type: "ellipse",
108
+ cx: 5,
109
+ cy: 5,
110
+ rx: 4.25,
111
+ ry: 4.25,
112
+ stroke: typeof ctx.stroke === "string" ? ctx.stroke : "context-stroke",
113
+ strokeWidth: ctx.lineWidth
114
+ }]
115
+ }
116
+ };
117
+ //#endregion
118
+ export { BUILTIN_ARROWS };
@@ -0,0 +1,43 @@
1
+ import { MarkerFill, MarkerPrimitive } from '../primitive/marker';
2
+ /**
3
+ * emit 拿到的运行时上下文
4
+ * @description framework 把宿主 path 已解析的颜色 / 描边粗细传进来;def 据此产 marker 几何。
5
+ * `stroke` / `fill` 是 `MarkerFill`(纯色串或 `{ kind: 'contextStroke' }`,无 override 时取 contextStroke
6
+ * 继承 path stroke、主题反应不冻结)——可直接当 marker primitive 的 `fill` / `stroke` 用,无需收窄。
7
+ */
8
+ export type ArrowEmitContext = {
9
+ /** 描边颜色(无 override 时 = `{ kind: 'contextStroke' }`,继承 path stroke) */
10
+ stroke: MarkerFill;
11
+ /** 填充颜色(实心箭头主导色;空心箭头由 framework 据 `hollow` 处理后传入) */
12
+ fill: MarkerFill;
13
+ /** 描边粗细(marker 局部坐标,user units);空心箭头据此画外轮廓 */
14
+ lineWidth: number;
15
+ /** 精度取整函数(与 compile/render 同一 round,保几何一致) */
16
+ round: (n: number) => number;
17
+ };
18
+ /**
19
+ * 一个 arrow 的可注册定义:几何尺寸 + emit
20
+ * @description plain object(factory 友好),含函数、**不进 IR**,走 `CompileOptions.arrows` 运行时注入。
21
+ * 内置 7 箭头也是注册项(无内置特权,对齐 `ShapeDefinition` / `BUILTIN_SHAPES`)。
22
+ *
23
+ * `lineContactX` 存**静态 base**(不含 lineWidth 调整):实心 normal/diamond/circle = 0、stealth = 3、
24
+ * open/openDiamond base = 1、openCircle base = 0.75。framework 对 `hollow: true` 的 def 统一减
25
+ * `lineWidth/2` 得到实际 refX / shrink 接触点(这条调整由编译器 / adapter 落,def 只声明静态 base)。
26
+ */
27
+ export type ArrowDefinition = {
28
+ /** marker 局部基准边长(viewBox `0 0 baseSize baseSize`,refY = baseSize/2);缺省 10 */
29
+ baseSize?: number;
30
+ /** 空心标志:true 时 framework 丢 fill、color 主导描边、启用 lineWidth;并对 lineContactX 减 lineWidth/2 */
31
+ hollow?: boolean;
32
+ /** 线接触点静态 base(决定 path shrink + marker refX);空心 def 由 framework 再减 lineWidth/2 */
33
+ lineContactX: number;
34
+ /** 尖端 x(shrink 用);缺省 = baseSize */
35
+ tipX?: number;
36
+ /** 默认箭头长度(length fallback);缺省 6 */
37
+ defaultLength?: number;
38
+ /** 默认箭头宽度(width fallback);缺省 6 */
39
+ defaultWidth?: number;
40
+ /** 局部坐标 marker 几何(renderer-agnostic);adapter 把产物嵌进 `<marker>` */
41
+ emit: (ctx: ArrowEmitContext) => Iterable<MarkerPrimitive>;
42
+ };
43
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/arrows/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEvE;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,sEAAsE;IACtE,MAAM,EAAE,UAAU,CAAC;IACnB,qDAAqD;IACrD,IAAI,EAAE,UAAU,CAAC;IACjB,8CAA8C;IAC9C,SAAS,EAAE,MAAM,CAAC;IAClB,8CAA8C;IAC9C,KAAK,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;CAC9B,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,yFAAyF;IACzF,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,kFAAkF;IAClF,YAAY,EAAE,MAAM,CAAC;IACrB,mCAAmC;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mCAAmC;IACnC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kCAAkC;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iEAAiE;IACjE,IAAI,EAAE,CAAC,GAAG,EAAE,gBAAgB,KAAK,QAAQ,CAAC,eAAe,CAAC,CAAC;CAC5D,CAAC"}
@@ -1,6 +1,9 @@
1
1
  import { IR } from '../ir';
2
2
  import { Scene } from '../primitive';
3
3
  import { ShapeDefinition } from '../shapes';
4
+ import { ArrowDefinition } from '../arrows';
5
+ import { PatternDefinition } from '../patterns';
6
+ import { PathGeneratorDefinition } from '../pathGenerators';
4
7
  import { TextMeasurer } from './text-metrics';
5
8
  /** 编译期警告:path / position 解析失败时通过 `CompileOptions.onWarn` 发出,不影响编译产物 */
6
9
  export type CompileWarning = {
@@ -8,7 +11,7 @@ export type CompileWarning = {
8
11
  * 警告类型代码(机器可读)
9
12
  * @description 用户可按 code 分支处理;未来 alpha 加新 code 不破坏调用方
10
13
  */
11
- code: 'UNRESOLVED_NODE_REFERENCE' | 'PATH_TOO_SHORT' | 'ANCHOR_RESOLUTION_FAILED' | 'OFFSET_BASE_UNRESOLVED' | 'POLAR_ORIGIN_UNRESOLVED' | 'AT_TARGET_UNRESOLVED' | 'RELATIVE_INITIAL_NO_PREV_END' | 'BBOX_EXTREME_INPUT' | 'DUPLICATE_NODE_ID' | 'SHAPE_OVERRIDES_BUILTIN' | (string & {});
14
+ code: 'UNRESOLVED_NODE_REFERENCE' | 'PATH_TOO_SHORT' | 'ANCHOR_RESOLUTION_FAILED' | 'OFFSET_BASE_UNRESOLVED' | 'POLAR_ORIGIN_UNRESOLVED' | 'AT_TARGET_UNRESOLVED' | 'RELATIVE_INITIAL_NO_PREV_END' | 'BBOX_EXTREME_INPUT' | 'DUPLICATE_NODE_ID' | 'SHAPE_OVERRIDES_BUILTIN' | 'ARROW_OVERRIDES_BUILTIN' | 'PATTERN_OVERRIDES_BUILTIN' | (string & {});
12
15
  /** 人类可读消息(英文) */
13
16
  message: string;
14
17
  /** IR locator 路径(jq-like,如 `'children[3].path.children[1].to'`) */
@@ -41,6 +44,28 @@ export type CompileOptions = {
41
44
  * `SHAPE_OVERRIDES_BUILTIN`。IR 的 `node.shape` 仍是字符串;未注册名在编译期 throw。
42
45
  */
43
46
  shapes?: Record<string, ShapeDefinition>;
47
+ /**
48
+ * 运行时注入的第三方 arrow(不进 IR)
49
+ * @description 有效 arrow 表 = `{ ...BUILTIN_ARROWS, ...arrows }`——同名 key 覆盖内置,经 `onWarn` 发
50
+ * `ARROW_OVERRIDES_BUILTIN`。IR 的 `arrowDetail.shape` 仍是字符串;未注册名在编译期 throw。
51
+ */
52
+ arrows?: Record<string, ArrowDefinition>;
53
+ /**
54
+ * 运行时注入的第三方 pattern motif(不进 IR)
55
+ * @description 有效 pattern 表 = `{ ...BUILTIN_PATTERNS, ...patterns }`——同名 key 覆盖内置,经 `onWarn` 发
56
+ * `PATTERN_OVERRIDES_BUILTIN`。IR 的 `pattern.shape` 仍是字符串;未注册名在编译期 throw。
57
+ * compile 对 pattern 资源查本表 + 调 `PatternDefinition.emit` 产 tile,写进 `SceneResource.tile`。
58
+ */
59
+ patterns?: Record<string, PatternDefinition>;
60
+ /**
61
+ * 运行时注入的第三方 path generator(不进 IR)
62
+ * @description generator step 编译时按 `name` 查本表;core 不内置任何曲线生成器,故无内置合并。
63
+ * 解析时序:查表(未注册 throw,错误列出可用名)→ `paramsSchema.parse(params)` →
64
+ * 对结果再跑 `JsonObjectSchema.parse` 二次确认 JSON-safe → `targetParams` 顶层 key 经 target lookup
65
+ * resolve 成世界坐标 → 调 `generate(ctx)` → splice 产出的 `PathCommand[]` 进命令流。IR 的
66
+ * `generator.name` 仍是字符串;generator 函数本身只在此运行时注入面、不进 IR。
67
+ */
68
+ pathGenerators?: Record<string, PathGeneratorDefinition>;
44
69
  };
45
70
  /**
46
71
  * IR → Scene 纯函数转换,所有 adapter 共享
@@ -1 +1 @@
1
- {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../../src/compile/compile.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAwC,MAAM,OAAO,CAAC;AACtE,OAAO,KAAK,EAAa,KAAK,EAA6B,MAAM,cAAc,CAAC;AAEhF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAqBjD,OAAO,EAAE,KAAK,YAAY,EAAoB,MAAM,gBAAgB,CAAC;AA4CrE,uEAAuE;AACvE,MAAM,MAAM,cAAc,GAAG;IAC3B;;;OAGG;IACH,IAAI,EACA,2BAA2B,GAC3B,gBAAgB,GAChB,0BAA0B,GAC1B,wBAAwB,GACxB,yBAAyB,GACzB,sBAAsB,GACtB,8BAA8B,GAC9B,oBAAoB,GACpB,mBAAmB,GACnB,yBAAyB,GACzB,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;IAClB,iBAAiB;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,2BAA2B;AAC3B,MAAM,MAAM,cAAc,GAAG;IAC3B,oCAAoC;IACpC,WAAW,CAAC,EAAE,YAAY,CAAC;IAC3B,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;IAC3C;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;CAC1C,CAAC;AA6FF;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,IAAI,EAAE,EAAE,UAAS,cAAmB,KAAG,KAoSrE,CAAC"}
1
+ {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../../src/compile/compile.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAwC,MAAM,OAAO,CAAC;AACtE,OAAO,KAAK,EAAa,KAAK,EAA6B,MAAM,cAAc,CAAC;AAEhF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAqBjE,OAAO,EAAE,KAAK,YAAY,EAAoB,MAAM,gBAAgB,CAAC;AA4CrE,uEAAuE;AACvE,MAAM,MAAM,cAAc,GAAG;IAC3B;;;OAGG;IACH,IAAI,EACA,2BAA2B,GAC3B,gBAAgB,GAChB,0BAA0B,GAC1B,wBAAwB,GACxB,yBAAyB,GACzB,sBAAsB,GACtB,8BAA8B,GAC9B,oBAAoB,GACpB,mBAAmB,GACnB,yBAAyB,GACzB,yBAAyB,GACzB,2BAA2B,GAC3B,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;IAClB,iBAAiB;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,2BAA2B;AAC3B,MAAM,MAAM,cAAc,GAAG;IAC3B,oCAAoC;IACpC,WAAW,CAAC,EAAE,YAAY,CAAC;IAC3B,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;IAC3C;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACzC;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACzC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IAC7C;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC;CAC1D,CAAC;AA6FF;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,IAAI,EAAE,EAAE,UAAS,cAAmB,KAAG,KA4UrE,CAAC"}
@@ -1,5 +1,7 @@
1
1
  import { rect } from "../geometry/rect.js";
2
2
  import { BUILTIN_SHAPES } from "../shapes/index.js";
3
+ import { BUILTIN_ARROWS } from "../arrows/index.js";
4
+ import { BUILTIN_PATTERNS } from "../patterns/index.js";
3
5
  import { NameStack } from "./name-stack.js";
4
6
  import { applyTransformChain, computeScopeBoundingBox, lowerScopeTransforms, projectLayoutToGlobal, registerScopeAsLayout } from "./scope.js";
5
7
  import { resolvePosition } from "./position.js";
@@ -110,6 +112,29 @@ var compileToScene = (ir, options = {}) => {
110
112
  path: `options.shapes.${name}`
111
113
  });
112
114
  }
115
+ const effectivePathGenerators = options.pathGenerators ?? {};
116
+ const effectiveArrows = options.arrows ? {
117
+ ...BUILTIN_ARROWS,
118
+ ...options.arrows
119
+ } : BUILTIN_ARROWS;
120
+ if (options.arrows) {
121
+ for (const name of Object.keys(options.arrows)) if (Object.prototype.hasOwnProperty.call(BUILTIN_ARROWS, name)) onWarn({
122
+ code: "ARROW_OVERRIDES_BUILTIN",
123
+ message: `Injected arrow '${name}' overrides the built-in arrow of the same name.`,
124
+ path: `options.arrows.${name}`
125
+ });
126
+ }
127
+ const effectivePatterns = options.patterns ? {
128
+ ...BUILTIN_PATTERNS,
129
+ ...options.patterns
130
+ } : BUILTIN_PATTERNS;
131
+ if (options.patterns) {
132
+ for (const name of Object.keys(options.patterns)) if (Object.prototype.hasOwnProperty.call(BUILTIN_PATTERNS, name)) onWarn({
133
+ code: "PATTERN_OVERRIDES_BUILTIN",
134
+ message: `Injected pattern '${name}' overrides the built-in pattern of the same name.`,
135
+ path: `options.patterns.${name}`
136
+ });
137
+ }
113
138
  const primitives = [];
114
139
  /** 已 push 但未回填的占位计数;compileToScene 返回前必须归零(无条件守 Scene 公开契约) */
115
140
  let placeholderBalance = 0;
@@ -134,7 +159,7 @@ var compileToScene = (ir, options = {}) => {
134
159
  };
135
160
  const nameStack = new NameStack({ onDuplicate: (info) => onWarn(formatDuplicateWarning(info)) });
136
161
  const allPoints = [];
137
- const paint = createPaintRegistry();
162
+ const paint = createPaintRegistry(effectivePatterns, round);
138
163
  /**
139
164
  * 解析一批本层收集的 pending paths(lookup-only 阶段)
140
165
  * @description 两种落点:有 `slot`(scopeChain 为空)→ 原位 splice 回填该 path 在本层 sink 占的位(按引用定位免索引漂移),保住与同层 node 的 IR 声明序;无 `slot`(scopeChain 非空)→ hoist 到顶层 `primitives`,因端点已是全局坐标、进 transformed GroupPrim 会被 scope.transform 二次 apply。NameStack 切到 pass2 守门:path 解析中误调 register 抛 internal error;解析完切回 pass1 让上层 scope 子树继续 register 子节点。
@@ -150,7 +175,9 @@ var compileToScene = (ir, options = {}) => {
150
175
  onWarn,
151
176
  irPath: item.irPath,
152
177
  scopeChain: item.scopeChain,
153
- resolveFill: paint.resolve
178
+ resolveFill: paint.resolve,
179
+ effectiveArrows,
180
+ effectivePathGenerators
154
181
  });
155
182
  if (item.slot) {
156
183
  const idx = item.slot.sink.indexOf(item.slot.placeholder);
@@ -0,0 +1,22 @@
1
+ import { MarkerPrimitive } from '../primitive/marker';
2
+ /** 深度查 emit 产物里有没有函数(守 Scene 100% JSON 可序列化) */
3
+ export declare const assertNoFunction: (owner: string, value: unknown) => void;
4
+ /**
5
+ * 深度查 emit 产物里有没有非 finite 数(NaN / Infinity)
6
+ * @description 第三方 / LLM 的 emit 算错坐标(除零 / 溢出)会产 NaN / Infinity;`JSON.stringify` 把它们变成
7
+ * `null`,破坏 Scene round-trip 等价。故在此抛含 owner 的清晰错,不放任非 finite 流入 Scene(与 arrow
8
+ * geometry / path generator 的 finite 守卫同源)。
9
+ */
10
+ export declare const assertFiniteNumbers: (owner: string, value: unknown) => void;
11
+ /**
12
+ * 递归校验单个 emit 产物符合 `MarkerPrimitive` 窄子集(运行时栅栏,TS 只能编译期守门)
13
+ * @description type 限 path/ellipse/rect/group(拒 text 等);fill 限 string | contextStroke(拒 resourceRef
14
+ * 等外部资源引用);group 递归 children。守"marker 内无文本布局 / 无外部资源 / 无递归 marker"契约。
15
+ */
16
+ export declare const assertValidMarkerPrim: (owner: string, prim: unknown) => void;
17
+ /**
18
+ * 跑完整窄子集 + JSON-safe 校验(产物逐个过 `assertValidMarkerPrim` + 深度无函数检查)
19
+ * @description arrow / pattern 调 emit 收齐 `MarkerPrimitive[]` 后调用;任一原语违窄子集即抛含 owner 的清晰错。
20
+ */
21
+ export declare const validateMarkerPrimitives: (owner: string, marker: ReadonlyArray<MarkerPrimitive>) => void;
22
+ //# sourceMappingURL=marker-prim.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"marker-prim.d.ts","sourceRoot":"","sources":["../../../src/compile/marker-prim.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAa3D,gDAAgD;AAChD,eAAO,MAAM,gBAAgB,GAAI,OAAO,MAAM,EAAE,OAAO,OAAO,KAAG,IAWhE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAAI,OAAO,MAAM,EAAE,OAAO,OAAO,KAAG,IAcnE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,GAAI,OAAO,MAAM,EAAE,MAAM,OAAO,KAAG,IA2BpE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,wBAAwB,GACnC,OAAO,MAAM,EACb,QAAQ,aAAa,CAAC,eAAe,CAAC,KACrC,IAIF,CAAC"}
@@ -0,0 +1,63 @@
1
+ //#region src/compile/marker-prim.ts
2
+ /**
3
+ * marker 窄子集运行时栅栏(arrow + pattern 共用)
4
+ * @description `MarkerPrimitive` 的窄子集(type 限 path/ellipse/rect/group、fill 限 string | contextStroke、
5
+ * 无外部 resourceRef / text / 函数)TS 只能编译期守门;第三方 / LLM 写出的 emit 会在运行时绕过类型,
6
+ * 故这里做运行时校验。arrow(marker 几何)与 pattern(motif 几何)emit 产物同契约,复用本组校验。
7
+ * `owner` 是错误消息里的归属串(如 `Arrow 'normal'` / `Pattern 'lines'`),便于第三方 / LLM 自修。
8
+ */
9
+ /** marker 子集允许的 primitive type(窄子集运行时栅栏) */
10
+ var MARKER_PRIM_TYPES = new Set([
11
+ "path",
12
+ "ellipse",
13
+ "rect",
14
+ "group"
15
+ ]);
16
+ /** 深度查 emit 产物里有没有函数(守 Scene 100% JSON 可序列化) */
17
+ var assertNoFunction = (owner, value) => {
18
+ if (typeof value === "function") throw new Error(`${owner} emit produced a marker containing a function; markers must be plain JSON data.`);
19
+ if (Array.isArray(value)) for (const v of value) assertNoFunction(owner, v);
20
+ else if (value !== null && typeof value === "object") for (const v of Object.values(value)) assertNoFunction(owner, v);
21
+ };
22
+ /**
23
+ * 深度查 emit 产物里有没有非 finite 数(NaN / Infinity)
24
+ * @description 第三方 / LLM 的 emit 算错坐标(除零 / 溢出)会产 NaN / Infinity;`JSON.stringify` 把它们变成
25
+ * `null`,破坏 Scene round-trip 等价。故在此抛含 owner 的清晰错,不放任非 finite 流入 Scene(与 arrow
26
+ * geometry / path generator 的 finite 守卫同源)。
27
+ */
28
+ var assertFiniteNumbers = (owner, value) => {
29
+ if (typeof value === "number") {
30
+ if (!Number.isFinite(value)) throw new Error(`${owner} emit produced a marker with a non-finite number (${String(value)}); marker coordinates must be finite.`);
31
+ return;
32
+ }
33
+ if (Array.isArray(value)) for (const v of value) assertFiniteNumbers(owner, v);
34
+ else if (value !== null && typeof value === "object") for (const v of Object.values(value)) assertFiniteNumbers(owner, v);
35
+ };
36
+ /**
37
+ * 递归校验单个 emit 产物符合 `MarkerPrimitive` 窄子集(运行时栅栏,TS 只能编译期守门)
38
+ * @description type 限 path/ellipse/rect/group(拒 text 等);fill 限 string | contextStroke(拒 resourceRef
39
+ * 等外部资源引用);group 递归 children。守"marker 内无文本布局 / 无外部资源 / 无递归 marker"契约。
40
+ */
41
+ var assertValidMarkerPrim = (owner, prim) => {
42
+ if (prim === null || typeof prim !== "object") throw new Error(`${owner} emit produced a non-object marker primitive.`);
43
+ const type = prim.type;
44
+ if (typeof type !== "string" || !MARKER_PRIM_TYPES.has(type)) throw new Error(`${owner} emit produced an invalid marker primitive type '${String(type)}'; allowed: group, path, ellipse, rect.`);
45
+ const fill = prim.fill;
46
+ if (fill !== void 0 && typeof fill !== "string" && !(typeof fill === "object" && fill !== null && fill.kind === "contextStroke")) throw new Error(`${owner} marker fill must be a color string or { kind: 'contextStroke' }; external paint references are not allowed inside markers.`);
47
+ if (type === "group") {
48
+ const children = prim.children;
49
+ if (!Array.isArray(children)) throw new Error(`${owner} marker group must have a children array.`);
50
+ for (const child of children) assertValidMarkerPrim(owner, child);
51
+ }
52
+ };
53
+ /**
54
+ * 跑完整窄子集 + JSON-safe 校验(产物逐个过 `assertValidMarkerPrim` + 深度无函数检查)
55
+ * @description arrow / pattern 调 emit 收齐 `MarkerPrimitive[]` 后调用;任一原语违窄子集即抛含 owner 的清晰错。
56
+ */
57
+ var validateMarkerPrimitives = (owner, marker) => {
58
+ for (const prim of marker) assertValidMarkerPrim(owner, prim);
59
+ assertNoFunction(owner, marker);
60
+ assertFiniteNumbers(owner, marker);
61
+ };
62
+ //#endregion
63
+ export { validateMarkerPrimitives };
@@ -1,4 +1,5 @@
1
1
  import { IRPaintSpec } from '../ir';
2
+ import { PatternDefinition } from '../patterns';
2
3
  import { PaintValue, SceneResource } from '../primitive';
3
4
  /** fill 解析器:纯色 string 原样返回;PaintSpec 去重 + 派稳定 id → `{ kind:'resourceRef', id }`;undefined 透传 */
4
5
  export type PaintResolver = (fill: string | IRPaintSpec | undefined) => PaintValue | undefined;
@@ -11,6 +12,10 @@ export type PaintRegistry = {
11
12
  * 建一个 paint 登记表
12
13
  * @description resolve 对相同 PaintSpec(结构化 JSON 深比较)合并为一个资源、派稳定 id(`paint-1` / `paint-2`…,首见序)。
13
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 几何一致)
14
19
  */
15
- export declare const createPaintRegistry: () => PaintRegistry;
20
+ export declare const createPaintRegistry: (effectivePatterns: Record<string, PatternDefinition>, round: (n: number) => number) => PaintRegistry;
16
21
  //# sourceMappingURL=paint.d.ts.map
@@ -1 +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,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE9D,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;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,QAAO,aAkBtC,CAAC"}
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"}
@@ -1,10 +1,65 @@
1
+ import { validateMarkerPrimitives } from "./marker-prim.js";
1
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
+ };
2
53
  /**
3
54
  * 建一个 paint 登记表
4
55
  * @description resolve 对相同 PaintSpec(结构化 JSON 深比较)合并为一个资源、派稳定 id(`paint-1` / `paint-2`…,首见序)。
5
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 几何一致)
6
61
  */
7
- var createPaintRegistry = () => {
62
+ var createPaintRegistry = (effectivePatterns, round) => {
8
63
  const idByKey = /* @__PURE__ */ new Map();
9
64
  const list = [];
10
65
  let counter = 0;
@@ -17,11 +72,13 @@ var createPaintRegistry = () => {
17
72
  counter += 1;
18
73
  id = `paint-${counter}`;
19
74
  idByKey.set(key, id);
20
- list.push({
75
+ const resource = {
21
76
  kind: "paint",
22
77
  id,
23
78
  spec: fill
24
- });
79
+ };
80
+ if (fill.type === "pattern") resource.tile = resolvePatternTile(fill, effectivePatterns, round);
81
+ list.push(resource);
25
82
  }
26
83
  return {
27
84
  kind: "resourceRef",
@@ -1,8 +1,10 @@
1
1
  import { PaintResolver } from '../paint';
2
2
  import { IRPath, IRPosition } from '../../ir';
3
3
  import { ScenePrimitive, Transform } from '../../primitive';
4
+ import { PathGeneratorDefinition } from '../../pathGenerators';
4
5
  import { NameStack } from '../name-stack';
5
6
  import { TextMeasurer } from '../text-metrics';
7
+ import { EffectiveArrows } from './shrink';
6
8
  /** emitPathPrimitive 可选 warn 钩子 */
7
9
  export type EmitPathWarnHook = {
8
10
  /** 警告收集器(由 compileToScene 传入) */
@@ -21,6 +23,19 @@ export type EmitPathWarnHook = {
21
23
  scopeChain?: ReadonlyArray<Transform>;
22
24
  /** fill 解析器(PaintSpec → resourceRef + 登记资源);缺省时纯色透传、PaintSpec 退化为无填充 */
23
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>;
24
39
  };
25
40
  /**
26
41
  * IR Path → PathPrim
@@ -1 +1 @@
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,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;IACtC,wEAAwE;IACxE,WAAW,CAAC,EAAE,aAAa,CAAC;CAC7B,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,IAqhBrE,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"}