@pie-qti/item-player 1.0.0-beta.0 → 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.
- package/dist/catalog/applyGlossaryTriggers.d.ts +2 -12
- package/dist/catalog/applyGlossaryTriggers.js +30 -16
- package/dist/catalog/applyGlossaryTriggers.js.map +1 -1
- package/dist/catalog/catalogLookup.d.ts +8 -4
- package/dist/catalog/catalogLookup.js +25 -16
- package/dist/catalog/catalogLookup.js.map +1 -1
- package/dist/core/ItemSession.js +4 -0
- package/dist/core/ItemSession.js.map +1 -1
- package/dist/core/Player.d.ts +4 -2
- package/dist/core/Player.js +29 -40
- package/dist/core/Player.js.map +1 -1
- package/dist/{element-class-D-kJi_w9.js → element-class-X2XXDa29.js} +2271 -2358
- package/dist/element-class-X2XXDa29.js.map +1 -0
- package/dist/element-class.d.ts +4 -2
- package/dist/element-class.js +1 -2
- package/dist/element.js +1 -1
- package/dist/element.js.map +1 -1
- package/dist/extensions/MathLiveEditor.d.ts +1 -1
- package/dist/extensions/MathLiveEditor.js +3 -5
- package/dist/extensions/MathLiveEditor.js.map +1 -1
- package/dist/interactions/extended-text/response.d.ts +5 -2
- package/dist/interactions/extended-text/response.js +16 -3
- package/dist/interactions/extended-text/response.js.map +1 -1
- package/package.json +7 -15
- package/dist/element-class-D-kJi_w9.js.map +0 -1
package/dist/element-class.d.ts
CHANGED
|
@@ -39,9 +39,11 @@ export declare class PieQtiItemPlayerElement extends HTMLElementBase {
|
|
|
39
39
|
*
|
|
40
40
|
* Applied by asking the provider for a locale-scoped view rather than by
|
|
41
41
|
* calling `setLocale()` on it: the provider is shared with everything else on
|
|
42
|
-
* the page, and `
|
|
42
|
+
* the page, and a host may have it persist or reload on `setLocale()`. Two
|
|
43
43
|
* players can therefore carry different `locale` attributes over one provider.
|
|
44
|
-
*
|
|
44
|
+
* A view whose catalog is not loaded renders English first and re-renders once
|
|
45
|
+
* its `ready` settles. Has no effect without an `i18n` provider — there is
|
|
46
|
+
* nothing to translate with.
|
|
45
47
|
*/
|
|
46
48
|
get locale(): string | undefined;
|
|
47
49
|
set locale(value: string | null | undefined);
|
package/dist/element-class.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { e as PieQtiItemPlayerElement };
|
|
1
|
+
export { t as PieQtiItemPlayerElement } from "./element-class-X2XXDa29.js";
|
package/dist/element.js
CHANGED
package/dist/element.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element.js","names":[],"sources":["../src/element.ts"],"sourcesContent":["/**\n * Side-effect entry that registers <pie-qti-item-player>.\n *\n * Import `@pie-qti/item-player/element-class` for the registration-free class.\n */\n\nimport { PieQtiItemPlayerElement } from './element-class.js';\n\nconst TAG = 'pie-qti-item-player';\n\nif (globalThis.customElements && !customElements.get(TAG)) {\n\tcustomElements.define(TAG, PieQtiItemPlayerElement);\n}\n\nexport * from './element-class.js';\n"],"mappings":";;AAQA,
|
|
1
|
+
{"version":3,"file":"element.js","names":["PieQtiItemPlayerElement","TAG"],"sources":["../src/element.ts"],"sourcesContent":["/**\n * Side-effect entry that registers <pie-qti-item-player>.\n *\n * Import `@pie-qti/item-player/element-class` for the registration-free class.\n */\n\nimport { PieQtiItemPlayerElement } from './element-class.js';\n\nconst TAG = 'pie-qti-item-player';\n\nif (globalThis.customElements && !customElements.get(TAG)) {\n\tcustomElements.define(TAG, PieQtiItemPlayerElement);\n}\n\nexport * from './element-class.js';\n"],"mappings":";;AAQA,IAAMC,IAAM;AAER,WAAW,kBAAkB,CAAC,eAAe,IAAIA,CAAG,KACvD,eAAe,OAAOA,GAAKD,CAAuB"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Note: MathLive CSS is loaded dynamically to avoid build issues with package exports.
|
|
8
8
|
*/
|
|
9
|
-
import type
|
|
9
|
+
import { type I18nProvider } from '@pie-qti/i18n';
|
|
10
10
|
import 'mathlive/mathlive-static.css';
|
|
11
11
|
export interface MathLiveEditorOptions {
|
|
12
12
|
/** Called when user confirms the LaTeX input */
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Note: MathLive CSS is loaded dynamically to avoid build issues with package exports.
|
|
8
8
|
*/
|
|
9
|
+
import { isImeComposing } from '@pie-qti/i18n';
|
|
9
10
|
// Import MathLive CSS from the local package
|
|
10
11
|
import 'mathlive/mathlive-static.css';
|
|
11
12
|
const DEFAULT_MATHLIVE_CSS_URL = ''; // No longer needed - CSS is imported above
|
|
@@ -39,10 +40,7 @@ export async function openMathLiveEditor(options) {
|
|
|
39
40
|
overlay.className = 'modal modal-open';
|
|
40
41
|
overlay.style.cssText = `
|
|
41
42
|
position: fixed;
|
|
42
|
-
|
|
43
|
-
left: 0;
|
|
44
|
-
right: 0;
|
|
45
|
-
bottom: 0;
|
|
43
|
+
inset: 0;
|
|
46
44
|
background: rgba(0, 0, 0, 0.5);
|
|
47
45
|
display: flex;
|
|
48
46
|
align-items: center;
|
|
@@ -205,7 +203,7 @@ export async function openMathLiveEditor(options) {
|
|
|
205
203
|
onConfirm(latex);
|
|
206
204
|
};
|
|
207
205
|
const handleEscape = (e) => {
|
|
208
|
-
if (e.key === 'Escape') {
|
|
206
|
+
if (e.key === 'Escape' && !isImeComposing(e)) {
|
|
209
207
|
handleCancel();
|
|
210
208
|
}
|
|
211
209
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MathLiveEditor.js","sourceRoot":"","sources":["../../src/extensions/MathLiveEditor.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,6CAA6C;AAC7C,OAAO,8BAA8B,CAAC;AAEtC,MAAM,wBAAwB,GAAG,EAAE,CAAC,CAAC,2CAA2C;AAEhF,6DAA6D;AAC7D,IAAI,cAAc,GAAyB,IAAI,CAAC;AAEhD,KAAK,UAAU,oBAAoB,CAAC,SAAiB,wBAAwB;IAC5E,IAAI,CAAC,c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AW,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":["/**\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';\nimport type { I18nProvider } from '@pie-qti/i18n';\n\n// Import MathLive CSS from the local package\nimport 'mathlive/mathlive-static.css';\n\nconst DEFAULT_MATHLIVE_CSS_URL = ''; // No longer needed - CSS is imported above\n\n// Dynamically import MathLive to register the custom element\nlet mathLiveLoaded: Promise<void> | null = null;\n\nasync function ensureMathLiveLoaded(cssUrl: string = DEFAULT_MATHLIVE_CSS_URL): 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\tawait import('mathlive');\n\n\t\t\t// CSS is already imported at the top of this file, but allow custom URL if provided\n\t\t\tif (cssUrl && !document.querySelector('link[href*=\"mathlive\"]')) {\n\t\t\t\tconst link = document.createElement('link');\n\t\t\t\tlink.rel = 'stylesheet';\n\t\t\t\tlink.href = cssUrl;\n\t\t\t\tdocument.head.appendChild(link);\n\t\t\t}\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/**\n\t * Optional MathLive stylesheet URL. Defaults to jsdelivr CDN.\n\t * Useful for CSP-restricted deployments (serve from your own domain).\n\t */\n\tcssUrl?: string;\n\t/** Optional i18n provider for translations */\n\ti18n?: I18nProvider;\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, cssUrl = DEFAULT_MATHLIVE_CSS_URL, i18n } = options;\n\n\t// Ensure MathLive is loaded and registered before creating the mathfield\n\tawait ensureMathLiveLoaded(cssUrl);\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\n\t\t? (i18n?.t('interactions.extendedText.insertBlockMath') ?? 'Insert Block Math')\n\t\t: (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 = '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 = '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 = '⌨️ 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 = '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 ? 'Update' : '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/extensions/MathLiveEditor.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,cAAc,EAAqB,MAAM,eAAe,CAAC;AAElE,6CAA6C;AAC7C,OAAO,8BAA8B,CAAC;AAEtC,MAAM,wBAAwB,GAAG,EAAE,CAAC,CAAC,2CAA2C;AAEhF,6DAA6D;AAC7D,IAAI,cAAc,GAAyB,IAAI,CAAC;AAEhD,KAAK,UAAU,oBAAoB,CAAC,SAAiB,wBAAwB;IAC5E,IAAI,CAAC,cAAc,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QACtD,cAAc,GAAG,CAAC,KAAK,IAAI,EAAE;YAC5B,8DAA8D;YAC9D,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC;YAEzB,oFAAoF;YACpF,IAAI,MAAM,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,wBAAwB,CAAC,EAAE,CAAC;gBACjE,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;gBAC5C,IAAI,CAAC,GAAG,GAAG,YA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C,CAAC;IAER,0BAA0B;IAC1B,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["/**\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';\nimport { isImeComposing, type I18nProvider } from '@pie-qti/i18n';\n\n// Import MathLive CSS from the local package\nimport 'mathlive/mathlive-static.css';\n\nconst DEFAULT_MATHLIVE_CSS_URL = ''; // No longer needed - CSS is imported above\n\n// Dynamically import MathLive to register the custom element\nlet mathLiveLoaded: Promise<void> | null = null;\n\nasync function ensureMathLiveLoaded(cssUrl: string = DEFAULT_MATHLIVE_CSS_URL): 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\tawait import('mathlive');\n\n\t\t\t// CSS is already imported at the top of this file, but allow custom URL if provided\n\t\t\tif (cssUrl && !document.querySelector('link[href*=\"mathlive\"]')) {\n\t\t\t\tconst link = document.createElement('link');\n\t\t\t\tlink.rel = 'stylesheet';\n\t\t\t\tlink.href = cssUrl;\n\t\t\t\tdocument.head.appendChild(link);\n\t\t\t}\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/**\n\t * Optional MathLive stylesheet URL. Defaults to jsdelivr CDN.\n\t * Useful for CSP-restricted deployments (serve from your own domain).\n\t */\n\tcssUrl?: string;\n\t/** Optional i18n provider for translations */\n\ti18n?: I18nProvider;\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, cssUrl = DEFAULT_MATHLIVE_CSS_URL, i18n } = options;\n\n\t// Ensure MathLive is loaded and registered before creating the mathfield\n\tawait ensureMathLiveLoaded(cssUrl);\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\n\t\t? (i18n?.t('interactions.extendedText.insertBlockMath') ?? 'Insert Block Math')\n\t\t: (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 = '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 = '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 = '⌨️ 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 = '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 ? 'Update' : '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"]}
|
|
@@ -21,8 +21,11 @@ export interface ExtendedTextNumericRecord {
|
|
|
21
21
|
nsf: number | null;
|
|
22
22
|
exponent: number | null;
|
|
23
23
|
}
|
|
24
|
-
/**
|
|
25
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Build the eight-field numeric detail record mandated by QTI. `stringValue`
|
|
26
|
+
* keeps the input as typed; the numeric fields read it in `language`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createExtendedTextNumericRecord(input: string, base?: number, language?: string): ExtendedTextNumericRecord;
|
|
26
29
|
/** Convert the current public response value into editor strings. */
|
|
27
30
|
export declare function extendedTextResponseToStrings(response: unknown, interaction: Pick<ExtendedTextInteractionData, 'cardinality' | 'base'>): string[];
|
|
28
31
|
/** Convert editor strings into the public response shape for the declaration. */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { normalizeResponse, numberMarks } from '@pie-qti/qti-processing';
|
|
1
2
|
export const EXTENDED_TEXT_RECORD_FIELD_TYPES = {
|
|
2
3
|
stringValue: 'string',
|
|
3
4
|
floatValue: 'float',
|
|
@@ -109,9 +110,21 @@ function parseNumericString(input, base) {
|
|
|
109
110
|
exponent,
|
|
110
111
|
};
|
|
111
112
|
}
|
|
112
|
-
/**
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
/**
|
|
114
|
+
* The number as `parseNumericString` reads it: digits in any script folded to
|
|
115
|
+
* 0-9, and the content language's decimal mark read as a point.
|
|
116
|
+
*/
|
|
117
|
+
function asciiNumberText(input, language) {
|
|
118
|
+
const folded = normalizeResponse(input, { language });
|
|
119
|
+
const { decimal } = numberMarks(language);
|
|
120
|
+
return decimal !== '.' && !folded.includes('.') ? folded.replace(decimal, '.') : folded;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Build the eight-field numeric detail record mandated by QTI. `stringValue`
|
|
124
|
+
* keeps the input as typed; the numeric fields read it in `language`.
|
|
125
|
+
*/
|
|
126
|
+
export function createExtendedTextNumericRecord(input, base = 10, language) {
|
|
127
|
+
const parsed = parseNumericString(asciiNumberText(input, language), base);
|
|
115
128
|
return {
|
|
116
129
|
stringValue: input,
|
|
117
130
|
floatValue: parsed.value,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response.js","sourceRoot":"","sources":["../../../src/interactions/extended-text/response.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,gCAAgC,GAAG;IAC/C,WAAW,EAAE,QAAQ;IACrB,UAAU,EAAE,OAAO;IACnB,YAAY,EAAE,SAAS;IACvB,UAAU,EAAE,SAAS;IACrB,WAAW,EAAE,SAAS;IACtB,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,QAAQ,EAAE,SAAS;CACV,CAAC;AA2BX,SAAS,UAAU,CAAC,SAAiB;IACpC,MAAM,IAAI,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IACnD,IAAI,IAAI,IAAI,EAAE,IAAI,IAAI,IAAI,EAAE;QAAE,OAAO,IAAI,GAAG,EAAE,CAAC;IAC/C,IAAI,IAAI,IAAI,EAAE,IAAI,IAAI,IAAI,EAAE;QAAE,OAAO,IAAI,GAAG,EAAE,GAAG,EAAE,CAAC;IACpD,OAAO,CAAC,CAAC,CAAC;AACX,CAAC;AAED,SAAS,WAAW,CAAC,IAAY,EAAE,IAAY;IAC9C,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,SAAS,IAAI,IAAI,EAAE,CAAC;QAC9B,MAAM,KAAK,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;QACpC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,IAAI,IAAI;YAAE,OAAO,IAAI,CAAC;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,GAAG,QAAQ;SACrB,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QACd,IAAI,WAAW,CAAC,QAAQ,KAAK,SAAS,IAAI,WAAW,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;YAC5E,OAAO,YAAY,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;QACzC,CAAC;QACD,OAAO,KAAK,CAAC;IACd,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,KAAK,EAA4B,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC;IAE9D,IAAI,WAAW,CAAC,WAAW,KAAK,UAAU,IAAI,WAAW,CAAC,WAAW,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC;IACnG,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AAC1B,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,gCAAgC,CAC/C,OAAiB,EACjB,WAAuD,EACvD,MAAe;IAEf,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,mBAAmB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IAC/E,IAAI,WAAW,KAAK,UAAU,IAAI,WAAW,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC;IAC7E,OAAO,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AAC5B,CAAC","sourcesContent":["import type { ExtendedTextInteractionData } from '../shared/types.js';\n\nexport const EXTENDED_TEXT_RECORD_FIELD_TYPES = {\n\tstringValue: 'string',\n\tfloatValue: 'float',\n\tintegerValue: 'integer',\n\tleftDigits: 'integer',\n\trightDigits: 'integer',\n\tndp: 'integer',\n\tnsf: 'integer',\n\texponent: 'integer',\n} as const;\n\nexport type ExtendedTextRecordField = keyof typeof EXTENDED_TEXT_RECORD_FIELD_TYPES;\n\n/** Public/plain representation of the numeric-detail record defined by QTI. */\nexport interface ExtendedTextNumericRecord {\n\tstringValue: string;\n\tfloatValue: number | null;\n\tintegerValue: number | null;\n\tleftDigits: number | null;\n\trightDigits: number | null;\n\tndp: number | null;\n\tnsf: number | null;\n\texponent: number | null;\n}\n\ninterface ParsedNumericString {\n\tvalid: boolean;\n\tvalue: number | null;\n\tintegerValue: number | null;\n\tleftDigits: number | null;\n\trightDigits: number | null;\n\tndp: number | null;\n\tnsf: number | null;\n\texponent: number | null;\n}\n\nfunction digitValue(character: string): number {\n\tconst code = character.toUpperCase().charCodeAt(0);\n\tif (code >= 48 && code <= 57) return code - 48;\n\tif (code >= 65 && code <= 90) return code - 65 + 10;\n\treturn -1;\n}\n\nfunction parseDigits(text: string, base: number): number | null {\n\tlet value = 0;\n\tfor (const character of text) {\n\t\tconst digit = digitValue(character);\n\t\tif (digit < 0 || digit >= base) return null;\n\t\tvalue = value * base + digit;\n\t}\n\treturn value;\n}\n\n/**\n * Parse the lexical numeric response used by QTI string interactions.\n *\n * An exponent is recognized for base 10. For other bases, letters such as E\n * are digits and therefore cannot unambiguously introduce an exponent.\n */\nfunction parseNumericString(input: string, base: number): ParsedNumericString {\n\tif (!Number.isInteger(base) || base < 2 || base > 36) {\n\t\treturn {\n\t\t\tvalid: false,\n\t\t\tvalue: null,\n\t\t\tintegerValue: null,\n\t\t\tleftDigits: null,\n\t\t\trightDigits: null,\n\t\t\tndp: null,\n\t\t\tnsf: null,\n\t\t\texponent: null,\n\t\t};\n\t}\n\n\tconst lexical = input.trim();\n\tconst match = base === 10\n\t\t? /^([+-]?)([0-9]*)(?:\\.([0-9]*))?(?:[eE]([+-]?\\d+))?$/.exec(lexical)\n\t\t: /^([+-]?)([0-9A-Za-z]*)(?:\\.([0-9A-Za-z]*))?$/.exec(lexical);\n\tconst left = match?.[2] ?? '';\n\tconst right = match?.[3] ?? '';\n\tif (!match || left.length + right.length === 0) {\n\t\treturn {\n\t\t\tvalid: false,\n\t\t\tvalue: null,\n\t\t\tintegerValue: null,\n\t\t\tleftDigits: null,\n\t\t\trightDigits: null,\n\t\t\tndp: null,\n\t\t\tnsf: null,\n\t\t\texponent: null,\n\t\t};\n\t}\n\n\tconst leftValue = parseDigits(left || '0', base);\n\tconst rightValue = parseDigits(right || '0', base);\n\tif (leftValue === null || rightValue === null) {\n\t\treturn {\n\t\t\tvalid: false,\n\t\t\tvalue: null,\n\t\t\tintegerValue: null,\n\t\t\tleftDigits: null,\n\t\t\trightDigits: null,\n\t\t\tndp: null,\n\t\t\tnsf: null,\n\t\t\texponent: null,\n\t\t};\n\t}\n\n\tconst exponent = match[4] === undefined ? null : Number.parseInt(match[4], 10);\n\tconst sign = match[1] === '-' ? -1 : 1;\n\tconst significand = leftValue + rightValue / base ** right.length;\n\tconst value = base === 10\n\t\t? Number(lexical)\n\t\t: sign * significand * base ** (exponent ?? 0);\n\tif (!Number.isFinite(value)) {\n\t\treturn {\n\t\t\tvalid: false,\n\t\t\tvalue: null,\n\t\t\tintegerValue: null,\n\t\t\tleftDigits: null,\n\t\t\trightDigits: null,\n\t\t\tndp: null,\n\t\t\tnsf: null,\n\t\t\texponent,\n\t\t};\n\t}\n\n\tconst allDigits = `${left}${right}`;\n\tconst withoutLeadingZeroes = allDigits.replace(/^0+/, '');\n\tconst nsf = withoutLeadingZeroes.length > 0 ? withoutLeadingZeroes.length : 1;\n\treturn {\n\t\tvalid: true,\n\t\tvalue,\n\t\tintegerValue: right.length === 0 && exponent === null ? value : null,\n\t\tleftDigits: left.length,\n\t\trightDigits: right.length,\n\t\tndp: Math.max(0, right.length - (exponent ?? 0)),\n\t\tnsf,\n\t\texponent,\n\t};\n}\n\n/** Build the eight-field numeric detail record mandated by QTI. */\nexport function createExtendedTextNumericRecord(input: string, base = 10): ExtendedTextNumericRecord {\n\tconst parsed = parseNumericString(input, base);\n\treturn {\n\t\tstringValue: input,\n\t\tfloatValue: parsed.value,\n\t\tintegerValue: parsed.integerValue,\n\t\tleftDigits: parsed.leftDigits,\n\t\trightDigits: parsed.rightDigits,\n\t\tndp: parsed.ndp,\n\t\tnsf: parsed.nsf,\n\t\texponent: parsed.exponent,\n\t};\n}\n\nfunction unwrapRecordStringValue(value: unknown): unknown {\n\tif (!value || typeof value !== 'object' || Array.isArray(value)) return value;\n\tconst field = (value as Record<string, unknown>).stringValue;\n\tif (field && typeof field === 'object' && 'kind' in field) {\n\t\treturn (field as { kind: string; value?: unknown }).kind === 'value'\n\t\t\t? (field as { value?: unknown }).value\n\t\t\t: '';\n\t}\n\treturn field;\n}\n\n/** Convert the current public response value into editor strings. */\nexport function extendedTextResponseToStrings(\n\tresponse: unknown,\n\tinteraction: Pick<ExtendedTextInteractionData, 'cardinality' | 'base'>,\n): string[] {\n\tif (interaction.cardinality === 'record') {\n\t\tconst raw = unwrapRecordStringValue(response);\n\t\treturn [raw === null || raw === undefined ? '' : String(raw)];\n\t}\n\tif (Array.isArray(response)) {\n\t\treturn response.length > 0 ? response.map((value) => String(value ?? '')) : [''];\n\t}\n\tif (response === null || response === undefined) return [''];\n\tif (typeof response === 'number' && interaction.base !== 10 && Number.isInteger(response)) {\n\t\treturn [response.toString(interaction.base)];\n\t}\n\treturn [String(response)];\n}\n\nfunction numericValue(input: string, interaction: Pick<ExtendedTextInteractionData, 'base' | 'baseType'>): number | null {\n\tconst parsed = parseNumericString(input, interaction.base);\n\tif (!parsed.valid || parsed.value === null) return null;\n\tif (interaction.baseType === 'integer') {\n\t\treturn parsed.integerValue;\n\t}\n\treturn parsed.value;\n}\n\nfunction hasMeaningfulString(value: string, format?: string): boolean {\n\tconst comparable = format === 'xhtml'\n\t\t? value.replace(/<[^>]*>/g, '').replace(/ | /gi, ' ')\n\t\t: value;\n\treturn comparable.trim().length > 0;\n}\n\n/** Convert editor strings into the public response shape for the declaration. */\nexport function createExtendedTextResponse(\n\tstrings: string[],\n\tinteraction: Pick<ExtendedTextInteractionData, 'cardinality' | 'baseType' | 'base'> &\n\t\tPartial<Pick<ExtendedTextInteractionData, 'format'>>,\n): string | number | Array<string | number> | ExtendedTextNumericRecord | null {\n\tconst nonEmpty = strings.filter((value) => hasMeaningfulString(value, interaction.format));\n\tif (interaction.cardinality === 'record') {\n\t\treturn nonEmpty.length === 0 ? null : createExtendedTextNumericRecord(nonEmpty[0]!, interaction.base);\n\t}\n\n\tconst values = nonEmpty\n\t\t.map((value) => {\n\t\t\tif (interaction.baseType === 'integer' || interaction.baseType === 'float') {\n\t\t\t\treturn numericValue(value, interaction);\n\t\t\t}\n\t\t\treturn value;\n\t\t})\n\t\t.filter((value): value is string | number => value !== null);\n\n\tif (interaction.cardinality === 'multiple' || interaction.cardinality === 'ordered') return values;\n\treturn values[0] ?? null;\n}\n\n/** Raw companion response captured by stringIdentifier. */\nexport function createExtendedTextStringResponse(\n\tstrings: string[],\n\tcardinality: ExtendedTextInteractionData['cardinality'],\n\tformat?: string,\n): string | string[] | null {\n\tconst nonEmpty = strings.filter((value) => hasMeaningfulString(value, format));\n\tif (cardinality === 'multiple' || cardinality === 'ordered') return nonEmpty;\n\treturn nonEmpty[0] ?? null;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"response.js","sourceRoot":"","sources":["../../../src/interactions/extended-text/response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGzE,MAAM,CAAC,MAAM,gCAAgC,GAAG;IAC/C,WAAW,EAAE,QAAQ;IACrB,UAAU,EAAE,OAAO;IACnB,YAAY,EAAE,SAAS;IACvB,UAAU,EAAE,SAAS;IACrB,WAAW,EAAE,SAAS;IACtB,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,QAAQ,EAAE,SAAS;CACV,CAAC;AA2BX,SAAS,UAAU,CAAC,SAAiB;IACpC,MAAM,IAAI,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IACnD,IAAI,IAAI,IAAI,EAAE,IAAI,IAAI,IAAI,EAAE;QAAE,OAAO,IAAI,GAAG,EAAE,CAAC;IAC/C,IAAI,IAAI,IAAI,EAAE,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O,MAAM,CAAC;IACnG,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AAC1B,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,gCAAgC,CAC/C,OAAiB,EACjB,WAAuD,EACvD,MAAe;IAEf,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,mBAAmB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IAC/E,IAAI,WAAW,KAAK,UAAU,IAAI,WAAW,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC;IAC7E,OAAO,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AAC5B,CAAC","sourcesContent":["import { normalizeResponse, numberMarks } from '@pie-qti/qti-processing';\nimport type { ExtendedTextInteractionData } from '../shared/types.js';\n\nexport const EXTENDED_TEXT_RECORD_FIELD_TYPES = {\n\tstringValue: 'string',\n\tfloatValue: 'float',\n\tintegerValue: 'integer',\n\tleftDigits: 'integer',\n\trightDigits: 'integer',\n\tndp: 'integer',\n\tnsf: 'integer',\n\texponent: 'integer',\n} as const;\n\nexport type ExtendedTextRecordField = keyof typeof EXTENDED_TEXT_RECORD_FIELD_TYPES;\n\n/** Public/plain representation of the numeric-detail record defined by QTI. */\nexport interface ExtendedTextNumericRecord {\n\tstringValue: string;\n\tfloatValue: number | null;\n\tintegerValue: number | null;\n\tleftDigits: number | null;\n\trightDigits: number | null;\n\tndp: number | null;\n\tnsf: number | null;\n\texponent: number | null;\n}\n\ninterface ParsedNumericString {\n\tvalid: boolean;\n\tvalue: number | null;\n\tintegerValue: number | null;\n\tleftDigits: number | null;\n\trightDigits: number | null;\n\tndp: number | null;\n\tnsf: number | null;\n\texponent: number | null;\n}\n\nfunction digitValue(character: string): number {\n\tconst code = character.toUpperCase().charCodeAt(0);\n\tif (code >= 48 && code <= 57) return code - 48;\n\tif (code >= 65 && code <= 90) return code - 65 + 10;\n\treturn -1;\n}\n\nfunction parseDigits(text: string, base: number): number | null {\n\tlet value = 0;\n\tfor (const character of text) {\n\t\tconst digit = digitValue(character);\n\t\tif (digit < 0 || digit >= base) return null;\n\t\tvalue = value * base + digit;\n\t}\n\treturn value;\n}\n\n/**\n * Parse the lexical numeric response used by QTI string interactions.\n *\n * An exponent is recognized for base 10. For other bases, letters such as E\n * are digits and therefore cannot unambiguously introduce an exponent.\n */\nfunction parseNumericString(input: string, base: number): ParsedNumericString {\n\tif (!Number.isInteger(base) || base < 2 || base > 36) {\n\t\treturn {\n\t\t\tvalid: false,\n\t\t\tvalue: null,\n\t\t\tintegerValue: null,\n\t\t\tleftDigits: null,\n\t\t\trightDigits: null,\n\t\t\tndp: null,\n\t\t\tnsf: null,\n\t\t\texponent: null,\n\t\t};\n\t}\n\n\tconst lexical = input.trim();\n\tconst match = base === 10\n\t\t? /^([+-]?)([0-9]*)(?:\\.([0-9]*))?(?:[eE]([+-]?\\d+))?$/.exec(lexical)\n\t\t: /^([+-]?)([0-9A-Za-z]*)(?:\\.([0-9A-Za-z]*))?$/.exec(lexical);\n\tconst left = match?.[2] ?? '';\n\tconst right = match?.[3] ?? '';\n\tif (!match || left.length + right.length === 0) {\n\t\treturn {\n\t\t\tvalid: false,\n\t\t\tvalue: null,\n\t\t\tintegerValue: null,\n\t\t\tleftDigits: null,\n\t\t\trightDigits: null,\n\t\t\tndp: null,\n\t\t\tnsf: null,\n\t\t\texponent: null,\n\t\t};\n\t}\n\n\tconst leftValue = parseDigits(left || '0', base);\n\tconst rightValue = parseDigits(right || '0', base);\n\tif (leftValue === null || rightValue === null) {\n\t\treturn {\n\t\t\tvalid: false,\n\t\t\tvalue: null,\n\t\t\tintegerValue: null,\n\t\t\tleftDigits: null,\n\t\t\trightDigits: null,\n\t\t\tndp: null,\n\t\t\tnsf: null,\n\t\t\texponent: null,\n\t\t};\n\t}\n\n\tconst exponent = match[4] === undefined ? null : Number.parseInt(match[4], 10);\n\tconst sign = match[1] === '-' ? -1 : 1;\n\tconst significand = leftValue + rightValue / base ** right.length;\n\tconst value = base === 10\n\t\t? Number(lexical)\n\t\t: sign * significand * base ** (exponent ?? 0);\n\tif (!Number.isFinite(value)) {\n\t\treturn {\n\t\t\tvalid: false,\n\t\t\tvalue: null,\n\t\t\tintegerValue: null,\n\t\t\tleftDigits: null,\n\t\t\trightDigits: null,\n\t\t\tndp: null,\n\t\t\tnsf: null,\n\t\t\texponent,\n\t\t};\n\t}\n\n\tconst allDigits = `${left}${right}`;\n\tconst withoutLeadingZeroes = allDigits.replace(/^0+/, '');\n\tconst nsf = withoutLeadingZeroes.length > 0 ? withoutLeadingZeroes.length : 1;\n\treturn {\n\t\tvalid: true,\n\t\tvalue,\n\t\tintegerValue: right.length === 0 && exponent === null ? value : null,\n\t\tleftDigits: left.length,\n\t\trightDigits: right.length,\n\t\tndp: Math.max(0, right.length - (exponent ?? 0)),\n\t\tnsf,\n\t\texponent,\n\t};\n}\n\n/**\n * The number as `parseNumericString` reads it: digits in any script folded to\n * 0-9, and the content language's decimal mark read as a point.\n */\nfunction asciiNumberText(input: string, language: string | undefined): string {\n\tconst folded = normalizeResponse(input, { language });\n\tconst { decimal } = numberMarks(language);\n\treturn decimal !== '.' && !folded.includes('.') ? folded.replace(decimal, '.') : folded;\n}\n\n/**\n * Build the eight-field numeric detail record mandated by QTI. `stringValue`\n * keeps the input as typed; the numeric fields read it in `language`.\n */\nexport function createExtendedTextNumericRecord(input: string, base = 10, language?: string): ExtendedTextNumericRecord {\n\tconst parsed = parseNumericString(asciiNumberText(input, language), base);\n\treturn {\n\t\tstringValue: input,\n\t\tfloatValue: parsed.value,\n\t\tintegerValue: parsed.integerValue,\n\t\tleftDigits: parsed.leftDigits,\n\t\trightDigits: parsed.rightDigits,\n\t\tndp: parsed.ndp,\n\t\tnsf: parsed.nsf,\n\t\texponent: parsed.exponent,\n\t};\n}\n\nfunction unwrapRecordStringValue(value: unknown): unknown {\n\tif (!value || typeof value !== 'object' || Array.isArray(value)) return value;\n\tconst field = (value as Record<string, unknown>).stringValue;\n\tif (field && typeof field === 'object' && 'kind' in field) {\n\t\treturn (field as { kind: string; value?: unknown }).kind === 'value'\n\t\t\t? (field as { value?: unknown }).value\n\t\t\t: '';\n\t}\n\treturn field;\n}\n\n/** Convert the current public response value into editor strings. */\nexport function extendedTextResponseToStrings(\n\tresponse: unknown,\n\tinteraction: Pick<ExtendedTextInteractionData, 'cardinality' | 'base'>,\n): string[] {\n\tif (interaction.cardinality === 'record') {\n\t\tconst raw = unwrapRecordStringValue(response);\n\t\treturn [raw === null || raw === undefined ? '' : String(raw)];\n\t}\n\tif (Array.isArray(response)) {\n\t\treturn response.length > 0 ? response.map((value) => String(value ?? '')) : [''];\n\t}\n\tif (response === null || response === undefined) return [''];\n\tif (typeof response === 'number' && interaction.base !== 10 && Number.isInteger(response)) {\n\t\treturn [response.toString(interaction.base)];\n\t}\n\treturn [String(response)];\n}\n\nfunction numericValue(input: string, interaction: Pick<ExtendedTextInteractionData, 'base' | 'baseType'>): number | null {\n\tconst parsed = parseNumericString(input, interaction.base);\n\tif (!parsed.valid || parsed.value === null) return null;\n\tif (interaction.baseType === 'integer') {\n\t\treturn parsed.integerValue;\n\t}\n\treturn parsed.value;\n}\n\nfunction hasMeaningfulString(value: string, format?: string): boolean {\n\tconst comparable = format === 'xhtml'\n\t\t? value.replace(/<[^>]*>/g, '').replace(/ | /gi, ' ')\n\t\t: value;\n\treturn comparable.trim().length > 0;\n}\n\n/** Convert editor strings into the public response shape for the declaration. */\nexport function createExtendedTextResponse(\n\tstrings: string[],\n\tinteraction: Pick<ExtendedTextInteractionData, 'cardinality' | 'baseType' | 'base'> &\n\t\tPartial<Pick<ExtendedTextInteractionData, 'format'>>,\n): string | number | Array<string | number> | ExtendedTextNumericRecord | null {\n\tconst nonEmpty = strings.filter((value) => hasMeaningfulString(value, interaction.format));\n\tif (interaction.cardinality === 'record') {\n\t\treturn nonEmpty.length === 0 ? null : createExtendedTextNumericRecord(nonEmpty[0]!, interaction.base);\n\t}\n\n\tconst values = nonEmpty\n\t\t.map((value) => {\n\t\t\tif (interaction.baseType === 'integer' || interaction.baseType === 'float') {\n\t\t\t\treturn numericValue(value, interaction);\n\t\t\t}\n\t\t\treturn value;\n\t\t})\n\t\t.filter((value): value is string | number => value !== null);\n\n\tif (interaction.cardinality === 'multiple' || interaction.cardinality === 'ordered') return values;\n\treturn values[0] ?? null;\n}\n\n/** Raw companion response captured by stringIdentifier. */\nexport function createExtendedTextStringResponse(\n\tstrings: string[],\n\tcardinality: ExtendedTextInteractionData['cardinality'],\n\tformat?: string,\n): string | string[] | null {\n\tconst nonEmpty = strings.filter((value) => hasMeaningfulString(value, format));\n\tif (cardinality === 'multiple' || cardinality === 'ordered') return nonEmpty;\n\treturn nonEmpty[0] ?? null;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-qti/item-player",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.2",
|
|
4
4
|
"description": "Modern QTI player supporting QTI 2.2 and 3.0 - Client-side with optional backend hooks",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -27,29 +27,21 @@
|
|
|
27
27
|
],
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@pie-qti/
|
|
31
|
-
"@pie-qti/
|
|
32
|
-
"@pie-qti/qti-
|
|
30
|
+
"@pie-qti/i18n": "1.0.0-beta.2",
|
|
31
|
+
"@pie-qti/ims-cp-core": "1.0.0-beta.2",
|
|
32
|
+
"@pie-qti/qti-common": "1.0.0-beta.2",
|
|
33
|
+
"@pie-qti/qti-processing": "1.0.0-beta.2",
|
|
33
34
|
"mathlive": "^0.110.0",
|
|
34
35
|
"node-html-parser": "^9.0.4"
|
|
35
36
|
},
|
|
36
|
-
"peerDependencies": {
|
|
37
|
-
"@pie-qti/i18n": "1.0.0-beta.0"
|
|
38
|
-
},
|
|
39
|
-
"peerDependenciesMeta": {
|
|
40
|
-
"@pie-qti/i18n": {
|
|
41
|
-
"optional": true
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
37
|
"devDependencies": {
|
|
45
38
|
"@biomejs/biome": "^2.5.15",
|
|
46
|
-
"@
|
|
47
|
-
"@sveltejs/vite-plugin-svelte": "^7.3.0",
|
|
39
|
+
"@sveltejs/vite-plugin-svelte": "^7.3.1",
|
|
48
40
|
"@types/node": "^26.6.4",
|
|
49
41
|
"svelte": "^5.57.1",
|
|
50
42
|
"svelte-check": "^4.7.5",
|
|
51
43
|
"typescript": "^5.9.3",
|
|
52
|
-
"vite": "^8.
|
|
44
|
+
"vite": "^8.3.4",
|
|
53
45
|
"vite-plugin-dts": "^5.1.2"
|
|
54
46
|
},
|
|
55
47
|
"exports": {
|