@citolab/qti-components 9.4.0 → 10.0.0-next.1

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 (57) hide show
  1. package/cdn/index.global.js +1 -1
  2. package/cdn/index.js +290 -243
  3. package/dist/base.d.ts +2 -2
  4. package/dist/base.js +1 -1
  5. package/dist/{chunk-C3JPUV36.js → chunk-35WWWFS6.js} +2 -2
  6. package/dist/{chunk-3BAQWO5C.js → chunk-6K3QWJHH.js} +2 -2
  7. package/dist/{chunk-XEWGFAS4.js → chunk-6U3YPHXU.js} +67 -27
  8. package/dist/chunk-6U3YPHXU.js.map +1 -0
  9. package/dist/{chunk-GNTO3IFM.js → chunk-CKJ7M7JQ.js} +571 -375
  10. package/dist/chunk-CKJ7M7JQ.js.map +1 -0
  11. package/dist/{chunk-BMXG7D2N.js → chunk-FD4AB6TM.js} +2 -2
  12. package/dist/{chunk-LKHRHFXO.js → chunk-FWR6HZQS.js} +6 -6
  13. package/dist/{chunk-B5XHZI2P.js → chunk-GBZNFSFY.js} +2 -2
  14. package/dist/{chunk-ACRN7YJM.js → chunk-MI7774NV.js} +2 -2
  15. package/dist/{chunk-MSGYZE6L.js → chunk-RSMYGGQK.js} +128 -48
  16. package/dist/chunk-RSMYGGQK.js.map +1 -0
  17. package/dist/{chunk-B74SYQB2.js → chunk-RU6332MD.js} +3 -3
  18. package/dist/{chunk-R7MMMDP7.js → chunk-TDWJ6WZA.js} +20 -2
  19. package/dist/chunk-TDWJ6WZA.js.map +1 -0
  20. package/dist/{chunk-JHPQJDAV.js → chunk-YYIS6FDP.js} +2 -2
  21. package/dist/chunk-ZP6QQYSU.js +7 -0
  22. package/dist/chunk-ZP6QQYSU.js.map +1 -0
  23. package/dist/corrections.d.ts +3 -3
  24. package/dist/corrections.js +8 -8
  25. package/dist/elements.d.ts +64 -2
  26. package/dist/elements.js +15 -5
  27. package/dist/index.d.ts +5 -5
  28. package/dist/index.js +28 -14
  29. package/dist/interactions.d.ts +2 -2
  30. package/dist/interactions.js +3 -3
  31. package/dist/item.css +11 -0
  32. package/dist/item.js +4 -4
  33. package/dist/loader.d.ts +1 -1
  34. package/dist/processing.d.ts +2 -2
  35. package/dist/processing.js +3 -3
  36. package/dist/qti-components-jsx.d.ts +138 -191
  37. package/dist/{qti-condition-expression.d-L7yb3Rzy.d.ts → qti-condition-expression.d-VJH6cWxf.d.ts} +1 -1
  38. package/dist/{qti-expression.d-CuaLjZ6g.d.ts → qti-expression.d-BPxEp8HU.d.ts} +7 -0
  39. package/dist/{qti-test.d-Cud5Gvy0.d.ts → qti-test.d-DkpBNcsv.d.ts} +67 -9
  40. package/dist/{qti-text-entry-interaction.d-DKvz9ncv.d.ts → qti-text-entry-interaction.d-q8u5BiVK.d.ts} +11 -2
  41. package/dist/test.d.ts +3 -3
  42. package/dist/test.js +9 -5
  43. package/package.json +10 -10
  44. package/dist/chunk-A32YH4H5.js +0 -7
  45. package/dist/chunk-A32YH4H5.js.map +0 -1
  46. package/dist/chunk-GNTO3IFM.js.map +0 -1
  47. package/dist/chunk-MSGYZE6L.js.map +0 -1
  48. package/dist/chunk-R7MMMDP7.js.map +0 -1
  49. package/dist/chunk-XEWGFAS4.js.map +0 -1
  50. /package/dist/{chunk-C3JPUV36.js.map → chunk-35WWWFS6.js.map} +0 -0
  51. /package/dist/{chunk-3BAQWO5C.js.map → chunk-6K3QWJHH.js.map} +0 -0
  52. /package/dist/{chunk-BMXG7D2N.js.map → chunk-FD4AB6TM.js.map} +0 -0
  53. /package/dist/{chunk-LKHRHFXO.js.map → chunk-FWR6HZQS.js.map} +0 -0
  54. /package/dist/{chunk-B5XHZI2P.js.map → chunk-GBZNFSFY.js.map} +0 -0
  55. /package/dist/{chunk-ACRN7YJM.js.map → chunk-MI7774NV.js.map} +0 -0
  56. /package/dist/{chunk-B74SYQB2.js.map → chunk-RU6332MD.js.map} +0 -0
  57. /package/dist/{chunk-JHPQJDAV.js.map → chunk-YYIS6FDP.js.map} +0 -0
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  qtiItemElements
3
- } from "./chunk-B74SYQB2.js";
3
+ } from "./chunk-RU6332MD.js";
4
4
 
5
5
  // ../qti-item/dist/register.js
6
6
  for (const { tag, ctor } of qtiItemElements) {
@@ -8,4 +8,4 @@ for (const { tag, ctor } of qtiItemElements) {
8
8
  customElements.define(tag, ctor);
9
9
  }
10
10
  }
11
- //# sourceMappingURL=chunk-BMXG7D2N.js.map
11
+ //# sourceMappingURL=chunk-FD4AB6TM.js.map
@@ -2,10 +2,10 @@ import {
2
2
  QtiTest,
3
3
  TestCheckItem,
4
4
  TestNavigation
5
- } from "./chunk-GNTO3IFM.js";
5
+ } from "./chunk-CKJ7M7JQ.js";
6
6
  import {
7
7
  QtiAssessmentItem
8
- } from "./chunk-XEWGFAS4.js";
8
+ } from "./chunk-6U3YPHXU.js";
9
9
  import {
10
10
  QtiAssociateInteraction,
11
11
  QtiChoiceInteraction,
@@ -28,10 +28,10 @@ import {
28
28
  QtiSimpleChoice,
29
29
  QtiSliderInteraction,
30
30
  QtiTextEntryInteraction
31
- } from "./chunk-MSGYZE6L.js";
31
+ } from "./chunk-RSMYGGQK.js";
32
32
  import {
33
33
  QtiItem
34
- } from "./chunk-B74SYQB2.js";
34
+ } from "./chunk-RU6332MD.js";
35
35
  import {
36
36
  watch
37
37
  } from "./chunk-4DB4SC5K.js";
@@ -41,7 +41,7 @@ import {
41
41
  computedItemContext,
42
42
  configContext,
43
43
  responseAttributeConverter
44
- } from "./chunk-R7MMMDP7.js";
44
+ } from "./chunk-TDWJ6WZA.js";
45
45
 
46
46
  // ../qti-corrections/dist/components/item-correct-response-mode/item-correct-response-mode.js
47
47
  import { html, LitElement } from "lit";
@@ -1661,4 +1661,4 @@ export {
1661
1661
  QtiTestCorrection,
1662
1662
  TestCheckItemCorrection
1663
1663
  };
1664
- //# sourceMappingURL=chunk-LKHRHFXO.js.map
1664
+ //# sourceMappingURL=chunk-FWR6HZQS.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  qtiContentElements
3
- } from "./chunk-XEWGFAS4.js";
3
+ } from "./chunk-6U3YPHXU.js";
4
4
 
5
5
  // ../qti-elements/dist/register.js
6
6
  for (const { tag, ctor } of qtiContentElements) {
@@ -8,4 +8,4 @@ for (const { tag, ctor } of qtiContentElements) {
8
8
  customElements.define(tag, ctor);
9
9
  }
10
10
  }
11
- //# sourceMappingURL=chunk-B5XHZI2P.js.map
11
+ //# sourceMappingURL=chunk-GBZNFSFY.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  qtiProcessingElements
3
- } from "./chunk-3BAQWO5C.js";
3
+ } from "./chunk-6K3QWJHH.js";
4
4
 
5
5
  // ../qti-processing/dist/register.js
6
6
  for (const { tag, ctor } of qtiProcessingElements) {
@@ -8,4 +8,4 @@ for (const { tag, ctor } of qtiProcessingElements) {
8
8
  customElements.define(tag, ctor);
9
9
  }
10
10
  }
11
- //# sourceMappingURL=chunk-ACRN7YJM.js.map
11
+ //# sourceMappingURL=chunk-MI7774NV.js.map
@@ -14,7 +14,7 @@ import {
14
14
  responseAttributeConverter,
15
15
  serializeResponseAttribute,
16
16
  validationMessage
17
- } from "./chunk-R7MMMDP7.js";
17
+ } from "./chunk-TDWJ6WZA.js";
18
18
 
19
19
  // ../interactions/core/dist/elements/qti-associable-hotspot/qti-associable-hotspot.js
20
20
  import { LitElement, html } from "lit";
@@ -5830,6 +5830,7 @@ var QtiExtendedTextInteraction = class extends Interaction {
5830
5830
  warnedAboutXhtml = true;
5831
5831
  console.warn('<qti-extended-text-interaction format="xhtml"> renders as plain text. The interaction has no rich-text editor; the recorded response will contain no markup.');
5832
5832
  };
5833
+ this.minStrings = 0;
5833
5834
  this.response = null;
5834
5835
  this._handleResponseChange = () => {
5835
5836
  this._internals.setFormValue(this.value);
@@ -5902,7 +5903,7 @@ var QtiExtendedTextInteraction = class extends Interaction {
5902
5903
  } else {
5903
5904
  isValid = textarea.checkValidity();
5904
5905
  }
5905
- if (isValid && !this.response) {
5906
+ if (isValid && !this.response && this.minStrings >= 1) {
5906
5907
  isValid = false;
5907
5908
  }
5908
5909
  if (!isValid && !validityMessage) {
@@ -5984,6 +5985,9 @@ __decorate18([
5984
5985
  __decorate18([
5985
5986
  watch("format")
5986
5987
  ], QtiExtendedTextInteraction.prototype, "_handleFormatChange", void 0);
5988
+ __decorate18([
5989
+ property17({ type: Number, attribute: "min-strings" })
5990
+ ], QtiExtendedTextInteraction.prototype, "minStrings", void 0);
5987
5991
  __decorate18([
5988
5992
  property17({ type: String, attribute: "pattern-mask" })
5989
5993
  ], QtiExtendedTextInteraction.prototype, "patternMask", void 0);
@@ -6499,7 +6503,8 @@ var qti_graphic_gap_match_interaction_styles_default = [
6499
6503
  width: 25%;
6500
6504
  }
6501
6505
  & [part='image'] {
6502
- width: 75%;
6506
+ /* A cap, not a width: the slot must stay exactly the graphic's box (see below). */
6507
+ max-width: 75%;
6503
6508
  }
6504
6509
  }
6505
6510
  :host(.qti-choices-right) {
@@ -6508,12 +6513,25 @@ var qti_graphic_gap_match_interaction_styles_default = [
6508
6513
  width: 25%;
6509
6514
  }
6510
6515
  & [part='image'] {
6511
- width: 75%;
6516
+ /* A cap, not a width: the slot must stay exactly the graphic's box (see below). */
6517
+ max-width: 75%;
6512
6518
  }
6513
6519
  }
6520
+ /*
6521
+ * The coordinate space the drop areas sit on. Every qti-associable-hotspot is position:absolute
6522
+ * and placed with left/top percentages of the graphic (positionShapes), so this slot must be
6523
+ * (a) a positioning context and (b) exactly the box of the graphic — the same contract as the
6524
+ * hotspot interaction's slot.
6525
+ *
6526
+ * width: fit-content shrink-wraps the slot to the graphic instead of the full row, so a
6527
+ * percentage of the slot is a percentage of the picture.
6528
+ * max-width: 100% lets the slot, and with it the graphic, narrow to the container.
6529
+ */
6514
6530
  [part='image'] {
6515
6531
  display: block;
6516
6532
  position: relative;
6533
+ width: fit-content;
6534
+ max-width: 100%;
6517
6535
  }
6518
6536
  /* [part='drops'] , */
6519
6537
 
@@ -6527,8 +6545,22 @@ var qti_graphic_gap_match_interaction_styles_default = [
6527
6545
  border-radius: 0.3rem;
6528
6546
  gap: 0.5rem;
6529
6547
  }
6530
- ::slotted(img) {
6531
- display: inline-block;
6548
+ /*
6549
+ * Fluid, like the hotspot interaction's graphic: an item declares the graphic at the size its
6550
+ * coords were authored in (often a full-resolution picture, 1600px wide), and it must still fit a
6551
+ * column or a phone. The drop areas are percentages of it, so they scale along.
6552
+ *
6553
+ * max-width: 100% shrinks a graphic wider than its container, never upscales a small one.
6554
+ * height: auto keeps the aspect ratio the width/height attributes declare; without it the
6555
+ * height attribute pins the height while the width shrinks.
6556
+ * display: block no inline descender gap under the picture, which would make the slot
6557
+ * taller than the graphic and skew every vertical percentage.
6558
+ */
6559
+ ::slotted(img),
6560
+ ::slotted(object) {
6561
+ display: block;
6562
+ max-width: 100%;
6563
+ height: auto;
6532
6564
  user-select: none;
6533
6565
  pointer-events: none;
6534
6566
  }
@@ -6550,36 +6582,57 @@ var QtiGraphicGapMatchInteraction = class extends DragDropSlottedSortableMixin(S
6550
6582
  shouldReturnToInventoryOnInventoryDrop() {
6551
6583
  return true;
6552
6584
  }
6553
- #positionHotspotOnRegister(e) {
6554
- const hotspot = e.target;
6585
+ /**
6586
+ * The background graphic: a direct child, as QTI places it. Not `findGraphic(this)`, which
6587
+ * searches every descendant and would pick up a `qti-gap-img`'s picture (or one in the prompt)
6588
+ * when it comes first.
6589
+ */
6590
+ #graphic() {
6591
+ return this.querySelector(':scope > img, :scope > object[type^="image"]');
6592
+ }
6593
+ /**
6594
+ * Pins the graphic's box to the aspect ratio its width/height attributes declare: the coordinate
6595
+ * space the drop areas are percentages of. With the fluid `height: auto` (see the styles) the box
6596
+ * would otherwise follow the bitmap — an `<object>` gets no ratio from its attributes at all, and
6597
+ * an `<img>` only `auto w / h`, where the loaded bitmap's own ratio wins. Either way a picture
6598
+ * whose pixels differ from its declared size would slide out from under its drop areas. Pinned,
6599
+ * it fills the declared box as it does at its fixed size.
6600
+ */
6601
+ #keepDeclaredRatio(graphic) {
6602
+ if (graphic.style.aspectRatio)
6603
+ return;
6604
+ const length = (name) => {
6605
+ const raw = (graphic.getAttribute(name) ?? "").trim();
6606
+ const value = parseFloat(raw);
6607
+ return raw.endsWith("%") || !(value > 0) ? null : value;
6608
+ };
6609
+ const width = length("width");
6610
+ const height = length("height");
6611
+ if (width && height)
6612
+ graphic.style.aspectRatio = `${width} / ${height}`;
6613
+ }
6614
+ /**
6615
+ * Places a drop area over the graphic with `positionShapes`, the hotspot interaction's helper:
6616
+ * percentages of the coordinate space the `coords` were authored in, so the areas scale with the
6617
+ * graphic when it is narrower than its declared width (see the styles). They used to be written
6618
+ * in pixels, which only held while the graphic rendered at exactly that width.
6619
+ */
6620
+ #positionHotspot(hotspot) {
6621
+ const graphic = this.#graphic();
6555
6622
  const coords = hotspot.getAttribute("coords");
6556
6623
  const shape = hotspot.getAttribute("shape");
6557
- const coordsNumber = coords.split(",").map((s) => parseInt(s));
6558
- switch (shape) {
6559
- case "circle":
6560
- {
6561
- const [centerX, centerY, radius] = coordsNumber;
6562
- hotspot.style.left = centerX - radius + "px";
6563
- hotspot.style.top = centerY - radius + "px";
6564
- hotspot.style.width = hotspot.style.height = 2 * radius + "px";
6565
- }
6566
- break;
6567
- case "rect":
6568
- {
6569
- const [leftX, topY, rightX, bottomY] = coordsNumber;
6570
- hotspot.style.left = leftX + "px";
6571
- hotspot.style.top = topY + "px";
6572
- hotspot.style.width = rightX - leftX + "px";
6573
- hotspot.style.height = bottomY - topY + "px";
6574
- }
6575
- break;
6576
- default:
6577
- break;
6578
- }
6624
+ if (!graphic || !coords || !shape)
6625
+ return;
6626
+ this.#keepDeclaredRatio(graphic);
6627
+ positionShapes(shape, coords.split(",").map((s) => parseFloat(s)), graphic, hotspot);
6579
6628
  }
6629
+ #positionHotspotOnRegister = (e) => {
6630
+ this.#positionHotspot(e.target);
6631
+ };
6580
6632
  connectedCallback() {
6581
6633
  super.connectedCallback();
6582
6634
  this.addEventListener("qti-register-hotspot", this.#positionHotspotOnRegister);
6635
+ this.querySelectorAll(":scope > qti-associable-hotspot").forEach((hotspot) => this.#positionHotspot(hotspot));
6583
6636
  }
6584
6637
  disconnectedCallback() {
6585
6638
  super.disconnectedCallback();
@@ -10655,7 +10708,7 @@ var qti_slider_interaction_styles_default = [
10655
10708
  transform: translateX(-50%);
10656
10709
  cursor: pointer;
10657
10710
  border-radius: 9999px; /* rounded-full */
10658
- left: var(--value-percentage);
10711
+ left: var(--value-percentage, 0%);
10659
10712
  }
10660
10713
  [part='value'] {
10661
10714
  position: absolute;
@@ -10682,7 +10735,7 @@ var __decorate26 = function(decorators, target, key, desc) {
10682
10735
  var QtiSliderInteraction = class extends Interaction {
10683
10736
  constructor() {
10684
10737
  super(...arguments);
10685
- this.#value = 0;
10738
+ this.#value = null;
10686
10739
  this.min = 0;
10687
10740
  this.max = 100;
10688
10741
  this.step = 1;
@@ -10690,44 +10743,71 @@ var QtiSliderInteraction = class extends Interaction {
10690
10743
  static {
10691
10744
  this.styles = qti_slider_interaction_styles_default;
10692
10745
  }
10746
+ /**
10747
+ * The value the slider shows, or `null` before there is one. A slider has no initial position of
10748
+ * its own (QTI 3): it starts at the response declaration's default, which reaches it through
10749
+ * `response` like any other value the item holds, or it starts empty.
10750
+ */
10693
10751
  #value;
10694
10752
  validate() {
10695
10753
  return true;
10696
10754
  }
10697
10755
  connectedCallback() {
10698
10756
  super.connectedCallback();
10699
- if (!this.hasAttribute("response")) {
10700
- this.#updateValue(this.min);
10701
- }
10702
10757
  this.setAttribute("tabindex", "0");
10703
10758
  this.setAttribute("role", "slider");
10704
10759
  }
10760
+ willUpdate(changed) {
10761
+ super.willUpdate(changed);
10762
+ this._internals.ariaValueMin = String(this.min);
10763
+ this._internals.ariaValueMax = String(this.max);
10764
+ }
10765
+ /**
10766
+ * Shows the value without publishing it: it came from the item (a default or a restored answer) or
10767
+ * from the host, which hold it already. Only the candidate's input is published.
10768
+ */
10705
10769
  get response() {
10706
- return this.#value.toString();
10770
+ return this.#value === null ? null : this.#value.toString();
10707
10771
  }
10708
10772
  set response(val) {
10709
- if (val === null || val === "")
10773
+ if (val === null || val === void 0 || val === "") {
10774
+ this.#show(null);
10710
10775
  return;
10776
+ }
10711
10777
  const newValue = parseFloat(val);
10712
10778
  if (!isNaN(newValue)) {
10713
- this.#updateValue(newValue);
10779
+ this.#show(newValue);
10714
10780
  }
10715
10781
  }
10716
10782
  /** Extension hook for optional content rendered on the slider rail. */
10717
10783
  renderRailSupplement() {
10718
10784
  return nothing5;
10719
10785
  }
10720
- #updateValue(newValue) {
10786
+ /** Moves the knob to `newValue`, clamped to the bounds, or empties the slider. Returns whether it moved. */
10787
+ #show(newValue) {
10721
10788
  const oldValue = this.#value;
10722
- this.#value = Math.min(this.max, Math.max(this.min, newValue));
10789
+ this.#value = newValue === null ? null : Math.min(this.max, Math.max(this.min, newValue));
10723
10790
  if (this.#value === oldValue) {
10724
- return;
10791
+ return false;
10792
+ }
10793
+ if (this.#value === null) {
10794
+ this.style.removeProperty("--value-percentage");
10795
+ this._internals.setFormValue(null);
10796
+ this._internals.ariaValueNow = null;
10797
+ } else {
10798
+ const valuePercentage = (this.#value - this.min) / (this.max - this.min) * 100;
10799
+ this.style.setProperty("--value-percentage", `${valuePercentage}%`);
10800
+ this._internals.setFormValue(this.value);
10801
+ this._internals.ariaValueNow = String(this.#value);
10725
10802
  }
10726
- const valuePercentage = (this.#value - this.min) / (this.max - this.min) * 100;
10727
- this.style.setProperty("--value-percentage", `${valuePercentage}%`);
10728
- this._internals.setFormValue(this.value);
10729
- this.saveResponse(this.response);
10730
10803
  this.requestUpdate();
10804
+ return true;
10805
+ }
10806
+ /** The candidate's input: shows it and publishes it. */
10807
+ #commit(newValue) {
10808
+ if (this.#show(newValue)) {
10809
+ this.saveResponse(this.response);
10810
+ }
10731
10811
  }
10732
10812
  render() {
10733
10813
  return html30`
@@ -10742,7 +10822,7 @@ var QtiSliderInteraction = class extends Interaction {
10742
10822
 
10743
10823
  <div id="rail" part="rail" @mousedown=${this.#onMouseDown} @touchstart=${this.#onTouchStart}>
10744
10824
  <div id="knob" part="knob">
10745
- <div id="value" part="value">${this.response}</div>
10825
+ ${this.#value === null ? nothing5 : html30`<div id="value" part="value">${this.#value}</div>`}
10746
10826
  </div>
10747
10827
 
10748
10828
  ${this.renderRailSupplement()}
@@ -10780,7 +10860,7 @@ var QtiSliderInteraction = class extends Interaction {
10780
10860
  const diffX = pageX - railRect.left;
10781
10861
  const percentage = Math.min(1, Math.max(0, diffX / railRect.width));
10782
10862
  const steppedValue = this.min + Math.round(percentage * (this.max - this.min) / this.step) * this.step;
10783
- this.#updateValue(steppedValue);
10863
+ this.#commit(steppedValue);
10784
10864
  }
10785
10865
  #onDragEnd() {
10786
10866
  this.dispatchEvent(new Event("change", { bubbles: true }));
@@ -11754,4 +11834,4 @@ export {
11754
11834
  elements31 as elements21,
11755
11835
  qtiInteractionElements
11756
11836
  };
11757
- //# sourceMappingURL=chunk-MSGYZE6L.js.map
11837
+ //# sourceMappingURL=chunk-RSMYGGQK.js.map