@zakisheriff/liquid-glass 0.2.7 → 0.3.0
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 +20 -4
- package/dist/index.css +205 -13
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +65 -2
- package/dist/index.d.ts +65 -2
- package/dist/index.js +616 -188
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +603 -176
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -134,6 +134,37 @@ function rubberband(offset, dimension, constant = 0.55) {
|
|
|
134
134
|
}
|
|
135
135
|
var clamp = (value, min, max) => Math.min(max, Math.max(min, value));
|
|
136
136
|
|
|
137
|
+
// src/engine/selection.ts
|
|
138
|
+
function guardSelection(el2) {
|
|
139
|
+
let held = false;
|
|
140
|
+
const block = (event) => {
|
|
141
|
+
if (held) event.preventDefault();
|
|
142
|
+
};
|
|
143
|
+
const clear = () => {
|
|
144
|
+
const selection = window.getSelection?.();
|
|
145
|
+
if (selection && !selection.isCollapsed) selection.removeAllRanges();
|
|
146
|
+
};
|
|
147
|
+
const down = () => {
|
|
148
|
+
held = true;
|
|
149
|
+
clear();
|
|
150
|
+
};
|
|
151
|
+
const up = () => {
|
|
152
|
+
if (!held) return;
|
|
153
|
+
held = false;
|
|
154
|
+
clear();
|
|
155
|
+
};
|
|
156
|
+
el2.addEventListener("pointerdown", down, true);
|
|
157
|
+
document.addEventListener("selectstart", block, true);
|
|
158
|
+
window.addEventListener("pointerup", up, true);
|
|
159
|
+
window.addEventListener("pointercancel", up, true);
|
|
160
|
+
return () => {
|
|
161
|
+
el2.removeEventListener("pointerdown", down, true);
|
|
162
|
+
document.removeEventListener("selectstart", block, true);
|
|
163
|
+
window.removeEventListener("pointerup", up, true);
|
|
164
|
+
window.removeEventListener("pointercancel", up, true);
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
137
168
|
// src/engine/press.ts
|
|
138
169
|
var FOLLOW = springFrom(0.2, 0.82);
|
|
139
170
|
function usePress(ref, options = {}) {
|
|
@@ -163,18 +194,20 @@ function usePress(ref, options = {}) {
|
|
|
163
194
|
};
|
|
164
195
|
const track = (event) => {
|
|
165
196
|
if (!pointer) return;
|
|
166
|
-
const { box, base } = pointer;
|
|
197
|
+
const { box, base, w, h } = pointer;
|
|
167
198
|
light(event, box);
|
|
168
199
|
const dx = event.clientX - pointer.x;
|
|
169
200
|
const dy = event.clientY - pointer.y;
|
|
170
|
-
const tx = rubberband(dx, lean * 2.2, 0.5);
|
|
171
|
-
const ty = rubberband(dy, lean * 2.2, 0.5);
|
|
172
201
|
const dist = Math.hypot(dx, dy);
|
|
173
|
-
const pull = 1 - 1 / (1 + dist / 55);
|
|
174
|
-
const k = stretch * pull;
|
|
175
202
|
const cx = dist ? (dx / dist) ** 2 : 0;
|
|
176
203
|
const cy = dist ? (dy / dist) ** 2 : 0;
|
|
177
|
-
|
|
204
|
+
const span = Math.min(w * cx + h * cy, 64);
|
|
205
|
+
const reach = rubberband(dist, span * stretch * 2, 0.55);
|
|
206
|
+
const ex = reach * cx / w;
|
|
207
|
+
const ey = reach * cy / h;
|
|
208
|
+
const tx = Math.sign(dx) * (reach * cx * base) / 2 + rubberband(dx, lean * 0.6, 0.4);
|
|
209
|
+
const ty = Math.sign(dy) * (reach * cy * base) / 2 + rubberband(dy, lean * 0.6, 0.4);
|
|
210
|
+
to([base * (1 + ex - ey * 0.35), base * (1 + ey - ex * 0.35), tx, ty], FOLLOW);
|
|
178
211
|
};
|
|
179
212
|
const move = (event) => {
|
|
180
213
|
if (event.pointerId === pointer?.id) track(event);
|
|
@@ -197,7 +230,7 @@ function usePress(ref, options = {}) {
|
|
|
197
230
|
const natural = Math.min(0.22, Math.max(0.07, 9 / Math.sqrt(w * h)));
|
|
198
231
|
const amount = (grow ?? natural) * (event.pointerType === "mouse" ? 0.75 : 1);
|
|
199
232
|
const base = 1 + amount;
|
|
200
|
-
pointer = { id: event.pointerId, x: event.clientX, y: event.clientY, box, base };
|
|
233
|
+
pointer = { id: event.pointerId, x: event.clientX, y: event.clientY, box, base, w, h };
|
|
201
234
|
el2.dataset.pressed = "";
|
|
202
235
|
light(event, box);
|
|
203
236
|
to([base, base, 0, 0], SPRINGS.press);
|
|
@@ -209,12 +242,14 @@ function usePress(ref, options = {}) {
|
|
|
209
242
|
const hold = (event) => {
|
|
210
243
|
if (pointer && event.cancelable) event.preventDefault();
|
|
211
244
|
};
|
|
245
|
+
const unguard = guardSelection(el2);
|
|
212
246
|
el2.addEventListener("touchmove", hold, { passive: false });
|
|
213
247
|
el2.addEventListener("pointerdown", down);
|
|
214
248
|
window.addEventListener("blur", blur);
|
|
215
249
|
return () => {
|
|
216
250
|
up();
|
|
217
251
|
springs.forEach((s) => s.stop());
|
|
252
|
+
unguard();
|
|
218
253
|
el2.removeEventListener("pointerdown", down);
|
|
219
254
|
el2.removeEventListener("touchmove", hold);
|
|
220
255
|
window.removeEventListener("blur", blur);
|
|
@@ -244,6 +279,7 @@ function clone(source) {
|
|
|
244
279
|
});
|
|
245
280
|
root.querySelectorAll(`[${SELF}], .lg-mirror, [data-lg-mirror-skip], input, textarea, select`).forEach((n) => n.remove());
|
|
246
281
|
root.removeAttribute("data-mirror");
|
|
282
|
+
root.setAttribute("data-lg-copy", "");
|
|
247
283
|
root.setAttribute("inert", "");
|
|
248
284
|
root.setAttribute("aria-hidden", "true");
|
|
249
285
|
return { root, pairs };
|
|
@@ -267,6 +303,7 @@ function backdropChain(glass, source) {
|
|
|
267
303
|
}
|
|
268
304
|
return chain;
|
|
269
305
|
}
|
|
306
|
+
var stateOf = (el2) => Array.from(el2.attributes).map((a) => a.name).filter((name) => name.startsWith("data-") && name !== "data-mirror" && !name.startsWith("data-lg-mirror")).sort().join(" ");
|
|
270
307
|
var BACKGROUND = ["background-color", "background-image", "background-size", "background-position", "background-repeat", "border-radius"];
|
|
271
308
|
function mirrorBackdrop(glass, source, padding, zoom, active2 = () => true) {
|
|
272
309
|
const layer = document.createElement("div");
|
|
@@ -350,6 +387,10 @@ function mirrorBackdrop(glass, source, padding, zoom, active2 = () => true) {
|
|
|
350
387
|
root.style.margin = "0px";
|
|
351
388
|
root.style.width = `${sw}px`;
|
|
352
389
|
root.style.height = `${sh}px`;
|
|
390
|
+
root.style.maxWidth = "none";
|
|
391
|
+
root.style.maxHeight = "none";
|
|
392
|
+
root.style.minWidth = "0px";
|
|
393
|
+
root.style.minHeight = "0px";
|
|
353
394
|
root.style.scale = "none";
|
|
354
395
|
root.style.translate = "none";
|
|
355
396
|
root.style.transformOrigin = "0 0";
|
|
@@ -372,10 +413,19 @@ function mirrorBackdrop(glass, source, padding, zoom, active2 = () => true) {
|
|
|
372
413
|
pair.copy.className = cls;
|
|
373
414
|
}
|
|
374
415
|
}
|
|
416
|
+
const flags = stateOf(source);
|
|
417
|
+
if (flags !== copyFlags) {
|
|
418
|
+
const now = new Set(flags.split(" "));
|
|
419
|
+
for (const name of copyFlags.split(" ")) if (name && !now.has(name)) copy.root.removeAttribute(name);
|
|
420
|
+
for (const name of flags.split(" ")) if (name) copy.root.setAttribute(name, source.getAttribute(name) ?? "");
|
|
421
|
+
copyFlags = flags;
|
|
422
|
+
}
|
|
375
423
|
};
|
|
424
|
+
let copyFlags = "";
|
|
376
425
|
let zoomed = "";
|
|
377
426
|
const applyZoom = () => {
|
|
378
|
-
const
|
|
427
|
+
const z = zoom();
|
|
428
|
+
const value = Array.isArray(z) ? `scale(${z[0]}, ${z[1]})` : `scale(${z})`;
|
|
379
429
|
if (value !== zoomed) zoomer.style.transform = zoomed = value;
|
|
380
430
|
};
|
|
381
431
|
const tick = () => {
|
|
@@ -401,6 +451,7 @@ function mirrorBackdrop(glass, source, padding, zoom, active2 = () => true) {
|
|
|
401
451
|
const next = clone(source);
|
|
402
452
|
copy.root.replaceWith(next.root);
|
|
403
453
|
copy = next;
|
|
454
|
+
copyFlags = "";
|
|
404
455
|
placed = "";
|
|
405
456
|
buildUnder();
|
|
406
457
|
align();
|
|
@@ -488,10 +539,17 @@ function bake(width, height, radius, shape, pad = 0, simple = false) {
|
|
|
488
539
|
const rimA = new Float32Array(cw * ch);
|
|
489
540
|
const rimHue = new Float32Array(cw * ch);
|
|
490
541
|
const inside = new Float32Array(cw * ch);
|
|
542
|
+
const zone = new Float32Array(cw * ch);
|
|
491
543
|
let max = 1e-4;
|
|
492
544
|
const hw = width / 2;
|
|
493
545
|
const hh = height / 2;
|
|
494
546
|
const px1 = 1 / density;
|
|
547
|
+
const edge = hh - shape.inset;
|
|
548
|
+
const band = (py) => {
|
|
549
|
+
if (!shape.inset) return 1;
|
|
550
|
+
const t = clamp((Math.abs(py) - (edge - 2)) / 3, 0, 1);
|
|
551
|
+
return 1 - t * t * (3 - 2 * t);
|
|
552
|
+
};
|
|
495
553
|
for (let y = 0; y < ch; y++) {
|
|
496
554
|
for (let x = 0; x < cw; x++) {
|
|
497
555
|
const px = (x + 0.5) * W / cw - W / 2;
|
|
@@ -515,18 +573,19 @@ function bake(width, height, radius, shape, pad = 0, simple = false) {
|
|
|
515
573
|
ny = Math.sign(py);
|
|
516
574
|
}
|
|
517
575
|
const i = y * cw + x;
|
|
518
|
-
const s = shift(d) * shape.strength * direction;
|
|
576
|
+
const s = shift(d) * shape.strength * direction * band(py);
|
|
519
577
|
let vx = nx * s;
|
|
520
578
|
let vy = ny * s;
|
|
521
579
|
if (simple && magnify) {
|
|
522
|
-
vx -= px * magnify;
|
|
523
|
-
vy -= py * magnify;
|
|
580
|
+
vx -= px * magnify * band(py);
|
|
581
|
+
vy -= py * magnify * band(py);
|
|
524
582
|
}
|
|
525
583
|
dx[i] = vx;
|
|
526
584
|
dy[i] = vy;
|
|
527
585
|
const m = Math.max(Math.abs(vx), Math.abs(vy));
|
|
528
586
|
if (m > max) max = m;
|
|
529
587
|
inside[i] = clamp(d / px1 + 0.5, 0, 1);
|
|
588
|
+
zone[i] = (d <= 0 ? 1 : clamp(1 - d / Math.max(1, shape.bezel), 0, 1) ** 1.3) * band(py);
|
|
530
589
|
if (d >= -px1) {
|
|
531
590
|
const facing = -(nx + ny) * Math.SQRT1_2;
|
|
532
591
|
const light = 0.22 + 0.78 * Math.abs(facing) ** 2.2 * (facing > 0 ? 1 : 0.62);
|
|
@@ -561,8 +620,9 @@ function bake(width, height, radius, shape, pad = 0, simple = false) {
|
|
|
561
620
|
const o = (y * cw + x) * 4;
|
|
562
621
|
const px = (x + 0.5) * W / cw - W / 2;
|
|
563
622
|
const py = (y + 0.5) * H / ch - H / 2;
|
|
564
|
-
|
|
565
|
-
ramp.data[o
|
|
623
|
+
const k = band(py);
|
|
624
|
+
ramp.data[o] = Math.round(127.5 - px / reach * 127.5 * k);
|
|
625
|
+
ramp.data[o + 1] = Math.round(127.5 - py / reach * 127.5 * k);
|
|
566
626
|
ramp.data[o + 2] = 128;
|
|
567
627
|
ramp.data[o + 3] = 255;
|
|
568
628
|
}
|
|
@@ -598,6 +658,17 @@ function bake(width, height, radius, shape, pad = 0, simple = false) {
|
|
|
598
658
|
}
|
|
599
659
|
ctx.putImageData(shapeMask, 0, 0);
|
|
600
660
|
const mask = canvas.toDataURL();
|
|
661
|
+
let smooth = "";
|
|
662
|
+
if (lens && !simple) {
|
|
663
|
+
const soft = ctx.createImageData(cw, ch);
|
|
664
|
+
for (let i = 0; i < cw * ch; i++) {
|
|
665
|
+
const o = i * 4;
|
|
666
|
+
soft.data[o] = soft.data[o + 1] = soft.data[o + 2] = 255;
|
|
667
|
+
soft.data[o + 3] = Math.round(zone[i] * 255);
|
|
668
|
+
}
|
|
669
|
+
ctx.putImageData(soft, 0, 0);
|
|
670
|
+
smooth = canvas.toDataURL();
|
|
671
|
+
}
|
|
601
672
|
const id = `lg-refract-${++counter}`;
|
|
602
673
|
const box = { x: 0, y: 0, width: W, height: H };
|
|
603
674
|
const filter = el("filter", {
|
|
@@ -662,9 +733,20 @@ function bake(width, height, radius, shape, pad = 0, simple = false) {
|
|
|
662
733
|
})
|
|
663
734
|
);
|
|
664
735
|
}
|
|
736
|
+
let out = "bent";
|
|
737
|
+
if (smooth) {
|
|
738
|
+
filter.append(
|
|
739
|
+
el("feGaussianBlur", { in: "bent", stdDeviation: 0.65, result: "bent-soft" }),
|
|
740
|
+
el("feImage", { href: smooth, ...box, preserveAspectRatio: "none", result: "rim-zone" }),
|
|
741
|
+
el("feComposite", { in: "bent-soft", in2: "rim-zone", operator: "in", result: "rim-soft" }),
|
|
742
|
+
el("feComposite", { in: "bent", in2: "rim-zone", operator: "out", result: "core" }),
|
|
743
|
+
el("feComposite", { in: "rim-soft", in2: "core", operator: "arithmetic", k2: 1, k3: 1, result: "smoothed" })
|
|
744
|
+
);
|
|
745
|
+
out = "smoothed";
|
|
746
|
+
}
|
|
665
747
|
filter.append(
|
|
666
748
|
el("feImage", { href: mask, ...box, preserveAspectRatio: "none", result: "shape" }),
|
|
667
|
-
el("feComposite", { in:
|
|
749
|
+
el("feComposite", { in: out, in2: "shape", operator: "in" })
|
|
668
750
|
);
|
|
669
751
|
container().append(filter);
|
|
670
752
|
return { filter: `url(#${id})`, rim: `url("${rim}")`, inner: `url("${mask}")` };
|
|
@@ -679,8 +761,11 @@ function resolve(shape, width, height) {
|
|
|
679
761
|
thickness: shape.thickness ?? (lens ? short * 0.55 : clamp(short * 0.32, 8, 26)),
|
|
680
762
|
ior: shape.ior ?? 1.5,
|
|
681
763
|
zoom: shape.zoom ?? (lens ? 1.16 : 1),
|
|
764
|
+
zoomX: shape.zoomX ?? shape.zoom ?? (lens ? 1.16 : 1),
|
|
682
765
|
dispersion: shape.dispersion ?? (lens ? 1 : 0),
|
|
683
|
-
strength: shape.strength ?? 1
|
|
766
|
+
strength: shape.strength ?? 1,
|
|
767
|
+
inset: shape.inset ?? 0,
|
|
768
|
+
copy: shape.copy ?? false
|
|
684
769
|
};
|
|
685
770
|
}
|
|
686
771
|
function glassFor(width, height, radius, shape = {}, pad = 0, simple = false) {
|
|
@@ -688,7 +773,7 @@ function glassFor(width, height, radius, shape = {}, pad = 0, simple = false) {
|
|
|
688
773
|
const h = Math.round(height);
|
|
689
774
|
const r = Math.min(w / 2, h / 2, Math.max(0, radius));
|
|
690
775
|
const full = resolve(shape, w, h);
|
|
691
|
-
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("|");
|
|
776
|
+
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("|");
|
|
692
777
|
let baked = cache.get(key);
|
|
693
778
|
if (!baked) {
|
|
694
779
|
baked = bake(w, h, r, full, pad, simple);
|
|
@@ -715,11 +800,18 @@ function useRefraction(ref, shape = {}, enabled = true, mirror, mirrorActive) {
|
|
|
715
800
|
useEffect2(() => {
|
|
716
801
|
const element = ref.current;
|
|
717
802
|
if (!element || !enabled) return;
|
|
718
|
-
const live = canRefractBackdrop();
|
|
803
|
+
const live = canRefractBackdrop() && !(shape.copy && mirror);
|
|
719
804
|
let cancel;
|
|
720
805
|
let filter = "";
|
|
721
806
|
let pad = 0;
|
|
722
807
|
let zoom = 1;
|
|
808
|
+
let zoomX = 1;
|
|
809
|
+
const bendCopy = shape.copy === "refract" && canRefractBackdrop() && !!mirror;
|
|
810
|
+
let copyFilter = "";
|
|
811
|
+
const applyCopyFilter = () => {
|
|
812
|
+
const viewport = element.querySelector(":scope > .lg-mirror > .lg-mirror__viewport");
|
|
813
|
+
if (viewport && copyFilter) viewport.style.filter = copyFilter;
|
|
814
|
+
};
|
|
723
815
|
const fit = () => {
|
|
724
816
|
const width = element.offsetWidth;
|
|
725
817
|
const height = element.offsetHeight;
|
|
@@ -729,10 +821,17 @@ function useRefraction(ref, shape = {}, enabled = true, mirror, mirrorActive) {
|
|
|
729
821
|
filter = baked.filter;
|
|
730
822
|
if (!live && mirror?.current) {
|
|
731
823
|
pad = Math.ceil(Math.min(width, height) * 0.45 + 6);
|
|
732
|
-
zoom = resolve(shape, width, height)
|
|
824
|
+
({ zoom, zoomX } = resolve(shape, width, height));
|
|
733
825
|
element.style.setProperty("--lg-inner-mask", baked.inner);
|
|
826
|
+
if (bendCopy) {
|
|
827
|
+
copyFilter = glassFor(width, height, radius, { ...shape, zoom: 1, zoomX: 1, dispersion: 0 }, pad).filter;
|
|
828
|
+
applyCopyFilter();
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
if (live) {
|
|
832
|
+
element.style.setProperty("--lg-filter", baked.filter);
|
|
833
|
+
element.setAttribute("data-lg-refract", "");
|
|
734
834
|
}
|
|
735
|
-
if (live) element.style.setProperty("--lg-filter", baked.filter);
|
|
736
835
|
element.style.setProperty("--lg-rim", baked.rim);
|
|
737
836
|
};
|
|
738
837
|
const observer = new ResizeObserver(() => {
|
|
@@ -742,13 +841,15 @@ function useRefraction(ref, shape = {}, enabled = true, mirror, mirrorActive) {
|
|
|
742
841
|
observer.observe(element);
|
|
743
842
|
fit();
|
|
744
843
|
const source = mirror?.current;
|
|
745
|
-
const unmirror = !live && source ? mirrorBackdrop(element, source, () => pad, () => zoom, mirrorActive) : void 0;
|
|
844
|
+
const unmirror = !live && source ? mirrorBackdrop(element, source, () => pad, () => [zoomX, zoom], mirrorActive) : void 0;
|
|
845
|
+
applyCopyFilter();
|
|
746
846
|
return () => {
|
|
747
847
|
cancel?.();
|
|
748
848
|
unmirror?.();
|
|
749
849
|
observer.disconnect();
|
|
750
850
|
element.style.removeProperty("--lg-filter");
|
|
751
851
|
element.style.removeProperty("--lg-rim");
|
|
852
|
+
element.removeAttribute("data-lg-refract");
|
|
752
853
|
};
|
|
753
854
|
}, [ref, signature, enabled, mirror]);
|
|
754
855
|
}
|
|
@@ -972,106 +1073,138 @@ import { createPortal } from "react-dom";
|
|
|
972
1073
|
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
973
1074
|
var OPEN = springFrom(0.42, 0.86);
|
|
974
1075
|
var CLOSE = springFrom(0.34, 1);
|
|
975
|
-
var
|
|
1076
|
+
var SNAP = springFrom(0.4, 0.84);
|
|
1077
|
+
var GlassSheet = ({ open, onClose, intensity = 5, tint, container: container2, detents, children, "aria-label": ariaLabel }) => {
|
|
976
1078
|
const [mounted, setMounted] = useState2(open);
|
|
977
1079
|
const sheetRef = useRef4(null);
|
|
978
1080
|
const scrimRef = useRef4(null);
|
|
979
|
-
const
|
|
1081
|
+
const api = useRef4(null);
|
|
1082
|
+
const stopsKey = detents?.join(",") ?? "";
|
|
980
1083
|
const closeRef = useRef4(onClose);
|
|
981
1084
|
closeRef.current = onClose;
|
|
982
1085
|
useEffect3(() => {
|
|
983
1086
|
if (open) setMounted(true);
|
|
984
|
-
else
|
|
1087
|
+
else api.current?.close();
|
|
985
1088
|
}, [open]);
|
|
986
1089
|
useRefraction(sheetRef, { kind: "surface", strength: Math.max(1, Math.min(10, intensity)) / 5, bezel: 20, thickness: 28 }, mounted);
|
|
987
1090
|
useEffect3(() => {
|
|
988
1091
|
if (!mounted) return;
|
|
989
1092
|
const sheet = sheetRef.current;
|
|
990
1093
|
const scrim = scrimRef.current;
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
1094
|
+
const layer = sheet.parentElement;
|
|
1095
|
+
const wanted = stopsKey ? stopsKey.split(",") : [];
|
|
1096
|
+
let height = 0;
|
|
1097
|
+
let hidden = 0;
|
|
1098
|
+
let stops = [0];
|
|
1099
|
+
let rest = 0;
|
|
1100
|
+
let medium = 0;
|
|
1101
|
+
const measure = () => {
|
|
1102
|
+
height = sheet.offsetHeight || 400;
|
|
1103
|
+
hidden = height + 24;
|
|
1104
|
+
medium = Math.max(0, height - layer.clientHeight * 0.5);
|
|
1105
|
+
stops = wanted.length ? wanted.map((d) => d === "large" ? 0 : medium).sort((x, y) => x - y) : [0];
|
|
1106
|
+
rest = wanted.includes("medium") ? medium : stops[0];
|
|
1107
|
+
};
|
|
1108
|
+
measure();
|
|
1109
|
+
const paint = (y) => {
|
|
995
1110
|
sheet.style.transform = `translateY(${y}px)`;
|
|
996
|
-
|
|
1111
|
+
const dim = wanted.includes("medium") && medium > 0 ? clamp(1 - y / medium, 0, 1) : clamp(1 - y / Math.max(1, height), 0, 1);
|
|
1112
|
+
scrim.style.opacity = String(dim);
|
|
1113
|
+
const raised = y <= 1;
|
|
1114
|
+
if (wanted.length && sheet.hasAttribute("data-raised") !== raised) sheet.toggleAttribute("data-raised", raised);
|
|
997
1115
|
};
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1116
|
+
let closing = false;
|
|
1117
|
+
const position = createSpring(hidden, OPEN, (y) => {
|
|
1118
|
+
paint(y);
|
|
1119
|
+
if (closing && y >= hidden - 1) setMounted(false);
|
|
1001
1120
|
});
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
set(
|
|
1005
|
-
|
|
1006
|
-
|
|
1121
|
+
const go = (y, feel) => {
|
|
1122
|
+
position.tune(feel);
|
|
1123
|
+
position.set(y);
|
|
1124
|
+
};
|
|
1125
|
+
api.current = {
|
|
1126
|
+
close() {
|
|
1127
|
+
closing = true;
|
|
1128
|
+
go(hidden, CLOSE);
|
|
1007
1129
|
}
|
|
1008
1130
|
};
|
|
1009
|
-
paint(
|
|
1131
|
+
paint(hidden);
|
|
1010
1132
|
requestAnimationFrame(() => {
|
|
1011
|
-
|
|
1012
|
-
|
|
1133
|
+
measure();
|
|
1134
|
+
position.set(hidden, true);
|
|
1135
|
+
if (open) go(rest, OPEN);
|
|
1013
1136
|
});
|
|
1014
1137
|
let gesture = null;
|
|
1015
1138
|
const down = (event) => {
|
|
1016
|
-
if (event.defaultPrevented) return;
|
|
1139
|
+
if (event.defaultPrevented || closing) return;
|
|
1017
1140
|
const target = event.target;
|
|
1018
|
-
|
|
1141
|
+
const raised = position.value <= 1;
|
|
1142
|
+
if (raised && !target.closest(".lg-sheet__grabber-zone") && sheet.scrollTop > 0) return;
|
|
1019
1143
|
if (target.closest('input, textarea, button, a, [role="slider"], [role="switch"]')) return;
|
|
1020
|
-
|
|
1144
|
+
position.stop();
|
|
1145
|
+
gesture = { id: event.pointerId, y: event.clientY, from: position.value, t: event.timeStamp, v: 0, last: position.value };
|
|
1021
1146
|
sheet.setPointerCapture(event.pointerId);
|
|
1022
1147
|
};
|
|
1023
1148
|
const move = (event) => {
|
|
1024
1149
|
if (event.pointerId !== gesture?.id) return;
|
|
1025
|
-
const
|
|
1150
|
+
const raw = gesture.from + event.clientY - gesture.y;
|
|
1151
|
+
const y = raw < 0 ? rubberband(raw, height, 0.3) : raw;
|
|
1026
1152
|
const dt = Math.max(1, event.timeStamp - gesture.t);
|
|
1027
|
-
gesture.v = (
|
|
1153
|
+
gesture.v = gesture.v * 0.2 + (y - gesture.last) / dt * 0.8;
|
|
1028
1154
|
gesture.t = event.timeStamp;
|
|
1029
|
-
|
|
1030
|
-
|
|
1155
|
+
gesture.last = y;
|
|
1156
|
+
position.set(y, true);
|
|
1157
|
+
paint(y);
|
|
1031
1158
|
};
|
|
1032
1159
|
const up = (event) => {
|
|
1033
1160
|
if (event.pointerId !== gesture?.id) return;
|
|
1034
|
-
const
|
|
1161
|
+
const { v, last: last2 } = gesture;
|
|
1035
1162
|
gesture = null;
|
|
1036
|
-
const
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
settle.stop();
|
|
1042
|
-
const p = 1 - clamp(drag / (height + 24), 0, 1);
|
|
1043
|
-
drag = 0;
|
|
1044
|
-
spring.set(p, true);
|
|
1163
|
+
const projected = last2 + v * 180;
|
|
1164
|
+
const lowest = stops[stops.length - 1];
|
|
1165
|
+
if (projected > lowest + (hidden - lowest) * 0.45 || v > 0.9 && last2 >= lowest - 4) {
|
|
1166
|
+
closing = true;
|
|
1167
|
+
go(hidden, CLOSE);
|
|
1045
1168
|
closeRef.current?.();
|
|
1046
|
-
|
|
1047
|
-
settle.set(0);
|
|
1169
|
+
return;
|
|
1048
1170
|
}
|
|
1171
|
+
const target = stops.reduce((best, stop) => Math.abs(stop - projected) < Math.abs(best - projected) ? stop : best, stops[0]);
|
|
1172
|
+
go(target, SNAP);
|
|
1049
1173
|
};
|
|
1050
1174
|
const key = (event) => {
|
|
1051
1175
|
if (event.key === "Escape") closeRef.current?.();
|
|
1052
1176
|
};
|
|
1177
|
+
const resize = () => {
|
|
1178
|
+
const at = position.target;
|
|
1179
|
+
const was = stops.indexOf(at);
|
|
1180
|
+
measure();
|
|
1181
|
+
if (!closing) go(was >= 0 ? stops[Math.min(was, stops.length - 1)] : rest, SNAP);
|
|
1182
|
+
};
|
|
1183
|
+
const observer = new ResizeObserver(resize);
|
|
1184
|
+
observer.observe(layer);
|
|
1053
1185
|
sheet.addEventListener("pointerdown", down);
|
|
1054
1186
|
sheet.addEventListener("pointermove", move);
|
|
1055
1187
|
sheet.addEventListener("pointerup", up);
|
|
1056
1188
|
sheet.addEventListener("pointercancel", up);
|
|
1057
1189
|
window.addEventListener("keydown", key);
|
|
1058
1190
|
const overflow = document.body.style.overflow;
|
|
1059
|
-
document.body.style.overflow = "hidden";
|
|
1191
|
+
if (!container2) document.body.style.overflow = "hidden";
|
|
1060
1192
|
sheet.focus({ preventScroll: true });
|
|
1061
1193
|
return () => {
|
|
1062
|
-
|
|
1063
|
-
|
|
1194
|
+
position.stop();
|
|
1195
|
+
api.current = null;
|
|
1196
|
+
observer.disconnect();
|
|
1064
1197
|
sheet.removeEventListener("pointerdown", down);
|
|
1065
1198
|
sheet.removeEventListener("pointermove", move);
|
|
1066
1199
|
sheet.removeEventListener("pointerup", up);
|
|
1067
1200
|
sheet.removeEventListener("pointercancel", up);
|
|
1068
1201
|
window.removeEventListener("keydown", key);
|
|
1069
|
-
document.body.style.overflow = overflow;
|
|
1202
|
+
if (!container2) document.body.style.overflow = overflow;
|
|
1070
1203
|
};
|
|
1071
|
-
}, [mounted]);
|
|
1204
|
+
}, [mounted, container2, stopsKey]);
|
|
1072
1205
|
if (!mounted || typeof document === "undefined") return null;
|
|
1073
1206
|
return createPortal(
|
|
1074
|
-
/* @__PURE__ */ jsxs3("div", { className: "lg-sheet-layer", "data-liquid-glass": "", children: [
|
|
1207
|
+
/* @__PURE__ */ jsxs3("div", { className: "lg-sheet-layer", "data-liquid-glass": "", style: container2 ? { position: "absolute" } : void 0, children: [
|
|
1075
1208
|
/* @__PURE__ */ jsx5("div", { ref: scrimRef, className: "lg-sheet__scrim", onClick: () => onClose?.(), "aria-hidden": "true" }),
|
|
1076
1209
|
/* @__PURE__ */ jsxs3(
|
|
1077
1210
|
"div",
|
|
@@ -1081,7 +1214,7 @@ var GlassSheet = ({ open, onClose, intensity = 5, tint, children, "aria-label":
|
|
|
1081
1214
|
"aria-modal": "true",
|
|
1082
1215
|
"aria-label": ariaLabel,
|
|
1083
1216
|
tabIndex: -1,
|
|
1084
|
-
className: "lg-glass lg-glass--host lg-sheet",
|
|
1217
|
+
className: ["lg-glass", "lg-glass--host", "lg-sheet", detents?.length ? "lg-sheet--detents" : ""].filter(Boolean).join(" "),
|
|
1085
1218
|
style: tint ? { "--lg-host-tint": tint } : void 0,
|
|
1086
1219
|
children: [
|
|
1087
1220
|
/* @__PURE__ */ jsx5("div", { className: "lg-sheet__grabber-zone", "aria-hidden": "true", children: /* @__PURE__ */ jsx5("span", { className: "lg-sheet__grabber" }) }),
|
|
@@ -1090,24 +1223,263 @@ var GlassSheet = ({ open, onClose, intensity = 5, tint, children, "aria-label":
|
|
|
1090
1223
|
}
|
|
1091
1224
|
)
|
|
1092
1225
|
] }),
|
|
1093
|
-
document.body
|
|
1226
|
+
container2 ?? document.body
|
|
1094
1227
|
);
|
|
1095
1228
|
};
|
|
1096
1229
|
GlassSheet.displayName = "GlassSheet";
|
|
1097
1230
|
|
|
1231
|
+
// src/components/GlassMenu/GlassMenu.tsx
|
|
1232
|
+
import { useEffect as useEffect4, useLayoutEffect, useRef as useRef5, useState as useState3 } from "react";
|
|
1233
|
+
import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1234
|
+
var OPEN2 = springFrom(0.36, 0.74);
|
|
1235
|
+
var CLOSE2 = springFrom(0.34, 0.9);
|
|
1236
|
+
var FADE = springFrom(0.24, 1);
|
|
1237
|
+
var FADE_OUT = springFrom(0.14, 1);
|
|
1238
|
+
var JELLY = springFrom(0.42, 0.4);
|
|
1239
|
+
var Tick = () => /* @__PURE__ */ jsx6("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsx6("path", { d: "M3.5 8.5l3 3 6-7", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round" }) });
|
|
1240
|
+
var GlassMenu = ({
|
|
1241
|
+
icon,
|
|
1242
|
+
items,
|
|
1243
|
+
"aria-label": ariaLabel,
|
|
1244
|
+
align = "end",
|
|
1245
|
+
size = "md",
|
|
1246
|
+
width = 230,
|
|
1247
|
+
check,
|
|
1248
|
+
className
|
|
1249
|
+
}) => {
|
|
1250
|
+
const [open, setOpen] = useState3(false);
|
|
1251
|
+
const [mounted, setMounted] = useState3(false);
|
|
1252
|
+
const anchorRef = useRef5(null);
|
|
1253
|
+
const triggerRef = useRef5(null);
|
|
1254
|
+
const surfaceRef = useRef5(null);
|
|
1255
|
+
const panelRef = useRef5(null);
|
|
1256
|
+
const contentRef = useRef5(null);
|
|
1257
|
+
const spring = useRef5(null);
|
|
1258
|
+
const itemsRef = useRef5(items);
|
|
1259
|
+
itemsRef.current = items;
|
|
1260
|
+
usePress(surfaceRef, { grow: 0.035, lean: 6, stretch: 0.1, disabled: !mounted });
|
|
1261
|
+
useEffect4(() => {
|
|
1262
|
+
if (open) setMounted(true);
|
|
1263
|
+
else if (spring.current) {
|
|
1264
|
+
spring.current.tune(CLOSE2);
|
|
1265
|
+
spring.current.set(0);
|
|
1266
|
+
}
|
|
1267
|
+
}, [open]);
|
|
1268
|
+
useLayoutEffect(() => {
|
|
1269
|
+
if (!mounted) return;
|
|
1270
|
+
const surface = surfaceRef.current;
|
|
1271
|
+
const panel = panelRef.current;
|
|
1272
|
+
const content = contentRef.current;
|
|
1273
|
+
const trigger = triggerRef.current;
|
|
1274
|
+
const w = trigger.offsetWidth;
|
|
1275
|
+
const h = trigger.offsetHeight;
|
|
1276
|
+
const W = Math.max(w, Math.min(width, window.innerWidth - 24));
|
|
1277
|
+
content.style.width = `${W}px`;
|
|
1278
|
+
const H = Math.max(h, content.offsetHeight);
|
|
1279
|
+
surface.style.width = `${W}px`;
|
|
1280
|
+
surface.style.height = `${H}px`;
|
|
1281
|
+
const end = align === "end";
|
|
1282
|
+
const box = { cw: w, ch: h, r: h / 2 };
|
|
1283
|
+
let scaleNow = 1;
|
|
1284
|
+
const clipContent = () => {
|
|
1285
|
+
const k = scaleNow;
|
|
1286
|
+
const right = Math.max(0, W - box.cw / k);
|
|
1287
|
+
const bottom = Math.max(0, H - box.ch / k);
|
|
1288
|
+
content.style.clipPath = box.cw >= W - 0.5 && box.ch >= H - 0.5 && k === 1 ? "" : `inset(0 ${end ? 0 : right}px ${bottom}px ${end ? right : 0}px round ${box.r / k}px)`;
|
|
1289
|
+
};
|
|
1290
|
+
const shape = (p) => {
|
|
1291
|
+
const cw = Math.max(1, w + (W - w) * p);
|
|
1292
|
+
const ch = Math.max(1, h + (H - h) * p);
|
|
1293
|
+
const sx = cw / W;
|
|
1294
|
+
const sy = ch / H;
|
|
1295
|
+
panel.style.transform = `scale(${sx}, ${sy})`;
|
|
1296
|
+
const land = clamp((p - 0.5) / 0.5, 0, 1);
|
|
1297
|
+
const r = Math.min(cw, ch) / 2 * (1 - land) + 24 * land;
|
|
1298
|
+
panel.style.borderRadius = `${r / sx}px / ${r / sy}px`;
|
|
1299
|
+
box.cw = cw;
|
|
1300
|
+
box.ch = ch;
|
|
1301
|
+
box.r = r;
|
|
1302
|
+
clipContent();
|
|
1303
|
+
const k = clamp(p / 0.35, 0, 1);
|
|
1304
|
+
panel.style.opacity = String(k);
|
|
1305
|
+
trigger.style.opacity = String(1 - k);
|
|
1306
|
+
};
|
|
1307
|
+
const reveal = (q) => {
|
|
1308
|
+
const t = clamp(q, 0, 1);
|
|
1309
|
+
const blur = 9 * (1 - t) ** 2.5;
|
|
1310
|
+
content.style.opacity = String(t);
|
|
1311
|
+
scaleNow = t < 0.999 ? 0.82 + 0.18 * t : 1;
|
|
1312
|
+
content.style.scale = scaleNow === 1 ? "" : String(scaleNow);
|
|
1313
|
+
clipContent();
|
|
1314
|
+
content.style.filter = blur > 0.05 ? `blur(${blur.toFixed(2)}px)` : "none";
|
|
1315
|
+
};
|
|
1316
|
+
shape(0);
|
|
1317
|
+
reveal(0);
|
|
1318
|
+
const s = createSpring(0, OPEN2, (p) => {
|
|
1319
|
+
shape(p);
|
|
1320
|
+
if (p <= 0.02 && s.target === 0) {
|
|
1321
|
+
trigger.style.opacity = "";
|
|
1322
|
+
const jelly = createSpring(0.07, JELLY, (v) => {
|
|
1323
|
+
trigger.style.scale = Math.abs(v) < 5e-4 ? "" : `${1 - v} ${1 + v}`;
|
|
1324
|
+
});
|
|
1325
|
+
jelly.set(0);
|
|
1326
|
+
setMounted(false);
|
|
1327
|
+
}
|
|
1328
|
+
});
|
|
1329
|
+
const fade = createSpring(0, FADE, reveal);
|
|
1330
|
+
spring.current = {
|
|
1331
|
+
...s,
|
|
1332
|
+
tune: s.tune,
|
|
1333
|
+
set(target, instant) {
|
|
1334
|
+
fade.tune(target ? FADE : FADE_OUT);
|
|
1335
|
+
fade.set(target, instant);
|
|
1336
|
+
s.set(target, instant);
|
|
1337
|
+
}
|
|
1338
|
+
};
|
|
1339
|
+
spring.current.set(1);
|
|
1340
|
+
content.querySelector('[role="menuitem"]:not([disabled])')?.focus({ preventScroll: true });
|
|
1341
|
+
return () => {
|
|
1342
|
+
s.stop();
|
|
1343
|
+
fade.stop();
|
|
1344
|
+
spring.current = null;
|
|
1345
|
+
trigger.style.opacity = "";
|
|
1346
|
+
};
|
|
1347
|
+
}, [mounted]);
|
|
1348
|
+
useEffect4(() => {
|
|
1349
|
+
if (!mounted) return;
|
|
1350
|
+
const panel = surfaceRef.current;
|
|
1351
|
+
let held = null;
|
|
1352
|
+
let hot = null;
|
|
1353
|
+
const itemAt = (x, y) => document.elementFromPoint(x, y)?.closest(".lg-menu__item:not(:disabled)") ?? null;
|
|
1354
|
+
const light = (next) => {
|
|
1355
|
+
if (next === hot) return;
|
|
1356
|
+
hot?.removeAttribute("data-active");
|
|
1357
|
+
hot = next;
|
|
1358
|
+
if (hot) {
|
|
1359
|
+
hot.setAttribute("data-active", "");
|
|
1360
|
+
haptic();
|
|
1361
|
+
}
|
|
1362
|
+
};
|
|
1363
|
+
const down = (event) => {
|
|
1364
|
+
if (!event.isPrimary || event.button !== 0) return;
|
|
1365
|
+
held = event.pointerId;
|
|
1366
|
+
hot = null;
|
|
1367
|
+
light(itemAt(event.clientX, event.clientY));
|
|
1368
|
+
};
|
|
1369
|
+
const move = (event) => {
|
|
1370
|
+
if (event.pointerId === held) light(itemAt(event.clientX, event.clientY));
|
|
1371
|
+
};
|
|
1372
|
+
const up = (event) => {
|
|
1373
|
+
if (event.pointerId !== held) return;
|
|
1374
|
+
held = null;
|
|
1375
|
+
const target = hot;
|
|
1376
|
+
light(null);
|
|
1377
|
+
const index = target ? Number(target.dataset.index) : -1;
|
|
1378
|
+
const item = itemsRef.current[index];
|
|
1379
|
+
if (item && !item.disabled) {
|
|
1380
|
+
event.preventDefault();
|
|
1381
|
+
haptic();
|
|
1382
|
+
item.onSelect?.();
|
|
1383
|
+
setOpen(false);
|
|
1384
|
+
}
|
|
1385
|
+
};
|
|
1386
|
+
const cancel = (event) => {
|
|
1387
|
+
if (event.pointerId !== held) return;
|
|
1388
|
+
held = null;
|
|
1389
|
+
light(null);
|
|
1390
|
+
};
|
|
1391
|
+
const hold = (event) => {
|
|
1392
|
+
if (held !== null && event.cancelable) event.preventDefault();
|
|
1393
|
+
};
|
|
1394
|
+
panel.addEventListener("pointerdown", down);
|
|
1395
|
+
window.addEventListener("pointermove", move);
|
|
1396
|
+
window.addEventListener("pointerup", up);
|
|
1397
|
+
window.addEventListener("pointercancel", cancel);
|
|
1398
|
+
panel.addEventListener("touchmove", hold, { passive: false });
|
|
1399
|
+
return () => {
|
|
1400
|
+
panel.removeEventListener("pointerdown", down);
|
|
1401
|
+
window.removeEventListener("pointermove", move);
|
|
1402
|
+
window.removeEventListener("pointerup", up);
|
|
1403
|
+
window.removeEventListener("pointercancel", cancel);
|
|
1404
|
+
panel.removeEventListener("touchmove", hold);
|
|
1405
|
+
};
|
|
1406
|
+
}, [mounted]);
|
|
1407
|
+
useEffect4(() => {
|
|
1408
|
+
if (!open) return;
|
|
1409
|
+
const outside = (event) => {
|
|
1410
|
+
if (!anchorRef.current?.contains(event.target)) setOpen(false);
|
|
1411
|
+
};
|
|
1412
|
+
const key = (event) => {
|
|
1413
|
+
if (event.key === "Escape") {
|
|
1414
|
+
setOpen(false);
|
|
1415
|
+
triggerRef.current?.focus({ preventScroll: true });
|
|
1416
|
+
}
|
|
1417
|
+
};
|
|
1418
|
+
document.addEventListener("pointerdown", outside, true);
|
|
1419
|
+
window.addEventListener("keydown", key);
|
|
1420
|
+
return () => {
|
|
1421
|
+
document.removeEventListener("pointerdown", outside, true);
|
|
1422
|
+
window.removeEventListener("keydown", key);
|
|
1423
|
+
};
|
|
1424
|
+
}, [open]);
|
|
1425
|
+
const select = (item) => {
|
|
1426
|
+
haptic();
|
|
1427
|
+
item.onSelect?.();
|
|
1428
|
+
setOpen(false);
|
|
1429
|
+
};
|
|
1430
|
+
return /* @__PURE__ */ jsxs4("span", { ref: anchorRef, className: ["lg-menu-anchor", className].filter(Boolean).join(" "), "data-align": align, children: [
|
|
1431
|
+
/* @__PURE__ */ jsx6(
|
|
1432
|
+
GlassButton,
|
|
1433
|
+
{
|
|
1434
|
+
ref: triggerRef,
|
|
1435
|
+
size,
|
|
1436
|
+
icon,
|
|
1437
|
+
"aria-label": ariaLabel,
|
|
1438
|
+
"aria-haspopup": "menu",
|
|
1439
|
+
"aria-expanded": open,
|
|
1440
|
+
onClick: () => setOpen((value) => !value)
|
|
1441
|
+
}
|
|
1442
|
+
),
|
|
1443
|
+
mounted && /* @__PURE__ */ jsxs4("div", { ref: surfaceRef, className: "lg-menu-surface", children: [
|
|
1444
|
+
/* @__PURE__ */ jsx6("div", { ref: panelRef, className: "lg-glass lg-menu", "data-liquid-glass": "", "aria-hidden": "true" }),
|
|
1445
|
+
/* @__PURE__ */ jsx6("div", { ref: contentRef, className: "lg-menu__content", role: "menu", "aria-label": ariaLabel, children: items.map((item, index) => /* @__PURE__ */ jsxs4(
|
|
1446
|
+
"button",
|
|
1447
|
+
{
|
|
1448
|
+
type: "button",
|
|
1449
|
+
role: "menuitem",
|
|
1450
|
+
className: "lg-menu__item",
|
|
1451
|
+
"data-destructive": item.destructive ? "" : void 0,
|
|
1452
|
+
"data-index": index,
|
|
1453
|
+
disabled: item.disabled,
|
|
1454
|
+
onClick: (event) => {
|
|
1455
|
+
if (event.detail === 0) select(item);
|
|
1456
|
+
},
|
|
1457
|
+
children: [
|
|
1458
|
+
item.icon != null && /* @__PURE__ */ jsx6("span", { className: "lg-menu__icon", children: item.icon }),
|
|
1459
|
+
/* @__PURE__ */ jsx6("span", { className: "lg-menu__label", children: item.label }),
|
|
1460
|
+
item.checked && /* @__PURE__ */ jsx6("span", { className: "lg-menu__check", children: check ?? /* @__PURE__ */ jsx6(Tick, {}) })
|
|
1461
|
+
]
|
|
1462
|
+
},
|
|
1463
|
+
index
|
|
1464
|
+
)) })
|
|
1465
|
+
] })
|
|
1466
|
+
] });
|
|
1467
|
+
};
|
|
1468
|
+
GlassMenu.displayName = "GlassMenu";
|
|
1469
|
+
|
|
1098
1470
|
// src/components/GlassNav/GlassNav.tsx
|
|
1099
|
-
import
|
|
1471
|
+
import React7 from "react";
|
|
1100
1472
|
|
|
1101
1473
|
// src/components/internal/LensTrack.tsx
|
|
1102
|
-
import { useRef as
|
|
1474
|
+
import { useRef as useRef7 } from "react";
|
|
1103
1475
|
|
|
1104
1476
|
// src/engine/lensTrack.ts
|
|
1105
|
-
import { useEffect as
|
|
1477
|
+
import { useEffect as useEffect5, useRef as useRef6 } from "react";
|
|
1106
1478
|
function useLensTrack(refs, options) {
|
|
1107
|
-
const latest =
|
|
1479
|
+
const latest = useRef6(options);
|
|
1108
1480
|
latest.current = options;
|
|
1109
|
-
const api =
|
|
1110
|
-
|
|
1481
|
+
const api = useRef6(null);
|
|
1482
|
+
useEffect5(() => {
|
|
1111
1483
|
const bar = refs.bar.current;
|
|
1112
1484
|
const lens = refs.lens.current;
|
|
1113
1485
|
const glass = refs.glass.current;
|
|
@@ -1124,7 +1496,7 @@ function useLensTrack(refs, options) {
|
|
|
1124
1496
|
let gesture = null;
|
|
1125
1497
|
let dropTimer = 0;
|
|
1126
1498
|
let suppressClick = false;
|
|
1127
|
-
const buttons = Array.from(bar.querySelectorAll("[data-lg-item]"));
|
|
1499
|
+
const buttons = Array.from(bar.querySelectorAll(":scope > [data-lg-item]"));
|
|
1128
1500
|
let glyphs = [];
|
|
1129
1501
|
const preview = (index) => {
|
|
1130
1502
|
if (index === void 0) delete bar.dataset.previewing;
|
|
@@ -1147,14 +1519,23 @@ function useLensTrack(refs, options) {
|
|
|
1147
1519
|
select.style.width = `${slot}px`;
|
|
1148
1520
|
select.style.left = `${pad}px`;
|
|
1149
1521
|
glyphs = buttons.flatMap(
|
|
1150
|
-
(button) => Array.from(button.querySelectorAll(".lg-nav__label, .lg-nav__icon > .lg-symbol")).map((node) =>
|
|
1151
|
-
node
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1522
|
+
(button) => Array.from(button.querySelectorAll(".lg-nav__label, .lg-nav__icon > .lg-symbol")).map((node) => {
|
|
1523
|
+
const label2 = node.classList.contains("lg-nav__label");
|
|
1524
|
+
const host = label2 ? node : node.parentElement;
|
|
1525
|
+
const n = node.getBoundingClientRect();
|
|
1526
|
+
const h = host.getBoundingClientRect();
|
|
1527
|
+
return {
|
|
1528
|
+
node,
|
|
1529
|
+
x: button.offsetLeft + node.offsetLeft - pad,
|
|
1530
|
+
y: node.offsetTop,
|
|
1531
|
+
width: node.offsetWidth,
|
|
1532
|
+
height: node.offsetHeight,
|
|
1533
|
+
label: label2,
|
|
1534
|
+
host,
|
|
1535
|
+
dx: n.left - h.left,
|
|
1536
|
+
dy: n.top - h.top
|
|
1537
|
+
};
|
|
1538
|
+
})
|
|
1158
1539
|
);
|
|
1159
1540
|
};
|
|
1160
1541
|
const paint = () => {
|
|
@@ -1176,8 +1557,24 @@ function useLensTrack(refs, options) {
|
|
|
1176
1557
|
if (lift2 <= 0.02 && !gesture) {
|
|
1177
1558
|
glyph.node.style.removeProperty("--lg-content-tint");
|
|
1178
1559
|
glyph.node.style.removeProperty("transform");
|
|
1560
|
+
glyph.host.style.removeProperty("--lg-content-hide");
|
|
1179
1561
|
continue;
|
|
1180
1562
|
}
|
|
1563
|
+
if (latest.current.copied) {
|
|
1564
|
+
const hy = H * ky / 2;
|
|
1565
|
+
const hx = H * kx / 2;
|
|
1566
|
+
const run = Math.max(0, (W - H) * kx / 2);
|
|
1567
|
+
const ccx = x2 + slot / 2 - glyph.x + glyph.dx;
|
|
1568
|
+
const ccy = height / 2 - glyph.y + glyph.dy;
|
|
1569
|
+
const fade = clamp(lift2 * 3, 0, 1);
|
|
1570
|
+
const solid = `rgb(0 0 0 / ${fade})`;
|
|
1571
|
+
glyph.host.style.setProperty("--lg-content-hide", [
|
|
1572
|
+
"linear-gradient(#000, #000)",
|
|
1573
|
+
`radial-gradient(ellipse ${hx}px ${hy}px at ${ccx - run}px ${ccy}px, ${solid} calc(100% - 1px), transparent 100%)`,
|
|
1574
|
+
`radial-gradient(ellipse ${hx}px ${hy}px at ${ccx + run}px ${ccy}px, ${solid} calc(100% - 1px), transparent 100%)`,
|
|
1575
|
+
`linear-gradient(${solid}, ${solid}) ${ccx - run}px ${ccy - hy}px / ${run * 2}px ${hy * 2}px no-repeat`
|
|
1576
|
+
].join(", "));
|
|
1577
|
+
}
|
|
1181
1578
|
const zoom = latest.current.contentZoom ?? 1;
|
|
1182
1579
|
const ry = H * ky / (2 * zoom);
|
|
1183
1580
|
const rx = H * kx / (2 * zoom);
|
|
@@ -1370,6 +1767,7 @@ function useLensTrack(refs, options) {
|
|
|
1370
1767
|
x.set(current * slot, true);
|
|
1371
1768
|
bar.dataset.ready = "";
|
|
1372
1769
|
observer.observe(bar);
|
|
1770
|
+
const unguard = guardSelection(bar);
|
|
1373
1771
|
bar.addEventListener("pointerdown", onDown);
|
|
1374
1772
|
window.addEventListener("pointermove", onMove);
|
|
1375
1773
|
window.addEventListener("pointerup", onUp);
|
|
@@ -1383,6 +1781,7 @@ function useLensTrack(refs, options) {
|
|
|
1383
1781
|
clearTimeout(dropTimer);
|
|
1384
1782
|
api.current = null;
|
|
1385
1783
|
[x, lift, swell].forEach((s) => s.stop());
|
|
1784
|
+
unguard();
|
|
1386
1785
|
observer.disconnect();
|
|
1387
1786
|
bar.removeEventListener("pointerdown", onDown);
|
|
1388
1787
|
window.removeEventListener("pointermove", onMove);
|
|
@@ -1395,19 +1794,20 @@ function useLensTrack(refs, options) {
|
|
|
1395
1794
|
delete bar.dataset.ready;
|
|
1396
1795
|
delete bar.dataset.lifted;
|
|
1397
1796
|
preview();
|
|
1398
|
-
glyphs.forEach(({ node }) => {
|
|
1797
|
+
glyphs.forEach(({ node, host }) => {
|
|
1399
1798
|
node.style.removeProperty("--lg-content-tint");
|
|
1400
1799
|
node.style.removeProperty("transform");
|
|
1800
|
+
host.style.removeProperty("--lg-content-hide");
|
|
1401
1801
|
});
|
|
1402
1802
|
};
|
|
1403
1803
|
}, [options.count]);
|
|
1404
|
-
|
|
1804
|
+
useEffect5(() => {
|
|
1405
1805
|
api.current?.setIndex(options.index);
|
|
1406
1806
|
}, [options.index]);
|
|
1407
1807
|
}
|
|
1408
1808
|
|
|
1409
1809
|
// src/components/internal/LensTrack.tsx
|
|
1410
|
-
import { jsx as
|
|
1810
|
+
import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
1411
1811
|
function LensTrack({
|
|
1412
1812
|
items,
|
|
1413
1813
|
labels,
|
|
@@ -1419,28 +1819,36 @@ function LensTrack({
|
|
|
1419
1819
|
style,
|
|
1420
1820
|
"aria-label": ariaLabel
|
|
1421
1821
|
}) {
|
|
1422
|
-
const bar =
|
|
1423
|
-
const glass =
|
|
1424
|
-
const lens =
|
|
1425
|
-
const select =
|
|
1822
|
+
const bar = useRef7(null);
|
|
1823
|
+
const glass = useRef7(null);
|
|
1824
|
+
const lens = useRef7(null);
|
|
1825
|
+
const select = useRef7(null);
|
|
1426
1826
|
const strength = Math.max(1, Math.min(10, intensity)) / 5;
|
|
1427
1827
|
const tabbar = variant === "tabbar";
|
|
1428
1828
|
const zoom = tabbar ? 1.14 : 1.1;
|
|
1429
1829
|
useRefraction(glass, { kind: "surface", strength });
|
|
1430
|
-
|
|
1830
|
+
const overhang = tabbar ? 14 : 12;
|
|
1831
|
+
useRefraction(
|
|
1832
|
+
lens,
|
|
1833
|
+
{ kind: "lens", strength: 0.85, zoom, dispersion: 0.25, inset: overhang / 2, copy: "refract" },
|
|
1834
|
+
true,
|
|
1835
|
+
bar,
|
|
1836
|
+
() => bar.current?.hasAttribute("data-lifted") ?? false
|
|
1837
|
+
);
|
|
1431
1838
|
useLensTrack(
|
|
1432
1839
|
{ bar, glass, lens, select },
|
|
1433
1840
|
{
|
|
1434
1841
|
count: items.length,
|
|
1435
1842
|
index,
|
|
1436
1843
|
onSelect: (next) => onChange?.(next),
|
|
1437
|
-
overhang
|
|
1844
|
+
overhang,
|
|
1438
1845
|
spread: tabbar ? 0.3 : 0.16,
|
|
1439
|
-
contentZoom:
|
|
1846
|
+
contentZoom: zoom,
|
|
1847
|
+
copied: true,
|
|
1440
1848
|
swell: tabbar ? 8 : 14
|
|
1441
1849
|
}
|
|
1442
1850
|
);
|
|
1443
|
-
return /* @__PURE__ */
|
|
1851
|
+
return /* @__PURE__ */ jsxs5(
|
|
1444
1852
|
"div",
|
|
1445
1853
|
{
|
|
1446
1854
|
ref: bar,
|
|
@@ -1450,9 +1858,9 @@ function LensTrack({
|
|
|
1450
1858
|
"data-liquid-glass": "",
|
|
1451
1859
|
style: { ...style, "--lg-count": items.length, "--lg-index": index },
|
|
1452
1860
|
children: [
|
|
1453
|
-
/* @__PURE__ */
|
|
1454
|
-
/* @__PURE__ */
|
|
1455
|
-
items.map((item, i) => /* @__PURE__ */
|
|
1861
|
+
/* @__PURE__ */ jsx7("span", { ref: glass, className: "lg-glass lg-track__glass", "aria-hidden": "true" }),
|
|
1862
|
+
/* @__PURE__ */ jsx7("span", { ref: select, className: "lg-track__select", "aria-hidden": "true" }),
|
|
1863
|
+
items.map((item, i) => /* @__PURE__ */ jsx7(
|
|
1456
1864
|
"button",
|
|
1457
1865
|
{
|
|
1458
1866
|
type: "button",
|
|
@@ -1466,38 +1874,40 @@ function LensTrack({
|
|
|
1466
1874
|
},
|
|
1467
1875
|
i
|
|
1468
1876
|
)),
|
|
1469
|
-
/* @__PURE__ */
|
|
1877
|
+
/* @__PURE__ */ jsx7("span", { ref: lens, className: "lg-glass lg-track__lens", "data-lg-mirror-bare": "", "aria-hidden": "true" })
|
|
1470
1878
|
]
|
|
1471
1879
|
}
|
|
1472
1880
|
);
|
|
1473
1881
|
}
|
|
1474
1882
|
|
|
1475
1883
|
// src/components/GlassNav/GlassNav.tsx
|
|
1476
|
-
import { jsx as
|
|
1884
|
+
import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1477
1885
|
var GlassNav = ({
|
|
1478
1886
|
items,
|
|
1479
1887
|
activeIndex = 0,
|
|
1480
1888
|
onChange,
|
|
1481
1889
|
intensity = 5,
|
|
1890
|
+
showLabels = true,
|
|
1482
1891
|
className,
|
|
1483
1892
|
style,
|
|
1484
1893
|
"aria-label": ariaLabel = "Tabs"
|
|
1485
1894
|
}) => {
|
|
1486
1895
|
const hasIcons = items.some((item) => item.icon != null);
|
|
1487
|
-
|
|
1896
|
+
const iconsOnly = hasIcons && !showLabels;
|
|
1897
|
+
return /* @__PURE__ */ jsx8(
|
|
1488
1898
|
LensTrack,
|
|
1489
1899
|
{
|
|
1490
1900
|
variant: "tabbar",
|
|
1491
|
-
className: ["lg-nav", hasIcons ? "" : "lg-track--labels-only", className].filter(Boolean).join(" "),
|
|
1901
|
+
className: ["lg-nav", hasIcons ? "" : "lg-track--labels-only", iconsOnly ? "lg-track--icons-only" : "", className].filter(Boolean).join(" "),
|
|
1492
1902
|
style,
|
|
1493
1903
|
"aria-label": ariaLabel,
|
|
1494
1904
|
intensity,
|
|
1495
1905
|
index: activeIndex,
|
|
1496
1906
|
onChange,
|
|
1497
1907
|
labels: items.map((item) => item.label),
|
|
1498
|
-
items: items.map((item, i) => /* @__PURE__ */
|
|
1499
|
-
item.icon != null && /* @__PURE__ */
|
|
1500
|
-
/* @__PURE__ */
|
|
1908
|
+
items: items.map((item, i) => /* @__PURE__ */ jsxs6(React7.Fragment, { children: [
|
|
1909
|
+
item.icon != null && /* @__PURE__ */ jsx8("span", { className: "lg-nav__icon", children: item.icon }),
|
|
1910
|
+
!iconsOnly && /* @__PURE__ */ jsx8("span", { className: "lg-nav__label", children: item.label })
|
|
1501
1911
|
] }, i))
|
|
1502
1912
|
}
|
|
1503
1913
|
);
|
|
@@ -1505,8 +1915,8 @@ var GlassNav = ({
|
|
|
1505
1915
|
GlassNav.displayName = "GlassNav";
|
|
1506
1916
|
|
|
1507
1917
|
// src/components/GlassSegmented/GlassSegmented.tsx
|
|
1508
|
-
import
|
|
1509
|
-
import { jsx as
|
|
1918
|
+
import React8 from "react";
|
|
1919
|
+
import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1510
1920
|
var GlassSegmented = ({
|
|
1511
1921
|
options,
|
|
1512
1922
|
value,
|
|
@@ -1518,7 +1928,7 @@ var GlassSegmented = ({
|
|
|
1518
1928
|
"aria-label": ariaLabel
|
|
1519
1929
|
}) => {
|
|
1520
1930
|
const normalized = options.map((option) => typeof option === "string" ? { label: option } : option);
|
|
1521
|
-
return /* @__PURE__ */
|
|
1931
|
+
return /* @__PURE__ */ jsx9(
|
|
1522
1932
|
LensTrack,
|
|
1523
1933
|
{
|
|
1524
1934
|
variant: "segmented",
|
|
@@ -1529,9 +1939,9 @@ var GlassSegmented = ({
|
|
|
1529
1939
|
index: value,
|
|
1530
1940
|
onChange,
|
|
1531
1941
|
labels: normalized.map((option) => option.label),
|
|
1532
|
-
items: normalized.map((option, i) => /* @__PURE__ */
|
|
1942
|
+
items: normalized.map((option, i) => /* @__PURE__ */ jsxs7(React8.Fragment, { children: [
|
|
1533
1943
|
option.icon,
|
|
1534
|
-
/* @__PURE__ */
|
|
1944
|
+
/* @__PURE__ */ jsx9("span", { className: "lg-nav__label", children: option.label })
|
|
1535
1945
|
] }, i))
|
|
1536
1946
|
}
|
|
1537
1947
|
);
|
|
@@ -1539,9 +1949,9 @@ var GlassSegmented = ({
|
|
|
1539
1949
|
GlassSegmented.displayName = "GlassSegmented";
|
|
1540
1950
|
|
|
1541
1951
|
// src/components/GlassSlider/GlassSlider.tsx
|
|
1542
|
-
import
|
|
1543
|
-
import { jsx as
|
|
1544
|
-
var GlassSlider =
|
|
1952
|
+
import React9, { useEffect as useEffect6, useImperativeHandle as useImperativeHandle4, useRef as useRef8 } from "react";
|
|
1953
|
+
import { jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1954
|
+
var GlassSlider = React9.forwardRef(
|
|
1545
1955
|
({
|
|
1546
1956
|
value = 0,
|
|
1547
1957
|
min = 0,
|
|
@@ -1560,22 +1970,23 @@ var GlassSlider = React8.forwardRef(
|
|
|
1560
1970
|
disabled,
|
|
1561
1971
|
...rest
|
|
1562
1972
|
}, forwardedRef) => {
|
|
1563
|
-
const rootRef =
|
|
1564
|
-
const inputRef =
|
|
1565
|
-
const thumbRef =
|
|
1566
|
-
const faceRef =
|
|
1567
|
-
const blockRef =
|
|
1973
|
+
const rootRef = useRef8(null);
|
|
1974
|
+
const inputRef = useRef8(null);
|
|
1975
|
+
const thumbRef = useRef8(null);
|
|
1976
|
+
const faceRef = useRef8(null);
|
|
1977
|
+
const blockRef = useRef8(null);
|
|
1978
|
+
const pastRef = useRef8(0);
|
|
1568
1979
|
useImperativeHandle4(forwardedRef, () => inputRef.current);
|
|
1569
|
-
|
|
1980
|
+
useEffect6(() => {
|
|
1570
1981
|
const input2 = inputRef.current;
|
|
1571
1982
|
const root = rootRef.current;
|
|
1572
1983
|
const setValue = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value").set;
|
|
1573
1984
|
let drag = null;
|
|
1574
1985
|
const update = (clientX) => {
|
|
1575
1986
|
if (!drag || max <= min) return;
|
|
1576
|
-
const
|
|
1577
|
-
const
|
|
1578
|
-
|
|
1987
|
+
const raw = drag.from + (clientX - drag.x) / drag.travel;
|
|
1988
|
+
const fraction = clamp(raw, 0, 1);
|
|
1989
|
+
pastRef.current = (raw - fraction) * drag.travel;
|
|
1579
1990
|
let next = min + fraction * (max - min);
|
|
1580
1991
|
const increment = Number(step2);
|
|
1581
1992
|
if (step2 !== "any" && Number.isFinite(increment) && increment > 0) {
|
|
@@ -1594,13 +2005,11 @@ var GlassSlider = React8.forwardRef(
|
|
|
1594
2005
|
if (event.pointerType !== "touch") input2.focus({ preventScroll: true });
|
|
1595
2006
|
const box = root.getBoundingClientRect();
|
|
1596
2007
|
const inset = showThumb ? 19 * box.width / root.offsetWidth : 0;
|
|
1597
|
-
const
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
drag = { id: event.pointerId, left: box.left, width: box.width, offset };
|
|
2008
|
+
const from = max > min ? clamp((input2.valueAsNumber - min) / (max - min), 0, 1) : 0;
|
|
2009
|
+
drag = { id: event.pointerId, x: event.clientX, from, travel: Math.max(1, box.width - inset * 2) };
|
|
2010
|
+
pastRef.current = 0;
|
|
1601
2011
|
root.dataset.dragging = "";
|
|
1602
2012
|
root.setPointerCapture(event.pointerId);
|
|
1603
|
-
update(event.clientX);
|
|
1604
2013
|
};
|
|
1605
2014
|
const move = (event) => {
|
|
1606
2015
|
if (event.pointerId !== drag?.id) return;
|
|
@@ -1611,6 +2020,7 @@ var GlassSlider = React8.forwardRef(
|
|
|
1611
2020
|
if (!drag) return;
|
|
1612
2021
|
const id = drag.id;
|
|
1613
2022
|
drag = null;
|
|
2023
|
+
pastRef.current = 0;
|
|
1614
2024
|
delete root.dataset.dragging;
|
|
1615
2025
|
if (root.hasPointerCapture(id)) root.releasePointerCapture(id);
|
|
1616
2026
|
};
|
|
@@ -1619,6 +2029,7 @@ var GlassSlider = React8.forwardRef(
|
|
|
1619
2029
|
update(event.clientX);
|
|
1620
2030
|
release();
|
|
1621
2031
|
};
|
|
2032
|
+
const unguard = guardSelection(root);
|
|
1622
2033
|
root.addEventListener("pointerdown", down);
|
|
1623
2034
|
root.addEventListener("pointermove", move);
|
|
1624
2035
|
root.addEventListener("pointerup", up);
|
|
@@ -1627,6 +2038,7 @@ var GlassSlider = React8.forwardRef(
|
|
|
1627
2038
|
window.addEventListener("blur", release);
|
|
1628
2039
|
return () => {
|
|
1629
2040
|
release();
|
|
2041
|
+
unguard();
|
|
1630
2042
|
root.removeEventListener("pointerdown", down);
|
|
1631
2043
|
root.removeEventListener("pointermove", move);
|
|
1632
2044
|
root.removeEventListener("pointerup", up);
|
|
@@ -1636,8 +2048,8 @@ var GlassSlider = React8.forwardRef(
|
|
|
1636
2048
|
};
|
|
1637
2049
|
}, [min, max, step2, showThumb]);
|
|
1638
2050
|
const strength = Math.max(1, Math.min(10, intensity)) / 5;
|
|
1639
|
-
const [mirrored, setMirrored] =
|
|
1640
|
-
|
|
2051
|
+
const [mirrored, setMirrored] = React9.useState(false);
|
|
2052
|
+
useEffect6(() => setMirrored(!canRefractBackdrop()), []);
|
|
1641
2053
|
const progress = max > min ? clamp((Number(value) - min) / (max - min), 0, 1) : 0;
|
|
1642
2054
|
useRefraction(
|
|
1643
2055
|
thumbRef,
|
|
@@ -1647,18 +2059,20 @@ var GlassSlider = React8.forwardRef(
|
|
|
1647
2059
|
() => parseFloat(rootRef.current?.style.getPropertyValue("--lg-lift") || "0") > 0.01
|
|
1648
2060
|
);
|
|
1649
2061
|
useRefraction(blockRef, { kind: "surface", strength }, !showThumb);
|
|
1650
|
-
|
|
2062
|
+
useEffect6(() => {
|
|
1651
2063
|
if (!showThumb) return;
|
|
1652
2064
|
const input2 = inputRef.current;
|
|
1653
2065
|
const thumb = thumbRef.current;
|
|
1654
2066
|
const face = faceRef.current;
|
|
1655
2067
|
const root = rootRef.current;
|
|
1656
|
-
const v = { lift: 0, stretch: 0 };
|
|
2068
|
+
const v = { lift: 0, stretch: 0, over: 0 };
|
|
1657
2069
|
const paint = () => {
|
|
1658
2070
|
const s = 0.655 + 0.345 * v.lift;
|
|
1659
|
-
|
|
2071
|
+
const pull = Math.abs(v.over) / 58 * 0.6;
|
|
2072
|
+
thumb.style.scale = `${s * (1 + v.stretch + pull)} ${s * (1 - v.stretch * 0.5 - pull * 0.4)}`;
|
|
1660
2073
|
face.style.opacity = String(1 - clamp(v.lift, 0, 1) * 0.92);
|
|
1661
2074
|
root.style.setProperty("--lg-lift", String(clamp(v.lift, 0, 1)));
|
|
2075
|
+
root.style.setProperty("--lg-over", `${v.over.toFixed(2)}px`);
|
|
1662
2076
|
if (v.lift < 0.01 && lift.target === 0) delete root.dataset.lifted;
|
|
1663
2077
|
};
|
|
1664
2078
|
const lift = createSpring(0, SPRINGS.lift, (x) => {
|
|
@@ -1669,6 +2083,10 @@ var GlassSlider = React8.forwardRef(
|
|
|
1669
2083
|
v.stretch = x;
|
|
1670
2084
|
paint();
|
|
1671
2085
|
});
|
|
2086
|
+
const over = createSpring(0, SPRINGS.release, (x) => {
|
|
2087
|
+
v.over = x;
|
|
2088
|
+
paint();
|
|
2089
|
+
});
|
|
1672
2090
|
paint();
|
|
1673
2091
|
let lastX = 0;
|
|
1674
2092
|
let lastT = 0;
|
|
@@ -1689,6 +2107,8 @@ var GlassSlider = React8.forwardRef(
|
|
|
1689
2107
|
lastT = event.timeStamp;
|
|
1690
2108
|
stretch.tune(SPRINGS.drag);
|
|
1691
2109
|
stretch.set(clamp(speed * 0.015, 0, 0.035));
|
|
2110
|
+
over.tune(SPRINGS.drag);
|
|
2111
|
+
over.set(rubberband(pastRef.current, 12, 0.5));
|
|
1692
2112
|
};
|
|
1693
2113
|
const up = () => {
|
|
1694
2114
|
if (lift.target === 0) return;
|
|
@@ -1696,6 +2116,8 @@ var GlassSlider = React8.forwardRef(
|
|
|
1696
2116
|
lift.set(0);
|
|
1697
2117
|
stretch.tune(SPRINGS.release);
|
|
1698
2118
|
stretch.set(0);
|
|
2119
|
+
over.tune(SPRINGS.release);
|
|
2120
|
+
over.set(0);
|
|
1699
2121
|
};
|
|
1700
2122
|
root.addEventListener("pointerdown", down);
|
|
1701
2123
|
window.addEventListener("pointermove", move);
|
|
@@ -1706,6 +2128,7 @@ var GlassSlider = React8.forwardRef(
|
|
|
1706
2128
|
return () => {
|
|
1707
2129
|
lift.stop();
|
|
1708
2130
|
stretch.stop();
|
|
2131
|
+
over.stop();
|
|
1709
2132
|
root.removeEventListener("pointerdown", down);
|
|
1710
2133
|
window.removeEventListener("pointermove", move);
|
|
1711
2134
|
window.removeEventListener("pointerup", up);
|
|
@@ -1715,7 +2138,7 @@ var GlassSlider = React8.forwardRef(
|
|
|
1715
2138
|
delete root.dataset.lifted;
|
|
1716
2139
|
};
|
|
1717
2140
|
}, [showThumb]);
|
|
1718
|
-
|
|
2141
|
+
useEffect6(() => {
|
|
1719
2142
|
if (showThumb) return;
|
|
1720
2143
|
const input2 = inputRef.current;
|
|
1721
2144
|
const block = blockRef.current;
|
|
@@ -1739,17 +2162,15 @@ var GlassSlider = React8.forwardRef(
|
|
|
1739
2162
|
let active2 = null;
|
|
1740
2163
|
const down = (event) => {
|
|
1741
2164
|
if (input2.disabled || !event.isPrimary || event.button !== 0) return;
|
|
1742
|
-
active2 = { id: event.pointerId
|
|
2165
|
+
active2 = { id: event.pointerId };
|
|
1743
2166
|
swell.tune(SPRINGS.press);
|
|
1744
2167
|
swell.set(1);
|
|
1745
2168
|
haptic();
|
|
1746
2169
|
};
|
|
1747
2170
|
const move = (event) => {
|
|
1748
2171
|
if (event.pointerId !== active2?.id) return;
|
|
1749
|
-
const { box } = active2;
|
|
1750
|
-
const past = event.clientX < box.left ? event.clientX - box.left : event.clientX > box.right ? event.clientX - box.right : 0;
|
|
1751
2172
|
over.tune(SPRINGS.drag);
|
|
1752
|
-
over.set(rubberband(
|
|
2173
|
+
over.set(rubberband(pastRef.current, 26, 0.6));
|
|
1753
2174
|
};
|
|
1754
2175
|
const reset = () => {
|
|
1755
2176
|
if (!active2) return;
|
|
@@ -1779,7 +2200,7 @@ var GlassSlider = React8.forwardRef(
|
|
|
1779
2200
|
window.removeEventListener("pointercancel", up);
|
|
1780
2201
|
};
|
|
1781
2202
|
}, [showThumb]);
|
|
1782
|
-
const input = /* @__PURE__ */
|
|
2203
|
+
const input = /* @__PURE__ */ jsx10(
|
|
1783
2204
|
"input",
|
|
1784
2205
|
{
|
|
1785
2206
|
ref: inputRef,
|
|
@@ -1799,7 +2220,7 @@ var GlassSlider = React8.forwardRef(
|
|
|
1799
2220
|
);
|
|
1800
2221
|
const vars = { "--lg-progress": progress, ...tint ? { "--lg-slider-fill": tint } : {}, ...style };
|
|
1801
2222
|
if (!showThumb) {
|
|
1802
|
-
return /* @__PURE__ */
|
|
2223
|
+
return /* @__PURE__ */ jsxs8(
|
|
1803
2224
|
"div",
|
|
1804
2225
|
{
|
|
1805
2226
|
ref: rootRef,
|
|
@@ -1807,16 +2228,16 @@ var GlassSlider = React8.forwardRef(
|
|
|
1807
2228
|
"data-liquid-glass": "",
|
|
1808
2229
|
style: vars,
|
|
1809
2230
|
children: [
|
|
1810
|
-
/* @__PURE__ */
|
|
1811
|
-
/* @__PURE__ */
|
|
1812
|
-
icon && /* @__PURE__ */
|
|
1813
|
-
label2 && /* @__PURE__ */
|
|
1814
|
-
/* @__PURE__ */
|
|
2231
|
+
/* @__PURE__ */ jsxs8("div", { ref: blockRef, className: "lg-glass lg-slider__block", children: [
|
|
2232
|
+
/* @__PURE__ */ jsxs8("span", { className: "lg-slider__block-content", "aria-hidden": "true", children: [
|
|
2233
|
+
icon && /* @__PURE__ */ jsx10("span", { className: "lg-slider__icon", children: icon }),
|
|
2234
|
+
label2 && /* @__PURE__ */ jsx10("span", { className: "lg-slider__label", children: label2 }),
|
|
2235
|
+
/* @__PURE__ */ jsx10("span", { className: "lg-slider__value", children: Math.round(Number(value)) })
|
|
1815
2236
|
] }),
|
|
1816
|
-
/* @__PURE__ */
|
|
1817
|
-
icon && /* @__PURE__ */
|
|
1818
|
-
label2 && /* @__PURE__ */
|
|
1819
|
-
/* @__PURE__ */
|
|
2237
|
+
/* @__PURE__ */ jsx10("span", { className: "lg-slider__block-fill", "aria-hidden": "true", children: /* @__PURE__ */ jsxs8("span", { className: "lg-slider__block-content lg-slider__block-content--lit", children: [
|
|
2238
|
+
icon && /* @__PURE__ */ jsx10("span", { className: "lg-slider__icon", children: icon }),
|
|
2239
|
+
label2 && /* @__PURE__ */ jsx10("span", { className: "lg-slider__label", children: label2 }),
|
|
2240
|
+
/* @__PURE__ */ jsx10("span", { className: "lg-slider__value", children: Math.round(Number(value)) })
|
|
1820
2241
|
] }) })
|
|
1821
2242
|
] }),
|
|
1822
2243
|
input
|
|
@@ -1824,7 +2245,7 @@ var GlassSlider = React8.forwardRef(
|
|
|
1824
2245
|
}
|
|
1825
2246
|
);
|
|
1826
2247
|
}
|
|
1827
|
-
return /* @__PURE__ */
|
|
2248
|
+
return /* @__PURE__ */ jsxs8(
|
|
1828
2249
|
"div",
|
|
1829
2250
|
{
|
|
1830
2251
|
ref: rootRef,
|
|
@@ -1833,8 +2254,8 @@ var GlassSlider = React8.forwardRef(
|
|
|
1833
2254
|
"data-mirror": mirrored ? "" : void 0,
|
|
1834
2255
|
style: vars,
|
|
1835
2256
|
children: [
|
|
1836
|
-
/* @__PURE__ */
|
|
1837
|
-
/* @__PURE__ */
|
|
2257
|
+
/* @__PURE__ */ jsx10("span", { className: "lg-slider__rail", "aria-hidden": "true", children: /* @__PURE__ */ jsx10("span", { className: "lg-slider__fill" }) }),
|
|
2258
|
+
/* @__PURE__ */ jsx10("span", { className: "lg-slider__thumb-slot", "aria-hidden": "true", children: /* @__PURE__ */ jsx10("span", { ref: thumbRef, className: "lg-glass lg-slider__thumb", "data-lg-mirror-bare": "", children: /* @__PURE__ */ jsx10("span", { ref: faceRef, className: "lg-slider__face" }) }) }),
|
|
1838
2259
|
input
|
|
1839
2260
|
]
|
|
1840
2261
|
}
|
|
@@ -1844,22 +2265,22 @@ var GlassSlider = React8.forwardRef(
|
|
|
1844
2265
|
GlassSlider.displayName = "GlassSlider";
|
|
1845
2266
|
|
|
1846
2267
|
// src/components/GlassSwitch/GlassSwitch.tsx
|
|
1847
|
-
import
|
|
1848
|
-
import { jsx as
|
|
2268
|
+
import React10, { useEffect as useEffect7, useImperativeHandle as useImperativeHandle5, useRef as useRef9, useState as useState4 } from "react";
|
|
2269
|
+
import { jsx as jsx11, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
1849
2270
|
var SETTLE = springFrom(0.36, 0.68);
|
|
1850
2271
|
var REST = 0.655;
|
|
1851
2272
|
var TRAVEL = 22;
|
|
1852
|
-
var GlassSwitch =
|
|
2273
|
+
var GlassSwitch = React10.forwardRef(
|
|
1853
2274
|
({ checked: checkedProp, defaultChecked = false, onChange, tint, intensity = 5, className, style, disabled, ...rest }, forwardedRef) => {
|
|
1854
|
-
const ref =
|
|
1855
|
-
const thumbRef =
|
|
1856
|
-
const fillRef =
|
|
1857
|
-
const faceRef =
|
|
2275
|
+
const ref = useRef9(null);
|
|
2276
|
+
const thumbRef = useRef9(null);
|
|
2277
|
+
const fillRef = useRef9(null);
|
|
2278
|
+
const faceRef = useRef9(null);
|
|
1858
2279
|
useImperativeHandle5(forwardedRef, () => ref.current);
|
|
1859
|
-
const [inner, setInner] =
|
|
2280
|
+
const [inner, setInner] = useState4(defaultChecked);
|
|
1860
2281
|
const controlled = checkedProp !== void 0;
|
|
1861
2282
|
const checked = controlled ? checkedProp : inner;
|
|
1862
|
-
const latest =
|
|
2283
|
+
const latest = useRef9({ checked, set: (_) => {
|
|
1863
2284
|
}, disabled });
|
|
1864
2285
|
latest.current = {
|
|
1865
2286
|
checked,
|
|
@@ -1869,15 +2290,15 @@ var GlassSwitch = React9.forwardRef(
|
|
|
1869
2290
|
onChange?.(next);
|
|
1870
2291
|
}
|
|
1871
2292
|
};
|
|
1872
|
-
const sync =
|
|
2293
|
+
const sync = useRef9(null);
|
|
1873
2294
|
useRefraction(
|
|
1874
2295
|
thumbRef,
|
|
1875
|
-
{ kind: "lens", zoom: 1, dispersion: 0.5, strength: Math.max(1, Math.min(10, intensity)) / 5 },
|
|
2296
|
+
{ kind: "lens", zoom: 0.72, zoomX: 1, dispersion: 0.5, copy: true, strength: Math.max(1, Math.min(10, intensity)) / 5 },
|
|
1876
2297
|
true,
|
|
1877
2298
|
ref,
|
|
1878
2299
|
() => parseFloat(ref.current?.style.getPropertyValue("--lg-lift") || "0") > 0.01
|
|
1879
2300
|
);
|
|
1880
|
-
|
|
2301
|
+
useEffect7(() => {
|
|
1881
2302
|
const el2 = ref.current;
|
|
1882
2303
|
const thumb = thumbRef.current;
|
|
1883
2304
|
const fill = fillRef.current;
|
|
@@ -1888,6 +2309,8 @@ var GlassSwitch = React9.forwardRef(
|
|
|
1888
2309
|
const sy = s * (1 - v.stretch * 0.5);
|
|
1889
2310
|
thumb.style.transform = `translate(${v.x * TRAVEL}px, -50%) scale(${sx}, ${sy})`;
|
|
1890
2311
|
const l = clamp(v.lift, 0, 1);
|
|
2312
|
+
el2.style.setProperty("--lg-knob-x", `${(21 + v.x * TRAVEL).toFixed(2)}px`);
|
|
2313
|
+
el2.style.setProperty("--lg-hole", `${(l > 0.01 ? 23 * sx : 0).toFixed(2)}px`);
|
|
1891
2314
|
el2.style.setProperty("--lg-lift", String(l));
|
|
1892
2315
|
el2.toggleAttribute("data-lifted", l > 0.01);
|
|
1893
2316
|
};
|
|
@@ -1977,6 +2400,7 @@ var GlassSwitch = React9.forwardRef(
|
|
|
1977
2400
|
latest.current.set(next);
|
|
1978
2401
|
sync.current?.(next);
|
|
1979
2402
|
};
|
|
2403
|
+
const unguard = guardSelection(el2);
|
|
1980
2404
|
el2.addEventListener("pointerdown", down);
|
|
1981
2405
|
el2.addEventListener("pointermove", move);
|
|
1982
2406
|
el2.addEventListener("pointerup", up);
|
|
@@ -1985,6 +2409,7 @@ var GlassSwitch = React9.forwardRef(
|
|
|
1985
2409
|
return () => {
|
|
1986
2410
|
clearTimeout(dropTimer);
|
|
1987
2411
|
[position, lift, color].forEach((s) => s.stop());
|
|
2412
|
+
unguard();
|
|
1988
2413
|
el2.removeEventListener("pointerdown", down);
|
|
1989
2414
|
el2.removeEventListener("pointermove", move);
|
|
1990
2415
|
el2.removeEventListener("pointerup", up);
|
|
@@ -1992,10 +2417,10 @@ var GlassSwitch = React9.forwardRef(
|
|
|
1992
2417
|
el2.removeEventListener("click", click);
|
|
1993
2418
|
};
|
|
1994
2419
|
}, []);
|
|
1995
|
-
|
|
2420
|
+
useEffect7(() => {
|
|
1996
2421
|
sync.current?.(checked);
|
|
1997
2422
|
}, [checked]);
|
|
1998
|
-
return /* @__PURE__ */
|
|
2423
|
+
return /* @__PURE__ */ jsxs9(
|
|
1999
2424
|
"button",
|
|
2000
2425
|
{
|
|
2001
2426
|
ref,
|
|
@@ -2012,8 +2437,9 @@ var GlassSwitch = React9.forwardRef(
|
|
|
2012
2437
|
rest.onKeyDown?.(event);
|
|
2013
2438
|
},
|
|
2014
2439
|
children: [
|
|
2015
|
-
/* @__PURE__ */
|
|
2016
|
-
/* @__PURE__ */
|
|
2440
|
+
/* @__PURE__ */ jsx11("span", { className: "lg-switch__track", "aria-hidden": "true" }),
|
|
2441
|
+
/* @__PURE__ */ jsx11("span", { ref: fillRef, className: "lg-switch__fill", "aria-hidden": "true" }),
|
|
2442
|
+
/* @__PURE__ */ jsx11("span", { ref: thumbRef, className: "lg-glass lg-switch__thumb", "aria-hidden": "true", children: /* @__PURE__ */ jsx11("span", { ref: faceRef, className: "lg-switch__face" }) })
|
|
2017
2443
|
]
|
|
2018
2444
|
}
|
|
2019
2445
|
);
|
|
@@ -2023,28 +2449,28 @@ GlassSwitch.displayName = "GlassSwitch";
|
|
|
2023
2449
|
|
|
2024
2450
|
// src/filters/LiquidGlassFilter.tsx
|
|
2025
2451
|
import { createContext, useContext } from "react";
|
|
2026
|
-
import { jsx as
|
|
2452
|
+
import { jsx as jsx12, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
2027
2453
|
var GlassFilterContext = createContext(false);
|
|
2028
2454
|
function LiquidGlassFilter({ children }) {
|
|
2029
|
-
return /* @__PURE__ */
|
|
2030
|
-
/* @__PURE__ */
|
|
2455
|
+
return /* @__PURE__ */ jsxs10(GlassFilterContext.Provider, { value: true, children: [
|
|
2456
|
+
/* @__PURE__ */ jsx12(GlassFilterSVG, {}),
|
|
2031
2457
|
children
|
|
2032
2458
|
] });
|
|
2033
2459
|
}
|
|
2034
2460
|
function GlassFilterSVG() {
|
|
2035
|
-
return /* @__PURE__ */
|
|
2461
|
+
return /* @__PURE__ */ jsx12(
|
|
2036
2462
|
"svg",
|
|
2037
2463
|
{
|
|
2038
2464
|
width: "0",
|
|
2039
2465
|
height: "0",
|
|
2040
2466
|
style: { position: "absolute", pointerEvents: "none" },
|
|
2041
2467
|
"aria-hidden": "true",
|
|
2042
|
-
children: /* @__PURE__ */
|
|
2468
|
+
children: /* @__PURE__ */ jsx12("defs", { children: Array.from({ length: 10 }, (_, i) => {
|
|
2043
2469
|
const level = i + 1;
|
|
2044
2470
|
const scale = level * 2;
|
|
2045
2471
|
const freq1 = 0.012 + level * 1e-3;
|
|
2046
2472
|
const freq2 = 0.01 + level * 8e-4;
|
|
2047
|
-
return /* @__PURE__ */
|
|
2473
|
+
return /* @__PURE__ */ jsxs10(
|
|
2048
2474
|
"filter",
|
|
2049
2475
|
{
|
|
2050
2476
|
id: `liquid-glass-refract-${level}`,
|
|
@@ -2054,7 +2480,7 @@ function GlassFilterSVG() {
|
|
|
2054
2480
|
height: "120%",
|
|
2055
2481
|
colorInterpolationFilters: "sRGB",
|
|
2056
2482
|
children: [
|
|
2057
|
-
/* @__PURE__ */
|
|
2483
|
+
/* @__PURE__ */ jsx12(
|
|
2058
2484
|
"feTurbulence",
|
|
2059
2485
|
{
|
|
2060
2486
|
type: "fractalNoise",
|
|
@@ -2064,7 +2490,7 @@ function GlassFilterSVG() {
|
|
|
2064
2490
|
result: "noise"
|
|
2065
2491
|
}
|
|
2066
2492
|
),
|
|
2067
|
-
/* @__PURE__ */
|
|
2493
|
+
/* @__PURE__ */ jsx12(
|
|
2068
2494
|
"feDisplacementMap",
|
|
2069
2495
|
{
|
|
2070
2496
|
in: "SourceGraphic",
|
|
@@ -2161,11 +2587,11 @@ function useGlassEffect(options = {}) {
|
|
|
2161
2587
|
}
|
|
2162
2588
|
|
|
2163
2589
|
// src/hooks/useGlassAnimation.ts
|
|
2164
|
-
import { useCallback, useState as
|
|
2590
|
+
import { useCallback, useState as useState5 } from "react";
|
|
2165
2591
|
function useGlassAnimation() {
|
|
2166
|
-
const [isHovered, setIsHovered] =
|
|
2167
|
-
const [isPressed, setIsPressed] =
|
|
2168
|
-
const [isFocused, setIsFocused] =
|
|
2592
|
+
const [isHovered, setIsHovered] = useState5(false);
|
|
2593
|
+
const [isPressed, setIsPressed] = useState5(false);
|
|
2594
|
+
const [isFocused, setIsFocused] = useState5(false);
|
|
2169
2595
|
const handlers = {
|
|
2170
2596
|
onPointerEnter: useCallback(() => setIsHovered(true), []),
|
|
2171
2597
|
onPointerLeave: useCallback(() => {
|
|
@@ -2183,6 +2609,7 @@ export {
|
|
|
2183
2609
|
GlassButton,
|
|
2184
2610
|
GlassCard,
|
|
2185
2611
|
GlassInput,
|
|
2612
|
+
GlassMenu,
|
|
2186
2613
|
GlassNav,
|
|
2187
2614
|
GlassSegmented,
|
|
2188
2615
|
GlassSheet,
|