@pie-qti/default-components 1.0.0-beta.4 → 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 (99) 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 +1 -1
  82. package/package.json +10 -10
  83. package/dist/chunks/__vite-browser-external-DwKjyYZK.js +0 -9
  84. package/dist/chunks/__vite-browser-external-DwKjyYZK.js.map +0 -1
  85. package/dist/chunks/ar-Cqx9S4Im.js +0 -919
  86. package/dist/chunks/ar-Cqx9S4Im.js.map +0 -1
  87. package/dist/chunks/es-DjA7IQ-N.js +0 -864
  88. package/dist/chunks/es-DjA7IQ-N.js.map +0 -1
  89. package/dist/chunks/fr-BhV6wQNG.js +0 -864
  90. package/dist/chunks/fr-BhV6wQNG.js.map +0 -1
  91. package/dist/chunks/nl-B0JlnB-a.js +0 -863
  92. package/dist/chunks/nl-B0JlnB-a.js.map +0 -1
  93. package/dist/chunks/ro-ClR0jejm.js +0 -864
  94. package/dist/chunks/ro-ClR0jejm.js.map +0 -1
  95. package/dist/chunks/rolldown-runtime-Y_bBpyJl.js +0 -20
  96. package/dist/chunks/th-RfNMAg5z.js +0 -863
  97. package/dist/chunks/th-RfNMAg5z.js.map +0 -1
  98. package/dist/chunks/zh-Hans-DJ82CLmG.js +0 -863
  99. package/dist/chunks/zh-Hans-DJ82CLmG.js.map +0 -1
@@ -39,7 +39,7 @@ export declare function createOrUpdatePair(pairs: string[], sourceId: string, ta
39
39
  * @param sourceId - The source identifier to remove
40
40
  * @returns A new array without the pair
41
41
  */
42
- export declare function removePairBySource(pairs: string[], sourceId: string): string[];
42
+ export declare function removePairBySource(pairs: readonly string[], sourceId: string): string[];
43
43
  /**
44
44
  * Removes a specific pair by source and target ID
45
45
  */
@@ -50,18 +50,52 @@ export declare function removePair(pairs: string[], sourceId: string, targetId:
50
50
  * @param targetId - The target identifier to remove
51
51
  * @returns A new array without the pair
52
52
  */
53
- export declare function removePairByTarget(pairs: string[], targetId: string): string[];
53
+ export declare function removePairByTarget(pairs: readonly string[], targetId: string): string[];
54
54
  /**
55
- * Checks if a source is paired
56
- * @param pairs - Array of pair strings
57
- * @param sourceId - The source identifier
58
- * @returns True if the source has a pair
55
+ * Counts the pairs that have an identifier as their source (the first token)
56
+ * @param pairs - Array of "sourceId targetId" pair strings
57
+ * @param sourceId - The source identifier to count
58
+ * @returns Number of pairs with that source
59
59
  */
60
- export declare function isSourcePaired(pairs: string[], sourceId: string): boolean;
60
+ export declare function countPairsForSource(pairs: readonly string[], sourceId: string): number;
61
61
  /**
62
- * Checks if a target is paired
63
- * @param pairs - Array of pair strings
64
- * @param targetId - The target identifier
65
- * @returns True if the target has a pair
62
+ * Places a source on a target in a directed-pair response, where each target holds one source
63
+ * (a gap, a graphic gap match hotspot). The pair is written "source target", the QTI
64
+ * `directedPair` order.
65
+ *
66
+ * - The target's previous pair is replaced.
67
+ * - `sourceCapacity` is how many targets the source may fill (its matchMax; 0 means no limit).
68
+ * Below it the source's other placements stay: the source is reused. At it the source moves:
69
+ * its other placements are removed, so the capacity is never exceeded. A single-use source
70
+ * (capacity 1) therefore always moves.
71
+ * - An empty `sourceId` adds no pair: the call clears the target.
72
+ *
73
+ * Unlike {@link createOrUpdatePair}, which keeps every other placement of the source (a
74
+ * many-to-many match, which refuses past its capacity instead), this moves a source at its
75
+ * capacity.
76
+ * @param pairs - Array of existing "sourceId targetId" pair strings
77
+ * @returns A new array with the placement applied
78
+ */
79
+ export declare function placeSourceOnTarget(pairs: readonly string[], sourceId: string, targetId: string, sourceCapacity: number): string[];
80
+ /**
81
+ * Whether the pairs hold the unordered pair of two identifiers, in either order: the reading of
82
+ * a QTI `pair` response (associate, graphic associate), whose pairs are unordered.
83
+ * @param pairs - Array of "first second" pair strings
84
+ * @returns True if "a b" or "b a" is among the pairs
85
+ */
86
+ export declare function hasUnorderedPair(pairs: readonly string[], a: string, b: string): boolean;
87
+ /**
88
+ * Checks if a pair string contains an identifier as its source or target token.
89
+ * Matches whole tokens only: "A B" contains "B" but not a substring like "B2".
90
+ * @param pair - A "sourceId targetId" pair string
91
+ * @param id - The identifier to look for
92
+ * @returns True if the identifier is either token of the pair
93
+ */
94
+ export declare function pairIncludesId(pair: string, id: string): boolean;
95
+ /**
96
+ * Counts how many pairs contain an identifier as source or target
97
+ * @param pairs - Array of "sourceId targetId" pair strings
98
+ * @param id - The identifier to count
99
+ * @returns Number of pairs involving the identifier
66
100
  */
67
- export declare function isTargetPaired(pairs: string[], targetId: string): boolean;
101
+ export declare function countPairsWithId(pairs: string[], id: string): number;
@@ -79,21 +79,73 @@ export function removePairByTarget(pairs, targetId) {
79
79
  return pairs.filter((p) => !p.endsWith(` ${targetId}`));
80
80
  }
81
81
  /**
82
- * Checks if a source is paired
83
- * @param pairs - Array of pair strings
84
- * @param sourceId - The source identifier
85
- * @returns True if the source has a pair
82
+ * Counts the pairs that have an identifier as their source (the first token)
83
+ * @param pairs - Array of "sourceId targetId" pair strings
84
+ * @param sourceId - The source identifier to count
85
+ * @returns Number of pairs with that source
86
86
  */
87
- export function isSourcePaired(pairs, sourceId) {
88
- return pairs.some((p) => p.startsWith(`${sourceId} `));
87
+ export function countPairsForSource(pairs, sourceId) {
88
+ return pairs.filter((p) => p.startsWith(`${sourceId} `)).length;
89
89
  }
90
90
  /**
91
- * Checks if a target is paired
92
- * @param pairs - Array of pair strings
93
- * @param targetId - The target identifier
94
- * @returns True if the target has a pair
91
+ * Places a source on a target in a directed-pair response, where each target holds one source
92
+ * (a gap, a graphic gap match hotspot). The pair is written "source target", the QTI
93
+ * `directedPair` order.
94
+ *
95
+ * - The target's previous pair is replaced.
96
+ * - `sourceCapacity` is how many targets the source may fill (its matchMax; 0 means no limit).
97
+ * Below it the source's other placements stay: the source is reused. At it the source moves:
98
+ * its other placements are removed, so the capacity is never exceeded. A single-use source
99
+ * (capacity 1) therefore always moves.
100
+ * - An empty `sourceId` adds no pair: the call clears the target.
101
+ *
102
+ * Unlike {@link createOrUpdatePair}, which keeps every other placement of the source (a
103
+ * many-to-many match, which refuses past its capacity instead), this moves a source at its
104
+ * capacity.
105
+ * @param pairs - Array of existing "sourceId targetId" pair strings
106
+ * @returns A new array with the placement applied
107
+ */
108
+ export function placeSourceOnTarget(pairs, sourceId, targetId, sourceCapacity) {
109
+ let next = removePairByTarget(pairs, targetId);
110
+ if (sourceCapacity > 0 && countPairsForSource(next, sourceId) >= sourceCapacity) {
111
+ next = removePairBySource(next, sourceId);
112
+ }
113
+ if (sourceId) {
114
+ const pair = `${sourceId} ${targetId}`;
115
+ if (!next.includes(pair))
116
+ next.push(pair);
117
+ }
118
+ return next;
119
+ }
120
+ /**
121
+ * Whether the pairs hold the unordered pair of two identifiers, in either order: the reading of
122
+ * a QTI `pair` response (associate, graphic associate), whose pairs are unordered.
123
+ * @param pairs - Array of "first second" pair strings
124
+ * @returns True if "a b" or "b a" is among the pairs
125
+ */
126
+ export function hasUnorderedPair(pairs, a, b) {
127
+ return pairs.some((p) => p === `${a} ${b}` || p === `${b} ${a}`);
128
+ }
129
+ /**
130
+ * Checks if a pair string contains an identifier as its source or target token.
131
+ * Matches whole tokens only: "A B" contains "B" but not a substring like "B2".
132
+ * @param pair - A "sourceId targetId" pair string
133
+ * @param id - The identifier to look for
134
+ * @returns True if the identifier is either token of the pair
135
+ */
136
+ export function pairIncludesId(pair, id) {
137
+ const spaceIndex = pair.indexOf(' ');
138
+ if (spaceIndex === -1)
139
+ return pair === id;
140
+ return pair.slice(0, spaceIndex) === id || pair.slice(spaceIndex + 1) === id;
141
+ }
142
+ /**
143
+ * Counts how many pairs contain an identifier as source or target
144
+ * @param pairs - Array of "sourceId targetId" pair strings
145
+ * @param id - The identifier to count
146
+ * @returns Number of pairs involving the identifier
95
147
  */
96
- export function isTargetPaired(pairs, targetId) {
97
- return pairs.some((p) => p.endsWith(` ${targetId}`));
148
+ export function countPairsWithId(pairs, id) {
149
+ return pairs.filter((p) => pairIncludesId(p, id)).length;
98
150
  }
99
151
  //# sourceMappingURL=pairHelpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pairHelpers.js","sourceRoot":"","sources":["../../../src/shared/utils/pairHelpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAe,EAAE,QAAgB;IACnE,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,QAAQ,GAAG,CAAC,CAAC,CAAC;IAC7D,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACzC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAe,EAAE,QAAgB;IACpE,OAAO,KAAK;SACV,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,QAAQ,GAAG,CAAC,CAAC;SAC3C,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;SAC3B,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnC,CAAC;AAED;;;;;GAKG;AAC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,CAAC;AAC7D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAe,EAAE,QAAgB;IACnE,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,QAAQ,EAAE,CAAC,CAAC,CAAC;AACzD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAe,EAAE,QAAgB;IAC/D,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,QAAQ,GAAG,CAAC,CAAC,CAAC;AACxD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAe,EAAE,QAAgB;IAC/D,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,QAAQ,EAAE,CAAC,CAAC,CAAC;AACtD,CAAC","sourcesContent":["/**\n * Utility functions for working with QTI pair responses\n * Pairs are represented as space-separated strings: \"sourceId targetId\"\n */\n\n/**\n * Gets the target ID matched with a source ID (first match only, for one-to-one display)\n * @param pairs - Array of \"sourceId targetId\" pair strings\n * @param sourceId - The source identifier to search for\n * @returns The matched target ID, or null if not found\n */\nexport function getTargetForSource(pairs: string[], sourceId: string): string | null {\n\tconst pair = pairs.find((p) => p.startsWith(`${sourceId} `));\n\treturn pair ? pair.split(' ')[1] : null;\n}\n\n/**\n * Gets all target IDs matched with a source ID (for many-to-many)\n * @param pairs - Array of \"sourceId targetId\" pair strings\n * @param sourceId - The source identifier to search for\n * @returns Array of matched target IDs\n */\nexport function getTargetsForSource(pairs: string[], sourceId: string): string[] {\n\treturn pairs\n\t\t.filter((p) => p.startsWith(`${sourceId} `))\n\t\t.map((p) => p.split(' ')[1])\n\t\t.filter((t): t is string => !!t);\n}\n\n/**\n * Gets the source ID matched with a target ID\n * @param pairs - Array of \"sourceId targetId\" pair strings\n * @param targetId - The target identifier to search for\n * @returns The matched source ID, or null if not found\n */\nexport function getSourceForTarget(pairs: string[], targetId: string): string | null {\n\tconst pair = pairs.find((p) => p.endsWith(` ${targetId}`));\n\treturn pair ? pair.split(' ')[0] : null;\n}\n\n/**\n * Creates or updates a pair.\n * - Removes any existing pair for the target (target receives at most one when matchMax=1)\n * - Does NOT remove other pairs for the source (allows many-to-many: one source → multiple targets)\n * @param pairs - Array of existing pair strings\n * @param sourceId - The source identifier\n * @param targetId - The target identifier\n * @returns A new array with the pair created/updated\n */\nexport function createOrUpdatePair(pairs: string[], sourceId: string, targetId: string): string[] {\n\t// Remove any existing pair for this target (target gets \"replaced\")\n\tlet newPairs = pairs.filter((p) => !p.endsWith(` ${targetId}`));\n\n\t// Don't remove source pairs - allows one source to match multiple targets (many-to-many)\n\t// Add new pair (avoid duplicate if same pair already exists)\n\tconst newPair = `${sourceId} ${targetId}`;\n\tif (!newPairs.includes(newPair)) {\n\t\tnewPairs.push(newPair);\n\t}\n\n\treturn newPairs;\n}\n\n/**\n * Removes a pair by source ID\n * @param pairs - Array of existing pair strings\n * @param sourceId - The source identifier to remove\n * @returns A new array without the pair\n */\nexport function removePairBySource(pairs: string[], sourceId: string): string[] {\n\treturn pairs.filter((p) => !p.startsWith(`${sourceId} `));\n}\n\n/**\n * Removes a specific pair by source and target ID\n */\nexport function removePair(pairs: string[], sourceId: string, targetId: string): string[] {\n\treturn pairs.filter((p) => p !== `${sourceId} ${targetId}`);\n}\n\n/**\n * Removes a pair by target ID\n * @param pairs - Array of existing pair strings\n * @param targetId - The target identifier to remove\n * @returns A new array without the pair\n */\nexport function removePairByTarget(pairs: string[], targetId: string): string[] {\n\treturn pairs.filter((p) => !p.endsWith(` ${targetId}`));\n}\n\n/**\n * Checks if a source is paired\n * @param pairs - Array of pair strings\n * @param sourceId - The source identifier\n * @returns True if the source has a pair\n */\nexport function isSourcePaired(pairs: string[], sourceId: string): boolean {\n\treturn pairs.some((p) => p.startsWith(`${sourceId} `));\n}\n\n/**\n * Checks if a target is paired\n * @param pairs - Array of pair strings\n * @param targetId - The target identifier\n * @returns True if the target has a pair\n */\nexport function isTargetPaired(pairs: string[], targetId: string): boolean {\n\treturn pairs.some((p) => p.endsWith(` ${targetId}`));\n}\n"]}
1
+ {"version":3,"file":"pairHelpers.js","sourceRoot":"","sources":["../../../src/shared/utils/pairHelpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAe,EAAE,QAAgB;IACnE,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,QAAQ,GAAG,CAAC,CAAC,CAAC;IAC7D,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACzC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAe,EAAE,QAAgB;IACpE,OAAO,KAAK;SACV,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,QAAQ,GAAG,CAAC,CAAC;SAC3C,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;SAC3B,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAe,EAAE,QAAgB;IACnE,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,QAAQ,EAAE,CAAC,CAAC,CAA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OAAO,CAAC,GAAG,CAAC,CAAC;IACrC,IAAI,UAAU,KAAK,CAAC,CAAC;QAAE,OAAO,IAAI,KAAK,EAAE,CAAC;IAC1C,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,KAAK,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;AAC9E,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAe,EAAE,EAAU;IAC3D,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,cAAc,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;AAC1D,CAAC","sourcesContent":["/**\n * Utility functions for working with QTI pair responses\n * Pairs are represented as space-separated strings: \"sourceId targetId\"\n */\n\n/**\n * Gets the target ID matched with a source ID (first match only, for one-to-one display)\n * @param pairs - Array of \"sourceId targetId\" pair strings\n * @param sourceId - The source identifier to search for\n * @returns The matched target ID, or null if not found\n */\nexport function getTargetForSource(pairs: string[], sourceId: string): string | null {\n\tconst pair = pairs.find((p) => p.startsWith(`${sourceId} `));\n\treturn pair ? pair.split(' ')[1] : null;\n}\n\n/**\n * Gets all target IDs matched with a source ID (for many-to-many)\n * @param pairs - Array of \"sourceId targetId\" pair strings\n * @param sourceId - The source identifier to search for\n * @returns Array of matched target IDs\n */\nexport function getTargetsForSource(pairs: string[], sourceId: string): string[] {\n\treturn pairs\n\t\t.filter((p) => p.startsWith(`${sourceId} `))\n\t\t.map((p) => p.split(' ')[1])\n\t\t.filter((t): t is string => !!t);\n}\n\n/**\n * Gets the source ID matched with a target ID\n * @param pairs - Array of \"sourceId targetId\" pair strings\n * @param targetId - The target identifier to search for\n * @returns The matched source ID, or null if not found\n */\nexport function getSourceForTarget(pairs: string[], targetId: string): string | null {\n\tconst pair = pairs.find((p) => p.endsWith(` ${targetId}`));\n\treturn pair ? pair.split(' ')[0] : null;\n}\n\n/**\n * Creates or updates a pair.\n * - Removes any existing pair for the target (target receives at most one when matchMax=1)\n * - Does NOT remove other pairs for the source (allows many-to-many: one source → multiple targets)\n * @param pairs - Array of existing pair strings\n * @param sourceId - The source identifier\n * @param targetId - The target identifier\n * @returns A new array with the pair created/updated\n */\nexport function createOrUpdatePair(pairs: string[], sourceId: string, targetId: string): string[] {\n\t// Remove any existing pair for this target (target gets \"replaced\")\n\tlet newPairs = pairs.filter((p) => !p.endsWith(` ${targetId}`));\n\n\t// Don't remove source pairs - allows one source to match multiple targets (many-to-many)\n\t// Add new pair (avoid duplicate if same pair already exists)\n\tconst newPair = `${sourceId} ${targetId}`;\n\tif (!newPairs.includes(newPair)) {\n\t\tnewPairs.push(newPair);\n\t}\n\n\treturn newPairs;\n}\n\n/**\n * Removes a pair by source ID\n * @param pairs - Array of existing pair strings\n * @param sourceId - The source identifier to remove\n * @returns A new array without the pair\n */\nexport function removePairBySource(pairs: readonly string[], sourceId: string): string[] {\n\treturn pairs.filter((p) => !p.startsWith(`${sourceId} `));\n}\n\n/**\n * Removes a specific pair by source and target ID\n */\nexport function removePair(pairs: string[], sourceId: string, targetId: string): string[] {\n\treturn pairs.filter((p) => p !== `${sourceId} ${targetId}`);\n}\n\n/**\n * Removes a pair by target ID\n * @param pairs - Array of existing pair strings\n * @param targetId - The target identifier to remove\n * @returns A new array without the pair\n */\nexport function removePairByTarget(pairs: readonly string[], targetId: string): string[] {\n\treturn pairs.filter((p) => !p.endsWith(` ${targetId}`));\n}\n\n/**\n * Counts the pairs that have an identifier as their source (the first token)\n * @param pairs - Array of \"sourceId targetId\" pair strings\n * @param sourceId - The source identifier to count\n * @returns Number of pairs with that source\n */\nexport function countPairsForSource(pairs: readonly string[], sourceId: string): number {\n\treturn pairs.filter((p) => p.startsWith(`${sourceId} `)).length;\n}\n\n/**\n * Places a source on a target in a directed-pair response, where each target holds one source\n * (a gap, a graphic gap match hotspot). The pair is written \"source target\", the QTI\n * `directedPair` order.\n *\n * - The target's previous pair is replaced.\n * - `sourceCapacity` is how many targets the source may fill (its matchMax; 0 means no limit).\n * Below it the source's other placements stay: the source is reused. At it the source moves:\n * its other placements are removed, so the capacity is never exceeded. A single-use source\n * (capacity 1) therefore always moves.\n * - An empty `sourceId` adds no pair: the call clears the target.\n *\n * Unlike {@link createOrUpdatePair}, which keeps every other placement of the source (a\n * many-to-many match, which refuses past its capacity instead), this moves a source at its\n * capacity.\n * @param pairs - Array of existing \"sourceId targetId\" pair strings\n * @returns A new array with the placement applied\n */\nexport function placeSourceOnTarget(\n\tpairs: readonly string[],\n\tsourceId: string,\n\ttargetId: string,\n\tsourceCapacity: number,\n): string[] {\n\tlet next = removePairByTarget(pairs, targetId);\n\tif (sourceCapacity > 0 && countPairsForSource(next, sourceId) >= sourceCapacity) {\n\t\tnext = removePairBySource(next, sourceId);\n\t}\n\tif (sourceId) {\n\t\tconst pair = `${sourceId} ${targetId}`;\n\t\tif (!next.includes(pair)) next.push(pair);\n\t}\n\treturn next;\n}\n\n/**\n * Whether the pairs hold the unordered pair of two identifiers, in either order: the reading of\n * a QTI `pair` response (associate, graphic associate), whose pairs are unordered.\n * @param pairs - Array of \"first second\" pair strings\n * @returns True if \"a b\" or \"b a\" is among the pairs\n */\nexport function hasUnorderedPair(pairs: readonly string[], a: string, b: string): boolean {\n\treturn pairs.some((p) => p === `${a} ${b}` || p === `${b} ${a}`);\n}\n\n/**\n * Checks if a pair string contains an identifier as its source or target token.\n * Matches whole tokens only: \"A B\" contains \"B\" but not a substring like \"B2\".\n * @param pair - A \"sourceId targetId\" pair string\n * @param id - The identifier to look for\n * @returns True if the identifier is either token of the pair\n */\nexport function pairIncludesId(pair: string, id: string): boolean {\n\tconst spaceIndex = pair.indexOf(' ');\n\tif (spaceIndex === -1) return pair === id;\n\treturn pair.slice(0, spaceIndex) === id || pair.slice(spaceIndex + 1) === id;\n}\n\n/**\n * Counts how many pairs contain an identifier as source or target\n * @param pairs - Array of \"sourceId targetId\" pair strings\n * @param id - The identifier to count\n * @returns Number of pairs involving the identifier\n */\nexport function countPairsWithId(pairs: string[], id: string): number {\n\treturn pairs.filter((p) => pairIncludesId(p, id)).length;\n}\n"]}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Keyboard model shared by the custom radio groups (single-select hottext and hotspot), the
3
+ * WAI-ARIA APG radio group pattern as native radios behave.
4
+ */
5
+ /**
6
+ * The move an arrow key makes through a radio group, in document order: 1 forward, -1 back,
7
+ * 0 for any other key. Up/Down are fixed; Left/Right follow the inline direction of `element`,
8
+ * as native radios do, so under RTL ArrowLeft moves forward. Arrows held with Alt, Ctrl or
9
+ * Meta stay with the browser and assistive technology (Alt+Left is Back): no move.
10
+ */
11
+ export declare function radioArrowStep(event: KeyboardEvent, element: Element): number;
12
+ /** The index `step` places away from `index` in a group of `count`, wrapping at both ends. */
13
+ export declare function wrapIndex(index: number, step: number, count: number): number;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Keyboard model shared by the custom radio groups (single-select hottext and hotspot), the
3
+ * WAI-ARIA APG radio group pattern as native radios behave.
4
+ */
5
+ /**
6
+ * The move an arrow key makes through a radio group, in document order: 1 forward, -1 back,
7
+ * 0 for any other key. Up/Down are fixed; Left/Right follow the inline direction of `element`,
8
+ * as native radios do, so under RTL ArrowLeft moves forward. Arrows held with Alt, Ctrl or
9
+ * Meta stay with the browser and assistive technology (Alt+Left is Back): no move.
10
+ */
11
+ export function radioArrowStep(event, element) {
12
+ if (event.altKey || event.ctrlKey || event.metaKey)
13
+ return 0;
14
+ if (event.key === 'ArrowDown')
15
+ return 1;
16
+ if (event.key === 'ArrowUp')
17
+ return -1;
18
+ if (event.key !== 'ArrowLeft' && event.key !== 'ArrowRight')
19
+ return 0;
20
+ const rtl = getComputedStyle(element).direction === 'rtl';
21
+ return (event.key === 'ArrowRight') !== rtl ? 1 : -1;
22
+ }
23
+ /** The index `step` places away from `index` in a group of `count`, wrapping at both ends. */
24
+ export function wrapIndex(index, step, count) {
25
+ return (((index + step) % count) + count) % count;
26
+ }
27
+ //# sourceMappingURL=radioGroup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"radioGroup.js","sourceRoot":"","sources":["../../../src/shared/utils/radioGroup.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAoB,EAAE,OAAgB;IACpE,IAAI,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO;QAAE,OAAO,CAAC,CAAC;IAC7D,IAAI,KAAK,CAAC,GAAG,KAAK,WAAW;QAAE,OAAO,CAAC,CAAC;IACxC,IAAI,KAAK,CAAC,GAAG,KAAK,SAAS;QAAE,OAAO,CAAC,CAAC,CAAC;IACvC,IAAI,KAAK,CAAC,GAAG,KAAK,WAAW,IAAI,KAAK,CAAC,GAAG,KAAK,YAAY;QAAE,OAAO,CAAC,CAAC;IACtE,MAAM,GAAG,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC,SAAS,KAAK,KAAK,CAAC;IAC1D,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,YAAY,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtD,CAAC;AAED,8FAA8F;AAC9F,MAAM,UAAU,SAAS,CAAC,KAAa,EAAE,IAAY,EAAE,KAAa;IACnE,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC;AACnD,CAAC","sourcesContent":["/**\n * Keyboard model shared by the custom radio groups (single-select hottext and hotspot), the\n * WAI-ARIA APG radio group pattern as native radios behave.\n */\n\n/**\n * The move an arrow key makes through a radio group, in document order: 1 forward, -1 back,\n * 0 for any other key. Up/Down are fixed; Left/Right follow the inline direction of `element`,\n * as native radios do, so under RTL ArrowLeft moves forward. Arrows held with Alt, Ctrl or\n * Meta stay with the browser and assistive technology (Alt+Left is Back): no move.\n */\nexport function radioArrowStep(event: KeyboardEvent, element: Element): number {\n\tif (event.altKey || event.ctrlKey || event.metaKey) return 0;\n\tif (event.key === 'ArrowDown') return 1;\n\tif (event.key === 'ArrowUp') return -1;\n\tif (event.key !== 'ArrowLeft' && event.key !== 'ArrowRight') return 0;\n\tconst rtl = getComputedStyle(element).direction === 'rtl';\n\treturn (event.key === 'ArrowRight') !== rtl ? 1 : -1;\n}\n\n/** The index `step` places away from `index` in a group of `count`, wrapping at both ends. */\nexport function wrapIndex(index: number, step: number, count: number): number {\n\treturn (((index + step) % count) + count) % count;\n}\n"]}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * The caller side of the shared ImageStage's sizing handshake, one instance per
3
+ * graphic interaction: the stage's pixel space (the image's authored width/height,
4
+ * else a raster image's natural size once loaded, else unknown), whether the
5
+ * overlay may draw in that space, the once-only author warning when the space
6
+ * never arrives, and the frame/scale derivations that keep CSS-px sizes steady
7
+ * while the image scales with its container (WCAG 1.4.10).
8
+ *
9
+ * QTI coordinates live in the image's pixel space, so unknown means the
10
+ * interaction refuses to place anything: a guessed space would silently
11
+ * misplace hotspots, points and areaMapping.
12
+ */
13
+ export interface StageImageOptions {
14
+ /**
15
+ * Whether the interaction's coordinates need the image's pixel space right now.
16
+ * Caller-derived, since the interactions legitimately differ: most gate on their
17
+ * image data (an absent image needs no space), while the hotspot's image is
18
+ * mandatory — the regions are its whole interaction — so it gates on the parsed
19
+ * interaction alone.
20
+ */
21
+ needsDimensions(): boolean;
22
+ /** The author warning when the pixel space never arrives; each interaction names itself in it. */
23
+ missingDimensionsWarning: string;
24
+ }
25
+ export interface StageImage {
26
+ /** The stage's pixel space; bind these to ImageStage's `width`/`height`. */
27
+ imageWidth: number | null;
28
+ imageHeight: number | null;
29
+ /** Whether the raster image failed to load; bind to ImageStage's `failed`. */
30
+ imageFailed: boolean;
31
+ /**
32
+ * True while a raster image without authored dimensions is still loading: the
33
+ * pixel space may still arrive, so the refusal holds until this settles. Bind to
34
+ * ImageStage's `awaiting`.
35
+ */
36
+ awaitingNaturalSize: boolean;
37
+ /** The stage container's rendered width (CSS px); bind to ImageStage's `renderedWidth` (with `reportWidth`). */
38
+ renderedWidth: number;
39
+ /** The overlay may draw: both pixel dimensions are known. */
40
+ readonly hasImageDimensions: boolean;
41
+ /** The interaction needs the pixel space, has none, and none is still coming. */
42
+ readonly missingDimensions: boolean;
43
+ /** Rendered CSS px per authored image px, for sizes that must not scale with the image; 1 while unknown. */
44
+ readonly renderScale: number;
45
+ /**
46
+ * Reflow (WCAG 1.4.10): the stage frame fills its container up to the image's
47
+ * natural size (plus the frame's 2px borders); empty while the size is unknown.
48
+ */
49
+ readonly frameStyle: string;
50
+ /**
51
+ * Tell the author once, on the console, when the pixel space never arrives.
52
+ * Call from a component effect so it re-runs as the state settles.
53
+ */
54
+ warnOnceMissingDimensions(): void;
55
+ }
56
+ export declare function createStageImage(options: StageImageOptions): StageImage;
@@ -0,0 +1,76 @@
1
+ /**
2
+ * The caller side of the shared ImageStage's sizing handshake, one instance per
3
+ * graphic interaction: the stage's pixel space (the image's authored width/height,
4
+ * else a raster image's natural size once loaded, else unknown), whether the
5
+ * overlay may draw in that space, the once-only author warning when the space
6
+ * never arrives, and the frame/scale derivations that keep CSS-px sizes steady
7
+ * while the image scales with its container (WCAG 1.4.10).
8
+ *
9
+ * QTI coordinates live in the image's pixel space, so unknown means the
10
+ * interaction refuses to place anything: a guessed space would silently
11
+ * misplace hotspots, points and areaMapping.
12
+ */
13
+ export function createStageImage(options) {
14
+ let imageWidth = $state(null);
15
+ let imageHeight = $state(null);
16
+ let imageFailed = $state(false);
17
+ let awaitingNaturalSize = $state(false);
18
+ let renderedWidth = $state(0);
19
+ const hasImageDimensions = $derived(imageWidth !== null && imageHeight !== null);
20
+ const missingDimensions = $derived(options.needsDimensions() && !hasImageDimensions && !awaitingNaturalSize);
21
+ const frameStyle = $derived(imageWidth ? `max-width: calc(${imageWidth}px + 4px);` : '');
22
+ const renderScale = $derived(imageWidth && renderedWidth > 0 ? renderedWidth / imageWidth : 1);
23
+ let warnedMissingDimensions = false;
24
+ function warnOnceMissingDimensions() {
25
+ if (missingDimensions && !warnedMissingDimensions) {
26
+ warnedMissingDimensions = true;
27
+ console.warn(options.missingDimensionsWarning);
28
+ }
29
+ }
30
+ return {
31
+ get imageWidth() {
32
+ return imageWidth;
33
+ },
34
+ set imageWidth(value) {
35
+ imageWidth = value;
36
+ },
37
+ get imageHeight() {
38
+ return imageHeight;
39
+ },
40
+ set imageHeight(value) {
41
+ imageHeight = value;
42
+ },
43
+ get imageFailed() {
44
+ return imageFailed;
45
+ },
46
+ set imageFailed(value) {
47
+ imageFailed = value;
48
+ },
49
+ get awaitingNaturalSize() {
50
+ return awaitingNaturalSize;
51
+ },
52
+ set awaitingNaturalSize(value) {
53
+ awaitingNaturalSize = value;
54
+ },
55
+ get renderedWidth() {
56
+ return renderedWidth;
57
+ },
58
+ set renderedWidth(value) {
59
+ renderedWidth = value;
60
+ },
61
+ get hasImageDimensions() {
62
+ return hasImageDimensions;
63
+ },
64
+ get missingDimensions() {
65
+ return missingDimensions;
66
+ },
67
+ get renderScale() {
68
+ return renderScale;
69
+ },
70
+ get frameStyle() {
71
+ return frameStyle;
72
+ },
73
+ warnOnceMissingDimensions,
74
+ };
75
+ }
76
+ //# sourceMappingURL=stageImage.svelte.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stageImage.svelte.js","sourceRoot":"","sources":["../../../src/shared/utils/stageImage.svelte.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AA+CH,MAAM,UAAU,gBAAgB,CAAC,OAA0B;IAC1D,IAAI,UAAU,GAAG,MAAM,CAAgB,IAAI,CAAC,CAAC;IAC7C,IAAI,WAAW,GAAG,MAAM,CAAgB,IAAI,CAAC,CAAC;IAC9C,IAAI,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAChC,IAAI,mBAAmB,GAAG,M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IAAI,mBAAmB,CAAC,KAAc;YACrC,mBAAmB,GAAG,KAAK,CAAC;QAC7B,CAAC;QACD,IAAI,aAAa;YAChB,OAAO,aAAa,CAAC;QACtB,CAAC;QACD,IAAI,aAAa,CAAC,KAAa;YAC9B,aAAa,GAAG,KAAK,CAAC;QACvB,CAAC;QACD,IAAI,kBAAkB;YACrB,OAAO,kBAAkB,CAAC;QAC3B,CAAC;QACD,IAAI,iBAAiB;YACpB,OAAO,iBAAiB,CAAC;QAC1B,CAAC;QACD,IAAI,WAAW;YACd,OAAO,WAAW,CAAC;QACpB,CAAC;QACD,IAAI,UAAU;YACb,OAAO,UAAU,CAAC;QACnB,CAAC;QACD,yBAAyB;KACzB,CAAC;AACH,CAAC","sourcesContent":["/**\n * The caller side of the shared ImageStage's sizing handshake, one instance per\n * graphic interaction: the stage's pixel space (the image's authored width/height,\n * else a raster image's natural size once loaded, else unknown), whether the\n * overlay may draw in that space, the once-only author warning when the space\n * never arrives, and the frame/scale derivations that keep CSS-px sizes steady\n * while the image scales with its container (WCAG 1.4.10).\n *\n * QTI coordinates live in the image's pixel space, so unknown means the\n * interaction refuses to place anything: a guessed space would silently\n * misplace hotspots, points and areaMapping.\n */\n\nexport interface StageImageOptions {\n\t/**\n\t * Whether the interaction's coordinates need the image's pixel space right now.\n\t * Caller-derived, since the interactions legitimately differ: most gate on their\n\t * image data (an absent image needs no space), while the hotspot's image is\n\t * mandatory — the regions are its whole interaction — so it gates on the parsed\n\t * interaction alone.\n\t */\n\tneedsDimensions(): boolean;\n\t/** The author warning when the pixel space never arrives; each interaction names itself in it. */\n\tmissingDimensionsWarning: string;\n}\n\nexport interface StageImage {\n\t/** The stage's pixel space; bind these to ImageStage's `width`/`height`. */\n\timageWidth: number | null;\n\timageHeight: number | null;\n\t/** Whether the raster image failed to load; bind to ImageStage's `failed`. */\n\timageFailed: boolean;\n\t/**\n\t * True while a raster image without authored dimensions is still loading: the\n\t * pixel space may still arrive, so the refusal holds until this settles. Bind to\n\t * ImageStage's `awaiting`.\n\t */\n\tawaitingNaturalSize: boolean;\n\t/** The stage container's rendered width (CSS px); bind to ImageStage's `renderedWidth` (with `reportWidth`). */\n\trenderedWidth: number;\n\t/** The overlay may draw: both pixel dimensions are known. */\n\treadonly hasImageDimensions: boolean;\n\t/** The interaction needs the pixel space, has none, and none is still coming. */\n\treadonly missingDimensions: boolean;\n\t/** Rendered CSS px per authored image px, for sizes that must not scale with the image; 1 while unknown. */\n\treadonly renderScale: number;\n\t/**\n\t * Reflow (WCAG 1.4.10): the stage frame fills its container up to the image's\n\t * natural size (plus the frame's 2px borders); empty while the size is unknown.\n\t */\n\treadonly frameStyle: string;\n\t/**\n\t * Tell the author once, on the console, when the pixel space never arrives.\n\t * Call from a component effect so it re-runs as the state settles.\n\t */\n\twarnOnceMissingDimensions(): void;\n}\n\nexport function createStageImage(options: StageImageOptions): StageImage {\n\tlet imageWidth = $state<number | null>(null);\n\tlet imageHeight = $state<number | null>(null);\n\tlet imageFailed = $state(false);\n\tlet awaitingNaturalSize = $state(false);\n\tlet renderedWidth = $state(0);\n\n\tconst hasImageDimensions = $derived(imageWidth !== null && imageHeight !== null);\n\tconst missingDimensions = $derived(options.needsDimensions() && !hasImageDimensions && !awaitingNaturalSize);\n\tconst frameStyle = $derived(imageWidth ? `max-width: calc(${imageWidth}px + 4px);` : '');\n\tconst renderScale = $derived(imageWidth && renderedWidth > 0 ? renderedWidth / imageWidth : 1);\n\n\tlet warnedMissingDimensions = false;\n\tfunction warnOnceMissingDimensions(): void {\n\t\tif (missingDimensions && !warnedMissingDimensions) {\n\t\t\twarnedMissingDimensions = true;\n\t\t\tconsole.warn(options.missingDimensionsWarning);\n\t\t}\n\t}\n\n\treturn {\n\t\tget imageWidth() {\n\t\t\treturn imageWidth;\n\t\t},\n\t\tset imageWidth(value: number | null) {\n\t\t\timageWidth = value;\n\t\t},\n\t\tget imageHeight() {\n\t\t\treturn imageHeight;\n\t\t},\n\t\tset imageHeight(value: number | null) {\n\t\t\timageHeight = value;\n\t\t},\n\t\tget imageFailed() {\n\t\t\treturn imageFailed;\n\t\t},\n\t\tset imageFailed(value: boolean) {\n\t\t\timageFailed = value;\n\t\t},\n\t\tget awaitingNaturalSize() {\n\t\t\treturn awaitingNaturalSize;\n\t\t},\n\t\tset awaitingNaturalSize(value: boolean) {\n\t\t\tawaitingNaturalSize = value;\n\t\t},\n\t\tget renderedWidth() {\n\t\t\treturn renderedWidth;\n\t\t},\n\t\tset renderedWidth(value: number) {\n\t\t\trenderedWidth = value;\n\t\t},\n\t\tget hasImageDimensions() {\n\t\t\treturn hasImageDimensions;\n\t\t},\n\t\tget missingDimensions() {\n\t\t\treturn missingDimensions;\n\t\t},\n\t\tget renderScale() {\n\t\t\treturn renderScale;\n\t\t},\n\t\tget frameStyle() {\n\t\t\treturn frameStyle;\n\t\t},\n\t\twarnOnceMissingDimensions,\n\t};\n}\n"]}
@@ -2,15 +2,47 @@
2
2
  * Helper utilities for web component prop handling
3
3
  */
4
4
  /**
5
- * Parse a prop that may be a JSON string or an object
6
- * Used when components are used as web components and receive JSON strings
5
+ * Parse a prop whose value is always an object (interaction data, a PNP profile): the object
6
+ * itself, or its JSON text, which is how an HTML attribute carries it
7
+ * (`<pie-qti-choice interaction='{"responseId":"R1",…}'>`). The string "null" stands for no
8
+ * value. Text that does not parse to an object — a truncated attribute, or JSON of another
9
+ * shape — is reported once on the console and read as no value, so the component renders its
10
+ * no-data state instead of a string masquerading as the data object.
11
+ *
12
+ * Never use it for a response: a string response is a value, and reading it as JSON would turn
13
+ * the answer "1.50" into 1.5 or "null" into no answer. Responses go through `responseProp`.
7
14
  */
8
15
  export declare function parseJsonProp<T>(prop: T | string | null | undefined): T | undefined;
16
+ /**
17
+ * A response-like prop (`response`, `correctResponse`) as the host set it. Hosts set responses as
18
+ * JavaScript properties, and a response is never JSON text: a string is the candidate's text or a
19
+ * choice identifier and stays exactly that ("1.50", "1e5", "true", "null", "[1]"). `null` means no
20
+ * response.
21
+ */
22
+ export declare function responseProp<T>(prop: T | null | undefined): T | undefined;
23
+ /**
24
+ * A list response (the `response`/`correctResponse` of the identifier-list interactions: order,
25
+ * match, associate, gap match and the graphic interactions, and a multiple-selection hotspot) as
26
+ * the host set it. Hosts set lists as JavaScript properties; an HTML attribute carries a list as
27
+ * its JSON text, so a string that reads as a JSON array is read as that list. Any other string
28
+ * stays as given: identifiers such as "true" or "null" are never JSON, and a list response is
29
+ * never a bare string value.
30
+ */
31
+ export declare function parseListResponseProp<T>(prop: T | string | null | undefined): T | undefined;
9
32
  export interface InteractionShellProps<TInteraction, TResponse, TCorrectResponse = TResponse> {
33
+ /** The interaction data, or its JSON text (an HTML attribute). */
10
34
  interaction?: TInteraction | string;
11
- response?: TResponse | string | null;
12
- correctResponse?: TCorrectResponse | string | null;
35
+ /** The response itself, never JSON text. */
36
+ response?: TResponse | null;
37
+ /** The correct response itself, never JSON text. */
38
+ correctResponse?: TCorrectResponse | null;
13
39
  role?: string;
40
+ /**
41
+ * The response and correct response are lists of identifiers. Set this so a string that reads
42
+ * as a JSON array — how an HTML attribute carries a list — is read as that list; every other
43
+ * string stays as given, so identifiers are never read as JSON.
44
+ */
45
+ listResponse?: boolean;
14
46
  }
15
47
  export interface InteractionShell<TInteraction, TResponse, TCorrectResponse = TResponse> {
16
48
  interaction: TInteraction | undefined;
@@ -21,4 +53,4 @@ export interface InteractionShell<TInteraction, TResponse, TCorrectResponse = TR
21
53
  }
22
54
  export declare function createInteractionShell<TInteraction extends {
23
55
  responseId?: string;
24
- }, TResponse, TCorrectResponse = TResponse>({ interaction, response, correctResponse, role, }: InteractionShellProps<TInteraction, TResponse, TCorrectResponse>): InteractionShell<TInteraction, TResponse, TCorrectResponse>;
56
+ }, TResponse, TCorrectResponse = TResponse>({ interaction, response, correctResponse, role, listResponse, }: InteractionShellProps<TInteraction, TResponse, TCorrectResponse>): InteractionShell<TInteraction, TResponse, TCorrectResponse>;
@@ -2,32 +2,85 @@
2
2
  * Helper utilities for web component prop handling
3
3
  */
4
4
  /**
5
- * Parse a prop that may be a JSON string or an object
6
- * Used when components are used as web components and receive JSON strings
5
+ * Parse a prop whose value is always an object (interaction data, a PNP profile): the object
6
+ * itself, or its JSON text, which is how an HTML attribute carries it
7
+ * (`<pie-qti-choice interaction='{"responseId":"R1",…}'>`). The string "null" stands for no
8
+ * value. Text that does not parse to an object — a truncated attribute, or JSON of another
9
+ * shape — is reported once on the console and read as no value, so the component renders its
10
+ * no-data state instead of a string masquerading as the data object.
11
+ *
12
+ * Never use it for a response: a string response is a value, and reading it as JSON would turn
13
+ * the answer "1.50" into 1.5 or "null" into no answer. Responses go through `responseProp`.
7
14
  */
8
15
  export function parseJsonProp(prop) {
9
16
  if (prop === null || prop === undefined)
10
17
  return undefined;
11
- if (typeof prop === 'string') {
12
- // Handle "null" string
13
- if (prop === 'null')
14
- return undefined;
15
- // Try to parse as JSON
16
- try {
17
- return JSON.parse(prop);
18
- }
19
- catch {
20
- // If it's not valid JSON, return the string as-is
21
- // This handles simple string identifiers
22
- return prop;
23
- }
18
+ if (typeof prop !== 'string')
19
+ return prop;
20
+ if (prop === 'null')
21
+ return undefined;
22
+ let value;
23
+ try {
24
+ value = JSON.parse(prop);
25
+ }
26
+ catch {
27
+ return reportInvalidJsonProp(prop);
28
+ }
29
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
30
+ return reportInvalidJsonProp(prop);
31
+ }
32
+ return value;
33
+ }
34
+ /**
35
+ * Report a data attribute that is not the JSON object its prop requires, and read it as no
36
+ * value. Once per distinct text: the shells derive from their props, so a live component
37
+ * re-runs the parse on every recompute — one warning per attribute keeps the console readable.
38
+ */
39
+ const reportedInvalidJsonProps = new Set();
40
+ function reportInvalidJsonProp(text) {
41
+ if (!reportedInvalidJsonProps.has(text)) {
42
+ reportedInvalidJsonProps.add(text);
43
+ const snippet = text.length > 80 ? `${text.slice(0, 80)}…` : text;
44
+ console.warn(`[pie-qti] a data attribute is not the JSON object its component requires and is treated as absent (the component shows its no-data state): ${snippet}`);
45
+ }
46
+ return undefined;
47
+ }
48
+ /**
49
+ * A response-like prop (`response`, `correctResponse`) as the host set it. Hosts set responses as
50
+ * JavaScript properties, and a response is never JSON text: a string is the candidate's text or a
51
+ * choice identifier and stays exactly that ("1.50", "1e5", "true", "null", "[1]"). `null` means no
52
+ * response.
53
+ */
54
+ export function responseProp(prop) {
55
+ return prop ?? undefined;
56
+ }
57
+ /**
58
+ * A list response (the `response`/`correctResponse` of the identifier-list interactions: order,
59
+ * match, associate, gap match and the graphic interactions, and a multiple-selection hotspot) as
60
+ * the host set it. Hosts set lists as JavaScript properties; an HTML attribute carries a list as
61
+ * its JSON text, so a string that reads as a JSON array is read as that list. Any other string
62
+ * stays as given: identifiers such as "true" or "null" are never JSON, and a list response is
63
+ * never a bare string value.
64
+ */
65
+ export function parseListResponseProp(prop) {
66
+ if (typeof prop !== 'string')
67
+ return responseProp(prop);
68
+ if (!prop.trimStart().startsWith('['))
69
+ return prop;
70
+ try {
71
+ const value = JSON.parse(prop);
72
+ return Array.isArray(value) ? value : prop;
73
+ }
74
+ catch {
75
+ return prop;
24
76
  }
25
- return prop;
26
77
  }
27
- export function createInteractionShell({ interaction, response, correctResponse, role = 'candidate', }) {
78
+ export function createInteractionShell({ interaction, response, correctResponse, role = 'candidate', listResponse = false, }) {
28
79
  const parsedInteraction = parseJsonProp(interaction);
29
- const parsedResponse = parseJsonProp(response);
30
- const parsedCorrectResponse = parseJsonProp(correctResponse);
80
+ const parsedResponse = listResponse ? parseListResponseProp(response) : responseProp(response);
81
+ const parsedCorrectResponse = listResponse
82
+ ? parseListResponseProp(correctResponse)
83
+ : responseProp(correctResponse);
31
84
  return {
32
85
  interaction: parsedInteraction,
33
86
  response: parsedResponse,
@@ -1 +1 @@
1
- {"version":3,"file":"webComponentHelpers.js","sourceRoot":"","sources":["../../../src/shared/utils/webComponentHelpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAI,IAAmC;IACnE,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAE1D,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9B,uBAAuB;QACvB,IAAI,IAAI,KAAK,MAAM;YAAE,OAAO,SAAS,CAAC;QAEtC,uBAAuB;QACvB,IAAI,CAAC;YACJ,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAM,CAAC;QAC9B,CAAC;QAAC,MAAM,CAAC;YACR,kDAAkD;YAClD,yCAAyC;YACzC,OAAO,IAAoB,CAAC;QAC7B,CAAC;IACF,CAAC;IAED,OAAO,IAAS,CAAC;AAClB,CAAC;AAiBD,MAAM,UAAU,sBAAsB,CAIpC,EACD,WAAW,EACX,QAAQ,EACR,eAAe,EACf,IAAI,GAAG,WAAW,GACgD;IAKlE,MAAM,iBAAiB,GAAG,aAAa,CAAe,WAAW,CAAC,CAAC;IACnE,MAAM,cAAc,GAAG,aAAa,CAAY,QAAQ,CAAC,CAAC;IAC1D,MAAM,qBAAqB,GAAG,aAAa,CAAmB,eAAe,CAAC,CAAC;IAE/E,OAAO;QACN,WAAW,EAAE,iBAAiB;QAC9B,QAAQ,EAAE,cAAc;QACxB,eAAe,EAAE,qBAAqB;QACtC,gBAAgB,EAAE,IAAI,KAAK,QAAQ,IAAI,qBAAqB,KAAK,SAAS;QAC1E,UAAU,EAAE,iBAAiB,EAAE,UAAU;KACzC,CAAC;AACH,CAAC","sourcesContent":["/**\n * Helper utilities for web component prop handling\n */\n\n/**\n * Parse a prop that may be a JSON string or an object\n * Used when components are used as web components and receive JSON strings\n */\nexport function parseJsonProp<T>(prop: T | string | null | undefined): T | undefined {\n\tif (prop === null || prop === undefined) return undefined;\n\n\tif (typeof prop === 'string') {\n\t\t// Handle \"null\" string\n\t\tif (prop === 'null') return undefined;\n\n\t\t// Try to parse as JSON\n\t\ttry {\n\t\t\treturn JSON.parse(prop) as T;\n\t\t} catch {\n\t\t\t// If it's not valid JSON, return the string as-is\n\t\t\t// This handles simple string identifiers\n\t\t\treturn prop as unknown as T;\n\t\t}\n\t}\n\n\treturn prop as T;\n}\n\nexport interface InteractionShellProps<TInteraction, TResponse, TCorrectResponse = TResponse> {\n\tinteraction?: TInteraction | string;\n\tresponse?: TResponse | string | null;\n\tcorrectResponse?: TCorrectResponse | string | null;\n\trole?: string;\n}\n\nexport interface InteractionShell<TInteraction, TResponse, TCorrectResponse = TResponse> {\n\tinteraction: TInteraction | undefined;\n\tresponse: TResponse | undefined;\n\tcorrectResponse: TCorrectResponse | undefined;\n\tisShowingCorrect: boolean;\n\tresponseId: string | undefined;\n}\n\nexport function createInteractionShell<\n\tTInteraction extends { responseId?: string },\n\tTResponse,\n\tTCorrectResponse = TResponse,\n>({\n\tinteraction,\n\tresponse,\n\tcorrectResponse,\n\trole = 'candidate',\n}: InteractionShellProps<TInteraction, TResponse, TCorrectResponse>): InteractionShell<\n\tTInteraction,\n\tTResponse,\n\tTCorrectResponse\n> {\n\tconst parsedInteraction = parseJsonProp<TInteraction>(interaction);\n\tconst parsedResponse = parseJsonProp<TResponse>(response);\n\tconst parsedCorrectResponse = parseJsonProp<TCorrectResponse>(correctResponse);\n\n\treturn {\n\t\tinteraction: parsedInteraction,\n\t\tresponse: parsedResponse,\n\t\tcorrectResponse: parsedCorrectResponse,\n\t\tisShowingCorrect: role === 'scorer' && parsedCorrectResponse !== undefined,\n\t\tresponseId: parsedInteraction?.responseId,\n\t};\n}\n"]}
1
+ {"version":3,"file":"webComponentHelpers.js","sourceRoot":"","sources":["../../../src/shared/utils/webComponentHelpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa,CAAI,IAAmC;IACnE,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1D,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAS,CAAC;I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AC,GAAG,CAAC;QAAE,OAAO,IAAoB,CAAC;IACnE,IAAI,CAAC;QACJ,MAAM,KAAK,GAAY,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACxC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAE,KAAW,CAAC,CAAC,CAAE,IAAqB,CAAC;IACrE,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,IAAoB,CAAC;IAC7B,CAAC;AACF,CAAC;AA0BD,MAAM,UAAU,sBAAsB,CAIpC,EACD,WAAW,EACX,QAAQ,EACR,eAAe,EACf,IAAI,GAAG,WAAW,EAClB,YAAY,GAAG,KAAK,GAC8C;IAKlE,MAAM,iBAAiB,GAAG,aAAa,CAAe,WAAW,CAAC,CAAC;IACnE,MAAM,cAAc,GAAG,YAAY,CAAC,CAAC,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC/F,MAAM,qBAAqB,GAAG,YAAY;QACzC,CAAC,CAAC,qBAAqB,CAAC,eAAe,CAAC;QACxC,CAAC,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;IAEjC,OAAO;QACN,WAAW,EAAE,iBAAiB;QAC9B,QAAQ,EAAE,cAAc;QACxB,eAAe,EAAE,qBAAqB;QACtC,gBAAgB,EAAE,IAAI,KAAK,QAAQ,IAAI,qBAAqB,KAAK,SAAS;QAC1E,UAAU,EAAE,iBAAiB,EAAE,UAAU;KACzC,CAAC;AACH,CAAC","sourcesContent":["/**\n * Helper utilities for web component prop handling\n */\n\n/**\n * Parse a prop whose value is always an object (interaction data, a PNP profile): the object\n * itself, or its JSON text, which is how an HTML attribute carries it\n * (`<pie-qti-choice interaction='{\"responseId\":\"R1\",…}'>`). The string \"null\" stands for no\n * value. Text that does not parse to an object — a truncated attribute, or JSON of another\n * shape — is reported once on the console and read as no value, so the component renders its\n * no-data state instead of a string masquerading as the data object.\n *\n * Never use it for a response: a string response is a value, and reading it as JSON would turn\n * the answer \"1.50\" into 1.5 or \"null\" into no answer. Responses go through `responseProp`.\n */\nexport function parseJsonProp<T>(prop: T | string | null | undefined): T | undefined {\n\tif (prop === null || prop === undefined) return undefined;\n\tif (typeof prop !== 'string') return prop as T;\n\tif (prop === 'null') return undefined;\n\n\tlet value: unknown;\n\ttry {\n\t\tvalue = JSON.parse(prop);\n\t} catch {\n\t\treturn reportInvalidJsonProp(prop);\n\t}\n\tif (typeof value !== 'object' || value === null || Array.isArray(value)) {\n\t\treturn reportInvalidJsonProp(prop);\n\t}\n\treturn value as T;\n}\n\n/**\n * Report a data attribute that is not the JSON object its prop requires, and read it as no\n * value. Once per distinct text: the shells derive from their props, so a live component\n * re-runs the parse on every recompute — one warning per attribute keeps the console readable.\n */\nconst reportedInvalidJsonProps = new Set<string>();\nfunction reportInvalidJsonProp(text: string): undefined {\n\tif (!reportedInvalidJsonProps.has(text)) {\n\t\treportedInvalidJsonProps.add(text);\n\t\tconst snippet = text.length > 80 ? `${text.slice(0, 80)}…` : text;\n\t\tconsole.warn(\n\t\t\t`[pie-qti] a data attribute is not the JSON object its component requires and is treated as absent (the component shows its no-data state): ${snippet}`,\n\t\t);\n\t}\n\treturn undefined;\n}\n\n/**\n * A response-like prop (`response`, `correctResponse`) as the host set it. Hosts set responses as\n * JavaScript properties, and a response is never JSON text: a string is the candidate's text or a\n * choice identifier and stays exactly that (\"1.50\", \"1e5\", \"true\", \"null\", \"[1]\"). `null` means no\n * response.\n */\nexport function responseProp<T>(prop: T | null | undefined): T | undefined {\n\treturn prop ?? undefined;\n}\n\n/**\n * A list response (the `response`/`correctResponse` of the identifier-list interactions: order,\n * match, associate, gap match and the graphic interactions, and a multiple-selection hotspot) as\n * the host set it. Hosts set lists as JavaScript properties; an HTML attribute carries a list as\n * its JSON text, so a string that reads as a JSON array is read as that list. Any other string\n * stays as given: identifiers such as \"true\" or \"null\" are never JSON, and a list response is\n * never a bare string value.\n */\nexport function parseListResponseProp<T>(prop: T | string | null | undefined): T | undefined {\n\tif (typeof prop !== 'string') return responseProp(prop);\n\tif (!prop.trimStart().startsWith('[')) return prop as unknown as T;\n\ttry {\n\t\tconst value: unknown = JSON.parse(prop);\n\t\treturn Array.isArray(value) ? (value as T) : (prop as unknown as T);\n\t} catch {\n\t\treturn prop as unknown as T;\n\t}\n}\n\nexport interface InteractionShellProps<TInteraction, TResponse, TCorrectResponse = TResponse> {\n\t/** The interaction data, or its JSON text (an HTML attribute). */\n\tinteraction?: TInteraction | string;\n\t/** The response itself, never JSON text. */\n\tresponse?: TResponse | null;\n\t/** The correct response itself, never JSON text. */\n\tcorrectResponse?: TCorrectResponse | null;\n\trole?: string;\n\t/**\n\t * The response and correct response are lists of identifiers. Set this so a string that reads\n\t * as a JSON array — how an HTML attribute carries a list — is read as that list; every other\n\t * string stays as given, so identifiers are never read as JSON.\n\t */\n\tlistResponse?: boolean;\n}\n\nexport interface InteractionShell<TInteraction, TResponse, TCorrectResponse = TResponse> {\n\tinteraction: TInteraction | undefined;\n\tresponse: TResponse | undefined;\n\tcorrectResponse: TCorrectResponse | undefined;\n\tisShowingCorrect: boolean;\n\tresponseId: string | undefined;\n}\n\nexport function createInteractionShell<\n\tTInteraction extends { responseId?: string },\n\tTResponse,\n\tTCorrectResponse = TResponse,\n>({\n\tinteraction,\n\tresponse,\n\tcorrectResponse,\n\trole = 'candidate',\n\tlistResponse = false,\n}: InteractionShellProps<TInteraction, TResponse, TCorrectResponse>): InteractionShell<\n\tTInteraction,\n\tTResponse,\n\tTCorrectResponse\n> {\n\tconst parsedInteraction = parseJsonProp<TInteraction>(interaction);\n\tconst parsedResponse = listResponse ? parseListResponseProp(response) : responseProp(response);\n\tconst parsedCorrectResponse = listResponse\n\t\t? parseListResponseProp(correctResponse)\n\t\t: responseProp(correctResponse);\n\n\treturn {\n\t\tinteraction: parsedInteraction,\n\t\tresponse: parsedResponse,\n\t\tcorrectResponse: parsedCorrectResponse,\n\t\tisShowingCorrect: role === 'scorer' && parsedCorrectResponse !== undefined,\n\t\tresponseId: parsedInteraction?.responseId,\n\t};\n}\n"]}