@citolab/qti-components 8.1.0 → 9.0.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 (63) hide show
  1. package/cdn/index.global.js +1 -1
  2. package/cdn/index.js +288 -182
  3. package/dist/base.d.ts +5 -5
  4. package/dist/base.js +1 -1
  5. package/dist/{chunk-TXIB3SKC.js → chunk-3MQNPN7A.js} +3 -3
  6. package/dist/{chunk-6V3A7NQP.js → chunk-3NPCS4IT.js} +2 -2
  7. package/dist/{chunk-MK2I3MQB.js → chunk-3VQSUWCK.js} +175 -15
  8. package/dist/chunk-3VQSUWCK.js.map +1 -0
  9. package/dist/{chunk-4XR2JHCP.js → chunk-5BXJRO5O.js} +1816 -551
  10. package/dist/chunk-5BXJRO5O.js.map +1 -0
  11. package/dist/{chunk-NZLW6EX7.js → chunk-DXEWBTJB.js} +2 -2
  12. package/dist/{chunk-Q52IJELT.js → chunk-GBDTBHUQ.js} +602 -263
  13. package/dist/chunk-GBDTBHUQ.js.map +1 -0
  14. package/dist/chunk-KCK27QBP.js +11 -0
  15. package/dist/chunk-KCK27QBP.js.map +1 -0
  16. package/dist/chunk-MKZ374OJ.js +179 -0
  17. package/dist/chunk-MKZ374OJ.js.map +1 -0
  18. package/dist/{chunk-3IACYIU2.js → chunk-RT6WZ3P7.js} +2 -2
  19. package/dist/chunk-TLTYXWW7.js +7 -0
  20. package/dist/chunk-TLTYXWW7.js.map +1 -0
  21. package/dist/{chunk-EKXZI26R.js → chunk-WCWJPIUQ.js} +58 -6
  22. package/dist/chunk-WCWJPIUQ.js.map +1 -0
  23. package/dist/{chunk-6XJUP55A.js → chunk-WKWCOV5P.js} +3 -3
  24. package/dist/chunk-WKWCOV5P.js.map +1 -0
  25. package/dist/{chunk-CF3DXJWM.js → chunk-WTV7NQHO.js} +731 -715
  26. package/dist/chunk-WTV7NQHO.js.map +1 -0
  27. package/dist/{computed.types.d-DpKIYO6e.d.ts → computed.types.d-CJarqC6s.d.ts} +12 -0
  28. package/dist/corrections.d.ts +14 -4
  29. package/dist/corrections.js +82 -7
  30. package/dist/corrections.js.map +1 -1
  31. package/dist/elements.d.ts +1 -1
  32. package/dist/elements.js +3 -3
  33. package/dist/index.d.ts +5 -5
  34. package/dist/index.js +26 -24
  35. package/dist/interactions.js +14 -15
  36. package/dist/item.css +81 -0
  37. package/dist/item.d.ts +1 -1
  38. package/dist/item.js +4 -4
  39. package/dist/loader.d.ts +1 -1
  40. package/dist/processing.d.ts +29 -3
  41. package/dist/processing.js +3 -2
  42. package/dist/qti-components-jsx.d.ts +7883 -7250
  43. package/dist/{qti-condition-expression.d-aMvBvpc6.d.ts → qti-condition-expression.d-CYwXOUb1.d.ts} +1 -1
  44. package/dist/{qti-expression.d-BietT_8b.d.ts → qti-expression.d-B_-m9emA.d.ts} +11 -1
  45. package/dist/{qti-feedback.d-DZbad0RN.d.ts → qti-feedback.d-B1EIF-fU.d.ts} +1 -0
  46. package/dist/{qti-test.d-_YAlhDbt.d.ts → qti-test.d-C6lCEMRB.d.ts} +38 -3
  47. package/dist/test.d.ts +5 -5
  48. package/dist/test.js +7 -5
  49. package/package.json +9 -9
  50. package/dist/chunk-4XR2JHCP.js.map +0 -1
  51. package/dist/chunk-6XJUP55A.js.map +0 -1
  52. package/dist/chunk-CF3DXJWM.js.map +0 -1
  53. package/dist/chunk-EKXZI26R.js.map +0 -1
  54. package/dist/chunk-IXPDMYKH.js +0 -1420
  55. package/dist/chunk-IXPDMYKH.js.map +0 -1
  56. package/dist/chunk-IYC7LZV6.js +0 -7
  57. package/dist/chunk-IYC7LZV6.js.map +0 -1
  58. package/dist/chunk-MK2I3MQB.js.map +0 -1
  59. package/dist/chunk-Q52IJELT.js.map +0 -1
  60. /package/dist/{chunk-TXIB3SKC.js.map → chunk-3MQNPN7A.js.map} +0 -0
  61. /package/dist/{chunk-6V3A7NQP.js.map → chunk-3NPCS4IT.js.map} +0 -0
  62. /package/dist/{chunk-NZLW6EX7.js.map → chunk-DXEWBTJB.js.map} +0 -0
  63. /package/dist/{chunk-3IACYIU2.js.map → chunk-RT6WZ3P7.js.map} +0 -0
package/dist/base.d.ts CHANGED
@@ -1,15 +1,15 @@
1
1
  import { C as ComputedItemContext } from './computed-item.types.d-BKZdSLLJ.js';
2
- import { C as ComputedContext } from './computed.types.d-DpKIYO6e.js';
3
- export { a as ComputedItem, I as INITIAL_SESSION_CONTEXT, S as SessionContext, V as View, s as sessionContext } from './computed.types.d-DpKIYO6e.js';
2
+ import { C as ComputedContext } from './computed.types.d-CJarqC6s.js';
3
+ export { a as ComputedItem, I as INITIAL_SESSION_CONTEXT, S as SessionContext, V as View, s as sessionContext } from './computed.types.d-CJarqC6s.js';
4
4
  export { C as ConfigContext, V as ValidationDisplayMode, c as configContext } from './config.context.d-BvU9r-Mg.js';
5
5
  export { C as ChoiceRole, I as Interaction, a as InteractionContext, i as interactionContext } from './interaction.d-CJiMv8H7.js';
6
6
  import { I as ItemContext, B as BaseType } from './item.types.d-QU7LljEK.js';
7
7
  export { C as Calculate, a as Cardinality, M as Multiple, O as Ordered, b as OutcomeVariable, Q as QtiAreaMapEntry, c as QtiAreaMapping, d as QtiMapEntry, e as QtiMapping, R as ResponseInteraction, f as ResponseVariable, T as TemplateVariable, V as VariableDeclaration, g as VariableValue, h as areaShape, i as directedPair, j as float, k as integer, l as itemContextVariables } from './item.types.d-QU7LljEK.js';
8
8
  export { Q as QtiContext, a as QtiContextType, S as Seed, b as asSeed, i as isSeed, q as qtiContext } from './qti.context.d-CejJMlfZ.js';
9
- export { I as INITIAL_TEST_CONTEXT, Q as QtiExpression, a as QtiExpressionBase, T as TestContext, t as testContext } from './qti-expression.d-BietT_8b.js';
9
+ export { I as INITIAL_TEST_CONTEXT, Q as QtiExpression, a as QtiExpressionBase, T as TestContext, t as testContext } from './qti-expression.d-B_-m9emA.js';
10
10
  import * as lit from 'lit';
11
- export { Q as QtiFeedback, a as QtiVariableDeclaration } from './qti-feedback.d-DZbad0RN.js';
12
- export { Q as QtiConditionExpression } from './qti-condition-expression.d-aMvBvpc6.js';
11
+ export { Q as QtiFeedback, a as QtiVariableDeclaration } from './qti-feedback.d-B1EIF-fU.js';
12
+ export { Q as QtiConditionExpression } from './qti-condition-expression.d-CYwXOUb1.js';
13
13
  export { D as DirectedPair, I as Identifier, P as Point, R as ResponseValue, i as iterResponseValues, p as parsePair, a as parsePoint, b as parseResponseAttribute, r as responseAttributeConverter, s as serializePair, c as serializePoint, d as serializeResponseAttribute } from './response.d-_8y4kjGP.js';
14
14
  export { F as FormAssociatedInteraction, I as IInteraction, R as ReadonlyInteraction, a as RegisteredInteraction, b as ResettableInteraction, c as ResponseIdentifiedInteraction, d as ResponseInteractionElement, V as ValidatableInteraction } from './interaction.interface.d-CvjHM2bi.js';
15
15
  export { Q as QtiRuleBase, a as QtiRuleElement } from './qti-rule-base.d-ajOnfGXY.js';
package/dist/base.js CHANGED
@@ -37,7 +37,7 @@ import {
37
37
  sessionContext,
38
38
  testContext,
39
39
  validationMessage
40
- } from "./chunk-EKXZI26R.js";
40
+ } from "./chunk-WCWJPIUQ.js";
41
41
  export {
42
42
  CustomStateSetShim,
43
43
  INITIAL_SESSION_CONTEXT,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  item_default
3
- } from "./chunk-IYC7LZV6.js";
3
+ } from "./chunk-TLTYXWW7.js";
4
4
  import {
5
5
  watch
6
6
  } from "./chunk-4DB4SC5K.js";
@@ -11,7 +11,7 @@ import {
11
11
  computedItemContext,
12
12
  configContext,
13
13
  qtiContext
14
- } from "./chunk-EKXZI26R.js";
14
+ } from "./chunk-WCWJPIUQ.js";
15
15
 
16
16
  // ../qti-item/dist/components/item-container/item-container.js
17
17
  import { consume } from "@lit/context";
@@ -292,4 +292,4 @@ export {
292
292
  QtiItem,
293
293
  qtiItemElements
294
294
  };
295
- //# sourceMappingURL=chunk-TXIB3SKC.js.map
295
+ //# sourceMappingURL=chunk-3MQNPN7A.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  qtiItemElements
3
- } from "./chunk-TXIB3SKC.js";
3
+ } from "./chunk-3MQNPN7A.js";
4
4
 
5
5
  // ../qti-item/dist/register.js
6
6
  for (const { tag, ctor } of qtiItemElements) {
@@ -8,4 +8,4 @@ for (const { tag, ctor } of qtiItemElements) {
8
8
  customElements.define(tag, ctor);
9
9
  }
10
10
  }
11
- //# sourceMappingURL=chunk-6V3A7NQP.js.map
11
+ //# sourceMappingURL=chunk-3NPCS4IT.js.map
@@ -5,7 +5,7 @@ import {
5
5
  convertNumberToUniversalFormat,
6
6
  itemContext,
7
7
  testContext
8
- } from "./chunk-EKXZI26R.js";
8
+ } from "./chunk-WCWJPIUQ.js";
9
9
 
10
10
  // ../qti-processing/dist/components/qti-and/qti-and.js
11
11
  var QtiAnd = class extends qtiAndMixin(QtiConditionExpression) {
@@ -1925,6 +1925,101 @@ var QtiPower = class extends QtiExpression {
1925
1925
  import { consume as consume3 } from "@lit/context";
1926
1926
  import { LitElement as LitElement3, html as html4, nothing } from "lit";
1927
1927
  import { property as property13, state as state3 } from "lit/decorators.js";
1928
+
1929
+ // ../qti-processing/dist/components/qti-printed-variable/printed-variable-format.js
1930
+ var CONVERSION = /%(?:(%)|([-+ 0#]*)(\d+)?(?:\.(\d+))?([diuoxXfFeEgGsc]))/g;
1931
+ function padExponent(exponential) {
1932
+ return exponential.replace(/e([+-])(\d)$/, "e$10$2");
1933
+ }
1934
+ function toExponential(value, precision) {
1935
+ return padExponent(precision === void 0 ? value.toExponential() : value.toExponential(precision));
1936
+ }
1937
+ function stripTrailingZeros(formatted) {
1938
+ const [mantissa, exponent] = formatted.split(/e/i);
1939
+ const trimmed = mantissa.includes(".") ? mantissa.replace(/\.?0+$/, "") : mantissa;
1940
+ const suffix = exponent === void 0 ? "" : `e${exponent}`;
1941
+ return `${trimmed}${suffix}`;
1942
+ }
1943
+ function toGeneral(value, precision) {
1944
+ const significant = precision === 0 ? 1 : precision;
1945
+ const exponent = value === 0 ? 0 : Math.floor(Math.log10(value));
1946
+ if (exponent < -4 || exponent >= significant) {
1947
+ return stripTrailingZeros(toExponential(value, significant - 1));
1948
+ }
1949
+ return stripTrailingZeros(value.toFixed(Math.max(0, significant - 1 - exponent)));
1950
+ }
1951
+ function convert(conversion, flags, precision, raw) {
1952
+ if (conversion === "s" || conversion === "c") {
1953
+ const text = conversion === "c" ? raw.slice(0, 1) : raw;
1954
+ return precision === void 0 ? text : text.slice(0, precision);
1955
+ }
1956
+ const numeric = Number(raw);
1957
+ if (raw.trim() === "" || !Number.isFinite(numeric))
1958
+ return raw;
1959
+ const magnitude = Math.abs(numeric);
1960
+ let body;
1961
+ let negative = numeric < 0;
1962
+ switch (conversion) {
1963
+ case "d":
1964
+ case "i":
1965
+ body = String(Math.trunc(magnitude));
1966
+ break;
1967
+ case "u":
1968
+ body = String(Math.trunc(magnitude));
1969
+ negative = false;
1970
+ break;
1971
+ case "o":
1972
+ body = `${flags.includes("#") ? "0" : ""}${Math.trunc(magnitude).toString(8)}`;
1973
+ break;
1974
+ case "x":
1975
+ body = `${flags.includes("#") ? "0x" : ""}${Math.trunc(magnitude).toString(16)}`;
1976
+ break;
1977
+ case "X":
1978
+ body = `${flags.includes("#") ? "0X" : ""}${Math.trunc(magnitude).toString(16).toUpperCase()}`;
1979
+ break;
1980
+ case "f":
1981
+ case "F":
1982
+ body = magnitude.toFixed(precision ?? 6);
1983
+ break;
1984
+ case "e":
1985
+ body = toExponential(magnitude, precision ?? 6);
1986
+ break;
1987
+ case "E":
1988
+ body = toExponential(magnitude, precision ?? 6).toUpperCase();
1989
+ break;
1990
+ case "g":
1991
+ body = toGeneral(magnitude, precision ?? 6);
1992
+ break;
1993
+ case "G":
1994
+ body = toGeneral(magnitude, precision ?? 6).toUpperCase();
1995
+ break;
1996
+ default:
1997
+ return raw;
1998
+ }
1999
+ const sign = negative ? "-" : flags.includes("+") ? "+" : flags.includes(" ") ? " " : "";
2000
+ return `${sign}${body}`;
2001
+ }
2002
+ function pad(text, flags, width) {
2003
+ if (text.length >= width)
2004
+ return text;
2005
+ const fill = width - text.length;
2006
+ if (flags.includes("-"))
2007
+ return `${text}${" ".repeat(fill)}`;
2008
+ if (flags.includes("0")) {
2009
+ const [, sign, digits] = /^([-+ ]?)(.*)$/.exec(text);
2010
+ return `${sign}${"0".repeat(fill)}${digits}`;
2011
+ }
2012
+ return `${" ".repeat(fill)}${text}`;
2013
+ }
2014
+ function applyFormat(format, value) {
2015
+ return format.replace(CONVERSION, (_match, percent, flags, width, precision, conversion) => {
2016
+ if (percent)
2017
+ return "%";
2018
+ return pad(convert(conversion, flags ?? "", precision === void 0 ? void 0 : Number(precision), value), flags ?? "", width === void 0 ? 0 : Number(width));
2019
+ });
2020
+ }
2021
+
2022
+ // ../qti-processing/dist/components/qti-printed-variable/qti-printed-variable.js
1928
2023
  var __decorate13 = function(decorators, target, key, desc) {
1929
2024
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1930
2025
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -1932,9 +2027,60 @@ var __decorate13 = function(decorators, target, key, desc) {
1932
2027
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1933
2028
  };
1934
2029
  var QtiPrintedVariable = class extends LitElement3 {
2030
+ constructor() {
2031
+ super(...arguments);
2032
+ this.base = 10;
2033
+ this.powerForm = false;
2034
+ this.delimiter = ";";
2035
+ this.mappingIndicator = "=";
2036
+ }
1935
2037
  render() {
1936
- const value = this.context?.variables.find((v) => v.identifier === this.identifier)?.value;
1937
- return value === null ? nothing : html4`${JSON.stringify(value, null, 2)}`;
2038
+ const variable = this.context?.variables.find((v) => v.identifier === this.identifier);
2039
+ const printed = variable ? this.#print(variable) : null;
2040
+ return printed === null ? nothing : html4`${printed}`;
2041
+ }
2042
+ /** Returns `null` for anything QTI treats as NULL, which prints as nothing. */
2043
+ #print(variable) {
2044
+ const value = variable.value;
2045
+ if (value === null || value === void 0)
2046
+ return null;
2047
+ if (Array.isArray(value)) {
2048
+ if (value.length === 0)
2049
+ return null;
2050
+ if (this.index !== void 0) {
2051
+ const selected = value[this.index - 1];
2052
+ return selected === null || selected === void 0 ? null : this.#printValue(selected, variable.baseType);
2053
+ }
2054
+ return value.map((entry) => this.#printValue(entry, variable.baseType)).join(this.delimiter);
2055
+ }
2056
+ if (typeof value === "object") {
2057
+ const record = value;
2058
+ if (this.field !== void 0) {
2059
+ const selected = record[this.field];
2060
+ return selected === null || selected === void 0 ? null : this.#printValue(selected, variable.baseType);
2061
+ }
2062
+ const fields = Object.entries(record).filter(([, entry]) => entry !== null && entry !== void 0);
2063
+ if (fields.length === 0)
2064
+ return null;
2065
+ return fields.map(([name, entry]) => `${name}${this.mappingIndicator}${this.#printValue(entry, variable.baseType)}`).join(this.delimiter);
2066
+ }
2067
+ return this.#printValue(value, variable.baseType);
2068
+ }
2069
+ #printValue(value, baseType) {
2070
+ const raw = Array.isArray(value) ? value.join(" ") : String(value);
2071
+ if (this.format)
2072
+ return applyFormat(this.format, raw);
2073
+ if (baseType === "integer" && this.base !== 10) {
2074
+ const integer = Number.parseInt(raw, 10);
2075
+ if (Number.isFinite(integer))
2076
+ return integer.toString(this.base);
2077
+ }
2078
+ if (this.powerForm) {
2079
+ const numeric = Number(raw);
2080
+ if (raw.trim() !== "" && Number.isFinite(numeric))
2081
+ return toExponential(numeric);
2082
+ }
2083
+ return raw;
1938
2084
  }
1939
2085
  calculate() {
1940
2086
  const result = this.context.variables.find((v) => v.identifier === this.identifier) || null;
@@ -1944,6 +2090,27 @@ var QtiPrintedVariable = class extends LitElement3 {
1944
2090
  __decorate13([
1945
2091
  property13({ type: String })
1946
2092
  ], QtiPrintedVariable.prototype, "identifier", void 0);
2093
+ __decorate13([
2094
+ property13({ type: String })
2095
+ ], QtiPrintedVariable.prototype, "format", void 0);
2096
+ __decorate13([
2097
+ property13({ type: Number })
2098
+ ], QtiPrintedVariable.prototype, "base", void 0);
2099
+ __decorate13([
2100
+ property13({ type: Number })
2101
+ ], QtiPrintedVariable.prototype, "index", void 0);
2102
+ __decorate13([
2103
+ property13({ type: Boolean, attribute: "power-form" })
2104
+ ], QtiPrintedVariable.prototype, "powerForm", void 0);
2105
+ __decorate13([
2106
+ property13({ type: String })
2107
+ ], QtiPrintedVariable.prototype, "field", void 0);
2108
+ __decorate13([
2109
+ property13({ type: String })
2110
+ ], QtiPrintedVariable.prototype, "delimiter", void 0);
2111
+ __decorate13([
2112
+ property13({ type: String, attribute: "mapping-indicator" })
2113
+ ], QtiPrintedVariable.prototype, "mappingIndicator", void 0);
1947
2114
  __decorate13([
1948
2115
  consume3({ context: itemContext, subscribe: true }),
1949
2116
  state3()
@@ -2750,9 +2917,8 @@ var QtiTruncate = class extends QtiExpression {
2750
2917
  // ../qti-processing/dist/components/qti-variable/qti-variable.js
2751
2918
  var QtiVariable = class extends QtiExpression {
2752
2919
  getResult() {
2753
- const identifier = this.getAttribute("identifier");
2754
- const result = this.context.variables.find((v) => v.identifier === identifier).value;
2755
- return result;
2920
+ const identifier = this.getAttribute("identifier") || "";
2921
+ return this.resolveVariable(identifier)?.value ?? null;
2756
2922
  }
2757
2923
  };
2758
2924
 
@@ -2827,13 +2993,6 @@ var qtiProcessingElements = [
2827
2993
  { tag: "qti-variable", ctor: QtiVariable }
2828
2994
  ];
2829
2995
 
2830
- // ../qti-processing/dist/register.js
2831
- for (const { tag, ctor } of qtiProcessingElements) {
2832
- if (!customElements.get(tag)) {
2833
- customElements.define(tag, ctor);
2834
- }
2835
- }
2836
-
2837
2996
  export {
2838
2997
  QtiAnd,
2839
2998
  qtiAndMixin,
@@ -2906,6 +3065,7 @@ export {
2906
3065
  QtiSum,
2907
3066
  QtiSumExpression,
2908
3067
  QtiTruncate,
2909
- QtiVariable
3068
+ QtiVariable,
3069
+ qtiProcessingElements
2910
3070
  };
2911
- //# sourceMappingURL=chunk-MK2I3MQB.js.map
3071
+ //# sourceMappingURL=chunk-3VQSUWCK.js.map