@siberiacancode/reactuse 0.2.19 → 0.2.20

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,5 +1,6 @@
1
1
  export * from './useActiveElement/useActiveElement';
2
2
  export * from './useAsync/useAsync';
3
+ export * from './useAudio/useAudio';
3
4
  export * from './useBattery/useBattery';
4
5
  export * from './useBluetooth/useBluetooth';
5
6
  export * from './useBoolean/useBoolean';
@@ -65,6 +66,7 @@ export * from './useLogger/useLogger';
65
66
  export * from './useLongPress/useLongPress';
66
67
  export * from './useMap/useMap';
67
68
  export * from './useMeasure/useMeasure';
69
+ export * from './useMediaControls/useMediaControls';
68
70
  export * from './useMediaQuery/useMediaQuery';
69
71
  export * from './useMemory/useMemory';
70
72
  export * from './useMount/useMount';
@@ -84,6 +86,7 @@ export * from './usePaint/usePaint';
84
86
  export * from './useParallax/useParallax';
85
87
  export * from './usePerformanceObserver/usePerformanceObserver';
86
88
  export * from './usePermission/usePermission';
89
+ export * from './usePictureInPicture/usePictureInPicture';
87
90
  export * from './usePointerLock/usePointerLock';
88
91
  export * from './usePostMessage/usePostMessage';
89
92
  export * from './usePreferredColorScheme/usePreferredColorScheme';
@@ -0,0 +1,58 @@
1
+ /** Type sprite map */
2
+ export interface SpriteMap {
3
+ /** [start time in seconds, end time in seconds] */
4
+ [key: string]: [number, number];
5
+ }
6
+ /** Type use audio options */
7
+ export interface UseAudioOptions {
8
+ /** Whether audio playback is initially enabled */
9
+ immediately?: boolean;
10
+ /** Whether to stop current playback when starting a new one */
11
+ interrupt?: boolean;
12
+ /** Initial playback speed (0.5 to 2) */
13
+ playbackRate?: number;
14
+ /** Map of named audio segments for sprite-based playback */
15
+ sprite?: SpriteMap;
16
+ /** Initial volume level (0 to 1) */
17
+ volume?: number;
18
+ }
19
+ /** Type use audio return type */
20
+ export interface UseAudioReturn {
21
+ /** Current playback speed (0.5 to 2) */
22
+ playbackRate: number;
23
+ /** Whether audio is currently playing */
24
+ playing: boolean;
25
+ /** Current volume level (0 to 1) */
26
+ volume: number;
27
+ /** Set playback speed (0.5 to 2) */
28
+ changePlaybackRate: (value: number) => void;
29
+ /** Pause audio playback at current position */
30
+ pause: () => void;
31
+ /** Start audio playback from the beginning or specified sprite segment */
32
+ play: (sprite?: string) => Promise<void>;
33
+ /** Set audio volume level (0 to 1) */
34
+ setVolume: (value: number) => void;
35
+ /** Stop audio playback and reset position to start */
36
+ stop: () => void;
37
+ }
38
+ /**
39
+ * @name useAudio
40
+ * @description - Hook that manages audio playback with sprite support
41
+ * @category Browser
42
+ *
43
+ * @browserapi Audio https://developer.mozilla.org/en-US/docs/Web/API/Audio
44
+ *
45
+ * @template Value The type of the value
46
+ * @param {string} url The URL of the audio file to play
47
+ * @param {UseAudioOptions} [options] Audio configuration options
48
+ * @param {number} [options.volume=1] Initial volume level (0 to 1)
49
+ * @param {number} [options.playbackRate=1] Initial playback speed (0.5 to 2)
50
+ * @param {boolean} [options.interrupt=false] Whether to stop current playback when starting a new one
51
+ * @param {boolean} [options.soundEnabled=true] Whether audio playback is initially enabled
52
+ * @param {SpriteMap} [options.sprite] Map of named audio segments for sprite-based playback
53
+ * @returns {UseAudioReturn} An object containing audio controls and state
54
+ *
55
+ * @example
56
+ * const audio = useAudio("/path/to/sound.mp3");
57
+ */
58
+ export declare const useAudio: (src: string, options?: UseAudioOptions) => UseAudioReturn;
@@ -0,0 +1,101 @@
1
+ import { HookTarget } from '../../utils/helpers';
2
+ import { StateRef } from '../useRefState/useRefState';
3
+ export declare const timeRangeToArray: (timeRanges: TimeRanges) => [number, number][];
4
+ /** The media source configuration type */
5
+ export interface UseMediaSource {
6
+ /** The media attribute of the media */
7
+ media?: string;
8
+ /** The source URL of the media */
9
+ src: string;
10
+ /** The MIME type of the media */
11
+ type?: string;
12
+ }
13
+ /** The media controls return type */
14
+ export interface UseMediaControlsReturn {
15
+ /** Whether the media is currently buffering */
16
+ buffered: [number, number][];
17
+ /** The current playback position in seconds */
18
+ currentTime: number;
19
+ /** The total duration of the media in seconds */
20
+ duration: number;
21
+ /** Whether the media has ended */
22
+ ended: boolean;
23
+ /** Whether the media is currently muted */
24
+ muted: boolean;
25
+ /** The current playback rate (1.0 is normal speed) */
26
+ playbackRate: number;
27
+ /** Whether the media is currently playing */
28
+ playing: boolean;
29
+ /** Whether the media is currently seeking */
30
+ seeking: boolean;
31
+ /** Whether the media is currently stalled */
32
+ stalled: boolean;
33
+ /** The current volume level (0.0 to 1.0) */
34
+ volume: number;
35
+ /** Whether the media is currently waiting */
36
+ waiting: boolean;
37
+ /** Set the playback rate */
38
+ changePlaybackRate: (rate: number) => void;
39
+ /** Set the volume level (0.0 to 1.0) */
40
+ changeVolume: (volume: number) => void;
41
+ /** Set the muted state */
42
+ mute: () => void;
43
+ /** Pause the media */
44
+ pause: () => void;
45
+ /** Start playing the media */
46
+ play: () => Promise<void>;
47
+ /** Seek to a specific time in seconds */
48
+ seek: (time: number) => void;
49
+ /** Toggle between play and pause */
50
+ toggle: () => Promise<void>;
51
+ /** Set the unmuted state */
52
+ unmute: () => void;
53
+ }
54
+ export interface UseMediaControls {
55
+ (target: HookTarget, src: string): UseMediaControlsReturn;
56
+ (target: HookTarget, options: UseMediaSource): UseMediaControlsReturn;
57
+ <Target extends HTMLMediaElement>(src: string): UseMediaControlsReturn & {
58
+ ref: StateRef<Target>;
59
+ };
60
+ <Target extends HTMLMediaElement>(options: UseMediaSource): UseMediaControlsReturn & {
61
+ ref: StateRef<Target>;
62
+ };
63
+ }
64
+ /**
65
+ * @name useMediaControls
66
+ * @description Hook that provides controls for HTML media elements (audio/video)
67
+ * @category Browser
68
+ *
69
+ * @overload
70
+ * @param {HookTarget} target The target media element
71
+ * @param {string} src The source URL of the media
72
+ * @returns {UseMediaControlsReturn} An object containing media controls and state
73
+ *
74
+ * @example
75
+ * const { playing, play, pause } = useMediaControls(videoRef, 'video.mp4');
76
+ *
77
+ * @overload
78
+ * @param {HookTarget} target The target media element
79
+ * @param {UseMediaSource} options The media source configuration
80
+ * @returns {UseMediaControlsReturn} An object containing media controls and state
81
+ *
82
+ * @example
83
+ * const { playing, play, pause } = useMediaControls(audioRef, { src: 'audio.mp3', type: 'audio/mp3' });
84
+ *
85
+ * @overload
86
+ * @template Target The target media element type
87
+ * @param {string} src The source URL of the media
88
+ * @returns {UseMediaControlsReturn & { ref: StateRef<Target> }} An object containing media controls, state and ref
89
+ *
90
+ * @example
91
+ * const { ref, playing, play, pause } = useMediaControls<HTMLVideoElement>('video.mp4');
92
+ *
93
+ * @overload
94
+ * @template Target The target media element type
95
+ * @param {UseMediaSource} options The media source configuration
96
+ * @returns {UseMediaControlsReturn & { ref: StateRef<Target> }} An object containing media controls, state and ref
97
+ *
98
+ * @example
99
+ * const { ref, playing, play, pause } = useMediaControls<HTMLVideoElement>({ src: 'video.mp4', type: 'video/mp4' });
100
+ */
101
+ export declare const useMediaControls: UseMediaControls;
@@ -0,0 +1,53 @@
1
+ import { HookTarget } from '../../utils/helpers';
2
+ import { StateRef } from '../useRefState/useRefState';
3
+ /** The use picture in picture options type */
4
+ export interface UsePictureInPictureOptions {
5
+ /** The callback when Picture-in-Picture mode is entered */
6
+ onEnter?: () => void;
7
+ /** The callback when Picture-in-Picture mode is exited */
8
+ onExit?: () => void;
9
+ }
10
+ /** The use picture in picture return type */
11
+ export interface UsePictureInPictureReturn {
12
+ /** Whether Picture-in-Picture mode is currently active */
13
+ open: boolean;
14
+ /** Whether Picture-in-Picture mode is supported by the browser */
15
+ supported: boolean;
16
+ /** Request to enter Picture-in-Picture mode */
17
+ enter: () => Promise<void>;
18
+ /** Request to exit Picture-in-Picture mode */
19
+ exit: () => Promise<void>;
20
+ /** Toggle Picture-in-Picture mode */
21
+ toggle: () => Promise<void>;
22
+ }
23
+ export interface UsePictureInPicture {
24
+ (target: HookTarget, options?: UsePictureInPictureOptions): UsePictureInPictureReturn;
25
+ (options?: UsePictureInPictureOptions): UsePictureInPictureReturn & {
26
+ ref: StateRef<HTMLVideoElement>;
27
+ };
28
+ }
29
+ /**
30
+ * @name usePictureInPicture
31
+ * @description - Hook that provides Picture-in-Picture functionality for video elements
32
+ * @category Browser
33
+ *
34
+ * @browserapi window.PictureInPicture https://developer.mozilla.org/en-US/docs/Web/API/Picture-in-Picture_API
35
+ *
36
+ * @overload
37
+ * @param {HookTarget} target The target video element
38
+ * @param {() => void} [options.onEnter] Callback when Picture-in-Picture mode is entered
39
+ * @param {() => void} [options.onExit] Callback when Picture-in-Picture mode is exited
40
+ * @returns {UsePictureInPictureReturn} An object containing Picture-in-Picture state and controls
41
+ *
42
+ * @example
43
+ * const { open, supported, enter, exit, toggle } = usePictureInPicture(videoRef);
44
+ *
45
+ * @overload
46
+ * @param {() => void} [options.onEnter] Callback when Picture-in-Picture mode is entered
47
+ * @param {() => void} [options.onExit] Callback when Picture-in-Picture mode is exited
48
+ * @returns {UsePictureInPictureReturn & { ref: StateRef<HTMLVideoElement> }} An object containing Picture-in-Picture state, controls and ref
49
+ *
50
+ * @example
51
+ * const { ref, open, supported, enter, exit, toggle } = usePictureInPicture();
52
+ */
53
+ export declare const usePictureInPicture: UsePictureInPicture;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@siberiacancode/reactuse",
3
- "version": "0.2.19",
3
+ "version": "0.2.20",
4
4
  "description": "The ultimate collection of react hooks",
5
5
  "author": {
6
6
  "name": "SIBERIA CAN CODE 🧊",
@@ -72,11 +72,11 @@
72
72
  "@types/react-dom": "^19.1.6",
73
73
  "@types/web-bluetooth": "^0.0.21",
74
74
  "@vitejs/plugin-react": "^4.6.0",
75
- "core-js": "^3.43.0",
75
+ "core-js": "^3.44.0",
76
76
  "react": "^19.1.0",
77
77
  "react-dom": "^19.1.0",
78
78
  "shx": "^0.4.0",
79
- "vite": "^7.0.2",
79
+ "vite": "^7.0.4",
80
80
  "vite-plugin-dts": "^4.5.4",
81
81
  "vitest": "^3.2.4"
82
82
  },