@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.
- package/LICENSE +21 -0
- package/README.md +73 -2
- package/dist/chunk-3JIQJ7J6.js +148 -0
- package/dist/chunk-3JIQJ7J6.js.map +1 -0
- package/dist/chunk-7I3V4HKP.js +132 -0
- package/dist/chunk-7I3V4HKP.js.map +1 -0
- package/dist/chunk-AMK7QKN7.js +50 -0
- package/dist/chunk-AMK7QKN7.js.map +1 -0
- package/dist/chunk-NBKMSPYQ.js +46 -0
- package/dist/chunk-NBKMSPYQ.js.map +1 -0
- package/dist/chunk-P3EWPYFQ.js +42 -0
- package/dist/chunk-P3EWPYFQ.js.map +1 -0
- package/dist/chunk-YBCEHG5I.js +68 -0
- package/dist/chunk-YBCEHG5I.js.map +1 -0
- package/dist/commands.cjs +198 -0
- package/dist/commands.cjs.map +1 -0
- package/dist/commands.d.cts +17 -0
- package/dist/commands.d.ts +17 -0
- package/dist/commands.js +171 -0
- package/dist/commands.js.map +1 -0
- package/dist/cues.cjs +78 -0
- package/dist/cues.cjs.map +1 -0
- package/dist/cues.d.cts +39 -0
- package/dist/cues.d.ts +39 -0
- package/dist/cues.js +15 -0
- package/dist/cues.js.map +1 -0
- package/dist/follow.cjs +162 -0
- package/dist/follow.cjs.map +1 -0
- package/dist/follow.d.cts +83 -0
- package/dist/follow.d.ts +83 -0
- package/dist/follow.js +19 -0
- package/dist/follow.js.map +1 -0
- package/dist/index.cjs +510 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +59 -0
- package/dist/index.js.map +1 -0
- package/dist/playback.cjs +72 -0
- package/dist/playback.cjs.map +1 -0
- package/dist/playback.d.cts +47 -0
- package/dist/playback.d.ts +47 -0
- package/dist/playback.js +11 -0
- package/dist/playback.js.map +1 -0
- package/dist/sleep.cjs +176 -0
- package/dist/sleep.cjs.map +1 -0
- package/dist/sleep.d.cts +99 -0
- package/dist/sleep.d.ts +99 -0
- package/dist/sleep.js +15 -0
- package/dist/sleep.js.map +1 -0
- package/dist/timed-text.cjs +155 -0
- package/dist/timed-text.cjs.map +1 -0
- package/dist/timed-text.d.cts +44 -0
- package/dist/timed-text.d.ts +44 -0
- package/dist/timed-text.js +9 -0
- package/dist/timed-text.js.map +1 -0
- package/dist/transport.cjs +167 -0
- package/dist/transport.cjs.map +1 -0
- package/dist/transport.d.cts +74 -0
- package/dist/transport.d.ts +74 -0
- package/dist/transport.js +110 -0
- package/dist/transport.js.map +1 -0
- package/dist/vtt.cjs +66 -0
- package/dist/vtt.cjs.map +1 -0
- package/dist/vtt.d.cts +22 -0
- package/dist/vtt.d.ts +22 -0
- package/dist/vtt.js +7 -0
- package/dist/vtt.js.map +1 -0
- package/package.json +155 -4
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
cueAt,
|
|
3
|
+
wordAt
|
|
4
|
+
} from "./chunk-AMK7QKN7.js";
|
|
5
|
+
import {
|
|
6
|
+
seekThenPlay
|
|
7
|
+
} from "./chunk-NBKMSPYQ.js";
|
|
8
|
+
|
|
9
|
+
// src/timed-text.ts
|
|
10
|
+
function createTimedText(cues, port, options = {}) {
|
|
11
|
+
const { playOnTap = true, play, follow, ...lookup } = options;
|
|
12
|
+
let state = { cue: -1, word: -1 };
|
|
13
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
14
|
+
let held = null;
|
|
15
|
+
const tick = () => {
|
|
16
|
+
const time = port.currentTime;
|
|
17
|
+
const cue = cueAt(cues, time, lookup);
|
|
18
|
+
const word = wordAt(cues[cue], time);
|
|
19
|
+
if (cue === state.cue && word === state.word) return;
|
|
20
|
+
const previous = state;
|
|
21
|
+
state = { cue, word };
|
|
22
|
+
listeners.forEach((l) => l(state, previous));
|
|
23
|
+
};
|
|
24
|
+
const cancelHeldPlay = () => {
|
|
25
|
+
if (!held) return false;
|
|
26
|
+
held.abort();
|
|
27
|
+
held = null;
|
|
28
|
+
return true;
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
get: () => state,
|
|
32
|
+
subscribe(listener) {
|
|
33
|
+
listeners.add(listener);
|
|
34
|
+
return () => listeners.delete(listener);
|
|
35
|
+
},
|
|
36
|
+
tick,
|
|
37
|
+
tapCue(index) {
|
|
38
|
+
const cue = cues[index];
|
|
39
|
+
if (!cue) return;
|
|
40
|
+
follow?.resume();
|
|
41
|
+
cancelHeldPlay();
|
|
42
|
+
if (playOnTap && port.paused) {
|
|
43
|
+
const mine = new AbortController();
|
|
44
|
+
held = mine;
|
|
45
|
+
seekThenPlay(port, cue.start, { play, signal: mine.signal }).then(
|
|
46
|
+
() => {
|
|
47
|
+
if (held === mine) held = null;
|
|
48
|
+
},
|
|
49
|
+
() => void 0
|
|
50
|
+
// cancelled, or refused: the host's `play` reports a refusal
|
|
51
|
+
);
|
|
52
|
+
} else {
|
|
53
|
+
port.currentTime = cue.start;
|
|
54
|
+
}
|
|
55
|
+
tick();
|
|
56
|
+
},
|
|
57
|
+
cancelHeldPlay,
|
|
58
|
+
dispose() {
|
|
59
|
+
cancelHeldPlay();
|
|
60
|
+
listeners.clear();
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export {
|
|
66
|
+
createTimedText
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=chunk-YBCEHG5I.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/timed-text.ts"],"sourcesContent":["/**\n * A timed text over a media port: which cue and word are being heard, and what a tap on a line\n * does. Renderer-agnostic; a transcript, a lyrics panel and a subtitle line all draw from it.\n *\n * A tap plays from the line by default (a transcript); `playOnTap: false` only moves there (a\n * lyrics panel whose player is elsewhere). Playing from a line uses `seekThenPlay`, so it plays\n * from the line on Safari too after the media has ended.\n */\nimport { cueAt, wordAt, type CueAtOptions, type CueLike } from './cues.js';\nimport { seekThenPlay, type SeekablePort } from './playback.js';\nimport type { Follow } from './follow.js';\n\n/** The part of a media element a timed text uses. */\nexport interface TimedTextPort extends SeekablePort {\n readonly paused: boolean;\n}\n\nexport interface TimedTextState {\n cue: number;\n word: number;\n}\n\nexport interface TimedTextOptions extends CueAtOptions {\n /** A tap on a line plays from it (default) or only moves there. */\n playOnTap?: boolean;\n /** What starting playback means, to catch a refusal; defaults to `port.play()`. */\n play?: () => Promise<void> | void;\n /** A follow state to resume when a line is tapped. */\n follow?: Follow;\n}\n\nexport interface TimedText {\n get(): TimedTextState;\n subscribe(listener: (state: TimedTextState, previous: TimedTextState) => void): () => void;\n /** Read the port's position; call on a frame while playing and on `seeked`. */\n tick(): void;\n /** A person chose line `index`. */\n tapCue(index: number): void;\n /** Cancel a play waiting for its seek (a pause tapped meanwhile). True if there was one. */\n cancelHeldPlay(): boolean;\n /** The view went away: cancel a held play and forget the listeners. */\n dispose(): void;\n}\n\nexport function createTimedText(cues: readonly CueLike[], port: TimedTextPort, options: TimedTextOptions = {}): TimedText {\n const { playOnTap = true, play, follow, ...lookup } = options;\n let state: TimedTextState = { cue: -1, word: -1 };\n const listeners = new Set<(state: TimedTextState, previous: TimedTextState) => void>();\n let held: AbortController | null = null;\n\n const tick = () => {\n const time = port.currentTime;\n const cue = cueAt(cues, time, lookup);\n const word = wordAt(cues[cue], time);\n if (cue === state.cue && word === state.word) return;\n const previous = state;\n state = { cue, word };\n listeners.forEach((l) => l(state, previous));\n };\n const cancelHeldPlay = () => {\n if (!held) return false;\n held.abort();\n held = null;\n return true;\n };\n\n return {\n get: () => state,\n subscribe(listener) {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n tick,\n tapCue(index) {\n const cue = cues[index];\n if (!cue) return;\n follow?.resume();\n cancelHeldPlay();\n if (playOnTap && port.paused) {\n const mine = new AbortController();\n held = mine;\n seekThenPlay(port, cue.start, { play, signal: mine.signal }).then(\n () => { if (held === mine) held = null; },\n () => undefined, // cancelled, or refused: the host's `play` reports a refusal\n );\n } else {\n port.currentTime = cue.start;\n }\n tick();\n },\n cancelHeldPlay,\n dispose() {\n cancelHeldPlay();\n listeners.clear();\n },\n };\n}\n"],"mappings":";;;;;;;;;AA4CO,SAAS,gBAAgB,MAA0B,MAAqB,UAA4B,CAAC,GAAc;AACxH,QAAM,EAAE,YAAY,MAAM,MAAM,QAAQ,GAAG,OAAO,IAAI;AACtD,MAAI,QAAwB,EAAE,KAAK,IAAI,MAAM,GAAG;AAChD,QAAM,YAAY,oBAAI,IAA+D;AACrF,MAAI,OAA+B;AAEnC,QAAM,OAAO,MAAM;AACjB,UAAM,OAAO,KAAK;AAClB,UAAM,MAAM,MAAM,MAAM,MAAM,MAAM;AACpC,UAAM,OAAO,OAAO,KAAK,GAAG,GAAG,IAAI;AACnC,QAAI,QAAQ,MAAM,OAAO,SAAS,MAAM,KAAM;AAC9C,UAAM,WAAW;AACjB,YAAQ,EAAE,KAAK,KAAK;AACpB,cAAU,QAAQ,CAAC,MAAM,EAAE,OAAO,QAAQ,CAAC;AAAA,EAC7C;AACA,QAAM,iBAAiB,MAAM;AAC3B,QAAI,CAAC,KAAM,QAAO;AAClB,SAAK,MAAM;AACX,WAAO;AACP,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,KAAK,MAAM;AAAA,IACX,UAAU,UAAU;AAClB,gBAAU,IAAI,QAAQ;AACtB,aAAO,MAAM,UAAU,OAAO,QAAQ;AAAA,IACxC;AAAA,IACA;AAAA,IACA,OAAO,OAAO;AACZ,YAAM,MAAM,KAAK,KAAK;AACtB,UAAI,CAAC,IAAK;AACV,cAAQ,OAAO;AACf,qBAAe;AACf,UAAI,aAAa,KAAK,QAAQ;AAC5B,cAAM,OAAO,IAAI,gBAAgB;AACjC,eAAO;AACP,qBAAa,MAAM,IAAI,OAAO,EAAE,MAAM,QAAQ,KAAK,OAAO,CAAC,EAAE;AAAA,UAC3D,MAAM;AAAE,gBAAI,SAAS,KAAM,QAAO;AAAA,UAAM;AAAA,UACxC,MAAM;AAAA;AAAA,QACR;AAAA,MACF,OAAO;AACL,aAAK,cAAc,IAAI;AAAA,MACzB;AACA,WAAK;AAAA,IACP;AAAA,IACA;AAAA,IACA,UAAU;AACR,qBAAe;AACf,gBAAU,MAAM;AAAA,IAClB;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,198 @@
|
|
|
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/commands.ts
|
|
21
|
+
var commands_exports = {};
|
|
22
|
+
__export(commands_exports, {
|
|
23
|
+
CONTINUOUS_COMMAND_IDS: () => CONTINUOUS_COMMAND_IDS,
|
|
24
|
+
mediaCommands: () => mediaCommands,
|
|
25
|
+
sleepCommands: () => sleepCommands
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(commands_exports);
|
|
28
|
+
var import_zod = require("zod");
|
|
29
|
+
var import_acture = require("acture");
|
|
30
|
+
var CONTINUOUS_COMMAND_IDS = ["media.seekTo", "media.setRate", "media.setVolume"];
|
|
31
|
+
function mediaCommands(player) {
|
|
32
|
+
const cat = "media";
|
|
33
|
+
const done = () => (0, import_acture.ok)(void 0);
|
|
34
|
+
return [
|
|
35
|
+
(0, import_acture.defineCommand)({
|
|
36
|
+
id: "media.play",
|
|
37
|
+
title: "Play",
|
|
38
|
+
category: cat,
|
|
39
|
+
keybinding: "Space",
|
|
40
|
+
execute: async () => {
|
|
41
|
+
await player.play();
|
|
42
|
+
return done();
|
|
43
|
+
}
|
|
44
|
+
}),
|
|
45
|
+
(0, import_acture.defineCommand)({
|
|
46
|
+
id: "media.pause",
|
|
47
|
+
title: "Pause",
|
|
48
|
+
category: cat,
|
|
49
|
+
execute: () => {
|
|
50
|
+
player.pause();
|
|
51
|
+
return done();
|
|
52
|
+
}
|
|
53
|
+
}),
|
|
54
|
+
(0, import_acture.defineCommand)({
|
|
55
|
+
id: "media.toggle",
|
|
56
|
+
title: "Play or pause",
|
|
57
|
+
category: cat,
|
|
58
|
+
keybinding: "k",
|
|
59
|
+
execute: async () => {
|
|
60
|
+
await player.toggle();
|
|
61
|
+
return done();
|
|
62
|
+
}
|
|
63
|
+
}),
|
|
64
|
+
(0, import_acture.defineCommand)({
|
|
65
|
+
id: "media.next",
|
|
66
|
+
title: "Next",
|
|
67
|
+
category: cat,
|
|
68
|
+
keybinding: "n",
|
|
69
|
+
execute: () => {
|
|
70
|
+
player.next();
|
|
71
|
+
return done();
|
|
72
|
+
}
|
|
73
|
+
}),
|
|
74
|
+
(0, import_acture.defineCommand)({
|
|
75
|
+
id: "media.previous",
|
|
76
|
+
title: "Previous",
|
|
77
|
+
category: cat,
|
|
78
|
+
keybinding: "p",
|
|
79
|
+
execute: () => {
|
|
80
|
+
player.previous();
|
|
81
|
+
return done();
|
|
82
|
+
}
|
|
83
|
+
}),
|
|
84
|
+
(0, import_acture.defineCommand)({
|
|
85
|
+
id: "media.skipBy",
|
|
86
|
+
title: "Skip by seconds",
|
|
87
|
+
category: cat,
|
|
88
|
+
params: import_zod.z.object({ seconds: import_zod.z.number() }),
|
|
89
|
+
execute: (p) => {
|
|
90
|
+
player.skipBy(p.seconds);
|
|
91
|
+
return done();
|
|
92
|
+
}
|
|
93
|
+
}),
|
|
94
|
+
(0, import_acture.defineCommand)({
|
|
95
|
+
id: "media.seekTo",
|
|
96
|
+
title: "Seek to position",
|
|
97
|
+
category: "media.continuous",
|
|
98
|
+
description: "Absolute target in seconds; idempotent, safe to send at 60 Hz.",
|
|
99
|
+
params: import_zod.z.object({ seconds: import_zod.z.number().min(0) }),
|
|
100
|
+
execute: (p) => {
|
|
101
|
+
player.seekTo(p.seconds);
|
|
102
|
+
return done();
|
|
103
|
+
}
|
|
104
|
+
}),
|
|
105
|
+
(0, import_acture.defineCommand)({
|
|
106
|
+
id: "media.setRate",
|
|
107
|
+
title: "Set speed",
|
|
108
|
+
category: "media.continuous",
|
|
109
|
+
params: import_zod.z.object({ rate: import_zod.z.number().positive() }),
|
|
110
|
+
execute: (p) => {
|
|
111
|
+
player.setRate(p.rate);
|
|
112
|
+
return done();
|
|
113
|
+
}
|
|
114
|
+
}),
|
|
115
|
+
(0, import_acture.defineCommand)({
|
|
116
|
+
id: "media.setVolume",
|
|
117
|
+
title: "Set volume",
|
|
118
|
+
category: "media.continuous",
|
|
119
|
+
params: import_zod.z.object({ volume: import_zod.z.number().min(0).max(1) }),
|
|
120
|
+
execute: (p) => {
|
|
121
|
+
player.setVolume(p.volume);
|
|
122
|
+
return done();
|
|
123
|
+
}
|
|
124
|
+
}),
|
|
125
|
+
(0, import_acture.defineCommand)({
|
|
126
|
+
id: "media.enqueue",
|
|
127
|
+
title: "Add to queue",
|
|
128
|
+
category: cat,
|
|
129
|
+
params: import_zod.z.object({ item: import_zod.z.object({ id: import_zod.z.string(), src: import_zod.z.string(), title: import_zod.z.string() }), next: import_zod.z.boolean().optional() }),
|
|
130
|
+
execute: (p) => {
|
|
131
|
+
if (!p.item.src) return (0, import_acture.err)("invalid_item", "src is required");
|
|
132
|
+
player.enqueue(p.item, { next: p.next });
|
|
133
|
+
return done();
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
];
|
|
137
|
+
}
|
|
138
|
+
function sleepCommands(timer) {
|
|
139
|
+
const cat = "media.sleep";
|
|
140
|
+
const done = () => (0, import_acture.ok)(void 0);
|
|
141
|
+
return [
|
|
142
|
+
(0, import_acture.defineCommand)({
|
|
143
|
+
id: "sleep.after",
|
|
144
|
+
title: "Sleep after minutes",
|
|
145
|
+
category: cat,
|
|
146
|
+
params: import_zod.z.object({ minutes: import_zod.z.number().positive() }),
|
|
147
|
+
execute: (p) => {
|
|
148
|
+
timer.set({ kind: "after", minutes: p.minutes });
|
|
149
|
+
return done();
|
|
150
|
+
}
|
|
151
|
+
}),
|
|
152
|
+
(0, import_acture.defineCommand)({
|
|
153
|
+
id: "sleep.at",
|
|
154
|
+
title: "Sleep at a point in the item",
|
|
155
|
+
category: cat,
|
|
156
|
+
params: import_zod.z.object({ seconds: import_zod.z.number().min(0), label: import_zod.z.string().optional() }),
|
|
157
|
+
execute: (p) => {
|
|
158
|
+
timer.set({ kind: "at", ...p });
|
|
159
|
+
return done();
|
|
160
|
+
}
|
|
161
|
+
}),
|
|
162
|
+
(0, import_acture.defineCommand)({
|
|
163
|
+
id: "sleep.end",
|
|
164
|
+
title: "Sleep at the end of the item",
|
|
165
|
+
category: cat,
|
|
166
|
+
execute: () => {
|
|
167
|
+
timer.set({ kind: "end" });
|
|
168
|
+
return done();
|
|
169
|
+
}
|
|
170
|
+
}),
|
|
171
|
+
(0, import_acture.defineCommand)({
|
|
172
|
+
id: "sleep.extend",
|
|
173
|
+
title: "Add minutes to the sleep timer",
|
|
174
|
+
category: cat,
|
|
175
|
+
params: import_zod.z.object({ minutes: import_zod.z.number().positive() }),
|
|
176
|
+
execute: (p) => {
|
|
177
|
+
timer.extend(p.minutes);
|
|
178
|
+
return done();
|
|
179
|
+
}
|
|
180
|
+
}),
|
|
181
|
+
(0, import_acture.defineCommand)({
|
|
182
|
+
id: "sleep.cancel",
|
|
183
|
+
title: "Turn the sleep timer off",
|
|
184
|
+
category: cat,
|
|
185
|
+
execute: () => {
|
|
186
|
+
timer.cancel();
|
|
187
|
+
return done();
|
|
188
|
+
}
|
|
189
|
+
})
|
|
190
|
+
];
|
|
191
|
+
}
|
|
192
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
193
|
+
0 && (module.exports = {
|
|
194
|
+
CONTINUOUS_COMMAND_IDS,
|
|
195
|
+
mediaCommands,
|
|
196
|
+
sleepCommands
|
|
197
|
+
});
|
|
198
|
+
//# sourceMappingURL=commands.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands.ts"],"sourcesContent":["/**\n * The transport's actions as acture commands, bound to one player. Register them with an acture\n * registry; a palette, hotkeys, MCP or a gesture controller then all send the same commands.\n *\n * Continuous commands (`seekTo`, `setRate`, `setVolume`) take a target value and are idempotent, so\n * a sender may emit them at 60 Hz; they are listed in `CONTINUOUS_COMMAND_IDS` so history and undo\n * can skip them. Kept apart from `./transport` so the transport needs neither acture nor zod.\n */\nimport { z } from 'zod';\nimport { defineCommand, ok, err, type AnyCommandRecord } from 'acture';\nimport type { MediaItem, MediaPlayer } from './transport.js';\nimport type { SleepTimer } from './sleep.js';\n\n/** Commands that carry a target value and are safe at 60 Hz; history and undo should skip them. */\nexport const CONTINUOUS_COMMAND_IDS = ['media.seekTo', 'media.setRate', 'media.setVolume'] as const;\n\n/** Builds the transport commands bound to one player. Register them with an acture registry. */\nexport function mediaCommands(player: MediaPlayer): AnyCommandRecord[] {\n const cat = 'media';\n const done = () => ok(undefined);\n return [\n defineCommand({ id: 'media.play', title: 'Play', category: cat, keybinding: 'Space',\n execute: async () => { await player.play(); return done(); } }),\n defineCommand({ id: 'media.pause', title: 'Pause', category: cat,\n execute: () => { player.pause(); return done(); } }),\n defineCommand({ id: 'media.toggle', title: 'Play or pause', category: cat, keybinding: 'k',\n execute: async () => { await player.toggle(); return done(); } }),\n defineCommand({ id: 'media.next', title: 'Next', category: cat, keybinding: 'n',\n execute: () => { player.next(); return done(); } }),\n defineCommand({ id: 'media.previous', title: 'Previous', category: cat, keybinding: 'p',\n execute: () => { player.previous(); return done(); } }),\n defineCommand({ id: 'media.skipBy', title: 'Skip by seconds', category: cat,\n params: z.object({ seconds: z.number() }),\n execute: (p: { seconds: number }) => { player.skipBy(p.seconds); return done(); } }),\n defineCommand({ id: 'media.seekTo', title: 'Seek to position', category: 'media.continuous',\n description: 'Absolute target in seconds; idempotent, safe to send at 60 Hz.',\n params: z.object({ seconds: z.number().min(0) }),\n execute: (p: { seconds: number }) => { player.seekTo(p.seconds); return done(); } }),\n defineCommand({ id: 'media.setRate', title: 'Set speed', category: 'media.continuous',\n params: z.object({ rate: z.number().positive() }),\n execute: (p: { rate: number }) => { player.setRate(p.rate); return done(); } }),\n defineCommand({ id: 'media.setVolume', title: 'Set volume', category: 'media.continuous',\n params: z.object({ volume: z.number().min(0).max(1) }),\n execute: (p: { volume: number }) => { player.setVolume(p.volume); return done(); } }),\n defineCommand({ id: 'media.enqueue', title: 'Add to queue', category: cat,\n params: z.object({ item: z.object({ id: z.string(), src: z.string(), title: z.string() }), next: z.boolean().optional() }),\n execute: (p: { item: MediaItem; next?: boolean }) => {\n if (!p.item.src) return err('invalid_item', 'src is required');\n player.enqueue(p.item, { next: p.next });\n return done();\n } }),\n ];\n}\n\n/**\n * A sleep timer's actions as acture commands (`./sleep`). `sleep.at` takes a media time, so a host\n * that knows its chapters registers its own \"end of chapter\" command on top of it.\n */\nexport function sleepCommands(timer: SleepTimer): AnyCommandRecord[] {\n const cat = 'media.sleep';\n const done = () => ok(undefined);\n return [\n defineCommand({ id: 'sleep.after', title: 'Sleep after minutes', category: cat,\n params: z.object({ minutes: z.number().positive() }),\n execute: (p: { minutes: number }) => { timer.set({ kind: 'after', minutes: p.minutes }); return done(); } }),\n defineCommand({ id: 'sleep.at', title: 'Sleep at a point in the item', category: cat,\n params: z.object({ seconds: z.number().min(0), label: z.string().optional() }),\n execute: (p: { seconds: number; label?: string }) => { timer.set({ kind: 'at', ...p }); return done(); } }),\n defineCommand({ id: 'sleep.end', title: 'Sleep at the end of the item', category: cat,\n execute: () => { timer.set({ kind: 'end' }); return done(); } }),\n defineCommand({ id: 'sleep.extend', title: 'Add minutes to the sleep timer', category: cat,\n params: z.object({ minutes: z.number().positive() }),\n execute: (p: { minutes: number }) => { timer.extend(p.minutes); return done(); } }),\n defineCommand({ id: 'sleep.cancel', title: 'Turn the sleep timer off', category: cat,\n execute: () => { timer.cancel(); return done(); } }),\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,iBAAkB;AAClB,oBAA8D;AAKvD,IAAM,yBAAyB,CAAC,gBAAgB,iBAAiB,iBAAiB;AAGlF,SAAS,cAAc,QAAyC;AACrE,QAAM,MAAM;AACZ,QAAM,OAAO,UAAM,kBAAG,MAAS;AAC/B,SAAO;AAAA,QACL,6BAAc;AAAA,MAAE,IAAI;AAAA,MAAc,OAAO;AAAA,MAAQ,UAAU;AAAA,MAAK,YAAY;AAAA,MAC1E,SAAS,YAAY;AAAE,cAAM,OAAO,KAAK;AAAG,eAAO,KAAK;AAAA,MAAG;AAAA,IAAE,CAAC;AAAA,QAChE,6BAAc;AAAA,MAAE,IAAI;AAAA,MAAe,OAAO;AAAA,MAAS,UAAU;AAAA,MAC3D,SAAS,MAAM;AAAE,eAAO,MAAM;AAAG,eAAO,KAAK;AAAA,MAAG;AAAA,IAAE,CAAC;AAAA,QACrD,6BAAc;AAAA,MAAE,IAAI;AAAA,MAAgB,OAAO;AAAA,MAAiB,UAAU;AAAA,MAAK,YAAY;AAAA,MACrF,SAAS,YAAY;AAAE,cAAM,OAAO,OAAO;AAAG,eAAO,KAAK;AAAA,MAAG;AAAA,IAAE,CAAC;AAAA,QAClE,6BAAc;AAAA,MAAE,IAAI;AAAA,MAAc,OAAO;AAAA,M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E,CAAC;AAAA,MAC7E,SAAS,CAAC,MAA2C;AAAE,cAAM,IAAI,EAAE,MAAM,MAAM,GAAG,EAAE,CAAC;AAAG,eAAO,KAAK;AAAA,MAAG;AAAA,IAAE,CAAC;AAAA,QAC5G,6BAAc;AAAA,MAAE,IAAI;AAAA,MAAa,OAAO;AAAA,MAAgC,UAAU;AAAA,MAChF,SAAS,MAAM;AAAE,cAAM,IAAI,EAAE,MAAM,MAAM,CAAC;AAAG,eAAO,KAAK;AAAA,MAAG;AAAA,IAAE,CAAC;AAAA,QACjE,6BAAc;AAAA,MAAE,IAAI;AAAA,MAAgB,OAAO;AAAA,MAAkC,UAAU;AAAA,MACrF,QAAQ,aAAE,OAAO,EAAE,SAAS,aAAE,OAAO,EAAE,SAAS,EAAE,CAAC;AAAA,MACnD,SAAS,CAAC,MAA2B;AAAE,cAAM,OAAO,EAAE,OAAO;AAAG,eAAO,KAAK;AAAA,MAAG;AAAA,IAAE,CAAC;AAAA,QACpF,6BAAc;AAAA,MAAE,IAAI;AAAA,MAAgB,OAAO;AAAA,MAA4B,UAAU;AAAA,MAC/E,SAAS,MAAM;AAAE,cAAM,OAAO;AAAG,eAAO,KAAK;AAAA,MAAG;AAAA,IAAE,CAAC;AAAA,EACvD;AACF;","names":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AnyCommandRecord } from 'acture';
|
|
2
|
+
import { MediaPlayer } from './transport.cjs';
|
|
3
|
+
import { SleepTimer } from './sleep.cjs';
|
|
4
|
+
import 'zustand/vanilla';
|
|
5
|
+
import './playback.cjs';
|
|
6
|
+
|
|
7
|
+
/** Commands that carry a target value and are safe at 60 Hz; history and undo should skip them. */
|
|
8
|
+
declare const CONTINUOUS_COMMAND_IDS: readonly ["media.seekTo", "media.setRate", "media.setVolume"];
|
|
9
|
+
/** Builds the transport commands bound to one player. Register them with an acture registry. */
|
|
10
|
+
declare function mediaCommands(player: MediaPlayer): AnyCommandRecord[];
|
|
11
|
+
/**
|
|
12
|
+
* A sleep timer's actions as acture commands (`./sleep`). `sleep.at` takes a media time, so a host
|
|
13
|
+
* that knows its chapters registers its own "end of chapter" command on top of it.
|
|
14
|
+
*/
|
|
15
|
+
declare function sleepCommands(timer: SleepTimer): AnyCommandRecord[];
|
|
16
|
+
|
|
17
|
+
export { CONTINUOUS_COMMAND_IDS, mediaCommands, sleepCommands };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AnyCommandRecord } from 'acture';
|
|
2
|
+
import { MediaPlayer } from './transport.js';
|
|
3
|
+
import { SleepTimer } from './sleep.js';
|
|
4
|
+
import 'zustand/vanilla';
|
|
5
|
+
import './playback.js';
|
|
6
|
+
|
|
7
|
+
/** Commands that carry a target value and are safe at 60 Hz; history and undo should skip them. */
|
|
8
|
+
declare const CONTINUOUS_COMMAND_IDS: readonly ["media.seekTo", "media.setRate", "media.setVolume"];
|
|
9
|
+
/** Builds the transport commands bound to one player. Register them with an acture registry. */
|
|
10
|
+
declare function mediaCommands(player: MediaPlayer): AnyCommandRecord[];
|
|
11
|
+
/**
|
|
12
|
+
* A sleep timer's actions as acture commands (`./sleep`). `sleep.at` takes a media time, so a host
|
|
13
|
+
* that knows its chapters registers its own "end of chapter" command on top of it.
|
|
14
|
+
*/
|
|
15
|
+
declare function sleepCommands(timer: SleepTimer): AnyCommandRecord[];
|
|
16
|
+
|
|
17
|
+
export { CONTINUOUS_COMMAND_IDS, mediaCommands, sleepCommands };
|
package/dist/commands.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// src/commands.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { defineCommand, ok, err } from "acture";
|
|
4
|
+
var CONTINUOUS_COMMAND_IDS = ["media.seekTo", "media.setRate", "media.setVolume"];
|
|
5
|
+
function mediaCommands(player) {
|
|
6
|
+
const cat = "media";
|
|
7
|
+
const done = () => ok(void 0);
|
|
8
|
+
return [
|
|
9
|
+
defineCommand({
|
|
10
|
+
id: "media.play",
|
|
11
|
+
title: "Play",
|
|
12
|
+
category: cat,
|
|
13
|
+
keybinding: "Space",
|
|
14
|
+
execute: async () => {
|
|
15
|
+
await player.play();
|
|
16
|
+
return done();
|
|
17
|
+
}
|
|
18
|
+
}),
|
|
19
|
+
defineCommand({
|
|
20
|
+
id: "media.pause",
|
|
21
|
+
title: "Pause",
|
|
22
|
+
category: cat,
|
|
23
|
+
execute: () => {
|
|
24
|
+
player.pause();
|
|
25
|
+
return done();
|
|
26
|
+
}
|
|
27
|
+
}),
|
|
28
|
+
defineCommand({
|
|
29
|
+
id: "media.toggle",
|
|
30
|
+
title: "Play or pause",
|
|
31
|
+
category: cat,
|
|
32
|
+
keybinding: "k",
|
|
33
|
+
execute: async () => {
|
|
34
|
+
await player.toggle();
|
|
35
|
+
return done();
|
|
36
|
+
}
|
|
37
|
+
}),
|
|
38
|
+
defineCommand({
|
|
39
|
+
id: "media.next",
|
|
40
|
+
title: "Next",
|
|
41
|
+
category: cat,
|
|
42
|
+
keybinding: "n",
|
|
43
|
+
execute: () => {
|
|
44
|
+
player.next();
|
|
45
|
+
return done();
|
|
46
|
+
}
|
|
47
|
+
}),
|
|
48
|
+
defineCommand({
|
|
49
|
+
id: "media.previous",
|
|
50
|
+
title: "Previous",
|
|
51
|
+
category: cat,
|
|
52
|
+
keybinding: "p",
|
|
53
|
+
execute: () => {
|
|
54
|
+
player.previous();
|
|
55
|
+
return done();
|
|
56
|
+
}
|
|
57
|
+
}),
|
|
58
|
+
defineCommand({
|
|
59
|
+
id: "media.skipBy",
|
|
60
|
+
title: "Skip by seconds",
|
|
61
|
+
category: cat,
|
|
62
|
+
params: z.object({ seconds: z.number() }),
|
|
63
|
+
execute: (p) => {
|
|
64
|
+
player.skipBy(p.seconds);
|
|
65
|
+
return done();
|
|
66
|
+
}
|
|
67
|
+
}),
|
|
68
|
+
defineCommand({
|
|
69
|
+
id: "media.seekTo",
|
|
70
|
+
title: "Seek to position",
|
|
71
|
+
category: "media.continuous",
|
|
72
|
+
description: "Absolute target in seconds; idempotent, safe to send at 60 Hz.",
|
|
73
|
+
params: z.object({ seconds: z.number().min(0) }),
|
|
74
|
+
execute: (p) => {
|
|
75
|
+
player.seekTo(p.seconds);
|
|
76
|
+
return done();
|
|
77
|
+
}
|
|
78
|
+
}),
|
|
79
|
+
defineCommand({
|
|
80
|
+
id: "media.setRate",
|
|
81
|
+
title: "Set speed",
|
|
82
|
+
category: "media.continuous",
|
|
83
|
+
params: z.object({ rate: z.number().positive() }),
|
|
84
|
+
execute: (p) => {
|
|
85
|
+
player.setRate(p.rate);
|
|
86
|
+
return done();
|
|
87
|
+
}
|
|
88
|
+
}),
|
|
89
|
+
defineCommand({
|
|
90
|
+
id: "media.setVolume",
|
|
91
|
+
title: "Set volume",
|
|
92
|
+
category: "media.continuous",
|
|
93
|
+
params: z.object({ volume: z.number().min(0).max(1) }),
|
|
94
|
+
execute: (p) => {
|
|
95
|
+
player.setVolume(p.volume);
|
|
96
|
+
return done();
|
|
97
|
+
}
|
|
98
|
+
}),
|
|
99
|
+
defineCommand({
|
|
100
|
+
id: "media.enqueue",
|
|
101
|
+
title: "Add to queue",
|
|
102
|
+
category: cat,
|
|
103
|
+
params: z.object({ item: z.object({ id: z.string(), src: z.string(), title: z.string() }), next: z.boolean().optional() }),
|
|
104
|
+
execute: (p) => {
|
|
105
|
+
if (!p.item.src) return err("invalid_item", "src is required");
|
|
106
|
+
player.enqueue(p.item, { next: p.next });
|
|
107
|
+
return done();
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
];
|
|
111
|
+
}
|
|
112
|
+
function sleepCommands(timer) {
|
|
113
|
+
const cat = "media.sleep";
|
|
114
|
+
const done = () => ok(void 0);
|
|
115
|
+
return [
|
|
116
|
+
defineCommand({
|
|
117
|
+
id: "sleep.after",
|
|
118
|
+
title: "Sleep after minutes",
|
|
119
|
+
category: cat,
|
|
120
|
+
params: z.object({ minutes: z.number().positive() }),
|
|
121
|
+
execute: (p) => {
|
|
122
|
+
timer.set({ kind: "after", minutes: p.minutes });
|
|
123
|
+
return done();
|
|
124
|
+
}
|
|
125
|
+
}),
|
|
126
|
+
defineCommand({
|
|
127
|
+
id: "sleep.at",
|
|
128
|
+
title: "Sleep at a point in the item",
|
|
129
|
+
category: cat,
|
|
130
|
+
params: z.object({ seconds: z.number().min(0), label: z.string().optional() }),
|
|
131
|
+
execute: (p) => {
|
|
132
|
+
timer.set({ kind: "at", ...p });
|
|
133
|
+
return done();
|
|
134
|
+
}
|
|
135
|
+
}),
|
|
136
|
+
defineCommand({
|
|
137
|
+
id: "sleep.end",
|
|
138
|
+
title: "Sleep at the end of the item",
|
|
139
|
+
category: cat,
|
|
140
|
+
execute: () => {
|
|
141
|
+
timer.set({ kind: "end" });
|
|
142
|
+
return done();
|
|
143
|
+
}
|
|
144
|
+
}),
|
|
145
|
+
defineCommand({
|
|
146
|
+
id: "sleep.extend",
|
|
147
|
+
title: "Add minutes to the sleep timer",
|
|
148
|
+
category: cat,
|
|
149
|
+
params: z.object({ minutes: z.number().positive() }),
|
|
150
|
+
execute: (p) => {
|
|
151
|
+
timer.extend(p.minutes);
|
|
152
|
+
return done();
|
|
153
|
+
}
|
|
154
|
+
}),
|
|
155
|
+
defineCommand({
|
|
156
|
+
id: "sleep.cancel",
|
|
157
|
+
title: "Turn the sleep timer off",
|
|
158
|
+
category: cat,
|
|
159
|
+
execute: () => {
|
|
160
|
+
timer.cancel();
|
|
161
|
+
return done();
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
];
|
|
165
|
+
}
|
|
166
|
+
export {
|
|
167
|
+
CONTINUOUS_COMMAND_IDS,
|
|
168
|
+
mediaCommands,
|
|
169
|
+
sleepCommands
|
|
170
|
+
};
|
|
171
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands.ts"],"sourcesContent":["/**\n * The transport's actions as acture commands, bound to one player. Register them with an acture\n * registry; a palette, hotkeys, MCP or a gesture controller then all send the same commands.\n *\n * Continuous commands (`seekTo`, `setRate`, `setVolume`) take a target value and are idempotent, so\n * a sender may emit them at 60 Hz; they are listed in `CONTINUOUS_COMMAND_IDS` so history and undo\n * can skip them. Kept apart from `./transport` so the transport needs neither acture nor zod.\n */\nimport { z } from 'zod';\nimport { defineCommand, ok, err, type AnyCommandRecord } from 'acture';\nimport type { MediaItem, MediaPlayer } from './transport.js';\nimport type { SleepTimer } from './sleep.js';\n\n/** Commands that carry a target value and are safe at 60 Hz; history and undo should skip them. */\nexport const CONTINUOUS_COMMAND_IDS = ['media.seekTo', 'media.setRate', 'media.setVolume'] as const;\n\n/** Builds the transport commands bound to one player. Register them with an acture registry. */\nexport function mediaCommands(player: MediaPlayer): AnyCommandRecord[] {\n const cat = 'media';\n const done = () => ok(undefined);\n return [\n defineCommand({ id: 'media.play', title: 'Play', category: cat, keybinding: 'Space',\n execute: async () => { await player.play(); return done(); } }),\n defineCommand({ id: 'media.pause', title: 'Pause', category: cat,\n execute: () => { player.pause(); return done(); } }),\n defineCommand({ id: 'media.toggle', title: 'Play or pause', category: cat, keybinding: 'k',\n execute: async () => { await player.toggle(); return done(); } }),\n defineCommand({ id: 'media.next', title: 'Next', category: cat, keybinding: 'n',\n execute: () => { player.next(); return done(); } }),\n defineCommand({ id: 'media.previous', title: 'Previous', category: cat, keybinding: 'p',\n execute: () => { player.previous(); return done(); } }),\n defineCommand({ id: 'media.skipBy', title: 'Skip by seconds', category: cat,\n params: z.object({ seconds: z.number() }),\n execute: (p: { seconds: number }) => { player.skipBy(p.seconds); return done(); } }),\n defineCommand({ id: 'media.seekTo', title: 'Seek to position', category: 'media.continuous',\n description: 'Absolute target in seconds; idempotent, safe to send at 60 Hz.',\n params: z.object({ seconds: z.number().min(0) }),\n execute: (p: { seconds: number }) => { player.seekTo(p.seconds); return done(); } }),\n defineCommand({ id: 'media.setRate', title: 'Set speed', category: 'media.continuous',\n params: z.object({ rate: z.number().positive() }),\n execute: (p: { rate: number }) => { player.setRate(p.rate); return done(); } }),\n defineCommand({ id: 'media.setVolume', title: 'Set volume', category: 'media.continuous',\n params: z.object({ volume: z.number().min(0).max(1) }),\n execute: (p: { volume: number }) => { player.setVolume(p.volume); return done(); } }),\n defineCommand({ id: 'media.enqueue', title: 'Add to queue', category: cat,\n params: z.object({ item: z.object({ id: z.string(), src: z.string(), title: z.string() }), next: z.boolean().optional() }),\n execute: (p: { item: MediaItem; next?: boolean }) => {\n if (!p.item.src) return err('invalid_item', 'src is required');\n player.enqueue(p.item, { next: p.next });\n return done();\n } }),\n ];\n}\n\n/**\n * A sleep timer's actions as acture commands (`./sleep`). `sleep.at` takes a media time, so a host\n * that knows its chapters registers its own \"end of chapter\" command on top of it.\n */\nexport function sleepCommands(timer: SleepTimer): AnyCommandRecord[] {\n const cat = 'media.sleep';\n const done = () => ok(undefined);\n return [\n defineCommand({ id: 'sleep.after', title: 'Sleep after minutes', category: cat,\n params: z.object({ minutes: z.number().positive() }),\n execute: (p: { minutes: number }) => { timer.set({ kind: 'after', minutes: p.minutes }); return done(); } }),\n defineCommand({ id: 'sleep.at', title: 'Sleep at a point in the item', category: cat,\n params: z.object({ seconds: z.number().min(0), label: z.string().optional() }),\n execute: (p: { seconds: number; label?: string }) => { timer.set({ kind: 'at', ...p }); return done(); } }),\n defineCommand({ id: 'sleep.end', title: 'Sleep at the end of the item', category: cat,\n execute: () => { timer.set({ kind: 'end' }); return done(); } }),\n defineCommand({ id: 'sleep.extend', title: 'Add minutes to the sleep timer', category: cat,\n params: z.object({ minutes: z.number().positive() }),\n execute: (p: { minutes: number }) => { timer.extend(p.minutes); return done(); } }),\n defineCommand({ id: 'sleep.cancel', title: 'Turn the sleep timer off', category: cat,\n execute: () => { timer.cancel(); return done(); } }),\n ];\n}\n"],"mappings":";AAQA,SAAS,SAAS;AAClB,SAAS,eAAe,IAAI,WAAkC;AAKvD,IAAM,yBAAyB,CAAC,gBAAgB,iBAAiB,iBAAiB;AAGlF,SAAS,cAAc,QAAyC;AACrE,Q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,IAAE,CAAC;AAAA,IACpF,cAAc;AAAA,MAAE,IAAI;AAAA,MAAgB,OAAO;AAAA,MAA4B,UAAU;AAAA,MAC/E,SAAS,MAAM;AAAE,cAAM,OAAO;AAAG,eAAO,KAAK;AAAA,MAAG;AAAA,IAAE,CAAC;AAAA,EACvD;AACF;","names":[]}
|
package/dist/cues.cjs
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
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/cues.ts
|
|
21
|
+
var cues_exports = {};
|
|
22
|
+
__export(cues_exports, {
|
|
23
|
+
CUE_EPSILON_S: () => CUE_EPSILON_S,
|
|
24
|
+
cueAt: () => cueAt,
|
|
25
|
+
cuesDuration: () => cuesDuration,
|
|
26
|
+
formatTime: () => formatTime,
|
|
27
|
+
wordAt: () => wordAt
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(cues_exports);
|
|
30
|
+
var CUE_EPSILON_S = 0.01;
|
|
31
|
+
var SECONDS_PER_MINUTE = 60;
|
|
32
|
+
var MINUTES_PER_HOUR = 60;
|
|
33
|
+
function lastStarted(count, startOf, time) {
|
|
34
|
+
let lo = 0;
|
|
35
|
+
let hi = count - 1;
|
|
36
|
+
let at = -1;
|
|
37
|
+
while (lo <= hi) {
|
|
38
|
+
const mid = lo + hi >> 1;
|
|
39
|
+
if (startOf(mid) <= time) {
|
|
40
|
+
at = mid;
|
|
41
|
+
lo = mid + 1;
|
|
42
|
+
} else {
|
|
43
|
+
hi = mid - 1;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return at;
|
|
47
|
+
}
|
|
48
|
+
function cueAt(cues, time, options = {}) {
|
|
49
|
+
const { epsilonS = CUE_EPSILON_S, gaps = false } = options;
|
|
50
|
+
const at = lastStarted(cues.length, (i) => cues[i].start, time + epsilonS);
|
|
51
|
+
if (gaps && at >= 0 && time >= cues[at].end) return -1;
|
|
52
|
+
return at;
|
|
53
|
+
}
|
|
54
|
+
function wordAt(cue, time) {
|
|
55
|
+
const words = cue?.words;
|
|
56
|
+
if (!words?.length) return -1;
|
|
57
|
+
return Math.max(0, lastStarted(words.length, (i) => words[i][0], time));
|
|
58
|
+
}
|
|
59
|
+
function cuesDuration(cues) {
|
|
60
|
+
return cues.length ? cues[cues.length - 1].end : 0;
|
|
61
|
+
}
|
|
62
|
+
function formatTime(seconds) {
|
|
63
|
+
const whole = Math.max(0, Math.floor(seconds || 0));
|
|
64
|
+
const hours = Math.floor(whole / (SECONDS_PER_MINUTE * MINUTES_PER_HOUR));
|
|
65
|
+
const minutes = Math.floor(whole / SECONDS_PER_MINUTE) % MINUTES_PER_HOUR;
|
|
66
|
+
const secs = whole % SECONDS_PER_MINUTE;
|
|
67
|
+
const mm = hours && minutes < 10 ? `0${minutes}` : `${minutes}`;
|
|
68
|
+
return `${hours ? `${hours}:` : ""}${mm}:${secs < 10 ? "0" : ""}${secs}`;
|
|
69
|
+
}
|
|
70
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
+
0 && (module.exports = {
|
|
72
|
+
CUE_EPSILON_S,
|
|
73
|
+
cueAt,
|
|
74
|
+
cuesDuration,
|
|
75
|
+
formatTime,
|
|
76
|
+
wordAt
|
|
77
|
+
});
|
|
78
|
+
//# sourceMappingURL=cues.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cues.ts"],"sourcesContent":["/**\n * Timed text, looked up by time: which cue and which word are being heard. Pure, no DOM.\n *\n * A cue is a span of text with a start and an end, in seconds, and optionally the times of its\n * words. A spoken overview's sentences (`@zodal/speech`), a song's lyric lines (arioso) and a\n * film's subtitles (srtplay) are all lists of cues. The shape is structural, so this module needs\n * no schema at runtime; the wire model is lacing's (`AlignedTrackV1`, media_hub ADR-0010).\n */\n\n/** The fields of a cue this module reads. `words` are `[start, end, text]`, in seconds. */\nexport interface CueLike {\n start: number;\n end: number;\n text?: string;\n words?: ReadonlyArray<readonly [number, number, string]>;\n}\n\n/**\n * Tolerance so a seek to a cue's own start lands in that cue and not the one before it, after\n * float rounding (`currentTime` is rarely exactly what was set).\n */\nexport const CUE_EPSILON_S = 0.01;\n\nconst SECONDS_PER_MINUTE = 60;\nconst MINUTES_PER_HOUR = 60;\n\n/** The last index `i` of a sorted list with `startOf(i) <= time`, or -1. */\nfunction lastStarted(count: number, startOf: (i: number) => number, time: number): number {\n let lo = 0;\n let hi = count - 1;\n let at = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (startOf(mid) <= time) {\n at = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n return at;\n}\n\nexport interface CueAtOptions {\n /** See `CUE_EPSILON_S`. */\n epsilonS?: number;\n /**\n * `false` (the default): the last cue that has started stays current through the gap after it,\n * as a transcript or lyrics view wants. `true`: -1 between cues, as subtitles want.\n */\n gaps?: boolean;\n}\n\n/** The index of the cue being heard at `time`: the last one that has started, or -1. */\nexport function cueAt(cues: readonly CueLike[], time: number, options: CueAtOptions = {}): number {\n const { epsilonS = CUE_EPSILON_S, gaps = false } = options;\n const at = lastStarted(cues.length, (i) => cues[i].start, time + epsilonS);\n if (gaps && at >= 0 && time >= cues[at].end) return -1;\n return at;\n}\n\n/** The index of the word being heard within `cue`, or -1 when it has no word times. */\nexport function wordAt(cue: CueLike | undefined, time: number): number {\n const words = cue?.words;\n if (!words?.length) return -1;\n return Math.max(0, lastStarted(words.length, (i) => words[i][0], time));\n}\n\n/** The cues' total length: the last cue's end, which stands in until the media reports its own. */\nexport function cuesDuration(cues: readonly CueLike[]): number {\n return cues.length ? cues[cues.length - 1].end : 0;\n}\n\n/** `m:ss`, or `h:mm:ss` past the hour. */\nexport function formatTime(seconds: number): string {\n const whole = Math.max(0, Math.floor(seconds || 0));\n const hours = Math.floor(whole / (SECONDS_PER_MINUTE * MINUTES_PER_HOUR));\n const minutes = Math.floor(whole / SECONDS_PER_MINUTE) % MINUTES_PER_HOUR;\n const secs = whole % SECONDS_PER_MINUTE;\n const mm = hours && minutes < 10 ? `0${minutes}` : `${minutes}`;\n return `${hours ? `${hours}:` : ''}${mm}:${secs < 10 ? '0' : ''}${secs}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBO,IAAM,gBAAgB;AAE7B,IAAM,qBAAqB;AAC3B,IAAM,mBAAmB;AAGzB,SAAS,YAAY,OAAe,SAAgC,MAAsB;AACxF,MAAI,KAAK;AACT,MAAI,KAAK,QAAQ;AACjB,MAAI,KAAK;AACT,SAAO,MAAM,IAAI;AACf,UAAM,MAAO,KAAK,MAAO;AACzB,QAAI,QAAQ,GAAG,KAAK,MAAM;AACxB,WAAK;AACL,WAAK,MAAM;AAAA,IACb,OAAO;AACL,WAAK,MAAM;AAAA,IACb;AAAA,EACF;AACA,SAAO;AACT;AAaO,SAAS,MAAM,MAA0B,MAAc,UAAwB,CAAC,GAAW;AAChG,QAAM,EAAE,WAAW,eAAe,OAAO,MAAM,IAAI;AACnD,QAAM,KAAK,YAAY,KAAK,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,OAAO,OAAO,QAAQ;AACzE,MAAI,QAAQ,MAAM,KAAK,QAAQ,KAAK,EAAE,EAAE,IAAK,QAAO;AACpD,SAAO;AACT;AAGO,SAAS,OAAO,KAA0B,MAAsB;AACrE,QAAM,QAAQ,KAAK;AACnB,MAAI,CAAC,OAAO,OAAQ,QAAO;AAC3B,SAAO,KAAK,IAAI,GAAG,YAAY,MAAM,QAAQ,CAAC,MAAM,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;AACxE;AAGO,SAAS,aAAa,MAAkC;AAC7D,SAAO,KAAK,SAAS,KAAK,KAAK,SAAS,CAAC,EAAE,MAAM;AACnD;AAGO,SAAS,WAAW,SAAyB;AAClD,QAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,MAAM,WAAW,CAAC,CAAC;AAClD,QAAM,QAAQ,KAAK,MAAM,SAAS,qBAAqB,iBAAiB;AACxE,QAAM,UAAU,KAAK,MAAM,QAAQ,kBAAkB,IAAI;AACzD,QAAM,OAAO,QAAQ;AACrB,QAAM,KAAK,SAAS,UAAU,KAAK,IAAI,OAAO,KAAK,GAAG,OAAO;AAC7D,SAAO,GAAG,QAAQ,GAAG,KAAK,MAAM,EAAE,GAAG,EAAE,IAAI,OAAO,KAAK,MAAM,EAAE,GAAG,IAAI;AACxE;","names":[]}
|
package/dist/cues.d.cts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timed text, looked up by time: which cue and which word are being heard. Pure, no DOM.
|
|
3
|
+
*
|
|
4
|
+
* A cue is a span of text with a start and an end, in seconds, and optionally the times of its
|
|
5
|
+
* words. A spoken overview's sentences (`@zodal/speech`), a song's lyric lines (arioso) and a
|
|
6
|
+
* film's subtitles (srtplay) are all lists of cues. The shape is structural, so this module needs
|
|
7
|
+
* no schema at runtime; the wire model is lacing's (`AlignedTrackV1`, media_hub ADR-0010).
|
|
8
|
+
*/
|
|
9
|
+
/** The fields of a cue this module reads. `words` are `[start, end, text]`, in seconds. */
|
|
10
|
+
interface CueLike {
|
|
11
|
+
start: number;
|
|
12
|
+
end: number;
|
|
13
|
+
text?: string;
|
|
14
|
+
words?: ReadonlyArray<readonly [number, number, string]>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Tolerance so a seek to a cue's own start lands in that cue and not the one before it, after
|
|
18
|
+
* float rounding (`currentTime` is rarely exactly what was set).
|
|
19
|
+
*/
|
|
20
|
+
declare const CUE_EPSILON_S = 0.01;
|
|
21
|
+
interface CueAtOptions {
|
|
22
|
+
/** See `CUE_EPSILON_S`. */
|
|
23
|
+
epsilonS?: number;
|
|
24
|
+
/**
|
|
25
|
+
* `false` (the default): the last cue that has started stays current through the gap after it,
|
|
26
|
+
* as a transcript or lyrics view wants. `true`: -1 between cues, as subtitles want.
|
|
27
|
+
*/
|
|
28
|
+
gaps?: boolean;
|
|
29
|
+
}
|
|
30
|
+
/** The index of the cue being heard at `time`: the last one that has started, or -1. */
|
|
31
|
+
declare function cueAt(cues: readonly CueLike[], time: number, options?: CueAtOptions): number;
|
|
32
|
+
/** The index of the word being heard within `cue`, or -1 when it has no word times. */
|
|
33
|
+
declare function wordAt(cue: CueLike | undefined, time: number): number;
|
|
34
|
+
/** The cues' total length: the last cue's end, which stands in until the media reports its own. */
|
|
35
|
+
declare function cuesDuration(cues: readonly CueLike[]): number;
|
|
36
|
+
/** `m:ss`, or `h:mm:ss` past the hour. */
|
|
37
|
+
declare function formatTime(seconds: number): string;
|
|
38
|
+
|
|
39
|
+
export { CUE_EPSILON_S, type CueAtOptions, type CueLike, cueAt, cuesDuration, formatTime, wordAt };
|