@zakisheriff/liquid-glass 0.2.0 → 0.2.2

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/index.js CHANGED
@@ -258,12 +258,17 @@ function usePress(ref, options = {}) {
258
258
  window.addEventListener("pointercancel", up);
259
259
  };
260
260
  const blur = () => up();
261
+ const hold = (event) => {
262
+ if (pointer && event.cancelable) event.preventDefault();
263
+ };
264
+ el2.addEventListener("touchmove", hold, { passive: false });
261
265
  el2.addEventListener("pointerdown", down);
262
266
  window.addEventListener("blur", blur);
263
267
  return () => {
264
268
  up();
265
269
  springs.forEach((s) => s.stop());
266
270
  el2.removeEventListener("pointerdown", down);
271
+ el2.removeEventListener("touchmove", hold);
267
272
  window.removeEventListener("blur", blur);
268
273
  el2.style.removeProperty("scale");
269
274
  el2.style.removeProperty("translate");
@@ -290,6 +295,7 @@ function clone(source) {
290
295
  pairs.push({ original, copy, css: original.style.cssText, cls: original.className.toString() });
291
296
  });
292
297
  root.querySelectorAll(`[${SELF}], .lg-mirror, [data-lg-mirror-skip], input, textarea, select`).forEach((n) => n.remove());
298
+ root.removeAttribute("data-mirror");
293
299
  root.setAttribute("inert", "");
294
300
  root.setAttribute("aria-hidden", "true");
295
301
  return { root, pairs };
@@ -302,18 +308,19 @@ var alpha = (color) => {
302
308
  };
303
309
  function backdropChain(glass, source) {
304
310
  const chain = [];
311
+ if (glass.hasAttribute("data-lg-mirror-bare")) return chain;
305
312
  for (let node = glass.parentElement; node; node = node.parentElement) {
306
313
  if (node === source || source.contains(node)) continue;
307
314
  const cs = getComputedStyle(node);
308
315
  const image = cs.backgroundImage !== "none";
309
316
  const a = alpha(cs.backgroundColor);
310
317
  if (image || a > 0) chain.unshift(node);
311
- if (image || a >= 1) break;
318
+ if (image || a >= 1 || node.classList.contains("lg-glass")) break;
312
319
  }
313
320
  return chain;
314
321
  }
315
322
  var BACKGROUND = ["background-color", "background-image", "background-size", "background-position", "background-repeat", "border-radius"];
316
- function mirrorBackdrop(glass, source, filter, padding) {
323
+ function mirrorBackdrop(glass, source, padding, zoom, active2 = () => true) {
317
324
  const layer = document.createElement("div");
318
325
  layer.className = "lg-mirror";
319
326
  layer.setAttribute("aria-hidden", "true");
@@ -322,6 +329,9 @@ function mirrorBackdrop(glass, source, filter, padding) {
322
329
  const viewport = document.createElement("div");
323
330
  viewport.className = "lg-mirror__viewport";
324
331
  layer.append(viewport);
332
+ const zoomer = document.createElement("div");
333
+ zoomer.className = "lg-mirror__zoom";
334
+ viewport.append(zoomer);
325
335
  let copy = clone(source);
326
336
  let under = [];
327
337
  const buildUnder = () => {
@@ -336,14 +346,15 @@ function mirrorBackdrop(glass, source, filter, padding) {
336
346
  div.style.transformOrigin = "0 0";
337
347
  return { original, copy: div, placed: "" };
338
348
  });
339
- viewport.prepend(...under.map((u) => u.copy));
349
+ zoomer.prepend(...under.map((u) => u.copy));
340
350
  };
341
- viewport.append(copy.root);
351
+ zoomer.append(copy.root);
342
352
  buildUnder();
343
353
  let stopped = false;
344
354
  let frame2 = 0;
345
355
  let visible = true;
346
356
  let placed = "";
357
+ let shown = true;
347
358
  let pad = 0;
348
359
  const place = (from, g, sgx, sgy) => {
349
360
  const sw = from.offsetWidth;
@@ -414,15 +425,21 @@ function mirrorBackdrop(glass, source, filter, padding) {
414
425
  }
415
426
  }
416
427
  };
417
- const applyFilter = () => {
418
- const value = filter();
419
- if (layer.style.filter !== value) layer.style.filter = value;
428
+ let zoomed = "";
429
+ const applyZoom = () => {
430
+ const value = `scale(${zoom()})`;
431
+ if (value !== zoomed) zoomer.style.transform = zoomed = value;
420
432
  };
421
433
  const tick = () => {
422
434
  frame2 = 0;
423
435
  if (stopped) return;
424
- if (visible && !document.hidden) {
425
- applyFilter();
436
+ const on = visible && !document.hidden && active2();
437
+ if (on !== shown) {
438
+ shown = on;
439
+ layer.style.visibility = on ? "" : "hidden";
440
+ }
441
+ if (on) {
442
+ applyZoom();
426
443
  sync();
427
444
  align();
428
445
  }
@@ -507,7 +524,7 @@ function bevelProfile(bezel, thickness, ior) {
507
524
  return a + (b - a) * (f - i);
508
525
  };
509
526
  }
510
- function bake(width, height, radius, shape, pad = 0) {
527
+ function bake(width, height, radius, shape, pad = 0, simple = false) {
511
528
  const W = width + pad * 2;
512
529
  const H = height + pad * 2;
513
530
  let density = Math.min(typeof devicePixelRatio === "number" ? devicePixelRatio : 1, 2);
@@ -516,13 +533,14 @@ function bake(width, height, radius, shape, pad = 0) {
516
533
  const ch = Math.max(1, Math.ceil(H * density));
517
534
  const lens = shape.kind === "lens";
518
535
  const shift = bevelProfile(shape.bezel, shape.thickness, shape.ior);
519
- const magnify = lens ? 1 - 1 / Math.max(1, shape.zoom) : 0;
536
+ const magnify = lens ? 1 - 1 / Math.max(0.5, shape.zoom) : 0;
520
537
  const direction = lens ? 1 : -1;
521
538
  const dx = new Float32Array(cw * ch);
522
539
  const dy = new Float32Array(cw * ch);
523
540
  const rimA = new Float32Array(cw * ch);
524
541
  const rimHue = new Float32Array(cw * ch);
525
542
  const inside = new Float32Array(cw * ch);
543
+ const depth = new Float32Array(cw * ch);
526
544
  let max = 1e-4;
527
545
  const hw = width / 2;
528
546
  const hh = height / 2;
@@ -551,20 +569,26 @@ function bake(width, height, radius, shape, pad = 0) {
551
569
  }
552
570
  const i = y * cw + x;
553
571
  const s = shift(d) * shape.strength * direction;
554
- const vx = nx * s;
555
- const vy = ny * s;
572
+ let vx = nx * s;
573
+ let vy = ny * s;
574
+ if (simple && magnify) {
575
+ vx -= px * magnify;
576
+ vy -= py * magnify;
577
+ }
556
578
  dx[i] = vx;
557
579
  dy[i] = vy;
558
580
  const m = Math.max(Math.abs(vx), Math.abs(vy));
559
581
  if (m > max) max = m;
560
582
  inside[i] = clamp(d / px1 + 0.5, 0, 1);
583
+ const t = clamp(d / (shape.bezel * 0.9), 0, 1);
584
+ depth[i] = t * t * (3 - 2 * t);
561
585
  if (d >= -px1) {
562
586
  const facing = -(nx + ny) * Math.SQRT1_2;
563
587
  const light = 0.22 + 0.78 * Math.abs(facing) ** 2.2 * (facing > 0 ? 1 : 0.62);
564
588
  const line = Math.exp(-(((d - 0.55) / 0.55) ** 2));
565
- const inner = Math.exp(-((d / (shape.bezel * 0.55)) ** 2)) * 0.14;
589
+ const inner2 = Math.exp(-((d / (shape.bezel * 0.55)) ** 2)) * 0.14;
566
590
  const edgeAA = clamp(d / px1 + 1, 0, 1);
567
- rimA[i] = clamp((line * (lens ? 0.95 : 0.7) + inner) * light * edgeAA, 0, 1);
591
+ rimA[i] = clamp((line * (lens ? 0.95 : 0.7) + inner2) * light * edgeAA, 0, 1);
568
592
  rimHue[i] = Math.atan2(ny, nx);
569
593
  }
570
594
  }
@@ -585,7 +609,7 @@ function bake(width, height, radius, shape, pad = 0) {
585
609
  const map = canvas.toDataURL();
586
610
  const reach = Math.max(W, H) / 2;
587
611
  let zoomMap = "";
588
- if (magnify) {
612
+ if (magnify && !simple) {
589
613
  const ramp = ctx.createImageData(cw, ch);
590
614
  for (let y = 0; y < ch; y++) {
591
615
  for (let x = 0; x < cw; x++) {
@@ -629,15 +653,18 @@ function bake(width, height, radius, shape, pad = 0) {
629
653
  }
630
654
  ctx.putImageData(shapeMask, 0, 0);
631
655
  const mask = canvas.toDataURL();
656
+ for (let i = 0; i < cw * ch; i++) shapeMask.data[i * 4 + 3] = Math.round(depth[i] * 255);
657
+ ctx.putImageData(shapeMask, 0, 0);
658
+ const inner = canvas.toDataURL();
632
659
  const id = `lg-refract-${++counter}`;
633
660
  const box = { x: 0, y: 0, width: W, height: H };
634
661
  const filter = el("filter", {
635
662
  id,
636
663
  // Generous region: the rim samples content from beyond the glass edge.
637
- x: -0.5,
638
- y: -0.5,
639
- width: 2,
640
- height: 2,
664
+ x: -0.25,
665
+ y: -0.25,
666
+ width: 1.5,
667
+ height: 1.5,
641
668
  "color-interpolation-filters": "sRGB"
642
669
  });
643
670
  filter.append(el("feImage", { href: map, ...box, preserveAspectRatio: "none", result: "field" }));
@@ -657,7 +684,7 @@ function bake(width, height, radius, shape, pad = 0) {
657
684
  source = "magnified";
658
685
  }
659
686
  const scale = max * 2;
660
- if (shape.dispersion > 0) {
687
+ if (shape.dispersion > 0 && !simple) {
661
688
  const spread = 0.16 * shape.dispersion;
662
689
  const channels = [
663
690
  ["r", 1 + spread, "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0"],
@@ -698,7 +725,7 @@ function bake(width, height, radius, shape, pad = 0) {
698
725
  el("feComposite", { in: "bent", in2: "shape", operator: "in" })
699
726
  );
700
727
  container().append(filter);
701
- return { filter: `url(#${id})`, rim: `url("${rim}")` };
728
+ return { filter: `url(#${id})`, rim: `url("${rim}")`, inner: `url("${inner}")` };
702
729
  }
703
730
  function resolve(shape, width, height) {
704
731
  const kind = shape.kind ?? "surface";
@@ -714,15 +741,15 @@ function resolve(shape, width, height) {
714
741
  strength: shape.strength ?? 1
715
742
  };
716
743
  }
717
- function glassFor(width, height, radius, shape = {}, pad = 0) {
744
+ function glassFor(width, height, radius, shape = {}, pad = 0, simple = false) {
718
745
  const w = Math.round(width);
719
746
  const h = Math.round(height);
720
747
  const r = Math.min(w / 2, h / 2, Math.max(0, radius));
721
748
  const full = resolve(shape, w, h);
722
- const key = [w, h, Math.round(r * 2) / 2, full.kind, full.bezel.toFixed(1), full.thickness.toFixed(1), full.ior, full.zoom, full.dispersion, full.strength, pad].join("|");
749
+ const key = [w, h, Math.round(r * 2) / 2, full.kind, full.bezel.toFixed(1), full.thickness.toFixed(1), full.ior, full.zoom, full.dispersion, full.strength, pad, simple].join("|");
723
750
  let baked = cache.get(key);
724
751
  if (!baked) {
725
- baked = bake(w, h, r, full, pad);
752
+ baked = bake(w, h, r, full, pad, simple);
726
753
  cache.set(key, baked);
727
754
  }
728
755
  return baked;
@@ -741,7 +768,7 @@ function cornerRadius(element, width, height) {
741
768
  if (!Number.isFinite(n)) return 0;
742
769
  return value.endsWith("%") ? Math.min(width, height) * n / 100 : n;
743
770
  }
744
- function useRefraction(ref, shape = {}, enabled = true, mirror) {
771
+ function useRefraction(ref, shape = {}, enabled = true, mirror, mirrorActive) {
745
772
  const signature = JSON.stringify(shape);
746
773
  (0, import_react2.useEffect)(() => {
747
774
  const element = ref.current;
@@ -750,6 +777,7 @@ function useRefraction(ref, shape = {}, enabled = true, mirror) {
750
777
  let cancel;
751
778
  let filter = "";
752
779
  let pad = 0;
780
+ let zoom = 1;
753
781
  const fit = () => {
754
782
  const width = element.offsetWidth;
755
783
  const height = element.offsetHeight;
@@ -757,7 +785,11 @@ function useRefraction(ref, shape = {}, enabled = true, mirror) {
757
785
  const radius = cornerRadius(element, width, height);
758
786
  const baked = glassFor(width, height, radius, shape);
759
787
  filter = baked.filter;
760
- if (!live && mirror?.current) pad = Math.ceil(Math.min(width, height) * 0.45 + 6);
788
+ if (!live && mirror?.current) {
789
+ pad = Math.ceil(Math.min(width, height) * 0.45 + 6);
790
+ zoom = resolve(shape, width, height).zoom;
791
+ element.style.setProperty("--lg-inner-mask", baked.inner);
792
+ }
761
793
  if (live) element.style.setProperty("--lg-filter", baked.filter);
762
794
  element.style.setProperty("--lg-rim", baked.rim);
763
795
  };
@@ -768,7 +800,7 @@ function useRefraction(ref, shape = {}, enabled = true, mirror) {
768
800
  observer.observe(element);
769
801
  fit();
770
802
  const source = mirror?.current;
771
- const unmirror = !live && source ? mirrorBackdrop(element, source, () => filter, () => pad) : void 0;
803
+ const unmirror = !live && source ? mirrorBackdrop(element, source, () => pad, () => zoom, mirrorActive) : void 0;
772
804
  return () => {
773
805
  cancel?.();
774
806
  unmirror?.();
@@ -816,7 +848,8 @@ var GlassButton = import_react3.default.forwardRef(
816
848
  shimmer = true,
817
849
  thickness = 1,
818
850
  size = "md",
819
- variant = "default",
851
+ variant = "glass",
852
+ destructive = false,
820
853
  icon,
821
854
  className,
822
855
  style,
@@ -836,7 +869,8 @@ var GlassButton = import_react3.default.forwardRef(
836
869
  bezel: Math.min(height * 0.36, 22) * Math.max(0.5, thickness)
837
870
  });
838
871
  const iconOnly = icon != null && (children == null || children === false);
839
- const kind = variant === "ghost" ? "clear" : variant;
872
+ const red = destructive || variant === "destructive";
873
+ const kind = variant === "ghost" ? "clear" : variant === "default" || variant === "destructive" ? "glass" : variant;
840
874
  const classes = ["lg-glass", "lg-button", `lg-button--${size}`, `lg-button--${kind}`, className].filter(Boolean).join(" ");
841
875
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
842
876
  "button",
@@ -847,6 +881,7 @@ var GlassButton = import_react3.default.forwardRef(
847
881
  "data-liquid-glass": "",
848
882
  "data-icon-only": iconOnly ? "" : void 0,
849
883
  "data-shimmer": shimmer ? "" : void 0,
884
+ "data-destructive": red ? "" : void 0,
850
885
  style: tint ? { "--lg-tint": tint, ...style } : style,
851
886
  onPointerDown: (event) => {
852
887
  if (!rest.disabled) haptic();
@@ -880,9 +915,9 @@ var GlassCard = import_react4.default.forwardRef(
880
915
  "div",
881
916
  {
882
917
  ref,
883
- className: ["lg-glass", "lg-card", `lg-card--${variant}`, className].filter(Boolean).join(" "),
918
+ className: ["lg-glass", "lg-glass--host", "lg-card", `lg-card--${variant}`, className].filter(Boolean).join(" "),
884
919
  "data-liquid-glass": "",
885
- style: { padding, borderRadius: radius, ...tint ? { "--lg-card-tint": tint } : {}, ...style },
920
+ style: { padding, borderRadius: radius, ...tint ? { "--lg-host-tint": tint } : {}, ...style },
886
921
  ...rest,
887
922
  children
888
923
  }
@@ -1088,8 +1123,8 @@ var GlassSheet = ({ open, onClose, intensity = 5, tint, children, "aria-label":
1088
1123
  "aria-modal": "true",
1089
1124
  "aria-label": ariaLabel,
1090
1125
  tabIndex: -1,
1091
- className: "lg-glass lg-sheet",
1092
- style: tint ? { "--lg-card-tint": tint } : void 0,
1126
+ className: "lg-glass lg-glass--host lg-sheet",
1127
+ style: tint ? { "--lg-host-tint": tint } : void 0,
1093
1128
  children: [
1094
1129
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "lg-sheet__grabber-zone", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "lg-sheet__grabber" }) }),
1095
1130
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "lg-sheet__content", children })
@@ -1176,8 +1211,9 @@ function useLensTrack(refs, options) {
1176
1211
  if (!gesture) return 0;
1177
1212
  const raw = gesture.anchor + clientX - gesture.startX;
1178
1213
  const max = slot * (latest.current.count - 1);
1179
- if (raw < 0) return rubberband(raw, slot, 0.5);
1180
- if (raw > max) return max + rubberband(raw - max, slot, 0.5);
1214
+ const give = Math.min(14, slot * 0.12);
1215
+ if (raw < 0) return rubberband(raw, give, 0.55);
1216
+ if (raw > max) return max + rubberband(raw - max, give, 0.55);
1181
1217
  return raw;
1182
1218
  };
1183
1219
  const light = (clientX, box) => {
@@ -1274,7 +1310,7 @@ function useLensTrack(refs, options) {
1274
1310
  bar.querySelector(`[data-lg-item="${next}"]`)?.focus();
1275
1311
  };
1276
1312
  const onTouchMove = (event) => {
1277
- if (gesture?.moved && event.cancelable) event.preventDefault();
1313
+ if (gesture && event.cancelable) event.preventDefault();
1278
1314
  };
1279
1315
  const observer = new ResizeObserver(() => {
1280
1316
  measure();
@@ -1332,7 +1368,7 @@ function LensTrack({
1332
1368
  const row = (0, import_react8.useRef)(null);
1333
1369
  const strength = Math.max(1, Math.min(10, intensity)) / 5;
1334
1370
  useRefraction(glass, { kind: "surface", strength });
1335
- useRefraction(lens, { kind: "lens", strength, zoom: variant === "tabbar" ? 1.14 : 1.1 }, true, bar);
1371
+ useRefraction(lens, { kind: "lens", strength, zoom: variant === "tabbar" ? 1.14 : 1.1 });
1336
1372
  const tabbar = variant === "tabbar";
1337
1373
  useLensTrack(
1338
1374
  { bar, glass, lens, tint, row },
@@ -1340,9 +1376,9 @@ function LensTrack({
1340
1376
  count: items.length,
1341
1377
  index,
1342
1378
  onSelect: (next) => onChange?.(next),
1343
- overhang: tabbar ? 8 : 14,
1344
- spread: tabbar ? 0.22 : 0.3,
1345
- swell: tabbar ? 10 : 22
1379
+ overhang: tabbar ? 8 : 12,
1380
+ spread: tabbar ? 0.18 : 0.16,
1381
+ swell: tabbar ? 8 : 14
1346
1382
  }
1347
1383
  );
1348
1384
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
@@ -1472,8 +1508,16 @@ var GlassSlider = import_react11.default.forwardRef(
1472
1508
  const blockRef = (0, import_react11.useRef)(null);
1473
1509
  (0, import_react11.useImperativeHandle)(forwardedRef, () => inputRef.current);
1474
1510
  const strength = Math.max(1, Math.min(10, intensity)) / 5;
1511
+ const [mirrored, setMirrored] = import_react11.default.useState(false);
1512
+ (0, import_react11.useEffect)(() => setMirrored(!canRefractBackdrop()), []);
1475
1513
  const progress = max > min ? clamp((Number(value) - min) / (max - min), 0, 1) : 0;
1476
- useRefraction(thumbRef, { kind: "lens", zoom: 1.95, strength, dispersion: 0.6 }, showThumb, rootRef);
1514
+ useRefraction(
1515
+ thumbRef,
1516
+ { kind: "lens", zoom: 1.95, bezel: 7, thickness: 16, strength, dispersion: 0.6 },
1517
+ showThumb,
1518
+ rootRef,
1519
+ () => parseFloat(rootRef.current?.style.getPropertyValue("--lg-lift") || "0") > 0.01
1520
+ );
1477
1521
  useRefraction(blockRef, { kind: "surface", strength }, !showThumb);
1478
1522
  (0, import_react11.useEffect)(() => {
1479
1523
  if (!showThumb) return;
@@ -1639,11 +1683,21 @@ var GlassSlider = import_react11.default.forwardRef(
1639
1683
  }
1640
1684
  );
1641
1685
  }
1642
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { ref: rootRef, className: ["lg-slider", className].filter(Boolean).join(" "), "data-liquid-glass": "", style: vars, children: [
1643
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "lg-slider__rail", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "lg-slider__fill" }) }),
1644
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "lg-slider__thumb-slot", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { ref: thumbRef, className: "lg-glass lg-slider__thumb", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { ref: faceRef, className: "lg-slider__face" }) }) }),
1645
- input
1646
- ] });
1686
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
1687
+ "div",
1688
+ {
1689
+ ref: rootRef,
1690
+ className: ["lg-slider", className].filter(Boolean).join(" "),
1691
+ "data-liquid-glass": "",
1692
+ "data-mirror": mirrored ? "" : void 0,
1693
+ style: vars,
1694
+ children: [
1695
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "lg-slider__rail", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "lg-slider__fill" }) }),
1696
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "lg-slider__thumb-slot", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { ref: thumbRef, className: "lg-glass lg-slider__thumb", "data-lg-mirror-bare": "", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { ref: faceRef, className: "lg-slider__face" }) }) }),
1697
+ input
1698
+ ]
1699
+ }
1700
+ );
1647
1701
  }
1648
1702
  );
1649
1703
  GlassSlider.displayName = "GlassSlider";
@@ -1651,6 +1705,7 @@ GlassSlider.displayName = "GlassSlider";
1651
1705
  // src/components/GlassSwitch/GlassSwitch.tsx
1652
1706
  var import_react12 = __toESM(require("react"));
1653
1707
  var import_jsx_runtime9 = require("react/jsx-runtime");
1708
+ var SETTLE = springFrom(0.36, 0.68);
1654
1709
  var REST = 0.655;
1655
1710
  var TRAVEL = 22;
1656
1711
  var GlassSwitch = import_react12.default.forwardRef(
@@ -1674,7 +1729,13 @@ var GlassSwitch = import_react12.default.forwardRef(
1674
1729
  }
1675
1730
  };
1676
1731
  const sync = (0, import_react12.useRef)(null);
1677
- useRefraction(thumbRef, { kind: "lens", zoom: 1.45, strength: Math.max(1, Math.min(10, intensity)) / 5 }, true, ref);
1732
+ useRefraction(
1733
+ thumbRef,
1734
+ { kind: "lens", zoom: 1, dispersion: 0.5, strength: Math.max(1, Math.min(10, intensity)) / 5 },
1735
+ true,
1736
+ ref,
1737
+ () => parseFloat(ref.current?.style.getPropertyValue("--lg-lift") || "0") > 0.01
1738
+ );
1678
1739
  (0, import_react12.useEffect)(() => {
1679
1740
  const el2 = ref.current;
1680
1741
  const thumb = thumbRef.current;
@@ -1692,7 +1753,7 @@ var GlassSwitch = import_react12.default.forwardRef(
1692
1753
  };
1693
1754
  const position = createSpring(v.x, SPRINGS.snap, (value, velocity) => {
1694
1755
  v.x = value;
1695
- v.stretch = clamp(Math.abs(velocity) / 40, 0, 0.14);
1756
+ v.stretch = clamp(Math.abs(velocity) / 140, 0, 0.05);
1696
1757
  paint();
1697
1758
  });
1698
1759
  const lift = createSpring(0, SPRINGS.lift, (value) => {
@@ -1715,11 +1776,12 @@ var GlassSwitch = import_react12.default.forwardRef(
1715
1776
  const drop = (delay) => {
1716
1777
  clearTimeout(dropTimer);
1717
1778
  dropTimer = window.setTimeout(() => {
1718
- lift.tune(SPRINGS.settle);
1779
+ lift.tune(SETTLE);
1719
1780
  lift.set(0);
1720
1781
  }, delay);
1721
1782
  };
1722
1783
  const down = (event) => {
1784
+ el2.removeAttribute("data-keyboard");
1723
1785
  if (!event.isPrimary || event.button !== 0 || latest.current.disabled) return;
1724
1786
  clearTimeout(dropTimer);
1725
1787
  gesture = { id: event.pointerId, x: event.clientX, from: latest.current.checked ? 1 : 0, moved: false, at: performance.now() };
@@ -1805,6 +1867,10 @@ var GlassSwitch = import_react12.default.forwardRef(
1805
1867
  "data-liquid-glass": "",
1806
1868
  style: tint ? { "--lg-switch-on": tint, ...style } : style,
1807
1869
  ...rest,
1870
+ onKeyDown: (event) => {
1871
+ event.currentTarget.setAttribute("data-keyboard", "");
1872
+ rest.onKeyDown?.(event);
1873
+ },
1808
1874
  children: [
1809
1875
  /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { ref: fillRef, className: "lg-switch__fill", "aria-hidden": "true" }),
1810
1876
  /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { ref: thumbRef, className: "lg-glass lg-switch__thumb", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { ref: faceRef, className: "lg-switch__face" }) })