@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
|
@@ -1,22 +1,12 @@
|
|
|
1
1
|
import { Camera, Flow, Graphics2D, Paint, } from "@motionscript/sdk";
|
|
2
2
|
/**
|
|
3
|
-
* What a
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* can currently see (from its `zoom`/`lookAt`/`heading`), so it only ever
|
|
10
|
-
* generates geometry for what's on screen, with no oversized node sized for the
|
|
11
|
-
* worst-case pan and zoom. With no `Camera` above it, it fills its own box, so the
|
|
12
|
-
* same pattern doubles as an ordinary full-bleed background.
|
|
13
|
-
*
|
|
14
|
-
* The pattern is itself a camera child, laid out at the camera's centre, so its
|
|
15
|
-
* local draw space shares the world origin its siblings use. The visible region
|
|
16
|
-
* is therefore expressed directly in that space: centred on the camera's
|
|
17
|
-
* `lookAt`, sized to the inverse of the camera transform.
|
|
3
|
+
* What a pattern filling the camera's visible region shares: spread `state` and
|
|
4
|
+
* `commands` in, pass `measure` and `layout`, and draw with {@link draw}. Inside a
|
|
5
|
+
* `Camera` the pattern is handed the world region it can see, so it only generates
|
|
6
|
+
* geometry for what is on screen; with none it fills its own box. It is laid out at
|
|
7
|
+
* the camera's centre, so its draw space shares the world origin its siblings use.
|
|
8
|
+
* A pattern is a shape: paints, and children laid out like a rect's.
|
|
18
9
|
*/
|
|
19
|
-
/** A pattern is a shape: paints, and children laid out like a rect's. */
|
|
20
10
|
export const state = { ...Paint.state, ...Flow.state };
|
|
21
11
|
export const commands = { ...Paint.commands };
|
|
22
12
|
export function measure(measurer, s, children) {
|
|
@@ -25,10 +15,7 @@ export function measure(measurer, s, children) {
|
|
|
25
15
|
export function layout(box, s, children) {
|
|
26
16
|
return Flow.layout(box, s, children, Paint.inset(s));
|
|
27
17
|
}
|
|
28
|
-
/**
|
|
29
|
-
* The region the pattern covers, in its own draw space: the world rect the
|
|
30
|
-
* nearest `Camera` above it sees, or its own box when there is none.
|
|
31
|
-
*/
|
|
18
|
+
/** The world rect the nearest `Camera` sees, in the pattern's draw space, else its own box. */
|
|
32
19
|
export function visibleBounds(ctx) {
|
|
33
20
|
const camera = ctx.ancestor(Camera);
|
|
34
21
|
if (!camera)
|
|
@@ -36,11 +23,9 @@ export function visibleBounds(ctx) {
|
|
|
36
23
|
const { width: vw, height: vh } = camera.size;
|
|
37
24
|
const zoom = camera.state.zoom || 1;
|
|
38
25
|
const heading = camera.state.heading;
|
|
39
|
-
// Inverse of the camera scale: a viewport `vw×vh` shows `vw/zoom × vh/zoom` of the world.
|
|
40
26
|
const hw = vw / 2 / zoom;
|
|
41
27
|
const hh = vh / 2 / zoom;
|
|
42
|
-
// With a heading the visible
|
|
43
|
-
// bounding box so the pattern covers the rotated viewport's full extent.
|
|
28
|
+
// With a heading the visible rect is rotated; its axis-aligned bounding box covers the full extent.
|
|
44
29
|
let bw = hw;
|
|
45
30
|
let bh = hh;
|
|
46
31
|
if (heading !== 0) {
|
|
@@ -50,20 +35,14 @@ export function visibleBounds(ctx) {
|
|
|
50
35
|
bw = hw * cos + hh * sin;
|
|
51
36
|
bh = hw * sin + hh * cos;
|
|
52
37
|
}
|
|
53
|
-
// Centred on the camera's `lookAt`, in y-up world space
|
|
54
|
-
// convention; the renderer applies the single y-up→canvas flip when the
|
|
55
|
-
// pattern's shapes are drawn).
|
|
38
|
+
// Centred on the camera's `lookAt`, in y-up world space.
|
|
56
39
|
const lookAt = camera.state.lookAt;
|
|
57
40
|
return { x: lookAt.x, y: lookAt.y, width: bw * 2, height: bh * 2 };
|
|
58
41
|
}
|
|
59
42
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* (so thick lines slide out instead of popping) trims cleanly. Inside a camera
|
|
64
|
-
* the viewport already clips, but this keeps edge strokes clean and bounds the
|
|
65
|
-
* work with no camera too. A `centerBounds` for a path drawn here is
|
|
66
|
-
* `[bounds.x - w/2, bounds.y - h/2, bounds.x + w/2, bounds.y + h/2]`.
|
|
43
|
+
* Paints `pattern` over the visible region, then the children. Clipped to the
|
|
44
|
+
* region so overscanned geometry trims cleanly even with no camera. A path drawn
|
|
45
|
+
* here takes `centerBounds` of `[bounds.x - w/2, bounds.y - h/2, bounds.x + w/2, bounds.y + h/2]`.
|
|
67
46
|
*/
|
|
68
47
|
export function draw(ctx, pattern) {
|
|
69
48
|
const bounds = visibleBounds(ctx);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viewport-pattern.js","sourceRoot":"","sources":["../../src/kit/viewport-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,MAAM,EACN,IAAI,EACJ,UAAU,EACV,KAAK,GAoBR,MAAM,mBAAmB,CAAC;AAE3B
|
|
1
|
+
{"version":3,"file":"viewport-pattern.js","sourceRoot":"","sources":["../../src/kit/viewport-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,MAAM,EACN,IAAI,EACJ,UAAU,EACV,KAAK,GAoBR,MAAM,mBAAmB,CAAC;AAE3B;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,EAAE,GAAG,KAAK,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;AAEvD,MAAM,CAAC,MAAM,QAAQ,GAAG,EAAE,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;AAI9C,MAAM,UAAU,OAAO,CAAC,QAAkB,EAAE,CAAa,EAAE,QAA8B;IACrF,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC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AAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QACpC,EAAE,GAAG,EAAE,GAAG,GAAG,GAAG,EAAE,GAAG,GAAG,CAAC;QACzB,EAAE,GAAG,EAAE,GAAG,GAAG,GAAG,EAAE,GAAG,GAAG,CAAC;IAC7B,CAAC;IAED,yDAAyD;IACzD,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;IACnC,OAAO,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC;AACvE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,IAAI,CAAC,GAAkB,EAAE,OAAoC;IACzE,MAAM,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;IAClC,MAAM,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IAC/G,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC3D,GAAG,CAAC,QAAQ,EAAE,CAAC;AACnB,CAAC","sourcesContent":["import {\n Camera,\n Flow,\n Graphics2D,\n Paint,\n type BoxBounds,\n type ChildView,\n type Measurer,\n type Placement2D,\n type RenderContext,\n type Size2D,\n type Values,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Alignment as _Alignment,\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type FlowMode as _FlowMode,\n type FlowResolved as _FlowResolved,\n type GapSize as _GapSize,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n type Vector2 as _Vector2,\n} from \"@motionscript/sdk\";\n\n/**\n * What a 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"]}
|
|
@@ -88,6 +88,4 @@ export declare const LineGridPattern: import("@motionscript/sdk").Component<"lin
|
|
|
88
88
|
};
|
|
89
89
|
}, _Node2D<_Node2DProps>>>>;
|
|
90
90
|
export type LineGridPattern = NodeOf<typeof LineGridPattern>;
|
|
91
|
-
/** What a call or a document row may set. */
|
|
92
|
-
export type LineGridPatternProps = NonNullable<Parameters<typeof LineGridPattern>[0]>;
|
|
93
91
|
//# sourceMappingURL=line-grid-pattern.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"line-grid-pattern.d.ts","sourceRoot":"","sources":["../../src/line-grid-pattern/line-grid-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EAOH,KAAK,MAAM,EAGX,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,EACzC,MAAM,mBAAmB,CAAC;AAI3B;;;;;GAKG;AACH,eAAO,MAAM,eAAe;IAKpB,4EAA4E;;IAE5E,gGAAgG;;IAEhG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AAC"}
|
|
@@ -55,8 +55,6 @@ export const LineGridPattern = component2d({
|
|
|
55
55
|
Paint.draw(ctx, state, null, { clipShape: box });
|
|
56
56
|
},
|
|
57
57
|
});
|
|
58
|
-
// One multi-subpath path per group, so each stroke paints its lines as a union with no
|
|
59
|
-
// destructive boolean op (which would erase open lines).
|
|
60
58
|
function gridPaths(width, height, divisions, subdivisions, overscan, offset) {
|
|
61
59
|
// Inset by `overscan` so the outermost lines sit fully inside the rect and are not
|
|
62
60
|
// trimmed to half weight by the clip.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"line-grid-pattern.js","sourceRoot":"","sources":["../../src/line-grid-pattern/line-grid-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,IAAI,EACJ,UAAU,EACV,KAAK,EACL,KAAK,EACL,WAAW,EACX,WAAW,GAkBd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE9E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC;IACvC,GAAG,EAAE,iBAAiB;IACtB,KAAK,EAAE;QACH,GAAG,KAAK,CAAC,KAAK;QACd,GAAG,IAAI,CAAC,KAAK;QACb,4EAA4E;QAC5E,SAAS,EAAE,CAAC;QACZ,gGAAgG;QAChG,YAAY,EAAE,CAAC;QACf,qGAAqG;QACrG,SAAS,EAAE,KAAK,CAAC,MAAM;QACvB,4FAA4F;QAC5F,MAAM,EAAE,KAAK,CAAC,MAAM,CAAU,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;KACvE;IACD,QAAQ,EAAE,EAAE,SAAS,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE;IACnE,QAAQ,EAAE,EAAE,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,GAAG,SAAS,GAAG,YAAY,CAAC;IACtC,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC;IACjD,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC;IAClD,MAAM,MAAM,GAAG,KAAK,GAAG,CAAC,GAAG,QAAQ,CAAC;IACpC,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,GAAG,QAAQ,CAAC;IAErC,4FAA4F;IAC5F,OAAO,aAAa,CAChB,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,EACrF,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,EACrF,YAAY,EACZ,QAAQ,CACX,CAAC;AACN,CAAC","sourcesContent":["import {\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"]}
|
package/dist/nodes.d.ts
CHANGED
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
import { DotGridPattern } from "./dot-grid-pattern/index.js";
|
|
2
2
|
import { GridPattern } from "./grid-pattern/index.js";
|
|
3
3
|
import { LineGridPattern } from "./line-grid-pattern/index.js";
|
|
4
|
-
/**
|
|
5
|
-
* Every node type this package publishes.
|
|
6
|
-
*
|
|
7
|
-
* A host registers these by handing the array to an engine —
|
|
8
|
-
* `new Engine(platform, { nodes: NODES })` — which reads each component's key.
|
|
9
|
-
* Defining a component only *declares* that key: nothing is registered by
|
|
10
|
-
* importing a module, so a registry holds exactly what its owner asked for.
|
|
11
|
-
*
|
|
12
|
-
* Listing the component **values** is also what survives bundling: this package
|
|
13
|
-
* declares `sideEffects: false`, and a document names a node type by string, so
|
|
14
|
-
* an import kept only for its side effect is exactly what gets shaken out.
|
|
15
|
-
*/
|
|
16
4
|
type KitNode = typeof LineGridPattern | typeof DotGridPattern | typeof GridPattern;
|
|
17
5
|
export declare const NODES: KitNode[];
|
|
18
6
|
export {};
|
package/dist/nodes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../src/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../src/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAGrD,KAAK,OAAO,GACN,OAAO,eAAe,GACtB,OAAO,cAAc,GACrB,OAAO,WAAW,CAAA;AAExB,eAAO,MAAM,KAAK,EAAE,OAAO,EAI1B,CAAA"}
|
package/dist/nodes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodes.js","sourceRoot":"","sources":["../src/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"nodes.js","sourceRoot":"","sources":["../src/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAQrD,MAAM,CAAC,MAAM,KAAK,GAAc;IAC5B,eAAe;IACf,cAAc;IACd,WAAW;CACd,CAAA","sourcesContent":["import { DotGridPattern } from \"./dot-grid-pattern\"\nimport { GridPattern } from \"./grid-pattern\"\nimport { LineGridPattern } from \"./line-grid-pattern\"\n\n// Typed by name, so the declaration names each component rather than spelling out its type through core.\ntype KitNode =\n | typeof LineGridPattern\n | typeof DotGridPattern\n | typeof GridPattern\n\nexport const NODES: KitNode[] = [\n LineGridPattern,\n DotGridPattern,\n GridPattern,\n]\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@motionscript/patterns",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1-alpha.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Background patterns for Motion Script: line and dot grids that fill a box, and an infinite grid that fills whatever a camera can see.",
|
|
6
6
|
"repository": {
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"license": "Apache-2.0",
|
|
52
52
|
"author": "Motionscript",
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@motionscript/sdk": "^0.1.
|
|
54
|
+
"@motionscript/sdk": "^0.1.1-alpha.1"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@types/node": "^25.6.2",
|
|
@@ -62,8 +62,8 @@
|
|
|
62
62
|
"typescript": "^6.0.3",
|
|
63
63
|
"typescript-eslint": "^8.48.0",
|
|
64
64
|
"vitest": "^4.1.5",
|
|
65
|
-
"@motionscript/core": "0.1.
|
|
66
|
-
"@motionscript/sdk": "0.1.
|
|
65
|
+
"@motionscript/core": "0.1.1-alpha.1",
|
|
66
|
+
"@motionscript/sdk": "0.1.1-alpha.1"
|
|
67
67
|
},
|
|
68
68
|
"scripts": {
|
|
69
69
|
"build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json --resolve-full-paths && node ../../../scripts/build-browser.mjs",
|
|
@@ -25,13 +25,7 @@ import {
|
|
|
25
25
|
|
|
26
26
|
import { addTiledLines } from "../kit"
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
interface GridPosition {
|
|
30
|
-
pos: number
|
|
31
|
-
isMajor: boolean
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Calls the tiling `LineGridPattern` uses, so dots stay on its intersections at every offset.
|
|
28
|
+
// The tiling `LineGridPattern` uses, so dots stay on its intersections at every offset.
|
|
35
29
|
function gridPositions(
|
|
36
30
|
min: number,
|
|
37
31
|
max: number,
|
|
@@ -39,9 +33,9 @@ function gridPositions(
|
|
|
39
33
|
offset: number,
|
|
40
34
|
subdivisions: number,
|
|
41
35
|
overscan: number
|
|
42
|
-
):
|
|
43
|
-
const out:
|
|
44
|
-
// Anchored at the near edge, so a column or row sits on each edge of the box for any count
|
|
36
|
+
): { pos: number; isMajor: boolean }[] {
|
|
37
|
+
const out: { pos: number; isMajor: boolean }[] = []
|
|
38
|
+
// Anchored at the near edge, so a column or row sits on each edge of the box for any cell count.
|
|
45
39
|
addTiledLines(min, max, step, offset, subdivisions, overscan, (pos, isMajor) => {
|
|
46
40
|
out.push({ pos, isMajor })
|
|
47
41
|
}, min)
|
|
@@ -51,19 +45,15 @@ function gridPositions(
|
|
|
51
45
|
const state = {
|
|
52
46
|
...Paint.state,
|
|
53
47
|
...Flow.state,
|
|
54
|
-
/** Cells along each axis, as in `LineGridPattern.divisions`: 4 puts 5 major dots on each
|
|
48
|
+
/** Cells along each axis, as in `LineGridPattern.divisions`: 4 puts 5 major dots on each. */
|
|
55
49
|
divisions: 4,
|
|
56
|
-
/**
|
|
50
|
+
/** `1` draws only the major dots; `2` puts one minor dot between each pair. */
|
|
57
51
|
subdivisions: 1,
|
|
58
52
|
/** Radius of a major dot. */
|
|
59
53
|
radius: 3,
|
|
60
|
-
/**
|
|
61
|
-
* A minor dot's radius as a fraction of a major one's. A fraction rather than a
|
|
62
|
-
* second paint stack, so the whole field stays one fill and a gradient crosses
|
|
63
|
-
* every dot in it.
|
|
64
|
-
*/
|
|
54
|
+
/** A minor dot's radius as a fraction of a major one's, not a second paint stack, so a gradient crosses every dot. */
|
|
65
55
|
subScale: 0.5,
|
|
66
|
-
/**
|
|
56
|
+
/** As `LineGridPattern.offset`, so the two stay aligned while both scroll. */
|
|
67
57
|
offset: Types.custom<Vector2>({ x: 0, y: 0 }, { lerp: lerpVector2 }),
|
|
68
58
|
}
|
|
69
59
|
|
|
@@ -77,16 +67,11 @@ interface DotField {
|
|
|
77
67
|
|
|
78
68
|
/**
|
|
79
69
|
* A field of dots on the same `divisions` / `subdivisions` / `offset` as
|
|
80
|
-
* `LineGridPattern`, so laid over one the dots sit on its intersections.
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
* What `clip` confines the children to, and what picking tests, is the node's
|
|
87
|
-
* box rather than the silhouette, which clips outer dots as they pan out and
|
|
88
|
-
* keeps the node selectable between dots. `start` / `end` act on nothing:
|
|
89
|
-
* trimming a disc leaves a crescent, not a partial grid.
|
|
70
|
+
* `LineGridPattern`, so laid over one the dots sit on its intersections. The
|
|
71
|
+
* dots are the silhouette `Paint.draw` paints; a background is a rectangle behind
|
|
72
|
+
* it. `clip` and picking use the node's box, not the silhouette, so outer dots
|
|
73
|
+
* clip as they pan out and the node stays selectable between dots. `start` and
|
|
74
|
+
* `end` act on nothing: trimming a disc leaves a crescent, not a partial grid.
|
|
90
75
|
*/
|
|
91
76
|
export const DotGridPattern = component2d({
|
|
92
77
|
key: "dotGridPattern",
|
|
@@ -104,10 +89,8 @@ export const DotGridPattern = component2d({
|
|
|
104
89
|
})
|
|
105
90
|
|
|
106
91
|
export type DotGridPattern = NodeOf<typeof DotGridPattern>
|
|
107
|
-
/** What a call or a document row may set. */
|
|
108
|
-
export type DotGridPatternProps = NonNullable<Parameters<typeof DotGridPattern>[0]>
|
|
109
92
|
|
|
110
|
-
/** Every dot
|
|
93
|
+
/** Every dot as one un-painted union: the paint stacks belong to the grid, not a dot. */
|
|
111
94
|
function dots(size: Size2D, s: DotField): Graphics2D | null {
|
|
112
95
|
const { width, height } = size
|
|
113
96
|
if (width <= 0 || height <= 0) return null
|
|
@@ -143,8 +126,7 @@ function dots(size: Size2D, s: DotField): Graphics2D | null {
|
|
|
143
126
|
let drew = false
|
|
144
127
|
for (const column of xs) {
|
|
145
128
|
for (const row of ys) {
|
|
146
|
-
//
|
|
147
|
-
// major rules, which is exactly the point a line grid draws heaviest.
|
|
129
|
+
// Major only where both axes are: an intersection of two major rules.
|
|
148
130
|
const size = column.isMajor && row.isMajor ? major : minor
|
|
149
131
|
if (size <= 0) continue
|
|
150
132
|
field.ellipse({ x: column.pos, y: row.pos, width: size * 2, height: size * 2 })
|
package/src/engine.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
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"
|
|
@@ -24,14 +24,13 @@ import {
|
|
|
24
24
|
type Stroke as _Stroke,
|
|
25
25
|
} from "@motionscript/sdk";
|
|
26
26
|
|
|
27
|
-
import { centered, defaultSubStroke, gridLines, maxWeight, ViewportPattern, type GridAxis } from "../kit";
|
|
27
|
+
import { centered, defaultSubStroke, gridLinePaths, gridLines, maxWeight, ViewportPattern, type GridAxis } from "../kit";
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
* An infinite line grid that fills the camera's visible region
|
|
31
|
-
* `LineGridPattern
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* camera it fills its own layout rect.
|
|
30
|
+
* An infinite line grid that fills the camera's visible region: like
|
|
31
|
+
* `LineGridPattern`, but it tiles a world-anchored grid (spacing `cellSize`)
|
|
32
|
+
* across what the nearest `Camera` sees, regenerated each frame. With no camera it
|
|
33
|
+
* fills its own layout rect.
|
|
35
34
|
*/
|
|
36
35
|
export const GridPattern = component2d({
|
|
37
36
|
key: "gridPattern",
|
|
@@ -54,8 +53,6 @@ export const GridPattern = component2d({
|
|
|
54
53
|
});
|
|
55
54
|
|
|
56
55
|
export type GridPattern = NodeOf<typeof GridPattern>;
|
|
57
|
-
/** What a call or a document row may set. */
|
|
58
|
-
export type GridPatternProps = NonNullable<Parameters<typeof GridPattern>[0]>;
|
|
59
56
|
|
|
60
57
|
interface GridState {
|
|
61
58
|
readonly fill: FillResolved[];
|
|
@@ -72,8 +69,7 @@ interface GridState {
|
|
|
72
69
|
function drawGrid(ctx: RenderContext, s: GridState, bounds: BoxBounds): void {
|
|
73
70
|
const halfW = bounds.width / 2;
|
|
74
71
|
const halfH = bounds.height / 2;
|
|
75
|
-
// `bounds` is centred on (x, y) in y-up world space
|
|
76
|
-
// and the renderer applies the single flip.
|
|
72
|
+
// `bounds` is centred on (x, y) in y-up world space.
|
|
77
73
|
const left = bounds.x - halfW;
|
|
78
74
|
const right = bounds.x + halfW;
|
|
79
75
|
const top = bounds.y - halfH;
|
|
@@ -107,9 +103,8 @@ function drawGrid(ctx: RenderContext, s: GridState, bounds: BoxBounds): void {
|
|
|
107
103
|
}
|
|
108
104
|
}
|
|
109
105
|
|
|
110
|
-
// A solid stroke paints the group as one union path. A dashed one draws each line on
|
|
111
|
-
//
|
|
112
|
-
// crawl as the camera pans or new lines scroll in.
|
|
106
|
+
// A solid stroke paints the group as one union path. A dashed one draws each line on its
|
|
107
|
+
// own, dash phase anchored to its world coordinate, so dashes never crawl as the camera pans.
|
|
113
108
|
function drawGroup(
|
|
114
109
|
ctx: RenderContext,
|
|
115
110
|
xAxis: GridAxis,
|
|
@@ -119,24 +114,22 @@ function drawGroup(
|
|
|
119
114
|
stroke: StrokeResolved[],
|
|
120
115
|
isMajor: boolean,
|
|
121
116
|
): void {
|
|
122
|
-
// Each line spans a whole number of dash cycles, so the renderer's per-path dash-fit
|
|
123
|
-
// is a no-op and every line dashes identically.
|
|
124
|
-
const cycle = dashCycle(stroke);
|
|
125
|
-
const g = gridLines(xAxis, yAxis, subdivisions, overscan, cycle);
|
|
126
|
-
const verticals = isMajor ? g.verticalMajor : g.verticalMinor;
|
|
127
|
-
const horizontals = isMajor ? g.horizontalMajor : g.horizontalMinor;
|
|
128
|
-
|
|
129
117
|
// Symmetric centerBounds give a zero recentre offset, so local coordinates draw verbatim.
|
|
130
118
|
const centerBounds = [-1, -1, 1, 1] as const;
|
|
131
119
|
|
|
120
|
+
const cycle = dashCycle(stroke);
|
|
132
121
|
if (cycle <= 0) {
|
|
133
|
-
const data
|
|
134
|
-
for (const px of verticals) data.push({ type: "M", x: px, y: g.top }, { type: "L", x: px, y: g.bottom });
|
|
135
|
-
for (const py of horizontals) data.push({ type: "M", x: g.left, y: py }, { type: "L", x: g.right, y: py });
|
|
122
|
+
const data = gridLinePaths(xAxis, yAxis, subdivisions, overscan)[isMajor ? "major" : "minor"];
|
|
136
123
|
if (data.length > 0) ctx.draw(new Graphics2D().path({ data, centerBounds }).stroke(stroke));
|
|
137
124
|
return;
|
|
138
125
|
}
|
|
139
126
|
|
|
127
|
+
// Each line spans a whole number of dash cycles, so the renderer's per-path dash-fit
|
|
128
|
+
// is a no-op and every line dashes identically.
|
|
129
|
+
const g = gridLines(xAxis, yAxis, subdivisions, overscan, cycle);
|
|
130
|
+
const verticals = isMajor ? g.verticalMajor : g.verticalMinor;
|
|
131
|
+
const horizontals = isMajor ? g.horizontalMajor : g.horizontalMinor;
|
|
132
|
+
|
|
140
133
|
for (const px of verticals) {
|
|
141
134
|
const data: PathCommand[] = [{ type: "M", x: px, y: g.top }, { type: "L", x: px, y: g.bottom }];
|
|
142
135
|
ctx.draw(new Graphics2D().path({ data, centerBounds }).stroke(phaseShift(stroke, g.top)));
|
|
@@ -159,8 +152,7 @@ function dashCycle(strokes: StrokeResolved[]): number {
|
|
|
159
152
|
return cycle;
|
|
160
153
|
}
|
|
161
154
|
|
|
162
|
-
// `dashOffset` advances the pattern, so it is negated to
|
|
163
|
-
// infinite line would have at this world coordinate.
|
|
155
|
+
// `dashOffset` advances the pattern, so it is negated to give the phase one infinite line would have at this world coordinate.
|
|
164
156
|
function phaseShift(strokes: StrokeResolved[], worldStart: number): StrokeResolved[] {
|
|
165
157
|
return strokes.map(s => (s.dash && s.dash.length > 0)
|
|
166
158
|
? { ...s, dashOffset: (s.dashOffset ?? 0) - worldStart }
|