@johnoscott/isometric-engine 0.14.1 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/iso-editor.js +199 -190
- package/iso-render.js +157 -148
- package/iso-systems.js +170 -159
- package/js/iso-objects/ants.js +36 -0
- package/js/iso-objects/index.js +47 -1
- package/js/iso-objects/looks.js +25 -0
- package/js/iso-objects/motion-builder.js +130 -0
- package/js/iso-objects/motion-doc.js +500 -0
- package/js/iso-objects/motion-entry.js +32 -0
- package/js/iso-objects/motion.js +635 -0
- package/js/iso-objects/resolve.js +238 -0
- package/js/iso-objects/scene.js +15 -13
- package/js/iso-objects/timeline.js +553 -0
- package/js/iso-systems/compile.js +59 -1
- package/js/iso-systems/index.js +4 -1
- package/js/iso-systems/render.js +20 -0
- package/js/iso-systems/schema.json +39 -0
- package/js/iso-viewer/page.js +2 -1
- package/js/iso-viewer/player.js +23 -34
- package/package.json +46 -1
- package/src/iso-objects/ants.ts +53 -0
- package/src/iso-objects/compile.ts +4 -1
- package/src/iso-objects/index.ts +14 -1
- package/src/iso-objects/looks.ts +21 -0
- package/src/iso-objects/motion-builder.ts +79 -0
- package/src/iso-objects/motion-doc.ts +361 -0
- package/src/iso-objects/motion-entry.ts +12 -0
- package/src/iso-objects/motion.ts +616 -0
- package/src/iso-objects/resolve.ts +196 -0
- package/src/iso-objects/scene.ts +29 -13
- package/src/iso-objects/timeline.ts +443 -0
- package/src/iso-objects/types.ts +20 -2
- package/src/iso-systems/compile.ts +58 -3
- package/src/iso-systems/index.ts +4 -1
- package/src/iso-systems/render.ts +41 -0
- package/src/iso-systems/schema.json +39 -0
- package/src/iso-viewer/page.ts +2 -1
- package/src/iso-viewer/player.ts +24 -41
- package/types/iso-objects/ants.d.ts +33 -0
- package/types/iso-objects/compile.d.ts +3 -0
- package/types/iso-objects/index.d.ts +14 -1
- package/types/iso-objects/looks.d.ts +4 -0
- package/types/iso-objects/motion-builder.d.ts +105 -0
- package/types/iso-objects/motion-doc.d.ts +787 -0
- package/types/iso-objects/motion-entry.d.ts +10 -0
- package/types/iso-objects/motion.d.ts +200 -0
- package/types/iso-objects/resolve.d.ts +20 -0
- package/types/iso-objects/scene.d.ts +11 -0
- package/types/iso-objects/timeline.d.ts +46 -0
- package/types/iso-objects/types.d.ts +32 -0
- package/types/iso-systems/compile.d.ts +20 -3
- package/types/iso-systems/index.d.ts +4 -1
- package/types/iso-systems/render.d.ts +21 -0
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
import { didYouMean } from "../iso-core/errors.js";
|
|
2
|
+
import { ASSEMBLE_STYLES, DISASSEMBLE_STYLES, MOTION_ORDERS } from "./motion.js";
|
|
3
|
+
const EASING_NAMES = ["linear", "ease", "ease-in", "ease-out", "ease-in-out", "settle", "bounce"];
|
|
4
|
+
const EXTRAPOLATE = ["extend", "clamp", "wrap", "identity"];
|
|
5
|
+
function msOf(t, fps) {
|
|
6
|
+
if (typeof t === "number") return Number.isFinite(t) ? t : void 0;
|
|
7
|
+
if (typeof t !== "string") return void 0;
|
|
8
|
+
const m = /^(-?\d+(?:\.\d+)?)(ms|s|f)?$/.exec(t.trim());
|
|
9
|
+
if (!m) return void 0;
|
|
10
|
+
const v = Number(m[1]);
|
|
11
|
+
return m[2] === "s" ? v * 1e3 : m[2] === "f" ? fps ? v / fps * 1e3 : void 0 : v;
|
|
12
|
+
}
|
|
13
|
+
function readMs(say, r) {
|
|
14
|
+
const o = r === true ? {} : r, base = o.base ?? 2600, per = o.perChar ?? 40, min = o.min ?? 5600, max = o.max ?? 12500;
|
|
15
|
+
return Math.max(min, Math.min(max, base + (say?.text ?? "").length * per));
|
|
16
|
+
}
|
|
17
|
+
const bezier = (x1, y1, x2, y2) => (x) => {
|
|
18
|
+
if (x <= 0) return 0;
|
|
19
|
+
if (x >= 1) return 1;
|
|
20
|
+
const at = (a, b, t) => 3 * a * t * (1 - t) ** 2 + 3 * b * t * t * (1 - t) + t ** 3;
|
|
21
|
+
let lo = 0, hi = 1;
|
|
22
|
+
for (let i = 0; i < 50; i++) {
|
|
23
|
+
const m = (lo + hi) / 2;
|
|
24
|
+
if (at(x1, x2, m) < x) lo = m;
|
|
25
|
+
else hi = m;
|
|
26
|
+
}
|
|
27
|
+
return at(y1, y2, (lo + hi) / 2);
|
|
28
|
+
};
|
|
29
|
+
const bounce = (f) => {
|
|
30
|
+
if (f <= 0) return 0;
|
|
31
|
+
if (f >= 1) return 1;
|
|
32
|
+
const n = 7.5625, d = 2.75;
|
|
33
|
+
if (f < 1 / d) return n * f * f;
|
|
34
|
+
if (f < 2 / d) return n * (f - 1.5 / d) ** 2 + 0.75;
|
|
35
|
+
if (f < 2.5 / d) return n * (f - 2.25 / d) ** 2 + 0.9375;
|
|
36
|
+
return n * (f - 2.625 / d) ** 2 + 0.984375;
|
|
37
|
+
};
|
|
38
|
+
const NAMED = {
|
|
39
|
+
linear: (f) => f,
|
|
40
|
+
ease: bezier(0.25, 0.1, 0.25, 1),
|
|
41
|
+
"ease-in": bezier(0.42, 0, 1, 1),
|
|
42
|
+
"ease-out": bezier(0, 0, 0.58, 1),
|
|
43
|
+
"ease-in-out": bezier(0.42, 0, 0.58, 1),
|
|
44
|
+
settle: bezier(0.16, 0.84, 0.3, 1),
|
|
45
|
+
bounce
|
|
46
|
+
};
|
|
47
|
+
function springAt(t, c = {}) {
|
|
48
|
+
const m = c.mass ?? 1, k = c.stiffness ?? 100, d = c.damping ?? 10, s = Math.max(0, t) / 1e3;
|
|
49
|
+
const w0 = Math.sqrt(k / m), z = d / (2 * Math.sqrt(k * m));
|
|
50
|
+
let x;
|
|
51
|
+
if (z < 1) {
|
|
52
|
+
const w = w0 * Math.sqrt(1 - z * z);
|
|
53
|
+
x = 1 - Math.exp(-z * w0 * s) * (Math.cos(w * s) + z * w0 / w * Math.sin(w * s));
|
|
54
|
+
} else x = 1 - Math.exp(-w0 * s) * (1 + w0 * s);
|
|
55
|
+
return c.overshootClamping ? Math.min(1, x) : x;
|
|
56
|
+
}
|
|
57
|
+
function easeOf(e, duration, otherwise = "ease-in-out") {
|
|
58
|
+
const v = e ?? otherwise;
|
|
59
|
+
if (typeof v === "string") return NAMED[v];
|
|
60
|
+
if ("bezier" in v) return bezier(...v.bezier);
|
|
61
|
+
return (f) => f <= 0 ? 0 : f >= 1 ? 1 : springAt(f * duration, v.spring);
|
|
62
|
+
}
|
|
63
|
+
function curveAt(c, t, fps) {
|
|
64
|
+
const ts = c.times.map((x) => msOf(x, fps)), vs = c.values, n = ts.length;
|
|
65
|
+
if (n === 1) return vs[0];
|
|
66
|
+
const edge = (how, low) => {
|
|
67
|
+
if (how === "clamp") return low ? vs[0] : vs[n - 1];
|
|
68
|
+
if (how === "identity") return t;
|
|
69
|
+
if (how === "wrap") {
|
|
70
|
+
const span2 = ts[n - 1] - ts[0];
|
|
71
|
+
return curveAt({ ...c, extrapolateLeft: "clamp", extrapolateRight: "clamp" }, ts[0] + ((t - ts[0]) % span2 + span2) % span2, fps);
|
|
72
|
+
}
|
|
73
|
+
return void 0;
|
|
74
|
+
};
|
|
75
|
+
if (t < ts[0]) {
|
|
76
|
+
const v = edge(c.extrapolateLeft ?? "extend", true);
|
|
77
|
+
if (v !== void 0) return v;
|
|
78
|
+
}
|
|
79
|
+
if (t > ts[n - 1]) {
|
|
80
|
+
const v = edge(c.extrapolateRight ?? "extend", false);
|
|
81
|
+
if (v !== void 0) return v;
|
|
82
|
+
}
|
|
83
|
+
let i = 0;
|
|
84
|
+
while (i < n - 2 && t >= ts[i + 1]) i++;
|
|
85
|
+
const span = ts[i + 1] - ts[i], f = (t - ts[i]) / span;
|
|
86
|
+
const g = f < 0 || f > 1 ? f : easeOf(c.easing, span, "linear")(f);
|
|
87
|
+
return vs[i] + (vs[i + 1] - vs[i]) * g;
|
|
88
|
+
}
|
|
89
|
+
const TIME = { anyOf: [{ type: "number" }, { type: "string", pattern: "^-?\\d+(\\.\\d+)?(ms|s|f)?$" }] };
|
|
90
|
+
const IDS = { type: "array", items: { type: "string" } };
|
|
91
|
+
const EASE = { anyOf: [{ enum: EASING_NAMES }, { type: "object", required: ["bezier"], additionalProperties: false, properties: { bezier: { type: "array", items: { type: "number" }, minItems: 4, maxItems: 4 } } }, { type: "object", required: ["spring"], additionalProperties: false, properties: { spring: { $ref: "#/$defs/spring" } } }] };
|
|
92
|
+
const timing = { from: { $ref: "#/$defs/time" }, duration: { $ref: "#/$defs/time" }, easing: { $ref: "#/$defs/ease" } };
|
|
93
|
+
const node = (key, value, more = {}, withTiming = true) => ({ type: "object", required: [key], additionalProperties: false, properties: { [key]: value, ...withTiming ? timing : {}, ...more } });
|
|
94
|
+
const MOTION_SCHEMA = {
|
|
95
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
96
|
+
title: "isomotion/1",
|
|
97
|
+
type: "object",
|
|
98
|
+
required: ["isomotion"],
|
|
99
|
+
additionalProperties: false,
|
|
100
|
+
properties: {
|
|
101
|
+
isomotion: { const: 1 },
|
|
102
|
+
fps: { type: "number", exclusiveMinimum: 0, description: 'Frames a second, for lengths written "30f".' },
|
|
103
|
+
seed: { type: "integer" },
|
|
104
|
+
ambient: { enum: ["on", "off"], description: "Off: the ants and the looping tokens and pulses stand still, each at its start." },
|
|
105
|
+
series: { $ref: "#/$defs/series" },
|
|
106
|
+
layers: { $ref: "#/$defs/nodes" },
|
|
107
|
+
markers: { type: "object", additionalProperties: { anyOf: [{ type: "number" }, { type: "string" }] } }
|
|
108
|
+
},
|
|
109
|
+
$defs: {
|
|
110
|
+
time: TIME,
|
|
111
|
+
ids: IDS,
|
|
112
|
+
ease: EASE,
|
|
113
|
+
spring: { type: "object", additionalProperties: false, properties: { mass: { type: "number", exclusiveMinimum: 0 }, damping: { type: "number", exclusiveMinimum: 0 }, stiffness: { type: "number", exclusiveMinimum: 0 }, overshootClamping: { type: "boolean" } } },
|
|
114
|
+
curve: { type: "object", required: ["times", "values"], additionalProperties: false, properties: { times: { type: "array", items: { $ref: "#/$defs/time" }, minItems: 1 }, values: { type: "array", items: { type: "number" }, minItems: 1 }, easing: { $ref: "#/$defs/ease" }, extrapolateLeft: { enum: EXTRAPOLATE }, extrapolateRight: { enum: EXTRAPOLATE } } },
|
|
115
|
+
say: { type: "object", additionalProperties: false, properties: { chapter: { type: "string" }, title: { type: "string" }, text: { type: "string" }, code: { type: "string" }, color: { type: "string" }, facts: { type: "array", items: { type: "array", items: { type: "string" }, minItems: 2, maxItems: 2 } } } },
|
|
116
|
+
focus: { type: "object", required: ["lit"], additionalProperties: false, properties: { lit: { $ref: "#/$defs/ids" }, scope: { enum: ["all", "links"] }, level: { type: "number", minimum: 0, maximum: 1 }, always: { $ref: "#/$defs/ids" } } },
|
|
117
|
+
sequence: {
|
|
118
|
+
type: "object",
|
|
119
|
+
additionalProperties: false,
|
|
120
|
+
properties: {
|
|
121
|
+
name: { type: "string", pattern: "^[A-Za-z][\\w-]*$" },
|
|
122
|
+
from: { $ref: "#/$defs/time" },
|
|
123
|
+
offset: { $ref: "#/$defs/time" },
|
|
124
|
+
trimBefore: { $ref: "#/$defs/time" },
|
|
125
|
+
duration: { anyOf: [{ $ref: "#/$defs/time" }, { type: "object", required: ["read"], additionalProperties: false, properties: { read: { anyOf: [{ const: true }, { type: "object", additionalProperties: false, properties: { base: { type: "number" }, perChar: { type: "number" }, min: { type: "number" }, max: { type: "number" } } }] } } }] },
|
|
126
|
+
loop: { anyOf: [{ type: "boolean" }, { type: "integer", minimum: 1 }] },
|
|
127
|
+
playbackRate: { type: "number", exclusiveMinimum: 0 },
|
|
128
|
+
say: { $ref: "#/$defs/say" },
|
|
129
|
+
show: { $ref: "#/$defs/ids" },
|
|
130
|
+
hide: { $ref: "#/$defs/ids" },
|
|
131
|
+
focus: { $ref: "#/$defs/focus" },
|
|
132
|
+
highlight: { $ref: "#/$defs/ids" },
|
|
133
|
+
levels: { type: "object", additionalProperties: { type: "number", minimum: 0, maximum: 1 } },
|
|
134
|
+
variants: { type: "object", additionalProperties: { type: "string" } },
|
|
135
|
+
enter: { type: "object", required: ["fade"], additionalProperties: false, properties: { fade: { $ref: "#/$defs/time" }, easing: { $ref: "#/$defs/ease" } } },
|
|
136
|
+
ants: { anyOf: [{ type: "boolean" }, { $ref: "#/$defs/ids" }] },
|
|
137
|
+
children: { $ref: "#/$defs/nodes" },
|
|
138
|
+
layers: { $ref: "#/$defs/nodes" },
|
|
139
|
+
series: { $ref: "#/$defs/series" }
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
series: { type: "array", items: { anyOf: [{ $ref: "#/$defs/seq" }, node("transition", { type: "object", required: ["presentation", "timing"], additionalProperties: false, properties: { presentation: { enum: ["fade", "none"] }, timing: { anyOf: [{ type: "object", required: ["linear"], additionalProperties: false, properties: { linear: { $ref: "#/$defs/time" } } }, { type: "object", required: ["spring"], additionalProperties: false, properties: { spring: { type: "object", additionalProperties: false, properties: { mass: { type: "number", exclusiveMinimum: 0 }, damping: { type: "number", exclusiveMinimum: 0 }, stiffness: { type: "number", exclusiveMinimum: 0 }, overshootClamping: { type: "boolean" }, duration: { $ref: "#/$defs/time" } } } } }] } } }, {}, false)] } },
|
|
143
|
+
seq: node("sequence", { $ref: "#/$defs/sequence" }, {}, false),
|
|
144
|
+
plan: { type: "object" },
|
|
145
|
+
nodes: {
|
|
146
|
+
type: "array",
|
|
147
|
+
items: { anyOf: [
|
|
148
|
+
{ $ref: "#/$defs/seq" },
|
|
149
|
+
node("series", { $ref: "#/$defs/series" }, {}, false),
|
|
150
|
+
node("layers", { $ref: "#/$defs/nodes" }, {}, false),
|
|
151
|
+
node("assemble", { type: "object", properties: { style: { enum: ASSEMBLE_STYLES }, order: { enum: MOTION_ORDERS } } }),
|
|
152
|
+
node("disassemble", { type: "object", properties: { style: { enum: DISASSEMBLE_STYLES }, order: { enum: MOTION_ORDERS } } }),
|
|
153
|
+
node("travel", { type: "array", items: { anyOf: [{ type: "string" }, { $ref: "#/$defs/ids" }] }, minItems: 1 }, { each: { $ref: "#/$defs/time" }, hold: { $ref: "#/$defs/time" }, loop: { type: "boolean" } }),
|
|
154
|
+
node("pulse", { $ref: "#/$defs/ids" }, { loop: { type: "boolean" } }),
|
|
155
|
+
node("ants", { anyOf: [{ const: true }, { $ref: "#/$defs/ids" }] }, { speed: { type: "number" }, dash: { type: "array", items: { type: "number", exclusiveMinimum: 0 }, minItems: 2, maxItems: 2 } }),
|
|
156
|
+
node("draw", { $ref: "#/$defs/ids" }, { by: { enum: ["stroke", "grow"] }, stagger: { $ref: "#/$defs/time" } }),
|
|
157
|
+
node("type", { $ref: "#/$defs/ids" }),
|
|
158
|
+
{ type: "object", required: ["move"], additionalProperties: false, properties: { move: { type: "string" }, from: { $ref: "#/$defs/time" }, x: { $ref: "#/$defs/curve" }, y: { $ref: "#/$defs/curve" }, scale: { $ref: "#/$defs/curve" }, opacity: { $ref: "#/$defs/curve" } } },
|
|
159
|
+
{ type: "object", required: ["lift", "by"], additionalProperties: false, properties: { lift: { $ref: "#/$defs/ids" }, by: { type: "number" }, stagger: { $ref: "#/$defs/time" }, to: { enum: ["up", "down"] }, opacity: { $ref: "#/$defs/curve" }, ...timing } },
|
|
160
|
+
node("focus", { $ref: "#/$defs/focus" }, { fade: { $ref: "#/$defs/time" } }),
|
|
161
|
+
node("highlight", { $ref: "#/$defs/ids" }, { fade: { $ref: "#/$defs/time" } }),
|
|
162
|
+
node("camera", { anyOf: [{ const: "fit" }, { type: "object", required: ["focus"], additionalProperties: false, properties: { focus: { anyOf: [{ type: "string" }, { $ref: "#/$defs/ids" }, { type: "array", items: { type: "number" }, minItems: 4, maxItems: 4 }] }, zoom: { type: "number", exclusiveMinimum: 0 }, margin: { type: "number" } } }] })
|
|
163
|
+
] }
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
const KINDS = ["sequence", "series", "layers", "assemble", "disassemble", "travel", "pulse", "ants", "draw", "type", "move", "lift", "focus", "highlight", "camera"];
|
|
168
|
+
const LATER = { morph: "the 2D morph is a later version's", diff: "diffs are a later version's", switch: "a look is a beat's: its variants" };
|
|
169
|
+
const TIMING = ["from", "duration", "easing"];
|
|
170
|
+
const KEYS = {
|
|
171
|
+
sequence: [],
|
|
172
|
+
series: [],
|
|
173
|
+
layers: [],
|
|
174
|
+
assemble: TIMING,
|
|
175
|
+
disassemble: TIMING,
|
|
176
|
+
travel: [...TIMING, "each", "hold", "loop"],
|
|
177
|
+
pulse: [...TIMING, "loop"],
|
|
178
|
+
ants: [...TIMING, "speed", "dash"],
|
|
179
|
+
draw: [...TIMING, "by", "stagger"],
|
|
180
|
+
type: TIMING,
|
|
181
|
+
move: ["from", "x", "y", "scale", "opacity"],
|
|
182
|
+
lift: [...TIMING, "by", "stagger", "to", "opacity"],
|
|
183
|
+
focus: [...TIMING, "fade"],
|
|
184
|
+
highlight: [...TIMING, "fade"],
|
|
185
|
+
camera: TIMING
|
|
186
|
+
};
|
|
187
|
+
const SEQ_KEYS = ["name", "from", "offset", "duration", "loop", "playbackRate", "trimBefore", "say", "show", "hide", "focus", "highlight", "levels", "variants", "enter", "ants", "children", "layers", "series"];
|
|
188
|
+
const isMap = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
189
|
+
function checkMotion(doc) {
|
|
190
|
+
const out = [];
|
|
191
|
+
const err = (path, message, hint) => {
|
|
192
|
+
out.push({ severity: "error", path, message, ...hint ? { hint } : {} });
|
|
193
|
+
};
|
|
194
|
+
const keys = (v, allowed, path) => {
|
|
195
|
+
for (const k of Object.keys(v)) if (!allowed.includes(k)) {
|
|
196
|
+
const d = didYouMean(k, allowed);
|
|
197
|
+
err(`${path}/${k}`, `unknown key "${k}"`, d ? `did you mean "${d}"?` : void 0);
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
if (!isMap(doc)) {
|
|
201
|
+
err("", "a motion document is a map");
|
|
202
|
+
return out;
|
|
203
|
+
}
|
|
204
|
+
keys(doc, ["isomotion", "fps", "seed", "ambient", "series", "layers", "markers"], "");
|
|
205
|
+
if (doc.isomotion !== 1) err("/isomotion", "isomotion is 1");
|
|
206
|
+
const fps = typeof doc.fps === "number" && doc.fps > 0 ? doc.fps : void 0;
|
|
207
|
+
if (doc.fps !== void 0 && fps === void 0) err("/fps", "fps is a number over 0");
|
|
208
|
+
if (doc.seed !== void 0 && !Number.isInteger(doc.seed)) err("/seed", "seed is a whole number");
|
|
209
|
+
if (doc.ambient !== void 0 && doc.ambient !== "on" && doc.ambient !== "off") err("/ambient", 'ambient is "on" or "off"');
|
|
210
|
+
const time = (v, path, o = {}) => {
|
|
211
|
+
if (v === void 0) return;
|
|
212
|
+
if (typeof v === "string" && /f$/.test(v) && fps === void 0) {
|
|
213
|
+
err(path, `"${v}" is in frames: the document needs its fps`);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const t = msOf(v, fps);
|
|
217
|
+
if (t === void 0) err(path, `${JSON.stringify(v)} isn't a time (ms, "1.2s", "450ms", "30f")`);
|
|
218
|
+
else if (t < 0 && !o.negative) err(path, "a time can't be negative");
|
|
219
|
+
};
|
|
220
|
+
const oneOf = (v, list, path) => {
|
|
221
|
+
if (v !== void 0 && !list.includes(v)) {
|
|
222
|
+
const d = typeof v === "string" ? didYouMean(v, list) : void 0;
|
|
223
|
+
err(path, `${JSON.stringify(v)} isn't one of ${list.join(", ")}`, d ? `did you mean "${d}"?` : void 0);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
const num = (v, path, o = {}) => {
|
|
227
|
+
if (v === void 0) return;
|
|
228
|
+
if (typeof v !== "number" || !Number.isFinite(v) || o.min !== void 0 && v < o.min || o.max !== void 0 && v > o.max || o.over !== void 0 && v <= o.over) err(path, `${JSON.stringify(v)} isn't a number${o.over !== void 0 ? ` over ${o.over}` : o.min !== void 0 ? ` from ${o.min}${o.max !== void 0 ? ` to ${o.max}` : ""}` : ""}`);
|
|
229
|
+
};
|
|
230
|
+
const ids = (v, path) => {
|
|
231
|
+
if (v === void 0) return;
|
|
232
|
+
if (!Array.isArray(v)) {
|
|
233
|
+
err(path, "a list of ids");
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
v.forEach((x, i) => {
|
|
237
|
+
if (typeof x !== "string") err(`${path}/${i}`, "an id");
|
|
238
|
+
});
|
|
239
|
+
};
|
|
240
|
+
const spring = (v, path, more = []) => {
|
|
241
|
+
if (!isMap(v)) {
|
|
242
|
+
err(path, "a spring is a map");
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
keys(v, ["mass", "damping", "stiffness", "overshootClamping", ...more], path);
|
|
246
|
+
for (const k of ["mass", "damping", "stiffness"]) num(v[k], `${path}/${k}`, { over: 0 });
|
|
247
|
+
if (v.overshootClamping !== void 0 && typeof v.overshootClamping !== "boolean") err(`${path}/overshootClamping`, "true or false");
|
|
248
|
+
};
|
|
249
|
+
const ease = (v, path) => {
|
|
250
|
+
if (v === void 0) return;
|
|
251
|
+
if (typeof v === "string") {
|
|
252
|
+
oneOf(v, EASING_NAMES, path);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
if (isMap(v) && "bezier" in v) {
|
|
256
|
+
keys(v, ["bezier"], path);
|
|
257
|
+
if (!Array.isArray(v.bezier) || v.bezier.length !== 4 || v.bezier.some((x) => typeof x !== "number")) err(`${path}/bezier`, "four numbers");
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
if (isMap(v) && "spring" in v) {
|
|
261
|
+
keys(v, ["spring"], path);
|
|
262
|
+
spring(v.spring, `${path}/spring`);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
err(path, "an easing is a name, { bezier: [a, b, c, d] } or { spring: { \u2026 } }");
|
|
266
|
+
};
|
|
267
|
+
const curve = (v, path) => {
|
|
268
|
+
if (v === void 0) return;
|
|
269
|
+
if (!isMap(v)) {
|
|
270
|
+
err(path, "a curve is { times, values }");
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
keys(v, ["times", "values", "easing", "extrapolateLeft", "extrapolateRight"], path);
|
|
274
|
+
const ts = v.times, vs = v.values;
|
|
275
|
+
if (!Array.isArray(ts) || !ts.length) err(`${path}/times`, "a list of times");
|
|
276
|
+
else {
|
|
277
|
+
ts.forEach((t, i) => time(t, `${path}/times/${i}`, { negative: true }));
|
|
278
|
+
const n = ts.map((t) => msOf(t, fps));
|
|
279
|
+
for (let i = 1; i < n.length; i++) if (n[i] !== void 0 && n[i - 1] !== void 0 && n[i] <= n[i - 1]) err(`${path}/times/${i}`, "times go up");
|
|
280
|
+
}
|
|
281
|
+
if (!Array.isArray(vs) || vs.some((x) => typeof x !== "number")) err(`${path}/values`, "a list of numbers");
|
|
282
|
+
else if (Array.isArray(ts) && vs.length !== ts.length) err(`${path}/values`, `${vs.length} values for ${ts.length} times`);
|
|
283
|
+
ease(v.easing, `${path}/easing`);
|
|
284
|
+
oneOf(v.extrapolateLeft, EXTRAPOLATE, `${path}/extrapolateLeft`);
|
|
285
|
+
oneOf(v.extrapolateRight, EXTRAPOLATE, `${path}/extrapolateRight`);
|
|
286
|
+
};
|
|
287
|
+
const focus = (v, path) => {
|
|
288
|
+
if (v === void 0) return;
|
|
289
|
+
if (!isMap(v)) {
|
|
290
|
+
err(path, "focus is { lit: [ids] }");
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
keys(v, ["lit", "scope", "level", "always"], path);
|
|
294
|
+
if (v.lit === void 0) err(`${path}/lit`, "what is lit");
|
|
295
|
+
ids(v.lit, `${path}/lit`);
|
|
296
|
+
ids(v.always, `${path}/always`);
|
|
297
|
+
oneOf(v.scope, ["all", "links"], `${path}/scope`);
|
|
298
|
+
num(v.level, `${path}/level`, { min: 0, max: 1 });
|
|
299
|
+
};
|
|
300
|
+
const text = (v, path) => {
|
|
301
|
+
if (v !== void 0 && typeof v !== "string") err(path, "text");
|
|
302
|
+
};
|
|
303
|
+
const names = /* @__PURE__ */ new Map();
|
|
304
|
+
function sequence(v, path, inSeries) {
|
|
305
|
+
if (!isMap(v)) {
|
|
306
|
+
err(path, "a sequence is a map");
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
keys(v, SEQ_KEYS, path);
|
|
310
|
+
if (v.name !== void 0) {
|
|
311
|
+
if (typeof v.name !== "string" || !/^[A-Za-z][\w-]*$/.test(v.name)) err(`${path}/name`, "a name is letters, digits, - and _, from a letter");
|
|
312
|
+
else if (names.has(v.name)) err(`${path}/name`, `"${v.name}" is already a name (${names.get(v.name)})`);
|
|
313
|
+
else names.set(v.name, path);
|
|
314
|
+
}
|
|
315
|
+
if (inSeries && v.from !== void 0) err(`${path}/from`, "in a series a sequence follows the one before", "offset moves it");
|
|
316
|
+
if (!inSeries && v.offset !== void 0) err(`${path}/offset`, "offset is for a series", "use from");
|
|
317
|
+
time(v.from, `${path}/from`);
|
|
318
|
+
time(v.offset, `${path}/offset`, { negative: true });
|
|
319
|
+
time(v.trimBefore, `${path}/trimBefore`);
|
|
320
|
+
if (isMap(v.duration)) {
|
|
321
|
+
keys(v.duration, ["read"], `${path}/duration`);
|
|
322
|
+
const r = v.duration.read;
|
|
323
|
+
if (r !== true && !isMap(r)) err(`${path}/duration/read`, "true, or { base, perChar, min, max }");
|
|
324
|
+
else if (isMap(r)) {
|
|
325
|
+
keys(r, ["base", "perChar", "min", "max"], `${path}/duration/read`);
|
|
326
|
+
for (const k of ["base", "perChar", "min", "max"]) num(r[k], `${path}/duration/read/${k}`, { min: 0 });
|
|
327
|
+
}
|
|
328
|
+
} else time(v.duration, `${path}/duration`);
|
|
329
|
+
if (v.loop !== void 0 && typeof v.loop !== "boolean" && !(Number.isInteger(v.loop) && v.loop >= 1)) err(`${path}/loop`, "true, false, or how many times");
|
|
330
|
+
num(v.playbackRate, `${path}/playbackRate`, { over: 0 });
|
|
331
|
+
if (v.say !== void 0) {
|
|
332
|
+
if (!isMap(v.say)) err(`${path}/say`, "say is a map");
|
|
333
|
+
else {
|
|
334
|
+
const s = v.say;
|
|
335
|
+
keys(s, ["chapter", "title", "text", "code", "facts", "color"], `${path}/say`);
|
|
336
|
+
for (const k of ["chapter", "title", "text", "code", "color"]) text(s[k], `${path}/say/${k}`);
|
|
337
|
+
if (s.facts !== void 0 && (!Array.isArray(s.facts) || s.facts.some((f) => !Array.isArray(f) || f.length !== 2 || f.some((x) => typeof x !== "string")))) err(`${path}/say/facts`, "a list of [name, value]");
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
for (const k of ["show", "hide", "highlight"]) ids(v[k], `${path}/${k}`);
|
|
341
|
+
focus(v.focus, `${path}/focus`);
|
|
342
|
+
if (v.levels !== void 0) {
|
|
343
|
+
if (!isMap(v.levels)) err(`${path}/levels`, "levels is a map: an id, and how much of it");
|
|
344
|
+
else for (const [k, x] of Object.entries(v.levels)) num(x, `${path}/levels/${k}`, { min: 0, max: 1 });
|
|
345
|
+
}
|
|
346
|
+
if (v.variants !== void 0) {
|
|
347
|
+
if (!isMap(v.variants)) err(`${path}/variants`, "variants is a map: an id, and the name of its look");
|
|
348
|
+
else for (const [k, x] of Object.entries(v.variants)) if (typeof x !== "string") err(`${path}/variants/${k}`, `a look's name, or "" for its own`);
|
|
349
|
+
}
|
|
350
|
+
if (v.enter !== void 0) {
|
|
351
|
+
if (!isMap(v.enter)) err(`${path}/enter`, "enter is { fade }");
|
|
352
|
+
else {
|
|
353
|
+
keys(v.enter, ["fade", "easing"], `${path}/enter`);
|
|
354
|
+
if (v.enter.fade === void 0) err(`${path}/enter/fade`, "how long the fade is");
|
|
355
|
+
time(v.enter.fade, `${path}/enter/fade`);
|
|
356
|
+
ease(v.enter.easing, `${path}/enter/easing`);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
if (v.ants !== void 0 && typeof v.ants !== "boolean") ids(v.ants, `${path}/ants`);
|
|
360
|
+
for (const k of ["children", "layers"]) if (v[k] !== void 0) nodes(v[k], `${path}/${k}`);
|
|
361
|
+
if (v.series !== void 0) series(v.series, `${path}/series`);
|
|
362
|
+
}
|
|
363
|
+
function series(v, path) {
|
|
364
|
+
if (!Array.isArray(v)) {
|
|
365
|
+
err(path, "a series is a list");
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
v.forEach((it, i) => {
|
|
369
|
+
const p = `${path}/${i}`;
|
|
370
|
+
if (!isMap(it) || Object.keys(it).length !== 1 || !("sequence" in it || "transition" in it)) {
|
|
371
|
+
err(p, "a series holds sequences and transitions");
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
if ("sequence" in it) {
|
|
375
|
+
sequence(it.sequence, `${p}/sequence`, true);
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
const t = it.transition, q = `${p}/transition`, seqAt = (k) => isMap(v[k]) && "sequence" in v[k];
|
|
379
|
+
if (!seqAt(i - 1) || !seqAt(i + 1)) err(q, "a transition is between two sequences");
|
|
380
|
+
if (!isMap(t)) {
|
|
381
|
+
err(q, "a transition is { presentation, timing }");
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
keys(t, ["presentation", "timing"], q);
|
|
385
|
+
if (t.presentation === void 0) err(`${q}/presentation`, "a presentation");
|
|
386
|
+
else oneOf(t.presentation, ["fade", "none"], `${q}/presentation`);
|
|
387
|
+
if (!isMap(t.timing)) err(`${q}/timing`, "a timing is { linear } or { spring }");
|
|
388
|
+
else if ("linear" in t.timing) {
|
|
389
|
+
keys(t.timing, ["linear"], `${q}/timing`);
|
|
390
|
+
time(t.timing.linear, `${q}/timing/linear`);
|
|
391
|
+
} else if ("spring" in t.timing) {
|
|
392
|
+
keys(t.timing, ["spring"], `${q}/timing`);
|
|
393
|
+
spring(t.timing.spring, `${q}/timing/spring`, ["duration"]);
|
|
394
|
+
if (isMap(t.timing.spring)) time(t.timing.spring.duration, `${q}/timing/spring/duration`);
|
|
395
|
+
} else err(`${q}/timing`, "a timing is { linear } or { spring }");
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
function nodes(v, path) {
|
|
399
|
+
if (!Array.isArray(v)) {
|
|
400
|
+
err(path, "a list");
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
v.forEach((n, i) => {
|
|
404
|
+
const p = `${path}/${i}`;
|
|
405
|
+
if (!isMap(n)) {
|
|
406
|
+
err(p, "a map");
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
const kinds = KINDS.filter((k2) => k2 in n);
|
|
410
|
+
if (kinds.length !== 1) {
|
|
411
|
+
const late = Object.keys(n).find((k2) => k2 in LATER), k0 = Object.keys(n)[0], d = k0 ? didYouMean(k0, KINDS) : void 0;
|
|
412
|
+
err(p, late ? `${late}: ${LATER[late]}` : kinds.length ? `one of ${kinds.join(", ")}, not several` : `one of ${KINDS.join(", ")}`, !late && !kinds.length && d ? `did you mean "${d}"?` : void 0);
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
const k = kinds[0], c = n[k], q = `${p}/${k}`;
|
|
416
|
+
keys(n, [k, ...KEYS[k]], p);
|
|
417
|
+
if (KEYS[k].includes("from")) time(n.from, `${p}/from`);
|
|
418
|
+
if (KEYS[k].includes("duration")) {
|
|
419
|
+
time(n.duration, `${p}/duration`);
|
|
420
|
+
ease(n.easing, `${p}/easing`);
|
|
421
|
+
}
|
|
422
|
+
for (const t of ["each", "hold", "stagger", "fade"]) if (KEYS[k].includes(t)) time(n[t], `${p}/${t}`);
|
|
423
|
+
if (KEYS[k].includes("loop") && n.loop !== void 0 && typeof n.loop !== "boolean") err(`${p}/loop`, "true or false");
|
|
424
|
+
if (k === "sequence") sequence(c, q, false);
|
|
425
|
+
else if (k === "series") series(c, q);
|
|
426
|
+
else if (k === "layers") nodes(c, q);
|
|
427
|
+
else if (k === "assemble" || k === "disassemble") {
|
|
428
|
+
if (!isMap(c)) err(q, `${k} is a map (its options)`);
|
|
429
|
+
else {
|
|
430
|
+
oneOf(c.style, k === "assemble" ? ASSEMBLE_STYLES : DISASSEMBLE_STYLES, `${q}/style`);
|
|
431
|
+
oneOf(c.order, MOTION_ORDERS, `${q}/order`);
|
|
432
|
+
if (c.duration !== void 0) err(`${q}/duration`, "its length is beside it", "duration is the node's");
|
|
433
|
+
}
|
|
434
|
+
} else if (k === "travel") {
|
|
435
|
+
if (!Array.isArray(c) || !c.length) err(q, "a list of connectors");
|
|
436
|
+
else c.forEach((x, j) => {
|
|
437
|
+
if (Array.isArray(x)) ids(x, `${q}/${j}`);
|
|
438
|
+
else if (typeof x !== "string") err(`${q}/${j}`, "a connector, or a list of them at once");
|
|
439
|
+
});
|
|
440
|
+
} else if (k === "ants") {
|
|
441
|
+
if (c !== true) ids(c, q);
|
|
442
|
+
num(n.speed, `${p}/speed`);
|
|
443
|
+
if (n.dash !== void 0 && (!Array.isArray(n.dash) || n.dash.length !== 2 || n.dash.some((x) => typeof x !== "number" || x <= 0))) err(`${p}/dash`, "two numbers over 0: on, off");
|
|
444
|
+
} else if (k === "move") {
|
|
445
|
+
if (typeof c !== "string") err(q, "an id");
|
|
446
|
+
for (const a of ["x", "y", "scale", "opacity"]) curve(n[a], `${p}/${a}`);
|
|
447
|
+
} else if (k === "focus") focus(c, q);
|
|
448
|
+
else if (k === "camera") {
|
|
449
|
+
if (c !== "fit") {
|
|
450
|
+
if (!isMap(c)) err(q, '"fit", or { focus, zoom, margin }');
|
|
451
|
+
else {
|
|
452
|
+
keys(c, ["focus", "zoom", "margin"], q);
|
|
453
|
+
num(c.zoom, `${q}/zoom`, { over: 0 });
|
|
454
|
+
num(c.margin, `${q}/margin`);
|
|
455
|
+
const f = c.focus;
|
|
456
|
+
if (!(typeof f === "string" || Array.isArray(f) && (f.every((x) => typeof x === "string") || f.length === 4 && f.every((x) => typeof x === "number")))) err(`${q}/focus`, "an id, some ids, or a box [x, y, w, h]");
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
} else ids(c, q);
|
|
460
|
+
if (k === "draw") oneOf(n.by, ["stroke", "grow"], `${p}/by`);
|
|
461
|
+
if (k === "lift") {
|
|
462
|
+
if (n.by === void 0) err(`${p}/by`, "how far apart");
|
|
463
|
+
num(n.by, `${p}/by`);
|
|
464
|
+
oneOf(n.to, ["up", "down"], `${p}/to`);
|
|
465
|
+
curve(n.opacity, `${p}/opacity`);
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
if (doc.series !== void 0) series(doc.series, "/series");
|
|
470
|
+
if (doc.layers !== void 0) nodes(doc.layers, "/layers");
|
|
471
|
+
if (doc.markers !== void 0) {
|
|
472
|
+
if (!isMap(doc.markers)) err("/markers", "markers is a map");
|
|
473
|
+
else for (const [k, v] of Object.entries(doc.markers)) {
|
|
474
|
+
if (typeof v === "string" && /^[A-Za-z][\w-]*([+-].+)?$/.test(v)) {
|
|
475
|
+
const m = /^([A-Za-z][\w-]*?)(?:([+-])(\d.*))?$/.exec(v);
|
|
476
|
+
const at = m && (names.has(m[1]) ? m[1] : void 0);
|
|
477
|
+
if (!at) {
|
|
478
|
+
const whole = names.has(v);
|
|
479
|
+
if (!whole) {
|
|
480
|
+
const d = didYouMean(m?.[1] ?? v, names.keys());
|
|
481
|
+
err(`/markers/${k}`, `no sequence is named "${m?.[1] ?? v}"`, d ? `did you mean "${d}"?` : void 0);
|
|
482
|
+
}
|
|
483
|
+
} else if (m[3] !== void 0) time(m[3], `/markers/${k}`);
|
|
484
|
+
} else time(v, `/markers/${k}`);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
return out;
|
|
488
|
+
}
|
|
489
|
+
export {
|
|
490
|
+
EASING_NAMES,
|
|
491
|
+
EXTRAPOLATE,
|
|
492
|
+
MOTION_SCHEMA,
|
|
493
|
+
bezier,
|
|
494
|
+
checkMotion,
|
|
495
|
+
curveAt,
|
|
496
|
+
easeOf,
|
|
497
|
+
msOf,
|
|
498
|
+
readMs,
|
|
499
|
+
springAt
|
|
500
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export * from "./motion.js";
|
|
2
|
+
import { bindMotion, motionOfSteps } from "./timeline.js";
|
|
3
|
+
import { motion, MotionBuilder, SeriesBuilder, NodesBuilder } from "./motion-builder.js";
|
|
4
|
+
import { MOTION_SCHEMA, EASING_NAMES, EXTRAPOLATE, checkMotion, msOf, readMs, easeOf, curveAt, springAt, bezier } from "./motion-doc.js";
|
|
5
|
+
import { withAnts, antsOf, antDash, ANTS_CSS, ANT_SPEED, ANT_DASH, ANT_STILL } from "./ants.js";
|
|
6
|
+
import { drawLooks } from "./looks.js";
|
|
7
|
+
export {
|
|
8
|
+
ANTS_CSS,
|
|
9
|
+
ANT_DASH,
|
|
10
|
+
ANT_SPEED,
|
|
11
|
+
ANT_STILL,
|
|
12
|
+
EASING_NAMES,
|
|
13
|
+
EXTRAPOLATE,
|
|
14
|
+
MOTION_SCHEMA,
|
|
15
|
+
MotionBuilder,
|
|
16
|
+
NodesBuilder,
|
|
17
|
+
SeriesBuilder,
|
|
18
|
+
antDash,
|
|
19
|
+
antsOf,
|
|
20
|
+
bezier,
|
|
21
|
+
bindMotion,
|
|
22
|
+
checkMotion,
|
|
23
|
+
curveAt,
|
|
24
|
+
drawLooks,
|
|
25
|
+
easeOf,
|
|
26
|
+
motion,
|
|
27
|
+
motionOfSteps,
|
|
28
|
+
msOf,
|
|
29
|
+
readMs,
|
|
30
|
+
springAt,
|
|
31
|
+
withAnts
|
|
32
|
+
};
|