@citolab/qti-components 9.4.0 → 9.5.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 (56) 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-3BAQWO5C.js → chunk-6K3QWJHH.js} +2 -2
  6. package/dist/{chunk-XEWGFAS4.js → chunk-6U3YPHXU.js} +67 -27
  7. package/dist/chunk-6U3YPHXU.js.map +1 -0
  8. package/dist/{chunk-MSGYZE6L.js → chunk-DAFB2E5H.js} +123 -47
  9. package/dist/{chunk-MSGYZE6L.js.map → chunk-DAFB2E5H.js.map} +1 -1
  10. package/dist/{chunk-BMXG7D2N.js → chunk-FD4AB6TM.js} +2 -2
  11. package/dist/{chunk-B5XHZI2P.js → chunk-GBZNFSFY.js} +2 -2
  12. package/dist/{chunk-ACRN7YJM.js → chunk-MI7774NV.js} +2 -2
  13. package/dist/{chunk-JHPQJDAV.js → chunk-OQDBARD5.js} +2 -2
  14. package/dist/{chunk-B74SYQB2.js → chunk-RU6332MD.js} +3 -3
  15. package/dist/{chunk-GNTO3IFM.js → chunk-SIE3E4FG.js} +717 -417
  16. package/dist/chunk-SIE3E4FG.js.map +1 -0
  17. package/dist/{chunk-LKHRHFXO.js → chunk-SU63QGGD.js} +6 -6
  18. package/dist/{chunk-R7MMMDP7.js → chunk-TDWJ6WZA.js} +20 -2
  19. package/dist/chunk-TDWJ6WZA.js.map +1 -0
  20. package/dist/{chunk-C3JPUV36.js → chunk-YZRODVYZ.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 +30 -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 +227 -187
  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-86TlaMlI.d.ts} +106 -9
  40. package/dist/{qti-text-entry-interaction.d-DKvz9ncv.d.ts → qti-text-entry-interaction.d-C4eixT-D.d.ts} +6 -1
  41. package/dist/test.d.ts +3 -3
  42. package/dist/test.js +11 -5
  43. package/package.json +5 -5
  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-R7MMMDP7.js.map +0 -1
  48. package/dist/chunk-XEWGFAS4.js.map +0 -1
  49. /package/dist/{chunk-3BAQWO5C.js.map → chunk-6K3QWJHH.js.map} +0 -0
  50. /package/dist/{chunk-BMXG7D2N.js.map → chunk-FD4AB6TM.js.map} +0 -0
  51. /package/dist/{chunk-B5XHZI2P.js.map → chunk-GBZNFSFY.js.map} +0 -0
  52. /package/dist/{chunk-ACRN7YJM.js.map → chunk-MI7774NV.js.map} +0 -0
  53. /package/dist/{chunk-JHPQJDAV.js.map → chunk-OQDBARD5.js.map} +0 -0
  54. /package/dist/{chunk-B74SYQB2.js.map → chunk-RU6332MD.js.map} +0 -0
  55. /package/dist/{chunk-LKHRHFXO.js.map → chunk-SU63QGGD.js.map} +0 -0
  56. /package/dist/{chunk-C3JPUV36.js.map → chunk-YZRODVYZ.js.map} +0 -0
@@ -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";
@@ -6499,7 +6499,8 @@ var qti_graphic_gap_match_interaction_styles_default = [
6499
6499
  width: 25%;
6500
6500
  }
6501
6501
  & [part='image'] {
6502
- width: 75%;
6502
+ /* A cap, not a width: the slot must stay exactly the graphic's box (see below). */
6503
+ max-width: 75%;
6503
6504
  }
6504
6505
  }
6505
6506
  :host(.qti-choices-right) {
@@ -6508,12 +6509,25 @@ var qti_graphic_gap_match_interaction_styles_default = [
6508
6509
  width: 25%;
6509
6510
  }
6510
6511
  & [part='image'] {
6511
- width: 75%;
6512
+ /* A cap, not a width: the slot must stay exactly the graphic's box (see below). */
6513
+ max-width: 75%;
6512
6514
  }
6513
6515
  }
6516
+ /*
6517
+ * The coordinate space the drop areas sit on. Every qti-associable-hotspot is position:absolute
6518
+ * and placed with left/top percentages of the graphic (positionShapes), so this slot must be
6519
+ * (a) a positioning context and (b) exactly the box of the graphic — the same contract as the
6520
+ * hotspot interaction's slot.
6521
+ *
6522
+ * width: fit-content shrink-wraps the slot to the graphic instead of the full row, so a
6523
+ * percentage of the slot is a percentage of the picture.
6524
+ * max-width: 100% lets the slot, and with it the graphic, narrow to the container.
6525
+ */
6514
6526
  [part='image'] {
6515
6527
  display: block;
6516
6528
  position: relative;
6529
+ width: fit-content;
6530
+ max-width: 100%;
6517
6531
  }
6518
6532
  /* [part='drops'] , */
6519
6533
 
@@ -6527,8 +6541,22 @@ var qti_graphic_gap_match_interaction_styles_default = [
6527
6541
  border-radius: 0.3rem;
6528
6542
  gap: 0.5rem;
6529
6543
  }
6530
- ::slotted(img) {
6531
- display: inline-block;
6544
+ /*
6545
+ * Fluid, like the hotspot interaction's graphic: an item declares the graphic at the size its
6546
+ * coords were authored in (often a full-resolution picture, 1600px wide), and it must still fit a
6547
+ * column or a phone. The drop areas are percentages of it, so they scale along.
6548
+ *
6549
+ * max-width: 100% shrinks a graphic wider than its container, never upscales a small one.
6550
+ * height: auto keeps the aspect ratio the width/height attributes declare; without it the
6551
+ * height attribute pins the height while the width shrinks.
6552
+ * display: block no inline descender gap under the picture, which would make the slot
6553
+ * taller than the graphic and skew every vertical percentage.
6554
+ */
6555
+ ::slotted(img),
6556
+ ::slotted(object) {
6557
+ display: block;
6558
+ max-width: 100%;
6559
+ height: auto;
6532
6560
  user-select: none;
6533
6561
  pointer-events: none;
6534
6562
  }
@@ -6550,36 +6578,57 @@ var QtiGraphicGapMatchInteraction = class extends DragDropSlottedSortableMixin(S
6550
6578
  shouldReturnToInventoryOnInventoryDrop() {
6551
6579
  return true;
6552
6580
  }
6553
- #positionHotspotOnRegister(e) {
6554
- const hotspot = e.target;
6581
+ /**
6582
+ * The background graphic: a direct child, as QTI places it. Not `findGraphic(this)`, which
6583
+ * searches every descendant and would pick up a `qti-gap-img`'s picture (or one in the prompt)
6584
+ * when it comes first.
6585
+ */
6586
+ #graphic() {
6587
+ return this.querySelector(':scope > img, :scope > object[type^="image"]');
6588
+ }
6589
+ /**
6590
+ * Pins the graphic's box to the aspect ratio its width/height attributes declare: the coordinate
6591
+ * space the drop areas are percentages of. With the fluid `height: auto` (see the styles) the box
6592
+ * would otherwise follow the bitmap — an `<object>` gets no ratio from its attributes at all, and
6593
+ * an `<img>` only `auto w / h`, where the loaded bitmap's own ratio wins. Either way a picture
6594
+ * whose pixels differ from its declared size would slide out from under its drop areas. Pinned,
6595
+ * it fills the declared box as it does at its fixed size.
6596
+ */
6597
+ #keepDeclaredRatio(graphic) {
6598
+ if (graphic.style.aspectRatio)
6599
+ return;
6600
+ const length = (name) => {
6601
+ const raw = (graphic.getAttribute(name) ?? "").trim();
6602
+ const value = parseFloat(raw);
6603
+ return raw.endsWith("%") || !(value > 0) ? null : value;
6604
+ };
6605
+ const width = length("width");
6606
+ const height = length("height");
6607
+ if (width && height)
6608
+ graphic.style.aspectRatio = `${width} / ${height}`;
6609
+ }
6610
+ /**
6611
+ * Places a drop area over the graphic with `positionShapes`, the hotspot interaction's helper:
6612
+ * percentages of the coordinate space the `coords` were authored in, so the areas scale with the
6613
+ * graphic when it is narrower than its declared width (see the styles). They used to be written
6614
+ * in pixels, which only held while the graphic rendered at exactly that width.
6615
+ */
6616
+ #positionHotspot(hotspot) {
6617
+ const graphic = this.#graphic();
6555
6618
  const coords = hotspot.getAttribute("coords");
6556
6619
  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
- }
6620
+ if (!graphic || !coords || !shape)
6621
+ return;
6622
+ this.#keepDeclaredRatio(graphic);
6623
+ positionShapes(shape, coords.split(",").map((s) => parseFloat(s)), graphic, hotspot);
6579
6624
  }
6625
+ #positionHotspotOnRegister = (e) => {
6626
+ this.#positionHotspot(e.target);
6627
+ };
6580
6628
  connectedCallback() {
6581
6629
  super.connectedCallback();
6582
6630
  this.addEventListener("qti-register-hotspot", this.#positionHotspotOnRegister);
6631
+ this.querySelectorAll(":scope > qti-associable-hotspot").forEach((hotspot) => this.#positionHotspot(hotspot));
6583
6632
  }
6584
6633
  disconnectedCallback() {
6585
6634
  super.disconnectedCallback();
@@ -10655,7 +10704,7 @@ var qti_slider_interaction_styles_default = [
10655
10704
  transform: translateX(-50%);
10656
10705
  cursor: pointer;
10657
10706
  border-radius: 9999px; /* rounded-full */
10658
- left: var(--value-percentage);
10707
+ left: var(--value-percentage, 0%);
10659
10708
  }
10660
10709
  [part='value'] {
10661
10710
  position: absolute;
@@ -10682,7 +10731,7 @@ var __decorate26 = function(decorators, target, key, desc) {
10682
10731
  var QtiSliderInteraction = class extends Interaction {
10683
10732
  constructor() {
10684
10733
  super(...arguments);
10685
- this.#value = 0;
10734
+ this.#value = null;
10686
10735
  this.min = 0;
10687
10736
  this.max = 100;
10688
10737
  this.step = 1;
@@ -10690,44 +10739,71 @@ var QtiSliderInteraction = class extends Interaction {
10690
10739
  static {
10691
10740
  this.styles = qti_slider_interaction_styles_default;
10692
10741
  }
10742
+ /**
10743
+ * The value the slider shows, or `null` before there is one. A slider has no initial position of
10744
+ * its own (QTI 3): it starts at the response declaration's default, which reaches it through
10745
+ * `response` like any other value the item holds, or it starts empty.
10746
+ */
10693
10747
  #value;
10694
10748
  validate() {
10695
10749
  return true;
10696
10750
  }
10697
10751
  connectedCallback() {
10698
10752
  super.connectedCallback();
10699
- if (!this.hasAttribute("response")) {
10700
- this.#updateValue(this.min);
10701
- }
10702
10753
  this.setAttribute("tabindex", "0");
10703
10754
  this.setAttribute("role", "slider");
10704
10755
  }
10756
+ willUpdate(changed) {
10757
+ super.willUpdate(changed);
10758
+ this._internals.ariaValueMin = String(this.min);
10759
+ this._internals.ariaValueMax = String(this.max);
10760
+ }
10761
+ /**
10762
+ * Shows the value without publishing it: it came from the item (a default or a restored answer) or
10763
+ * from the host, which hold it already. Only the candidate's input is published.
10764
+ */
10705
10765
  get response() {
10706
- return this.#value.toString();
10766
+ return this.#value === null ? null : this.#value.toString();
10707
10767
  }
10708
10768
  set response(val) {
10709
- if (val === null || val === "")
10769
+ if (val === null || val === void 0 || val === "") {
10770
+ this.#show(null);
10710
10771
  return;
10772
+ }
10711
10773
  const newValue = parseFloat(val);
10712
10774
  if (!isNaN(newValue)) {
10713
- this.#updateValue(newValue);
10775
+ this.#show(newValue);
10714
10776
  }
10715
10777
  }
10716
10778
  /** Extension hook for optional content rendered on the slider rail. */
10717
10779
  renderRailSupplement() {
10718
10780
  return nothing5;
10719
10781
  }
10720
- #updateValue(newValue) {
10782
+ /** Moves the knob to `newValue`, clamped to the bounds, or empties the slider. Returns whether it moved. */
10783
+ #show(newValue) {
10721
10784
  const oldValue = this.#value;
10722
- this.#value = Math.min(this.max, Math.max(this.min, newValue));
10785
+ this.#value = newValue === null ? null : Math.min(this.max, Math.max(this.min, newValue));
10723
10786
  if (this.#value === oldValue) {
10724
- return;
10787
+ return false;
10788
+ }
10789
+ if (this.#value === null) {
10790
+ this.style.removeProperty("--value-percentage");
10791
+ this._internals.setFormValue(null);
10792
+ this._internals.ariaValueNow = null;
10793
+ } else {
10794
+ const valuePercentage = (this.#value - this.min) / (this.max - this.min) * 100;
10795
+ this.style.setProperty("--value-percentage", `${valuePercentage}%`);
10796
+ this._internals.setFormValue(this.value);
10797
+ this._internals.ariaValueNow = String(this.#value);
10725
10798
  }
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
10799
  this.requestUpdate();
10800
+ return true;
10801
+ }
10802
+ /** The candidate's input: shows it and publishes it. */
10803
+ #commit(newValue) {
10804
+ if (this.#show(newValue)) {
10805
+ this.saveResponse(this.response);
10806
+ }
10731
10807
  }
10732
10808
  render() {
10733
10809
  return html30`
@@ -10742,7 +10818,7 @@ var QtiSliderInteraction = class extends Interaction {
10742
10818
 
10743
10819
  <div id="rail" part="rail" @mousedown=${this.#onMouseDown} @touchstart=${this.#onTouchStart}>
10744
10820
  <div id="knob" part="knob">
10745
- <div id="value" part="value">${this.response}</div>
10821
+ ${this.#value === null ? nothing5 : html30`<div id="value" part="value">${this.#value}</div>`}
10746
10822
  </div>
10747
10823
 
10748
10824
  ${this.renderRailSupplement()}
@@ -10780,7 +10856,7 @@ var QtiSliderInteraction = class extends Interaction {
10780
10856
  const diffX = pageX - railRect.left;
10781
10857
  const percentage = Math.min(1, Math.max(0, diffX / railRect.width));
10782
10858
  const steppedValue = this.min + Math.round(percentage * (this.max - this.min) / this.step) * this.step;
10783
- this.#updateValue(steppedValue);
10859
+ this.#commit(steppedValue);
10784
10860
  }
10785
10861
  #onDragEnd() {
10786
10862
  this.dispatchEvent(new Event("change", { bubbles: true }));
@@ -11754,4 +11830,4 @@ export {
11754
11830
  elements31 as elements21,
11755
11831
  qtiInteractionElements
11756
11832
  };
11757
- //# sourceMappingURL=chunk-MSGYZE6L.js.map
11833
+ //# sourceMappingURL=chunk-DAFB2E5H.js.map