@citolab/qti-components 7.14.2 → 7.15.0

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 (147) hide show
  1. package/cdn/index.global.js +1 -1
  2. package/cdn/index.js +4070 -4048
  3. package/custom-elements.json +10320 -25886
  4. package/dist/base.d.ts +8 -0
  5. package/dist/base.js +50 -0
  6. package/dist/{chunks/chunk-7567ZPN6.js → chunk-2DOYPVF5.js} +252 -136
  7. package/dist/chunk-2DOYPVF5.js.map +1 -0
  8. package/dist/chunk-2ZEJ3RR5.js +89 -0
  9. package/dist/chunk-2ZEJ3RR5.js.map +1 -0
  10. package/dist/{chunks/chunk-Z2FFXTKX.js → chunk-352OTVTY.js} +1483 -445
  11. package/dist/chunk-352OTVTY.js.map +1 -0
  12. package/dist/{chunks/chunk-2X2C5WI5.js → chunk-C2HQFI2C.js} +939 -3842
  13. package/dist/chunk-C2HQFI2C.js.map +1 -0
  14. package/dist/chunk-DWIRLYDS.js +20 -0
  15. package/dist/chunk-DWIRLYDS.js.map +1 -0
  16. package/dist/{chunks/chunk-H2JE6IVU.js → chunk-EUXUH3YW.js} +1 -1
  17. package/dist/chunk-F44CI35W.js +145 -0
  18. package/dist/chunk-F44CI35W.js.map +1 -0
  19. package/dist/{chunks/chunk-XBPO6E25.js → chunk-INKI27D5.js} +6 -5
  20. package/dist/chunk-INKI27D5.js.map +1 -0
  21. package/dist/chunk-JEUY3MYB.js +2010 -0
  22. package/dist/chunk-JEUY3MYB.js.map +1 -0
  23. package/dist/chunk-O4XIWHTF.js +1139 -0
  24. package/dist/chunk-O4XIWHTF.js.map +1 -0
  25. package/dist/chunk-RI47B4ZT.js +1753 -0
  26. package/dist/chunk-RI47B4ZT.js.map +1 -0
  27. package/dist/{qti-loader/index.js → chunk-VEV4DGPH.js} +6 -6
  28. package/dist/chunk-VEV4DGPH.js.map +1 -0
  29. package/dist/{chunks/chunk-PT5ASWGQ.js → chunk-W4SQRNWO.js} +105 -2
  30. package/dist/chunk-W4SQRNWO.js.map +1 -0
  31. package/dist/elements.d.ts +1 -0
  32. package/dist/elements.js +42 -0
  33. package/dist/index.d.ts +8 -24
  34. package/dist/index.js +118 -284
  35. package/dist/index.js.map +1 -1
  36. package/dist/interactions.d.ts +1 -0
  37. package/dist/interactions.js +72 -0
  38. package/dist/item.css +8 -0
  39. package/dist/item.d.ts +1 -0
  40. package/dist/item.js +23 -0
  41. package/dist/loader.d.ts +1 -0
  42. package/dist/loader.js +11 -0
  43. package/dist/processing.d.ts +1 -0
  44. package/dist/processing.js +103 -0
  45. package/dist/qti-components-jsx.d.ts +1540 -2452
  46. package/dist/test.d.ts +1 -0
  47. package/dist/{qti-test/index.js → test.js} +11 -19
  48. package/dist/transformers.d.ts +1 -0
  49. package/dist/{qti-transformers/index.js → transformers.js} +3 -3
  50. package/dist/vscode.html-custom-data.json +469 -631
  51. package/package.json +71 -167
  52. package/LICENSE.md +0 -674
  53. package/dist/chunks/chunk-2X2C5WI5.js.map +0 -1
  54. package/dist/chunks/chunk-4OGJBG35.js +0 -8
  55. package/dist/chunks/chunk-4OGJBG35.js.map +0 -1
  56. package/dist/chunks/chunk-7567ZPN6.js.map +0 -1
  57. package/dist/chunks/chunk-BHJSX3Q6.js +0 -8
  58. package/dist/chunks/chunk-BHJSX3Q6.js.map +0 -1
  59. package/dist/chunks/chunk-C5RLRG3L.js +0 -10
  60. package/dist/chunks/chunk-C5RLRG3L.js.map +0 -1
  61. package/dist/chunks/chunk-CJADUWEC.js +0 -10
  62. package/dist/chunks/chunk-CJADUWEC.js.map +0 -1
  63. package/dist/chunks/chunk-DVQQ7I6Y.js +0 -8
  64. package/dist/chunks/chunk-DVQQ7I6Y.js.map +0 -1
  65. package/dist/chunks/chunk-ELDMXTUQ.js +0 -31
  66. package/dist/chunks/chunk-ELDMXTUQ.js.map +0 -1
  67. package/dist/chunks/chunk-GAAFN7QF.js +0 -146
  68. package/dist/chunks/chunk-GAAFN7QF.js.map +0 -1
  69. package/dist/chunks/chunk-H6KHXSIO.js +0 -8
  70. package/dist/chunks/chunk-H6KHXSIO.js.map +0 -1
  71. package/dist/chunks/chunk-JQ6HWGRY.js +0 -22
  72. package/dist/chunks/chunk-JQ6HWGRY.js.map +0 -1
  73. package/dist/chunks/chunk-NJNQOQUU.js +0 -8
  74. package/dist/chunks/chunk-NJNQOQUU.js.map +0 -1
  75. package/dist/chunks/chunk-P4QBOVQ2.js +0 -206
  76. package/dist/chunks/chunk-P4QBOVQ2.js.map +0 -1
  77. package/dist/chunks/chunk-PT5ASWGQ.js.map +0 -1
  78. package/dist/chunks/chunk-SV4K25ZI.js +0 -19
  79. package/dist/chunks/chunk-SV4K25ZI.js.map +0 -1
  80. package/dist/chunks/chunk-XBPO6E25.js.map +0 -1
  81. package/dist/chunks/chunk-YD7FVKDP.js +0 -236
  82. package/dist/chunks/chunk-YD7FVKDP.js.map +0 -1
  83. package/dist/chunks/chunk-Z2FFXTKX.js.map +0 -1
  84. package/dist/exports/computed-item.context.d.ts +0 -23
  85. package/dist/exports/computed-item.context.js +0 -8
  86. package/dist/exports/computed.context.d.ts +0 -34
  87. package/dist/exports/computed.context.js +0 -8
  88. package/dist/exports/config.context.d.ts +0 -14
  89. package/dist/exports/config.context.js +0 -8
  90. package/dist/exports/expression-result.d.ts +0 -19
  91. package/dist/exports/expression-result.js +0 -1
  92. package/dist/exports/interaction.d.ts +0 -46
  93. package/dist/exports/interaction.interface.d.ts +0 -13
  94. package/dist/exports/interaction.interface.js +0 -1
  95. package/dist/exports/interaction.js +0 -12
  96. package/dist/exports/item.context.d.ts +0 -11
  97. package/dist/exports/item.context.js +0 -8
  98. package/dist/exports/qti-assessment-item.context.d.ts +0 -9
  99. package/dist/exports/qti-assessment-item.context.js +0 -8
  100. package/dist/exports/qti-condition-expression.d.ts +0 -14
  101. package/dist/exports/qti-condition-expression.js +0 -11
  102. package/dist/exports/qti-condition-expression.js.map +0 -1
  103. package/dist/exports/qti-expression.d.ts +0 -23
  104. package/dist/exports/qti-expression.js +0 -10
  105. package/dist/exports/qti-expression.js.map +0 -1
  106. package/dist/exports/qti-test.d.ts +0 -12
  107. package/dist/exports/qti-test.js +0 -1
  108. package/dist/exports/qti-test.js.map +0 -1
  109. package/dist/exports/qti.context.d.ts +0 -14
  110. package/dist/exports/qti.context.js +0 -8
  111. package/dist/exports/qti.context.js.map +0 -1
  112. package/dist/exports/session.context.d.ts +0 -15
  113. package/dist/exports/session.context.js +0 -10
  114. package/dist/exports/session.context.js.map +0 -1
  115. package/dist/exports/test.context.d.ts +0 -16
  116. package/dist/exports/test.context.js +0 -10
  117. package/dist/exports/test.context.js.map +0 -1
  118. package/dist/exports/variables.d.ts +0 -2
  119. package/dist/exports/variables.js +0 -1
  120. package/dist/exports/variables.js.map +0 -1
  121. package/dist/qti-assessment-item-l-mN3teH.d.ts +0 -105
  122. package/dist/qti-components/index.d.ts +0 -1522
  123. package/dist/qti-components/index.js +0 -214
  124. package/dist/qti-components/index.js.map +0 -1
  125. package/dist/qti-item/index.d.ts +0 -114
  126. package/dist/qti-item/index.js +0 -19
  127. package/dist/qti-item/index.js.map +0 -1
  128. package/dist/qti-loader/index.d.ts +0 -21
  129. package/dist/qti-loader/index.js.map +0 -1
  130. package/dist/qti-modal-feedback-PKbhO-3w.d.ts +0 -30
  131. package/dist/qti-test/index.d.ts +0 -480
  132. package/dist/qti-test/index.js.map +0 -1
  133. package/dist/qti-test-Db7oNIWY.d.ts +0 -120
  134. package/dist/qti-transform-test-Bz9A3hmD.d.ts +0 -63
  135. package/dist/qti-transformers/index.d.ts +0 -18
  136. package/dist/qti-transformers/index.js.map +0 -1
  137. package/dist/variables-BCkyLoXK.d.ts +0 -55
  138. package/readme.md +0 -59
  139. /package/dist/{chunks/chunk-H2JE6IVU.js.map → base.js.map} +0 -0
  140. /package/dist/{exports/computed-item.context.js.map → chunk-EUXUH3YW.js.map} +0 -0
  141. /package/dist/{exports/computed.context.js.map → elements.js.map} +0 -0
  142. /package/dist/{exports/config.context.js.map → interactions.js.map} +0 -0
  143. /package/dist/{exports/expression-result.js.map → item.js.map} +0 -0
  144. /package/dist/{exports/interaction.interface.js.map → loader.js.map} +0 -0
  145. /package/dist/{exports/interaction.js.map → processing.js.map} +0 -0
  146. /package/dist/{exports/item.context.js.map → test.js.map} +0 -0
  147. /package/dist/{exports/qti-assessment-item.context.js.map → transformers.js.map} +0 -0
@@ -0,0 +1,1753 @@
1
+ import {
2
+ E,
3
+ QtiConditionExpression,
4
+ QtiExpression,
5
+ ScoringHelper,
6
+ c,
7
+ convertNumberToUniversalFormat,
8
+ i2 as i,
9
+ itemContext,
10
+ n,
11
+ r,
12
+ t,
13
+ testContext,
14
+ x
15
+ } from "./chunk-JEUY3MYB.js";
16
+ import {
17
+ __decorateClass
18
+ } from "./chunk-EUXUH3YW.js";
19
+
20
+ // ../qti-processing/src/components/qti-rule/qti-rule.ts
21
+ var QtiRule = class extends i {
22
+ render() {
23
+ return x`<slot></slot>`;
24
+ }
25
+ process() {
26
+ throw new Error("Not implemented");
27
+ }
28
+ };
29
+ QtiRule = __decorateClass([
30
+ t("qti-rule")
31
+ ], QtiRule);
32
+
33
+ // ../qti-processing/src/components/qti-lookup-outcome-value/qti-lookup-outcome-value.ts
34
+ var QtiLookupOutcomeValue = class extends QtiRule {
35
+ get childExpression() {
36
+ return this.firstElementChild;
37
+ }
38
+ process() {
39
+ const identifier = this.getAttribute("identifier");
40
+ const outcomeVariable = this.context.variables.find((v) => v.identifier === identifier) || null;
41
+ let value;
42
+ if (outcomeVariable.interpolationTable) {
43
+ value = outcomeVariable.interpolationTable.get(parseFloat(this.childExpression.calculate()));
44
+ }
45
+ if (value === null || value === void 0) {
46
+ console.warn("lookupOutcomeValue: value is null or undefined");
47
+ return 0;
48
+ }
49
+ this.dispatchEvent(
50
+ new CustomEvent("qti-set-outcome-value", {
51
+ bubbles: true,
52
+ composed: true,
53
+ detail: {
54
+ outcomeIdentifier: this.identifier,
55
+ value: convertNumberToUniversalFormat(value)
56
+ }
57
+ })
58
+ );
59
+ return value;
60
+ }
61
+ };
62
+ __decorateClass([
63
+ n({ type: String })
64
+ ], QtiLookupOutcomeValue.prototype, "identifier", 2);
65
+ __decorateClass([
66
+ c({ context: itemContext, subscribe: true }),
67
+ r()
68
+ ], QtiLookupOutcomeValue.prototype, "context", 2);
69
+ customElements.define("qti-lookup-outcome-value", QtiLookupOutcomeValue);
70
+
71
+ // ../qti-processing/src/components/qti-response-condition/qti-response-condition.ts
72
+ var QtiResponseCondition = class extends QtiRule {
73
+ render() {
74
+ return x`<slot></slot>`;
75
+ }
76
+ process() {
77
+ const branches = [...this.children];
78
+ for (let i2 = 0; i2 < branches.length; i2++) {
79
+ const branch = branches[i2];
80
+ if (branch.calculate()) {
81
+ branch.process();
82
+ return;
83
+ }
84
+ }
85
+ }
86
+ };
87
+ customElements.define("qti-response-condition", QtiResponseCondition);
88
+
89
+ // ../qti-processing/src/components/qti-set-outcome-value/qti-set-outcome-value.ts
90
+ var QtiSetOutcomeValue = class extends QtiRule {
91
+ /**
92
+ * Processes the QTI rule and dispatches a custom event with the computed outcome value.
93
+ */
94
+ process() {
95
+ const outcomeIdentifier = this.getAttribute("identifier");
96
+ if (!outcomeIdentifier) {
97
+ console.warn('QtiSetOutcomeValue: Missing "identifier" attribute.');
98
+ return;
99
+ }
100
+ const expression = this.firstElementChild;
101
+ if (!expression) {
102
+ console.warn("QtiSetOutcomeValue: No expression found.");
103
+ return;
104
+ }
105
+ const rule = new QtiSetOutcomeValueRule(expression);
106
+ const value = rule.process();
107
+ this.dispatchEvent(
108
+ new CustomEvent("qti-set-outcome-value", {
109
+ bubbles: true,
110
+ composed: true,
111
+ detail: {
112
+ outcomeIdentifier,
113
+ value: this.formatValue(value)
114
+ }
115
+ })
116
+ );
117
+ }
118
+ /**
119
+ * Formats the computed value before dispatching.
120
+ * Ensures numbers are converted to a universal format.
121
+ */
122
+ formatValue(value) {
123
+ if (Array.isArray(value)) {
124
+ return value.map(convertNumberToUniversalFormat);
125
+ }
126
+ return value !== null ? convertNumberToUniversalFormat(value) : null;
127
+ }
128
+ };
129
+ var QtiSetOutcomeValueRule = class {
130
+ constructor(expression) {
131
+ this.expression = expression;
132
+ }
133
+ /**
134
+ * Evaluates the expression and returns its value.
135
+ */
136
+ process() {
137
+ const value = this.expression.calculate() ?? null;
138
+ if (value === null) {
139
+ console.warn("QtiSetOutcomeValueRule: Evaluated value is null.");
140
+ }
141
+ return Array.isArray(value) ? value.map((v) => v.value ? v.value : v) : value;
142
+ }
143
+ };
144
+ customElements.define("qti-set-outcome-value", QtiSetOutcomeValue);
145
+
146
+ // ../qti-processing/src/components/qti-response-else/qti-response-else.ts
147
+ var QtiResponseElse = class extends i {
148
+ render() {
149
+ return x`<slot></slot>`;
150
+ }
151
+ calculate() {
152
+ return true;
153
+ }
154
+ getSubRules() {
155
+ return [...this.children];
156
+ }
157
+ process() {
158
+ const subRules = this.getSubRules();
159
+ for (let i2 = 0; i2 < subRules.length; i2++) {
160
+ const subRule = subRules[i2];
161
+ subRule.process();
162
+ }
163
+ }
164
+ };
165
+ customElements.define("qti-response-else", QtiResponseElse);
166
+
167
+ // ../qti-processing/src/components/qti-response-if/qti-response-if.ts
168
+ var QtiResponseIf = class extends QtiResponseElse {
169
+ calculate() {
170
+ const expression = this.firstElementChild;
171
+ const result = expression.calculate();
172
+ return result;
173
+ }
174
+ getSubRules() {
175
+ const result = [];
176
+ for (let i2 = 1; i2 < this.children.length; i2++) {
177
+ result.push(this.children[i2]);
178
+ }
179
+ return result;
180
+ }
181
+ };
182
+ customElements.define("qti-response-if", QtiResponseIf);
183
+
184
+ // ../qti-processing/src/components/qti-response-else-if/qti-response-else-if.ts
185
+ var QtiResponseElseIf = class extends QtiResponseIf {
186
+ render() {
187
+ return x`${super.render()}`;
188
+ }
189
+ };
190
+ customElements.define("qti-response-else-if", QtiResponseElseIf);
191
+
192
+ // ../qti-processing/src/components/qti-and/qti-and.ts
193
+ var QtiAnd = class extends qtiAndMixin(QtiConditionExpression) {
194
+ calculate() {
195
+ return this.calculateChildren(Array.from(this.children));
196
+ }
197
+ };
198
+ QtiAnd = __decorateClass([
199
+ t("qti-and")
200
+ ], QtiAnd);
201
+ function qtiAndMixin(Base) {
202
+ return class MockQtiAnd extends Base {
203
+ calculateChildren(children) {
204
+ const values = children.map((c2) => {
205
+ const condition = c2;
206
+ if (!condition.calculate) {
207
+ console.error("Element doesn't implement QtiConditionExpression");
208
+ return null;
209
+ }
210
+ const value = condition.calculate();
211
+ let val = false;
212
+ if (typeof value === "string") {
213
+ if (value === "true") {
214
+ val = true;
215
+ } else if (value === "false") {
216
+ val = false;
217
+ } else {
218
+ console.error("unexpected val in qti-or, expected boolean");
219
+ return null;
220
+ }
221
+ } else {
222
+ if (typeof value === "boolean") {
223
+ val = value;
224
+ }
225
+ }
226
+ return val;
227
+ });
228
+ return values.every((e) => {
229
+ return typeof e === "boolean" && e;
230
+ });
231
+ }
232
+ };
233
+ }
234
+
235
+ // ../qti-processing/src/components/qti-basevalue/qti-basevalue.ts
236
+ var QtiBaseValue = class extends QtiExpression {
237
+ constructor() {
238
+ super(...arguments);
239
+ this.baseType = "string";
240
+ }
241
+ getResult() {
242
+ const value = this.textContent.trim();
243
+ return value;
244
+ }
245
+ };
246
+ __decorateClass([
247
+ n({ type: String, attribute: "base-type" })
248
+ ], QtiBaseValue.prototype, "baseType", 2);
249
+ customElements.define("qti-base-value", QtiBaseValue);
250
+
251
+ // ../qti-processing/src/components/qti-container-size/qti-container-size.ts
252
+ var QtiContainerSize = class extends QtiExpression {
253
+ getResult() {
254
+ if (this.children?.length !== 1) {
255
+ console.error("qti-container-size must have exactly one child expression");
256
+ return 0;
257
+ }
258
+ const variables = this.getVariables();
259
+ if (!variables || variables?.length === 0) {
260
+ return 0;
261
+ }
262
+ const variable = variables[0];
263
+ if (variable.value === null || variable.value === void 0) {
264
+ return 0;
265
+ }
266
+ if (variable.cardinality !== "multiple" && variable.cardinality !== "ordered") {
267
+ console.error("qti-container-size requires multiple or ordered cardinality");
268
+ return 0;
269
+ }
270
+ if (!Array.isArray(variable.value)) {
271
+ console.error("qti-container-size: expected array value for multiple/ordered cardinality");
272
+ return 0;
273
+ }
274
+ return variable.value.length;
275
+ }
276
+ };
277
+ customElements.define("qti-container-size", QtiContainerSize);
278
+
279
+ // ../qti-processing/src/components/qti-contains/qti-contains.ts
280
+ var QtiContains = class extends QtiConditionExpression {
281
+ getResult() {
282
+ const values = this.getVariables();
283
+ if (this.children.length === 2) {
284
+ const value1 = values[0];
285
+ const value2 = values[1];
286
+ if (value1.baseType === "directedPair" && value2.baseType === "directedPair" && value1.cardinality === "multiple") {
287
+ const projection1 = value1.value;
288
+ const projection2 = value2.value;
289
+ const enumerable = projection1.filter((x2) => projection2.includes(x2));
290
+ const result = enumerable.length > 0;
291
+ return result;
292
+ } else if (value1.baseType === "directedPair" && value2.baseType === "directedPair" && value1.cardinality === "single") {
293
+ const projection1 = value1.value;
294
+ const projection2 = value2.value;
295
+ return projection2.includes(projection1);
296
+ } else {
297
+ console.error(
298
+ "unsupported baseType or cardinality in qti contains, only baseType: directedPair and cardinality: multiple is supported"
299
+ );
300
+ }
301
+ } else {
302
+ console.error("unexpected number of children in qti contains");
303
+ }
304
+ return false;
305
+ }
306
+ };
307
+ customElements.define("qti-contains", QtiContains);
308
+
309
+ // ../qti-processing/src/components/qti-correct/qti-correct.ts
310
+ var QtiCorrect = class extends QtiExpression {
311
+ get interpretation() {
312
+ return this.getAttribute("interpretation") || "";
313
+ }
314
+ getResult() {
315
+ const identifier = this.getAttribute("identifier") || "";
316
+ const responseVariable = this.context.variables.find((v) => v.identifier === identifier) || null;
317
+ if (responseVariable.cardinality !== "single") {
318
+ return responseVariable.correctResponse.length > 0 ? responseVariable.correctResponse[0] : "";
319
+ } else {
320
+ return responseVariable.correctResponse;
321
+ }
322
+ }
323
+ };
324
+ customElements.define("qti-correct", QtiCorrect);
325
+
326
+ // ../qti-processing/src/components/qti-default/qti-default.ts
327
+ var QtiDefault = class extends QtiExpression {
328
+ constructor() {
329
+ super(...arguments);
330
+ this.identifier = "";
331
+ }
332
+ getResult() {
333
+ if (!this.identifier) {
334
+ console.error("qti-default requires an identifier attribute");
335
+ return null;
336
+ }
337
+ const parts = this.identifier.split(".");
338
+ let itemId = null;
339
+ let variableId;
340
+ if (parts.length === 2) {
341
+ itemId = parts[0];
342
+ variableId = parts[1];
343
+ } else if (parts.length === 1) {
344
+ variableId = parts[0];
345
+ } else {
346
+ console.error("qti-default: invalid identifier format");
347
+ return null;
348
+ }
349
+ if (itemId) {
350
+ const itemContext2 = this._testContext.items.find((item) => item.identifier === itemId);
351
+ console.debug(`itemContext: ${JSON.stringify(itemContext2)}`);
352
+ if (!this._testContext || !itemContext2) {
353
+ console.warn(`qti-default: item "${itemId}" not found in test context`);
354
+ return null;
355
+ }
356
+ const variable2 = this._testContext.items.find((item) => item.identifier === itemId)?.variables.find((v) => v.identifier === variableId);
357
+ if (!variable2) {
358
+ console.warn(`qti-default: variable "${variableId}" not found in item "${itemId}"`);
359
+ return null;
360
+ }
361
+ return variable2.defaultValue || null;
362
+ }
363
+ if (!this.context?.variables) {
364
+ console.warn("qti-default: no variables found in item context");
365
+ return null;
366
+ }
367
+ const variable = this.context.variables.find((v) => v.identifier === variableId);
368
+ if (!variable) {
369
+ console.warn(`qti-default: variable "${variableId}" not found in item context`);
370
+ return null;
371
+ }
372
+ return variable.defaultValue || null;
373
+ }
374
+ };
375
+ __decorateClass([
376
+ n({ type: String })
377
+ ], QtiDefault.prototype, "identifier", 2);
378
+ __decorateClass([
379
+ c({ context: itemContext, subscribe: true }),
380
+ r()
381
+ ], QtiDefault.prototype, "context", 2);
382
+ __decorateClass([
383
+ r(),
384
+ c({ context: testContext, subscribe: true })
385
+ ], QtiDefault.prototype, "_testContext", 2);
386
+ customElements.define("qti-default", QtiDefault);
387
+
388
+ // ../qti-processing/src/components/qti-equal-rounded/qti-equal-rounded.ts
389
+ var QtiEqualRounded = class extends QtiExpression {
390
+ constructor() {
391
+ super(...arguments);
392
+ this.roundingMode = "significantFigures";
393
+ }
394
+ get figures() {
395
+ const attr = this.getAttribute("figures");
396
+ if (!attr) {
397
+ console.error("figures attribute is missing");
398
+ return null;
399
+ }
400
+ const figures = parseInt(this.getAttribute("figures") || "0");
401
+ if (isNaN(figures)) {
402
+ console.error("figures attribute is not a number");
403
+ return null;
404
+ }
405
+ if (figures < 0) {
406
+ console.error("figures attribute is negative");
407
+ return null;
408
+ }
409
+ if (figures < 1 && this.roundingMode === "significantFigures") {
410
+ console.error("figures cannot be smaller than 1 for RoundingMode significantFigures");
411
+ return null;
412
+ }
413
+ return figures;
414
+ }
415
+ getResult() {
416
+ if (this.children.length === 2) {
417
+ const values = this.getVariables();
418
+ const value1 = values[0];
419
+ const value2 = values[1];
420
+ if (this.roundingMode === null) {
421
+ return null;
422
+ }
423
+ if (value1.cardinality !== "single" || value2.cardinality !== "single" || Array.isArray(value1.value) || Array.isArray(value2.value)) {
424
+ console.error("unexpected cardinality in qti equal");
425
+ return false;
426
+ }
427
+ switch (values[0].baseType) {
428
+ case "integer":
429
+ case "float": {
430
+ const float1 = parseFloat(value1.value);
431
+ const float2 = parseFloat(value2.value);
432
+ if (!isNaN(float1) && !isNaN(float2)) {
433
+ if (this.roundingMode === "significantFigures") {
434
+ return float1.toPrecision(this.figures) === float2.toPrecision(this.figures);
435
+ } else {
436
+ return Math.round(float1 * Math.pow(10, this.figures)) / Math.pow(10, this.figures) === Math.round(float2 * Math.pow(10, this.figures)) / Math.pow(10, this.figures);
437
+ }
438
+ } else {
439
+ console.error(`value cannot be casted to numeric value in equalRounded operator: ${float1}, ${float2}`);
440
+ }
441
+ break;
442
+ }
443
+ default: {
444
+ console.error(`values other than float and int cannot be used in equalRounded operator.`);
445
+ break;
446
+ }
447
+ }
448
+ return false;
449
+ }
450
+ console.error("unexpected number of children in qti-equal-rounded");
451
+ return null;
452
+ }
453
+ };
454
+ __decorateClass([
455
+ n({ type: String })
456
+ ], QtiEqualRounded.prototype, "roundingMode", 2);
457
+ customElements.define("qti-equal-rounded", QtiEqualRounded);
458
+
459
+ // ../qti-processing/src/components/qti-round/qti-round.ts
460
+ var QtiRound = class extends QtiExpression {
461
+ getResult() {
462
+ if (this.children.length !== 1) {
463
+ console.error("qti-round must have exactly one child expression");
464
+ return null;
465
+ }
466
+ const variables = this.getVariables();
467
+ if (!variables || variables.length === 0) {
468
+ return null;
469
+ }
470
+ const variable = variables[0];
471
+ if (variable.cardinality !== "single") {
472
+ console.error("qti-round requires single cardinality");
473
+ return null;
474
+ }
475
+ if (Array.isArray(variable.value)) {
476
+ console.error("qti-round unexpected array value for single cardinality");
477
+ return null;
478
+ }
479
+ if (variable.value === null || variable.value === void 0) {
480
+ return null;
481
+ }
482
+ if (variable.baseType !== "integer" && variable.baseType !== "float") {
483
+ console.error("qti-round requires numerical base-type (integer or float)");
484
+ return null;
485
+ }
486
+ const numericValue = parseFloat(variable.value);
487
+ if (isNaN(numericValue)) {
488
+ console.warn("qti-round: NaN input results in NULL");
489
+ return null;
490
+ }
491
+ if (!isFinite(numericValue)) {
492
+ if (numericValue === Infinity) {
493
+ return Infinity;
494
+ }
495
+ if (numericValue === -Infinity) {
496
+ return -Infinity;
497
+ }
498
+ return null;
499
+ }
500
+ return Math.floor(numericValue + 0.5);
501
+ }
502
+ };
503
+ customElements.define("qti-round", QtiRound);
504
+
505
+ // ../qti-processing/src/components/qti-round-to/qti-round-to.ts
506
+ var QtiRoundTo = class extends QtiExpression {
507
+ constructor() {
508
+ super(...arguments);
509
+ this.roundingMode = "significantFigures";
510
+ this.figures = 3;
511
+ }
512
+ getResult() {
513
+ if (this.children.length !== 1) {
514
+ console.error("qti-round-to must have exactly one child expression");
515
+ return null;
516
+ }
517
+ const variables = this.getVariables();
518
+ if (!variables || variables.length === 0) {
519
+ return null;
520
+ }
521
+ const variable = variables[0];
522
+ if (variable.cardinality !== "single") {
523
+ console.error("qti-round-to requires single cardinality");
524
+ return null;
525
+ }
526
+ if (Array.isArray(variable.value)) {
527
+ console.error("qti-round-to unexpected array value for single cardinality");
528
+ return null;
529
+ }
530
+ if (variable.value === null || variable.value === void 0) {
531
+ return null;
532
+ }
533
+ if (variable.baseType !== "integer" && variable.baseType !== "float") {
534
+ console.error("qti-round-to requires numerical base-type");
535
+ return null;
536
+ }
537
+ const numericValue = parseFloat(variable.value);
538
+ if (isNaN(numericValue)) {
539
+ return null;
540
+ }
541
+ if (!isFinite(numericValue)) {
542
+ if (numericValue === Infinity) {
543
+ return Infinity;
544
+ }
545
+ if (numericValue === -Infinity) {
546
+ return -Infinity;
547
+ }
548
+ return null;
549
+ }
550
+ if (this.figures < 0) {
551
+ console.error("qti-round-to: figures must be non-negative");
552
+ return null;
553
+ }
554
+ if (this.roundingMode === "significantFigures" && this.figures < 1) {
555
+ console.error("qti-round-to: figures must be at least 1 for significantFigures mode");
556
+ return null;
557
+ }
558
+ if (this.roundingMode === "decimalPlaces") {
559
+ return this._roundToDecimalPlaces(numericValue, this.figures);
560
+ } else {
561
+ return this._roundToSignificantFigures(numericValue, this.figures);
562
+ }
563
+ }
564
+ /**
565
+ * Round to specified number of decimal places
566
+ */
567
+ _roundToDecimalPlaces(value, decimalPlaces) {
568
+ if (value === 0) {
569
+ return 0;
570
+ }
571
+ const multiplier = Math.pow(10, decimalPlaces);
572
+ return Math.round(value * multiplier) / multiplier;
573
+ }
574
+ /**
575
+ * Round to specified number of significant figures
576
+ */
577
+ _roundToSignificantFigures(value, significantFigures) {
578
+ if (value === 0) {
579
+ return 0;
580
+ }
581
+ const magnitude = Math.floor(Math.log10(Math.abs(value)));
582
+ const multiplier = Math.pow(10, significantFigures - magnitude - 1);
583
+ return Math.round(value * multiplier) / multiplier;
584
+ }
585
+ };
586
+ __decorateClass([
587
+ n({ type: String, attribute: "rounding-mode" })
588
+ ], QtiRoundTo.prototype, "roundingMode", 2);
589
+ __decorateClass([
590
+ n({ type: Number })
591
+ ], QtiRoundTo.prototype, "figures", 2);
592
+ customElements.define("qti-round-to", QtiRoundTo);
593
+
594
+ // ../qti-processing/src/components/qti-equal/qti-equal.ts
595
+ var QtiEqual = class extends QtiExpression {
596
+ constructor() {
597
+ super(...arguments);
598
+ this.toleranceMode = "exact";
599
+ }
600
+ getResult() {
601
+ if (this.children.length === 2) {
602
+ const values = this.getVariables();
603
+ const value1 = values[0];
604
+ const value2 = values[1];
605
+ if (this.toleranceMode !== "exact") {
606
+ console.error("toleranceMode is not supported yet");
607
+ return false;
608
+ }
609
+ if (value1.cardinality !== "single" || value2.cardinality !== "single" || Array.isArray(value1.value) || Array.isArray(value2.value)) {
610
+ console.error("unexpected cardinality in qti equal");
611
+ return false;
612
+ }
613
+ return ScoringHelper.compareSingleValues(value1.value, value2.value, value1.baseType);
614
+ }
615
+ console.error("unexpected number of children in qti-equal");
616
+ return null;
617
+ }
618
+ };
619
+ __decorateClass([
620
+ n({ type: String })
621
+ ], QtiEqual.prototype, "toleranceMode", 2);
622
+ customElements.define("qti-equal", QtiEqual);
623
+
624
+ // ../qti-processing/src/components/qti-gcd/qti.gcd.ts
625
+ var QtiGcd = class extends QtiExpression {
626
+ getResult() {
627
+ if (this.children.length === 0) {
628
+ console.error("qti-gcd must have at least one child expression");
629
+ return null;
630
+ }
631
+ const variables = this.getVariables();
632
+ if (!variables || variables.length === 0) {
633
+ return null;
634
+ }
635
+ const allValues = [];
636
+ for (const variable of variables) {
637
+ if (variable.baseType !== "integer") {
638
+ console.error("qti-gcd requires integer base-type");
639
+ return null;
640
+ }
641
+ if (variable.value === null || variable.value === void 0) {
642
+ return null;
643
+ }
644
+ if (variable.cardinality === "single") {
645
+ if (Array.isArray(variable.value)) {
646
+ console.error("qti-gcd unexpected array value for single cardinality");
647
+ return null;
648
+ }
649
+ const numValue = parseInt(variable.value, 10);
650
+ if (isNaN(numValue)) {
651
+ console.error("qti-gcd non-numerical value");
652
+ return null;
653
+ }
654
+ allValues.push(numValue);
655
+ } else if (variable.cardinality === "multiple" || variable.cardinality === "ordered") {
656
+ if (!Array.isArray(variable.value)) {
657
+ console.error("qti-gcd expected array value for multiple/ordered cardinality");
658
+ return null;
659
+ }
660
+ for (const value of variable.value) {
661
+ if (value === null || value === void 0) {
662
+ return null;
663
+ }
664
+ const numValue = parseInt(value, 10);
665
+ if (isNaN(numValue)) {
666
+ console.error("qti-gcd non-numerical value");
667
+ return null;
668
+ }
669
+ allValues.push(numValue);
670
+ }
671
+ } else {
672
+ console.error("qti-gcd unsupported cardinality");
673
+ return null;
674
+ }
675
+ }
676
+ if (allValues.length === 0) {
677
+ return null;
678
+ }
679
+ return this._calculateGcd(allValues);
680
+ }
681
+ /**
682
+ * Calculate the greatest common divisor of an array of integers
683
+ */
684
+ _calculateGcd(values) {
685
+ if (values.length === 0) {
686
+ return 0;
687
+ }
688
+ if (values.length === 1) {
689
+ return Math.abs(values[0]);
690
+ }
691
+ let result = Math.abs(values[0]);
692
+ for (let i2 = 1; i2 < values.length; i2++) {
693
+ result = this._gcdTwoNumbers(result, Math.abs(values[i2]));
694
+ if (result === 1) {
695
+ break;
696
+ }
697
+ }
698
+ return result;
699
+ }
700
+ /**
701
+ * Calculate GCD of two numbers using Euclidean algorithm
702
+ */
703
+ _gcdTwoNumbers(a, b) {
704
+ if (a === 0 && b === 0) {
705
+ return 0;
706
+ }
707
+ if (a === 0) {
708
+ return b;
709
+ }
710
+ if (b === 0) {
711
+ return a;
712
+ }
713
+ while (b !== 0) {
714
+ const temp = b;
715
+ b = a % b;
716
+ a = temp;
717
+ }
718
+ return a;
719
+ }
720
+ };
721
+ customElements.define("qti-gcd", QtiGcd);
722
+
723
+ // ../qti-processing/src/components/qti-gt/qti-gt.ts
724
+ var QtiGt = class extends QtiExpression {
725
+ getResult() {
726
+ if (this.children.length === 2) {
727
+ const values = this.getVariables();
728
+ const value1 = values[0];
729
+ const value2 = values[1];
730
+ if ((value1.baseType === "integer" || value1.baseType === "float") && (value2.baseType === "integer" || value2.baseType === "float")) {
731
+ return +value1.value > +value2.value;
732
+ } else {
733
+ console.error("unexpected baseType or cardinality in qti gt");
734
+ }
735
+ }
736
+ console.error("unexpected number of children in qt");
737
+ return null;
738
+ }
739
+ };
740
+ customElements.define("qti-gt", QtiGt);
741
+
742
+ // ../qti-processing/src/components/qti-gte/qti-gte.ts
743
+ var QtiGte = class extends QtiConditionExpression {
744
+ getResult() {
745
+ if (this.children.length === 2) {
746
+ const values = this.getVariables();
747
+ const value1 = values[0];
748
+ const value2 = values[1];
749
+ if ((value1.baseType === "integer" || value1.baseType === "float") && (value2.baseType === "integer" || value2.baseType === "float")) {
750
+ return +value1.value >= +value2.value;
751
+ } else {
752
+ console.error("unexpected baseType or cardinality in qti gte");
753
+ return null;
754
+ }
755
+ }
756
+ console.log("unexpected number of children in qte");
757
+ return null;
758
+ }
759
+ };
760
+ customElements.define("qti-gte", QtiGte);
761
+
762
+ // ../qti-processing/src/components/qti-null/qti-null.ts
763
+ var QtiNull = class extends QtiExpression {
764
+ getResult() {
765
+ return null;
766
+ }
767
+ };
768
+ customElements.define("qti-null", QtiNull);
769
+
770
+ // ../qti-processing/src/components/qti-is-null/qti-is-null.ts
771
+ var QtiIsNull = class extends QtiExpression {
772
+ getResult() {
773
+ if (this.children.length === 1) {
774
+ const variables = this.getVariables();
775
+ if (!variables) {
776
+ return true;
777
+ }
778
+ const value = variables[0].value;
779
+ return value == null || value == void 0 || value === "";
780
+ }
781
+ console.error("unexpected number of children in qti Null");
782
+ return null;
783
+ }
784
+ };
785
+ customElements.define("qti-is-null", QtiIsNull);
786
+
787
+ // ../qti-processing/src/components/qti-field-value/qti-field-value.ts
788
+ var QtiFieldValue = class extends QtiExpression {
789
+ getResult() {
790
+ const fieldIdentifier = this.getAttribute("field-identifier");
791
+ if (!fieldIdentifier) {
792
+ throw new Error("field-identifier attribute is required");
793
+ }
794
+ const childElements = Array.from(this.children);
795
+ if (childElements.length !== 1) {
796
+ throw new Error("qti-field-value must have exactly one child expression");
797
+ }
798
+ const variable = this.getVariables()[0];
799
+ if (variable.baseType !== "record" || variable.value === null) {
800
+ throw new Error("qti-field-value child expression must return a record");
801
+ }
802
+ const fieldValue = variable.value[fieldIdentifier];
803
+ if (fieldValue === void 0) {
804
+ throw new Error(`Field "${fieldIdentifier}" not found in record`);
805
+ }
806
+ return fieldValue;
807
+ }
808
+ };
809
+ customElements.define("qti-field-value", QtiFieldValue);
810
+
811
+ // ../qti-processing/src/components/qti-lt/qti-lt.ts
812
+ var QtiLt = class extends QtiExpression {
813
+ getResult() {
814
+ if (this.children.length === 2) {
815
+ const values = this.getVariables();
816
+ const value1 = values[0];
817
+ const value2 = values[1];
818
+ if ((value1.baseType === "integer" || value1.baseType === "float") && (value2.baseType === "integer" || value2.baseType === "float")) {
819
+ return +value1.value < +value2.value;
820
+ } else {
821
+ console.error("unexpected baseType or cardinality in qti lt");
822
+ }
823
+ }
824
+ console.error("unexpected number of children in lt");
825
+ return null;
826
+ }
827
+ };
828
+ customElements.define("qti-lt", QtiLt);
829
+
830
+ // ../qti-processing/src/components/qti-lte/qti-lte.ts
831
+ var QtiLte = class extends QtiConditionExpression {
832
+ getResult() {
833
+ if (this.children.length === 2) {
834
+ const values = this.getVariables();
835
+ const value1 = values[0];
836
+ const value2 = values[1];
837
+ if ((value1.baseType === "integer" || value1.baseType === "float") && (value2.baseType === "integer" || value2.baseType === "float")) {
838
+ return +value1.value <= +value2.value;
839
+ } else {
840
+ console.error("unexpected baseType or cardinality in qti lte");
841
+ return null;
842
+ }
843
+ }
844
+ console.log("unexpected number of children in lte");
845
+ return null;
846
+ }
847
+ };
848
+ customElements.define("qti-lte", QtiLte);
849
+
850
+ // ../qti-processing/src/components/qti-map-response/qti-map-response.ts
851
+ var QtiMapResponse = class extends QtiExpression {
852
+ getResult() {
853
+ const response = this.context.variables.find((r2) => r2.identifier === this.identifier);
854
+ if (!response || !response.mapping) {
855
+ console.error(`Response ${this.identifier} can not be found`);
856
+ return null;
857
+ }
858
+ const mapping = response.mapping;
859
+ const candidateResponses = !Array.isArray(response.value) ? [response.value] : response.value;
860
+ let result = 0;
861
+ for (const candidateResponse of candidateResponses) {
862
+ const mappedValues = mapping.mapEntries.filter((entry) => {
863
+ if (response.baseType === "string" && !entry.caseSensitive) {
864
+ return ScoringHelper.compareSingleValues(
865
+ entry.mapKey.toLowerCase(),
866
+ candidateResponse.toLowerCase(),
867
+ response.baseType
868
+ );
869
+ } else {
870
+ return ScoringHelper.compareSingleValues(entry.mapKey, candidateResponse, response.baseType);
871
+ }
872
+ });
873
+ const mappedValue = mappedValues.reduce(
874
+ (prev, current) => prev.mappedValue > current.mappedValue ? prev : current,
875
+ mappedValues.length > 0 ? mappedValues[0] : { mapKey: null, mappedValue: null }
876
+ // Use the first element instead of a manual initial value
877
+ );
878
+ if (!(mappedValue === null || mappedValue.mappedValue == void 0)) {
879
+ result += mappedValue.mappedValue;
880
+ } else {
881
+ result += mapping.defaultValue;
882
+ }
883
+ }
884
+ if (mapping?.lowerBound !== null && mapping?.lowerBound !== void 0) {
885
+ result = Math.max(mapping.lowerBound, result);
886
+ }
887
+ if (mapping?.upperBound !== null && mapping?.upperBound !== void 0) {
888
+ result = Math.min(mapping.upperBound, result);
889
+ }
890
+ return result;
891
+ }
892
+ };
893
+ __decorateClass([
894
+ n({ type: String })
895
+ ], QtiMapResponse.prototype, "identifier", 2);
896
+ customElements.define("qti-map-response", QtiMapResponse);
897
+
898
+ // ../qti-processing/src/components/qti-map-response-point/qti-map-response-point.ts
899
+ var QtiMapResponsePoint = class extends QtiExpression {
900
+ getResult() {
901
+ const response = this.context.variables.find((r2) => r2.identifier === this.identifier);
902
+ if (!response) {
903
+ console.warn(`Response ${this.identifier} cannot be found`);
904
+ return null;
905
+ }
906
+ const areaMapping = response.areaMapping;
907
+ if (!areaMapping) {
908
+ console.warn(`Area mapping not found for response ${this.identifier}`);
909
+ return null;
910
+ }
911
+ const candidateResponses = !Array.isArray(response.value) ? [response.value] : response.value;
912
+ if (!candidateResponses || candidateResponses.length === 0) {
913
+ console.warn(`No candidate responses for response ${this.identifier}`);
914
+ return null;
915
+ }
916
+ let result = 0;
917
+ const mappedAreas = /* @__PURE__ */ new Set();
918
+ for (const candidateResponse of candidateResponses) {
919
+ for (const entry of areaMapping.areaMapEntries) {
920
+ if (mappedAreas.has(entry.coords)) {
921
+ continue;
922
+ }
923
+ const isPointInArea = ScoringHelper.isPointInArea(
924
+ candidateResponse,
925
+ `${entry.shape},${entry.coords}`,
926
+ response.baseType
927
+ );
928
+ if (isPointInArea) {
929
+ result += entry.mappedValue ?? 0;
930
+ mappedAreas.add(entry.coords);
931
+ }
932
+ }
933
+ }
934
+ if (mappedAreas.size < candidateResponses.length) {
935
+ result += areaMapping.defaultValue;
936
+ }
937
+ if (areaMapping.lowerBound != null) {
938
+ result = Math.max(areaMapping.lowerBound, result);
939
+ }
940
+ if (areaMapping.upperBound != null) {
941
+ result = Math.min(areaMapping.upperBound, result);
942
+ }
943
+ return result;
944
+ }
945
+ };
946
+ __decorateClass([
947
+ n({ type: String })
948
+ ], QtiMapResponsePoint.prototype, "identifier", 2);
949
+ customElements.define("qti-map-response-point", QtiMapResponsePoint);
950
+
951
+ // ../qti-processing/src/components/qti-math-operator/qti-math-operator.ts
952
+ var QtiMathOperator = class extends QtiExpression {
953
+ constructor() {
954
+ super(...arguments);
955
+ this.name = "";
956
+ }
957
+ getResult() {
958
+ if (!this.name) {
959
+ console.error("qti-math-operator requires a name attribute");
960
+ return null;
961
+ }
962
+ const variables = this.getVariables();
963
+ if (!variables || variables.length === 0) {
964
+ return null;
965
+ }
966
+ const values = [];
967
+ for (const variable of variables) {
968
+ if (variable.cardinality !== "single") {
969
+ console.error("qti-math-operator requires single cardinality");
970
+ return null;
971
+ }
972
+ if (Array.isArray(variable.value)) {
973
+ console.error("qti-math-operator unexpected array value for single cardinality");
974
+ return null;
975
+ }
976
+ if (variable.value === null || variable.value === void 0) {
977
+ return null;
978
+ }
979
+ if (variable.baseType !== "integer" && variable.baseType !== "float") {
980
+ console.error("qti-math-operator requires numerical base-type");
981
+ return null;
982
+ }
983
+ const numValue = parseFloat(variable.value);
984
+ if (isNaN(numValue)) {
985
+ console.error("qti-math-operator non-numerical value");
986
+ return null;
987
+ }
988
+ values.push(numValue);
989
+ }
990
+ return this._performOperation(this.name, values);
991
+ }
992
+ _performOperation(operation, values) {
993
+ try {
994
+ switch (operation.toLowerCase()) {
995
+ // Single argument functions
996
+ case "sin":
997
+ if (values.length !== 1) return null;
998
+ return Math.sin(values[0]);
999
+ case "cos":
1000
+ if (values.length !== 1) return null;
1001
+ return Math.cos(values[0]);
1002
+ case "tan":
1003
+ if (values.length !== 1) return null;
1004
+ return Math.tan(values[0]);
1005
+ case "asin":
1006
+ if (values.length !== 1) return null;
1007
+ if (values[0] < -1 || values[0] > 1) return null;
1008
+ return Math.asin(values[0]);
1009
+ case "acos":
1010
+ if (values.length !== 1) return null;
1011
+ if (values[0] < -1 || values[0] > 1) return null;
1012
+ return Math.acos(values[0]);
1013
+ case "atan":
1014
+ if (values.length !== 1) return null;
1015
+ return Math.atan(values[0]);
1016
+ case "sinh":
1017
+ if (values.length !== 1) return null;
1018
+ return Math.sinh(values[0]);
1019
+ case "cosh":
1020
+ if (values.length !== 1) return null;
1021
+ return Math.cosh(values[0]);
1022
+ case "tanh":
1023
+ if (values.length !== 1) return null;
1024
+ return Math.tanh(values[0]);
1025
+ case "log":
1026
+ if (values.length !== 1) return null;
1027
+ if (values[0] <= 0) return null;
1028
+ return Math.log(values[0]);
1029
+ case "ln":
1030
+ if (values.length !== 1) return null;
1031
+ if (values[0] <= 0) return null;
1032
+ return Math.log(values[0]);
1033
+ case "log10":
1034
+ if (values.length !== 1) return null;
1035
+ if (values[0] <= 0) return null;
1036
+ return Math.log10(values[0]);
1037
+ case "exp":
1038
+ if (values.length !== 1) return null;
1039
+ return Math.exp(values[0]);
1040
+ case "abs":
1041
+ if (values.length !== 1) return null;
1042
+ return Math.abs(values[0]);
1043
+ case "sqrt":
1044
+ if (values.length !== 1) return null;
1045
+ if (values[0] < 0) return null;
1046
+ return Math.sqrt(values[0]);
1047
+ case "signum":
1048
+ if (values.length !== 1) return null;
1049
+ return Math.sign(values[0]);
1050
+ // Returns -1, 0, or 1 (integer)
1051
+ case "floor":
1052
+ if (values.length !== 1) return null;
1053
+ return Math.floor(values[0]);
1054
+ // Returns integer
1055
+ case "ceil":
1056
+ if (values.length !== 1) return null;
1057
+ return Math.ceil(values[0]);
1058
+ // Returns integer
1059
+ case "round":
1060
+ if (values.length !== 1) return null;
1061
+ return Math.round(values[0]);
1062
+ // Two argument functions
1063
+ case "atan2":
1064
+ if (values.length !== 2) return null;
1065
+ return Math.atan2(values[0], values[1]);
1066
+ case "pow": {
1067
+ if (values.length !== 2) {
1068
+ return null;
1069
+ }
1070
+ const base = values[0];
1071
+ const exponent = values[1];
1072
+ if (base === 0 && exponent <= 0) return null;
1073
+ if (base < 0 && !Number.isInteger(exponent)) return null;
1074
+ return Math.pow(base, exponent);
1075
+ }
1076
+ case "log_base": {
1077
+ if (values.length !== 2) {
1078
+ return null;
1079
+ }
1080
+ const value = values[0];
1081
+ const base = values[1];
1082
+ if (value <= 0 || base <= 0 || base === 1) return null;
1083
+ return Math.log(value) / Math.log(base);
1084
+ }
1085
+ case "mod":
1086
+ if (values.length !== 2) return null;
1087
+ if (values[1] === 0) return null;
1088
+ return values[0] % values[1];
1089
+ case "max":
1090
+ if (values.length < 1) return null;
1091
+ return Math.max(...values);
1092
+ case "min":
1093
+ if (values.length < 1) return null;
1094
+ return Math.min(...values);
1095
+ default:
1096
+ console.error(`qti-math-operator: unknown operation "${operation}"`);
1097
+ return null;
1098
+ }
1099
+ } catch (error) {
1100
+ console.error(`qti-math-operator: error performing operation "${operation}":`, error);
1101
+ return null;
1102
+ }
1103
+ }
1104
+ };
1105
+ __decorateClass([
1106
+ n({ type: String })
1107
+ ], QtiMathOperator.prototype, "name", 2);
1108
+ customElements.define("qti-math-operator", QtiMathOperator);
1109
+
1110
+ // ../qti-processing/src/components/qti-match/qti-match.ts
1111
+ var QtiMatch = class _QtiMatch extends QtiExpression {
1112
+ //PK : FIXME.
1113
+ // This was a little experiment if we could call the match function as a static function,
1114
+ // This can be used for all kind of things, but now especially for use in
1115
+ // qti-response-condition-script
1116
+ // in which we pass the expressions as pure functions, and hope for the best.
1117
+ // SADLY, the getVariables throws roet in de eten.. weet nog niet precies hoe deze werkt.
1118
+ // Maar ik ga erin duiken.
1119
+ getResult() {
1120
+ if (this.children.length === 2) {
1121
+ const values = this.getVariables();
1122
+ const valueToMap = values[0];
1123
+ const correctValueInfo = values[1];
1124
+ return _QtiMatch.match(valueToMap, correctValueInfo);
1125
+ }
1126
+ console.error("unexpected number of children in match");
1127
+ return null;
1128
+ }
1129
+ static match(valueToMap, correctValueInfo) {
1130
+ if (valueToMap.value === null) return false;
1131
+ switch (correctValueInfo.cardinality) {
1132
+ case "single": {
1133
+ if (Array.isArray(valueToMap.value) || Array.isArray(correctValueInfo.value)) {
1134
+ console.error("unexpected cardinality in qti match");
1135
+ return false;
1136
+ }
1137
+ return ScoringHelper.compareSingleValues(
1138
+ valueToMap.value?.toString(),
1139
+ correctValueInfo.value.toString(),
1140
+ correctValueInfo.baseType
1141
+ );
1142
+ }
1143
+ case "ordered": {
1144
+ if (!Array.isArray(valueToMap.value) || !Array.isArray(correctValueInfo.value)) {
1145
+ console.error("unexpected cardinality in qti match");
1146
+ return false;
1147
+ }
1148
+ if (valueToMap.value.length !== correctValueInfo.value.length) {
1149
+ return false;
1150
+ }
1151
+ for (let i2 = 0; i2 < valueToMap.value.length; i2++) {
1152
+ const result = ScoringHelper.compareSingleValues(
1153
+ correctValueInfo.value[i2],
1154
+ valueToMap.value[i2],
1155
+ correctValueInfo.baseType
1156
+ );
1157
+ if (!result) {
1158
+ return false;
1159
+ }
1160
+ }
1161
+ return true;
1162
+ }
1163
+ case "multiple": {
1164
+ if (!Array.isArray(valueToMap.value) || !Array.isArray(correctValueInfo.value)) {
1165
+ console.error("unexpected cardinality in qti match");
1166
+ return false;
1167
+ }
1168
+ if (valueToMap.value.length !== correctValueInfo.value.length) {
1169
+ return false;
1170
+ }
1171
+ let answerIndex = 0;
1172
+ for (const correctAnswer of correctValueInfo.value) {
1173
+ let matchingValue = null;
1174
+ const arr = [...valueToMap.value];
1175
+ for (const mv of arr) {
1176
+ const result = ScoringHelper.compareSingleValues(correctAnswer, mv, correctValueInfo.baseType);
1177
+ if (result) {
1178
+ matchingValue = mv;
1179
+ break;
1180
+ }
1181
+ }
1182
+ if (matchingValue !== null) {
1183
+ arr.splice(arr.indexOf(matchingValue), 1);
1184
+ } else {
1185
+ return false;
1186
+ }
1187
+ answerIndex++;
1188
+ }
1189
+ return true;
1190
+ }
1191
+ default:
1192
+ console.error("unexpected cardinality in qti match");
1193
+ return false;
1194
+ }
1195
+ }
1196
+ };
1197
+ customElements.define("qti-match", QtiMatch);
1198
+
1199
+ // ../qti-processing/src/components/qti-member/qti-member.ts
1200
+ var QtiMember = class extends QtiExpression {
1201
+ getResult() {
1202
+ const values = this.getVariables();
1203
+ if (!(this.children.length === 2)) {
1204
+ console.warn("The member operator takes two sub-expressions");
1205
+ }
1206
+ const [value1, value2] = values;
1207
+ if (!(value1.baseType === value2.baseType || value1.baseType === "integer" && value2.baseType === "float" || value1.baseType === "float" && value2.baseType === "integer")) {
1208
+ console.warn("Which must both have the same base-type");
1209
+ }
1210
+ if (!(value2.cardinality === "multiple" || value2.cardinality === "ordered")) {
1211
+ console.warn("and the second must be a multiple or ordered container");
1212
+ }
1213
+ if (value1.baseType === "float" || value2.baseType === "float") {
1214
+ console.warn("The member operator should not be used on sub-expressions with a base-type of float");
1215
+ }
1216
+ if (value1.baseType === "duration" || value2.baseType === "duration") {
1217
+ console.warn("It must not be used on sub-expressions with a base-type of duration");
1218
+ }
1219
+ if (value1.value === null || value2.value === null) {
1220
+ return null;
1221
+ }
1222
+ const projection1 = value1.value;
1223
+ const projection2 = value2.value;
1224
+ return projection2.includes(projection1);
1225
+ }
1226
+ };
1227
+ customElements.define("qti-member", QtiMember);
1228
+
1229
+ // ../qti-processing/src/components/qti-multiple/qti-multiple.ts
1230
+ var QtiMultiple = class extends QtiExpression {
1231
+ getResult() {
1232
+ console.debug("qti-multiple getResult called", this.innerHTML);
1233
+ const variables = this.getVariables();
1234
+ if (variables.length === 0) {
1235
+ console.error("unexpected number of children in qti multiple");
1236
+ return null;
1237
+ }
1238
+ for (const variable of variables) {
1239
+ if (variable.cardinality !== "multiple" && variable.cardinality !== "single") {
1240
+ console.error("unexpected cardinality in qti multiple");
1241
+ return [];
1242
+ }
1243
+ }
1244
+ return variables;
1245
+ }
1246
+ };
1247
+ customElements.define("qti-multiple", QtiMultiple);
1248
+
1249
+ // ../qti-processing/src/components/qti-not/qti-not.ts
1250
+ var QtiNot = class extends QtiExpression {
1251
+ render() {
1252
+ return x`${super.render()}`;
1253
+ }
1254
+ getResult() {
1255
+ const expression = this.firstElementChild;
1256
+ const result = expression.calculate();
1257
+ return !result;
1258
+ }
1259
+ };
1260
+ customElements.define("qti-not", QtiNot);
1261
+
1262
+ // ../qti-processing/src/components/qti-or/qti-or.ts
1263
+ var QtiOr = class extends QtiConditionExpression {
1264
+ getResult() {
1265
+ const values = Array.from(this.children).map((c2) => {
1266
+ const condition = c2;
1267
+ if (!condition.calculate) {
1268
+ console.error("Element doesn't implement QtiConditionExpression");
1269
+ return null;
1270
+ }
1271
+ const value = condition.calculate();
1272
+ let val = false;
1273
+ if (typeof value === "string") {
1274
+ if (value === "true") {
1275
+ val = true;
1276
+ } else if (value === "false") {
1277
+ val = false;
1278
+ } else {
1279
+ console.error("unexpected val in qti-or, expected boolean");
1280
+ return null;
1281
+ }
1282
+ } else {
1283
+ if (typeof value === "boolean") {
1284
+ val = value;
1285
+ }
1286
+ }
1287
+ return val;
1288
+ });
1289
+ return values.some((e) => {
1290
+ return typeof e === "boolean" && e;
1291
+ });
1292
+ }
1293
+ };
1294
+ customElements.define("qti-or", QtiOr);
1295
+
1296
+ // ../qti-processing/src/components/qti-ordered/qti-ordered.ts
1297
+ var QtiOrdered = class extends QtiExpression {
1298
+ getResult() {
1299
+ const variables = this.getVariables();
1300
+ if (variables.length === 0) {
1301
+ console.error("unexpected number of children in qti multiple");
1302
+ return null;
1303
+ }
1304
+ for (const variable of variables) {
1305
+ if (variable.cardinality !== "ordered" && variable.cardinality !== "single") {
1306
+ console.error("unexpected cardinality in qti ordered");
1307
+ return [];
1308
+ }
1309
+ }
1310
+ return variables;
1311
+ }
1312
+ };
1313
+ customElements.define("qti-ordered", QtiOrdered);
1314
+
1315
+ // ../qti-processing/src/components/qti-power/qti-power.ts
1316
+ var QtiPower = class extends QtiExpression {
1317
+ getResult() {
1318
+ if (this.children.length !== 2) {
1319
+ console.error("qti-power must have exactly two child expressions");
1320
+ return null;
1321
+ }
1322
+ const variables = this.getVariables();
1323
+ if (!variables || variables.length !== 2) {
1324
+ return null;
1325
+ }
1326
+ const [base, exponent] = variables;
1327
+ if (base.cardinality !== "single" || exponent.cardinality !== "single") {
1328
+ console.error("qti-power requires single cardinality for both expressions");
1329
+ return null;
1330
+ }
1331
+ if (Array.isArray(base.value) || Array.isArray(exponent.value)) {
1332
+ console.error("qti-power unexpected array value for single cardinality");
1333
+ return null;
1334
+ }
1335
+ if (base.value === null || base.value === void 0 || exponent.value === null || exponent.value === void 0) {
1336
+ return null;
1337
+ }
1338
+ if (base.baseType !== "integer" && base.baseType !== "float" || exponent.baseType !== "integer" && exponent.baseType !== "float") {
1339
+ console.error("qti-power requires numerical base-types");
1340
+ return null;
1341
+ }
1342
+ const baseValue = parseFloat(base.value);
1343
+ const exponentValue = parseFloat(exponent.value);
1344
+ if (isNaN(baseValue) || isNaN(exponentValue)) {
1345
+ console.error("qti-power: non-numerical values encountered");
1346
+ return null;
1347
+ }
1348
+ if (baseValue === 0 && exponentValue <= 0) {
1349
+ return null;
1350
+ }
1351
+ if (baseValue < 0 && !Number.isInteger(exponentValue)) {
1352
+ return null;
1353
+ }
1354
+ let result;
1355
+ try {
1356
+ result = Math.pow(baseValue, exponentValue);
1357
+ } catch (error) {
1358
+ console.error("qti-power: error calculating power:", error);
1359
+ return null;
1360
+ }
1361
+ if (isNaN(result)) {
1362
+ return null;
1363
+ }
1364
+ if (result === Infinity || result === -Infinity) {
1365
+ return result;
1366
+ }
1367
+ if (!isFinite(result)) {
1368
+ return null;
1369
+ }
1370
+ if (Math.abs(result) > Number.MAX_VALUE) {
1371
+ return null;
1372
+ }
1373
+ if (result !== 0 && Math.abs(result) < Number.MIN_VALUE) {
1374
+ return null;
1375
+ }
1376
+ if (isFinite(result) && result !== 0) {
1377
+ const magnitude = Math.floor(Math.log10(Math.abs(result)));
1378
+ const precision = Math.max(0, 14 - magnitude);
1379
+ const factor = Math.pow(10, precision);
1380
+ result = Math.round(result * factor) / factor;
1381
+ }
1382
+ return result;
1383
+ }
1384
+ };
1385
+ customElements.define("qti-power", QtiPower);
1386
+
1387
+ // ../qti-processing/src/components/qti-printed-variable/qti-printed-variable.ts
1388
+ var QtiPrintedVariable = class extends i {
1389
+ render() {
1390
+ const value = this.context?.variables.find((v) => v.identifier === this.identifier)?.value;
1391
+ return value === null ? E : x`${JSON.stringify(value, null, 2)}`;
1392
+ }
1393
+ calculate() {
1394
+ const result = this.context.variables.find((v) => v.identifier === this.identifier) || null;
1395
+ return result;
1396
+ }
1397
+ };
1398
+ __decorateClass([
1399
+ n({ type: String })
1400
+ ], QtiPrintedVariable.prototype, "identifier", 2);
1401
+ __decorateClass([
1402
+ c({ context: itemContext, subscribe: true }),
1403
+ r()
1404
+ ], QtiPrintedVariable.prototype, "context", 2);
1405
+ customElements.define("qti-printed-variable", QtiPrintedVariable);
1406
+
1407
+ // ../qti-processing/src/components/qti-product/qti-product.ts
1408
+ var QtiProduct = class extends QtiExpression {
1409
+ getResult() {
1410
+ const values = this.getVariables();
1411
+ const product = values.reduce((accumulator, currentValue) => {
1412
+ if (currentValue.baseType == "float" || currentValue.baseType == "integer") {
1413
+ try {
1414
+ return accumulator * parseFloat(currentValue.value.toString());
1415
+ } catch (error) {
1416
+ console.warn(`can not convert to number`);
1417
+ }
1418
+ } else {
1419
+ console.warn(`has another baseType ${currentValue.baseType}`);
1420
+ }
1421
+ return accumulator;
1422
+ }, 1);
1423
+ return product;
1424
+ }
1425
+ };
1426
+ customElements.define("qti-product", QtiProduct);
1427
+
1428
+ // ../qti-processing/src/components/qti-subtract/qti-subtract.ts
1429
+ var QtiSubtract = class extends qtiSubtractMixin(QtiExpression) {
1430
+ getResult() {
1431
+ const value = this.calculateChildren(Array.from(this.children));
1432
+ return value;
1433
+ }
1434
+ };
1435
+ function qtiSubtractMixin(Base) {
1436
+ return class MockQtiSubtract extends Base {
1437
+ calculateChildren(children) {
1438
+ const values = children.map((expression) => {
1439
+ if (!expression.calculate) {
1440
+ console.error("Element doesn't implement QtiConditionExpression");
1441
+ return null;
1442
+ }
1443
+ const value = expression.calculate();
1444
+ if (Number.isNaN(value)) {
1445
+ console.error("Unexpected value in qti-subtract, expected number");
1446
+ return null;
1447
+ }
1448
+ return Number(value);
1449
+ });
1450
+ if (values.some((value) => value === null)) {
1451
+ console.error("One or more child expressions returned invalid values");
1452
+ return 0;
1453
+ }
1454
+ return values[0] - values[1];
1455
+ }
1456
+ };
1457
+ }
1458
+
1459
+ // ../qti-processing/src/components/qti-string-match/qti-string-match.ts
1460
+ var QtiStringMatch = class extends QtiExpression {
1461
+ constructor() {
1462
+ super(...arguments);
1463
+ this.caseSensitive = "true";
1464
+ }
1465
+ getResult() {
1466
+ if (this.children.length === 2) {
1467
+ const values = this.getVariables();
1468
+ const value1 = values[0];
1469
+ const value2 = values[1];
1470
+ if (value1.cardinality !== "single" || value2.cardinality !== "single" || Array.isArray(value1.value) || Array.isArray(value2.value)) {
1471
+ console.error("unexpected cardinality in qti string-match");
1472
+ return false;
1473
+ }
1474
+ const v1 = this.caseSensitive === "true" ? value1.value : value1.value.toLowerCase();
1475
+ const v2 = this.caseSensitive === "true" ? value2.value : value2.value.toLowerCase();
1476
+ return ScoringHelper.compareSingleValues(v1, v2, value1.baseType);
1477
+ }
1478
+ console.error("unexpected number of children in qti-string-match");
1479
+ return null;
1480
+ }
1481
+ };
1482
+ __decorateClass([
1483
+ n({ type: String, attribute: "case-sensitive" })
1484
+ ], QtiStringMatch.prototype, "caseSensitive", 2);
1485
+ customElements.define("qti-string-match", QtiStringMatch);
1486
+
1487
+ // ../qti-processing/src/components/qti-sum/qti-sum.ts
1488
+ var QtiSum = class extends QtiExpression {
1489
+ constructor() {
1490
+ super();
1491
+ this._expression = new QtiSumExpression(Array.from(this.children));
1492
+ }
1493
+ getResult() {
1494
+ const value = this._expression.calculate();
1495
+ return value;
1496
+ }
1497
+ };
1498
+ var QtiSumExpression = class {
1499
+ constructor(expressions) {
1500
+ this.expressions = expressions;
1501
+ }
1502
+ calculate() {
1503
+ const expressions = this.expressions.filter((c2) => c2.calculate !== void 0);
1504
+ if (expressions.some((c2) => c2.calculate() === null)) {
1505
+ return null;
1506
+ }
1507
+ const values = this.expressions.map((c2) => {
1508
+ const value = c2.calculate();
1509
+ if (Number.isNaN(value)) {
1510
+ console.error("unexpected value in qti-sum, expected number");
1511
+ return null;
1512
+ }
1513
+ return Number(value);
1514
+ });
1515
+ return values.reduce((a, b) => a + b, 0);
1516
+ }
1517
+ };
1518
+ customElements.define("qti-sum", QtiSum);
1519
+
1520
+ // ../qti-processing/src/components/qti-variable/qti-variable.ts
1521
+ var QtiVariable = class extends QtiExpression {
1522
+ getResult() {
1523
+ const identifier = this.getAttribute("identifier");
1524
+ const result = this.context.variables.find((v) => v.identifier === identifier).value;
1525
+ return result;
1526
+ }
1527
+ };
1528
+ customElements.define("qti-variable", QtiVariable);
1529
+
1530
+ // ../qti-processing/src/components/qti-random-integer/qti-random-integer.ts
1531
+ var QtiRandomInteger = class extends QtiExpression {
1532
+ constructor() {
1533
+ super(...arguments);
1534
+ this.min = 0;
1535
+ this.max = 10;
1536
+ this.step = 1;
1537
+ }
1538
+ getResult() {
1539
+ if (this.min > this.max) {
1540
+ console.error("qti-random-integer: min cannot be greater than max");
1541
+ return this.min;
1542
+ }
1543
+ if (this.step <= 0) {
1544
+ console.error("qti-random-integer: step must be positive");
1545
+ return this.min;
1546
+ }
1547
+ const possibleValues = [];
1548
+ let n2 = 0;
1549
+ while (true) {
1550
+ const value = this.min + this.step * n2;
1551
+ if (value > this.max) {
1552
+ break;
1553
+ }
1554
+ if (Number.isInteger(value)) {
1555
+ possibleValues.push(value);
1556
+ }
1557
+ n2++;
1558
+ }
1559
+ if (possibleValues.length === 0) {
1560
+ console.warn("qti-random-integer: no valid integer values in range");
1561
+ return Number.isInteger(this.min) ? this.min : Math.floor(this.min);
1562
+ }
1563
+ const randomIndex = Math.floor(Math.random() * possibleValues.length);
1564
+ return possibleValues[randomIndex];
1565
+ }
1566
+ /**
1567
+ * Get all possible values for testing purposes
1568
+ */
1569
+ getPossibleValues() {
1570
+ const possibleValues = [];
1571
+ if (this.min > this.max || this.step <= 0) {
1572
+ return [Number.isInteger(this.min) ? this.min : Math.floor(this.min)];
1573
+ }
1574
+ let n2 = 0;
1575
+ while (true) {
1576
+ const value = this.min + this.step * n2;
1577
+ if (value > this.max) {
1578
+ break;
1579
+ }
1580
+ if (Number.isInteger(value)) {
1581
+ possibleValues.push(value);
1582
+ }
1583
+ n2++;
1584
+ }
1585
+ return possibleValues.length > 0 ? possibleValues : [Number.isInteger(this.min) ? this.min : Math.floor(this.min)];
1586
+ }
1587
+ };
1588
+ __decorateClass([
1589
+ n({ type: Number })
1590
+ ], QtiRandomInteger.prototype, "min", 2);
1591
+ __decorateClass([
1592
+ n({ type: Number })
1593
+ ], QtiRandomInteger.prototype, "max", 2);
1594
+ __decorateClass([
1595
+ n({ type: Number })
1596
+ ], QtiRandomInteger.prototype, "step", 2);
1597
+ customElements.define("qti-random-integer", QtiRandomInteger);
1598
+
1599
+ // ../qti-processing/src/components/qti-random/qti-random.ts
1600
+ var QtiRandom = class extends QtiExpression {
1601
+ getResult() {
1602
+ const values = this.getVariables();
1603
+ if (values.length === 1) {
1604
+ const value = values[0].value;
1605
+ if (Array.isArray(value)) {
1606
+ const randomIndex = Math.floor(Math.random() * value.length);
1607
+ return value[randomIndex];
1608
+ }
1609
+ return value;
1610
+ }
1611
+ console.error("unexpected number of children in match");
1612
+ return null;
1613
+ }
1614
+ };
1615
+ customElements.define("qti-random", QtiRandom);
1616
+
1617
+ // ../qti-processing/src/components/qti-delete/qti-delete.ts
1618
+ var QtiDelete = class extends QtiExpression {
1619
+ getResult() {
1620
+ if (this.children.length === 2) {
1621
+ const values = this.getVariables();
1622
+ const value1 = values[0];
1623
+ const value2 = values[1];
1624
+ if (value1.cardinality !== "single" || !Array.isArray(value2.value)) {
1625
+ console.error("unexpected cardinality in qti equal");
1626
+ return null;
1627
+ }
1628
+ if (values[0].baseType !== values[1].baseType) {
1629
+ console.error("The baseType of the two variables is different");
1630
+ return null;
1631
+ }
1632
+ const filtered = value2.value.filter((v) => !value1.value.includes(v));
1633
+ return filtered;
1634
+ }
1635
+ return null;
1636
+ }
1637
+ };
1638
+ customElements.define("qti-delete", QtiDelete);
1639
+
1640
+ // ../qti-processing/src/components/qti-index/qti-index.ts
1641
+ var QtiIndex = class extends QtiExpression {
1642
+ // Required attribute, can be a number or an identifier
1643
+ getResult() {
1644
+ if (!this.n) {
1645
+ console.error('qti-index: missing required attribute "n"');
1646
+ return null;
1647
+ }
1648
+ if (this.children.length !== 1) {
1649
+ console.error("qti-index: must have exactly one child container element");
1650
+ return null;
1651
+ }
1652
+ const containerVariable = this.getVariables()[0];
1653
+ if (!containerVariable) {
1654
+ console.error("qti-index: missing container");
1655
+ return null;
1656
+ }
1657
+ let index;
1658
+ if (!isNaN(Number(this.n))) {
1659
+ index = Number(this.n);
1660
+ } else {
1661
+ const variableValue = this.lookupVariableValue(this.n);
1662
+ if (variableValue === null) {
1663
+ console.error(`qti-index: variable "${this.n}" is not a valid number`);
1664
+ return null;
1665
+ }
1666
+ index = Number(variableValue);
1667
+ }
1668
+ if (index <= 0 || !Number.isInteger(index)) {
1669
+ console.error("qti-index: index must be a positive integer");
1670
+ return null;
1671
+ }
1672
+ if (containerVariable.cardinality === "ordered") {
1673
+ const containerValues = Array.isArray(containerVariable.value) ? containerVariable.value : [containerVariable.value];
1674
+ if (containerVariable.value === null || index > containerValues.length) {
1675
+ return null;
1676
+ }
1677
+ return containerValues[index - 1];
1678
+ } else {
1679
+ console.error("qti-index: child must have ordered cardinality");
1680
+ return null;
1681
+ }
1682
+ }
1683
+ // Helper method to look up a variable value by identifier
1684
+ // This would need to be implemented based on your actual QTI runtime environment
1685
+ lookupVariableValue(identifier) {
1686
+ const value = this.context.variables.find((v) => v.identifier === identifier)?.value;
1687
+ if (value === null || isNaN(Number(value))) {
1688
+ return null;
1689
+ }
1690
+ return Number(value);
1691
+ }
1692
+ };
1693
+ __decorateClass([
1694
+ n({ type: String })
1695
+ ], QtiIndex.prototype, "n", 2);
1696
+ QtiIndex = __decorateClass([
1697
+ t("qti-index")
1698
+ ], QtiIndex);
1699
+
1700
+ // ../qti-processing/src/components/qti-subtract/index.ts
1701
+ customElements.define("qti-subtract", QtiSubtract);
1702
+
1703
+ export {
1704
+ QtiLookupOutcomeValue,
1705
+ QtiResponseCondition,
1706
+ QtiSetOutcomeValue,
1707
+ QtiSetOutcomeValueRule,
1708
+ QtiResponseElse,
1709
+ QtiResponseIf,
1710
+ QtiResponseElseIf,
1711
+ QtiAnd,
1712
+ qtiAndMixin,
1713
+ QtiBaseValue,
1714
+ QtiContainerSize,
1715
+ QtiContains,
1716
+ QtiCorrect,
1717
+ QtiDefault,
1718
+ QtiEqualRounded,
1719
+ QtiRound,
1720
+ QtiRoundTo,
1721
+ QtiEqual,
1722
+ QtiGcd,
1723
+ QtiGt,
1724
+ QtiGte,
1725
+ QtiNull,
1726
+ QtiIsNull,
1727
+ QtiFieldValue,
1728
+ QtiLt,
1729
+ QtiLte,
1730
+ QtiMapResponse,
1731
+ QtiMapResponsePoint,
1732
+ QtiMathOperator,
1733
+ QtiMatch,
1734
+ QtiMember,
1735
+ QtiMultiple,
1736
+ QtiNot,
1737
+ QtiOr,
1738
+ QtiOrdered,
1739
+ QtiPower,
1740
+ QtiPrintedVariable,
1741
+ QtiProduct,
1742
+ QtiSubtract,
1743
+ qtiSubtractMixin,
1744
+ QtiStringMatch,
1745
+ QtiSum,
1746
+ QtiSumExpression,
1747
+ QtiVariable,
1748
+ QtiRandomInteger,
1749
+ QtiRandom,
1750
+ QtiDelete,
1751
+ QtiIndex
1752
+ };
1753
+ //# sourceMappingURL=chunk-RI47B4ZT.js.map