All files / web/src/lib/audio audioClipRegistry.ts

94.87% Statements 37/39
66.66% Branches 4/6
100% Functions 3/3
94.87% Lines 37/39

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 401x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 165x 165x     165x 165x 165x 1x 1x 25x 25x 1x 1x 2x 2x  
export type AudioTone =
  | 'math-dictation'
  | 'celebration'
  | 'corrective'
  | 'encouragement'
  | 'tutorial-instruction'
  | 'tutorial-celebration'
 
interface ClipMeta {
  text: string
  tone: AudioTone
}
 
const registry = new Map<string, ClipMeta>()
 
/**
 * Declare and register an audio clip.
 *
 * Call at module scope — the clip is added to a global registry
 * the first time the module is evaluated.
 *
 * @returns The clip ID (pass-through for convenience).
 */
export function audioClip(id: string, text: string, tone: AudioTone): string {
  const existing = registry.get(id)
  if (existing && (existing.text !== text || existing.tone !== tone)) {
    throw new Error(`audioClip: duplicate ID "${id}" registered with different text/tone`)
  }
  registry.set(id, { text, tone })
  return id
}
 
export function getClipMeta(id: string): ClipMeta | undefined {
  return registry.get(id)
}
 
export function getAllRegisteredClips(): Array<ClipMeta & { id: string }> {
  return Array.from(registry.entries()).map(([id, meta]) => ({ id, ...meta }))
}