@vocasync/astro 0.1.7 → 0.1.9

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 (67) hide show
  1. package/README.md +9 -6
  2. package/dist/api/client.d.ts +1 -1
  3. package/dist/api/client.d.ts.map +1 -1
  4. package/dist/api/client.js +5 -9
  5. package/dist/api/client.js.map +1 -1
  6. package/dist/cli.js +4 -48
  7. package/dist/cli.js.map +1 -1
  8. package/dist/components/AudioPlayer.astro +1 -1
  9. package/dist/components/index.d.ts +14 -0
  10. package/dist/components/index.d.ts.map +1 -1
  11. package/dist/config/index.d.ts +1 -0
  12. package/dist/config/index.d.ts.map +1 -1
  13. package/dist/config/index.js +1 -0
  14. package/dist/config/index.js.map +1 -1
  15. package/dist/config/loader.d.ts +11 -0
  16. package/dist/config/loader.d.ts.map +1 -0
  17. package/dist/config/loader.js +42 -0
  18. package/dist/config/loader.js.map +1 -0
  19. package/dist/core/audio-map.d.ts +1 -1
  20. package/dist/core/audio-map.d.ts.map +1 -1
  21. package/dist/core/audio-map.js +1 -1
  22. package/dist/core/audio-map.js.map +1 -1
  23. package/dist/core/content-loader.d.ts +1 -1
  24. package/dist/core/content-loader.d.ts.map +1 -1
  25. package/dist/core/content-loader.js +1 -1
  26. package/dist/core/content-loader.js.map +1 -1
  27. package/dist/core/speech-builder.d.ts +1 -1
  28. package/dist/core/speech-builder.d.ts.map +1 -1
  29. package/dist/core/speech-builder.js +4 -4
  30. package/dist/core/speech-builder.js.map +1 -1
  31. package/dist/integration.d.ts.map +1 -1
  32. package/dist/integration.js +3 -21
  33. package/dist/integration.js.map +1 -1
  34. package/dist/lib/latex-to-speech/index.d.ts.map +1 -1
  35. package/dist/lib/latex-to-speech/index.js +5 -3
  36. package/dist/lib/latex-to-speech/index.js.map +1 -1
  37. package/dist/rehype/audio-words.d.ts.map +1 -1
  38. package/dist/rehype/audio-words.js +9 -8
  39. package/dist/rehype/audio-words.js.map +1 -1
  40. package/dist/rehype/rehype-math-speech.d.ts.map +1 -1
  41. package/dist/rehype/rehype-math-speech.js +1 -1
  42. package/dist/rehype/rehype-math-speech.js.map +1 -1
  43. package/dist/rehype/remark-math-speech.d.ts.map +1 -1
  44. package/dist/rehype/remark-math-speech.js +2 -2
  45. package/dist/rehype/remark-math-speech.js.map +1 -1
  46. package/dist/styles/variables.css +27 -27
  47. package/dist/sync/orchestrator.d.ts +1 -1
  48. package/dist/sync/orchestrator.d.ts.map +1 -1
  49. package/dist/sync/orchestrator.js +3 -3
  50. package/dist/sync/orchestrator.js.map +1 -1
  51. package/package.json +1 -1
  52. package/src/api/client.ts +13 -24
  53. package/src/cli.ts +13 -61
  54. package/src/components/AudioPlayer.astro +1 -1
  55. package/src/components/index.ts +10 -0
  56. package/src/config/index.ts +2 -0
  57. package/src/config/loader.ts +48 -0
  58. package/src/core/audio-map.ts +2 -2
  59. package/src/core/content-loader.ts +2 -2
  60. package/src/core/speech-builder.ts +10 -8
  61. package/src/integration.ts +4 -27
  62. package/src/lib/latex-to-speech/index.ts +17 -17
  63. package/src/rehype/audio-words.ts +22 -16
  64. package/src/rehype/rehype-math-speech.ts +6 -7
  65. package/src/rehype/remark-math-speech.ts +4 -4
  66. package/src/styles/variables.css +27 -27
  67. package/src/sync/orchestrator.ts +8 -14
package/src/cli.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { readFile } from "node:fs/promises";
4
3
  import { existsSync } from "node:fs";
4
+ import { readFile } from "node:fs/promises";
5
5
  import { resolve } from "node:path";
6
- import { validateConfig, type VocaSyncUserConfig } from "./config/index.js";
7
6
  import { createClient } from "./api/client.js";
8
- import { sync, checkConfig } from "./sync/orchestrator.js";
7
+ import { loadVocaSyncConfig, validateConfig } from "./config/index.js";
8
+ import { checkConfig, sync } from "./sync/orchestrator.js";
9
9
 
10
10
  /**
11
11
  * Load .env file manually (no external dependency)
@@ -13,25 +13,27 @@ import { sync, checkConfig } from "./sync/orchestrator.js";
13
13
  async function loadEnvFile(): Promise<void> {
14
14
  const envPath = resolve(process.cwd(), ".env");
15
15
  if (!existsSync(envPath)) return;
16
-
16
+
17
17
  try {
18
18
  const content = await readFile(envPath, "utf-8");
19
19
  for (const line of content.split("\n")) {
20
20
  const trimmed = line.trim();
21
21
  if (!trimmed || trimmed.startsWith("#")) continue;
22
-
22
+
23
23
  const eqIndex = trimmed.indexOf("=");
24
24
  if (eqIndex === -1) continue;
25
-
25
+
26
26
  const key = trimmed.slice(0, eqIndex).trim();
27
27
  let value = trimmed.slice(eqIndex + 1).trim();
28
-
28
+
29
29
  // Remove quotes if present
30
- if ((value.startsWith('"') && value.endsWith('"')) ||
31
- (value.startsWith("'") && value.endsWith("'"))) {
30
+ if (
31
+ (value.startsWith('"') && value.endsWith('"')) ||
32
+ (value.startsWith("'") && value.endsWith("'"))
33
+ ) {
32
34
  value = value.slice(1, -1);
33
35
  }
34
-
36
+
35
37
  // Don't override existing env vars
36
38
  if (!(key in process.env)) {
37
39
  process.env[key] = value;
@@ -143,56 +145,6 @@ function parseArgs(args: string[]): {
143
145
  return { command, options, positional };
144
146
  }
145
147
 
146
- /**
147
- * Load configuration from vocasync.config.ts/js/mjs.
148
- *
149
- * @example
150
- * ```ts
151
- * // vocasync.config.mjs
152
- * export default {
153
- * collection: { name: "articles", path: "./src/content/articles" },
154
- * voice: { id: "aura-asteria-en", provider: "deepgram" },
155
- * };
156
- * ```
157
- */
158
- async function loadConfig(configPath?: string): Promise<VocaSyncUserConfig> {
159
- const cwd = process.cwd();
160
-
161
- // Try explicit config path first
162
- if (configPath) {
163
- const fullPath = resolve(cwd, configPath);
164
- return loadConfigFile(fullPath);
165
- }
166
-
167
- // Try vocasync.config.ts / .mjs / .js
168
- for (const ext of [".ts", ".mjs", ".js"]) {
169
- const configFile = resolve(cwd, `vocasync.config${ext}`);
170
- if (existsSync(configFile)) {
171
- return await loadConfigFile(configFile);
172
- }
173
- }
174
-
175
- throw new Error(
176
- "No VocaSync configuration found.\n" +
177
- "Create a vocasync.config.mjs file with your configuration."
178
- );
179
- }
180
-
181
- /**
182
- * Load and execute a config file.
183
- * Uses file:// URLs for proper ESM import resolution.
184
- */
185
- async function loadConfigFile(filePath: string): Promise<VocaSyncUserConfig> {
186
- try {
187
- // Use file:// URL for proper ESM resolution
188
- const fileUrl = `file://${filePath}`;
189
- const module = await import(fileUrl);
190
- return (module.default || module) as VocaSyncUserConfig;
191
- } catch (error) {
192
- throw new Error(`Failed to load config from ${filePath}: ${error}`);
193
- }
194
- }
195
-
196
148
  /**
197
149
  * Main CLI entry point.
198
150
  */
@@ -214,7 +166,7 @@ async function main(): Promise<void> {
214
166
 
215
167
  try {
216
168
  // Load configuration
217
- const userConfig = await loadConfig(options.config as string | undefined);
169
+ const userConfig = await loadVocaSyncConfig(options.config as string | undefined);
218
170
  const config = validateConfig(userConfig);
219
171
  const client = createClient(config);
220
172
 
@@ -224,7 +224,7 @@ const audioDataJson = audioEntry ? JSON.stringify({
224
224
 
225
225
  <!-- Mini player (floating) -->
226
226
  {enableMiniPlayer && (
227
- <div class="vocasync-mini-player" data-mini-player hidden>
227
+ <div class="vocasync-mini-player" id={`${playerId}-mini`} data-mini-player hidden>
228
228
  <button
229
229
  type="button"
230
230
  class="vocasync-mini-player__play-btn"
@@ -7,6 +7,14 @@
7
7
  export interface AudioPlayerProps {
8
8
  /** Post slug to lookup audio in audio-map */
9
9
  slug: string;
10
+ /** Audio entry data from audio-map.json */
11
+ audioEntry?: {
12
+ audioUrl: string;
13
+ alignmentUrl?: string;
14
+ words?: { word: string; start: number; end: number }[];
15
+ duration?: number;
16
+ publishableKey?: string;
17
+ };
10
18
  /** Accessible label for the player */
11
19
  label?: string;
12
20
  /** Show placeholder when no audio available */
@@ -19,6 +27,8 @@ export interface AudioPlayerProps {
19
27
  enableMiniPlayer?: boolean;
20
28
  /** Enable word highlighting during playback */
21
29
  enableHighlighting?: boolean;
30
+ /** Enable click on words to seek to that position */
31
+ enableClickToSeek?: boolean;
22
32
  /** Number of trailing highlighted words */
23
33
  trailLength?: number;
24
34
  }
@@ -28,3 +28,5 @@ export type {
28
28
  Language,
29
29
  MathStyle,
30
30
  } from "./schema.js";
31
+
32
+ export { loadVocaSyncConfig } from "./loader.js";
@@ -0,0 +1,48 @@
1
+ import { existsSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import type { VocaSyncUserConfig } from "./schema.js";
4
+
5
+ /**
6
+ * Load and execute a config file.
7
+ * Uses file:// URLs for proper ESM import resolution.
8
+ */
9
+ async function loadConfigFile(filePath: string): Promise<VocaSyncUserConfig> {
10
+ try {
11
+ const fileUrl = `file://${filePath}`;
12
+ const module = await import(fileUrl);
13
+ return (module.default || module) as VocaSyncUserConfig;
14
+ } catch (error) {
15
+ throw new Error(`Failed to load config from ${filePath}: ${error}`);
16
+ }
17
+ }
18
+
19
+ /**
20
+ * Discover and load a VocaSync configuration file.
21
+ *
22
+ * Searches for vocasync.config.{ts,mjs,js} in the current working directory,
23
+ * or loads from an explicit path if provided.
24
+ *
25
+ * @param configPath - Optional explicit path to config file
26
+ */
27
+ export async function loadVocaSyncConfig(configPath?: string): Promise<VocaSyncUserConfig> {
28
+ const cwd = process.cwd();
29
+
30
+ // Try explicit config path first
31
+ if (configPath) {
32
+ const fullPath = resolve(cwd, configPath);
33
+ return loadConfigFile(fullPath);
34
+ }
35
+
36
+ // Try vocasync.config.ts / .mjs / .js
37
+ for (const ext of [".ts", ".mjs", ".js"]) {
38
+ const configFile = resolve(cwd, `vocasync.config${ext}`);
39
+ if (existsSync(configFile)) {
40
+ return await loadConfigFile(configFile);
41
+ }
42
+ }
43
+
44
+ throw new Error(
45
+ "No VocaSync configuration found.\n" +
46
+ "Create a vocasync.config.mjs file with your configuration."
47
+ );
48
+ }
@@ -1,6 +1,6 @@
1
- import { readFile, writeFile, mkdir } from "node:fs/promises";
1
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
2
2
  import { dirname } from "node:path";
3
- import type { AudioMap, AudioArtifact } from "../types/index.js";
3
+ import type { AudioArtifact, AudioMap } from "../types/index.js";
4
4
 
5
5
  /**
6
6
  * Create an empty audio map structure
@@ -1,7 +1,7 @@
1
1
  import { readFile, readdir, stat } from "node:fs/promises";
2
- import { join, extname, basename, relative } from "node:path";
3
- import type { ContentItem } from "../types/index.js";
2
+ import { basename, extname, join, relative } from "node:path";
4
3
  import type { CollectionConfig } from "../config/index.js";
4
+ import type { ContentItem } from "../types/index.js";
5
5
 
6
6
  /**
7
7
  * Parse frontmatter from markdown content.
@@ -1,9 +1,9 @@
1
- import { unified } from "unified";
2
- import remarkParse from "remark-parse";
1
+ import type { Code, Content, Emphasis, Heading, InlineCode, Root, Strong, Text } from "mdast";
3
2
  import remarkMath from "remark-math";
4
- import type { Root, Content, Text, InlineCode, Code, Heading, Emphasis, Strong } from "mdast";
5
- import type { ContentItem, SpeechDocument } from "../types/index.js";
3
+ import remarkParse from "remark-parse";
4
+ import { unified } from "unified";
6
5
  import type { MathConfig } from "../config/index.js";
6
+ import type { ContentItem, SpeechDocument } from "../types/index.js";
7
7
  import { computeHash } from "./hash-manager.js";
8
8
 
9
9
  /**
@@ -15,7 +15,9 @@ interface LaTeXConverter {
15
15
 
16
16
  // Cache for latex-to-speech results
17
17
  const latexSpeechCache = new Map<string, Promise<string>>();
18
- let latexToSpeech: ((exprs: string[], options?: Record<string, unknown>) => Promise<string[]>) | null = null;
18
+ let latexToSpeech:
19
+ | ((exprs: string[], options?: Record<string, unknown>) => Promise<string[]>)
20
+ | null = null;
19
21
  let latexToSpeechLoadAttempted = false;
20
22
  let warnedLatexSpeechFailure = false;
21
23
 
@@ -41,7 +43,7 @@ async function createLatexConverter(config: MathConfig): Promise<LaTeXConverter
41
43
  try {
42
44
  const mod = await import("../lib/latex-to-speech/index.js");
43
45
  latexToSpeech = mod.latexToSpeech || mod.default;
44
- } catch (e) {
46
+ } catch {
45
47
  console.warn(
46
48
  "[vocasync] Math-to-speech initialization failed. Install optional dependencies:",
47
49
  "\n npm install speech-rule-engine mathjax-full"
@@ -64,7 +66,7 @@ async function createLatexConverter(config: MathConfig): Promise<LaTeXConverter
64
66
  async convert(latex: string, display: boolean): Promise<string> {
65
67
  const trimmed = latex.trim();
66
68
  if (!trimmed) return "";
67
-
69
+
68
70
  const cacheKey = `${display}:${trimmed}`;
69
71
  if (!latexSpeechCache.has(cacheKey)) {
70
72
  const pending = (async () => {
@@ -284,7 +286,7 @@ export async function buildSpeechDocument(
284
286
  const resolvedParts = await Promise.all(textParts);
285
287
 
286
288
  // Clean up and normalize text
287
- let text = resolvedParts
289
+ const text = resolvedParts
288
290
  .join(" ")
289
291
  .replace(/\s+/g, " ") // Normalize whitespace
290
292
  .replace(/\n\s*\n/g, "\n\n") // Preserve paragraph breaks
@@ -1,34 +1,11 @@
1
1
  import type { AstroIntegration } from "astro";
2
- import { existsSync } from "node:fs";
3
- import { resolve } from "node:path";
4
- import { validateConfig, type VocaSyncUserConfig } from "./config/index.js";
5
- import { loadAudioMap } from "./core/audio-map.js";
2
+ import { type VocaSyncConfig, loadVocaSyncConfig, validateConfig } from "./config/index.js";
3
+ import { createEmptyAudioMap, loadAudioMap } from "./core/audio-map.js";
6
4
  import type { AudioMap } from "./types/index.js";
7
5
 
8
6
  // Cache for the loaded audio map
9
7
  let audioMapCache: AudioMap | null = null;
10
8
 
11
- /**
12
- * Load configuration from vocasync.config.ts/js/mjs.
13
- */
14
- async function loadVocaSyncConfig(): Promise<VocaSyncUserConfig> {
15
- const cwd = process.cwd();
16
-
17
- for (const ext of [".ts", ".mjs", ".js"]) {
18
- const configFile = resolve(cwd, `vocasync.config${ext}`);
19
- if (existsSync(configFile)) {
20
- const fileUrl = `file://${configFile}`;
21
- const module = await import(fileUrl);
22
- return (module.default || module) as VocaSyncUserConfig;
23
- }
24
- }
25
-
26
- throw new Error(
27
- "No VocaSync configuration found.\n" +
28
- "Create a vocasync.config.mjs file with your configuration."
29
- );
30
- }
31
-
32
9
  /**
33
10
  * VocaSync Astro Integration.
34
11
  *
@@ -58,7 +35,7 @@ export default function vocasyncIntegration(): AstroIntegration {
58
35
  hooks: {
59
36
  "astro:config:setup": async ({ updateConfig, logger }) => {
60
37
  // Load config from vocasync.config.mjs
61
- let config;
38
+ let config: VocaSyncConfig;
62
39
  try {
63
40
  const userConfig = await loadVocaSyncConfig();
64
41
  config = validateConfig(userConfig);
@@ -77,7 +54,7 @@ export default function vocasyncIntegration(): AstroIntegration {
77
54
  logger.warn(
78
55
  `Audio map not found at ${config.output.audioMapPath}. Run 'npx vocasync sync' first.`
79
56
  );
80
- audioMapCache = { version: 1, updatedAt: "", entries: {} };
57
+ audioMapCache = createEmptyAudioMap();
81
58
  }
82
59
 
83
60
  // Add virtual module for audio-map access
@@ -1,10 +1,11 @@
1
1
  /**
2
2
  * LaTeX to Speech conversion using speech-rule-engine and mathjax-full.
3
- *
3
+ *
4
4
  * This module provides the same interface as the vendored latex-to-speech package
5
5
  * but works with the optional peer dependencies instead of bundling MathJax.
6
6
  */
7
7
 
8
+ // biome-ignore lint/suspicious/noExplicitAny: speech-rule-engine is an optional peer dep with no bundled types
8
9
  let SRE: any = null;
9
10
  let tex2mml: ((latex: string) => string) | null = null;
10
11
  let engineSetup = false;
@@ -16,7 +17,7 @@ let initPromise: Promise<boolean> | null = null;
16
17
  */
17
18
  async function init(): Promise<boolean> {
18
19
  if (initPromise) return initPromise;
19
-
20
+
20
21
  initPromise = (async () => {
21
22
  try {
22
23
  // Dynamically import speech-rule-engine
@@ -34,32 +35,34 @@ async function init(): Promise<boolean> {
34
35
  const { HTMLDocument } = await import("mathjax-full/js/handlers/html/HTMLDocument.js");
35
36
  // @ts-expect-error - mathjax-full is an optional peer dependency
36
37
  const { liteAdaptor } = await import("mathjax-full/js/adaptors/liteAdaptor.js");
37
- // @ts-expect-error - mathjax-full is an optional peer dependency
38
- const { SerializedMmlVisitor } = await import("mathjax-full/js/core/MmlTree/SerializedMmlVisitor.js");
38
+ const { SerializedMmlVisitor } = await import(
39
+ // @ts-expect-error - mathjax-full is an optional peer dependency
40
+ "mathjax-full/js/core/MmlTree/SerializedMmlVisitor.js"
41
+ );
39
42
  // @ts-expect-error - mathjax-full is an optional peer dependency
40
43
  const { AllPackages } = await import("mathjax-full/js/input/tex/AllPackages.js");
41
44
 
42
45
  // Filter out problematic packages
43
46
  const packages = AllPackages.filter((p: string) => p !== "bussproofs");
44
-
47
+
45
48
  // Create TeX input jax with all packages
46
49
  const texInput = new TeX({ packages });
47
-
50
+
48
51
  // Create a minimal HTML document for conversion
49
52
  const adaptor = liteAdaptor();
50
53
  const doc = new HTMLDocument("", adaptor, { InputJax: texInput });
51
-
54
+
52
55
  // Create a visitor to serialize to MathML
53
56
  const visitor = new SerializedMmlVisitor();
54
-
57
+
55
58
  // Create the tex2mml function
56
59
  tex2mml = (latex: string): string => {
57
60
  const node = doc.convert(latex, { display: true });
58
61
  return visitor.visitTree(node);
59
62
  };
60
-
63
+
61
64
  return true;
62
- } catch (e) {
65
+ } catch {
63
66
  console.warn("[vocasync] mathjax-full not installed. Math-to-speech disabled.");
64
67
  console.warn("[vocasync] Install with: npm install mathjax-full speech-rule-engine");
65
68
  return false;
@@ -82,17 +85,14 @@ export interface SREOptions {
82
85
 
83
86
  /**
84
87
  * Convert an array of LaTeX expressions to speech.
85
- *
88
+ *
86
89
  * @param exprs - Array of LaTeX expressions to convert
87
90
  * @param options - SRE configuration options
88
91
  * @returns Promise resolving to array of speech strings
89
92
  */
90
- export async function latexToSpeech(
91
- exprs: string[],
92
- options: SREOptions = {}
93
- ): Promise<string[]> {
93
+ export async function latexToSpeech(exprs: string[], options: SREOptions = {}): Promise<string[]> {
94
94
  const available = await init();
95
-
95
+
96
96
  if (!available || !SRE || !tex2mml) {
97
97
  // Return empty descriptions when dependencies not available
98
98
  return exprs.map(() => "");
@@ -116,7 +116,7 @@ export async function latexToSpeech(
116
116
  try {
117
117
  const mml = tex2mml!(latex);
118
118
  return SRE!.toSpeech(mml);
119
- } catch (e) {
119
+ } catch {
120
120
  console.warn(`[vocasync] Failed to convert LaTeX to speech: ${latex}`);
121
121
  return "";
122
122
  }
@@ -1,9 +1,9 @@
1
- import type { Root, Element, Text } from "hast";
2
- import type { Plugin } from "unified";
3
- import { visitParents } from "unist-util-visit-parents";
1
+ import { execFileSync } from "node:child_process";
4
2
  import { readFileSync } from "node:fs";
5
3
  import { resolve } from "node:path";
6
- import { execSync } from "node:child_process";
4
+ import type { Element, Root, Text } from "hast";
5
+ import type { Plugin } from "unified";
6
+ import { visitParents } from "unist-util-visit-parents";
7
7
  import type { AlignedWord, AudioMap } from "../types/index.js";
8
8
 
9
9
  /**
@@ -62,7 +62,11 @@ function loadAudioMapSync(audioMapPath: string): AudioMap | null {
62
62
  * @param slug - The content slug for caching
63
63
  * @param publishableKey - Optional publishable key for authentication
64
64
  */
65
- function fetchAlignmentSync(alignmentUrl: string, slug: string, publishableKey?: string): AlignedWord[] | null {
65
+ function fetchAlignmentSync(
66
+ alignmentUrl: string,
67
+ slug: string,
68
+ publishableKey?: string
69
+ ): AlignedWord[] | null {
66
70
  // Check cache first
67
71
  if (alignmentCache.has(slug)) {
68
72
  return alignmentCache.get(slug) ?? null;
@@ -77,16 +81,16 @@ function fetchAlignmentSync(alignmentUrl: string, slug: string, publishableKey?:
77
81
  fetchUrl = url.toString();
78
82
  }
79
83
 
80
- // Use sync-fetch or execSync to make a synchronous HTTP request
81
- // We'll use child_process.execSync with curl as a simple solution
84
+ // Use execFileSync with curl to make a synchronous HTTP request
85
+ // execFileSync avoids shell invocation, preventing command injection
82
86
  // Note: -L flag follows redirects (required for vocasync.io signed URLs)
83
- const result = execSync(`curl -sL "${fetchUrl}"`, {
87
+ const result = execFileSync("curl", ["-sL", fetchUrl], {
84
88
  encoding: "utf-8",
85
89
  timeout: 30000,
86
90
  });
87
91
 
88
92
  const data = JSON.parse(result);
89
-
93
+
90
94
  // The alignment response contains a words array
91
95
  const words = data.words as AlignedWord[] | undefined;
92
96
  if (words && Array.isArray(words)) {
@@ -128,7 +132,7 @@ const rehypeAudioWords: Plugin<[RehypeAudioWordsOptions?], Root> = (options = {}
128
132
  const {
129
133
  audioMapPath = ".vocasync/audio-map.json",
130
134
  classPrefix = "vocasync",
131
- collectionName = "articles"
135
+ collectionName = "articles",
132
136
  } = options;
133
137
 
134
138
  return (tree, file) => {
@@ -140,20 +144,22 @@ const rehypeAudioWords: Plugin<[RehypeAudioWordsOptions?], Root> = (options = {}
140
144
 
141
145
  // Resolve slug from file path
142
146
  // Files are typically at paths like: /src/content/articles/hello-world.md
143
- const filePath = file.path ?? (Array.isArray(file.history) ? file.history[file.history.length - 1] : undefined);
144
-
147
+ const filePath =
148
+ file.path ??
149
+ (Array.isArray(file.history) ? file.history[file.history.length - 1] : undefined);
150
+
145
151
  if (!filePath) {
146
152
  return; // No file path, skip processing
147
153
  }
148
-
154
+
149
155
  // Normalize path separators
150
156
  const normalizedPath = filePath.replace(/\\/g, "/");
151
-
157
+
152
158
  // Try to extract slug from collection path
153
159
  // Pattern: /src/content/{collectionName}/{slug}.md or .mdx
154
160
  const collectionPattern = new RegExp(`/content/${collectionName}/([^/]+)\\.(md|mdx)$`);
155
161
  const match = normalizedPath.match(collectionPattern);
156
-
162
+
157
163
  let slug: string | undefined;
158
164
  if (match) {
159
165
  slug = match[1];
@@ -262,7 +268,7 @@ function processTextNode(
262
268
  const wordPattern = /[\p{L}\p{N}'']+/gu;
263
269
  let match: RegExpExecArray | null;
264
270
 
265
- // biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
271
+ // biome-ignore lint/suspicious/noAssignInExpressions: regex exec loop requires assignment in condition
266
272
  while ((match = wordPattern.exec(text)) !== null) {
267
273
  const word = match[0];
268
274
  const start = match.index;
@@ -5,7 +5,9 @@ import type { MathSpeechEntry } from "./remark-math-speech.js";
5
5
 
6
6
  const SR_SPEECH_CLASS = "vocasync-math-speech";
7
7
 
8
- let latexToSpeech: ((exprs: string[], options?: Record<string, unknown>) => Promise<string[]>) | null = null;
8
+ let latexToSpeech:
9
+ | ((exprs: string[], options?: Record<string, unknown>) => Promise<string[]>)
10
+ | null = null;
9
11
  let latexToSpeechLoadAttempted = false;
10
12
 
11
13
  const latexSpeechCache = new Map<string, Promise<string>>();
@@ -22,10 +24,7 @@ interface RehypeMathSpeechOptions {
22
24
  /**
23
25
  * Convert LaTeX to spoken text using speech-rule-engine and mathjax-full.
24
26
  */
25
- async function speakLatex(
26
- value: string,
27
- style: string = "clearspeak"
28
- ): Promise<string> {
27
+ async function speakLatex(value: string, style = "clearspeak"): Promise<string> {
29
28
  const trimmed = String(value ?? "").trim();
30
29
  if (!trimmed) return "";
31
30
 
@@ -35,7 +34,7 @@ async function speakLatex(
35
34
  try {
36
35
  const mod = await import("../lib/latex-to-speech/index.js");
37
36
  latexToSpeech = mod.latexToSpeech || mod.default;
38
- } catch (e) {
37
+ } catch {
39
38
  console.warn(
40
39
  "[vocasync] Math-to-speech initialization failed. Install optional dependencies:",
41
40
  "\n npm install speech-rule-engine mathjax-full"
@@ -82,7 +81,7 @@ function normalizeWhitespace(value = ""): string {
82
81
  /**
83
82
  * Rehype plugin that injects hidden spoken text next to math elements.
84
83
  * This allows rehypeAudioWords to wrap the spoken words with timing data.
85
- *
84
+ *
86
85
  * Must run AFTER rehype-katex or rehype-mathjax, and BEFORE rehypeAudioWords.
87
86
  */
88
87
  export default function rehypeMathSpeech(options: RehypeMathSpeechOptions = {}) {
@@ -1,5 +1,5 @@
1
- import { visit } from "unist-util-visit";
2
1
  import type { Root } from "mdast";
2
+ import { visit } from "unist-util-visit";
3
3
  import type { VFile } from "vfile";
4
4
 
5
5
  export type MathSpeechEntry = {
@@ -15,9 +15,9 @@ export type MathSpeechEntry = {
15
15
  export default function remarkMathSpeechCollector() {
16
16
  return function transformer(tree: Root, file: VFile) {
17
17
  const entries: MathSpeechEntry[] = [];
18
- visit(tree, (node: any) => {
19
- if (node?.type !== "math" && node?.type !== "inlineMath") return;
20
- const latex = String(node.value ?? "").trim();
18
+ visit(tree, (node) => {
19
+ if (node.type !== "math" && node.type !== "inlineMath") return;
20
+ const latex = String("value" in node ? (node.value ?? "") : "").trim();
21
21
  if (!latex) return;
22
22
  entries.push({
23
23
  latex,