@vocasync/astro 1.0.1 → 2.0.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/README.md +618 -80
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js.map +1 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +1 -1
- package/dist/api/index.js.map +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/components/AudioPlayer.astro +298 -1141
- package/dist/components/index.d.ts +10 -32
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -3
- package/dist/components/index.js.map +1 -1
- package/dist/components/types.d.ts +117 -0
- package/dist/components/types.d.ts.map +1 -0
- package/dist/components/types.js +2 -0
- package/dist/components/types.js.map +1 -0
- package/dist/config/index.d.ts +2 -2
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +1 -1
- package/dist/config/index.js.map +1 -1
- package/dist/config/schema.d.ts +124 -169
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +4 -4
- package/dist/config/schema.js.map +1 -1
- package/dist/core/content-loader.js +1 -1
- package/dist/core/content-loader.js.map +1 -1
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -2
- package/dist/core/index.js.map +1 -1
- package/dist/core/speech-builder.js.map +1 -1
- package/dist/index.d.ts +6 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -6
- package/dist/index.js.map +1 -1
- package/dist/integration.d.ts +28 -2
- package/dist/integration.d.ts.map +1 -1
- package/dist/integration.js +40 -3
- package/dist/integration.js.map +1 -1
- package/dist/lib/latex-to-speech/index.d.ts.map +1 -1
- package/dist/lib/latex-to-speech/index.js.map +1 -1
- package/dist/player-core/boot.d.ts +9 -0
- package/dist/player-core/boot.d.ts.map +1 -0
- package/dist/player-core/boot.js +59 -0
- package/dist/player-core/boot.js.map +1 -0
- package/dist/player-core/highlighter.d.ts +31 -0
- package/dist/player-core/highlighter.d.ts.map +1 -0
- package/dist/player-core/highlighter.js +103 -0
- package/dist/player-core/highlighter.js.map +1 -0
- package/dist/player-core/index.d.ts +17 -0
- package/dist/player-core/index.d.ts.map +1 -0
- package/dist/player-core/index.js +24 -0
- package/dist/player-core/index.js.map +1 -0
- package/dist/player-core/media-url.d.ts +18 -0
- package/dist/player-core/media-url.d.ts.map +1 -0
- package/dist/player-core/media-url.js +33 -0
- package/dist/player-core/media-url.js.map +1 -0
- package/dist/player-core/player.d.ts +9 -0
- package/dist/player-core/player.d.ts.map +1 -0
- package/dist/player-core/player.js +622 -0
- package/dist/player-core/player.js.map +1 -0
- package/dist/player-core/registry.d.ts +20 -0
- package/dist/player-core/registry.d.ts.map +1 -0
- package/dist/player-core/registry.js +31 -0
- package/dist/player-core/registry.js.map +1 -0
- package/dist/player-core/seek-delegate.d.ts +24 -0
- package/dist/player-core/seek-delegate.d.ts.map +1 -0
- package/dist/player-core/seek-delegate.js +64 -0
- package/dist/player-core/seek-delegate.js.map +1 -0
- package/dist/player-core/storage.d.ts +38 -0
- package/dist/player-core/storage.d.ts.map +1 -0
- package/dist/player-core/storage.js +107 -0
- package/dist/player-core/storage.js.map +1 -0
- package/dist/player-core/strings.d.ts +53 -0
- package/dist/player-core/strings.d.ts.map +1 -0
- package/dist/player-core/strings.js +45 -0
- package/dist/player-core/strings.js.map +1 -0
- package/dist/player-core/timings.d.ts +56 -0
- package/dist/player-core/timings.d.ts.map +1 -0
- package/dist/player-core/timings.js +90 -0
- package/dist/player-core/timings.js.map +1 -0
- package/dist/rehype/audio-words.d.ts +9 -3
- package/dist/rehype/audio-words.d.ts.map +1 -1
- package/dist/rehype/audio-words.js +8 -8
- package/dist/rehype/audio-words.js.map +1 -1
- package/dist/rehype/index.d.ts +2 -2
- package/dist/rehype/index.d.ts.map +1 -1
- package/dist/rehype/index.js.map +1 -1
- package/dist/rehype/rehype-math-speech.d.ts.map +1 -1
- package/dist/rehype/rehype-math-speech.js +2 -0
- package/dist/rehype/rehype-math-speech.js.map +1 -1
- package/dist/styles/content.css +41 -0
- package/dist/styles/layers.css +13 -0
- package/dist/styles/player.css +517 -0
- package/dist/styles/preset-shadcn.css +31 -0
- package/dist/styles/tokens.css +266 -0
- package/dist/styles/vocasync.css +10 -0
- package/dist/sync/index.d.ts +1 -1
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +1 -1
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/orchestrator.d.ts.map +1 -1
- package/dist/sync/orchestrator.js.map +1 -1
- package/package.json +40 -17
- package/src/api/index.ts +4 -4
- package/src/components/AudioPlayer.astro +298 -1141
- package/src/components/index.ts +19 -34
- package/src/components/types.ts +140 -0
- package/src/config/index.ts +23 -24
- package/src/config/schema.ts +4 -4
- package/src/core/content-loader.ts +1 -1
- package/src/core/index.ts +7 -7
- package/src/env.d.ts +2 -0
- package/src/index.ts +23 -28
- package/src/integration.ts +66 -4
- package/src/player-core/boot.ts +62 -0
- package/src/player-core/highlighter.ts +159 -0
- package/src/player-core/index.ts +45 -0
- package/src/player-core/media-url.ts +35 -0
- package/src/player-core/player.ts +725 -0
- package/src/player-core/registry.ts +40 -0
- package/src/player-core/seek-delegate.ts +92 -0
- package/src/player-core/storage.ts +112 -0
- package/src/player-core/strings.ts +89 -0
- package/src/player-core/timings.ts +115 -0
- package/src/rehype/audio-words.ts +17 -11
- package/src/rehype/index.ts +2 -3
- package/src/rehype/rehype-math-speech.ts +3 -1
- package/src/styles/content.css +41 -0
- package/src/styles/layers.css +13 -0
- package/src/styles/player.css +517 -0
- package/src/styles/preset-shadcn.css +31 -0
- package/src/styles/tokens.css +266 -0
- package/src/styles/vocasync.css +10 -0
- package/src/sync/index.ts +1 -1
- package/src/sync/orchestrator.ts +1 -1
- package/dist/styles/variables.css +0 -164
- package/src/styles/variables.css +0 -164
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tracks live player instances on the page.
|
|
3
|
+
*
|
|
4
|
+
* Exists for two reasons: exclusive playback (starting one player stops the others,
|
|
5
|
+
* rather than letting several tracks overlap), and teardown, which a view-transition
|
|
6
|
+
* navigation needs so animation loops and observers do not leak across pages.
|
|
7
|
+
*/
|
|
8
|
+
export interface RegisteredPlayer {
|
|
9
|
+
readonly root: Element;
|
|
10
|
+
pause(): void;
|
|
11
|
+
destroy(): void;
|
|
12
|
+
}
|
|
13
|
+
export declare function register(player: RegisteredPlayer): void;
|
|
14
|
+
export declare function unregister(player: RegisteredPlayer): void;
|
|
15
|
+
/** Pause every player except the one starting. */
|
|
16
|
+
export declare function pauseOthers(except: RegisteredPlayer): void;
|
|
17
|
+
/** Destroy every instance. Called before a view-transition swap. */
|
|
18
|
+
export declare function destroyAll(): void;
|
|
19
|
+
export declare function count(): number;
|
|
20
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/player-core/registry.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,KAAK,IAAI,IAAI,CAAC;IACd,OAAO,IAAI,IAAI,CAAC;CACjB;AAID,wBAAgB,QAAQ,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAEvD;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAEzD;AAED,kDAAkD;AAClD,wBAAgB,WAAW,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAI1D;AAED,oEAAoE;AACpE,wBAAgB,UAAU,IAAI,IAAI,CAGjC;AAED,wBAAgB,KAAK,IAAI,MAAM,CAE9B"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tracks live player instances on the page.
|
|
3
|
+
*
|
|
4
|
+
* Exists for two reasons: exclusive playback (starting one player stops the others,
|
|
5
|
+
* rather than letting several tracks overlap), and teardown, which a view-transition
|
|
6
|
+
* navigation needs so animation loops and observers do not leak across pages.
|
|
7
|
+
*/
|
|
8
|
+
const instances = new Set();
|
|
9
|
+
export function register(player) {
|
|
10
|
+
instances.add(player);
|
|
11
|
+
}
|
|
12
|
+
export function unregister(player) {
|
|
13
|
+
instances.delete(player);
|
|
14
|
+
}
|
|
15
|
+
/** Pause every player except the one starting. */
|
|
16
|
+
export function pauseOthers(except) {
|
|
17
|
+
for (const player of instances) {
|
|
18
|
+
if (player !== except)
|
|
19
|
+
player.pause();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** Destroy every instance. Called before a view-transition swap. */
|
|
23
|
+
export function destroyAll() {
|
|
24
|
+
for (const player of Array.from(instances))
|
|
25
|
+
player.destroy();
|
|
26
|
+
instances.clear();
|
|
27
|
+
}
|
|
28
|
+
export function count() {
|
|
29
|
+
return instances.size;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/player-core/registry.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH,MAAM,SAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;AAE9C,MAAM,UAAU,QAAQ,CAAC,MAAwB;IAC/C,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,MAAwB;IACjD,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC3B,CAAC;AAED,kDAAkD;AAClD,MAAM,UAAU,WAAW,CAAC,MAAwB;IAClD,KAAK,MAAM,MAAM,IAAI,SAAS,EAAE,CAAC;QAC/B,IAAI,MAAM,KAAK,MAAM;YAAE,MAAM,CAAC,KAAK,EAAE,CAAC;IACxC,CAAC;AACH,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,UAAU;IACxB,KAAK,MAAM,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC;QAAE,MAAM,CAAC,OAAO,EAAE,CAAC;IAC7D,SAAS,CAAC,KAAK,EAAE,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,KAAK;IACnB,OAAO,SAAS,CAAC,IAAI,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Click-to-seek delegation, keyed by the article root rather than the document.
|
|
3
|
+
*
|
|
4
|
+
* The shipped player attached a `click` listener to `document` from inside every
|
|
5
|
+
* player's init function. On a page with one player per post -- an index page, the
|
|
6
|
+
* common case -- clicking any word ran every listener, so every player seeked to that
|
|
7
|
+
* word and called play(). Several tracks started at once.
|
|
8
|
+
*
|
|
9
|
+
* Here each article root gets exactly one listener no matter how many players are on
|
|
10
|
+
* the page, and a word only ever reaches the player that owns the root containing it.
|
|
11
|
+
*/
|
|
12
|
+
export type SeekHandler = (dataI: number) => void;
|
|
13
|
+
export interface SeekDelegateOptions {
|
|
14
|
+
wordSelector?: string;
|
|
15
|
+
/** Marks the root so CSS can show a pointer cursor over words. */
|
|
16
|
+
activeClass?: string;
|
|
17
|
+
/** Reports an ambiguous configuration; defaults to console.warn. */
|
|
18
|
+
onWarn?: (message: string) => void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Route word clicks inside `root` to `handler`. Returns an unregister function.
|
|
22
|
+
*/
|
|
23
|
+
export declare function registerSeekRoot(root: Element, handler: SeekHandler, options?: SeekDelegateOptions): () => void;
|
|
24
|
+
//# sourceMappingURL=seek-delegate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seek-delegate.d.ts","sourceRoot":"","sources":["../../src/player-core/seek-delegate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;AASlD,MAAM,WAAW,mBAAmB;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kEAAkE;IAClE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oEAAoE;IACpE,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,WAAW,EACpB,OAAO,GAAE,mBAAwB,GAChC,MAAM,IAAI,CAuDZ"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Click-to-seek delegation, keyed by the article root rather than the document.
|
|
3
|
+
*
|
|
4
|
+
* The shipped player attached a `click` listener to `document` from inside every
|
|
5
|
+
* player's init function. On a page with one player per post -- an index page, the
|
|
6
|
+
* common case -- clicking any word ran every listener, so every player seeked to that
|
|
7
|
+
* word and called play(). Several tracks started at once.
|
|
8
|
+
*
|
|
9
|
+
* Here each article root gets exactly one listener no matter how many players are on
|
|
10
|
+
* the page, and a word only ever reaches the player that owns the root containing it.
|
|
11
|
+
*/
|
|
12
|
+
const bindings = new WeakMap();
|
|
13
|
+
/**
|
|
14
|
+
* Route word clicks inside `root` to `handler`. Returns an unregister function.
|
|
15
|
+
*/
|
|
16
|
+
export function registerSeekRoot(root, handler, options = {}) {
|
|
17
|
+
const { wordSelector = ".vocasync-word[data-i]", activeClass = "vocasync-click-seek", onWarn = (message) => console.warn(message), } = options;
|
|
18
|
+
let binding = bindings.get(root);
|
|
19
|
+
if (!binding) {
|
|
20
|
+
const created = {
|
|
21
|
+
handlers: [],
|
|
22
|
+
listener: (event) => {
|
|
23
|
+
const target = event.target;
|
|
24
|
+
const span = target?.closest?.(wordSelector);
|
|
25
|
+
if (!span)
|
|
26
|
+
return;
|
|
27
|
+
// Never hijack a text selection the reader is making.
|
|
28
|
+
const selection = root.ownerDocument?.defaultView?.getSelection?.();
|
|
29
|
+
if (selection && selection.toString().length > 0)
|
|
30
|
+
return;
|
|
31
|
+
const dataI = Number.parseInt(span.dataset.i ?? "", 10);
|
|
32
|
+
if (!Number.isFinite(dataI))
|
|
33
|
+
return;
|
|
34
|
+
// Only the owning player acts. Notifying every handler is precisely the
|
|
35
|
+
// bug this module exists to fix.
|
|
36
|
+
created.handlers[0]?.(dataI);
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
root.addEventListener("click", created.listener);
|
|
40
|
+
root.classList.add(activeClass);
|
|
41
|
+
bindings.set(root, created);
|
|
42
|
+
binding = created;
|
|
43
|
+
}
|
|
44
|
+
binding.handlers.push(handler);
|
|
45
|
+
if (binding.handlers.length > 1) {
|
|
46
|
+
onWarn("[vocasync] Two players resolve to the same article root, so click-to-seek is " +
|
|
47
|
+
"ambiguous and only the first player will respond. Give each player its own " +
|
|
48
|
+
"`articleSelector`.");
|
|
49
|
+
}
|
|
50
|
+
return () => {
|
|
51
|
+
const current = bindings.get(root);
|
|
52
|
+
if (!current)
|
|
53
|
+
return;
|
|
54
|
+
const index = current.handlers.indexOf(handler);
|
|
55
|
+
if (index !== -1)
|
|
56
|
+
current.handlers.splice(index, 1);
|
|
57
|
+
if (current.handlers.length === 0) {
|
|
58
|
+
root.removeEventListener("click", current.listener);
|
|
59
|
+
root.classList.remove(activeClass);
|
|
60
|
+
bindings.delete(root);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=seek-delegate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seek-delegate.js","sourceRoot":"","sources":["../../src/player-core/seek-delegate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AASH,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAwB,CAAC;AAUrD;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,IAAa,EACb,OAAoB,EACpB,OAAO,GAAwB,EAAE;IAEjC,MAAM,EACJ,YAAY,GAAG,wBAAwB,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C;IACpB,CAAC;IAED,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC/B,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChC,MAAM,CACJ,+EAA+E;YAC7E,6EAA6E;YAC7E,oBAAoB,CACvB,CAAC;IACJ,CAAC;IAED,OAAO,GAAG,EAAE;QACV,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACnC,IAAI,CAAC,OAAO;YAAE,OAAO;QACrB,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAChD,IAAI,KAAK,KAAK,CAAC,CAAC;YAAE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACpD,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAClC,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;YACpD,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YACnC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remembered playback preferences and positions.
|
|
3
|
+
*
|
|
4
|
+
* Every access is guarded. `localStorage` throws outright when a browser is
|
|
5
|
+
* configured to block site data, and in Safari's private mode writes throw once the
|
|
6
|
+
* quota is hit -- a player that crashes on boot because someone hardened their
|
|
7
|
+
* browser would be a poor trade for remembering a volume setting.
|
|
8
|
+
*/
|
|
9
|
+
/** Preferences shared by every player on the site. */
|
|
10
|
+
export interface PlayerPrefs {
|
|
11
|
+
rate?: number;
|
|
12
|
+
volume?: number;
|
|
13
|
+
muted?: boolean;
|
|
14
|
+
highlighting?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface StorageLike {
|
|
17
|
+
getItem(key: string): string | null;
|
|
18
|
+
setItem(key: string, value: string): void;
|
|
19
|
+
removeItem(key: string): void;
|
|
20
|
+
}
|
|
21
|
+
/** Returns null rather than throwing when storage is unavailable. */
|
|
22
|
+
export declare function getStorage(view?: {
|
|
23
|
+
localStorage?: StorageLike;
|
|
24
|
+
} | null): StorageLike | null;
|
|
25
|
+
export declare function readPrefs(store: StorageLike | null): PlayerPrefs;
|
|
26
|
+
export declare function writePrefs(store: StorageLike | null, patch: PlayerPrefs): void;
|
|
27
|
+
export declare function readPosition(store: StorageLike | null, slug: string): number | null;
|
|
28
|
+
export declare function writePosition(store: StorageLike | null, slug: string, seconds: number): void;
|
|
29
|
+
export declare function clearPosition(store: StorageLike | null, slug: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* Where to resume, given a remembered position.
|
|
32
|
+
*
|
|
33
|
+
* Declines when the reader was essentially at the start or had all but finished, so a
|
|
34
|
+
* fresh listen is not skipped a few seconds in and a completed article does not
|
|
35
|
+
* reopen at its final second.
|
|
36
|
+
*/
|
|
37
|
+
export declare function resumePoint(saved: number | null, duration: number): number | null;
|
|
38
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/player-core/storage.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,sDAAsD;AACtD,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACpC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED,qEAAqE;AACrE,wBAAgB,UAAU,CAAC,IAAI,CAAC,EAAE;IAAE,YAAY,CAAC,EAAE,WAAW,CAAA;CAAE,GAAG,IAAI,GAAG,WAAW,GAAG,IAAI,CAY3F;AAcD,wBAAgB,SAAS,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,GAAG,WAAW,CAYhE;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,EAAE,KAAK,EAAE,WAAW,GAAG,IAAI,CAO9E;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGnF;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAO5F;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAO3E;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKjF"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remembered playback preferences and positions.
|
|
3
|
+
*
|
|
4
|
+
* Every access is guarded. `localStorage` throws outright when a browser is
|
|
5
|
+
* configured to block site data, and in Safari's private mode writes throw once the
|
|
6
|
+
* quota is hit -- a player that crashes on boot because someone hardened their
|
|
7
|
+
* browser would be a poor trade for remembering a volume setting.
|
|
8
|
+
*/
|
|
9
|
+
const PREFS_KEY = "vocasync:prefs";
|
|
10
|
+
const POSITION_PREFIX = "vocasync:pos:";
|
|
11
|
+
/** Returns null rather than throwing when storage is unavailable. */
|
|
12
|
+
export function getStorage(view) {
|
|
13
|
+
try {
|
|
14
|
+
const store = view?.localStorage;
|
|
15
|
+
if (!store)
|
|
16
|
+
return null;
|
|
17
|
+
// Presence is not permission: probe before trusting it.
|
|
18
|
+
const probe = "vocasync:probe";
|
|
19
|
+
store.setItem(probe, "1");
|
|
20
|
+
store.removeItem(probe);
|
|
21
|
+
return store;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function readJson(store, key) {
|
|
28
|
+
if (!store)
|
|
29
|
+
return null;
|
|
30
|
+
try {
|
|
31
|
+
const raw = store.getItem(key);
|
|
32
|
+
return raw ? JSON.parse(raw) : null;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const isFiniteNumber = (v) => typeof v === "number" && Number.isFinite(v);
|
|
39
|
+
export function readPrefs(store) {
|
|
40
|
+
const raw = readJson(store, PREFS_KEY);
|
|
41
|
+
if (!raw || typeof raw !== "object")
|
|
42
|
+
return {};
|
|
43
|
+
const { rate, volume, muted, highlighting } = raw;
|
|
44
|
+
const prefs = {};
|
|
45
|
+
// Validate rather than trust: this is user-writable storage, and a bad rate would
|
|
46
|
+
// be assigned straight to playbackRate.
|
|
47
|
+
if (isFiniteNumber(rate) && rate > 0 && rate <= 5)
|
|
48
|
+
prefs.rate = rate;
|
|
49
|
+
if (isFiniteNumber(volume) && volume >= 0 && volume <= 1)
|
|
50
|
+
prefs.volume = volume;
|
|
51
|
+
if (typeof muted === "boolean")
|
|
52
|
+
prefs.muted = muted;
|
|
53
|
+
if (typeof highlighting === "boolean")
|
|
54
|
+
prefs.highlighting = highlighting;
|
|
55
|
+
return prefs;
|
|
56
|
+
}
|
|
57
|
+
export function writePrefs(store, patch) {
|
|
58
|
+
if (!store)
|
|
59
|
+
return;
|
|
60
|
+
try {
|
|
61
|
+
store.setItem(PREFS_KEY, JSON.stringify({ ...readPrefs(store), ...patch }));
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// Quota or a blocked write; preferences are a convenience, not a requirement.
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export function readPosition(store, slug) {
|
|
68
|
+
const raw = readJson(store, POSITION_PREFIX + slug);
|
|
69
|
+
return isFiniteNumber(raw) && raw > 0 ? raw : null;
|
|
70
|
+
}
|
|
71
|
+
export function writePosition(store, slug, seconds) {
|
|
72
|
+
if (!store || !Number.isFinite(seconds))
|
|
73
|
+
return;
|
|
74
|
+
try {
|
|
75
|
+
store.setItem(POSITION_PREFIX + slug, JSON.stringify(seconds));
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
/* ignore */
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export function clearPosition(store, slug) {
|
|
82
|
+
if (!store)
|
|
83
|
+
return;
|
|
84
|
+
try {
|
|
85
|
+
store.removeItem(POSITION_PREFIX + slug);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
/* ignore */
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Where to resume, given a remembered position.
|
|
93
|
+
*
|
|
94
|
+
* Declines when the reader was essentially at the start or had all but finished, so a
|
|
95
|
+
* fresh listen is not skipped a few seconds in and a completed article does not
|
|
96
|
+
* reopen at its final second.
|
|
97
|
+
*/
|
|
98
|
+
export function resumePoint(saved, duration) {
|
|
99
|
+
if (saved === null || !Number.isFinite(duration) || duration <= 0)
|
|
100
|
+
return null;
|
|
101
|
+
if (saved < 5)
|
|
102
|
+
return null;
|
|
103
|
+
if (saved > duration - 10)
|
|
104
|
+
return null;
|
|
105
|
+
return saved;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["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KAAK,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,OAAO;IAChD,IAAI,CAAC;QACH,KAAK,CAAC,OAAO,CAAC,eAAe,GAAG,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;IACjE,CAAC;IAAC,MAAM,CAAC;QACP,YAAY;IACd,CAAC;AACH,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAyB,EAAE,IAAY;IACnE,IAAI,CAAC,KAAK;QAAE,OAAO;IACnB,IAAI,CAAC;QACH,KAAK,CAAC,UAAU,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IAC3C,CAAC;IAAC,MAAM,CAAC;QACP,YAAY;IACd,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,KAAoB,EAAE,QAAgB;IAChE,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,QAAQ,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC/E,IAAI,KAAK,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3B,IAAI,KAAK,GAAG,QAAQ,GAAG,EAAE;QAAE,OAAO,IAAI,CAAC;IACvC,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every piece of text the player can show or announce.
|
|
3
|
+
*
|
|
4
|
+
* All of it was hardcoded English -- including the aria-labels -- in a product whose
|
|
5
|
+
* premise is 57 languages. The keys are the contract; how they get filled is up to the
|
|
6
|
+
* platform (a `strings` prop here, gettext in the WordPress plugin).
|
|
7
|
+
*/
|
|
8
|
+
export interface PlayerStrings {
|
|
9
|
+
/** Accessible name for the player region. */
|
|
10
|
+
label: string;
|
|
11
|
+
loading: string;
|
|
12
|
+
/** Shown when the article has no audio. */
|
|
13
|
+
unavailable: string;
|
|
14
|
+
/** Shown when the audio exists but failed to load. */
|
|
15
|
+
error: string;
|
|
16
|
+
retry: string;
|
|
17
|
+
play: string;
|
|
18
|
+
pause: string;
|
|
19
|
+
seek: string;
|
|
20
|
+
/**
|
|
21
|
+
* Announced by the seek slider. `{current}` and `{total}` are replaced with spoken
|
|
22
|
+
* durations, e.g. "2 minutes 30 seconds of 10 minutes".
|
|
23
|
+
*/
|
|
24
|
+
seekPosition: string;
|
|
25
|
+
mute: string;
|
|
26
|
+
unmute: string;
|
|
27
|
+
volume: string;
|
|
28
|
+
speed: string;
|
|
29
|
+
/** Label for a speed step. `{rate}` is replaced with the playback rate. */
|
|
30
|
+
speedValue: string;
|
|
31
|
+
highlightOn: string;
|
|
32
|
+
highlightOff: string;
|
|
33
|
+
/** Accessible name for skip-back. `{seconds}` is replaced with the interval. */
|
|
34
|
+
skipBack: string;
|
|
35
|
+
skipForward: string;
|
|
36
|
+
}
|
|
37
|
+
export declare const defaultStrings: PlayerStrings;
|
|
38
|
+
/**
|
|
39
|
+
* Every string is a plain string, so all of them are translatable and all of them
|
|
40
|
+
* survive JSON. They were briefly functions, which quietly made the four
|
|
41
|
+
* placeholder-bearing ones -- the skip labels, the rate label and the seek
|
|
42
|
+
* announcement -- impossible to override at all.
|
|
43
|
+
*/
|
|
44
|
+
export type SerializableStrings = PlayerStrings;
|
|
45
|
+
export declare function resolveStrings(overrides?: Partial<PlayerStrings>): PlayerStrings;
|
|
46
|
+
/**
|
|
47
|
+
* Substitute `{name}` placeholders. Unknown placeholders are left alone rather than
|
|
48
|
+
* blanked, so a mistyped key in a translation is visible instead of silently missing.
|
|
49
|
+
*/
|
|
50
|
+
export declare function formatString(template: string, vars: Record<string, string | number>): string;
|
|
51
|
+
/** Spoken duration for aria-valuetext: "2 minutes 30 seconds", not "150". */
|
|
52
|
+
export declare function describeTime(seconds: number): string;
|
|
53
|
+
//# sourceMappingURL=strings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src/player-core/strings.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC5B,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,WAAW,EAAE,MAAM,CAAC;IACpB,sDAAsD;IACtD,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,2EAA2E;IAC3E,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,gFAAgF;IAChF,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,cAAc,EAAE,aAmB5B,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG,aAAa,CAAC;AAEhD,wBAAgB,cAAc,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,aAAa,CAEhF;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG,MAAM,CAE5F;AAED,6EAA6E;AAC7E,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CASpD"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export const defaultStrings = {
|
|
2
|
+
label: "Listen to this article",
|
|
3
|
+
loading: "Loading audio…",
|
|
4
|
+
unavailable: "Audio not available for this article",
|
|
5
|
+
error: "Audio could not be loaded",
|
|
6
|
+
retry: "Try again",
|
|
7
|
+
play: "Play",
|
|
8
|
+
pause: "Pause",
|
|
9
|
+
seek: "Seek",
|
|
10
|
+
seekPosition: "{current} of {total}",
|
|
11
|
+
mute: "Mute",
|
|
12
|
+
unmute: "Unmute",
|
|
13
|
+
volume: "Volume",
|
|
14
|
+
speed: "Playback speed",
|
|
15
|
+
speedValue: "{rate}x",
|
|
16
|
+
highlightOn: "Disable word highlighting",
|
|
17
|
+
highlightOff: "Enable word highlighting",
|
|
18
|
+
skipBack: "Back {seconds} seconds",
|
|
19
|
+
skipForward: "Forward {seconds} seconds",
|
|
20
|
+
};
|
|
21
|
+
export function resolveStrings(overrides) {
|
|
22
|
+
return { ...defaultStrings, ...(overrides ?? {}) };
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Substitute `{name}` placeholders. Unknown placeholders are left alone rather than
|
|
26
|
+
* blanked, so a mistyped key in a translation is visible instead of silently missing.
|
|
27
|
+
*/
|
|
28
|
+
export function formatString(template, vars) {
|
|
29
|
+
return template.replace(/\{(\w+)\}/g, (match, key) => (key in vars ? String(vars[key]) : match));
|
|
30
|
+
}
|
|
31
|
+
/** Spoken duration for aria-valuetext: "2 minutes 30 seconds", not "150". */
|
|
32
|
+
export function describeTime(seconds) {
|
|
33
|
+
if (!Number.isFinite(seconds) || seconds < 0)
|
|
34
|
+
return "0 seconds";
|
|
35
|
+
const total = Math.floor(seconds);
|
|
36
|
+
const m = Math.floor(total / 60);
|
|
37
|
+
const s = total % 60;
|
|
38
|
+
const parts = [];
|
|
39
|
+
if (m)
|
|
40
|
+
parts.push(`${m} minute${m === 1 ? "" : "s"}`);
|
|
41
|
+
if (s || !m)
|
|
42
|
+
parts.push(`${s} second${s === 1 ? "" : "s"}`);
|
|
43
|
+
return parts.join(" ");
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=strings.js.map
|
|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K,CAAC,OAAO,CAAC,CAAC;IAClC,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC;IACjC,MAAM,CAAC,GAAG,KAAK,GAAG,EAAE,CAAC;IACrB,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;IACtD,IAAI,CAAC,IAAI,CAAC,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;IAC5D,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure word-highlighting math. No DOM, no audio element, no side effects.
|
|
3
|
+
*
|
|
4
|
+
* The rehype plugin wraps each visible word in a span carrying `data-i` (its start
|
|
5
|
+
* index in the alignment word stream) and `data-n` (how many alignment tokens it
|
|
6
|
+
* consumes). One visible unit can span several tokens -- "$50" is spoken as two
|
|
7
|
+
* tokens, an equation as many -- so its span runs from the earliest start to the
|
|
8
|
+
* latest end of the tokens it covers.
|
|
9
|
+
*
|
|
10
|
+
* `ref` is passed through opaquely: the DOM element in the browser, an id in tests.
|
|
11
|
+
*/
|
|
12
|
+
/** Tolerance for float comparisons against alignment timings. */
|
|
13
|
+
export declare const EPS = 0.0001;
|
|
14
|
+
/** A word timing from the alignment stream. */
|
|
15
|
+
export interface WordTiming {
|
|
16
|
+
start: number;
|
|
17
|
+
end: number;
|
|
18
|
+
}
|
|
19
|
+
/** A visible unit and the slice of the alignment stream it covers. */
|
|
20
|
+
export interface SpanItem<Ref> {
|
|
21
|
+
dataI: number;
|
|
22
|
+
dataN: number;
|
|
23
|
+
ref: Ref;
|
|
24
|
+
}
|
|
25
|
+
/** A visible unit resolved to a time span. */
|
|
26
|
+
export interface SpanTiming<Ref> {
|
|
27
|
+
start: number;
|
|
28
|
+
end: number;
|
|
29
|
+
ref: Ref;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Resolve each visible unit to `min(start)..max(end)` over the alignment tokens it
|
|
33
|
+
* covers. Units whose tokens are all missing are dropped rather than guessed at, so a
|
|
34
|
+
* stale audio map degrades to "some words never highlight" instead of highlighting
|
|
35
|
+
* the wrong ones. The result is sorted by start time, which `idxForTime` relies on.
|
|
36
|
+
*/
|
|
37
|
+
export declare function computeSpanTimings<Ref>(items: readonly SpanItem<Ref>[], words: readonly WordTiming[]): SpanTiming<Ref>[];
|
|
38
|
+
/**
|
|
39
|
+
* Index of the first span whose end is after `t`. Returns `spanTimings.length` when
|
|
40
|
+
* `t` is past every span, and -1 when there are none. The result is a *candidate*:
|
|
41
|
+
* the caller still has to check that `t` falls inside that span, because the audio
|
|
42
|
+
* has real silence between words where nothing should be highlighted.
|
|
43
|
+
*/
|
|
44
|
+
export declare function idxForTime<Ref>(spanTimings: readonly SpanTiming<Ref>[], t: number): number;
|
|
45
|
+
/**
|
|
46
|
+
* The span active at `t`, or null when `t` falls in silence between words.
|
|
47
|
+
*/
|
|
48
|
+
export declare function spanAtTime<Ref>(spanTimings: readonly SpanTiming<Ref>[], t: number): SpanTiming<Ref> | null;
|
|
49
|
+
/**
|
|
50
|
+
* The half-open range `[start, end)` of spans forming the trail behind index `lo`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function trailRange(lo: number, trailLength: number): {
|
|
53
|
+
start: number;
|
|
54
|
+
end: number;
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=timings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timings.d.ts","sourceRoot":"","sources":["../../src/player-core/timings.ts"],"names":[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
3
|
+
*
|
|
4
|
+
* The rehype plugin wraps each visible word in a span carrying `data-i` (its start
|
|
5
|
+
* index in the alignment word stream) and `data-n` (how many alignment tokens it
|
|
6
|
+
* consumes). One visible unit can span several tokens -- "$50" is spoken as two
|
|
7
|
+
* tokens, an equation as many -- so its span runs from the earliest start to the
|
|
8
|
+
* latest end of the tokens it covers.
|
|
9
|
+
*
|
|
10
|
+
* `ref` is passed through opaquely: the DOM element in the browser, an id in tests.
|
|
11
|
+
*/
|
|
12
|
+
/** Tolerance for float comparisons against alignment timings. */
|
|
13
|
+
export const EPS = 0.0001;
|
|
14
|
+
/**
|
|
15
|
+
* Resolve each visible unit to `min(start)..max(end)` over the alignment tokens it
|
|
16
|
+
* covers. Units whose tokens are all missing are dropped rather than guessed at, so a
|
|
17
|
+
* stale audio map degrades to "some words never highlight" instead of highlighting
|
|
18
|
+
* the wrong ones. The result is sorted by start time, which `idxForTime` relies on.
|
|
19
|
+
*/
|
|
20
|
+
export function computeSpanTimings(items, words) {
|
|
21
|
+
const out = [];
|
|
22
|
+
for (const item of items) {
|
|
23
|
+
const { dataI, dataN, ref } = item;
|
|
24
|
+
if (!Number.isFinite(dataI) || !Number.isFinite(dataN) || dataN < 1)
|
|
25
|
+
continue;
|
|
26
|
+
let minStart = Number.POSITIVE_INFINITY;
|
|
27
|
+
let maxEnd = Number.NEGATIVE_INFINITY;
|
|
28
|
+
for (let k = dataI; k < dataI + dataN; k++) {
|
|
29
|
+
const t = words[k];
|
|
30
|
+
if (!t)
|
|
31
|
+
continue;
|
|
32
|
+
if (t.start < minStart)
|
|
33
|
+
minStart = t.start;
|
|
34
|
+
if (t.end > maxEnd)
|
|
35
|
+
maxEnd = t.end;
|
|
36
|
+
}
|
|
37
|
+
if (Number.isFinite(minStart) && Number.isFinite(maxEnd)) {
|
|
38
|
+
// Widen a zero-length or inverted span. `idxForTime` advances past any span
|
|
39
|
+
// whose end is <= t, so a span with end == start can never be selected and the
|
|
40
|
+
// word would silently never highlight. Only degenerate alignment data is
|
|
41
|
+
// affected; every real span already has end > start.
|
|
42
|
+
if (!(maxEnd > minStart))
|
|
43
|
+
maxEnd = minStart + EPS;
|
|
44
|
+
out.push({ start: minStart, end: maxEnd, ref });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
out.sort((a, b) => a.start - b.start);
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Index of the first span whose end is after `t`. Returns `spanTimings.length` when
|
|
52
|
+
* `t` is past every span, and -1 when there are none. The result is a *candidate*:
|
|
53
|
+
* the caller still has to check that `t` falls inside that span, because the audio
|
|
54
|
+
* has real silence between words where nothing should be highlighted.
|
|
55
|
+
*/
|
|
56
|
+
export function idxForTime(spanTimings, t) {
|
|
57
|
+
const n = spanTimings.length;
|
|
58
|
+
if (!n)
|
|
59
|
+
return -1;
|
|
60
|
+
let lo = 0;
|
|
61
|
+
let hi = n - 1;
|
|
62
|
+
while (lo <= hi) {
|
|
63
|
+
const mid = (lo + hi) >> 1;
|
|
64
|
+
if (spanTimings[mid].end <= t)
|
|
65
|
+
lo = mid + 1;
|
|
66
|
+
else
|
|
67
|
+
hi = mid - 1;
|
|
68
|
+
}
|
|
69
|
+
return lo;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The span active at `t`, or null when `t` falls in silence between words.
|
|
73
|
+
*/
|
|
74
|
+
export function spanAtTime(spanTimings, t) {
|
|
75
|
+
if (!Number.isFinite(t))
|
|
76
|
+
return null;
|
|
77
|
+
const lo = idxForTime(spanTimings, t + EPS);
|
|
78
|
+
const entry = spanTimings[lo];
|
|
79
|
+
if (!entry)
|
|
80
|
+
return null;
|
|
81
|
+
return t >= entry.start - EPS && t < entry.end + EPS ? entry : null;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The half-open range `[start, end)` of spans forming the trail behind index `lo`.
|
|
85
|
+
*/
|
|
86
|
+
export function trailRange(lo, trailLength) {
|
|
87
|
+
const end = Math.max(0, lo);
|
|
88
|
+
return { start: Math.max(0, end - Math.max(0, trailLength)), end };
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=timings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timings.js","sourceRoot":"","sources":["../../src/player-core/timings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,iEAAiE;AACjE,MAAM,CAAC,MAAM,GAAG,GAAG,MAAM,CAAC;AAsB1B;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAChC,KAA+B,EAC/B,KAA4B;IAE5B,MAAM,GAAG,GAAsB,EAAE,CAAC;IAElC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QACnC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC;YAAE,SAAS;QAE9E,IAAI,QAAQ,GAAG,MAAM,CAAC,iBAAiB,CAAC;QACxC,IAAI,MAAM,GAAG,MAAM,CAAC,iBAAiB,CAAC;QACtC,KAAK,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,KAAK,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;YAC3C,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YACnB,IAAI,CAAC,CAAC;gBAAE,SAAS;YACjB,IAAI,CAAC,CAAC,KAAK,GAAG,QAAQ;gBAAE,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC;YAC3C,IAAI,CAAC,CAAC,GAAG,GAAG,MAAM;gBAAE,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC;QACrC,CAAC;QAED,IAAI,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,M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AAC,CAAC;IAC5C,MAAM,KAAK,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC;IAC9B,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxB,OAAO,CAAC,IAAI,KAAK,CAAC,KAAK,GAAG,GAAG,IAAI,CAAC,GAAG,KAAK,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACtE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,EAAU,EAAE,WAAmB;IACxD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC5B,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC;AACrE,CAAC"}
|
|
@@ -10,10 +10,16 @@ export interface RehypeAudioWordsOptions {
|
|
|
10
10
|
*/
|
|
11
11
|
audioMapPath?: string;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* An extra class added to every word span, alongside `vocasync-word`.
|
|
14
|
+
*
|
|
15
|
+
* Additive on purpose. The previous `classPrefix` option renamed the span class but
|
|
16
|
+
* nothing else: `.vocasync-word` stayed hardcoded in the stylesheet, the player and
|
|
17
|
+
* the WordPress fork, and `.vocasync-click-seek` and `.vocasync-math` were never
|
|
18
|
+
* covered at all -- so setting it silently broke highlighting. If you need to
|
|
19
|
+
* restyle the spans, target this class or override the tokens; if you need entirely
|
|
20
|
+
* different markup, drive the engine yourself via `@vocasync/astro/player-core`.
|
|
15
21
|
*/
|
|
16
|
-
|
|
22
|
+
extraWordClass?: string;
|
|
17
23
|
/**
|
|
18
24
|
* Content collection folder name used to extract slugs.
|
|
19
25
|
* @default "articles"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audio-words.d.ts","sourceRoot":"","sources":["../../src/rehype/audio-words.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,IAAI,EAAQ,MAAM,MAAM,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAKtC;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB
|
|
1
|
+
{"version":3,"file":"audio-words.d.ts","sourceRoot":"","sources":["../../src/rehype/audio-words.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,IAAI,EAAQ,MAAM,MAAM,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAKtC;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;;;;;;OASG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAuBD;;;;;;;;;;;;;GAaG;AACH,QAAA,MAAM,gBAAgB,EAAE,MAAM,CAAC,CAAC,uBAAuB,CAAC,CAAC,EAAE,IAAI,CAmF9D,CAAC;eAqDa,gBAAgB;AAC/B,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|