@pie-qti/default-components 1.0.0-beta.1 → 1.0.0-beta.2

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.
@@ -1,4 +1,13 @@
1
1
  /// <reference lib="dom" />
2
+ /**
3
+ * MathLive Editor Extension for TipTap
4
+ *
5
+ * Integrates MathLive (visual math editor) with TipTap's Mathematics extension.
6
+ * Provides a modal dialog with MathLive mathfield for editing LaTeX formulas.
7
+ *
8
+ * Note: MathLive CSS is loaded dynamically to avoid build issues with package exports.
9
+ */
10
+ import { isImeComposing } from '@pie-qti/i18n';
2
11
  // Import MathLive CSS from the local package
3
12
  import 'mathlive/static.css';
4
13
  // Dynamically import MathLive to register the custom element
@@ -25,10 +34,7 @@ export async function openMathLiveEditor(options) {
25
34
  overlay.className = 'modal modal-open';
26
35
  overlay.style.cssText = `
27
36
  position: fixed;
28
- top: 0;
29
- left: 0;
30
- right: 0;
31
- bottom: 0;
37
+ inset: 0;
32
38
  background: rgba(0, 0, 0, 0.5);
33
39
  display: flex;
34
40
  align-items: center;
@@ -191,7 +197,7 @@ export async function openMathLiveEditor(options) {
191
197
  onConfirm(latex);
192
198
  };
193
199
  const handleEscape = (e) => {
194
- if (e.key === 'Escape') {
200
+ if (e.key === 'Escape' && !isImeComposing(e)) {
195
201
  handleCancel();
196
202
  }
197
203
  };
@@ -1 +1 @@
1
- {"version":3,"file":"MathLiveEditor.js","sourceRoot":"","sources":["../../../src/shared/extensions/MathLiveEditor.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAY3B,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;YA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,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 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\ttop: 0;\n\t\tleft: 0;\n\t\tright: 0;\n\t\tbottom: 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') {\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;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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AM,eAAe,GAAG,QAAQ,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;YAChE,IAAI,CAAC,eAAe,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"]}
@@ -167,7 +167,7 @@
167
167
 
168
168
  [data-qti-layout='single-column'] .qti-layout-row > * {
169
169
  width: 100%;
170
- margin-left: 0;
170
+ margin-inline-start: 0;
171
171
  }
172
172
 
173
173
  /* =============================================================================
@@ -31,6 +31,7 @@
31
31
  ============================================================================= */
32
32
 
33
33
  .qti-align-left {
34
+ /* i18n-physical: the spec defines qti-align-left as physical */
34
35
  text-align: left;
35
36
  }
36
37
 
@@ -39,6 +40,7 @@
39
40
  }
40
41
 
41
42
  .qti-align-right {
43
+ /* i18n-physical: the spec defines qti-align-right as physical */
42
44
  text-align: right;
43
45
  }
44
46
 
@@ -80,13 +82,11 @@
80
82
  .qti-layout-row {
81
83
  display: flex;
82
84
  flex-wrap: wrap;
83
- margin-left: -0.5rem;
84
- margin-right: -0.5rem;
85
+ margin-inline: -0.5rem;
85
86
  }
86
87
 
87
88
  .qti-layout-row > * {
88
- padding-left: 0.5rem;
89
- padding-right: 0.5rem;
89
+ padding-inline: 0.5rem;
90
90
  box-sizing: border-box;
91
91
  }
92
92
 
@@ -103,17 +103,17 @@
103
103
  .qti-layout-col11 { width: 91.6667%; }
104
104
  .qti-layout-col12 { width: 100%; }
105
105
 
106
- .qti-layout-offset1 { margin-left: 8.3333%; }
107
- .qti-layout-offset2 { margin-left: 16.6667%; }
108
- .qti-layout-offset3 { margin-left: 25%; }
109
- .qti-layout-offset4 { margin-left: 33.3333%; }
110
- .qti-layout-offset5 { margin-left: 41.6667%; }
111
- .qti-layout-offset6 { margin-left: 50%; }
112
- .qti-layout-offset7 { margin-left: 58.3333%; }
113
- .qti-layout-offset8 { margin-left: 66.6667%; }
114
- .qti-layout-offset9 { margin-left: 75%; }
115
- .qti-layout-offset10 { margin-left: 83.3333%; }
116
- .qti-layout-offset11 { margin-left: 91.6667%; }
106
+ .qti-layout-offset1 { margin-inline-start: 8.3333%; }
107
+ .qti-layout-offset2 { margin-inline-start: 16.6667%; }
108
+ .qti-layout-offset3 { margin-inline-start: 25%; }
109
+ .qti-layout-offset4 { margin-inline-start: 33.3333%; }
110
+ .qti-layout-offset5 { margin-inline-start: 41.6667%; }
111
+ .qti-layout-offset6 { margin-inline-start: 50%; }
112
+ .qti-layout-offset7 { margin-inline-start: 58.3333%; }
113
+ .qti-layout-offset8 { margin-inline-start: 66.6667%; }
114
+ .qti-layout-offset9 { margin-inline-start: 75%; }
115
+ .qti-layout-offset10 { margin-inline-start: 83.3333%; }
116
+ .qti-layout-offset11 { margin-inline-start: 91.6667%; }
117
117
 
118
118
  /* =============================================================================
119
119
  Padding (0–5 scale; ~4px per unit)
@@ -126,12 +126,12 @@
126
126
  .qti-padding-4 { padding: 1rem; }
127
127
  .qti-padding-5 { padding: 1.25rem; }
128
128
 
129
- .qti-padding-x-0 { padding-left: 0; padding-right: 0; }
130
- .qti-padding-x-1 { padding-left: 0.25rem; padding-right: 0.25rem; }
131
- .qti-padding-x-2 { padding-left: 0.5rem; padding-right: 0.5rem; }
132
- .qti-padding-x-3 { padding-left: 0.75rem; padding-right: 0.75rem; }
133
- .qti-padding-x-4 { padding-left: 1rem; padding-right: 1rem; }
134
- .qti-padding-x-5 { padding-left: 1.25rem; padding-right: 1.25rem; }
129
+ .qti-padding-x-0 { padding-inline: 0; }
130
+ .qti-padding-x-1 { padding-inline: 0.25rem; }
131
+ .qti-padding-x-2 { padding-inline: 0.5rem; }
132
+ .qti-padding-x-3 { padding-inline: 0.75rem; }
133
+ .qti-padding-x-4 { padding-inline: 1rem; }
134
+ .qti-padding-x-5 { padding-inline: 1.25rem; }
135
135
 
136
136
  .qti-padding-y-0 { padding-top: 0; padding-bottom: 0; }
137
137
  .qti-padding-y-1 { padding-top: 0.25rem; padding-bottom: 0.25rem; }
@@ -181,13 +181,13 @@
181
181
  .qti-margin-5 { margin: 1.25rem; }
182
182
  .qti-margin-auto { margin: auto; }
183
183
 
184
- .qti-margin-x-0 { margin-left: 0; margin-right: 0; }
185
- .qti-margin-x-1 { margin-left: 0.25rem; margin-right: 0.25rem; }
186
- .qti-margin-x-2 { margin-left: 0.5rem; margin-right: 0.5rem; }
187
- .qti-margin-x-3 { margin-left: 0.75rem; margin-right: 0.75rem; }
188
- .qti-margin-x-4 { margin-left: 1rem; margin-right: 1rem; }
189
- .qti-margin-x-5 { margin-left: 1.25rem; margin-right: 1.25rem; }
190
- .qti-margin-x-auto { margin-left: auto; margin-right: auto; }
184
+ .qti-margin-x-0 { margin-inline: 0; }
185
+ .qti-margin-x-1 { margin-inline: 0.25rem; }
186
+ .qti-margin-x-2 { margin-inline: 0.5rem; }
187
+ .qti-margin-x-3 { margin-inline: 0.75rem; }
188
+ .qti-margin-x-4 { margin-inline: 1rem; }
189
+ .qti-margin-x-5 { margin-inline: 1.25rem; }
190
+ .qti-margin-x-auto { margin-inline: auto; }
191
191
 
192
192
  .qti-margin-y-0 { margin-top: 0; margin-bottom: 0; }
193
193
  .qti-margin-y-1 { margin-top: 0.25rem; margin-bottom: 0.25rem; }
@@ -427,11 +427,12 @@
427
427
  Float
428
428
  ============================================================================= */
429
429
 
430
- .qti-float-left { float: left; }
431
- .qti-float-right { float: right; }
430
+ /* i18n-physical: qti-float-* and qti-float-clear-* are physical by spec */
431
+ .qti-float-left { float: left; } /* i18n-physical */
432
+ .qti-float-right { float: right; } /* i18n-physical */
432
433
  .qti-float-none { float: none; }
433
- .qti-float-clear-left { clear: left; }
434
- .qti-float-clear-right { clear: right; }
434
+ .qti-float-clear-left { clear: left; } /* i18n-physical */
435
+ .qti-float-clear-right { clear: right; } /* i18n-physical */
435
436
  .qti-float-clear-both { clear: both; }
436
437
  .qti-float-clearfix::after {
437
438
  content: '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-qti/default-components",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.2",
4
4
  "description": "Default Svelte-based component implementations for QTI (2.x and 3.0) player",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -28,25 +28,17 @@
28
28
  ],
29
29
  "license": "MIT",
30
30
  "dependencies": {
31
- "@pie-qti/item-player": "1.0.0-beta.1",
32
- "@pie-qti/qti-common": "1.0.0-beta.1",
31
+ "@pie-qti/i18n": "1.0.0-beta.2",
32
+ "@pie-qti/item-player": "1.0.0-beta.2",
33
+ "@pie-qti/qti-common": "1.0.0-beta.2",
33
34
  "@tiptap/core": "3.32.0",
34
35
  "@tiptap/extension-mathematics": "3.32.0",
35
36
  "@tiptap/extension-placeholder": "3.32.0",
36
37
  "@tiptap/starter-kit": "3.32.0",
37
38
  "mathlive": "^0.110.0"
38
39
  },
39
- "peerDependencies": {
40
- "@pie-qti/i18n": "1.0.0-beta.1"
41
- },
42
- "peerDependenciesMeta": {
43
- "@pie-qti/i18n": {
44
- "optional": true
45
- }
46
- },
47
40
  "devDependencies": {
48
41
  "@biomejs/biome": "^2.5.15",
49
- "@pie-qti/i18n": "1.0.0-beta.1",
50
42
  "@sveltejs/vite-plugin-svelte": "7.3.1",
51
43
  "@types/node": "^26.6.4",
52
44
  "jsdom": "^30.1.3",