@zakisheriff/liquid-glass 0.2.1 → 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.css +47 -9
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +41 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +41 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -206,12 +206,17 @@ function usePress(ref, options = {}) {
|
|
|
206
206
|
window.addEventListener("pointercancel", up);
|
|
207
207
|
};
|
|
208
208
|
const blur = () => up();
|
|
209
|
+
const hold = (event) => {
|
|
210
|
+
if (pointer && event.cancelable) event.preventDefault();
|
|
211
|
+
};
|
|
212
|
+
el2.addEventListener("touchmove", hold, { passive: false });
|
|
209
213
|
el2.addEventListener("pointerdown", down);
|
|
210
214
|
window.addEventListener("blur", blur);
|
|
211
215
|
return () => {
|
|
212
216
|
up();
|
|
213
217
|
springs.forEach((s) => s.stop());
|
|
214
218
|
el2.removeEventListener("pointerdown", down);
|
|
219
|
+
el2.removeEventListener("touchmove", hold);
|
|
215
220
|
window.removeEventListener("blur", blur);
|
|
216
221
|
el2.style.removeProperty("scale");
|
|
217
222
|
el2.style.removeProperty("translate");
|
|
@@ -238,6 +243,7 @@ function clone(source) {
|
|
|
238
243
|
pairs.push({ original, copy, css: original.style.cssText, cls: original.className.toString() });
|
|
239
244
|
});
|
|
240
245
|
root.querySelectorAll(`[${SELF}], .lg-mirror, [data-lg-mirror-skip], input, textarea, select`).forEach((n) => n.remove());
|
|
246
|
+
root.removeAttribute("data-mirror");
|
|
241
247
|
root.setAttribute("inert", "");
|
|
242
248
|
root.setAttribute("aria-hidden", "true");
|
|
243
249
|
return { root, pairs };
|
|
@@ -250,6 +256,7 @@ var alpha = (color) => {
|
|
|
250
256
|
};
|
|
251
257
|
function backdropChain(glass, source) {
|
|
252
258
|
const chain = [];
|
|
259
|
+
if (glass.hasAttribute("data-lg-mirror-bare")) return chain;
|
|
253
260
|
for (let node = glass.parentElement; node; node = node.parentElement) {
|
|
254
261
|
if (node === source || source.contains(node)) continue;
|
|
255
262
|
const cs = getComputedStyle(node);
|
|
@@ -474,7 +481,7 @@ function bake(width, height, radius, shape, pad = 0, simple = false) {
|
|
|
474
481
|
const ch = Math.max(1, Math.ceil(H * density));
|
|
475
482
|
const lens = shape.kind === "lens";
|
|
476
483
|
const shift = bevelProfile(shape.bezel, shape.thickness, shape.ior);
|
|
477
|
-
const magnify = lens ? 1 - 1 / Math.max(
|
|
484
|
+
const magnify = lens ? 1 - 1 / Math.max(0.5, shape.zoom) : 0;
|
|
478
485
|
const direction = lens ? 1 : -1;
|
|
479
486
|
const dx = new Float32Array(cw * ch);
|
|
480
487
|
const dy = new Float32Array(cw * ch);
|
|
@@ -856,9 +863,9 @@ var GlassCard = React2.forwardRef(
|
|
|
856
863
|
"div",
|
|
857
864
|
{
|
|
858
865
|
ref,
|
|
859
|
-
className: ["lg-glass", "lg-card", `lg-card--${variant}`, className].filter(Boolean).join(" "),
|
|
866
|
+
className: ["lg-glass", "lg-glass--host", "lg-card", `lg-card--${variant}`, className].filter(Boolean).join(" "),
|
|
860
867
|
"data-liquid-glass": "",
|
|
861
|
-
style: { padding, borderRadius: radius, ...tint ? { "--lg-
|
|
868
|
+
style: { padding, borderRadius: radius, ...tint ? { "--lg-host-tint": tint } : {}, ...style },
|
|
862
869
|
...rest,
|
|
863
870
|
children
|
|
864
871
|
}
|
|
@@ -1064,8 +1071,8 @@ var GlassSheet = ({ open, onClose, intensity = 5, tint, children, "aria-label":
|
|
|
1064
1071
|
"aria-modal": "true",
|
|
1065
1072
|
"aria-label": ariaLabel,
|
|
1066
1073
|
tabIndex: -1,
|
|
1067
|
-
className: "lg-glass lg-sheet",
|
|
1068
|
-
style: tint ? { "--lg-
|
|
1074
|
+
className: "lg-glass lg-glass--host lg-sheet",
|
|
1075
|
+
style: tint ? { "--lg-host-tint": tint } : void 0,
|
|
1069
1076
|
children: [
|
|
1070
1077
|
/* @__PURE__ */ jsx4("div", { className: "lg-sheet__grabber-zone", "aria-hidden": "true", children: /* @__PURE__ */ jsx4("span", { className: "lg-sheet__grabber" }) }),
|
|
1071
1078
|
/* @__PURE__ */ jsx4("div", { className: "lg-sheet__content", children })
|
|
@@ -1251,7 +1258,7 @@ function useLensTrack(refs, options) {
|
|
|
1251
1258
|
bar.querySelector(`[data-lg-item="${next}"]`)?.focus();
|
|
1252
1259
|
};
|
|
1253
1260
|
const onTouchMove = (event) => {
|
|
1254
|
-
if (gesture
|
|
1261
|
+
if (gesture && event.cancelable) event.preventDefault();
|
|
1255
1262
|
};
|
|
1256
1263
|
const observer = new ResizeObserver(() => {
|
|
1257
1264
|
measure();
|
|
@@ -1309,13 +1316,7 @@ function LensTrack({
|
|
|
1309
1316
|
const row = useRef6(null);
|
|
1310
1317
|
const strength = Math.max(1, Math.min(10, intensity)) / 5;
|
|
1311
1318
|
useRefraction(glass, { kind: "surface", strength });
|
|
1312
|
-
useRefraction(
|
|
1313
|
-
lens,
|
|
1314
|
-
{ kind: "lens", strength, zoom: variant === "tabbar" ? 1.14 : 1.1 },
|
|
1315
|
-
true,
|
|
1316
|
-
bar,
|
|
1317
|
-
() => Boolean(bar.current?.hasAttribute("data-lifted"))
|
|
1318
|
-
);
|
|
1319
|
+
useRefraction(lens, { kind: "lens", strength, zoom: variant === "tabbar" ? 1.14 : 1.1 });
|
|
1319
1320
|
const tabbar = variant === "tabbar";
|
|
1320
1321
|
useLensTrack(
|
|
1321
1322
|
{ bar, glass, lens, tint, row },
|
|
@@ -1455,10 +1456,12 @@ var GlassSlider = React8.forwardRef(
|
|
|
1455
1456
|
const blockRef = useRef7(null);
|
|
1456
1457
|
useImperativeHandle4(forwardedRef, () => inputRef.current);
|
|
1457
1458
|
const strength = Math.max(1, Math.min(10, intensity)) / 5;
|
|
1459
|
+
const [mirrored, setMirrored] = React8.useState(false);
|
|
1460
|
+
useEffect5(() => setMirrored(!canRefractBackdrop()), []);
|
|
1458
1461
|
const progress = max > min ? clamp((Number(value) - min) / (max - min), 0, 1) : 0;
|
|
1459
1462
|
useRefraction(
|
|
1460
1463
|
thumbRef,
|
|
1461
|
-
{ kind: "lens", zoom: 1.95, strength, dispersion: 0.6 },
|
|
1464
|
+
{ kind: "lens", zoom: 1.95, bezel: 7, thickness: 16, strength, dispersion: 0.6 },
|
|
1462
1465
|
showThumb,
|
|
1463
1466
|
rootRef,
|
|
1464
1467
|
() => parseFloat(rootRef.current?.style.getPropertyValue("--lg-lift") || "0") > 0.01
|
|
@@ -1628,11 +1631,21 @@ var GlassSlider = React8.forwardRef(
|
|
|
1628
1631
|
}
|
|
1629
1632
|
);
|
|
1630
1633
|
}
|
|
1631
|
-
return /* @__PURE__ */ jsxs7(
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1634
|
+
return /* @__PURE__ */ jsxs7(
|
|
1635
|
+
"div",
|
|
1636
|
+
{
|
|
1637
|
+
ref: rootRef,
|
|
1638
|
+
className: ["lg-slider", className].filter(Boolean).join(" "),
|
|
1639
|
+
"data-liquid-glass": "",
|
|
1640
|
+
"data-mirror": mirrored ? "" : void 0,
|
|
1641
|
+
style: vars,
|
|
1642
|
+
children: [
|
|
1643
|
+
/* @__PURE__ */ jsx8("span", { className: "lg-slider__rail", "aria-hidden": "true", children: /* @__PURE__ */ jsx8("span", { className: "lg-slider__fill" }) }),
|
|
1644
|
+
/* @__PURE__ */ jsx8("span", { className: "lg-slider__thumb-slot", "aria-hidden": "true", children: /* @__PURE__ */ jsx8("span", { ref: thumbRef, className: "lg-glass lg-slider__thumb", "data-lg-mirror-bare": "", children: /* @__PURE__ */ jsx8("span", { ref: faceRef, className: "lg-slider__face" }) }) }),
|
|
1645
|
+
input
|
|
1646
|
+
]
|
|
1647
|
+
}
|
|
1648
|
+
);
|
|
1636
1649
|
}
|
|
1637
1650
|
);
|
|
1638
1651
|
GlassSlider.displayName = "GlassSlider";
|
|
@@ -1640,6 +1653,7 @@ GlassSlider.displayName = "GlassSlider";
|
|
|
1640
1653
|
// src/components/GlassSwitch/GlassSwitch.tsx
|
|
1641
1654
|
import React9, { useEffect as useEffect6, useImperativeHandle as useImperativeHandle5, useRef as useRef8, useState as useState3 } from "react";
|
|
1642
1655
|
import { jsx as jsx9, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1656
|
+
var SETTLE = springFrom(0.36, 0.68);
|
|
1643
1657
|
var REST = 0.655;
|
|
1644
1658
|
var TRAVEL = 22;
|
|
1645
1659
|
var GlassSwitch = React9.forwardRef(
|
|
@@ -1665,7 +1679,7 @@ var GlassSwitch = React9.forwardRef(
|
|
|
1665
1679
|
const sync = useRef8(null);
|
|
1666
1680
|
useRefraction(
|
|
1667
1681
|
thumbRef,
|
|
1668
|
-
{ kind: "lens", zoom: 1.
|
|
1682
|
+
{ kind: "lens", zoom: 1, dispersion: 0.5, strength: Math.max(1, Math.min(10, intensity)) / 5 },
|
|
1669
1683
|
true,
|
|
1670
1684
|
ref,
|
|
1671
1685
|
() => parseFloat(ref.current?.style.getPropertyValue("--lg-lift") || "0") > 0.01
|
|
@@ -1687,7 +1701,7 @@ var GlassSwitch = React9.forwardRef(
|
|
|
1687
1701
|
};
|
|
1688
1702
|
const position = createSpring(v.x, SPRINGS.snap, (value, velocity) => {
|
|
1689
1703
|
v.x = value;
|
|
1690
|
-
v.stretch = clamp(Math.abs(velocity) /
|
|
1704
|
+
v.stretch = clamp(Math.abs(velocity) / 140, 0, 0.05);
|
|
1691
1705
|
paint();
|
|
1692
1706
|
});
|
|
1693
1707
|
const lift = createSpring(0, SPRINGS.lift, (value) => {
|
|
@@ -1710,11 +1724,12 @@ var GlassSwitch = React9.forwardRef(
|
|
|
1710
1724
|
const drop = (delay) => {
|
|
1711
1725
|
clearTimeout(dropTimer);
|
|
1712
1726
|
dropTimer = window.setTimeout(() => {
|
|
1713
|
-
lift.tune(
|
|
1727
|
+
lift.tune(SETTLE);
|
|
1714
1728
|
lift.set(0);
|
|
1715
1729
|
}, delay);
|
|
1716
1730
|
};
|
|
1717
1731
|
const down = (event) => {
|
|
1732
|
+
el2.removeAttribute("data-keyboard");
|
|
1718
1733
|
if (!event.isPrimary || event.button !== 0 || latest.current.disabled) return;
|
|
1719
1734
|
clearTimeout(dropTimer);
|
|
1720
1735
|
gesture = { id: event.pointerId, x: event.clientX, from: latest.current.checked ? 1 : 0, moved: false, at: performance.now() };
|
|
@@ -1800,6 +1815,10 @@ var GlassSwitch = React9.forwardRef(
|
|
|
1800
1815
|
"data-liquid-glass": "",
|
|
1801
1816
|
style: tint ? { "--lg-switch-on": tint, ...style } : style,
|
|
1802
1817
|
...rest,
|
|
1818
|
+
onKeyDown: (event) => {
|
|
1819
|
+
event.currentTarget.setAttribute("data-keyboard", "");
|
|
1820
|
+
rest.onKeyDown?.(event);
|
|
1821
|
+
},
|
|
1803
1822
|
children: [
|
|
1804
1823
|
/* @__PURE__ */ jsx9("span", { ref: fillRef, className: "lg-switch__fill", "aria-hidden": "true" }),
|
|
1805
1824
|
/* @__PURE__ */ jsx9("span", { ref: thumbRef, className: "lg-glass lg-switch__thumb", "aria-hidden": "true", children: /* @__PURE__ */ jsx9("span", { ref: faceRef, className: "lg-switch__face" }) })
|