@motionscript/patterns 0.1.0 → 0.1.1-alpha.1
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 +21 -0
- package/dist/browser/chunks/{chunk-FXDYEY4R.js → chunk-DRFXMB3M.js} +1 -1
- package/dist/browser/chunks/chunk-DRFXMB3M.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 +17 -36
- package/dist/dot-grid-pattern/dot-grid-pattern.d.ts.map +1 -1
- package/dist/dot-grid-pattern/dot-grid-pattern.js +13 -23
- package/dist/dot-grid-pattern/dot-grid-pattern.js.map +1 -1
- package/dist/engine.d.ts +3 -8
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +3 -8
- package/dist/engine.js.map +1 -1
- package/dist/grid-pattern/grid-pattern.d.ts +4 -7
- package/dist/grid-pattern/grid-pattern.d.ts.map +1 -1
- package/dist/grid-pattern/grid-pattern.js +16 -24
- package/dist/grid-pattern/grid-pattern.js.map +1 -1
- package/dist/kit/grid-lines.d.ts +24 -66
- package/dist/kit/grid-lines.d.ts.map +1 -1
- package/dist/kit/grid-lines.js +24 -52
- package/dist/kit/grid-lines.js.map +1 -1
- package/dist/kit/viewport-pattern.d.ts +10 -27
- package/dist/kit/viewport-pattern.d.ts.map +1 -1
- package/dist/kit/viewport-pattern.js +12 -33
- package/dist/kit/viewport-pattern.js.map +1 -1
- package/dist/line-grid-pattern/line-grid-pattern.d.ts +0 -2
- package/dist/line-grid-pattern/line-grid-pattern.d.ts.map +1 -1
- package/dist/line-grid-pattern/line-grid-pattern.js +0 -2
- package/dist/line-grid-pattern/line-grid-pattern.js.map +1 -1
- package/dist/nodes.d.ts +0 -12
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js.map +1 -1
- package/package.json +4 -4
- package/src/dot-grid-pattern/dot-grid-pattern.ts +15 -33
- package/src/engine.ts +3 -8
- package/src/grid-pattern/grid-pattern.ts +17 -25
- package/src/kit/grid-lines.ts +30 -81
- package/src/kit/viewport-pattern.ts +12 -34
- package/src/line-grid-pattern/line-grid-pattern.ts +0 -4
- package/src/nodes.ts +0 -12
- package/dist/browser/chunks/chunk-FXDYEY4R.js.map +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @motionscript/patterns
|
|
2
2
|
|
|
3
|
+
## 0.1.1-alpha.1
|
|
4
|
+
|
|
5
|
+
## 0.1.1-alpha.0
|
|
6
|
+
|
|
7
|
+
### Patch Changes
|
|
8
|
+
|
|
9
|
+
- e279864: **Breaking:** the component kits drop exports nothing used.
|
|
10
|
+
|
|
11
|
+
- **math:** the hand-mirrored `*Props` interfaces of 24 components (`AngleMarkProps`, `CurlyBraceProps`, `EmphasisMarkProps`, `CurveAreaProps`, `DropLinesProps`, `PlotPointProps`, `RiemannSumProps`, `TangentLineProps`, `VectorArrowProps`, `PointsPlotProps`, `StreamLinesProps`, `TracedPathProps`, `VectorFieldProps`, `NetworkGraphProps`, `SampleSpaceProps`, `NumberLineProps`, `NumberPlaneProps`, `PolarPlaneProps`, `LatexMatrixProps`, `Axes3dProps`, `CurvePlot3dProps`, `PlotPoint3dProps`, `SurfacePlot3dProps`, `VectorArrow3dProps`), `FILL_PAINT`, `STROKE_PAINT`, `OUTLINE_TRIM` and `spaceOf` from `./kit`, and `LatexPathResult.commands`.
|
|
12
|
+
- **charts:** `LineChartProps`, `BarChartProps`, `PieChartProps`, `PieRingProps`, `PieLegendProps`, `ChartBarsProps`, `CategoryAxisProps`, `ChartBorderProps`, `ChartCanvasProps`, `ChartLegendProps`, `VerticalAxisProps`, and from `./kit` `axisTweenTarget`, `resolvePalettePaint`, `legendShows`, `MarkerLabel`, `clampUnit` (use the SDK's `clamp`). `niceStep` and `enterBudget` stay reachable from `@motionscript/sdk/component`.
|
|
13
|
+
- **audio:** `FullWaveformProps`, `LiveWaveformProps`, and `clamp01` from `./kit`.
|
|
14
|
+
- **patterns:** `DotGridPatternProps`, `GridPatternProps`, `LineGridPatternProps`.
|
|
15
|
+
- **code:** `DEFAULT_THEMES`, `splitTokensAt`, `LINE_ALIGN_CELLS`, `EDIT_ALIGN_CELLS`, and `phasesFor` (use `defaultCodePhases`). `ensureHighlighter`, `loadCodeLanguage`, `initSyntaxHighlighter` and `canHighlight` lose their ignored theme argument.
|
|
16
|
+
- **grids:** the `findNode2D` and `frameIn` re-exports (import them from `@motionscript/sdk`), `ArrangementKind`, `PathGridShape`, `RectangularGridProps`, `RadialGridProps`, `PathGridProps`, `SphereGridProps`.
|
|
17
|
+
- **geography:** `GeoBorderProps`.
|
|
18
|
+
|
|
19
|
+
Migration: no stored document is affected; only TypeScript imports change. Code that imported a removed `*Props` interface states the props it passes inline, and code that used a removed helper uses the replacement named beside it above.
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [e279864]
|
|
22
|
+
- @motionscript/sdk@0.1.1-alpha.0
|
|
23
|
+
|
|
3
24
|
## 0.1.0
|
|
4
25
|
|
|
5
26
|
## 0.1.0-alpha.10
|
|
@@ -1,2 +1,2 @@
|
|
|
1
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-
|
|
2
|
+
//# sourceMappingURL=chunk-DRFXMB3M.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\";\n\n/** A grid extent on one axis: lines tile within `[min, max]`, on a lattice that starts at `anchor`. */\nexport interface GridAxis {\n min: number;\n max: number;\n /** Spacing between adjacent (minor) lines. */\n step: number;\n /** Pan offset in pixels. */\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\n * 0, the world origin, which a camera-following grid keeps. A grid with a box of\n * its own sets it to `min`, so the box's edges are lines whatever the cell count.\n */\n anchor?: number;\n}\n\n/** Where each line sits, split into major (division) and minor (subdivision) lines. Vertical lines run `top` to `bottom`, horizontal ones `left` to `right`. */\ninterface GridLines {\n top: number;\n bottom: number;\n left: number;\n right: number;\n verticalMajor: number[];\n verticalMinor: number[];\n horizontalMajor: number[];\n horizontalMinor: number[];\n}\n\n/**\n * The cross-axis spans and the major/minor line positions per axis. Spans are\n * grown by `overscan` so a thick line slides out under the clip instead of\n * popping, and snapped outward so a line's start stays fixed as the camera pans\n * (a dashed stroke anchored to it would otherwise crawl). `cycle`, the dash\n * period, snaps the span to whole dash cycles too, so every parallel line is the\n * same length and the renderer's per-path dash-fit is a no-op.\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 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 * The lines as one multi-subpath path per group (major, minor), so each stroke\n * paints as a union with no destructive boolean op, which would erase open lines.\n * For solid strokes; dashed strokes that must stay world-locked draw per line from\n * {@link gridLines}.\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// Snaps `pos` outward to a stable world position, since the renderer anchors dash\n// phase to the subpath start. It snaps to the line lattice (`n*step + offset`), or\n// to the dash lattice (`n*cycle`, anchored to world 0) when a `cycle` is given.\n// The lattice is the one about 0 whatever an axis's `anchor`: a span only has to\n// reach past the edge.\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 * Emits every line position in `[min, max]` (grown by `overscan`) for spacing\n * `step`, panned by `offset`. The line at tile index `n`, counted from `anchor`,\n * is major when `n` is a multiple of `subdivisions`; `n` is relative to the\n * un-panned lattice, so classification stays stable as the grid scrolls.\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]. 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 const isMajor = ((n % subdivisions) + subdivisions) % subdivisions === 0;\n emit(pos, isMajor);\n }\n}\n\n/** Largest layer weight, to 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/** Every layer centred: grid lines are open paths, so inside/outside alignment means nothing. Makes explicit what the renderer does and ignores any author `align`. */\nexport function centered(strokes: StrokeResolved[]): StrokeResolved[] {\n return strokes.map(s => (s.align === 0 ? s : { ...s, align: 0 }));\n}\n\n/** The default minor-line stroke is the major one with every fill's opacity scaled by `factor`. */\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 given, a binding read once. */\nfunction valueOf(prop: unknown): unknown {\n return typeof prop === \"function\" ? (prop as () => unknown)() : prop;\n}\n", "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 pattern filling the camera's visible region shares: spread `state` and\n * `commands` in, pass `measure` and `layout`, and draw with {@link draw}. Inside a\n * `Camera` the pattern is handed the world region it can see, so it only generates\n * geometry for what is on screen; with none it fills its own box. It is laid out at\n * the camera's centre, so its draw space shares the world origin its siblings use.\n * A pattern is a shape: paints, and children laid out like a rect's.\n */\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/** The world rect the nearest `Camera` sees, in the pattern's draw space, else its own box. */\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 const hw = vw / 2 / zoom;\n const hh = vh / 2 / zoom;\n\n // With a heading the visible rect is rotated; its axis-aligned bounding box covers the 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.\n const lookAt = camera.state.lookAt;\n return { x: lookAt.x, y: lookAt.y, width: bw * 2, height: bh * 2 };\n}\n\n/**\n * Paints `pattern` over the visible region, then the children. Clipped to the\n * region so overscanned geometry trims cleanly even with no camera. A path drawn\n * here takes `centerBounds` of `[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"],
|
|
5
|
+
"mappings": "0FAAA,OAAS,aAAAA,MAAsF,oBAuCzF,SAAUC,EACZC,EACAC,EACAC,EACAC,EACAC,EAAQ,EAAC,CAET,IAAMC,EAA0B,CAAA,EA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"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 T,b as k,c as V,d as w,e as x,f as nt,g as P,h as g}from"./chunks/chunk-DRFXMB3M.js";import{Flow as z,Graphics2D as v,Paint as M,Types as W,component2d as _,lerpVector2 as q}from"@motionscript/sdk";var X=_({key:"lineGridPattern",state:{...M.state,...z.state,divisions:4,subdivisions:1,subStroke:W.stroke,offset:W.custom({x:0,y:0},{lerp:q})},defaults:{subStroke:(o,t)=>P(t)},commands:{...M.commands},measure:(o,t,e)=>z.measure(o,t,e,M.inset(t)),layout:(o,t,e)=>z.layout(o,t,e,M.inset(t)),render:(o,t)=>{let{width:e,height:r}=o.size,i=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)),s=Math.max(1,Math.floor(t.subdivisions)),l=x(t.stroke),f=x(t.subStroke),n=Math.max(w(l),w(f))/2,a=A(e,r,c,s,n,t.offset),m=[-e/2,-r/2,e/2,r/2];o.clip(i,()=>{s>1&&f.length>0&&a.minor.length>0&&o.draw(new v().path({data:a.minor,centerBounds:m}).stroke(f)),a.major.length>0&&o.draw(new v().path({data:a.major,centerBounds:m}).stroke(l))})}),M.draw(o,t,null,{clipShape:i})}});function A(o,t,e,r,i,c){let s=e*r,l=Math.max(0,o-2*i),f=Math.max(0,t-2*i),n=o/2-i,a=t/2-i;return k({min:-n,max:n,step:l/s,offset:c.x,anchor:-n},{min:-a,max:a,step:f/s,offset:c.y,anchor:-a},r,i)}import{Flow as j,Graphics2D as F,Paint as S,Types as I,component2d as J,lerpVector2 as K}from"@motionscript/sdk";function Y(o,t,e,r,i,c){let s=[];return V(o,t,e,r,i,c,(l,f)=>{s.push({pos:l,isMajor:f})},o),s}var Q={...S.state,...j.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:{...S.commands},measure:(o,t,e)=>j.measure(o,t,e,S.inset(t)),layout:(o,t,e)=>j.layout(o,t,e,S.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});S.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 i=Math.max(1,Math.floor(t.divisions)),c=Math.max(1,Math.floor(t.subdivisions)),s=Math.max(0,t.radius),l=s*Math.max(0,t.subScale);if(s<=0&&l<=0)return null;let f=i*c,n=Math.max(0,e/2-s),a=Math.max(0,r/2-s),m=Y(-n,n,n*2/f,t.offset.x,c,s),d=Y(-a,a,a*2/f,t.offset.y,c,s),h=new F,b=!1;for(let p of m)for(let u of d){let y=p.isMajor&&u.isMajor?s:l;y<=0||(h.ellipse({x:p.pos,y:u.pos,width:y*2,height:y*2}),b=!0)}return b?h:null}import{Graphics2D as G,Types as L,component2d as U,lerpNumber as Z,lerpVector2 as E}from"@motionscript/sdk";var H=U({key:"gridPattern",state:{...g.state,cellSize:L.custom(100,{lerp:ot}),subdivisions:1,subStroke:L.stroke,offset:L.custom({x:0,y:0},{lerp:E})},defaults:{subStroke:(o,t)=>P(t)},commands:{...g.commands},measure:g.measure,layout:g.layout,render:(o,t)=>g.draw(o,e=>$(o,t,e))});function $(o,t,e){let r=e.width/2,i=e.height/2,c=e.x-r,s=e.x+r,l=e.y-i,f=e.y+i;o.draw(new G().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 n=Math.max(1,Math.floor(t.subdivisions)),a=t.cellSize,m=Math.max(.001,typeof a=="number"?a:a.x),d=Math.max(.001,typeof a=="number"?a:a.y),h=m/n,b=d/n,p=x(t.stroke),u=x(t.subStroke),y=Math.max(w(p),w(u))/2,D={min:c,max:s,step:h,offset:t.offset.x},O={min:l,max:f,step:b,offset:t.offset.y};n>1&&u.length>0&&B(o,D,O,n,y,u,!1),p.length>0&&B(o,D,O,n,y,p,!0)}function B(o,t,e,r,i,c,s){let l=[-1,-1,1,1],f=tt(c);if(f<=0){let d=k(t,e,r,i)[s?"major":"minor"];d.length>0&&o.draw(new G().path({data:d,centerBounds:l}).stroke(c));return}let n=T(t,e,r,i,f),a=s?n.verticalMajor:n.verticalMinor,m=s?n.horizontalMajor:n.horizontalMinor;for(let d of a){let h=[{type:"M",x:d,y:n.top},{type:"L",x:d,y:n.bottom}];o.draw(new G().path({data:h,centerBounds:l}).stroke(C(c,n.top)))}for(let d of m){let h=[{type:"M",x:n.left,y:d},{type:"L",x:n.right,y:d}];o.draw(new G().path({data:h,centerBounds:l}).stroke(C(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((i,c)=>i+c,0);r>t&&(t=r)}return t}function C(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):E(typeof o=="number"?{x:o,y:o}:o,typeof t=="number"?{x:t,y:t}:t,e)}var et=[X,N,H];export{N as DotGridPattern,H as GridPattern,X as LineGridPattern,et as NODES,g as ViewportPattern,V as addTiledLines,x as centered,P as defaultSubStroke,nt as dimStroke,k as gridLinePaths,T as gridLines,w 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 {\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", "import {\n Flow,\n Graphics2D,\n Paint,\n Types,\n component2d,\n lerpVector2,\n type NodeOf,\n type Size2D,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Alignment as _Alignment,\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type FlowMode as _FlowMode,\n type FlowResolved as _FlowResolved,\n type GapSize as _GapSize,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n} from \"@motionscript/sdk\"\n\nimport { addTiledLines } from \"../kit\"\n\n/** One mark's place on an axis, and whether it lands on the coarse grid. */\ninterface GridPosition {\n pos: number\n isMajor: boolean\n}\n\n// Calls the tiling `LineGridPattern` uses, so dots stay on its intersections at every offset.\nfunction gridPositions(\n min: number,\n max: number,\n step: number,\n offset: number,\n subdivisions: number,\n overscan: number\n): GridPosition[] {\n const out: GridPosition[] = []\n // Anchored at the near edge, so a column or row sits on each edge of the box for any count of cells.\n addTiledLines(min, max, step, offset, subdivisions, overscan, (pos, isMajor) => {\n out.push({ pos, isMajor })\n }, min)\n return out\n}\n\nconst state = {\n ...Paint.state,\n ...Flow.state,\n /** Cells along each axis, as in `LineGridPattern.divisions`: 4 puts 5 major dots on each axis. */\n divisions: 4,\n /** Splits each division again. `1` draws only the major dots; `2` puts one minor dot between each pair. */\n subdivisions: 1,\n /** Radius of a major dot. */\n radius: 3,\n /**\n * A minor dot's radius as a fraction of a major one's. A fraction rather than a\n * second paint stack, so the whole field stays one fill and a gradient crosses\n * every dot in it.\n */\n subScale: 0.5,\n /** Pans the field, as `LineGridPattern.offset` does, so the two stay aligned while both scroll. */\n offset: Types.custom<Vector2>({ x: 0, y: 0 }, { lerp: lerpVector2 }),\n}\n\ninterface DotField {\n readonly divisions: number\n readonly subdivisions: number\n readonly radius: number\n readonly subScale: number\n readonly offset: Vector2\n}\n\n/**\n * A field of dots on the same `divisions` / `subdivisions` / `offset` as\n * `LineGridPattern`, so laid over one the dots sit on its intersections.\n *\n * The silhouette is the dots, which `Paint.draw` paints with `shadow`, `fill`,\n * `overlay` and `stroke`. A dot grid has no \"paper\": a rectangle behind it is how\n * it gets a background.\n *\n * What `clip` confines the children to, and what picking tests, is the node's\n * box rather than the silhouette, which clips outer dots as they pan out and\n * keeps the node selectable between dots. `start` / `end` act on nothing:\n * trimming a disc leaves a crescent, not a partial grid.\n */\nexport const DotGridPattern = component2d({\n key: \"dotGridPattern\",\n state,\n commands: { ...Paint.commands },\n measure: (measurer, state, children) => Flow.measure(measurer, state, children, Paint.inset(state)),\n layout: (box, state, children) => Flow.layout(box, state, children, Paint.inset(state)),\n render: (ctx, state) => {\n const untrimmed = {\n fill: state.fill, stroke: state.stroke, shadow: state.shadow, overlay: state.overlay, start: 0, end: 1, clip: state.clip,\n }\n const box = new Graphics2D().rect({ width: ctx.size.width, height: ctx.size.height })\n Paint.draw(ctx, untrimmed, dots(ctx.size, state), { clipShape: box })\n },\n})\n\nexport type DotGridPattern = NodeOf<typeof DotGridPattern>\n/** What a call or a document row may set. */\nexport type DotGridPatternProps = NonNullable<Parameters<typeof DotGridPattern>[0]>\n\n/** Every dot in the field as one un-painted union: the paint stacks belong to the grid, not to a dot. */\nfunction dots(size: Size2D, s: DotField): Graphics2D | null {\n const { width, height } = size\n if (width <= 0 || height <= 0) return null\n\n const divisions = Math.max(1, Math.floor(s.divisions))\n const subdivisions = Math.max(1, Math.floor(s.subdivisions))\n const major = Math.max(0, s.radius)\n const minor = major * Math.max(0, s.subScale)\n if (major <= 0 && minor <= 0) return null\n\n // Inset by a dot's radius so an edge dot sits inside the box rather than being halved by the clip.\n const cols = divisions * subdivisions\n const insetX = Math.max(0, width / 2 - major)\n const insetY = Math.max(0, height / 2 - major)\n const xs = gridPositions(\n -insetX,\n insetX,\n (insetX * 2) / cols,\n s.offset.x,\n subdivisions,\n major\n )\n const ys = gridPositions(\n -insetY,\n insetY,\n (insetY * 2) / cols,\n s.offset.y,\n subdivisions,\n major\n )\n\n const field = new Graphics2D()\n let drew = false\n for (const column of xs) {\n for (const row of ys) {\n // A dot is major only where *both* axes are — an intersection of two\n // major rules, which is exactly the point a line grid draws heaviest.\n const size = column.isMajor && row.isMajor ? major : minor\n if (size <= 0) continue\n field.ellipse({ x: column.pos, y: row.pos, width: size * 2, height: size * 2 })\n drew = true\n }\n }\n return drew ? field : null\n}\n", "import {\n Graphics2D,\n Types,\n component2d,\n lerpNumber,\n lerpVector2,\n type BoxBounds,\n type NodeOf,\n type PathCommand,\n type RenderContext,\n type ShadowResolved,\n type FillResolved,\n type StrokeResolved,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Alignment as _Alignment,\n type Fill as _Fill,\n type FlowMode as _FlowMode,\n type FlowResolved as _FlowResolved,\n type GapSize as _GapSize,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type Stroke as _Stroke,\n} from \"@motionscript/sdk\";\n\nimport { centered, defaultSubStroke, gridLines, maxWeight, ViewportPattern, type GridAxis } from \"../kit\";\n\n/**\n * An infinite line grid that fills the camera's visible region. Like\n * `LineGridPattern` it draws major and minor strokes over a fill and pans\n * with `offset`, but it tiles a world-anchored grid (spacing `cellSize`) across\n * what the nearest `Camera` above it can see, regenerated each frame. With no\n * camera it fills its own layout rect.\n */\nexport const GridPattern = component2d({\n key: \"gridPattern\",\n state: {\n ...ViewportPattern.state,\n /** Spacing between grid lines in world units: one number for both axes, or `{ x, y }`. */\n cellSize: Types.custom<number | Vector2>(100, { lerp: lerpCellSize }),\n /** Finer cells each cell is split into, as in `LineGridPattern.subdivisions`. */\n subdivisions: 1,\n /** Stroke for the minor lines. Unset, the major `stroke` at half opacity when `subdivisions > 1`. */\n subStroke: Types.stroke,\n /** Scrolls the pattern relative to the world, which it is otherwise anchored to. */\n offset: Types.custom<Vector2>({ x: 0, y: 0 }, { lerp: lerpVector2 }),\n },\n defaults: { subStroke: (_state, given) => defaultSubStroke(given) },\n commands: { ...ViewportPattern.commands },\n measure: ViewportPattern.measure,\n layout: ViewportPattern.layout,\n render: (ctx, state) => ViewportPattern.draw(ctx, (bounds) => drawGrid(ctx, state, bounds)),\n});\n\nexport type GridPattern = NodeOf<typeof GridPattern>;\n/** What a call or a document row may set. */\nexport type GridPatternProps = NonNullable<Parameters<typeof GridPattern>[0]>;\n\ninterface GridState {\n readonly fill: FillResolved[];\n readonly stroke: StrokeResolved[];\n readonly shadow: ShadowResolved[];\n readonly start: number;\n readonly end: number;\n readonly cellSize: number | Vector2;\n readonly subdivisions: number;\n readonly subStroke: StrokeResolved[];\n readonly offset: Vector2;\n}\n\nfunction drawGrid(ctx: RenderContext, s: GridState, bounds: BoxBounds): void {\n const halfW = bounds.width / 2;\n const halfH = bounds.height / 2;\n // `bounds` is centred on (x, y) in y-up world space: descriptor coordinates are y-up\n // and the renderer applies the single flip.\n const left = bounds.x - halfW;\n const right = bounds.x + halfW;\n const top = bounds.y - halfH;\n const bottom = bounds.y + halfH;\n\n ctx.draw(new Graphics2D()\n .rect({ x: bounds.x, y: bounds.y, width: bounds.width, height: bounds.height, start: s.start, end: s.end })\n .shadow(s.shadow)\n .fill(s.fill));\n\n const subdivisions = Math.max(1, Math.floor(s.subdivisions));\n const cell = s.cellSize;\n const cellX = Math.max(1e-3, typeof cell === \"number\" ? cell : cell.x);\n const cellY = Math.max(1e-3, typeof cell === \"number\" ? cell : cell.y);\n const stepX = cellX / subdivisions;\n const stepY = cellY / subdivisions;\n\n const major = centered(s.stroke);\n const minorStroke = centered(s.subStroke);\n const overscan = Math.max(maxWeight(major), maxWeight(minorStroke)) / 2;\n\n const xAxis: GridAxis = { min: left, max: right, step: stepX, offset: s.offset.x };\n const yAxis: GridAxis = { min: top, max: bottom, step: stepY, offset: s.offset.y };\n\n // Minor lines first so the major lines sit on top.\n if (subdivisions > 1 && minorStroke.length > 0) {\n drawGroup(ctx, xAxis, yAxis, subdivisions, overscan, minorStroke, false);\n }\n if (major.length > 0) {\n drawGroup(ctx, xAxis, yAxis, subdivisions, overscan, major, true);\n }\n}\n\n// A solid stroke paints the group as one union path. A dashed one draws each line on\n// its own with its dash phase anchored to the line's world coordinate, so dashes never\n// crawl as the camera pans or new lines scroll in.\nfunction drawGroup(\n ctx: RenderContext,\n xAxis: GridAxis,\n yAxis: GridAxis,\n subdivisions: number,\n overscan: number,\n stroke: StrokeResolved[],\n isMajor: boolean,\n): void {\n // Each line spans a whole number of dash cycles, so the renderer's per-path dash-fit\n // is a no-op and every line dashes identically.\n const cycle = dashCycle(stroke);\n const g = gridLines(xAxis, yAxis, subdivisions, overscan, cycle);\n const verticals = isMajor ? g.verticalMajor : g.verticalMinor;\n const horizontals = isMajor ? g.horizontalMajor : g.horizontalMinor;\n\n // Symmetric centerBounds give a zero recentre offset, so local coordinates draw verbatim.\n const centerBounds = [-1, -1, 1, 1] as const;\n\n if (cycle <= 0) {\n const data: PathCommand[] = [];\n for (const px of verticals) data.push({ type: \"M\", x: px, y: g.top }, { type: \"L\", x: px, y: g.bottom });\n for (const py of horizontals) data.push({ type: \"M\", x: g.left, y: py }, { type: \"L\", x: g.right, y: py });\n if (data.length > 0) ctx.draw(new Graphics2D().path({ data, centerBounds }).stroke(stroke));\n return;\n }\n\n for (const px of verticals) {\n const data: PathCommand[] = [{ type: \"M\", x: px, y: g.top }, { type: \"L\", x: px, y: g.bottom }];\n ctx.draw(new Graphics2D().path({ data, centerBounds }).stroke(phaseShift(stroke, g.top)));\n }\n for (const py of horizontals) {\n const data: PathCommand[] = [{ type: \"M\", x: g.left, y: py }, { type: \"L\", x: g.right, y: py }];\n ctx.draw(new Graphics2D().path({ data, centerBounds }).stroke(phaseShift(stroke, g.left)));\n }\n}\n\n// The largest dash-array sum across the layers, or 0 when none is dashed.\nfunction dashCycle(strokes: StrokeResolved[]): number {\n let cycle = 0;\n for (const s of strokes) {\n if (s.dash && s.dash.length > 0) {\n const sum = s.dash.reduce((a, b) => a + b, 0);\n if (sum > cycle) cycle = sum;\n }\n }\n return cycle;\n}\n\n// `dashOffset` advances the pattern, so it is negated to put the \"on\" run at the phase one\n// infinite line would have at this world coordinate.\nfunction phaseShift(strokes: StrokeResolved[], worldStart: number): StrokeResolved[] {\n return strokes.map(s => (s.dash && s.dash.length > 0)\n ? { ...s, dashOffset: (s.dashOffset ?? 0) - worldStart }\n : s);\n}\n\n// A number and a vector tween by promoting the number to a uniform vector.\nfunction lerpCellSize(from: number | Vector2, to: number | Vector2, t: number): number | Vector2 {\n if (typeof from === \"number\" && typeof to === \"number\") return lerpNumber(from, to, t);\n const a = typeof from === \"number\" ? { x: from, y: from } : from;\n const b = typeof to === \"number\" ? { x: to, y: to } : to;\n return lerpVector2(a, b, t);\n}\n", "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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AcD,EAASV,EAAM,SAAS,EACtCY,EAAW,KAAK,IAAIC,EAAUJ,CAAK,EAAGI,EAAUF,CAAW,CAAC,EAAI,EAChEG,EAAQC,EAAUX,EAAOC,EAAQE,EAAWC,EAAcI,EAAUZ,EAAM,MAAM,EAChFgB,EAA2B,CAAC,CAACZ,EAAQ,EAAG,CAACC,EAAS,EAAGD,EAAQ,EAAGC,EAAS,CAAC,EAEhFF,EAAI,KAAKD,EAAK,IAAK,CAEXM,EAAe,GAAKG,EAAY,OAAS,GAAKG,EAAM,MAAM,OAAS,GACnEX,EAAI,KAAK,IAAIG,EAAU,EAAG,KAAK,CAAE,KAAMQ,EAAM,MAAO,aAAAE,CAAY,CAAE,EAAE,OAAOL,CAAW,CAAC,EAEvFG,EAAM,MAAM,OAAS,GACrBX,EAAI,KAAK,IAAIG,EAAU,EAAG,KAAK,CAAE,KAAMQ,EAAM,MAAO,aAAAE,CAAY,CAAE,EAAE,OAAOP,CAAK,CAAC,CAEzF,CAAC,CACL,CAAC,EAEDjB,EAAM,KAAKW,EAAKH,EAAO,KAAM,CAAE,UAAWE,CAAG,CAAE,CACnD,EACH,
|
|
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", "
|
|
4
|
+
"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\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", "import {\n Flow,\n Graphics2D,\n Paint,\n Types,\n component2d,\n lerpVector2,\n type NodeOf,\n type Size2D,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Alignment as _Alignment,\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type FlowMode as _FlowMode,\n type FlowResolved as _FlowResolved,\n type GapSize as _GapSize,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n} from \"@motionscript/sdk\"\n\nimport { addTiledLines } from \"../kit\"\n\n// The tiling `LineGridPattern` uses, so dots stay on its intersections at every offset.\nfunction gridPositions(\n min: number,\n max: number,\n step: number,\n offset: number,\n subdivisions: number,\n overscan: number\n): { pos: number; isMajor: boolean }[] {\n const out: { pos: number; isMajor: boolean }[] = []\n // Anchored at the near edge, so a column or row sits on each edge of the box for any cell count.\n addTiledLines(min, max, step, offset, subdivisions, overscan, (pos, isMajor) => {\n out.push({ pos, isMajor })\n }, min)\n return out\n}\n\nconst state = {\n ...Paint.state,\n ...Flow.state,\n /** Cells along each axis, as in `LineGridPattern.divisions`: 4 puts 5 major dots on each. */\n divisions: 4,\n /** `1` draws only the major dots; `2` puts one minor dot between each pair. */\n subdivisions: 1,\n /** Radius of a major dot. */\n radius: 3,\n /** A minor dot's radius as a fraction of a major one's, not a second paint stack, so a gradient crosses every dot. */\n subScale: 0.5,\n /** As `LineGridPattern.offset`, so the two stay aligned while both scroll. */\n offset: Types.custom<Vector2>({ x: 0, y: 0 }, { lerp: lerpVector2 }),\n}\n\ninterface DotField {\n readonly divisions: number\n readonly subdivisions: number\n readonly radius: number\n readonly subScale: number\n readonly offset: Vector2\n}\n\n/**\n * A field of dots on the same `divisions` / `subdivisions` / `offset` as\n * `LineGridPattern`, so laid over one the dots sit on its intersections. The\n * dots are the silhouette `Paint.draw` paints; a background is a rectangle behind\n * it. `clip` and picking use the node's box, not the silhouette, so outer dots\n * clip as they pan out and the node stays selectable between dots. `start` and\n * `end` act on nothing: trimming a disc leaves a crescent, not a partial grid.\n */\nexport const DotGridPattern = component2d({\n key: \"dotGridPattern\",\n state,\n commands: { ...Paint.commands },\n measure: (measurer, state, children) => Flow.measure(measurer, state, children, Paint.inset(state)),\n layout: (box, state, children) => Flow.layout(box, state, children, Paint.inset(state)),\n render: (ctx, state) => {\n const untrimmed = {\n fill: state.fill, stroke: state.stroke, shadow: state.shadow, overlay: state.overlay, start: 0, end: 1, clip: state.clip,\n }\n const box = new Graphics2D().rect({ width: ctx.size.width, height: ctx.size.height })\n Paint.draw(ctx, untrimmed, dots(ctx.size, state), { clipShape: box })\n },\n})\n\nexport type DotGridPattern = NodeOf<typeof DotGridPattern>\n\n/** Every dot as one un-painted union: the paint stacks belong to the grid, not a dot. */\nfunction dots(size: Size2D, s: DotField): Graphics2D | null {\n const { width, height } = size\n if (width <= 0 || height <= 0) return null\n\n const divisions = Math.max(1, Math.floor(s.divisions))\n const subdivisions = Math.max(1, Math.floor(s.subdivisions))\n const major = Math.max(0, s.radius)\n const minor = major * Math.max(0, s.subScale)\n if (major <= 0 && minor <= 0) return null\n\n // Inset by a dot's radius so an edge dot sits inside the box rather than being halved by the clip.\n const cols = divisions * subdivisions\n const insetX = Math.max(0, width / 2 - major)\n const insetY = Math.max(0, height / 2 - major)\n const xs = gridPositions(\n -insetX,\n insetX,\n (insetX * 2) / cols,\n s.offset.x,\n subdivisions,\n major\n )\n const ys = gridPositions(\n -insetY,\n insetY,\n (insetY * 2) / cols,\n s.offset.y,\n subdivisions,\n major\n )\n\n const field = new Graphics2D()\n let drew = false\n for (const column of xs) {\n for (const row of ys) {\n // Major only where both axes are: an intersection of two major rules.\n const size = column.isMajor && row.isMajor ? major : minor\n if (size <= 0) continue\n field.ellipse({ x: column.pos, y: row.pos, width: size * 2, height: size * 2 })\n drew = true\n }\n }\n return drew ? field : null\n}\n", "import {\n Graphics2D,\n Types,\n component2d,\n lerpNumber,\n lerpVector2,\n type BoxBounds,\n type NodeOf,\n type PathCommand,\n type RenderContext,\n type ShadowResolved,\n type FillResolved,\n type StrokeResolved,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Alignment as _Alignment,\n type Fill as _Fill,\n type FlowMode as _FlowMode,\n type FlowResolved as _FlowResolved,\n type GapSize as _GapSize,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type Stroke as _Stroke,\n} from \"@motionscript/sdk\";\n\nimport { centered, defaultSubStroke, gridLinePaths, gridLines, maxWeight, ViewportPattern, type GridAxis } from \"../kit\";\n\n/**\n * An infinite line grid that fills the camera's visible region: like\n * `LineGridPattern`, but it tiles a world-anchored grid (spacing `cellSize`)\n * across what the nearest `Camera` sees, regenerated each frame. With no camera it\n * fills its own layout rect.\n */\nexport const GridPattern = component2d({\n key: \"gridPattern\",\n state: {\n ...ViewportPattern.state,\n /** Spacing between grid lines in world units: one number for both axes, or `{ x, y }`. */\n cellSize: Types.custom<number | Vector2>(100, { lerp: lerpCellSize }),\n /** Finer cells each cell is split into, as in `LineGridPattern.subdivisions`. */\n subdivisions: 1,\n /** Stroke for the minor lines. Unset, the major `stroke` at half opacity when `subdivisions > 1`. */\n subStroke: Types.stroke,\n /** Scrolls the pattern relative to the world, which it is otherwise anchored to. */\n offset: Types.custom<Vector2>({ x: 0, y: 0 }, { lerp: lerpVector2 }),\n },\n defaults: { subStroke: (_state, given) => defaultSubStroke(given) },\n commands: { ...ViewportPattern.commands },\n measure: ViewportPattern.measure,\n layout: ViewportPattern.layout,\n render: (ctx, state) => ViewportPattern.draw(ctx, (bounds) => drawGrid(ctx, state, bounds)),\n});\n\nexport type GridPattern = NodeOf<typeof GridPattern>;\n\ninterface GridState {\n readonly fill: FillResolved[];\n readonly stroke: StrokeResolved[];\n readonly shadow: ShadowResolved[];\n readonly start: number;\n readonly end: number;\n readonly cellSize: number | Vector2;\n readonly subdivisions: number;\n readonly subStroke: StrokeResolved[];\n readonly offset: Vector2;\n}\n\nfunction drawGrid(ctx: RenderContext, s: GridState, bounds: BoxBounds): void {\n const halfW = bounds.width / 2;\n const halfH = bounds.height / 2;\n // `bounds` is centred on (x, y) in y-up world space.\n const left = bounds.x - halfW;\n const right = bounds.x + halfW;\n const top = bounds.y - halfH;\n const bottom = bounds.y + halfH;\n\n ctx.draw(new Graphics2D()\n .rect({ x: bounds.x, y: bounds.y, width: bounds.width, height: bounds.height, start: s.start, end: s.end })\n .shadow(s.shadow)\n .fill(s.fill));\n\n const subdivisions = Math.max(1, Math.floor(s.subdivisions));\n const cell = s.cellSize;\n const cellX = Math.max(1e-3, typeof cell === \"number\" ? cell : cell.x);\n const cellY = Math.max(1e-3, typeof cell === \"number\" ? cell : cell.y);\n const stepX = cellX / subdivisions;\n const stepY = cellY / subdivisions;\n\n const major = centered(s.stroke);\n const minorStroke = centered(s.subStroke);\n const overscan = Math.max(maxWeight(major), maxWeight(minorStroke)) / 2;\n\n const xAxis: GridAxis = { min: left, max: right, step: stepX, offset: s.offset.x };\n const yAxis: GridAxis = { min: top, max: bottom, step: stepY, offset: s.offset.y };\n\n // Minor lines first so the major lines sit on top.\n if (subdivisions > 1 && minorStroke.length > 0) {\n drawGroup(ctx, xAxis, yAxis, subdivisions, overscan, minorStroke, false);\n }\n if (major.length > 0) {\n drawGroup(ctx, xAxis, yAxis, subdivisions, overscan, major, true);\n }\n}\n\n// A solid stroke paints the group as one union path. A dashed one draws each line on its\n// own, dash phase anchored to its world coordinate, so dashes never crawl as the camera pans.\nfunction drawGroup(\n ctx: RenderContext,\n xAxis: GridAxis,\n yAxis: GridAxis,\n subdivisions: number,\n overscan: number,\n stroke: StrokeResolved[],\n isMajor: boolean,\n): void {\n // Symmetric centerBounds give a zero recentre offset, so local coordinates draw verbatim.\n const centerBounds = [-1, -1, 1, 1] as const;\n\n const cycle = dashCycle(stroke);\n if (cycle <= 0) {\n const data = gridLinePaths(xAxis, yAxis, subdivisions, overscan)[isMajor ? \"major\" : \"minor\"];\n if (data.length > 0) ctx.draw(new Graphics2D().path({ data, centerBounds }).stroke(stroke));\n return;\n }\n\n // Each line spans a whole number of dash cycles, so the renderer's per-path dash-fit\n // is a no-op and every line dashes identically.\n const g = gridLines(xAxis, yAxis, subdivisions, overscan, cycle);\n const verticals = isMajor ? g.verticalMajor : g.verticalMinor;\n const horizontals = isMajor ? g.horizontalMajor : g.horizontalMinor;\n\n for (const px of verticals) {\n const data: PathCommand[] = [{ type: \"M\", x: px, y: g.top }, { type: \"L\", x: px, y: g.bottom }];\n ctx.draw(new Graphics2D().path({ data, centerBounds }).stroke(phaseShift(stroke, g.top)));\n }\n for (const py of horizontals) {\n const data: PathCommand[] = [{ type: \"M\", x: g.left, y: py }, { type: \"L\", x: g.right, y: py }];\n ctx.draw(new Graphics2D().path({ data, centerBounds }).stroke(phaseShift(stroke, g.left)));\n }\n}\n\n// The largest dash-array sum across the layers, or 0 when none is dashed.\nfunction dashCycle(strokes: StrokeResolved[]): number {\n let cycle = 0;\n for (const s of strokes) {\n if (s.dash && s.dash.length > 0) {\n const sum = s.dash.reduce((a, b) => a + b, 0);\n if (sum > cycle) cycle = sum;\n }\n }\n return cycle;\n}\n\n// `dashOffset` advances the pattern, so it is negated to give the phase one infinite line would have at this world coordinate.\nfunction phaseShift(strokes: StrokeResolved[], worldStart: number): StrokeResolved[] {\n return strokes.map(s => (s.dash && s.dash.length > 0)\n ? { ...s, dashOffset: (s.dashOffset ?? 0) - worldStart }\n : s);\n}\n\n// A number and a vector tween by promoting the number to a uniform vector.\nfunction lerpCellSize(from: number | Vector2, to: number | Vector2, t: number): number | Vector2 {\n if (typeof from === \"number\" && typeof to === \"number\") return lerpNumber(from, to, t);\n const a = typeof from === \"number\" ? { x: from, y: from } : from;\n const b = typeof to === \"number\" ? { x: to, y: to } : to;\n return lerpVector2(a, b, t);\n}\n", "import { DotGridPattern } from \"./dot-grid-pattern\"\nimport { GridPattern } from \"./grid-pattern\"\nimport { LineGridPattern } from \"./line-grid-pattern\"\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"],
|
|
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,EAAQC,IAAUC,EAAiBD,CAAK,CAAC,EACjE,SAAU,CAAE,GAAGL,EAAM,QAAQ,EAC7B,QAAS,CAACO,EAAUC,EAAOC,IAAaR,EAAK,QAAQM,EAAUC,EAAOC,EAAUT,EAAM,MAAMQ,CAAK,CAAC,EAClG,OAAQ,CAACE,EAAKF,EAAOC,IAAaR,EAAK,OAAOS,EAAKF,EAAOC,EAAUT,EAAM,MAAMQ,CAAK,CAAC,EACtF,OAAQ,CAACG,EAAKH,IAAS,CACnB,GAAM,CAAE,MAAAI,EAAO,OAAAC,CAAM,EAAKF,EAAI,KACxBD,EAAM,IAAII,EAAU,EAAG,KAAK,CAAE,MAAAF,EAAO,OAAAC,CAAM,CAAE,EACnDF,EAAI,QAAQ,IAAK,CACbA,EAAI,KAAK,IAAIG,EAAU,EAClB,KAAK,CAAE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AAKA,EAClD,OAAOC,GAAO,SAAW,CAAE,EAAGA,EAAI,EAAGA,CAAE,EAAKA,EAC7BC,CAAC,CAC9B,CC7JO,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", "centerBounds", "cycle", "dashCycle", "data", "gridLinePaths", "g", "gridLines", "verticals", "horizontals", "px", "phaseShift", "py", "strokes", "sum", "a", "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,h}from"./chunks/chunk-
|
|
1
|
+
import{a,b,c,d,e,f,g,h}from"./chunks/chunk-DRFXMB3M.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,31 +1,22 @@
|
|
|
1
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
2
|
/**
|
|
3
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
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
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.
|
|
4
|
+
* `LineGridPattern`, so laid over one the dots sit on its intersections. The
|
|
5
|
+
* dots are the silhouette `Paint.draw` paints; a background is a rectangle behind
|
|
6
|
+
* it. `clip` and picking use the node's box, not the silhouette, so outer dots
|
|
7
|
+
* clip as they pan out and the node stays selectable between dots. `start` and
|
|
8
|
+
* `end` act on nothing: trimming a disc leaves a crescent, not a partial grid.
|
|
14
9
|
*/
|
|
15
10
|
export declare const DotGridPattern: import("@motionscript/sdk").Component<"dotGridPattern", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
16
|
-
/** Cells along each axis, as in `LineGridPattern.divisions`: 4 puts 5 major dots on each
|
|
11
|
+
/** Cells along each axis, as in `LineGridPattern.divisions`: 4 puts 5 major dots on each. */
|
|
17
12
|
divisions: number;
|
|
18
|
-
/**
|
|
13
|
+
/** `1` draws only the major dots; `2` puts one minor dot between each pair. */
|
|
19
14
|
subdivisions: number;
|
|
20
15
|
/** Radius of a major dot. */
|
|
21
16
|
radius: number;
|
|
22
|
-
/**
|
|
23
|
-
* A minor dot's radius as a fraction of a major one's. A fraction rather than a
|
|
24
|
-
* second paint stack, so the whole field stays one fill and a gradient crosses
|
|
25
|
-
* every dot in it.
|
|
26
|
-
*/
|
|
17
|
+
/** A minor dot's radius as a fraction of a major one's, not a second paint stack, so a gradient crosses every dot. */
|
|
27
18
|
subScale: number;
|
|
28
|
-
/**
|
|
19
|
+
/** As `LineGridPattern.offset`, so the two stay aligned while both scroll. */
|
|
29
20
|
offset: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
|
|
30
21
|
flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
|
|
31
22
|
gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
|
|
@@ -49,19 +40,15 @@ export declare const DotGridPattern: import("@motionscript/sdk").Component<"dotG
|
|
|
49
40
|
readonly portion: import("@motionscript/sdk").Type<number, number, false>;
|
|
50
41
|
};
|
|
51
42
|
}, 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
|
|
43
|
+
/** Cells along each axis, as in `LineGridPattern.divisions`: 4 puts 5 major dots on each. */
|
|
53
44
|
divisions: number;
|
|
54
|
-
/**
|
|
45
|
+
/** `1` draws only the major dots; `2` puts one minor dot between each pair. */
|
|
55
46
|
subdivisions: number;
|
|
56
47
|
/** Radius of a major dot. */
|
|
57
48
|
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
|
-
*/
|
|
49
|
+
/** A minor dot's radius as a fraction of a major one's, not a second paint stack, so a gradient crosses every dot. */
|
|
63
50
|
subScale: number;
|
|
64
|
-
/**
|
|
51
|
+
/** As `LineGridPattern.offset`, so the two stay aligned while both scroll. */
|
|
65
52
|
offset: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
|
|
66
53
|
flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
|
|
67
54
|
gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
|
|
@@ -76,19 +63,15 @@ export declare const DotGridPattern: import("@motionscript/sdk").Component<"dotG
|
|
|
76
63
|
start: import("@motionscript/sdk").Type<number, number, false>;
|
|
77
64
|
end: import("@motionscript/sdk").Type<number, number, false>;
|
|
78
65
|
}>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
79
|
-
/** Cells along each axis, as in `LineGridPattern.divisions`: 4 puts 5 major dots on each
|
|
66
|
+
/** Cells along each axis, as in `LineGridPattern.divisions`: 4 puts 5 major dots on each. */
|
|
80
67
|
divisions: number;
|
|
81
|
-
/**
|
|
68
|
+
/** `1` draws only the major dots; `2` puts one minor dot between each pair. */
|
|
82
69
|
subdivisions: number;
|
|
83
70
|
/** Radius of a major dot. */
|
|
84
71
|
radius: number;
|
|
85
|
-
/**
|
|
86
|
-
* A minor dot's radius as a fraction of a major one's. A fraction rather than a
|
|
87
|
-
* second paint stack, so the whole field stays one fill and a gradient crosses
|
|
88
|
-
* every dot in it.
|
|
89
|
-
*/
|
|
72
|
+
/** A minor dot's radius as a fraction of a major one's, not a second paint stack, so a gradient crosses every dot. */
|
|
90
73
|
subScale: number;
|
|
91
|
-
/**
|
|
74
|
+
/** As `LineGridPattern.offset`, so the two stay aligned while both scroll. */
|
|
92
75
|
offset: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
|
|
93
76
|
flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
|
|
94
77
|
gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
|
|
@@ -113,6 +96,4 @@ export declare const DotGridPattern: import("@motionscript/sdk").Component<"dotG
|
|
|
113
96
|
};
|
|
114
97
|
}, _Node2D<_Node2DProps>>>>;
|
|
115
98
|
export type DotGridPattern = NodeOf<typeof DotGridPattern>;
|
|
116
|
-
/** What a call or a document row may set. */
|
|
117
|
-
export type DotGridPatternProps = NonNullable<Parameters<typeof DotGridPattern>[0]>;
|
|
118
99
|
//# 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,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;
|
|
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;AA4C1B;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc;IA5BzB,6FAA6F;;IAE7F,+EAA+E;;IAE/E,6BAA6B;;IAE7B,sHAAsH;;IAEtH,8EAA8E;;;;;;;;;;;;;;;;;;;;;;;;IAR9E,6FAA6F;;IAE7F,+EAA+E;;IAE/E,6BAA6B;;IAE7B,sHAAsH;;IAEtH,8EAA8E;;;;;;;;;;;;;;;IAR9E,6FAA6F;;IAE7F,+EAA+E;;IAE/E,6BAA6B;;IAE7B,sHAAsH;;IAEtH,8EAA8E;;;;;;;;;;;;;;;;;;;;;;;2BAiC9E,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,cAAc,CAAC,CAAA"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Flow, Graphics2D, Paint, Types, component2d, lerpVector2, } from "@motionscript/sdk";
|
|
2
2
|
import { addTiledLines } from "../kit/index.js";
|
|
3
|
-
//
|
|
3
|
+
// The tiling `LineGridPattern` uses, so dots stay on its intersections at every offset.
|
|
4
4
|
function gridPositions(min, max, step, offset, subdivisions, overscan) {
|
|
5
5
|
const out = [];
|
|
6
|
-
// Anchored at the near edge, so a column or row sits on each edge of the box for any count
|
|
6
|
+
// Anchored at the near edge, so a column or row sits on each edge of the box for any cell count.
|
|
7
7
|
addTiledLines(min, max, step, offset, subdivisions, overscan, (pos, isMajor) => {
|
|
8
8
|
out.push({ pos, isMajor });
|
|
9
9
|
}, min);
|
|
@@ -12,33 +12,24 @@ function gridPositions(min, max, step, offset, subdivisions, overscan) {
|
|
|
12
12
|
const state = {
|
|
13
13
|
...Paint.state,
|
|
14
14
|
...Flow.state,
|
|
15
|
-
/** Cells along each axis, as in `LineGridPattern.divisions`: 4 puts 5 major dots on each
|
|
15
|
+
/** Cells along each axis, as in `LineGridPattern.divisions`: 4 puts 5 major dots on each. */
|
|
16
16
|
divisions: 4,
|
|
17
|
-
/**
|
|
17
|
+
/** `1` draws only the major dots; `2` puts one minor dot between each pair. */
|
|
18
18
|
subdivisions: 1,
|
|
19
19
|
/** Radius of a major dot. */
|
|
20
20
|
radius: 3,
|
|
21
|
-
/**
|
|
22
|
-
* A minor dot's radius as a fraction of a major one's. A fraction rather than a
|
|
23
|
-
* second paint stack, so the whole field stays one fill and a gradient crosses
|
|
24
|
-
* every dot in it.
|
|
25
|
-
*/
|
|
21
|
+
/** A minor dot's radius as a fraction of a major one's, not a second paint stack, so a gradient crosses every dot. */
|
|
26
22
|
subScale: 0.5,
|
|
27
|
-
/**
|
|
23
|
+
/** As `LineGridPattern.offset`, so the two stay aligned while both scroll. */
|
|
28
24
|
offset: Types.custom({ x: 0, y: 0 }, { lerp: lerpVector2 }),
|
|
29
25
|
};
|
|
30
26
|
/**
|
|
31
27
|
* A field of dots on the same `divisions` / `subdivisions` / `offset` as
|
|
32
|
-
* `LineGridPattern`, so laid over one the dots sit on its intersections.
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* What `clip` confines the children to, and what picking tests, is the node's
|
|
39
|
-
* box rather than the silhouette, which clips outer dots as they pan out and
|
|
40
|
-
* keeps the node selectable between dots. `start` / `end` act on nothing:
|
|
41
|
-
* trimming a disc leaves a crescent, not a partial grid.
|
|
28
|
+
* `LineGridPattern`, so laid over one the dots sit on its intersections. The
|
|
29
|
+
* dots are the silhouette `Paint.draw` paints; a background is a rectangle behind
|
|
30
|
+
* it. `clip` and picking use the node's box, not the silhouette, so outer dots
|
|
31
|
+
* clip as they pan out and the node stays selectable between dots. `start` and
|
|
32
|
+
* `end` act on nothing: trimming a disc leaves a crescent, not a partial grid.
|
|
42
33
|
*/
|
|
43
34
|
export const DotGridPattern = component2d({
|
|
44
35
|
key: "dotGridPattern",
|
|
@@ -54,7 +45,7 @@ export const DotGridPattern = component2d({
|
|
|
54
45
|
Paint.draw(ctx, untrimmed, dots(ctx.size, state), { clipShape: box });
|
|
55
46
|
},
|
|
56
47
|
});
|
|
57
|
-
/** Every dot
|
|
48
|
+
/** Every dot as one un-painted union: the paint stacks belong to the grid, not a dot. */
|
|
58
49
|
function dots(size, s) {
|
|
59
50
|
const { width, height } = size;
|
|
60
51
|
if (width <= 0 || height <= 0)
|
|
@@ -75,8 +66,7 @@ function dots(size, s) {
|
|
|
75
66
|
let drew = false;
|
|
76
67
|
for (const column of xs) {
|
|
77
68
|
for (const row of ys) {
|
|
78
|
-
//
|
|
79
|
-
// major rules, which is exactly the point a line grid draws heaviest.
|
|
69
|
+
// Major only where both axes are: an intersection of two major rules.
|
|
80
70
|
const size = column.isMajor && row.isMajor ? major : minor;
|
|
81
71
|
if (size <= 0)
|
|
82
72
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dot-grid-pattern.js","sourceRoot":"","sources":["../../src/dot-grid-pattern/dot-grid-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,UAAU,EACV,KAAK,EACL,KAAK,EACL,WAAW,EACX,WAAW,GAiBZ,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"dot-grid-pattern.js","sourceRoot":"","sources":["../../src/dot-grid-pattern/dot-grid-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,UAAU,EACV,KAAK,EACL,KAAK,EACL,WAAW,EACX,WAAW,GAiBZ,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,a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AA;YAC1D,IAAI,IAAI,IAAI,CAAC;gBAAE,SAAQ;YACvB,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,GAAG,CAAC,EAAE,MAAM,EAAE,IAAI,GAAG,CAAC,EAAE,CAAC,CAAA;YAC/E,IAAI,GAAG,IAAI,CAAA;QACb,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAA;AAC5B,CAAC","sourcesContent":["import {\n Flow,\n Graphics2D,\n Paint,\n Types,\n component2d,\n lerpVector2,\n type NodeOf,\n type Size2D,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Alignment as _Alignment,\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type FlowMode as _FlowMode,\n type FlowResolved as _FlowResolved,\n type GapSize as _GapSize,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n} from \"@motionscript/sdk\"\n\nimport { addTiledLines } from \"../kit\"\n\n// The tiling `LineGridPattern` uses, so dots stay on its intersections at every offset.\nfunction gridPositions(\n min: number,\n max: number,\n step: number,\n offset: number,\n subdivisions: number,\n overscan: number\n): { pos: number; isMajor: boolean }[] {\n const out: { pos: number; isMajor: boolean }[] = []\n // Anchored at the near edge, so a column or row sits on each edge of the box for any cell count.\n addTiledLines(min, max, step, offset, subdivisions, overscan, (pos, isMajor) => {\n out.push({ pos, isMajor })\n }, min)\n return out\n}\n\nconst state = {\n ...Paint.state,\n ...Flow.state,\n /** Cells along each axis, as in `LineGridPattern.divisions`: 4 puts 5 major dots on each. */\n divisions: 4,\n /** `1` draws only the major dots; `2` puts one minor dot between each pair. */\n subdivisions: 1,\n /** Radius of a major dot. */\n radius: 3,\n /** A minor dot's radius as a fraction of a major one's, not a second paint stack, so a gradient crosses every dot. */\n subScale: 0.5,\n /** As `LineGridPattern.offset`, so the two stay aligned while both scroll. */\n offset: Types.custom<Vector2>({ x: 0, y: 0 }, { lerp: lerpVector2 }),\n}\n\ninterface DotField {\n readonly divisions: number\n readonly subdivisions: number\n readonly radius: number\n readonly subScale: number\n readonly offset: Vector2\n}\n\n/**\n * A field of dots on the same `divisions` / `subdivisions` / `offset` as\n * `LineGridPattern`, so laid over one the dots sit on its intersections. The\n * dots are the silhouette `Paint.draw` paints; a background is a rectangle behind\n * it. `clip` and picking use the node's box, not the silhouette, so outer dots\n * clip as they pan out and the node stays selectable between dots. `start` and\n * `end` act on nothing: trimming a disc leaves a crescent, not a partial grid.\n */\nexport const DotGridPattern = component2d({\n key: \"dotGridPattern\",\n state,\n commands: { ...Paint.commands },\n measure: (measurer, state, children) => Flow.measure(measurer, state, children, Paint.inset(state)),\n layout: (box, state, children) => Flow.layout(box, state, children, Paint.inset(state)),\n render: (ctx, state) => {\n const untrimmed = {\n fill: state.fill, stroke: state.stroke, shadow: state.shadow, overlay: state.overlay, start: 0, end: 1, clip: state.clip,\n }\n const box = new Graphics2D().rect({ width: ctx.size.width, height: ctx.size.height })\n Paint.draw(ctx, untrimmed, dots(ctx.size, state), { clipShape: box })\n },\n})\n\nexport type DotGridPattern = NodeOf<typeof DotGridPattern>\n\n/** Every dot as one un-painted union: the paint stacks belong to the grid, not a dot. */\nfunction dots(size: Size2D, s: DotField): Graphics2D | null {\n const { width, height } = size\n if (width <= 0 || height <= 0) return null\n\n const divisions = Math.max(1, Math.floor(s.divisions))\n const subdivisions = Math.max(1, Math.floor(s.subdivisions))\n const major = Math.max(0, s.radius)\n const minor = major * Math.max(0, s.subScale)\n if (major <= 0 && minor <= 0) return null\n\n // Inset by a dot's radius so an edge dot sits inside the box rather than being halved by the clip.\n const cols = divisions * subdivisions\n const insetX = Math.max(0, width / 2 - major)\n const insetY = Math.max(0, height / 2 - major)\n const xs = gridPositions(\n -insetX,\n insetX,\n (insetX * 2) / cols,\n s.offset.x,\n subdivisions,\n major\n )\n const ys = gridPositions(\n -insetY,\n insetY,\n (insetY * 2) / cols,\n s.offset.y,\n subdivisions,\n major\n )\n\n const field = new Graphics2D()\n let drew = false\n for (const column of xs) {\n for (const row of ys) {\n // Major only where both axes are: an intersection of two major rules.\n const size = column.isMajor && row.isMajor ? major : minor\n if (size <= 0) continue\n field.ellipse({ x: column.pos, y: row.pos, width: size * 2, height: size * 2 })\n drew = true\n }\n }\n return drew ? field : null\n}\n"]}
|
package/dist/engine.d.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The patterns
|
|
3
|
-
*
|
|
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.
|
|
2
|
+
* The patterns kit, which a copy imports from `@motionscript/patterns/kit`.
|
|
3
|
+
* `grid-lines` is the tiling every pattern shares; a copy that kept its own
|
|
4
|
+
* would drift, and the dots would leave the line grid's intersections.
|
|
10
5
|
*/
|
|
11
6
|
export * from "./kit/index.js";
|
|
12
7
|
//# sourceMappingURL=engine.d.ts.map
|
package/dist/engine.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,OAAO,CAAA"}
|
package/dist/engine.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The patterns
|
|
3
|
-
*
|
|
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.
|
|
2
|
+
* The patterns kit, which a copy imports from `@motionscript/patterns/kit`.
|
|
3
|
+
* `grid-lines` is the tiling every pattern shares; a copy that kept its own
|
|
4
|
+
* would drift, and the dots would leave the line grid's intersections.
|
|
10
5
|
*/
|
|
11
6
|
export * from "./kit/index.js";
|
|
12
7
|
//# sourceMappingURL=engine.js.map
|
package/dist/engine.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,OAAO,CAAA","sourcesContent":["/**\n * The patterns kit, which a copy imports from `@motionscript/patterns/kit`.\n * `grid-lines` is the tiling every pattern shares; a copy that kept its own\n * would drift, and the dots would leave the line grid's intersections.\n */\nexport * from \"./kit\"\n"]}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { type NodeOf, type ShadowResolved, type FillResolved, type StrokeResolved, type Vector2, type Alignment as _Alignment, type Fill as _Fill, type FlowMode as _FlowMode, type FlowResolved as _FlowResolved, type GapSize as _GapSize, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Shadow as _Shadow, type Stroke as _Stroke } from "@motionscript/sdk";
|
|
2
2
|
/**
|
|
3
|
-
* An infinite line grid that fills the camera's visible region
|
|
4
|
-
* `LineGridPattern
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* camera it fills its own layout rect.
|
|
3
|
+
* An infinite line grid that fills the camera's visible region: like
|
|
4
|
+
* `LineGridPattern`, but it tiles a world-anchored grid (spacing `cellSize`)
|
|
5
|
+
* across what the nearest `Camera` sees, regenerated each frame. With no camera it
|
|
6
|
+
* fills its own layout rect.
|
|
8
7
|
*/
|
|
9
8
|
export declare const GridPattern: import("@motionscript/sdk").Component<"gridPattern", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
10
9
|
/** Spacing between grid lines in world units: one number for both axes, or `{ x, y }`. */
|
|
@@ -89,6 +88,4 @@ export declare const GridPattern: import("@motionscript/sdk").Component<"gridPat
|
|
|
89
88
|
};
|
|
90
89
|
}, _Node2D<_Node2DProps>>>>;
|
|
91
90
|
export type GridPattern = NodeOf<typeof GridPattern>;
|
|
92
|
-
/** What a call or a document row may set. */
|
|
93
|
-
export type GridPatternProps = NonNullable<Parameters<typeof GridPattern>[0]>;
|
|
94
91
|
//# sourceMappingURL=grid-pattern.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grid-pattern.d.ts","sourceRoot":"","sources":["../../src/grid-pattern/grid-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EAOH,KAAK,MAAM,EAGX,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,OAAO,EAEZ,KAAK,SAAS,IAAI,UAAU,EAC5B,KAAK,IAAI,IAAI,KAAK,EAClB,KAAK,QAAQ,IAAI,SAAS,EAC1B,KAAK,YAAY,IAAI,aAAa,EAClC,KAAK,OAAO,IAAI,QAAQ,EACxB,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,IAAI,YAAY,EAChC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,MAAM,IAAI,OAAO,EACzB,MAAM,mBAAmB,CAAC;AAI3B
|
|
1
|
+
{"version":3,"file":"grid-pattern.d.ts","sourceRoot":"","sources":["../../src/grid-pattern/grid-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EAOH,KAAK,MAAM,E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