@remotion/rive 4.0.533 → 4.0.535

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.
@@ -1,37 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
4
  };
@@ -39,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
6
  exports.RemotionRiveCanvas = exports.riveCanvasSchema = void 0;
40
7
  const jsx_runtime_1 = require("react/jsx-runtime");
41
8
  const canvas_advanced_1 = __importDefault(require("@rive-app/canvas-advanced"));
42
- const react_1 = __importStar(require("react"));
9
+ const react_1 = require("react");
43
10
  const remotion_1 = require("remotion");
44
11
  const map_enums_js_1 = require("./map-enums.js");
45
12
  const { runEffectChain, useEffectChainState, useMemoizedEffectDefinitions, useMemoizedEffects, } = remotion_1.Internals;
@@ -85,13 +52,13 @@ exports.riveCanvasSchema = {
85
52
  ...remotion_1.Interactive.cropSchema,
86
53
  };
87
54
  const RemotionRiveCanvasContentForwardRefFunction = ({ src, fit, alignment, artboard: artboardName, animation: animationIndex, onLoad = null, assetLoader, enableRiveAssetCdn, className, style, effects, controls, canvasRef, }, ref) => {
88
- var _a;
55
+ var _a, _b, _c;
89
56
  const { width, fps, height } = (0, remotion_1.useVideoConfig)();
90
57
  const frame = (0, remotion_1.useCurrentFrame)();
91
- const [riveCanvasInstance, setRiveCanvas] = (0, react_1.useState)(null);
58
+ const [loadedRuntime, setLoadedRuntime] = (0, react_1.useState)(null);
59
+ const riveCanvasInstance = (_a = loadedRuntime === null || loadedRuntime === void 0 ? void 0 : loadedRuntime.instance) !== null && _a !== void 0 ? _a : null;
92
60
  const [err, setError] = (0, react_1.useState)(null);
93
61
  const { delayRender, continueRender } = (0, remotion_1.useDelayRender)();
94
- const [handle] = (0, react_1.useState)(() => delayRender());
95
62
  const lastFrame = (0, react_1.useRef)(0);
96
63
  // Rive draws to this offscreen-style canvas; the effect chain then
97
64
  // composites from here onto the visible output canvas.
@@ -104,7 +71,8 @@ const RemotionRiveCanvasContentForwardRefFunction = ({ src, fit, alignment, artb
104
71
  const chainState = useEffectChainState();
105
72
  const memoizedEffects = useMemoizedEffects({
106
73
  effects,
107
- overrideId: (_a = controls === null || controls === void 0 ? void 0 : controls.overrideId) !== null && _a !== void 0 ? _a : null,
74
+ overrideId: (_b = controls === null || controls === void 0 ? void 0 : controls.overrideId) !== null && _b !== void 0 ? _b : null,
75
+ videoConfigValues: (_c = controls === null || controls === void 0 ? void 0 : controls.videoConfigValues) !== null && _c !== void 0 ? _c : null,
108
76
  });
109
77
  if (err) {
110
78
  throw err;
@@ -129,35 +97,51 @@ const RemotionRiveCanvasContentForwardRefFunction = ({ src, fit, alignment, artb
129
97
  },
130
98
  };
131
99
  }, [rive, riveCanvasInstance]);
132
- (0, react_1.useEffect)(() => {
100
+ (0, react_1.useLayoutEffect)(() => {
101
+ const handle = delayRender('Loading Rive runtime');
102
+ let cancelled = false;
133
103
  (0, canvas_advanced_1.default)({
134
104
  locateFile: () => 'https://unpkg.com/@rive-app/canvas-advanced@2.31.5/rive.wasm',
135
105
  })
136
106
  .then((riveInstance) => {
137
- setRiveCanvas(riveInstance);
138
- continueRender(handle);
107
+ if (!cancelled) {
108
+ setLoadedRuntime({ instance: riveInstance, handle });
109
+ }
139
110
  })
140
111
  .catch((newErr) => {
141
- setError(newErr);
112
+ if (!cancelled) {
113
+ setError(newErr);
114
+ }
142
115
  });
143
- }, [handle, continueRender]);
144
- (0, react_1.useEffect)(() => {
145
- if (!riveCanvasInstance || !sourceCanvas) {
116
+ return () => {
117
+ cancelled = true;
118
+ continueRender(handle);
119
+ };
120
+ }, [delayRender, continueRender]);
121
+ (0, react_1.useLayoutEffect)(() => {
122
+ if (!riveCanvasInstance || !sourceCanvas || !loadedRuntime) {
146
123
  return;
147
124
  }
125
+ const handle = delayRender(`Loading <RemotionRiveCanvas src="${src}"/>`);
126
+ continueRender(loadedRuntime.handle);
127
+ let cancelled = false;
128
+ const controller = new AbortController();
148
129
  sourceCanvas.width = width;
149
130
  sourceCanvas.height = height;
150
131
  const renderer = riveCanvasInstance.makeRenderer(sourceCanvas);
151
- fetch(new Request(src))
132
+ fetch(new Request(src), { signal: controller.signal })
152
133
  .then((f) => f.arrayBuffer())
153
134
  .then((b) => {
154
- riveCanvasInstance
135
+ return riveCanvasInstance
155
136
  .load(new Uint8Array(b), assetLoader
156
137
  ? new riveCanvasInstance.CustomFileAssetLoader({
157
138
  loadContents: assetLoader,
158
139
  })
159
140
  : undefined, enableRiveAssetCdn)
160
141
  .then((file) => {
142
+ if (cancelled) {
143
+ return;
144
+ }
161
145
  const artboard = typeof artboardName === 'string'
162
146
  ? file.artboardByName(artboardName)
163
147
  : typeof artboardName === 'number'
@@ -173,12 +157,20 @@ const RemotionRiveCanvasContentForwardRefFunction = ({ src, fit, alignment, artb
173
157
  artboard,
174
158
  renderer,
175
159
  file,
160
+ handle,
176
161
  });
177
162
  });
178
163
  })
179
164
  .catch((newErr) => {
180
- setError(newErr);
165
+ if (!cancelled) {
166
+ setError(newErr);
167
+ }
181
168
  });
169
+ return () => {
170
+ cancelled = true;
171
+ controller.abort();
172
+ continueRender(handle);
173
+ };
182
174
  }, [
183
175
  animationIndex,
184
176
  artboardName,
@@ -190,13 +182,16 @@ const RemotionRiveCanvasContentForwardRefFunction = ({ src, fit, alignment, artb
190
182
  sourceCanvas,
191
183
  width,
192
184
  height,
185
+ loadedRuntime,
186
+ delayRender,
187
+ continueRender,
193
188
  ]);
194
189
  (0, react_1.useEffect)(() => {
195
190
  if (onLoad && rive) {
196
191
  onLoad(rive.file);
197
192
  }
198
193
  }, [onLoad, rive]);
199
- react_1.default.useEffect(() => {
194
+ (0, react_1.useLayoutEffect)(() => {
200
195
  if (!riveCanvasInstance || !rive) {
201
196
  return;
202
197
  }
@@ -244,6 +239,7 @@ const RemotionRiveCanvasContentForwardRefFunction = ({ src, fit, alignment, artb
244
239
  return;
245
240
  }
246
241
  const effectChainHandle = delayRender(`Rendering frame at ${frame} of <RemotionRiveCanvas src="${src}"/>`);
242
+ continueRender(rive.handle);
247
243
  let cancelled = false;
248
244
  runEffectChain({
249
245
  state,
@@ -316,9 +312,7 @@ const RemotionRiveCanvasInnerForwardRefFunction = ({ src, fit = 'contain', align
316
312
  style: premountingStyle,
317
313
  componentName: '<RemotionRiveCanvas />',
318
314
  });
319
- return (jsx_runtime_1.jsx(remotion_1.Freeze, { frame: freezeFrame, active: isPremountingOrPostmounting, children: jsx_runtime_1.jsx(remotion_1.Sequence, { layout: "none", from: from, trimBefore: trimBefore, playbackRate: playbackRate, loop: loop, freeze: freeze, hidden: hidden, showInTimeline: showInTimeline, name: name !== null && name !== void 0 ? name : '<RemotionRiveCanvas>', _remotionInternalDocumentationLink: name === undefined
320
- ? 'https://www.remotion.dev/docs/rive/remotionrivecanvas'
321
- : undefined, durationInFrames: durationInFrames, controls: controls, _remotionInternalEffects: memoizedEffectDefinitions, ...props, _remotionInternalPremountDisplay: effectivePremountFor || null, _remotionInternalPostmountDisplay: effectivePostmountFor || null, _remotionInternalIsPremounting: premountingActive, _remotionInternalIsPostmounting: postmountingActive, children: jsx_runtime_1.jsx(RemotionRiveCanvasContent, { ref: ref, src: src, fit: fit, alignment: alignment, artboard: artboard, animation: animation, onLoad: onLoad, assetLoader: assetLoader, enableRiveAssetCdn: enableRiveAssetCdn, className: className, style: croppedStyle !== null && croppedStyle !== void 0 ? croppedStyle : undefined, effects: effects, controls: controls, canvasRef: canvasRef }) }) }));
315
+ return (jsx_runtime_1.jsx(remotion_1.Freeze, { frame: freezeFrame, active: isPremountingOrPostmounting, children: jsx_runtime_1.jsx(remotion_1.Sequence, { layout: "none", from: from, trimBefore: trimBefore, playbackRate: playbackRate, loop: loop, freeze: freeze, hidden: hidden, showInTimeline: showInTimeline, name: name !== null && name !== void 0 ? name : '<RemotionRiveCanvas>', _remotionInternalDocumentationLink: "https://www.remotion.dev/docs/rive/remotionrivecanvas", durationInFrames: durationInFrames, controls: controls, _remotionInternalEffects: memoizedEffectDefinitions, ...props, _remotionInternalPremountDisplay: effectivePremountFor || null, _remotionInternalPostmountDisplay: effectivePostmountFor || null, _remotionInternalIsPremounting: premountingActive, _remotionInternalIsPostmounting: postmountingActive, children: jsx_runtime_1.jsx(RemotionRiveCanvasContent, { ref: ref, src: src, fit: fit, alignment: alignment, artboard: artboard, animation: animation, onLoad: onLoad, assetLoader: assetLoader, enableRiveAssetCdn: enableRiveAssetCdn, className: className, style: croppedStyle !== null && croppedStyle !== void 0 ? croppedStyle : undefined, effects: effects, controls: controls, canvasRef: canvasRef }) }) }));
322
316
  };
323
317
  const RemotionRiveCanvasInner = (0, react_1.forwardRef)(RemotionRiveCanvasInnerForwardRefFunction);
324
318
  exports.RemotionRiveCanvas = remotion_1.Interactive.withSchema({
@@ -1,9 +1,10 @@
1
1
  // src/RemotionRiveCanvas.tsx
2
2
  import riveCanvas from "@rive-app/canvas-advanced";
3
- import React, {
3
+ import {
4
4
  forwardRef,
5
5
  useEffect,
6
6
  useImperativeHandle,
7
+ useLayoutEffect,
7
8
  useMemo,
8
9
  useRef,
9
10
  useState
@@ -140,10 +141,10 @@ var RemotionRiveCanvasContentForwardRefFunction = ({
140
141
  }, ref) => {
141
142
  const { width, fps, height } = useVideoConfig();
142
143
  const frame = useCurrentFrame();
143
- const [riveCanvasInstance, setRiveCanvas] = useState(null);
144
+ const [loadedRuntime, setLoadedRuntime] = useState(null);
145
+ const riveCanvasInstance = loadedRuntime?.instance ?? null;
144
146
  const [err, setError] = useState(null);
145
147
  const { delayRender, continueRender } = useDelayRender();
146
- const [handle] = useState(() => delayRender());
147
148
  const lastFrame = useRef(0);
148
149
  const sourceCanvas = useMemo(() => {
149
150
  if (typeof document === "undefined") {
@@ -154,7 +155,8 @@ var RemotionRiveCanvasContentForwardRefFunction = ({
154
155
  const chainState = useEffectChainState();
155
156
  const memoizedEffects = useMemoizedEffects({
156
157
  effects,
157
- overrideId: controls?.overrideId ?? null
158
+ overrideId: controls?.overrideId ?? null,
159
+ videoConfigValues: controls?.videoConfigValues ?? null
158
160
  });
159
161
  if (err) {
160
162
  throw err;
@@ -176,39 +178,63 @@ var RemotionRiveCanvasContentForwardRefFunction = ({
176
178
  }
177
179
  };
178
180
  }, [rive, riveCanvasInstance]);
179
- useEffect(() => {
181
+ useLayoutEffect(() => {
182
+ const handle = delayRender("Loading Rive runtime");
183
+ let cancelled = false;
180
184
  riveCanvas({
181
185
  locateFile: () => "https://unpkg.com/@rive-app/canvas-advanced@2.31.5/rive.wasm"
182
186
  }).then((riveInstance) => {
183
- setRiveCanvas(riveInstance);
184
- continueRender(handle);
187
+ if (!cancelled) {
188
+ setLoadedRuntime({ instance: riveInstance, handle });
189
+ }
185
190
  }).catch((newErr) => {
186
- setError(newErr);
191
+ if (!cancelled) {
192
+ setError(newErr);
193
+ }
187
194
  });
188
- }, [handle, continueRender]);
189
- useEffect(() => {
190
- if (!riveCanvasInstance || !sourceCanvas) {
195
+ return () => {
196
+ cancelled = true;
197
+ continueRender(handle);
198
+ };
199
+ }, [delayRender, continueRender]);
200
+ useLayoutEffect(() => {
201
+ if (!riveCanvasInstance || !sourceCanvas || !loadedRuntime) {
191
202
  return;
192
203
  }
204
+ const handle = delayRender(`Loading <RemotionRiveCanvas src="${src}"/>`);
205
+ continueRender(loadedRuntime.handle);
206
+ let cancelled = false;
207
+ const controller = new AbortController;
193
208
  sourceCanvas.width = width;
194
209
  sourceCanvas.height = height;
195
210
  const renderer = riveCanvasInstance.makeRenderer(sourceCanvas);
196
- fetch(new Request(src)).then((f) => f.arrayBuffer()).then((b) => {
197
- riveCanvasInstance.load(new Uint8Array(b), assetLoader ? new riveCanvasInstance.CustomFileAssetLoader({
211
+ fetch(new Request(src), { signal: controller.signal }).then((f) => f.arrayBuffer()).then((b) => {
212
+ return riveCanvasInstance.load(new Uint8Array(b), assetLoader ? new riveCanvasInstance.CustomFileAssetLoader({
198
213
  loadContents: assetLoader
199
214
  }) : undefined, enableRiveAssetCdn).then((file) => {
215
+ if (cancelled) {
216
+ return;
217
+ }
200
218
  const artboard = typeof artboardName === "string" ? file.artboardByName(artboardName) : typeof artboardName === "number" ? file.artboardByIndex(artboardName) : file.defaultArtboard();
201
219
  const animation = new riveCanvasInstance.LinearAnimationInstance(typeof animationIndex === "number" ? artboard.animationByIndex(animationIndex) : typeof animationIndex === "string" ? artboard.animationByName(animationIndex) : artboard.animationByIndex(0), artboard);
202
220
  setRive({
203
221
  animation,
204
222
  artboard,
205
223
  renderer,
206
- file
224
+ file,
225
+ handle
207
226
  });
208
227
  });
209
228
  }).catch((newErr) => {
210
- setError(newErr);
229
+ if (!cancelled) {
230
+ setError(newErr);
231
+ }
211
232
  });
233
+ return () => {
234
+ cancelled = true;
235
+ controller.abort();
236
+ continueRender(handle);
237
+ };
212
238
  }, [
213
239
  animationIndex,
214
240
  artboardName,
@@ -219,14 +245,17 @@ var RemotionRiveCanvasContentForwardRefFunction = ({
219
245
  enableRiveAssetCdn,
220
246
  sourceCanvas,
221
247
  width,
222
- height
248
+ height,
249
+ loadedRuntime,
250
+ delayRender,
251
+ continueRender
223
252
  ]);
224
253
  useEffect(() => {
225
254
  if (onLoad && rive) {
226
255
  onLoad(rive.file);
227
256
  }
228
257
  }, [onLoad, rive]);
229
- React.useEffect(() => {
258
+ useLayoutEffect(() => {
230
259
  if (!riveCanvasInstance || !rive) {
231
260
  return;
232
261
  }
@@ -265,6 +294,7 @@ var RemotionRiveCanvasContentForwardRefFunction = ({
265
294
  return;
266
295
  }
267
296
  const effectChainHandle = delayRender(`Rendering frame at ${frame} of <RemotionRiveCanvas src="${src}"/>`);
297
+ continueRender(rive.handle);
268
298
  let cancelled = false;
269
299
  runEffectChain({
270
300
  state,
@@ -392,7 +422,7 @@ var RemotionRiveCanvasInnerForwardRefFunction = ({
392
422
  hidden,
393
423
  showInTimeline,
394
424
  name: name ?? "<RemotionRiveCanvas>",
395
- _remotionInternalDocumentationLink: name === undefined ? "https://www.remotion.dev/docs/rive/remotionrivecanvas" : undefined,
425
+ _remotionInternalDocumentationLink: "https://www.remotion.dev/docs/rive/remotionrivecanvas",
396
426
  durationInFrames,
397
427
  controls,
398
428
  _remotionInternalEffects: memoizedEffectDefinitions,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "url": "https://github.com/remotion-dev/remotion/tree/main/packages/rive"
4
4
  },
5
5
  "name": "@remotion/rive",
6
- "version": "4.0.533",
6
+ "version": "4.0.535",
7
7
  "description": "Embed Rive animations in a Remotion video",
8
8
  "main": "dist/cjs/index.js",
9
9
  "types": "dist/cjs/index.d.ts",
@@ -23,7 +23,7 @@
23
23
  "license": "See LICENSE.md",
24
24
  "dependencies": {
25
25
  "@rive-app/canvas-advanced": "2.31.5",
26
- "remotion": "4.0.533"
26
+ "remotion": "4.0.535"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "react": ">=18.2.0",
@@ -32,7 +32,7 @@
32
32
  "devDependencies": {
33
33
  "react": "19.2.3",
34
34
  "react-dom": "19.2.3",
35
- "@remotion/eslint-config-internal": "4.0.533",
35
+ "@remotion/eslint-config-internal": "4.0.535",
36
36
  "eslint": "9.19.0",
37
37
  "@typescript/native-preview": "7.0.0-dev.20260217.1"
38
38
  },