@sofyan/glass 0.2.0 → 0.3.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.
@@ -110,9 +110,328 @@ var GlassButton = forwardRef2(function GlassButton2({ variant = "glass", size =
110
110
  );
111
111
  });
112
112
 
113
+ // src/react/GlassConfirm.tsx
114
+ import {
115
+ useCallback,
116
+ useEffect,
117
+ useId,
118
+ useLayoutEffect,
119
+ useRef,
120
+ useState
121
+ } from "react";
122
+
123
+ // src/react/dialog.ts
124
+ function openDialog(dialog) {
125
+ if (typeof dialog.showModal === "function") dialog.showModal();
126
+ else dialog.setAttribute("open", "");
127
+ }
128
+ function closeDialog(dialog) {
129
+ if (typeof dialog.close === "function") dialog.close();
130
+ else dialog.removeAttribute("open");
131
+ }
132
+ var canShowModal = (dialog) => typeof dialog.showModal === "function";
133
+
134
+ // src/react/node.ts
135
+ var renders = (node) => node !== null && node !== void 0 && typeof node !== "boolean" && node !== "";
136
+
137
+ // src/react/GlassConfirm.tsx
138
+ import { Fragment, jsx as jsx3, jsxs } from "react/jsx-runtime";
139
+ var useIsomorphicLayoutEffect = typeof document === "undefined" ? useEffect : useLayoutEffect;
140
+ function GlassConfirm({
141
+ open,
142
+ onConfirm,
143
+ onCancel,
144
+ title,
145
+ message,
146
+ confirmLabel = "Confirm",
147
+ cancelLabel = "Cancel",
148
+ tone = "neutral",
149
+ confirmDisabled = false,
150
+ children,
151
+ className
152
+ }) {
153
+ const dialogRef = useRef(null);
154
+ const detailsRef = useRef(null);
155
+ const confirmRef = useRef(null);
156
+ const cancelRef = useRef(null);
157
+ const titleId = useId();
158
+ const messageId = useId();
159
+ const hasMessage = renders(message);
160
+ const [shown, setShown] = useState(false);
161
+ useIsomorphicLayoutEffect(() => {
162
+ const dialog = dialogRef.current;
163
+ if (!dialog) return;
164
+ const isOpen = dialog.hasAttribute("open");
165
+ if (open && !isOpen) openDialog(dialog);
166
+ if (!open && isOpen) closeDialog(dialog);
167
+ setShown(open);
168
+ }, [open]);
169
+ useIsomorphicLayoutEffect(() => {
170
+ if (!shown) return;
171
+ const details = detailsRef.current;
172
+ if (details?.contains(document.activeElement)) return;
173
+ const marked = details?.querySelector("[autofocus]");
174
+ if (marked) {
175
+ marked.focus();
176
+ return;
177
+ }
178
+ const safest = tone === "danger" || confirmDisabled ? cancelRef : confirmRef;
179
+ safest.current?.focus();
180
+ }, [shown]);
181
+ const handleCancel = (e) => {
182
+ e.preventDefault();
183
+ onCancel();
184
+ };
185
+ const handleClose = () => {
186
+ if (open && !dialogRef.current?.hasAttribute("open")) onCancel();
187
+ };
188
+ const handleKeyDown = (e) => {
189
+ if (e.key !== "Escape" || e.defaultPrevented || canShowModal(e.currentTarget)) return;
190
+ e.preventDefault();
191
+ onCancel();
192
+ };
193
+ return /* @__PURE__ */ jsx3(
194
+ "dialog",
195
+ {
196
+ ref: dialogRef,
197
+ role: "alertdialog",
198
+ "aria-modal": "true",
199
+ "aria-labelledby": titleId,
200
+ "aria-describedby": hasMessage ? messageId : void 0,
201
+ tabIndex: -1,
202
+ onCancel: handleCancel,
203
+ onClose: handleClose,
204
+ onKeyDown: handleKeyDown,
205
+ className: cx("glass-confirm", className),
206
+ children: shown && /* @__PURE__ */ jsxs(Fragment, { children: [
207
+ /* @__PURE__ */ jsx3("h2", { id: titleId, className: "glass-confirm-title", children: title }),
208
+ hasMessage && /* @__PURE__ */ jsx3("div", { id: messageId, className: "glass-confirm-message", children: message }),
209
+ renders(children) && /* @__PURE__ */ jsx3("div", { ref: detailsRef, className: "glass-confirm-details", children }),
210
+ /* @__PURE__ */ jsxs("div", { className: "glass-confirm-actions", children: [
211
+ /* @__PURE__ */ jsx3(GlassButton, { ref: cancelRef, onClick: onCancel, children: cancelLabel }),
212
+ /* @__PURE__ */ jsx3(
213
+ GlassButton,
214
+ {
215
+ ref: confirmRef,
216
+ variant: tone === "danger" ? "danger" : "primary",
217
+ disabled: confirmDisabled,
218
+ onClick: onConfirm,
219
+ children: confirmLabel
220
+ }
221
+ )
222
+ ] })
223
+ ] })
224
+ }
225
+ );
226
+ }
227
+ function useGlassConfirm() {
228
+ const [state, setState] = useState({
229
+ open: false,
230
+ options: { title: "" }
231
+ });
232
+ const pending = useRef(null);
233
+ const queued = useRef(null);
234
+ const answer = useCallback((confirmed) => {
235
+ const request = pending.current;
236
+ if (!request) return;
237
+ pending.current = null;
238
+ request.resolve(confirmed);
239
+ setState((s) => ({ ...s, open: false }));
240
+ }, []);
241
+ const confirm = useCallback(
242
+ (options) => new Promise((resolve) => {
243
+ const request = { options, resolve };
244
+ const previous = pending.current;
245
+ pending.current = request;
246
+ if (!previous) {
247
+ setState({ open: true, options });
248
+ return;
249
+ }
250
+ previous.resolve(false);
251
+ queued.current = request;
252
+ setState((s) => ({ ...s, open: false }));
253
+ }),
254
+ []
255
+ );
256
+ useIsomorphicLayoutEffect(() => {
257
+ const next = queued.current;
258
+ if (state.open || !next) return;
259
+ queued.current = null;
260
+ setState({ open: true, options: next.options });
261
+ });
262
+ useEffect(
263
+ () => () => {
264
+ pending.current?.resolve(false);
265
+ pending.current = null;
266
+ queued.current = null;
267
+ },
268
+ []
269
+ );
270
+ const { title, message, confirmLabel, cancelLabel, tone, details } = state.options;
271
+ const dialog = /* @__PURE__ */ jsx3(
272
+ GlassConfirm,
273
+ {
274
+ open: state.open,
275
+ onConfirm: () => answer(true),
276
+ onCancel: () => answer(false),
277
+ title,
278
+ message,
279
+ confirmLabel,
280
+ cancelLabel,
281
+ tone,
282
+ children: details
283
+ }
284
+ );
285
+ return { confirm, dialog };
286
+ }
287
+
288
+ // src/react/GlassField.tsx
289
+ import {
290
+ forwardRef as forwardRef3,
291
+ useId as useId2
292
+ } from "react";
293
+ import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
294
+ function useField({ id, hint, error, describedBy, invalid }) {
295
+ const generated = useId2();
296
+ const controlId = id || generated;
297
+ const hintId = renders(hint) ? `${controlId}-hint` : void 0;
298
+ const errorId = renders(error) ? `${controlId}-error` : void 0;
299
+ return {
300
+ controlId,
301
+ hintId,
302
+ errorId,
303
+ control: {
304
+ id: controlId,
305
+ "aria-describedby": [describedBy, hintId, errorId].filter(Boolean).join(" ") || void 0,
306
+ // Only once there is an error (WCAG 3.3.1, ARIA21): an untouched field is not invalid.
307
+ "aria-invalid": errorId ? true : invalid
308
+ }
309
+ };
310
+ }
311
+ function FieldShell({
312
+ field,
313
+ label,
314
+ hint,
315
+ error,
316
+ hideLabel,
317
+ required,
318
+ className,
319
+ children
320
+ }) {
321
+ return /* @__PURE__ */ jsxs2("div", { className: cx("glass-field", className), children: [
322
+ /* @__PURE__ */ jsxs2(
323
+ "label",
324
+ {
325
+ htmlFor: field.controlId,
326
+ className: cx("glass-field-label", hideLabel && "glass-field-label-hidden"),
327
+ children: [
328
+ label,
329
+ required && /* @__PURE__ */ jsx4("span", { className: "glass-field-required", "aria-hidden": "true", children: "*" })
330
+ ]
331
+ }
332
+ ),
333
+ children,
334
+ field.hintId && /* @__PURE__ */ jsx4("div", { id: field.hintId, className: "glass-field-hint", children: hint }),
335
+ field.errorId && /* @__PURE__ */ jsx4("div", { id: field.errorId, className: "glass-field-error", children: error })
336
+ ] });
337
+ }
338
+ var GlassInput = forwardRef3(function GlassInput2({
339
+ label,
340
+ hint,
341
+ error,
342
+ hideLabel,
343
+ className,
344
+ inputClassName,
345
+ id,
346
+ "aria-describedby": describedBy,
347
+ "aria-invalid": invalid,
348
+ ...rest
349
+ }, ref) {
350
+ const field = useField({ id, hint, error, describedBy, invalid });
351
+ return /* @__PURE__ */ jsx4(
352
+ FieldShell,
353
+ {
354
+ field,
355
+ label,
356
+ hint,
357
+ error,
358
+ hideLabel,
359
+ required: rest.required,
360
+ className,
361
+ children: /* @__PURE__ */ jsx4("input", { ref, ...rest, ...field.control, className: cx("glass-input", inputClassName) })
362
+ }
363
+ );
364
+ });
365
+ var GlassTextarea = forwardRef3(
366
+ function GlassTextarea2({
367
+ label,
368
+ hint,
369
+ error,
370
+ hideLabel,
371
+ className,
372
+ inputClassName,
373
+ id,
374
+ "aria-describedby": describedBy,
375
+ "aria-invalid": invalid,
376
+ ...rest
377
+ }, ref) {
378
+ const field = useField({ id, hint, error, describedBy, invalid });
379
+ return /* @__PURE__ */ jsx4(
380
+ FieldShell,
381
+ {
382
+ field,
383
+ label,
384
+ hint,
385
+ error,
386
+ hideLabel,
387
+ required: rest.required,
388
+ className,
389
+ children: /* @__PURE__ */ jsx4(
390
+ "textarea",
391
+ {
392
+ ref,
393
+ ...rest,
394
+ ...field.control,
395
+ className: cx("glass-input", inputClassName)
396
+ }
397
+ )
398
+ }
399
+ );
400
+ }
401
+ );
402
+ var GlassSelect = forwardRef3(function GlassSelect2({
403
+ label,
404
+ hint,
405
+ error,
406
+ hideLabel,
407
+ className,
408
+ inputClassName,
409
+ id,
410
+ "aria-describedby": describedBy,
411
+ "aria-invalid": invalid,
412
+ ...rest
413
+ }, ref) {
414
+ const field = useField({ id, hint, error, describedBy, invalid });
415
+ const listBox = rest.multiple || (rest.size ?? 1) > 1;
416
+ const select = /* @__PURE__ */ jsx4("select", { ref, ...rest, ...field.control, className: cx("glass-input", inputClassName) });
417
+ return /* @__PURE__ */ jsx4(
418
+ FieldShell,
419
+ {
420
+ field,
421
+ label,
422
+ hint,
423
+ error,
424
+ hideLabel,
425
+ required: rest.required,
426
+ className,
427
+ children: listBox ? select : /* @__PURE__ */ jsx4("div", { className: "glass-select", children: select })
428
+ }
429
+ );
430
+ });
431
+
113
432
  // src/react/GlassFilter.tsx
114
- import { useEffect } from "react";
115
- import { jsx as jsx3, jsxs } from "react/jsx-runtime";
433
+ import { useEffect as useEffect2 } from "react";
434
+ import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
116
435
  function supportsBackdropRefraction() {
117
436
  if (typeof navigator === "undefined" || typeof CSS === "undefined") return false;
118
437
  const uaData = navigator.userAgentData;
@@ -120,7 +439,7 @@ function supportsBackdropRefraction() {
120
439
  return isChromium && CSS.supports("backdrop-filter", "url(#lg-refract)");
121
440
  }
122
441
  function GlassFilter() {
123
- useEffect(() => {
442
+ useEffect2(() => {
124
443
  if (!supportsBackdropRefraction()) return;
125
444
  const root = document.documentElement;
126
445
  root.setAttribute("data-lg-refract", "");
@@ -128,7 +447,7 @@ function GlassFilter() {
128
447
  root.removeAttribute("data-lg-refract");
129
448
  };
130
449
  }, []);
131
- return /* @__PURE__ */ jsx3(
450
+ return /* @__PURE__ */ jsx5(
132
451
  "svg",
133
452
  {
134
453
  "aria-hidden": "true",
@@ -136,7 +455,7 @@ function GlassFilter() {
136
455
  width: "0",
137
456
  height: "0",
138
457
  style: { position: "absolute", width: 0, height: 0, overflow: "hidden" },
139
- children: /* @__PURE__ */ jsxs(
458
+ children: /* @__PURE__ */ jsxs3(
140
459
  "filter",
141
460
  {
142
461
  id: "lg-refract",
@@ -146,7 +465,7 @@ function GlassFilter() {
146
465
  height: "100%",
147
466
  colorInterpolationFilters: "sRGB",
148
467
  children: [
149
- /* @__PURE__ */ jsx3(
468
+ /* @__PURE__ */ jsx5(
150
469
  "feTurbulence",
151
470
  {
152
471
  type: "fractalNoise",
@@ -156,8 +475,8 @@ function GlassFilter() {
156
475
  result: "noise"
157
476
  }
158
477
  ),
159
- /* @__PURE__ */ jsx3("feGaussianBlur", { in: "noise", stdDeviation: "2", result: "softNoise" }),
160
- /* @__PURE__ */ jsx3(
478
+ /* @__PURE__ */ jsx5("feGaussianBlur", { in: "noise", stdDeviation: "2", result: "softNoise" }),
479
+ /* @__PURE__ */ jsx5(
161
480
  "feDisplacementMap",
162
481
  {
163
482
  in: "SourceGraphic",
@@ -176,13 +495,28 @@ function GlassFilter() {
176
495
 
177
496
  // src/react/GlassSheet.tsx
178
497
  import {
179
- useEffect as useEffect3,
180
- useId,
181
- useRef as useRef2
498
+ useEffect as useEffect4,
499
+ useId as useId3,
500
+ useRef as useRef3
182
501
  } from "react";
183
502
 
503
+ // src/react/CloseIcon.tsx
504
+ import { jsx as jsx6 } from "react/jsx-runtime";
505
+ function CloseIcon() {
506
+ return /* @__PURE__ */ jsx6("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsx6(
507
+ "path",
508
+ {
509
+ d: "M6 18 18 6M6 6l12 12",
510
+ stroke: "currentColor",
511
+ strokeWidth: "1.5",
512
+ strokeLinecap: "round",
513
+ strokeLinejoin: "round"
514
+ }
515
+ ) });
516
+ }
517
+
184
518
  // src/react/swipe.ts
185
- import { useEffect as useEffect2, useRef } from "react";
519
+ import { useEffect as useEffect3, useRef as useRef2 } from "react";
186
520
  var DRAG_SLOP_PX = 8;
187
521
  var CLOSE_DISTANCE_RATIO = 0.25;
188
522
  var CLOSE_VELOCITY = 0.5;
@@ -203,9 +537,9 @@ var anyCanScroll = (scrollers) => scrollers.some((el) => el.scrollHeight > el.cl
203
537
  var runs = /* @__PURE__ */ new WeakMap();
204
538
  var prefersReducedMotion = () => typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
205
539
  function useSwipeToClose(sheetRef, { enabled, scrollRef, onClose, media = "(max-width: 639.98px)" }) {
206
- const onCloseRef = useRef(onClose);
540
+ const onCloseRef = useRef2(onClose);
207
541
  onCloseRef.current = onClose;
208
- useEffect2(() => {
542
+ useEffect3(() => {
209
543
  const sheet = sheetRef.current;
210
544
  if (!enabled || !sheet) return;
211
545
  let drag = null;
@@ -416,24 +750,12 @@ function useSwipeToClose(sheetRef, { enabled, scrollRef, onClose, media = "(max-
416
750
  }
417
751
 
418
752
  // src/react/GlassSheet.tsx
419
- import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
753
+ import { jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
420
754
  var needsLightDismissFallback = () => typeof HTMLDialogElement !== "undefined" && !("closedBy" in HTMLDialogElement.prototype);
421
755
  var isOutside = (e) => {
422
756
  const r = e.currentTarget.getBoundingClientRect();
423
757
  return e.clientX < r.left || e.clientX > r.right || e.clientY < r.top || e.clientY > r.bottom;
424
758
  };
425
- function CloseIcon() {
426
- return /* @__PURE__ */ jsx4("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsx4(
427
- "path",
428
- {
429
- d: "M6 18 18 6M6 6l12 12",
430
- stroke: "currentColor",
431
- strokeWidth: "1.5",
432
- strokeLinecap: "round",
433
- strokeLinejoin: "round"
434
- }
435
- ) });
436
- }
437
759
  function GlassSheet({
438
760
  open,
439
761
  onClose,
@@ -446,26 +768,23 @@ function GlassSheet({
446
768
  className,
447
769
  bodyClassName
448
770
  }) {
449
- const dialogRef = useRef2(null);
450
- const bodyRef = useRef2(null);
451
- const titleId = useId();
452
- const pressedOutside = useRef2(false);
453
- useEffect3(() => {
771
+ const dialogRef = useRef3(null);
772
+ const bodyRef = useRef3(null);
773
+ const titleId = useId3();
774
+ const pressedOutside = useRef3(false);
775
+ useEffect4(() => {
454
776
  const dialog = dialogRef.current;
455
777
  if (!dialog || open === dialog.hasAttribute("open")) return;
456
778
  if (open) {
457
- if (typeof dialog.showModal === "function") dialog.showModal();
458
- else dialog.setAttribute("open", "");
779
+ openDialog(dialog);
459
780
  dialog.focus({ preventScroll: true });
460
781
  if (bodyRef.current) bodyRef.current.scrollTop = 0;
461
- } else if (typeof dialog.close === "function") {
462
- dialog.close();
463
782
  } else {
464
- dialog.removeAttribute("open");
783
+ closeDialog(dialog);
465
784
  }
466
785
  }, [open]);
467
786
  useSwipeToClose(dialogRef, { enabled: open && swipeToClose, scrollRef: bodyRef, onClose });
468
- return /* @__PURE__ */ jsxs2(
787
+ return /* @__PURE__ */ jsxs4(
469
788
  "dialog",
470
789
  {
471
790
  ref: dialogRef,
@@ -484,37 +803,284 @@ function GlassSheet({
484
803
  },
485
804
  className: cx("glass-dialog", className),
486
805
  children: [
487
- swipeToClose && /* @__PURE__ */ jsx4("div", { className: "glass-dialog-grabber", "aria-hidden": "true" }),
488
- /* @__PURE__ */ jsxs2("header", { className: "glass-dialog-header", children: [
489
- /* @__PURE__ */ jsxs2("div", { className: "glass-dialog-heading", children: [
490
- eyebrow && /* @__PURE__ */ jsx4("p", { className: "glass-dialog-eyebrow", children: eyebrow }),
491
- /* @__PURE__ */ jsx4("h2", { id: titleId, className: "glass-dialog-title", children: title })
806
+ swipeToClose && /* @__PURE__ */ jsx7("div", { className: "glass-dialog-grabber", "aria-hidden": "true" }),
807
+ /* @__PURE__ */ jsxs4("header", { className: "glass-dialog-header", children: [
808
+ /* @__PURE__ */ jsxs4("div", { className: "glass-dialog-heading", children: [
809
+ eyebrow && /* @__PURE__ */ jsx7("p", { className: "glass-dialog-eyebrow", children: eyebrow }),
810
+ /* @__PURE__ */ jsx7("h2", { id: titleId, className: "glass-dialog-title", children: title })
492
811
  ] }),
493
- /* @__PURE__ */ jsx4(
812
+ /* @__PURE__ */ jsx7(
494
813
  "button",
495
814
  {
496
815
  type: "button",
497
816
  onClick: onClose,
498
817
  "aria-label": closeLabel,
499
818
  className: "glass-dialog-close",
500
- children: /* @__PURE__ */ jsx4(CloseIcon, {})
819
+ children: /* @__PURE__ */ jsx7(CloseIcon, {})
501
820
  }
502
821
  )
503
822
  ] }),
504
- /* @__PURE__ */ jsx4("div", { ref: bodyRef, className: cx("glass-dialog-body", bodyClassName), children }),
505
- footer && /* @__PURE__ */ jsx4("div", { className: "glass-dialog-footer", children: footer })
823
+ /* @__PURE__ */ jsx7("div", { ref: bodyRef, className: cx("glass-dialog-body", bodyClassName), children }),
824
+ footer && /* @__PURE__ */ jsx7("div", { className: "glass-dialog-footer", children: footer })
825
+ ]
826
+ }
827
+ );
828
+ }
829
+
830
+ // src/react/GlassTabs.tsx
831
+ import {
832
+ createContext,
833
+ useContext,
834
+ useId as useId4,
835
+ useMemo
836
+ } from "react";
837
+ import { jsx as jsx8 } from "react/jsx-runtime";
838
+ var TabsContext = createContext(null);
839
+ function useTabs(component) {
840
+ const tabs = useContext(TabsContext);
841
+ if (!tabs) throw new Error(`<${component}> must be inside <GlassTabs>.`);
842
+ return tabs;
843
+ }
844
+ var idPart = (value) => value.replace(/[\s%]/g, (c) => `%${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
845
+ var tabId = (prefix, value) => `${prefix}-tab-${idPart(value)}`;
846
+ var panelId = (prefix, value) => `${prefix}-panel-${idPart(value)}`;
847
+ var tabValues = /* @__PURE__ */ new WeakMap();
848
+ function moveTo(key, from, count, vertical, rtl) {
849
+ switch (key) {
850
+ case "Home":
851
+ return 0;
852
+ case "End":
853
+ return count - 1;
854
+ case "ArrowDown":
855
+ return vertical ? (from + 1) % count : void 0;
856
+ case "ArrowUp":
857
+ return vertical ? (from - 1 + count) % count : void 0;
858
+ case "ArrowRight":
859
+ case "ArrowLeft": {
860
+ if (vertical) return void 0;
861
+ const forward = key === "ArrowRight" !== rtl();
862
+ return (from + (forward ? 1 : -1) + count) % count;
863
+ }
864
+ default:
865
+ return void 0;
866
+ }
867
+ }
868
+ function GlassTabs({
869
+ value,
870
+ onChange,
871
+ label,
872
+ orientation = "horizontal",
873
+ children
874
+ }) {
875
+ const idPrefix = useId4();
876
+ const context = useMemo(
877
+ () => ({ value, onChange, label, orientation, idPrefix }),
878
+ [value, onChange, label, orientation, idPrefix]
879
+ );
880
+ return /* @__PURE__ */ jsx8(TabsContext.Provider, { value: context, children });
881
+ }
882
+ function GlassTabList({ children, className }) {
883
+ const { value, onChange, label, orientation } = useTabs("GlassTabList");
884
+ const vertical = orientation === "vertical";
885
+ const onKeyDown = (e) => {
886
+ if (e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey) return;
887
+ const list = e.currentTarget;
888
+ const tabs = Array.from(list.querySelectorAll('[role="tab"]')).filter(
889
+ (tab2) => !tab2.disabled && tab2.closest('[role="tablist"]') === list
890
+ );
891
+ const from = tabs.findIndex((tab2) => tab2.contains(e.target));
892
+ if (from === -1) return;
893
+ const rtl = () => getComputedStyle(list).direction === "rtl";
894
+ const to = moveTo(e.key, from, tabs.length, vertical, rtl);
895
+ const tab = to === void 0 ? void 0 : tabs[to];
896
+ if (!tab) return;
897
+ e.preventDefault();
898
+ tab.focus();
899
+ const next = tabValues.get(tab);
900
+ if (next !== void 0 && next !== value) onChange(next);
901
+ };
902
+ return /* @__PURE__ */ jsx8(
903
+ "div",
904
+ {
905
+ role: "tablist",
906
+ "aria-label": label,
907
+ "aria-orientation": vertical ? "vertical" : void 0,
908
+ "data-glass-no-drag": "",
909
+ onKeyDown,
910
+ className: cx("glass-tabs", className),
911
+ children
912
+ }
913
+ );
914
+ }
915
+ function GlassTab({ value, disabled, children, className }) {
916
+ const tabs = useTabs("GlassTab");
917
+ const selected = tabs.value === value;
918
+ return /* @__PURE__ */ jsx8(
919
+ "button",
920
+ {
921
+ ref: (el) => {
922
+ if (el) tabValues.set(el, value);
923
+ },
924
+ type: "button",
925
+ role: "tab",
926
+ id: tabId(tabs.idPrefix, value),
927
+ "aria-selected": selected,
928
+ "aria-controls": panelId(tabs.idPrefix, value),
929
+ tabIndex: selected ? 0 : -1,
930
+ disabled,
931
+ onClick: () => {
932
+ if (!selected) tabs.onChange(value);
933
+ },
934
+ className: cx("glass-tab", className),
935
+ children
936
+ }
937
+ );
938
+ }
939
+ function GlassTabPanel({ value, children, className }) {
940
+ const tabs = useTabs("GlassTabPanel");
941
+ return /* @__PURE__ */ jsx8(
942
+ "div",
943
+ {
944
+ role: "tabpanel",
945
+ id: panelId(tabs.idPrefix, value),
946
+ "aria-labelledby": tabId(tabs.idPrefix, value),
947
+ hidden: tabs.value !== value,
948
+ tabIndex: 0,
949
+ className: cx("glass-tab-panel", className),
950
+ children
951
+ }
952
+ );
953
+ }
954
+
955
+ // src/react/GlassToast.tsx
956
+ import {
957
+ useEffect as useEffect5,
958
+ useRef as useRef4,
959
+ useState as useState2,
960
+ useSyncExternalStore
961
+ } from "react";
962
+ import { createPortal } from "react-dom";
963
+ import { jsx as jsx9, jsxs as jsxs5 } from "react/jsx-runtime";
964
+ var MAX_TOASTS = 3;
965
+ var DEFAULT_DURATION_MS = 5e3;
966
+ var MAX_TIMEOUT_MS = 2 ** 31 - 1;
967
+ var toasts = [];
968
+ var nextId = 1;
969
+ var listeners = /* @__PURE__ */ new Set();
970
+ var NONE = [];
971
+ var emit = () => {
972
+ for (const listener of listeners) listener();
973
+ };
974
+ var subscribe = (listener) => {
975
+ listeners.add(listener);
976
+ return () => {
977
+ listeners.delete(listener);
978
+ };
979
+ };
980
+ var getSnapshot = () => toasts;
981
+ var getServerSnapshot = () => NONE;
982
+ function trim(list) {
983
+ while (list.length > MAX_TOASTS) {
984
+ const neutral = list.findIndex((t) => t.tone !== "danger");
985
+ list.splice(neutral === -1 ? 0 : neutral, 1);
986
+ }
987
+ return list;
988
+ }
989
+ function toast(message, options = {}) {
990
+ const { tone = "neutral", duration = DEFAULT_DURATION_MS } = options;
991
+ const id = nextId++;
992
+ toasts = trim([...toasts, { id, message, tone, duration }]);
993
+ emit();
994
+ return id;
995
+ }
996
+ function dismissToast(id) {
997
+ const next = id === void 0 ? NONE : toasts.filter((t) => t.id !== id);
998
+ if (next.length === toasts.length) return;
999
+ toasts = next;
1000
+ emit();
1001
+ }
1002
+ var leavesByItself = ({ tone, duration }) => tone !== "danger" && Number.isFinite(duration) && duration > 0;
1003
+ function Toast({ item, dismissLabel }) {
1004
+ const { id, tone, message } = item;
1005
+ const timed = leavesByItself(item);
1006
+ const [hovered, setHovered] = useState2(false);
1007
+ const [focused, setFocused] = useState2(false);
1008
+ const remaining = useRef4(item.duration);
1009
+ const paused = hovered || focused;
1010
+ useEffect5(() => {
1011
+ if (!timed || paused) return;
1012
+ const started = Date.now();
1013
+ const timer = setTimeout(() => dismissToast(id), Math.min(remaining.current, MAX_TIMEOUT_MS));
1014
+ return () => {
1015
+ clearTimeout(timer);
1016
+ remaining.current -= Date.now() - started;
1017
+ };
1018
+ }, [id, timed, paused]);
1019
+ const onBlur = (e) => {
1020
+ if (!e.currentTarget.contains(e.relatedTarget)) setFocused(false);
1021
+ };
1022
+ return /* @__PURE__ */ jsxs5(
1023
+ "div",
1024
+ {
1025
+ className: cx("glass-toast", tone === "danger" && "glass-toast-danger"),
1026
+ onMouseEnter: () => setHovered(true),
1027
+ onMouseLeave: () => setHovered(false),
1028
+ onFocus: () => setFocused(true),
1029
+ onBlur,
1030
+ children: [
1031
+ /* @__PURE__ */ jsx9("div", { className: "glass-toast-message", children: message }),
1032
+ !timed && /* @__PURE__ */ jsx9(
1033
+ "button",
1034
+ {
1035
+ type: "button",
1036
+ className: "glass-toast-dismiss",
1037
+ "aria-label": dismissLabel,
1038
+ onClick: () => dismissToast(id),
1039
+ children: /* @__PURE__ */ jsx9(CloseIcon, {})
1040
+ }
1041
+ )
506
1042
  ]
507
1043
  }
508
1044
  );
509
1045
  }
1046
+ function GlassToasts({
1047
+ dismissLabel = "Dismiss",
1048
+ position = "top",
1049
+ className
1050
+ }) {
1051
+ const items = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
1052
+ const [mounted, setMounted] = useState2(false);
1053
+ useEffect5(() => setMounted(true), []);
1054
+ if (!mounted) return null;
1055
+ const renderToast = (item) => /* @__PURE__ */ jsx9(Toast, { item, dismissLabel }, item.id);
1056
+ return createPortal(
1057
+ /* @__PURE__ */ jsxs5("div", { className: cx("glass-toasts", position === "bottom" && "glass-toasts-bottom", className), children: [
1058
+ /* @__PURE__ */ jsx9("div", { role: "status", "aria-atomic": "false", className: "glass-toasts-region", children: items.filter((t) => t.tone !== "danger").map(renderToast) }),
1059
+ /* @__PURE__ */ jsx9("div", { role: "alert", "aria-atomic": "false", className: "glass-toasts-region", children: items.filter((t) => t.tone === "danger").map(renderToast) })
1060
+ ] }),
1061
+ document.body
1062
+ );
1063
+ }
510
1064
  export {
511
1065
  Glass,
512
1066
  GlassButton,
1067
+ GlassConfirm,
513
1068
  GlassFilter,
1069
+ GlassInput,
1070
+ GlassSelect,
514
1071
  GlassSheet,
1072
+ GlassTab,
1073
+ GlassTabList,
1074
+ GlassTabPanel,
1075
+ GlassTabs,
1076
+ GlassTextarea,
1077
+ GlassToasts,
1078
+ dismissToast,
515
1079
  glassClasses,
516
1080
  shouldClose,
517
1081
  supportsBackdropRefraction,
1082
+ toast,
1083
+ useGlassConfirm,
518
1084
  useSwipeToClose
519
1085
  };
520
1086
  //# sourceMappingURL=index.js.map