@zeyos/zx 5.7.0 → 5.7.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.
package/dist/zx.css CHANGED
@@ -1417,18 +1417,22 @@ svg.zx-icon {
1417
1417
  color: var(--zx-color-text);
1418
1418
  }
1419
1419
  .zx-btn[aria-pressed=true] {
1420
- border-color: var(--zx-color-border-control);
1421
- background: var(--zx-color-bg-current);
1420
+ border-color: var(--zx-color-text-subtle);
1421
+ background: color-mix(in srgb, var(--zx-color-text) 14%, transparent);
1422
1422
  color: var(--zx-color-text);
1423
- }
1424
- .zx-btn[data-kind=ghost][aria-pressed=true] {
1425
- border-color: transparent;
1423
+ box-shadow: none;
1426
1424
  }
1427
1425
  .zx-btn[aria-pressed=true] > .zx-icon {
1428
1426
  color: var(--zx-color-text);
1429
1427
  }
1430
- .zx-btn[aria-pressed=true]:hover:not(:disabled) {
1431
- background: var(--zx-color-bg-current);
1428
+ .zx-btn[aria-pressed=true]:hover:not(:disabled),
1429
+ .zx-btn[aria-pressed=true]:active:not(:disabled),
1430
+ .zx-btn[data-kind=ghost][aria-pressed=true][aria-expanded=true]:not(:disabled) {
1431
+ border-color: var(--zx-color-text-subtle);
1432
+ background: color-mix(in srgb, var(--zx-color-text) 14%, transparent);
1433
+ }
1434
+ .zx-btn[aria-pressed=true]:focus-visible {
1435
+ box-shadow: var(--zx-focus-ring);
1432
1436
  }
1433
1437
  .zx-btn[data-size=sm] {
1434
1438
  min-block-size: calc(var(--zx-control-height) - var(--zx-space-1));
@@ -1467,9 +1471,12 @@ svg.zx-icon {
1467
1471
  border-start-end-radius: 0;
1468
1472
  border-end-end-radius: 0;
1469
1473
  }
1470
- .zx-btn-group > .zx-btn:focus-visible {
1474
+ .zx-btn-group > .zx-btn[aria-pressed=true] {
1471
1475
  z-index: 1;
1472
1476
  }
1477
+ .zx-btn-group > .zx-btn:focus-visible {
1478
+ z-index: 2;
1479
+ }
1473
1480
  @media (prefers-reduced-transparency: reduce) {
1474
1481
  .zx-btn {
1475
1482
  background: var(--zx-color-bg-control);
@@ -7942,7 +7949,7 @@ body:has(.zx-modal:modal) {
7942
7949
  padding: var(--zx-space-1) var(--zx-space-2);
7943
7950
  line-height: 1.35;
7944
7951
  }
7945
- .zx-checklist__item:hover {
7952
+ .zx-checklist:not([aria-disabled=true]) .zx-checklist__item:hover {
7946
7953
  background: var(--zx-color-bg-hover);
7947
7954
  }
7948
7955
  .zx-checklist__item:has(input:checked) {
@@ -7964,6 +7971,12 @@ body:has(.zx-modal:modal) {
7964
7971
  .zx-checklist[data-state=loading] .zx-checklist__list {
7965
7972
  color: var(--zx-color-text-muted);
7966
7973
  }
7974
+ .zx-checklist[aria-disabled=true] {
7975
+ opacity: var(--zx-control-disabled-opacity);
7976
+ }
7977
+ .zx-checklist[aria-disabled=true] .zx-checklist__item {
7978
+ cursor: default;
7979
+ }
7967
7980
 
7968
7981
  /* src/components/tag-picker/tag-picker.css */
7969
7982
  .zx-tag-picker {
package/dist/zx.esm.js CHANGED
@@ -388,10 +388,32 @@ function snapshotTarget(element) {
388
388
  }
389
389
  function restoreTarget(element, snapshot10) {
390
390
  if (!snapshot10) return;
391
- for (const attribute of Array.from(element.attributes)) element.removeAttribute(attribute.name);
392
- for (const [name2, value] of snapshot10.attributes) element.setAttribute(name2, value);
391
+ const styled = (
392
+ /** @type {Element & ElementCSSInlineStyle} */
393
+ element
394
+ );
395
+ const cssom = typeof styled.style?.cssText === "string";
396
+ const saved = new Map(snapshot10.attributes);
397
+ const intact = snapshot10.attributes.every(([name2]) => element.hasAttribute(name2));
398
+ for (const attribute of Array.from(element.attributes)) {
399
+ if (!intact || !saved.has(attribute.name)) {
400
+ if (attribute.name === "style" && cssom) restoreInlineStyle(styled, null);
401
+ else element.removeAttribute(attribute.name);
402
+ }
403
+ }
404
+ for (const [name2, value] of snapshot10.attributes) {
405
+ if (name2 === "style" && cssom) restoreInlineStyle(styled, value);
406
+ else if (element.getAttribute(name2) !== value) element.setAttribute(name2, value);
407
+ }
393
408
  element.replaceChildren(...snapshot10.children);
394
409
  }
410
+ function restoreInlineStyle(element, value) {
411
+ const current = element.getAttribute("style");
412
+ if (current === value || !value && current === null) return;
413
+ element.style.cssText = value ?? "";
414
+ element.getAttribute("style");
415
+ if (!value) element.removeAttribute("style");
416
+ }
395
417
  function htmlEscape(str) {
396
418
  return String(str).replace(/[&<>"']/g, (character) => ({
397
419
  "&": "&amp;",
@@ -2470,6 +2492,8 @@ var Checklist = class extends Component {
2470
2492
  search: true,
2471
2493
  height: 280,
2472
2494
  defaultChecked: false,
2495
+ label: null,
2496
+ disabled: false,
2473
2497
  hideLabel: false,
2474
2498
  load: null
2475
2499
  };
@@ -2491,12 +2515,14 @@ var Checklist = class extends Component {
2491
2515
  );
2492
2516
  this.el = root;
2493
2517
  if (!this._createdRoot) this._originalChildren = Array.from(root.childNodes);
2494
- for (const name2 of ["role", "aria-label", "aria-labelledby", "data-state"]) {
2518
+ this._disabled = Boolean(this.options.disabled);
2519
+ for (const name2 of ["role", "aria-label", "aria-labelledby", "aria-disabled", "data-state"]) {
2495
2520
  this._originalAttributes.set(name2, root.getAttribute(name2));
2496
2521
  }
2497
- const labelText = this._message("checklist.label", "Checklist");
2522
+ const labelText = this._labelText(this.options.label);
2498
2523
  const labelId = uid("zx-checklist-label");
2499
2524
  const title = this.options.hideLabel ? null : h("div", {
2525
+ ref: "label",
2500
2526
  class: "zx-checklist__label",
2501
2527
  id: labelId
2502
2528
  }, labelText);
@@ -2507,7 +2533,8 @@ var Checklist = class extends Component {
2507
2533
  autocomplete: "off",
2508
2534
  placeholder: this._message("checklist.search", "Search"),
2509
2535
  ariaLabel: this._message("checklist.search", "Search checklist"),
2510
- hidden: !this.options.search
2536
+ hidden: !this.options.search,
2537
+ disabled: this._disabled
2511
2538
  });
2512
2539
  const list = h("div", {
2513
2540
  ref: "list",
@@ -2536,6 +2563,7 @@ var Checklist = class extends Component {
2536
2563
  this.emit("change", { values: this.getValues() });
2537
2564
  });
2538
2565
  this._replaceItems(this.options.items);
2566
+ this._syncDisabled();
2539
2567
  if (typeof this.options.load === "function") {
2540
2568
  queueMicrotask(() => {
2541
2569
  if (this._active) void this.reload().catch(() => {
@@ -2553,6 +2581,33 @@ var Checklist = class extends Component {
2553
2581
  this._replaceItems(items);
2554
2582
  return this;
2555
2583
  }
2584
+ /**
2585
+ * Replaces the heading text, which is also the group's accessible name.
2586
+ * @param {string|null} label New label; null restores the `checklist.label` message.
2587
+ * @returns {this}
2588
+ */
2589
+ setLabel(label) {
2590
+ const text6 = this._labelText(label);
2591
+ if (this.refs.label) this.refs.label.textContent = text6;
2592
+ else this.el.setAttribute("aria-label", text6);
2593
+ return this;
2594
+ }
2595
+ /** Enables the search field and the checkboxes. @returns {this} */
2596
+ enable() {
2597
+ this._disabled = false;
2598
+ this._syncDisabled();
2599
+ return this;
2600
+ }
2601
+ /** Disables the search field and the checkboxes; values can still be set programmatically. @returns {this} */
2602
+ disable() {
2603
+ this._disabled = true;
2604
+ this._syncDisabled();
2605
+ return this;
2606
+ }
2607
+ /** Whether the checklist is disabled. @returns {boolean} */
2608
+ isDisabled() {
2609
+ return this._disabled;
2610
+ }
2556
2611
  /** Returns checked IDs in item order. @returns {unknown[]} */
2557
2612
  getValues() {
2558
2613
  return this._items.map((item) => this._itemValue(item)).filter((value) => this._checked.has(value));
@@ -2651,6 +2706,7 @@ var Checklist = class extends Component {
2651
2706
  type: "checkbox",
2652
2707
  id: checkboxId,
2653
2708
  checked: this._checked.has(this._itemValue(item)),
2709
+ disabled: this._disabled,
2654
2710
  dataset: { index }
2655
2711
  });
2656
2712
  return h("label", {
@@ -2666,6 +2722,19 @@ var Checklist = class extends Component {
2666
2722
  }
2667
2723
  this.refs.list.replaceChildren(...rows);
2668
2724
  }
2725
+ /** @returns {void} */
2726
+ _syncDisabled() {
2727
+ if (this._disabled) this.el.setAttribute("aria-disabled", "true");
2728
+ else this.el.removeAttribute("aria-disabled");
2729
+ this.refs.search.disabled = this._disabled;
2730
+ for (const input of this.refs.list.querySelectorAll('input[type="checkbox"]')) {
2731
+ input.disabled = this._disabled;
2732
+ }
2733
+ }
2734
+ /** @param {string|null|undefined} label @returns {string} */
2735
+ _labelText(label) {
2736
+ return label == null || label === "" ? this._message("checklist.label", "Checklist") : String(label);
2737
+ }
2669
2738
  /** @param {Set<unknown>} next @returns {void} */
2670
2739
  _replaceChecked(next) {
2671
2740
  if (setsEqual(this._checked, next)) return;
@@ -2708,19 +2777,11 @@ function setsEqual(left, right) {
2708
2777
  function registerChecklistFieldAdapter() {
2709
2778
  Field.register("checklist", (field, options) => {
2710
2779
  const checklist = field.own(new Checklist(null, { hideLabel: true, ...options.props ?? {} }));
2711
- let disabled = false;
2712
2780
  let setting = false;
2713
- const syncDisabled = () => {
2714
- checklist.el.setAttribute("aria-disabled", String(disabled));
2715
- for (const control of checklist.el.querySelectorAll("input, button, select, textarea")) {
2716
- control.disabled = disabled;
2717
- }
2718
- };
2719
2781
  field.listen(checklist.el, "change", (event) => event.stopImmediatePropagation());
2720
2782
  checklist.on("change", (event) => {
2721
2783
  if (!setting) field.emit("change", { value: event.detail.values });
2722
2784
  });
2723
- checklist.on("loaded", syncDisabled);
2724
2785
  return {
2725
2786
  el: checklist.el,
2726
2787
  get: () => checklist.getValues(),
@@ -2731,15 +2792,14 @@ function registerChecklistFieldAdapter() {
2731
2792
  } finally {
2732
2793
  setting = false;
2733
2794
  }
2734
- syncDisabled();
2735
2795
  },
2736
2796
  focus: () => {
2737
2797
  const search = checklist.el.querySelector(".zx-checklist__search:not([hidden]):not([disabled])");
2738
2798
  (search ?? checklist.el.querySelector('input[type="checkbox"]:not([disabled])'))?.focus();
2739
2799
  },
2740
2800
  setDisabled: (value) => {
2741
- disabled = Boolean(value);
2742
- syncDisabled();
2801
+ if (value) checklist.disable();
2802
+ else checklist.enable();
2743
2803
  }
2744
2804
  };
2745
2805
  });
@@ -3423,6 +3483,12 @@ var icons = Object.freeze({
3423
3483
  success: outline("M2 12a10 10 0 1 0 20 0a10 10 0 1 0-20 0zM16 9l-5.5 5.5L8 12"),
3424
3484
  // circle-check
3425
3485
  upload: outline("M12 3v12M17 8l-5-5-5 5M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"),
3486
+ download: outline("M12 15V3M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4M7 10l5 5 5-5"),
3487
+ "box-archive": outline("M3 3h18a1 1 0 0 1 1 1v3a1 1 0 0 1-1 1h-18a1 1 0 0 1-1-1v-3a1 1 0 0 1 1-1zM4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8M10 12h4"),
3488
+ // archive
3489
+ pencil: outline("M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497zM15 5l4 4"),
3490
+ "pen-to-square": outline("M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z"),
3491
+ // square-pen
3426
3492
  drag: outline("M8 12a1 1 0 1 0 2 0a1 1 0 1 0-2 0zM8 5a1 1 0 1 0 2 0a1 1 0 1 0-2 0zM8 19a1 1 0 1 0 2 0a1 1 0 1 0-2 0zM14 12a1 1 0 1 0 2 0a1 1 0 1 0-2 0zM14 5a1 1 0 1 0 2 0a1 1 0 1 0-2 0zM14 19a1 1 0 1 0 2 0a1 1 0 1 0-2 0z"),
3427
3493
  // grip-vertical
3428
3494
  star: outline("M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z"),
@@ -3450,6 +3516,8 @@ var icons = Object.freeze({
3450
3516
  // </lucide-glyphs>
3451
3517
  });
3452
3518
  var aliases = Object.freeze({
3519
+ archive: "box-archive",
3520
+ edit: "pen-to-square",
3453
3521
  settings: "gear",
3454
3522
  clear: "x",
3455
3523
  checked: "check",
@@ -3505,7 +3573,7 @@ function iconNames() {
3505
3573
  function icon(name2, options = {}) {
3506
3574
  const spec = parseIconSpec(name2);
3507
3575
  if (spec.classes) return faIcon(spec.classes, options);
3508
- const resolved = aliases[spec.name] ?? spec.name;
3576
+ const resolved = Object.hasOwn(extraGlyphs, spec.name) ? spec.name : aliases[spec.name] ?? spec.name;
3509
3577
  if (spec.provider === "builtin") return builtinIcon(resolved, options);
3510
3578
  if (spec.provider === "fa") {
3511
3579
  return faIcon(faIconClasses(resolved, {
@@ -4719,9 +4787,9 @@ function position(anchor, floating, options = {}) {
4719
4787
  const rest2 = anchorNames(anchor).filter((name2) => name2 !== anchorName);
4720
4788
  if (rest2.length) anchor.style.setProperty("anchor-name", rest2.join(", "));
4721
4789
  else anchor.style.removeProperty("anchor-name");
4722
- if (anchorStyle === null && anchor.getAttribute("style") === "") anchor.removeAttribute("style");
4790
+ if (!anchorStyle && anchor.getAttribute("style") === "") anchor.removeAttribute("style");
4723
4791
  }
4724
- restoreAttribute(floating, "style", floatingStyle);
4792
+ restoreInlineStyle(floating, floatingStyle);
4725
4793
  restoreAttribute(floating, "popover", popover);
4726
4794
  }
4727
4795
  };
@@ -7441,6 +7509,7 @@ var NumberField = class extends Component {
7441
7509
  step: 1,
7442
7510
  largeStep: 10,
7443
7511
  precision: null,
7512
+ snap: true,
7444
7513
  wrap: false,
7445
7514
  placeholder: "",
7446
7515
  label: null,
@@ -7467,7 +7536,10 @@ var NumberField = class extends Component {
7467
7536
  this.el = root;
7468
7537
  const step2 = normalizeStep2(this.options.step);
7469
7538
  this._step = step2;
7470
- this._precision = this.options.precision === null ? decimalsOf(step2) : Math.max(0, Math.trunc(Number(this.options.precision) || 0));
7539
+ this._snap = this.options.snap !== false;
7540
+ const explicit = this.options.precision !== null && this.options.precision !== void 0;
7541
+ this._precision = explicit ? Math.max(0, Math.trunc(Number(this.options.precision) || 0)) : decimalsOf(step2);
7542
+ this._fixedPrecision = this._snap || explicit;
7471
7543
  const down = this._stepButton("down", "minus");
7472
7544
  const up = this._stepButton("up", "plus");
7473
7545
  const input = h("input", {
@@ -7475,7 +7547,7 @@ var NumberField = class extends Component {
7475
7547
  class: "zx-number-field__input",
7476
7548
  type: "text",
7477
7549
  role: "spinbutton",
7478
- inputMode: this._precision > 0 ? "decimal" : "numeric",
7550
+ inputMode: this._precision > 0 || !this._fixedPrecision ? "decimal" : "numeric",
7479
7551
  autocomplete: "off",
7480
7552
  spellcheck: false,
7481
7553
  placeholder: String(this.options.placeholder ?? ""),
@@ -7536,7 +7608,8 @@ var NumberField = class extends Component {
7536
7608
  return this._value;
7537
7609
  }
7538
7610
  /**
7539
- * Sets the value, snapping it to `step` and clamping it into `[min, max]`.
7611
+ * Sets the value, clamping it into `[min, max]` and — unless `snap` is off — moving it onto the
7612
+ * `step` grid.
7540
7613
  * @param {number|string|null} next Next value; empty strings and null clear the field.
7541
7614
  * @param {{silent?: boolean}} [options={}] Set `silent` to suppress `change`.
7542
7615
  * @returns {this}
@@ -7653,6 +7726,15 @@ var NumberField = class extends Component {
7653
7726
  _coerce(raw2) {
7654
7727
  const parsed = parseNumber(raw2, this.options.group ? this._separators() : null);
7655
7728
  if (parsed === null) return null;
7729
+ if (!this._snap) {
7730
+ if (this._decimalsFor(parsed) > ROUNDABLE_DECIMALS) return clampNumber(parsed, this._rangeMin, this._rangeMax);
7731
+ return snapNumber(parsed, {
7732
+ min: this._rangeMin,
7733
+ max: this._rangeMax,
7734
+ step: 0,
7735
+ precision: this._decimalsFor(parsed)
7736
+ });
7737
+ }
7656
7738
  return snapNumber(parsed, {
7657
7739
  min: this._rangeMin,
7658
7740
  max: this._rangeMax,
@@ -7673,7 +7755,8 @@ var NumberField = class extends Component {
7673
7755
  const current = typed ?? this._value;
7674
7756
  const base = current === null ? min ?? 0 : current;
7675
7757
  const start = current === null && count2 > 0 && min !== null ? min - this._step * count2 : base;
7676
- let next = round(start + this._step * count2, this._precision);
7758
+ const decimals = this._decimalsFor(start);
7759
+ let next = decimals > ROUNDABLE_DECIMALS ? start + this._step * count2 : round(start + this._step * count2, decimals);
7677
7760
  if (this.options.wrap && min !== null && max !== null) {
7678
7761
  if (next > max) next = min;
7679
7762
  else if (next < min) next = max;
@@ -7774,13 +7857,24 @@ var NumberField = class extends Component {
7774
7857
  * @returns {string}
7775
7858
  */
7776
7859
  _format(value, editing) {
7777
- if (!this.options.group) return value.toFixed(this._precision);
7860
+ const decimals = this._decimalsFor(value);
7861
+ if (!this.options.group) return value.toFixed(decimals);
7778
7862
  return new Intl.NumberFormat(formattingLocale(this.options.locale), {
7779
- minimumFractionDigits: this._precision,
7780
- maximumFractionDigits: this._precision,
7863
+ minimumFractionDigits: decimals,
7864
+ maximumFractionDigits: decimals,
7781
7865
  useGrouping: !editing
7782
7866
  }).format(value);
7783
7867
  }
7868
+ /**
7869
+ * Decimal places a value is held and shown at: the field's precision, widened to the value's
7870
+ * own decimals when nothing fixed the precision (`snap: false` without `precision`).
7871
+ * @param {number} value Value in question.
7872
+ * @returns {number}
7873
+ */
7874
+ _decimalsFor(value) {
7875
+ if (this._fixedPrecision) return this._precision;
7876
+ return Math.min(MAX_DECIMALS, Math.max(this._precision, decimalsOf(value)));
7877
+ }
7784
7878
  /**
7785
7879
  * @param {string} key Message key.
7786
7880
  * @param {string} fallback Text used when the host has no translation.
@@ -7854,12 +7948,17 @@ function normalizeStep2(step2) {
7854
7948
  const value = Number(step2);
7855
7949
  return Number.isFinite(value) && value > 0 ? value : 1;
7856
7950
  }
7857
- function decimalsOf(step2) {
7858
- const text6 = String(step2);
7859
- const exponent = text6.match(/e-(\d+)/i);
7860
- if (exponent) return Number(exponent[1]);
7861
- const fraction = text6.split(".")[1];
7862
- return fraction ? fraction.length : 0;
7951
+ var MAX_DECIMALS = 100;
7952
+ var ROUNDABLE_DECIMALS = 15;
7953
+ function clampNumber(value, min, max) {
7954
+ if (min !== null && value < min) return min;
7955
+ if (max !== null && value > max) return max;
7956
+ return value;
7957
+ }
7958
+ function decimalsOf(value) {
7959
+ const [mantissa, exponent = "0"] = String(value).toLowerCase().split("e");
7960
+ const fraction = mantissa.split(".")[1]?.length ?? 0;
7961
+ return Math.max(0, fraction - Number(exponent));
7863
7962
  }
7864
7963
  function round(value, precision) {
7865
7964
  if (!Number.isFinite(value)) return value;
@@ -13267,8 +13366,21 @@ var Modal = class extends Component {
13267
13366
  super(null, options);
13268
13367
  this.#setWidth(this.options.width);
13269
13368
  replaceContent(this.refs.content, this.options.content);
13369
+ if (typeof window !== "undefined") this.listen(window, "keydown", (event) => {
13370
+ const key = (
13371
+ /** @type {KeyboardEvent} */
13372
+ event
13373
+ );
13374
+ if (key.key !== "Escape" || key.defaultPrevented || key.isComposing) return;
13375
+ if (!this.isOpen() || !this.el.matches(":modal")) return;
13376
+ const modals = document.querySelectorAll("dialog:modal");
13377
+ if (modals[modals.length - 1] !== this.el) return;
13378
+ if (this.options.closable) this._requestDismiss("escape");
13379
+ else this.emit("cancel", { reason: "escape" });
13380
+ key.preventDefault();
13381
+ });
13270
13382
  this.listen(this.el, "cancel", (event) => {
13271
- const cancelEvent = this.emit("cancel");
13383
+ const cancelEvent = this.emit("cancel", { reason: "escape" });
13272
13384
  if (!this.options.closable || cancelEvent.defaultPrevented) event.preventDefault();
13273
13385
  });
13274
13386
  this.listen(this.el, "close", () => {
@@ -13276,7 +13388,7 @@ var Modal = class extends Component {
13276
13388
  });
13277
13389
  this.listen(this.el, "click", (event) => {
13278
13390
  if (!this.options.lightDismiss || event.target !== this.el || !isBackdropClick(this.el, event)) return;
13279
- this.close();
13391
+ this._requestDismiss("backdrop");
13280
13392
  });
13281
13393
  this.on("close", () => this.#restoreFocus());
13282
13394
  }
@@ -13344,8 +13456,9 @@ var Modal = class extends Component {
13344
13456
  * Describes the current presentation for the overlay stack, or returns null to stay off it.
13345
13457
  *
13346
13458
  * The kind is read from the platform like `aria-modal` is: a `showModal()` dialog is `modal`,
13347
- * and its Escape and backdrop stay the browser's; anything else is `non-modal`, and a subclass
13348
- * presenting that way adds the Escape and outside-press handling it wants.
13459
+ * and the stack leaves its Escape alone (this class answers it, see the constructor); anything
13460
+ * else is `non-modal`, and a subclass presenting that way adds the Escape and outside-press
13461
+ * handling it wants.
13349
13462
  * @returns {import('../../core/overlay-stack.js').OverlayEntryOptions|null}
13350
13463
  * @protected
13351
13464
  */
@@ -13357,6 +13470,21 @@ var Modal = class extends Component {
13357
13470
  anchor: this.#opener
13358
13471
  };
13359
13472
  }
13473
+ /**
13474
+ * Asks to close on the reader's behalf: emits a preventable `cancel` naming what they did, and
13475
+ * closes unless a listener prevented it. Every dismissal gesture goes through here; `close()`
13476
+ * itself stays unconditional, for the application's own decisions.
13477
+ * @param {ModalDismissReason} reason What the reader did.
13478
+ * @returns {boolean} Whether the overlay is closing.
13479
+ * @fires Modal#cancel
13480
+ * @protected
13481
+ */
13482
+ _requestDismiss(reason) {
13483
+ if (!this.isOpen()) return false;
13484
+ if (this.emit("cancel", { reason }).defaultPrevented) return false;
13485
+ this.close();
13486
+ return true;
13487
+ }
13360
13488
  /**
13361
13489
  * Re-registers the current presentation on the overlay stack: called after every presentation,
13362
13490
  * including a subclass's change of address that bypasses `open()`.
@@ -13852,7 +13980,7 @@ var Dialog = class _Dialog extends Modal {
13852
13980
  this.#baseButtons = normalizeDialogButtons(this.options.buttons);
13853
13981
  this.#renderButtons(this.#baseButtons);
13854
13982
  this.refs.close.hidden = !this.options.closable;
13855
- this.listen(this.refs.close, "click", () => this.close());
13983
+ this.listen(this.refs.close, "click", () => this._requestDismiss("close-button"));
13856
13984
  this.listen(this.refs.footer, "click", (event) => {
13857
13985
  const button2 = event.target.closest?.("[data-dialog-button]");
13858
13986
  if (!button2 || !this.refs.footer.contains(button2)) return;
@@ -14228,8 +14356,7 @@ var Dialog = class _Dialog extends Modal {
14228
14356
  if (action === "close") {
14229
14357
  this.close();
14230
14358
  } else if (action === "cancel") {
14231
- const event = this.emit("cancel");
14232
- if (!event.defaultPrevented) this.close();
14359
+ this._requestDismiss("button");
14233
14360
  } else if (typeof action === "function") {
14234
14361
  action(this);
14235
14362
  }
@@ -26189,7 +26316,8 @@ var Sheet = class extends Dialog {
26189
26316
  }
26190
26317
  if (this.options.closable && next < min / 2) {
26191
26318
  this._applySize(this.#dragStart);
26192
- this.close();
26319
+ this.#syncHandleAria();
26320
+ this._requestDismiss("drag");
26193
26321
  return;
26194
26322
  }
26195
26323
  const detents = this.#detents(total);
@@ -26336,15 +26464,19 @@ var Sheet = class extends Dialog {
26336
26464
  ...entry,
26337
26465
  // An Escape pressed outside the sheet and everything it opened is not addressed to it.
26338
26466
  onEscape: (event) => {
26339
- if (!this.options.closable || !this._overlayContains(
26467
+ if (!this._overlayContains(
26340
26468
  /** @type {Node|null} */
26341
26469
  event.target
26342
26470
  )) return false;
26343
- if (!this.emit("cancel").defaultPrevented) this.close();
26471
+ if (!this.options.closable) {
26472
+ this.emit("cancel", { reason: "escape" });
26473
+ return false;
26474
+ }
26475
+ this._requestDismiss("escape");
26344
26476
  return void 0;
26345
26477
  },
26346
26478
  onOutsidePointer: this.options.lightDismiss ? () => {
26347
- this.close();
26479
+ this._requestDismiss("outside");
26348
26480
  } : void 0,
26349
26481
  // Hosted inside a modal that has now closed, the sheet would stay open but never be seen.
26350
26482
  onParentClose: () => {