@motionscript/patterns 0.0.0-stage → 0.1.0-alpha.10

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 (73) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +49 -0
  4. package/README.md +82 -2
  5. package/dist/browser/chunks/chunk-FXDYEY4R.js +2 -0
  6. package/dist/browser/chunks/chunk-FXDYEY4R.js.map +7 -0
  7. package/dist/browser/index.js +2 -0
  8. package/dist/browser/index.js.map +7 -0
  9. package/dist/browser/kit.js +2 -0
  10. package/dist/browser/kit.js.map +7 -0
  11. package/dist/browser/manifest.json +13 -0
  12. package/dist/dot-grid-pattern/dot-grid-pattern.d.ts +118 -0
  13. package/dist/dot-grid-pattern/dot-grid-pattern.d.ts.map +1 -0
  14. package/dist/dot-grid-pattern/dot-grid-pattern.js +89 -0
  15. package/dist/dot-grid-pattern/dot-grid-pattern.js.map +1 -0
  16. package/dist/dot-grid-pattern/index.d.ts +2 -0
  17. package/dist/dot-grid-pattern/index.d.ts.map +1 -0
  18. package/dist/dot-grid-pattern/index.js +2 -0
  19. package/dist/dot-grid-pattern/index.js.map +1 -0
  20. package/dist/engine.d.ts +12 -0
  21. package/dist/engine.d.ts.map +1 -0
  22. package/dist/engine.js +12 -0
  23. package/dist/engine.js.map +1 -0
  24. package/dist/grid-pattern/grid-pattern.d.ts +94 -0
  25. package/dist/grid-pattern/grid-pattern.d.ts.map +1 -0
  26. package/dist/grid-pattern/grid-pattern.js +119 -0
  27. package/dist/grid-pattern/grid-pattern.js.map +1 -0
  28. package/dist/grid-pattern/index.d.ts +2 -0
  29. package/dist/grid-pattern/index.d.ts.map +1 -0
  30. package/dist/grid-pattern/index.js +2 -0
  31. package/dist/grid-pattern/index.js.map +1 -0
  32. package/dist/index.d.ts +6 -0
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.js +6 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/kit/grid-lines.d.ts +111 -0
  37. package/dist/kit/grid-lines.d.ts.map +1 -0
  38. package/dist/kit/grid-lines.js +148 -0
  39. package/dist/kit/grid-lines.js.map +1 -0
  40. package/dist/kit/index.d.ts +3 -0
  41. package/dist/kit/index.d.ts.map +1 -0
  42. package/dist/kit/index.js +3 -0
  43. package/dist/kit/index.js.map +1 -0
  44. package/dist/kit/viewport-pattern.d.ts +81 -0
  45. package/dist/kit/viewport-pattern.d.ts.map +1 -0
  46. package/dist/kit/viewport-pattern.js +74 -0
  47. package/dist/kit/viewport-pattern.js.map +1 -0
  48. package/dist/line-grid-pattern/index.d.ts +2 -0
  49. package/dist/line-grid-pattern/index.d.ts.map +1 -0
  50. package/dist/line-grid-pattern/index.js +2 -0
  51. package/dist/line-grid-pattern/index.js.map +1 -0
  52. package/dist/line-grid-pattern/line-grid-pattern.d.ts +93 -0
  53. package/dist/line-grid-pattern/line-grid-pattern.d.ts.map +1 -0
  54. package/dist/line-grid-pattern/line-grid-pattern.js +71 -0
  55. package/dist/line-grid-pattern/line-grid-pattern.js.map +1 -0
  56. package/dist/nodes.d.ts +19 -0
  57. package/dist/nodes.d.ts.map +1 -0
  58. package/dist/nodes.js +9 -0
  59. package/dist/nodes.js.map +1 -0
  60. package/package.json +73 -3
  61. package/registry.json +26 -0
  62. package/src/dot-grid-pattern/dot-grid-pattern.ts +155 -0
  63. package/src/dot-grid-pattern/index.ts +1 -0
  64. package/src/engine.ts +11 -0
  65. package/src/grid-pattern/grid-pattern.ts +176 -0
  66. package/src/grid-pattern/index.ts +1 -0
  67. package/src/index.ts +5 -0
  68. package/src/kit/grid-lines.ts +223 -0
  69. package/src/kit/index.ts +2 -0
  70. package/src/kit/viewport-pattern.ts +109 -0
  71. package/src/line-grid-pattern/index.ts +1 -0
  72. package/src/line-grid-pattern/line-grid-pattern.ts +117 -0
  73. package/src/nodes.ts +27 -0
@@ -0,0 +1,118 @@
1
+ import { type NodeOf, type Vector2, type Alignment as _Alignment, type Fill as _Fill, type FillResolved as _FillResolved, type FlowMode as _FlowMode, type FlowResolved as _FlowResolved, type GapSize as _GapSize, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Shadow as _Shadow, type ShadowResolved as _ShadowResolved, type Stroke as _Stroke, type StrokeResolved as _StrokeResolved } from "@motionscript/sdk";
2
+ /**
3
+ * A field of dots on the same `divisions` / `subdivisions` / `offset` as
4
+ * `LineGridPattern`, so laid over one the dots sit on its intersections.
5
+ *
6
+ * The silhouette is the dots, which `Paint.draw` paints with `shadow`, `fill`,
7
+ * `overlay` and `stroke`. A dot grid has no "paper": a rectangle behind it is how
8
+ * it gets a background.
9
+ *
10
+ * What `clip` confines the children to, and what picking tests, is the node's
11
+ * box rather than the silhouette, which clips outer dots as they pan out and
12
+ * keeps the node selectable between dots. `start` / `end` act on nothing:
13
+ * trimming a disc leaves a crescent, not a partial grid.
14
+ */
15
+ export declare const DotGridPattern: import("@motionscript/sdk").Component<"dotGridPattern", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
16
+ /** Cells along each axis, as in `LineGridPattern.divisions`: 4 puts 5 major dots on each axis. */
17
+ divisions: number;
18
+ /** Splits each division again. `1` draws only the major dots; `2` puts one minor dot between each pair. */
19
+ subdivisions: number;
20
+ /** Radius of a major dot. */
21
+ radius: number;
22
+ /**
23
+ * A minor dot's radius as a fraction of a major one's. A fraction rather than a
24
+ * second paint stack, so the whole field stays one fill and a gradient crosses
25
+ * every dot in it.
26
+ */
27
+ subScale: number;
28
+ /** Pans the field, as `LineGridPattern.offset` does, so the two stay aligned while both scroll. */
29
+ offset: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
30
+ flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
31
+ gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
32
+ wrap: boolean;
33
+ crossGap: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
34
+ columns: import("@motionscript/sdk").Type<number, number, false>;
35
+ align: import("@motionscript/sdk").Attribute<_Alignment, Vector2>;
36
+ fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
37
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
38
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
39
+ overlay: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
40
+ start: import("@motionscript/sdk").Type<number, number, false>;
41
+ end: import("@motionscript/sdk").Type<number, number, false>;
42
+ }>, {
43
+ readonly fillTo: readonly ["fill"];
44
+ readonly strokeTo: readonly ["stroke"];
45
+ readonly shadowTo: readonly ["shadow"];
46
+ readonly overlayTo: readonly ["overlay"];
47
+ readonly progressTo: readonly ["start", "end"];
48
+ readonly flash: {
49
+ readonly portion: import("@motionscript/sdk").Type<number, number, false>;
50
+ };
51
+ }, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
52
+ /** Cells along each axis, as in `LineGridPattern.divisions`: 4 puts 5 major dots on each axis. */
53
+ divisions: number;
54
+ /** Splits each division again. `1` draws only the major dots; `2` puts one minor dot between each pair. */
55
+ subdivisions: number;
56
+ /** Radius of a major dot. */
57
+ radius: number;
58
+ /**
59
+ * A minor dot's radius as a fraction of a major one's. A fraction rather than a
60
+ * second paint stack, so the whole field stays one fill and a gradient crosses
61
+ * every dot in it.
62
+ */
63
+ subScale: number;
64
+ /** Pans the field, as `LineGridPattern.offset` does, so the two stay aligned while both scroll. */
65
+ offset: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
66
+ flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
67
+ gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
68
+ wrap: boolean;
69
+ crossGap: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
70
+ columns: import("@motionscript/sdk").Type<number, number, false>;
71
+ align: import("@motionscript/sdk").Attribute<_Alignment, Vector2>;
72
+ fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
73
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
74
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
75
+ overlay: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
76
+ start: import("@motionscript/sdk").Type<number, number, false>;
77
+ end: import("@motionscript/sdk").Type<number, number, false>;
78
+ }>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
79
+ /** Cells along each axis, as in `LineGridPattern.divisions`: 4 puts 5 major dots on each axis. */
80
+ divisions: number;
81
+ /** Splits each division again. `1` draws only the major dots; `2` puts one minor dot between each pair. */
82
+ subdivisions: number;
83
+ /** Radius of a major dot. */
84
+ radius: number;
85
+ /**
86
+ * A minor dot's radius as a fraction of a major one's. A fraction rather than a
87
+ * second paint stack, so the whole field stays one fill and a gradient crosses
88
+ * every dot in it.
89
+ */
90
+ subScale: number;
91
+ /** Pans the field, as `LineGridPattern.offset` does, so the two stay aligned while both scroll. */
92
+ offset: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
93
+ flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
94
+ gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
95
+ wrap: boolean;
96
+ crossGap: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
97
+ columns: import("@motionscript/sdk").Type<number, number, false>;
98
+ align: import("@motionscript/sdk").Attribute<_Alignment, Vector2>;
99
+ fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
100
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
101
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
102
+ overlay: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
103
+ start: import("@motionscript/sdk").Type<number, number, false>;
104
+ end: import("@motionscript/sdk").Type<number, number, false>;
105
+ }>, {
106
+ readonly fillTo: readonly ["fill"];
107
+ readonly strokeTo: readonly ["stroke"];
108
+ readonly shadowTo: readonly ["shadow"];
109
+ readonly overlayTo: readonly ["overlay"];
110
+ readonly progressTo: readonly ["start", "end"];
111
+ readonly flash: {
112
+ readonly portion: import("@motionscript/sdk").Type<number, number, false>;
113
+ };
114
+ }, _Node2D<_Node2DProps>>>>;
115
+ export type DotGridPattern = NodeOf<typeof DotGridPattern>;
116
+ /** What a call or a document row may set. */
117
+ export type DotGridPatternProps = NonNullable<Parameters<typeof DotGridPattern>[0]>;
118
+ //# sourceMappingURL=dot-grid-pattern.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dot-grid-pattern.d.ts","sourceRoot":"","sources":["../../src/dot-grid-pattern/dot-grid-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,MAAM,EAEX,KAAK,OAAO,EAEZ,KAAK,SAAS,IAAI,UAAU,EAC5B,KAAK,IAAI,IAAI,KAAK,EAClB,KAAK,YAAY,IAAI,aAAa,EAClC,KAAK,QAAQ,IAAI,SAAS,EAC1B,KAAK,YAAY,IAAI,aAAa,EAClC,KAAK,OAAO,IAAI,QAAQ,EACxB,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,IAAI,YAAY,EAChC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACtC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACvC,MAAM,mBAAmB,CAAA;AAsD1B;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,cAAc;IArCzB,kGAAkG;;IAElG,2GAA2G;;IAE3G,6BAA6B;;IAE7B;;;;OAIG;;IAEH,mGAAmG;;;;;;;;;;;;;;;;;;;;;;;;IAZnG,kGAAkG;;IAElG,2GAA2G;;IAE3G,6BAA6B;;IAE7B;;;;OAIG;;IAEH,mGAAmG;;;;;;;;;;;;;;;IAZnG,kGAAkG;;IAElG,2GAA2G;;IAE3G,6BAA6B;;IAE7B;;;;OAIG;;IAEH,mGAAmG;;;;;;;;;;;;;;;;;;;;;;;2BAsCnG,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,cAAc,CAAC,CAAA;AAC1D,6CAA6C;AAC7C,MAAM,MAAM,mBAAmB,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA"}
@@ -0,0 +1,89 @@
1
+ import { Flow, Graphics2D, Paint, Types, component2d, lerpVector2, } from "@motionscript/sdk";
2
+ import { addTiledLines } from "../kit/index.js";
3
+ // Calls the tiling `LineGridPattern` uses, so dots stay on its intersections at every offset.
4
+ function gridPositions(min, max, step, offset, subdivisions, overscan) {
5
+ const out = [];
6
+ // Anchored at the near edge, so a column or row sits on each edge of the box for any count of cells.
7
+ addTiledLines(min, max, step, offset, subdivisions, overscan, (pos, isMajor) => {
8
+ out.push({ pos, isMajor });
9
+ }, min);
10
+ return out;
11
+ }
12
+ const state = {
13
+ ...Paint.state,
14
+ ...Flow.state,
15
+ /** Cells along each axis, as in `LineGridPattern.divisions`: 4 puts 5 major dots on each axis. */
16
+ divisions: 4,
17
+ /** Splits each division again. `1` draws only the major dots; `2` puts one minor dot between each pair. */
18
+ subdivisions: 1,
19
+ /** Radius of a major dot. */
20
+ radius: 3,
21
+ /**
22
+ * A minor dot's radius as a fraction of a major one's. A fraction rather than a
23
+ * second paint stack, so the whole field stays one fill and a gradient crosses
24
+ * every dot in it.
25
+ */
26
+ subScale: 0.5,
27
+ /** Pans the field, as `LineGridPattern.offset` does, so the two stay aligned while both scroll. */
28
+ offset: Types.custom({ x: 0, y: 0 }, { lerp: lerpVector2 }),
29
+ };
30
+ /**
31
+ * A field of dots on the same `divisions` / `subdivisions` / `offset` as
32
+ * `LineGridPattern`, so laid over one the dots sit on its intersections.
33
+ *
34
+ * The silhouette is the dots, which `Paint.draw` paints with `shadow`, `fill`,
35
+ * `overlay` and `stroke`. A dot grid has no "paper": a rectangle behind it is how
36
+ * it gets a background.
37
+ *
38
+ * What `clip` confines the children to, and what picking tests, is the node's
39
+ * box rather than the silhouette, which clips outer dots as they pan out and
40
+ * keeps the node selectable between dots. `start` / `end` act on nothing:
41
+ * trimming a disc leaves a crescent, not a partial grid.
42
+ */
43
+ export const DotGridPattern = component2d({
44
+ key: "dotGridPattern",
45
+ state,
46
+ commands: { ...Paint.commands },
47
+ measure: (measurer, state, children) => Flow.measure(measurer, state, children, Paint.inset(state)),
48
+ layout: (box, state, children) => Flow.layout(box, state, children, Paint.inset(state)),
49
+ render: (ctx, state) => {
50
+ const untrimmed = {
51
+ fill: state.fill, stroke: state.stroke, shadow: state.shadow, overlay: state.overlay, start: 0, end: 1, clip: state.clip,
52
+ };
53
+ const box = new Graphics2D().rect({ width: ctx.size.width, height: ctx.size.height });
54
+ Paint.draw(ctx, untrimmed, dots(ctx.size, state), { clipShape: box });
55
+ },
56
+ });
57
+ /** Every dot in the field as one un-painted union: the paint stacks belong to the grid, not to a dot. */
58
+ function dots(size, s) {
59
+ const { width, height } = size;
60
+ if (width <= 0 || height <= 0)
61
+ return null;
62
+ const divisions = Math.max(1, Math.floor(s.divisions));
63
+ const subdivisions = Math.max(1, Math.floor(s.subdivisions));
64
+ const major = Math.max(0, s.radius);
65
+ const minor = major * Math.max(0, s.subScale);
66
+ if (major <= 0 && minor <= 0)
67
+ return null;
68
+ // Inset by a dot's radius so an edge dot sits inside the box rather than being halved by the clip.
69
+ const cols = divisions * subdivisions;
70
+ const insetX = Math.max(0, width / 2 - major);
71
+ const insetY = Math.max(0, height / 2 - major);
72
+ const xs = gridPositions(-insetX, insetX, (insetX * 2) / cols, s.offset.x, subdivisions, major);
73
+ const ys = gridPositions(-insetY, insetY, (insetY * 2) / cols, s.offset.y, subdivisions, major);
74
+ const field = new Graphics2D();
75
+ let drew = false;
76
+ for (const column of xs) {
77
+ for (const row of ys) {
78
+ // A dot is major only where *both* axes are — an intersection of two
79
+ // major rules, which is exactly the point a line grid draws heaviest.
80
+ const size = column.isMajor && row.isMajor ? major : minor;
81
+ if (size <= 0)
82
+ continue;
83
+ field.ellipse({ x: column.pos, y: row.pos, width: size * 2, height: size * 2 });
84
+ drew = true;
85
+ }
86
+ }
87
+ return drew ? field : null;
88
+ }
89
+ //# sourceMappingURL=dot-grid-pattern.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dot-grid-pattern.js","sourceRoot":"","sources":["../../src/dot-grid-pattern/dot-grid-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,UAAU,EACV,KAAK,EACL,KAAK,EACL,WAAW,EACX,WAAW,GAiBZ,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAQtC,8FAA8F;AAC9F,SAAS,aAAa,CACpB,GAAW,EACX,GAAW,EACX,IAAY,EACZ,MAAc,EACd,YAAoB,EACpB,QAAgB;IAEhB,MAAM,GAAG,GAAmB,EAAE,CAAA;IAC9B,qGAAqG;IACrG,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE;QAC7E,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAA;IAC5B,CAAC,EAAE,GAAG,CAAC,CAAA;IACP,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,MAAM,KAAK,GAAG;IACZ,GAAG,KAAK,CAAC,KAAK;IACd,GAAG,IAAI,CAAC,KAAK;IACb,kGAAkG;IAClG,SAAS,EAAE,CAAC;IACZ,2GAA2G;IAC3G,YAAY,EAAE,CAAC;IACf,6BAA6B;IAC7B,MAAM,EAAE,CAAC;IACT;;;;OAIG;IACH,QAAQ,EAAE,GAAG;IACb,mGAAmG;IACnG,MAAM,EAAE,KAAK,CAAC,MAA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CAAA;IACD,MAAM,EAAE,GAAG,aAAa,CACtB,CAAC,MAAM,EACP,MAAM,EACN,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI,EACnB,CAAC,CAAC,MAAM,CAAC,CAAC,EACV,YAAY,EACZ,KAAK,CACN,CAAA;IAED,MAAM,KAAK,GAAG,IAAI,UAAU,EAAE,CAAA;IAC9B,IAAI,IAAI,GAAG,KAAK,CAAA;IAChB,KAAK,MAAM,MAAM,IAAI,EAAE,EAAE,CAAC;QACxB,KAAK,MAAM,GAAG,IAAI,EAAE,EAAE,CAAC;YACrB,qEAAqE;YACrE,sEAAsE;YACtE,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAA;YAC1D,IAAI,IAAI,IAAI,CAAC;gBAAE,SAAQ;YACvB,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,GAAG,CAAC,EAAE,MAAM,EAAE,IAAI,GAAG,CAAC,EAAE,CAAC,CAAA;YAC/E,IAAI,GAAG,IAAI,CAAA;QACb,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAA;AAC5B,CAAC","sourcesContent":["import {\n Flow,\n Graphics2D,\n Paint,\n Types,\n component2d,\n lerpVector2,\n type NodeOf,\n type Size2D,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Alignment as _Alignment,\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type FlowMode as _FlowMode,\n type FlowResolved as _FlowResolved,\n type GapSize as _GapSize,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n} from \"@motionscript/sdk\"\n\nimport { addTiledLines } from \"../kit\"\n\n/** One mark's place on an axis, and whether it lands on the coarse grid. */\ninterface GridPosition {\n pos: number\n isMajor: boolean\n}\n\n// Calls the tiling `LineGridPattern` uses, so dots stay on its intersections at every offset.\nfunction gridPositions(\n min: number,\n max: number,\n step: number,\n offset: number,\n subdivisions: number,\n overscan: number\n): GridPosition[] {\n const out: GridPosition[] = []\n // Anchored at the near edge, so a column or row sits on each edge of the box for any count of cells.\n addTiledLines(min, max, step, offset, subdivisions, overscan, (pos, isMajor) => {\n out.push({ pos, isMajor })\n }, min)\n return out\n}\n\nconst state = {\n ...Paint.state,\n ...Flow.state,\n /** Cells along each axis, as in `LineGridPattern.divisions`: 4 puts 5 major dots on each axis. */\n divisions: 4,\n /** Splits each division again. `1` draws only the major dots; `2` puts one minor dot between each pair. */\n subdivisions: 1,\n /** Radius of a major dot. */\n radius: 3,\n /**\n * A minor dot's radius as a fraction of a major one's. A fraction rather than a\n * second paint stack, so the whole field stays one fill and a gradient crosses\n * every dot in it.\n */\n subScale: 0.5,\n /** Pans the field, as `LineGridPattern.offset` does, so the two stay aligned while both scroll. */\n offset: Types.custom<Vector2>({ x: 0, y: 0 }, { lerp: lerpVector2 }),\n}\n\ninterface DotField {\n readonly divisions: number\n readonly subdivisions: number\n readonly radius: number\n readonly subScale: number\n readonly offset: Vector2\n}\n\n/**\n * A field of dots on the same `divisions` / `subdivisions` / `offset` as\n * `LineGridPattern`, so laid over one the dots sit on its intersections.\n *\n * The silhouette is the dots, which `Paint.draw` paints with `shadow`, `fill`,\n * `overlay` and `stroke`. A dot grid has no \"paper\": a rectangle behind it is how\n * it gets a background.\n *\n * What `clip` confines the children to, and what picking tests, is the node's\n * box rather than the silhouette, which clips outer dots as they pan out and\n * keeps the node selectable between dots. `start` / `end` act on nothing:\n * trimming a disc leaves a crescent, not a partial grid.\n */\nexport const DotGridPattern = component2d({\n key: \"dotGridPattern\",\n state,\n commands: { ...Paint.commands },\n measure: (measurer, state, children) => Flow.measure(measurer, state, children, Paint.inset(state)),\n layout: (box, state, children) => Flow.layout(box, state, children, Paint.inset(state)),\n render: (ctx, state) => {\n const untrimmed = {\n fill: state.fill, stroke: state.stroke, shadow: state.shadow, overlay: state.overlay, start: 0, end: 1, clip: state.clip,\n }\n const box = new Graphics2D().rect({ width: ctx.size.width, height: ctx.size.height })\n Paint.draw(ctx, untrimmed, dots(ctx.size, state), { clipShape: box })\n },\n})\n\nexport type DotGridPattern = NodeOf<typeof DotGridPattern>\n/** What a call or a document row may set. */\nexport type DotGridPatternProps = NonNullable<Parameters<typeof DotGridPattern>[0]>\n\n/** Every dot in the field as one un-painted union: the paint stacks belong to the grid, not to a dot. */\nfunction dots(size: Size2D, s: DotField): Graphics2D | null {\n const { width, height } = size\n if (width <= 0 || height <= 0) return null\n\n const divisions = Math.max(1, Math.floor(s.divisions))\n const subdivisions = Math.max(1, Math.floor(s.subdivisions))\n const major = Math.max(0, s.radius)\n const minor = major * Math.max(0, s.subScale)\n if (major <= 0 && minor <= 0) return null\n\n // Inset by a dot's radius so an edge dot sits inside the box rather than being halved by the clip.\n const cols = divisions * subdivisions\n const insetX = Math.max(0, width / 2 - major)\n const insetY = Math.max(0, height / 2 - major)\n const xs = gridPositions(\n -insetX,\n insetX,\n (insetX * 2) / cols,\n s.offset.x,\n subdivisions,\n major\n )\n const ys = gridPositions(\n -insetY,\n insetY,\n (insetY * 2) / cols,\n s.offset.y,\n subdivisions,\n major\n )\n\n const field = new Graphics2D()\n let drew = false\n for (const column of xs) {\n for (const row of ys) {\n // A dot is major only where *both* axes are — an intersection of two\n // major rules, which is exactly the point a line grid draws heaviest.\n const size = column.isMajor && row.isMajor ? major : minor\n if (size <= 0) continue\n field.ellipse({ x: column.pos, y: row.pos, width: size * 2, height: size * 2 })\n drew = true\n }\n }\n return drew ? field : null\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export * from "./dot-grid-pattern.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dot-grid-pattern/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from "./dot-grid-pattern.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dot-grid-pattern/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA","sourcesContent":["export * from \"./dot-grid-pattern\"\n"]}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The patterns **kit**: what the three patterns share, and what a copied one does
3
+ * not copy.
4
+ *
5
+ * A copy takes a pattern's own files into your project and rewrites its reach
6
+ * for these to `@motionscript/patterns/kit`. `ViewportPattern` is the module a
7
+ * camera-filling pattern is built from; `grid-lines` is the tiling every pattern
8
+ * shares, which is what keeps a dot grid on a line grid's intersections, and a
9
+ * copy that kept its own would drift from it.
10
+ */
11
+ export * from "./kit/index.js";
12
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,cAAc,OAAO,CAAA"}
package/dist/engine.js ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The patterns **kit**: what the three patterns share, and what a copied one does
3
+ * not copy.
4
+ *
5
+ * A copy takes a pattern's own files into your project and rewrites its reach
6
+ * for these to `@motionscript/patterns/kit`. `ViewportPattern` is the module a
7
+ * camera-filling pattern is built from; `grid-lines` is the tiling every pattern
8
+ * shares, which is what keeps a dot grid on a line grid's intersections, and a
9
+ * copy that kept its own would drift from it.
10
+ */
11
+ export * from "./kit/index.js";
12
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,cAAc,OAAO,CAAA","sourcesContent":["/**\n * The patterns **kit**: what the three patterns share, and what a copied one does\n * not copy.\n *\n * A copy takes a pattern's own files into your project and rewrites its reach\n * for these to `@motionscript/patterns/kit`. `ViewportPattern` is the module a\n * camera-filling pattern is built from; `grid-lines` is the tiling every pattern\n * shares, which is what keeps a dot grid on a line grid's intersections, and a\n * copy that kept its own would drift from it.\n */\nexport * from \"./kit\"\n"]}
@@ -0,0 +1,94 @@
1
+ import { type NodeOf, type ShadowResolved, type FillResolved, type StrokeResolved, type Vector2, type Alignment as _Alignment, type Fill as _Fill, type FlowMode as _FlowMode, type FlowResolved as _FlowResolved, type GapSize as _GapSize, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Shadow as _Shadow, type Stroke as _Stroke } from "@motionscript/sdk";
2
+ /**
3
+ * An infinite line grid that fills the camera's visible region. Like
4
+ * `LineGridPattern` it draws major and minor strokes over a fill and pans
5
+ * with `offset`, but it tiles a world-anchored grid (spacing `cellSize`) across
6
+ * what the nearest `Camera` above it can see, regenerated each frame. With no
7
+ * camera it fills its own layout rect.
8
+ */
9
+ export declare const GridPattern: import("@motionscript/sdk").Component<"gridPattern", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
10
+ /** Spacing between grid lines in world units: one number for both axes, or `{ x, y }`. */
11
+ readonly cellSize: import("@motionscript/sdk").Type<number | Vector2, number | Vector2, false>;
12
+ /** Finer cells each cell is split into, as in `LineGridPattern.subdivisions`. */
13
+ readonly subdivisions: 1;
14
+ /** Stroke for the minor lines. Unset, the major `stroke` at half opacity when `subdivisions > 1`. */
15
+ readonly subStroke: import("@motionscript/sdk").Attribute<_Stroke, StrokeResolved[]>;
16
+ /** Scrolls the pattern relative to the world, which it is otherwise anchored to. */
17
+ readonly offset: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
18
+ readonly flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
19
+ readonly gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
20
+ readonly wrap: boolean;
21
+ readonly crossGap: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
22
+ readonly columns: import("@motionscript/sdk").Type<number, number, false>;
23
+ readonly align: import("@motionscript/sdk").Attribute<_Alignment, Vector2>;
24
+ readonly fill: import("@motionscript/sdk").Attribute<_Fill, FillResolved[]>;
25
+ readonly stroke: import("@motionscript/sdk").Attribute<_Stroke, StrokeResolved[]>;
26
+ readonly shadow: import("@motionscript/sdk").Attribute<_Shadow, ShadowResolved[]>;
27
+ readonly overlay: import("@motionscript/sdk").Attribute<_Fill, FillResolved[]>;
28
+ readonly start: import("@motionscript/sdk").Type<number, number, false>;
29
+ readonly end: import("@motionscript/sdk").Type<number, number, false>;
30
+ }>, {
31
+ readonly fillTo: readonly ["fill"];
32
+ readonly strokeTo: readonly ["stroke"];
33
+ readonly shadowTo: readonly ["shadow"];
34
+ readonly overlayTo: readonly ["overlay"];
35
+ readonly progressTo: readonly ["start", "end"];
36
+ readonly flash: {
37
+ readonly portion: import("@motionscript/sdk").Type<number, number, false>;
38
+ };
39
+ }, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
40
+ /** Spacing between grid lines in world units: one number for both axes, or `{ x, y }`. */
41
+ readonly cellSize: import("@motionscript/sdk").Type<number | Vector2, number | Vector2, false>;
42
+ /** Finer cells each cell is split into, as in `LineGridPattern.subdivisions`. */
43
+ readonly subdivisions: 1;
44
+ /** Stroke for the minor lines. Unset, the major `stroke` at half opacity when `subdivisions > 1`. */
45
+ readonly subStroke: import("@motionscript/sdk").Attribute<_Stroke, StrokeResolved[]>;
46
+ /** Scrolls the pattern relative to the world, which it is otherwise anchored to. */
47
+ readonly offset: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
48
+ readonly flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
49
+ readonly gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
50
+ readonly wrap: boolean;
51
+ readonly crossGap: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
52
+ readonly columns: import("@motionscript/sdk").Type<number, number, false>;
53
+ readonly align: import("@motionscript/sdk").Attribute<_Alignment, Vector2>;
54
+ readonly fill: import("@motionscript/sdk").Attribute<_Fill, FillResolved[]>;
55
+ readonly stroke: import("@motionscript/sdk").Attribute<_Stroke, StrokeResolved[]>;
56
+ readonly shadow: import("@motionscript/sdk").Attribute<_Shadow, ShadowResolved[]>;
57
+ readonly overlay: import("@motionscript/sdk").Attribute<_Fill, FillResolved[]>;
58
+ readonly start: import("@motionscript/sdk").Type<number, number, false>;
59
+ readonly end: import("@motionscript/sdk").Type<number, number, false>;
60
+ }>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
61
+ /** Spacing between grid lines in world units: one number for both axes, or `{ x, y }`. */
62
+ readonly cellSize: import("@motionscript/sdk").Type<number | Vector2, number | Vector2, false>;
63
+ /** Finer cells each cell is split into, as in `LineGridPattern.subdivisions`. */
64
+ readonly subdivisions: 1;
65
+ /** Stroke for the minor lines. Unset, the major `stroke` at half opacity when `subdivisions > 1`. */
66
+ readonly subStroke: import("@motionscript/sdk").Attribute<_Stroke, StrokeResolved[]>;
67
+ /** Scrolls the pattern relative to the world, which it is otherwise anchored to. */
68
+ readonly offset: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
69
+ readonly flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
70
+ readonly gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
71
+ readonly wrap: boolean;
72
+ readonly crossGap: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
73
+ readonly columns: import("@motionscript/sdk").Type<number, number, false>;
74
+ readonly align: import("@motionscript/sdk").Attribute<_Alignment, Vector2>;
75
+ readonly fill: import("@motionscript/sdk").Attribute<_Fill, FillResolved[]>;
76
+ readonly stroke: import("@motionscript/sdk").Attribute<_Stroke, StrokeResolved[]>;
77
+ readonly shadow: import("@motionscript/sdk").Attribute<_Shadow, ShadowResolved[]>;
78
+ readonly overlay: import("@motionscript/sdk").Attribute<_Fill, FillResolved[]>;
79
+ readonly start: import("@motionscript/sdk").Type<number, number, false>;
80
+ readonly end: import("@motionscript/sdk").Type<number, number, false>;
81
+ }>, {
82
+ readonly fillTo: readonly ["fill"];
83
+ readonly strokeTo: readonly ["stroke"];
84
+ readonly shadowTo: readonly ["shadow"];
85
+ readonly overlayTo: readonly ["overlay"];
86
+ readonly progressTo: readonly ["start", "end"];
87
+ readonly flash: {
88
+ readonly portion: import("@motionscript/sdk").Type<number, number, false>;
89
+ };
90
+ }, _Node2D<_Node2DProps>>>>;
91
+ export type GridPattern = NodeOf<typeof GridPattern>;
92
+ /** What a call or a document row may set. */
93
+ export type GridPatternProps = NonNullable<Parameters<typeof GridPattern>[0]>;
94
+ //# sourceMappingURL=grid-pattern.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grid-pattern.d.ts","sourceRoot":"","sources":["../../src/grid-pattern/grid-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EAOH,KAAK,MAAM,EAGX,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,OAAO,EAEZ,KAAK,SAAS,IAAI,UAAU,EAC5B,KAAK,IAAI,IAAI,KAAK,EAClB,KAAK,QAAQ,IAAI,SAAS,EAC1B,KAAK,YAAY,IAAI,aAAa,EAClC,KAAK,OAAO,IAAI,QAAQ,EACxB,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,IAAI,YAAY,EAChC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,MAAM,IAAI,OAAO,EACzB,MAAM,mBAAmB,CAAC;AAI3B;;;;;;GAMG;AACH,eAAO,MAAM,WAAW;IAIhB,0FAA0F;;IAE1F,iFAAiF;;IAEjF,qGAAqG;;IAErG,oFAAoF;;;;;;;;;;;;;;;;;;;;;;;;IANpF,0FAA0F;;IAE1F,iFAAiF;;IAEjF,qGAAqG;;IAErG,oFAAoF;;;;;;;;;;;;;;;IANpF,0FAA0F;;IAE1F,iFAAiF;;IAEjF,qGAAqG;;IAErG,oFAAoF;;;;;;;;;;;;;;;;;;;;;;;2BAQ1F,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,CAAC;AACrD,6CAA6C;AAC7C,MAAM,MAAM,gBAAgB,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,119 @@
1
+ import { Graphics2D, Types, component2d, lerpNumber, lerpVector2, } from "@motionscript/sdk";
2
+ import { centered, defaultSubStroke, gridLines, maxWeight, ViewportPattern } from "../kit/index.js";
3
+ /**
4
+ * An infinite line grid that fills the camera's visible region. Like
5
+ * `LineGridPattern` it draws major and minor strokes over a fill and pans
6
+ * with `offset`, but it tiles a world-anchored grid (spacing `cellSize`) across
7
+ * what the nearest `Camera` above it can see, regenerated each frame. With no
8
+ * camera it fills its own layout rect.
9
+ */
10
+ export const GridPattern = component2d({
11
+ key: "gridPattern",
12
+ state: {
13
+ ...ViewportPattern.state,
14
+ /** Spacing between grid lines in world units: one number for both axes, or `{ x, y }`. */
15
+ cellSize: Types.custom(100, { lerp: lerpCellSize }),
16
+ /** Finer cells each cell is split into, as in `LineGridPattern.subdivisions`. */
17
+ subdivisions: 1,
18
+ /** Stroke for the minor lines. Unset, the major `stroke` at half opacity when `subdivisions > 1`. */
19
+ subStroke: Types.stroke,
20
+ /** Scrolls the pattern relative to the world, which it is otherwise anchored to. */
21
+ offset: Types.custom({ x: 0, y: 0 }, { lerp: lerpVector2 }),
22
+ },
23
+ defaults: { subStroke: (_state, given) => defaultSubStroke(given) },
24
+ commands: { ...ViewportPattern.commands },
25
+ measure: ViewportPattern.measure,
26
+ layout: ViewportPattern.layout,
27
+ render: (ctx, state) => ViewportPattern.draw(ctx, (bounds) => drawGrid(ctx, state, bounds)),
28
+ });
29
+ function drawGrid(ctx, s, bounds) {
30
+ const halfW = bounds.width / 2;
31
+ const halfH = bounds.height / 2;
32
+ // `bounds` is centred on (x, y) in y-up world space: descriptor coordinates are y-up
33
+ // and the renderer applies the single flip.
34
+ const left = bounds.x - halfW;
35
+ const right = bounds.x + halfW;
36
+ const top = bounds.y - halfH;
37
+ const bottom = bounds.y + halfH;
38
+ ctx.draw(new Graphics2D()
39
+ .rect({ x: bounds.x, y: bounds.y, width: bounds.width, height: bounds.height, start: s.start, end: s.end })
40
+ .shadow(s.shadow)
41
+ .fill(s.fill));
42
+ const subdivisions = Math.max(1, Math.floor(s.subdivisions));
43
+ const cell = s.cellSize;
44
+ const cellX = Math.max(1e-3, typeof cell === "number" ? cell : cell.x);
45
+ const cellY = Math.max(1e-3, typeof cell === "number" ? cell : cell.y);
46
+ const stepX = cellX / subdivisions;
47
+ const stepY = cellY / subdivisions;
48
+ const major = centered(s.stroke);
49
+ const minorStroke = centered(s.subStroke);
50
+ const overscan = Math.max(maxWeight(major), maxWeight(minorStroke)) / 2;
51
+ const xAxis = { min: left, max: right, step: stepX, offset: s.offset.x };
52
+ const yAxis = { min: top, max: bottom, step: stepY, offset: s.offset.y };
53
+ // Minor lines first so the major lines sit on top.
54
+ if (subdivisions > 1 && minorStroke.length > 0) {
55
+ drawGroup(ctx, xAxis, yAxis, subdivisions, overscan, minorStroke, false);
56
+ }
57
+ if (major.length > 0) {
58
+ drawGroup(ctx, xAxis, yAxis, subdivisions, overscan, major, true);
59
+ }
60
+ }
61
+ // A solid stroke paints the group as one union path. A dashed one draws each line on
62
+ // its own with its dash phase anchored to the line's world coordinate, so dashes never
63
+ // crawl as the camera pans or new lines scroll in.
64
+ function drawGroup(ctx, xAxis, yAxis, subdivisions, overscan, stroke, isMajor) {
65
+ // Each line spans a whole number of dash cycles, so the renderer's per-path dash-fit
66
+ // is a no-op and every line dashes identically.
67
+ const cycle = dashCycle(stroke);
68
+ const g = gridLines(xAxis, yAxis, subdivisions, overscan, cycle);
69
+ const verticals = isMajor ? g.verticalMajor : g.verticalMinor;
70
+ const horizontals = isMajor ? g.horizontalMajor : g.horizontalMinor;
71
+ // Symmetric centerBounds give a zero recentre offset, so local coordinates draw verbatim.
72
+ const centerBounds = [-1, -1, 1, 1];
73
+ if (cycle <= 0) {
74
+ const data = [];
75
+ for (const px of verticals)
76
+ data.push({ type: "M", x: px, y: g.top }, { type: "L", x: px, y: g.bottom });
77
+ for (const py of horizontals)
78
+ data.push({ type: "M", x: g.left, y: py }, { type: "L", x: g.right, y: py });
79
+ if (data.length > 0)
80
+ ctx.draw(new Graphics2D().path({ data, centerBounds }).stroke(stroke));
81
+ return;
82
+ }
83
+ for (const px of verticals) {
84
+ const data = [{ type: "M", x: px, y: g.top }, { type: "L", x: px, y: g.bottom }];
85
+ ctx.draw(new Graphics2D().path({ data, centerBounds }).stroke(phaseShift(stroke, g.top)));
86
+ }
87
+ for (const py of horizontals) {
88
+ const data = [{ type: "M", x: g.left, y: py }, { type: "L", x: g.right, y: py }];
89
+ ctx.draw(new Graphics2D().path({ data, centerBounds }).stroke(phaseShift(stroke, g.left)));
90
+ }
91
+ }
92
+ // The largest dash-array sum across the layers, or 0 when none is dashed.
93
+ function dashCycle(strokes) {
94
+ let cycle = 0;
95
+ for (const s of strokes) {
96
+ if (s.dash && s.dash.length > 0) {
97
+ const sum = s.dash.reduce((a, b) => a + b, 0);
98
+ if (sum > cycle)
99
+ cycle = sum;
100
+ }
101
+ }
102
+ return cycle;
103
+ }
104
+ // `dashOffset` advances the pattern, so it is negated to put the "on" run at the phase one
105
+ // infinite line would have at this world coordinate.
106
+ function phaseShift(strokes, worldStart) {
107
+ return strokes.map(s => (s.dash && s.dash.length > 0)
108
+ ? { ...s, dashOffset: (s.dashOffset ?? 0) - worldStart }
109
+ : s);
110
+ }
111
+ // A number and a vector tween by promoting the number to a uniform vector.
112
+ function lerpCellSize(from, to, t) {
113
+ if (typeof from === "number" && typeof to === "number")
114
+ return lerpNumber(from, to, t);
115
+ const a = typeof from === "number" ? { x: from, y: from } : from;
116
+ const b = typeof to === "number" ? { x: to, y: to } : to;
117
+ return lerpVector2(a, b, t);
118
+ }
119
+ //# sourceMappingURL=grid-pattern.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grid-pattern.js","sourceRoot":"","sources":["../../src/grid-pattern/grid-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,UAAU,EACV,KAAK,EACL,WAAW,EACX,UAAU,EACV,WAAW,GAmBd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAiB,MAAM,QAAQ,CAAC;AAE1G;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,WAAW,CAAC;IACnC,GAAG,EAAE,aAAa;IAClB,KAAK,EAAE;QACH,GAAG,eAAe,CAAC,KAAK;QACxB,0FAA0F;QAC1F,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAmB,GAAG,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;QACrE,iFAAiF;QACjF,YAAY,EAAE,CAAC;QACf,qGAAqG;QACrG,SAAS,EAAE,KAAK,CAAC,MAAM;QACvB,oFAAoF;QACpF,MAAM,EAAE,KAAK,CAAC,MAAM,CAAU,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;KACvE;IACD,QAAQ,EAAE,EAAE,SAAS,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE;IACnE,QAAQ,EAAE,EAAE,GAAG,eAAe,CAAC,QAAQ,EAAE;IACzC,OAAO,EAAE,eAAe,CAAC,OAAO;IAChC,MAAM,EAAE,eAAe,CAAC,MAAM;IAC9B,MA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AK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACjE,MAAM,CAAC,GAAG,OAAO,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACzD,OAAO,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import {\n Graphics2D,\n Types,\n component2d,\n lerpNumber,\n lerpVector2,\n type BoxBounds,\n type NodeOf,\n type PathCommand,\n type RenderContext,\n type ShadowResolved,\n type FillResolved,\n type StrokeResolved,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Alignment as _Alignment,\n type Fill as _Fill,\n type FlowMode as _FlowMode,\n type FlowResolved as _FlowResolved,\n type GapSize as _GapSize,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type Stroke as _Stroke,\n} from \"@motionscript/sdk\";\n\nimport { centered, defaultSubStroke, gridLines, maxWeight, ViewportPattern, type GridAxis } from \"../kit\";\n\n/**\n * An infinite line grid that fills the camera's visible region. Like\n * `LineGridPattern` it draws major and minor strokes over a fill and pans\n * with `offset`, but it tiles a world-anchored grid (spacing `cellSize`) across\n * what the nearest `Camera` above it can see, regenerated each frame. With no\n * camera it fills its own layout rect.\n */\nexport const GridPattern = component2d({\n key: \"gridPattern\",\n state: {\n ...ViewportPattern.state,\n /** Spacing between grid lines in world units: one number for both axes, or `{ x, y }`. */\n cellSize: Types.custom<number | Vector2>(100, { lerp: lerpCellSize }),\n /** Finer cells each cell is split into, as in `LineGridPattern.subdivisions`. */\n subdivisions: 1,\n /** Stroke for the minor lines. Unset, the major `stroke` at half opacity when `subdivisions > 1`. */\n subStroke: Types.stroke,\n /** Scrolls the pattern relative to the world, which it is otherwise anchored to. */\n offset: Types.custom<Vector2>({ x: 0, y: 0 }, { lerp: lerpVector2 }),\n },\n defaults: { subStroke: (_state, given) => defaultSubStroke(given) },\n commands: { ...ViewportPattern.commands },\n measure: ViewportPattern.measure,\n layout: ViewportPattern.layout,\n render: (ctx, state) => ViewportPattern.draw(ctx, (bounds) => drawGrid(ctx, state, bounds)),\n});\n\nexport type GridPattern = NodeOf<typeof GridPattern>;\n/** What a call or a document row may set. */\nexport type GridPatternProps = NonNullable<Parameters<typeof GridPattern>[0]>;\n\ninterface GridState {\n readonly fill: FillResolved[];\n readonly stroke: StrokeResolved[];\n readonly shadow: ShadowResolved[];\n readonly start: number;\n readonly end: number;\n readonly cellSize: number | Vector2;\n readonly subdivisions: number;\n readonly subStroke: StrokeResolved[];\n readonly offset: Vector2;\n}\n\nfunction drawGrid(ctx: RenderContext, s: GridState, bounds: BoxBounds): void {\n const halfW = bounds.width / 2;\n const halfH = bounds.height / 2;\n // `bounds` is centred on (x, y) in y-up world space: descriptor coordinates are y-up\n // and the renderer applies the single flip.\n const left = bounds.x - halfW;\n const right = bounds.x + halfW;\n const top = bounds.y - halfH;\n const bottom = bounds.y + halfH;\n\n ctx.draw(new Graphics2D()\n .rect({ x: bounds.x, y: bounds.y, width: bounds.width, height: bounds.height, start: s.start, end: s.end })\n .shadow(s.shadow)\n .fill(s.fill));\n\n const subdivisions = Math.max(1, Math.floor(s.subdivisions));\n const cell = s.cellSize;\n const cellX = Math.max(1e-3, typeof cell === \"number\" ? cell : cell.x);\n const cellY = Math.max(1e-3, typeof cell === \"number\" ? cell : cell.y);\n const stepX = cellX / subdivisions;\n const stepY = cellY / subdivisions;\n\n const major = centered(s.stroke);\n const minorStroke = centered(s.subStroke);\n const overscan = Math.max(maxWeight(major), maxWeight(minorStroke)) / 2;\n\n const xAxis: GridAxis = { min: left, max: right, step: stepX, offset: s.offset.x };\n const yAxis: GridAxis = { min: top, max: bottom, step: stepY, offset: s.offset.y };\n\n // Minor lines first so the major lines sit on top.\n if (subdivisions > 1 && minorStroke.length > 0) {\n drawGroup(ctx, xAxis, yAxis, subdivisions, overscan, minorStroke, false);\n }\n if (major.length > 0) {\n drawGroup(ctx, xAxis, yAxis, subdivisions, overscan, major, true);\n }\n}\n\n// A solid stroke paints the group as one union path. A dashed one draws each line on\n// its own with its dash phase anchored to the line's world coordinate, so dashes never\n// crawl as the camera pans or new lines scroll in.\nfunction drawGroup(\n ctx: RenderContext,\n xAxis: GridAxis,\n yAxis: GridAxis,\n subdivisions: number,\n overscan: number,\n stroke: StrokeResolved[],\n isMajor: boolean,\n): void {\n // Each line spans a whole number of dash cycles, so the renderer's per-path dash-fit\n // is a no-op and every line dashes identically.\n const cycle = dashCycle(stroke);\n const g = gridLines(xAxis, yAxis, subdivisions, overscan, cycle);\n const verticals = isMajor ? g.verticalMajor : g.verticalMinor;\n const horizontals = isMajor ? g.horizontalMajor : g.horizontalMinor;\n\n // Symmetric centerBounds give a zero recentre offset, so local coordinates draw verbatim.\n const centerBounds = [-1, -1, 1, 1] as const;\n\n if (cycle <= 0) {\n const data: PathCommand[] = [];\n for (const px of verticals) data.push({ type: \"M\", x: px, y: g.top }, { type: \"L\", x: px, y: g.bottom });\n for (const py of horizontals) data.push({ type: \"M\", x: g.left, y: py }, { type: \"L\", x: g.right, y: py });\n if (data.length > 0) ctx.draw(new Graphics2D().path({ data, centerBounds }).stroke(stroke));\n return;\n }\n\n for (const px of verticals) {\n const data: PathCommand[] = [{ type: \"M\", x: px, y: g.top }, { type: \"L\", x: px, y: g.bottom }];\n ctx.draw(new Graphics2D().path({ data, centerBounds }).stroke(phaseShift(stroke, g.top)));\n }\n for (const py of horizontals) {\n const data: PathCommand[] = [{ type: \"M\", x: g.left, y: py }, { type: \"L\", x: g.right, y: py }];\n ctx.draw(new Graphics2D().path({ data, centerBounds }).stroke(phaseShift(stroke, g.left)));\n }\n}\n\n// The largest dash-array sum across the layers, or 0 when none is dashed.\nfunction dashCycle(strokes: StrokeResolved[]): number {\n let cycle = 0;\n for (const s of strokes) {\n if (s.dash && s.dash.length > 0) {\n const sum = s.dash.reduce((a, b) => a + b, 0);\n if (sum > cycle) cycle = sum;\n }\n }\n return cycle;\n}\n\n// `dashOffset` advances the pattern, so it is negated to put the \"on\" run at the phase one\n// infinite line would have at this world coordinate.\nfunction phaseShift(strokes: StrokeResolved[], worldStart: number): StrokeResolved[] {\n return strokes.map(s => (s.dash && s.dash.length > 0)\n ? { ...s, dashOffset: (s.dashOffset ?? 0) - worldStart }\n : s);\n}\n\n// A number and a vector tween by promoting the number to a uniform vector.\nfunction lerpCellSize(from: number | Vector2, to: number | Vector2, t: number): number | Vector2 {\n if (typeof from === \"number\" && typeof to === \"number\") return lerpNumber(from, to, t);\n const a = typeof from === \"number\" ? { x: from, y: from } : from;\n const b = typeof to === \"number\" ? { x: to, y: to } : to;\n return lerpVector2(a, b, t);\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export * from "./grid-pattern.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/grid-pattern/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from "./grid-pattern.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/grid-pattern/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA","sourcesContent":["export * from \"./grid-pattern\"\n"]}
@@ -0,0 +1,6 @@
1
+ export * from "./line-grid-pattern/index.js";
2
+ export * from "./dot-grid-pattern/index.js";
3
+ export * from "./grid-pattern/index.js";
4
+ export * from "./engine.js";
5
+ export { NODES } from "./nodes.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,UAAU,CAAA;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export * from "./line-grid-pattern/index.js";
2
+ export * from "./dot-grid-pattern/index.js";
3
+ export * from "./grid-pattern/index.js";
4
+ export * from "./engine.js";
5
+ export { NODES } from "./nodes.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,UAAU,CAAA;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA","sourcesContent":["export * from \"./line-grid-pattern\"\nexport * from \"./dot-grid-pattern\"\nexport * from \"./grid-pattern\"\nexport * from \"./engine\"\nexport { NODES } from \"./nodes\"\n"]}