@motionscript/patterns 0.1.0-alpha.7 → 0.1.0-alpha.9

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 (40) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/LICENSE +201 -201
  3. package/NOTICE +49 -48
  4. package/README.md +83 -83
  5. package/dist/browser/chunks/{chunk-REWLNFZ2.js → chunk-FXDYEY4R.js} +1 -1
  6. package/dist/browser/chunks/chunk-FXDYEY4R.js.map +7 -0
  7. package/dist/browser/index.js +1 -1
  8. package/dist/browser/index.js.map +1 -1
  9. package/dist/browser/kit.js +1 -1
  10. package/dist/browser/manifest.json +1 -1
  11. package/dist/dot-grid-pattern/dot-grid-pattern.js.map +1 -1
  12. package/dist/dot-grid-pattern/index.js.map +1 -1
  13. package/dist/engine.d.ts +1 -1
  14. package/dist/engine.js +1 -1
  15. package/dist/engine.js.map +1 -1
  16. package/dist/grid-pattern/grid-pattern.js.map +1 -1
  17. package/dist/grid-pattern/index.js.map +1 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/kit/grid-lines.js.map +1 -1
  20. package/dist/kit/index.js.map +1 -1
  21. package/dist/kit/viewport-pattern.d.ts.map +1 -1
  22. package/dist/kit/viewport-pattern.js.map +1 -1
  23. package/dist/line-grid-pattern/index.js.map +1 -1
  24. package/dist/line-grid-pattern/line-grid-pattern.js.map +1 -1
  25. package/dist/nodes.js.map +1 -1
  26. package/package.json +5 -4
  27. package/registry.json +26 -26
  28. package/src/dot-grid-pattern/dot-grid-pattern.ts +155 -155
  29. package/src/dot-grid-pattern/index.ts +1 -1
  30. package/src/engine.ts +11 -11
  31. package/src/grid-pattern/grid-pattern.ts +176 -176
  32. package/src/grid-pattern/index.ts +1 -1
  33. package/src/index.ts +5 -5
  34. package/src/kit/grid-lines.ts +223 -223
  35. package/src/kit/index.ts +2 -2
  36. package/src/kit/viewport-pattern.ts +109 -109
  37. package/src/line-grid-pattern/index.ts +1 -1
  38. package/src/line-grid-pattern/line-grid-pattern.ts +117 -117
  39. package/src/nodes.ts +27 -27
  40. package/dist/browser/chunks/chunk-REWLNFZ2.js.map +0 -7
@@ -1 +1 @@
1
- {"version":3,"file":"grid-lines.js","sourceRoot":"","sources":["../../src/kit/grid-lines.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAuE,MAAM,mBAAmB,CAAC;AAsDnH;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,SAAS,CACrB,CAAW,EACX,CAAW,EACX,YAAoB,EACpB,QAAgB,EAChB,KAAK,GAAG,CAAC;IAET,MAAM,aAAa,GAAa,EAAE,CAAC;IACnC,MAAM,aAAa,GAAa,EAAE,CAAC;IACnC,MAAM,eAAe,GAAa,EAAE,CAAC;IACrC,MAAM,eAAe,GAAa,EAAE,CAAC;IAErC,4EAA4E;IAC5E,8EAA8E;IAC9E,MAAM,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,GAAG,QAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IAC5E,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,GAAG,QAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9E,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,GAAG,QAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7E,MAAM,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,GAAG,QAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IAE7E,aAAa,CAAC,CAAC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I,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAChG,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AAED,0DAA0D;AAC1D,SAAS,OAAO,CAAC,IAAa;IAC1B,OAAO,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC,CAAE,IAAsB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACzE,CAAC","sourcesContent":["import { strokeOps, type PathCommand, type Stroke, 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\r\nconst SUB_STROKES = new WeakMap<object, StrokeResolved[]>();\r\n\r\n/**\r\n * The minor-line stroke of a pattern built with a `stroke` and no `subStroke`:\r\n * the major one at half opacity, when it was built with minor lines. Read off\r\n * what the pattern was built with (`given`), so it is not kept in step with a\r\n * stroke written later.\r\n */\r\nexport function defaultSubStroke(given: Readonly<Record<string, unknown>>): StrokeResolved[] {\r\n let sub = SUB_STROKES.get(given);\r\n if (!sub) {\r\n const stroke = valueOf(given.stroke) as Stroke | undefined;\r\n const subdivisions = (valueOf(given.subdivisions) as number | undefined) ?? 1;\r\n sub = stroke !== undefined && subdivisions > 1 ? dimStroke(strokeOps.resolve(stroke), 0.5) : [];\r\n SUB_STROKES.set(given, sub);\r\n }\r\n return sub;\r\n}\r\n\r\n/** A prop as it stood when given: a binding read once. */\r\nfunction valueOf(prop: unknown): unknown {\r\n return typeof prop === \"function\" ? (prop as () => unknown)() : prop;\r\n}\r\n"]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CAAC,EAAE,CAAC;QAChG,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AAED,0DAA0D;AAC1D,SAAS,OAAO,CAAC,IAAa;IAC1B,OAAO,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC,CAAE,IAAsB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACzE,CAAC","sourcesContent":["import { strokeOps, type PathCommand, type Stroke, type StrokeProp, type StrokeResolved } from \"@motionscript/sdk\";\n\n/**\n * Shared geometry for line grids. Both {@link LineGridPattern} (a fixed grid filling\n * its layout rect) and {@link GridPattern} (an infinite grid tiled across the\n * camera's visible region) build the same multi-subpath line paths from these\n * helpers — they differ only in how the extent and step are chosen.\n *\n * Lines are tiled by the minor step and panned by an origin offset: every\n * position within the extent (grown by `overscan` so thick lines clip out\n * smoothly) is emitted regardless of the offset, so the area always stays full\n * and animating the offset scrolls the grid. The lattice starts at the axis's\n * `anchor` (the world origin unless it says otherwise). A tile whose index\n * aligns to the division grid is major; the rest are minor. Each is built as a\n * single multi-subpath path so the trailing stroke paints every line as one\n * union with no destructive boolean op (which would erase the open lines).\n */\n\n/** A grid extent on one axis: lines tile within `[min, max]`, on a lattice that starts at `anchor`. */\nexport interface GridAxis {\n /** Minimum coordinate (typically negative). */\n min: number;\n /** Maximum coordinate. */\n max: number;\n /** Spacing between adjacent (minor) lines. */\n step: number;\n /** Pan offset in pixels along this axis. */\n offset: number;\n /**\n * Where the lattice starts: a line sits at `anchor + n * step`, and the tile\n * index `n` that decides which lines are major counts from there. Omitted it is 0, the\n * world origin, which is what a grid that follows a camera keeps. A grid with a box of its\n * own sets it to `min`, so the box's edges are lines whatever the count of cells.\n */\n anchor?: number;\n}\n\n/** The resolved grid: where each line sits and how far it runs. Vertical lines\n * sit at x = `verticalX[i]` and run from `top` to `bottom`; horizontal lines sit\n * at y = `horizontalY[i]` and run from `left` to `right`. Positions are split\n * into major (division) and minor (subdivision) lines. */\nexport interface GridLines {\n /** y-extent every vertical line spans. */\n top: number;\n bottom: number;\n /** x-extent every horizontal line spans. */\n left: number;\n right: number;\n verticalMajor: number[];\n verticalMinor: number[];\n horizontalMajor: number[];\n horizontalMinor: number[];\n}\n\n/**\n * Resolve the grid for the given per-axis extents: the cross-axis span and the\n * major/minor line positions on each axis. Vertical lines span the full y\n * extent; horizontal lines span the full x extent. Both spans are grown by\n * `overscan` so a thick line slides out under the clip instead of popping, and\n * snapped outward to the grid so the endpoints sit on stable world positions\n * (a line's start stays fixed as the camera pans, so a dashed stroke anchored to\n * it doesn't crawl).\n *\n * `cycle` (the dash period, when dashed) snaps the cross-axis span to a whole\n * number of dash cycles too, so each parallel line is the same dash-aligned\n * length and the renderer's per-path dash-fit becomes a no-op (no per-frame\n * resizing of the dashes as lines enter and leave view).\n */\nexport function gridLines(\n x: GridAxis,\n y: GridAxis,\n subdivisions: number,\n overscan: number,\n cycle = 0,\n): GridLines {\n const verticalMajor: number[] = [];\n const verticalMinor: number[] = [];\n const horizontalMajor: number[] = [];\n const horizontalMinor: number[] = [];\n\n // Span each line across the cross axis, snapped outward to the grid (and to\n // the dash cycle when dashed) so the endpoints sit on stable world positions.\n const top = snapSpan(y.min - overscan, y.step, y.offset, cycle, Math.floor);\n const bottom = snapSpan(y.max + overscan, y.step, y.offset, cycle, Math.ceil);\n const left = snapSpan(x.min - overscan, x.step, x.offset, cycle, Math.floor);\n const right = snapSpan(x.max + overscan, x.step, x.offset, cycle, Math.ceil);\n\n addTiledLines(x.min, x.max, x.step, x.offset, subdivisions, overscan, (px, isMajor) => {\n (isMajor ? verticalMajor : verticalMinor).push(px);\n }, x.anchor);\n addTiledLines(y.min, y.max, y.step, y.offset, subdivisions, overscan, (py, isMajor) => {\n (isMajor ? horizontalMajor : horizontalMinor).push(py);\n }, y.anchor);\n\n return { top, bottom, left, right, verticalMajor, verticalMinor, horizontalMajor, horizontalMinor };\n}\n\n/**\n * Build the grid lines as multi-subpath path commands, split into the major\n * (division) lines and the minor (subdivision) lines, for the given per-axis\n * extents. Every line in a group shares one stroke (drawn as one union path), so\n * this is the path for solid strokes; dashed strokes that must stay world-locked\n * draw per line from {@link gridLines} instead.\n */\nexport function gridLinePaths(\n x: GridAxis,\n y: GridAxis,\n subdivisions: number,\n overscan: number,\n): { major: PathCommand[]; minor: PathCommand[] } {\n const g = gridLines(x, y, subdivisions, overscan);\n const major: PathCommand[] = [];\n const minor: PathCommand[] = [];\n for (const px of g.verticalMajor) major.push({ type: \"M\", x: px, y: g.top }, { type: \"L\", x: px, y: g.bottom });\n for (const px of g.verticalMinor) minor.push({ type: \"M\", x: px, y: g.top }, { type: \"L\", x: px, y: g.bottom });\n for (const py of g.horizontalMajor) major.push({ type: \"M\", x: g.left, y: py }, { type: \"L\", x: g.right, y: py });\n for (const py of g.horizontalMinor) minor.push({ type: \"M\", x: g.left, y: py }, { type: \"L\", x: g.right, y: py });\n return { major, minor };\n}\n\n// Snap `pos` outward to a stable world position so a dashed line's start stays\n// fixed as the viewport moves (the renderer anchors dash phase to the subpath\n// start). Snap to the grid line lattice (`n*step + offset`); when a dash `cycle`\n// is given, snap to the dash lattice instead (`n*cycle`, anchored to world 0) so\n// every parallel line is the same whole number of cycles long and the renderer's\n// per-path dash-fit stays a no-op. `round` is `Math.floor` to snap below, `ceil`\n// to snap above. The lattice is the one about 0 whatever an axis's `anchor`: a span\n// only has to reach past the edge, and a line's ends stay where they always were.\nfunction snapSpan(pos: number, step: number, offset: number, cycle: number, round: (n: number) => number): number {\n if (cycle > 0) return round(pos / cycle) * cycle;\n if (step <= 0) return pos;\n return round((pos - offset) / step) * step + offset;\n}\n\n/**\n * Emit every grid line position in `[min, max]` (grown by `overscan` on each\n * end) for a grid of spacing `step`, panned by `offset` px. Without panning the\n * lattice starts at `anchor` (0 unless given) and its tile indices count outward\n * from there; the line at tile index `n` is major when `n` is a multiple of\n * `subdivisions`. The pan shifts each position by `offset` while keeping the\n * area full, so `n` is taken relative to the un-panned lattice (offset folded\n * out) to keep classification stable as it scrolls.\n *\n * A fixed grid anchors at `min`, so its first line is on the box's edge and the\n * last is too whenever the extent is a whole number of steps. An infinite grid\n * keeps the default, so its lines stay on the world's lattice.\n */\nexport function addTiledLines(\n min: number,\n max: number,\n step: number,\n offset: number,\n subdivisions: number,\n overscan: number,\n emit: (pos: number, isMajor: boolean) => void,\n anchor = 0,\n): void {\n if (step <= 0) return;\n // First/last tile index whose panned position is within the overscanned\n // [min, max]. Positions are `anchor + n*step + offset` (n=0 sits on the\n // anchor). A small epsilon keeps a line that lands exactly on an edge (an\n // anchor at `min`, or a world lattice that reaches it) from being dropped by FP error.\n const eps = step * 1e-6;\n const startN = Math.ceil((min - overscan - offset - anchor - eps) / step);\n const endN = Math.floor((max + overscan - offset - anchor + eps) / step);\n for (let n = startN; n <= endN; n++) {\n const pos = anchor + n * step + offset;\n // mod that stays non-negative for negative n.\n const isMajor = ((n % subdivisions) + subdivisions) % subdivisions === 0;\n emit(pos, isMajor);\n }\n}\n\n/** Largest stroke weight across the layers of a resolved stroke array. Used to\n * overscan the tiling so a thick line stays drawn until fully off the area. */\nexport function maxWeight(strokes: StrokeResolved[]): number {\n let max = 0;\n for (const s of strokes) if (s.weight > max) max = s.weight;\n return max;\n}\n\n/** Force every layer of a resolved stroke array to centered alignment. Grid\n * lines are open paths, not a closed region, so inside/outside alignment is\n * meaningless — they always straddle their position. (Open paths are already\n * stroked centered by the renderer; this makes the intent explicit and ignores\n * any author `align`.) */\nexport function centered(strokes: StrokeResolved[]): StrokeResolved[] {\n return strokes.map(s => (s.align === 0 ? s : { ...s, align: 0 }));\n}\n\n/** Copy a resolved stroke array with every fill layer's opacity scaled by\n * `factor`. Used to derive the default minor-line stroke from the major one.\n * Every resolved fill carries an `opacity` field, so this is type-uniform. */\nexport function dimStroke(strokes: StrokeResolved[], factor: number): StrokeResolved[] {\n return strokeOps.resolve(strokes.map(s => ({\n ...s,\n fill: s.fill.map(f => ({ ...f, opacity: (f.opacity ?? 1) * factor })),\n })) as unknown as StrokeProp[]);\n}\n\nconst SUB_STROKES = new WeakMap<object, StrokeResolved[]>();\n\n/**\n * The minor-line stroke of a pattern built with a `stroke` and no `subStroke`:\n * the major one at half opacity, when it was built with minor lines. Read off\n * what the pattern was built with (`given`), so it is not kept in step with a\n * stroke written later.\n */\nexport function defaultSubStroke(given: Readonly<Record<string, unknown>>): StrokeResolved[] {\n let sub = SUB_STROKES.get(given);\n if (!sub) {\n const stroke = valueOf(given.stroke) as Stroke | undefined;\n const subdivisions = (valueOf(given.subdivisions) as number | undefined) ?? 1;\n sub = stroke !== undefined && subdivisions > 1 ? dimStroke(strokeOps.resolve(stroke), 0.5) : [];\n SUB_STROKES.set(given, sub);\n }\n return sub;\n}\n\n/** A prop as it stood when given: a binding read once. */\nfunction valueOf(prop: unknown): unknown {\n return typeof prop === \"function\" ? (prop as () => unknown)() : prop;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/kit/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,OAAO,KAAK,eAAe,MAAM,oBAAoB,CAAA","sourcesContent":["export * from \"./grid-lines\"\r\nexport * as ViewportPattern from \"./viewport-pattern\"\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/kit/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,OAAO,KAAK,eAAe,MAAM,oBAAoB,CAAA","sourcesContent":["export * from \"./grid-lines\"\nexport * as ViewportPattern from \"./viewport-pattern\"\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"viewport-pattern.d.ts","sourceRoot":"","sources":["../../src/kit/viewport-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,IAAI,EAEJ,KAAK,EACL,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,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AAC,EAAE,CAAC;AACvE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,IAAI,CAAC,GAAkB,EAAE,OAAoC;IACzE,MAAM,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;IAClC,MAAM,MAAM,GAAG,IAAI,UAAU,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;IAC/G,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC3D,GAAG,CAAC,QAAQ,EAAE,CAAC;AACnB,CAAC","sourcesContent":["import {\r\n Camera,\r\n Flow,\r\n Graphics2D,\r\n Paint,\r\n type BoxBounds,\r\n type ChildView,\r\n type Measurer,\r\n type Placement2D,\r\n type RenderContext,\r\n type Size2D,\r\n type Values,\r\n // Named so the emitted declaration reaches these through the sdk, not core.\r\n type Alignment as _Alignment,\r\n type Fill as _Fill,\r\n type FillResolved as _FillResolved,\r\n type FlowMode as _FlowMode,\r\n type FlowResolved as _FlowResolved,\r\n type GapSize as _GapSize,\r\n type Shadow as _Shadow,\r\n type ShadowResolved as _ShadowResolved,\r\n type Stroke as _Stroke,\r\n type StrokeResolved as _StrokeResolved,\r\n type Vector2 as _Vector2,\r\n} from \"@motionscript/sdk\";\r\n\r\n/**\r\n * What a background that fills whatever region is currently visible shares,\r\n * rather than a fixed rect: `GridPattern` is built from it, and so is a pattern\r\n * of your own. Spread `state` and `commands` in, pass `measure` and `layout`, and\r\n * draw with {@link draw}.\r\n *\r\n * Placed inside a `Camera`, the pattern is handed the world region the camera\r\n * can currently see (from its `zoom`/`lookAt`/`heading`), so it only ever\r\n * generates geometry for what's on screen, with no oversized node sized for the\r\n * worst-case pan and zoom. With no `Camera` above it, it fills its own box, so the\r\n * same pattern doubles as an ordinary full-bleed background.\r\n *\r\n * The pattern is itself a camera child, laid out at the camera's centre, so its\r\n * local draw space shares the world origin its siblings use. The visible region\r\n * is therefore expressed directly in that space: centred on the camera's\r\n * `lookAt`, sized to the inverse of the camera transform.\r\n */\r\n\r\n/** A pattern is a shape: paints, and children laid out like a rect's. */\r\nexport const state = { ...Paint.state, ...Flow.state };\r\n\r\nexport const commands = { ...Paint.commands };\r\n\r\ntype ShapeState = Flow.FlowState & Values<typeof Paint.state>;\r\n\r\nexport function measure(measurer: Measurer, s: ShapeState, children: readonly ChildView[]): Size2D {\r\n return Flow.measure(measurer, s, children, Paint.inset(s));\r\n}\r\n\r\nexport function layout(box: BoxBounds, s: ShapeState, children: readonly ChildView[]): readonly Placement2D[] {\r\n return Flow.layout(box, s, children, Paint.inset(s));\r\n}\r\n\r\n/**\r\n * The region the pattern covers, in its own draw space: the world rect the\r\n * nearest `Camera` above it sees, or its own box when there is none.\r\n */\r\nexport function visibleBounds(ctx: RenderContext): BoxBounds {\r\n const camera = ctx.ancestor(Camera);\r\n if (!camera) return { x: 0, y: 0, width: ctx.size.width, height: ctx.size.height };\r\n\r\n const { width: vw, height: vh } = camera.size;\r\n const zoom = camera.state.zoom || 1;\r\n const heading = camera.state.heading;\r\n\r\n // Inverse of the camera scale: a viewport `vw×vh` shows `vw/zoom × vh/zoom` 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 // Centred on the camera's `lookAt`, in y-up world space (the descriptor\r\n // convention; the renderer applies the single y-up→canvas flip when the\r\n // pattern's shapes are drawn).\r\n const lookAt = camera.state.lookAt;\r\n return { x: lookAt.x, y: lookAt.y, width: bw * 2, height: bh * 2 };\r\n}\r\n\r\n/**\r\n * Paint `pattern` over the visible region, once per render, then the children.\r\n *\r\n * The pattern is clipped to the region, so geometry overscanned past the edge\r\n * (so thick lines slide out instead of popping) trims cleanly. Inside a camera\r\n * the viewport already clips, but this keeps edge strokes clean and bounds the\r\n * work with no camera too. A `centerBounds` for a path drawn here is\r\n * `[bounds.x - w/2, bounds.y - h/2, bounds.x + w/2, bounds.y + h/2]`.\r\n */\r\nexport function draw(ctx: RenderContext, pattern: (bounds: BoxBounds) => void): void {\r\n const bounds = visibleBounds(ctx);\r\n const region = new Graphics2D().rect({ x: bounds.x, y: bounds.y, width: bounds.width, height: bounds.height });\r\n ctx.inFront(() => ctx.clip(region, () => pattern(bounds)));\r\n ctx.children();\r\n}\r\n"]}
1
+ {"version":3,"file":"viewport-pattern.js","sourceRoot":"","sources":["../../src/kit/viewport-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,MAAM,EACN,IAAI,EACJ,UAAU,EACV,KAAK,GAoBR,MAAM,mBAAmB,CAAC;AAE3B;;;;;;;;;;;;;;;;GAgBG;AAEH,yEAAyE;AACzE,MAAM,CAAC,MAAM,KAAK,GAAG,EAAE,GAAG,KAAK,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;AAEvD,MAAM,CAAC,MAAM,QAAQ,GAAG,EAAE,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;AAI9C,MAAM,UAAU,OAAO,CAAC,QAAkB,EAAE,CAAa,EAAE,QAA8B;IACrF,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/D,CAAC;AAED,MA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CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QACpC,EAAE,GAAG,EAAE,GAAG,GAAG,GAAG,EAAE,GAAG,GAAG,CAAC;QACzB,EAAE,GAAG,EAAE,GAAG,GAAG,GAAG,EAAE,GAAG,GAAG,CAAC;IAC7B,CAAC;IAED,wEAAwE;IACxE,wEAAwE;IACxE,+BAA+B;IAC/B,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;IACnC,OAAO,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC;AACvE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,IAAI,CAAC,GAAkB,EAAE,OAAoC;IACzE,MAAM,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;IAClC,MAAM,MAAM,GAAG,IAAI,UAAU,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;IAC/G,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC3D,GAAG,CAAC,QAAQ,EAAE,CAAC;AACnB,CAAC","sourcesContent":["import {\n Camera,\n Flow,\n Graphics2D,\n Paint,\n type BoxBounds,\n type ChildView,\n type Measurer,\n type Placement2D,\n type RenderContext,\n type Size2D,\n type Values,\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 Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n type Vector2 as _Vector2,\n} from \"@motionscript/sdk\";\n\n/**\n * What a background that fills whatever region is currently visible shares,\n * rather than a fixed rect: `GridPattern` is built from it, and so is a pattern\n * of your own. Spread `state` and `commands` in, pass `measure` and `layout`, and\n * draw with {@link draw}.\n *\n * Placed inside a `Camera`, the pattern is handed the world region the camera\n * can currently see (from its `zoom`/`lookAt`/`heading`), so it only ever\n * generates geometry for what's on screen, with no oversized node sized for the\n * worst-case pan and zoom. With no `Camera` above it, it fills its own box, so the\n * same pattern doubles as an ordinary full-bleed background.\n *\n * The pattern is itself a camera child, laid out at the camera's centre, so its\n * local draw space shares the world origin its siblings use. The visible region\n * is therefore expressed directly in that space: centred on the camera's\n * `lookAt`, sized to the inverse of the camera transform.\n */\n\n/** A pattern is a shape: paints, and children laid out like a rect's. */\nexport const state = { ...Paint.state, ...Flow.state };\n\nexport const commands = { ...Paint.commands };\n\ntype ShapeState = Flow.FlowState & Values<typeof Paint.state>;\n\nexport function measure(measurer: Measurer, s: ShapeState, children: readonly ChildView[]): Size2D {\n return Flow.measure(measurer, s, children, Paint.inset(s));\n}\n\nexport function layout(box: BoxBounds, s: ShapeState, children: readonly ChildView[]): readonly Placement2D[] {\n return Flow.layout(box, s, children, Paint.inset(s));\n}\n\n/**\n * The region the pattern covers, in its own draw space: the world rect the\n * nearest `Camera` above it sees, or its own box when there is none.\n */\nexport function visibleBounds(ctx: RenderContext): BoxBounds {\n const camera = ctx.ancestor(Camera);\n if (!camera) return { x: 0, y: 0, width: ctx.size.width, height: ctx.size.height };\n\n const { width: vw, height: vh } = camera.size;\n const zoom = camera.state.zoom || 1;\n const heading = camera.state.heading;\n\n // Inverse of the camera scale: a viewport `vw×vh` shows `vw/zoom × vh/zoom` of the world.\n const hw = vw / 2 / zoom;\n const hh = vh / 2 / zoom;\n\n // With a heading the visible world rect is rotated; take its axis-aligned\n // bounding box so the pattern covers the rotated viewport's full extent.\n let bw = hw;\n let bh = hh;\n if (heading !== 0) {\n const rad = (heading * Math.PI) / 180;\n const cos = Math.abs(Math.cos(rad));\n const sin = Math.abs(Math.sin(rad));\n bw = hw * cos + hh * sin;\n bh = hw * sin + hh * cos;\n }\n\n // Centred on the camera's `lookAt`, in y-up world space (the descriptor\n // convention; the renderer applies the single y-up→canvas flip when the\n // pattern's shapes are drawn).\n const lookAt = camera.state.lookAt;\n return { x: lookAt.x, y: lookAt.y, width: bw * 2, height: bh * 2 };\n}\n\n/**\n * Paint `pattern` over the visible region, once per render, then the children.\n *\n * The pattern is clipped to the region, so geometry overscanned past the edge\n * (so thick lines slide out instead of popping) trims cleanly. Inside a camera\n * the viewport already clips, but this keeps edge strokes clean and bounds the\n * work with no camera too. A `centerBounds` for a path drawn here is\n * `[bounds.x - w/2, bounds.y - h/2, bounds.x + w/2, bounds.y + h/2]`.\n */\nexport function draw(ctx: RenderContext, pattern: (bounds: BoxBounds) => void): void {\n const bounds = visibleBounds(ctx);\n const region = new Graphics2D().rect({ x: bounds.x, y: bounds.y, width: bounds.width, height: bounds.height });\n ctx.inFront(() => ctx.clip(region, () => pattern(bounds)));\n ctx.children();\n}\n"]}
@@ -1 +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"]}
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\"\n"]}
@@ -1 +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,EAC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GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC;IAClD,MAAM,MAAM,GAAG,KAAK,GAAG,CAAC,GAAG,QAAQ,CAAC;IACpC,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,GAAG,QAAQ,CAAC;IAErC,4FAA4F;IAC5F,OAAO,aAAa,CAChB,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,EACrF,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,EACrF,YAAY,EACZ,QAAQ,CACX,CAAC;AACN,CAAC","sourcesContent":["import {\r\n Flow,\r\n Graphics2D,\r\n Paint,\r\n Types,\r\n component2d,\r\n lerpVector2,\r\n type NodeOf,\r\n type PathBounds,\r\n type PathCommand,\r\n type Vector2,\r\n // Named so the emitted declaration reaches these through the sdk, not core.\r\n type Alignment as _Alignment,\r\n type Fill as _Fill,\r\n type FillResolved as _FillResolved,\r\n type FlowMode as _FlowMode,\r\n type FlowResolved as _FlowResolved,\r\n type GapSize as _GapSize,\r\n type Node2D as _Node2D,\r\n type Node2DProps as _Node2DProps,\r\n type Shadow as _Shadow,\r\n type ShadowResolved as _ShadowResolved,\r\n type Stroke as _Stroke,\r\n type StrokeResolved as _StrokeResolved,\r\n} from \"@motionscript/sdk\";\r\n\r\nimport { centered, defaultSubStroke, gridLinePaths, maxWeight } from \"../kit\";\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\nexport const LineGridPattern = component2d({\r\n key: \"lineGridPattern\",\r\n state: {\r\n ...Paint.state,\r\n ...Flow.state,\r\n /** Cells along each axis: `divisions` of 4 draws 5 major lines per axis. */\r\n divisions: 4,\r\n /** Finer cells each division is split into. 1 draws no minor lines; 2 adds one per division. */\r\n subdivisions: 1,\r\n /** Stroke for the minor lines. Unset, the major `stroke` at half opacity when `subdivisions > 1`. */\r\n subStroke: Types.stroke,\r\n /** Pans the grid. Lines wrap and tile, so the rect stays full while `offset` scrolls it. */\r\n offset: Types.custom<Vector2>({ x: 0, y: 0 }, { lerp: lerpVector2 }),\r\n },\r\n defaults: { subStroke: (_state, given) => defaultSubStroke(given) },\r\n commands: { ...Paint.commands },\r\n measure: (measurer, state, children) => Flow.measure(measurer, state, children, Paint.inset(state)),\r\n layout: (box, state, children) => Flow.layout(box, state, children, Paint.inset(state)),\r\n render: (ctx, state) => {\r\n const { width, height } = ctx.size;\r\n const box = new Graphics2D().rect({ width, height });\r\n ctx.inFront(() => {\r\n ctx.draw(new Graphics2D()\r\n .rect({ width, height, start: state.start, end: state.end })\r\n .shadow(state.shadow)\r\n .fill(state.fill));\r\n\r\n const divisions = Math.max(1, Math.floor(state.divisions));\r\n const subdivisions = Math.max(1, Math.floor(state.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(state.stroke);\r\n const minorStroke = centered(state.subStroke);\r\n const overscan = Math.max(maxWeight(major), maxWeight(minorStroke)) / 2;\r\n const lines = gridPaths(width, height, divisions, subdivisions, overscan, state.offset);\r\n const centerBounds: PathBounds = [-width / 2, -height / 2, width / 2, height / 2];\r\n\r\n ctx.clip(box, () => {\r\n // Minor lines first so the major lines sit on top.\r\n if (subdivisions > 1 && minorStroke.length > 0 && lines.minor.length > 0) {\r\n ctx.draw(new Graphics2D().path({ data: lines.minor, centerBounds }).stroke(minorStroke));\r\n }\r\n if (lines.major.length > 0) {\r\n ctx.draw(new Graphics2D().path({ data: lines.major, centerBounds }).stroke(major));\r\n }\r\n });\r\n });\r\n // The rect is what `clip` confines the children to and what picking tests; it paints nothing more.\r\n Paint.draw(ctx, state, null, { clipShape: box });\r\n },\r\n});\r\n\r\nexport type LineGridPattern = NodeOf<typeof LineGridPattern>;\r\n/** What a call or a document row may set. */\r\nexport type LineGridPatternProps = NonNullable<Parameters<typeof LineGridPattern>[0]>;\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\nfunction gridPaths(\r\n width: number,\r\n height: number,\r\n divisions: number,\r\n subdivisions: number,\r\n overscan: number,\r\n offset: Vector2,\r\n): { 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: offset.x, anchor: -insetX },\r\n { min: -insetY, max: insetY, step: innerH / cols, offset: offset.y, anchor: -insetY },\r\n subdivisions,\r\n overscan,\r\n );\r\n}\r\n"]}
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,KAAK,EACL,KAAK,EACL,WAAW,EACX,WAAW,GAkBd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE9E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC;IACvC,GAAG,EAAE,iBAAiB;IACtB,KAAK,EAAE;QAC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,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,EACrF,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,EACrF,YAAY,EACZ,QAAQ,CACX,CAAC;AACN,CAAC","sourcesContent":["import {\n Flow,\n Graphics2D,\n Paint,\n Types,\n component2d,\n lerpVector2,\n type NodeOf,\n type PathBounds,\n type PathCommand,\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 { centered, defaultSubStroke, gridLinePaths, maxWeight } from \"../kit\";\n\n/**\n * A rectangular grid of lines filling the node's layout rect.\n *\n * `stroke` paints the major lines and `subStroke` the minor ones, each as a\n * single union path. `fill` and `shadow` cover the whole rect, behind the lines.\n */\nexport const LineGridPattern = component2d({\n key: \"lineGridPattern\",\n state: {\n ...Paint.state,\n ...Flow.state,\n /** Cells along each axis: `divisions` of 4 draws 5 major lines per axis. */\n divisions: 4,\n /** Finer cells each division is split into. 1 draws no minor lines; 2 adds one per division. */\n subdivisions: 1,\n /** Stroke for the minor lines. Unset, the major `stroke` at half opacity when `subdivisions > 1`. */\n subStroke: Types.stroke,\n /** Pans the grid. Lines wrap and tile, so the rect stays full while `offset` scrolls it. */\n offset: Types.custom<Vector2>({ x: 0, y: 0 }, { lerp: lerpVector2 }),\n },\n defaults: { subStroke: (_state, given) => defaultSubStroke(given) },\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 { width, height } = ctx.size;\n const box = new Graphics2D().rect({ width, height });\n ctx.inFront(() => {\n ctx.draw(new Graphics2D()\n .rect({ width, height, start: state.start, end: state.end })\n .shadow(state.shadow)\n .fill(state.fill));\n\n const divisions = Math.max(1, Math.floor(state.divisions));\n const subdivisions = Math.max(1, Math.floor(state.subdivisions));\n\n // Lines overscan the rect by half the thickest stroke and are clipped to it, so a\n // thick line slides out under the clip instead of popping at the boundary.\n const major = centered(state.stroke);\n const minorStroke = centered(state.subStroke);\n const overscan = Math.max(maxWeight(major), maxWeight(minorStroke)) / 2;\n const lines = gridPaths(width, height, divisions, subdivisions, overscan, state.offset);\n const centerBounds: PathBounds = [-width / 2, -height / 2, width / 2, height / 2];\n\n ctx.clip(box, () => {\n // Minor lines first so the major lines sit on top.\n if (subdivisions > 1 && minorStroke.length > 0 && lines.minor.length > 0) {\n ctx.draw(new Graphics2D().path({ data: lines.minor, centerBounds }).stroke(minorStroke));\n }\n if (lines.major.length > 0) {\n ctx.draw(new Graphics2D().path({ data: lines.major, centerBounds }).stroke(major));\n }\n });\n });\n // The rect is what `clip` confines the children to and what picking tests; it paints nothing more.\n Paint.draw(ctx, state, null, { clipShape: box });\n },\n});\n\nexport type LineGridPattern = NodeOf<typeof LineGridPattern>;\n/** What a call or a document row may set. */\nexport type LineGridPatternProps = NonNullable<Parameters<typeof LineGridPattern>[0]>;\n\n// One multi-subpath path per group, so each stroke paints its lines as a union with no\n// destructive boolean op (which would erase open lines).\nfunction gridPaths(\n width: number,\n height: number,\n divisions: number,\n subdivisions: number,\n overscan: number,\n offset: Vector2,\n): { major: PathCommand[]; minor: PathCommand[] } {\n // Inset by `overscan` so the outermost lines sit fully inside the rect and are not\n // trimmed to half weight by the clip.\n const cols = divisions * subdivisions;\n const innerW = Math.max(0, width - 2 * overscan);\n const innerH = Math.max(0, height - 2 * overscan);\n const insetX = width / 2 - overscan;\n const insetY = height / 2 - overscan;\n\n // Anchored at the near edge, so a line sits on each edge of the box for any count of cells.\n return gridLinePaths(\n { min: -insetX, max: insetX, step: innerW / cols, offset: offset.x, anchor: -insetX },\n { min: -insetY, max: insetY, step: innerH / cols, offset: offset.y, anchor: -insetY },\n subdivisions,\n overscan,\n );\n}\n"]}
package/dist/nodes.js.map CHANGED
@@ -1 +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;AAoBrD,MAAM,CAAC,MAAM,KAAK,GAAc;IAC5B,eAAe;IACf,cAAc;IACd,WAAW;CACd,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 component's key.\r\n * Defining a component only *declares* that key: nothing is registered by\r\n * importing a module, so a registry holds exactly what its owner asked for.\r\n *\r\n * Listing the component **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\n// Typed by name, so the declaration names each component rather than spelling out its type through core.\r\ntype KitNode =\r\n | typeof LineGridPattern\r\n | typeof DotGridPattern\r\n | typeof GridPattern\r\n\r\nexport const NODES: KitNode[] = [\r\n LineGridPattern,\r\n DotGridPattern,\r\n GridPattern,\r\n]\r\n"]}
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;AAoBrD,MAAM,CAAC,MAAM,KAAK,GAAc;IAC5B,eAAe;IACf,cAAc;IACd,WAAW;CACd,CAAA","sourcesContent":["import { DotGridPattern } from \"./dot-grid-pattern\"\nimport { GridPattern } from \"./grid-pattern\"\nimport { LineGridPattern } from \"./line-grid-pattern\"\n\n/**\n * Every node type this package publishes.\n *\n * A host registers these by handing the array to an engine —\n * `new Engine(platform, { nodes: NODES })` — which reads each component's key.\n * Defining a component only *declares* that key: nothing is registered by\n * importing a module, so a registry holds exactly what its owner asked for.\n *\n * Listing the component **values** is also what survives bundling: this package\n * declares `sideEffects: false`, and a document names a node type by string, so\n * an import kept only for its side effect is exactly what gets shaken out.\n */\n// Typed by name, so the declaration names each component rather than spelling out its type through core.\ntype KitNode =\n | typeof LineGridPattern\n | typeof DotGridPattern\n | typeof GridPattern\n\nexport const NODES: KitNode[] = [\n LineGridPattern,\n DotGridPattern,\n GridPattern,\n]\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@motionscript/patterns",
3
- "version": "0.1.0-alpha.7",
3
+ "version": "0.1.0-alpha.9",
4
4
  "type": "module",
5
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
6
  "repository": {
@@ -49,8 +49,9 @@
49
49
  "animation"
50
50
  ],
51
51
  "license": "Apache-2.0",
52
+ "author": "Motionscript",
52
53
  "peerDependencies": {
53
- "@motionscript/sdk": "^0.1.0-alpha.7"
54
+ "@motionscript/sdk": "^0.1.0-alpha.9"
54
55
  },
55
56
  "devDependencies": {
56
57
  "@types/node": "^25.6.2",
@@ -61,8 +62,8 @@
61
62
  "typescript": "^6.0.3",
62
63
  "typescript-eslint": "^8.48.0",
63
64
  "vitest": "^4.1.5",
64
- "@motionscript/core": "0.1.0-alpha.7",
65
- "@motionscript/sdk": "0.1.0-alpha.7"
65
+ "@motionscript/core": "0.1.0-alpha.9",
66
+ "@motionscript/sdk": "0.1.0-alpha.9"
66
67
  },
67
68
  "scripts": {
68
69
  "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json --resolve-full-paths && node ../../../scripts/build-browser.mjs",
package/registry.json CHANGED
@@ -1,26 +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
- }
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
+ }
@@ -1,155 +1,155 @@
1
- import {
2
- Flow,
3
- Graphics2D,
4
- Paint,
5
- Types,
6
- component2d,
7
- lerpVector2,
8
- type NodeOf,
9
- type Size2D,
10
- type Vector2,
11
- // Named so the emitted declaration reaches these through the sdk, not core.
12
- type Alignment as _Alignment,
13
- type Fill as _Fill,
14
- type FillResolved as _FillResolved,
15
- type FlowMode as _FlowMode,
16
- type FlowResolved as _FlowResolved,
17
- type GapSize as _GapSize,
18
- type Node2D as _Node2D,
19
- type Node2DProps as _Node2DProps,
20
- type Shadow as _Shadow,
21
- type ShadowResolved as _ShadowResolved,
22
- type Stroke as _Stroke,
23
- type StrokeResolved as _StrokeResolved,
24
- } from "@motionscript/sdk"
25
-
26
- import { addTiledLines } from "../kit"
27
-
28
- /** One mark's place on an axis, and whether it lands on the coarse grid. */
29
- interface GridPosition {
30
- pos: number
31
- isMajor: boolean
32
- }
33
-
34
- // Calls the tiling `LineGridPattern` uses, so dots stay on its intersections at every offset.
35
- function gridPositions(
36
- min: number,
37
- max: number,
38
- step: number,
39
- offset: number,
40
- subdivisions: number,
41
- overscan: number
42
- ): GridPosition[] {
43
- const out: GridPosition[] = []
44
- // Anchored at the near edge, so a column or row sits on each edge of the box for any count of cells.
45
- addTiledLines(min, max, step, offset, subdivisions, overscan, (pos, isMajor) => {
46
- out.push({ pos, isMajor })
47
- }, min)
48
- return out
49
- }
50
-
51
- const state = {
52
- ...Paint.state,
53
- ...Flow.state,
54
- /** Cells along each axis, as in `LineGridPattern.divisions`: 4 puts 5 major dots on each axis. */
55
- divisions: 4,
56
- /** Splits each division again. `1` draws only the major dots; `2` puts one minor dot between each pair. */
57
- subdivisions: 1,
58
- /** Radius of a major dot. */
59
- radius: 3,
60
- /**
61
- * A minor dot's radius as a fraction of a major one's. A fraction rather than a
62
- * second paint stack, so the whole field stays one fill and a gradient crosses
63
- * every dot in it.
64
- */
65
- subScale: 0.5,
66
- /** Pans the field, as `LineGridPattern.offset` does, so the two stay aligned while both scroll. */
67
- offset: Types.custom<Vector2>({ x: 0, y: 0 }, { lerp: lerpVector2 }),
68
- }
69
-
70
- interface DotField {
71
- readonly divisions: number
72
- readonly subdivisions: number
73
- readonly radius: number
74
- readonly subScale: number
75
- readonly offset: Vector2
76
- }
77
-
78
- /**
79
- * A field of dots on the same `divisions` / `subdivisions` / `offset` as
80
- * `LineGridPattern`, so laid over one the dots sit on its intersections.
81
- *
82
- * The silhouette is the dots, which `Paint.draw` paints with `shadow`, `fill`,
83
- * `overlay` and `stroke`. A dot grid has no "paper": a rectangle behind it is how
84
- * it gets a background.
85
- *
86
- * What `clip` confines the children to, and what picking tests, is the node's
87
- * box rather than the silhouette, which clips outer dots as they pan out and
88
- * keeps the node selectable between dots. `start` / `end` act on nothing:
89
- * trimming a disc leaves a crescent, not a partial grid.
90
- */
91
- export const DotGridPattern = component2d({
92
- key: "dotGridPattern",
93
- state,
94
- commands: { ...Paint.commands },
95
- measure: (measurer, state, children) => Flow.measure(measurer, state, children, Paint.inset(state)),
96
- layout: (box, state, children) => Flow.layout(box, state, children, Paint.inset(state)),
97
- render: (ctx, state) => {
98
- const untrimmed = {
99
- fill: state.fill, stroke: state.stroke, shadow: state.shadow, overlay: state.overlay, start: 0, end: 1, clip: state.clip,
100
- }
101
- const box = new Graphics2D().rect({ width: ctx.size.width, height: ctx.size.height })
102
- Paint.draw(ctx, untrimmed, dots(ctx.size, state), { clipShape: box })
103
- },
104
- })
105
-
106
- export type DotGridPattern = NodeOf<typeof DotGridPattern>
107
- /** What a call or a document row may set. */
108
- export type DotGridPatternProps = NonNullable<Parameters<typeof DotGridPattern>[0]>
109
-
110
- /** Every dot in the field as one un-painted union: the paint stacks belong to the grid, not to a dot. */
111
- function dots(size: Size2D, s: DotField): Graphics2D | null {
112
- const { width, height } = size
113
- if (width <= 0 || height <= 0) return null
114
-
115
- const divisions = Math.max(1, Math.floor(s.divisions))
116
- const subdivisions = Math.max(1, Math.floor(s.subdivisions))
117
- const major = Math.max(0, s.radius)
118
- const minor = major * Math.max(0, s.subScale)
119
- if (major <= 0 && minor <= 0) return null
120
-
121
- // Inset by a dot's radius so an edge dot sits inside the box rather than being halved by the clip.
122
- const cols = divisions * subdivisions
123
- const insetX = Math.max(0, width / 2 - major)
124
- const insetY = Math.max(0, height / 2 - major)
125
- const xs = gridPositions(
126
- -insetX,
127
- insetX,
128
- (insetX * 2) / cols,
129
- s.offset.x,
130
- subdivisions,
131
- major
132
- )
133
- const ys = gridPositions(
134
- -insetY,
135
- insetY,
136
- (insetY * 2) / cols,
137
- s.offset.y,
138
- subdivisions,
139
- major
140
- )
141
-
142
- const field = new Graphics2D()
143
- let drew = false
144
- for (const column of xs) {
145
- for (const row of ys) {
146
- // A dot is major only where *both* axes are — an intersection of two
147
- // major rules, which is exactly the point a line grid draws heaviest.
148
- const size = column.isMajor && row.isMajor ? major : minor
149
- if (size <= 0) continue
150
- field.ellipse({ x: column.pos, y: row.pos, width: size * 2, height: size * 2 })
151
- drew = true
152
- }
153
- }
154
- return drew ? field : null
155
- }
1
+ import {
2
+ Flow,
3
+ Graphics2D,
4
+ Paint,
5
+ Types,
6
+ component2d,
7
+ lerpVector2,
8
+ type NodeOf,
9
+ type Size2D,
10
+ type Vector2,
11
+ // Named so the emitted declaration reaches these through the sdk, not core.
12
+ type Alignment as _Alignment,
13
+ type Fill as _Fill,
14
+ type FillResolved as _FillResolved,
15
+ type FlowMode as _FlowMode,
16
+ type FlowResolved as _FlowResolved,
17
+ type GapSize as _GapSize,
18
+ type Node2D as _Node2D,
19
+ type Node2DProps as _Node2DProps,
20
+ type Shadow as _Shadow,
21
+ type ShadowResolved as _ShadowResolved,
22
+ type Stroke as _Stroke,
23
+ type StrokeResolved as _StrokeResolved,
24
+ } from "@motionscript/sdk"
25
+
26
+ import { addTiledLines } from "../kit"
27
+
28
+ /** One mark's place on an axis, and whether it lands on the coarse grid. */
29
+ interface GridPosition {
30
+ pos: number
31
+ isMajor: boolean
32
+ }
33
+
34
+ // Calls the tiling `LineGridPattern` uses, so dots stay on its intersections at every offset.
35
+ function gridPositions(
36
+ min: number,
37
+ max: number,
38
+ step: number,
39
+ offset: number,
40
+ subdivisions: number,
41
+ overscan: number
42
+ ): GridPosition[] {
43
+ const out: GridPosition[] = []
44
+ // Anchored at the near edge, so a column or row sits on each edge of the box for any count of cells.
45
+ addTiledLines(min, max, step, offset, subdivisions, overscan, (pos, isMajor) => {
46
+ out.push({ pos, isMajor })
47
+ }, min)
48
+ return out
49
+ }
50
+
51
+ const state = {
52
+ ...Paint.state,
53
+ ...Flow.state,
54
+ /** Cells along each axis, as in `LineGridPattern.divisions`: 4 puts 5 major dots on each axis. */
55
+ divisions: 4,
56
+ /** Splits each division again. `1` draws only the major dots; `2` puts one minor dot between each pair. */
57
+ subdivisions: 1,
58
+ /** Radius of a major dot. */
59
+ radius: 3,
60
+ /**
61
+ * A minor dot's radius as a fraction of a major one's. A fraction rather than a
62
+ * second paint stack, so the whole field stays one fill and a gradient crosses
63
+ * every dot in it.
64
+ */
65
+ subScale: 0.5,
66
+ /** Pans the field, as `LineGridPattern.offset` does, so the two stay aligned while both scroll. */
67
+ offset: Types.custom<Vector2>({ x: 0, y: 0 }, { lerp: lerpVector2 }),
68
+ }
69
+
70
+ interface DotField {
71
+ readonly divisions: number
72
+ readonly subdivisions: number
73
+ readonly radius: number
74
+ readonly subScale: number
75
+ readonly offset: Vector2
76
+ }
77
+
78
+ /**
79
+ * A field of dots on the same `divisions` / `subdivisions` / `offset` as
80
+ * `LineGridPattern`, so laid over one the dots sit on its intersections.
81
+ *
82
+ * The silhouette is the dots, which `Paint.draw` paints with `shadow`, `fill`,
83
+ * `overlay` and `stroke`. A dot grid has no "paper": a rectangle behind it is how
84
+ * it gets a background.
85
+ *
86
+ * What `clip` confines the children to, and what picking tests, is the node's
87
+ * box rather than the silhouette, which clips outer dots as they pan out and
88
+ * keeps the node selectable between dots. `start` / `end` act on nothing:
89
+ * trimming a disc leaves a crescent, not a partial grid.
90
+ */
91
+ export const DotGridPattern = component2d({
92
+ key: "dotGridPattern",
93
+ state,
94
+ commands: { ...Paint.commands },
95
+ measure: (measurer, state, children) => Flow.measure(measurer, state, children, Paint.inset(state)),
96
+ layout: (box, state, children) => Flow.layout(box, state, children, Paint.inset(state)),
97
+ render: (ctx, state) => {
98
+ const untrimmed = {
99
+ fill: state.fill, stroke: state.stroke, shadow: state.shadow, overlay: state.overlay, start: 0, end: 1, clip: state.clip,
100
+ }
101
+ const box = new Graphics2D().rect({ width: ctx.size.width, height: ctx.size.height })
102
+ Paint.draw(ctx, untrimmed, dots(ctx.size, state), { clipShape: box })
103
+ },
104
+ })
105
+
106
+ export type DotGridPattern = NodeOf<typeof DotGridPattern>
107
+ /** What a call or a document row may set. */
108
+ export type DotGridPatternProps = NonNullable<Parameters<typeof DotGridPattern>[0]>
109
+
110
+ /** Every dot in the field as one un-painted union: the paint stacks belong to the grid, not to a dot. */
111
+ function dots(size: Size2D, s: DotField): Graphics2D | null {
112
+ const { width, height } = size
113
+ if (width <= 0 || height <= 0) return null
114
+
115
+ const divisions = Math.max(1, Math.floor(s.divisions))
116
+ const subdivisions = Math.max(1, Math.floor(s.subdivisions))
117
+ const major = Math.max(0, s.radius)
118
+ const minor = major * Math.max(0, s.subScale)
119
+ if (major <= 0 && minor <= 0) return null
120
+
121
+ // Inset by a dot's radius so an edge dot sits inside the box rather than being halved by the clip.
122
+ const cols = divisions * subdivisions
123
+ const insetX = Math.max(0, width / 2 - major)
124
+ const insetY = Math.max(0, height / 2 - major)
125
+ const xs = gridPositions(
126
+ -insetX,
127
+ insetX,
128
+ (insetX * 2) / cols,
129
+ s.offset.x,
130
+ subdivisions,
131
+ major
132
+ )
133
+ const ys = gridPositions(
134
+ -insetY,
135
+ insetY,
136
+ (insetY * 2) / cols,
137
+ s.offset.y,
138
+ subdivisions,
139
+ major
140
+ )
141
+
142
+ const field = new Graphics2D()
143
+ let drew = false
144
+ for (const column of xs) {
145
+ for (const row of ys) {
146
+ // A dot is major only where *both* axes are — an intersection of two
147
+ // major rules, which is exactly the point a line grid draws heaviest.
148
+ const size = column.isMajor && row.isMajor ? major : minor
149
+ if (size <= 0) continue
150
+ field.ellipse({ x: column.pos, y: row.pos, width: size * 2, height: size * 2 })
151
+ drew = true
152
+ }
153
+ }
154
+ return drew ? field : null
155
+ }
@@ -1 +1 @@
1
- export * from "./dot-grid-pattern"
1
+ export * from "./dot-grid-pattern"
package/src/engine.ts CHANGED
@@ -1,11 +1,11 @@
1
- /**
2
- * The patterns **kit**: what the three patterns share, and what a copied one does
3
- * not copy.
4
- *
5
- * `ms add` writes 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"
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"