remotion 3.3.36 → 3.3.37

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.
@@ -34,9 +34,11 @@ const Composition = ({ width, height, fps, durationInFrames, id, defaultProps, .
34
34
  const video = (0, use_video_1.useVideo)();
35
35
  const lazy = (0, use_lazy_component_1.useLazyComponent)(compProps);
36
36
  const nonce = (0, nonce_1.useNonce)();
37
+ const environment = (0, get_environment_1.useRemotionEnvironment)();
37
38
  const canUseComposition = (0, react_1.useContext)(internals_1.Internals.CanUseRemotionHooks);
38
39
  if (canUseComposition) {
39
- if (typeof window !== 'undefined' && window.remotion_isPlayer) {
40
+ if (environment === 'player-development' ||
41
+ environment === 'player-production') {
40
42
  throw new Error('<Composition> was mounted inside the `component` that was passed to the <Player>. See https://remotion.dev/docs/wrong-composition-mount for help.');
41
43
  }
42
44
  throw new Error('<Composition> mounted inside another composition. See https://remotion.dev/docs/wrong-composition-mount for help.');
@@ -81,16 +83,12 @@ const Composition = ({ width, height, fps, durationInFrames, id, defaultProps, .
81
83
  nonce,
82
84
  parentName,
83
85
  ]);
84
- if ((0, get_environment_1.getRemotionEnvironment)() === 'preview' &&
85
- video &&
86
- video.component === lazy) {
86
+ if (environment === 'preview' && video && video.component === lazy) {
87
87
  const Comp = lazy;
88
88
  const inputProps = (0, input_props_1.getInputProps)();
89
89
  return (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsx)(exports.ClipComposition, { children: (0, jsx_runtime_1.jsx)(CanUseRemotionHooks_1.CanUseRemotionHooksProvider, { children: (0, jsx_runtime_1.jsx)(react_1.Suspense, { fallback: (0, jsx_runtime_1.jsx)(loading_indicator_1.Loading, {}), children: (0, jsx_runtime_1.jsx)(Comp, { ...defaultProps, ...inputProps }) }) }) }), (0, portal_node_1.portalNode)());
90
90
  }
91
- if ((0, get_environment_1.getRemotionEnvironment)() === 'rendering' &&
92
- video &&
93
- video.component === lazy) {
91
+ if (environment === 'rendering' && video && video.component === lazy) {
94
92
  const Comp = lazy;
95
93
  const inputProps = (0, input_props_1.getInputProps)();
96
94
  return (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsx)(CanUseRemotionHooks_1.CanUseRemotionHooksProvider, { children: (0, jsx_runtime_1.jsx)(react_1.Suspense, { fallback: (0, jsx_runtime_1.jsx)(Fallback, {}), children: (0, jsx_runtime_1.jsx)(Comp, { ...defaultProps, ...inputProps }) }) }), (0, portal_node_1.portalNode)());
package/dist/Img.js CHANGED
@@ -8,6 +8,7 @@ const get_environment_1 = require("./get-environment");
8
8
  const prefetch_1 = require("./prefetch");
9
9
  const ImgRefForwarding = ({ onError, src, ...props }, ref) => {
10
10
  const imageRef = (0, react_1.useRef)(null);
11
+ const environment = (0, get_environment_1.useRemotionEnvironment)();
11
12
  (0, react_1.useImperativeHandle)(ref, () => {
12
13
  return imageRef.current;
13
14
  }, []);
@@ -22,7 +23,7 @@ const ImgRefForwarding = ({ onError, src, ...props }, ref) => {
22
23
  }
23
24
  }, [onError]);
24
25
  // If image source switches, make new handle
25
- if ((0, get_environment_1.getRemotionEnvironment)() === 'rendering') {
26
+ if (environment === 'rendering') {
26
27
  // eslint-disable-next-line react-hooks/rules-of-hooks
27
28
  (0, react_1.useLayoutEffect)(() => {
28
29
  if (process.env.NODE_ENV === 'test') {
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import type { Layer } from './layers';
3
+ export declare const LayerMaster: <T extends object>({ layers, defaultProps, inputProps, fallbackComponent: FallbackComponent, }: {
4
+ layers: Layer<T>[];
5
+ defaultProps: T | undefined;
6
+ inputProps: any;
7
+ fallbackComponent: React.FC | null;
8
+ }) => JSX.Element;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LayerMaster = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const AbsoluteFill_1 = require("./AbsoluteFill");
7
+ const get_environment_1 = require("./get-environment");
8
+ const LayerMaster = ({ layers, defaultProps, inputProps, fallbackComponent: FallbackComponent, }) => {
9
+ return (
10
+ // TODO: Same styles as normal
11
+ (0, jsx_runtime_1.jsx)(AbsoluteFill_1.AbsoluteFill, { children: layers.map((layer, i) => {
12
+ const Comp = layer.component;
13
+ if (layer.type === 'web') {
14
+ if (FallbackComponent === null) {
15
+ // eslint-disable-next-line react/no-array-index-key
16
+ return (0, jsx_runtime_1.jsx)(Comp, { ...defaultProps, ...inputProps }, String(i));
17
+ }
18
+ return (
19
+ // eslint-disable-next-line react/no-array-index-key
20
+ (0, jsx_runtime_1.jsx)(react_1.Suspense, { fallback: (0, jsx_runtime_1.jsx)(FallbackComponent, {}), children: (0, jsx_runtime_1.jsx)(Comp, { ...defaultProps, ...inputProps }) }, String(i)));
21
+ }
22
+ // SVG should not support suspense
23
+ if (layer.type === 'svg') {
24
+ if ((0, get_environment_1.getRemotionEnvironment)() === 'rendering') {
25
+ return null;
26
+ }
27
+ return ((0, jsx_runtime_1.jsx)(AbsoluteFill_1.AbsoluteFill, { children: (0, jsx_runtime_1.jsx)(Comp, { ...defaultProps, ...inputProps }, String(i)) }));
28
+ }
29
+ if (layer.type === 'video') {
30
+ if ((0, get_environment_1.getRemotionEnvironment)() === 'rendering') {
31
+ return null;
32
+ }
33
+ // TODO: AbsoluteFill is different flex direction
34
+ return ((0, jsx_runtime_1.jsx)(AbsoluteFill_1.AbsoluteFill, { children: (0, jsx_runtime_1.jsx)(Comp, { ...defaultProps, ...inputProps }, String(i)) }));
35
+ }
36
+ throw new Error('Unknown layer type');
37
+ }) }));
38
+ };
39
+ exports.LayerMaster = LayerMaster;
@@ -0,0 +1,5 @@
1
+ import type { PropsWithChildren } from 'react';
2
+ import React from 'react';
3
+ export declare const Satori: React.FC<PropsWithChildren>;
4
+ export declare const SatoriForRendering: React.FC<PropsWithChildren>;
5
+ export declare const SatoriForDevelopment: React.FC<PropsWithChildren>;
package/dist/Satori.js ADDED
@@ -0,0 +1,92 @@
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.SatoriForDevelopment = exports.SatoriForRendering = exports.Satori = void 0;
30
+ const jsx_runtime_1 = require("react/jsx-runtime");
31
+ const react_1 = __importStar(require("react"));
32
+ const satori_1 = __importDefault(require("satori"));
33
+ const _1 = require(".");
34
+ const get_environment_1 = require("./get-environment");
35
+ const NativeLayers_1 = require("./NativeLayers");
36
+ const use_video_config_1 = require("./use-video-config");
37
+ const Satori = ({ children }) => {
38
+ if ((0, get_environment_1.getRemotionEnvironment)() === 'rendering') {
39
+ return (0, jsx_runtime_1.jsx)(exports.SatoriForRendering, { children: children });
40
+ }
41
+ return (0, jsx_runtime_1.jsx)(exports.SatoriForDevelopment, { children: children });
42
+ };
43
+ exports.Satori = Satori;
44
+ const SatoriForRendering = ({ children }) => {
45
+ const { width, height } = (0, use_video_config_1.useVideoConfig)();
46
+ const { setSatoriStack } = (0, react_1.useContext)(NativeLayers_1.NativeLayersContext);
47
+ (0, react_1.useLayoutEffect)(() => {
48
+ const handle = (0, _1.delayRender)();
49
+ (0, satori_1.default)(children, {
50
+ width,
51
+ height,
52
+ fonts: [],
53
+ })
54
+ .then((svg) => {
55
+ (0, _1.continueRender)(handle);
56
+ setSatoriStack(svg);
57
+ console.log({ svg });
58
+ })
59
+ .catch((err) => {
60
+ console.log(err);
61
+ });
62
+ }, [children, height, setSatoriStack, width]);
63
+ return (0, jsx_runtime_1.jsx)(_1.Experimental.Null, {});
64
+ };
65
+ exports.SatoriForRendering = SatoriForRendering;
66
+ const SatoriForDevelopment = ({ children, }) => {
67
+ const [markup, setMarkup] = react_1.default.useState(null);
68
+ const { width, height } = (0, use_video_config_1.useVideoConfig)();
69
+ (0, react_1.useEffect)(() => {
70
+ (0, satori_1.default)(children, {
71
+ width,
72
+ height,
73
+ fonts: [],
74
+ })
75
+ .then((svg) => {
76
+ setMarkup(svg);
77
+ console.log({ svg });
78
+ })
79
+ .catch((err) => {
80
+ console.log(err);
81
+ });
82
+ }, [children, height, width]);
83
+ if (!markup) {
84
+ return null;
85
+ }
86
+ return ((0, jsx_runtime_1.jsx)("div", {
87
+ // eslint-disable-next-line react/no-danger
88
+ dangerouslySetInnerHTML: {
89
+ __html: markup,
90
+ } }));
91
+ };
92
+ exports.SatoriForDevelopment = SatoriForDevelopment;
package/dist/Sequence.js CHANGED
@@ -20,6 +20,7 @@ const SequenceRefForwardingFunction = ({ from = 0, durationInFrames = Infinity,
20
20
  ? parentSequence.cumulatedFrom + parentSequence.relativeFrom
21
21
  : 0;
22
22
  const nonce = (0, nonce_1.useNonce)();
23
+ const environment = (0, get_environment_1.useRemotionEnvironment)();
23
24
  if (layout !== 'absolute-fill' && layout !== 'none') {
24
25
  throw new TypeError(`The layout prop of <Sequence /> expects either "absolute-fill" or "none", but you passed: ${layout}`);
25
26
  }
@@ -71,7 +72,7 @@ const SequenceRefForwardingFunction = ({ from = 0, durationInFrames = Infinity,
71
72
  }, [children, name]);
72
73
  (0, react_1.useEffect)(() => {
73
74
  var _a;
74
- if ((0, get_environment_1.getRemotionEnvironment)() !== 'preview') {
75
+ if (environment !== 'preview') {
75
76
  return;
76
77
  }
77
78
  registerSequence({
@@ -103,6 +104,7 @@ const SequenceRefForwardingFunction = ({ from = 0, durationInFrames = Infinity,
103
104
  showInTimeline,
104
105
  nonce,
105
106
  showLoopTimesInTimeline,
107
+ environment,
106
108
  ]);
107
109
  const endThreshold = cumulatedFrom + from + durationInFrames - 1;
108
110
  const content = absoluteFrame < cumulatedFrom + from
@@ -19,6 +19,7 @@ const AudioRefForwardingFunction = (props, ref) => {
19
19
  const { startFrom, endAt, ...otherProps } = props;
20
20
  const { loop, ...propsOtherThanLoop } = props;
21
21
  const { fps } = (0, use_video_config_1.useVideoConfig)();
22
+ const environment = (0, get_environment_1.useRemotionEnvironment)();
22
23
  const { durations, setDurations } = (0, react_1.useContext)(duration_state_1.DurationsContext);
23
24
  if (typeof props.src !== 'string') {
24
25
  throw new TypeError(`The \`<Audio>\` tag requires a string for \`src\`, but got ${JSON.stringify(props.src)} instead.`);
@@ -43,7 +44,7 @@ const AudioRefForwardingFunction = (props, ref) => {
43
44
  return ((0, jsx_runtime_1.jsx)(Sequence_1.Sequence, { layout: "none", from: 0 - startFromFrameNo, showInTimeline: false, durationInFrames: endAtFrameNo, children: (0, jsx_runtime_1.jsx)(exports.Audio, { ...otherProps, ref: ref }) }));
44
45
  }
45
46
  (0, validate_media_props_1.validateMediaProps)(props, 'Audio');
46
- if ((0, get_environment_1.getRemotionEnvironment)() === 'rendering') {
47
+ if (environment === 'rendering') {
47
48
  return ((0, jsx_runtime_1.jsx)(AudioForRendering_1.AudioForRendering, { onDuration: onDuration, ...props, ref: ref, onError: onError }));
48
49
  }
49
50
  return ((0, jsx_runtime_1.jsx)(AudioForDevelopment_1.AudioForDevelopment, { shouldPreMountAudioTags: audioContext !== null && audioContext.numberOfAudioTags > 0, ...props, ref: ref, onError: onError, onDuration: onDuration }));
@@ -20,6 +20,7 @@ const AudioForRenderingRefForwardingFunction = (props, ref) => {
20
20
  const frame = (0, use_current_frame_1.useCurrentFrame)();
21
21
  const sequenceContext = (0, react_1.useContext)(Sequence_1.SequenceContext);
22
22
  const { registerAsset, unregisterAsset } = (0, react_1.useContext)(CompositionManager_1.CompositionManager);
23
+ const environment = (0, get_environment_1.useRemotionEnvironment)();
23
24
  // Generate a string that's as unique as possible for this asset
24
25
  // but at the same time the same on all threads
25
26
  const id = (0, react_1.useMemo)(() => {
@@ -77,7 +78,7 @@ const AudioForRenderingRefForwardingFunction = (props, ref) => {
77
78
  ]);
78
79
  const { src, onDuration } = props;
79
80
  // If audio source switches, make new handle
80
- if ((0, get_environment_1.getRemotionEnvironment)() === 'rendering') {
81
+ if (environment === 'rendering') {
81
82
  // eslint-disable-next-line react-hooks/rules-of-hooks
82
83
  (0, react_1.useLayoutEffect)(() => {
83
84
  if (process.env.NODE_ENV === 'test') {
@@ -0,0 +1,3 @@
1
+ import type { ComponentType } from 'react';
2
+ import type { TCompMetadata } from './CompositionManager';
3
+ export declare const getCompositionsFromMarkup: (Comp: ComponentType) => TCompMetadata[];
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCompositionsFromMarkup = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const server_1 = require("react-dom/server");
6
+ const Composition_1 = require("./Composition");
7
+ const getCompositionsFromMarkup = (Comp) => {
8
+ // TODO: Is this still necessary?
9
+ process.env.REMOTION_SERVER_RENDERING = 'true';
10
+ const str = (0, server_1.renderToString)((0, jsx_runtime_1.jsx)(Composition_1.GetCompositionsFromMarkupModeProvider, { children: (0, jsx_runtime_1.jsx)(Comp, {}) }));
11
+ const matches = str.matchAll(/<div>(.*?)<\/div>/g);
12
+ const metadata = [];
13
+ for (const match of matches) {
14
+ const json = JSON.parse(match[1]);
15
+ metadata.push(json);
16
+ }
17
+ return metadata;
18
+ };
19
+ exports.getCompositionsFromMarkup = getCompositionsFromMarkup;
@@ -1,2 +1,3 @@
1
1
  export declare type RemotionEnvironment = 'preview' | 'rendering' | 'player-development' | 'player-production';
2
2
  export declare const getRemotionEnvironment: () => RemotionEnvironment;
3
+ export declare const useRemotionEnvironment: () => RemotionEnvironment;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRemotionEnvironment = void 0;
3
+ exports.useRemotionEnvironment = exports.getRemotionEnvironment = void 0;
4
+ const is_player_1 = require("./is-player");
4
5
  const getRemotionEnvironment = () => {
5
6
  if (process.env.NODE_ENV === 'production') {
6
7
  if (typeof window !== 'undefined' && window.remotion_isPlayer) {
@@ -20,3 +21,14 @@ const getRemotionEnvironment = () => {
20
21
  return 'preview';
21
22
  };
22
23
  exports.getRemotionEnvironment = getRemotionEnvironment;
24
+ const useRemotionEnvironment = () => {
25
+ const isPlayer = (0, is_player_1.useIsPlayer)();
26
+ if (isPlayer) {
27
+ if (process.env.NODE_ENV === 'production') {
28
+ return 'player-production';
29
+ }
30
+ return 'player-development';
31
+ }
32
+ return (0, exports.getRemotionEnvironment)();
33
+ };
34
+ exports.useRemotionEnvironment = useRemotionEnvironment;
package/dist/index.d.ts CHANGED
@@ -85,4 +85,5 @@ export declare const Experimental: {
85
85
  y: number;
86
86
  }>;
87
87
  Null: import("react").FC<{}>;
88
+ useIsPlayer: () => boolean;
88
89
  };
package/dist/index.js CHANGED
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.Experimental = exports.useCurrentFrame = exports.staticFile = exports.Series = exports.Sequence = exports.registerRoot = exports.random = exports.prefetch = exports.Loop = exports.interpolateColors = exports.getStaticFiles = exports.getInputProps = exports.Config = void 0;
18
18
  require("./asset-types");
19
19
  const Clipper_1 = require("./Clipper");
20
+ const is_player_1 = require("./is-player");
20
21
  const multiple_versions_warning_1 = require("./multiple-versions-warning");
21
22
  const Null_1 = require("./Null");
22
23
  (0, multiple_versions_warning_1.checkMultipleRemotionVersions)();
@@ -64,4 +65,5 @@ __exportStar(require("./video-config"), exports);
64
65
  exports.Experimental = {
65
66
  Clipper: Clipper_1.Clipper,
66
67
  Null: Null_1.Null,
68
+ useIsPlayer: is_player_1.useIsPlayer,
67
69
  };
@@ -86,6 +86,11 @@ export declare const Internals: {
86
86
  DurationsContextProvider: import("react").FC<{
87
87
  children: import("react").ReactNode;
88
88
  }>;
89
+ IsPlayerContextProvider: import("react").FC<{
90
+ children?: import("react").ReactNode;
91
+ }>;
92
+ useIsPlayer: () => boolean;
93
+ useRemotionEnvironment: () => RemotionEnvironment;
89
94
  };
90
95
  declare type WebpackConfiguration = Configuration;
91
96
  declare type WebpackOverrideFn = (currentConfiguration: WebpackConfiguration) => WebpackConfiguration;
package/dist/internals.js CHANGED
@@ -32,6 +32,7 @@ const CSSUtils = __importStar(require("./default-css"));
32
32
  const delay_render_1 = require("./delay-render");
33
33
  const get_environment_1 = require("./get-environment");
34
34
  const get_preview_dom_element_1 = require("./get-preview-dom-element");
35
+ const is_player_1 = require("./is-player");
35
36
  const portal_node_1 = require("./portal-node");
36
37
  const prefetch_state_1 = require("./prefetch-state");
37
38
  const register_root_1 = require("./register-root");
@@ -92,4 +93,7 @@ exports.Internals = {
92
93
  enableLegacyRemotionConfig: config_1.enableLegacyRemotionConfig,
93
94
  PrefetchProvider: prefetch_state_1.PrefetchProvider,
94
95
  DurationsContextProvider: duration_state_1.DurationsContextProvider,
96
+ IsPlayerContextProvider: is_player_1.IsPlayerContextProvider,
97
+ useIsPlayer: is_player_1.useIsPlayer,
98
+ useRemotionEnvironment: get_environment_1.useRemotionEnvironment,
95
99
  };
@@ -0,0 +1,3 @@
1
+ import type { PropsWithChildren } from 'react';
2
+ export declare const IsPlayerContextProvider: React.FC<PropsWithChildren>;
3
+ export declare const useIsPlayer: () => boolean;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useIsPlayer = exports.IsPlayerContextProvider = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const IsPlayerContext = (0, react_1.createContext)(false);
7
+ const IsPlayerContextProvider = ({ children, }) => {
8
+ return (0, jsx_runtime_1.jsx)(IsPlayerContext.Provider, { value: true, children: children });
9
+ };
10
+ exports.IsPlayerContextProvider = IsPlayerContextProvider;
11
+ const useIsPlayer = () => {
12
+ return (0, react_1.useContext)(IsPlayerContext);
13
+ };
14
+ exports.useIsPlayer = useIsPlayer;
@@ -0,0 +1,24 @@
1
+ import type { ComponentType, LazyExoticComponent } from 'react';
2
+ import React from 'react';
3
+ export declare type LooseComponentType<T> = ComponentType<T> | ((props: T) => React.ReactNode);
4
+ export declare type InputLayer<T> = {
5
+ component: LooseComponentType<T>;
6
+ type: 'web' | 'svg' | 'video';
7
+ };
8
+ export declare type CompProps<T> = {
9
+ lazyComponent: () => Promise<{
10
+ default: LooseComponentType<T>;
11
+ }>;
12
+ } | {
13
+ component: LooseComponentType<T>;
14
+ } | {
15
+ layers: InputLayer<T>[];
16
+ };
17
+ export declare type Layer<T> = {
18
+ component: LazyExoticComponent<ComponentType<T>>;
19
+ type: 'web' | 'svg' | 'video';
20
+ };
21
+ export declare type SmallLayer = Pick<Layer<unknown>, 'type'>;
22
+ export declare const convertComponentTypesToLayers: <T>(compProps: CompProps<T>) => Layer<T>[];
23
+ export declare const convertComponentTypesToLayersWithCache: <T>(compProps: CompProps<T>, prevCompProps: CompProps<T> | null, prevReturnValue: Layer<T>[] | null) => Layer<T>[];
24
+ export declare const useLayers: <T>(compProps: CompProps<T>) => Layer<T>[];
package/dist/layers.js ADDED
@@ -0,0 +1,149 @@
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.useLayers = exports.convertComponentTypesToLayersWithCache = exports.convertComponentTypesToLayers = void 0;
27
+ const react_1 = __importStar(require("react"));
28
+ const inputLayersToLayers = (layers) => {
29
+ return layers.map((layer) => {
30
+ if (layer.type === 'web') {
31
+ return {
32
+ component: react_1.default.lazy(() => Promise.resolve({ default: layer.component })),
33
+ type: 'web',
34
+ };
35
+ }
36
+ // No lazy for Video allowed!
37
+ if (layer.type === 'video') {
38
+ return {
39
+ component: layer.component,
40
+ type: 'video',
41
+ };
42
+ }
43
+ // No lazy for SVG allowed!
44
+ return {
45
+ component: layer.component,
46
+ type: 'svg',
47
+ };
48
+ });
49
+ };
50
+ const convertComponentTypesToLayers = (compProps) => {
51
+ if ('component' in compProps) {
52
+ // In SSR, suspense is not yet supported, we cannot use React.lazy
53
+ if (typeof document === 'undefined') {
54
+ return [
55
+ {
56
+ component: compProps.component,
57
+ type: 'web',
58
+ },
59
+ ];
60
+ }
61
+ return [
62
+ {
63
+ component: react_1.default.lazy(() => Promise.resolve({ default: compProps.component })),
64
+ type: 'web',
65
+ },
66
+ ];
67
+ }
68
+ if ('lazyComponent' in compProps) {
69
+ return [
70
+ {
71
+ component: react_1.default.lazy(compProps.lazyComponent),
72
+ type: 'web',
73
+ },
74
+ ];
75
+ }
76
+ if ('layers' in compProps) {
77
+ return inputLayersToLayers(compProps.layers);
78
+ }
79
+ throw new Error('Unknown component type');
80
+ };
81
+ exports.convertComponentTypesToLayers = convertComponentTypesToLayers;
82
+ const convertComponentTypesToLayersWithCache = (compProps, prevCompProps, prevReturnValue) => {
83
+ if ('component' in compProps) {
84
+ if (prevCompProps &&
85
+ 'component' in prevCompProps &&
86
+ compProps.component === prevCompProps.component &&
87
+ prevReturnValue) {
88
+ return prevReturnValue;
89
+ }
90
+ return [
91
+ {
92
+ type: 'web',
93
+ component: react_1.default.lazy(() => Promise.resolve({ default: compProps.component })),
94
+ },
95
+ ];
96
+ }
97
+ if ('lazyComponent' in compProps) {
98
+ if (prevCompProps &&
99
+ 'lazyComponent' in prevCompProps &&
100
+ compProps.lazyComponent === prevCompProps.lazyComponent &&
101
+ prevReturnValue) {
102
+ return prevReturnValue;
103
+ }
104
+ return [
105
+ {
106
+ type: 'web',
107
+ component: react_1.default.lazy(compProps.lazyComponent),
108
+ },
109
+ ];
110
+ }
111
+ if ('layers' in compProps) {
112
+ const isTheSame = () => {
113
+ if (!prevCompProps) {
114
+ return false;
115
+ }
116
+ if (!('layers' in prevCompProps)) {
117
+ return false;
118
+ }
119
+ if (compProps.layers.length !== prevCompProps.layers.length) {
120
+ return false;
121
+ }
122
+ for (let i = 0; i < compProps.layers.length; i++) {
123
+ if (compProps.layers[i].component !== prevCompProps.layers[i].component) {
124
+ return false;
125
+ }
126
+ if (compProps.layers[i].type !== prevCompProps.layers[i].type) {
127
+ return false;
128
+ }
129
+ }
130
+ return true;
131
+ };
132
+ if (isTheSame()) {
133
+ return prevReturnValue;
134
+ }
135
+ return inputLayersToLayers(compProps.layers);
136
+ }
137
+ throw new Error('Unknown component type');
138
+ };
139
+ exports.convertComponentTypesToLayersWithCache = convertComponentTypesToLayersWithCache;
140
+ const useLayers = (compProps) => {
141
+ var _a, _b;
142
+ const prevCompProps = (0, react_1.useRef)();
143
+ const prevLayers = (0, react_1.useRef)();
144
+ const layers = (0, exports.convertComponentTypesToLayersWithCache)(compProps, (_a = prevCompProps.current) !== null && _a !== void 0 ? _a : null, (_b = prevLayers.current) !== null && _b !== void 0 ? _b : null);
145
+ prevCompProps.current = compProps;
146
+ prevLayers.current = layers;
147
+ return layers;
148
+ };
149
+ exports.useLayers = useLayers;
@@ -37,6 +37,7 @@ const useMediaInTimeline = ({ volume, mediaVolume, mediaRef, src, mediaType, pla
37
37
  ? Math.min(parentSequence.durationInFrames, videoConfig.durationInFrames)
38
38
  : videoConfig.durationInFrames;
39
39
  const doesVolumeChange = typeof volume === 'function';
40
+ const environment = (0, get_environment_1.useRemotionEnvironment)();
40
41
  const volumes = (0, react_1.useMemo)(() => {
41
42
  if (typeof volume === 'number') {
42
43
  return volume;
@@ -66,8 +67,7 @@ const useMediaInTimeline = ({ volume, mediaVolume, mediaRef, src, mediaType, pla
66
67
  if (!src) {
67
68
  throw new Error('No src passed');
68
69
  }
69
- if ((0, get_environment_1.getRemotionEnvironment)() !== 'preview' &&
70
- process.env.NODE_ENV !== 'test') {
70
+ if (environment !== 'preview' && process.env.NODE_ENV !== 'test') {
71
71
  return;
72
72
  }
73
73
  registerSequence({
@@ -107,6 +107,7 @@ const useMediaInTimeline = ({ volume, mediaVolume, mediaRef, src, mediaType, pla
107
107
  mediaType,
108
108
  startsAt,
109
109
  playbackRate,
110
+ environment,
110
111
  ]);
111
112
  (0, react_1.useEffect)(() => {
112
113
  const tag = {
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useVideoConfig = void 0;
4
4
  const react_1 = require("react");
5
5
  const CanUseRemotionHooks_1 = require("./CanUseRemotionHooks");
6
+ const is_player_1 = require("./is-player");
6
7
  const use_unsafe_video_config_1 = require("./use-unsafe-video-config");
7
8
  /**
8
9
  * Get some info about the context of the video that you are making.
@@ -12,8 +13,10 @@ const use_unsafe_video_config_1 = require("./use-unsafe-video-config");
12
13
  const useVideoConfig = () => {
13
14
  const videoConfig = (0, use_unsafe_video_config_1.useUnsafeVideoConfig)();
14
15
  const context = (0, react_1.useContext)(CanUseRemotionHooks_1.CanUseRemotionHooks);
16
+ const isPlayer = (0, is_player_1.useIsPlayer)();
15
17
  if (!videoConfig) {
16
- if (typeof window !== 'undefined' && window.remotion_isPlayer) {
18
+ if ((typeof window !== 'undefined' && window.remotion_isPlayer) ||
19
+ isPlayer) {
17
20
  throw new Error('No video config found. You are probably calling useVideoConfig() from outside the component passed to <Player />. See https://www.remotion.dev/docs/player/examples for how to set up the Player correctly.');
18
21
  }
19
22
  throw new Error('No video config found. You are probably calling useVideoConfig() from a component which has not been registered as a <Composition />. See https://www.remotion.dev/docs/the-fundamentals#defining-compositions for more information.');
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "3.3.36";
1
+ export declare const VERSION = "3.3.37";
package/dist/version.js CHANGED
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  // Automatically generated on publish
5
- exports.VERSION = '3.3.36';
5
+ exports.VERSION = '3.3.37';
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import type { RemotionMainVideoProps } from './props';
3
+ export declare const NativeVideo: React.FC<{
4
+ src: string;
5
+ } & RemotionMainVideoProps>;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NativeVideo = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const get_environment_1 = require("../get-environment");
7
+ const Sequence_1 = require("../Sequence");
8
+ const validate_media_props_1 = require("../validate-media-props");
9
+ const validate_start_from_props_1 = require("../validate-start-from-props");
10
+ const NativeVideoForRendering_1 = require("./NativeVideoForRendering");
11
+ const VideoForDevelopment_1 = require("./VideoForDevelopment");
12
+ const NativeVideo = (props) => {
13
+ const { startFrom, endAt, ...otherProps } = props;
14
+ const onDuration = (0, react_1.useCallback)(() => undefined, []);
15
+ if (typeof props.src !== 'string') {
16
+ throw new TypeError(`The \`<NativeVideo>\` tag requires a string for \`src\`, but got ${JSON.stringify(props.src)} instead.`);
17
+ }
18
+ if (typeof startFrom !== 'undefined' || typeof endAt !== 'undefined') {
19
+ (0, validate_start_from_props_1.validateStartFromProps)(startFrom, endAt);
20
+ const startFromFrameNo = startFrom !== null && startFrom !== void 0 ? startFrom : 0;
21
+ const endAtFrameNo = endAt !== null && endAt !== void 0 ? endAt : Infinity;
22
+ return ((0, jsx_runtime_1.jsx)(Sequence_1.Sequence, { layout: "none", from: 0 - startFromFrameNo, showInTimeline: false, durationInFrames: endAtFrameNo, children: (0, jsx_runtime_1.jsx)(exports.NativeVideo, { ...otherProps }) }));
23
+ }
24
+ (0, validate_media_props_1.validateMediaProps)(props, 'Video');
25
+ if ((0, get_environment_1.getRemotionEnvironment)() === 'rendering') {
26
+ throw new Error('Cannot render in the browser');
27
+ }
28
+ if ((0, get_environment_1.getRemotionEnvironment)() === 'server-rendering') {
29
+ return (0, jsx_runtime_1.jsx)(NativeVideoForRendering_1.NativeVideoForRendering, { ...otherProps });
30
+ }
31
+ return ((0, jsx_runtime_1.jsx)(VideoForDevelopment_1.VideoForDevelopment, { onDuration: onDuration, onlyWarnForMediaSeekingError: true, ...otherProps }));
32
+ };
33
+ exports.NativeVideo = NativeVideo;
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ export declare type NativeVideoLayerInfo = {
3
+ src: string;
4
+ frame: number;
5
+ };
6
+ export declare const NativeVideoForRendering: React.FC<{
7
+ src: string;
8
+ }>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NativeVideoForRendering = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const use_current_frame_1 = require("../use-current-frame");
6
+ const NativeVideoForRendering = ({ src }) => {
7
+ const frame = (0, use_current_frame_1.useCurrentFrame)();
8
+ return ((0, jsx_runtime_1.jsx)("div", {
9
+ // eslint-disable-next-line react/no-danger
10
+ dangerouslySetInnerHTML: {
11
+ __html: JSON.stringify({ src, frame }),
12
+ } }));
13
+ };
14
+ exports.NativeVideoForRendering = NativeVideoForRendering;
@@ -12,6 +12,7 @@ const OffthreadVideoForRendering_1 = require("./OffthreadVideoForRendering");
12
12
  const VideoForDevelopment_1 = require("./VideoForDevelopment");
13
13
  const OffthreadVideo = (props) => {
14
14
  const { startFrom, endAt, ...otherProps } = props;
15
+ const environment = (0, get_environment_1.useRemotionEnvironment)();
15
16
  const onDuration = (0, react_1.useCallback)(() => undefined, []);
16
17
  if (typeof props.src !== 'string') {
17
18
  throw new TypeError(`The \`<OffthreadVideo>\` tag requires a string for \`src\`, but got ${JSON.stringify(props.src)} instead.`);
@@ -24,7 +25,7 @@ const OffthreadVideo = (props) => {
24
25
  }
25
26
  (0, validate_media_props_1.validateMediaProps)(props, 'Video');
26
27
  (0, validate_offthreadvideo_image_format_1.validateOffthreadVideoImageFormat)(props.imageFormat);
27
- if ((0, get_environment_1.getRemotionEnvironment)() === 'rendering') {
28
+ if (environment === 'rendering') {
28
29
  return (0, jsx_runtime_1.jsx)(OffthreadVideoForRendering_1.OffthreadVideoForRendering, { ...otherProps });
29
30
  }
30
31
  return ((0, jsx_runtime_1.jsx)(VideoForDevelopment_1.VideoForDevelopment, { onDuration: onDuration, onlyWarnForMediaSeekingError: true, ...otherProps }));
@@ -17,6 +17,7 @@ const VideoForwardingFunction = (props, ref) => {
17
17
  const { startFrom, endAt, ...otherProps } = props;
18
18
  const { loop, ...propsOtherThanLoop } = props;
19
19
  const { fps } = (0, use_video_config_1.useVideoConfig)();
20
+ const environment = (0, get_environment_1.useRemotionEnvironment)();
20
21
  const { durations, setDurations } = (0, react_1.useContext)(duration_state_1.DurationsContext);
21
22
  if (typeof ref === 'string') {
22
23
  throw new Error('string refs are not supported');
@@ -40,7 +41,7 @@ const VideoForwardingFunction = (props, ref) => {
40
41
  return ((0, jsx_runtime_1.jsx)(Sequence_1.Sequence, { layout: "none", from: 0 - startFromFrameNo, showInTimeline: false, durationInFrames: endAtFrameNo, children: (0, jsx_runtime_1.jsx)(exports.Video, { ...otherProps, ref: ref }) }));
41
42
  }
42
43
  (0, validate_media_props_1.validateMediaProps)(props, 'Video');
43
- if ((0, get_environment_1.getRemotionEnvironment)() === 'rendering') {
44
+ if (environment === 'rendering') {
44
45
  return ((0, jsx_runtime_1.jsx)(VideoForRendering_1.VideoForRendering, { onDuration: onDuration, ...otherProps, ref: ref }));
45
46
  }
46
47
  return ((0, jsx_runtime_1.jsx)(VideoForDevelopment_1.VideoForDevelopment, { onlyWarnForMediaSeekingError: false, ...otherProps, ref: ref, onDuration: onDuration }));
@@ -25,6 +25,7 @@ const VideoForRenderingForwardFunction = ({ onError, volume: volumeProp, allowAm
25
25
  const videoRef = (0, react_1.useRef)(null);
26
26
  const sequenceContext = (0, react_1.useContext)(Sequence_1.SequenceContext);
27
27
  const mediaStartsAt = (0, use_audio_frame_1.useMediaStartsAt)();
28
+ const environment = (0, get_environment_1.useRemotionEnvironment)();
28
29
  const { registerAsset, unregisterAsset } = (0, react_1.useContext)(CompositionManager_1.CompositionManager);
29
30
  // Generate a string that's as unique as possible for this asset
30
31
  // but at the same time the same on all threads
@@ -169,7 +170,7 @@ const VideoForRenderingForwardFunction = ({ onError, volume: volumeProp, allowAm
169
170
  ]);
170
171
  const { src } = props;
171
172
  // If video source switches, make new handle
172
- if ((0, get_environment_1.getRemotionEnvironment)() === 'rendering') {
173
+ if (environment === 'rendering') {
173
174
  // eslint-disable-next-line react-hooks/rules-of-hooks
174
175
  (0, react_1.useLayoutEffect)(() => {
175
176
  if (process.env.NODE_ENV === 'test') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remotion",
3
- "version": "3.3.36",
3
+ "version": "3.3.37",
4
4
  "description": "Render videos in React",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -65,5 +65,5 @@
65
65
  ]
66
66
  }
67
67
  },
68
- "gitHead": "623bf1e883e7b26b9d02458037c930ccbe8857e4"
68
+ "gitHead": "ead6bdacc14a9953cae738159c49bf3daf09e9b0"
69
69
  }