@remotion/player 4.0.471 → 4.0.473

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.
@@ -42,7 +42,7 @@ export declare const PlayerInternals: {
42
42
  getCurrentFrame: () => number;
43
43
  muted: boolean;
44
44
  }) => void;
45
- useElementSize: (ref: import("react").RefObject<HTMLElement | null>, options: {
45
+ useElementSize: (source: HTMLElement | import("react").RefObject<HTMLElement | null> | null, options: {
46
46
  triggerOnWindowResize: boolean;
47
47
  shouldApplyCssTransforms: boolean;
48
48
  }) => import("./index.js").Size | null;
@@ -32,12 +32,15 @@ const usePlayer = () => {
32
32
  }
33
33
  const { buffering } = bufferingContext;
34
34
  const seek = (0, react_1.useCallback)((newFrame) => {
35
+ const frameToSeekTo = config
36
+ ? remotion_1.Internals.TimelinePosition.clampFrameToCompositionRange(newFrame, config.durationInFrames)
37
+ : Math.max(0, newFrame);
35
38
  if (video === null || video === void 0 ? void 0 : video.id) {
36
- setTimelinePosition((c) => ({ ...c, [video.id]: newFrame }));
39
+ setTimelinePosition((c) => ({ ...c, [video.id]: frameToSeekTo }));
37
40
  }
38
- frameRef.current = newFrame;
39
- emitter.dispatchSeek(newFrame);
40
- }, [emitter, setTimelinePosition, video === null || video === void 0 ? void 0 : video.id]);
41
+ frameRef.current = frameToSeekTo;
42
+ emitter.dispatchSeek(frameToSeekTo);
43
+ }, [config, emitter, setTimelinePosition, video === null || video === void 0 ? void 0 : video.id]);
41
44
  const play = (0, react_1.useCallback)((e) => {
42
45
  if (imperativePlaying.current) {
43
46
  return;
@@ -10,7 +10,9 @@ export type Size = {
10
10
  refresh: () => void;
11
11
  };
12
12
  export declare const updateAllElementsSizes: () => void;
13
- export declare const useElementSize: (ref: import("react").RefObject<HTMLElement | null>, options: {
13
+ type ElementSizeSource = React.RefObject<HTMLElement | null> | HTMLElement | null;
14
+ export declare const useElementSize: (source: ElementSizeSource, options: {
14
15
  triggerOnWindowResize: boolean;
15
16
  shouldApplyCssTransforms: boolean;
16
17
  }) => Size | null;
18
+ export {};
@@ -9,12 +9,22 @@ const updateAllElementsSizes = () => {
9
9
  }
10
10
  };
11
11
  exports.updateAllElementsSizes = updateAllElementsSizes;
12
- const useElementSize = (ref, options) => {
12
+ const getElement = (source) => {
13
+ if (!source) {
14
+ return null;
15
+ }
16
+ if ('current' in source) {
17
+ return source.current;
18
+ }
19
+ return source;
20
+ };
21
+ const useElementSize = (source, options) => {
13
22
  const [size, setSize] = (0, react_1.useState)(() => {
14
- if (!ref.current) {
23
+ const element = getElement(source);
24
+ if (!element) {
15
25
  return null;
16
26
  }
17
- const rect = ref.current.getClientRects();
27
+ const rect = element.getClientRects();
18
28
  if (!rect[0]) {
19
29
  return null;
20
30
  }
@@ -77,10 +87,11 @@ const useElementSize = (ref, options) => {
77
87
  });
78
88
  }, [options.shouldApplyCssTransforms]);
79
89
  const updateSize = (0, react_1.useCallback)(() => {
80
- if (!ref.current) {
90
+ const element = getElement(source);
91
+ if (!element) {
81
92
  return;
82
93
  }
83
- const rect = ref.current.getClientRects();
94
+ const rect = element.getClientRects();
84
95
  if (!rect[0]) {
85
96
  setSize(null);
86
97
  return;
@@ -107,21 +118,24 @@ const useElementSize = (ref, options) => {
107
118
  },
108
119
  };
109
120
  });
110
- }, [ref]);
121
+ }, [source]);
122
+ (0, react_1.useEffect)(() => {
123
+ updateSize();
124
+ }, [updateSize]);
111
125
  (0, react_1.useEffect)(() => {
112
126
  if (!observer) {
113
127
  return;
114
128
  }
115
- const { current } = ref;
116
- if (current) {
117
- observer.observe(current);
129
+ const element = getElement(source);
130
+ if (element) {
131
+ observer.observe(element);
118
132
  }
119
133
  return () => {
120
- if (current) {
121
- observer.unobserve(current);
134
+ if (element) {
135
+ observer.unobserve(element);
122
136
  }
123
137
  };
124
- }, [observer, ref, updateSize]);
138
+ }, [observer, source]);
125
139
  (0, react_1.useEffect)(() => {
126
140
  if (!options.triggerOnWindowResize) {
127
141
  return;
@@ -594,12 +594,13 @@ var usePlayer = () => {
594
594
  }
595
595
  const { buffering } = bufferingContext;
596
596
  const seek = useCallback((newFrame) => {
597
+ const frameToSeekTo = config ? Internals4.TimelinePosition.clampFrameToCompositionRange(newFrame, config.durationInFrames) : Math.max(0, newFrame);
597
598
  if (video?.id) {
598
- setTimelinePosition((c) => ({ ...c, [video.id]: newFrame }));
599
+ setTimelinePosition((c) => ({ ...c, [video.id]: frameToSeekTo }));
599
600
  }
600
- frameRef.current = newFrame;
601
- emitter.dispatchSeek(newFrame);
602
- }, [emitter, setTimelinePosition, video?.id]);
601
+ frameRef.current = frameToSeekTo;
602
+ emitter.dispatchSeek(frameToSeekTo);
603
+ }, [config, emitter, setTimelinePosition, video?.id]);
603
604
  const play = useCallback((e) => {
604
605
  if (imperativePlaying.current) {
605
606
  return;
@@ -1186,12 +1187,22 @@ var updateAllElementsSizes = () => {
1186
1187
  listener();
1187
1188
  }
1188
1189
  };
1189
- var useElementSize = (ref, options) => {
1190
+ var getElement = (source) => {
1191
+ if (!source) {
1192
+ return null;
1193
+ }
1194
+ if ("current" in source) {
1195
+ return source.current;
1196
+ }
1197
+ return source;
1198
+ };
1199
+ var useElementSize = (source, options) => {
1190
1200
  const [size, setSize] = useState4(() => {
1191
- if (!ref.current) {
1201
+ const element = getElement(source);
1202
+ if (!element) {
1192
1203
  return null;
1193
1204
  }
1194
- const rect = ref.current.getClientRects();
1205
+ const rect = element.getClientRects();
1195
1206
  if (!rect[0]) {
1196
1207
  return null;
1197
1208
  }
@@ -1240,10 +1251,11 @@ var useElementSize = (ref, options) => {
1240
1251
  });
1241
1252
  }, [options.shouldApplyCssTransforms]);
1242
1253
  const updateSize = useCallback2(() => {
1243
- if (!ref.current) {
1254
+ const element = getElement(source);
1255
+ if (!element) {
1244
1256
  return;
1245
1257
  }
1246
- const rect = ref.current.getClientRects();
1258
+ const rect = element.getClientRects();
1247
1259
  if (!rect[0]) {
1248
1260
  setSize(null);
1249
1261
  return;
@@ -1264,21 +1276,24 @@ var useElementSize = (ref, options) => {
1264
1276
  }
1265
1277
  };
1266
1278
  });
1267
- }, [ref]);
1279
+ }, [source]);
1280
+ useEffect6(() => {
1281
+ updateSize();
1282
+ }, [updateSize]);
1268
1283
  useEffect6(() => {
1269
1284
  if (!observer) {
1270
1285
  return;
1271
1286
  }
1272
- const { current } = ref;
1273
- if (current) {
1274
- observer.observe(current);
1287
+ const element = getElement(source);
1288
+ if (element) {
1289
+ observer.observe(element);
1275
1290
  }
1276
1291
  return () => {
1277
- if (current) {
1278
- observer.unobserve(current);
1292
+ if (element) {
1293
+ observer.unobserve(element);
1279
1294
  }
1280
1295
  };
1281
- }, [observer, ref, updateSize]);
1296
+ }, [observer, source]);
1282
1297
  useEffect6(() => {
1283
1298
  if (!options.triggerOnWindowResize) {
1284
1299
  return;
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.471",
6
+ "version": "4.0.473",
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.471"
38
+ "remotion": "4.0.473"
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.3.6",
52
- "@remotion/eslint-config-internal": "4.0.471",
52
+ "@remotion/eslint-config-internal": "4.0.473",
53
53
  "eslint": "9.19.0",
54
54
  "@typescript/native-preview": "7.0.0-dev.20260217.1"
55
55
  },