@zakisheriff/liquid-glass 0.2.4 → 0.2.5

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.mjs CHANGED
@@ -1134,8 +1134,8 @@ function useLensTrack(refs, options) {
1134
1134
  slot = (bar.clientWidth - pad - (parseFloat(style.paddingRight) || 0)) / latest.current.count;
1135
1135
  height = bar.clientHeight - (parseFloat(style.paddingTop) || 0) - (parseFloat(style.paddingBottom) || 0);
1136
1136
  const { overhang, spread } = latest.current;
1137
- W = Math.round(slot * (1 + spread));
1138
1137
  H = Math.round(bar.offsetHeight + overhang);
1138
+ W = Math.round(Math.max(slot * (1 + spread), slot + H - height));
1139
1139
  lens.style.width = `${W}px`;
1140
1140
  lens.style.height = `${H}px`;
1141
1141
  lens.style.left = `${pad + (slot - W) / 2}px`;
@@ -1508,7 +1508,7 @@ var GlassSlider = React8.forwardRef(
1508
1508
  value = 0,
1509
1509
  min = 0,
1510
1510
  max = 100,
1511
- step: step2 = 1,
1511
+ step: step2 = "any",
1512
1512
  intensity = 5,
1513
1513
  tint,
1514
1514
  shimmer: _shimmer,
@@ -1528,6 +1528,74 @@ var GlassSlider = React8.forwardRef(
1528
1528
  const faceRef = useRef7(null);
1529
1529
  const blockRef = useRef7(null);
1530
1530
  useImperativeHandle4(forwardedRef, () => inputRef.current);
1531
+ useEffect5(() => {
1532
+ const input2 = inputRef.current;
1533
+ const root = rootRef.current;
1534
+ const setValue = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value").set;
1535
+ let drag = null;
1536
+ const update = (clientX) => {
1537
+ if (!drag || max <= min) return;
1538
+ const inset = showThumb ? 19 * drag.width / root.offsetWidth : 0;
1539
+ const travel = Math.max(1, drag.width - inset * 2);
1540
+ const fraction = clamp((clientX - drag.left - inset - drag.offset) / travel, 0, 1);
1541
+ let next = min + fraction * (max - min);
1542
+ const increment = Number(step2);
1543
+ if (step2 !== "any" && Number.isFinite(increment) && increment > 0) {
1544
+ next = clamp(min + Math.round((next - min) / increment) * increment, min, max);
1545
+ next = Number(next.toFixed(10));
1546
+ }
1547
+ root.style.setProperty("--lg-progress", String((next - min) / (max - min)));
1548
+ if (next === input2.valueAsNumber) return;
1549
+ setValue.call(input2, String(next));
1550
+ input2.dispatchEvent(new Event("input", { bubbles: true }));
1551
+ };
1552
+ const down = (event) => {
1553
+ if (input2.disabled || !event.isPrimary || event.button !== 0 || drag) return;
1554
+ event.preventDefault();
1555
+ input2.focus({ preventScroll: true });
1556
+ const box = root.getBoundingClientRect();
1557
+ const inset = showThumb ? 19 * box.width / root.offsetWidth : 0;
1558
+ const current = max > min ? clamp((input2.valueAsNumber - min) / (max - min), 0, 1) : 0;
1559
+ const center = box.left + inset + current * (box.width - inset * 2);
1560
+ const offset = showThumb && Math.abs(event.clientX - center) <= inset ? event.clientX - center : 0;
1561
+ drag = { id: event.pointerId, left: box.left, width: box.width, offset };
1562
+ root.dataset.dragging = "";
1563
+ input2.setPointerCapture(event.pointerId);
1564
+ update(event.clientX);
1565
+ };
1566
+ const move = (event) => {
1567
+ if (event.pointerId !== drag?.id) return;
1568
+ event.preventDefault();
1569
+ update(event.clientX);
1570
+ };
1571
+ const release = () => {
1572
+ if (!drag) return;
1573
+ const id = drag.id;
1574
+ drag = null;
1575
+ delete root.dataset.dragging;
1576
+ if (input2.hasPointerCapture(id)) input2.releasePointerCapture(id);
1577
+ };
1578
+ const up = (event) => {
1579
+ if (event.pointerId !== drag?.id) return;
1580
+ update(event.clientX);
1581
+ release();
1582
+ };
1583
+ input2.addEventListener("pointerdown", down);
1584
+ input2.addEventListener("pointermove", move);
1585
+ input2.addEventListener("pointerup", up);
1586
+ input2.addEventListener("pointercancel", release);
1587
+ input2.addEventListener("lostpointercapture", release);
1588
+ window.addEventListener("blur", release);
1589
+ return () => {
1590
+ release();
1591
+ input2.removeEventListener("pointerdown", down);
1592
+ input2.removeEventListener("pointermove", move);
1593
+ input2.removeEventListener("pointerup", up);
1594
+ input2.removeEventListener("pointercancel", release);
1595
+ input2.removeEventListener("lostpointercapture", release);
1596
+ window.removeEventListener("blur", release);
1597
+ };
1598
+ }, [min, max, step2, showThumb]);
1531
1599
  const strength = Math.max(1, Math.min(10, intensity)) / 5;
1532
1600
  const [mirrored, setMirrored] = React8.useState(false);
1533
1601
  useEffect5(() => setMirrored(!canRefractBackdrop()), []);
@@ -1552,6 +1620,7 @@ var GlassSlider = React8.forwardRef(
1552
1620
  thumb.style.scale = `${s * (1 + v.stretch)} ${s * (1 - v.stretch * 0.5)}`;
1553
1621
  face.style.opacity = String(1 - clamp(v.lift, 0, 1) * 0.92);
1554
1622
  root.style.setProperty("--lg-lift", String(clamp(v.lift, 0, 1)));
1623
+ if (v.lift < 0.01 && lift.target === 0) delete root.dataset.lifted;
1555
1624
  };
1556
1625
  const lift = createSpring(0, SPRINGS.lift, (x) => {
1557
1626
  v.lift = x;
@@ -1568,6 +1637,7 @@ var GlassSlider = React8.forwardRef(
1568
1637
  if (input2.disabled) return;
1569
1638
  lastX = event.clientX;
1570
1639
  lastT = event.timeStamp;
1640
+ root.dataset.lifted = "";
1571
1641
  lift.tune(SPRINGS.lift);
1572
1642
  lift.set(1);
1573
1643
  haptic();
@@ -1593,6 +1663,7 @@ var GlassSlider = React8.forwardRef(
1593
1663
  window.addEventListener("pointerup", up);
1594
1664
  window.addEventListener("pointercancel", up);
1595
1665
  input2.addEventListener("blur", up);
1666
+ window.addEventListener("blur", up);
1596
1667
  return () => {
1597
1668
  lift.stop();
1598
1669
  stretch.stop();
@@ -1601,6 +1672,8 @@ var GlassSlider = React8.forwardRef(
1601
1672
  window.removeEventListener("pointerup", up);
1602
1673
  window.removeEventListener("pointercancel", up);
1603
1674
  input2.removeEventListener("blur", up);
1675
+ window.removeEventListener("blur", up);
1676
+ delete root.dataset.lifted;
1604
1677
  };
1605
1678
  }, [showThumb]);
1606
1679
  useEffect5(() => {
@@ -1691,12 +1764,12 @@ var GlassSlider = React8.forwardRef(
1691
1764
  /* @__PURE__ */ jsxs7("span", { className: "lg-slider__block-content", "aria-hidden": "true", children: [
1692
1765
  icon && /* @__PURE__ */ jsx9("span", { className: "lg-slider__icon", children: icon }),
1693
1766
  label2 && /* @__PURE__ */ jsx9("span", { className: "lg-slider__label", children: label2 }),
1694
- /* @__PURE__ */ jsx9("span", { className: "lg-slider__value", children: Number(value) })
1767
+ /* @__PURE__ */ jsx9("span", { className: "lg-slider__value", children: Math.round(Number(value)) })
1695
1768
  ] }),
1696
1769
  /* @__PURE__ */ jsx9("span", { className: "lg-slider__block-fill", "aria-hidden": "true", children: /* @__PURE__ */ jsxs7("span", { className: "lg-slider__block-content lg-slider__block-content--lit", children: [
1697
1770
  icon && /* @__PURE__ */ jsx9("span", { className: "lg-slider__icon", children: icon }),
1698
1771
  label2 && /* @__PURE__ */ jsx9("span", { className: "lg-slider__label", children: label2 }),
1699
- /* @__PURE__ */ jsx9("span", { className: "lg-slider__value", children: Number(value) })
1772
+ /* @__PURE__ */ jsx9("span", { className: "lg-slider__value", children: Math.round(Number(value)) })
1700
1773
  ] }) })
1701
1774
  ] }),
1702
1775
  input
@@ -1761,7 +1834,6 @@ var GlassSwitch = React9.forwardRef(
1761
1834
  const el2 = ref.current;
1762
1835
  const thumb = thumbRef.current;
1763
1836
  const fill = fillRef.current;
1764
- const face = faceRef.current;
1765
1837
  const v = { x: checked ? 1 : 0, lift: 0, stretch: 0 };
1766
1838
  const paint = () => {
1767
1839
  const s = REST + (1 - REST) * v.lift;
@@ -1769,8 +1841,8 @@ var GlassSwitch = React9.forwardRef(
1769
1841
  const sy = s * (1 - v.stretch * 0.5);
1770
1842
  thumb.style.transform = `translate(${v.x * TRAVEL}px, -50%) scale(${sx}, ${sy})`;
1771
1843
  const l = clamp(v.lift, 0, 1);
1772
- face.style.opacity = String(1 - l * 0.92);
1773
1844
  el2.style.setProperty("--lg-lift", String(l));
1845
+ el2.toggleAttribute("data-lifted", l > 0.01);
1774
1846
  };
1775
1847
  const position = createSpring(v.x, SPRINGS.snap, (value, velocity) => {
1776
1848
  v.x = value;