remotion 3.3.92 → 3.3.93

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.
@@ -32,6 +32,11 @@ declare type EnhancedTSequenceData = {
32
32
  startMediaFrom: number;
33
33
  playbackRate: number;
34
34
  };
35
+ export declare type LoopDisplay = {
36
+ numberOfTimes: number;
37
+ startOffset: number;
38
+ durationInFrames: number;
39
+ };
35
40
  export declare type TSequence = {
36
41
  from: number;
37
42
  duration: number;
@@ -41,7 +46,7 @@ export declare type TSequence = {
41
46
  rootId: string;
42
47
  showInTimeline: boolean;
43
48
  nonce: number;
44
- showLoopTimesInTimeline: number | undefined;
49
+ loopDisplay: LoopDisplay | undefined;
45
50
  } & EnhancedTSequenceData;
46
51
  export declare type TAsset = {
47
52
  type: 'audio' | 'video';
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import type { LoopDisplay } from './CompositionManager.js';
2
3
  export declare type LayoutAndStyle = {
3
4
  layout: 'none';
4
5
  } | {
@@ -12,7 +13,7 @@ export declare type SequenceProps = {
12
13
  durationInFrames?: number;
13
14
  name?: string;
14
15
  showInTimeline?: boolean;
15
- showLoopTimesInTimeline?: number;
16
+ loopDisplay?: LoopDisplay;
16
17
  } & LayoutAndStyle;
17
18
  /**
18
19
  * @description A component that time-shifts its children and wraps them in an absolutely positioned <div>.
@@ -11,7 +11,7 @@ const nonce_js_1 = require("./nonce.js");
11
11
  const SequenceContext_js_1 = require("./SequenceContext.js");
12
12
  const timeline_position_state_js_1 = require("./timeline-position-state.js");
13
13
  const use_video_config_js_1 = require("./use-video-config.js");
14
- const SequenceRefForwardingFunction = ({ from = 0, durationInFrames = Infinity, children, name, showInTimeline = true, showLoopTimesInTimeline, ...other }, ref) => {
14
+ const SequenceRefForwardingFunction = ({ from = 0, durationInFrames = Infinity, children, name, showInTimeline = true, loopDisplay, ...other }, ref) => {
15
15
  const { layout = 'absolute-fill' } = other;
16
16
  const [id] = (0, react_1.useState)(() => String(Math.random()));
17
17
  const parentSequence = (0, react_1.useContext)(SequenceContext_js_1.SequenceContext);
@@ -81,7 +81,7 @@ const SequenceRefForwardingFunction = ({ from = 0, durationInFrames = Infinity,
81
81
  rootId,
82
82
  showInTimeline,
83
83
  nonce,
84
- showLoopTimesInTimeline,
84
+ loopDisplay,
85
85
  });
86
86
  return () => {
87
87
  unregisterSequence(id);
@@ -99,7 +99,7 @@ const SequenceRefForwardingFunction = ({ from = 0, durationInFrames = Infinity,
99
99
  from,
100
100
  showInTimeline,
101
101
  nonce,
102
- showLoopTimesInTimeline,
102
+ loopDisplay,
103
103
  environment,
104
104
  ]);
105
105
  const endThreshold = cumulatedFrom + from + durationInFrames - 1;
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Loop = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
5
6
  const Sequence_js_1 = require("../Sequence.js");
7
+ const use_current_frame_js_1 = require("../use-current-frame.js");
6
8
  const use_video_config_js_1 = require("../use-video-config.js");
7
9
  const validate_duration_in_frames_js_1 = require("../validation/validate-duration-in-frames.js");
8
10
  /**
@@ -10,6 +12,7 @@ const validate_duration_in_frames_js_1 = require("../validation/validate-duratio
10
12
  * @see [Documentation](https://www.remotion.dev/docs/loop)
11
13
  */
12
14
  const Loop = ({ durationInFrames, times = Infinity, children, name, ...props }) => {
15
+ const currentFrame = (0, use_current_frame_js_1.useCurrentFrame)();
13
16
  const { durationInFrames: compDuration } = (0, use_video_config_js_1.useVideoConfig)();
14
17
  (0, validate_duration_in_frames_js_1.validateDurationInFrames)({
15
18
  durationInFrames,
@@ -28,10 +31,16 @@ const Loop = ({ durationInFrames, times = Infinity, children, name, ...props })
28
31
  const maxTimes = Math.ceil(compDuration / durationInFrames);
29
32
  const actualTimes = Math.min(maxTimes, times);
30
33
  const style = props.layout === 'none' ? undefined : props.style;
31
- return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: new Array(actualTimes).fill(true).map((_, i) => {
32
- return ((0, jsx_runtime_1.jsx)(Sequence_js_1.Sequence
33
- // eslint-disable-next-line react/no-array-index-key
34
- , { durationInFrames: durationInFrames, from: i * durationInFrames, name: name, showLoopTimesInTimeline: actualTimes, showInTimeline: i === 0, layout: props.layout, style: style, children: children }, `loop-${i}`));
35
- }) }));
34
+ const maxFrame = durationInFrames * (actualTimes - 1);
35
+ const start = Math.floor(currentFrame / durationInFrames) * durationInFrames;
36
+ const from = Math.min(start, maxFrame);
37
+ const loopDisplay = (0, react_1.useMemo)(() => {
38
+ return {
39
+ numberOfTimes: actualTimes,
40
+ startOffset: -from,
41
+ durationInFrames,
42
+ };
43
+ }, [actualTimes, durationInFrames, from]);
44
+ return ((0, jsx_runtime_1.jsx)(Sequence_js_1.Sequence, { durationInFrames: durationInFrames, from: from, name: name, loopDisplay: loopDisplay, layout: props.layout, style: style, children: children }));
36
45
  };
37
46
  exports.Loop = Loop;
@@ -84,7 +84,7 @@ const useMediaInTimeline = ({ volume, mediaVolume, mediaRef, src, mediaType, pla
84
84
  nonce,
85
85
  startMediaFrom: 0 - startsAt,
86
86
  doesVolumeChange,
87
- showLoopTimesInTimeline: undefined,
87
+ loopDisplay: undefined,
88
88
  playbackRate,
89
89
  });
90
90
  return () => {
@@ -1 +1 @@
1
- export declare const VERSION = "3.3.92";
1
+ export declare const VERSION = "3.3.93";
@@ -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.92';
5
+ exports.VERSION = '3.3.93';
@@ -58,7 +58,7 @@ function truthy(value) {
58
58
  }
59
59
 
60
60
  // Automatically generated on publish
61
- const VERSION = '3.3.92';
61
+ const VERSION = '3.3.93';
62
62
 
63
63
  const checkMultipleRemotionVersions = () => {
64
64
  if (typeof globalThis === 'undefined') {
@@ -666,7 +666,7 @@ const useVideoConfig = () => {
666
666
  return videoConfig;
667
667
  };
668
668
 
669
- const SequenceRefForwardingFunction = ({ from = 0, durationInFrames = Infinity, children, name, showInTimeline = true, showLoopTimesInTimeline, ...other }, ref) => {
669
+ const SequenceRefForwardingFunction = ({ from = 0, durationInFrames = Infinity, children, name, showInTimeline = true, loopDisplay, ...other }, ref) => {
670
670
  const { layout = 'absolute-fill' } = other;
671
671
  const [id] = useState(() => String(Math.random()));
672
672
  const parentSequence = useContext(SequenceContext);
@@ -736,7 +736,7 @@ const SequenceRefForwardingFunction = ({ from = 0, durationInFrames = Infinity,
736
736
  rootId,
737
737
  showInTimeline,
738
738
  nonce,
739
- showLoopTimesInTimeline,
739
+ loopDisplay,
740
740
  });
741
741
  return () => {
742
742
  unregisterSequence(id);
@@ -754,7 +754,7 @@ const SequenceRefForwardingFunction = ({ from = 0, durationInFrames = Infinity,
754
754
  from,
755
755
  showInTimeline,
756
756
  nonce,
757
- showLoopTimesInTimeline,
757
+ loopDisplay,
758
758
  environment,
759
759
  ]);
760
760
  const endThreshold = cumulatedFrom + from + durationInFrames - 1;
@@ -781,6 +781,26 @@ const SequenceRefForwardingFunction = ({ from = 0, durationInFrames = Infinity,
781
781
  */
782
782
  const Sequence = forwardRef(SequenceRefForwardingFunction);
783
783
 
784
+ /**
785
+ * @description Get the current frame of the video. Frames are 0-indexed, meaning the first frame is 0, the last frame is the duration of the composition in frames minus one.
786
+ * @see [Documentation](https://remotion.dev/docs/use-current-frame)
787
+ */
788
+ const useCurrentFrame = () => {
789
+ const canUseRemotionHooks = useContext(CanUseRemotionHooks);
790
+ if (!canUseRemotionHooks) {
791
+ if (typeof window !== 'undefined' && window.remotion_isPlayer) {
792
+ throw new Error(`useCurrentFrame can only be called inside a component that was passed to <Player>. See: https://www.remotion.dev/docs/player/examples`);
793
+ }
794
+ throw new Error(`useCurrentFrame() can only be called inside a component that was registered as a composition. See https://www.remotion.dev/docs/the-fundamentals#defining-compositions`);
795
+ }
796
+ const frame = useTimelinePosition();
797
+ const context = useContext(SequenceContext);
798
+ const contextOffset = context
799
+ ? context.cumulatedFrom + context.relativeFrom
800
+ : 0;
801
+ return frame - contextOffset;
802
+ };
803
+
784
804
  const validateDurationInFrames = ({ allowFloats, component, durationInFrames, }) => {
785
805
  if (typeof durationInFrames !== 'number') {
786
806
  throw new Error(`The "durationInFrames" prop ${component} must be a number, but you passed a value of type ${typeof durationInFrames}`);
@@ -801,6 +821,7 @@ const validateDurationInFrames = ({ allowFloats, component, durationInFrames, })
801
821
  * @see [Documentation](https://www.remotion.dev/docs/loop)
802
822
  */
803
823
  const Loop = ({ durationInFrames, times = Infinity, children, name, ...props }) => {
824
+ const currentFrame = useCurrentFrame();
804
825
  const { durationInFrames: compDuration } = useVideoConfig();
805
826
  validateDurationInFrames({
806
827
  durationInFrames,
@@ -819,11 +840,17 @@ const Loop = ({ durationInFrames, times = Infinity, children, name, ...props })
819
840
  const maxTimes = Math.ceil(compDuration / durationInFrames);
820
841
  const actualTimes = Math.min(maxTimes, times);
821
842
  const style = props.layout === 'none' ? undefined : props.style;
822
- return (jsx(Fragment, { children: new Array(actualTimes).fill(true).map((_, i) => {
823
- return (jsx(Sequence
824
- // eslint-disable-next-line react/no-array-index-key
825
- , { durationInFrames: durationInFrames, from: i * durationInFrames, name: name, showLoopTimesInTimeline: actualTimes, showInTimeline: i === 0, layout: props.layout, style: style, children: children }, `loop-${i}`));
826
- }) }));
843
+ const maxFrame = durationInFrames * (actualTimes - 1);
844
+ const start = Math.floor(currentFrame / durationInFrames) * durationInFrames;
845
+ const from = Math.min(start, maxFrame);
846
+ const loopDisplay = useMemo(() => {
847
+ return {
848
+ numberOfTimes: actualTimes,
849
+ startOffset: -from,
850
+ durationInFrames,
851
+ };
852
+ }, [actualTimes, durationInFrames, from]);
853
+ return (jsx(Sequence, { durationInFrames: durationInFrames, from: from, name: name, loopDisplay: loopDisplay, layout: props.layout, style: style, children: children }));
827
854
  };
828
855
 
829
856
  const validateMediaProps = (props, component) => {
@@ -1067,26 +1094,6 @@ const random = (seed, dummy) => {
1067
1094
  throw new Error('random() argument must be a number or a string');
1068
1095
  };
1069
1096
 
1070
- /**
1071
- * @description Get the current frame of the video. Frames are 0-indexed, meaning the first frame is 0, the last frame is the duration of the composition in frames minus one.
1072
- * @see [Documentation](https://remotion.dev/docs/use-current-frame)
1073
- */
1074
- const useCurrentFrame = () => {
1075
- const canUseRemotionHooks = useContext(CanUseRemotionHooks);
1076
- if (!canUseRemotionHooks) {
1077
- if (typeof window !== 'undefined' && window.remotion_isPlayer) {
1078
- throw new Error(`useCurrentFrame can only be called inside a component that was passed to <Player>. See: https://www.remotion.dev/docs/player/examples`);
1079
- }
1080
- throw new Error(`useCurrentFrame() can only be called inside a component that was registered as a composition. See https://www.remotion.dev/docs/the-fundamentals#defining-compositions`);
1081
- }
1082
- const frame = useTimelinePosition();
1083
- const context = useContext(SequenceContext);
1084
- const contextOffset = context
1085
- ? context.cumulatedFrom + context.relativeFrom
1086
- : 0;
1087
- return frame - contextOffset;
1088
- };
1089
-
1090
1097
  const useMediaStartsAt = () => {
1091
1098
  var _a;
1092
1099
  const parentSequence = useContext(SequenceContext);
@@ -1248,7 +1255,7 @@ const useMediaInTimeline = ({ volume, mediaVolume, mediaRef, src, mediaType, pla
1248
1255
  nonce,
1249
1256
  startMediaFrom: 0 - startsAt,
1250
1257
  doesVolumeChange,
1251
- showLoopTimesInTimeline: undefined,
1258
+ loopDisplay: undefined,
1252
1259
  playbackRate,
1253
1260
  });
1254
1261
  return () => {
@@ -1,4 +1,4 @@
1
1
  // Automatically generated on publish
2
- const VERSION = '3.3.92';
2
+ const VERSION = '3.3.93';
3
3
 
4
4
  export { VERSION };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remotion",
3
- "version": "3.3.92",
3
+ "version": "3.3.93",
4
4
  "description": "Render videos in React",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/cjs/index.d.ts",
@@ -1,15 +0,0 @@
1
- import React from 'react';
2
- declare type Props = Record<string, object>;
3
- export declare type EditorPropsContextType = {
4
- props: Props;
5
- updateProps: (options: {
6
- id: string;
7
- defaultProps: object;
8
- newProps: object;
9
- }) => void;
10
- };
11
- export declare const EditorPropsContext: React.Context<EditorPropsContextType>;
12
- export declare const EditorPropsProvider: React.FC<{
13
- children: React.ReactNode;
14
- }>;
15
- export {};
@@ -1,53 +0,0 @@
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.EditorPropsProvider = exports.EditorPropsContext = void 0;
27
- const jsx_runtime_1 = require("react/jsx-runtime");
28
- const react_1 = __importStar(require("react"));
29
- exports.EditorPropsContext = (0, react_1.createContext)({
30
- props: {},
31
- updateProps: () => {
32
- throw new Error('Not implemented');
33
- },
34
- });
35
- const EditorPropsProvider = ({ children }) => {
36
- const [props, setProps] = react_1.default.useState({});
37
- const updateProps = (0, react_1.useCallback)(({ defaultProps, id, newProps, }) => {
38
- setProps((prev) => {
39
- var _a;
40
- return {
41
- ...prev,
42
- [id]: typeof newProps === 'function'
43
- ? newProps((_a = prev[id]) !== null && _a !== void 0 ? _a : defaultProps)
44
- : newProps,
45
- };
46
- });
47
- }, []);
48
- const ctx = (0, react_1.useMemo)(() => {
49
- return { props, updateProps };
50
- }, [props, updateProps]);
51
- return ((0, jsx_runtime_1.jsx)(exports.EditorPropsContext.Provider, { value: ctx, children: children }));
52
- };
53
- exports.EditorPropsProvider = EditorPropsProvider;
@@ -1,10 +0,0 @@
1
- import type { z } from 'zod';
2
- export declare type PropsIfHasProps<Schema extends z.ZodTypeAny, Props> = z.ZodTypeAny extends Schema ? {} extends Props ? {
3
- defaultProps?: Props;
4
- } : {
5
- defaultProps: Props;
6
- } : {} extends Props ? {
7
- defaultProps: z.infer<Schema>;
8
- } : {
9
- defaultProps: z.infer<Schema> & Props;
10
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,9 +0,0 @@
1
- import { z } from 'zod';
2
- export declare const REMOTION_COLOR_BRAND = "__remotion-color";
3
- export declare const parseColor: (value: string) => {
4
- a: number;
5
- r: number;
6
- g: number;
7
- b: number;
8
- };
9
- export declare const zColor: () => z.ZodEffects<z.ZodString, string, string>;
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.zColor = exports.parseColor = exports.REMOTION_COLOR_BRAND = void 0;
4
- const zod_1 = require("zod");
5
- const interpolate_colors_js_1 = require("./interpolate-colors.js");
6
- exports.REMOTION_COLOR_BRAND = '__remotion-color';
7
- const parseColor = (value) => {
8
- const colored = (0, interpolate_colors_js_1.processColor)(value).toString(16).padStart(8, '0');
9
- const opacity = parseInt(colored.slice(0, 2), 16);
10
- const r = parseInt(colored.slice(2, 4), 16);
11
- const g = parseInt(colored.slice(4, 6), 16);
12
- const b = parseInt(colored.slice(6, 8), 16);
13
- return { a: opacity, r, g, b };
14
- };
15
- exports.parseColor = parseColor;
16
- const zColor = () => zod_1.z
17
- .string()
18
- .refine((value) => {
19
- try {
20
- (0, exports.parseColor)(value);
21
- return true;
22
- }
23
- catch (err) {
24
- return false;
25
- }
26
- }, { message: 'Invalid color' })
27
- .describe(exports.REMOTION_COLOR_BRAND);
28
- exports.zColor = zColor;