@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.
- package/README.md +13 -0
- package/dist/chunks/{mathlive.min-Cmxm6f5R.js → mathlive.min-DHkAtaP5.js} +15 -16
- package/dist/chunks/{mathlive.min-Cmxm6f5R.js.map → mathlive.min-DHkAtaP5.js.map} +1 -1
- package/dist/index.js +13 -110
- package/dist/index.js.map +1 -1
- package/dist/plugins/extended-text/textInput.d.ts +47 -0
- package/dist/plugins/extended-text/textInput.js +65 -0
- package/dist/plugins/extended-text/textInput.js.map +1 -0
- package/dist/plugins/media/mediaPlayback.d.ts +39 -0
- package/dist/plugins/media/mediaPlayback.js +49 -0
- package/dist/plugins/media/mediaPlayback.js.map +1 -0
- package/dist/plugins.js +13779 -21944
- package/dist/plugins.js.map +1 -1
- package/dist/shared/components/icons.d.ts +12 -0
- package/dist/shared/components/icons.js +13 -0
- package/dist/shared/components/icons.js.map +1 -0
- package/dist/shared/components/keyboardCrosshair.svelte.d.ts +37 -0
- package/dist/shared/components/keyboardCrosshair.svelte.js +67 -0
- package/dist/shared/components/keyboardCrosshair.svelte.js.map +1 -0
- package/dist/shared/components/pickUpPlace.svelte.d.ts +42 -0
- package/dist/shared/components/pickUpPlace.svelte.js +58 -0
- package/dist/shared/components/pickUpPlace.svelte.js.map +1 -0
- package/dist/shared/extensions/MathLiveEditor.d.ts +33 -6
- package/dist/shared/extensions/MathLiveEditor.js +354 -175
- package/dist/shared/extensions/MathLiveEditor.js.map +1 -1
- package/dist/shared/extensions/modalDialog.d.ts +31 -0
- package/dist/shared/extensions/modalDialog.js +165 -0
- package/dist/shared/extensions/modalDialog.js.map +1 -0
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.js +2 -0
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/styles/qti-pnp.css +44 -0
- package/dist/shared/styles/qti-shared-vocabulary.css +6 -2
- package/dist/shared/styles/srOnly.d.ts +23 -0
- package/dist/shared/styles/srOnly.js +70 -0
- package/dist/shared/styles/srOnly.js.map +1 -0
- package/dist/shared/utils/accessibleText.d.ts +24 -0
- package/dist/shared/utils/accessibleText.js +72 -0
- package/dist/shared/utils/accessibleText.js.map +1 -0
- package/dist/shared/utils/announcer.svelte.d.ts +26 -0
- package/dist/shared/utils/announcer.svelte.js +30 -0
- package/dist/shared/utils/announcer.svelte.js.map +1 -0
- package/dist/shared/utils/capacity.d.ts +26 -0
- package/dist/shared/utils/capacity.js +37 -0
- package/dist/shared/utils/capacity.js.map +1 -0
- package/dist/shared/utils/choiceName.d.ts +44 -0
- package/dist/shared/utils/choiceName.js +28 -0
- package/dist/shared/utils/choiceName.js.map +1 -0
- package/dist/shared/utils/confirmationFlow.svelte.d.ts +31 -0
- package/dist/shared/utils/confirmationFlow.svelte.js +41 -0
- package/dist/shared/utils/confirmationFlow.svelte.js.map +1 -0
- package/dist/shared/utils/eliminationTool.svelte.d.ts +11 -0
- package/dist/shared/utils/eliminationTool.svelte.js +26 -0
- package/dist/shared/utils/eliminationTool.svelte.js.map +1 -0
- package/dist/shared/utils/graphicRegions.d.ts +78 -0
- package/dist/shared/utils/graphicRegions.js +169 -0
- package/dist/shared/utils/graphicRegions.js.map +1 -0
- package/dist/shared/utils/interactionAria.d.ts +18 -5
- package/dist/shared/utils/interactionAria.js +42 -3
- package/dist/shared/utils/interactionAria.js.map +1 -1
- package/dist/shared/utils/interactionProps.d.ts +52 -0
- package/dist/shared/utils/interactionProps.js +14 -0
- package/dist/shared/utils/interactionProps.js.map +1 -0
- package/dist/shared/utils/matchGroupUtils.d.ts +26 -4
- package/dist/shared/utils/matchGroupUtils.js +25 -8
- package/dist/shared/utils/matchGroupUtils.js.map +1 -1
- package/dist/shared/utils/minimumRequirement.d.ts +56 -0
- package/dist/shared/utils/minimumRequirement.js +50 -0
- package/dist/shared/utils/minimumRequirement.js.map +1 -0
- package/dist/shared/utils/pairHelpers.d.ts +46 -12
- package/dist/shared/utils/pairHelpers.js +64 -12
- package/dist/shared/utils/pairHelpers.js.map +1 -1
- package/dist/shared/utils/radioGroup.d.ts +13 -0
- package/dist/shared/utils/radioGroup.js +27 -0
- package/dist/shared/utils/radioGroup.js.map +1 -0
- package/dist/shared/utils/stageImage.svelte.d.ts +56 -0
- package/dist/shared/utils/stageImage.svelte.js +76 -0
- package/dist/shared/utils/stageImage.svelte.js.map +1 -0
- package/dist/shared/utils/webComponentHelpers.d.ts +37 -5
- package/dist/shared/utils/webComponentHelpers.js +72 -19
- package/dist/shared/utils/webComponentHelpers.js.map +1 -1
- package/dist/shared.css +1 -1
- package/package.json +18 -18
- package/dist/chunks/__vite-browser-external-DwKjyYZK.js +0 -9
- package/dist/chunks/__vite-browser-external-DwKjyYZK.js.map +0 -1
- package/dist/chunks/ar-Cqx9S4Im.js +0 -919
- package/dist/chunks/ar-Cqx9S4Im.js.map +0 -1
- package/dist/chunks/es-DjA7IQ-N.js +0 -864
- package/dist/chunks/es-DjA7IQ-N.js.map +0 -1
- package/dist/chunks/fr-BhV6wQNG.js +0 -864
- package/dist/chunks/fr-BhV6wQNG.js.map +0 -1
- package/dist/chunks/nl-B0JlnB-a.js +0 -863
- package/dist/chunks/nl-B0JlnB-a.js.map +0 -1
- package/dist/chunks/ro-ClR0jejm.js +0 -864
- package/dist/chunks/ro-ClR0jejm.js.map +0 -1
- package/dist/chunks/rolldown-runtime-Y_bBpyJl.js +0 -20
- package/dist/chunks/th-RfNMAg5z.js +0 -863
- package/dist/chunks/th-RfNMAg5z.js.map +0 -1
- package/dist/chunks/zh-Hans-DJ82CLmG.js +0 -863
- package/dist/chunks/zh-Hans-DJ82CLmG.js.map +0 -1
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
/** Collapse runs of whitespace so announcements read like sentences, not source. */
|
|
16
|
+
function collapseWhitespace(text) {
|
|
17
|
+
return text.replace(/\s+/g, ' ').trim();
|
|
18
|
+
}
|
|
19
|
+
/** An element's own text alternative (`alt`, `alttext`, `aria-label`, `<title>`), if any. */
|
|
20
|
+
function ownAlternative(element) {
|
|
21
|
+
const tag = element.tagName.toLowerCase();
|
|
22
|
+
if (tag === 'img' || tag === 'object') {
|
|
23
|
+
return element.getAttribute('alt') ?? '';
|
|
24
|
+
}
|
|
25
|
+
if (tag === 'math') {
|
|
26
|
+
return element.getAttribute('alttext') ?? element.getAttribute('aria-label') ?? '';
|
|
27
|
+
}
|
|
28
|
+
if (tag === 'svg') {
|
|
29
|
+
const title = element.querySelector(':scope > title')?.textContent ?? '';
|
|
30
|
+
return title || element.getAttribute('aria-label') || '';
|
|
31
|
+
}
|
|
32
|
+
return '';
|
|
33
|
+
}
|
|
34
|
+
function textFromNode(node) {
|
|
35
|
+
if (node.nodeType === Node.TEXT_NODE)
|
|
36
|
+
return node.textContent ?? '';
|
|
37
|
+
if (node.nodeType !== Node.ELEMENT_NODE)
|
|
38
|
+
return '';
|
|
39
|
+
const element = node;
|
|
40
|
+
// Hidden content contributes nothing, even an icon that carries alt text or a
|
|
41
|
+
// title: a hidden icon beside the same visible word must not read it twice.
|
|
42
|
+
if (element.getAttribute('aria-hidden') === 'true')
|
|
43
|
+
return '';
|
|
44
|
+
const alternative = ownAlternative(element);
|
|
45
|
+
// A node with its own alternative is read as that alternative; its children
|
|
46
|
+
// (e.g. an <object>'s fallback markup) are not announced in addition.
|
|
47
|
+
if (alternative)
|
|
48
|
+
return alternative;
|
|
49
|
+
return Array.from(element.childNodes).map(textFromNode).join(' ');
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The text assistive technology would read for a rich-content HTML snippet:
|
|
53
|
+
* `img`/`object` alt, MathML `alttext`/`aria-label`, SVG `<title>`/`aria-label`,
|
|
54
|
+
* otherwise the text content. Returns '' when there is nothing to read, so the
|
|
55
|
+
* caller can pick a meaningful fallback. Safe on the server: falls back to a
|
|
56
|
+
* tag-stripping pass when no DOM is available (there, image alt text cannot be
|
|
57
|
+
* recovered from serialized HTML and only visible text survives).
|
|
58
|
+
*/
|
|
59
|
+
export function accessibleTextFromHtml(html) {
|
|
60
|
+
if (html == null || html === '')
|
|
61
|
+
return '';
|
|
62
|
+
if (typeof document !== 'undefined') {
|
|
63
|
+
const template = document.createElement('template');
|
|
64
|
+
// Passing the value through unchanged preserves TrustedHTML identity at
|
|
65
|
+
// this parsing sink; the resulting text is used only for accessibility.
|
|
66
|
+
template.innerHTML = html;
|
|
67
|
+
return collapseWhitespace(Array.from(template.content.childNodes).map(textFromNode).join(' '));
|
|
68
|
+
}
|
|
69
|
+
const serialized = typeof html === 'string' ? html : String(html);
|
|
70
|
+
return collapseWhitespace(serialized.replace(/<[^>]*>/g, ' '));
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=accessibleText.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accessibleText.js","sourceRoot":"","sources":["../../../src/shared/utils/accessibleText.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,oFAAoF;AACpF,SAAS,kBAAkB,CAAC,IAAY;IACvC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AACzC,CAAC;AAED,6FAA6F;AAC7F,SAAS,cAAc,CAAC,OAAgB;IACvC,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;IAC1C,IAAI,GAAG,KAAK,KAAK,IAAI,GAAG,KAAK,QAAQ,EAAE,CAAC;QACvC,OAAO,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IAC1C,CAAC;IACD,IAAI,GAAG,KAAK,MAAM,EAAE,CAAC;QACpB,OAAO,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,OAAO,CAAC,YAAY,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;IACpF,CAAC;IACD,IAAI,GAAG,KAAK,KAAK,EAAE,CAAC;QACnB,MAAM,KAAK,GAAG,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,EAAE,WAAW,IAAI,EAAE,CAAC;QACzE,OAAO,KAAK,IAAI,OAAO,CAAC,YAAY,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;IAC1D,CAAC;IACD,OAAO,EAAE,CAAC;AACX,CAAC;AAED,SAAS,YAAY,CAAC,IAAU;IAC/B,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC;IACpE,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,YAAY;QAAE,OAAO,EAAE,CAAC;IACnD,MAAM,OAAO,GAAG,IAAe,CAAC;IAChC,8EAA8E;IAC9E,4EAA4E;IAC5E,IAAI,OAAO,CAAC,YAAY,CAAC,aAAa,CAAC,KAAK,MAAM;QAAE,OAAO,EAAE,CAAC;IAC9D,MAAM,WAAW,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IAC5C,4EAA4E;IAC5E,sEAAsE;IACtE,IAAI,WAAW;QAAE,OAAO,WAAW,CAAC;IACpC,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACnE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAAoC;IAC1E,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,KAAK,EAAE;QAAE,OAAO,EAAE,CAAC;IAC3C,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE,CAAC;QACrC,MAAM,QAAQ,GAAG,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;QACpD,wEAAwE;QACxE,wEAAwE;QACxE,QAAQ,CAAC,SAAS,GAAG,IAAyB,CAAC;QAC/C,OAAO,kBAAkB,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAChG,CAAC;IACD,MAAM,UAAU,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAClE,OAAO,kBAAkB,CAAC,UAAU,CAAC,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,CAAC;AAChE,CAAC","sourcesContent":["/**\n * Accessible text of rich choice content.\n *\n * Choice content is rich HTML: an image-only choice must read its `alt`, a\n * MathML formula must read its `alttext` (not a flattened \"x2\"), an SVG must\n * read its `title`. `textContent` drops all of that, so names and live-region\n * announcements built from it describe images as nothing at all.\n *\n * `accessibleTextFromHtml` walks the content in reading order and returns the\n * text assistive technology would derive. It never substitutes a placeholder\n * itself: callers decide the fallback, and must not fall back to \"Item\" or an\n * identifier when content exists — a silent \"Item\" names every choice alike\n * and makes the interaction unusable.\n */\n\nimport type { HtmlContent } from '@pie-qti/item-player';\n\n/** Collapse runs of whitespace so announcements read like sentences, not source. */\nfunction collapseWhitespace(text: string): string {\n\treturn text.replace(/\\s+/g, ' ').trim();\n}\n\n/** An element's own text alternative (`alt`, `alttext`, `aria-label`, `<title>`), if any. */\nfunction ownAlternative(element: Element): string {\n\tconst tag = element.tagName.toLowerCase();\n\tif (tag === 'img' || tag === 'object') {\n\t\treturn element.getAttribute('alt') ?? '';\n\t}\n\tif (tag === 'math') {\n\t\treturn element.getAttribute('alttext') ?? element.getAttribute('aria-label') ?? '';\n\t}\n\tif (tag === 'svg') {\n\t\tconst title = element.querySelector(':scope > title')?.textContent ?? '';\n\t\treturn title || element.getAttribute('aria-label') || '';\n\t}\n\treturn '';\n}\n\nfunction textFromNode(node: Node): string {\n\tif (node.nodeType === Node.TEXT_NODE) return node.textContent ?? '';\n\tif (node.nodeType !== Node.ELEMENT_NODE) return '';\n\tconst element = node as Element;\n\t// Hidden content contributes nothing, even an icon that carries alt text or a\n\t// title: a hidden icon beside the same visible word must not read it twice.\n\tif (element.getAttribute('aria-hidden') === 'true') return '';\n\tconst alternative = ownAlternative(element);\n\t// A node with its own alternative is read as that alternative; its children\n\t// (e.g. an <object>'s fallback markup) are not announced in addition.\n\tif (alternative) return alternative;\n\treturn Array.from(element.childNodes).map(textFromNode).join(' ');\n}\n\n/**\n * The text assistive technology would read for a rich-content HTML snippet:\n * `img`/`object` alt, MathML `alttext`/`aria-label`, SVG `<title>`/`aria-label`,\n * otherwise the text content. Returns '' when there is nothing to read, so the\n * caller can pick a meaningful fallback. Safe on the server: falls back to a\n * tag-stripping pass when no DOM is available (there, image alt text cannot be\n * recovered from serialized HTML and only visible text survives).\n */\nexport function accessibleTextFromHtml(html: HtmlContent | null | undefined): string {\n\tif (html == null || html === '') return '';\n\tif (typeof document !== 'undefined') {\n\t\tconst template = document.createElement('template');\n\t\t// Passing the value through unchanged preserves TrustedHTML identity at\n\t\t// this parsing sink; the resulting text is used only for accessibility.\n\t\ttemplate.innerHTML = html as unknown as string;\n\t\treturn collapseWhitespace(Array.from(template.content.childNodes).map(textFromNode).join(' '));\n\t}\n\tconst serialized = typeof html === 'string' ? html : String(html);\n\treturn collapseWhitespace(serialized.replace(/<[^>]*>/g, ' '));\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The polite live-region announcer every interaction shares.
|
|
3
|
+
*
|
|
4
|
+
* A live region announces a change of its text; announcing the same sentence
|
|
5
|
+
* twice therefore needs the text to change again, invisibly. The helper holds
|
|
6
|
+
* the region's text and appends a trailing zero-width space (silent to screen
|
|
7
|
+
* readers) when the same message is announced again. Components keep their
|
|
8
|
+
* own region markup — classes, parts, `aria-*` — and bind `message` to it.
|
|
9
|
+
*
|
|
10
|
+
* The rule and the toggle live here once; what each interaction announces
|
|
11
|
+
* stays its own.
|
|
12
|
+
*/
|
|
13
|
+
export interface Announcer {
|
|
14
|
+
/** The text the live region currently holds (bind this to it). */
|
|
15
|
+
readonly message: string;
|
|
16
|
+
/** Announce `message` through the region; a repeat still changes the DOM. */
|
|
17
|
+
announce(message: string): void;
|
|
18
|
+
/**
|
|
19
|
+
* State the region's text without the re-announce toggle, for messages the
|
|
20
|
+
* interaction writes directly (a repeat leaves the DOM unchanged, as before).
|
|
21
|
+
*/
|
|
22
|
+
set(message: string): void;
|
|
23
|
+
/** Empty the region, so the next announcement is a fresh change. */
|
|
24
|
+
clear(): void;
|
|
25
|
+
}
|
|
26
|
+
export declare function createAnnouncer(): Announcer;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The polite live-region announcer every interaction shares.
|
|
3
|
+
*
|
|
4
|
+
* A live region announces a change of its text; announcing the same sentence
|
|
5
|
+
* twice therefore needs the text to change again, invisibly. The helper holds
|
|
6
|
+
* the region's text and appends a trailing zero-width space (silent to screen
|
|
7
|
+
* readers) when the same message is announced again. Components keep their
|
|
8
|
+
* own region markup — classes, parts, `aria-*` — and bind `message` to it.
|
|
9
|
+
*
|
|
10
|
+
* The rule and the toggle live here once; what each interaction announces
|
|
11
|
+
* stays its own.
|
|
12
|
+
*/
|
|
13
|
+
export function createAnnouncer() {
|
|
14
|
+
let message = $state('');
|
|
15
|
+
return {
|
|
16
|
+
get message() {
|
|
17
|
+
return message;
|
|
18
|
+
},
|
|
19
|
+
announce(next) {
|
|
20
|
+
message = message === next ? `${next}\u200b` : next;
|
|
21
|
+
},
|
|
22
|
+
set(next) {
|
|
23
|
+
message = next;
|
|
24
|
+
},
|
|
25
|
+
clear() {
|
|
26
|
+
message = '';
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=announcer.svelte.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"announcer.svelte.js","sourceRoot":"","sources":["../../../src/shared/utils/announcer.svelte.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAgBH,MAAM,UAAU,eAAe;IAC9B,IAAI,OAAO,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;IAEzB,OAAO;QACN,IAAI,OAAO;YACV,OAAO,OAAO,CAAC;QAChB,CAAC;QACD,QAAQ,CAAC,IAAY;YACpB,OAAO,GAAG,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;QACrD,CAAC;QACD,GAAG,CAAC,IAAY;YACf,OAAO,GAAG,IAAI,CAAC;QAChB,CAAC;QACD,KAAK;YACJ,OAAO,GAAG,EAAE,CAAC;QACd,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["/**\n * The polite live-region announcer every interaction shares.\n *\n * A live region announces a change of its text; announcing the same sentence\n * twice therefore needs the text to change again, invisibly. The helper holds\n * the region's text and appends a trailing zero-width space (silent to screen\n * readers) when the same message is announced again. Components keep their\n * own region markup — classes, parts, `aria-*` — and bind `message` to it.\n *\n * The rule and the toggle live here once; what each interaction announces\n * stays its own.\n */\n\nexport interface Announcer {\n\t/** The text the live region currently holds (bind this to it). */\n\treadonly message: string;\n\t/** Announce `message` through the region; a repeat still changes the DOM. */\n\tannounce(message: string): void;\n\t/**\n\t * State the region's text without the re-announce toggle, for messages the\n\t * interaction writes directly (a repeat leaves the DOM unchanged, as before).\n\t */\n\tset(message: string): void;\n\t/** Empty the region, so the next announcement is a fresh change. */\n\tclear(): void;\n}\n\nexport function createAnnouncer(): Announcer {\n\tlet message = $state('');\n\n\treturn {\n\t\tget message() {\n\t\t\treturn message;\n\t\t},\n\t\tannounce(next: string) {\n\t\t\tmessage = message === next ? `${next}\\u200b` : next;\n\t\t},\n\t\tset(next: string) {\n\t\t\tmessage = next;\n\t\t},\n\t\tclear() {\n\t\t\tmessage = '';\n\t\t},\n\t};\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QTI capacity limits — maxChoices, maxAssociations, matchMax — and the message that states one.
|
|
3
|
+
*
|
|
4
|
+
* One rule for every interaction: a positive limit restricts, and 0 means no restriction, as
|
|
5
|
+
* QTI 2.2 and 3.0 define it for each of these attributes. Values are taken as given: these
|
|
6
|
+
* helpers impose no defaults. The item-player extractors set the spec default of an absent
|
|
7
|
+
* attribute, and the components pass the delivered value through.
|
|
8
|
+
*/
|
|
9
|
+
/** Whether `limit` restricts at all: only a positive limit does; 0 is no restriction. */
|
|
10
|
+
export declare function isLimited(limit: number): boolean;
|
|
11
|
+
/** Whether `count` has reached a positive `limit`, so one more would pass it. */
|
|
12
|
+
export declare function isAtLimit(count: number, limit: number): boolean;
|
|
13
|
+
/** Whether `count` is past a positive `limit`: a would-be response that breaks it. */
|
|
14
|
+
export declare function exceedsLimit(count: number, limit: number): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The message that states a limit: the author's `data-max-selections-message` when it has text
|
|
17
|
+
* (QTI 3.0: "rendered upon violation of the max-choices constraint"), else `fallback`, the
|
|
18
|
+
* interaction's localized default.
|
|
19
|
+
*/
|
|
20
|
+
export declare function limitMessage(authored: string | null | undefined, fallback: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Whether a selection interaction states its limit message: at a positive limit, an authored
|
|
23
|
+
* message at any cardinality, and the default only where a further selection is refused (a
|
|
24
|
+
* limit above 1; a single selection switches instead).
|
|
25
|
+
*/
|
|
26
|
+
export declare function isLimitMessageShown(count: number, limit: number, authored: string | null | undefined): boolean;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QTI capacity limits — maxChoices, maxAssociations, matchMax — and the message that states one.
|
|
3
|
+
*
|
|
4
|
+
* One rule for every interaction: a positive limit restricts, and 0 means no restriction, as
|
|
5
|
+
* QTI 2.2 and 3.0 define it for each of these attributes. Values are taken as given: these
|
|
6
|
+
* helpers impose no defaults. The item-player extractors set the spec default of an absent
|
|
7
|
+
* attribute, and the components pass the delivered value through.
|
|
8
|
+
*/
|
|
9
|
+
/** Whether `limit` restricts at all: only a positive limit does; 0 is no restriction. */
|
|
10
|
+
export function isLimited(limit) {
|
|
11
|
+
return limit > 0;
|
|
12
|
+
}
|
|
13
|
+
/** Whether `count` has reached a positive `limit`, so one more would pass it. */
|
|
14
|
+
export function isAtLimit(count, limit) {
|
|
15
|
+
return limit > 0 && count >= limit;
|
|
16
|
+
}
|
|
17
|
+
/** Whether `count` is past a positive `limit`: a would-be response that breaks it. */
|
|
18
|
+
export function exceedsLimit(count, limit) {
|
|
19
|
+
return limit > 0 && count > limit;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The message that states a limit: the author's `data-max-selections-message` when it has text
|
|
23
|
+
* (QTI 3.0: "rendered upon violation of the max-choices constraint"), else `fallback`, the
|
|
24
|
+
* interaction's localized default.
|
|
25
|
+
*/
|
|
26
|
+
export function limitMessage(authored, fallback) {
|
|
27
|
+
return authored?.trim() || fallback;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Whether a selection interaction states its limit message: at a positive limit, an authored
|
|
31
|
+
* message at any cardinality, and the default only where a further selection is refused (a
|
|
32
|
+
* limit above 1; a single selection switches instead).
|
|
33
|
+
*/
|
|
34
|
+
export function isLimitMessageShown(count, limit, authored) {
|
|
35
|
+
return isAtLimit(count, limit) && (!!authored?.trim() || limit > 1);
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=capacity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capacity.js","sourceRoot":"","sources":["../../../src/shared/utils/capacity.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,yFAAyF;AACzF,MAAM,UAAU,SAAS,CAAC,KAAa;IACtC,OAAO,KAAK,GAAG,CAAC,CAAC;AAClB,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,SAAS,CAAC,KAAa,EAAE,KAAa;IACrD,OAAO,KAAK,GAAG,CAAC,IAAI,KAAK,IAAI,KAAK,CAAC;AACpC,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,KAAa;IACxD,OAAO,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,KAAK,CAAC;AACnC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,QAAmC,EAAE,QAAgB;IACjF,OAAO,QAAQ,EAAE,IAAI,EAAE,IAAI,QAAQ,CAAC;AACrC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAa,EAAE,KAAa,EAAE,QAAmC;IACpG,OAAO,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC;AACrE,CAAC","sourcesContent":["/**\n * QTI capacity limits — maxChoices, maxAssociations, matchMax — and the message that states one.\n *\n * One rule for every interaction: a positive limit restricts, and 0 means no restriction, as\n * QTI 2.2 and 3.0 define it for each of these attributes. Values are taken as given: these\n * helpers impose no defaults. The item-player extractors set the spec default of an absent\n * attribute, and the components pass the delivered value through.\n */\n\n/** Whether `limit` restricts at all: only a positive limit does; 0 is no restriction. */\nexport function isLimited(limit: number): boolean {\n\treturn limit > 0;\n}\n\n/** Whether `count` has reached a positive `limit`, so one more would pass it. */\nexport function isAtLimit(count: number, limit: number): boolean {\n\treturn limit > 0 && count >= limit;\n}\n\n/** Whether `count` is past a positive `limit`: a would-be response that breaks it. */\nexport function exceedsLimit(count: number, limit: number): boolean {\n\treturn limit > 0 && count > limit;\n}\n\n/**\n * The message that states a limit: the author's `data-max-selections-message` when it has text\n * (QTI 3.0: \"rendered upon violation of the max-choices constraint\"), else `fallback`, the\n * interaction's localized default.\n */\nexport function limitMessage(authored: string | null | undefined, fallback: string): string {\n\treturn authored?.trim() || fallback;\n}\n\n/**\n * Whether a selection interaction states its limit message: at a positive limit, an authored\n * message at any cardinality, and the default only where a further selection is refused (a\n * limit above 1; a single selection switches instead).\n */\nexport function isLimitMessageShown(count: number, limit: number, authored: string | null | undefined): boolean {\n\treturn isAtLimit(count, limit) && (!!authored?.trim() || limit > 1);\n}\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The accessible name of an interactive choice.
|
|
3
|
+
*
|
|
4
|
+
* A choice is named by its authored content — the text `accessibleTextFromHtml`
|
|
5
|
+
* derives from it (visible text, image `alt`, MathML `alttext`, SVG `<title>`).
|
|
6
|
+
* A choice whose content carries no readable text (an image without alt, empty
|
|
7
|
+
* markup) is named by a localized ordinal of its presented position ("Choice
|
|
8
|
+
* 3"), so it still has a name a candidate can use and repeat back.
|
|
9
|
+
*
|
|
10
|
+
* The fallback is never the QTI identifier: identifiers are author-internal,
|
|
11
|
+
* meaningless to candidates, and can leak the answer key (`CORRECT_A`) through
|
|
12
|
+
* a screen reader. The ordinal is 1-based over the order the candidate sees
|
|
13
|
+
* (after shuffle), so it is stable for a rendering and matches what a sighted
|
|
14
|
+
* candidate would count.
|
|
15
|
+
*/
|
|
16
|
+
import { type I18nProvider } from '@pie-qti/i18n';
|
|
17
|
+
export interface ChoiceNameInput {
|
|
18
|
+
i18n: I18nProvider | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* The choice's authored label: `accessibleTextFromHtml` of its content (for
|
|
21
|
+
* plain-text choices, the text itself). Empty when there is nothing to read.
|
|
22
|
+
*/
|
|
23
|
+
label: string | undefined;
|
|
24
|
+
/** The choice's 1-based position as presented to the candidate (after shuffle). */
|
|
25
|
+
position: number;
|
|
26
|
+
/**
|
|
27
|
+
* The interaction's own localized ordinal, when its vocabulary names the
|
|
28
|
+
* choice differently ("Region 3", "Object 2"): the catalog key and its
|
|
29
|
+
* English form, both carrying `{index}`. Absent, the shared
|
|
30
|
+
* `accessibility.choiceFallback` ("Choice {index}") is used.
|
|
31
|
+
*/
|
|
32
|
+
fallback?: {
|
|
33
|
+
key: string;
|
|
34
|
+
text: string;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The accessible name of a choice: its authored label, else a localized
|
|
39
|
+
* ordinal of the position the candidate sees — `accessibility.choiceFallback`
|
|
40
|
+
* ("Choice {index}"), or the interaction's own noun through `fallback`. Every
|
|
41
|
+
* interactive choice label, announcement and `aria-label` fallback names a
|
|
42
|
+
* choice through this, so no identifier can reach a candidate's screen reader.
|
|
43
|
+
*/
|
|
44
|
+
export declare function choiceAccessibleName({ i18n, label, position, fallback }: ChoiceNameInput): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The accessible name of an interactive choice.
|
|
3
|
+
*
|
|
4
|
+
* A choice is named by its authored content — the text `accessibleTextFromHtml`
|
|
5
|
+
* derives from it (visible text, image `alt`, MathML `alttext`, SVG `<title>`).
|
|
6
|
+
* A choice whose content carries no readable text (an image without alt, empty
|
|
7
|
+
* markup) is named by a localized ordinal of its presented position ("Choice
|
|
8
|
+
* 3"), so it still has a name a candidate can use and repeat back.
|
|
9
|
+
*
|
|
10
|
+
* The fallback is never the QTI identifier: identifiers are author-internal,
|
|
11
|
+
* meaningless to candidates, and can leak the answer key (`CORRECT_A`) through
|
|
12
|
+
* a screen reader. The ordinal is 1-based over the order the candidate sees
|
|
13
|
+
* (after shuffle), so it is stable for a rendering and matches what a sighted
|
|
14
|
+
* candidate would count.
|
|
15
|
+
*/
|
|
16
|
+
import { translate } from '@pie-qti/i18n';
|
|
17
|
+
/**
|
|
18
|
+
* The accessible name of a choice: its authored label, else a localized
|
|
19
|
+
* ordinal of the position the candidate sees — `accessibility.choiceFallback`
|
|
20
|
+
* ("Choice {index}"), or the interaction's own noun through `fallback`. Every
|
|
21
|
+
* interactive choice label, announcement and `aria-label` fallback names a
|
|
22
|
+
* choice through this, so no identifier can reach a candidate's screen reader.
|
|
23
|
+
*/
|
|
24
|
+
export function choiceAccessibleName({ i18n, label, position, fallback }) {
|
|
25
|
+
const [key, text] = fallback ? [fallback.key, fallback.text] : ['accessibility.choiceFallback', 'Choice {index}'];
|
|
26
|
+
return (label ?? '').trim() || translate(i18n, key, text, { index: position });
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=choiceName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"choiceName.js","sourceRoot":"","sources":["../../../src/shared/utils/choiceName.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,SAAS,EAAqB,MAAM,eAAe,CAAC;AAoB7D;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAmB;IACxF,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,8BAA8B,EAAE,gBAAgB,CAAC,CAAC;IAClH,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;AAChF,CAAC","sourcesContent":["/**\n * The accessible name of an interactive choice.\n *\n * A choice is named by its authored content — the text `accessibleTextFromHtml`\n * derives from it (visible text, image `alt`, MathML `alttext`, SVG `<title>`).\n * A choice whose content carries no readable text (an image without alt, empty\n * markup) is named by a localized ordinal of its presented position (\"Choice\n * 3\"), so it still has a name a candidate can use and repeat back.\n *\n * The fallback is never the QTI identifier: identifiers are author-internal,\n * meaningless to candidates, and can leak the answer key (`CORRECT_A`) through\n * a screen reader. The ordinal is 1-based over the order the candidate sees\n * (after shuffle), so it is stable for a rendering and matches what a sighted\n * candidate would count.\n */\n\nimport { translate, type I18nProvider } from '@pie-qti/i18n';\n\nexport interface ChoiceNameInput {\n\ti18n: I18nProvider | undefined;\n\t/**\n\t * The choice's authored label: `accessibleTextFromHtml` of its content (for\n\t * plain-text choices, the text itself). Empty when there is nothing to read.\n\t */\n\tlabel: string | undefined;\n\t/** The choice's 1-based position as presented to the candidate (after shuffle). */\n\tposition: number;\n\t/**\n\t * The interaction's own localized ordinal, when its vocabulary names the\n\t * choice differently (\"Region 3\", \"Object 2\"): the catalog key and its\n\t * English form, both carrying `{index}`. Absent, the shared\n\t * `accessibility.choiceFallback` (\"Choice {index}\") is used.\n\t */\n\tfallback?: { key: string; text: string };\n}\n\n/**\n * The accessible name of a choice: its authored label, else a localized\n * ordinal of the position the candidate sees — `accessibility.choiceFallback`\n * (\"Choice {index}\"), or the interaction's own noun through `fallback`. Every\n * interactive choice label, announcement and `aria-label` fallback names a\n * choice through this, so no identifier can reach a candidate's screen reader.\n */\nexport function choiceAccessibleName({ i18n, label, position, fallback }: ChoiceNameInput): string {\n\tconst [key, text] = fallback ? [fallback.key, fallback.text] : ['accessibility.choiceFallback', 'Choice {index}'];\n\treturn (label ?? '').trim() || translate(i18n, key, text, { index: position });\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared confirm-before-submit flow for ordering interactions (WCAG 2.2 SC 3.3.4): the response
|
|
3
|
+
* only becomes final when the candidate confirms, drag reordering auto-confirms, and an
|
|
4
|
+
* externally cleared response re-arms the confirmation.
|
|
5
|
+
*/
|
|
6
|
+
export interface ConfirmationFlowOptions {
|
|
7
|
+
/** The candidate-visible order. */
|
|
8
|
+
orderedIds: () => string[];
|
|
9
|
+
/** The authored order, used to detect whether the candidate reordered. */
|
|
10
|
+
initialOrder: () => string[];
|
|
11
|
+
disabled: () => boolean;
|
|
12
|
+
/** The response as the plugin sees it (raw bindable or parsed prop); null before first commit. */
|
|
13
|
+
response: () => unknown;
|
|
14
|
+
/** Commits an order as the response (sets the bindable and emits the change). */
|
|
15
|
+
commit: (order: string[]) => void;
|
|
16
|
+
}
|
|
17
|
+
export interface ConfirmationFlow {
|
|
18
|
+
/** True when the candidate's order differs from the authored order. */
|
|
19
|
+
readonly hasReordered: boolean;
|
|
20
|
+
/** True while the confirm button should render. */
|
|
21
|
+
readonly needsConfirmation: boolean;
|
|
22
|
+
/** True once the candidate (or a drag) confirmed the current order. */
|
|
23
|
+
readonly hasConfirmed: boolean;
|
|
24
|
+
/** A drag reorder is a deliberate placement: confirm on the candidate's behalf. */
|
|
25
|
+
autoConfirm(): void;
|
|
26
|
+
/** Commit the current order as final (no-op when disabled or already confirmed). */
|
|
27
|
+
confirmOrder(): void;
|
|
28
|
+
/** Re-arm the confirmation when the response is externally cleared. */
|
|
29
|
+
resetIfCleared(): void;
|
|
30
|
+
}
|
|
31
|
+
export declare function createConfirmationFlow(options: ConfirmationFlowOptions): ConfirmationFlow;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared confirm-before-submit flow for ordering interactions (WCAG 2.2 SC 3.3.4): the response
|
|
3
|
+
* only becomes final when the candidate confirms, drag reordering auto-confirms, and an
|
|
4
|
+
* externally cleared response re-arms the confirmation.
|
|
5
|
+
*/
|
|
6
|
+
export function createConfirmationFlow(options) {
|
|
7
|
+
let hasConfirmed = $state(false);
|
|
8
|
+
const hasReordered = $derived.by(() => {
|
|
9
|
+
const ids = options.orderedIds();
|
|
10
|
+
const initial = options.initialOrder();
|
|
11
|
+
return ids.length > 0 && ids.some((id, index) => id !== initial[index]);
|
|
12
|
+
});
|
|
13
|
+
const needsConfirmation = $derived(!options.disabled() && (!options.response() || !hasConfirmed) && options.orderedIds().length > 0);
|
|
14
|
+
return {
|
|
15
|
+
get hasReordered() {
|
|
16
|
+
return hasReordered;
|
|
17
|
+
},
|
|
18
|
+
get needsConfirmation() {
|
|
19
|
+
return needsConfirmation;
|
|
20
|
+
},
|
|
21
|
+
get hasConfirmed() {
|
|
22
|
+
return hasConfirmed;
|
|
23
|
+
},
|
|
24
|
+
autoConfirm() {
|
|
25
|
+
hasConfirmed = true;
|
|
26
|
+
},
|
|
27
|
+
confirmOrder() {
|
|
28
|
+
if (options.disabled() || hasConfirmed)
|
|
29
|
+
return;
|
|
30
|
+
hasConfirmed = true;
|
|
31
|
+
options.commit(options.orderedIds());
|
|
32
|
+
},
|
|
33
|
+
resetIfCleared() {
|
|
34
|
+
const value = options.response();
|
|
35
|
+
if (value === null || (Array.isArray(value) && value.length === 0)) {
|
|
36
|
+
hasConfirmed = false;
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=confirmationFlow.svelte.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confirmationFlow.svelte.js","sourceRoot":"","sources":["../../../src/shared/utils/confirmationFlow.svelte.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA6BH,MAAM,UAAU,sBAAsB,CAAC,OAAgC;IACtE,IAAI,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAEjC,MAAM,YAAY,GAAG,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE;QACrC,MAAM,GAAG,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;QACjC,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;QACvC,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,KAAK,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;IACzE,CAAC,CAAC,CAAC;IAEH,MAAM,iBAAiB,GAAG,QAAQ,CACjC,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,MAAM,GAAG,CAAC,CAChG,CAAC;IAEF,OAAO;QACN,IAAI,YAAY;YACf,OAAO,YAAY,CAAC;QACrB,CAAC;QACD,IAAI,iBAAiB;YACpB,OAAO,iBAAiB,CAAC;QAC1B,CAAC;QACD,IAAI,YAAY;YACf,OAAO,YAAY,CAAC;QACrB,CAAC;QACD,WAAW;YACV,YAAY,GAAG,IAAI,CAAC;QACrB,CAAC;QACD,YAAY;YACX,IAAI,OAAO,CAAC,QAAQ,EAAE,IAAI,YAAY;gBAAE,OAAO;YAC/C,YAAY,GAAG,IAAI,CAAC;YACpB,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;QACtC,CAAC;QACD,cAAc;YACb,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;YACjC,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC;gBACpE,YAAY,GAAG,KAAK,CAAC;YACtB,CAAC;QACF,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["/**\n * Shared confirm-before-submit flow for ordering interactions (WCAG 2.2 SC 3.3.4): the response\n * only becomes final when the candidate confirms, drag reordering auto-confirms, and an\n * externally cleared response re-arms the confirmation.\n */\n\nexport interface ConfirmationFlowOptions {\n\t/** The candidate-visible order. */\n\torderedIds: () => string[];\n\t/** The authored order, used to detect whether the candidate reordered. */\n\tinitialOrder: () => string[];\n\tdisabled: () => boolean;\n\t/** The response as the plugin sees it (raw bindable or parsed prop); null before first commit. */\n\tresponse: () => unknown;\n\t/** Commits an order as the response (sets the bindable and emits the change). */\n\tcommit: (order: string[]) => void;\n}\n\nexport interface ConfirmationFlow {\n\t/** True when the candidate's order differs from the authored order. */\n\treadonly hasReordered: boolean;\n\t/** True while the confirm button should render. */\n\treadonly needsConfirmation: boolean;\n\t/** True once the candidate (or a drag) confirmed the current order. */\n\treadonly hasConfirmed: boolean;\n\t/** A drag reorder is a deliberate placement: confirm on the candidate's behalf. */\n\tautoConfirm(): void;\n\t/** Commit the current order as final (no-op when disabled or already confirmed). */\n\tconfirmOrder(): void;\n\t/** Re-arm the confirmation when the response is externally cleared. */\n\tresetIfCleared(): void;\n}\n\nexport function createConfirmationFlow(options: ConfirmationFlowOptions): ConfirmationFlow {\n\tlet hasConfirmed = $state(false);\n\n\tconst hasReordered = $derived.by(() => {\n\t\tconst ids = options.orderedIds();\n\t\tconst initial = options.initialOrder();\n\t\treturn ids.length > 0 && ids.some((id, index) => id !== initial[index]);\n\t});\n\n\tconst needsConfirmation = $derived(\n\t\t!options.disabled() && (!options.response() || !hasConfirmed) && options.orderedIds().length > 0\n\t);\n\n\treturn {\n\t\tget hasReordered() {\n\t\t\treturn hasReordered;\n\t\t},\n\t\tget needsConfirmation() {\n\t\t\treturn needsConfirmation;\n\t\t},\n\t\tget hasConfirmed() {\n\t\t\treturn hasConfirmed;\n\t\t},\n\t\tautoConfirm(): void {\n\t\t\thasConfirmed = true;\n\t\t},\n\t\tconfirmOrder(): void {\n\t\t\tif (options.disabled() || hasConfirmed) return;\n\t\t\thasConfirmed = true;\n\t\t\toptions.commit(options.orderedIds());\n\t\t},\n\t\tresetIfCleared(): void {\n\t\t\tconst value = options.response();\n\t\t\tif (value === null || (Array.isArray(value) && value.length === 0)) {\n\t\t\t\thasConfirmed = false;\n\t\t\t}\n\t\t},\n\t};\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QTI 3.0 PNP §6.2 elimination tool: per-identifier scratch-work toggles. Eliminated items stay
|
|
3
|
+
* in the DOM and in the response; only the candidate's view of them changes.
|
|
4
|
+
*/
|
|
5
|
+
export interface EliminationTool {
|
|
6
|
+
/** The current set of eliminated identifiers. */
|
|
7
|
+
readonly eliminated: Set<string>;
|
|
8
|
+
isEliminated(identifier: string): boolean;
|
|
9
|
+
toggle(identifier: string): void;
|
|
10
|
+
}
|
|
11
|
+
export declare function createEliminationTool(): EliminationTool;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QTI 3.0 PNP §6.2 elimination tool: per-identifier scratch-work toggles. Eliminated items stay
|
|
3
|
+
* in the DOM and in the response; only the candidate's view of them changes.
|
|
4
|
+
*/
|
|
5
|
+
export function createEliminationTool() {
|
|
6
|
+
let eliminatedChoices = $state(new Set());
|
|
7
|
+
return {
|
|
8
|
+
get eliminated() {
|
|
9
|
+
return eliminatedChoices;
|
|
10
|
+
},
|
|
11
|
+
isEliminated(identifier) {
|
|
12
|
+
return eliminatedChoices.has(identifier);
|
|
13
|
+
},
|
|
14
|
+
toggle(identifier) {
|
|
15
|
+
const next = new Set(eliminatedChoices);
|
|
16
|
+
if (next.has(identifier)) {
|
|
17
|
+
next.delete(identifier);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
next.add(identifier);
|
|
21
|
+
}
|
|
22
|
+
eliminatedChoices = next;
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=eliminationTool.svelte.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eliminationTool.svelte.js","sourceRoot":"","sources":["../../../src/shared/utils/eliminationTool.svelte.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,MAAM,UAAU,qBAAqB;IACpC,IAAI,iBAAiB,GAAG,MAAM,CAAC,IAAI,GAAG,EAAU,CAAC,CAAC;IAElD,OAAO;QACN,IAAI,UAAU;YACb,OAAO,iBAAiB,CAAC;QAC1B,CAAC;QACD,YAAY,CAAC,UAAkB;YAC9B,OAAO,iBAAiB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC1C,CAAC;QACD,MAAM,CAAC,UAAkB;YACxB,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,iBAAiB,CAAC,CAAC;YACxC,IAAI,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC1B,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YACzB,CAAC;iBAAM,CAAC;gBACP,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YACtB,CAAC;YACD,iBAAiB,GAAG,IAAI,CAAC;QAC1B,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["/**\n * QTI 3.0 PNP §6.2 elimination tool: per-identifier scratch-work toggles. Eliminated items stay\n * in the DOM and in the response; only the candidate's view of them changes.\n */\n\nexport interface EliminationTool {\n\t/** The current set of eliminated identifiers. */\n\treadonly eliminated: Set<string>;\n\tisEliminated(identifier: string): boolean;\n\ttoggle(identifier: string): void;\n}\n\nexport function createEliminationTool(): EliminationTool {\n\tlet eliminatedChoices = $state(new Set<string>());\n\n\treturn {\n\t\tget eliminated() {\n\t\t\treturn eliminatedChoices;\n\t\t},\n\t\tisEliminated(identifier: string): boolean {\n\t\t\treturn eliminatedChoices.has(identifier);\n\t\t},\n\t\ttoggle(identifier: string): void {\n\t\t\tconst next = new Set(eliminatedChoices);\n\t\t\tif (next.has(identifier)) {\n\t\t\t\tnext.delete(identifier);\n\t\t\t} else {\n\t\t\t\tnext.add(identifier);\n\t\t\t}\n\t\t\teliminatedChoices = next;\n\t\t},\n\t};\n}\n"]}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helpers for the graphic interactions (hotspot, graphic associate,
|
|
3
|
+
* graphic gap match, graphic order, select point, position object).
|
|
4
|
+
*
|
|
5
|
+
* QTI region `coords` and point responses live in the image's natural pixel
|
|
6
|
+
* space. Renderers scale the image to its container (WCAG 1.4.10 Reflow), so
|
|
7
|
+
* everything here works in natural image coordinates and converts to and from
|
|
8
|
+
* rendered CSS pixels only at the edges (pointer input, target sizing).
|
|
9
|
+
*/
|
|
10
|
+
export interface Bounds {
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
}
|
|
16
|
+
export interface Point {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
}
|
|
20
|
+
/** Bounding box of a QTI shape (circle, ellipse, rect, poly) in image coordinates. */
|
|
21
|
+
export declare function shapeBounds(shape: string, coords: string | undefined): Bounds | null;
|
|
22
|
+
/** Centre of a QTI shape in image coordinates (polygon: vertex average). */
|
|
23
|
+
export declare function shapeCenter(shape: string, coords: string | undefined): Point;
|
|
24
|
+
/**
|
|
25
|
+
* Where a marker (a check, a position badge) for a QTI region sits, in image coordinates: the
|
|
26
|
+
* centre of its shape, or for the `default` shape — the whole image (QTI 3.0 §8.29) — `insetPx`
|
|
27
|
+
* CSS px in from the image's top-left corner at the rendered `renderScale`, clear of the other
|
|
28
|
+
* regions' markers at their centres. A shape whose `coords` are missing or unreadable marks at
|
|
29
|
+
* the image origin.
|
|
30
|
+
*/
|
|
31
|
+
export declare function regionMarkerPoint(shape: string, coords: string | undefined, renderScale: number, insetPx: number): Point;
|
|
32
|
+
/**
|
|
33
|
+
* Width (CSS px) of a transparent, non-scaling hit stroke that grows a shape's
|
|
34
|
+
* pointer target to at least {@link MIN_TARGET_PX} at the rendered scale. The
|
|
35
|
+
* stroke straddles the outline, so the target's smallest extent becomes
|
|
36
|
+
* `rendered size + stroke`. Zero for shapes that are already large enough.
|
|
37
|
+
* Scoring geometry is untouched: only the hit area grows.
|
|
38
|
+
*/
|
|
39
|
+
export declare function hitStrokeWidth(shape: string, coords: string | undefined, renderScale: number): number;
|
|
40
|
+
/**
|
|
41
|
+
* Map a pointer or touch position (client px) on the rendered image to natural
|
|
42
|
+
* image coordinates, so responses stay in the image's own pixel space at any
|
|
43
|
+
* scale. The point is clamped to the image. It is rounded to whole image
|
|
44
|
+
* pixels unless `round: false` — interactions that round (or don't) at their
|
|
45
|
+
* own emission step pass `round: false` and keep their own rule.
|
|
46
|
+
*/
|
|
47
|
+
export declare function clientToImagePoint(clientX: number, clientY: number, rect: {
|
|
48
|
+
left: number;
|
|
49
|
+
top: number;
|
|
50
|
+
width: number;
|
|
51
|
+
height: number;
|
|
52
|
+
}, naturalWidth: number, naturalHeight: number, options?: {
|
|
53
|
+
round?: boolean;
|
|
54
|
+
}): Point | null;
|
|
55
|
+
export interface ImageTextAlternative {
|
|
56
|
+
alt?: string;
|
|
57
|
+
altDescription?: string;
|
|
58
|
+
decorative?: boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The `alt` to render for an authored graphic-interaction image: empty only when
|
|
62
|
+
* the author explicitly marked it decorative, else the authored text, else the
|
|
63
|
+
* localized generic `fallback` (never an identifier or interaction-type name).
|
|
64
|
+
*/
|
|
65
|
+
export declare function imageAltText(image: ImageTextAlternative | null | undefined, fallback: string): string;
|
|
66
|
+
/**
|
|
67
|
+
* Escape plain text for a renderer that takes HTML (e.g. SortableList item text).
|
|
68
|
+
* Extracted hotspot labels are decoded plain text, not sanitized HTML.
|
|
69
|
+
*/
|
|
70
|
+
export declare function escapeHtml(text: string): string;
|
|
71
|
+
/**
|
|
72
|
+
* Svelte action reporting an element's rendered width (CSS px) now and on
|
|
73
|
+
* resize. Environments without ResizeObserver report once.
|
|
74
|
+
*/
|
|
75
|
+
export declare function observeWidth(node: HTMLElement, onWidth: (width: number) => void): {
|
|
76
|
+
update(next: (width: number) => void): void;
|
|
77
|
+
destroy(): void;
|
|
78
|
+
};
|