@learnosity/lib-qti-converter 0.12.0 → 0.12.2

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 (34) hide show
  1. package/README.md +9 -3
  2. package/docs/GETTING_STARTED.md +10 -4
  3. package/docs/TAGS_TO_QTI_METADATA.md +291 -0
  4. package/docs/_sidebar.md +10 -9
  5. package/package.json +7 -7
  6. package/packages/cli/dist/batchProcessors-BfmvnTQ5.js +215 -0
  7. package/packages/cli/dist/batchProcessors-BfmvnTQ5.js.map +1 -0
  8. package/packages/cli/dist/batchWorker.js +1 -1
  9. package/packages/cli/dist/configOutput-FwkFyQmk.js +399 -0
  10. package/packages/cli/dist/configOutput-FwkFyQmk.js.map +1 -0
  11. package/packages/cli/dist/create-prompt-COXnAzFl.js +1387 -0
  12. package/packages/cli/dist/create-prompt-COXnAzFl.js.map +1 -0
  13. package/packages/cli/dist/dist-CVD-X-DZ.js +278 -0
  14. package/packages/cli/dist/dist-CVD-X-DZ.js.map +1 -0
  15. package/packages/cli/dist/learnosityToQti-sKxcj5Hi.js +102 -0
  16. package/packages/cli/dist/learnosityToQti-sKxcj5Hi.js.map +1 -0
  17. package/packages/cli/dist/learnosityToQtiPackage-Ij4cM39M.js +632 -0
  18. package/packages/cli/dist/learnosityToQtiPackage-Ij4cM39M.js.map +1 -0
  19. package/packages/cli/dist/main.js +32 -37155
  20. package/packages/cli/dist/main.js.map +1 -1
  21. package/packages/cli/dist/pathUtils-Cz2GpPEb.js +2386 -0
  22. package/packages/cli/dist/pathUtils-Cz2GpPEb.js.map +1 -0
  23. package/packages/cli/dist/qtiPackageToLearnosity-CvXdmwsb.js +354 -0
  24. package/packages/cli/dist/qtiPackageToLearnosity-CvXdmwsb.js.map +1 -0
  25. package/packages/cli/dist/qtiToLearnosity-CkD0r1q0.js +97 -0
  26. package/packages/cli/dist/qtiToLearnosity-CkD0r1q0.js.map +1 -0
  27. package/packages/cli/dist/resolveOptions-CfXUqGkd.js +31562 -0
  28. package/packages/cli/dist/resolveOptions-CfXUqGkd.js.map +1 -0
  29. package/packages/cli/dist/rolldown-runtime-B4iAMlE-.js +35 -0
  30. package/packages/cli/dist/{batchProcessors-B8EQvMbH.js → table-DYcNeyJ_.js} +906 -1150
  31. package/packages/cli/dist/table-DYcNeyJ_.js.map +1 -0
  32. package/packages/core/dist/index.js +389 -411
  33. package/packages/core/dist/node.js +389 -411
  34. package/packages/cli/dist/batchProcessors-B8EQvMbH.js.map +0 -1
@@ -622,7 +622,9 @@ function parseClozeformulaData(data, file, diagnostics) {
622
622
  "showHints",
623
623
  "show_hints_button",
624
624
  "numberPad",
625
- "text_blocks"
625
+ "text_blocks",
626
+ "horizontal_layout",
627
+ "horizontalPad"
626
628
  ]);
627
629
  for (const key of Object.keys(data)) if (!knownKeys.has(key)) diagnostics.push({
628
630
  level: "warning",
@@ -18535,6 +18537,77 @@ function getMimeTypeFromExtension(src) {
18535
18537
  if (ext === "webm") return "video/webm";
18536
18538
  if (ext === "ogv") return "video/ogg";
18537
18539
  }
18540
+ /**
18541
+ * Generic section-extraction wrapper that eliminates boilerplate from individual
18542
+ * interaction builders. Calls the provided `buildXml` function to generate raw XML
18543
+ * fragments, then regex-extracts the standard QTI assessmentItem sections.
18544
+ *
18545
+ * Handles both self-closing (`<responseDeclaration ... />`) and paired
18546
+ * (`<responseDeclaration ...>...</responseDeclaration>`) element forms.
18547
+ *
18548
+ * @example
18549
+ * ```ts
18550
+ * export function buildAssociateInteractionSections(...) {
18551
+ * buildInteractionSections(
18552
+ * buildAssociateInteractionXml,
18553
+ * [interaction, diagnostics],
18554
+ * sections, indent, indent2, indent3, nl
18555
+ * );
18556
+ * }
18557
+ * ```
18558
+ */
18559
+ function buildInteractionSections(buildXml, buildArgs, _diagnostics, sections, indent, indent2, indent3, nl, opts) {
18560
+ const tempParts = [];
18561
+ buildXml(...buildArgs, tempParts, indent, indent2, indent3, nl);
18562
+ const joined = tempParts.join("");
18563
+ if (opts?.multiResponseDeclarations) {
18564
+ const matches = joined.matchAll(/(<responseDeclaration[\s\S]*?(?:\/>|<\/responseDeclaration>))/g);
18565
+ for (const m of matches) sections.responseDeclarations.push(m[1] + nl);
18566
+ } else if (opts?.selfClosingResponseDecl) {
18567
+ const match = joined.match(/(<responseDeclaration[\s\S]*?(?:\/>|<\/responseDeclaration>))/);
18568
+ if (match) sections.responseDeclarations.push(match[1] + nl);
18569
+ } else {
18570
+ const match = joined.match(/(<responseDeclaration[\s\S]*?<\/responseDeclaration>)/);
18571
+ if (match) sections.responseDeclarations.push(match[1] + nl);
18572
+ }
18573
+ if (opts?.multiOutcomeDeclarations) {
18574
+ const matches = joined.matchAll(/(<outcomeDeclaration[\s\S]*?<\/outcomeDeclaration>)/g);
18575
+ for (const m of matches) sections.outcomeDeclarations.push(m[1] + nl);
18576
+ } else {
18577
+ const match = joined.match(/(<outcomeDeclaration[\s\S]*?<\/outcomeDeclaration>)/);
18578
+ if (match) sections.outcomeDeclarations.push(match[1] + nl);
18579
+ }
18580
+ const itemBodyMatch = joined.match(/(<itemBody>[\s\S]*?<\/itemBody>)/);
18581
+ if (itemBodyMatch) sections.itemBody = itemBodyMatch[1] + nl;
18582
+ const responseProcMatch = joined.match(/(<responseProcessing[\s\S]*?(?:\/>|<\/responseProcessing>))/);
18583
+ if (responseProcMatch) sections.responseProcessing = responseProcMatch[1] + nl;
18584
+ }
18585
+ /**
18586
+ * Emit the standard SCORE outcomeDeclaration block.
18587
+ *
18588
+ * Used by: associate, choice, gapMatch, inlineChoice, match, order, textEntry (×2)
18589
+ */
18590
+ function pushScoreOutcomeDeclaration(parts, indent, indent2, indent3, nl) {
18591
+ parts.push(`${indent}<outcomeDeclaration identifier="SCORE" cardinality="single" baseType="float">`);
18592
+ parts.push(nl);
18593
+ parts.push(`${indent2}<defaultValue>`);
18594
+ parts.push(nl);
18595
+ parts.push(`${indent3}<value>0</value>`);
18596
+ parts.push(nl);
18597
+ parts.push(`${indent2}</defaultValue>`);
18598
+ parts.push(nl);
18599
+ parts.push(`${indent}</outcomeDeclaration>`);
18600
+ parts.push(nl);
18601
+ }
18602
+ /**
18603
+ * Emit the standard responseProcessing match_correct template reference.
18604
+ *
18605
+ * Used by: associate, choice, gapMatch, hotspot, hottext, match, order, textEntry (×2)
18606
+ */
18607
+ function pushMatchCorrectResponseProcessing(parts, indent, nl) {
18608
+ parts.push(`${indent}<responseProcessing template="http://www.imsglobal.org/question/qti_v2p2/rptemplates/match_correct"/>`);
18609
+ parts.push(nl);
18610
+ }
18538
18611
  //#endregion
18539
18612
  //#region src/qti-serializer/multiWidgetSerializer.ts
18540
18613
  /**
@@ -18835,16 +18908,7 @@ function buildMultiWidgetItemXml(ast, diagnostics, parts, indent, indent2, inden
18835
18908
  parts.push(nl);
18836
18909
  }
18837
18910
  }
18838
- parts.push(`${indent}<outcomeDeclaration identifier="SCORE" cardinality="single" baseType="float">`);
18839
- parts.push(nl);
18840
- parts.push(`${indent2}<defaultValue>`);
18841
- parts.push(nl);
18842
- parts.push(`${indent3}<value>0</value>`);
18843
- parts.push(nl);
18844
- parts.push(`${indent2}</defaultValue>`);
18845
- parts.push(nl);
18846
- parts.push(`${indent}</outcomeDeclaration>`);
18847
- parts.push(nl);
18911
+ pushScoreOutcomeDeclaration(parts, indent, indent2, indent3, nl);
18848
18912
  parts.push(`${indent}<itemBody>`);
18849
18913
  parts.push(nl);
18850
18914
  let contentHtml = layout.contentHtml;
@@ -18893,10 +18957,7 @@ function buildMultiWidgetItemXml(ast, diagnostics, parts, indent, indent2, inden
18893
18957
  else if (int.type === "textEntry") return (int.correctResponses?.length ?? 0) > 0;
18894
18958
  else if (int.type === "order") return (int.correctResponse?.length ?? 0) > 0;
18895
18959
  return false;
18896
- })) {
18897
- parts.push(`${indent}<responseProcessing template="http://www.imsglobal.org/question/qti_v2p2/rptemplates/match_correct"/>`);
18898
- parts.push(nl);
18899
- }
18960
+ })) pushMatchCorrectResponseProcessing(parts, indent, nl);
18900
18961
  }
18901
18962
  /**
18902
18963
  * Render an interaction as XML string (for multi-widget layouts)
@@ -19225,17 +19286,11 @@ function convertVideoplayerToQh5(data) {
19225
19286
  * Section-based wrapper for buildChoiceInteractionXml
19226
19287
  */
19227
19288
  function buildChoiceInteractionSections(interaction, feedbackBlock, diagnostics, sections, indent, indent2, indent3, nl) {
19228
- const tempParts = [];
19229
- buildChoiceInteractionXml(interaction, feedbackBlock, diagnostics, tempParts, indent, indent2, indent3, nl);
19230
- const joined = tempParts.join("");
19231
- const responseDeclMatch = joined.match(/(<responseDeclaration[\s\S]*?<\/responseDeclaration>)/);
19232
- const outcomeDeclMatches = joined.matchAll(/(<outcomeDeclaration[\s\S]*?<\/outcomeDeclaration>)/g);
19233
- const itemBodyMatch = joined.match(/(<itemBody>[\s\S]*?<\/itemBody>)/);
19234
- const responseProcMatch = joined.match(/(<responseProcessing[^>]*\/>)/);
19235
- if (responseDeclMatch) sections.responseDeclarations.push(responseDeclMatch[1] + nl);
19236
- for (const match of outcomeDeclMatches) sections.outcomeDeclarations.push(match[1] + nl);
19237
- if (itemBodyMatch) sections.itemBody = itemBodyMatch[1] + nl;
19238
- if (responseProcMatch) sections.responseProcessing = responseProcMatch[1] + nl;
19289
+ buildInteractionSections(buildChoiceInteractionXml, [
19290
+ interaction,
19291
+ feedbackBlock,
19292
+ diagnostics
19293
+ ], diagnostics, sections, indent, indent2, indent3, nl, { multiOutcomeDeclarations: true });
19239
19294
  }
19240
19295
  /**
19241
19296
  * Build choice interaction XML (MCQ)
@@ -19265,16 +19320,7 @@ function buildChoiceInteractionXml(interaction, feedbackBlock, diagnostics, part
19265
19320
  parts.push(`${indent}</responseDeclaration>`);
19266
19321
  parts.push(nl);
19267
19322
  }
19268
- parts.push(`${indent}<outcomeDeclaration identifier="SCORE" cardinality="single" baseType="float">`);
19269
- parts.push(nl);
19270
- parts.push(`${indent2}<defaultValue>`);
19271
- parts.push(nl);
19272
- parts.push(`${indent3}<value>0</value>`);
19273
- parts.push(nl);
19274
- parts.push(`${indent2}</defaultValue>`);
19275
- parts.push(nl);
19276
- parts.push(`${indent}</outcomeDeclaration>`);
19277
- parts.push(nl);
19323
+ pushScoreOutcomeDeclaration(parts, indent, indent2, indent3, nl);
19278
19324
  if (feedbackBlock && feedbackBlock.length > 0) {
19279
19325
  parts.push(`${indent}<outcomeDeclaration identifier="FEEDBACK" cardinality="single" baseType="identifier">`);
19280
19326
  parts.push(nl);
@@ -19327,10 +19373,7 @@ function buildChoiceInteractionXml(interaction, feedbackBlock, diagnostics, part
19327
19373
  }
19328
19374
  parts.push(`${indent}</itemBody>`);
19329
19375
  parts.push(nl);
19330
- if (interaction.correctResponse) {
19331
- parts.push(`${indent}<responseProcessing template="http://www.imsglobal.org/question/qti_v2p2/rptemplates/match_correct"/>`);
19332
- parts.push(nl);
19333
- }
19376
+ if (interaction.correctResponse) pushMatchCorrectResponseProcessing(parts, indent, nl);
19334
19377
  }
19335
19378
  //#endregion
19336
19379
  //#region src/qti-serializer/interaction-builders/buildTextEntryInteraction.ts
@@ -19338,17 +19381,7 @@ function buildChoiceInteractionXml(interaction, feedbackBlock, diagnostics, part
19338
19381
  * Section-based wrapper for buildTextEntryInteractionXml
19339
19382
  */
19340
19383
  function buildTextEntryInteractionSections(interaction, diagnostics, sections, indent, indent2, indent3, nl) {
19341
- const tempParts = [];
19342
- buildTextEntryInteractionXml(interaction, diagnostics, tempParts, indent, indent2, indent3, nl);
19343
- const joined = tempParts.join("");
19344
- const responseDeclMatches = joined.matchAll(/(<responseDeclaration[\s\S]*?(?:\/>|<\/responseDeclaration>))/g);
19345
- for (const match of responseDeclMatches) sections.responseDeclarations.push(match[1] + nl);
19346
- const outcomeDeclMatch = joined.match(/(<outcomeDeclaration[\s\S]*?<\/outcomeDeclaration>)/);
19347
- const itemBodyMatch = joined.match(/(<itemBody>[\s\S]*?<\/itemBody>)/);
19348
- const responseProcMatch = joined.match(/(<responseProcessing[^>]*\/>)/);
19349
- if (outcomeDeclMatch) sections.outcomeDeclarations.push(outcomeDeclMatch[1] + nl);
19350
- if (itemBodyMatch) sections.itemBody = itemBodyMatch[1] + nl;
19351
- if (responseProcMatch) sections.responseProcessing = responseProcMatch[1] + nl;
19384
+ buildInteractionSections(buildTextEntryInteractionXml, [interaction, diagnostics], diagnostics, sections, indent, indent2, indent3, nl, { multiResponseDeclarations: true });
19352
19385
  }
19353
19386
  /**
19354
19387
  * Build text entry interaction XML (clozetext)
@@ -19382,16 +19415,7 @@ function buildTextEntryInteractionXml(interaction, diagnostics, parts, indent, i
19382
19415
  parts.push(`${indent}<responseDeclaration identifier="${interaction.responseIdentifier}" cardinality="single" baseType="string"/>`);
19383
19416
  parts.push(nl);
19384
19417
  }
19385
- parts.push(`${indent}<outcomeDeclaration identifier="SCORE" cardinality="single" baseType="float">`);
19386
- parts.push(nl);
19387
- parts.push(`${indent2}<defaultValue>`);
19388
- parts.push(nl);
19389
- parts.push(`${indent3}<value>0</value>`);
19390
- parts.push(nl);
19391
- parts.push(`${indent2}</defaultValue>`);
19392
- parts.push(nl);
19393
- parts.push(`${indent}</outcomeDeclaration>`);
19394
- parts.push(nl);
19418
+ pushScoreOutcomeDeclaration(parts, indent, indent2, indent3, nl);
19395
19419
  parts.push(`${indent}<itemBody>`);
19396
19420
  parts.push(nl);
19397
19421
  diagnostics.push({
@@ -19421,10 +19445,7 @@ function buildTextEntryInteractionXml(interaction, diagnostics, parts, indent, i
19421
19445
  parts.push(nl);
19422
19446
  parts.push(`${indent}</itemBody>`);
19423
19447
  parts.push(nl);
19424
- if (interaction.correctResponses && interaction.correctResponses.length > 0) {
19425
- parts.push(`${indent}<responseProcessing template="http://www.imsglobal.org/question/qti_v2p2/rptemplates/match_correct"/>`);
19426
- parts.push(nl);
19427
- }
19448
+ if (interaction.correctResponses && interaction.correctResponses.length > 0) pushMatchCorrectResponseProcessing(parts, indent, nl);
19428
19449
  return;
19429
19450
  }
19430
19451
  if (!Array.isArray(interaction.textEntries) || interaction.textEntries.length === 0) {
@@ -19461,16 +19482,7 @@ function buildTextEntryInteractionXml(interaction, diagnostics, parts, indent, i
19461
19482
  parts.push(`${indent}<responseDeclaration identifier="${entry.responseIdentifier}" cardinality="single" baseType="string"/>`);
19462
19483
  parts.push(nl);
19463
19484
  }
19464
- parts.push(`${indent}<outcomeDeclaration identifier="SCORE" cardinality="single" baseType="float">`);
19465
- parts.push(nl);
19466
- parts.push(`${indent2}<defaultValue>`);
19467
- parts.push(nl);
19468
- parts.push(`${indent3}<value>0</value>`);
19469
- parts.push(nl);
19470
- parts.push(`${indent2}</defaultValue>`);
19471
- parts.push(nl);
19472
- parts.push(`${indent}</outcomeDeclaration>`);
19473
- parts.push(nl);
19485
+ pushScoreOutcomeDeclaration(parts, indent, indent2, indent3, nl);
19474
19486
  parts.push(`${indent}<itemBody>`);
19475
19487
  parts.push(nl);
19476
19488
  if (interaction.prompt) {
@@ -19520,10 +19532,7 @@ function buildTextEntryInteractionXml(interaction, diagnostics, parts, indent, i
19520
19532
  parts.push(nl);
19521
19533
  parts.push(`${indent}</itemBody>`);
19522
19534
  parts.push(nl);
19523
- if (interaction.textEntries.some((e) => e.correctResponse)) {
19524
- parts.push(`${indent}<responseProcessing template="http://www.imsglobal.org/question/qti_v2p2/rptemplates/match_correct"/>`);
19525
- parts.push(nl);
19526
- }
19535
+ if (interaction.textEntries.some((e) => e.correctResponse)) pushMatchCorrectResponseProcessing(parts, indent, nl);
19527
19536
  }
19528
19537
  //#endregion
19529
19538
  //#region src/qti-serializer/interaction-builders/buildExtendedTextInteraction.ts
@@ -19531,15 +19540,14 @@ function buildTextEntryInteractionXml(interaction, diagnostics, parts, indent, i
19531
19540
  * Section-based wrapper for buildExtendedTextInteractionXml
19532
19541
  */
19533
19542
  function buildExtendedTextInteractionSections(interaction, outcomeDeclaration, diagnostics, sections, indent, indent2, indent3, nl) {
19534
- const tempParts = [];
19535
- buildExtendedTextInteractionXml(interaction, outcomeDeclaration, diagnostics, tempParts, indent, indent2, indent3, nl);
19536
- const joined = tempParts.join("");
19537
- const responseDeclMatch = joined.match(/(<responseDeclaration[\s\S]*?(?:\/>|<\/responseDeclaration>))/);
19538
- const outcomeDeclMatches = joined.matchAll(/(<outcomeDeclaration[\s\S]*?<\/outcomeDeclaration>)/g);
19539
- for (const match of outcomeDeclMatches) sections.outcomeDeclarations.push(match[1] + nl);
19540
- const itemBodyMatch = joined.match(/(<itemBody>[\s\S]*?<\/itemBody>)/);
19541
- if (responseDeclMatch) sections.responseDeclarations.push(responseDeclMatch[1] + nl);
19542
- if (itemBodyMatch) sections.itemBody = itemBodyMatch[1] + nl;
19543
+ buildInteractionSections(buildExtendedTextInteractionXml, [
19544
+ interaction,
19545
+ outcomeDeclaration,
19546
+ diagnostics
19547
+ ], diagnostics, sections, indent, indent2, indent3, nl, {
19548
+ multiOutcomeDeclarations: true,
19549
+ selfClosingResponseDecl: true
19550
+ });
19543
19551
  }
19544
19552
  /**
19545
19553
  * Build extended text interaction XML (essay/long answer)
@@ -19587,15 +19595,10 @@ function buildExtendedTextInteractionXml(interaction, outcomeDeclaration, diagno
19587
19595
  * Section-based wrapper for buildUploadInteractionXml
19588
19596
  */
19589
19597
  function buildUploadInteractionSections(interaction, diagnostics, sections, indent, indent2, nl) {
19590
- const tempParts = [];
19591
- buildUploadInteractionXml(interaction, diagnostics, tempParts, indent, indent2, nl);
19592
- const joined = tempParts.join("");
19593
- const responseDeclMatch = joined.match(/(<responseDeclaration[\s\S]*?(?:\/>|<\/responseDeclaration>))/);
19594
- const itemBodyMatch = joined.match(/(<itemBody>[\s\S]*?<\/itemBody>)/);
19595
- const responseProcessingMatch = joined.match(/(<responseProcessing[\s\S]*?(?:\/>|<\/responseProcessing>))/);
19596
- if (responseDeclMatch) sections.responseDeclarations.push(responseDeclMatch[1] + nl);
19597
- if (itemBodyMatch) sections.itemBody = itemBodyMatch[1] + nl;
19598
- if (responseProcessingMatch) sections.responseProcessing = responseProcessingMatch[1] + nl;
19598
+ const buildXmlAdapter = (interaction, diagnostics, parts, indent, indent2, _indent3, nl) => {
19599
+ buildUploadInteractionXml(interaction, diagnostics, parts, indent, indent2, nl);
19600
+ };
19601
+ buildInteractionSections(buildXmlAdapter, [interaction, diagnostics], diagnostics, sections, indent, indent2, "", nl, { selfClosingResponseDecl: true });
19599
19602
  }
19600
19603
  /**
19601
19604
  * Build upload interaction XML (file upload)
@@ -19634,15 +19637,7 @@ function buildUploadInteractionXml(interaction, diagnostics, parts, indent, inde
19634
19637
  * Build drawingInteraction sections
19635
19638
  */
19636
19639
  function buildDrawingInteractionSections(interaction, diagnostics, sections, indent, indent2, indent3, nl) {
19637
- const tempParts = [];
19638
- buildDrawingInteractionXml(interaction, diagnostics, tempParts, indent, indent2, indent3, nl);
19639
- const joined = tempParts.join("");
19640
- const responseDeclMatch = joined.match(/(<responseDeclaration[\s\S]*?(?:\/>|<\/responseDeclaration>))/);
19641
- const itemBodyMatch = joined.match(/(<itemBody>[\s\S]*?<\/itemBody>)/);
19642
- const responseProcessingMatch = joined.match(/(<responseProcessing[\s\S]*?(?:\/>|<\/responseProcessing>))/);
19643
- if (responseDeclMatch) sections.responseDeclarations.push(responseDeclMatch[1] + nl);
19644
- if (itemBodyMatch) sections.itemBody = itemBodyMatch[1] + nl;
19645
- if (responseProcessingMatch) sections.responseProcessing = responseProcessingMatch[1] + nl;
19640
+ buildInteractionSections(buildDrawingInteractionXml, [interaction, diagnostics], diagnostics, sections, indent, indent2, indent3, nl, { selfClosingResponseDecl: true });
19646
19641
  }
19647
19642
  /**
19648
19643
  * Build drawingInteraction XML
@@ -19700,17 +19695,7 @@ function buildDrawingInteractionXml(interaction, diagnostics, parts, indent, ind
19700
19695
  * Section-based wrapper for buildInlineChoiceInteractionXml
19701
19696
  */
19702
19697
  function buildInlineChoiceInteractionSections(interaction, diagnostics, sections, indent, indent2, indent3, nl) {
19703
- const tempParts = [];
19704
- buildInlineChoiceInteractionXml(interaction, diagnostics, tempParts, indent, indent2, indent3, nl);
19705
- const joined = tempParts.join("");
19706
- const responseDeclMatches = joined.matchAll(/(<responseDeclaration[\s\S]*?(?:\/>|<\/responseDeclaration>))/g);
19707
- for (const match of responseDeclMatches) sections.responseDeclarations.push(match[1] + nl);
19708
- const outcomeDeclMatch = joined.match(/(<outcomeDeclaration[\s\S]*?<\/outcomeDeclaration>)/);
19709
- const itemBodyMatch = joined.match(/(<itemBody>[\s\S]*?<\/itemBody>)/);
19710
- const responseProcMatch = joined.match(/(<responseProcessing[^>]*\/>)/);
19711
- if (outcomeDeclMatch) sections.outcomeDeclarations.push(outcomeDeclMatch[1] + nl);
19712
- if (itemBodyMatch) sections.itemBody = itemBodyMatch[1] + nl;
19713
- if (responseProcMatch) sections.responseProcessing = responseProcMatch[1] + nl;
19698
+ buildInteractionSections(buildInlineChoiceInteractionXml, [interaction, diagnostics], diagnostics, sections, indent, indent2, indent3, nl, { multiResponseDeclarations: true });
19714
19699
  }
19715
19700
  /**
19716
19701
  * Build inline choice interaction XML (clozedropdown)
@@ -19740,16 +19725,7 @@ function buildInlineChoiceInteractionXml(interaction, diagnostics, parts, indent
19740
19725
  parts.push(nl);
19741
19726
  }
19742
19727
  }
19743
- parts.push(`${indent}<outcomeDeclaration identifier="SCORE" cardinality="single" baseType="float">`);
19744
- parts.push(nl);
19745
- parts.push(`${indent2}<defaultValue>`);
19746
- parts.push(nl);
19747
- parts.push(`${indent3}<value>0</value>`);
19748
- parts.push(nl);
19749
- parts.push(`${indent2}</defaultValue>`);
19750
- parts.push(nl);
19751
- parts.push(`${indent}</outcomeDeclaration>`);
19752
- parts.push(nl);
19728
+ pushScoreOutcomeDeclaration(parts, indent, indent2, indent3, nl);
19753
19729
  parts.push(`${indent}<itemBody>`);
19754
19730
  parts.push(nl);
19755
19731
  if (interaction.prompt) {
@@ -19788,17 +19764,7 @@ function buildInlineChoiceInteractionXml(interaction, diagnostics, parts, indent
19788
19764
  * Section-based wrapper for buildGapMatchInteractionXml
19789
19765
  */
19790
19766
  function buildGapMatchInteractionSections(interaction, diagnostics, sections, indent, indent2, indent3, nl) {
19791
- const tempParts = [];
19792
- buildGapMatchInteractionXml(interaction, diagnostics, tempParts, indent, indent2, indent3, nl);
19793
- const joined = tempParts.join("");
19794
- const responseDeclMatch = joined.match(/(<responseDeclaration[\s\S]*?<\/responseDeclaration>)/);
19795
- const outcomeDeclMatch = joined.match(/(<outcomeDeclaration[\s\S]*?<\/outcomeDeclaration>)/);
19796
- const itemBodyMatch = joined.match(/(<itemBody>[\s\S]*?<\/itemBody>)/);
19797
- const responseProcMatch = joined.match(/(<responseProcessing[^>]*\/>)/);
19798
- if (responseDeclMatch) sections.responseDeclarations.push(responseDeclMatch[1] + nl);
19799
- if (outcomeDeclMatch) sections.outcomeDeclarations.push(outcomeDeclMatch[1] + nl);
19800
- if (itemBodyMatch) sections.itemBody = itemBodyMatch[1] + nl;
19801
- if (responseProcMatch) sections.responseProcessing = responseProcMatch[1] + nl;
19767
+ buildInteractionSections(buildGapMatchInteractionXml, [interaction, diagnostics], diagnostics, sections, indent, indent2, indent3, nl);
19802
19768
  }
19803
19769
  /**
19804
19770
  * Build gapMatch interaction XML for clozeassociation
@@ -19832,16 +19798,7 @@ function buildGapMatchInteractionXml(interaction, diagnostics, parts, indent, in
19832
19798
  parts.push(nl);
19833
19799
  }
19834
19800
  }
19835
- parts.push(`${indent}<outcomeDeclaration identifier="SCORE" cardinality="single" baseType="float">`);
19836
- parts.push(nl);
19837
- parts.push(`${indent2}<defaultValue>`);
19838
- parts.push(nl);
19839
- parts.push(`${indent3}<value>0</value>`);
19840
- parts.push(nl);
19841
- parts.push(`${indent2}</defaultValue>`);
19842
- parts.push(nl);
19843
- parts.push(`${indent}</outcomeDeclaration>`);
19844
- parts.push(nl);
19801
+ pushScoreOutcomeDeclaration(parts, indent, indent2, indent3, nl);
19845
19802
  parts.push(`${indent}<itemBody>`);
19846
19803
  parts.push(nl);
19847
19804
  if (interaction.prompt) {
@@ -19888,17 +19845,7 @@ function buildGapMatchInteractionXml(interaction, diagnostics, parts, indent, in
19888
19845
  * Section-based wrapper for buildOrderInteractionXml
19889
19846
  */
19890
19847
  function buildOrderInteractionSections(interaction, diagnostics, sections, indent, indent2, indent3, nl) {
19891
- const tempParts = [];
19892
- buildOrderInteractionXml(interaction, diagnostics, tempParts, indent, indent2, indent3, nl);
19893
- const joined = tempParts.join("");
19894
- const responseDeclMatch = joined.match(/(<responseDeclaration[\s\S]*?<\/responseDeclaration>)/);
19895
- const outcomeDeclMatch = joined.match(/(<outcomeDeclaration[\s\S]*?<\/outcomeDeclaration>)/);
19896
- const itemBodyMatch = joined.match(/(<itemBody>[\s\S]*?<\/itemBody>)/);
19897
- const responseProcMatch = joined.match(/(<responseProcessing[^>]*\/>)/);
19898
- if (responseDeclMatch) sections.responseDeclarations.push(responseDeclMatch[1] + nl);
19899
- if (outcomeDeclMatch) sections.outcomeDeclarations.push(outcomeDeclMatch[1] + nl);
19900
- if (itemBodyMatch) sections.itemBody = itemBodyMatch[1] + nl;
19901
- if (responseProcMatch) sections.responseProcessing = responseProcMatch[1] + nl;
19848
+ buildInteractionSections(buildOrderInteractionXml, [interaction, diagnostics], diagnostics, sections, indent, indent2, indent3, nl);
19902
19849
  }
19903
19850
  /**
19904
19851
  * Build orderInteraction XML (for single-widget items)
@@ -19931,16 +19878,7 @@ function buildOrderInteractionXml(interaction, diagnostics, parts, indent, inden
19931
19878
  parts.push(`${indent}<responseDeclaration identifier="${interaction.responseIdentifier}" cardinality="ordered" baseType="identifier"/>`);
19932
19879
  parts.push(nl);
19933
19880
  }
19934
- parts.push(`${indent}<outcomeDeclaration identifier="SCORE" cardinality="single" baseType="float">`);
19935
- parts.push(nl);
19936
- parts.push(`${indent2}<defaultValue>`);
19937
- parts.push(nl);
19938
- parts.push(`${indent3}<value>0</value>`);
19939
- parts.push(nl);
19940
- parts.push(`${indent2}</defaultValue>`);
19941
- parts.push(nl);
19942
- parts.push(`${indent}</outcomeDeclaration>`);
19943
- parts.push(nl);
19881
+ pushScoreOutcomeDeclaration(parts, indent, indent2, indent3, nl);
19944
19882
  parts.push(`${indent}<itemBody>`);
19945
19883
  parts.push(nl);
19946
19884
  if (interaction.prompt) {
@@ -19973,10 +19911,7 @@ function buildOrderInteractionXml(interaction, diagnostics, parts, indent, inden
19973
19911
  parts.push(nl);
19974
19912
  parts.push(`${indent}</itemBody>`);
19975
19913
  parts.push(nl);
19976
- if (interaction.correctResponse && interaction.correctResponse.length > 0) {
19977
- parts.push(`${indent}<responseProcessing template="http://www.imsglobal.org/question/qti_v2p2/rptemplates/match_correct"/>`);
19978
- parts.push(nl);
19979
- }
19914
+ if (interaction.correctResponse && interaction.correctResponse.length > 0) pushMatchCorrectResponseProcessing(parts, indent, nl);
19980
19915
  }
19981
19916
  //#endregion
19982
19917
  //#region src/qti-serializer/interaction-builders/buildMatchInteraction.ts
@@ -19984,17 +19919,7 @@ function buildOrderInteractionXml(interaction, diagnostics, parts, indent, inden
19984
19919
  * Section-based wrapper for buildMatchInteractionXml
19985
19920
  */
19986
19921
  function buildMatchInteractionSections(interaction, diagnostics, sections, indent, indent2, indent3, nl) {
19987
- const tempParts = [];
19988
- buildMatchInteractionXml(interaction, diagnostics, tempParts, indent, indent2, indent3, nl);
19989
- const joined = tempParts.join("");
19990
- const responseDeclMatch = joined.match(/(<responseDeclaration[\s\S]*?<\/responseDeclaration>)/);
19991
- const outcomeDeclMatch = joined.match(/(<outcomeDeclaration[\s\S]*?<\/outcomeDeclaration>)/);
19992
- const itemBodyMatch = joined.match(/(<itemBody>[\s\S]*?<\/itemBody>)/);
19993
- const responseProcMatch = joined.match(/(<responseProcessing[^>]*\/>)/);
19994
- if (responseDeclMatch) sections.responseDeclarations.push(responseDeclMatch[1] + nl);
19995
- if (outcomeDeclMatch) sections.outcomeDeclarations.push(outcomeDeclMatch[1] + nl);
19996
- if (itemBodyMatch) sections.itemBody = itemBodyMatch[1] + nl;
19997
- if (responseProcMatch) sections.responseProcessing = responseProcMatch[1] + nl;
19922
+ buildInteractionSections(buildMatchInteractionXml, [interaction, diagnostics], diagnostics, sections, indent, indent2, indent3, nl);
19998
19923
  }
19999
19924
  /**
20000
19925
  * Build matchInteraction XML (choicematrix)
@@ -20017,16 +19942,7 @@ function buildMatchInteractionXml(interaction, diagnostics, parts, indent, inden
20017
19942
  parts.push(`${indent}<responseDeclaration identifier="${interaction.responseIdentifier}" cardinality="multiple" baseType="directedPair"/>`);
20018
19943
  parts.push(nl);
20019
19944
  }
20020
- parts.push(`${indent}<outcomeDeclaration identifier="SCORE" cardinality="single" baseType="float">`);
20021
- parts.push(nl);
20022
- parts.push(`${indent2}<defaultValue>`);
20023
- parts.push(nl);
20024
- parts.push(`${indent3}<value>0</value>`);
20025
- parts.push(nl);
20026
- parts.push(`${indent2}</defaultValue>`);
20027
- parts.push(nl);
20028
- parts.push(`${indent}</outcomeDeclaration>`);
20029
- parts.push(nl);
19945
+ pushScoreOutcomeDeclaration(parts, indent, indent2, indent3, nl);
20030
19946
  parts.push(`${indent}<itemBody>`);
20031
19947
  parts.push(nl);
20032
19948
  if (interaction.prompt) {
@@ -20065,8 +19981,7 @@ function buildMatchInteractionXml(interaction, diagnostics, parts, indent, inden
20065
19981
  parts.push(nl);
20066
19982
  parts.push(`${indent}</itemBody>`);
20067
19983
  parts.push(nl);
20068
- parts.push(`${indent}<responseProcessing template="http://www.imsglobal.org/question/qti_v2p2/rptemplates/match_correct"/>`);
20069
- parts.push(nl);
19984
+ pushMatchCorrectResponseProcessing(parts, indent, nl);
20070
19985
  }
20071
19986
  //#endregion
20072
19987
  //#region src/qti-serializer/interaction-builders/buildHottextInteraction.ts
@@ -20074,15 +19989,7 @@ function buildMatchInteractionXml(interaction, diagnostics, parts, indent, inden
20074
19989
  * Build hottext interaction sections (tokenhighlight)
20075
19990
  */
20076
19991
  function buildHottextInteractionSections(interaction, diagnostics, sections, indent, indent2, indent3, nl) {
20077
- const tempParts = [];
20078
- buildHottextInteractionXml(interaction, diagnostics, tempParts, indent, indent2, indent3, nl);
20079
- const joined = tempParts.join("");
20080
- const responseDeclMatch = joined.match(/(<responseDeclaration[\s\S]*?<\/responseDeclaration>)/);
20081
- const itemBodyMatch = joined.match(/(<itemBody>[\s\S]*?<\/itemBody>)/);
20082
- const responseProcMatch = joined.match(/(<responseProcessing[^>]*\/>)/);
20083
- if (responseDeclMatch) sections.responseDeclarations.push(responseDeclMatch[1] + nl);
20084
- if (itemBodyMatch) sections.itemBody = itemBodyMatch[1] + nl;
20085
- if (responseProcMatch) sections.responseProcessing = responseProcMatch[1] + nl;
19992
+ buildInteractionSections(buildHottextInteractionXml, [interaction, diagnostics], diagnostics, sections, indent, indent2, indent3, nl);
20086
19993
  }
20087
19994
  /**
20088
19995
  * Build hottext interaction XML (tokenhighlight)
@@ -20137,10 +20044,7 @@ function buildHottextInteractionXml(interaction, diagnostics, parts, indent, ind
20137
20044
  parts.push(nl);
20138
20045
  parts.push(`${indent}</itemBody>`);
20139
20046
  parts.push(nl);
20140
- if (interaction.correctResponse && interaction.correctResponse.length > 0) {
20141
- parts.push(`${indent}<responseProcessing template="http://www.imsglobal.org/question/qti_v2p2/rptemplates/match_correct"/>`);
20142
- parts.push(nl);
20143
- }
20047
+ if (interaction.correctResponse && interaction.correctResponse.length > 0) pushMatchCorrectResponseProcessing(parts, indent, nl);
20144
20048
  }
20145
20049
  //#endregion
20146
20050
  //#region src/qti-serializer/interaction-builders/buildHotspotInteraction.ts
@@ -20148,15 +20052,7 @@ function buildHottextInteractionXml(interaction, diagnostics, parts, indent, ind
20148
20052
  * Build hotspotInteraction sections
20149
20053
  */
20150
20054
  function buildHotspotInteractionSections(interaction, diagnostics, sections, indent, indent2, indent3, nl) {
20151
- const tempParts = [];
20152
- buildHotspotInteractionXml(interaction, diagnostics, tempParts, indent, indent2, indent3, nl);
20153
- const joined = tempParts.join("");
20154
- const responseDeclMatch = joined.match(/(<responseDeclaration[\s\S]*?<\/responseDeclaration>)/);
20155
- const itemBodyMatch = joined.match(/(<itemBody>[\s\S]*?<\/itemBody>)/);
20156
- const responseProcMatch = joined.match(/(<responseProcessing[^>]*\/>)/);
20157
- if (responseDeclMatch) sections.responseDeclarations.push(responseDeclMatch[1] + nl);
20158
- if (itemBodyMatch) sections.itemBody = itemBodyMatch[1] + nl;
20159
- if (responseProcMatch) sections.responseProcessing = responseProcMatch[1] + nl;
20055
+ buildInteractionSections(buildHotspotInteractionXml, [interaction, diagnostics], diagnostics, sections, indent, indent2, indent3, nl, { selfClosingResponseDecl: true });
20160
20056
  }
20161
20057
  /**
20162
20058
  * Build hotspotInteraction XML
@@ -20203,10 +20099,7 @@ function buildHotspotInteractionXml(interaction, _diagnostics, parts, indent, in
20203
20099
  parts.push(nl);
20204
20100
  parts.push(`${indent}</itemBody>`);
20205
20101
  parts.push(nl);
20206
- if (interaction.correctResponse && interaction.correctResponse.length > 0) {
20207
- parts.push(`${indent}<responseProcessing template="http://www.imsglobal.org/question/qti_v2p2/rptemplates/match_correct"/>`);
20208
- parts.push(nl);
20209
- }
20102
+ if (interaction.correctResponse && interaction.correctResponse.length > 0) pushMatchCorrectResponseProcessing(parts, indent, nl);
20210
20103
  }
20211
20104
  //#endregion
20212
20105
  //#region src/qti-serializer/interaction-builders/buildGraphicGapMatchInteraction.ts
@@ -20214,15 +20107,7 @@ function buildHotspotInteractionXml(interaction, _diagnostics, parts, indent, in
20214
20107
  * Build graphicGapMatchInteraction sections
20215
20108
  */
20216
20109
  function buildGraphicGapMatchInteractionSections(interaction, diagnostics, sections, indent, indent2, indent3, nl) {
20217
- const tempParts = [];
20218
- buildGraphicGapMatchInteractionXml(interaction, diagnostics, tempParts, indent, indent2, indent3, nl);
20219
- const joined = tempParts.join("");
20220
- const responseDeclMatch = joined.match(/(<responseDeclaration[\s\S]*?<\/responseDeclaration>)/);
20221
- const itemBodyMatch = joined.match(/(<itemBody>[\s\S]*?<\/itemBody>)/);
20222
- const responseProcMatch = joined.match(/(<responseProcessing[^>]*\/>)/);
20223
- if (responseDeclMatch) sections.responseDeclarations.push(responseDeclMatch[1] + nl);
20224
- if (itemBodyMatch) sections.itemBody = itemBodyMatch[1] + nl;
20225
- if (responseProcMatch) sections.responseProcessing = responseProcMatch[1] + nl;
20110
+ buildInteractionSections(buildGraphicGapMatchInteractionXml, [interaction, diagnostics], diagnostics, sections, indent, indent2, indent3, nl, { selfClosingResponseDecl: true });
20226
20111
  }
20227
20112
  /**
20228
20113
  * Build graphicGapMatchInteraction XML (imageclozeassociationV2)
@@ -20301,17 +20186,7 @@ function buildGraphicGapMatchInteractionXml(interaction, diagnostics, parts, ind
20301
20186
  * Section-based wrapper for buildAssociateInteractionXml
20302
20187
  */
20303
20188
  function buildAssociateInteractionSections(interaction, diagnostics, sections, indent, indent2, indent3, nl) {
20304
- const tempParts = [];
20305
- buildAssociateInteractionXml(interaction, diagnostics, tempParts, indent, indent2, indent3, nl);
20306
- const joined = tempParts.join("");
20307
- const responseDeclMatch = joined.match(/(<responseDeclaration[\s\S]*?<\/responseDeclaration>)/);
20308
- const outcomeDeclMatch = joined.match(/(<outcomeDeclaration[\s\S]*?<\/outcomeDeclaration>)/);
20309
- const itemBodyMatch = joined.match(/(<itemBody>[\s\S]*?<\/itemBody>)/);
20310
- const responseProcMatch = joined.match(/(<responseProcessing[^>]*\/>)/);
20311
- if (responseDeclMatch) sections.responseDeclarations.push(responseDeclMatch[1] + nl);
20312
- if (outcomeDeclMatch) sections.outcomeDeclarations.push(outcomeDeclMatch[1] + nl);
20313
- if (itemBodyMatch) sections.itemBody = itemBodyMatch[1] + nl;
20314
- if (responseProcMatch) sections.responseProcessing = responseProcMatch[1] + nl;
20189
+ buildInteractionSections(buildAssociateInteractionXml, [interaction, diagnostics], diagnostics, sections, indent, indent2, indent3, nl);
20315
20190
  }
20316
20191
  /**
20317
20192
  * Build associateInteraction XML (for single-widget items, classification)
@@ -20334,16 +20209,7 @@ function buildAssociateInteractionXml(interaction, diagnostics, parts, indent, i
20334
20209
  parts.push(`${indent}<responseDeclaration identifier="${interaction.responseIdentifier}" cardinality="multiple" baseType="pair"/>`);
20335
20210
  parts.push(nl);
20336
20211
  }
20337
- parts.push(`${indent}<outcomeDeclaration identifier="SCORE" cardinality="single" baseType="float">`);
20338
- parts.push(nl);
20339
- parts.push(`${indent2}<defaultValue>`);
20340
- parts.push(nl);
20341
- parts.push(`${indent3}<value>0</value>`);
20342
- parts.push(nl);
20343
- parts.push(`${indent2}</defaultValue>`);
20344
- parts.push(nl);
20345
- parts.push(`${indent}</outcomeDeclaration>`);
20346
- parts.push(nl);
20212
+ pushScoreOutcomeDeclaration(parts, indent, indent2, indent3, nl);
20347
20213
  parts.push(`${indent}<itemBody>`);
20348
20214
  parts.push(nl);
20349
20215
  if (interaction.prompt) {
@@ -20372,10 +20238,7 @@ function buildAssociateInteractionXml(interaction, diagnostics, parts, indent, i
20372
20238
  parts.push(nl);
20373
20239
  parts.push(`${indent}</itemBody>`);
20374
20240
  parts.push(nl);
20375
- if (interaction.correctResponse && interaction.correctResponse.length > 0) {
20376
- parts.push(`${indent}<responseProcessing template="http://www.imsglobal.org/question/qti_v2p2/rptemplates/match_correct"/>`);
20377
- parts.push(nl);
20378
- }
20241
+ if (interaction.correctResponse && interaction.correctResponse.length > 0) pushMatchCorrectResponseProcessing(parts, indent, nl);
20379
20242
  }
20380
20243
  //#endregion
20381
20244
  //#region src/qti-serializer/serializeAssessmentItem.ts
@@ -27100,104 +26963,267 @@ function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, org
27100
26963
  };
27101
26964
  }
27102
26965
  //#endregion
27103
- //#region src/qti-parser/readAssessmentItemDrawing.ts
26966
+ //#region src/qti-parser/createAssessmentItemReader.ts
27104
26967
  /**
27105
- * Read QTI drawingInteraction using streaming parser
26968
+ * Shared SAX streaming scaffold for QTI assessmentItem readers.
26969
+ *
26970
+ * Every `readAssessmentItemXxx` parser repeats the same ~40 lines of boilerplate:
26971
+ * - Create a SaxesParser
26972
+ * - Handle assessmentItem opentag (extract identifier, title)
26973
+ * - Handle responseDeclaration + correctResponse + value extraction
26974
+ * - Handle itemBody detection
26975
+ * - text/cdata capture dispatch
26976
+ * - try/catch error handling with diagnostics
26977
+ * - Post-parse validations (foundAssessmentItem, foundItemBody, interaction count)
26978
+ *
26979
+ * This utility extracts the shared envelope, leaving each parser to focus only
26980
+ * on its interaction-specific logic.
27106
26981
  */
27107
- function readAssessmentItemDrawing(inputXml) {
27108
- const diagnostics = [];
27109
- const result = { diagnostics };
27110
- const parser = new import_saxes.SaxesParser();
27111
- const stimulusBuf = [];
27112
- const promptBuf = [];
27113
- let capture = null;
27114
- let inDrawingInteraction = false;
27115
- let foundAssessmentItem = false;
27116
- let foundItemBody = false;
27117
- let drawingInteractionCount = 0;
27118
- parser.on("opentag", (tag) => {
27119
- const localName = tag.local ?? tag.name;
27120
- if (localName === "assessmentItem") {
27121
- foundAssessmentItem = true;
27122
- result.identifier = getAttr$5(tag, "identifier");
27123
- result.title = getAttr$5(tag, "title") ?? null;
27124
- } else if (localName === "itemBody") {
27125
- foundItemBody = true;
27126
- capture = "stimulus";
27127
- stimulusBuf.length = 0;
27128
- } else if (localName === "drawingInteraction") {
27129
- drawingInteractionCount++;
27130
- inDrawingInteraction = true;
27131
- result.responseIdentifier = getAttr$5(tag, "responseIdentifier");
27132
- if (capture === "stimulus") {
27133
- result.stimulusText = normalizeWhitespace(stimulusBuf.join(""));
27134
- capture = null;
26982
+ /**
26983
+ * Create an assessmentItem reader with the shared envelope handled automatically.
26984
+ *
26985
+ * The returned function accepts XML input and returns the typed result, with all
26986
+ * the common scaffolding (parser creation, assessmentItem/responseDeclaration/itemBody
26987
+ * handling, error handling, validations) done for you.
26988
+ *
26989
+ * @example
26990
+ * ```ts
26991
+ * export const readAssessmentItemDrawing = createAssessmentItemReader<ReadDrawingResult>({
26992
+ * interactionName: 'drawingInteraction',
26993
+ * createResult: (diagnostics) => ({ diagnostics, ... }),
26994
+ * onInteractionOpen: (tag, result, ctx) => { ... },
26995
+ * });
26996
+ * ```
26997
+ */
26998
+ function createAssessmentItemReader(hooks) {
26999
+ return (inputXml) => {
27000
+ const diagnostics = [];
27001
+ const result = hooks.createResult(diagnostics);
27002
+ const parser = new import_saxes.SaxesParser(hooks.parserOptions);
27003
+ const buffers = /* @__PURE__ */ new Map();
27004
+ let foundAssessmentItem = false;
27005
+ let foundItemBody = false;
27006
+ let inItemBody = false;
27007
+ let inInteraction = false;
27008
+ let interactionCount = 0;
27009
+ let currentResponseDeclId;
27010
+ let inCorrectResponse = false;
27011
+ const correctResponsesByIdentifier = /* @__PURE__ */ new Map();
27012
+ const correctValueBuf = [];
27013
+ const ctx = {
27014
+ get capture() {
27015
+ return _capture;
27016
+ },
27017
+ set capture(val) {
27018
+ _capture = val;
27019
+ },
27020
+ get inItemBody() {
27021
+ return inItemBody;
27022
+ },
27023
+ diagnostics,
27024
+ correctResponsesByIdentifier,
27025
+ get currentResponseDeclId() {
27026
+ return currentResponseDeclId;
27027
+ },
27028
+ getAttr: getAttr$5,
27029
+ normalizeWhitespace,
27030
+ pushToBuffer(name, text) {
27031
+ if (!buffers.has(name)) buffers.set(name, []);
27032
+ buffers.get(name).push(text);
27033
+ },
27034
+ flushBuffer(name) {
27035
+ const buf = buffers.get(name);
27036
+ if (!buf) return "";
27037
+ const result = normalizeWhitespace(buf.join(""));
27038
+ buf.length = 0;
27039
+ return result;
27040
+ },
27041
+ peekBuffer(name) {
27042
+ const buf = buffers.get(name);
27043
+ return buf ? buf.join("") : "";
27044
+ },
27045
+ clearBuffer(name) {
27046
+ const buf = buffers.get(name);
27047
+ if (buf) buf.length = 0;
27135
27048
  }
27136
- } else if (localName === "prompt" && inDrawingInteraction) {
27137
- capture = "prompt";
27138
- promptBuf.length = 0;
27139
- } else if (localName === "img" && inDrawingInteraction) {
27140
- result.imageSource = getAttr$5(tag, "src");
27141
- result.imageAlt = getAttr$5(tag, "alt");
27142
- const widthAttr = getAttr$5(tag, "width");
27143
- const heightAttr = getAttr$5(tag, "height");
27144
- if (widthAttr) result.imageWidth = parseInt(widthAttr, 10);
27145
- if (heightAttr) result.imageHeight = parseInt(heightAttr, 10);
27146
- }
27147
- });
27148
- parser.on("closetag", (tag) => {
27149
- const localName = tag.local ?? tag.name;
27150
- if (localName === "itemBody") {} else if (localName === "drawingInteraction") inDrawingInteraction = false;
27151
- else if (localName === "prompt" && capture === "prompt") {
27152
- result.promptText = normalizeWhitespace(promptBuf.join(""));
27153
- capture = null;
27049
+ };
27050
+ let _capture = null;
27051
+ parser.on("opentag", (tag) => {
27052
+ const localName = tag.local ?? tag.name;
27053
+ if (localName === "assessmentItem") {
27054
+ foundAssessmentItem = true;
27055
+ result.identifier = getAttr$5(tag, "identifier");
27056
+ result.title = getAttr$5(tag, "title") ?? null;
27057
+ return;
27058
+ }
27059
+ if (localName === "itemBody") {
27060
+ foundItemBody = true;
27061
+ inItemBody = true;
27062
+ return;
27063
+ }
27064
+ if (localName === hooks.interactionName) {
27065
+ interactionCount++;
27066
+ inInteraction = true;
27067
+ hooks.onInteractionOpen(tag, result, ctx);
27068
+ return;
27069
+ }
27070
+ if (localName === "responseDeclaration") {
27071
+ const identifier = getAttr$5(tag, "identifier");
27072
+ if (identifier) {
27073
+ currentResponseDeclId = identifier;
27074
+ correctResponsesByIdentifier.set(identifier, []);
27075
+ }
27076
+ return;
27077
+ }
27078
+ if (localName === "correctResponse") {
27079
+ inCorrectResponse = true;
27080
+ correctValueBuf.length = 0;
27081
+ return;
27082
+ }
27083
+ if (localName === "value" && inCorrectResponse) {
27084
+ correctValueBuf.length = 0;
27085
+ return;
27086
+ }
27087
+ const location = inInteraction ? "in-interaction" : inItemBody ? "pre-interaction" : "post-interaction";
27088
+ hooks.onOpenTag?.(localName, tag, result, ctx, location);
27089
+ });
27090
+ parser.on("closetag", (tag) => {
27091
+ const localName = tag.local ?? tag.name;
27092
+ if (localName === "itemBody") {
27093
+ inItemBody = false;
27094
+ return;
27095
+ }
27096
+ if (localName === hooks.interactionName) {
27097
+ inInteraction = false;
27098
+ hooks.onInteractionClose?.(result, ctx);
27099
+ return;
27100
+ }
27101
+ if (localName === "responseDeclaration") {
27102
+ currentResponseDeclId = void 0;
27103
+ return;
27104
+ }
27105
+ if (localName === "correctResponse") {
27106
+ inCorrectResponse = false;
27107
+ return;
27108
+ }
27109
+ if (localName === "value" && inCorrectResponse) {
27110
+ const value = normalizeWhitespace(correctValueBuf.join(""));
27111
+ if (value && currentResponseDeclId) {
27112
+ const values = correctResponsesByIdentifier.get(currentResponseDeclId);
27113
+ if (values) values.push(value);
27114
+ }
27115
+ correctValueBuf.length = 0;
27116
+ return;
27117
+ }
27118
+ const location = inInteraction ? "in-interaction" : inItemBody ? "pre-interaction" : "post-interaction";
27119
+ hooks.onCloseTag?.(localName, tag, result, ctx, location);
27120
+ });
27121
+ parser.on("text", (text) => {
27122
+ if (inCorrectResponse) {
27123
+ correctValueBuf.push(text);
27124
+ return;
27125
+ }
27126
+ if (_capture) ctx.pushToBuffer(_capture, text);
27127
+ });
27128
+ parser.on("cdata", (text) => {
27129
+ if (inCorrectResponse) {
27130
+ correctValueBuf.push(text);
27131
+ return;
27132
+ }
27133
+ if (_capture) ctx.pushToBuffer(_capture, text);
27134
+ });
27135
+ parser.on("error", (error) => {
27136
+ diagnostics.push({
27137
+ code: DiagnosticCode.LRN_SCHEMA_INVALID,
27138
+ level: "error",
27139
+ file: "assessmentItem",
27140
+ message: `Failed to parse QTI XML: ${error.message}`
27141
+ });
27142
+ });
27143
+ try {
27144
+ parser.write(inputXml).close();
27145
+ } catch (error) {
27146
+ diagnostics.push({
27147
+ code: DiagnosticCode.LRN_SCHEMA_INVALID,
27148
+ level: "error",
27149
+ file: "assessmentItem",
27150
+ message: `Failed to parse QTI XML: ${error instanceof Error ? error.message : String(error)}`
27151
+ });
27152
+ return result;
27154
27153
  }
27155
- });
27156
- parser.on("text", (text) => {
27157
- if (capture === "stimulus") stimulusBuf.push(text);
27158
- else if (capture === "prompt") promptBuf.push(text);
27159
- });
27160
- parser.on("cdata", (text) => {
27161
- if (capture === "stimulus") stimulusBuf.push(text);
27162
- else if (capture === "prompt") promptBuf.push(text);
27163
- });
27164
- try {
27165
- parser.write(inputXml).close();
27166
- } catch (error) {
27167
- diagnostics.push({
27154
+ hooks.onParseComplete?.(result, ctx);
27155
+ if (!foundAssessmentItem) diagnostics.push({
27168
27156
  code: DiagnosticCode.LRN_SCHEMA_INVALID,
27169
27157
  level: "error",
27170
27158
  file: "assessmentItem",
27171
- message: `Failed to parse QTI XML: ${error instanceof Error ? error.message : String(error)}`
27159
+ message: "No assessmentItem element found"
27172
27160
  });
27173
- }
27174
- if (!foundAssessmentItem) diagnostics.push({
27175
- code: DiagnosticCode.LRN_SCHEMA_INVALID,
27176
- level: "error",
27177
- file: "assessmentItem",
27178
- message: "No assessmentItem element found"
27179
- });
27180
- if (!foundItemBody) diagnostics.push({
27181
- code: DiagnosticCode.LRN_SCHEMA_INVALID,
27182
- level: "error",
27183
- file: "assessmentItem",
27184
- message: "No itemBody element found"
27185
- });
27186
- if (foundItemBody && drawingInteractionCount === 0) diagnostics.push({
27187
- code: DiagnosticCode.QTI_UNSUPPORTED_INTERACTION,
27188
- level: "error",
27189
- file: "assessmentItem.itemBody",
27190
- message: "No drawingInteraction found in itemBody"
27191
- });
27192
- if (drawingInteractionCount > 1) diagnostics.push({
27193
- code: DiagnosticCode.QTI_MULTIPLE_INTERACTIONS,
27194
- level: "error",
27195
- file: "assessmentItem.itemBody",
27196
- message: `Multiple drawingInteraction elements found (${drawingInteractionCount}), only single interaction supported`
27197
- });
27198
- return result;
27161
+ if (!foundItemBody) diagnostics.push({
27162
+ code: DiagnosticCode.LRN_SCHEMA_INVALID,
27163
+ level: "error",
27164
+ file: "assessmentItem",
27165
+ message: "No itemBody element found"
27166
+ });
27167
+ if (foundItemBody && interactionCount === 0) diagnostics.push({
27168
+ code: DiagnosticCode.QTI_UNSUPPORTED_INTERACTION,
27169
+ level: "error",
27170
+ file: "assessmentItem.itemBody",
27171
+ message: `No ${hooks.interactionName} found in itemBody`
27172
+ });
27173
+ if (interactionCount > 1) diagnostics.push({
27174
+ code: DiagnosticCode.QTI_MULTIPLE_INTERACTIONS,
27175
+ level: "error",
27176
+ file: "assessmentItem.itemBody",
27177
+ message: `Multiple ${hooks.interactionName} elements found (${interactionCount}), only single interaction supported`
27178
+ });
27179
+ hooks.validate?.(result, ctx, interactionCount);
27180
+ return result;
27181
+ };
27199
27182
  }
27200
27183
  //#endregion
27184
+ //#region src/qti-parser/readAssessmentItemDrawing.ts
27185
+ const readAssessmentItemDrawing = createAssessmentItemReader({
27186
+ interactionName: "drawingInteraction",
27187
+ createResult: (diagnostics) => ({ diagnostics }),
27188
+ onInteractionOpen: (tag, result, ctx) => {
27189
+ result.responseIdentifier = ctx.getAttr(tag, "responseIdentifier");
27190
+ if (ctx.capture === "stimulus") {
27191
+ result.stimulusText = ctx.flushBuffer("stimulus");
27192
+ ctx.capture = null;
27193
+ }
27194
+ },
27195
+ onOpenTag: (localName, tag, result, ctx, location) => {
27196
+ if (location === "pre-interaction") {
27197
+ if (!ctx.capture) {
27198
+ ctx.capture = "stimulus";
27199
+ ctx.clearBuffer("stimulus");
27200
+ }
27201
+ } else if (location === "in-interaction") {
27202
+ if (localName === "prompt") {
27203
+ ctx.capture = "prompt";
27204
+ ctx.clearBuffer("prompt");
27205
+ return true;
27206
+ }
27207
+ if (localName === "img") {
27208
+ result.imageSource = ctx.getAttr(tag, "src");
27209
+ result.imageAlt = ctx.getAttr(tag, "alt");
27210
+ const widthAttr = ctx.getAttr(tag, "width");
27211
+ const heightAttr = ctx.getAttr(tag, "height");
27212
+ if (widthAttr) result.imageWidth = parseInt(widthAttr, 10);
27213
+ if (heightAttr) result.imageHeight = parseInt(heightAttr, 10);
27214
+ return true;
27215
+ }
27216
+ }
27217
+ },
27218
+ onCloseTag: (localName, _tag, result, ctx, location) => {
27219
+ if (location === "in-interaction" && localName === "prompt" && ctx.capture === "prompt") {
27220
+ result.promptText = ctx.flushBuffer("prompt");
27221
+ ctx.capture = null;
27222
+ return true;
27223
+ }
27224
+ }
27225
+ });
27226
+ //#endregion
27201
27227
  //#region src/qti-to-learnosity/convertDrawingToLearnosity.ts
27202
27228
  /**
27203
27229
  * Build drawing stimulus from parsed QTI data
@@ -28672,14 +28698,6 @@ function parseMetadataTags(metadataXml, options = {}) {
28672
28698
  }
28673
28699
  //#endregion
28674
28700
  //#region src/qti-parser/readAssessmentItemUpload.ts
28675
- /**
28676
- * Read QTI uploadInteraction using a streaming parser.
28677
- *
28678
- * The Learnosity -> QTI serializer carries the fileupload allow-list on the
28679
- * interaction's `class` attribute as `lrn-allow-<suffix>` tokens and the file
28680
- * limit as `maxChoices` (QTI has no standard field for either). This reader
28681
- * recovers both, plus the stimulus HTML, so a fileupload item round-trips.
28682
- */
28683
28701
  /** Parse `lrn-allow-<suffix>` tokens from a class attribute into allow_* suffixes. */
28684
28702
  function parseAllowedFileTypes(classAttr) {
28685
28703
  if (!classAttr) return [];
@@ -28697,69 +28715,29 @@ function extractStimulus(inputXml) {
28697
28715
  const stimulus = itemBodyMatch[1].replace(/<uploadInteraction[\s\S]*?(?:\/>|<\/uploadInteraction>)/gi, "").trim();
28698
28716
  return stimulus.length > 0 ? stimulus : void 0;
28699
28717
  }
28700
- function readAssessmentItemUpload(inputXml) {
28701
- const diagnostics = [];
28702
- const result = {
28718
+ const _baseReader = createAssessmentItemReader({
28719
+ interactionName: "uploadInteraction",
28720
+ createResult: (diagnostics) => ({
28703
28721
  allowedFileTypes: [],
28704
28722
  diagnostics
28705
- };
28706
- const parser = new import_saxes.SaxesParser();
28707
- let foundAssessmentItem = false;
28708
- let foundItemBody = false;
28709
- let uploadInteractionCount = 0;
28710
- parser.on("opentag", (tag) => {
28711
- const localName = tag.local ?? tag.name;
28712
- if (localName === "assessmentItem") {
28713
- foundAssessmentItem = true;
28714
- result.identifier = getAttr$5(tag, "identifier");
28715
- result.title = getAttr$5(tag, "title") ?? null;
28716
- } else if (localName === "itemBody") foundItemBody = true;
28717
- else if (localName === "uploadInteraction") {
28718
- uploadInteractionCount++;
28719
- result.responseIdentifier = getAttr$5(tag, "responseIdentifier");
28720
- result.allowedFileTypes = parseAllowedFileTypes(getAttr$5(tag, "class"));
28721
- const maxChoices = getAttr$5(tag, "maxChoices");
28722
- if (maxChoices) {
28723
- const parsed = parseInt(maxChoices, 10);
28724
- if (!Number.isNaN(parsed)) result.maxFiles = parsed;
28725
- }
28723
+ }),
28724
+ onInteractionOpen: (tag, result, ctx) => {
28725
+ result.responseIdentifier = ctx.getAttr(tag, "responseIdentifier");
28726
+ result.allowedFileTypes = parseAllowedFileTypes(getAttr$5(tag, "class"));
28727
+ const maxChoices = ctx.getAttr(tag, "maxChoices");
28728
+ if (maxChoices) {
28729
+ const parsed = parseInt(maxChoices, 10);
28730
+ if (!Number.isNaN(parsed)) result.maxFiles = parsed;
28726
28731
  }
28727
- });
28728
- try {
28729
- parser.write(inputXml).close();
28730
- } catch (error) {
28731
- diagnostics.push({
28732
- code: DiagnosticCode.LRN_SCHEMA_INVALID,
28733
- level: "error",
28734
- file: "assessmentItem",
28735
- message: `Failed to parse QTI XML: ${error instanceof Error ? error.message : String(error)}`
28736
- });
28737
28732
  }
28738
- if (!foundAssessmentItem) diagnostics.push({
28739
- code: DiagnosticCode.LRN_SCHEMA_INVALID,
28740
- level: "error",
28741
- file: "assessmentItem",
28742
- message: "No assessmentItem element found"
28743
- });
28744
- if (!foundItemBody) diagnostics.push({
28745
- code: DiagnosticCode.LRN_SCHEMA_INVALID,
28746
- level: "error",
28747
- file: "assessmentItem",
28748
- message: "No itemBody element found"
28749
- });
28750
- if (foundItemBody && uploadInteractionCount === 0) diagnostics.push({
28751
- code: DiagnosticCode.QTI_UNSUPPORTED_INTERACTION,
28752
- level: "error",
28753
- file: "assessmentItem.itemBody",
28754
- message: "No uploadInteraction found in itemBody"
28755
- });
28756
- if (uploadInteractionCount > 1) diagnostics.push({
28757
- code: DiagnosticCode.QTI_MULTIPLE_INTERACTIONS,
28758
- level: "error",
28759
- file: "assessmentItem.itemBody",
28760
- message: `Multiple uploadInteraction elements found (${uploadInteractionCount}), only single interaction supported`
28761
- });
28762
- if (diagnostics.every((d) => d.level !== "error")) result.stimulus = extractStimulus(inputXml);
28733
+ });
28734
+ /**
28735
+ * Read uploadInteraction data from QTI assessmentItem XML.
28736
+ * Wraps the base reader to add post-parse stimulus extraction from raw XML.
28737
+ */
28738
+ function readAssessmentItemUpload(inputXml) {
28739
+ const result = _baseReader(inputXml);
28740
+ if (result.diagnostics.every((d) => d.level !== "error")) result.stimulus = extractStimulus(inputXml);
28763
28741
  return result;
28764
28742
  }
28765
28743
  //#endregion