@learnosity/lib-qti-converter 0.13.0 → 0.15.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 (33) hide show
  1. package/docs/EXAMPLES.md +48 -34
  2. package/docs/GETTING_STARTED.md +43 -28
  3. package/docs/LEARNOSITY_BUNDLE_FORMAT.md +1 -1
  4. package/docs/QTI_METADATA_TO_TAGS.md +47 -4
  5. package/docs/TAGS_TO_QTI_METADATA.md +8 -7
  6. package/package.json +1 -1
  7. package/packages/cli/dist/{batchProcessors-DgiDpfpP.js → batchProcessors-B6Xmhfaz.js} +32 -6
  8. package/packages/cli/dist/batchProcessors-B6Xmhfaz.js.map +1 -0
  9. package/packages/cli/dist/batchWorker.js +1 -1
  10. package/packages/cli/dist/{learnosityToQti-CIj5603P.js → learnosityToQti-hFKA3KnZ.js} +4 -4
  11. package/packages/cli/dist/{learnosityToQti-CIj5603P.js.map → learnosityToQti-hFKA3KnZ.js.map} +1 -1
  12. package/packages/cli/dist/{learnosityToQtiPackage-n6nGGr32.js → learnosityToQtiPackage-DI7bYisT.js} +4 -4
  13. package/packages/cli/dist/{learnosityToQtiPackage-n6nGGr32.js.map → learnosityToQtiPackage-DI7bYisT.js.map} +1 -1
  14. package/packages/cli/dist/main.js +4 -4
  15. package/packages/cli/dist/{pathUtils-mTQZ0wYS.js → pathUtils-DkptaCiz.js} +22 -7
  16. package/packages/cli/dist/{pathUtils-mTQZ0wYS.js.map → pathUtils-DkptaCiz.js.map} +1 -1
  17. package/packages/cli/dist/{qtiPackageToLearnosity-B4cD8jUw.js → qtiPackageToLearnosity-JDifZn8o.js} +14 -8
  18. package/packages/cli/dist/qtiPackageToLearnosity-JDifZn8o.js.map +1 -0
  19. package/packages/cli/dist/{qtiToLearnosity-DDjcpShJ.js → qtiToLearnosity-Be0s-5Dr.js} +6 -5
  20. package/packages/cli/dist/qtiToLearnosity-Be0s-5Dr.js.map +1 -0
  21. package/packages/cli/dist/{resolveOptions-Czapkfc1.js → resolveOptions-BotCofhl.js} +15 -5
  22. package/packages/cli/dist/resolveOptions-BotCofhl.js.map +1 -0
  23. package/packages/cli/dist/{table-DTSv0atR.js → table-DlY4LGmL.js} +98 -43
  24. package/packages/cli/dist/table-DlY4LGmL.js.map +1 -0
  25. package/packages/core/dist/index.d.ts +10 -4
  26. package/packages/core/dist/index.js +128 -46
  27. package/packages/core/dist/node.d.ts +13 -5
  28. package/packages/core/dist/node.js +129 -46
  29. package/packages/cli/dist/batchProcessors-DgiDpfpP.js.map +0 -1
  30. package/packages/cli/dist/qtiPackageToLearnosity-B4cD8jUw.js.map +0 -1
  31. package/packages/cli/dist/qtiToLearnosity-DDjcpShJ.js.map +0 -1
  32. package/packages/cli/dist/resolveOptions-Czapkfc1.js.map +0 -1
  33. package/packages/cli/dist/table-DTSv0atR.js.map +0 -1
@@ -251,13 +251,16 @@ type OutputFormat = 'dir' | 'zip' | 'stdout';
251
251
  */
252
252
  type DiagnosticsOutput = 'stderr' | 'file' | 'both' | 'none';
253
253
  /**
254
- * Item reference source for QTI → Learnosity conversion
254
+ * Item reference source for QTI → Learnosity conversion.
255
+ * `'itemIdentifier'` (default) uses the QTI `identifier` attribute.
256
+ * `'qti'` is a deprecated alias of `'itemIdentifier'`.
255
257
  */
256
- type ItemReferenceSource = 'sourceFilename' | 'qti' | 'uuid';
258
+ type ItemReferenceSource = 'sourceFilename' | 'qti' | 'uuid' | 'itemIdentifier';
257
259
  /**
258
- * Item filename source for output JSON file naming (QTI → Learnosity)
260
+ * Item filename source for output JSON file naming (QTI → Learnosity).
261
+ * `'qti'` is a deprecated alias of `'itemIdentifier'`.
259
262
  */
260
- type ItemFilenameSource = 'sourceFilename' | 'qti';
263
+ type ItemFilenameSource = 'sourceFilename' | 'qti' | 'itemIdentifier';
261
264
  /**
262
265
  * Shared conversion options
263
266
  */
@@ -278,6 +281,7 @@ interface ConversionOptions {
278
281
  preserveAssetFilenames?: boolean;
279
282
  itemReferenceSource?: ItemReferenceSource;
280
283
  truncateTags?: boolean;
284
+ splitCsvTags?: boolean;
281
285
  /**
282
286
  * Optional filesystem access for passage/LOM lookups. Omit for in-memory /
283
287
  * browser use (disk lookups become no-ops). Node callers can inject
@@ -2574,6 +2578,7 @@ interface ConvertOptions {
2574
2578
  sourceHrefBase?: string;
2575
2579
  itemReferenceSource?: ItemReferenceSource;
2576
2580
  truncateTags?: boolean;
2581
+ splitCsvTags?: boolean;
2577
2582
  fileAccess?: FileAccess;
2578
2583
  packageRoot?: string;
2579
2584
  }
@@ -2626,6 +2631,7 @@ interface ConvertQtiPackageToLearnosityBundleOptions {
2626
2631
  itemFilenameSource?: ItemFilenameSource;
2627
2632
  packageVersion?: string;
2628
2633
  truncateTags?: boolean;
2634
+ splitCsvTags?: boolean;
2629
2635
  /** Base directory for resolving item source paths (Node disk conversion). */
2630
2636
  sourceDir?: string;
2631
2637
  /** Injected filesystem access for passage/LOM lookups (Node only). */
@@ -22992,6 +22992,34 @@ function md5hex(input) {
22992
22992
  return hex;
22993
22993
  }
22994
22994
  //#endregion
22995
+ //#region src/qti-to-learnosity/utils/generateQuestionReference.ts
22996
+ /**
22997
+ * Shared utility for generating Learnosity question references.
22998
+ */
22999
+ /**
23000
+ * Generate a Learnosity question reference from the resolved item reference and
23001
+ * the question's position within that item.
23002
+ *
23003
+ * The reference is `md5hex(`${itemRef}_${index}`)`, which guarantees it is both
23004
+ * unique (scoped to the item plus the per-item ordinal) and repeatable.
23005
+ *
23006
+ * - `itemRef` is the ALREADY-RESOLVED Learnosity item reference. Because it is
23007
+ * resolved upstream, the question reference automatically inherits the user's
23008
+ * `--item-reference-source` choice (item `identifier`, a `uuid`, or the source
23009
+ * filename) without this helper needing to re-read that option.
23010
+ * - `index` is the question's 1-BASED ordinal WITHIN the item. It is reset per
23011
+ * item, not a global counter: the first question in an item is `1`, the second
23012
+ * `2`, and so on. Single-question items always use `1` (a lone question is
23013
+ * `_1`), so there is no bare, unsuffixed variant.
23014
+ *
23015
+ * @param itemRef Resolved Learnosity item reference.
23016
+ * @param index 1-based ordinal of the question within the item.
23017
+ * @returns A 32-character lowercase hex MD5 question reference.
23018
+ */
23019
+ function generateQuestionReference(itemRef, index) {
23020
+ return md5hex(`${itemRef}_${index}`);
23021
+ }
23022
+ //#endregion
22995
23023
  //#region src/qti-to-learnosity/utils/mediaFeature.ts
22996
23024
  /**
22997
23025
  * Build a stable UUID-shaped identifier for a media feature.
@@ -23361,12 +23389,16 @@ function transformAssetUrls(html, options) {
23361
23389
  //#endregion
23362
23390
  //#region src/qti-to-learnosity/utils/generateItemReference.ts
23363
23391
  /**
23364
- * Generate item reference based on the configured source
23392
+ * Generate item reference based on the configured source.
23393
+ *
23394
+ * - `'itemIdentifier'` (default) and its deprecated alias `'qti'`, as well as an
23395
+ * omitted source, return the QTI `identifier`.
23396
+ * - `'uuid'` returns an MD5 hash of the QTI `identifier`.
23397
+ * - `'sourceFilename'` derives the reference from the source file name.
23365
23398
  */
23366
23399
  function generateItemReference(qtiIdentifier, itemReferenceSource, sourceFile) {
23367
- if (itemReferenceSource === "qti") return qtiIdentifier;
23368
23400
  if (itemReferenceSource === "uuid") return md5hex(qtiIdentifier);
23369
- if (sourceFile) return (sourceFile.split(/[\\/]/).pop() ?? sourceFile).replace(/\.xml$/i, "");
23401
+ if (itemReferenceSource === "sourceFilename" && sourceFile) return (sourceFile.split(/[\\/]/).pop() ?? sourceFile).replace(/\.xml$/i, "");
23370
23402
  return qtiIdentifier;
23371
23403
  }
23372
23404
  //#endregion
@@ -23511,7 +23543,7 @@ function convertMatchToLearnosity(inputXml, diagnostics, lomTags, organisationId
23511
23543
  preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
23512
23544
  sourceHrefBase: assetTransformContext?.sourceHrefBase
23513
23545
  };
23514
- const questionRef = md5hex(itemRef);
23546
+ const questionRef = generateQuestionReference(itemRef, 1);
23515
23547
  const stems = parsed.stems.map((stem) => transformAssetUrls(stem.text, {
23516
23548
  organisationId,
23517
23549
  mediaVault,
@@ -23933,7 +23965,7 @@ function convertGapMatchToLearnosity(inputXml, diagnostics, lomTags, organisatio
23933
23965
  preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
23934
23966
  sourceHrefBase: assetTransformContext?.sourceHrefBase
23935
23967
  };
23936
- const questionRef = md5hex(itemRef);
23968
+ const questionRef = generateQuestionReference(itemRef, 1);
23937
23969
  const possibleResponses = parsed.gapTexts.map((gt) => transformAssetUrls(gt.text, {
23938
23970
  organisationId,
23939
23971
  mediaVault,
@@ -24401,7 +24433,7 @@ function convertInlineChoiceToLearnosity(inputXml, diagnostics, lomTags, organis
24401
24433
  preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
24402
24434
  sourceHrefBase: assetTransformContext?.sourceHrefBase
24403
24435
  };
24404
- const questionRef = md5hex(itemRef);
24436
+ const questionRef = generateQuestionReference(itemRef, 1);
24405
24437
  const possibleResponses = parsed.interactions.map((interaction) => interaction.choices.map((choice) => transformAssetUrls(choice.text, transformOpts)));
24406
24438
  const validationValue = buildValidationValues(parsed.interactions, parsed.responseDeclarations, diagnostics, transformOpts, sourceFile);
24407
24439
  if (!validationValue) return { diagnostics };
@@ -24680,7 +24712,7 @@ function convertOrderToLearnosity(inputXml, diagnostics, lomTags, organisationId
24680
24712
  preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
24681
24713
  sourceHrefBase: assetTransformContext?.sourceHrefBase
24682
24714
  };
24683
- const questionRef = md5hex(itemRef);
24715
+ const questionRef = generateQuestionReference(itemRef, 1);
24684
24716
  const stimulus = transformAssetUrls(parsed.stimulusText ?? "", {
24685
24717
  organisationId,
24686
24718
  mediaVault,
@@ -25131,7 +25163,7 @@ function convertHotspotToLearnosity(inputXml, diagnostics, lomTags, organisation
25131
25163
  preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
25132
25164
  sourceHrefBase: assetTransformContext?.sourceHrefBase
25133
25165
  };
25134
- const questionRef = md5hex(itemRef);
25166
+ const questionRef = generateQuestionReference(itemRef, 1);
25135
25167
  const stimulus = buildHotspotStimulus(parsed, organisationId, mediaVault, customAssetUrl, transformContext);
25136
25168
  const imageSource = organisationId ? transformUrl(parsed.imageSource, organisationId, mediaVault, customAssetUrl, transformContext) : parsed.imageSource;
25137
25169
  const areas = [];
@@ -25429,7 +25461,7 @@ function convertHottextToLearnosity(inputXml, diagnostics, lomTags, organisation
25429
25461
  preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
25430
25462
  sourceHrefBase: assetTransformContext?.sourceHrefBase
25431
25463
  };
25432
- const questionRef = md5hex(itemRef);
25464
+ const questionRef = generateQuestionReference(itemRef, 1);
25433
25465
  if (parsed.shuffle) diagnostics.push({
25434
25466
  code: DiagnosticCode.QTI_SHUFFLE_NOT_SUPPORTED,
25435
25467
  level: "warning",
@@ -25941,8 +25973,9 @@ function convertMcqToLearnosity(inputXml, diagnostics, lomTags, sourceFile, orga
25941
25973
  const questions = [];
25942
25974
  const widgets = [];
25943
25975
  const questionSpans = [];
25944
- for (const interaction of parsed.interactions) {
25945
- const questionRef = md5hex(interaction.responseIdentifier);
25976
+ for (let i = 0; i < parsed.interactions.length; i++) {
25977
+ const interaction = parsed.interactions[i];
25978
+ const questionRef = generateQuestionReference(itemRef, i + 1);
25946
25979
  const stimulus = interaction.stimulusText ? transformAssetUrls(interaction.stimulusText, {
25947
25980
  organisationId,
25948
25981
  mediaVault,
@@ -26386,7 +26419,7 @@ function convertShorttextToLearnosity(parsed, diagnostics, lomTags, organisation
26386
26419
  preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
26387
26420
  sourceHrefBase: assetTransformContext?.sourceHrefBase
26388
26421
  };
26389
- const questionRef = md5hex(parsed.responseIdentifier ?? parsed.identifier);
26422
+ const questionRef = generateQuestionReference(itemRef, 1);
26390
26423
  const stimulus = normalizeFinalText(transformAssetUrls((parsed.templateText || "").replace(/{{response}}(?:\s*<\/[^>]+>)*\s*$/, "").trim(), {
26391
26424
  organisationId,
26392
26425
  mediaVault,
@@ -26480,7 +26513,7 @@ function convertClozetextToLearnosity(parsed, diagnostics, lomTags, organisation
26480
26513
  preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
26481
26514
  sourceHrefBase: assetTransformContext?.sourceHrefBase
26482
26515
  };
26483
- const questionRef = md5hex(parsed.responseIdentifier ?? parsed.identifier);
26516
+ const questionRef = generateQuestionReference(itemRef, 1);
26484
26517
  const stimulus = parsed.stimulusText ? normalizeFinalText(transformAssetUrls(parsed.stimulusText, {
26485
26518
  organisationId,
26486
26519
  mediaVault,
@@ -26730,7 +26763,7 @@ function readAssessmentItemExtendedText(inputXml) {
26730
26763
  /**
26731
26764
  * Build multi-interaction extended text item (multiple longtextV2 questions)
26732
26765
  */
26733
- function buildMultiExtendedTextItem(parsed, inputXml, stimulusOverride, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext) {
26766
+ function buildMultiExtendedTextItem(parsed, _inputXml, stimulusOverride, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext) {
26734
26767
  const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier ?? "unknown", itemReferenceSource, sourceFile);
26735
26768
  const transformContext = {
26736
26769
  finalItemReference: itemRef,
@@ -26740,9 +26773,8 @@ function buildMultiExtendedTextItem(parsed, inputXml, stimulusOverride, diagnost
26740
26773
  const questions = [];
26741
26774
  const widgets = [];
26742
26775
  const questionSpans = [];
26743
- const responseIdentifiers = extractResponseIdentifiers(inputXml, "extendedTextInteraction");
26744
26776
  for (let i = 0; i < stimulusOverride.length; i++) {
26745
- const questionRef = md5hex(responseIdentifiers[i] || `RESPONSE_${i}`);
26777
+ const questionRef = generateQuestionReference(itemRef, i + 1);
26746
26778
  const stimulus = transformAssetUrls(stimulusOverride[i], {
26747
26779
  organisationId,
26748
26780
  mediaVault,
@@ -26784,16 +26816,6 @@ function buildMultiExtendedTextItem(parsed, inputXml, stimulusOverride, diagnost
26784
26816
  };
26785
26817
  }
26786
26818
  /**
26787
- * Extract responseIdentifier values from interactions in XML
26788
- */
26789
- function extractResponseIdentifiers(inputXml, interactionTag) {
26790
- const responseIdentifiers = [];
26791
- const interactionPattern = new RegExp(`<${assertXmlTagName(interactionTag)}[^>]+responseIdentifier=["']([^"']+)["']`, "g");
26792
- let match;
26793
- while ((match = interactionPattern.exec(inputXml)) !== null) responseIdentifiers.push(match[1]);
26794
- return responseIdentifiers;
26795
- }
26796
- /**
26797
26819
  * Convert extended text (extendedTextInteraction) to Learnosity longtextV2
26798
26820
  * TASK 036: Added stimulusOverride parameter for composite items
26799
26821
  */
@@ -26809,7 +26831,7 @@ function convertExtendedTextToLearnosity(inputXml, diagnostics, lomTags, sourceF
26809
26831
  preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
26810
26832
  sourceHrefBase: assetTransformContext?.sourceHrefBase
26811
26833
  };
26812
- const questionRef = md5hex(parsed.responseIdentifier ?? parsed.identifier ?? "unknown");
26834
+ const questionRef = generateQuestionReference(itemRef, 1);
26813
26835
  const stimulusRaw = stimulusOverride && stimulusOverride.length === 1 ? stimulusOverride[0] : parsed.stimulusText;
26814
26836
  const stimulus = stimulusRaw ? transformAssetUrls(stimulusRaw, {
26815
26837
  organisationId,
@@ -27185,7 +27207,7 @@ function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, org
27185
27207
  };
27186
27208
  });
27187
27209
  const validationValue = buildValidationValue$1(parsed.hotspots, parsed.correctPairs, gapImgIdToResponse);
27188
- const questionRef = md5hex(parsed.identifier ?? "graphicgapmatch");
27210
+ const questionRef = generateQuestionReference(itemRef, 1);
27189
27211
  const question = {
27190
27212
  type: "imageclozeassociationV2",
27191
27213
  image: {
@@ -27559,7 +27581,7 @@ function convertDrawingToLearnosity(inputXml, diagnostics, lomTags, organisation
27559
27581
  preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
27560
27582
  sourceHrefBase: assetTransformContext?.sourceHrefBase
27561
27583
  };
27562
- const questionRef = md5hex(itemRef + (parsed.responseIdentifier ?? "drawing"));
27584
+ const questionRef = generateQuestionReference(itemRef, 1);
27563
27585
  const questionData = { type: "drawing" };
27564
27586
  const stimulus = buildDrawingStimulus(parsed, organisationId, mediaVault, customAssetUrl, transformContext);
27565
27587
  if (stimulus !== void 0) questionData.stimulus = stimulus;
@@ -27872,7 +27894,7 @@ function convertAssociationToLearnosity(inputXml, diagnostics, lomTags, organisa
27872
27894
  preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
27873
27895
  sourceHrefBase: assetTransformContext?.sourceHrefBase
27874
27896
  };
27875
- const questionRef = md5hex(itemRef);
27897
+ const questionRef = generateQuestionReference(itemRef, 1);
27876
27898
  const stimulus = transformAssetUrls(parsed.stimulusText ? `<p>${parsed.stimulusText}</p>` : "", {
27877
27899
  organisationId,
27878
27900
  mediaVault,
@@ -28339,6 +28361,7 @@ function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, or
28339
28361
  }
28340
28362
  const allQuestions = [];
28341
28363
  const allWidgets = [];
28364
+ let placeholderRefCounter = 0;
28342
28365
  const processResult = (result, subDiagnostics) => {
28343
28366
  if (result.item) {
28344
28367
  allQuestions.push(...result.item.questions);
@@ -28395,7 +28418,7 @@ function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, or
28395
28418
  if (groupEntries.length > 0) {
28396
28419
  const correctResponses = [];
28397
28420
  for (const entry of groupEntries) if (entry.correctResponse) correctResponses.push(entry.correctResponse);
28398
- const questionRef = md5hex(group.responseIdentifiers[0] || (parsed.identifier ?? "textentry"));
28421
+ const questionRef = `__mixed_placeholder_${placeholderRefCounter++}`;
28399
28422
  const templateParts = [];
28400
28423
  const groupWrapperOpen = group.wrapperOpens[0];
28401
28424
  if (groupWrapperOpen) templateParts.push(groupWrapperOpen);
@@ -28559,6 +28582,17 @@ function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, or
28559
28582
  });
28560
28583
  return { diagnostics };
28561
28584
  }
28585
+ const reassignedWidgets = /* @__PURE__ */ new Set();
28586
+ allQuestions.forEach((question, idx) => {
28587
+ const oldRef = question.reference;
28588
+ const newRef = generateQuestionReference(itemRef, idx + 1);
28589
+ const widget = allWidgets.find((w) => w.widget_type === "response" && w.reference === oldRef && !reassignedWidgets.has(w));
28590
+ if (widget) {
28591
+ widget.reference = newRef;
28592
+ reassignedWidgets.add(widget);
28593
+ }
28594
+ question.reference = newRef;
28595
+ });
28562
28596
  const allFeatures = [];
28563
28597
  if (hasPassageContent(inputXml)) {
28564
28598
  if (extractPassageFromItemBody(inputXml)) {
@@ -28833,6 +28867,18 @@ function readAssessmentItemPassage(inputXml) {
28833
28867
  */
28834
28868
  const MAX_TAG_LENGTH = 255;
28835
28869
  /**
28870
+ * Split a tag value on commas into separate trimmed values.
28871
+ *
28872
+ * When `splitCsvTags` is false the value is returned unchanged as a single
28873
+ * element. When true, the value is split on literal commas, each part is
28874
+ * trimmed, and empty parts (from leading/trailing/double commas) are dropped.
28875
+ * A value without a comma yields a single trimmed element.
28876
+ */
28877
+ function splitTagValue(value, splitCsvTags) {
28878
+ if (!splitCsvTags) return [value];
28879
+ return value.split(",").map((part) => part.trim()).filter((part) => part.length > 0);
28880
+ }
28881
+ /**
28836
28882
  * Validate and optionally truncate tag types and tag names
28837
28883
  *
28838
28884
  * @param tags - Tags to validate
@@ -28894,9 +28940,10 @@ function validateAndProcessTags(tags, options = {}) {
28894
28940
  * Extracts csm:labelledGUID entries as Learnosity tags
28895
28941
  *
28896
28942
  * @param metadataXml - XML containing Common Cartridge metadata
28943
+ * @param splitCsvTags - Split comma-separated GUID values into separate elements (default: true)
28897
28944
  * @returns Tags object with type->name[] mapping
28898
28945
  */
28899
- function parseCommonCartridgeTags(metadataXml) {
28946
+ function parseCommonCartridgeTags(metadataXml, splitCsvTags = true) {
28900
28947
  const tags = {};
28901
28948
  const stack = [];
28902
28949
  let inLabel = false;
@@ -28925,7 +28972,7 @@ function parseCommonCartridgeTags(metadataXml) {
28925
28972
  inLabel = false;
28926
28973
  } else if (localName === "GUID" && inGuid) {
28927
28974
  const guidValue = textBuf.join("").trim();
28928
- if (currentLabel && guidValue) addTagValue(tags, currentLabel, guidValue);
28975
+ if (currentLabel && guidValue) addTagValue(tags, currentLabel, guidValue, splitCsvTags);
28929
28976
  inGuid = false;
28930
28977
  } else if (localName === "labelledGUID") currentLabel = "";
28931
28978
  stack.pop();
@@ -28937,17 +28984,23 @@ function parseCommonCartridgeTags(metadataXml) {
28937
28984
  return tags;
28938
28985
  }
28939
28986
  /**
28940
- * Add a tag value to the tags object with deduplication
28987
+ * Add a tag value to the tags object, splitting comma-separated values when
28988
+ * enabled and deduplicating in insertion order.
28989
+ *
28990
+ * @param splitCsvTags - Split a comma-separated value into separate elements (default: true)
28941
28991
  */
28942
- function addTagValue(tags, source, value) {
28943
- tags[source] = tags[source] ?? [];
28944
- if (!tags[source].includes(value)) tags[source].push(value);
28992
+ function addTagValue(tags, source, value, splitCsvTags = true) {
28993
+ const existing = tags[source] = tags[source] ?? [];
28994
+ for (const part of splitTagValue(value, splitCsvTags)) if (!existing.includes(part)) existing.push(part);
28945
28995
  }
28946
28996
  /**
28947
28997
  * Parse LOM XML and extract tags for Learnosity
28948
28998
  * Extracts classification/taxonPath entries grouped by source langstring
28999
+ *
29000
+ * @param lomXml - XML containing LOM metadata
29001
+ * @param splitCsvTags - Split comma-separated taxon entry values into separate elements (default: true)
28949
29002
  */
28950
- function parseLomXml(lomXml) {
29003
+ function parseLomXml(lomXml, splitCsvTags = true) {
28951
29004
  const tags = {};
28952
29005
  const stack = [];
28953
29006
  let inTaxonPathSource = false;
@@ -28979,7 +29032,7 @@ function parseLomXml(lomXml) {
28979
29032
  inTaxonPathSource = false;
28980
29033
  } else if (inTaxonEntry) {
28981
29034
  const value = textBuf.join("").trim();
28982
- if (value && currentSource) addTagValue(tags, currentSource, value);
29035
+ if (value && currentSource) addTagValue(tags, currentSource, value, splitCsvTags);
28983
29036
  inTaxonEntry = false;
28984
29037
  }
28985
29038
  }
@@ -29004,8 +29057,9 @@ function parseLomXml(lomXml) {
29004
29057
  * @returns Merged tags object and diagnostics
29005
29058
  */
29006
29059
  function parseMetadataTags(metadataXml, options = {}) {
29007
- const lomTags = parseLomXml(metadataXml);
29008
- const ccTags = parseCommonCartridgeTags(metadataXml);
29060
+ const splitCsvTags = options.splitCsvTags ?? true;
29061
+ const lomTags = parseLomXml(metadataXml, splitCsvTags);
29062
+ const ccTags = parseCommonCartridgeTags(metadataXml, splitCsvTags);
29009
29063
  const mergedTags = { ...lomTags };
29010
29064
  for (const [tagType, tagValues] of Object.entries(ccTags)) {
29011
29065
  const values = tagValues;
@@ -29078,7 +29132,7 @@ function convertUploadToLearnosity(inputXml, diagnostics, lomTags, organisationI
29078
29132
  preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
29079
29133
  sourceHrefBase: assetTransformContext?.sourceHrefBase
29080
29134
  };
29081
- const questionRef = md5hex(itemRef + (parsed.responseIdentifier ?? "fileupload"));
29135
+ const questionRef = generateQuestionReference(itemRef, 1);
29082
29136
  const questionData = { type: "fileupload" };
29083
29137
  if (parsed.stimulus) try {
29084
29138
  questionData.stimulus = transformAssetUrls(parsed.stimulus, {
@@ -29397,6 +29451,7 @@ function convertQtiAssessmentItemToLearnosity(inputXml, opts = {}) {
29397
29451
  if (lomXml) try {
29398
29452
  const tagResult = parseMetadataTags(lomXml, {
29399
29453
  truncateTags: opts.truncateTags,
29454
+ splitCsvTags: opts.splitCsvTags,
29400
29455
  filePath: opts.inputPath
29401
29456
  });
29402
29457
  lomTags = tagResult.tags;
@@ -29537,11 +29592,13 @@ function convertQtiToLearnosity(input, opts) {
29537
29592
  const result = convertQtiAssessmentItemToLearnosity(input, {
29538
29593
  qtiVersion: opts.qtiVersion,
29539
29594
  inputPath: opts.inputPath,
29595
+ sourceFile: opts.inputPath,
29540
29596
  organisationId: opts.organisationId,
29541
29597
  mediaVault: opts.mediaVault,
29542
29598
  customAssetUrl: opts.customAssetUrl,
29543
29599
  preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
29544
29600
  itemReferenceSource: opts.itemReferenceSource,
29601
+ splitCsvTags: opts.splitCsvTags,
29545
29602
  fileAccess: opts.fileAccess
29546
29603
  });
29547
29604
  return Promise.resolve({
@@ -31349,6 +31406,15 @@ var AssetFilenameRegistry = class {
31349
31406
  * - Does not write outputs if any error diagnostics exist
31350
31407
  * - Deterministic ordering and stable JSON serialization
31351
31408
  */
31409
+ /**
31410
+ * Normalize an item reference / filename source for comparison and defaulting.
31411
+ * `'qti'` is a deprecated alias of `'itemIdentifier'`, and an omitted value
31412
+ * defaults to `'itemIdentifier'`.
31413
+ */
31414
+ function normalizeRefSource(source) {
31415
+ if (source === "qti" || source === void 0) return "itemIdentifier";
31416
+ return source;
31417
+ }
31352
31418
  const utf8Decoder = new TextDecoder();
31353
31419
  /** Decode entry bytes as UTF-8 (works for both Uint8Array and Node Buffer). */
31354
31420
  function decodeUtf8(data) {
@@ -31400,6 +31466,17 @@ function readAssessmentItemIdentifier(inputXml, fallback) {
31400
31466
  } catch {}
31401
31467
  return identifier;
31402
31468
  }
31469
+ function readAssessmentTestIdentifier(inputXml, fallback) {
31470
+ let identifier = fallback;
31471
+ const parser = new import_saxes.SaxesParser({ xmlns: true });
31472
+ parser.on("opentag", (tag) => {
31473
+ if ((tag.local ?? tag.name) === "assessmentTest") identifier = getAttr$5(tag, "identifier") ?? fallback;
31474
+ });
31475
+ try {
31476
+ parser.write(inputXml).close();
31477
+ } catch {}
31478
+ return identifier;
31479
+ }
31403
31480
  function uniqueItemReference(baseReference, sourceHref, items) {
31404
31481
  if (!items.has(baseReference)) return baseReference;
31405
31482
  const readableCandidate = `${baseReference}_${normalizeHref(sourceHref).split("/").at(-1)?.replace(/\.xml$/i, "") ?? "item"}`;
@@ -31624,6 +31701,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
31624
31701
  customAssetUrl: opts?.customAssetUrl,
31625
31702
  preserveAssetFilenames: opts?.preserveAssetFilenames ?? false,
31626
31703
  itemReferenceSource: opts?.itemReferenceSource,
31704
+ splitCsvTags: opts?.splitCsvTags,
31627
31705
  fileAccess: opts?.fileAccess,
31628
31706
  packageRoot: opts?.sourceDir,
31629
31707
  finalItemReference,
@@ -31660,6 +31738,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
31660
31738
  if (itemResource.metadataXml) try {
31661
31739
  const tagResult = parseMetadataTags(itemResource.metadataXml, {
31662
31740
  truncateTags: opts?.truncateTags,
31741
+ splitCsvTags: opts?.splitCsvTags,
31663
31742
  filePath: itemResource.href
31664
31743
  });
31665
31744
  diagnostics.push(...tagResult.diagnostics);
@@ -31681,7 +31760,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
31681
31760
  inputXml: itemXml
31682
31761
  });
31683
31762
  const filenameSource = opts?.itemFilenameSource;
31684
- if (filenameSource && filenameSource !== (opts.itemReferenceSource ?? "sourceFilename")) {
31763
+ if (filenameSource && normalizeRefSource(filenameSource) !== normalizeRefSource(opts.itemReferenceSource)) {
31685
31764
  const filename = generateItemReference(readAssessmentItemIdentifier(itemXml, md5Ref), filenameSource, itemFilePath);
31686
31765
  itemFilenames.set(md5Ref, filename);
31687
31766
  }
@@ -31712,8 +31791,10 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
31712
31791
  const activitiesManifest = {};
31713
31792
  if (testResources.length > 0) for (const testResource of testResources) {
31714
31793
  let activityReference;
31715
- if (opts?.itemReferenceSource === "qti") activityReference = testResource.identifier;
31716
- else {
31794
+ if (normalizeRefSource(opts?.itemReferenceSource) === "itemIdentifier") {
31795
+ const testEntry = entries.get(normalizeHref(testResource.href));
31796
+ activityReference = testEntry ? readAssessmentTestIdentifier(decodeUtf8(testEntry.data), testResource.identifier) : testResource.identifier;
31797
+ } else {
31717
31798
  const hrefParts = testResource.href.split("/");
31718
31799
  activityReference = hrefParts[hrefParts.length - 1].replace(/\.xml$/i, "");
31719
31800
  }
@@ -31755,6 +31836,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
31755
31836
  if (testResource.metadataXml) try {
31756
31837
  const tagResult = parseMetadataTags(testResource.metadataXml, {
31757
31838
  truncateTags: opts?.truncateTags,
31839
+ splitCsvTags: opts?.splitCsvTags,
31758
31840
  filePath: testResource.href
31759
31841
  });
31760
31842
  diagnostics.push(...tagResult.diagnostics);
@@ -31849,7 +31931,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
31849
31931
  mediaVault: opts?.mediaVault ?? false,
31850
31932
  customAssetUrl: opts?.customAssetUrl,
31851
31933
  preserveAssetFilenames: opts?.preserveAssetFilenames ?? false,
31852
- itemReferenceSource: opts?.itemReferenceSource ?? "sourceFilename"
31934
+ itemReferenceSource: opts?.itemReferenceSource ?? "itemIdentifier"
31853
31935
  }
31854
31936
  },
31855
31937
  items: Array.from(items.keys()).sort(),
@@ -251,13 +251,16 @@ type OutputFormat = 'dir' | 'zip' | 'stdout';
251
251
  */
252
252
  type DiagnosticsOutput = 'stderr' | 'file' | 'both' | 'none';
253
253
  /**
254
- * Item reference source for QTI → Learnosity conversion
254
+ * Item reference source for QTI → Learnosity conversion.
255
+ * `'itemIdentifier'` (default) uses the QTI `identifier` attribute.
256
+ * `'qti'` is a deprecated alias of `'itemIdentifier'`.
255
257
  */
256
- type ItemReferenceSource = 'sourceFilename' | 'qti' | 'uuid';
258
+ type ItemReferenceSource = 'sourceFilename' | 'qti' | 'uuid' | 'itemIdentifier';
257
259
  /**
258
- * Item filename source for output JSON file naming (QTI → Learnosity)
260
+ * Item filename source for output JSON file naming (QTI → Learnosity).
261
+ * `'qti'` is a deprecated alias of `'itemIdentifier'`.
259
262
  */
260
- type ItemFilenameSource = 'sourceFilename' | 'qti';
263
+ type ItemFilenameSource = 'sourceFilename' | 'qti' | 'itemIdentifier';
261
264
  /**
262
265
  * Shared conversion options
263
266
  */
@@ -278,6 +281,7 @@ interface ConversionOptions {
278
281
  preserveAssetFilenames?: boolean;
279
282
  itemReferenceSource?: ItemReferenceSource;
280
283
  truncateTags?: boolean;
284
+ splitCsvTags?: boolean;
281
285
  /**
282
286
  * Optional filesystem access for passage/LOM lookups. Omit for in-memory /
283
287
  * browser use (disk lookups become no-ops). Node callers can inject
@@ -2582,6 +2586,7 @@ interface ConvertOptions {
2582
2586
  sourceHrefBase?: string;
2583
2587
  itemReferenceSource?: ItemReferenceSource;
2584
2588
  truncateTags?: boolean;
2589
+ splitCsvTags?: boolean;
2585
2590
  fileAccess?: FileAccess;
2586
2591
  packageRoot?: string;
2587
2592
  }
@@ -2634,6 +2639,7 @@ interface ConvertQtiPackageToLearnosityBundleOptions {
2634
2639
  itemFilenameSource?: ItemFilenameSource;
2635
2640
  packageVersion?: string;
2636
2641
  truncateTags?: boolean;
2642
+ splitCsvTags?: boolean;
2637
2643
  /** Base directory for resolving item source paths (Node disk conversion). */
2638
2644
  sourceDir?: string;
2639
2645
  /** Injected filesystem access for passage/LOM lookups (Node only). */
@@ -2881,12 +2887,14 @@ interface ConvertQtiPackageToLearnosityOptions {
2881
2887
  customAssetUrl?: string;
2882
2888
  /** Preserve original QTI asset basenames instead of using hashed names (default: false) */
2883
2889
  preserveAssetFilenames?: boolean;
2884
- /** How to generate item references (default: 'sourceFilename') */
2890
+ /** How to generate item references (default: 'itemIdentifier'; 'qti' is a deprecated alias of 'itemIdentifier') */
2885
2891
  itemReferenceSource?: ItemReferenceSource;
2886
2892
  /** How to generate output filenames (defaults to itemReferenceSource) */
2887
2893
  itemFilenameSource?: ItemFilenameSource;
2888
2894
  /** Truncate tag types and names to 255 characters instead of failing */
2889
2895
  truncateTags?: boolean;
2896
+ /** Split comma-separated tag values into separate array elements (default: true) */
2897
+ splitCsvTags?: boolean;
2890
2898
  }
2891
2899
  /**
2892
2900
  * Result of converting a QTI Content Package to Learnosity