motionary 10.6.0 → 10.8.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/AGENTS.md +2 -0
- package/CHANGELOG.md +36 -0
- package/README.md +77 -4
- package/bin/motionary-mcp.mjs +160 -11
- package/dist/chunks/{anim-image-DECLkPH4.cjs → anim-image-BzTQa2k3.cjs} +2 -2
- package/dist/chunks/{anim-image-DECLkPH4.cjs.map → anim-image-BzTQa2k3.cjs.map} +1 -1
- package/dist/chunks/{anim-image-DNghy017.js → anim-image-iD646Q7i.js} +2 -2
- package/dist/chunks/{anim-image-DNghy017.js.map → anim-image-iD646Q7i.js.map} +1 -1
- package/dist/chunks/{keyframes-F6vp6tZZ.js → keyframes-B4zefz0k.js} +2 -2
- package/dist/chunks/{keyframes-F6vp6tZZ.js.map → keyframes-B4zefz0k.js.map} +1 -1
- package/dist/chunks/{keyframes-CbUZjD_5.cjs → keyframes-BlOyB1PP.cjs} +2 -2
- package/dist/chunks/{keyframes-CbUZjD_5.cjs.map → keyframes-BlOyB1PP.cjs.map} +1 -1
- package/dist/chunks/{registry-dr1CPTk1.cjs → registry-BZxDVL3h.cjs} +2 -2
- package/dist/chunks/{registry-dr1CPTk1.cjs.map → registry-BZxDVL3h.cjs.map} +1 -1
- package/dist/chunks/{registry-D8LAoXI-.js → registry-Bkt3-3ET.js} +3 -3
- package/dist/chunks/{registry-D8LAoXI-.js.map → registry-Bkt3-3ET.js.map} +1 -1
- package/dist/chunks/runtime-link-CUiZ8lbE.cjs +38 -0
- package/dist/chunks/runtime-link-CUiZ8lbE.cjs.map +1 -0
- package/dist/chunks/runtime-link-c13gskBZ.js +36 -0
- package/dist/chunks/runtime-link-c13gskBZ.js.map +1 -0
- package/dist/chunks/{ticker-DaAlEyOd.cjs → ticker-BfxAECfO.cjs} +2 -2
- package/dist/chunks/{ticker-DaAlEyOd.cjs.map → ticker-BfxAECfO.cjs.map} +1 -1
- package/dist/chunks/{ticker-Do9bGsaV.js → ticker-ZtweD3U4.js} +2 -2
- package/dist/chunks/{ticker-Do9bGsaV.js.map → ticker-ZtweD3U4.js.map} +1 -1
- package/dist/chunks/{tween-CmkdSyaC.cjs → tween--MD-39y0.cjs} +2 -2
- package/dist/chunks/{tween-CmkdSyaC.cjs.map → tween--MD-39y0.cjs.map} +1 -1
- package/dist/chunks/{tween-BzCGq_Ba.js → tween-DACdkLyO.js} +2 -2
- package/dist/chunks/{tween-BzCGq_Ba.js.map → tween-DACdkLyO.js.map} +1 -1
- package/dist/components/ai.cjs +314 -0
- package/dist/components/ai.cjs.map +1 -0
- package/dist/components/ai.d.cts +58 -0
- package/dist/components/ai.d.ts +58 -0
- package/dist/components/ai.js +311 -0
- package/dist/components/ai.js.map +1 -0
- package/dist/components/snap-carousel.cjs +216 -0
- package/dist/components/snap-carousel.cjs.map +1 -0
- package/dist/components/snap-carousel.d.cts +80 -0
- package/dist/components/snap-carousel.d.ts +80 -0
- package/dist/components/snap-carousel.js +214 -0
- package/dist/components/snap-carousel.js.map +1 -0
- package/dist/components/widgets.cjs +626 -268
- package/dist/components/widgets.cjs.map +1 -1
- package/dist/components/widgets.d.cts +515 -39
- package/dist/components/widgets.d.ts +515 -39
- package/dist/components/widgets.js +617 -262
- package/dist/components/widgets.js.map +1 -1
- package/dist/llms-full.txt +191 -6
- package/dist/llms.txt +10 -3
- package/dist/manifest.json +497 -19
- package/dist/runtime/drag-snap.cjs +269 -0
- package/dist/runtime/drag-snap.cjs.map +1 -0
- package/dist/runtime/drag-snap.d.cts +109 -0
- package/dist/runtime/drag-snap.d.ts +109 -0
- package/dist/runtime/drag-snap.iife.js +2 -0
- package/dist/runtime/drag-snap.iife.js.map +1 -0
- package/dist/runtime/drag-snap.js +261 -0
- package/dist/runtime/drag-snap.js.map +1 -0
- package/dist/runtime/format-apng.cjs +4 -4
- package/dist/runtime/format-apng.js +4 -4
- package/dist/runtime/format-css.cjs +4 -4
- package/dist/runtime/format-css.js +4 -4
- package/dist/runtime/format-gif.cjs +4 -4
- package/dist/runtime/format-gif.js +4 -4
- package/dist/runtime/format-gltf.cjs +37 -18
- package/dist/runtime/format-gltf.cjs.map +1 -1
- package/dist/runtime/format-gltf.d.cts +18 -2
- package/dist/runtime/format-gltf.d.ts +18 -2
- package/dist/runtime/format-gltf.iife.js +1 -1
- package/dist/runtime/format-gltf.iife.js.map +1 -1
- package/dist/runtime/format-gltf.js +37 -18
- package/dist/runtime/format-gltf.js.map +1 -1
- package/dist/runtime/format-motion.cjs +4 -4
- package/dist/runtime/format-motion.js +4 -4
- package/dist/runtime/format-obj.cjs +1 -1
- package/dist/runtime/format-obj.d.cts +2 -0
- package/dist/runtime/format-obj.d.ts +2 -0
- package/dist/runtime/format-obj.iife.js.map +1 -1
- package/dist/runtime/format-obj.js +1 -1
- package/dist/runtime/format-scene.cjs +241 -0
- package/dist/runtime/format-scene.cjs.map +1 -0
- package/dist/runtime/format-scene.d.cts +349 -0
- package/dist/runtime/format-scene.d.ts +349 -0
- package/dist/runtime/format-scene.iife.js +2 -0
- package/dist/runtime/format-scene.iife.js.map +1 -0
- package/dist/runtime/format-scene.js +233 -0
- package/dist/runtime/format-scene.js.map +1 -0
- package/dist/runtime/format-sprite.cjs +3 -3
- package/dist/runtime/format-sprite.js +3 -3
- package/dist/runtime/format-svg.cjs +3 -3
- package/dist/runtime/format-svg.js +3 -3
- package/dist/runtime/format-webp.cjs +4 -4
- package/dist/runtime/format-webp.js +4 -4
- package/dist/runtime/gl.cjs +17 -4
- package/dist/runtime/gl.cjs.map +1 -1
- package/dist/runtime/gl.d.cts +2 -0
- package/dist/runtime/gl.d.ts +2 -0
- package/dist/runtime/gl.iife.js +1 -1
- package/dist/runtime/gl.iife.js.map +1 -1
- package/dist/runtime/gl.js +17 -4
- package/dist/runtime/gl.js.map +1 -1
- package/dist/runtime/gltf-anim.cjs +251 -0
- package/dist/runtime/gltf-anim.cjs.map +1 -0
- package/dist/runtime/gltf-anim.d.cts +216 -0
- package/dist/runtime/gltf-anim.d.ts +216 -0
- package/dist/runtime/gltf-anim.iife.js +2 -0
- package/dist/runtime/gltf-anim.iife.js.map +1 -0
- package/dist/runtime/gltf-anim.js +243 -0
- package/dist/runtime/gltf-anim.js.map +1 -0
- package/dist/runtime/physics.cjs +739 -0
- package/dist/runtime/physics.cjs.map +1 -0
- package/dist/runtime/physics.d.cts +250 -0
- package/dist/runtime/physics.d.ts +250 -0
- package/dist/runtime/physics.iife.js +2 -0
- package/dist/runtime/physics.iife.js.map +1 -0
- package/dist/runtime/physics.js +731 -0
- package/dist/runtime/physics.js.map +1 -0
- package/dist/runtime/scroll.cjs +2 -2
- package/dist/runtime/scroll.js +2 -2
- package/dist/runtime/smooth.cjs +1 -1
- package/dist/runtime/smooth.js +1 -1
- package/dist/runtime/text.cjs +1 -1
- package/dist/runtime/text.js +1 -1
- package/dist/runtime/vector.cjs +421 -11
- package/dist/runtime/vector.cjs.map +1 -1
- package/dist/runtime/vector.d.cts +20 -4
- package/dist/runtime/vector.d.ts +20 -4
- package/dist/runtime/vector.iife.js +1 -1
- package/dist/runtime/vector.iife.js.map +1 -1
- package/dist/runtime/vector.js +421 -12
- package/dist/runtime/vector.js.map +1 -1
- package/dist/runtime.cjs +3 -3
- package/dist/runtime.d.cts +1 -1
- package/dist/runtime.d.ts +1 -1
- package/dist/runtime.iife.js +1 -1
- package/dist/runtime.iife.js.map +1 -1
- package/dist/runtime.js +5 -5
- package/dist/widgets.umd.js +1 -1
- package/dist/widgets.umd.js.map +1 -1
- package/docs/ROADMAP.md +2 -2
- package/docs/components/README.md +5 -2
- package/docs/components/usa-gl-scene.md +27 -6
- package/docs/components/usa-lottie-player.md +18 -0
- package/docs/components/usa-motion-prompt.md +32 -0
- package/docs/components/usa-physics-playground.md +63 -0
- package/docs/components/usa-snap-carousel.md +68 -0
- package/docs/components.md +95 -3
- package/docs/runtime/drag-snap.md +60 -0
- package/docs/runtime/format-gltf.md +3 -2
- package/docs/runtime/format-scene.md +59 -0
- package/docs/runtime/gltf-anim.md +62 -0
- package/docs/runtime/physics.md +61 -0
- package/docs/runtime/vector.md +3 -2
- package/package.json +61 -1
package/dist/runtime/vector.cjs
CHANGED
|
@@ -1,10 +1,321 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var registry = require('../chunks/registry-
|
|
4
|
-
var tween = require('../chunks/tween-
|
|
5
|
-
require('../chunks/ticker-
|
|
3
|
+
var registry = require('../chunks/registry-BZxDVL3h.cjs');
|
|
4
|
+
var tween = require('../chunks/tween--MD-39y0.cjs');
|
|
5
|
+
require('../chunks/ticker-BfxAECfO.cjs');
|
|
6
6
|
require('../chunks/ease-HwYZnZat.cjs');
|
|
7
7
|
|
|
8
|
+
const ALLOWED = new Set(['time', 'value', 'thisComp', 'thisLayer', 'thisProperty', 'Math', 'wiggle', 'loopOut', 'loopIn', 'loopOutDuration', 'loopInDuration', 'linear', 'ease', 'easeIn', 'easeOut', 'clamp', 'valueAtTime', 'framesToTime', 'timeToFrames', 'degreesToRadians', 'radiansToDegrees', 'add', 'sub', 'mul', 'div', 'length', 'true', 'false', '$bm_rt', 'index']);
|
|
9
|
+
function lex(src) {
|
|
10
|
+
const t = [];
|
|
11
|
+
const re = /\s*(?:(\/\/[^\n]*|\/\*[\s\S]*?\*\/)|(\d+\.?\d*(?:e[+-]?\d+)?|\.\d+)|("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')|([A-Za-z_$][\w$]*)|(===|!==|==|!=|<=|>=|&&|\|\||[-+*/%()[\],.;=<>!?:{}]))/gy;
|
|
12
|
+
let m, at = 0;
|
|
13
|
+
while (at < src.length) {
|
|
14
|
+
re.lastIndex = at;
|
|
15
|
+
if (!(m = re.exec(src)))
|
|
16
|
+
break;
|
|
17
|
+
at = re.lastIndex;
|
|
18
|
+
if (m[1])
|
|
19
|
+
continue;
|
|
20
|
+
const tok = m[2] || m[3] || m[4] || m[5];
|
|
21
|
+
if (tok)
|
|
22
|
+
t.push(m[2] ? '#' + tok : m[3] ? '"' + m[3].slice(1, -1) : tok);
|
|
23
|
+
}
|
|
24
|
+
if (src.slice(at).trim())
|
|
25
|
+
throw new Error('expr: unexpected ' + src.slice(at, at + 10));
|
|
26
|
+
return t;
|
|
27
|
+
}
|
|
28
|
+
/** Compile an expression to an AST (throws on anything outside the subset). */
|
|
29
|
+
function compileExpression(src) {
|
|
30
|
+
const T = lex(src);
|
|
31
|
+
let i = 0;
|
|
32
|
+
const peek = () => T[i], next = () => T[i++];
|
|
33
|
+
const eat = (s) => {
|
|
34
|
+
if (T[i] !== s)
|
|
35
|
+
throw new Error(`expr: expected ${s} got ${T[i]}`);
|
|
36
|
+
i++;
|
|
37
|
+
};
|
|
38
|
+
const declared = new Set();
|
|
39
|
+
const prim = () => {
|
|
40
|
+
const k = next();
|
|
41
|
+
if (k === undefined)
|
|
42
|
+
throw new Error('expr: unexpected end');
|
|
43
|
+
if (k[0] === '#')
|
|
44
|
+
return ['n', +k.slice(1)];
|
|
45
|
+
if (k[0] === '"')
|
|
46
|
+
return ['s', k.slice(1)];
|
|
47
|
+
if (k === '(') {
|
|
48
|
+
const e = expr();
|
|
49
|
+
eat(')');
|
|
50
|
+
return e;
|
|
51
|
+
}
|
|
52
|
+
if (k === '[') {
|
|
53
|
+
const a = [];
|
|
54
|
+
while (peek() !== ']') {
|
|
55
|
+
a.push(expr());
|
|
56
|
+
if (peek() === ',')
|
|
57
|
+
next();
|
|
58
|
+
}
|
|
59
|
+
eat(']');
|
|
60
|
+
return ['arr', a];
|
|
61
|
+
}
|
|
62
|
+
if (/^[A-Za-z_$]/.test(k)) {
|
|
63
|
+
if (!ALLOWED.has(k) && !declared.has(k))
|
|
64
|
+
throw new Error('expr: unsupported ' + k);
|
|
65
|
+
return ['id', k];
|
|
66
|
+
}
|
|
67
|
+
throw new Error('expr: unexpected ' + k);
|
|
68
|
+
};
|
|
69
|
+
const post = () => {
|
|
70
|
+
let e = prim();
|
|
71
|
+
for (;;) {
|
|
72
|
+
if (peek() === '.') {
|
|
73
|
+
next();
|
|
74
|
+
e = ['get', e, ['s', next()]];
|
|
75
|
+
}
|
|
76
|
+
else if (peek() === '[') {
|
|
77
|
+
next();
|
|
78
|
+
e = ['get', e, expr()];
|
|
79
|
+
eat(']');
|
|
80
|
+
}
|
|
81
|
+
else if (peek() === '(') {
|
|
82
|
+
next();
|
|
83
|
+
const a = [];
|
|
84
|
+
while (peek() !== ')') {
|
|
85
|
+
a.push(expr());
|
|
86
|
+
if (peek() === ',')
|
|
87
|
+
next();
|
|
88
|
+
}
|
|
89
|
+
eat(')');
|
|
90
|
+
e = ['call', e, a];
|
|
91
|
+
}
|
|
92
|
+
else
|
|
93
|
+
return e;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const un = () => (peek() === '-' || peek() === '+' || peek() === '!' ? ['un', next(), un()] : post());
|
|
97
|
+
const bin = (ops, sub) => () => {
|
|
98
|
+
let e = sub();
|
|
99
|
+
while (ops.includes(peek()))
|
|
100
|
+
e = ['bin', next(), e, sub()];
|
|
101
|
+
return e;
|
|
102
|
+
};
|
|
103
|
+
const mul = bin(['*', '/', '%'], un), add = bin(['+', '-'], mul), cmp = bin(['<', '>', '<=', '>='], add), eq = bin(['==', '!=', '===', '!=='], cmp), and = bin(['&&'], eq), or = bin(['||'], and);
|
|
104
|
+
const expr = () => {
|
|
105
|
+
const c = or();
|
|
106
|
+
if (peek() !== '?')
|
|
107
|
+
return c;
|
|
108
|
+
next();
|
|
109
|
+
const a = expr();
|
|
110
|
+
eat(':');
|
|
111
|
+
return ['if', c, a, expr()];
|
|
112
|
+
};
|
|
113
|
+
const stmts = [];
|
|
114
|
+
while (i < T.length) {
|
|
115
|
+
if (peek() === ';') {
|
|
116
|
+
next();
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (['var', 'let', 'const'].includes(peek())) {
|
|
120
|
+
next();
|
|
121
|
+
const name = next();
|
|
122
|
+
declared.add(name);
|
|
123
|
+
eat('=');
|
|
124
|
+
stmts.push(['set', name, expr()]);
|
|
125
|
+
}
|
|
126
|
+
else if (/^[A-Za-z_$]/.test(peek() || '') && T[i + 1] === '=') {
|
|
127
|
+
const name = next();
|
|
128
|
+
next();
|
|
129
|
+
declared.add(name);
|
|
130
|
+
stmts.push(['set', name, expr()]);
|
|
131
|
+
}
|
|
132
|
+
else
|
|
133
|
+
stmts.push(expr());
|
|
134
|
+
}
|
|
135
|
+
if (!stmts.length)
|
|
136
|
+
throw new Error('expr: empty');
|
|
137
|
+
return ['prog', stmts];
|
|
138
|
+
}
|
|
139
|
+
// ------------------------------------------------------------------ values
|
|
140
|
+
const isA = Array.isArray;
|
|
141
|
+
const zip = (a, b, f) => (isA(a) && isA(b) ? Array.from({ length: Math.max(a.length, b.length) }, (_, i) => f(a[i] ?? 0, b[i] ?? 0)) : isA(a) ? a.map((x) => f(x, b)) : isA(b) ? b.map((y) => f(a, y)) : f(a, b));
|
|
142
|
+
const vadd = (a, b) => (typeof a === 'string' || typeof b === 'string' ? String(a) + String(b) : zip(a, b, (x, y) => x + y));
|
|
143
|
+
const vsub = (a, b) => zip(a, b, (x, y) => x - y);
|
|
144
|
+
const vmul = (a, b) => zip(a, b, (x, y) => x * y);
|
|
145
|
+
const vdiv = (a, b) => zip(a, b, (x, y) => x / y);
|
|
146
|
+
const lerpV = (a, b, p) => vadd(a, vmul(vsub(b, a), p));
|
|
147
|
+
// smooth 1D value noise in [-1, 1]
|
|
148
|
+
const hash = (n) => {
|
|
149
|
+
const s = Math.sin(n * 127.1 + 311.7) * 43758.5453;
|
|
150
|
+
return (s - Math.floor(s)) * 2 - 1;
|
|
151
|
+
};
|
|
152
|
+
const noise = (x) => {
|
|
153
|
+
const i = Math.floor(x), f = x - i, u = f * f * (3 - 2 * f);
|
|
154
|
+
return hash(i) * (1 - u) + hash(i + 1) * u;
|
|
155
|
+
};
|
|
156
|
+
function remap(ease, args) {
|
|
157
|
+
const [t, a, b, c, d] = args;
|
|
158
|
+
let tMin = 0, tMax = 1, v1, v2;
|
|
159
|
+
if (args.length >= 5)
|
|
160
|
+
(tMin = a), (tMax = b), (v1 = c), (v2 = d);
|
|
161
|
+
else
|
|
162
|
+
(v1 = a), (v2 = b);
|
|
163
|
+
const p = tMax === tMin ? (t >= tMax ? 1 : 0) : Math.min(1, Math.max(0, (t - tMin) / (tMax - tMin)));
|
|
164
|
+
return lerpV(v1, v2, ease(tMax < tMin ? 1 - p : p));
|
|
165
|
+
}
|
|
166
|
+
function loop(c, out, type = 'cycle', n = 0, dur = 0) {
|
|
167
|
+
const K = c.keys, f = c.time * c.fr;
|
|
168
|
+
if (K.length < 2)
|
|
169
|
+
return c.value;
|
|
170
|
+
const first = K[0], last = K[K.length - 1];
|
|
171
|
+
let a = out ? (n > 0 ? K[Math.max(0, K.length - 1 - n)] : first) : first;
|
|
172
|
+
let b = out ? last : n > 0 ? K[Math.min(K.length - 1, n)] : last;
|
|
173
|
+
if (dur > 0)
|
|
174
|
+
out ? (a = last - dur * c.fr) : (b = first + dur * c.fr);
|
|
175
|
+
if (out ? f <= b : f >= a)
|
|
176
|
+
return c.value;
|
|
177
|
+
const d = b - a || 1;
|
|
178
|
+
if (type === 'continue') {
|
|
179
|
+
const e = out ? b : a, v = c.at(e), slope = out ? vsub(v, c.at(e - 1)) : vsub(c.at(e + 1), v);
|
|
180
|
+
return vadd(v, vmul(slope, f - e));
|
|
181
|
+
}
|
|
182
|
+
const over = out ? f - b : a - f, k = Math.floor(over / d), r = over - k * d;
|
|
183
|
+
if (type === 'pingpong')
|
|
184
|
+
return c.at(out ? (k % 2 ? a + r : b - r) : k % 2 ? b - r : a + r);
|
|
185
|
+
const base = c.at(out ? a + r : b - r);
|
|
186
|
+
if (type === 'offset')
|
|
187
|
+
return vadd(base, vmul(vsub(c.at(b), c.at(a)), out ? k + 1 : -(k + 1)));
|
|
188
|
+
return base; // cycle
|
|
189
|
+
}
|
|
190
|
+
/** Evaluate a compiled expression. */
|
|
191
|
+
function runExpression(ast, c) {
|
|
192
|
+
const vars = {};
|
|
193
|
+
const fr = c.fr;
|
|
194
|
+
const lib = {
|
|
195
|
+
Math,
|
|
196
|
+
thisComp: { frameDuration: 1 / fr },
|
|
197
|
+
thisLayer: {},
|
|
198
|
+
thisProperty: { value: c.value },
|
|
199
|
+
index: 1,
|
|
200
|
+
true: true,
|
|
201
|
+
false: false,
|
|
202
|
+
wiggle: (freq, amp, oct = 1, mult = 0.5, t = c.time) => {
|
|
203
|
+
const w = (d) => {
|
|
204
|
+
let s = 0, a = 1, fq = freq, tot = 0;
|
|
205
|
+
for (let o = 0; o < Math.max(1, oct); o++)
|
|
206
|
+
(s += a * noise(t * fq + c.seed * 13.7 + d * 101.3)), (tot += a), (a *= mult), (fq *= 2);
|
|
207
|
+
return s / tot;
|
|
208
|
+
};
|
|
209
|
+
return isA(c.value) ? c.value.map((v, d) => v + (isA(amp) ? amp[d] ?? 0 : amp) * w(d)) : c.value + amp * w(0);
|
|
210
|
+
},
|
|
211
|
+
loopOut: (t, n) => loop(c, true, t, n),
|
|
212
|
+
loopIn: (t, n) => loop(c, false, t, n),
|
|
213
|
+
loopOutDuration: (t, d) => loop(c, true, t, 0, d),
|
|
214
|
+
loopInDuration: (t, d) => loop(c, false, t, 0, d),
|
|
215
|
+
linear: (...a) => remap((p) => p, a),
|
|
216
|
+
ease: (...a) => remap((p) => p * p * (3 - 2 * p), a),
|
|
217
|
+
easeIn: (...a) => remap((p) => p * p, a),
|
|
218
|
+
easeOut: (...a) => remap((p) => 1 - (1 - p) * (1 - p), a),
|
|
219
|
+
clamp: (v, lo, hi) => zip(zip(v, lo, Math.max), hi, Math.min),
|
|
220
|
+
valueAtTime: (t) => c.at(t * fr),
|
|
221
|
+
framesToTime: (f) => f / fr,
|
|
222
|
+
timeToFrames: (t = c.time) => t * fr,
|
|
223
|
+
degreesToRadians: (d) => (d * Math.PI) / 180,
|
|
224
|
+
radiansToDegrees: (r) => (r * 180) / Math.PI,
|
|
225
|
+
add: vadd,
|
|
226
|
+
sub: vsub,
|
|
227
|
+
mul: vmul,
|
|
228
|
+
div: vdiv,
|
|
229
|
+
length: (a, b) => {
|
|
230
|
+
const d = b === undefined ? a : vsub(a, b);
|
|
231
|
+
return isA(d) ? Math.hypot(...d) : Math.abs(d);
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
const ev = (n) => {
|
|
235
|
+
switch (n[0]) {
|
|
236
|
+
case 'n':
|
|
237
|
+
case 's':
|
|
238
|
+
return n[1];
|
|
239
|
+
case 'arr':
|
|
240
|
+
return n[1].map(ev);
|
|
241
|
+
case 'id': {
|
|
242
|
+
const k = n[1];
|
|
243
|
+
if (k in vars)
|
|
244
|
+
return vars[k];
|
|
245
|
+
if (k === 'time')
|
|
246
|
+
return c.time;
|
|
247
|
+
if (k === 'value')
|
|
248
|
+
return c.value;
|
|
249
|
+
return lib[k];
|
|
250
|
+
}
|
|
251
|
+
case 'get': {
|
|
252
|
+
const o = ev(n[1]), k = ev(n[2]);
|
|
253
|
+
if (o === null || o === undefined || (typeof k === 'string' && /^(__proto__|constructor|prototype)$/.test(k)))
|
|
254
|
+
throw new Error('expr: bad member');
|
|
255
|
+
if (o === Math && typeof k === 'string' && !(k in Math))
|
|
256
|
+
throw new Error('expr: Math.' + k);
|
|
257
|
+
return o[k];
|
|
258
|
+
}
|
|
259
|
+
case 'call': {
|
|
260
|
+
const f = ev(n[1]);
|
|
261
|
+
if (typeof f !== 'function')
|
|
262
|
+
throw new Error('expr: not a function');
|
|
263
|
+
return f(...n[2].map(ev));
|
|
264
|
+
}
|
|
265
|
+
case 'un': {
|
|
266
|
+
const v = ev(n[2]);
|
|
267
|
+
return n[1] === '-' ? vmul(v, -1) : n[1] === '!' ? !v : v;
|
|
268
|
+
}
|
|
269
|
+
case 'bin': {
|
|
270
|
+
const a = ev(n[2]), b = ev(n[3]);
|
|
271
|
+
switch (n[1]) {
|
|
272
|
+
case '+': return vadd(a, b);
|
|
273
|
+
case '-': return vsub(a, b);
|
|
274
|
+
case '*': return vmul(a, b);
|
|
275
|
+
case '/': return vdiv(a, b);
|
|
276
|
+
case '%': return zip(a, b, (x, y) => x % y);
|
|
277
|
+
case '<': return a < b;
|
|
278
|
+
case '>': return a > b;
|
|
279
|
+
case '<=': return a <= b;
|
|
280
|
+
case '>=': return a >= b;
|
|
281
|
+
case '==':
|
|
282
|
+
case '===': return a === b;
|
|
283
|
+
case '!=':
|
|
284
|
+
case '!==': return a !== b;
|
|
285
|
+
case '&&': return a && b;
|
|
286
|
+
default: return a || b;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
case 'if':
|
|
290
|
+
return ev(n[1]) ? ev(n[2]) : ev(n[3]);
|
|
291
|
+
case 'set':
|
|
292
|
+
return (vars[n[1]] = ev(n[2]));
|
|
293
|
+
default: {
|
|
294
|
+
let r;
|
|
295
|
+
for (const s of n[1])
|
|
296
|
+
r = ev(s);
|
|
297
|
+
return '$bm_rt' in vars ? vars.$bm_rt : r;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
return ev(ast);
|
|
302
|
+
}
|
|
303
|
+
const cache = new Map();
|
|
304
|
+
/** Compile (cached); null when outside the subset. */
|
|
305
|
+
function expression(src) {
|
|
306
|
+
if (!cache.has(src)) {
|
|
307
|
+
let ast = null;
|
|
308
|
+
try {
|
|
309
|
+
ast = compileExpression(src);
|
|
310
|
+
}
|
|
311
|
+
catch {
|
|
312
|
+
ast = null;
|
|
313
|
+
}
|
|
314
|
+
cache.set(src, ast);
|
|
315
|
+
}
|
|
316
|
+
return cache.get(src);
|
|
317
|
+
}
|
|
318
|
+
|
|
8
319
|
/**
|
|
9
320
|
* `motionary/runtime/vector` (10.6) — a Lottie (bodymovin JSON) + dotLottie
|
|
10
321
|
* player written for Motionary (own renderer on Canvas 2D; no lottie-web
|
|
@@ -27,8 +338,12 @@ require('../chunks/ease-HwYZnZat.cjs');
|
|
|
27
338
|
* `DecompressionStream`), `manifest.json` v1 / v2, several animations,
|
|
28
339
|
* embedded images.
|
|
29
340
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
341
|
+
* 10.8: **text layers** (system / web fonts by family + style, justification,
|
|
342
|
+
* tracking, line height, fill + stroke, box text with wrapping, source-text
|
|
343
|
+
* keyframes and expressions) and an **expression subset** (see
|
|
344
|
+
* `lottie-expr.ts`: time, value, wiggle, loopOut / loopIn, linear / ease,
|
|
345
|
+
* Math…; no eval). Not supported (documented): 3D layers, effects, text
|
|
346
|
+
* animators, glyph outlines (`chars`), merge paths, repeaters. `lottiePlayer()` is a
|
|
32
347
|
* runtime timeline (seek, reverse, scrub with `progress`, markers → labels).
|
|
33
348
|
*/
|
|
34
349
|
// ------------------------------------------------------------------ keyframes
|
|
@@ -60,10 +375,29 @@ const lerpAny = (a, b, p) => {
|
|
|
60
375
|
return { c: a.c, v: lerpAny(a.v, b.v, p), i: lerpAny(a.i, b.i, p), o: lerpAny(a.o, b.o, p) };
|
|
61
376
|
return a;
|
|
62
377
|
};
|
|
63
|
-
|
|
378
|
+
let FR = 30; // frame rate of the composition being rendered (expressions)
|
|
379
|
+
const seedOf = (s) => Array.from(s).reduce((h, c) => (h * 31 + c.charCodeAt(0)) % 9973, 7);
|
|
380
|
+
const isKeyed = (p) => !!(p.a || (Array.isArray(p.k) && p.k.length && typeof p.k[0] === 'object' && 't' in p.k[0]));
|
|
381
|
+
/** Run a property's expression (10.8 subset) on its keyframed value; the value itself when there is none or it is unsupported. */
|
|
382
|
+
function withExpr(p, f, v) {
|
|
383
|
+
const ast = typeof p.x === 'string' ? expression(p.x) : null;
|
|
384
|
+
if (!ast)
|
|
385
|
+
return v;
|
|
386
|
+
try {
|
|
387
|
+
const r = runExpression(ast, { time: f / FR, value: v, fr: FR, at: (g) => keyValue(p, g), keys: isKeyed(p) ? p.k.map((k) => k.t) : [], seed: seedOf(p.x) });
|
|
388
|
+
return r === undefined || (typeof r === 'number' && !isFinite(r)) ? v : r;
|
|
389
|
+
}
|
|
390
|
+
catch {
|
|
391
|
+
return v;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
/** Value of an (animated or static) property at frame `f` (10.8: with its expression applied). */
|
|
64
395
|
function propValue(p, f, fallback) {
|
|
65
396
|
if (!p)
|
|
66
397
|
return fallback;
|
|
398
|
+
return withExpr(p, f, keyValue(p, f));
|
|
399
|
+
}
|
|
400
|
+
function keyValue(p, f) {
|
|
67
401
|
if (!p.a && !(Array.isArray(p.k) && p.k.length && typeof p.k[0] === 'object' && 't' in p.k[0]))
|
|
68
402
|
return p.k;
|
|
69
403
|
const ks = p.k;
|
|
@@ -432,6 +766,9 @@ function drawLayers(ctx, anim, layers, f, o, base, w, h, depth = 0) {
|
|
|
432
766
|
for (const p of ops)
|
|
433
767
|
paint(x, p, lf);
|
|
434
768
|
}
|
|
769
|
+
else if (L.ty === 5) {
|
|
770
|
+
drawText(x, anim, L, lf, m);
|
|
771
|
+
}
|
|
435
772
|
else if (L.ty === 1) {
|
|
436
773
|
x.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
|
437
774
|
x.fillStyle = L.sc || '#000';
|
|
@@ -483,9 +820,66 @@ function drawLayers(ctx, anim, layers, f, o, base, w, h, depth = 0) {
|
|
|
483
820
|
}
|
|
484
821
|
}
|
|
485
822
|
}
|
|
823
|
+
// ------------------------------------------------------------------ text layers (10.8)
|
|
824
|
+
function textDoc(L, f) {
|
|
825
|
+
const d = L.t?.d;
|
|
826
|
+
let s = d?.k?.[0]?.s;
|
|
827
|
+
for (const k of d?.k || [])
|
|
828
|
+
if (k.t <= f)
|
|
829
|
+
s = k.s;
|
|
830
|
+
if (s && typeof d.x === 'string')
|
|
831
|
+
s = { ...s, t: String(withExpr({ k: s.t, x: d.x }, f, s.t)) };
|
|
832
|
+
return s;
|
|
833
|
+
}
|
|
834
|
+
function drawText(x, anim, L, f, m) {
|
|
835
|
+
const d = textDoc(L, f);
|
|
836
|
+
if (!d)
|
|
837
|
+
return;
|
|
838
|
+
x.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
|
839
|
+
const font = anim.fonts?.list?.find((q) => q.fName === d.f);
|
|
840
|
+
const st = (font?.fStyle || d.f || '').toLowerCase();
|
|
841
|
+
const wt = /black|heavy/.test(st) ? 900 : /extra ?bold/.test(st) ? 800 : /semi ?bold|demi/.test(st) ? 600 : /bold/.test(st) ? 700 : /medium/.test(st) ? 500 : /light/.test(st) ? 300 : /thin/.test(st) ? 100 : 400;
|
|
842
|
+
x.font = `${/italic|oblique/.test(st) ? 'italic ' : ''}${wt} ${d.s}px ${font?.fFamily ? `"${font.fFamily}", ` : ''}sans-serif`;
|
|
843
|
+
x.textAlign = d.j === 1 ? 'right' : d.j === 2 ? 'center' : 'left';
|
|
844
|
+
x.textBaseline = 'alphabetic';
|
|
845
|
+
if ('letterSpacing' in x)
|
|
846
|
+
x.letterSpacing = `${((d.tr || 0) * d.s) / 1000}px`;
|
|
847
|
+
const lh = d.lh || d.s * 1.2;
|
|
848
|
+
let lines = String(d.t ?? '').split(/\r\n|\r|\n|\u0003/);
|
|
849
|
+
let ox = 0, oy = 0;
|
|
850
|
+
if (d.sz) {
|
|
851
|
+
// box text: wrap to the box width; `ps` is the box's top-left
|
|
852
|
+
const bw = d.sz[0], [px, py] = d.ps || [0, 0];
|
|
853
|
+
lines = lines.flatMap((ln) => {
|
|
854
|
+
const out = [];
|
|
855
|
+
let cur = '';
|
|
856
|
+
for (const w of ln.split(' ')) {
|
|
857
|
+
const t = cur ? cur + ' ' + w : w;
|
|
858
|
+
if (cur && x.measureText(t).width > bw)
|
|
859
|
+
out.push(cur), (cur = w);
|
|
860
|
+
else
|
|
861
|
+
cur = t;
|
|
862
|
+
}
|
|
863
|
+
return out.concat(cur);
|
|
864
|
+
});
|
|
865
|
+
ox = px + (d.j === 1 ? bw : d.j === 2 ? bw / 2 : 0);
|
|
866
|
+
oy = py + d.s;
|
|
867
|
+
}
|
|
868
|
+
const fill = d.fc ? col(d.fc) : null, stroke = d.sc && d.sw ? col(d.sc) : null;
|
|
869
|
+
lines.forEach((ln, i) => {
|
|
870
|
+
const y = oy + i * lh;
|
|
871
|
+
const F = () => fill && ((x.fillStyle = fill), x.fillText(ln, ox, y));
|
|
872
|
+
const S = () => stroke && ((x.strokeStyle = stroke), (x.lineWidth = d.sw), (x.lineJoin = 'round'), x.strokeText(ln, ox, y));
|
|
873
|
+
if (d.of)
|
|
874
|
+
F(), S();
|
|
875
|
+
else
|
|
876
|
+
S(), F();
|
|
877
|
+
});
|
|
878
|
+
}
|
|
486
879
|
/** Render one frame onto a 2D context sized `width × height` (the animation is fitted with `fit`). */
|
|
487
880
|
function renderLottieFrame(ctx, anim, frame, o = {}) {
|
|
488
881
|
const W = o.width ?? ctx.canvas.width, H = o.height ?? ctx.canvas.height;
|
|
882
|
+
FR = anim.fr || 30;
|
|
489
883
|
ctx.save();
|
|
490
884
|
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
491
885
|
ctx.clearRect(0, 0, W, H);
|
|
@@ -527,16 +921,21 @@ function inspectLottie(anim) {
|
|
|
527
921
|
u.add('3D layers');
|
|
528
922
|
if (l.ef?.length)
|
|
529
923
|
u.add('effects');
|
|
530
|
-
if (l.ty === 5)
|
|
531
|
-
u.add('text
|
|
924
|
+
if (l.ty === 5 && l.t?.a?.length)
|
|
925
|
+
u.add('text animators (range selectors)');
|
|
532
926
|
if (l.tt === 3 || l.tt === 4)
|
|
533
927
|
u.add('luma mattes (approximated by alpha)');
|
|
534
|
-
|
|
535
|
-
|
|
928
|
+
JSON.stringify([l.ks, l.t, l.shapes], (k, v) => {
|
|
929
|
+
if (k === 'x' && typeof v === 'string' && !expression(v))
|
|
930
|
+
u.add('expressions outside the supported subset');
|
|
931
|
+
return v;
|
|
932
|
+
});
|
|
536
933
|
walkShapes(l.shapes || []);
|
|
537
934
|
});
|
|
538
935
|
walk(anim.layers);
|
|
539
936
|
anim.assets?.forEach((a) => a.layers && walk(a.layers));
|
|
937
|
+
if (anim.chars?.length)
|
|
938
|
+
u.add('glyph outlines (chars): drawn with system fonts');
|
|
540
939
|
return { layers: anim.layers.length, unsupported: [...u] };
|
|
541
940
|
}
|
|
542
941
|
/** Read a zip archive's entries (central directory; stored + deflate). Pure; inflating uses `DecompressionStream`. */
|
|
@@ -687,9 +1086,20 @@ class LPlayer extends tween.Playable {
|
|
|
687
1086
|
function lottiePlayer(canvas, animation, o = {}) {
|
|
688
1087
|
return new LPlayer(canvas, animation, o);
|
|
689
1088
|
}
|
|
1089
|
+
/** Evaluate a Lottie expression (10.8 subset) on a value at `time` seconds — `undefined` when it is outside the subset. */
|
|
1090
|
+
function evalExpression(src, value, time = 0, fr = 30) {
|
|
1091
|
+
const ast = expression(src);
|
|
1092
|
+
try {
|
|
1093
|
+
return ast ? runExpression(ast, { time, value, fr, at: () => value, keys: [], seed: seedOf(src) }) : undefined;
|
|
1094
|
+
}
|
|
1095
|
+
catch {
|
|
1096
|
+
return undefined;
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
690
1099
|
/** The module object for `use(vector)`. */
|
|
691
|
-
const vector = { id: 'vector', version: registry.RUNTIME_VERSION, requires: ['core'], api: { loadLottie, parseDotLottie, unzipEntries, lottiePlayer, renderLottieFrame, inspectLottie, propValue, transformAt, trimContours, loadLottieImages } };
|
|
1100
|
+
const vector = { id: 'vector', version: registry.RUNTIME_VERSION, requires: ['core'], api: { evalExpression, loadLottie, parseDotLottie, unzipEntries, lottiePlayer, renderLottieFrame, inspectLottie, propValue, transformAt, trimContours, loadLottieImages } };
|
|
692
1101
|
|
|
1102
|
+
exports.evalExpression = evalExpression;
|
|
693
1103
|
exports.inspectLottie = inspectLottie;
|
|
694
1104
|
exports.loadLottie = loadLottie;
|
|
695
1105
|
exports.loadLottieImages = loadLottieImages;
|