@motionscript/patterns 0.1.0-alpha.5 → 0.1.0-alpha.7

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 +24 -0
  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 +104 -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 +89 -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 +86 -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,10 +1,4 @@
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, } from "@motionscript/sdk";
1
+ import { Flow, Graphics2D, Paint, Types, component2d, lerpVector2, } from "@motionscript/sdk";
8
2
  import { addTiledLines } from "../kit/index.js";
9
3
  // Calls the tiling `LineGridPattern` uses, so dots stay on its intersections at every offset.
10
4
  function gridPositions(min, max, step, offset, subdivisions, overscan) {
@@ -15,79 +9,81 @@ function gridPositions(min, max, step, offset, subdivisions, overscan) {
15
9
  }, min);
16
10
  return out;
17
11
  }
12
+ const state = {
13
+ ...Paint.state,
14
+ ...Flow.state,
15
+ /** Cells along each axis, as in `LineGridPattern.divisions`: 4 puts 5 major dots on each axis. */
16
+ divisions: 4,
17
+ /** Splits each division again. `1` draws only the major dots; `2` puts one minor dot between each pair. */
18
+ subdivisions: 1,
19
+ /** Radius of a major dot. */
20
+ radius: 3,
21
+ /**
22
+ * A minor dot's radius as a fraction of a major one's. A fraction rather than a
23
+ * second paint stack, so the whole field stays one fill and a gradient crosses
24
+ * every dot in it.
25
+ */
26
+ subScale: 0.5,
27
+ /** Pans the field, as `LineGridPattern.offset` does, so the two stay aligned while both scroll. */
28
+ offset: Types.custom({ x: 0, y: 0 }, { lerp: lerpVector2 }),
29
+ };
18
30
  /**
19
31
  * A field of dots on the same `divisions` / `subdivisions` / `offset` as
20
- * {@link LineGridPattern}, so laid over one the dots sit on its intersections.
32
+ * `LineGridPattern`, so laid over one the dots sit on its intersections.
21
33
  *
22
- * The silhouette is the dots (see {@link DotGridPattern.shapeGraphics}), so
23
- * `ShapeNode` paints `shadow`, `fill`, `overlay` and `stroke` with no render code
24
- * here. A dot grid has no "paper": a rectangle behind it is how it gets a
25
- * background.
34
+ * The silhouette is the dots, which `Paint.draw` paints with `shadow`, `fill`,
35
+ * `overlay` and `stroke`. A dot grid has no "paper": a rectangle behind it is how
36
+ * it gets a background.
26
37
  *
27
- * `clipSelf` is the node's box rather than the silhouette, which clips outer dots
28
- * as they pan out and keeps the node selectable between dots. `start` / `end` act
29
- * on nothing: trimming a disc leaves a crescent, not a partial grid.
38
+ * What `clip` confines the children to, and what picking tests, is the node's
39
+ * box rather than the silhouette, which clips outer dots as they pan out and
40
+ * keeps the node selectable between dots. `start` / `end` act on nothing:
41
+ * trimming a disc leaves a crescent, not a partial grid.
30
42
  */
31
- let DotGridPattern = class DotGridPattern extends ShapeNode {
32
- /** Every dot in the field as one un-painted union: the paint stacks belong to the grid, not to a dot. */
33
- shapeGraphics() {
34
- const bounds = this.layoutBounds;
35
- const width = bounds?.width ?? 0;
36
- const height = bounds?.height ?? 0;
37
- if (width <= 0 || height <= 0)
38
- return null;
39
- const divisions = Math.max(1, Math.floor(this.divisions));
40
- const subdivisions = Math.max(1, Math.floor(this.subdivisions));
41
- const major = Math.max(0, this.radius);
42
- const minor = major * Math.max(0, this.subScale);
43
- if (major <= 0 && minor <= 0)
44
- return null;
45
- // Inset by a dot's radius so an edge dot sits inside the box rather than being halved by the clip.
46
- const cols = divisions * subdivisions;
47
- const insetX = Math.max(0, width / 2 - major);
48
- const insetY = Math.max(0, height / 2 - major);
49
- const xs = gridPositions(-insetX, insetX, (insetX * 2) / cols, this.offset.x, subdivisions, major);
50
- const ys = gridPositions(-insetY, insetY, (insetY * 2) / cols, this.offset.y, subdivisions, major);
51
- const dots = new Graphics2D();
52
- let drew = false;
53
- for (const column of xs) {
54
- for (const row of ys) {
55
- // A dot is major only where *both* axes are — an intersection of two
56
- // major rules, which is exactly the point a line grid draws heaviest.
57
- const size = column.isMajor && row.isMajor ? major : minor;
58
- if (size <= 0)
59
- continue;
60
- dots.ellipse({ x: column.pos, y: row.pos, width: size * 2, height: size * 2 });
61
- drew = true;
62
- }
43
+ export const DotGridPattern = component2d({
44
+ key: "dotGridPattern",
45
+ state,
46
+ commands: { ...Paint.commands },
47
+ measure: (measurer, state, children) => Flow.measure(measurer, state, children, Paint.inset(state)),
48
+ layout: (box, state, children) => Flow.layout(box, state, children, Paint.inset(state)),
49
+ render: (ctx, state) => {
50
+ const untrimmed = {
51
+ fill: state.fill, stroke: state.stroke, shadow: state.shadow, overlay: state.overlay, start: 0, end: 1, clip: state.clip,
52
+ };
53
+ const box = new Graphics2D().rect({ width: ctx.size.width, height: ctx.size.height });
54
+ Paint.draw(ctx, untrimmed, dots(ctx.size, state), { clipShape: box });
55
+ },
56
+ });
57
+ /** Every dot in the field as one un-painted union: the paint stacks belong to the grid, not to a dot. */
58
+ function dots(size, s) {
59
+ const { width, height } = size;
60
+ if (width <= 0 || height <= 0)
61
+ return null;
62
+ const divisions = Math.max(1, Math.floor(s.divisions));
63
+ const subdivisions = Math.max(1, Math.floor(s.subdivisions));
64
+ const major = Math.max(0, s.radius);
65
+ const minor = major * Math.max(0, s.subScale);
66
+ if (major <= 0 && minor <= 0)
67
+ return null;
68
+ // Inset by a dot's radius so an edge dot sits inside the box rather than being halved by the clip.
69
+ const cols = divisions * subdivisions;
70
+ const insetX = Math.max(0, width / 2 - major);
71
+ const insetY = Math.max(0, height / 2 - major);
72
+ const xs = gridPositions(-insetX, insetX, (insetX * 2) / cols, s.offset.x, subdivisions, major);
73
+ const ys = gridPositions(-insetY, insetY, (insetY * 2) / cols, s.offset.y, subdivisions, major);
74
+ const field = new Graphics2D();
75
+ let drew = false;
76
+ for (const column of xs) {
77
+ for (const row of ys) {
78
+ // A dot is major only where *both* axes are — an intersection of two
79
+ // major rules, which is exactly the point a line grid draws heaviest.
80
+ const size = column.isMajor && row.isMajor ? major : minor;
81
+ if (size <= 0)
82
+ continue;
83
+ field.ellipse({ x: column.pos, y: row.pos, width: size * 2, height: size * 2 });
84
+ drew = true;
63
85
  }
64
- return drew ? dots : null;
65
- }
66
- clipSelf() {
67
- const bounds = this.layoutBounds;
68
- return new Clip().rect({
69
- width: bounds?.width ?? 0,
70
- height: bounds?.height ?? 0,
71
- });
72
86
  }
73
- };
74
- __decorate([
75
- property({ default: 4 })
76
- ], DotGridPattern.prototype, "divisions", void 0);
77
- __decorate([
78
- property({ default: 1 })
79
- ], DotGridPattern.prototype, "subdivisions", void 0);
80
- __decorate([
81
- property({ default: 3 })
82
- ], DotGridPattern.prototype, "radius", void 0);
83
- __decorate([
84
- property({ default: 0.5 })
85
- ], DotGridPattern.prototype, "subScale", void 0);
86
- __decorate([
87
- property({ default: { x: 0, y: 0 }, tween: lerpVector2 })
88
- ], DotGridPattern.prototype, "offset", void 0);
89
- DotGridPattern = __decorate([
90
- node({ key: "dotGridPattern", parentKey: "shape", forkable: true })
91
- ], DotGridPattern);
92
- export { DotGridPattern };
87
+ return drew ? field : null;
88
+ }
93
89
  //# sourceMappingURL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EAAE,IAAI,EAAE,CAAC;GACvD,cAAc,CAgE1B","sourcesContent":["import {\r\n Clip,\r\n Graphics2D,\r\n ShapeNode,\r\n lerpVector2,\r\n node,\r\n property,\r\n type ShapeProps,\r\n type Vector2,\r\n} from \"@motionscript/sdk\"\r\n\r\nimport { addTiledLines } from \"../kit\"\r\n\r\n/** One mark's place on an axis, and whether it lands on the coarse grid. */\r\ninterface GridPosition {\r\n pos: number\r\n isMajor: boolean\r\n}\r\n\r\n// Calls the tiling `LineGridPattern` uses, so dots stay on its intersections at every offset.\r\nfunction gridPositions(\r\n min: number,\r\n max: number,\r\n step: number,\r\n offset: number,\r\n subdivisions: number,\r\n overscan: number\r\n): GridPosition[] {\r\n const out: GridPosition[] = []\r\n // Anchored at the near edge, so a column or row sits on each edge of the box for any count of cells.\r\n addTiledLines(min, max, step, offset, subdivisions, overscan, (pos, isMajor) => {\r\n out.push({ pos, isMajor })\r\n }, min)\r\n return out\r\n}\r\n\r\nexport interface DotGridPatternProps extends ShapeProps {\r\n /** Cells along each axis, as in `LineGridPattern.divisions`: 4 puts 5 major dots on each axis. */\r\n divisions: number\r\n /** Splits each division again. `1` draws only the major dots; `2` puts one minor dot between each pair. */\r\n subdivisions: number\r\n /** Radius of a major dot. */\r\n radius: number\r\n /**\r\n * A minor dot's radius as a fraction of a major one's. A fraction rather than a\r\n * second paint stack, so the whole field stays one fill and a gradient crosses\r\n * every dot in it.\r\n */\r\n subScale: number\r\n /** Pans the field, as `LineGridPattern.offset` does, so the two stay aligned while both scroll. */\r\n offset: Vector2\r\n}\r\n\r\n/**\r\n * A field of dots on the same `divisions` / `subdivisions` / `offset` as\r\n * {@link LineGridPattern}, so laid over one the dots sit on its intersections.\r\n *\r\n * The silhouette is the dots (see {@link DotGridPattern.shapeGraphics}), so\r\n * `ShapeNode` paints `shadow`, `fill`, `overlay` and `stroke` with no render code\r\n * here. A dot grid has no \"paper\": a rectangle behind it is how it gets a\r\n * background.\r\n *\r\n * `clipSelf` is the node's box rather than the silhouette, which clips outer dots\r\n * as they pan out and keeps the node selectable between dots. `start` / `end` act\r\n * on nothing: trimming a disc leaves a crescent, not a partial grid.\r\n */\r\n@node({ key: \"dotGridPattern\", parentKey: \"shape\", forkable: true })\r\nexport class DotGridPattern extends ShapeNode<DotGridPatternProps> {\r\n @property({ default: 4 }) declare readonly divisions: number\r\n @property({ default: 1 }) declare readonly subdivisions: number\r\n @property({ default: 3 }) declare readonly radius: number\r\n @property({ default: 0.5 }) declare readonly subScale: number\r\n @property({ default: { x: 0, y: 0 }, tween: lerpVector2 })\r\n declare readonly offset: Vector2\r\n\r\n /** Every dot in the field as one un-painted union: the paint stacks belong to the grid, not to a dot. */\r\n protected override shapeGraphics(): Graphics2D | null {\r\n const bounds = this.layoutBounds\r\n const width = bounds?.width ?? 0\r\n const height = bounds?.height ?? 0\r\n if (width <= 0 || height <= 0) return null\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 const major = Math.max(0, this.radius)\r\n const minor = major * Math.max(0, this.subScale)\r\n if (major <= 0 && minor <= 0) return null\r\n\r\n // Inset by a dot's radius so an edge dot sits inside the box rather than being halved by the clip.\r\n const cols = divisions * subdivisions\r\n const insetX = Math.max(0, width / 2 - major)\r\n const insetY = Math.max(0, height / 2 - major)\r\n const xs = gridPositions(\r\n -insetX,\r\n insetX,\r\n (insetX * 2) / cols,\r\n this.offset.x,\r\n subdivisions,\r\n major\r\n )\r\n const ys = gridPositions(\r\n -insetY,\r\n insetY,\r\n (insetY * 2) / cols,\r\n this.offset.y,\r\n subdivisions,\r\n major\r\n )\r\n\r\n const dots = new Graphics2D()\r\n let drew = false\r\n for (const column of xs) {\r\n for (const row of ys) {\r\n // A dot is major only where *both* axes are — an intersection of two\r\n // major rules, which is exactly the point a line grid draws heaviest.\r\n const size = column.isMajor && row.isMajor ? major : minor\r\n if (size <= 0) continue\r\n dots.ellipse({ x: column.pos, y: row.pos, width: size * 2, height: size * 2 })\r\n drew = true\r\n }\r\n }\r\n return drew ? dots : null\r\n }\r\n\r\n protected override clipSelf(): Clip {\r\n const bounds = this.layoutBounds\r\n return new Clip().rect({\r\n width: bounds?.width ?? 0,\r\n height: bounds?.height ?? 0,\r\n })\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"dot-grid-pattern.js","sourceRoot":"","sources":["../../src/dot-grid-pattern/dot-grid-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,UAAU,EACV,KAAK,EACL,KAAK,EACL,WAAW,EACX,WAAW,GAiBZ,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAQtC,8FAA8F;AAC9F,SAAS,aAAa,CACpB,GAAW,EACX,GAAW,EACX,IAAY,EACZ,MAAc,EACd,YAAoB,EACpB,QAAgB;IAEhB,MAAM,GAAG,GAAmB,EAAE,CAAA;IAC9B,qGAAqG;IACrG,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE;QAC7E,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAA;IAC5B,CAAC,EAAE,GAAG,CAAC,CAAA;IACP,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,MAAM,KAAK,GAAG;IACZ,GAAG,KAAK,CAAC,KAAK;IACd,GAAG,IAAI,CAAC,KAAK;IACb,kGAAkG;IAClG,SAAS,EAAE,CAAC;IACZ,2GAA2G;IAC3G,YAAY,EAAE,CAAC;IACf,6BAA6B;IAC7B,MAAM,EAAE,CAAC;IACT;;;;OAIG;IACH,QAAQ,EAAE,GAAG;IACb,mGAAmG;IACnG,MAAM,EAAE,KAAK,CAAC,MAAM,CAAU,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,IAA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M,GAAG,CAAC,CAAC,GAAG,IAAI,EACnB,CAAC,CAAC,MAAM,CAAC,CAAC,EACV,YAAY,EACZ,KAAK,CACN,CAAA;IAED,MAAM,KAAK,GAAG,IAAI,UAAU,EAAE,CAAA;IAC9B,IAAI,IAAI,GAAG,KAAK,CAAA;IAChB,KAAK,MAAM,MAAM,IAAI,EAAE,EAAE,CAAC;QACxB,KAAK,MAAM,GAAG,IAAI,EAAE,EAAE,CAAC;YACrB,qEAAqE;YACrE,sEAAsE;YACtE,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAA;YAC1D,IAAI,IAAI,IAAI,CAAC;gBAAE,SAAQ;YACvB,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,GAAG,CAAC,EAAE,MAAM,EAAE,IAAI,GAAG,CAAC,EAAE,CAAC,CAAA;YAC/E,IAAI,GAAG,IAAI,CAAA;QACb,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAA;AAC5B,CAAC","sourcesContent":["import {\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 Size2D,\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 { addTiledLines } from \"../kit\"\r\n\r\n/** One mark's place on an axis, and whether it lands on the coarse grid. */\r\ninterface GridPosition {\r\n pos: number\r\n isMajor: boolean\r\n}\r\n\r\n// Calls the tiling `LineGridPattern` uses, so dots stay on its intersections at every offset.\r\nfunction gridPositions(\r\n min: number,\r\n max: number,\r\n step: number,\r\n offset: number,\r\n subdivisions: number,\r\n overscan: number\r\n): GridPosition[] {\r\n const out: GridPosition[] = []\r\n // Anchored at the near edge, so a column or row sits on each edge of the box for any count of cells.\r\n addTiledLines(min, max, step, offset, subdivisions, overscan, (pos, isMajor) => {\r\n out.push({ pos, isMajor })\r\n }, min)\r\n return out\r\n}\r\n\r\nconst state = {\r\n ...Paint.state,\r\n ...Flow.state,\r\n /** Cells along each axis, as in `LineGridPattern.divisions`: 4 puts 5 major dots on each axis. */\r\n divisions: 4,\r\n /** Splits each division again. `1` draws only the major dots; `2` puts one minor dot between each pair. */\r\n subdivisions: 1,\r\n /** Radius of a major dot. */\r\n radius: 3,\r\n /**\r\n * A minor dot's radius as a fraction of a major one's. A fraction rather than a\r\n * second paint stack, so the whole field stays one fill and a gradient crosses\r\n * every dot in it.\r\n */\r\n subScale: 0.5,\r\n /** Pans the field, as `LineGridPattern.offset` does, so the two stay aligned while both scroll. */\r\n offset: Types.custom<Vector2>({ x: 0, y: 0 }, { lerp: lerpVector2 }),\r\n}\r\n\r\ninterface DotField {\r\n readonly divisions: number\r\n readonly subdivisions: number\r\n readonly radius: number\r\n readonly subScale: number\r\n readonly offset: Vector2\r\n}\r\n\r\n/**\r\n * A field of dots on the same `divisions` / `subdivisions` / `offset` as\r\n * `LineGridPattern`, so laid over one the dots sit on its intersections.\r\n *\r\n * The silhouette is the dots, which `Paint.draw` paints with `shadow`, `fill`,\r\n * `overlay` and `stroke`. A dot grid has no \"paper\": a rectangle behind it is how\r\n * it gets a background.\r\n *\r\n * What `clip` confines the children to, and what picking tests, is the node's\r\n * box rather than the silhouette, which clips outer dots as they pan out and\r\n * keeps the node selectable between dots. `start` / `end` act on nothing:\r\n * trimming a disc leaves a crescent, not a partial grid.\r\n */\r\nexport const DotGridPattern = component2d({\r\n key: \"dotGridPattern\",\r\n state,\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 untrimmed = {\r\n fill: state.fill, stroke: state.stroke, shadow: state.shadow, overlay: state.overlay, start: 0, end: 1, clip: state.clip,\r\n }\r\n const box = new Graphics2D().rect({ width: ctx.size.width, height: ctx.size.height })\r\n Paint.draw(ctx, untrimmed, dots(ctx.size, state), { clipShape: box })\r\n },\r\n})\r\n\r\nexport type DotGridPattern = NodeOf<typeof DotGridPattern>\r\n/** What a call or a document row may set. */\r\nexport type DotGridPatternProps = NonNullable<Parameters<typeof DotGridPattern>[0]>\r\n\r\n/** Every dot in the field as one un-painted union: the paint stacks belong to the grid, not to a dot. */\r\nfunction dots(size: Size2D, s: DotField): Graphics2D | null {\r\n const { width, height } = size\r\n if (width <= 0 || height <= 0) return null\r\n\r\n const divisions = Math.max(1, Math.floor(s.divisions))\r\n const subdivisions = Math.max(1, Math.floor(s.subdivisions))\r\n const major = Math.max(0, s.radius)\r\n const minor = major * Math.max(0, s.subScale)\r\n if (major <= 0 && minor <= 0) return null\r\n\r\n // Inset by a dot's radius so an edge dot sits inside the box rather than being halved by the clip.\r\n const cols = divisions * subdivisions\r\n const insetX = Math.max(0, width / 2 - major)\r\n const insetY = Math.max(0, height / 2 - major)\r\n const xs = gridPositions(\r\n -insetX,\r\n insetX,\r\n (insetX * 2) / cols,\r\n s.offset.x,\r\n subdivisions,\r\n major\r\n )\r\n const ys = gridPositions(\r\n -insetY,\r\n insetY,\r\n (insetY * 2) / cols,\r\n s.offset.y,\r\n subdivisions,\r\n major\r\n )\r\n\r\n const field = new Graphics2D()\r\n let drew = false\r\n for (const column of xs) {\r\n for (const row of ys) {\r\n // A dot is major only where *both* axes are — an intersection of two\r\n // major rules, which is exactly the point a line grid draws heaviest.\r\n const size = column.isMajor && row.isMajor ? major : minor\r\n if (size <= 0) continue\r\n field.ellipse({ x: column.pos, y: row.pos, width: size * 2, height: size * 2 })\r\n drew = true\r\n }\r\n }\r\n return drew ? field : null\r\n}\r\n"]}
package/dist/engine.d.ts CHANGED
@@ -3,10 +3,10 @@
3
3
  * not copy.
4
4
  *
5
5
  * `ms add` writes a pattern's own files into your project and rewrites its reach
6
- * for these to `@motionscript/patterns/kit`. The engine keys prop machinery to
7
- * class identity, so a second copy of `ViewportPattern` would be a second base
8
- * class answering to one name; `grid-lines` is the tiling every pattern shares,
9
- * which is what keeps a dot grid on a line grid's intersections.
6
+ * for these to `@motionscript/patterns/kit`. `ViewportPattern` is the module a
7
+ * camera-filling pattern is built from; `grid-lines` is the tiling every pattern
8
+ * shares, which is what keeps a dot grid on a line grid's intersections, and a
9
+ * copy that kept its own would drift from it.
10
10
  */
11
11
  export * from "./kit/index.js";
12
12
  //# sourceMappingURL=engine.d.ts.map
package/dist/engine.js CHANGED
@@ -3,10 +3,10 @@
3
3
  * not copy.
4
4
  *
5
5
  * `ms add` writes a pattern's own files into your project and rewrites its reach
6
- * for these to `@motionscript/patterns/kit`. The engine keys prop machinery to
7
- * class identity, so a second copy of `ViewportPattern` would be a second base
8
- * class answering to one name; `grid-lines` is the tiling every pattern shares,
9
- * which is what keeps a dot grid on a line grid's intersections.
6
+ * for these to `@motionscript/patterns/kit`. `ViewportPattern` is the module a
7
+ * camera-filling pattern is built from; `grid-lines` is the tiling every pattern
8
+ * shares, which is what keeps a dot grid on a line grid's intersections, and a
9
+ * copy that kept its own would drift from it.
10
10
  */
11
11
  export * from "./kit/index.js";
12
12
  //# sourceMappingURL=engine.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,cAAc,OAAO,CAAA","sourcesContent":["/**\r\n * The patterns **kit**: what the three patterns share, and what a copied one does\r\n * not copy.\r\n *\r\n * `ms add` writes a pattern's own files into your project and rewrites its reach\r\n * for these to `@motionscript/patterns/kit`. The engine keys prop machinery to\r\n * class identity, so a second copy of `ViewportPattern` would be a second base\r\n * class answering to one name; `grid-lines` is the tiling every pattern shares,\r\n * which is what keeps a dot grid on a line grid's intersections.\r\n */\r\nexport * from \"./kit\"\r\n"]}
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,cAAc,OAAO,CAAA","sourcesContent":["/**\r\n * The patterns **kit**: what the three patterns share, and what a copied one does\r\n * not copy.\r\n *\r\n * `ms add` writes a pattern's own files into your project and rewrites its reach\r\n * for these to `@motionscript/patterns/kit`. `ViewportPattern` is the module a\r\n * camera-filling pattern is built from; `grid-lines` is the tiling every pattern\r\n * shares, which is what keeps a dot grid on a line grid's intersections, and a\r\n * copy that kept its own would drift from it.\r\n */\r\nexport * from \"./kit\"\r\n"]}
@@ -1,31 +1,94 @@
1
- import { type AssetScope, type BoxBounds, type NodeConfig, type RenderContext2D, type ShapeProps, type Stroke, type StrokeResolved, type Vector2 } from "@motionscript/sdk";
2
- import { ViewportPattern } from "../kit/index.js";
3
- export interface GridPatternProps extends ShapeProps {
4
- /** Spacing between grid lines in world units: one number for both axes, or `{ x, y }`. */
5
- cellSize: number | Vector2;
6
- /** Finer cells each cell is split into, as in {@link LineGridPattern.subdivisions}. */
7
- subdivisions: number;
8
- /** Stroke for the minor lines. Defaults to the major `stroke` at half opacity when `subdivisions > 1`. */
9
- subStroke?: Stroke;
10
- /** Scrolls the pattern relative to the world, which it is otherwise anchored to. */
11
- offset: Vector2;
12
- }
1
+ import { type NodeOf, type ShadowResolved, type FillResolved, type StrokeResolved, type Vector2, type Alignment as _Alignment, type Fill as _Fill, type FlowMode as _FlowMode, type FlowResolved as _FlowResolved, type GapSize as _GapSize, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Shadow as _Shadow, type Stroke as _Stroke } from "@motionscript/sdk";
13
2
  /**
14
3
  * An infinite line grid that fills the camera's visible region. Like
15
- * {@link LineGridPattern} it draws major and minor strokes over a fill and pans
4
+ * `LineGridPattern` it draws major and minor strokes over a fill and pans
16
5
  * with `offset`, but it tiles a world-anchored grid (spacing `cellSize`) across
17
- * what the parent {@link Camera} can see, regenerated each frame. With no camera
18
- * it fills its own layout rect.
6
+ * what the nearest `Camera` above it can see, regenerated each frame. With no
7
+ * camera it fills its own layout rect.
19
8
  */
20
- export declare class GridPattern extends ViewportPattern<GridPatternProps> {
21
- readonly cellSize: number | Vector2;
22
- readonly subdivisions: number;
23
- get subStroke(): StrokeResolved[];
24
- set subStroke(value: Stroke);
25
- readonly offset: Vector2;
26
- constructor(props: NodeConfig<GridPattern, GridPatternProps>);
27
- declareAssets(assets: AssetScope): void;
28
- protected renderPattern(draw: RenderContext2D, bounds: BoxBounds): void;
29
- private _drawGroup;
30
- }
9
+ export declare const GridPattern: import("@motionscript/sdk").Component<"gridPattern", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
10
+ /** Spacing between grid lines in world units: one number for both axes, or `{ x, y }`. */
11
+ readonly cellSize: import("@motionscript/sdk").Type<number | Vector2, number | Vector2, false>;
12
+ /** Finer cells each cell is split into, as in `LineGridPattern.subdivisions`. */
13
+ readonly subdivisions: 1;
14
+ /** Stroke for the minor lines. Unset, the major `stroke` at half opacity when `subdivisions > 1`. */
15
+ readonly subStroke: import("@motionscript/sdk").Attribute<_Stroke, StrokeResolved[]>;
16
+ /** Scrolls the pattern relative to the world, which it is otherwise anchored to. */
17
+ readonly offset: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
18
+ readonly flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
19
+ readonly gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
20
+ readonly wrap: boolean;
21
+ readonly crossGap: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
22
+ readonly columns: import("@motionscript/sdk").Type<number, number, false>;
23
+ readonly align: import("@motionscript/sdk").Attribute<_Alignment, Vector2>;
24
+ readonly fill: import("@motionscript/sdk").Attribute<_Fill, FillResolved[]>;
25
+ readonly stroke: import("@motionscript/sdk").Attribute<_Stroke, StrokeResolved[]>;
26
+ readonly shadow: import("@motionscript/sdk").Attribute<_Shadow, ShadowResolved[]>;
27
+ readonly overlay: import("@motionscript/sdk").Attribute<_Fill, FillResolved[]>;
28
+ readonly start: import("@motionscript/sdk").Type<number, number, false>;
29
+ readonly end: import("@motionscript/sdk").Type<number, number, false>;
30
+ }>, {
31
+ readonly fillTo: readonly ["fill"];
32
+ readonly strokeTo: readonly ["stroke"];
33
+ readonly shadowTo: readonly ["shadow"];
34
+ readonly overlayTo: readonly ["overlay"];
35
+ readonly progressTo: readonly ["start", "end"];
36
+ readonly flash: {
37
+ readonly portion: import("@motionscript/sdk").Type<number, number, false>;
38
+ };
39
+ }, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
40
+ /** Spacing between grid lines in world units: one number for both axes, or `{ x, y }`. */
41
+ readonly cellSize: import("@motionscript/sdk").Type<number | Vector2, number | Vector2, false>;
42
+ /** Finer cells each cell is split into, as in `LineGridPattern.subdivisions`. */
43
+ readonly subdivisions: 1;
44
+ /** Stroke for the minor lines. Unset, the major `stroke` at half opacity when `subdivisions > 1`. */
45
+ readonly subStroke: import("@motionscript/sdk").Attribute<_Stroke, StrokeResolved[]>;
46
+ /** Scrolls the pattern relative to the world, which it is otherwise anchored to. */
47
+ readonly offset: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
48
+ readonly flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
49
+ readonly gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
50
+ readonly wrap: boolean;
51
+ readonly crossGap: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
52
+ readonly columns: import("@motionscript/sdk").Type<number, number, false>;
53
+ readonly align: import("@motionscript/sdk").Attribute<_Alignment, Vector2>;
54
+ readonly fill: import("@motionscript/sdk").Attribute<_Fill, FillResolved[]>;
55
+ readonly stroke: import("@motionscript/sdk").Attribute<_Stroke, StrokeResolved[]>;
56
+ readonly shadow: import("@motionscript/sdk").Attribute<_Shadow, ShadowResolved[]>;
57
+ readonly overlay: import("@motionscript/sdk").Attribute<_Fill, FillResolved[]>;
58
+ readonly start: import("@motionscript/sdk").Type<number, number, false>;
59
+ readonly end: import("@motionscript/sdk").Type<number, number, false>;
60
+ }>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
61
+ /** Spacing between grid lines in world units: one number for both axes, or `{ x, y }`. */
62
+ readonly cellSize: import("@motionscript/sdk").Type<number | Vector2, number | Vector2, false>;
63
+ /** Finer cells each cell is split into, as in `LineGridPattern.subdivisions`. */
64
+ readonly subdivisions: 1;
65
+ /** Stroke for the minor lines. Unset, the major `stroke` at half opacity when `subdivisions > 1`. */
66
+ readonly subStroke: import("@motionscript/sdk").Attribute<_Stroke, StrokeResolved[]>;
67
+ /** Scrolls the pattern relative to the world, which it is otherwise anchored to. */
68
+ readonly offset: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
69
+ readonly flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
70
+ readonly gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
71
+ readonly wrap: boolean;
72
+ readonly crossGap: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
73
+ readonly columns: import("@motionscript/sdk").Type<number, number, false>;
74
+ readonly align: import("@motionscript/sdk").Attribute<_Alignment, Vector2>;
75
+ readonly fill: import("@motionscript/sdk").Attribute<_Fill, FillResolved[]>;
76
+ readonly stroke: import("@motionscript/sdk").Attribute<_Stroke, StrokeResolved[]>;
77
+ readonly shadow: import("@motionscript/sdk").Attribute<_Shadow, ShadowResolved[]>;
78
+ readonly overlay: import("@motionscript/sdk").Attribute<_Fill, FillResolved[]>;
79
+ readonly start: import("@motionscript/sdk").Type<number, number, false>;
80
+ readonly end: import("@motionscript/sdk").Type<number, number, false>;
81
+ }>, {
82
+ readonly fillTo: readonly ["fill"];
83
+ readonly strokeTo: readonly ["stroke"];
84
+ readonly shadowTo: readonly ["shadow"];
85
+ readonly overlayTo: readonly ["overlay"];
86
+ readonly progressTo: readonly ["start", "end"];
87
+ readonly flash: {
88
+ readonly portion: import("@motionscript/sdk").Type<number, number, false>;
89
+ };
90
+ }, _Node2D<_Node2DProps>>>>;
91
+ export type GridPattern = NodeOf<typeof GridPattern>;
92
+ /** What a call or a document row may set. */
93
+ export type GridPatternProps = NonNullable<Parameters<typeof GridPattern>[0]>;
31
94
  //# sourceMappingURL=grid-pattern.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"grid-pattern.d.ts","sourceRoot":"","sources":["../../src/grid-pattern/grid-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,EAOH,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,UAAU,EAEf,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,MAAM,EACX,KAAK,cAAc,EACnB,KAAK,OAAO,EACf,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAA6C,eAAe,EAAiB,MAAM,QAAQ,CAAC;AAEnG,MAAM,WAAW,gBAAiB,SAAQ,UAAU;IAChD,0FAA0F;IAC1F,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3B,uFAAuF;IACvF,YAAY,EAAE,MAAM,CAAC;IACrB,0GAA0G;IAC1G,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oFAAoF;IACpF,MAAM,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;GAMG;AACH,qBACa,WAAY,SAAQ,eAAe,CAAC,gBAAgB,CAAC;IAE9D,SACiB,QAAQ,EAAE,MAAM,GA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,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,CAAC;AACrD,6CAA6C;AAC7C,MAAM,MAAM,gBAAgB,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
@@ -1,113 +1,94 @@
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 { Graphics2D, lerpNumber, lerpVector2, node, property, strokeProperty, } from "@motionscript/sdk";
8
- import { centered, dimStroke, gridLines, maxWeight, ViewportPattern } from "../kit/index.js";
1
+ import { Graphics2D, Types, component2d, lerpNumber, lerpVector2, } from "@motionscript/sdk";
2
+ import { centered, defaultSubStroke, gridLines, maxWeight, ViewportPattern } from "../kit/index.js";
9
3
  /**
10
4
  * An infinite line grid that fills the camera's visible region. Like
11
- * {@link LineGridPattern} it draws major and minor strokes over a fill and pans
5
+ * `LineGridPattern` it draws major and minor strokes over a fill and pans
12
6
  * with `offset`, but it tiles a world-anchored grid (spacing `cellSize`) across
13
- * what the parent {@link Camera} can see, regenerated each frame. With no camera
14
- * it fills its own layout rect.
7
+ * what the nearest `Camera` above it can see, regenerated each frame. With no
8
+ * camera it fills its own layout rect.
15
9
  */
16
- let GridPattern = class GridPattern extends ViewportPattern {
17
- // Asymmetric accessor like `ShapeNode.stroke`: reads yield `StrokeResolved[]`, writes accept `Stroke`.
18
- get subStroke() { return undefined; }
19
- set subStroke(value) { }
20
- constructor(props) {
21
- super(props);
22
- if (props.subStroke === undefined && props.stroke !== undefined && this.subdivisions > 1) {
23
- this.set({ subStroke: dimStroke(this.stroke, 0.5) });
24
- }
10
+ export const GridPattern = component2d({
11
+ key: "gridPattern",
12
+ state: {
13
+ ...ViewportPattern.state,
14
+ /** Spacing between grid lines in world units: one number for both axes, or `{ x, y }`. */
15
+ cellSize: Types.custom(100, { lerp: lerpCellSize }),
16
+ /** Finer cells each cell is split into, as in `LineGridPattern.subdivisions`. */
17
+ subdivisions: 1,
18
+ /** Stroke for the minor lines. Unset, the major `stroke` at half opacity when `subdivisions > 1`. */
19
+ subStroke: Types.stroke,
20
+ /** Scrolls the pattern relative to the world, which it is otherwise anchored to. */
21
+ offset: Types.custom({ x: 0, y: 0 }, { lerp: lerpVector2 }),
22
+ },
23
+ defaults: { subStroke: (_state, given) => defaultSubStroke(given) },
24
+ commands: { ...ViewportPattern.commands },
25
+ measure: ViewportPattern.measure,
26
+ layout: ViewportPattern.layout,
27
+ render: (ctx, state) => ViewportPattern.draw(ctx, (bounds) => drawGrid(ctx, state, bounds)),
28
+ });
29
+ function drawGrid(ctx, s, bounds) {
30
+ const halfW = bounds.width / 2;
31
+ const halfH = bounds.height / 2;
32
+ // `bounds` is centred on (x, y) in y-up world space: descriptor coordinates are y-up
33
+ // and the renderer applies the single flip.
34
+ const left = bounds.x - halfW;
35
+ const right = bounds.x + halfW;
36
+ const top = bounds.y - halfH;
37
+ const bottom = bounds.y + halfH;
38
+ ctx.draw(new Graphics2D()
39
+ .rect({ x: bounds.x, y: bounds.y, width: bounds.width, height: bounds.height, start: s.start, end: s.end })
40
+ .shadow(s.shadow)
41
+ .fill(s.fill));
42
+ const subdivisions = Math.max(1, Math.floor(s.subdivisions));
43
+ const cell = s.cellSize;
44
+ const cellX = Math.max(1e-3, typeof cell === "number" ? cell : cell.x);
45
+ const cellY = Math.max(1e-3, typeof cell === "number" ? cell : cell.y);
46
+ const stepX = cellX / subdivisions;
47
+ const stepY = cellY / subdivisions;
48
+ const major = centered(s.stroke);
49
+ const minorStroke = centered(s.subStroke);
50
+ const overscan = Math.max(maxWeight(major), maxWeight(minorStroke)) / 2;
51
+ const xAxis = { min: left, max: right, step: stepX, offset: s.offset.x };
52
+ const yAxis = { min: top, max: bottom, step: stepY, offset: s.offset.y };
53
+ // Minor lines first so the major lines sit on top.
54
+ if (subdivisions > 1 && minorStroke.length > 0) {
55
+ drawGroup(ctx, xAxis, yAxis, subdivisions, overscan, minorStroke, false);
25
56
  }
26
- declareAssets(assets) {
27
- super.declareAssets(assets);
28
- for (const stroke of this.subStroke)
29
- assets.fill(stroke.fill);
57
+ if (major.length > 0) {
58
+ drawGroup(ctx, xAxis, yAxis, subdivisions, overscan, major, true);
30
59
  }
31
- renderPattern(draw, bounds) {
32
- const halfW = bounds.width / 2;
33
- const halfH = bounds.height / 2;
34
- // `bounds` is centred on (x, y) in y-up world space: descriptor coordinates are y-up
35
- // and the renderer applies the single flip.
36
- const left = bounds.x - halfW;
37
- const right = bounds.x + halfW;
38
- const top = bounds.y - halfH;
39
- const bottom = bounds.y + halfH;
40
- draw.draw(new Graphics2D()
41
- .rect({ x: bounds.x, y: bounds.y, width: bounds.width, height: bounds.height, start: this.start, end: this.end })
42
- .shadow(this.shadow)
43
- .fill(this.fill));
44
- const subdivisions = Math.max(1, Math.floor(this.subdivisions));
45
- const cell = this.cellSize;
46
- const cellX = Math.max(1e-3, typeof cell === "number" ? cell : cell.x);
47
- const cellY = Math.max(1e-3, typeof cell === "number" ? cell : cell.y);
48
- const stepX = cellX / subdivisions;
49
- const stepY = cellY / subdivisions;
50
- const major = centered(this.stroke);
51
- const minorStroke = centered(this.subStroke);
52
- const overscan = Math.max(maxWeight(major), maxWeight(minorStroke)) / 2;
53
- const xAxis = { min: left, max: right, step: stepX, offset: this.offset.x };
54
- const yAxis = { min: top, max: bottom, step: stepY, offset: this.offset.y };
55
- // Minor lines first so the major lines sit on top.
56
- if (subdivisions > 1 && minorStroke.length > 0) {
57
- this._drawGroup(draw, xAxis, yAxis, subdivisions, overscan, minorStroke, false);
58
- }
59
- if (major.length > 0) {
60
- this._drawGroup(draw, xAxis, yAxis, subdivisions, overscan, major, true);
61
- }
60
+ }
61
+ // A solid stroke paints the group as one union path. A dashed one draws each line on
62
+ // its own with its dash phase anchored to the line's world coordinate, so dashes never
63
+ // crawl as the camera pans or new lines scroll in.
64
+ 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
+ // Symmetric centerBounds give a zero recentre offset, so local coordinates draw verbatim.
72
+ const centerBounds = [-1, -1, 1, 1];
73
+ 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 });
79
+ if (data.length > 0)
80
+ ctx.draw(new Graphics2D().path({ data, centerBounds }).stroke(stroke));
81
+ return;
62
82
  }
63
- // A solid stroke paints the group as one union path. A dashed one draws each line on
64
- // its own with its dash phase anchored to the line's world coordinate, so dashes never
65
- // crawl as the camera pans or new lines scroll in.
66
- _drawGroup(draw, xAxis, yAxis, subdivisions, overscan, stroke, isMajor) {
67
- // Each line spans a whole number of dash cycles, so the renderer's per-path dash-fit
68
- // is a no-op and every line dashes identically.
69
- const cycle = dashCycle(stroke);
70
- const g = gridLines(xAxis, yAxis, subdivisions, overscan, cycle);
71
- const verticals = isMajor ? g.verticalMajor : g.verticalMinor;
72
- const horizontals = isMajor ? g.horizontalMajor : g.horizontalMinor;
73
- // Symmetric centerBounds give a zero recentre offset, so local coordinates draw verbatim.
74
- const centerBounds = [-1, -1, 1, 1];
75
- if (cycle <= 0) {
76
- const data = [];
77
- for (const px of verticals)
78
- data.push({ type: "M", x: px, y: g.top }, { type: "L", x: px, y: g.bottom });
79
- for (const py of horizontals)
80
- data.push({ type: "M", x: g.left, y: py }, { type: "L", x: g.right, y: py });
81
- if (data.length > 0)
82
- draw.draw(new Graphics2D().path({ data, centerBounds }).stroke(stroke));
83
- return;
84
- }
85
- for (const px of verticals) {
86
- const data = [{ type: "M", x: px, y: g.top }, { type: "L", x: px, y: g.bottom }];
87
- draw.draw(new Graphics2D().path({ data, centerBounds }).stroke(phaseShift(stroke, g.top)));
88
- }
89
- for (const py of horizontals) {
90
- const data = [{ type: "M", x: g.left, y: py }, { type: "L", x: g.right, y: py }];
91
- draw.draw(new Graphics2D().path({ data, centerBounds }).stroke(phaseShift(stroke, g.left)));
92
- }
83
+ for (const px of verticals) {
84
+ const data = [{ type: "M", x: px, y: g.top }, { type: "L", x: px, y: g.bottom }];
85
+ ctx.draw(new Graphics2D().path({ data, centerBounds }).stroke(phaseShift(stroke, g.top)));
93
86
  }
94
- };
95
- __decorate([
96
- property({ default: 100, tween: lerpCellSize })
97
- ], GridPattern.prototype, "cellSize", void 0);
98
- __decorate([
99
- property({ default: 1 })
100
- ], GridPattern.prototype, "subdivisions", void 0);
101
- __decorate([
102
- strokeProperty()
103
- ], GridPattern.prototype, "subStroke", null);
104
- __decorate([
105
- property({ default: { x: 0, y: 0 }, tween: lerpVector2 })
106
- ], GridPattern.prototype, "offset", void 0);
107
- GridPattern = __decorate([
108
- node({ key: "gridPattern", parentKey: "shape", forkable: true })
109
- ], GridPattern);
110
- export { GridPattern };
87
+ for (const py of horizontals) {
88
+ const data = [{ type: "M", x: g.left, y: py }, { type: "L", x: g.right, y: py }];
89
+ ctx.draw(new Graphics2D().path({ data, centerBounds }).stroke(phaseShift(stroke, g.left)));
90
+ }
91
+ }
111
92
  // The largest dash-array sum across the layers, or 0 when none is dashed.
112
93
  function dashCycle(strokes) {
113
94
  let cycle = 0;