@pie-qti/default-components 1.0.0-beta.3 → 1.0.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/README.md +13 -0
  2. package/dist/chunks/mathlive.min-Cmxm6f5R.js.map +1 -1
  3. package/dist/index.js +13 -110
  4. package/dist/index.js.map +1 -1
  5. package/dist/plugins/extended-text/textInput.d.ts +47 -0
  6. package/dist/plugins/extended-text/textInput.js +65 -0
  7. package/dist/plugins/extended-text/textInput.js.map +1 -0
  8. package/dist/plugins/media/mediaPlayback.d.ts +39 -0
  9. package/dist/plugins/media/mediaPlayback.js +49 -0
  10. package/dist/plugins/media/mediaPlayback.js.map +1 -0
  11. package/dist/plugins.js +13689 -21735
  12. package/dist/plugins.js.map +1 -1
  13. package/dist/shared/components/icons.d.ts +12 -0
  14. package/dist/shared/components/icons.js +13 -0
  15. package/dist/shared/components/icons.js.map +1 -0
  16. package/dist/shared/components/keyboardCrosshair.svelte.d.ts +37 -0
  17. package/dist/shared/components/keyboardCrosshair.svelte.js +67 -0
  18. package/dist/shared/components/keyboardCrosshair.svelte.js.map +1 -0
  19. package/dist/shared/components/pickUpPlace.svelte.d.ts +42 -0
  20. package/dist/shared/components/pickUpPlace.svelte.js +58 -0
  21. package/dist/shared/components/pickUpPlace.svelte.js.map +1 -0
  22. package/dist/shared/extensions/MathLiveEditor.d.ts +33 -6
  23. package/dist/shared/extensions/MathLiveEditor.js +354 -175
  24. package/dist/shared/extensions/MathLiveEditor.js.map +1 -1
  25. package/dist/shared/extensions/modalDialog.d.ts +31 -0
  26. package/dist/shared/extensions/modalDialog.js +165 -0
  27. package/dist/shared/extensions/modalDialog.js.map +1 -0
  28. package/dist/shared/index.d.ts +1 -0
  29. package/dist/shared/index.js +2 -0
  30. package/dist/shared/index.js.map +1 -1
  31. package/dist/shared/styles/qti-pnp.css +44 -0
  32. package/dist/shared/styles/qti-shared-vocabulary.css +6 -2
  33. package/dist/shared/styles/srOnly.d.ts +23 -0
  34. package/dist/shared/styles/srOnly.js +70 -0
  35. package/dist/shared/styles/srOnly.js.map +1 -0
  36. package/dist/shared/utils/accessibleText.d.ts +24 -0
  37. package/dist/shared/utils/accessibleText.js +72 -0
  38. package/dist/shared/utils/accessibleText.js.map +1 -0
  39. package/dist/shared/utils/announcer.svelte.d.ts +26 -0
  40. package/dist/shared/utils/announcer.svelte.js +30 -0
  41. package/dist/shared/utils/announcer.svelte.js.map +1 -0
  42. package/dist/shared/utils/capacity.d.ts +26 -0
  43. package/dist/shared/utils/capacity.js +37 -0
  44. package/dist/shared/utils/capacity.js.map +1 -0
  45. package/dist/shared/utils/choiceName.d.ts +44 -0
  46. package/dist/shared/utils/choiceName.js +28 -0
  47. package/dist/shared/utils/choiceName.js.map +1 -0
  48. package/dist/shared/utils/confirmationFlow.svelte.d.ts +31 -0
  49. package/dist/shared/utils/confirmationFlow.svelte.js +41 -0
  50. package/dist/shared/utils/confirmationFlow.svelte.js.map +1 -0
  51. package/dist/shared/utils/eliminationTool.svelte.d.ts +11 -0
  52. package/dist/shared/utils/eliminationTool.svelte.js +26 -0
  53. package/dist/shared/utils/eliminationTool.svelte.js.map +1 -0
  54. package/dist/shared/utils/graphicRegions.d.ts +78 -0
  55. package/dist/shared/utils/graphicRegions.js +169 -0
  56. package/dist/shared/utils/graphicRegions.js.map +1 -0
  57. package/dist/shared/utils/interactionAria.d.ts +18 -5
  58. package/dist/shared/utils/interactionAria.js +42 -3
  59. package/dist/shared/utils/interactionAria.js.map +1 -1
  60. package/dist/shared/utils/interactionProps.d.ts +52 -0
  61. package/dist/shared/utils/interactionProps.js +14 -0
  62. package/dist/shared/utils/interactionProps.js.map +1 -0
  63. package/dist/shared/utils/matchGroupUtils.d.ts +26 -4
  64. package/dist/shared/utils/matchGroupUtils.js +25 -8
  65. package/dist/shared/utils/matchGroupUtils.js.map +1 -1
  66. package/dist/shared/utils/minimumRequirement.d.ts +56 -0
  67. package/dist/shared/utils/minimumRequirement.js +50 -0
  68. package/dist/shared/utils/minimumRequirement.js.map +1 -0
  69. package/dist/shared/utils/pairHelpers.d.ts +46 -12
  70. package/dist/shared/utils/pairHelpers.js +64 -12
  71. package/dist/shared/utils/pairHelpers.js.map +1 -1
  72. package/dist/shared/utils/radioGroup.d.ts +13 -0
  73. package/dist/shared/utils/radioGroup.js +27 -0
  74. package/dist/shared/utils/radioGroup.js.map +1 -0
  75. package/dist/shared/utils/stageImage.svelte.d.ts +56 -0
  76. package/dist/shared/utils/stageImage.svelte.js +76 -0
  77. package/dist/shared/utils/stageImage.svelte.js.map +1 -0
  78. package/dist/shared/utils/webComponentHelpers.d.ts +37 -5
  79. package/dist/shared/utils/webComponentHelpers.js +72 -19
  80. package/dist/shared/utils/webComponentHelpers.js.map +1 -1
  81. package/dist/shared.css +2 -0
  82. package/package.json +20 -31
  83. package/dist/assets/default-components.css +0 -2
  84. package/dist/chunks/__vite-browser-external-DwKjyYZK.js +0 -9
  85. package/dist/chunks/__vite-browser-external-DwKjyYZK.js.map +0 -1
  86. package/dist/chunks/ar-Cqx9S4Im.js +0 -919
  87. package/dist/chunks/ar-Cqx9S4Im.js.map +0 -1
  88. package/dist/chunks/es-DjA7IQ-N.js +0 -864
  89. package/dist/chunks/es-DjA7IQ-N.js.map +0 -1
  90. package/dist/chunks/fr-BhV6wQNG.js +0 -864
  91. package/dist/chunks/fr-BhV6wQNG.js.map +0 -1
  92. package/dist/chunks/nl-B0JlnB-a.js +0 -863
  93. package/dist/chunks/nl-B0JlnB-a.js.map +0 -1
  94. package/dist/chunks/ro-ClR0jejm.js +0 -864
  95. package/dist/chunks/ro-ClR0jejm.js.map +0 -1
  96. package/dist/chunks/rolldown-runtime-Y_bBpyJl.js +0 -20
  97. package/dist/chunks/th-RfNMAg5z.js +0 -863
  98. package/dist/chunks/th-RfNMAg5z.js.map +0 -1
  99. package/dist/chunks/zh-Hans-DJ82CLmG.js +0 -863
  100. package/dist/chunks/zh-Hans-DJ82CLmG.js.map +0 -1
@@ -0,0 +1,169 @@
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
+ /** Minimum pointer target edge in CSS px: WCAG 2.2 SC 2.5.8 Target Size (Minimum), level AA. */
11
+ const MIN_TARGET_PX = 24;
12
+ /** Parse QTI `coords` ("a,b,c") into numbers; a missing or non-numeric part becomes NaN. */
13
+ function parseCoords(coords) {
14
+ return (coords ?? '').split(',').map((part) => Number(part.trim()));
15
+ }
16
+ /** Bounding box of a QTI shape (circle, ellipse, rect, poly) in image coordinates. */
17
+ export function shapeBounds(shape, coords) {
18
+ const n = parseCoords(coords);
19
+ if (n.some((value) => !Number.isFinite(value)))
20
+ return null;
21
+ switch (shape) {
22
+ case 'circle': {
23
+ const [cx, cy, r] = n;
24
+ if (r === undefined)
25
+ return null;
26
+ return { x: cx - r, y: cy - r, width: r * 2, height: r * 2 };
27
+ }
28
+ case 'ellipse': {
29
+ const [cx, cy, rx, ry] = n;
30
+ if (ry === undefined)
31
+ return null;
32
+ return { x: cx - rx, y: cy - ry, width: rx * 2, height: ry * 2 };
33
+ }
34
+ case 'rect': {
35
+ const [left, top, right, bottom] = n;
36
+ if (bottom === undefined)
37
+ return null;
38
+ return { x: left, y: top, width: right - left, height: bottom - top };
39
+ }
40
+ case 'poly': {
41
+ const xs = n.filter((_, i) => i % 2 === 0);
42
+ const ys = n.filter((_, i) => i % 2 === 1);
43
+ if (xs.length === 0 || ys.length === 0)
44
+ return null;
45
+ const x = Math.min(...xs);
46
+ const y = Math.min(...ys);
47
+ return { x, y, width: Math.max(...xs) - x, height: Math.max(...ys) - y };
48
+ }
49
+ default:
50
+ return null;
51
+ }
52
+ }
53
+ /** Centre of a QTI shape in image coordinates (polygon: vertex average). */
54
+ export function shapeCenter(shape, coords) {
55
+ const n = parseCoords(coords);
56
+ if (shape === 'circle' || shape === 'ellipse')
57
+ return { x: n[0] || 0, y: n[1] || 0 };
58
+ if (shape === 'poly') {
59
+ const xs = n.filter((_, i) => i % 2 === 0);
60
+ const ys = n.filter((_, i) => i % 2 === 1);
61
+ if (xs.length === 0 || ys.length === 0)
62
+ return { x: 0, y: 0 };
63
+ return {
64
+ x: xs.reduce((a, b) => a + b, 0) / xs.length,
65
+ y: ys.reduce((a, b) => a + b, 0) / ys.length,
66
+ };
67
+ }
68
+ const bounds = shapeBounds(shape, coords);
69
+ return bounds ? { x: bounds.x + bounds.width / 2, y: bounds.y + bounds.height / 2 } : { x: n[0] || 0, y: n[1] || 0 };
70
+ }
71
+ /**
72
+ * Where a marker (a check, a position badge) for a QTI region sits, in image coordinates: the
73
+ * centre of its shape, or for the `default` shape — the whole image (QTI 3.0 §8.29) — `insetPx`
74
+ * CSS px in from the image's top-left corner at the rendered `renderScale`, clear of the other
75
+ * regions' markers at their centres. A shape whose `coords` are missing or unreadable marks at
76
+ * the image origin.
77
+ */
78
+ export function regionMarkerPoint(shape, coords, renderScale, insetPx) {
79
+ if (shape === 'default') {
80
+ const inset = insetPx / (renderScale > 0 ? renderScale : 1);
81
+ return { x: inset, y: inset };
82
+ }
83
+ const at = shapeCenter(shape, coords);
84
+ return Number.isFinite(at.x) && Number.isFinite(at.y) ? at : { x: 0, y: 0 };
85
+ }
86
+ /**
87
+ * Width (CSS px) of a transparent, non-scaling hit stroke that grows a shape's
88
+ * pointer target to at least {@link MIN_TARGET_PX} at the rendered scale. The
89
+ * stroke straddles the outline, so the target's smallest extent becomes
90
+ * `rendered size + stroke`. Zero for shapes that are already large enough.
91
+ * Scoring geometry is untouched: only the hit area grows.
92
+ */
93
+ export function hitStrokeWidth(shape, coords, renderScale) {
94
+ const bounds = shapeBounds(shape, coords);
95
+ if (!bounds)
96
+ return 0;
97
+ const smallest = Math.min(bounds.width, bounds.height) * (renderScale > 0 ? renderScale : 1);
98
+ return Math.max(0, Math.ceil(MIN_TARGET_PX - smallest));
99
+ }
100
+ /**
101
+ * Map a pointer or touch position (client px) on the rendered image to natural
102
+ * image coordinates, so responses stay in the image's own pixel space at any
103
+ * scale. The point is clamped to the image. It is rounded to whole image
104
+ * pixels unless `round: false` — interactions that round (or don't) at their
105
+ * own emission step pass `round: false` and keep their own rule.
106
+ */
107
+ export function clientToImagePoint(clientX, clientY, rect, naturalWidth, naturalHeight, options = {}) {
108
+ if (!(rect.width > 0) || !(rect.height > 0))
109
+ return null;
110
+ const x = ((clientX - rect.left) / rect.width) * naturalWidth;
111
+ const y = ((clientY - rect.top) / rect.height) * naturalHeight;
112
+ if (options.round === false) {
113
+ return {
114
+ x: Math.min(naturalWidth, Math.max(0, x)),
115
+ y: Math.min(naturalHeight, Math.max(0, y)),
116
+ };
117
+ }
118
+ return {
119
+ x: Math.min(naturalWidth, Math.max(0, Math.round(x))),
120
+ y: Math.min(naturalHeight, Math.max(0, Math.round(y))),
121
+ };
122
+ }
123
+ /**
124
+ * The `alt` to render for an authored graphic-interaction image: empty only when
125
+ * the author explicitly marked it decorative, else the authored text, else the
126
+ * localized generic `fallback` (never an identifier or interaction-type name).
127
+ */
128
+ export function imageAltText(image, fallback) {
129
+ if (image?.decorative)
130
+ return '';
131
+ return image?.alt?.trim() || fallback;
132
+ }
133
+ /**
134
+ * Escape plain text for a renderer that takes HTML (e.g. SortableList item text).
135
+ * Extracted hotspot labels are decoded plain text, not sanitized HTML.
136
+ */
137
+ export function escapeHtml(text) {
138
+ return text
139
+ .replace(/&/g, '&')
140
+ .replace(/</g, '&lt;')
141
+ .replace(/>/g, '&gt;')
142
+ .replace(/"/g, '&quot;')
143
+ .replace(/'/g, '&#39;');
144
+ }
145
+ /**
146
+ * Svelte action reporting an element's rendered width (CSS px) now and on
147
+ * resize. Environments without ResizeObserver report once.
148
+ */
149
+ export function observeWidth(node, onWidth) {
150
+ let callback = onWidth;
151
+ callback(node.getBoundingClientRect().width);
152
+ const RO = globalThis.ResizeObserver;
153
+ const observer = RO
154
+ ? new RO((entries) => {
155
+ for (const entry of entries)
156
+ callback(entry.contentRect.width);
157
+ })
158
+ : null;
159
+ observer?.observe(node);
160
+ return {
161
+ update(next) {
162
+ callback = next;
163
+ },
164
+ destroy() {
165
+ observer?.disconnect();
166
+ },
167
+ };
168
+ }
169
+ //# sourceMappingURL=graphicRegions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphicRegions.js","sourceRoot":"","sources":["../../../src/shared/utils/graphicRegions.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,gGAAgG;AAChG,MAAM,aAAa,GAAG,EAAE,CAAC;AAczB,4FAA4F;AAC5F,SAAS,WAAW,CAAC,MAA0B;IAC9C,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AACrE,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,WAAW,CAAC,KAAa,EAAE,MAA0B;IACpE,MAAM,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;IAC9B,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAC5D,QAAQ,KAAK,EAAE,CAAC;QACf,KAAK,QAAQ,CAAC,CAAC,CAAC;YACf,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;YACtB,IAAI,CAAC,KAAK,SAAS;gBAAE,OAAO,IAAI,CAAC;YACjC,OAAO,EAAE,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC,EAAE,EAA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,EAAE,EAAE;YACnB,KAAK,MAAM,KAAK,IAAI,OAAO;gBAAE,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAChE,CAAC,CAAC;QACH,CAAC,CAAC,IAAI,CAAC;IACR,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB,OAAO;QACN,MAAM,CAAC,IAA6B;YACnC,QAAQ,GAAG,IAAI,CAAC;QACjB,CAAC;QACD,OAAO;YACN,QAAQ,EAAE,UAAU,EAAE,CAAC;QACxB,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["/**\n * Shared helpers for the graphic interactions (hotspot, graphic associate,\n * graphic gap match, graphic order, select point, position object).\n *\n * QTI region `coords` and point responses live in the image's natural pixel\n * space. Renderers scale the image to its container (WCAG 1.4.10 Reflow), so\n * everything here works in natural image coordinates and converts to and from\n * rendered CSS pixels only at the edges (pointer input, target sizing).\n */\n\n/** Minimum pointer target edge in CSS px: WCAG 2.2 SC 2.5.8 Target Size (Minimum), level AA. */\nconst MIN_TARGET_PX = 24;\n\nexport interface Bounds {\n\tx: number;\n\ty: number;\n\twidth: number;\n\theight: number;\n}\n\nexport interface Point {\n\tx: number;\n\ty: number;\n}\n\n/** Parse QTI `coords` (\"a,b,c\") into numbers; a missing or non-numeric part becomes NaN. */\nfunction parseCoords(coords: string | undefined): number[] {\n\treturn (coords ?? '').split(',').map((part) => Number(part.trim()));\n}\n\n/** Bounding box of a QTI shape (circle, ellipse, rect, poly) in image coordinates. */\nexport function shapeBounds(shape: string, coords: string | undefined): Bounds | null {\n\tconst n = parseCoords(coords);\n\tif (n.some((value) => !Number.isFinite(value))) return null;\n\tswitch (shape) {\n\t\tcase 'circle': {\n\t\t\tconst [cx, cy, r] = n;\n\t\t\tif (r === undefined) return null;\n\t\t\treturn { x: cx - r, y: cy - r, width: r * 2, height: r * 2 };\n\t\t}\n\t\tcase 'ellipse': {\n\t\t\tconst [cx, cy, rx, ry] = n;\n\t\t\tif (ry === undefined) return null;\n\t\t\treturn { x: cx - rx, y: cy - ry, width: rx * 2, height: ry * 2 };\n\t\t}\n\t\tcase 'rect': {\n\t\t\tconst [left, top, right, bottom] = n;\n\t\t\tif (bottom === undefined) return null;\n\t\t\treturn { x: left, y: top, width: right - left, height: bottom - top };\n\t\t}\n\t\tcase 'poly': {\n\t\t\tconst xs = n.filter((_, i) => i % 2 === 0);\n\t\t\tconst ys = n.filter((_, i) => i % 2 === 1);\n\t\t\tif (xs.length === 0 || ys.length === 0) return null;\n\t\t\tconst x = Math.min(...xs);\n\t\t\tconst y = Math.min(...ys);\n\t\t\treturn { x, y, width: Math.max(...xs) - x, height: Math.max(...ys) - y };\n\t\t}\n\t\tdefault:\n\t\t\treturn null;\n\t}\n}\n\n/** Centre of a QTI shape in image coordinates (polygon: vertex average). */\nexport function shapeCenter(shape: string, coords: string | undefined): Point {\n\tconst n = parseCoords(coords);\n\tif (shape === 'circle' || shape === 'ellipse') return { x: n[0] || 0, y: n[1] || 0 };\n\tif (shape === 'poly') {\n\t\tconst xs = n.filter((_, i) => i % 2 === 0);\n\t\tconst ys = n.filter((_, i) => i % 2 === 1);\n\t\tif (xs.length === 0 || ys.length === 0) return { x: 0, y: 0 };\n\t\treturn {\n\t\t\tx: xs.reduce((a, b) => a + b, 0) / xs.length,\n\t\t\ty: ys.reduce((a, b) => a + b, 0) / ys.length,\n\t\t};\n\t}\n\tconst bounds = shapeBounds(shape, coords);\n\treturn bounds ? { x: bounds.x + bounds.width / 2, y: bounds.y + bounds.height / 2 } : { x: n[0] || 0, y: n[1] || 0 };\n}\n\n/**\n * Where a marker (a check, a position badge) for a QTI region sits, in image coordinates: the\n * centre of its shape, or for the `default` shape — the whole image (QTI 3.0 §8.29) — `insetPx`\n * CSS px in from the image's top-left corner at the rendered `renderScale`, clear of the other\n * regions' markers at their centres. A shape whose `coords` are missing or unreadable marks at\n * the image origin.\n */\nexport function regionMarkerPoint(shape: string, coords: string | undefined, renderScale: number, insetPx: number): Point {\n\tif (shape === 'default') {\n\t\tconst inset = insetPx / (renderScale > 0 ? renderScale : 1);\n\t\treturn { x: inset, y: inset };\n\t}\n\tconst at = shapeCenter(shape, coords);\n\treturn Number.isFinite(at.x) && Number.isFinite(at.y) ? at : { x: 0, y: 0 };\n}\n\n/**\n * Width (CSS px) of a transparent, non-scaling hit stroke that grows a shape's\n * pointer target to at least {@link MIN_TARGET_PX} at the rendered scale. The\n * stroke straddles the outline, so the target's smallest extent becomes\n * `rendered size + stroke`. Zero for shapes that are already large enough.\n * Scoring geometry is untouched: only the hit area grows.\n */\nexport function hitStrokeWidth(shape: string, coords: string | undefined, renderScale: number): number {\n\tconst bounds = shapeBounds(shape, coords);\n\tif (!bounds) return 0;\n\tconst smallest = Math.min(bounds.width, bounds.height) * (renderScale > 0 ? renderScale : 1);\n\treturn Math.max(0, Math.ceil(MIN_TARGET_PX - smallest));\n}\n\n/**\n * Map a pointer or touch position (client px) on the rendered image to natural\n * image coordinates, so responses stay in the image's own pixel space at any\n * scale. The point is clamped to the image. It is rounded to whole image\n * pixels unless `round: false` — interactions that round (or don't) at their\n * own emission step pass `round: false` and keep their own rule.\n */\nexport function clientToImagePoint(\n\tclientX: number,\n\tclientY: number,\n\trect: { left: number; top: number; width: number; height: number },\n\tnaturalWidth: number,\n\tnaturalHeight: number,\n\toptions: { round?: boolean } = {},\n): Point | null {\n\tif (!(rect.width > 0) || !(rect.height > 0)) return null;\n\tconst x = ((clientX - rect.left) / rect.width) * naturalWidth;\n\tconst y = ((clientY - rect.top) / rect.height) * naturalHeight;\n\tif (options.round === false) {\n\t\treturn {\n\t\t\tx: Math.min(naturalWidth, Math.max(0, x)),\n\t\t\ty: Math.min(naturalHeight, Math.max(0, y)),\n\t\t};\n\t}\n\treturn {\n\t\tx: Math.min(naturalWidth, Math.max(0, Math.round(x))),\n\t\ty: Math.min(naturalHeight, Math.max(0, Math.round(y))),\n\t};\n}\n\nexport interface ImageTextAlternative {\n\talt?: string;\n\taltDescription?: string;\n\tdecorative?: boolean;\n}\n\n/**\n * The `alt` to render for an authored graphic-interaction image: empty only when\n * the author explicitly marked it decorative, else the authored text, else the\n * localized generic `fallback` (never an identifier or interaction-type name).\n */\nexport function imageAltText(image: ImageTextAlternative | null | undefined, fallback: string): string {\n\tif (image?.decorative) return '';\n\treturn image?.alt?.trim() || fallback;\n}\n\n/**\n * Escape plain text for a renderer that takes HTML (e.g. SortableList item text).\n * Extracted hotspot labels are decoded plain text, not sanitized HTML.\n */\nexport function escapeHtml(text: string): string {\n\treturn text\n\t\t.replace(/&/g, '&amp;')\n\t\t.replace(/</g, '&lt;')\n\t\t.replace(/>/g, '&gt;')\n\t\t.replace(/\"/g, '&quot;')\n\t\t.replace(/'/g, '&#39;');\n}\n\n/**\n * Svelte action reporting an element's rendered width (CSS px) now and on\n * resize. Environments without ResizeObserver report once.\n */\nexport function observeWidth(node: HTMLElement, onWidth: (width: number) => void) {\n\tlet callback = onWidth;\n\tcallback(node.getBoundingClientRect().width);\n\tconst RO = (globalThis as { ResizeObserver?: typeof ResizeObserver }).ResizeObserver;\n\tconst observer = RO\n\t\t? new RO((entries) => {\n\t\t\t\tfor (const entry of entries) callback(entry.contentRect.width);\n\t\t\t})\n\t\t: null;\n\tobserver?.observe(node);\n\treturn {\n\t\tupdate(next: (width: number) => void) {\n\t\t\tcallback = next;\n\t\t},\n\t\tdestroy() {\n\t\t\tobserver?.disconnect();\n\t\t},\n\t};\n}\n"]}
@@ -1,11 +1,24 @@
1
1
  import type { InteractionAccessibility } from '@pie-qti/item-player';
2
- /** The id of the hidden element `InteractionDescription` renders in an interaction's shadow root. */
2
+ /**
3
+ * Prefix of the id of the hidden element that carries an interaction's authored description.
4
+ * The full id is unique to one interaction: use `interactionDescriptionId(interaction)`.
5
+ */
3
6
  export declare const INTERACTION_DESCRIPTION_ID = "qti-interaction-description";
7
+ /** An interaction whose authored accessibility this module reads. */
8
+ export interface DescribedInteraction {
9
+ accessibility?: InteractionAccessibility;
10
+ }
11
+ /**
12
+ * The id of the hidden element that holds the interaction's authored description, or `null`
13
+ * when the interaction authors none. A custom component that renders its own description
14
+ * element gives it this id, read from the same interaction object it passes to
15
+ * `interactionAria()`.
16
+ */
17
+ export declare function interactionDescriptionId(interaction: DescribedInteraction | null | undefined): string | null;
4
18
  /**
5
19
  * Attributes that give an interaction's root its authored accessible name and description:
6
20
  * a labelled `group`, or nothing when the interaction carries no authored `aria-*`. The
7
- * description is the text `InteractionDescription` renders beside them.
21
+ * description is the text `InteractionDescription` renders beside them, under the id
22
+ * `interactionDescriptionId()` gives this interaction.
8
23
  */
9
- export declare function interactionAria(interaction: {
10
- accessibility?: InteractionAccessibility;
11
- } | null | undefined): Record<string, string>;
24
+ export declare function interactionAria(interaction: DescribedInteraction | null | undefined): Record<string, string>;
@@ -1,18 +1,57 @@
1
- /** The id of the hidden element `InteractionDescription` renders in an interaction's shadow root. */
1
+ /**
2
+ * Prefix of the id of the hidden element that carries an interaction's authored description.
3
+ * The full id is unique to one interaction: use `interactionDescriptionId(interaction)`.
4
+ */
2
5
  export const INTERACTION_DESCRIPTION_ID = 'qti-interaction-description';
6
+ /**
7
+ * One description id per interaction object. `interactionAria()` (the `aria-describedby` on the
8
+ * interaction root) and `<InteractionDescription interaction={…}>` (the hidden element it
9
+ * references) both ask for the id of the same parsed interaction object, so they stay in step,
10
+ * while every other interaction on the page — the other interactions of a composite item, or a
11
+ * second rendering of the same item — gets an id of its own, also when several interactions
12
+ * share one DOM tree instead of one shadow root each.
13
+ *
14
+ * Keyed weakly by the object the extractors delivered (or the component parsed from its JSON
15
+ * attribute), so an id lives exactly as long as that object. One object rendered twice in one
16
+ * tree shares its id, which then names the same description text.
17
+ */
18
+ const descriptionIds = new WeakMap();
19
+ let descriptionSequence = 0;
20
+ /**
21
+ * The id of the hidden element that holds the interaction's authored description, or `null`
22
+ * when the interaction authors none. A custom component that renders its own description
23
+ * element gives it this id, read from the same interaction object it passes to
24
+ * `interactionAria()`.
25
+ */
26
+ export function interactionDescriptionId(interaction) {
27
+ if (!interaction?.accessibility?.description)
28
+ return null;
29
+ // WeakMap keys must be objects; malformed non-object host data keeps the plain prefix.
30
+ if (typeof interaction !== 'object')
31
+ return INTERACTION_DESCRIPTION_ID;
32
+ let id = descriptionIds.get(interaction);
33
+ if (!id) {
34
+ descriptionSequence += 1;
35
+ id = `${INTERACTION_DESCRIPTION_ID}-${descriptionSequence}`;
36
+ descriptionIds.set(interaction, id);
37
+ }
38
+ return id;
39
+ }
3
40
  /**
4
41
  * Attributes that give an interaction's root its authored accessible name and description:
5
42
  * a labelled `group`, or nothing when the interaction carries no authored `aria-*`. The
6
- * description is the text `InteractionDescription` renders beside them.
43
+ * description is the text `InteractionDescription` renders beside them, under the id
44
+ * `interactionDescriptionId()` gives this interaction.
7
45
  */
8
46
  export function interactionAria(interaction) {
9
47
  const accessibility = interaction?.accessibility;
10
48
  if (!accessibility?.label && !accessibility?.description)
11
49
  return {};
50
+ const descriptionId = interactionDescriptionId(interaction);
12
51
  return {
13
52
  role: 'group',
14
53
  ...(accessibility.label ? { 'aria-label': accessibility.label } : {}),
15
- ...(accessibility.description ? { 'aria-describedby': INTERACTION_DESCRIPTION_ID } : {}),
54
+ ...(descriptionId ? { 'aria-describedby': descriptionId } : {}),
16
55
  };
17
56
  }
18
57
  //# sourceMappingURL=interactionAria.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"interactionAria.js","sourceRoot":"","sources":["../../../src/shared/utils/interactionAria.ts"],"names":[],"mappings":"AAEA,qGAAqG;AACrG,MAAM,CAAC,MAAM,0BAA0B,GAAG,6BAA6B,CAAC;AAExE;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAC9B,WAA4E;IAE5E,MAAM,aAAa,GAAG,WAAW,EAAE,aAAa,CAAC;IACjD,IAAI,CAAC,aAAa,EAAE,KAAK,IAAI,CAAC,aAAa,EAAE,WAAW;QAAE,OAAO,EAAE,CAAC;IACpE,OAAO;QACN,IAAI,EAAE,OAAO;QACb,GAAG,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,aAAa,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrE,GAAG,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACxF,CAAC;AACH,CAAC","sourcesContent":["import type { InteractionAccessibility } from '@pie-qti/item-player';\n\n/** The id of the hidden element `InteractionDescription` renders in an interaction's shadow root. */\nexport const INTERACTION_DESCRIPTION_ID = 'qti-interaction-description';\n\n/**\n * Attributes that give an interaction's root its authored accessible name and description:\n * a labelled `group`, or nothing when the interaction carries no authored `aria-*`. The\n * description is the text `InteractionDescription` renders beside them.\n */\nexport function interactionAria(\n\tinteraction: { accessibility?: InteractionAccessibility } | null | undefined,\n): Record<string, string> {\n\tconst accessibility = interaction?.accessibility;\n\tif (!accessibility?.label && !accessibility?.description) return {};\n\treturn {\n\t\trole: 'group',\n\t\t...(accessibility.label ? { 'aria-label': accessibility.label } : {}),\n\t\t...(accessibility.description ? { 'aria-describedby': INTERACTION_DESCRIPTION_ID } : {}),\n\t};\n}\n"]}
1
+ {"version":3,"file":"interactionAria.js","sourceRoot":"","sources":["../../../src/shared/utils/interactionAria.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,6BAA6B,CAAC;AAOxE;;;;;;;;;;;GAWG;AACH,MAAM,cAAc,GAAG,IAAI,OAAO,EAAkB,CAAC;AACrD,IAAI,mBAAmB,GAAG,CAAC,CAAC;AAE5B;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAAC,WAAoD;IAC5F,IAAI,CAAC,WAAW,EAAE,aAAa,EAAE,WAAW;QAAE,OAAO,IAAI,CAAC;IAC1D,uFAAuF;IACvF,IAAI,OAAO,WAAW,KAAK,QAAQ;QAAE,OAAO,0BAA0B,CAAC;IACvE,IAAI,EAAE,GAAG,cAAc,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACzC,IAAI,CAAC,EAAE,EAAE,CAAC;QACT,mBAAmB,IAAI,CAAC,CAAC;QACzB,EAAE,GAAG,GAAG,0BAA0B,IAAI,mBAAmB,EAAE,CAAC;QAC5D,cAAc,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,EAAE,CAAC;AACX,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAC9B,WAAoD;IAEpD,MAAM,aAAa,GAAG,WAAW,EAAE,aAAa,CAAC;IACjD,IAAI,CAAC,aAAa,EAAE,KAAK,IAAI,CAAC,aAAa,EAAE,WAAW;QAAE,OAAO,EAAE,CAAC;IACpE,MAAM,aAAa,GAAG,wBAAwB,CAAC,WAAW,CAAC,CAAC;IAC5D,OAAO;QACN,IAAI,EAAE,OAAO;QACb,GAAG,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,aAAa,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrE,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC/D,CAAC;AACH,CAAC","sourcesContent":["import type { InteractionAccessibility } from '@pie-qti/item-player';\n\n/**\n * Prefix of the id of the hidden element that carries an interaction's authored description.\n * The full id is unique to one interaction: use `interactionDescriptionId(interaction)`.\n */\nexport const INTERACTION_DESCRIPTION_ID = 'qti-interaction-description';\n\n/** An interaction whose authored accessibility this module reads. */\nexport interface DescribedInteraction {\n\taccessibility?: InteractionAccessibility;\n}\n\n/**\n * One description id per interaction object. `interactionAria()` (the `aria-describedby` on the\n * interaction root) and `<InteractionDescription interaction={…}>` (the hidden element it\n * references) both ask for the id of the same parsed interaction object, so they stay in step,\n * while every other interaction on the page — the other interactions of a composite item, or a\n * second rendering of the same item — gets an id of its own, also when several interactions\n * share one DOM tree instead of one shadow root each.\n *\n * Keyed weakly by the object the extractors delivered (or the component parsed from its JSON\n * attribute), so an id lives exactly as long as that object. One object rendered twice in one\n * tree shares its id, which then names the same description text.\n */\nconst descriptionIds = new WeakMap<object, string>();\nlet descriptionSequence = 0;\n\n/**\n * The id of the hidden element that holds the interaction's authored description, or `null`\n * when the interaction authors none. A custom component that renders its own description\n * element gives it this id, read from the same interaction object it passes to\n * `interactionAria()`.\n */\nexport function interactionDescriptionId(interaction: DescribedInteraction | null | undefined): string | null {\n\tif (!interaction?.accessibility?.description) return null;\n\t// WeakMap keys must be objects; malformed non-object host data keeps the plain prefix.\n\tif (typeof interaction !== 'object') return INTERACTION_DESCRIPTION_ID;\n\tlet id = descriptionIds.get(interaction);\n\tif (!id) {\n\t\tdescriptionSequence += 1;\n\t\tid = `${INTERACTION_DESCRIPTION_ID}-${descriptionSequence}`;\n\t\tdescriptionIds.set(interaction, id);\n\t}\n\treturn id;\n}\n\n/**\n * Attributes that give an interaction's root its authored accessible name and description:\n * a labelled `group`, or nothing when the interaction carries no authored `aria-*`. The\n * description is the text `InteractionDescription` renders beside them, under the id\n * `interactionDescriptionId()` gives this interaction.\n */\nexport function interactionAria(\n\tinteraction: DescribedInteraction | null | undefined,\n): Record<string, string> {\n\tconst accessibility = interaction?.accessibility;\n\tif (!accessibility?.label && !accessibility?.description) return {};\n\tconst descriptionId = interactionDescriptionId(interaction);\n\treturn {\n\t\trole: 'group',\n\t\t...(accessibility.label ? { 'aria-label': accessibility.label } : {}),\n\t\t...(descriptionId ? { 'aria-describedby': descriptionId } : {}),\n\t};\n}\n"]}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The props every interaction plugin shares.
3
+ *
4
+ * One type, keyed by the interaction's QTI type: the delivered data comes from
5
+ * `InteractionDataMap`, and what the plugin emits — its `onChange` argument and
6
+ * the `qti-change` event's value — from `InteractionValueMap`, so a plugin's
7
+ * emission type can never drift from the documented one. A plugin adds only
8
+ * what is its own.
9
+ *
10
+ * Types only: which props a plugin (and its custom element) actually exposes is
11
+ * decided by its `$props()` destructuring, which this does not change.
12
+ */
13
+ import type { I18nProvider } from '@pie-qti/i18n';
14
+ import type { InteractionDataMap, InteractionValueMap } from '@pie-qti/item-player';
15
+ /** The QTI interaction types the default plugins render. */
16
+ export type InteractionKey = keyof InteractionDataMap & keyof InteractionValueMap;
17
+ /**
18
+ * The shared props of an interaction plugin.
19
+ *
20
+ * @typeParam T - the interaction type, e.g. `'choiceInteraction'`
21
+ * @typeParam TResponse - the response a host passes in; defaults to the emitted
22
+ * value or null. A plugin that also accepts other inbound shapes (a single
23
+ * string for a list, a record) names its own.
24
+ * @typeParam TCorrect - the correct response a host passes in; defaults to
25
+ * `TResponse`.
26
+ */
27
+ export interface InteractionProps<T extends InteractionKey, TResponse = InteractionValueMap[T] | null, TCorrect = TResponse> {
28
+ /** The interaction's delivered data, or its JSON (custom element attribute usage). */
29
+ interaction?: InteractionDataMap[T] | string;
30
+ /** The candidate's response. */
31
+ response?: TResponse;
32
+ /** The correct response, shown in the scorer role. */
33
+ correctResponse?: TCorrect;
34
+ /** While true the interaction renders but takes no input. */
35
+ disabled?: boolean;
36
+ /** The viewing role: `candidate` (the default), or `scorer`, which sees the correct response. */
37
+ role?: string;
38
+ /** Localization provider for the plugin's own messages. */
39
+ i18n?: I18nProvider;
40
+ /** Called with each value the plugin emits: the `qti-change` event's value. */
41
+ onChange?: (value: InteractionValueMap[T]) => void;
42
+ }
43
+ /**
44
+ * The shared props of an interaction that has no correct response and no
45
+ * scorer view (media, end attempt, upload, drawing, custom, portable custom).
46
+ */
47
+ export type ResponseOnlyInteractionProps<T extends InteractionKey, TResponse = InteractionValueMap[T] | null> = Omit<InteractionProps<T, TResponse>, 'correctResponse' | 'role'>;
48
+ /** The math-typesetting hook of the interactions that render authored rich content. */
49
+ export interface TypesetProps {
50
+ /** Typesets math in an element after its content renders. */
51
+ typeset?: (element: HTMLElement) => void;
52
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The props every interaction plugin shares.
3
+ *
4
+ * One type, keyed by the interaction's QTI type: the delivered data comes from
5
+ * `InteractionDataMap`, and what the plugin emits — its `onChange` argument and
6
+ * the `qti-change` event's value — from `InteractionValueMap`, so a plugin's
7
+ * emission type can never drift from the documented one. A plugin adds only
8
+ * what is its own.
9
+ *
10
+ * Types only: which props a plugin (and its custom element) actually exposes is
11
+ * decided by its `$props()` destructuring, which this does not change.
12
+ */
13
+ export {};
14
+ //# sourceMappingURL=interactionProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interactionProps.js","sourceRoot":"","sources":["../../../src/shared/utils/interactionProps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG","sourcesContent":["/**\n * The props every interaction plugin shares.\n *\n * One type, keyed by the interaction's QTI type: the delivered data comes from\n * `InteractionDataMap`, and what the plugin emits — its `onChange` argument and\n * the `qti-change` event's value — from `InteractionValueMap`, so a plugin's\n * emission type can never drift from the documented one. A plugin adds only\n * what is its own.\n *\n * Types only: which props a plugin (and its custom element) actually exposes is\n * decided by its `$props()` destructuring, which this does not change.\n */\n\nimport type { I18nProvider } from '@pie-qti/i18n';\nimport type { InteractionDataMap, InteractionValueMap } from '@pie-qti/item-player';\n\n/** The QTI interaction types the default plugins render. */\nexport type InteractionKey = keyof InteractionDataMap & keyof InteractionValueMap;\n\n/**\n * The shared props of an interaction plugin.\n *\n * @typeParam T - the interaction type, e.g. `'choiceInteraction'`\n * @typeParam TResponse - the response a host passes in; defaults to the emitted\n * value or null. A plugin that also accepts other inbound shapes (a single\n * string for a list, a record) names its own.\n * @typeParam TCorrect - the correct response a host passes in; defaults to\n * `TResponse`.\n */\nexport interface InteractionProps<\n\tT extends InteractionKey,\n\tTResponse = InteractionValueMap[T] | null,\n\tTCorrect = TResponse,\n> {\n\t/** The interaction's delivered data, or its JSON (custom element attribute usage). */\n\tinteraction?: InteractionDataMap[T] | string;\n\t/** The candidate's response. */\n\tresponse?: TResponse;\n\t/** The correct response, shown in the scorer role. */\n\tcorrectResponse?: TCorrect;\n\t/** While true the interaction renders but takes no input. */\n\tdisabled?: boolean;\n\t/** The viewing role: `candidate` (the default), or `scorer`, which sees the correct response. */\n\trole?: string;\n\t/** Localization provider for the plugin's own messages. */\n\ti18n?: I18nProvider;\n\t/** Called with each value the plugin emits: the `qti-change` event's value. */\n\tonChange?: (value: InteractionValueMap[T]) => void;\n}\n\n/**\n * The shared props of an interaction that has no correct response and no\n * scorer view (media, end attempt, upload, drawing, custom, portable custom).\n */\nexport type ResponseOnlyInteractionProps<\n\tT extends InteractionKey,\n\tTResponse = InteractionValueMap[T] | null,\n> = Omit<InteractionProps<T, TResponse>, 'correctResponse' | 'role'>;\n\n/** The math-typesetting hook of the interactions that render authored rich content. */\nexport interface TypesetProps {\n\t/** Typesets math in an element after its content renders. */\n\ttypeset?: (element: HTMLElement) => void;\n}\n"]}
@@ -1,7 +1,29 @@
1
1
  /**
2
- * Returns true if a source and target choice are compatible for pairing.
2
+ * A choice, gap or hotspot that takes part in pairings, with its authored `matchGroup`.
3
+ * The renderer data omits the attribute when the author wrote none.
4
+ */
5
+ export interface MatchGroupBearer {
6
+ identifier: string;
7
+ matchGroup?: string[];
8
+ }
9
+ /**
10
+ * Whether the delivered UI may pair `a` with `b`: exactly the rule response validation applies
11
+ * (`isMatchGroupCompatible` from `@pie-qti/item-player`), so the UI never allows a pair that
12
+ * validation rejects nor blocks one it accepts.
3
13
  *
4
- * Per QTI spec, an empty/absent matchGroup is unrestricted (pairs with anything).
5
- * Two non-empty matchGroups are compatible only if they share at least one value.
14
+ * QTI defines `matchGroup` as "a list of the identifiers for the objects that can be matched
15
+ * with this" choice, gap text, gap image, gap or hotspot: QTI 2.2.4 ASI Information Model
16
+ * (Final Release, 2021) Tables 5.98.5, 5.39.4, 5.37.4, 5.36.4 and 5.5.4; QTI 3.0 ASI
17
+ * Information Model (Final Release 1.0, 2022) Tables 5.131.5, 5.58.4, 5.56.4, 5.55.4 and 5.7.4.
18
+ * Content also uses the tokens as shared group labels, and the shared rule accepts a pair when
19
+ * either reading allows it. A side the interaction does not have is left to other validation,
20
+ * as response validation does.
21
+ */
22
+ export declare function isCompatibleMatchGroup(a: MatchGroupBearer | null | undefined, b: MatchGroupBearer | null | undefined): boolean;
23
+ /**
24
+ * The identifiers of the `candidates` that `source` may not be paired with — the targets a held
25
+ * or dragged source marks as refusing it — by {@link isCompatibleMatchGroup}, the rule response
26
+ * validation applies, so the UI blocks exactly the pairs validation rejects. No source blocks
27
+ * nothing.
6
28
  */
7
- export declare function isCompatibleMatchGroup(sourceGroups: string[] | undefined, targetGroups: string[] | undefined): boolean;
29
+ export declare function matchGroupBlockedIds(source: MatchGroupBearer | null | undefined, candidates: readonly MatchGroupBearer[]): Set<string>;
@@ -1,14 +1,31 @@
1
+ import { isMatchGroupCompatible } from '@pie-qti/item-player';
1
2
  /**
2
- * Returns true if a source and target choice are compatible for pairing.
3
+ * Whether the delivered UI may pair `a` with `b`: exactly the rule response validation applies
4
+ * (`isMatchGroupCompatible` from `@pie-qti/item-player`), so the UI never allows a pair that
5
+ * validation rejects nor blocks one it accepts.
3
6
  *
4
- * Per QTI spec, an empty/absent matchGroup is unrestricted (pairs with anything).
5
- * Two non-empty matchGroups are compatible only if they share at least one value.
7
+ * QTI defines `matchGroup` as "a list of the identifiers for the objects that can be matched
8
+ * with this" choice, gap text, gap image, gap or hotspot: QTI 2.2.4 ASI Information Model
9
+ * (Final Release, 2021) Tables 5.98.5, 5.39.4, 5.37.4, 5.36.4 and 5.5.4; QTI 3.0 ASI
10
+ * Information Model (Final Release 1.0, 2022) Tables 5.131.5, 5.58.4, 5.56.4, 5.55.4 and 5.7.4.
11
+ * Content also uses the tokens as shared group labels, and the shared rule accepts a pair when
12
+ * either reading allows it. A side the interaction does not have is left to other validation,
13
+ * as response validation does.
6
14
  */
7
- export function isCompatibleMatchGroup(sourceGroups, targetGroups) {
8
- if (!sourceGroups || sourceGroups.length === 0)
15
+ export function isCompatibleMatchGroup(a, b) {
16
+ if (!a || !b)
9
17
  return true;
10
- if (!targetGroups || targetGroups.length === 0)
11
- return true;
12
- return sourceGroups.some((g) => targetGroups.includes(g));
18
+ return isMatchGroupCompatible({ identifier: a.identifier, matchGroup: a.matchGroup ?? [] }, { identifier: b.identifier, matchGroup: b.matchGroup ?? [] });
19
+ }
20
+ /**
21
+ * The identifiers of the `candidates` that `source` may not be paired with — the targets a held
22
+ * or dragged source marks as refusing it — by {@link isCompatibleMatchGroup}, the rule response
23
+ * validation applies, so the UI blocks exactly the pairs validation rejects. No source blocks
24
+ * nothing.
25
+ */
26
+ export function matchGroupBlockedIds(source, candidates) {
27
+ if (!source)
28
+ return new Set();
29
+ return new Set(candidates.filter((candidate) => !isCompatibleMatchGroup(source, candidate)).map((candidate) => candidate.identifier));
13
30
  }
14
31
  //# sourceMappingURL=matchGroupUtils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"matchGroupUtils.js","sourceRoot":"","sources":["../../../src/shared/utils/matchGroupUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACrC,YAAkC,EAClC,YAAkC;IAElC,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAC5D,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAC5D,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3D,CAAC","sourcesContent":["/**\n * Returns true if a source and target choice are compatible for pairing.\n *\n * Per QTI spec, an empty/absent matchGroup is unrestricted (pairs with anything).\n * Two non-empty matchGroups are compatible only if they share at least one value.\n */\nexport function isCompatibleMatchGroup(\n\tsourceGroups: string[] | undefined,\n\ttargetGroups: string[] | undefined\n): boolean {\n\tif (!sourceGroups || sourceGroups.length === 0) return true;\n\tif (!targetGroups || targetGroups.length === 0) return true;\n\treturn sourceGroups.some((g) => targetGroups.includes(g));\n}\n"]}
1
+ {"version":3,"file":"matchGroupUtils.js","sourceRoot":"","sources":["../../../src/shared/utils/matchGroupUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAW9D;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,sBAAsB,CAAC,CAAsC,EAAE,CAAsC;IACpH,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1B,OAAO,sBAAsB,CAC5B,EAAE,UAAU,EAAE,CAAC,CAAC,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC,UAAU,IAAI,EAAE,EAAE,EAC5D,EAAE,UAAU,EAAE,CAAC,CAAC,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC,UAAU,IAAI,EAAE,EAAE,CAC5D,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CACnC,MAA2C,EAC3C,UAAuC;IAEvC,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,GAAG,EAAE,CAAC;IAC9B,OAAO,IAAI,GAAG,CACb,UAAU,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,sBAAsB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC,CACrH,CAAC;AACH,CAAC","sourcesContent":["import { isMatchGroupCompatible } from '@pie-qti/item-player';\n\n/**\n * A choice, gap or hotspot that takes part in pairings, with its authored `matchGroup`.\n * The renderer data omits the attribute when the author wrote none.\n */\nexport interface MatchGroupBearer {\n\tidentifier: string;\n\tmatchGroup?: string[];\n}\n\n/**\n * Whether the delivered UI may pair `a` with `b`: exactly the rule response validation applies\n * (`isMatchGroupCompatible` from `@pie-qti/item-player`), so the UI never allows a pair that\n * validation rejects nor blocks one it accepts.\n *\n * QTI defines `matchGroup` as \"a list of the identifiers for the objects that can be matched\n * with this\" choice, gap text, gap image, gap or hotspot: QTI 2.2.4 ASI Information Model\n * (Final Release, 2021) Tables 5.98.5, 5.39.4, 5.37.4, 5.36.4 and 5.5.4; QTI 3.0 ASI\n * Information Model (Final Release 1.0, 2022) Tables 5.131.5, 5.58.4, 5.56.4, 5.55.4 and 5.7.4.\n * Content also uses the tokens as shared group labels, and the shared rule accepts a pair when\n * either reading allows it. A side the interaction does not have is left to other validation,\n * as response validation does.\n */\nexport function isCompatibleMatchGroup(a: MatchGroupBearer | null | undefined, b: MatchGroupBearer | null | undefined): boolean {\n\tif (!a || !b) return true;\n\treturn isMatchGroupCompatible(\n\t\t{ identifier: a.identifier, matchGroup: a.matchGroup ?? [] },\n\t\t{ identifier: b.identifier, matchGroup: b.matchGroup ?? [] },\n\t);\n}\n\n/**\n * The identifiers of the `candidates` that `source` may not be paired with — the targets a held\n * or dragged source marks as refusing it — by {@link isCompatibleMatchGroup}, the rule response\n * validation applies, so the UI blocks exactly the pairs validation rejects. No source blocks\n * nothing.\n */\nexport function matchGroupBlockedIds(\n\tsource: MatchGroupBearer | null | undefined,\n\tcandidates: readonly MatchGroupBearer[],\n): Set<string> {\n\tif (!source) return new Set();\n\treturn new Set(\n\t\tcandidates.filter((candidate) => !isCompatibleMatchGroup(source, candidate)).map((candidate) => candidate.identifier),\n\t);\n}\n"]}
@@ -0,0 +1,56 @@
1
+ import { type I18nProvider } from '@pie-qti/i18n';
2
+ /** A minimum an interaction's response must reach before it counts as complete. */
3
+ export interface MinimumHintOptions {
4
+ i18n: I18nProvider | undefined;
5
+ /** The authored minimum (minChoices, minAssociations); 0, absent or invalid means none. */
6
+ minimum: number | null | undefined;
7
+ /** How many the response holds now: selections, associations, ordered items. */
8
+ count: number;
9
+ /** The author's `data-min-selections-message`, which wins over the localized default. */
10
+ authored?: string | null;
11
+ /** The plural group of the localized default; `{count}` is the minimum. */
12
+ key: string;
13
+ /** English forms used when no catalog carries `key`. */
14
+ fallback: {
15
+ one: string;
16
+ other: string;
17
+ };
18
+ }
19
+ /**
20
+ * What an interaction states while its response is below an authored minimum — the same
21
+ * minimum response validation enforces before an answer counts as complete — so a candidate
22
+ * learns what is missing on the question itself, not only from a refused submit (WCAG 3.3.2,
23
+ * 3.3.3). Empty when there is no minimum or the response meets it.
24
+ */
25
+ export declare function minimumHint({ i18n, minimum, count, authored, key, fallback }: MinimumHintOptions): string;
26
+ /** The limits of a subset-ordering interaction (see `orderChoiceLimits` in item-player). */
27
+ export interface SubsetOrderHintOptions {
28
+ i18n: I18nProvider | undefined;
29
+ /** The fewest items a complete response orders (minChoices). */
30
+ min: number;
31
+ /** The most items a response may order (maxChoices, clamped to the choices). */
32
+ max: number;
33
+ /** How many items the response orders now. */
34
+ count: number;
35
+ /** The author's `data-min-selections-message`, which wins over the localized default. */
36
+ authored?: string | null;
37
+ /** Catalog namespace: `interactions.order` or `interactions.graphicOrder`. */
38
+ namespace: string;
39
+ }
40
+ /**
41
+ * The limits of subset ordering, stated in the same place and on the same terms as
42
+ * `minimumHint` while the order is short of its minimum (WCAG 3.3.2): "Choose 2 items and put
43
+ * them in order." when the minimum is also the maximum, else "Choose between 1 and 3 items…".
44
+ */
45
+ export declare function subsetOrderHint({ i18n, min, max, count, authored, namespace }: SubsetOrderHintOptions): string;
46
+ /** Space-separated `aria-describedby` ids, without the empty ones; undefined when none remain. */
47
+ export declare function describedByIds(...ids: Array<string | null | undefined | false>): string | undefined;
48
+ /**
49
+ * The choices of a pairing interaction (match, associate) whose authored `matchMin` the pairs do
50
+ * not reach yet, in authored order: a pair "a b" uses both of its choices, as response validation
51
+ * counts them.
52
+ */
53
+ export declare function choicesShortOfMatchMin<T extends {
54
+ identifier: string;
55
+ matchMin?: number;
56
+ }>(choices: readonly T[], pairs: readonly string[]): T[];
@@ -0,0 +1,50 @@
1
+ import { translatePlural } from '@pie-qti/i18n';
2
+ /**
3
+ * What an interaction states while its response is below an authored minimum — the same
4
+ * minimum response validation enforces before an answer counts as complete — so a candidate
5
+ * learns what is missing on the question itself, not only from a refused submit (WCAG 3.3.2,
6
+ * 3.3.3). Empty when there is no minimum or the response meets it.
7
+ */
8
+ export function minimumHint({ i18n, minimum, count, authored, key, fallback }) {
9
+ const required = Number(minimum ?? 0);
10
+ if (!Number.isFinite(required) || required <= 0 || count >= required)
11
+ return '';
12
+ return authored?.trim() || translatePlural(i18n, key, fallback, required);
13
+ }
14
+ /**
15
+ * The limits of subset ordering, stated in the same place and on the same terms as
16
+ * `minimumHint` while the order is short of its minimum (WCAG 3.3.2): "Choose 2 items and put
17
+ * them in order." when the minimum is also the maximum, else "Choose between 1 and 3 items…".
18
+ */
19
+ export function subsetOrderHint({ i18n, min, max, count, authored, namespace }) {
20
+ if (min <= 0 || count >= min)
21
+ return '';
22
+ if (authored?.trim())
23
+ return authored.trim();
24
+ return max === min
25
+ ? translatePlural(i18n, `${namespace}.subsetExactHint`, { one: 'Choose {count} item for your order.', other: 'Choose {count} items and put them in order.' }, min)
26
+ : translatePlural(i18n, `${namespace}.subsetRangeHint`, {
27
+ one: 'Choose between {min} and {max} item and put them in order.',
28
+ other: 'Choose between {min} and {max} items and put them in order.',
29
+ }, max, { min, max });
30
+ }
31
+ /** Space-separated `aria-describedby` ids, without the empty ones; undefined when none remain. */
32
+ export function describedByIds(...ids) {
33
+ const joined = ids.filter((id) => !!id).join(' ');
34
+ return joined || undefined;
35
+ }
36
+ /**
37
+ * The choices of a pairing interaction (match, associate) whose authored `matchMin` the pairs do
38
+ * not reach yet, in authored order: a pair "a b" uses both of its choices, as response validation
39
+ * counts them.
40
+ */
41
+ export function choicesShortOfMatchMin(choices, pairs) {
42
+ return choices.filter((choice) => {
43
+ const required = Number(choice.matchMin ?? 0);
44
+ if (!Number.isFinite(required) || required <= 0)
45
+ return false;
46
+ const uses = pairs.filter((pair) => pair.split(' ').includes(choice.identifier)).length;
47
+ return uses < required;
48
+ });
49
+ }
50
+ //# sourceMappingURL=minimumRequirement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"minimumRequirement.js","sourceRoot":"","sources":["../../../src/shared/utils/minimumRequirement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAqB,MAAM,eAAe,CAAC;AAiBnE;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAsB;IAChG,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC;IACtC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,QAAQ,IAAI,CAAC,IAAI,KAAK,IAAI,QAAQ;QAAE,OAAO,EAAE,CAAC;IAChF,OAAO,QAAQ,EAAE,IAAI,EAAE,IAAI,eAAe,CAAC,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC3E,CAAC;AAiBD;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAA0B;IACrG,IAAI,GAAG,IAAI,CAAC,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,EAAE,CAAC;IACxC,IAAI,QAAQ,EAAE,IAAI,EAAE;QAAE,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC7C,OAAO,GAAG,KAAK,GAAG;QACjB,CAAC,CAAC,eAAe,CACf,IAAI,EACJ,GAAG,SAAS,kBAAkB,EAC9B,EAAE,GAAG,EAAE,qCAAqC,EAAE,KAAK,EAAE,6CAA6C,EAAE,EACpG,GAAG,CACH;QACF,CAAC,CAAC,eAAe,CACf,IAAI,EACJ,GAAG,SAAS,kBAAkB,EAC9B;YACC,GAAG,EAAE,4DAA4D;YACjE,KAAK,EAAE,6DAA6D;SACpE,EACD,GAAG,EACH,EAAE,GAAG,EAAE,GAAG,EAAE,CACZ,CAAC;AACL,CAAC;AAED,kGAAkG;AAClG,MAAM,UAAU,cAAc,CAAC,GAAG,GAA6C;IAC9E,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,EAAgB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChE,OAAO,MAAM,IAAI,SAAS,CAAC;AAC5B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CACrC,OAAqB,EACrB,KAAwB;IAExB,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE;QAChC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC;QAC9C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,QAAQ,IAAI,CAAC;YAAE,OAAO,KAAK,CAAC;QAC9D,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC;QACxF,OAAO,IAAI,GAAG,QAAQ,CAAC;IACxB,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { translatePlural, type I18nProvider } from '@pie-qti/i18n';\n\n/** A minimum an interaction's response must reach before it counts as complete. */\nexport interface MinimumHintOptions {\n\ti18n: I18nProvider | undefined;\n\t/** The authored minimum (minChoices, minAssociations); 0, absent or invalid means none. */\n\tminimum: number | null | undefined;\n\t/** How many the response holds now: selections, associations, ordered items. */\n\tcount: number;\n\t/** The author's `data-min-selections-message`, which wins over the localized default. */\n\tauthored?: string | null;\n\t/** The plural group of the localized default; `{count}` is the minimum. */\n\tkey: string;\n\t/** English forms used when no catalog carries `key`. */\n\tfallback: { one: string; other: string };\n}\n\n/**\n * What an interaction states while its response is below an authored minimum — the same\n * minimum response validation enforces before an answer counts as complete — so a candidate\n * learns what is missing on the question itself, not only from a refused submit (WCAG 3.3.2,\n * 3.3.3). Empty when there is no minimum or the response meets it.\n */\nexport function minimumHint({ i18n, minimum, count, authored, key, fallback }: MinimumHintOptions): string {\n\tconst required = Number(minimum ?? 0);\n\tif (!Number.isFinite(required) || required <= 0 || count >= required) return '';\n\treturn authored?.trim() || translatePlural(i18n, key, fallback, required);\n}\n\n/** The limits of a subset-ordering interaction (see `orderChoiceLimits` in item-player). */\nexport interface SubsetOrderHintOptions {\n\ti18n: I18nProvider | undefined;\n\t/** The fewest items a complete response orders (minChoices). */\n\tmin: number;\n\t/** The most items a response may order (maxChoices, clamped to the choices). */\n\tmax: number;\n\t/** How many items the response orders now. */\n\tcount: number;\n\t/** The author's `data-min-selections-message`, which wins over the localized default. */\n\tauthored?: string | null;\n\t/** Catalog namespace: `interactions.order` or `interactions.graphicOrder`. */\n\tnamespace: string;\n}\n\n/**\n * The limits of subset ordering, stated in the same place and on the same terms as\n * `minimumHint` while the order is short of its minimum (WCAG 3.3.2): \"Choose 2 items and put\n * them in order.\" when the minimum is also the maximum, else \"Choose between 1 and 3 items…\".\n */\nexport function subsetOrderHint({ i18n, min, max, count, authored, namespace }: SubsetOrderHintOptions): string {\n\tif (min <= 0 || count >= min) return '';\n\tif (authored?.trim()) return authored.trim();\n\treturn max === min\n\t\t? translatePlural(\n\t\t\t\ti18n,\n\t\t\t\t`${namespace}.subsetExactHint`,\n\t\t\t\t{ one: 'Choose {count} item for your order.', other: 'Choose {count} items and put them in order.' },\n\t\t\t\tmin,\n\t\t\t)\n\t\t: translatePlural(\n\t\t\t\ti18n,\n\t\t\t\t`${namespace}.subsetRangeHint`,\n\t\t\t\t{\n\t\t\t\t\tone: 'Choose between {min} and {max} item and put them in order.',\n\t\t\t\t\tother: 'Choose between {min} and {max} items and put them in order.',\n\t\t\t\t},\n\t\t\t\tmax,\n\t\t\t\t{ min, max },\n\t\t\t);\n}\n\n/** Space-separated `aria-describedby` ids, without the empty ones; undefined when none remain. */\nexport function describedByIds(...ids: Array<string | null | undefined | false>): string | undefined {\n\tconst joined = ids.filter((id): id is string => !!id).join(' ');\n\treturn joined || undefined;\n}\n\n/**\n * The choices of a pairing interaction (match, associate) whose authored `matchMin` the pairs do\n * not reach yet, in authored order: a pair \"a b\" uses both of its choices, as response validation\n * counts them.\n */\nexport function choicesShortOfMatchMin<T extends { identifier: string; matchMin?: number }>(\n\tchoices: readonly T[],\n\tpairs: readonly string[],\n): T[] {\n\treturn choices.filter((choice) => {\n\t\tconst required = Number(choice.matchMin ?? 0);\n\t\tif (!Number.isFinite(required) || required <= 0) return false;\n\t\tconst uses = pairs.filter((pair) => pair.split(' ').includes(choice.identifier)).length;\n\t\treturn uses < required;\n\t});\n}\n"]}