@pie-players/pie-assessment-toolkit 0.3.44 → 0.3.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -69
- package/dist/components/ItemToolBar.custom-element.js +479 -324
- package/dist/components/PieAssessmentToolkit.custom-element.js +19498 -3590
- package/dist/components/SectionToolBar.custom-element.js +761 -507
- package/dist/index.d.ts +3 -6
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/policy/core/ToolPolicyEngine.d.ts +1 -2
- package/dist/policy/core/ToolPolicyEngine.js +1 -2
- package/dist/policy/core/ToolPolicyEngine.js.map +1 -1
- package/dist/policy/core/pnp-policy-inputs.d.ts +2 -3
- package/dist/policy/core/pnp-policy-inputs.js +2 -3
- package/dist/policy/core/pnp-policy-inputs.js.map +1 -1
- package/dist/policy/core/provenance.d.ts +7 -34
- package/dist/policy/core/provenance.js +4 -21
- package/dist/policy/core/provenance.js.map +1 -1
- package/dist/policy/sources/PnpPolicySource.d.ts +6 -19
- package/dist/policy/sources/PnpPolicySource.js +6 -19
- package/dist/policy/sources/PnpPolicySource.js.map +1 -1
- package/dist/runtime/SectionRuntimeEngine.d.ts +13 -28
- package/dist/runtime/SectionRuntimeEngine.js +13 -27
- package/dist/runtime/SectionRuntimeEngine.js.map +1 -1
- package/dist/runtime/adapter/SectionEngineAdapter.d.ts +2 -2
- package/dist/runtime/adapter/SectionEngineAdapter.js +2 -2
- package/dist/runtime/adapter/SectionEngineAdapter.js.map +1 -1
- package/dist/runtime/adapter/coordinator-bridge.d.ts +1 -1
- package/dist/runtime/adapter/coordinator-bridge.js +1 -1
- package/dist/runtime/adapter/coordinator-bridge.js.map +1 -1
- package/dist/runtime/adapter/dom-event-bridge.d.ts +1 -1
- package/dist/runtime/adapter/dom-event-bridge.js +1 -1
- package/dist/runtime/adapter/dom-event-bridge.js.map +1 -1
- package/dist/runtime/catalog-registration.d.ts +12 -0
- package/dist/runtime/catalog-registration.js +54 -0
- package/dist/runtime/catalog-registration.js.map +1 -0
- package/dist/runtime/core/engine-output.d.ts +2 -2
- package/dist/runtime/core/engine-output.js +2 -2
- package/dist/runtime/core/engine-output.js.map +1 -1
- package/dist/runtime/core/engine-readiness.d.ts +2 -2
- package/dist/runtime/core/engine-readiness.js.map +1 -1
- package/dist/runtime/core/engine-resolver.d.ts +13 -41
- package/dist/runtime/core/engine-resolver.js +19 -76
- package/dist/runtime/core/engine-resolver.js.map +1 -1
- package/dist/runtime/core/engine-transition.d.ts +1 -1
- package/dist/runtime/core/engine-transition.js +1 -1
- package/dist/runtime/core/engine-transition.js.map +1 -1
- package/dist/runtime/engine.d.ts +1 -1
- package/dist/runtime/engine.js.map +1 -1
- package/dist/runtime/section-runtime-engine-host-context.d.ts +22 -15
- package/dist/runtime/section-runtime-engine-host-context.js +10 -10
- package/dist/runtime/section-runtime-engine-host-context.js.map +1 -1
- package/dist/runtime/stage-emit-gate.d.ts +4 -4
- package/dist/runtime/stage-emit-gate.js +3 -3
- package/dist/runtime/stage-emit-gate.js.map +1 -1
- package/dist/services/AccessibilityCatalogResolver.d.ts +23 -0
- package/dist/services/AccessibilityCatalogResolver.js +200 -28
- package/dist/services/AccessibilityCatalogResolver.js.map +1 -1
- package/dist/services/HighlightCoordinator.d.ts +25 -0
- package/dist/services/HighlightCoordinator.js +125 -0
- package/dist/services/HighlightCoordinator.js.map +1 -1
- package/dist/services/SSMLExtractor.d.ts +16 -1
- package/dist/services/SSMLExtractor.js +86 -7
- package/dist/services/SSMLExtractor.js.map +1 -1
- package/dist/services/TTSService.d.ts +30 -4
- package/dist/services/TTSService.js +652 -159
- package/dist/services/TTSService.js.map +1 -1
- package/dist/services/ToolRegistry.d.ts +2 -2
- package/dist/services/ToolRegistry.js +1 -1
- package/dist/services/ToolRegistry.js.map +1 -1
- package/dist/services/ToolkitCoordinator.d.ts +16 -73
- package/dist/services/ToolkitCoordinator.js +34 -113
- package/dist/services/ToolkitCoordinator.js.map +1 -1
- package/dist/services/interfaces.d.ts +20 -2
- package/dist/services/interfaces.js.map +1 -1
- package/dist/services/tool-config-validation.d.ts +1 -1
- package/dist/services/tool-config-validation.js +7 -7
- package/dist/services/tool-config-validation.js.map +1 -1
- package/dist/services/tool-instance-id.js +1 -1
- package/dist/services/tool-instance-id.js.map +1 -1
- package/dist/services/tool-providers/TTSToolProvider.js +3 -3
- package/dist/services/tool-providers/TTSToolProvider.js.map +1 -1
- package/dist/services/tools-config-normalizer.d.ts +13 -2
- package/dist/services/tools-config-normalizer.js +3 -8
- package/dist/services/tools-config-normalizer.js.map +1 -1
- package/dist/services/tts/browser-provider.js +2 -0
- package/dist/services/tts/browser-provider.js.map +1 -1
- package/dist/services/tts/catalog-span-alignment.d.ts +39 -0
- package/dist/services/tts/catalog-span-alignment.js +300 -0
- package/dist/services/tts/catalog-span-alignment.js.map +1 -0
- package/dist/services/tts/generated-speech/assemble-plan.d.ts +33 -0
- package/dist/services/tts/generated-speech/assemble-plan.js +111 -0
- package/dist/services/tts/generated-speech/assemble-plan.js.map +1 -0
- package/dist/services/tts/generated-speech/dom/build-dom-plan.d.ts +25 -0
- package/dist/services/tts/generated-speech/dom/build-dom-plan.js +66 -0
- package/dist/services/tts/generated-speech/dom/build-dom-plan.js.map +1 -0
- package/dist/services/tts/generated-speech/dom/to-chunk-inputs.d.ts +19 -0
- package/dist/services/tts/generated-speech/dom/to-chunk-inputs.js +71 -0
- package/dist/services/tts/generated-speech/dom/to-chunk-inputs.js.map +1 -0
- package/dist/services/tts/generated-speech/dom/types.d.ts +37 -0
- package/dist/services/tts/generated-speech/dom/types.js +2 -0
- package/dist/services/tts/generated-speech/dom/types.js.map +1 -0
- package/dist/services/tts/generated-speech/index.d.ts +17 -0
- package/dist/services/tts/generated-speech/index.js +17 -0
- package/dist/services/tts/generated-speech/index.js.map +1 -0
- package/dist/services/tts/generated-speech/math-speech-cache.d.ts +15 -0
- package/dist/services/tts/generated-speech/math-speech-cache.js +78 -0
- package/dist/services/tts/generated-speech/math-speech-cache.js.map +1 -0
- package/dist/services/tts/generated-speech/types.d.ts +104 -0
- package/dist/services/tts/generated-speech/types.js +18 -0
- package/dist/services/tts/generated-speech/types.js.map +1 -0
- package/dist/services/tts/highlight-pipeline/boundary-normalizer.d.ts +2 -0
- package/dist/services/tts/highlight-pipeline/boundary-normalizer.js +106 -0
- package/dist/services/tts/highlight-pipeline/boundary-normalizer.js.map +1 -0
- package/dist/services/tts/highlight-pipeline/create-highlight-plan.d.ts +6 -0
- package/dist/services/tts/highlight-pipeline/create-highlight-plan.js +217 -0
- package/dist/services/tts/highlight-pipeline/create-highlight-plan.js.map +1 -0
- package/dist/services/tts/highlight-pipeline/highlight-policy.d.ts +2 -0
- package/dist/services/tts/highlight-pipeline/highlight-policy.js +32 -0
- package/dist/services/tts/highlight-pipeline/highlight-policy.js.map +1 -0
- package/dist/services/tts/highlight-pipeline/index.d.ts +9 -0
- package/dist/services/tts/highlight-pipeline/index.js +9 -0
- package/dist/services/tts/highlight-pipeline/index.js.map +1 -0
- package/dist/services/tts/highlight-pipeline/math-semantic-resolver.d.ts +3 -0
- package/dist/services/tts/highlight-pipeline/math-semantic-resolver.js +32 -0
- package/dist/services/tts/highlight-pipeline/math-semantic-resolver.js.map +1 -0
- package/dist/services/tts/highlight-pipeline/normalize-speech-chunks.d.ts +29 -0
- package/dist/services/tts/highlight-pipeline/normalize-speech-chunks.js +44 -0
- package/dist/services/tts/highlight-pipeline/normalize-speech-chunks.js.map +1 -0
- package/dist/services/tts/highlight-pipeline/prose-boundary-resolver.d.ts +2 -0
- package/dist/services/tts/highlight-pipeline/prose-boundary-resolver.js +20 -0
- package/dist/services/tts/highlight-pipeline/prose-boundary-resolver.js.map +1 -0
- package/dist/services/tts/highlight-pipeline/readable-region.d.ts +1 -0
- package/dist/services/tts/highlight-pipeline/readable-region.js +19 -0
- package/dist/services/tts/highlight-pipeline/readable-region.js.map +1 -0
- package/dist/services/tts/highlight-pipeline/rendered-math-target-resolver.d.ts +6 -0
- package/dist/services/tts/highlight-pipeline/rendered-math-target-resolver.js +198 -0
- package/dist/services/tts/highlight-pipeline/rendered-math-target-resolver.js.map +1 -0
- package/dist/services/tts/highlight-pipeline/types.d.ts +72 -0
- package/dist/services/tts/highlight-pipeline/types.js +2 -0
- package/dist/services/tts/highlight-pipeline/types.js.map +1 -0
- package/dist/services/tts/highlight-pipeline/visible-map-range.d.ts +2 -0
- package/dist/services/tts/highlight-pipeline/visible-map-range.js +22 -0
- package/dist/services/tts/highlight-pipeline/visible-map-range.js.map +1 -0
- package/dist/services/tts/math-alignment/index.d.ts +30 -0
- package/dist/services/tts/math-alignment/index.js +66 -0
- package/dist/services/tts/math-alignment/index.js.map +1 -0
- package/dist/services/tts/math-alignment/mathml-tokenizer.d.ts +2 -0
- package/dist/services/tts/math-alignment/mathml-tokenizer.js +317 -0
- package/dist/services/tts/math-alignment/mathml-tokenizer.js.map +1 -0
- package/dist/services/tts/math-alignment/range-resolver.d.ts +10 -0
- package/dist/services/tts/math-alignment/range-resolver.js +13 -0
- package/dist/services/tts/math-alignment/range-resolver.js.map +1 -0
- package/dist/services/tts/math-alignment/sequence-aligner.d.ts +7 -0
- package/dist/services/tts/math-alignment/sequence-aligner.js +119 -0
- package/dist/services/tts/math-alignment/sequence-aligner.js.map +1 -0
- package/dist/services/tts/math-alignment/speech-tokenizer.d.ts +31 -0
- package/dist/services/tts/math-alignment/speech-tokenizer.js +143 -0
- package/dist/services/tts/math-alignment/speech-tokenizer.js.map +1 -0
- package/dist/services/tts/math-alignment/types.d.ts +58 -0
- package/dist/services/tts/math-alignment/types.js +2 -0
- package/dist/services/tts/math-alignment/types.js.map +1 -0
- package/dist/services/tts/math-aware-text-processing.d.ts +18 -0
- package/dist/services/tts/math-aware-text-processing.js +348 -0
- package/dist/services/tts/math-aware-text-processing.js.map +1 -0
- package/dist/services/tts/math-speech.d.ts +44 -0
- package/dist/services/tts/math-speech.js +147 -0
- package/dist/services/tts/math-speech.js.map +1 -0
- package/dist/services/tts/mathml-sanitization.d.ts +1 -0
- package/dist/services/tts/mathml-sanitization.js +170 -0
- package/dist/services/tts/mathml-sanitization.js.map +1 -0
- package/dist/services/tts/ssml/spoken-text.d.ts +33 -0
- package/dist/services/tts/ssml/spoken-text.js +159 -0
- package/dist/services/tts/ssml/spoken-text.js.map +1 -0
- package/dist/services/tts/text-processing.d.ts +3 -0
- package/dist/services/tts/text-processing.js +30 -4
- package/dist/services/tts/text-processing.js.map +1 -1
- package/dist/services/tts-runtime-config.d.ts +17 -1
- package/dist/services/tts-runtime-config.js +11 -1
- package/dist/services/tts-runtime-config.js.map +1 -1
- package/dist/tools/registrations/accessibility-tools.js +0 -1
- package/dist/tools/registrations/accessibility-tools.js.map +1 -1
- package/dist/tools/registrations/calculator.js +41 -2
- package/dist/tools/registrations/calculator.js.map +1 -1
- package/dist/tools/tool-tag-map.js +0 -1
- package/dist/tools/tool-tag-map.js.map +1 -1
- package/package.json +8 -11
- package/dist/services/PNPToolResolver.d.ts +0 -280
- package/dist/services/PNPToolResolver.js +0 -514
- package/dist/services/PNPToolResolver.js.map +0 -1
- package/dist/services/pnp-provenance.d.ts +0 -166
- package/dist/services/pnp-provenance.js +0 -231
- package/dist/services/pnp-provenance.js.map +0 -1
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
export const normalizeTextForSpeech = (text) => text.trim().replace(/\s+/g, " ");
|
|
2
|
+
// Single source of truth for aligning spoken text to visible / math text.
|
|
3
|
+
// Letters are matched with `\p{L}` so the tokenizer is Unicode-aware — accented
|
|
4
|
+
// Latin ("café") and non-Latin scripts stay one token instead of being split
|
|
5
|
+
// or dropped, which is what previously limited word-level highlight alignment
|
|
6
|
+
// to ASCII. Numbers cover integers and decimals; the trailing class lists the
|
|
7
|
+
// math glyphs a TTS engine may surface as a single visible token. A fresh
|
|
8
|
+
// RegExp is returned each call because the global flag carries mutable
|
|
9
|
+
// `lastIndex` state that must not be shared across call sites.
|
|
10
|
+
export const createSpeechAlignmentTokenPattern = () => /[\p{L}]+|\d+(?:\.\d+)?|[±√=+\-*/()²³^×÷≤≥≠≈<>|%°'′\u2062]/gu;
|
|
2
11
|
export const isElementHiddenForTTS = (element) => {
|
|
3
12
|
if (element.hidden)
|
|
4
13
|
return true;
|
|
14
|
+
if (element.tagName?.toLowerCase() === "mjx-assistive-mml")
|
|
15
|
+
return true;
|
|
5
16
|
if (element.getAttribute("aria-hidden") === "true")
|
|
6
17
|
return true;
|
|
7
18
|
if (element.hasAttribute("inert"))
|
|
@@ -38,7 +49,20 @@ export const isElementHiddenForTTS = (element) => {
|
|
|
38
49
|
}
|
|
39
50
|
return false;
|
|
40
51
|
};
|
|
41
|
-
const
|
|
52
|
+
export const isNodeHiddenForTTS = (node, root) => {
|
|
53
|
+
let current = node.nodeType === 1
|
|
54
|
+
? node
|
|
55
|
+
: node.parentElement;
|
|
56
|
+
while (current) {
|
|
57
|
+
if (isElementHiddenForTTS(current))
|
|
58
|
+
return true;
|
|
59
|
+
if (root && current === root)
|
|
60
|
+
break;
|
|
61
|
+
current = current.parentElement;
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
};
|
|
65
|
+
export const shouldInsertWordBoundarySpace = (previousChar, nextChar, options) => {
|
|
42
66
|
if (!previousChar || !nextChar)
|
|
43
67
|
return false;
|
|
44
68
|
if (/\s/.test(previousChar) || /\s/.test(nextChar))
|
|
@@ -50,7 +74,9 @@ const shouldInsertBoundarySpace = (previousChar, nextChar, options) => {
|
|
|
50
74
|
try {
|
|
51
75
|
const Segmenter = globalThis.Intl?.Segmenter;
|
|
52
76
|
if (typeof Segmenter === "function") {
|
|
53
|
-
const segmenter = new Segmenter(options?.locale, {
|
|
77
|
+
const segmenter = new Segmenter(options?.locale, {
|
|
78
|
+
granularity: "word",
|
|
79
|
+
});
|
|
54
80
|
const segments = Array.from(segmenter.segment(`${previousChar}${nextChar}`));
|
|
55
81
|
const wordLikeCount = segments.filter((segment) => segment.isWordLike !== false &&
|
|
56
82
|
segment.segment.trim().length > 0).length;
|
|
@@ -85,13 +111,13 @@ export const collectVisibleTextAndMap = (element, options) => {
|
|
|
85
111
|
while (current) {
|
|
86
112
|
const textNode = current;
|
|
87
113
|
const parent = textNode.parentElement;
|
|
88
|
-
if (parent && !
|
|
114
|
+
if (parent && !isNodeHiddenForTTS(textNode, element)) {
|
|
89
115
|
const raw = textNode.textContent || "";
|
|
90
116
|
const firstVisibleMatch = raw.match(/\S/);
|
|
91
117
|
const firstVisibleChar = firstVisibleMatch ? firstVisibleMatch[0] : null;
|
|
92
118
|
if (!inLeadingWhitespace &&
|
|
93
119
|
!lastCharWasWhitespace &&
|
|
94
|
-
|
|
120
|
+
shouldInsertWordBoundarySpace(previousVisibleChar, firstVisibleChar, options)) {
|
|
95
121
|
outChars.push(" ");
|
|
96
122
|
if (lastMapped) {
|
|
97
123
|
map.set(outPos, lastMapped);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text-processing.js","sourceRoot":"","sources":["../../../src/services/tts/text-processing.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,IAAY,EAAU,EAAE,CAC9D,IAAI,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAElC,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,OAAgB,EAAW,EAAE;IAClE,IAAK,OAAuB,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACjD,IAAI,OAAO,CAAC,YAAY,CAAC,aAAa,CAAC,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC;IAChE,IAAI,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAC;IAC/C,MAAM,SAAS,GAAI,OAAuB,CAAC,SAAS,CAAC;IACrD,IACC,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC;QAC9B,SAAS,EAAE,QAAQ,CAAC,aAAa,CAAC;QAClC,SAAS,EAAE,QAAQ,C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QAAQ,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;wBAC/C,UAAU,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;wBAC3C,MAAM,EAAE,CAAC;oBACV,CAAC;oBACD,qBAAqB,GAAG,IAAI,CAAC;gBAC9B,CAAC;qBAAM,CAAC;oBACP,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;oBAClB,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;oBAC/C,UAAU,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;oBAC3C,MAAM,EAAE,CAAC;oBACT,qBAAqB,GAAG,KAAK,CAAC;oBAC9B,mBAAmB,GAAG,EAAE,CAAC;gBAC1B,CAAC;YACF,CAAC;QACF,CAAC;QACD,OAAO,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;IAED,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;IACzC,OAAO,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QAC7B,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACzB,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;AACtB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CACjC,OAAgB,EAChB,OAA+B,EACtB,EAAE,CAAC,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC","sourcesContent":["export type NormalizedTextMap = Map<number, { node: Text; offset: number }>;\nexport type BoundarySpacingMode = \"segmenterPreferred\" | \"alnum\" | \"none\";\n\nexport interface TextProcessingOptions {\n\tlocale?: string;\n\tboundarySpacingMode?: BoundarySpacingMode;\n}\n\nexport const normalizeTextForSpeech = (text: string): string =>\n\ttext.trim().replace(/\\s+/g, \" \");\n\nexport const isElementHiddenForTTS = (element: Element): boolean => {\n\tif ((element as HTMLElement).hidden) return true;\n\tif (element.getAttribute(\"aria-hidden\") === \"true\") return true;\n\tif (element.hasAttribute(\"inert\")) return true;\n\tconst classList = (element as HTMLElement).classList;\n\tif (\n\t\tclassList?.contains(\"sr-only\") ||\n\t\tclassList?.contains(\"pie-sr-only\") ||\n\t\tclassList?.contains(\"visually-hidden\")\n\t) {\n\t\treturn true;\n\t}\n\tif (typeof window !== \"undefined\") {\n\t\tconst style = window.getComputedStyle(element);\n\t\tif (style.display === \"none\" || style.visibility === \"hidden\") {\n\t\t\treturn true;\n\t\t}\n\t\tconst width = Number.parseFloat(style.width || \"0\");\n\t\tconst height = Number.parseFloat(style.height || \"0\");\n\t\tconst isTiny =\n\t\t\tNumber.isFinite(width) &&\n\t\t\tNumber.isFinite(height) &&\n\t\t\twidth <= 1 &&\n\t\t\theight <= 1;\n\t\tconst isOffscreenClip =\n\t\t\tstyle.clipPath.includes(\"inset(50%\") ||\n\t\t\tstyle.clipPath.includes(\"inset(100%\") ||\n\t\t\tstyle.clip.includes(\"rect(0px, 0px, 0px, 0px)\") ||\n\t\t\tstyle.clip.includes(\"rect(0 0 0 0)\");\n\t\tif (\n\t\t\t(style.position === \"absolute\" || style.position === \"fixed\") &&\n\t\t\tisTiny &&\n\t\t\t(style.overflow === \"hidden\" || isOffscreenClip)\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t\tif (style.opacity === \"0\" && isTiny) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n};\n\nconst shouldInsertBoundarySpace = (\n\tpreviousChar: string | null,\n\tnextChar: string | null,\n\toptions?: TextProcessingOptions,\n): boolean => {\n\tif (!previousChar || !nextChar) return false;\n\tif (/\\s/.test(previousChar) || /\\s/.test(nextChar)) return false;\n\tconst mode = options?.boundarySpacingMode ?? \"segmenterPreferred\";\n\tif (mode === \"none\") return false;\n\tif (mode === \"segmenterPreferred\") {\n\t\ttry {\n\t\t\tconst Segmenter = globalThis.Intl?.Segmenter;\n\t\t\tif (typeof Segmenter === \"function\") {\n\t\t\t\tconst segmenter = new Segmenter(options?.locale, { granularity: \"word\" });\n\t\t\t\tconst segments = Array.from(segmenter.segment(`${previousChar}${nextChar}`));\n\t\t\t\tconst wordLikeCount = segments.filter(\n\t\t\t\t\t(segment) =>\n\t\t\t\t\t\t(segment as { isWordLike?: boolean }).isWordLike !== false &&\n\t\t\t\t\t\tsegment.segment.trim().length > 0,\n\t\t\t\t).length;\n\t\t\t\tif (wordLikeCount >= 2) return true;\n\t\t\t}\n\t\t} catch {\n\t\t\t// Fall back to alnum heuristics below.\n\t\t}\n\t}\n\tconst prevIsAlnum = /[A-Za-z0-9]/.test(previousChar);\n\tconst nextIsAlnum = /[A-Za-z0-9]/.test(nextChar);\n\treturn prevIsAlnum && nextIsAlnum;\n};\n\nexport const collectVisibleTextAndMap = (\n\telement: Element,\n\toptions?: TextProcessingOptions,\n): { text: string; map: NormalizedTextMap } => {\n\tconst map: NormalizedTextMap = new Map();\n\tif (\n\t\ttypeof document === \"undefined\" ||\n\t\ttypeof (document as { createTreeWalker?: unknown }).createTreeWalker !==\n\t\t\t\"function\" ||\n\t\ttypeof NodeFilter === \"undefined\"\n\t) {\n\t\treturn { text: \"\", map };\n\t}\n\tconst outChars: string[] = [];\n\tlet outPos = 0;\n\tlet inLeadingWhitespace = true;\n\tlet lastCharWasWhitespace = false;\n\tlet lastMapped: { node: Text; offset: number } | null = null;\n\tlet previousVisibleChar: string | null = null;\n\n\tconst walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT);\n\tlet current = walker.nextNode();\n\twhile (current) {\n\t\tconst textNode = current as Text;\n\t\tconst parent = textNode.parentElement;\n\t\tif (parent && !isElementHiddenForTTS(parent)) {\n\t\t\tconst raw = textNode.textContent || \"\";\n\t\t\tconst firstVisibleMatch = raw.match(/\\S/);\n\t\t\tconst firstVisibleChar = firstVisibleMatch ? firstVisibleMatch[0] : null;\n\n\t\t\tif (\n\t\t\t\t!inLeadingWhitespace &&\n\t\t\t\t!lastCharWasWhitespace &&\n\t\t\t\tshouldInsertBoundarySpace(previousVisibleChar, firstVisibleChar, options)\n\t\t\t) {\n\t\t\t\toutChars.push(\" \");\n\t\t\t\tif (lastMapped) {\n\t\t\t\t\tmap.set(outPos, lastMapped);\n\t\t\t\t}\n\t\t\t\toutPos++;\n\t\t\t\tlastCharWasWhitespace = true;\n\t\t\t}\n\n\t\t\tfor (let i = 0; i < raw.length; i++) {\n\t\t\t\tconst ch = raw[i];\n\t\t\t\tconst isWhitespace = /\\s/.test(ch);\n\n\t\t\t\tif (inLeadingWhitespace) {\n\t\t\t\t\tif (!isWhitespace) {\n\t\t\t\t\t\tinLeadingWhitespace = false;\n\t\t\t\t\t\toutChars.push(ch);\n\t\t\t\t\t\tmap.set(outPos, { node: textNode, offset: i });\n\t\t\t\t\t\tlastMapped = { node: textNode, offset: i };\n\t\t\t\t\t\toutPos++;\n\t\t\t\t\t\tlastCharWasWhitespace = false;\n\t\t\t\t\t\tpreviousVisibleChar = ch;\n\t\t\t\t\t}\n\t\t\t\t} else if (isWhitespace) {\n\t\t\t\t\tif (!lastCharWasWhitespace) {\n\t\t\t\t\t\toutChars.push(\" \");\n\t\t\t\t\t\tmap.set(outPos, { node: textNode, offset: i });\n\t\t\t\t\t\tlastMapped = { node: textNode, offset: i };\n\t\t\t\t\t\toutPos++;\n\t\t\t\t\t}\n\t\t\t\t\tlastCharWasWhitespace = true;\n\t\t\t\t} else {\n\t\t\t\t\toutChars.push(ch);\n\t\t\t\t\tmap.set(outPos, { node: textNode, offset: i });\n\t\t\t\t\tlastMapped = { node: textNode, offset: i };\n\t\t\t\t\toutPos++;\n\t\t\t\t\tlastCharWasWhitespace = false;\n\t\t\t\t\tpreviousVisibleChar = ch;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcurrent = walker.nextNode();\n\t}\n\n\tconst text = outChars.join(\"\").trimEnd();\n\twhile (map.has(text.length)) {\n\t\tmap.delete(text.length);\n\t}\n\treturn { text, map };\n};\n\nexport const extractVisibleText = (\n\telement: Element,\n\toptions?: TextProcessingOptions,\n): string => collectVisibleTextAndMap(element, options).text;\n"]}
|
|
1
|
+
{"version":3,"file":"text-processing.js","sourceRoot":"","sources":["../../../src/services/tts/text-processing.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,IAAY,EAAU,EAAE,CAC9D,IAAI,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAElC,0EAA0E;AAC1E,gFAAgF;AAChF,6EAA6E;AAC7E,8EAA8E;AAC9E,8EAA8E;AAC9E,0EAA0E;AAC1E,uEAAuE;AACvE,+DAA+D;AAC/D,MAAM,CAAC,MAAM,iCAAiC,GAAG,GAAW,EAAE,CAC7D,6DAA6D,CAAC;AAE/D,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,OAAgB,EAAW,EAAE;IAClE,IAAK,OAAuB,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACjD,IAAI,OAAO,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,mBAAmB;QAAE,OAAO,IAAI,CAAC;IACxE,IAAI,OAAO,CAAC,YAAY,CAAC,aAAa,CAAC,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC;IAChE,IAAI,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAC;IAC/C,MAAM,SAAS,GAAI,OAAuB,CAAC,SAAS,CAAC;IACrD,IACC,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC;QAC9B,SAAS,EAAE,QAAQ,CAAC,aAAa,CAAC;QAClC,SAAS,EAAE,QAAQ,CAAC,iBAAiB,CAAC,EACrC,CAAC;QACF,OAAO,IAAI,CAAC;IACb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AAG,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACzB,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;AACtB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CACjC,OAAgB,EAChB,OAA+B,EACtB,EAAE,CAAC,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC","sourcesContent":["export type NormalizedTextMap = Map<number, { node: Text; offset: number }>;\nexport type BoundarySpacingMode = \"segmenterPreferred\" | \"alnum\" | \"none\";\n\nexport interface TextProcessingOptions {\n\tlocale?: string;\n\tboundarySpacingMode?: BoundarySpacingMode;\n}\n\nexport const normalizeTextForSpeech = (text: string): string =>\n\ttext.trim().replace(/\\s+/g, \" \");\n\n// Single source of truth for aligning spoken text to visible / math text.\n// Letters are matched with `\\p{L}` so the tokenizer is Unicode-aware — accented\n// Latin (\"café\") and non-Latin scripts stay one token instead of being split\n// or dropped, which is what previously limited word-level highlight alignment\n// to ASCII. Numbers cover integers and decimals; the trailing class lists the\n// math glyphs a TTS engine may surface as a single visible token. A fresh\n// RegExp is returned each call because the global flag carries mutable\n// `lastIndex` state that must not be shared across call sites.\nexport const createSpeechAlignmentTokenPattern = (): RegExp =>\n\t/[\\p{L}]+|\\d+(?:\\.\\d+)?|[±√=+\\-*/()²³^×÷≤≥≠≈<>|%°'′\\u2062]/gu;\n\nexport const isElementHiddenForTTS = (element: Element): boolean => {\n\tif ((element as HTMLElement).hidden) return true;\n\tif (element.tagName?.toLowerCase() === \"mjx-assistive-mml\") return true;\n\tif (element.getAttribute(\"aria-hidden\") === \"true\") return true;\n\tif (element.hasAttribute(\"inert\")) return true;\n\tconst classList = (element as HTMLElement).classList;\n\tif (\n\t\tclassList?.contains(\"sr-only\") ||\n\t\tclassList?.contains(\"pie-sr-only\") ||\n\t\tclassList?.contains(\"visually-hidden\")\n\t) {\n\t\treturn true;\n\t}\n\tif (typeof window !== \"undefined\") {\n\t\tconst style = window.getComputedStyle(element);\n\t\tif (style.display === \"none\" || style.visibility === \"hidden\") {\n\t\t\treturn true;\n\t\t}\n\t\tconst width = Number.parseFloat(style.width || \"0\");\n\t\tconst height = Number.parseFloat(style.height || \"0\");\n\t\tconst isTiny =\n\t\t\tNumber.isFinite(width) &&\n\t\t\tNumber.isFinite(height) &&\n\t\t\twidth <= 1 &&\n\t\t\theight <= 1;\n\t\tconst isOffscreenClip =\n\t\t\tstyle.clipPath.includes(\"inset(50%\") ||\n\t\t\tstyle.clipPath.includes(\"inset(100%\") ||\n\t\t\tstyle.clip.includes(\"rect(0px, 0px, 0px, 0px)\") ||\n\t\t\tstyle.clip.includes(\"rect(0 0 0 0)\");\n\t\tif (\n\t\t\t(style.position === \"absolute\" || style.position === \"fixed\") &&\n\t\t\tisTiny &&\n\t\t\t(style.overflow === \"hidden\" || isOffscreenClip)\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t\tif (style.opacity === \"0\" && isTiny) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n};\n\nexport const isNodeHiddenForTTS = (\n\tnode: Node,\n\troot?: Element | null,\n): boolean => {\n\tlet current =\n\t\tnode.nodeType === 1\n\t\t\t? (node as Element)\n\t\t\t: (node.parentElement as Element | null);\n\twhile (current) {\n\t\tif (isElementHiddenForTTS(current)) return true;\n\t\tif (root && current === root) break;\n\t\tcurrent = current.parentElement;\n\t}\n\treturn false;\n};\n\nexport const shouldInsertWordBoundarySpace = (\n\tpreviousChar: string | null,\n\tnextChar: string | null,\n\toptions?: TextProcessingOptions,\n): boolean => {\n\tif (!previousChar || !nextChar) return false;\n\tif (/\\s/.test(previousChar) || /\\s/.test(nextChar)) return false;\n\tconst mode = options?.boundarySpacingMode ?? \"segmenterPreferred\";\n\tif (mode === \"none\") return false;\n\tif (mode === \"segmenterPreferred\") {\n\t\ttry {\n\t\t\tconst Segmenter = globalThis.Intl?.Segmenter;\n\t\t\tif (typeof Segmenter === \"function\") {\n\t\t\t\tconst segmenter = new Segmenter(options?.locale, {\n\t\t\t\t\tgranularity: \"word\",\n\t\t\t\t});\n\t\t\t\tconst segments = Array.from(\n\t\t\t\t\tsegmenter.segment(`${previousChar}${nextChar}`),\n\t\t\t\t);\n\t\t\t\tconst wordLikeCount = segments.filter(\n\t\t\t\t\t(segment) =>\n\t\t\t\t\t\t(segment as { isWordLike?: boolean }).isWordLike !== false &&\n\t\t\t\t\t\tsegment.segment.trim().length > 0,\n\t\t\t\t).length;\n\t\t\t\tif (wordLikeCount >= 2) return true;\n\t\t\t}\n\t\t} catch {\n\t\t\t// Fall back to alnum heuristics below.\n\t\t}\n\t}\n\tconst prevIsAlnum = /[A-Za-z0-9]/.test(previousChar);\n\tconst nextIsAlnum = /[A-Za-z0-9]/.test(nextChar);\n\treturn prevIsAlnum && nextIsAlnum;\n};\n\nexport const collectVisibleTextAndMap = (\n\telement: Element,\n\toptions?: TextProcessingOptions,\n): { text: string; map: NormalizedTextMap } => {\n\tconst map: NormalizedTextMap = new Map();\n\tif (\n\t\ttypeof document === \"undefined\" ||\n\t\ttypeof (document as { createTreeWalker?: unknown }).createTreeWalker !==\n\t\t\t\"function\" ||\n\t\ttypeof NodeFilter === \"undefined\"\n\t) {\n\t\treturn { text: \"\", map };\n\t}\n\tconst outChars: string[] = [];\n\tlet outPos = 0;\n\tlet inLeadingWhitespace = true;\n\tlet lastCharWasWhitespace = false;\n\tlet lastMapped: { node: Text; offset: number } | null = null;\n\tlet previousVisibleChar: string | null = null;\n\n\tconst walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT);\n\tlet current = walker.nextNode();\n\twhile (current) {\n\t\tconst textNode = current as Text;\n\t\tconst parent = textNode.parentElement;\n\t\tif (parent && !isNodeHiddenForTTS(textNode, element)) {\n\t\t\tconst raw = textNode.textContent || \"\";\n\t\t\tconst firstVisibleMatch = raw.match(/\\S/);\n\t\t\tconst firstVisibleChar = firstVisibleMatch ? firstVisibleMatch[0] : null;\n\n\t\t\tif (\n\t\t\t\t!inLeadingWhitespace &&\n\t\t\t\t!lastCharWasWhitespace &&\n\t\t\t\tshouldInsertWordBoundarySpace(\n\t\t\t\t\tpreviousVisibleChar,\n\t\t\t\t\tfirstVisibleChar,\n\t\t\t\t\toptions,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\toutChars.push(\" \");\n\t\t\t\tif (lastMapped) {\n\t\t\t\t\tmap.set(outPos, lastMapped);\n\t\t\t\t}\n\t\t\t\toutPos++;\n\t\t\t\tlastCharWasWhitespace = true;\n\t\t\t}\n\n\t\t\tfor (let i = 0; i < raw.length; i++) {\n\t\t\t\tconst ch = raw[i];\n\t\t\t\tconst isWhitespace = /\\s/.test(ch);\n\n\t\t\t\tif (inLeadingWhitespace) {\n\t\t\t\t\tif (!isWhitespace) {\n\t\t\t\t\t\tinLeadingWhitespace = false;\n\t\t\t\t\t\toutChars.push(ch);\n\t\t\t\t\t\tmap.set(outPos, { node: textNode, offset: i });\n\t\t\t\t\t\tlastMapped = { node: textNode, offset: i };\n\t\t\t\t\t\toutPos++;\n\t\t\t\t\t\tlastCharWasWhitespace = false;\n\t\t\t\t\t\tpreviousVisibleChar = ch;\n\t\t\t\t\t}\n\t\t\t\t} else if (isWhitespace) {\n\t\t\t\t\tif (!lastCharWasWhitespace) {\n\t\t\t\t\t\toutChars.push(\" \");\n\t\t\t\t\t\tmap.set(outPos, { node: textNode, offset: i });\n\t\t\t\t\t\tlastMapped = { node: textNode, offset: i };\n\t\t\t\t\t\toutPos++;\n\t\t\t\t\t}\n\t\t\t\t\tlastCharWasWhitespace = true;\n\t\t\t\t} else {\n\t\t\t\t\toutChars.push(ch);\n\t\t\t\t\tmap.set(outPos, { node: textNode, offset: i });\n\t\t\t\t\tlastMapped = { node: textNode, offset: i };\n\t\t\t\t\toutPos++;\n\t\t\t\t\tlastCharWasWhitespace = false;\n\t\t\t\t\tpreviousVisibleChar = ch;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcurrent = walker.nextNode();\n\t}\n\n\tconst text = outChars.join(\"\").trimEnd();\n\twhile (map.has(text.length)) {\n\t\tmap.delete(text.length);\n\t}\n\treturn { text, map };\n};\n\nexport const extractVisibleText = (\n\telement: Element,\n\toptions?: TextProcessingOptions,\n): string => collectVisibleTextAndMap(element, options).text;\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { TTSConfig } from "./TTSService.js";
|
|
2
2
|
import type { ToolProviderConfig } from "./tools-config-normalizer.js";
|
|
3
|
+
import { type SREMathSpeechOptions } from "./tts/math-speech.js";
|
|
3
4
|
export type TTSLayoutMode = "reserved-row" | "expanding-row" | "floating-overlay" | "left-aligned";
|
|
4
5
|
export interface TTSHostToolbarLayout {
|
|
5
6
|
mount: "before-buttons";
|
|
@@ -37,6 +38,21 @@ export interface TTSRuntimeSettings {
|
|
|
37
38
|
*/
|
|
38
39
|
speedOptions?: number[];
|
|
39
40
|
layoutMode?: TTSLayoutMode;
|
|
41
|
+
/**
|
|
42
|
+
* Per-token highlighting of math expressions.
|
|
43
|
+
* - `true` / omitted (default): when the spoken math aligns confidently to the
|
|
44
|
+
* rendered MathML, the formula is highlighted glyph by glyph; otherwise it
|
|
45
|
+
* safely falls back to a whole-formula block.
|
|
46
|
+
* - `false`: every formula is highlighted as a single block (the fallback),
|
|
47
|
+
* never broken into per-token highlights. Prose word tracking is unaffected.
|
|
48
|
+
*/
|
|
49
|
+
mathTokenHighlighting?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Speech Rule Engine options for generated MathML speech. Hosts can use these
|
|
52
|
+
* to tune SRE itself (for example ClearSpeak ImpliedTimes/Paren preferences)
|
|
53
|
+
* instead of relying on toolkit-specific speech rewrites.
|
|
54
|
+
*/
|
|
55
|
+
mathSpeech?: SREMathSpeechOptions;
|
|
40
56
|
}
|
|
41
57
|
export declare const normalizeTTSLayoutMode: (value: unknown, fallback?: TTSLayoutMode) => TTSLayoutMode;
|
|
42
58
|
/** Default inline TTS speed button multipliers (excluding 1.0×). */
|
|
@@ -56,7 +72,7 @@ export declare const formatTTSSpeedOptionsAsText: (values: number[]) => string;
|
|
|
56
72
|
* - Non-empty text with no parseable finite numbers → same as invalid-only array config: defaults.
|
|
57
73
|
*/
|
|
58
74
|
export declare const parseTTSSpeedOptionsFromText: (text: string) => number[];
|
|
59
|
-
export declare const resolveTTSRuntimeSettings: (config: ToolProviderConfig | undefined) => TTSRuntimeSettings;
|
|
75
|
+
export declare const resolveTTSRuntimeSettings: (config: ToolProviderConfig | TTSRuntimeSettings | undefined) => TTSRuntimeSettings;
|
|
60
76
|
export declare const resolveTTSBackend: (config: TTSRuntimeSettings) => NonNullable<TTSRuntimeSettings["backend"]>;
|
|
61
77
|
export declare const resolveRuntimeProvider: (config: TTSRuntimeSettings, backend: NonNullable<TTSRuntimeSettings["backend"]>) => TTSRuntimeSettings["serverProvider"];
|
|
62
78
|
export declare const resolveTransportMode: (config: TTSRuntimeSettings, runtimeProvider: TTSRuntimeSettings["serverProvider"]) => NonNullable<TTSRuntimeSettings["transportMode"]>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { normalizeSREMathSpeechOptions, } from "./tts/math-speech.js";
|
|
1
2
|
const VALID_TTS_LAYOUT_MODES = new Set([
|
|
2
3
|
"reserved-row",
|
|
3
4
|
"expanding-row",
|
|
@@ -94,7 +95,7 @@ const applyRuntimeDefaults = (config) => {
|
|
|
94
95
|
};
|
|
95
96
|
export const resolveTTSRuntimeSettings = (config) => {
|
|
96
97
|
const configRecord = toRecord(config);
|
|
97
|
-
const settingsRecord = toRecord(
|
|
98
|
+
const settingsRecord = toRecord(configRecord.settings);
|
|
98
99
|
return applyRuntimeDefaults({
|
|
99
100
|
...configRecord,
|
|
100
101
|
...settingsRecord,
|
|
@@ -114,6 +115,7 @@ export const buildRuntimeTTSConfig = (config) => {
|
|
|
114
115
|
const backend = resolveTTSBackend(config);
|
|
115
116
|
const runtimeProvider = resolveRuntimeProvider(config, backend);
|
|
116
117
|
const transportMode = resolveTransportMode(config, runtimeProvider);
|
|
118
|
+
const mathSpeech = normalizeSREMathSpeechOptions(config.mathSpeech);
|
|
117
119
|
return {
|
|
118
120
|
voice: config.defaultVoice,
|
|
119
121
|
rate: config.rate,
|
|
@@ -141,6 +143,7 @@ export const buildRuntimeTTSConfig = (config) => {
|
|
|
141
143
|
...(transportMode === "custom" && config.lang_id
|
|
142
144
|
? { lang_id: config.lang_id }
|
|
143
145
|
: {}),
|
|
146
|
+
...(mathSpeech ? { mathSpeech } : {}),
|
|
144
147
|
},
|
|
145
148
|
apiEndpoint: config.apiEndpoint,
|
|
146
149
|
provider: runtimeProvider,
|
|
@@ -150,6 +153,13 @@ export const buildRuntimeTTSConfig = (config) => {
|
|
|
150
153
|
endpointValidationMode: config.endpointValidationMode,
|
|
151
154
|
includeAuthOnAssetFetch: config.includeAuthOnAssetFetch,
|
|
152
155
|
validateEndpoint: config.validateEndpoint,
|
|
156
|
+
// Toolkit-level highlight setting carried through the config channel
|
|
157
|
+
// (like apiEndpoint/transportMode); consumed by the highlight pipeline,
|
|
158
|
+
// ignored by providers. Only forwarded when set so the pipeline default
|
|
159
|
+
// (per-token enabled) applies otherwise.
|
|
160
|
+
...(typeof config.mathTokenHighlighting === "boolean"
|
|
161
|
+
? { mathTokenHighlighting: config.mathTokenHighlighting }
|
|
162
|
+
: {}),
|
|
153
163
|
};
|
|
154
164
|
};
|
|
155
165
|
export const resolveTTSLayoutMode = (config) => normalizeTTSLayoutMode(config.layoutMode);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tts-runtime-config.js","sourceRoot":"","sources":["../../src/services/tts-runtime-config.ts"],"names":[],"mappings":"AASA,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAgB;IACrD,cAAc;IACd,eAAe;IACf,kBAAkB;IAClB,cAAc;CACd,CAAC,CAAC;AAyCH,MAAM,QAAQ,GAAG,CAAC,KAAc,EAA2B,EAAE,CAC5D,KAAK,IAAI,OAAO,KAAK,KAA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,EAAE,KAAK;oBACnB,oBAAoB,EAAE,KAAK;iBAC3B;aACD,CAAC;IACJ,CAAC;AACF,CAAC,CAAC","sourcesContent":["import type { TTSConfig } from \"./TTSService.js\";\nimport type { ToolProviderConfig } from \"./tools-config-normalizer.js\";\n\nexport type TTSLayoutMode =\n\t| \"reserved-row\"\n\t| \"expanding-row\"\n\t| \"floating-overlay\"\n\t| \"left-aligned\";\n\nconst VALID_TTS_LAYOUT_MODES = new Set<TTSLayoutMode>([\n\t\"reserved-row\",\n\t\"expanding-row\",\n\t\"floating-overlay\",\n\t\"left-aligned\",\n]);\n\nexport interface TTSHostToolbarLayout {\n\tmount: \"before-buttons\";\n\tcontrolsRow: {\n\t\treserveSpace: boolean;\n\t\texpandWhenToolActive: boolean;\n\t};\n}\n\nexport interface TTSRuntimeSettings {\n\tbackend?: \"browser\" | \"polly\" | \"google\" | \"server\";\n\tserverProvider?: \"polly\" | \"google\" | \"custom\";\n\tprovider?: \"polly\" | \"google\" | \"custom\";\n\tengine?: \"standard\" | \"neural\";\n\tsampleRate?: number;\n\tformat?: \"mp3\" | \"ogg\" | \"pcm\";\n\tspeechMarksMode?: \"word\" | \"word+sentence\";\n\tdefaultVoice?: string;\n\trate?: number;\n\tpitch?: number;\n\tapiEndpoint?: string;\n\tlanguage?: string;\n\ttransportMode?: \"pie\" | \"custom\";\n\tendpointMode?: \"synthesizePath\" | \"rootPost\";\n\tendpointValidationMode?: \"voices\" | \"endpoint\" | \"none\";\n\tincludeAuthOnAssetFetch?: boolean;\n\tvalidateEndpoint?: boolean;\n\tcache?: boolean;\n\tspeedRate?: \"slow\" | \"medium\" | \"fast\";\n\tlang_id?: string;\n\t/**\n\t * Optional inline TTS speed buttons.\n\t * - Omitted/non-array: default speed buttons are shown.\n\t * - Empty array: hide speed buttons.\n\t * - Arrays that sanitize to no valid values: default speed buttons are shown.\n\t */\n\tspeedOptions?: number[];\n\tlayoutMode?: TTSLayoutMode;\n}\n\nconst toRecord = (value: unknown): Record<string, unknown> =>\n\tvalue && typeof value === \"object\" ? (value as Record<string, unknown>) : {};\n\nconst isServerBackend = (\n\tbackend: TTSRuntimeSettings[\"backend\"],\n): backend is \"polly\" | \"google\" | \"server\" =>\n\tbackend === \"polly\" || backend === \"google\" || backend === \"server\";\n\nconst withDefault = <T>(value: T | undefined, fallback: T): T =>\n\tvalue === undefined ? fallback : value;\n\nexport const normalizeTTSLayoutMode = (\n\tvalue: unknown,\n\tfallback: TTSLayoutMode = \"left-aligned\",\n): TTSLayoutMode =>\n\ttypeof value === \"string\" &&\n\tVALID_TTS_LAYOUT_MODES.has(value as TTSLayoutMode)\n\t\t? (value as TTSLayoutMode)\n\t\t: fallback;\n\n/** Default inline TTS speed button multipliers (excluding 1.0×). */\nexport const DEFAULT_TTS_SPEED_OPTIONS = Object.freeze([0.8, 1.25]);\n\n/**\n * Resolves inline toolbar speed options from host config.\n * - Omitted/non-array: default speed buttons.\n * - Empty array: hide speed buttons.\n * - Arrays that sanitize to no valid values: default speed buttons.\n * - 1.0× is never shown as a discrete speed button.\n */\nexport const normalizeTTSSpeedOptions = (value: unknown): number[] => {\n\tif (!Array.isArray(value)) return [...DEFAULT_TTS_SPEED_OPTIONS];\n\tif (value.length === 0) return [];\n\tconst deduped = new Set<number>();\n\tfor (const entry of value) {\n\t\tif (typeof entry !== \"number\" || !Number.isFinite(entry) || entry <= 0) continue;\n\t\tconst rounded = Math.round(entry * 100) / 100;\n\t\tif (rounded === 1) continue;\n\t\tdeduped.add(rounded);\n\t}\n\treturn deduped.size ? Array.from(deduped) : [...DEFAULT_TTS_SPEED_OPTIONS];\n};\n\nexport const formatTTSSpeedOptionsAsText = (values: number[]): string =>\n\tvalues.join(\", \");\n\n/**\n * Parse comma/semicolon-separated multipliers from settings UI text.\n * - Empty or whitespace-only string → hide speed buttons (`[]`).\n * - Non-empty text with no parseable finite numbers → same as invalid-only array config: defaults.\n */\nexport const parseTTSSpeedOptionsFromText = (text: string): number[] => {\n\tconst trimmed = text.trim();\n\tif (!trimmed) return [];\n\tconst parts = trimmed\n\t\t.split(/[,;]+/)\n\t\t.map((p) => p.trim())\n\t\t.filter(Boolean);\n\tconst candidates = parts\n\t\t.map((p) => Number.parseFloat(p))\n\t\t.filter((n) => Number.isFinite(n));\n\tif (!candidates.length) return [...DEFAULT_TTS_SPEED_OPTIONS];\n\treturn normalizeTTSSpeedOptions(candidates);\n};\n\nconst applyRuntimeDefaults = (\n\tconfig: TTSRuntimeSettings,\n): TTSRuntimeSettings => {\n\tconst withLayoutDefaults: TTSRuntimeSettings = {\n\t\t...config,\n\t\tlayoutMode: normalizeTTSLayoutMode(config.layoutMode),\n\t};\n\tconst backend = config.backend || \"browser\";\n\tif (!isServerBackend(backend)) return withLayoutDefaults;\n\n\tconst withServerDefaults: TTSRuntimeSettings = {\n\t\t...withLayoutDefaults,\n\t\tapiEndpoint: withDefault(withLayoutDefaults.apiEndpoint, \"/api/tts\"),\n\t\ttransportMode: withDefault(withLayoutDefaults.transportMode, \"pie\"),\n\t\tendpointValidationMode: withDefault(\n\t\t\twithLayoutDefaults.endpointValidationMode,\n\t\t\t\"voices\",\n\t\t),\n\t\tvalidateEndpoint: withDefault(withLayoutDefaults.validateEndpoint, true),\n\t\tincludeAuthOnAssetFetch: withDefault(\n\t\t\twithLayoutDefaults.includeAuthOnAssetFetch,\n\t\t\tfalse,\n\t\t),\n\t\trate: withDefault(withLayoutDefaults.rate, 1.0),\n\t\tlanguage: withDefault(withLayoutDefaults.language, \"en-US\"),\n\t};\n\n\tif (backend === \"polly\") {\n\t\treturn {\n\t\t\t...withServerDefaults,\n\t\t\tdefaultVoice: withDefault(withServerDefaults.defaultVoice, \"Joanna\"),\n\t\t\tengine: withDefault(withServerDefaults.engine, \"neural\"),\n\t\t\tformat: withDefault(withServerDefaults.format, \"mp3\"),\n\t\t\tspeechMarksMode: withDefault(\n\t\t\t\twithServerDefaults.speechMarksMode,\n\t\t\t\t\"word+sentence\",\n\t\t\t),\n\t\t};\n\t}\n\n\tif (backend === \"google\") {\n\t\treturn {\n\t\t\t...withServerDefaults,\n\t\t\tdefaultVoice: withDefault(withServerDefaults.defaultVoice, \"en-US-Wavenet-A\"),\n\t\t};\n\t}\n\n\treturn withServerDefaults;\n};\n\nexport const resolveTTSRuntimeSettings = (\n\tconfig: ToolProviderConfig | undefined,\n): TTSRuntimeSettings => {\n\tconst configRecord = toRecord(config);\n\tconst settingsRecord = toRecord(config?.settings);\n\treturn applyRuntimeDefaults({\n\t\t...configRecord,\n\t\t...settingsRecord,\n\t} as TTSRuntimeSettings);\n};\n\nexport const resolveTTSBackend = (\n\tconfig: TTSRuntimeSettings,\n): NonNullable<TTSRuntimeSettings[\"backend\"]> => config.backend || \"browser\";\n\nexport const resolveRuntimeProvider = (\n\tconfig: TTSRuntimeSettings,\n\tbackend: NonNullable<TTSRuntimeSettings[\"backend\"]>,\n): TTSRuntimeSettings[\"serverProvider\"] => {\n\tif (backend === \"polly\" || backend === \"google\") return backend;\n\tif (backend === \"server\") {\n\t\treturn config.serverProvider || config.provider;\n\t}\n\treturn config.serverProvider || config.provider;\n};\n\nexport const resolveTransportMode = (\n\tconfig: TTSRuntimeSettings,\n\truntimeProvider: TTSRuntimeSettings[\"serverProvider\"],\n): NonNullable<TTSRuntimeSettings[\"transportMode\"]> =>\n\tconfig.transportMode || (runtimeProvider === \"custom\" ? \"custom\" : \"pie\");\n\nexport const buildRuntimeTTSConfig = (\n\tconfig: TTSRuntimeSettings,\n): Partial<TTSConfig> => {\n\tconst backend = resolveTTSBackend(config);\n\tconst runtimeProvider = resolveRuntimeProvider(config, backend);\n\tconst transportMode = resolveTransportMode(config, runtimeProvider);\n\treturn {\n\t\tvoice: config.defaultVoice,\n\t\trate: config.rate,\n\t\tpitch: config.pitch,\n\t\tproviderOptions: {\n\t\t\t...(config.language ? { locale: config.language } : {}),\n\t\t\t...(backend === \"polly\" && config.engine ? { engine: config.engine } : {}),\n\t\t\t...(backend === \"polly\" && typeof config.sampleRate === \"number\"\n\t\t\t\t? { sampleRate: config.sampleRate }\n\t\t\t\t: {}),\n\t\t\t...(backend === \"polly\" && config.format ? { format: config.format } : {}),\n\t\t\t...(backend === \"polly\"\n\t\t\t\t? {\n\t\t\t\t\t\tspeechMarkTypes:\n\t\t\t\t\t\t\tconfig.speechMarksMode === \"word+sentence\"\n\t\t\t\t\t\t\t\t? [\"word\", \"sentence\"]\n\t\t\t\t\t\t\t\t: [\"word\"],\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\t...(transportMode === \"custom\" && typeof config.cache === \"boolean\"\n\t\t\t\t? { cache: config.cache }\n\t\t\t\t: {}),\n\t\t\t...(transportMode === \"custom\" && config.speedRate\n\t\t\t\t? { speedRate: config.speedRate }\n\t\t\t\t: {}),\n\t\t\t...(transportMode === \"custom\" && config.lang_id\n\t\t\t\t? { lang_id: config.lang_id }\n\t\t\t\t: {}),\n\t\t},\n\t\tapiEndpoint: config.apiEndpoint,\n\t\tprovider: runtimeProvider,\n\t\tlanguage: config.language,\n\t\ttransportMode,\n\t\tendpointMode: config.endpointMode,\n\t\tendpointValidationMode: config.endpointValidationMode,\n\t\tincludeAuthOnAssetFetch: config.includeAuthOnAssetFetch,\n\t\tvalidateEndpoint: config.validateEndpoint,\n\t} as Partial<TTSConfig>;\n};\n\nexport const resolveTTSLayoutMode = (\n\tconfig: TTSRuntimeSettings,\n): TTSLayoutMode => normalizeTTSLayoutMode(config.layoutMode);\n\nexport const resolveTTSHostToolbarLayout = (\n\tconfig: TTSRuntimeSettings,\n): TTSHostToolbarLayout => {\n\tconst layoutMode = resolveTTSLayoutMode(config);\n\tswitch (layoutMode) {\n\t\tcase \"reserved-row\":\n\t\t\treturn {\n\t\t\t\tmount: \"before-buttons\",\n\t\t\t\tcontrolsRow: {\n\t\t\t\t\treserveSpace: true,\n\t\t\t\t\texpandWhenToolActive: false,\n\t\t\t\t},\n\t\t\t};\n\t\tcase \"expanding-row\":\n\t\t\treturn {\n\t\t\t\tmount: \"before-buttons\",\n\t\t\t\tcontrolsRow: {\n\t\t\t\t\treserveSpace: false,\n\t\t\t\t\texpandWhenToolActive: true,\n\t\t\t\t},\n\t\t\t};\n\t\tcase \"floating-overlay\":\n\t\tcase \"left-aligned\":\n\t\tdefault:\n\t\t\treturn {\n\t\t\t\tmount: \"before-buttons\",\n\t\t\t\tcontrolsRow: {\n\t\t\t\t\treserveSpace: false,\n\t\t\t\t\texpandWhenToolActive: false,\n\t\t\t\t},\n\t\t\t};\n\t}\n};\n"]}
|
|
1
|
+
{"version":3,"file":"tts-runtime-config.js","sourceRoot":"","sources":["../../src/services/tts-runtime-config.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,6BAA6B,GAE7B,MAAM,sBAAsB,CAAC;AAQ9B,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAgB;IACrD,cAAc;IACd,eAAe;IACf,kBAAkB;IAClB,cAAc;CACd,CAAC,CAAC;AAwDH,MAAM,QAAQ,GAAG,CAAC,KAAc,EAA2B,EAAE,CAC5D,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAE,KAAiC,CAAC,CAAC,CAAC,EAAE,CAAC;AAE9E,MAAM,eAAe,GAAG,CACvB,OAAsC,EACK,EAAE,CAC7C,OAAO,KAAK,OAAO,IAAI,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,QAAQ,CAAC;AAErE,MAAM,WAAW,GAAG,CAAI,KAAoB,EAAE,QAAW,EAAK,EAAE,CAC/D,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC;AAExC,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACrC,KAAc,EACd,WAA0B,cAAc,EACxB,EAAE,CAClB,OAAO,KAAK,KAAK,QAAQ;IACzB,sBAAsB,CAAC,GAAG,CAAC,KAAsB,CAAC;IACjD,CAAC,CAAE,KAAuB;IAC1B,CAAC,CAAC,QAAQ,CAAC;AAEb,oEAAoE;AACpE,MAAM,CAAC,M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BAAsB;QACrD,uBAAuB,EAAE,MAAM,CAAC,uBAAuB;QACvD,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;QACzC,qEAAqE;QACrE,wEAAwE;QACxE,wEAAwE;QACxE,yCAAyC;QACzC,GAAG,CAAC,OAAO,MAAM,CAAC,qBAAqB,KAAK,SAAS;YACpD,CAAC,CAAC,EAAE,qBAAqB,EAAE,MAAM,CAAC,qBAAqB,EAAE;YACzD,CAAC,CAAC,EAAE,CAAC;KACgB,CAAC;AACzB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CACnC,MAA0B,EACV,EAAE,CAAC,sBAAsB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AAE9D,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAC1C,MAA0B,EACH,EAAE;IACzB,MAAM,UAAU,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAChD,QAAQ,UAAU,EAAE,CAAC;QACpB,KAAK,cAAc;YAClB,OAAO;gBACN,KAAK,EAAE,gBAAgB;gBACvB,WAAW,EAAE;oBACZ,YAAY,EAAE,IAAI;oBAClB,oBAAoB,EAAE,KAAK;iBAC3B;aACD,CAAC;QACH,KAAK,eAAe;YACnB,OAAO;gBACN,KAAK,EAAE,gBAAgB;gBACvB,WAAW,EAAE;oBACZ,YAAY,EAAE,KAAK;oBACnB,oBAAoB,EAAE,IAAI;iBAC1B;aACD,CAAC;QACH,KAAK,kBAAkB,CAAC;QACxB,KAAK,cAAc,CAAC;QACpB;YACC,OAAO;gBACN,KAAK,EAAE,gBAAgB;gBACvB,WAAW,EAAE;oBACZ,YAAY,EAAE,KAAK;oBACnB,oBAAoB,EAAE,KAAK;iBAC3B;aACD,CAAC;IACJ,CAAC;AACF,CAAC,CAAC","sourcesContent":["import type { TTSConfig } from \"./TTSService.js\";\nimport type { ToolProviderConfig } from \"./tools-config-normalizer.js\";\nimport {\n\tnormalizeSREMathSpeechOptions,\n\ttype SREMathSpeechOptions,\n} from \"./tts/math-speech.js\";\n\nexport type TTSLayoutMode =\n\t| \"reserved-row\"\n\t| \"expanding-row\"\n\t| \"floating-overlay\"\n\t| \"left-aligned\";\n\nconst VALID_TTS_LAYOUT_MODES = new Set<TTSLayoutMode>([\n\t\"reserved-row\",\n\t\"expanding-row\",\n\t\"floating-overlay\",\n\t\"left-aligned\",\n]);\n\nexport interface TTSHostToolbarLayout {\n\tmount: \"before-buttons\";\n\tcontrolsRow: {\n\t\treserveSpace: boolean;\n\t\texpandWhenToolActive: boolean;\n\t};\n}\n\nexport interface TTSRuntimeSettings {\n\tbackend?: \"browser\" | \"polly\" | \"google\" | \"server\";\n\tserverProvider?: \"polly\" | \"google\" | \"custom\";\n\tprovider?: \"polly\" | \"google\" | \"custom\";\n\tengine?: \"standard\" | \"neural\";\n\tsampleRate?: number;\n\tformat?: \"mp3\" | \"ogg\" | \"pcm\";\n\tspeechMarksMode?: \"word\" | \"word+sentence\";\n\tdefaultVoice?: string;\n\trate?: number;\n\tpitch?: number;\n\tapiEndpoint?: string;\n\tlanguage?: string;\n\ttransportMode?: \"pie\" | \"custom\";\n\tendpointMode?: \"synthesizePath\" | \"rootPost\";\n\tendpointValidationMode?: \"voices\" | \"endpoint\" | \"none\";\n\tincludeAuthOnAssetFetch?: boolean;\n\tvalidateEndpoint?: boolean;\n\tcache?: boolean;\n\tspeedRate?: \"slow\" | \"medium\" | \"fast\";\n\tlang_id?: string;\n\t/**\n\t * Optional inline TTS speed buttons.\n\t * - Omitted/non-array: default speed buttons are shown.\n\t * - Empty array: hide speed buttons.\n\t * - Arrays that sanitize to no valid values: default speed buttons are shown.\n\t */\n\tspeedOptions?: number[];\n\tlayoutMode?: TTSLayoutMode;\n\t/**\n\t * Per-token highlighting of math expressions.\n\t * - `true` / omitted (default): when the spoken math aligns confidently to the\n\t * rendered MathML, the formula is highlighted glyph by glyph; otherwise it\n\t * safely falls back to a whole-formula block.\n\t * - `false`: every formula is highlighted as a single block (the fallback),\n\t * never broken into per-token highlights. Prose word tracking is unaffected.\n\t */\n\tmathTokenHighlighting?: boolean;\n\t/**\n\t * Speech Rule Engine options for generated MathML speech. Hosts can use these\n\t * to tune SRE itself (for example ClearSpeak ImpliedTimes/Paren preferences)\n\t * instead of relying on toolkit-specific speech rewrites.\n\t */\n\tmathSpeech?: SREMathSpeechOptions;\n}\n\nconst toRecord = (value: unknown): Record<string, unknown> =>\n\tvalue && typeof value === \"object\" ? (value as Record<string, unknown>) : {};\n\nconst isServerBackend = (\n\tbackend: TTSRuntimeSettings[\"backend\"],\n): backend is \"polly\" | \"google\" | \"server\" =>\n\tbackend === \"polly\" || backend === \"google\" || backend === \"server\";\n\nconst withDefault = <T>(value: T | undefined, fallback: T): T =>\n\tvalue === undefined ? fallback : value;\n\nexport const normalizeTTSLayoutMode = (\n\tvalue: unknown,\n\tfallback: TTSLayoutMode = \"left-aligned\",\n): TTSLayoutMode =>\n\ttypeof value === \"string\" &&\n\tVALID_TTS_LAYOUT_MODES.has(value as TTSLayoutMode)\n\t\t? (value as TTSLayoutMode)\n\t\t: fallback;\n\n/** Default inline TTS speed button multipliers (excluding 1.0×). */\nexport const DEFAULT_TTS_SPEED_OPTIONS = Object.freeze([0.8, 1.25]);\n\n/**\n * Resolves inline toolbar speed options from host config.\n * - Omitted/non-array: default speed buttons.\n * - Empty array: hide speed buttons.\n * - Arrays that sanitize to no valid values: default speed buttons.\n * - 1.0× is never shown as a discrete speed button.\n */\nexport const normalizeTTSSpeedOptions = (value: unknown): number[] => {\n\tif (!Array.isArray(value)) return [...DEFAULT_TTS_SPEED_OPTIONS];\n\tif (value.length === 0) return [];\n\tconst deduped = new Set<number>();\n\tfor (const entry of value) {\n\t\tif (typeof entry !== \"number\" || !Number.isFinite(entry) || entry <= 0) continue;\n\t\tconst rounded = Math.round(entry * 100) / 100;\n\t\tif (rounded === 1) continue;\n\t\tdeduped.add(rounded);\n\t}\n\treturn deduped.size ? Array.from(deduped) : [...DEFAULT_TTS_SPEED_OPTIONS];\n};\n\nexport const formatTTSSpeedOptionsAsText = (values: number[]): string =>\n\tvalues.join(\", \");\n\n/**\n * Parse comma/semicolon-separated multipliers from settings UI text.\n * - Empty or whitespace-only string → hide speed buttons (`[]`).\n * - Non-empty text with no parseable finite numbers → same as invalid-only array config: defaults.\n */\nexport const parseTTSSpeedOptionsFromText = (text: string): number[] => {\n\tconst trimmed = text.trim();\n\tif (!trimmed) return [];\n\tconst parts = trimmed\n\t\t.split(/[,;]+/)\n\t\t.map((p) => p.trim())\n\t\t.filter(Boolean);\n\tconst candidates = parts\n\t\t.map((p) => Number.parseFloat(p))\n\t\t.filter((n) => Number.isFinite(n));\n\tif (!candidates.length) return [...DEFAULT_TTS_SPEED_OPTIONS];\n\treturn normalizeTTSSpeedOptions(candidates);\n};\n\nconst applyRuntimeDefaults = (\n\tconfig: TTSRuntimeSettings,\n): TTSRuntimeSettings => {\n\tconst withLayoutDefaults: TTSRuntimeSettings = {\n\t\t...config,\n\t\tlayoutMode: normalizeTTSLayoutMode(config.layoutMode),\n\t};\n\tconst backend = config.backend || \"browser\";\n\tif (!isServerBackend(backend)) return withLayoutDefaults;\n\n\tconst withServerDefaults: TTSRuntimeSettings = {\n\t\t...withLayoutDefaults,\n\t\tapiEndpoint: withDefault(withLayoutDefaults.apiEndpoint, \"/api/tts\"),\n\t\ttransportMode: withDefault(withLayoutDefaults.transportMode, \"pie\"),\n\t\tendpointValidationMode: withDefault(\n\t\t\twithLayoutDefaults.endpointValidationMode,\n\t\t\t\"voices\",\n\t\t),\n\t\tvalidateEndpoint: withDefault(withLayoutDefaults.validateEndpoint, true),\n\t\tincludeAuthOnAssetFetch: withDefault(\n\t\t\twithLayoutDefaults.includeAuthOnAssetFetch,\n\t\t\tfalse,\n\t\t),\n\t\trate: withDefault(withLayoutDefaults.rate, 1.0),\n\t\tlanguage: withDefault(withLayoutDefaults.language, \"en-US\"),\n\t};\n\n\tif (backend === \"polly\") {\n\t\treturn {\n\t\t\t...withServerDefaults,\n\t\t\tdefaultVoice: withDefault(withServerDefaults.defaultVoice, \"Joanna\"),\n\t\t\tengine: withDefault(withServerDefaults.engine, \"neural\"),\n\t\t\tformat: withDefault(withServerDefaults.format, \"mp3\"),\n\t\t\tspeechMarksMode: withDefault(\n\t\t\t\twithServerDefaults.speechMarksMode,\n\t\t\t\t\"word+sentence\",\n\t\t\t),\n\t\t};\n\t}\n\n\tif (backend === \"google\") {\n\t\treturn {\n\t\t\t...withServerDefaults,\n\t\t\tdefaultVoice: withDefault(withServerDefaults.defaultVoice, \"en-US-Wavenet-A\"),\n\t\t};\n\t}\n\n\treturn withServerDefaults;\n};\n\nexport const resolveTTSRuntimeSettings = (\n\tconfig: ToolProviderConfig | TTSRuntimeSettings | undefined,\n): TTSRuntimeSettings => {\n\tconst configRecord = toRecord(config);\n\tconst settingsRecord = toRecord(configRecord.settings);\n\treturn applyRuntimeDefaults({\n\t\t...configRecord,\n\t\t...settingsRecord,\n\t} as TTSRuntimeSettings);\n};\n\nexport const resolveTTSBackend = (\n\tconfig: TTSRuntimeSettings,\n): NonNullable<TTSRuntimeSettings[\"backend\"]> => config.backend || \"browser\";\n\nexport const resolveRuntimeProvider = (\n\tconfig: TTSRuntimeSettings,\n\tbackend: NonNullable<TTSRuntimeSettings[\"backend\"]>,\n): TTSRuntimeSettings[\"serverProvider\"] => {\n\tif (backend === \"polly\" || backend === \"google\") return backend;\n\tif (backend === \"server\") {\n\t\treturn config.serverProvider || config.provider;\n\t}\n\treturn config.serverProvider || config.provider;\n};\n\nexport const resolveTransportMode = (\n\tconfig: TTSRuntimeSettings,\n\truntimeProvider: TTSRuntimeSettings[\"serverProvider\"],\n): NonNullable<TTSRuntimeSettings[\"transportMode\"]> =>\n\tconfig.transportMode || (runtimeProvider === \"custom\" ? \"custom\" : \"pie\");\n\nexport const buildRuntimeTTSConfig = (\n\tconfig: TTSRuntimeSettings,\n): Partial<TTSConfig> => {\n\tconst backend = resolveTTSBackend(config);\n\tconst runtimeProvider = resolveRuntimeProvider(config, backend);\n\tconst transportMode = resolveTransportMode(config, runtimeProvider);\n\tconst mathSpeech = normalizeSREMathSpeechOptions(config.mathSpeech);\n\treturn {\n\t\tvoice: config.defaultVoice,\n\t\trate: config.rate,\n\t\tpitch: config.pitch,\n\t\tproviderOptions: {\n\t\t\t...(config.language ? { locale: config.language } : {}),\n\t\t\t...(backend === \"polly\" && config.engine ? { engine: config.engine } : {}),\n\t\t\t...(backend === \"polly\" && typeof config.sampleRate === \"number\"\n\t\t\t\t? { sampleRate: config.sampleRate }\n\t\t\t\t: {}),\n\t\t\t...(backend === \"polly\" && config.format ? { format: config.format } : {}),\n\t\t\t...(backend === \"polly\"\n\t\t\t\t? {\n\t\t\t\t\t\tspeechMarkTypes:\n\t\t\t\t\t\t\tconfig.speechMarksMode === \"word+sentence\"\n\t\t\t\t\t\t\t\t? [\"word\", \"sentence\"]\n\t\t\t\t\t\t\t\t: [\"word\"],\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\t...(transportMode === \"custom\" && typeof config.cache === \"boolean\"\n\t\t\t\t? { cache: config.cache }\n\t\t\t\t: {}),\n\t\t\t...(transportMode === \"custom\" && config.speedRate\n\t\t\t\t? { speedRate: config.speedRate }\n\t\t\t\t: {}),\n\t\t\t...(transportMode === \"custom\" && config.lang_id\n\t\t\t\t? { lang_id: config.lang_id }\n\t\t\t\t: {}),\n\t\t\t...(mathSpeech ? { mathSpeech } : {}),\n\t\t},\n\t\tapiEndpoint: config.apiEndpoint,\n\t\tprovider: runtimeProvider,\n\t\tlanguage: config.language,\n\t\ttransportMode,\n\t\tendpointMode: config.endpointMode,\n\t\tendpointValidationMode: config.endpointValidationMode,\n\t\tincludeAuthOnAssetFetch: config.includeAuthOnAssetFetch,\n\t\tvalidateEndpoint: config.validateEndpoint,\n\t\t// Toolkit-level highlight setting carried through the config channel\n\t\t// (like apiEndpoint/transportMode); consumed by the highlight pipeline,\n\t\t// ignored by providers. Only forwarded when set so the pipeline default\n\t\t// (per-token enabled) applies otherwise.\n\t\t...(typeof config.mathTokenHighlighting === \"boolean\"\n\t\t\t? { mathTokenHighlighting: config.mathTokenHighlighting }\n\t\t\t: {}),\n\t} as Partial<TTSConfig>;\n};\n\nexport const resolveTTSLayoutMode = (\n\tconfig: TTSRuntimeSettings,\n): TTSLayoutMode => normalizeTTSLayoutMode(config.layoutMode);\n\nexport const resolveTTSHostToolbarLayout = (\n\tconfig: TTSRuntimeSettings,\n): TTSHostToolbarLayout => {\n\tconst layoutMode = resolveTTSLayoutMode(config);\n\tswitch (layoutMode) {\n\t\tcase \"reserved-row\":\n\t\t\treturn {\n\t\t\t\tmount: \"before-buttons\",\n\t\t\t\tcontrolsRow: {\n\t\t\t\t\treserveSpace: true,\n\t\t\t\t\texpandWhenToolActive: false,\n\t\t\t\t},\n\t\t\t};\n\t\tcase \"expanding-row\":\n\t\t\treturn {\n\t\t\t\tmount: \"before-buttons\",\n\t\t\t\tcontrolsRow: {\n\t\t\t\t\treserveSpace: false,\n\t\t\t\t\texpandWhenToolActive: true,\n\t\t\t\t},\n\t\t\t};\n\t\tcase \"floating-overlay\":\n\t\tcase \"left-aligned\":\n\t\tdefault:\n\t\t\treturn {\n\t\t\t\tmount: \"before-buttons\",\n\t\t\t\tcontrolsRow: {\n\t\t\t\t\treserveSpace: false,\n\t\t\t\t\texpandWhenToolActive: false,\n\t\t\t\t},\n\t\t\t};\n\t}\n};\n"]}
|
|
@@ -94,7 +94,6 @@ export const themeToolRegistration = {
|
|
|
94
94
|
"highContrastDisplay", // QTI 3.0 standard (visual.highContrastDisplay)
|
|
95
95
|
"colorContrast", // QTI 3.0 standard (visual.colorContrast)
|
|
96
96
|
"invertColors", // QTI 3.0 standard (visual.invertColors)
|
|
97
|
-
"colorScheme", // Legacy alias
|
|
98
97
|
"theme", // Canonical id
|
|
99
98
|
"highContrast", // Common variant
|
|
100
99
|
"customColors", // Common variant
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accessibility-tools.js","sourceRoot":"","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,GAAgC;YAC3C,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,KAAK,EAAE,IAAI,CAAC,IAAI;YAChB,IAAI,EAAE,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI;YACtE,QAAQ,EAAE,KAAK;YACf,SAAS,EAAE,qCAAqC;YAChD,OAAO,EAAE,WAAW;YACpB,OAAO,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC;YACrD,MAAM,EAAE,UAAU,CAAC,QAAQ,EAAE;SAC7B,CAAC;QACF,MAAM,kBAAkB,GACtB,cAAc,CAAC,kBAAyD,IAAI,EAAE,CAAC;QACjF,MAAM,OAAO,GAAG,iBAAiB,CAChC,IAAI,CAAC,MAAM,EACX,OAAO,EACP,cAAc,EACd,kBAAkB,CAKlB,CAAC;QACF,OAAO,CAAC,YAAY,CAAC,SAAS,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;QACvD,OAAO;YACN,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,MAAM;YACN,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC;YACxD,IAAI,EAAE,GAAG,EAAE;gBACV,8BAA8B,CAAC;oBAC9B,MAAM;oBACN,OAAO;oBACP,QAAQ,EAAE,UAAU,CAAC,QAAQ;iBAC7B,CAAC,CAAC;gBACH,IAAI,cAAc,CAAC,kBAAkB,EAAE,CAAC;oBACvC,OAAO,CAAC,kBAAkB,GAAG,cAAc,CAAC,kBAAkB,CAAC;gBAChE,CAAC;YACF,CAAC;YACD,eAAe,EAAE,UAAU,CAAC,eAAe;SAC3C,CAAC;IACH,CAAC;CACD,CAAC","sourcesContent":["/**\n * Accessibility Tools Registrations\n *\n * Registers tools for visual accessibility and reading support:\n * - Line Reader (reading guide)\n * - Color Scheme (theme/contrast)\n * - Annotation Toolbar (text highlighting)\n *\n * Maps to QTI 3.0 standard access features from:\n * - visual category: highContrastDisplay, colorContrast\n * - reading category: readingMask, readingGuide, highlighting\n */\n\nimport type {\n\tToolRegistration,\n\tToolToolbarButtonDefinition,\n\tToolToolbarRenderResult,\n\tToolbarContext,\n} from \"../../services/ToolRegistry.js\";\nimport type { ToolContext } from \"../../services/tool-context.js\";\nimport { hasReadableText } from \"../../services/tool-context.js\";\nimport {\n\tcreateToolElement,\n\ttype ToolComponentOverrides,\n} from \"../tool-tag-map.js\";\nimport {\n\tapplyOverlaySurface,\n\tcreateScopedVisibilityBinding,\n\tsyncButtonAndOverlayVisibility,\n} from \"./toolbar-registration-helpers.js\";\n\n/**\n * Line Reader tool registration\n *\n * Provides a reading guide overlay to help track reading position.\n * Useful for text-heavy passages and questions.\n */\nexport const lineReaderToolRegistration: ToolRegistration = {\n\ttoolId: \"lineReader\",\n\tname: \"Line Reader\",\n\tdescription: \"Reading guide overlay\",\n\ticon: \"bars-3\",\n\n\t// Line reader appears where there's text to read\n\tsupportedLevels: [\"section\", \"passage\", \"rubric\", \"item\"],\n\n\t// PNP support IDs\n\t// Maps to QTI 3.0 standard features: readingMask, readingGuide, readingRuler\n\tpnpSupportIds: [\n\t\t\"readingMask\", // QTI 3.0 standard (reading.readingMask)\n\t\t\"readingGuide\", // QTI 3.0 standard (reading.readingGuide)\n\t\t\"readingRuler\", // QTI 3.0 standard (reading.readingRuler)\n\t\t\"lineReader\", // Common variant\n\t\t\"trackingGuide\", // Common variant\n\t],\n\n\t/**\n\t * Pass 2: Line reader is relevant when readable text is present\n\t */\n\tisVisibleInContext(context: ToolContext): boolean {\n\t\treturn hasReadableText(context);\n\t},\n\n\trenderToolbar(\n\t\tcontext: ToolContext,\n\t\ttoolbarContext: ToolbarContext,\n\t): ToolToolbarRenderResult {\n\t\tconst visibility = createScopedVisibilityBinding(this.toolId, toolbarContext);\n\t\tconst button: ToolToolbarButtonDefinition = {\n\t\t\ttoolId: this.toolId,\n\t\t\tlabel: this.name,\n\t\t\ticon: typeof this.icon === \"function\" ? this.icon(context) : this.icon,\n\t\t\tdisabled: false,\n\t\t\tariaLabel: \"Line reader - Reading guide\",\n\t\t\ttooltip: \"Line Reader\",\n\t\t\tonClick: () => toolbarContext.toggleTool(this.toolId),\n\t\t\tactive: visibility.isActive(),\n\t\t};\n\t\tconst componentOverrides =\n\t\t\t(toolbarContext.componentOverrides as ToolComponentOverrides | undefined) ?? {};\n\t\tconst overlay = createToolElement(\n\t\t\tthis.toolId,\n\t\t\tcontext,\n\t\t\ttoolbarContext,\n\t\t\tcomponentOverrides,\n\t\t) as HTMLElement & {\n\t\t\tvisible?: boolean;\n\t\t\ttoolId?: string;\n\t\t\ttoolkitCoordinator: unknown;\n\t\t};\n\t\toverlay.setAttribute(\"tool-id\", visibility.fullToolId);\n\t\tapplyOverlaySurface(overlay, \"frameless\");\n\t\treturn {\n\t\t\ttoolId: this.toolId,\n\t\t\tbutton,\n\t\t\telements: [{ element: overlay, mount: \"after-buttons\" }],\n\t\t\tsync: () => {\n\t\t\t\tsyncButtonAndOverlayVisibility({\n\t\t\t\t\tbutton,\n\t\t\t\t\toverlay,\n\t\t\t\t\tisActive: visibility.isActive,\n\t\t\t\t});\n\t\t\t\tif (toolbarContext.toolkitCoordinator) {\n\t\t\t\t\toverlay.toolkitCoordinator = toolbarContext.toolkitCoordinator;\n\t\t\t\t}\n\t\t\t},\n\t\t\tsubscribeActive: visibility.subscribeActive,\n\t\t};\n\t},\n};\n\n/**\n * Theme tool registration\n *\n * Provides accessible theme and contrast controls.\n * Global tool that affects entire assessment.\n */\nexport const themeToolRegistration: ToolRegistration = {\n\ttoolId: \"theme\",\n\tname: \"Theme\",\n\tdescription: \"Accessible themes and contrast\",\n\ticon: \"swatch\",\n\n\t// Color scheme is assessment-wide\n\tsupportedLevels: [\"assessment\", \"section\"],\n\n\t// PNP support IDs\n\t// Maps to QTI 3.0 standard features: highContrastDisplay, colorContrast, invertColors\n\tpnpSupportIds: [\n\t\t\"highContrastDisplay\", // QTI 3.0 standard (visual.highContrastDisplay)\n\t\t\"colorContrast\", // QTI 3.0 standard (visual.colorContrast)\n\t\t\"invertColors\", // QTI 3.0 standard (visual.invertColors)\n\t\t\"colorScheme\", // Legacy alias\n\t\t\"theme\", // Canonical id\n\t\t\"highContrast\", // Common variant\n\t\t\"customColors\", // Common variant\n\t],\n\n\t/**\n\t * Pass 2: Color scheme is always relevant when allowed\n\t */\n\tisVisibleInContext(context: ToolContext): boolean {\n\t\treturn true; // Always show if allowed by orchestrator\n\t},\n\n\trenderToolbar(\n\t\tcontext: ToolContext,\n\t\ttoolbarContext: ToolbarContext,\n\t): ToolToolbarRenderResult {\n\t\tconst visibility = createScopedVisibilityBinding(this.toolId, toolbarContext);\n\t\tconst button: ToolToolbarButtonDefinition = {\n\t\t\ttoolId: this.toolId,\n\t\t\tlabel: this.name,\n\t\t\ticon: typeof this.icon === \"function\" ? this.icon(context) : this.icon,\n\t\t\tdisabled: false,\n\t\t\tariaLabel: \"Theme - Change colors and contrast\",\n\t\t\ttooltip: \"Theme\",\n\t\t\tonClick: () => toolbarContext.toggleTool(this.toolId),\n\t\t\tactive: visibility.isActive(),\n\t\t};\n\t\tconst componentOverrides =\n\t\t\t(toolbarContext.componentOverrides as ToolComponentOverrides | undefined) ?? {};\n\t\tconst overlay = createToolElement(\n\t\t\tthis.toolId,\n\t\t\tcontext,\n\t\t\ttoolbarContext,\n\t\t\tcomponentOverrides,\n\t\t) as HTMLElement & {\n\t\t\tvisible?: boolean;\n\t\t\ttoolId?: string;\n\t\t\ttoolkitCoordinator: unknown;\n\t\t};\n\t\toverlay.setAttribute(\"tool-id\", visibility.fullToolId);\n\t\treturn {\n\t\t\ttoolId: this.toolId,\n\t\t\tbutton,\n\t\t\telements: [\n\t\t\t\t{\n\t\t\t\t\telement: overlay,\n\t\t\t\t\tmount: \"after-buttons\",\n\t\t\t\t\tshell: {\n\t\t\t\t\t\ttitle: this.name,\n\t\t\t\t\t\tdraggable: true,\n\t\t\t\t\t\tresizable: false,\n\t\t\t\t\t\tcloseable: true,\n\t\t\t\t\t\tinitialWidth: 520,\n\t\t\t\t\t\tinitialHeight: 380,\n\t\t\t\t\t\tminWidth: 420,\n\t\t\t\t\t\tminHeight: 300,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t],\n\t\t\tsync: () => {\n\t\t\t\tsyncButtonAndOverlayVisibility({\n\t\t\t\t\tbutton,\n\t\t\t\t\toverlay,\n\t\t\t\t\tisActive: visibility.isActive,\n\t\t\t\t});\n\t\t\t\tif (toolbarContext.toolkitCoordinator) {\n\t\t\t\t\toverlay.toolkitCoordinator = toolbarContext.toolkitCoordinator;\n\t\t\t\t}\n\t\t\t},\n\t\t\tsubscribeActive: visibility.subscribeActive,\n\t\t};\n\t},\n};\n\n/**\n * Annotation Toolbar registration\n *\n * Text highlighting with CSS Custom Highlight API.\n * Zero DOM mutation, optimal performance.\n */\nexport const annotationToolbarRegistration: ToolRegistration = {\n\ttoolId: \"annotationToolbar\",\n\tname: \"Highlighter\",\n\tdescription: \"Highlight and annotate text\",\n\ticon: \"highlighter\",\n\tactivation: \"selection-gateway\",\n\tsingletonScope: \"section\",\n\n\t// Annotation appears where there's text content\n\tsupportedLevels: [\"passage\", \"rubric\", \"item\", \"element\"],\n\n\t// PNP support IDs\n\t// Maps to QTI 3.0 standard features: highlighting, annotations\n\tpnpSupportIds: [\n\t\t\"highlighting\", // QTI 3.0 standard (cognitive.highlighting / reading.wordHighlighting)\n\t\t\"annotations\", // QTI 3.0 standard (cognitive.annotations)\n\t\t\"highlighter\", // Common variant\n\t\t\"textHighlight\", // Common variant\n\t\t\"annotation\", // Common variant\n\t],\n\n\t/**\n\t * Pass 2: Annotation is relevant when readable text is present\n\t */\n\tisVisibleInContext(context: ToolContext): boolean {\n\t\treturn hasReadableText(context);\n\t},\n\n\trenderToolbar(\n\t\tcontext: ToolContext,\n\t\ttoolbarContext: ToolbarContext,\n\t): ToolToolbarRenderResult {\n\t\tconst visibility = createScopedVisibilityBinding(this.toolId, toolbarContext);\n\t\tconst button: ToolToolbarButtonDefinition = {\n\t\t\ttoolId: this.toolId,\n\t\t\tlabel: this.name,\n\t\t\ticon: typeof this.icon === \"function\" ? this.icon(context) : this.icon,\n\t\t\tdisabled: false,\n\t\t\tariaLabel: \"Annotation toolbar - Highlight text\",\n\t\t\ttooltip: \"Highlight\",\n\t\t\tonClick: () => toolbarContext.toggleTool(this.toolId),\n\t\t\tactive: visibility.isActive(),\n\t\t};\n\t\tconst componentOverrides =\n\t\t\t(toolbarContext.componentOverrides as ToolComponentOverrides | undefined) ?? {};\n\t\tconst overlay = createToolElement(\n\t\t\tthis.toolId,\n\t\t\tcontext,\n\t\t\ttoolbarContext,\n\t\t\tcomponentOverrides,\n\t\t) as HTMLElement & {\n\t\t\tvisible?: boolean;\n\t\t\ttoolId?: string;\n\t\t\ttoolkitCoordinator: unknown;\n\t\t};\n\t\toverlay.setAttribute(\"tool-id\", visibility.fullToolId);\n\t\treturn {\n\t\t\ttoolId: this.toolId,\n\t\t\tbutton,\n\t\t\telements: [{ element: overlay, mount: \"after-buttons\" }],\n\t\t\tsync: () => {\n\t\t\t\tsyncButtonAndOverlayVisibility({\n\t\t\t\t\tbutton,\n\t\t\t\t\toverlay,\n\t\t\t\t\tisActive: visibility.isActive,\n\t\t\t\t});\n\t\t\t\tif (toolbarContext.toolkitCoordinator) {\n\t\t\t\t\toverlay.toolkitCoordinator = toolbarContext.toolkitCoordinator;\n\t\t\t\t}\n\t\t\t},\n\t\t\tsubscribeActive: visibility.subscribeActive,\n\t\t};\n\t},\n};\n"]}
|
|
1
|
+
{"version":3,"file":"accessibility-tools.js","sourceRoot":"","sources":["../../../src/tools/registrations/accessibility-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AASH,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EACN,iBAAi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AI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI;YACtE,QAAQ,EAAE,KAAK;YACf,SAAS,EAAE,qCAAqC;YAChD,OAAO,EAAE,WAAW;YACpB,OAAO,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC;YACrD,MAAM,EAAE,UAAU,CAAC,QAAQ,EAAE;SAC7B,CAAC;QACF,MAAM,kBAAkB,GACtB,cAAc,CAAC,kBAAyD,IAAI,EAAE,CAAC;QACjF,MAAM,OAAO,GAAG,iBAAiB,CAChC,IAAI,CAAC,MAAM,EACX,OAAO,EACP,cAAc,EACd,kBAAkB,CAKlB,CAAC;QACF,OAAO,CAAC,YAAY,CAAC,SAAS,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;QACvD,OAAO;YACN,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,MAAM;YACN,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC;YACxD,IAAI,EAAE,GAAG,EAAE;gBACV,8BAA8B,CAAC;oBAC9B,MAAM;oBACN,OAAO;oBACP,QAAQ,EAAE,UAAU,CAAC,QAAQ;iBAC7B,CAAC,CAAC;gBACH,IAAI,cAAc,CAAC,kBAAkB,EAAE,CAAC;oBACvC,OAAO,CAAC,kBAAkB,GAAG,cAAc,CAAC,kBAAkB,CAAC;gBAChE,CAAC;YACF,CAAC;YACD,eAAe,EAAE,UAAU,CAAC,eAAe;SAC3C,CAAC;IACH,CAAC;CACD,CAAC","sourcesContent":["/**\n * Accessibility Tools Registrations\n *\n * Registers tools for visual accessibility and reading support:\n * - Line Reader (reading guide)\n * - Color Scheme (theme/contrast)\n * - Annotation Toolbar (text highlighting)\n *\n * Maps to QTI 3.0 standard access features from:\n * - visual category: highContrastDisplay, colorContrast\n * - reading category: readingMask, readingGuide, highlighting\n */\n\nimport type {\n\tToolRegistration,\n\tToolToolbarButtonDefinition,\n\tToolToolbarRenderResult,\n\tToolbarContext,\n} from \"../../services/ToolRegistry.js\";\nimport type { ToolContext } from \"../../services/tool-context.js\";\nimport { hasReadableText } from \"../../services/tool-context.js\";\nimport {\n\tcreateToolElement,\n\ttype ToolComponentOverrides,\n} from \"../tool-tag-map.js\";\nimport {\n\tapplyOverlaySurface,\n\tcreateScopedVisibilityBinding,\n\tsyncButtonAndOverlayVisibility,\n} from \"./toolbar-registration-helpers.js\";\n\n/**\n * Line Reader tool registration\n *\n * Provides a reading guide overlay to help track reading position.\n * Useful for text-heavy passages and questions.\n */\nexport const lineReaderToolRegistration: ToolRegistration = {\n\ttoolId: \"lineReader\",\n\tname: \"Line Reader\",\n\tdescription: \"Reading guide overlay\",\n\ticon: \"bars-3\",\n\n\t// Line reader appears where there's text to read\n\tsupportedLevels: [\"section\", \"passage\", \"rubric\", \"item\"],\n\n\t// PNP support IDs\n\t// Maps to QTI 3.0 standard features: readingMask, readingGuide, readingRuler\n\tpnpSupportIds: [\n\t\t\"readingMask\", // QTI 3.0 standard (reading.readingMask)\n\t\t\"readingGuide\", // QTI 3.0 standard (reading.readingGuide)\n\t\t\"readingRuler\", // QTI 3.0 standard (reading.readingRuler)\n\t\t\"lineReader\", // Common variant\n\t\t\"trackingGuide\", // Common variant\n\t],\n\n\t/**\n\t * Pass 2: Line reader is relevant when readable text is present\n\t */\n\tisVisibleInContext(context: ToolContext): boolean {\n\t\treturn hasReadableText(context);\n\t},\n\n\trenderToolbar(\n\t\tcontext: ToolContext,\n\t\ttoolbarContext: ToolbarContext,\n\t): ToolToolbarRenderResult {\n\t\tconst visibility = createScopedVisibilityBinding(this.toolId, toolbarContext);\n\t\tconst button: ToolToolbarButtonDefinition = {\n\t\t\ttoolId: this.toolId,\n\t\t\tlabel: this.name,\n\t\t\ticon: typeof this.icon === \"function\" ? this.icon(context) : this.icon,\n\t\t\tdisabled: false,\n\t\t\tariaLabel: \"Line reader - Reading guide\",\n\t\t\ttooltip: \"Line Reader\",\n\t\t\tonClick: () => toolbarContext.toggleTool(this.toolId),\n\t\t\tactive: visibility.isActive(),\n\t\t};\n\t\tconst componentOverrides =\n\t\t\t(toolbarContext.componentOverrides as ToolComponentOverrides | undefined) ?? {};\n\t\tconst overlay = createToolElement(\n\t\t\tthis.toolId,\n\t\t\tcontext,\n\t\t\ttoolbarContext,\n\t\t\tcomponentOverrides,\n\t\t) as HTMLElement & {\n\t\t\tvisible?: boolean;\n\t\t\ttoolId?: string;\n\t\t\ttoolkitCoordinator: unknown;\n\t\t};\n\t\toverlay.setAttribute(\"tool-id\", visibility.fullToolId);\n\t\tapplyOverlaySurface(overlay, \"frameless\");\n\t\treturn {\n\t\t\ttoolId: this.toolId,\n\t\t\tbutton,\n\t\t\telements: [{ element: overlay, mount: \"after-buttons\" }],\n\t\t\tsync: () => {\n\t\t\t\tsyncButtonAndOverlayVisibility({\n\t\t\t\t\tbutton,\n\t\t\t\t\toverlay,\n\t\t\t\t\tisActive: visibility.isActive,\n\t\t\t\t});\n\t\t\t\tif (toolbarContext.toolkitCoordinator) {\n\t\t\t\t\toverlay.toolkitCoordinator = toolbarContext.toolkitCoordinator;\n\t\t\t\t}\n\t\t\t},\n\t\t\tsubscribeActive: visibility.subscribeActive,\n\t\t};\n\t},\n};\n\n/**\n * Theme tool registration\n *\n * Provides accessible theme and contrast controls.\n * Global tool that affects entire assessment.\n */\nexport const themeToolRegistration: ToolRegistration = {\n\ttoolId: \"theme\",\n\tname: \"Theme\",\n\tdescription: \"Accessible themes and contrast\",\n\ticon: \"swatch\",\n\n\t// Color scheme is assessment-wide\n\tsupportedLevels: [\"assessment\", \"section\"],\n\n\t// PNP support IDs\n\t// Maps to QTI 3.0 standard features: highContrastDisplay, colorContrast, invertColors\n\tpnpSupportIds: [\n\t\t\"highContrastDisplay\", // QTI 3.0 standard (visual.highContrastDisplay)\n\t\t\"colorContrast\", // QTI 3.0 standard (visual.colorContrast)\n\t\t\"invertColors\", // QTI 3.0 standard (visual.invertColors)\n\t\t\"theme\", // Canonical id\n\t\t\"highContrast\", // Common variant\n\t\t\"customColors\", // Common variant\n\t],\n\n\t/**\n\t * Pass 2: Color scheme is always relevant when allowed\n\t */\n\tisVisibleInContext(context: ToolContext): boolean {\n\t\treturn true; // Always show if allowed by orchestrator\n\t},\n\n\trenderToolbar(\n\t\tcontext: ToolContext,\n\t\ttoolbarContext: ToolbarContext,\n\t): ToolToolbarRenderResult {\n\t\tconst visibility = createScopedVisibilityBinding(this.toolId, toolbarContext);\n\t\tconst button: ToolToolbarButtonDefinition = {\n\t\t\ttoolId: this.toolId,\n\t\t\tlabel: this.name,\n\t\t\ticon: typeof this.icon === \"function\" ? this.icon(context) : this.icon,\n\t\t\tdisabled: false,\n\t\t\tariaLabel: \"Theme - Change colors and contrast\",\n\t\t\ttooltip: \"Theme\",\n\t\t\tonClick: () => toolbarContext.toggleTool(this.toolId),\n\t\t\tactive: visibility.isActive(),\n\t\t};\n\t\tconst componentOverrides =\n\t\t\t(toolbarContext.componentOverrides as ToolComponentOverrides | undefined) ?? {};\n\t\tconst overlay = createToolElement(\n\t\t\tthis.toolId,\n\t\t\tcontext,\n\t\t\ttoolbarContext,\n\t\t\tcomponentOverrides,\n\t\t) as HTMLElement & {\n\t\t\tvisible?: boolean;\n\t\t\ttoolId?: string;\n\t\t\ttoolkitCoordinator: unknown;\n\t\t};\n\t\toverlay.setAttribute(\"tool-id\", visibility.fullToolId);\n\t\treturn {\n\t\t\ttoolId: this.toolId,\n\t\t\tbutton,\n\t\t\telements: [\n\t\t\t\t{\n\t\t\t\t\telement: overlay,\n\t\t\t\t\tmount: \"after-buttons\",\n\t\t\t\t\tshell: {\n\t\t\t\t\t\ttitle: this.name,\n\t\t\t\t\t\tdraggable: true,\n\t\t\t\t\t\tresizable: false,\n\t\t\t\t\t\tcloseable: true,\n\t\t\t\t\t\tinitialWidth: 520,\n\t\t\t\t\t\tinitialHeight: 380,\n\t\t\t\t\t\tminWidth: 420,\n\t\t\t\t\t\tminHeight: 300,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t],\n\t\t\tsync: () => {\n\t\t\t\tsyncButtonAndOverlayVisibility({\n\t\t\t\t\tbutton,\n\t\t\t\t\toverlay,\n\t\t\t\t\tisActive: visibility.isActive,\n\t\t\t\t});\n\t\t\t\tif (toolbarContext.toolkitCoordinator) {\n\t\t\t\t\toverlay.toolkitCoordinator = toolbarContext.toolkitCoordinator;\n\t\t\t\t}\n\t\t\t},\n\t\t\tsubscribeActive: visibility.subscribeActive,\n\t\t};\n\t},\n};\n\n/**\n * Annotation Toolbar registration\n *\n * Text highlighting with CSS Custom Highlight API.\n * Zero DOM mutation, optimal performance.\n */\nexport const annotationToolbarRegistration: ToolRegistration = {\n\ttoolId: \"annotationToolbar\",\n\tname: \"Highlighter\",\n\tdescription: \"Highlight and annotate text\",\n\ticon: \"highlighter\",\n\tactivation: \"selection-gateway\",\n\tsingletonScope: \"section\",\n\n\t// Annotation appears where there's text content\n\tsupportedLevels: [\"passage\", \"rubric\", \"item\", \"element\"],\n\n\t// PNP support IDs\n\t// Maps to QTI 3.0 standard features: highlighting, annotations\n\tpnpSupportIds: [\n\t\t\"highlighting\", // QTI 3.0 standard (cognitive.highlighting / reading.wordHighlighting)\n\t\t\"annotations\", // QTI 3.0 standard (cognitive.annotations)\n\t\t\"highlighter\", // Common variant\n\t\t\"textHighlight\", // Common variant\n\t\t\"annotation\", // Common variant\n\t],\n\n\t/**\n\t * Pass 2: Annotation is relevant when readable text is present\n\t */\n\tisVisibleInContext(context: ToolContext): boolean {\n\t\treturn hasReadableText(context);\n\t},\n\n\trenderToolbar(\n\t\tcontext: ToolContext,\n\t\ttoolbarContext: ToolbarContext,\n\t): ToolToolbarRenderResult {\n\t\tconst visibility = createScopedVisibilityBinding(this.toolId, toolbarContext);\n\t\tconst button: ToolToolbarButtonDefinition = {\n\t\t\ttoolId: this.toolId,\n\t\t\tlabel: this.name,\n\t\t\ticon: typeof this.icon === \"function\" ? this.icon(context) : this.icon,\n\t\t\tdisabled: false,\n\t\t\tariaLabel: \"Annotation toolbar - Highlight text\",\n\t\t\ttooltip: \"Highlight\",\n\t\t\tonClick: () => toolbarContext.toggleTool(this.toolId),\n\t\t\tactive: visibility.isActive(),\n\t\t};\n\t\tconst componentOverrides =\n\t\t\t(toolbarContext.componentOverrides as ToolComponentOverrides | undefined) ?? {};\n\t\tconst overlay = createToolElement(\n\t\t\tthis.toolId,\n\t\t\tcontext,\n\t\t\ttoolbarContext,\n\t\t\tcomponentOverrides,\n\t\t) as HTMLElement & {\n\t\t\tvisible?: boolean;\n\t\t\ttoolId?: string;\n\t\t\ttoolkitCoordinator: unknown;\n\t\t};\n\t\toverlay.setAttribute(\"tool-id\", visibility.fullToolId);\n\t\treturn {\n\t\t\ttoolId: this.toolId,\n\t\t\tbutton,\n\t\t\telements: [{ element: overlay, mount: \"after-buttons\" }],\n\t\t\tsync: () => {\n\t\t\t\tsyncButtonAndOverlayVisibility({\n\t\t\t\t\tbutton,\n\t\t\t\t\toverlay,\n\t\t\t\t\tisActive: visibility.isActive,\n\t\t\t\t});\n\t\t\t\tif (toolbarContext.toolkitCoordinator) {\n\t\t\t\t\toverlay.toolkitCoordinator = toolbarContext.toolkitCoordinator;\n\t\t\t\t}\n\t\t\t},\n\t\t\tsubscribeActive: visibility.subscribeActive,\n\t\t};\n\t},\n};\n"]}
|
|
@@ -12,6 +12,38 @@ import { hasMathContent } from "../../services/tool-context.js";
|
|
|
12
12
|
import { createScopedToolId } from "../../services/tool-instance-id.js";
|
|
13
13
|
import { DesmosToolProvider } from "../../services/tool-providers/index.js";
|
|
14
14
|
import { createToolElement } from "../tool-tag-map.js";
|
|
15
|
+
// The toolbar parent re-derives `renderedTools` whenever item state changes
|
|
16
|
+
// (e.g. the learner answers a question and `effectiveItem`/`renderContext`
|
|
17
|
+
// recompute). Calculator initialization is expensive (Desmos boot, container
|
|
18
|
+
// mount), so we cache the overlay element by coordinator + scoped tool id.
|
|
19
|
+
// Reusing the same element keeps `mountContent` a no-op and avoids tearing
|
|
20
|
+
// down and re-initializing the calculator on every re-render.
|
|
21
|
+
const overlayElementCache = new WeakMap();
|
|
22
|
+
function getCachedOverlay(coordinator, fullToolId) {
|
|
23
|
+
if (!coordinator)
|
|
24
|
+
return null;
|
|
25
|
+
const scoped = overlayElementCache.get(coordinator);
|
|
26
|
+
const element = scoped?.get(fullToolId);
|
|
27
|
+
if (!element)
|
|
28
|
+
return null;
|
|
29
|
+
// Svelte custom elements destroy their component when disconnected.
|
|
30
|
+
// A detached cached element is a dead instance — drop it and recreate.
|
|
31
|
+
if (!element.isConnected) {
|
|
32
|
+
scoped?.delete(fullToolId);
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return element;
|
|
36
|
+
}
|
|
37
|
+
function setCachedOverlay(coordinator, fullToolId, element) {
|
|
38
|
+
if (!coordinator)
|
|
39
|
+
return;
|
|
40
|
+
let scoped = overlayElementCache.get(coordinator);
|
|
41
|
+
if (!scoped) {
|
|
42
|
+
scoped = new Map();
|
|
43
|
+
overlayElementCache.set(coordinator, scoped);
|
|
44
|
+
}
|
|
45
|
+
scoped.set(fullToolId, element);
|
|
46
|
+
}
|
|
15
47
|
function normalizeCalculatorType(value) {
|
|
16
48
|
return value === "basic" || value === "scientific" ? value : null;
|
|
17
49
|
}
|
|
@@ -113,7 +145,12 @@ export const calculatorToolRegistration = {
|
|
|
113
145
|
const { calculatorType, availableTypes, displayName } = getCalculatorRenderParams(toolbarContext);
|
|
114
146
|
const fullToolId = createScopedToolId(this.toolId, toolbarContext.scope.level, toolbarContext.scope.scopeId);
|
|
115
147
|
const componentOverrides = toolbarContext.componentOverrides;
|
|
116
|
-
const
|
|
148
|
+
const cachedOverlay = getCachedOverlay(toolbarContext.toolCoordinator, fullToolId);
|
|
149
|
+
const overlay = (cachedOverlay ??
|
|
150
|
+
createToolElement(this.toolId, context, toolbarContext, componentOverrides));
|
|
151
|
+
if (!cachedOverlay) {
|
|
152
|
+
setCachedOverlay(toolbarContext.toolCoordinator, fullToolId, overlay);
|
|
153
|
+
}
|
|
117
154
|
overlay.setAttribute("tool-id", fullToolId);
|
|
118
155
|
overlay.toolkitCoordinator = toolbarContext.toolkitCoordinator;
|
|
119
156
|
applyCalculatorParamsToElement(overlay, calculatorType, availableTypes);
|
|
@@ -134,7 +171,9 @@ export const calculatorToolRegistration = {
|
|
|
134
171
|
active: toolbarContext.isToolVisible(fullToolId),
|
|
135
172
|
};
|
|
136
173
|
let lastVisibleState = button.active;
|
|
137
|
-
overlay.visible
|
|
174
|
+
if (overlay.visible !== button.active) {
|
|
175
|
+
overlay.visible = button.active;
|
|
176
|
+
}
|
|
138
177
|
return {
|
|
139
178
|
toolId: this.toolId,
|
|
140
179
|
elements: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculator.js","sourceRoot":"","sources":["../../../src/tools/registrations/calculator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAUH,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAIvD,SAAS,uBAAuB,CAAC,KAAc;IAC9C,OAAO,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACnE,CAAC;AAED,SAAS,yBAAyB,CAAC,cAA8B;IAKhE,MAAM,MAAM,GAAG,cAAc,CAAC,mBAAmB,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;IACxE,MAAM,cAAc,GAAG,uBAAuB,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IACtE,MAAM,iBAAiB,GAAG,MAAM,CAAC,cAAc,CAAC;IAChD,MAAM,cAAc,GAAG,KAAK,CAA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AAkB,KAAK,cAAc,CAAC,kBAAkB,EAAE,CAAC;oBACtE,OAAO,CAAC,kBAAkB,GAAG,cAAc,CAAC,kBAAkB,CAAC;gBAChE,CAAC;gBACD,8BAA8B,CAAC,OAAO,EAAE,cAAc,EAAE,cAAc,CAAC,CAAC;YACzE,CAAC;YACD,eAAe,EAAE,CAAC,QAAmC,EAAE,EAAE;gBACxD,IAAI,CAAC,cAAc,CAAC,mBAAmB;oBAAE,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;gBACzD,OAAO,cAAc,CAAC,mBAAmB,CAAC,GAAG,EAAE;oBAC9C,QAAQ,CAAC,cAAc,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC;gBACpD,CAAC,CAAC,CAAC;YACJ,CAAC;SACD,CAAC;IACH,CAAC;CACD,CAAC","sourcesContent":["/**\n * Calculator Tool Registration\n *\n * Registers the calculator tool with support for multiple calculator types\n * (basic, scientific, graphing) via Desmos provider.\n *\n * Maps to QTI 3.0 standard access features:\n * - calculator (cognitive support)\n * - graphingCalculator (assessment tool)\n */\n\nimport type {\n\tToolRegistration,\n\tToolToolbarButtonDefinition,\n\tToolToolbarRenderResult,\n\tToolbarContext,\n} from \"../../services/ToolRegistry.js\";\nimport type { ToolProviderConfig } from \"../../services/tools-config-normalizer.js\";\nimport type { ToolContext } from \"../../services/tool-context.js\";\nimport { hasMathContent } from \"../../services/tool-context.js\";\nimport { createScopedToolId } from \"../../services/tool-instance-id.js\";\nimport { DesmosToolProvider } from \"../../services/tool-providers/index.js\";\nimport { createToolElement } from \"../tool-tag-map.js\";\n\ntype CalculatorType = \"basic\" | \"scientific\";\n\nfunction normalizeCalculatorType(value: unknown): CalculatorType | null {\n\treturn value === \"basic\" || value === \"scientific\" ? value : null;\n}\n\nfunction getCalculatorRenderParams(toolbarContext: ToolbarContext): {\n\tcalculatorType: CalculatorType | null;\n\tavailableTypes: CalculatorType[] | null;\n\tdisplayName: string;\n} {\n\tconst params = toolbarContext.getToolRenderParams?.(\"calculator\") ?? {};\n\tconst calculatorType = normalizeCalculatorType(params.calculatorType);\n\tconst availableTypesRaw = params.availableTypes;\n\tconst availableTypes = Array.isArray(availableTypesRaw)\n\t\t? availableTypesRaw\n\t\t\t\t.map((value) => normalizeCalculatorType(value))\n\t\t\t\t.filter((value): value is CalculatorType => value !== null)\n\t\t: calculatorType\n\t\t\t? [calculatorType]\n\t\t\t: null;\n\n\treturn {\n\t\tcalculatorType,\n\t\tavailableTypes,\n\t\tdisplayName:\n\t\t\tcalculatorType === \"scientific\"\n\t\t\t\t? \"Scientific Calculator\"\n\t\t\t\t: calculatorType === \"basic\"\n\t\t\t\t\t? \"Basic Calculator\"\n\t\t\t\t\t: \"Calculator\",\n\t};\n}\n\nfunction applyCalculatorParamsToElement(\n\telement: HTMLElement,\n\tcalculatorType: CalculatorType | null,\n\tavailableTypes: CalculatorType[] | null,\n): void {\n\tconst calculatorElement = element as HTMLElement & {\n\t\tcalculatorType?: CalculatorType;\n\t\tavailableTypes?: CalculatorType[];\n\t};\n\n\tif (calculatorType) {\n\t\tcalculatorElement.calculatorType = calculatorType;\n\t\telement.setAttribute(\"calculator-type\", calculatorType);\n\t} else {\n\t\tdelete calculatorElement.calculatorType;\n\t\telement.removeAttribute(\"calculator-type\");\n\t}\n\n\tif (availableTypes && availableTypes.length > 0) {\n\t\tcalculatorElement.availableTypes = availableTypes;\n\t} else {\n\t\tdelete calculatorElement.availableTypes;\n\t}\n}\n\n/**\n * Calculator tool registration\n *\n * Supports:\n * - Basic, scientific, and graphing calculators via Desmos\n * - Context-aware visibility (shows only when math content is detected)\n * - Item level only\n */\nexport const calculatorToolRegistration: ToolRegistration = {\n\ttoolId: \"calculator\",\n\tname: \"Calculator\",\n\tdescription: \"Multi-type calculator (basic, scientific, graphing)\",\n\ticon: \"calculator\",\n\tprovider: {\n\t\tgetProviderId: (config: ToolProviderConfig | undefined) =>\n\t\t\ttypeof config?.provider?.id === \"string\" && config.provider.id.length > 0\n\t\t\t\t? config.provider.id\n\t\t\t\t: \"calculator-desmos\",\n\t\tcreateProvider: () => new DesmosToolProvider(),\n\t\tgetInitConfig: (config: ToolProviderConfig | undefined) =>\n\t\t\tconfig?.provider?.init ?? {},\n\t\tgetAuthFetcher: (config: ToolProviderConfig | undefined) => {\n\t\t\tconst runtimeAuthFetcher = config?.provider?.runtime?.authFetcher;\n\t\t\tif (typeof runtimeAuthFetcher === \"function\") return runtimeAuthFetcher;\n\t\t\treturn async () => {\n\t\t\t\tconst response = await fetch(\"/api/tools/desmos/auth\", {\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\tcredentials: \"same-origin\",\n\t\t\t\t});\n\t\t\t\tif (!response.ok) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Failed to fetch Desmos auth config (${response.status})`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn (await response.json()) as Record<string, unknown>;\n\t\t\t};\n\t\t},\n\t\tlazy: true,\n\t},\n\n\t// Calculator is item-level in this player architecture.\n\tsupportedLevels: [\"item\"],\n\n\t// PNP support IDs that enable this tool\n\t// Maps to QTI 3.0 standard features: calculator, graphingCalculator\n\tpnpSupportIds: [\n\t\t\"calculator\", // QTI 3.0 standard (cognitive.calculator)\n\t\t\"graphingCalculator\", // QTI 3.0 standard (assessment.graphingCalculator)\n\t\t\"basicCalculator\", // Common variant\n\t\t\"scientificCalculator\", // Common variant\n\t],\n\n\t/**\n\t * Pass 2: Determine if calculator is relevant in this context\n\t *\n\t * Calculator is relevant when context contains mathematical content\n\t * (MathML, LaTeX, arithmetic markers).\n\t */\n\tisVisibleInContext(context: ToolContext): boolean {\n\t\t// Show only when math is present in item content.\n\t\treturn hasMathContent(context);\n\t},\n\n\trenderToolbar(\n\t\tcontext: ToolContext,\n\t\ttoolbarContext: ToolbarContext,\n\t): ToolToolbarRenderResult {\n\t\tconst { calculatorType, availableTypes, displayName } =\n\t\t\tgetCalculatorRenderParams(toolbarContext);\n\t\tconst fullToolId = createScopedToolId(\n\t\t\tthis.toolId,\n\t\t\ttoolbarContext.scope.level,\n\t\t\ttoolbarContext.scope.scopeId,\n\t\t);\n\t\tconst componentOverrides = toolbarContext.componentOverrides;\n\t\tconst overlay = createToolElement(\n\t\t\tthis.toolId,\n\t\t\tcontext,\n\t\t\ttoolbarContext,\n\t\t\tcomponentOverrides,\n\t\t) as HTMLElement & {\n\t\t\tvisible?: boolean;\n\t\t\ttoolId?: string;\n\t\t\ttoolkitCoordinator?: unknown;\n\t\t};\n\t\toverlay.setAttribute(\"tool-id\", fullToolId);\n\t\toverlay.toolkitCoordinator = toolbarContext.toolkitCoordinator;\n\t\tapplyCalculatorParamsToElement(overlay, calculatorType, availableTypes);\n\t\tconst openLabel =\n\t\t\tcalculatorType === null\n\t\t\t\t? \"Open scientific calculator\"\n\t\t\t\t: `Open ${displayName.toLowerCase()}`;\n\t\tconst closeLabel =\n\t\t\tcalculatorType === null\n\t\t\t\t? \"Close scientific calculator\"\n\t\t\t\t: `Close ${displayName.toLowerCase()}`;\n\t\tconst button: ToolToolbarButtonDefinition = {\n\t\t\ttoolId: this.toolId,\n\t\t\tlabel: displayName,\n\t\t\ticon: typeof this.icon === \"function\" ? this.icon(context) : this.icon,\n\t\t\tdisabled: false,\n\t\t\tariaLabel: openLabel,\n\t\t\ttooltip: displayName,\n\t\t\tonClick: () => toolbarContext.toggleTool(this.toolId),\n\t\t\tactive: toolbarContext.isToolVisible(fullToolId),\n\t\t};\n\t\tlet lastVisibleState: boolean | undefined = button.active;\n\t\toverlay.visible = button.active;\n\n\t\treturn {\n\t\t\ttoolId: this.toolId,\n\t\t\telements: [\n\t\t\t\t{\n\t\t\t\t\telement: overlay,\n\t\t\t\t\tmount: \"after-buttons\",\n\t\t\t\t\tshell: {\n\t\t\t\t\t\ttitle: this.name,\n\t\t\t\t\t\tdraggable: true,\n\t\t\t\t\t\tresizable: true,\n\t\t\t\t\t\tcloseable: true,\n\t\t\t\t\t\tinitialWidth: 720,\n\t\t\t\t\t\tinitialHeight: 620,\n\t\t\t\t\t\tminWidth: 360,\n\t\t\t\t\t\tminHeight: 420,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t],\n\t\t\tbutton,\n\t\t\tsync: () => {\n\t\t\t\tconst active = toolbarContext.isToolVisible(fullToolId);\n\t\t\t\tbutton.active = active;\n\t\t\t\tbutton.label = displayName;\n\t\t\t\tbutton.ariaLabel = active ? closeLabel : openLabel;\n\t\t\t\tbutton.tooltip = active\n\t\t\t\t\t? `Close ${displayName.toLowerCase()}`\n\t\t\t\t\t: displayName;\n\t\t\t\tif (lastVisibleState !== active) {\n\t\t\t\t\toverlay.visible = active;\n\t\t\t\t\tlastVisibleState = active;\n\t\t\t\t}\n\t\t\t\tif (overlay.toolkitCoordinator !== toolbarContext.toolkitCoordinator) {\n\t\t\t\t\toverlay.toolkitCoordinator = toolbarContext.toolkitCoordinator;\n\t\t\t\t}\n\t\t\t\tapplyCalculatorParamsToElement(overlay, calculatorType, availableTypes);\n\t\t\t},\n\t\t\tsubscribeActive: (callback: (active: boolean) => void) => {\n\t\t\t\tif (!toolbarContext.subscribeVisibility) return () => {};\n\t\t\t\treturn toolbarContext.subscribeVisibility(() => {\n\t\t\t\t\tcallback(toolbarContext.isToolVisible(fullToolId));\n\t\t\t\t});\n\t\t\t},\n\t\t};\n\t},\n};\n"]}
|
|
1
|
+
{"version":3,"file":"calculator.js","sourceRoot":"","sources":["../../../src/tools/registrations/calculator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAWH,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAIvD,4EAA4E;AAC5E,2EAA2E;AAC3E,6EAA6E;AAC7E,2EAA2E;AAC3E,2EAA2E;AAC3E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;gBACvB,MAAM,CAAC,KAAK,GAAG,WAAW,CAAC;gBAC3B,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;gBACnD,MAAM,CAAC,OAAO,GAAG,MAAM;oBACtB,CAAC,CAAC,SAAS,WAAW,CAAC,WAAW,EAAE,EAAE;oBACtC,CAAC,CAAC,WAAW,CAAC;gBACf,IAAI,gBAAgB,KAAK,MAAM,EAAE,CAAC;oBACjC,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC;oBACzB,gBAAgB,GAAG,MAAM,CAAC;gBAC3B,CAAC;gBACD,IAAI,OAAO,CAAC,kBAAkB,KAAK,cAAc,CAAC,kBAAkB,EAAE,CAAC;oBACtE,OAAO,CAAC,kBAAkB,GAAG,cAAc,CAAC,kBAAkB,CAAC;gBAChE,CAAC;gBACD,8BAA8B,CAAC,OAAO,EAAE,cAAc,EAAE,cAAc,CAAC,CAAC;YACzE,CAAC;YACD,eAAe,EAAE,CAAC,QAAmC,EAAE,EAAE;gBACxD,IAAI,CAAC,cAAc,CAAC,mBAAmB;oBAAE,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;gBACzD,OAAO,cAAc,CAAC,mBAAmB,CAAC,GAAG,EAAE;oBAC9C,QAAQ,CAAC,cAAc,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC;gBACpD,CAAC,CAAC,CAAC;YACJ,CAAC;SACD,CAAC;IACH,CAAC;CACD,CAAC","sourcesContent":["/**\n * Calculator Tool Registration\n *\n * Registers the calculator tool with support for multiple calculator types\n * (basic, scientific, graphing) via Desmos provider.\n *\n * Maps to QTI 3.0 standard access features:\n * - calculator (cognitive support)\n * - graphingCalculator (assessment tool)\n */\n\nimport type {\n\tToolRegistration,\n\tToolToolbarButtonDefinition,\n\tToolToolbarRenderResult,\n\tToolbarContext,\n} from \"../../services/ToolRegistry.js\";\nimport type { ToolCoordinatorApi } from \"../../services/interfaces.js\";\nimport type { ToolProviderConfig } from \"../../services/tools-config-normalizer.js\";\nimport type { ToolContext } from \"../../services/tool-context.js\";\nimport { hasMathContent } from \"../../services/tool-context.js\";\nimport { createScopedToolId } from \"../../services/tool-instance-id.js\";\nimport { DesmosToolProvider } from \"../../services/tool-providers/index.js\";\nimport { createToolElement } from \"../tool-tag-map.js\";\n\ntype CalculatorType = \"basic\" | \"scientific\";\n\n// The toolbar parent re-derives `renderedTools` whenever item state changes\n// (e.g. the learner answers a question and `effectiveItem`/`renderContext`\n// recompute). Calculator initialization is expensive (Desmos boot, container\n// mount), so we cache the overlay element by coordinator + scoped tool id.\n// Reusing the same element keeps `mountContent` a no-op and avoids tearing\n// down and re-initializing the calculator on every re-render.\nconst overlayElementCache = new WeakMap<\n\tToolCoordinatorApi,\n\tMap<string, HTMLElement>\n>();\n\nfunction getCachedOverlay(\n\tcoordinator: ToolCoordinatorApi | null,\n\tfullToolId: string,\n): HTMLElement | null {\n\tif (!coordinator) return null;\n\tconst scoped = overlayElementCache.get(coordinator);\n\tconst element = scoped?.get(fullToolId);\n\tif (!element) return null;\n\t// Svelte custom elements destroy their component when disconnected.\n\t// A detached cached element is a dead instance — drop it and recreate.\n\tif (!element.isConnected) {\n\t\tscoped?.delete(fullToolId);\n\t\treturn null;\n\t}\n\treturn element;\n}\n\nfunction setCachedOverlay(\n\tcoordinator: ToolCoordinatorApi | null,\n\tfullToolId: string,\n\telement: HTMLElement,\n): void {\n\tif (!coordinator) return;\n\tlet scoped = overlayElementCache.get(coordinator);\n\tif (!scoped) {\n\t\tscoped = new Map();\n\t\toverlayElementCache.set(coordinator, scoped);\n\t}\n\tscoped.set(fullToolId, element);\n}\n\nfunction normalizeCalculatorType(value: unknown): CalculatorType | null {\n\treturn value === \"basic\" || value === \"scientific\" ? value : null;\n}\n\nfunction getCalculatorRenderParams(toolbarContext: ToolbarContext): {\n\tcalculatorType: CalculatorType | null;\n\tavailableTypes: CalculatorType[] | null;\n\tdisplayName: string;\n} {\n\tconst params = toolbarContext.getToolRenderParams?.(\"calculator\") ?? {};\n\tconst calculatorType = normalizeCalculatorType(params.calculatorType);\n\tconst availableTypesRaw = params.availableTypes;\n\tconst availableTypes = Array.isArray(availableTypesRaw)\n\t\t? availableTypesRaw\n\t\t\t\t.map((value) => normalizeCalculatorType(value))\n\t\t\t\t.filter((value): value is CalculatorType => value !== null)\n\t\t: calculatorType\n\t\t\t? [calculatorType]\n\t\t\t: null;\n\n\treturn {\n\t\tcalculatorType,\n\t\tavailableTypes,\n\t\tdisplayName:\n\t\t\tcalculatorType === \"scientific\"\n\t\t\t\t? \"Scientific Calculator\"\n\t\t\t\t: calculatorType === \"basic\"\n\t\t\t\t\t? \"Basic Calculator\"\n\t\t\t\t\t: \"Calculator\",\n\t};\n}\n\nfunction applyCalculatorParamsToElement(\n\telement: HTMLElement,\n\tcalculatorType: CalculatorType | null,\n\tavailableTypes: CalculatorType[] | null,\n): void {\n\tconst calculatorElement = element as HTMLElement & {\n\t\tcalculatorType?: CalculatorType;\n\t\tavailableTypes?: CalculatorType[];\n\t};\n\n\tif (calculatorType) {\n\t\tcalculatorElement.calculatorType = calculatorType;\n\t\telement.setAttribute(\"calculator-type\", calculatorType);\n\t} else {\n\t\tdelete calculatorElement.calculatorType;\n\t\telement.removeAttribute(\"calculator-type\");\n\t}\n\n\tif (availableTypes && availableTypes.length > 0) {\n\t\tcalculatorElement.availableTypes = availableTypes;\n\t} else {\n\t\tdelete calculatorElement.availableTypes;\n\t}\n}\n\n/**\n * Calculator tool registration\n *\n * Supports:\n * - Basic, scientific, and graphing calculators via Desmos\n * - Context-aware visibility (shows only when math content is detected)\n * - Item level only\n */\nexport const calculatorToolRegistration: ToolRegistration = {\n\ttoolId: \"calculator\",\n\tname: \"Calculator\",\n\tdescription: \"Multi-type calculator (basic, scientific, graphing)\",\n\ticon: \"calculator\",\n\tprovider: {\n\t\tgetProviderId: (config: ToolProviderConfig | undefined) =>\n\t\t\ttypeof config?.provider?.id === \"string\" && config.provider.id.length > 0\n\t\t\t\t? config.provider.id\n\t\t\t\t: \"calculator-desmos\",\n\t\tcreateProvider: () => new DesmosToolProvider(),\n\t\tgetInitConfig: (config: ToolProviderConfig | undefined) =>\n\t\t\tconfig?.provider?.init ?? {},\n\t\tgetAuthFetcher: (config: ToolProviderConfig | undefined) => {\n\t\t\tconst runtimeAuthFetcher = config?.provider?.runtime?.authFetcher;\n\t\t\tif (typeof runtimeAuthFetcher === \"function\") return runtimeAuthFetcher;\n\t\t\treturn async () => {\n\t\t\t\tconst response = await fetch(\"/api/tools/desmos/auth\", {\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\tcredentials: \"same-origin\",\n\t\t\t\t});\n\t\t\t\tif (!response.ok) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Failed to fetch Desmos auth config (${response.status})`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn (await response.json()) as Record<string, unknown>;\n\t\t\t};\n\t\t},\n\t\tlazy: true,\n\t},\n\n\t// Calculator is item-level in this player architecture.\n\tsupportedLevels: [\"item\"],\n\n\t// PNP support IDs that enable this tool\n\t// Maps to QTI 3.0 standard features: calculator, graphingCalculator\n\tpnpSupportIds: [\n\t\t\"calculator\", // QTI 3.0 standard (cognitive.calculator)\n\t\t\"graphingCalculator\", // QTI 3.0 standard (assessment.graphingCalculator)\n\t\t\"basicCalculator\", // Common variant\n\t\t\"scientificCalculator\", // Common variant\n\t],\n\n\t/**\n\t * Pass 2: Determine if calculator is relevant in this context\n\t *\n\t * Calculator is relevant when context contains mathematical content\n\t * (MathML, LaTeX, arithmetic markers).\n\t */\n\tisVisibleInContext(context: ToolContext): boolean {\n\t\t// Show only when math is present in item content.\n\t\treturn hasMathContent(context);\n\t},\n\n\trenderToolbar(\n\t\tcontext: ToolContext,\n\t\ttoolbarContext: ToolbarContext,\n\t): ToolToolbarRenderResult {\n\t\tconst { calculatorType, availableTypes, displayName } =\n\t\t\tgetCalculatorRenderParams(toolbarContext);\n\t\tconst fullToolId = createScopedToolId(\n\t\t\tthis.toolId,\n\t\t\ttoolbarContext.scope.level,\n\t\t\ttoolbarContext.scope.scopeId,\n\t\t);\n\t\tconst componentOverrides = toolbarContext.componentOverrides;\n\t\tconst cachedOverlay = getCachedOverlay(\n\t\t\ttoolbarContext.toolCoordinator,\n\t\t\tfullToolId,\n\t\t);\n\t\tconst overlay = (cachedOverlay ??\n\t\t\tcreateToolElement(\n\t\t\t\tthis.toolId,\n\t\t\t\tcontext,\n\t\t\t\ttoolbarContext,\n\t\t\t\tcomponentOverrides,\n\t\t\t)) as HTMLElement & {\n\t\t\tvisible?: boolean;\n\t\t\ttoolId?: string;\n\t\t\ttoolkitCoordinator?: unknown;\n\t\t};\n\t\tif (!cachedOverlay) {\n\t\t\tsetCachedOverlay(toolbarContext.toolCoordinator, fullToolId, overlay);\n\t\t}\n\t\toverlay.setAttribute(\"tool-id\", fullToolId);\n\t\toverlay.toolkitCoordinator = toolbarContext.toolkitCoordinator;\n\t\tapplyCalculatorParamsToElement(overlay, calculatorType, availableTypes);\n\t\tconst openLabel =\n\t\t\tcalculatorType === null\n\t\t\t\t? \"Open scientific calculator\"\n\t\t\t\t: `Open ${displayName.toLowerCase()}`;\n\t\tconst closeLabel =\n\t\t\tcalculatorType === null\n\t\t\t\t? \"Close scientific calculator\"\n\t\t\t\t: `Close ${displayName.toLowerCase()}`;\n\t\tconst button: ToolToolbarButtonDefinition = {\n\t\t\ttoolId: this.toolId,\n\t\t\tlabel: displayName,\n\t\t\ticon: typeof this.icon === \"function\" ? this.icon(context) : this.icon,\n\t\t\tdisabled: false,\n\t\t\tariaLabel: openLabel,\n\t\t\ttooltip: displayName,\n\t\t\tonClick: () => toolbarContext.toggleTool(this.toolId),\n\t\t\tactive: toolbarContext.isToolVisible(fullToolId),\n\t\t};\n\t\tlet lastVisibleState: boolean | undefined = button.active;\n\t\tif (overlay.visible !== button.active) {\n\t\t\toverlay.visible = button.active;\n\t\t}\n\n\t\treturn {\n\t\t\ttoolId: this.toolId,\n\t\t\telements: [\n\t\t\t\t{\n\t\t\t\t\telement: overlay,\n\t\t\t\t\tmount: \"after-buttons\",\n\t\t\t\t\tshell: {\n\t\t\t\t\t\ttitle: this.name,\n\t\t\t\t\t\tdraggable: true,\n\t\t\t\t\t\tresizable: true,\n\t\t\t\t\t\tcloseable: true,\n\t\t\t\t\t\tinitialWidth: 720,\n\t\t\t\t\t\tinitialHeight: 620,\n\t\t\t\t\t\tminWidth: 360,\n\t\t\t\t\t\tminHeight: 420,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t],\n\t\t\tbutton,\n\t\t\tsync: () => {\n\t\t\t\tconst active = toolbarContext.isToolVisible(fullToolId);\n\t\t\t\tbutton.active = active;\n\t\t\t\tbutton.label = displayName;\n\t\t\t\tbutton.ariaLabel = active ? closeLabel : openLabel;\n\t\t\t\tbutton.tooltip = active\n\t\t\t\t\t? `Close ${displayName.toLowerCase()}`\n\t\t\t\t\t: displayName;\n\t\t\t\tif (lastVisibleState !== active) {\n\t\t\t\t\toverlay.visible = active;\n\t\t\t\t\tlastVisibleState = active;\n\t\t\t\t}\n\t\t\t\tif (overlay.toolkitCoordinator !== toolbarContext.toolkitCoordinator) {\n\t\t\t\t\toverlay.toolkitCoordinator = toolbarContext.toolkitCoordinator;\n\t\t\t\t}\n\t\t\t\tapplyCalculatorParamsToElement(overlay, calculatorType, availableTypes);\n\t\t\t},\n\t\t\tsubscribeActive: (callback: (active: boolean) => void) => {\n\t\t\t\tif (!toolbarContext.subscribeVisibility) return () => {};\n\t\t\t\treturn toolbarContext.subscribeVisibility(() => {\n\t\t\t\t\tcallback(toolbarContext.isToolVisible(fullToolId));\n\t\t\t\t});\n\t\t\t},\n\t\t};\n\t},\n};\n"]}
|
|
@@ -12,7 +12,6 @@ export const DEFAULT_TOOL_TAG_MAP = {
|
|
|
12
12
|
highlighter: "pie-tool-annotation-toolbar",
|
|
13
13
|
lineReader: "pie-tool-line-reader",
|
|
14
14
|
theme: "pie-tool-theme",
|
|
15
|
-
colorScheme: "pie-tool-theme",
|
|
16
15
|
annotationToolbar: "pie-tool-annotation-toolbar",
|
|
17
16
|
graph: "pie-tool-graph",
|
|
18
17
|
periodicTable: "pie-tool-periodic-table",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-tag-map.js","sourceRoot":"","sources":["../../src/tools/tool-tag-map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,+CAA+C,CAAC;AAqBzF;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAe;IAC/C,UAAU,EAAE,qBAAqB;IACjC,YAAY,EAAE,yBAAyB;IACvC,KAAK,EAAE,gBAAgB;IACvB,UAAU,EAAE,qBAAqB;IACjC,gBAAgB,EAAE,4BAA4B;IAC9C,WAAW,EAAE,6BAA6B;IAC1C,UAAU,EAAE,sBAAsB;IAClC,KAAK,EAAE,gBAAgB;IACvB,
|
|
1
|
+
{"version":3,"file":"tool-tag-map.js","sourceRoot":"","sources":["../../src/tools/tool-tag-map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,+CAA+C,CAAC;AAqBzF;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAe;IAC/C,UAAU,EAAE,qBAAqB;IACjC,YAAY,EAAE,yBAAyB;IACvC,KAAK,EAAE,gBAAgB;IACvB,UAAU,EAAE,qBAAqB;IACjC,gBAAgB,EAAE,4BAA4B;IAC9C,WAAW,EAAE,6BAA6B;IAC1C,UAAU,EAAE,sBAAsB;IAClC,KAAK,EAAE,gBAAgB;IACvB,iBAAiB,EAAE,6BAA6B;IAChD,KAAK,EAAE,gBAAgB;IACvB,aAAa,EAAE,yBAAyB;CACxC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,CAC7B,MAAc,EACd,SAAkC,EACzB,EAAE;IACX,MAAM,MAAM,GACX,SAAS,EAAE,UAAU,EAAE,CAAC,MAAM,CAAC,IAAI,oBAAoB,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC;IAC3E,OAAO,wBAAwB,CAAC,MAAM,EAAE,2BAA2B,MAAM,GAAG,CAAC,CAAC;AAC/E,CAAC,CAAC;AAEF,MAAM,wBAAwB,GAAG,CAAC,OAAe,EAAe,EAAE,CACjE,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;AAEjC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAChC,MAAc,EACd,OAAoB,EACpB,cAA8B,EAC9B,SAAkC,EACpB,EAAE;IAChB,MAAM,OAAO,GAAG,cAAc,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAClD,MAAM,cAAc,GAAG,SAAS,EAAE,sBAAsB,EAAE,CAAC,MAAM,CAAC,CAAC;IACnE,MAAM,OAAO,GAAG,cAAc,IAAI,SAAS,EAAE,oBAAoB,CAAC;IAClE,OAAO,OAAO;QACb,CAAC,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;QACvD,CAAC,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,CAC9B,OAAe,EACf,SAAkC,EACb,EAAE;IACvB,MAAM,QAAQ,GAAG,wBAAwB,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC;IACzE,MAAM,GAAG,GAAG,EAAE,GAAG,oBAAoB,EAAE,GAAG,SAAS,EAAE,UAAU,EAAE,CAAC;IAClE,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AACrE,CAAC,CAAC","sourcesContent":["import { validateCustomElementTag } from \"@pie-players/pie-players-shared/pie/tag-names\";\nimport type { ToolContext } from \"../services/tool-context.js\";\nimport type { ToolbarContext } from \"../services/ToolRegistry.js\";\n\nexport type ToolTagMap = Record<string, string>;\n\nexport type ToolComponentFactory = (args: {\n\ttoolId: string;\n\ttagName: string;\n\tcontext: ToolContext;\n\ttoolbarContext: ToolbarContext;\n}) => HTMLElement;\n\nexport type ToolComponentFactoryMap = Record<string, ToolComponentFactory>;\n\nexport interface ToolComponentOverrides {\n\ttoolTagMap?: Partial<ToolTagMap>;\n\ttoolComponentFactory?: ToolComponentFactory;\n\ttoolComponentFactories?: Partial<ToolComponentFactoryMap>;\n}\n\n/**\n * Canonical default web component tag mapping for toolkit tools.\n * Integrators can override any entry via ToolComponentOverrides.\n */\nexport const DEFAULT_TOOL_TAG_MAP: ToolTagMap = {\n\tcalculator: \"pie-tool-calculator\",\n\ttextToSpeech: \"pie-tool-text-to-speech\",\n\truler: \"pie-tool-ruler\",\n\tprotractor: \"pie-tool-protractor\",\n\tanswerEliminator: \"pie-tool-answer-eliminator\",\n\thighlighter: \"pie-tool-annotation-toolbar\",\n\tlineReader: \"pie-tool-line-reader\",\n\ttheme: \"pie-tool-theme\",\n\tannotationToolbar: \"pie-tool-annotation-toolbar\",\n\tgraph: \"pie-tool-graph\",\n\tperiodicTable: \"pie-tool-periodic-table\",\n};\n\nexport const resolveToolTag = (\n\ttoolId: string,\n\toverrides?: ToolComponentOverrides,\n): string => {\n\tconst mapped =\n\t\toverrides?.toolTagMap?.[toolId] ?? DEFAULT_TOOL_TAG_MAP[toolId] ?? toolId;\n\treturn validateCustomElementTag(mapped, `tool component tag for \"${toolId}\"`);\n};\n\nconst createDefaultToolElement = (tagName: string): HTMLElement =>\n\tdocument.createElement(tagName);\n\nexport const createToolElement = (\n\ttoolId: string,\n\tcontext: ToolContext,\n\ttoolbarContext: ToolbarContext,\n\toverrides?: ToolComponentOverrides,\n): HTMLElement => {\n\tconst tagName = resolveToolTag(toolId, overrides);\n\tconst factoryForTool = overrides?.toolComponentFactories?.[toolId];\n\tconst factory = factoryForTool ?? overrides?.toolComponentFactory;\n\treturn factory\n\t\t? factory({ toolId, tagName, context, toolbarContext })\n\t\t: createDefaultToolElement(tagName);\n};\n\nexport const toToolIdFromTag = (\n\ttagName: string,\n\toverrides?: ToolComponentOverrides,\n): string | undefined => {\n\tconst validTag = validateCustomElementTag(tagName, \"tool component tag\");\n\tconst map = { ...DEFAULT_TOOL_TAG_MAP, ...overrides?.toolTagMap };\n\treturn Object.entries(map).find(([, tag]) => tag === validTag)?.[0];\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-players/pie-assessment-toolkit",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.45",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "PIE assessment toolkit: composable services + reference implementation for assessment players and tool coordination",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,10 +41,6 @@
|
|
|
41
41
|
"types": "./dist/services/pnp-standard-features.d.ts",
|
|
42
42
|
"import": "./dist/services/pnp-standard-features.js"
|
|
43
43
|
},
|
|
44
|
-
"./services/pnp-provenance": {
|
|
45
|
-
"types": "./dist/services/pnp-provenance.d.ts",
|
|
46
|
-
"import": "./dist/services/pnp-provenance.js"
|
|
47
|
-
},
|
|
48
44
|
"./services/I18nService": {
|
|
49
45
|
"types": "./dist/services/I18nService.d.ts",
|
|
50
46
|
"import": "./dist/services/I18nService.js"
|
|
@@ -79,14 +75,15 @@
|
|
|
79
75
|
"test": "bun test"
|
|
80
76
|
},
|
|
81
77
|
"dependencies": {
|
|
82
|
-
"@pie-players/pie-calculator": "0.3.
|
|
83
|
-
"@pie-players/pie-context": "0.3.
|
|
84
|
-
"@pie-players/pie-players-shared": "0.3.
|
|
85
|
-
"@pie-players/pie-tts": "0.3.
|
|
78
|
+
"@pie-players/pie-calculator": "0.3.45",
|
|
79
|
+
"@pie-players/pie-context": "0.3.45",
|
|
80
|
+
"@pie-players/pie-players-shared": "0.3.45",
|
|
81
|
+
"@pie-players/pie-tts": "0.3.45",
|
|
82
|
+
"speech-rule-engine": "^5.0.0-rc.1"
|
|
86
83
|
},
|
|
87
84
|
"peerDependencies": {
|
|
88
|
-
"@pie-players/pie-calculator-desmos": "0.3.
|
|
89
|
-
"@pie-players/tts-client-server": "0.3.
|
|
85
|
+
"@pie-players/pie-calculator-desmos": "0.3.45",
|
|
86
|
+
"@pie-players/tts-client-server": "0.3.45"
|
|
90
87
|
},
|
|
91
88
|
"peerDependenciesMeta": {
|
|
92
89
|
"@pie-players/pie-calculator-desmos": {
|