@vocasync/astro 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +580 -0
- package/dist/api/client.d.ts +77 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +223 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +2 -0
- package/dist/api/index.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +257 -0
- package/dist/cli.js.map +1 -0
- package/dist/components/AudioPlayer.astro +1097 -0
- package/dist/components/index.d.ts +19 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +4 -0
- package/dist/components/index.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +2 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/schema.d.ts +275 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +124 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/core/audio-map.d.ts +52 -0
- package/dist/core/audio-map.d.ts.map +1 -0
- package/dist/core/audio-map.js +97 -0
- package/dist/core/audio-map.js.map +1 -0
- package/dist/core/content-loader.d.ts +17 -0
- package/dist/core/content-loader.d.ts.map +1 -0
- package/dist/core/content-loader.js +141 -0
- package/dist/core/content-loader.js.map +1 -0
- package/dist/core/hash-manager.d.ts +16 -0
- package/dist/core/hash-manager.d.ts.map +1 -0
- package/dist/core/hash-manager.js +21 -0
- package/dist/core/hash-manager.js.map +1 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +5 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/speech-builder.d.ts +19 -0
- package/dist/core/speech-builder.d.ts.map +1 -0
- package/dist/core/speech-builder.js +252 -0
- package/dist/core/speech-builder.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/integration.d.ts +27 -0
- package/dist/integration.d.ts.map +1 -0
- package/dist/integration.js +110 -0
- package/dist/integration.js.map +1 -0
- package/dist/lib/latex-to-speech/index.d.ts +26 -0
- package/dist/lib/latex-to-speech/index.d.ts.map +1 -0
- package/dist/lib/latex-to-speech/index.js +101 -0
- package/dist/lib/latex-to-speech/index.js.map +1 -0
- package/dist/rehype/audio-words.d.ts +50 -0
- package/dist/rehype/audio-words.d.ts.map +1 -0
- package/dist/rehype/audio-words.js +269 -0
- package/dist/rehype/audio-words.js.map +1 -0
- package/dist/rehype/index.d.ts +6 -0
- package/dist/rehype/index.d.ts.map +1 -0
- package/dist/rehype/index.js +4 -0
- package/dist/rehype/index.js.map +1 -0
- package/dist/rehype/rehype-math-speech.d.ts +18 -0
- package/dist/rehype/rehype-math-speech.d.ts.map +1 -0
- package/dist/rehype/rehype-math-speech.js +117 -0
- package/dist/rehype/rehype-math-speech.js.map +1 -0
- package/dist/rehype/remark-math-speech.d.ts +13 -0
- package/dist/rehype/remark-math-speech.d.ts.map +1 -0
- package/dist/rehype/remark-math-speech.js +26 -0
- package/dist/rehype/remark-math-speech.js.map +1 -0
- package/dist/styles/variables.css +181 -0
- package/dist/sync/index.d.ts +3 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +2 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/orchestrator.d.ts +36 -0
- package/dist/sync/orchestrator.d.ts.map +1 -0
- package/dist/sync/orchestrator.js +166 -0
- package/dist/sync/orchestrator.js.map +1 -0
- package/dist/types/index.d.ts +196 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +89 -0
- package/src/api/client.ts +316 -0
- package/src/api/index.ts +1 -0
- package/src/cli.ts +301 -0
- package/src/components/AudioPlayer.astro +1097 -0
- package/src/components/index.ts +24 -0
- package/src/config/index.ts +30 -0
- package/src/config/schema.ts +177 -0
- package/src/core/audio-map.ts +107 -0
- package/src/core/content-loader.ts +171 -0
- package/src/core/hash-manager.ts +22 -0
- package/src/core/index.ts +12 -0
- package/src/core/speech-builder.ts +307 -0
- package/src/data/audio-map.example.json +19 -0
- package/src/env.d.ts +13 -0
- package/src/index.ts +67 -0
- package/src/integration.ts +123 -0
- package/src/lib/latex-to-speech/index.ts +126 -0
- package/src/rehype/audio-words.ts +345 -0
- package/src/rehype/index.ts +6 -0
- package/src/rehype/rehype-math-speech.ts +145 -0
- package/src/rehype/remark-math-speech.ts +31 -0
- package/src/styles/variables.css +181 -0
- package/src/sync/index.ts +2 -0
- package/src/sync/orchestrator.ts +239 -0
- package/src/types/index.ts +211 -0
- package/src/types/modules.d.ts +11 -0
|
@@ -0,0 +1,1097 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* VocaSync AudioPlayer Component
|
|
4
|
+
*
|
|
5
|
+
* A full-featured audio player with word-level highlighting support.
|
|
6
|
+
* Uses native HTML5 audio and range inputs - no external dependencies.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```astro
|
|
10
|
+
* <AudioPlayer
|
|
11
|
+
* slug={post.slug}
|
|
12
|
+
* label="Listen to this article"
|
|
13
|
+
* enableMiniPlayer={true}
|
|
14
|
+
* />
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type { AlignedWord } from "../types/index.js";
|
|
19
|
+
|
|
20
|
+
interface AudioEntry {
|
|
21
|
+
audioUrl: string;
|
|
22
|
+
alignmentUrl?: string;
|
|
23
|
+
words?: AlignedWord[];
|
|
24
|
+
duration?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface Props {
|
|
28
|
+
/** Post slug to lookup audio in audio-map */
|
|
29
|
+
slug: string;
|
|
30
|
+
/** Audio entry data (from audio-map.json import) */
|
|
31
|
+
audioEntry?: AudioEntry;
|
|
32
|
+
/** Accessible label for the player */
|
|
33
|
+
label?: string;
|
|
34
|
+
/** Show placeholder when no audio available */
|
|
35
|
+
showPlaceholder?: boolean;
|
|
36
|
+
/** Additional CSS classes */
|
|
37
|
+
class?: string;
|
|
38
|
+
/** Selector for article body (for word highlighting) */
|
|
39
|
+
articleSelector?: string;
|
|
40
|
+
/** Enable floating mini player when main player scrolls out of view */
|
|
41
|
+
enableMiniPlayer?: boolean;
|
|
42
|
+
/** Enable word highlighting during playback */
|
|
43
|
+
enableHighlighting?: boolean;
|
|
44
|
+
/** Number of trailing highlighted words */
|
|
45
|
+
trailLength?: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const {
|
|
49
|
+
slug,
|
|
50
|
+
audioEntry,
|
|
51
|
+
label = "Listen to this article",
|
|
52
|
+
showPlaceholder = true,
|
|
53
|
+
class: className = "",
|
|
54
|
+
articleSelector = "[data-article-body]",
|
|
55
|
+
enableMiniPlayer = true,
|
|
56
|
+
enableHighlighting = true,
|
|
57
|
+
trailLength = 4,
|
|
58
|
+
} = Astro.props;
|
|
59
|
+
|
|
60
|
+
// Generate unique IDs for this player instance
|
|
61
|
+
const playerId = `vocasync-player-${slug.replace(/[^a-z0-9]/gi, "-")}`;
|
|
62
|
+
const audioId = `${playerId}-audio`;
|
|
63
|
+
|
|
64
|
+
// Serialize audio data for client-side use
|
|
65
|
+
const audioDataJson = audioEntry ? JSON.stringify({
|
|
66
|
+
audioUrl: audioEntry.audioUrl,
|
|
67
|
+
words: audioEntry.words || [],
|
|
68
|
+
duration: audioEntry.duration,
|
|
69
|
+
}) : null;
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
<div
|
|
73
|
+
class:list={["vocasync-player", className]}
|
|
74
|
+
id={playerId}
|
|
75
|
+
data-slug={slug}
|
|
76
|
+
data-audio-entry={audioDataJson}
|
|
77
|
+
data-article-selector={articleSelector}
|
|
78
|
+
data-enable-mini={enableMiniPlayer}
|
|
79
|
+
data-enable-highlighting={enableHighlighting}
|
|
80
|
+
data-trail-length={trailLength}
|
|
81
|
+
aria-label={label}
|
|
82
|
+
tabindex="0"
|
|
83
|
+
>
|
|
84
|
+
<!-- Hidden audio element -->
|
|
85
|
+
<audio id={audioId} preload="metadata"></audio>
|
|
86
|
+
|
|
87
|
+
<!-- Loading state -->
|
|
88
|
+
<div class="vocasync-player__loading" data-state="loading">
|
|
89
|
+
<div class="vocasync-player__spinner"></div>
|
|
90
|
+
<span>Loading audio...</span>
|
|
91
|
+
</div>
|
|
92
|
+
|
|
93
|
+
<!-- No audio placeholder -->
|
|
94
|
+
<div class="vocasync-player__placeholder" data-state="no-audio" hidden>
|
|
95
|
+
{showPlaceholder && (
|
|
96
|
+
<span class="vocasync-player__placeholder-text">
|
|
97
|
+
Audio not available for this article
|
|
98
|
+
</span>
|
|
99
|
+
)}
|
|
100
|
+
</div>
|
|
101
|
+
|
|
102
|
+
<!-- Main player controls -->
|
|
103
|
+
<div class="vocasync-player__controls" data-state="ready" hidden>
|
|
104
|
+
<!-- Play/Pause button -->
|
|
105
|
+
<button
|
|
106
|
+
type="button"
|
|
107
|
+
class="vocasync-player__play-btn"
|
|
108
|
+
aria-label="Play"
|
|
109
|
+
data-action="play-pause"
|
|
110
|
+
title="Play/Pause (Space)"
|
|
111
|
+
>
|
|
112
|
+
<svg class="vocasync-icon vocasync-icon--play" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
|
|
113
|
+
<path d="M8 5v14l11-7z"/>
|
|
114
|
+
</svg>
|
|
115
|
+
<svg class="vocasync-icon vocasync-icon--pause" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true" hidden>
|
|
116
|
+
<rect x="6" y="4" width="4" height="16"/>
|
|
117
|
+
<rect x="14" y="4" width="4" height="16"/>
|
|
118
|
+
</svg>
|
|
119
|
+
</button>
|
|
120
|
+
|
|
121
|
+
<!-- Progress section -->
|
|
122
|
+
<div class="vocasync-player__progress-section">
|
|
123
|
+
<!-- Time display -->
|
|
124
|
+
<div class="vocasync-player__time">
|
|
125
|
+
<span data-time="current">0:00</span>
|
|
126
|
+
<span class="vocasync-player__time-sep">/</span>
|
|
127
|
+
<span data-time="duration">0:00</span>
|
|
128
|
+
</div>
|
|
129
|
+
|
|
130
|
+
<!-- Progress bar -->
|
|
131
|
+
<input
|
|
132
|
+
type="range"
|
|
133
|
+
class="vocasync-player__progress"
|
|
134
|
+
min="0"
|
|
135
|
+
max="100"
|
|
136
|
+
value="0"
|
|
137
|
+
step="0.1"
|
|
138
|
+
aria-label="Seek"
|
|
139
|
+
data-action="seek"
|
|
140
|
+
title="Seek (Arrow keys)"
|
|
141
|
+
/>
|
|
142
|
+
</div>
|
|
143
|
+
|
|
144
|
+
<!-- Control buttons group -->
|
|
145
|
+
<div class="vocasync-player__button-group">
|
|
146
|
+
<!-- Highlighting toggle -->
|
|
147
|
+
<button
|
|
148
|
+
type="button"
|
|
149
|
+
class="vocasync-player__icon-btn"
|
|
150
|
+
aria-label="Toggle word highlighting"
|
|
151
|
+
data-action="toggle-highlighting"
|
|
152
|
+
data-highlighting="on"
|
|
153
|
+
title="Toggle highlighting (H)"
|
|
154
|
+
>
|
|
155
|
+
<svg class="vocasync-icon vocasync-icon--highlight-on" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
|
|
156
|
+
<path d="M15.6 2.3L12 2l-3.6.3-.2.4L11 6h2l2.8-3.3-.2-.4zM2 22h20v-2H2v2zm1-3h18l-1.5-7.6-.5-.4h-14l-.5.4L3 19zm6-2H7v-2h2v2zm4 0h-2v-2h2v2zm4 0h-2v-2h2v2zm-5-5h-1l-1-4h3l-1 4z"/>
|
|
157
|
+
</svg>
|
|
158
|
+
<svg class="vocasync-icon vocasync-icon--highlight-off" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true" hidden>
|
|
159
|
+
<path d="M15.6 2.3L12 2l-3.6.3-.2.4L11 6h2l2.8-3.3-.2-.4zM2 22h20v-2H2v2zm1-3h18l-1.5-7.6-.5-.4h-14l-.5.4L3 19zm6-2H7v-2h2v2zm4 0h-2v-2h2v2zm4 0h-2v-2h2v2zm-5-5h-1l-1-4h3l-1 4z" opacity="0.3"/>
|
|
160
|
+
<line x1="4" y1="4" x2="20" y2="20" stroke="currentColor" stroke-width="2"/>
|
|
161
|
+
</svg>
|
|
162
|
+
</button>
|
|
163
|
+
|
|
164
|
+
<!-- Speed control -->
|
|
165
|
+
<div class="vocasync-player__speed">
|
|
166
|
+
<button
|
|
167
|
+
type="button"
|
|
168
|
+
class="vocasync-player__speed-btn"
|
|
169
|
+
aria-label="Playback speed"
|
|
170
|
+
data-action="speed"
|
|
171
|
+
>
|
|
172
|
+
<span data-speed-label>1x</span>
|
|
173
|
+
</button>
|
|
174
|
+
<div class="vocasync-player__speed-menu" hidden>
|
|
175
|
+
<button type="button" data-speed="0.5">0.5x</button>
|
|
176
|
+
<button type="button" data-speed="0.75">0.75x</button>
|
|
177
|
+
<button type="button" data-speed="1" data-active>1x</button>
|
|
178
|
+
<button type="button" data-speed="1.25">1.25x</button>
|
|
179
|
+
<button type="button" data-speed="1.5">1.5x</button>
|
|
180
|
+
<button type="button" data-speed="2">2x</button>
|
|
181
|
+
</div>
|
|
182
|
+
</div>
|
|
183
|
+
|
|
184
|
+
<!-- Volume control -->
|
|
185
|
+
<div class="vocasync-player__volume">
|
|
186
|
+
<button
|
|
187
|
+
type="button"
|
|
188
|
+
class="vocasync-player__icon-btn"
|
|
189
|
+
aria-label="Toggle mute"
|
|
190
|
+
data-action="mute"
|
|
191
|
+
title="Toggle mute (M)"
|
|
192
|
+
>
|
|
193
|
+
<svg class="vocasync-icon vocasync-icon--volume-high" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
|
|
194
|
+
<path d="M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z"/>
|
|
195
|
+
</svg>
|
|
196
|
+
<svg class="vocasync-icon vocasync-icon--volume-mute" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true" hidden>
|
|
197
|
+
<path d="M16.5 12c0-1.77-1.02-3.29-2.5-4.03v2.21l2.45 2.45c.03-.2.05-.41.05-.63zm2.5 0c0 .94-.2 1.82-.54 2.64l1.51 1.51C20.63 14.91 21 13.5 21 12c0-4.28-2.99-7.86-7-8.77v2.06c2.89.86 5 3.54 5 6.71zM4.27 3L3 4.27 7.73 9H3v6h4l5 5v-6.73l4.25 4.25c-.67.52-1.42.93-2.25 1.18v2.06c1.38-.31 2.63-.95 3.69-1.81L19.73 21 21 19.73l-9-9L4.27 3zM12 4L9.91 6.09 12 8.18V4z"/>
|
|
198
|
+
</svg>
|
|
199
|
+
</button>
|
|
200
|
+
<input
|
|
201
|
+
type="range"
|
|
202
|
+
class="vocasync-player__volume-slider"
|
|
203
|
+
min="0"
|
|
204
|
+
max="100"
|
|
205
|
+
value="100"
|
|
206
|
+
aria-label="Volume"
|
|
207
|
+
data-action="volume"
|
|
208
|
+
/>
|
|
209
|
+
</div>
|
|
210
|
+
class="vocasync-mini-player__play-btn"
|
|
211
|
+
aria-label="Play"
|
|
212
|
+
data-action="play-pause"
|
|
213
|
+
>
|
|
214
|
+
<svg class="vocasync-icon vocasync-icon--play" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
|
|
215
|
+
<path d="M8 5v14l11-7z"/>
|
|
216
|
+
</svg>
|
|
217
|
+
<svg class="vocasync-icon vocasync-icon--pause" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true" hidden>
|
|
218
|
+
<rect x="6" y="4" width="4" height="16"/>
|
|
219
|
+
<rect x="14" y="4" width="4" height="16"/>
|
|
220
|
+
</svg>
|
|
221
|
+
</button>
|
|
222
|
+
<div class="vocasync-mini-player__progress">
|
|
223
|
+
<div class="vocasync-mini-player__progress-bar" data-progress></div>
|
|
224
|
+
</div>
|
|
225
|
+
<span class="vocasync-mini-player__time" data-time="current">0:00</span>
|
|
226
|
+
<button
|
|
227
|
+
type="button"
|
|
228
|
+
class="vocasync-mini-player__close-btn"
|
|
229
|
+
aria-label="Close mini player"
|
|
230
|
+
data-action="close-mini"
|
|
231
|
+
>
|
|
232
|
+
<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
|
|
233
|
+
<path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/>
|
|
234
|
+
</svg>
|
|
235
|
+
</button>
|
|
236
|
+
</div>
|
|
237
|
+
)}
|
|
238
|
+
|
|
239
|
+
<style>
|
|
240
|
+
/* ========================================
|
|
241
|
+
* MAIN PLAYER STYLES
|
|
242
|
+
* ======================================== */
|
|
243
|
+
|
|
244
|
+
.vocasync-player {
|
|
245
|
+
display: flex;
|
|
246
|
+
flex-direction: column;
|
|
247
|
+
gap: var(--vocasync-player-gap);
|
|
248
|
+
padding: var(--vocasync-player-padding);
|
|
249
|
+
background: var(--vocasync-surface);
|
|
250
|
+
border: 1px solid var(--vocasync-border);
|
|
251
|
+
border-radius: var(--vocasync-player-radius);
|
|
252
|
+
box-shadow: var(--vocasync-shadow-sm);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
.vocasync-player:focus-visible {
|
|
256
|
+
outline: 2px solid var(--vocasync-border-focus);
|
|
257
|
+
outline-offset: 2px;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
.vocasync-player__loading,
|
|
261
|
+
.vocasync-player__placeholder {
|
|
262
|
+
display: flex;
|
|
263
|
+
align-items: center;
|
|
264
|
+
justify-content: center;
|
|
265
|
+
gap: 0.5rem;
|
|
266
|
+
padding: 0.75rem;
|
|
267
|
+
color: var(--vocasync-text-muted);
|
|
268
|
+
font-size: 0.875rem;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/* Hidden state for loading/placeholder/controls - overrides display: flex */
|
|
272
|
+
.vocasync-player__loading[hidden],
|
|
273
|
+
.vocasync-player__placeholder[hidden],
|
|
274
|
+
.vocasync-player__controls[hidden] {
|
|
275
|
+
display: none !important;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
.vocasync-player__spinner {
|
|
279
|
+
width: 1.25rem;
|
|
280
|
+
height: 1.25rem;
|
|
281
|
+
border: 2px solid var(--vocasync-border);
|
|
282
|
+
border-top-color: var(--vocasync-primary);
|
|
283
|
+
border-radius: 50%;
|
|
284
|
+
animation: vocasync-spin 0.75s linear infinite;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
@keyframes vocasync-spin {
|
|
288
|
+
to { transform: rotate(360deg); }
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
.vocasync-player__controls {
|
|
292
|
+
display: flex;
|
|
293
|
+
align-items: center;
|
|
294
|
+
gap: var(--vocasync-player-gap);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/* Play button */
|
|
298
|
+
.vocasync-player__play-btn {
|
|
299
|
+
display: flex;
|
|
300
|
+
align-items: center;
|
|
301
|
+
justify-content: center;
|
|
302
|
+
width: var(--vocasync-button-size);
|
|
303
|
+
height: var(--vocasync-button-size);
|
|
304
|
+
flex-shrink: 0;
|
|
305
|
+
background: var(--vocasync-primary);
|
|
306
|
+
color: var(--vocasync-primary-content);
|
|
307
|
+
border: none;
|
|
308
|
+
border-radius: var(--vocasync-button-radius);
|
|
309
|
+
cursor: pointer;
|
|
310
|
+
transition: background-color var(--vocasync-transition-fast);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
.vocasync-player__play-btn:hover {
|
|
314
|
+
background: var(--vocasync-primary-hover);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
.vocasync-player__play-btn:focus-visible {
|
|
318
|
+
outline: 2px solid var(--vocasync-border-focus);
|
|
319
|
+
outline-offset: 2px;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
.vocasync-icon {
|
|
323
|
+
width: 1.25rem;
|
|
324
|
+
height: 1.25rem;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/* Progress section */
|
|
328
|
+
.vocasync-player__progress-section {
|
|
329
|
+
display: flex;
|
|
330
|
+
flex-direction: column;
|
|
331
|
+
gap: 0.25rem;
|
|
332
|
+
flex: 1;
|
|
333
|
+
min-width: 0;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
.vocasync-player__time {
|
|
337
|
+
display: flex;
|
|
338
|
+
gap: 0.25rem;
|
|
339
|
+
font-size: 0.75rem;
|
|
340
|
+
font-variant-numeric: tabular-nums;
|
|
341
|
+
color: var(--vocasync-text-muted);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
.vocasync-player__time-sep {
|
|
345
|
+
color: var(--vocasync-text-faint);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/* Range input (progress & volume) */
|
|
349
|
+
.vocasync-player__progress,
|
|
350
|
+
.vocasync-player__volume-slider {
|
|
351
|
+
-webkit-appearance: none;
|
|
352
|
+
appearance: none;
|
|
353
|
+
width: 100%;
|
|
354
|
+
height: var(--vocasync-slider-height);
|
|
355
|
+
background: var(--vocasync-border);
|
|
356
|
+
border-radius: var(--vocasync-slider-radius);
|
|
357
|
+
cursor: pointer;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
.vocasync-player__progress::-webkit-slider-thumb,
|
|
361
|
+
.vocasync-player__volume-slider::-webkit-slider-thumb {
|
|
362
|
+
-webkit-appearance: none;
|
|
363
|
+
appearance: none;
|
|
364
|
+
width: var(--vocasync-slider-thumb-size);
|
|
365
|
+
height: var(--vocasync-slider-thumb-size);
|
|
366
|
+
background: var(--vocasync-primary);
|
|
367
|
+
border-radius: 50%;
|
|
368
|
+
border: none;
|
|
369
|
+
box-shadow: var(--vocasync-shadow);
|
|
370
|
+
transition: transform var(--vocasync-transition-fast);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
.vocasync-player__progress::-webkit-slider-thumb:hover,
|
|
374
|
+
.vocasync-player__volume-slider::-webkit-slider-thumb:hover {
|
|
375
|
+
transform: scale(1.1);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
.vocasync-player__progress::-moz-range-thumb,
|
|
379
|
+
.vocasync-player__volume-slider::-moz-range-thumb {
|
|
380
|
+
width: var(--vocasync-slider-thumb-size);
|
|
381
|
+
height: var(--vocasync-slider-thumb-size);
|
|
382
|
+
background: var(--vocasync-primary);
|
|
383
|
+
border-radius: 50%;
|
|
384
|
+
border: none;
|
|
385
|
+
box-shadow: var(--vocasync-shadow);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/* Button group */
|
|
389
|
+
.vocasync-player__button-group {
|
|
390
|
+
display: flex;
|
|
391
|
+
align-items: center;
|
|
392
|
+
gap: 0.25rem;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/* Icon buttons (highlight toggle, mute) */
|
|
396
|
+
.vocasync-player__icon-btn {
|
|
397
|
+
display: flex;
|
|
398
|
+
align-items: center;
|
|
399
|
+
justify-content: center;
|
|
400
|
+
width: 2rem;
|
|
401
|
+
height: 2rem;
|
|
402
|
+
color: var(--vocasync-text-muted);
|
|
403
|
+
background: transparent;
|
|
404
|
+
border: none;
|
|
405
|
+
border-radius: 0.375rem;
|
|
406
|
+
cursor: pointer;
|
|
407
|
+
transition: color var(--vocasync-transition-fast), background-color var(--vocasync-transition-fast);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
.vocasync-player__icon-btn:hover {
|
|
411
|
+
color: var(--vocasync-text);
|
|
412
|
+
background: var(--vocasync-border);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
.vocasync-player__icon-btn:focus-visible {
|
|
416
|
+
outline: 2px solid var(--vocasync-border-focus);
|
|
417
|
+
outline-offset: 2px;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
.vocasync-player__icon-btn[data-highlighting="off"] {
|
|
421
|
+
color: var(--vocasync-text-faint);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/* Speed control */
|
|
425
|
+
.vocasync-player__speed {
|
|
426
|
+
position: relative;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
.vocasync-player__speed-btn {
|
|
430
|
+
display: flex;
|
|
431
|
+
align-items: center;
|
|
432
|
+
justify-content: center;
|
|
433
|
+
min-width: 2.5rem;
|
|
434
|
+
height: 1.75rem;
|
|
435
|
+
padding: 0 0.5rem;
|
|
436
|
+
font-size: 0.75rem;
|
|
437
|
+
font-weight: 500;
|
|
438
|
+
color: var(--vocasync-text-muted);
|
|
439
|
+
background: var(--vocasync-surface-elevated);
|
|
440
|
+
border: 1px solid var(--vocasync-border);
|
|
441
|
+
border-radius: 0.375rem;
|
|
442
|
+
cursor: pointer;
|
|
443
|
+
transition: all var(--vocasync-transition-fast);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
.vocasync-player__speed-btn:hover {
|
|
447
|
+
color: var(--vocasync-text);
|
|
448
|
+
border-color: var(--vocasync-primary);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
.vocasync-player__speed-menu {
|
|
452
|
+
position: absolute;
|
|
453
|
+
bottom: 100%;
|
|
454
|
+
left: 50%;
|
|
455
|
+
transform: translateX(-50%);
|
|
456
|
+
display: flex;
|
|
457
|
+
flex-direction: column;
|
|
458
|
+
gap: 0.125rem;
|
|
459
|
+
padding: 0.25rem;
|
|
460
|
+
margin-bottom: 0.5rem;
|
|
461
|
+
background: var(--vocasync-surface-elevated);
|
|
462
|
+
border: 1px solid var(--vocasync-border);
|
|
463
|
+
border-radius: 0.5rem;
|
|
464
|
+
box-shadow: var(--vocasync-shadow-lg);
|
|
465
|
+
z-index: 10;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
.vocasync-player__speed-menu button {
|
|
469
|
+
padding: 0.375rem 0.75rem;
|
|
470
|
+
font-size: 0.75rem;
|
|
471
|
+
color: var(--vocasync-text-muted);
|
|
472
|
+
background: transparent;
|
|
473
|
+
border: none;
|
|
474
|
+
border-radius: 0.25rem;
|
|
475
|
+
cursor: pointer;
|
|
476
|
+
white-space: nowrap;
|
|
477
|
+
transition: all var(--vocasync-transition-fast);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
.vocasync-player__speed-menu button:hover {
|
|
481
|
+
background: var(--vocasync-border);
|
|
482
|
+
color: var(--vocasync-text);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
.vocasync-player__speed-menu button[data-active] {
|
|
486
|
+
background: var(--vocasync-primary);
|
|
487
|
+
color: var(--vocasync-primary-content);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/* Volume control */
|
|
491
|
+
.vocasync-player__volume {
|
|
492
|
+
display: flex;
|
|
493
|
+
align-items: center;
|
|
494
|
+
gap: 0.25rem;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
.vocasync-player__volume-slider {
|
|
498
|
+
width: 4rem;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/* Hide volume slider on mobile */
|
|
502
|
+
@media (max-width: 640px) {
|
|
503
|
+
.vocasync-player__volume-slider {
|
|
504
|
+
display: none;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/* ========================================
|
|
509
|
+
* MINI PLAYER STYLES
|
|
510
|
+
* ======================================== */
|
|
511
|
+
|
|
512
|
+
.vocasync-mini-player {
|
|
513
|
+
position: fixed;
|
|
514
|
+
bottom: var(--vocasync-mini-offset);
|
|
515
|
+
left: var(--vocasync-mini-offset);
|
|
516
|
+
right: var(--vocasync-mini-offset);
|
|
517
|
+
display: flex;
|
|
518
|
+
align-items: center;
|
|
519
|
+
gap: 0.75rem;
|
|
520
|
+
height: var(--vocasync-mini-height);
|
|
521
|
+
padding: 0 1rem;
|
|
522
|
+
background: var(--vocasync-surface-elevated);
|
|
523
|
+
border: 1px solid var(--vocasync-border);
|
|
524
|
+
border-radius: 9999px;
|
|
525
|
+
box-shadow: var(--vocasync-shadow-lg);
|
|
526
|
+
z-index: 1000;
|
|
527
|
+
transition: transform var(--vocasync-transition), opacity var(--vocasync-transition);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
.vocasync-mini-player[hidden] {
|
|
531
|
+
display: flex; /* Override hidden for animation */
|
|
532
|
+
opacity: 0;
|
|
533
|
+
transform: translateY(100%);
|
|
534
|
+
pointer-events: none;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
.vocasync-mini-player:not([hidden]) {
|
|
538
|
+
opacity: 1;
|
|
539
|
+
transform: translateY(0);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
.vocasync-mini-player__play-btn {
|
|
543
|
+
display: flex;
|
|
544
|
+
align-items: center;
|
|
545
|
+
justify-content: center;
|
|
546
|
+
width: 2rem;
|
|
547
|
+
height: 2rem;
|
|
548
|
+
flex-shrink: 0;
|
|
549
|
+
background: var(--vocasync-primary);
|
|
550
|
+
color: var(--vocasync-primary-content);
|
|
551
|
+
border: none;
|
|
552
|
+
border-radius: 50%;
|
|
553
|
+
cursor: pointer;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
.vocasync-mini-player__play-btn .vocasync-icon {
|
|
557
|
+
width: 1rem;
|
|
558
|
+
height: 1rem;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
.vocasync-mini-player__progress {
|
|
562
|
+
flex: 1;
|
|
563
|
+
height: 0.25rem;
|
|
564
|
+
background: var(--vocasync-border);
|
|
565
|
+
border-radius: 9999px;
|
|
566
|
+
overflow: hidden;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
.vocasync-mini-player__progress-bar {
|
|
570
|
+
height: 100%;
|
|
571
|
+
background: var(--vocasync-primary);
|
|
572
|
+
border-radius: 9999px;
|
|
573
|
+
transition: width 100ms linear;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
.vocasync-mini-player__time {
|
|
577
|
+
font-size: 0.75rem;
|
|
578
|
+
font-variant-numeric: tabular-nums;
|
|
579
|
+
color: var(--vocasync-text-muted);
|
|
580
|
+
min-width: 2.5rem;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
.vocasync-mini-player__close-btn {
|
|
584
|
+
display: flex;
|
|
585
|
+
align-items: center;
|
|
586
|
+
justify-content: center;
|
|
587
|
+
width: 1.5rem;
|
|
588
|
+
height: 1.5rem;
|
|
589
|
+
color: var(--vocasync-text-faint);
|
|
590
|
+
background: transparent;
|
|
591
|
+
border: none;
|
|
592
|
+
border-radius: 50%;
|
|
593
|
+
cursor: pointer;
|
|
594
|
+
transition: color var(--vocasync-transition-fast);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
.vocasync-mini-player__close-btn:hover {
|
|
598
|
+
color: var(--vocasync-text);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
.vocasync-mini-player__close-btn svg {
|
|
602
|
+
width: 1rem;
|
|
603
|
+
height: 1rem;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
/* Desktop: constrain mini player width */
|
|
607
|
+
@media (min-width: 640px) {
|
|
608
|
+
.vocasync-mini-player {
|
|
609
|
+
left: auto;
|
|
610
|
+
right: var(--vocasync-mini-offset);
|
|
611
|
+
max-width: 20rem;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/* ========================================
|
|
616
|
+
* MATH SPEECH (hidden visually, accessible to highlighter)
|
|
617
|
+
* ======================================== */
|
|
618
|
+
:global(.vocasync-math-speech) {
|
|
619
|
+
position: absolute !important;
|
|
620
|
+
width: 1px !important;
|
|
621
|
+
height: 1px !important;
|
|
622
|
+
padding: 0 !important;
|
|
623
|
+
margin: -1px !important;
|
|
624
|
+
overflow: hidden !important;
|
|
625
|
+
clip: rect(0, 0, 0, 0) !important;
|
|
626
|
+
white-space: nowrap !important;
|
|
627
|
+
border: 0 !important;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/* Hide KaTeX HTML fallback rendering (keep MathML for native browser rendering) */
|
|
631
|
+
:global(.katex-html) {
|
|
632
|
+
position: absolute !important;
|
|
633
|
+
width: 1px !important;
|
|
634
|
+
height: 1px !important;
|
|
635
|
+
padding: 0 !important;
|
|
636
|
+
margin: -1px !important;
|
|
637
|
+
overflow: hidden !important;
|
|
638
|
+
clip: rect(0, 0, 0, 0) !important;
|
|
639
|
+
white-space: nowrap !important;
|
|
640
|
+
border: 0 !important;
|
|
641
|
+
}
|
|
642
|
+
</style>
|
|
643
|
+
|
|
644
|
+
<script define:vars={{ playerId, audioId, slug, articleSelector, enableHighlighting, enableMiniPlayer, trailLength }}>
|
|
645
|
+
// Self-invoking function to avoid global scope pollution
|
|
646
|
+
(function() {
|
|
647
|
+
const player = document.getElementById(playerId);
|
|
648
|
+
const audio = document.getElementById(audioId);
|
|
649
|
+
const miniPlayer = enableMiniPlayer ? document.getElementById(`${playerId}-mini`) : null;
|
|
650
|
+
|
|
651
|
+
if (!player || !audio) return;
|
|
652
|
+
|
|
653
|
+
// State
|
|
654
|
+
let isPlaying = false;
|
|
655
|
+
let isMiniVisible = false;
|
|
656
|
+
let animationFrame = null;
|
|
657
|
+
let miniDismissed = false;
|
|
658
|
+
let highlightingEnabled = enableHighlighting;
|
|
659
|
+
|
|
660
|
+
// DOM elements
|
|
661
|
+
const loadingEl = player.querySelector('[data-state="loading"]');
|
|
662
|
+
const placeholderEl = player.querySelector('[data-state="no-audio"]');
|
|
663
|
+
const controlsEl = player.querySelector('[data-state="ready"]');
|
|
664
|
+
const playBtn = player.querySelector('[data-action="play-pause"]');
|
|
665
|
+
const progressInput = player.querySelector('[data-action="seek"]');
|
|
666
|
+
const volumeInput = player.querySelector('[data-action="volume"]');
|
|
667
|
+
const muteBtn = player.querySelector('[data-action="mute"]');
|
|
668
|
+
const speedBtn = player.querySelector('[data-action="speed"]');
|
|
669
|
+
const speedMenu = player.querySelector('.vocasync-player__speed-menu');
|
|
670
|
+
const highlightBtn = player.querySelector('[data-action="toggle-highlighting"]');
|
|
671
|
+
const currentTimeEl = player.querySelector('[data-time="current"]');
|
|
672
|
+
const durationTimeEl = player.querySelector('[data-time="duration"]');
|
|
673
|
+
|
|
674
|
+
// Format time as M:SS
|
|
675
|
+
function formatTime(seconds) {
|
|
676
|
+
if (!seconds || !isFinite(seconds)) return '0:00';
|
|
677
|
+
const m = Math.floor(seconds / 60);
|
|
678
|
+
const s = Math.floor(seconds % 60);
|
|
679
|
+
return `${m}:${s.toString().padStart(2, '0')}`;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
// Update play/pause button icon
|
|
683
|
+
function updatePlayButton(playing) {
|
|
684
|
+
const playIcon = player.querySelector('.vocasync-icon--play');
|
|
685
|
+
const pauseIcon = player.querySelector('.vocasync-icon--pause');
|
|
686
|
+
if (playIcon && pauseIcon) {
|
|
687
|
+
playIcon.hidden = playing;
|
|
688
|
+
pauseIcon.hidden = !playing;
|
|
689
|
+
playBtn.setAttribute('aria-label', playing ? 'Pause' : 'Play');
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
// Update mini player too
|
|
693
|
+
if (miniPlayer) {
|
|
694
|
+
const miniPlayIcon = miniPlayer.querySelector('.vocasync-icon--play');
|
|
695
|
+
const miniPauseIcon = miniPlayer.querySelector('.vocasync-icon--pause');
|
|
696
|
+
if (miniPlayIcon && miniPauseIcon) {
|
|
697
|
+
miniPlayIcon.hidden = playing;
|
|
698
|
+
miniPauseIcon.hidden = !playing;
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
// Update volume icon
|
|
704
|
+
function updateVolumeIcon(muted) {
|
|
705
|
+
const highIcon = player.querySelector('.vocasync-icon--volume-high');
|
|
706
|
+
const muteIcon = player.querySelector('.vocasync-icon--volume-mute');
|
|
707
|
+
if (highIcon && muteIcon) {
|
|
708
|
+
highIcon.hidden = muted;
|
|
709
|
+
muteIcon.hidden = !muted;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
// Update highlighting toggle button
|
|
714
|
+
function updateHighlightButton() {
|
|
715
|
+
if (!highlightBtn) return;
|
|
716
|
+
const onIcon = highlightBtn.querySelector('.vocasync-icon--highlight-on');
|
|
717
|
+
const offIcon = highlightBtn.querySelector('.vocasync-icon--highlight-off');
|
|
718
|
+
if (onIcon && offIcon) {
|
|
719
|
+
onIcon.hidden = !highlightingEnabled;
|
|
720
|
+
offIcon.hidden = highlightingEnabled;
|
|
721
|
+
}
|
|
722
|
+
highlightBtn.setAttribute('data-highlighting', highlightingEnabled ? 'on' : 'off');
|
|
723
|
+
highlightBtn.setAttribute('aria-label', highlightingEnabled ? 'Disable word highlighting' : 'Enable word highlighting');
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
// Word highlighting state (populated from DOM)
|
|
727
|
+
let wordEls = [];
|
|
728
|
+
let starts = [];
|
|
729
|
+
let ends = [];
|
|
730
|
+
let activeIndex = -1;
|
|
731
|
+
|
|
732
|
+
// Initialize word highlighting from DOM elements
|
|
733
|
+
function initWordHighlighting() {
|
|
734
|
+
const article = document.querySelector(articleSelector);
|
|
735
|
+
if (!article) return false;
|
|
736
|
+
|
|
737
|
+
wordEls = Array.from(article.querySelectorAll('.vocasync-word[data-start][data-end]'));
|
|
738
|
+
if (!wordEls.length) return false;
|
|
739
|
+
|
|
740
|
+
starts = [];
|
|
741
|
+
ends = [];
|
|
742
|
+
for (let i = 0; i < wordEls.length; i++) {
|
|
743
|
+
starts[i] = Number(wordEls[i].dataset.start || '0');
|
|
744
|
+
ends[i] = Number(wordEls[i].dataset.end || '0');
|
|
745
|
+
if (!(ends[i] >= starts[i])) ends[i] = starts[i] + 0.0001;
|
|
746
|
+
}
|
|
747
|
+
return true;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
// Binary search: find index of word for current time
|
|
751
|
+
function idxForTime(t) {
|
|
752
|
+
if (!wordEls.length) return -1;
|
|
753
|
+
let lo = 0, hi = wordEls.length - 1, ans = -1;
|
|
754
|
+
while (lo <= hi) {
|
|
755
|
+
const mid = (lo + hi) >> 1;
|
|
756
|
+
if (starts[mid] <= t) { ans = mid; lo = mid + 1; } else { hi = mid - 1; }
|
|
757
|
+
}
|
|
758
|
+
if (ans >= 0 && t >= ends[ans] && ans + 1 < wordEls.length) ans++;
|
|
759
|
+
// Only return if we're actually within the word's time range
|
|
760
|
+
if (ans >= 0 && t >= starts[ans] && t < ends[ans]) return ans;
|
|
761
|
+
return ans;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
// Clear all highlights
|
|
765
|
+
function clearHighlights() {
|
|
766
|
+
if (activeIndex >= 0 && activeIndex < wordEls.length) {
|
|
767
|
+
wordEls[activeIndex].removeAttribute('data-active');
|
|
768
|
+
for (let j = 1; j <= trailLength; j++) {
|
|
769
|
+
const k = activeIndex - j;
|
|
770
|
+
if (k >= 0) wordEls[k].removeAttribute('data-trail');
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
activeIndex = -1;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
// Mark a word as active
|
|
777
|
+
function markActive(i) {
|
|
778
|
+
if (i === activeIndex) return;
|
|
779
|
+
if (activeIndex >= 0 && activeIndex < wordEls.length) {
|
|
780
|
+
wordEls[activeIndex].removeAttribute('data-active');
|
|
781
|
+
for (let j = 1; j <= trailLength; j++) {
|
|
782
|
+
const k = activeIndex - j;
|
|
783
|
+
if (k >= 0) wordEls[k].removeAttribute('data-trail');
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
activeIndex = i;
|
|
787
|
+
if (highlightingEnabled && i >= 0 && i < wordEls.length) {
|
|
788
|
+
wordEls[i].setAttribute('data-active', 'true');
|
|
789
|
+
for (let j = 1; j <= trailLength; j++) {
|
|
790
|
+
const k = i - j;
|
|
791
|
+
if (k >= 0) wordEls[k].setAttribute('data-trail', String(j));
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
// Update word highlighting based on current time
|
|
797
|
+
function updateHighlighting() {
|
|
798
|
+
if (!wordEls.length) return;
|
|
799
|
+
const t = audio.currentTime;
|
|
800
|
+
const i = idxForTime(t);
|
|
801
|
+
if (i !== activeIndex) {
|
|
802
|
+
markActive(i);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
// Animation loop for highlighting
|
|
807
|
+
function startHighlightLoop() {
|
|
808
|
+
function loop() {
|
|
809
|
+
if (isPlaying) {
|
|
810
|
+
updateHighlighting();
|
|
811
|
+
animationFrame = requestAnimationFrame(loop);
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
animationFrame = requestAnimationFrame(loop);
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
function stopHighlightLoop() {
|
|
818
|
+
if (animationFrame) {
|
|
819
|
+
cancelAnimationFrame(animationFrame);
|
|
820
|
+
animationFrame = null;
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
// Toggle highlighting on/off
|
|
825
|
+
function toggleHighlighting() {
|
|
826
|
+
highlightingEnabled = !highlightingEnabled;
|
|
827
|
+
updateHighlightButton();
|
|
828
|
+
if (!highlightingEnabled) {
|
|
829
|
+
clearHighlights();
|
|
830
|
+
} else if (isPlaying) {
|
|
831
|
+
updateHighlighting();
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
// Setup intersection observer for mini player
|
|
836
|
+
function setupMiniPlayer() {
|
|
837
|
+
if (!miniPlayer || !enableMiniPlayer) return;
|
|
838
|
+
|
|
839
|
+
const observer = new IntersectionObserver(
|
|
840
|
+
(entries) => {
|
|
841
|
+
const [entry] = entries;
|
|
842
|
+
const shouldShow = !entry.isIntersecting && isPlaying && !miniDismissed;
|
|
843
|
+
|
|
844
|
+
if (shouldShow && !isMiniVisible) {
|
|
845
|
+
miniPlayer.hidden = false;
|
|
846
|
+
isMiniVisible = true;
|
|
847
|
+
} else if (!shouldShow && isMiniVisible) {
|
|
848
|
+
miniPlayer.hidden = true;
|
|
849
|
+
isMiniVisible = false;
|
|
850
|
+
}
|
|
851
|
+
},
|
|
852
|
+
{ threshold: 0 }
|
|
853
|
+
);
|
|
854
|
+
|
|
855
|
+
observer.observe(player);
|
|
856
|
+
|
|
857
|
+
// Mini player controls
|
|
858
|
+
const miniPlayBtn = miniPlayer.querySelector('[data-action="play-pause"]');
|
|
859
|
+
const miniCloseBtn = miniPlayer.querySelector('[data-action="close-mini"]');
|
|
860
|
+
|
|
861
|
+
miniPlayBtn?.addEventListener('click', togglePlay);
|
|
862
|
+
miniCloseBtn?.addEventListener('click', () => {
|
|
863
|
+
miniDismissed = true;
|
|
864
|
+
miniPlayer.hidden = true;
|
|
865
|
+
isMiniVisible = false;
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
// Update mini player progress
|
|
870
|
+
function updateMiniProgress() {
|
|
871
|
+
if (!miniPlayer) return;
|
|
872
|
+
|
|
873
|
+
const progressBar = miniPlayer.querySelector('[data-progress]');
|
|
874
|
+
const timeEl = miniPlayer.querySelector('[data-time="current"]');
|
|
875
|
+
|
|
876
|
+
if (progressBar) {
|
|
877
|
+
const percent = (audio.currentTime / audio.duration) * 100 || 0;
|
|
878
|
+
progressBar.style.width = `${percent}%`;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
if (timeEl) {
|
|
882
|
+
timeEl.textContent = formatTime(audio.currentTime);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
// Setup click handlers for pre-wrapped words (from rehype plugin)
|
|
887
|
+
function setupWordClickHandlers() {
|
|
888
|
+
const article = document.querySelector(articleSelector);
|
|
889
|
+
if (!article) return;
|
|
890
|
+
|
|
891
|
+
const wordSpans = article.querySelectorAll('.vocasync-word[data-start]');
|
|
892
|
+
wordSpans.forEach((span) => {
|
|
893
|
+
span.style.cursor = 'pointer';
|
|
894
|
+
span.addEventListener('click', () => {
|
|
895
|
+
const start = parseFloat(span.getAttribute('data-start') || '0');
|
|
896
|
+
audio.currentTime = start;
|
|
897
|
+
if (audio.paused) {
|
|
898
|
+
audio.play();
|
|
899
|
+
}
|
|
900
|
+
});
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
// Load audio map and initialize
|
|
905
|
+
async function init() {
|
|
906
|
+
try {
|
|
907
|
+
// Get audio data from embedded data attribute
|
|
908
|
+
const audioDataAttr = player.dataset.audioEntry;
|
|
909
|
+
|
|
910
|
+
if (!audioDataAttr) {
|
|
911
|
+
showNoAudio();
|
|
912
|
+
return;
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
let entry;
|
|
916
|
+
try {
|
|
917
|
+
entry = JSON.parse(audioDataAttr);
|
|
918
|
+
} catch {
|
|
919
|
+
showNoAudio();
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
if (!entry || !entry.audioUrl) {
|
|
924
|
+
showNoAudio();
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
// Set audio source
|
|
929
|
+
audio.src = entry.audioUrl;
|
|
930
|
+
|
|
931
|
+
// Initialize word highlighting from DOM spans (from rehype plugin)
|
|
932
|
+
// Defer to DOMContentLoaded since the content div comes after the player in the HTML
|
|
933
|
+
if (enableHighlighting) {
|
|
934
|
+
const initHighlighting = () => {
|
|
935
|
+
initWordHighlighting();
|
|
936
|
+
setupWordClickHandlers();
|
|
937
|
+
};
|
|
938
|
+
if (document.readyState === 'loading') {
|
|
939
|
+
document.addEventListener('DOMContentLoaded', initHighlighting);
|
|
940
|
+
} else {
|
|
941
|
+
// DOM already loaded
|
|
942
|
+
initHighlighting();
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
// Show controls
|
|
947
|
+
showReady();
|
|
948
|
+
|
|
949
|
+
// Setup mini player
|
|
950
|
+
setupMiniPlayer();
|
|
951
|
+
|
|
952
|
+
// Initialize highlight button state
|
|
953
|
+
updateHighlightButton();
|
|
954
|
+
|
|
955
|
+
} catch (error) {
|
|
956
|
+
console.error('VocaSync: Failed to initialize player', error);
|
|
957
|
+
showNoAudio();
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
function showLoading() {
|
|
962
|
+
loadingEl.hidden = false;
|
|
963
|
+
placeholderEl.hidden = true;
|
|
964
|
+
controlsEl.hidden = true;
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
function showNoAudio() {
|
|
968
|
+
loadingEl.hidden = true;
|
|
969
|
+
placeholderEl.hidden = false;
|
|
970
|
+
controlsEl.hidden = true;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
function showReady() {
|
|
974
|
+
loadingEl.hidden = true;
|
|
975
|
+
placeholderEl.hidden = true;
|
|
976
|
+
controlsEl.hidden = false;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
function togglePlay() {
|
|
980
|
+
if (audio.paused) {
|
|
981
|
+
audio.play();
|
|
982
|
+
} else {
|
|
983
|
+
audio.pause();
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
// Event listeners
|
|
988
|
+
playBtn?.addEventListener('click', togglePlay);
|
|
989
|
+
highlightBtn?.addEventListener('click', toggleHighlighting);
|
|
990
|
+
|
|
991
|
+
audio.addEventListener('play', () => {
|
|
992
|
+
isPlaying = true;
|
|
993
|
+
updatePlayButton(true);
|
|
994
|
+
startHighlightLoop();
|
|
995
|
+
miniDismissed = false;
|
|
996
|
+
});
|
|
997
|
+
|
|
998
|
+
audio.addEventListener('pause', () => {
|
|
999
|
+
isPlaying = false;
|
|
1000
|
+
updatePlayButton(false);
|
|
1001
|
+
stopHighlightLoop();
|
|
1002
|
+
});
|
|
1003
|
+
|
|
1004
|
+
audio.addEventListener('ended', () => {
|
|
1005
|
+
isPlaying = false;
|
|
1006
|
+
updatePlayButton(false);
|
|
1007
|
+
stopHighlightLoop();
|
|
1008
|
+
});
|
|
1009
|
+
|
|
1010
|
+
audio.addEventListener('loadedmetadata', () => {
|
|
1011
|
+
durationTimeEl.textContent = formatTime(audio.duration);
|
|
1012
|
+
progressInput.max = audio.duration;
|
|
1013
|
+
});
|
|
1014
|
+
|
|
1015
|
+
audio.addEventListener('timeupdate', () => {
|
|
1016
|
+
currentTimeEl.textContent = formatTime(audio.currentTime);
|
|
1017
|
+
progressInput.value = audio.currentTime;
|
|
1018
|
+
updateMiniProgress();
|
|
1019
|
+
});
|
|
1020
|
+
|
|
1021
|
+
progressInput?.addEventListener('input', () => {
|
|
1022
|
+
audio.currentTime = parseFloat(progressInput.value);
|
|
1023
|
+
});
|
|
1024
|
+
|
|
1025
|
+
volumeInput?.addEventListener('input', () => {
|
|
1026
|
+
audio.volume = parseFloat(volumeInput.value) / 100;
|
|
1027
|
+
updateVolumeIcon(audio.volume === 0);
|
|
1028
|
+
});
|
|
1029
|
+
|
|
1030
|
+
muteBtn?.addEventListener('click', () => {
|
|
1031
|
+
audio.muted = !audio.muted;
|
|
1032
|
+
updateVolumeIcon(audio.muted);
|
|
1033
|
+
});
|
|
1034
|
+
|
|
1035
|
+
speedBtn?.addEventListener('click', () => {
|
|
1036
|
+
speedMenu.hidden = !speedMenu.hidden;
|
|
1037
|
+
});
|
|
1038
|
+
|
|
1039
|
+
speedMenu?.addEventListener('click', (e) => {
|
|
1040
|
+
const btn = e.target.closest('[data-speed]');
|
|
1041
|
+
if (!btn) return;
|
|
1042
|
+
|
|
1043
|
+
const speed = parseFloat(btn.dataset.speed);
|
|
1044
|
+
audio.playbackRate = speed;
|
|
1045
|
+
|
|
1046
|
+
// Update active state
|
|
1047
|
+
speedMenu.querySelectorAll('[data-speed]').forEach(b => b.removeAttribute('data-active'));
|
|
1048
|
+
btn.setAttribute('data-active', '');
|
|
1049
|
+
|
|
1050
|
+
// Update label
|
|
1051
|
+
const label = player.querySelector('[data-speed-label]');
|
|
1052
|
+
if (label) label.textContent = `${speed}x`;
|
|
1053
|
+
|
|
1054
|
+
speedMenu.hidden = true;
|
|
1055
|
+
});
|
|
1056
|
+
|
|
1057
|
+
// Close speed menu on outside click
|
|
1058
|
+
document.addEventListener('click', (e) => {
|
|
1059
|
+
if (!speedBtn?.contains(e.target) && !speedMenu?.contains(e.target)) {
|
|
1060
|
+
if (speedMenu) speedMenu.hidden = true;
|
|
1061
|
+
}
|
|
1062
|
+
});
|
|
1063
|
+
|
|
1064
|
+
// Keyboard shortcuts
|
|
1065
|
+
player.addEventListener('keydown', (e) => {
|
|
1066
|
+
// Don't handle if focus is on an input
|
|
1067
|
+
if (e.target.tagName === 'INPUT') return;
|
|
1068
|
+
|
|
1069
|
+
switch (e.code) {
|
|
1070
|
+
case 'Space':
|
|
1071
|
+
e.preventDefault();
|
|
1072
|
+
togglePlay();
|
|
1073
|
+
break;
|
|
1074
|
+
case 'ArrowLeft':
|
|
1075
|
+
e.preventDefault();
|
|
1076
|
+
audio.currentTime = Math.max(0, audio.currentTime - 5);
|
|
1077
|
+
break;
|
|
1078
|
+
case 'ArrowRight':
|
|
1079
|
+
e.preventDefault();
|
|
1080
|
+
audio.currentTime = Math.min(audio.duration || 0, audio.currentTime + 5);
|
|
1081
|
+
break;
|
|
1082
|
+
case 'KeyM':
|
|
1083
|
+
e.preventDefault();
|
|
1084
|
+
audio.muted = !audio.muted;
|
|
1085
|
+
updateVolumeIcon(audio.muted);
|
|
1086
|
+
break;
|
|
1087
|
+
case 'KeyH':
|
|
1088
|
+
e.preventDefault();
|
|
1089
|
+
toggleHighlighting();
|
|
1090
|
+
break;
|
|
1091
|
+
}
|
|
1092
|
+
});
|
|
1093
|
+
|
|
1094
|
+
// Initialize
|
|
1095
|
+
init();
|
|
1096
|
+
})();
|
|
1097
|
+
</script>
|