@remotion/rive 4.0.462 → 4.0.464
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/cjs/RemotionRiveCanvas.d.ts +9 -3
- package/dist/cjs/RemotionRiveCanvas.js +154 -29
- package/dist/cjs/index.d.ts +1 -1
- package/dist/esm/index.mjs +208 -35
- package/package.json +3 -3
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { Artboard, CanvasRenderer, File, FileAsset, LinearAnimationInstance, RiveCanvas } from '@rive-app/canvas-advanced';
|
|
2
2
|
import React from 'react';
|
|
3
|
+
import type { EffectsProp, SequenceProps } from 'remotion';
|
|
3
4
|
import type { RemotionRiveCanvasAlignment, RemotionRiveCanvasFit } from './map-enums.js';
|
|
4
5
|
type assetLoadCallback = (asset: FileAsset, bytes: Uint8Array) => boolean;
|
|
5
6
|
type onLoadCallback = (file: File) => void;
|
|
6
|
-
|
|
7
|
+
type RiveSequenceInheritedProps = Pick<SequenceProps, 'durationInFrames' | 'name' | 'from' | 'showInTimeline' | 'hidden'>;
|
|
8
|
+
type RemotionRiveCanvasOwnProps = {
|
|
7
9
|
readonly src: string;
|
|
8
10
|
readonly fit?: RemotionRiveCanvasFit;
|
|
9
11
|
readonly alignment?: RemotionRiveCanvasAlignment;
|
|
@@ -12,12 +14,16 @@ interface RiveProps {
|
|
|
12
14
|
readonly onLoad?: onLoadCallback | null;
|
|
13
15
|
readonly enableRiveAssetCdn?: boolean;
|
|
14
16
|
readonly assetLoader?: assetLoadCallback;
|
|
15
|
-
|
|
17
|
+
readonly className?: string;
|
|
18
|
+
readonly style?: React.CSSProperties;
|
|
19
|
+
readonly _experimentalEffects?: EffectsProp;
|
|
20
|
+
};
|
|
21
|
+
export type RemotionRiveCanvasProps = RemotionRiveCanvasOwnProps & RiveSequenceInheritedProps;
|
|
16
22
|
export type RiveCanvasRef = {
|
|
17
23
|
getAnimationInstance: () => LinearAnimationInstance | null;
|
|
18
24
|
getArtboard: () => Artboard | null;
|
|
19
25
|
getRenderer: () => CanvasRenderer | null;
|
|
20
26
|
getCanvas: () => RiveCanvas | null;
|
|
21
27
|
};
|
|
22
|
-
export declare const RemotionRiveCanvas: React.ForwardRefExoticComponent<
|
|
28
|
+
export declare const RemotionRiveCanvas: React.ForwardRefExoticComponent<RemotionRiveCanvasOwnProps & RiveSequenceInheritedProps & React.RefAttributes<RiveCanvasRef>>;
|
|
23
29
|
export {};
|
|
@@ -42,7 +42,45 @@ const canvas_advanced_1 = __importDefault(require("@rive-app/canvas-advanced"));
|
|
|
42
42
|
const react_1 = __importStar(require("react"));
|
|
43
43
|
const remotion_1 = require("remotion");
|
|
44
44
|
const map_enums_js_1 = require("./map-enums.js");
|
|
45
|
-
const
|
|
45
|
+
const { addSequenceStackTraces, hiddenField, runEffectChain, sequenceVisualStyleSchema, useEffectChainState, useMemoizedEffectDefinitions, useMemoizedEffects, wrapInSchema, } = remotion_1.Internals;
|
|
46
|
+
const riveFitVariants = {
|
|
47
|
+
contain: {},
|
|
48
|
+
cover: {},
|
|
49
|
+
fill: {},
|
|
50
|
+
'fit-height': {},
|
|
51
|
+
'fit-width': {},
|
|
52
|
+
none: {},
|
|
53
|
+
'scale-down': {},
|
|
54
|
+
};
|
|
55
|
+
const riveAlignmentVariants = {
|
|
56
|
+
center: {},
|
|
57
|
+
'bottom-center': {},
|
|
58
|
+
'bottom-left': {},
|
|
59
|
+
'bottom-right': {},
|
|
60
|
+
'center-left': {},
|
|
61
|
+
'center-right': {},
|
|
62
|
+
'top-center': {},
|
|
63
|
+
'top-left': {},
|
|
64
|
+
'top-right': {},
|
|
65
|
+
};
|
|
66
|
+
const riveCanvasSchema = {
|
|
67
|
+
fit: {
|
|
68
|
+
type: 'enum',
|
|
69
|
+
default: 'contain',
|
|
70
|
+
description: 'Fit',
|
|
71
|
+
variants: riveFitVariants,
|
|
72
|
+
},
|
|
73
|
+
alignment: {
|
|
74
|
+
type: 'enum',
|
|
75
|
+
default: 'center',
|
|
76
|
+
description: 'Alignment',
|
|
77
|
+
variants: riveAlignmentVariants,
|
|
78
|
+
},
|
|
79
|
+
...sequenceVisualStyleSchema,
|
|
80
|
+
hidden: hiddenField,
|
|
81
|
+
};
|
|
82
|
+
const RemotionRiveCanvasContentForwardRefFunction = ({ src, fit, alignment, artboard: artboardName, animation: animationIndex, onLoad = null, assetLoader, enableRiveAssetCdn, className, style, effects, controls, }, ref) => {
|
|
83
|
+
var _a;
|
|
46
84
|
const { width, fps, height } = (0, remotion_1.useVideoConfig)();
|
|
47
85
|
const frame = (0, remotion_1.useCurrentFrame)();
|
|
48
86
|
const canvas = (0, react_1.useRef)(null);
|
|
@@ -51,6 +89,19 @@ const RemotionRiveCanvasForwardRefFunction = ({ src, fit = 'contain', alignment
|
|
|
51
89
|
const { delayRender, continueRender } = (0, remotion_1.useDelayRender)();
|
|
52
90
|
const [handle] = (0, react_1.useState)(() => delayRender());
|
|
53
91
|
const lastFrame = (0, react_1.useRef)(0);
|
|
92
|
+
// Rive draws to this offscreen-style canvas; the effect chain then
|
|
93
|
+
// composites from here onto the visible output canvas.
|
|
94
|
+
const sourceCanvas = (0, react_1.useMemo)(() => {
|
|
95
|
+
if (typeof document === 'undefined') {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
return document.createElement('canvas');
|
|
99
|
+
}, []);
|
|
100
|
+
const chainState = useEffectChainState();
|
|
101
|
+
const memoizedEffects = useMemoizedEffects({
|
|
102
|
+
effects,
|
|
103
|
+
overrideId: (_a = controls === null || controls === void 0 ? void 0 : controls.overrideId) !== null && _a !== void 0 ? _a : null,
|
|
104
|
+
});
|
|
54
105
|
if (err) {
|
|
55
106
|
throw err;
|
|
56
107
|
}
|
|
@@ -87,10 +138,12 @@ const RemotionRiveCanvasForwardRefFunction = ({ src, fit = 'contain', alignment
|
|
|
87
138
|
});
|
|
88
139
|
}, [handle, continueRender]);
|
|
89
140
|
(0, react_1.useEffect)(() => {
|
|
90
|
-
if (!riveCanvasInstance) {
|
|
141
|
+
if (!riveCanvasInstance || !sourceCanvas) {
|
|
91
142
|
return;
|
|
92
143
|
}
|
|
93
|
-
|
|
144
|
+
sourceCanvas.width = width;
|
|
145
|
+
sourceCanvas.height = height;
|
|
146
|
+
const renderer = riveCanvasInstance.makeRenderer(sourceCanvas);
|
|
94
147
|
fetch(new Request(src))
|
|
95
148
|
.then((f) => f.arrayBuffer())
|
|
96
149
|
.then((b) => {
|
|
@@ -130,6 +183,9 @@ const RemotionRiveCanvasForwardRefFunction = ({ src, fit = 'contain', alignment
|
|
|
130
183
|
onLoad,
|
|
131
184
|
assetLoader,
|
|
132
185
|
enableRiveAssetCdn,
|
|
186
|
+
sourceCanvas,
|
|
187
|
+
width,
|
|
188
|
+
height,
|
|
133
189
|
]);
|
|
134
190
|
(0, react_1.useEffect)(() => {
|
|
135
191
|
if (onLoad && rive) {
|
|
@@ -137,36 +193,105 @@ const RemotionRiveCanvasForwardRefFunction = ({ src, fit = 'contain', alignment
|
|
|
137
193
|
}
|
|
138
194
|
}, [onLoad, rive]);
|
|
139
195
|
react_1.default.useEffect(() => {
|
|
140
|
-
if (!riveCanvasInstance) {
|
|
196
|
+
if (!riveCanvasInstance || !rive) {
|
|
141
197
|
return;
|
|
142
198
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
199
|
+
const outputCanvas = canvas.current;
|
|
200
|
+
if (!outputCanvas || !sourceCanvas) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
// Keep source/output dimensions in sync with the video config.
|
|
204
|
+
if (sourceCanvas.width !== width || sourceCanvas.height !== height) {
|
|
205
|
+
sourceCanvas.width = width;
|
|
206
|
+
sourceCanvas.height = height;
|
|
207
|
+
}
|
|
208
|
+
if (outputCanvas.width !== width || outputCanvas.height !== height) {
|
|
209
|
+
outputCanvas.width = width;
|
|
210
|
+
outputCanvas.height = height;
|
|
211
|
+
}
|
|
212
|
+
const diff = frame - lastFrame.current;
|
|
213
|
+
rive.renderer.clear();
|
|
214
|
+
if (rive.animation) {
|
|
215
|
+
rive.animation.advance(diff / fps);
|
|
216
|
+
rive.animation.apply(1);
|
|
217
|
+
}
|
|
218
|
+
rive.artboard.advance(diff / fps);
|
|
219
|
+
rive.renderer.save();
|
|
220
|
+
rive.renderer.align((0, map_enums_js_1.mapToFit)(fit, riveCanvasInstance), (0, map_enums_js_1.mapToAlignment)(alignment, riveCanvasInstance.Alignment), {
|
|
221
|
+
minX: 0,
|
|
222
|
+
minY: 0,
|
|
223
|
+
maxX: sourceCanvas.width,
|
|
224
|
+
maxY: sourceCanvas.height,
|
|
225
|
+
}, rive.artboard.bounds);
|
|
226
|
+
rive.artboard.draw(rive.renderer);
|
|
227
|
+
rive.renderer.restore();
|
|
228
|
+
// Flush the renderer's queued draw calls so `sourceCanvas` actually
|
|
229
|
+
// contains the pixels we just drew before `runEffectChain` reads from
|
|
230
|
+
// it. We don't use `riveCanvasInstance.requestAnimationFrame` (which
|
|
231
|
+
// would flush implicitly at the end of its own callback) because the
|
|
232
|
+
// effect chain needs the flushed pixels synchronously, and waiting
|
|
233
|
+
// for a Rive-scheduled frame would mean the very first paint after
|
|
234
|
+
// mount (and after every prop change) would composite an empty /
|
|
235
|
+
// stale source canvas to the output.
|
|
236
|
+
riveCanvasInstance.resolveAnimationFrame();
|
|
237
|
+
lastFrame.current = frame;
|
|
238
|
+
const state = chainState.get(width, height);
|
|
239
|
+
if (!state) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
const effectChainHandle = delayRender(`Rendering frame at ${frame} of <RemotionRiveCanvas src="${src}"/>`);
|
|
243
|
+
let cancelled = false;
|
|
244
|
+
runEffectChain({
|
|
245
|
+
state,
|
|
246
|
+
source: sourceCanvas,
|
|
247
|
+
effects: memoizedEffects,
|
|
248
|
+
output: outputCanvas,
|
|
249
|
+
width,
|
|
250
|
+
height,
|
|
251
|
+
})
|
|
252
|
+
.then(() => {
|
|
253
|
+
if (!cancelled) {
|
|
254
|
+
continueRender(effectChainHandle);
|
|
152
255
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
minX: 0,
|
|
157
|
-
minY: 0,
|
|
158
|
-
maxX: canvas.current.width,
|
|
159
|
-
maxY: canvas.current.height,
|
|
160
|
-
}, rive.artboard.bounds);
|
|
161
|
-
rive.artboard.draw(rive.renderer);
|
|
162
|
-
rive.renderer.restore();
|
|
163
|
-
lastFrame.current = frame;
|
|
256
|
+
})
|
|
257
|
+
.catch((newErr) => {
|
|
258
|
+
setError(newErr);
|
|
164
259
|
});
|
|
165
|
-
|
|
166
|
-
|
|
260
|
+
return () => {
|
|
261
|
+
cancelled = true;
|
|
262
|
+
continueRender(effectChainHandle);
|
|
263
|
+
};
|
|
264
|
+
}, [
|
|
265
|
+
frame,
|
|
266
|
+
fps,
|
|
267
|
+
rive,
|
|
268
|
+
riveCanvasInstance,
|
|
269
|
+
fit,
|
|
270
|
+
alignment,
|
|
271
|
+
width,
|
|
272
|
+
height,
|
|
273
|
+
sourceCanvas,
|
|
274
|
+
memoizedEffects,
|
|
275
|
+
chainState,
|
|
276
|
+
delayRender,
|
|
277
|
+
continueRender,
|
|
278
|
+
src,
|
|
279
|
+
]);
|
|
280
|
+
const canvasStyle = (0, react_1.useMemo)(() => ({
|
|
167
281
|
height,
|
|
168
282
|
width,
|
|
169
|
-
|
|
170
|
-
|
|
283
|
+
...style,
|
|
284
|
+
}), [height, style, width]);
|
|
285
|
+
return (jsx_runtime_1.jsx("canvas", { ref: canvas, width: width, height: height, className: className, style: canvasStyle }));
|
|
286
|
+
};
|
|
287
|
+
const RemotionRiveCanvasContent = (0, react_1.forwardRef)(RemotionRiveCanvasContentForwardRefFunction);
|
|
288
|
+
const RemotionRiveCanvasInnerForwardRefFunction = ({ src, fit = 'contain', alignment = 'center', artboard, animation, onLoad = null, assetLoader, enableRiveAssetCdn = true, className, style, _experimentalEffects: effects = [], _experimentalControls: controls, durationInFrames, name, from, showInTimeline, hidden, ...props }, ref) => {
|
|
289
|
+
props;
|
|
290
|
+
const memoizedEffectDefinitions = useMemoizedEffectDefinitions(effects);
|
|
291
|
+
return (jsx_runtime_1.jsx(remotion_1.Sequence, { layout: "none", from: from, hidden: hidden, showInTimeline: showInTimeline, name: name !== null && name !== void 0 ? name : '<RemotionRiveCanvas>', durationInFrames: durationInFrames, _experimentalControls: controls, _experimentalEffects: memoizedEffectDefinitions, ...props, 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: style, effects: effects, controls: controls }) }));
|
|
171
292
|
};
|
|
172
|
-
|
|
293
|
+
const RemotionRiveCanvasInner = (0, react_1.forwardRef)(RemotionRiveCanvasInnerForwardRefFunction);
|
|
294
|
+
exports.RemotionRiveCanvas = wrapInSchema(RemotionRiveCanvasInner, riveCanvasSchema);
|
|
295
|
+
addSequenceStackTraces(exports.RemotionRiveCanvas);
|
|
296
|
+
exports.RemotionRiveCanvas.displayName =
|
|
297
|
+
'RemotionRiveCanvas';
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { RemotionRiveCanvas, RiveCanvasRef } from './RemotionRiveCanvas.js';
|
|
1
|
+
export { RemotionRiveCanvas, RemotionRiveCanvasProps, RiveCanvasRef, } from './RemotionRiveCanvas.js';
|
package/dist/esm/index.mjs
CHANGED
|
@@ -8,7 +8,13 @@ import React, {
|
|
|
8
8
|
useRef,
|
|
9
9
|
useState
|
|
10
10
|
} from "react";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
Internals,
|
|
13
|
+
Sequence,
|
|
14
|
+
useCurrentFrame,
|
|
15
|
+
useDelayRender,
|
|
16
|
+
useVideoConfig
|
|
17
|
+
} from "remotion";
|
|
12
18
|
|
|
13
19
|
// src/map-enums.ts
|
|
14
20
|
var mapToFit = (fit, canvas) => {
|
|
@@ -68,15 +74,65 @@ var mapToAlignment = (alignment, factory) => {
|
|
|
68
74
|
|
|
69
75
|
// src/RemotionRiveCanvas.tsx
|
|
70
76
|
import { jsx } from "react/jsx-runtime";
|
|
71
|
-
var
|
|
77
|
+
var {
|
|
78
|
+
addSequenceStackTraces,
|
|
79
|
+
hiddenField,
|
|
80
|
+
runEffectChain,
|
|
81
|
+
sequenceVisualStyleSchema,
|
|
82
|
+
useEffectChainState,
|
|
83
|
+
useMemoizedEffectDefinitions,
|
|
84
|
+
useMemoizedEffects,
|
|
85
|
+
wrapInSchema
|
|
86
|
+
} = Internals;
|
|
87
|
+
var riveFitVariants = {
|
|
88
|
+
contain: {},
|
|
89
|
+
cover: {},
|
|
90
|
+
fill: {},
|
|
91
|
+
"fit-height": {},
|
|
92
|
+
"fit-width": {},
|
|
93
|
+
none: {},
|
|
94
|
+
"scale-down": {}
|
|
95
|
+
};
|
|
96
|
+
var riveAlignmentVariants = {
|
|
97
|
+
center: {},
|
|
98
|
+
"bottom-center": {},
|
|
99
|
+
"bottom-left": {},
|
|
100
|
+
"bottom-right": {},
|
|
101
|
+
"center-left": {},
|
|
102
|
+
"center-right": {},
|
|
103
|
+
"top-center": {},
|
|
104
|
+
"top-left": {},
|
|
105
|
+
"top-right": {}
|
|
106
|
+
};
|
|
107
|
+
var riveCanvasSchema = {
|
|
108
|
+
fit: {
|
|
109
|
+
type: "enum",
|
|
110
|
+
default: "contain",
|
|
111
|
+
description: "Fit",
|
|
112
|
+
variants: riveFitVariants
|
|
113
|
+
},
|
|
114
|
+
alignment: {
|
|
115
|
+
type: "enum",
|
|
116
|
+
default: "center",
|
|
117
|
+
description: "Alignment",
|
|
118
|
+
variants: riveAlignmentVariants
|
|
119
|
+
},
|
|
120
|
+
...sequenceVisualStyleSchema,
|
|
121
|
+
hidden: hiddenField
|
|
122
|
+
};
|
|
123
|
+
var RemotionRiveCanvasContentForwardRefFunction = ({
|
|
72
124
|
src,
|
|
73
|
-
fit
|
|
74
|
-
alignment
|
|
125
|
+
fit,
|
|
126
|
+
alignment,
|
|
75
127
|
artboard: artboardName,
|
|
76
128
|
animation: animationIndex,
|
|
77
129
|
onLoad = null,
|
|
78
130
|
assetLoader,
|
|
79
|
-
enableRiveAssetCdn
|
|
131
|
+
enableRiveAssetCdn,
|
|
132
|
+
className,
|
|
133
|
+
style,
|
|
134
|
+
effects,
|
|
135
|
+
controls
|
|
80
136
|
}, ref) => {
|
|
81
137
|
const { width, fps, height } = useVideoConfig();
|
|
82
138
|
const frame = useCurrentFrame();
|
|
@@ -86,6 +142,17 @@ var RemotionRiveCanvasForwardRefFunction = ({
|
|
|
86
142
|
const { delayRender, continueRender } = useDelayRender();
|
|
87
143
|
const [handle] = useState(() => delayRender());
|
|
88
144
|
const lastFrame = useRef(0);
|
|
145
|
+
const sourceCanvas = useMemo(() => {
|
|
146
|
+
if (typeof document === "undefined") {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
return document.createElement("canvas");
|
|
150
|
+
}, []);
|
|
151
|
+
const chainState = useEffectChainState();
|
|
152
|
+
const memoizedEffects = useMemoizedEffects({
|
|
153
|
+
effects,
|
|
154
|
+
overrideId: controls?.overrideId ?? null
|
|
155
|
+
});
|
|
89
156
|
if (err) {
|
|
90
157
|
throw err;
|
|
91
158
|
}
|
|
@@ -117,10 +184,12 @@ var RemotionRiveCanvasForwardRefFunction = ({
|
|
|
117
184
|
});
|
|
118
185
|
}, [handle, continueRender]);
|
|
119
186
|
useEffect(() => {
|
|
120
|
-
if (!riveCanvasInstance) {
|
|
187
|
+
if (!riveCanvasInstance || !sourceCanvas) {
|
|
121
188
|
return;
|
|
122
189
|
}
|
|
123
|
-
|
|
190
|
+
sourceCanvas.width = width;
|
|
191
|
+
sourceCanvas.height = height;
|
|
192
|
+
const renderer = riveCanvasInstance.makeRenderer(sourceCanvas);
|
|
124
193
|
fetch(new Request(src)).then((f) => f.arrayBuffer()).then((b) => {
|
|
125
194
|
riveCanvasInstance.load(new Uint8Array(b), assetLoader ? new riveCanvasInstance.CustomFileAssetLoader({
|
|
126
195
|
loadContents: assetLoader
|
|
@@ -144,7 +213,10 @@ var RemotionRiveCanvasForwardRefFunction = ({
|
|
|
144
213
|
src,
|
|
145
214
|
onLoad,
|
|
146
215
|
assetLoader,
|
|
147
|
-
enableRiveAssetCdn
|
|
216
|
+
enableRiveAssetCdn,
|
|
217
|
+
sourceCanvas,
|
|
218
|
+
width,
|
|
219
|
+
height
|
|
148
220
|
]);
|
|
149
221
|
useEffect(() => {
|
|
150
222
|
if (onLoad && rive) {
|
|
@@ -152,44 +224,145 @@ var RemotionRiveCanvasForwardRefFunction = ({
|
|
|
152
224
|
}
|
|
153
225
|
}, [onLoad, rive]);
|
|
154
226
|
React.useEffect(() => {
|
|
155
|
-
if (!riveCanvasInstance) {
|
|
227
|
+
if (!riveCanvasInstance || !rive) {
|
|
156
228
|
return;
|
|
157
229
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
230
|
+
const outputCanvas = canvas.current;
|
|
231
|
+
if (!outputCanvas || !sourceCanvas) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
if (sourceCanvas.width !== width || sourceCanvas.height !== height) {
|
|
235
|
+
sourceCanvas.width = width;
|
|
236
|
+
sourceCanvas.height = height;
|
|
237
|
+
}
|
|
238
|
+
if (outputCanvas.width !== width || outputCanvas.height !== height) {
|
|
239
|
+
outputCanvas.width = width;
|
|
240
|
+
outputCanvas.height = height;
|
|
241
|
+
}
|
|
242
|
+
const diff = frame - lastFrame.current;
|
|
243
|
+
rive.renderer.clear();
|
|
244
|
+
if (rive.animation) {
|
|
245
|
+
rive.animation.advance(diff / fps);
|
|
246
|
+
rive.animation.apply(1);
|
|
247
|
+
}
|
|
248
|
+
rive.artboard.advance(diff / fps);
|
|
249
|
+
rive.renderer.save();
|
|
250
|
+
rive.renderer.align(mapToFit(fit, riveCanvasInstance), mapToAlignment(alignment, riveCanvasInstance.Alignment), {
|
|
251
|
+
minX: 0,
|
|
252
|
+
minY: 0,
|
|
253
|
+
maxX: sourceCanvas.width,
|
|
254
|
+
maxY: sourceCanvas.height
|
|
255
|
+
}, rive.artboard.bounds);
|
|
256
|
+
rive.artboard.draw(rive.renderer);
|
|
257
|
+
rive.renderer.restore();
|
|
258
|
+
riveCanvasInstance.resolveAnimationFrame();
|
|
259
|
+
lastFrame.current = frame;
|
|
260
|
+
const state = chainState.get(width, height);
|
|
261
|
+
if (!state) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const effectChainHandle = delayRender(`Rendering frame at ${frame} of <RemotionRiveCanvas src="${src}"/>`);
|
|
265
|
+
let cancelled = false;
|
|
266
|
+
runEffectChain({
|
|
267
|
+
state,
|
|
268
|
+
source: sourceCanvas,
|
|
269
|
+
effects: memoizedEffects,
|
|
270
|
+
output: outputCanvas,
|
|
271
|
+
width,
|
|
272
|
+
height
|
|
273
|
+
}).then(() => {
|
|
274
|
+
if (!cancelled) {
|
|
275
|
+
continueRender(effectChainHandle);
|
|
167
276
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
rive.renderer.align(mapToFit(fit, riveCanvasInstance), mapToAlignment(alignment, riveCanvasInstance.Alignment), {
|
|
171
|
-
minX: 0,
|
|
172
|
-
minY: 0,
|
|
173
|
-
maxX: canvas.current.width,
|
|
174
|
-
maxY: canvas.current.height
|
|
175
|
-
}, rive.artboard.bounds);
|
|
176
|
-
rive.artboard.draw(rive.renderer);
|
|
177
|
-
rive.renderer.restore();
|
|
178
|
-
lastFrame.current = frame;
|
|
277
|
+
}).catch((newErr) => {
|
|
278
|
+
setError(newErr);
|
|
179
279
|
});
|
|
180
|
-
|
|
181
|
-
|
|
280
|
+
return () => {
|
|
281
|
+
cancelled = true;
|
|
282
|
+
continueRender(effectChainHandle);
|
|
283
|
+
};
|
|
284
|
+
}, [
|
|
285
|
+
frame,
|
|
286
|
+
fps,
|
|
287
|
+
rive,
|
|
288
|
+
riveCanvasInstance,
|
|
289
|
+
fit,
|
|
290
|
+
alignment,
|
|
291
|
+
width,
|
|
292
|
+
height,
|
|
293
|
+
sourceCanvas,
|
|
294
|
+
memoizedEffects,
|
|
295
|
+
chainState,
|
|
296
|
+
delayRender,
|
|
297
|
+
continueRender,
|
|
298
|
+
src
|
|
299
|
+
]);
|
|
300
|
+
const canvasStyle = useMemo(() => ({
|
|
182
301
|
height,
|
|
183
|
-
width
|
|
184
|
-
|
|
302
|
+
width,
|
|
303
|
+
...style
|
|
304
|
+
}), [height, style, width]);
|
|
185
305
|
return /* @__PURE__ */ jsx("canvas", {
|
|
186
306
|
ref: canvas,
|
|
187
307
|
width,
|
|
188
308
|
height,
|
|
189
|
-
|
|
309
|
+
className,
|
|
310
|
+
style: canvasStyle
|
|
311
|
+
});
|
|
312
|
+
};
|
|
313
|
+
var RemotionRiveCanvasContent = forwardRef(RemotionRiveCanvasContentForwardRefFunction);
|
|
314
|
+
var RemotionRiveCanvasInnerForwardRefFunction = ({
|
|
315
|
+
src,
|
|
316
|
+
fit = "contain",
|
|
317
|
+
alignment = "center",
|
|
318
|
+
artboard,
|
|
319
|
+
animation,
|
|
320
|
+
onLoad = null,
|
|
321
|
+
assetLoader,
|
|
322
|
+
enableRiveAssetCdn = true,
|
|
323
|
+
className,
|
|
324
|
+
style,
|
|
325
|
+
_experimentalEffects: effects = [],
|
|
326
|
+
_experimentalControls: controls,
|
|
327
|
+
durationInFrames,
|
|
328
|
+
name,
|
|
329
|
+
from,
|
|
330
|
+
showInTimeline,
|
|
331
|
+
hidden,
|
|
332
|
+
...props
|
|
333
|
+
}, ref) => {
|
|
334
|
+
const memoizedEffectDefinitions = useMemoizedEffectDefinitions(effects);
|
|
335
|
+
return /* @__PURE__ */ jsx(Sequence, {
|
|
336
|
+
layout: "none",
|
|
337
|
+
from,
|
|
338
|
+
hidden,
|
|
339
|
+
showInTimeline,
|
|
340
|
+
name: name ?? "<RemotionRiveCanvas>",
|
|
341
|
+
durationInFrames,
|
|
342
|
+
_experimentalControls: controls,
|
|
343
|
+
_experimentalEffects: memoizedEffectDefinitions,
|
|
344
|
+
...props,
|
|
345
|
+
children: /* @__PURE__ */ jsx(RemotionRiveCanvasContent, {
|
|
346
|
+
ref,
|
|
347
|
+
src,
|
|
348
|
+
fit,
|
|
349
|
+
alignment,
|
|
350
|
+
artboard,
|
|
351
|
+
animation,
|
|
352
|
+
onLoad,
|
|
353
|
+
assetLoader,
|
|
354
|
+
enableRiveAssetCdn,
|
|
355
|
+
className,
|
|
356
|
+
style,
|
|
357
|
+
effects,
|
|
358
|
+
controls
|
|
359
|
+
})
|
|
190
360
|
});
|
|
191
361
|
};
|
|
192
|
-
var
|
|
362
|
+
var RemotionRiveCanvasInner = forwardRef(RemotionRiveCanvasInnerForwardRefFunction);
|
|
363
|
+
var RemotionRiveCanvas = wrapInSchema(RemotionRiveCanvasInner, riveCanvasSchema);
|
|
364
|
+
addSequenceStackTraces(RemotionRiveCanvas);
|
|
365
|
+
RemotionRiveCanvas.displayName = "RemotionRiveCanvas";
|
|
193
366
|
export {
|
|
194
367
|
RemotionRiveCanvas
|
|
195
368
|
};
|
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.
|
|
6
|
+
"version": "4.0.464",
|
|
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",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"license": "See LICENSE.md",
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@rive-app/canvas-advanced": "2.31.5",
|
|
25
|
-
"remotion": "4.0.
|
|
25
|
+
"remotion": "4.0.464"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"react": ">=18.2.0",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"react": "19.2.3",
|
|
33
33
|
"react-dom": "19.2.3",
|
|
34
|
-
"@remotion/eslint-config-internal": "4.0.
|
|
34
|
+
"@remotion/eslint-config-internal": "4.0.464",
|
|
35
35
|
"eslint": "9.19.0",
|
|
36
36
|
"@typescript/native-preview": "7.0.0-dev.20260217.1"
|
|
37
37
|
},
|