@motionscript/patterns 0.1.0 → 0.1.1-alpha.0
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 +19 -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,11 +1,10 @@
|
|
|
1
1
|
import { Graphics2D, Types, component2d, lerpNumber, lerpVector2, } from "@motionscript/sdk";
|
|
2
|
-
import { centered, defaultSubStroke, gridLines, maxWeight, ViewportPattern } from "../kit/index.js";
|
|
2
|
+
import { centered, defaultSubStroke, gridLinePaths, gridLines, maxWeight, ViewportPattern } from "../kit/index.js";
|
|
3
3
|
/**
|
|
4
|
-
* An infinite line grid that fills the camera's visible region
|
|
5
|
-
* `LineGridPattern
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* camera it fills its own layout rect.
|
|
4
|
+
* An infinite line grid that fills the camera's visible region: like
|
|
5
|
+
* `LineGridPattern`, but it tiles a world-anchored grid (spacing `cellSize`)
|
|
6
|
+
* across what the nearest `Camera` sees, regenerated each frame. With no camera it
|
|
7
|
+
* fills its own layout rect.
|
|
9
8
|
*/
|
|
10
9
|
export const GridPattern = component2d({
|
|
11
10
|
key: "gridPattern",
|
|
@@ -29,8 +28,7 @@ export const GridPattern = component2d({
|
|
|
29
28
|
function drawGrid(ctx, s, bounds) {
|
|
30
29
|
const halfW = bounds.width / 2;
|
|
31
30
|
const halfH = bounds.height / 2;
|
|
32
|
-
// `bounds` is centred on (x, y) in y-up world space
|
|
33
|
-
// and the renderer applies the single flip.
|
|
31
|
+
// `bounds` is centred on (x, y) in y-up world space.
|
|
34
32
|
const left = bounds.x - halfW;
|
|
35
33
|
const right = bounds.x + halfW;
|
|
36
34
|
const top = bounds.y - halfH;
|
|
@@ -58,28 +56,23 @@ function drawGrid(ctx, s, bounds) {
|
|
|
58
56
|
drawGroup(ctx, xAxis, yAxis, subdivisions, overscan, major, true);
|
|
59
57
|
}
|
|
60
58
|
}
|
|
61
|
-
// A solid stroke paints the group as one union path. A dashed one draws each line on
|
|
62
|
-
//
|
|
63
|
-
// crawl as the camera pans or new lines scroll in.
|
|
59
|
+
// A solid stroke paints the group as one union path. A dashed one draws each line on its
|
|
60
|
+
// own, dash phase anchored to its world coordinate, so dashes never crawl as the camera pans.
|
|
64
61
|
function drawGroup(ctx, xAxis, yAxis, subdivisions, overscan, stroke, isMajor) {
|
|
65
|
-
// Each line spans a whole number of dash cycles, so the renderer's per-path dash-fit
|
|
66
|
-
// is a no-op and every line dashes identically.
|
|
67
|
-
const cycle = dashCycle(stroke);
|
|
68
|
-
const g = gridLines(xAxis, yAxis, subdivisions, overscan, cycle);
|
|
69
|
-
const verticals = isMajor ? g.verticalMajor : g.verticalMinor;
|
|
70
|
-
const horizontals = isMajor ? g.horizontalMajor : g.horizontalMinor;
|
|
71
62
|
// Symmetric centerBounds give a zero recentre offset, so local coordinates draw verbatim.
|
|
72
63
|
const centerBounds = [-1, -1, 1, 1];
|
|
64
|
+
const cycle = dashCycle(stroke);
|
|
73
65
|
if (cycle <= 0) {
|
|
74
|
-
const data = [];
|
|
75
|
-
for (const px of verticals)
|
|
76
|
-
data.push({ type: "M", x: px, y: g.top }, { type: "L", x: px, y: g.bottom });
|
|
77
|
-
for (const py of horizontals)
|
|
78
|
-
data.push({ type: "M", x: g.left, y: py }, { type: "L", x: g.right, y: py });
|
|
66
|
+
const data = gridLinePaths(xAxis, yAxis, subdivisions, overscan)[isMajor ? "major" : "minor"];
|
|
79
67
|
if (data.length > 0)
|
|
80
68
|
ctx.draw(new Graphics2D().path({ data, centerBounds }).stroke(stroke));
|
|
81
69
|
return;
|
|
82
70
|
}
|
|
71
|
+
// Each line spans a whole number of dash cycles, so the renderer's per-path dash-fit
|
|
72
|
+
// is a no-op and every line dashes identically.
|
|
73
|
+
const g = gridLines(xAxis, yAxis, subdivisions, overscan, cycle);
|
|
74
|
+
const verticals = isMajor ? g.verticalMajor : g.verticalMinor;
|
|
75
|
+
const horizontals = isMajor ? g.horizontalMajor : g.horizontalMinor;
|
|
83
76
|
for (const px of verticals) {
|
|
84
77
|
const data = [{ type: "M", x: px, y: g.top }, { type: "L", x: px, y: g.bottom }];
|
|
85
78
|
ctx.draw(new Graphics2D().path({ data, centerBounds }).stroke(phaseShift(stroke, g.top)));
|
|
@@ -101,8 +94,7 @@ function dashCycle(strokes) {
|
|
|
101
94
|
}
|
|
102
95
|
return cycle;
|
|
103
96
|
}
|
|
104
|
-
// `dashOffset` advances the pattern, so it is negated to
|
|
105
|
-
// infinite line would have at this world coordinate.
|
|
97
|
+
// `dashOffset` advances the pattern, so it is negated to give the phase one infinite line would have at this world coordinate.
|
|
106
98
|
function phaseShift(strokes, worldStart) {
|
|
107
99
|
return strokes.map(s => (s.dash && s.dash.length > 0)
|
|
108
100
|
? { ...s, dashOffset: (s.dashOffset ?? 0) - worldStart }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grid-pattern.js","sourceRoot":"","sources":["../../src/grid-pattern/grid-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,UAAU,EACV,KAAK,EACL,WAAW,EACX,UAAU,EACV,WAAW,GAmBd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAiB,MAAM,QAAQ,CAAC;AAE1G;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,WAAW,CAAC;IACnC,GAAG,EAAE,aAAa;IAClB,KAAK,EAAE;QACH,GAAG,eAAe,CAAC,KAAK;QACxB,0FAA0F;QAC1F,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAmB,GAAG,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;QACrE,iFAAiF;QACjF,YAAY,EAAE,CAAC;QACf,qGAAqG;QACrG,SAAS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AC,MAAM,GAAG,CAAC,CAAC;QACjD,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,GAAG,UAAU,EAAE;QACxD,CAAC,CAAC,CAAC,CAAC,CAAC;AACb,CAAC;AAED,2EAA2E;AAC3E,SAAS,YAAY,CAAC,IAAsB,EAAE,EAAoB,EAAE,CAAS;IACzE,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,EAAE,KAAK,QAAQ;QAAE,OAAO,UAAU,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IACvF,MAAM,CAAC,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACjE,MAAM,CAAC,GAAG,OAAO,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACzD,OAAO,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAChC,CAAC","sourcesContent":["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"]}
|
|
1
|
+
{"version":3,"file":"grid-pattern.js","sourceRoot":"","sources":["../../src/grid-pattern/grid-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,UAAU,EACV,KAAK,EACL,WAAW,EACX,UAAU,EACV,WAAW,GAmBd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,aAAa,EAAE,SAAS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AAC,UAAU,IAAI,CAAC,CAAC,GAAG,UAAU,EAAE;QACxD,CAAC,CAAC,CAAC,CAAC,CAAC;AACb,CAAC;AAED,2EAA2E;AAC3E,SAAS,YAAY,CAAC,IAAsB,EAAE,EAAoB,EAAE,CAAS;IACzE,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,EAAE,KAAK,QAAQ;QAAE,OAAO,UAAU,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IACvF,MAAM,CAAC,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACjE,MAAM,CAAC,GAAG,OAAO,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACzD,OAAO,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAChC,CAAC","sourcesContent":["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"]}
|
package/dist/kit/grid-lines.d.ts
CHANGED
|
@@ -1,46 +1,24 @@
|
|
|
1
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
2
|
/** A grid extent on one axis: lines tile within `[min, max]`, on a lattice that starts at `anchor`. */
|
|
18
3
|
export interface GridAxis {
|
|
19
|
-
/** Minimum coordinate (typically negative). */
|
|
20
4
|
min: number;
|
|
21
|
-
/** Maximum coordinate. */
|
|
22
5
|
max: number;
|
|
23
6
|
/** Spacing between adjacent (minor) lines. */
|
|
24
7
|
step: number;
|
|
25
|
-
/** Pan offset in pixels
|
|
8
|
+
/** Pan offset in pixels. */
|
|
26
9
|
offset: number;
|
|
27
10
|
/**
|
|
28
11
|
* 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
|
|
30
|
-
* world origin, which
|
|
31
|
-
* own sets it to `min`, so the box's edges are lines whatever the count
|
|
12
|
+
* index `n` that decides which lines are major counts from there. Omitted it is
|
|
13
|
+
* 0, the world origin, which a camera-following grid keeps. A grid with a box of
|
|
14
|
+
* its own sets it to `min`, so the box's edges are lines whatever the cell count.
|
|
32
15
|
*/
|
|
33
16
|
anchor?: number;
|
|
34
17
|
}
|
|
35
|
-
/**
|
|
36
|
-
|
|
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. */
|
|
18
|
+
/** Where each line sits, split into major (division) and minor (subdivision) lines. Vertical lines run `top` to `bottom`, horizontal ones `left` to `right`. */
|
|
19
|
+
interface GridLines {
|
|
41
20
|
top: number;
|
|
42
21
|
bottom: number;
|
|
43
|
-
/** x-extent every horizontal line spans. */
|
|
44
22
|
left: number;
|
|
45
23
|
right: number;
|
|
46
24
|
verticalMajor: number[];
|
|
@@ -49,57 +27,36 @@ export interface GridLines {
|
|
|
49
27
|
horizontalMinor: number[];
|
|
50
28
|
}
|
|
51
29
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
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).
|
|
30
|
+
* The cross-axis spans and the major/minor line positions per axis. Spans are
|
|
31
|
+
* grown by `overscan` so a thick line slides out under the clip instead of
|
|
32
|
+
* popping, and snapped outward so a line's start stays fixed as the camera pans
|
|
33
|
+
* (a dashed stroke anchored to it would otherwise crawl). `cycle`, the dash
|
|
34
|
+
* period, snaps the span to whole dash cycles too, so every parallel line is the
|
|
35
|
+
* same length and the renderer's per-path dash-fit is a no-op.
|
|
64
36
|
*/
|
|
65
37
|
export declare function gridLines(x: GridAxis, y: GridAxis, subdivisions: number, overscan: number, cycle?: number): GridLines;
|
|
66
38
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* draw per line from {@link gridLines} instead.
|
|
39
|
+
* The lines as one multi-subpath path per group (major, minor), so each stroke
|
|
40
|
+
* paints as a union with no destructive boolean op, which would erase open lines.
|
|
41
|
+
* For solid strokes; dashed strokes that must stay world-locked draw per line from
|
|
42
|
+
* {@link gridLines}.
|
|
72
43
|
*/
|
|
73
44
|
export declare function gridLinePaths(x: GridAxis, y: GridAxis, subdivisions: number, overscan: number): {
|
|
74
45
|
major: PathCommand[];
|
|
75
46
|
minor: PathCommand[];
|
|
76
47
|
};
|
|
77
48
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
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.
|
|
49
|
+
* Emits every line position in `[min, max]` (grown by `overscan`) for spacing
|
|
50
|
+
* `step`, panned by `offset`. The line at tile index `n`, counted from `anchor`,
|
|
51
|
+
* is major when `n` is a multiple of `subdivisions`; `n` is relative to the
|
|
52
|
+
* un-panned lattice, so classification stays stable as the grid scrolls.
|
|
89
53
|
*/
|
|
90
54
|
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
|
|
92
|
-
* overscan the tiling so a thick line stays drawn until fully off the area. */
|
|
55
|
+
/** Largest layer weight, to overscan the tiling so a thick line stays drawn until fully off the area. */
|
|
93
56
|
export declare function maxWeight(strokes: StrokeResolved[]): number;
|
|
94
|
-
/**
|
|
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`.) */
|
|
57
|
+
/** 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`. */
|
|
99
58
|
export declare function centered(strokes: StrokeResolved[]): StrokeResolved[];
|
|
100
|
-
/**
|
|
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. */
|
|
59
|
+
/** The default minor-line stroke is the major one with every fill's opacity scaled by `factor`. */
|
|
103
60
|
export declare function dimStroke(strokes: StrokeResolved[], factor: number): StrokeResolved[];
|
|
104
61
|
/**
|
|
105
62
|
* The minor-line stroke of a pattern built with a `stroke` and no `subStroke`:
|
|
@@ -108,4 +65,5 @@ export declare function dimStroke(strokes: StrokeResolved[], factor: number): St
|
|
|
108
65
|
* stroke written later.
|
|
109
66
|
*/
|
|
110
67
|
export declare function defaultSubStroke(given: Readonly<Record<string, unknown>>): StrokeResolved[];
|
|
68
|
+
export {};
|
|
111
69
|
//# sourceMappingURL=grid-lines.d.ts.map
|
|
@@ -1 +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
|
|
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,uGAAuG;AACvG,MAAM,WAAW,QAAQ;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,gKAAgK;AAChK,UAAU,SAAS;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,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;;;;;;;GAOG;AACH,wBAAgB,SAAS,CACrB,CAAC,EAAE,QAAQ,EACX,CAAC,EAAE,QAAQ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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).
|
|
3
|
+
* The cross-axis spans and the major/minor line positions per axis. Spans are
|
|
4
|
+
* grown by `overscan` so a thick line slides out under the clip instead of
|
|
5
|
+
* popping, and snapped outward so a line's start stays fixed as the camera pans
|
|
6
|
+
* (a dashed stroke anchored to it would otherwise crawl). `cycle`, the dash
|
|
7
|
+
* period, snaps the span to whole dash cycles too, so every parallel line is the
|
|
8
|
+
* same length and the renderer's per-path dash-fit is a no-op.
|
|
15
9
|
*/
|
|
16
10
|
export function gridLines(x, y, subdivisions, overscan, cycle = 0) {
|
|
17
11
|
const verticalMajor = [];
|
|
18
12
|
const verticalMinor = [];
|
|
19
13
|
const horizontalMajor = [];
|
|
20
14
|
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
15
|
const top = snapSpan(y.min - overscan, y.step, y.offset, cycle, Math.floor);
|
|
24
16
|
const bottom = snapSpan(y.max + overscan, y.step, y.offset, cycle, Math.ceil);
|
|
25
17
|
const left = snapSpan(x.min - overscan, x.step, x.offset, cycle, Math.floor);
|
|
@@ -33,11 +25,10 @@ export function gridLines(x, y, subdivisions, overscan, cycle = 0) {
|
|
|
33
25
|
return { top, bottom, left, right, verticalMajor, verticalMinor, horizontalMajor, horizontalMinor };
|
|
34
26
|
}
|
|
35
27
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* draw per line from {@link gridLines} instead.
|
|
28
|
+
* The lines as one multi-subpath path per group (major, minor), so each stroke
|
|
29
|
+
* paints as a union with no destructive boolean op, which would erase open lines.
|
|
30
|
+
* For solid strokes; dashed strokes that must stay world-locked draw per line from
|
|
31
|
+
* {@link gridLines}.
|
|
41
32
|
*/
|
|
42
33
|
export function gridLinePaths(x, y, subdivisions, overscan) {
|
|
43
34
|
const g = gridLines(x, y, subdivisions, overscan);
|
|
@@ -53,14 +44,11 @@ export function gridLinePaths(x, y, subdivisions, overscan) {
|
|
|
53
44
|
minor.push({ type: "M", x: g.left, y: py }, { type: "L", x: g.right, y: py });
|
|
54
45
|
return { major, minor };
|
|
55
46
|
}
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
//
|
|
59
|
-
// is
|
|
60
|
-
//
|
|
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.
|
|
47
|
+
// Snaps `pos` outward to a stable world position, since the renderer anchors dash
|
|
48
|
+
// phase to the subpath start. It snaps to the line lattice (`n*step + offset`), or
|
|
49
|
+
// to the dash lattice (`n*cycle`, anchored to world 0) when a `cycle` is given.
|
|
50
|
+
// The lattice is the one about 0 whatever an axis's `anchor`: a span only has to
|
|
51
|
+
// reach past the edge.
|
|
64
52
|
function snapSpan(pos, step, offset, cycle, round) {
|
|
65
53
|
if (cycle > 0)
|
|
66
54
|
return round(pos / cycle) * cycle;
|
|
@@ -69,37 +57,27 @@ function snapSpan(pos, step, offset, cycle, round) {
|
|
|
69
57
|
return round((pos - offset) / step) * step + offset;
|
|
70
58
|
}
|
|
71
59
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
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.
|
|
60
|
+
* Emits every line position in `[min, max]` (grown by `overscan`) for spacing
|
|
61
|
+
* `step`, panned by `offset`. The line at tile index `n`, counted from `anchor`,
|
|
62
|
+
* is major when `n` is a multiple of `subdivisions`; `n` is relative to the
|
|
63
|
+
* un-panned lattice, so classification stays stable as the grid scrolls.
|
|
83
64
|
*/
|
|
84
65
|
export function addTiledLines(min, max, step, offset, subdivisions, overscan, emit, anchor = 0) {
|
|
85
66
|
if (step <= 0)
|
|
86
67
|
return;
|
|
87
68
|
// First/last tile index whose panned position is within the overscanned
|
|
88
|
-
// [min, max].
|
|
89
|
-
// anchor). A small epsilon keeps a line that lands exactly on an edge (an
|
|
69
|
+
// [min, max]. A small epsilon keeps a line that lands exactly on an edge (an
|
|
90
70
|
// anchor at `min`, or a world lattice that reaches it) from being dropped by FP error.
|
|
91
71
|
const eps = step * 1e-6;
|
|
92
72
|
const startN = Math.ceil((min - overscan - offset - anchor - eps) / step);
|
|
93
73
|
const endN = Math.floor((max + overscan - offset - anchor + eps) / step);
|
|
94
74
|
for (let n = startN; n <= endN; n++) {
|
|
95
75
|
const pos = anchor + n * step + offset;
|
|
96
|
-
// mod that stays non-negative for negative n.
|
|
97
76
|
const isMajor = ((n % subdivisions) + subdivisions) % subdivisions === 0;
|
|
98
77
|
emit(pos, isMajor);
|
|
99
78
|
}
|
|
100
79
|
}
|
|
101
|
-
/** Largest
|
|
102
|
-
* overscan the tiling so a thick line stays drawn until fully off the area. */
|
|
80
|
+
/** Largest layer weight, to overscan the tiling so a thick line stays drawn until fully off the area. */
|
|
103
81
|
export function maxWeight(strokes) {
|
|
104
82
|
let max = 0;
|
|
105
83
|
for (const s of strokes)
|
|
@@ -107,17 +85,11 @@ export function maxWeight(strokes) {
|
|
|
107
85
|
max = s.weight;
|
|
108
86
|
return max;
|
|
109
87
|
}
|
|
110
|
-
/**
|
|
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`.) */
|
|
88
|
+
/** 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`. */
|
|
115
89
|
export function centered(strokes) {
|
|
116
90
|
return strokes.map(s => (s.align === 0 ? s : { ...s, align: 0 }));
|
|
117
91
|
}
|
|
118
|
-
/**
|
|
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. */
|
|
92
|
+
/** The default minor-line stroke is the major one with every fill's opacity scaled by `factor`. */
|
|
121
93
|
export function dimStroke(strokes, factor) {
|
|
122
94
|
return strokeOps.resolve(strokes.map(s => ({
|
|
123
95
|
...s,
|
|
@@ -141,7 +113,7 @@ export function defaultSubStroke(given) {
|
|
|
141
113
|
}
|
|
142
114
|
return sub;
|
|
143
115
|
}
|
|
144
|
-
/** A prop as
|
|
116
|
+
/** A prop as given, a binding read once. */
|
|
145
117
|
function valueOf(prop) {
|
|
146
118
|
return typeof prop === "function" ? prop() : prop;
|
|
147
119
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grid-lines.js","sourceRoot":"","sources":["../../src/kit/grid-lines.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAuE,MAAM,mBAAmB,CAAC;AAsDnH;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,SAAS,CACrB,CAAW,EACX,CAAW,EACX,YAAoB,EACpB,QAAgB,EAChB,KAAK,GAAG,CAAC;IAET,MAAM,aAAa,GAAa,EAAE,CAAC;IACnC,MAAM,aAAa,GAAa,EAAE,CAAC;IACnC,MAAM,eAAe,GAAa,EAAE,CAAC;IACrC,MAAM,eAAe,GAAa,EAAE,CAAC;IAErC,4EAA4E;IAC5E,8EAA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,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACvC,GAAG,CAAC;QACJ,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,GAAG,MAAM,EAAE,CAAC,CAAC;KACxE,CAAC,CAA4B,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,WAAW,GAAG,IAAI,OAAO,EAA4B,CAAC;AAE5D;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAwC;IACrE,IAAI,GAAG,GAAG,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACjC,IAAI,CAAC,GAAG,EAAE,CAAC;QACP,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAuB,CAAC;QAC3D,MAAM,YAAY,GAAI,OAAO,CAAC,KAAK,CAAC,YAAY,CAAwB,IAAI,CAAC,CAAC;QAC9E,GAAG,GAAG,MAAM,KAAK,SAAS,IAAI,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAChG,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AAED,0DAA0D;AAC1D,SAAS,OAAO,CAAC,IAAa;IAC1B,OAAO,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC,CAAE,IAAsB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACzE,CAAC","sourcesContent":["import { strokeOps, type PathCommand, type Stroke, type StrokeProp, type StrokeResolved } from \"@motionscript/sdk\";\n\n/**\n * Shared geometry for line grids. Both {@link LineGridPattern} (a fixed grid filling\n * its layout rect) and {@link GridPattern} (an infinite grid tiled across the\n * camera's visible region) build the same multi-subpath line paths from these\n * helpers — they differ only in how the extent and step are chosen.\n *\n * Lines are tiled by the minor step and panned by an origin offset: every\n * position within the extent (grown by `overscan` so thick lines clip out\n * smoothly) is emitted regardless of the offset, so the area always stays full\n * and animating the offset scrolls the grid. The lattice starts at the axis's\n * `anchor` (the world origin unless it says otherwise). A tile whose index\n * aligns to the division grid is major; the rest are minor. Each is built as a\n * single multi-subpath path so the trailing stroke paints every line as one\n * union with no destructive boolean op (which would erase the open lines).\n */\n\n/** A grid extent on one axis: lines tile within `[min, max]`, on a lattice that starts at `anchor`. */\nexport interface GridAxis {\n /** Minimum coordinate (typically negative). */\n min: number;\n /** Maximum coordinate. */\n max: number;\n /** Spacing between adjacent (minor) lines. */\n step: number;\n /** Pan offset in pixels along this axis. */\n offset: number;\n /**\n * Where the lattice starts: a line sits at `anchor + n * step`, and the tile\n * index `n` that decides which lines are major counts from there. Omitted it is 0, the\n * world origin, which is what a grid that follows a camera keeps. A grid with a box of its\n * own sets it to `min`, so the box's edges are lines whatever the count of cells.\n */\n anchor?: number;\n}\n\n/** The resolved grid: where each line sits and how far it runs. Vertical lines\n * sit at x = `verticalX[i]` and run from `top` to `bottom`; horizontal lines sit\n * at y = `horizontalY[i]` and run from `left` to `right`. Positions are split\n * into major (division) and minor (subdivision) lines. */\nexport interface GridLines {\n /** y-extent every vertical line spans. */\n top: number;\n bottom: number;\n /** x-extent every horizontal line spans. */\n left: number;\n right: number;\n verticalMajor: number[];\n verticalMinor: number[];\n horizontalMajor: number[];\n horizontalMinor: number[];\n}\n\n/**\n * Resolve the grid for the given per-axis extents: the cross-axis span and the\n * major/minor line positions on each axis. Vertical lines span the full y\n * extent; horizontal lines span the full x extent. Both spans are grown by\n * `overscan` so a thick line slides out under the clip instead of popping, and\n * snapped outward to the grid so the endpoints sit on stable world positions\n * (a line's start stays fixed as the camera pans, so a dashed stroke anchored to\n * it doesn't crawl).\n *\n * `cycle` (the dash period, when dashed) snaps the cross-axis span to a whole\n * number of dash cycles too, so each parallel line is the same dash-aligned\n * length and the renderer's per-path dash-fit becomes a no-op (no per-frame\n * resizing of the dashes as lines enter and leave view).\n */\nexport function gridLines(\n x: GridAxis,\n y: GridAxis,\n subdivisions: number,\n overscan: number,\n cycle = 0,\n): GridLines {\n const verticalMajor: number[] = [];\n const verticalMinor: number[] = [];\n const horizontalMajor: number[] = [];\n const horizontalMinor: number[] = [];\n\n // Span each line across the cross axis, snapped outward to the grid (and to\n // the dash cycle when dashed) so the endpoints sit on stable world positions.\n const top = snapSpan(y.min - overscan, y.step, y.offset, cycle, Math.floor);\n const bottom = snapSpan(y.max + overscan, y.step, y.offset, cycle, Math.ceil);\n const left = snapSpan(x.min - overscan, x.step, x.offset, cycle, Math.floor);\n const right = snapSpan(x.max + overscan, x.step, x.offset, cycle, Math.ceil);\n\n addTiledLines(x.min, x.max, x.step, x.offset, subdivisions, overscan, (px, isMajor) => {\n (isMajor ? verticalMajor : verticalMinor).push(px);\n }, x.anchor);\n addTiledLines(y.min, y.max, y.step, y.offset, subdivisions, overscan, (py, isMajor) => {\n (isMajor ? horizontalMajor : horizontalMinor).push(py);\n }, y.anchor);\n\n return { top, bottom, left, right, verticalMajor, verticalMinor, horizontalMajor, horizontalMinor };\n}\n\n/**\n * Build the grid lines as multi-subpath path commands, split into the major\n * (division) lines and the minor (subdivision) lines, for the given per-axis\n * extents. Every line in a group shares one stroke (drawn as one union path), so\n * this is the path for solid strokes; dashed strokes that must stay world-locked\n * draw per line from {@link gridLines} instead.\n */\nexport function gridLinePaths(\n x: GridAxis,\n y: GridAxis,\n subdivisions: number,\n overscan: number,\n): { major: PathCommand[]; minor: PathCommand[] } {\n const g = gridLines(x, y, subdivisions, overscan);\n const major: PathCommand[] = [];\n const minor: PathCommand[] = [];\n for (const px of g.verticalMajor) major.push({ type: \"M\", x: px, y: g.top }, { type: \"L\", x: px, y: g.bottom });\n for (const px of g.verticalMinor) minor.push({ type: \"M\", x: px, y: g.top }, { type: \"L\", x: px, y: g.bottom });\n for (const py of g.horizontalMajor) major.push({ type: \"M\", x: g.left, y: py }, { type: \"L\", x: g.right, y: py });\n for (const py of g.horizontalMinor) minor.push({ type: \"M\", x: g.left, y: py }, { type: \"L\", x: g.right, y: py });\n return { major, minor };\n}\n\n// Snap `pos` outward to a stable world position so a dashed line's start stays\n// fixed as the viewport moves (the renderer anchors dash phase to the subpath\n// start). Snap to the grid line lattice (`n*step + offset`); when a dash `cycle`\n// is given, snap to the dash lattice instead (`n*cycle`, anchored to world 0) so\n// every parallel line is the same whole number of cycles long and the renderer's\n// per-path dash-fit stays a no-op. `round` is `Math.floor` to snap below, `ceil`\n// to snap above. The lattice is the one about 0 whatever an axis's `anchor`: a span\n// only has to reach past the edge, and a line's ends stay where they always were.\nfunction snapSpan(pos: number, step: number, offset: number, cycle: number, round: (n: number) => number): number {\n if (cycle > 0) return round(pos / cycle) * cycle;\n if (step <= 0) return pos;\n return round((pos - offset) / step) * step + offset;\n}\n\n/**\n * Emit every grid line position in `[min, max]` (grown by `overscan` on each\n * end) for a grid of spacing `step`, panned by `offset` px. Without panning the\n * lattice starts at `anchor` (0 unless given) and its tile indices count outward\n * from there; the line at tile index `n` is major when `n` is a multiple of\n * `subdivisions`. The pan shifts each position by `offset` while keeping the\n * area full, so `n` is taken relative to the un-panned lattice (offset folded\n * out) to keep classification stable as it scrolls.\n *\n * A fixed grid anchors at `min`, so its first line is on the box's edge and the\n * last is too whenever the extent is a whole number of steps. An infinite grid\n * keeps the default, so its lines stay on the world's lattice.\n */\nexport function addTiledLines(\n min: number,\n max: number,\n step: number,\n offset: number,\n subdivisions: number,\n overscan: number,\n emit: (pos: number, isMajor: boolean) => void,\n anchor = 0,\n): void {\n if (step <= 0) return;\n // First/last tile index whose panned position is within the overscanned\n // [min, max]. Positions are `anchor + n*step + offset` (n=0 sits on the\n // anchor). A small epsilon keeps a line that lands exactly on an edge (an\n // anchor at `min`, or a world lattice that reaches it) from being dropped by FP error.\n const eps = step * 1e-6;\n const startN = Math.ceil((min - overscan - offset - anchor - eps) / step);\n const endN = Math.floor((max + overscan - offset - anchor + eps) / step);\n for (let n = startN; n <= endN; n++) {\n const pos = anchor + n * step + offset;\n // mod that stays non-negative for negative n.\n const isMajor = ((n % subdivisions) + subdivisions) % subdivisions === 0;\n emit(pos, isMajor);\n }\n}\n\n/** Largest stroke weight across the layers of a resolved stroke array. Used to\n * overscan the tiling so a thick line stays drawn until fully off the area. */\nexport function maxWeight(strokes: StrokeResolved[]): number {\n let max = 0;\n for (const s of strokes) if (s.weight > max) max = s.weight;\n return max;\n}\n\n/** Force every layer of a resolved stroke array to centered alignment. Grid\n * lines are open paths, not a closed region, so inside/outside alignment is\n * meaningless — they always straddle their position. (Open paths are already\n * stroked centered by the renderer; this makes the intent explicit and ignores\n * any author `align`.) */\nexport function centered(strokes: StrokeResolved[]): StrokeResolved[] {\n return strokes.map(s => (s.align === 0 ? s : { ...s, align: 0 }));\n}\n\n/** Copy a resolved stroke array with every fill layer's opacity scaled by\n * `factor`. Used to derive the default minor-line stroke from the major one.\n * Every resolved fill carries an `opacity` field, so this is type-uniform. */\nexport function dimStroke(strokes: StrokeResolved[], factor: number): StrokeResolved[] {\n return strokeOps.resolve(strokes.map(s => ({\n ...s,\n fill: s.fill.map(f => ({ ...f, opacity: (f.opacity ?? 1) * factor })),\n })) as unknown as StrokeProp[]);\n}\n\nconst SUB_STROKES = new WeakMap<object, StrokeResolved[]>();\n\n/**\n * The minor-line stroke of a pattern built with a `stroke` and no `subStroke`:\n * the major one at half opacity, when it was built with minor lines. Read off\n * what the pattern was built with (`given`), so it is not kept in step with a\n * stroke written later.\n */\nexport function defaultSubStroke(given: Readonly<Record<string, unknown>>): StrokeResolved[] {\n let sub = SUB_STROKES.get(given);\n if (!sub) {\n const stroke = valueOf(given.stroke) as Stroke | undefined;\n const subdivisions = (valueOf(given.subdivisions) as number | undefined) ?? 1;\n sub = stroke !== undefined && subdivisions > 1 ? dimStroke(strokeOps.resolve(stroke), 0.5) : [];\n SUB_STROKES.set(given, sub);\n }\n return sub;\n}\n\n/** A prop as it stood when given: a binding read once. */\nfunction valueOf(prop: unknown): unknown {\n return typeof prop === \"function\" ? (prop as () => unknown)() : prop;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"grid-lines.js","sourceRoot":"","sources":["../../src/kit/grid-lines.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAuE,MAAM,mBAAmB,CAAC;AA+BnH;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CACrB,CAAW,EACX,CAAW,EACX,YAAoB,EACpB,QAAgB,EAChB,KAAK,GAAG,CAAC;IAET,MAAM,aAAa,GAAa,EAAE,CAAC;IACnC,MAAM,aAAa,GAAa,EAAE,CAAC;IACnC,MAAM,eAAe,GAAa,EAAE,CAAC;IACrC,MAAM,eAAe,GAAa,EAAE,CAAC;IAErC,MAAM,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,GAAG,QAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IAC5E,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,GAAG,QAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9E,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,GAAG,QAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7E,MAAM,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,GAAG,QAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IAE7E,aAAa,CAA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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,4CAA4C;AAC5C,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/** 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"]}
|
|
@@ -1,22 +1,12 @@
|
|
|
1
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
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 declare const state: {
|
|
21
11
|
flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
|
|
22
12
|
gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
|
|
@@ -62,19 +52,12 @@ export declare const commands: {
|
|
|
62
52
|
type ShapeState = Flow.FlowState & Values<typeof Paint.state>;
|
|
63
53
|
export declare function measure(measurer: Measurer, s: ShapeState, children: readonly ChildView[]): Size2D;
|
|
64
54
|
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
|
-
*/
|
|
55
|
+
/** The world rect the nearest `Camera` sees, in the pattern's draw space, else its own box. */
|
|
69
56
|
export declare function visibleBounds(ctx: RenderContext): BoxBounds;
|
|
70
57
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
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]`.
|
|
58
|
+
* Paints `pattern` over the visible region, then the children. Clipped to the
|
|
59
|
+
* region so overscanned geometry trims cleanly even with no camera. A path drawn
|
|
60
|
+
* here takes `centerBounds` of `[bounds.x - w/2, bounds.y - h/2, bounds.x + w/2, bounds.y + h/2]`.
|
|
78
61
|
*/
|
|
79
62
|
export declare function draw(ctx: RenderContext, pattern: (bounds: BoxBounds) => void): void;
|
|
80
63
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viewport-pattern.d.ts","sourceRoot":"","sources":["../../src/kit/viewport-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,IAAI,EAEJ,KAAK,EACL,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,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
|
|
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,I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