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