@remotion/motion-blur 4.0.0-retry.9 → 4.1.0-alpha2
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/LICENSE.md +1 -1
- package/dist/cjs/CameraMotionBlur.d.ts +11 -0
- package/dist/{CameraMotionBlur.js → cjs/CameraMotionBlur.js} +24 -4
- package/dist/cjs/Trail.d.ts +12 -0
- package/dist/{Trail.js → cjs/Trail.js} +4 -0
- package/dist/{index.d.ts → cjs/index.d.ts} +0 -1
- package/dist/{index.js → cjs/index.js} +1 -3
- package/dist/esm/CameraMotionBlur.d.ts +11 -0
- package/dist/esm/Trail.d.ts +12 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.mjs +90 -0
- package/package.json +60 -48
- package/rollup.config.js +23 -0
- package/tsconfig-esm.json +12 -0
- package/.prettierrc.js +0 -14
- package/dist/CameraMotionBlur.d.ts +0 -7
- package/dist/MotionBlur.d.ts +0 -9
- package/dist/MotionBlur.js +0 -17
- package/dist/Trail.d.ts +0 -8
- package/tsconfig.json +0 -15
package/LICENSE.md
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export type CameraMotionBlurProps = {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
shutterAngle?: number;
|
|
5
|
+
samples?: number;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* @description Produces natural looking motion blur similar to what would be produced by a film camera.
|
|
9
|
+
* @see [Documentation](https://www.remotion.dev/docs/motion-blur/camera-motion-blur)
|
|
10
|
+
*/
|
|
11
|
+
export declare const CameraMotionBlur: React.FC<CameraMotionBlurProps>;
|
|
@@ -3,6 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CameraMotionBlur = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const remotion_1 = require("remotion");
|
|
6
|
+
/**
|
|
7
|
+
* If the current frame is 0, then it is rendered with low opacity,
|
|
8
|
+
* and the trailing elements have frame numbers -1, -2, -3, -4, etc.
|
|
9
|
+
* To fix this, we instead reduce the number of samples to not go into negative territory.
|
|
10
|
+
*/
|
|
11
|
+
const getNumberOfSamples = ({ shutterFraction, samples, currentFrame, }) => {
|
|
12
|
+
const maxOffset = shutterFraction * samples;
|
|
13
|
+
const maxTimeReverse = currentFrame - maxOffset;
|
|
14
|
+
const factor = Math.min(1, Math.max(0, maxTimeReverse / maxOffset + 1));
|
|
15
|
+
return Math.max(1, Math.round(Math.min(factor * samples, samples)));
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* @description Produces natural looking motion blur similar to what would be produced by a film camera.
|
|
19
|
+
* @see [Documentation](https://www.remotion.dev/docs/motion-blur/camera-motion-blur)
|
|
20
|
+
*/
|
|
6
21
|
const CameraMotionBlur = ({ children, shutterAngle = 180, samples = 10, }) => {
|
|
7
22
|
const currentFrame = (0, remotion_1.useCurrentFrame)();
|
|
8
23
|
if (typeof samples !== 'number' ||
|
|
@@ -25,13 +40,18 @@ const CameraMotionBlur = ({ children, shutterAngle = 180, samples = 10, }) => {
|
|
|
25
40
|
throw new TypeError(`"shutterAngle" must be between 0 and 360, but got ${JSON.stringify(shutterAngle)}`);
|
|
26
41
|
}
|
|
27
42
|
const shutterFraction = shutterAngle / 360;
|
|
28
|
-
|
|
43
|
+
const actualSamples = getNumberOfSamples({
|
|
44
|
+
currentFrame,
|
|
45
|
+
samples,
|
|
46
|
+
shutterFraction,
|
|
47
|
+
});
|
|
48
|
+
return ((0, jsx_runtime_1.jsx)(remotion_1.AbsoluteFill, { style: { isolation: 'isolate' }, children: new Array(actualSamples).fill(true).map((_, i) => {
|
|
29
49
|
const sample = i + 1;
|
|
30
|
-
const sampleFrameOffset = shutterFraction * (sample /
|
|
50
|
+
const sampleFrameOffset = shutterFraction * (sample / actualSamples);
|
|
31
51
|
return ((0, jsx_runtime_1.jsx)(remotion_1.AbsoluteFill, { style: {
|
|
32
52
|
mixBlendMode: 'plus-lighter',
|
|
33
|
-
filter: `opacity(${1 /
|
|
34
|
-
}, children: (0, jsx_runtime_1.jsx)(remotion_1.Freeze, { frame: currentFrame - sampleFrameOffset, children: children }) }, `frame-${i.toString()}`));
|
|
53
|
+
filter: `opacity(${1 / actualSamples})`,
|
|
54
|
+
}, children: (0, jsx_runtime_1.jsx)(remotion_1.Freeze, { frame: currentFrame - sampleFrameOffset + 1, children: children }) }, `frame-${i.toString()}`));
|
|
35
55
|
}) }));
|
|
36
56
|
};
|
|
37
57
|
exports.CameraMotionBlur = CameraMotionBlur;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export type TrailProps = {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
layers: number;
|
|
5
|
+
lagInFrames: number;
|
|
6
|
+
trailOpacity: number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* @description The <Trail> component duplicates it's children and adds a time offset to each layer in order to create a trail effect.
|
|
10
|
+
* @see [Documentation](https://www.remotion.dev/docs/motion-blur/trail)
|
|
11
|
+
*/
|
|
12
|
+
export declare const Trail: React.FC<TrailProps>;
|
|
@@ -3,6 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Trail = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const remotion_1 = require("remotion");
|
|
6
|
+
/**
|
|
7
|
+
* @description The <Trail> component duplicates it's children and adds a time offset to each layer in order to create a trail effect.
|
|
8
|
+
* @see [Documentation](https://www.remotion.dev/docs/motion-blur/trail)
|
|
9
|
+
*/
|
|
6
10
|
const Trail = ({ children, layers, lagInFrames, trailOpacity, }) => {
|
|
7
11
|
const frame = (0, remotion_1.useCurrentFrame)();
|
|
8
12
|
if (typeof layers !== 'number' ||
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Trail = exports.
|
|
3
|
+
exports.Trail = exports.CameraMotionBlur = void 0;
|
|
4
4
|
var CameraMotionBlur_1 = require("./CameraMotionBlur");
|
|
5
5
|
Object.defineProperty(exports, "CameraMotionBlur", { enumerable: true, get: function () { return CameraMotionBlur_1.CameraMotionBlur; } });
|
|
6
|
-
var MotionBlur_1 = require("./MotionBlur");
|
|
7
|
-
Object.defineProperty(exports, "MotionBlur", { enumerable: true, get: function () { return MotionBlur_1.MotionBlur; } });
|
|
8
6
|
var Trail_1 = require("./Trail");
|
|
9
7
|
Object.defineProperty(exports, "Trail", { enumerable: true, get: function () { return Trail_1.Trail; } });
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export type CameraMotionBlurProps = {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
shutterAngle?: number;
|
|
5
|
+
samples?: number;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* @description Produces natural looking motion blur similar to what would be produced by a film camera.
|
|
9
|
+
* @see [Documentation](https://www.remotion.dev/docs/motion-blur/camera-motion-blur)
|
|
10
|
+
*/
|
|
11
|
+
export declare const CameraMotionBlur: React.FC<CameraMotionBlurProps>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export type TrailProps = {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
layers: number;
|
|
5
|
+
lagInFrames: number;
|
|
6
|
+
trailOpacity: number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* @description The <Trail> component duplicates it's children and adds a time offset to each layer in order to create a trail effect.
|
|
10
|
+
* @see [Documentation](https://www.remotion.dev/docs/motion-blur/trail)
|
|
11
|
+
*/
|
|
12
|
+
export declare const Trail: React.FC<TrailProps>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import { useCurrentFrame, AbsoluteFill, Freeze } from 'remotion';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* If the current frame is 0, then it is rendered with low opacity,
|
|
6
|
+
* and the trailing elements have frame numbers -1, -2, -3, -4, etc.
|
|
7
|
+
* To fix this, we instead reduce the number of samples to not go into negative territory.
|
|
8
|
+
*/
|
|
9
|
+
const getNumberOfSamples = ({ shutterFraction, samples, currentFrame, }) => {
|
|
10
|
+
const maxOffset = shutterFraction * samples;
|
|
11
|
+
const maxTimeReverse = currentFrame - maxOffset;
|
|
12
|
+
const factor = Math.min(1, Math.max(0, maxTimeReverse / maxOffset + 1));
|
|
13
|
+
return Math.max(1, Math.round(Math.min(factor * samples, samples)));
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* @description Produces natural looking motion blur similar to what would be produced by a film camera.
|
|
17
|
+
* @see [Documentation](https://www.remotion.dev/docs/motion-blur/camera-motion-blur)
|
|
18
|
+
*/
|
|
19
|
+
const CameraMotionBlur = ({ children, shutterAngle = 180, samples = 10, }) => {
|
|
20
|
+
const currentFrame = useCurrentFrame();
|
|
21
|
+
if (typeof samples !== 'number' ||
|
|
22
|
+
Number.isNaN(samples) ||
|
|
23
|
+
!Number.isFinite(samples)) {
|
|
24
|
+
throw new TypeError(`"samples" must be a number, but got ${JSON.stringify(samples)}`);
|
|
25
|
+
}
|
|
26
|
+
if (samples % 1 !== 0) {
|
|
27
|
+
throw new TypeError(`"samples" must be an integer, but got ${JSON.stringify(samples)}`);
|
|
28
|
+
}
|
|
29
|
+
if (samples < 0) {
|
|
30
|
+
throw new TypeError(`"samples" must be non-negative, but got ${JSON.stringify(samples)}`);
|
|
31
|
+
}
|
|
32
|
+
if (typeof shutterAngle !== 'number' ||
|
|
33
|
+
Number.isNaN(shutterAngle) ||
|
|
34
|
+
!Number.isFinite(shutterAngle)) {
|
|
35
|
+
throw new TypeError(`"shutterAngle" must be a number, but got ${JSON.stringify(shutterAngle)}`);
|
|
36
|
+
}
|
|
37
|
+
if (shutterAngle < 0 || shutterAngle > 360) {
|
|
38
|
+
throw new TypeError(`"shutterAngle" must be between 0 and 360, but got ${JSON.stringify(shutterAngle)}`);
|
|
39
|
+
}
|
|
40
|
+
const shutterFraction = shutterAngle / 360;
|
|
41
|
+
const actualSamples = getNumberOfSamples({
|
|
42
|
+
currentFrame,
|
|
43
|
+
samples,
|
|
44
|
+
shutterFraction,
|
|
45
|
+
});
|
|
46
|
+
return (jsx(AbsoluteFill, { style: { isolation: 'isolate' }, children: new Array(actualSamples).fill(true).map((_, i) => {
|
|
47
|
+
const sample = i + 1;
|
|
48
|
+
const sampleFrameOffset = shutterFraction * (sample / actualSamples);
|
|
49
|
+
return (jsx(AbsoluteFill, { style: {
|
|
50
|
+
mixBlendMode: 'plus-lighter',
|
|
51
|
+
filter: `opacity(${1 / actualSamples})`,
|
|
52
|
+
}, children: jsx(Freeze, { frame: currentFrame - sampleFrameOffset + 1, children: children }) }, `frame-${i.toString()}`));
|
|
53
|
+
}) }));
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @description The <Trail> component duplicates it's children and adds a time offset to each layer in order to create a trail effect.
|
|
58
|
+
* @see [Documentation](https://www.remotion.dev/docs/motion-blur/trail)
|
|
59
|
+
*/
|
|
60
|
+
const Trail = ({ children, layers, lagInFrames, trailOpacity, }) => {
|
|
61
|
+
const frame = useCurrentFrame();
|
|
62
|
+
if (typeof layers !== 'number' ||
|
|
63
|
+
Number.isNaN(layers) ||
|
|
64
|
+
!Number.isFinite(layers)) {
|
|
65
|
+
throw new TypeError(`"layers" must be a number, but got ${JSON.stringify(layers)}`);
|
|
66
|
+
}
|
|
67
|
+
if (layers % 1 !== 0) {
|
|
68
|
+
throw new TypeError(`"layers" must be an integer, but got ${JSON.stringify(layers)}`);
|
|
69
|
+
}
|
|
70
|
+
if (layers < 0) {
|
|
71
|
+
throw new TypeError(`"layers" must be non-negative, but got ${JSON.stringify(layers)}`);
|
|
72
|
+
}
|
|
73
|
+
if (typeof trailOpacity !== 'number' ||
|
|
74
|
+
Number.isNaN(trailOpacity) ||
|
|
75
|
+
!Number.isFinite(trailOpacity)) {
|
|
76
|
+
throw new TypeError(`"trailOpacity" must be a number, but got ${JSON.stringify(trailOpacity)}`);
|
|
77
|
+
}
|
|
78
|
+
if (typeof lagInFrames !== 'number' ||
|
|
79
|
+
Number.isNaN(lagInFrames) ||
|
|
80
|
+
!Number.isFinite(lagInFrames)) {
|
|
81
|
+
throw new TypeError(`"lagInFrames" must be a number, but got ${JSON.stringify(lagInFrames)}`);
|
|
82
|
+
}
|
|
83
|
+
return (jsxs(AbsoluteFill, { children: [new Array(layers).fill(true).map((_, i) => {
|
|
84
|
+
return (jsx(AbsoluteFill, { style: {
|
|
85
|
+
opacity: trailOpacity - ((layers - i) / layers) * trailOpacity,
|
|
86
|
+
}, children: jsx(Freeze, { frame: frame - lagInFrames * (layers - i), children: children }) }, `frame-${i.toString()}`));
|
|
87
|
+
}), children] }));
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export { CameraMotionBlur, Trail };
|
package/package.json
CHANGED
|
@@ -1,49 +1,61 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
2
|
+
"name": "@remotion/motion-blur",
|
|
3
|
+
"version": "4.1.0-alpha2",
|
|
4
|
+
"description": "Motion blur effect for Remotion",
|
|
5
|
+
"main": "dist/cjs/index.js",
|
|
6
|
+
"types": "dist/cjs/index.d.ts",
|
|
7
|
+
"module": "dist/esm/index.mjs",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"author": "Matt McGillivray, Ilija Boshkov <ilija@codechem.com>, Jonny Burger <jonny@remotion.dev>",
|
|
10
|
+
"contributors": [],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"repository": {
|
|
13
|
+
"url": "https://github.com/remotion-dev/remotion"
|
|
14
|
+
},
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/remotion-dev/remotion/issues"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"remotion": "4.1.0-alpha2"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"react": ">=16.8.0",
|
|
23
|
+
"react-dom": ">=16.8.0"
|
|
24
|
+
},
|
|
25
|
+
"exports": {
|
|
26
|
+
"./package.json": "./package.json",
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/cjs/index.d.ts",
|
|
29
|
+
"module": "./dist/esm/index.mjs",
|
|
30
|
+
"import": "./dist/esm/index.mjs",
|
|
31
|
+
"require": "./dist/cjs/index.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@jonny/eslint-config": "3.0.266",
|
|
36
|
+
"@rollup/plugin-typescript": "^8.2.0",
|
|
37
|
+
"@types/react": "18.0.26",
|
|
38
|
+
"eslint": "8.42.0",
|
|
39
|
+
"prettier": "^2.7.1",
|
|
40
|
+
"prettier-plugin-organize-imports": "^2.3.4",
|
|
41
|
+
"react": "18.0.0",
|
|
42
|
+
"react-dom": "18.0.0",
|
|
43
|
+
"rollup": "^2.70.1",
|
|
44
|
+
"typescript": "4.9.5",
|
|
45
|
+
"remotion": "4.1.0-alpha2"
|
|
46
|
+
},
|
|
47
|
+
"keywords": [
|
|
48
|
+
"remotion",
|
|
49
|
+
"motion",
|
|
50
|
+
"blur"
|
|
51
|
+
],
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"formatting": "prettier src --check",
|
|
57
|
+
"lint": "eslint src --ext ts,tsx",
|
|
58
|
+
"watch": "tsc -w",
|
|
59
|
+
"build": "rollup --config rollup.config.js && tsc -d"
|
|
60
|
+
}
|
|
61
|
+
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// rollup.config.js
|
|
2
|
+
import typescript from '@rollup/plugin-typescript';
|
|
3
|
+
|
|
4
|
+
export default [
|
|
5
|
+
{
|
|
6
|
+
input: 'src/index.ts',
|
|
7
|
+
output: [
|
|
8
|
+
{
|
|
9
|
+
file: 'dist/esm/index.mjs',
|
|
10
|
+
format: 'es',
|
|
11
|
+
sourcemap: false,
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
external: ['react', 'remotion', 'react/jsx-runtime'],
|
|
15
|
+
plugins: [
|
|
16
|
+
typescript({
|
|
17
|
+
tsconfig: 'tsconfig-esm.json',
|
|
18
|
+
sourceMap: false,
|
|
19
|
+
outputToFilesystem: true,
|
|
20
|
+
}),
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../tsconfig-esm.settings.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"rootDir": "./src",
|
|
5
|
+
"outDir": "./dist/esm",
|
|
6
|
+
"skipLibCheck": true,
|
|
7
|
+
"jsx": "react-jsx",
|
|
8
|
+
"moduleResolution": "node"
|
|
9
|
+
},
|
|
10
|
+
"references": [{"path": "../core"}],
|
|
11
|
+
"include": ["./src"]
|
|
12
|
+
}
|
package/.prettierrc.js
DELETED
package/dist/MotionBlur.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import type { TrailProps } from './Trail';
|
|
3
|
-
export declare type MotionBlurProps = Omit<TrailProps, 'trailOpacity'> & {
|
|
4
|
-
blurOpacity: number;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* @deprecated The component has been renamed "Trail" instead: https://remotion.dev/docs/motion-blur/trail
|
|
8
|
-
*/
|
|
9
|
-
export declare const MotionBlur: React.FC<MotionBlurProps>;
|
package/dist/MotionBlur.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MotionBlur = void 0;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const Trail_1 = require("./Trail");
|
|
6
|
-
/**
|
|
7
|
-
* @deprecated The component has been renamed "Trail" instead: https://remotion.dev/docs/motion-blur/trail
|
|
8
|
-
*/
|
|
9
|
-
const MotionBlur = ({ blurOpacity, ...rest }) => {
|
|
10
|
-
if (typeof blurOpacity !== 'number' ||
|
|
11
|
-
Number.isNaN(blurOpacity) ||
|
|
12
|
-
!Number.isFinite(blurOpacity)) {
|
|
13
|
-
throw new TypeError(`"blurOpacity" must be a number, but got ${JSON.stringify(blurOpacity)}`);
|
|
14
|
-
}
|
|
15
|
-
return (0, jsx_runtime_1.jsx)(Trail_1.Trail, { ...rest, trailOpacity: blurOpacity });
|
|
16
|
-
};
|
|
17
|
-
exports.MotionBlur = MotionBlur;
|
package/dist/Trail.d.ts
DELETED
package/tsconfig.json
DELETED