@remotion/player 4.0.533 → 4.0.535

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -52,6 +52,7 @@ export type PlayerProps<Schema extends AnyZodObject, Props extends Record<string
52
52
  readonly showPlaybackRateControl?: boolean | number[];
53
53
  readonly posterFillMode?: PosterFillMode;
54
54
  readonly bufferStateDelayInMilliseconds?: number;
55
+ readonly defaultPremountInSeconds?: number;
55
56
  readonly hideControlsWhenPointerDoesntMove?: boolean | number;
56
57
  readonly overflowVisible?: boolean;
57
58
  readonly browserMediaControlsBehavior?: BrowserMediaControlsBehavior;
@@ -59,15 +59,22 @@ const componentOrNullIfLazy = (props) => {
59
59
  };
60
60
  exports.componentOrNullIfLazy = componentOrNullIfLazy;
61
61
  const TimelineSequenceObserverComponent = ({ onTimelineSequenceChange }) => {
62
- const sequences = remotion_1.Internals.useSequenceManagerSequences();
63
- (0, react_1.useEffect)(() => {
64
- onTimelineSequenceChange(sequences);
65
- }, [onTimelineSequenceChange, sequences]);
62
+ const registry = react_1.default.useContext(remotion_1.Internals.SequenceRegistryContext);
63
+ (0, react_1.useLayoutEffect)(() => {
64
+ if (registry === null) {
65
+ throw new Error('Timeline sequence observer requires a sequence registry');
66
+ }
67
+ const publish = () => onTimelineSequenceChange(registry.getSnapshot());
68
+ const unsubscribe = registry.subscribe(publish);
69
+ publish();
70
+ return unsubscribe;
71
+ }, [onTimelineSequenceChange, registry]);
66
72
  return null;
67
73
  };
68
74
  const PlayerFn = ({ durationInFrames, compositionHeight, compositionWidth, fps, inputProps, style, controls = false, loop = false, autoPlay = false, showVolumeControls = true, allowFullscreen = true, clickToPlay, doubleClickToFullscreen = false, spaceKeyToPlayOrPause = true, moveToBeginningWhenEnded = true, numberOfSharedAudioTags = no_react_1.NoReactInternals.ENABLE_V5_BREAKING_CHANGES
69
75
  ? 0
70
- : 5, errorFallback = () => '⚠️', playbackRate = 1, renderLoading, className, showPosterWhenUnplayed, showPosterWhenEnded, showPosterWhenPaused, showPosterWhenBuffering, showPosterWhenBufferingAndPaused, initialFrame, renderPoster, inFrame, outFrame, initiallyShowControls, renderFullscreenButton, renderPlayPauseButton, renderVolumeSlider, renderCustomControls, alwaysShowControls = false, initiallyMuted = false, showPlaybackRateControl = false, posterFillMode = 'player-size', bufferStateDelayInMilliseconds, hideControlsWhenPointerDoesntMove = true, overflowVisible = false, renderMuteButton, browserMediaControlsBehavior: passedBrowserMediaControlsBehavior, overrideInternalClassName, logLevel = 'info', noSuspense, acknowledgeRemotionLicense, audioLatencyHint = 'playback', sampleRate = 48000, volumePersistenceKey, initialVolume, _experimentalKeepAudioContextAlive = false, ...componentProps }, ref) => {
76
+ : 5, errorFallback = () => '⚠️', playbackRate = 1, renderLoading, className, showPosterWhenUnplayed, showPosterWhenEnded, showPosterWhenPaused, showPosterWhenBuffering, showPosterWhenBufferingAndPaused, initialFrame, renderPoster, inFrame, outFrame, initiallyShowControls, renderFullscreenButton, renderPlayPauseButton, renderVolumeSlider, renderCustomControls, alwaysShowControls = false, initiallyMuted = false, showPlaybackRateControl = false, posterFillMode = 'player-size', bufferStateDelayInMilliseconds, defaultPremountInSeconds = no_react_1.NoReactInternals.DEFAULT_PREMOUNT_IN_SECONDS, hideControlsWhenPointerDoesntMove = true, overflowVisible = false, renderMuteButton, browserMediaControlsBehavior: passedBrowserMediaControlsBehavior, overrideInternalClassName, logLevel = 'info', noSuspense, acknowledgeRemotionLicense, audioLatencyHint = 'playback', sampleRate = 48000, volumePersistenceKey, initialVolume, _experimentalKeepAudioContextAlive = false, ...componentProps }, ref) => {
77
+ no_react_1.NoReactInternals.validateDefaultPremountInSeconds(defaultPremountInSeconds);
71
78
  if (typeof window !== 'undefined') {
72
79
  window.remotion_isPlayer = true;
73
80
  }
@@ -251,11 +258,8 @@ const PlayerFn = ({ durationInFrames, compositionHeight, compositionWidth, fps,
251
258
  const player = (jsx_runtime_1.jsx(remotion_1.Internals.IsPlayerContextProvider, { children: jsx_runtime_1.jsx(remotion_1.Internals.SetTimelineContext.Provider, { value: setTimelineContextValue, children: jsx_runtime_1.jsx(SharedPlayerContext_js_1.SharedPlayerContexts, { timelineContext: timelineContextValue, playbackRateContext: playbackRateContextValue, component: component, compositionHeight: compositionHeight, compositionWidth: compositionWidth, durationInFrames: durationInFrames, fps: fps, numberOfSharedAudioTags: numberOfSharedAudioTags, initiallyMuted: initiallyMuted, logLevel: logLevel, audioLatencyHint: audioLatencyHint, sampleRate: sampleRate, _experimentalKeepAudioContextAlive: _experimentalKeepAudioContextAlive, volumePersistenceKey: volumePersistenceKey, initialVolume: initialVolume, inputProps: actualInputProps, audioEnabled: true, children: jsx_runtime_1.jsx(EmitterProvider_js_1.PlayerEmitterProvider, { currentPlaybackRate: currentPlaybackRate, children: jsx_runtime_1.jsx(PlayerUI_js_1.default, { ref: rootRef, posterFillMode: posterFillMode, renderLoading: renderLoading, autoPlay: Boolean(autoPlay), loop: Boolean(loop), controls: Boolean(controls), errorFallback: errorFallback, style: style, inputProps: actualInputProps, allowFullscreen: Boolean(allowFullscreen), moveToBeginningWhenEnded: Boolean(moveToBeginningWhenEnded), clickToPlay: typeof clickToPlay === 'boolean'
252
259
  ? clickToPlay
253
260
  : Boolean(controls), showVolumeControls: Boolean(showVolumeControls), doubleClickToFullscreen: Boolean(doubleClickToFullscreen), spaceKeyToPlayOrPause: Boolean(spaceKeyToPlayOrPause), playbackRate: currentPlaybackRate, className: className !== null && className !== void 0 ? className : undefined, showPosterWhenUnplayed: Boolean(showPosterWhenUnplayed), showPosterWhenEnded: Boolean(showPosterWhenEnded), showPosterWhenPaused: Boolean(showPosterWhenPaused), showPosterWhenBuffering: Boolean(showPosterWhenBuffering), showPosterWhenBufferingAndPaused: Boolean(showPosterWhenBufferingAndPaused), renderPoster: renderPoster, inFrame: inFrame !== null && inFrame !== void 0 ? inFrame : null, outFrame: outFrame !== null && outFrame !== void 0 ? outFrame : null, initiallyShowControls: initiallyShowControls !== null && initiallyShowControls !== void 0 ? initiallyShowControls : true, renderFullscreen: renderFullscreenButton !== null && renderFullscreenButton !== void 0 ? renderFullscreenButton : null, renderPlayPauseButton: renderPlayPauseButton !== null && renderPlayPauseButton !== void 0 ? renderPlayPauseButton : null, renderMuteButton: renderMuteButton !== null && renderMuteButton !== void 0 ? renderMuteButton : null, renderVolumeSlider: renderVolumeSlider !== null && renderVolumeSlider !== void 0 ? renderVolumeSlider : null, renderCustomControls: renderCustomControls !== null && renderCustomControls !== void 0 ? renderCustomControls : null, alwaysShowControls: alwaysShowControls, showPlaybackRateControl: showPlaybackRateControl, bufferStateDelayInMilliseconds: bufferStateDelayInMilliseconds !== null && bufferStateDelayInMilliseconds !== void 0 ? bufferStateDelayInMilliseconds : 300, hideControlsWhenPointerDoesntMove: hideControlsWhenPointerDoesntMove, overflowVisible: overflowVisible, browserMediaControlsBehavior: browserMediaControlsBehavior, overrideInternalClassName: overrideInternalClassName !== null && overrideInternalClassName !== void 0 ? overrideInternalClassName : undefined, noSuspense: Boolean(noSuspense) }) }) }) }) }));
254
- if (!onTimelineSequenceChange) {
255
- return player;
256
- }
257
- return (jsx_runtime_1.jsx(remotion_1.Internals.SequenceRegistrationContext.Provider, { value: true, children: jsx_runtime_1.jsxs(remotion_1.Internals.SequenceManagerProvider, { children: [
258
- jsx_runtime_1.jsx(TimelineSequenceObserverComponent, { onTimelineSequenceChange: onTimelineSequenceChange }), player] }) }));
261
+ return (jsx_runtime_1.jsx(remotion_1.Internals.DefaultPremountContext.Provider, { value: defaultPremountInSeconds, children: onTimelineSequenceChange ? (jsx_runtime_1.jsx(remotion_1.Internals.SequenceRegistrationContext.Provider, { value: true, children: jsx_runtime_1.jsxs(remotion_1.Internals.SequenceManagerProvider, { children: [
262
+ jsx_runtime_1.jsx(TimelineSequenceObserverComponent, { onTimelineSequenceChange: onTimelineSequenceChange }), player] }) })) : (player) }));
259
263
  };
260
264
  const forward = react_1.forwardRef;
261
265
  /*
@@ -86,6 +86,7 @@ const PlayerUI = ({ controls, style, loop, autoPlay, allowFullscreen, inputProps
86
86
  }, [player]);
87
87
  const { playerMuted, mediaVolume } = (0, react_1.useContext)(remotion_1.Internals.MediaVolumeContext);
88
88
  const canvasOverlay = (0, react_1.useContext)(canvas_overlay_context_js_1.CanvasOverlayContext);
89
+ const canvasContentRef = (0, react_1.useRef)(null);
89
90
  (0, react_1.useEffect)(() => {
90
91
  player.emitter.dispatchVolumeChange(mediaVolume);
91
92
  }, [player.emitter, mediaVolume]);
@@ -209,6 +210,7 @@ const PlayerUI = ({ controls, style, loop, autoPlay, allowFullscreen, inputProps
209
210
  });
210
211
  }, [canvasSize, config]);
211
212
  const scale = (_b = layout === null || layout === void 0 ? void 0 : layout.scale) !== null && _b !== void 0 ? _b : 1;
213
+ const canvasContent = (0, react_1.useMemo)(() => ({ rootRef: canvasContentRef, scale }), [scale]);
212
214
  const initialScaleIgnored = (0, react_1.useRef)(false);
213
215
  (0, react_1.useEffect)(() => {
214
216
  if (!initialScaleIgnored.current) {
@@ -449,11 +451,12 @@ const PlayerUI = ({ controls, style, loop, autoPlay, allowFullscreen, inputProps
449
451
  const { left, top, width, height, ...outerWithoutScale } = outer;
450
452
  const content = (jsx_runtime_1.jsxs(jsx_runtime_1.Fragment, { children: [
451
453
  jsx_runtime_1.jsxs("div", { style: outer, onPointerDown: clickToPlay ? handlePointerDown : undefined, onDoubleClick: doubleClickToFullscreen ? handleDoubleClick : undefined, children: [
452
- jsx_runtime_1.jsxs("div", { style: containerStyle, className: (0, player_css_classname_js_1.playerCssClassname)(overrideInternalClassName), children: [VideoComponent ? (jsx_runtime_1.jsx(error_boundary_js_1.ErrorBoundary, { onError: onError, errorFallback: errorFallback, children: jsx_runtime_1.jsx(remotion_1.Internals.CurrentScaleContext.Provider, { value: currentScale, children: jsx_runtime_1.jsx(canvas_overlay_context_js_1.CanvasOverlayContext.Provider, { value: null, children: jsx_runtime_1.jsx(VideoComponent, { ...((_c = video === null || video === void 0 ? void 0 : video.props) !== null && _c !== void 0 ? _c : {}), ...(inputProps !== null && inputProps !== void 0 ? inputProps : {}) }) }) }) })) : null, shouldShowPoster && posterFillMode === 'composition-size' ? (jsx_runtime_1.jsx("div", { style: {
454
+ jsx_runtime_1.jsxs("div", { ref: canvasContentRef, style: containerStyle, className: (0, player_css_classname_js_1.playerCssClassname)(overrideInternalClassName), children: [VideoComponent ? (jsx_runtime_1.jsx(error_boundary_js_1.ErrorBoundary, { onError: onError, errorFallback: errorFallback, children: jsx_runtime_1.jsx(remotion_1.Internals.CurrentScaleContext.Provider, { value: currentScale, children: jsx_runtime_1.jsx(canvas_overlay_context_js_1.CanvasOverlayContext.Provider, { value: null, children: jsx_runtime_1.jsx(VideoComponent, { ...((_c = video === null || video === void 0 ? void 0 : video.props) !== null && _c !== void 0 ? _c : {}), ...(inputProps !== null && inputProps !== void 0 ? inputProps : {}) }) }) }) })) : null, shouldShowPoster && posterFillMode === 'composition-size' ? (jsx_runtime_1.jsx("div", { style: {
453
455
  ...outerWithoutScale,
454
456
  width: config.width,
455
457
  height: config.height,
456
- }, onPointerDown: clickToPlay ? handlePointerDown : undefined, onDoubleClick: doubleClickToFullscreen ? handleDoubleClick : undefined, children: poster })) : null] }), jsx_runtime_1.jsx(license_blacklist_js_1.RenderWarningIfBlacklist, {}), canvasOverlay] }), shouldShowPoster && posterFillMode === 'player-size' ? (jsx_runtime_1.jsx("div", { style: outer, onPointerDown: clickToPlay ? handlePointerDown : undefined, onDoubleClick: doubleClickToFullscreen ? handleDoubleClick : undefined, children: poster })) : null, controls ? (jsx_runtime_1.jsx(PlayerControls_js_1.Controls, { fps: config.fps, playing: playing, toggle: toggle, durationInFrames: config.durationInFrames, containerRef: container, onFullscreenButtonClick: onFullscreenButtonClick, isFullscreen: isFullscreen, allowFullscreen: allowFullscreen, showVolumeControls: showVolumeControls, onExitFullscreenButtonClick: onExitFullscreenButtonClick, spaceKeyToPlayOrPause: spaceKeyToPlayOrPause, onSeekEnd: onSeekEnd, onSeekStart: onSeekStart, inFrame: inFrame, outFrame: outFrame, initiallyShowControls: initiallyShowControls, canvasSize: canvasSize, renderFullscreenButton: renderFullscreenButton, renderPlayPauseButton: renderPlayPauseButton, alwaysShowControls: alwaysShowControls, showPlaybackRateControl: showPlaybackRateControl, buffering: showBufferIndicator, hideControlsWhenPointerDoesntMove: hideControlsWhenPointerDoesntMove, onDoubleClick: doubleClickToFullscreen ? handleDoubleClick : undefined, onPointerDown: clickToPlay
458
+ }, onPointerDown: clickToPlay ? handlePointerDown : undefined, onDoubleClick: doubleClickToFullscreen ? handleDoubleClick : undefined, children: poster })) : null] }), jsx_runtime_1.jsx(license_blacklist_js_1.RenderWarningIfBlacklist, {}), jsx_runtime_1.jsx(canvas_overlay_context_js_1.CanvasContentContext.Provider, { value: canvasContent, children: canvasOverlay })
459
+ ] }), shouldShowPoster && posterFillMode === 'player-size' ? (jsx_runtime_1.jsx("div", { style: outer, onPointerDown: clickToPlay ? handlePointerDown : undefined, onDoubleClick: doubleClickToFullscreen ? handleDoubleClick : undefined, children: poster })) : null, controls ? (jsx_runtime_1.jsx(PlayerControls_js_1.Controls, { fps: config.fps, playing: playing, toggle: toggle, durationInFrames: config.durationInFrames, containerRef: container, onFullscreenButtonClick: onFullscreenButtonClick, isFullscreen: isFullscreen, allowFullscreen: allowFullscreen, showVolumeControls: showVolumeControls, onExitFullscreenButtonClick: onExitFullscreenButtonClick, spaceKeyToPlayOrPause: spaceKeyToPlayOrPause, onSeekEnd: onSeekEnd, onSeekStart: onSeekStart, inFrame: inFrame, outFrame: outFrame, initiallyShowControls: initiallyShowControls, canvasSize: canvasSize, renderFullscreenButton: renderFullscreenButton, renderPlayPauseButton: renderPlayPauseButton, alwaysShowControls: alwaysShowControls, showPlaybackRateControl: showPlaybackRateControl, buffering: showBufferIndicator, hideControlsWhenPointerDoesntMove: hideControlsWhenPointerDoesntMove, onDoubleClick: doubleClickToFullscreen ? handleDoubleClick : undefined, onPointerDown: clickToPlay
457
460
  ? handlePointerDown
458
461
  : undefined, renderMuteButton: renderMuteButton, renderVolumeSlider: renderVolumeSlider, renderCustomControls: renderCustomControls })) : null] }));
459
462
  if (noSuspense || (is_node_js_1.IS_NODE && !doesReactVersionSupportSuspense)) {
@@ -93,6 +93,6 @@ const SharedPlayerContexts = ({ children, timelineContext, playbackRateContext,
93
93
  isReadOnlyStudio: false,
94
94
  };
95
95
  }, []);
96
- return (jsx_runtime_1.jsx(remotion_1.Internals.RemotionEnvironmentContext.Provider, { value: env, children: jsx_runtime_1.jsx(remotion_1.Internals.LogLevelContext.Provider, { value: logLevelContext, children: jsx_runtime_1.jsx(remotion_1.Internals.CanUseRemotionHooksProvider, { children: jsx_runtime_1.jsx(remotion_1.Internals.AbsoluteTimeContext.Provider, { value: timelineContext, children: jsx_runtime_1.jsx(remotion_1.Internals.PlaybackRateContext.Provider, { value: playbackRateContext, children: jsx_runtime_1.jsx(remotion_1.Internals.TimelineContext.Provider, { value: timelineContext, children: jsx_runtime_1.jsx(remotion_1.Internals.CompositionManager.Provider, { value: compositionManagerContext, children: jsx_runtime_1.jsx(remotion_1.Internals.PrefetchProvider, { children: jsx_runtime_1.jsx(remotion_1.Internals.DurationsContextProvider, { children: jsx_runtime_1.jsx(remotion_1.Internals.MediaVolumeContext.Provider, { value: mediaVolumeContextValue, children: jsx_runtime_1.jsx(remotion_1.Internals.SetMediaVolumeContext.Provider, { value: setMediaVolumeContextValue, children: jsx_runtime_1.jsx(remotion_1.Internals.BufferingProvider, { children: jsx_runtime_1.jsx(remotion_1.Internals.SharedAudioContextProvider, { audioLatencyHint: audioLatencyHint, audioEnabled: shouldCreateAudioContext, previewSampleRate: sampleRate, _experimentalKeepAudioContextAlive: _experimentalKeepAudioContextAlive, children: jsx_runtime_1.jsx(remotion_1.Internals.SharedAudioTagsContextProvider, { numberOfAudioTags: numberOfSharedAudioTags, children: children }) }) }) }) }) }) }) }) }) }) }) }) }) }));
96
+ return (jsx_runtime_1.jsx(remotion_1.Internals.RemotionEnvironmentContext.Provider, { value: env, children: jsx_runtime_1.jsx(remotion_1.Internals.LogLevelContext.Provider, { value: logLevelContext, children: jsx_runtime_1.jsx(remotion_1.Internals.CanUseRemotionHooksProvider, { children: jsx_runtime_1.jsx(remotion_1.Internals.AbsoluteTimeContext.Provider, { value: timelineContext, children: jsx_runtime_1.jsx(remotion_1.Internals.PlaybackRateContext.Provider, { value: playbackRateContext, children: jsx_runtime_1.jsx(remotion_1.Internals.TimelineContext.Provider, { value: timelineContext, children: jsx_runtime_1.jsx(remotion_1.Internals.CompositionManager.Provider, { value: compositionManagerContext, children: jsx_runtime_1.jsx(remotion_1.Internals.VideoProvider, { children: jsx_runtime_1.jsx(remotion_1.Internals.PrefetchProvider, { children: jsx_runtime_1.jsx(remotion_1.Internals.DurationsContextProvider, { children: jsx_runtime_1.jsx(remotion_1.Internals.MediaVolumeContext.Provider, { value: mediaVolumeContextValue, children: jsx_runtime_1.jsx(remotion_1.Internals.SetMediaVolumeContext.Provider, { value: setMediaVolumeContextValue, children: jsx_runtime_1.jsx(remotion_1.Internals.BufferingProvider, { children: jsx_runtime_1.jsx(remotion_1.Internals.SharedAudioContextProvider, { audioLatencyHint: audioLatencyHint, audioEnabled: shouldCreateAudioContext, previewSampleRate: sampleRate, _experimentalKeepAudioContextAlive: _experimentalKeepAudioContextAlive, children: jsx_runtime_1.jsx(remotion_1.Internals.SharedAudioTagsContextProvider, { numberOfAudioTags: numberOfSharedAudioTags, children: children }) }) }) }) }) }) }) }) }) }) }) }) }) }) }));
97
97
  };
98
98
  exports.SharedPlayerContexts = SharedPlayerContexts;
@@ -1,2 +1,6 @@
1
- import type { ReactNode } from 'react';
1
+ import type { ReactNode, RefObject } from 'react';
2
2
  export declare const CanvasOverlayContext: import("react").Context<ReactNode>;
3
+ export declare const CanvasContentContext: import("react").Context<{
4
+ readonly rootRef: RefObject<HTMLDivElement | null>;
5
+ readonly scale: number;
6
+ } | null>;
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CanvasOverlayContext = void 0;
3
+ exports.CanvasContentContext = exports.CanvasOverlayContext = void 0;
4
4
  const react_1 = require("react");
5
5
  // Canvas supplies its authoring UI here so it shares the Player's timeline,
6
6
  // clipping and fullscreen container without wrapping the user's composition.
7
7
  exports.CanvasOverlayContext = (0, react_1.createContext)(null);
8
+ // The SDK measures against the unscaled composition and projects into the overlay.
9
+ exports.CanvasContentContext = (0, react_1.createContext)(null);
@@ -54,4 +54,8 @@ export declare const PlayerInternals: {
54
54
  }>;
55
55
  TimelineSequenceObserverContext: import("react").Context<import("./timeline-sequence-observer-context.js").TimelineSequenceObserver | null>;
56
56
  CanvasOverlayContext: import("react").Context<import("react").ReactNode>;
57
+ CanvasContentContext: import("react").Context<{
58
+ readonly rootRef: import("react").RefObject<HTMLDivElement | null>;
59
+ readonly scale: number;
60
+ } | null>;
57
61
  };
package/dist/cjs/index.js CHANGED
@@ -30,4 +30,5 @@ exports.PlayerInternals = {
30
30
  BufferingIndicator: BufferingIndicator_js_1.BufferingIndicator,
31
31
  TimelineSequenceObserverContext: timeline_sequence_observer_context_js_1.TimelineSequenceObserverContext,
32
32
  CanvasOverlayContext: canvas_overlay_context_js_1.CanvasOverlayContext,
33
+ CanvasContentContext: canvas_overlay_context_js_1.CanvasContentContext,
33
34
  };
@@ -1,4 +1,3 @@
1
- export declare const ALLOWED_GLOBAL_TIME_ANCHOR_SHIFT = 0.1;
2
1
  export declare const setGlobalTimeAnchor: ({ audioContext, audioSyncAnchor, absoluteTimeInSeconds, globalPlaybackRate, logLevel, force, }: {
3
2
  audioContext: AudioContext;
4
3
  audioSyncAnchor: {
@@ -1,16 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setGlobalTimeAnchor = exports.ALLOWED_GLOBAL_TIME_ANCHOR_SHIFT = void 0;
3
+ exports.setGlobalTimeAnchor = void 0;
4
4
  const remotion_1 = require("remotion");
5
- exports.ALLOWED_GLOBAL_TIME_ANCHOR_SHIFT = 0.1;
6
5
  const setGlobalTimeAnchor = ({ audioContext, audioSyncAnchor, absoluteTimeInSeconds, globalPlaybackRate, logLevel, force, }) => {
7
6
  const newAnchor = audioContext.currentTime - absoluteTimeInSeconds / globalPlaybackRate;
8
7
  const shift = newAnchor - audioSyncAnchor.value;
9
- const { outputLatency } = audioContext;
10
- const safeOutputLatency = outputLatency === 0 ? 0.3 : outputLatency;
11
- const latency = audioContext.baseLatency + safeOutputLatency;
8
+ const tolerance = remotion_1.Internals.getAudioSyncAnchorTolerance(audioContext);
12
9
  // Skip small shifts to avoid audio glitches from frame-quantized re-anchoring
13
- if (Math.abs(shift) < exports.ALLOWED_GLOBAL_TIME_ANCHOR_SHIFT + latency && !force) {
10
+ if (Math.abs(shift) < tolerance && !force) {
14
11
  return false;
15
12
  }
16
13
  // If force is true, but shift is zero, no change is needed
@@ -188,10 +188,14 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
188
188
  shouldLoop: loop,
189
189
  });
190
190
  framesAdvanced += framesToAdvance;
191
- if (nextFrame !== getCurrentFrame() &&
192
- (!hasEnded || moveToBeginningWhenEnded) &&
193
- !isBuffering()) {
194
- setFrameFromPlayback((c) => ({ ...c, [config.id]: nextFrame }));
191
+ // A late callback can skip the endpoint. Hold that exact frame on end.
192
+ const frameToDisplay = hasEnded && !moveToBeginningWhenEnded
193
+ ? playbackRate > 0
194
+ ? actualLastFrame
195
+ : actualFirstFrame
196
+ : nextFrame;
197
+ if (frameToDisplay !== getCurrentFrame() && !isBuffering()) {
198
+ setFrameFromPlayback((c) => ({ ...c, [config.id]: frameToDisplay }));
195
199
  }
196
200
  if (hasEnded) {
197
201
  stop();
@@ -350,6 +350,7 @@ var calculateOuter = ({
350
350
  // src/canvas-overlay-context.ts
351
351
  import { createContext as createContext2 } from "react";
352
352
  var CanvasOverlayContext = createContext2(null);
353
+ var CanvasContentContext = createContext2(null);
353
354
 
354
355
  // src/emitter-context.ts
355
356
  import React from "react";
@@ -910,7 +911,6 @@ var useIsBackgrounded = () => {
910
911
 
911
912
  // src/set-global-time-anchor.ts
912
913
  import { Internals as Internals5 } from "remotion";
913
- var ALLOWED_GLOBAL_TIME_ANCHOR_SHIFT = 0.1;
914
914
  var setGlobalTimeAnchor = ({
915
915
  audioContext,
916
916
  audioSyncAnchor,
@@ -921,10 +921,8 @@ var setGlobalTimeAnchor = ({
921
921
  }) => {
922
922
  const newAnchor = audioContext.currentTime - absoluteTimeInSeconds / globalPlaybackRate;
923
923
  const shift = newAnchor - audioSyncAnchor.value;
924
- const { outputLatency } = audioContext;
925
- const safeOutputLatency = outputLatency === 0 ? 0.3 : outputLatency;
926
- const latency = audioContext.baseLatency + safeOutputLatency;
927
- if (Math.abs(shift) < ALLOWED_GLOBAL_TIME_ANCHOR_SHIFT + latency && !force) {
924
+ const tolerance = Internals5.getAudioSyncAnchorTolerance(audioContext);
925
+ if (Math.abs(shift) < tolerance && !force) {
928
926
  return false;
929
927
  }
930
928
  if (Math.abs(shift) < Number.EPSILON) {
@@ -1100,8 +1098,9 @@ var usePlayback = ({
1100
1098
  shouldLoop: loop
1101
1099
  });
1102
1100
  framesAdvanced += framesToAdvance;
1103
- if (nextFrame !== getCurrentFrame() && (!hasEnded || moveToBeginningWhenEnded) && !isBuffering()) {
1104
- setFrameFromPlayback((c) => ({ ...c, [config.id]: nextFrame }));
1101
+ const frameToDisplay = hasEnded && !moveToBeginningWhenEnded ? playbackRate > 0 ? actualLastFrame : actualFirstFrame : nextFrame;
1102
+ if (frameToDisplay !== getCurrentFrame() && !isBuffering()) {
1103
+ setFrameFromPlayback((c) => ({ ...c, [config.id]: frameToDisplay }));
1105
1104
  }
1106
1105
  if (hasEnded) {
1107
1106
  stop();
@@ -2575,7 +2574,7 @@ if (reactVersion === "0") {
2575
2574
  var doesReactVersionSupportSuspense = parseInt(reactVersion, 10) >= 18;
2576
2575
  var PlayerUI = ({
2577
2576
  controls,
2578
- style: style2,
2577
+ style,
2579
2578
  loop,
2580
2579
  autoPlay,
2581
2580
  allowFullscreen,
@@ -2588,7 +2587,7 @@ var PlayerUI = ({
2588
2587
  playbackRate,
2589
2588
  renderLoading,
2590
2589
  renderPoster,
2591
- className: className2,
2590
+ className,
2592
2591
  moveToBeginningWhenEnded,
2593
2592
  showPosterWhenUnplayed,
2594
2593
  showPosterWhenEnded,
@@ -2643,6 +2642,7 @@ var PlayerUI = ({
2643
2642
  }, [player]);
2644
2643
  const { playerMuted, mediaVolume } = useContext4(Internals11.MediaVolumeContext);
2645
2644
  const canvasOverlay = useContext4(CanvasOverlayContext);
2645
+ const canvasContentRef = useRef10(null);
2646
2646
  useEffect12(() => {
2647
2647
  player.emitter.dispatchVolumeChange(mediaVolume);
2648
2648
  }, [player.emitter, mediaVolume]);
@@ -2751,6 +2751,7 @@ var PlayerUI = ({
2751
2751
  });
2752
2752
  }, [canvasSize, config]);
2753
2753
  const scale = layout?.scale ?? 1;
2754
+ const canvasContent = useMemo12(() => ({ rootRef: canvasContentRef, scale }), [scale]);
2754
2755
  const initialScaleIgnored = useRef10(false);
2755
2756
  useEffect12(() => {
2756
2757
  if (!initialScaleIgnored.current) {
@@ -2883,15 +2884,15 @@ var PlayerUI = ({
2883
2884
  return calculateOuterStyle({
2884
2885
  canvasSize,
2885
2886
  config,
2886
- style: style2,
2887
+ style,
2887
2888
  overflowVisible,
2888
2889
  layout
2889
2890
  });
2890
- }, [canvasSize, config, layout, overflowVisible, style2]);
2891
+ }, [canvasSize, config, layout, overflowVisible, style]);
2891
2892
  const outer = useMemo12(() => {
2892
2893
  return calculateOuter({ config, layout, scale, overflowVisible });
2893
2894
  }, [config, layout, overflowVisible, scale]);
2894
- const containerStyle3 = useMemo12(() => {
2895
+ const containerStyle = useMemo12(() => {
2895
2896
  return calculateContainerStyle({
2896
2897
  config,
2897
2898
  layout,
@@ -2981,7 +2982,8 @@ var PlayerUI = ({
2981
2982
  onDoubleClick: doubleClickToFullscreen ? handleDoubleClick : undefined,
2982
2983
  children: [
2983
2984
  /* @__PURE__ */ jsxs9("div", {
2984
- style: containerStyle3,
2985
+ ref: canvasContentRef,
2986
+ style: containerStyle,
2985
2987
  className: playerCssClassname(overrideInternalClassName),
2986
2988
  children: [
2987
2989
  VideoComponent ? /* @__PURE__ */ jsx12(ErrorBoundary, {
@@ -3011,7 +3013,10 @@ var PlayerUI = ({
3011
3013
  ]
3012
3014
  }),
3013
3015
  /* @__PURE__ */ jsx12(RenderWarningIfBlacklist, {}),
3014
- canvasOverlay
3016
+ /* @__PURE__ */ jsx12(CanvasContentContext.Provider, {
3017
+ value: canvasContent,
3018
+ children: canvasOverlay
3019
+ })
3015
3020
  ]
3016
3021
  }),
3017
3022
  shouldShowPoster && posterFillMode === "player-size" ? /* @__PURE__ */ jsx12("div", {
@@ -3056,14 +3061,14 @@ var PlayerUI = ({
3056
3061
  return /* @__PURE__ */ jsx12("div", {
3057
3062
  ref: container,
3058
3063
  style: outerStyle,
3059
- className: className2,
3064
+ className,
3060
3065
  children: content
3061
3066
  });
3062
3067
  }
3063
3068
  return /* @__PURE__ */ jsx12("div", {
3064
3069
  ref: container,
3065
3070
  style: outerStyle,
3066
- className: className2,
3071
+ className,
3067
3072
  children: /* @__PURE__ */ jsx12(Suspense, {
3068
3073
  fallback: loadingMarkup,
3069
3074
  children: content
@@ -3220,21 +3225,23 @@ var SharedPlayerContexts = ({
3220
3225
  value: timelineContext,
3221
3226
  children: /* @__PURE__ */ jsx13(Internals13.CompositionManager.Provider, {
3222
3227
  value: compositionManagerContext,
3223
- children: /* @__PURE__ */ jsx13(Internals13.PrefetchProvider, {
3224
- children: /* @__PURE__ */ jsx13(Internals13.DurationsContextProvider, {
3225
- children: /* @__PURE__ */ jsx13(Internals13.MediaVolumeContext.Provider, {
3226
- value: mediaVolumeContextValue,
3227
- children: /* @__PURE__ */ jsx13(Internals13.SetMediaVolumeContext.Provider, {
3228
- value: setMediaVolumeContextValue,
3229
- children: /* @__PURE__ */ jsx13(Internals13.BufferingProvider, {
3230
- children: /* @__PURE__ */ jsx13(Internals13.SharedAudioContextProvider, {
3231
- audioLatencyHint,
3232
- audioEnabled: shouldCreateAudioContext,
3233
- previewSampleRate: sampleRate,
3234
- _experimentalKeepAudioContextAlive,
3235
- children: /* @__PURE__ */ jsx13(Internals13.SharedAudioTagsContextProvider, {
3236
- numberOfAudioTags: numberOfSharedAudioTags,
3237
- children
3228
+ children: /* @__PURE__ */ jsx13(Internals13.VideoProvider, {
3229
+ children: /* @__PURE__ */ jsx13(Internals13.PrefetchProvider, {
3230
+ children: /* @__PURE__ */ jsx13(Internals13.DurationsContextProvider, {
3231
+ children: /* @__PURE__ */ jsx13(Internals13.MediaVolumeContext.Provider, {
3232
+ value: mediaVolumeContextValue,
3233
+ children: /* @__PURE__ */ jsx13(Internals13.SetMediaVolumeContext.Provider, {
3234
+ value: setMediaVolumeContextValue,
3235
+ children: /* @__PURE__ */ jsx13(Internals13.BufferingProvider, {
3236
+ children: /* @__PURE__ */ jsx13(Internals13.SharedAudioContextProvider, {
3237
+ audioLatencyHint,
3238
+ audioEnabled: shouldCreateAudioContext,
3239
+ previewSampleRate: sampleRate,
3240
+ _experimentalKeepAudioContextAlive,
3241
+ children: /* @__PURE__ */ jsx13(Internals13.SharedAudioTagsContextProvider, {
3242
+ numberOfAudioTags: numberOfSharedAudioTags,
3243
+ children
3244
+ })
3238
3245
  })
3239
3246
  })
3240
3247
  })
@@ -3371,10 +3378,16 @@ var componentOrNullIfLazy = (props) => {
3371
3378
  return null;
3372
3379
  };
3373
3380
  var TimelineSequenceObserverComponent = ({ onTimelineSequenceChange }) => {
3374
- const sequences = Internals15.useSequenceManagerSequences();
3375
- useEffect13(() => {
3376
- onTimelineSequenceChange(sequences);
3377
- }, [onTimelineSequenceChange, sequences]);
3381
+ const registry = React13.useContext(Internals15.SequenceRegistryContext);
3382
+ useLayoutEffect3(() => {
3383
+ if (registry === null) {
3384
+ throw new Error("Timeline sequence observer requires a sequence registry");
3385
+ }
3386
+ const publish = () => onTimelineSequenceChange(registry.getSnapshot());
3387
+ const unsubscribe = registry.subscribe(publish);
3388
+ publish();
3389
+ return unsubscribe;
3390
+ }, [onTimelineSequenceChange, registry]);
3378
3391
  return null;
3379
3392
  };
3380
3393
  var PlayerFn = ({
@@ -3383,7 +3396,7 @@ var PlayerFn = ({
3383
3396
  compositionWidth,
3384
3397
  fps,
3385
3398
  inputProps,
3386
- style: style2,
3399
+ style,
3387
3400
  controls = false,
3388
3401
  loop = false,
3389
3402
  autoPlay = false,
@@ -3397,7 +3410,7 @@ var PlayerFn = ({
3397
3410
  errorFallback = () => "⚠️",
3398
3411
  playbackRate = 1,
3399
3412
  renderLoading,
3400
- className: className2,
3413
+ className,
3401
3414
  showPosterWhenUnplayed,
3402
3415
  showPosterWhenEnded,
3403
3416
  showPosterWhenPaused,
@@ -3417,6 +3430,7 @@ var PlayerFn = ({
3417
3430
  showPlaybackRateControl = false,
3418
3431
  posterFillMode = "player-size",
3419
3432
  bufferStateDelayInMilliseconds,
3433
+ defaultPremountInSeconds = NoReactInternals2.DEFAULT_PREMOUNT_IN_SECONDS,
3420
3434
  hideControlsWhenPointerDoesntMove = true,
3421
3435
  overflowVisible = false,
3422
3436
  renderMuteButton,
@@ -3432,6 +3446,7 @@ var PlayerFn = ({
3432
3446
  _experimentalKeepAudioContextAlive = false,
3433
3447
  ...componentProps
3434
3448
  }, ref) => {
3449
+ NoReactInternals2.validateDefaultPremountInSeconds(defaultPremountInSeconds);
3435
3450
  if (typeof window !== "undefined") {
3436
3451
  window.remotion_isPlayer = true;
3437
3452
  }
@@ -3622,7 +3637,7 @@ var PlayerFn = ({
3622
3637
  loop: Boolean(loop),
3623
3638
  controls: Boolean(controls),
3624
3639
  errorFallback,
3625
- style: style2,
3640
+ style,
3626
3641
  inputProps: actualInputProps,
3627
3642
  allowFullscreen: Boolean(allowFullscreen),
3628
3643
  moveToBeginningWhenEnded: Boolean(moveToBeginningWhenEnded),
@@ -3631,7 +3646,7 @@ var PlayerFn = ({
3631
3646
  doubleClickToFullscreen: Boolean(doubleClickToFullscreen),
3632
3647
  spaceKeyToPlayOrPause: Boolean(spaceKeyToPlayOrPause),
3633
3648
  playbackRate: currentPlaybackRate,
3634
- className: className2 ?? undefined,
3649
+ className: className ?? undefined,
3635
3650
  showPosterWhenUnplayed: Boolean(showPosterWhenUnplayed),
3636
3651
  showPosterWhenEnded: Boolean(showPosterWhenEnded),
3637
3652
  showPosterWhenPaused: Boolean(showPosterWhenPaused),
@@ -3659,19 +3674,19 @@ var PlayerFn = ({
3659
3674
  })
3660
3675
  })
3661
3676
  });
3662
- if (!onTimelineSequenceChange) {
3663
- return player;
3664
- }
3665
- return /* @__PURE__ */ jsx14(Internals15.SequenceRegistrationContext.Provider, {
3666
- value: true,
3667
- children: /* @__PURE__ */ jsxs10(Internals15.SequenceManagerProvider, {
3668
- children: [
3669
- /* @__PURE__ */ jsx14(TimelineSequenceObserverComponent, {
3670
- onTimelineSequenceChange
3671
- }),
3672
- player
3673
- ]
3674
- })
3677
+ return /* @__PURE__ */ jsx14(Internals15.DefaultPremountContext.Provider, {
3678
+ value: defaultPremountInSeconds,
3679
+ children: onTimelineSequenceChange ? /* @__PURE__ */ jsx14(Internals15.SequenceRegistrationContext.Provider, {
3680
+ value: true,
3681
+ children: /* @__PURE__ */ jsxs10(Internals15.SequenceManagerProvider, {
3682
+ children: [
3683
+ /* @__PURE__ */ jsx14(TimelineSequenceObserverComponent, {
3684
+ onTimelineSequenceChange
3685
+ }),
3686
+ player
3687
+ ]
3688
+ })
3689
+ }) : player
3675
3690
  });
3676
3691
  };
3677
3692
  var forward = forwardRef2;
@@ -3721,11 +3736,11 @@ if (reactVersion2 === "0") {
3721
3736
  }
3722
3737
  var doesReactVersionSupportSuspense2 = parseInt(reactVersion2, 10) >= 18;
3723
3738
  var ThumbnailUI = ({
3724
- style: style2,
3739
+ style,
3725
3740
  inputProps,
3726
3741
  errorFallback,
3727
3742
  renderLoading,
3728
- className: className2,
3743
+ className,
3729
3744
  overflowVisible,
3730
3745
  noSuspense,
3731
3746
  overrideInternalClassName
@@ -3762,16 +3777,16 @@ var ThumbnailUI = ({
3762
3777
  const outerStyle = useMemo16(() => {
3763
3778
  return calculateOuterStyle({
3764
3779
  config,
3765
- style: style2,
3780
+ style,
3766
3781
  canvasSize,
3767
3782
  overflowVisible,
3768
3783
  layout
3769
3784
  });
3770
- }, [canvasSize, config, layout, overflowVisible, style2]);
3785
+ }, [canvasSize, config, layout, overflowVisible, style]);
3771
3786
  const outer = useMemo16(() => {
3772
3787
  return calculateOuter({ config, layout, scale, overflowVisible });
3773
3788
  }, [config, layout, overflowVisible, scale]);
3774
- const containerStyle3 = useMemo16(() => {
3789
+ const containerStyle = useMemo16(() => {
3775
3790
  return calculateContainerStyle({
3776
3791
  config,
3777
3792
  layout,
@@ -3801,7 +3816,7 @@ var ThumbnailUI = ({
3801
3816
  const content = /* @__PURE__ */ jsx15("div", {
3802
3817
  style: outer,
3803
3818
  children: /* @__PURE__ */ jsx15("div", {
3804
- style: containerStyle3,
3819
+ style: containerStyle,
3805
3820
  className: playerCssClassname(overrideInternalClassName),
3806
3821
  children: VideoComponent ? /* @__PURE__ */ jsx15(ErrorBoundary, {
3807
3822
  onError,
@@ -3820,14 +3835,14 @@ var ThumbnailUI = ({
3820
3835
  return /* @__PURE__ */ jsx15("div", {
3821
3836
  ref: container,
3822
3837
  style: outerStyle,
3823
- className: className2,
3838
+ className,
3824
3839
  children: content
3825
3840
  });
3826
3841
  }
3827
3842
  return /* @__PURE__ */ jsx15("div", {
3828
3843
  ref: container,
3829
3844
  style: outerStyle,
3830
- className: className2,
3845
+ className,
3831
3846
  children: /* @__PURE__ */ jsx15(Suspense2, {
3832
3847
  fallback: loadingMarkup,
3833
3848
  children: content
@@ -3840,13 +3855,13 @@ var ThumbnailUI_default = forwardRef3(ThumbnailUI);
3840
3855
  import { jsx as jsx16 } from "react/jsx-runtime";
3841
3856
  var ThumbnailFn = ({
3842
3857
  frameToDisplay,
3843
- style: style2,
3858
+ style,
3844
3859
  inputProps,
3845
3860
  compositionHeight,
3846
3861
  compositionWidth,
3847
3862
  durationInFrames,
3848
3863
  fps,
3849
- className: className2,
3864
+ className,
3850
3865
  errorFallback = () => "⚠️",
3851
3866
  renderLoading,
3852
3867
  overflowVisible = false,
@@ -3941,11 +3956,11 @@ var ThumbnailFn = ({
3941
3956
  value: emitter,
3942
3957
  children: /* @__PURE__ */ jsx16(ThumbnailUI_default, {
3943
3958
  ref: rootRef,
3944
- className: className2,
3959
+ className,
3945
3960
  errorFallback,
3946
3961
  inputProps: passedInputProps,
3947
3962
  renderLoading,
3948
- style: style2,
3963
+ style,
3949
3964
  overflowVisible,
3950
3965
  overrideInternalClassName,
3951
3966
  noSuspense: Boolean(noSuspense)
@@ -3971,10 +3986,11 @@ var PlayerInternals = {
3971
3986
  PlayerEmitterProvider,
3972
3987
  BufferingIndicator,
3973
3988
  TimelineSequenceObserverContext,
3974
- CanvasOverlayContext
3989
+ CanvasOverlayContext,
3990
+ CanvasContentContext
3975
3991
  };
3976
3992
  export {
3977
- Thumbnail,
3993
+ Player,
3978
3994
  PlayerInternals,
3979
- Player
3995
+ Thumbnail
3980
3996
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "url": "https://github.com/remotion-dev/remotion/tree/main/packages/player"
4
4
  },
5
5
  "name": "@remotion/player",
6
- "version": "4.0.533",
6
+ "version": "4.0.535",
7
7
  "description": "React component for embedding a Remotion preview into your app",
8
8
  "main": "dist/cjs/index.js",
9
9
  "types": "dist/cjs/index.d.ts",
@@ -35,7 +35,7 @@
35
35
  ],
36
36
  "license": "SEE LICENSE IN LICENSE.md",
37
37
  "dependencies": {
38
- "remotion": "4.0.533"
38
+ "remotion": "4.0.535"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "react": ">=16.8.0",
@@ -49,7 +49,7 @@
49
49
  "react-dom": "19.2.3",
50
50
  "webpack": "5.105.0",
51
51
  "zod": "4.5.4",
52
- "@remotion/eslint-config-internal": "4.0.533",
52
+ "@remotion/eslint-config-internal": "4.0.535",
53
53
  "eslint": "9.19.0",
54
54
  "@typescript/native-preview": "7.0.0-dev.20260217.1"
55
55
  },