@learnosity/lib-qti-converter 0.12.7 → 0.12.8

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 (32) hide show
  1. package/package.json +8 -8
  2. package/packages/cli/dist/{batchProcessors-DU1HwpHY.js → batchProcessors-CUJoQD8a.js} +3 -3
  3. package/packages/cli/dist/{batchProcessors-DU1HwpHY.js.map → batchProcessors-CUJoQD8a.js.map} +1 -1
  4. package/packages/cli/dist/batchWorker.js +1 -1
  5. package/packages/cli/dist/{create-prompt-DU9wLVhI.js → create-prompt-DyNnKXYU.js} +63 -53
  6. package/packages/cli/dist/create-prompt-DyNnKXYU.js.map +1 -0
  7. package/packages/cli/dist/{dist-DjpU2mIj.js → dist-D3v6G5F8.js} +6 -6
  8. package/packages/cli/dist/{dist-DjpU2mIj.js.map → dist-D3v6G5F8.js.map} +1 -1
  9. package/packages/cli/dist/{learnosityToQti-BSbH3jyx.js → learnosityToQti-CvfVQ6Kl.js} +4 -4
  10. package/packages/cli/dist/{learnosityToQti-BSbH3jyx.js.map → learnosityToQti-CvfVQ6Kl.js.map} +1 -1
  11. package/packages/cli/dist/{learnosityToQtiPackage-B0xRzYmy.js → learnosityToQtiPackage-CXMsJNQD.js} +7 -7
  12. package/packages/cli/dist/{learnosityToQtiPackage-B0xRzYmy.js.map → learnosityToQtiPackage-CXMsJNQD.js.map} +1 -1
  13. package/packages/cli/dist/main.js +5 -5
  14. package/packages/cli/dist/{nodeFileAccess-BkzSHCOh.js → nodeFileAccess-BhCoGDOi.js} +6 -3
  15. package/packages/cli/dist/{nodeFileAccess-BkzSHCOh.js.map → nodeFileAccess-BhCoGDOi.js.map} +1 -1
  16. package/packages/cli/dist/{pathUtils-B9yPTlVF.js → pathUtils-DmtCfutO.js} +26 -20
  17. package/packages/cli/dist/pathUtils-DmtCfutO.js.map +1 -0
  18. package/packages/cli/dist/{qtiPackageToLearnosity-C7JaaUDU.js → qtiPackageToLearnosity-FhfNr7gf.js} +5 -5
  19. package/packages/cli/dist/{qtiPackageToLearnosity-C7JaaUDU.js.map → qtiPackageToLearnosity-FhfNr7gf.js.map} +1 -1
  20. package/packages/cli/dist/{qtiToLearnosity-CYoG2aIX.js → qtiToLearnosity-5lQ5f3-t.js} +5 -5
  21. package/packages/cli/dist/{qtiToLearnosity-CYoG2aIX.js.map → qtiToLearnosity-5lQ5f3-t.js.map} +1 -1
  22. package/packages/cli/dist/{resolveOptions-CW80R2EQ.js → resolveOptions-lHxSyq9F.js} +5 -5
  23. package/packages/cli/dist/{resolveOptions-CW80R2EQ.js.map → resolveOptions-lHxSyq9F.js.map} +1 -1
  24. package/packages/cli/dist/{table-DjOn2Tsk.js → table-7b-8MN2z.js} +91 -65
  25. package/packages/cli/dist/table-7b-8MN2z.js.map +1 -0
  26. package/packages/core/dist/index.d.ts +184 -184
  27. package/packages/core/dist/index.js +90 -64
  28. package/packages/core/dist/node.d.ts +196 -196
  29. package/packages/core/dist/node.js +95 -66
  30. package/packages/cli/dist/create-prompt-DU9wLVhI.js.map +0 -1
  31. package/packages/cli/dist/pathUtils-B9yPTlVF.js.map +0 -1
  32. package/packages/cli/dist/table-DjOn2Tsk.js.map +0 -1
@@ -5737,14 +5737,14 @@ var DomHandler = class {
5737
5737
  //#endregion
5738
5738
  //#region ../../node_modules/.pnpm/entities@4.5.0/node_modules/entities/lib/esm/escape.js
5739
5739
  const xmlReplacer = /["&'<>$\x80-\uFFFF]/g;
5740
- const xmlCodeMap$1 = /* @__PURE__ */ new Map([
5740
+ const xmlCodeMap = /* @__PURE__ */ new Map([
5741
5741
  [34, "&quot;"],
5742
5742
  [38, "&amp;"],
5743
5743
  [39, "&apos;"],
5744
5744
  [60, "&lt;"],
5745
5745
  [62, "&gt;"]
5746
5746
  ]);
5747
- const getCodePoint$1 = String.prototype.codePointAt != null ? (str, index) => str.codePointAt(index) : (c, index) => (c.charCodeAt(index) & 64512) === 55296 ? (c.charCodeAt(index) - 55296) * 1024 + c.charCodeAt(index + 1) - 56320 + 65536 : c.charCodeAt(index);
5747
+ const getCodePoint = String.prototype.codePointAt != null ? (str, index) => str.codePointAt(index) : (c, index) => (c.charCodeAt(index) & 64512) === 55296 ? (c.charCodeAt(index) - 55296) * 1024 + c.charCodeAt(index + 1) - 56320 + 65536 : c.charCodeAt(index);
5748
5748
  /**
5749
5749
  * Encodes all non-ASCII characters, as well as characters not valid in XML
5750
5750
  * documents using XML entities.
@@ -5759,12 +5759,12 @@ function encodeXML$1(str) {
5759
5759
  while ((match = xmlReplacer.exec(str)) !== null) {
5760
5760
  const i = match.index;
5761
5761
  const char = str.charCodeAt(i);
5762
- const next = xmlCodeMap$1.get(char);
5762
+ const next = xmlCodeMap.get(char);
5763
5763
  if (next !== void 0) {
5764
5764
  ret += str.substring(lastIdx, i) + next;
5765
5765
  lastIdx = i + 1;
5766
5766
  } else {
5767
- ret += `${str.substring(lastIdx, i)}&#x${getCodePoint$1(str, i).toString(16)};`;
5767
+ ret += `${str.substring(lastIdx, i)}&#x${getCodePoint(str, i).toString(16)};`;
5768
5768
  lastIdx = xmlReplacer.lastIndex += Number((char & 64512) === 55296);
5769
5769
  }
5770
5770
  }
@@ -5780,7 +5780,7 @@ function encodeXML$1(str) {
5780
5780
  * @returns Function that escapes all characters matched by the given regular
5781
5781
  * expression using the given map of characters to escape to their entities.
5782
5782
  */
5783
- function getEscaper$1(regex, map) {
5783
+ function getEscaper(regex, map) {
5784
5784
  return function escape(data) {
5785
5785
  let match;
5786
5786
  let lastIdx = 0;
@@ -5799,7 +5799,7 @@ function getEscaper$1(regex, map) {
5799
5799
  *
5800
5800
  * @param data String to escape.
5801
5801
  */
5802
- const escapeAttribute$1 = getEscaper$1(/["&\u00A0]/g, /* @__PURE__ */ new Map([
5802
+ const escapeAttribute$1 = getEscaper(/["&\u00A0]/g, /* @__PURE__ */ new Map([
5803
5803
  [34, "&quot;"],
5804
5804
  [38, "&amp;"],
5805
5805
  [160, "&nbsp;"]
@@ -5810,7 +5810,7 @@ const escapeAttribute$1 = getEscaper$1(/["&\u00A0]/g, /* @__PURE__ */ new Map([
5810
5810
  *
5811
5811
  * @param data String to escape.
5812
5812
  */
5813
- const escapeText$1 = getEscaper$1(/[&<>\u00A0]/g, /* @__PURE__ */ new Map([
5813
+ const escapeText$1 = getEscaper(/[&<>\u00A0]/g, /* @__PURE__ */ new Map([
5814
5814
  [38, "&amp;"],
5815
5815
  [60, "&lt;"],
5816
5816
  [62, "&gt;"],
@@ -8873,93 +8873,116 @@ function getElementsByTagType(type, nodes, recurse = true, limit = Number.POSITI
8873
8873
  return filter(Checks["tag_type"](type), nodes, recurse, limit);
8874
8874
  }
8875
8875
  //#endregion
8876
- //#region ../../node_modules/.pnpm/entities@8.0.0/node_modules/entities/dist/escape.js
8877
- const xmlCodeMap = /* @__PURE__ */ new Map([
8878
- [34, "&quot;"],
8879
- [38, "&amp;"],
8880
- [39, "&apos;"],
8881
- [60, "&lt;"],
8882
- [62, "&gt;"]
8883
- ]);
8876
+ //#region ../../node_modules/.pnpm/entities@8.1.0/node_modules/entities/dist/escape.js
8877
+ /**
8878
+ * Get the named reference for an XML special character or U+00A0.
8879
+ * @param char Code unit matched by one of the escape regexes.
8880
+ */
8881
+ function getEscape(char) {
8882
+ return char === 34 ? "&quot;" : char === 38 ? "&amp;" : char === 39 ? "&apos;" : char === 60 ? "&lt;" : char === 62 ? "&gt;" : "&nbsp;";
8883
+ }
8884
+ /**
8885
+ * Matches exactly the characters `encodeXML` escapes: the five XML special
8886
+ * characters plus every non-ASCII code unit (lone surrogates included — no
8887
+ * `u` flag). Kept in sync with `XML_BITSET_VALUE`.
8888
+ *
8889
+ * Shared with `encodeNonAsciiHTML` in `encode.ts`. Because the regex is
8890
+ * stateful (`g` flag), every call site must set `lastIndex` before use.
8891
+ */
8892
+ const xmlEncodeRegex = /["&'<>\u0080-\uFFFF]/g;
8884
8893
  /**
8885
- * Read a code point at a given index.
8886
- * @param input Input string to encode or decode.
8887
- * @param index Current read position in the input string.
8894
+ * Whether `code` (a UTF-16 code unit) is escaped by {@link encodeXML}: a
8895
+ * non-ASCII unit, or one of the five XML specials flagged in
8896
+ * `XML_BITSET_VALUE` (which is only meaningful for code units 32-63).
8897
+ * @param code Code unit to test.
8888
8898
  */
8889
- const getCodePoint = typeof String.prototype.codePointAt === "function" ? (input, index) => input.codePointAt(index) : (c, index) => (c.charCodeAt(index) & 64512) === 55296 ? (c.charCodeAt(index) - 55296) * 1024 + c.charCodeAt(index + 1) - 56320 + 65536 : c.charCodeAt(index);
8899
+ function isXmlEscapable(code) {
8900
+ return code >= 128 || code >= 32 && code < 64 && (1342177476 >>> code & 1) === 1;
8901
+ }
8890
8902
  /**
8891
8903
  * Encodes all non-ASCII characters, as well as characters not valid in XML
8892
- * documents using XML entities. Uses a fast bitset scan instead of RegExp.
8904
+ * documents using XML entities.
8893
8905
  *
8894
8906
  * If a character has no equivalent entity, a numeric hexadecimal reference
8895
8907
  * (eg. `&#xfc;`) will be used.
8896
- * @param input Input string to encode or decode.
8908
+ * @param input Input string to encode.
8897
8909
  */
8898
8910
  function encodeXML(input) {
8911
+ const { length } = input;
8899
8912
  let out;
8900
8913
  let last = 0;
8901
- const { length } = input;
8902
- for (let index = 0; index < length; index++) {
8914
+ let index = 0;
8915
+ while (index < length) {
8903
8916
  const char = input.charCodeAt(index);
8904
- if (char < 128 && ((1342177476 >>> char & 1) === 0 || char >= 64 || char < 32)) continue;
8917
+ if (!isXmlEscapable(char)) {
8918
+ const bound = Math.min(index + 32, length);
8919
+ let next = index + 1;
8920
+ while (next < bound && !isXmlEscapable(input.charCodeAt(next))) next++;
8921
+ if (next < bound) {
8922
+ index = next;
8923
+ continue;
8924
+ }
8925
+ if (next >= length) break;
8926
+ xmlEncodeRegex.lastIndex = next;
8927
+ if (!xmlEncodeRegex.test(input)) break;
8928
+ index = xmlEncodeRegex.lastIndex - 1;
8929
+ continue;
8930
+ }
8905
8931
  if (out === void 0) out = input.substring(0, index);
8906
8932
  else if (last !== index) out += input.substring(last, index);
8907
8933
  if (char < 64) {
8908
- out += xmlCodeMap.get(char);
8909
- last = index + 1;
8934
+ out += getEscape(char);
8935
+ last = index += 1;
8910
8936
  continue;
8911
8937
  }
8912
- const cp = getCodePoint(input, index);
8938
+ const cp = input.codePointAt(index);
8913
8939
  out += `&#x${cp.toString(16)};`;
8914
8940
  if (cp !== char) index++;
8915
- last = index + 1;
8941
+ last = index += 1;
8916
8942
  }
8917
8943
  if (out === void 0) return input;
8918
8944
  if (last < length) out += input.substr(last);
8919
8945
  return out;
8920
8946
  }
8921
8947
  /**
8922
- * Creates a function that escapes all characters matched by the given regular
8923
- * expression using the given map of characters to escape to their entities.
8924
- * @param regex Regular expression to match characters to escape.
8925
- * @param map Map of characters to escape to their entities.
8926
- * @returns Function that escapes all characters matched by the given regular
8927
- * expression using the given map of characters to escape to their entities.
8948
+ * Escape `data` using `re`, mapping each matched character to its entity.
8949
+ * Every match is one UTF-16 code unit, so its index is `lastIndex - 1`.
8950
+ * @param re Global regex matching exactly the characters to escape
8951
+ * (`"`, `&`, `'`, `<`, `>`, `\u00A0` at most).
8952
+ * @param data String to escape.
8928
8953
  */
8929
- function getEscaper(regex, map) {
8930
- return function escape(data) {
8931
- let match;
8932
- let lastIndex = 0;
8933
- let result = "";
8934
- while (match = regex.exec(data)) {
8935
- if (lastIndex !== match.index) result += data.substring(lastIndex, match.index);
8936
- result += map.get(match[0].charCodeAt(0));
8937
- lastIndex = match.index + 1;
8938
- }
8939
- return result + data.substring(lastIndex);
8940
- };
8954
+ function escapeWithRegex(re, data) {
8955
+ re.lastIndex = 0;
8956
+ if (!re.test(data)) return data;
8957
+ let out = "";
8958
+ let last = 0;
8959
+ do {
8960
+ const index = re.lastIndex - 1;
8961
+ if (last !== index) out += data.substring(last, index);
8962
+ const char = data.charCodeAt(index);
8963
+ out += getEscape(char);
8964
+ last = index + 1;
8965
+ } while (re.test(data));
8966
+ return out + data.substring(last);
8941
8967
  }
8968
+ const attributeEscapeRegex = /["&\u{A0}]/gu;
8942
8969
  /**
8943
8970
  * Encodes all characters that have to be escaped in HTML attributes,
8944
8971
  * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
8945
8972
  * @param data String to escape.
8946
8973
  */
8947
- const escapeAttribute = /* #__PURE__ */ getEscaper(/["&\u00A0]/g, /* @__PURE__ */ new Map([
8948
- [34, "&quot;"],
8949
- [38, "&amp;"],
8950
- [160, "&nbsp;"]
8951
- ]));
8974
+ function escapeAttribute(data) {
8975
+ return escapeWithRegex(attributeEscapeRegex, data);
8976
+ }
8977
+ const textEscapeRegex = /[&<>\u{A0}]/gu;
8952
8978
  /**
8953
8979
  * Encodes all characters that have to be escaped in HTML text,
8954
8980
  * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
8955
8981
  * @param data String to escape.
8956
8982
  */
8957
- const escapeText = /* #__PURE__ */ getEscaper(/[&<>\u00A0]/g, /* @__PURE__ */ new Map([
8958
- [38, "&amp;"],
8959
- [60, "&lt;"],
8960
- [62, "&gt;"],
8961
- [160, "&nbsp;"]
8962
- ]));
8983
+ function escapeText(data) {
8984
+ return escapeWithRegex(textEscapeRegex, data);
8985
+ }
8963
8986
  //#endregion
8964
8987
  //#region ../../node_modules/.pnpm/dom-serializer@3.1.1/node_modules/dom-serializer/dist/foreign-names.js
8965
8988
  /**
@@ -24244,6 +24267,7 @@ function readAssessmentItemOrder(inputXml) {
24244
24267
  } else if (localName === "value" && capture === "correct") {}
24245
24268
  if (capture === "stimulus" && stack.length > stimulusCaptureDepth && localName !== "orderInteraction") stimulusBuf.push(buildOpeningTag$2(tag, localName));
24246
24269
  else if (capture === "prompt" && localName !== "prompt") promptBuf.push(buildOpeningTag$2(tag, localName));
24270
+ else if (capture === "choice" && localName !== "simpleChoice") choiceBuf.push(buildOpeningTag$2(tag, localName));
24247
24271
  });
24248
24272
  parser.on("text", (text) => {
24249
24273
  if (capture === "stimulus") stimulusBuf.push(text);
@@ -24267,6 +24291,8 @@ function readAssessmentItemOrder(inputXml) {
24267
24291
  capture = null;
24268
24292
  } else if (capture === "prompt" && localName !== "prompt") {
24269
24293
  if (!QTI_VOID_ELEMENTS.has(localName.toLowerCase())) promptBuf.push(`</${localName}>`);
24294
+ } else if (capture === "choice" && localName !== "simpleChoice") {
24295
+ if (!QTI_VOID_ELEMENTS.has(localName.toLowerCase())) choiceBuf.push(`</${localName}>`);
24270
24296
  } else if (localName === "simpleChoice" && capture === "choice") {
24271
24297
  const text = normalizeWhitespace(choiceBuf.join(""));
24272
24298
  if (currentChoiceId) {
@@ -24669,14 +24695,14 @@ function readAssessmentItemHotspot(inputXml) {
24669
24695
  * Convert QTI shape coordinates to Learnosity polygon coordinates
24670
24696
  * QTI uses absolute pixel coordinates, Learnosity uses percentage coordinates
24671
24697
  */
24672
- function convertShapeToPolygon(choice, imageWidth, imageHeight, diagnostics) {
24698
+ function convertShapeToPolygon(choice, imageWidth, imageHeight, diagnostics, sourceFile) {
24673
24699
  const coords = choice.coords.split(",").map((c) => parseFloat(c.trim()));
24674
24700
  if (choice.shape === "circle") {
24675
24701
  if (coords.length !== 3) {
24676
24702
  diagnostics.push({
24677
24703
  code: DiagnosticCode.LRN_SCHEMA_INVALID,
24678
24704
  level: "error",
24679
- file: `hotspotChoice[@identifier="${choice.identifier}"]`,
24705
+ file: sourceFile ?? `hotspotChoice[@identifier="${choice.identifier}"]`,
24680
24706
  message: `Invalid circle coords for ${choice.identifier}: expected 3 values (x,y,radius), got ${coords.length}`
24681
24707
  });
24682
24708
  return null;
@@ -24699,7 +24725,7 @@ function convertShapeToPolygon(choice, imageWidth, imageHeight, diagnostics) {
24699
24725
  diagnostics.push({
24700
24726
  code: DiagnosticCode.LRN_SCHEMA_INVALID,
24701
24727
  level: "error",
24702
- file: `hotspotChoice[@identifier="${choice.identifier}"]`,
24728
+ file: sourceFile ?? `hotspotChoice[@identifier="${choice.identifier}"]`,
24703
24729
  message: `Invalid rect coords for ${choice.identifier}: expected 4 values (x1,y1,x2,y2), got ${coords.length}`
24704
24730
  });
24705
24731
  return null;
@@ -24728,7 +24754,7 @@ function convertShapeToPolygon(choice, imageWidth, imageHeight, diagnostics) {
24728
24754
  diagnostics.push({
24729
24755
  code: DiagnosticCode.LRN_SCHEMA_INVALID,
24730
24756
  level: "error",
24731
- file: `hotspotChoice[@identifier="${choice.identifier}"]`,
24757
+ file: sourceFile ?? `hotspotChoice[@identifier="${choice.identifier}"]`,
24732
24758
  message: `Invalid poly coords for ${choice.identifier}: expected at least 6 values (3 points) in pairs, got ${coords.length}`
24733
24759
  });
24734
24760
  return null;
@@ -24744,7 +24770,7 @@ function convertShapeToPolygon(choice, imageWidth, imageHeight, diagnostics) {
24744
24770
  diagnostics.push({
24745
24771
  code: DiagnosticCode.LRN_SCHEMA_INVALID,
24746
24772
  level: "error",
24747
- file: `hotspotChoice[@identifier="${choice.identifier}"]`,
24773
+ file: sourceFile ?? `hotspotChoice[@identifier="${choice.identifier}"]`,
24748
24774
  message: `Invalid ellipse coords for ${choice.identifier}: expected 4 values (cx,cy,rx,ry), got ${coords.length}`
24749
24775
  });
24750
24776
  return null;
@@ -24766,7 +24792,7 @@ function convertShapeToPolygon(choice, imageWidth, imageHeight, diagnostics) {
24766
24792
  diagnostics.push({
24767
24793
  code: DiagnosticCode.LRN_SCHEMA_INVALID,
24768
24794
  level: "error",
24769
- file: `hotspotChoice[@identifier="${choice.identifier}"]`,
24795
+ file: sourceFile ?? `hotspotChoice[@identifier="${choice.identifier}"]`,
24770
24796
  message: `Unsupported shape type: ${choice.shape}`
24771
24797
  });
24772
24798
  return null;
@@ -24839,7 +24865,7 @@ function convertHotspotToLearnosity(inputXml, diagnostics, lomTags, organisation
24839
24865
  const areas = [];
24840
24866
  const choiceIdToIndex = /* @__PURE__ */ new Map();
24841
24867
  for (const choice of parsed.hotspotChoices) {
24842
- const polygon = convertShapeToPolygon(choice, parsed.imageWidth, parsed.imageHeight, diagnostics);
24868
+ const polygon = convertShapeToPolygon(choice, parsed.imageWidth, parsed.imageHeight, diagnostics, sourceFile);
24843
24869
  if (polygon) {
24844
24870
  choiceIdToIndex.set(choice.identifier, areas.length);
24845
24871
  areas.push(polygon);
@@ -31294,4 +31320,4 @@ function formatDiagnosticsSummaryTable(diagnostics) {
31294
31320
  //#endregion
31295
31321
  export { mapLearnosityToAst as _, require_cli_table3 as a, parseLearnosityItem as b, transformForwardAssetUrlsInXml as c, generateItemReference as d, md5hex as f, downgradeAssessmentTestToQti21 as g, escapeXml as h, chalk as i, convertQtiAssessmentItemToLearnosity as l, serializeAssessmentItem as m, formatDiagnosticsSummaryTable as n, require_string_width as o, require_saxes as p, formatDiagnosticsTable as r, writeDiagnostics as s, countErrors as t, parseMetadataTags as u, normalizeXhtmlVoidElements as v, DiagnosticCode as x, sanitizeHtmlContent as y };
31296
31322
 
31297
- //# sourceMappingURL=table-DjOn2Tsk.js.map
31323
+ //# sourceMappingURL=table-7b-8MN2z.js.map