@hanifhan1f/vidstack-react 1.12.13
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.
- package/.templates/sandbox/document.css +27 -0
- package/.templates/sandbox/favicon-32x32.png +0 -0
- package/.templates/sandbox/index.html +21 -0
- package/.templates/sandbox/main.tsx +12 -0
- package/.templates/sandbox/player.css +39 -0
- package/.templates/sandbox/player.tsx +121 -0
- package/.templates/sandbox/tracks.ts +23 -0
- package/LICENSE +21 -0
- package/README.md +23 -0
- package/analyze.config.ts +7 -0
- package/build/build-icons.js +62 -0
- package/npm/analyze.json.d.ts +7 -0
- package/package.json +162 -0
- package/rollup.config.ts +256 -0
- package/src/components/announcer.tsx +47 -0
- package/src/components/layouts/default/audio-layout.tsx +231 -0
- package/src/components/layouts/default/context.ts +28 -0
- package/src/components/layouts/default/hooks.ts +13 -0
- package/src/components/layouts/default/icons.tsx +225 -0
- package/src/components/layouts/default/index.ts +11 -0
- package/src/components/layouts/default/media-layout.tsx +259 -0
- package/src/components/layouts/default/slots.tsx +98 -0
- package/src/components/layouts/default/ui/announcer.tsx +22 -0
- package/src/components/layouts/default/ui/buttons.tsx +301 -0
- package/src/components/layouts/default/ui/captions.tsx +16 -0
- package/src/components/layouts/default/ui/controls.tsx +12 -0
- package/src/components/layouts/default/ui/keyboard-display.tsx +132 -0
- package/src/components/layouts/default/ui/menus/accessibility-menu.tsx +100 -0
- package/src/components/layouts/default/ui/menus/audio-menu.tsx +167 -0
- package/src/components/layouts/default/ui/menus/captions-menu.tsx +61 -0
- package/src/components/layouts/default/ui/menus/chapters-menu.tsx +132 -0
- package/src/components/layouts/default/ui/menus/font-menu.tsx +331 -0
- package/src/components/layouts/default/ui/menus/items/menu-checkbox.tsx +72 -0
- package/src/components/layouts/default/ui/menus/items/menu-items.tsx +135 -0
- package/src/components/layouts/default/ui/menus/items/menu-slider.tsx +92 -0
- package/src/components/layouts/default/ui/menus/playback-menu.tsx +232 -0
- package/src/components/layouts/default/ui/menus/settings-menu.tsx +114 -0
- package/src/components/layouts/default/ui/menus/utils.ts +12 -0
- package/src/components/layouts/default/ui/sliders.tsx +136 -0
- package/src/components/layouts/default/ui/time.tsx +73 -0
- package/src/components/layouts/default/ui/title.tsx +24 -0
- package/src/components/layouts/default/ui/tooltip.tsx +27 -0
- package/src/components/layouts/default/ui.ts +8 -0
- package/src/components/layouts/default/video-layout.tsx +344 -0
- package/src/components/layouts/plyr/context.ts +26 -0
- package/src/components/layouts/plyr/icons/plyr-airplay.js +1 -0
- package/src/components/layouts/plyr/icons/plyr-captions-off.js +1 -0
- package/src/components/layouts/plyr/icons/plyr-captions-on.js +1 -0
- package/src/components/layouts/plyr/icons/plyr-download.js +1 -0
- package/src/components/layouts/plyr/icons/plyr-enter-fullscreen.js +1 -0
- package/src/components/layouts/plyr/icons/plyr-exit-fullscreen.js +1 -0
- package/src/components/layouts/plyr/icons/plyr-fast-forward.js +1 -0
- package/src/components/layouts/plyr/icons/plyr-muted.js +1 -0
- package/src/components/layouts/plyr/icons/plyr-pause.js +1 -0
- package/src/components/layouts/plyr/icons/plyr-pip.js +1 -0
- package/src/components/layouts/plyr/icons/plyr-play.js +1 -0
- package/src/components/layouts/plyr/icons/plyr-restart.js +1 -0
- package/src/components/layouts/plyr/icons/plyr-rewind.js +1 -0
- package/src/components/layouts/plyr/icons/plyr-settings.js +1 -0
- package/src/components/layouts/plyr/icons/plyr-volume.js +1 -0
- package/src/components/layouts/plyr/icons.tsx +71 -0
- package/src/components/layouts/plyr/index.ts +11 -0
- package/src/components/layouts/plyr/layout.tsx +1024 -0
- package/src/components/layouts/plyr/props.ts +104 -0
- package/src/components/layouts/plyr/slots.tsx +52 -0
- package/src/components/layouts/remotion-ui.ts +13 -0
- package/src/components/layouts/utils.ts +17 -0
- package/src/components/player-callbacks.ts +67 -0
- package/src/components/player.tsx +67 -0
- package/src/components/primitives/instances.ts +92 -0
- package/src/components/primitives/nodes.tsx +58 -0
- package/src/components/primitives/slot.tsx +132 -0
- package/src/components/provider.tsx +187 -0
- package/src/components/text-track.tsx +106 -0
- package/src/components/ui/buttons/airplay-button.tsx +53 -0
- package/src/components/ui/buttons/caption-button.tsx +55 -0
- package/src/components/ui/buttons/fullscreen-button.tsx +55 -0
- package/src/components/ui/buttons/google-cast-button.tsx +53 -0
- package/src/components/ui/buttons/live-button.tsx +56 -0
- package/src/components/ui/buttons/mute-button.tsx +60 -0
- package/src/components/ui/buttons/pip-button.tsx +54 -0
- package/src/components/ui/buttons/play-button.tsx +53 -0
- package/src/components/ui/buttons/seek-button.tsx +55 -0
- package/src/components/ui/buttons/toggle-button.tsx +51 -0
- package/src/components/ui/caption.tsx +70 -0
- package/src/components/ui/captions.tsx +41 -0
- package/src/components/ui/chapter-title.tsx +40 -0
- package/src/components/ui/controls.tsx +90 -0
- package/src/components/ui/gesture.tsx +43 -0
- package/src/components/ui/menu.tsx +251 -0
- package/src/components/ui/poster.tsx +101 -0
- package/src/components/ui/radio-group.tsx +88 -0
- package/src/components/ui/sliders/audio-gain-slider.tsx +55 -0
- package/src/components/ui/sliders/quality-slider.tsx +54 -0
- package/src/components/ui/sliders/slider-callbacks.ts +14 -0
- package/src/components/ui/sliders/slider-value.tsx +13 -0
- package/src/components/ui/sliders/slider.tsx +254 -0
- package/src/components/ui/sliders/speed-slider.tsx +54 -0
- package/src/components/ui/sliders/time-slider.tsx +379 -0
- package/src/components/ui/sliders/volume-slider.tsx +55 -0
- package/src/components/ui/spinner.tsx +105 -0
- package/src/components/ui/thumbnail.tsx +82 -0
- package/src/components/ui/time.tsx +77 -0
- package/src/components/ui/title.tsx +32 -0
- package/src/components/ui/tooltip.tsx +135 -0
- package/src/globals.d.ts +3 -0
- package/src/hooks/create-text-track.ts +22 -0
- package/src/hooks/options/use-audio-gain-options.ts +75 -0
- package/src/hooks/options/use-audio-options.ts +71 -0
- package/src/hooks/options/use-caption-options.ts +95 -0
- package/src/hooks/options/use-chapter-options.ts +97 -0
- package/src/hooks/options/use-playback-rate-options.ts +75 -0
- package/src/hooks/options/use-video-quality-options.ts +123 -0
- package/src/hooks/use-active-text-cues.ts +28 -0
- package/src/hooks/use-active-text-track.ts +19 -0
- package/src/hooks/use-chapter-title.ts +12 -0
- package/src/hooks/use-dom.ts +121 -0
- package/src/hooks/use-media-context.ts +6 -0
- package/src/hooks/use-media-player.ts +19 -0
- package/src/hooks/use-media-provider.ts +31 -0
- package/src/hooks/use-media-remote.ts +37 -0
- package/src/hooks/use-media-state.ts +58 -0
- package/src/hooks/use-signals.ts +24 -0
- package/src/hooks/use-slider-preview.ts +126 -0
- package/src/hooks/use-slider-state.ts +63 -0
- package/src/hooks/use-state.ts +47 -0
- package/src/hooks/use-text-cues.ts +33 -0
- package/src/hooks/use-thumbnails.ts +69 -0
- package/src/icon.ts +37 -0
- package/src/icons.ts +754 -0
- package/src/index.ts +181 -0
- package/src/providers/remotion/index.ts +10 -0
- package/src/providers/remotion/layout-engine.ts +123 -0
- package/src/providers/remotion/loader.ts +35 -0
- package/src/providers/remotion/playback-engine.ts +142 -0
- package/src/providers/remotion/provider.tsx +514 -0
- package/src/providers/remotion/type-check.ts +13 -0
- package/src/providers/remotion/types.ts +94 -0
- package/src/providers/remotion/ui/context.tsx +120 -0
- package/src/providers/remotion/ui/error-boundary.tsx +57 -0
- package/src/providers/remotion/ui/poster.tsx +33 -0
- package/src/providers/remotion/ui/slider-thumbnail.tsx +41 -0
- package/src/providers/remotion/ui/thumbnail.tsx +166 -0
- package/src/providers/remotion/validate.ts +220 -0
- package/src/source.ts +5 -0
- package/src/utils.ts +27 -0
- package/tsconfig.build.json +10 -0
- package/tsconfig.json +11 -0
- package/types/react/src/components/announcer.d.ts +16 -0
- package/types/react/src/components/layouts/default/audio-layout.d.ts +27 -0
- package/types/react/src/components/layouts/default/context.d.ts +14 -0
- package/types/react/src/components/layouts/default/hooks.d.ts +2 -0
- package/types/react/src/components/layouts/default/icons.d.ts +95 -0
- package/types/react/src/components/layouts/default/index.d.ts +5 -0
- package/types/react/src/components/layouts/default/media-layout.d.ts +133 -0
- package/types/react/src/components/layouts/default/slots.d.ts +22 -0
- package/types/react/src/components/layouts/default/ui/announcer.d.ts +6 -0
- package/types/react/src/components/layouts/default/ui/buttons.d.ts +54 -0
- package/types/react/src/components/layouts/default/ui/captions.d.ts +6 -0
- package/types/react/src/components/layouts/default/ui/controls.d.ts +6 -0
- package/types/react/src/components/layouts/default/ui/keyboard-display.d.ts +8 -0
- package/types/react/src/components/layouts/default/ui/menus/accessibility-menu.d.ts +10 -0
- package/types/react/src/components/layouts/default/ui/menus/audio-menu.d.ts +10 -0
- package/types/react/src/components/layouts/default/ui/menus/captions-menu.d.ts +10 -0
- package/types/react/src/components/layouts/default/ui/menus/chapters-menu.d.ts +7 -0
- package/types/react/src/components/layouts/default/ui/menus/font-menu.d.ts +6 -0
- package/types/react/src/components/layouts/default/ui/menus/items/menu-checkbox.d.ts +13 -0
- package/types/react/src/components/layouts/default/ui/menus/items/menu-items.d.ts +49 -0
- package/types/react/src/components/layouts/default/ui/menus/items/menu-slider.d.ts +26 -0
- package/types/react/src/components/layouts/default/ui/menus/playback-menu.d.ts +10 -0
- package/types/react/src/components/layouts/default/ui/menus/settings-menu.d.ts +15 -0
- package/types/react/src/components/layouts/default/ui/menus/utils.d.ts +1 -0
- package/types/react/src/components/layouts/default/ui/sliders.d.ts +24 -0
- package/types/react/src/components/layouts/default/ui/time.d.ts +30 -0
- package/types/react/src/components/layouts/default/ui/title.d.ts +6 -0
- package/types/react/src/components/layouts/default/ui/tooltip.d.ts +12 -0
- package/types/react/src/components/layouts/default/ui.d.ts +8 -0
- package/types/react/src/components/layouts/default/video-layout.d.ts +47 -0
- package/types/react/src/components/layouts/plyr/context.d.ts +12 -0
- package/types/react/src/components/layouts/plyr/icons/plyr-airplay.d.ts +2 -0
- package/types/react/src/components/layouts/plyr/icons/plyr-captions-off.d.ts +2 -0
- package/types/react/src/components/layouts/plyr/icons/plyr-captions-on.d.ts +2 -0
- package/types/react/src/components/layouts/plyr/icons/plyr-download.d.ts +2 -0
- package/types/react/src/components/layouts/plyr/icons/plyr-enter-fullscreen.d.ts +2 -0
- package/types/react/src/components/layouts/plyr/icons/plyr-exit-fullscreen.d.ts +2 -0
- package/types/react/src/components/layouts/plyr/icons/plyr-fast-forward.d.ts +2 -0
- package/types/react/src/components/layouts/plyr/icons/plyr-muted.d.ts +2 -0
- package/types/react/src/components/layouts/plyr/icons/plyr-pause.d.ts +2 -0
- package/types/react/src/components/layouts/plyr/icons/plyr-pip.d.ts +2 -0
- package/types/react/src/components/layouts/plyr/icons/plyr-play.d.ts +2 -0
- package/types/react/src/components/layouts/plyr/icons/plyr-restart.d.ts +2 -0
- package/types/react/src/components/layouts/plyr/icons/plyr-rewind.d.ts +2 -0
- package/types/react/src/components/layouts/plyr/icons/plyr-settings.d.ts +2 -0
- package/types/react/src/components/layouts/plyr/icons/plyr-volume.d.ts +2 -0
- package/types/react/src/components/layouts/plyr/icons.d.ts +25 -0
- package/types/react/src/components/layouts/plyr/index.d.ts +6 -0
- package/types/react/src/components/layouts/plyr/layout.d.ts +17 -0
- package/types/react/src/components/layouts/plyr/props.d.ts +71 -0
- package/types/react/src/components/layouts/plyr/slots.d.ts +9 -0
- package/types/react/src/components/layouts/remotion-ui.d.ts +3 -0
- package/types/react/src/components/layouts/utils.d.ts +1 -0
- package/types/react/src/components/player-callbacks.d.ts +6 -0
- package/types/react/src/components/player.d.ts +32 -0
- package/types/react/src/components/primitives/instances.d.ts +83 -0
- package/types/react/src/components/primitives/nodes.d.ts +15 -0
- package/types/react/src/components/primitives/slot.d.ts +11 -0
- package/types/react/src/components/provider.d.ts +26 -0
- package/types/react/src/components/text-track.d.ts +100 -0
- package/types/react/src/components/ui/buttons/airplay-button.d.ts +22 -0
- package/types/react/src/components/ui/buttons/caption-button.d.ts +24 -0
- package/types/react/src/components/ui/buttons/fullscreen-button.d.ts +24 -0
- package/types/react/src/components/ui/buttons/google-cast-button.d.ts +22 -0
- package/types/react/src/components/ui/buttons/live-button.d.ts +26 -0
- package/types/react/src/components/ui/buttons/mute-button.d.ts +30 -0
- package/types/react/src/components/ui/buttons/pip-button.d.ts +24 -0
- package/types/react/src/components/ui/buttons/play-button.d.ts +23 -0
- package/types/react/src/components/ui/buttons/seek-button.d.ts +25 -0
- package/types/react/src/components/ui/buttons/toggle-button.d.ts +22 -0
- package/types/react/src/components/ui/caption.d.ts +11 -0
- package/types/react/src/components/ui/captions.d.ts +20 -0
- package/types/react/src/components/ui/chapter-title.d.ts +20 -0
- package/types/react/src/components/ui/controls.d.ts +40 -0
- package/types/react/src/components/ui/gesture.d.ts +20 -0
- package/types/react/src/components/ui/menu.d.ts +102 -0
- package/types/react/src/components/ui/poster.d.ts +25 -0
- package/types/react/src/components/ui/radio-group.d.ts +39 -0
- package/types/react/src/components/ui/sliders/audio-gain-slider.d.ts +29 -0
- package/types/react/src/components/ui/sliders/quality-slider.d.ts +28 -0
- package/types/react/src/components/ui/sliders/slider-callbacks.d.ts +6 -0
- package/types/react/src/components/ui/sliders/slider-value.d.ts +9 -0
- package/types/react/src/components/ui/sliders/slider.d.ts +134 -0
- package/types/react/src/components/ui/sliders/speed-slider.d.ts +28 -0
- package/types/react/src/components/ui/sliders/time-slider.d.ts +124 -0
- package/types/react/src/components/ui/sliders/volume-slider.d.ts +29 -0
- package/types/react/src/components/ui/spinner.d.ts +31 -0
- package/types/react/src/components/ui/thumbnail.d.ts +26 -0
- package/types/react/src/components/ui/time.d.ts +20 -0
- package/types/react/src/components/ui/title.d.ts +15 -0
- package/types/react/src/components/ui/tooltip.d.ts +63 -0
- package/types/react/src/hooks/create-text-track.d.ts +7 -0
- package/types/react/src/hooks/options/use-audio-gain-options.d.ts +22 -0
- package/types/react/src/hooks/options/use-audio-options.d.ts +17 -0
- package/types/react/src/hooks/options/use-caption-options.d.ts +24 -0
- package/types/react/src/hooks/options/use-chapter-options.d.ts +18 -0
- package/types/react/src/hooks/options/use-playback-rate-options.d.ts +22 -0
- package/types/react/src/hooks/options/use-video-quality-options.d.ts +35 -0
- package/types/react/src/hooks/use-active-text-cues.d.ts +6 -0
- package/types/react/src/hooks/use-active-text-track.d.ts +5 -0
- package/types/react/src/hooks/use-chapter-title.d.ts +4 -0
- package/types/react/src/hooks/use-dom.d.ts +9 -0
- package/types/react/src/hooks/use-media-context.d.ts +1 -0
- package/types/react/src/hooks/use-media-player.d.ts +7 -0
- package/types/react/src/hooks/use-media-provider.d.ts +7 -0
- package/types/react/src/hooks/use-media-remote.d.ts +12 -0
- package/types/react/src/hooks/use-media-state.d.ts +15 -0
- package/types/react/src/hooks/use-signals.d.ts +5 -0
- package/types/react/src/hooks/use-slider-preview.d.ts +27 -0
- package/types/react/src/hooks/use-slider-state.d.ts +16 -0
- package/types/react/src/hooks/use-state.d.ts +18 -0
- package/types/react/src/hooks/use-text-cues.d.ts +6 -0
- package/types/react/src/hooks/use-thumbnails.d.ts +16 -0
- package/types/react/src/icon.d.ts +17 -0
- package/types/react/src/icons.d.ts +215 -0
- package/types/react/src/index.d.ts +78 -0
- package/types/react/src/providers/remotion/index.d.ts +7 -0
- package/types/react/src/providers/remotion/layout-engine.d.ts +8 -0
- package/types/react/src/providers/remotion/loader.d.ts +9 -0
- package/types/react/src/providers/remotion/playback-engine.d.ts +11 -0
- package/types/react/src/providers/remotion/provider.d.ts +26 -0
- package/types/react/src/providers/remotion/type-check.d.ts +6 -0
- package/types/react/src/providers/remotion/types.d.ts +91 -0
- package/types/react/src/providers/remotion/ui/context.d.ts +17 -0
- package/types/react/src/providers/remotion/ui/error-boundary.d.ts +21 -0
- package/types/react/src/providers/remotion/ui/poster.d.ts +18 -0
- package/types/react/src/providers/remotion/ui/slider-thumbnail.d.ts +17 -0
- package/types/react/src/providers/remotion/ui/thumbnail.d.ts +32 -0
- package/types/react/src/providers/remotion/validate.d.ts +12 -0
- package/types/react/src/source.d.ts +3 -0
- package/types/react/src/utils.d.ts +3 -0
- package/types/vidstack/src/core/api/src-types.d.ts +50 -0
- package/types/vidstack/src/utils/mime.d.ts +15 -0
- package/types/vidstack/src/utils/network.d.ts +17 -0
- package/types/vidstack/src/utils/support.d.ts +72 -0
- package/vite.config.ts +23 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
import type { AnyRecord, Component, State } from 'maverick.js';
|
|
4
|
+
import { useSignal, useSignalRecord } from 'maverick.js/react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* This hook is used to subscribe to specific state on a component instance.
|
|
8
|
+
*
|
|
9
|
+
* @docs {@link https://www.vidstack.io/docs/player/api/hooks/use-state}
|
|
10
|
+
*/
|
|
11
|
+
export function useState<T extends AnyRecord, R extends keyof T>(
|
|
12
|
+
ctor: { state: State<T> },
|
|
13
|
+
prop: R,
|
|
14
|
+
ref: React.RefObject<Component<any, T, any, any> | null>,
|
|
15
|
+
): T[R] {
|
|
16
|
+
const initialValue = React.useMemo(() => ctor.state.record[prop], [ctor, prop]);
|
|
17
|
+
return useSignal(ref.current ? ref.current.$state[prop] : initialValue);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const storesCache = new Map<any, any>();
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* This hook is used to subscribe to multiple states on a component instance.
|
|
24
|
+
*
|
|
25
|
+
* @docs {@link https://www.vidstack.io/docs/player/api/hooks/use-store}
|
|
26
|
+
*/
|
|
27
|
+
export function useStore<T extends AnyRecord>(
|
|
28
|
+
ctor: { state: State<T> },
|
|
29
|
+
ref: React.RefObject<Component<any, T, any, any> | null>,
|
|
30
|
+
): T {
|
|
31
|
+
const initialStore = React.useMemo<any>(() => {
|
|
32
|
+
let store = storesCache.get(ctor);
|
|
33
|
+
|
|
34
|
+
// Share the same initial store proxy across constructors.
|
|
35
|
+
if (!store) {
|
|
36
|
+
store = new Proxy(ctor.state.record, {
|
|
37
|
+
get: (_, prop: any) => () => ctor.state.record[prop],
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
storesCache.set(ctor, store);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return store;
|
|
44
|
+
}, [ctor]);
|
|
45
|
+
|
|
46
|
+
return useSignalRecord(ref.current ? ref.current.$state : initialStore);
|
|
47
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
import { EventsController } from 'maverick.js/std';
|
|
4
|
+
import type { VTTCue } from 'media-captions';
|
|
5
|
+
import type { TextTrack } from 'vidstack';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @docs {@link https://www.vidstack.io/docs/player/api/hooks/use-text-cues}
|
|
9
|
+
*/
|
|
10
|
+
export function useTextCues(track: TextTrack | null): VTTCue[] {
|
|
11
|
+
const [cues, setCues] = React.useState<VTTCue[]>([]);
|
|
12
|
+
|
|
13
|
+
React.useEffect(() => {
|
|
14
|
+
if (!track) return;
|
|
15
|
+
|
|
16
|
+
function onCuesChange() {
|
|
17
|
+
if (track) setCues([...track.cues]);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const events = new EventsController(track)
|
|
21
|
+
.add('add-cue', onCuesChange)
|
|
22
|
+
.add('remove-cue', onCuesChange);
|
|
23
|
+
|
|
24
|
+
onCuesChange();
|
|
25
|
+
|
|
26
|
+
return () => {
|
|
27
|
+
setCues([]);
|
|
28
|
+
events.abort();
|
|
29
|
+
};
|
|
30
|
+
}, [track]);
|
|
31
|
+
|
|
32
|
+
return cues;
|
|
33
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
import { useReactScope, useSignal } from 'maverick.js/react';
|
|
4
|
+
import {
|
|
5
|
+
ThumbnailsLoader,
|
|
6
|
+
type MediaCrossOrigin,
|
|
7
|
+
type ThumbnailImage,
|
|
8
|
+
type ThumbnailSrc,
|
|
9
|
+
} from 'vidstack';
|
|
10
|
+
|
|
11
|
+
import { createSignal, useScoped } from './use-signals';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The function will return the resolved thumbnail images given a thumbnail resource. It's safe to
|
|
15
|
+
* call this hook in multiple places with the same `src` argument as work is de-duped and cached
|
|
16
|
+
* internally.
|
|
17
|
+
*
|
|
18
|
+
* @docs {@link https://www.vidstack.io/docs/player/api/hooks/use-thumbnails}
|
|
19
|
+
*/
|
|
20
|
+
export function useThumbnails(
|
|
21
|
+
src: ThumbnailSrc,
|
|
22
|
+
crossOrigin: MediaCrossOrigin | null = null,
|
|
23
|
+
): ThumbnailImage[] {
|
|
24
|
+
const scope = useReactScope(),
|
|
25
|
+
$src = createSignal(src),
|
|
26
|
+
$crossOrigin = createSignal(crossOrigin),
|
|
27
|
+
loader = useScoped(() => ThumbnailsLoader.create($src, $crossOrigin));
|
|
28
|
+
|
|
29
|
+
if (__DEV__ && !scope) {
|
|
30
|
+
console.warn(
|
|
31
|
+
`[vidstack] \`useThumbnails\` must be called inside a child component of \`<MediaPlayer>\``,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
React.useEffect(() => {
|
|
36
|
+
$src.set(src);
|
|
37
|
+
}, [src]);
|
|
38
|
+
|
|
39
|
+
React.useEffect(() => {
|
|
40
|
+
$crossOrigin.set(crossOrigin);
|
|
41
|
+
}, [crossOrigin]);
|
|
42
|
+
|
|
43
|
+
return useSignal(loader.$images);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Returns the active thumbnail image based on the given time.
|
|
48
|
+
*
|
|
49
|
+
* @param thumbnails - thumbnail images.
|
|
50
|
+
* @param time - the current time to determine which thumbnail is active.
|
|
51
|
+
*/
|
|
52
|
+
export function useActiveThumbnail(
|
|
53
|
+
thumbnails: ThumbnailImage[],
|
|
54
|
+
time: number,
|
|
55
|
+
): ThumbnailImage | null {
|
|
56
|
+
return React.useMemo(() => {
|
|
57
|
+
let activeIndex = -1;
|
|
58
|
+
|
|
59
|
+
for (let i = thumbnails.length - 1; i >= 0; i--) {
|
|
60
|
+
const image = thumbnails[i];
|
|
61
|
+
if (time >= image.startTime && (!image.endTime || time < image.endTime)) {
|
|
62
|
+
activeIndex = i;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return thumbnails[activeIndex] || null;
|
|
68
|
+
}, [thumbnails, time]);
|
|
69
|
+
}
|
package/src/icon.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
export interface IconProps
|
|
4
|
+
extends React.PropsWithoutRef<React.SVGProps<SVGSVGElement>>,
|
|
5
|
+
React.RefAttributes<SVGElement | SVGSVGElement> {
|
|
6
|
+
/**
|
|
7
|
+
* The horizontal (width) and vertical (height) length of the underlying `<svg>` element.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/width}
|
|
10
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/height}
|
|
11
|
+
*/
|
|
12
|
+
size?: number;
|
|
13
|
+
part?: string;
|
|
14
|
+
/** @internal */
|
|
15
|
+
paths?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface IconComponent extends React.ForwardRefExoticComponent<IconProps> {}
|
|
19
|
+
|
|
20
|
+
const Icon: IconComponent = /* #__PURE__*/ React.forwardRef((props, ref) => {
|
|
21
|
+
const { width, height, size = null, paths, ...restProps } = props;
|
|
22
|
+
return React.createElement('svg', {
|
|
23
|
+
viewBox: '0 0 32 32',
|
|
24
|
+
...restProps,
|
|
25
|
+
width: width ?? size,
|
|
26
|
+
height: height ?? size,
|
|
27
|
+
fill: 'none',
|
|
28
|
+
'aria-hidden': 'true',
|
|
29
|
+
focusable: 'false',
|
|
30
|
+
xmlns: 'http://www.w3.org/2000/svg',
|
|
31
|
+
ref,
|
|
32
|
+
dangerouslySetInnerHTML: { __html: paths },
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
Icon.displayName = 'VidstackIcon';
|
|
37
|
+
export { Icon };
|