@pie-players/pie-assessment-toolkit 0.3.47 → 0.3.49
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/dist/attempt/AssessmentSession.js +2 -1
- package/dist/attempt/AssessmentSession.js.map +1 -1
- package/dist/attempt/adapters/activity-to-test-attempt-session.js +12 -8
- package/dist/attempt/adapters/activity-to-test-attempt-session.js.map +1 -1
- package/dist/components/ItemToolBar.custom-element.js +56 -17
- package/dist/components/PieAssessmentToolkit.custom-element.js +84 -29
- package/dist/components/SectionToolBar.custom-element.js +55 -17
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/policy/core/pnp-policy-inputs.js +1 -2
- package/dist/policy/core/pnp-policy-inputs.js.map +1 -1
- package/dist/policy/core/provenance.js.map +1 -1
- package/dist/runtime/SectionRuntimeEngine.js +1 -1
- package/dist/runtime/SectionRuntimeEngine.js.map +1 -1
- package/dist/runtime/core/cohort.js.map +1 -1
- package/dist/runtime/core/engine-input.js.map +1 -1
- package/dist/runtime/core/engine-readiness.js.map +1 -1
- package/dist/runtime/core/engine-resolver.js.map +1 -1
- package/dist/runtime/core/engine-transition.js +1 -3
- package/dist/runtime/core/engine-transition.js.map +1 -1
- package/dist/runtime/registration-events.js.map +1 -1
- package/dist/runtime/session-event-emitter-policy.js.map +1 -1
- package/dist/services/HighlightCoordinator.js +2 -1
- package/dist/services/HighlightCoordinator.js.map +1 -1
- package/dist/services/I18nService.d.ts +1 -1
- package/dist/services/I18nService.js.map +1 -1
- package/dist/services/SSMLExtractor.js.map +1 -1
- package/dist/services/TTSService.js +5 -2
- package/dist/services/TTSService.js.map +1 -1
- package/dist/services/ThemeProvider.js.map +1 -1
- package/dist/services/ToolRegistry.d.ts +1 -1
- package/dist/services/ToolRegistry.js.map +1 -1
- package/dist/services/ToolkitCoordinator.js +21 -11
- package/dist/services/ToolkitCoordinator.js.map +1 -1
- package/dist/services/createDefaultToolRegistry.js +4 -2
- package/dist/services/createDefaultToolRegistry.js.map +1 -1
- package/dist/services/framework-error-bus.js.map +1 -1
- package/dist/services/framework-error.js.map +1 -1
- package/dist/services/interfaces.js.map +1 -1
- package/dist/services/section-controller-types.js.map +1 -1
- package/dist/services/tool-config-defaults.js +7 -1
- package/dist/services/tool-config-defaults.js.map +1 -1
- package/dist/services/tool-config-validation.js +3 -1
- package/dist/services/tool-config-validation.js.map +1 -1
- package/dist/services/tool-instance-id.js.map +1 -1
- package/dist/services/tool-providers/DesmosToolProvider.js.map +1 -1
- package/dist/services/tool-providers/TTSToolProvider.js.map +1 -1
- package/dist/services/toolbar-items.js.map +1 -1
- package/dist/services/tools-config-normalizer.js +1 -2
- package/dist/services/tools-config-normalizer.js.map +1 -1
- package/dist/services/tts/browser-provider.js +60 -18
- package/dist/services/tts/browser-provider.js.map +1 -1
- package/dist/services/tts/catalog-span-alignment.js +8 -3
- package/dist/services/tts/catalog-span-alignment.js.map +1 -1
- package/dist/services/tts/generated-speech/assemble-plan.js.map +1 -1
- package/dist/services/tts/generated-speech/index.d.ts +1 -1
- package/dist/services/tts/generated-speech/index.js +1 -1
- package/dist/services/tts/generated-speech/index.js.map +1 -1
- package/dist/services/tts/generated-speech/math-speech-cache.js +3 -1
- package/dist/services/tts/generated-speech/math-speech-cache.js.map +1 -1
- package/dist/services/tts/highlight-pipeline/boundary-normalizer.js.map +1 -1
- package/dist/services/tts/highlight-pipeline/create-highlight-plan.js.map +1 -1
- package/dist/services/tts/math-alignment/mathml-tokenizer.js.map +1 -1
- package/dist/services/tts/math-alignment/sequence-aligner.js.map +1 -1
- package/dist/services/tts/math-alignment/speech-tokenizer.js.map +1 -1
- package/dist/services/tts/math-aware-text-processing.js +6 -3
- package/dist/services/tts/math-aware-text-processing.js.map +1 -1
- package/dist/services/tts/math-speech.js +3 -1
- package/dist/services/tts/math-speech.js.map +1 -1
- package/dist/services/tts/visual-line-ranges.js.map +1 -1
- package/dist/services/tts-runtime-config.js +6 -2
- package/dist/services/tts-runtime-config.js.map +1 -1
- package/dist/tools/calculators/desmos-provider.js.map +1 -1
- package/dist/tools/default-tool-module-loaders.js.map +1 -1
- package/dist/tools/registrations/accessibility-tools.js.map +1 -1
- package/dist/tools/registrations/calculator.js +1 -1
- package/dist/tools/registrations/calculator.js.map +1 -1
- package/dist/tools/registrations/interaction-tools.js.map +1 -1
- package/dist/tools/registrations/measurement-tools.js.map +1 -1
- package/dist/tools/registrations/subject-specific-tools.js +1 -1
- package/dist/tools/registrations/subject-specific-tools.js.map +1 -1
- package/dist/tools/registrations/tts.js +4 -2
- package/dist/tools/registrations/tts.js.map +1 -1
- package/dist/tools/types.js.map +1 -1
- package/dist/tools/variant-resolver.js.map +1 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registration-events.js","sourceRoot":"","sources":["../../src/runtime/registration-events.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,cAAc,CAAC;AACjD,MAAM,CAAC,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AACrD,MAAM,CAAC,MAAM,uCAAuC,
|
|
1
|
+
{"version":3,"file":"registration-events.js","sourceRoot":"","sources":["../../src/runtime/registration-events.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,cAAc,CAAC;AACjD,MAAM,CAAC,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AACrD,MAAM,CAAC,MAAM,uCAAuC,GACnD,0BAA0B,CAAC;AAC5B,MAAM,CAAC,MAAM,8BAA8B,GAAG,sBAAsB,CAAC;AACrE,MAAM,CAAC,MAAM,iCAAiC,GAAG,oBAAoB,CAAC;AACtE,MAAM,CAAC,MAAM,oCAAoC,GAAG,uBAAuB,CAAC","sourcesContent":["export const PIE_REGISTER_EVENT = \"pie-register\";\nexport const PIE_UNREGISTER_EVENT = \"pie-unregister\";\nexport const PIE_INTERNAL_ITEM_SESSION_CHANGED_EVENT =\n\t\"pie-item-session-changed\";\nexport const PIE_ITEM_SESSION_CHANGED_EVENT = \"item-session-changed\";\nexport const PIE_INTERNAL_CONTENT_LOADED_EVENT = \"pie-content-loaded\";\nexport const PIE_INTERNAL_ITEM_PLAYER_ERROR_EVENT = \"pie-item-player-error\";\n\nexport type RuntimeRegistrationKind = \"item\" | \"passage\";\n\nexport interface RuntimeRegistrationDetail {\n\tkind: RuntimeRegistrationKind;\n\titemId: string;\n\tcanonicalItemId?: string;\n\tcontentKind?: string;\n\titem?: unknown;\n\telement: HTMLElement;\n}\n\nexport interface ItemSessionChangedDetail {\n\titemId: string;\n\tcanonicalItemId?: string;\n\tsession: unknown;\n\tsourceRuntimeId?: string;\n}\n\nexport interface InternalItemSessionChangedDetail {\n\titemId: string;\n\tsession: unknown;\n}\n\nexport interface InternalContentLoadedDetail {\n\titemId: string;\n\tcanonicalItemId?: string;\n\tcontentKind?: string;\n\tdetail?: unknown;\n}\n\nexport interface InternalItemPlayerErrorDetail {\n\titemId: string;\n\tcanonicalItemId?: string;\n\tcontentKind?: string;\n\terror: unknown;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-event-emitter-policy.js","sourceRoot":"","sources":["../../src/runtime/session-event-emitter-policy.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,4BAA4B;IAC3C,OAAO;QACN,iCAAiC,EAAE,IAAI,GAAG,EAAkB;QAC5D,6BAA6B,EAAE,IAAI,GAAG,EAAkB;KACxD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,2BAA2B,
|
|
1
|
+
{"version":3,"file":"session-event-emitter-policy.js","sourceRoot":"","sources":["../../src/runtime/session-event-emitter-policy.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,4BAA4B;IAC3C,OAAO;QACN,iCAAiC,EAAE,IAAI,GAAG,EAAkB;QAC5D,6BAA6B,EAAE,IAAI,GAAG,EAAkB;KACxD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,2BAA2B,CAC1C,KAA6B;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E,CAAC,CAAC;IAC7C,CAAC;AACF,CAAC;AAED,SAAS,mBAAmB,CAAC,OAAgC;IAC5D,OAAO,OAAO,CAAC,MAAM,KAAK,eAAe,CAAC;AAC3C,CAAC;AAED,SAAS,wBAAwB,CAAC,OAAgC;IACjE,IAAI,CAAC;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC;YACrB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,eAAe,EAAE,OAAO,CAAC,eAAe;YACxC,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,IAAI;YAClC,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,IAAI;SACpC,CAAC,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;IACrC,CAAC;AACF,CAAC","sourcesContent":["export type SessionEmitPolicyState = {\n\tlastSessionEventSignatureByItemId: Map<string, string>;\n\tlastMetadataSignatureByItemId: Map<string, string>;\n};\n\nexport function createSessionEmitPolicyState(): SessionEmitPolicyState {\n\treturn {\n\t\tlastSessionEventSignatureByItemId: new Map<string, string>(),\n\t\tlastMetadataSignatureByItemId: new Map<string, string>(),\n\t};\n}\n\nexport function resetSessionEmitPolicyState(\n\tstate: SessionEmitPolicyState,\n): void {\n\tstate.lastSessionEventSignatureByItemId.clear();\n\tstate.lastMetadataSignatureByItemId.clear();\n}\n\nexport function shouldEmitCanonicalSessionEvent(args: {\n\tstate: SessionEmitPolicyState;\n\titemId: string;\n\tpayload: Record<string, unknown>;\n}): boolean {\n\tconst { state, itemId, payload } = args;\n\tif (isMetadataOnlyEvent(payload)) {\n\t\tconst metadataSignature = getMetadataOnlySignature(payload);\n\t\tconst previousMetadataSignature =\n\t\t\tstate.lastMetadataSignatureByItemId.get(itemId);\n\t\tif (previousMetadataSignature === metadataSignature) {\n\t\t\treturn false;\n\t\t}\n\t\tstate.lastMetadataSignatureByItemId.set(itemId, metadataSignature);\n\t}\n\tconst signature = getSessionEventSemanticSignature(payload);\n\tconst previousSignature = state.lastSessionEventSignatureByItemId.get(itemId);\n\tif (previousSignature === signature) {\n\t\treturn false;\n\t}\n\tstate.lastSessionEventSignatureByItemId.set(itemId, signature);\n\treturn true;\n}\n\nfunction getSessionEventSemanticSignature(\n\tpayload: Record<string, unknown>,\n): string {\n\tconst semanticPayload = { ...payload };\n\tdelete semanticPayload.timestamp;\n\tdelete semanticPayload.sourceRuntimeId;\n\ttry {\n\t\treturn JSON.stringify(semanticPayload);\n\t} catch {\n\t\treturn String(semanticPayload.itemId || \"\");\n\t}\n}\n\nfunction isMetadataOnlyEvent(payload: Record<string, unknown>): boolean {\n\treturn payload.intent === \"metadata-only\";\n}\n\nfunction getMetadataOnlySignature(payload: Record<string, unknown>): string {\n\ttry {\n\t\treturn JSON.stringify({\n\t\t\titemId: payload.itemId,\n\t\t\tcanonicalItemId: payload.canonicalItemId,\n\t\t\tintent: payload.intent,\n\t\t\tcomplete: payload.complete ?? null,\n\t\t\tcomponent: payload.component ?? null,\n\t\t});\n\t} catch {\n\t\treturn String(payload.itemId || \"\");\n\t}\n}\n"]}
|
|
@@ -185,7 +185,8 @@ export class HighlightCoordinator {
|
|
|
185
185
|
const computed = target && typeof getComputedStyle === "function"
|
|
186
186
|
? getComputedStyle(target)
|
|
187
187
|
: null;
|
|
188
|
-
const background = this.parseColor(computed?.getPropertyValue("--pie-background") ||
|
|
188
|
+
const background = this.parseColor(computed?.getPropertyValue("--pie-background") ||
|
|
189
|
+
computed?.backgroundColor) || fallbackBackground;
|
|
189
190
|
const text = this.parseColor(computed?.getPropertyValue("--pie-text")) || fallbackText;
|
|
190
191
|
const accent = this.explicitTTSColorOverride
|
|
191
192
|
? this.parseColor(this.explicitTTSColorOverride.color) || fallbackMissing
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HighlightCoordinator.js","sourceRoot":"","sources":["../../src/services/HighlightCo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ations (persistent).\n * Uses CSS Custom Highlight API - zero DOM mutation, preserves accessibility.\n *\n * Features:\n * - Separate layers prevent TTS clearing from removing student annotations\n * - CSS Custom Highlight API (no DOM mutation)\n * - Full accessibility support (screen readers see original text)\n * - Configurable colors and styles\n * - Annotation persistence via RangeSerializer\n *\n * Part of PIE Assessment Toolkit.\n *\n * Browser Support:\n * - Chrome/Edge 105+\n * - Safari 17.2+\n * - Firefox: Behind flag (not recommended for production)\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/CSS_Custom_Highlight_API\n */\n\nimport type { HighlightCoordinatorApi } from \"./interfaces.js\";\nimport { RangeSerializer, type SerializedRange } from \"./RangeSerializer.js\";\n\n/**\n * Highlight types\n */\nexport enum HighlightType {\n\tTTS_WORD = \"tts-word\",\n\tTTS_SENTENCE = \"tts-sentence\",\n\tANNOTATION = \"annotation\",\n}\n\n/**\n * Highlight colors for annotations\n */\nexport enum HighlightColor {\n\tYELLOW = \"yellow\",\n\tGREEN = \"green\",\n\tBLUE = \"blue\",\n\tPINK = \"pink\",\n\tORANGE = \"orange\",\n\tUNDERLINE = \"underline\",\n}\n\n/**\n * Annotation data\n */\nexport interface Annotation {\n\tid: string;\n\trange: Range;\n\ttype: HighlightType.ANNOTATION;\n\tcolor: HighlightColor;\n\ttimestamp: number;\n}\n\n/**\n * Configuration for HighlightCoordinator\n * Currently empty but allows future extension without breaking changes\n */\nexport type HighlightCoordinatorConfig = Record<string, never>;\n\nexport class HighlightCoordinator implements HighlightCoordinatorApi {\n\tprivate config: HighlightCoordinatorConfig;\n\tprivate ttsWordHighlight: Highlight | null = null;\n\tprivate ttsSentenceHighlight: Highlight | null = null;\n\tprivate ttsWordElementHighlights = new Set<Element>();\n\tprivate ttsSentenceElementHighlights = new Set<Element>();\n\tprivate annotations = new Map<string, Annotation>();\n\t// Shared highlights per color (one Highlight object per color, contains all ranges)\n\tprivate colorHighlights = new Map<HighlightColor, Highlight>();\n\tprivate nextAnnotationId = 1;\n\tprivate supported = false;\n\tprivate rangeSerializer: RangeSerializer;\n\tprivate themeObserver: MutationObserver | null = null;\n\tprivate explicitTTSColorOverride: { color: string; opacity: number } | null = null;\n\n\tconstructor(config: HighlightCoordinatorConfig = {}) {\n\t\tthis.config = config;\n\t\tthis.rangeSerializer = new RangeSerializer();\n\n\t\t// SSR guard\n\t\tif (typeof CSS === \"undefined\" || !(\"highlights\" in CSS)) {\n\t\t\tconsole.warn(\n\t\t\t\t\"CSS Custom Highlight API not supported (SSR or unsupported browser)\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.supported = true;\n\t\tthis.initializeHighlights();\n\t\tthis.registerStyles();\n\t\tthis.applyAdaptiveTTSStyle();\n\t\tthis.setupThemeObservation();\n\t}\n\n\tprivate setupThemeObservation(): void {\n\t\tif (typeof document === \"undefined\") return;\n\t\tif (typeof MutationObserver === \"undefined\") return;\n\n\t\tconst refresh = () => this.applyAdaptiveTTSStyle();\n\t\tthis.themeObserver = new MutationObserver(refresh);\n\n\t\tthis.themeObserver.observe(document.documentElement, {\n\t\t\tattributes: true,\n\t\t\tattributeFilter: [\"style\", \"data-theme\", \"data-color-scheme\", \"class\"],\n\t\t});\n\n\t\tfor (const host of document.querySelectorAll(\"pie-theme\")) {\n\t\t\tthis.themeObserver.observe(host, {\n\t\t\t\tattributes: true,\n\t\t\t\tattributeFilter: [\n\t\t\t\t\t\"theme\",\n\t\t\t\t\t\"scheme\",\n\t\t\t\t\t\"provider\",\n\t\t\t\t\t\"variables\",\n\t\t\t\t\t\"style\",\n\t\t\t\t\t\"data-theme\",\n\t\t\t\t\t\"data-color-scheme\",\n\t\t\t\t],\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate parseColor(input: string | null | undefined): [number, number, number] | null {\n\t\tif (!input) return null;\n\t\tconst value = input.trim();\n\t\tif (!value) return null;\n\n\t\tconst hexMatch = /^#([a-f\\d]{3}|[a-f\\d]{6})$/i.exec(value);\n\t\tif (hexMatch) {\n\t\t\tconst hex = hexMatch[1];\n\t\t\tif (hex.length === 3) {\n\t\t\t\treturn [\n\t\t\t\t\tparseInt(hex[0] + hex[0], 16),\n\t\t\t\t\tparseInt(hex[1] + hex[1], 16),\n\t\t\t\t\tparseInt(hex[2] + hex[2], 16),\n\t\t\t\t];\n\t\t\t}\n\t\t\treturn [\n\t\t\t\tparseInt(hex.slice(0, 2), 16),\n\t\t\t\tparseInt(hex.slice(2, 4), 16),\n\t\t\t\tparseInt(hex.slice(4, 6), 16),\n\t\t\t];\n\t\t}\n\n\t\tconst rgbMatch = /^rgba?\\((.+)\\)$/i.exec(value);\n\t\tif (rgbMatch) {\n\t\t\tconst normalized = rgbMatch[1].replace(/\\//g, \",\");\n\t\t\tconst parts = normalized\n\t\t\t\t.split(/[,\\s]+/)\n\t\t\t\t.map((part) => part.trim())\n\t\t\t\t.filter(Boolean);\n\t\t\tconst r = Number(parts[0]);\n\t\t\tconst g = Number(parts[1]);\n\t\t\tconst b = Number(parts[2]);\n\t\t\tif (Number.isFinite(r) && Number.isFinite(g) && Number.isFinite(b)) {\n\t\t\t\treturn [r, g, b];\n\t\t\t}\n\t\t}\n\n\t\t// Browser parser fallback (covers formats like oklch()).\n\t\tif (typeof document !== \"undefined\") {\n\t\t\tconst parserEl = document.createElement(\"span\");\n\t\t\tparserEl.style.color = value;\n\t\t\tif (typeof parserEl.style.color === \"string\" && parserEl.style.color) {\n\t\t\t\tdocument.body?.appendChild(parserEl);\n\t\t\t\tconst resolved =\n\t\t\t\t\ttypeof getComputedStyle === \"function\"\n\t\t\t\t\t\t? getComputedStyle(parserEl).color\n\t\t\t\t\t\t: \"\";\n\t\t\t\tparserEl.remove();\n\t\t\t\tconst normalizedResolved = resolved.trim();\n\t\t\t\t// Guard against recursive loops when computed style returns the same\n\t\t\t\t// unresolved function syntax (observed with certain color formats).\n\t\t\t\tif (normalizedResolved && normalizedResolved !== value) {\n\t\t\t\t\treturn this.parseColor(resolved);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn null;\n\t}\n\n\tprivate relativeLuminance([r, g, b]: [number, number, number]): number {\n\t\tconst toLinear = (channel: number) => {\n\t\t\tconst n = channel / 255;\n\t\t\treturn n <= 0.03928 ? n / 12.92 : ((n + 0.055) / 1.055) ** 2.4;\n\t\t};\n\t\tconst lr = toLinear(r);\n\t\tconst lg = toLinear(g);\n\t\tconst lb = toLinear(b);\n\t\treturn 0.2126 * lr + 0.7152 * lg + 0.0722 * lb;\n\t}\n\n\tprivate contrastRatio(\n\t\ta: [number, number, number],\n\t\tb: [number, number, number],\n\t): number {\n\t\tconst la = this.relativeLuminance(a);\n\t\tconst lb = this.relativeLuminance(b);\n\t\tconst lighter = Math.max(la, lb);\n\t\tconst darker = Math.min(la, lb);\n\t\treturn (lighter + 0.05) / (darker + 0.05);\n\t}\n\n\tprivate blend(\n\t\tfg: [number, number, number],\n\t\tbg: [number, number, number],\n\t\talpha: number,\n\t): [number, number, number] {\n\t\treturn [\n\t\t\tMath.round(fg[0] * alpha + bg[0] * (1 - alpha)),\n\t\t\tMath.round(fg[1] * alpha + bg[1] * (1 - alpha)),\n\t\t\tMath.round(fg[2] * alpha + bg[2] * (1 - alpha)),\n\t\t];\n\t}\n\n\tprivate resolveAdaptiveTTSStyle(sourceEl?: Element | null): {\n\t\twordHighlight: string;\n\t\tsentenceHighlight: string;\n\t\twordUnderline: string;\n\t\twordShadow: string;\n\t} {\n\t\tconst fallbackMissing: [number, number, number] = [255, 235, 59];\n\t\tconst fallbackText: [number, number, number] = [17, 24, 39];\n\t\tconst fallbackBackground: [number, number, number] = [255, 255, 255];\n\n\t\tconst target =\n\t\t\tsourceEl ||\n\t\t\t(typeof document !== \"undefined\" ? document.documentElement : null);\n\t\tconst computed =\n\t\t\ttarget && typeof getComputedStyle === \"function\"\n\t\t\t\t? getComputedStyle(target)\n\t\t\t\t: null;\n\n\t\tconst background =\n\t\t\tthis.parseColor(\n\t\t\t\tcomputed?.getPropertyValue(\"--pie-background\") || computed?.backgroundColor,\n\t\t\t) || fallbackBackground;\n\t\tconst text =\n\t\t\tthis.parseColor(computed?.getPropertyValue(\"--pie-text\")) || fallbackText;\n\t\tconst accent = this.explicitTTSColorOverride\n\t\t\t? this.parseColor(this.explicitTTSColorOverride.color) || fallbackMissing\n\t\t\t: this.parseColor(computed?.getPropertyValue(\"--pie-missing\")) ||\n\t\t\t\tfallbackMissing;\n\n\t\tconst opacityCandidates = this.explicitTTSColorOverride\n\t\t\t? [Math.max(0.3, Math.min(0.95, this.explicitTTSColorOverride.opacity))]\n\t\t\t: [0.8, 0.72, 0.68, 0.62, 0.56, 0.5];\n\n\t\tlet selectedOpacity = opacityCandidates[opacityCandidates.length - 1];\n\t\tlet bestScore = -Infinity;\n\n\t\tfor (const opacity of opacityCandidates) {\n\t\t\tconst blended = this.blend(accent, background, opacity);\n\t\t\tconst backgroundDelta = this.contrastRatio(blended, background);\n\t\t\tconst textContrast = this.contrastRatio(blended, text);\n\t\t\tconst score = backgroundDelta * 1.2 + textContrast * 0.8;\n\t\t\tif (backgroundDelta >= 1.25 && textContrast >= 2.4) {\n\t\t\t\tselectedOpacity = opacity;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (score > bestScore) {\n\t\t\t\tbestScore = score;\n\t\t\t\tselectedOpacity = opacity;\n\t\t\t}\n\t\t}\n\n\t\tconst sentenceOpacity = Math.max(0.24, Math.min(0.85, selectedOpacity * 0.55));\n\t\tconst underlineOpacity = Math.max(0.55, Math.min(0.95, selectedOpacity + 0.2));\n\t\tconst shadowOpacity = Math.max(0.22, Math.min(0.6, selectedOpacity * 0.45));\n\n\t\tconst underlineColor = text;\n\t\tconst underlineBlend = this.blend(underlineColor, background, underlineOpacity);\n\t\tconst underlineDelta = this.contrastRatio(underlineBlend, background);\n\t\tconst fallbackUnderline: [number, number, number] =\n\t\t\tthis.relativeLuminance(background) > 0.45 ? [0, 0, 0] : [255, 255, 255];\n\t\tconst finalUnderline = underlineDelta >= 1.35 ? underlineColor : fallbackUnderline;\n\n\t\tconst wordHighlight = `rgba(${accent[0]}, ${accent[1]}, ${accent[2]}, ${selectedOpacity})`;\n\t\tconst sentenceHighlight = `rgba(${accent[0]}, ${accent[1]}, ${accent[2]}, ${sentenceOpacity})`;\n\t\tconst wordUnderline = `rgba(${finalUnderline[0]}, ${finalUnderline[1]}, ${finalUnderline[2]}, ${underlineOpacity})`;\n\t\tconst wordShadow = `rgba(${finalUnderline[0]}, ${finalUnderline[1]}, ${finalUnderline[2]}, ${shadowOpacity})`;\n\n\t\treturn {\n\t\t\twordHighlight,\n\t\t\tsentenceHighlight,\n\t\t\twordUnderline,\n\t\t\twordShadow,\n\t\t};\n\t}\n\n\tprivate applyAdaptiveTTSStyle(sourceEl?: Element | null): void {\n\t\tif (typeof document === \"undefined\") return;\n\t\tconst vars = this.resolveAdaptiveTTSStyle(sourceEl);\n\t\tdocument.documentElement.style.setProperty(\n\t\t\t\"--pie-tts-word-highlight\",\n\t\t\tvars.wordHighlight,\n\t\t);\n\t\tdocument.documentElement.style.setProperty(\n\t\t\t\"--pie-tts-sentence-highlight\",\n\t\t\tvars.sentenceHighlight,\n\t\t);\n\t\tdocument.documentElement.style.setProperty(\n\t\t\t\"--pie-tts-line-highlight\",\n\t\t\tvars.sentenceHighlight,\n\t\t);\n\t\tdocument.documentElement.style.setProperty(\n\t\t\t\"--pie-tts-word-underline\",\n\t\t\tvars.wordUnderline,\n\t\t);\n\t\tdocument.documentElement.style.setProperty(\n\t\t\t\"--pie-tts-word-shadow\",\n\t\t\tvars.wordShadow,\n\t\t);\n\t}\n\n\t/**\n\t * Initialize CSS Custom Highlights\n\t */\n\tprivate initializeHighlights(): void {\n\t\tif (!this.supported) return;\n\n\t\t// Create highlight registries for TTS\n\t\tthis.ttsWordHighlight = new Highlight();\n\t\tthis.ttsSentenceHighlight = new Highlight();\n\n\t\t// Register TTS highlights with CSS\n\t\tCSS.highlights.set(\"tts-word\", this.ttsWordHighlight);\n\t\tCSS.highlights.set(\"tts-sentence\", this.ttsSentenceHighlight);\n\n\t\t// Create shared highlights for each annotation color\n\t\tfor (const color of Object.values(HighlightColor)) {\n\t\t\tconst highlight = new Highlight();\n\t\t\tthis.colorHighlights.set(color, highlight);\n\t\t\tCSS.highlights.set(`annotation-${color}`, highlight);\n\t\t}\n\t}\n\n\t/**\n\t * Register CSS styles for highlights\n\t */\n\tprivate registerStyles(): void {\n\t\tif (!this.supported) return;\n\t\tif (typeof document === \"undefined\") return; // SSR guard\n\n\t\t// Check if styles already exist\n\t\tif (document.getElementById(\"pie-highlight-styles\")) return;\n\n\t\tconst style = document.createElement(\"style\");\n\t\tstyle.id = \"pie-highlight-styles\";\n\t\tstyle.textContent = `\n /* TTS highlights - temporary */\n ::highlight(tts-word) {\n background-color: var(--pie-tts-word-highlight, color-mix(in srgb, var(--pie-missing, #ffeb3b) 68%, transparent));\n text-decoration: underline 2px solid var(--pie-tts-word-underline, color-mix(in srgb, var(--pie-text, #111827) 70%, transparent));\n text-underline-offset: 2px;\n text-shadow: 0 0 1px var(--pie-tts-word-shadow, color-mix(in srgb, var(--pie-text, #111827) 35%, transparent));\n color: inherit;\n }\n\n /* tts-sentence registry id: coarse read-along band (visual line boxes in layout) */\n ::highlight(tts-sentence) {\n background-color: var(--pie-tts-line-highlight, var(--pie-tts-sentence-highlight, color-mix(in srgb, var(--pie-missing, #ffeb3b) 38%, transparent)));\n color: inherit;\n }\n\n [data-pie-tts-sentence-element=\"true\"] {\n background-color: var(--pie-tts-line-highlight, var(--pie-tts-sentence-highlight, color-mix(in srgb, var(--pie-missing, #ffeb3b) 38%, transparent)));\n border-radius: 0.12em;\n box-decoration-break: clone;\n -webkit-box-decoration-break: clone;\n }\n\n [data-pie-tts-word-element=\"true\"] {\n background-color: var(--pie-tts-word-highlight, color-mix(in srgb, var(--pie-missing, #ffeb3b) 68%, transparent));\n text-decoration: underline 2px solid var(--pie-tts-word-underline, color-mix(in srgb, var(--pie-text, #111827) 70%, transparent));\n text-underline-offset: 2px;\n text-shadow: 0 0 1px var(--pie-tts-word-shadow, color-mix(in srgb, var(--pie-text, #111827) 35%, transparent));\n border-bottom: 2px solid var(--pie-tts-word-underline, color-mix(in srgb, var(--pie-text, #111827) 70%, transparent));\n padding-bottom: 1px;\n border-radius: 0.12em;\n box-decoration-break: clone;\n -webkit-box-decoration-break: clone;\n }\n\n /* Annotation highlights - persistent */\n ::highlight(annotation-yellow) {\n background-color: color-mix(in srgb, var(--pie-missing, #ffff00) 35%, transparent);\n color: inherit;\n }\n\n ::highlight(annotation-green) {\n background-color: color-mix(in srgb, var(--pie-correct, #90ee90) 35%, transparent);\n color: inherit;\n }\n\n ::highlight(annotation-blue) {\n background-color: color-mix(in srgb, var(--pie-tertiary, #add8e6) 35%, transparent);\n color: inherit;\n }\n\n ::highlight(annotation-pink) {\n background-color: color-mix(in srgb, var(--pie-secondary-light, #ffb6c1) 35%, transparent);\n color: inherit;\n }\n\n ::highlight(annotation-orange) {\n background-color: color-mix(in srgb, var(--pie-incorrect, #ffa500) 35%, transparent);\n color: inherit;\n }\n\n ::highlight(annotation-underline) {\n background-color: transparent;\n text-decoration: underline 2px solid var(--pie-primary, #0066cc);\n text-underline-offset: 2px;\n color: inherit;\n }\n `;\n\t\tdocument.head.appendChild(style);\n\t}\n\n\t/**\n\t * Highlight a word for TTS (temporary)\n\t *\n\t * @param textNode Text node containing the word\n\t * @param startOffset Start position in text node\n\t * @param endOffset End position in text node\n\t */\n\thighlightTTSWord(\n\t\ttextNode: Text,\n\t\tstartOffset: number,\n\t\tendOffset: number,\n\t): void {\n\t\tif (!this.ttsWordHighlight) return;\n\t\tthis.applyAdaptiveTTSStyle(textNode.parentElement);\n\n\t\t// Clear previous word highlight\n\t\tthis.clearTTSWord();\n\n\t\t// Create range for word\n\t\tconst range = document.createRange();\n\t\trange.setStart(textNode, startOffset);\n\t\trange.setEnd(textNode, endOffset);\n\n\t\t// Add to highlight\n\t\tthis.ttsWordHighlight.add(range);\n\t}\n\n\t/**\n\t * Highlight a single element as the active TTS word (temporary).\n\t *\n\t * Unlike {@link highlightTTSWord} (which paints a CSS range over a text node)\n\t * this marks the element itself via `data-pie-tts-word-element`. It is used\n\t * for atomic targets that have no direct text node to range over — most\n\t * notably MathJax CHTML tokens (e.g. `<mjx-mi><mjx-c/></mjx-mi>`, whose glyph\n\t * lives in a font-driven pseudo-element a CSS range cannot paint) and\n\t * whole-expression fallbacks.\n\t *\n\t * The supplied element is painted exactly; we deliberately do NOT walk up to\n\t * a containing `<math>` / `<mjx-container>`. That escalation is what made\n\t * MathJax-rendered math highlight as a full block while native MathML tracked\n\t * per-token: a resolved single token must paint as a token, and only a\n\t * genuine expression fallback (where the element already is the container)\n\t * should paint the whole expression.\n\t */\n\thighlightTTSWordElement(element: Element): void {\n\t\tif (!this.ttsWordHighlight) return;\n\t\tthis.applyAdaptiveTTSStyle(element);\n\n\t\t// Clear previous word highlight (CSS range and any element attributes)\n\t\tthis.clearTTSWord();\n\n\t\telement.setAttribute(\"data-pie-tts-word-element\", \"true\");\n\t\tthis.ttsWordElementHighlights.add(element);\n\t}\n\n\t/**\n\t * Highlight the coarse TTS read-along band (temporary).\n\t * Usually one Range per visual line; CSS layer `tts-sentence` for compatibility.\n\t *\n\t * @param ranges Line (or sentence) ranges to paint with `--pie-tts-line-highlight`\n\t */\n\thighlightTTSSentence(ranges: Range[]): void {\n\t\tif (!this.ttsSentenceHighlight) return;\n\t\tconst source = ranges[0]?.startContainer;\n\t\tconst sourceElement =\n\t\t\tsource?.nodeType === Node.ELEMENT_NODE\n\t\t\t\t? (source as Element)\n\t\t\t\t: source?.parentElement;\n\t\tthis.applyAdaptiveTTSStyle(sourceElement);\n\n\t\t// Clear previous sentence highlight\n\t\tthis.clearTTSSentence();\n\n\t\t// Add all ranges\n\t\tfor (const range of ranges) {\n\t\t\tthis.ttsSentenceHighlight.add(range);\n\t\t}\n\t\tthis.highlightTTSElementFallbacks(ranges);\n\t}\n\n\t// The read-along (sentence) band legitimately covers whole equations and\n\t// replaced elements, so it escalates to them.\n\tprivate static readonly SENTENCE_FALLBACK_SELECTOR =\n\t\t\"math, mjx-container, svg, img, canvas, [role='img']\";\n\n\t// The word layer must NOT escalate a multi-node range to the enclosing\n\t// `<math>` / `<mjx-container>`: that is what made an equation flash as a\n\t// whole block whenever a spoken word's visible range crossed several math\n\t// glyph nodes. Math is tracked per token (or held / region) by the highlight\n\t// pipeline instead. Replaced elements (svg/img/canvas) still need the element\n\t// fallback because a CSS range cannot paint them.\n\tprivate static readonly WORD_FALLBACK_SELECTOR =\n\t\t\"svg, img, canvas, [role='img']\";\n\n\tprivate highlightTTSElementFallbacks(ranges: Range[]): void {\n\t\tif (typeof Element === \"undefined\") return;\n\t\tthis.highlightElementFallbacks(\n\t\t\tranges,\n\t\t\t\"data-pie-tts-sentence-element\",\n\t\t\tthis.ttsSentenceElementHighlights,\n\t\t\tHighlightCoordinator.SENTENCE_FALLBACK_SELECTOR,\n\t\t);\n\t}\n\n\tprivate highlightTTSWordElementFallbacks(ranges: Range[]): void {\n\t\tif (typeof Element === \"undefined\") return;\n\t\tthis.highlightElementFallbacks(\n\t\t\tranges,\n\t\t\t\"data-pie-tts-word-element\",\n\t\t\tthis.ttsWordElementHighlights,\n\t\t\tHighlightCoordinator.WORD_FALLBACK_SELECTOR,\n\t\t);\n\t}\n\n\tprivate highlightElementFallbacks(\n\t\tranges: Range[],\n\t\tattributeName: string,\n\t\ttrackedElements: Set<Element>,\n\t\tselector: string,\n\t): void {\n\t\tfor (const range of ranges) {\n\t\t\tconst root =\n\t\t\t\trange.commonAncestorContainer.nodeType === Node.ELEMENT_NODE\n\t\t\t\t\t? (range.commonAncestorContainer as Element)\n\t\t\t\t\t: range.commonAncestorContainer.parentElement;\n\t\t\tif (!root) continue;\n\t\t\tconst candidates: Element[] = [];\n\t\t\tconst rangeStartElement =\n\t\t\t\trange.startContainer.nodeType === Node.ELEMENT_NODE\n\t\t\t\t\t? (range.startContainer as Element)\n\t\t\t\t\t: range.startContainer.parentElement;\n\t\t\tconst rangeEndElement =\n\t\t\t\trange.endContainer.nodeType === Node.ELEMENT_NODE\n\t\t\t\t\t? (range.endContainer as Element)\n\t\t\t\t\t: range.endContainer.parentElement;\n\t\t\tfor (const element of [rangeStartElement, rangeEndElement]) {\n\t\t\t\tlet current: Element | null = element;\n\t\t\t\twhile (current) {\n\t\t\t\t\tif (current.matches?.(selector)) candidates.push(current);\n\t\t\t\t\tcurrent = current.parentElement;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (root.matches?.(selector)) {\n\t\t\t\tcandidates.push(root);\n\t\t\t}\n\t\t\tcandidates.push(...Array.from(root.querySelectorAll(selector)));\n\t\t\tfor (const element of new Set(candidates)) {\n\t\t\t\ttry {\n\t\t\t\t\tif (\n\t\t\t\t\t\t!range.intersectsNode(element) &&\n\t\t\t\t\t\t!element.contains(rangeStartElement) &&\n\t\t\t\t\t\t!element.contains(rangeEndElement)\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\telement.setAttribute(attributeName, \"true\");\n\t\t\t\ttrackedElements.add(element);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Clear TTS word highlight\n\t */\n\tclearTTSWord(): void {\n\t\tif (!this.ttsWordHighlight) return;\n\t\tthis.ttsWordHighlight.clear();\n\t\tfor (const element of this.ttsWordElementHighlights) {\n\t\t\telement.removeAttribute(\"data-pie-tts-word-element\");\n\t\t}\n\t\tthis.ttsWordElementHighlights.clear();\n\t}\n\n\t/**\n\t * Clear TTS sentence highlight\n\t */\n\tclearTTSSentence(): void {\n\t\tif (!this.ttsSentenceHighlight) return;\n\t\tthis.ttsSentenceHighlight.clear();\n\t\tfor (const element of this.ttsSentenceElementHighlights) {\n\t\t\telement.removeAttribute(\"data-pie-tts-sentence-element\");\n\t\t}\n\t\tthis.ttsSentenceElementHighlights.clear();\n\t}\n\n\t/**\n\t * Clear all TTS highlights\n\t */\n\tclearTTS(): void {\n\t\tthis.clearTTSWord();\n\t\tthis.clearTTSSentence();\n\t}\n\n\t/**\n\t * Add an annotation highlight (persistent)\n\t *\n\t * @param range Text range to annotate\n\t * @param color Highlight color\n\t * @returns Annotation ID for later removal\n\t */\n\taddAnnotation(\n\t\trange: Range,\n\t\tcolor: HighlightColor = HighlightColor.YELLOW,\n\t): string {\n\t\tconst id = `annotation-${this.nextAnnotationId++}`;\n\n\t\t// Clone the range to store\n\t\tconst clonedRange = range.cloneRange();\n\n\t\t// Store annotation data\n\t\tconst annotation: Annotation = {\n\t\t\tid,\n\t\t\trange: clonedRange,\n\t\t\ttype: HighlightType.ANNOTATION,\n\t\t\tcolor,\n\t\t\ttimestamp: Date.now(),\n\t\t};\n\t\tthis.annotations.set(id, annotation);\n\n\t\t// Add the SAME range object to the shared color highlight\n\t\t// This ensures we can later delete it by reference\n\t\tconst colorHighlight = this.colorHighlights.get(color);\n\t\tif (colorHighlight) {\n\t\t\tcolorHighlight.add(clonedRange);\n\t\t}\n\n\t\treturn id;\n\t}\n\n\t/**\n\t * Remove an annotation\n\t *\n\t * @param id Annotation ID\n\t */\n\tremoveAnnotation(id: string): void {\n\t\tconst annotation = this.annotations.get(id);\n\t\tif (!annotation) {\n\t\t\tconsole.warn(`[HighlightCoordinator] Annotation ${id} not found`);\n\t\t\treturn;\n\t\t}\n\n\t\tconsole.log(\n\t\t\t`[HighlightCoordinator] Removing annotation ${id} (color: ${annotation.color})`,\n\t\t);\n\n\t\t// Remove range from the shared color highlight\n\t\tconst colorHighlight = this.colorHighlights.get(annotation.color);\n\t\tif (colorHighlight) {\n\t\t\tconst deleted = colorHighlight.delete(annotation.range);\n\t\t\tconsole.log(\n\t\t\t\t`[HighlightCoordinator] Highlight.delete() returned:`,\n\t\t\t\tdeleted,\n\t\t\t);\n\t\t}\n\n\t\t// Clean up\n\t\tthis.annotations.delete(id);\n\t\tconsole.log(\n\t\t\t`[HighlightCoordinator] Annotation ${id} removed from map. Remaining:`,\n\t\t\tthis.annotations.size,\n\t\t);\n\t}\n\n\t/**\n\t * Remove all annotations\n\t */\n\tclearAnnotations(): void {\n\t\t// Clear all color highlights\n\t\tfor (const colorHighlight of this.colorHighlights.values()) {\n\t\t\tcolorHighlight.clear();\n\t\t}\n\n\t\t// Clear annotation data\n\t\tthis.annotations.clear();\n\t}\n\n\t/**\n\t * Get all annotations\n\t */\n\tgetAnnotations(): Annotation[] {\n\t\treturn Array.from(this.annotations.values());\n\t}\n\n\t/**\n\t * Get annotation by ID\n\t */\n\tgetAnnotation(id: string): Annotation | null {\n\t\treturn this.annotations.get(id) ?? null;\n\t}\n\n\t/**\n\t * Change annotation color\n\t *\n\t * @param id Annotation ID\n\t * @param newColor New color\n\t */\n\tchangeAnnotationColor(id: string, newColor: HighlightColor): void {\n\t\tconst annotation = this.annotations.get(id);\n\t\tif (!annotation) return;\n\n\t\tconst oldColor = annotation.color;\n\t\tif (oldColor === newColor) return;\n\n\t\t// Remove from old color highlight\n\t\tconst oldColorHighlight = this.colorHighlights.get(oldColor);\n\t\tif (oldColorHighlight) {\n\t\t\toldColorHighlight.delete(annotation.range);\n\t\t}\n\n\t\t// Update color\n\t\tannotation.color = newColor;\n\n\t\t// Add to new color highlight\n\t\tconst newColorHighlight = this.colorHighlights.get(newColor);\n\t\tif (newColorHighlight) {\n\t\t\tnewColorHighlight.add(annotation.range);\n\t\t}\n\t}\n\n\t/**\n\t * Export annotations as serializable data for persistence.\n\t * Uses RangeSerializer for robust DOM range serialization.\n\t *\n\t * @param root Root element for serialization (typically document.body or content container)\n\t * @returns Array of serialized annotations\n\t */\n\texportAnnotations(\n\t\troot: Element = document.body,\n\t): Array<\n\t\tSerializedRange & { id: string; color: HighlightColor; timestamp: number }\n\t> {\n\t\treturn this.getAnnotations().map((annotation) => ({\n\t\t\t...this.rangeSerializer.serialize(annotation.range, root),\n\t\t\tid: annotation.id,\n\t\t\tcolor: annotation.color,\n\t\t\ttimestamp: annotation.timestamp,\n\t\t}));\n\t}\n\n\t/**\n\t * Import annotations from serialized data.\n\t * Restores annotations after page navigation or refresh.\n\t *\n\t * @param data Array of serialized annotations\n\t * @param root Root element for deserialization (same as used in export)\n\t * @returns Number of successfully restored annotations\n\t */\n\timportAnnotations(\n\t\tdata: Array<\n\t\t\tSerializedRange & {\n\t\t\t\tid?: string;\n\t\t\t\tcolor: HighlightColor;\n\t\t\t\ttimestamp?: number;\n\t\t\t}\n\t\t>,\n\t\troot: Element = document.body,\n\t): number {\n\t\tlet restored = 0;\n\n\t\tfor (const item of data) {\n\t\t\tconst range = this.rangeSerializer.deserialize(item, root);\n\t\t\tif (range) {\n\t\t\t\tthis.addAnnotation(range, item.color);\n\t\t\t\trestored++;\n\t\t\t}\n\t\t}\n\n\t\treturn restored;\n\t}\n\n\t// ============================================================================\n\t// HighlightCoordinatorApi interface implementation\n\t// ============================================================================\n\n\t/**\n\t * Highlight a text range (interface method)\n\t *\n\t * Generic method that adapts to the specific highlight type.\n\t * For more control, use the specific methods like highlightTTSWord().\n\t */\n\thighlightRange(\n\t\trange: Range,\n\t\ttype: HighlightType,\n\t\tcolor: HighlightColor = HighlightColor.YELLOW,\n\t): void {\n\t\tif (!this.supported) return;\n\n\t\tswitch (type) {\n\t\t\tcase HighlightType.TTS_WORD:\n\t\t\tcase HighlightType.TTS_SENTENCE: {\n\t\t\t\t// For TTS, add to appropriate highlight\n\t\t\t\tconst highlight =\n\t\t\t\t\ttype === HighlightType.TTS_WORD\n\t\t\t\t\t\t? this.ttsWordHighlight\n\t\t\t\t\t\t: this.ttsSentenceHighlight;\n\t\t\t\tif (highlight) {\n\t\t\t\t\thighlight.clear();\n\t\t\t\t\thighlight.add(range);\n\t\t\t\t\tif (type === HighlightType.TTS_WORD) {\n\t\t\t\t\t\tfor (const element of this.ttsWordElementHighlights) {\n\t\t\t\t\t\t\telement.removeAttribute(\"data-pie-tts-word-element\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.ttsWordElementHighlights.clear();\n\t\t\t\t\t\tthis.highlightTTSWordElementFallbacks([range]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase HighlightType.ANNOTATION:\n\t\t\t\t// For annotations, use the existing method\n\t\t\t\tthis.addAnnotation(range, color);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\t/**\n\t * Clear highlights of a specific type (interface method)\n\t */\n\tclearHighlights(type: HighlightType): void {\n\t\tif (!this.supported) return;\n\n\t\tswitch (type) {\n\t\t\tcase HighlightType.TTS_WORD:\n\t\t\t\tthis.clearTTSWord();\n\t\t\t\tbreak;\n\t\t\tcase HighlightType.TTS_SENTENCE:\n\t\t\t\tthis.clearTTSSentence();\n\t\t\t\tbreak;\n\t\t\tcase HighlightType.ANNOTATION:\n\t\t\t\tthis.clearAnnotations();\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\t/**\n\t * Clear all highlights (interface method)\n\t */\n\tclearAll(): void {\n\t\tif (!this.supported) return;\n\t\tthis.clearTTS();\n\t\tthis.clearAnnotations();\n\t}\n\n\t/**\n\t * Check if CSS Highlight API is supported (interface method)\n\t */\n\tisSupported(): boolean {\n\t\treturn this.supported;\n\t}\n\n\t/**\n\t * Update TTS highlight style dynamically\n\t *\n\t * @param color CSS color value (e.g., '#ffeb3b')\n\t * @param opacity Opacity value (0.0 to 1.0)\n\t */\n\tupdateTTSHighlightStyle(color: string, opacity: number): void {\n\t\tif (!this.supported) return;\n\t\tif (typeof document === \"undefined\") return;\n\n\t\tconst styleEl = document.getElementById(\"pie-highlight-styles\");\n\t\tif (!styleEl) return;\n\n\t\t// Convert hex to rgba\n\t\tconst hexToRgb = (hex: string) => {\n\t\t\tconst result = /^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(hex);\n\t\t\treturn result\n\t\t\t\t? {\n\t\t\t\t\t\tr: parseInt(result[1], 16),\n\t\t\t\t\t\tg: parseInt(result[2], 16),\n\t\t\t\t\t\tb: parseInt(result[3], 16),\n\t\t\t\t\t}\n\t\t\t\t: null;\n\t\t};\n\n\t\tconst rgb = hexToRgb(color);\n\t\tif (!rgb) return;\n\n\t\tthis.explicitTTSColorOverride = {\n\t\t\tcolor: `rgb(${rgb.r}, ${rgb.g}, ${rgb.b})`,\n\t\t\topacity: Math.max(0.2, Math.min(0.95, opacity)),\n\t\t};\n\t\tthis.applyAdaptiveTTSStyle();\n\t}\n\n\t/**\n\t * Cleanup - remove all highlights\n\t */\n\tdestroy(): void {\n\t\tif (!this.supported) return;\n\n\t\tthis.clearTTS();\n\t\tthis.clearAnnotations();\n\n\t\t// Remove style element\n\t\tif (typeof document !== \"undefined\") {\n\t\t\tconst styleEl = document.getElementById(\"pie-highlight-styles\");\n\t\t\tif (styleEl) {\n\t\t\t\tstyleEl.remove();\n\t\t\t}\n\t\t}\n\t\tthis.themeObserver?.disconnect();\n\t\tthis.themeObserver = null;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"HighlightCoordinator.js","sourceRoot":"","sources":["../../src/services/HighlightCoordinator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,EAAE,eAAe,EAAwB,MAAM,sBAAsB,CAAC;AAE7E;;GAEG;AACH,MAAM,CAAN,IAAY,aAIX;AAJD,WAAY,aAAa;IACxB,sCAAqB,CAAA;IACrB,8CAA6B,CAAA;IAC7B,0CAAyB,CAAA;AAC1B,CAAC,EAJW,aAAa,KAAb,aAAa,QAIxB;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,cAOX;AAPD,WAAY,cAAc;IACzB,mCAAiB,CAAA;IACjB,iCAAe,CAAA;IACf,+BAAa,CAAA;IACb,+BAAa,CAAA;IACb,mCAAiB,CAAA;IACjB,yCAAuB,CAAA;AACxB,CAAC,EAPW,cAAc,KAAd,cAAc,QAOzB;AAmBD,MAAM,OAAO,oBAAoB;IACxB,MAAM,CAA6B;IACnC,gBAAgB,GAAqB,IAAI,CAAC;IAC1C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AC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;SAC/C,CAAC;QACF,IAAI,CAAC,qBAAqB,EAAE,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,OAAO;QACN,IAAI,CAAC,IAAI,CAAC,SAAS;YAAE,OAAO;QAE5B,IAAI,CAAC,QAAQ,EAAE,CAAC;QAChB,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAExB,uBAAuB;QACvB,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE,CAAC;YACrC,MAAM,OAAO,GAAG,QAAQ,CAAC,cAAc,CAAC,sBAAsB,CAAC,CAAC;YAChE,IAAI,OAAO,EAAE,CAAC;gBACb,OAAO,CAAC,MAAM,EAAE,CAAC;YAClB,CAAC;QACF,CAAC;QACD,IAAI,CAAC,aAAa,EAAE,UAAU,EAAE,CAAC;QACjC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;IAC3B,CAAC","sourcesContent":["/**\n * HighlightCoordinator\n *\n * Manages separate highlight layers for TTS (temporary) and annotations (persistent).\n * Uses CSS Custom Highlight API - zero DOM mutation, preserves accessibility.\n *\n * Features:\n * - Separate layers prevent TTS clearing from removing student annotations\n * - CSS Custom Highlight API (no DOM mutation)\n * - Full accessibility support (screen readers see original text)\n * - Configurable colors and styles\n * - Annotation persistence via RangeSerializer\n *\n * Part of PIE Assessment Toolkit.\n *\n * Browser Support:\n * - Chrome/Edge 105+\n * - Safari 17.2+\n * - Firefox: Behind flag (not recommended for production)\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/CSS_Custom_Highlight_API\n */\n\nimport type { HighlightCoordinatorApi } from \"./interfaces.js\";\nimport { RangeSerializer, type SerializedRange } from \"./RangeSerializer.js\";\n\n/**\n * Highlight types\n */\nexport enum HighlightType {\n\tTTS_WORD = \"tts-word\",\n\tTTS_SENTENCE = \"tts-sentence\",\n\tANNOTATION = \"annotation\",\n}\n\n/**\n * Highlight colors for annotations\n */\nexport enum HighlightColor {\n\tYELLOW = \"yellow\",\n\tGREEN = \"green\",\n\tBLUE = \"blue\",\n\tPINK = \"pink\",\n\tORANGE = \"orange\",\n\tUNDERLINE = \"underline\",\n}\n\n/**\n * Annotation data\n */\nexport interface Annotation {\n\tid: string;\n\trange: Range;\n\ttype: HighlightType.ANNOTATION;\n\tcolor: HighlightColor;\n\ttimestamp: number;\n}\n\n/**\n * Configuration for HighlightCoordinator\n * Currently empty but allows future extension without breaking changes\n */\nexport type HighlightCoordinatorConfig = Record<string, never>;\n\nexport class HighlightCoordinator implements HighlightCoordinatorApi {\n\tprivate config: HighlightCoordinatorConfig;\n\tprivate ttsWordHighlight: Highlight | null = null;\n\tprivate ttsSentenceHighlight: Highlight | null = null;\n\tprivate ttsWordElementHighlights = new Set<Element>();\n\tprivate ttsSentenceElementHighlights = new Set<Element>();\n\tprivate annotations = new Map<string, Annotation>();\n\t// Shared highlights per color (one Highlight object per color, contains all ranges)\n\tprivate colorHighlights = new Map<HighlightColor, Highlight>();\n\tprivate nextAnnotationId = 1;\n\tprivate supported = false;\n\tprivate rangeSerializer: RangeSerializer;\n\tprivate themeObserver: MutationObserver | null = null;\n\tprivate explicitTTSColorOverride: { color: string; opacity: number } | null =\n\t\tnull;\n\n\tconstructor(config: HighlightCoordinatorConfig = {}) {\n\t\tthis.config = config;\n\t\tthis.rangeSerializer = new RangeSerializer();\n\n\t\t// SSR guard\n\t\tif (typeof CSS === \"undefined\" || !(\"highlights\" in CSS)) {\n\t\t\tconsole.warn(\n\t\t\t\t\"CSS Custom Highlight API not supported (SSR or unsupported browser)\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.supported = true;\n\t\tthis.initializeHighlights();\n\t\tthis.registerStyles();\n\t\tthis.applyAdaptiveTTSStyle();\n\t\tthis.setupThemeObservation();\n\t}\n\n\tprivate setupThemeObservation(): void {\n\t\tif (typeof document === \"undefined\") return;\n\t\tif (typeof MutationObserver === \"undefined\") return;\n\n\t\tconst refresh = () => this.applyAdaptiveTTSStyle();\n\t\tthis.themeObserver = new MutationObserver(refresh);\n\n\t\tthis.themeObserver.observe(document.documentElement, {\n\t\t\tattributes: true,\n\t\t\tattributeFilter: [\"style\", \"data-theme\", \"data-color-scheme\", \"class\"],\n\t\t});\n\n\t\tfor (const host of document.querySelectorAll(\"pie-theme\")) {\n\t\t\tthis.themeObserver.observe(host, {\n\t\t\t\tattributes: true,\n\t\t\t\tattributeFilter: [\n\t\t\t\t\t\"theme\",\n\t\t\t\t\t\"scheme\",\n\t\t\t\t\t\"provider\",\n\t\t\t\t\t\"variables\",\n\t\t\t\t\t\"style\",\n\t\t\t\t\t\"data-theme\",\n\t\t\t\t\t\"data-color-scheme\",\n\t\t\t\t],\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate parseColor(\n\t\tinput: string | null | undefined,\n\t): [number, number, number] | null {\n\t\tif (!input) return null;\n\t\tconst value = input.trim();\n\t\tif (!value) return null;\n\n\t\tconst hexMatch = /^#([a-f\\d]{3}|[a-f\\d]{6})$/i.exec(value);\n\t\tif (hexMatch) {\n\t\t\tconst hex = hexMatch[1];\n\t\t\tif (hex.length === 3) {\n\t\t\t\treturn [\n\t\t\t\t\tparseInt(hex[0] + hex[0], 16),\n\t\t\t\t\tparseInt(hex[1] + hex[1], 16),\n\t\t\t\t\tparseInt(hex[2] + hex[2], 16),\n\t\t\t\t];\n\t\t\t}\n\t\t\treturn [\n\t\t\t\tparseInt(hex.slice(0, 2), 16),\n\t\t\t\tparseInt(hex.slice(2, 4), 16),\n\t\t\t\tparseInt(hex.slice(4, 6), 16),\n\t\t\t];\n\t\t}\n\n\t\tconst rgbMatch = /^rgba?\\((.+)\\)$/i.exec(value);\n\t\tif (rgbMatch) {\n\t\t\tconst normalized = rgbMatch[1].replace(/\\//g, \",\");\n\t\t\tconst parts = normalized\n\t\t\t\t.split(/[,\\s]+/)\n\t\t\t\t.map((part) => part.trim())\n\t\t\t\t.filter(Boolean);\n\t\t\tconst r = Number(parts[0]);\n\t\t\tconst g = Number(parts[1]);\n\t\t\tconst b = Number(parts[2]);\n\t\t\tif (Number.isFinite(r) && Number.isFinite(g) && Number.isFinite(b)) {\n\t\t\t\treturn [r, g, b];\n\t\t\t}\n\t\t}\n\n\t\t// Browser parser fallback (covers formats like oklch()).\n\t\tif (typeof document !== \"undefined\") {\n\t\t\tconst parserEl = document.createElement(\"span\");\n\t\t\tparserEl.style.color = value;\n\t\t\tif (typeof parserEl.style.color === \"string\" && parserEl.style.color) {\n\t\t\t\tdocument.body?.appendChild(parserEl);\n\t\t\t\tconst resolved =\n\t\t\t\t\ttypeof getComputedStyle === \"function\"\n\t\t\t\t\t\t? getComputedStyle(parserEl).color\n\t\t\t\t\t\t: \"\";\n\t\t\t\tparserEl.remove();\n\t\t\t\tconst normalizedResolved = resolved.trim();\n\t\t\t\t// Guard against recursive loops when computed style returns the same\n\t\t\t\t// unresolved function syntax (observed with certain color formats).\n\t\t\t\tif (normalizedResolved && normalizedResolved !== value) {\n\t\t\t\t\treturn this.parseColor(resolved);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn null;\n\t}\n\n\tprivate relativeLuminance([r, g, b]: [number, number, number]): number {\n\t\tconst toLinear = (channel: number) => {\n\t\t\tconst n = channel / 255;\n\t\t\treturn n <= 0.03928 ? n / 12.92 : ((n + 0.055) / 1.055) ** 2.4;\n\t\t};\n\t\tconst lr = toLinear(r);\n\t\tconst lg = toLinear(g);\n\t\tconst lb = toLinear(b);\n\t\treturn 0.2126 * lr + 0.7152 * lg + 0.0722 * lb;\n\t}\n\n\tprivate contrastRatio(\n\t\ta: [number, number, number],\n\t\tb: [number, number, number],\n\t): number {\n\t\tconst la = this.relativeLuminance(a);\n\t\tconst lb = this.relativeLuminance(b);\n\t\tconst lighter = Math.max(la, lb);\n\t\tconst darker = Math.min(la, lb);\n\t\treturn (lighter + 0.05) / (darker + 0.05);\n\t}\n\n\tprivate blend(\n\t\tfg: [number, number, number],\n\t\tbg: [number, number, number],\n\t\talpha: number,\n\t): [number, number, number] {\n\t\treturn [\n\t\t\tMath.round(fg[0] * alpha + bg[0] * (1 - alpha)),\n\t\t\tMath.round(fg[1] * alpha + bg[1] * (1 - alpha)),\n\t\t\tMath.round(fg[2] * alpha + bg[2] * (1 - alpha)),\n\t\t];\n\t}\n\n\tprivate resolveAdaptiveTTSStyle(sourceEl?: Element | null): {\n\t\twordHighlight: string;\n\t\tsentenceHighlight: string;\n\t\twordUnderline: string;\n\t\twordShadow: string;\n\t} {\n\t\tconst fallbackMissing: [number, number, number] = [255, 235, 59];\n\t\tconst fallbackText: [number, number, number] = [17, 24, 39];\n\t\tconst fallbackBackground: [number, number, number] = [255, 255, 255];\n\n\t\tconst target =\n\t\t\tsourceEl ||\n\t\t\t(typeof document !== \"undefined\" ? document.documentElement : null);\n\t\tconst computed =\n\t\t\ttarget && typeof getComputedStyle === \"function\"\n\t\t\t\t? getComputedStyle(target)\n\t\t\t\t: null;\n\n\t\tconst background =\n\t\t\tthis.parseColor(\n\t\t\t\tcomputed?.getPropertyValue(\"--pie-background\") ||\n\t\t\t\t\tcomputed?.backgroundColor,\n\t\t\t) || fallbackBackground;\n\t\tconst text =\n\t\t\tthis.parseColor(computed?.getPropertyValue(\"--pie-text\")) || fallbackText;\n\t\tconst accent = this.explicitTTSColorOverride\n\t\t\t? this.parseColor(this.explicitTTSColorOverride.color) || fallbackMissing\n\t\t\t: this.parseColor(computed?.getPropertyValue(\"--pie-missing\")) ||\n\t\t\t\tfallbackMissing;\n\n\t\tconst opacityCandidates = this.explicitTTSColorOverride\n\t\t\t? [Math.max(0.3, Math.min(0.95, this.explicitTTSColorOverride.opacity))]\n\t\t\t: [0.8, 0.72, 0.68, 0.62, 0.56, 0.5];\n\n\t\tlet selectedOpacity = opacityCandidates[opacityCandidates.length - 1];\n\t\tlet bestScore = -Infinity;\n\n\t\tfor (const opacity of opacityCandidates) {\n\t\t\tconst blended = this.blend(accent, background, opacity);\n\t\t\tconst backgroundDelta = this.contrastRatio(blended, background);\n\t\t\tconst textContrast = this.contrastRatio(blended, text);\n\t\t\tconst score = backgroundDelta * 1.2 + textContrast * 0.8;\n\t\t\tif (backgroundDelta >= 1.25 && textContrast >= 2.4) {\n\t\t\t\tselectedOpacity = opacity;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (score > bestScore) {\n\t\t\t\tbestScore = score;\n\t\t\t\tselectedOpacity = opacity;\n\t\t\t}\n\t\t}\n\n\t\tconst sentenceOpacity = Math.max(\n\t\t\t0.24,\n\t\t\tMath.min(0.85, selectedOpacity * 0.55),\n\t\t);\n\t\tconst underlineOpacity = Math.max(\n\t\t\t0.55,\n\t\t\tMath.min(0.95, selectedOpacity + 0.2),\n\t\t);\n\t\tconst shadowOpacity = Math.max(0.22, Math.min(0.6, selectedOpacity * 0.45));\n\n\t\tconst underlineColor = text;\n\t\tconst underlineBlend = this.blend(\n\t\t\tunderlineColor,\n\t\t\tbackground,\n\t\t\tunderlineOpacity,\n\t\t);\n\t\tconst underlineDelta = this.contrastRatio(underlineBlend, background);\n\t\tconst fallbackUnderline: [number, number, number] =\n\t\t\tthis.relativeLuminance(background) > 0.45 ? [0, 0, 0] : [255, 255, 255];\n\t\tconst finalUnderline =\n\t\t\tunderlineDelta >= 1.35 ? underlineColor : fallbackUnderline;\n\n\t\tconst wordHighlight = `rgba(${accent[0]}, ${accent[1]}, ${accent[2]}, ${selectedOpacity})`;\n\t\tconst sentenceHighlight = `rgba(${accent[0]}, ${accent[1]}, ${accent[2]}, ${sentenceOpacity})`;\n\t\tconst wordUnderline = `rgba(${finalUnderline[0]}, ${finalUnderline[1]}, ${finalUnderline[2]}, ${underlineOpacity})`;\n\t\tconst wordShadow = `rgba(${finalUnderline[0]}, ${finalUnderline[1]}, ${finalUnderline[2]}, ${shadowOpacity})`;\n\n\t\treturn {\n\t\t\twordHighlight,\n\t\t\tsentenceHighlight,\n\t\t\twordUnderline,\n\t\t\twordShadow,\n\t\t};\n\t}\n\n\tprivate applyAdaptiveTTSStyle(sourceEl?: Element | null): void {\n\t\tif (typeof document === \"undefined\") return;\n\t\tconst vars = this.resolveAdaptiveTTSStyle(sourceEl);\n\t\tdocument.documentElement.style.setProperty(\n\t\t\t\"--pie-tts-word-highlight\",\n\t\t\tvars.wordHighlight,\n\t\t);\n\t\tdocument.documentElement.style.setProperty(\n\t\t\t\"--pie-tts-sentence-highlight\",\n\t\t\tvars.sentenceHighlight,\n\t\t);\n\t\tdocument.documentElement.style.setProperty(\n\t\t\t\"--pie-tts-line-highlight\",\n\t\t\tvars.sentenceHighlight,\n\t\t);\n\t\tdocument.documentElement.style.setProperty(\n\t\t\t\"--pie-tts-word-underline\",\n\t\t\tvars.wordUnderline,\n\t\t);\n\t\tdocument.documentElement.style.setProperty(\n\t\t\t\"--pie-tts-word-shadow\",\n\t\t\tvars.wordShadow,\n\t\t);\n\t}\n\n\t/**\n\t * Initialize CSS Custom Highlights\n\t */\n\tprivate initializeHighlights(): void {\n\t\tif (!this.supported) return;\n\n\t\t// Create highlight registries for TTS\n\t\tthis.ttsWordHighlight = new Highlight();\n\t\tthis.ttsSentenceHighlight = new Highlight();\n\n\t\t// Register TTS highlights with CSS\n\t\tCSS.highlights.set(\"tts-word\", this.ttsWordHighlight);\n\t\tCSS.highlights.set(\"tts-sentence\", this.ttsSentenceHighlight);\n\n\t\t// Create shared highlights for each annotation color\n\t\tfor (const color of Object.values(HighlightColor)) {\n\t\t\tconst highlight = new Highlight();\n\t\t\tthis.colorHighlights.set(color, highlight);\n\t\t\tCSS.highlights.set(`annotation-${color}`, highlight);\n\t\t}\n\t}\n\n\t/**\n\t * Register CSS styles for highlights\n\t */\n\tprivate registerStyles(): void {\n\t\tif (!this.supported) return;\n\t\tif (typeof document === \"undefined\") return; // SSR guard\n\n\t\t// Check if styles already exist\n\t\tif (document.getElementById(\"pie-highlight-styles\")) return;\n\n\t\tconst style = document.createElement(\"style\");\n\t\tstyle.id = \"pie-highlight-styles\";\n\t\tstyle.textContent = `\n /* TTS highlights - temporary */\n ::highlight(tts-word) {\n background-color: var(--pie-tts-word-highlight, color-mix(in srgb, var(--pie-missing, #ffeb3b) 68%, transparent));\n text-decoration: underline 2px solid var(--pie-tts-word-underline, color-mix(in srgb, var(--pie-text, #111827) 70%, transparent));\n text-underline-offset: 2px;\n text-shadow: 0 0 1px var(--pie-tts-word-shadow, color-mix(in srgb, var(--pie-text, #111827) 35%, transparent));\n color: inherit;\n }\n\n /* tts-sentence registry id: coarse read-along band (visual line boxes in layout) */\n ::highlight(tts-sentence) {\n background-color: var(--pie-tts-line-highlight, var(--pie-tts-sentence-highlight, color-mix(in srgb, var(--pie-missing, #ffeb3b) 38%, transparent)));\n color: inherit;\n }\n\n [data-pie-tts-sentence-element=\"true\"] {\n background-color: var(--pie-tts-line-highlight, var(--pie-tts-sentence-highlight, color-mix(in srgb, var(--pie-missing, #ffeb3b) 38%, transparent)));\n border-radius: 0.12em;\n box-decoration-break: clone;\n -webkit-box-decoration-break: clone;\n }\n\n [data-pie-tts-word-element=\"true\"] {\n background-color: var(--pie-tts-word-highlight, color-mix(in srgb, var(--pie-missing, #ffeb3b) 68%, transparent));\n text-decoration: underline 2px solid var(--pie-tts-word-underline, color-mix(in srgb, var(--pie-text, #111827) 70%, transparent));\n text-underline-offset: 2px;\n text-shadow: 0 0 1px var(--pie-tts-word-shadow, color-mix(in srgb, var(--pie-text, #111827) 35%, transparent));\n border-bottom: 2px solid var(--pie-tts-word-underline, color-mix(in srgb, var(--pie-text, #111827) 70%, transparent));\n padding-bottom: 1px;\n border-radius: 0.12em;\n box-decoration-break: clone;\n -webkit-box-decoration-break: clone;\n }\n\n /* Annotation highlights - persistent */\n ::highlight(annotation-yellow) {\n background-color: color-mix(in srgb, var(--pie-missing, #ffff00) 35%, transparent);\n color: inherit;\n }\n\n ::highlight(annotation-green) {\n background-color: color-mix(in srgb, var(--pie-correct, #90ee90) 35%, transparent);\n color: inherit;\n }\n\n ::highlight(annotation-blue) {\n background-color: color-mix(in srgb, var(--pie-tertiary, #add8e6) 35%, transparent);\n color: inherit;\n }\n\n ::highlight(annotation-pink) {\n background-color: color-mix(in srgb, var(--pie-secondary-light, #ffb6c1) 35%, transparent);\n color: inherit;\n }\n\n ::highlight(annotation-orange) {\n background-color: color-mix(in srgb, var(--pie-incorrect, #ffa500) 35%, transparent);\n color: inherit;\n }\n\n ::highlight(annotation-underline) {\n background-color: transparent;\n text-decoration: underline 2px solid var(--pie-primary, #0066cc);\n text-underline-offset: 2px;\n color: inherit;\n }\n `;\n\t\tdocument.head.appendChild(style);\n\t}\n\n\t/**\n\t * Highlight a word for TTS (temporary)\n\t *\n\t * @param textNode Text node containing the word\n\t * @param startOffset Start position in text node\n\t * @param endOffset End position in text node\n\t */\n\thighlightTTSWord(\n\t\ttextNode: Text,\n\t\tstartOffset: number,\n\t\tendOffset: number,\n\t): void {\n\t\tif (!this.ttsWordHighlight) return;\n\t\tthis.applyAdaptiveTTSStyle(textNode.parentElement);\n\n\t\t// Clear previous word highlight\n\t\tthis.clearTTSWord();\n\n\t\t// Create range for word\n\t\tconst range = document.createRange();\n\t\trange.setStart(textNode, startOffset);\n\t\trange.setEnd(textNode, endOffset);\n\n\t\t// Add to highlight\n\t\tthis.ttsWordHighlight.add(range);\n\t}\n\n\t/**\n\t * Highlight a single element as the active TTS word (temporary).\n\t *\n\t * Unlike {@link highlightTTSWord} (which paints a CSS range over a text node)\n\t * this marks the element itself via `data-pie-tts-word-element`. It is used\n\t * for atomic targets that have no direct text node to range over — most\n\t * notably MathJax CHTML tokens (e.g. `<mjx-mi><mjx-c/></mjx-mi>`, whose glyph\n\t * lives in a font-driven pseudo-element a CSS range cannot paint) and\n\t * whole-expression fallbacks.\n\t *\n\t * The supplied element is painted exactly; we deliberately do NOT walk up to\n\t * a containing `<math>` / `<mjx-container>`. That escalation is what made\n\t * MathJax-rendered math highlight as a full block while native MathML tracked\n\t * per-token: a resolved single token must paint as a token, and only a\n\t * genuine expression fallback (where the element already is the container)\n\t * should paint the whole expression.\n\t */\n\thighlightTTSWordElement(element: Element): void {\n\t\tif (!this.ttsWordHighlight) return;\n\t\tthis.applyAdaptiveTTSStyle(element);\n\n\t\t// Clear previous word highlight (CSS range and any element attributes)\n\t\tthis.clearTTSWord();\n\n\t\telement.setAttribute(\"data-pie-tts-word-element\", \"true\");\n\t\tthis.ttsWordElementHighlights.add(element);\n\t}\n\n\t/**\n\t * Highlight the coarse TTS read-along band (temporary).\n\t * Usually one Range per visual line; CSS layer `tts-sentence` for compatibility.\n\t *\n\t * @param ranges Line (or sentence) ranges to paint with `--pie-tts-line-highlight`\n\t */\n\thighlightTTSSentence(ranges: Range[]): void {\n\t\tif (!this.ttsSentenceHighlight) return;\n\t\tconst source = ranges[0]?.startContainer;\n\t\tconst sourceElement =\n\t\t\tsource?.nodeType === Node.ELEMENT_NODE\n\t\t\t\t? (source as Element)\n\t\t\t\t: source?.parentElement;\n\t\tthis.applyAdaptiveTTSStyle(sourceElement);\n\n\t\t// Clear previous sentence highlight\n\t\tthis.clearTTSSentence();\n\n\t\t// Add all ranges\n\t\tfor (const range of ranges) {\n\t\t\tthis.ttsSentenceHighlight.add(range);\n\t\t}\n\t\tthis.highlightTTSElementFallbacks(ranges);\n\t}\n\n\t// The read-along (sentence) band legitimately covers whole equations and\n\t// replaced elements, so it escalates to them.\n\tprivate static readonly SENTENCE_FALLBACK_SELECTOR =\n\t\t\"math, mjx-container, svg, img, canvas, [role='img']\";\n\n\t// The word layer must NOT escalate a multi-node range to the enclosing\n\t// `<math>` / `<mjx-container>`: that is what made an equation flash as a\n\t// whole block whenever a spoken word's visible range crossed several math\n\t// glyph nodes. Math is tracked per token (or held / region) by the highlight\n\t// pipeline instead. Replaced elements (svg/img/canvas) still need the element\n\t// fallback because a CSS range cannot paint them.\n\tprivate static readonly WORD_FALLBACK_SELECTOR =\n\t\t\"svg, img, canvas, [role='img']\";\n\n\tprivate highlightTTSElementFallbacks(ranges: Range[]): void {\n\t\tif (typeof Element === \"undefined\") return;\n\t\tthis.highlightElementFallbacks(\n\t\t\tranges,\n\t\t\t\"data-pie-tts-sentence-element\",\n\t\t\tthis.ttsSentenceElementHighlights,\n\t\t\tHighlightCoordinator.SENTENCE_FALLBACK_SELECTOR,\n\t\t);\n\t}\n\n\tprivate highlightTTSWordElementFallbacks(ranges: Range[]): void {\n\t\tif (typeof Element === \"undefined\") return;\n\t\tthis.highlightElementFallbacks(\n\t\t\tranges,\n\t\t\t\"data-pie-tts-word-element\",\n\t\t\tthis.ttsWordElementHighlights,\n\t\t\tHighlightCoordinator.WORD_FALLBACK_SELECTOR,\n\t\t);\n\t}\n\n\tprivate highlightElementFallbacks(\n\t\tranges: Range[],\n\t\tattributeName: string,\n\t\ttrackedElements: Set<Element>,\n\t\tselector: string,\n\t): void {\n\t\tfor (const range of ranges) {\n\t\t\tconst root =\n\t\t\t\trange.commonAncestorContainer.nodeType === Node.ELEMENT_NODE\n\t\t\t\t\t? (range.commonAncestorContainer as Element)\n\t\t\t\t\t: range.commonAncestorContainer.parentElement;\n\t\t\tif (!root) continue;\n\t\t\tconst candidates: Element[] = [];\n\t\t\tconst rangeStartElement =\n\t\t\t\trange.startContainer.nodeType === Node.ELEMENT_NODE\n\t\t\t\t\t? (range.startContainer as Element)\n\t\t\t\t\t: range.startContainer.parentElement;\n\t\t\tconst rangeEndElement =\n\t\t\t\trange.endContainer.nodeType === Node.ELEMENT_NODE\n\t\t\t\t\t? (range.endContainer as Element)\n\t\t\t\t\t: range.endContainer.parentElement;\n\t\t\tfor (const element of [rangeStartElement, rangeEndElement]) {\n\t\t\t\tlet current: Element | null = element;\n\t\t\t\twhile (current) {\n\t\t\t\t\tif (current.matches?.(selector)) candidates.push(current);\n\t\t\t\t\tcurrent = current.parentElement;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (root.matches?.(selector)) {\n\t\t\t\tcandidates.push(root);\n\t\t\t}\n\t\t\tcandidates.push(...Array.from(root.querySelectorAll(selector)));\n\t\t\tfor (const element of new Set(candidates)) {\n\t\t\t\ttry {\n\t\t\t\t\tif (\n\t\t\t\t\t\t!range.intersectsNode(element) &&\n\t\t\t\t\t\t!element.contains(rangeStartElement) &&\n\t\t\t\t\t\t!element.contains(rangeEndElement)\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\telement.setAttribute(attributeName, \"true\");\n\t\t\t\ttrackedElements.add(element);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Clear TTS word highlight\n\t */\n\tclearTTSWord(): void {\n\t\tif (!this.ttsWordHighlight) return;\n\t\tthis.ttsWordHighlight.clear();\n\t\tfor (const element of this.ttsWordElementHighlights) {\n\t\t\telement.removeAttribute(\"data-pie-tts-word-element\");\n\t\t}\n\t\tthis.ttsWordElementHighlights.clear();\n\t}\n\n\t/**\n\t * Clear TTS sentence highlight\n\t */\n\tclearTTSSentence(): void {\n\t\tif (!this.ttsSentenceHighlight) return;\n\t\tthis.ttsSentenceHighlight.clear();\n\t\tfor (const element of this.ttsSentenceElementHighlights) {\n\t\t\telement.removeAttribute(\"data-pie-tts-sentence-element\");\n\t\t}\n\t\tthis.ttsSentenceElementHighlights.clear();\n\t}\n\n\t/**\n\t * Clear all TTS highlights\n\t */\n\tclearTTS(): void {\n\t\tthis.clearTTSWord();\n\t\tthis.clearTTSSentence();\n\t}\n\n\t/**\n\t * Add an annotation highlight (persistent)\n\t *\n\t * @param range Text range to annotate\n\t * @param color Highlight color\n\t * @returns Annotation ID for later removal\n\t */\n\taddAnnotation(\n\t\trange: Range,\n\t\tcolor: HighlightColor = HighlightColor.YELLOW,\n\t): string {\n\t\tconst id = `annotation-${this.nextAnnotationId++}`;\n\n\t\t// Clone the range to store\n\t\tconst clonedRange = range.cloneRange();\n\n\t\t// Store annotation data\n\t\tconst annotation: Annotation = {\n\t\t\tid,\n\t\t\trange: clonedRange,\n\t\t\ttype: HighlightType.ANNOTATION,\n\t\t\tcolor,\n\t\t\ttimestamp: Date.now(),\n\t\t};\n\t\tthis.annotations.set(id, annotation);\n\n\t\t// Add the SAME range object to the shared color highlight\n\t\t// This ensures we can later delete it by reference\n\t\tconst colorHighlight = this.colorHighlights.get(color);\n\t\tif (colorHighlight) {\n\t\t\tcolorHighlight.add(clonedRange);\n\t\t}\n\n\t\treturn id;\n\t}\n\n\t/**\n\t * Remove an annotation\n\t *\n\t * @param id Annotation ID\n\t */\n\tremoveAnnotation(id: string): void {\n\t\tconst annotation = this.annotations.get(id);\n\t\tif (!annotation) {\n\t\t\tconsole.warn(`[HighlightCoordinator] Annotation ${id} not found`);\n\t\t\treturn;\n\t\t}\n\n\t\tconsole.log(\n\t\t\t`[HighlightCoordinator] Removing annotation ${id} (color: ${annotation.color})`,\n\t\t);\n\n\t\t// Remove range from the shared color highlight\n\t\tconst colorHighlight = this.colorHighlights.get(annotation.color);\n\t\tif (colorHighlight) {\n\t\t\tconst deleted = colorHighlight.delete(annotation.range);\n\t\t\tconsole.log(\n\t\t\t\t`[HighlightCoordinator] Highlight.delete() returned:`,\n\t\t\t\tdeleted,\n\t\t\t);\n\t\t}\n\n\t\t// Clean up\n\t\tthis.annotations.delete(id);\n\t\tconsole.log(\n\t\t\t`[HighlightCoordinator] Annotation ${id} removed from map. Remaining:`,\n\t\t\tthis.annotations.size,\n\t\t);\n\t}\n\n\t/**\n\t * Remove all annotations\n\t */\n\tclearAnnotations(): void {\n\t\t// Clear all color highlights\n\t\tfor (const colorHighlight of this.colorHighlights.values()) {\n\t\t\tcolorHighlight.clear();\n\t\t}\n\n\t\t// Clear annotation data\n\t\tthis.annotations.clear();\n\t}\n\n\t/**\n\t * Get all annotations\n\t */\n\tgetAnnotations(): Annotation[] {\n\t\treturn Array.from(this.annotations.values());\n\t}\n\n\t/**\n\t * Get annotation by ID\n\t */\n\tgetAnnotation(id: string): Annotation | null {\n\t\treturn this.annotations.get(id) ?? null;\n\t}\n\n\t/**\n\t * Change annotation color\n\t *\n\t * @param id Annotation ID\n\t * @param newColor New color\n\t */\n\tchangeAnnotationColor(id: string, newColor: HighlightColor): void {\n\t\tconst annotation = this.annotations.get(id);\n\t\tif (!annotation) return;\n\n\t\tconst oldColor = annotation.color;\n\t\tif (oldColor === newColor) return;\n\n\t\t// Remove from old color highlight\n\t\tconst oldColorHighlight = this.colorHighlights.get(oldColor);\n\t\tif (oldColorHighlight) {\n\t\t\toldColorHighlight.delete(annotation.range);\n\t\t}\n\n\t\t// Update color\n\t\tannotation.color = newColor;\n\n\t\t// Add to new color highlight\n\t\tconst newColorHighlight = this.colorHighlights.get(newColor);\n\t\tif (newColorHighlight) {\n\t\t\tnewColorHighlight.add(annotation.range);\n\t\t}\n\t}\n\n\t/**\n\t * Export annotations as serializable data for persistence.\n\t * Uses RangeSerializer for robust DOM range serialization.\n\t *\n\t * @param root Root element for serialization (typically document.body or content container)\n\t * @returns Array of serialized annotations\n\t */\n\texportAnnotations(\n\t\troot: Element = document.body,\n\t): Array<\n\t\tSerializedRange & { id: string; color: HighlightColor; timestamp: number }\n\t> {\n\t\treturn this.getAnnotations().map((annotation) => ({\n\t\t\t...this.rangeSerializer.serialize(annotation.range, root),\n\t\t\tid: annotation.id,\n\t\t\tcolor: annotation.color,\n\t\t\ttimestamp: annotation.timestamp,\n\t\t}));\n\t}\n\n\t/**\n\t * Import annotations from serialized data.\n\t * Restores annotations after page navigation or refresh.\n\t *\n\t * @param data Array of serialized annotations\n\t * @param root Root element for deserialization (same as used in export)\n\t * @returns Number of successfully restored annotations\n\t */\n\timportAnnotations(\n\t\tdata: Array<\n\t\t\tSerializedRange & {\n\t\t\t\tid?: string;\n\t\t\t\tcolor: HighlightColor;\n\t\t\t\ttimestamp?: number;\n\t\t\t}\n\t\t>,\n\t\troot: Element = document.body,\n\t): number {\n\t\tlet restored = 0;\n\n\t\tfor (const item of data) {\n\t\t\tconst range = this.rangeSerializer.deserialize(item, root);\n\t\t\tif (range) {\n\t\t\t\tthis.addAnnotation(range, item.color);\n\t\t\t\trestored++;\n\t\t\t}\n\t\t}\n\n\t\treturn restored;\n\t}\n\n\t// ============================================================================\n\t// HighlightCoordinatorApi interface implementation\n\t// ============================================================================\n\n\t/**\n\t * Highlight a text range (interface method)\n\t *\n\t * Generic method that adapts to the specific highlight type.\n\t * For more control, use the specific methods like highlightTTSWord().\n\t */\n\thighlightRange(\n\t\trange: Range,\n\t\ttype: HighlightType,\n\t\tcolor: HighlightColor = HighlightColor.YELLOW,\n\t): void {\n\t\tif (!this.supported) return;\n\n\t\tswitch (type) {\n\t\t\tcase HighlightType.TTS_WORD:\n\t\t\tcase HighlightType.TTS_SENTENCE: {\n\t\t\t\t// For TTS, add to appropriate highlight\n\t\t\t\tconst highlight =\n\t\t\t\t\ttype === HighlightType.TTS_WORD\n\t\t\t\t\t\t? this.ttsWordHighlight\n\t\t\t\t\t\t: this.ttsSentenceHighlight;\n\t\t\t\tif (highlight) {\n\t\t\t\t\thighlight.clear();\n\t\t\t\t\thighlight.add(range);\n\t\t\t\t\tif (type === HighlightType.TTS_WORD) {\n\t\t\t\t\t\tfor (const element of this.ttsWordElementHighlights) {\n\t\t\t\t\t\t\telement.removeAttribute(\"data-pie-tts-word-element\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.ttsWordElementHighlights.clear();\n\t\t\t\t\t\tthis.highlightTTSWordElementFallbacks([range]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase HighlightType.ANNOTATION:\n\t\t\t\t// For annotations, use the existing method\n\t\t\t\tthis.addAnnotation(range, color);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\t/**\n\t * Clear highlights of a specific type (interface method)\n\t */\n\tclearHighlights(type: HighlightType): void {\n\t\tif (!this.supported) return;\n\n\t\tswitch (type) {\n\t\t\tcase HighlightType.TTS_WORD:\n\t\t\t\tthis.clearTTSWord();\n\t\t\t\tbreak;\n\t\t\tcase HighlightType.TTS_SENTENCE:\n\t\t\t\tthis.clearTTSSentence();\n\t\t\t\tbreak;\n\t\t\tcase HighlightType.ANNOTATION:\n\t\t\t\tthis.clearAnnotations();\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\t/**\n\t * Clear all highlights (interface method)\n\t */\n\tclearAll(): void {\n\t\tif (!this.supported) return;\n\t\tthis.clearTTS();\n\t\tthis.clearAnnotations();\n\t}\n\n\t/**\n\t * Check if CSS Highlight API is supported (interface method)\n\t */\n\tisSupported(): boolean {\n\t\treturn this.supported;\n\t}\n\n\t/**\n\t * Update TTS highlight style dynamically\n\t *\n\t * @param color CSS color value (e.g., '#ffeb3b')\n\t * @param opacity Opacity value (0.0 to 1.0)\n\t */\n\tupdateTTSHighlightStyle(color: string, opacity: number): void {\n\t\tif (!this.supported) return;\n\t\tif (typeof document === \"undefined\") return;\n\n\t\tconst styleEl = document.getElementById(\"pie-highlight-styles\");\n\t\tif (!styleEl) return;\n\n\t\t// Convert hex to rgba\n\t\tconst hexToRgb = (hex: string) => {\n\t\t\tconst result = /^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(hex);\n\t\t\treturn result\n\t\t\t\t? {\n\t\t\t\t\t\tr: parseInt(result[1], 16),\n\t\t\t\t\t\tg: parseInt(result[2], 16),\n\t\t\t\t\t\tb: parseInt(result[3], 16),\n\t\t\t\t\t}\n\t\t\t\t: null;\n\t\t};\n\n\t\tconst rgb = hexToRgb(color);\n\t\tif (!rgb) return;\n\n\t\tthis.explicitTTSColorOverride = {\n\t\t\tcolor: `rgb(${rgb.r}, ${rgb.g}, ${rgb.b})`,\n\t\t\topacity: Math.max(0.2, Math.min(0.95, opacity)),\n\t\t};\n\t\tthis.applyAdaptiveTTSStyle();\n\t}\n\n\t/**\n\t * Cleanup - remove all highlights\n\t */\n\tdestroy(): void {\n\t\tif (!this.supported) return;\n\n\t\tthis.clearTTS();\n\t\tthis.clearAnnotations();\n\n\t\t// Remove style element\n\t\tif (typeof document !== \"undefined\") {\n\t\t\tconst styleEl = document.getElementById(\"pie-highlight-styles\");\n\t\t\tif (styleEl) {\n\t\t\t\tstyleEl.remove();\n\t\t\t}\n\t\t}\n\t\tthis.themeObserver?.disconnect();\n\t\tthis.themeObserver = null;\n\t}\n}\n"]}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* Part of PIE Assessment Toolkit.
|
|
16
16
|
*/
|
|
17
17
|
import type { I18nConfig, I18nServiceApi, PluralTranslation, TranslationBundle } from "@pie-players/pie-players-shared/i18n";
|
|
18
|
-
export type { I18nConfig, I18nServiceApi, PluralTranslation, TranslationBundle };
|
|
18
|
+
export type { I18nConfig, I18nServiceApi, PluralTranslation, TranslationBundle, };
|
|
19
19
|
/**
|
|
20
20
|
* I18nService
|
|
21
21
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"I18nService.js","sourceRoot":"","sources":["../../src/services/I18nService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAQH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,GAAG,GAAG,YAAY,CAAC,aAAa,CAAC,CAAC;AAKxC;;;;GAIG;AACH,MAAM,OAAO,WAAW;IACf,MAAM,GAAW,IAAI,CAAC;IACtB,cAAc,GAAW,IAAI,CAAC;IAC9B,SAAS,GAAkB,KAAK,CAAC;IACjC,YAAY,GAAG,IAAI,GAAG,EAA6B,CAAC;IACpD,SAAS,GAAG,IAAI,GAAG,EAAc,CAAC;IAClC,eAAe,GAAG,IAAI,GAAG,EAAyB,CAAC;IACnD,MAAM,CAAa;IAE3B,YAAY,SAAqB,EAAE;QAClC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,IAAI,IAAI,CAAC;QAEpD,GAAG,CAAC,yBAAyB,EAAE,EAAE,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;QAExE,iDAAiD;QACjD,IAAI,MAAM,CAAC,mBAA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AW,EAAE,CAAC;YACrD,IAAI,CAAC;gBACJ,MAAM,KAAK,GAAG,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;gBAC3C,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACrC,OAAO,QAAmC,CAAC;YAC5C,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,GAAG,CAAC,8CAA8C,MAAM,EAAE,EAAE,MAAM,CAAC,CAAC;YACrE,CAAC;QACF,CAAC;QAED,2BAA2B;QAC3B,IAAI,KAAK,KAAK,CAAC;YAAE,OAAO,MAAM,CAAC;QAC/B,IAAI,KAAK,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QAC9B,OAAO,OAAO,CAAC;IAChB,CAAC;IAED;;OAEG;IACK,mBAAmB;QAC1B,IAAI,OAAO,SAAS,KAAK,WAAW;YAAE,OAAO,IAAI,CAAC;QAElD,MAAM,WAAW,GAChB,SAAS,CAAC,QAAQ;YAClB,CAAC,SAAS,CAAC,SAAS,IAAI,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YAC/C,IAAI,CAAC;QAEN,gDAAgD;QAChD,OAAO,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAClC,CAAC;CACD","sourcesContent":["/**\n * I18nService\n *\n * Internationalization service with hybrid loading strategy.\n * Manages translations, locale switching, and RTL/LTR direction.\n *\n * Features:\n * - Subscriber/listener pattern for reactive updates\n * - Hybrid loading: Bundle English, lazy-load other locales\n * - Interpolation: {variable} syntax\n * - Pluralization: ICU-style plural rules\n * - RTL detection: Automatic based on locale\n * - Fallback to English for missing keys\n *\n * Part of PIE Assessment Toolkit.\n */\n\nimport type {\n\tI18nConfig,\n\tI18nServiceApi,\n\tPluralTranslation,\n\tTranslationBundle,\n} from \"@pie-players/pie-players-shared/i18n\";\nimport { createLogger } from \"../utils/logger.js\";\n\nconst log = createLogger(\"I18nService\");\n\n// Re-export types for convenience\nexport type { I18nConfig, I18nServiceApi, PluralTranslation, TranslationBundle };\n\n/**\n * I18nService\n *\n * Manages internationalization with reactive state updates.\n */\nexport class I18nService implements I18nServiceApi {\n\tprivate locale: string = \"en\";\n\tprivate fallbackLocale: string = \"en\";\n\tprivate direction: \"ltr\" | \"rtl\" = \"ltr\";\n\tprivate translations = new Map<string, TranslationBundle>();\n\tprivate listeners = new Set<() => void>();\n\tprivate loadingPromises = new Map<string, Promise<void>>();\n\tprivate config: I18nConfig;\n\n\tconstructor(config: I18nConfig = {}) {\n\t\tthis.config = config;\n\t\tthis.fallbackLocale = config.fallbackLocale || \"en\";\n\n\t\tlog(\"I18nService initialized\", { fallbackLocale: this.fallbackLocale });\n\n\t\t// Load bundled translations (English by default)\n\t\tif (config.bundledTranslations) {\n\t\t\tfor (const [locale, bundle] of Object.entries(\n\t\t\t\tconfig.bundledTranslations,\n\t\t\t)) {\n\t\t\t\tthis.translations.set(locale, bundle);\n\t\t\t\tlog(`Loaded bundled translations for: ${locale}`);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Initialize i18n with locale and loading strategy\n\t */\n\tasync initialize(config: I18nConfig): Promise<void> {\n\t\tObject.assign(this.config, config);\n\n\t\tconst locale = config.locale || this.detectBrowserLocale();\n\t\tlog(`Initializing with locale: ${locale}`);\n\n\t\tawait this.setLocale(locale);\n\t}\n\n\t/**\n\t * Translate a key with optional interpolation\n\t *\n\t * @param key Translation key (e.g., 'common.save')\n\t * @param params Optional parameters for interpolation\n\t * @returns Translated string\n\t */\n\tt(key: string, params?: Record<string, any>): string {\n\t\tconst translation = this.getTranslation(key);\n\t\treturn this.interpolate(translation as string, params);\n\t}\n\n\t/**\n\t * Translate with pluralization\n\t *\n\t * @param key Translation key\n\t * @param count Count for pluralization\n\t * @param params Optional parameters for interpolation\n\t * @returns Translated string with plural form\n\t */\n\ttn(key: string, count: number, params?: Record<string, any>): string {\n\t\tconst translation = this.getTranslation(key);\n\n\t\tif (typeof translation === \"object\") {\n\t\t\tconst pluralForm = this.selectPluralForm(count, this.locale);\n\t\t\tconst text = translation[pluralForm] || translation.other;\n\t\t\treturn this.interpolate(text, { ...params, count });\n\t\t}\n\n\t\treturn this.interpolate(translation as string, { ...params, count });\n\t}\n\n\t/**\n\t * Get current locale\n\t */\n\tgetLocale(): string {\n\t\treturn this.locale;\n\t}\n\n\t/**\n\t * Change locale (triggers async loading if needed)\n\t *\n\t * @param locale Locale code (e.g., 'en', 'es', 'zh', 'ar')\n\t */\n\tasync setLocale(locale: string): Promise<void> {\n\t\tlog(`Setting locale to: ${locale}`);\n\n\t\t// Check if already loading\n\t\tif (this.loadingPromises.has(locale)) {\n\t\t\tlog(`Locale ${locale} is already loading, waiting...`);\n\t\t\tawait this.loadingPromises.get(locale);\n\t\t\treturn;\n\t\t}\n\n\t\t// Check if already loaded\n\t\tif (this.translations.has(locale)) {\n\t\t\tlog(`Locale ${locale} already loaded`);\n\t\t\tthis.applyLocale(locale);\n\t\t\treturn;\n\t\t}\n\n\t\t// Load translations\n\t\tconst loadingPromise = this.loadTranslationsForLocale(locale);\n\t\tthis.loadingPromises.set(locale, loadingPromise);\n\n\t\ttry {\n\t\t\tawait loadingPromise;\n\t\t\tthis.applyLocale(locale);\n\t\t} finally {\n\t\t\tthis.loadingPromises.delete(locale);\n\t\t}\n\t}\n\n\t/**\n\t * Get current text direction\n\t */\n\tgetDirection(): \"ltr\" | \"rtl\" {\n\t\treturn this.direction;\n\t}\n\n\t/**\n\t * Get available locales\n\t */\n\tgetAvailableLocales(): string[] {\n\t\treturn Array.from(this.translations.keys());\n\t}\n\n\t/**\n\t * Check if locale is loaded\n\t */\n\tisLocaleLoaded(locale: string): boolean {\n\t\treturn this.translations.has(locale);\n\t}\n\n\t/**\n\t * Subscribe to locale/translation changes\n\t * Returns unsubscribe function\n\t */\n\tsubscribe(listener: () => void): () => void {\n\t\tthis.listeners.add(listener);\n\t\treturn () => {\n\t\t\tthis.listeners.delete(listener);\n\t\t};\n\t}\n\n\t/**\n\t * Check if a translation key exists\n\t */\n\thasKey(key: string): boolean {\n\t\tconst bundle = this.translations.get(this.locale);\n\t\treturn !!bundle?.translations[key];\n\t}\n\n\t/**\n\t * Notify all listeners of state change\n\t */\n\tprivate notifyListeners(): void {\n\t\tthis.listeners.forEach((listener) => listener());\n\t}\n\n\t/**\n\t * Apply locale and notify listeners\n\t */\n\tprivate applyLocale(locale: string): void {\n\t\tconst bundle = this.translations.get(locale);\n\t\tif (!bundle) {\n\t\t\tlog(`No bundle found for locale: ${locale}`, \"warn\");\n\t\t\treturn;\n\t\t}\n\n\t\tconst previousLocale = this.locale;\n\t\tthis.locale = locale;\n\t\tthis.direction = bundle.direction;\n\n\t\tlog(`Applied locale: ${locale} (direction: ${this.direction})`);\n\n\t\tthis.applyDOMDirection();\n\t\tthis.notifyListeners();\n\t}\n\n\t/**\n\t * Apply direction to DOM\n\t */\n\tprivate applyDOMDirection(): void {\n\t\tif (typeof document === \"undefined\") return;\n\n\t\tdocument.documentElement.setAttribute(\"dir\", this.direction);\n\t\tdocument.documentElement.setAttribute(\"lang\", this.locale);\n\n\t\tlog(\n\t\t\t`Applied DOM attributes: dir=\"${this.direction}\" lang=\"${this.locale}\"`,\n\t\t);\n\t}\n\n\t/**\n\t * Load translations for a locale\n\t */\n\tprivate async loadTranslationsForLocale(locale: string): Promise<void> {\n\t\tif (!this.config.loadTranslations) {\n\t\t\tthrow new Error(`No translation loader configured for locale: ${locale}`);\n\t\t}\n\n\t\tlog(`Loading translations for: ${locale}`);\n\n\t\ttry {\n\t\t\tconst bundle = await this.config.loadTranslations(locale);\n\t\t\tthis.translations.set(locale, bundle);\n\t\t\tlog(\n\t\t\t\t`Loaded translations for: ${locale} (${Object.keys(bundle.translations).length} keys)`,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tlog(`Failed to load translations for: ${locale}`, \"error\");\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Get translation for a key\n\t */\n\tprivate getTranslation(key: string): string | PluralTranslation {\n\t\t// Try current locale\n\t\tconst currentBundle = this.translations.get(this.locale);\n\t\tif (currentBundle?.translations[key]) {\n\t\t\treturn currentBundle.translations[key];\n\t\t}\n\n\t\t// Try fallback locale\n\t\tconst fallbackBundle = this.translations.get(this.fallbackLocale);\n\t\tif (fallbackBundle?.translations[key]) {\n\t\t\tif (this.config.debug) {\n\t\t\t\tlog(`Using fallback translation for key: ${key}`);\n\t\t\t}\n\t\t\treturn fallbackBundle.translations[key];\n\t\t}\n\n\t\t// Missing key handling\n\t\tif (this.config.onMissingKey) {\n\t\t\tthis.config.onMissingKey(key, this.locale);\n\t\t}\n\n\t\tif (this.config.debug) {\n\t\t\tlog(`Missing translation key: ${key} (locale: ${this.locale})`, \"warn\");\n\t\t}\n\n\t\treturn key;\n\t}\n\n\t/**\n\t * Interpolate variables in translation string\n\t * Replaces {variable} with params.variable\n\t */\n\tprivate interpolate(text: string, params?: Record<string, any>): string {\n\t\tif (!params) return text;\n\n\t\treturn text.replace(/\\{(\\w+)\\}/g, (match, key) => {\n\t\t\treturn params[key]?.toString() || match;\n\t\t});\n\t}\n\n\t/**\n\t * Select plural form based on count and locale\n\t * Simplified implementation - real implementation would use Intl.PluralRules\n\t */\n\tprivate selectPluralForm(\n\t\tcount: number,\n\t\tlocale: string,\n\t): keyof PluralTranslation {\n\t\t// Use Intl.PluralRules if available\n\t\tif (typeof Intl !== \"undefined\" && Intl.PluralRules) {\n\t\t\ttry {\n\t\t\t\tconst rules = new Intl.PluralRules(locale);\n\t\t\t\tconst category = rules.select(count);\n\t\t\t\treturn category as keyof PluralTranslation;\n\t\t\t} catch (error) {\n\t\t\t\tlog(`Failed to use Intl.PluralRules for locale: ${locale}`, \"warn\");\n\t\t\t}\n\t\t}\n\n\t\t// Fallback to simple rules\n\t\tif (count === 0) return \"zero\";\n\t\tif (count === 1) return \"one\";\n\t\treturn \"other\";\n\t}\n\n\t/**\n\t * Detect browser locale\n\t */\n\tprivate detectBrowserLocale(): string {\n\t\tif (typeof navigator === \"undefined\") return \"en\";\n\n\t\tconst browserLang =\n\t\t\tnavigator.language ||\n\t\t\t(navigator.languages && navigator.languages[0]) ||\n\t\t\t\"en\";\n\n\t\t// Extract language code (e.g., 'en-US' -> 'en')\n\t\treturn browserLang.split(\"-\")[0];\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"I18nService.js","sourceRoot":"","sources":["../../src/services/I18nService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAQH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,GAAG,GAAG,YAAY,CAAC,aAAa,CAAC,CAAC;AAUxC;;;;GAIG;AACH,MAAM,OAAO,WAAW;IACf,MAAM,GAAW,IAAI,CAAC;IACtB,cAAc,GAAW,IAAI,CAAC;IAC9B,SAAS,GAAkB,KAAK,CAAC;IACjC,YAAY,GAAG,IAAI,GAAG,EAA6B,CAAC;IACpD,SAAS,GAAG,IAAI,GAAG,EAAc,CAAC;IAClC,eAAe,GAAG,IAAI,GAAG,EAAyB,CAAC;IACnD,MAAM,CAAa;IAE3B,YAAY,SAAqB,EAAE;QAClC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,IAAI,IAAI,CAAC;QAEpD,GAAG,CAAC,yBAAyB,EAAE,EAAE,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;QAExE,iDAAiD;QACjD,IAAI,MAAM,CAAC,mBAAmB,EAAE,CAAC;YAChC,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAC5C,MAAM,CAAC,mBAAmB,CAC1B,EAAE,CAAC;gBACH,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBACtC,GAAG,CAAC,oCAAoC,MAAM,EAAE,CAAC,CAA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AG,CAAC,8CAA8C,MAAM,EAAE,EAAE,MAAM,CAAC,CAAC;YACrE,CAAC;QACF,CAAC;QAED,2BAA2B;QAC3B,IAAI,KAAK,KAAK,CAAC;YAAE,OAAO,MAAM,CAAC;QAC/B,IAAI,KAAK,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QAC9B,OAAO,OAAO,CAAC;IAChB,CAAC;IAED;;OAEG;IACK,mBAAmB;QAC1B,IAAI,OAAO,SAAS,KAAK,WAAW;YAAE,OAAO,IAAI,CAAC;QAElD,MAAM,WAAW,GAChB,SAAS,CAAC,QAAQ;YAClB,CAAC,SAAS,CAAC,SAAS,IAAI,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YAC/C,IAAI,CAAC;QAEN,gDAAgD;QAChD,OAAO,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAClC,CAAC;CACD","sourcesContent":["/**\n * I18nService\n *\n * Internationalization service with hybrid loading strategy.\n * Manages translations, locale switching, and RTL/LTR direction.\n *\n * Features:\n * - Subscriber/listener pattern for reactive updates\n * - Hybrid loading: Bundle English, lazy-load other locales\n * - Interpolation: {variable} syntax\n * - Pluralization: ICU-style plural rules\n * - RTL detection: Automatic based on locale\n * - Fallback to English for missing keys\n *\n * Part of PIE Assessment Toolkit.\n */\n\nimport type {\n\tI18nConfig,\n\tI18nServiceApi,\n\tPluralTranslation,\n\tTranslationBundle,\n} from \"@pie-players/pie-players-shared/i18n\";\nimport { createLogger } from \"../utils/logger.js\";\n\nconst log = createLogger(\"I18nService\");\n\n// Re-export types for convenience\nexport type {\n\tI18nConfig,\n\tI18nServiceApi,\n\tPluralTranslation,\n\tTranslationBundle,\n};\n\n/**\n * I18nService\n *\n * Manages internationalization with reactive state updates.\n */\nexport class I18nService implements I18nServiceApi {\n\tprivate locale: string = \"en\";\n\tprivate fallbackLocale: string = \"en\";\n\tprivate direction: \"ltr\" | \"rtl\" = \"ltr\";\n\tprivate translations = new Map<string, TranslationBundle>();\n\tprivate listeners = new Set<() => void>();\n\tprivate loadingPromises = new Map<string, Promise<void>>();\n\tprivate config: I18nConfig;\n\n\tconstructor(config: I18nConfig = {}) {\n\t\tthis.config = config;\n\t\tthis.fallbackLocale = config.fallbackLocale || \"en\";\n\n\t\tlog(\"I18nService initialized\", { fallbackLocale: this.fallbackLocale });\n\n\t\t// Load bundled translations (English by default)\n\t\tif (config.bundledTranslations) {\n\t\t\tfor (const [locale, bundle] of Object.entries(\n\t\t\t\tconfig.bundledTranslations,\n\t\t\t)) {\n\t\t\t\tthis.translations.set(locale, bundle);\n\t\t\t\tlog(`Loaded bundled translations for: ${locale}`);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Initialize i18n with locale and loading strategy\n\t */\n\tasync initialize(config: I18nConfig): Promise<void> {\n\t\tObject.assign(this.config, config);\n\n\t\tconst locale = config.locale || this.detectBrowserLocale();\n\t\tlog(`Initializing with locale: ${locale}`);\n\n\t\tawait this.setLocale(locale);\n\t}\n\n\t/**\n\t * Translate a key with optional interpolation\n\t *\n\t * @param key Translation key (e.g., 'common.save')\n\t * @param params Optional parameters for interpolation\n\t * @returns Translated string\n\t */\n\tt(key: string, params?: Record<string, any>): string {\n\t\tconst translation = this.getTranslation(key);\n\t\treturn this.interpolate(translation as string, params);\n\t}\n\n\t/**\n\t * Translate with pluralization\n\t *\n\t * @param key Translation key\n\t * @param count Count for pluralization\n\t * @param params Optional parameters for interpolation\n\t * @returns Translated string with plural form\n\t */\n\ttn(key: string, count: number, params?: Record<string, any>): string {\n\t\tconst translation = this.getTranslation(key);\n\n\t\tif (typeof translation === \"object\") {\n\t\t\tconst pluralForm = this.selectPluralForm(count, this.locale);\n\t\t\tconst text = translation[pluralForm] || translation.other;\n\t\t\treturn this.interpolate(text, { ...params, count });\n\t\t}\n\n\t\treturn this.interpolate(translation as string, { ...params, count });\n\t}\n\n\t/**\n\t * Get current locale\n\t */\n\tgetLocale(): string {\n\t\treturn this.locale;\n\t}\n\n\t/**\n\t * Change locale (triggers async loading if needed)\n\t *\n\t * @param locale Locale code (e.g., 'en', 'es', 'zh', 'ar')\n\t */\n\tasync setLocale(locale: string): Promise<void> {\n\t\tlog(`Setting locale to: ${locale}`);\n\n\t\t// Check if already loading\n\t\tif (this.loadingPromises.has(locale)) {\n\t\t\tlog(`Locale ${locale} is already loading, waiting...`);\n\t\t\tawait this.loadingPromises.get(locale);\n\t\t\treturn;\n\t\t}\n\n\t\t// Check if already loaded\n\t\tif (this.translations.has(locale)) {\n\t\t\tlog(`Locale ${locale} already loaded`);\n\t\t\tthis.applyLocale(locale);\n\t\t\treturn;\n\t\t}\n\n\t\t// Load translations\n\t\tconst loadingPromise = this.loadTranslationsForLocale(locale);\n\t\tthis.loadingPromises.set(locale, loadingPromise);\n\n\t\ttry {\n\t\t\tawait loadingPromise;\n\t\t\tthis.applyLocale(locale);\n\t\t} finally {\n\t\t\tthis.loadingPromises.delete(locale);\n\t\t}\n\t}\n\n\t/**\n\t * Get current text direction\n\t */\n\tgetDirection(): \"ltr\" | \"rtl\" {\n\t\treturn this.direction;\n\t}\n\n\t/**\n\t * Get available locales\n\t */\n\tgetAvailableLocales(): string[] {\n\t\treturn Array.from(this.translations.keys());\n\t}\n\n\t/**\n\t * Check if locale is loaded\n\t */\n\tisLocaleLoaded(locale: string): boolean {\n\t\treturn this.translations.has(locale);\n\t}\n\n\t/**\n\t * Subscribe to locale/translation changes\n\t * Returns unsubscribe function\n\t */\n\tsubscribe(listener: () => void): () => void {\n\t\tthis.listeners.add(listener);\n\t\treturn () => {\n\t\t\tthis.listeners.delete(listener);\n\t\t};\n\t}\n\n\t/**\n\t * Check if a translation key exists\n\t */\n\thasKey(key: string): boolean {\n\t\tconst bundle = this.translations.get(this.locale);\n\t\treturn !!bundle?.translations[key];\n\t}\n\n\t/**\n\t * Notify all listeners of state change\n\t */\n\tprivate notifyListeners(): void {\n\t\tthis.listeners.forEach((listener) => listener());\n\t}\n\n\t/**\n\t * Apply locale and notify listeners\n\t */\n\tprivate applyLocale(locale: string): void {\n\t\tconst bundle = this.translations.get(locale);\n\t\tif (!bundle) {\n\t\t\tlog(`No bundle found for locale: ${locale}`, \"warn\");\n\t\t\treturn;\n\t\t}\n\n\t\tconst previousLocale = this.locale;\n\t\tthis.locale = locale;\n\t\tthis.direction = bundle.direction;\n\n\t\tlog(`Applied locale: ${locale} (direction: ${this.direction})`);\n\n\t\tthis.applyDOMDirection();\n\t\tthis.notifyListeners();\n\t}\n\n\t/**\n\t * Apply direction to DOM\n\t */\n\tprivate applyDOMDirection(): void {\n\t\tif (typeof document === \"undefined\") return;\n\n\t\tdocument.documentElement.setAttribute(\"dir\", this.direction);\n\t\tdocument.documentElement.setAttribute(\"lang\", this.locale);\n\n\t\tlog(\n\t\t\t`Applied DOM attributes: dir=\"${this.direction}\" lang=\"${this.locale}\"`,\n\t\t);\n\t}\n\n\t/**\n\t * Load translations for a locale\n\t */\n\tprivate async loadTranslationsForLocale(locale: string): Promise<void> {\n\t\tif (!this.config.loadTranslations) {\n\t\t\tthrow new Error(`No translation loader configured for locale: ${locale}`);\n\t\t}\n\n\t\tlog(`Loading translations for: ${locale}`);\n\n\t\ttry {\n\t\t\tconst bundle = await this.config.loadTranslations(locale);\n\t\t\tthis.translations.set(locale, bundle);\n\t\t\tlog(\n\t\t\t\t`Loaded translations for: ${locale} (${Object.keys(bundle.translations).length} keys)`,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tlog(`Failed to load translations for: ${locale}`, \"error\");\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Get translation for a key\n\t */\n\tprivate getTranslation(key: string): string | PluralTranslation {\n\t\t// Try current locale\n\t\tconst currentBundle = this.translations.get(this.locale);\n\t\tif (currentBundle?.translations[key]) {\n\t\t\treturn currentBundle.translations[key];\n\t\t}\n\n\t\t// Try fallback locale\n\t\tconst fallbackBundle = this.translations.get(this.fallbackLocale);\n\t\tif (fallbackBundle?.translations[key]) {\n\t\t\tif (this.config.debug) {\n\t\t\t\tlog(`Using fallback translation for key: ${key}`);\n\t\t\t}\n\t\t\treturn fallbackBundle.translations[key];\n\t\t}\n\n\t\t// Missing key handling\n\t\tif (this.config.onMissingKey) {\n\t\t\tthis.config.onMissingKey(key, this.locale);\n\t\t}\n\n\t\tif (this.config.debug) {\n\t\t\tlog(`Missing translation key: ${key} (locale: ${this.locale})`, \"warn\");\n\t\t}\n\n\t\treturn key;\n\t}\n\n\t/**\n\t * Interpolate variables in translation string\n\t * Replaces {variable} with params.variable\n\t */\n\tprivate interpolate(text: string, params?: Record<string, any>): string {\n\t\tif (!params) return text;\n\n\t\treturn text.replace(/\\{(\\w+)\\}/g, (match, key) => {\n\t\t\treturn params[key]?.toString() || match;\n\t\t});\n\t}\n\n\t/**\n\t * Select plural form based on count and locale\n\t * Simplified implementation - real implementation would use Intl.PluralRules\n\t */\n\tprivate selectPluralForm(\n\t\tcount: number,\n\t\tlocale: string,\n\t): keyof PluralTranslation {\n\t\t// Use Intl.PluralRules if available\n\t\tif (typeof Intl !== \"undefined\" && Intl.PluralRules) {\n\t\t\ttry {\n\t\t\t\tconst rules = new Intl.PluralRules(locale);\n\t\t\t\tconst category = rules.select(count);\n\t\t\t\treturn category as keyof PluralTranslation;\n\t\t\t} catch (error) {\n\t\t\t\tlog(`Failed to use Intl.PluralRules for locale: ${locale}`, \"warn\");\n\t\t\t}\n\t\t}\n\n\t\t// Fallback to simple rules\n\t\tif (count === 0) return \"zero\";\n\t\tif (count === 1) return \"one\";\n\t\treturn \"other\";\n\t}\n\n\t/**\n\t * Detect browser locale\n\t */\n\tprivate detectBrowserLocale(): string {\n\t\tif (typeof navigator === \"undefined\") return \"en\";\n\n\t\tconst browserLang =\n\t\t\tnavigator.language ||\n\t\t\t(navigator.languages && navigator.languages[0]) ||\n\t\t\t\"en\";\n\n\t\t// Extract language code (e.g., 'en-US' -> 'en')\n\t\treturn browserLang.split(\"-\")[0];\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SSMLExtractor.js","sourceRoot":"","sources":["../../src/services/SSMLExtractor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAwBH;;;;;GAKG;AACH,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IACjC,OAAO;IACP,OAAO;IACP,SAAS;IACT,UAAU;IACV,QAAQ;IACR,KAAK;IACL,MAAM;IACN,SAAS;IACT,MAAM;IACN,GAAG;IACH,GAAG;IACH,OAAO;IACP,OAAO;IACP,SAAS;CACT,CAAC,CAAC;AAEH;;;;GAIG;AACH;;;;GAIG;AACH,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC;IACpC,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,OAAO;IACP,eAAe;IACf,UAAU;IACV,UAAU;CACV,CAAC,CAAC;AAEH,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;IAClC,UAAU;IACV,IAAI;IACJ,MAAM;IACN,UAAU;IACV,MAAM;IACN,OAAO;IACP,QAAQ;IACR,MAAM;IACN,cAAc;IACd,QAAQ;IACR,QAAQ;IACR,UAAU;IACV,UAAU;IACV,MAAM;IACN,QAAQ;IACR,KAAK;CACL,CAAC,CAAC;AAEH;;;;;;;;;;;;;GAaG;AACH,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AAE7D;;;;;;;GAOG;AACH,SAAS,yBAAyB,CAAC,KAAa;IAC/C,IAAI,IAAI,GAAG,KAAK,CAAC;IACjB,KAAK,MAAM,GAAG,IAAI,cAAc,EAAE,CAAC;QAClC,MAAM,WAAW,GAAG,IAAI,MAAM,CAAC,IAAI,GAAG,oBAAoB,EAAE,IAAI,CAAC,CAAC;QAClE,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,MAAM,EAAE,KAAa,EAAE,EAAE;YAC1D,MAAM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AE,QAAQ,EAAE,EAAE,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC;QAChD,CAAC;IACF,CAAC;IAED;;;;;OAKG;IACK,iBAAiB,CAAC,MAAc;QACvC,MAAM,EAAE,GAAG,QAAQ,MAAM,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;QACnD,IAAI,CAAC,cAAc,EAAE,CAAC;QACtB,OAAO,EAAE,CAAC;IACX,CAAC;IAED;;OAEG;IACH,KAAK;QACJ,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC;IACzB,CAAC;CACD","sourcesContent":["/**\n * SSMLExtractor\n *\n * Service for extracting embedded SSML from PIE item content and converting\n * it into QTI 3.0 accessibility catalogs.\n *\n * Authors can embed <speak> SSML tags directly in content for convenience.\n * The extractor automatically:\n * 1. Parses markup and finds all <speak> elements\n * 2. Extracts SSML content with language metadata\n * 3. Generates accessibility catalogs with unique IDs\n * 4. Cleans visual markup (removes SSML, adds data-catalog-idref)\n *\n * This enables proper pronunciation, emphasis, and pacing for TTS without\n * requiring authors to maintain separate catalog files.\n *\n * Part of PIE Assessment Toolkit.\n */\n\nimport type {\n\tAccessibilityCatalog,\n\tConfigEntity,\n\tPieModel,\n} from \"@pie-players/pie-players-shared/types\";\n\n/**\n * Result from extracting SSML from markup\n */\ninterface MarkupExtractionResult {\n\tcatalogs: AccessibilityCatalog[];\n\tcleanedMarkup: string;\n}\n\n/**\n * Result from extracting SSML from entire item config\n */\nexport interface ExtractionResult {\n\tcatalogs: AccessibilityCatalog[];\n\tcleanedConfig: ConfigEntity;\n}\n\n/**\n * Allow-listed SSML elements (from the SSML 1.1 spec subset we forward to\n * TTS providers). Anything outside this list is unwrapped during\n * sanitization so we never leak author-supplied scripts, iframes, or\n * arbitrary HTML into the TTS pipeline.\n */\nconst SSML_ALLOWED_TAGS = new Set([\n\t\"speak\",\n\t\"break\",\n\t\"prosody\",\n\t\"emphasis\",\n\t\"say-as\",\n\t\"sub\",\n\t\"mark\",\n\t\"phoneme\",\n\t\"lang\",\n\t\"p\",\n\t\"s\",\n\t\"voice\",\n\t\"audio\",\n\t\"lexicon\",\n]);\n\n/**\n * Allow-listed attributes across SSML elements. Attribute allow-listing is\n * global (not per-tag) because the union is small and consistent across\n * providers.\n */\n/**\n * Tags whose content must be dropped entirely (rather than unwrapped to\n * preserve phrasing text). These are dangerous containers whose text\n * payload could be re-interpreted downstream.\n */\nconst SSML_DROP_FULLY_TAGS = new Set([\n\t\"script\",\n\t\"style\",\n\t\"iframe\",\n\t\"object\",\n\t\"embed\",\n\t\"foreignobject\",\n\t\"noscript\",\n\t\"template\",\n]);\n\nconst SSML_ALLOWED_ATTRS = new Set([\n\t\"alphabet\",\n\t\"ph\",\n\t\"time\",\n\t\"strength\",\n\t\"rate\",\n\t\"pitch\",\n\t\"volume\",\n\t\"name\",\n\t\"interpret-as\",\n\t\"format\",\n\t\"detail\",\n\t\"language\",\n\t\"xml:lang\",\n\t\"lang\",\n\t\"gender\",\n\t\"src\",\n]);\n\n/**\n * SSML elements that are empty in practice (no child content). Authors\n * typically write them as self-closing (`<break time=\"200ms\"/>`). HTML's\n * parser does NOT recognize them as void elements and silently drops the\n * `/`, then nests every subsequent sibling as a child — producing\n * malformed SSML like `<break>…rest of paragraph…</break>` when\n * round-tripped. Pre-processing self-closing forms to explicit\n * open+close pairs before HTML parsing avoids the reflow, and the\n * serializer re-emits them as self-closing so providers see valid SSML.\n *\n * `audio` is intentionally excluded — SSML <audio> may carry fallback\n * children (the spec's \"alternate content\"), so treating it as void\n * would lose author intent.\n */\nconst SSML_VOID_TAGS = new Set([\"break\", \"mark\", \"lexicon\"]);\n\n/**\n * Normalize self-closing forms of SSML void elements to explicit\n * open+close pairs BEFORE handing the string to an HTML parser. The\n * HTML5 parser ignores the `/` on non-void tags, so `<break/>` becomes\n * a plain `<break>` open tag that swallows every following sibling.\n * Rewriting to `<break></break>` preserves the empty-element shape\n * across the HTML round-trip.\n */\nfunction expandSelfClosingVoidTags(input: string): string {\n\tlet next = input;\n\tfor (const tag of SSML_VOID_TAGS) {\n\t\tconst selfClosing = new RegExp(`<${tag}\\\\b([^>/]*?)\\\\s*/>`, \"gi\");\n\t\tnext = next.replace(selfClosing, (_match, attrs: string) => {\n\t\t\tconst attrText = attrs ? attrs.replace(/\\s+$/, \"\") : \"\";\n\t\t\treturn `<${tag}${attrText}></${tag}>`;\n\t\t});\n\t}\n\treturn next;\n}\n\n/**\n * Hosts that must never appear inside an SSML `<audio src>` because they\n * would cause the server-side TTS provider to fetch a private / metadata\n * endpoint on behalf of the request. Mirrors the SchoolCity provider's\n * defense-in-depth check; the SSML-side block is cheap and belt-and-braces.\n */\nconst SSML_PRIVATE_AUDIO_HOSTS: RegExp[] = [\n\t/^localhost$/i,\n\t/^127(?:\\.\\d{1,3}){3}$/,\n\t/^0(?:\\.\\d{1,3}){3}$/,\n\t/^10(?:\\.\\d{1,3}){3}$/,\n\t/^192\\.168(?:\\.\\d{1,3}){2}$/,\n\t/^172\\.(?:1[6-9]|2\\d|3[01])(?:\\.\\d{1,3}){2}$/,\n\t/^169\\.254(?:\\.\\d{1,3}){2}$/,\n\t/^::1$/,\n\t/^fe80:/i,\n\t/^fc00:/i,\n\t/^fd[0-9a-f]{2}:/i,\n\t/^metadata\\.google\\.internal$/i,\n\t/^metadata\\.azure\\.internal$/i,\n\t/^metadata\\.packet\\.net$/i,\n];\n\nfunction isSafeSsmlAudioSrc(raw: string): boolean {\n\tif (typeof raw !== \"string\" || raw.length === 0) return false;\n\tlet parsed: URL;\n\ttry {\n\t\tparsed = new URL(raw);\n\t} catch {\n\t\treturn false;\n\t}\n\tif (parsed.protocol !== \"http:\" && parsed.protocol !== \"https:\") {\n\t\treturn false;\n\t}\n\tconst hostname = parsed.hostname.replace(/^\\[|\\]$/g, \"\").replace(/\\.$/, \"\");\n\treturn !SSML_PRIVATE_AUDIO_HOSTS.some((pattern) => pattern.test(hostname));\n}\n\n/**\n * Sanitize an SSML subtree in place: remove disallowed attributes and\n * replace disallowed elements with their text content (so phrasing order\n * is preserved but no scripts / iframes / unknown tags survive).\n */\nexport function sanitizeSsmlElement(element: Element): void {\n\t// Walk children snapshot first because we may replace nodes as we go.\n\tconst children = Array.from(element.children);\n\tfor (const child of children) {\n\t\tconst tagName = child.tagName.toLowerCase();\n\t\tif (SSML_DROP_FULLY_TAGS.has(tagName)) {\n\t\t\tchild.remove();\n\t\t\tcontinue;\n\t\t}\n\t\tsanitizeSsmlElement(child);\n\t\tif (!SSML_ALLOWED_TAGS.has(tagName)) {\n\t\t\tconst textNode = element.ownerDocument.createTextNode(\n\t\t\t\tchild.textContent ?? \"\",\n\t\t\t);\n\t\t\tchild.replaceWith(textNode);\n\t\t}\n\t}\n\t// Strip disallowed attributes on the surviving node.\n\tconst attrNames = Array.from(element.attributes).map((attr) => attr.name);\n\tfor (const attrName of attrNames) {\n\t\tif (!SSML_ALLOWED_ATTRS.has(attrName.toLowerCase())) {\n\t\t\telement.removeAttribute(attrName);\n\t\t}\n\t}\n\t// Belt-and-braces: even though `src` is allow-listed, SSML `<audio>`\n\t// sends its URL to a server-side TTS provider that will dereference\n\t// it. Refuse non-http(s) schemes and private / cloud-metadata hosts\n\t// at the SSML boundary so we never forward an SSRF primitive.\n\tif (element.tagName.toLowerCase() === \"audio\") {\n\t\tconst src = element.getAttribute(\"src\");\n\t\tif (src !== null && !isSafeSsmlAudioSrc(src)) {\n\t\t\telement.removeAttribute(\"src\");\n\t\t}\n\t}\n}\n\n/**\n * Serialize a sanitized `<speak>` element back to a minimal SSML string.\n * Uses a manual walker instead of `outerHTML` so that any namespace\n * quirks (e.g. `xmlns` attributes added by the HTML parser) are\n * normalised and disallowed descendants cannot reappear through quirks\n * in the serializer.\n */\nexport function serializeSsmlElement(element: Element): string {\n\tconst tagName = element.tagName.toLowerCase();\n\tconst attrs = Array.from(element.attributes)\n\t\t.filter((attr) => SSML_ALLOWED_ATTRS.has(attr.name.toLowerCase()))\n\t\t.map((attr) => ` ${attr.name}=\"${escapeXmlAttr(attr.value)}\"`)\n\t\t.join(\"\");\n\t// SSML void elements (e.g. <break>, <mark>) must be emitted as\n\t// self-closing so providers like AWS Polly accept them. Emitting\n\t// `<break></break>` parses fine on the SSML side but is wasteful;\n\t// emitting `<break>` (open without close) is invalid SSML.\n\tif (SSML_VOID_TAGS.has(tagName)) {\n\t\treturn `<${tagName}${attrs}/>`;\n\t}\n\tconst childPieces: string[] = [];\n\tfor (const node of Array.from(element.childNodes)) {\n\t\tif (node.nodeType === 3 /* text */) {\n\t\t\tchildPieces.push(escapeXmlText(node.nodeValue ?? \"\"));\n\t\t} else if (node.nodeType === 1 /* element */) {\n\t\t\tconst childElement = node as Element;\n\t\t\tconst childTag = childElement.tagName.toLowerCase();\n\t\t\tif (SSML_DROP_FULLY_TAGS.has(childTag)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (SSML_ALLOWED_TAGS.has(childTag)) {\n\t\t\t\tchildPieces.push(serializeSsmlElement(childElement));\n\t\t\t} else {\n\t\t\t\tchildPieces.push(escapeXmlText(childElement.textContent ?? \"\"));\n\t\t\t}\n\t\t}\n\t}\n\treturn `<${tagName}${attrs}>${childPieces.join(\"\")}</${tagName}>`;\n}\n\nexport function sanitizeSsmlString(input: string): string {\n\tconst trimmed = String(input || \"\").trim();\n\tif (!trimmed || !trimmed.includes(\"<\")) return input;\n\tif (typeof DOMParser === \"undefined\") return input;\n\tconst parser = new DOMParser();\n\tconst doc = parser.parseFromString(expandSelfClosingVoidTags(trimmed), \"text/html\");\n\tconst speakElement = doc.querySelector(\"speak\");\n\tif (speakElement) {\n\t\tsanitizeSsmlElement(speakElement);\n\t\treturn serializeSsmlElement(speakElement);\n\t}\n\tconst wrapper = doc.createElement(\"speak\");\n\tfor (const node of Array.from(doc.body.childNodes)) {\n\t\twrapper.appendChild(node);\n\t}\n\tsanitizeSsmlElement(wrapper);\n\treturn Array.from(wrapper.childNodes)\n\t\t.map((node) => {\n\t\t\tif (node.nodeType === 3 /* text */) {\n\t\t\t\treturn escapeXmlText(node.nodeValue ?? \"\");\n\t\t\t}\n\t\t\tif (node.nodeType === 1 /* element */) {\n\t\t\t\tconst child = node as Element;\n\t\t\t\tif (SSML_ALLOWED_TAGS.has(child.tagName.toLowerCase())) {\n\t\t\t\t\treturn serializeSsmlElement(child);\n\t\t\t\t}\n\t\t\t\treturn escapeXmlText(child.textContent ?? \"\");\n\t\t\t}\n\t\t\treturn \"\";\n\t\t})\n\t\t.join(\"\");\n}\n\nfunction escapeXmlText(value: string): string {\n\treturn value\n\t\t.replace(/&/g, \"&\")\n\t\t.replace(/</g, \"<\")\n\t\t.replace(/>/g, \">\");\n}\n\nfunction escapeXmlAttr(value: string): string {\n\treturn value\n\t\t.replace(/&/g, \"&\")\n\t\t.replace(/</g, \"<\")\n\t\t.replace(/>/g, \">\")\n\t\t.replace(/\"/g, \""\");\n}\n\n/**\n * SSMLExtractor Service\n *\n * Extracts embedded SSML from PIE content and generates accessibility catalogs.\n */\nexport class SSMLExtractor {\n\tprivate catalogCounter = 0;\n\n\t/**\n\t * Extract SSML from entire item config (markup + models)\n\t *\n\t * @param config Item configuration with potential embedded SSML\n\t * @returns Extracted catalogs and cleaned config\n\t */\n\textractFromItemConfig(config: ConfigEntity): ExtractionResult {\n\t\tconst allCatalogs: AccessibilityCatalog[] = [];\n\n\t\t// Shallow clone of config + a fresh models array. The per-model/choice\n\t\t// objects are replaced (not mutated in place) by the `.map` below, so the\n\t\t// caller's original config and its models are never mutated.\n\t\tconst cleanedConfig: ConfigEntity = {\n\t\t\t...config,\n\t\t\tmodels: config.models ? [...config.models] : [],\n\t\t};\n\n\t\t// 1. Extract from top-level markup (passages)\n\t\tif (config.markup) {\n\t\t\tconst markupResult = this.extractFromMarkup(config.markup, \"markup\");\n\t\t\tallCatalogs.push(...markupResult.catalogs);\n\t\t\tcleanedConfig.markup = markupResult.cleanedMarkup;\n\t\t}\n\n\t\t// 2. Extract from models (prompts, choices, etc.)\n\t\tif (config.models && config.models.length > 0) {\n\t\t\tcleanedConfig.models = config.models.map((model) => {\n\t\t\t\tconst cleanedModel = { ...model };\n\t\t\t\tconst modelCatalogs: AccessibilityCatalog[] = [];\n\n\t\t\t\t// Extract from prompt\n\t\t\t\tif (model.prompt && typeof model.prompt === \"string\") {\n\t\t\t\t\tconst promptResult = this.extractFromMarkup(\n\t\t\t\t\t\tmodel.prompt,\n\t\t\t\t\t\t`prompt-${model.id}`,\n\t\t\t\t\t);\n\t\t\t\t\tmodelCatalogs.push(...promptResult.catalogs);\n\t\t\t\t\tcleanedModel.prompt = promptResult.cleanedMarkup;\n\t\t\t\t}\n\n\t\t\t\t// Extract from choices\n\t\t\t\tif (model.choices && Array.isArray(model.choices)) {\n\t\t\t\t\tcleanedModel.choices = model.choices.map((choice) => {\n\t\t\t\t\t\tif (choice.label && typeof choice.label === \"string\") {\n\t\t\t\t\t\t\tconst choiceResult = this.extractFromMarkup(\n\t\t\t\t\t\t\t\tchoice.label,\n\t\t\t\t\t\t\t\t`choice-${model.id}-${choice.value}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tmodelCatalogs.push(...choiceResult.catalogs);\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t...choice,\n\t\t\t\t\t\t\t\tlabel: choiceResult.cleanedMarkup,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn choice;\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tallCatalogs.push(...modelCatalogs);\n\t\t\t\treturn cleanedModel;\n\t\t\t});\n\t\t}\n\n\t\treturn {\n\t\t\tcatalogs: allCatalogs,\n\t\t\tcleanedConfig,\n\t\t};\n\t}\n\n\t/**\n\t * Extract SSML from markup string\n\t *\n\t * @param markup HTML markup potentially containing <speak> elements\n\t * @param idPrefix Prefix for generating catalog IDs\n\t * @returns Extracted catalogs and cleaned markup\n\t */\n\tprivate extractFromMarkup(\n\t\tmarkup: string,\n\t\tidPrefix: string,\n\t): MarkupExtractionResult {\n\t\tif (!markup || markup.trim() === \"\") {\n\t\t\treturn { catalogs: [], cleanedMarkup: markup };\n\t\t}\n\n\t\t// Check if running in browser environment\n\t\tif (typeof window === \"undefined\" || typeof DOMParser === \"undefined\") {\n\t\t\tconsole.warn(\n\t\t\t\t\"[SSMLExtractor] DOMParser not available (SSR?), skipping extraction\",\n\t\t\t);\n\t\t\treturn { catalogs: [], cleanedMarkup: markup };\n\t\t}\n\n\t\tconst catalogs: AccessibilityCatalog[] = [];\n\n\t\ttry {\n\t\t\tconst parser = new DOMParser();\n\t\t\tconst doc = parser.parseFromString(\n\t\t\t\texpandSelfClosingVoidTags(markup),\n\t\t\t\t\"text/html\",\n\t\t\t);\n\n\t\t\t// Find all <speak> elements\n\t\t\tconst speakElements = Array.from(doc.querySelectorAll(\"speak\"));\n\n\t\t\tif (speakElements.length === 0) {\n\t\t\t\t// No SSML found, return original markup\n\t\t\t\treturn { catalogs: [], cleanedMarkup: markup };\n\t\t\t}\n\n\t\t\t// Process each <speak> element\n\t\t\tfor (const speakEl of speakElements) {\n\t\t\t\ttry {\n\t\t\t\t\t// Generate unique catalog ID\n\t\t\t\t\tconst catalogId = this.generateCatalogId(idPrefix);\n\n\t\t\t\t\t// Sanitize before serializing so the SSML forwarded to the TTS\n\t\t\t\t\t// provider only contains spec-allowed tags/attributes. This\n\t\t\t\t\t// closes an author-content -> TTS-server pipeline that would\n\t\t\t\t\t// otherwise accept arbitrary HTML.\n\t\t\t\t\tsanitizeSsmlElement(speakEl);\n\t\t\t\t\tconst ssmlContent = serializeSsmlElement(speakEl);\n\n\t\t\t\t\t// Extract language (check both xml:lang and lang attributes)\n\t\t\t\t\tconst language =\n\t\t\t\t\t\tspeakEl.getAttribute(\"xml:lang\") ||\n\t\t\t\t\t\tspeakEl.getAttribute(\"lang\") ||\n\t\t\t\t\t\t\"en-US\";\n\n\t\t\t\t\t// Get plain text for visual display\n\t\t\t\t\tconst plainText = speakEl.textContent || \"\";\n\n\t\t\t\t\t// Find parent element or create wrapper\n\t\t\t\t\tlet wrapper = speakEl.parentElement;\n\n\t\t\t\t\tif (!wrapper || wrapper.tagName === \"BODY\") {\n\t\t\t\t\t\t// SPEAK is at root level - create span wrapper\n\t\t\t\t\t\tconst span = doc.createElement(\"span\");\n\t\t\t\t\t\tspeakEl.parentNode?.insertBefore(span, speakEl);\n\t\t\t\t\t\tspan.appendChild(doc.createTextNode(plainText));\n\t\t\t\t\t\twrapper = span;\n\t\t\t\t\t\tspeakEl.remove();\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Just remove <speak> - visual content should be in sibling element\n\t\t\t\t\t\tspeakEl.remove();\n\t\t\t\t\t}\n\n\t\t\t\t\t// Tag the wrapper with the QTI-style catalog reference so the\n\t\t\t\t\t// runtime can resolve this region's spoken content. Same attribute\n\t\t\t\t\t// authored content uses (`data-catalog-idref`) — one canonical name.\n\t\t\t\t\tif (wrapper) {\n\t\t\t\t\t\twrapper.setAttribute(\"data-catalog-idref\", catalogId);\n\t\t\t\t\t}\n\n\t\t\t\t\t// Create catalog entry\n\t\t\t\t\tcatalogs.push({\n\t\t\t\t\t\tidentifier: catalogId,\n\t\t\t\t\t\tcards: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcatalog: \"spoken\",\n\t\t\t\t\t\t\t\tlanguage,\n\t\t\t\t\t\t\t\tcontent: ssmlContent,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\"[SSMLExtractor] Error processing <speak> element:\",\n\t\t\t\t\t\terror,\n\t\t\t\t\t);\n\t\t\t\t\t// Continue with other elements\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Return cleaned markup\n\t\t\tconst cleanedMarkup = doc.body.innerHTML;\n\n\t\t\treturn { catalogs, cleanedMarkup };\n\t\t} catch (error) {\n\t\t\tconsole.error(\"[SSMLExtractor] Error parsing markup:\", error);\n\t\t\t// Return original markup if parsing fails\n\t\t\treturn { catalogs: [], cleanedMarkup: markup };\n\t\t}\n\t}\n\n\t/**\n\t * Generate unique catalog ID\n\t *\n\t * @param prefix Context prefix (e.g., 'prompt-q1', 'choice-q1-a')\n\t * @returns Unique catalog ID (e.g., 'auto-prompt-q1-0')\n\t */\n\tprivate generateCatalogId(prefix: string): string {\n\t\tconst id = `auto-${prefix}-${this.catalogCounter}`;\n\t\tthis.catalogCounter++;\n\t\treturn id;\n\t}\n\n\t/**\n\t * Reset counter (useful for testing or new extraction contexts)\n\t */\n\treset(): void {\n\t\tthis.catalogCounter = 0;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SSMLExtractor.js","sourceRoot":"","sources":["../../src/services/SSMLExtractor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAwBH;;;;;GAKG;AACH,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IACjC,OAAO;IACP,OAAO;IACP,SAAS;IACT,UAAU;IACV,QAAQ;IACR,KAAK;IACL,MAAM;IACN,SAAS;IACT,MAAM;IACN,GAAG;IACH,GAAG;IACH,OAAO;IACP,OAAO;IACP,SAAS;CACT,CAAC,CAAC;AAEH;;;;GAIG;AACH;;;;GAIG;AACH,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC;IACpC,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,OAAO;IACP,eAAe;IACf,UAAU;IACV,UAAU;CACV,CAAC,CAAC;AAEH,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;IAClC,UAAU;IACV,IAAI;IACJ,MAAM;IACN,UAAU;IACV,MAAM;IACN,OAAO;IACP,QAAQ;IACR,MAAM;IACN,cAAc;IACd,QAAQ;IACR,QAAQ;IACR,UAAU;IACV,UAAU;IACV,MAAM;IACN,QAAQ;IACR,KAAK;CACL,CAAC,CAAC;AAEH;;;;;;;;;;;;;GAaG;AACH,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,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AAK,EAAE,CAAC;oBAChB,OAAO,CAAC,KAAK,CACZ,mDAAmD,EACnD,KAAK,CACL,CAAC;oBACF,+BAA+B;gBAChC,CAAC;YACF,CAAC;YAED,wBAAwB;YACxB,MAAM,aAAa,GAAG,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC;YAEzC,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC;QACpC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,KAAK,CAAC,CAAC;YAC9D,0CAA0C;YAC1C,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC;QAChD,CAAC;IACF,CAAC;IAED;;;;;OAKG;IACK,iBAAiB,CAAC,MAAc;QACvC,MAAM,EAAE,GAAG,QAAQ,MAAM,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;QACnD,IAAI,CAAC,cAAc,EAAE,CAAC;QACtB,OAAO,EAAE,CAAC;IACX,CAAC;IAED;;OAEG;IACH,KAAK;QACJ,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC;IACzB,CAAC;CACD","sourcesContent":["/**\n * SSMLExtractor\n *\n * Service for extracting embedded SSML from PIE item content and converting\n * it into QTI 3.0 accessibility catalogs.\n *\n * Authors can embed <speak> SSML tags directly in content for convenience.\n * The extractor automatically:\n * 1. Parses markup and finds all <speak> elements\n * 2. Extracts SSML content with language metadata\n * 3. Generates accessibility catalogs with unique IDs\n * 4. Cleans visual markup (removes SSML, adds data-catalog-idref)\n *\n * This enables proper pronunciation, emphasis, and pacing for TTS without\n * requiring authors to maintain separate catalog files.\n *\n * Part of PIE Assessment Toolkit.\n */\n\nimport type {\n\tAccessibilityCatalog,\n\tConfigEntity,\n\tPieModel,\n} from \"@pie-players/pie-players-shared/types\";\n\n/**\n * Result from extracting SSML from markup\n */\ninterface MarkupExtractionResult {\n\tcatalogs: AccessibilityCatalog[];\n\tcleanedMarkup: string;\n}\n\n/**\n * Result from extracting SSML from entire item config\n */\nexport interface ExtractionResult {\n\tcatalogs: AccessibilityCatalog[];\n\tcleanedConfig: ConfigEntity;\n}\n\n/**\n * Allow-listed SSML elements (from the SSML 1.1 spec subset we forward to\n * TTS providers). Anything outside this list is unwrapped during\n * sanitization so we never leak author-supplied scripts, iframes, or\n * arbitrary HTML into the TTS pipeline.\n */\nconst SSML_ALLOWED_TAGS = new Set([\n\t\"speak\",\n\t\"break\",\n\t\"prosody\",\n\t\"emphasis\",\n\t\"say-as\",\n\t\"sub\",\n\t\"mark\",\n\t\"phoneme\",\n\t\"lang\",\n\t\"p\",\n\t\"s\",\n\t\"voice\",\n\t\"audio\",\n\t\"lexicon\",\n]);\n\n/**\n * Allow-listed attributes across SSML elements. Attribute allow-listing is\n * global (not per-tag) because the union is small and consistent across\n * providers.\n */\n/**\n * Tags whose content must be dropped entirely (rather than unwrapped to\n * preserve phrasing text). These are dangerous containers whose text\n * payload could be re-interpreted downstream.\n */\nconst SSML_DROP_FULLY_TAGS = new Set([\n\t\"script\",\n\t\"style\",\n\t\"iframe\",\n\t\"object\",\n\t\"embed\",\n\t\"foreignobject\",\n\t\"noscript\",\n\t\"template\",\n]);\n\nconst SSML_ALLOWED_ATTRS = new Set([\n\t\"alphabet\",\n\t\"ph\",\n\t\"time\",\n\t\"strength\",\n\t\"rate\",\n\t\"pitch\",\n\t\"volume\",\n\t\"name\",\n\t\"interpret-as\",\n\t\"format\",\n\t\"detail\",\n\t\"language\",\n\t\"xml:lang\",\n\t\"lang\",\n\t\"gender\",\n\t\"src\",\n]);\n\n/**\n * SSML elements that are empty in practice (no child content). Authors\n * typically write them as self-closing (`<break time=\"200ms\"/>`). HTML's\n * parser does NOT recognize them as void elements and silently drops the\n * `/`, then nests every subsequent sibling as a child — producing\n * malformed SSML like `<break>…rest of paragraph…</break>` when\n * round-tripped. Pre-processing self-closing forms to explicit\n * open+close pairs before HTML parsing avoids the reflow, and the\n * serializer re-emits them as self-closing so providers see valid SSML.\n *\n * `audio` is intentionally excluded — SSML <audio> may carry fallback\n * children (the spec's \"alternate content\"), so treating it as void\n * would lose author intent.\n */\nconst SSML_VOID_TAGS = new Set([\"break\", \"mark\", \"lexicon\"]);\n\n/**\n * Normalize self-closing forms of SSML void elements to explicit\n * open+close pairs BEFORE handing the string to an HTML parser. The\n * HTML5 parser ignores the `/` on non-void tags, so `<break/>` becomes\n * a plain `<break>` open tag that swallows every following sibling.\n * Rewriting to `<break></break>` preserves the empty-element shape\n * across the HTML round-trip.\n */\nfunction expandSelfClosingVoidTags(input: string): string {\n\tlet next = input;\n\tfor (const tag of SSML_VOID_TAGS) {\n\t\tconst selfClosing = new RegExp(`<${tag}\\\\b([^>/]*?)\\\\s*/>`, \"gi\");\n\t\tnext = next.replace(selfClosing, (_match, attrs: string) => {\n\t\t\tconst attrText = attrs ? attrs.replace(/\\s+$/, \"\") : \"\";\n\t\t\treturn `<${tag}${attrText}></${tag}>`;\n\t\t});\n\t}\n\treturn next;\n}\n\n/**\n * Hosts that must never appear inside an SSML `<audio src>` because they\n * would cause the server-side TTS provider to fetch a private / metadata\n * endpoint on behalf of the request. Mirrors the SchoolCity provider's\n * defense-in-depth check; the SSML-side block is cheap and belt-and-braces.\n */\nconst SSML_PRIVATE_AUDIO_HOSTS: RegExp[] = [\n\t/^localhost$/i,\n\t/^127(?:\\.\\d{1,3}){3}$/,\n\t/^0(?:\\.\\d{1,3}){3}$/,\n\t/^10(?:\\.\\d{1,3}){3}$/,\n\t/^192\\.168(?:\\.\\d{1,3}){2}$/,\n\t/^172\\.(?:1[6-9]|2\\d|3[01])(?:\\.\\d{1,3}){2}$/,\n\t/^169\\.254(?:\\.\\d{1,3}){2}$/,\n\t/^::1$/,\n\t/^fe80:/i,\n\t/^fc00:/i,\n\t/^fd[0-9a-f]{2}:/i,\n\t/^metadata\\.google\\.internal$/i,\n\t/^metadata\\.azure\\.internal$/i,\n\t/^metadata\\.packet\\.net$/i,\n];\n\nfunction isSafeSsmlAudioSrc(raw: string): boolean {\n\tif (typeof raw !== \"string\" || raw.length === 0) return false;\n\tlet parsed: URL;\n\ttry {\n\t\tparsed = new URL(raw);\n\t} catch {\n\t\treturn false;\n\t}\n\tif (parsed.protocol !== \"http:\" && parsed.protocol !== \"https:\") {\n\t\treturn false;\n\t}\n\tconst hostname = parsed.hostname.replace(/^\\[|\\]$/g, \"\").replace(/\\.$/, \"\");\n\treturn !SSML_PRIVATE_AUDIO_HOSTS.some((pattern) => pattern.test(hostname));\n}\n\n/**\n * Sanitize an SSML subtree in place: remove disallowed attributes and\n * replace disallowed elements with their text content (so phrasing order\n * is preserved but no scripts / iframes / unknown tags survive).\n */\nexport function sanitizeSsmlElement(element: Element): void {\n\t// Walk children snapshot first because we may replace nodes as we go.\n\tconst children = Array.from(element.children);\n\tfor (const child of children) {\n\t\tconst tagName = child.tagName.toLowerCase();\n\t\tif (SSML_DROP_FULLY_TAGS.has(tagName)) {\n\t\t\tchild.remove();\n\t\t\tcontinue;\n\t\t}\n\t\tsanitizeSsmlElement(child);\n\t\tif (!SSML_ALLOWED_TAGS.has(tagName)) {\n\t\t\tconst textNode = element.ownerDocument.createTextNode(\n\t\t\t\tchild.textContent ?? \"\",\n\t\t\t);\n\t\t\tchild.replaceWith(textNode);\n\t\t}\n\t}\n\t// Strip disallowed attributes on the surviving node.\n\tconst attrNames = Array.from(element.attributes).map((attr) => attr.name);\n\tfor (const attrName of attrNames) {\n\t\tif (!SSML_ALLOWED_ATTRS.has(attrName.toLowerCase())) {\n\t\t\telement.removeAttribute(attrName);\n\t\t}\n\t}\n\t// Belt-and-braces: even though `src` is allow-listed, SSML `<audio>`\n\t// sends its URL to a server-side TTS provider that will dereference\n\t// it. Refuse non-http(s) schemes and private / cloud-metadata hosts\n\t// at the SSML boundary so we never forward an SSRF primitive.\n\tif (element.tagName.toLowerCase() === \"audio\") {\n\t\tconst src = element.getAttribute(\"src\");\n\t\tif (src !== null && !isSafeSsmlAudioSrc(src)) {\n\t\t\telement.removeAttribute(\"src\");\n\t\t}\n\t}\n}\n\n/**\n * Serialize a sanitized `<speak>` element back to a minimal SSML string.\n * Uses a manual walker instead of `outerHTML` so that any namespace\n * quirks (e.g. `xmlns` attributes added by the HTML parser) are\n * normalised and disallowed descendants cannot reappear through quirks\n * in the serializer.\n */\nexport function serializeSsmlElement(element: Element): string {\n\tconst tagName = element.tagName.toLowerCase();\n\tconst attrs = Array.from(element.attributes)\n\t\t.filter((attr) => SSML_ALLOWED_ATTRS.has(attr.name.toLowerCase()))\n\t\t.map((attr) => ` ${attr.name}=\"${escapeXmlAttr(attr.value)}\"`)\n\t\t.join(\"\");\n\t// SSML void elements (e.g. <break>, <mark>) must be emitted as\n\t// self-closing so providers like AWS Polly accept them. Emitting\n\t// `<break></break>` parses fine on the SSML side but is wasteful;\n\t// emitting `<break>` (open without close) is invalid SSML.\n\tif (SSML_VOID_TAGS.has(tagName)) {\n\t\treturn `<${tagName}${attrs}/>`;\n\t}\n\tconst childPieces: string[] = [];\n\tfor (const node of Array.from(element.childNodes)) {\n\t\tif (node.nodeType === 3 /* text */) {\n\t\t\tchildPieces.push(escapeXmlText(node.nodeValue ?? \"\"));\n\t\t} else if (node.nodeType === 1 /* element */) {\n\t\t\tconst childElement = node as Element;\n\t\t\tconst childTag = childElement.tagName.toLowerCase();\n\t\t\tif (SSML_DROP_FULLY_TAGS.has(childTag)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (SSML_ALLOWED_TAGS.has(childTag)) {\n\t\t\t\tchildPieces.push(serializeSsmlElement(childElement));\n\t\t\t} else {\n\t\t\t\tchildPieces.push(escapeXmlText(childElement.textContent ?? \"\"));\n\t\t\t}\n\t\t}\n\t}\n\treturn `<${tagName}${attrs}>${childPieces.join(\"\")}</${tagName}>`;\n}\n\nexport function sanitizeSsmlString(input: string): string {\n\tconst trimmed = String(input || \"\").trim();\n\tif (!trimmed || !trimmed.includes(\"<\")) return input;\n\tif (typeof DOMParser === \"undefined\") return input;\n\tconst parser = new DOMParser();\n\tconst doc = parser.parseFromString(\n\t\texpandSelfClosingVoidTags(trimmed),\n\t\t\"text/html\",\n\t);\n\tconst speakElement = doc.querySelector(\"speak\");\n\tif (speakElement) {\n\t\tsanitizeSsmlElement(speakElement);\n\t\treturn serializeSsmlElement(speakElement);\n\t}\n\tconst wrapper = doc.createElement(\"speak\");\n\tfor (const node of Array.from(doc.body.childNodes)) {\n\t\twrapper.appendChild(node);\n\t}\n\tsanitizeSsmlElement(wrapper);\n\treturn Array.from(wrapper.childNodes)\n\t\t.map((node) => {\n\t\t\tif (node.nodeType === 3 /* text */) {\n\t\t\t\treturn escapeXmlText(node.nodeValue ?? \"\");\n\t\t\t}\n\t\t\tif (node.nodeType === 1 /* element */) {\n\t\t\t\tconst child = node as Element;\n\t\t\t\tif (SSML_ALLOWED_TAGS.has(child.tagName.toLowerCase())) {\n\t\t\t\t\treturn serializeSsmlElement(child);\n\t\t\t\t}\n\t\t\t\treturn escapeXmlText(child.textContent ?? \"\");\n\t\t\t}\n\t\t\treturn \"\";\n\t\t})\n\t\t.join(\"\");\n}\n\nfunction escapeXmlText(value: string): string {\n\treturn value\n\t\t.replace(/&/g, \"&\")\n\t\t.replace(/</g, \"<\")\n\t\t.replace(/>/g, \">\");\n}\n\nfunction escapeXmlAttr(value: string): string {\n\treturn value\n\t\t.replace(/&/g, \"&\")\n\t\t.replace(/</g, \"<\")\n\t\t.replace(/>/g, \">\")\n\t\t.replace(/\"/g, \""\");\n}\n\n/**\n * SSMLExtractor Service\n *\n * Extracts embedded SSML from PIE content and generates accessibility catalogs.\n */\nexport class SSMLExtractor {\n\tprivate catalogCounter = 0;\n\n\t/**\n\t * Extract SSML from entire item config (markup + models)\n\t *\n\t * @param config Item configuration with potential embedded SSML\n\t * @returns Extracted catalogs and cleaned config\n\t */\n\textractFromItemConfig(config: ConfigEntity): ExtractionResult {\n\t\tconst allCatalogs: AccessibilityCatalog[] = [];\n\n\t\t// Shallow clone of config + a fresh models array. The per-model/choice\n\t\t// objects are replaced (not mutated in place) by the `.map` below, so the\n\t\t// caller's original config and its models are never mutated.\n\t\tconst cleanedConfig: ConfigEntity = {\n\t\t\t...config,\n\t\t\tmodels: config.models ? [...config.models] : [],\n\t\t};\n\n\t\t// 1. Extract from top-level markup (passages)\n\t\tif (config.markup) {\n\t\t\tconst markupResult = this.extractFromMarkup(config.markup, \"markup\");\n\t\t\tallCatalogs.push(...markupResult.catalogs);\n\t\t\tcleanedConfig.markup = markupResult.cleanedMarkup;\n\t\t}\n\n\t\t// 2. Extract from models (prompts, choices, etc.)\n\t\tif (config.models && config.models.length > 0) {\n\t\t\tcleanedConfig.models = config.models.map((model) => {\n\t\t\t\tconst cleanedModel = { ...model };\n\t\t\t\tconst modelCatalogs: AccessibilityCatalog[] = [];\n\n\t\t\t\t// Extract from prompt\n\t\t\t\tif (model.prompt && typeof model.prompt === \"string\") {\n\t\t\t\t\tconst promptResult = this.extractFromMarkup(\n\t\t\t\t\t\tmodel.prompt,\n\t\t\t\t\t\t`prompt-${model.id}`,\n\t\t\t\t\t);\n\t\t\t\t\tmodelCatalogs.push(...promptResult.catalogs);\n\t\t\t\t\tcleanedModel.prompt = promptResult.cleanedMarkup;\n\t\t\t\t}\n\n\t\t\t\t// Extract from choices\n\t\t\t\tif (model.choices && Array.isArray(model.choices)) {\n\t\t\t\t\tcleanedModel.choices = model.choices.map((choice) => {\n\t\t\t\t\t\tif (choice.label && typeof choice.label === \"string\") {\n\t\t\t\t\t\t\tconst choiceResult = this.extractFromMarkup(\n\t\t\t\t\t\t\t\tchoice.label,\n\t\t\t\t\t\t\t\t`choice-${model.id}-${choice.value}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tmodelCatalogs.push(...choiceResult.catalogs);\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t...choice,\n\t\t\t\t\t\t\t\tlabel: choiceResult.cleanedMarkup,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn choice;\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tallCatalogs.push(...modelCatalogs);\n\t\t\t\treturn cleanedModel;\n\t\t\t});\n\t\t}\n\n\t\treturn {\n\t\t\tcatalogs: allCatalogs,\n\t\t\tcleanedConfig,\n\t\t};\n\t}\n\n\t/**\n\t * Extract SSML from markup string\n\t *\n\t * @param markup HTML markup potentially containing <speak> elements\n\t * @param idPrefix Prefix for generating catalog IDs\n\t * @returns Extracted catalogs and cleaned markup\n\t */\n\tprivate extractFromMarkup(\n\t\tmarkup: string,\n\t\tidPrefix: string,\n\t): MarkupExtractionResult {\n\t\tif (!markup || markup.trim() === \"\") {\n\t\t\treturn { catalogs: [], cleanedMarkup: markup };\n\t\t}\n\n\t\t// Check if running in browser environment\n\t\tif (typeof window === \"undefined\" || typeof DOMParser === \"undefined\") {\n\t\t\tconsole.warn(\n\t\t\t\t\"[SSMLExtractor] DOMParser not available (SSR?), skipping extraction\",\n\t\t\t);\n\t\t\treturn { catalogs: [], cleanedMarkup: markup };\n\t\t}\n\n\t\tconst catalogs: AccessibilityCatalog[] = [];\n\n\t\ttry {\n\t\t\tconst parser = new DOMParser();\n\t\t\tconst doc = parser.parseFromString(\n\t\t\t\texpandSelfClosingVoidTags(markup),\n\t\t\t\t\"text/html\",\n\t\t\t);\n\n\t\t\t// Find all <speak> elements\n\t\t\tconst speakElements = Array.from(doc.querySelectorAll(\"speak\"));\n\n\t\t\tif (speakElements.length === 0) {\n\t\t\t\t// No SSML found, return original markup\n\t\t\t\treturn { catalogs: [], cleanedMarkup: markup };\n\t\t\t}\n\n\t\t\t// Process each <speak> element\n\t\t\tfor (const speakEl of speakElements) {\n\t\t\t\ttry {\n\t\t\t\t\t// Generate unique catalog ID\n\t\t\t\t\tconst catalogId = this.generateCatalogId(idPrefix);\n\n\t\t\t\t\t// Sanitize before serializing so the SSML forwarded to the TTS\n\t\t\t\t\t// provider only contains spec-allowed tags/attributes. This\n\t\t\t\t\t// closes an author-content -> TTS-server pipeline that would\n\t\t\t\t\t// otherwise accept arbitrary HTML.\n\t\t\t\t\tsanitizeSsmlElement(speakEl);\n\t\t\t\t\tconst ssmlContent = serializeSsmlElement(speakEl);\n\n\t\t\t\t\t// Extract language (check both xml:lang and lang attributes)\n\t\t\t\t\tconst language =\n\t\t\t\t\t\tspeakEl.getAttribute(\"xml:lang\") ||\n\t\t\t\t\t\tspeakEl.getAttribute(\"lang\") ||\n\t\t\t\t\t\t\"en-US\";\n\n\t\t\t\t\t// Get plain text for visual display\n\t\t\t\t\tconst plainText = speakEl.textContent || \"\";\n\n\t\t\t\t\t// Find parent element or create wrapper\n\t\t\t\t\tlet wrapper = speakEl.parentElement;\n\n\t\t\t\t\tif (!wrapper || wrapper.tagName === \"BODY\") {\n\t\t\t\t\t\t// SPEAK is at root level - create span wrapper\n\t\t\t\t\t\tconst span = doc.createElement(\"span\");\n\t\t\t\t\t\tspeakEl.parentNode?.insertBefore(span, speakEl);\n\t\t\t\t\t\tspan.appendChild(doc.createTextNode(plainText));\n\t\t\t\t\t\twrapper = span;\n\t\t\t\t\t\tspeakEl.remove();\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Just remove <speak> - visual content should be in sibling element\n\t\t\t\t\t\tspeakEl.remove();\n\t\t\t\t\t}\n\n\t\t\t\t\t// Tag the wrapper with the QTI-style catalog reference so the\n\t\t\t\t\t// runtime can resolve this region's spoken content. Same attribute\n\t\t\t\t\t// authored content uses (`data-catalog-idref`) — one canonical name.\n\t\t\t\t\tif (wrapper) {\n\t\t\t\t\t\twrapper.setAttribute(\"data-catalog-idref\", catalogId);\n\t\t\t\t\t}\n\n\t\t\t\t\t// Create catalog entry\n\t\t\t\t\tcatalogs.push({\n\t\t\t\t\t\tidentifier: catalogId,\n\t\t\t\t\t\tcards: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcatalog: \"spoken\",\n\t\t\t\t\t\t\t\tlanguage,\n\t\t\t\t\t\t\t\tcontent: ssmlContent,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\"[SSMLExtractor] Error processing <speak> element:\",\n\t\t\t\t\t\terror,\n\t\t\t\t\t);\n\t\t\t\t\t// Continue with other elements\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Return cleaned markup\n\t\t\tconst cleanedMarkup = doc.body.innerHTML;\n\n\t\t\treturn { catalogs, cleanedMarkup };\n\t\t} catch (error) {\n\t\t\tconsole.error(\"[SSMLExtractor] Error parsing markup:\", error);\n\t\t\t// Return original markup if parsing fails\n\t\t\treturn { catalogs: [], cleanedMarkup: markup };\n\t\t}\n\t}\n\n\t/**\n\t * Generate unique catalog ID\n\t *\n\t * @param prefix Context prefix (e.g., 'prompt-q1', 'choice-q1-a')\n\t * @returns Unique catalog ID (e.g., 'auto-prompt-q1-0')\n\t */\n\tprivate generateCatalogId(prefix: string): string {\n\t\tconst id = `auto-${prefix}-${this.catalogCounter}`;\n\t\tthis.catalogCounter++;\n\t\treturn id;\n\t}\n\n\t/**\n\t * Reset counter (useful for testing or new extraction contexts)\n\t */\n\treset(): void {\n\t\tthis.catalogCounter = 0;\n\t}\n}\n"]}
|
|
@@ -45,7 +45,10 @@ const sameRange = (left, right) => left === right ||
|
|
|
45
45
|
const sameRenderableHighlightTarget = (left, right) => {
|
|
46
46
|
if (left === right)
|
|
47
47
|
return true;
|
|
48
|
-
if (!left ||
|
|
48
|
+
if (!left ||
|
|
49
|
+
!right ||
|
|
50
|
+
left.type !== right.type ||
|
|
51
|
+
left.quality !== right.quality) {
|
|
49
52
|
return false;
|
|
50
53
|
}
|
|
51
54
|
if (left.type === "range" && right.type === "range") {
|
|
@@ -1094,7 +1097,7 @@ export class TTSService {
|
|
|
1094
1097
|
// emits playback chunks. The aggregate `contentToSpeak` stays plain text
|
|
1095
1098
|
// (`plan.plainSpeechText`) so seek/structural-pause planning is unaffected.
|
|
1096
1099
|
const playbackFormat = this.resolveGeneratedPlaybackFormat();
|
|
1097
|
-
const { plan, containsMathMarkup, visibleText: collectedVisibleText } = await buildGeneratedSpeechFromRoot({
|
|
1100
|
+
const { plan, containsMathMarkup, visibleText: collectedVisibleText, } = await buildGeneratedSpeechFromRoot({
|
|
1098
1101
|
contentRoot: contentElement,
|
|
1099
1102
|
language,
|
|
1100
1103
|
mathSpeech: this.getMathSpeechOptions(),
|