@vocasync/astro 0.1.9 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -41
- package/dist/api/client.d.ts +63 -50
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +132 -145
- 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 +7 -7
- package/dist/cli.js.map +1 -1
- package/dist/components/AudioPlayer.astro +136 -137
- package/dist/config/schema.d.ts +21 -20
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +15 -4
- package/dist/config/schema.js.map +1 -1
- package/dist/core/audio-map.js +1 -1
- package/dist/core/speech-builder.d.ts +10 -7
- package/dist/core/speech-builder.d.ts.map +1 -1
- package/dist/core/speech-builder.js +73 -168
- package/dist/core/speech-builder.js.map +1 -1
- package/dist/core/spoken-form.d.ts +52 -0
- package/dist/core/spoken-form.d.ts.map +1 -0
- package/dist/core/spoken-form.js +279 -0
- package/dist/core/spoken-form.js.map +1 -0
- package/dist/lib/latex-to-speech/index.d.ts +9 -2
- package/dist/lib/latex-to-speech/index.d.ts.map +1 -1
- package/dist/lib/latex-to-speech/index.js +20 -22
- package/dist/lib/latex-to-speech/index.js.map +1 -1
- package/dist/lib/latex-to-speech/speak.d.ts +13 -0
- package/dist/lib/latex-to-speech/speak.d.ts.map +1 -0
- package/dist/lib/latex-to-speech/speak.js +47 -0
- package/dist/lib/latex-to-speech/speak.js.map +1 -0
- package/dist/rehype/audio-words.d.ts +14 -24
- package/dist/rehype/audio-words.d.ts.map +1 -1
- package/dist/rehype/audio-words.js +131 -252
- package/dist/rehype/audio-words.js.map +1 -1
- package/dist/rehype/index.d.ts +1 -2
- package/dist/rehype/index.d.ts.map +1 -1
- package/dist/rehype/index.js +0 -1
- package/dist/rehype/index.js.map +1 -1
- package/dist/rehype/rehype-math-speech.d.ts +26 -10
- package/dist/rehype/rehype-math-speech.d.ts.map +1 -1
- package/dist/rehype/rehype-math-speech.js +59 -92
- package/dist/rehype/rehype-math-speech.js.map +1 -1
- package/dist/rehype/shared.d.ts +9 -0
- package/dist/rehype/shared.d.ts.map +1 -0
- package/dist/rehype/shared.js +31 -0
- package/dist/rehype/shared.js.map +1 -0
- package/dist/sync/orchestrator.d.ts +4 -22
- package/dist/sync/orchestrator.d.ts.map +1 -1
- package/dist/sync/orchestrator.js +123 -123
- package/dist/sync/orchestrator.js.map +1 -1
- package/dist/types/index.d.ts +82 -46
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +14 -11
- package/src/api/client.ts +175 -190
- package/src/api/index.ts +8 -1
- package/src/cli.ts +7 -14
- package/src/components/AudioPlayer.astro +136 -137
- package/src/config/schema.ts +15 -4
- package/src/core/audio-map.ts +1 -1
- package/src/core/speech-builder.ts +75 -192
- package/src/core/spoken-form.ts +298 -0
- package/src/lib/latex-to-speech/index.ts +32 -22
- package/src/lib/latex-to-speech/speak.ts +55 -0
- package/src/rehype/audio-words.ts +145 -307
- package/src/rehype/index.ts +1 -2
- package/src/rehype/rehype-math-speech.ts +64 -117
- package/src/rehype/shared.ts +36 -0
- package/src/sync/orchestrator.ts +150 -157
- package/src/types/index.ts +85 -47
- package/src/types/modules.d.ts +5 -2
- package/dist/rehype/remark-math-speech.d.ts +0 -13
- package/dist/rehype/remark-math-speech.d.ts.map +0 -1
- package/dist/rehype/remark-math-speech.js +0 -26
- package/dist/rehype/remark-math-speech.js.map +0 -1
- package/src/rehype/remark-math-speech.ts +0 -31
|
@@ -1,280 +1,159 @@
|
|
|
1
|
-
import { execFileSync } from "node:child_process";
|
|
2
|
-
import { readFileSync } from "node:fs";
|
|
3
|
-
import { resolve } from "node:path";
|
|
4
1
|
import { visitParents } from "unist-util-visit-parents";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Fetch alignment data from URL (synchronously using a worker thread approach).
|
|
29
|
-
* Since rehype plugins must be synchronous, we use a sync HTTP request.
|
|
30
|
-
* @param alignmentUrl - The base alignment URL
|
|
31
|
-
* @param slug - The content slug for caching
|
|
32
|
-
* @param publishableKey - Optional publishable key for authentication
|
|
33
|
-
*/
|
|
34
|
-
function fetchAlignmentSync(alignmentUrl, slug, publishableKey) {
|
|
35
|
-
// Check cache first
|
|
36
|
-
if (alignmentCache.has(slug)) {
|
|
37
|
-
return alignmentCache.get(slug) ?? null;
|
|
38
|
-
}
|
|
39
|
-
try {
|
|
40
|
-
// Build the URL with publishable key if provided
|
|
41
|
-
let fetchUrl = alignmentUrl;
|
|
42
|
-
if (publishableKey) {
|
|
43
|
-
const url = new URL(alignmentUrl);
|
|
44
|
-
url.searchParams.set("pk", publishableKey);
|
|
45
|
-
fetchUrl = url.toString();
|
|
46
|
-
}
|
|
47
|
-
// Use execFileSync with curl to make a synchronous HTTP request
|
|
48
|
-
// execFileSync avoids shell invocation, preventing command injection
|
|
49
|
-
// Note: -L flag follows redirects (required for vocasync.io signed URLs)
|
|
50
|
-
const result = execFileSync("curl", ["-sL", fetchUrl], {
|
|
51
|
-
encoding: "utf-8",
|
|
52
|
-
timeout: 30000,
|
|
53
|
-
});
|
|
54
|
-
const data = JSON.parse(result);
|
|
55
|
-
// The alignment response contains a words array
|
|
56
|
-
const words = data.words;
|
|
57
|
-
if (words && Array.isArray(words)) {
|
|
58
|
-
alignmentCache.set(slug, words);
|
|
59
|
-
return words;
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
// Failed to fetch - return null
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
2
|
+
import { spokenTokenCount } from "../core/spoken-form.js";
|
|
3
|
+
import { loadAudioMapSync, resolveSlug } from "./shared.js";
|
|
4
|
+
// Matches a visible "word": letters/digits/currency/percent, with intra-word
|
|
5
|
+
// apostrophes. Currency (\p{Sc}) and % are kept attached to their number so
|
|
6
|
+
// "$50" and "50%" stay single tokens whose spokenTokenCount matches the
|
|
7
|
+
// transcript ("fifty dollar", "fifty percent"). Comma-grouped numbers
|
|
8
|
+
// (e.g. "1,000,000") are a known limitation — author numbers without commas.
|
|
9
|
+
const WORD_PATTERN = /[\p{L}\p{N}\p{Sc}%]+(?:['’][\p{L}\p{N}\p{Sc}%]+)*/gu;
|
|
10
|
+
const SKIP_TAGS = new Set([
|
|
11
|
+
"pre",
|
|
12
|
+
"code",
|
|
13
|
+
"script",
|
|
14
|
+
"style",
|
|
15
|
+
"textarea",
|
|
16
|
+
"svg",
|
|
17
|
+
"math",
|
|
18
|
+
"mjx-container",
|
|
19
|
+
"img",
|
|
20
|
+
"figcaption",
|
|
21
|
+
]);
|
|
22
|
+
const SKIP_CLASSES = new Set(["katex", "katex-mathml", "katex-html"]);
|
|
68
23
|
/**
|
|
69
|
-
* Rehype plugin that wraps
|
|
70
|
-
*
|
|
71
|
-
* For each text node in the document, this plugin:
|
|
72
|
-
* 1. Tokenizes the text into words
|
|
73
|
-
* 2. Matches words against alignment data
|
|
74
|
-
* 3. Wraps matched words in <span> elements with data-start and data-end attributes
|
|
24
|
+
* Rehype plugin that wraps each visible word in
|
|
25
|
+
* `<span class="vocasync-word" data-i="N" data-n="K">…</span>`:
|
|
75
26
|
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* import { rehypeAudioWords } from "@vocasync/astro/rehype";
|
|
27
|
+
* data-i = the word's starting index in the alignment word stream
|
|
28
|
+
* (the normalisedSpeechtext POSTed to VocaSync).
|
|
29
|
+
* data-n = how many alignment tokens this visible word expands to
|
|
30
|
+
* (via spokenTokenCount): "$50" -> 2, "1995" -> 6, words -> 1.
|
|
81
31
|
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
* ]
|
|
87
|
-
* }
|
|
88
|
-
* });
|
|
89
|
-
* ```
|
|
32
|
+
* No alignment data is fetched here — tokenization is deterministic and runs
|
|
33
|
+
* the same `spokenTokenCount` used to build the transcript, so indices line
|
|
34
|
+
* up token-for-token. Math containers carrying `data-speech` (attached by
|
|
35
|
+
* rehypeMathSpeech) are wrapped as a single unit with their token count.
|
|
90
36
|
*/
|
|
91
37
|
const rehypeAudioWords = (options = {}) => {
|
|
92
38
|
const { audioMapPath = ".vocasync/audio-map.json", classPrefix = "vocasync", collectionName = "articles", } = options;
|
|
39
|
+
const wordClass = `${classPrefix}-word`;
|
|
93
40
|
return (tree, file) => {
|
|
94
|
-
// Load audio map (cached after first load)
|
|
95
41
|
const audioMap = loadAudioMapSync(audioMapPath);
|
|
96
|
-
if (!audioMap)
|
|
97
|
-
return;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return; // No file path, skip processing
|
|
105
|
-
}
|
|
106
|
-
// Normalize path separators
|
|
107
|
-
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
108
|
-
// Try to extract slug from collection path
|
|
109
|
-
// Pattern: /src/content/{collectionName}/{slug}.md or .mdx
|
|
110
|
-
const collectionPattern = new RegExp(`/content/${collectionName}/([^/]+)\\.(md|mdx)$`);
|
|
111
|
-
const match = normalizedPath.match(collectionPattern);
|
|
112
|
-
let slug;
|
|
113
|
-
if (match) {
|
|
114
|
-
slug = match[1];
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
// Fallback: just get the filename without extension
|
|
118
|
-
const filenameMatch = normalizedPath.match(/\/([^/]+)\.(md|mdx)$/);
|
|
119
|
-
if (filenameMatch) {
|
|
120
|
-
slug = filenameMatch[1];
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
if (!slug) {
|
|
124
|
-
return; // No slug, skip processing
|
|
125
|
-
}
|
|
126
|
-
// Get alignment URL for this slug from audio map
|
|
127
|
-
const entry = audioMap.entries[slug];
|
|
128
|
-
if (!entry?.alignmentUrl) {
|
|
129
|
-
return; // No alignment URL, skip
|
|
130
|
-
}
|
|
131
|
-
// Fetch alignment words from URL with publishable key
|
|
132
|
-
const words = fetchAlignmentSync(entry.alignmentUrl, slug, entry.publishableKey);
|
|
133
|
-
if (!words || words.length === 0) {
|
|
134
|
-
return; // No alignment data, skip
|
|
135
|
-
}
|
|
136
|
-
// Track word index as we process text nodes
|
|
137
|
-
let wordIndex = 0;
|
|
138
|
-
// Process all text nodes in the document
|
|
139
|
-
visitParents(tree, "text", (node, ancestors) => {
|
|
140
|
-
const textNode = node;
|
|
42
|
+
if (!audioMap)
|
|
43
|
+
return;
|
|
44
|
+
const slug = resolveSlug(file, collectionName);
|
|
45
|
+
if (!slug || !audioMap.entries[slug])
|
|
46
|
+
return; // only wrap posts that have audio
|
|
47
|
+
let nextIndex = 0;
|
|
48
|
+
const replacements = [];
|
|
49
|
+
visitParents(tree, (node) => node.type === "text" || (node.type === "element" && hasDataSpeech(node)), (node, ancestors) => {
|
|
141
50
|
const parent = ancestors[ancestors.length - 1];
|
|
142
|
-
|
|
143
|
-
|
|
51
|
+
if (!parent)
|
|
52
|
+
return;
|
|
53
|
+
// Math container with attached spoken form -> wrap as one unit.
|
|
54
|
+
if (node.type === "element") {
|
|
55
|
+
const speech = node.properties?.dataSpeech;
|
|
56
|
+
if (typeof speech !== "string" || !speech)
|
|
57
|
+
return;
|
|
58
|
+
const count = spokenTokenCount(speech);
|
|
59
|
+
if (count === 0)
|
|
60
|
+
return;
|
|
61
|
+
const index = parent.children.indexOf(node);
|
|
62
|
+
if (index === -1)
|
|
63
|
+
return;
|
|
64
|
+
replacements.push({
|
|
65
|
+
parent,
|
|
66
|
+
index,
|
|
67
|
+
nodes: [wrapSpan([node], nextIndex, count, wordClass)],
|
|
68
|
+
});
|
|
69
|
+
nextIndex += count;
|
|
144
70
|
return;
|
|
145
71
|
}
|
|
146
|
-
//
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
if (
|
|
157
|
-
|
|
72
|
+
// Text node -> wrap each word, skipping non-textual ancestors.
|
|
73
|
+
if (isSkipped(ancestors))
|
|
74
|
+
return;
|
|
75
|
+
const text = node.value;
|
|
76
|
+
if (!text)
|
|
77
|
+
return;
|
|
78
|
+
const matches = Array.from(text.matchAll(WORD_PATTERN));
|
|
79
|
+
if (matches.length === 0)
|
|
80
|
+
return;
|
|
81
|
+
const index = parent.children.indexOf(node);
|
|
82
|
+
if (index === -1)
|
|
83
|
+
return;
|
|
84
|
+
const out = [];
|
|
85
|
+
let cursor = 0;
|
|
86
|
+
for (const m of matches) {
|
|
87
|
+
const start = m.index ?? 0;
|
|
88
|
+
const end = start + m[0].length;
|
|
89
|
+
if (start > cursor)
|
|
90
|
+
out.push({ type: "text", value: text.slice(cursor, start) });
|
|
91
|
+
const count = spokenTokenCount(m[0]);
|
|
92
|
+
if (count > 0) {
|
|
93
|
+
out.push(wrapText(m[0], nextIndex, count, wordClass));
|
|
94
|
+
nextIndex += count;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
out.push({ type: "text", value: m[0] });
|
|
98
|
+
}
|
|
99
|
+
cursor = end;
|
|
158
100
|
}
|
|
101
|
+
if (cursor < text.length)
|
|
102
|
+
out.push({ type: "text", value: text.slice(cursor) });
|
|
103
|
+
replacements.push({ parent, index, nodes: out });
|
|
159
104
|
});
|
|
105
|
+
// Apply in reverse so earlier indices stay valid.
|
|
106
|
+
for (let i = replacements.length - 1; i >= 0; i--) {
|
|
107
|
+
const r = replacements[i];
|
|
108
|
+
r.parent.children.splice(r.index, 1, ...r.nodes);
|
|
109
|
+
}
|
|
160
110
|
};
|
|
161
111
|
};
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
112
|
+
function wrapText(word, dataI, dataN, wordClass) {
|
|
113
|
+
return {
|
|
114
|
+
type: "element",
|
|
115
|
+
tagName: "span",
|
|
116
|
+
properties: {
|
|
117
|
+
className: [wordClass],
|
|
118
|
+
"data-i": String(dataI),
|
|
119
|
+
"data-n": String(dataN),
|
|
120
|
+
},
|
|
121
|
+
children: [{ type: "text", value: word }],
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function wrapSpan(children, dataI, dataN, wordClass) {
|
|
125
|
+
return {
|
|
126
|
+
type: "element",
|
|
127
|
+
tagName: "span",
|
|
128
|
+
properties: {
|
|
129
|
+
className: [wordClass],
|
|
130
|
+
"data-i": String(dataI),
|
|
131
|
+
"data-n": String(dataN),
|
|
132
|
+
},
|
|
133
|
+
children,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function hasDataSpeech(node) {
|
|
137
|
+
const props = node.properties ?? {};
|
|
138
|
+
return typeof props.dataSpeech === "string" && props.dataSpeech.length > 0;
|
|
139
|
+
}
|
|
140
|
+
function isSkipped(ancestors) {
|
|
168
141
|
for (const ancestor of ancestors) {
|
|
169
|
-
if ("tagName" in ancestor
|
|
142
|
+
if (!("tagName" in ancestor))
|
|
143
|
+
continue;
|
|
144
|
+
if (SKIP_TAGS.has(ancestor.tagName))
|
|
170
145
|
return true;
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const classes = Array.isArray(ancestor.properties.className)
|
|
175
|
-
? ancestor.properties.className
|
|
176
|
-
: [ancestor.properties.className];
|
|
146
|
+
const className = ancestor.properties?.className;
|
|
147
|
+
if (className) {
|
|
148
|
+
const classes = Array.isArray(className) ? className : [className];
|
|
177
149
|
for (const cls of classes) {
|
|
178
|
-
if (typeof cls === "string" &&
|
|
150
|
+
if (typeof cls === "string" && SKIP_CLASSES.has(cls))
|
|
179
151
|
return true;
|
|
180
|
-
}
|
|
181
152
|
}
|
|
182
153
|
}
|
|
183
154
|
}
|
|
184
155
|
return false;
|
|
185
156
|
}
|
|
186
|
-
/**
|
|
187
|
-
* Process a text node and create annotated nodes.
|
|
188
|
-
*/
|
|
189
|
-
function processTextNode(text, words, startIndex, classPrefix) {
|
|
190
|
-
const nodes = [];
|
|
191
|
-
let wordIndex = startIndex;
|
|
192
|
-
let lastEnd = 0;
|
|
193
|
-
// Regex to match words (similar to word boundaries)
|
|
194
|
-
const wordPattern = /[\p{L}\p{N}'']+/gu;
|
|
195
|
-
let match;
|
|
196
|
-
// biome-ignore lint/suspicious/noAssignInExpressions: regex exec loop requires assignment in condition
|
|
197
|
-
while ((match = wordPattern.exec(text)) !== null) {
|
|
198
|
-
const word = match[0];
|
|
199
|
-
const start = match.index;
|
|
200
|
-
// Add text before this word
|
|
201
|
-
if (start > lastEnd) {
|
|
202
|
-
nodes.push({
|
|
203
|
-
type: "text",
|
|
204
|
-
value: text.slice(lastEnd, start),
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
// Try to match with alignment data - look ahead if needed
|
|
208
|
-
const normalizedWord = normalizeWord(word);
|
|
209
|
-
let matchedIndex = -1;
|
|
210
|
-
let matchedAligned = null;
|
|
211
|
-
// Search forward from current index to find matching word
|
|
212
|
-
// Look ahead up to 10 words to handle minor ordering differences
|
|
213
|
-
const maxLookahead = 10;
|
|
214
|
-
for (let i = wordIndex; i < Math.min(wordIndex + maxLookahead, words.length); i++) {
|
|
215
|
-
const candidate = words[i];
|
|
216
|
-
if (normalizeWord(candidate.word) === normalizedWord) {
|
|
217
|
-
matchedIndex = i;
|
|
218
|
-
matchedAligned = candidate;
|
|
219
|
-
break;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
if (matchedAligned && matchedIndex !== -1) {
|
|
223
|
-
// Create annotated span
|
|
224
|
-
nodes.push({
|
|
225
|
-
type: "element",
|
|
226
|
-
tagName: "span",
|
|
227
|
-
properties: {
|
|
228
|
-
className: [`${classPrefix}-word`],
|
|
229
|
-
"data-word-index": matchedIndex,
|
|
230
|
-
"data-start": matchedAligned.start.toFixed(3),
|
|
231
|
-
"data-end": matchedAligned.end.toFixed(3),
|
|
232
|
-
},
|
|
233
|
-
children: [{ type: "text", value: word }],
|
|
234
|
-
});
|
|
235
|
-
wordIndex = matchedIndex + 1;
|
|
236
|
-
}
|
|
237
|
-
else {
|
|
238
|
-
// No match, just add as text
|
|
239
|
-
nodes.push({
|
|
240
|
-
type: "text",
|
|
241
|
-
value: word,
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
lastEnd = start + word.length;
|
|
245
|
-
}
|
|
246
|
-
// Add remaining text
|
|
247
|
-
if (lastEnd < text.length) {
|
|
248
|
-
nodes.push({
|
|
249
|
-
type: "text",
|
|
250
|
-
value: text.slice(lastEnd),
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
// Merge adjacent text nodes
|
|
254
|
-
const merged = [];
|
|
255
|
-
for (const node of nodes) {
|
|
256
|
-
const last = merged[merged.length - 1];
|
|
257
|
-
if (node.type === "text" && last?.type === "text") {
|
|
258
|
-
last.value += node.value;
|
|
259
|
-
}
|
|
260
|
-
else {
|
|
261
|
-
merged.push(node);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
return {
|
|
265
|
-
nodes: merged,
|
|
266
|
-
nextWordIndex: wordIndex,
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Normalize a word for comparison (lowercase, remove punctuation).
|
|
271
|
-
*/
|
|
272
|
-
function normalizeWord(word) {
|
|
273
|
-
return word
|
|
274
|
-
.toLowerCase()
|
|
275
|
-
.replace(/[^\p{L}\p{N}]/gu, "")
|
|
276
|
-
.trim();
|
|
277
|
-
}
|
|
278
157
|
export default rehypeAudioWords;
|
|
279
158
|
export { rehypeAudioWords };
|
|
280
159
|
//# sourceMappingURL=audio-words.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audio-words.js","sourceRoot":"","sources":["../../src/rehype/audio-words.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"audio-words.js","sourceRoot":"","sources":["../../src/rehype/audio-words.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAuB5D,6EAA6E;AAC7E,4EAA4E;AAC5E,wEAAwE;AACxE,sEAAsE;AACtE,6EAA6E;AAC7E,MAAM,YAAY,GAAG,qDAAqD,CAAC;AAE3E,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC;IACxB,KAAK;IACL,MAAM;IACN,QAAQ;IACR,OAAO;IACP,UAAU;IACV,KAAK;IACL,MAAM;IACN,eAAe;IACf,KAAK;IACL,YAAY;CACb,CAAC,CAAC;AACH,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC,CAAC;AAEtE;;;;;;;;;;;;;GAaG;AACH,MAAM,gBAAgB,GAA6C,CAAC,OAAO,GAAG,EAAE,EAAE,EAAE;IAClF,MAAM,EACJ,YAAY,GAAG,0BAA0B,EACzC,WAAW,GAAG,UAAU,EACxB,cAAc,GAAG,UAAU,GAC5B,GAAG,OAAO,CAAC;IACZ,MAAM,SAAS,GAAG,GAAG,WAAW,OAAO,CAAC;IAExC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;QACpB,MAAM,QAAQ,GAAG,gBAAgB,CAAC,YAAY,CAAC,CAAC;QAChD,IAAI,CAAC,QAAQ;YAAE,OAAO;QAEt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-words.js";
|
|
2
2
|
export type { RehypeAudioWordsOptions } from "./audio-words.js";
|
|
3
3
|
export { default as rehypeMathSpeech } from "./rehype-math-speech.js";
|
|
4
|
-
export {
|
|
5
|
-
export type { MathSpeechEntry } from "./remark-math-speech.js";
|
|
4
|
+
export type { RehypeMathSpeechOptions } from "./rehype-math-speech.js";
|
|
6
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rehype/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,YAAY,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAEhE,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACtE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rehype/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,YAAY,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAEhE,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACtE,YAAY,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/rehype/index.js
CHANGED
package/dist/rehype/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rehype/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAG7D,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rehype/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAG7D,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -1,18 +1,34 @@
|
|
|
1
1
|
import type { Root } from "hast";
|
|
2
|
-
|
|
3
|
-
interface RehypeMathSpeechOptions {
|
|
2
|
+
export interface RehypeMathSpeechOptions {
|
|
4
3
|
/**
|
|
5
|
-
*
|
|
6
|
-
* @default "
|
|
4
|
+
* Path to the audio map JSON file (absolute or relative to project root).
|
|
5
|
+
* @default ".vocasync/audio-map.json"
|
|
7
6
|
*/
|
|
8
|
-
|
|
7
|
+
audioMapPath?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Content collection folder name used to extract slugs.
|
|
10
|
+
* @default "articles"
|
|
11
|
+
*/
|
|
12
|
+
collectionName?: string;
|
|
9
13
|
}
|
|
10
14
|
/**
|
|
11
|
-
* Rehype plugin that
|
|
12
|
-
*
|
|
15
|
+
* Rehype plugin that attaches each math expression's spoken form as a
|
|
16
|
+
* `data-speech` attribute, so rehypeAudioWords can wrap the whole expression
|
|
17
|
+
* as one highlight unit whose `data-n` is the spoken token count.
|
|
18
|
+
*
|
|
19
|
+
* The spoken forms are read from the audio map (where `vocasync sync` stored
|
|
20
|
+
* them, keyed by latex) — math-to-speech runs only in the CLI, never here.
|
|
21
|
+
* This guarantees the math tokens match what was synthesized AND avoids
|
|
22
|
+
* running the math engines inside Astro's Vite build.
|
|
13
23
|
*
|
|
14
|
-
*
|
|
24
|
+
* Reads the LaTeX from the `code.math-inline` / `code.math-display` elements
|
|
25
|
+
* that `remark-math` produces and wraps each in
|
|
26
|
+
* `<span class="vocasync-math" data-speech="…">`. MUST run BEFORE
|
|
27
|
+
* rehype-mathjax / rehype-katex (which replace the inner element) and before
|
|
28
|
+
* rehypeAudioWords.
|
|
15
29
|
*/
|
|
16
|
-
export default function rehypeMathSpeech(options?: RehypeMathSpeechOptions): (tree: Root, file:
|
|
17
|
-
|
|
30
|
+
export default function rehypeMathSpeech(options?: RehypeMathSpeechOptions): (tree: Root, file: {
|
|
31
|
+
path?: string;
|
|
32
|
+
history?: string[];
|
|
33
|
+
}) => void;
|
|
18
34
|
//# sourceMappingURL=rehype-math-speech.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rehype-math-speech.d.ts","sourceRoot":"","sources":["../../src/rehype/rehype-math-speech.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,IAAI,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"rehype-math-speech.d.ts","sourceRoot":"","sources":["../../src/rehype/rehype-math-speech.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,IAAI,EAAE,MAAM,MAAM,CAAC;AAIlD,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,OAAO,GAAE,uBAA4B,IAGhD,MAAM,IAAI,EAAE,MAAM;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,UAsCpF"}
|