@zodal/media 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.
Files changed (69) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +73 -2
  3. package/dist/chunk-3JIQJ7J6.js +148 -0
  4. package/dist/chunk-3JIQJ7J6.js.map +1 -0
  5. package/dist/chunk-7I3V4HKP.js +132 -0
  6. package/dist/chunk-7I3V4HKP.js.map +1 -0
  7. package/dist/chunk-AMK7QKN7.js +50 -0
  8. package/dist/chunk-AMK7QKN7.js.map +1 -0
  9. package/dist/chunk-NBKMSPYQ.js +46 -0
  10. package/dist/chunk-NBKMSPYQ.js.map +1 -0
  11. package/dist/chunk-P3EWPYFQ.js +42 -0
  12. package/dist/chunk-P3EWPYFQ.js.map +1 -0
  13. package/dist/chunk-YBCEHG5I.js +68 -0
  14. package/dist/chunk-YBCEHG5I.js.map +1 -0
  15. package/dist/commands.cjs +198 -0
  16. package/dist/commands.cjs.map +1 -0
  17. package/dist/commands.d.cts +17 -0
  18. package/dist/commands.d.ts +17 -0
  19. package/dist/commands.js +171 -0
  20. package/dist/commands.js.map +1 -0
  21. package/dist/cues.cjs +78 -0
  22. package/dist/cues.cjs.map +1 -0
  23. package/dist/cues.d.cts +39 -0
  24. package/dist/cues.d.ts +39 -0
  25. package/dist/cues.js +15 -0
  26. package/dist/cues.js.map +1 -0
  27. package/dist/follow.cjs +162 -0
  28. package/dist/follow.cjs.map +1 -0
  29. package/dist/follow.d.cts +83 -0
  30. package/dist/follow.d.ts +83 -0
  31. package/dist/follow.js +19 -0
  32. package/dist/follow.js.map +1 -0
  33. package/dist/index.cjs +510 -0
  34. package/dist/index.cjs.map +1 -0
  35. package/dist/index.d.cts +6 -0
  36. package/dist/index.d.ts +6 -0
  37. package/dist/index.js +59 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/playback.cjs +72 -0
  40. package/dist/playback.cjs.map +1 -0
  41. package/dist/playback.d.cts +47 -0
  42. package/dist/playback.d.ts +47 -0
  43. package/dist/playback.js +11 -0
  44. package/dist/playback.js.map +1 -0
  45. package/dist/sleep.cjs +176 -0
  46. package/dist/sleep.cjs.map +1 -0
  47. package/dist/sleep.d.cts +99 -0
  48. package/dist/sleep.d.ts +99 -0
  49. package/dist/sleep.js +15 -0
  50. package/dist/sleep.js.map +1 -0
  51. package/dist/timed-text.cjs +155 -0
  52. package/dist/timed-text.cjs.map +1 -0
  53. package/dist/timed-text.d.cts +44 -0
  54. package/dist/timed-text.d.ts +44 -0
  55. package/dist/timed-text.js +9 -0
  56. package/dist/timed-text.js.map +1 -0
  57. package/dist/transport.cjs +167 -0
  58. package/dist/transport.cjs.map +1 -0
  59. package/dist/transport.d.cts +74 -0
  60. package/dist/transport.d.ts +74 -0
  61. package/dist/transport.js +110 -0
  62. package/dist/transport.js.map +1 -0
  63. package/dist/vtt.cjs +66 -0
  64. package/dist/vtt.cjs.map +1 -0
  65. package/dist/vtt.d.cts +22 -0
  66. package/dist/vtt.d.ts +22 -0
  67. package/dist/vtt.js +7 -0
  68. package/dist/vtt.js.map +1 -0
  69. package/package.json +155 -4
@@ -0,0 +1,110 @@
1
+ import {
2
+ seekLanded
3
+ } from "./chunk-NBKMSPYQ.js";
4
+
5
+ // src/transport.ts
6
+ import { createStore } from "zustand/vanilla";
7
+ var urlSource = (ref) => ({
8
+ id: ref,
9
+ src: ref,
10
+ title: decodeURIComponent(ref.split("/").pop()?.split("?")[0] ?? ref)
11
+ });
12
+ var clamp = (n, lo, hi) => Math.min(hi, Math.max(lo, n));
13
+ var DEFAULT_SKIP_BACK_S = 15;
14
+ var DEFAULT_SKIP_AHEAD_S = 30;
15
+ function createMediaPlayer(port, options = {}) {
16
+ const { load, skipBackS = DEFAULT_SKIP_BACK_S, skipAheadS = DEFAULT_SKIP_AHEAD_S } = options;
17
+ const store = createStore(() => ({
18
+ queue: [],
19
+ index: -1,
20
+ playing: false,
21
+ time: 0,
22
+ duration: 0,
23
+ rate: 1,
24
+ volume: 1
25
+ }));
26
+ const set = store.setState;
27
+ const get = store.getState;
28
+ const sync = () => set({ time: port.currentTime, duration: port.duration || 0, playing: !port.paused });
29
+ let soughtAfterEnd = false;
30
+ let held = null;
31
+ const select = (index) => {
32
+ const item = get().queue[index];
33
+ if (!item) return;
34
+ set({ index });
35
+ load?.(item, port);
36
+ if (item.resumeAt) port.currentTime = item.resumeAt;
37
+ sync();
38
+ };
39
+ const player = {
40
+ store,
41
+ port,
42
+ sync,
43
+ async play() {
44
+ if (get().index < 0 && get().queue.length) select(0);
45
+ if (soughtAfterEnd) {
46
+ held?.abort();
47
+ const mine = held = new AbortController();
48
+ try {
49
+ await seekLanded(port, { signal: mine.signal });
50
+ } catch {
51
+ return;
52
+ } finally {
53
+ if (held === mine) held = null;
54
+ }
55
+ }
56
+ soughtAfterEnd = false;
57
+ await port.play();
58
+ sync();
59
+ },
60
+ pause() {
61
+ held?.abort();
62
+ port.pause();
63
+ sync();
64
+ },
65
+ async toggle() {
66
+ if (held) player.pause();
67
+ else if (port.paused) await player.play();
68
+ else player.pause();
69
+ },
70
+ seekTo(seconds) {
71
+ const max = port.duration || Infinity;
72
+ soughtAfterEnd = soughtAfterEnd || !!port.ended;
73
+ port.currentTime = clamp(seconds, 0, max);
74
+ sync();
75
+ },
76
+ skipBy(delta) {
77
+ player.seekTo(port.currentTime + delta);
78
+ },
79
+ setRate(rate) {
80
+ port.playbackRate = clamp(rate, 0.25, 4);
81
+ set({ rate: port.playbackRate });
82
+ },
83
+ setVolume(volume) {
84
+ port.volume = clamp(volume, 0, 1);
85
+ set({ volume: port.volume });
86
+ },
87
+ enqueue(item, { next = false } = {}) {
88
+ const { queue, index } = get();
89
+ const at = next ? index + 1 : queue.length;
90
+ const q = [...queue.slice(0, at), item, ...queue.slice(at)];
91
+ set({ queue: q });
92
+ if (index < 0) select(0);
93
+ },
94
+ next() {
95
+ if (get().index + 1 < get().queue.length) select(get().index + 1);
96
+ },
97
+ previous() {
98
+ if (port.currentTime > skipBackS / 3 || get().index <= 0) player.seekTo(0);
99
+ else select(get().index - 1);
100
+ }
101
+ };
102
+ void skipBackS;
103
+ void skipAheadS;
104
+ return player;
105
+ }
106
+ export {
107
+ createMediaPlayer,
108
+ urlSource
109
+ };
110
+ //# sourceMappingURL=transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/transport.ts"],"sourcesContent":["/**\n * The transport: a headless media player with no DOM and no React, over any `MediaPort`.\n *\n * `MediaPort` is the part of an HTMLMediaElement the player uses (an element is one as it is; a\n * test fake, a wall clock or an embed adapter can be one too). `createMediaPlayer` is a zustand\n * store over a port, with a queue. Every action is also an acture command (`./commands`), so\n * keyboard, Media Session, a palette, MCP or gesture input are all just senders.\n *\n * Moved here from `@zodal/speech/media`, its seed (i2mint/zodal-speech#4).\n */\nimport { createStore, type StoreApi } from 'zustand/vanilla';\nimport { seekLanded, type SeekablePort } from './playback.js';\n\n/** The part of an HTMLMediaElement the player uses. */\nexport interface MediaPort extends SeekablePort {\n currentTime: number;\n readonly duration: number;\n readonly paused: boolean;\n playbackRate: number;\n volume: number;\n play(): Promise<void> | void;\n pause(): void;\n}\n\n/** A playable item. `src` is a URL the port can load (a presigned S3 URL, a stream route, a file URL). */\nexport interface MediaItem {\n id: string;\n src: string;\n title: string;\n kind?: 'audio' | 'video';\n /** Where to resume, in seconds. */\n resumeAt?: number;\n}\n\n/** Turns a source reference into an item. A source is any function with this shape. */\nexport type MediaSource = (ref: string) => MediaItem | Promise<MediaItem>;\n\n/** The simplest source: a URL (S3, a stream route or an HTML media element's file) becomes an item. */\nexport const urlSource: MediaSource = (ref) => ({\n id: ref,\n src: ref,\n title: decodeURIComponent(ref.split('/').pop()?.split('?')[0] ?? ref),\n});\n\nexport interface MediaState {\n queue: MediaItem[];\n index: number;\n playing: boolean;\n time: number;\n duration: number;\n rate: number;\n volume: number;\n}\n\nexport interface MediaPlayerOptions {\n /** Called when the current item changes, so the host can set the element's `src`. */\n load?: (item: MediaItem, port: MediaPort) => void;\n skipBackS?: number;\n skipAheadS?: number;\n}\n\nconst clamp = (n: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, n));\nconst DEFAULT_SKIP_BACK_S = 15;\nconst DEFAULT_SKIP_AHEAD_S = 30;\n\nexport interface MediaPlayer {\n store: StoreApi<MediaState>;\n port: MediaPort;\n play(): Promise<void>;\n pause(): void;\n toggle(): Promise<void>;\n seekTo(seconds: number): void;\n skipBy(deltaSeconds: number): void;\n setRate(rate: number): void;\n setVolume(volume: number): void;\n enqueue(item: MediaItem, opts?: { next?: boolean }): void;\n next(): void;\n previous(): void;\n /** Pull time and duration from the port into the store; call from `timeupdate` or a timer. */\n sync(): void;\n}\n\n/** Creates the headless player over any `MediaPort`. */\nexport function createMediaPlayer(port: MediaPort, options: MediaPlayerOptions = {}): MediaPlayer {\n const { load, skipBackS = DEFAULT_SKIP_BACK_S, skipAheadS = DEFAULT_SKIP_AHEAD_S } = options;\n const store = createStore<MediaState>(() => ({\n queue: [], index: -1, playing: false, time: 0, duration: 0, rate: 1, volume: 1,\n }));\n const set = store.setState;\n const get = store.getState;\n\n const sync = () => set({ time: port.currentTime, duration: port.duration || 0, playing: !port.paused });\n // A seek made after the end must land before play() on WebKit (see playback.ts).\n let soughtAfterEnd = false;\n let held: AbortController | null = null;\n const select = (index: number) => {\n const item = get().queue[index];\n if (!item) return;\n set({ index });\n load?.(item, port);\n if (item.resumeAt) port.currentTime = item.resumeAt;\n sync();\n };\n const player: MediaPlayer = {\n store, port, sync,\n async play() {\n if (get().index < 0 && get().queue.length) select(0);\n if (soughtAfterEnd) {\n held?.abort();\n const mine = (held = new AbortController());\n try {\n await seekLanded(port, { signal: mine.signal });\n } catch {\n return; // paused while the seek was landing\n } finally {\n if (held === mine) held = null;\n }\n }\n soughtAfterEnd = false;\n await port.play();\n sync();\n },\n pause() { held?.abort(); port.pause(); sync(); },\n async toggle() {\n if (held) player.pause(); // a play waiting for its seek: the tap means pause\n else if (port.paused) await player.play();\n else player.pause();\n },\n seekTo(seconds) {\n const max = port.duration || Infinity;\n soughtAfterEnd = soughtAfterEnd || !!port.ended;\n port.currentTime = clamp(seconds, 0, max);\n sync();\n },\n skipBy(delta) { player.seekTo(port.currentTime + delta); },\n setRate(rate) { port.playbackRate = clamp(rate, 0.25, 4); set({ rate: port.playbackRate }); },\n setVolume(volume) { port.volume = clamp(volume, 0, 1); set({ volume: port.volume }); },\n enqueue(item, { next = false } = {}) {\n const { queue, index } = get();\n const at = next ? index + 1 : queue.length;\n const q = [...queue.slice(0, at), item, ...queue.slice(at)];\n set({ queue: q });\n if (index < 0) select(0);\n },\n next() { if (get().index + 1 < get().queue.length) select(get().index + 1); },\n previous() {\n if (port.currentTime > skipBackS / 3 || get().index <= 0) player.seekTo(0);\n else select(get().index - 1);\n },\n };\n void skipBackS; void skipAheadS;\n return player;\n}\n"],"mappings":";;;;;AAUA,SAAS,mBAAkC;AA4BpC,IAAM,YAAyB,CAAC,SAAS;AAAA,EAC9C,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,OAAO,mBAAmB,IAAI,MAAM,GAAG,EAAE,IAAI,GAAG,MAAM,GAAG,EAAE,CAAC,KAAK,GAAG;AACtE;AAmBA,IAAM,QAAQ,CAAC,GAAW,IAAY,OAAe,KAAK,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,CAAC;AACjF,IAAM,sBAAsB;AAC5B,IAAM,uBAAuB;AAoBtB,SAAS,kBAAkB,MAAiB,UAA8B,CAAC,GAAgB;AAChG,QAAM,EAAE,MAAM,YAAY,qBAAqB,aAAa,qBAAqB,IAAI;AACrF,QAAM,QAAQ,YAAwB,OAAO;AAAA,IAC3C,OAAO,CAAC;AAAA,IAAG,OAAO;AAAA,IAAI,SAAS;AAAA,IAAO,MAAM;AAAA,IAAG,UAAU;AAAA,IAAG,MAAM;AAAA,IAAG,QAAQ;AAAA,EAC/E,EAAE;AACF,QAAM,MAAM,MAAM;AAClB,QAAM,MAAM,MAAM;AAElB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Ac,KAAK;AAAA,IAAG;AAAA,IACzD,QAAQ,MAAM;AAAE,WAAK,eAAe,MAAM,MAAM,MAAM,CAAC;AAAG,UAAI,EAAE,MAAM,KAAK,aAAa,CAAC;AAAA,IAAG;AAAA,IAC5F,UAAU,QAAQ;AAAE,WAAK,SAAS,MAAM,QAAQ,GAAG,CAAC;AAAG,UAAI,EAAE,QAAQ,KAAK,OAAO,CAAC;AAAA,IAAG;AAAA,IACrF,QAAQ,MAAM,EAAE,OAAO,MAAM,IAAI,CAAC,GAAG;AACnC,YAAM,EAAE,OAAO,MAAM,IAAI,IAAI;AAC7B,YAAM,KAAK,OAAO,QAAQ,IAAI,MAAM;AACpC,YAAM,IAAI,CAAC,GAAG,MAAM,MAAM,GAAG,EAAE,GAAG,MAAM,GAAG,MAAM,MAAM,EAAE,CAAC;AAC1D,UAAI,EAAE,OAAO,EAAE,CAAC;AAChB,UAAI,QAAQ,EAAG,QAAO,CAAC;AAAA,IACzB;AAAA,IACA,OAAO;AAAE,UAAI,IAAI,EAAE,QAAQ,IAAI,IAAI,EAAE,MAAM,OAAQ,QAAO,IAAI,EAAE,QAAQ,CAAC;AAAA,IAAG;AAAA,IAC5E,WAAW;AACT,UAAI,KAAK,cAAc,YAAY,KAAK,IAAI,EAAE,SAAS,EAAG,QAAO,OAAO,CAAC;AAAA,UACpE,QAAO,IAAI,EAAE,QAAQ,CAAC;AAAA,IAC7B;AAAA,EACF;AACA,OAAK;AAAW,OAAK;AACrB,SAAO;AACT;","names":[]}
package/dist/vtt.cjs ADDED
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/vtt.ts
21
+ var vtt_exports = {};
22
+ __export(vtt_exports, {
23
+ parseWebVtt: () => parseWebVtt
24
+ });
25
+ module.exports = __toCommonJS(vtt_exports);
26
+ var SECONDS_PER_MINUTE = 60;
27
+ var SECONDS_PER_HOUR = 3600;
28
+ var MS_PER_SECOND = 1e3;
29
+ var TIME = String.raw`(?:(\d+):)?(\d{1,2}):(\d{2})[.,](\d{1,3})`;
30
+ var TIMING = new RegExp(String.raw`^\s*${TIME}\s+-->\s+${TIME}`);
31
+ var SKIPPED_BLOCKS = /^(WEBVTT|NOTE|STYLE|REGION)(\s|$)/;
32
+ var VOICE = /<v(?:\.[^\s>]*)?\s+([^>]+)>/;
33
+ var ENTITIES = { amp: "&", lt: "<", gt: ">", nbsp: "\xA0", lrm: "\u200E", rlm: "\u200F", quot: '"', apos: "'" };
34
+ function seconds(h, m, s, frac) {
35
+ return Number(h ?? 0) * SECONDS_PER_HOUR + Number(m) * SECONDS_PER_MINUTE + Number(s) + Number(frac.padEnd(3, "0")) / MS_PER_SECOND;
36
+ }
37
+ function plain(payload) {
38
+ return payload.replace(/<[^>]*>/g, "").replace(/&(\w+);/g, (all, name) => ENTITIES[name] ?? all).replace(/\s+/g, " ").trim();
39
+ }
40
+ function parseWebVtt(text) {
41
+ const blocks = text.replace(/^/, "").replace(/\r\n?/g, "\n").split(/\n{2,}/);
42
+ const cues = [];
43
+ for (const block of blocks) {
44
+ const lines = block.split("\n").filter((line, i) => i > 0 || line.trim() !== "");
45
+ if (!lines.length || SKIPPED_BLOCKS.test(lines[0])) continue;
46
+ const at = lines.findIndex((line) => TIMING.test(line));
47
+ if (at < 0 || at > 1) continue;
48
+ const m = TIMING.exec(lines[at]);
49
+ const payload = lines.slice(at + 1).join("\n");
50
+ const cue = {
51
+ start: seconds(m[1], m[2], m[3], m[4]),
52
+ end: seconds(m[5], m[6], m[7], m[8]),
53
+ text: plain(payload)
54
+ };
55
+ if (at === 1 && lines[0].trim()) cue.id = lines[0].trim();
56
+ const voice = VOICE.exec(payload);
57
+ if (voice) cue.speaker = voice[1].trim();
58
+ cues.push(cue);
59
+ }
60
+ return cues.sort((a, b) => a.start - b.start);
61
+ }
62
+ // Annotate the CommonJS export names for ESM import in node:
63
+ 0 && (module.exports = {
64
+ parseWebVtt
65
+ });
66
+ //# sourceMappingURL=vtt.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/vtt.ts"],"sourcesContent":["/**\n * WebVTT (and SRT) text to cues. Pure, no DOM.\n *\n * Captions, a transcript or chapters often arrive as a `.vtt` file beside the audio: every\n * captioning tool writes it, and `<track kind=\"chapters\">` uses the same format with one title\n * per cue. `parseWebVtt` reads the cue blocks and skips the header, `NOTE`, `STYLE` and `REGION`\n * blocks. It tolerates SRT too (numbered blocks, a comma before the milliseconds). Markup in a\n * cue's text is removed; a voice tag (`<v Ana>`) becomes the cue's `speaker`.\n */\nimport type { CueLike } from './cues.js';\n\n/** A cue read from WebVTT: always with its text, and with its id and speaker when present. */\nexport interface VttCue extends CueLike {\n text: string;\n id?: string;\n speaker?: string;\n}\n\nconst SECONDS_PER_MINUTE = 60;\nconst SECONDS_PER_HOUR = 3600;\nconst MS_PER_SECOND = 1000;\nconst TIME = String.raw`(?:(\\d+):)?(\\d{1,2}):(\\d{2})[.,](\\d{1,3})`;\nconst TIMING = new RegExp(String.raw`^\\s*${TIME}\\s+-->\\s+${TIME}`);\nconst SKIPPED_BLOCKS = /^(WEBVTT|NOTE|STYLE|REGION)(\\s|$)/;\nconst VOICE = /<v(?:\\.[^\\s>]*)?\\s+([^>]+)>/;\nconst ENTITIES: Record<string, string> = { amp: '&', lt: '<', gt: '>', nbsp: ' ', lrm: '‎', rlm: '‏', quot: '\"', apos: \"'\" };\n\nfunction seconds(h: string | undefined, m: string, s: string, frac: string): number {\n return Number(h ?? 0) * SECONDS_PER_HOUR + Number(m) * SECONDS_PER_MINUTE + Number(s) + Number(frac.padEnd(3, '0')) / MS_PER_SECOND;\n}\n\nfunction plain(payload: string): string {\n return payload\n .replace(/<[^>]*>/g, '')\n .replace(/&(\\w+);/g, (all, name: string) => ENTITIES[name] ?? all)\n .replace(/\\s+/g, ' ')\n .trim();\n}\n\n/** The cues of a WebVTT (or SRT) text, in time order. Blocks without a timing line are skipped. */\nexport function parseWebVtt(text: string): VttCue[] {\n const blocks = text.replace(/^/, '').replace(/\\r\\n?/g, '\\n').split(/\\n{2,}/);\n const cues: VttCue[] = [];\n for (const block of blocks) {\n const lines = block.split('\\n').filter((line, i) => i > 0 || line.trim() !== '');\n if (!lines.length || SKIPPED_BLOCKS.test(lines[0])) continue;\n const at = lines.findIndex((line) => TIMING.test(line));\n if (at < 0 || at > 1) continue;\n const m = TIMING.exec(lines[at]) as RegExpExecArray;\n const payload = lines.slice(at + 1).join('\\n');\n const cue: VttCue = {\n start: seconds(m[1], m[2], m[3], m[4]),\n end: seconds(m[5], m[6], m[7], m[8]),\n text: plain(payload),\n };\n if (at === 1 && lines[0].trim()) cue.id = lines[0].trim();\n const voice = VOICE.exec(payload);\n if (voice) cue.speaker = voice[1].trim();\n cues.push(cue);\n }\n return cues.sort((a, b) => a.start - b.start);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBA,IAAM,qBAAqB;AAC3B,IAAM,mBAAmB;AACzB,IAAM,gBAAgB;AACtB,IAAM,OAAO,OAAO;AACpB,IAAM,SAAS,IAAI,OAAO,OAAO,UAAU,IAAI,YAAY,IAAI,EAAE;AACjE,IAAM,iBAAiB;AACvB,IAAM,QAAQ;AACd,IAAM,WAA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,MAAM,MAAM,OAAO;AAAA,IACrB;AACA,QAAI,OAAO,KAAK,MAAM,CAAC,EAAE,KAAK,EAAG,KAAI,KAAK,MAAM,CAAC,EAAE,KAAK;AACxD,UAAM,QAAQ,MAAM,KAAK,OAAO;AAChC,QAAI,MAAO,KAAI,UAAU,MAAM,CAAC,EAAE,KAAK;AACvC,SAAK,KAAK,GAAG;AAAA,EACf;AACA,SAAO,KAAK,KAAK,CAAC,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK;AAC9C;","names":[]}
package/dist/vtt.d.cts ADDED
@@ -0,0 +1,22 @@
1
+ import { CueLike } from './cues.cjs';
2
+
3
+ /**
4
+ * WebVTT (and SRT) text to cues. Pure, no DOM.
5
+ *
6
+ * Captions, a transcript or chapters often arrive as a `.vtt` file beside the audio: every
7
+ * captioning tool writes it, and `<track kind="chapters">` uses the same format with one title
8
+ * per cue. `parseWebVtt` reads the cue blocks and skips the header, `NOTE`, `STYLE` and `REGION`
9
+ * blocks. It tolerates SRT too (numbered blocks, a comma before the milliseconds). Markup in a
10
+ * cue's text is removed; a voice tag (`<v Ana>`) becomes the cue's `speaker`.
11
+ */
12
+
13
+ /** A cue read from WebVTT: always with its text, and with its id and speaker when present. */
14
+ interface VttCue extends CueLike {
15
+ text: string;
16
+ id?: string;
17
+ speaker?: string;
18
+ }
19
+ /** The cues of a WebVTT (or SRT) text, in time order. Blocks without a timing line are skipped. */
20
+ declare function parseWebVtt(text: string): VttCue[];
21
+
22
+ export { type VttCue, parseWebVtt };
package/dist/vtt.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { CueLike } from './cues.js';
2
+
3
+ /**
4
+ * WebVTT (and SRT) text to cues. Pure, no DOM.
5
+ *
6
+ * Captions, a transcript or chapters often arrive as a `.vtt` file beside the audio: every
7
+ * captioning tool writes it, and `<track kind="chapters">` uses the same format with one title
8
+ * per cue. `parseWebVtt` reads the cue blocks and skips the header, `NOTE`, `STYLE` and `REGION`
9
+ * blocks. It tolerates SRT too (numbered blocks, a comma before the milliseconds). Markup in a
10
+ * cue's text is removed; a voice tag (`<v Ana>`) becomes the cue's `speaker`.
11
+ */
12
+
13
+ /** A cue read from WebVTT: always with its text, and with its id and speaker when present. */
14
+ interface VttCue extends CueLike {
15
+ text: string;
16
+ id?: string;
17
+ speaker?: string;
18
+ }
19
+ /** The cues of a WebVTT (or SRT) text, in time order. Blocks without a timing line are skipped. */
20
+ declare function parseWebVtt(text: string): VttCue[];
21
+
22
+ export { type VttCue, parseWebVtt };
package/dist/vtt.js ADDED
@@ -0,0 +1,7 @@
1
+ import {
2
+ parseWebVtt
3
+ } from "./chunk-P3EWPYFQ.js";
4
+ export {
5
+ parseWebVtt
6
+ };
7
+ //# sourceMappingURL=vtt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -1,6 +1,157 @@
1
1
  {
2
2
  "name": "@zodal/media",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Headless audio and media UI affordances for zodal: timed text (transcripts, lyrics, subtitles) that follows the voice, a safe seek-and-play, a transport with a queue, and its commands.",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ },
20
+ "./cues": {
21
+ "import": {
22
+ "types": "./dist/cues.d.ts",
23
+ "default": "./dist/cues.js"
24
+ },
25
+ "require": {
26
+ "types": "./dist/cues.d.cts",
27
+ "default": "./dist/cues.cjs"
28
+ }
29
+ },
30
+ "./vtt": {
31
+ "import": {
32
+ "types": "./dist/vtt.d.ts",
33
+ "default": "./dist/vtt.js"
34
+ },
35
+ "require": {
36
+ "types": "./dist/vtt.d.cts",
37
+ "default": "./dist/vtt.cjs"
38
+ }
39
+ },
40
+ "./playback": {
41
+ "import": {
42
+ "types": "./dist/playback.d.ts",
43
+ "default": "./dist/playback.js"
44
+ },
45
+ "require": {
46
+ "types": "./dist/playback.d.cts",
47
+ "default": "./dist/playback.cjs"
48
+ }
49
+ },
50
+ "./follow": {
51
+ "import": {
52
+ "types": "./dist/follow.d.ts",
53
+ "default": "./dist/follow.js"
54
+ },
55
+ "require": {
56
+ "types": "./dist/follow.d.cts",
57
+ "default": "./dist/follow.cjs"
58
+ }
59
+ },
60
+ "./timed-text": {
61
+ "import": {
62
+ "types": "./dist/timed-text.d.ts",
63
+ "default": "./dist/timed-text.js"
64
+ },
65
+ "require": {
66
+ "types": "./dist/timed-text.d.cts",
67
+ "default": "./dist/timed-text.cjs"
68
+ }
69
+ },
70
+ "./sleep": {
71
+ "import": {
72
+ "types": "./dist/sleep.d.ts",
73
+ "default": "./dist/sleep.js"
74
+ },
75
+ "require": {
76
+ "types": "./dist/sleep.d.cts",
77
+ "default": "./dist/sleep.cjs"
78
+ }
79
+ },
80
+ "./transport": {
81
+ "import": {
82
+ "types": "./dist/transport.d.ts",
83
+ "default": "./dist/transport.js"
84
+ },
85
+ "require": {
86
+ "types": "./dist/transport.d.cts",
87
+ "default": "./dist/transport.cjs"
88
+ }
89
+ },
90
+ "./commands": {
91
+ "import": {
92
+ "types": "./dist/commands.d.ts",
93
+ "default": "./dist/commands.js"
94
+ },
95
+ "require": {
96
+ "types": "./dist/commands.d.cts",
97
+ "default": "./dist/commands.cjs"
98
+ }
99
+ }
100
+ },
101
+ "publishConfig": {
102
+ "access": "public"
103
+ },
104
+ "files": [
105
+ "dist"
106
+ ],
107
+ "sideEffects": false,
108
+ "scripts": {
109
+ "build": "tsup",
110
+ "prepare": "tsup",
111
+ "test": "vitest run",
112
+ "typecheck": "tsc --noEmit"
113
+ },
114
+ "peerDependencies": {
115
+ "zustand": "^5.0.3",
116
+ "zod": "^4.0.0",
117
+ "acture": ">=1.3.0 <2.0.0"
118
+ },
119
+ "peerDependenciesMeta": {
120
+ "zustand": {
121
+ "optional": true
122
+ },
123
+ "zod": {
124
+ "optional": true
125
+ },
126
+ "acture": {
127
+ "optional": true
128
+ }
129
+ },
130
+ "devDependencies": {
131
+ "acture": "^1.3.1",
132
+ "jsdom": "^26.0.0",
133
+ "tsup": "^8.0.0",
134
+ "typescript": "^5.7.0",
135
+ "vitest": "^3.0.0",
136
+ "zod": "^4.0.0",
137
+ "zustand": "^5.0.3"
138
+ },
139
+ "license": "MIT",
140
+ "repository": {
141
+ "type": "git",
142
+ "url": "https://github.com/i2mint/zodal-media.git"
143
+ },
144
+ "keywords": [
145
+ "zodal",
146
+ "media",
147
+ "audio",
148
+ "player",
149
+ "transcript",
150
+ "lyrics",
151
+ "subtitles",
152
+ "karaoke",
153
+ "headless",
154
+ "sleep-timer"
155
+ ],
156
+ "packageManager": "pnpm@9.15.0"
157
+ }