@motionscript/patterns 0.1.0-alpha.5 → 0.1.0-alpha.6
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.
- package/CHANGELOG.md +22 -0
- package/README.md +13 -9
- package/dist/browser/chunks/chunk-REWLNFZ2.js +2 -0
- package/dist/browser/chunks/chunk-REWLNFZ2.js.map +7 -0
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +3 -3
- package/dist/browser/kit.js +1 -1
- package/dist/browser/manifest.json +1 -1
- package/dist/dot-grid-pattern/dot-grid-pattern.d.ts +68 -27
- package/dist/dot-grid-pattern/dot-grid-pattern.d.ts.map +1 -1
- package/dist/dot-grid-pattern/dot-grid-pattern.js +71 -75
- package/dist/dot-grid-pattern/dot-grid-pattern.js.map +1 -1
- package/dist/engine.d.ts +4 -4
- package/dist/engine.js +4 -4
- package/dist/engine.js.map +1 -1
- package/dist/grid-pattern/grid-pattern.d.ts +59 -26
- package/dist/grid-pattern/grid-pattern.d.ts.map +1 -1
- package/dist/grid-pattern/grid-pattern.js +83 -102
- package/dist/grid-pattern/grid-pattern.js.map +1 -1
- package/dist/kit/grid-lines.d.ts +7 -0
- package/dist/kit/grid-lines.d.ts.map +1 -1
- package/dist/kit/grid-lines.js +21 -0
- package/dist/kit/grid-lines.js.map +1 -1
- package/dist/kit/index.d.ts +1 -1
- package/dist/kit/index.d.ts.map +1 -1
- package/dist/kit/index.js +1 -1
- package/dist/kit/index.js.map +1 -1
- package/dist/kit/viewport-pattern.d.ts +75 -30
- package/dist/kit/viewport-pattern.d.ts.map +1 -1
- package/dist/kit/viewport-pattern.js +66 -69
- package/dist/kit/viewport-pattern.js.map +1 -1
- package/dist/line-grid-pattern/line-grid-pattern.d.ts +56 -23
- package/dist/line-grid-pattern/line-grid-pattern.d.ts.map +1 -1
- package/dist/line-grid-pattern/line-grid-pattern.js +63 -88
- package/dist/line-grid-pattern/line-grid-pattern.js.map +1 -1
- package/dist/nodes.d.ts +8 -3
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +5 -10
- package/dist/nodes.js.map +1 -1
- package/package.json +4 -4
- package/src/dot-grid-pattern/dot-grid-pattern.ts +101 -78
- package/src/engine.ts +4 -4
- package/src/grid-pattern/grid-pattern.ts +126 -120
- package/src/kit/grid-lines.ts +25 -1
- package/src/kit/index.ts +1 -1
- package/src/kit/viewport-pattern.ts +89 -78
- package/src/line-grid-pattern/line-grid-pattern.ts +95 -103
- package/src/nodes.ts +16 -3
- package/dist/browser/chunks/chunk-EZEE76AY.js +0 -2
- package/dist/browser/chunks/chunk-EZEE76AY.js.map +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @motionscript/patterns
|
|
2
2
|
|
|
3
|
+
## 0.1.0-alpha.6
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 163b708: Node types are components: one spec object handed to `component2d`, `component3d` or `componentAudio`, with no classes, decorators or JSX.
|
|
8
|
+
|
|
9
|
+
- **Writing a node type.** A component is one object literal: `key`, `state` (literals and `Types`), `defaults`, `commands`, `children`, `allowedChildren`/`allowedParents`, `provide`, `load`, and its tree's own fields (`measure`, `layout`, `render` for 2D). Behaviour comes from modules you spread in and call: `Paint`, `Flow`, `Shapes`, `Typeface`, `TextLayout`, `Aim`, `Material`, `View3D`. ADR 0007 and the custom-node docs cover it.
|
|
10
|
+
- **Building nodes in code** uses calls: `Rect({ fill: 'tomato', children: [Text({ text: 'Hi' })] })`, or `new Rect({...})` for the node itself.
|
|
11
|
+
- **Every built-in and every kit node is a component**, under the same document key. Code that tested `instanceof` a class now uses the component's `.is`, or `instanceof X.node`. Changed members:
|
|
12
|
+
- `SurfacePlot3d.valueAt` and `FunctionPlot.valueAt` are now the functions `surfaceValueAt` and `curveValue`.
|
|
13
|
+
- A system's `coordinates` is replaced by `planeMap`/`axesMap`/`systemMap`.
|
|
14
|
+
- `PieChart.isSelected` is replaced by `isSliceSelected`.
|
|
15
|
+
- `ItemGrid` is a kit module (`ItemGrid.isGrid`, `ItemGrid.define`), not a base class.
|
|
16
|
+
- **The sdk no longer exports the class surface:**
|
|
17
|
+
- the decorators: `node`, `property` and every `*Property`, `command`, `withdraw`, `driveCommand`;
|
|
18
|
+
- the authoring bases: `PaintNode`, `ShapeNode`, `TextBase`, `Mesh3DBase`, `Canvas3DBase` and the `*Base` geometry classes;
|
|
19
|
+
- `asCommand`, `compose`, `drive` and `declarePaints` from `@motionscript/sdk/component`;
|
|
20
|
+
- the `jsx-runtime` and `jsx-dev-runtime` subpaths.
|
|
21
|
+
- `Node`, `Node2D`, `Node3D` and `NodeAudio` remain as types.
|
|
22
|
+
- **Editor metadata leaves the engine.** The kits no longer declare `parentKey`, `forkable`, `layout`, `seed`, `within`, `beside` or `closed`; a host keeps those in its own configs. `describe()` now reports `holds`, the trees a type takes children from, and the placement checks use it, so a 2D viewport of your own that takes 3D children places them.
|
|
23
|
+
- A command called from code with no argument runs, and a refused child is told what its parent takes (`allowedChildren`) or where it goes (`allowedParents`).
|
|
24
|
+
|
|
3
25
|
## 0.1.0-alpha.5
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -19,18 +19,20 @@ the engine given `NODES`.
|
|
|
19
19
|
`DotGridPattern` shares `divisions`, `subdivisions` and `offset` with
|
|
20
20
|
`LineGridPattern`, and both tile through the same function, so a dot grid laid
|
|
21
21
|
over a line grid with the same numbers keeps its dots on the intersections while
|
|
22
|
-
both scroll. `GridPattern`
|
|
23
|
-
pattern of your own:
|
|
24
|
-
|
|
22
|
+
both scroll. `GridPattern` is built from `ViewportPattern`, a module exported for
|
|
23
|
+
a pattern of your own: spread its `state` and `commands` into a `component2d`,
|
|
24
|
+
pass its `measure` and `layout`, and draw with `ViewportPattern.draw(ctx, (bounds) => …)`,
|
|
25
|
+
which hands over the region the camera sees so only what is on screen is generated.
|
|
25
26
|
|
|
26
27
|
Core's `grid` and `dotGrid` **fills** are a different thing: paints over any
|
|
27
28
|
shape, built into the engine.
|
|
28
29
|
|
|
29
30
|
## Nodes and props
|
|
30
31
|
|
|
31
|
-
All three are shapes
|
|
32
|
-
(`fill`, `stroke`, `shadow`, ...) and children,
|
|
33
|
-
|
|
32
|
+
All three are shapes, built with a shape's paint and layout (`Paint`, `Flow`), so
|
|
33
|
+
they take a shape's paint props (`fill`, `stroke`, `shadow`, ...) and children,
|
|
34
|
+
and the paint commands, and declare no commands of their own: `to` on `offset`
|
|
35
|
+
(all three) and on `cellSize` (`gridPattern`) animates them.
|
|
34
36
|
|
|
35
37
|
| Key | Own props | Space |
|
|
36
38
|
|---|---|---|
|
|
@@ -40,14 +42,16 @@ own: `to` on `offset` (all three) and on `cellSize` (`gridPattern`) animates the
|
|
|
40
42
|
|
|
41
43
|
`stroke` paints the major lines and `subStroke` the minor ones (drawn when
|
|
42
44
|
`subdivisions > 1`); when a pattern is built with a `stroke` and no `subStroke`, the
|
|
43
|
-
minor stroke is the major one at half opacity
|
|
45
|
+
minor stroke is the major one at half opacity: the stroke it was built with, so a
|
|
46
|
+
later change to `stroke` leaves it as it was.
|
|
44
47
|
|
|
45
48
|
- **One tiling.** Every mark of every pattern comes from `addTiledLines`
|
|
46
49
|
(`src/kit/grid-lines.ts`), so patterns with the same `divisions`, `subdivisions` and
|
|
47
50
|
`offset` agree on every intersection. A mark is major by its tile index against the
|
|
48
51
|
un-panned grid, so panning never changes a mark's class.
|
|
49
|
-
- **`gridPattern` is world-locked and has no box of its own.** `ViewportPattern`
|
|
50
|
-
|
|
52
|
+
- **`gridPattern` is world-locked and has no box of its own.** `ViewportPattern.draw`
|
|
53
|
+
covers `ViewportPattern.visibleBounds(ctx)`: the world rect the nearest `Camera`
|
|
54
|
+
ancestor sees (`ctx.ancestor(Camera)`)
|
|
51
55
|
(widened to the bounding box of the turned viewport when it has a `heading`), or,
|
|
52
56
|
with no camera, the node's own layout rect centred on its origin. Nothing is kept
|
|
53
57
|
between frames, so a pan or zoom regenerates the marks for the region; only
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var L=Object.defineProperty;var S=(o,t)=>{for(var n in t)L(o,n,{get:t[n],enumerable:!0})};import{strokeOps as b}from"@motionscript/sdk";function j(o,t,n,r,e=0){let s=[],a=[],i=[],f=[],p=m(t.min-r,t.step,t.offset,e,Math.floor),u=m(t.max+r,t.step,t.offset,e,Math.ceil),h=m(o.min-r,o.step,o.offset,e,Math.floor),l=m(o.max+r,o.step,o.offset,e,Math.ceil);return g(o.min,o.max,o.step,o.offset,n,r,(c,d)=>{(d?s:a).push(c)},o.anchor),g(t.min,t.max,t.step,t.offset,n,r,(c,d)=>{(d?i:f).push(c)},t.anchor),{top:p,bottom:u,left:h,right:l,verticalMajor:s,verticalMinor:a,horizontalMajor:i,horizontalMinor:f}}function E(o,t,n,r){let e=j(o,t,n,r),s=[],a=[];for(let i of e.verticalMajor)s.push({type:"M",x:i,y:e.top},{type:"L",x:i,y:e.bottom});for(let i of e.verticalMinor)a.push({type:"M",x:i,y:e.top},{type:"L",x:i,y:e.bottom});for(let i of e.horizontalMajor)s.push({type:"M",x:e.left,y:i},{type:"L",x:e.right,y:i});for(let i of e.horizontalMinor)a.push({type:"M",x:e.left,y:i},{type:"L",x:e.right,y:i});return{major:s,minor:a}}function m(o,t,n,r,e){return r>0?e(o/r)*r:t<=0?o:e((o-n)/t)*t+n}function g(o,t,n,r,e,s,a,i=0){if(n<=0)return;let f=n*1e-6,p=Math.ceil((o-s-r-i-f)/n),u=Math.floor((t+s-r-i+f)/n);for(let h=p;h<=u;h++){let l=i+h*n+r,c=(h%e+e)%e===0;a(l,c)}}function G(o){let t=0;for(let n of o)n.weight>t&&(t=n.weight);return t}function I(o){return o.map(t=>t.align===0?t:{...t,align:0})}function P(o,t){return b.resolve(o.map(n=>({...n,fill:n.fill.map(r=>({...r,opacity:(r.opacity??1)*t}))})))}var w=new WeakMap;function K(o){let t=w.get(o);if(!t){let n=y(o.stroke),r=y(o.subdivisions)??1;t=n!==void 0&&r>1?P(b.resolve(n),.5):[],w.set(o,t)}return t}function y(o){return typeof o=="function"?o():o}var k={};S(k,{commands:()=>F,draw:()=>W,layout:()=>T,measure:()=>N,state:()=>B,visibleBounds:()=>z});import{Camera as O,Flow as x,Graphics2D as A,Paint as M}from"@motionscript/sdk";var B={...M.state,...x.state},F={...M.commands};function N(o,t,n){return x.measure(o,t,n,M.inset(t))}function T(o,t,n){return x.layout(o,t,n,M.inset(t))}function z(o){let t=o.ancestor(O);if(!t)return{x:0,y:0,width:o.size.width,height:o.size.height};let{width:n,height:r}=t.size,e=t.state.zoom||1,s=t.state.heading,a=n/2/e,i=r/2/e,f=a,p=i;if(s!==0){let h=s*Math.PI/180,l=Math.abs(Math.cos(h)),c=Math.abs(Math.sin(h));f=a*l+i*c,p=a*c+i*l}let u=t.state.lookAt;return{x:u.x,y:u.y,width:f*2,height:p*2}}function W(o,t){let n=z(o),r=new A().rect({x:n.x,y:n.y,width:n.width,height:n.height});o.inFront(()=>o.clip(r,()=>t(n))),o.children()}export{j as a,E as b,g as c,G as d,I as e,P as f,K as g,k as h};
|
|
2
|
+
//# sourceMappingURL=chunk-REWLNFZ2.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/kit/grid-lines.ts", "../../../src/kit/viewport-pattern.ts"],
|
|
4
|
+
"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", "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"],
|
|
5
|
+
"mappings": "0FAAA,OAAS,aAAAA,MAAsF,oBAoEzF,SAAUC,EACZC,EACAC,EACAC,EACAC,EACAC,EAAQ,EAAC,CAET,IAAMC,EAA0B,CAAA,EAC1BC,EAA0B,CAAA,EAC1BC,EAA4B,CAAA,EAC5BC,EAA4B,CAAA,EAI5BC,EAAMC,EAAST,EAAE,IAAME,EAAUF,EAAE,KAAMA,EAAE,OAAQG,EAAO,KAAK,KAAK,EACpEO,EAASD,EAAST,EAAE,IAAME,EAAUF,EAAE,KAAMA,EAAE,OAAQG,EAAO,KAAK,IAAI,EACtEQ,EAAOF,EAASV,EAAE,IAAMG,EAAUH,EAAE,KAAMA,EAAE,OAAQI,EAAO,KAAK,KAAK,EACrES,EAAQH,EAASV,EAAE,IAAMG,EAAUH,EAAE,KAAMA,EAAE,OAAQI,EAAO,KAAK,IAAI,EAE3E,OAAAU,EAAcd,EAAE,IAAKA,EAAE,IAAKA,EAAE,KAAMA,EAAE,OAAQE,EAAcC,EAAU,CAACY,EAAIC,IAAW,EACjFA,EAAUX,EAAgBC,GAAe,KAAKS,CAAE,CACrD,EAAG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K,IAAI,KAAK,IAAID,CAAG,CAAC,EAC5BE,EAAM,KAAK,IAAI,KAAK,IAAIF,CAAG,CAAC,EAClCF,EAAKF,EAAKK,EAAMJ,EAAKK,EACrBH,EAAKH,EAAKM,EAAML,EAAKI,CACzB,CAKA,IAAME,EAASZ,EAAO,MAAM,OAC5B,MAAO,CAAE,EAAGY,EAAO,EAAG,EAAGA,EAAO,EAAG,MAAOL,EAAK,EAAG,OAAQC,EAAK,CAAC,CACpE,CAWM,SAAUtB,EAAKa,EAAoBc,EAAoC,CACzE,IAAMC,EAASxB,EAAcS,CAAG,EAC1BgB,EAAS,IAAItB,EAAU,EAAG,KAAK,CAAE,EAAGqB,EAAO,EAAG,EAAGA,EAAO,EAAG,MAAOA,EAAO,MAAO,OAAQA,EAAO,MAAM,CAAE,EAC7Gf,EAAI,QAAQ,IAAMA,EAAI,KAAKgB,EAAQ,IAAMF,EAAQC,CAAM,CAAC,CAAC,EACzDf,EAAI,SAAQ,CAChB",
|
|
6
|
+
"names": ["strokeOps", "gridLines", "x", "y", "subdivisions", "overscan", "cycle", "verticalMajor", "verticalMinor", "horizontalMajor", "horizontalMinor", "top", "snapSpan", "bottom", "left", "right", "addTiledLines", "px", "isMajor", "py", "gridLinePaths", "g", "major", "minor", "pos", "step", "offset", "round", "min", "max", "emit", "anchor", "eps", "startN", "endN", "n", "maxWeight", "strokes", "s", "centered", "dimStroke", "factor", "f", "SUB_STROKES", "defaultSubStroke", "given", "sub", "stroke", "valueOf", "prop", "viewport_pattern_exports", "__export", "commands", "draw", "layout", "measure", "state", "visibleBounds", "Camera", "Flow", "Graphics2D", "Paint", "measurer", "s", "children", "box", "ctx", "camera", "vw", "vh", "zoom", "heading", "hw", "hh", "bw", "bh", "rad", "cos", "sin", "lookAt", "pattern", "bounds", "region"]
|
|
7
|
+
}
|
package/dist/browser/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as O,b as T,c as V,d as x,e as w,f as nt,g as k,h as M}from"./chunks/chunk-REWLNFZ2.js";import{Flow as G,Graphics2D as v,Paint as g,Types as W,component2d as H,lerpVector2 as _}from"@motionscript/sdk";var X=H({key:"lineGridPattern",state:{...g.state,...G.state,divisions:4,subdivisions:1,subStroke:W.stroke,offset:W.custom({x:0,y:0},{lerp:_})},defaults:{subStroke:(o,t)=>k(t)},commands:{...g.commands},measure:(o,t,e)=>G.measure(o,t,e,g.inset(t)),layout:(o,t,e)=>G.layout(o,t,e,g.inset(t)),render:(o,t)=>{let{width:e,height:r}=o.size,a=new v().rect({width:e,height:r});o.inFront(()=>{o.draw(new v().rect({width:e,height:r,start:t.start,end:t.end}).shadow(t.shadow).fill(t.fill));let c=Math.max(1,Math.floor(t.divisions)),i=Math.max(1,Math.floor(t.subdivisions)),f=w(t.stroke),n=w(t.subStroke),l=Math.max(x(f),x(n))/2,s=q(e,r,c,i,l,t.offset),m=[-e/2,-r/2,e/2,r/2];o.clip(a,()=>{i>1&&n.length>0&&s.minor.length>0&&o.draw(new v().path({data:s.minor,centerBounds:m}).stroke(n)),s.major.length>0&&o.draw(new v().path({data:s.major,centerBounds:m}).stroke(f))})}),g.draw(o,t,null,{clipShape:a})}});function q(o,t,e,r,a,c){let i=e*r,f=Math.max(0,o-2*a),n=Math.max(0,t-2*a),l=o/2-a,s=t/2-a;return T({min:-l,max:l,step:f/i,offset:c.x,anchor:-l},{min:-s,max:s,step:n/i,offset:c.y,anchor:-s},r,a)}import{Flow as z,Graphics2D as F,Paint as b,Types as I,component2d as J,lerpVector2 as K}from"@motionscript/sdk";function Y(o,t,e,r,a,c){let i=[];return V(o,t,e,r,a,c,(f,n)=>{i.push({pos:f,isMajor:n})},o),i}var Q={...b.state,...z.state,divisions:4,subdivisions:1,radius:3,subScale:.5,offset:I.custom({x:0,y:0},{lerp:K})},N=J({key:"dotGridPattern",state:Q,commands:{...b.commands},measure:(o,t,e)=>z.measure(o,t,e,b.inset(t)),layout:(o,t,e)=>z.layout(o,t,e,b.inset(t)),render:(o,t)=>{let e={fill:t.fill,stroke:t.stroke,shadow:t.shadow,overlay:t.overlay,start:0,end:1,clip:t.clip},r=new F().rect({width:o.size.width,height:o.size.height});b.draw(o,e,R(o.size,t),{clipShape:r})}});function R(o,t){let{width:e,height:r}=o;if(e<=0||r<=0)return null;let a=Math.max(1,Math.floor(t.divisions)),c=Math.max(1,Math.floor(t.subdivisions)),i=Math.max(0,t.radius),f=i*Math.max(0,t.subScale);if(i<=0&&f<=0)return null;let n=a*c,l=Math.max(0,e/2-i),s=Math.max(0,r/2-i),m=Y(-l,l,l*2/n,t.offset.x,c,i),d=Y(-s,s,s*2/n,t.offset.y,c,i),h=new F,S=!1;for(let p of m)for(let u of d){let y=p.isMajor&&u.isMajor?i:f;y<=0||(h.ellipse({x:p.pos,y:u.pos,width:y*2,height:y*2}),S=!0)}return S?h:null}import{Graphics2D as P,Types as L,component2d as U,lerpNumber as Z,lerpVector2 as C}from"@motionscript/sdk";var E=U({key:"gridPattern",state:{...M.state,cellSize:L.custom(100,{lerp:ot}),subdivisions:1,subStroke:L.stroke,offset:L.custom({x:0,y:0},{lerp:C})},defaults:{subStroke:(o,t)=>k(t)},commands:{...M.commands},measure:M.measure,layout:M.layout,render:(o,t)=>M.draw(o,e=>$(o,t,e))});function $(o,t,e){let r=e.width/2,a=e.height/2,c=e.x-r,i=e.x+r,f=e.y-a,n=e.y+a;o.draw(new P().rect({x:e.x,y:e.y,width:e.width,height:e.height,start:t.start,end:t.end}).shadow(t.shadow).fill(t.fill));let l=Math.max(1,Math.floor(t.subdivisions)),s=t.cellSize,m=Math.max(.001,typeof s=="number"?s:s.x),d=Math.max(.001,typeof s=="number"?s:s.y),h=m/l,S=d/l,p=w(t.stroke),u=w(t.subStroke),y=Math.max(x(p),x(u))/2,j={min:c,max:i,step:h,offset:t.offset.x},D={min:f,max:n,step:S,offset:t.offset.y};l>1&&u.length>0&&A(o,j,D,l,y,u,!1),p.length>0&&A(o,j,D,l,y,p,!0)}function A(o,t,e,r,a,c,i){let f=tt(c),n=O(t,e,r,a,f),l=i?n.verticalMajor:n.verticalMinor,s=i?n.horizontalMajor:n.horizontalMinor,m=[-1,-1,1,1];if(f<=0){let d=[];for(let h of l)d.push({type:"M",x:h,y:n.top},{type:"L",x:h,y:n.bottom});for(let h of s)d.push({type:"M",x:n.left,y:h},{type:"L",x:n.right,y:h});d.length>0&&o.draw(new P().path({data:d,centerBounds:m}).stroke(c));return}for(let d of l){let h=[{type:"M",x:d,y:n.top},{type:"L",x:d,y:n.bottom}];o.draw(new P().path({data:h,centerBounds:m}).stroke(B(c,n.top)))}for(let d of s){let h=[{type:"M",x:n.left,y:d},{type:"L",x:n.right,y:d}];o.draw(new P().path({data:h,centerBounds:m}).stroke(B(c,n.left)))}}function tt(o){let t=0;for(let e of o)if(e.dash&&e.dash.length>0){let r=e.dash.reduce((a,c)=>a+c,0);r>t&&(t=r)}return t}function B(o,t){return o.map(e=>e.dash&&e.dash.length>0?{...e,dashOffset:(e.dashOffset??0)-t}:e)}function ot(o,t,e){return typeof o=="number"&&typeof t=="number"?Z(o,t,e):C(typeof o=="number"?{x:o,y:o}:o,typeof t=="number"?{x:t,y:t}:t,e)}var et=[X,N,E];export{N as DotGridPattern,E as GridPattern,X as LineGridPattern,et as NODES,M as ViewportPattern,V as addTiledLines,w as centered,k as defaultSubStroke,nt as dimStroke,T as gridLinePaths,O as gridLines,x as maxWeight};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/line-grid-pattern/line-grid-pattern.ts", "../../src/dot-grid-pattern/dot-grid-pattern.ts", "../../src/grid-pattern/grid-pattern.ts", "../../src/nodes.ts"],
|
|
4
|
-
"sourcesContent": ["import {\r\n Clip,\r\n Graphics2D,\r\n ShapeNode,\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", "import {\r\n Clip,\r\n Graphics2D,\r\n ShapeNode,\r\n lerpVector2,\r\n node,\r\n property,\r\n type ShapeProps,\r\n type Vector2,\r\n} from \"@motionscript/sdk\"\r\n\r\nimport { addTiledLines } from \"../kit\"\r\n\r\n/** One mark's place on an axis, and whether it lands on the coarse grid. */\r\ninterface GridPosition {\r\n pos: number\r\n isMajor: boolean\r\n}\r\n\r\n// Calls the tiling `LineGridPattern` uses, so dots stay on its intersections at every offset.\r\nfunction gridPositions(\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): GridPosition[] {\r\n const out: GridPosition[] = []\r\n // Anchored at the near edge, so a column or row sits on each edge of the box for any count of cells.\r\n addTiledLines(min, max, step, offset, subdivisions, overscan, (pos, isMajor) => {\r\n out.push({ pos, isMajor })\r\n }, min)\r\n return out\r\n}\r\n\r\nexport interface DotGridPatternProps extends ShapeProps {\r\n /** Cells along each axis, as in `LineGridPattern.divisions`: 4 puts 5 major dots on each axis. */\r\n divisions: number\r\n /** Splits each division again. `1` draws only the major dots; `2` puts one minor dot between each pair. */\r\n subdivisions: number\r\n /** Radius of a major dot. */\r\n radius: number\r\n /**\r\n * A minor dot's radius as a fraction of a major one's. A fraction rather than a\r\n * second paint stack, so the whole field stays one fill and a gradient crosses\r\n * every dot in it.\r\n */\r\n subScale: number\r\n /** Pans the field, as `LineGridPattern.offset` does, so the two stay aligned while both scroll. */\r\n offset: Vector2\r\n}\r\n\r\n/**\r\n * A field of dots on the same `divisions` / `subdivisions` / `offset` as\r\n * {@link LineGridPattern}, so laid over one the dots sit on its intersections.\r\n *\r\n * The silhouette is the dots (see {@link DotGridPattern.shapeGraphics}), so\r\n * `ShapeNode` paints `shadow`, `fill`, `overlay` and `stroke` with no render code\r\n * here. A dot grid has no \"paper\": a rectangle behind it is how it gets a\r\n * background.\r\n *\r\n * `clipSelf` is the node's box rather than the silhouette, which clips outer dots\r\n * as they pan out and keeps the node selectable between dots. `start` / `end` act\r\n * on nothing: trimming a disc leaves a crescent, not a partial grid.\r\n */\r\n@node({ key: \"dotGridPattern\", parentKey: \"shape\", forkable: true })\r\nexport class DotGridPattern extends ShapeNode<DotGridPatternProps> {\r\n @property({ default: 4 }) declare readonly divisions: number\r\n @property({ default: 1 }) declare readonly subdivisions: number\r\n @property({ default: 3 }) declare readonly radius: number\r\n @property({ default: 0.5 }) declare readonly subScale: number\r\n @property({ default: { x: 0, y: 0 }, tween: lerpVector2 })\r\n declare readonly offset: Vector2\r\n\r\n /** Every dot in the field as one un-painted union: the paint stacks belong to the grid, not to a dot. */\r\n protected override shapeGraphics(): Graphics2D | null {\r\n const bounds = this.layoutBounds\r\n const width = bounds?.width ?? 0\r\n const height = bounds?.height ?? 0\r\n if (width <= 0 || height <= 0) return null\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 const major = Math.max(0, this.radius)\r\n const minor = major * Math.max(0, this.subScale)\r\n if (major <= 0 && minor <= 0) return null\r\n\r\n // Inset by a dot's radius so an edge dot sits inside the box rather than being halved by the clip.\r\n const cols = divisions * subdivisions\r\n const insetX = Math.max(0, width / 2 - major)\r\n const insetY = Math.max(0, height / 2 - major)\r\n const xs = gridPositions(\r\n -insetX,\r\n insetX,\r\n (insetX * 2) / cols,\r\n this.offset.x,\r\n subdivisions,\r\n major\r\n )\r\n const ys = gridPositions(\r\n -insetY,\r\n insetY,\r\n (insetY * 2) / cols,\r\n this.offset.y,\r\n subdivisions,\r\n major\r\n )\r\n\r\n const dots = new Graphics2D()\r\n let drew = false\r\n for (const column of xs) {\r\n for (const row of ys) {\r\n // A dot is major only where *both* axes are — an intersection of two\r\n // major rules, which is exactly the point a line grid draws heaviest.\r\n const size = column.isMajor && row.isMajor ? major : minor\r\n if (size <= 0) continue\r\n dots.ellipse({ x: column.pos, y: row.pos, width: size * 2, height: size * 2 })\r\n drew = true\r\n }\r\n }\r\n return drew ? dots : null\r\n }\r\n\r\n protected override clipSelf(): Clip {\r\n const bounds = this.layoutBounds\r\n return new Clip().rect({\r\n width: bounds?.width ?? 0,\r\n height: bounds?.height ?? 0,\r\n })\r\n }\r\n}\r\n", "import {\r\n Graphics2D,\r\n lerpNumber,\r\n lerpVector2,\r\n node,\r\n property,\r\n strokeProperty,\r\n type AssetScope,\r\n type BoxBounds,\r\n type NodeConfig,\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, gridLines, maxWeight, ViewportPattern, type GridAxis } from \"../kit\";\r\n\r\nexport interface GridPatternProps extends ShapeProps {\r\n /** Spacing between grid lines in world units: one number for both axes, or `{ x, y }`. */\r\n cellSize: number | Vector2;\r\n /** Finer cells each cell is split into, as in {@link LineGridPattern.subdivisions}. */\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 /** Scrolls the pattern relative to the world, which it is otherwise anchored to. */\r\n offset: Vector2;\r\n}\r\n\r\n/**\r\n * An infinite line grid that fills the camera's visible region. Like\r\n * {@link LineGridPattern} it draws major and minor strokes over a fill and pans\r\n * with `offset`, but it tiles a world-anchored grid (spacing `cellSize`) across\r\n * what the parent {@link Camera} can see, regenerated each frame. With no camera\r\n * it fills its own layout rect.\r\n */\r\n@node({ key: \"gridPattern\", parentKey: \"shape\", forkable: true })\r\nexport class GridPattern extends ViewportPattern<GridPatternProps> {\r\n\r\n @property({ default: 100, tween: lerpCellSize })\r\n declare readonly cellSize: number | Vector2;\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<GridPattern, GridPatternProps>) {\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 renderPattern(draw: RenderContext2D, bounds: BoxBounds): void {\r\n const halfW = bounds.width / 2;\r\n const halfH = bounds.height / 2;\r\n // `bounds` is centred on (x, y) in y-up world space: descriptor coordinates are y-up\r\n // and the renderer applies the single flip.\r\n const left = bounds.x - halfW;\r\n const right = bounds.x + halfW;\r\n const top = bounds.y - halfH;\r\n const bottom = bounds.y + halfH;\r\n\r\n draw.draw(new Graphics2D()\r\n .rect({ x: bounds.x, y: bounds.y, width: bounds.width, height: bounds.height, start: this.start, end: this.end })\r\n .shadow(this.shadow)\r\n .fill(this.fill));\r\n\r\n const subdivisions = Math.max(1, Math.floor(this.subdivisions));\r\n const cell = this.cellSize;\r\n const cellX = Math.max(1e-3, typeof cell === \"number\" ? cell : cell.x);\r\n const cellY = Math.max(1e-3, typeof cell === \"number\" ? cell : cell.y);\r\n const stepX = cellX / subdivisions;\r\n const stepY = cellY / subdivisions;\r\n\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\r\n const xAxis: GridAxis = { min: left, max: right, step: stepX, offset: this.offset.x };\r\n const yAxis: GridAxis = { min: top, max: bottom, step: stepY, offset: this.offset.y };\r\n\r\n // Minor lines first so the major lines sit on top.\r\n if (subdivisions > 1 && minorStroke.length > 0) {\r\n this._drawGroup(draw, xAxis, yAxis, subdivisions, overscan, minorStroke, false);\r\n }\r\n if (major.length > 0) {\r\n this._drawGroup(draw, xAxis, yAxis, subdivisions, overscan, major, true);\r\n }\r\n }\r\n\r\n // A solid stroke paints the group as one union path. A dashed one draws each line on\r\n // its own with its dash phase anchored to the line's world coordinate, so dashes never\r\n // crawl as the camera pans or new lines scroll in.\r\n private _drawGroup(\r\n draw: RenderContext2D,\r\n xAxis: GridAxis,\r\n yAxis: GridAxis,\r\n subdivisions: number,\r\n overscan: number,\r\n stroke: StrokeResolved[],\r\n isMajor: boolean,\r\n ): void {\r\n // Each line spans a whole number of dash cycles, so the renderer's per-path dash-fit\r\n // is a no-op and every line dashes identically.\r\n const cycle = dashCycle(stroke);\r\n const g = gridLines(xAxis, yAxis, subdivisions, overscan, cycle);\r\n const verticals = isMajor ? g.verticalMajor : g.verticalMinor;\r\n const horizontals = isMajor ? g.horizontalMajor : g.horizontalMinor;\r\n\r\n // Symmetric centerBounds give a zero recentre offset, so local coordinates draw verbatim.\r\n const centerBounds = [-1, -1, 1, 1] as const;\r\n\r\n if (cycle <= 0) {\r\n const data: PathCommand[] = [];\r\n for (const px of verticals) data.push({ type: \"M\", x: px, y: g.top }, { type: \"L\", x: px, y: g.bottom });\r\n for (const py of horizontals) data.push({ type: \"M\", x: g.left, y: py }, { type: \"L\", x: g.right, y: py });\r\n if (data.length > 0) draw.draw(new Graphics2D().path({ data, centerBounds }).stroke(stroke));\r\n return;\r\n }\r\n\r\n for (const px of verticals) {\r\n const data: PathCommand[] = [{ type: \"M\", x: px, y: g.top }, { type: \"L\", x: px, y: g.bottom }];\r\n draw.draw(new Graphics2D().path({ data, centerBounds }).stroke(phaseShift(stroke, g.top)));\r\n }\r\n for (const py of horizontals) {\r\n const data: PathCommand[] = [{ type: \"M\", x: g.left, y: py }, { type: \"L\", x: g.right, y: py }];\r\n draw.draw(new Graphics2D().path({ data, centerBounds }).stroke(phaseShift(stroke, g.left)));\r\n }\r\n }\r\n}\r\n\r\n// The largest dash-array sum across the layers, or 0 when none is dashed.\r\nfunction dashCycle(strokes: StrokeResolved[]): number {\r\n let cycle = 0;\r\n for (const s of strokes) {\r\n if (s.dash && s.dash.length > 0) {\r\n const sum = s.dash.reduce((a, b) => a + b, 0);\r\n if (sum > cycle) cycle = sum;\r\n }\r\n }\r\n return cycle;\r\n}\r\n\r\n// `dashOffset` advances the pattern, so it is negated to put the \"on\" run at the phase one\r\n// infinite line would have at this world coordinate.\r\nfunction phaseShift(strokes: StrokeResolved[], worldStart: number): StrokeResolved[] {\r\n return strokes.map(s => (s.dash && s.dash.length > 0)\r\n ? { ...s, dashOffset: (s.dashOffset ?? 0) - worldStart }\r\n : s);\r\n}\r\n\r\n// A number and a vector tween by promoting the number to a uniform vector.\r\nfunction lerpCellSize(from: number | Vector2, to: number | Vector2, t: number): number | Vector2 {\r\n if (typeof from === \"number\" && typeof to === \"number\") return lerpNumber(from, to, t);\r\n const a = typeof from === \"number\" ? { x: from, y: from } : from;\r\n const b = typeof to === \"number\" ? { x: to, y: to } : to;\r\n return lerpVector2(a, b, t);\r\n}\r\n", "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"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
4
|
+
"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", "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 Size2D,\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 { addTiledLines } from \"../kit\"\r\n\r\n/** One mark's place on an axis, and whether it lands on the coarse grid. */\r\ninterface GridPosition {\r\n pos: number\r\n isMajor: boolean\r\n}\r\n\r\n// Calls the tiling `LineGridPattern` uses, so dots stay on its intersections at every offset.\r\nfunction gridPositions(\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): GridPosition[] {\r\n const out: GridPosition[] = []\r\n // Anchored at the near edge, so a column or row sits on each edge of the box for any count of cells.\r\n addTiledLines(min, max, step, offset, subdivisions, overscan, (pos, isMajor) => {\r\n out.push({ pos, isMajor })\r\n }, min)\r\n return out\r\n}\r\n\r\nconst state = {\r\n ...Paint.state,\r\n ...Flow.state,\r\n /** Cells along each axis, as in `LineGridPattern.divisions`: 4 puts 5 major dots on each axis. */\r\n divisions: 4,\r\n /** Splits each division again. `1` draws only the major dots; `2` puts one minor dot between each pair. */\r\n subdivisions: 1,\r\n /** Radius of a major dot. */\r\n radius: 3,\r\n /**\r\n * A minor dot's radius as a fraction of a major one's. A fraction rather than a\r\n * second paint stack, so the whole field stays one fill and a gradient crosses\r\n * every dot in it.\r\n */\r\n subScale: 0.5,\r\n /** Pans the field, as `LineGridPattern.offset` does, so the two stay aligned while both scroll. */\r\n offset: Types.custom<Vector2>({ x: 0, y: 0 }, { lerp: lerpVector2 }),\r\n}\r\n\r\ninterface DotField {\r\n readonly divisions: number\r\n readonly subdivisions: number\r\n readonly radius: number\r\n readonly subScale: number\r\n readonly offset: Vector2\r\n}\r\n\r\n/**\r\n * A field of dots on the same `divisions` / `subdivisions` / `offset` as\r\n * `LineGridPattern`, so laid over one the dots sit on its intersections.\r\n *\r\n * The silhouette is the dots, which `Paint.draw` paints with `shadow`, `fill`,\r\n * `overlay` and `stroke`. A dot grid has no \"paper\": a rectangle behind it is how\r\n * it gets a background.\r\n *\r\n * What `clip` confines the children to, and what picking tests, is the node's\r\n * box rather than the silhouette, which clips outer dots as they pan out and\r\n * keeps the node selectable between dots. `start` / `end` act on nothing:\r\n * trimming a disc leaves a crescent, not a partial grid.\r\n */\r\nexport const DotGridPattern = component2d({\r\n key: \"dotGridPattern\",\r\n state,\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 untrimmed = {\r\n fill: state.fill, stroke: state.stroke, shadow: state.shadow, overlay: state.overlay, start: 0, end: 1, clip: state.clip,\r\n }\r\n const box = new Graphics2D().rect({ width: ctx.size.width, height: ctx.size.height })\r\n Paint.draw(ctx, untrimmed, dots(ctx.size, state), { clipShape: box })\r\n },\r\n})\r\n\r\nexport type DotGridPattern = NodeOf<typeof DotGridPattern>\r\n/** What a call or a document row may set. */\r\nexport type DotGridPatternProps = NonNullable<Parameters<typeof DotGridPattern>[0]>\r\n\r\n/** Every dot in the field as one un-painted union: the paint stacks belong to the grid, not to a dot. */\r\nfunction dots(size: Size2D, s: DotField): Graphics2D | null {\r\n const { width, height } = size\r\n if (width <= 0 || height <= 0) return null\r\n\r\n const divisions = Math.max(1, Math.floor(s.divisions))\r\n const subdivisions = Math.max(1, Math.floor(s.subdivisions))\r\n const major = Math.max(0, s.radius)\r\n const minor = major * Math.max(0, s.subScale)\r\n if (major <= 0 && minor <= 0) return null\r\n\r\n // Inset by a dot's radius so an edge dot sits inside the box rather than being halved by the clip.\r\n const cols = divisions * subdivisions\r\n const insetX = Math.max(0, width / 2 - major)\r\n const insetY = Math.max(0, height / 2 - major)\r\n const xs = gridPositions(\r\n -insetX,\r\n insetX,\r\n (insetX * 2) / cols,\r\n s.offset.x,\r\n subdivisions,\r\n major\r\n )\r\n const ys = gridPositions(\r\n -insetY,\r\n insetY,\r\n (insetY * 2) / cols,\r\n s.offset.y,\r\n subdivisions,\r\n major\r\n )\r\n\r\n const field = new Graphics2D()\r\n let drew = false\r\n for (const column of xs) {\r\n for (const row of ys) {\r\n // A dot is major only where *both* axes are — an intersection of two\r\n // major rules, which is exactly the point a line grid draws heaviest.\r\n const size = column.isMajor && row.isMajor ? major : minor\r\n if (size <= 0) continue\r\n field.ellipse({ x: column.pos, y: row.pos, width: size * 2, height: size * 2 })\r\n drew = true\r\n }\r\n }\r\n return drew ? field : null\r\n}\r\n", "import {\r\n Graphics2D,\r\n Types,\r\n component2d,\r\n lerpNumber,\r\n lerpVector2,\r\n type BoxBounds,\r\n type NodeOf,\r\n type PathCommand,\r\n type RenderContext,\r\n type ShadowResolved,\r\n type FillResolved,\r\n type StrokeResolved,\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 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 Stroke as _Stroke,\r\n} from \"@motionscript/sdk\";\r\n\r\nimport { centered, defaultSubStroke, gridLines, maxWeight, ViewportPattern, type GridAxis } from \"../kit\";\r\n\r\n/**\r\n * An infinite line grid that fills the camera's visible region. Like\r\n * `LineGridPattern` it draws major and minor strokes over a fill and pans\r\n * with `offset`, but it tiles a world-anchored grid (spacing `cellSize`) across\r\n * what the nearest `Camera` above it can see, regenerated each frame. With no\r\n * camera it fills its own layout rect.\r\n */\r\nexport const GridPattern = component2d({\r\n key: \"gridPattern\",\r\n state: {\r\n ...ViewportPattern.state,\r\n /** Spacing between grid lines in world units: one number for both axes, or `{ x, y }`. */\r\n cellSize: Types.custom<number | Vector2>(100, { lerp: lerpCellSize }),\r\n /** Finer cells each cell is split into, as in `LineGridPattern.subdivisions`. */\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 /** Scrolls the pattern relative to the world, which it is otherwise anchored to. */\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: { ...ViewportPattern.commands },\r\n measure: ViewportPattern.measure,\r\n layout: ViewportPattern.layout,\r\n render: (ctx, state) => ViewportPattern.draw(ctx, (bounds) => drawGrid(ctx, state, bounds)),\r\n});\r\n\r\nexport type GridPattern = NodeOf<typeof GridPattern>;\r\n/** What a call or a document row may set. */\r\nexport type GridPatternProps = NonNullable<Parameters<typeof GridPattern>[0]>;\r\n\r\ninterface GridState {\r\n readonly fill: FillResolved[];\r\n readonly stroke: StrokeResolved[];\r\n readonly shadow: ShadowResolved[];\r\n readonly start: number;\r\n readonly end: number;\r\n readonly cellSize: number | Vector2;\r\n readonly subdivisions: number;\r\n readonly subStroke: StrokeResolved[];\r\n readonly offset: Vector2;\r\n}\r\n\r\nfunction drawGrid(ctx: RenderContext, s: GridState, bounds: BoxBounds): void {\r\n const halfW = bounds.width / 2;\r\n const halfH = bounds.height / 2;\r\n // `bounds` is centred on (x, y) in y-up world space: descriptor coordinates are y-up\r\n // and the renderer applies the single flip.\r\n const left = bounds.x - halfW;\r\n const right = bounds.x + halfW;\r\n const top = bounds.y - halfH;\r\n const bottom = bounds.y + halfH;\r\n\r\n ctx.draw(new Graphics2D()\r\n .rect({ x: bounds.x, y: bounds.y, width: bounds.width, height: bounds.height, start: s.start, end: s.end })\r\n .shadow(s.shadow)\r\n .fill(s.fill));\r\n\r\n const subdivisions = Math.max(1, Math.floor(s.subdivisions));\r\n const cell = s.cellSize;\r\n const cellX = Math.max(1e-3, typeof cell === \"number\" ? cell : cell.x);\r\n const cellY = Math.max(1e-3, typeof cell === \"number\" ? cell : cell.y);\r\n const stepX = cellX / subdivisions;\r\n const stepY = cellY / subdivisions;\r\n\r\n const major = centered(s.stroke);\r\n const minorStroke = centered(s.subStroke);\r\n const overscan = Math.max(maxWeight(major), maxWeight(minorStroke)) / 2;\r\n\r\n const xAxis: GridAxis = { min: left, max: right, step: stepX, offset: s.offset.x };\r\n const yAxis: GridAxis = { min: top, max: bottom, step: stepY, offset: s.offset.y };\r\n\r\n // Minor lines first so the major lines sit on top.\r\n if (subdivisions > 1 && minorStroke.length > 0) {\r\n drawGroup(ctx, xAxis, yAxis, subdivisions, overscan, minorStroke, false);\r\n }\r\n if (major.length > 0) {\r\n drawGroup(ctx, xAxis, yAxis, subdivisions, overscan, major, true);\r\n }\r\n}\r\n\r\n// A solid stroke paints the group as one union path. A dashed one draws each line on\r\n// its own with its dash phase anchored to the line's world coordinate, so dashes never\r\n// crawl as the camera pans or new lines scroll in.\r\nfunction drawGroup(\r\n ctx: RenderContext,\r\n xAxis: GridAxis,\r\n yAxis: GridAxis,\r\n subdivisions: number,\r\n overscan: number,\r\n stroke: StrokeResolved[],\r\n isMajor: boolean,\r\n): void {\r\n // Each line spans a whole number of dash cycles, so the renderer's per-path dash-fit\r\n // is a no-op and every line dashes identically.\r\n const cycle = dashCycle(stroke);\r\n const g = gridLines(xAxis, yAxis, subdivisions, overscan, cycle);\r\n const verticals = isMajor ? g.verticalMajor : g.verticalMinor;\r\n const horizontals = isMajor ? g.horizontalMajor : g.horizontalMinor;\r\n\r\n // Symmetric centerBounds give a zero recentre offset, so local coordinates draw verbatim.\r\n const centerBounds = [-1, -1, 1, 1] as const;\r\n\r\n if (cycle <= 0) {\r\n const data: PathCommand[] = [];\r\n for (const px of verticals) data.push({ type: \"M\", x: px, y: g.top }, { type: \"L\", x: px, y: g.bottom });\r\n for (const py of horizontals) data.push({ type: \"M\", x: g.left, y: py }, { type: \"L\", x: g.right, y: py });\r\n if (data.length > 0) ctx.draw(new Graphics2D().path({ data, centerBounds }).stroke(stroke));\r\n return;\r\n }\r\n\r\n for (const px of verticals) {\r\n const data: PathCommand[] = [{ type: \"M\", x: px, y: g.top }, { type: \"L\", x: px, y: g.bottom }];\r\n ctx.draw(new Graphics2D().path({ data, centerBounds }).stroke(phaseShift(stroke, g.top)));\r\n }\r\n for (const py of horizontals) {\r\n const data: PathCommand[] = [{ type: \"M\", x: g.left, y: py }, { type: \"L\", x: g.right, y: py }];\r\n ctx.draw(new Graphics2D().path({ data, centerBounds }).stroke(phaseShift(stroke, g.left)));\r\n }\r\n}\r\n\r\n// The largest dash-array sum across the layers, or 0 when none is dashed.\r\nfunction dashCycle(strokes: StrokeResolved[]): number {\r\n let cycle = 0;\r\n for (const s of strokes) {\r\n if (s.dash && s.dash.length > 0) {\r\n const sum = s.dash.reduce((a, b) => a + b, 0);\r\n if (sum > cycle) cycle = sum;\r\n }\r\n }\r\n return cycle;\r\n}\r\n\r\n// `dashOffset` advances the pattern, so it is negated to put the \"on\" run at the phase one\r\n// infinite line would have at this world coordinate.\r\nfunction phaseShift(strokes: StrokeResolved[], worldStart: number): StrokeResolved[] {\r\n return strokes.map(s => (s.dash && s.dash.length > 0)\r\n ? { ...s, dashOffset: (s.dashOffset ?? 0) - worldStart }\r\n : s);\r\n}\r\n\r\n// A number and a vector tween by promoting the number to a uniform vector.\r\nfunction lerpCellSize(from: number | Vector2, to: number | Vector2, t: number): number | Vector2 {\r\n if (typeof from === \"number\" && typeof to === \"number\") return lerpNumber(from, to, t);\r\n const a = typeof from === \"number\" ? { x: from, y: from } : from;\r\n const b = typeof to === \"number\" ? { x: to, y: to } : to;\r\n return lerpVector2(a, b, t);\r\n}\r\n", "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"],
|
|
5
|
+
"mappings": "iGAAA,OACI,QAAAA,EACA,cAAAC,EACA,SAAAC,EACA,SAAAC,EACA,eAAAC,EACA,eAAAC,MAkBG,oBAUA,IAAMC,EAAkBC,EAAY,CACvC,IAAK,kBACL,MAAO,CACH,GAAGC,EAAM,MACT,GAAGC,EAAK,MAER,UAAW,EAEX,aAAc,EAEd,UAAWC,EAAM,OAEjB,OAAQA,EAAM,OAAgB,CAAE,EAAG,EAAG,EAAG,CAAC,EAAI,CAAE,KAAMC,CAAW,CAAE,GAEvE,SAAU,CAAE,UAAW,CAACC,EA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EAAU,EAAG,KAAK,CAAE,KAAAwB,EAAM,aAAAD,CAAY,CAAE,EAAE,OAAOI,EAAWZ,EAAQI,EAAE,IAAI,CAAC,CAAC,CAC7F,CACJ,CAGA,SAASD,GAAUU,EAAyB,CACxC,IAAIX,EAAQ,EACZ,QAAWxB,KAAKmC,EACZ,GAAInC,EAAE,MAAQA,EAAE,KAAK,OAAS,EAAG,CAC7B,IAAMoC,EAAMpC,EAAE,KAAK,OAAO,CAAC,EAAGqC,IAAM,EAAIA,EAAG,CAAC,EACxCD,EAAMZ,IAAOA,EAAQY,EAC7B,CAEJ,OAAOZ,CACX,CAIA,SAASU,EAAWC,EAA2BG,EAAkB,CAC7D,OAAOH,EAAQ,IAAInC,GAAMA,EAAE,MAAQA,EAAE,KAAK,OAAS,EAC7C,CAAE,GAAGA,EAAG,YAAaA,EAAE,YAAc,GAAKsC,CAAU,EACpDtC,CAAC,CACX,CAGA,SAAST,GAAagD,EAAwBC,EAAsBC,EAAS,CACzE,OAAI,OAAOF,GAAS,UAAY,OAAOC,GAAO,SAAiBE,EAAWH,EAAMC,EAAIC,CAAC,EAG9EjD,EAFG,OAAO+C,GAAS,SAAW,CAAE,EAAGA,EAAM,EAAGA,CAAI,EAAKA,EAClD,OAAOC,GAAO,SAAW,CAAE,EAAGA,EAAI,EAAGA,CAAE,EAAKA,EAC7BC,CAAC,CAC9B,CCzJO,IAAME,GAAmB,CAC5BC,EACAC,EACAC",
|
|
6
|
+
"names": ["Flow", "Graphics2D", "Paint", "Types", "component2d", "lerpVector2", "LineGridPattern", "component2d", "Paint", "Flow", "Types", "lerpVector2", "_state", "given", "defaultSubStroke", "measurer", "state", "children", "box", "ctx", "width", "height", "Graphics2D", "divisions", "subdivisions", "major", "centered", "minorStroke", "overscan", "maxWeight", "lines", "gridPaths", "centerBounds", "offset", "cols", "innerW", "innerH", "insetX", "insetY", "gridLinePaths", "Flow", "Graphics2D", "Paint", "Types", "component2d", "lerpVector2", "gridPositions", "min", "max", "step", "offset", "subdivisions", "overscan", "out", "addTiledLines", "pos", "isMajor", "state", "Paint", "Flow", "Types", "lerpVector2", "DotGridPattern", "component2d", "measurer", "children", "box", "ctx", "untrimmed", "Graphics2D", "dots", "size", "s", "width", "height", "divisions", "major", "minor", "cols", "insetX", "insetY", "xs", "ys", "field", "drew", "column", "row", "Graphics2D", "Types", "component2d", "lerpNumber", "lerpVector2", "GridPattern", "component2d", "viewport_pattern_exports", "Types", "lerpCellSize", "lerpVector2", "_state", "given", "defaultSubStroke", "ctx", "state", "bounds", "drawGrid", "s", "halfW", "halfH", "left", "right", "top", "bottom", "Graphics2D", "subdivisions", "cell", "cellX", "cellY", "stepX", "stepY", "major", "centered", "minorStroke", "overscan", "maxWeight", "xAxis", "yAxis", "drawGroup", "stroke", "isMajor", "cycle", "dashCycle", "g", "gridLines", "verticals", "horizontals", "centerBounds", "data", "px", "py", "phaseShift", "strokes", "sum", "b", "worldStart", "from", "to", "t", "lerpNumber", "NODES", "LineGridPattern", "DotGridPattern", "GridPattern"]
|
|
7
7
|
}
|
package/dist/browser/kit.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b,c,d,e,f,g}from"./chunks/chunk-
|
|
1
|
+
import{a,b,c,d,e,f,g,h}from"./chunks/chunk-REWLNFZ2.js";export{h as ViewportPattern,c as addTiledLines,e as centered,g as defaultSubStroke,f as dimStroke,b as gridLinePaths,a as gridLines,d as maxWeight};
|
|
2
2
|
//# sourceMappingURL=kit.js.map
|
|
@@ -1,5 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { type NodeOf, type Vector2, type Alignment as _Alignment, type Fill as _Fill, type FillResolved as _FillResolved, type FlowMode as _FlowMode, type FlowResolved as _FlowResolved, type GapSize as _GapSize, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Shadow as _Shadow, type ShadowResolved as _ShadowResolved, type Stroke as _Stroke, type StrokeResolved as _StrokeResolved } from "@motionscript/sdk";
|
|
2
|
+
/**
|
|
3
|
+
* A field of dots on the same `divisions` / `subdivisions` / `offset` as
|
|
4
|
+
* `LineGridPattern`, so laid over one the dots sit on its intersections.
|
|
5
|
+
*
|
|
6
|
+
* The silhouette is the dots, which `Paint.draw` paints with `shadow`, `fill`,
|
|
7
|
+
* `overlay` and `stroke`. A dot grid has no "paper": a rectangle behind it is how
|
|
8
|
+
* it gets a background.
|
|
9
|
+
*
|
|
10
|
+
* What `clip` confines the children to, and what picking tests, is the node's
|
|
11
|
+
* box rather than the silhouette, which clips outer dots as they pan out and
|
|
12
|
+
* keeps the node selectable between dots. `start` / `end` act on nothing:
|
|
13
|
+
* trimming a disc leaves a crescent, not a partial grid.
|
|
14
|
+
*/
|
|
15
|
+
export declare const DotGridPattern: import("@motionscript/sdk").Component<"dotGridPattern", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
3
16
|
/** Cells along each axis, as in `LineGridPattern.divisions`: 4 puts 5 major dots on each axis. */
|
|
4
17
|
divisions: number;
|
|
5
18
|
/** Splits each division again. `1` draws only the major dots; `2` puts one minor dot between each pair. */
|
|
@@ -13,29 +26,57 @@ export interface DotGridPatternProps extends ShapeProps {
|
|
|
13
26
|
*/
|
|
14
27
|
subScale: number;
|
|
15
28
|
/** Pans the field, as `LineGridPattern.offset` does, so the two stay aligned while both scroll. */
|
|
16
|
-
offset: Vector2
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
readonly
|
|
33
|
-
readonly
|
|
34
|
-
readonly
|
|
35
|
-
readonly
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
offset: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
|
|
30
|
+
flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
|
|
31
|
+
gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
|
|
32
|
+
wrap: boolean;
|
|
33
|
+
crossGap: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
|
|
34
|
+
columns: import("@motionscript/sdk").Type<number, number, false>;
|
|
35
|
+
align: import("@motionscript/sdk").Attribute<_Alignment, Vector2>;
|
|
36
|
+
fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
37
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
38
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
39
|
+
overlay: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
40
|
+
start: import("@motionscript/sdk").Type<number, number, false>;
|
|
41
|
+
end: import("@motionscript/sdk").Type<number, number, false>;
|
|
42
|
+
}>, {
|
|
43
|
+
readonly fillTo: readonly ["fill"];
|
|
44
|
+
readonly strokeTo: readonly ["stroke"];
|
|
45
|
+
readonly shadowTo: readonly ["shadow"];
|
|
46
|
+
readonly overlayTo: readonly ["overlay"];
|
|
47
|
+
readonly progressTo: readonly ["start", "end"];
|
|
48
|
+
readonly flash: {
|
|
49
|
+
readonly portion: import("@motionscript/sdk").Type<number, number, false>;
|
|
50
|
+
};
|
|
51
|
+
}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
52
|
+
/** Cells along each axis, as in `LineGridPattern.divisions`: 4 puts 5 major dots on each axis. */
|
|
53
|
+
divisions: number;
|
|
54
|
+
/** Splits each division again. `1` draws only the major dots; `2` puts one minor dot between each pair. */
|
|
55
|
+
subdivisions: number;
|
|
56
|
+
/** Radius of a major dot. */
|
|
57
|
+
radius: number;
|
|
58
|
+
/**
|
|
59
|
+
* A minor dot's radius as a fraction of a major one's. A fraction rather than a
|
|
60
|
+
* second paint stack, so the whole field stays one fill and a gradient crosses
|
|
61
|
+
* every dot in it.
|
|
62
|
+
*/
|
|
63
|
+
subScale: number;
|
|
64
|
+
/** Pans the field, as `LineGridPattern.offset` does, so the two stay aligned while both scroll. */
|
|
65
|
+
offset: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
|
|
66
|
+
flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
|
|
67
|
+
gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
|
|
68
|
+
wrap: boolean;
|
|
69
|
+
crossGap: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
|
|
70
|
+
columns: import("@motionscript/sdk").Type<number, number, false>;
|
|
71
|
+
align: import("@motionscript/sdk").Attribute<_Alignment, Vector2>;
|
|
72
|
+
fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
73
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
74
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
75
|
+
overlay: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
76
|
+
start: import("@motionscript/sdk").Type<number, number, false>;
|
|
77
|
+
end: import("@motionscript/sdk").Type<number, number, false>;
|
|
78
|
+
}>, null>>;
|
|
79
|
+
export type DotGridPattern = NodeOf<typeof DotGridPattern>;
|
|
80
|
+
/** What a call or a document row may set. */
|
|
81
|
+
export type DotGridPatternProps = NonNullable<Parameters<typeof DotGridPattern>[0]>;
|
|
41
82
|
//# sourceMappingURL=dot-grid-pattern.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dot-grid-pattern.d.ts","sourceRoot":"","sources":["../../src/dot-grid-pattern/dot-grid-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"dot-grid-pattern.d.ts","sourceRoot":"","sources":["../../src/dot-grid-pattern/dot-grid-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,MAAM,EAEX,KAAK,OAAO,EAEZ,KAAK,SAAS,IAAI,UAAU,EAC5B,KAAK,IAAI,IAAI,KAAK,EAClB,KAAK,YAAY,IAAI,aAAa,EAClC,KAAK,QAAQ,IAAI,SAAS,EAC1B,KAAK,YAAY,IAAI,aAAa,EAClC,KAAK,OAAO,IAAI,QAAQ,EACxB,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,IAAI,YAAY,EAChC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACtC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACvC,MAAM,mBAAmB,CAAA;AAsD1B;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,cAAc;IArCzB,kGAAkG;;IAElG,2GAA2G;;IAE3G,6BAA6B;;IAE7B;;;;OAIG;;IAEH,mGAAmG;;;;;;;;;;;;;;;;;;;;;;;;IAZnG,kGAAkG;;IAElG,2GAA2G;;IAE3G,6BAA6B;;IAE7B;;;;OAIG;;IAEH,mGAAmG;;;;;;;;;;;;;;UAsCnG,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,cAAc,CAAC,CAAA;AAC1D,6CAA6C;AAC7C,MAAM,MAAM,mBAAmB,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA"}
|