@vocasync/astro 1.0.0 → 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.
Files changed (139) hide show
  1. package/README.md +618 -80
  2. package/dist/api/client.d.ts.map +1 -1
  3. package/dist/api/client.js.map +1 -1
  4. package/dist/api/index.d.ts +1 -1
  5. package/dist/api/index.d.ts.map +1 -1
  6. package/dist/api/index.js +1 -1
  7. package/dist/api/index.js.map +1 -1
  8. package/dist/cli.js.map +1 -1
  9. package/dist/components/AudioPlayer.astro +298 -1136
  10. package/dist/components/index.d.ts +10 -32
  11. package/dist/components/index.d.ts.map +1 -1
  12. package/dist/components/index.js +1 -3
  13. package/dist/components/index.js.map +1 -1
  14. package/dist/components/types.d.ts +117 -0
  15. package/dist/components/types.d.ts.map +1 -0
  16. package/dist/components/types.js +2 -0
  17. package/dist/components/types.js.map +1 -0
  18. package/dist/config/index.d.ts +2 -2
  19. package/dist/config/index.d.ts.map +1 -1
  20. package/dist/config/index.js +1 -1
  21. package/dist/config/index.js.map +1 -1
  22. package/dist/config/schema.d.ts +124 -169
  23. package/dist/config/schema.d.ts.map +1 -1
  24. package/dist/config/schema.js +4 -4
  25. package/dist/config/schema.js.map +1 -1
  26. package/dist/core/content-loader.js +1 -1
  27. package/dist/core/content-loader.js.map +1 -1
  28. package/dist/core/index.d.ts +2 -2
  29. package/dist/core/index.d.ts.map +1 -1
  30. package/dist/core/index.js +2 -2
  31. package/dist/core/index.js.map +1 -1
  32. package/dist/core/speech-builder.js.map +1 -1
  33. package/dist/index.d.ts +6 -7
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +5 -6
  36. package/dist/index.js.map +1 -1
  37. package/dist/integration.d.ts +28 -2
  38. package/dist/integration.d.ts.map +1 -1
  39. package/dist/integration.js +40 -3
  40. package/dist/integration.js.map +1 -1
  41. package/dist/lib/latex-to-speech/index.d.ts.map +1 -1
  42. package/dist/lib/latex-to-speech/index.js.map +1 -1
  43. package/dist/player-core/boot.d.ts +9 -0
  44. package/dist/player-core/boot.d.ts.map +1 -0
  45. package/dist/player-core/boot.js +59 -0
  46. package/dist/player-core/boot.js.map +1 -0
  47. package/dist/player-core/highlighter.d.ts +31 -0
  48. package/dist/player-core/highlighter.d.ts.map +1 -0
  49. package/dist/player-core/highlighter.js +103 -0
  50. package/dist/player-core/highlighter.js.map +1 -0
  51. package/dist/player-core/index.d.ts +17 -0
  52. package/dist/player-core/index.d.ts.map +1 -0
  53. package/dist/player-core/index.js +24 -0
  54. package/dist/player-core/index.js.map +1 -0
  55. package/dist/player-core/media-url.d.ts +18 -0
  56. package/dist/player-core/media-url.d.ts.map +1 -0
  57. package/dist/player-core/media-url.js +33 -0
  58. package/dist/player-core/media-url.js.map +1 -0
  59. package/dist/player-core/player.d.ts +9 -0
  60. package/dist/player-core/player.d.ts.map +1 -0
  61. package/dist/player-core/player.js +622 -0
  62. package/dist/player-core/player.js.map +1 -0
  63. package/dist/player-core/registry.d.ts +20 -0
  64. package/dist/player-core/registry.d.ts.map +1 -0
  65. package/dist/player-core/registry.js +31 -0
  66. package/dist/player-core/registry.js.map +1 -0
  67. package/dist/player-core/seek-delegate.d.ts +24 -0
  68. package/dist/player-core/seek-delegate.d.ts.map +1 -0
  69. package/dist/player-core/seek-delegate.js +64 -0
  70. package/dist/player-core/seek-delegate.js.map +1 -0
  71. package/dist/player-core/storage.d.ts +38 -0
  72. package/dist/player-core/storage.d.ts.map +1 -0
  73. package/dist/player-core/storage.js +107 -0
  74. package/dist/player-core/storage.js.map +1 -0
  75. package/dist/player-core/strings.d.ts +53 -0
  76. package/dist/player-core/strings.d.ts.map +1 -0
  77. package/dist/player-core/strings.js +45 -0
  78. package/dist/player-core/strings.js.map +1 -0
  79. package/dist/player-core/timings.d.ts +56 -0
  80. package/dist/player-core/timings.d.ts.map +1 -0
  81. package/dist/player-core/timings.js +90 -0
  82. package/dist/player-core/timings.js.map +1 -0
  83. package/dist/rehype/audio-words.d.ts +9 -3
  84. package/dist/rehype/audio-words.d.ts.map +1 -1
  85. package/dist/rehype/audio-words.js +8 -8
  86. package/dist/rehype/audio-words.js.map +1 -1
  87. package/dist/rehype/index.d.ts +2 -2
  88. package/dist/rehype/index.d.ts.map +1 -1
  89. package/dist/rehype/index.js.map +1 -1
  90. package/dist/rehype/rehype-math-speech.d.ts.map +1 -1
  91. package/dist/rehype/rehype-math-speech.js +2 -0
  92. package/dist/rehype/rehype-math-speech.js.map +1 -1
  93. package/dist/styles/content.css +41 -0
  94. package/dist/styles/layers.css +13 -0
  95. package/dist/styles/player.css +517 -0
  96. package/dist/styles/preset-shadcn.css +31 -0
  97. package/dist/styles/tokens.css +266 -0
  98. package/dist/styles/vocasync.css +10 -0
  99. package/dist/sync/index.d.ts +1 -1
  100. package/dist/sync/index.d.ts.map +1 -1
  101. package/dist/sync/index.js +1 -1
  102. package/dist/sync/index.js.map +1 -1
  103. package/dist/sync/orchestrator.d.ts.map +1 -1
  104. package/dist/sync/orchestrator.js.map +1 -1
  105. package/package.json +40 -17
  106. package/src/api/index.ts +4 -4
  107. package/src/components/AudioPlayer.astro +298 -1136
  108. package/src/components/index.ts +19 -34
  109. package/src/components/types.ts +140 -0
  110. package/src/config/index.ts +23 -24
  111. package/src/config/schema.ts +4 -4
  112. package/src/core/content-loader.ts +1 -1
  113. package/src/core/index.ts +7 -7
  114. package/src/env.d.ts +2 -0
  115. package/src/index.ts +23 -28
  116. package/src/integration.ts +66 -4
  117. package/src/player-core/boot.ts +62 -0
  118. package/src/player-core/highlighter.ts +159 -0
  119. package/src/player-core/index.ts +45 -0
  120. package/src/player-core/media-url.ts +35 -0
  121. package/src/player-core/player.ts +725 -0
  122. package/src/player-core/registry.ts +40 -0
  123. package/src/player-core/seek-delegate.ts +92 -0
  124. package/src/player-core/storage.ts +112 -0
  125. package/src/player-core/strings.ts +89 -0
  126. package/src/player-core/timings.ts +115 -0
  127. package/src/rehype/audio-words.ts +17 -11
  128. package/src/rehype/index.ts +2 -3
  129. package/src/rehype/rehype-math-speech.ts +3 -1
  130. package/src/styles/content.css +41 -0
  131. package/src/styles/layers.css +13 -0
  132. package/src/styles/player.css +517 -0
  133. package/src/styles/preset-shadcn.css +31 -0
  134. package/src/styles/tokens.css +266 -0
  135. package/src/styles/vocasync.css +10 -0
  136. package/src/sync/index.ts +1 -1
  137. package/src/sync/orchestrator.ts +1 -1
  138. package/dist/styles/variables.css +0 -164
  139. package/src/styles/variables.css +0 -164
package/README.md CHANGED
@@ -7,9 +7,12 @@ Turn your Astro blog posts into narrated audio with word-level synchronization.
7
7
  - 🎙️ **Text-to-Speech Synthesis** - Generate natural-sounding audio narration for your content
8
8
  - 🎯 **Word-Level Alignment** - Precise timestamps for every word, powered by forced alignment
9
9
  - ✨ **Live Word Highlighting** - Karaoke-style highlighting that follows along with playback
10
- - 🎛️ **Built-in Audio Player** - Accessible player with keyboard shortcuts and mini-player mode
10
+ - 🎛️ **Built-in Audio Player** - Keyboard shortcuts, a floating dock, and controls you can reorder or replace
11
11
  - 🌍 **14 Languages** - Global reach with support for 14 languages
12
- - 🎨 **Fully Themeable** - CSS variables for seamless integration with any design
12
+ - 🎨 **Themeable down to the pixel** - Four seeds carry a whole theme; every rule loses to yours, so no `!important`
13
+ - 🌗 **Dark mode that follows yours** - The OS preference plus `.dark`, `[data-theme]` and `[data-mode]`, with no configuration
14
+ - 🈯 **Translatable** - Every visible string and accessible label is overridable
15
+ - 🧩 **Headless option** - Import the engine and bring your own markup
13
16
 
14
17
  ## Demo
15
18
 
@@ -23,13 +26,17 @@ Turn your Astro blog posts into narrated audio with word-level synchronization.
23
26
  - [Quick Start](#quick-start)
24
27
  - [Project Structure](#project-structure)
25
28
  - [Configuration](#configuration)
29
+ - [Integration options](#integration-options)
26
30
  - [CLI Commands](#cli-commands)
27
31
  - [Components](#components)
32
+ - [Headless usage](#headless-usage)
28
33
  - [Supported Languages](#supported-languages)
29
34
  - [Math Support](#math-support)
30
35
  - [Deployment](#deployment)
31
36
  - [Important: Audio Map](#important-audio-map)
32
- - [Customizing Styles](#customizing-styles)
37
+ - [Theming](#theming)
38
+ - [Migrating from v1](#migrating-from-v1)
39
+ - [Troubleshooting](#troubleshooting)
33
40
 
34
41
  ## Installation
35
42
 
@@ -41,6 +48,18 @@ bun add @vocasync/astro
41
48
  pnpm add @vocasync/astro
42
49
  ```
43
50
 
51
+ ### Astro 7
52
+
53
+ Astro 7 no longer installs `@astrojs/markdown-remark` by default, and the rehype
54
+ plugins that produce word highlighting cannot run without it:
55
+
56
+ ```bash
57
+ bun add @astrojs/markdown-remark
58
+ ```
59
+
60
+ Astro 4, 5 and 6 need nothing extra. The plugin is tested against all four on every
61
+ change.
62
+
44
63
  ## Quick Start
45
64
 
46
65
  ### 1. Create VocaSync Config
@@ -123,16 +142,31 @@ const audioEntry = audioMap.entries[post.slug];
123
142
  ---
124
143
 
125
144
  <article>
126
- <!-- Audio player at the top -->
127
- <AudioPlayer slug={post.slug} audioEntry={audioEntry} label="Listen to this post" />
128
-
129
- <!-- Article content - must have data-article-body for word highlighting -->
145
+ <AudioPlayer slug={post.slug} audioEntry={audioEntry} />
146
+
147
+ <!-- Word highlighting needs a root to find the spans in -->
130
148
  <div data-article-body>
131
149
  <slot />
132
150
  </div>
133
151
  </article>
134
152
  ```
135
153
 
154
+ ### 7. Make it look like your site
155
+
156
+ The player is styled by four CSS custom properties. Point them at tokens you already
157
+ have and it adopts your palette and your dark mode:
158
+
159
+ ```css
160
+ :root {
161
+ --vocasync-accent: var(--color-primary);
162
+ --vocasync-surface: var(--color-card);
163
+ --vocasync-text: var(--color-text);
164
+ }
165
+ ```
166
+
167
+ There is a lot more available — variants, control ordering, slots, translation — see
168
+ [Theming](#theming) and [Components](#components). Nothing needs `!important`.
169
+
136
170
  ## Project Structure
137
171
 
138
172
  After setup, your project should look like this:
@@ -156,6 +190,33 @@ my-astro-site/
156
190
 
157
191
  ## Configuration
158
192
 
193
+ ### Integration options
194
+
195
+ `vocasync()` takes an options object in `astro.config.mjs`. Everything about *content*
196
+ lives in `vocasync.config.mjs` below; these are about the integration itself.
197
+
198
+ ```javascript
199
+ integrations: [
200
+ vocasync({
201
+ // Inject the player stylesheet on every page. Set false to import it yourself:
202
+ // `@vocasync/astro/styles/vocasync.css`, or just `content.css` when you drive the
203
+ // engine headlessly and ship your own chrome.
204
+ styles: true,
205
+
206
+ theme: {
207
+ // A selector your site already uses for dark mode. Usually unnecessary --
208
+ // `.dark`, `[data-theme="dark"]` and `[data-mode="dark"]` are recognised out of
209
+ // the box, covering Tailwind, next-themes, daisyUI and Starlight.
210
+ darkSelector: '[data-appearance="night"]',
211
+ },
212
+ }),
213
+ ]
214
+ ```
215
+
216
+ The integration does **not** register the rehype plugins. Add `rehypeAudioWords` (and
217
+ `rehypeMathSpeech` if you use maths) to `markdown.rehypePlugins` yourself — their order
218
+ relative to your maths renderer matters, so it is left explicit.
219
+
159
220
  ### vocasync.config.mjs
160
221
 
161
222
  Full configuration options:
@@ -229,7 +290,7 @@ Invalid values are skipped with a warning. Changing any of these re-syncs the po
229
290
  [rehypeAudioWords, {
230
291
  collectionName: "blog", // Content collection name
231
292
  audioMapPath: "src/data/audio-map.json", // Path to audio map
232
- classPrefix: "vocasync", // CSS class prefix (default: "vocasync")
293
+ extraWordClass: "prose-word", // optional extra class on each word span
233
294
  }]
234
295
  ```
235
296
 
@@ -274,74 +335,250 @@ npx vocasync help
274
335
 
275
336
  ### AudioPlayer
276
337
 
277
- The main audio player component with word highlighting support.
278
-
279
338
  ```astro
280
339
  ---
281
340
  import AudioPlayer from "@vocasync/astro/components/AudioPlayer.astro";
341
+ import audioMap from "../data/audio-map.json";
282
342
  ---
283
343
 
284
- <AudioPlayer
285
- slug={post.slug}
286
- label="Listen to this post"
287
- articleSelector="[data-article-body]"
288
- enableHighlighting={true}
289
- enableClickToSeek={true}
290
- enableMiniPlayer={true}
291
- trailLength={4}
292
- />
344
+ <AudioPlayer slug={slug} audioEntry={audioMap.entries[slug]} />
345
+
346
+ <div data-article-body>
347
+ <Content />
348
+ </div>
293
349
  ```
294
350
 
351
+ The player renders markup only. Playback, highlighting and the view-transition
352
+ lifecycle live in a module script that is bundled once per page, no matter how many
353
+ players are on it.
354
+
295
355
  #### Props
296
356
 
297
357
  | Prop | Type | Default | Description |
298
358
  |------|------|---------|-------------|
299
- | `slug` | `string` | required | Post slug to lookup audio |
300
- | `audioEntry` | `object` | `undefined` | Audio entry from audio-map.json (`audioUrl`, `synthesisPublishableKey`, `words`, `duration`) |
301
- | `label` | `string` | `"Listen to this article"` | Accessible label |
302
- | `showPlaceholder` | `boolean` | `true` | Show message when no audio |
303
- | `class` | `string` | `""` | Additional CSS classes |
304
- | `articleSelector` | `string` | `"[data-article-body]"` | Selector for word highlighting container |
305
- | `enableMiniPlayer` | `boolean` | `true` | Show floating mini player on scroll |
306
- | `enableHighlighting` | `boolean` | `true` | Enable word highlighting |
307
- | `enableClickToSeek` | `boolean` | `true` | Enable click on words to seek audio |
308
- | `trailLength` | `number` | `4` | Number of trailing highlighted words |
359
+ | `slug` | `string` | required | Post slug, used to look up audio |
360
+ | `audioEntry` | `AudioEntry` | — | Entry from `audio-map.json` |
361
+ | `variant` | `"bar" \| "minimal" \| "card"` | `"bar"` | Shape of the player |
362
+ | `size` | `"sm" \| "md" \| "lg"` | `"md"` | Scales the whole player |
363
+ | `controls` | `ControlName[]` | see below | Which controls render, and in what order |
364
+ | `speeds` | `number[]` | `[0.5, 0.75, 1, 1.25, 1.5, 2]` | Playback rates in the speed menu |
365
+ | `skipSeconds` | `number` | `15` | How far the skip controls and arrow keys jump |
366
+ | `strings` | `Partial<PlayerStrings>` | English | Every visible string and accessible label |
367
+ | `articleSelector` | `string` | `"[data-article-body]"` | Element containing the word spans |
368
+ | `highlight` | `HighlightOptions` | `{}` | `{ enabled, trailLength, clickToSeek }` |
369
+ | `dock` | `DockOptions` | `{}` | `{ enabled }` — the floating player |
370
+ | `autoScroll` | `"off" \| "paragraph"` | `"off"` | Scroll the spoken paragraph into view |
371
+ | `exclusive` | `boolean` | `true` | Starting this player pauses the others |
372
+ | `rememberPreferences` | `boolean` | `true` | Persist speed, volume, mute and highlighting |
373
+ | `rememberPosition` | `boolean` | `false` | Resume where the reader left off, keyed by `slug` |
374
+ | `mediaSession` | `boolean` | `true` | Publish to the OS media controls |
375
+ | `title` | `string` | — | Title for the OS media controls |
376
+ | `artwork` | `string` | — | Artwork URL for the OS media controls |
377
+ | `showPlaceholder` | `boolean` | `true` | Show a message when there is no audio |
378
+ | `class` | `string` | `""` | Extra classes on the root |
379
+ | `id` | `string` | derived | Overrides the generated element id |
380
+
381
+ #### Controls, and their order
382
+
383
+ `controls` sets both which controls appear and where they sit:
309
384
 
310
- #### Keyboard Shortcuts
385
+ ```astro
386
+ <AudioPlayer slug={slug} controls={["play", "volume", "progress", "highlight"]} />
387
+ ```
311
388
 
312
- When the player is focused (click on it or Tab to it), the following keyboard shortcuts are available:
389
+ | Name | Renders |
390
+ |------|---------|
391
+ | `play` | Play/pause button |
392
+ | `progress` | Elapsed/total time above the seek bar; grows to fill the row |
393
+ | `time` | Elapsed/total time on its own |
394
+ | `highlight` | Word-highlighting toggle |
395
+ | `speed` | Playback-speed menu |
396
+ | `volume` | Mute button and volume slider |
397
+ | `skip-back` | Jump backwards by `skipSeconds` |
398
+ | `skip-forward` | Jump forwards by `skipSeconds` |
313
399
 
314
- | Key | Action |
315
- |-----|--------|
316
- | `Space` | Play/Pause |
317
- | `←` Left Arrow | Seek backward 5 seconds |
318
- | `→` Right Arrow | Seek forward 5 seconds |
319
- | `M` | Toggle mute |
320
- | `H` | Toggle word highlighting |
400
+ Default: `["play", "progress", "highlight", "speed", "volume"]`. Anything you leave out
401
+ is not rendered — pass `[]` with `dock={{ enabled: true }}` for a dock-only player.
402
+
403
+ #### Variants
404
+
405
+ `bar` is a horizontal strip on a card. `minimal` drops the background, border, shadow
406
+ and padding so the player borrows the page — useful inline with prose or under a title.
407
+ `card` opens room above the controls for a title or artwork through the `before` slot.
408
+
409
+ #### Slots
410
+
411
+ Every slot falls back to the shipped markup, so override only what you need.
321
412
 
322
- #### Highlighting Toggle
413
+ | Slot | Replaces |
414
+ |------|----------|
415
+ | `icon-play`, `icon-pause` | Play/pause icons |
416
+ | `icon-volume`, `icon-muted` | Volume icons |
417
+ | `icon-highlight-on`, `icon-highlight-off` | Highlight-toggle icons |
418
+ | `icon-skip-back`, `icon-skip-forward` | Skip icons |
419
+ | `placeholder` | The "no audio" message |
420
+ | `error` | The failed-to-load message and its retry button |
421
+ | `before`, `after` | Arbitrary content above/below the controls |
323
422
 
324
- The player includes a highlighter icon button that allows users to toggle word highlighting on/off during playback. This is useful for users who find the highlighting distracting or prefer to just listen.
423
+ ```astro
424
+ <AudioPlayer slug={slug} audioEntry={entry} variant="card">
425
+ <div slot="before"><strong>{title}</strong></div>
426
+ <svg slot="icon-play" class="vocasync-icon vocasync-icon--play" viewBox="0 0 24 24">
427
+ <path d="M8 5v14l11-7z" fill="currentColor" />
428
+ </svg>
429
+ </AudioPlayer>
430
+ ```
431
+
432
+ #### Text and translation
433
+
434
+ Every visible string and every `aria-label` comes from `strings`:
325
435
 
326
- #### Click-to-Seek
436
+ ```astro
437
+ <AudioPlayer
438
+ slug={slug}
439
+ audioEntry={entry}
440
+ strings={{
441
+ label: "Écouter cet article",
442
+ play: "Lire",
443
+ pause: "Pause",
444
+ unavailable: "Audio non disponible pour cet article",
445
+ }}
446
+ />
447
+ ```
327
448
 
328
- When `enableClickToSeek` is enabled (default), clicking on any word in the article will:
329
- 1. Seek the audio to that word's timestamp
330
- 2. Start playback if paused
449
+ Every key is a plain string, and anything you omit keeps its English default.
450
+
451
+ | Key | Default | Notes |
452
+ |-----|---------|-------|
453
+ | `label` | `Listen to this article` | Names the player region; also the media-session title fallback |
454
+ | `loading` | `Loading audio…` | |
455
+ | `unavailable` | `Audio not available for this article` | No audio for this post |
456
+ | `error` | `Audio could not be loaded` | Audio exists but failed |
457
+ | `retry` | `Try again` | |
458
+ | `play` / `pause` | `Play` / `Pause` | |
459
+ | `seek` | `Seek` | |
460
+ | `seekPosition` | `{current} of {total}` | Announced by the seek slider; placeholders are spoken durations |
461
+ | `mute` / `unmute` | `Mute` / `Unmute` | |
462
+ | `volume` | `Volume` | |
463
+ | `speed` | `Playback speed` | |
464
+ | `speedValue` | `{rate}x` | Each entry in the speed menu |
465
+ | `highlightOn` / `highlightOff` | `Disable…` / `Enable word highlighting` | |
466
+ | `skipBack` / `skipForward` | `Back {seconds} seconds` / `Forward {seconds} seconds` | |
467
+
468
+ Placeholders in `{braces}` are substituted at render time. An unrecognised one is left
469
+ visible rather than blanked, so a typo in a translation shows up instead of quietly
470
+ disappearing — which matters when the string is an accessible label nobody sees.
471
+
472
+ ### Remembering what the reader chose
473
+
474
+ Speed, volume, mute and the highlighting toggle persist across pages and visits by
475
+ default — set `rememberPreferences={false}` to opt out. `rememberPosition` is separate
476
+ and off by default: resuming is welcome on a long article and confusing on a short post
477
+ someone expects to start from the beginning. When on, a position is only restored if
478
+ the reader was more than five seconds in and more than ten seconds from the end, and it
479
+ is cleared once the audio finishes.
480
+
481
+ All of it degrades quietly. `localStorage` throws outright in browsers configured to
482
+ block site data, and stored values are validated before use — a hand-edited playback
483
+ rate is not assigned to the media element.
484
+
485
+ ### Loading and failure states
486
+
487
+ The player root carries `data-player-state` (`loading`, `ready`, `no-audio`, `error`)
488
+ and `data-player-buffering` while the media element is waiting on the network. They are
489
+ distinct on purpose: a slow connection should not look like a broken one. Both are
490
+ styleable:
331
491
 
332
- This is useful for jumping to specific parts of an article. Disable it with `enableClickToSeek={false}` if you prefer words to not be interactive.
492
+ ```css
493
+ :root:has(.vocasync-player[data-player-buffering]) { /* … */ }
494
+ ```
495
+
496
+ The seek bar also paints its buffered range, driven by `--vocasync-played` and
497
+ `--vocasync-buffered`.
498
+
499
+ #### Events
500
+
501
+ The root element dispatches bubbling `CustomEvent`s, so you can hook analytics or
502
+ build your own UI alongside the player without forking it:
503
+
504
+ `vocasync:ready`, `vocasync:play`, `vocasync:pause`, `vocasync:ended`,
505
+ `vocasync:error`, `vocasync:ratechange`, `vocasync:wordchange`.
506
+
507
+ ```js
508
+ document.querySelector(".vocasync-player")
509
+ .addEventListener("vocasync:wordchange", (e) => {
510
+ // e.detail is { index, el } or null during silence between words
511
+ });
512
+ ```
513
+
514
+ #### Keyboard shortcuts
515
+
516
+ Available when focus is inside the player.
517
+
518
+ | Key | Action |
519
+ |-----|--------|
520
+ | `Space` | Play/pause |
521
+ | `←` / `→` | Skip by `skipSeconds` (default 15) |
522
+ | `M` | Toggle mute |
523
+ | `H` | Toggle word highlighting |
524
+ | `Esc` | Close the speed menu |
525
+
526
+ Inside the speed menu, `↑`/`↓`, `Home` and `End` move between rates and `Esc` returns
527
+ focus to the trigger.
333
528
 
334
529
  ### Word Highlighting
335
530
 
336
- For word highlighting to work, wrap your article content with `data-article-body`:
531
+ Wrap your article content so the player can find the word spans:
337
532
 
338
533
  ```astro
339
534
  <div data-article-body>
340
- <Content /> <!-- Your markdown content -->
535
+ <Content />
341
536
  </div>
342
537
  ```
343
538
 
344
- The rehype plugin wraps each word in a `<span>` with timing data at build time.
539
+ The rehype plugin wraps each word in a `<span class="vocasync-word" data-i data-n>` at
540
+ build time. `data-i` is the word's start index in the alignment stream and `data-n` is
541
+ how many alignment tokens it consumes — a visible word can span several, since "$50" is
542
+ spoken as two.
543
+
544
+ Clicking a word seeks to it. That is independent of the highlighting toggle, so a
545
+ reader who turns highlighting off keeps click-to-seek.
546
+
547
+ ## Headless usage
548
+
549
+ If you want entirely your own markup, import the engine and skip the component. This
550
+ API is covered by semver from 2.0.0.
551
+
552
+ ```ts
553
+ import { createPlayer } from "@vocasync/astro/player-core";
554
+
555
+ const player = createPlayer(document.querySelector(".my-player"));
556
+ // player.pause(); player.destroy();
557
+ ```
558
+
559
+ `createPlayer` reads its configuration from a
560
+ `<script type="application/json" class="vocasync-data">` inside the element, and finds
561
+ controls by `data-action` and `data-state` attributes — see the shipped component for
562
+ the shape it expects.
563
+
564
+ Lower-level pieces are exported too, for building something quite different:
565
+
566
+ ```ts
567
+ import {
568
+ computeSpanTimings, // visible units -> time spans
569
+ spanAtTime, // the span active at t, or null during silence
570
+ idxForTime,
571
+ createHighlighter,
572
+ resolveAudioSrc,
573
+ } from "@vocasync/astro/player-core";
574
+ ```
575
+
576
+ Headless consumers still need `content.css` for the word-highlighting styles, but can
577
+ skip `player.css`:
578
+
579
+ ```css
580
+ @import "@vocasync/astro/styles/content.css";
581
+ ```
345
582
 
346
583
  ## Supported Languages
347
584
 
@@ -564,56 +801,357 @@ Add your `.env` file to `.gitignore`:
564
801
  .env.local
565
802
  ```
566
803
 
567
- ## Customizing Styles
804
+ ## Theming
805
+
806
+ The player is designed to disappear into your site. Every visual decision is a CSS
807
+ custom property, and every rule it ships sits in a cascade layer *and* is wrapped in
808
+ `:where()` — so it has zero specificity and any rule you write beats it, whatever your
809
+ import order. You should never need `!important`.
568
810
 
569
- Override CSS variables to match your theme:
811
+ The stylesheet is injected for you. Pass `styles: false` to the integration if you
812
+ would rather import it yourself.
813
+
814
+ ### Start with four seeds
570
815
 
571
816
  ```css
572
817
  :root {
573
- /* Player colors */
574
- --vocasync-primary: #3b82f6;
575
- --vocasync-primary-content: white;
576
- --vocasync-surface: #f8fafc;
577
- --vocasync-border: #e2e8f0;
578
- --vocasync-text: #1e293b;
579
- --vocasync-text-muted: #64748b;
580
-
581
- /* Word highlighting */
582
- --vocasync-highlight: #10b981;
583
- --vocasync-highlight-text: white;
584
- --vocasync-highlight-active-opacity: 0.25;
585
- --vocasync-highlight-trail-opacity: 0.12;
818
+ --vocasync-accent: #7c3aed;
819
+ --vocasync-surface: #ffffff;
820
+ --vocasync-text: #1e1b2e;
821
+ --vocasync-highlight: #f59e0b;
586
822
  }
823
+ ```
587
824
 
588
- /* Dark mode */
589
- @media (prefers-color-scheme: dark) {
590
- :root {
591
- --vocasync-surface: #1e293b;
592
- --vocasync-border: #334155;
593
- --vocasync-text: #f1f5f9;
594
- --vocasync-text-muted: #94a3b8;
595
- }
825
+ Borders, muted text, hover states, the track behind the progress bar and the contrast
826
+ colour on the play button all derive from those four. Override any derived token on
827
+ its own if a derivation is not what you wanted.
828
+
829
+ ### Better: point them at tokens you already have
830
+
831
+ ```css
832
+ :root {
833
+ --vocasync-accent: var(--color-primary);
834
+ --vocasync-surface: var(--color-card);
835
+ --vocasync-text: var(--color-text);
596
836
  }
597
837
  ```
598
838
 
839
+ Now the player follows your palette *and* your dark mode, because your tokens already
840
+ flip. For shadcn/ui and Tailwind that is a single import:
841
+
842
+ ```css
843
+ @import "@vocasync/astro/styles/preset-shadcn.css";
844
+ ```
845
+
846
+ ### Dark mode
847
+
848
+ Recognised with no configuration: the OS preference, plus `.dark`,
849
+ `[data-theme="dark"]` and `[data-mode="dark"]` — which covers Tailwind, next-themes,
850
+ daisyUI and Starlight. An explicit `.light`, `[data-theme="light"]` or
851
+ `data-vocasync-scheme="light"` opts out of the OS preference.
852
+
853
+ If your site signals dark mode some other way, name the selector:
854
+
855
+ ```js
856
+ vocasync({ theme: { darkSelector: '[data-appearance="night"]' } })
857
+ ```
858
+
859
+ ### Token reference
860
+
861
+ **Colour — seeds**
862
+
863
+ | Token | Default | Notes |
864
+ |-------|---------|-------|
865
+ | `--vocasync-accent` | `#3b82f6` | Play button, progress fill, slider thumbs |
866
+ | `--vocasync-surface` | `#f8fafc` | Player background |
867
+ | `--vocasync-text` | `#1e293b` | Primary text |
868
+ | `--vocasync-highlight` | `#10b981` | The word currently being spoken |
869
+
870
+ These four are registered with `@property`, so assigning something that is not a colour
871
+ falls back instead of blanking the component.
872
+
873
+ **Colour — derived** (override individually if you want)
874
+
875
+ | Token | Derived from |
876
+ |-------|--------------|
877
+ | `--vocasync-accent-hover` | accent, darkened |
878
+ | `--vocasync-accent-content` | black or white, whichever reads on the accent |
879
+ | `--vocasync-surface-raised` | surface, lightened — menus and the dock |
880
+ | `--vocasync-text-muted` | text mixed toward surface |
881
+ | `--vocasync-text-faint` | text mixed further toward surface |
882
+ | `--vocasync-border` | text mixed heavily toward surface |
883
+ | `--vocasync-track` | the unfilled part of a slider |
884
+ | `--vocasync-buffered-color` | the loaded-so-far range behind the seek bar |
885
+ | `--vocasync-highlight-active-bg` | highlight at 25% |
886
+ | `--vocasync-highlight-trail-bg` | highlight at 12% |
887
+ | `--vocasync-highlight-active-text` | unset — the active word keeps the prose colour |
888
+ | `--vocasync-l-threshold` | `0.623` — lightness at which `accent-content` flips to black. Perceptual, not a WCAG measurement; raise it if your accent needs dark text sooner |
889
+
890
+ **Typography**
891
+
892
+ | Token | Default |
893
+ |-------|---------|
894
+ | `--vocasync-font-family` | `inherit` |
895
+ | `--vocasync-font-size` | `0.875rem` |
896
+ | `--vocasync-font-size-sm` | `0.75rem` |
897
+ | `--vocasync-font-weight` | `400` |
898
+ | `--vocasync-font-weight-medium` | `500` |
899
+ | `--vocasync-line-height` | `1.4` |
900
+ | `--vocasync-numeric` | `tabular-nums` |
901
+
902
+ **Density and size** — `--vocasync-density` multiplies all of the following, so one
903
+ value rescales the player. The `size` prop sets it per player.
904
+
905
+ | Token | Default |
906
+ |-------|---------|
907
+ | `--vocasync-density` | `1` |
908
+ | `--vocasync-unit` | `0.25rem` |
909
+ | `--vocasync-gap` | `0.75rem` |
910
+ | `--vocasync-gap-sm` | `0.25rem` |
911
+ | `--vocasync-padding` | `1rem` |
912
+ | `--vocasync-control-size` | `2.5rem` |
913
+ | `--vocasync-control-size-sm` | `2rem` |
914
+ | `--vocasync-icon-size` | `1.25rem` |
915
+
916
+ **Shape**
917
+
918
+ | Token | Default |
919
+ |-------|---------|
920
+ | `--vocasync-radius` | `0.75rem` |
921
+ | `--vocasync-radius-control` | `0.375rem` |
922
+ | `--vocasync-radius-menu` | `0.5rem` |
923
+ | `--vocasync-radius-pill` | `9999px` |
924
+ | `--vocasync-word-radius` | `0.125rem` |
925
+ | `--vocasync-border-width` | `1px` |
926
+
927
+ **Sliders, dock, focus, elevation, motion, layering**
928
+
929
+ | Token | Default |
930
+ |-------|---------|
931
+ | `--vocasync-slider-height` | `0.375rem` |
932
+ | `--vocasync-played` | runtime state — the played range, written by the player |
933
+ | `--vocasync-buffered` | runtime state — the loaded range, written by the player |
934
+ | `--vocasync-slider-thumb-size` | `1rem` |
935
+ | `--vocasync-volume-width` | `4rem` |
936
+ | `--vocasync-dock-height` | `3.5rem` |
937
+ | `--vocasync-dock-offset` | `1rem` |
938
+ | `--vocasync-dock-width` | `20rem` |
939
+ | `--vocasync-focus-width` | `2px` |
940
+ | `--vocasync-focus-offset` | `2px` |
941
+ | `--vocasync-focus-color` | `var(--vocasync-accent)` |
942
+ | `--vocasync-shadow-sm`, `--vocasync-shadow`, `--vocasync-shadow-lg` | subtle elevation |
943
+ | `--vocasync-transition-fast`, `--vocasync-transition` | `150ms` / `200ms` ease |
944
+ | `--vocasync-menu-z` | `10` |
945
+ | `--vocasync-dock-z` | `1000` |
946
+
947
+ ### Stylesheets
948
+
949
+ | Import | Contains |
950
+ |--------|----------|
951
+ | `@vocasync/astro/styles/vocasync.css` | Everything (what the integration injects) |
952
+ | `@vocasync/astro/styles/layers.css` | The `@layer` order statement only |
953
+ | `@vocasync/astro/styles/tokens.css` | The tokens above |
954
+ | `@vocasync/astro/styles/content.css` | Word highlighting — needed even when headless |
955
+ | `@vocasync/astro/styles/player.css` | The player chrome — skip it if you bring your own |
956
+ | `@vocasync/astro/styles/preset-shadcn.css` | Maps our tokens onto a shadcn host's |
957
+
958
+ Import `layers.css` first if you want the layer order pinned regardless of where your
959
+ other imports land.
960
+
961
+ ## Migrating from v1
962
+
963
+ **Your audio map is unchanged.** The schema stays at version 3, so there is no re-sync
964
+ and no API spend — this release is presentation only.
965
+
966
+ ### Why the styling changed
967
+
968
+ Astro compiles a component's scoped styles to `.vocasync-player[data-astro-cid-…]`,
969
+ which has higher specificity than a plain class. Your own `.vocasync-player { … }` lost
970
+ to it, and so did any Tailwind utility passed through `class`. Three `!important`
971
+ declarations closed the rest. In practice the player could not be restyled.
972
+
973
+ The CSS now ships as ordinary stylesheets, in a cascade layer, with every selector
974
+ wrapped in `:where()`. Your rules win — layered or not, in any import order — and
975
+ nothing needs `!important`.
976
+
977
+ ### Stylesheet import
978
+
979
+ ```diff
980
+ - import "@vocasync/astro/styles/variables.css";
981
+ ```
982
+
983
+ Delete it. The integration injects the stylesheet; pass `styles: false` if you would
984
+ rather import `@vocasync/astro/styles/vocasync.css` yourself.
985
+
986
+ ### Token renames
987
+
988
+ | v1 | v2 |
989
+ |----|----|
990
+ | `--vocasync-primary` | `--vocasync-accent` |
991
+ | `--vocasync-primary-hover` | `--vocasync-accent-hover` |
992
+ | `--vocasync-primary-content` | `--vocasync-accent-content` |
993
+ | `--vocasync-surface-elevated` | `--vocasync-surface-raised` |
994
+ | `--vocasync-border-focus` | `--vocasync-focus-color` |
995
+ | `--vocasync-player-radius` | `--vocasync-radius` |
996
+ | `--vocasync-player-padding` | `--vocasync-padding` |
997
+ | `--vocasync-player-gap` | `--vocasync-gap` |
998
+ | `--vocasync-button-size` | `--vocasync-control-size` |
999
+ | `--vocasync-button-radius` | `--vocasync-radius-pill` |
1000
+ | `--vocasync-slider-radius` | `--vocasync-radius-pill` |
1001
+ | `--vocasync-mini-height` | `--vocasync-dock-height` |
1002
+ | `--vocasync-mini-offset` | `--vocasync-dock-offset` |
1003
+ | `--vocasync-highlight-active-opacity` | `--vocasync-highlight-active-bg` (a colour, not a number) |
1004
+ | `--vocasync-highlight-trail-opacity` | `--vocasync-highlight-trail-bg` (a colour, not a number) |
1005
+ | `--vocasync-highlight-text` | **removed** |
1006
+ | `--vocasync-transition-slow` | **removed** |
1007
+
1008
+ `--vocasync-highlight-text` was documented but no rule ever read it, so setting it
1009
+ never did anything. `--vocasync-transition-slow` was never referenced.
1010
+
1011
+ In most cases you can delete the overrides entirely and set the four seeds instead.
1012
+
1013
+ ### Prop changes
1014
+
1015
+ | v1 | v2 |
1016
+ |----|----|
1017
+ | `label="…"` | `strings={{ label: "…" }}` |
1018
+ | `enableMiniPlayer={false}` | `dock={{ enabled: false }}` |
1019
+ | `enableHighlighting={false}` | `highlight={{ enabled: false }}` |
1020
+ | `enableClickToSeek={false}` | `highlight={{ clickToSeek: false }}` |
1021
+ | `trailLength={4}` | `highlight={{ trailLength: 4 }}` |
1022
+
1023
+ ```diff
1024
+ <AudioPlayer
1025
+ slug={slug}
1026
+ audioEntry={audioEntry}
1027
+ - label={`Listen to "${title}"`}
1028
+ - enableMiniPlayer={true}
1029
+ - enableHighlighting={true}
1030
+ - trailLength={4}
1031
+ + strings={{ label: `Listen to "${title}"` }}
1032
+ + highlight={{ trailLength: 4 }}
1033
+ />
1034
+ ```
1035
+
1036
+ ### Behaviour changes
1037
+
1038
+ - **Arrow keys skip 15 seconds, not 5.** Set `skipSeconds={5}` to keep the old jump.
1039
+ - **Speed, volume, mute and highlighting are remembered** across pages and visits. Set
1040
+ `rememberPreferences={false}` to opt out.
1041
+ - **Autoscroll is off by default.** It used to follow the spoken word with no way to
1042
+ stop it, taking over the reader's scroll position. Pass `autoScroll="paragraph"` to
1043
+ keep the old behaviour.
1044
+ - **Starting one player pauses the others.** Pass `exclusive={false}` to allow overlap.
1045
+ - **A failed load shows an error state with a retry**, rather than leaving controls
1046
+ that look interactive but do nothing.
1047
+ - **Click-to-seek no longer depends on highlighting.** Turning highlighting off used to
1048
+ disable it silently.
1049
+ - **Autoscroll yields to the reader.** Scrolling suspends it for a few seconds rather
1050
+ than dragging the page back.
1051
+
1052
+ ### Rehype plugin
1053
+
1054
+ `classPrefix` is removed. It renamed the word-span class while `.vocasync-word` stayed
1055
+ hardcoded in the stylesheet, the player and the WordPress plugin, so setting it
1056
+ silently broke highlighting. Use `extraWordClass` to add a class alongside
1057
+ `vocasync-word`, or drive the engine headlessly for entirely different markup.
1058
+
1059
+ ```diff
1060
+ - [rehypeAudioWords, { collectionName, audioMapPath, classPrefix: "vocasync" }]
1061
+ + [rehypeAudioWords, { collectionName, audioMapPath }]
1062
+ ```
1063
+
1064
+ ### Astro 7
1065
+
1066
+ Astro 7 replaced its default Markdown processor, so `@astrojs/markdown-remark` is no
1067
+ longer installed with it — and rehype plugins do not run without it. On Astro 7:
1068
+
1069
+ ```bash
1070
+ bun add @astrojs/markdown-remark
1071
+ ```
1072
+
1073
+ Astro 4, 5 and 6 need nothing extra.
1074
+
599
1075
  ## Troubleshooting
600
1076
 
601
1077
  ### "No VocaSync configuration found"
602
1078
 
603
1079
  Create a `vocasync.config.mjs` file in your project root.
604
1080
 
605
- ### Words not highlighting
1081
+ ### No words are highlighted
1082
+
1083
+ 1. **On Astro 7, install `@astrojs/markdown-remark`.** Astro 7 stopped bundling it, and
1084
+ rehype plugins — which is what produces the word spans — do not run without it. The
1085
+ build fails with a message naming the package.
1086
+ 2. Check the rehype plugins are registered in `astro.config.mjs`, and that
1087
+ `collectionName` and `audioMapPath` match your setup.
1088
+ 3. Make sure the article content is inside the element named by `articleSelector`
1089
+ (`[data-article-body]` by default).
1090
+ 4. View source: each word should be a `<span class="vocasync-word" data-i="…">`. If the
1091
+ spans are absent the rehype plugin did not run; if they are present but nothing
1092
+ lights up, the audio map and the page disagree — see below.
1093
+
1094
+ ### Highlighting drifts partway through a post
1095
+
1096
+ The audio map is stale. `data-i` indices are assigned at build time against the word
1097
+ stream in `audio-map.json`, so editing a post without re-running `npx vocasync sync`
1098
+ leaves the spans pointing at the wrong words from the edit onwards.
1099
+
1100
+ ### The player is invisible or unstyled
1101
+
1102
+ The stylesheet is injected by the integration. If you passed `styles: false`, import it
1103
+ yourself — `@vocasync/astro/styles/vocasync.css`. If you are driving the engine
1104
+ headlessly with your own markup, you still need `content.css` for the word spans.
1105
+
1106
+ ### My CSS override does not apply
1107
+
1108
+ It should — every rule the player ships is inside a cascade layer *and* wrapped in
1109
+ `:where()`, so it has zero specificity and loses to anything you write. If an override
1110
+ is not landing, it is almost certainly a selector that does not match rather than a
1111
+ specificity problem. Check the element in devtools; the player root is
1112
+ `.vocasync-player`, and it carries `data-variant`, `data-size` and `data-player-state`
1113
+ attributes you can target.
1114
+
1115
+ You should never need `!important`. If you do, that is a bug worth reporting.
1116
+
1117
+ ### The player stays light when my site goes dark
1118
+
1119
+ `.dark`, `[data-theme="dark"]` and `[data-mode="dark"]` are recognised automatically.
1120
+ If your site signals dark mode some other way, name it:
1121
+
1122
+ ```js
1123
+ vocasync({ theme: { darkSelector: '[data-appearance="night"]' } })
1124
+ ```
1125
+
1126
+ If your site has its own tokens, the tidier fix is to point ours at them — then the
1127
+ player follows whatever your tokens do, in both directions.
1128
+
1129
+ ### The play button does nothing
1130
+
1131
+ Check `data-player-state` on the player root:
1132
+
1133
+ - `error` — the audio failed to load. Usually an expired publishable key; re-run
1134
+ `npx vocasync sync`. The player shows a retry button.
1135
+ - `no-audio` — there is no entry for this `slug` in the audio map.
1136
+ - `ready` with `data-player-buffering` — it is still loading, not broken.
1137
+
1138
+ Browsers also block playback that is not user-initiated; a `NotAllowedError` in the
1139
+ console after a programmatic `play()` is expected, not a fault.
1140
+
1141
+ ### Several players on one page interfere
1142
+
1143
+ They should not, but each needs its own `articleSelector` if more than one article body
1144
+ is on the page — otherwise click-to-seek cannot tell which player owns a word, and the
1145
+ first one wins. A warning is logged in that case.
606
1146
 
607
- 1. Make sure the rehype plugin is configured in `astro.config.mjs`
608
- 2. Check that `collectionName` matches your collection
609
- 3. Verify `audioMapPath` points to your audio map
610
- 4. Ensure content is wrapped in `[data-article-body]`
1147
+ By default, starting one player pauses the others. Pass `exclusive={false}` if you want
1148
+ them to overlap.
611
1149
 
612
- ### Audio not playing
1150
+ ### The player stops working after a client-side navigation
613
1151
 
614
- 1. Run `npx vocasync sync` to generate audio
615
- 2. Check that `audio-map.json` exists and has entries
616
- 3. Verify the `slug` prop matches your content slug
1152
+ The player boots on `astro:page-load` and tears down on `astro:before-swap`, so
1153
+ `<ClientRouter />` is supported. If you are using a different client-side router, call
1154
+ `install()` from `@vocasync/astro/player-core` after each navigation.
617
1155
 
618
1156
  ### CLI errors
619
1157