@citolab/qti-components 8.2.0 → 9.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.
Files changed (50) hide show
  1. package/cdn/index.global.js +1 -1
  2. package/cdn/index.js +190 -190
  3. package/dist/base.js +1 -1
  4. package/dist/{chunk-OVBG223G.js → chunk-3VQSUWCK.js} +173 -12
  5. package/dist/chunk-3VQSUWCK.js.map +1 -0
  6. package/dist/{chunk-Q6ZK4LRH.js → chunk-5BXJRO5O.js} +1792 -551
  7. package/dist/chunk-5BXJRO5O.js.map +1 -0
  8. package/dist/{chunk-OIUK5BFU.js → chunk-5SU3MP6Y.js} +811 -811
  9. package/dist/chunk-5SU3MP6Y.js.map +1 -0
  10. package/dist/{chunk-LMGJOBJA.js → chunk-DAUU2NJL.js} +5 -5
  11. package/dist/chunk-DAUU2NJL.js.map +1 -0
  12. package/dist/chunk-KCK27QBP.js +11 -0
  13. package/dist/chunk-KCK27QBP.js.map +1 -0
  14. package/dist/{chunk-M7K5C522.js → chunk-LDY4C2OT.js} +2 -2
  15. package/dist/chunk-MKZ374OJ.js +179 -0
  16. package/dist/chunk-MKZ374OJ.js.map +1 -0
  17. package/dist/{chunk-CRLXQZFA.js → chunk-QCPN7E6K.js} +14 -10
  18. package/dist/chunk-QCPN7E6K.js.map +1 -0
  19. package/dist/{chunk-U7YCXDYC.js → chunk-RT6WZ3P7.js} +2 -2
  20. package/dist/{chunk-7D3NKAGZ.js → chunk-WCWJPIUQ.js} +5 -4
  21. package/dist/chunk-WCWJPIUQ.js.map +1 -0
  22. package/dist/{chunk-YLRMOX6C.js → chunk-WKWCOV5P.js} +2 -2
  23. package/dist/chunk-XE7BALDO.js +7 -0
  24. package/dist/chunk-XE7BALDO.js.map +1 -0
  25. package/dist/{chunk-UC3T3NI3.js → chunk-XYQNTF5B.js} +2 -2
  26. package/dist/corrections.js +82 -7
  27. package/dist/corrections.js.map +1 -1
  28. package/dist/elements.js +3 -3
  29. package/dist/index.js +24 -24
  30. package/dist/interactions.js +14 -15
  31. package/dist/item.js +4 -4
  32. package/dist/processing.d.ts +26 -0
  33. package/dist/processing.js +3 -2
  34. package/dist/qti-components-jsx.d.ts +60 -4
  35. package/dist/test.js +5 -5
  36. package/package.json +7 -7
  37. package/dist/chunk-43XBJ47H.js +0 -1420
  38. package/dist/chunk-43XBJ47H.js.map +0 -1
  39. package/dist/chunk-7D3NKAGZ.js.map +0 -1
  40. package/dist/chunk-CRLXQZFA.js.map +0 -1
  41. package/dist/chunk-LMGJOBJA.js.map +0 -1
  42. package/dist/chunk-OIUK5BFU.js.map +0 -1
  43. package/dist/chunk-OVBG223G.js.map +0 -1
  44. package/dist/chunk-Q6ZK4LRH.js.map +0 -1
  45. package/dist/chunk-TLTYXWW7.js +0 -7
  46. package/dist/chunk-TLTYXWW7.js.map +0 -1
  47. /package/dist/{chunk-M7K5C522.js.map → chunk-LDY4C2OT.js.map} +0 -0
  48. /package/dist/{chunk-U7YCXDYC.js.map → chunk-RT6WZ3P7.js.map} +0 -0
  49. /package/dist/{chunk-YLRMOX6C.js.map → chunk-WKWCOV5P.js.map} +0 -0
  50. /package/dist/{chunk-UC3T3NI3.js.map → chunk-XYQNTF5B.js.map} +0 -0
package/dist/base.js CHANGED
@@ -37,7 +37,7 @@ import {
37
37
  sessionContext,
38
38
  testContext,
39
39
  validationMessage
40
- } from "./chunk-7D3NKAGZ.js";
40
+ } from "./chunk-WCWJPIUQ.js";
41
41
  export {
42
42
  CustomStateSetShim,
43
43
  INITIAL_SESSION_CONTEXT,
@@ -5,7 +5,7 @@ import {
5
5
  convertNumberToUniversalFormat,
6
6
  itemContext,
7
7
  testContext
8
- } from "./chunk-7D3NKAGZ.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()
@@ -2826,13 +2993,6 @@ var qtiProcessingElements = [
2826
2993
  { tag: "qti-variable", ctor: QtiVariable }
2827
2994
  ];
2828
2995
 
2829
- // ../qti-processing/dist/register.js
2830
- for (const { tag, ctor } of qtiProcessingElements) {
2831
- if (!customElements.get(tag)) {
2832
- customElements.define(tag, ctor);
2833
- }
2834
- }
2835
-
2836
2996
  export {
2837
2997
  QtiAnd,
2838
2998
  qtiAndMixin,
@@ -2905,6 +3065,7 @@ export {
2905
3065
  QtiSum,
2906
3066
  QtiSumExpression,
2907
3067
  QtiTruncate,
2908
- QtiVariable
3068
+ QtiVariable,
3069
+ qtiProcessingElements
2909
3070
  };
2910
- //# sourceMappingURL=chunk-OVBG223G.js.map
3071
+ //# sourceMappingURL=chunk-3VQSUWCK.js.map