@motionscript/patterns 0.1.0-alpha.4 → 0.1.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/CHANGELOG.md +48 -16
  2. package/README.md +13 -9
  3. package/dist/browser/chunks/chunk-REWLNFZ2.js +2 -0
  4. package/dist/browser/chunks/chunk-REWLNFZ2.js.map +7 -0
  5. package/dist/browser/index.js +1 -1
  6. package/dist/browser/index.js.map +3 -3
  7. package/dist/browser/kit.js +1 -1
  8. package/dist/browser/manifest.json +1 -1
  9. package/dist/dot-grid-pattern/dot-grid-pattern.d.ts +68 -27
  10. package/dist/dot-grid-pattern/dot-grid-pattern.d.ts.map +1 -1
  11. package/dist/dot-grid-pattern/dot-grid-pattern.js +71 -75
  12. package/dist/dot-grid-pattern/dot-grid-pattern.js.map +1 -1
  13. package/dist/engine.d.ts +4 -4
  14. package/dist/engine.js +4 -4
  15. package/dist/engine.js.map +1 -1
  16. package/dist/grid-pattern/grid-pattern.d.ts +59 -26
  17. package/dist/grid-pattern/grid-pattern.d.ts.map +1 -1
  18. package/dist/grid-pattern/grid-pattern.js +83 -102
  19. package/dist/grid-pattern/grid-pattern.js.map +1 -1
  20. package/dist/kit/grid-lines.d.ts +7 -0
  21. package/dist/kit/grid-lines.d.ts.map +1 -1
  22. package/dist/kit/grid-lines.js +21 -0
  23. package/dist/kit/grid-lines.js.map +1 -1
  24. package/dist/kit/index.d.ts +1 -1
  25. package/dist/kit/index.d.ts.map +1 -1
  26. package/dist/kit/index.js +1 -1
  27. package/dist/kit/index.js.map +1 -1
  28. package/dist/kit/viewport-pattern.d.ts +75 -30
  29. package/dist/kit/viewport-pattern.d.ts.map +1 -1
  30. package/dist/kit/viewport-pattern.js +66 -69
  31. package/dist/kit/viewport-pattern.js.map +1 -1
  32. package/dist/line-grid-pattern/line-grid-pattern.d.ts +56 -23
  33. package/dist/line-grid-pattern/line-grid-pattern.d.ts.map +1 -1
  34. package/dist/line-grid-pattern/line-grid-pattern.js +63 -88
  35. package/dist/line-grid-pattern/line-grid-pattern.js.map +1 -1
  36. package/dist/nodes.d.ts +8 -3
  37. package/dist/nodes.d.ts.map +1 -1
  38. package/dist/nodes.js +5 -10
  39. package/dist/nodes.js.map +1 -1
  40. package/package.json +4 -4
  41. package/src/dot-grid-pattern/dot-grid-pattern.ts +101 -78
  42. package/src/engine.ts +4 -4
  43. package/src/grid-pattern/grid-pattern.ts +126 -120
  44. package/src/kit/grid-lines.ts +25 -1
  45. package/src/kit/index.ts +1 -1
  46. package/src/kit/viewport-pattern.ts +89 -78
  47. package/src/line-grid-pattern/line-grid-pattern.ts +95 -103
  48. package/src/nodes.ts +16 -3
  49. package/dist/browser/chunks/chunk-EZEE76AY.js +0 -2
  50. package/dist/browser/chunks/chunk-EZEE76AY.js.map +0 -7
@@ -1,30 +1,63 @@
1
- import { Clip, ShapeNode, type AssetScope, type NodeConfig, type RenderContext2D, type ShapeProps, type Stroke, type StrokeResolved, type Vector2 } from "@motionscript/sdk";
2
- export interface LineGridPatternProps extends ShapeProps {
3
- /** Cells along each axis: `divisions` of 4 draws 5 major lines per axis. */
4
- divisions: number;
5
- /** Finer cells each division is split into. 1 draws no minor lines; 2 adds one per division. */
6
- subdivisions: number;
7
- /** Stroke for the minor lines. Defaults to the major `stroke` at half opacity when `subdivisions > 1`. */
8
- subStroke?: Stroke;
9
- /** Pans the grid. Lines wrap and tile, so the rect stays full while `offset` scrolls it. */
10
- offset: Vector2;
11
- }
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";
12
2
  /**
13
3
  * A rectangular grid of lines filling the node's layout rect.
14
4
  *
15
5
  * `stroke` paints the major lines and `subStroke` the minor ones, each as a
16
6
  * single union path. `fill` and `shadow` cover the whole rect, behind the lines.
17
7
  */
18
- export declare class LineGridPattern extends ShapeNode<LineGridPatternProps> {
19
- readonly divisions: number;
20
- readonly subdivisions: number;
21
- get subStroke(): StrokeResolved[];
22
- set subStroke(value: Stroke);
23
- readonly offset: Vector2;
24
- constructor(props: NodeConfig<LineGridPattern, LineGridPatternProps>);
25
- declareAssets(assets: AssetScope): void;
26
- protected renderSelf(draw: RenderContext2D): void;
27
- protected clipSelf(): Clip;
28
- private _gridPaths;
29
- }
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>>;
60
+ export type LineGridPattern = NodeOf<typeof LineGridPattern>;
61
+ /** What a call or a document row may set. */
62
+ export type LineGridPatternProps = NonNullable<Parameters<typeof LineGridPattern>[0]>;
30
63
  //# sourceMappingURL=line-grid-pattern.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"line-grid-pattern.d.ts","sourceRoot":"","sources":["../../src/line-grid-pattern/line-grid-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,IAAI,EAEJ,SAAS,EAKT,KAAK,UAAU,EACf,KAAK,UAAU,EAGf,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,MAAM,EACX,KAAK,cAAc,EACnB,KAAK,OAAO,EACf,MAAM,mBAAmB,CAAC;AAI3B,MAAM,WAAW,oBAAqB,SAAQ,UAAU;IACpD,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAC;IAClB,gGAAgG;IAChG,YAAY,EAAE,MAAM,CAAC;IACrB,0GAA0G;IAC1G,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4FAA4F;IAC5F,MAAM,EAAE,OAAO,CAAC;CACnB;AAED;;;;;GAKG;AACH,qBACa,eAAgB,SAAQ,SAAS,CAAC,oBAAoB,CAAC;IAEhE,SAA2C,SAAS,EAAE,MAAM,CAAC;IAC7D,SAA2C,YAAY,EAAE,MAAM,CAAC;IAEhE,IACI,SAAS,IAAI,cAAc,EAAE,CAAuB;IACxD,IAAI,SAAS,CAAC,KAAK,EAAE,MAAM,EAAkC;IAC7D,SACiB,MAAM,EAAE,OAAO,CAAC;gBAErB,KAAK,EAAE,UAAU,CAAC,eAAe,EAAE,oBAAoB,CAAC;IAQ3D,aAAa,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAKhD,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI;cAmC9B,QAAQ,IAAI,IAAI;IASnC,OAAO,CAAC,UAAU;CAiBrB"}
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;;;;;;;;;;;;;;UAwClG,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"}
@@ -1,96 +1,71 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import { Clip, Graphics2D, ShapeNode, lerpVector2, node, property, strokeProperty, } from "@motionscript/sdk";
8
- import { centered, dimStroke, gridLinePaths, maxWeight } from "../kit/index.js";
1
+ import { Flow, Graphics2D, Paint, Types, component2d, lerpVector2, } from "@motionscript/sdk";
2
+ import { centered, defaultSubStroke, gridLinePaths, maxWeight } from "../kit/index.js";
9
3
  /**
10
4
  * A rectangular grid of lines filling the node's layout rect.
11
5
  *
12
6
  * `stroke` paints the major lines and `subStroke` the minor ones, each as a
13
7
  * single union path. `fill` and `shadow` cover the whole rect, behind the lines.
14
8
  */
15
- let LineGridPattern = class LineGridPattern extends ShapeNode {
16
- // Asymmetric accessor like `ShapeNode.stroke`: reads yield `StrokeResolved[]`, writes accept `Stroke`.
17
- get subStroke() { return undefined; }
18
- set subStroke(value) { }
19
- constructor(props) {
20
- super(props);
21
- if (props.subStroke === undefined && props.stroke !== undefined && this.subdivisions > 1) {
22
- this.set({ subStroke: dimStroke(this.stroke, 0.5) });
23
- }
24
- }
25
- declareAssets(assets) {
26
- super.declareAssets(assets);
27
- for (const stroke of this.subStroke)
28
- assets.fill(stroke.fill);
29
- }
30
- renderSelf(draw) {
31
- const width = this.layoutBounds.width;
32
- const height = this.layoutBounds.height;
33
- const centerBounds = [-width / 2, -height / 2, width / 2, height / 2];
34
- draw.draw(new Graphics2D()
35
- .rect({ width, height, start: this.start, end: this.end })
36
- .shadow(this.shadow)
37
- .fill(this.fill));
38
- const divisions = Math.max(1, Math.floor(this.divisions));
39
- const subdivisions = Math.max(1, Math.floor(this.subdivisions));
40
- // Lines overscan the rect by half the thickest stroke and are clipped to it, so a
41
- // thick line slides out under the clip instead of popping at the boundary.
42
- const major = centered(this.stroke);
43
- const minorStroke = centered(this.subStroke);
44
- const overscan = Math.max(maxWeight(major), maxWeight(minorStroke)) / 2;
45
- const { major: majorLines, minor: minorLines } = this._gridPaths(width, height, divisions, subdivisions, overscan);
46
- draw.beginClip(new Clip().rect({ width, height }));
47
- // Minor lines first so the major lines sit on top.
48
- if (subdivisions > 1 && minorStroke.length > 0 && minorLines.length > 0) {
49
- draw.draw(new Graphics2D()
50
- .path({ data: minorLines, centerBounds })
51
- .stroke(minorStroke));
52
- }
53
- if (majorLines.length > 0) {
54
- draw.draw(new Graphics2D()
55
- .path({ data: majorLines, centerBounds })
56
- .stroke(major));
57
- }
58
- draw.endClip();
59
- }
60
- clipSelf() {
61
- return new Clip().rect({
62
- width: this.layoutBounds.width,
63
- height: this.layoutBounds.height,
9
+ export const LineGridPattern = component2d({
10
+ key: "lineGridPattern",
11
+ state: {
12
+ ...Paint.state,
13
+ ...Flow.state,
14
+ /** Cells along each axis: `divisions` of 4 draws 5 major lines per axis. */
15
+ divisions: 4,
16
+ /** Finer cells each division is split into. 1 draws no minor lines; 2 adds one per division. */
17
+ subdivisions: 1,
18
+ /** Stroke for the minor lines. Unset, the major `stroke` at half opacity when `subdivisions > 1`. */
19
+ subStroke: Types.stroke,
20
+ /** Pans the grid. Lines wrap and tile, so the rect stays full while `offset` scrolls it. */
21
+ offset: Types.custom({ x: 0, y: 0 }, { lerp: lerpVector2 }),
22
+ },
23
+ defaults: { subStroke: (_state, given) => defaultSubStroke(given) },
24
+ commands: { ...Paint.commands },
25
+ measure: (measurer, state, children) => Flow.measure(measurer, state, children, Paint.inset(state)),
26
+ layout: (box, state, children) => Flow.layout(box, state, children, Paint.inset(state)),
27
+ render: (ctx, state) => {
28
+ const { width, height } = ctx.size;
29
+ const box = new Graphics2D().rect({ width, height });
30
+ ctx.inFront(() => {
31
+ ctx.draw(new Graphics2D()
32
+ .rect({ width, height, start: state.start, end: state.end })
33
+ .shadow(state.shadow)
34
+ .fill(state.fill));
35
+ const divisions = Math.max(1, Math.floor(state.divisions));
36
+ const subdivisions = Math.max(1, Math.floor(state.subdivisions));
37
+ // Lines overscan the rect by half the thickest stroke and are clipped to it, so a
38
+ // thick line slides out under the clip instead of popping at the boundary.
39
+ const major = centered(state.stroke);
40
+ const minorStroke = centered(state.subStroke);
41
+ const overscan = Math.max(maxWeight(major), maxWeight(minorStroke)) / 2;
42
+ const lines = gridPaths(width, height, divisions, subdivisions, overscan, state.offset);
43
+ const centerBounds = [-width / 2, -height / 2, width / 2, height / 2];
44
+ ctx.clip(box, () => {
45
+ // Minor lines first so the major lines sit on top.
46
+ if (subdivisions > 1 && minorStroke.length > 0 && lines.minor.length > 0) {
47
+ ctx.draw(new Graphics2D().path({ data: lines.minor, centerBounds }).stroke(minorStroke));
48
+ }
49
+ if (lines.major.length > 0) {
50
+ ctx.draw(new Graphics2D().path({ data: lines.major, centerBounds }).stroke(major));
51
+ }
52
+ });
64
53
  });
65
- }
66
- // One multi-subpath path per group, so each stroke paints its lines as a union with no
67
- // destructive boolean op (which would erase open lines).
68
- _gridPaths(width, height, divisions, subdivisions, overscan) {
69
- // Inset by `overscan` so the outermost lines sit fully inside the rect and are not
70
- // trimmed to half weight by the clip.
71
- const cols = divisions * subdivisions;
72
- const innerW = Math.max(0, width - 2 * overscan);
73
- const innerH = Math.max(0, height - 2 * overscan);
74
- const insetX = width / 2 - overscan;
75
- const insetY = height / 2 - overscan;
76
- // Anchored at the near edge, so a line sits on each edge of the box for any count of cells.
77
- return gridLinePaths({ min: -insetX, max: insetX, step: innerW / cols, offset: this.offset.x, anchor: -insetX }, { min: -insetY, max: insetY, step: innerH / cols, offset: this.offset.y, anchor: -insetY }, subdivisions, overscan);
78
- }
79
- };
80
- __decorate([
81
- property({ default: 4 })
82
- ], LineGridPattern.prototype, "divisions", void 0);
83
- __decorate([
84
- property({ default: 1 })
85
- ], LineGridPattern.prototype, "subdivisions", void 0);
86
- __decorate([
87
- strokeProperty()
88
- ], LineGridPattern.prototype, "subStroke", null);
89
- __decorate([
90
- property({ default: { x: 0, y: 0 }, tween: lerpVector2 })
91
- ], LineGridPattern.prototype, "offset", void 0);
92
- LineGridPattern = __decorate([
93
- node({ key: "lineGridPattern", parentKey: "shape", forkable: true })
94
- ], LineGridPattern);
95
- export { LineGridPattern };
54
+ // The rect is what `clip` confines the children to and what picking tests; it paints nothing more.
55
+ Paint.draw(ctx, state, null, { clipShape: box });
56
+ },
57
+ });
58
+ // One multi-subpath path per group, so each stroke paints its lines as a union with no
59
+ // destructive boolean op (which would erase open lines).
60
+ function gridPaths(width, height, divisions, subdivisions, overscan, offset) {
61
+ // Inset by `overscan` so the outermost lines sit fully inside the rect and are not
62
+ // trimmed to half weight by the clip.
63
+ const cols = divisions * subdivisions;
64
+ const innerW = Math.max(0, width - 2 * overscan);
65
+ const innerH = Math.max(0, height - 2 * overscan);
66
+ const insetX = width / 2 - overscan;
67
+ const insetY = height / 2 - overscan;
68
+ // Anchored at the near edge, so a line sits on each edge of the box for any count of cells.
69
+ return gridLinePaths({ min: -insetX, max: insetX, step: innerW / cols, offset: offset.x, anchor: -insetX }, { min: -insetY, max: insetY, step: innerH / cols, offset: offset.y, anchor: -insetY }, subdivisions, overscan);
70
+ }
96
71
  //# sourceMappingURL=line-grid-pattern.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"line-grid-pattern.js","sourceRoot":"","sources":["../../src/line-grid-pattern/line-grid-pattern.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACH,IAAI,EACJ,UAAU,EACV,SAAS,EACT,WAAW,EACX,IAAI,EACJ,QAAQ,EACR,cAAc,GAUjB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAavE;;;;;GAKG;AAEI,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,SAA+B;IAIhE,uGAAuG;IAEvG,IAAI,SAAS,KAAuB,OAAO,SAAU,CAAC,CAAC,CAAC;IACxD,IAAI,SAAS,CAAC,KAAa,IAAiC,CAAC;IAI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B;IAA1C,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;qDAAuC;AAGhE;IADC,cAAc,EAAE;gDACuC;AAGvC;IADhB,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;+CACzB;AATxB,eAAe;IAD3B,IAAI,CAAC,EAAE,GAAG,EAAE,iBAAiB,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;GACxD,eAAe,CAqF3B","sourcesContent":["import {\r\n Clip,\r\n Graphics2D,\r\n ShapeNode,\r\n lerpVector2,\r\n node,\r\n property,\r\n strokeProperty,\r\n type AssetScope,\r\n type NodeConfig,\r\n type PathBounds,\r\n type PathCommand,\r\n type RenderContext2D,\r\n type ShapeProps,\r\n type Stroke,\r\n type StrokeResolved,\r\n type Vector2,\r\n} from \"@motionscript/sdk\";\r\n\r\nimport { centered, dimStroke, gridLinePaths, maxWeight } from \"../kit\";\r\n\r\nexport interface LineGridPatternProps extends ShapeProps {\r\n /** Cells along each axis: `divisions` of 4 draws 5 major lines per axis. */\r\n divisions: number;\r\n /** Finer cells each division is split into. 1 draws no minor lines; 2 adds one per division. */\r\n subdivisions: number;\r\n /** Stroke for the minor lines. Defaults to the major `stroke` at half opacity when `subdivisions > 1`. */\r\n subStroke?: Stroke;\r\n /** Pans the grid. Lines wrap and tile, so the rect stays full while `offset` scrolls it. */\r\n offset: Vector2;\r\n}\r\n\r\n/**\r\n * A rectangular grid of lines filling the node's layout rect.\r\n *\r\n * `stroke` paints the major lines and `subStroke` the minor ones, each as a\r\n * single union path. `fill` and `shadow` cover the whole rect, behind the lines.\r\n */\r\n@node({ key: \"lineGridPattern\", parentKey: \"shape\", forkable: true })\r\nexport class LineGridPattern extends ShapeNode<LineGridPatternProps> {\r\n\r\n @property({ default: 4 }) declare readonly divisions: number;\r\n @property({ default: 1 }) declare readonly subdivisions: number;\r\n // Asymmetric accessor like `ShapeNode.stroke`: reads yield `StrokeResolved[]`, writes accept `Stroke`.\r\n @strokeProperty()\r\n get subStroke(): StrokeResolved[] { return undefined!; }\r\n set subStroke(value: Stroke) { /* installed by @property */ }\r\n @property({ default: { x: 0, y: 0 }, tween: lerpVector2 })\r\n declare readonly offset: Vector2;\r\n\r\n constructor(props: NodeConfig<LineGridPattern, LineGridPatternProps>) {\r\n super(props);\r\n\r\n if (props.subStroke === undefined && props.stroke !== undefined && this.subdivisions > 1) {\r\n this.set({ subStroke: dimStroke(this.stroke as StrokeResolved[], 0.5) });\r\n }\r\n }\r\n\r\n override declareAssets(assets: AssetScope): void {\r\n super.declareAssets(assets);\r\n for (const stroke of this.subStroke) assets.fill(stroke.fill);\r\n }\r\n\r\n protected renderSelf(draw: RenderContext2D): void {\r\n const width = this.layoutBounds.width;\r\n const height = this.layoutBounds.height;\r\n const centerBounds: PathBounds = [-width / 2, -height / 2, width / 2, height / 2];\r\n\r\n draw.draw(new Graphics2D()\r\n .rect({ width, height, start: this.start, end: this.end })\r\n .shadow(this.shadow)\r\n .fill(this.fill));\r\n\r\n const divisions = Math.max(1, Math.floor(this.divisions));\r\n const subdivisions = Math.max(1, Math.floor(this.subdivisions));\r\n\r\n // Lines overscan the rect by half the thickest stroke and are clipped to it, so a\r\n // thick line slides out under the clip instead of popping at the boundary.\r\n const major = centered(this.stroke as StrokeResolved[]);\r\n const minorStroke = centered(this.subStroke as StrokeResolved[]);\r\n const overscan = Math.max(maxWeight(major), maxWeight(minorStroke)) / 2;\r\n const { major: majorLines, minor: minorLines } = this._gridPaths(width, height, divisions, subdivisions, overscan);\r\n\r\n draw.beginClip(new Clip().rect({ width, height }));\r\n // Minor lines first so the major lines sit on top.\r\n if (subdivisions > 1 && minorStroke.length > 0 && minorLines.length > 0) {\r\n draw.draw(new Graphics2D()\r\n .path({ data: minorLines, centerBounds })\r\n .stroke(minorStroke));\r\n }\r\n if (majorLines.length > 0) {\r\n draw.draw(new Graphics2D()\r\n .path({ data: majorLines, centerBounds })\r\n .stroke(major));\r\n }\r\n draw.endClip();\r\n }\r\n\r\n protected override clipSelf(): Clip {\r\n return new Clip().rect({\r\n width: this.layoutBounds.width,\r\n height: this.layoutBounds.height,\r\n });\r\n }\r\n\r\n // One multi-subpath path per group, so each stroke paints its lines as a union with no\r\n // destructive boolean op (which would erase open lines).\r\n private _gridPaths(width: number, height: number, divisions: number, subdivisions: number, overscan: number): { major: PathCommand[]; minor: PathCommand[] } {\r\n // Inset by `overscan` so the outermost lines sit fully inside the rect and are not\r\n // trimmed to half weight by the clip.\r\n const cols = divisions * subdivisions;\r\n const innerW = Math.max(0, width - 2 * overscan);\r\n const innerH = Math.max(0, height - 2 * overscan);\r\n const insetX = width / 2 - overscan;\r\n const insetY = height / 2 - overscan;\r\n\r\n // Anchored at the near edge, so a line sits on each edge of the box for any count of cells.\r\n return gridLinePaths(\r\n { min: -insetX, max: insetX, step: innerW / cols, offset: this.offset.x, anchor: -insetX },\r\n { min: -insetY, max: insetY, step: innerH / cols, offset: this.offset.y, anchor: -insetY },\r\n subdivisions,\r\n overscan,\r\n );\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"line-grid-pattern.js","sourceRoot":"","sources":["../../src/line-grid-pattern/line-grid-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,IAAI,EACJ,UAAU,EACV,KAAK,EACL,KAAK,EACL,WAAW,EACX,WAAW,GAkBd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE9E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC;IACvC,GAAG,EAAE,iBAAiB;IACtB,KAAK,EAAE;QACH,GAAG,KAAK,CAAC,KAAK;QACd,GAAG,IAAI,CAAC,KAAK;QACb,4EAA4E;QAC5E,SAAS,EAAE,CAA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GAAG,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,EACrF,YAAY,EACZ,QAAQ,CACX,CAAC;AACN,CAAC","sourcesContent":["import {\r\n Flow,\r\n Graphics2D,\r\n Paint,\r\n Types,\r\n component2d,\r\n lerpVector2,\r\n type NodeOf,\r\n type PathBounds,\r\n type PathCommand,\r\n type Vector2,\r\n // Named so the emitted declaration reaches these through the sdk, not core.\r\n type Alignment as _Alignment,\r\n type Fill as _Fill,\r\n type FillResolved as _FillResolved,\r\n type FlowMode as _FlowMode,\r\n type FlowResolved as _FlowResolved,\r\n type GapSize as _GapSize,\r\n type Node2D as _Node2D,\r\n type Node2DProps as _Node2DProps,\r\n type Shadow as _Shadow,\r\n type ShadowResolved as _ShadowResolved,\r\n type Stroke as _Stroke,\r\n type StrokeResolved as _StrokeResolved,\r\n} from \"@motionscript/sdk\";\r\n\r\nimport { centered, defaultSubStroke, gridLinePaths, maxWeight } from \"../kit\";\r\n\r\n/**\r\n * A rectangular grid of lines filling the node's layout rect.\r\n *\r\n * `stroke` paints the major lines and `subStroke` the minor ones, each as a\r\n * single union path. `fill` and `shadow` cover the whole rect, behind the lines.\r\n */\r\nexport const LineGridPattern = component2d({\r\n key: \"lineGridPattern\",\r\n state: {\r\n ...Paint.state,\r\n ...Flow.state,\r\n /** Cells along each axis: `divisions` of 4 draws 5 major lines per axis. */\r\n divisions: 4,\r\n /** Finer cells each division is split into. 1 draws no minor lines; 2 adds one per division. */\r\n subdivisions: 1,\r\n /** Stroke for the minor lines. Unset, the major `stroke` at half opacity when `subdivisions > 1`. */\r\n subStroke: Types.stroke,\r\n /** Pans the grid. Lines wrap and tile, so the rect stays full while `offset` scrolls it. */\r\n offset: Types.custom<Vector2>({ x: 0, y: 0 }, { lerp: lerpVector2 }),\r\n },\r\n defaults: { subStroke: (_state, given) => defaultSubStroke(given) },\r\n commands: { ...Paint.commands },\r\n measure: (measurer, state, children) => Flow.measure(measurer, state, children, Paint.inset(state)),\r\n layout: (box, state, children) => Flow.layout(box, state, children, Paint.inset(state)),\r\n render: (ctx, state) => {\r\n const { width, height } = ctx.size;\r\n const box = new Graphics2D().rect({ width, height });\r\n ctx.inFront(() => {\r\n ctx.draw(new Graphics2D()\r\n .rect({ width, height, start: state.start, end: state.end })\r\n .shadow(state.shadow)\r\n .fill(state.fill));\r\n\r\n const divisions = Math.max(1, Math.floor(state.divisions));\r\n const subdivisions = Math.max(1, Math.floor(state.subdivisions));\r\n\r\n // Lines overscan the rect by half the thickest stroke and are clipped to it, so a\r\n // thick line slides out under the clip instead of popping at the boundary.\r\n const major = centered(state.stroke);\r\n const minorStroke = centered(state.subStroke);\r\n const overscan = Math.max(maxWeight(major), maxWeight(minorStroke)) / 2;\r\n const lines = gridPaths(width, height, divisions, subdivisions, overscan, state.offset);\r\n const centerBounds: PathBounds = [-width / 2, -height / 2, width / 2, height / 2];\r\n\r\n ctx.clip(box, () => {\r\n // Minor lines first so the major lines sit on top.\r\n if (subdivisions > 1 && minorStroke.length > 0 && lines.minor.length > 0) {\r\n ctx.draw(new Graphics2D().path({ data: lines.minor, centerBounds }).stroke(minorStroke));\r\n }\r\n if (lines.major.length > 0) {\r\n ctx.draw(new Graphics2D().path({ data: lines.major, centerBounds }).stroke(major));\r\n }\r\n });\r\n });\r\n // The rect is what `clip` confines the children to and what picking tests; it paints nothing more.\r\n Paint.draw(ctx, state, null, { clipShape: box });\r\n },\r\n});\r\n\r\nexport type LineGridPattern = NodeOf<typeof LineGridPattern>;\r\n/** What a call or a document row may set. */\r\nexport type LineGridPatternProps = NonNullable<Parameters<typeof LineGridPattern>[0]>;\r\n\r\n// One multi-subpath path per group, so each stroke paints its lines as a union with no\r\n// destructive boolean op (which would erase open lines).\r\nfunction gridPaths(\r\n width: number,\r\n height: number,\r\n divisions: number,\r\n subdivisions: number,\r\n overscan: number,\r\n offset: Vector2,\r\n): { major: PathCommand[]; minor: PathCommand[] } {\r\n // Inset by `overscan` so the outermost lines sit fully inside the rect and are not\r\n // trimmed to half weight by the clip.\r\n const cols = divisions * subdivisions;\r\n const innerW = Math.max(0, width - 2 * overscan);\r\n const innerH = Math.max(0, height - 2 * overscan);\r\n const insetX = width / 2 - overscan;\r\n const insetY = height / 2 - overscan;\r\n\r\n // Anchored at the near edge, so a line sits on each edge of the box for any count of cells.\r\n return gridLinePaths(\r\n { min: -insetX, max: insetX, step: innerW / cols, offset: offset.x, anchor: -insetX },\r\n { min: -insetY, max: insetY, step: innerH / cols, offset: offset.y, anchor: -insetY },\r\n subdivisions,\r\n overscan,\r\n );\r\n}\r\n"]}
package/dist/nodes.d.ts CHANGED
@@ -5,10 +5,15 @@ import { LineGridPattern } from "./line-grid-pattern/index.js";
5
5
  * Every node type this package publishes.
6
6
  *
7
7
  * A host registers these by handing the array to an engine —
8
- * `new Engine(platform, { nodes: NODES })` — which reads each class's `@node()`
9
- * key. Listing class **values** is also what survives bundling: this package
8
+ * `new Engine(platform, { nodes: NODES })` — which reads each component's key.
9
+ * Defining a component only *declares* that key: nothing is registered by
10
+ * importing a module, so a registry holds exactly what its owner asked for.
11
+ *
12
+ * Listing the component **values** is also what survives bundling: this package
10
13
  * declares `sideEffects: false`, and a document names a node type by string, so
11
14
  * an import kept only for its side effect is exactly what gets shaken out.
12
15
  */
13
- export declare const NODES: (typeof LineGridPattern | typeof DotGridPattern | typeof GridPattern)[];
16
+ type KitNode = typeof LineGridPattern | typeof DotGridPattern | typeof GridPattern;
17
+ export declare const NODES: KitNode[];
18
+ export {};
14
19
  //# sourceMappingURL=nodes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../src/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAErD;;;;;;;;GAQG;AACH,eAAO,MAAM,KAAK,yEAAiD,CAAA"}
1
+ {"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../src/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAErD;;;;;;;;;;;GAWG;AAEH,KAAK,OAAO,GACN,OAAO,eAAe,GACtB,OAAO,cAAc,GACrB,OAAO,WAAW,CAAA;AAExB,eAAO,MAAM,KAAK,EAAE,OAAO,EAI1B,CAAA"}
package/dist/nodes.js CHANGED
@@ -1,14 +1,9 @@
1
1
  import { DotGridPattern } from "./dot-grid-pattern/index.js";
2
2
  import { GridPattern } from "./grid-pattern/index.js";
3
3
  import { LineGridPattern } from "./line-grid-pattern/index.js";
4
- /**
5
- * Every node type this package publishes.
6
- *
7
- * A host registers these by handing the array to an engine —
8
- * `new Engine(platform, { nodes: NODES })` — which reads each class's `@node()`
9
- * key. Listing class **values** is also what survives bundling: this package
10
- * declares `sideEffects: false`, and a document names a node type by string, so
11
- * an import kept only for its side effect is exactly what gets shaken out.
12
- */
13
- export const NODES = [LineGridPattern, DotGridPattern, GridPattern];
4
+ export const NODES = [
5
+ LineGridPattern,
6
+ DotGridPattern,
7
+ GridPattern,
8
+ ];
14
9
  //# sourceMappingURL=nodes.js.map
package/dist/nodes.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"nodes.js","sourceRoot":"","sources":["../src/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAErD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,eAAe,EAAE,cAAc,EAAE,WAAW,CAAC,CAAA","sourcesContent":["import { DotGridPattern } from \"./dot-grid-pattern\"\r\nimport { GridPattern } from \"./grid-pattern\"\r\nimport { LineGridPattern } from \"./line-grid-pattern\"\r\n\r\n/**\r\n * Every node type this package publishes.\r\n *\r\n * A host registers these by handing the array to an engine —\r\n * `new Engine(platform, { nodes: NODES })` — which reads each class's `@node()`\r\n * key. Listing class **values** is also what survives bundling: this package\r\n * declares `sideEffects: false`, and a document names a node type by string, so\r\n * an import kept only for its side effect is exactly what gets shaken out.\r\n */\r\nexport const NODES = [LineGridPattern, DotGridPattern, GridPattern]\r\n"]}
1
+ {"version":3,"file":"nodes.js","sourceRoot":"","sources":["../src/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAoBrD,MAAM,CAAC,MAAM,KAAK,GAAc;IAC5B,eAAe;IACf,cAAc;IACd,WAAW;CACd,CAAA","sourcesContent":["import { DotGridPattern } from \"./dot-grid-pattern\"\r\nimport { GridPattern } from \"./grid-pattern\"\r\nimport { LineGridPattern } from \"./line-grid-pattern\"\r\n\r\n/**\r\n * Every node type this package publishes.\r\n *\r\n * A host registers these by handing the array to an engine —\r\n * `new Engine(platform, { nodes: NODES })` — which reads each component's key.\r\n * Defining a component only *declares* that key: nothing is registered by\r\n * importing a module, so a registry holds exactly what its owner asked for.\r\n *\r\n * Listing the component **values** is also what survives bundling: this package\r\n * declares `sideEffects: false`, and a document names a node type by string, so\r\n * an import kept only for its side effect is exactly what gets shaken out.\r\n */\r\n// Typed by name, so the declaration names each component rather than spelling out its type through core.\r\ntype KitNode =\r\n | typeof LineGridPattern\r\n | typeof DotGridPattern\r\n | typeof GridPattern\r\n\r\nexport const NODES: KitNode[] = [\r\n LineGridPattern,\r\n DotGridPattern,\r\n GridPattern,\r\n]\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@motionscript/patterns",
3
- "version": "0.1.0-alpha.4",
3
+ "version": "0.1.0-alpha.6",
4
4
  "type": "module",
5
5
  "description": "Background patterns for Motion Script: line and dot grids that fill a box, and an infinite grid that fills whatever a camera can see.",
6
6
  "repository": {
@@ -50,7 +50,7 @@
50
50
  ],
51
51
  "license": "Apache-2.0",
52
52
  "peerDependencies": {
53
- "@motionscript/sdk": "^0.1.0-alpha.4"
53
+ "@motionscript/sdk": "^0.1.0-alpha.6"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@types/node": "^25.6.2",
@@ -61,8 +61,8 @@
61
61
  "typescript": "^6.0.3",
62
62
  "typescript-eslint": "^8.48.0",
63
63
  "vitest": "^4.1.5",
64
- "@motionscript/core": "0.1.0-alpha.4",
65
- "@motionscript/sdk": "0.1.0-alpha.4"
64
+ "@motionscript/core": "0.1.0-alpha.6",
65
+ "@motionscript/sdk": "0.1.0-alpha.6"
66
66
  },
67
67
  "scripts": {
68
68
  "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json --resolve-full-paths && node ../../../scripts/build-browser.mjs",