@motionscript/patterns 0.0.0-stage → 0.1.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 (73) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +48 -0
  4. package/README.md +79 -3
  5. package/dist/browser/chunks/chunk-EZEE76AY.js +2 -0
  6. package/dist/browser/chunks/chunk-EZEE76AY.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 +41 -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 +93 -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 +31 -0
  25. package/dist/grid-pattern/grid-pattern.d.ts.map +1 -0
  26. package/dist/grid-pattern/grid-pattern.js +138 -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 +104 -0
  37. package/dist/kit/grid-lines.d.ts.map +1 -0
  38. package/dist/kit/grid-lines.js +127 -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 +36 -0
  45. package/dist/kit/viewport-pattern.d.ts.map +1 -0
  46. package/dist/kit/viewport-pattern.js +77 -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 +30 -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 +96 -0
  55. package/dist/line-grid-pattern/line-grid-pattern.js.map +1 -0
  56. package/dist/nodes.d.ts +14 -0
  57. package/dist/nodes.d.ts.map +1 -0
  58. package/dist/nodes.js +14 -0
  59. package/dist/nodes.js.map +1 -0
  60. package/package.json +72 -3
  61. package/registry.json +26 -0
  62. package/src/dot-grid-pattern/dot-grid-pattern.ts +132 -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 +170 -0
  66. package/src/grid-pattern/index.ts +1 -0
  67. package/src/index.ts +5 -0
  68. package/src/kit/grid-lines.ts +199 -0
  69. package/src/kit/index.ts +2 -0
  70. package/src/kit/viewport-pattern.ts +98 -0
  71. package/src/line-grid-pattern/index.ts +1 -0
  72. package/src/line-grid-pattern/line-grid-pattern.ts +125 -0
  73. package/src/nodes.ts +14 -0
@@ -0,0 +1,127 @@
1
+ import { strokeOps } from "@motionscript/sdk";
2
+ /**
3
+ * Resolve the grid for the given per-axis extents: the cross-axis span and the
4
+ * major/minor line positions on each axis. Vertical lines span the full y
5
+ * extent; horizontal lines span the full x extent. Both spans are grown by
6
+ * `overscan` so a thick line slides out under the clip instead of popping, and
7
+ * snapped outward to the grid so the endpoints sit on stable world positions
8
+ * (a line's start stays fixed as the camera pans, so a dashed stroke anchored to
9
+ * it doesn't crawl).
10
+ *
11
+ * `cycle` (the dash period, when dashed) snaps the cross-axis span to a whole
12
+ * number of dash cycles too, so each parallel line is the same dash-aligned
13
+ * length and the renderer's per-path dash-fit becomes a no-op (no per-frame
14
+ * resizing of the dashes as lines enter and leave view).
15
+ */
16
+ export function gridLines(x, y, subdivisions, overscan, cycle = 0) {
17
+ const verticalMajor = [];
18
+ const verticalMinor = [];
19
+ const horizontalMajor = [];
20
+ const horizontalMinor = [];
21
+ // Span each line across the cross axis, snapped outward to the grid (and to
22
+ // the dash cycle when dashed) so the endpoints sit on stable world positions.
23
+ const top = snapSpan(y.min - overscan, y.step, y.offset, cycle, Math.floor);
24
+ const bottom = snapSpan(y.max + overscan, y.step, y.offset, cycle, Math.ceil);
25
+ const left = snapSpan(x.min - overscan, x.step, x.offset, cycle, Math.floor);
26
+ const right = snapSpan(x.max + overscan, x.step, x.offset, cycle, Math.ceil);
27
+ addTiledLines(x.min, x.max, x.step, x.offset, subdivisions, overscan, (px, isMajor) => {
28
+ (isMajor ? verticalMajor : verticalMinor).push(px);
29
+ }, x.anchor);
30
+ addTiledLines(y.min, y.max, y.step, y.offset, subdivisions, overscan, (py, isMajor) => {
31
+ (isMajor ? horizontalMajor : horizontalMinor).push(py);
32
+ }, y.anchor);
33
+ return { top, bottom, left, right, verticalMajor, verticalMinor, horizontalMajor, horizontalMinor };
34
+ }
35
+ /**
36
+ * Build the grid lines as multi-subpath path commands, split into the major
37
+ * (division) lines and the minor (subdivision) lines, for the given per-axis
38
+ * extents. Every line in a group shares one stroke (drawn as one union path), so
39
+ * this is the path for solid strokes; dashed strokes that must stay world-locked
40
+ * draw per line from {@link gridLines} instead.
41
+ */
42
+ export function gridLinePaths(x, y, subdivisions, overscan) {
43
+ const g = gridLines(x, y, subdivisions, overscan);
44
+ const major = [];
45
+ const minor = [];
46
+ for (const px of g.verticalMajor)
47
+ major.push({ type: "M", x: px, y: g.top }, { type: "L", x: px, y: g.bottom });
48
+ for (const px of g.verticalMinor)
49
+ minor.push({ type: "M", x: px, y: g.top }, { type: "L", x: px, y: g.bottom });
50
+ for (const py of g.horizontalMajor)
51
+ major.push({ type: "M", x: g.left, y: py }, { type: "L", x: g.right, y: py });
52
+ for (const py of g.horizontalMinor)
53
+ minor.push({ type: "M", x: g.left, y: py }, { type: "L", x: g.right, y: py });
54
+ return { major, minor };
55
+ }
56
+ // Snap `pos` outward to a stable world position so a dashed line's start stays
57
+ // fixed as the viewport moves (the renderer anchors dash phase to the subpath
58
+ // start). Snap to the grid line lattice (`n*step + offset`); when a dash `cycle`
59
+ // is given, snap to the dash lattice instead (`n*cycle`, anchored to world 0) so
60
+ // every parallel line is the same whole number of cycles long and the renderer's
61
+ // per-path dash-fit stays a no-op. `round` is `Math.floor` to snap below, `ceil`
62
+ // to snap above. The lattice is the one about 0 whatever an axis's `anchor`: a span
63
+ // only has to reach past the edge, and a line's ends stay where they always were.
64
+ function snapSpan(pos, step, offset, cycle, round) {
65
+ if (cycle > 0)
66
+ return round(pos / cycle) * cycle;
67
+ if (step <= 0)
68
+ return pos;
69
+ return round((pos - offset) / step) * step + offset;
70
+ }
71
+ /**
72
+ * Emit every grid line position in `[min, max]` (grown by `overscan` on each
73
+ * end) for a grid of spacing `step`, panned by `offset` px. Without panning the
74
+ * lattice starts at `anchor` (0 unless given) and its tile indices count outward
75
+ * from there; the line at tile index `n` is major when `n` is a multiple of
76
+ * `subdivisions`. The pan shifts each position by `offset` while keeping the
77
+ * area full, so `n` is taken relative to the un-panned lattice (offset folded
78
+ * out) to keep classification stable as it scrolls.
79
+ *
80
+ * A fixed grid anchors at `min`, so its first line is on the box's edge and the
81
+ * last is too whenever the extent is a whole number of steps. An infinite grid
82
+ * keeps the default, so its lines stay on the world's lattice.
83
+ */
84
+ export function addTiledLines(min, max, step, offset, subdivisions, overscan, emit, anchor = 0) {
85
+ if (step <= 0)
86
+ return;
87
+ // First/last tile index whose panned position is within the overscanned
88
+ // [min, max]. Positions are `anchor + n*step + offset` (n=0 sits on the
89
+ // anchor). A small epsilon keeps a line that lands exactly on an edge (an
90
+ // anchor at `min`, or a world lattice that reaches it) from being dropped by FP error.
91
+ const eps = step * 1e-6;
92
+ const startN = Math.ceil((min - overscan - offset - anchor - eps) / step);
93
+ const endN = Math.floor((max + overscan - offset - anchor + eps) / step);
94
+ for (let n = startN; n <= endN; n++) {
95
+ const pos = anchor + n * step + offset;
96
+ // mod that stays non-negative for negative n.
97
+ const isMajor = ((n % subdivisions) + subdivisions) % subdivisions === 0;
98
+ emit(pos, isMajor);
99
+ }
100
+ }
101
+ /** Largest stroke weight across the layers of a resolved stroke array. Used to
102
+ * overscan the tiling so a thick line stays drawn until fully off the area. */
103
+ export function maxWeight(strokes) {
104
+ let max = 0;
105
+ for (const s of strokes)
106
+ if (s.weight > max)
107
+ max = s.weight;
108
+ return max;
109
+ }
110
+ /** Force every layer of a resolved stroke array to centered alignment. Grid
111
+ * lines are open paths, not a closed region, so inside/outside alignment is
112
+ * meaningless — they always straddle their position. (Open paths are already
113
+ * stroked centered by the renderer; this makes the intent explicit and ignores
114
+ * any author `align`.) */
115
+ export function centered(strokes) {
116
+ return strokes.map(s => (s.align === 0 ? s : { ...s, align: 0 }));
117
+ }
118
+ /** Copy a resolved stroke array with every fill layer's opacity scaled by
119
+ * `factor`. Used to derive the default minor-line stroke from the major one.
120
+ * Every resolved fill carries an `opacity` field, so this is type-uniform. */
121
+ export function dimStroke(strokes, factor) {
122
+ return strokeOps.resolve(strokes.map(s => ({
123
+ ...s,
124
+ fill: s.fill.map(f => ({ ...f, opacity: (f.opacity ?? 1) * factor })),
125
+ })));
126
+ }
127
+ //# source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AG,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5D,OAAO,GAAG,CAAC;AACf,CAAC;AAED;;;;0BAI0B;AAC1B,MAAM,UAAU,QAAQ,CAAC,OAAyB;IAC9C,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACtE,CAAC;AAED;;8EAE8E;AAC9E,MAAM,UAAU,SAAS,CAAC,OAAyB,EAAE,MAAc;IAC/D,OAAO,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACvC,GAAG,CAAC;QACJ,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,GAAG,MAAM,EAAE,CAAC,CAAC;KACxE,CAAC,CAA4B,CAAC,CAAC;AACpC,CAAC","sourcesContent":["import { strokeOps, type PathCommand, type StrokeProp, type StrokeResolved } from \"@motionscript/sdk\";\r\n\r\n/**\r\n * Shared geometry for line grids. Both {@link LineGridPattern} (a fixed grid filling\r\n * its layout rect) and {@link GridPattern} (an infinite grid tiled across the\r\n * camera's visible region) build the same multi-subpath line paths from these\r\n * helpers — they differ only in how the extent and step are chosen.\r\n *\r\n * Lines are tiled by the minor step and panned by an origin offset: every\r\n * position within the extent (grown by `overscan` so thick lines clip out\r\n * smoothly) is emitted regardless of the offset, so the area always stays full\r\n * and animating the offset scrolls the grid. The lattice starts at the axis's\r\n * `anchor` (the world origin unless it says otherwise). A tile whose index\r\n * aligns to the division grid is major; the rest are minor. Each is built as a\r\n * single multi-subpath path so the trailing stroke paints every line as one\r\n * union with no destructive boolean op (which would erase the open lines).\r\n */\r\n\r\n/** A grid extent on one axis: lines tile within `[min, max]`, on a lattice that starts at `anchor`. */\r\nexport interface GridAxis {\r\n /** Minimum coordinate (typically negative). */\r\n min: number;\r\n /** Maximum coordinate. */\r\n max: number;\r\n /** Spacing between adjacent (minor) lines. */\r\n step: number;\r\n /** Pan offset in pixels along this axis. */\r\n offset: number;\r\n /**\r\n * Where the lattice starts: a line sits at `anchor + n * step`, and the tile\r\n * index `n` that decides which lines are major counts from there. Omitted it is 0, the\r\n * world origin, which is what a grid that follows a camera keeps. A grid with a box of its\r\n * own sets it to `min`, so the box's edges are lines whatever the count of cells.\r\n */\r\n anchor?: number;\r\n}\r\n\r\n/** The resolved grid: where each line sits and how far it runs. Vertical lines\r\n * sit at x = `verticalX[i]` and run from `top` to `bottom`; horizontal lines sit\r\n * at y = `horizontalY[i]` and run from `left` to `right`. Positions are split\r\n * into major (division) and minor (subdivision) lines. */\r\nexport interface GridLines {\r\n /** y-extent every vertical line spans. */\r\n top: number;\r\n bottom: number;\r\n /** x-extent every horizontal line spans. */\r\n left: number;\r\n right: number;\r\n verticalMajor: number[];\r\n verticalMinor: number[];\r\n horizontalMajor: number[];\r\n horizontalMinor: number[];\r\n}\r\n\r\n/**\r\n * Resolve the grid for the given per-axis extents: the cross-axis span and the\r\n * major/minor line positions on each axis. Vertical lines span the full y\r\n * extent; horizontal lines span the full x extent. Both spans are grown by\r\n * `overscan` so a thick line slides out under the clip instead of popping, and\r\n * snapped outward to the grid so the endpoints sit on stable world positions\r\n * (a line's start stays fixed as the camera pans, so a dashed stroke anchored to\r\n * it doesn't crawl).\r\n *\r\n * `cycle` (the dash period, when dashed) snaps the cross-axis span to a whole\r\n * number of dash cycles too, so each parallel line is the same dash-aligned\r\n * length and the renderer's per-path dash-fit becomes a no-op (no per-frame\r\n * resizing of the dashes as lines enter and leave view).\r\n */\r\nexport function gridLines(\r\n x: GridAxis,\r\n y: GridAxis,\r\n subdivisions: number,\r\n overscan: number,\r\n cycle = 0,\r\n): GridLines {\r\n const verticalMajor: number[] = [];\r\n const verticalMinor: number[] = [];\r\n const horizontalMajor: number[] = [];\r\n const horizontalMinor: number[] = [];\r\n\r\n // Span each line across the cross axis, snapped outward to the grid (and to\r\n // the dash cycle when dashed) so the endpoints sit on stable world positions.\r\n const top = snapSpan(y.min - overscan, y.step, y.offset, cycle, Math.floor);\r\n const bottom = snapSpan(y.max + overscan, y.step, y.offset, cycle, Math.ceil);\r\n const left = snapSpan(x.min - overscan, x.step, x.offset, cycle, Math.floor);\r\n const right = snapSpan(x.max + overscan, x.step, x.offset, cycle, Math.ceil);\r\n\r\n addTiledLines(x.min, x.max, x.step, x.offset, subdivisions, overscan, (px, isMajor) => {\r\n (isMajor ? verticalMajor : verticalMinor).push(px);\r\n }, x.anchor);\r\n addTiledLines(y.min, y.max, y.step, y.offset, subdivisions, overscan, (py, isMajor) => {\r\n (isMajor ? horizontalMajor : horizontalMinor).push(py);\r\n }, y.anchor);\r\n\r\n return { top, bottom, left, right, verticalMajor, verticalMinor, horizontalMajor, horizontalMinor };\r\n}\r\n\r\n/**\r\n * Build the grid lines as multi-subpath path commands, split into the major\r\n * (division) lines and the minor (subdivision) lines, for the given per-axis\r\n * extents. Every line in a group shares one stroke (drawn as one union path), so\r\n * this is the path for solid strokes; dashed strokes that must stay world-locked\r\n * draw per line from {@link gridLines} instead.\r\n */\r\nexport function gridLinePaths(\r\n x: GridAxis,\r\n y: GridAxis,\r\n subdivisions: number,\r\n overscan: number,\r\n): { major: PathCommand[]; minor: PathCommand[] } {\r\n const g = gridLines(x, y, subdivisions, overscan);\r\n const major: PathCommand[] = [];\r\n const minor: PathCommand[] = [];\r\n for (const px of g.verticalMajor) major.push({ type: \"M\", x: px, y: g.top }, { type: \"L\", x: px, y: g.bottom });\r\n for (const px of g.verticalMinor) minor.push({ type: \"M\", x: px, y: g.top }, { type: \"L\", x: px, y: g.bottom });\r\n for (const py of g.horizontalMajor) major.push({ type: \"M\", x: g.left, y: py }, { type: \"L\", x: g.right, y: py });\r\n for (const py of g.horizontalMinor) minor.push({ type: \"M\", x: g.left, y: py }, { type: \"L\", x: g.right, y: py });\r\n return { major, minor };\r\n}\r\n\r\n// Snap `pos` outward to a stable world position so a dashed line's start stays\r\n// fixed as the viewport moves (the renderer anchors dash phase to the subpath\r\n// start). Snap to the grid line lattice (`n*step + offset`); when a dash `cycle`\r\n// is given, snap to the dash lattice instead (`n*cycle`, anchored to world 0) so\r\n// every parallel line is the same whole number of cycles long and the renderer's\r\n// per-path dash-fit stays a no-op. `round` is `Math.floor` to snap below, `ceil`\r\n// to snap above. The lattice is the one about 0 whatever an axis's `anchor`: a span\r\n// only has to reach past the edge, and a line's ends stay where they always were.\r\nfunction snapSpan(pos: number, step: number, offset: number, cycle: number, round: (n: number) => number): number {\r\n if (cycle > 0) return round(pos / cycle) * cycle;\r\n if (step <= 0) return pos;\r\n return round((pos - offset) / step) * step + offset;\r\n}\r\n\r\n/**\r\n * Emit every grid line position in `[min, max]` (grown by `overscan` on each\r\n * end) for a grid of spacing `step`, panned by `offset` px. Without panning the\r\n * lattice starts at `anchor` (0 unless given) and its tile indices count outward\r\n * from there; the line at tile index `n` is major when `n` is a multiple of\r\n * `subdivisions`. The pan shifts each position by `offset` while keeping the\r\n * area full, so `n` is taken relative to the un-panned lattice (offset folded\r\n * out) to keep classification stable as it scrolls.\r\n *\r\n * A fixed grid anchors at `min`, so its first line is on the box's edge and the\r\n * last is too whenever the extent is a whole number of steps. An infinite grid\r\n * keeps the default, so its lines stay on the world's lattice.\r\n */\r\nexport function addTiledLines(\r\n min: number,\r\n max: number,\r\n step: number,\r\n offset: number,\r\n subdivisions: number,\r\n overscan: number,\r\n emit: (pos: number, isMajor: boolean) => void,\r\n anchor = 0,\r\n): void {\r\n if (step <= 0) return;\r\n // First/last tile index whose panned position is within the overscanned\r\n // [min, max]. Positions are `anchor + n*step + offset` (n=0 sits on the\r\n // anchor). A small epsilon keeps a line that lands exactly on an edge (an\r\n // anchor at `min`, or a world lattice that reaches it) from being dropped by FP error.\r\n const eps = step * 1e-6;\r\n const startN = Math.ceil((min - overscan - offset - anchor - eps) / step);\r\n const endN = Math.floor((max + overscan - offset - anchor + eps) / step);\r\n for (let n = startN; n <= endN; n++) {\r\n const pos = anchor + n * step + offset;\r\n // mod that stays non-negative for negative n.\r\n const isMajor = ((n % subdivisions) + subdivisions) % subdivisions === 0;\r\n emit(pos, isMajor);\r\n }\r\n}\r\n\r\n/** Largest stroke weight across the layers of a resolved stroke array. Used to\r\n * overscan the tiling so a thick line stays drawn until fully off the area. */\r\nexport function maxWeight(strokes: StrokeResolved[]): number {\r\n let max = 0;\r\n for (const s of strokes) if (s.weight > max) max = s.weight;\r\n return max;\r\n}\r\n\r\n/** Force every layer of a resolved stroke array to centered alignment. Grid\r\n * lines are open paths, not a closed region, so inside/outside alignment is\r\n * meaningless — they always straddle their position. (Open paths are already\r\n * stroked centered by the renderer; this makes the intent explicit and ignores\r\n * any author `align`.) */\r\nexport function centered(strokes: StrokeResolved[]): StrokeResolved[] {\r\n return strokes.map(s => (s.align === 0 ? s : { ...s, align: 0 }));\r\n}\r\n\r\n/** Copy a resolved stroke array with every fill layer's opacity scaled by\r\n * `factor`. Used to derive the default minor-line stroke from the major one.\r\n * Every resolved fill carries an `opacity` field, so this is type-uniform. */\r\nexport function dimStroke(strokes: StrokeResolved[], factor: number): StrokeResolved[] {\r\n return strokeOps.resolve(strokes.map(s => ({\r\n ...s,\r\n fill: s.fill.map(f => ({ ...f, opacity: (f.opacity ?? 1) * factor })),\r\n })) as unknown as StrokeProp[]);\r\n}\r\n"]}
@@ -0,0 +1,3 @@
1
+ export * from "./grid-lines.js";
2
+ export * from "./viewport-pattern.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/kit/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA"}
@@ -0,0 +1,3 @@
1
+ export * from "./grid-lines.js";
2
+ export * from "./viewport-pattern.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/kit/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA","sourcesContent":["export * from \"./grid-lines\"\r\nexport * from \"./viewport-pattern\"\r\n"]}
@@ -0,0 +1,36 @@
1
+ import { Camera, ShapeNode, type BoxBounds, type RenderContext2D, type ShapeProps } from "@motionscript/sdk";
2
+ /**
3
+ * Base for backgrounds that fill whatever region is currently visible, rather
4
+ * than a fixed rect. Placed inside a {@link Camera}, the node resolves the
5
+ * world region the camera can currently see (from its `zoom`/`origin`/`heading`)
6
+ * and hands those bounds to {@link renderPattern}, so the subclass only ever
7
+ * generates geometry for what's on screen — no oversized static node sized for
8
+ * the worst-case pan/zoom.
9
+ *
10
+ * With no ancestor `Camera` the node falls back to its own layout rect, so the
11
+ * same pattern doubles as an ordinary full-bleed background.
12
+ *
13
+ * The pattern node is itself a camera child, laid out stack-style at the
14
+ * camera's centre, so its local draw space shares the world origin its siblings
15
+ * use. The visible region is therefore expressed directly in that space: centred
16
+ * on the camera's `origin`, sized to the inverse of the camera transform.
17
+ */
18
+ export declare abstract class ViewportPattern<P extends ShapeProps = ShapeProps> extends ShapeNode<P> {
19
+ /**
20
+ * Fill `bounds` (in this node's local draw space) with the pattern. Called
21
+ * once per render with the currently-visible region. The `centerBounds` for
22
+ * path ops drawn here is `[bounds.x - w/2, bounds.y - h/2, bounds.x + w/2,
23
+ * bounds.y + h/2]`.
24
+ */
25
+ protected abstract renderPattern(draw: RenderContext2D, bounds: BoxBounds): void;
26
+ protected renderSelf(draw: RenderContext2D): void;
27
+ /**
28
+ * The region this node should cover, in its own local draw space. Inside a
29
+ * camera this is the world rect the camera currently sees; otherwise it's the
30
+ * node's own layout rect (a normal background).
31
+ */
32
+ protected visibleBounds(): BoxBounds;
33
+ /** Nearest ancestor {@link Camera}, or `null` when rendered outside one. */
34
+ protected findCamera(): Camera | null;
35
+ }
36
+ //# sourceMappingURL=viewport-pattern.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viewport-pattern.d.ts","sourceRoot":"","sources":["../../src/kit/viewport-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,MAAM,EAEN,SAAS,EACT,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,UAAU,EAClB,MAAM,mBAAmB,CAAC;AAE3B;;;;;;;;;;;;;;;GAeG;AACH,8BAAsB,eAAe,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,CAAE,SAAQ,SAAS,CAAC,CAAC,CAAC;IAEzF;;;;;OAKG;IACH,SAAS,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,SAAS,GAAG,IAAI;IAEhF,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI;IAWjD;;;;OAIG;IACH,SAAS,CAAC,aAAa,IAAI,SAAS;IAuCpC,4EAA4E;IAC5E,SAAS,CAAC,UAAU,IAAI,MAAM,GAAG,IAAI;CAMxC"}
@@ -0,0 +1,77 @@
1
+ import { Camera, Clip, ShapeNode, } from "@motionscript/sdk";
2
+ /**
3
+ * Base for backgrounds that fill whatever region is currently visible, rather
4
+ * than a fixed rect. Placed inside a {@link Camera}, the node resolves the
5
+ * world region the camera can currently see (from its `zoom`/`origin`/`heading`)
6
+ * and hands those bounds to {@link renderPattern}, so the subclass only ever
7
+ * generates geometry for what's on screen — no oversized static node sized for
8
+ * the worst-case pan/zoom.
9
+ *
10
+ * With no ancestor `Camera` the node falls back to its own layout rect, so the
11
+ * same pattern doubles as an ordinary full-bleed background.
12
+ *
13
+ * The pattern node is itself a camera child, laid out stack-style at the
14
+ * camera's centre, so its local draw space shares the world origin its siblings
15
+ * use. The visible region is therefore expressed directly in that space: centred
16
+ * on the camera's `origin`, sized to the inverse of the camera transform.
17
+ */
18
+ export class ViewportPattern extends ShapeNode {
19
+ renderSelf(draw) {
20
+ const bounds = this.visibleBounds();
21
+ // Clip to the visible region so geometry overscanned past the edge (so
22
+ // thick lines slide out instead of popping) trims cleanly. When inside a
23
+ // camera the viewport already clips, but this keeps edge strokes clean
24
+ // and bounds the work in the no-camera fallback too.
25
+ draw.beginClip(new Clip().rect({ x: bounds.x, y: bounds.y, width: bounds.width, height: bounds.height }));
26
+ this.renderPattern(draw, bounds);
27
+ draw.endClip();
28
+ }
29
+ /**
30
+ * The region this node should cover, in its own local draw space. Inside a
31
+ * camera this is the world rect the camera currently sees; otherwise it's the
32
+ * node's own layout rect (a normal background).
33
+ */
34
+ visibleBounds() {
35
+ const camera = this.findCamera();
36
+ if (!camera) {
37
+ // No camera — fill our own cell, centred on this node's origin.
38
+ const w = this.layoutBounds?.width ?? 0;
39
+ const h = this.layoutBounds?.height ?? 0;
40
+ return { x: 0, y: 0, width: w, height: h };
41
+ }
42
+ const vw = camera.measuredWidth;
43
+ const vh = camera.measuredHeight;
44
+ const zoom = camera.zoom || 1;
45
+ const heading = camera.heading;
46
+ // Inverse of the camera scale: a viewport `vw×vh` shows `vw/zoom × vh/zoom`
47
+ // of the world.
48
+ const hw = vw / 2 / zoom;
49
+ const hh = vh / 2 / zoom;
50
+ // With a heading the visible world rect is rotated; take its axis-aligned
51
+ // bounding box so the pattern covers the rotated viewport's full extent.
52
+ let bw = hw;
53
+ let bh = hh;
54
+ if (heading !== 0) {
55
+ const rad = (heading * Math.PI) / 180;
56
+ const cos = Math.abs(Math.cos(rad));
57
+ const sin = Math.abs(Math.sin(rad));
58
+ bw = hw * cos + hh * sin;
59
+ bh = hw * sin + hh * cos;
60
+ }
61
+ // The visible region centres on the camera's `lookAt`, returned in y-UP
62
+ // world space (matching the descriptor convention; the renderer applies
63
+ // the single y-up→canvas flip when the pattern's shapes are drawn). A
64
+ // y-down consumer would have wanted -lookAt.y; we hand back the y-up value.
65
+ const lookAt = camera.lookAt;
66
+ return { x: lookAt.x, y: lookAt.y, width: bw * 2, height: bh * 2 };
67
+ }
68
+ /** Nearest ancestor {@link Camera}, or `null` when rendered outside one. */
69
+ findCamera() {
70
+ for (let n = this.parent; n; n = n.parent) {
71
+ if (n instanceof Camera)
72
+ return n;
73
+ }
74
+ return null;
75
+ }
76
+ }
77
+ //# sourceMappingURL=viewport-pattern.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viewport-pattern.js","sourceRoot":"","sources":["../../src/kit/viewport-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,MAAM,EACN,IAAI,EACJ,SAAS,GAIZ,MAAM,mBAAmB,CAAC;AAE3B;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAgB,eAAmD,SAAQ,SAAY;IAU/E,UAAU,CAAC,IAAqB;QACtC,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QACpC,uEAAuE;QACvE,yEAAyE;QACzE,uEAAuE;QACvE,qDAAqD;QACrD,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAC1G,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACjC,IAAI,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACO,aAAa;QACnB,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QACjC,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,gEAAgE;YAChE,MAAM,CAAC,GAAG,IAAI,CAAC,YAAY,EAAE,KAAK,IAAI,CAAC,CAAC;YACxC,MAAM,CAAC,GAAG,IAAI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EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC;IACvE,CAAC;IAED,4EAA4E;IAClE,UAAU;QAChB,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;YACxC,IAAI,CAAC,YAAY,MAAM;gBAAE,OAAO,CAAC,CAAC;QACtC,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ","sourcesContent":["import {\r\n Camera,\r\n Clip,\r\n ShapeNode,\r\n type BoxBounds,\r\n type RenderContext2D,\r\n type ShapeProps,\r\n} from \"@motionscript/sdk\";\r\n\r\n/**\r\n * Base for backgrounds that fill whatever region is currently visible, rather\r\n * than a fixed rect. Placed inside a {@link Camera}, the node resolves the\r\n * world region the camera can currently see (from its `zoom`/`origin`/`heading`)\r\n * and hands those bounds to {@link renderPattern}, so the subclass only ever\r\n * generates geometry for what's on screen — no oversized static node sized for\r\n * the worst-case pan/zoom.\r\n *\r\n * With no ancestor `Camera` the node falls back to its own layout rect, so the\r\n * same pattern doubles as an ordinary full-bleed background.\r\n *\r\n * The pattern node is itself a camera child, laid out stack-style at the\r\n * camera's centre, so its local draw space shares the world origin its siblings\r\n * use. The visible region is therefore expressed directly in that space: centred\r\n * on the camera's `origin`, sized to the inverse of the camera transform.\r\n */\r\nexport abstract class ViewportPattern<P extends ShapeProps = ShapeProps> extends ShapeNode<P> {\r\n\r\n /**\r\n * Fill `bounds` (in this node's local draw space) with the pattern. Called\r\n * once per render with the currently-visible region. The `centerBounds` for\r\n * path ops drawn here is `[bounds.x - w/2, bounds.y - h/2, bounds.x + w/2,\r\n * bounds.y + h/2]`.\r\n */\r\n protected abstract renderPattern(draw: RenderContext2D, bounds: BoxBounds): void;\r\n\r\n protected renderSelf(draw: RenderContext2D): void {\r\n const bounds = this.visibleBounds();\r\n // Clip to the visible region so geometry overscanned past the edge (so\r\n // thick lines slide out instead of popping) trims cleanly. When inside a\r\n // camera the viewport already clips, but this keeps edge strokes clean\r\n // and bounds the work in the no-camera fallback too.\r\n draw.beginClip(new Clip().rect({ x: bounds.x, y: bounds.y, width: bounds.width, height: bounds.height }));\r\n this.renderPattern(draw, bounds);\r\n draw.endClip();\r\n }\r\n\r\n /**\r\n * The region this node should cover, in its own local draw space. Inside a\r\n * camera this is the world rect the camera currently sees; otherwise it's the\r\n * node's own layout rect (a normal background).\r\n */\r\n protected visibleBounds(): BoxBounds {\r\n const camera = this.findCamera();\r\n if (!camera) {\r\n // No camera — fill our own cell, centred on this node's origin.\r\n const w = this.layoutBounds?.width ?? 0;\r\n const h = this.layoutBounds?.height ?? 0;\r\n return { x: 0, y: 0, width: w, height: h };\r\n }\r\n\r\n const vw = camera.measuredWidth;\r\n const vh = camera.measuredHeight;\r\n const zoom = camera.zoom || 1;\r\n const heading = camera.heading;\r\n\r\n // Inverse of the camera scale: a viewport `vw×vh` shows `vw/zoom × vh/zoom`\r\n // of the world.\r\n const hw = vw / 2 / zoom;\r\n const hh = vh / 2 / zoom;\r\n\r\n // With a heading the visible world rect is rotated; take its axis-aligned\r\n // bounding box so the pattern covers the rotated viewport's full extent.\r\n let bw = hw;\r\n let bh = hh;\r\n if (heading !== 0) {\r\n const rad = (heading * Math.PI) / 180;\r\n const cos = Math.abs(Math.cos(rad));\r\n const sin = Math.abs(Math.sin(rad));\r\n bw = hw * cos + hh * sin;\r\n bh = hw * sin + hh * cos;\r\n }\r\n\r\n // The visible region centres on the camera's `lookAt`, returned in y-UP\r\n // world space (matching the descriptor convention; the renderer applies\r\n // the single y-up→canvas flip when the pattern's shapes are drawn). A\r\n // y-down consumer would have wanted -lookAt.y; we hand back the y-up value.\r\n const lookAt = camera.lookAt;\r\n return { x: lookAt.x, y: lookAt.y, width: bw * 2, height: bh * 2 };\r\n }\r\n\r\n /** Nearest ancestor {@link Camera}, or `null` when rendered outside one. */\r\n protected findCamera(): Camera | null {\r\n for (let n = this.parent; n; n = n.parent) {\r\n if (n instanceof Camera) return n;\r\n }\r\n return null;\r\n }\r\n}\r\n"]}
@@ -0,0 +1,2 @@
1
+ export * from "./line-grid-pattern.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/line-grid-pattern/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from "./line-grid-pattern.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/line-grid-pattern/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA","sourcesContent":["export * from \"./line-grid-pattern\"\r\n"]}
@@ -0,0 +1,30 @@
1
+ import { Clip, ShapeNode, type AssetScope, type NodeConfig, type RenderContext2D, type ShapeProps, type Stroke, type StrokeResolved, type Vector2 } from "@motionscript/sdk";
2
+ export interface LineGridPatternProps extends ShapeProps {
3
+ /** Cells along each axis: `divisions` of 4 draws 5 major lines per axis. */
4
+ divisions: number;
5
+ /** Finer cells each division is split into. 1 draws no minor lines; 2 adds one per division. */
6
+ subdivisions: number;
7
+ /** Stroke for the minor lines. Defaults to the major `stroke` at half opacity when `subdivisions > 1`. */
8
+ subStroke?: Stroke;
9
+ /** Pans the grid. Lines wrap and tile, so the rect stays full while `offset` scrolls it. */
10
+ offset: Vector2;
11
+ }
12
+ /**
13
+ * A rectangular grid of lines filling the node's layout rect.
14
+ *
15
+ * `stroke` paints the major lines and `subStroke` the minor ones, each as a
16
+ * single union path. `fill` and `shadow` cover the whole rect, behind the lines.
17
+ */
18
+ export declare class LineGridPattern extends ShapeNode<LineGridPatternProps> {
19
+ readonly divisions: number;
20
+ readonly subdivisions: number;
21
+ get subStroke(): StrokeResolved[];
22
+ set subStroke(value: Stroke);
23
+ readonly offset: Vector2;
24
+ constructor(props: NodeConfig<LineGridPattern, LineGridPatternProps>);
25
+ declareAssets(assets: AssetScope): void;
26
+ protected renderSelf(draw: RenderContext2D): void;
27
+ protected clipSelf(): Clip;
28
+ private _gridPaths;
29
+ }
30
+ //# sourceMappingURL=line-grid-pattern.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"line-grid-pattern.d.ts","sourceRoot":"","sources":["../../src/line-grid-pattern/line-grid-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,IAAI,EAEJ,SAAS,EAKT,KAAK,UAAU,EACf,KAAK,UAAU,EAGf,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,MAAM,EACX,KAAK,cAAc,EACnB,KAAK,OAAO,EACf,MAAM,mBAAmB,CAAC;AAI3B,MAAM,WAAW,oBAAqB,SAAQ,UAAU;IACpD,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAC;IAClB,gGAAgG;IAChG,YAAY,EAAE,MAAM,CAAC;IACrB,0GAA0G;IAC1G,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4FAA4F;IAC5F,MAAM,EAAE,OAAO,CAAC;CACnB;AAED;;;;;GAKG;AACH,qBACa,eAAgB,SAAQ,SAAS,CAAC,oBAAoB,CAAC;IAEhE,SAA2C,SAAS,EAAE,MAAM,CAAC;IAC7D,SAA2C,YAAY,EAAE,MAAM,CAAC;IAEhE,IACI,SAAS,IAAI,cAAc,EAAE,CAAuB;IACxD,IAAI,SAAS,CAAC,KAAK,EAAE,MAAM,EAAkC;IAC7D,SACiB,MAAM,EAAE,OAAO,CAAC;gBAErB,KAAK,EAAE,UAAU,CAAC,eAAe,EAAE,oBAAoB,CAAC;IAQ3D,aAAa,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAKhD,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI;cAmC9B,QAAQ,IAAI,IAAI;IASnC,OAAO,CAAC,UAAU;CAiBrB"}
@@ -0,0 +1,96 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { Clip, Graphics2D, ShapeNode, lerpVector2, node, property, strokeProperty, } from "@motionscript/sdk";
8
+ import { centered, dimStroke, gridLinePaths, maxWeight } from "../kit/index.js";
9
+ /**
10
+ * A rectangular grid of lines filling the node's layout rect.
11
+ *
12
+ * `stroke` paints the major lines and `subStroke` the minor ones, each as a
13
+ * single union path. `fill` and `shadow` cover the whole rect, behind the lines.
14
+ */
15
+ let LineGridPattern = class LineGridPattern extends ShapeNode {
16
+ // Asymmetric accessor like `ShapeNode.stroke`: reads yield `StrokeResolved[]`, writes accept `Stroke`.
17
+ get subStroke() { return undefined; }
18
+ set subStroke(value) { }
19
+ constructor(props) {
20
+ super(props);
21
+ if (props.subStroke === undefined && props.stroke !== undefined && this.subdivisions > 1) {
22
+ this.set({ subStroke: dimStroke(this.stroke, 0.5) });
23
+ }
24
+ }
25
+ declareAssets(assets) {
26
+ super.declareAssets(assets);
27
+ for (const stroke of this.subStroke)
28
+ assets.fill(stroke.fill);
29
+ }
30
+ renderSelf(draw) {
31
+ const width = this.layoutBounds.width;
32
+ const height = this.layoutBounds.height;
33
+ const centerBounds = [-width / 2, -height / 2, width / 2, height / 2];
34
+ draw.draw(new Graphics2D()
35
+ .rect({ width, height, start: this.start, end: this.end })
36
+ .shadow(this.shadow)
37
+ .fill(this.fill));
38
+ const divisions = Math.max(1, Math.floor(this.divisions));
39
+ const subdivisions = Math.max(1, Math.floor(this.subdivisions));
40
+ // Lines overscan the rect by half the thickest stroke and are clipped to it, so a
41
+ // thick line slides out under the clip instead of popping at the boundary.
42
+ const major = centered(this.stroke);
43
+ const minorStroke = centered(this.subStroke);
44
+ const overscan = Math.max(maxWeight(major), maxWeight(minorStroke)) / 2;
45
+ const { major: majorLines, minor: minorLines } = this._gridPaths(width, height, divisions, subdivisions, overscan);
46
+ draw.beginClip(new Clip().rect({ width, height }));
47
+ // Minor lines first so the major lines sit on top.
48
+ if (subdivisions > 1 && minorStroke.length > 0 && minorLines.length > 0) {
49
+ draw.draw(new Graphics2D()
50
+ .path({ data: minorLines, centerBounds })
51
+ .stroke(minorStroke));
52
+ }
53
+ if (majorLines.length > 0) {
54
+ draw.draw(new Graphics2D()
55
+ .path({ data: majorLines, centerBounds })
56
+ .stroke(major));
57
+ }
58
+ draw.endClip();
59
+ }
60
+ clipSelf() {
61
+ return new Clip().rect({
62
+ width: this.layoutBounds.width,
63
+ height: this.layoutBounds.height,
64
+ });
65
+ }
66
+ // One multi-subpath path per group, so each stroke paints its lines as a union with no
67
+ // destructive boolean op (which would erase open lines).
68
+ _gridPaths(width, height, divisions, subdivisions, overscan) {
69
+ // Inset by `overscan` so the outermost lines sit fully inside the rect and are not
70
+ // trimmed to half weight by the clip.
71
+ const cols = divisions * subdivisions;
72
+ const innerW = Math.max(0, width - 2 * overscan);
73
+ const innerH = Math.max(0, height - 2 * overscan);
74
+ const insetX = width / 2 - overscan;
75
+ const insetY = height / 2 - overscan;
76
+ // Anchored at the near edge, so a line sits on each edge of the box for any count of cells.
77
+ return gridLinePaths({ min: -insetX, max: insetX, step: innerW / cols, offset: this.offset.x, anchor: -insetX }, { min: -insetY, max: insetY, step: innerH / cols, offset: this.offset.y, anchor: -insetY }, subdivisions, overscan);
78
+ }
79
+ };
80
+ __decorate([
81
+ property({ default: 4 })
82
+ ], LineGridPattern.prototype, "divisions", void 0);
83
+ __decorate([
84
+ property({ default: 1 })
85
+ ], LineGridPattern.prototype, "subdivisions", void 0);
86
+ __decorate([
87
+ strokeProperty()
88
+ ], LineGridPattern.prototype, "subStroke", null);
89
+ __decorate([
90
+ property({ default: { x: 0, y: 0 }, tween: lerpVector2 })
91
+ ], LineGridPattern.prototype, "offset", void 0);
92
+ LineGridPattern = __decorate([
93
+ node({ key: "lineGridPattern", parentKey: "shape", forkable: true })
94
+ ], LineGridPattern);
95
+ export { LineGridPattern };
96
+ //# sourceMappingURL=line-grid-pattern.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"line-grid-pattern.js","sourceRoot":"","sources":["../../src/line-grid-pattern/line-grid-pattern.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACH,IAAI,EACJ,UAAU,EACV,SAAS,EACT,WAAW,EACX,IAAI,EACJ,QAAQ,EACR,cAAc,GAUjB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAavE;;;;;GAKG;AAEI,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,SAA+B;IAIhE,uGAAuG;IAEvG,IAAI,SAAS,KAAuB,OAAO,SAAU,CAAC,CAAC,CAAC;IACxD,IAAI,SAAS,CAAC,KAAa,IAAiC,CAAC;IAI7D,YAAY,KAAwD;QAChE,KAAK,CAAC,KAAK,CAAC,CAAC;QAEb,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,IAAI,IAAI,CAAC,YAAY,GAAG,CAAC,EAAE,CAAC;YACvF,IAAI,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,MAA0B,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;QAC7E,CAAC;IACL,CAAC;IAEQ,aAAa,CAAC,MAAkB;QACrC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAC5B,KAAK,MAAM,MAAM,IAAI,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Node,\r\n lerpVector2,\r\n node,\r\n property,\r\n strokeProperty,\r\n type AssetScope,\r\n type NodeConfig,\r\n type PathBounds,\r\n type PathCommand,\r\n type RenderContext2D,\r\n type ShapeProps,\r\n type Stroke,\r\n type StrokeResolved,\r\n type Vector2,\r\n} from \"@motionscript/sdk\";\r\n\r\nimport { centered, dimStroke, gridLinePaths, maxWeight } from \"../kit\";\r\n\r\nexport interface LineGridPatternProps extends ShapeProps {\r\n /** Cells along each axis: `divisions` of 4 draws 5 major lines per axis. */\r\n divisions: number;\r\n /** Finer cells each division is split into. 1 draws no minor lines; 2 adds one per division. */\r\n subdivisions: number;\r\n /** Stroke for the minor lines. Defaults to the major `stroke` at half opacity when `subdivisions > 1`. */\r\n subStroke?: Stroke;\r\n /** Pans the grid. Lines wrap and tile, so the rect stays full while `offset` scrolls it. */\r\n offset: Vector2;\r\n}\r\n\r\n/**\r\n * A rectangular grid of lines filling the node's layout rect.\r\n *\r\n * `stroke` paints the major lines and `subStroke` the minor ones, each as a\r\n * single union path. `fill` and `shadow` cover the whole rect, behind the lines.\r\n */\r\n@node({ key: \"lineGridPattern\", parentKey: \"shape\", forkable: true })\r\nexport class LineGridPattern extends ShapeNode<LineGridPatternProps> {\r\n\r\n @property({ default: 4 }) declare readonly divisions: number;\r\n @property({ default: 1 }) declare readonly subdivisions: number;\r\n // Asymmetric accessor like `ShapeNode.stroke`: reads yield `StrokeResolved[]`, writes accept `Stroke`.\r\n @strokeProperty()\r\n get subStroke(): StrokeResolved[] { return undefined!; }\r\n set subStroke(value: Stroke) { /* installed by @property */ }\r\n @property({ default: { x: 0, y: 0 }, tween: lerpVector2 })\r\n declare readonly offset: Vector2;\r\n\r\n constructor(props: NodeConfig<LineGridPattern, LineGridPatternProps>) {\r\n super(props);\r\n\r\n if (props.subStroke === undefined && props.stroke !== undefined && this.subdivisions > 1) {\r\n this.set({ subStroke: dimStroke(this.stroke as StrokeResolved[], 0.5) });\r\n }\r\n }\r\n\r\n override declareAssets(assets: AssetScope): void {\r\n super.declareAssets(assets);\r\n for (const stroke of this.subStroke) assets.fill(stroke.fill);\r\n }\r\n\r\n protected renderSelf(draw: RenderContext2D): void {\r\n const width = this.layoutBounds.width;\r\n const height = this.layoutBounds.height;\r\n const centerBounds: PathBounds = [-width / 2, -height / 2, width / 2, height / 2];\r\n\r\n draw.draw(new Graphics2D()\r\n .rect({ width, height, start: this.start, end: this.end })\r\n .shadow(this.shadow)\r\n .fill(this.fill));\r\n\r\n const divisions = Math.max(1, Math.floor(this.divisions));\r\n const subdivisions = Math.max(1, Math.floor(this.subdivisions));\r\n\r\n // Lines overscan the rect by half the thickest stroke and are clipped to it, so a\r\n // thick line slides out under the clip instead of popping at the boundary.\r\n const major = centered(this.stroke as StrokeResolved[]);\r\n const minorStroke = centered(this.subStroke as StrokeResolved[]);\r\n const overscan = Math.max(maxWeight(major), maxWeight(minorStroke)) / 2;\r\n const { major: majorLines, minor: minorLines } = this._gridPaths(width, height, divisions, subdivisions, overscan);\r\n\r\n draw.beginClip(new Clip().rect({ width, height }));\r\n // Minor lines first so the major lines sit on top.\r\n if (subdivisions > 1 && minorStroke.length > 0 && minorLines.length > 0) {\r\n draw.draw(new Graphics2D()\r\n .path({ data: minorLines, centerBounds })\r\n .stroke(minorStroke));\r\n }\r\n if (majorLines.length > 0) {\r\n draw.draw(new Graphics2D()\r\n .path({ data: majorLines, centerBounds })\r\n .stroke(major));\r\n }\r\n draw.endClip();\r\n }\r\n\r\n protected override clipSelf(): Clip {\r\n return new Clip().rect({\r\n width: this.layoutBounds.width,\r\n height: this.layoutBounds.height,\r\n });\r\n }\r\n\r\n // One multi-subpath path per group, so each stroke paints its lines as a union with no\r\n // destructive boolean op (which would erase open lines).\r\n private _gridPaths(width: number, height: number, divisions: number, subdivisions: number, overscan: number): { major: PathCommand[]; minor: PathCommand[] } {\r\n // Inset by `overscan` so the outermost lines sit fully inside the rect and are not\r\n // trimmed to half weight by the clip.\r\n const cols = divisions * subdivisions;\r\n const innerW = Math.max(0, width - 2 * overscan);\r\n const innerH = Math.max(0, height - 2 * overscan);\r\n const insetX = width / 2 - overscan;\r\n const insetY = height / 2 - overscan;\r\n\r\n // Anchored at the near edge, so a line sits on each edge of the box for any count of cells.\r\n return gridLinePaths(\r\n { min: -insetX, max: insetX, step: innerW / cols, offset: this.offset.x, anchor: -insetX },\r\n { min: -insetY, max: insetY, step: innerH / cols, offset: this.offset.y, anchor: -insetY },\r\n subdivisions,\r\n overscan,\r\n );\r\n }\r\n}\r\n"]}
@@ -0,0 +1,14 @@
1
+ import { DotGridPattern } from "./dot-grid-pattern/index.js";
2
+ import { GridPattern } from "./grid-pattern/index.js";
3
+ import { LineGridPattern } from "./line-grid-pattern/index.js";
4
+ /**
5
+ * Every node type this package publishes.
6
+ *
7
+ * A host registers these by handing the array to an engine —
8
+ * `new Engine(platform, { nodes: NODES })` — which reads each class's `@node()`
9
+ * key. Listing class **values** is also what survives bundling: this package
10
+ * declares `sideEffects: false`, and a document names a node type by string, so
11
+ * an import kept only for its side effect is exactly what gets shaken out.
12
+ */
13
+ export declare const NODES: (typeof LineGridPattern | typeof DotGridPattern | typeof GridPattern)[];
14
+ //# sourceMappingURL=nodes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../src/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAErD;;;;;;;;GAQG;AACH,eAAO,MAAM,KAAK,yEAAiD,CAAA"}
package/dist/nodes.js ADDED
@@ -0,0 +1,14 @@
1
+ import { DotGridPattern } from "./dot-grid-pattern/index.js";
2
+ import { GridPattern } from "./grid-pattern/index.js";
3
+ import { LineGridPattern } from "./line-grid-pattern/index.js";
4
+ /**
5
+ * Every node type this package publishes.
6
+ *
7
+ * A host registers these by handing the array to an engine —
8
+ * `new Engine(platform, { nodes: NODES })` — which reads each class's `@node()`
9
+ * key. Listing class **values** is also what survives bundling: this package
10
+ * declares `sideEffects: false`, and a document names a node type by string, so
11
+ * an import kept only for its side effect is exactly what gets shaken out.
12
+ */
13
+ export const NODES = [LineGridPattern, DotGridPattern, GridPattern];
14
+ //# sourceMappingURL=nodes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodes.js","sourceRoot":"","sources":["../src/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAErD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,eAAe,EAAE,cAAc,EAAE,WAAW,CAAC,CAAA","sourcesContent":["import { DotGridPattern } from \"./dot-grid-pattern\"\r\nimport { GridPattern } from \"./grid-pattern\"\r\nimport { LineGridPattern } from \"./line-grid-pattern\"\r\n\r\n/**\r\n * Every node type this package publishes.\r\n *\r\n * A host registers these by handing the array to an engine —\r\n * `new Engine(platform, { nodes: NODES })` — which reads each class's `@node()`\r\n * key. Listing class **values** is also what survives bundling: this package\r\n * declares `sideEffects: false`, and a document names a node type by string, so\r\n * an import kept only for its side effect is exactly what gets shaken out.\r\n */\r\nexport const NODES = [LineGridPattern, DotGridPattern, GridPattern]\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,75 @@
1
1
  {
2
2
  "name": "@motionscript/patterns",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0-alpha.4",
4
+ "type": "module",
5
+ "description": "Background patterns for Motion Script: line and dot grids that fill a box, and an infinite grid that fills whatever a camera can see.",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/motionscript-dev/motionscript.git",
9
+ "directory": "packages/components/patterns"
10
+ },
11
+ "homepage": "https://motionscript.dev",
12
+ "bugs": {
13
+ "url": "https://github.com/motionscript-dev/motionscript/issues"
14
+ },
15
+ "main": "dist/index.js",
16
+ "types": "dist/index.d.ts",
17
+ "sideEffects": false,
18
+ "files": [
19
+ "NOTICE",
20
+ "dist",
21
+ "src",
22
+ "registry.json",
23
+ "CHANGELOG.md",
24
+ "!dist/**/*.tsbuildinfo",
25
+ "!src/**/tests/**",
26
+ "!src/**/*.test.ts",
27
+ "!src/**/*.test.tsx",
28
+ "!src/**/*.fixtures.ts"
29
+ ],
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "exports": {
34
+ ".": {
35
+ "types": "./dist/index.d.ts",
36
+ "default": "./dist/index.js"
37
+ },
38
+ "./kit": {
39
+ "types": "./dist/engine.d.ts",
40
+ "default": "./dist/engine.js"
41
+ }
42
+ },
43
+ "keywords": [
44
+ "motion-script",
45
+ "motion script",
46
+ "grid",
47
+ "pattern",
48
+ "background",
49
+ "animation"
50
+ ],
51
+ "license": "Apache-2.0",
52
+ "peerDependencies": {
53
+ "@motionscript/sdk": "^0.1.0-alpha.4"
54
+ },
55
+ "devDependencies": {
56
+ "@types/node": "^25.6.2",
57
+ "eslint": "^9.39.4",
58
+ "eslint-import-resolver-typescript": "^4.4.4",
59
+ "eslint-plugin-import-x": "^4.16.1",
60
+ "tsc-alias": "^1.8.16",
61
+ "typescript": "^6.0.3",
62
+ "typescript-eslint": "^8.48.0",
63
+ "vitest": "^4.1.5",
64
+ "@motionscript/core": "0.1.0-alpha.4",
65
+ "@motionscript/sdk": "0.1.0-alpha.4"
66
+ },
67
+ "scripts": {
68
+ "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json --resolve-full-paths && node ../../../scripts/build-browser.mjs",
69
+ "dev": "tsc -p tsconfig.build.json --watch & tsc-alias -p tsconfig.build.json --resolve-full-paths -w",
70
+ "clean": "rimraf --glob dist .turbo *.tsbuildinfo",
71
+ "test": "vitest",
72
+ "lint": "eslint .",
73
+ "typecheck": "tsc -p tsconfig.json --noEmit"
74
+ }
6
75
  }
package/registry.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "kit": {
3
+ "barrel": "src/engine.ts",
4
+ "specifier": "@motionscript/patterns/kit"
5
+ },
6
+ "items": [
7
+ {
8
+ "name": "line-grid-pattern",
9
+ "description": "A rectangular grid of lines in a fixed box, with minor lines between the major ones and an offset that scrolls it.",
10
+ "root": "src/line-grid-pattern",
11
+ "files": ["index.ts", "line-grid-pattern.ts"]
12
+ },
13
+ {
14
+ "name": "dot-grid-pattern",
15
+ "description": "A field of dots on the same divisions and offset as a line grid, so one laid over the other lines up.",
16
+ "root": "src/dot-grid-pattern",
17
+ "files": ["index.ts", "dot-grid-pattern.ts"]
18
+ },
19
+ {
20
+ "name": "grid-pattern",
21
+ "description": "An infinite world-anchored line grid that fills whatever the camera can see, with dashes locked to the world.",
22
+ "root": "src/grid-pattern",
23
+ "files": ["index.ts", "grid-pattern.ts"]
24
+ }
25
+ ]
26
+ }