bobinejs 0.0.0-stage → 0.1.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.
package/dist/hls.js ADDED
@@ -0,0 +1,38 @@
1
+ // ../../lib/media-hls.ts
2
+ var canPlayNatively = (media) => media.canPlayType("application/vnd.apple.mpegurl") !== "";
3
+ var hlsLoader = (media, src) => {
4
+ if (!/\.m3u8($|\?)/i.test(src) || canPlayNatively(media)) {
5
+ media.src = src;
6
+ return () => {
7
+ media.removeAttribute("src");
8
+ media.load();
9
+ };
10
+ }
11
+ let disposed = false;
12
+ let destroy;
13
+ import('hls.js').then(({ default: Hls }) => {
14
+ if (disposed) return;
15
+ if (!Hls.isSupported()) {
16
+ media.src = src;
17
+ return;
18
+ }
19
+ const hls = new Hls({ enableWorker: true });
20
+ hls.on(Hls.Events.ERROR, (_, data) => {
21
+ if (!data.fatal) return;
22
+ if (data.type === Hls.ErrorTypes.NETWORK_ERROR) hls.startLoad();
23
+ else if (data.type === Hls.ErrorTypes.MEDIA_ERROR) hls.recoverMediaError();
24
+ else hls.destroy();
25
+ });
26
+ hls.loadSource(src);
27
+ hls.attachMedia(media);
28
+ destroy = () => hls.destroy();
29
+ });
30
+ return () => {
31
+ disposed = true;
32
+ destroy?.();
33
+ };
34
+ };
35
+
36
+ export { hlsLoader };
37
+ //# sourceMappingURL=hls.js.map
38
+ //# sourceMappingURL=hls.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../lib/media-hls.ts"],"names":[],"mappings":";AAEA,IAAM,kBAAkB,CAAC,KAAA,KACvB,KAAA,CAAM,WAAA,CAAY,+BAA+B,CAAA,KAAM,EAAA;AAMlD,IAAM,SAAA,GAA+B,CAAC,KAAA,EAAO,GAAA,KAAQ;AAC1D,EAAA,IAAI,CAAC,eAAA,CAAgB,IAAA,CAAK,GAAG,CAAA,IAAK,eAAA,CAAgB,KAAK,CAAA,EAAG;AACxD,IAAA,KAAA,CAAM,GAAA,GAAM,GAAA;AACZ,IAAA,OAAO,MAAM;AACX,MAAA,KAAA,CAAM,gBAAgB,KAAK,CAAA;AAC3B,MAAA,KAAA,CAAM,IAAA,EAAK;AAAA,IACb,CAAA;AAAA,EACF;AAEA,EAAA,IAAI,QAAA,GAAW,KAAA;AACf,EAAA,IAAI,OAAA;AAEJ,EAAA,OAAO,QAAQ,CAAA,CAAE,IAAA,CAAK,CAAC,EAAE,OAAA,EAAS,KAAI,KAAM;AAC1C,IAAA,IAAI,QAAA,EAAU;AACd,IAAA,IAAI,CAAC,GAAA,CAAI,WAAA,EAAY,EAAG;AACtB,MAAA,KAAA,CAAM,GAAA,GAAM,GAAA;AACZ,MAAA;AAAA,IACF;AACA,IAAA,MAAM,MAAM,IAAI,GAAA,CAAI,EAAE,YAAA,EAAc,MAAM,CAAA;AAC1C,IAAA,GAAA,CAAI,GAAG,GAAA,CAAI,MAAA,CAAO,KAAA,EAAO,CAAC,GAAG,IAAA,KAAS;AACpC,MAAA,IAAI,CAAC,KAAK,KAAA,EAAO;AACjB,MAAA,IAAI,KAAK,IAAA,KAAS,GAAA,CAAI,UAAA,CAAW,aAAA,MAAmB,SAAA,EAAU;AAAA,WAAA,IACrD,KAAK,IAAA,KAAS,GAAA,CAAI,UAAA,CAAW,WAAA,MAAiB,iBAAA,EAAkB;AAAA,eAChE,OAAA,EAAQ;AAAA,IACnB,CAAC,CAAA;AACD,IAAA,GAAA,CAAI,WAAW,GAAG,CAAA;AAClB,IAAA,GAAA,CAAI,YAAY,KAAK,CAAA;AACrB,IAAA,OAAA,GAAU,MAAM,IAAI,OAAA,EAAQ;AAAA,EAC9B,CAAC,CAAA;AAED,EAAA,OAAO,MAAM;AACX,IAAA,QAAA,GAAW,IAAA;AACX,IAAA,OAAA,IAAU;AAAA,EACZ,CAAA;AACF","file":"hls.js","sourcesContent":["import type { MediaSourceLoader } from \"@/components/ui/media\"\r\n\r\nconst canPlayNatively = (media: HTMLMediaElement) =>\r\n media.canPlayType(\"application/vnd.apple.mpegurl\") !== \"\"\r\n\r\n/**\r\n * Plays `.m3u8` streams. Safari plays HLS natively; everywhere else hls.js\r\n * is loaded on demand so it never lands in the main bundle.\r\n */\r\nexport const hlsLoader: MediaSourceLoader = (media, src) => {\r\n if (!/\\.m3u8($|\\?)/i.test(src) || canPlayNatively(media)) {\r\n media.src = src\r\n return () => {\r\n media.removeAttribute(\"src\")\r\n media.load()\r\n }\r\n }\r\n\r\n let disposed = false\r\n let destroy: (() => void) | undefined\r\n\r\n import(\"hls.js\").then(({ default: Hls }) => {\r\n if (disposed) return\r\n if (!Hls.isSupported()) {\r\n media.src = src\r\n return\r\n }\r\n const hls = new Hls({ enableWorker: true })\r\n hls.on(Hls.Events.ERROR, (_, data) => {\r\n if (!data.fatal) return\r\n if (data.type === Hls.ErrorTypes.NETWORK_ERROR) hls.startLoad()\r\n else if (data.type === Hls.ErrorTypes.MEDIA_ERROR) hls.recoverMediaError()\r\n else hls.destroy()\r\n })\r\n hls.loadSource(src)\r\n hls.attachMedia(media)\r\n destroy = () => hls.destroy()\r\n })\r\n\r\n return () => {\r\n disposed = true\r\n destroy?.()\r\n }\r\n}\r\n"]}
@@ -0,0 +1,282 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as React from 'react';
3
+
4
+ type MediaTextTrack = {
5
+ label: string;
6
+ language: string;
7
+ kind: "captions" | "subtitles";
8
+ };
9
+ type MediaInfo = {
10
+ title?: string;
11
+ artist?: string;
12
+ album?: string;
13
+ artwork?: {
14
+ src: string;
15
+ sizes?: string;
16
+ type?: string;
17
+ }[];
18
+ };
19
+ type MediaState = {
20
+ paused: boolean;
21
+ ended: boolean;
22
+ started: boolean;
23
+ waiting: boolean;
24
+ currentTime: number;
25
+ duration: number;
26
+ bufferedEnd: number;
27
+ volume: number;
28
+ muted: boolean;
29
+ playbackRate: number;
30
+ fullscreen: boolean;
31
+ pictureInPicture: boolean;
32
+ error: MediaError | null;
33
+ /** Caption and subtitle tracks, in document order. */
34
+ textTracks: MediaTextTrack[];
35
+ /** Index into `textTracks`, or -1 when captions are off. */
36
+ textTrack: number;
37
+ /** Text of the cues active right now, one entry per cue. */
38
+ cues: string[];
39
+ };
40
+ type MediaStoreOptions = {
41
+ /** localStorage key used to remember volume, mute and speed. Off by default. */
42
+ persistKey?: string;
43
+ };
44
+ type Listener = () => void;
45
+ /**
46
+ * Framework-agnostic store over any HTMLMediaElement. React bindings,
47
+ * web components, or anything else can subscribe to it.
48
+ */
49
+ declare function createMediaStore({ persistKey }?: MediaStoreOptions): {
50
+ play: () => Promise<void>;
51
+ pause: () => void | undefined;
52
+ toggle: () => void | Promise<void>;
53
+ seek: (time: number) => void;
54
+ seekBy: (delta: number) => void;
55
+ /** Jump to a fraction (0–1) of the duration. */
56
+ seekToRatio: (ratio: number) => void;
57
+ setVolume: (volume: number) => void;
58
+ toggleMute: () => void;
59
+ setPlaybackRate: (rate: number) => void;
60
+ /** Select a caption track by index, or -1 to turn captions off. */
61
+ setTextTrack: (index: number) => void;
62
+ toggleCaptions: () => void;
63
+ /** Reload the current source after an error. */
64
+ retry: () => void;
65
+ setMetadata: (next: MediaInfo | null) => void;
66
+ toggleFullscreen: () => Promise<void>;
67
+ togglePictureInPicture: () => Promise<void>;
68
+ getState: () => MediaState;
69
+ getServerState: () => MediaState;
70
+ getMedia: () => HTMLMediaElement | null;
71
+ subscribe: (listener: Listener) => () => boolean;
72
+ attach: (el: HTMLMediaElement | null) => void;
73
+ setContainer: (el: HTMLElement | null) => void;
74
+ };
75
+ type MediaStore = ReturnType<typeof createMediaStore>;
76
+ declare function formatTime(seconds: number): string;
77
+ /** Human-readable message for a MediaError code. */
78
+ declare function describeMediaError(error: MediaError | null): "Playback was aborted." | "A network error stopped the download." | "This media could not be decoded." | "This format or source isn't supported." | "Something went wrong during playback.";
79
+
80
+ declare function useMediaStore(): {
81
+ play: () => Promise<void>;
82
+ pause: () => void | undefined;
83
+ toggle: () => void | Promise<void>;
84
+ seek: (time: number) => void;
85
+ seekBy: (delta: number) => void;
86
+ seekToRatio: (ratio: number) => void;
87
+ setVolume: (volume: number) => void;
88
+ toggleMute: () => void;
89
+ setPlaybackRate: (rate: number) => void;
90
+ setTextTrack: (index: number) => void;
91
+ toggleCaptions: () => void;
92
+ retry: () => void;
93
+ setMetadata: (next: MediaInfo | null) => void;
94
+ toggleFullscreen: () => Promise<void>;
95
+ togglePictureInPicture: () => Promise<void>;
96
+ getState: () => MediaState;
97
+ getServerState: () => MediaState;
98
+ getMedia: () => HTMLMediaElement | null;
99
+ subscribe: (listener: () => void) => () => boolean;
100
+ attach: (el: HTMLMediaElement | null) => void;
101
+ setContainer: (el: HTMLElement | null) => void;
102
+ };
103
+ declare function useMedia<T>(selector: (state: MediaState) => T): T;
104
+ type MediaRootProps = React.ComponentProps<"div"> & {
105
+ /** Milliseconds of pointer inactivity before controls hide during playback. */
106
+ idleTimeout?: number;
107
+ /** Remember volume, mute and speed in localStorage under this key. */
108
+ persistKey?: string;
109
+ /** Title, artist and artwork for OS media controls (Media Session API). */
110
+ metadata?: MediaInfo;
111
+ /** Enable keyboard shortcuts while focus is inside the player. */
112
+ hotkeys?: boolean;
113
+ /** Small labels over the buttons on hover and keyboard focus, with their shortcut. */
114
+ tooltips?: boolean;
115
+ };
116
+ declare function MediaRoot({ className, idleTimeout, persistKey, metadata, hotkeys, tooltips, onPointerMove, onPointerDown, onPointerLeave, onKeyDown, ref, ...props }: MediaRootProps): react_jsx_runtime.JSX.Element;
117
+ /**
118
+ * Attaches a source the element can't play natively (HLS, DASH, MSE).
119
+ * Return a cleanup function to tear the adapter down when `src` changes.
120
+ */
121
+ type MediaSourceLoader = (media: HTMLMediaElement, src: string) => void | (() => void);
122
+ type MediaElementProps<T> = T & {
123
+ /** Custom source adapter, e.g. `hlsLoader` from `@/lib/media-hls`. */
124
+ loader?: MediaSourceLoader;
125
+ };
126
+ type MediaVideoProps = MediaElementProps<React.ComponentProps<"video">>;
127
+ declare function MediaVideo({ className, ref, src, loader, ...props }: MediaVideoProps): react_jsx_runtime.JSX.Element;
128
+ type MediaAudioProps = MediaElementProps<React.ComponentProps<"audio">>;
129
+ declare function MediaAudio({ ref, src, loader, ...props }: MediaAudioProps): react_jsx_runtime.JSX.Element;
130
+ type MediaTooltipAlign = "start" | "center" | "end";
131
+ type MediaButtonProps = React.ComponentProps<"button"> & {
132
+ /** Tooltip text, shown when the root has `tooltips`. `false` hides it. */
133
+ tooltip?: React.ReactNode;
134
+ /** Shortcut shown beside the tooltip when the root has `hotkeys`. */
135
+ shortcut?: string;
136
+ /** Pin the tooltip to an edge for buttons at either end of a bar. */
137
+ tooltipAlign?: MediaTooltipAlign;
138
+ };
139
+ declare function MediaButton({ className, type, tooltip, shortcut, tooltipAlign, children, ...props }: MediaButtonProps): react_jsx_runtime.JSX.Element;
140
+ declare function MediaPlayButton({ onClick, ...props }: MediaButtonProps): react_jsx_runtime.JSX.Element;
141
+ declare function MediaMuteButton({ onClick, ...props }: MediaButtonProps): react_jsx_runtime.JSX.Element;
142
+ declare function MediaFullscreenButton({ onClick, ...props }: MediaButtonProps): react_jsx_runtime.JSX.Element;
143
+ declare function MediaPictureInPictureButton({ onClick, ...props }: MediaButtonProps): react_jsx_runtime.JSX.Element | null;
144
+ type MediaPlaybackRateButtonProps = MediaButtonProps & {
145
+ /** Speeds a click cycles through, in order. */
146
+ rates?: number[];
147
+ };
148
+ declare function MediaPlaybackRateButton({ rates, className, style, onClick, ...props }: MediaPlaybackRateButtonProps): react_jsx_runtime.JSX.Element;
149
+ /**
150
+ * Bar that reveals while the pointer is active, playback is paused,
151
+ * or keyboard focus is inside the player.
152
+ */
153
+ type MediaControlsProps = React.ComponentProps<"div">;
154
+ declare function MediaControls({ className, ...props }: MediaControlsProps): react_jsx_runtime.JSX.Element;
155
+ type MediaSurfaceProps = React.ComponentProps<"button"> & {
156
+ /** Seconds a double-tap on either half seeks by. 0 disables it. */
157
+ doubleTapSeek?: number;
158
+ /** Double-click with a mouse toggles fullscreen. */
159
+ doubleClickFullscreen?: boolean;
160
+ /** Classes for the "±10s" bubble shown after a double-tap seek. */
161
+ indicatorClassName?: string;
162
+ };
163
+ /**
164
+ * Full-bleed click target under the controls. Click toggles playback; on touch,
165
+ * the first tap reveals controls and a double-tap on either half seeks.
166
+ */
167
+ declare function MediaSurface({ className, doubleTapSeek, doubleClickFullscreen, indicatorClassName, onClick, onDoubleClick, onPointerDown, children, ...props }: MediaSurfaceProps): react_jsx_runtime.JSX.Element;
168
+ type MediaSeekProps = Omit<React.ComponentProps<"div">, "children"> & {
169
+ /** Seconds moved per arrow key press. */
170
+ step?: number;
171
+ /** Show a time tooltip while hovering. */
172
+ preview?: boolean;
173
+ previewClassName?: string;
174
+ };
175
+ declare function MediaSeek({ className, step, preview, previewClassName, ...props }: MediaSeekProps): react_jsx_runtime.JSX.Element;
176
+ type MediaVolumeProps = Omit<React.ComponentProps<"div">, "children"> & {
177
+ /** "vertical" fills from the bottom, for a slider in a popover. */
178
+ orientation?: "horizontal" | "vertical";
179
+ };
180
+ declare function MediaVolume({ orientation, className, ...props }: MediaVolumeProps): react_jsx_runtime.JSX.Element;
181
+ type MediaTimeProps = React.ComponentProps<"span"> & {
182
+ type?: "current" | "duration" | "remaining";
183
+ /** Click to show remaining time and back. "remaining" swaps with elapsed. */
184
+ toggle?: boolean;
185
+ };
186
+ declare function MediaTime({ type, toggle, className, ...props }: MediaTimeProps): react_jsx_runtime.JSX.Element;
187
+ type MediaLoadingProps = React.ComponentProps<"span">;
188
+ declare function MediaLoading({ className, ...props }: MediaLoadingProps): react_jsx_runtime.JSX.Element;
189
+ /**
190
+ * Renders active caption cues. Native rendering is disabled so cues can be
191
+ * styled and can slide above the controls when they appear.
192
+ */
193
+ type MediaCaptionsProps = React.ComponentProps<"div">;
194
+ declare function MediaCaptions({ className, ...props }: MediaCaptionsProps): react_jsx_runtime.JSX.Element | null;
195
+ declare function MediaCaptionsButton({ onClick, ...props }: MediaButtonProps): react_jsx_runtime.JSX.Element | null;
196
+ type MediaSettingsProps = Omit<React.ComponentProps<"div">, "children"> & {
197
+ rates?: number[];
198
+ /** Classes for the floating panel. */
199
+ panelClassName?: string;
200
+ };
201
+ /**
202
+ * Popover with playback speed and caption track choices. Arrow keys move
203
+ * between options; Escape or a click outside closes it.
204
+ */
205
+ declare function MediaSettings({ rates, className, panelClassName, ...props }: MediaSettingsProps): react_jsx_runtime.JSX.Element;
206
+ type MediaErrorMessageProps = Omit<React.ComponentProps<"div">, "children"> & {
207
+ /** Override the default message for a given MediaError. */
208
+ message?: (error: MediaError) => React.ReactNode;
209
+ };
210
+ declare function MediaErrorMessage({ className, message, ...props }: MediaErrorMessageProps): react_jsx_runtime.JSX.Element | null;
211
+
212
+ type VideoTrack = {
213
+ src: string;
214
+ label: string;
215
+ srcLang: string;
216
+ kind?: "captions" | "subtitles";
217
+ default?: boolean;
218
+ };
219
+ type VideoPlayerProps = Omit<React.ComponentProps<"video">, "controls"> & {
220
+ /** Classes for the outer frame. `className` targets the <video> element. */
221
+ frameClassName?: string;
222
+ /** WebVTT caption or subtitle files. */
223
+ tracks?: VideoTrack[];
224
+ /** Adapter for sources the browser can't play natively, e.g. HLS. */
225
+ loader?: MediaSourceLoader;
226
+ /** Shown in OS media controls and lock screens. */
227
+ metadata?: MediaInfo;
228
+ /** Remember volume, mute and speed under this localStorage key. */
229
+ persistKey?: string;
230
+ /** Small labels with shortcuts over the controls on hover and focus. On by default. */
231
+ tooltips?: boolean;
232
+ };
233
+ declare function VideoPlayer({ className, frameClassName, tracks, loader, metadata, persistKey, tooltips, children, crossOrigin, ...props }: VideoPlayerProps): react_jsx_runtime.JSX.Element;
234
+
235
+ type AudioPlayerProps = Omit<React.ComponentProps<"audio">, "controls" | "title"> & {
236
+ title?: React.ReactNode;
237
+ description?: React.ReactNode;
238
+ /** Cover image shown beside the controls and in OS media controls. */
239
+ artwork?: string;
240
+ /** Show a playback speed toggle. Useful for podcasts and voice notes. */
241
+ showSpeed?: boolean;
242
+ /** Small labels with shortcuts over the controls on hover and focus. On by default. */
243
+ tooltips?: boolean;
244
+ /** Classes for the outer frame. `className` targets the <audio> element. */
245
+ frameClassName?: string;
246
+ /** Adapter for sources the browser can't play natively, e.g. HLS. */
247
+ loader?: MediaSourceLoader;
248
+ /** Overrides metadata derived from `title`, `description` and `artwork`. */
249
+ metadata?: MediaInfo;
250
+ /** Remember volume, mute and speed under this localStorage key. */
251
+ persistKey?: string;
252
+ };
253
+ declare function AudioPlayer({ title, description, artwork, showSpeed, tooltips, className, frameClassName, loader, metadata, persistKey, ...props }: AudioPlayerProps): react_jsx_runtime.JSX.Element;
254
+
255
+ type MediaIconProps = React.ComponentProps<"svg">;
256
+ /**
257
+ * Optically centred: the filled area's centroid, not the bounding box, sits
258
+ * on the viewBox centre (x = 12), measured from the rendered shape. A
259
+ * box-centred triangle looks shifted right, because its weight is in the flat
260
+ * left side.
261
+ */
262
+ declare function PlayIcon(props: MediaIconProps): react_jsx_runtime.JSX.Element;
263
+ declare function PauseIcon(props: MediaIconProps): react_jsx_runtime.JSX.Element;
264
+ declare function VolumeIcon({ muted, ...props }: MediaIconProps & {
265
+ muted?: boolean;
266
+ }): react_jsx_runtime.JSX.Element;
267
+ declare function EnterFullscreenIcon(props: MediaIconProps): react_jsx_runtime.JSX.Element;
268
+ declare function ExitFullscreenIcon(props: MediaIconProps): react_jsx_runtime.JSX.Element;
269
+ declare function PictureInPictureIcon(props: MediaIconProps): react_jsx_runtime.JSX.Element;
270
+ /** Outlined when off; filled with knocked-out letters when on. */
271
+ declare function CaptionsIcon({ active, ...props }: MediaIconProps & {
272
+ active?: boolean;
273
+ }): react_jsx_runtime.JSX.Element;
274
+ declare function SettingsIcon(props: MediaIconProps): react_jsx_runtime.JSX.Element;
275
+ declare function RetryIcon(props: MediaIconProps): react_jsx_runtime.JSX.Element;
276
+ declare function CheckIcon(props: MediaIconProps): react_jsx_runtime.JSX.Element;
277
+ declare function SeekIcon({ direction, ...props }: MediaIconProps & {
278
+ direction: "back" | "forward";
279
+ }): react_jsx_runtime.JSX.Element;
280
+
281
+ export { AudioPlayer, CaptionsIcon, CheckIcon, EnterFullscreenIcon, ExitFullscreenIcon, MediaAudio, MediaButton, MediaCaptions, MediaCaptionsButton, MediaControls, MediaErrorMessage, MediaFullscreenButton, MediaLoading, MediaMuteButton, MediaPictureInPictureButton, MediaPlayButton, MediaPlaybackRateButton, MediaRoot, MediaSeek, MediaSettings, MediaSurface, MediaTime, MediaVideo, MediaVolume, PauseIcon, PictureInPictureIcon, PlayIcon, RetryIcon, SeekIcon, SettingsIcon, VideoPlayer, VolumeIcon, createMediaStore, describeMediaError, formatTime, useMedia, useMediaStore };
282
+ export type { AudioPlayerProps, MediaAudioProps, MediaButtonProps, MediaCaptionsProps, MediaControlsProps, MediaErrorMessageProps, MediaIconProps, MediaInfo, MediaLoadingProps, MediaPlaybackRateButtonProps, MediaRootProps, MediaSeekProps, MediaSettingsProps, MediaSourceLoader, MediaState, MediaStore, MediaStoreOptions, MediaSurfaceProps, MediaTextTrack, MediaTimeProps, MediaTooltipAlign, MediaVideoProps, MediaVolumeProps, VideoPlayerProps, VideoTrack };