@motionscript/layout-grid 0.0.0-stage → 0.1.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/LICENSE +201 -0
- package/dist/browser/chunks/chunk-LEUMKC3A.js +2 -0
- package/dist/browser/chunks/chunk-LEUMKC3A.js.map +7 -0
- package/dist/browser/index.js +2 -0
- package/dist/browser/index.js.map +7 -0
- package/dist/browser/kit.js +2 -0
- package/dist/browser/kit.js.map +7 -0
- package/dist/browser/manifest.json +12 -0
- package/dist/engine.d.ts +13 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +13 -0
- package/dist/engine.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/kit/index.d.ts +7 -0
- package/dist/kit/index.d.ts.map +1 -0
- package/dist/kit/index.js +7 -0
- package/dist/kit/index.js.map +1 -0
- package/dist/kit/item-effects.d.ts +37 -0
- package/dist/kit/item-effects.d.ts.map +1 -0
- package/dist/kit/item-effects.js +76 -0
- package/dist/kit/item-effects.js.map +1 -0
- package/dist/kit/layout-grid.d.ts +243 -0
- package/dist/kit/layout-grid.d.ts.map +1 -0
- package/dist/kit/layout-grid.js +542 -0
- package/dist/kit/layout-grid.js.map +1 -0
- package/dist/kit/order.d.ts +13 -0
- package/dist/kit/order.d.ts.map +1 -0
- package/dist/kit/order.js +43 -0
- package/dist/kit/order.js.map +1 -0
- package/dist/kit/random.d.ts +7 -0
- package/dist/kit/random.d.ts.map +1 -0
- package/dist/kit/random.js +29 -0
- package/dist/kit/random.js.map +1 -0
- package/dist/kit/slots/index.d.ts +22 -0
- package/dist/kit/slots/index.d.ts.map +1 -0
- package/dist/kit/slots/index.js +28 -0
- package/dist/kit/slots/index.js.map +1 -0
- package/dist/kit/slots/path-templates.d.ts +15 -0
- package/dist/kit/slots/path-templates.d.ts.map +1 -0
- package/dist/kit/slots/path-templates.js +113 -0
- package/dist/kit/slots/path-templates.js.map +1 -0
- package/dist/kit/slots/path.d.ts +45 -0
- package/dist/kit/slots/path.d.ts.map +1 -0
- package/dist/kit/slots/path.js +87 -0
- package/dist/kit/slots/path.js.map +1 -0
- package/dist/kit/slots/radial.d.ts +30 -0
- package/dist/kit/slots/radial.d.ts.map +1 -0
- package/dist/kit/slots/radial.js +45 -0
- package/dist/kit/slots/radial.js.map +1 -0
- package/dist/kit/slots/rectangular.d.ts +42 -0
- package/dist/kit/slots/rectangular.d.ts.map +1 -0
- package/dist/kit/slots/rectangular.js +79 -0
- package/dist/kit/slots/rectangular.js.map +1 -0
- package/dist/kit/slots/slot.d.ts +62 -0
- package/dist/kit/slots/slot.d.ts.map +1 -0
- package/dist/kit/slots/slot.js +41 -0
- package/dist/kit/slots/slot.js.map +1 -0
- package/dist/kit/slots/sphere.d.ts +36 -0
- package/dist/kit/slots/sphere.d.ts.map +1 -0
- package/dist/kit/slots/sphere.js +68 -0
- package/dist/kit/slots/sphere.js.map +1 -0
- package/dist/kit/stagger.d.ts +24 -0
- package/dist/kit/stagger.d.ts.map +1 -0
- package/dist/kit/stagger.js +90 -0
- package/dist/kit/stagger.js.map +1 -0
- package/dist/nodes.d.ts +15 -0
- package/dist/nodes.d.ts.map +1 -0
- package/dist/nodes.js +15 -0
- package/dist/nodes.js.map +1 -0
- package/dist/path-grid/index.d.ts +2 -0
- package/dist/path-grid/index.d.ts.map +1 -0
- package/dist/path-grid/index.js +2 -0
- package/dist/path-grid/index.js.map +1 -0
- package/dist/path-grid/path-grid.d.ts +82 -0
- package/dist/path-grid/path-grid.d.ts.map +1 -0
- package/dist/path-grid/path-grid.js +192 -0
- package/dist/path-grid/path-grid.js.map +1 -0
- package/dist/radial-grid/index.d.ts +2 -0
- package/dist/radial-grid/index.d.ts.map +1 -0
- package/dist/radial-grid/index.js +2 -0
- package/dist/radial-grid/index.js.map +1 -0
- package/dist/radial-grid/radial-grid.d.ts +51 -0
- package/dist/radial-grid/radial-grid.d.ts.map +1 -0
- package/dist/radial-grid/radial-grid.js +95 -0
- package/dist/radial-grid/radial-grid.js.map +1 -0
- package/dist/rectangular-grid/index.d.ts +2 -0
- package/dist/rectangular-grid/index.d.ts.map +1 -0
- package/dist/rectangular-grid/index.js +2 -0
- package/dist/rectangular-grid/index.js.map +1 -0
- package/dist/rectangular-grid/rectangular-grid.d.ts +79 -0
- package/dist/rectangular-grid/rectangular-grid.d.ts.map +1 -0
- package/dist/rectangular-grid/rectangular-grid.js +156 -0
- package/dist/rectangular-grid/rectangular-grid.js.map +1 -0
- package/dist/sphere-grid/index.d.ts +2 -0
- package/dist/sphere-grid/index.d.ts.map +1 -0
- package/dist/sphere-grid/index.js +2 -0
- package/dist/sphere-grid/index.js.map +1 -0
- package/dist/sphere-grid/sphere-grid.d.ts +68 -0
- package/dist/sphere-grid/sphere-grid.d.ts.map +1 -0
- package/dist/sphere-grid/sphere-grid.js +149 -0
- package/dist/sphere-grid/sphere-grid.js.map +1 -0
- package/package.json +70 -3
- package/registry.json +32 -0
- package/src/engine.ts +12 -0
- package/src/index.ts +6 -0
- package/src/kit/index.ts +6 -0
- package/src/kit/item-effects.ts +114 -0
- package/src/kit/layout-grid.ts +605 -0
- package/src/kit/order.ts +41 -0
- package/src/kit/random.ts +29 -0
- package/src/kit/slots/index.ts +39 -0
- package/src/kit/slots/path-templates.ts +120 -0
- package/src/kit/slots/path.ts +120 -0
- package/src/kit/slots/radial.ts +62 -0
- package/src/kit/slots/rectangular.ts +108 -0
- package/src/kit/slots/slot.ts +82 -0
- package/src/kit/slots/sphere.ts +94 -0
- package/src/kit/stagger.ts +96 -0
- package/src/nodes.ts +15 -0
- package/src/path-grid/index.ts +1 -0
- package/src/path-grid/path-grid.ts +213 -0
- package/src/radial-grid/index.ts +1 -0
- package/src/radial-grid/radial-grid.ts +90 -0
- package/src/rectangular-grid/index.ts +1 -0
- package/src/rectangular-grid/rectangular-grid.ts +160 -0
- package/src/sphere-grid/index.ts +1 -0
- package/src/sphere-grid/sphere-grid.ts +143 -0
- package/README.md +0 -4
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { type Command, type CommandArgs, type NodeConfig, type PathData, type Size2D } from "@motionscript/sdk";
|
|
2
|
+
import { LayoutGrid, type LayoutGridProps, type PathArrangement, type PathSpacing, type StaggerArgs } from "../kit/index.js";
|
|
3
|
+
/** A template, or `custom` for the grid's own {@link PathGrid.path}. */
|
|
4
|
+
export declare const PATH_GRID_SHAPES: readonly ["circle", "square", "star", "heart", "infinity", "wave", "spiral", "arc", "line", "custom"];
|
|
5
|
+
export type PathGridShape = (typeof PATH_GRID_SHAPES)[number];
|
|
6
|
+
export interface PathGridProps extends LayoutGridProps {
|
|
7
|
+
shape: PathGridShape;
|
|
8
|
+
path: PathData;
|
|
9
|
+
pathNode: string;
|
|
10
|
+
spacing: PathSpacing;
|
|
11
|
+
spacingDistance: number;
|
|
12
|
+
offset: number;
|
|
13
|
+
flowSpeed: number;
|
|
14
|
+
trimStart: number;
|
|
15
|
+
trimEnd: number;
|
|
16
|
+
alignToPath: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Children along a path: one of the templates drawn to fill the node's box,
|
|
20
|
+
* a path of the grid's own, or a `Path` node elsewhere in the scene, followed
|
|
21
|
+
* wherever it is.
|
|
22
|
+
*
|
|
23
|
+
* Items are spaced by distance along the curve, so they sit evenly on a tight
|
|
24
|
+
* bend and a straight alike. Animating {@link offset} moves them along it — on
|
|
25
|
+
* a closed path they come round again, which is a conveyor belt for free.
|
|
26
|
+
*/
|
|
27
|
+
export declare class PathGrid extends LayoutGrid<PathGridProps> {
|
|
28
|
+
shape: PathGridShape;
|
|
29
|
+
/** Used when {@link shape} is `custom`: an SVG path, y-down as SVG writes one, centred on its own bounds. */
|
|
30
|
+
path: PathData;
|
|
31
|
+
/** A path node to follow instead, by id — the items track it wherever it goes. */
|
|
32
|
+
pathNode: string;
|
|
33
|
+
spacing: PathSpacing;
|
|
34
|
+
spacingDistance: number;
|
|
35
|
+
/** Share of the path the items are moved along — `1` is once round. */
|
|
36
|
+
offset: number;
|
|
37
|
+
/** Share of the path per second the items travel on their own. */
|
|
38
|
+
flowSpeed: number;
|
|
39
|
+
trimStart: number;
|
|
40
|
+
trimEnd: number;
|
|
41
|
+
alignToPath: boolean;
|
|
42
|
+
constructor(props?: NodeConfig<PathGrid, PathGridProps>);
|
|
43
|
+
/** Move the items along the path by `loops` — `1` is once round, and they keep their spacing. */
|
|
44
|
+
flow(args: CommandArgs<{
|
|
45
|
+
loops?: number;
|
|
46
|
+
}> & {
|
|
47
|
+
duration: number;
|
|
48
|
+
}): Command<PathGridProps>;
|
|
49
|
+
/** Squeeze the items into part of the path, between two shares of its length. */
|
|
50
|
+
trimTo(args: CommandArgs<{
|
|
51
|
+
trimStart?: number;
|
|
52
|
+
trimEnd?: number;
|
|
53
|
+
}> & {
|
|
54
|
+
duration: number;
|
|
55
|
+
}): Command<PathGridProps>;
|
|
56
|
+
/**
|
|
57
|
+
* Move the items onto another path — a template, or a `Path` node in the
|
|
58
|
+
* scene. Each item travels from its place on the old path to its place on the
|
|
59
|
+
* new one; the path itself is not morphed.
|
|
60
|
+
*/
|
|
61
|
+
setPath(args: CommandArgs<{
|
|
62
|
+
shape?: PathGridShape;
|
|
63
|
+
pathNode?: string;
|
|
64
|
+
} & StaggerArgs> & {
|
|
65
|
+
duration: number;
|
|
66
|
+
}): Command<PathGridProps>;
|
|
67
|
+
protected arrangementFor(box: Size2D): PathArrangement;
|
|
68
|
+
protected applyDefaultSize(props?: {
|
|
69
|
+
readonly width?: unknown;
|
|
70
|
+
readonly height?: unknown;
|
|
71
|
+
}): void;
|
|
72
|
+
private _linked;
|
|
73
|
+
/** The path the items follow, and where its coordinates land in this grid's frame. */
|
|
74
|
+
private _pathIn;
|
|
75
|
+
/**
|
|
76
|
+
* A path node's geometry as it draws it: stored in its unit box, y-down, and
|
|
77
|
+
* scaled to its laid-out size — kept while neither changes, so the path's
|
|
78
|
+
* measurement is kept with it.
|
|
79
|
+
*/
|
|
80
|
+
private _unitPath;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=path-grid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-grid.d.ts","sourceRoot":"","sources":["../../src/path-grid/path-grid.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,MAAM,EACZ,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAGL,UAAU,EAMV,KAAK,eAAe,EACpB,KAAK,eAAe,EAEpB,KAAK,WAAW,EAEhB,KAAK,WAAW,EACjB,MAAM,QAAQ,CAAA;AAEf,wEAAwE;AACxE,eAAO,MAAM,gBAAgB,uGAAyC,CAAA;AACtE,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAA;AAE7D,MAAM,WAAW,aAAc,SAAQ,eAAe;IACpD,KAAK,EAAE,aAAa,CAAA;IACpB,IAAI,EAAE,QAAQ,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,WAAW,CAAA;IACpB,eAAe,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,EAAE,OAAO,CAAA;CACrB;AAOD;;;;;;;;GAQG;AACH,qBAca,QAAS,SAAQ,UAAU,CAAC,aAAa,CAAC;IAC6B,KAAK,EAAE,aAAa,CAAA;IACtG,6GAA6G;IACrF,IAAI,EAAE,QAAQ,CAAA;IACtC,kFAAkF;IACU,QAAQ,EAAE,MAAM,CAAA;IACzB,OAAO,EAAE,WAAW,CAAA;IACnD,eAAe,EAAE,MAAM,C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|
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 { command, node, Path, pathOps, PathShape, pathProperty, property, } from "@motionscript/sdk";
|
|
8
|
+
import { findNode2D, frameIn, LayoutGrid, PATH_SPACINGS, PATH_TEMPLATES, staggerArgs, TRANSITION_STAGGER, templatePath, } from "../kit/index.js";
|
|
9
|
+
/** A template, or `custom` for the grid's own {@link PathGrid.path}. */
|
|
10
|
+
export const PATH_GRID_SHAPES = [...PATH_TEMPLATES, "custom"];
|
|
11
|
+
const AT_ORIGIN = { originX: 0, originY: 0, x: 0, y: 0, rotation: 0, scale: 1 };
|
|
12
|
+
/** The size a path grid is placed at when nothing says otherwise, since a template is drawn to fill it. */
|
|
13
|
+
const DEFAULT_SIZE = { width: 640, height: 400 };
|
|
14
|
+
/**
|
|
15
|
+
* Children along a path: one of the templates drawn to fill the node's box,
|
|
16
|
+
* a path of the grid's own, or a `Path` node elsewhere in the scene, followed
|
|
17
|
+
* wherever it is.
|
|
18
|
+
*
|
|
19
|
+
* Items are spaced by distance along the curve, so they sit evenly on a tight
|
|
20
|
+
* bend and a straight alike. Animating {@link offset} moves them along it — on
|
|
21
|
+
* a closed path they come round again, which is a conveyor belt for free.
|
|
22
|
+
*/
|
|
23
|
+
let PathGrid = class PathGrid extends LayoutGrid {
|
|
24
|
+
constructor(props) {
|
|
25
|
+
super(props);
|
|
26
|
+
}
|
|
27
|
+
/** Move the items along the path by `loops` — `1` is once round, and they keep their spacing. */
|
|
28
|
+
flow(args) {
|
|
29
|
+
const loops = args.data?.loops ?? 1;
|
|
30
|
+
return this.to({ data: { offset: this.offset + loops }, duration: args.duration, easing: args.easing });
|
|
31
|
+
}
|
|
32
|
+
/** Squeeze the items into part of the path, between two shares of its length. */
|
|
33
|
+
trimTo(args) {
|
|
34
|
+
return this.to({
|
|
35
|
+
data: { trimStart: args.data?.trimStart ?? this.trimStart, trimEnd: args.data?.trimEnd ?? this.trimEnd },
|
|
36
|
+
duration: args.duration,
|
|
37
|
+
easing: args.easing,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Move the items onto another path — a template, or a `Path` node in the
|
|
42
|
+
* scene. Each item travels from its place on the old path to its place on the
|
|
43
|
+
* new one; the path itself is not morphed.
|
|
44
|
+
*/
|
|
45
|
+
setPath(args) {
|
|
46
|
+
const pathNode = args.data?.pathNode ?? "";
|
|
47
|
+
const changes = pathNode ? { pathNode } : { shape: args.data?.shape ?? this.shape, pathNode: "" };
|
|
48
|
+
return this._transitionTo(changes, args);
|
|
49
|
+
}
|
|
50
|
+
arrangementFor(box) {
|
|
51
|
+
const { path, placement } = this._pathIn(box);
|
|
52
|
+
return {
|
|
53
|
+
kind: "path",
|
|
54
|
+
path,
|
|
55
|
+
placement,
|
|
56
|
+
spacing: this.spacing,
|
|
57
|
+
spacingDistance: this.spacingDistance,
|
|
58
|
+
offset: this.offset,
|
|
59
|
+
flowSpeed: this.flowSpeed,
|
|
60
|
+
trimStart: this.trimStart,
|
|
61
|
+
trimEnd: this.trimEnd,
|
|
62
|
+
alignToPath: this.alignToPath,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
// A template is drawn to fill the box, so a path grid needs one of its own
|
|
66
|
+
// rather than hugging items whose places depend on it.
|
|
67
|
+
applyDefaultSize(props) {
|
|
68
|
+
if (!props || props.width === undefined)
|
|
69
|
+
this.applyProp("width", DEFAULT_SIZE.width);
|
|
70
|
+
if (!props || props.height === undefined)
|
|
71
|
+
this.applyProp("height", DEFAULT_SIZE.height);
|
|
72
|
+
}
|
|
73
|
+
_linked = null;
|
|
74
|
+
/** The path the items follow, and where its coordinates land in this grid's frame. */
|
|
75
|
+
_pathIn(box) {
|
|
76
|
+
const linked = this.pathNode ? findNode2D(this, this.pathNode) : null;
|
|
77
|
+
if (linked instanceof PathShape) {
|
|
78
|
+
return { path: this._unitPath(linked), placement: { ...AT_ORIGIN, ...frameIn(this, linked) } };
|
|
79
|
+
}
|
|
80
|
+
if (linked instanceof Path && pathOps.bounds(linked.data)) {
|
|
81
|
+
// A `Path` draws its data centred on the data's own bounds, at its own position.
|
|
82
|
+
const bounds = pathOps.bounds(linked.data);
|
|
83
|
+
const frame = frameIn(this, linked);
|
|
84
|
+
return {
|
|
85
|
+
path: linked.data,
|
|
86
|
+
placement: {
|
|
87
|
+
originX: (bounds.minX + bounds.maxX) / 2,
|
|
88
|
+
originY: (bounds.minY + bounds.maxY) / 2,
|
|
89
|
+
...frame,
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
if (this.shape === "custom") {
|
|
94
|
+
const bounds = pathOps.bounds(this.path);
|
|
95
|
+
if (bounds) {
|
|
96
|
+
return {
|
|
97
|
+
path: this.path,
|
|
98
|
+
placement: {
|
|
99
|
+
...AT_ORIGIN,
|
|
100
|
+
originX: (bounds.minX + bounds.maxX) / 2,
|
|
101
|
+
originY: (bounds.minY + bounds.maxY) / 2,
|
|
102
|
+
flipY: true,
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const template = this.shape === "custom" ? "circle" : this.shape;
|
|
108
|
+
return { path: templatePath(template, box), placement: AT_ORIGIN };
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* A path node's geometry as it draws it: stored in its unit box, y-down, and
|
|
112
|
+
* scaled to its laid-out size — kept while neither changes, so the path's
|
|
113
|
+
* measurement is kept with it.
|
|
114
|
+
*/
|
|
115
|
+
_unitPath(shape) {
|
|
116
|
+
const { width, height } = shape.layoutBounds;
|
|
117
|
+
const cached = this._linked;
|
|
118
|
+
if (cached && cached.data === shape.data && cached.width === width && cached.height === height)
|
|
119
|
+
return cached.path;
|
|
120
|
+
const path = pathOps.anchorCommands(pathOps.anchors(shape.data), (p) => ({ x: p.x * width, y: -p.y * height }));
|
|
121
|
+
this._linked = { data: shape.data, width, height, path };
|
|
122
|
+
return path;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
__decorate([
|
|
126
|
+
property({ default: "circle", kind: "enum", options: PATH_GRID_SHAPES })
|
|
127
|
+
], PathGrid.prototype, "shape", void 0);
|
|
128
|
+
__decorate([
|
|
129
|
+
pathProperty()
|
|
130
|
+
], PathGrid.prototype, "path", void 0);
|
|
131
|
+
__decorate([
|
|
132
|
+
property({ default: "", kind: "nodeRef", nodeTypes: ["path"], animatable: false })
|
|
133
|
+
], PathGrid.prototype, "pathNode", void 0);
|
|
134
|
+
__decorate([
|
|
135
|
+
property({ default: "distribute", kind: "enum", options: PATH_SPACINGS })
|
|
136
|
+
], PathGrid.prototype, "spacing", void 0);
|
|
137
|
+
__decorate([
|
|
138
|
+
property({ default: 80, min: 0, step: 1 })
|
|
139
|
+
], PathGrid.prototype, "spacingDistance", void 0);
|
|
140
|
+
__decorate([
|
|
141
|
+
property({ default: 0, step: 0.01 })
|
|
142
|
+
], PathGrid.prototype, "offset", void 0);
|
|
143
|
+
__decorate([
|
|
144
|
+
property({ default: 0, step: 0.01, unit: "/s" })
|
|
145
|
+
], PathGrid.prototype, "flowSpeed", void 0);
|
|
146
|
+
__decorate([
|
|
147
|
+
property({ default: 0, min: 0, max: 1, step: 0.01 })
|
|
148
|
+
], PathGrid.prototype, "trimStart", void 0);
|
|
149
|
+
__decorate([
|
|
150
|
+
property({ default: 1, min: 0, max: 1, step: 0.01 })
|
|
151
|
+
], PathGrid.prototype, "trimEnd", void 0);
|
|
152
|
+
__decorate([
|
|
153
|
+
property({ default: true })
|
|
154
|
+
], PathGrid.prototype, "alignToPath", void 0);
|
|
155
|
+
__decorate([
|
|
156
|
+
command({ args: [{ key: "loops", step: 0.25, default: 1 }] })
|
|
157
|
+
], PathGrid.prototype, "flow", null);
|
|
158
|
+
__decorate([
|
|
159
|
+
command({
|
|
160
|
+
args: [
|
|
161
|
+
{ key: "trimStart", min: 0, max: 1, step: 0.01, default: 0.25 },
|
|
162
|
+
{ key: "trimEnd", min: 0, max: 1, step: 0.01, default: 0.75 },
|
|
163
|
+
],
|
|
164
|
+
})
|
|
165
|
+
], PathGrid.prototype, "trimTo", null);
|
|
166
|
+
__decorate([
|
|
167
|
+
command({
|
|
168
|
+
args: [
|
|
169
|
+
{ key: "shape", kind: "enum", options: PATH_GRID_SHAPES, default: "heart" },
|
|
170
|
+
{ key: "pathNode", kind: "nodeRef", nodeTypes: ["path"] },
|
|
171
|
+
...staggerArgs(TRANSITION_STAGGER),
|
|
172
|
+
],
|
|
173
|
+
})
|
|
174
|
+
], PathGrid.prototype, "setPath", null);
|
|
175
|
+
PathGrid = __decorate([
|
|
176
|
+
node({
|
|
177
|
+
key: "pathGrid",
|
|
178
|
+
parentKey: "node",
|
|
179
|
+
forkable: true,
|
|
180
|
+
layout: {
|
|
181
|
+
children: "flow",
|
|
182
|
+
acceptsChildren: true,
|
|
183
|
+
defaultWidthMode: "fixed",
|
|
184
|
+
defaultHeightMode: "fixed",
|
|
185
|
+
defaultWidth: DEFAULT_SIZE.width,
|
|
186
|
+
defaultHeight: DEFAULT_SIZE.height,
|
|
187
|
+
},
|
|
188
|
+
seed: { ...DEFAULT_SIZE },
|
|
189
|
+
})
|
|
190
|
+
], PathGrid);
|
|
191
|
+
export { PathGrid };
|
|
192
|
+
//# sourceMappingURL=path-grid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-grid.js","sourceRoot":"","sources":["../../src/path-grid/path-grid.ts"],"names":[],"mappings":";;;;;;AAAA,OAA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\n node,\n Path,\n pathOps,\n PathShape,\n pathProperty,\n property,\n type Command,\n type CommandArgs,\n type NodeConfig,\n type PathData,\n type Size2D,\n} from \"@motionscript/sdk\"\n\nimport {\n findNode2D,\n frameIn,\n LayoutGrid,\n PATH_SPACINGS,\n PATH_TEMPLATES,\n staggerArgs,\n TRANSITION_STAGGER,\n templatePath,\n type LayoutGridProps,\n type PathArrangement,\n type PathPlacement,\n type PathSpacing,\n type PathTemplate,\n type StaggerArgs,\n} from \"../kit\"\n\n/** A template, or `custom` for the grid's own {@link PathGrid.path}. */\nexport const PATH_GRID_SHAPES = [...PATH_TEMPLATES, \"custom\"] as const\nexport type PathGridShape = (typeof PATH_GRID_SHAPES)[number]\n\nexport interface PathGridProps extends LayoutGridProps {\n shape: PathGridShape\n path: PathData\n pathNode: string\n spacing: PathSpacing\n spacingDistance: number\n offset: number\n flowSpeed: number\n trimStart: number\n trimEnd: number\n alignToPath: boolean\n}\n\nconst AT_ORIGIN: PathPlacement = { originX: 0, originY: 0, x: 0, y: 0, rotation: 0, scale: 1 }\n\n/** The size a path grid is placed at when nothing says otherwise, since a template is drawn to fill it. */\nconst DEFAULT_SIZE = { width: 640, height: 400 }\n\n/**\n * Children along a path: one of the templates drawn to fill the node's box,\n * a path of the grid's own, or a `Path` node elsewhere in the scene, followed\n * wherever it is.\n *\n * Items are spaced by distance along the curve, so they sit evenly on a tight\n * bend and a straight alike. Animating {@link offset} moves them along it — on\n * a closed path they come round again, which is a conveyor belt for free.\n */\n@node({\n key: \"pathGrid\",\n parentKey: \"node\",\n forkable: true,\n layout: {\n children: \"flow\",\n acceptsChildren: true,\n defaultWidthMode: \"fixed\",\n defaultHeightMode: \"fixed\",\n defaultWidth: DEFAULT_SIZE.width,\n defaultHeight: DEFAULT_SIZE.height,\n },\n seed: { ...DEFAULT_SIZE },\n})\nexport class PathGrid extends LayoutGrid<PathGridProps> {\n @property({ default: \"circle\", kind: \"enum\", options: PATH_GRID_SHAPES }) declare shape: PathGridShape\n /** Used when {@link shape} is `custom`: an SVG path, y-down as SVG writes one, centred on its own bounds. */\n @pathProperty() declare path: PathData\n /** A path node to follow instead, by id — the items track it wherever it goes. */\n @property({ default: \"\", kind: \"nodeRef\", nodeTypes: [\"path\"], animatable: false }) declare pathNode: string\n @property({ default: \"distribute\", kind: \"enum\", options: PATH_SPACINGS }) declare spacing: PathSpacing\n @property({ default: 80, min: 0, step: 1 }) declare spacingDistance: number\n /** Share of the path the items are moved along — `1` is once round. */\n @property({ default: 0, step: 0.01 }) declare offset: number\n /** Share of the path per second the items travel on their own. */\n @property({ default: 0, step: 0.01, unit: \"/s\" }) declare flowSpeed: number\n @property({ default: 0, min: 0, max: 1, step: 0.01 }) declare trimStart: number\n @property({ default: 1, min: 0, max: 1, step: 0.01 }) declare trimEnd: number\n @property({ default: true }) declare alignToPath: boolean\n\n constructor(props?: NodeConfig<PathGrid, PathGridProps>) {\n super(props)\n }\n\n /** Move the items along the path by `loops` — `1` is once round, and they keep their spacing. */\n @command({ args: [{ key: \"loops\", step: 0.25, default: 1 }] })\n flow(args: CommandArgs<{ loops?: number }> & { duration: number }): Command<PathGridProps> {\n const loops = args.data?.loops ?? 1\n return this.to({ data: { offset: this.offset + loops }, duration: args.duration, easing: args.easing })\n }\n\n /** Squeeze the items into part of the path, between two shares of its length. */\n @command({\n args: [\n { key: \"trimStart\", min: 0, max: 1, step: 0.01, default: 0.25 },\n { key: \"trimEnd\", min: 0, max: 1, step: 0.01, default: 0.75 },\n ],\n })\n trimTo(args: CommandArgs<{ trimStart?: number; trimEnd?: number }> & { duration: number }): Command<PathGridProps> {\n return this.to({\n data: { trimStart: args.data?.trimStart ?? this.trimStart, trimEnd: args.data?.trimEnd ?? this.trimEnd },\n duration: args.duration,\n easing: args.easing,\n })\n }\n\n /**\n * Move the items onto another path — a template, or a `Path` node in the\n * scene. Each item travels from its place on the old path to its place on the\n * new one; the path itself is not morphed.\n */\n @command({\n args: [\n { key: \"shape\", kind: \"enum\", options: PATH_GRID_SHAPES, default: \"heart\" },\n { key: \"pathNode\", kind: \"nodeRef\", nodeTypes: [\"path\"] },\n ...staggerArgs(TRANSITION_STAGGER),\n ],\n })\n setPath(args: CommandArgs<{ shape?: PathGridShape; pathNode?: string } & StaggerArgs> & { duration: number }): Command<PathGridProps> {\n const pathNode = args.data?.pathNode ?? \"\"\n const changes: Partial<PathGridProps> = pathNode ? { pathNode } : { shape: args.data?.shape ?? this.shape, pathNode: \"\" }\n return this._transitionTo(changes, args)\n }\n\n protected override arrangementFor(box: Size2D): PathArrangement {\n const { path, placement } = this._pathIn(box)\n return {\n kind: \"path\",\n path,\n placement,\n spacing: this.spacing,\n spacingDistance: this.spacingDistance,\n offset: this.offset,\n flowSpeed: this.flowSpeed,\n trimStart: this.trimStart,\n trimEnd: this.trimEnd,\n alignToPath: this.alignToPath,\n }\n }\n\n // A template is drawn to fill the box, so a path grid needs one of its own\n // rather than hugging items whose places depend on it.\n protected override applyDefaultSize(props?: { readonly width?: unknown; readonly height?: unknown }): void {\n if (!props || props.width === undefined) this.applyProp(\"width\", DEFAULT_SIZE.width)\n if (!props || props.height === undefined) this.applyProp(\"height\", DEFAULT_SIZE.height)\n }\n\n private _linked: { data: PathData; width: number; height: number; path: PathData } | null = null\n\n /** The path the items follow, and where its coordinates land in this grid's frame. */\n private _pathIn(box: Size2D): { path: PathData; placement: PathPlacement } {\n const linked = this.pathNode ? findNode2D(this, this.pathNode) : null\n if (linked instanceof PathShape) {\n return { path: this._unitPath(linked), placement: { ...AT_ORIGIN, ...frameIn(this, linked) } }\n }\n if (linked instanceof Path && pathOps.bounds(linked.data)) {\n // A `Path` draws its data centred on the data's own bounds, at its own position.\n const bounds = pathOps.bounds(linked.data)!\n const frame = frameIn(this, linked)\n return {\n path: linked.data,\n placement: {\n originX: (bounds.minX + bounds.maxX) / 2,\n originY: (bounds.minY + bounds.maxY) / 2,\n ...frame,\n },\n }\n }\n if (this.shape === \"custom\") {\n const bounds = pathOps.bounds(this.path)\n if (bounds) {\n return {\n path: this.path,\n placement: {\n ...AT_ORIGIN,\n originX: (bounds.minX + bounds.maxX) / 2,\n originY: (bounds.minY + bounds.maxY) / 2,\n flipY: true,\n },\n }\n }\n }\n const template: PathTemplate = this.shape === \"custom\" ? \"circle\" : this.shape\n return { path: templatePath(template, box), placement: AT_ORIGIN }\n }\n\n /**\n * A path node's geometry as it draws it: stored in its unit box, y-down, and\n * scaled to its laid-out size — kept while neither changes, so the path's\n * measurement is kept with it.\n */\n private _unitPath(shape: PathShape): PathData {\n const { width, height } = shape.layoutBounds\n const cached = this._linked\n if (cached && cached.data === shape.data && cached.width === width && cached.height === height) return cached.path\n const path = pathOps.anchorCommands(pathOps.anchors(shape.data), (p) => ({ x: p.x * width, y: -p.y * height }))\n this._linked = { data: shape.data, width, height, path }\n return path\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/radial-grid/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/radial-grid/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA","sourcesContent":["export * from \"./radial-grid\"\n"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type Command, type CommandArgs, type NodeConfig } from "@motionscript/sdk";
|
|
2
|
+
import { LayoutGrid, type LayoutGridProps, type RadialArrangement, type RadialDirection } from "../kit/index.js";
|
|
3
|
+
export interface RadialGridProps extends LayoutGridProps {
|
|
4
|
+
radius: number;
|
|
5
|
+
startAngle: number;
|
|
6
|
+
sweep: number;
|
|
7
|
+
direction: RadialDirection;
|
|
8
|
+
rotateItems: boolean;
|
|
9
|
+
spinSpeed: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Children round a circle, or along an arc of one.
|
|
13
|
+
*
|
|
14
|
+
* A full circle spaces the items evenly with none on top of another; an arc
|
|
15
|
+
* puts one at each end. Angles run clockwise from twelve o'clock, so
|
|
16
|
+
* {@link turnTo} can bring any item to the top like a dial.
|
|
17
|
+
*/
|
|
18
|
+
export declare class RadialGrid extends LayoutGrid<RadialGridProps> {
|
|
19
|
+
radius: number;
|
|
20
|
+
startAngle: number;
|
|
21
|
+
sweep: number;
|
|
22
|
+
direction: RadialDirection;
|
|
23
|
+
rotateItems: boolean;
|
|
24
|
+
spinSpeed: number;
|
|
25
|
+
constructor(props?: NodeConfig<RadialGrid, RadialGridProps>);
|
|
26
|
+
/** Orbit the items round the centre by `degrees` — `360` is one full turn. */
|
|
27
|
+
spin(args: CommandArgs<{
|
|
28
|
+
degrees?: number;
|
|
29
|
+
}> & {
|
|
30
|
+
duration: number;
|
|
31
|
+
}): Command<RadialGridProps>;
|
|
32
|
+
/** Turn the ring the shorter way round until an item (by its place in the layers) sits at the top. */
|
|
33
|
+
turnTo(args: CommandArgs<{
|
|
34
|
+
item?: number;
|
|
35
|
+
}> & {
|
|
36
|
+
duration: number;
|
|
37
|
+
}): Command<RadialGridProps>;
|
|
38
|
+
radiusTo(args: CommandArgs<{
|
|
39
|
+
radius: number;
|
|
40
|
+
}> & {
|
|
41
|
+
duration: number;
|
|
42
|
+
}): Command<RadialGridProps>;
|
|
43
|
+
/** Open or close the arc like a fan — from `0` to `360` is a reveal of its own. */
|
|
44
|
+
sweepTo(args: CommandArgs<{
|
|
45
|
+
sweep: number;
|
|
46
|
+
}> & {
|
|
47
|
+
duration: number;
|
|
48
|
+
}): Command<RadialGridProps>;
|
|
49
|
+
protected arrangementFor(): RadialArrangement;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=radial-grid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"radial-grid.d.ts","sourceRoot":"","sources":["../../src/radial-grid/radial-grid.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,OAAO,EAAE,KAAK,WAAW,EAAE,KA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AI,EAAE,WAAW,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,eAAe,CAAC;cAI3E,cAAc,IAAI,iBAAiB;CAWvD"}
|
|
@@ -0,0 +1,95 @@
|
|
|
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 { command, node, property } from "@motionscript/sdk";
|
|
8
|
+
import { LayoutGrid, normalizeOrder, RADIAL_DIRECTIONS, radialTurnToTop, } from "../kit/index.js";
|
|
9
|
+
/**
|
|
10
|
+
* Children round a circle, or along an arc of one.
|
|
11
|
+
*
|
|
12
|
+
* A full circle spaces the items evenly with none on top of another; an arc
|
|
13
|
+
* puts one at each end. Angles run clockwise from twelve o'clock, so
|
|
14
|
+
* {@link turnTo} can bring any item to the top like a dial.
|
|
15
|
+
*/
|
|
16
|
+
let RadialGrid = class RadialGrid extends LayoutGrid {
|
|
17
|
+
constructor(props) {
|
|
18
|
+
super(props);
|
|
19
|
+
}
|
|
20
|
+
/** Orbit the items round the centre by `degrees` — `360` is one full turn. */
|
|
21
|
+
spin(args) {
|
|
22
|
+
const degrees = args.data?.degrees ?? 360;
|
|
23
|
+
return this.to({ data: { startAngle: this.startAngle + degrees }, duration: args.duration, easing: args.easing });
|
|
24
|
+
}
|
|
25
|
+
/** Turn the ring the shorter way round until an item (by its place in the layers) sits at the top. */
|
|
26
|
+
turnTo(args) {
|
|
27
|
+
const count = this._itemCount();
|
|
28
|
+
const slot = normalizeOrder(this.order, count).indexOf(Math.round(args.data?.item ?? 0));
|
|
29
|
+
const turn = slot < 0 ? 0 : radialTurnToTop(this.arrangementFor(), count, slot);
|
|
30
|
+
return this.to({ data: { startAngle: this.startAngle + turn }, duration: args.duration, easing: args.easing });
|
|
31
|
+
}
|
|
32
|
+
radiusTo(args) {
|
|
33
|
+
return this.to({ data: { radius: args.data?.radius ?? this.radius }, duration: args.duration, easing: args.easing });
|
|
34
|
+
}
|
|
35
|
+
/** Open or close the arc like a fan — from `0` to `360` is a reveal of its own. */
|
|
36
|
+
sweepTo(args) {
|
|
37
|
+
return this.to({ data: { sweep: args.data?.sweep ?? this.sweep }, duration: args.duration, easing: args.easing });
|
|
38
|
+
}
|
|
39
|
+
arrangementFor() {
|
|
40
|
+
return {
|
|
41
|
+
kind: "radial",
|
|
42
|
+
radius: this.radius,
|
|
43
|
+
startAngle: this.startAngle,
|
|
44
|
+
sweep: this.sweep,
|
|
45
|
+
direction: this.direction,
|
|
46
|
+
rotateItems: this.rotateItems,
|
|
47
|
+
spinSpeed: this.spinSpeed,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
__decorate([
|
|
52
|
+
property({ default: 200, min: 0, step: 1 })
|
|
53
|
+
], RadialGrid.prototype, "radius", void 0);
|
|
54
|
+
__decorate([
|
|
55
|
+
property({ default: 0, step: 1, unit: "°" })
|
|
56
|
+
], RadialGrid.prototype, "startAngle", void 0);
|
|
57
|
+
__decorate([
|
|
58
|
+
property({ default: 360, min: -360, max: 360, step: 1, unit: "°" })
|
|
59
|
+
], RadialGrid.prototype, "sweep", void 0);
|
|
60
|
+
__decorate([
|
|
61
|
+
property({ default: "clockwise", kind: "enum", options: RADIAL_DIRECTIONS })
|
|
62
|
+
], RadialGrid.prototype, "direction", void 0);
|
|
63
|
+
__decorate([
|
|
64
|
+
property({ default: false })
|
|
65
|
+
], RadialGrid.prototype, "rotateItems", void 0);
|
|
66
|
+
__decorate([
|
|
67
|
+
property({ default: 0, step: 1, unit: "°/s" })
|
|
68
|
+
], RadialGrid.prototype, "spinSpeed", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
command({ args: [{ key: "degrees", step: 15, unit: "°", default: 360 }] })
|
|
71
|
+
], RadialGrid.prototype, "spin", null);
|
|
72
|
+
__decorate([
|
|
73
|
+
command({ args: [{ key: "item", min: 0, step: 1, default: 0 }] })
|
|
74
|
+
], RadialGrid.prototype, "turnTo", null);
|
|
75
|
+
__decorate([
|
|
76
|
+
command({ args: [{ key: "radius", min: 0, default: 280 }] })
|
|
77
|
+
], RadialGrid.prototype, "radiusTo", null);
|
|
78
|
+
__decorate([
|
|
79
|
+
command({ args: [{ key: "sweep", min: -360, max: 360, unit: "°", default: 360 }] })
|
|
80
|
+
], RadialGrid.prototype, "sweepTo", null);
|
|
81
|
+
RadialGrid = __decorate([
|
|
82
|
+
node({
|
|
83
|
+
key: "radialGrid",
|
|
84
|
+
parentKey: "node",
|
|
85
|
+
forkable: true,
|
|
86
|
+
layout: {
|
|
87
|
+
children: "flow",
|
|
88
|
+
acceptsChildren: true,
|
|
89
|
+
defaultWidthMode: "hug",
|
|
90
|
+
defaultHeightMode: "hug",
|
|
91
|
+
},
|
|
92
|
+
})
|
|
93
|
+
], RadialGrid);
|
|
94
|
+
export { RadialGrid };
|
|
95
|
+
//# sourceMappingURL=radial-grid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"radial-grid.js","sourceRoot":"","sources":["../../src/radial-grid/radial-grid.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAmD,MAAM,mBAAmB,CAAA;AAE5G,OAAO,EACL,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,eAAe,GAIhB,MAAM,QAAQ,CAAA;AAWf;;;;;;GAMG;AAYI,IAAM,UAAU,GAAhB,M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AAO,EAAE,KAAK,EAAE,CAAC;+CAA6B;AACF;IAAvD,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;6CAA0B;AAQzE;IADC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;sCAI1E;AAID;IADC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;wCAMjE;AAGD;IADC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;0CAG5D;AAID;IADC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;yCAGnF;AArCU,UAAU;IAXtB,IAAI,CAAC;QACJ,GAAG,EAAE,YAAY;QACjB,SAAS,EAAE,MAAM;QACjB,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE;YACN,QAAQ,EAAE,MAAM;YAChB,eAAe,EAAE,IAAI;YACrB,gBAAgB,EAAE,KAAK;YACvB,iBAAiB,EAAE,KAAK;SACzB;KACF,CAAC;GACW,UAAU,CAkDtB","sourcesContent":["import { command, node, property, type Command, type CommandArgs, type NodeConfig } from \"@motionscript/sdk\"\n\nimport {\n LayoutGrid,\n normalizeOrder,\n RADIAL_DIRECTIONS,\n radialTurnToTop,\n type LayoutGridProps,\n type RadialArrangement,\n type RadialDirection,\n} from \"../kit\"\n\nexport interface RadialGridProps extends LayoutGridProps {\n radius: number\n startAngle: number\n sweep: number\n direction: RadialDirection\n rotateItems: boolean\n spinSpeed: number\n}\n\n/**\n * Children round a circle, or along an arc of one.\n *\n * A full circle spaces the items evenly with none on top of another; an arc\n * puts one at each end. Angles run clockwise from twelve o'clock, so\n * {@link turnTo} can bring any item to the top like a dial.\n */\n@node({\n key: \"radialGrid\",\n parentKey: \"node\",\n forkable: true,\n layout: {\n children: \"flow\",\n acceptsChildren: true,\n defaultWidthMode: \"hug\",\n defaultHeightMode: \"hug\",\n },\n})\nexport class RadialGrid extends LayoutGrid<RadialGridProps> {\n @property({ default: 200, min: 0, step: 1 }) declare radius: number\n @property({ default: 0, step: 1, unit: \"°\" }) declare startAngle: number\n @property({ default: 360, min: -360, max: 360, step: 1, unit: \"°\" }) declare sweep: number\n @property({ default: \"clockwise\", kind: \"enum\", options: RADIAL_DIRECTIONS }) declare direction: RadialDirection\n @property({ default: false }) declare rotateItems: boolean\n @property({ default: 0, step: 1, unit: \"°/s\" }) declare spinSpeed: number\n\n constructor(props?: NodeConfig<RadialGrid, RadialGridProps>) {\n super(props)\n }\n\n /** Orbit the items round the centre by `degrees` — `360` is one full turn. */\n @command({ args: [{ key: \"degrees\", step: 15, unit: \"°\", default: 360 }] })\n spin(args: CommandArgs<{ degrees?: number }> & { duration: number }): Command<RadialGridProps> {\n const degrees = args.data?.degrees ?? 360\n return this.to({ data: { startAngle: this.startAngle + degrees }, duration: args.duration, easing: args.easing })\n }\n\n /** Turn the ring the shorter way round until an item (by its place in the layers) sits at the top. */\n @command({ args: [{ key: \"item\", min: 0, step: 1, default: 0 }] })\n turnTo(args: CommandArgs<{ item?: number }> & { duration: number }): Command<RadialGridProps> {\n const count = this._itemCount()\n const slot = normalizeOrder(this.order, count).indexOf(Math.round(args.data?.item ?? 0))\n const turn = slot < 0 ? 0 : radialTurnToTop(this.arrangementFor(), count, slot)\n return this.to({ data: { startAngle: this.startAngle + turn }, duration: args.duration, easing: args.easing })\n }\n\n @command({ args: [{ key: \"radius\", min: 0, default: 280 }] })\n radiusTo(args: CommandArgs<{ radius: number }> & { duration: number }): Command<RadialGridProps> {\n return this.to({ data: { radius: args.data?.radius ?? this.radius }, duration: args.duration, easing: args.easing })\n }\n\n /** Open or close the arc like a fan — from `0` to `360` is a reveal of its own. */\n @command({ args: [{ key: \"sweep\", min: -360, max: 360, unit: \"°\", default: 360 }] })\n sweepTo(args: CommandArgs<{ sweep: number }> & { duration: number }): Command<RadialGridProps> {\n return this.to({ data: { sweep: args.data?.sweep ?? this.sweep }, duration: args.duration, easing: args.easing })\n }\n\n protected override arrangementFor(): RadialArrangement {\n return {\n kind: \"radial\",\n radius: this.radius,\n startAngle: this.startAngle,\n sweep: this.sweep,\n direction: this.direction,\n rotateItems: this.rotateItems,\n spinSpeed: this.spinSpeed,\n }\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rectangular-grid/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rectangular-grid/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA","sourcesContent":["export * from \"./rectangular-grid\"\n"]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { type Command, type CommandArgs, type NodeConfig, type Size2D } from "@motionscript/sdk";
|
|
2
|
+
import { LayoutGrid, type CellMode, type FillDirection, type LayoutGridProps, type LineAlign, type RectangularArrangement, type StaggerArgs } from "../kit/index.js";
|
|
3
|
+
export interface RectangularGridProps extends LayoutGridProps {
|
|
4
|
+
columns: number;
|
|
5
|
+
fillDirection: FillDirection;
|
|
6
|
+
cellMode: CellMode;
|
|
7
|
+
cellWidth: number;
|
|
8
|
+
cellHeight: number;
|
|
9
|
+
columnGap: number;
|
|
10
|
+
rowGap: number;
|
|
11
|
+
lastLineAlign: LineAlign;
|
|
12
|
+
rowOffset: number;
|
|
13
|
+
columnOffset: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Children in rows and columns — the grid the other three are variations on.
|
|
17
|
+
*
|
|
18
|
+
* Cells are as big as the largest child (`fit`), a size of their own
|
|
19
|
+
* (`fixed`), or an equal share of the node's box (`fill`), which is also the
|
|
20
|
+
* room a child set to fill grows into. Shift every other row by half a cell
|
|
21
|
+
* for a brick bond or a hex pack.
|
|
22
|
+
*/
|
|
23
|
+
export declare class RectangularGrid extends LayoutGrid<RectangularGridProps> {
|
|
24
|
+
columns: number;
|
|
25
|
+
fillDirection: FillDirection;
|
|
26
|
+
cellMode: CellMode;
|
|
27
|
+
cellWidth: number;
|
|
28
|
+
cellHeight: number;
|
|
29
|
+
columnGap: number;
|
|
30
|
+
rowGap: number;
|
|
31
|
+
lastLineAlign: LineAlign;
|
|
32
|
+
rowOffset: number;
|
|
33
|
+
columnOffset: number;
|
|
34
|
+
constructor(props?: NodeConfig<RectangularGrid, RectangularGridProps>);
|
|
35
|
+
/** Re-flow the items into `columns` columns, each moving to its new cell. */
|
|
36
|
+
columnsTo(args: CommandArgs<{
|
|
37
|
+
columns: number;
|
|
38
|
+
} & StaggerArgs> & {
|
|
39
|
+
duration: number;
|
|
40
|
+
}): Command<RectangularGridProps>;
|
|
41
|
+
/** Animate the spacing between columns and rows. */
|
|
42
|
+
gapTo(args: CommandArgs<{
|
|
43
|
+
columnGap?: number;
|
|
44
|
+
rowGap?: number;
|
|
45
|
+
}> & {
|
|
46
|
+
duration: number;
|
|
47
|
+
}): Command<RectangularGridProps>;
|
|
48
|
+
/**
|
|
49
|
+
* Animate the cell size, from whatever the cells measure now. The grid
|
|
50
|
+
* switches to `fixed` cells as it starts, since a size of its own is what
|
|
51
|
+
* `fixed` means.
|
|
52
|
+
*/
|
|
53
|
+
cellSizeTo(args: CommandArgs<{
|
|
54
|
+
cellWidth?: number;
|
|
55
|
+
cellHeight?: number;
|
|
56
|
+
}> & {
|
|
57
|
+
duration: number;
|
|
58
|
+
}): Command<RectangularGridProps>;
|
|
59
|
+
/** Bring one row (from 0 at the top) forward and push the rest back. */
|
|
60
|
+
focusRow(args: CommandArgs<{
|
|
61
|
+
row?: number;
|
|
62
|
+
dim?: number;
|
|
63
|
+
grow?: number;
|
|
64
|
+
}> & {
|
|
65
|
+
duration: number;
|
|
66
|
+
}): Command<LayoutGridProps>;
|
|
67
|
+
/** Bring one column (from 0 at the left) forward and push the rest back. */
|
|
68
|
+
focusColumn(args: CommandArgs<{
|
|
69
|
+
column?: number;
|
|
70
|
+
dim?: number;
|
|
71
|
+
grow?: number;
|
|
72
|
+
}> & {
|
|
73
|
+
duration: number;
|
|
74
|
+
}): Command<LayoutGridProps>;
|
|
75
|
+
protected arrangementFor(): RectangularArrangement;
|
|
76
|
+
/** A child set to fill takes its cell, where the cell is not simply the largest child. */
|
|
77
|
+
protected itemSpace(count: number, space: Size2D): Size2D;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=rectangular-grid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rectangular-grid.d.ts","sourceRoot":"","sources":["../../src/rectangular-grid/rectangular-grid.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,MAAM,EACZ,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAKL,UAAU,EAIV,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,sBAAsB,EAC3B,KAAK,WAAW,EACjB,MAAM,QAAQ,CAAA;AAEf,MAAM,WAAW,oBAAqB,SAAQ,eAAe;IAC3D,OAAO,EAAE,MAAM,CAAA;IACf,aAAa,EAAE,aAAa,CAA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