@qti-components/processing 1.1.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.
- package/LICENSE.md +674 -0
- package/dist/components/index.d.ts +38 -0
- package/dist/components/index.js +44 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/qti-and/qti-and.d.ts +20 -0
- package/dist/components/qti-and/qti-and.js +56 -0
- package/dist/components/qti-and/qti-and.js.map +1 -0
- package/dist/components/qti-basevalue/qti-basevalue.d.ts +6 -0
- package/dist/components/qti-basevalue/qti-basevalue.js +23 -0
- package/dist/components/qti-basevalue/qti-basevalue.js.map +1 -0
- package/dist/components/qti-container-size/qti-container-size.d.ts +12 -0
- package/dist/components/qti-container-size/qti-container-size.js +40 -0
- package/dist/components/qti-container-size/qti-container-size.js.map +1 -0
- package/dist/components/qti-contains/qti-contains.d.ts +4 -0
- package/dist/components/qti-contains/qti-contains.js +38 -0
- package/dist/components/qti-contains/qti-contains.js.map +1 -0
- package/dist/components/qti-correct/qti-correct.d.ts +5 -0
- package/dist/components/qti-correct/qti-correct.js +18 -0
- package/dist/components/qti-correct/qti-correct.js.map +1 -0
- package/dist/components/qti-default/qti-default.d.ts +17 -0
- package/dist/components/qti-default/qti-default.js +87 -0
- package/dist/components/qti-default/qti-default.js.map +1 -0
- package/dist/components/qti-delete/qti-delete.d.ts +4 -0
- package/dist/components/qti-delete/qti-delete.js +23 -0
- package/dist/components/qti-delete/qti-delete.js.map +1 -0
- package/dist/components/qti-equal/qti-equal.d.ts +5 -0
- package/dist/components/qti-equal/qti-equal.js +41 -0
- package/dist/components/qti-equal/qti-equal.js.map +1 -0
- package/dist/components/qti-equal-rounded/qti-equal-rounded.d.ts +6 -0
- package/dist/components/qti-equal-rounded/qti-equal-rounded.js +84 -0
- package/dist/components/qti-equal-rounded/qti-equal-rounded.js.map +1 -0
- package/dist/components/qti-field-value/qti-field-value.d.ts +4 -0
- package/dist/components/qti-field-value/qti-field-value.js +27 -0
- package/dist/components/qti-field-value/qti-field-value.js.map +1 -0
- package/dist/components/qti-gcd/qti.gcd.d.ts +13 -0
- package/dist/components/qti-gcd/qti.gcd.js +119 -0
- package/dist/components/qti-gcd/qti.gcd.js.map +1 -0
- package/dist/components/qti-gt/qti-gt.d.ts +4 -0
- package/dist/components/qti-gt/qti-gt.js +21 -0
- package/dist/components/qti-gt/qti-gt.js.map +1 -0
- package/dist/components/qti-gte/qti-gte.d.ts +4 -0
- package/dist/components/qti-gte/qti-gte.js +24 -0
- package/dist/components/qti-gte/qti-gte.js.map +1 -0
- package/dist/components/qti-index/qti-index.d.ts +6 -0
- package/dist/components/qti-index/qti-index.js +82 -0
- package/dist/components/qti-index/qti-index.js.map +1 -0
- package/dist/components/qti-is-null/qti-is-null.d.ts +4 -0
- package/dist/components/qti-is-null/qti-is-null.js +19 -0
- package/dist/components/qti-is-null/qti-is-null.js.map +1 -0
- package/dist/components/qti-lookup-outcome-value/qti-lookup-outcome-value.d.ts +19 -0
- package/dist/components/qti-lookup-outcome-value/qti-lookup-outcome-value.js +51 -0
- package/dist/components/qti-lookup-outcome-value/qti-lookup-outcome-value.js.map +1 -0
- package/dist/components/qti-lt/qti-lt.d.ts +4 -0
- package/dist/components/qti-lt/qti-lt.js +21 -0
- package/dist/components/qti-lt/qti-lt.js.map +1 -0
- package/dist/components/qti-lte/qti-lte.d.ts +4 -0
- package/dist/components/qti-lte/qti-lte.js +24 -0
- package/dist/components/qti-lte/qti-lte.js.map +1 -0
- package/dist/components/qti-map-response/qti-map-response.d.ts +5 -0
- package/dist/components/qti-map-response/qti-map-response.js +52 -0
- package/dist/components/qti-map-response/qti-map-response.js.map +1 -0
- package/dist/components/qti-map-response-point/qti-map-response-point.d.ts +5 -0
- package/dist/components/qti-map-response-point/qti-map-response-point.js +60 -0
- package/dist/components/qti-map-response-point/qti-map-response-point.js.map +1 -0
- package/dist/components/qti-match/qti-match.d.ts +6 -0
- package/dist/components/qti-match/qti-match.js +84 -0
- package/dist/components/qti-match/qti-match.js.map +1 -0
- package/dist/components/qti-math-operator/qti-math-operator.d.ts +14 -0
- package/dist/components/qti-math-operator/qti-math-operator.js +213 -0
- package/dist/components/qti-math-operator/qti-math-operator.js.map +1 -0
- package/dist/components/qti-member/qti-member.d.ts +4 -0
- package/dist/components/qti-member/qti-member.js +34 -0
- package/dist/components/qti-member/qti-member.js.map +1 -0
- package/dist/components/qti-multiple/qti-multiple.d.ts +5 -0
- package/dist/components/qti-multiple/qti-multiple.js +26 -0
- package/dist/components/qti-multiple/qti-multiple.js.map +1 -0
- package/dist/components/qti-not/qti-not.d.ts +5 -0
- package/dist/components/qti-not/qti-not.js +14 -0
- package/dist/components/qti-not/qti-not.js.map +1 -0
- package/dist/components/qti-null/qti-null.d.ts +11 -0
- package/dist/components/qti-null/qti-null.js +15 -0
- package/dist/components/qti-null/qti-null.js.map +1 -0
- package/dist/components/qti-or/qti-or.d.ts +4 -0
- package/dist/components/qti-or/qti-or.js +39 -0
- package/dist/components/qti-or/qti-or.js.map +1 -0
- package/dist/components/qti-ordered/qti-ordered.d.ts +5 -0
- package/dist/components/qti-ordered/qti-ordered.js +19 -0
- package/dist/components/qti-ordered/qti-ordered.js.map +1 -0
- package/dist/components/qti-power/qti-power.d.ts +12 -0
- package/dist/components/qti-power/qti-power.js +99 -0
- package/dist/components/qti-power/qti-power.js.map +1 -0
- package/dist/components/qti-printed-variable/qti-printed-variable.d.ts +9 -0
- package/dist/components/qti-printed-variable/qti-printed-variable.js +29 -0
- package/dist/components/qti-printed-variable/qti-printed-variable.js.map +1 -0
- package/dist/components/qti-product/qti-product.d.ts +4 -0
- package/dist/components/qti-product/qti-product.js +23 -0
- package/dist/components/qti-product/qti-product.js.map +1 -0
- package/dist/components/qti-random/qti-random.d.ts +4 -0
- package/dist/components/qti-random/qti-random.js +19 -0
- package/dist/components/qti-random/qti-random.js.map +1 -0
- package/dist/components/qti-random-integer/qti-random-integer.d.ts +18 -0
- package/dist/components/qti-random-integer/qti-random-integer.js +90 -0
- package/dist/components/qti-random-integer/qti-random-integer.js.map +1 -0
- package/dist/components/qti-response-condition/qti-response-condition.d.ts +5 -0
- package/dist/components/qti-response-condition/qti-response-condition.js +19 -0
- package/dist/components/qti-response-condition/qti-response-condition.js.map +1 -0
- package/dist/components/qti-response-else/qti-response-else.d.ts +8 -0
- package/dist/components/qti-response-else/qti-response-else.js +21 -0
- package/dist/components/qti-response-else/qti-response-else.js.map +1 -0
- package/dist/components/qti-response-else-if/qti-response-else-if.d.ts +4 -0
- package/dist/components/qti-response-else-if/qti-response-else-if.js +9 -0
- package/dist/components/qti-response-else-if/qti-response-else-if.js.map +1 -0
- package/dist/components/qti-response-if/qti-response-if.d.ts +6 -0
- package/dist/components/qti-response-if/qti-response-if.js +17 -0
- package/dist/components/qti-response-if/qti-response-if.js.map +1 -0
- package/dist/components/qti-round/qti-round.d.ts +13 -0
- package/dist/components/qti-round/qti-round.js +66 -0
- package/dist/components/qti-round/qti-round.js.map +1 -0
- package/dist/components/qti-round-to/qti-round-to.d.ts +15 -0
- package/dist/components/qti-round-to/qti-round-to.js +117 -0
- package/dist/components/qti-round-to/qti-round-to.js.map +1 -0
- package/dist/components/qti-rule/qti-rule.d.ts +11 -0
- package/dist/components/qti-rule/qti-rule.js +21 -0
- package/dist/components/qti-rule/qti-rule.js.map +1 -0
- package/dist/components/qti-set-outcome-value/qti-set-outcome-value.d.ts +24 -0
- package/dist/components/qti-set-outcome-value/qti-set-outcome-value.js +63 -0
- package/dist/components/qti-set-outcome-value/qti-set-outcome-value.js.map +1 -0
- package/dist/components/qti-string-match/qti-string-match.d.ts +5 -0
- package/dist/components/qti-string-match/qti-string-match.js +39 -0
- package/dist/components/qti-string-match/qti-string-match.js.map +1 -0
- package/dist/components/qti-subtract/index.d.ts +7 -0
- package/dist/components/qti-subtract/index.js +4 -0
- package/dist/components/qti-subtract/index.js.map +1 -0
- package/dist/components/qti-subtract/qti-subtract.d.ts +20 -0
- package/dist/components/qti-subtract/qti-subtract.js +34 -0
- package/dist/components/qti-subtract/qti-subtract.js.map +1 -0
- package/dist/components/qti-sum/qti-sum.d.ts +12 -0
- package/dist/components/qti-sum/qti-sum.js +36 -0
- package/dist/components/qti-sum/qti-sum.js.map +1 -0
- package/dist/components/qti-variable/qti-variable.d.ts +4 -0
- package/dist/components/qti-variable/qti-variable.js +10 -0
- package/dist/components/qti-variable/qti-variable.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { property } from 'lit/decorators.js';
|
|
8
|
+
import { QtiExpression } from '@qti-components/base';
|
|
9
|
+
export class QtiEqualRounded extends QtiExpression {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
this.roundingMode = 'significantFigures';
|
|
13
|
+
}
|
|
14
|
+
get figures() {
|
|
15
|
+
const attr = this.getAttribute('figures');
|
|
16
|
+
if (!attr) {
|
|
17
|
+
console.error('figures attribute is missing');
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const figures = parseInt(this.getAttribute('figures') || '0');
|
|
21
|
+
if (isNaN(figures)) {
|
|
22
|
+
console.error('figures attribute is not a number');
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
if (figures < 0) {
|
|
26
|
+
console.error('figures attribute is negative');
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
if (figures < 1 && this.roundingMode === 'significantFigures') {
|
|
30
|
+
console.error('figures cannot be smaller than 1 for RoundingMode significantFigures');
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return figures;
|
|
34
|
+
}
|
|
35
|
+
getResult() {
|
|
36
|
+
if (this.children.length === 2) {
|
|
37
|
+
const values = this.getVariables();
|
|
38
|
+
const value1 = values[0];
|
|
39
|
+
const value2 = values[1];
|
|
40
|
+
if (this.roundingMode === null) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
if (value1.cardinality !== 'single' ||
|
|
44
|
+
value2.cardinality !== 'single' ||
|
|
45
|
+
Array.isArray(value1.value) ||
|
|
46
|
+
Array.isArray(value2.value)) {
|
|
47
|
+
console.error('unexpected cardinality in qti equal');
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
switch (values[0].baseType) {
|
|
51
|
+
case 'integer':
|
|
52
|
+
case 'float': {
|
|
53
|
+
const float1 = parseFloat(value1.value);
|
|
54
|
+
const float2 = parseFloat(value2.value);
|
|
55
|
+
if (!isNaN(float1) && !isNaN(float2)) {
|
|
56
|
+
if (this.roundingMode === 'significantFigures') {
|
|
57
|
+
return float1.toPrecision(this.figures) === float2.toPrecision(this.figures);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
return (Math.round(float1 * Math.pow(10, this.figures)) / Math.pow(10, this.figures) ===
|
|
61
|
+
Math.round(float2 * Math.pow(10, this.figures)) / Math.pow(10, this.figures));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
console.error(`value cannot be casted to numeric value in equalRounded operator: ${float1}, ${float2}`);
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
default: {
|
|
70
|
+
console.error(`values other than float and int cannot be used in equalRounded operator.`);
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
console.error('unexpected number of children in qti-equal-rounded');
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
__decorate([
|
|
81
|
+
property({ type: String })
|
|
82
|
+
], QtiEqualRounded.prototype, "roundingMode", void 0);
|
|
83
|
+
customElements.define('qti-equal-rounded', QtiEqualRounded);
|
|
84
|
+
//# sourceMappingURL=qti-equal-rounded.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qti-equal-rounded.js","sourceRoot":"","sources":["../../../src/components/qti-equal-rounded/qti-equal-rounded.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAIrD,MAAM,OAAO,eAAgB,SAAQ,aAAsB;IAA3D;;QAC8B,iBAAY,GAA2C,oBAAoB,CAAC;IAuE1G,CAAC;IArEC,IAAI,OAAO;QACT,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;QAC1C,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;YAC9C,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,GAAG,CAAC,CAAC;QAC9D,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;YACnB,OAAO,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC;YACnD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;YAChB,OAAO,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;YAC/C,OAAO,IAAI,CAAC;QACd,CAAC;QACD,IAAI,OAAO,GAAG,CAAC,IAAI,IAAI,CAAC,YAAY,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C,OAAO,CAAC,KAAK,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;wBAC/E,CAAC;6BAAM,CAAC;4BACN,OAAO,CACL,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC;gCAC5E,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAC7E,CAAC;wBACJ,CAAC;oBACH,CAAC;yBAAM,CAAC;wBACN,OAAO,CAAC,KAAK,CAAC,qEAAqE,MAAM,KAAK,MAAM,EAAE,CAAC,CAAC;oBAC1G,CAAC;oBACD,MAAM;gBACR,CAAC;gBACD,OAAO,CAAC,CAAC,CAAC;oBACR,OAAO,CAAC,KAAK,CAAC,0EAA0E,CAAC,CAAC;oBAC1F,MAAM;gBACR,CAAC;YACH,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,CAAC,KAAK,CAAC,oDAAoD,CAAC,CAAC;QACpE,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAvE6B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;qDAA6E;AAyE1G,cAAc,CAAC,MAAM,CAAC,mBAAmB,EAAE,eAAe,CAAC,CAAC","sourcesContent":["import { property } from 'lit/decorators.js';\n\nimport { QtiExpression } from '@qti-components/base';\n\nimport type { ResponseVariable } from '@qti-components/base';\n\nexport class QtiEqualRounded extends QtiExpression<boolean> {\n @property({ type: String }) roundingMode: 'decimalPlaces' | 'significantFigures' = 'significantFigures';\n\n get figures() {\n const attr = this.getAttribute('figures');\n if (!attr) {\n console.error('figures attribute is missing');\n return null;\n }\n const figures = parseInt(this.getAttribute('figures') || '0');\n if (isNaN(figures)) {\n console.error('figures attribute is not a number');\n return null;\n }\n if (figures < 0) {\n console.error('figures attribute is negative');\n return null;\n }\n if (figures < 1 && this.roundingMode === 'significantFigures') {\n console.error('figures cannot be smaller than 1 for RoundingMode significantFigures');\n return null;\n }\n return figures;\n }\n\n public override getResult() {\n if (this.children.length === 2) {\n const values = this.getVariables() as ResponseVariable[];\n const value1 = values[0];\n const value2 = values[1];\n if (this.roundingMode === null) {\n return null;\n }\n if (\n value1.cardinality !== 'single' ||\n value2.cardinality !== 'single' ||\n Array.isArray(value1.value) ||\n Array.isArray(value2.value)\n ) {\n console.error('unexpected cardinality in qti equal');\n return false;\n }\n switch (values[0].baseType) {\n case 'integer':\n case 'float': {\n const float1 = parseFloat(value1.value as string);\n const float2 = parseFloat(value2.value as string);\n\n if (!isNaN(float1) && !isNaN(float2)) {\n if (this.roundingMode === 'significantFigures') {\n return float1.toPrecision(this.figures) === float2.toPrecision(this.figures);\n } else {\n return (\n Math.round(float1 * Math.pow(10, this.figures)) / Math.pow(10, this.figures) ===\n Math.round(float2 * Math.pow(10, this.figures)) / Math.pow(10, this.figures)\n );\n }\n } else {\n console.error(`value cannot be casted to numeric value in equalRounded operator: ${float1}, ${float2}`);\n }\n break;\n }\n default: {\n console.error(`values other than float and int cannot be used in equalRounded operator.`);\n break;\n }\n }\n return false;\n }\n console.error('unexpected number of children in qti-equal-rounded');\n return null;\n }\n}\n\ncustomElements.define('qti-equal-rounded', QtiEqualRounded);\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { QtiExpression } from '@qti-components/base';
|
|
2
|
+
export class QtiFieldValue extends QtiExpression {
|
|
3
|
+
getResult() {
|
|
4
|
+
const fieldIdentifier = this.getAttribute('field-identifier');
|
|
5
|
+
if (!fieldIdentifier) {
|
|
6
|
+
throw new Error('field-identifier attribute is required');
|
|
7
|
+
}
|
|
8
|
+
// Get the result from the child expression (should be a record)
|
|
9
|
+
const childElements = Array.from(this.children);
|
|
10
|
+
if (childElements.length !== 1) {
|
|
11
|
+
throw new Error('qti-field-value must have exactly one child expression');
|
|
12
|
+
}
|
|
13
|
+
const variable = this.getVariables()[0];
|
|
14
|
+
// Check if the result is a record/object
|
|
15
|
+
if (variable.baseType !== 'record' || variable.value === null) {
|
|
16
|
+
throw new Error('qti-field-value child expression must return a record');
|
|
17
|
+
}
|
|
18
|
+
// Return the field value
|
|
19
|
+
const fieldValue = variable.value[fieldIdentifier];
|
|
20
|
+
if (fieldValue === undefined) {
|
|
21
|
+
throw new Error(`Field "${fieldIdentifier}" not found in record`);
|
|
22
|
+
}
|
|
23
|
+
return fieldValue;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
customElements.define('qti-field-value', QtiFieldValue);
|
|
27
|
+
//# sourceMappingURL=qti-field-value.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qti-field-value.js","sourceRoot":"","sources":["../../../src/components/qti-field-value/qti-field-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAIrD,MAAM,OAAO,aAAc,SAAQ,aAAgC;IACjD,SAAS;QACvB,MAAM,eAAe,GAAG,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC;QAE9D,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;QAC5D,CAAC;QAED,gEAAgE;QAChE,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAyB,CAAC;QAExE,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;QAC5E,CAAC;QAED,MAAM,QAAQ,GAAI,IAAI,CAAC,YAAY,EAAyB,CAAC,CAAC,CAAC,CAAC;QAEhE,yCAAyC;QACzC,IAAI,QAAQ,CAAC,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;YAC9D,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;QAC3E,CAAC;QAED,yBAAyB;QACzB,MAAM,UAAU,GAAI,QAAQ,CAAC,KAA6B,CAAC,eAAe,CAAC,CAAC;QAE5E,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,UAAU,eAAe,uBAAuB,CAAC,CAAC;QACpE,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;CACF;AAED,cAAc,CAAC,MAAM,CAAC,iBAAiB,EAAE,aAAa,CAAC,CAAC","sourcesContent":["import { QtiExpression } from '@qti-components/base';\n\nimport type { ResponseVariable } from '@qti-components/base';\n\nexport class QtiFieldValue extends QtiExpression<string | string[]> {\n public override getResult() {\n const fieldIdentifier = this.getAttribute('field-identifier');\n\n if (!fieldIdentifier) {\n throw new Error('field-identifier attribute is required');\n }\n\n // Get the result from the child expression (should be a record)\n const childElements = Array.from(this.children) as QtiExpression<any>[];\n\n if (childElements.length !== 1) {\n throw new Error('qti-field-value must have exactly one child expression');\n }\n\n const variable = (this.getVariables() as ResponseVariable[])[0];\n\n // Check if the result is a record/object\n if (variable.baseType !== 'record' || variable.value === null) {\n throw new Error('qti-field-value child expression must return a record');\n }\n\n // Return the field value\n const fieldValue = (variable.value as Record<string, any>)[fieldIdentifier];\n\n if (fieldValue === undefined) {\n throw new Error(`Field \"${fieldIdentifier}\" not found in record`);\n }\n\n return fieldValue;\n }\n}\n\ncustomElements.define('qti-field-value', QtiFieldValue);\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { QtiExpression } from '@qti-components/base';
|
|
2
|
+
/**
|
|
3
|
+
* @summary The qti-gcd operator calculates the greatest common divisor of integer values.
|
|
4
|
+
* @documentation https://www.imsglobal.org/spec/qti/v3p0/impl#h.gcd
|
|
5
|
+
*
|
|
6
|
+
* Takes 1 or more sub-expressions with base-type integer and any cardinality.
|
|
7
|
+
* Returns a single integer equal to the greatest common divisor of all argument values.
|
|
8
|
+
* Special cases: gcd(0,0)=0, gcd(0,n)=n if n≠0, returns NULL if any argument is NULL or non-numerical.
|
|
9
|
+
*/
|
|
10
|
+
export declare class QtiGcd extends QtiExpression<number | null> {
|
|
11
|
+
#private;
|
|
12
|
+
getResult(): number | null;
|
|
13
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { QtiExpression } from '@qti-components/base';
|
|
2
|
+
/**
|
|
3
|
+
* @summary The qti-gcd operator calculates the greatest common divisor of integer values.
|
|
4
|
+
* @documentation https://www.imsglobal.org/spec/qti/v3p0/impl#h.gcd
|
|
5
|
+
*
|
|
6
|
+
* Takes 1 or more sub-expressions with base-type integer and any cardinality.
|
|
7
|
+
* Returns a single integer equal to the greatest common divisor of all argument values.
|
|
8
|
+
* Special cases: gcd(0,0)=0, gcd(0,n)=n if n≠0, returns NULL if any argument is NULL or non-numerical.
|
|
9
|
+
*/
|
|
10
|
+
export class QtiGcd extends QtiExpression {
|
|
11
|
+
getResult() {
|
|
12
|
+
if (this.children.length === 0) {
|
|
13
|
+
console.error('qti-gcd must have at least one child expression');
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
const variables = this.getVariables();
|
|
17
|
+
if (!variables || variables.length === 0) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
// Collect all integer values from all variables
|
|
21
|
+
const allValues = [];
|
|
22
|
+
for (const variable of variables) {
|
|
23
|
+
// Check base type
|
|
24
|
+
if (variable.baseType !== 'integer') {
|
|
25
|
+
console.error('qti-gcd requires integer base-type');
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
// Handle null values
|
|
29
|
+
if (variable.value === null || variable.value === undefined) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
// Handle different cardinalities
|
|
33
|
+
if (variable.cardinality === 'single') {
|
|
34
|
+
if (Array.isArray(variable.value)) {
|
|
35
|
+
console.error('qti-gcd unexpected array value for single cardinality');
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const numValue = parseInt(variable.value, 10);
|
|
39
|
+
if (isNaN(numValue)) {
|
|
40
|
+
console.error('qti-gcd non-numerical value');
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
allValues.push(numValue);
|
|
44
|
+
}
|
|
45
|
+
else if (variable.cardinality === 'multiple' || variable.cardinality === 'ordered') {
|
|
46
|
+
if (!Array.isArray(variable.value)) {
|
|
47
|
+
console.error('qti-gcd expected array value for multiple/ordered cardinality');
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
for (const value of variable.value) {
|
|
51
|
+
if (value === null || value === undefined) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
const numValue = parseInt(value, 10);
|
|
55
|
+
if (isNaN(numValue)) {
|
|
56
|
+
console.error('qti-gcd non-numerical value');
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
allValues.push(numValue);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
console.error('qti-gcd unsupported cardinality');
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (allValues.length === 0) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
// Calculate GCD of all values
|
|
71
|
+
return this.#calculateGcd(allValues);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Calculate the greatest common divisor of an array of integers
|
|
75
|
+
*/
|
|
76
|
+
#calculateGcd(values) {
|
|
77
|
+
if (values.length === 0) {
|
|
78
|
+
return 0;
|
|
79
|
+
}
|
|
80
|
+
if (values.length === 1) {
|
|
81
|
+
return Math.abs(values[0]);
|
|
82
|
+
}
|
|
83
|
+
// Start with the first value
|
|
84
|
+
let result = Math.abs(values[0]);
|
|
85
|
+
// Calculate GCD with each subsequent value
|
|
86
|
+
for (let i = 1; i < values.length; i++) {
|
|
87
|
+
result = this.#gcdTwoNumbers(result, Math.abs(values[i]));
|
|
88
|
+
// Early termination: if GCD becomes 1, it won't get smaller
|
|
89
|
+
if (result === 1) {
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Calculate GCD of two numbers using Euclidean algorithm
|
|
97
|
+
*/
|
|
98
|
+
#gcdTwoNumbers(a, b) {
|
|
99
|
+
// Handle special cases according to QTI spec
|
|
100
|
+
if (a === 0 && b === 0) {
|
|
101
|
+
return 0; // gcd(0,0) = 0
|
|
102
|
+
}
|
|
103
|
+
if (a === 0) {
|
|
104
|
+
return b; // gcd(0,n) = n
|
|
105
|
+
}
|
|
106
|
+
if (b === 0) {
|
|
107
|
+
return a; // gcd(n,0) = n
|
|
108
|
+
}
|
|
109
|
+
// Euclidean algorithm
|
|
110
|
+
while (b !== 0) {
|
|
111
|
+
const temp = b;
|
|
112
|
+
b = a % b;
|
|
113
|
+
a = temp;
|
|
114
|
+
}
|
|
115
|
+
return a;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
customElements.define('qti-gcd', QtiGcd);
|
|
119
|
+
//# sourceMappingURL=qti.gcd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qti.gcd.js","sourceRoot":"","sources":["../../../src/components/qti-gcd/qti.gcd.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAIrD;;;;;;;GAOG;AACH,MAAM,OAAO,MAAO,SAAQ,aAA4B;IACtC,SAAS;QACvB,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC/B,OAAO,CAAC,KAAK,CAAC,iDAAiD,CAAC,CAAC;YACjE,OAAO,IAAI,CAAC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CAA2C;QAC3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACvC,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAE1D,4DAA4D;YAC5D,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC;gBACjB,MAAM;YACR,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACH,cAAc,CAAC,CAAS,EAAE,CAAS;QACjC,6CAA6C;QAC7C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,OAAO,CAAC,CAAC,CAAC,eAAe;QAC3B,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACZ,OAAO,CAAC,CAAC,CAAC,eAAe;QAC3B,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACZ,OAAO,CAAC,CAAC,CAAC,eAAe;QAC3B,CAAC;QAED,sBAAsB;QACtB,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACf,MAAM,IAAI,GAAG,CAAC,CAAC;YACf,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACV,CAAC,GAAG,IAAI,CAAC;QACX,CAAC;QAED,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AAED,cAAc,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC","sourcesContent":["import { QtiExpression } from '@qti-components/base';\n\nimport type { ResponseVariable } from '@qti-components/base';\n\n/**\n * @summary The qti-gcd operator calculates the greatest common divisor of integer values.\n * @documentation https://www.imsglobal.org/spec/qti/v3p0/impl#h.gcd\n *\n * Takes 1 or more sub-expressions with base-type integer and any cardinality.\n * Returns a single integer equal to the greatest common divisor of all argument values.\n * Special cases: gcd(0,0)=0, gcd(0,n)=n if n≠0, returns NULL if any argument is NULL or non-numerical.\n */\nexport class QtiGcd extends QtiExpression<number | null> {\n public override getResult(): number | null {\n if (this.children.length === 0) {\n console.error('qti-gcd must have at least one child expression');\n return null;\n }\n\n const variables = this.getVariables() as ResponseVariable[];\n if (!variables || variables.length === 0) {\n return null;\n }\n\n // Collect all integer values from all variables\n const allValues: number[] = [];\n\n for (const variable of variables) {\n // Check base type\n if (variable.baseType !== 'integer') {\n console.error('qti-gcd requires integer base-type');\n return null;\n }\n\n // Handle null values\n if (variable.value === null || variable.value === undefined) {\n return null;\n }\n\n // Handle different cardinalities\n if (variable.cardinality === 'single') {\n if (Array.isArray(variable.value)) {\n console.error('qti-gcd unexpected array value for single cardinality');\n return null;\n }\n const numValue = parseInt(variable.value as string, 10);\n if (isNaN(numValue)) {\n console.error('qti-gcd non-numerical value');\n return null;\n }\n allValues.push(numValue);\n } else if (variable.cardinality === 'multiple' || variable.cardinality === 'ordered') {\n if (!Array.isArray(variable.value)) {\n console.error('qti-gcd expected array value for multiple/ordered cardinality');\n return null;\n }\n for (const value of variable.value) {\n if (value === null || value === undefined) {\n return null;\n }\n const numValue = parseInt(value as string, 10);\n if (isNaN(numValue)) {\n console.error('qti-gcd non-numerical value');\n return null;\n }\n allValues.push(numValue);\n }\n } else {\n console.error('qti-gcd unsupported cardinality');\n return null;\n }\n }\n\n if (allValues.length === 0) {\n return null;\n }\n\n // Calculate GCD of all values\n return this.#calculateGcd(allValues);\n }\n\n /**\n * Calculate the greatest common divisor of an array of integers\n */\n #calculateGcd(values: number[]): number {\n if (values.length === 0) {\n return 0;\n }\n\n if (values.length === 1) {\n return Math.abs(values[0]);\n }\n\n // Start with the first value\n let result = Math.abs(values[0]);\n\n // Calculate GCD with each subsequent value\n for (let i = 1; i < values.length; i++) {\n result = this.#gcdTwoNumbers(result, Math.abs(values[i]));\n\n // Early termination: if GCD becomes 1, it won't get smaller\n if (result === 1) {\n break;\n }\n }\n\n return result;\n }\n\n /**\n * Calculate GCD of two numbers using Euclidean algorithm\n */\n #gcdTwoNumbers(a: number, b: number): number {\n // Handle special cases according to QTI spec\n if (a === 0 && b === 0) {\n return 0; // gcd(0,0) = 0\n }\n if (a === 0) {\n return b; // gcd(0,n) = n\n }\n if (b === 0) {\n return a; // gcd(n,0) = n\n }\n\n // Euclidean algorithm\n while (b !== 0) {\n const temp = b;\n b = a % b;\n a = temp;\n }\n\n return a;\n }\n}\n\ncustomElements.define('qti-gcd', QtiGcd);\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { QtiExpression } from '@qti-components/base';
|
|
2
|
+
export class QtiGt extends QtiExpression {
|
|
3
|
+
getResult() {
|
|
4
|
+
if (this.children.length === 2) {
|
|
5
|
+
const values = this.getVariables();
|
|
6
|
+
const value1 = values[0];
|
|
7
|
+
const value2 = values[1];
|
|
8
|
+
if ((value1.baseType === 'integer' || value1.baseType === 'float') &&
|
|
9
|
+
(value2.baseType === 'integer' || value2.baseType === 'float')) {
|
|
10
|
+
return +value1.value > +value2.value;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
console.error('unexpected baseType or cardinality in qti gt');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
console.error('unexpected number of children in qt');
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
customElements.define('qti-gt', QtiGt);
|
|
21
|
+
//# sourceMappingURL=qti-gt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qti-gt.js","sourceRoot":"","sources":["../../../src/components/qti-gt/qti-gt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAIrD,MAAM,OAAO,KAAM,SAAQ,aAAsB;IAC/B,SAAS;QACvB,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,EAAwB,CAAC;YACzD,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YACzB,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YACzB,IACE,CAAC,MAAM,CAAC,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,KAAK,OAAO,CAAC;gBAC9D,CAAC,MAAM,CAAC,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,KAAK,OAAO,CAAC,EAC9D,CAAC;gBACD,OAAO,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC;YACvC,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CAAC,8CAA8C,CAAC,CAAC;YAChE,CAAC;QACH,CAAC;QACD,OAAO,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC;QACrD,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,cAAc,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC","sourcesContent":["import { QtiExpression } from '@qti-components/base';\n\nimport type { ResponseVariable } from '@qti-components/base';\n\nexport class QtiGt extends QtiExpression<boolean> {\n public override getResult(): boolean {\n if (this.children.length === 2) {\n const values = this.getVariables() as ResponseVariable[];\n const value1 = values[0];\n const value2 = values[1];\n if (\n (value1.baseType === 'integer' || value1.baseType === 'float') &&\n (value2.baseType === 'integer' || value2.baseType === 'float')\n ) {\n return +value1.value > +value2.value;\n } else {\n console.error('unexpected baseType or cardinality in qti gt');\n }\n }\n console.error('unexpected number of children in qt');\n return null;\n }\n}\n\ncustomElements.define('qti-gt', QtiGt);\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { QtiConditionExpression } from '@qti-components/base';
|
|
2
|
+
// PK: For the contains we assume the expressions to calculate are all directedPairs
|
|
3
|
+
// I don't know it this in QTI is always the case however?
|
|
4
|
+
export class QtiGte extends QtiConditionExpression {
|
|
5
|
+
getResult() {
|
|
6
|
+
if (this.children.length === 2) {
|
|
7
|
+
const values = this.getVariables();
|
|
8
|
+
const value1 = values[0];
|
|
9
|
+
const value2 = values[1];
|
|
10
|
+
if ((value1.baseType === 'integer' || value1.baseType === 'float') &&
|
|
11
|
+
(value2.baseType === 'integer' || value2.baseType === 'float')) {
|
|
12
|
+
return +value1.value >= +value2.value;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
console.error('unexpected baseType or cardinality in qti gte');
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
console.log('unexpected number of children in qte');
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
customElements.define('qti-gte', QtiGte);
|
|
24
|
+
//# sourceMappingURL=qti-gte.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qti-gte.js","sourceRoot":"","sources":["../../../src/components/qti-gte/qti-gte.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAI9D,oFAAoF;AACpF,0DAA0D;AAC1D,MAAM,OAAO,MAAO,SAAQ,sBAAsB;IAChC,SAAS;QACvB,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,EAAwB,CAAC;YACzD,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YACzB,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YACzB,IACE,CAAC,MAAM,CAAC,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,KAAK,OAAO,CAAC;gBAC9D,CAAC,MAAM,CAAC,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,KAAK,OAAO,CAAC,EAC9D,CAAC;gBACD,OAAO,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;YACxC,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAC;gBAC/D,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC;QACpD,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,cAAc,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC","sourcesContent":["import { QtiConditionExpression } from '@qti-components/base';\n\nimport type { ResponseVariable } from '@qti-components/base';\n\n// PK: For the contains we assume the expressions to calculate are all directedPairs\n// I don't know it this in QTI is always the case however?\nexport class QtiGte extends QtiConditionExpression {\n public override getResult(): boolean {\n if (this.children.length === 2) {\n const values = this.getVariables() as ResponseVariable[];\n const value1 = values[0];\n const value2 = values[1];\n if (\n (value1.baseType === 'integer' || value1.baseType === 'float') &&\n (value2.baseType === 'integer' || value2.baseType === 'float')\n ) {\n return +value1.value >= +value2.value;\n } else {\n console.error('unexpected baseType or cardinality in qti gte');\n return null;\n }\n }\n console.log('unexpected number of children in qte');\n return null;\n }\n}\n\ncustomElements.define('qti-gte', QtiGte);\n"]}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { customElement, property } from 'lit/decorators.js';
|
|
8
|
+
import { QtiExpression } from '@qti-components/base';
|
|
9
|
+
let QtiIndex = class QtiIndex extends QtiExpression {
|
|
10
|
+
getResult() {
|
|
11
|
+
if (!this.n) {
|
|
12
|
+
console.error('qti-index: missing required attribute "n"');
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
// Check if there is exactly one child
|
|
16
|
+
if (this.children.length !== 1) {
|
|
17
|
+
console.error('qti-index: must have exactly one child container element');
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
// Get the container from the child
|
|
21
|
+
const containerVariable = this.getVariables()[0];
|
|
22
|
+
if (!containerVariable) {
|
|
23
|
+
console.error('qti-index: missing container');
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
// Determine the index value - either from n as a direct number or by looking up identifier
|
|
27
|
+
let index;
|
|
28
|
+
if (!isNaN(Number(this.n))) {
|
|
29
|
+
// n is a direct number
|
|
30
|
+
index = Number(this.n);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
// n is an identifier - need to look up its value at runtime
|
|
34
|
+
// This would require access to the QTI runtime context to resolve variables
|
|
35
|
+
const variableValue = this.#lookupVariableValue(this.n);
|
|
36
|
+
if (variableValue === null) {
|
|
37
|
+
console.error(`qti-index: variable "${this.n}" is not a valid number`);
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
index = Number(variableValue);
|
|
41
|
+
}
|
|
42
|
+
// Check if index is a positive integer
|
|
43
|
+
if (index <= 0 || !Number.isInteger(index)) {
|
|
44
|
+
console.error('qti-index: index must be a positive integer');
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
// Check if container has ordered values
|
|
48
|
+
if (containerVariable.cardinality === 'ordered') {
|
|
49
|
+
const containerValues = Array.isArray(containerVariable.value)
|
|
50
|
+
? containerVariable.value
|
|
51
|
+
: [containerVariable.value];
|
|
52
|
+
// Index out of bounds or container is NULL
|
|
53
|
+
if (containerVariable.value === null || index > containerValues.length) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
// Return the nth value (index is 1-based)
|
|
57
|
+
return containerValues[index - 1];
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
console.error('qti-index: child must have ordered cardinality');
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// Helper method to look up a variable value by identifier
|
|
65
|
+
// This would need to be implemented based on your actual QTI runtime environment
|
|
66
|
+
#lookupVariableValue(identifier) {
|
|
67
|
+
const value = this.context.variables.find(v => v.identifier === identifier)?.value;
|
|
68
|
+
// check if value is a number
|
|
69
|
+
if (value === null || isNaN(Number(value))) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
return Number(value);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
__decorate([
|
|
76
|
+
property({ type: String })
|
|
77
|
+
], QtiIndex.prototype, "n", void 0);
|
|
78
|
+
QtiIndex = __decorate([
|
|
79
|
+
customElement('qti-index')
|
|
80
|
+
], QtiIndex);
|
|
81
|
+
export { QtiIndex };
|
|
82
|
+
//# sourceMappingURL=qti-index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qti-index.js","sourceRoot":"","sources":["../../../src/components/qti-index/qti-index.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAM9C,IAAM,QAAQ,GAAd,MAAM,QAAS,SAAQ,aAAkB;IAI9B,SAAS;QACvB,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;YACZ,OAAO,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;YAC3D,OAAO,IAAI,CAAC;QACd,CAAC;QAED,sCAAsC;QACtC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC/B,OAAO,CAAC,KAAK,CAAC,0DAA0D,CAAC,CAAC;YAC1E,OAAO,IAAI,CAAC;QACd,CAAC;QAED,mCAAmC;Q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,KAAK,IAAI,IAAI,KAAK,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC;gBACvE,OAAO,IAAI,CAAC;YACd,CAAC;YAED,0CAA0C;YAC1C,OAAO,eAAe,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QACpC,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,KAAK,CAAC,gDAAgD,CAAC,CAAC;YAChE,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,0DAA0D;IAC1D,iFAAiF;IACjF,oBAAoB,CAAC,UAAkB;QACrC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,UAAU,CAAC,EAAE,KAAK,CAAC;QACnF,6BAA6B;QAC7B,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YAC3C,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,MAAM,CAAC,KAAK,CAAY,CAAC;IAClC,CAAC;CACF,CAAA;AAzEC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;mCAChB;AAFA,QAAQ;IADpB,aAAa,CAAC,WAAW,CAAC;GACd,QAAQ,CA2EpB","sourcesContent":["import { customElement, property } from 'lit/decorators.js';\n\nimport { QtiExpression } from '@qti-components/base';\n\nimport type { integer } from '@qti-components/base';\nimport type { ResponseVariable } from '@qti-components/base';\n\n@customElement('qti-index')\nexport class QtiIndex extends QtiExpression<any> {\n @property({ type: String })\n n!: string; // Required attribute, can be a number or an identifier\n\n public override getResult(): any {\n if (!this.n) {\n console.error('qti-index: missing required attribute \"n\"');\n return null;\n }\n\n // Check if there is exactly one child\n if (this.children.length !== 1) {\n console.error('qti-index: must have exactly one child container element');\n return null;\n }\n\n // Get the container from the child\n const containerVariable = this.getVariables()[0] as ResponseVariable;\n if (!containerVariable) {\n console.error('qti-index: missing container');\n return null;\n }\n\n // Determine the index value - either from n as a direct number or by looking up identifier\n let index: number;\n\n if (!isNaN(Number(this.n))) {\n // n is a direct number\n index = Number(this.n);\n } else {\n // n is an identifier - need to look up its value at runtime\n // This would require access to the QTI runtime context to resolve variables\n const variableValue = this.#lookupVariableValue(this.n);\n if (variableValue === null) {\n console.error(`qti-index: variable \"${this.n}\" is not a valid number`);\n return null;\n }\n index = Number(variableValue);\n }\n\n // Check if index is a positive integer\n if (index <= 0 || !Number.isInteger(index)) {\n console.error('qti-index: index must be a positive integer');\n return null;\n }\n\n // Check if container has ordered values\n if (containerVariable.cardinality === 'ordered') {\n const containerValues = Array.isArray(containerVariable.value)\n ? containerVariable.value\n : [containerVariable.value];\n\n // Index out of bounds or container is NULL\n if (containerVariable.value === null || index > containerValues.length) {\n return null;\n }\n\n // Return the nth value (index is 1-based)\n return containerValues[index - 1];\n } else {\n console.error('qti-index: child must have ordered cardinality');\n return null;\n }\n }\n\n // Helper method to look up a variable value by identifier\n // This would need to be implemented based on your actual QTI runtime environment\n #lookupVariableValue(identifier: string): integer | null {\n const value = this.context.variables.find(v => v.identifier === identifier)?.value;\n // check if value is a number\n if (value === null || isNaN(Number(value))) {\n return null;\n }\n return Number(value) as integer;\n }\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { QtiExpression } from '@qti-components/base';
|
|
2
|
+
// PK: For the contains we assume the expressions to calculate are all directedPairs
|
|
3
|
+
// I don't know it this in QTI is always the case however?
|
|
4
|
+
export class QtiIsNull extends QtiExpression {
|
|
5
|
+
getResult() {
|
|
6
|
+
if (this.children.length === 1) {
|
|
7
|
+
const variables = this.getVariables();
|
|
8
|
+
if (!variables) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
const value = variables[0].value;
|
|
12
|
+
return value == null || value == undefined || value === '';
|
|
13
|
+
}
|
|
14
|
+
console.error('unexpected number of children in qti Null');
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
customElements.define('qti-is-null', QtiIsNull);
|
|
19
|
+
//# sourceMappingURL=qti-is-null.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qti-is-null.js","sourceRoot":"","sources":["../../../src/components/qti-is-null/qti-is-null.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAIrD,oFAAoF;AACpF,0DAA0D;AAC1D,MAAM,OAAO,SAAU,SAAQ,aAAsB;IACnC,SAAS;QACvB,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC/B,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,EAAwB,CAAC;YAC5D,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,OAAO,IAAI,CAAC;YACd,CAAC;YACD,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;YACjC,OAAO,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI,SAAS,IAAI,KAAK,KAAK,EAAE,CAAC;QAC7D,CAAC;QACD,OAAO,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC3D,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,cAAc,CAAC,MAAM,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC","sourcesContent":["import { QtiExpression } from '@qti-components/base';\n\nimport type { ResponseVariable } from '@qti-components/base';\n\n// PK: For the contains we assume the expressions to calculate are all directedPairs\n// I don't know it this in QTI is always the case however?\nexport class QtiIsNull extends QtiExpression<boolean> {\n public override getResult(): boolean {\n if (this.children.length === 1) {\n const variables = this.getVariables() as ResponseVariable[];\n if (!variables) {\n return true;\n }\n const value = variables[0].value;\n return value == null || value == undefined || value === '';\n }\n console.error('unexpected number of children in qti Null');\n return null;\n }\n}\n\ncustomElements.define('qti-is-null', QtiIsNull);\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { QtiRule } from '../qti-rule/qti-rule';
|
|
2
|
+
import type { QtiExpression } from '@qti-components/base';
|
|
3
|
+
import type { ItemContext } from '@qti-components/base';
|
|
4
|
+
/**
|
|
5
|
+
* The lookupOutcomeValue rule sets the value of an outcome variable to the value obtained
|
|
6
|
+
* by looking up the value of the associated expression in the lookupTable associated
|
|
7
|
+
* with the outcome's declaration.
|
|
8
|
+
*/
|
|
9
|
+
export declare class QtiLookupOutcomeValue extends QtiRule {
|
|
10
|
+
identifier: string;
|
|
11
|
+
protected context?: ItemContext;
|
|
12
|
+
get childExpression(): QtiExpression<string>;
|
|
13
|
+
process(): number;
|
|
14
|
+
}
|
|
15
|
+
declare global {
|
|
16
|
+
interface HTMLElementTagNameMap {
|
|
17
|
+
'qti-lookup-outcome-value': QtiLookupOutcomeValue;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { property, state } from 'lit/decorators.js';
|
|
8
|
+
import { consume } from '@lit/context';
|
|
9
|
+
import { convertNumberToUniversalFormat } from '@qti-components/base';
|
|
10
|
+
import { itemContext } from '@qti-components/base';
|
|
11
|
+
import { QtiRule } from '../qti-rule/qti-rule';
|
|
12
|
+
/**
|
|
13
|
+
* The lookupOutcomeValue rule sets the value of an outcome variable to the value obtained
|
|
14
|
+
* by looking up the value of the associated expression in the lookupTable associated
|
|
15
|
+
* with the outcome's declaration.
|
|
16
|
+
*/
|
|
17
|
+
export class QtiLookupOutcomeValue extends QtiRule {
|
|
18
|
+
get childExpression() {
|
|
19
|
+
return this.firstElementChild;
|
|
20
|
+
}
|
|
21
|
+
process() {
|
|
22
|
+
const identifier = this.getAttribute('identifier');
|
|
23
|
+
const outcomeVariable = this.context.variables.find(v => v.identifier === identifier) || null;
|
|
24
|
+
let value;
|
|
25
|
+
if (outcomeVariable.interpolationTable) {
|
|
26
|
+
value = outcomeVariable.interpolationTable.get(parseFloat(this.childExpression.calculate()));
|
|
27
|
+
}
|
|
28
|
+
if (value === null || value === undefined) {
|
|
29
|
+
console.warn('lookupOutcomeValue: value is null or undefined');
|
|
30
|
+
return 0;
|
|
31
|
+
}
|
|
32
|
+
this.dispatchEvent(new CustomEvent('qti-set-outcome-value', {
|
|
33
|
+
bubbles: true,
|
|
34
|
+
composed: true,
|
|
35
|
+
detail: {
|
|
36
|
+
outcomeIdentifier: this.identifier,
|
|
37
|
+
value: convertNumberToUniversalFormat(value)
|
|
38
|
+
}
|
|
39
|
+
}));
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
__decorate([
|
|
44
|
+
property({ type: String })
|
|
45
|
+
], QtiLookupOutcomeValue.prototype, "identifier", void 0);
|
|
46
|
+
__decorate([
|
|
47
|
+
consume({ context: itemContext, subscribe: true }),
|
|
48
|
+
state()
|
|
49
|
+
], QtiLookupOutcomeValue.prototype, "context", void 0);
|
|
50
|
+
customElements.define('qti-lookup-outcome-value', QtiLookupOutcomeValue);
|
|
51
|
+
//# sourceMappingURL=qti-lookup-outcome-value.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qti-lookup-outcome-value.js","sourceRoot":"","sources":["../../../src/components/qti-lookup-outcome-value/qti-lookup-outcome-value.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC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EAAE,MAAM,EAAE,CAAC;yDAAoB;AAIrC;IAFT,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAClD,KAAK,EAAE;sDACwB;AAiClC,cAAc,CAAC,MAAM,CAAC,0BAA0B,EAAE,qBAAqB,CAAC,CAAC","sourcesContent":["import { property, state } from 'lit/decorators.js';\nimport { consume } from '@lit/context';\n\nimport { convertNumberToUniversalFormat } from '@qti-components/base';\nimport { itemContext } from '@qti-components/base';\n\nimport { QtiRule } from '../qti-rule/qti-rule';\n\nimport type { QtiExpression } from '@qti-components/base';\nimport type { OutcomeVariable } from '@qti-components/base';\nimport type { ItemContext } from '@qti-components/base';\n\n/**\n * The lookupOutcomeValue rule sets the value of an outcome variable to the value obtained\n * by looking up the value of the associated expression in the lookupTable associated\n * with the outcome's declaration.\n */\nexport class QtiLookupOutcomeValue extends QtiRule {\n @property({ type: String }) identifier: string;\n\n @consume({ context: itemContext, subscribe: true })\n @state()\n protected context?: ItemContext;\n\n get childExpression(): QtiExpression<string> {\n return this.firstElementChild as QtiExpression<string>;\n }\n\n public override process(): number {\n const identifier = this.getAttribute('identifier');\n\n const outcomeVariable: OutcomeVariable | null =\n this.context.variables.find(v => v.identifier === identifier) || null;\n\n let value;\n if (outcomeVariable.interpolationTable) {\n value = outcomeVariable.interpolationTable.get(parseFloat(this.childExpression.calculate()));\n }\n if (value === null || value === undefined) {\n console.warn('lookupOutcomeValue: value is null or undefined');\n return 0;\n }\n this.dispatchEvent(\n new CustomEvent<{ outcomeIdentifier: string; value: string | string[] }>('qti-set-outcome-value', {\n bubbles: true,\n composed: true,\n detail: {\n outcomeIdentifier: this.identifier,\n value: convertNumberToUniversalFormat(value)\n }\n })\n );\n return value;\n }\n}\ncustomElements.define('qti-lookup-outcome-value', QtiLookupOutcomeValue);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-lookup-outcome-value': QtiLookupOutcomeValue;\n }\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { QtiExpression } from '@qti-components/base';
|
|
2
|
+
export class QtiLt extends QtiExpression {
|
|
3
|
+
getResult() {
|
|
4
|
+
if (this.children.length === 2) {
|
|
5
|
+
const values = this.getVariables();
|
|
6
|
+
const value1 = values[0];
|
|
7
|
+
const value2 = values[1];
|
|
8
|
+
if ((value1.baseType === 'integer' || value1.baseType === 'float') &&
|
|
9
|
+
(value2.baseType === 'integer' || value2.baseType === 'float')) {
|
|
10
|
+
return +value1.value < +value2.value;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
console.error('unexpected baseType or cardinality in qti lt');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
console.error('unexpected number of children in lt');
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
customElements.define('qti-lt', QtiLt);
|
|
21
|
+
//# sourceMappingURL=qti-lt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qti-lt.js","sourceRoot":"","sources":["../../../src/components/qti-lt/qti-lt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAIrD,MAAM,OAAO,KAAM,SAAQ,aAAsB;IAC/B,SAAS;QACvB,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,EAAwB,CAAC;YACzD,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YACzB,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YACzB,IACE,CAAC,MAAM,CAAC,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,KAAK,OAAO,CAAC;gBAC9D,CAAC,MAAM,CAAC,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,KAAK,OAAO,CAAC,EAC9D,CAAC;gBACD,OAAO,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC;YACvC,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CAAC,8CAA8C,CAAC,CAAC;YAChE,CAAC;QACH,CAAC;QACD,OAAO,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC;QACrD,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,cAAc,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC","sourcesContent":["import { QtiExpression } from '@qti-components/base';\n\nimport type { ResponseVariable } from '@qti-components/base';\n\nexport class QtiLt extends QtiExpression<boolean> {\n public override getResult(): boolean {\n if (this.children.length === 2) {\n const values = this.getVariables() as ResponseVariable[];\n const value1 = values[0];\n const value2 = values[1];\n if (\n (value1.baseType === 'integer' || value1.baseType === 'float') &&\n (value2.baseType === 'integer' || value2.baseType === 'float')\n ) {\n return +value1.value < +value2.value;\n } else {\n console.error('unexpected baseType or cardinality in qti lt');\n }\n }\n console.error('unexpected number of children in lt');\n return null;\n }\n}\n\ncustomElements.define('qti-lt', QtiLt);\n"]}
|