@tangible/ui 0.2.53 → 0.2.54

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.
@@ -2,6 +2,7 @@
2
2
 
3
3
  /* @tui-tokens
4
4
  --tui-checkbox-accent
5
+ --tui-checkbox-icon
5
6
  --tui-checkbox-border
6
7
  --tui-checkbox-border-hover
7
8
  --tui-checkbox-border-invalid
@@ -13,9 +14,10 @@
13
14
  --tui-checkbox-fg-disabled
14
15
  */
15
16
 
16
- // Structural SCSS constants (compile away, not overridable)
17
- $_checkmark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
18
- $_indeterminate: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3.5' stroke-linecap='round'%3E%3Cpath d='M6 12h12'/%3E%3C/svg%3E");
17
+ // Structural SCSS constants (compile away, not overridable). Used as masks:
18
+ // only their shape counts, the colour comes from --_icon.
19
+ $_checkmark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
20
+ $_indeterminate: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3.5' stroke-linecap='round'%3E%3Cpath d='M6 12h12'/%3E%3C/svg%3E");
19
21
 
20
22
  @mixin styles() {
21
23
  // ==========================================================================
@@ -31,6 +33,12 @@ $_indeterminate: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/sv
31
33
  // Component API tokens (never defined here, only read via fallback):
32
34
  // --tui-checkbox-accent Accent color for checked/indeterminate
33
35
  // → --tui-input-accent → --tui-theme-primary-base
36
+ // --tui-checkbox-icon Tick and dash colour on the accent fill
37
+ // → --tui-theme-primary-on-base
38
+ // Doesn't follow an accent override: set
39
+ // it with --tui-checkbox-accent or
40
+ // --tui-input-accent when the fill isn't
41
+ // primary (as Chip's -icon, Button's -fg)
34
42
  // --tui-checkbox-border Border color (unchecked)
35
43
  // --tui-checkbox-border-hover Hover border (opt-in; default: no change)
36
44
  // → --tui-input-border → --tui-color-border-control
@@ -46,10 +54,11 @@ $_indeterminate: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/sv
46
54
  // --tui-checkbox-fg-disabled Label color when disabled (default fg-muted);
47
55
  // wins over -label-color
48
56
  //
49
- // Note: Checkmark/indeterminate icons are white (#fff) SVGs embedded as
50
- // data URIs. CSS custom properties cannot be referenced inside data URIs,
51
- // so the icon colour is fixed. Accent overrides must contrast against white
52
- // at 3:1 or better to keep the icon legible.
57
+ // The tick and dash are a ::before painted in --_icon through an SVG mask,
58
+ // so they follow the fill's on-base colour: white on TUI's default fills,
59
+ // dark on a lifted dark-mode fill. A baked white SVG can't read a custom
60
+ // property, and vanished on light fills. Chromium, WebKit and Firefox
61
+ // (162) all draw pseudo-elements on an appearance: none checkbox.
53
62
  //
54
63
  // ==========================================================================
55
64
 
@@ -69,6 +78,7 @@ $_indeterminate: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/sv
69
78
  --_border: var(--_border-rest);
70
79
  --_radius: var(--#{sys.$prefix}checkbox-radius, var(--#{sys.$prefix}radius-sm));
71
80
  --_bg: var(--#{sys.$prefix}checkbox-bg, var(--#{sys.$prefix}color-bg));
81
+ --_icon: var(--#{sys.$prefix}checkbox-icon, var(--#{sys.$prefix}theme-primary-on-base));
72
82
 
73
83
  // Reset native appearance
74
84
  appearance: none;
@@ -81,6 +91,7 @@ $_indeterminate: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/sv
81
91
 
82
92
  // Box
83
93
  display: inline-block;
94
+ position: relative; // contains the ::before mark
84
95
  width: 1em;
85
96
  min-width: 1em;
86
97
  height: 1em;
@@ -91,10 +102,25 @@ $_indeterminate: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/sv
91
102
  border: var(--#{sys.$prefix}border-width) solid var(--_border);
92
103
  border-radius: var(--_radius);
93
104
  background-color: var(--_bg);
94
- background-size: 75%;
95
- background-position: center;
96
- background-repeat: no-repeat;
97
105
  cursor: pointer;
106
+ // The fill and the mark are both backgrounds, which print drops by
107
+ // default: checked would print as an empty box.
108
+ print-color-adjust: exact;
109
+
110
+ // The mark: hidden until checked or indeterminate sets its shape.
111
+ &::before {
112
+ content: "";
113
+ position: absolute;
114
+ inset: 0;
115
+ margin: auto;
116
+ width: 75%;
117
+ height: 75%;
118
+ background-color: var(--_icon);
119
+ print-color-adjust: exact;
120
+ -webkit-mask: var(--_icon-shape, none) center / contain no-repeat;
121
+ mask: var(--_icon-shape, none) center / contain no-repeat;
122
+ visibility: hidden;
123
+ }
98
124
 
99
125
  // Transitions
100
126
  transition-duration: var(--#{sys.$prefix}motion-duration);
@@ -105,7 +131,11 @@ $_indeterminate: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/sv
105
131
  &:checked {
106
132
  background-color: var(--_accent);
107
133
  border-color: var(--_accent);
108
- background-image: $_checkmark;
134
+
135
+ &::before {
136
+ --_icon-shape: #{$_checkmark};
137
+ visibility: visible;
138
+ }
109
139
  }
110
140
 
111
141
  // Indeterminate — uses :indeterminate pseudo-class which tracks the DOM property.
@@ -115,7 +145,11 @@ $_indeterminate: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/sv
115
145
  &:indeterminate {
116
146
  background-color: var(--_accent);
117
147
  border-color: var(--_accent);
118
- background-image: $_indeterminate;
148
+
149
+ &::before {
150
+ --_icon-shape: #{$_indeterminate};
151
+ visibility: visible;
152
+ }
119
153
  }
120
154
 
121
155
  // Hover: before Invalid so an invalid box keeps its red. Checked and
@@ -193,6 +227,13 @@ $_indeterminate: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/sv
193
227
  ) {
194
228
  // Let the browser render the checkbox natively in WHCM
195
229
  forced-color-adjust: auto;
230
+
231
+ // The forced palette would repaint the mark's background-color to
232
+ // Canvas, the same as the box: draw it in the text colour instead.
233
+ &::before {
234
+ forced-color-adjust: none;
235
+ background-color: CanvasText;
236
+ }
196
237
  }
197
238
 
198
239
  // The fg-muted cue is replaced by the system palette.
package/tui-manifest.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
- "version": "0.2.53",
3
- "generated": "2026-11-26T19:55:17.116Z",
2
+ "version": "0.2.54",
3
+ "generated": "2026-12-02T23:57:41.885Z",
4
4
  "components": {
5
5
  "Accordion": {
6
6
  "props": {
@@ -573,6 +573,7 @@
573
573
  },
574
574
  "cssTokens": [
575
575
  "--tui-checkbox-accent",
576
+ "--tui-checkbox-icon",
576
577
  "--tui-checkbox-border",
577
578
  "--tui-checkbox-border-hover",
578
579
  "--tui-checkbox-border-invalid",
@@ -41,14 +41,21 @@ export function useFocusTrap(containerRef, options) {
41
41
  const first = nodes[0];
42
42
  const last = nodes[nodes.length - 1];
43
43
  const active = document.activeElement;
44
+ // Wrap by position, not identity: focus can sit on something outside the
45
+ // Tab order (an autofocus heading or the container at tabindex="-1", an
46
+ // inactive roving option someone clicked). From before the first stop,
47
+ // Shift+Tab leaves the trap; from after the last, Tab does.
48
+ const inside = !!active && container.contains(active);
49
+ const beforeFirst = active === first || (inside && !!(first.compareDocumentPosition(active) & Node.DOCUMENT_POSITION_PRECEDING));
50
+ const afterLast = active === last || (inside && !!(last.compareDocumentPosition(active) & Node.DOCUMENT_POSITION_FOLLOWING));
44
51
  if (e.shiftKey) {
45
- if (active === first || !container.contains(active)) {
52
+ if (beforeFirst || !inside) {
46
53
  e.preventDefault();
47
54
  last.focus();
48
55
  }
49
56
  }
50
57
  else {
51
- if (active === last || !container.contains(active)) {
58
+ if (afterLast || !inside) {
52
59
  e.preventDefault();
53
60
  first.focus();
54
61
  }
@@ -27,7 +27,7 @@ export declare function findFocusTarget(container: HTMLElement, selector: string
27
27
  target: HTMLElement | null;
28
28
  problem?: string;
29
29
  };
30
- /** The focusable elements in `container` that can actually take focus, in DOM order. */
30
+ /** The elements in `container` that are in the Tab sequence and can take focus, in DOM order. */
31
31
  export declare function getTabbable(container: HTMLElement): HTMLElement[];
32
32
  /**
33
33
  * Finds the first focusable element within a container.
package/utils/tabbable.js CHANGED
@@ -5,7 +5,6 @@
5
5
  * Used by focus trap and initial focus logic.
6
6
  */
7
7
  export const FOCUSABLE_SELECTOR = [
8
- '[data-autofocus]',
9
8
  'a[href]',
10
9
  'area[href]',
11
10
  'button:not([disabled])',
@@ -16,6 +15,8 @@ export const FOCUSABLE_SELECTOR = [
16
15
  'audio[controls]',
17
16
  'video[controls]',
18
17
  '[contenteditable]:not([contenteditable="false"])',
18
+ // Only -1 is excluded here; getTabbable drops every negative value
19
+ // (isOutOfTabOrder), including -1 on a natively focusable element.
19
20
  '[tabindex]:not([tabindex="-1"])',
20
21
  ].join(',');
21
22
  /**
@@ -72,9 +73,21 @@ export function findFocusTarget(container, selector) {
72
73
  }
73
74
  return { target: match };
74
75
  }
75
- /** The focusable elements in `container` that can actually take focus, in DOM order. */
76
+ /**
77
+ * Whether `el` opted out of the Tab sequence with a negative `tabindex`: a
78
+ * roving group's inactive members (SegmentedControl, Tabs, Toolbar). The
79
+ * selector still matches them (`button:not([disabled])`), and as a trap's
80
+ * first or last edge they let Tab walk out of the dialog. Read from the
81
+ * attribute, since jsdom's `tabIndex` default differs from browsers'.
82
+ */
83
+ function isOutOfTabOrder(el) {
84
+ // An unparseable value (NaN) counts as in the order, as browsers ignore it.
85
+ const attr = el.getAttribute('tabindex');
86
+ return attr !== null && Number.parseInt(attr, 10) < 0;
87
+ }
88
+ /** The elements in `container` that are in the Tab sequence and can take focus, in DOM order. */
76
89
  export function getTabbable(container) {
77
- return Array.from(container.querySelectorAll(FOCUSABLE_SELECTOR)).filter((n) => isTabbable(n, container));
90
+ return Array.from(container.querySelectorAll(FOCUSABLE_SELECTOR)).filter((n) => !isOutOfTabOrder(n) && isTabbable(n, container));
78
91
  }
79
92
  /**
80
93
  * Finds the first focusable element within a container.
@@ -94,10 +107,12 @@ export function getInitialFocus(container, preferredSelector, { lastResort } = {
94
107
  return target;
95
108
  }
96
109
  // [data-autofocus] first, then DOM order, skipping anything that can't take focus.
97
- const tabbable = getTabbable(container);
98
- const autofocus = tabbable.find((n) => n.matches('[data-autofocus]'));
110
+ // A [data-autofocus] target may sit outside the Tab order (a heading with
111
+ // tabindex="-1"), so it's looked up on its own, not among the tabbables.
112
+ const autofocus = Array.from(container.querySelectorAll('[data-autofocus]')).find((n) => isFocusTarget(n, container));
99
113
  if (autofocus)
100
114
  return autofocus;
115
+ const tabbable = getTabbable(container);
101
116
  const first = lastResort ? tabbable.find((n) => !n.matches(lastResort)) : tabbable[0];
102
117
  return first ?? tabbable[0] ?? container;
103
118
  }
package/vanilla/modal.js CHANGED
@@ -53,7 +53,7 @@
53
53
  * Anything that portals to <body> (a React Select, a third-party datepicker)
54
54
  * renders under the top layer and is inert while a modal is open.
55
55
  */
56
- import { getTabbable, isTabbable } from '../utils/tabbable.js';
56
+ import { getTabbable, isFocusTarget } from '../utils/tabbable.js';
57
57
  import { lockScroll, unlockScroll } from '../utils/scroll-lock.js';
58
58
  const OPEN_ATTR = 'data-tui-modal-open';
59
59
  const CLOSE_ATTR = 'data-tui-modal-close';
@@ -186,7 +186,7 @@ function waitForExit(dialog) {
186
186
  }
187
187
  function initialFocus(box) {
188
188
  const preferred = box.querySelector('[autofocus], [data-autofocus]');
189
- if (preferred && isTabbable(preferred, box))
189
+ if (preferred && isFocusTarget(preferred, box))
190
190
  return preferred;
191
191
  const controls = getTabbable(box).filter((el) => !el.matches(EMBED_SELECTOR));
192
192
  return controls.find((el) => !el.matches(CLOSE_BUTTON_SELECTOR)) ?? controls[0] ?? box;
@@ -1 +1 @@
1
- (()=>{var Y=Object.defineProperty;var J=(t,e)=>{for(var n in e)Y(t,n,{get:e[n],enumerable:!0})};var D={};J(D,{MODAL_CLOSE_EVENT:()=>j,MODAL_OPEN_EVENT:()=>y,close:()=>p,init:()=>S,open:()=>K});var Q=["[data-autofocus]","a[href]","area[href]","button:not([disabled])",'input:not([disabled]):not([type="hidden"])',"select:not([disabled])","textarea:not([disabled])","iframe","audio[controls]","video[controls]",'[contenteditable]:not([contenteditable="false"])','[tabindex]:not([tabindex="-1"])'].join(",");function h(t,e){if(t.matches(":disabled")||t.closest("[inert]"))return!1;if(typeof t.checkVisibility=="function")return t.checkVisibility({visibilityProperty:!0});for(let n=t;n&&n!==e;n=n.parentElement){if(n.hidden)return!1;let o=getComputedStyle(n);if(o.display==="none"||n===t&&o.visibility==="hidden")return!1}return!0}function x(t){return Array.from(t.querySelectorAll(Q)).filter(e=>h(e,t))}var k="tui-modal-open",g="tuiScrollLock",C="--tui-scroll-lock-pad",w="--tui-scroll-lock-gutter",Z=["left","right"];function L(){return Number(document.body.dataset[g]??0)||0}function P(t){t.style.removeProperty(C);for(let e of Z)t.classList.remove(`tui-scroll-lock-pad-${e}`),t.style.removeProperty(`${w}-${e}`)}function _(){let t=document.body,e=L()===0;if(t.dataset[g]=String(L()+1),!e)return;P(t);let n=document.documentElement,o=n.clientWidth,r=t.getBoundingClientRect().left;t.classList.add(k);let i=n.clientWidth-o;if(i<=0)return;let l=t.getBoundingClientRect().left<r?"left":"right",a=parseFloat(getComputedStyle(t)[l==="left"?"paddingLeft":"paddingRight"])||0;t.style.setProperty(C,`${a+i}px`),t.style.setProperty(`${w}-${l}`,`${i}px`),t.classList.add(`tui-scroll-lock-pad-${l}`)}function O(){let t=document.body,e=L()-1;if(e>0){t.dataset[g]=String(e);return}delete t.dataset[g],t.classList.remove(k),P(t)}var b="data-tui-modal-open",c="data-tui-modal-close",tt="data-tui-modal-backdrop",M="data-tui-modal-src",R="data-tui-modal-restore-focus",et=".tui-modal__close",nt=":scope > .tui-modal__dialog",ot="iframe, object, embed, audio, video",it=1e3,y="tui-modal-open",j="tui-modal-close",m=new WeakMap,f=new WeakMap,B=new WeakSet,v=null,E=null,N=0;function s(t){console.warn(`[TUI modal] ${t}`)}function u(t){let e=t.getAttribute("data-state");return e==="open"||e==="closing"}function T(t){return t.querySelector(nt)}function I(t){return t.matches(":disabled")||t.closest('[aria-disabled="true"]')!==null}function z(t){if(typeof t!="string")return t;let e=document.getElementById(t);return e instanceof HTMLDialogElement?e:(s(e?`#${t} is a <${e.tagName.toLowerCase()}>, not a <dialog>. The modal must be a <dialog> element.`:`No element with id "${t}".`),null)}function q(t){return t.split(/\s+/).filter(e=>e&&!document.getElementById(e))}function rt(t){if(B.has(t))return;B.add(t);let e=`<dialog id="${t.id}">`,n=t.getAttribute("aria-labelledby"),o=t.getAttribute("aria-describedby");if(n){let i=q(n);i.length&&s(`${e} has aria-labelledby="${n}", but nothing has the id ${i.map(l=>`"${l}"`).join(", ")}, so the dialog has no name. Give the heading that id.`)}else t.hasAttribute("aria-label")||s(`${e} has no accessible name. Point aria-labelledby at its visible heading (WCAG 4.1.2).`);o&&q(o).length&&s(`${e} has aria-describedby="${o}", but not every id in it exists.`),t.getAttribute("role")==="alertdialog"&&!o&&s(`${e} is role="alertdialog" without aria-describedby. Point it at the message, or screen readers announce the heading and nothing about what is being confirmed.`),T(t)||s(`${e} has no .tui-modal__dialog box as its child. The box is the visible dialog; without it the backdrop can't be told apart and backdrop clicks are ignored.`),t.querySelector(`[${c}], form[method="dialog"]`)||Array.from(document.querySelectorAll(`[${c}]`)).some(i=>i.getAttribute(c)===t.id)||s(`${e} has no close control. Touch screen-reader users have no Escape key; add a button with ${c}.`)}function lt(t){let e=t.getAttribute(tt);return e==="dismiss"?!0:e==="static"?!1:t.getAttribute("role")!=="alertdialog"}function F(t){let e=getComputedStyle(t),n=i=>{let l=parseFloat(i);return Number.isNaN(l)?0:i.trim().endsWith("ms")?l:l*1e3},o=e.transitionDuration.split(","),r=e.transitionDelay.split(",");return Math.max(0,...o.map((i,l)=>n(i)+n(r[l%r.length]??"")))}function st(t){let e=T(t),n=Math.min(it,Math.max(F(t),e?F(e):0));return n>0?new Promise(o=>setTimeout(o,n)):Promise.resolve()}function at(t){let e=t.querySelector("[autofocus], [data-autofocus]");if(e&&h(e,t))return e;let n=x(t).filter(o=>!o.matches(ot));return n.find(o=>!o.matches(et))??n[0]??t}function K(t,e){let n=z(t);if(!n)return!1;if(n.getAttribute("data-state")==="closing")return f.delete(n),e&&m.set(n,e),n.setAttribute("data-state","open"),A(n,y,{opener:m.get(n)??null}),!0;if(n.open&&u(n))return!0;u(n)&&H(n),n.open&&(s(`<dialog id="${n.id}"> was already open, not as a modal. Drop the open attribute from the markup.`),n.close()),rt(n);try{n.showModal()}catch(a){return s(`<dialog id="${n.id}"> couldn't open: ${a.message}`),!1}_();let o=document.activeElement,r=e??(o instanceof HTMLElement&&o!==document.body?o:null);m.set(n,r);for(let a of n.querySelectorAll(`[${M}]`))a.hasAttribute("src")||a.setAttribute("src",a.getAttribute(M)??"");let i=T(n)??n,l=at(i);return l===i&&!i.hasAttribute("tabindex")&&(i.tabIndex=-1),l.focus(),n.offsetWidth,n.setAttribute("data-state","open"),A(n,y,{opener:r}),!0}function p(t){let e=z(t);if(!e?.open)return Promise.resolve();if(!u(e))return e.close(),Promise.resolve();let n=f.get(e);if(n)return n;e.setAttribute("data-state","closing");let o=st(e).then(()=>{f.get(e)===o&&(e.close(),H(e))});return f.set(e,o),o}function A(t,e,n){t.dispatchEvent(new CustomEvent(e,{bubbles:!0,detail:n}))}function H(t){if(!u(t))return;t.setAttribute("data-state","closed"),f.delete(t);for(let n of t.querySelectorAll("audio, video"))n.paused||n.pause();for(let n of t.querySelectorAll(`[${M}][src]`)){n.removeAttribute("src");let o=n.parentNode,r=n.nextSibling;n.remove(),o?.insertBefore(n,r)}O();let e=m.get(t)??null;m.delete(t),ct(t,e),A(t,j,{opener:e,returnValue:t.returnValue})}function ct(t,e){let n=t.getAttribute(R),o=[n?document.getElementById(n):null,e,...Array.from(document.querySelectorAll(`[${b}]`)).filter(r=>r.getAttribute(b)===t.id)];for(let r of o)if(!(!r?.isConnected||r===document.body)&&(r.focus(),document.activeElement===r))return;!e&&!n||s(`Focus had nowhere to return when <dialog id="${t.id}"> closed: its trigger is gone or can't take focus, so focus fell to <body> (WCAG 2.4.3). Set ${R}="<id>" on the dialog to name an element that will still be there.`)}function ut(t){return t.matches('a[href], input[type="submit"]')?!0:t instanceof HTMLButtonElement&&t.type==="submit"&&t.form!==null}function W(t){v=t.target,E=null}function U(t){E=t.target}function V(t){let e=v,n=E;v=E=null;let o=t.target;if(!(o instanceof Element))return;let r=o.closest(`[${b}]`);if(r){if(I(r))return;t.preventDefault(),K(r.getAttribute(b)??"",r);return}let i=o.closest(`[${c}]`);if(i){if(I(i))return;let a=i.getAttribute(c)||i.closest("dialog");if(!a){s(`A [${c}] control is outside any <dialog>. Give it the dialog's id as its value.`);return}ut(i)||t.preventDefault(),p(a);return}o instanceof HTMLDialogElement&&u(o)&&e===o&&n===o&&T(o)!==null&&lt(o)&&!dt(o,t)&&p(o)}function dt(t,e){let{clientWidth:n,clientHeight:o}=t;return n>0&&e.offsetX>=n||o>0&&e.offsetY>=o}function G(t){let e=t.target;!(e instanceof HTMLDialogElement)||!u(e)||t.cancelable&&(t.preventDefault(),p(e))}function X(t){let e=t.target;e instanceof HTMLDialogElement&&!e.open&&H(e)}function S(){N++===0&&(document.addEventListener("pointerdown",W,!0),document.addEventListener("pointerup",U,!0),document.addEventListener("click",V),document.addEventListener("cancel",G,!0),document.addEventListener("close",X,!0));let t=!1;return()=>{t||(t=!0,!(--N>0)&&(document.removeEventListener("pointerdown",W,!0),document.removeEventListener("pointerup",U,!0),document.removeEventListener("click",V),document.removeEventListener("cancel",G,!0),document.removeEventListener("close",X,!0)))}}var $=Symbol.for("tangible-ui/vanilla/modal"),d=globalThis;d[$]||(d[$]=D,S());d.TangibleUI=d.TangibleUI||{};d.TangibleUI.modal=d[$];})();
1
+ (()=>{var Q=Object.defineProperty;var Z=(t,e)=>{for(var n in e)Q(t,n,{get:e[n],enumerable:!0})};var S={};Z(S,{MODAL_CLOSE_EVENT:()=>K,MODAL_OPEN_EVENT:()=>M,close:()=>p,init:()=>H,open:()=>J});var $=["a[href]","area[href]","button:not([disabled])",'input:not([disabled]):not([type="hidden"])',"select:not([disabled])","textarea:not([disabled])","iframe","audio[controls]","video[controls]",'[contenteditable]:not([contenteditable="false"])','[tabindex]:not([tabindex="-1"])'].join(",");function x(t,e){if(t.matches(":disabled")||t.closest("[inert]"))return!1;if(typeof t.checkVisibility=="function")return t.checkVisibility({visibilityProperty:!0});for(let n=t;n&&n!==e;n=n.parentElement){if(n.hidden)return!1;let o=getComputedStyle(n);if(o.display==="none"||n===t&&o.visibility==="hidden")return!1}return!0}function k(t,e){return(t.matches($)||t.hasAttribute("tabindex"))&&x(t,e)}function tt(t){let e=t.getAttribute("tabindex");return e!==null&&Number.parseInt(e,10)<0}function C(t){return Array.from(t.querySelectorAll($)).filter(e=>!tt(e)&&x(e,t))}var w="tui-modal-open",g="tuiScrollLock",P="--tui-scroll-lock-pad",O="--tui-scroll-lock-gutter",et=["left","right"];function h(){return Number(document.body.dataset[g]??0)||0}function _(t){t.style.removeProperty(P);for(let e of et)t.classList.remove(`tui-scroll-lock-pad-${e}`),t.style.removeProperty(`${O}-${e}`)}function R(){let t=document.body,e=h()===0;if(t.dataset[g]=String(h()+1),!e)return;_(t);let n=document.documentElement,o=n.clientWidth,i=t.getBoundingClientRect().left;t.classList.add(w);let r=n.clientWidth-o;if(r<=0)return;let l=t.getBoundingClientRect().left<i?"left":"right",a=parseFloat(getComputedStyle(t)[l==="left"?"paddingLeft":"paddingRight"])||0;t.style.setProperty(P,`${a+r}px`),t.style.setProperty(`${O}-${l}`,`${r}px`),t.classList.add(`tui-scroll-lock-pad-${l}`)}function B(){let t=document.body,e=h()-1;if(e>0){t.dataset[g]=String(e);return}delete t.dataset[g],t.classList.remove(w),_(t)}var b="data-tui-modal-open",c="data-tui-modal-close",nt="data-tui-modal-backdrop",L="data-tui-modal-src",N="data-tui-modal-restore-focus",ot=".tui-modal__close",rt=":scope > .tui-modal__dialog",it="iframe, object, embed, audio, video",lt=1e3,M="tui-modal-open",K="tui-modal-close",m=new WeakMap,f=new WeakMap,I=new WeakSet,y=null,E=null,q=0;function s(t){console.warn(`[TUI modal] ${t}`)}function u(t){let e=t.getAttribute("data-state");return e==="open"||e==="closing"}function T(t){return t.querySelector(rt)}function F(t){return t.matches(":disabled")||t.closest('[aria-disabled="true"]')!==null}function Y(t){if(typeof t!="string")return t;let e=document.getElementById(t);return e instanceof HTMLDialogElement?e:(s(e?`#${t} is a <${e.tagName.toLowerCase()}>, not a <dialog>. The modal must be a <dialog> element.`:`No element with id "${t}".`),null)}function W(t){return t.split(/\s+/).filter(e=>e&&!document.getElementById(e))}function st(t){if(I.has(t))return;I.add(t);let e=`<dialog id="${t.id}">`,n=t.getAttribute("aria-labelledby"),o=t.getAttribute("aria-describedby");if(n){let r=W(n);r.length&&s(`${e} has aria-labelledby="${n}", but nothing has the id ${r.map(l=>`"${l}"`).join(", ")}, so the dialog has no name. Give the heading that id.`)}else t.hasAttribute("aria-label")||s(`${e} has no accessible name. Point aria-labelledby at its visible heading (WCAG 4.1.2).`);o&&W(o).length&&s(`${e} has aria-describedby="${o}", but not every id in it exists.`),t.getAttribute("role")==="alertdialog"&&!o&&s(`${e} is role="alertdialog" without aria-describedby. Point it at the message, or screen readers announce the heading and nothing about what is being confirmed.`),T(t)||s(`${e} has no .tui-modal__dialog box as its child. The box is the visible dialog; without it the backdrop can't be told apart and backdrop clicks are ignored.`),t.querySelector(`[${c}], form[method="dialog"]`)||Array.from(document.querySelectorAll(`[${c}]`)).some(r=>r.getAttribute(c)===t.id)||s(`${e} has no close control. Touch screen-reader users have no Escape key; add a button with ${c}.`)}function at(t){let e=t.getAttribute(nt);return e==="dismiss"?!0:e==="static"?!1:t.getAttribute("role")!=="alertdialog"}function U(t){let e=getComputedStyle(t),n=r=>{let l=parseFloat(r);return Number.isNaN(l)?0:r.trim().endsWith("ms")?l:l*1e3},o=e.transitionDuration.split(","),i=e.transitionDelay.split(",");return Math.max(0,...o.map((r,l)=>n(r)+n(i[l%i.length]??"")))}function ct(t){let e=T(t),n=Math.min(lt,Math.max(U(t),e?U(e):0));return n>0?new Promise(o=>setTimeout(o,n)):Promise.resolve()}function ut(t){let e=t.querySelector("[autofocus], [data-autofocus]");if(e&&k(e,t))return e;let n=C(t).filter(o=>!o.matches(it));return n.find(o=>!o.matches(ot))??n[0]??t}function J(t,e){let n=Y(t);if(!n)return!1;if(n.getAttribute("data-state")==="closing")return f.delete(n),e&&m.set(n,e),n.setAttribute("data-state","open"),v(n,M,{opener:m.get(n)??null}),!0;if(n.open&&u(n))return!0;u(n)&&A(n),n.open&&(s(`<dialog id="${n.id}"> was already open, not as a modal. Drop the open attribute from the markup.`),n.close()),st(n);try{n.showModal()}catch(a){return s(`<dialog id="${n.id}"> couldn't open: ${a.message}`),!1}R();let o=document.activeElement,i=e??(o instanceof HTMLElement&&o!==document.body?o:null);m.set(n,i);for(let a of n.querySelectorAll(`[${L}]`))a.hasAttribute("src")||a.setAttribute("src",a.getAttribute(L)??"");let r=T(n)??n,l=ut(r);return l===r&&!r.hasAttribute("tabindex")&&(r.tabIndex=-1),l.focus(),n.offsetWidth,n.setAttribute("data-state","open"),v(n,M,{opener:i}),!0}function p(t){let e=Y(t);if(!e?.open)return Promise.resolve();if(!u(e))return e.close(),Promise.resolve();let n=f.get(e);if(n)return n;e.setAttribute("data-state","closing");let o=ct(e).then(()=>{f.get(e)===o&&(e.close(),A(e))});return f.set(e,o),o}function v(t,e,n){t.dispatchEvent(new CustomEvent(e,{bubbles:!0,detail:n}))}function A(t){if(!u(t))return;t.setAttribute("data-state","closed"),f.delete(t);for(let n of t.querySelectorAll("audio, video"))n.paused||n.pause();for(let n of t.querySelectorAll(`[${L}][src]`)){n.removeAttribute("src");let o=n.parentNode,i=n.nextSibling;n.remove(),o?.insertBefore(n,i)}B();let e=m.get(t)??null;m.delete(t),dt(t,e),v(t,K,{opener:e,returnValue:t.returnValue})}function dt(t,e){let n=t.getAttribute(N),o=[n?document.getElementById(n):null,e,...Array.from(document.querySelectorAll(`[${b}]`)).filter(i=>i.getAttribute(b)===t.id)];for(let i of o)if(!(!i?.isConnected||i===document.body)&&(i.focus(),document.activeElement===i))return;!e&&!n||s(`Focus had nowhere to return when <dialog id="${t.id}"> closed: its trigger is gone or can't take focus, so focus fell to <body> (WCAG 2.4.3). Set ${N}="<id>" on the dialog to name an element that will still be there.`)}function mt(t){return t.matches('a[href], input[type="submit"]')?!0:t instanceof HTMLButtonElement&&t.type==="submit"&&t.form!==null}function V(t){y=t.target,E=null}function G(t){E=t.target}function X(t){let e=y,n=E;y=E=null;let o=t.target;if(!(o instanceof Element))return;let i=o.closest(`[${b}]`);if(i){if(F(i))return;t.preventDefault(),J(i.getAttribute(b)??"",i);return}let r=o.closest(`[${c}]`);if(r){if(F(r))return;let a=r.getAttribute(c)||r.closest("dialog");if(!a){s(`A [${c}] control is outside any <dialog>. Give it the dialog's id as its value.`);return}mt(r)||t.preventDefault(),p(a);return}o instanceof HTMLDialogElement&&u(o)&&e===o&&n===o&&T(o)!==null&&at(o)&&!ft(o,t)&&p(o)}function ft(t,e){let{clientWidth:n,clientHeight:o}=t;return n>0&&e.offsetX>=n||o>0&&e.offsetY>=o}function j(t){let e=t.target;!(e instanceof HTMLDialogElement)||!u(e)||t.cancelable&&(t.preventDefault(),p(e))}function z(t){let e=t.target;e instanceof HTMLDialogElement&&!e.open&&A(e)}function H(){q++===0&&(document.addEventListener("pointerdown",V,!0),document.addEventListener("pointerup",G,!0),document.addEventListener("click",X),document.addEventListener("cancel",j,!0),document.addEventListener("close",z,!0));let t=!1;return()=>{t||(t=!0,!(--q>0)&&(document.removeEventListener("pointerdown",V,!0),document.removeEventListener("pointerup",G,!0),document.removeEventListener("click",X),document.removeEventListener("cancel",j,!0),document.removeEventListener("close",z,!0)))}}var D=Symbol.for("tangible-ui/vanilla/modal"),d=globalThis;d[D]||(d[D]=S,H());d.TangibleUI=d.TangibleUI||{};d.TangibleUI.modal=d[D];})();