@vocasync/astro 1.0.1 → 2.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/README.md +735 -93
- 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 +305 -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 +3 -2
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +2 -1
- package/dist/config/index.js.map +1 -1
- package/dist/config/languages.d.ts +33 -0
- package/dist/config/languages.d.ts.map +1 -0
- package/dist/config/languages.js +167 -0
- package/dist/config/languages.js.map +1 -0
- package/dist/config/schema.d.ts +225 -172
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +45 -24
- 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 +17 -9
- 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 +101 -47
- package/dist/sync/orchestrator.js.map +1 -1
- package/dist/types/index.d.ts +19 -5
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +39 -17
- package/src/api/index.ts +4 -4
- package/src/components/AudioPlayer.astro +305 -1141
- package/src/components/index.ts +19 -34
- package/src/components/types.ts +140 -0
- package/src/config/index.ts +29 -24
- package/src/config/languages.ts +171 -0
- package/src/config/schema.ts +47 -24
- 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 +25 -12
- 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 +120 -56
- package/src/types/index.ts +19 -5
- package/dist/styles/variables.css +0 -164
- package/src/styles/variables.css +0 -164
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The VocaSync theming surface.
|
|
3
|
+
*
|
|
4
|
+
* Four seeds carry a whole theme:
|
|
5
|
+
*
|
|
6
|
+
* :root {
|
|
7
|
+
* --vocasync-accent: #8b5cf6;
|
|
8
|
+
* --vocasync-surface: #faf7ff;
|
|
9
|
+
* --vocasync-text: #1e1b2e;
|
|
10
|
+
* --vocasync-highlight: #f59e0b;
|
|
11
|
+
* }
|
|
12
|
+
*
|
|
13
|
+
* Everything else derives from them, and every derived token can still be overridden
|
|
14
|
+
* on its own. Point a seed at a token you already have and the player adopts your
|
|
15
|
+
* palette -- and your dark mode with it, because your token already flips:
|
|
16
|
+
*
|
|
17
|
+
* :root { --vocasync-accent: var(--primary); }
|
|
18
|
+
*
|
|
19
|
+
* See preset-shadcn.css for that wired up.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/* Must precede @property: only @charset, @import and @layer may come first. */
|
|
23
|
+
@layer vocasync.tokens, vocasync.base, vocasync.variants;
|
|
24
|
+
|
|
25
|
+
/*
|
|
26
|
+
* Registering the seeds means a value that is not a colour -- a gradient, a typo,
|
|
27
|
+
* `currentColor` -- falls back to the default instead of resolving to `unset` and
|
|
28
|
+
* rendering the component invisible. Only the seeds are registered: constraining the
|
|
29
|
+
* derived tokens would stop consumers assigning whatever they like to them.
|
|
30
|
+
*/
|
|
31
|
+
@property --vocasync-accent {
|
|
32
|
+
syntax: "<color>";
|
|
33
|
+
inherits: true;
|
|
34
|
+
initial-value: #3b82f6;
|
|
35
|
+
}
|
|
36
|
+
@property --vocasync-surface {
|
|
37
|
+
syntax: "<color>";
|
|
38
|
+
inherits: true;
|
|
39
|
+
initial-value: #f8fafc;
|
|
40
|
+
}
|
|
41
|
+
@property --vocasync-text {
|
|
42
|
+
syntax: "<color>";
|
|
43
|
+
inherits: true;
|
|
44
|
+
initial-value: #1e293b;
|
|
45
|
+
}
|
|
46
|
+
@property --vocasync-highlight {
|
|
47
|
+
syntax: "<color>";
|
|
48
|
+
inherits: true;
|
|
49
|
+
initial-value: #10b981;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@layer vocasync.tokens {
|
|
53
|
+
:root {
|
|
54
|
+
/* ---------------------------------------------------------------- seeds */
|
|
55
|
+
--vocasync-accent: #3b82f6;
|
|
56
|
+
--vocasync-surface: #f8fafc;
|
|
57
|
+
--vocasync-text: #1e293b;
|
|
58
|
+
--vocasync-highlight: #10b981;
|
|
59
|
+
|
|
60
|
+
/* ------------------------------------------------ derived: static values
|
|
61
|
+
* Overridden below by the @supports blocks wherever the browser can compute
|
|
62
|
+
* them from the seeds. These literals are what a browser without relative
|
|
63
|
+
* colour syntax falls back to, so they match the default seeds rather than
|
|
64
|
+
* tracking a custom one.
|
|
65
|
+
*/
|
|
66
|
+
--vocasync-accent-hover: #2563eb;
|
|
67
|
+
--vocasync-accent-content: #ffffff;
|
|
68
|
+
--vocasync-surface-raised: #ffffff;
|
|
69
|
+
--vocasync-text-muted: #64748b;
|
|
70
|
+
--vocasync-text-faint: #94a3b8;
|
|
71
|
+
--vocasync-border: #e2e8f0;
|
|
72
|
+
--vocasync-track: #e2e8f0;
|
|
73
|
+
--vocasync-buffered-color: #cbd5e1;
|
|
74
|
+
--vocasync-highlight-active-bg: rgb(16 185 129 / 0.25);
|
|
75
|
+
--vocasync-highlight-trail-bg: rgb(16 185 129 / 0.12);
|
|
76
|
+
/* Left unset so the active word keeps the prose colour. Set it to force one. */
|
|
77
|
+
--vocasync-highlight-active-text: ;
|
|
78
|
+
|
|
79
|
+
/* ------------------------------------------------------------ typography
|
|
80
|
+
* The family inherits by default: the player should read as part of the page
|
|
81
|
+
* it sits in, not announce itself.
|
|
82
|
+
*/
|
|
83
|
+
--vocasync-font-family: inherit;
|
|
84
|
+
--vocasync-font-size: 0.875rem;
|
|
85
|
+
--vocasync-font-size-sm: 0.75rem;
|
|
86
|
+
--vocasync-font-weight: 400;
|
|
87
|
+
--vocasync-font-weight-medium: 500;
|
|
88
|
+
--vocasync-line-height: 1.4;
|
|
89
|
+
--vocasync-numeric: tabular-nums;
|
|
90
|
+
|
|
91
|
+
/* ---------------------------------------------------------------- density
|
|
92
|
+
* One multiplier scales padding, gaps and control sizes together, so a player
|
|
93
|
+
* can be made compact without restating a dozen lengths.
|
|
94
|
+
*/
|
|
95
|
+
--vocasync-density: 1;
|
|
96
|
+
--vocasync-unit: 0.25rem;
|
|
97
|
+
/* Undensified base sizes. The density multiplier is applied where each of these is
|
|
98
|
+
* USED, not here: a custom property resolves its var() references on the element
|
|
99
|
+
* that declares it, so multiplying at :root would bake in density 1 and a
|
|
100
|
+
* per-player override -- which is exactly what `size` does -- could never take
|
|
101
|
+
* effect. Set any of these directly to change a size without touching density. */
|
|
102
|
+
--vocasync-gap: calc(var(--vocasync-unit) * 3);
|
|
103
|
+
--vocasync-gap-sm: var(--vocasync-unit);
|
|
104
|
+
--vocasync-padding: calc(var(--vocasync-unit) * 4);
|
|
105
|
+
--vocasync-control-size: 2.5rem;
|
|
106
|
+
--vocasync-control-size-sm: 2rem;
|
|
107
|
+
--vocasync-icon-size: 1.25rem;
|
|
108
|
+
|
|
109
|
+
/* ------------------------------------------------------------------ shape */
|
|
110
|
+
--vocasync-radius: 0.75rem;
|
|
111
|
+
--vocasync-radius-control: 0.375rem;
|
|
112
|
+
--vocasync-radius-menu: 0.5rem;
|
|
113
|
+
--vocasync-radius-pill: 9999px;
|
|
114
|
+
--vocasync-word-radius: 0.125rem;
|
|
115
|
+
--vocasync-border-width: 1px;
|
|
116
|
+
|
|
117
|
+
/* ---------------------------------------------------------------- sliders */
|
|
118
|
+
/* Runtime state, not settings: the player writes these onto the seek bar as
|
|
119
|
+
* percentages each frame. Declared here so the value is always defined. */
|
|
120
|
+
--vocasync-played: 0%;
|
|
121
|
+
--vocasync-buffered: 0%;
|
|
122
|
+
|
|
123
|
+
--vocasync-slider-height: 0.375rem;
|
|
124
|
+
--vocasync-slider-thumb-size: 1rem;
|
|
125
|
+
--vocasync-volume-width: 4rem;
|
|
126
|
+
|
|
127
|
+
/* ------------------------------------------------------------------- dock */
|
|
128
|
+
--vocasync-dock-height: 3.5rem;
|
|
129
|
+
--vocasync-dock-offset: 1rem;
|
|
130
|
+
--vocasync-dock-width: 20rem;
|
|
131
|
+
|
|
132
|
+
/* ------------------------------------------------------------------ focus */
|
|
133
|
+
--vocasync-focus-width: 2px;
|
|
134
|
+
--vocasync-focus-offset: 2px;
|
|
135
|
+
--vocasync-focus-color: var(--vocasync-accent);
|
|
136
|
+
|
|
137
|
+
/* -------------------------------------------------------------- elevation */
|
|
138
|
+
--vocasync-shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
|
|
139
|
+
--vocasync-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
|
|
140
|
+
--vocasync-shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
|
|
141
|
+
|
|
142
|
+
/* ----------------------------------------------------------------- motion */
|
|
143
|
+
--vocasync-transition-fast: 150ms ease;
|
|
144
|
+
--vocasync-transition: 200ms ease;
|
|
145
|
+
|
|
146
|
+
/* ------------------------------------------------------------------ layer */
|
|
147
|
+
--vocasync-menu-z: 10;
|
|
148
|
+
--vocasync-dock-z: 1000;
|
|
149
|
+
|
|
150
|
+
/* Lightness above which accent-content flips to black. Perceptual, not a WCAG
|
|
151
|
+
* measurement -- raise it if your accent needs dark text sooner. */
|
|
152
|
+
--vocasync-l-threshold: 0.623;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/* ------------------------------------------------------------------- dark
|
|
156
|
+
* Three ways in, because sites disagree on how they signal dark mode:
|
|
157
|
+
* - the OS preference, unless the page has explicitly opted into light
|
|
158
|
+
* - our own attribute, for explicit control
|
|
159
|
+
* - the conventions Tailwind, next-themes, daisyUI and Starlight already use,
|
|
160
|
+
* so most sites need no configuration at all
|
|
161
|
+
*
|
|
162
|
+
* These selectors are deliberately NOT wrapped in :where(). Zero specificity would
|
|
163
|
+
* lose to the `:root` block above, and the class-based switch -- the whole reason
|
|
164
|
+
* this exists -- would silently never apply.
|
|
165
|
+
*/
|
|
166
|
+
@media (prefers-color-scheme: dark) {
|
|
167
|
+
:root:not([data-vocasync-scheme="light"]):not(.light):not([data-theme="light"]):not(
|
|
168
|
+
[data-mode="light"]
|
|
169
|
+
) {
|
|
170
|
+
--vocasync-accent: #60a5fa;
|
|
171
|
+
--vocasync-surface: #1e293b;
|
|
172
|
+
--vocasync-text: #f1f5f9;
|
|
173
|
+
--vocasync-highlight: #34d399;
|
|
174
|
+
|
|
175
|
+
/* Static fallbacks for browsers without color-mix(); the @supports block below
|
|
176
|
+
* recomputes these from whichever seeds are in play. */
|
|
177
|
+
--vocasync-accent-hover: #3b82f6;
|
|
178
|
+
--vocasync-accent-content: #1e293b;
|
|
179
|
+
--vocasync-surface-raised: #334155;
|
|
180
|
+
--vocasync-text-muted: #94a3b8;
|
|
181
|
+
--vocasync-text-faint: #64748b;
|
|
182
|
+
--vocasync-border: #475569;
|
|
183
|
+
--vocasync-track: #475569;
|
|
184
|
+
--vocasync-buffered-color: #64748b;
|
|
185
|
+
--vocasync-highlight-active-bg: rgb(52 211 153 / 0.25);
|
|
186
|
+
--vocasync-highlight-trail-bg: rgb(52 211 153 / 0.12);
|
|
187
|
+
|
|
188
|
+
--vocasync-shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.2);
|
|
189
|
+
--vocasync-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.3), 0 1px 2px -1px rgb(0 0 0 / 0.3);
|
|
190
|
+
--vocasync-shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3), 0 4px 6px -4px rgb(0 0 0 / 0.3);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
[data-vocasync-scheme="dark"],
|
|
195
|
+
.dark,
|
|
196
|
+
[data-theme="dark"],
|
|
197
|
+
[data-mode="dark"] {
|
|
198
|
+
--vocasync-accent: #60a5fa;
|
|
199
|
+
--vocasync-surface: #1e293b;
|
|
200
|
+
--vocasync-text: #f1f5f9;
|
|
201
|
+
--vocasync-highlight: #34d399;
|
|
202
|
+
|
|
203
|
+
/* Static fallbacks for browsers without color-mix(); the @supports block below
|
|
204
|
+
* recomputes these from whichever seeds are in play. */
|
|
205
|
+
--vocasync-accent-hover: #3b82f6;
|
|
206
|
+
--vocasync-accent-content: #1e293b;
|
|
207
|
+
--vocasync-surface-raised: #334155;
|
|
208
|
+
--vocasync-text-muted: #94a3b8;
|
|
209
|
+
--vocasync-text-faint: #64748b;
|
|
210
|
+
--vocasync-border: #475569;
|
|
211
|
+
--vocasync-track: #475569;
|
|
212
|
+
--vocasync-buffered-color: #64748b;
|
|
213
|
+
--vocasync-highlight-active-bg: rgb(52 211 153 / 0.25);
|
|
214
|
+
--vocasync-highlight-trail-bg: rgb(52 211 153 / 0.12);
|
|
215
|
+
|
|
216
|
+
--vocasync-shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.2);
|
|
217
|
+
--vocasync-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.3), 0 1px 2px -1px rgb(0 0 0 / 0.3);
|
|
218
|
+
--vocasync-shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3), 0 4px 6px -4px rgb(0 0 0 / 0.3);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/* --------------------------------------------------- derived: computed, last
|
|
222
|
+
* These come after the scheme blocks on purpose. Each derives from whichever
|
|
223
|
+
* seeds ended up winning, so overriding one seed re-colours the whole player in
|
|
224
|
+
* light AND dark. Putting them earlier -- as the first draft did -- let the dark
|
|
225
|
+
* block's static literals win, and a custom seed only half-applied.
|
|
226
|
+
*/
|
|
227
|
+
@supports (color: color-mix(in oklab, red, blue)) {
|
|
228
|
+
:root {
|
|
229
|
+
--vocasync-accent-hover: color-mix(in oklab, var(--vocasync-accent), black 12%);
|
|
230
|
+
--vocasync-surface-raised: color-mix(in oklab, var(--vocasync-surface), white 60%);
|
|
231
|
+
--vocasync-text-muted: color-mix(in oklab, var(--vocasync-text), var(--vocasync-surface) 40%);
|
|
232
|
+
--vocasync-text-faint: color-mix(in oklab, var(--vocasync-text), var(--vocasync-surface) 60%);
|
|
233
|
+
--vocasync-border: color-mix(in oklab, var(--vocasync-text), var(--vocasync-surface) 85%);
|
|
234
|
+
--vocasync-track: color-mix(in oklab, var(--vocasync-text), var(--vocasync-surface) 85%);
|
|
235
|
+
--vocasync-buffered-color: color-mix(
|
|
236
|
+
in oklab,
|
|
237
|
+
var(--vocasync-text),
|
|
238
|
+
var(--vocasync-surface) 70%
|
|
239
|
+
);
|
|
240
|
+
--vocasync-highlight-active-bg: color-mix(
|
|
241
|
+
in oklab,
|
|
242
|
+
var(--vocasync-highlight) 25%,
|
|
243
|
+
transparent
|
|
244
|
+
);
|
|
245
|
+
--vocasync-highlight-trail-bg: color-mix(
|
|
246
|
+
in oklab,
|
|
247
|
+
var(--vocasync-highlight) 12%,
|
|
248
|
+
transparent
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/*
|
|
254
|
+
* Black or white against the accent, whichever reads. Relative colour syntax
|
|
255
|
+
* cannot lift `l` out into a custom property, so the decision is made inline:
|
|
256
|
+
* below the threshold the clamp resolves to 1 (white), above it to 0 (black).
|
|
257
|
+
*/
|
|
258
|
+
@supports (color: oklch(from red l c h)) {
|
|
259
|
+
:root {
|
|
260
|
+
--vocasync-accent-content: oklch(
|
|
261
|
+
from var(--vocasync-accent) clamp(0, (l / var(--vocasync-l-threshold) - 1) * -infinity, 1) 0
|
|
262
|
+
h
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Everything, in the right order. This is what the integration injects.
|
|
3
|
+
*
|
|
4
|
+
* Import the parts directly instead if you want less: content.css alone is enough
|
|
5
|
+
* for a headless player that ships its own chrome.
|
|
6
|
+
*/
|
|
7
|
+
@import "./layers.css";
|
|
8
|
+
@import "./tokens.css";
|
|
9
|
+
@import "./content.css";
|
|
10
|
+
@import "./player.css";
|
package/src/sync/index.ts
CHANGED
package/src/sync/orchestrator.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { type VocaSyncClient,
|
|
1
|
+
import { type VocaSyncClient, withPublishableKey } from "../api/client.js";
|
|
2
2
|
import { FormatSchema, LanguageSchema, type VocaSyncConfig, VoiceSchema } from "../config/index.js";
|
|
3
|
+
import { canAlign, LANGUAGE_NAMES, toAlignmentLocale } from "../config/languages.js";
|
|
3
4
|
import { getAudioEntry, loadAudioMap, saveAudioMap, setAudioEntry } from "../core/audio-map.js";
|
|
4
5
|
import { loadContent } from "../core/content-loader.js";
|
|
5
6
|
import { computeHash } from "../core/hash-manager.js";
|
|
6
7
|
import { buildSpeechDocument } from "../core/speech-builder.js";
|
|
7
8
|
import type {
|
|
9
|
+
AlignedWord,
|
|
8
10
|
AudioArtifact,
|
|
9
11
|
AudioMap,
|
|
10
12
|
ContentItem,
|
|
@@ -25,7 +27,7 @@ type Progress = NonNullable<SyncOptions["onProgress"]>;
|
|
|
25
27
|
function resolveParams(
|
|
26
28
|
item: ContentItem,
|
|
27
29
|
config: VocaSyncConfig
|
|
28
|
-
): { voice: string; language: string; format: string } | { error: string } {
|
|
30
|
+
): { voice: string; language: string; format: string; align: boolean } | { error: string } {
|
|
29
31
|
const fm = item.frontmatter;
|
|
30
32
|
|
|
31
33
|
let voice = config.synthesis.voice as string;
|
|
@@ -49,18 +51,50 @@ function resolveParams(
|
|
|
49
51
|
format = parsed.data;
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
|
|
54
|
+
let align = config.align;
|
|
55
|
+
if (fm.align !== undefined && fm.align !== null) {
|
|
56
|
+
if (typeof fm.align !== "boolean") {
|
|
57
|
+
return { error: `frontmatter align must be true or false, got "${String(fm.align)}"` };
|
|
58
|
+
}
|
|
59
|
+
align = fm.align;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// A post can ask for a language its own alignment cannot support. Caught here so the
|
|
63
|
+
// run stops before paying for synthesis, naming the post rather than failing later
|
|
64
|
+
// with an opaque rejection from the alignment endpoint.
|
|
65
|
+
if (align && !canAlign(language)) {
|
|
66
|
+
const name = LANGUAGE_NAMES[language] ?? language;
|
|
67
|
+
return {
|
|
68
|
+
error:
|
|
69
|
+
`${name} ("${language}") cannot be force-aligned. ` +
|
|
70
|
+
"Add `align: false` to this post's frontmatter to narrate it without highlighting.",
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return { voice, language, format, align };
|
|
53
75
|
}
|
|
54
76
|
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
77
|
+
/**
|
|
78
|
+
* True when an existing entry is complete for what was asked of it.
|
|
79
|
+
*
|
|
80
|
+
* `align` is part of the question, not just the answer. Judging completeness by the
|
|
81
|
+
* presence of alignment fields alone would mark every deliberately unaligned entry as
|
|
82
|
+
* incomplete and re-synthesise it on every run -- paying for the same audio forever.
|
|
83
|
+
* Entries written before v2.1.0 carry no `aligned` flag and were always aligned, so
|
|
84
|
+
* their alignment fields stand in for it.
|
|
85
|
+
*/
|
|
86
|
+
function isUpToDate(
|
|
87
|
+
entry: AudioArtifact | undefined,
|
|
88
|
+
contentHash: string,
|
|
89
|
+
align: boolean
|
|
90
|
+
): boolean {
|
|
91
|
+
if (!entry || entry.contentHash !== contentHash || !entry.synthesisProjectUuid) return false;
|
|
92
|
+
|
|
93
|
+
const wasAligned = entry.aligned ?? Boolean(entry.alignmentProjectUuid);
|
|
94
|
+
if (wasAligned !== align) return false;
|
|
95
|
+
|
|
96
|
+
// Only an aligned entry owes timings.
|
|
97
|
+
return align ? Boolean(entry.alignmentProjectUuid) && Array.isArray(entry.words) : true;
|
|
64
98
|
}
|
|
65
99
|
|
|
66
100
|
/** Orchestrate the full sync: load -> build -> two-POST synthesis+alignment -> persist. */
|
|
@@ -121,15 +155,16 @@ async function processItem(
|
|
|
121
155
|
onProgress(`⚠ ${item.slug} - skipped: ${resolved.error}`, "warn");
|
|
122
156
|
return { slug: item.slug, status: "error", error: resolved.error };
|
|
123
157
|
}
|
|
124
|
-
const { voice, language, format } = resolved;
|
|
158
|
+
const { voice, language, format, align } = resolved;
|
|
125
159
|
|
|
126
160
|
const speechDoc = await buildSpeechDocument(item, { math: config.math });
|
|
161
|
+
// `align` participates in the hash: flipping it changes what the artifact is.
|
|
127
162
|
const contentHash = computeHash(
|
|
128
|
-
JSON.stringify([speechDoc.normalisedSpeechtext, voice, language, format])
|
|
163
|
+
JSON.stringify([speechDoc.normalisedSpeechtext, voice, language, format, align])
|
|
129
164
|
);
|
|
130
165
|
|
|
131
166
|
const existingEntry = getAudioEntry(audioMap, item.slug);
|
|
132
|
-
if (!force && isUpToDate(existingEntry, contentHash)) {
|
|
167
|
+
if (!force && isUpToDate(existingEntry, contentHash, align)) {
|
|
133
168
|
onProgress(`⏭ ${item.slug} - unchanged`, "info");
|
|
134
169
|
return { slug: item.slug, status: "unchanged" };
|
|
135
170
|
}
|
|
@@ -138,7 +173,8 @@ async function processItem(
|
|
|
138
173
|
|
|
139
174
|
if (dryRun) {
|
|
140
175
|
onProgress(
|
|
141
|
-
`🔍 ${item.slug} - would ${status} (voice=${voice}, lang=${language}
|
|
176
|
+
`🔍 ${item.slug} - would ${status} (voice=${voice}, lang=${language}` +
|
|
177
|
+
`${align ? "" : ", no alignment"}) [dry run]`,
|
|
142
178
|
"info"
|
|
143
179
|
);
|
|
144
180
|
return { slug: item.slug, status };
|
|
@@ -155,52 +191,73 @@ async function processItem(
|
|
|
155
191
|
outputFormat: format,
|
|
156
192
|
});
|
|
157
193
|
const synthUuid = synthesis.projectUuid;
|
|
158
|
-
await client.pollUntilComplete(synthUuid, {
|
|
194
|
+
const synthesisStatus = await client.pollUntilComplete(synthUuid, {
|
|
159
195
|
onProgress: (s) => onProgress(` synthesis: ${s.status}`, "info"),
|
|
160
196
|
});
|
|
161
197
|
const synthesisPublishableKey = await client.createPublishableKey(synthUuid);
|
|
162
198
|
|
|
163
|
-
// 2. Alignment
|
|
164
|
-
onProgress(`🔗 ${item.slug} - aligning...`, "info");
|
|
199
|
+
// 2. Alignment, unless this post asked to go without ---------------------
|
|
165
200
|
const audioStreamUrl = client.streamUrl(synthUuid, "synthesis");
|
|
166
|
-
const { bytes: audioBytes, contentType } = await client.downloadBytes(
|
|
167
|
-
withPublishableKey(audioStreamUrl, synthesisPublishableKey)
|
|
168
|
-
);
|
|
169
|
-
const transcriptBytes = new TextEncoder().encode(speechDoc.normalisedSpeechtext);
|
|
170
|
-
const alignmentLocale = toAlignmentLocale(language);
|
|
171
|
-
|
|
172
|
-
const presign = await client.presignAlignment({
|
|
173
|
-
audioName: `synthesis.${format}`,
|
|
174
|
-
audioType: contentType,
|
|
175
|
-
audioSize: audioBytes.byteLength,
|
|
176
|
-
transcriptSize: transcriptBytes.byteLength,
|
|
177
|
-
language: alignmentLocale,
|
|
178
|
-
});
|
|
179
201
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
projectUuid: presign.projectUuid,
|
|
185
|
-
audioFileKey: presign.audio.key,
|
|
186
|
-
transcriptFileKey: presign.transcript.key,
|
|
187
|
-
audioFileSizeBytes: audioBytes.byteLength,
|
|
188
|
-
transcriptFileSizeBytes: transcriptBytes.byteLength,
|
|
189
|
-
language: alignmentLocale,
|
|
190
|
-
projectName: `astro-${item.slug}`,
|
|
191
|
-
});
|
|
192
|
-
const alignUuid = presign.projectUuid;
|
|
193
|
-
await client.pollUntilComplete(alignUuid, {
|
|
194
|
-
onProgress: (s) => onProgress(` alignment: ${s.status}`, "info"),
|
|
195
|
-
});
|
|
196
|
-
const alignmentPublishableKey = await client.createPublishableKey(alignUuid);
|
|
202
|
+
let alignUuid: string | undefined;
|
|
203
|
+
let alignmentPublishableKey: string | undefined;
|
|
204
|
+
let words: AlignedWord[] | undefined;
|
|
205
|
+
let effectiveDuration = 0;
|
|
197
206
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
207
|
+
if (align) {
|
|
208
|
+
onProgress(`🔗 ${item.slug} - aligning...`, "info");
|
|
209
|
+
const { bytes: audioBytes, contentType } = await client.downloadBytes(
|
|
210
|
+
withPublishableKey(audioStreamUrl, synthesisPublishableKey)
|
|
211
|
+
);
|
|
212
|
+
const transcriptBytes = new TextEncoder().encode(speechDoc.normalisedSpeechtext);
|
|
213
|
+
const alignmentLocale = toAlignmentLocale(language);
|
|
214
|
+
if (!alignmentLocale) {
|
|
215
|
+
// resolveParams rejects this earlier; reaching here means the two disagree.
|
|
216
|
+
return {
|
|
217
|
+
slug: item.slug,
|
|
218
|
+
status: "error",
|
|
219
|
+
error: `no alignment locale for language "${language}"`,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const presign = await client.presignAlignment({
|
|
224
|
+
audioName: `synthesis.${format}`,
|
|
225
|
+
audioType: contentType,
|
|
226
|
+
audioSize: audioBytes.byteLength,
|
|
227
|
+
transcriptSize: transcriptBytes.byteLength,
|
|
228
|
+
language: alignmentLocale,
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
await client.uploadToPresigned(presign.audio.uploadUrl, audioBytes, contentType);
|
|
232
|
+
await client.uploadToPresigned(presign.transcript.uploadUrl, transcriptBytes, "text/plain");
|
|
233
|
+
|
|
234
|
+
await client.submitAlignment({
|
|
235
|
+
projectUuid: presign.projectUuid,
|
|
236
|
+
audioFileKey: presign.audio.key,
|
|
237
|
+
transcriptFileKey: presign.transcript.key,
|
|
238
|
+
audioFileSizeBytes: audioBytes.byteLength,
|
|
239
|
+
transcriptFileSizeBytes: transcriptBytes.byteLength,
|
|
240
|
+
language: alignmentLocale,
|
|
241
|
+
projectName: `astro-${item.slug}`,
|
|
242
|
+
});
|
|
243
|
+
alignUuid = presign.projectUuid;
|
|
244
|
+
await client.pollUntilComplete(alignUuid, {
|
|
245
|
+
onProgress: (st) => onProgress(` alignment: ${st.status}`, "info"),
|
|
246
|
+
});
|
|
247
|
+
alignmentPublishableKey = await client.createPublishableKey(alignUuid);
|
|
248
|
+
|
|
249
|
+
// 3. Fetch timings ------------------------------------------------------
|
|
250
|
+
const aligned = await client.fetchAlignmentWords(
|
|
251
|
+
withPublishableKey(client.streamUrl(alignUuid, "alignment"), alignmentPublishableKey)
|
|
252
|
+
);
|
|
253
|
+
words = aligned.words;
|
|
254
|
+
// The alignment stream may omit total duration; fall back to the last word's end.
|
|
255
|
+
effectiveDuration = aligned.duration || (words.length ? words[words.length - 1].end : 0);
|
|
256
|
+
} else {
|
|
257
|
+
onProgress(`🔇 ${item.slug} - narration only (no word timings)`, "info");
|
|
258
|
+
// Without alignment the only duration available is what synthesis reported.
|
|
259
|
+
effectiveDuration = synthesisStatus.durationSeconds ?? 0;
|
|
260
|
+
}
|
|
204
261
|
|
|
205
262
|
const now = new Date().toISOString();
|
|
206
263
|
const artifact: AudioArtifact = {
|
|
@@ -211,6 +268,9 @@ async function processItem(
|
|
|
211
268
|
synthesisProjectUuid: synthUuid,
|
|
212
269
|
synthesisPublishableKey,
|
|
213
270
|
audioUrl: audioStreamUrl,
|
|
271
|
+
// Recorded so a later sync can tell "deliberately unaligned" from "alignment
|
|
272
|
+
// never finished", instead of re-synthesising this post on every run.
|
|
273
|
+
aligned: align,
|
|
214
274
|
alignmentProjectUuid: alignUuid,
|
|
215
275
|
alignmentPublishableKey,
|
|
216
276
|
words,
|
|
@@ -221,7 +281,11 @@ async function processItem(
|
|
|
221
281
|
};
|
|
222
282
|
setAudioEntry(audioMap, item.slug, artifact);
|
|
223
283
|
|
|
224
|
-
onProgress(
|
|
284
|
+
onProgress(
|
|
285
|
+
`✅ ${item.slug} - ${status} complete` +
|
|
286
|
+
(words ? ` (${words.length} words)` : " (narration only)"),
|
|
287
|
+
"success"
|
|
288
|
+
);
|
|
225
289
|
return { slug: item.slug, status, projectUuid: synthUuid };
|
|
226
290
|
} catch (error) {
|
|
227
291
|
const message = error instanceof Error ? error.message : String(error);
|
package/src/types/index.ts
CHANGED
|
@@ -69,11 +69,25 @@ export interface AudioArtifact {
|
|
|
69
69
|
synthesisPublishableKey: string;
|
|
70
70
|
/** Stable audio stream URL (without the publishable key) */
|
|
71
71
|
audioUrl: string;
|
|
72
|
-
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Whether this artifact was force-aligned.
|
|
74
|
+
*
|
|
75
|
+
* Recorded explicitly because absence cannot express intent: without it, an entry
|
|
76
|
+
* synthesised deliberately without alignment is indistinguishable from one whose
|
|
77
|
+
* alignment failed halfway, and `isUpToDate` would re-synthesise it on every sync --
|
|
78
|
+
* paying for the audio again, silently, forever.
|
|
79
|
+
*
|
|
80
|
+
* Absent on artifacts written before v2.1.0, which were always aligned.
|
|
81
|
+
*/
|
|
82
|
+
aligned?: boolean;
|
|
83
|
+
/** Alignment project (source of the embedded timings). Absent when not aligned. */
|
|
84
|
+
alignmentProjectUuid?: string;
|
|
85
|
+
alignmentPublishableKey?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Word timings, indexed positionally by the rehype plugin's data-i.
|
|
88
|
+
* Absent when the artifact was synthesised without alignment.
|
|
89
|
+
*/
|
|
90
|
+
words?: AlignedWord[];
|
|
77
91
|
/** Total audio duration in seconds */
|
|
78
92
|
duration: number;
|
|
79
93
|
/** Spoken form of each math expression, keyed by `${'d'|'i'}:${latex}`. */
|