@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
package/src/components/index.ts
CHANGED
|
@@ -1,34 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
/** Show placeholder when no audio available */
|
|
21
|
-
showPlaceholder?: boolean;
|
|
22
|
-
/** Additional CSS classes */
|
|
23
|
-
class?: string;
|
|
24
|
-
/** Selector for article body (for word highlighting) */
|
|
25
|
-
articleSelector?: string;
|
|
26
|
-
/** Enable floating mini player when main player scrolls out of view */
|
|
27
|
-
enableMiniPlayer?: boolean;
|
|
28
|
-
/** Enable word highlighting during playback */
|
|
29
|
-
enableHighlighting?: boolean;
|
|
30
|
-
/** Enable click on words to seek to that position */
|
|
31
|
-
enableClickToSeek?: boolean;
|
|
32
|
-
/** Number of trailing highlighted words */
|
|
33
|
-
trailLength?: number;
|
|
34
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Types for the AudioPlayer component.
|
|
3
|
+
*
|
|
4
|
+
* The component itself is an .astro file and cannot be re-exported from JavaScript;
|
|
5
|
+
* import it directly:
|
|
6
|
+
*
|
|
7
|
+
* import AudioPlayer from "@vocasync/astro/components/AudioPlayer.astro";
|
|
8
|
+
*/
|
|
9
|
+
export type {
|
|
10
|
+
AudioEntry,
|
|
11
|
+
AudioPlayerProps,
|
|
12
|
+
AutoScrollMode,
|
|
13
|
+
ControlName,
|
|
14
|
+
DockOptions,
|
|
15
|
+
HighlightOptions,
|
|
16
|
+
PlayerSize,
|
|
17
|
+
PlayerVariant,
|
|
18
|
+
} from "./types.js";
|
|
19
|
+
export { DEFAULT_CONTROLS } from "./types.js";
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { SerializableStrings } from "../player-core/strings.js";
|
|
2
|
+
import type { AlignedWord } from "../types/index.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The AudioPlayer's props, defined once.
|
|
6
|
+
*
|
|
7
|
+
* This file previously described a component that did not exist: it declared
|
|
8
|
+
* `publishableKey` and `alignmentUrl` while the component took `synthesisPublishableKey`
|
|
9
|
+
* and had no `alignmentUrl` at all, and it advertised a named `AudioPlayer` export that
|
|
10
|
+
* could not be imported. The .astro now imports this type rather than restating it, so
|
|
11
|
+
* the two cannot drift again.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** A control the player can render, in the order you list it. */
|
|
15
|
+
export type ControlName =
|
|
16
|
+
| "play"
|
|
17
|
+
/** Elapsed/total time above the seek bar; grows to fill the row. */
|
|
18
|
+
| "progress"
|
|
19
|
+
/** Elapsed/total time on its own. */
|
|
20
|
+
| "time"
|
|
21
|
+
| "highlight"
|
|
22
|
+
| "speed"
|
|
23
|
+
/** Mute button plus volume slider. */
|
|
24
|
+
| "volume"
|
|
25
|
+
/** Jump backwards by `skipSeconds`. */
|
|
26
|
+
| "skip-back"
|
|
27
|
+
/** Jump forwards by `skipSeconds`. */
|
|
28
|
+
| "skip-forward";
|
|
29
|
+
|
|
30
|
+
export const DEFAULT_CONTROLS: ControlName[] = ["play", "progress", "highlight", "speed", "volume"];
|
|
31
|
+
|
|
32
|
+
/** Shape of the player. `bar` is the default horizontal strip. */
|
|
33
|
+
export type PlayerVariant = "bar" | "minimal" | "card";
|
|
34
|
+
|
|
35
|
+
export type PlayerSize = "sm" | "md" | "lg";
|
|
36
|
+
|
|
37
|
+
/** What follows the spoken word as it plays. */
|
|
38
|
+
export type AutoScrollMode = "off" | "paragraph";
|
|
39
|
+
|
|
40
|
+
export interface AudioEntry {
|
|
41
|
+
audioUrl: string;
|
|
42
|
+
words?: AlignedWord[];
|
|
43
|
+
duration?: number;
|
|
44
|
+
/** Publishable key for the synthesis stream (v3 audio-map). */
|
|
45
|
+
synthesisPublishableKey?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface HighlightOptions {
|
|
49
|
+
/** @default true */
|
|
50
|
+
enabled?: boolean;
|
|
51
|
+
/** Words kept marked behind the active one. @default 4 */
|
|
52
|
+
trailLength?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Clicking a word seeks to it.
|
|
55
|
+
*
|
|
56
|
+
* Independent of `enabled`: it used to live inside the highlighting branch, so
|
|
57
|
+
* turning highlighting off silently disabled click-to-seek too.
|
|
58
|
+
*
|
|
59
|
+
* @default true
|
|
60
|
+
*/
|
|
61
|
+
clickToSeek?: boolean;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface DockOptions {
|
|
65
|
+
/** Show a floating player once the main one scrolls out of view. @default true */
|
|
66
|
+
enabled?: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface AudioPlayerProps {
|
|
70
|
+
/** Post slug, used to look up audio and to key saved playback position. */
|
|
71
|
+
slug: string;
|
|
72
|
+
/** Audio entry from audio-map.json. */
|
|
73
|
+
audioEntry?: AudioEntry;
|
|
74
|
+
|
|
75
|
+
/** Shape and scale. */
|
|
76
|
+
variant?: PlayerVariant;
|
|
77
|
+
size?: PlayerSize;
|
|
78
|
+
/** Which controls to render, and in what order. */
|
|
79
|
+
controls?: ControlName[];
|
|
80
|
+
/** Playback rates offered by the speed menu. */
|
|
81
|
+
speeds?: number[];
|
|
82
|
+
/** How far the skip controls and arrow keys jump. @default 15 */
|
|
83
|
+
skipSeconds?: number;
|
|
84
|
+
|
|
85
|
+
/** Overrides for any visible text or accessible label. */
|
|
86
|
+
strings?: Partial<SerializableStrings>;
|
|
87
|
+
|
|
88
|
+
/** Selector for the element containing the article's word spans. */
|
|
89
|
+
articleSelector?: string;
|
|
90
|
+
highlight?: HighlightOptions;
|
|
91
|
+
dock?: DockOptions;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Follow the spoken word by scrolling its paragraph into view.
|
|
95
|
+
*
|
|
96
|
+
* Defaults to off. It was previously forced on with no way to disable it, which
|
|
97
|
+
* takes over the reader's scroll position while they are reading something else.
|
|
98
|
+
*
|
|
99
|
+
* @default "off"
|
|
100
|
+
*/
|
|
101
|
+
autoScroll?: AutoScrollMode;
|
|
102
|
+
|
|
103
|
+
/** Pause other players on the page when this one starts. @default true */
|
|
104
|
+
exclusive?: boolean;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Remember speed, volume, mute and highlighting across pages and visits.
|
|
108
|
+
* @default true
|
|
109
|
+
*/
|
|
110
|
+
rememberPreferences?: boolean;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Resume where the reader left off, keyed by `slug`.
|
|
114
|
+
*
|
|
115
|
+
* Off by default: it is a pleasant surprise on a long article and a confusing one
|
|
116
|
+
* on a short post that someone expects to start from the beginning.
|
|
117
|
+
*
|
|
118
|
+
* @default false
|
|
119
|
+
*/
|
|
120
|
+
rememberPosition?: boolean;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Publish title and artwork to the OS media controls (lock screen, media keys).
|
|
124
|
+
* @default true
|
|
125
|
+
*/
|
|
126
|
+
mediaSession?: boolean;
|
|
127
|
+
|
|
128
|
+
/** Title for the OS media controls. Falls back to the accessible label. */
|
|
129
|
+
title?: string;
|
|
130
|
+
/** Artwork URL for the OS media controls. */
|
|
131
|
+
artwork?: string;
|
|
132
|
+
|
|
133
|
+
/** Show a message when the article has no audio. @default true */
|
|
134
|
+
showPlaceholder?: boolean;
|
|
135
|
+
|
|
136
|
+
/** Extra classes on the player root. */
|
|
137
|
+
class?: string;
|
|
138
|
+
/** Overrides the generated element id. */
|
|
139
|
+
id?: string;
|
|
140
|
+
}
|
package/src/config/index.ts
CHANGED
|
@@ -1,32 +1,31 @@
|
|
|
1
|
-
export {
|
|
2
|
-
VocaSyncConfigSchema,
|
|
3
|
-
CollectionConfigSchema,
|
|
4
|
-
SynthesisConfigSchema,
|
|
5
|
-
MathConfigSchema,
|
|
6
|
-
OutputConfigSchema,
|
|
7
|
-
ProcessingConfigSchema,
|
|
8
|
-
VoiceSchema,
|
|
9
|
-
QualitySchema,
|
|
10
|
-
FormatSchema,
|
|
11
|
-
LanguageSchema,
|
|
12
|
-
MathStyleSchema,
|
|
13
|
-
validateConfig,
|
|
14
|
-
defaultConfig,
|
|
15
|
-
} from "./schema.js";
|
|
1
|
+
export { loadVocaSyncConfig } from "./loader.js";
|
|
16
2
|
|
|
17
3
|
export type {
|
|
18
|
-
VocaSyncConfig,
|
|
19
|
-
VocaSyncUserConfig,
|
|
20
4
|
CollectionConfig,
|
|
21
|
-
|
|
5
|
+
Format,
|
|
6
|
+
Language,
|
|
22
7
|
MathConfig,
|
|
8
|
+
MathStyle,
|
|
23
9
|
OutputConfig,
|
|
24
10
|
ProcessingConfig,
|
|
25
|
-
Voice,
|
|
26
11
|
Quality,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
12
|
+
SynthesisConfig,
|
|
13
|
+
VocaSyncConfig,
|
|
14
|
+
VocaSyncUserConfig,
|
|
15
|
+
Voice,
|
|
16
|
+
} from "./schema.js";
|
|
17
|
+
export {
|
|
18
|
+
CollectionConfigSchema,
|
|
19
|
+
defaultConfig,
|
|
20
|
+
FormatSchema,
|
|
21
|
+
LanguageSchema,
|
|
22
|
+
MathConfigSchema,
|
|
23
|
+
MathStyleSchema,
|
|
24
|
+
OutputConfigSchema,
|
|
25
|
+
ProcessingConfigSchema,
|
|
26
|
+
QualitySchema,
|
|
27
|
+
SynthesisConfigSchema,
|
|
28
|
+
VocaSyncConfigSchema,
|
|
29
|
+
VoiceSchema,
|
|
30
|
+
validateConfig,
|
|
30
31
|
} from "./schema.js";
|
|
31
|
-
|
|
32
|
-
export { loadVocaSyncConfig } from "./loader.js";
|
package/src/config/schema.ts
CHANGED
|
@@ -124,15 +124,15 @@ export const VocaSyncConfigSchema = z.object({
|
|
|
124
124
|
/** Language for synthesis (e.g., "en", "fr", "de") */
|
|
125
125
|
language: LanguageSchema.default("en"),
|
|
126
126
|
/** Synthesis options */
|
|
127
|
-
synthesis: SynthesisConfigSchema.
|
|
127
|
+
synthesis: SynthesisConfigSchema.prefault({}),
|
|
128
128
|
/** Math/LaTeX support */
|
|
129
|
-
math: MathConfigSchema.
|
|
129
|
+
math: MathConfigSchema.prefault({}),
|
|
130
130
|
/** Output paths */
|
|
131
|
-
output: OutputConfigSchema.
|
|
131
|
+
output: OutputConfigSchema.prefault({}),
|
|
132
132
|
/** Frontmatter field to check for audio opt-in/out (true/false) */
|
|
133
133
|
frontmatterField: z.string().optional(),
|
|
134
134
|
/** Processing options */
|
|
135
|
-
processing: ProcessingConfigSchema.
|
|
135
|
+
processing: ProcessingConfigSchema.prefault({}),
|
|
136
136
|
});
|
|
137
137
|
|
|
138
138
|
export type VocaSyncConfig = z.infer<typeof VocaSyncConfigSchema>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readdir, readFile, stat } from "node:fs/promises";
|
|
2
2
|
import { basename, extname, join, relative } from "node:path";
|
|
3
3
|
import type { CollectionConfig } from "../config/index.js";
|
|
4
4
|
import type { ContentItem } from "../types/index.js";
|
package/src/core/index.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export { loadContent, loadContentBySlug } from "./content-loader.js";
|
|
2
|
-
export { buildSpeechDocument } from "./speech-builder.js";
|
|
3
|
-
export { computeHash, hasChanged } from "./hash-manager.js";
|
|
4
1
|
export {
|
|
2
|
+
createEmptyAudioMap,
|
|
3
|
+
getAudioEntry,
|
|
4
|
+
getAudioSlugs,
|
|
5
5
|
loadAudioMap,
|
|
6
|
+
removeAudioEntry,
|
|
6
7
|
saveAudioMap,
|
|
7
|
-
getAudioEntry,
|
|
8
8
|
setAudioEntry,
|
|
9
|
-
removeAudioEntry,
|
|
10
|
-
getAudioSlugs,
|
|
11
|
-
createEmptyAudioMap,
|
|
12
9
|
} from "./audio-map.js";
|
|
10
|
+
export { loadContent, loadContentBySlug } from "./content-loader.js";
|
|
11
|
+
export { computeHash, hasChanged } from "./hash-manager.js";
|
|
12
|
+
export { buildSpeechDocument } from "./speech-builder.js";
|
package/src/env.d.ts
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
declare module "virtual:vocasync/audio-map" {
|
|
4
4
|
import type { AudioMap } from "@vocasync/astro";
|
|
5
|
+
|
|
5
6
|
const audioMap: AudioMap;
|
|
6
7
|
export default audioMap;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
declare module "virtual:vocasync/config" {
|
|
10
11
|
import type { VocaSyncConfig } from "@vocasync/astro";
|
|
12
|
+
|
|
11
13
|
const config: VocaSyncConfig;
|
|
12
14
|
export default config;
|
|
13
15
|
}
|
package/src/index.ts
CHANGED
|
@@ -23,45 +23,40 @@
|
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
export type {
|
|
27
|
+
Format,
|
|
28
|
+
Language,
|
|
29
|
+
MathStyle,
|
|
30
|
+
Quality,
|
|
31
|
+
VocaSyncConfig,
|
|
32
|
+
VocaSyncUserConfig,
|
|
33
|
+
Voice,
|
|
34
|
+
} from "./config/index.js";
|
|
30
35
|
// Configuration
|
|
31
36
|
export {
|
|
32
|
-
validateConfig,
|
|
33
37
|
defaultConfig,
|
|
34
|
-
VocaSyncConfigSchema,
|
|
35
|
-
VoiceSchema,
|
|
36
|
-
QualitySchema,
|
|
37
38
|
FormatSchema,
|
|
38
39
|
LanguageSchema,
|
|
40
|
+
QualitySchema,
|
|
41
|
+
VocaSyncConfigSchema,
|
|
42
|
+
VoiceSchema,
|
|
43
|
+
validateConfig,
|
|
39
44
|
} from "./config/index.js";
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
Language,
|
|
48
|
-
MathStyle,
|
|
49
|
-
} from "./config/index.js";
|
|
50
|
-
|
|
45
|
+
export { getAudioEntry, loadAudioMap, saveAudioMap } from "./core/audio-map.js";
|
|
46
|
+
// Core utilities (for advanced usage)
|
|
47
|
+
export { loadContent } from "./core/content-loader.js";
|
|
48
|
+
export { computeHash } from "./core/hash-manager.js";
|
|
49
|
+
export { buildSpeechDocument } from "./core/speech-builder.js";
|
|
50
|
+
// Astro Integration
|
|
51
|
+
export { default, default as vocasync } from "./integration.js";
|
|
51
52
|
// Types
|
|
52
53
|
export type {
|
|
53
|
-
ContentItem,
|
|
54
|
-
SpeechDocument,
|
|
55
54
|
AlignedWord,
|
|
56
55
|
AudioArtifact,
|
|
57
56
|
AudioMap,
|
|
57
|
+
ContentItem,
|
|
58
|
+
SpeechDocument,
|
|
58
59
|
SyncResult,
|
|
59
|
-
SyncSummary,
|
|
60
60
|
SyncStatus,
|
|
61
|
+
SyncSummary,
|
|
61
62
|
} from "./types/index.js";
|
|
62
|
-
|
|
63
|
-
// Core utilities (for advanced usage)
|
|
64
|
-
export { loadContent } from "./core/content-loader.js";
|
|
65
|
-
export { buildSpeechDocument } from "./core/speech-builder.js";
|
|
66
|
-
export { computeHash } from "./core/hash-manager.js";
|
|
67
|
-
export { loadAudioMap, saveAudioMap, getAudioEntry } from "./core/audio-map.js";
|
package/src/integration.ts
CHANGED
|
@@ -1,19 +1,62 @@
|
|
|
1
1
|
import type { AstroIntegration } from "astro";
|
|
2
|
-
import { type VocaSyncConfig,
|
|
2
|
+
import { loadVocaSyncConfig, type VocaSyncConfig, validateConfig } from "./config/index.js";
|
|
3
3
|
import { createEmptyAudioMap, loadAudioMap } from "./core/audio-map.js";
|
|
4
4
|
import type { AudioMap } from "./types/index.js";
|
|
5
5
|
|
|
6
6
|
// Cache for the loaded audio map
|
|
7
7
|
let audioMapCache: AudioMap | null = null;
|
|
8
8
|
|
|
9
|
+
export interface VocaSyncThemeOptions {
|
|
10
|
+
/**
|
|
11
|
+
* A selector your site already uses to signal dark mode, e.g. `".dark"` or
|
|
12
|
+
* `'[data-theme="night"]'`. The player's dark tokens are emitted under it as well.
|
|
13
|
+
*
|
|
14
|
+
* Usually unnecessary: `.dark`, `[data-theme="dark"]` and `[data-mode="dark"]` are
|
|
15
|
+
* recognised out of the box, which covers Tailwind, next-themes, daisyUI and
|
|
16
|
+
* Starlight. Reach for this only when your site signals dark mode some other way.
|
|
17
|
+
*/
|
|
18
|
+
darkSelector?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface VocaSyncOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Inject the player stylesheet on every page. Set false to import the parts
|
|
24
|
+
* yourself -- `@vocasync/astro/styles/vocasync.css`, or just `content.css` when you
|
|
25
|
+
* drive the engine headlessly and ship your own chrome.
|
|
26
|
+
*
|
|
27
|
+
* @default true
|
|
28
|
+
*/
|
|
29
|
+
styles?: boolean;
|
|
30
|
+
theme?: VocaSyncThemeOptions;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Dark-mode tokens, emitted again under a host's own dark selector. */
|
|
34
|
+
const DARK_TOKENS = `
|
|
35
|
+
--vocasync-accent: #60a5fa;
|
|
36
|
+
--vocasync-surface: #1e293b;
|
|
37
|
+
--vocasync-text: #f1f5f9;
|
|
38
|
+
--vocasync-highlight: #34d399;
|
|
39
|
+
--vocasync-accent-hover: #3b82f6;
|
|
40
|
+
--vocasync-accent-content: #1e293b;
|
|
41
|
+
--vocasync-surface-raised: #334155;
|
|
42
|
+
--vocasync-text-muted: #94a3b8;
|
|
43
|
+
--vocasync-text-faint: #64748b;
|
|
44
|
+
--vocasync-border: #475569;
|
|
45
|
+
--vocasync-track: #475569;
|
|
46
|
+
`;
|
|
47
|
+
|
|
9
48
|
/**
|
|
10
49
|
* VocaSync Astro Integration.
|
|
11
50
|
*
|
|
12
51
|
* Provides:
|
|
13
52
|
* - Virtual module `virtual:vocasync/audio-map` for accessing audio data
|
|
14
|
-
* -
|
|
53
|
+
* - The player stylesheet, injected on every page unless `styles: false`
|
|
15
54
|
* - Optional build-time sync command
|
|
16
55
|
*
|
|
56
|
+
* It does NOT register the rehype plugins. Add `rehypeMathSpeech` and
|
|
57
|
+
* `rehypeAudioWords` to `markdown.rehypePlugins` yourself; their order relative to
|
|
58
|
+
* your maths renderer matters, so it is left explicit.
|
|
59
|
+
*
|
|
17
60
|
* @example
|
|
18
61
|
* ```typescript
|
|
19
62
|
* // astro.config.mjs
|
|
@@ -29,11 +72,12 @@ let audioMapCache: AudioMap | null = null;
|
|
|
29
72
|
* };
|
|
30
73
|
* ```
|
|
31
74
|
*/
|
|
32
|
-
export default function vocasyncIntegration(): AstroIntegration {
|
|
75
|
+
export default function vocasyncIntegration(options: VocaSyncOptions = {}): AstroIntegration {
|
|
76
|
+
const { styles = true, theme = {} } = options;
|
|
33
77
|
return {
|
|
34
78
|
name: "@vocasync/astro",
|
|
35
79
|
hooks: {
|
|
36
|
-
"astro:config:setup": async ({ updateConfig, logger }) => {
|
|
80
|
+
"astro:config:setup": async ({ updateConfig, injectScript, logger }) => {
|
|
37
81
|
// Load config from vocasync.config.mjs
|
|
38
82
|
let config: VocaSyncConfig;
|
|
39
83
|
try {
|
|
@@ -46,6 +90,15 @@ export default function vocasyncIntegration(): AstroIntegration {
|
|
|
46
90
|
|
|
47
91
|
logger.info("VocaSync integration loaded");
|
|
48
92
|
|
|
93
|
+
// Injected rather than left to the consumer: forgetting the import used to
|
|
94
|
+
// yield an unstyled player AND invisible word highlighting, with no error.
|
|
95
|
+
if (styles) {
|
|
96
|
+
injectScript("page-ssr", 'import "@vocasync/astro/styles/vocasync.css";');
|
|
97
|
+
if (theme.darkSelector) {
|
|
98
|
+
injectScript("page-ssr", 'import "virtual:vocasync/theme.css";');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
49
102
|
// Pre-load audio map for rehype plugin
|
|
50
103
|
try {
|
|
51
104
|
audioMapCache = await loadAudioMap(config.output.audioMapPath);
|
|
@@ -70,6 +123,11 @@ export default function vocasyncIntegration(): AstroIntegration {
|
|
|
70
123
|
if (id === "virtual:vocasync/config") {
|
|
71
124
|
return "\0virtual:vocasync/config";
|
|
72
125
|
}
|
|
126
|
+
// Keep the .css suffix: Vite decides how to handle a module by its
|
|
127
|
+
// extension, and without it this would be treated as JavaScript.
|
|
128
|
+
if (id === "virtual:vocasync/theme.css") {
|
|
129
|
+
return "\0virtual:vocasync/theme.css";
|
|
130
|
+
}
|
|
73
131
|
return null;
|
|
74
132
|
},
|
|
75
133
|
async load(id: string) {
|
|
@@ -81,6 +139,10 @@ export default function vocasyncIntegration(): AstroIntegration {
|
|
|
81
139
|
// Export the validated config
|
|
82
140
|
return `export default ${JSON.stringify(config)};`;
|
|
83
141
|
}
|
|
142
|
+
if (id === "\0virtual:vocasync/theme.css") {
|
|
143
|
+
if (!theme.darkSelector) return "";
|
|
144
|
+
return `@layer vocasync.tokens {\n ${theme.darkSelector} {${DARK_TOKENS} }\n}\n`;
|
|
145
|
+
}
|
|
84
146
|
return null;
|
|
85
147
|
},
|
|
86
148
|
},
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { createPlayer } from "./player.js";
|
|
2
|
+
import * as registry from "./registry.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Finds every player on the page and wires it up.
|
|
6
|
+
*
|
|
7
|
+
* The component previously used `define:vars`, which forces an inline script: Astro
|
|
8
|
+
* re-executes those on a view-transition swap, so the player kept working across
|
|
9
|
+
* navigations by accident. A hoisted module script does NOT re-execute -- the browser
|
|
10
|
+
* has already loaded it -- so the lifecycle has to be explicit:
|
|
11
|
+
*
|
|
12
|
+
* - boot on load, for pages without <ClientRouter />
|
|
13
|
+
* - boot again on `astro:page-load`, which fires after every swap
|
|
14
|
+
* - tear down on `astro:before-swap`, or animation loops, IntersectionObservers and
|
|
15
|
+
* click delegates leak onto every subsequent page
|
|
16
|
+
*
|
|
17
|
+
* `data-vocasync-ready` makes booting idempotent, since both paths can fire for the
|
|
18
|
+
* same document.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const READY_ATTR = "data-vocasync-ready";
|
|
22
|
+
const PLAYER_SELECTOR = ".vocasync-player";
|
|
23
|
+
|
|
24
|
+
/** Wire up every player in `doc` that is not already running. */
|
|
25
|
+
export function bootAll(doc: Document = document): void {
|
|
26
|
+
for (const el of Array.from(doc.querySelectorAll(PLAYER_SELECTOR))) {
|
|
27
|
+
const root = el as HTMLElement;
|
|
28
|
+
if (root.hasAttribute(READY_ATTR)) continue;
|
|
29
|
+
try {
|
|
30
|
+
createPlayer(root);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
// One malformed player must not stop the others on the page.
|
|
33
|
+
console.error("[vocasync] Failed to initialise player", error);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Destroy every live player. Runs before a view-transition swap. */
|
|
39
|
+
export function teardownAll(): void {
|
|
40
|
+
registry.destroyAll();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let installed = false;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Install the lifecycle once per document. Safe to call repeatedly.
|
|
47
|
+
*/
|
|
48
|
+
export function install(doc: Document = document): void {
|
|
49
|
+
if (installed) return;
|
|
50
|
+
installed = true;
|
|
51
|
+
|
|
52
|
+
if (doc.readyState === "loading") {
|
|
53
|
+
doc.addEventListener("DOMContentLoaded", () => bootAll(doc), { once: true });
|
|
54
|
+
} else {
|
|
55
|
+
bootAll(doc);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Astro's view transitions. These listeners survive swaps because the module is
|
|
59
|
+
// evaluated once; that is precisely why they have to exist.
|
|
60
|
+
doc.addEventListener("astro:page-load", () => bootAll(doc));
|
|
61
|
+
doc.addEventListener("astro:before-swap", teardownAll);
|
|
62
|
+
}
|