@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.
Files changed (86) hide show
  1. package/dist/attempt/AssessmentSession.js +2 -1
  2. package/dist/attempt/AssessmentSession.js.map +1 -1
  3. package/dist/attempt/adapters/activity-to-test-attempt-session.js +12 -8
  4. package/dist/attempt/adapters/activity-to-test-attempt-session.js.map +1 -1
  5. package/dist/components/ItemToolBar.custom-element.js +56 -17
  6. package/dist/components/PieAssessmentToolkit.custom-element.js +84 -29
  7. package/dist/components/SectionToolBar.custom-element.js +55 -17
  8. package/dist/index.d.ts +1 -1
  9. package/dist/index.js.map +1 -1
  10. package/dist/policy/core/pnp-policy-inputs.js +1 -2
  11. package/dist/policy/core/pnp-policy-inputs.js.map +1 -1
  12. package/dist/policy/core/provenance.js.map +1 -1
  13. package/dist/runtime/SectionRuntimeEngine.js +1 -1
  14. package/dist/runtime/SectionRuntimeEngine.js.map +1 -1
  15. package/dist/runtime/core/cohort.js.map +1 -1
  16. package/dist/runtime/core/engine-input.js.map +1 -1
  17. package/dist/runtime/core/engine-readiness.js.map +1 -1
  18. package/dist/runtime/core/engine-resolver.js.map +1 -1
  19. package/dist/runtime/core/engine-transition.js +1 -3
  20. package/dist/runtime/core/engine-transition.js.map +1 -1
  21. package/dist/runtime/registration-events.js.map +1 -1
  22. package/dist/runtime/session-event-emitter-policy.js.map +1 -1
  23. package/dist/services/HighlightCoordinator.js +2 -1
  24. package/dist/services/HighlightCoordinator.js.map +1 -1
  25. package/dist/services/I18nService.d.ts +1 -1
  26. package/dist/services/I18nService.js.map +1 -1
  27. package/dist/services/SSMLExtractor.js.map +1 -1
  28. package/dist/services/TTSService.js +5 -2
  29. package/dist/services/TTSService.js.map +1 -1
  30. package/dist/services/ThemeProvider.js.map +1 -1
  31. package/dist/services/ToolRegistry.d.ts +1 -1
  32. package/dist/services/ToolRegistry.js.map +1 -1
  33. package/dist/services/ToolkitCoordinator.js +21 -11
  34. package/dist/services/ToolkitCoordinator.js.map +1 -1
  35. package/dist/services/createDefaultToolRegistry.js +4 -2
  36. package/dist/services/createDefaultToolRegistry.js.map +1 -1
  37. package/dist/services/framework-error-bus.js.map +1 -1
  38. package/dist/services/framework-error.js.map +1 -1
  39. package/dist/services/interfaces.js.map +1 -1
  40. package/dist/services/section-controller-types.js.map +1 -1
  41. package/dist/services/tool-config-defaults.js +7 -1
  42. package/dist/services/tool-config-defaults.js.map +1 -1
  43. package/dist/services/tool-config-validation.js +3 -1
  44. package/dist/services/tool-config-validation.js.map +1 -1
  45. package/dist/services/tool-instance-id.js.map +1 -1
  46. package/dist/services/tool-providers/DesmosToolProvider.js.map +1 -1
  47. package/dist/services/tool-providers/TTSToolProvider.js.map +1 -1
  48. package/dist/services/toolbar-items.js.map +1 -1
  49. package/dist/services/tools-config-normalizer.js +1 -2
  50. package/dist/services/tools-config-normalizer.js.map +1 -1
  51. package/dist/services/tts/browser-provider.js +60 -18
  52. package/dist/services/tts/browser-provider.js.map +1 -1
  53. package/dist/services/tts/catalog-span-alignment.js +8 -3
  54. package/dist/services/tts/catalog-span-alignment.js.map +1 -1
  55. package/dist/services/tts/generated-speech/assemble-plan.js.map +1 -1
  56. package/dist/services/tts/generated-speech/index.d.ts +1 -1
  57. package/dist/services/tts/generated-speech/index.js +1 -1
  58. package/dist/services/tts/generated-speech/index.js.map +1 -1
  59. package/dist/services/tts/generated-speech/math-speech-cache.js +3 -1
  60. package/dist/services/tts/generated-speech/math-speech-cache.js.map +1 -1
  61. package/dist/services/tts/highlight-pipeline/boundary-normalizer.js.map +1 -1
  62. package/dist/services/tts/highlight-pipeline/create-highlight-plan.js.map +1 -1
  63. package/dist/services/tts/math-alignment/mathml-tokenizer.js.map +1 -1
  64. package/dist/services/tts/math-alignment/sequence-aligner.js.map +1 -1
  65. package/dist/services/tts/math-alignment/speech-tokenizer.js.map +1 -1
  66. package/dist/services/tts/math-aware-text-processing.js +6 -3
  67. package/dist/services/tts/math-aware-text-processing.js.map +1 -1
  68. package/dist/services/tts/math-speech.js +3 -1
  69. package/dist/services/tts/math-speech.js.map +1 -1
  70. package/dist/services/tts/visual-line-ranges.js.map +1 -1
  71. package/dist/services/tts-runtime-config.js +6 -2
  72. package/dist/services/tts-runtime-config.js.map +1 -1
  73. package/dist/tools/calculators/desmos-provider.js.map +1 -1
  74. package/dist/tools/default-tool-module-loaders.js.map +1 -1
  75. package/dist/tools/registrations/accessibility-tools.js.map +1 -1
  76. package/dist/tools/registrations/calculator.js +1 -1
  77. package/dist/tools/registrations/calculator.js.map +1 -1
  78. package/dist/tools/registrations/interaction-tools.js.map +1 -1
  79. package/dist/tools/registrations/measurement-tools.js.map +1 -1
  80. package/dist/tools/registrations/subject-specific-tools.js +1 -1
  81. package/dist/tools/registrations/subject-specific-tools.js.map +1 -1
  82. package/dist/tools/registrations/tts.js +4 -2
  83. package/dist/tools/registrations/tts.js.map +1 -1
  84. package/dist/tools/types.js.map +1 -1
  85. package/dist/tools/variant-resolver.js.map +1 -1
  86. package/package.json +7 -7
@@ -1 +1 @@
1
- {"version":3,"file":"ThemeProvider.js","sourceRoot":"","sources":["../../src/services/ThemeProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAwBH;;GAEG;AACH,MAAM,eAAe,GAA6B;IACjD,KAAK,EAAE,KAAK,EAAE,oBAAoB;IAClC,MAAM,EAAE,GAAG,EAAE,oBAAoB;IACjC,KAAK,EAAE,IAAI,EAAE,oBAAoB;IACjC,MAAM,EAAE,GAAG,EAAE,oBAAoB;CACjC,CAAC;AAEF;;GAEG;AACH,MAAM,aAAa,GAA0B;IAC5C,YAAY,EAAE,KAAK;IACnB,QAAQ,EAAE,QAAQ;IAClB,eAAe,EAAE,SAAS;IAC1B,eAAe,EAAE,SAAS;IAC1B,WAAW,EAAE,SAAS;IACtB,SAAS,EAAE,SAAS;IACpB,UAAU,EAAE,SAAS;IACrB,YAAY,EAAE,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C;QAC7D,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC;QAC5D,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,cAAc,CAAC,uBAAuB,CAAC,CAAC;QAC/D,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,cAAc,CAAC,2BAA2B,CAAC,CAAC;QACnE,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,cAAc,CAAC,0BAA0B,CAAC,CAAC;QAClE,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,cAAc,CAAC,wBAAwB,CAAC,CAAC;QAChE,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,cAAc,CAAC,4BAA4B,CAAC,CAAC;IACrE,CAAC;CACD","sourcesContent":["/**\n * ThemeProvider\n *\n * Applies consistent accessibility theming across items and tools.\n * Uses CSS custom properties and classes for framework-agnostic theming.\n *\n * Features:\n * - High contrast mode\n * - Font size scaling (small, normal, large, xlarge)\n * - Color customization (background, foreground, accent)\n * - Consistent theming across shadow DOM boundaries\n * - No framework dependencies\n *\n * Part of PIE Assessment Toolkit.\n */\n\nimport type { ThemeProviderApi } from \"./interfaces.js\";\n\n/**\n * Font size options\n */\nexport type FontSize = \"small\" | \"normal\" | \"large\" | \"xlarge\";\n\n/**\n * Theme configuration\n */\nexport interface ThemeConfig {\n\thighContrast?: boolean;\n\tfontSize?: FontSize;\n\tbackgroundColor?: string;\n\tforegroundColor?: string;\n\taccentColor?: string;\n\tlinkColor?: string;\n\terrorColor?: string;\n\tsuccessColor?: string;\n\twarningColor?: string;\n}\n\n/**\n * Font size scale (in rem units)\n */\nconst FONT_SIZE_SCALE: Record<FontSize, number> = {\n\tsmall: 0.875, // 14px at 16px base\n\tnormal: 1.0, // 16px at 16px base\n\tlarge: 1.25, // 20px at 16px base\n\txlarge: 1.5, // 24px at 16px base\n};\n\n/**\n * Default theme values\n */\nconst DEFAULT_THEME: Required<ThemeConfig> = {\n\thighContrast: false,\n\tfontSize: \"normal\",\n\tbackgroundColor: \"#ffffff\",\n\tforegroundColor: \"#000000\",\n\taccentColor: \"#3f51b5\",\n\tlinkColor: \"#146eb3\",\n\terrorColor: \"#ff9800\",\n\tsuccessColor: \"#4caf50\",\n\twarningColor: \"#d32f2f\",\n};\n\n/**\n * High contrast theme overrides\n */\nconst HIGH_CONTRAST_THEME: Partial<ThemeConfig> = {\n\tbackgroundColor: \"#000000\",\n\tforegroundColor: \"#ffffff\",\n\taccentColor: \"#ffff00\",\n\tlinkColor: \"#00ffff\",\n\terrorColor: \"#ff0000\",\n\tsuccessColor: \"#00ff00\",\n\twarningColor: \"#ffff00\",\n};\n\nexport class ThemeProvider implements ThemeProviderApi {\n\tprivate currentTheme: Required<ThemeConfig> = { ...DEFAULT_THEME };\n\tprivate styleElement: HTMLStyleElement | null = null;\n\tprivate rootElement: HTMLElement | null;\n\tprivate styleContainer: ShadowRoot | HTMLHeadElement | null = null;\n\n\tconstructor(\n\t\trootElement: HTMLElement | null = typeof document !== \"undefined\"\n\t\t\t? document.documentElement\n\t\t\t: null,\n\t) {\n\t\tthis.rootElement = rootElement;\n\n\t\t// SSR guard\n\t\tif (typeof document === \"undefined\") {\n\t\t\tconsole.warn(\"ThemeProvider: document not available (SSR context)\");\n\t\t\treturn;\n\t\t}\n\n\t\tthis.initializeStyles();\n\t}\n\n\t/**\n\t * Initialize theme styles\n\t */\n\tprivate initializeStyles(): void {\n\t\tif (!this.rootElement) return;\n\n\t\tconst rootNode = this.rootElement.getRootNode();\n\t\tif (rootNode instanceof ShadowRoot) {\n\t\t\tthis.styleContainer = rootNode;\n\t\t\tthis.styleElement = rootNode.querySelector(\n\t\t\t\t'style[data-pie-theme-styles=\"true\"]',\n\t\t\t) as HTMLStyleElement | null;\n\t\t} else {\n\t\t\tthis.styleContainer = document.head;\n\t\t\tthis.styleElement = document.getElementById(\n\t\t\t\t\"pie-theme-styles\",\n\t\t\t) as HTMLStyleElement | null;\n\t\t}\n\n\t\tif (!this.styleElement) {\n\t\t\tthis.styleElement = document.createElement(\"style\");\n\t\t\tif (this.styleContainer instanceof ShadowRoot) {\n\t\t\t\tthis.styleElement.setAttribute(\"data-pie-theme-styles\", \"true\");\n\t\t\t\tthis.styleContainer.appendChild(this.styleElement);\n\t\t\t} else {\n\t\t\t\tthis.styleElement.id = \"pie-theme-styles\";\n\t\t\t\tdocument.head.appendChild(this.styleElement);\n\t\t\t}\n\t\t}\n\n\t\t// Apply default theme\n\t\tthis.applyTheme({});\n\t}\n\n\t/**\n\t * Apply theme configuration\n\t *\n\t * @param config Partial theme configuration (merged with current theme)\n\t */\n\tapplyTheme(config: ThemeConfig): void {\n\t\tif (!this.rootElement) return;\n\n\t\t// Merge with current theme\n\t\tconst newTheme = {\n\t\t\t...this.currentTheme,\n\t\t\t...config,\n\t\t};\n\n\t\t// Apply high contrast overrides if enabled\n\t\tif (newTheme.highContrast) {\n\t\t\tObject.assign(newTheme, HIGH_CONTRAST_THEME);\n\t\t}\n\n\t\tthis.currentTheme = newTheme;\n\n\t\t// Apply CSS custom properties\n\t\tthis.applyCSSVariables();\n\n\t\t// Apply CSS classes\n\t\tthis.applyCSSClasses();\n\n\t\t// Update global styles\n\t\tthis.updateGlobalStyles();\n\t}\n\n\t/**\n\t * Apply CSS custom properties to root element\n\t */\n\tprivate applyCSSVariables(): void {\n\t\tif (!this.rootElement) return;\n\n\t\tconst {\n\t\t\tfontSize,\n\t\t\tbackgroundColor,\n\t\t\tforegroundColor,\n\t\t\taccentColor,\n\t\t\tlinkColor,\n\t\t\terrorColor,\n\t\t\tsuccessColor,\n\t\t\twarningColor,\n\t\t} = this.currentTheme;\n\n\t\t// Font sizing\n\t\tthis.rootElement.style.setProperty(\"--pie-font-scale\", String(FONT_SIZE_SCALE[fontSize]));\n\n\t\t// Canonical PIE variables\n\t\tthis.rootElement.style.setProperty(\"--pie-background\", backgroundColor);\n\t\tthis.rootElement.style.setProperty(\"--pie-text\", foregroundColor);\n\t\tthis.rootElement.style.setProperty(\"--pie-primary\", accentColor);\n\t\tthis.rootElement.style.setProperty(\"--pie-tertiary\", linkColor);\n\t\tthis.rootElement.style.setProperty(\"--pie-incorrect\", errorColor);\n\t\tthis.rootElement.style.setProperty(\"--pie-correct\", successColor);\n\t\tthis.rootElement.style.setProperty(\"--pie-missing\", warningColor);\n\n\t\t// Derived surface tokens\n\t\tthis.rootElement.style.setProperty(\"--pie-background-dark\", this.adjustOpacity(backgroundColor, 0.95));\n\t\tthis.rootElement.style.setProperty(\"--pie-secondary-background\", this.adjustOpacity(backgroundColor, 0.92));\n\t\tthis.rootElement.style.setProperty(\"--pie-border\", this.adjustOpacity(foregroundColor, 0.25));\n\t\tthis.rootElement.style.setProperty(\"--pie-border-light\", this.adjustOpacity(foregroundColor, 0.16));\n\t\tthis.rootElement.style.setProperty(\"--pie-border-dark\", this.adjustOpacity(foregroundColor, 0.4));\n\t\tthis.rootElement.style.setProperty(\"--pie-focus-checked\", this.adjustOpacity(accentColor, 0.18));\n\t\tthis.rootElement.style.setProperty(\"--pie-focus-checked-border\", accentColor);\n\n\t\t// Button tokens used by toolkit controls\n\t\tthis.rootElement.style.setProperty(\"--pie-button-bg\", backgroundColor);\n\t\tthis.rootElement.style.setProperty(\"--pie-button-border\", this.adjustOpacity(foregroundColor, 0.2));\n\t\tthis.rootElement.style.setProperty(\"--pie-button-color\", foregroundColor);\n\t\tthis.rootElement.style.setProperty(\"--pie-button-hover-bg\", this.adjustOpacity(accentColor, 0.1));\n\t\tthis.rootElement.style.setProperty(\"--pie-button-hover-border\", this.adjustOpacity(accentColor, 0.5));\n\t\tthis.rootElement.style.setProperty(\"--pie-button-hover-color\", foregroundColor);\n\t\tthis.rootElement.style.setProperty(\"--pie-button-active-bg\", this.adjustOpacity(accentColor, 0.16));\n\t\tthis.rootElement.style.setProperty(\"--pie-button-focus-outline\", accentColor);\n\t}\n\n\t/**\n\t * Apply CSS classes to root element\n\t */\n\tprivate applyCSSClasses(): void {\n\t\tif (!this.rootElement) return;\n\n\t\tconst { highContrast, fontSize } = this.currentTheme;\n\n\t\t// High contrast class\n\t\tthis.rootElement.classList.toggle(\"pie-high-contrast\", highContrast);\n\n\t\t// Font size classes\n\t\tthis.rootElement.classList.remove(\n\t\t\t\"pie-font-small\",\n\t\t\t\"pie-font-normal\",\n\t\t\t\"pie-font-large\",\n\t\t\t\"pie-font-xlarge\",\n\t\t);\n\t\tthis.rootElement.classList.add(`pie-font-${fontSize}`);\n\t}\n\n\t/**\n\t * Update global theme styles\n\t */\n\tprivate updateGlobalStyles(): void {\n\t\tif (!this.styleElement) return;\n\n\t\tthis.styleElement.textContent = `\n /* PIE Assessment Toolkit - Theme Styles */\n\n /* Font scaling */\n .pie-themed,\n .pie-themed * {\n font-size: calc(1rem * var(--pie-font-scale, 1));\n }\n\n /* Color theming */\n .pie-themed {\n background-color: var(--pie-background);\n color: var(--pie-text);\n }\n\n .pie-themed a {\n color: var(--pie-tertiary);\n }\n\n .pie-themed a:hover {\n opacity: 0.8;\n }\n\n /* High contrast mode */\n .pie-high-contrast .pie-themed {\n border: 2px solid var(--pie-text);\n }\n\n .pie-high-contrast .pie-themed a {\n text-decoration: underline;\n font-weight: bold;\n }\n\n .pie-high-contrast .pie-themed button {\n border: 2px solid var(--pie-text);\n background-color: var(--pie-background);\n color: var(--pie-text);\n }\n\n .pie-high-contrast .pie-themed button:hover {\n background-color: var(--pie-text);\n color: var(--pie-background);\n }\n\n /* Error/Success/Warning states */\n .pie-themed .pie-error {\n color: var(--pie-incorrect);\n }\n\n .pie-themed .pie-success {\n color: var(--pie-correct);\n }\n\n .pie-themed .pie-warning {\n color: var(--pie-missing);\n }\n\n /* Focus indicators (accessibility) */\n .pie-themed *:focus-visible {\n outline: 3px solid var(--pie-focus-checked-border);\n outline-offset: 2px;\n }\n\n .pie-high-contrast *:focus-visible {\n outline-width: 4px;\n }\n\n /* Responsive font scaling */\n @media (max-width: 768px) {\n .pie-themed,\n .pie-themed * {\n font-size: calc(1rem * var(--pie-font-scale, 1) * 0.9);\n }\n }\n `;\n\t}\n\n\t/**\n\t * Set high contrast mode\n\t */\n\tsetHighContrast(enabled: boolean): void {\n\t\tthis.applyTheme({ highContrast: enabled });\n\t}\n\n\t/**\n\t * Set font size\n\t */\n\tsetFontSize(size: FontSize): void {\n\t\tthis.applyTheme({ fontSize: size });\n\t}\n\n\t/**\n\t * Set color scheme\n\t */\n\tsetColors(colors: {\n\t\tbackgroundColor?: string;\n\t\tforegroundColor?: string;\n\t\taccentColor?: string;\n\t}): void {\n\t\tthis.applyTheme(colors);\n\t}\n\n\t/**\n\t * Get current theme configuration\n\t */\n\tgetCurrentTheme(): Required<ThemeConfig> {\n\t\treturn { ...this.currentTheme };\n\t}\n\n\t/**\n\t * Reset to default theme\n\t */\n\treset(): void {\n\t\tthis.currentTheme = { ...DEFAULT_THEME };\n\t\tthis.applyTheme({});\n\t}\n\n\t/**\n\t * Adjust color opacity (helper)\n\t */\n\tprivate adjustOpacity(color: string, opacity: number): string {\n\t\t// Simple hex to rgba conversion\n\t\tif (color.startsWith(\"#\")) {\n\t\t\tconst r = parseInt(color.slice(1, 3), 16);\n\t\t\tconst g = parseInt(color.slice(3, 5), 16);\n\t\t\tconst b = parseInt(color.slice(5, 7), 16);\n\t\t\treturn `rgba(${r}, ${g}, ${b}, ${opacity})`;\n\t\t}\n\n\t\t// If already rgba/rgb, just return as-is (simplified)\n\t\treturn color;\n\t}\n\n\t/**\n\t * Cleanup - remove theme styles\n\t */\n\tdestroy(): void {\n\t\tif (this.styleElement) {\n\t\t\tthis.styleElement.remove();\n\t\t\tthis.styleElement = null;\n\t\t}\n\t\tthis.styleContainer = null;\n\n\t\tif (!this.rootElement) return;\n\n\t\t// Remove CSS classes\n\t\tthis.rootElement.classList.remove(\n\t\t\t\"pie-high-contrast\",\n\t\t\t\"pie-font-small\",\n\t\t\t\"pie-font-normal\",\n\t\t\t\"pie-font-large\",\n\t\t\t\"pie-font-xlarge\",\n\t\t);\n\n\t\t// Remove CSS custom properties\n\t\tthis.rootElement.style.removeProperty(\"--pie-font-scale\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-background\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-text\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-primary\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-tertiary\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-incorrect\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-correct\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-missing\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-background-dark\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-secondary-background\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-border\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-border-light\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-border-dark\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-focus-checked\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-focus-checked-border\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-button-bg\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-button-border\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-button-color\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-button-hover-bg\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-button-hover-border\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-button-hover-color\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-button-active-bg\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-button-focus-outline\");\n\t}\n}\n"]}
1
+ {"version":3,"file":"ThemeProvider.js","sourceRoot":"","sources":["../../src/services/ThemeProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAwBH;;GAEG;AACH,MAAM,eAAe,GAA6B;IACjD,KAAK,EAAE,KAAK,EAAE,oBAAoB;IAClC,MAAM,EAAE,GAAG,EAAE,oBAAoB;IACjC,KAAK,EAAE,IAAI,EAAE,oBAAoB;IACjC,MAAM,EAAE,GA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AAqB,CAAC,CAAC;QAC7D,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,cAAc,CAAC,4BAA4B,CAAC,CAAC;QACpE,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;QACzD,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,cAAc,CAAC,qBAAqB,CAAC,CAAC;QAC7D,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC;QAC5D,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,cAAc,CAAC,uBAAuB,CAAC,CAAC;QAC/D,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,cAAc,CAAC,2BAA2B,CAAC,CAAC;QACnE,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,cAAc,CAAC,0BAA0B,CAAC,CAAC;QAClE,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,cAAc,CAAC,wBAAwB,CAAC,CAAC;QAChE,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,cAAc,CAAC,4BAA4B,CAAC,CAAC;IACrE,CAAC;CACD","sourcesContent":["/**\n * ThemeProvider\n *\n * Applies consistent accessibility theming across items and tools.\n * Uses CSS custom properties and classes for framework-agnostic theming.\n *\n * Features:\n * - High contrast mode\n * - Font size scaling (small, normal, large, xlarge)\n * - Color customization (background, foreground, accent)\n * - Consistent theming across shadow DOM boundaries\n * - No framework dependencies\n *\n * Part of PIE Assessment Toolkit.\n */\n\nimport type { ThemeProviderApi } from \"./interfaces.js\";\n\n/**\n * Font size options\n */\nexport type FontSize = \"small\" | \"normal\" | \"large\" | \"xlarge\";\n\n/**\n * Theme configuration\n */\nexport interface ThemeConfig {\n\thighContrast?: boolean;\n\tfontSize?: FontSize;\n\tbackgroundColor?: string;\n\tforegroundColor?: string;\n\taccentColor?: string;\n\tlinkColor?: string;\n\terrorColor?: string;\n\tsuccessColor?: string;\n\twarningColor?: string;\n}\n\n/**\n * Font size scale (in rem units)\n */\nconst FONT_SIZE_SCALE: Record<FontSize, number> = {\n\tsmall: 0.875, // 14px at 16px base\n\tnormal: 1.0, // 16px at 16px base\n\tlarge: 1.25, // 20px at 16px base\n\txlarge: 1.5, // 24px at 16px base\n};\n\n/**\n * Default theme values\n */\nconst DEFAULT_THEME: Required<ThemeConfig> = {\n\thighContrast: false,\n\tfontSize: \"normal\",\n\tbackgroundColor: \"#ffffff\",\n\tforegroundColor: \"#000000\",\n\taccentColor: \"#3f51b5\",\n\tlinkColor: \"#146eb3\",\n\terrorColor: \"#ff9800\",\n\tsuccessColor: \"#4caf50\",\n\twarningColor: \"#d32f2f\",\n};\n\n/**\n * High contrast theme overrides\n */\nconst HIGH_CONTRAST_THEME: Partial<ThemeConfig> = {\n\tbackgroundColor: \"#000000\",\n\tforegroundColor: \"#ffffff\",\n\taccentColor: \"#ffff00\",\n\tlinkColor: \"#00ffff\",\n\terrorColor: \"#ff0000\",\n\tsuccessColor: \"#00ff00\",\n\twarningColor: \"#ffff00\",\n};\n\nexport class ThemeProvider implements ThemeProviderApi {\n\tprivate currentTheme: Required<ThemeConfig> = { ...DEFAULT_THEME };\n\tprivate styleElement: HTMLStyleElement | null = null;\n\tprivate rootElement: HTMLElement | null;\n\tprivate styleContainer: ShadowRoot | HTMLHeadElement | null = null;\n\n\tconstructor(\n\t\trootElement: HTMLElement | null = typeof document !== \"undefined\"\n\t\t\t? document.documentElement\n\t\t\t: null,\n\t) {\n\t\tthis.rootElement = rootElement;\n\n\t\t// SSR guard\n\t\tif (typeof document === \"undefined\") {\n\t\t\tconsole.warn(\"ThemeProvider: document not available (SSR context)\");\n\t\t\treturn;\n\t\t}\n\n\t\tthis.initializeStyles();\n\t}\n\n\t/**\n\t * Initialize theme styles\n\t */\n\tprivate initializeStyles(): void {\n\t\tif (!this.rootElement) return;\n\n\t\tconst rootNode = this.rootElement.getRootNode();\n\t\tif (rootNode instanceof ShadowRoot) {\n\t\t\tthis.styleContainer = rootNode;\n\t\t\tthis.styleElement = rootNode.querySelector(\n\t\t\t\t'style[data-pie-theme-styles=\"true\"]',\n\t\t\t) as HTMLStyleElement | null;\n\t\t} else {\n\t\t\tthis.styleContainer = document.head;\n\t\t\tthis.styleElement = document.getElementById(\n\t\t\t\t\"pie-theme-styles\",\n\t\t\t) as HTMLStyleElement | null;\n\t\t}\n\n\t\tif (!this.styleElement) {\n\t\t\tthis.styleElement = document.createElement(\"style\");\n\t\t\tif (this.styleContainer instanceof ShadowRoot) {\n\t\t\t\tthis.styleElement.setAttribute(\"data-pie-theme-styles\", \"true\");\n\t\t\t\tthis.styleContainer.appendChild(this.styleElement);\n\t\t\t} else {\n\t\t\t\tthis.styleElement.id = \"pie-theme-styles\";\n\t\t\t\tdocument.head.appendChild(this.styleElement);\n\t\t\t}\n\t\t}\n\n\t\t// Apply default theme\n\t\tthis.applyTheme({});\n\t}\n\n\t/**\n\t * Apply theme configuration\n\t *\n\t * @param config Partial theme configuration (merged with current theme)\n\t */\n\tapplyTheme(config: ThemeConfig): void {\n\t\tif (!this.rootElement) return;\n\n\t\t// Merge with current theme\n\t\tconst newTheme = {\n\t\t\t...this.currentTheme,\n\t\t\t...config,\n\t\t};\n\n\t\t// Apply high contrast overrides if enabled\n\t\tif (newTheme.highContrast) {\n\t\t\tObject.assign(newTheme, HIGH_CONTRAST_THEME);\n\t\t}\n\n\t\tthis.currentTheme = newTheme;\n\n\t\t// Apply CSS custom properties\n\t\tthis.applyCSSVariables();\n\n\t\t// Apply CSS classes\n\t\tthis.applyCSSClasses();\n\n\t\t// Update global styles\n\t\tthis.updateGlobalStyles();\n\t}\n\n\t/**\n\t * Apply CSS custom properties to root element\n\t */\n\tprivate applyCSSVariables(): void {\n\t\tif (!this.rootElement) return;\n\n\t\tconst {\n\t\t\tfontSize,\n\t\t\tbackgroundColor,\n\t\t\tforegroundColor,\n\t\t\taccentColor,\n\t\t\tlinkColor,\n\t\t\terrorColor,\n\t\t\tsuccessColor,\n\t\t\twarningColor,\n\t\t} = this.currentTheme;\n\n\t\t// Font sizing\n\t\tthis.rootElement.style.setProperty(\n\t\t\t\"--pie-font-scale\",\n\t\t\tString(FONT_SIZE_SCALE[fontSize]),\n\t\t);\n\n\t\t// Canonical PIE variables\n\t\tthis.rootElement.style.setProperty(\"--pie-background\", backgroundColor);\n\t\tthis.rootElement.style.setProperty(\"--pie-text\", foregroundColor);\n\t\tthis.rootElement.style.setProperty(\"--pie-primary\", accentColor);\n\t\tthis.rootElement.style.setProperty(\"--pie-tertiary\", linkColor);\n\t\tthis.rootElement.style.setProperty(\"--pie-incorrect\", errorColor);\n\t\tthis.rootElement.style.setProperty(\"--pie-correct\", successColor);\n\t\tthis.rootElement.style.setProperty(\"--pie-missing\", warningColor);\n\n\t\t// Derived surface tokens\n\t\tthis.rootElement.style.setProperty(\n\t\t\t\"--pie-background-dark\",\n\t\t\tthis.adjustOpacity(backgroundColor, 0.95),\n\t\t);\n\t\tthis.rootElement.style.setProperty(\n\t\t\t\"--pie-secondary-background\",\n\t\t\tthis.adjustOpacity(backgroundColor, 0.92),\n\t\t);\n\t\tthis.rootElement.style.setProperty(\n\t\t\t\"--pie-border\",\n\t\t\tthis.adjustOpacity(foregroundColor, 0.25),\n\t\t);\n\t\tthis.rootElement.style.setProperty(\n\t\t\t\"--pie-border-light\",\n\t\t\tthis.adjustOpacity(foregroundColor, 0.16),\n\t\t);\n\t\tthis.rootElement.style.setProperty(\n\t\t\t\"--pie-border-dark\",\n\t\t\tthis.adjustOpacity(foregroundColor, 0.4),\n\t\t);\n\t\tthis.rootElement.style.setProperty(\n\t\t\t\"--pie-focus-checked\",\n\t\t\tthis.adjustOpacity(accentColor, 0.18),\n\t\t);\n\t\tthis.rootElement.style.setProperty(\n\t\t\t\"--pie-focus-checked-border\",\n\t\t\taccentColor,\n\t\t);\n\n\t\t// Button tokens used by toolkit controls\n\t\tthis.rootElement.style.setProperty(\"--pie-button-bg\", backgroundColor);\n\t\tthis.rootElement.style.setProperty(\n\t\t\t\"--pie-button-border\",\n\t\t\tthis.adjustOpacity(foregroundColor, 0.2),\n\t\t);\n\t\tthis.rootElement.style.setProperty(\"--pie-button-color\", foregroundColor);\n\t\tthis.rootElement.style.setProperty(\n\t\t\t\"--pie-button-hover-bg\",\n\t\t\tthis.adjustOpacity(accentColor, 0.1),\n\t\t);\n\t\tthis.rootElement.style.setProperty(\n\t\t\t\"--pie-button-hover-border\",\n\t\t\tthis.adjustOpacity(accentColor, 0.5),\n\t\t);\n\t\tthis.rootElement.style.setProperty(\n\t\t\t\"--pie-button-hover-color\",\n\t\t\tforegroundColor,\n\t\t);\n\t\tthis.rootElement.style.setProperty(\n\t\t\t\"--pie-button-active-bg\",\n\t\t\tthis.adjustOpacity(accentColor, 0.16),\n\t\t);\n\t\tthis.rootElement.style.setProperty(\n\t\t\t\"--pie-button-focus-outline\",\n\t\t\taccentColor,\n\t\t);\n\t}\n\n\t/**\n\t * Apply CSS classes to root element\n\t */\n\tprivate applyCSSClasses(): void {\n\t\tif (!this.rootElement) return;\n\n\t\tconst { highContrast, fontSize } = this.currentTheme;\n\n\t\t// High contrast class\n\t\tthis.rootElement.classList.toggle(\"pie-high-contrast\", highContrast);\n\n\t\t// Font size classes\n\t\tthis.rootElement.classList.remove(\n\t\t\t\"pie-font-small\",\n\t\t\t\"pie-font-normal\",\n\t\t\t\"pie-font-large\",\n\t\t\t\"pie-font-xlarge\",\n\t\t);\n\t\tthis.rootElement.classList.add(`pie-font-${fontSize}`);\n\t}\n\n\t/**\n\t * Update global theme styles\n\t */\n\tprivate updateGlobalStyles(): void {\n\t\tif (!this.styleElement) return;\n\n\t\tthis.styleElement.textContent = `\n /* PIE Assessment Toolkit - Theme Styles */\n\n /* Font scaling */\n .pie-themed,\n .pie-themed * {\n font-size: calc(1rem * var(--pie-font-scale, 1));\n }\n\n /* Color theming */\n .pie-themed {\n background-color: var(--pie-background);\n color: var(--pie-text);\n }\n\n .pie-themed a {\n color: var(--pie-tertiary);\n }\n\n .pie-themed a:hover {\n opacity: 0.8;\n }\n\n /* High contrast mode */\n .pie-high-contrast .pie-themed {\n border: 2px solid var(--pie-text);\n }\n\n .pie-high-contrast .pie-themed a {\n text-decoration: underline;\n font-weight: bold;\n }\n\n .pie-high-contrast .pie-themed button {\n border: 2px solid var(--pie-text);\n background-color: var(--pie-background);\n color: var(--pie-text);\n }\n\n .pie-high-contrast .pie-themed button:hover {\n background-color: var(--pie-text);\n color: var(--pie-background);\n }\n\n /* Error/Success/Warning states */\n .pie-themed .pie-error {\n color: var(--pie-incorrect);\n }\n\n .pie-themed .pie-success {\n color: var(--pie-correct);\n }\n\n .pie-themed .pie-warning {\n color: var(--pie-missing);\n }\n\n /* Focus indicators (accessibility) */\n .pie-themed *:focus-visible {\n outline: 3px solid var(--pie-focus-checked-border);\n outline-offset: 2px;\n }\n\n .pie-high-contrast *:focus-visible {\n outline-width: 4px;\n }\n\n /* Responsive font scaling */\n @media (max-width: 768px) {\n .pie-themed,\n .pie-themed * {\n font-size: calc(1rem * var(--pie-font-scale, 1) * 0.9);\n }\n }\n `;\n\t}\n\n\t/**\n\t * Set high contrast mode\n\t */\n\tsetHighContrast(enabled: boolean): void {\n\t\tthis.applyTheme({ highContrast: enabled });\n\t}\n\n\t/**\n\t * Set font size\n\t */\n\tsetFontSize(size: FontSize): void {\n\t\tthis.applyTheme({ fontSize: size });\n\t}\n\n\t/**\n\t * Set color scheme\n\t */\n\tsetColors(colors: {\n\t\tbackgroundColor?: string;\n\t\tforegroundColor?: string;\n\t\taccentColor?: string;\n\t}): void {\n\t\tthis.applyTheme(colors);\n\t}\n\n\t/**\n\t * Get current theme configuration\n\t */\n\tgetCurrentTheme(): Required<ThemeConfig> {\n\t\treturn { ...this.currentTheme };\n\t}\n\n\t/**\n\t * Reset to default theme\n\t */\n\treset(): void {\n\t\tthis.currentTheme = { ...DEFAULT_THEME };\n\t\tthis.applyTheme({});\n\t}\n\n\t/**\n\t * Adjust color opacity (helper)\n\t */\n\tprivate adjustOpacity(color: string, opacity: number): string {\n\t\t// Simple hex to rgba conversion\n\t\tif (color.startsWith(\"#\")) {\n\t\t\tconst r = parseInt(color.slice(1, 3), 16);\n\t\t\tconst g = parseInt(color.slice(3, 5), 16);\n\t\t\tconst b = parseInt(color.slice(5, 7), 16);\n\t\t\treturn `rgba(${r}, ${g}, ${b}, ${opacity})`;\n\t\t}\n\n\t\t// If already rgba/rgb, just return as-is (simplified)\n\t\treturn color;\n\t}\n\n\t/**\n\t * Cleanup - remove theme styles\n\t */\n\tdestroy(): void {\n\t\tif (this.styleElement) {\n\t\t\tthis.styleElement.remove();\n\t\t\tthis.styleElement = null;\n\t\t}\n\t\tthis.styleContainer = null;\n\n\t\tif (!this.rootElement) return;\n\n\t\t// Remove CSS classes\n\t\tthis.rootElement.classList.remove(\n\t\t\t\"pie-high-contrast\",\n\t\t\t\"pie-font-small\",\n\t\t\t\"pie-font-normal\",\n\t\t\t\"pie-font-large\",\n\t\t\t\"pie-font-xlarge\",\n\t\t);\n\n\t\t// Remove CSS custom properties\n\t\tthis.rootElement.style.removeProperty(\"--pie-font-scale\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-background\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-text\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-primary\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-tertiary\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-incorrect\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-correct\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-missing\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-background-dark\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-secondary-background\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-border\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-border-light\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-border-dark\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-focus-checked\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-focus-checked-border\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-button-bg\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-button-border\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-button-color\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-button-hover-bg\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-button-hover-border\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-button-hover-color\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-button-active-bg\");\n\t\tthis.rootElement.style.removeProperty(\"--pie-button-focus-outline\");\n\t}\n}\n"]}
@@ -91,7 +91,7 @@ export interface ToolWindowShellAction {
91
91
  * Alignment corner for the initial shell position.
92
92
  * The shell is offset by `initialMargin` (default 16 px) from the chosen corner.
93
93
  */
94
- export type ToolWindowShellAlign = 'center' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
94
+ export type ToolWindowShellAlign = "center" | "top-left" | "top-right" | "bottom-left" | "bottom-right";
95
95
  export interface ToolWindowShellConfig {
96
96
  title?: string;
97
97
  draggable?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"ToolRegistry.js","sourceRoot":"","sources":["../../src/services/ToolRegistry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AA2OlE,MAAM,iBAAiB,GAAgB;IACtC,YAAY;IACZ,SAAS;IACT,MAAM;IACN,SAAS;IACT,QAAQ;IACR,SAAS;CACT,CAAC;AAEF,SAAS,oBAAoB,CAC5B,KAAc,EACd,SAAiB;IAEjB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5D,MAAM,IAAI,KAAK,CACd,+BAA+B,SAAS,+BAA+B,CACvE,CAAC;IACH,CAAC;AACF,CAAC;AAED,wEAAwE;AACxE,sEAAsE;AACtE,uEAAuE;AACvE,0EAA0E;AAC1E,mCAA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IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,gBAAgB,CACf,MAAc,EACd,OAAoB,EACpB,cAA8B;QAE9B,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC9B,IAAI,CAAC,IAAI,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,SAAS,MAAM,qBAAqB,CAAC,CAAC;QACvD,CAAC;QAED,MAAM,aAAa,GAAmB;YACrC,GAAG,cAAc;YACjB,kBAAkB,EAAE;gBACnB,GAAG,CAAC,IAAI,CAAC,kBAAkB,IAAI,EAAE,CAAC;gBAClC,GAAG,CAAC,cAAc,CAAC,kBAAkB,IAAI,EAAE,CAAC;aAC5C;SACD,CAAC;QAEF,OAAO,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IACnD,CAAC;CACD","sourcesContent":["/**\n * Tool Registry\n *\n * Central registry for all assessment tools. Manages tool metadata, visibility logic,\n * and button/instance creation. Supports dynamic registration and override by integrators.\n */\n\nimport type { ToolContext, ToolLevel } from \"./tool-context.js\";\nimport type { ToolComponentOverrides } from \"../tools/tool-tag-map.js\";\nimport type {\n\tElementToolStateStoreApi,\n\tToolCoordinatorApi,\n\tToolkitCoordinatorApi,\n\tTtsServiceApi,\n} from \"./interfaces.js\";\nimport type { ToolProviderApi } from \"./tool-providers/ToolProviderApi.js\";\nimport type { ToolProviderConfig as ToolRuntimeConfig } from \"./tools-config-normalizer.js\";\nimport type { ToolConfigDiagnostic } from \"./tool-config-validation.js\";\nimport { normalizeToolAlias } from \"./tools-config-normalizer.js\";\n\nexport type ToolModuleLoader = () => Promise<unknown>;\n\nexport interface ToolToolbarButtonDefinition {\n\ttoolId: string;\n\tlabel: string;\n\ticon: string;\n\tariaLabel: string;\n\ttooltip?: string;\n\tonClick: () => void;\n\tclassName?: string;\n\tdisabled?: boolean;\n\tactive?: boolean;\n}\n\nexport interface ToolbarContext {\n\tscope: {\n\t\tlevel: ToolLevel;\n\t\tscopeId: string;\n\t\tassessmentId?: string;\n\t\tsectionId?: string;\n\t\titemId?: string;\n\t\tcanonicalItemId?: string;\n\t\tcontentKind?: string;\n\t};\n\titemId: string;\n\tcatalogId: string;\n\tlanguage: string;\n\tui?: {\n\t\tsize?: string;\n\t};\n\tgetScopeElement?: () => HTMLElement | null;\n\tgetGlobalElementId?: () => string | null;\n\ttoolCoordinator: ToolCoordinatorApi | null;\n\ttoolkitCoordinator: ToolkitCoordinatorApi | null;\n\tttsService: TtsServiceApi | null;\n\telementToolStateStore: ElementToolStateStoreApi | null;\n\ttoggleTool: (toolId: string) => void;\n\tisToolVisible: (toolId: string) => boolean;\n\tsubscribeVisibility: ((listener: () => void) => () => void) | null;\n\tcomponentOverrides?: ToolComponentOverrides;\n\tgetResolvedToolContext?: (toolId: string) => ResolvedToolContext | null;\n\tgetToolRenderParams?: (toolId: string) => Record<string, unknown> | null;\n}\n\nexport interface ToolContextResolverContext {\n\ttoolId: string;\n\tcontext: ToolContext;\n\ttoolbarContext: ToolbarContext;\n}\n\nexport interface ToolContextResolverResult {\n\tvisible?: boolean;\n\tparams?: Record<string, unknown>;\n\treason?: string;\n}\n\nexport type ToolContextResolver = (\n\tcontext: ToolContextResolverContext,\n) => ToolContextResolverResult | null | undefined;\n\nexport type ToolContextResolverMap = Record<\n\tstring,\n\tToolContextResolver | null | undefined\n>;\n\nexport interface ResolvedToolContext {\n\ttoolId: string;\n\tvisible: boolean;\n\tparams: Record<string, unknown>;\n\treason?: string;\n}\n\nexport interface ToolRenderElement {\n\telement: HTMLElement | null;\n\tmount: \"before-buttons\" | \"after-buttons\" | \"controls-row\";\n\tlayoutHints?: {\n\t\tcontrolsRow?: {\n\t\t\treserveSpace?: boolean;\n\t\t\tshowWhenToolActive?: boolean;\n\t\t};\n\t};\n\tshell?: ToolWindowShellConfig;\n}\n\nexport interface ToolWindowShellAction {\n\tid: string;\n\tlabel: string;\n\tariaLabel?: string;\n\ticonSvg?: string;\n\tonClick: () => void;\n}\n\n/**\n * Alignment corner for the initial shell position.\n * The shell is offset by `initialMargin` (default 16 px) from the chosen corner.\n */\nexport type ToolWindowShellAlign =\n\t| 'center'\n\t| 'top-left'\n\t| 'top-right'\n\t| 'bottom-left'\n\t| 'bottom-right';\n\nexport interface ToolWindowShellConfig {\n\ttitle?: string;\n\tdraggable?: boolean;\n\tresizable?: boolean;\n\tcloseable?: boolean;\n\tinitialWidth?: number;\n\tinitialHeight?: number;\n\tminWidth?: number;\n\tminHeight?: number;\n\tmaxWidth?: number;\n\tmaxHeight?: number;\n\t/** Initial placement of the shell. Defaults to `'center'`. */\n\tinitialAlign?: ToolWindowShellAlign;\n\t/** Distance (px) from the viewport edge when using a corner align. Defaults to 16. */\n\tinitialMargin?: number;\n\tactions?: ToolWindowShellAction[];\n}\n\nexport interface HostedToolContext {\n\ttoolId: string;\n\ttoolbarContext: ToolbarContext;\n\tshellConfig: ToolWindowShellConfig;\n}\n\nexport interface HostedToolSize {\n\twidth: number;\n\theight: number;\n}\n\nexport interface ToolProviderDescriptor {\n\tgetProviderId?: (config: ToolRuntimeConfig | undefined) => string;\n\tcreateProvider: (config: ToolRuntimeConfig | undefined) => ToolProviderApi;\n\tgetInitConfig?: (\n\t\tconfig: ToolRuntimeConfig | undefined,\n\t) => Record<string, unknown>;\n\tsanitizeConfig?: (config: ToolRuntimeConfig) => ToolRuntimeConfig;\n\tvalidateConfig?: (config: ToolRuntimeConfig) => ToolConfigDiagnostic[];\n\tgetAuthFetcher?: (\n\t\tconfig: ToolRuntimeConfig | undefined,\n\t) => (() => Promise<Record<string, unknown>>) | undefined;\n\tlazy?: boolean;\n}\n\nexport interface ToolToolbarRenderResult {\n\ttoolId: string;\n\telements?: ToolRenderElement[];\n\tbutton?: ToolToolbarButtonDefinition | null;\n\tsync?: () => void;\n\tsubscribeActive?: (callback: (active: boolean) => void) => () => void;\n}\n\nexport type ToolActivation = \"toolbar-toggle\" | \"selection-gateway\";\nexport type ToolSingletonScope = \"section\";\n\n/**\n * Tool registration interface\n */\nexport interface ToolRegistration {\n\t/** Unique tool identifier (e.g., 'calculator', 'textToSpeech') */\n\ttoolId: string;\n\n\t/** Human-readable name */\n\tname: string;\n\n\t/** Description of what the tool does */\n\tdescription: string;\n\n\t/** Icon identifier or SVG string */\n\ticon: string | ((context: ToolContext) => string);\n\n\t/** Which levels this tool supports */\n\tsupportedLevels: ToolLevel[];\n\n\t/**\n\t * Activation model for this tool.\n\t * - toolbar-toggle: rendered as a toolbar button (default)\n\t * - selection-gateway: rendered as a singleton selection-driven gateway\n\t */\n\tactivation?: ToolActivation;\n\n\t/**\n\t * Optional singleton scope for activation models that mount exactly one instance.\n\t */\n\tsingletonScope?: ToolSingletonScope;\n\n\t/**\n\t * PNP support IDs that enable this tool (optional)\n\t * Used by the tool policy engine to determine if a PNP support enables this tool.\n\t * Example: ['calculator', 'basic-calculator', 'scientific-calculator']\n\t */\n\tpnpSupportIds?: string[];\n\t/**\n\t * Optional provider registration metadata.\n\t * When present, ToolkitCoordinator can register provider(s) generically\n\t * without hardcoded tool-specific branches.\n\t */\n\tprovider?: ToolProviderDescriptor;\n\t/**\n\t * Optional shell-host lifecycle hooks for hosted (floating) tools.\n\t */\n\tonHostedMount?: (\n\t\telement: HTMLElement,\n\t\tcontext: HostedToolContext,\n\t) => void | Promise<void>;\n\tonHostedResize?: (\n\t\tsize: HostedToolSize,\n\t\telement: HTMLElement,\n\t\tcontext: HostedToolContext,\n\t) => void | Promise<void>;\n\tonHostedUnmount?: (\n\t\telement: HTMLElement,\n\t\tcontext: HostedToolContext,\n\t) => void | Promise<void>;\n\n\t/**\n\t * Pass 2: Tool decides if it's relevant in this context\n\t * Called ONLY if orchestrator has already allowed the tool (Pass 1)\n\t *\n\t * @param context - Rich context about where tool is being evaluated\n\t * @returns true if tool should be visible, false to hide\n\t */\n\tisVisibleInContext(context: ToolContext): boolean;\n\n\t/** Required toolbar-first render contract. */\n\trenderToolbar(\n\t\tcontext: ToolContext,\n\t\ttoolbarContext: ToolbarContext,\n\t): ToolToolbarRenderResult | null;\n}\n\nconst VALID_TOOL_LEVELS: ToolLevel[] = [\n\t\"assessment\",\n\t\"section\",\n\t\"item\",\n\t\"passage\",\n\t\"rubric\",\n\t\"element\",\n];\n\nfunction assertNonEmptyString(\n\tvalue: unknown,\n\tfieldName: string,\n): asserts value is string {\n\tif (typeof value !== \"string\" || value.trim().length === 0) {\n\t\tthrow new Error(\n\t\t\t`Invalid tool registration: \"${fieldName}\" must be a non-empty string.`,\n\t\t);\n\t}\n}\n\n// Defence-in-depth: reject obvious XSS payloads in tool-registered icon\n// markup at registration time. Runtime rendering still runs each icon\n// through DOMPurify (see `ToolIcon.svelte`), but surfacing the problem\n// early produces a clearer error for tool authors than \"the icon silently\n// disappeared after sanitization\".\nconst SCRIPTABLE_ICON_PATTERNS: Array<{ pattern: RegExp; reason: string }> = [\n\t{ pattern: /<script\\b/i, reason: \"contains a <script> tag\" },\n\t{\n\t\tpattern: /\\son[a-z]+\\s*=/i,\n\t\treason: \"contains an inline event handler (on*=) attribute\",\n\t},\n\t{ pattern: /javascript:/i, reason: \"contains a javascript: URL\" },\n\t{\n\t\tpattern: /<foreignObject\\b/i,\n\t\treason: \"contains a <foreignObject> element\",\n\t},\n];\n\nfunction assertIconStringIsSafe(\n\ttoolId: string,\n\ticon: string,\n\tfieldName: string,\n): void {\n\tconst trimmed = icon.trimStart();\n\tconst looksLikeSvg = trimmed.toLowerCase().startsWith(\"<svg\");\n\tconst looksLikeUrl = /^https?:/i.test(trimmed);\n\tconst looksLikeDataUrl = /^data:/i.test(trimmed);\n\tif (looksLikeDataUrl) {\n\t\tthrow new Error(\n\t\t\t`Invalid tool registration \"${toolId}\": \"${fieldName}\" may not be a data: URL.`,\n\t\t);\n\t}\n\tif (!looksLikeSvg && !looksLikeUrl) return;\n\tfor (const { pattern, reason } of SCRIPTABLE_ICON_PATTERNS) {\n\t\tif (pattern.test(icon)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid tool registration \"${toolId}\": \"${fieldName}\" ${reason}. Inline SVG icons must not include scriptable content.`,\n\t\t\t);\n\t\t}\n\t}\n}\n\nfunction assertToolRegistrationShape(registration: ToolRegistration): void {\n\tassertNonEmptyString(registration.toolId, \"toolId\");\n\tassertNonEmptyString(registration.name, \"name\");\n\tassertNonEmptyString(registration.description, \"description\");\n\n\tif (\n\t\ttypeof registration.icon !== \"string\" &&\n\t\ttypeof registration.icon !== \"function\"\n\t) {\n\t\tthrow new Error(\n\t\t\t`Invalid tool registration \"${registration.toolId}\": \"icon\" must be a string or function.`,\n\t\t);\n\t}\n\tif (typeof registration.icon === \"string\") {\n\t\tassertIconStringIsSafe(registration.toolId, registration.icon, \"icon\");\n\t}\n\tif (\n\t\t!Array.isArray(registration.supportedLevels) ||\n\t\tregistration.supportedLevels.length === 0\n\t) {\n\t\tthrow new Error(\n\t\t\t`Invalid tool registration \"${registration.toolId}\": \"supportedLevels\" must be a non-empty array.`,\n\t\t);\n\t}\n\tconst invalidLevel = registration.supportedLevels.find(\n\t\t(level) => !VALID_TOOL_LEVELS.includes(level),\n\t);\n\tif (invalidLevel) {\n\t\tthrow new Error(\n\t\t\t`Invalid tool registration \"${registration.toolId}\": unsupported level \"${invalidLevel}\".`,\n\t\t);\n\t}\n\tif (\n\t\tregistration.activation !== undefined &&\n\t\tregistration.activation !== \"toolbar-toggle\" &&\n\t\tregistration.activation !== \"selection-gateway\"\n\t) {\n\t\tthrow new Error(\n\t\t\t`Invalid tool registration \"${registration.toolId}\": unsupported activation \"${String(registration.activation)}\".`,\n\t\t);\n\t}\n\tif (\n\t\tregistration.singletonScope !== undefined &&\n\t\tregistration.singletonScope !== \"section\"\n\t) {\n\t\tthrow new Error(\n\t\t\t`Invalid tool registration \"${registration.toolId}\": unsupported singletonScope \"${String(registration.singletonScope)}\".`,\n\t\t);\n\t}\n\tif (\n\t\tregistration.activation === \"selection-gateway\" &&\n\t\tregistration.singletonScope !== \"section\"\n\t) {\n\t\tthrow new Error(\n\t\t\t`Invalid tool registration \"${registration.toolId}\": selection-gateway tools must declare singletonScope \"section\".`,\n\t\t);\n\t}\n\tif (\n\t\tregistration.pnpSupportIds !== undefined &&\n\t\t(!Array.isArray(registration.pnpSupportIds) ||\n\t\t\tregistration.pnpSupportIds.some(\n\t\t\t\t(pnpId) => typeof pnpId !== \"string\" || pnpId.trim().length === 0,\n\t\t\t))\n\t) {\n\t\tthrow new Error(\n\t\t\t`Invalid tool registration \"${registration.toolId}\": \"pnpSupportIds\" must be an array of non-empty strings.`,\n\t\t);\n\t}\n\tif (typeof registration.isVisibleInContext !== \"function\") {\n\t\tthrow new Error(\n\t\t\t`Invalid tool registration \"${registration.toolId}\": \"isVisibleInContext\" must be a function.`,\n\t\t);\n\t}\n\tif (typeof registration.renderToolbar !== \"function\") {\n\t\tthrow new Error(\n\t\t\t`Invalid tool registration \"${registration.toolId}\": \"renderToolbar\" must be a function.`,\n\t\t);\n\t}\n}\n\n/**\n * Tool Registry\n *\n * Manages tool registrations and provides query/lookup functionality\n */\nexport class ToolRegistry {\n\tprivate tools = new Map<string, ToolRegistration>();\n\tprivate pnpIndex = new Map<string, Set<string>>(); // pnpSupportId → Set<toolId>\n\tprivate componentOverrides: ToolComponentOverrides = {};\n\tprivate moduleLoaders = new Map<string, ToolModuleLoader>();\n\tprivate loadedToolModules = new Set<string>();\n\tprivate moduleLoadPromises = new Map<string, Promise<void>>();\n\n\t/**\n\t * Normalize a single tool alias to canonical toolId.\n\t */\n\tnormalizeToolId(toolId: string): string {\n\t\treturn normalizeToolAlias(toolId);\n\t}\n\n\t/**\n\t * Normalize a list of tool aliases to canonical toolIds.\n\t */\n\tnormalizeToolIds(toolIds: string[]): string[] {\n\t\treturn toolIds.map((toolId) => this.normalizeToolId(toolId));\n\t}\n\n\t/**\n\t * Register a tool\n\t *\n\t * @param registration - Tool registration\n\t * @throws Error if toolId is already registered\n\t */\n\tregister(registration: ToolRegistration): void {\n\t\tassertToolRegistrationShape(registration);\n\t\tif (this.tools.has(registration.toolId)) {\n\t\t\tthrow new Error(`Tool '${registration.toolId}' is already registered`);\n\t\t}\n\n\t\tthis.tools.set(registration.toolId, registration);\n\n\t\t// Index PNP support IDs\n\t\tif (registration.pnpSupportIds) {\n\t\t\tfor (const pnpId of registration.pnpSupportIds) {\n\t\t\t\tif (!this.pnpIndex.has(pnpId)) {\n\t\t\t\t\tthis.pnpIndex.set(pnpId, new Set());\n\t\t\t\t}\n\t\t\t\tthis.pnpIndex.get(pnpId)!.add(registration.toolId);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Override an existing tool registration\n\t *\n\t * @param registration - New tool registration (must have existing toolId)\n\t */\n\toverride(registration: ToolRegistration): void {\n\t\tassertToolRegistrationShape(registration);\n\t\tif (!this.tools.has(registration.toolId)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot override non-existent tool '${registration.toolId}'`,\n\t\t\t);\n\t\t}\n\n\t\t// Remove old PNP index entries\n\t\tconst oldReg = this.tools.get(registration.toolId)!;\n\t\tif (oldReg.pnpSupportIds) {\n\t\t\tfor (const pnpId of oldReg.pnpSupportIds) {\n\t\t\t\tthis.pnpIndex.get(pnpId)?.delete(registration.toolId);\n\t\t\t}\n\t\t}\n\n\t\t// Add new registration\n\t\tthis.tools.set(registration.toolId, registration);\n\n\t\t// Re-index PNP support IDs\n\t\tif (registration.pnpSupportIds) {\n\t\t\tfor (const pnpId of registration.pnpSupportIds) {\n\t\t\t\tif (!this.pnpIndex.has(pnpId)) {\n\t\t\t\t\tthis.pnpIndex.set(pnpId, new Set());\n\t\t\t\t}\n\t\t\t\tthis.pnpIndex.get(pnpId)!.add(registration.toolId);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Unregister a tool\n\t *\n\t * @param toolId - Tool ID to remove\n\t */\n\tunregister(toolId: string): void {\n\t\tconst reg = this.tools.get(toolId);\n\t\tif (!reg) return;\n\n\t\t// Remove PNP index entries\n\t\tif (reg.pnpSupportIds) {\n\t\t\tfor (const pnpId of reg.pnpSupportIds) {\n\t\t\t\tthis.pnpIndex.get(pnpId)?.delete(toolId);\n\t\t\t}\n\t\t}\n\n\t\tthis.tools.delete(toolId);\n\t}\n\n\t/**\n\t * Get a tool registration by ID\n\t *\n\t * @param toolId - Tool ID\n\t * @returns Tool registration or undefined\n\t */\n\tget(toolId: string): ToolRegistration | undefined {\n\t\treturn this.tools.get(toolId);\n\t}\n\n\t/**\n\t * Check if a tool is registered\n\t *\n\t * @param toolId - Tool ID\n\t * @returns true if registered\n\t */\n\thas(toolId: string): boolean {\n\t\treturn this.tools.has(toolId);\n\t}\n\n\t/**\n\t * Get all registered tool IDs\n\t *\n\t * @returns Array of tool IDs\n\t */\n\tgetAllToolIds(): string[] {\n\t\treturn Array.from(this.tools.keys());\n\t}\n\n\t/**\n\t * Get all tool registrations\n\t *\n\t * @returns Array of tool registrations\n\t */\n\tgetAllTools(): ToolRegistration[] {\n\t\treturn Array.from(this.tools.values());\n\t}\n\n\t/**\n\t * Find tool IDs that support a given PNP support ID\n\t *\n\t * @param pnpSupportId - PNP support ID (e.g., 'calculator')\n\t * @returns Set of tool IDs that support this PNP ID\n\t */\n\tgetToolsByPNPSupport(pnpSupportId: string): Set<string> {\n\t\treturn this.pnpIndex.get(pnpSupportId) || new Set();\n\t}\n\n\t/**\n\t * Get tools that support a specific level\n\t *\n\t * @param level - Tool level (assessment, section, item, passage, element)\n\t * @returns Array of tool registrations that support this level\n\t */\n\tgetToolsByLevel(level: ToolLevel): ToolRegistration[] {\n\t\treturn this.getAllTools().filter((tool) =>\n\t\t\ttool.supportedLevels.includes(level),\n\t\t);\n\t}\n\n\t/**\n\t * Resolve tool activation, defaulting to toolbar-toggle.\n\t */\n\tgetToolActivation(toolId: string): ToolActivation {\n\t\treturn this.get(toolId)?.activation || \"toolbar-toggle\";\n\t}\n\n\t/**\n\t * Resolve singleton scope for a tool when present.\n\t */\n\tgetToolSingletonScope(toolId: string): ToolSingletonScope | null {\n\t\treturn this.get(toolId)?.singletonScope || null;\n\t}\n\n\t/**\n\t * Filter tool IDs by activation type.\n\t */\n\tfilterToolIdsByActivation(\n\t\ttoolIds: string[],\n\t\tactivation: ToolActivation,\n\t): string[] {\n\t\treturn toolIds.filter(\n\t\t\t(toolId) => this.getToolActivation(toolId) === activation,\n\t\t);\n\t}\n\n\t/**\n\t * Filter tools by visibility in a given context\n\t *\n\t * Pass 2 of the two-pass model: Given a list of allowed tool IDs (from Pass 1),\n\t * ask each tool if it's relevant in this context.\n\t *\n\t * @param allowedToolIds - Tool IDs that passed Pass 1 (orchestrator approval)\n\t * @param context - Context to evaluate\n\t * @returns Array of visible tool registrations\n\t */\n\tfilterVisibleInContext(\n\t\tallowedToolIds: string[],\n\t\tcontext: ToolContext,\n\t): ToolRegistration[] {\n\t\tconst visible: ToolRegistration[] = [];\n\n\t\tfor (const toolId of allowedToolIds) {\n\t\t\tconst tool = this.get(toolId);\n\t\t\tif (!tool) {\n\t\t\t\tconsole.warn(`Tool '${toolId}' is allowed but not registered`);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Check if tool supports this level\n\t\t\tif (!tool.supportedLevels.includes(context.level)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Pass 2: Ask tool if it's relevant\n\t\t\ttry {\n\t\t\t\tif (tool.isVisibleInContext(context)) {\n\t\t\t\t\tvisible.push(tool);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`Error evaluating visibility for tool '${toolId}':`,\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn visible;\n\t}\n\n\t/**\n\t * Get tool metadata for building UIs\n\t * Useful for building PNP configuration interfaces\n\t *\n\t * @returns Array of tool metadata (id, name, description, pnpSupportIds)\n\t */\n\tgetToolMetadata(): Array<{\n\t\ttoolId: string;\n\t\tname: string;\n\t\tdescription: string;\n\t\tpnpSupportIds: string[];\n\t\tsupportedLevels: ToolLevel[];\n\t\tactivation: ToolActivation;\n\t\tsingletonScope: ToolSingletonScope | null;\n\t}> {\n\t\treturn this.getAllTools().map((tool) => ({\n\t\t\ttoolId: tool.toolId,\n\t\t\tname: tool.name,\n\t\t\tdescription: tool.description,\n\t\t\tpnpSupportIds: tool.pnpSupportIds || [],\n\t\t\tsupportedLevels: tool.supportedLevels,\n\t\t\tactivation: tool.activation || \"toolbar-toggle\",\n\t\t\tsingletonScope: tool.singletonScope || null,\n\t\t}));\n\t}\n\n\t/**\n\t * Generate PNP support IDs from enabled tools\n\t * Useful for creating PNP profiles\n\t *\n\t * @param enabledToolIds - Tool IDs to enable\n\t * @returns Array of unique PNP support IDs\n\t */\n\tgeneratePNPSupportsFromTools(enabledToolIds: string[]): string[] {\n\t\tconst pnpSupports = new Set<string>();\n\n\t\tfor (const toolId of enabledToolIds) {\n\t\t\tconst tool = this.get(toolId);\n\t\t\tif (tool?.pnpSupportIds) {\n\t\t\t\tfor (const pnpId of tool.pnpSupportIds) {\n\t\t\t\t\tpnpSupports.add(pnpId);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn Array.from(pnpSupports);\n\t}\n\n\t/**\n\t * Clear all registrations (useful for testing)\n\t */\n\tclear(): void {\n\t\tthis.tools.clear();\n\t\tthis.pnpIndex.clear();\n\t}\n\n\t/**\n\t * Configure global component overrides used by tool instance creation.\n\t */\n\tsetComponentOverrides(overrides: ToolComponentOverrides): void {\n\t\tthis.componentOverrides = overrides;\n\t}\n\n\t/**\n\t * Register lazy module loaders by toolId.\n\t * Toolbars call ensureToolModuleLoaded(toolId) before instance creation.\n\t */\n\tsetToolModuleLoaders(\n\t\tloaders: Partial<Record<string, ToolModuleLoader>>,\n\t): void {\n\t\tfor (const [toolId, loader] of Object.entries(loaders)) {\n\t\t\tif (!loader) continue;\n\t\t\tassertNonEmptyString(toolId, \"tool module loader id\");\n\t\t\tif (typeof loader !== \"function\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid tool module loader for \"${toolId}\": expected a function.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.moduleLoaders.set(toolId, loader);\n\t\t}\n\t}\n\n\t/**\n\t * Ensure tool module side-effects are loaded exactly once.\n\t * Safe to call repeatedly; concurrent callers share the same promise.\n\t */\n\tasync ensureToolModuleLoaded(toolId: string): Promise<void> {\n\t\tif (this.loadedToolModules.has(toolId)) return;\n\n\t\tconst existingPromise = this.moduleLoadPromises.get(toolId);\n\t\tif (existingPromise) {\n\t\t\tawait existingPromise;\n\t\t\treturn;\n\t\t}\n\n\t\tconst loader = this.moduleLoaders.get(toolId);\n\t\tif (!loader) return;\n\n\t\tconst loadPromise = (async () => {\n\t\t\tawait loader();\n\t\t\tthis.loadedToolModules.add(toolId);\n\t\t})();\n\n\t\tthis.moduleLoadPromises.set(toolId, loadPromise);\n\t\ttry {\n\t\t\tawait loadPromise;\n\t\t} finally {\n\t\t\tthis.moduleLoadPromises.delete(toolId);\n\t\t}\n\t}\n\n\t/**\n\t * Ensure a set of tool modules are loaded.\n\t */\n\tasync ensureToolModulesLoaded(toolIds: string[]): Promise<void> {\n\t\tawait Promise.all(\n\t\t\ttoolIds.map((toolId) => this.ensureToolModuleLoaded(toolId)),\n\t\t);\n\t}\n\n\t/**\n\t * Whether a tool module has already been loaded.\n\t */\n\tisToolModuleLoaded(toolId: string): boolean {\n\t\treturn this.loadedToolModules.has(toolId);\n\t}\n\n\t/**\n\t * Render a tool for toolbar use with component overrides attached.\n\t */\n\trenderForToolbar(\n\t\ttoolId: string,\n\t\tcontext: ToolContext,\n\t\ttoolbarContext: ToolbarContext,\n\t): ToolToolbarRenderResult | null {\n\t\tconst tool = this.get(toolId);\n\t\tif (!tool) {\n\t\t\tthrow new Error(`Tool '${toolId}' is not registered`);\n\t\t}\n\n\t\tconst mergedContext: ToolbarContext = {\n\t\t\t...toolbarContext,\n\t\t\tcomponentOverrides: {\n\t\t\t\t...(this.componentOverrides || {}),\n\t\t\t\t...(toolbarContext.componentOverrides || {}),\n\t\t\t},\n\t\t};\n\n\t\treturn tool.renderToolbar(context, mergedContext);\n\t}\n}\n"]}
1
+ {"version":3,"file":"ToolRegistry.js","sourceRoot":"","sources":["../../src/services/ToolRegistry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AA2OlE,MAAM,iBAAiB,GAAgB;IACtC,YAAY;IACZ,SAAS;IACT,MAAM;IACN,SAAS;IACT,QAAQ;IACR,SAAS;CACT,CAAC;AAEF,SAAS,oBAAoB,CAC5B,KAAc,EACd,SAAiB;IAEjB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5D,MAAM,IAAI,KAAK,CACd,+BAA+B,SAAS,+BAA+B,CACvE,CAAC;IACH,CAAC;AACF,CAAC;AAED,wEAAwE;AACxE,sEAAsE;AACtE,uEAAuE;AACvE,0EAA0E;AAC1E,mCAAmC;AACnC,MAAM,wBAAwB,GAA+C;IAC5E,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,yBAAyB,EAAE;IAC5D;QACC,OAAO,EAAE,iBAAiB;QAC1B,MAAM,EAAE,mDAAmD;KAC3D;IACD,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,4BAA4B,EAAE;IACjE;QACC,OAAO,EAAE,mBAAmB;QAC5B,MAAM,EAAE,oCAAoC;KAC5C;CACD,CAAC;AAEF,SAAS,sBAAsB,CAC9B,MAAc,EACd,IAAY,EACZ,SAAiB;IAEjB,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IACjC,MAAM,YAAY,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAC9D,MAAM,YAAY,GAAG,WAAW,CAAC,IAAI,CA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AO,EAAE,aAAa,CAAC,CAAC;IACnD,CAAC;CACD","sourcesContent":["/**\n * Tool Registry\n *\n * Central registry for all assessment tools. Manages tool metadata, visibility logic,\n * and button/instance creation. Supports dynamic registration and override by integrators.\n */\n\nimport type { ToolContext, ToolLevel } from \"./tool-context.js\";\nimport type { ToolComponentOverrides } from \"../tools/tool-tag-map.js\";\nimport type {\n\tElementToolStateStoreApi,\n\tToolCoordinatorApi,\n\tToolkitCoordinatorApi,\n\tTtsServiceApi,\n} from \"./interfaces.js\";\nimport type { ToolProviderApi } from \"./tool-providers/ToolProviderApi.js\";\nimport type { ToolProviderConfig as ToolRuntimeConfig } from \"./tools-config-normalizer.js\";\nimport type { ToolConfigDiagnostic } from \"./tool-config-validation.js\";\nimport { normalizeToolAlias } from \"./tools-config-normalizer.js\";\n\nexport type ToolModuleLoader = () => Promise<unknown>;\n\nexport interface ToolToolbarButtonDefinition {\n\ttoolId: string;\n\tlabel: string;\n\ticon: string;\n\tariaLabel: string;\n\ttooltip?: string;\n\tonClick: () => void;\n\tclassName?: string;\n\tdisabled?: boolean;\n\tactive?: boolean;\n}\n\nexport interface ToolbarContext {\n\tscope: {\n\t\tlevel: ToolLevel;\n\t\tscopeId: string;\n\t\tassessmentId?: string;\n\t\tsectionId?: string;\n\t\titemId?: string;\n\t\tcanonicalItemId?: string;\n\t\tcontentKind?: string;\n\t};\n\titemId: string;\n\tcatalogId: string;\n\tlanguage: string;\n\tui?: {\n\t\tsize?: string;\n\t};\n\tgetScopeElement?: () => HTMLElement | null;\n\tgetGlobalElementId?: () => string | null;\n\ttoolCoordinator: ToolCoordinatorApi | null;\n\ttoolkitCoordinator: ToolkitCoordinatorApi | null;\n\tttsService: TtsServiceApi | null;\n\telementToolStateStore: ElementToolStateStoreApi | null;\n\ttoggleTool: (toolId: string) => void;\n\tisToolVisible: (toolId: string) => boolean;\n\tsubscribeVisibility: ((listener: () => void) => () => void) | null;\n\tcomponentOverrides?: ToolComponentOverrides;\n\tgetResolvedToolContext?: (toolId: string) => ResolvedToolContext | null;\n\tgetToolRenderParams?: (toolId: string) => Record<string, unknown> | null;\n}\n\nexport interface ToolContextResolverContext {\n\ttoolId: string;\n\tcontext: ToolContext;\n\ttoolbarContext: ToolbarContext;\n}\n\nexport interface ToolContextResolverResult {\n\tvisible?: boolean;\n\tparams?: Record<string, unknown>;\n\treason?: string;\n}\n\nexport type ToolContextResolver = (\n\tcontext: ToolContextResolverContext,\n) => ToolContextResolverResult | null | undefined;\n\nexport type ToolContextResolverMap = Record<\n\tstring,\n\tToolContextResolver | null | undefined\n>;\n\nexport interface ResolvedToolContext {\n\ttoolId: string;\n\tvisible: boolean;\n\tparams: Record<string, unknown>;\n\treason?: string;\n}\n\nexport interface ToolRenderElement {\n\telement: HTMLElement | null;\n\tmount: \"before-buttons\" | \"after-buttons\" | \"controls-row\";\n\tlayoutHints?: {\n\t\tcontrolsRow?: {\n\t\t\treserveSpace?: boolean;\n\t\t\tshowWhenToolActive?: boolean;\n\t\t};\n\t};\n\tshell?: ToolWindowShellConfig;\n}\n\nexport interface ToolWindowShellAction {\n\tid: string;\n\tlabel: string;\n\tariaLabel?: string;\n\ticonSvg?: string;\n\tonClick: () => void;\n}\n\n/**\n * Alignment corner for the initial shell position.\n * The shell is offset by `initialMargin` (default 16 px) from the chosen corner.\n */\nexport type ToolWindowShellAlign =\n\t| \"center\"\n\t| \"top-left\"\n\t| \"top-right\"\n\t| \"bottom-left\"\n\t| \"bottom-right\";\n\nexport interface ToolWindowShellConfig {\n\ttitle?: string;\n\tdraggable?: boolean;\n\tresizable?: boolean;\n\tcloseable?: boolean;\n\tinitialWidth?: number;\n\tinitialHeight?: number;\n\tminWidth?: number;\n\tminHeight?: number;\n\tmaxWidth?: number;\n\tmaxHeight?: number;\n\t/** Initial placement of the shell. Defaults to `'center'`. */\n\tinitialAlign?: ToolWindowShellAlign;\n\t/** Distance (px) from the viewport edge when using a corner align. Defaults to 16. */\n\tinitialMargin?: number;\n\tactions?: ToolWindowShellAction[];\n}\n\nexport interface HostedToolContext {\n\ttoolId: string;\n\ttoolbarContext: ToolbarContext;\n\tshellConfig: ToolWindowShellConfig;\n}\n\nexport interface HostedToolSize {\n\twidth: number;\n\theight: number;\n}\n\nexport interface ToolProviderDescriptor {\n\tgetProviderId?: (config: ToolRuntimeConfig | undefined) => string;\n\tcreateProvider: (config: ToolRuntimeConfig | undefined) => ToolProviderApi;\n\tgetInitConfig?: (\n\t\tconfig: ToolRuntimeConfig | undefined,\n\t) => Record<string, unknown>;\n\tsanitizeConfig?: (config: ToolRuntimeConfig) => ToolRuntimeConfig;\n\tvalidateConfig?: (config: ToolRuntimeConfig) => ToolConfigDiagnostic[];\n\tgetAuthFetcher?: (\n\t\tconfig: ToolRuntimeConfig | undefined,\n\t) => (() => Promise<Record<string, unknown>>) | undefined;\n\tlazy?: boolean;\n}\n\nexport interface ToolToolbarRenderResult {\n\ttoolId: string;\n\telements?: ToolRenderElement[];\n\tbutton?: ToolToolbarButtonDefinition | null;\n\tsync?: () => void;\n\tsubscribeActive?: (callback: (active: boolean) => void) => () => void;\n}\n\nexport type ToolActivation = \"toolbar-toggle\" | \"selection-gateway\";\nexport type ToolSingletonScope = \"section\";\n\n/**\n * Tool registration interface\n */\nexport interface ToolRegistration {\n\t/** Unique tool identifier (e.g., 'calculator', 'textToSpeech') */\n\ttoolId: string;\n\n\t/** Human-readable name */\n\tname: string;\n\n\t/** Description of what the tool does */\n\tdescription: string;\n\n\t/** Icon identifier or SVG string */\n\ticon: string | ((context: ToolContext) => string);\n\n\t/** Which levels this tool supports */\n\tsupportedLevels: ToolLevel[];\n\n\t/**\n\t * Activation model for this tool.\n\t * - toolbar-toggle: rendered as a toolbar button (default)\n\t * - selection-gateway: rendered as a singleton selection-driven gateway\n\t */\n\tactivation?: ToolActivation;\n\n\t/**\n\t * Optional singleton scope for activation models that mount exactly one instance.\n\t */\n\tsingletonScope?: ToolSingletonScope;\n\n\t/**\n\t * PNP support IDs that enable this tool (optional)\n\t * Used by the tool policy engine to determine if a PNP support enables this tool.\n\t * Example: ['calculator', 'basic-calculator', 'scientific-calculator']\n\t */\n\tpnpSupportIds?: string[];\n\t/**\n\t * Optional provider registration metadata.\n\t * When present, ToolkitCoordinator can register provider(s) generically\n\t * without hardcoded tool-specific branches.\n\t */\n\tprovider?: ToolProviderDescriptor;\n\t/**\n\t * Optional shell-host lifecycle hooks for hosted (floating) tools.\n\t */\n\tonHostedMount?: (\n\t\telement: HTMLElement,\n\t\tcontext: HostedToolContext,\n\t) => void | Promise<void>;\n\tonHostedResize?: (\n\t\tsize: HostedToolSize,\n\t\telement: HTMLElement,\n\t\tcontext: HostedToolContext,\n\t) => void | Promise<void>;\n\tonHostedUnmount?: (\n\t\telement: HTMLElement,\n\t\tcontext: HostedToolContext,\n\t) => void | Promise<void>;\n\n\t/**\n\t * Pass 2: Tool decides if it's relevant in this context\n\t * Called ONLY if orchestrator has already allowed the tool (Pass 1)\n\t *\n\t * @param context - Rich context about where tool is being evaluated\n\t * @returns true if tool should be visible, false to hide\n\t */\n\tisVisibleInContext(context: ToolContext): boolean;\n\n\t/** Required toolbar-first render contract. */\n\trenderToolbar(\n\t\tcontext: ToolContext,\n\t\ttoolbarContext: ToolbarContext,\n\t): ToolToolbarRenderResult | null;\n}\n\nconst VALID_TOOL_LEVELS: ToolLevel[] = [\n\t\"assessment\",\n\t\"section\",\n\t\"item\",\n\t\"passage\",\n\t\"rubric\",\n\t\"element\",\n];\n\nfunction assertNonEmptyString(\n\tvalue: unknown,\n\tfieldName: string,\n): asserts value is string {\n\tif (typeof value !== \"string\" || value.trim().length === 0) {\n\t\tthrow new Error(\n\t\t\t`Invalid tool registration: \"${fieldName}\" must be a non-empty string.`,\n\t\t);\n\t}\n}\n\n// Defence-in-depth: reject obvious XSS payloads in tool-registered icon\n// markup at registration time. Runtime rendering still runs each icon\n// through DOMPurify (see `ToolIcon.svelte`), but surfacing the problem\n// early produces a clearer error for tool authors than \"the icon silently\n// disappeared after sanitization\".\nconst SCRIPTABLE_ICON_PATTERNS: Array<{ pattern: RegExp; reason: string }> = [\n\t{ pattern: /<script\\b/i, reason: \"contains a <script> tag\" },\n\t{\n\t\tpattern: /\\son[a-z]+\\s*=/i,\n\t\treason: \"contains an inline event handler (on*=) attribute\",\n\t},\n\t{ pattern: /javascript:/i, reason: \"contains a javascript: URL\" },\n\t{\n\t\tpattern: /<foreignObject\\b/i,\n\t\treason: \"contains a <foreignObject> element\",\n\t},\n];\n\nfunction assertIconStringIsSafe(\n\ttoolId: string,\n\ticon: string,\n\tfieldName: string,\n): void {\n\tconst trimmed = icon.trimStart();\n\tconst looksLikeSvg = trimmed.toLowerCase().startsWith(\"<svg\");\n\tconst looksLikeUrl = /^https?:/i.test(trimmed);\n\tconst looksLikeDataUrl = /^data:/i.test(trimmed);\n\tif (looksLikeDataUrl) {\n\t\tthrow new Error(\n\t\t\t`Invalid tool registration \"${toolId}\": \"${fieldName}\" may not be a data: URL.`,\n\t\t);\n\t}\n\tif (!looksLikeSvg && !looksLikeUrl) return;\n\tfor (const { pattern, reason } of SCRIPTABLE_ICON_PATTERNS) {\n\t\tif (pattern.test(icon)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid tool registration \"${toolId}\": \"${fieldName}\" ${reason}. Inline SVG icons must not include scriptable content.`,\n\t\t\t);\n\t\t}\n\t}\n}\n\nfunction assertToolRegistrationShape(registration: ToolRegistration): void {\n\tassertNonEmptyString(registration.toolId, \"toolId\");\n\tassertNonEmptyString(registration.name, \"name\");\n\tassertNonEmptyString(registration.description, \"description\");\n\n\tif (\n\t\ttypeof registration.icon !== \"string\" &&\n\t\ttypeof registration.icon !== \"function\"\n\t) {\n\t\tthrow new Error(\n\t\t\t`Invalid tool registration \"${registration.toolId}\": \"icon\" must be a string or function.`,\n\t\t);\n\t}\n\tif (typeof registration.icon === \"string\") {\n\t\tassertIconStringIsSafe(registration.toolId, registration.icon, \"icon\");\n\t}\n\tif (\n\t\t!Array.isArray(registration.supportedLevels) ||\n\t\tregistration.supportedLevels.length === 0\n\t) {\n\t\tthrow new Error(\n\t\t\t`Invalid tool registration \"${registration.toolId}\": \"supportedLevels\" must be a non-empty array.`,\n\t\t);\n\t}\n\tconst invalidLevel = registration.supportedLevels.find(\n\t\t(level) => !VALID_TOOL_LEVELS.includes(level),\n\t);\n\tif (invalidLevel) {\n\t\tthrow new Error(\n\t\t\t`Invalid tool registration \"${registration.toolId}\": unsupported level \"${invalidLevel}\".`,\n\t\t);\n\t}\n\tif (\n\t\tregistration.activation !== undefined &&\n\t\tregistration.activation !== \"toolbar-toggle\" &&\n\t\tregistration.activation !== \"selection-gateway\"\n\t) {\n\t\tthrow new Error(\n\t\t\t`Invalid tool registration \"${registration.toolId}\": unsupported activation \"${String(registration.activation)}\".`,\n\t\t);\n\t}\n\tif (\n\t\tregistration.singletonScope !== undefined &&\n\t\tregistration.singletonScope !== \"section\"\n\t) {\n\t\tthrow new Error(\n\t\t\t`Invalid tool registration \"${registration.toolId}\": unsupported singletonScope \"${String(registration.singletonScope)}\".`,\n\t\t);\n\t}\n\tif (\n\t\tregistration.activation === \"selection-gateway\" &&\n\t\tregistration.singletonScope !== \"section\"\n\t) {\n\t\tthrow new Error(\n\t\t\t`Invalid tool registration \"${registration.toolId}\": selection-gateway tools must declare singletonScope \"section\".`,\n\t\t);\n\t}\n\tif (\n\t\tregistration.pnpSupportIds !== undefined &&\n\t\t(!Array.isArray(registration.pnpSupportIds) ||\n\t\t\tregistration.pnpSupportIds.some(\n\t\t\t\t(pnpId) => typeof pnpId !== \"string\" || pnpId.trim().length === 0,\n\t\t\t))\n\t) {\n\t\tthrow new Error(\n\t\t\t`Invalid tool registration \"${registration.toolId}\": \"pnpSupportIds\" must be an array of non-empty strings.`,\n\t\t);\n\t}\n\tif (typeof registration.isVisibleInContext !== \"function\") {\n\t\tthrow new Error(\n\t\t\t`Invalid tool registration \"${registration.toolId}\": \"isVisibleInContext\" must be a function.`,\n\t\t);\n\t}\n\tif (typeof registration.renderToolbar !== \"function\") {\n\t\tthrow new Error(\n\t\t\t`Invalid tool registration \"${registration.toolId}\": \"renderToolbar\" must be a function.`,\n\t\t);\n\t}\n}\n\n/**\n * Tool Registry\n *\n * Manages tool registrations and provides query/lookup functionality\n */\nexport class ToolRegistry {\n\tprivate tools = new Map<string, ToolRegistration>();\n\tprivate pnpIndex = new Map<string, Set<string>>(); // pnpSupportId → Set<toolId>\n\tprivate componentOverrides: ToolComponentOverrides = {};\n\tprivate moduleLoaders = new Map<string, ToolModuleLoader>();\n\tprivate loadedToolModules = new Set<string>();\n\tprivate moduleLoadPromises = new Map<string, Promise<void>>();\n\n\t/**\n\t * Normalize a single tool alias to canonical toolId.\n\t */\n\tnormalizeToolId(toolId: string): string {\n\t\treturn normalizeToolAlias(toolId);\n\t}\n\n\t/**\n\t * Normalize a list of tool aliases to canonical toolIds.\n\t */\n\tnormalizeToolIds(toolIds: string[]): string[] {\n\t\treturn toolIds.map((toolId) => this.normalizeToolId(toolId));\n\t}\n\n\t/**\n\t * Register a tool\n\t *\n\t * @param registration - Tool registration\n\t * @throws Error if toolId is already registered\n\t */\n\tregister(registration: ToolRegistration): void {\n\t\tassertToolRegistrationShape(registration);\n\t\tif (this.tools.has(registration.toolId)) {\n\t\t\tthrow new Error(`Tool '${registration.toolId}' is already registered`);\n\t\t}\n\n\t\tthis.tools.set(registration.toolId, registration);\n\n\t\t// Index PNP support IDs\n\t\tif (registration.pnpSupportIds) {\n\t\t\tfor (const pnpId of registration.pnpSupportIds) {\n\t\t\t\tif (!this.pnpIndex.has(pnpId)) {\n\t\t\t\t\tthis.pnpIndex.set(pnpId, new Set());\n\t\t\t\t}\n\t\t\t\tthis.pnpIndex.get(pnpId)!.add(registration.toolId);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Override an existing tool registration\n\t *\n\t * @param registration - New tool registration (must have existing toolId)\n\t */\n\toverride(registration: ToolRegistration): void {\n\t\tassertToolRegistrationShape(registration);\n\t\tif (!this.tools.has(registration.toolId)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot override non-existent tool '${registration.toolId}'`,\n\t\t\t);\n\t\t}\n\n\t\t// Remove old PNP index entries\n\t\tconst oldReg = this.tools.get(registration.toolId)!;\n\t\tif (oldReg.pnpSupportIds) {\n\t\t\tfor (const pnpId of oldReg.pnpSupportIds) {\n\t\t\t\tthis.pnpIndex.get(pnpId)?.delete(registration.toolId);\n\t\t\t}\n\t\t}\n\n\t\t// Add new registration\n\t\tthis.tools.set(registration.toolId, registration);\n\n\t\t// Re-index PNP support IDs\n\t\tif (registration.pnpSupportIds) {\n\t\t\tfor (const pnpId of registration.pnpSupportIds) {\n\t\t\t\tif (!this.pnpIndex.has(pnpId)) {\n\t\t\t\t\tthis.pnpIndex.set(pnpId, new Set());\n\t\t\t\t}\n\t\t\t\tthis.pnpIndex.get(pnpId)!.add(registration.toolId);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Unregister a tool\n\t *\n\t * @param toolId - Tool ID to remove\n\t */\n\tunregister(toolId: string): void {\n\t\tconst reg = this.tools.get(toolId);\n\t\tif (!reg) return;\n\n\t\t// Remove PNP index entries\n\t\tif (reg.pnpSupportIds) {\n\t\t\tfor (const pnpId of reg.pnpSupportIds) {\n\t\t\t\tthis.pnpIndex.get(pnpId)?.delete(toolId);\n\t\t\t}\n\t\t}\n\n\t\tthis.tools.delete(toolId);\n\t}\n\n\t/**\n\t * Get a tool registration by ID\n\t *\n\t * @param toolId - Tool ID\n\t * @returns Tool registration or undefined\n\t */\n\tget(toolId: string): ToolRegistration | undefined {\n\t\treturn this.tools.get(toolId);\n\t}\n\n\t/**\n\t * Check if a tool is registered\n\t *\n\t * @param toolId - Tool ID\n\t * @returns true if registered\n\t */\n\thas(toolId: string): boolean {\n\t\treturn this.tools.has(toolId);\n\t}\n\n\t/**\n\t * Get all registered tool IDs\n\t *\n\t * @returns Array of tool IDs\n\t */\n\tgetAllToolIds(): string[] {\n\t\treturn Array.from(this.tools.keys());\n\t}\n\n\t/**\n\t * Get all tool registrations\n\t *\n\t * @returns Array of tool registrations\n\t */\n\tgetAllTools(): ToolRegistration[] {\n\t\treturn Array.from(this.tools.values());\n\t}\n\n\t/**\n\t * Find tool IDs that support a given PNP support ID\n\t *\n\t * @param pnpSupportId - PNP support ID (e.g., 'calculator')\n\t * @returns Set of tool IDs that support this PNP ID\n\t */\n\tgetToolsByPNPSupport(pnpSupportId: string): Set<string> {\n\t\treturn this.pnpIndex.get(pnpSupportId) || new Set();\n\t}\n\n\t/**\n\t * Get tools that support a specific level\n\t *\n\t * @param level - Tool level (assessment, section, item, passage, element)\n\t * @returns Array of tool registrations that support this level\n\t */\n\tgetToolsByLevel(level: ToolLevel): ToolRegistration[] {\n\t\treturn this.getAllTools().filter((tool) =>\n\t\t\ttool.supportedLevels.includes(level),\n\t\t);\n\t}\n\n\t/**\n\t * Resolve tool activation, defaulting to toolbar-toggle.\n\t */\n\tgetToolActivation(toolId: string): ToolActivation {\n\t\treturn this.get(toolId)?.activation || \"toolbar-toggle\";\n\t}\n\n\t/**\n\t * Resolve singleton scope for a tool when present.\n\t */\n\tgetToolSingletonScope(toolId: string): ToolSingletonScope | null {\n\t\treturn this.get(toolId)?.singletonScope || null;\n\t}\n\n\t/**\n\t * Filter tool IDs by activation type.\n\t */\n\tfilterToolIdsByActivation(\n\t\ttoolIds: string[],\n\t\tactivation: ToolActivation,\n\t): string[] {\n\t\treturn toolIds.filter(\n\t\t\t(toolId) => this.getToolActivation(toolId) === activation,\n\t\t);\n\t}\n\n\t/**\n\t * Filter tools by visibility in a given context\n\t *\n\t * Pass 2 of the two-pass model: Given a list of allowed tool IDs (from Pass 1),\n\t * ask each tool if it's relevant in this context.\n\t *\n\t * @param allowedToolIds - Tool IDs that passed Pass 1 (orchestrator approval)\n\t * @param context - Context to evaluate\n\t * @returns Array of visible tool registrations\n\t */\n\tfilterVisibleInContext(\n\t\tallowedToolIds: string[],\n\t\tcontext: ToolContext,\n\t): ToolRegistration[] {\n\t\tconst visible: ToolRegistration[] = [];\n\n\t\tfor (const toolId of allowedToolIds) {\n\t\t\tconst tool = this.get(toolId);\n\t\t\tif (!tool) {\n\t\t\t\tconsole.warn(`Tool '${toolId}' is allowed but not registered`);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Check if tool supports this level\n\t\t\tif (!tool.supportedLevels.includes(context.level)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Pass 2: Ask tool if it's relevant\n\t\t\ttry {\n\t\t\t\tif (tool.isVisibleInContext(context)) {\n\t\t\t\t\tvisible.push(tool);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`Error evaluating visibility for tool '${toolId}':`,\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn visible;\n\t}\n\n\t/**\n\t * Get tool metadata for building UIs\n\t * Useful for building PNP configuration interfaces\n\t *\n\t * @returns Array of tool metadata (id, name, description, pnpSupportIds)\n\t */\n\tgetToolMetadata(): Array<{\n\t\ttoolId: string;\n\t\tname: string;\n\t\tdescription: string;\n\t\tpnpSupportIds: string[];\n\t\tsupportedLevels: ToolLevel[];\n\t\tactivation: ToolActivation;\n\t\tsingletonScope: ToolSingletonScope | null;\n\t}> {\n\t\treturn this.getAllTools().map((tool) => ({\n\t\t\ttoolId: tool.toolId,\n\t\t\tname: tool.name,\n\t\t\tdescription: tool.description,\n\t\t\tpnpSupportIds: tool.pnpSupportIds || [],\n\t\t\tsupportedLevels: tool.supportedLevels,\n\t\t\tactivation: tool.activation || \"toolbar-toggle\",\n\t\t\tsingletonScope: tool.singletonScope || null,\n\t\t}));\n\t}\n\n\t/**\n\t * Generate PNP support IDs from enabled tools\n\t * Useful for creating PNP profiles\n\t *\n\t * @param enabledToolIds - Tool IDs to enable\n\t * @returns Array of unique PNP support IDs\n\t */\n\tgeneratePNPSupportsFromTools(enabledToolIds: string[]): string[] {\n\t\tconst pnpSupports = new Set<string>();\n\n\t\tfor (const toolId of enabledToolIds) {\n\t\t\tconst tool = this.get(toolId);\n\t\t\tif (tool?.pnpSupportIds) {\n\t\t\t\tfor (const pnpId of tool.pnpSupportIds) {\n\t\t\t\t\tpnpSupports.add(pnpId);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn Array.from(pnpSupports);\n\t}\n\n\t/**\n\t * Clear all registrations (useful for testing)\n\t */\n\tclear(): void {\n\t\tthis.tools.clear();\n\t\tthis.pnpIndex.clear();\n\t}\n\n\t/**\n\t * Configure global component overrides used by tool instance creation.\n\t */\n\tsetComponentOverrides(overrides: ToolComponentOverrides): void {\n\t\tthis.componentOverrides = overrides;\n\t}\n\n\t/**\n\t * Register lazy module loaders by toolId.\n\t * Toolbars call ensureToolModuleLoaded(toolId) before instance creation.\n\t */\n\tsetToolModuleLoaders(\n\t\tloaders: Partial<Record<string, ToolModuleLoader>>,\n\t): void {\n\t\tfor (const [toolId, loader] of Object.entries(loaders)) {\n\t\t\tif (!loader) continue;\n\t\t\tassertNonEmptyString(toolId, \"tool module loader id\");\n\t\t\tif (typeof loader !== \"function\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid tool module loader for \"${toolId}\": expected a function.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.moduleLoaders.set(toolId, loader);\n\t\t}\n\t}\n\n\t/**\n\t * Ensure tool module side-effects are loaded exactly once.\n\t * Safe to call repeatedly; concurrent callers share the same promise.\n\t */\n\tasync ensureToolModuleLoaded(toolId: string): Promise<void> {\n\t\tif (this.loadedToolModules.has(toolId)) return;\n\n\t\tconst existingPromise = this.moduleLoadPromises.get(toolId);\n\t\tif (existingPromise) {\n\t\t\tawait existingPromise;\n\t\t\treturn;\n\t\t}\n\n\t\tconst loader = this.moduleLoaders.get(toolId);\n\t\tif (!loader) return;\n\n\t\tconst loadPromise = (async () => {\n\t\t\tawait loader();\n\t\t\tthis.loadedToolModules.add(toolId);\n\t\t})();\n\n\t\tthis.moduleLoadPromises.set(toolId, loadPromise);\n\t\ttry {\n\t\t\tawait loadPromise;\n\t\t} finally {\n\t\t\tthis.moduleLoadPromises.delete(toolId);\n\t\t}\n\t}\n\n\t/**\n\t * Ensure a set of tool modules are loaded.\n\t */\n\tasync ensureToolModulesLoaded(toolIds: string[]): Promise<void> {\n\t\tawait Promise.all(\n\t\t\ttoolIds.map((toolId) => this.ensureToolModuleLoaded(toolId)),\n\t\t);\n\t}\n\n\t/**\n\t * Whether a tool module has already been loaded.\n\t */\n\tisToolModuleLoaded(toolId: string): boolean {\n\t\treturn this.loadedToolModules.has(toolId);\n\t}\n\n\t/**\n\t * Render a tool for toolbar use with component overrides attached.\n\t */\n\trenderForToolbar(\n\t\ttoolId: string,\n\t\tcontext: ToolContext,\n\t\ttoolbarContext: ToolbarContext,\n\t): ToolToolbarRenderResult | null {\n\t\tconst tool = this.get(toolId);\n\t\tif (!tool) {\n\t\t\tthrow new Error(`Tool '${toolId}' is not registered`);\n\t\t}\n\n\t\tconst mergedContext: ToolbarContext = {\n\t\t\t...toolbarContext,\n\t\t\tcomponentOverrides: {\n\t\t\t\t...(this.componentOverrides || {}),\n\t\t\t\t...(toolbarContext.componentOverrides || {}),\n\t\t\t},\n\t\t};\n\n\t\treturn tool.renderToolbar(context, mergedContext);\n\t}\n}\n"]}
@@ -1255,30 +1255,40 @@ export class ToolkitCoordinator {
1255
1255
  return;
1256
1256
  await new Promise((resolve) => {
1257
1257
  let settled = false;
1258
+ const canUseEventTarget = typeof synth.addEventListener === "function" &&
1259
+ typeof synth.removeEventListener === "function";
1260
+ const canUseHandler = !canUseEventTarget && "onvoiceschanged" in synth;
1261
+ const previousHandler = canUseHandler ? synth.onvoiceschanged : null;
1262
+ let assignedHandler = false;
1258
1263
  const finish = () => {
1259
1264
  if (settled)
1260
1265
  return;
1261
1266
  settled = true;
1262
- resolve();
1263
- };
1264
- const timeoutId = window.setTimeout(() => {
1265
- synth.removeEventListener("voiceschanged", onVoicesChanged);
1266
- finish();
1267
- }, timeoutMs);
1268
- const onVoicesChanged = () => {
1269
1267
  window.clearTimeout(timeoutId);
1270
- if (typeof synth.removeEventListener === "function" &&
1271
- typeof synth.addEventListener === "function") {
1268
+ if (canUseEventTarget) {
1272
1269
  synth.removeEventListener("voiceschanged", onVoicesChanged);
1273
1270
  }
1271
+ else if (assignedHandler && synth.onvoiceschanged === onVoicesChanged) {
1272
+ synth.onvoiceschanged = previousHandler;
1273
+ }
1274
+ resolve();
1275
+ };
1276
+ const onVoicesChanged = (event) => {
1277
+ if (!canUseEventTarget && typeof previousHandler === "function" && event) {
1278
+ previousHandler.call(synth, event);
1279
+ }
1274
1280
  finish();
1275
1281
  };
1276
- if (typeof synth.addEventListener === "function" &&
1277
- typeof synth.removeEventListener === "function") {
1282
+ const timeoutId = window.setTimeout(finish, timeoutMs);
1283
+ if (canUseEventTarget) {
1278
1284
  synth.addEventListener("voiceschanged", onVoicesChanged, {
1279
1285
  once: true,
1280
1286
  });
1281
1287
  }
1288
+ else if (canUseHandler) {
1289
+ synth.onvoiceschanged = onVoicesChanged;
1290
+ assignedHandler = true;
1291
+ }
1282
1292
  });
1283
1293
  const voicesAfterWait = synth.getVoices();
1284
1294
  await this.emitTelemetry("pie-toolkit-tts-browser-voices-ready", {