@zakisheriff/liquid-glass 0.2.5 → 0.2.7
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/README.md +2 -0
- package/dist/index.css +12 -4
- package/dist/index.css.map +1 -1
- package/dist/index.js +89 -42
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +89 -42
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1013,6 +1013,7 @@ var GlassSheet = ({ open, onClose, intensity = 5, tint, children, "aria-label":
|
|
|
1013
1013
|
});
|
|
1014
1014
|
let gesture = null;
|
|
1015
1015
|
const down = (event) => {
|
|
1016
|
+
if (event.defaultPrevented) return;
|
|
1016
1017
|
const target = event.target;
|
|
1017
1018
|
if (!target.closest(".lg-sheet__grabber-zone") && sheet.scrollTop > 0) return;
|
|
1018
1019
|
if (target.closest('input, textarea, button, a, [role="slider"], [role="switch"]')) return;
|
|
@@ -1115,11 +1116,13 @@ function useLensTrack(refs, options) {
|
|
|
1115
1116
|
let slot = 0;
|
|
1116
1117
|
let height = 0;
|
|
1117
1118
|
let pad = 0;
|
|
1119
|
+
let padY = 0;
|
|
1118
1120
|
let W = 0;
|
|
1119
1121
|
let H = 0;
|
|
1120
1122
|
const state = { x: 0, lift: 0, swell: 0, squash: 0 };
|
|
1121
1123
|
let current = latest.current.index;
|
|
1122
1124
|
let gesture = null;
|
|
1125
|
+
let dropTimer = 0;
|
|
1123
1126
|
let suppressClick = false;
|
|
1124
1127
|
const buttons = Array.from(bar.querySelectorAll("[data-lg-item]"));
|
|
1125
1128
|
let glyphs = [];
|
|
@@ -1131,37 +1134,41 @@ function useLensTrack(refs, options) {
|
|
|
1131
1134
|
const measure = () => {
|
|
1132
1135
|
const style = getComputedStyle(bar);
|
|
1133
1136
|
pad = parseFloat(style.paddingLeft) || 0;
|
|
1137
|
+
padY = parseFloat(style.paddingTop) || 0;
|
|
1134
1138
|
slot = (bar.clientWidth - pad - (parseFloat(style.paddingRight) || 0)) / latest.current.count;
|
|
1135
|
-
height = bar.clientHeight -
|
|
1139
|
+
height = bar.clientHeight - padY - (parseFloat(style.paddingBottom) || 0);
|
|
1136
1140
|
const { overhang, spread } = latest.current;
|
|
1137
1141
|
H = Math.round(bar.offsetHeight + overhang);
|
|
1138
1142
|
W = Math.round(Math.max(slot * (1 + spread), slot + H - height));
|
|
1139
1143
|
lens.style.width = `${W}px`;
|
|
1140
1144
|
lens.style.height = `${H}px`;
|
|
1141
1145
|
lens.style.left = `${pad + (slot - W) / 2}px`;
|
|
1142
|
-
lens.style.top = `${
|
|
1146
|
+
lens.style.top = `${padY + (height - H) / 2}px`;
|
|
1143
1147
|
select.style.width = `${slot}px`;
|
|
1148
|
+
select.style.left = `${pad}px`;
|
|
1144
1149
|
glyphs = buttons.flatMap(
|
|
1145
1150
|
(button) => Array.from(button.querySelectorAll(".lg-nav__label, .lg-nav__icon > .lg-symbol")).map((node) => ({
|
|
1146
1151
|
node,
|
|
1147
1152
|
x: button.offsetLeft + node.offsetLeft - pad,
|
|
1148
|
-
y: node.offsetTop
|
|
1153
|
+
y: node.offsetTop,
|
|
1149
1154
|
width: node.offsetWidth,
|
|
1155
|
+
height: node.offsetHeight,
|
|
1150
1156
|
label: node.classList.contains("lg-nav__label")
|
|
1151
1157
|
}))
|
|
1152
1158
|
);
|
|
1153
1159
|
};
|
|
1154
1160
|
const paint = () => {
|
|
1155
|
-
const {
|
|
1161
|
+
const { swell: swell2, squash } = state;
|
|
1162
|
+
const x2 = state.x;
|
|
1156
1163
|
const lift2 = clamp(state.lift, 0, 1.08);
|
|
1157
1164
|
if (!W || !H) return;
|
|
1158
1165
|
const kx = (slot + (W - slot) * lift2) / W * (1 + squash);
|
|
1159
1166
|
const ky = (height + (H - height) * lift2) / H * (1 - squash * 0.6);
|
|
1167
|
+
const grow = 1 + latest.current.swell / Math.max(bar.offsetWidth, 1) * swell2;
|
|
1160
1168
|
const transform = `translateX(${x2}px) scale(${kx}, ${ky})`;
|
|
1161
1169
|
lens.style.transform = transform;
|
|
1162
1170
|
select.style.transform = `translateX(${x2}px)`;
|
|
1163
1171
|
lens.style.opacity = String(clamp(lift2 * 4, 0, 1));
|
|
1164
|
-
const grow = 1 + latest.current.swell / Math.max(bar.offsetWidth, 1) * swell2;
|
|
1165
1172
|
bar.style.scale = `${grow}`;
|
|
1166
1173
|
lens.style.setProperty("--lg-lift", String(clamp(lift2, 0, 1)));
|
|
1167
1174
|
bar.style.setProperty("--lg-lift", String(clamp(lift2, 0, 1)));
|
|
@@ -1171,16 +1178,31 @@ function useLensTrack(refs, options) {
|
|
|
1171
1178
|
glyph.node.style.removeProperty("transform");
|
|
1172
1179
|
continue;
|
|
1173
1180
|
}
|
|
1174
|
-
const
|
|
1175
|
-
const
|
|
1176
|
-
const
|
|
1181
|
+
const zoom = latest.current.contentZoom ?? 1;
|
|
1182
|
+
const ry = H * ky / (2 * zoom);
|
|
1183
|
+
const rx = H * kx / (2 * zoom);
|
|
1184
|
+
const straight = Math.max(0, (W - H) * kx / (2 * zoom));
|
|
1185
|
+
const dy = clamp(Math.abs(glyph.y + glyph.height / 2 - height / 2) / ry, 0, 1);
|
|
1186
|
+
const half = straight + rx * Math.sqrt(1 - dy * dy);
|
|
1177
1187
|
const from = x2 + slot / 2 - half - glyph.x;
|
|
1178
1188
|
const to = x2 + slot / 2 + half - glyph.x;
|
|
1179
1189
|
const normal = "var(--lg-fg)";
|
|
1180
1190
|
const active2 = "var(--lg-track-active, var(--lg-accent))";
|
|
1181
|
-
glyph.node.style.setProperty("--lg-content-tint", `linear-gradient(90deg, ${normal} ${from}px, ${active2} ${from}px, ${active2} ${to}px, ${normal} ${to}px)`);
|
|
1182
1191
|
const coverage = clamp((Math.min(glyph.width, to) - Math.max(0, from)) / Math.max(1, glyph.width), 0, 1);
|
|
1183
|
-
|
|
1192
|
+
const scale = 1 + clamp(lift2, 0, 1) * coverage * (glyph.label ? 0.035 : 0.08);
|
|
1193
|
+
const cx = (x2 + slot / 2 - glyph.x - glyph.width / 2) / scale + glyph.width / 2;
|
|
1194
|
+
const cy = (height / 2 - glyph.y - glyph.height / 2) / scale + glyph.height / 2;
|
|
1195
|
+
const left = cx - straight / scale;
|
|
1196
|
+
const right = cx + straight / scale;
|
|
1197
|
+
const radiusX = rx / scale;
|
|
1198
|
+
const radiusY = ry / scale;
|
|
1199
|
+
glyph.node.style.setProperty("--lg-content-tint", [
|
|
1200
|
+
`radial-gradient(ellipse ${radiusX}px ${radiusY}px at ${left}px ${cy}px, ${active2} calc(100% - 0.5px), transparent 100%)`,
|
|
1201
|
+
`radial-gradient(ellipse ${radiusX}px ${radiusY}px at ${right}px ${cy}px, ${active2} calc(100% - 0.5px), transparent 100%)`,
|
|
1202
|
+
`linear-gradient(${active2}, ${active2}) ${left}px ${cy - radiusY}px / ${right - left}px ${radiusY * 2}px no-repeat`,
|
|
1203
|
+
`linear-gradient(${normal}, ${normal})`
|
|
1204
|
+
].join(", "));
|
|
1205
|
+
glyph.node.style.transform = `scale(${scale})`;
|
|
1184
1206
|
}
|
|
1185
1207
|
if (!gesture && lift2 < 0.02) delete bar.dataset.lifted;
|
|
1186
1208
|
};
|
|
@@ -1222,12 +1244,14 @@ function useLensTrack(refs, options) {
|
|
|
1222
1244
|
return target && bar.contains(target) ? Number(target.dataset.lgItem) : -1;
|
|
1223
1245
|
};
|
|
1224
1246
|
const onDown = (event) => {
|
|
1247
|
+
delete bar.dataset.keyboard;
|
|
1225
1248
|
if (!event.isPrimary || event.button !== 0 || gesture) return;
|
|
1226
1249
|
const index = itemAt(event);
|
|
1227
1250
|
if (index < 0) return;
|
|
1251
|
+
clearTimeout(dropTimer);
|
|
1228
1252
|
measure();
|
|
1229
1253
|
const box = bar.getBoundingClientRect();
|
|
1230
|
-
gesture = { id: event.pointerId, startX: event.clientX, anchor: index * slot, moved: false, box, hovered: index };
|
|
1254
|
+
gesture = { id: event.pointerId, startX: event.clientX, anchor: index * slot, moved: false, box, hovered: index, startedAt: performance.now() };
|
|
1231
1255
|
suppressClick = false;
|
|
1232
1256
|
bar.dataset.lifted = "";
|
|
1233
1257
|
preview(index);
|
|
@@ -1265,7 +1289,7 @@ function useLensTrack(refs, options) {
|
|
|
1265
1289
|
};
|
|
1266
1290
|
const finish = (event, commit) => {
|
|
1267
1291
|
if (event.pointerId !== gesture?.id) return;
|
|
1268
|
-
const { moved, box } = gesture;
|
|
1292
|
+
const { moved, box, startedAt } = gesture;
|
|
1269
1293
|
const at = moved ? position(event.clientX) : gesture.anchor;
|
|
1270
1294
|
const index = clamp(Math.round(at / slot), 0, latest.current.count - 1);
|
|
1271
1295
|
gesture = null;
|
|
@@ -1273,8 +1297,13 @@ function useLensTrack(refs, options) {
|
|
|
1273
1297
|
delete lens.dataset.pressed;
|
|
1274
1298
|
if (bar.hasPointerCapture?.(event.pointerId)) bar.releasePointerCapture(event.pointerId);
|
|
1275
1299
|
const inside = event.clientY >= box.top - 30 && event.clientY <= box.bottom + 30;
|
|
1276
|
-
|
|
1277
|
-
|
|
1300
|
+
const drop = () => {
|
|
1301
|
+
lift.tune(SPRINGS.settle);
|
|
1302
|
+
lift.set(0);
|
|
1303
|
+
};
|
|
1304
|
+
const hold = commit && !moved ? Math.max(0, 200 - (performance.now() - startedAt)) : 0;
|
|
1305
|
+
if (hold) dropTimer = window.setTimeout(drop, hold);
|
|
1306
|
+
else drop();
|
|
1278
1307
|
swell.tune(SPRINGS.release);
|
|
1279
1308
|
swell.set(0);
|
|
1280
1309
|
x.tune(SPRINGS.snap);
|
|
@@ -1290,7 +1319,12 @@ function useLensTrack(refs, options) {
|
|
|
1290
1319
|
const onUp = (event) => finish(event, true);
|
|
1291
1320
|
const onCancel = (event) => finish(event, false);
|
|
1292
1321
|
const onBlur = () => {
|
|
1293
|
-
|
|
1322
|
+
clearTimeout(dropTimer);
|
|
1323
|
+
if (!gesture) {
|
|
1324
|
+
lift.tune(SPRINGS.settle);
|
|
1325
|
+
lift.set(0);
|
|
1326
|
+
return;
|
|
1327
|
+
}
|
|
1294
1328
|
const id = gesture.id;
|
|
1295
1329
|
gesture = null;
|
|
1296
1330
|
preview();
|
|
@@ -1318,6 +1352,7 @@ function useLensTrack(refs, options) {
|
|
|
1318
1352
|
const onKey = (event) => {
|
|
1319
1353
|
const keys = ["ArrowLeft", "ArrowRight", "Home", "End"];
|
|
1320
1354
|
if (!keys.includes(event.key)) return;
|
|
1355
|
+
bar.dataset.keyboard = "";
|
|
1321
1356
|
event.preventDefault();
|
|
1322
1357
|
const { count, index } = latest.current;
|
|
1323
1358
|
const next = event.key === "Home" ? 0 : event.key === "End" ? count - 1 : (index + (event.key === "ArrowRight" ? 1 : count - 1)) % count;
|
|
@@ -1345,6 +1380,7 @@ function useLensTrack(refs, options) {
|
|
|
1345
1380
|
bar.addEventListener("touchmove", onTouchMove, { passive: false });
|
|
1346
1381
|
api.current = { setIndex: place };
|
|
1347
1382
|
return () => {
|
|
1383
|
+
clearTimeout(dropTimer);
|
|
1348
1384
|
api.current = null;
|
|
1349
1385
|
[x, lift, swell].forEach((s) => s.stop());
|
|
1350
1386
|
observer.disconnect();
|
|
@@ -1388,17 +1424,19 @@ function LensTrack({
|
|
|
1388
1424
|
const lens = useRef6(null);
|
|
1389
1425
|
const select = useRef6(null);
|
|
1390
1426
|
const strength = Math.max(1, Math.min(10, intensity)) / 5;
|
|
1391
|
-
useRefraction(glass, { kind: "surface", strength });
|
|
1392
|
-
useRefraction(lens, { kind: "lens", strength, zoom: variant === "tabbar" ? 1.14 : 1.1 });
|
|
1393
1427
|
const tabbar = variant === "tabbar";
|
|
1428
|
+
const zoom = tabbar ? 1.14 : 1.1;
|
|
1429
|
+
useRefraction(glass, { kind: "surface", strength });
|
|
1430
|
+
useRefraction(lens, { kind: "lens", strength: 0, zoom, dispersion: 0, bezel: 2 });
|
|
1394
1431
|
useLensTrack(
|
|
1395
1432
|
{ bar, glass, lens, select },
|
|
1396
1433
|
{
|
|
1397
1434
|
count: items.length,
|
|
1398
1435
|
index,
|
|
1399
1436
|
onSelect: (next) => onChange?.(next),
|
|
1400
|
-
overhang: tabbar ?
|
|
1401
|
-
spread: tabbar ? 0.
|
|
1437
|
+
overhang: tabbar ? 14 : 12,
|
|
1438
|
+
spread: tabbar ? 0.3 : 0.16,
|
|
1439
|
+
contentZoom: canRefractBackdrop() ? zoom : 1,
|
|
1402
1440
|
swell: tabbar ? 8 : 14
|
|
1403
1441
|
}
|
|
1404
1442
|
);
|
|
@@ -1552,7 +1590,8 @@ var GlassSlider = React8.forwardRef(
|
|
|
1552
1590
|
const down = (event) => {
|
|
1553
1591
|
if (input2.disabled || !event.isPrimary || event.button !== 0 || drag) return;
|
|
1554
1592
|
event.preventDefault();
|
|
1555
|
-
|
|
1593
|
+
delete root.dataset.keyboard;
|
|
1594
|
+
if (event.pointerType !== "touch") input2.focus({ preventScroll: true });
|
|
1556
1595
|
const box = root.getBoundingClientRect();
|
|
1557
1596
|
const inset = showThumb ? 19 * box.width / root.offsetWidth : 0;
|
|
1558
1597
|
const current = max > min ? clamp((input2.valueAsNumber - min) / (max - min), 0, 1) : 0;
|
|
@@ -1560,7 +1599,7 @@ var GlassSlider = React8.forwardRef(
|
|
|
1560
1599
|
const offset = showThumb && Math.abs(event.clientX - center) <= inset ? event.clientX - center : 0;
|
|
1561
1600
|
drag = { id: event.pointerId, left: box.left, width: box.width, offset };
|
|
1562
1601
|
root.dataset.dragging = "";
|
|
1563
|
-
|
|
1602
|
+
root.setPointerCapture(event.pointerId);
|
|
1564
1603
|
update(event.clientX);
|
|
1565
1604
|
};
|
|
1566
1605
|
const move = (event) => {
|
|
@@ -1573,26 +1612,26 @@ var GlassSlider = React8.forwardRef(
|
|
|
1573
1612
|
const id = drag.id;
|
|
1574
1613
|
drag = null;
|
|
1575
1614
|
delete root.dataset.dragging;
|
|
1576
|
-
if (
|
|
1615
|
+
if (root.hasPointerCapture(id)) root.releasePointerCapture(id);
|
|
1577
1616
|
};
|
|
1578
1617
|
const up = (event) => {
|
|
1579
1618
|
if (event.pointerId !== drag?.id) return;
|
|
1580
1619
|
update(event.clientX);
|
|
1581
1620
|
release();
|
|
1582
1621
|
};
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1622
|
+
root.addEventListener("pointerdown", down);
|
|
1623
|
+
root.addEventListener("pointermove", move);
|
|
1624
|
+
root.addEventListener("pointerup", up);
|
|
1625
|
+
root.addEventListener("pointercancel", release);
|
|
1626
|
+
root.addEventListener("lostpointercapture", release);
|
|
1588
1627
|
window.addEventListener("blur", release);
|
|
1589
1628
|
return () => {
|
|
1590
1629
|
release();
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1630
|
+
root.removeEventListener("pointerdown", down);
|
|
1631
|
+
root.removeEventListener("pointermove", move);
|
|
1632
|
+
root.removeEventListener("pointerup", up);
|
|
1633
|
+
root.removeEventListener("pointercancel", release);
|
|
1634
|
+
root.removeEventListener("lostpointercapture", release);
|
|
1596
1635
|
window.removeEventListener("blur", release);
|
|
1597
1636
|
};
|
|
1598
1637
|
}, [min, max, step2, showThumb]);
|
|
@@ -1634,7 +1673,7 @@ var GlassSlider = React8.forwardRef(
|
|
|
1634
1673
|
let lastX = 0;
|
|
1635
1674
|
let lastT = 0;
|
|
1636
1675
|
const down = (event) => {
|
|
1637
|
-
if (input2.disabled) return;
|
|
1676
|
+
if (input2.disabled || !event.isPrimary || event.button !== 0) return;
|
|
1638
1677
|
lastX = event.clientX;
|
|
1639
1678
|
lastT = event.timeStamp;
|
|
1640
1679
|
root.dataset.lifted = "";
|
|
@@ -1658,20 +1697,20 @@ var GlassSlider = React8.forwardRef(
|
|
|
1658
1697
|
stretch.tune(SPRINGS.release);
|
|
1659
1698
|
stretch.set(0);
|
|
1660
1699
|
};
|
|
1661
|
-
|
|
1700
|
+
root.addEventListener("pointerdown", down);
|
|
1662
1701
|
window.addEventListener("pointermove", move);
|
|
1663
1702
|
window.addEventListener("pointerup", up);
|
|
1664
1703
|
window.addEventListener("pointercancel", up);
|
|
1665
|
-
|
|
1704
|
+
root.addEventListener("lostpointercapture", up);
|
|
1666
1705
|
window.addEventListener("blur", up);
|
|
1667
1706
|
return () => {
|
|
1668
1707
|
lift.stop();
|
|
1669
1708
|
stretch.stop();
|
|
1670
|
-
|
|
1709
|
+
root.removeEventListener("pointerdown", down);
|
|
1671
1710
|
window.removeEventListener("pointermove", move);
|
|
1672
1711
|
window.removeEventListener("pointerup", up);
|
|
1673
1712
|
window.removeEventListener("pointercancel", up);
|
|
1674
|
-
|
|
1713
|
+
root.removeEventListener("lostpointercapture", up);
|
|
1675
1714
|
window.removeEventListener("blur", up);
|
|
1676
1715
|
delete root.dataset.lifted;
|
|
1677
1716
|
};
|
|
@@ -1680,6 +1719,7 @@ var GlassSlider = React8.forwardRef(
|
|
|
1680
1719
|
if (showThumb) return;
|
|
1681
1720
|
const input2 = inputRef.current;
|
|
1682
1721
|
const block = blockRef.current;
|
|
1722
|
+
const root = rootRef.current;
|
|
1683
1723
|
const v = { swell: 0, over: 0 };
|
|
1684
1724
|
const paint = () => {
|
|
1685
1725
|
const w = block.offsetWidth || 1;
|
|
@@ -1698,7 +1738,7 @@ var GlassSlider = React8.forwardRef(
|
|
|
1698
1738
|
});
|
|
1699
1739
|
let active2 = null;
|
|
1700
1740
|
const down = (event) => {
|
|
1701
|
-
if (input2.disabled) return;
|
|
1741
|
+
if (input2.disabled || !event.isPrimary || event.button !== 0) return;
|
|
1702
1742
|
active2 = { id: event.pointerId, box: block.getBoundingClientRect() };
|
|
1703
1743
|
swell.tune(SPRINGS.press);
|
|
1704
1744
|
swell.set(1);
|
|
@@ -1711,22 +1751,29 @@ var GlassSlider = React8.forwardRef(
|
|
|
1711
1751
|
over.tune(SPRINGS.drag);
|
|
1712
1752
|
over.set(rubberband(past, 26, 0.6));
|
|
1713
1753
|
};
|
|
1714
|
-
const
|
|
1715
|
-
if (
|
|
1754
|
+
const reset = () => {
|
|
1755
|
+
if (!active2) return;
|
|
1716
1756
|
active2 = null;
|
|
1717
1757
|
swell.tune(SPRINGS.release);
|
|
1718
1758
|
swell.set(0);
|
|
1719
1759
|
over.tune(SPRINGS.release);
|
|
1720
1760
|
over.set(0);
|
|
1721
1761
|
};
|
|
1722
|
-
|
|
1762
|
+
const up = (event) => {
|
|
1763
|
+
if (event.pointerId === active2?.id) reset();
|
|
1764
|
+
};
|
|
1765
|
+
root.addEventListener("pointerdown", down);
|
|
1766
|
+
root.addEventListener("lostpointercapture", reset);
|
|
1767
|
+
window.addEventListener("blur", reset);
|
|
1723
1768
|
window.addEventListener("pointermove", move);
|
|
1724
1769
|
window.addEventListener("pointerup", up);
|
|
1725
1770
|
window.addEventListener("pointercancel", up);
|
|
1726
1771
|
return () => {
|
|
1727
1772
|
swell.stop();
|
|
1728
1773
|
over.stop();
|
|
1729
|
-
|
|
1774
|
+
root.removeEventListener("pointerdown", down);
|
|
1775
|
+
root.removeEventListener("lostpointercapture", reset);
|
|
1776
|
+
window.removeEventListener("blur", reset);
|
|
1730
1777
|
window.removeEventListener("pointermove", move);
|
|
1731
1778
|
window.removeEventListener("pointerup", up);
|
|
1732
1779
|
window.removeEventListener("pointercancel", up);
|