@rendiv/core 0.1.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/dist/__tests__/animated-image.test.d.ts +2 -0
- package/dist/__tests__/animated-image.test.d.ts.map +1 -0
- package/dist/__tests__/audio.test.d.ts +2 -0
- package/dist/__tests__/audio.test.d.ts.map +1 -0
- package/dist/__tests__/delay-render.test.d.ts +2 -0
- package/dist/__tests__/delay-render.test.d.ts.map +1 -0
- package/dist/__tests__/freeze.test.d.ts +2 -0
- package/dist/__tests__/freeze.test.d.ts.map +1 -0
- package/dist/__tests__/iframe.test.d.ts +2 -0
- package/dist/__tests__/iframe.test.d.ts.map +1 -0
- package/dist/__tests__/img.test.d.ts +2 -0
- package/dist/__tests__/img.test.d.ts.map +1 -0
- package/dist/__tests__/interpolate.test.d.ts +2 -0
- package/dist/__tests__/interpolate.test.d.ts.map +1 -0
- package/dist/__tests__/loop.test.d.ts +2 -0
- package/dist/__tests__/loop.test.d.ts.map +1 -0
- package/dist/__tests__/sequence.test.d.ts +2 -0
- package/dist/__tests__/sequence.test.d.ts.map +1 -0
- package/dist/__tests__/series.test.d.ts +2 -0
- package/dist/__tests__/series.test.d.ts.map +1 -0
- package/dist/__tests__/spring.test.d.ts +2 -0
- package/dist/__tests__/spring.test.d.ts.map +1 -0
- package/dist/__tests__/video.test.d.ts +2 -0
- package/dist/__tests__/video.test.d.ts.map +1 -0
- package/dist/animation/easing.d.ts +17 -0
- package/dist/animation/easing.d.ts.map +1 -0
- package/dist/animation/interpolate-colors.d.ts +3 -0
- package/dist/animation/interpolate-colors.d.ts.map +1 -0
- package/dist/animation/interpolate.d.ts +9 -0
- package/dist/animation/interpolate.d.ts.map +1 -0
- package/dist/animation/measure-spring.d.ts +10 -0
- package/dist/animation/measure-spring.d.ts.map +1 -0
- package/dist/animation/spring.d.ts +17 -0
- package/dist/animation/spring.d.ts.map +1 -0
- package/dist/components/AnimatedImage.d.ts +15 -0
- package/dist/components/AnimatedImage.d.ts.map +1 -0
- package/dist/components/Audio.d.ts +18 -0
- package/dist/components/Audio.d.ts.map +1 -0
- package/dist/components/Composition.d.ts +14 -0
- package/dist/components/Composition.d.ts.map +1 -0
- package/dist/components/Fill.d.ts +3 -0
- package/dist/components/Fill.d.ts.map +1 -0
- package/dist/components/Folder.d.ts +7 -0
- package/dist/components/Folder.d.ts.map +1 -0
- package/dist/components/Freeze.d.ts +10 -0
- package/dist/components/Freeze.d.ts.map +1 -0
- package/dist/components/IFrame.d.ts +10 -0
- package/dist/components/IFrame.d.ts.map +1 -0
- package/dist/components/Img.d.ts +10 -0
- package/dist/components/Img.d.ts.map +1 -0
- package/dist/components/Loop.d.ts +13 -0
- package/dist/components/Loop.d.ts.map +1 -0
- package/dist/components/Sequence.d.ts +11 -0
- package/dist/components/Sequence.d.ts.map +1 -0
- package/dist/components/Series.d.ts +27 -0
- package/dist/components/Series.d.ts.map +1 -0
- package/dist/components/Still.d.ts +10 -0
- package/dist/components/Still.d.ts.map +1 -0
- package/dist/components/Video.d.ts +22 -0
- package/dist/components/Video.d.ts.map +1 -0
- package/dist/context/CompositionContext.d.ts +10 -0
- package/dist/context/CompositionContext.d.ts.map +1 -0
- package/dist/context/CompositionManagerContext.d.ts +34 -0
- package/dist/context/CompositionManagerContext.d.ts.map +1 -0
- package/dist/context/FolderContext.d.ts +2 -0
- package/dist/context/FolderContext.d.ts.map +1 -0
- package/dist/context/RendivEnvironmentContext.d.ts +6 -0
- package/dist/context/RendivEnvironmentContext.d.ts.map +1 -0
- package/dist/context/SequenceContext.d.ts +10 -0
- package/dist/context/SequenceContext.d.ts.map +1 -0
- package/dist/context/TimelineContext.d.ts +8 -0
- package/dist/context/TimelineContext.d.ts.map +1 -0
- package/dist/context/TimelineRegistryContext.d.ts +17 -0
- package/dist/context/TimelineRegistryContext.d.ts.map +1 -0
- package/dist/delay-render.d.ts +11 -0
- package/dist/delay-render.d.ts.map +1 -0
- package/dist/get-input-props.d.ts +7 -0
- package/dist/get-input-props.d.ts.map +1 -0
- package/dist/get-rendiv-environment.d.ts +11 -0
- package/dist/get-rendiv-environment.d.ts.map +1 -0
- package/dist/hooks/use-composition-config.d.ts +3 -0
- package/dist/hooks/use-composition-config.d.ts.map +1 -0
- package/dist/hooks/use-frame.d.ts +2 -0
- package/dist/hooks/use-frame.d.ts.map +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +829 -0
- package/dist/register-root.d.ts +4 -0
- package/dist/register-root.d.ts.map +1 -0
- package/dist/static-file.d.ts +2 -0
- package/dist/static-file.d.ts.map +1 -0
- package/package.json +42 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,829 @@
|
|
|
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({
|
|
4
|
+
frame: 0,
|
|
5
|
+
playing: !1,
|
|
6
|
+
playingRef: { current: !1 }
|
|
7
|
+
}), R = P({
|
|
8
|
+
id: null,
|
|
9
|
+
from: 0,
|
|
10
|
+
durationInFrames: 1 / 0,
|
|
11
|
+
parentOffset: 0,
|
|
12
|
+
accumulatedOffset: 0,
|
|
13
|
+
localOffset: 0
|
|
14
|
+
});
|
|
15
|
+
function Ne() {
|
|
16
|
+
const e = p(x), n = p(R);
|
|
17
|
+
return e.frame - n.accumulatedOffset;
|
|
18
|
+
}
|
|
19
|
+
const z = P(null);
|
|
20
|
+
function _e() {
|
|
21
|
+
const e = p(z);
|
|
22
|
+
if (!e)
|
|
23
|
+
throw new Error(
|
|
24
|
+
"useCompositionConfig() must be called inside a <Composition>, <Player>, or during rendering."
|
|
25
|
+
);
|
|
26
|
+
return e;
|
|
27
|
+
}
|
|
28
|
+
const X = () => {
|
|
29
|
+
}, ee = P({
|
|
30
|
+
compositions: [],
|
|
31
|
+
registerComposition: X,
|
|
32
|
+
unregisterComposition: X,
|
|
33
|
+
currentCompositionId: null,
|
|
34
|
+
setCurrentCompositionId: X,
|
|
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({
|
|
40
|
+
id: e.id,
|
|
41
|
+
component: e.component,
|
|
42
|
+
durationInFrames: e.durationInFrames,
|
|
43
|
+
fps: e.fps,
|
|
44
|
+
width: e.width,
|
|
45
|
+
height: e.height,
|
|
46
|
+
defaultProps: e.defaultProps ?? {},
|
|
47
|
+
group: o,
|
|
48
|
+
resolveConfig: e.resolveConfig,
|
|
49
|
+
type: "composition"
|
|
50
|
+
}), () => t(e.id)), [e.id]), null;
|
|
51
|
+
}
|
|
52
|
+
const le = {
|
|
53
|
+
position: "absolute",
|
|
54
|
+
top: 0,
|
|
55
|
+
left: 0,
|
|
56
|
+
right: 0,
|
|
57
|
+
bottom: 0,
|
|
58
|
+
width: "100%",
|
|
59
|
+
height: "100%",
|
|
60
|
+
display: "flex",
|
|
61
|
+
flexDirection: "column"
|
|
62
|
+
}, U = ie(
|
|
63
|
+
({ style: e, ...n }, t) => /* @__PURE__ */ E(
|
|
64
|
+
"div",
|
|
65
|
+
{
|
|
66
|
+
ref: t,
|
|
67
|
+
style: { ...le, ...e },
|
|
68
|
+
...n
|
|
69
|
+
}
|
|
70
|
+
)
|
|
71
|
+
);
|
|
72
|
+
U.displayName = "Fill";
|
|
73
|
+
const ne = ({
|
|
74
|
+
from: e = 0,
|
|
75
|
+
durationInFrames: n = 1 / 0,
|
|
76
|
+
name: t,
|
|
77
|
+
layout: o = "absolute-fill",
|
|
78
|
+
style: r,
|
|
79
|
+
children: i
|
|
80
|
+
}) => {
|
|
81
|
+
const s = p(R), a = p(x), l = se(), d = s.accumulatedOffset + e, g = a.frame;
|
|
82
|
+
N(() => {
|
|
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"));
|
|
89
|
+
};
|
|
90
|
+
}, [l, t, d, n]);
|
|
91
|
+
const m = H(
|
|
92
|
+
() => ({
|
|
93
|
+
id: l,
|
|
94
|
+
from: d,
|
|
95
|
+
durationInFrames: n,
|
|
96
|
+
parentOffset: s.accumulatedOffset,
|
|
97
|
+
accumulatedOffset: d,
|
|
98
|
+
localOffset: e
|
|
99
|
+
}),
|
|
100
|
+
[l, d, n, s.accumulatedOffset, e]
|
|
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 });
|
|
105
|
+
};
|
|
106
|
+
ne.displayName = "Sequence";
|
|
107
|
+
function xe(e) {
|
|
108
|
+
const { registerComposition: n, unregisterComposition: t } = p(ee), o = p(A);
|
|
109
|
+
return N(() => (n({
|
|
110
|
+
id: e.id,
|
|
111
|
+
component: e.component,
|
|
112
|
+
durationInFrames: 1,
|
|
113
|
+
fps: 30,
|
|
114
|
+
width: e.width,
|
|
115
|
+
height: e.height,
|
|
116
|
+
defaultProps: e.defaultProps ?? {},
|
|
117
|
+
group: o,
|
|
118
|
+
type: "still"
|
|
119
|
+
}), () => t(e.id)), [e.id]), null;
|
|
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 });
|
|
124
|
+
};
|
|
125
|
+
ue.displayName = "Folder";
|
|
126
|
+
function j(e) {
|
|
127
|
+
throw new Error(
|
|
128
|
+
"<Series.Sequence> can only be used as a direct child of <Series>."
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
j.displayName = "Series.Sequence";
|
|
132
|
+
function te({ children: e }) {
|
|
133
|
+
const n = J.toArray(e);
|
|
134
|
+
let t = 0;
|
|
135
|
+
const o = [];
|
|
136
|
+
for (const r of n) {
|
|
137
|
+
if (!G.isValidElement(r)) continue;
|
|
138
|
+
if (r.type !== j)
|
|
139
|
+
throw new Error(
|
|
140
|
+
"Only <Series.Sequence> elements are allowed as children of <Series>."
|
|
141
|
+
);
|
|
142
|
+
const {
|
|
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;
|
|
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;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
o.push(
|
|
162
|
+
/* @__PURE__ */ E(
|
|
163
|
+
ne,
|
|
164
|
+
{
|
|
165
|
+
from: m,
|
|
166
|
+
durationInFrames: i,
|
|
167
|
+
name: b,
|
|
168
|
+
layout: l,
|
|
169
|
+
style: d,
|
|
170
|
+
children: g
|
|
171
|
+
},
|
|
172
|
+
r.key ?? o.length
|
|
173
|
+
)
|
|
174
|
+
), t = m + i;
|
|
175
|
+
}
|
|
176
|
+
return /* @__PURE__ */ E(ce, { children: o });
|
|
177
|
+
}
|
|
178
|
+
te.displayName = "Series";
|
|
179
|
+
const Re = Object.assign(te, {
|
|
180
|
+
Sequence: j
|
|
181
|
+
});
|
|
182
|
+
function fe({
|
|
183
|
+
durationInFrames: e,
|
|
184
|
+
times: n = 1 / 0,
|
|
185
|
+
layout: t = "absolute-fill",
|
|
186
|
+
style: o,
|
|
187
|
+
children: r
|
|
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(
|
|
192
|
+
() => ({
|
|
193
|
+
frame: l + s.accumulatedOffset,
|
|
194
|
+
playing: i.playing,
|
|
195
|
+
playingRef: i.playingRef
|
|
196
|
+
}),
|
|
197
|
+
[l, s.accumulatedOffset, i.playing, i.playingRef]
|
|
198
|
+
), g = H(
|
|
199
|
+
() => ({
|
|
200
|
+
id: null,
|
|
201
|
+
from: s.accumulatedOffset,
|
|
202
|
+
durationInFrames: e,
|
|
203
|
+
parentOffset: s.accumulatedOffset,
|
|
204
|
+
accumulatedOffset: s.accumulatedOffset,
|
|
205
|
+
localOffset: 0
|
|
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 });
|
|
210
|
+
}
|
|
211
|
+
fe.displayName = "Loop";
|
|
212
|
+
function de({ frame: e, children: n }) {
|
|
213
|
+
const t = p(x), o = H(
|
|
214
|
+
() => ({
|
|
215
|
+
frame: e,
|
|
216
|
+
playing: t.playing,
|
|
217
|
+
playingRef: t.playingRef
|
|
218
|
+
}),
|
|
219
|
+
[e, t.playing, t.playingRef]
|
|
220
|
+
);
|
|
221
|
+
return /* @__PURE__ */ E(x.Provider, { value: o, children: n });
|
|
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 ?? {};
|
|
228
|
+
let i = null;
|
|
229
|
+
return r !== void 0 && r > 0 && (i = setTimeout(() => {
|
|
230
|
+
if ($.has(t))
|
|
231
|
+
throw $.delete(t), new Error(
|
|
232
|
+
`holdRender() timed out after ${r}ms (label: "${o}"). You can increase the timeout by passing a larger timeoutInMilliseconds to holdRender().`
|
|
233
|
+
);
|
|
234
|
+
}, r)), $.set(t, { label: o, timeoutId: i }), t;
|
|
235
|
+
}
|
|
236
|
+
function _(e) {
|
|
237
|
+
const n = $.get(e);
|
|
238
|
+
if (!n)
|
|
239
|
+
throw new Error(
|
|
240
|
+
`releaseRender() was called with handle ${e}, but no corresponding holdRender() exists.`
|
|
241
|
+
);
|
|
242
|
+
n.timeoutId !== null && clearTimeout(n.timeoutId), $.delete(e);
|
|
243
|
+
}
|
|
244
|
+
function Te(e) {
|
|
245
|
+
throw new Error(`Render cancelled: ${e}`);
|
|
246
|
+
}
|
|
247
|
+
function $e() {
|
|
248
|
+
return $.size;
|
|
249
|
+
}
|
|
250
|
+
function Pe() {
|
|
251
|
+
return Array.from($.values()).map((e) => e.label);
|
|
252
|
+
}
|
|
253
|
+
function he({
|
|
254
|
+
holdRenderTimeout: e = 3e4,
|
|
255
|
+
onLoad: n,
|
|
256
|
+
onError: t,
|
|
257
|
+
...o
|
|
258
|
+
}) {
|
|
259
|
+
const r = F(null);
|
|
260
|
+
N(() => {
|
|
261
|
+
const a = D(
|
|
262
|
+
`Loading <Img> with src="${o.src}"`,
|
|
263
|
+
{ timeoutInMilliseconds: e }
|
|
264
|
+
);
|
|
265
|
+
return r.current = a, () => {
|
|
266
|
+
r.current !== null && (_(r.current), r.current = null);
|
|
267
|
+
};
|
|
268
|
+
}, [o.src, e]);
|
|
269
|
+
const i = V(
|
|
270
|
+
(a) => {
|
|
271
|
+
r.current !== null && (_(r.current), r.current = null), n == null || n(a);
|
|
272
|
+
},
|
|
273
|
+
[n]
|
|
274
|
+
), s = V(
|
|
275
|
+
(a) => {
|
|
276
|
+
r.current !== null && (_(r.current), r.current = null), t == null || t(a);
|
|
277
|
+
},
|
|
278
|
+
[t]
|
|
279
|
+
);
|
|
280
|
+
return /* @__PURE__ */ E(
|
|
281
|
+
"img",
|
|
282
|
+
{
|
|
283
|
+
...o,
|
|
284
|
+
onLoad: i,
|
|
285
|
+
onError: s
|
|
286
|
+
}
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
he.displayName = "Img";
|
|
290
|
+
const Y = P({
|
|
291
|
+
environment: "studio"
|
|
292
|
+
});
|
|
293
|
+
function ge({
|
|
294
|
+
src: e,
|
|
295
|
+
startFrom: n = 0,
|
|
296
|
+
endAt: t,
|
|
297
|
+
volume: o = 1,
|
|
298
|
+
playbackRate: r = 1,
|
|
299
|
+
muted: i = !1,
|
|
300
|
+
style: s,
|
|
301
|
+
className: a,
|
|
302
|
+
holdRenderTimeout: l = 3e4,
|
|
303
|
+
...d
|
|
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(
|
|
308
|
+
`Loading <Video> metadata for src="${e}"`,
|
|
309
|
+
{ timeoutInMilliseconds: l }
|
|
310
|
+
);
|
|
311
|
+
return c.current = h, () => {
|
|
312
|
+
c.current !== null && (_(c.current), c.current = null);
|
|
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);
|
|
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();
|
|
331
|
+
return;
|
|
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);
|
|
341
|
+
};
|
|
342
|
+
h.addEventListener("seeked", k), h.currentTime = C;
|
|
343
|
+
}
|
|
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();
|
|
347
|
+
}
|
|
348
|
+
}, [M, w, C, m.playing, t, I, l]), /* @__PURE__ */ E(
|
|
349
|
+
"video",
|
|
350
|
+
{
|
|
351
|
+
ref: g,
|
|
352
|
+
src: e,
|
|
353
|
+
preload: "auto",
|
|
354
|
+
playsInline: !0,
|
|
355
|
+
style: s,
|
|
356
|
+
className: a,
|
|
357
|
+
onLoadedMetadata: T,
|
|
358
|
+
onError: q,
|
|
359
|
+
...d
|
|
360
|
+
}
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
ge.displayName = "Video";
|
|
364
|
+
function pe({
|
|
365
|
+
src: e,
|
|
366
|
+
startFrom: n = 0,
|
|
367
|
+
endAt: t,
|
|
368
|
+
volume: o = 1,
|
|
369
|
+
playbackRate: r = 1,
|
|
370
|
+
muted: i = !1
|
|
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();
|
|
379
|
+
return;
|
|
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(
|
|
384
|
+
"audio",
|
|
385
|
+
{
|
|
386
|
+
ref: s,
|
|
387
|
+
src: e,
|
|
388
|
+
preload: "auto"
|
|
389
|
+
}
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
pe.displayName = "Audio";
|
|
393
|
+
function ye({
|
|
394
|
+
src: e,
|
|
395
|
+
width: n,
|
|
396
|
+
height: t,
|
|
397
|
+
style: o,
|
|
398
|
+
className: r,
|
|
399
|
+
holdRenderTimeout: i = 3e4
|
|
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(
|
|
404
|
+
`Loading <AnimatedImage> frames from "${e}"`,
|
|
405
|
+
{ timeoutInMilliseconds: i }
|
|
406
|
+
);
|
|
407
|
+
m.current = f;
|
|
408
|
+
let w = !1;
|
|
409
|
+
async function v() {
|
|
410
|
+
try {
|
|
411
|
+
const I = await (await fetch(e)).blob();
|
|
412
|
+
if (typeof ImageDecoder < "u") {
|
|
413
|
+
const C = new ImageDecoder({
|
|
414
|
+
data: await I.arrayBuffer(),
|
|
415
|
+
type: I.type
|
|
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();
|
|
424
|
+
}
|
|
425
|
+
C.close(), w || (g.current = h, y(!0));
|
|
426
|
+
} else {
|
|
427
|
+
const C = await createImageBitmap(I);
|
|
428
|
+
w || (g.current = [{ image: C, duration: 1 / 0 }], y(!0));
|
|
429
|
+
}
|
|
430
|
+
} catch (M) {
|
|
431
|
+
console.error("AnimatedImage: failed to decode frames", M);
|
|
432
|
+
} finally {
|
|
433
|
+
m.current !== null && (_(m.current), m.current = null);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
return v(), () => {
|
|
437
|
+
w = !0, m.current !== null && (_(m.current), m.current = null);
|
|
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;
|
|
455
|
+
break;
|
|
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(
|
|
460
|
+
"canvas",
|
|
461
|
+
{
|
|
462
|
+
ref: s,
|
|
463
|
+
width: n,
|
|
464
|
+
height: t,
|
|
465
|
+
style: o,
|
|
466
|
+
className: r
|
|
467
|
+
}
|
|
468
|
+
);
|
|
469
|
+
}
|
|
470
|
+
ye.displayName = "AnimatedImage";
|
|
471
|
+
function we({
|
|
472
|
+
holdRenderTimeout: e = 3e4,
|
|
473
|
+
onLoad: n,
|
|
474
|
+
onError: t,
|
|
475
|
+
...o
|
|
476
|
+
}) {
|
|
477
|
+
const r = F(null);
|
|
478
|
+
N(() => {
|
|
479
|
+
const a = D(
|
|
480
|
+
`Loading <IFrame> with src="${o.src}"`,
|
|
481
|
+
{ timeoutInMilliseconds: e }
|
|
482
|
+
);
|
|
483
|
+
return r.current = a, () => {
|
|
484
|
+
r.current !== null && (_(r.current), r.current = null);
|
|
485
|
+
};
|
|
486
|
+
}, [o.src, e]);
|
|
487
|
+
const i = V(
|
|
488
|
+
(a) => {
|
|
489
|
+
r.current !== null && (_(r.current), r.current = null), n == null || n(a);
|
|
490
|
+
},
|
|
491
|
+
[n]
|
|
492
|
+
), s = V(
|
|
493
|
+
(a) => {
|
|
494
|
+
r.current !== null && (_(r.current), r.current = null), t == null || t(a);
|
|
495
|
+
},
|
|
496
|
+
[t]
|
|
497
|
+
);
|
|
498
|
+
return /* @__PURE__ */ E(
|
|
499
|
+
"iframe",
|
|
500
|
+
{
|
|
501
|
+
...o,
|
|
502
|
+
onLoad: i,
|
|
503
|
+
onError: s
|
|
504
|
+
}
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
we.displayName = "IFrame";
|
|
508
|
+
function be(e, n) {
|
|
509
|
+
for (let t = 1; t < n.length; t++)
|
|
510
|
+
if (e <= n[t]) return t - 1;
|
|
511
|
+
return n.length - 2;
|
|
512
|
+
}
|
|
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);
|
|
516
|
+
}
|
|
517
|
+
function O(e, n, t, o) {
|
|
518
|
+
if (n.length !== t.length)
|
|
519
|
+
throw new Error(
|
|
520
|
+
`inputRange (${n.length}) and outputRange (${t.length}) must have the same length.`
|
|
521
|
+
);
|
|
522
|
+
if (n.length < 2)
|
|
523
|
+
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])
|
|
526
|
+
throw new Error("inputRange must be monotonically non-decreasing.");
|
|
527
|
+
const {
|
|
528
|
+
easing: r,
|
|
529
|
+
extrapolateLeft: i = "extend",
|
|
530
|
+
extrapolateRight: s = "extend"
|
|
531
|
+
} = o ?? {};
|
|
532
|
+
if (e < n[0])
|
|
533
|
+
return i === "clamp" ? t[0] : i === "identity" ? e : B(
|
|
534
|
+
e,
|
|
535
|
+
n[0],
|
|
536
|
+
n[1],
|
|
537
|
+
t[0],
|
|
538
|
+
t[1],
|
|
539
|
+
r
|
|
540
|
+
);
|
|
541
|
+
if (e > n[n.length - 1]) {
|
|
542
|
+
if (s === "clamp")
|
|
543
|
+
return t[t.length - 1];
|
|
544
|
+
if (s === "identity")
|
|
545
|
+
return e;
|
|
546
|
+
const l = n.length - 1;
|
|
547
|
+
return B(
|
|
548
|
+
e,
|
|
549
|
+
n[l - 1],
|
|
550
|
+
n[l],
|
|
551
|
+
t[l - 1],
|
|
552
|
+
t[l],
|
|
553
|
+
r
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
const a = be(e, n);
|
|
557
|
+
return B(
|
|
558
|
+
e,
|
|
559
|
+
n[a],
|
|
560
|
+
n[a + 1],
|
|
561
|
+
t[a],
|
|
562
|
+
t[a + 1],
|
|
563
|
+
r
|
|
564
|
+
);
|
|
565
|
+
}
|
|
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 };
|
|
569
|
+
}
|
|
570
|
+
function Ie(e) {
|
|
571
|
+
const {
|
|
572
|
+
frame: n,
|
|
573
|
+
fps: t,
|
|
574
|
+
config: o = {},
|
|
575
|
+
from: r = 0,
|
|
576
|
+
to: i = 1,
|
|
577
|
+
durationInFrames: s,
|
|
578
|
+
durationRestThreshold: a = 5e-3
|
|
579
|
+
} = e, {
|
|
580
|
+
damping: l = 10,
|
|
581
|
+
mass: d = 1,
|
|
582
|
+
stiffness: g = 100,
|
|
583
|
+
clampOvershoot: m = !1
|
|
584
|
+
} = o;
|
|
585
|
+
if (n < 0) return r;
|
|
586
|
+
if (s !== void 0 && n >= s)
|
|
587
|
+
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;
|
|
594
|
+
}
|
|
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)
|
|
596
|
+
return i;
|
|
597
|
+
}
|
|
598
|
+
return c;
|
|
599
|
+
}
|
|
600
|
+
function qe(e) {
|
|
601
|
+
const {
|
|
602
|
+
fps: n,
|
|
603
|
+
config: t,
|
|
604
|
+
from: o = 0,
|
|
605
|
+
to: r = 1,
|
|
606
|
+
threshold: i = 5e-3
|
|
607
|
+
} = e, s = n * 60;
|
|
608
|
+
for (let a = 0; a < s; a++) {
|
|
609
|
+
const l = Ie({
|
|
610
|
+
frame: a,
|
|
611
|
+
fps: n,
|
|
612
|
+
config: t,
|
|
613
|
+
from: o,
|
|
614
|
+
to: r,
|
|
615
|
+
durationRestThreshold: i
|
|
616
|
+
});
|
|
617
|
+
if (Math.abs(l - r) < i)
|
|
618
|
+
return a;
|
|
619
|
+
}
|
|
620
|
+
return s;
|
|
621
|
+
}
|
|
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;
|
|
626
|
+
}
|
|
627
|
+
function m(u) {
|
|
628
|
+
return ((d * u + l) * u + a) * u;
|
|
629
|
+
}
|
|
630
|
+
function b(u) {
|
|
631
|
+
return (3 * s * u + 2 * i) * u + r;
|
|
632
|
+
}
|
|
633
|
+
function y(u) {
|
|
634
|
+
let c = u;
|
|
635
|
+
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;
|
|
641
|
+
}
|
|
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;
|
|
647
|
+
}
|
|
648
|
+
return c;
|
|
649
|
+
}
|
|
650
|
+
return (u) => u <= 0 ? 0 : u >= 1 ? 1 : m(y(u));
|
|
651
|
+
}
|
|
652
|
+
const ke = {
|
|
653
|
+
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,
|
|
659
|
+
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
|
+
elastic: (e = 1) => {
|
|
661
|
+
const n = 0.3 / Math.max(e, 1e-3);
|
|
662
|
+
return (t) => t <= 0 ? 0 : t >= 1 ? 1 : Math.pow(2, -10 * t) * Math.sin((t - n / 4) * (2 * Math.PI) / n) + 1;
|
|
663
|
+
},
|
|
664
|
+
in: (e) => e,
|
|
665
|
+
out: (e) => (n) => 1 - e(1 - n),
|
|
666
|
+
inOut: (e) => (n) => n < 0.5 ? e(n * 2) / 2 : 1 - e((1 - n) * 2) / 2
|
|
667
|
+
};
|
|
668
|
+
function K(e) {
|
|
669
|
+
let n = e.replace("#", "");
|
|
670
|
+
n.length === 3 && (n = n[0] + n[0] + n[1] + n[1] + n[2] + n[2]), n.length === 6 && (n += "ff");
|
|
671
|
+
const t = parseInt(n, 16);
|
|
672
|
+
return [
|
|
673
|
+
t >> 24 & 255,
|
|
674
|
+
t >> 16 & 255,
|
|
675
|
+
t >> 8 & 255,
|
|
676
|
+
(t & 255) / 255
|
|
677
|
+
];
|
|
678
|
+
}
|
|
679
|
+
function Q(e) {
|
|
680
|
+
const n = e.match(
|
|
681
|
+
/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)(?:\s*,\s*([\d.]+))?\s*\)/
|
|
682
|
+
);
|
|
683
|
+
if (n)
|
|
684
|
+
return [
|
|
685
|
+
Number(n[1]),
|
|
686
|
+
Number(n[2]),
|
|
687
|
+
Number(n[3]),
|
|
688
|
+
n[4] !== void 0 ? Number(n[4]) : 1
|
|
689
|
+
];
|
|
690
|
+
throw new Error(`Cannot parse color: ${e}`);
|
|
691
|
+
}
|
|
692
|
+
const Z = {
|
|
693
|
+
black: "#000000",
|
|
694
|
+
white: "#ffffff",
|
|
695
|
+
red: "#ff0000",
|
|
696
|
+
green: "#008000",
|
|
697
|
+
blue: "#0000ff",
|
|
698
|
+
yellow: "#ffff00",
|
|
699
|
+
cyan: "#00ffff",
|
|
700
|
+
magenta: "#ff00ff",
|
|
701
|
+
orange: "#ffa500",
|
|
702
|
+
purple: "#800080",
|
|
703
|
+
pink: "#ffc0cb",
|
|
704
|
+
gray: "#808080",
|
|
705
|
+
grey: "#808080",
|
|
706
|
+
transparent: "rgba(0,0,0,0)"
|
|
707
|
+
};
|
|
708
|
+
function Ce(e) {
|
|
709
|
+
const n = e.trim().toLowerCase();
|
|
710
|
+
if (Z[n]) {
|
|
711
|
+
const t = Z[n];
|
|
712
|
+
return t.startsWith("#") ? K(t) : Q(t);
|
|
713
|
+
}
|
|
714
|
+
if (n.startsWith("#"))
|
|
715
|
+
return K(n);
|
|
716
|
+
if (n.startsWith("rgb"))
|
|
717
|
+
return Q(n);
|
|
718
|
+
throw new Error(`Unsupported color format: ${e}`);
|
|
719
|
+
}
|
|
720
|
+
function Ee(e) {
|
|
721
|
+
const [n, t, o, r] = e;
|
|
722
|
+
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
|
+
}
|
|
724
|
+
function Ve(e, n, t, o) {
|
|
725
|
+
if (n.length !== t.length)
|
|
726
|
+
throw new Error("inputRange and outputRange must have the same length.");
|
|
727
|
+
const r = t.map(Ce), i = O(
|
|
728
|
+
e,
|
|
729
|
+
n,
|
|
730
|
+
r.map((d) => d[0]),
|
|
731
|
+
o
|
|
732
|
+
), s = O(
|
|
733
|
+
e,
|
|
734
|
+
n,
|
|
735
|
+
r.map((d) => d[1]),
|
|
736
|
+
o
|
|
737
|
+
), a = O(
|
|
738
|
+
e,
|
|
739
|
+
n,
|
|
740
|
+
r.map((d) => d[2]),
|
|
741
|
+
o
|
|
742
|
+
), l = O(
|
|
743
|
+
e,
|
|
744
|
+
n,
|
|
745
|
+
r.map((d) => d[3]),
|
|
746
|
+
o
|
|
747
|
+
);
|
|
748
|
+
return Ee([
|
|
749
|
+
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))
|
|
753
|
+
]);
|
|
754
|
+
}
|
|
755
|
+
let W = null;
|
|
756
|
+
function Le(e) {
|
|
757
|
+
if (W !== null)
|
|
758
|
+
throw new Error("setRootComponent() can only be called once.");
|
|
759
|
+
W = e;
|
|
760
|
+
}
|
|
761
|
+
function De() {
|
|
762
|
+
return W;
|
|
763
|
+
}
|
|
764
|
+
function Oe(e) {
|
|
765
|
+
return `/${e.startsWith("/") ? e.slice(1) : e}`;
|
|
766
|
+
}
|
|
767
|
+
function He() {
|
|
768
|
+
return typeof window < "u" && window.__RENDIV_INPUT_PROPS__ ? window.__RENDIV_INPUT_PROPS__ : {};
|
|
769
|
+
}
|
|
770
|
+
function Ae() {
|
|
771
|
+
const { environment: e } = p(Y);
|
|
772
|
+
return {
|
|
773
|
+
isStudio: e === "studio",
|
|
774
|
+
isRendering: e === "rendering",
|
|
775
|
+
isPlayer: e === "player"
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
function ze() {
|
|
779
|
+
if (typeof window < "u") {
|
|
780
|
+
const e = window.__RENDIV_ENVIRONMENT__;
|
|
781
|
+
return {
|
|
782
|
+
isStudio: e === "studio",
|
|
783
|
+
isRendering: e === "rendering",
|
|
784
|
+
isPlayer: e === "player"
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
return { isStudio: !1, isRendering: !1, isPlayer: !1 };
|
|
788
|
+
}
|
|
789
|
+
const Xe = P(null);
|
|
790
|
+
export {
|
|
791
|
+
ye as AnimatedImage,
|
|
792
|
+
pe as Audio,
|
|
793
|
+
Fe as Composition,
|
|
794
|
+
z as CompositionContext,
|
|
795
|
+
ee as CompositionManagerContext,
|
|
796
|
+
ke as Easing,
|
|
797
|
+
U as Fill,
|
|
798
|
+
ue as Folder,
|
|
799
|
+
A as FolderContext,
|
|
800
|
+
de as Freeze,
|
|
801
|
+
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
|
|
829
|
+
};
|