@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/README.md +46 -7
- package/dist/index.css +68 -13
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +11 -6
- package/dist/index.d.ts +11 -6
- package/dist/index.js +116 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +116 -50
- 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,18 +256,19 @@ 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);
|
|
256
263
|
const image = cs.backgroundImage !== "none";
|
|
257
264
|
const a = alpha(cs.backgroundColor);
|
|
258
265
|
if (image || a > 0) chain.unshift(node);
|
|
259
|
-
if (image || a >= 1) break;
|
|
266
|
+
if (image || a >= 1 || node.classList.contains("lg-glass")) break;
|
|
260
267
|
}
|
|
261
268
|
return chain;
|
|
262
269
|
}
|
|
263
270
|
var BACKGROUND = ["background-color", "background-image", "background-size", "background-position", "background-repeat", "border-radius"];
|
|
264
|
-
function mirrorBackdrop(glass, source,
|
|
271
|
+
function mirrorBackdrop(glass, source, padding, zoom, active2 = () => true) {
|
|
265
272
|
const layer = document.createElement("div");
|
|
266
273
|
layer.className = "lg-mirror";
|
|
267
274
|
layer.setAttribute("aria-hidden", "true");
|
|
@@ -270,6 +277,9 @@ function mirrorBackdrop(glass, source, filter, padding) {
|
|
|
270
277
|
const viewport = document.createElement("div");
|
|
271
278
|
viewport.className = "lg-mirror__viewport";
|
|
272
279
|
layer.append(viewport);
|
|
280
|
+
const zoomer = document.createElement("div");
|
|
281
|
+
zoomer.className = "lg-mirror__zoom";
|
|
282
|
+
viewport.append(zoomer);
|
|
273
283
|
let copy = clone(source);
|
|
274
284
|
let under = [];
|
|
275
285
|
const buildUnder = () => {
|
|
@@ -284,14 +294,15 @@ function mirrorBackdrop(glass, source, filter, padding) {
|
|
|
284
294
|
div.style.transformOrigin = "0 0";
|
|
285
295
|
return { original, copy: div, placed: "" };
|
|
286
296
|
});
|
|
287
|
-
|
|
297
|
+
zoomer.prepend(...under.map((u) => u.copy));
|
|
288
298
|
};
|
|
289
|
-
|
|
299
|
+
zoomer.append(copy.root);
|
|
290
300
|
buildUnder();
|
|
291
301
|
let stopped = false;
|
|
292
302
|
let frame2 = 0;
|
|
293
303
|
let visible = true;
|
|
294
304
|
let placed = "";
|
|
305
|
+
let shown = true;
|
|
295
306
|
let pad = 0;
|
|
296
307
|
const place = (from, g, sgx, sgy) => {
|
|
297
308
|
const sw = from.offsetWidth;
|
|
@@ -362,15 +373,21 @@ function mirrorBackdrop(glass, source, filter, padding) {
|
|
|
362
373
|
}
|
|
363
374
|
}
|
|
364
375
|
};
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
376
|
+
let zoomed = "";
|
|
377
|
+
const applyZoom = () => {
|
|
378
|
+
const value = `scale(${zoom()})`;
|
|
379
|
+
if (value !== zoomed) zoomer.style.transform = zoomed = value;
|
|
368
380
|
};
|
|
369
381
|
const tick = () => {
|
|
370
382
|
frame2 = 0;
|
|
371
383
|
if (stopped) return;
|
|
372
|
-
|
|
373
|
-
|
|
384
|
+
const on = visible && !document.hidden && active2();
|
|
385
|
+
if (on !== shown) {
|
|
386
|
+
shown = on;
|
|
387
|
+
layer.style.visibility = on ? "" : "hidden";
|
|
388
|
+
}
|
|
389
|
+
if (on) {
|
|
390
|
+
applyZoom();
|
|
374
391
|
sync();
|
|
375
392
|
align();
|
|
376
393
|
}
|
|
@@ -455,7 +472,7 @@ function bevelProfile(bezel, thickness, ior) {
|
|
|
455
472
|
return a + (b - a) * (f - i);
|
|
456
473
|
};
|
|
457
474
|
}
|
|
458
|
-
function bake(width, height, radius, shape, pad = 0) {
|
|
475
|
+
function bake(width, height, radius, shape, pad = 0, simple = false) {
|
|
459
476
|
const W = width + pad * 2;
|
|
460
477
|
const H = height + pad * 2;
|
|
461
478
|
let density = Math.min(typeof devicePixelRatio === "number" ? devicePixelRatio : 1, 2);
|
|
@@ -464,13 +481,14 @@ function bake(width, height, radius, shape, pad = 0) {
|
|
|
464
481
|
const ch = Math.max(1, Math.ceil(H * density));
|
|
465
482
|
const lens = shape.kind === "lens";
|
|
466
483
|
const shift = bevelProfile(shape.bezel, shape.thickness, shape.ior);
|
|
467
|
-
const magnify = lens ? 1 - 1 / Math.max(
|
|
484
|
+
const magnify = lens ? 1 - 1 / Math.max(0.5, shape.zoom) : 0;
|
|
468
485
|
const direction = lens ? 1 : -1;
|
|
469
486
|
const dx = new Float32Array(cw * ch);
|
|
470
487
|
const dy = new Float32Array(cw * ch);
|
|
471
488
|
const rimA = new Float32Array(cw * ch);
|
|
472
489
|
const rimHue = new Float32Array(cw * ch);
|
|
473
490
|
const inside = new Float32Array(cw * ch);
|
|
491
|
+
const depth = new Float32Array(cw * ch);
|
|
474
492
|
let max = 1e-4;
|
|
475
493
|
const hw = width / 2;
|
|
476
494
|
const hh = height / 2;
|
|
@@ -499,20 +517,26 @@ function bake(width, height, radius, shape, pad = 0) {
|
|
|
499
517
|
}
|
|
500
518
|
const i = y * cw + x;
|
|
501
519
|
const s = shift(d) * shape.strength * direction;
|
|
502
|
-
|
|
503
|
-
|
|
520
|
+
let vx = nx * s;
|
|
521
|
+
let vy = ny * s;
|
|
522
|
+
if (simple && magnify) {
|
|
523
|
+
vx -= px * magnify;
|
|
524
|
+
vy -= py * magnify;
|
|
525
|
+
}
|
|
504
526
|
dx[i] = vx;
|
|
505
527
|
dy[i] = vy;
|
|
506
528
|
const m = Math.max(Math.abs(vx), Math.abs(vy));
|
|
507
529
|
if (m > max) max = m;
|
|
508
530
|
inside[i] = clamp(d / px1 + 0.5, 0, 1);
|
|
531
|
+
const t = clamp(d / (shape.bezel * 0.9), 0, 1);
|
|
532
|
+
depth[i] = t * t * (3 - 2 * t);
|
|
509
533
|
if (d >= -px1) {
|
|
510
534
|
const facing = -(nx + ny) * Math.SQRT1_2;
|
|
511
535
|
const light = 0.22 + 0.78 * Math.abs(facing) ** 2.2 * (facing > 0 ? 1 : 0.62);
|
|
512
536
|
const line = Math.exp(-(((d - 0.55) / 0.55) ** 2));
|
|
513
|
-
const
|
|
537
|
+
const inner2 = Math.exp(-((d / (shape.bezel * 0.55)) ** 2)) * 0.14;
|
|
514
538
|
const edgeAA = clamp(d / px1 + 1, 0, 1);
|
|
515
|
-
rimA[i] = clamp((line * (lens ? 0.95 : 0.7) +
|
|
539
|
+
rimA[i] = clamp((line * (lens ? 0.95 : 0.7) + inner2) * light * edgeAA, 0, 1);
|
|
516
540
|
rimHue[i] = Math.atan2(ny, nx);
|
|
517
541
|
}
|
|
518
542
|
}
|
|
@@ -533,7 +557,7 @@ function bake(width, height, radius, shape, pad = 0) {
|
|
|
533
557
|
const map = canvas.toDataURL();
|
|
534
558
|
const reach = Math.max(W, H) / 2;
|
|
535
559
|
let zoomMap = "";
|
|
536
|
-
if (magnify) {
|
|
560
|
+
if (magnify && !simple) {
|
|
537
561
|
const ramp = ctx.createImageData(cw, ch);
|
|
538
562
|
for (let y = 0; y < ch; y++) {
|
|
539
563
|
for (let x = 0; x < cw; x++) {
|
|
@@ -577,15 +601,18 @@ function bake(width, height, radius, shape, pad = 0) {
|
|
|
577
601
|
}
|
|
578
602
|
ctx.putImageData(shapeMask, 0, 0);
|
|
579
603
|
const mask = canvas.toDataURL();
|
|
604
|
+
for (let i = 0; i < cw * ch; i++) shapeMask.data[i * 4 + 3] = Math.round(depth[i] * 255);
|
|
605
|
+
ctx.putImageData(shapeMask, 0, 0);
|
|
606
|
+
const inner = canvas.toDataURL();
|
|
580
607
|
const id = `lg-refract-${++counter}`;
|
|
581
608
|
const box = { x: 0, y: 0, width: W, height: H };
|
|
582
609
|
const filter = el("filter", {
|
|
583
610
|
id,
|
|
584
611
|
// Generous region: the rim samples content from beyond the glass edge.
|
|
585
|
-
x: -0.
|
|
586
|
-
y: -0.
|
|
587
|
-
width:
|
|
588
|
-
height:
|
|
612
|
+
x: -0.25,
|
|
613
|
+
y: -0.25,
|
|
614
|
+
width: 1.5,
|
|
615
|
+
height: 1.5,
|
|
589
616
|
"color-interpolation-filters": "sRGB"
|
|
590
617
|
});
|
|
591
618
|
filter.append(el("feImage", { href: map, ...box, preserveAspectRatio: "none", result: "field" }));
|
|
@@ -605,7 +632,7 @@ function bake(width, height, radius, shape, pad = 0) {
|
|
|
605
632
|
source = "magnified";
|
|
606
633
|
}
|
|
607
634
|
const scale = max * 2;
|
|
608
|
-
if (shape.dispersion > 0) {
|
|
635
|
+
if (shape.dispersion > 0 && !simple) {
|
|
609
636
|
const spread = 0.16 * shape.dispersion;
|
|
610
637
|
const channels = [
|
|
611
638
|
["r", 1 + spread, "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0"],
|
|
@@ -646,7 +673,7 @@ function bake(width, height, radius, shape, pad = 0) {
|
|
|
646
673
|
el("feComposite", { in: "bent", in2: "shape", operator: "in" })
|
|
647
674
|
);
|
|
648
675
|
container().append(filter);
|
|
649
|
-
return { filter: `url(#${id})`, rim: `url("${rim}")` };
|
|
676
|
+
return { filter: `url(#${id})`, rim: `url("${rim}")`, inner: `url("${inner}")` };
|
|
650
677
|
}
|
|
651
678
|
function resolve(shape, width, height) {
|
|
652
679
|
const kind = shape.kind ?? "surface";
|
|
@@ -662,15 +689,15 @@ function resolve(shape, width, height) {
|
|
|
662
689
|
strength: shape.strength ?? 1
|
|
663
690
|
};
|
|
664
691
|
}
|
|
665
|
-
function glassFor(width, height, radius, shape = {}, pad = 0) {
|
|
692
|
+
function glassFor(width, height, radius, shape = {}, pad = 0, simple = false) {
|
|
666
693
|
const w = Math.round(width);
|
|
667
694
|
const h = Math.round(height);
|
|
668
695
|
const r = Math.min(w / 2, h / 2, Math.max(0, radius));
|
|
669
696
|
const full = resolve(shape, w, h);
|
|
670
|
-
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("|");
|
|
697
|
+
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("|");
|
|
671
698
|
let baked = cache.get(key);
|
|
672
699
|
if (!baked) {
|
|
673
|
-
baked = bake(w, h, r, full, pad);
|
|
700
|
+
baked = bake(w, h, r, full, pad, simple);
|
|
674
701
|
cache.set(key, baked);
|
|
675
702
|
}
|
|
676
703
|
return baked;
|
|
@@ -689,7 +716,7 @@ function cornerRadius(element, width, height) {
|
|
|
689
716
|
if (!Number.isFinite(n)) return 0;
|
|
690
717
|
return value.endsWith("%") ? Math.min(width, height) * n / 100 : n;
|
|
691
718
|
}
|
|
692
|
-
function useRefraction(ref, shape = {}, enabled = true, mirror) {
|
|
719
|
+
function useRefraction(ref, shape = {}, enabled = true, mirror, mirrorActive) {
|
|
693
720
|
const signature = JSON.stringify(shape);
|
|
694
721
|
useEffect2(() => {
|
|
695
722
|
const element = ref.current;
|
|
@@ -698,6 +725,7 @@ function useRefraction(ref, shape = {}, enabled = true, mirror) {
|
|
|
698
725
|
let cancel;
|
|
699
726
|
let filter = "";
|
|
700
727
|
let pad = 0;
|
|
728
|
+
let zoom = 1;
|
|
701
729
|
const fit = () => {
|
|
702
730
|
const width = element.offsetWidth;
|
|
703
731
|
const height = element.offsetHeight;
|
|
@@ -705,7 +733,11 @@ function useRefraction(ref, shape = {}, enabled = true, mirror) {
|
|
|
705
733
|
const radius = cornerRadius(element, width, height);
|
|
706
734
|
const baked = glassFor(width, height, radius, shape);
|
|
707
735
|
filter = baked.filter;
|
|
708
|
-
if (!live && mirror?.current)
|
|
736
|
+
if (!live && mirror?.current) {
|
|
737
|
+
pad = Math.ceil(Math.min(width, height) * 0.45 + 6);
|
|
738
|
+
zoom = resolve(shape, width, height).zoom;
|
|
739
|
+
element.style.setProperty("--lg-inner-mask", baked.inner);
|
|
740
|
+
}
|
|
709
741
|
if (live) element.style.setProperty("--lg-filter", baked.filter);
|
|
710
742
|
element.style.setProperty("--lg-rim", baked.rim);
|
|
711
743
|
};
|
|
@@ -716,7 +748,7 @@ function useRefraction(ref, shape = {}, enabled = true, mirror) {
|
|
|
716
748
|
observer.observe(element);
|
|
717
749
|
fit();
|
|
718
750
|
const source = mirror?.current;
|
|
719
|
-
const unmirror = !live && source ? mirrorBackdrop(element, source, () =>
|
|
751
|
+
const unmirror = !live && source ? mirrorBackdrop(element, source, () => pad, () => zoom, mirrorActive) : void 0;
|
|
720
752
|
return () => {
|
|
721
753
|
cancel?.();
|
|
722
754
|
unmirror?.();
|
|
@@ -764,7 +796,8 @@ var GlassButton = React.forwardRef(
|
|
|
764
796
|
shimmer = true,
|
|
765
797
|
thickness = 1,
|
|
766
798
|
size = "md",
|
|
767
|
-
variant = "
|
|
799
|
+
variant = "glass",
|
|
800
|
+
destructive = false,
|
|
768
801
|
icon,
|
|
769
802
|
className,
|
|
770
803
|
style,
|
|
@@ -784,7 +817,8 @@ var GlassButton = React.forwardRef(
|
|
|
784
817
|
bezel: Math.min(height * 0.36, 22) * Math.max(0.5, thickness)
|
|
785
818
|
});
|
|
786
819
|
const iconOnly = icon != null && (children == null || children === false);
|
|
787
|
-
const
|
|
820
|
+
const red = destructive || variant === "destructive";
|
|
821
|
+
const kind = variant === "ghost" ? "clear" : variant === "default" || variant === "destructive" ? "glass" : variant;
|
|
788
822
|
const classes = ["lg-glass", "lg-button", `lg-button--${size}`, `lg-button--${kind}`, className].filter(Boolean).join(" ");
|
|
789
823
|
return /* @__PURE__ */ jsxs(
|
|
790
824
|
"button",
|
|
@@ -795,6 +829,7 @@ var GlassButton = React.forwardRef(
|
|
|
795
829
|
"data-liquid-glass": "",
|
|
796
830
|
"data-icon-only": iconOnly ? "" : void 0,
|
|
797
831
|
"data-shimmer": shimmer ? "" : void 0,
|
|
832
|
+
"data-destructive": red ? "" : void 0,
|
|
798
833
|
style: tint ? { "--lg-tint": tint, ...style } : style,
|
|
799
834
|
onPointerDown: (event) => {
|
|
800
835
|
if (!rest.disabled) haptic();
|
|
@@ -828,9 +863,9 @@ var GlassCard = React2.forwardRef(
|
|
|
828
863
|
"div",
|
|
829
864
|
{
|
|
830
865
|
ref,
|
|
831
|
-
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(" "),
|
|
832
867
|
"data-liquid-glass": "",
|
|
833
|
-
style: { padding, borderRadius: radius, ...tint ? { "--lg-
|
|
868
|
+
style: { padding, borderRadius: radius, ...tint ? { "--lg-host-tint": tint } : {}, ...style },
|
|
834
869
|
...rest,
|
|
835
870
|
children
|
|
836
871
|
}
|
|
@@ -1036,8 +1071,8 @@ var GlassSheet = ({ open, onClose, intensity = 5, tint, children, "aria-label":
|
|
|
1036
1071
|
"aria-modal": "true",
|
|
1037
1072
|
"aria-label": ariaLabel,
|
|
1038
1073
|
tabIndex: -1,
|
|
1039
|
-
className: "lg-glass lg-sheet",
|
|
1040
|
-
style: tint ? { "--lg-
|
|
1074
|
+
className: "lg-glass lg-glass--host lg-sheet",
|
|
1075
|
+
style: tint ? { "--lg-host-tint": tint } : void 0,
|
|
1041
1076
|
children: [
|
|
1042
1077
|
/* @__PURE__ */ jsx4("div", { className: "lg-sheet__grabber-zone", "aria-hidden": "true", children: /* @__PURE__ */ jsx4("span", { className: "lg-sheet__grabber" }) }),
|
|
1043
1078
|
/* @__PURE__ */ jsx4("div", { className: "lg-sheet__content", children })
|
|
@@ -1124,8 +1159,9 @@ function useLensTrack(refs, options) {
|
|
|
1124
1159
|
if (!gesture) return 0;
|
|
1125
1160
|
const raw = gesture.anchor + clientX - gesture.startX;
|
|
1126
1161
|
const max = slot * (latest.current.count - 1);
|
|
1127
|
-
|
|
1128
|
-
if (raw
|
|
1162
|
+
const give = Math.min(14, slot * 0.12);
|
|
1163
|
+
if (raw < 0) return rubberband(raw, give, 0.55);
|
|
1164
|
+
if (raw > max) return max + rubberband(raw - max, give, 0.55);
|
|
1129
1165
|
return raw;
|
|
1130
1166
|
};
|
|
1131
1167
|
const light = (clientX, box) => {
|
|
@@ -1222,7 +1258,7 @@ function useLensTrack(refs, options) {
|
|
|
1222
1258
|
bar.querySelector(`[data-lg-item="${next}"]`)?.focus();
|
|
1223
1259
|
};
|
|
1224
1260
|
const onTouchMove = (event) => {
|
|
1225
|
-
if (gesture
|
|
1261
|
+
if (gesture && event.cancelable) event.preventDefault();
|
|
1226
1262
|
};
|
|
1227
1263
|
const observer = new ResizeObserver(() => {
|
|
1228
1264
|
measure();
|
|
@@ -1280,7 +1316,7 @@ function LensTrack({
|
|
|
1280
1316
|
const row = useRef6(null);
|
|
1281
1317
|
const strength = Math.max(1, Math.min(10, intensity)) / 5;
|
|
1282
1318
|
useRefraction(glass, { kind: "surface", strength });
|
|
1283
|
-
useRefraction(lens, { kind: "lens", strength, zoom: variant === "tabbar" ? 1.14 : 1.1 }
|
|
1319
|
+
useRefraction(lens, { kind: "lens", strength, zoom: variant === "tabbar" ? 1.14 : 1.1 });
|
|
1284
1320
|
const tabbar = variant === "tabbar";
|
|
1285
1321
|
useLensTrack(
|
|
1286
1322
|
{ bar, glass, lens, tint, row },
|
|
@@ -1288,9 +1324,9 @@ function LensTrack({
|
|
|
1288
1324
|
count: items.length,
|
|
1289
1325
|
index,
|
|
1290
1326
|
onSelect: (next) => onChange?.(next),
|
|
1291
|
-
overhang: tabbar ? 8 :
|
|
1292
|
-
spread: tabbar ? 0.
|
|
1293
|
-
swell: tabbar ?
|
|
1327
|
+
overhang: tabbar ? 8 : 12,
|
|
1328
|
+
spread: tabbar ? 0.18 : 0.16,
|
|
1329
|
+
swell: tabbar ? 8 : 14
|
|
1294
1330
|
}
|
|
1295
1331
|
);
|
|
1296
1332
|
return /* @__PURE__ */ jsxs4(
|
|
@@ -1420,8 +1456,16 @@ var GlassSlider = React8.forwardRef(
|
|
|
1420
1456
|
const blockRef = useRef7(null);
|
|
1421
1457
|
useImperativeHandle4(forwardedRef, () => inputRef.current);
|
|
1422
1458
|
const strength = Math.max(1, Math.min(10, intensity)) / 5;
|
|
1459
|
+
const [mirrored, setMirrored] = React8.useState(false);
|
|
1460
|
+
useEffect5(() => setMirrored(!canRefractBackdrop()), []);
|
|
1423
1461
|
const progress = max > min ? clamp((Number(value) - min) / (max - min), 0, 1) : 0;
|
|
1424
|
-
useRefraction(
|
|
1462
|
+
useRefraction(
|
|
1463
|
+
thumbRef,
|
|
1464
|
+
{ kind: "lens", zoom: 1.95, bezel: 7, thickness: 16, strength, dispersion: 0.6 },
|
|
1465
|
+
showThumb,
|
|
1466
|
+
rootRef,
|
|
1467
|
+
() => parseFloat(rootRef.current?.style.getPropertyValue("--lg-lift") || "0") > 0.01
|
|
1468
|
+
);
|
|
1425
1469
|
useRefraction(blockRef, { kind: "surface", strength }, !showThumb);
|
|
1426
1470
|
useEffect5(() => {
|
|
1427
1471
|
if (!showThumb) return;
|
|
@@ -1587,11 +1631,21 @@ var GlassSlider = React8.forwardRef(
|
|
|
1587
1631
|
}
|
|
1588
1632
|
);
|
|
1589
1633
|
}
|
|
1590
|
-
return /* @__PURE__ */ jsxs7(
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
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
|
+
);
|
|
1595
1649
|
}
|
|
1596
1650
|
);
|
|
1597
1651
|
GlassSlider.displayName = "GlassSlider";
|
|
@@ -1599,6 +1653,7 @@ GlassSlider.displayName = "GlassSlider";
|
|
|
1599
1653
|
// src/components/GlassSwitch/GlassSwitch.tsx
|
|
1600
1654
|
import React9, { useEffect as useEffect6, useImperativeHandle as useImperativeHandle5, useRef as useRef8, useState as useState3 } from "react";
|
|
1601
1655
|
import { jsx as jsx9, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1656
|
+
var SETTLE = springFrom(0.36, 0.68);
|
|
1602
1657
|
var REST = 0.655;
|
|
1603
1658
|
var TRAVEL = 22;
|
|
1604
1659
|
var GlassSwitch = React9.forwardRef(
|
|
@@ -1622,7 +1677,13 @@ var GlassSwitch = React9.forwardRef(
|
|
|
1622
1677
|
}
|
|
1623
1678
|
};
|
|
1624
1679
|
const sync = useRef8(null);
|
|
1625
|
-
useRefraction(
|
|
1680
|
+
useRefraction(
|
|
1681
|
+
thumbRef,
|
|
1682
|
+
{ kind: "lens", zoom: 1, dispersion: 0.5, strength: Math.max(1, Math.min(10, intensity)) / 5 },
|
|
1683
|
+
true,
|
|
1684
|
+
ref,
|
|
1685
|
+
() => parseFloat(ref.current?.style.getPropertyValue("--lg-lift") || "0") > 0.01
|
|
1686
|
+
);
|
|
1626
1687
|
useEffect6(() => {
|
|
1627
1688
|
const el2 = ref.current;
|
|
1628
1689
|
const thumb = thumbRef.current;
|
|
@@ -1640,7 +1701,7 @@ var GlassSwitch = React9.forwardRef(
|
|
|
1640
1701
|
};
|
|
1641
1702
|
const position = createSpring(v.x, SPRINGS.snap, (value, velocity) => {
|
|
1642
1703
|
v.x = value;
|
|
1643
|
-
v.stretch = clamp(Math.abs(velocity) /
|
|
1704
|
+
v.stretch = clamp(Math.abs(velocity) / 140, 0, 0.05);
|
|
1644
1705
|
paint();
|
|
1645
1706
|
});
|
|
1646
1707
|
const lift = createSpring(0, SPRINGS.lift, (value) => {
|
|
@@ -1663,11 +1724,12 @@ var GlassSwitch = React9.forwardRef(
|
|
|
1663
1724
|
const drop = (delay) => {
|
|
1664
1725
|
clearTimeout(dropTimer);
|
|
1665
1726
|
dropTimer = window.setTimeout(() => {
|
|
1666
|
-
lift.tune(
|
|
1727
|
+
lift.tune(SETTLE);
|
|
1667
1728
|
lift.set(0);
|
|
1668
1729
|
}, delay);
|
|
1669
1730
|
};
|
|
1670
1731
|
const down = (event) => {
|
|
1732
|
+
el2.removeAttribute("data-keyboard");
|
|
1671
1733
|
if (!event.isPrimary || event.button !== 0 || latest.current.disabled) return;
|
|
1672
1734
|
clearTimeout(dropTimer);
|
|
1673
1735
|
gesture = { id: event.pointerId, x: event.clientX, from: latest.current.checked ? 1 : 0, moved: false, at: performance.now() };
|
|
@@ -1753,6 +1815,10 @@ var GlassSwitch = React9.forwardRef(
|
|
|
1753
1815
|
"data-liquid-glass": "",
|
|
1754
1816
|
style: tint ? { "--lg-switch-on": tint, ...style } : style,
|
|
1755
1817
|
...rest,
|
|
1818
|
+
onKeyDown: (event) => {
|
|
1819
|
+
event.currentTarget.setAttribute("data-keyboard", "");
|
|
1820
|
+
rest.onKeyDown?.(event);
|
|
1821
|
+
},
|
|
1756
1822
|
children: [
|
|
1757
1823
|
/* @__PURE__ */ jsx9("span", { ref: fillRef, className: "lg-switch__fill", "aria-hidden": "true" }),
|
|
1758
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" }) })
|