@zakisheriff/liquid-glass 0.3.5 → 0.3.8
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/THIRD_PARTY_NOTICES.md +33 -9
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +80 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +80 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -96,7 +96,7 @@ function loop(time) {
|
|
|
96
96
|
frame = 0;
|
|
97
97
|
const dt = Math.min(0.064, Math.max(0, (time - last) / 1e3));
|
|
98
98
|
last = time;
|
|
99
|
-
for (const s of active) {
|
|
99
|
+
for (const s of [...active]) {
|
|
100
100
|
step(s, dt);
|
|
101
101
|
if (Math.abs(s.value - s.target) < 1e-4 && Math.abs(s.velocity) < 1e-3) {
|
|
102
102
|
s.value = s.target;
|
|
@@ -105,7 +105,7 @@ function loop(time) {
|
|
|
105
105
|
}
|
|
106
106
|
s.onUpdate(s.value, s.velocity);
|
|
107
107
|
}
|
|
108
|
-
if (active.size) frame = requestAnimationFrame(loop);
|
|
108
|
+
if (active.size && !frame) frame = requestAnimationFrame(loop);
|
|
109
109
|
}
|
|
110
110
|
function wake() {
|
|
111
111
|
if (frame) return;
|
|
@@ -178,8 +178,21 @@ var SPRINGS = {
|
|
|
178
178
|
/** Lens deflating back into a pill: visibly wobbly. */
|
|
179
179
|
settle: springFrom(0.45, 0.46),
|
|
180
180
|
/** Colour cross-fades. */
|
|
181
|
-
fade: springFrom(0.3, 1)
|
|
181
|
+
fade: springFrom(0.3, 1),
|
|
182
|
+
/** A dragged lens's stretch: loose, so it wobbles when the drag stops. */
|
|
183
|
+
jelly: springFrom(0.3, 0.3)
|
|
182
184
|
};
|
|
185
|
+
function createJelly(onUpdate, max, speed) {
|
|
186
|
+
const spring = createSpring(0, SPRINGS.jelly, (value) => onUpdate(value));
|
|
187
|
+
return {
|
|
188
|
+
feed(velocity) {
|
|
189
|
+
spring.set(max * Math.tanh(Math.abs(velocity) / speed));
|
|
190
|
+
},
|
|
191
|
+
stop() {
|
|
192
|
+
spring.stop();
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
}
|
|
183
196
|
function rubberband(offset, dimension, constant = 0.55) {
|
|
184
197
|
const sign = Math.sign(offset);
|
|
185
198
|
const x = Math.abs(offset);
|
|
@@ -500,14 +513,16 @@ function mirrorBackdrop(glass, source, padding, zoom, active2 = () => true) {
|
|
|
500
513
|
shown = on;
|
|
501
514
|
layer.style.visibility = on ? "" : "hidden";
|
|
502
515
|
}
|
|
503
|
-
if (on)
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
}
|
|
516
|
+
if (!on) return;
|
|
517
|
+
applyZoom();
|
|
518
|
+
sync();
|
|
519
|
+
align();
|
|
508
520
|
frame2 = requestAnimationFrame(tick);
|
|
509
521
|
};
|
|
510
|
-
|
|
522
|
+
const wake2 = () => {
|
|
523
|
+
if (!frame2 && !stopped) frame2 = requestAnimationFrame(tick);
|
|
524
|
+
};
|
|
525
|
+
wake2();
|
|
511
526
|
let pending = 0;
|
|
512
527
|
const recopy = () => {
|
|
513
528
|
pending = 0;
|
|
@@ -522,6 +537,7 @@ function mirrorBackdrop(glass, source, padding, zoom, active2 = () => true) {
|
|
|
522
537
|
};
|
|
523
538
|
const mutations = new MutationObserver((records) => {
|
|
524
539
|
if (records.every((r) => layer.contains(r.target) || r.target === layer || r.target === glass)) return;
|
|
540
|
+
wake2();
|
|
525
541
|
const structural = records.some((r) => r.type !== "attributes" && !layer.contains(r.target));
|
|
526
542
|
if (structural && !pending) pending = requestAnimationFrame(recopy);
|
|
527
543
|
else if (!structural && !stopped && visible && !document.hidden && active2()) {
|
|
@@ -533,14 +549,17 @@ function mirrorBackdrop(glass, source, padding, zoom, active2 = () => true) {
|
|
|
533
549
|
mutations.observe(source, { childList: true, characterData: true, attributes: true, attributeFilter: ["style", "class"], subtree: true });
|
|
534
550
|
const io = typeof IntersectionObserver === "function" ? new IntersectionObserver((entries) => {
|
|
535
551
|
visible = entries.some((e) => e.isIntersecting);
|
|
552
|
+
wake2();
|
|
536
553
|
}) : null;
|
|
537
554
|
io?.observe(glass);
|
|
555
|
+
document.addEventListener("visibilitychange", wake2);
|
|
538
556
|
return () => {
|
|
539
557
|
stopped = true;
|
|
540
558
|
cancelAnimationFrame(frame2);
|
|
541
559
|
cancelAnimationFrame(pending);
|
|
542
560
|
mutations.disconnect();
|
|
543
561
|
io?.disconnect();
|
|
562
|
+
document.removeEventListener("visibilitychange", wake2);
|
|
544
563
|
layer.remove();
|
|
545
564
|
glass.removeAttribute(SELF);
|
|
546
565
|
};
|
|
@@ -592,7 +611,7 @@ function bevelProfile(bezel, thickness, ior) {
|
|
|
592
611
|
return a + (b - a) * (f - i);
|
|
593
612
|
};
|
|
594
613
|
}
|
|
595
|
-
function bake(width, height, radius, shape, pad = 0, simple = false) {
|
|
614
|
+
function bake(width, height, radius, shape, pad = 0, simple = false, fringe = false) {
|
|
596
615
|
const W = width + pad * 2;
|
|
597
616
|
const H = height + pad * 2;
|
|
598
617
|
let density = Math.min(typeof devicePixelRatio === "number" ? devicePixelRatio : 1, 2);
|
|
@@ -766,7 +785,31 @@ function bake(width, height, radius, shape, pad = 0, simple = false) {
|
|
|
766
785
|
source = "magnified";
|
|
767
786
|
}
|
|
768
787
|
const scale = max * 2;
|
|
769
|
-
if (shape.dispersion > 0 && !simple) {
|
|
788
|
+
if (shape.dispersion > 0 && !simple && fringe) {
|
|
789
|
+
const spread = 0.3 * shape.dispersion;
|
|
790
|
+
for (const [name, factor] of [["r", 1 + spread], ["g", 1], ["b", 1 - spread]]) {
|
|
791
|
+
filter.append(
|
|
792
|
+
el("feDisplacementMap", {
|
|
793
|
+
in: source,
|
|
794
|
+
in2: "field",
|
|
795
|
+
scale: scale * factor,
|
|
796
|
+
xChannelSelector: "R",
|
|
797
|
+
yChannelSelector: "G",
|
|
798
|
+
result: `${name}-ray`
|
|
799
|
+
})
|
|
800
|
+
);
|
|
801
|
+
}
|
|
802
|
+
filter.append(
|
|
803
|
+
el("feComposite", { in: "r-ray", in2: "g-ray", operator: "out", result: "r-edge" }),
|
|
804
|
+
el("feColorMatrix", { in: "r-edge", type: "matrix", values: "0.2 0 0 0 0.62 0 0.2 0 0 0.16 0 0 0.2 0 0.8 0 0 0 1 0", result: "warm" }),
|
|
805
|
+
el("feComposite", { in: "b-ray", in2: "g-ray", operator: "out", result: "b-edge" }),
|
|
806
|
+
el("feColorMatrix", { in: "b-edge", type: "matrix", values: "0.2 0 0 0 0.1 0 0.2 0 0 0.78 0 0 0.2 0 0.62 0 0 0 1 0", result: "cool" }),
|
|
807
|
+
el("feMerge", {})
|
|
808
|
+
);
|
|
809
|
+
const merge = filter.lastElementChild;
|
|
810
|
+
for (const name of ["warm", "cool", "g-ray"]) merge.append(el("feMergeNode", { in: name }));
|
|
811
|
+
merge.setAttribute("result", "bent");
|
|
812
|
+
} else if (shape.dispersion > 0 && !simple) {
|
|
770
813
|
const spread = 0.16 * shape.dispersion;
|
|
771
814
|
const channels = [
|
|
772
815
|
["r", 1 + spread, "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0"],
|
|
@@ -837,15 +880,15 @@ function resolve(shape, width, height) {
|
|
|
837
880
|
copy: shape.copy ?? false
|
|
838
881
|
};
|
|
839
882
|
}
|
|
840
|
-
function glassFor(width, height, radius, shape = {}, pad = 0, simple = false) {
|
|
883
|
+
function glassFor(width, height, radius, shape = {}, pad = 0, simple = false, fringe = false) {
|
|
841
884
|
const w = Math.round(width);
|
|
842
885
|
const h = Math.round(height);
|
|
843
886
|
const r = Math.min(w / 2, h / 2, Math.max(0, radius));
|
|
844
887
|
const full = resolve(shape, w, h);
|
|
845
|
-
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, full.inset, pad, simple].join("|");
|
|
888
|
+
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, full.inset, pad, simple, fringe].join("|");
|
|
846
889
|
let baked = cache.get(key);
|
|
847
890
|
if (!baked) {
|
|
848
|
-
baked = bake(w, h, r, full, pad, simple);
|
|
891
|
+
baked = bake(w, h, r, full, pad, simple, fringe);
|
|
849
892
|
cache.set(key, baked);
|
|
850
893
|
}
|
|
851
894
|
return baked;
|
|
@@ -893,12 +936,13 @@ function useRefraction(ref, shape = {}, enabled = true, mirror, mirrorActive) {
|
|
|
893
936
|
({ zoom, zoomX } = resolve(shape, width, height));
|
|
894
937
|
element.style.setProperty("--lg-inner-mask", baked.inner);
|
|
895
938
|
if (bendCopy) {
|
|
896
|
-
copyFilter = glassFor(width, height, radius, { ...shape, zoom: 1, zoomX: 1,
|
|
939
|
+
copyFilter = glassFor(width, height, radius, { ...shape, zoom: 1, zoomX: 1 }, pad, false, true).filter;
|
|
897
940
|
applyCopyFilter();
|
|
898
941
|
}
|
|
899
942
|
}
|
|
900
|
-
if (live) {
|
|
901
|
-
|
|
943
|
+
if (live || bendCopy) {
|
|
944
|
+
const backdrop = live ? baked.filter : glassFor(width, height, radius, { ...shape, zoom: 1, zoomX: 1, strength: (shape.strength ?? 1) * 0.45 }).filter;
|
|
945
|
+
element.style.setProperty("--lg-filter", backdrop);
|
|
902
946
|
element.setAttribute("data-lg-refract", "");
|
|
903
947
|
}
|
|
904
948
|
element.style.setProperty("--lg-rim", baked.rim);
|
|
@@ -1057,8 +1101,8 @@ function Symbol2({ source, size = 24, className, style, ...props }) {
|
|
|
1057
1101
|
}
|
|
1058
1102
|
|
|
1059
1103
|
// src/components/internal/inputSymbols.ts
|
|
1060
|
-
var searchSymbol = "data:image/
|
|
1061
|
-
var clearSymbol = "data:image/
|
|
1104
|
+
var searchSymbol = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 256 256' fill='black'%3E%3Cpath d='M232.49,215.51,185,168a92.12,92.12,0,1,0-17,17l47.53,47.54a12,12,0,0,0,17-17ZM44,112a68,68,0,1,1,68,68A68.07,68.07,0,0,1,44,112Z'/%3E%3C/svg%3E";
|
|
1105
|
+
var clearSymbol = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 256 256' fill='black'%3E%3Cpath d='M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm37.66,130.34a8,8,0,0,1-11.32,11.32L128,139.31l-26.34,26.35a8,8,0,0,1-11.32-11.32L116.69,128,90.34,101.66a8,8,0,0,1,11.32-11.32L128,116.69l26.34-26.35a8,8,0,0,1,11.32,11.32L139.31,128Z'/%3E%3C/svg%3E";
|
|
1062
1106
|
|
|
1063
1107
|
// src/components/GlassInput/GlassInput.tsx
|
|
1064
1108
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
@@ -1679,9 +1723,13 @@ function useLensTrack(refs, options) {
|
|
|
1679
1723
|
}
|
|
1680
1724
|
if (!gesture && lift2 < 0.02) delete bar.dataset.lifted;
|
|
1681
1725
|
};
|
|
1726
|
+
const jelly = createJelly((value) => {
|
|
1727
|
+
state.squash = value;
|
|
1728
|
+
paint();
|
|
1729
|
+
}, 0.13, 1600);
|
|
1682
1730
|
const x = createSpring(current * slot, SPRINGS.snap, (value, velocity) => {
|
|
1683
1731
|
state.x = value;
|
|
1684
|
-
|
|
1732
|
+
jelly.feed(velocity);
|
|
1685
1733
|
paint();
|
|
1686
1734
|
});
|
|
1687
1735
|
const lift = createSpring(0, SPRINGS.lift, (value) => {
|
|
@@ -1856,7 +1904,7 @@ function useLensTrack(refs, options) {
|
|
|
1856
1904
|
return () => {
|
|
1857
1905
|
clearTimeout(dropTimer);
|
|
1858
1906
|
api.current = null;
|
|
1859
|
-
[x, lift, swell].forEach((s) => s.stop());
|
|
1907
|
+
[x, lift, swell, jelly].forEach((s) => s.stop());
|
|
1860
1908
|
unguard();
|
|
1861
1909
|
observer.disconnect();
|
|
1862
1910
|
bar.removeEventListener("pointerdown", onDown);
|
|
@@ -1906,7 +1954,7 @@ function LensTrack({
|
|
|
1906
1954
|
const overhang = tabbar ? 14 : 12;
|
|
1907
1955
|
useRefraction(
|
|
1908
1956
|
lens,
|
|
1909
|
-
{ kind: "lens", strength:
|
|
1957
|
+
{ kind: "lens", strength: 1.15, zoom, dispersion: 1, copy: "refract" },
|
|
1910
1958
|
true,
|
|
1911
1959
|
bar,
|
|
1912
1960
|
() => bar.current?.hasAttribute("data-lifted") ?? false
|
|
@@ -2369,7 +2417,7 @@ var GlassSwitch = import_react13.default.forwardRef(
|
|
|
2369
2417
|
const sync = (0, import_react13.useRef)(null);
|
|
2370
2418
|
useRefraction(
|
|
2371
2419
|
thumbRef,
|
|
2372
|
-
{ kind: "lens", zoom: 0.72, zoomX: 1, dispersion:
|
|
2420
|
+
{ kind: "lens", zoom: 0.72, zoomX: 1, dispersion: 1, copy: "refract", strength: Math.max(1, Math.min(10, intensity)) / 5 },
|
|
2373
2421
|
true,
|
|
2374
2422
|
ref,
|
|
2375
2423
|
() => parseFloat(ref.current?.style.getPropertyValue("--lg-lift") || "0") > 0.01
|
|
@@ -2390,9 +2438,13 @@ var GlassSwitch = import_react13.default.forwardRef(
|
|
|
2390
2438
|
el2.style.setProperty("--lg-lift", String(l));
|
|
2391
2439
|
el2.toggleAttribute("data-lifted", l > 0.01);
|
|
2392
2440
|
};
|
|
2441
|
+
const jelly = createJelly((value) => {
|
|
2442
|
+
v.stretch = value;
|
|
2443
|
+
paint();
|
|
2444
|
+
}, 0.14, 5);
|
|
2393
2445
|
const position = createSpring(v.x, SPRINGS.snap, (value, velocity) => {
|
|
2394
2446
|
v.x = value;
|
|
2395
|
-
|
|
2447
|
+
jelly.feed(velocity);
|
|
2396
2448
|
paint();
|
|
2397
2449
|
});
|
|
2398
2450
|
const lift = createSpring(0, SPRINGS.lift, (value) => {
|
|
@@ -2409,6 +2461,7 @@ var GlassSwitch = import_react13.default.forwardRef(
|
|
|
2409
2461
|
position.set(value ? 1 : 0);
|
|
2410
2462
|
color.set(value ? 1 : 0);
|
|
2411
2463
|
};
|
|
2464
|
+
const flips = (from, raw) => from ? raw > 0.3 : raw > 0.7;
|
|
2412
2465
|
let gesture = null;
|
|
2413
2466
|
let dropTimer = 0;
|
|
2414
2467
|
let ignoreClick = false;
|
|
@@ -2441,7 +2494,7 @@ var GlassSwitch = import_react13.default.forwardRef(
|
|
|
2441
2494
|
const over = raw < 0 ? rubberband(raw * TRAVEL, TRAVEL, 0.6) / TRAVEL : raw > 1 ? 1 + rubberband((raw - 1) * TRAVEL, TRAVEL, 0.6) / TRAVEL : raw;
|
|
2442
2495
|
position.tune(SPRINGS.drag);
|
|
2443
2496
|
position.set(over);
|
|
2444
|
-
const on = raw
|
|
2497
|
+
const on = flips(gesture.from, raw);
|
|
2445
2498
|
if (color.target === 1 !== on) haptic();
|
|
2446
2499
|
color.set(on ? 1 : 0);
|
|
2447
2500
|
};
|
|
@@ -2450,7 +2503,7 @@ var GlassSwitch = import_react13.default.forwardRef(
|
|
|
2450
2503
|
const { from, x, moved, at } = gesture;
|
|
2451
2504
|
gesture = null;
|
|
2452
2505
|
ignoreClick = true;
|
|
2453
|
-
const next = moved ? from + (event.clientX - x) / TRAVEL
|
|
2506
|
+
const next = moved ? flips(from, from + (event.clientX - x) / TRAVEL) : !latest.current.checked;
|
|
2454
2507
|
position.tune(SPRINGS.snap);
|
|
2455
2508
|
position.set(next ? 1 : 0);
|
|
2456
2509
|
color.set(next ? 1 : 0);
|
|
@@ -2484,7 +2537,7 @@ var GlassSwitch = import_react13.default.forwardRef(
|
|
|
2484
2537
|
el2.addEventListener("click", click);
|
|
2485
2538
|
return () => {
|
|
2486
2539
|
clearTimeout(dropTimer);
|
|
2487
|
-
[position, lift, color].forEach((s) => s.stop());
|
|
2540
|
+
[position, lift, color, jelly].forEach((s) => s.stop());
|
|
2488
2541
|
unguard();
|
|
2489
2542
|
el2.removeEventListener("pointerdown", down);
|
|
2490
2543
|
el2.removeEventListener("pointermove", move);
|