@pie-qti/default-components 1.0.0-beta.4 → 1.0.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/README.md +13 -0
  2. package/dist/chunks/{mathlive.min-Cmxm6f5R.js → mathlive.min-DHkAtaP5.js} +15 -16
  3. package/dist/chunks/{mathlive.min-Cmxm6f5R.js.map → mathlive.min-DHkAtaP5.js.map} +1 -1
  4. package/dist/index.js +13 -110
  5. package/dist/index.js.map +1 -1
  6. package/dist/plugins/extended-text/textInput.d.ts +47 -0
  7. package/dist/plugins/extended-text/textInput.js +65 -0
  8. package/dist/plugins/extended-text/textInput.js.map +1 -0
  9. package/dist/plugins/media/mediaPlayback.d.ts +39 -0
  10. package/dist/plugins/media/mediaPlayback.js +49 -0
  11. package/dist/plugins/media/mediaPlayback.js.map +1 -0
  12. package/dist/plugins.js +13779 -21944
  13. package/dist/plugins.js.map +1 -1
  14. package/dist/shared/components/icons.d.ts +12 -0
  15. package/dist/shared/components/icons.js +13 -0
  16. package/dist/shared/components/icons.js.map +1 -0
  17. package/dist/shared/components/keyboardCrosshair.svelte.d.ts +37 -0
  18. package/dist/shared/components/keyboardCrosshair.svelte.js +67 -0
  19. package/dist/shared/components/keyboardCrosshair.svelte.js.map +1 -0
  20. package/dist/shared/components/pickUpPlace.svelte.d.ts +42 -0
  21. package/dist/shared/components/pickUpPlace.svelte.js +58 -0
  22. package/dist/shared/components/pickUpPlace.svelte.js.map +1 -0
  23. package/dist/shared/extensions/MathLiveEditor.d.ts +33 -6
  24. package/dist/shared/extensions/MathLiveEditor.js +354 -175
  25. package/dist/shared/extensions/MathLiveEditor.js.map +1 -1
  26. package/dist/shared/extensions/modalDialog.d.ts +31 -0
  27. package/dist/shared/extensions/modalDialog.js +165 -0
  28. package/dist/shared/extensions/modalDialog.js.map +1 -0
  29. package/dist/shared/index.d.ts +1 -0
  30. package/dist/shared/index.js +2 -0
  31. package/dist/shared/index.js.map +1 -1
  32. package/dist/shared/styles/qti-pnp.css +44 -0
  33. package/dist/shared/styles/qti-shared-vocabulary.css +6 -2
  34. package/dist/shared/styles/srOnly.d.ts +23 -0
  35. package/dist/shared/styles/srOnly.js +70 -0
  36. package/dist/shared/styles/srOnly.js.map +1 -0
  37. package/dist/shared/utils/accessibleText.d.ts +24 -0
  38. package/dist/shared/utils/accessibleText.js +72 -0
  39. package/dist/shared/utils/accessibleText.js.map +1 -0
  40. package/dist/shared/utils/announcer.svelte.d.ts +26 -0
  41. package/dist/shared/utils/announcer.svelte.js +30 -0
  42. package/dist/shared/utils/announcer.svelte.js.map +1 -0
  43. package/dist/shared/utils/capacity.d.ts +26 -0
  44. package/dist/shared/utils/capacity.js +37 -0
  45. package/dist/shared/utils/capacity.js.map +1 -0
  46. package/dist/shared/utils/choiceName.d.ts +44 -0
  47. package/dist/shared/utils/choiceName.js +28 -0
  48. package/dist/shared/utils/choiceName.js.map +1 -0
  49. package/dist/shared/utils/confirmationFlow.svelte.d.ts +31 -0
  50. package/dist/shared/utils/confirmationFlow.svelte.js +41 -0
  51. package/dist/shared/utils/confirmationFlow.svelte.js.map +1 -0
  52. package/dist/shared/utils/eliminationTool.svelte.d.ts +11 -0
  53. package/dist/shared/utils/eliminationTool.svelte.js +26 -0
  54. package/dist/shared/utils/eliminationTool.svelte.js.map +1 -0
  55. package/dist/shared/utils/graphicRegions.d.ts +78 -0
  56. package/dist/shared/utils/graphicRegions.js +169 -0
  57. package/dist/shared/utils/graphicRegions.js.map +1 -0
  58. package/dist/shared/utils/interactionAria.d.ts +18 -5
  59. package/dist/shared/utils/interactionAria.js +42 -3
  60. package/dist/shared/utils/interactionAria.js.map +1 -1
  61. package/dist/shared/utils/interactionProps.d.ts +52 -0
  62. package/dist/shared/utils/interactionProps.js +14 -0
  63. package/dist/shared/utils/interactionProps.js.map +1 -0
  64. package/dist/shared/utils/matchGroupUtils.d.ts +26 -4
  65. package/dist/shared/utils/matchGroupUtils.js +25 -8
  66. package/dist/shared/utils/matchGroupUtils.js.map +1 -1
  67. package/dist/shared/utils/minimumRequirement.d.ts +56 -0
  68. package/dist/shared/utils/minimumRequirement.js +50 -0
  69. package/dist/shared/utils/minimumRequirement.js.map +1 -0
  70. package/dist/shared/utils/pairHelpers.d.ts +46 -12
  71. package/dist/shared/utils/pairHelpers.js +64 -12
  72. package/dist/shared/utils/pairHelpers.js.map +1 -1
  73. package/dist/shared/utils/radioGroup.d.ts +13 -0
  74. package/dist/shared/utils/radioGroup.js +27 -0
  75. package/dist/shared/utils/radioGroup.js.map +1 -0
  76. package/dist/shared/utils/stageImage.svelte.d.ts +56 -0
  77. package/dist/shared/utils/stageImage.svelte.js +76 -0
  78. package/dist/shared/utils/stageImage.svelte.js.map +1 -0
  79. package/dist/shared/utils/webComponentHelpers.d.ts +37 -5
  80. package/dist/shared/utils/webComponentHelpers.js +72 -19
  81. package/dist/shared/utils/webComponentHelpers.js.map +1 -1
  82. package/dist/shared.css +1 -1
  83. package/package.json +18 -18
  84. package/dist/chunks/__vite-browser-external-DwKjyYZK.js +0 -9
  85. package/dist/chunks/__vite-browser-external-DwKjyYZK.js.map +0 -1
  86. package/dist/chunks/ar-Cqx9S4Im.js +0 -919
  87. package/dist/chunks/ar-Cqx9S4Im.js.map +0 -1
  88. package/dist/chunks/es-DjA7IQ-N.js +0 -864
  89. package/dist/chunks/es-DjA7IQ-N.js.map +0 -1
  90. package/dist/chunks/fr-BhV6wQNG.js +0 -864
  91. package/dist/chunks/fr-BhV6wQNG.js.map +0 -1
  92. package/dist/chunks/nl-B0JlnB-a.js +0 -863
  93. package/dist/chunks/nl-B0JlnB-a.js.map +0 -1
  94. package/dist/chunks/ro-ClR0jejm.js +0 -864
  95. package/dist/chunks/ro-ClR0jejm.js.map +0 -1
  96. package/dist/chunks/rolldown-runtime-Y_bBpyJl.js +0 -20
  97. package/dist/chunks/th-RfNMAg5z.js +0 -863
  98. package/dist/chunks/th-RfNMAg5z.js.map +0 -1
  99. package/dist/chunks/zh-Hans-DJ82CLmG.js +0 -863
  100. package/dist/chunks/zh-Hans-DJ82CLmG.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"MathLiveEditor.js","sourceRoot":"","sources":["../../../src/shared/extensions/MathLiveEditor.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAE3B;;;;;;;GAOG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,6CAA6C;AAC7C,OAAO,qBAAqB,CAAC;AAE7B,6DAA6D;AAC7D,IAAI,cAAc,GAAyB,IAAI,CAAC;AAEhD,KAAK,UAAU,oBAAoB;IAClC,IAAI,CAAC,cAAc,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QACtD,cAAc,GAAG,CAAC,KAAK,IAAI,EAAE;YAC5B,8DAA8D;YAC9D,kDAAkD;YAClD,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC;QAC1B,CAAC,CAAC,EAAE,CAAC;IACN,CAAC;IACD,OAAO,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;AAC5C,CAAC;AAeD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,OAA8B;IACtE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,GAAG,EAAE,EAAE,OAAO,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IAE5E,yEAAyE;IACzE,MAAM,oBAAoB,EAAE,CAAC;IAE7B,mDAAmD;IACnD,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC9C,OAAO,CAAC,SAAS,GAAG,kBAAkB,CAAC;IACvC,OAAO,CAAC,KAAK,CAAC,OAAO,GAAG;;;;;;;;EAQvB,CAAC;IAEF,oDAAoD;IACpD,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC5C,KAAK,CAAC,SAAS,GAAG,qBAAqB,CAAC;IACxC,K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AAe,EAAE,CAAC;gBACtB,YAAY,EAAE,CAAC;YAChB,CAAC;QACF,CAAC;IACF,CAAC,CAAC;IAEF,yBAAyB;IACzB,SAAS,CAAC,gBAAgB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAClD,SAAS,CAAC,gBAAgB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IACnD,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;IACnD,OAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;IAEtD,yCAAyC;IACzC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAExC,aAAa;IACb,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAEnC,qDAAqD;IACrD,UAAU,CAAC,GAAG,EAAE;QACf,SAAS,CAAC,KAAK,EAAE,CAAC;QAClB,kEAAkE;QAClE,IAAI,CAAC;YACH,SAAiB,CAAC,UAAU,CAAC;gBAC7B,0BAA0B,EAAE,EAAE;aAC9B,CAAC,CAAC;QACJ,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACZ,4CAA4C;QAC7C,CAAC;IACF,CAAC,EAAE,GAAG,CAAC,CAAC;IAER,0BAA0B;IAC1B,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["/// <reference lib=\"dom\" />\n\n/**\n * MathLive Editor Extension for TipTap\n *\n * Integrates MathLive (visual math editor) with TipTap's Mathematics extension.\n * Provides a modal dialog with MathLive mathfield for editing LaTeX formulas.\n *\n * Note: MathLive CSS is loaded dynamically to avoid build issues with package exports.\n */\n\nimport { isImeComposing } from '@pie-qti/i18n';\nimport type { MathfieldElement } from 'mathlive';\n// Import MathLive CSS from the local package\nimport 'mathlive/static.css';\n\n// Dynamically import MathLive to register the custom element\nlet mathLiveLoaded: Promise<void> | null = null;\n\nasync function ensureMathLiveLoaded(): Promise<void> {\n\tif (!mathLiveLoaded && typeof window !== 'undefined') {\n\t\tmathLiveLoaded = (async () => {\n\t\t\t// Import MathLive to register the <math-field> custom element\n\t\t\t// CSS is already imported at the top of this file\n\t\t\tawait import('mathlive');\n\t\t})();\n\t}\n\treturn mathLiveLoaded || Promise.resolve();\n}\n\nexport interface MathLiveEditorOptions {\n\t/** Called when user confirms the LaTeX input */\n\tonConfirm: (latex: string) => void;\n\t/** Called when user cancels */\n\tonCancel: () => void;\n\t/** Initial LaTeX value */\n\tinitialLatex?: string;\n\t/** Whether this is inline or block math */\n\tisBlock?: boolean;\n\t/** Optional i18n provider for translations */\n\ti18n?: { t: (key: string) => string | undefined };\n}\n\n/**\n * Opens a modal dialog with MathLive editor for LaTeX input\n */\nexport async function openMathLiveEditor(options: MathLiveEditorOptions): Promise<() => void> {\n\tconst { onConfirm, onCancel, initialLatex = '', isBlock = false } = options;\n\n\t// Ensure MathLive is loaded and registered before creating the mathfield\n\tawait ensureMathLiveLoaded();\n\n\t// Create modal overlay - use DaisyUI modal classes\n\tconst overlay = document.createElement('div');\n\toverlay.className = 'modal modal-open';\n\toverlay.style.cssText = `\n\t\tposition: fixed;\n\t\tinset: 0;\n\t\tbackground: rgba(0, 0, 0, 0.5);\n\t\tdisplay: flex;\n\t\talign-items: center;\n\t\tjustify-content: center;\n\t\tz-index: 9999;\n\t`;\n\n\t// Create modal dialog - use DaisyUI modal-box class\n\tconst modal = document.createElement('div');\n\tmodal.className = 'modal-box max-w-2xl';\n\tmodal.style.cssText = `\n\t\tpadding: 1.5rem;\n\t\tposition: relative;\n\t\tz-index: 10000;\n\t`;\n\n\t// Create header - use DaisyUI font-bold text-lg\n\tconst header = document.createElement('h3');\n\theader.textContent = isBlock ? (options.i18n?.t('interactions.extendedText.insertBlockMath') ?? 'Insert Block Math') : (options.i18n?.t('interactions.extendedText.insertInlineMath') ?? 'Insert Inline Math');\n\theader.className = 'font-bold text-lg mb-4';\n\n\t// Create form control wrapper\n\tconst formControl = document.createElement('div');\n\tformControl.className = 'form-control';\n\n\t// Create label for mathfield\n\tconst label = document.createElement('label');\n\tlabel.className = 'label';\n\tconst labelText = document.createElement('span');\n\tlabelText.className = 'label-text';\n\tlabelText.textContent = options.i18n?.t('interactions.extendedText.enterMathExpression') ?? 'Enter your math expression:';\n\tlabel.appendChild(labelText);\n\n\t// Create MathLive mathfield - style like DaisyUI input\n\tconst mathfield = document.createElement('math-field') as MathfieldElement;\n\tmathfield.value = initialLatex;\n\tmathfield.className = 'input input-bordered w-full';\n\tmathfield.style.cssText = `\n\t\tdisplay: block;\n\t\tmin-height: 100px;\n\t\tpadding: 0.75rem;\n\t\tfont-size: 1.125rem;\n\t`;\n\n\t// Set MathLive options for better UX via attributes\n\t// Use 'manual' mode so keyboard only shows when explicitly requested\n\tmathfield.setAttribute('virtual-keyboard-mode', 'manual');\n\tmathfield.setAttribute('smart-mode', 'on');\n\t// Explicitly enable virtual keyboard\n\tmathfield.setAttribute('use-shared-virtual-keyboard', 'true');\n\t// Hide the built-in virtual keyboard toggle\n\tmathfield.setAttribute('virtual-keyboard-toggle-glyph', '');\n\n\t// Inject CSS to ensure virtual keyboard appears above modal and accepts clicks\n\tconst style = document.createElement('style');\n\tstyle.textContent = `\n\t\t/* Ensure MathLive virtual keyboard appears above the modal and is clickable */\n\t\t.ML__keyboard {\n\t\t\tz-index: 10001 !important;\n\t\t\tpointer-events: auto !important;\n\t\t}\n\t\t/* Hide the built-in keyboard toggle button in the mathfield - try multiple selectors */\n\t\t.ML__virtual-keyboard-toggle,\n\t\t.ML__keyboard-toggle,\n\t\tmath-field::part(virtual-keyboard-toggle) {\n\t\t\tdisplay: none !important;\n\t\t\tvisibility: hidden !important;\n\t\t\topacity: 0 !important;\n\t\t\tpointer-events: none !important;\n\t\t}\n\t`;\n\tdocument.head.appendChild(style);\n\n\t// Create LaTeX preview label\n\tconst previewLabel = document.createElement('label');\n\tpreviewLabel.className = 'label';\n\tconst previewLabelText = document.createElement('span');\n\tpreviewLabelText.className = 'label-text';\n\tpreviewLabelText.textContent = options.i18n?.t('interactions.extendedText.latexSource') ?? 'LaTeX source:';\n\tpreviewLabel.appendChild(previewLabelText);\n\n\t// Create LaTeX preview/source - use alert info styling\n\tconst latexPreview = document.createElement('div');\n\tlatexPreview.className = 'alert alert-info';\n\tlatexPreview.style.cssText = `\n\t\tfont-family: 'Monaco', 'Courier New', monospace;\n\t\tfont-size: 0.875rem;\n\t\tword-break: break-all;\n\t\tmargin-bottom: 1rem;\n\t`;\n\tlatexPreview.textContent = initialLatex || '(LaTeX will appear here)';\n\n\t// Update preview when mathfield changes\n\tmathfield.addEventListener('input', () => {\n\t\tconst latex = mathfield.value;\n\t\tlatexPreview.textContent = latex || '(LaTeX will appear here)';\n\t});\n\n\t// Create button container - use DaisyUI modal-action class\n\tconst buttons = document.createElement('div');\n\tbuttons.className = 'modal-action';\n\tbuttons.style.cssText = 'justify-content: space-between;';\n\n\t// Create left-side buttons (keyboard toggle)\n\tconst leftButtons = document.createElement('div');\n\tleftButtons.style.cssText = 'display: flex; gap: 0.5rem;';\n\n\t// Create Keyboard Toggle button\n\tconst keyboardBtn = document.createElement('button');\n\tkeyboardBtn.textContent = `⌨️ ${options.i18n?.t('interactions.extendedText.keyboard') ?? 'Keyboard'}`;\n\tkeyboardBtn.type = 'button';\n\tkeyboardBtn.className = 'btn btn-sm btn-outline';\n\tkeyboardBtn.onclick = () => {\n\t\tif (mathfield.executeCommand) {\n\t\t\tmathfield.executeCommand('toggleVirtualKeyboard');\n\t\t}\n\t};\n\n\tleftButtons.appendChild(keyboardBtn);\n\n\t// Create right-side buttons (Cancel/Insert)\n\tconst rightButtons = document.createElement('div');\n\trightButtons.style.cssText = 'display: flex; gap: 0.5rem;';\n\n\t// Create Cancel button - use DaisyUI classes\n\tconst cancelBtn = document.createElement('button');\n\tcancelBtn.textContent = options.i18n?.t('common.cancel') ?? 'Cancel';\n\tcancelBtn.type = 'button';\n\tcancelBtn.className = 'btn btn-ghost';\n\n\t// Create Insert button - use DaisyUI classes\n\tconst insertBtn = document.createElement('button');\n\tinsertBtn.textContent = initialLatex\n\t\t? (options.i18n?.t('interactions.extendedText.update') ?? 'Update')\n\t\t: (options.i18n?.t('interactions.extendedText.insert') ?? 'Insert');\n\tinsertBtn.type = 'button';\n\tinsertBtn.className = 'btn btn-primary';\n\n\trightButtons.appendChild(cancelBtn);\n\trightButtons.appendChild(insertBtn);\n\n\t// Assemble modal\n\tbuttons.appendChild(leftButtons);\n\tbuttons.appendChild(rightButtons);\n\n\t// Assemble form-control\n\tformControl.appendChild(label);\n\tformControl.appendChild(mathfield);\n\tformControl.appendChild(previewLabel);\n\tformControl.appendChild(latexPreview);\n\n\tmodal.appendChild(header);\n\tmodal.appendChild(formControl);\n\tmodal.appendChild(buttons);\n\n\toverlay.appendChild(modal);\n\n\t// Cleanup function\n\tconst cleanup = () => {\n\t\t// Remove event listeners to prevent memory leaks\n\t\tcancelBtn.removeEventListener('click', handleCancel);\n\t\tinsertBtn.removeEventListener('click', handleConfirm);\n\t\tdocument.removeEventListener('keydown', handleEscape);\n\t\toverlay.removeEventListener('click', handleOverlayClick);\n\n\t\t// Hide virtual keyboard before cleanup\n\t\tif (mathfield.executeCommand) {\n\t\t\tmathfield.executeCommand('hideVirtualKeyboard');\n\t\t}\n\n\t\t// Remove DOM elements\n\t\toverlay.remove();\n\t\tstyle.remove();\n\n\t\t// Restore body scroll\n\t\tdocument.body.style.overflow = '';\n\t};\n\n\t// Event handlers\n\tconst handleCancel = () => {\n\t\tcleanup();\n\t\tonCancel();\n\t};\n\n\tconst handleConfirm = () => {\n\t\tconst latex = mathfield.value;\n\t\tcleanup();\n\t\tonConfirm(latex);\n\t};\n\n\tconst handleEscape = (e: KeyboardEvent) => {\n\t\tif (e.key === 'Escape' && !isImeComposing(e)) {\n\t\t\thandleCancel();\n\t\t}\n\t};\n\n\tconst handleOverlayClick = (e: MouseEvent) => {\n\t\t// Don't close if clicking on the modal content or virtual keyboard\n\t\tconst target = e.target as HTMLElement;\n\n\t\t// Check if click is on overlay background (not modal or keyboard)\n\t\tif (target === overlay) {\n\t\t\t// Additional check: don't close if virtual keyboard is open\n\t\t\t// MathLive virtual keyboard has class 'ML__keyboard'\n\t\t\tconst virtualKeyboard = document.querySelector('.ML__keyboard');\n\t\t\tif (!virtualKeyboard) {\n\t\t\t\thandleCancel();\n\t\t\t}\n\t\t}\n\t};\n\n\t// Attach event listeners\n\tcancelBtn.addEventListener('click', handleCancel);\n\tinsertBtn.addEventListener('click', handleConfirm);\n\tdocument.addEventListener('keydown', handleEscape);\n\toverlay.addEventListener('click', handleOverlayClick);\n\n\t// Prevent body scroll when modal is open\n\tdocument.body.style.overflow = 'hidden';\n\n\t// Add to DOM\n\tdocument.body.appendChild(overlay);\n\n\t// Focus the mathfield (but don't auto-show keyboard)\n\tsetTimeout(() => {\n\t\tmathfield.focus();\n\t\t// Try to programmatically disable the built-in toggle via options\n\t\ttry {\n\t\t\t(mathfield as any).setOptions({\n\t\t\t\tvirtualKeyboardToggleGlyph: '',\n\t\t\t});\n\t\t} catch (e) {\n\t\t\t// Silently ignore if this API doesn't exist\n\t\t}\n\t}, 100);\n\n\t// Return cleanup function\n\treturn cleanup;\n}\n"]}
1
+ {"version":3,"file":"MathLiveEditor.js","sourceRoot":"","sources":["../../../src/shared/extensions/MathLiveEditor.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAc3B,6CAA6C;AAC7C,OAAO,qBAAqB,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE3E,6DAA6D;AAC7D,IAAI,cAAc,GAAyB,IAAI,CAAC;AAEhD,KAAK,UAAU,oBAAoB;IAClC,IAAI,CAAC,cAAc,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QACtD,cAAc,GAAG,CAAC,KAAK,IAAI,EAAE;YAC5B,8DAA8D;YAC9D,kDAAkD;YAClD,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC;QAC1B,C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Editor Extension for TipTap\n *\n * Integrates MathLive (visual math editor) with TipTap's Mathematics extension.\n * Opens a modal dialog (WAI-ARIA APG pattern: `role=\"dialog\"`, `aria-modal`,\n * named by its title, focus moved in and trapped, Escape cancels, focus\n * returned to the opener) with a labelled MathLive mathfield for LaTeX input.\n *\n * Note: MathLive CSS is loaded dynamically to avoid build issues with package exports.\n */\n\nimport type { MathfieldElement } from 'mathlive';\n// Import MathLive CSS from the local package\nimport 'mathlive/static.css';\nimport { createModalDialog, getFocusableElements } from './modalDialog.js';\n\n// Dynamically import MathLive to register the custom element\nlet mathLiveLoaded: Promise<void> | null = null;\n\nasync function ensureMathLiveLoaded(): Promise<void> {\n\tif (!mathLiveLoaded && typeof window !== 'undefined') {\n\t\tmathLiveLoaded = (async () => {\n\t\t\t// Import MathLive to register the <math-field> custom element\n\t\t\t// CSS is already imported at the top of this file\n\t\t\tawait import('mathlive');\n\t\t})();\n\t}\n\treturn mathLiveLoaded || Promise.resolve();\n}\n\n/**\n * The translation surface the editor uses; an `I18nProvider` satisfies it, and\n * so does the earlier `{ t(key) }` shape.\n */\nexport interface MathLiveEditorI18n {\n\tt: (key: string, fallback?: string, values?: Record<string, unknown>) => string | undefined;\n}\n\n/** How a dialog closed without its math being confirmed. */\nexport interface MathLiveEditorCancelDetails {\n\t/**\n\t * True when a host closed the dialog (`pie-qti-close-transient-ui`, a proctor pause), not\n\t * the candidate: the opener may keep `latex` and offer it again when the candidate reopens\n\t * the dialog, so the pause does not cost them what they typed.\n\t */\n\tinterrupted: boolean;\n\t/** The LaTeX in the field when the dialog closed (the initial value if it never opened). */\n\tlatex: string;\n}\n\nexport interface MathLiveEditorOptions {\n\t/** Called when user confirms the LaTeX input */\n\tonConfirm: (latex: string) => void;\n\t/** Called when the dialog closes without confirming: the candidate cancelled, or a host closed it. */\n\tonCancel: (details: MathLiveEditorCancelDetails) => void;\n\t/** Initial LaTeX value */\n\tinitialLatex?: string;\n\t/** Whether this is inline or block math */\n\tisBlock?: boolean;\n\t/**\n\t * Whether the dialog inserts new math or edits existing math: it sets the\n\t * title and the confirm button. Defaults to `edit` when `initialLatex` is set.\n\t */\n\tmode?: 'insert' | 'edit';\n\t/**\n\t * The control that opened the dialog, where focus returns when it closes.\n\t * Defaults to the element focused when the dialog was requested.\n\t */\n\treturnFocusTo?: HTMLElement | null;\n\t/** Optional i18n provider for translations */\n\ti18n?: MathLiveEditorI18n;\n}\n\n/** The candidate-visible strings, from `interactions.mathInput` (and `common.cancel`). */\nfunction createTranslator(i18n: MathLiveEditorI18n | undefined) {\n\treturn (key: string, fallback: string): string => {\n\t\tconst translated = i18n?.t(key, fallback);\n\t\treturn translated && translated !== key ? translated : fallback;\n\t};\n}\n\nlet dialogCount = 0;\n\n/** Dialog styles that must hold without the host's DaisyUI/Tailwind classes. */\nconst DIALOG_STYLES = `\n\t/* Keep MathLive's virtual keyboard above the modal. Its container spans the\n\t whole viewport and must keep MathLive's own pointer-events: none (only the\n\t keyboard panel takes clicks), or it would block the dialog's buttons. */\n\t.ML__keyboard {\n\t\tz-index: 10001 !important;\n\t}\n\t/* Hide the built-in keyboard toggle button in the mathfield - try multiple selectors */\n\t.ML__virtual-keyboard-toggle,\n\t.ML__keyboard-toggle,\n\tmath-field::part(virtual-keyboard-toggle) {\n\t\tdisplay: none !important;\n\t\tvisibility: hidden !important;\n\t\topacity: 0 !important;\n\t\tpointer-events: none !important;\n\t}\n\t.pie-qti-math-dialog {\n\t\tbox-sizing: border-box;\n\t\tinline-size: min(42rem, calc(100vw - 2rem));\n\t\t/* Of the backdrop's content box, which excludes an open virtual keyboard. */\n\t\tmax-block-size: calc(100% - 2rem);\n\t\toverflow: auto;\n\t\tpadding: 1.5rem;\n\t\tborder-radius: 0.75rem;\n\t\tbackground: var(--pie-qti-base-100, #ffffff);\n\t\tcolor: var(--pie-qti-base-content, #1f2937);\n\t\tposition: relative;\n\t\tz-index: 10000;\n\t}\n\t.pie-qti-math-dialog-title {\n\t\tmargin-block: 0 0.5rem;\n\t\tfont-size: 1.125rem;\n\t\tfont-weight: 700;\n\t}\n\t.pie-qti-math-dialog-instructions {\n\t\tmargin-block: 0 1rem;\n\t}\n\t.pie-qti-math-dialog-field-label {\n\t\tdisplay: block;\n\t\tmargin-block-end: 0.5rem;\n\t\tfont-weight: 600;\n\t}\n\t.pie-qti-math-dialog math-field {\n\t\tdisplay: block;\n\t\tbox-sizing: border-box;\n\t\tinline-size: 100%;\n\t\tmin-block-size: 100px;\n\t\tpadding: 0.75rem;\n\t\tfont-size: 1.125rem;\n\t\tborder: 1px solid var(--pie-qti-border-strong, #767676);\n\t\tborder-radius: 0.5rem;\n\t}\n\t.pie-qti-math-dialog math-field:focus-within {\n\t\toutline: 2px solid var(--pie-qti-focus, #4338ca);\n\t\toutline-offset: 2px;\n\t}\n\t.pie-qti-math-dialog-source-label {\n\t\tmargin-block: 1rem 0.25rem;\n\t\tfont-weight: 600;\n\t}\n\t.pie-qti-math-dialog-source {\n\t\tdisplay: block;\n\t\tmargin-block-end: 1rem;\n\t\tpadding: 0.5rem 0.75rem;\n\t\tborder: 1px solid var(--pie-qti-border-strong, #767676);\n\t\tborder-radius: 0.5rem;\n\t\tfont-family: 'Monaco', 'Courier New', monospace;\n\t\tfont-size: 0.875rem;\n\t\tword-break: break-all;\n\t}\n\t.pie-qti-math-dialog-source[data-empty='true'] {\n\t\tfont-style: italic;\n\t}\n\t.pie-qti-math-dialog-actions {\n\t\tdisplay: flex;\n\t\tflex-wrap: wrap;\n\t\tjustify-content: space-between;\n\t\tgap: 0.5rem;\n\t}\n\t.pie-qti-math-dialog-actions > div {\n\t\tdisplay: flex;\n\t\tflex-wrap: wrap;\n\t\tgap: 0.5rem;\n\t}\n\t.pie-qti-math-dialog button {\n\t\tbox-sizing: border-box;\n\t\tmin-block-size: 2.75rem;\n\t\tmin-inline-size: 2.75rem;\n\t\tpadding-block: 0.5rem;\n\t\tpadding-inline: 1rem;\n\t\tborder: 1px solid var(--pie-qti-border-strong, #767676);\n\t\tborder-radius: 0.5rem;\n\t\tbackground: var(--pie-qti-base-100, #ffffff);\n\t\tcolor: var(--pie-qti-base-content, #1f2937);\n\t\tfont: inherit;\n\t\tcursor: pointer;\n\t}\n\t.pie-qti-math-dialog button:focus-visible {\n\t\toutline: 2px solid var(--pie-qti-focus, #4338ca);\n\t\toutline-offset: 2px;\n\t}\n\t.pie-qti-math-dialog button[aria-pressed='true'] {\n\t\tfont-weight: 700;\n\t\tborder-width: 2px;\n\t}\n`;\n\ninterface VirtualKeyboardHandle {\n\tvisible?: boolean;\n\tboundingRect?: DOMRect;\n\thide?: (options?: { animate?: boolean }) => void;\n\taddEventListener?: (type: string, listener: () => void) => void;\n\tremoveEventListener?: (type: string, listener: () => void) => void;\n}\n\nfunction sharedVirtualKeyboard(): VirtualKeyboardHandle | undefined {\n\treturn (globalThis as { mathVirtualKeyboard?: VirtualKeyboardHandle }).mathVirtualKeyboard;\n}\n\n/**\n * Hosts dispatch this on `document` when transient UI must close: the assessment shell does on\n * a proctor pause (`detail.reason: 'pause'`), so no dialog stays open, or traps focus, under the\n * pause overlay. The dialog closes through its cancel path, reporting the interruption and the\n * LaTeX typed so far (`MathLiveEditorCancelDetails`), so the opener can offer it again.\n */\nconst CLOSE_TRANSIENT_UI_EVENT = 'pie-qti-close-transient-ui';\n\n/**\n * Opens a modal dialog with MathLive editor for LaTeX input.\n * Resolves to a function that closes the dialog without calling either callback.\n */\nexport async function openMathLiveEditor(options: MathLiveEditorOptions): Promise<() => void> {\n\tconst { onConfirm, onCancel, initialLatex = '', isBlock = false } = options;\n\tconst mode = options.mode ?? (initialLatex ? 'edit' : 'insert');\n\tconst t = createTranslator(options.i18n);\n\t// Capture the opener before loading MathLive, while it still holds focus.\n\tconst opener = options.returnFocusTo ?? (document.activeElement as HTMLElement | null);\n\n\t// Ensure MathLive is loaded and registered before creating the mathfield. A request to\n\t// close transient UI while it loads cancels the dialog before it ever opens.\n\tlet closedWhileLoading = false;\n\tconst cancelWhileLoading = () => {\n\t\tclosedWhileLoading = true;\n\t};\n\tdocument.addEventListener(CLOSE_TRANSIENT_UI_EVENT, cancelWhileLoading);\n\ttry {\n\t\tawait ensureMathLiveLoaded();\n\t} finally {\n\t\tdocument.removeEventListener(CLOSE_TRANSIENT_UI_EVENT, cancelWhileLoading);\n\t}\n\tif (closedWhileLoading) {\n\t\tonCancel({ interrupted: true, latex: initialLatex });\n\t\treturn () => {};\n\t}\n\n\tconst id = `pie-qti-math-dialog-${++dialogCount}`;\n\n\t// Backdrop - keeps DaisyUI modal classes for hosts that theme them\n\tconst overlay = document.createElement('div');\n\toverlay.className = 'modal modal-open pie-qti-math-dialog-backdrop';\n\toverlay.style.cssText = `\n\t\tposition: fixed;\n\t\tinset: 0;\n\t\tbackground: rgba(0, 0, 0, 0.5);\n\t\tdisplay: flex;\n\t\talign-items: center;\n\t\tjustify-content: center;\n\t\tz-index: 9999;\n\t`;\n\n\t// The dialog itself: a named, described modal\n\tconst dialog = document.createElement('div');\n\tdialog.className = 'modal-box max-w-2xl pie-qti-math-dialog';\n\tdialog.setAttribute('role', 'dialog');\n\tdialog.setAttribute('aria-modal', 'true');\n\tdialog.setAttribute('aria-labelledby', `${id}-title`);\n\tdialog.setAttribute('aria-describedby', `${id}-instructions`);\n\t// The dialog lives in the document body, outside the editor's shadow root:\n\t// carry the opener's writing direction across.\n\tif (opener?.isConnected && getComputedStyle(opener).direction === 'rtl') dialog.dir = 'rtl';\n\n\tconst title = document.createElement('h2');\n\ttitle.id = `${id}-title`;\n\ttitle.className = 'pie-qti-math-dialog-title';\n\ttitle.textContent =\n\t\tmode === 'edit'\n\t\t\t? isBlock\n\t\t\t\t? t('interactions.mathInput.editBlockTitle', 'Edit block math')\n\t\t\t\t: t('interactions.mathInput.editInlineTitle', 'Edit inline math')\n\t\t\t: isBlock\n\t\t\t\t? t('interactions.mathInput.insertBlockTitle', 'Insert block math')\n\t\t\t\t: t('interactions.mathInput.insertInlineTitle', 'Insert inline math');\n\n\tconst instructions = document.createElement('p');\n\tinstructions.id = `${id}-instructions`;\n\tinstructions.className = 'pie-qti-math-dialog-instructions';\n\tinstructions.textContent = t(\n\t\t'interactions.mathInput.instructions',\n\t\t'Type the expression, or open the math keyboard. Press Escape to cancel.',\n\t);\n\n\t// The mathfield's label: associated both ways MathLive resolves a name\n\tconst fieldLabel = document.createElement('label');\n\tfieldLabel.id = `${id}-field-label`;\n\tfieldLabel.htmlFor = `${id}-field`;\n\tfieldLabel.className = 'pie-qti-math-dialog-field-label';\n\tfieldLabel.textContent = t('interactions.mathInput.fieldLabel', 'Math expression');\n\n\tconst mathfield = document.createElement('math-field') as MathfieldElement;\n\tmathfield.id = `${id}-field`;\n\tmathfield.setAttribute('aria-labelledby', fieldLabel.id);\n\tmathfield.value = initialLatex;\n\n\t// Set MathLive options for better UX via attributes\n\t// Use 'manual' mode so keyboard only shows when explicitly requested\n\tmathfield.setAttribute('virtual-keyboard-mode', 'manual');\n\tmathfield.setAttribute('smart-mode', 'on');\n\t// Explicitly enable virtual keyboard\n\tmathfield.setAttribute('use-shared-virtual-keyboard', 'true');\n\t// Hide the built-in virtual keyboard toggle\n\tmathfield.setAttribute('virtual-keyboard-toggle-glyph', '');\n\n\t// Inject CSS: virtual keyboard layering and the dialog's own fallback styles\n\tconst style = document.createElement('style');\n\tstyle.textContent = DIALOG_STYLES;\n\tdocument.head.appendChild(style);\n\n\t// LaTeX source preview: a visual aid; the mathfield itself is what assistive technology reads\n\tconst sourceLabel = document.createElement('p');\n\tsourceLabel.className = 'pie-qti-math-dialog-source-label';\n\tsourceLabel.textContent = t('interactions.mathInput.latexSourceLabel', 'LaTeX source');\n\n\tconst latexPreview = document.createElement('code');\n\tlatexPreview.className = 'pie-qti-math-dialog-source';\n\tconst latexEmpty = t('interactions.mathInput.latexEmpty', 'LaTeX will appear here');\n\tconst showLatex = (latex: string) => {\n\t\tlatexPreview.textContent = latex || latexEmpty;\n\t\tlatexPreview.dataset.empty = latex ? 'false' : 'true';\n\t};\n\tshowLatex(initialLatex);\n\n\t// Update preview when mathfield changes\n\tmathfield.addEventListener('input', () => showLatex(mathfield.value));\n\n\t// Actions: keyboard toggle on one side, cancel/confirm on the other\n\tconst actions = document.createElement('div');\n\tactions.className = 'modal-action pie-qti-math-dialog-actions';\n\n\tconst leftActions = document.createElement('div');\n\tconst rightActions = document.createElement('div');\n\n\tconst keyboardButton = document.createElement('button');\n\tkeyboardButton.type = 'button';\n\tkeyboardButton.className = 'btn btn-sm btn-outline';\n\tkeyboardButton.textContent = t('interactions.mathInput.toggleKeyboard', 'Math keyboard');\n\tconst syncKeyboardState = () => {\n\t\tconst keyboard = sharedVirtualKeyboard();\n\t\tkeyboardButton.setAttribute('aria-pressed', keyboard?.visible ? 'true' : 'false');\n\t\t// The virtual keyboard docks over the bottom of the page, above this dialog:\n\t\t// reserve its height so the dialog (and the focused control) stays visible.\n\t\tconst height = keyboard?.visible ? (keyboard.boundingRect?.height ?? 0) : 0;\n\t\toverlay.style.paddingBlockEnd = height > 0 ? `${Math.ceil(height)}px` : '';\n\t};\n\tsyncKeyboardState();\n\tkeyboardButton.addEventListener('click', () => {\n\t\tif (mathfield.executeCommand) {\n\t\t\tmathfield.executeCommand('toggleVirtualKeyboard');\n\t\t}\n\t\tsyncKeyboardState();\n\t});\n\tsharedVirtualKeyboard()?.addEventListener?.('virtual-keyboard-toggle', syncKeyboardState);\n\tsharedVirtualKeyboard()?.addEventListener?.('geometrychange', syncKeyboardState);\n\n\tconst cancelButton = document.createElement('button');\n\tcancelButton.type = 'button';\n\tcancelButton.className = 'btn btn-ghost';\n\tcancelButton.textContent = t('common.cancel', 'Cancel');\n\n\tconst confirmButton = document.createElement('button');\n\tconfirmButton.type = 'button';\n\tconfirmButton.className = 'btn btn-primary';\n\tconfirmButton.textContent =\n\t\tmode === 'edit'\n\t\t\t? t('interactions.mathInput.update', 'Update')\n\t\t\t: t('interactions.mathInput.insert', 'Insert');\n\n\tleftActions.appendChild(keyboardButton);\n\trightActions.appendChild(cancelButton);\n\trightActions.appendChild(confirmButton);\n\tactions.appendChild(leftActions);\n\tactions.appendChild(rightActions);\n\n\tdialog.appendChild(title);\n\tdialog.appendChild(instructions);\n\tdialog.appendChild(fieldLabel);\n\tdialog.appendChild(mathfield);\n\tdialog.appendChild(sourceLabel);\n\tdialog.appendChild(latexPreview);\n\tdialog.appendChild(actions);\n\toverlay.appendChild(dialog);\n\n\tconst previousOverflow = document.body.style.overflow;\n\tlet closed = false;\n\tlet focusTimer: ReturnType<typeof setTimeout> | undefined;\n\n\t// Add to DOM, then make it modal\n\tdocument.body.appendChild(overlay);\n\t// Prevent body scroll when modal is open\n\tdocument.body.style.overflow = 'hidden';\n\n\tconst modal = createModalDialog(dialog, {\n\t\tinitialFocus: mathfield,\n\t\treturnFocusTo: opener,\n\t\tonEscape: () => close(false),\n\t});\n\n\t// MathLive reports when an arrow/Tab key has nowhere to go inside the field\n\t// (`move-out`): wrap focus to the dialog's controls instead of staying stuck.\n\t// The dialog's own Tab handler only covers keys MathLive did not claim, so\n\t// this is what makes forward wrapping work from the field.\n\tconst handleMoveOut = (event: Event) => {\n\t\tif (closed) return;\n\t\tconst direction = (event as CustomEvent<{ direction?: string }>).detail?.direction;\n\t\tconst focusable = getFocusableElements(dialog);\n\t\tif (focusable.length === 0) return;\n\t\tif (direction === 'backward') focusable[focusable.length - 1]!.focus();\n\t\telse if (direction === 'forward') focusable[0]!.focus();\n\t};\n\tmathfield.addEventListener('move-out', handleMoveOut);\n\n\t// MathLive claims Tab/Shift+Tab for placeholder navigation and prevents default\n\t// even at the field's boundary — including empty fields, where it dispatches no\n\t// `move-out` — so the dialog's Tab trap never sees those keys and backward\n\t// navigation is dead. Interaction model for this dialog: Tab keeps MathLive's\n\t// placeholder navigation (forward wrapping via `move-out`); Shift+Tab always\n\t// leaves the field backward. Reverse placeholder traversal stays on the arrow\n\t// keys, which MathLive exits correctly via `move-out`.\n\tconst handleFieldShiftTabCapture = (event: KeyboardEvent) => {\n\t\tif (closed || event.key !== 'Tab' || !event.shiftKey) return;\n\t\tif (!event.composedPath().includes(mathfield)) return;\n\t\tevent.preventDefault();\n\t\tevent.stopPropagation();\n\t\tconst focusable = getFocusableElements(dialog);\n\t\tif (focusable.length === 0) return;\n\t\tfocusable[focusable.length - 1]!.focus();\n\t};\n\tdocument.addEventListener('keydown', handleFieldShiftTabCapture, true);\n\n\tfunction teardown() {\n\t\tclosed = true;\n\t\tif (focusTimer !== undefined) clearTimeout(focusTimer);\n\t\tmathfield.removeEventListener('move-out', handleMoveOut);\n\t\tdocument.removeEventListener('keydown', handleFieldShiftTabCapture, true);\n\t\tdocument.removeEventListener(CLOSE_TRANSIENT_UI_EVENT, handleCloseTransientUi);\n\t\tcancelButton.removeEventListener('click', handleCancel);\n\t\tconfirmButton.removeEventListener('click', handleConfirm);\n\t\toverlay.removeEventListener('click', handleOverlayClick);\n\t\tsharedVirtualKeyboard()?.removeEventListener?.('virtual-keyboard-toggle', syncKeyboardState);\n\t\tsharedVirtualKeyboard()?.removeEventListener?.('geometrychange', syncKeyboardState);\n\n\t\t// Hide the shared virtual keyboard through its own API: the mathfield's\n\t\t// `hideVirtualKeyboard` command would refocus the field and schedule an\n\t\t// update that runs after the field is gone.\n\t\tconst keyboard = sharedVirtualKeyboard();\n\t\tif (keyboard?.visible) keyboard.hide?.();\n\n\t\t// Remove DOM elements\n\t\toverlay.remove();\n\t\tstyle.remove();\n\n\t\t// Restore body scroll\n\t\tdocument.body.style.overflow = previousOverflow;\n\n\t\t// Return focus to the control that opened the dialog\n\t\tmodal.release();\n\t}\n\n\tfunction close(confirmed: boolean, interrupted = false) {\n\t\tif (closed) return;\n\t\tconst latex = mathfield.value;\n\t\tteardown();\n\t\tif (confirmed) onConfirm(latex);\n\t\telse onCancel({ interrupted, latex });\n\t}\n\n\tconst handleCancel = () => close(false);\n\tconst handleConfirm = () => close(true);\n\t// A host closing transient UI (a proctor pause) cancels: the focus trap is released and\n\t// focus returns to the opener, so the host's own overlay can take it. The typed LaTeX goes\n\t// to the opener as an interrupted cancel, so it can be offered again after the pause.\n\tconst handleCloseTransientUi = () => close(false, true);\n\n\tconst handleOverlayClick = (e: MouseEvent) => {\n\t\t// Only a click on the backdrop itself closes; never one on the dialog or the\n\t\t// virtual keyboard, which MathLive attaches outside it.\n\t\tif (e.target === overlay && !document.querySelector('.ML__keyboard')) {\n\t\t\tclose(false);\n\t\t}\n\t};\n\n\tcancelButton.addEventListener('click', handleCancel);\n\tconfirmButton.addEventListener('click', handleConfirm);\n\toverlay.addEventListener('click', handleOverlayClick);\n\tdocument.addEventListener(CLOSE_TRANSIENT_UI_EVENT, handleCloseTransientUi);\n\n\t// Focus the mathfield (but don't auto-show keyboard)\n\tmodal.focusInitial();\n\tfocusTimer = setTimeout(() => {\n\t\tif (closed) return;\n\t\t// MathLive moves focus into the field after a short delay of its own; if the\n\t\t// field still has no focus by now, it never will (e.g. MathLive failed to\n\t\t// load), so focus goes to the next control in the dialog instead.\n\t\tmodal.ensureFocusInside();\n\t\t// Try to programmatically disable the built-in toggle via options\n\t\ttry {\n\t\t\t(mathfield as unknown as { setOptions?: (options: Record<string, unknown>) => void }).setOptions?.({\n\t\t\t\tvirtualKeyboardToggleGlyph: '',\n\t\t\t});\n\t\t} catch {\n\t\t\t// Silently ignore if this API doesn't exist\n\t\t}\n\t}, 100);\n\n\t// Closing from outside calls neither callback.\n\treturn () => {\n\t\tif (!closed) teardown();\n\t};\n}\n"]}
@@ -0,0 +1,31 @@
1
+ export interface ModalDialogOptions {
2
+ /** The element to focus first; defaults to the first focusable element in the dialog. */
3
+ initialFocus?: HTMLElement | null;
4
+ /** Where focus returns on release; defaults to the element focused when the dialog opened. */
5
+ returnFocusTo?: HTMLElement | null;
6
+ /** Escape was pressed (outside IME composition): the owner should close the dialog. */
7
+ onEscape?: () => void;
8
+ /** Elements outside the dialog that may hold focus while it is open (CSS selector). */
9
+ allowFocusOutside?: string;
10
+ }
11
+ export interface ModalDialogHandle {
12
+ /** Move focus into the dialog (the initial focus target, or the first focusable element). */
13
+ focusInitial(): void;
14
+ /**
15
+ * Make sure focus is inside the dialog: retry the initial target and, if it
16
+ * cannot take focus (an editor that never upgraded), focus the next
17
+ * focusable element, or the dialog itself.
18
+ */
19
+ ensureFocusInside(): void;
20
+ /** Stop trapping focus and return it to the opener. Safe to call more than once. */
21
+ release(options?: {
22
+ restoreFocus?: boolean;
23
+ }): void;
24
+ }
25
+ /** The focusable elements of `container`, in tab order (positive tabindex is not used here). */
26
+ export declare function getFocusableElements(container: HTMLElement): HTMLElement[];
27
+ /**
28
+ * Make `dialog` behave as a modal dialog until the returned handle is released.
29
+ * The dialog must already be attached to the document.
30
+ */
31
+ export declare function createModalDialog(dialog: HTMLElement, options?: ModalDialogOptions): ModalDialogHandle;
@@ -0,0 +1,165 @@
1
+ /// <reference lib="dom" />
2
+ /**
3
+ * Modal dialog behavior for overlays built from plain DOM (the MathLive editor).
4
+ *
5
+ * Implements the WAI-ARIA APG modal dialog pattern on an element that already
6
+ * carries `role="dialog"`, `aria-modal="true"` and an accessible name: focus
7
+ * moves in on open, Tab and Shift+Tab cycle within the dialog, Escape asks to
8
+ * close, and focus returns to the element that opened it when it is released.
9
+ */
10
+ import { isImeComposing } from '@pie-qti/i18n';
11
+ const FOCUSABLE_SELECTOR = [
12
+ 'a[href]',
13
+ 'button:not([disabled])',
14
+ 'input:not([disabled]):not([type="hidden"])',
15
+ 'select:not([disabled])',
16
+ 'textarea:not([disabled])',
17
+ '[contenteditable="true"]',
18
+ 'math-field',
19
+ '[tabindex]:not([tabindex="-1"])',
20
+ ].join(',');
21
+ /**
22
+ * UI that an editor inside the dialog renders outside it and that must stay
23
+ * usable (MathLive's virtual keyboard and menus are attached to the document body).
24
+ */
25
+ const DEFAULT_ALLOWED_OUTSIDE = '.ML__keyboard, .ui-menu-container, [class^="ML__"]';
26
+ /** The focusable elements of `container`, in tab order (positive tabindex is not used here). */
27
+ export function getFocusableElements(container) {
28
+ return Array.from(container.querySelectorAll(FOCUSABLE_SELECTOR)).filter((element) => !element.hasAttribute('inert') && !element.closest('[hidden], [inert]'));
29
+ }
30
+ /** The deepest focused element, looking through open shadow roots. */
31
+ function activeElementOf(doc) {
32
+ let active = doc.activeElement;
33
+ while (active?.shadowRoot?.activeElement)
34
+ active = active.shadowRoot.activeElement;
35
+ return active;
36
+ }
37
+ /** Whether `node` is `dialog` or inside it, counting shadow hosts (a math-field's internals). */
38
+ function isInside(dialog, node) {
39
+ let current = node instanceof Node ? node : null;
40
+ while (current) {
41
+ if (current === dialog)
42
+ return true;
43
+ const parent = current.parentNode;
44
+ current = parent instanceof ShadowRoot ? parent.host : parent;
45
+ }
46
+ return false;
47
+ }
48
+ /**
49
+ * Make `dialog` behave as a modal dialog until the returned handle is released.
50
+ * The dialog must already be attached to the document.
51
+ */
52
+ export function createModalDialog(dialog, options = {}) {
53
+ const doc = dialog.ownerDocument;
54
+ const opener = options.returnFocusTo ?? activeElementOf(doc);
55
+ const allowedOutside = options.allowFocusOutside ?? DEFAULT_ALLOWED_OUTSIDE;
56
+ let released = false;
57
+ const focusDialog = () => {
58
+ if (!dialog.hasAttribute('tabindex'))
59
+ dialog.setAttribute('tabindex', '-1');
60
+ dialog.focus();
61
+ };
62
+ const focusInitial = () => {
63
+ const target = options.initialFocus ?? getFocusableElements(dialog)[0];
64
+ if (target)
65
+ target.focus();
66
+ else
67
+ focusDialog();
68
+ };
69
+ const ensureFocusInside = () => {
70
+ if (isInside(dialog, activeElementOf(doc)))
71
+ return;
72
+ focusInitial();
73
+ if (isInside(dialog, activeElementOf(doc)))
74
+ return;
75
+ const fallback = getFocusableElements(dialog).find((element) => {
76
+ if (element === options.initialFocus)
77
+ return false;
78
+ element.focus();
79
+ return isInside(dialog, activeElementOf(doc));
80
+ });
81
+ if (!fallback)
82
+ focusDialog();
83
+ };
84
+ /** A dialog removed from the document by its host stops trapping without being closed. */
85
+ const detached = () => {
86
+ if (dialog.isConnected)
87
+ return false;
88
+ handle.release({ restoreFocus: false });
89
+ return true;
90
+ };
91
+ // Escape is caught on the way down, before an editor inside (MathLive maps
92
+ // Escape to its LaTeX mode) can claim it: in a modal dialog, Escape closes.
93
+ const handleEscape = (event) => {
94
+ if (detached() || event.key !== 'Escape' || isImeComposing(event))
95
+ return;
96
+ event.preventDefault();
97
+ event.stopPropagation();
98
+ options.onEscape?.();
99
+ };
100
+ // Tab is handled on the way up, so an editor that uses Tab itself (to move
101
+ // between placeholders) and prevents the default keeps it.
102
+ const handleTab = (event) => {
103
+ if (detached() || event.key !== 'Tab' || event.defaultPrevented)
104
+ return;
105
+ const focusable = getFocusableElements(dialog);
106
+ if (focusable.length === 0) {
107
+ event.preventDefault();
108
+ dialog.focus();
109
+ return;
110
+ }
111
+ const first = focusable[0];
112
+ const last = focusable[focusable.length - 1];
113
+ const active = doc.activeElement;
114
+ if (event.shiftKey && (active === first || !isInside(dialog, active))) {
115
+ event.preventDefault();
116
+ last.focus();
117
+ }
118
+ else if (!event.shiftKey && (active === last || !isInside(dialog, active))) {
119
+ event.preventDefault();
120
+ first.focus();
121
+ }
122
+ };
123
+ // Focus that escapes by other means (a click on the page behind) comes back. The focus
124
+ // moves this handler makes are not handled again: when another containment (a host's
125
+ // pause overlay) takes focus straight back, the two must not chase each other into
126
+ // unbounded recursion. That containment then keeps focus; the dialog takes it back on
127
+ // the candidate's next move.
128
+ let redirecting = false;
129
+ const handleFocusIn = (event) => {
130
+ if (redirecting || detached())
131
+ return;
132
+ const target = event.target;
133
+ if (isInside(dialog, target))
134
+ return;
135
+ if (target instanceof Element && target.closest(allowedOutside))
136
+ return;
137
+ redirecting = true;
138
+ try {
139
+ ensureFocusInside();
140
+ }
141
+ finally {
142
+ redirecting = false;
143
+ }
144
+ };
145
+ // Listening on the document covers focus that fell to the page body.
146
+ doc.addEventListener('keydown', handleEscape, true);
147
+ doc.addEventListener('keydown', handleTab);
148
+ doc.addEventListener('focusin', handleFocusIn);
149
+ const handle = {
150
+ focusInitial,
151
+ ensureFocusInside,
152
+ release({ restoreFocus = true } = {}) {
153
+ if (released)
154
+ return;
155
+ released = true;
156
+ doc.removeEventListener('keydown', handleEscape, true);
157
+ doc.removeEventListener('keydown', handleTab);
158
+ doc.removeEventListener('focusin', handleFocusIn);
159
+ if (restoreFocus && opener?.isConnected)
160
+ opener.focus();
161
+ },
162
+ };
163
+ return handle;
164
+ }
165
+ //# sourceMappingURL=modalDialog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modalDialog.js","sourceRoot":"","sources":["../../../src/shared/extensions/modalDialog.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAE3B;;;;;;;GAOG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,kBAAkB,GAAG;IAC1B,SAAS;IACT,wBAAwB;IACxB,4CAA4C;IAC5C,wBAAwB;IACxB,0BAA0B;IAC1B,0BAA0B;IAC1B,YAAY;IACZ,iCAAiC;CACjC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEZ;;;GAGG;AACH,MAAM,uBAAuB,GAAG,oDAAoD,CAAC;AA0BrF,gGAAgG;AAChG,MAAM,UAAU,oBAAoB,CAAC,SAAsB;IAC1D,OAAO,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAc,kBAAkB,CAAC,CAAC,CAAC,MAAM,CACpF,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC,CACpF,CAAC;AACH,CAAC;AAED,sEAAsE;AACtE,SAAS,eAAe,CAAC,GAAa;IACrC,IAAI,MAAM,GAAmB,GAAG,CAAC,aAAa,CAAC;IAC/C,OAAO,MAAM,EAAE,UAAU,EAAE,aAAa;QAAE,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,aAAa,CAAC;IACnF,OAAO,MAAM,CAAC;AACf,CAAC;AAED,iGAAiG;AACjG,SAAS,QAAQ,CAAC,MAAmB,EAAE,I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AAI,CAAC;QACnB,IAAI,CAAC;YACJ,iBAAiB,EAAE,CAAC;QACrB,CAAC;gBAAS,CAAC;YACV,WAAW,GAAG,KAAK,CAAC;QACrB,CAAC;IACF,CAAC,CAAC;IAEF,qEAAqE;IACrE,GAAG,CAAC,gBAAgB,CAAC,SAAS,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC;IACpD,GAAG,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAC3C,GAAG,CAAC,gBAAgB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;IAE/C,MAAM,MAAM,GAAsB;QACjC,YAAY;QACZ,iBAAiB;QACjB,OAAO,CAAC,EAAE,YAAY,GAAG,IAAI,EAAE,GAAG,EAAE;YACnC,IAAI,QAAQ;gBAAE,OAAO;YACrB,QAAQ,GAAG,IAAI,CAAC;YAChB,GAAG,CAAC,mBAAmB,CAAC,SAAS,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC;YACvD,GAAG,CAAC,mBAAmB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;YAC9C,GAAG,CAAC,mBAAmB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;YAClD,IAAI,YAAY,IAAI,MAAM,EAAE,WAAW;gBAAE,MAAM,CAAC,KAAK,EAAE,CAAC;QACzD,CAAC;KACD,CAAC;IACF,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/// <reference lib=\"dom\" />\n\n/**\n * Modal dialog behavior for overlays built from plain DOM (the MathLive editor).\n *\n * Implements the WAI-ARIA APG modal dialog pattern on an element that already\n * carries `role=\"dialog\"`, `aria-modal=\"true\"` and an accessible name: focus\n * moves in on open, Tab and Shift+Tab cycle within the dialog, Escape asks to\n * close, and focus returns to the element that opened it when it is released.\n */\n\nimport { isImeComposing } from '@pie-qti/i18n';\n\nconst FOCUSABLE_SELECTOR = [\n\t'a[href]',\n\t'button:not([disabled])',\n\t'input:not([disabled]):not([type=\"hidden\"])',\n\t'select:not([disabled])',\n\t'textarea:not([disabled])',\n\t'[contenteditable=\"true\"]',\n\t'math-field',\n\t'[tabindex]:not([tabindex=\"-1\"])',\n].join(',');\n\n/**\n * UI that an editor inside the dialog renders outside it and that must stay\n * usable (MathLive's virtual keyboard and menus are attached to the document body).\n */\nconst DEFAULT_ALLOWED_OUTSIDE = '.ML__keyboard, .ui-menu-container, [class^=\"ML__\"]';\n\nexport interface ModalDialogOptions {\n\t/** The element to focus first; defaults to the first focusable element in the dialog. */\n\tinitialFocus?: HTMLElement | null;\n\t/** Where focus returns on release; defaults to the element focused when the dialog opened. */\n\treturnFocusTo?: HTMLElement | null;\n\t/** Escape was pressed (outside IME composition): the owner should close the dialog. */\n\tonEscape?: () => void;\n\t/** Elements outside the dialog that may hold focus while it is open (CSS selector). */\n\tallowFocusOutside?: string;\n}\n\nexport interface ModalDialogHandle {\n\t/** Move focus into the dialog (the initial focus target, or the first focusable element). */\n\tfocusInitial(): void;\n\t/**\n\t * Make sure focus is inside the dialog: retry the initial target and, if it\n\t * cannot take focus (an editor that never upgraded), focus the next\n\t * focusable element, or the dialog itself.\n\t */\n\tensureFocusInside(): void;\n\t/** Stop trapping focus and return it to the opener. Safe to call more than once. */\n\trelease(options?: { restoreFocus?: boolean }): void;\n}\n\n/** The focusable elements of `container`, in tab order (positive tabindex is not used here). */\nexport function getFocusableElements(container: HTMLElement): HTMLElement[] {\n\treturn Array.from(container.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR)).filter(\n\t\t(element) => !element.hasAttribute('inert') && !element.closest('[hidden], [inert]'),\n\t);\n}\n\n/** The deepest focused element, looking through open shadow roots. */\nfunction activeElementOf(doc: Document): Element | null {\n\tlet active: Element | null = doc.activeElement;\n\twhile (active?.shadowRoot?.activeElement) active = active.shadowRoot.activeElement;\n\treturn active;\n}\n\n/** Whether `node` is `dialog` or inside it, counting shadow hosts (a math-field's internals). */\nfunction isInside(dialog: HTMLElement, node: EventTarget | null): boolean {\n\tlet current = node instanceof Node ? node : null;\n\twhile (current) {\n\t\tif (current === dialog) return true;\n\t\tconst parent: Node | null = current.parentNode;\n\t\tcurrent = parent instanceof ShadowRoot ? parent.host : parent;\n\t}\n\treturn false;\n}\n\n/**\n * Make `dialog` behave as a modal dialog until the returned handle is released.\n * The dialog must already be attached to the document.\n */\nexport function createModalDialog(dialog: HTMLElement, options: ModalDialogOptions = {}): ModalDialogHandle {\n\tconst doc = dialog.ownerDocument;\n\tconst opener = options.returnFocusTo ?? (activeElementOf(doc) as HTMLElement | null);\n\tconst allowedOutside = options.allowFocusOutside ?? DEFAULT_ALLOWED_OUTSIDE;\n\tlet released = false;\n\n\tconst focusDialog = () => {\n\t\tif (!dialog.hasAttribute('tabindex')) dialog.setAttribute('tabindex', '-1');\n\t\tdialog.focus();\n\t};\n\n\tconst focusInitial = () => {\n\t\tconst target = options.initialFocus ?? getFocusableElements(dialog)[0];\n\t\tif (target) target.focus();\n\t\telse focusDialog();\n\t};\n\n\tconst ensureFocusInside = () => {\n\t\tif (isInside(dialog, activeElementOf(doc))) return;\n\t\tfocusInitial();\n\t\tif (isInside(dialog, activeElementOf(doc))) return;\n\t\tconst fallback = getFocusableElements(dialog).find((element) => {\n\t\t\tif (element === options.initialFocus) return false;\n\t\t\telement.focus();\n\t\t\treturn isInside(dialog, activeElementOf(doc));\n\t\t});\n\t\tif (!fallback) focusDialog();\n\t};\n\n\t/** A dialog removed from the document by its host stops trapping without being closed. */\n\tconst detached = () => {\n\t\tif (dialog.isConnected) return false;\n\t\thandle.release({ restoreFocus: false });\n\t\treturn true;\n\t};\n\n\t// Escape is caught on the way down, before an editor inside (MathLive maps\n\t// Escape to its LaTeX mode) can claim it: in a modal dialog, Escape closes.\n\tconst handleEscape = (event: KeyboardEvent) => {\n\t\tif (detached() || event.key !== 'Escape' || isImeComposing(event)) return;\n\t\tevent.preventDefault();\n\t\tevent.stopPropagation();\n\t\toptions.onEscape?.();\n\t};\n\n\t// Tab is handled on the way up, so an editor that uses Tab itself (to move\n\t// between placeholders) and prevents the default keeps it.\n\tconst handleTab = (event: KeyboardEvent) => {\n\t\tif (detached() || event.key !== 'Tab' || event.defaultPrevented) return;\n\t\tconst focusable = getFocusableElements(dialog);\n\t\tif (focusable.length === 0) {\n\t\t\tevent.preventDefault();\n\t\t\tdialog.focus();\n\t\t\treturn;\n\t\t}\n\t\tconst first = focusable[0]!;\n\t\tconst last = focusable[focusable.length - 1]!;\n\t\tconst active = doc.activeElement;\n\t\tif (event.shiftKey && (active === first || !isInside(dialog, active))) {\n\t\t\tevent.preventDefault();\n\t\t\tlast.focus();\n\t\t} else if (!event.shiftKey && (active === last || !isInside(dialog, active))) {\n\t\t\tevent.preventDefault();\n\t\t\tfirst.focus();\n\t\t}\n\t};\n\n\t// Focus that escapes by other means (a click on the page behind) comes back. The focus\n\t// moves this handler makes are not handled again: when another containment (a host's\n\t// pause overlay) takes focus straight back, the two must not chase each other into\n\t// unbounded recursion. That containment then keeps focus; the dialog takes it back on\n\t// the candidate's next move.\n\tlet redirecting = false;\n\tconst handleFocusIn = (event: FocusEvent) => {\n\t\tif (redirecting || detached()) return;\n\t\tconst target = event.target;\n\t\tif (isInside(dialog, target)) return;\n\t\tif (target instanceof Element && target.closest(allowedOutside)) return;\n\t\tredirecting = true;\n\t\ttry {\n\t\t\tensureFocusInside();\n\t\t} finally {\n\t\t\tredirecting = false;\n\t\t}\n\t};\n\n\t// Listening on the document covers focus that fell to the page body.\n\tdoc.addEventListener('keydown', handleEscape, true);\n\tdoc.addEventListener('keydown', handleTab);\n\tdoc.addEventListener('focusin', handleFocusIn);\n\n\tconst handle: ModalDialogHandle = {\n\t\tfocusInitial,\n\t\tensureFocusInside,\n\t\trelease({ restoreFocus = true } = {}) {\n\t\t\tif (released) return;\n\t\t\treleased = true;\n\t\t\tdoc.removeEventListener('keydown', handleEscape, true);\n\t\t\tdoc.removeEventListener('keydown', handleTab);\n\t\t\tdoc.removeEventListener('focusin', handleFocusIn);\n\t\t\tif (restoreFocus && opener?.isConnected) opener.focus();\n\t\t},\n\t};\n\treturn handle;\n}\n"]}
@@ -8,3 +8,4 @@ export * from './extensions/MathLiveEditor.js';
8
8
  export * from './utils/eventHelpers.js';
9
9
  export * from './utils/pairHelpers.js';
10
10
  export * from './utils/interactionAria.js';
11
+ export * from './utils/graphicRegions.js';
@@ -13,4 +13,6 @@ export * from './utils/eventHelpers.js';
13
13
  export * from './utils/pairHelpers.js';
14
14
  // Authored accessible name and description for an interaction root
15
15
  export * from './utils/interactionAria.js';
16
+ // QTI graphic-region geometry (shapes, coords, markers) for the graphic interactions
17
+ export * from './utils/graphicRegions.js';
16
18
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,oCAAoC;AACpC,cAAc,4BAA4B,CAAC;AAC3C,kDAAkD;AAClD,cAAc,gCAAgC,CAAC;AAC/C,0CAA0C;AAC1C,cAAc,yBAAyB,CAAC;AACxC,qDAAqD;AACrD,cAAc,wBAAwB,CAAC;AACvC,mEAAmE;AACnE,cAAc,4BAA4B,CAAC","sourcesContent":["/**\n * Shared utilities and helpers for QTI interaction plugins\n *\n * This module exports common utilities used across all interaction plugins.\n */\n\n\n// Typeset action for math rendering\nexport * from './actions/typesetAction.js';\n// MathLive editor extension for visual math input\nexport * from './extensions/MathLiveEditor.js';\n// Event helpers for creating CustomEvents\nexport * from './utils/eventHelpers.js';\n// Pair helpers for matching/association interactions\nexport * from './utils/pairHelpers.js';\n// Authored accessible name and description for an interaction root\nexport * from './utils/interactionAria.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,oCAAoC;AACpC,cAAc,4BAA4B,CAAC;AAC3C,kDAAkD;AAClD,cAAc,gCAAgC,CAAC;AAC/C,0CAA0C;AAC1C,cAAc,yBAAyB,CAAC;AACxC,qDAAqD;AACrD,cAAc,wBAAwB,CAAC;AACvC,mEAAmE;AACnE,cAAc,4BAA4B,CAAC;AAC3C,qFAAqF;AACrF,cAAc,2BAA2B,CAAC","sourcesContent":["/**\n * Shared utilities and helpers for QTI interaction plugins\n *\n * This module exports common utilities used across all interaction plugins.\n */\n\n\n// Typeset action for math rendering\nexport * from './actions/typesetAction.js';\n// MathLive editor extension for visual math input\nexport * from './extensions/MathLiveEditor.js';\n// Event helpers for creating CustomEvents\nexport * from './utils/eventHelpers.js';\n// Pair helpers for matching/association interactions\nexport * from './utils/pairHelpers.js';\n// Authored accessible name and description for an interaction root\nexport * from './utils/interactionAria.js';\n// QTI graphic-region geometry (shapes, coords, markers) for the graphic interactions\nexport * from './utils/graphicRegions.js';\n"]}
@@ -131,6 +131,12 @@
131
131
  --pie-qti-neutral: var(--qti-scheme-fg);
132
132
  --pie-qti-neutral-content: var(--qti-scheme-bg);
133
133
  --pie-qti-focus: var(--qti-scheme-fg);
134
+ /* Message/state text and control boundaries draw in the scheme's two colours. */
135
+ --pie-qti-error-text: var(--qti-scheme-fg);
136
+ --pie-qti-warning-text: var(--qti-scheme-fg);
137
+ --pie-qti-success-text: var(--qti-scheme-fg);
138
+ --pie-qti-info-text: var(--qti-scheme-fg);
139
+ --pie-qti-border-strong: var(--qti-scheme-fg);
134
140
  }
135
141
 
136
142
  [data-qti-colorscheme] :where(a),
@@ -151,6 +157,17 @@
151
157
  filter: invert(1) hue-rotate(180deg);
152
158
  }
153
159
 
160
+ /*
161
+ * Forced colours (Windows high contrast) already paint the candidate's own palette: inverting
162
+ * it on top would turn that palette into its complement, the colours they did not choose.
163
+ */
164
+ @media (forced-colors: active) {
165
+ [data-qti-invert-polarity='invert'],
166
+ [data-qti-invert-polarity='invert'] :where(img, picture, video, canvas, object) {
167
+ filter: none;
168
+ }
169
+ }
170
+
154
171
  /* With the profile's colours, they take the scheme's place. */
155
172
  [data-qti-invert-polarity='colors'] {
156
173
  --qti-scheme-fg: var(--qti-invert-foreground, #ffffff);
@@ -174,13 +191,19 @@
174
191
  Text appearance: each property the profile sets is a token on the attribute
175
192
  ============================================================================= */
176
193
 
194
+ /*
195
+ * The --pie-qti-* typography tokens follow the profile too, so player chrome
196
+ * sized from those tokens keeps the candidate's text appearance.
197
+ */
177
198
  [data-qti-text-appearance~='font-size'] {
178
199
  font-size: var(--qti-font-size);
200
+ --pie-qti-font-size-base: var(--qti-font-size);
179
201
  }
180
202
 
181
203
  [data-qti-text-appearance~='font-family'],
182
204
  [data-qti-text-appearance~='font-family'] :where(p, li, td, th, label, span, div, button, input, textarea, select) {
183
205
  font-family: var(--qti-font-family);
206
+ --pie-qti-font-family: var(--qti-font-family);
184
207
  }
185
208
 
186
209
  [data-qti-text-appearance~='font-color'] {
@@ -189,15 +212,36 @@
189
212
  --pie-qti-base-content: var(--qti-font-color);
190
213
  }
191
214
 
215
+ /* Raised surfaces take the candidate's background too, so text on them keeps the chosen contrast. */
192
216
  [data-qti-text-appearance~='background-color'] {
193
217
  background-color: var(--qti-background-color);
194
218
  --color-base-100: var(--qti-background-color);
219
+ --color-base-200: var(--qti-background-color);
195
220
  --pie-qti-base-100: var(--qti-background-color);
221
+ --pie-qti-base-200: var(--qti-background-color);
222
+ }
223
+
224
+ /*
225
+ * The theme's message/state text, control boundary and focus colours are only checked
226
+ * against the theme's own surfaces. With the candidate's own text or background colour they
227
+ * draw in the text colour instead: the candidate's (--pie-qti-base-content is the font colour
228
+ * on this element), or the theme's when only a background is chosen. They keep the contrast
229
+ * the candidate chose; state is also conveyed by icons and text, never by colour alone.
230
+ */
231
+ [data-qti-text-appearance~='font-color'],
232
+ [data-qti-text-appearance~='background-color'] {
233
+ --pie-qti-error-text: var(--pie-qti-base-content, oklch(21% 0 0));
234
+ --pie-qti-warning-text: var(--pie-qti-base-content, oklch(21% 0 0));
235
+ --pie-qti-success-text: var(--pie-qti-base-content, oklch(21% 0 0));
236
+ --pie-qti-info-text: var(--pie-qti-base-content, oklch(21% 0 0));
237
+ --pie-qti-border-strong: var(--pie-qti-base-content, oklch(21% 0 0));
238
+ --pie-qti-focus: var(--pie-qti-base-content, oklch(21% 0 0));
196
239
  }
197
240
 
198
241
  [data-qti-text-appearance~='line-height'],
199
242
  [data-qti-text-appearance~='line-height'] :where(p, li, td, th, label, span, div) {
200
243
  line-height: var(--qti-line-height);
244
+ --pie-qti-line-height: var(--qti-line-height);
201
245
  }
202
246
 
203
247
  [data-qti-text-appearance~='letter-spacing'] {
@@ -70,9 +70,13 @@
70
70
 
71
71
  .qti-well {
72
72
  padding: 1em;
73
- border: 1px solid #ccc;
73
+ /*
74
+ * Theme-aware surface (a fixed light grey broke dark themes and PNP colour
75
+ * schemes); the border is a non-text boundary at >= 3:1 (WCAG 1.4.11).
76
+ */
77
+ border: 1px solid var(--pie-qti-border-strong, #767676);
74
78
  border-radius: 4px;
75
- background-color: #f9f9f9;
79
+ background-color: var(--pie-qti-base-200, #f9f9f9);
76
80
  }
77
81
 
78
82
  /* =============================================================================
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The one visually hidden (`.sr-only`) rule.
3
+ *
4
+ * Every element the components render for assistive technology only — live
5
+ * regions, instructions, state sentences — hides through this single rule. It
6
+ * is injected into the document (light DOM) once on import, and into each
7
+ * component's shadow root by ShadowBaseStyles, so a host needs neither
8
+ * Tailwind nor any other stylesheet for hidden content to stay hidden.
9
+ *
10
+ * An element opts in with the shared `sr-only` class, or with its
11
+ * interaction's own hook listed below (live regions keep their names: tests
12
+ * and themes target them). A new hook is added to `HIDDEN_CLASSES`, never as
13
+ * a private copy of the declarations.
14
+ */
15
+ /** The shared class any visually hidden element can carry. */
16
+ export declare const SR_ONLY_CLASS = "sr-only";
17
+ /** The rule text, injected verbatim into the document and into shadow roots. */
18
+ export declare const SR_ONLY_RULE: string;
19
+ /**
20
+ * Inject the rule into the document once. Safe to call repeatedly (and called
21
+ * on import): later calls are no-ops when the rule is already present.
22
+ */
23
+ export declare function ensureSrOnlyStyles(): void;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * The one visually hidden (`.sr-only`) rule.
3
+ *
4
+ * Every element the components render for assistive technology only — live
5
+ * regions, instructions, state sentences — hides through this single rule. It
6
+ * is injected into the document (light DOM) once on import, and into each
7
+ * component's shadow root by ShadowBaseStyles, so a host needs neither
8
+ * Tailwind nor any other stylesheet for hidden content to stay hidden.
9
+ *
10
+ * An element opts in with the shared `sr-only` class, or with its
11
+ * interaction's own hook listed below (live regions keep their names: tests
12
+ * and themes target them). A new hook is added to `HIDDEN_CLASSES`, never as
13
+ * a private copy of the declarations.
14
+ */
15
+ /** The shared class any visually hidden element can carry. */
16
+ export const SR_ONLY_CLASS = 'sr-only';
17
+ /** Class hooks that name a visually hidden element beside the shared class. */
18
+ const HIDDEN_CLASSES = [
19
+ SR_ONLY_CLASS,
20
+ // Confirmation live regions (order, graphic order)
21
+ 'qti-order-confirmation-live',
22
+ 'qti-go-confirmation-live',
23
+ // Per-interaction sr-only hooks and live regions (graphic interactions, match family)
24
+ 'qti-go-sr-only',
25
+ 'qti-ga-sr-only',
26
+ 'qti-ga-live-region',
27
+ 'qti-hotspot-sr-only',
28
+ 'qti-hotspot-live-region',
29
+ 'qti-sp-sr-only',
30
+ 'qti-po-sr-only',
31
+ 'qti-associate-live-region',
32
+ 'qti-gm-live-region',
33
+ // Shared components' live regions (order subset, minimum hint, upload)
34
+ 'qti-subset-live',
35
+ 'qti-min-hint-live',
36
+ 'qti-upload-live-region',
37
+ ];
38
+ const DECLARATIONS = [
39
+ 'position: absolute',
40
+ 'width: 1px',
41
+ 'height: 1px',
42
+ 'padding: 0',
43
+ 'margin: -1px',
44
+ 'overflow: hidden',
45
+ 'clip: rect(0, 0, 0, 0)',
46
+ 'white-space: nowrap',
47
+ 'border-width: 0',
48
+ ];
49
+ /** The rule text, injected verbatim into the document and into shadow roots. */
50
+ export const SR_ONLY_RULE = `${HIDDEN_CLASSES.map((hook) => `.${hook}`).join(',\n')} {
51
+ ${DECLARATIONS.join(';\n\t')};
52
+ }`;
53
+ const STYLE_ATTRIBUTE = 'data-sr-only-source';
54
+ const STYLE_SOURCE = 'pie-qti';
55
+ /**
56
+ * Inject the rule into the document once. Safe to call repeatedly (and called
57
+ * on import): later calls are no-ops when the rule is already present.
58
+ */
59
+ export function ensureSrOnlyStyles() {
60
+ if (typeof document === 'undefined')
61
+ return;
62
+ if (document.querySelector(`style[${STYLE_ATTRIBUTE}="${STYLE_SOURCE}"]`))
63
+ return;
64
+ const style = document.createElement('style');
65
+ style.setAttribute(STYLE_ATTRIBUTE, STYLE_SOURCE);
66
+ style.textContent = SR_ONLY_RULE;
67
+ document.head.appendChild(style);
68
+ }
69
+ ensureSrOnlyStyles();
70
+ //# sourceMappingURL=srOnly.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"srOnly.js","sourceRoot":"","sources":["../../../src/shared/styles/srOnly.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,8DAA8D;AAC9D,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AAEvC,+EAA+E;AAC/E,MAAM,cAAc,GAAsB;IACzC,aAAa;IACb,mDAAmD;IACnD,6BAA6B;IAC7B,0BAA0B;IAC1B,sFAAsF;IACtF,gBAAgB;IAChB,gBAAgB;IAChB,oBAAoB;IACpB,qBAAqB;IACrB,yBAAyB;IACzB,gBAAgB;IAChB,gBAAgB;IAChB,2BAA2B;IAC3B,oBAAoB;IACpB,uEAAuE;IACvE,iBAAiB;IACjB,mBAAmB;IACnB,wBAAwB;CACxB,CAAC;AAEF,MAAM,YAAY,GAAG;IACpB,oBAAoB;IACpB,YAAY;IACZ,aAAa;IACb,YAAY;IACZ,cAAc;IACd,kBAAkB;IAClB,wBAAwB;IACxB,qBAAqB;IACrB,iBAAiB;CACjB,CAAC;AAEF,gFAAgF;AAChF,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;GAChF,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC;EAC3B,CAAC;AAEH,MAAM,eAAe,GAAG,qBAAqB,CAAC;AAC9C,MAAM,YAAY,GAAG,SAAS,CAAC;AAE/B;;;GAGG;AACH,MAAM,UAAU,kBAAkB;IACjC,IAAI,OAAO,QAAQ,KAAK,WAAW;QAAE,OAAO;IAC5C,IAAI,QAAQ,CAAC,aAAa,CAAC,SAAS,eAAe,KAAK,YAAY,IAAI,CAAC;QAAE,OAAO;IAClF,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IAC9C,KAAK,CAAC,YAAY,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC;IAClD,KAAK,CAAC,WAAW,GAAG,YAAY,CAAC;IACjC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;AAClC,CAAC;AAED,kBAAkB,EAAE,CAAC","sourcesContent":["/**\n * The one visually hidden (`.sr-only`) rule.\n *\n * Every element the components render for assistive technology only — live\n * regions, instructions, state sentences — hides through this single rule. It\n * is injected into the document (light DOM) once on import, and into each\n * component's shadow root by ShadowBaseStyles, so a host needs neither\n * Tailwind nor any other stylesheet for hidden content to stay hidden.\n *\n * An element opts in with the shared `sr-only` class, or with its\n * interaction's own hook listed below (live regions keep their names: tests\n * and themes target them). A new hook is added to `HIDDEN_CLASSES`, never as\n * a private copy of the declarations.\n */\n\n/** The shared class any visually hidden element can carry. */\nexport const SR_ONLY_CLASS = 'sr-only';\n\n/** Class hooks that name a visually hidden element beside the shared class. */\nconst HIDDEN_CLASSES: readonly string[] = [\n\tSR_ONLY_CLASS,\n\t// Confirmation live regions (order, graphic order)\n\t'qti-order-confirmation-live',\n\t'qti-go-confirmation-live',\n\t// Per-interaction sr-only hooks and live regions (graphic interactions, match family)\n\t'qti-go-sr-only',\n\t'qti-ga-sr-only',\n\t'qti-ga-live-region',\n\t'qti-hotspot-sr-only',\n\t'qti-hotspot-live-region',\n\t'qti-sp-sr-only',\n\t'qti-po-sr-only',\n\t'qti-associate-live-region',\n\t'qti-gm-live-region',\n\t// Shared components' live regions (order subset, minimum hint, upload)\n\t'qti-subset-live',\n\t'qti-min-hint-live',\n\t'qti-upload-live-region',\n];\n\nconst DECLARATIONS = [\n\t'position: absolute',\n\t'width: 1px',\n\t'height: 1px',\n\t'padding: 0',\n\t'margin: -1px',\n\t'overflow: hidden',\n\t'clip: rect(0, 0, 0, 0)',\n\t'white-space: nowrap',\n\t'border-width: 0',\n];\n\n/** The rule text, injected verbatim into the document and into shadow roots. */\nexport const SR_ONLY_RULE = `${HIDDEN_CLASSES.map((hook) => `.${hook}`).join(',\\n')} {\n\t${DECLARATIONS.join(';\\n\\t')};\n}`;\n\nconst STYLE_ATTRIBUTE = 'data-sr-only-source';\nconst STYLE_SOURCE = 'pie-qti';\n\n/**\n * Inject the rule into the document once. Safe to call repeatedly (and called\n * on import): later calls are no-ops when the rule is already present.\n */\nexport function ensureSrOnlyStyles(): void {\n\tif (typeof document === 'undefined') return;\n\tif (document.querySelector(`style[${STYLE_ATTRIBUTE}=\"${STYLE_SOURCE}\"]`)) return;\n\tconst style = document.createElement('style');\n\tstyle.setAttribute(STYLE_ATTRIBUTE, STYLE_SOURCE);\n\tstyle.textContent = SR_ONLY_RULE;\n\tdocument.head.appendChild(style);\n}\n\nensureSrOnlyStyles();\n"]}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Accessible text of rich choice content.
3
+ *
4
+ * Choice content is rich HTML: an image-only choice must read its `alt`, a
5
+ * MathML formula must read its `alttext` (not a flattened "x2"), an SVG must
6
+ * read its `title`. `textContent` drops all of that, so names and live-region
7
+ * announcements built from it describe images as nothing at all.
8
+ *
9
+ * `accessibleTextFromHtml` walks the content in reading order and returns the
10
+ * text assistive technology would derive. It never substitutes a placeholder
11
+ * itself: callers decide the fallback, and must not fall back to "Item" or an
12
+ * identifier when content exists — a silent "Item" names every choice alike
13
+ * and makes the interaction unusable.
14
+ */
15
+ import type { HtmlContent } from '@pie-qti/item-player';
16
+ /**
17
+ * The text assistive technology would read for a rich-content HTML snippet:
18
+ * `img`/`object` alt, MathML `alttext`/`aria-label`, SVG `<title>`/`aria-label`,
19
+ * otherwise the text content. Returns '' when there is nothing to read, so the
20
+ * caller can pick a meaningful fallback. Safe on the server: falls back to a
21
+ * tag-stripping pass when no DOM is available (there, image alt text cannot be
22
+ * recovered from serialized HTML and only visible text survives).
23
+ */
24
+ export declare function accessibleTextFromHtml(html: HtmlContent | null | undefined): string;