@retikz/core 0.1.0 → 0.2.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/es/compile/anchor-cache.d.ts +12 -0
  2. package/dist/es/compile/anchor-cache.d.ts.map +1 -0
  3. package/dist/es/compile/anchor-cache.js +41 -0
  4. package/dist/es/compile/compile.d.ts +2 -2
  5. package/dist/es/compile/compile.d.ts.map +1 -1
  6. package/dist/es/compile/compile.js +148 -40
  7. package/dist/es/compile/index.d.ts +1 -0
  8. package/dist/es/compile/index.d.ts.map +1 -1
  9. package/dist/es/compile/name-stack.d.ts +81 -0
  10. package/dist/es/compile/name-stack.d.ts.map +1 -0
  11. package/dist/es/compile/name-stack.js +104 -0
  12. package/dist/es/compile/node.d.ts +8 -4
  13. package/dist/es/compile/node.d.ts.map +1 -1
  14. package/dist/es/compile/node.js +13 -5
  15. package/dist/es/compile/path/anchor.d.ts +11 -5
  16. package/dist/es/compile/path/anchor.d.ts.map +1 -1
  17. package/dist/es/compile/path/anchor.js +24 -13
  18. package/dist/es/compile/path/index.d.ts +9 -3
  19. package/dist/es/compile/path/index.d.ts.map +1 -1
  20. package/dist/es/compile/path/index.js +17 -16
  21. package/dist/es/compile/path/relative.d.ts +10 -4
  22. package/dist/es/compile/path/relative.d.ts.map +1 -1
  23. package/dist/es/compile/path/relative.js +16 -8
  24. package/dist/es/compile/position.d.ts +19 -3
  25. package/dist/es/compile/position.d.ts.map +1 -1
  26. package/dist/es/compile/position.js +28 -8
  27. package/dist/es/compile/scope.d.ts +66 -0
  28. package/dist/es/compile/scope.d.ts.map +1 -0
  29. package/dist/es/compile/scope.js +256 -0
  30. package/dist/es/index.d.ts +2 -2
  31. package/dist/es/index.d.ts.map +1 -1
  32. package/dist/es/index.js +3 -1
  33. package/dist/es/ir/index.d.ts +2 -0
  34. package/dist/es/ir/index.d.ts.map +1 -1
  35. package/dist/es/ir/scene.d.ts +18 -3542
  36. package/dist/es/ir/scene.d.ts.map +1 -1
  37. package/dist/es/ir/scene.js +11 -3
  38. package/dist/es/ir/scope.d.ts +190 -0
  39. package/dist/es/ir/scope.d.ts.map +1 -0
  40. package/dist/es/ir/scope.js +29 -0
  41. package/dist/es/ir/transform.d.ts +204 -0
  42. package/dist/es/ir/transform.d.ts.map +1 -0
  43. package/dist/es/ir/transform.js +56 -0
  44. package/dist/lib/compile/anchor-cache.cjs +41 -0
  45. package/dist/lib/compile/anchor-cache.d.ts +12 -0
  46. package/dist/lib/compile/anchor-cache.d.ts.map +1 -0
  47. package/dist/lib/compile/compile.cjs +148 -40
  48. package/dist/lib/compile/compile.d.ts +2 -2
  49. package/dist/lib/compile/compile.d.ts.map +1 -1
  50. package/dist/lib/compile/index.d.ts +1 -0
  51. package/dist/lib/compile/index.d.ts.map +1 -1
  52. package/dist/lib/compile/name-stack.cjs +104 -0
  53. package/dist/lib/compile/name-stack.d.ts +81 -0
  54. package/dist/lib/compile/name-stack.d.ts.map +1 -0
  55. package/dist/lib/compile/node.cjs +13 -5
  56. package/dist/lib/compile/node.d.ts +8 -4
  57. package/dist/lib/compile/node.d.ts.map +1 -1
  58. package/dist/lib/compile/path/anchor.cjs +23 -12
  59. package/dist/lib/compile/path/anchor.d.ts +11 -5
  60. package/dist/lib/compile/path/anchor.d.ts.map +1 -1
  61. package/dist/lib/compile/path/index.cjs +17 -16
  62. package/dist/lib/compile/path/index.d.ts +9 -3
  63. package/dist/lib/compile/path/index.d.ts.map +1 -1
  64. package/dist/lib/compile/path/relative.cjs +16 -8
  65. package/dist/lib/compile/path/relative.d.ts +10 -4
  66. package/dist/lib/compile/path/relative.d.ts.map +1 -1
  67. package/dist/lib/compile/position.cjs +28 -8
  68. package/dist/lib/compile/position.d.ts +19 -3
  69. package/dist/lib/compile/position.d.ts.map +1 -1
  70. package/dist/lib/compile/scope.cjs +261 -0
  71. package/dist/lib/compile/scope.d.ts +66 -0
  72. package/dist/lib/compile/scope.d.ts.map +1 -0
  73. package/dist/lib/index.cjs +4 -0
  74. package/dist/lib/index.d.ts +2 -2
  75. package/dist/lib/index.d.ts.map +1 -1
  76. package/dist/lib/ir/index.d.ts +2 -0
  77. package/dist/lib/ir/index.d.ts.map +1 -1
  78. package/dist/lib/ir/scene.cjs +11 -3
  79. package/dist/lib/ir/scene.d.ts +18 -3542
  80. package/dist/lib/ir/scene.d.ts.map +1 -1
  81. package/dist/lib/ir/scope.cjs +30 -0
  82. package/dist/lib/ir/scope.d.ts +190 -0
  83. package/dist/lib/ir/scope.d.ts.map +1 -0
  84. package/dist/lib/ir/transform.cjs +56 -0
  85. package/dist/lib/ir/transform.d.ts +204 -0
  86. package/dist/lib/ir/transform.d.ts.map +1 -0
  87. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"scene.d.ts","sourceRoot":"","sources":["../../../src/ir/scene.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkBrB,CAAC;AAEJ,4CAA4C;AAC5C,MAAM,MAAM,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAE7C,qCAAqC;AACrC,eAAO,MAAM,kBAAkB,EAAG,CAAU,CAAC"}
1
+ {"version":3,"file":"scene.d.ts","sourceRoot":"","sources":["../../../src/ir/scene.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAoB,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,KAAK,MAAM,EAAc,MAAM,QAAQ,CAAC;AACjD,OAAO,EAAE,KAAK,MAAM,EAAc,MAAM,QAAQ,CAAC;AACjD,OAAO,EAAE,KAAK,OAAO,EAAsC,MAAM,SAAS,CAAC;AAE3E;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,YAAY,GAAG,OAAO,CAAC;AAE/D;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAM1C,CAAC;AAKF,eAAO,MAAM,WAAW;;;;;;;;;;;;EAkBrB,CAAC;AAEJ,4CAA4C;AAC5C,MAAM,MAAM,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAE7C,qCAAqC;AACrC,eAAO,MAAM,kBAAkB,EAAG,CAAU,CAAC"}
@@ -1,13 +1,21 @@
1
1
  import { PathSchema } from "./path/path.js";
2
2
  import { NodeSchema } from "./node.js";
3
3
  import { CoordinateSchema } from "./coordinate.js";
4
+ import { ScopeSchema, __registerChildSchema } from "./scope.js";
4
5
  import { z } from "zod";
5
6
  //#region src/ir/scene.ts
6
- var ChildSchema = z.discriminatedUnion("type", [
7
+ /**
8
+ * ChildSchema:4 类 IR 子节点的 discriminated union
9
+ * @description 用 `z.ZodType<IRChild>` + `z.lazy` 包裹整个 union 让 ScopeSchema.children 能递归引用自己;
10
+ * scope 内嵌 scope 无深度限制(与 polar/offset 嵌套规则一致)
11
+ */
12
+ var ChildSchema = z.lazy(() => z.discriminatedUnion("type", [
7
13
  NodeSchema,
8
14
  PathSchema,
9
- CoordinateSchema
10
- ]).describe("Top-level scene child: a node, a path, or a coordinate placeholder; discriminator field is `type`");
15
+ CoordinateSchema,
16
+ ScopeSchema
17
+ ]).describe("Top-level scene child: a node, a path, a coordinate placeholder, or a scope container; discriminator field is `type`"));
18
+ __registerChildSchema(ChildSchema);
11
19
  var SceneSchema = z.object({
12
20
  version: z.literal(1).describe("IR major version number; bump only on breaking schema changes"),
13
21
  type: z.literal("scene").describe("Discriminator marking this object as the root scene"),
@@ -0,0 +1,190 @@
1
+ import { z } from 'zod';
2
+ import { IRCoordinate } from './coordinate';
3
+ import { IRNode } from './node';
4
+ import { IRPath } from './path';
5
+ import { IRTransform } from './transform';
6
+ /**
7
+ * Scope IR 类型——手写而非 z.infer 派生
8
+ * @description ChildSchema 通过 z.lazy 延迟回灌,z.infer 推断 children 元素时拿不到精确的 IRNode | IRPath | IRCoordinate | IRScope union;手写让 children 类型显式表达递归 union
9
+ */
10
+ export type IRScope = {
11
+ type: 'scope';
12
+ id?: string;
13
+ localNamespace?: boolean;
14
+ transforms?: Array<IRTransform>;
15
+ children: Array<IRNode | IRPath | IRCoordinate | IRScope>;
16
+ };
17
+ /**
18
+ * 注册 ChildSchema 引用——由 scene.ts 在定义 ChildSchema 后调用一次
19
+ * @description 解决 scope.children 用 ChildSchema 与 scene.ChildSchema discriminatedUnion 用 ScopeSchema 的双向依赖
20
+ */
21
+ export declare const __registerChildSchema: (schema: z.ZodTypeAny) => void;
22
+ /**
23
+ * Scope schema:4 IRScope 字段
24
+ * @description 直接 `z.object` 让 ChildSchema discriminatedUnion 能识别 `type` 鉴别字段;
25
+ * children 字段内部用 z.lazy 引用 ChildSchema 实现递归,避免直接 `z.lazy(() => z.object(...))` 让外层 union 拒识 type
26
+ */
27
+ export declare const ScopeSchema: z.ZodObject<{
28
+ type: z.ZodLiteral<"scope">;
29
+ id: z.ZodOptional<z.ZodString>;
30
+ localNamespace: z.ZodOptional<z.ZodBoolean>;
31
+ transforms: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
32
+ kind: z.ZodLiteral<"translate">;
33
+ x: z.ZodNumber;
34
+ y: z.ZodNumber;
35
+ }, "strip", z.ZodTypeAny, {
36
+ kind: "translate";
37
+ x: number;
38
+ y: number;
39
+ }, {
40
+ kind: "translate";
41
+ x: number;
42
+ y: number;
43
+ }>, z.ZodObject<{
44
+ kind: z.ZodLiteral<"polar-translate">;
45
+ origin: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>, z.ZodType<import('./position').PolarPosition, z.ZodTypeDef, import('./position').PolarPosition>]>>;
46
+ angle: z.ZodNumber;
47
+ radius: z.ZodNumber;
48
+ }, "strip", z.ZodTypeAny, {
49
+ angle: number;
50
+ radius: number;
51
+ kind: "polar-translate";
52
+ origin?: string | [number, number] | import('./position').PolarPosition | undefined;
53
+ }, {
54
+ angle: number;
55
+ radius: number;
56
+ kind: "polar-translate";
57
+ origin?: string | [number, number] | import('./position').PolarPosition | undefined;
58
+ }>, z.ZodObject<{
59
+ kind: z.ZodLiteral<"at-translate">;
60
+ direction: z.ZodNativeEnum<{
61
+ readonly above: "above";
62
+ readonly below: "below";
63
+ readonly left: "left";
64
+ readonly right: "right";
65
+ readonly 'above-left': "above-left";
66
+ readonly 'above-right': "above-right";
67
+ readonly 'below-left': "below-left";
68
+ readonly 'below-right': "below-right";
69
+ }>;
70
+ of: z.ZodString;
71
+ distance: z.ZodOptional<z.ZodNumber>;
72
+ }, "strip", z.ZodTypeAny, {
73
+ direction: "above" | "below" | "left" | "right" | "above-left" | "above-right" | "below-left" | "below-right";
74
+ of: string;
75
+ kind: "at-translate";
76
+ distance?: number | undefined;
77
+ }, {
78
+ direction: "above" | "below" | "left" | "right" | "above-left" | "above-right" | "below-left" | "below-right";
79
+ of: string;
80
+ kind: "at-translate";
81
+ distance?: number | undefined;
82
+ }>, z.ZodObject<{
83
+ kind: z.ZodLiteral<"offset-translate">;
84
+ of: z.ZodUnion<[z.ZodString, z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>, z.ZodType<import('./position').PolarPosition, z.ZodTypeDef, import('./position').PolarPosition>]>;
85
+ offset: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
86
+ }, "strip", z.ZodTypeAny, {
87
+ of: string | [number, number] | import('./position').PolarPosition;
88
+ kind: "offset-translate";
89
+ offset?: [number, number] | undefined;
90
+ }, {
91
+ of: string | [number, number] | import('./position').PolarPosition;
92
+ kind: "offset-translate";
93
+ offset?: [number, number] | undefined;
94
+ }>, z.ZodObject<{
95
+ kind: z.ZodLiteral<"rotate">;
96
+ degrees: z.ZodNumber;
97
+ cx: z.ZodOptional<z.ZodNumber>;
98
+ cy: z.ZodOptional<z.ZodNumber>;
99
+ }, "strip", z.ZodTypeAny, {
100
+ kind: "rotate";
101
+ degrees: number;
102
+ cx?: number | undefined;
103
+ cy?: number | undefined;
104
+ }, {
105
+ kind: "rotate";
106
+ degrees: number;
107
+ cx?: number | undefined;
108
+ cy?: number | undefined;
109
+ }>, z.ZodObject<{
110
+ kind: z.ZodLiteral<"scale">;
111
+ x: z.ZodNumber;
112
+ y: z.ZodOptional<z.ZodNumber>;
113
+ }, "strip", z.ZodTypeAny, {
114
+ kind: "scale";
115
+ x: number;
116
+ y?: number | undefined;
117
+ }, {
118
+ kind: "scale";
119
+ x: number;
120
+ y?: number | undefined;
121
+ }>]>, "many">>;
122
+ children: z.ZodArray<z.ZodLazy<z.ZodTypeAny>, "many">;
123
+ }, "strip", z.ZodTypeAny, {
124
+ type: "scope";
125
+ children: any[];
126
+ id?: string | undefined;
127
+ localNamespace?: boolean | undefined;
128
+ transforms?: ({
129
+ kind: "translate";
130
+ x: number;
131
+ y: number;
132
+ } | {
133
+ angle: number;
134
+ radius: number;
135
+ kind: "polar-translate";
136
+ origin?: string | [number, number] | import('./position').PolarPosition | undefined;
137
+ } | {
138
+ direction: "above" | "below" | "left" | "right" | "above-left" | "above-right" | "below-left" | "below-right";
139
+ of: string;
140
+ kind: "at-translate";
141
+ distance?: number | undefined;
142
+ } | {
143
+ of: string | [number, number] | import('./position').PolarPosition;
144
+ kind: "offset-translate";
145
+ offset?: [number, number] | undefined;
146
+ } | {
147
+ kind: "rotate";
148
+ degrees: number;
149
+ cx?: number | undefined;
150
+ cy?: number | undefined;
151
+ } | {
152
+ kind: "scale";
153
+ x: number;
154
+ y?: number | undefined;
155
+ })[] | undefined;
156
+ }, {
157
+ type: "scope";
158
+ children: any[];
159
+ id?: string | undefined;
160
+ localNamespace?: boolean | undefined;
161
+ transforms?: ({
162
+ kind: "translate";
163
+ x: number;
164
+ y: number;
165
+ } | {
166
+ angle: number;
167
+ radius: number;
168
+ kind: "polar-translate";
169
+ origin?: string | [number, number] | import('./position').PolarPosition | undefined;
170
+ } | {
171
+ direction: "above" | "below" | "left" | "right" | "above-left" | "above-right" | "below-left" | "below-right";
172
+ of: string;
173
+ kind: "at-translate";
174
+ distance?: number | undefined;
175
+ } | {
176
+ of: string | [number, number] | import('./position').PolarPosition;
177
+ kind: "offset-translate";
178
+ offset?: [number, number] | undefined;
179
+ } | {
180
+ kind: "rotate";
181
+ degrees: number;
182
+ cx?: number | undefined;
183
+ cy?: number | undefined;
184
+ } | {
185
+ kind: "scale";
186
+ x: number;
187
+ y?: number | undefined;
188
+ })[] | undefined;
189
+ }>;
190
+ //# sourceMappingURL=scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../../src/ir/scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,KAAK,WAAW,EAAmB,MAAM,aAAa,CAAC;AAEhE;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,OAAO,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IAChC,QAAQ,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,YAAY,GAAG,OAAO,CAAC,CAAC;CAC3D,CAAC;AAOF;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAAI,QAAQ,CAAC,CAAC,UAAU,KAAG,IAE5D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyCrB,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { TransformSchema } from "./transform.js";
2
+ import { z } from "zod";
3
+ //#region src/ir/scope.ts
4
+ /** schema 注册顺序:scene.ts import 时由 __registerChildSchema 一次性回灌;之后只读 */
5
+ var childSchemaRef = null;
6
+ /**
7
+ * 注册 ChildSchema 引用——由 scene.ts 在定义 ChildSchema 后调用一次
8
+ * @description 解决 scope.children 用 ChildSchema 与 scene.ChildSchema discriminatedUnion 用 ScopeSchema 的双向依赖
9
+ */
10
+ var __registerChildSchema = (schema) => {
11
+ childSchemaRef = schema;
12
+ };
13
+ /**
14
+ * Scope schema:4 IRScope 字段
15
+ * @description 直接 `z.object` 让 ChildSchema discriminatedUnion 能识别 `type` 鉴别字段;
16
+ * children 字段内部用 z.lazy 引用 ChildSchema 实现递归,避免直接 `z.lazy(() => z.object(...))` 让外层 union 拒识 type
17
+ */
18
+ var ScopeSchema = z.object({
19
+ type: z.literal("scope").describe("Discriminator marking this child as a scope container."),
20
+ id: z.string().min(1).optional().describe("Optional reference id; when set, the scope registers a synthetic rectangle bbox node in the **parent** namespace frame so paths / positions can target the scope as a whole. scope.id always registers in the parent frame, regardless of `localNamespace` (it is the external handle)."),
21
+ localNamespace: z.boolean().optional().describe("When true, the scope creates a local namespace boundary — child node / coordinate / nested-scope ids registered inside do NOT propagate to the parent namespace; external lookups cannot see them. Default false (matches TikZ pgf default: child ids flow up to global). scope.id itself always registers in the parent frame regardless of this flag."),
22
+ transforms: z.array(TransformSchema).optional().describe("Local transforms applied to all scope children; array order = application order (first element applied innermost, matching Scene `GroupPrim.transforms` / SVG transform list). Supports 6 variants; the 4 translate variants are lowered to Cartesian translate at compile time."),
23
+ children: z.array(z.lazy(() => {
24
+ if (!childSchemaRef) throw new Error("ScopeSchema: ChildSchema not registered yet; ensure scene.ts loaded");
25
+ return childSchemaRef;
26
+ })).describe("Scope children: nested nodes / paths / coordinates / scopes. Recursive via the parent ChildSchema (registered late to break the IRChild <-> IRScope cycle).")
27
+ }).describe("Scope container: groups child IR elements and applies local transforms. Corresponds to TikZ `\\begin{scope}` (with optional `local bounding box=id` when id is set, and `name prefix`-like isolation when localNamespace is true).");
28
+ //#endregion
29
+ export { ScopeSchema, __registerChildSchema };
@@ -0,0 +1,204 @@
1
+ import { z } from 'zod';
2
+ declare const TranslateSchema: z.ZodObject<{
3
+ kind: z.ZodLiteral<"translate">;
4
+ x: z.ZodNumber;
5
+ y: z.ZodNumber;
6
+ }, "strip", z.ZodTypeAny, {
7
+ kind: "translate";
8
+ x: number;
9
+ y: number;
10
+ }, {
11
+ kind: "translate";
12
+ x: number;
13
+ y: number;
14
+ }>;
15
+ declare const PolarTranslateSchema: z.ZodObject<{
16
+ kind: z.ZodLiteral<"polar-translate">;
17
+ origin: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>, z.ZodType<import('./position').PolarPosition, z.ZodTypeDef, import('./position').PolarPosition>]>>;
18
+ angle: z.ZodNumber;
19
+ radius: z.ZodNumber;
20
+ }, "strip", z.ZodTypeAny, {
21
+ angle: number;
22
+ radius: number;
23
+ kind: "polar-translate";
24
+ origin?: string | [number, number] | import('./position').PolarPosition | undefined;
25
+ }, {
26
+ angle: number;
27
+ radius: number;
28
+ kind: "polar-translate";
29
+ origin?: string | [number, number] | import('./position').PolarPosition | undefined;
30
+ }>;
31
+ declare const AtTranslateSchema: z.ZodObject<{
32
+ kind: z.ZodLiteral<"at-translate">;
33
+ direction: z.ZodNativeEnum<{
34
+ readonly above: "above";
35
+ readonly below: "below";
36
+ readonly left: "left";
37
+ readonly right: "right";
38
+ readonly 'above-left': "above-left";
39
+ readonly 'above-right': "above-right";
40
+ readonly 'below-left': "below-left";
41
+ readonly 'below-right': "below-right";
42
+ }>;
43
+ of: z.ZodString;
44
+ distance: z.ZodOptional<z.ZodNumber>;
45
+ }, "strip", z.ZodTypeAny, {
46
+ direction: "above" | "below" | "left" | "right" | "above-left" | "above-right" | "below-left" | "below-right";
47
+ of: string;
48
+ kind: "at-translate";
49
+ distance?: number | undefined;
50
+ }, {
51
+ direction: "above" | "below" | "left" | "right" | "above-left" | "above-right" | "below-left" | "below-right";
52
+ of: string;
53
+ kind: "at-translate";
54
+ distance?: number | undefined;
55
+ }>;
56
+ declare const OffsetTranslateSchema: z.ZodObject<{
57
+ kind: z.ZodLiteral<"offset-translate">;
58
+ of: z.ZodUnion<[z.ZodString, z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>, z.ZodType<import('./position').PolarPosition, z.ZodTypeDef, import('./position').PolarPosition>]>;
59
+ offset: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
60
+ }, "strip", z.ZodTypeAny, {
61
+ of: string | [number, number] | import('./position').PolarPosition;
62
+ kind: "offset-translate";
63
+ offset?: [number, number] | undefined;
64
+ }, {
65
+ of: string | [number, number] | import('./position').PolarPosition;
66
+ kind: "offset-translate";
67
+ offset?: [number, number] | undefined;
68
+ }>;
69
+ declare const RotateSchema: z.ZodObject<{
70
+ kind: z.ZodLiteral<"rotate">;
71
+ degrees: z.ZodNumber;
72
+ cx: z.ZodOptional<z.ZodNumber>;
73
+ cy: z.ZodOptional<z.ZodNumber>;
74
+ }, "strip", z.ZodTypeAny, {
75
+ kind: "rotate";
76
+ degrees: number;
77
+ cx?: number | undefined;
78
+ cy?: number | undefined;
79
+ }, {
80
+ kind: "rotate";
81
+ degrees: number;
82
+ cx?: number | undefined;
83
+ cy?: number | undefined;
84
+ }>;
85
+ declare const ScaleSchema: z.ZodObject<{
86
+ kind: z.ZodLiteral<"scale">;
87
+ x: z.ZodNumber;
88
+ y: z.ZodOptional<z.ZodNumber>;
89
+ }, "strip", z.ZodTypeAny, {
90
+ kind: "scale";
91
+ x: number;
92
+ y?: number | undefined;
93
+ }, {
94
+ kind: "scale";
95
+ x: number;
96
+ y?: number | undefined;
97
+ }>;
98
+ export declare const TransformSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
99
+ kind: z.ZodLiteral<"translate">;
100
+ x: z.ZodNumber;
101
+ y: z.ZodNumber;
102
+ }, "strip", z.ZodTypeAny, {
103
+ kind: "translate";
104
+ x: number;
105
+ y: number;
106
+ }, {
107
+ kind: "translate";
108
+ x: number;
109
+ y: number;
110
+ }>, z.ZodObject<{
111
+ kind: z.ZodLiteral<"polar-translate">;
112
+ origin: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>, z.ZodType<import('./position').PolarPosition, z.ZodTypeDef, import('./position').PolarPosition>]>>;
113
+ angle: z.ZodNumber;
114
+ radius: z.ZodNumber;
115
+ }, "strip", z.ZodTypeAny, {
116
+ angle: number;
117
+ radius: number;
118
+ kind: "polar-translate";
119
+ origin?: string | [number, number] | import('./position').PolarPosition | undefined;
120
+ }, {
121
+ angle: number;
122
+ radius: number;
123
+ kind: "polar-translate";
124
+ origin?: string | [number, number] | import('./position').PolarPosition | undefined;
125
+ }>, z.ZodObject<{
126
+ kind: z.ZodLiteral<"at-translate">;
127
+ direction: z.ZodNativeEnum<{
128
+ readonly above: "above";
129
+ readonly below: "below";
130
+ readonly left: "left";
131
+ readonly right: "right";
132
+ readonly 'above-left': "above-left";
133
+ readonly 'above-right': "above-right";
134
+ readonly 'below-left': "below-left";
135
+ readonly 'below-right': "below-right";
136
+ }>;
137
+ of: z.ZodString;
138
+ distance: z.ZodOptional<z.ZodNumber>;
139
+ }, "strip", z.ZodTypeAny, {
140
+ direction: "above" | "below" | "left" | "right" | "above-left" | "above-right" | "below-left" | "below-right";
141
+ of: string;
142
+ kind: "at-translate";
143
+ distance?: number | undefined;
144
+ }, {
145
+ direction: "above" | "below" | "left" | "right" | "above-left" | "above-right" | "below-left" | "below-right";
146
+ of: string;
147
+ kind: "at-translate";
148
+ distance?: number | undefined;
149
+ }>, z.ZodObject<{
150
+ kind: z.ZodLiteral<"offset-translate">;
151
+ of: z.ZodUnion<[z.ZodString, z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>, z.ZodType<import('./position').PolarPosition, z.ZodTypeDef, import('./position').PolarPosition>]>;
152
+ offset: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
153
+ }, "strip", z.ZodTypeAny, {
154
+ of: string | [number, number] | import('./position').PolarPosition;
155
+ kind: "offset-translate";
156
+ offset?: [number, number] | undefined;
157
+ }, {
158
+ of: string | [number, number] | import('./position').PolarPosition;
159
+ kind: "offset-translate";
160
+ offset?: [number, number] | undefined;
161
+ }>, z.ZodObject<{
162
+ kind: z.ZodLiteral<"rotate">;
163
+ degrees: z.ZodNumber;
164
+ cx: z.ZodOptional<z.ZodNumber>;
165
+ cy: z.ZodOptional<z.ZodNumber>;
166
+ }, "strip", z.ZodTypeAny, {
167
+ kind: "rotate";
168
+ degrees: number;
169
+ cx?: number | undefined;
170
+ cy?: number | undefined;
171
+ }, {
172
+ kind: "rotate";
173
+ degrees: number;
174
+ cx?: number | undefined;
175
+ cy?: number | undefined;
176
+ }>, z.ZodObject<{
177
+ kind: z.ZodLiteral<"scale">;
178
+ x: z.ZodNumber;
179
+ y: z.ZodOptional<z.ZodNumber>;
180
+ }, "strip", z.ZodTypeAny, {
181
+ kind: "scale";
182
+ x: number;
183
+ y?: number | undefined;
184
+ }, {
185
+ kind: "scale";
186
+ x: number;
187
+ y?: number | undefined;
188
+ }>]>;
189
+ /** IR 层 transform 类型——6 变体 discriminated union(4 translate + rotate + scale) */
190
+ export type IRTransform = z.infer<typeof TransformSchema>;
191
+ /** 笛卡尔 translate 子分支 */
192
+ export type IRTranslateTransform = z.infer<typeof TranslateSchema>;
193
+ /** 极坐标 translate 子分支 */
194
+ export type IRPolarTranslateTransform = z.infer<typeof PolarTranslateSchema>;
195
+ /** 相对方向 translate 子分支 */
196
+ export type IRAtTranslateTransform = z.infer<typeof AtTranslateSchema>;
197
+ /** 偏移 translate 子分支 */
198
+ export type IROffsetTranslateTransform = z.infer<typeof OffsetTranslateSchema>;
199
+ /** 旋转子分支 */
200
+ export type IRRotateTransform = z.infer<typeof RotateSchema>;
201
+ /** 缩放子分支 */
202
+ export type IRScaleTransform = z.infer<typeof ScaleSchema>;
203
+ export {};
204
+ //# sourceMappingURL=transform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/ir/transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,QAAA,MAAM,eAAe;;;;;;;;;;;;EAYlB,CAAC;AAEJ,QAAA,MAAM,oBAAoB;;;;;;;;;;;;;;;EA0BvB,CAAC;AAEJ,QAAA,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;EAwBpB,CAAC;AAEJ,QAAA,MAAM,qBAAqB;;;;;;;;;;;;EAmBxB,CAAC;AAEJ,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;EAsBf,CAAC;AAEJ,QAAA,MAAM,WAAW;;;;;;;;;;;;EAqBd,CAAC;AAEJ,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAWzB,CAAC;AAEJ,gFAAgF;AAChF,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAC1D,wBAAwB;AACxB,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AACnE,wBAAwB;AACxB,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAC7E,yBAAyB;AACzB,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AACvE,uBAAuB;AACvB,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAC/E,YAAY;AACZ,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAC7D,YAAY;AACZ,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC"}
@@ -0,0 +1,56 @@
1
+ import { PositionSchema } from "./position/position.js";
2
+ import { PolarPositionSchema } from "./position/polar-position.js";
3
+ import { AT_DIRECTIONS } from "./position/at-position.js";
4
+ import { z } from "zod";
5
+ //#region src/ir/transform.ts
6
+ var TranslateSchema = z.object({
7
+ kind: z.literal("translate").describe("Discriminator: Cartesian translate (the 3-variant Scene transform shape)."),
8
+ x: z.number().describe("Cartesian x translation in user units."),
9
+ y: z.number().describe("Cartesian y translation in user units (screen y-down).")
10
+ }).describe("Cartesian translate transform; mirrors the Position [x, y] literal. Lowered directly to Scene `GroupPrim` translate.");
11
+ var PolarTranslateSchema = z.object({
12
+ kind: z.literal("polar-translate").describe("Discriminator: polar translate; mirrors PolarPosition."),
13
+ origin: z.union([
14
+ z.string().min(1),
15
+ PositionSchema,
16
+ PolarPositionSchema
17
+ ]).optional().describe("Origin reference (same union as PolarPosition.origin): node id string / Cartesian [x, y] / nested PolarPosition; omit = origin at (0, 0) so this acts as an absolute polar shift."),
18
+ angle: z.number().finite().describe("Angle in degrees; 0° = +x, 90° = +y (screen-down); matches PolarPosition.angle convention."),
19
+ radius: z.number().finite().describe("Radius / distance in user units; negative values are accepted (equivalent to angle + 180°).")
20
+ }).describe("Polar translate transform; mirrors PolarPosition. Lowered to Cartesian translate at compile time via resolvePosition.");
21
+ var AtTranslateSchema = z.object({
22
+ kind: z.literal("at-translate").describe("Discriminator: direction-relative translate; mirrors AtPosition."),
23
+ direction: z.nativeEnum(AT_DIRECTIONS).describe("Direction enum (8 values, shared with AtPosition.direction)."),
24
+ of: z.string().min(1).describe("Referent node id; must be defined earlier in the IR (forward references rejected, mirroring AtPosition.of)."),
25
+ distance: z.number().positive().optional().describe("Distance along direction in user units; omit → falls back to CompileOptions.nodeDistance (same default chain as AtPosition.distance).")
26
+ }).describe("Direction-relative translate transform; mirrors AtPosition. Lowered to Cartesian translate at compile time via resolvePosition.");
27
+ var OffsetTranslateSchema = z.object({
28
+ kind: z.literal("offset-translate").describe("Discriminator: offset-from-referent translate; mirrors OffsetPosition."),
29
+ of: z.union([
30
+ z.string().min(1),
31
+ PositionSchema,
32
+ PolarPositionSchema
33
+ ]).describe("Referent base point (same union as OffsetPosition.of): node id (forward references rejected) / Cartesian [x, y] / PolarPosition."),
34
+ offset: z.tuple([z.number().finite(), z.number().finite()]).optional().describe("Additional [dx, dy] offset in user units; omit = [0, 0] so the transform translates exactly to the referent.")
35
+ }).describe("Offset translate transform; mirrors OffsetPosition. Lowered to Cartesian translate at compile time via resolvePosition.");
36
+ var RotateSchema = z.object({
37
+ kind: z.literal("rotate").describe("Discriminator: rotation about a point."),
38
+ degrees: z.number().finite().describe("Rotation angle in degrees; positive = visually clockwise under screen y-down."),
39
+ cx: z.number().finite().optional().describe("Rotation center x in user units; omit = 0 (rotate about local origin)."),
40
+ cy: z.number().finite().optional().describe("Rotation center y in user units; omit = 0 (rotate about local origin).")
41
+ }).describe("Rotation transform; identical shape to Scene `RotateTransform`. Passed through to GroupPrim without further lowering.");
42
+ var ScaleSchema = z.object({
43
+ kind: z.literal("scale").describe("Discriminator: uniform / anisotropic scale."),
44
+ x: z.number().finite().describe("Scale factor on the x axis. Zero scale collapses the coordinate system and is not invertible — relative positions inside the scope degrade to the local origin (0, 0). Avoid zero in practice; use a tiny positive value if a \"near-invisible\" effect is desired."),
45
+ y: z.number().finite().optional().describe("Scale factor on the y axis; omit = x (uniform scaling). Zero scale falls back to (0, 0) for relative position inverse projection (see `x`).")
46
+ }).describe("Scale transform; identical shape to Scene `ScaleTransform`. Passed through to GroupPrim without further lowering.");
47
+ var TransformSchema = z.discriminatedUnion("kind", [
48
+ TranslateSchema,
49
+ PolarTranslateSchema,
50
+ AtTranslateSchema,
51
+ OffsetTranslateSchema,
52
+ RotateSchema,
53
+ ScaleSchema
54
+ ]).describe("IR-level transform; 6 variants. The 4 translate variants (translate / polar-translate / at-translate / offset-translate) mirror the Node.position union one-for-one; rotate and scale match the Scene `Transform` shape. At compile time the 4 translate variants are lowered to Cartesian translate via resolvePosition before being pushed onto the cumulative chain emitted to Scene `GroupPrim` (which stays at 3 variants).");
55
+ //#endregion
56
+ export { TransformSchema };
@@ -0,0 +1,41 @@
1
+ const require_node = require("./node.cjs");
2
+ //#region src/compile/anchor-cache.ts
3
+ /**
4
+ * (layout, anchorName) → IRPosition 缓存
5
+ * @description WeakMap 让 NodeLayout 引用一旦失效(compile 结束、NameStack 回收),对应 Map 自动 GC,无需手动 invalidate
6
+ */
7
+ var cache = /* @__PURE__ */ new WeakMap();
8
+ /** 角度字符串识别:可选负号 + 数字 + 可选小数;与 parseTarget.ts 的 ANGLE_RE 同语义 */
9
+ var ANGLE_RE = /^-?\d+(\.\d+)?$/;
10
+ /**
11
+ * 把 anchorName 解析到对应 shape 的 anchor / boundaryPoint 上
12
+ * @description 数字字符串走 angleBoundaryOf;其余按 RectAnchor 走 anchorOf
13
+ */
14
+ var computeAnchor = (layout, anchorName) => {
15
+ if (ANGLE_RE.test(anchorName)) return positionToIR(require_node.angleBoundaryOf(layout, Number(anchorName)));
16
+ return positionToIR(require_node.anchorOf(layout, anchorName));
17
+ };
18
+ /** geometry Position(含 readonly 形态)转 IRPosition 元组(IRPosition === [number, number]) */
19
+ var positionToIR = (p) => [p[0], p[1]];
20
+ /**
21
+ * 取节点 anchor 的全局坐标,带 per-layout 缓存
22
+ * @description name 接受 RectAnchor 关键字(如 `'north'` / `'south-west'`)或数字角度字符串(如 `'30'` / `'-45'`);
23
+ * 同一 (layout, name) 第二次起返回首调用结果的**同一引用**——上游可用 `===` 判定 cache 命中
24
+ * @param layout 已 Pass 1 完成的 NodeLayout(rect 已是全局坐标)
25
+ * @param anchorName 关键字或数字角度字符串
26
+ * @returns 全局坐标系下的 IRPosition `[x, y]`
27
+ */
28
+ var resolveAnchor = (layout, anchorName) => {
29
+ let layoutCache = cache.get(layout);
30
+ if (!layoutCache) {
31
+ layoutCache = /* @__PURE__ */ new Map();
32
+ cache.set(layout, layoutCache);
33
+ }
34
+ const cached = layoutCache.get(anchorName);
35
+ if (cached !== void 0) return cached;
36
+ const result = computeAnchor(layout, anchorName);
37
+ layoutCache.set(anchorName, result);
38
+ return result;
39
+ };
40
+ //#endregion
41
+ exports.resolveAnchor = resolveAnchor;
@@ -0,0 +1,12 @@
1
+ import { IRPosition } from '../ir';
2
+ import { NodeLayout } from './node';
3
+ /**
4
+ * 取节点 anchor 的全局坐标,带 per-layout 缓存
5
+ * @description name 接受 RectAnchor 关键字(如 `'north'` / `'south-west'`)或数字角度字符串(如 `'30'` / `'-45'`);
6
+ * 同一 (layout, name) 第二次起返回首调用结果的**同一引用**——上游可用 `===` 判定 cache 命中
7
+ * @param layout 已 Pass 1 完成的 NodeLayout(rect 已是全局坐标)
8
+ * @param anchorName 关键字或数字角度字符串
9
+ * @returns 全局坐标系下的 IRPosition `[x, y]`
10
+ */
11
+ export declare const resolveAnchor: (layout: NodeLayout, anchorName: string) => IRPosition;
12
+ //# sourceMappingURL=anchor-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anchor-cache.d.ts","sourceRoot":"","sources":["../../../src/compile/anchor-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAExC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AA4BzC;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,GACxB,QAAQ,UAAU,EAClB,YAAY,MAAM,KACjB,UAWF,CAAC"}