@motionscript/grids 0.1.0-alpha.8 → 0.1.0-alpha.9

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 (62) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/LICENSE +201 -201
  3. package/NOTICE +49 -49
  4. package/README.md +118 -118
  5. package/dist/browser/chunks/{chunk-J62D7EFZ.js → chunk-TYNFMZ3D.js} +1 -1
  6. package/dist/browser/chunks/chunk-TYNFMZ3D.js.map +7 -0
  7. package/dist/browser/index.js +1 -1
  8. package/dist/browser/index.js.map +1 -1
  9. package/dist/browser/kit.js +1 -1
  10. package/dist/engine.d.ts +1 -1
  11. package/dist/engine.js +1 -1
  12. package/dist/engine.js.map +1 -1
  13. package/dist/index.js.map +1 -1
  14. package/dist/kit/index.js.map +1 -1
  15. package/dist/kit/item-effects.js.map +1 -1
  16. package/dist/kit/item-grid.js.map +1 -1
  17. package/dist/kit/order.js.map +1 -1
  18. package/dist/kit/random.js.map +1 -1
  19. package/dist/kit/slots/index.js.map +1 -1
  20. package/dist/kit/slots/path-templates.js.map +1 -1
  21. package/dist/kit/slots/path.js.map +1 -1
  22. package/dist/kit/slots/radial.js.map +1 -1
  23. package/dist/kit/slots/rectangular.js.map +1 -1
  24. package/dist/kit/slots/slot.js.map +1 -1
  25. package/dist/kit/slots/sphere.js.map +1 -1
  26. package/dist/kit/stagger.js.map +1 -1
  27. package/dist/nodes.js.map +1 -1
  28. package/dist/path-grid/index.js.map +1 -1
  29. package/dist/path-grid/path-grid.js.map +1 -1
  30. package/dist/radial-grid/index.js.map +1 -1
  31. package/dist/radial-grid/radial-grid.js.map +1 -1
  32. package/dist/rectangular-grid/index.js.map +1 -1
  33. package/dist/rectangular-grid/rectangular-grid.js.map +1 -1
  34. package/dist/sphere-grid/index.js.map +1 -1
  35. package/dist/sphere-grid/sphere-grid.js.map +1 -1
  36. package/package.json +4 -4
  37. package/registry.json +32 -32
  38. package/src/engine.ts +12 -12
  39. package/src/index.ts +6 -6
  40. package/src/kit/index.ts +18 -18
  41. package/src/kit/item-effects.ts +114 -114
  42. package/src/kit/item-grid.ts +648 -648
  43. package/src/kit/order.ts +41 -41
  44. package/src/kit/random.ts +29 -29
  45. package/src/kit/slots/index.ts +39 -39
  46. package/src/kit/slots/path-templates.ts +120 -120
  47. package/src/kit/slots/path.ts +120 -120
  48. package/src/kit/slots/radial.ts +62 -62
  49. package/src/kit/slots/rectangular.ts +108 -108
  50. package/src/kit/slots/slot.ts +82 -82
  51. package/src/kit/slots/sphere.ts +94 -94
  52. package/src/kit/stagger.ts +96 -96
  53. package/src/nodes.ts +30 -30
  54. package/src/path-grid/index.ts +1 -1
  55. package/src/path-grid/path-grid.ts +186 -186
  56. package/src/radial-grid/index.ts +1 -1
  57. package/src/radial-grid/radial-grid.ts +81 -81
  58. package/src/rectangular-grid/index.ts +1 -1
  59. package/src/rectangular-grid/rectangular-grid.ts +145 -145
  60. package/src/sphere-grid/index.ts +1 -1
  61. package/src/sphere-grid/sphere-grid.ts +129 -129
  62. package/dist/browser/chunks/chunk-J62D7EFZ.js.map +0 -7
package/registry.json CHANGED
@@ -1,32 +1,32 @@
1
- {
2
- "kit": {
3
- "barrel": "src/engine.ts",
4
- "specifier": "@motionscript/grids/kit"
5
- },
6
- "items": [
7
- {
8
- "name": "rectangular-grid",
9
- "description": "Children in rows and columns, with brick offsets and cells that fit, fix or fill.",
10
- "root": "src/rectangular-grid",
11
- "files": ["index.ts", "rectangular-grid.ts"]
12
- },
13
- {
14
- "name": "radial-grid",
15
- "description": "Children round a circle or along an arc, turned to face out if you like.",
16
- "root": "src/radial-grid",
17
- "files": ["index.ts", "radial-grid.ts"]
18
- },
19
- {
20
- "name": "path-grid",
21
- "description": "Children spaced along a template, a path of their own, or a Path node in the scene.",
22
- "root": "src/path-grid",
23
- "files": ["index.ts", "path-grid.ts"]
24
- },
25
- {
26
- "name": "sphere-grid",
27
- "description": "Children spread evenly over a sphere, seen through a camera of its own.",
28
- "root": "src/sphere-grid",
29
- "files": ["index.ts", "sphere-grid.ts"]
30
- }
31
- ]
32
- }
1
+ {
2
+ "kit": {
3
+ "barrel": "src/engine.ts",
4
+ "specifier": "@motionscript/grids/kit"
5
+ },
6
+ "items": [
7
+ {
8
+ "name": "rectangular-grid",
9
+ "description": "Children in rows and columns, with brick offsets and cells that fit, fix or fill.",
10
+ "root": "src/rectangular-grid",
11
+ "files": ["index.ts", "rectangular-grid.ts"]
12
+ },
13
+ {
14
+ "name": "radial-grid",
15
+ "description": "Children round a circle or along an arc, turned to face out if you like.",
16
+ "root": "src/radial-grid",
17
+ "files": ["index.ts", "radial-grid.ts"]
18
+ },
19
+ {
20
+ "name": "path-grid",
21
+ "description": "Children spaced along a template, a path of their own, or a Path node in the scene.",
22
+ "root": "src/path-grid",
23
+ "files": ["index.ts", "path-grid.ts"]
24
+ },
25
+ {
26
+ "name": "sphere-grid",
27
+ "description": "Children spread evenly over a sphere, seen through a camera of its own.",
28
+ "root": "src/sphere-grid",
29
+ "files": ["index.ts", "sphere-grid.ts"]
30
+ }
31
+ ]
32
+ }
package/src/engine.ts CHANGED
@@ -1,12 +1,12 @@
1
- /**
2
- * The item grid **kit**: what the four grids share, and what a copied one does
3
- * not copy.
4
- *
5
- * `ms add` writes a grid's own files into your project and rewrites its reach for
6
- * these to `@motionscript/grids`, so the shared parts stay a real
7
- * dependency. That is not a size decision. `ItemGrid` keeps the register of
8
- * grids a morph looks another grid's arrangement up in, so a second copy of it
9
- * would be a second register, and a morph from one grid to another would only
10
- * find the grids its own copy was told of.
11
- */
12
- export * from "./kit"
1
+ /**
2
+ * The item grid **kit**: what the four grids share, and what a copied one does
3
+ * not copy.
4
+ *
5
+ * A copy takes a grid's own files into your project and rewrites its reach for
6
+ * these to `@motionscript/grids`, so the shared parts stay a real
7
+ * dependency. That is not a size decision. `ItemGrid` keeps the register of
8
+ * grids a morph looks another grid's arrangement up in, so a second copy of it
9
+ * would be a second register, and a morph from one grid to another would only
10
+ * find the grids its own copy was told of.
11
+ */
12
+ export * from "./kit"
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
- export * from "./rectangular-grid"
2
- export * from "./radial-grid"
3
- export * from "./path-grid"
4
- export * from "./sphere-grid"
5
- export * from "./engine"
6
- export { NODES } from "./nodes"
1
+ export * from "./rectangular-grid"
2
+ export * from "./radial-grid"
3
+ export * from "./path-grid"
4
+ export * from "./sphere-grid"
5
+ export * from "./engine"
6
+ export { NODES } from "./nodes"
package/src/kit/index.ts CHANGED
@@ -1,18 +1,18 @@
1
- export * from "./slots"
2
- export * from "./stagger"
3
- export * from "./item-effects"
4
- export * from "./order"
5
- export * from "./random"
6
- export * as ItemGrid from "./item-grid"
7
- export {
8
- contentBoxOf,
9
- ITEM_GRID_TYPES,
10
- staggerArgs,
11
- TRANSITION_STAGGER,
12
- type GridSnapshot,
13
- type GridTransition,
14
- type StaggerArgs,
15
- } from "./item-grid"
16
-
17
- // Once this kit's own; kept on its barrel for whoever imports them from it.
18
- export { findNode2D, frameIn } from "@motionscript/sdk"
1
+ export * from "./slots"
2
+ export * from "./stagger"
3
+ export * from "./item-effects"
4
+ export * from "./order"
5
+ export * from "./random"
6
+ export * as ItemGrid from "./item-grid"
7
+ export {
8
+ contentBoxOf,
9
+ ITEM_GRID_TYPES,
10
+ staggerArgs,
11
+ TRANSITION_STAGGER,
12
+ type GridSnapshot,
13
+ type GridTransition,
14
+ type StaggerArgs,
15
+ } from "./item-grid"
16
+
17
+ // Once this kit's own; kept on its barrel for whoever imports them from it.
18
+ export { findNode2D, frameIn } from "@motionscript/sdk"
@@ -1,114 +1,114 @@
1
- import type { Size2D } from "@motionscript/sdk"
2
-
3
- import type { Slot } from "./slots"
4
-
5
- /**
6
- * What an item does on its way in (or out): grow from nothing, fade, fly out of
7
- * the grid's centre, rise into place, flip up, or spin in.
8
- */
9
- export const REVEAL_STYLES = ["scale", "fade", "center", "rise", "flip", "spin"] as const
10
- export type RevealStyle = (typeof REVEAL_STYLES)[number]
11
-
12
- /** What a wave does to each item as it passes. */
13
- export const WAVE_STYLES = ["scale", "lift", "fade", "spin"] as const
14
- export type WaveStyle = (typeof WAVE_STYLES)[number]
15
-
16
- /**
17
- * How far into view each item is, `1` shown and `0` gone — past `1` on the
18
- * way to it under an overshooting ease. Absent means every item is shown.
19
- */
20
- export interface RevealState {
21
- style: RevealStyle
22
- values: readonly number[]
23
- }
24
-
25
- /** Each item's share of the wave passing through it, `0` at rest and `1` at the crest. */
26
- export interface WaveState {
27
- style: WaveStyle
28
- /** How big the crest is — a share of the item's size, opacity or a turn, by style. */
29
- amount: number
30
- values: readonly number[]
31
- }
32
-
33
- /** Each item's emphasis: `1` the focus, `-1` pushed back, `0` untouched. */
34
- export interface FocusState {
35
- /** How far the others fade, `0..1`. */
36
- dim: number
37
- /** How much the focus grows, as a share of its size; the others shrink by half that. */
38
- grow: number
39
- values: readonly number[]
40
- }
41
-
42
- /** Layer item `i`'s reveal, wave and focus onto its slot, in place. */
43
- export function applyItemEffects(
44
- s: Slot,
45
- i: number,
46
- size: Size2D,
47
- reveal: RevealState | null | undefined,
48
- wave: WaveState | null | undefined,
49
- focus: FocusState | null | undefined,
50
- ): void {
51
- if (reveal) applyReveal(s, reveal.style, reveal.values[i] ?? 1, size)
52
- if (wave) applyWave(s, wave, wave.values[i] ?? 0, size)
53
- if (focus) applyFocus(s, focus, focus.values[i] ?? 0)
54
- }
55
-
56
- function applyReveal(s: Slot, style: RevealStyle, v: number, size: Size2D): void {
57
- if (v === 1) return
58
- const shown = clamp01(v)
59
- switch (style) {
60
- case "fade":
61
- s.opacity *= shown
62
- break
63
- case "center":
64
- s.x *= v
65
- s.y *= v
66
- s.depth *= v
67
- s.opacity *= clamp01(v * 4)
68
- break
69
- case "rise":
70
- s.y -= (1 - v) * Math.max(40, size.height)
71
- s.opacity *= shown
72
- break
73
- case "flip":
74
- s.rotationX += (1 - v) * 90
75
- break
76
- case "spin":
77
- s.rotation -= (1 - v) * 180
78
- s.scale *= Math.max(0, v)
79
- break
80
- default:
81
- s.scale *= Math.max(0, v)
82
- }
83
- }
84
-
85
- function applyWave(s: Slot, wave: WaveState, w: number, size: Size2D): void {
86
- if (w === 0) return
87
- switch (wave.style) {
88
- case "lift":
89
- s.y += wave.amount * w * Math.max(40, size.height)
90
- break
91
- case "fade":
92
- s.opacity *= clamp01(1 - wave.amount * w)
93
- break
94
- case "spin":
95
- s.rotation += wave.amount * w * 360
96
- break
97
- default:
98
- s.scale *= 1 + wave.amount * w
99
- }
100
- }
101
-
102
- function applyFocus(s: Slot, focus: FocusState, f: number): void {
103
- if (f === 0) return
104
- if (f > 0) {
105
- s.scale *= 1 + focus.grow * f
106
- return
107
- }
108
- s.opacity *= clamp01(1 - focus.dim * -f)
109
- s.scale *= Math.max(0, 1 + focus.grow * 0.5 * f)
110
- }
111
-
112
- function clamp01(v: number): number {
113
- return v < 0 ? 0 : v > 1 ? 1 : v
114
- }
1
+ import type { Size2D } from "@motionscript/sdk"
2
+
3
+ import type { Slot } from "./slots"
4
+
5
+ /**
6
+ * What an item does on its way in (or out): grow from nothing, fade, fly out of
7
+ * the grid's centre, rise into place, flip up, or spin in.
8
+ */
9
+ export const REVEAL_STYLES = ["scale", "fade", "center", "rise", "flip", "spin"] as const
10
+ export type RevealStyle = (typeof REVEAL_STYLES)[number]
11
+
12
+ /** What a wave does to each item as it passes. */
13
+ export const WAVE_STYLES = ["scale", "lift", "fade", "spin"] as const
14
+ export type WaveStyle = (typeof WAVE_STYLES)[number]
15
+
16
+ /**
17
+ * How far into view each item is, `1` shown and `0` gone — past `1` on the
18
+ * way to it under an overshooting ease. Absent means every item is shown.
19
+ */
20
+ export interface RevealState {
21
+ style: RevealStyle
22
+ values: readonly number[]
23
+ }
24
+
25
+ /** Each item's share of the wave passing through it, `0` at rest and `1` at the crest. */
26
+ export interface WaveState {
27
+ style: WaveStyle
28
+ /** How big the crest is — a share of the item's size, opacity or a turn, by style. */
29
+ amount: number
30
+ values: readonly number[]
31
+ }
32
+
33
+ /** Each item's emphasis: `1` the focus, `-1` pushed back, `0` untouched. */
34
+ export interface FocusState {
35
+ /** How far the others fade, `0..1`. */
36
+ dim: number
37
+ /** How much the focus grows, as a share of its size; the others shrink by half that. */
38
+ grow: number
39
+ values: readonly number[]
40
+ }
41
+
42
+ /** Layer item `i`'s reveal, wave and focus onto its slot, in place. */
43
+ export function applyItemEffects(
44
+ s: Slot,
45
+ i: number,
46
+ size: Size2D,
47
+ reveal: RevealState | null | undefined,
48
+ wave: WaveState | null | undefined,
49
+ focus: FocusState | null | undefined,
50
+ ): void {
51
+ if (reveal) applyReveal(s, reveal.style, reveal.values[i] ?? 1, size)
52
+ if (wave) applyWave(s, wave, wave.values[i] ?? 0, size)
53
+ if (focus) applyFocus(s, focus, focus.values[i] ?? 0)
54
+ }
55
+
56
+ function applyReveal(s: Slot, style: RevealStyle, v: number, size: Size2D): void {
57
+ if (v === 1) return
58
+ const shown = clamp01(v)
59
+ switch (style) {
60
+ case "fade":
61
+ s.opacity *= shown
62
+ break
63
+ case "center":
64
+ s.x *= v
65
+ s.y *= v
66
+ s.depth *= v
67
+ s.opacity *= clamp01(v * 4)
68
+ break
69
+ case "rise":
70
+ s.y -= (1 - v) * Math.max(40, size.height)
71
+ s.opacity *= shown
72
+ break
73
+ case "flip":
74
+ s.rotationX += (1 - v) * 90
75
+ break
76
+ case "spin":
77
+ s.rotation -= (1 - v) * 180
78
+ s.scale *= Math.max(0, v)
79
+ break
80
+ default:
81
+ s.scale *= Math.max(0, v)
82
+ }
83
+ }
84
+
85
+ function applyWave(s: Slot, wave: WaveState, w: number, size: Size2D): void {
86
+ if (w === 0) return
87
+ switch (wave.style) {
88
+ case "lift":
89
+ s.y += wave.amount * w * Math.max(40, size.height)
90
+ break
91
+ case "fade":
92
+ s.opacity *= clamp01(1 - wave.amount * w)
93
+ break
94
+ case "spin":
95
+ s.rotation += wave.amount * w * 360
96
+ break
97
+ default:
98
+ s.scale *= 1 + wave.amount * w
99
+ }
100
+ }
101
+
102
+ function applyFocus(s: Slot, focus: FocusState, f: number): void {
103
+ if (f === 0) return
104
+ if (f > 0) {
105
+ s.scale *= 1 + focus.grow * f
106
+ return
107
+ }
108
+ s.opacity *= clamp01(1 - focus.dim * -f)
109
+ s.scale *= Math.max(0, 1 + focus.grow * 0.5 * f)
110
+ }
111
+
112
+ function clamp01(v: number): number {
113
+ return v < 0 ? 0 : v > 1 ? 1 : v
114
+ }