react-x11 2.31.0 → 2.33.0

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.
@@ -0,0 +1,29 @@
1
+ // `useVideoFrames`: a VideoFrames sink for a component (src/videoframes.js).
2
+ import { useMemo } from 'react';
3
+
4
+ import { useApp } from './appcontext.js';
5
+ import { createVideoFrames } from './videoframes.js';
6
+
7
+ /**
8
+ * A sink for decoded frames of one size and format, the same object across
9
+ * renders and a new one when the size, the format or the colour changes —
10
+ * so a decoder started in an effect keyed on it is restarted exactly when
11
+ * its output would no longer fit:
12
+ *
13
+ * ```jsx
14
+ * const frames = useVideoFrames({ width: 1280, height: 720, format: 'NV12' });
15
+ * useEffect(() => startDecoder(url, frames), [frames, url]);
16
+ * <video frames={frames} style={{ width: '100%', aspectRatio: 16 / 9 }} />;
17
+ * ```
18
+ *
19
+ * Nothing to close on unmount: a sink owns nothing native, and what shows
20
+ * it lets go of what it made when it stops showing it.
21
+ */
22
+ export function useVideoFrames(options) {
23
+ const app = useApp();
24
+ const { width, height, format, colorSpace, range } = options ?? {};
25
+ return useMemo(
26
+ () => createVideoFrames(app, { width, height, format, colorSpace, range }),
27
+ [app, width, height, format, colorSpace, range],
28
+ );
29
+ }