@qti-components/processing 1.3.1 → 1.3.3

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 (112) hide show
  1. package/dist/components/index.d.ts +18 -0
  2. package/dist/components/index.js +18 -0
  3. package/dist/components/index.js.map +1 -1
  4. package/dist/components/qti-and/qti-and.d.ts +8 -0
  5. package/dist/components/qti-and/qti-and.js +8 -0
  6. package/dist/components/qti-and/qti-and.js.map +1 -1
  7. package/dist/components/qti-any-n/qti-any-n.d.ts +15 -0
  8. package/dist/components/qti-any-n/qti-any-n.js +61 -0
  9. package/dist/components/qti-any-n/qti-any-n.js.map +1 -0
  10. package/dist/components/qti-container-size/qti-container-size.d.ts +5 -5
  11. package/dist/components/qti-container-size/qti-container-size.js +5 -5
  12. package/dist/components/qti-container-size/qti-container-size.js.map +1 -1
  13. package/dist/components/qti-correct/qti-correct.d.ts +8 -0
  14. package/dist/components/qti-correct/qti-correct.js +8 -0
  15. package/dist/components/qti-correct/qti-correct.js.map +1 -1
  16. package/dist/components/qti-default/qti-default.d.ts +5 -5
  17. package/dist/components/qti-default/qti-default.js +5 -5
  18. package/dist/components/qti-default/qti-default.js.map +1 -1
  19. package/dist/components/qti-delete/qti-delete.d.ts +8 -0
  20. package/dist/components/qti-delete/qti-delete.js +8 -0
  21. package/dist/components/qti-delete/qti-delete.js.map +1 -1
  22. package/dist/components/qti-divide/qti-divide.d.ts +13 -0
  23. package/dist/components/qti-divide/qti-divide.js +50 -0
  24. package/dist/components/qti-divide/qti-divide.js.map +1 -0
  25. package/dist/components/qti-duration-gte/qti-duration-gte.d.ts +5 -0
  26. package/dist/components/qti-duration-gte/qti-duration-gte.js +45 -0
  27. package/dist/components/qti-duration-gte/qti-duration-gte.js.map +1 -0
  28. package/dist/components/qti-duration-lt/qti-duration-lt.d.ts +13 -0
  29. package/dist/components/qti-duration-lt/qti-duration-lt.js +53 -0
  30. package/dist/components/qti-duration-lt/qti-duration-lt.js.map +1 -0
  31. package/dist/components/qti-equal/qti-equal.d.ts +9 -0
  32. package/dist/components/qti-equal/qti-equal.js +15 -0
  33. package/dist/components/qti-equal/qti-equal.js.map +1 -1
  34. package/dist/components/qti-equal-rounded/qti-equal-rounded.d.ts +9 -0
  35. package/dist/components/qti-equal-rounded/qti-equal-rounded.js +9 -0
  36. package/dist/components/qti-equal-rounded/qti-equal-rounded.js.map +1 -1
  37. package/dist/components/qti-field-value/qti-field-value.d.ts +8 -0
  38. package/dist/components/qti-field-value/qti-field-value.js +8 -0
  39. package/dist/components/qti-field-value/qti-field-value.js.map +1 -1
  40. package/dist/components/qti-index/qti-index.d.ts +8 -0
  41. package/dist/components/qti-index/qti-index.js +8 -0
  42. package/dist/components/qti-index/qti-index.js.map +1 -1
  43. package/dist/components/qti-inside/qti-inside.d.ts +7 -0
  44. package/dist/components/qti-inside/qti-inside.js +141 -0
  45. package/dist/components/qti-inside/qti-inside.js.map +1 -0
  46. package/dist/components/qti-integer-divide/qti-integer-divide.d.ts +13 -0
  47. package/dist/components/qti-integer-divide/qti-integer-divide.js +48 -0
  48. package/dist/components/qti-integer-divide/qti-integer-divide.js.map +1 -0
  49. package/dist/components/qti-integer-modulus/qti-integer-modulus.d.ts +13 -0
  50. package/dist/components/qti-integer-modulus/qti-integer-modulus.js +48 -0
  51. package/dist/components/qti-integer-modulus/qti-integer-modulus.js.map +1 -0
  52. package/dist/components/qti-integer-to-float/qti-integer-to-float.d.ts +12 -0
  53. package/dist/components/qti-integer-to-float/qti-integer-to-float.js +38 -0
  54. package/dist/components/qti-integer-to-float/qti-integer-to-float.js.map +1 -0
  55. package/dist/components/qti-is-null/qti-is-null.d.ts +8 -0
  56. package/dist/components/qti-is-null/qti-is-null.js +8 -2
  57. package/dist/components/qti-is-null/qti-is-null.js.map +1 -1
  58. package/dist/components/qti-lcm/qti-lcm.d.ts +5 -0
  59. package/dist/components/qti-lcm/qti-lcm.js +71 -0
  60. package/dist/components/qti-lcm/qti-lcm.js.map +1 -0
  61. package/dist/components/qti-map-response/qti-map-response.d.ts +8 -0
  62. package/dist/components/qti-map-response/qti-map-response.js +8 -0
  63. package/dist/components/qti-map-response/qti-map-response.js.map +1 -1
  64. package/dist/components/qti-match/qti-match.d.ts +8 -0
  65. package/dist/components/qti-match/qti-match.js +8 -0
  66. package/dist/components/qti-match/qti-match.js.map +1 -1
  67. package/dist/components/qti-max/qti-max.d.ts +13 -0
  68. package/dist/components/qti-max/qti-max.js +46 -0
  69. package/dist/components/qti-max/qti-max.js.map +1 -0
  70. package/dist/components/qti-min/qti-min.d.ts +13 -0
  71. package/dist/components/qti-min/qti-min.js +46 -0
  72. package/dist/components/qti-min/qti-min.js.map +1 -0
  73. package/dist/components/qti-not/qti-not.d.ts +8 -0
  74. package/dist/components/qti-not/qti-not.js +8 -0
  75. package/dist/components/qti-not/qti-not.js.map +1 -1
  76. package/dist/components/qti-or/qti-or.d.ts +8 -0
  77. package/dist/components/qti-or/qti-or.js +8 -0
  78. package/dist/components/qti-or/qti-or.js.map +1 -1
  79. package/dist/components/qti-pattern-match/qti-pattern-match.d.ts +13 -0
  80. package/dist/components/qti-pattern-match/qti-pattern-match.js +53 -0
  81. package/dist/components/qti-pattern-match/qti-pattern-match.js.map +1 -0
  82. package/dist/components/qti-product/qti-product.d.ts +8 -0
  83. package/dist/components/qti-product/qti-product.js +8 -0
  84. package/dist/components/qti-product/qti-product.js.map +1 -1
  85. package/dist/components/qti-repeat/qti-repeat.d.ts +15 -0
  86. package/dist/components/qti-repeat/qti-repeat.js +113 -0
  87. package/dist/components/qti-repeat/qti-repeat.js.map +1 -0
  88. package/dist/components/qti-round/qti-round.d.ts +4 -5
  89. package/dist/components/qti-round/qti-round.js +4 -5
  90. package/dist/components/qti-round/qti-round.js.map +1 -1
  91. package/dist/components/qti-set-correct-response/qti-set-correct-response.d.ts +24 -0
  92. package/dist/components/qti-set-correct-response/qti-set-correct-response.js +77 -0
  93. package/dist/components/qti-set-correct-response/qti-set-correct-response.js.map +1 -0
  94. package/dist/components/qti-set-template-value/qti-set-template-value.d.ts +24 -0
  95. package/dist/components/qti-set-template-value/qti-set-template-value.js +81 -0
  96. package/dist/components/qti-set-template-value/qti-set-template-value.js.map +1 -0
  97. package/dist/components/qti-stats-operator/qti-stats-operator.d.ts +15 -0
  98. package/dist/components/qti-stats-operator/qti-stats-operator.js +78 -0
  99. package/dist/components/qti-stats-operator/qti-stats-operator.js.map +1 -0
  100. package/dist/components/qti-substring/qti-substring.d.ts +13 -0
  101. package/dist/components/qti-substring/qti-substring.js +51 -0
  102. package/dist/components/qti-substring/qti-substring.js.map +1 -0
  103. package/dist/components/qti-subtract/qti-subtract.d.ts +8 -0
  104. package/dist/components/qti-subtract/qti-subtract.js +8 -0
  105. package/dist/components/qti-subtract/qti-subtract.js.map +1 -1
  106. package/dist/components/qti-sum/qti-sum.d.ts +8 -0
  107. package/dist/components/qti-sum/qti-sum.js +8 -0
  108. package/dist/components/qti-sum/qti-sum.js.map +1 -1
  109. package/dist/components/qti-truncate/qti-truncate.d.ts +12 -0
  110. package/dist/components/qti-truncate/qti-truncate.js +38 -0
  111. package/dist/components/qti-truncate/qti-truncate.js.map +1 -0
  112. package/package.json +4 -4
@@ -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 } from 'lit/decorators.js';
8
+ import { QtiExpression } from '@qti-components/base';
9
+ /**
10
+ * @summary The qti-substring operator checks if one string is contained within another.
11
+ * @documentation https://www.imsglobal.org/spec/qti/v3p0/info/index.html#substring
12
+ *
13
+ * Takes 2 sub-expressions with base-type string and single cardinality.
14
+ * Returns true if the first string is a substring of the second.
15
+ * Special cases: Returns NULL if either argument is NULL.
16
+ */
17
+ export class QtiSubstring extends QtiExpression {
18
+ constructor() {
19
+ super(...arguments);
20
+ this.caseSensitive = 'true';
21
+ }
22
+ getResult() {
23
+ const variables = this.getVariables();
24
+ if (variables.length !== 2) {
25
+ console.error('qti-substring requires exactly 2 child expressions');
26
+ return null;
27
+ }
28
+ const [needle, haystack] = variables;
29
+ if (needle.cardinality !== 'single' ||
30
+ haystack.cardinality !== 'single' ||
31
+ Array.isArray(needle.value) ||
32
+ Array.isArray(haystack.value)) {
33
+ console.error('qti-substring requires single cardinality');
34
+ return null;
35
+ }
36
+ if (needle.value === null || haystack.value === null || needle.value === undefined || haystack.value === undefined) {
37
+ return null;
38
+ }
39
+ const left = needle.value.toString();
40
+ const right = haystack.value.toString();
41
+ if (this.caseSensitive !== 'true') {
42
+ return right.toLowerCase().includes(left.toLowerCase());
43
+ }
44
+ return right.includes(left);
45
+ }
46
+ }
47
+ __decorate([
48
+ property({ type: String, attribute: 'case-sensitive' })
49
+ ], QtiSubstring.prototype, "caseSensitive", void 0);
50
+ customElements.define('qti-substring', QtiSubstring);
51
+ //# sourceMappingURL=qti-substring.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qti-substring.js","sourceRoot":"","sources":["../../../src/components/qti-substring/qti-substring.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAIrD;;;;;;;GAOG;AACH,MAAM,OAAO,YAAa,SAAQ,aAA6B;IAA/D;;QAC2D,kBAAa,GAAG,MAAM,CAAC;IAgClF,CAAC;IA9BiB,SAAS;QACvB,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,EAAwB,CAAC;QAE5D,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO,CAAC,KAAK,CAAC,oDAAoD,CAAC,CAAC;YACpE,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,SAAS,CAAC;QACrC,IACE,MAAM,CAAC,WAAW,KAAK,QAAQ;YAC/B,QAAQ,CAAC,WAAW,KAAK,QAAQ;YACjC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;YAC3B,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAC7B,CAAC;YACD,OAAO,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;YAC3D,OAAO,IAAI,CAAC;QACd,CAAC;QACD,IAAI,MAAM,CAAC,KAAK,KAAK,IAAI,IAAI,QAAQ,CAAC,KAAK,KAAK,IAAI,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,IAAI,QAAQ,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YACnH,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;QACxC,IAAI,IAAI,CAAC,aAAa,KAAK,MAAM,EAAE,CAAC;YAClC,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;QAC1D,CAAC;QAED,OAAO,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;CACF;AAhC0D;IAAxD,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,CAAC;mDAAwB;AAkClF,cAAc,CAAC,MAAM,CAAC,eAAe,EAAE,YAAY,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\n/**\n * @summary The qti-substring operator checks if one string is contained within another.\n * @documentation https://www.imsglobal.org/spec/qti/v3p0/info/index.html#substring\n *\n * Takes 2 sub-expressions with base-type string and single cardinality.\n * Returns true if the first string is a substring of the second.\n * Special cases: Returns NULL if either argument is NULL.\n */\nexport class QtiSubstring extends QtiExpression<boolean | null> {\n @property({ type: String, attribute: 'case-sensitive' }) caseSensitive = 'true';\n\n public override getResult(): boolean | null {\n const variables = this.getVariables() as ResponseVariable[];\n\n if (variables.length !== 2) {\n console.error('qti-substring requires exactly 2 child expressions');\n return null;\n }\n\n const [needle, haystack] = variables;\n if (\n needle.cardinality !== 'single' ||\n haystack.cardinality !== 'single' ||\n Array.isArray(needle.value) ||\n Array.isArray(haystack.value)\n ) {\n console.error('qti-substring requires single cardinality');\n return null;\n }\n if (needle.value === null || haystack.value === null || needle.value === undefined || haystack.value === undefined) {\n return null;\n }\n\n const left = needle.value.toString();\n const right = haystack.value.toString();\n if (this.caseSensitive !== 'true') {\n return right.toLowerCase().includes(left.toLowerCase());\n }\n\n return right.includes(left);\n }\n}\n\ncustomElements.define('qti-substring', QtiSubstring);\n"]}
@@ -5,6 +5,14 @@ declare const QtiSubtract_base: {
5
5
  calculateChildren(children: Array<MockQtiExpression<any>>): number;
6
6
  };
7
7
  } & Constructor<QtiExpression<number>>;
8
+ /**
9
+ * @summary The qti-subtract operator performs numerical subtraction.
10
+ * @documentation https://www.imsglobal.org/spec/qti/v3p0/info/index.html#subtract
11
+ *
12
+ * Takes exactly 2 sub-expressions with numerical base-types and single cardinality.
13
+ * Returns (first - second) as a float, or integer if both inputs are integers.
14
+ * Special cases: Returns NULL if either sub-expression is NULL.
15
+ */
8
16
  export declare class QtiSubtract extends QtiSubtract_base {
9
17
  getResult(): number;
10
18
  }
@@ -1,4 +1,12 @@
1
1
  import { QtiExpression } from '@qti-components/base';
2
+ /**
3
+ * @summary The qti-subtract operator performs numerical subtraction.
4
+ * @documentation https://www.imsglobal.org/spec/qti/v3p0/info/index.html#subtract
5
+ *
6
+ * Takes exactly 2 sub-expressions with numerical base-types and single cardinality.
7
+ * Returns (first - second) as a float, or integer if both inputs are integers.
8
+ * Special cases: Returns NULL if either sub-expression is NULL.
9
+ */
2
10
  export class QtiSubtract extends qtiSubtractMixin((QtiExpression)) {
3
11
  getResult() {
4
12
  // children can be a mix of qti-expression and qti-condition-expression
@@ -1 +1 @@
1
- {"version":3,"file":"qti-subtract.js","sourceRoot":"","sources":["../../../src/components/qti-subtract/qti-subtract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,MAAM,OAAO,WAAY,SAAQ,gBAAgB,CAAC,CAAA,aAAmE,CAAA,CAAC;IACpG,SAAS;QACvB,uEAAuE;QACvE,MAAM,KAAK,GAAG,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAA2C,CAAC,CAAC,CAAC;QACnG,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAKD,MAAM,UAAU,gBAAgB,CAAgC,IAAW;IACzE,OAAO,MAAM,eAAgB,SAAQ,IAAI;QAChC,iBAAiB,CAAC,QAAuC;YAC9D,uEAAuE;YACvE,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;gBACvC,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC;oBAC1B,OAAO,CAAC,KAAK,CAAC,kDAAkD,CAAC,CAAC;oBAClE,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,MAAM,KAAK,GAAG,UAAU,CAAC,SAAS,EAAE,CAAC;gBACrC,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;oBACxB,OAAO,CAAC,KAAK,CAAC,mDAAmD,CAAC,CAAC;oBACnE,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;YACvB,CAAC,CAAC,CAAC;YACH,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,EAAE,CAAC;gBACzC,OAAO,CAAC,KAAK,CAAC,uDAAuD,CAAC,CAAC;gBACvE,OAAO,CAAC,CAAC;YACX,CAAC;YACD,0BAA0B;YAC1B,OAAO,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QAC/B,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { QtiExpression } from '@qti-components/base';\n\ntype Constructor<T> = new (...args: any[]) => T;\nexport class QtiSubtract extends qtiSubtractMixin(QtiExpression<any> as unknown as Constructor<QtiExpression<number>>) {\n public override getResult() {\n // children can be a mix of qti-expression and qti-condition-expression\n const value = this.calculateChildren(Array.from(this.children as unknown as QtiExpression<any>[]));\n return value;\n }\n}\n\ntype MockQtiExpression<T> = { calculate: () => T };\ntype MockConstructor = new (...args: any[]) => {};\n\nexport function qtiSubtractMixin<TBase extends MockConstructor>(Base: TBase) {\n return class MockQtiSubtract extends Base {\n public calculateChildren(children: Array<MockQtiExpression<any>>) {\n // children can be a mix of qti-expression and qti-condition-expression\n const values = children.map(expression => {\n if (!expression.calculate) {\n console.error(\"Element doesn't implement QtiConditionExpression\");\n return null;\n }\n const value = expression.calculate();\n if (Number.isNaN(value)) {\n console.error('Unexpected value in qti-subtract, expected number');\n return null;\n }\n return Number(value);\n });\n if (values.some(value => value === null)) {\n console.error('One or more child expressions returned invalid values');\n return 0;\n }\n // Subtract the two values\n return values[0] - values[1];\n }\n };\n}\n"]}
1
+ {"version":3,"file":"qti-subtract.js","sourceRoot":"","sources":["../../../src/components/qti-subtract/qti-subtract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAIrD;;;;;;;GAOG;AACH,MAAM,OAAO,WAAY,SAAQ,gBAAgB,CAAC,CAAA,aAAmE,CAAA,CAAC;IACpG,SAAS;QACvB,uEAAuE;QACvE,MAAM,KAAK,GAAG,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAA2C,CAAC,CAAC,CAAC;QACnG,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAKD,MAAM,UAAU,gBAAgB,CAAgC,IAAW;IACzE,OAAO,MAAM,eAAgB,SAAQ,IAAI;QAChC,iBAAiB,CAAC,QAAuC;YAC9D,uEAAuE;YACvE,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;gBACvC,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC;oBAC1B,OAAO,CAAC,KAAK,CAAC,kDAAkD,CAAC,CAAC;oBAClE,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,MAAM,KAAK,GAAG,UAAU,CAAC,SAAS,EAAE,CAAC;gBACrC,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;oBACxB,OAAO,CAAC,KAAK,CAAC,mDAAmD,CAAC,CAAC;oBACnE,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;YACvB,CAAC,CAAC,CAAC;YACH,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,EAAE,CAAC;gBACzC,OAAO,CAAC,KAAK,CAAC,uDAAuD,CAAC,CAAC;gBACvE,OAAO,CAAC,CAAC;YACX,CAAC;YACD,0BAA0B;YAC1B,OAAO,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QAC/B,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { QtiExpression } from '@qti-components/base';\n\ntype Constructor<T> = new (...args: any[]) => T;\n\n/**\n * @summary The qti-subtract operator performs numerical subtraction.\n * @documentation https://www.imsglobal.org/spec/qti/v3p0/info/index.html#subtract\n *\n * Takes exactly 2 sub-expressions with numerical base-types and single cardinality.\n * Returns (first - second) as a float, or integer if both inputs are integers.\n * Special cases: Returns NULL if either sub-expression is NULL.\n */\nexport class QtiSubtract extends qtiSubtractMixin(QtiExpression<any> as unknown as Constructor<QtiExpression<number>>) {\n public override getResult() {\n // children can be a mix of qti-expression and qti-condition-expression\n const value = this.calculateChildren(Array.from(this.children as unknown as QtiExpression<any>[]));\n return value;\n }\n}\n\ntype MockQtiExpression<T> = { calculate: () => T };\ntype MockConstructor = new (...args: any[]) => {};\n\nexport function qtiSubtractMixin<TBase extends MockConstructor>(Base: TBase) {\n return class MockQtiSubtract extends Base {\n public calculateChildren(children: Array<MockQtiExpression<any>>) {\n // children can be a mix of qti-expression and qti-condition-expression\n const values = children.map(expression => {\n if (!expression.calculate) {\n console.error(\"Element doesn't implement QtiConditionExpression\");\n return null;\n }\n const value = expression.calculate();\n if (Number.isNaN(value)) {\n console.error('Unexpected value in qti-subtract, expected number');\n return null;\n }\n return Number(value);\n });\n if (values.some(value => value === null)) {\n console.error('One or more child expressions returned invalid values');\n return 0;\n }\n // Subtract the two values\n return values[0] - values[1];\n }\n };\n}\n"]}
@@ -1,5 +1,13 @@
1
1
  import { QtiExpression } from '@qti-components/base';
2
2
  import type { QtiExpressionBase } from '@qti-components/base';
3
+ /**
4
+ * @summary The qti-sum operator calculates the total of multiple numerical values.
5
+ * @documentation https://www.imsglobal.org/spec/qti/v3p0/info/index.html#sum
6
+ *
7
+ * Takes 1 or more sub-expressions with numerical base-types and any cardinality.
8
+ * Returns a single float (or integer if all arguments are integers) representing the total.
9
+ * Special cases: Returns NULL if any sub-expression is NULL.
10
+ */
3
11
  export declare class QtiSum extends QtiExpression<number> {
4
12
  getResult(): number;
5
13
  }
@@ -1,4 +1,12 @@
1
1
  import { QtiExpression } from '@qti-components/base';
2
+ /**
3
+ * @summary The qti-sum operator calculates the total of multiple numerical values.
4
+ * @documentation https://www.imsglobal.org/spec/qti/v3p0/info/index.html#sum
5
+ *
6
+ * Takes 1 or more sub-expressions with numerical base-types and any cardinality.
7
+ * Returns a single float (or integer if all arguments are integers) representing the total.
8
+ * Special cases: Returns NULL if any sub-expression is NULL.
9
+ */
2
10
  export class QtiSum extends QtiExpression {
3
11
  getResult() {
4
12
  // children can be a mix of qti-expression and qti-condition-expression
@@ -1 +1 @@
1
- {"version":3,"file":"qti-sum.js","sourceRoot":"","sources":["../../../src/components/qti-sum/qti-sum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAIrD,MAAM,OAAO,MAAO,SAAQ,aAAqB;IAC/B,SAAS;QACvB,uEAAuE;QACvE,MAAM,UAAU,GAAG,IAAI,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAkD,CAAC,CAAC,CAAC;QAC7G,MAAM,KAAK,GAAG,UAAU,CAAC,SAAS,EAAE,CAAC;QACrC,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,MAAM,OAAO,gBAAgB;IAC3B,YAAoB,WAAwC;QAAxC,gBAAW,GAAX,WAAW,CAA6B;IAAG,CAAC;IAEzD,SAAS;QACd,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC;QAC5E,wCAAwC;QACxC,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;YAClD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;YACtC,MAAM,KAAK,GAAG,CAAC,CAAC,SAAS,EAAE,CAAC;YAC5B,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;gBACxB,OAAO,CAAC,KAAK,CAAC,8CAA8C,CAAC,CAAC;gBAC9D,OAAO,IAAI,CAAC;YACd,CAAC;YAED,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IAC3C,CAAC;CACF;AAED,cAAc,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC","sourcesContent":["import { QtiExpression } from '@qti-components/base';\n\nimport type { QtiExpressionBase } from '@qti-components/base';\n\nexport class QtiSum extends QtiExpression<number> {\n public override getResult() {\n // children can be a mix of qti-expression and qti-condition-expression\n const expression = new QtiSumExpression(Array.from(this.children as unknown as QtiExpressionBase<number>[]));\n const value = expression.calculate();\n return value;\n }\n}\n\nexport class QtiSumExpression implements QtiExpressionBase<number> {\n constructor(private expressions: QtiExpressionBase<number>[]) {}\n\n public calculate() {\n const expressions = this.expressions.filter(c => c.calculate !== undefined);\n // check if one expresssion returns null\n if (expressions.some(c => c.calculate() === null)) {\n return null;\n }\n\n const values = this.expressions.map(c => {\n const value = c.calculate();\n if (Number.isNaN(value)) {\n console.error('unexpected value in qti-sum, expected number');\n return null;\n }\n\n return Number(value);\n });\n return values.reduce((a, b) => a + b, 0);\n }\n}\n\ncustomElements.define('qti-sum', QtiSum);\n"]}
1
+ {"version":3,"file":"qti-sum.js","sourceRoot":"","sources":["../../../src/components/qti-sum/qti-sum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAIrD;;;;;;;GAOG;AACH,MAAM,OAAO,MAAO,SAAQ,aAAqB;IAC/B,SAAS;QACvB,uEAAuE;QACvE,MAAM,UAAU,GAAG,IAAI,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAkD,CAAC,CAAC,CAAC;QAC7G,MAAM,KAAK,GAAG,UAAU,CAAC,SAAS,EAAE,CAAC;QACrC,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,MAAM,OAAO,gBAAgB;IAC3B,YAAoB,WAAwC;QAAxC,gBAAW,GAAX,WAAW,CAA6B;IAAG,CAAC;IAEzD,SAAS;QACd,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC;QAC5E,wCAAwC;QACxC,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;YAClD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;YACtC,MAAM,KAAK,GAAG,CAAC,CAAC,SAAS,EAAE,CAAC;YAC5B,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;gBACxB,OAAO,CAAC,KAAK,CAAC,8CAA8C,CAAC,CAAC;gBAC9D,OAAO,IAAI,CAAC;YACd,CAAC;YAED,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IAC3C,CAAC;CACF;AAED,cAAc,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC","sourcesContent":["import { QtiExpression } from '@qti-components/base';\n\nimport type { QtiExpressionBase } from '@qti-components/base';\n\n/**\n * @summary The qti-sum operator calculates the total of multiple numerical values.\n * @documentation https://www.imsglobal.org/spec/qti/v3p0/info/index.html#sum\n *\n * Takes 1 or more sub-expressions with numerical base-types and any cardinality.\n * Returns a single float (or integer if all arguments are integers) representing the total.\n * Special cases: Returns NULL if any sub-expression is NULL.\n */\nexport class QtiSum extends QtiExpression<number> {\n public override getResult() {\n // children can be a mix of qti-expression and qti-condition-expression\n const expression = new QtiSumExpression(Array.from(this.children as unknown as QtiExpressionBase<number>[]));\n const value = expression.calculate();\n return value;\n }\n}\n\nexport class QtiSumExpression implements QtiExpressionBase<number> {\n constructor(private expressions: QtiExpressionBase<number>[]) {}\n\n public calculate() {\n const expressions = this.expressions.filter(c => c.calculate !== undefined);\n // check if one expresssion returns null\n if (expressions.some(c => c.calculate() === null)) {\n return null;\n }\n\n const values = this.expressions.map(c => {\n const value = c.calculate();\n if (Number.isNaN(value)) {\n console.error('unexpected value in qti-sum, expected number');\n return null;\n }\n\n return Number(value);\n });\n return values.reduce((a, b) => a + b, 0);\n }\n}\n\ncustomElements.define('qti-sum', QtiSum);\n"]}
@@ -0,0 +1,12 @@
1
+ import { QtiExpression } from '@qti-components/base';
2
+ /**
3
+ * @summary The qti-truncate operator removes fractional parts of a number.
4
+ * @documentation https://www.imsglobal.org/spec/qti/v3p0/info/index.html#truncate
5
+ *
6
+ * Takes 1 numerical sub-expression of single cardinality.
7
+ * Returns integer formed by truncating value toward zero.
8
+ * Special cases: Returns NULL if input is NULL or NaN.
9
+ */
10
+ export declare class QtiTruncate extends QtiExpression<number | null> {
11
+ getResult(): number | null;
12
+ }
@@ -0,0 +1,38 @@
1
+ import { QtiExpression } from '@qti-components/base';
2
+ /**
3
+ * @summary The qti-truncate operator removes fractional parts of a number.
4
+ * @documentation https://www.imsglobal.org/spec/qti/v3p0/info/index.html#truncate
5
+ *
6
+ * Takes 1 numerical sub-expression of single cardinality.
7
+ * Returns integer formed by truncating value toward zero.
8
+ * Special cases: Returns NULL if input is NULL or NaN.
9
+ */
10
+ export class QtiTruncate extends QtiExpression {
11
+ getResult() {
12
+ const variables = this.getVariables();
13
+ if (variables.length !== 1) {
14
+ console.error('qti-truncate requires exactly one child expression');
15
+ return null;
16
+ }
17
+ const variable = variables[0];
18
+ if (variable.cardinality !== 'single' || Array.isArray(variable.value)) {
19
+ console.error('qti-truncate requires single cardinality');
20
+ return null;
21
+ }
22
+ if (variable.baseType !== 'integer' && variable.baseType !== 'float') {
23
+ console.error('qti-truncate requires numerical base-type');
24
+ return null;
25
+ }
26
+ if (variable.value === null || variable.value === undefined) {
27
+ return null;
28
+ }
29
+ const value = Number.parseFloat(variable.value);
30
+ if (Number.isNaN(value)) {
31
+ console.error('qti-truncate requires a numerical value');
32
+ return null;
33
+ }
34
+ return Math.trunc(value);
35
+ }
36
+ }
37
+ customElements.define('qti-truncate', QtiTruncate);
38
+ //# sourceMappingURL=qti-truncate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qti-truncate.js","sourceRoot":"","sources":["../../../src/components/qti-truncate/qti-truncate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAIrD;;;;;;;GAOG;AACH,MAAM,OAAO,WAAY,SAAQ,aAA4B;IAC3C,SAAS;QACvB,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,EAAwB,CAAC;QAE5D,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO,CAAC,KAAK,CAAC,oDAAoD,CAAC,CAAC;YACpE,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;QAC9B,IAAI,QAAQ,CAAC,WAAW,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACvE,OAAO,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;YAC1D,OAAO,IAAI,CAAC;QACd,CAAC;QACD,IAAI,QAAQ,CAAC,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;YACrE,OAAO,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;YAC3D,OAAO,IAAI,CAAC;QACd,CAAC;QACD,IAAI,QAAQ,CAAC,KAAK,KAAK,IAAI,IAAI,QAAQ,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAC5D,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAe,CAAC,CAAC;QAC1D,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YACxB,OAAO,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;YACzD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;CACF;AAED,cAAc,CAAC,MAAM,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC","sourcesContent":["import { QtiExpression } from '@qti-components/base';\n\nimport type { ResponseVariable } from '@qti-components/base';\n\n/**\n * @summary The qti-truncate operator removes fractional parts of a number.\n * @documentation https://www.imsglobal.org/spec/qti/v3p0/info/index.html#truncate\n *\n * Takes 1 numerical sub-expression of single cardinality.\n * Returns integer formed by truncating value toward zero.\n * Special cases: Returns NULL if input is NULL or NaN.\n */\nexport class QtiTruncate extends QtiExpression<number | null> {\n public override getResult(): number | null {\n const variables = this.getVariables() as ResponseVariable[];\n\n if (variables.length !== 1) {\n console.error('qti-truncate requires exactly one child expression');\n return null;\n }\n\n const variable = variables[0];\n if (variable.cardinality !== 'single' || Array.isArray(variable.value)) {\n console.error('qti-truncate requires single cardinality');\n return null;\n }\n if (variable.baseType !== 'integer' && variable.baseType !== 'float') {\n console.error('qti-truncate requires numerical base-type');\n return null;\n }\n if (variable.value === null || variable.value === undefined) {\n return null;\n }\n\n const value = Number.parseFloat(variable.value as string);\n if (Number.isNaN(value)) {\n console.error('qti-truncate requires a numerical value');\n return null;\n }\n\n return Math.trunc(value);\n }\n}\n\ncustomElements.define('qti-truncate', QtiTruncate);\n"]}
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@qti-components/processing",
3
3
  "description": "QTI processing utilities",
4
- "version": "1.3.1",
4
+ "version": "1.3.3",
5
5
  "author": "",
6
6
  "dependencies": {
7
- "@qti-components/base": "^1.4.1",
8
- "@qti-components/utilities": "^1.3.1"
7
+ "@qti-components/base": "^1.4.3",
8
+ "@qti-components/utilities": "^1.3.3"
9
9
  },
10
10
  "devDependencies": {
11
11
  "@lit/context": "^1.1.6",
12
- "lit": "^3.3.1"
12
+ "lit": "^3.3.2"
13
13
  },
14
14
  "keywords": [
15
15
  "processing",