@retikz/core 0.2.0-alpha.2 → 0.2.0-alpha.4

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 (81) hide show
  1. package/dist/es/compile/compile.d.ts +8 -1
  2. package/dist/es/compile/compile.d.ts.map +1 -1
  3. package/dist/es/compile/compile.js +89 -14
  4. package/dist/es/compile/node.d.ts +19 -10
  5. package/dist/es/compile/node.d.ts.map +1 -1
  6. package/dist/es/compile/node.js +121 -207
  7. package/dist/es/compile/scope.d.ts.map +1 -1
  8. package/dist/es/compile/scope.js +3 -1
  9. package/dist/es/index.d.ts +3 -1
  10. package/dist/es/index.d.ts.map +1 -1
  11. package/dist/es/index.js +4 -2
  12. package/dist/es/ir/node.d.ts +45 -12
  13. package/dist/es/ir/node.d.ts.map +1 -1
  14. package/dist/es/ir/node.js +10 -3
  15. package/dist/es/ir/path/path.d.ts +3 -0
  16. package/dist/es/ir/path/path.d.ts.map +1 -1
  17. package/dist/es/ir/path/path.js +1 -0
  18. package/dist/es/ir/scope.d.ts +44 -22
  19. package/dist/es/ir/scope.d.ts.map +1 -1
  20. package/dist/es/ir/scope.js +5 -2
  21. package/dist/es/shapes/_shared.d.ts +7 -0
  22. package/dist/es/shapes/_shared.d.ts.map +1 -0
  23. package/dist/es/shapes/_shared.js +11 -0
  24. package/dist/es/shapes/circle.d.ts +8 -0
  25. package/dist/es/shapes/circle.d.ts.map +1 -0
  26. package/dist/es/shapes/circle.js +33 -0
  27. package/dist/es/shapes/diamond.d.ts +8 -0
  28. package/dist/es/shapes/diamond.d.ts.map +1 -0
  29. package/dist/es/shapes/diamond.js +65 -0
  30. package/dist/es/shapes/ellipse.d.ts +8 -0
  31. package/dist/es/shapes/ellipse.d.ts.map +1 -0
  32. package/dist/es/shapes/ellipse.js +45 -0
  33. package/dist/es/shapes/index.d.ts +14 -0
  34. package/dist/es/shapes/index.d.ts.map +1 -0
  35. package/dist/es/shapes/index.js +15 -0
  36. package/dist/es/shapes/rectangle.d.ts +8 -0
  37. package/dist/es/shapes/rectangle.d.ts.map +1 -0
  38. package/dist/es/shapes/rectangle.js +40 -0
  39. package/dist/es/shapes/types.d.ts +44 -0
  40. package/dist/es/shapes/types.d.ts.map +1 -0
  41. package/dist/lib/compile/compile.cjs +91 -16
  42. package/dist/lib/compile/compile.d.ts +8 -1
  43. package/dist/lib/compile/compile.d.ts.map +1 -1
  44. package/dist/lib/compile/node.cjs +121 -207
  45. package/dist/lib/compile/node.d.ts +19 -10
  46. package/dist/lib/compile/node.d.ts.map +1 -1
  47. package/dist/lib/compile/scope.cjs +3 -1
  48. package/dist/lib/compile/scope.d.ts.map +1 -1
  49. package/dist/lib/index.cjs +6 -1
  50. package/dist/lib/index.d.ts +3 -1
  51. package/dist/lib/index.d.ts.map +1 -1
  52. package/dist/lib/ir/node.cjs +10 -3
  53. package/dist/lib/ir/node.d.ts +45 -12
  54. package/dist/lib/ir/node.d.ts.map +1 -1
  55. package/dist/lib/ir/path/path.cjs +1 -0
  56. package/dist/lib/ir/path/path.d.ts +3 -0
  57. package/dist/lib/ir/path/path.d.ts.map +1 -1
  58. package/dist/lib/ir/scope.cjs +5 -2
  59. package/dist/lib/ir/scope.d.ts +44 -22
  60. package/dist/lib/ir/scope.d.ts.map +1 -1
  61. package/dist/lib/shapes/_shared.cjs +11 -0
  62. package/dist/lib/shapes/_shared.d.ts +7 -0
  63. package/dist/lib/shapes/_shared.d.ts.map +1 -0
  64. package/dist/lib/shapes/circle.cjs +33 -0
  65. package/dist/lib/shapes/circle.d.ts +8 -0
  66. package/dist/lib/shapes/circle.d.ts.map +1 -0
  67. package/dist/lib/shapes/diamond.cjs +65 -0
  68. package/dist/lib/shapes/diamond.d.ts +8 -0
  69. package/dist/lib/shapes/diamond.d.ts.map +1 -0
  70. package/dist/lib/shapes/ellipse.cjs +45 -0
  71. package/dist/lib/shapes/ellipse.d.ts +8 -0
  72. package/dist/lib/shapes/ellipse.d.ts.map +1 -0
  73. package/dist/lib/shapes/index.cjs +14 -0
  74. package/dist/lib/shapes/index.d.ts +14 -0
  75. package/dist/lib/shapes/index.d.ts.map +1 -0
  76. package/dist/lib/shapes/rectangle.cjs +40 -0
  77. package/dist/lib/shapes/rectangle.d.ts +8 -0
  78. package/dist/lib/shapes/rectangle.d.ts.map +1 -0
  79. package/dist/lib/shapes/types.d.ts +44 -0
  80. package/dist/lib/shapes/types.d.ts.map +1 -0
  81. package/package.json +1 -1
@@ -0,0 +1,65 @@
1
+ const require__shared = require("./_shared.cjs");
2
+ const require_diamond = require("../geometry/diamond.cjs");
3
+ //#region src/shapes/diamond.ts
4
+ /** 外接框 Rect → Diamond(halfA/halfB = 半宽/半高;顶点在 ±halfA / ±halfB) */
5
+ var toDiamond = (r) => ({
6
+ x: r.x,
7
+ y: r.y,
8
+ halfA: r.width / 2,
9
+ halfB: r.height / 2,
10
+ rotate: r.rotate
11
+ });
12
+ /**
13
+ * diamond 注册项
14
+ * @description circumscribe = 内框 ×2(内框 4 顶点落在菱形 4 边上);几何由外接框半轴派生;
15
+ * emit 在**轴对齐空间**取 4 顶点出 PathPrim(rotate 由外层 group 施加),与旧 `emitDiamondShape(unrotated(...))` 等价
16
+ */
17
+ var diamond = {
18
+ circumscribe: (hw, hh) => ({
19
+ halfWidth: hw * 2,
20
+ halfHeight: hh * 2
21
+ }),
22
+ boundaryPoint: (r, toward) => require_diamond.diamond.boundaryPoint(toDiamond(r), toward),
23
+ anchor: (r, name) => {
24
+ const a = require__shared.asRectAnchor(name);
25
+ return a ? require_diamond.diamond.anchor(toDiamond(r), a) : void 0;
26
+ },
27
+ *emit(r, style, round) {
28
+ const d = toDiamond(r);
29
+ const e = require_diamond.diamond.anchor(d, "east");
30
+ const n = require_diamond.diamond.anchor(d, "north");
31
+ const w = require_diamond.diamond.anchor(d, "west");
32
+ const s = require_diamond.diamond.anchor(d, "south");
33
+ yield {
34
+ type: "path",
35
+ commands: [
36
+ {
37
+ kind: "move",
38
+ to: [round(e[0]), round(e[1])]
39
+ },
40
+ {
41
+ kind: "line",
42
+ to: [round(n[0]), round(n[1])]
43
+ },
44
+ {
45
+ kind: "line",
46
+ to: [round(w[0]), round(w[1])]
47
+ },
48
+ {
49
+ kind: "line",
50
+ to: [round(s[0]), round(s[1])]
51
+ },
52
+ { kind: "close" }
53
+ ],
54
+ fill: style.fill ?? "transparent",
55
+ fillOpacity: style.fillOpacity,
56
+ stroke: style.stroke ?? "currentColor",
57
+ strokeOpacity: style.strokeOpacity,
58
+ strokeWidth: style.strokeWidth ?? 1,
59
+ dashPattern: style.dashPattern,
60
+ opacity: style.opacity
61
+ };
62
+ }
63
+ };
64
+ //#endregion
65
+ exports.diamond = diamond;
@@ -0,0 +1,8 @@
1
+ import { ShapeDefinition } from './types';
2
+ /**
3
+ * diamond 注册项
4
+ * @description circumscribe = 内框 ×2(内框 4 顶点落在菱形 4 边上);几何由外接框半轴派生;
5
+ * emit 在**轴对齐空间**取 4 顶点出 PathPrim(rotate 由外层 group 施加),与旧 `emitDiamondShape(unrotated(...))` 等价
6
+ */
7
+ export declare const diamond: ShapeDefinition;
8
+ //# sourceMappingURL=diamond.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diamond.d.ts","sourceRoot":"","sources":["../../../src/shapes/diamond.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAW/C;;;;GAIG;AACH,eAAO,MAAM,OAAO,EAAE,eA+BrB,CAAC"}
@@ -0,0 +1,45 @@
1
+ const require_ellipse = require("../geometry/ellipse.cjs");
2
+ const require__shared = require("./_shared.cjs");
3
+ //#region src/shapes/ellipse.ts
4
+ /** 外接框 Rect → Ellipse(rx/ry = 半宽/半高) */
5
+ var toEllipse = (r) => ({
6
+ x: r.x,
7
+ y: r.y,
8
+ rx: r.width / 2,
9
+ ry: r.height / 2,
10
+ rotate: r.rotate
11
+ });
12
+ /**
13
+ * ellipse 注册项
14
+ * @description circumscribe = 内框 ×√2(内框 4 顶点落在椭圆周上);几何由外接框半轴派生;
15
+ * emit 出 EllipsePrim,与旧 `emitEllipseShape` 逐字段等价
16
+ */
17
+ var ellipse = {
18
+ circumscribe: (hw, hh) => ({
19
+ halfWidth: hw * Math.SQRT2,
20
+ halfHeight: hh * Math.SQRT2
21
+ }),
22
+ boundaryPoint: (r, toward) => require_ellipse.ellipse.boundaryPoint(toEllipse(r), toward),
23
+ anchor: (r, name) => {
24
+ const a = require__shared.asRectAnchor(name);
25
+ return a ? require_ellipse.ellipse.anchor(toEllipse(r), a) : void 0;
26
+ },
27
+ *emit(r, style, round) {
28
+ yield {
29
+ type: "ellipse",
30
+ cx: round(r.x),
31
+ cy: round(r.y),
32
+ rx: round(r.width / 2),
33
+ ry: round(r.height / 2),
34
+ fill: style.fill ?? "transparent",
35
+ fillOpacity: style.fillOpacity,
36
+ stroke: style.stroke ?? "currentColor",
37
+ strokeOpacity: style.strokeOpacity,
38
+ strokeWidth: style.strokeWidth ?? 1,
39
+ dashPattern: style.dashPattern,
40
+ opacity: style.opacity
41
+ };
42
+ }
43
+ };
44
+ //#endregion
45
+ exports.ellipse = ellipse;
@@ -0,0 +1,8 @@
1
+ import { ShapeDefinition } from './types';
2
+ /**
3
+ * ellipse 注册项
4
+ * @description circumscribe = 内框 ×√2(内框 4 顶点落在椭圆周上);几何由外接框半轴派生;
5
+ * emit 出 EllipsePrim,与旧 `emitEllipseShape` 逐字段等价
6
+ */
7
+ export declare const ellipse: ShapeDefinition;
8
+ //# sourceMappingURL=ellipse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ellipse.d.ts","sourceRoot":"","sources":["../../../src/shapes/ellipse.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAW/C;;;;GAIG;AACH,eAAO,MAAM,OAAO,EAAE,eAuBrB,CAAC"}
@@ -0,0 +1,14 @@
1
+ require("../geometry/_transform.cjs");
2
+ const require_ellipse = require("./ellipse.cjs");
3
+ const require_circle = require("./circle.cjs");
4
+ const require_diamond = require("./diamond.cjs");
5
+ //#region src/shapes/index.ts
6
+ /** 内置 4 shape 注册项;与 `CompileOptions.shapes` 合并时被同名注入覆盖 */
7
+ var BUILTIN_SHAPES = {
8
+ rectangle: require("./rectangle.cjs").rectangle,
9
+ circle: require_circle.circle,
10
+ ellipse: require_ellipse.ellipse,
11
+ diamond: require_diamond.diamond
12
+ };
13
+ //#endregion
14
+ exports.BUILTIN_SHAPES = BUILTIN_SHAPES;
@@ -0,0 +1,14 @@
1
+ import { BuiltinShapeName } from '../ir/node';
2
+ import { circle } from './circle';
3
+ import { diamond } from './diamond';
4
+ import { ellipse } from './ellipse';
5
+ import { rectangle } from './rectangle';
6
+ import { ShapeDefinition } from './types';
7
+ /** 内置 4 shape 注册项;与 `CompileOptions.shapes` 合并时被同名注入覆盖 */
8
+ export declare const BUILTIN_SHAPES: Record<BuiltinShapeName, ShapeDefinition>;
9
+ export { rectangle, circle, ellipse, diamond };
10
+ export type { ShapeDefinition, ShapeStyle } from './types';
11
+ export type { Rect } from '../geometry/rect';
12
+ export type { Position } from '../geometry/point';
13
+ export { worldToLocal, localToWorld } from '../geometry/_transform';
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/shapes/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,0DAA0D;AAC1D,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,gBAAgB,EAAE,eAAe,CAKpE,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAC/C,YAAY,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE3D,YAAY,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,YAAY,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,40 @@
1
+ const require_rect = require("../geometry/rect.cjs");
2
+ const require__shared = require("./_shared.cjs");
3
+ //#region src/shapes/rectangle.ts
4
+ /**
5
+ * rectangle 注册项
6
+ * @description circumscribe = identity(视觉边界 = 内框);boundaryPoint / anchor 直接走 rect 数学层;
7
+ * emit 出 RectPrim(圆角走 cornerRadius),与旧 `emitRectShape` 逐字段等价
8
+ */
9
+ var rectangle = {
10
+ circumscribe: (hw, hh) => ({
11
+ halfWidth: hw,
12
+ halfHeight: hh
13
+ }),
14
+ boundaryPoint: (r, toward) => require_rect.rect.boundaryPoint(r, toward),
15
+ anchor: (r, name) => {
16
+ const a = require__shared.asRectAnchor(name);
17
+ return a ? require_rect.rect.anchor(r, a) : void 0;
18
+ },
19
+ *emit(r, style, round) {
20
+ const halfW = r.width / 2;
21
+ const halfH = r.height / 2;
22
+ yield {
23
+ type: "rect",
24
+ x: round(r.x - halfW),
25
+ y: round(r.y - halfH),
26
+ width: round(r.width),
27
+ height: round(r.height),
28
+ fill: style.fill ?? "transparent",
29
+ fillOpacity: style.fillOpacity,
30
+ stroke: style.stroke ?? "currentColor",
31
+ strokeOpacity: style.strokeOpacity,
32
+ strokeWidth: style.strokeWidth ?? 1,
33
+ dashPattern: style.dashPattern,
34
+ cornerRadius: style.roundedCorners,
35
+ opacity: style.opacity
36
+ };
37
+ }
38
+ };
39
+ //#endregion
40
+ exports.rectangle = rectangle;
@@ -0,0 +1,8 @@
1
+ import { ShapeDefinition } from './types';
2
+ /**
3
+ * rectangle 注册项
4
+ * @description circumscribe = identity(视觉边界 = 内框);boundaryPoint / anchor 直接走 rect 数学层;
5
+ * emit 出 RectPrim(圆角走 cornerRadius),与旧 `emitRectShape` 逐字段等价
6
+ */
7
+ export declare const rectangle: ShapeDefinition;
8
+ //# sourceMappingURL=rectangle.d.ts.map
@@ -0,0 +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,eA0BvB,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { Position } from '../geometry/point';
2
+ import { Rect } from '../geometry/rect';
3
+ import { ScenePrimitive } from '../primitive';
4
+ /**
5
+ * emit 需要的视觉样式子集
6
+ * @description 从 NodeLayout 的样式字段收敛(不含几何 / 文本);独立 type,不耦合内部 NodeLayout。
7
+ * 字段名与 NodeLayout 样式字段一致(单一词汇表)。
8
+ */
9
+ export type ShapeStyle = {
10
+ fill?: string;
11
+ fillOpacity?: number;
12
+ stroke?: string;
13
+ strokeOpacity?: number;
14
+ strokeWidth?: number;
15
+ dashPattern?: Array<number>;
16
+ roundedCorners?: number;
17
+ opacity?: number;
18
+ };
19
+ /**
20
+ * 一个 shape 的可注册定义:外接 / 边界 / anchor / emit 四件事
21
+ * @description plain object(factory 友好:`createPolygonShape(6)` 这类普通函数返回它即可);含函数、
22
+ * **不进 IR**,走 `CompileOptions.shapes` 运行时注入。内置 4 shape 也是注册项(无内置特权)。
23
+ *
24
+ * 坐标语义两套,第三方最易写错:
25
+ * - `boundaryPoint` / `anchor` 收**带 `rotate` 的 Rect**——用 re-export 的 `worldToLocal` / `localToWorld` 写局部系几何。
26
+ * - `emit` 收**轴对齐 Rect(rotate=0)**——旋转由编译器在外层 `GroupPrim` 统一施加。
27
+ */
28
+ export type ShapeDefinition = {
29
+ /**
30
+ * 外接:内容半轴(text + padding)→ 外接框半轴。
31
+ * @description rectangle: identity;circle: √(hw²+hh²) 两轴相等;ellipse: ×√2;diamond: ×2。
32
+ */
33
+ circumscribe: (innerHalfWidth: number, innerHalfHeight: number) => {
34
+ halfWidth: number;
35
+ halfHeight: number;
36
+ };
37
+ /** 中心 → toward 射线 ∩ 边界(rect 带 rotate)。 */
38
+ boundaryPoint: (rect: Rect, toward: Position) => Position;
39
+ /** 命名 anchor 世界坐标;shape 不认识的名字返回 `undefined`(调用方据此抛清晰错误)。 */
40
+ anchor: (rect: Rect, name: string) => Position | undefined;
41
+ /** 视觉 primitive,**轴对齐空间**(rotate 由编译器外层 GroupPrim 统一施加)。 */
42
+ emit: (rect: Rect, style: ShapeStyle, round: (n: number) => number) => Iterable<ScenePrimitive>;
43
+ };
44
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +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,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,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,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retikz/core",
3
- "version": "0.2.0-alpha.2",
3
+ "version": "0.2.0-alpha.4",
4
4
  "description": "retikz v0.1 core: framework-agnostic IR, scene compiler, and pure parsers.",
5
5
  "type": "module",
6
6
  "author": "Pionpill",