@motionscript/patterns 0.0.0-stage → 0.1.0-alpha.10
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 +56 -0
- package/LICENSE +201 -0
- package/NOTICE +49 -0
- package/README.md +82 -2
- package/dist/browser/chunks/chunk-FXDYEY4R.js +2 -0
- package/dist/browser/chunks/chunk-FXDYEY4R.js.map +7 -0
- package/dist/browser/index.js +2 -0
- package/dist/browser/index.js.map +7 -0
- package/dist/browser/kit.js +2 -0
- package/dist/browser/kit.js.map +7 -0
- package/dist/browser/manifest.json +13 -0
- package/dist/dot-grid-pattern/dot-grid-pattern.d.ts +118 -0
- package/dist/dot-grid-pattern/dot-grid-pattern.d.ts.map +1 -0
- package/dist/dot-grid-pattern/dot-grid-pattern.js +89 -0
- package/dist/dot-grid-pattern/dot-grid-pattern.js.map +1 -0
- package/dist/dot-grid-pattern/index.d.ts +2 -0
- package/dist/dot-grid-pattern/index.d.ts.map +1 -0
- package/dist/dot-grid-pattern/index.js +2 -0
- package/dist/dot-grid-pattern/index.js.map +1 -0
- package/dist/engine.d.ts +12 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +12 -0
- package/dist/engine.js.map +1 -0
- package/dist/grid-pattern/grid-pattern.d.ts +94 -0
- package/dist/grid-pattern/grid-pattern.d.ts.map +1 -0
- package/dist/grid-pattern/grid-pattern.js +119 -0
- package/dist/grid-pattern/grid-pattern.js.map +1 -0
- package/dist/grid-pattern/index.d.ts +2 -0
- package/dist/grid-pattern/index.d.ts.map +1 -0
- package/dist/grid-pattern/index.js +2 -0
- package/dist/grid-pattern/index.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/kit/grid-lines.d.ts +111 -0
- package/dist/kit/grid-lines.d.ts.map +1 -0
- package/dist/kit/grid-lines.js +148 -0
- package/dist/kit/grid-lines.js.map +1 -0
- package/dist/kit/index.d.ts +3 -0
- package/dist/kit/index.d.ts.map +1 -0
- package/dist/kit/index.js +3 -0
- package/dist/kit/index.js.map +1 -0
- package/dist/kit/viewport-pattern.d.ts +81 -0
- package/dist/kit/viewport-pattern.d.ts.map +1 -0
- package/dist/kit/viewport-pattern.js +74 -0
- package/dist/kit/viewport-pattern.js.map +1 -0
- package/dist/line-grid-pattern/index.d.ts +2 -0
- package/dist/line-grid-pattern/index.d.ts.map +1 -0
- package/dist/line-grid-pattern/index.js +2 -0
- package/dist/line-grid-pattern/index.js.map +1 -0
- package/dist/line-grid-pattern/line-grid-pattern.d.ts +93 -0
- package/dist/line-grid-pattern/line-grid-pattern.d.ts.map +1 -0
- package/dist/line-grid-pattern/line-grid-pattern.js +71 -0
- package/dist/line-grid-pattern/line-grid-pattern.js.map +1 -0
- package/dist/nodes.d.ts +19 -0
- package/dist/nodes.d.ts.map +1 -0
- package/dist/nodes.js +9 -0
- package/dist/nodes.js.map +1 -0
- package/package.json +73 -3
- package/registry.json +26 -0
- package/src/dot-grid-pattern/dot-grid-pattern.ts +155 -0
- package/src/dot-grid-pattern/index.ts +1 -0
- package/src/engine.ts +11 -0
- package/src/grid-pattern/grid-pattern.ts +176 -0
- package/src/grid-pattern/index.ts +1 -0
- package/src/index.ts +5 -0
- package/src/kit/grid-lines.ts +223 -0
- package/src/kit/index.ts +2 -0
- package/src/kit/viewport-pattern.ts +109 -0
- package/src/line-grid-pattern/index.ts +1 -0
- package/src/line-grid-pattern/line-grid-pattern.ts +117 -0
- package/src/nodes.ts +27 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { type PathCommand, type StrokeResolved } from "@motionscript/sdk";
|
|
2
|
+
/**
|
|
3
|
+
* Shared geometry for line grids. Both {@link LineGridPattern} (a fixed grid filling
|
|
4
|
+
* its layout rect) and {@link GridPattern} (an infinite grid tiled across the
|
|
5
|
+
* camera's visible region) build the same multi-subpath line paths from these
|
|
6
|
+
* helpers — they differ only in how the extent and step are chosen.
|
|
7
|
+
*
|
|
8
|
+
* Lines are tiled by the minor step and panned by an origin offset: every
|
|
9
|
+
* position within the extent (grown by `overscan` so thick lines clip out
|
|
10
|
+
* smoothly) is emitted regardless of the offset, so the area always stays full
|
|
11
|
+
* and animating the offset scrolls the grid. The lattice starts at the axis's
|
|
12
|
+
* `anchor` (the world origin unless it says otherwise). A tile whose index
|
|
13
|
+
* aligns to the division grid is major; the rest are minor. Each is built as a
|
|
14
|
+
* single multi-subpath path so the trailing stroke paints every line as one
|
|
15
|
+
* union with no destructive boolean op (which would erase the open lines).
|
|
16
|
+
*/
|
|
17
|
+
/** A grid extent on one axis: lines tile within `[min, max]`, on a lattice that starts at `anchor`. */
|
|
18
|
+
export interface GridAxis {
|
|
19
|
+
/** Minimum coordinate (typically negative). */
|
|
20
|
+
min: number;
|
|
21
|
+
/** Maximum coordinate. */
|
|
22
|
+
max: number;
|
|
23
|
+
/** Spacing between adjacent (minor) lines. */
|
|
24
|
+
step: number;
|
|
25
|
+
/** Pan offset in pixels along this axis. */
|
|
26
|
+
offset: number;
|
|
27
|
+
/**
|
|
28
|
+
* Where the lattice starts: a line sits at `anchor + n * step`, and the tile
|
|
29
|
+
* index `n` that decides which lines are major counts from there. Omitted it is 0, the
|
|
30
|
+
* world origin, which is what a grid that follows a camera keeps. A grid with a box of its
|
|
31
|
+
* own sets it to `min`, so the box's edges are lines whatever the count of cells.
|
|
32
|
+
*/
|
|
33
|
+
anchor?: number;
|
|
34
|
+
}
|
|
35
|
+
/** The resolved grid: where each line sits and how far it runs. Vertical lines
|
|
36
|
+
* sit at x = `verticalX[i]` and run from `top` to `bottom`; horizontal lines sit
|
|
37
|
+
* at y = `horizontalY[i]` and run from `left` to `right`. Positions are split
|
|
38
|
+
* into major (division) and minor (subdivision) lines. */
|
|
39
|
+
export interface GridLines {
|
|
40
|
+
/** y-extent every vertical line spans. */
|
|
41
|
+
top: number;
|
|
42
|
+
bottom: number;
|
|
43
|
+
/** x-extent every horizontal line spans. */
|
|
44
|
+
left: number;
|
|
45
|
+
right: number;
|
|
46
|
+
verticalMajor: number[];
|
|
47
|
+
verticalMinor: number[];
|
|
48
|
+
horizontalMajor: number[];
|
|
49
|
+
horizontalMinor: number[];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Resolve the grid for the given per-axis extents: the cross-axis span and the
|
|
53
|
+
* major/minor line positions on each axis. Vertical lines span the full y
|
|
54
|
+
* extent; horizontal lines span the full x extent. Both spans are grown by
|
|
55
|
+
* `overscan` so a thick line slides out under the clip instead of popping, and
|
|
56
|
+
* snapped outward to the grid so the endpoints sit on stable world positions
|
|
57
|
+
* (a line's start stays fixed as the camera pans, so a dashed stroke anchored to
|
|
58
|
+
* it doesn't crawl).
|
|
59
|
+
*
|
|
60
|
+
* `cycle` (the dash period, when dashed) snaps the cross-axis span to a whole
|
|
61
|
+
* number of dash cycles too, so each parallel line is the same dash-aligned
|
|
62
|
+
* length and the renderer's per-path dash-fit becomes a no-op (no per-frame
|
|
63
|
+
* resizing of the dashes as lines enter and leave view).
|
|
64
|
+
*/
|
|
65
|
+
export declare function gridLines(x: GridAxis, y: GridAxis, subdivisions: number, overscan: number, cycle?: number): GridLines;
|
|
66
|
+
/**
|
|
67
|
+
* Build the grid lines as multi-subpath path commands, split into the major
|
|
68
|
+
* (division) lines and the minor (subdivision) lines, for the given per-axis
|
|
69
|
+
* extents. Every line in a group shares one stroke (drawn as one union path), so
|
|
70
|
+
* this is the path for solid strokes; dashed strokes that must stay world-locked
|
|
71
|
+
* draw per line from {@link gridLines} instead.
|
|
72
|
+
*/
|
|
73
|
+
export declare function gridLinePaths(x: GridAxis, y: GridAxis, subdivisions: number, overscan: number): {
|
|
74
|
+
major: PathCommand[];
|
|
75
|
+
minor: PathCommand[];
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Emit every grid line position in `[min, max]` (grown by `overscan` on each
|
|
79
|
+
* end) for a grid of spacing `step`, panned by `offset` px. Without panning the
|
|
80
|
+
* lattice starts at `anchor` (0 unless given) and its tile indices count outward
|
|
81
|
+
* from there; the line at tile index `n` is major when `n` is a multiple of
|
|
82
|
+
* `subdivisions`. The pan shifts each position by `offset` while keeping the
|
|
83
|
+
* area full, so `n` is taken relative to the un-panned lattice (offset folded
|
|
84
|
+
* out) to keep classification stable as it scrolls.
|
|
85
|
+
*
|
|
86
|
+
* A fixed grid anchors at `min`, so its first line is on the box's edge and the
|
|
87
|
+
* last is too whenever the extent is a whole number of steps. An infinite grid
|
|
88
|
+
* keeps the default, so its lines stay on the world's lattice.
|
|
89
|
+
*/
|
|
90
|
+
export declare function addTiledLines(min: number, max: number, step: number, offset: number, subdivisions: number, overscan: number, emit: (pos: number, isMajor: boolean) => void, anchor?: number): void;
|
|
91
|
+
/** Largest stroke weight across the layers of a resolved stroke array. Used to
|
|
92
|
+
* overscan the tiling so a thick line stays drawn until fully off the area. */
|
|
93
|
+
export declare function maxWeight(strokes: StrokeResolved[]): number;
|
|
94
|
+
/** Force every layer of a resolved stroke array to centered alignment. Grid
|
|
95
|
+
* lines are open paths, not a closed region, so inside/outside alignment is
|
|
96
|
+
* meaningless — they always straddle their position. (Open paths are already
|
|
97
|
+
* stroked centered by the renderer; this makes the intent explicit and ignores
|
|
98
|
+
* any author `align`.) */
|
|
99
|
+
export declare function centered(strokes: StrokeResolved[]): StrokeResolved[];
|
|
100
|
+
/** Copy a resolved stroke array with every fill layer's opacity scaled by
|
|
101
|
+
* `factor`. Used to derive the default minor-line stroke from the major one.
|
|
102
|
+
* Every resolved fill carries an `opacity` field, so this is type-uniform. */
|
|
103
|
+
export declare function dimStroke(strokes: StrokeResolved[], factor: number): StrokeResolved[];
|
|
104
|
+
/**
|
|
105
|
+
* The minor-line stroke of a pattern built with a `stroke` and no `subStroke`:
|
|
106
|
+
* the major one at half opacity, when it was built with minor lines. Read off
|
|
107
|
+
* what the pattern was built with (`given`), so it is not kept in step with a
|
|
108
|
+
* stroke written later.
|
|
109
|
+
*/
|
|
110
|
+
export declare function defaultSubStroke(given: Readonly<Record<string, unknown>>): StrokeResolved[];
|
|
111
|
+
//# sourceMappingURL=grid-lines.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grid-lines.d.ts","sourceRoot":"","sources":["../../src/kit/grid-lines.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,WAAW,EAAgC,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnH;;;;;;;;;;;;;;GAcG;AAEH,uGAAuG;AACvG,MAAM,WAAW,QAAQ;IACrB,+CAA+C;IAC/C,GAAG,EAAE,MAAM,CAAC;IACZ,0BAA0B;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;0DAG0D;AAC1D,MAAM,WAAW,SAAS;IACtB,0CAA0C;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,eAAe,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CACrB,CAAC,EAAE,QAAQ,EACX,CAAC,EAAE,QAAQ,EACX,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,KAAK,SAAI,GACV,SAAS,CAqBX;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CACzB,CAAC,EAAE,QAAQ,EACX,CAAC,EAAE,QAAQ,EACX,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,GACjB;IAAE,KAAK,EAAE,WAAW,EAAE,CAAC;IAAC,KAAK,EAAE,WAAW,EAAE,CAAA;CAAE,CAShD;AAgBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CACzB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,EAC7C,MAAM,SAAI,GACX,IAAI,CAeN;AAED;+EAC+E;AAC/E,wBAAgB,SAAS,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,MAAM,CAI3D;AAED;;;;0BAI0B;AAC1B,wBAAgB,QAAQ,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,CAEpE;AAED;;8EAE8E;AAC9E,wBAAgB,SAAS,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,cAAc,EAAE,CAKrF;AAID;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,cAAc,EAAE,CAS3F"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { strokeOps } from "@motionscript/sdk";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve the grid for the given per-axis extents: the cross-axis span and the
|
|
4
|
+
* major/minor line positions on each axis. Vertical lines span the full y
|
|
5
|
+
* extent; horizontal lines span the full x extent. Both spans are grown by
|
|
6
|
+
* `overscan` so a thick line slides out under the clip instead of popping, and
|
|
7
|
+
* snapped outward to the grid so the endpoints sit on stable world positions
|
|
8
|
+
* (a line's start stays fixed as the camera pans, so a dashed stroke anchored to
|
|
9
|
+
* it doesn't crawl).
|
|
10
|
+
*
|
|
11
|
+
* `cycle` (the dash period, when dashed) snaps the cross-axis span to a whole
|
|
12
|
+
* number of dash cycles too, so each parallel line is the same dash-aligned
|
|
13
|
+
* length and the renderer's per-path dash-fit becomes a no-op (no per-frame
|
|
14
|
+
* resizing of the dashes as lines enter and leave view).
|
|
15
|
+
*/
|
|
16
|
+
export function gridLines(x, y, subdivisions, overscan, cycle = 0) {
|
|
17
|
+
const verticalMajor = [];
|
|
18
|
+
const verticalMinor = [];
|
|
19
|
+
const horizontalMajor = [];
|
|
20
|
+
const horizontalMinor = [];
|
|
21
|
+
// Span each line across the cross axis, snapped outward to the grid (and to
|
|
22
|
+
// the dash cycle when dashed) so the endpoints sit on stable world positions.
|
|
23
|
+
const top = snapSpan(y.min - overscan, y.step, y.offset, cycle, Math.floor);
|
|
24
|
+
const bottom = snapSpan(y.max + overscan, y.step, y.offset, cycle, Math.ceil);
|
|
25
|
+
const left = snapSpan(x.min - overscan, x.step, x.offset, cycle, Math.floor);
|
|
26
|
+
const right = snapSpan(x.max + overscan, x.step, x.offset, cycle, Math.ceil);
|
|
27
|
+
addTiledLines(x.min, x.max, x.step, x.offset, subdivisions, overscan, (px, isMajor) => {
|
|
28
|
+
(isMajor ? verticalMajor : verticalMinor).push(px);
|
|
29
|
+
}, x.anchor);
|
|
30
|
+
addTiledLines(y.min, y.max, y.step, y.offset, subdivisions, overscan, (py, isMajor) => {
|
|
31
|
+
(isMajor ? horizontalMajor : horizontalMinor).push(py);
|
|
32
|
+
}, y.anchor);
|
|
33
|
+
return { top, bottom, left, right, verticalMajor, verticalMinor, horizontalMajor, horizontalMinor };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Build the grid lines as multi-subpath path commands, split into the major
|
|
37
|
+
* (division) lines and the minor (subdivision) lines, for the given per-axis
|
|
38
|
+
* extents. Every line in a group shares one stroke (drawn as one union path), so
|
|
39
|
+
* this is the path for solid strokes; dashed strokes that must stay world-locked
|
|
40
|
+
* draw per line from {@link gridLines} instead.
|
|
41
|
+
*/
|
|
42
|
+
export function gridLinePaths(x, y, subdivisions, overscan) {
|
|
43
|
+
const g = gridLines(x, y, subdivisions, overscan);
|
|
44
|
+
const major = [];
|
|
45
|
+
const minor = [];
|
|
46
|
+
for (const px of g.verticalMajor)
|
|
47
|
+
major.push({ type: "M", x: px, y: g.top }, { type: "L", x: px, y: g.bottom });
|
|
48
|
+
for (const px of g.verticalMinor)
|
|
49
|
+
minor.push({ type: "M", x: px, y: g.top }, { type: "L", x: px, y: g.bottom });
|
|
50
|
+
for (const py of g.horizontalMajor)
|
|
51
|
+
major.push({ type: "M", x: g.left, y: py }, { type: "L", x: g.right, y: py });
|
|
52
|
+
for (const py of g.horizontalMinor)
|
|
53
|
+
minor.push({ type: "M", x: g.left, y: py }, { type: "L", x: g.right, y: py });
|
|
54
|
+
return { major, minor };
|
|
55
|
+
}
|
|
56
|
+
// Snap `pos` outward to a stable world position so a dashed line's start stays
|
|
57
|
+
// fixed as the viewport moves (the renderer anchors dash phase to the subpath
|
|
58
|
+
// start). Snap to the grid line lattice (`n*step + offset`); when a dash `cycle`
|
|
59
|
+
// is given, snap to the dash lattice instead (`n*cycle`, anchored to world 0) so
|
|
60
|
+
// every parallel line is the same whole number of cycles long and the renderer's
|
|
61
|
+
// per-path dash-fit stays a no-op. `round` is `Math.floor` to snap below, `ceil`
|
|
62
|
+
// to snap above. The lattice is the one about 0 whatever an axis's `anchor`: a span
|
|
63
|
+
// only has to reach past the edge, and a line's ends stay where they always were.
|
|
64
|
+
function snapSpan(pos, step, offset, cycle, round) {
|
|
65
|
+
if (cycle > 0)
|
|
66
|
+
return round(pos / cycle) * cycle;
|
|
67
|
+
if (step <= 0)
|
|
68
|
+
return pos;
|
|
69
|
+
return round((pos - offset) / step) * step + offset;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Emit every grid line position in `[min, max]` (grown by `overscan` on each
|
|
73
|
+
* end) for a grid of spacing `step`, panned by `offset` px. Without panning the
|
|
74
|
+
* lattice starts at `anchor` (0 unless given) and its tile indices count outward
|
|
75
|
+
* from there; the line at tile index `n` is major when `n` is a multiple of
|
|
76
|
+
* `subdivisions`. The pan shifts each position by `offset` while keeping the
|
|
77
|
+
* area full, so `n` is taken relative to the un-panned lattice (offset folded
|
|
78
|
+
* out) to keep classification stable as it scrolls.
|
|
79
|
+
*
|
|
80
|
+
* A fixed grid anchors at `min`, so its first line is on the box's edge and the
|
|
81
|
+
* last is too whenever the extent is a whole number of steps. An infinite grid
|
|
82
|
+
* keeps the default, so its lines stay on the world's lattice.
|
|
83
|
+
*/
|
|
84
|
+
export function addTiledLines(min, max, step, offset, subdivisions, overscan, emit, anchor = 0) {
|
|
85
|
+
if (step <= 0)
|
|
86
|
+
return;
|
|
87
|
+
// First/last tile index whose panned position is within the overscanned
|
|
88
|
+
// [min, max]. Positions are `anchor + n*step + offset` (n=0 sits on the
|
|
89
|
+
// anchor). A small epsilon keeps a line that lands exactly on an edge (an
|
|
90
|
+
// anchor at `min`, or a world lattice that reaches it) from being dropped by FP error.
|
|
91
|
+
const eps = step * 1e-6;
|
|
92
|
+
const startN = Math.ceil((min - overscan - offset - anchor - eps) / step);
|
|
93
|
+
const endN = Math.floor((max + overscan - offset - anchor + eps) / step);
|
|
94
|
+
for (let n = startN; n <= endN; n++) {
|
|
95
|
+
const pos = anchor + n * step + offset;
|
|
96
|
+
// mod that stays non-negative for negative n.
|
|
97
|
+
const isMajor = ((n % subdivisions) + subdivisions) % subdivisions === 0;
|
|
98
|
+
emit(pos, isMajor);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** Largest stroke weight across the layers of a resolved stroke array. Used to
|
|
102
|
+
* overscan the tiling so a thick line stays drawn until fully off the area. */
|
|
103
|
+
export function maxWeight(strokes) {
|
|
104
|
+
let max = 0;
|
|
105
|
+
for (const s of strokes)
|
|
106
|
+
if (s.weight > max)
|
|
107
|
+
max = s.weight;
|
|
108
|
+
return max;
|
|
109
|
+
}
|
|
110
|
+
/** Force every layer of a resolved stroke array to centered alignment. Grid
|
|
111
|
+
* lines are open paths, not a closed region, so inside/outside alignment is
|
|
112
|
+
* meaningless — they always straddle their position. (Open paths are already
|
|
113
|
+
* stroked centered by the renderer; this makes the intent explicit and ignores
|
|
114
|
+
* any author `align`.) */
|
|
115
|
+
export function centered(strokes) {
|
|
116
|
+
return strokes.map(s => (s.align === 0 ? s : { ...s, align: 0 }));
|
|
117
|
+
}
|
|
118
|
+
/** Copy a resolved stroke array with every fill layer's opacity scaled by
|
|
119
|
+
* `factor`. Used to derive the default minor-line stroke from the major one.
|
|
120
|
+
* Every resolved fill carries an `opacity` field, so this is type-uniform. */
|
|
121
|
+
export function dimStroke(strokes, factor) {
|
|
122
|
+
return strokeOps.resolve(strokes.map(s => ({
|
|
123
|
+
...s,
|
|
124
|
+
fill: s.fill.map(f => ({ ...f, opacity: (f.opacity ?? 1) * factor })),
|
|
125
|
+
})));
|
|
126
|
+
}
|
|
127
|
+
const SUB_STROKES = new WeakMap();
|
|
128
|
+
/**
|
|
129
|
+
* The minor-line stroke of a pattern built with a `stroke` and no `subStroke`:
|
|
130
|
+
* the major one at half opacity, when it was built with minor lines. Read off
|
|
131
|
+
* what the pattern was built with (`given`), so it is not kept in step with a
|
|
132
|
+
* stroke written later.
|
|
133
|
+
*/
|
|
134
|
+
export function defaultSubStroke(given) {
|
|
135
|
+
let sub = SUB_STROKES.get(given);
|
|
136
|
+
if (!sub) {
|
|
137
|
+
const stroke = valueOf(given.stroke);
|
|
138
|
+
const subdivisions = valueOf(given.subdivisions) ?? 1;
|
|
139
|
+
sub = stroke !== undefined && subdivisions > 1 ? dimStroke(strokeOps.resolve(stroke), 0.5) : [];
|
|
140
|
+
SUB_STROKES.set(given, sub);
|
|
141
|
+
}
|
|
142
|
+
return sub;
|
|
143
|
+
}
|
|
144
|
+
/** A prop as it stood when given: a binding read once. */
|
|
145
|
+
function valueOf(prop) {
|
|
146
|
+
return typeof prop === "function" ? prop() : prop;
|
|
147
|
+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AC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAChG,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AAED,0DAA0D;AAC1D,SAAS,OAAO,CAAC,IAAa;IAC1B,OAAO,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC,CAAE,IAAsB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACzE,CAAC","sourcesContent":["import { strokeOps, type PathCommand, type Stroke, type StrokeProp, type StrokeResolved } from \"@motionscript/sdk\";\n\n/**\n * Shared geometry for line grids. Both {@link LineGridPattern} (a fixed grid filling\n * its layout rect) and {@link GridPattern} (an infinite grid tiled across the\n * camera's visible region) build the same multi-subpath line paths from these\n * helpers — they differ only in how the extent and step are chosen.\n *\n * Lines are tiled by the minor step and panned by an origin offset: every\n * position within the extent (grown by `overscan` so thick lines clip out\n * smoothly) is emitted regardless of the offset, so the area always stays full\n * and animating the offset scrolls the grid. The lattice starts at the axis's\n * `anchor` (the world origin unless it says otherwise). A tile whose index\n * aligns to the division grid is major; the rest are minor. Each is built as a\n * single multi-subpath path so the trailing stroke paints every line as one\n * union with no destructive boolean op (which would erase the open lines).\n */\n\n/** A grid extent on one axis: lines tile within `[min, max]`, on a lattice that starts at `anchor`. */\nexport interface GridAxis {\n /** Minimum coordinate (typically negative). */\n min: number;\n /** Maximum coordinate. */\n max: number;\n /** Spacing between adjacent (minor) lines. */\n step: number;\n /** Pan offset in pixels along this axis. */\n offset: number;\n /**\n * Where the lattice starts: a line sits at `anchor + n * step`, and the tile\n * index `n` that decides which lines are major counts from there. Omitted it is 0, the\n * world origin, which is what a grid that follows a camera keeps. A grid with a box of its\n * own sets it to `min`, so the box's edges are lines whatever the count of cells.\n */\n anchor?: number;\n}\n\n/** The resolved grid: where each line sits and how far it runs. Vertical lines\n * sit at x = `verticalX[i]` and run from `top` to `bottom`; horizontal lines sit\n * at y = `horizontalY[i]` and run from `left` to `right`. Positions are split\n * into major (division) and minor (subdivision) lines. */\nexport interface GridLines {\n /** y-extent every vertical line spans. */\n top: number;\n bottom: number;\n /** x-extent every horizontal line spans. */\n left: number;\n right: number;\n verticalMajor: number[];\n verticalMinor: number[];\n horizontalMajor: number[];\n horizontalMinor: number[];\n}\n\n/**\n * Resolve the grid for the given per-axis extents: the cross-axis span and the\n * major/minor line positions on each axis. Vertical lines span the full y\n * extent; horizontal lines span the full x extent. Both spans are grown by\n * `overscan` so a thick line slides out under the clip instead of popping, and\n * snapped outward to the grid so the endpoints sit on stable world positions\n * (a line's start stays fixed as the camera pans, so a dashed stroke anchored to\n * it doesn't crawl).\n *\n * `cycle` (the dash period, when dashed) snaps the cross-axis span to a whole\n * number of dash cycles too, so each parallel line is the same dash-aligned\n * length and the renderer's per-path dash-fit becomes a no-op (no per-frame\n * resizing of the dashes as lines enter and leave view).\n */\nexport function gridLines(\n x: GridAxis,\n y: GridAxis,\n subdivisions: number,\n overscan: number,\n cycle = 0,\n): GridLines {\n const verticalMajor: number[] = [];\n const verticalMinor: number[] = [];\n const horizontalMajor: number[] = [];\n const horizontalMinor: number[] = [];\n\n // Span each line across the cross axis, snapped outward to the grid (and to\n // the dash cycle when dashed) so the endpoints sit on stable world positions.\n const top = snapSpan(y.min - overscan, y.step, y.offset, cycle, Math.floor);\n const bottom = snapSpan(y.max + overscan, y.step, y.offset, cycle, Math.ceil);\n const left = snapSpan(x.min - overscan, x.step, x.offset, cycle, Math.floor);\n const right = snapSpan(x.max + overscan, x.step, x.offset, cycle, Math.ceil);\n\n addTiledLines(x.min, x.max, x.step, x.offset, subdivisions, overscan, (px, isMajor) => {\n (isMajor ? verticalMajor : verticalMinor).push(px);\n }, x.anchor);\n addTiledLines(y.min, y.max, y.step, y.offset, subdivisions, overscan, (py, isMajor) => {\n (isMajor ? horizontalMajor : horizontalMinor).push(py);\n }, y.anchor);\n\n return { top, bottom, left, right, verticalMajor, verticalMinor, horizontalMajor, horizontalMinor };\n}\n\n/**\n * Build the grid lines as multi-subpath path commands, split into the major\n * (division) lines and the minor (subdivision) lines, for the given per-axis\n * extents. Every line in a group shares one stroke (drawn as one union path), so\n * this is the path for solid strokes; dashed strokes that must stay world-locked\n * draw per line from {@link gridLines} instead.\n */\nexport function gridLinePaths(\n x: GridAxis,\n y: GridAxis,\n subdivisions: number,\n overscan: number,\n): { major: PathCommand[]; minor: PathCommand[] } {\n const g = gridLines(x, y, subdivisions, overscan);\n const major: PathCommand[] = [];\n const minor: PathCommand[] = [];\n for (const px of g.verticalMajor) major.push({ type: \"M\", x: px, y: g.top }, { type: \"L\", x: px, y: g.bottom });\n for (const px of g.verticalMinor) minor.push({ type: \"M\", x: px, y: g.top }, { type: \"L\", x: px, y: g.bottom });\n for (const py of g.horizontalMajor) major.push({ type: \"M\", x: g.left, y: py }, { type: \"L\", x: g.right, y: py });\n for (const py of g.horizontalMinor) minor.push({ type: \"M\", x: g.left, y: py }, { type: \"L\", x: g.right, y: py });\n return { major, minor };\n}\n\n// Snap `pos` outward to a stable world position so a dashed line's start stays\n// fixed as the viewport moves (the renderer anchors dash phase to the subpath\n// start). Snap to the grid line lattice (`n*step + offset`); when a dash `cycle`\n// is given, snap to the dash lattice instead (`n*cycle`, anchored to world 0) so\n// every parallel line is the same whole number of cycles long and the renderer's\n// per-path dash-fit stays a no-op. `round` is `Math.floor` to snap below, `ceil`\n// to snap above. The lattice is the one about 0 whatever an axis's `anchor`: a span\n// only has to reach past the edge, and a line's ends stay where they always were.\nfunction snapSpan(pos: number, step: number, offset: number, cycle: number, round: (n: number) => number): number {\n if (cycle > 0) return round(pos / cycle) * cycle;\n if (step <= 0) return pos;\n return round((pos - offset) / step) * step + offset;\n}\n\n/**\n * Emit every grid line position in `[min, max]` (grown by `overscan` on each\n * end) for a grid of spacing `step`, panned by `offset` px. Without panning the\n * lattice starts at `anchor` (0 unless given) and its tile indices count outward\n * from there; the line at tile index `n` is major when `n` is a multiple of\n * `subdivisions`. The pan shifts each position by `offset` while keeping the\n * area full, so `n` is taken relative to the un-panned lattice (offset folded\n * out) to keep classification stable as it scrolls.\n *\n * A fixed grid anchors at `min`, so its first line is on the box's edge and the\n * last is too whenever the extent is a whole number of steps. An infinite grid\n * keeps the default, so its lines stay on the world's lattice.\n */\nexport function addTiledLines(\n min: number,\n max: number,\n step: number,\n offset: number,\n subdivisions: number,\n overscan: number,\n emit: (pos: number, isMajor: boolean) => void,\n anchor = 0,\n): void {\n if (step <= 0) return;\n // First/last tile index whose panned position is within the overscanned\n // [min, max]. Positions are `anchor + n*step + offset` (n=0 sits on the\n // anchor). A small epsilon keeps a line that lands exactly on an edge (an\n // anchor at `min`, or a world lattice that reaches it) from being dropped by FP error.\n const eps = step * 1e-6;\n const startN = Math.ceil((min - overscan - offset - anchor - eps) / step);\n const endN = Math.floor((max + overscan - offset - anchor + eps) / step);\n for (let n = startN; n <= endN; n++) {\n const pos = anchor + n * step + offset;\n // mod that stays non-negative for negative n.\n const isMajor = ((n % subdivisions) + subdivisions) % subdivisions === 0;\n emit(pos, isMajor);\n }\n}\n\n/** Largest stroke weight across the layers of a resolved stroke array. Used to\n * overscan the tiling so a thick line stays drawn until fully off the area. */\nexport function maxWeight(strokes: StrokeResolved[]): number {\n let max = 0;\n for (const s of strokes) if (s.weight > max) max = s.weight;\n return max;\n}\n\n/** Force every layer of a resolved stroke array to centered alignment. Grid\n * lines are open paths, not a closed region, so inside/outside alignment is\n * meaningless — they always straddle their position. (Open paths are already\n * stroked centered by the renderer; this makes the intent explicit and ignores\n * any author `align`.) */\nexport function centered(strokes: StrokeResolved[]): StrokeResolved[] {\n return strokes.map(s => (s.align === 0 ? s : { ...s, align: 0 }));\n}\n\n/** Copy a resolved stroke array with every fill layer's opacity scaled by\n * `factor`. Used to derive the default minor-line stroke from the major one.\n * Every resolved fill carries an `opacity` field, so this is type-uniform. */\nexport function dimStroke(strokes: StrokeResolved[], factor: number): StrokeResolved[] {\n return strokeOps.resolve(strokes.map(s => ({\n ...s,\n fill: s.fill.map(f => ({ ...f, opacity: (f.opacity ?? 1) * factor })),\n })) as unknown as StrokeProp[]);\n}\n\nconst SUB_STROKES = new WeakMap<object, StrokeResolved[]>();\n\n/**\n * The minor-line stroke of a pattern built with a `stroke` and no `subStroke`:\n * the major one at half opacity, when it was built with minor lines. Read off\n * what the pattern was built with (`given`), so it is not kept in step with a\n * stroke written later.\n */\nexport function defaultSubStroke(given: Readonly<Record<string, unknown>>): StrokeResolved[] {\n let sub = SUB_STROKES.get(given);\n if (!sub) {\n const stroke = valueOf(given.stroke) as Stroke | undefined;\n const subdivisions = (valueOf(given.subdivisions) as number | undefined) ?? 1;\n sub = stroke !== undefined && subdivisions > 1 ? dimStroke(strokeOps.resolve(stroke), 0.5) : [];\n SUB_STROKES.set(given, sub);\n }\n return sub;\n}\n\n/** A prop as it stood when given: a binding read once. */\nfunction valueOf(prop: unknown): unknown {\n return typeof prop === \"function\" ? (prop as () => unknown)() : prop;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/kit/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,OAAO,KAAK,eAAe,MAAM,oBAAoB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/kit/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,OAAO,KAAK,eAAe,MAAM,oBAAoB,CAAA","sourcesContent":["export * from \"./grid-lines\"\nexport * as ViewportPattern from \"./viewport-pattern\"\n"]}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Flow, Paint, type BoxBounds, type ChildView, type Measurer, type Placement2D, type RenderContext, type Size2D, type Values, 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 Shadow as _Shadow, type ShadowResolved as _ShadowResolved, type Stroke as _Stroke, type StrokeResolved as _StrokeResolved, type Vector2 as _Vector2 } from "@motionscript/sdk";
|
|
2
|
+
/**
|
|
3
|
+
* What a background that fills whatever region is currently visible shares,
|
|
4
|
+
* rather than a fixed rect: `GridPattern` is built from it, and so is a pattern
|
|
5
|
+
* of your own. Spread `state` and `commands` in, pass `measure` and `layout`, and
|
|
6
|
+
* draw with {@link draw}.
|
|
7
|
+
*
|
|
8
|
+
* Placed inside a `Camera`, the pattern is handed the world region the camera
|
|
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.
|
|
18
|
+
*/
|
|
19
|
+
/** A pattern is a shape: paints, and children laid out like a rect's. */
|
|
20
|
+
export declare const state: {
|
|
21
|
+
flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
|
|
22
|
+
gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
|
|
23
|
+
wrap: boolean;
|
|
24
|
+
crossGap: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
|
|
25
|
+
columns: import("@motionscript/sdk").Type<number, number, false>;
|
|
26
|
+
align: import("@motionscript/sdk").Attribute<_Alignment, _Vector2>;
|
|
27
|
+
fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
28
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
29
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
30
|
+
overlay: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
31
|
+
start: import("@motionscript/sdk").Type<number, number, false>;
|
|
32
|
+
end: import("@motionscript/sdk").Type<number, number, false>;
|
|
33
|
+
};
|
|
34
|
+
export declare const commands: {
|
|
35
|
+
fillTo: {
|
|
36
|
+
readonly args: readonly ["fill"];
|
|
37
|
+
readonly run?: undefined;
|
|
38
|
+
};
|
|
39
|
+
strokeTo: {
|
|
40
|
+
readonly args: readonly ["stroke"];
|
|
41
|
+
readonly run?: undefined;
|
|
42
|
+
};
|
|
43
|
+
shadowTo: {
|
|
44
|
+
readonly args: readonly ["shadow"];
|
|
45
|
+
readonly run?: undefined;
|
|
46
|
+
};
|
|
47
|
+
overlayTo: {
|
|
48
|
+
readonly args: readonly ["overlay"];
|
|
49
|
+
readonly run?: undefined;
|
|
50
|
+
};
|
|
51
|
+
progressTo: {
|
|
52
|
+
readonly args: readonly ["start", "end"];
|
|
53
|
+
readonly run?: undefined;
|
|
54
|
+
};
|
|
55
|
+
flash: {
|
|
56
|
+
readonly args: {
|
|
57
|
+
readonly portion: import("@motionscript/sdk").Type<number, number, false>;
|
|
58
|
+
};
|
|
59
|
+
run(timeline: any, state: any, children: any): import("@motionscript/sdk").Piece;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
type ShapeState = Flow.FlowState & Values<typeof Paint.state>;
|
|
63
|
+
export declare function measure(measurer: Measurer, s: ShapeState, children: readonly ChildView[]): Size2D;
|
|
64
|
+
export declare function layout(box: BoxBounds, s: ShapeState, children: readonly ChildView[]): readonly Placement2D[];
|
|
65
|
+
/**
|
|
66
|
+
* The region the pattern covers, in its own draw space: the world rect the
|
|
67
|
+
* nearest `Camera` above it sees, or its own box when there is none.
|
|
68
|
+
*/
|
|
69
|
+
export declare function visibleBounds(ctx: RenderContext): BoxBounds;
|
|
70
|
+
/**
|
|
71
|
+
* Paint `pattern` over the visible region, once per render, then the children.
|
|
72
|
+
*
|
|
73
|
+
* The pattern is clipped to the region, so geometry overscanned past the edge
|
|
74
|
+
* (so thick lines slide out instead of popping) trims cleanly. Inside a camera
|
|
75
|
+
* the viewport already clips, but this keeps edge strokes clean and bounds the
|
|
76
|
+
* work with no camera too. A `centerBounds` for a path drawn here is
|
|
77
|
+
* `[bounds.x - w/2, bounds.y - h/2, bounds.x + w/2, bounds.y + h/2]`.
|
|
78
|
+
*/
|
|
79
|
+
export declare function draw(ctx: RenderContext, pattern: (bounds: BoxBounds) => void): void;
|
|
80
|
+
export {};
|
|
81
|
+
//# sourceMappingURL=viewport-pattern.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"viewport-pattern.d.ts","sourceRoot":"","sources":["../../src/kit/viewport-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,IAAI,EAEJ,KAAK,EACL,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,MAAM,EACX,KAAK,MAAM,EAEX,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,cAAc,IAAI,eAAe,EACtC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACtC,KAAK,OAAO,IAAI,QAAQ,EAC3B,MAAM,mBAAmB,CAAC;AAE3B;;;;;;;;;;;;;;;;GAgBG;AAEH,yEAAyE;AACzE,eAAO,MAAM,KAAK;;;;;;;;;;;;;CAAoC,CAAC;AAEvD,eAAO,MAAM,QAAQ;;;oBAToB,CAAA;;;;oBAC4B,CAAC;;;;oBAE9C,CAAC;;;;oBAG+C,CAAC;;;;oBAK9D,CAAC;;;;;;;;CAFiC,CAAC;AAE9C,KAAK,UAAU,GAAG,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC;AAE9D,wBAAgB,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,SAAS,EAAE,GAAG,MAAM,CAEjG;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,SAAS,EAAE,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,WAAW,EAAE,CAE5G;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,aAAa,GAAG,SAAS,CA6B3D;AAED;;;;;;;;GAQG;AACH,wBAAgB,IAAI,CAAC,GAAG,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,IAAI,GAAG,IAAI,CAKnF"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Camera, Flow, Graphics2D, Paint, } from "@motionscript/sdk";
|
|
2
|
+
/**
|
|
3
|
+
* What a background that fills whatever region is currently visible shares,
|
|
4
|
+
* rather than a fixed rect: `GridPattern` is built from it, and so is a pattern
|
|
5
|
+
* of your own. Spread `state` and `commands` in, pass `measure` and `layout`, and
|
|
6
|
+
* draw with {@link draw}.
|
|
7
|
+
*
|
|
8
|
+
* Placed inside a `Camera`, the pattern is handed the world region the camera
|
|
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.
|
|
18
|
+
*/
|
|
19
|
+
/** A pattern is a shape: paints, and children laid out like a rect's. */
|
|
20
|
+
export const state = { ...Paint.state, ...Flow.state };
|
|
21
|
+
export const commands = { ...Paint.commands };
|
|
22
|
+
export function measure(measurer, s, children) {
|
|
23
|
+
return Flow.measure(measurer, s, children, Paint.inset(s));
|
|
24
|
+
}
|
|
25
|
+
export function layout(box, s, children) {
|
|
26
|
+
return Flow.layout(box, s, children, Paint.inset(s));
|
|
27
|
+
}
|
|
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
|
+
*/
|
|
32
|
+
export function visibleBounds(ctx) {
|
|
33
|
+
const camera = ctx.ancestor(Camera);
|
|
34
|
+
if (!camera)
|
|
35
|
+
return { x: 0, y: 0, width: ctx.size.width, height: ctx.size.height };
|
|
36
|
+
const { width: vw, height: vh } = camera.size;
|
|
37
|
+
const zoom = camera.state.zoom || 1;
|
|
38
|
+
const heading = camera.state.heading;
|
|
39
|
+
// Inverse of the camera scale: a viewport `vw×vh` shows `vw/zoom × vh/zoom` of the world.
|
|
40
|
+
const hw = vw / 2 / zoom;
|
|
41
|
+
const hh = vh / 2 / zoom;
|
|
42
|
+
// With a heading the visible world rect is rotated; take its axis-aligned
|
|
43
|
+
// bounding box so the pattern covers the rotated viewport's full extent.
|
|
44
|
+
let bw = hw;
|
|
45
|
+
let bh = hh;
|
|
46
|
+
if (heading !== 0) {
|
|
47
|
+
const rad = (heading * Math.PI) / 180;
|
|
48
|
+
const cos = Math.abs(Math.cos(rad));
|
|
49
|
+
const sin = Math.abs(Math.sin(rad));
|
|
50
|
+
bw = hw * cos + hh * sin;
|
|
51
|
+
bh = hw * sin + hh * cos;
|
|
52
|
+
}
|
|
53
|
+
// Centred on the camera's `lookAt`, in y-up world space (the descriptor
|
|
54
|
+
// convention; the renderer applies the single y-up→canvas flip when the
|
|
55
|
+
// pattern's shapes are drawn).
|
|
56
|
+
const lookAt = camera.state.lookAt;
|
|
57
|
+
return { x: lookAt.x, y: lookAt.y, width: bw * 2, height: bh * 2 };
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Paint `pattern` over the visible region, once per render, then the children.
|
|
61
|
+
*
|
|
62
|
+
* The pattern is clipped to the region, so geometry overscanned past the edge
|
|
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]`.
|
|
67
|
+
*/
|
|
68
|
+
export function draw(ctx, pattern) {
|
|
69
|
+
const bounds = visibleBounds(ctx);
|
|
70
|
+
const region = new Graphics2D().rect({ x: bounds.x, y: bounds.y, width: bounds.width, height: bounds.height });
|
|
71
|
+
ctx.inFront(() => ctx.clip(region, () => pattern(bounds)));
|
|
72
|
+
ctx.children();
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=viewport-pattern.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"viewport-pattern.js","sourceRoot":"","sources":["../../src/kit/viewport-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,MAAM,EACN,IAAI,EACJ,UAAU,EACV,KAAK,GAoBR,MAAM,mBAAmB,CAAC;AAE3B;;;;;;;;;;;;;;;;GAgBG;AAEH,yEAAyE;AACzE,MAAM,CAAC,MAAM,KAAK,GAAG,EAAE,GAAG,KAAK,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;AAEvD,MAAM,CAAC,MAAM,QAAQ,GAAG,EAAE,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;AAI9C,MAAM,UAAU,OAAO,CAAC,QAAkB,EAAE,CA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type BoxBounds,\n type ChildView,\n type Measurer,\n type Placement2D,\n type RenderContext,\n type Size2D,\n type Values,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Alignment as _Alignment,\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type FlowMode as _FlowMode,\n type FlowResolved as _FlowResolved,\n type GapSize as _GapSize,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n type Vector2 as _Vector2,\n} from \"@motionscript/sdk\";\n\n/**\n * What a background that fills whatever region is currently visible shares,\n * rather than a fixed rect: `GridPattern` is built from it, and so is a pattern\n * of your own. Spread `state` and `commands` in, pass `measure` and `layout`, and\n * draw with {@link draw}.\n *\n * Placed inside a `Camera`, the pattern is handed the world region the camera\n * can currently see (from its `zoom`/`lookAt`/`heading`), so it only ever\n * generates geometry for what's on screen, with no oversized node sized for the\n * worst-case pan and zoom. With no `Camera` above it, it fills its own box, so the\n * same pattern doubles as an ordinary full-bleed background.\n *\n * The pattern is itself a camera child, laid out at the camera's centre, so its\n * local draw space shares the world origin its siblings use. The visible region\n * is therefore expressed directly in that space: centred on the camera's\n * `lookAt`, sized to the inverse of the camera transform.\n */\n\n/** A pattern is a shape: paints, and children laid out like a rect's. */\nexport const state = { ...Paint.state, ...Flow.state };\n\nexport const commands = { ...Paint.commands };\n\ntype ShapeState = Flow.FlowState & Values<typeof Paint.state>;\n\nexport function measure(measurer: Measurer, s: ShapeState, children: readonly ChildView[]): Size2D {\n return Flow.measure(measurer, s, children, Paint.inset(s));\n}\n\nexport function layout(box: BoxBounds, s: ShapeState, children: readonly ChildView[]): readonly Placement2D[] {\n return Flow.layout(box, s, children, Paint.inset(s));\n}\n\n/**\n * The region the pattern covers, in its own draw space: the world rect the\n * nearest `Camera` above it sees, or its own box when there is none.\n */\nexport function visibleBounds(ctx: RenderContext): BoxBounds {\n const camera = ctx.ancestor(Camera);\n if (!camera) return { x: 0, y: 0, width: ctx.size.width, height: ctx.size.height };\n\n const { width: vw, height: vh } = camera.size;\n const zoom = camera.state.zoom || 1;\n const heading = camera.state.heading;\n\n // Inverse of the camera scale: a viewport `vw×vh` shows `vw/zoom × vh/zoom` of the world.\n const hw = vw / 2 / zoom;\n const hh = vh / 2 / zoom;\n\n // With a heading the visible world rect is rotated; take its axis-aligned\n // bounding box so the pattern covers the rotated viewport's full extent.\n let bw = hw;\n let bh = hh;\n if (heading !== 0) {\n const rad = (heading * Math.PI) / 180;\n const cos = Math.abs(Math.cos(rad));\n const sin = Math.abs(Math.sin(rad));\n bw = hw * cos + hh * sin;\n bh = hw * sin + hh * cos;\n }\n\n // Centred on the camera's `lookAt`, in y-up world space (the descriptor\n // convention; the renderer applies the single y-up→canvas flip when the\n // pattern's shapes are drawn).\n const lookAt = camera.state.lookAt;\n return { x: lookAt.x, y: lookAt.y, width: bw * 2, height: bh * 2 };\n}\n\n/**\n * Paint `pattern` over the visible region, once per render, then the children.\n *\n * The pattern is clipped to the region, so geometry overscanned past the edge\n * (so thick lines slide out instead of popping) trims cleanly. Inside a camera\n * the viewport already clips, but this keeps edge strokes clean and bounds the\n * work with no camera too. A `centerBounds` for a path drawn here is\n * `[bounds.x - w/2, bounds.y - h/2, bounds.x + w/2, bounds.y + h/2]`.\n */\nexport function draw(ctx: RenderContext, pattern: (bounds: BoxBounds) => void): void {\n const bounds = visibleBounds(ctx);\n const region = new Graphics2D().rect({ x: bounds.x, y: bounds.y, width: bounds.width, height: bounds.height });\n ctx.inFront(() => ctx.clip(region, () => pattern(bounds)));\n ctx.children();\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/line-grid-pattern/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/line-grid-pattern/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA","sourcesContent":["export * from \"./line-grid-pattern\"\n"]}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { type NodeOf, type Vector2, type Alignment as _Alignment, type Fill as _Fill, type FillResolved as _FillResolved, type FlowMode as _FlowMode, type FlowResolved as _FlowResolved, type GapSize as _GapSize, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Shadow as _Shadow, type ShadowResolved as _ShadowResolved, type Stroke as _Stroke, type StrokeResolved as _StrokeResolved } from "@motionscript/sdk";
|
|
2
|
+
/**
|
|
3
|
+
* A rectangular grid of lines filling the node's layout rect.
|
|
4
|
+
*
|
|
5
|
+
* `stroke` paints the major lines and `subStroke` the minor ones, each as a
|
|
6
|
+
* single union path. `fill` and `shadow` cover the whole rect, behind the lines.
|
|
7
|
+
*/
|
|
8
|
+
export declare const LineGridPattern: import("@motionscript/sdk").Component<"lineGridPattern", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
9
|
+
/** Cells along each axis: `divisions` of 4 draws 5 major lines per axis. */
|
|
10
|
+
readonly divisions: 4;
|
|
11
|
+
/** Finer cells each division is split into. 1 draws no minor lines; 2 adds one per division. */
|
|
12
|
+
readonly subdivisions: 1;
|
|
13
|
+
/** Stroke for the minor lines. Unset, the major `stroke` at half opacity when `subdivisions > 1`. */
|
|
14
|
+
readonly subStroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
15
|
+
/** Pans the grid. Lines wrap and tile, so the rect stays full while `offset` scrolls it. */
|
|
16
|
+
readonly offset: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
|
|
17
|
+
readonly flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
|
|
18
|
+
readonly gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
|
|
19
|
+
readonly wrap: boolean;
|
|
20
|
+
readonly crossGap: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
|
|
21
|
+
readonly columns: import("@motionscript/sdk").Type<number, number, false>;
|
|
22
|
+
readonly align: import("@motionscript/sdk").Attribute<_Alignment, Vector2>;
|
|
23
|
+
readonly fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
24
|
+
readonly stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
25
|
+
readonly shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
26
|
+
readonly overlay: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
27
|
+
readonly start: import("@motionscript/sdk").Type<number, number, false>;
|
|
28
|
+
readonly end: import("@motionscript/sdk").Type<number, number, false>;
|
|
29
|
+
}>, {
|
|
30
|
+
readonly fillTo: readonly ["fill"];
|
|
31
|
+
readonly strokeTo: readonly ["stroke"];
|
|
32
|
+
readonly shadowTo: readonly ["shadow"];
|
|
33
|
+
readonly overlayTo: readonly ["overlay"];
|
|
34
|
+
readonly progressTo: readonly ["start", "end"];
|
|
35
|
+
readonly flash: {
|
|
36
|
+
readonly portion: import("@motionscript/sdk").Type<number, number, false>;
|
|
37
|
+
};
|
|
38
|
+
}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
39
|
+
/** Cells along each axis: `divisions` of 4 draws 5 major lines per axis. */
|
|
40
|
+
readonly divisions: 4;
|
|
41
|
+
/** Finer cells each division is split into. 1 draws no minor lines; 2 adds one per division. */
|
|
42
|
+
readonly subdivisions: 1;
|
|
43
|
+
/** Stroke for the minor lines. Unset, the major `stroke` at half opacity when `subdivisions > 1`. */
|
|
44
|
+
readonly subStroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
45
|
+
/** Pans the grid. Lines wrap and tile, so the rect stays full while `offset` scrolls it. */
|
|
46
|
+
readonly offset: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
|
|
47
|
+
readonly flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
|
|
48
|
+
readonly gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
|
|
49
|
+
readonly wrap: boolean;
|
|
50
|
+
readonly crossGap: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
|
|
51
|
+
readonly columns: import("@motionscript/sdk").Type<number, number, false>;
|
|
52
|
+
readonly align: import("@motionscript/sdk").Attribute<_Alignment, Vector2>;
|
|
53
|
+
readonly fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
54
|
+
readonly stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
55
|
+
readonly shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
56
|
+
readonly overlay: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
57
|
+
readonly start: import("@motionscript/sdk").Type<number, number, false>;
|
|
58
|
+
readonly end: import("@motionscript/sdk").Type<number, number, false>;
|
|
59
|
+
}>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
60
|
+
/** Cells along each axis: `divisions` of 4 draws 5 major lines per axis. */
|
|
61
|
+
readonly divisions: 4;
|
|
62
|
+
/** Finer cells each division is split into. 1 draws no minor lines; 2 adds one per division. */
|
|
63
|
+
readonly subdivisions: 1;
|
|
64
|
+
/** Stroke for the minor lines. Unset, the major `stroke` at half opacity when `subdivisions > 1`. */
|
|
65
|
+
readonly subStroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
66
|
+
/** Pans the grid. Lines wrap and tile, so the rect stays full while `offset` scrolls it. */
|
|
67
|
+
readonly offset: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
|
|
68
|
+
readonly flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
|
|
69
|
+
readonly gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
|
|
70
|
+
readonly wrap: boolean;
|
|
71
|
+
readonly crossGap: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
|
|
72
|
+
readonly columns: import("@motionscript/sdk").Type<number, number, false>;
|
|
73
|
+
readonly align: import("@motionscript/sdk").Attribute<_Alignment, Vector2>;
|
|
74
|
+
readonly fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
75
|
+
readonly stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
76
|
+
readonly shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
77
|
+
readonly overlay: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
78
|
+
readonly start: import("@motionscript/sdk").Type<number, number, false>;
|
|
79
|
+
readonly end: import("@motionscript/sdk").Type<number, number, false>;
|
|
80
|
+
}>, {
|
|
81
|
+
readonly fillTo: readonly ["fill"];
|
|
82
|
+
readonly strokeTo: readonly ["stroke"];
|
|
83
|
+
readonly shadowTo: readonly ["shadow"];
|
|
84
|
+
readonly overlayTo: readonly ["overlay"];
|
|
85
|
+
readonly progressTo: readonly ["start", "end"];
|
|
86
|
+
readonly flash: {
|
|
87
|
+
readonly portion: import("@motionscript/sdk").Type<number, number, false>;
|
|
88
|
+
};
|
|
89
|
+
}, _Node2D<_Node2DProps>>>>;
|
|
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
|
+
//# sourceMappingURL=line-grid-pattern.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"line-grid-pattern.d.ts","sourceRoot":"","sources":["../../src/line-grid-pattern/line-grid-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,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,qGAAqG;;IAErG,4FAA4F;;;;;;;;;;;;;;;;;;;;;;;;IAN5F,4EAA4E;;IAE5E,gGAAgG;;IAEhG,qGAAqG;;IAErG,4FAA4F;;;;;;;;;;;;;;;IAN5F,4EAA4E;;IAE5E,gGAAgG;;IAEhG,qGAAqG;;IAErG,4FAA4F;;;;;;;;;;;;;;;;;;;;;;;2BAwClG,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,eAAe,CAAC,CAAC;AAC7D,6CAA6C;AAC7C,MAAM,MAAM,oBAAoB,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
|