@rendiv/core 0.1.0 → 0.1.1

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/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import G, { createContext as P, useContext as p, useEffect as N, forwardRef as ie, useId as se, useMemo as H, Children as J, useRef as F, useCallback as V, useState as ae } from "react";
2
- import { jsx as E, Fragment as ce } from "react/jsx-runtime";
3
- const x = P({
1
+ import G, { createContext as O, useContext as p, useEffect as M, forwardRef as le, useId as ae, useMemo as H, Children as J, useRef as R, useCallback as $, useState as ee } from "react";
2
+ import { jsx as I, Fragment as se } from "react/jsx-runtime";
3
+ const F = O({
4
4
  frame: 0,
5
5
  playing: !1,
6
6
  playingRef: { current: !1 }
7
- }), R = P({
7
+ }), x = O({
8
8
  id: null,
9
9
  from: 0,
10
10
  durationInFrames: 1 / 0,
@@ -12,13 +12,13 @@ const x = P({
12
12
  accumulatedOffset: 0,
13
13
  localOffset: 0
14
14
  });
15
- function Ne() {
16
- const e = p(x), n = p(R);
15
+ function Re() {
16
+ const e = p(F), n = p(x);
17
17
  return e.frame - n.accumulatedOffset;
18
18
  }
19
- const z = P(null);
20
- function _e() {
21
- const e = p(z);
19
+ const D = O(null);
20
+ function Fe() {
21
+ const e = p(D);
22
22
  if (!e)
23
23
  throw new Error(
24
24
  "useCompositionConfig() must be called inside a <Composition>, <Player>, or during rendering."
@@ -26,17 +26,17 @@ function _e() {
26
26
  return e;
27
27
  }
28
28
  const X = () => {
29
- }, ee = P({
29
+ }, ne = O({
30
30
  compositions: [],
31
31
  registerComposition: X,
32
32
  unregisterComposition: X,
33
33
  currentCompositionId: null,
34
34
  setCurrentCompositionId: X,
35
35
  inputProps: {}
36
- }), A = P(null);
37
- function Fe(e) {
38
- const { registerComposition: n, unregisterComposition: t } = p(ee), o = p(A);
39
- return N(() => (n({
36
+ }), j = O(null);
37
+ function xe(e) {
38
+ const { registerComposition: n, unregisterComposition: t } = p(ne), o = p(j);
39
+ return M(() => (n({
40
40
  id: e.id,
41
41
  component: e.component,
42
42
  durationInFrames: e.durationInFrames,
@@ -49,7 +49,7 @@ function Fe(e) {
49
49
  type: "composition"
50
50
  }), () => t(e.id)), [e.id]), null;
51
51
  }
52
- const le = {
52
+ const ue = {
53
53
  position: "absolute",
54
54
  top: 0,
55
55
  left: 0,
@@ -59,18 +59,18 @@ const le = {
59
59
  height: "100%",
60
60
  display: "flex",
61
61
  flexDirection: "column"
62
- }, U = ie(
63
- ({ style: e, ...n }, t) => /* @__PURE__ */ E(
62
+ }, W = le(
63
+ ({ style: e, ...n }, t) => /* @__PURE__ */ I(
64
64
  "div",
65
65
  {
66
66
  ref: t,
67
- style: { ...le, ...e },
67
+ style: { ...ue, ...e },
68
68
  ...n
69
69
  }
70
70
  )
71
71
  );
72
- U.displayName = "Fill";
73
- const ne = ({
72
+ W.displayName = "Fill";
73
+ const te = ({
74
74
  from: e = 0,
75
75
  durationInFrames: n = 1 / 0,
76
76
  name: t,
@@ -78,35 +78,35 @@ const ne = ({
78
78
  style: r,
79
79
  children: i
80
80
  }) => {
81
- const s = p(R), a = p(x), l = se(), d = s.accumulatedOffset + e, g = a.frame;
82
- N(() => {
81
+ const c = p(x), l = p(F), u = ae(), a = c.accumulatedOffset + e, m = l.frame;
82
+ M(() => {
83
83
  if (typeof window > "u") return;
84
- const y = window;
85
- y.__RENDIV_TIMELINE_ENTRIES__ || (y.__RENDIV_TIMELINE_ENTRIES__ = /* @__PURE__ */ new Map());
86
- const u = y.__RENDIV_TIMELINE_ENTRIES__, c = s.id, f = { id: l, name: t ?? "Sequence", from: d, durationInFrames: n, parentId: c };
87
- return u.set(l, f), document.dispatchEvent(new CustomEvent("rendiv:timeline-sync")), () => {
88
- u.delete(l), document.dispatchEvent(new CustomEvent("rendiv:timeline-sync"));
84
+ const w = window;
85
+ w.__RENDIV_TIMELINE_ENTRIES__ || (w.__RENDIV_TIMELINE_ENTRIES__ = /* @__PURE__ */ new Map());
86
+ const f = w.__RENDIV_TIMELINE_ENTRIES__, s = c.id, d = { id: u, name: t ?? "Sequence", from: a, durationInFrames: n, parentId: s };
87
+ return f.set(u, d), document.dispatchEvent(new CustomEvent("rendiv:timeline-sync")), () => {
88
+ f.delete(u), document.dispatchEvent(new CustomEvent("rendiv:timeline-sync"));
89
89
  };
90
- }, [l, t, d, n]);
91
- const m = H(
90
+ }, [u, t, a, n]);
91
+ const h = H(
92
92
  () => ({
93
- id: l,
94
- from: d,
93
+ id: u,
94
+ from: a,
95
95
  durationInFrames: n,
96
- parentOffset: s.accumulatedOffset,
97
- accumulatedOffset: d,
96
+ parentOffset: c.accumulatedOffset,
97
+ accumulatedOffset: a,
98
98
  localOffset: e
99
99
  }),
100
- [l, d, n, s.accumulatedOffset, e]
100
+ [u, a, n, c.accumulatedOffset, e]
101
101
  );
102
- if (g < d || g >= d + n) return null;
103
- const b = /* @__PURE__ */ E(R.Provider, { value: m, children: i });
104
- return o === "none" ? b : /* @__PURE__ */ E(U, { style: r, children: b });
102
+ if (m < a || m >= a + n) return null;
103
+ const b = /* @__PURE__ */ I(x.Provider, { value: h, children: i });
104
+ return o === "none" ? b : /* @__PURE__ */ I(W, { style: r, children: b });
105
105
  };
106
- ne.displayName = "Sequence";
107
- function xe(e) {
108
- const { registerComposition: n, unregisterComposition: t } = p(ee), o = p(A);
109
- return N(() => (n({
106
+ te.displayName = "Sequence";
107
+ function $e(e) {
108
+ const { registerComposition: n, unregisterComposition: t } = p(ne), o = p(j);
109
+ return M(() => (n({
110
110
  id: e.id,
111
111
  component: e.component,
112
112
  durationInFrames: 1,
@@ -118,99 +118,99 @@ function xe(e) {
118
118
  type: "still"
119
119
  }), () => t(e.id)), [e.id]), null;
120
120
  }
121
- const ue = ({ name: e, children: n }) => {
122
- const t = p(A), o = t ? `${t}/${e}` : e;
123
- return /* @__PURE__ */ E(A.Provider, { value: o, children: n });
121
+ const fe = ({ name: e, children: n }) => {
122
+ const t = p(j), o = t ? `${t}/${e}` : e;
123
+ return /* @__PURE__ */ I(j.Provider, { value: o, children: n });
124
124
  };
125
- ue.displayName = "Folder";
126
- function j(e) {
125
+ fe.displayName = "Folder";
126
+ function Y(e) {
127
127
  throw new Error(
128
128
  "<Series.Sequence> can only be used as a direct child of <Series>."
129
129
  );
130
130
  }
131
- j.displayName = "Series.Sequence";
132
- function te({ children: e }) {
131
+ Y.displayName = "Series.Sequence";
132
+ function re({ children: e }) {
133
133
  const n = J.toArray(e);
134
134
  let t = 0;
135
135
  const o = [];
136
136
  for (const r of n) {
137
137
  if (!G.isValidElement(r)) continue;
138
- if (r.type !== j)
138
+ if (r.type !== Y)
139
139
  throw new Error(
140
140
  "Only <Series.Sequence> elements are allowed as children of <Series>."
141
141
  );
142
142
  const {
143
143
  durationInFrames: i,
144
- offset: s = 0,
145
- name: a,
146
- layout: l,
147
- style: d,
148
- children: g
149
- } = r.props, m = t + s;
150
- let b = a;
144
+ offset: c = 0,
145
+ name: l,
146
+ layout: u,
147
+ style: a,
148
+ children: m
149
+ } = r.props, h = t + c;
150
+ let b = l;
151
151
  if (!b) {
152
- const y = J.toArray(g);
153
- if (y.length > 0) {
154
- const u = y[0];
155
- if (G.isValidElement(u) && typeof u.type != "string") {
156
- const c = u.type;
157
- b = c.displayName || c.name;
152
+ const w = J.toArray(m);
153
+ if (w.length > 0) {
154
+ const f = w[0];
155
+ if (G.isValidElement(f) && typeof f.type != "string") {
156
+ const s = f.type;
157
+ b = s.displayName || s.name;
158
158
  }
159
159
  }
160
160
  }
161
161
  o.push(
162
- /* @__PURE__ */ E(
163
- ne,
162
+ /* @__PURE__ */ I(
163
+ te,
164
164
  {
165
- from: m,
165
+ from: h,
166
166
  durationInFrames: i,
167
167
  name: b,
168
- layout: l,
169
- style: d,
170
- children: g
168
+ layout: u,
169
+ style: a,
170
+ children: m
171
171
  },
172
172
  r.key ?? o.length
173
173
  )
174
- ), t = m + i;
174
+ ), t = h + i;
175
175
  }
176
- return /* @__PURE__ */ E(ce, { children: o });
176
+ return /* @__PURE__ */ I(se, { children: o });
177
177
  }
178
- te.displayName = "Series";
179
- const Re = Object.assign(te, {
180
- Sequence: j
178
+ re.displayName = "Series";
179
+ const Pe = Object.assign(re, {
180
+ Sequence: Y
181
181
  });
182
- function fe({
182
+ function de({
183
183
  durationInFrames: e,
184
184
  times: n = 1 / 0,
185
185
  layout: t = "absolute-fill",
186
186
  style: o,
187
187
  children: r
188
188
  }) {
189
- const i = p(x), s = p(R), a = i.frame - s.accumulatedOffset;
190
- if (a < 0 || n !== 1 / 0 && a >= e * n) return null;
191
- const l = a % e, d = H(
189
+ const i = p(F), c = p(x), l = i.frame - c.accumulatedOffset;
190
+ if (l < 0 || n !== 1 / 0 && l >= e * n) return null;
191
+ const u = l % e, a = H(
192
192
  () => ({
193
- frame: l + s.accumulatedOffset,
193
+ frame: u + c.accumulatedOffset,
194
194
  playing: i.playing,
195
195
  playingRef: i.playingRef
196
196
  }),
197
- [l, s.accumulatedOffset, i.playing, i.playingRef]
198
- ), g = H(
197
+ [u, c.accumulatedOffset, i.playing, i.playingRef]
198
+ ), m = H(
199
199
  () => ({
200
200
  id: null,
201
- from: s.accumulatedOffset,
201
+ from: c.accumulatedOffset,
202
202
  durationInFrames: e,
203
- parentOffset: s.accumulatedOffset,
204
- accumulatedOffset: s.accumulatedOffset,
203
+ parentOffset: c.accumulatedOffset,
204
+ accumulatedOffset: c.accumulatedOffset,
205
205
  localOffset: 0
206
206
  }),
207
- [s.accumulatedOffset, e]
208
- ), m = /* @__PURE__ */ E(x.Provider, { value: d, children: /* @__PURE__ */ E(R.Provider, { value: g, children: r }) });
209
- return t === "none" ? m : /* @__PURE__ */ E(U, { style: o, children: m });
207
+ [c.accumulatedOffset, e]
208
+ ), h = /* @__PURE__ */ I(F.Provider, { value: a, children: /* @__PURE__ */ I(x.Provider, { value: m, children: r }) });
209
+ return t === "none" ? h : /* @__PURE__ */ I(W, { style: o, children: h });
210
210
  }
211
- fe.displayName = "Loop";
212
- function de({ frame: e, children: n }) {
213
- const t = p(x), o = H(
211
+ de.displayName = "Loop";
212
+ function me({ frame: e, children: n }) {
213
+ const t = p(F), o = H(
214
214
  () => ({
215
215
  frame: e,
216
216
  playing: t.playing,
@@ -218,149 +218,149 @@ function de({ frame: e, children: n }) {
218
218
  }),
219
219
  [e, t.playing, t.playingRef]
220
220
  );
221
- return /* @__PURE__ */ E(x.Provider, { value: o, children: n });
221
+ return /* @__PURE__ */ I(F.Provider, { value: o, children: n });
222
222
  }
223
- de.displayName = "Freeze";
224
- let me = 0;
225
- const $ = /* @__PURE__ */ new Map();
226
- function D(e, n) {
227
- const t = ++me, o = e ?? `Handle ${t}`, { timeoutInMilliseconds: r } = n ?? {};
223
+ me.displayName = "Freeze";
224
+ let he = 0;
225
+ const L = /* @__PURE__ */ new Map();
226
+ function k(e, n) {
227
+ const t = ++he, o = e ?? `Handle ${t}`, { timeoutInMilliseconds: r } = n ?? {};
228
228
  let i = null;
229
229
  return r !== void 0 && r > 0 && (i = setTimeout(() => {
230
- if ($.has(t))
231
- throw $.delete(t), new Error(
230
+ if (L.has(t))
231
+ throw L.delete(t), new Error(
232
232
  `holdRender() timed out after ${r}ms (label: "${o}"). You can increase the timeout by passing a larger timeoutInMilliseconds to holdRender().`
233
233
  );
234
- }, r)), $.set(t, { label: o, timeoutId: i }), t;
234
+ }, r)), L.set(t, { label: o, timeoutId: i }), t;
235
235
  }
236
- function _(e) {
237
- const n = $.get(e);
236
+ function S(e) {
237
+ const n = L.get(e);
238
238
  if (!n)
239
239
  throw new Error(
240
240
  `releaseRender() was called with handle ${e}, but no corresponding holdRender() exists.`
241
241
  );
242
- n.timeoutId !== null && clearTimeout(n.timeoutId), $.delete(e);
242
+ n.timeoutId !== null && clearTimeout(n.timeoutId), L.delete(e);
243
243
  }
244
- function Te(e) {
244
+ function Le(e) {
245
245
  throw new Error(`Render cancelled: ${e}`);
246
246
  }
247
- function $e() {
248
- return $.size;
247
+ function Oe() {
248
+ return L.size;
249
249
  }
250
- function Pe() {
251
- return Array.from($.values()).map((e) => e.label);
250
+ function Te() {
251
+ return Array.from(L.values()).map((e) => e.label);
252
252
  }
253
- function he({
253
+ function ge({
254
254
  holdRenderTimeout: e = 3e4,
255
255
  onLoad: n,
256
256
  onError: t,
257
257
  ...o
258
258
  }) {
259
- const r = F(null);
260
- N(() => {
261
- const a = D(
259
+ const r = R(null);
260
+ M(() => {
261
+ const l = k(
262
262
  `Loading <Img> with src="${o.src}"`,
263
263
  { timeoutInMilliseconds: e }
264
264
  );
265
- return r.current = a, () => {
266
- r.current !== null && (_(r.current), r.current = null);
265
+ return r.current = l, () => {
266
+ r.current !== null && (S(r.current), r.current = null);
267
267
  };
268
268
  }, [o.src, e]);
269
- const i = V(
270
- (a) => {
271
- r.current !== null && (_(r.current), r.current = null), n == null || n(a);
269
+ const i = $(
270
+ (l) => {
271
+ r.current !== null && (S(r.current), r.current = null), n == null || n(l);
272
272
  },
273
273
  [n]
274
- ), s = V(
275
- (a) => {
276
- r.current !== null && (_(r.current), r.current = null), t == null || t(a);
274
+ ), c = $(
275
+ (l) => {
276
+ r.current !== null && (S(r.current), r.current = null), t == null || t(l);
277
277
  },
278
278
  [t]
279
279
  );
280
- return /* @__PURE__ */ E(
280
+ return /* @__PURE__ */ I(
281
281
  "img",
282
282
  {
283
283
  ...o,
284
284
  onLoad: i,
285
- onError: s
285
+ onError: c
286
286
  }
287
287
  );
288
288
  }
289
- he.displayName = "Img";
290
- const Y = P({
289
+ ge.displayName = "Img";
290
+ const z = O({
291
291
  environment: "studio"
292
292
  });
293
- function ge({
293
+ function oe({
294
294
  src: e,
295
295
  startFrom: n = 0,
296
296
  endAt: t,
297
297
  volume: o = 1,
298
298
  playbackRate: r = 1,
299
299
  muted: i = !1,
300
- style: s,
301
- className: a,
302
- holdRenderTimeout: l = 3e4,
303
- ...d
300
+ style: c,
301
+ className: l,
302
+ holdRenderTimeout: u = 3e4,
303
+ ...a
304
304
  }) {
305
- const g = F(null), m = p(x), b = p(R), y = p(z), { environment: u } = p(Y), c = F(null), f = F(null), w = u === "rendering", v = (y == null ? void 0 : y.fps) ?? 30, M = m.frame - b.accumulatedOffset, I = M + n, C = I / v;
306
- N(() => {
307
- const h = D(
305
+ const m = R(null), h = p(F), b = p(x), w = p(D), { environment: f } = p(z), s = R(null), d = R(null), y = f === "rendering", v = (w == null ? void 0 : w.fps) ?? 30, _ = h.frame - b.accumulatedOffset, C = _ + n, E = C / v;
306
+ M(() => {
307
+ const g = k(
308
308
  `Loading <Video> metadata for src="${e}"`,
309
- { timeoutInMilliseconds: l }
309
+ { timeoutInMilliseconds: u }
310
310
  );
311
- return c.current = h, () => {
312
- c.current !== null && (_(c.current), c.current = null);
311
+ return s.current = g, () => {
312
+ s.current !== null && (S(s.current), s.current = null);
313
313
  };
314
- }, [e, l]);
315
- const T = V(() => {
316
- c.current !== null && (_(c.current), c.current = null);
317
- }, []), q = V(() => {
318
- c.current !== null && (_(c.current), c.current = null);
314
+ }, [e, u]);
315
+ const P = $(() => {
316
+ s.current !== null && (S(s.current), s.current = null);
317
+ }, []), T = $(() => {
318
+ s.current !== null && (S(s.current), s.current = null);
319
319
  }, []);
320
- return N(() => {
321
- const h = g.current;
322
- h && (h.volume = o, h.muted = i);
323
- }, [o, i]), N(() => {
324
- const h = g.current;
325
- h && (h.playbackRate = r);
326
- }, [r]), N(() => {
327
- const h = g.current;
328
- if (h) {
329
- if (t !== void 0 && I >= t) {
330
- h.pause();
320
+ return M(() => {
321
+ const g = m.current;
322
+ g && (g.volume = o, g.muted = i);
323
+ }, [o, i]), M(() => {
324
+ const g = m.current;
325
+ g && (g.playbackRate = r);
326
+ }, [r]), M(() => {
327
+ const g = m.current;
328
+ if (g) {
329
+ if (t !== void 0 && C >= t) {
330
+ g.pause();
331
331
  return;
332
332
  }
333
- if (w) {
334
- if (h.pause(), f.current !== C) {
335
- f.current = C;
336
- const S = D(
337
- `Seeking <Video> to ${C.toFixed(3)}s`,
338
- { timeoutInMilliseconds: l }
339
- ), k = () => {
340
- _(S), h.removeEventListener("seeked", k);
333
+ if (y) {
334
+ if (g.pause(), d.current !== E) {
335
+ d.current = E;
336
+ const N = k(
337
+ `Seeking <Video> to ${E.toFixed(3)}s`,
338
+ { timeoutInMilliseconds: u }
339
+ ), V = () => {
340
+ S(N), g.removeEventListener("seeked", V);
341
341
  };
342
- h.addEventListener("seeked", k), h.currentTime = C;
342
+ g.addEventListener("seeked", V), g.currentTime = E;
343
343
  }
344
344
  } else
345
- Math.abs(h.currentTime - C) > 0.1 && (h.currentTime = C), m.playing && h.paused ? h.play().catch(() => {
346
- }) : !m.playing && !h.paused && h.pause();
345
+ Math.abs(g.currentTime - E) > 0.1 && (g.currentTime = E), h.playing && g.paused ? g.play().catch(() => {
346
+ }) : !h.playing && !g.paused && g.pause();
347
347
  }
348
- }, [M, w, C, m.playing, t, I, l]), /* @__PURE__ */ E(
348
+ }, [_, y, E, h.playing, t, C, u]), /* @__PURE__ */ I(
349
349
  "video",
350
350
  {
351
- ref: g,
351
+ ref: m,
352
352
  src: e,
353
353
  preload: "auto",
354
354
  playsInline: !0,
355
- style: s,
356
- className: a,
357
- onLoadedMetadata: T,
358
- onError: q,
359
- ...d
355
+ style: c,
356
+ className: l,
357
+ onLoadedMetadata: P,
358
+ onError: T,
359
+ ...a
360
360
  }
361
361
  );
362
362
  }
363
- ge.displayName = "Video";
363
+ oe.displayName = "Video";
364
364
  function pe({
365
365
  src: e,
366
366
  startFrom: n = 0,
@@ -369,21 +369,21 @@ function pe({
369
369
  playbackRate: r = 1,
370
370
  muted: i = !1
371
371
  }) {
372
- const s = F(null), a = p(x), l = p(R), d = p(z), { environment: g } = p(Y), m = g === "rendering", b = (d == null ? void 0 : d.fps) ?? 30, y = a.frame - l.accumulatedOffset, u = y + n, c = u / b;
373
- return N(() => {
374
- if (m) return;
375
- const f = s.current;
376
- if (!f) return;
377
- if (f.volume = o, f.muted = i, f.playbackRate = r, t !== void 0 && u >= t) {
378
- f.pause();
372
+ const c = R(null), l = p(F), u = p(x), a = p(D), { environment: m } = p(z), h = m === "rendering", b = (a == null ? void 0 : a.fps) ?? 30, w = l.frame - u.accumulatedOffset, f = w + n, s = f / b;
373
+ return M(() => {
374
+ if (h) return;
375
+ const d = c.current;
376
+ if (!d) return;
377
+ if (d.volume = o, d.muted = i, d.playbackRate = r, t !== void 0 && f >= t) {
378
+ d.pause();
379
379
  return;
380
380
  }
381
- Math.abs(f.currentTime - c) > 0.1 && (f.currentTime = c), a.playing && f.paused ? f.play().catch(() => {
382
- }) : !a.playing && !f.paused && f.pause();
383
- }, [y, m, c, a.playing, o, i, r, t, u]), m ? null : /* @__PURE__ */ E(
381
+ Math.abs(d.currentTime - s) > 0.1 && (d.currentTime = s), l.playing && d.paused ? d.play().catch(() => {
382
+ }) : !l.playing && !d.paused && d.pause();
383
+ }, [w, h, s, l.playing, o, i, r, t, f]), h ? null : /* @__PURE__ */ I(
384
384
  "audio",
385
385
  {
386
- ref: s,
386
+ ref: c,
387
387
  src: e,
388
388
  preload: "auto"
389
389
  }
@@ -398,68 +398,68 @@ function ye({
398
398
  className: r,
399
399
  holdRenderTimeout: i = 3e4
400
400
  }) {
401
- const s = F(null), a = p(x), l = p(R), d = p(z), g = F([]), m = F(null), [b, y] = ae(!1), u = (d == null ? void 0 : d.fps) ?? 30, c = a.frame - l.accumulatedOffset;
402
- return N(() => {
403
- const f = D(
401
+ const c = R(null), l = p(F), u = p(x), a = p(D), m = R([]), h = R(null), [b, w] = ee(!1), f = (a == null ? void 0 : a.fps) ?? 30, s = l.frame - u.accumulatedOffset;
402
+ return M(() => {
403
+ const d = k(
404
404
  `Loading <AnimatedImage> frames from "${e}"`,
405
405
  { timeoutInMilliseconds: i }
406
406
  );
407
- m.current = f;
408
- let w = !1;
407
+ h.current = d;
408
+ let y = !1;
409
409
  async function v() {
410
410
  try {
411
- const I = await (await fetch(e)).blob();
411
+ const C = await (await fetch(e)).blob();
412
412
  if (typeof ImageDecoder < "u") {
413
- const C = new ImageDecoder({
414
- data: await I.arrayBuffer(),
415
- type: I.type
413
+ const E = new ImageDecoder({
414
+ data: await C.arrayBuffer(),
415
+ type: C.type
416
416
  });
417
- await C.tracks.ready;
418
- const T = C.tracks.selectedTrack;
419
- if (!T) throw new Error("No image track found");
420
- const q = T.frameCount, h = [];
421
- for (let S = 0; S < q; S++) {
422
- const k = await C.decode({ frameIndex: S }), re = await createImageBitmap(k.image), oe = (k.image.duration ?? 1e5) / 1e3;
423
- h.push({ image: re, duration: oe }), k.image.close();
417
+ await E.tracks.ready;
418
+ const P = E.tracks.selectedTrack;
419
+ if (!P) throw new Error("No image track found");
420
+ const T = P.frameCount, g = [];
421
+ for (let N = 0; N < T; N++) {
422
+ const V = await E.decode({ frameIndex: N }), ie = await createImageBitmap(V.image), ce = (V.image.duration ?? 1e5) / 1e3;
423
+ g.push({ image: ie, duration: ce }), V.image.close();
424
424
  }
425
- C.close(), w || (g.current = h, y(!0));
425
+ E.close(), y || (m.current = g, w(!0));
426
426
  } else {
427
- const C = await createImageBitmap(I);
428
- w || (g.current = [{ image: C, duration: 1 / 0 }], y(!0));
427
+ const E = await createImageBitmap(C);
428
+ y || (m.current = [{ image: E, duration: 1 / 0 }], w(!0));
429
429
  }
430
- } catch (M) {
431
- console.error("AnimatedImage: failed to decode frames", M);
430
+ } catch (_) {
431
+ console.error("AnimatedImage: failed to decode frames", _);
432
432
  } finally {
433
- m.current !== null && (_(m.current), m.current = null);
433
+ h.current !== null && (S(h.current), h.current = null);
434
434
  }
435
435
  }
436
436
  return v(), () => {
437
- w = !0, m.current !== null && (_(m.current), m.current = null);
437
+ y = !0, h.current !== null && (S(h.current), h.current = null);
438
438
  };
439
- }, [e, i]), N(() => {
440
- if (!b || g.current.length === 0) return;
441
- const f = s.current;
442
- if (!f) return;
443
- const w = f.getContext("2d");
444
- if (!w) return;
445
- const v = g.current, M = c / u * 1e3;
446
- let I = 0;
447
- for (const S of v)
448
- I += S.duration;
449
- if (I <= 0) return;
450
- const C = (M % I + I) % I;
451
- let T = 0, q = 0;
452
- for (let S = 0; S < v.length; S++)
453
- if (T += v[S].duration, C < T) {
454
- q = S;
439
+ }, [e, i]), M(() => {
440
+ if (!b || m.current.length === 0) return;
441
+ const d = c.current;
442
+ if (!d) return;
443
+ const y = d.getContext("2d");
444
+ if (!y) return;
445
+ const v = m.current, _ = s / f * 1e3;
446
+ let C = 0;
447
+ for (const N of v)
448
+ C += N.duration;
449
+ if (C <= 0) return;
450
+ const E = (_ % C + C) % C;
451
+ let P = 0, T = 0;
452
+ for (let N = 0; N < v.length; N++)
453
+ if (P += v[N].duration, E < P) {
454
+ T = N;
455
455
  break;
456
456
  }
457
- const h = v[q];
458
- h && (f.width = n ?? h.image.width, f.height = t ?? h.image.height, w.clearRect(0, 0, f.width, f.height), w.drawImage(h.image, 0, 0, f.width, f.height));
459
- }, [c, u, b, n, t]), /* @__PURE__ */ E(
457
+ const g = v[T];
458
+ g && (d.width = n ?? g.image.width, d.height = t ?? g.image.height, y.clearRect(0, 0, d.width, d.height), y.drawImage(g.image, 0, 0, d.width, d.height));
459
+ }, [s, f, b, n, t]), /* @__PURE__ */ I(
460
460
  "canvas",
461
461
  {
462
- ref: s,
462
+ ref: c,
463
463
  width: n,
464
464
  height: t,
465
465
  style: o,
@@ -474,63 +474,159 @@ function we({
474
474
  onError: t,
475
475
  ...o
476
476
  }) {
477
- const r = F(null);
478
- N(() => {
479
- const a = D(
477
+ const r = R(null);
478
+ M(() => {
479
+ const l = k(
480
480
  `Loading <IFrame> with src="${o.src}"`,
481
481
  { timeoutInMilliseconds: e }
482
482
  );
483
- return r.current = a, () => {
484
- r.current !== null && (_(r.current), r.current = null);
483
+ return r.current = l, () => {
484
+ r.current !== null && (S(r.current), r.current = null);
485
485
  };
486
486
  }, [o.src, e]);
487
- const i = V(
488
- (a) => {
489
- r.current !== null && (_(r.current), r.current = null), n == null || n(a);
487
+ const i = $(
488
+ (l) => {
489
+ r.current !== null && (S(r.current), r.current = null), n == null || n(l);
490
490
  },
491
491
  [n]
492
- ), s = V(
493
- (a) => {
494
- r.current !== null && (_(r.current), r.current = null), t == null || t(a);
492
+ ), c = $(
493
+ (l) => {
494
+ r.current !== null && (S(r.current), r.current = null), t == null || t(l);
495
495
  },
496
496
  [t]
497
497
  );
498
- return /* @__PURE__ */ E(
498
+ return /* @__PURE__ */ I(
499
499
  "iframe",
500
500
  {
501
501
  ...o,
502
502
  onLoad: i,
503
- onError: s
503
+ onError: c
504
504
  }
505
505
  );
506
506
  }
507
507
  we.displayName = "IFrame";
508
- function be(e, n) {
508
+ function be({
509
+ src: e,
510
+ startFrom: n = 0,
511
+ endAt: t,
512
+ volume: o = 1,
513
+ playbackRate: r = 1,
514
+ muted: i = !1,
515
+ style: c,
516
+ className: l,
517
+ holdRenderTimeout: u = 3e4
518
+ }) {
519
+ const a = p(F), m = p(x), h = p(D), { environment: b } = p(z), w = b === "rendering", f = (h == null ? void 0 : h.fps) ?? 30, d = a.frame - m.accumulatedOffset + n, y = d / f;
520
+ return w ? /* @__PURE__ */ I(
521
+ ve,
522
+ {
523
+ src: e,
524
+ currentTime: y,
525
+ videoFrame: d,
526
+ endAt: t,
527
+ style: c,
528
+ className: l,
529
+ holdRenderTimeout: u
530
+ }
531
+ ) : /* @__PURE__ */ I(
532
+ oe,
533
+ {
534
+ src: e,
535
+ startFrom: n,
536
+ endAt: t,
537
+ volume: o,
538
+ playbackRate: r,
539
+ muted: i,
540
+ style: c,
541
+ className: l,
542
+ holdRenderTimeout: u
543
+ }
544
+ );
545
+ }
546
+ be.displayName = "OffthreadVideo";
547
+ function ve({
548
+ src: e,
549
+ currentTime: n,
550
+ videoFrame: t,
551
+ endAt: o,
552
+ style: r,
553
+ className: i,
554
+ holdRenderTimeout: c
555
+ }) {
556
+ const [l, u] = ee(null), a = R(null), m = R(null);
557
+ if (o !== void 0 && t >= o)
558
+ return null;
559
+ M(() => {
560
+ const w = k(
561
+ `Extracting <OffthreadVideo> frame at ${n.toFixed(3)}s from "${e}"`,
562
+ { timeoutInMilliseconds: c }
563
+ );
564
+ a.current = w;
565
+ const f = new URLSearchParams({
566
+ src: e,
567
+ time: String(n)
568
+ }), s = `${window.location.origin}/__offthread_video__?${f.toString()}`;
569
+ let d = !1;
570
+ return fetch(s).then((y) => {
571
+ if (!y.ok)
572
+ throw new Error(`OffthreadVideo: Failed to extract frame (HTTP ${y.status})`);
573
+ return y.blob();
574
+ }).then((y) => {
575
+ if (d) return;
576
+ m.current && URL.revokeObjectURL(m.current);
577
+ const v = URL.createObjectURL(y);
578
+ m.current = v, u(v);
579
+ }).catch((y) => {
580
+ console.error("OffthreadVideo frame extraction error:", y), a.current !== null && (S(a.current), a.current = null);
581
+ }), () => {
582
+ d = !0, a.current !== null && (S(a.current), a.current = null);
583
+ };
584
+ }, [n, e, c]), M(() => () => {
585
+ m.current && (URL.revokeObjectURL(m.current), m.current = null);
586
+ }, []);
587
+ const h = $(() => {
588
+ a.current !== null && (S(a.current), a.current = null);
589
+ }, []), b = $(() => {
590
+ a.current !== null && (S(a.current), a.current = null);
591
+ }, []);
592
+ return l ? /* @__PURE__ */ I(
593
+ "img",
594
+ {
595
+ src: l,
596
+ style: r,
597
+ className: i,
598
+ onLoad: h,
599
+ onError: b,
600
+ alt: ""
601
+ }
602
+ ) : null;
603
+ }
604
+ function Ie(e, n) {
509
605
  for (let t = 1; t < n.length; t++)
510
606
  if (e <= n[t]) return t - 1;
511
607
  return n.length - 2;
512
608
  }
513
- function B(e, n, t, o, r, i) {
514
- let s;
515
- return n === t ? s = 0 : s = (e - n) / (t - n), i && (s = i(s)), o + s * (r - o);
609
+ function A(e, n, t, o, r, i) {
610
+ let c;
611
+ return n === t ? c = 0 : c = (e - n) / (t - n), i && (c = i(c)), o + c * (r - o);
516
612
  }
517
- function O(e, n, t, o) {
613
+ function U(e, n, t, o) {
518
614
  if (n.length !== t.length)
519
615
  throw new Error(
520
616
  `inputRange (${n.length}) and outputRange (${t.length}) must have the same length.`
521
617
  );
522
618
  if (n.length < 2)
523
619
  throw new Error("inputRange and outputRange must have at least 2 elements.");
524
- for (let l = 1; l < n.length; l++)
525
- if (n[l] < n[l - 1])
620
+ for (let u = 1; u < n.length; u++)
621
+ if (n[u] < n[u - 1])
526
622
  throw new Error("inputRange must be monotonically non-decreasing.");
527
623
  const {
528
624
  easing: r,
529
625
  extrapolateLeft: i = "extend",
530
- extrapolateRight: s = "extend"
626
+ extrapolateRight: c = "extend"
531
627
  } = o ?? {};
532
628
  if (e < n[0])
533
- return i === "clamp" ? t[0] : i === "identity" ? e : B(
629
+ return i === "clamp" ? t[0] : i === "identity" ? e : A(
534
630
  e,
535
631
  n[0],
536
632
  n[1],
@@ -539,123 +635,123 @@ function O(e, n, t, o) {
539
635
  r
540
636
  );
541
637
  if (e > n[n.length - 1]) {
542
- if (s === "clamp")
638
+ if (c === "clamp")
543
639
  return t[t.length - 1];
544
- if (s === "identity")
640
+ if (c === "identity")
545
641
  return e;
546
- const l = n.length - 1;
547
- return B(
642
+ const u = n.length - 1;
643
+ return A(
548
644
  e,
549
- n[l - 1],
550
- n[l],
551
- t[l - 1],
552
- t[l],
645
+ n[u - 1],
646
+ n[u],
647
+ t[u - 1],
648
+ t[u],
553
649
  r
554
650
  );
555
651
  }
556
- const a = be(e, n);
557
- return B(
652
+ const l = Ie(e, n);
653
+ return A(
558
654
  e,
559
- n[a],
560
- n[a + 1],
561
- t[a],
562
- t[a + 1],
655
+ n[l],
656
+ n[l + 1],
657
+ t[l],
658
+ t[l + 1],
563
659
  r
564
660
  );
565
661
  }
566
- function ve(e, n, t, o, r, i, s) {
567
- const a = -o * (e - t), l = -r * n, d = (a + l) / i, g = n + d * s;
568
- return { position: e + g * s, velocity: g };
662
+ function Ce(e, n, t, o, r, i, c) {
663
+ const l = -o * (e - t), u = -r * n, a = (l + u) / i, m = n + a * c;
664
+ return { position: e + m * c, velocity: m };
569
665
  }
570
- function Ie(e) {
666
+ function Ee(e) {
571
667
  const {
572
668
  frame: n,
573
669
  fps: t,
574
670
  config: o = {},
575
671
  from: r = 0,
576
672
  to: i = 1,
577
- durationInFrames: s,
578
- durationRestThreshold: a = 5e-3
673
+ durationInFrames: c,
674
+ durationRestThreshold: l = 5e-3
579
675
  } = e, {
580
- damping: l = 10,
581
- mass: d = 1,
582
- stiffness: g = 100,
583
- clampOvershoot: m = !1
676
+ damping: u = 10,
677
+ mass: a = 1,
678
+ stiffness: m = 100,
679
+ clampOvershoot: h = !1
584
680
  } = o;
585
681
  if (n < 0) return r;
586
- if (s !== void 0 && n >= s)
682
+ if (c !== void 0 && n >= c)
587
683
  return i;
588
- const b = 1 / t, y = 4, u = b / y;
589
- let c = r, f = 0;
590
- for (let w = 0; w < n; w++) {
591
- for (let v = 0; v < y; v++) {
592
- const M = ve(c, f, i, g, l, d, u);
593
- c = M.position, f = M.velocity;
684
+ const b = 1 / t, w = 4, f = b / w;
685
+ let s = r, d = 0;
686
+ for (let y = 0; y < n; y++) {
687
+ for (let v = 0; v < w; v++) {
688
+ const _ = Ce(s, d, i, m, u, a, f);
689
+ s = _.position, d = _.velocity;
594
690
  }
595
- if (m && (r < i ? c = Math.min(c, i) : c = Math.max(c, i), c === i && (f = 0)), Math.abs(c - i) < a && Math.abs(f) < a)
691
+ if (h && (r < i ? s = Math.min(s, i) : s = Math.max(s, i), s === i && (d = 0)), Math.abs(s - i) < l && Math.abs(d) < l)
596
692
  return i;
597
693
  }
598
- return c;
694
+ return s;
599
695
  }
600
- function qe(e) {
696
+ function Ve(e) {
601
697
  const {
602
698
  fps: n,
603
699
  config: t,
604
700
  from: o = 0,
605
701
  to: r = 1,
606
702
  threshold: i = 5e-3
607
- } = e, s = n * 60;
608
- for (let a = 0; a < s; a++) {
609
- const l = Ie({
610
- frame: a,
703
+ } = e, c = n * 60;
704
+ for (let l = 0; l < c; l++) {
705
+ const u = Ee({
706
+ frame: l,
611
707
  fps: n,
612
708
  config: t,
613
709
  from: o,
614
710
  to: r,
615
711
  durationRestThreshold: i
616
712
  });
617
- if (Math.abs(l - r) < i)
618
- return a;
713
+ if (Math.abs(u - r) < i)
714
+ return l;
619
715
  }
620
- return s;
716
+ return c;
621
717
  }
622
- function L(e, n, t, o) {
623
- const r = 3 * e, i = 3 * (t - e) - r, s = 1 - r - i, a = 3 * n, l = 3 * (o - n) - a, d = 1 - a - l;
624
- function g(u) {
625
- return ((s * u + i) * u + r) * u;
718
+ function q(e, n, t, o) {
719
+ const r = 3 * e, i = 3 * (t - e) - r, c = 1 - r - i, l = 3 * n, u = 3 * (o - n) - l, a = 1 - l - u;
720
+ function m(f) {
721
+ return ((c * f + i) * f + r) * f;
626
722
  }
627
- function m(u) {
628
- return ((d * u + l) * u + a) * u;
723
+ function h(f) {
724
+ return ((a * f + u) * f + l) * f;
629
725
  }
630
- function b(u) {
631
- return (3 * s * u + 2 * i) * u + r;
726
+ function b(f) {
727
+ return (3 * c * f + 2 * i) * f + r;
632
728
  }
633
- function y(u) {
634
- let c = u;
729
+ function w(f) {
730
+ let s = f;
635
731
  for (let v = 0; v < 8; v++) {
636
- const M = g(c) - u;
637
- if (Math.abs(M) < 1e-7) return c;
638
- const I = b(c);
639
- if (Math.abs(I) < 1e-7) break;
640
- c -= M / I;
732
+ const _ = m(s) - f;
733
+ if (Math.abs(_) < 1e-7) return s;
734
+ const C = b(s);
735
+ if (Math.abs(C) < 1e-7) break;
736
+ s -= _ / C;
641
737
  }
642
- let f = 0, w = 1;
643
- for (c = u; f < w; ) {
644
- const v = g(c);
645
- if (Math.abs(v - u) < 1e-7) return c;
646
- u > v ? f = c : w = c, c = (f + w) / 2;
738
+ let d = 0, y = 1;
739
+ for (s = f; d < y; ) {
740
+ const v = m(s);
741
+ if (Math.abs(v - f) < 1e-7) return s;
742
+ f > v ? d = s : y = s, s = (d + y) / 2;
647
743
  }
648
- return c;
744
+ return s;
649
745
  }
650
- return (u) => u <= 0 ? 0 : u >= 1 ? 1 : m(y(u));
746
+ return (f) => f <= 0 ? 0 : f >= 1 ? 1 : h(w(f));
651
747
  }
652
748
  const ke = {
653
749
  linear: ((e) => e),
654
- ease: L(0.25, 0.1, 0.25, 1),
655
- easeIn: L(0.42, 0, 1, 1),
656
- easeOut: L(0, 0, 0.58, 1),
657
- easeInOut: L(0.42, 0, 0.58, 1),
658
- bezier: L,
750
+ ease: q(0.25, 0.1, 0.25, 1),
751
+ easeIn: q(0.42, 0, 1, 1),
752
+ easeOut: q(0, 0, 0.58, 1),
753
+ easeInOut: q(0.42, 0, 0.58, 1),
754
+ bezier: q,
659
755
  bounce: ((e) => e < 1 / 2.75 ? 7.5625 * e * e : e < 2 / 2.75 ? 7.5625 * (e -= 1.5 / 2.75) * e + 0.75 : e < 2.5 / 2.75 ? 7.5625 * (e -= 2.25 / 2.75) * e + 0.9375 : 7.5625 * (e -= 2.625 / 2.75) * e + 0.984375),
660
756
  elastic: (e = 1) => {
661
757
  const n = 0.3 / Math.max(e, 1e-3);
@@ -705,7 +801,7 @@ const Z = {
705
801
  grey: "#808080",
706
802
  transparent: "rgba(0,0,0,0)"
707
803
  };
708
- function Ce(e) {
804
+ function Se(e) {
709
805
  const n = e.trim().toLowerCase();
710
806
  if (Z[n]) {
711
807
  const t = Z[n];
@@ -717,65 +813,65 @@ function Ce(e) {
717
813
  return Q(n);
718
814
  throw new Error(`Unsupported color format: ${e}`);
719
815
  }
720
- function Ee(e) {
816
+ function Me(e) {
721
817
  const [n, t, o, r] = e;
722
818
  return r === 1 ? `rgb(${Math.round(n)}, ${Math.round(t)}, ${Math.round(o)})` : `rgba(${Math.round(n)}, ${Math.round(t)}, ${Math.round(o)}, ${Number(r.toFixed(3))})`;
723
819
  }
724
- function Ve(e, n, t, o) {
820
+ function qe(e, n, t, o) {
725
821
  if (n.length !== t.length)
726
822
  throw new Error("inputRange and outputRange must have the same length.");
727
- const r = t.map(Ce), i = O(
823
+ const r = t.map(Se), i = U(
728
824
  e,
729
825
  n,
730
- r.map((d) => d[0]),
826
+ r.map((a) => a[0]),
731
827
  o
732
- ), s = O(
828
+ ), c = U(
733
829
  e,
734
830
  n,
735
- r.map((d) => d[1]),
831
+ r.map((a) => a[1]),
736
832
  o
737
- ), a = O(
833
+ ), l = U(
738
834
  e,
739
835
  n,
740
- r.map((d) => d[2]),
836
+ r.map((a) => a[2]),
741
837
  o
742
- ), l = O(
838
+ ), u = U(
743
839
  e,
744
840
  n,
745
- r.map((d) => d[3]),
841
+ r.map((a) => a[3]),
746
842
  o
747
843
  );
748
- return Ee([
844
+ return Me([
749
845
  Math.max(0, Math.min(255, i)),
750
- Math.max(0, Math.min(255, s)),
751
- Math.max(0, Math.min(255, a)),
752
- Math.max(0, Math.min(1, l))
846
+ Math.max(0, Math.min(255, c)),
847
+ Math.max(0, Math.min(255, l)),
848
+ Math.max(0, Math.min(1, u))
753
849
  ]);
754
850
  }
755
- let W = null;
756
- function Le(e) {
757
- if (W !== null)
851
+ let B = null;
852
+ function De(e) {
853
+ if (B !== null)
758
854
  throw new Error("setRootComponent() can only be called once.");
759
- W = e;
855
+ B = e;
760
856
  }
761
- function De() {
762
- return W;
857
+ function Ue() {
858
+ return B;
763
859
  }
764
- function Oe(e) {
860
+ function He(e) {
765
861
  return `/${e.startsWith("/") ? e.slice(1) : e}`;
766
862
  }
767
- function He() {
863
+ function je() {
768
864
  return typeof window < "u" && window.__RENDIV_INPUT_PROPS__ ? window.__RENDIV_INPUT_PROPS__ : {};
769
865
  }
770
- function Ae() {
771
- const { environment: e } = p(Y);
866
+ function ze() {
867
+ const { environment: e } = p(z);
772
868
  return {
773
869
  isStudio: e === "studio",
774
870
  isRendering: e === "rendering",
775
871
  isPlayer: e === "player"
776
872
  };
777
873
  }
778
- function ze() {
874
+ function Xe() {
779
875
  if (typeof window < "u") {
780
876
  const e = window.__RENDIV_ENVIRONMENT__;
781
877
  return {
@@ -786,44 +882,45 @@ function ze() {
786
882
  }
787
883
  return { isStudio: !1, isRendering: !1, isPlayer: !1 };
788
884
  }
789
- const Xe = P(null);
885
+ const Ae = O(null);
790
886
  export {
791
887
  ye as AnimatedImage,
792
888
  pe as Audio,
793
- Fe as Composition,
794
- z as CompositionContext,
795
- ee as CompositionManagerContext,
889
+ xe as Composition,
890
+ D as CompositionContext,
891
+ ne as CompositionManagerContext,
796
892
  ke as Easing,
797
- U as Fill,
798
- ue as Folder,
799
- A as FolderContext,
800
- de as Freeze,
893
+ W as Fill,
894
+ fe as Folder,
895
+ j as FolderContext,
896
+ me as Freeze,
801
897
  we as IFrame,
802
- he as Img,
803
- fe as Loop,
804
- Y as RendivEnvironmentContext,
805
- ne as Sequence,
806
- R as SequenceContext,
807
- Re as Series,
808
- xe as Still,
809
- x as TimelineContext,
810
- Xe as TimelineRegistryContext,
811
- ge as Video,
812
- Te as abortRender,
813
- Ve as blendColors,
814
- He as getInputProps,
815
- $e as getPendingHoldCount,
816
- Pe as getPendingHoldLabels,
817
- ze as getRendivEnvironment,
818
- De as getRootComponent,
819
- qe as getSpringDuration,
820
- D as holdRender,
821
- O as interpolate,
822
- _ as releaseRender,
823
- Le as setRootComponent,
824
- Ie as spring,
825
- Oe as staticFile,
826
- _e as useCompositionConfig,
827
- Ne as useFrame,
828
- Ae as useRendivEnvironment
898
+ ge as Img,
899
+ de as Loop,
900
+ be as OffthreadVideo,
901
+ z as RendivEnvironmentContext,
902
+ te as Sequence,
903
+ x as SequenceContext,
904
+ Pe as Series,
905
+ $e as Still,
906
+ F as TimelineContext,
907
+ Ae as TimelineRegistryContext,
908
+ oe as Video,
909
+ Le as abortRender,
910
+ qe as blendColors,
911
+ je as getInputProps,
912
+ Oe as getPendingHoldCount,
913
+ Te as getPendingHoldLabels,
914
+ Xe as getRendivEnvironment,
915
+ Ue as getRootComponent,
916
+ Ve as getSpringDuration,
917
+ k as holdRender,
918
+ U as interpolate,
919
+ S as releaseRender,
920
+ De as setRootComponent,
921
+ Ee as spring,
922
+ He as staticFile,
923
+ Fe as useCompositionConfig,
924
+ Re as useFrame,
925
+ ze as useRendivEnvironment
829
926
  };