@zakisheriff/liquid-glass 0.2.6 → 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 +209 -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 +648 -210
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +635 -198
- 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,105 +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) => {
|
|
1139
|
+
if (event.defaultPrevented || closing) return;
|
|
1016
1140
|
const target = event.target;
|
|
1017
|
-
|
|
1141
|
+
const raised = position.value <= 1;
|
|
1142
|
+
if (raised && !target.closest(".lg-sheet__grabber-zone") && sheet.scrollTop > 0) return;
|
|
1018
1143
|
if (target.closest('input, textarea, button, a, [role="slider"], [role="switch"]')) return;
|
|
1019
|
-
|
|
1144
|
+
position.stop();
|
|
1145
|
+
gesture = { id: event.pointerId, y: event.clientY, from: position.value, t: event.timeStamp, v: 0, last: position.value };
|
|
1020
1146
|
sheet.setPointerCapture(event.pointerId);
|
|
1021
1147
|
};
|
|
1022
1148
|
const move = (event) => {
|
|
1023
1149
|
if (event.pointerId !== gesture?.id) return;
|
|
1024
|
-
const
|
|
1150
|
+
const raw = gesture.from + event.clientY - gesture.y;
|
|
1151
|
+
const y = raw < 0 ? rubberband(raw, height, 0.3) : raw;
|
|
1025
1152
|
const dt = Math.max(1, event.timeStamp - gesture.t);
|
|
1026
|
-
gesture.v = (
|
|
1153
|
+
gesture.v = gesture.v * 0.2 + (y - gesture.last) / dt * 0.8;
|
|
1027
1154
|
gesture.t = event.timeStamp;
|
|
1028
|
-
|
|
1029
|
-
|
|
1155
|
+
gesture.last = y;
|
|
1156
|
+
position.set(y, true);
|
|
1157
|
+
paint(y);
|
|
1030
1158
|
};
|
|
1031
1159
|
const up = (event) => {
|
|
1032
1160
|
if (event.pointerId !== gesture?.id) return;
|
|
1033
|
-
const
|
|
1161
|
+
const { v, last: last2 } = gesture;
|
|
1034
1162
|
gesture = null;
|
|
1035
|
-
const
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
settle.stop();
|
|
1041
|
-
const p = 1 - clamp(drag / (height + 24), 0, 1);
|
|
1042
|
-
drag = 0;
|
|
1043
|
-
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);
|
|
1044
1168
|
closeRef.current?.();
|
|
1045
|
-
|
|
1046
|
-
settle.set(0);
|
|
1169
|
+
return;
|
|
1047
1170
|
}
|
|
1171
|
+
const target = stops.reduce((best, stop) => Math.abs(stop - projected) < Math.abs(best - projected) ? stop : best, stops[0]);
|
|
1172
|
+
go(target, SNAP);
|
|
1048
1173
|
};
|
|
1049
1174
|
const key = (event) => {
|
|
1050
1175
|
if (event.key === "Escape") closeRef.current?.();
|
|
1051
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);
|
|
1052
1185
|
sheet.addEventListener("pointerdown", down);
|
|
1053
1186
|
sheet.addEventListener("pointermove", move);
|
|
1054
1187
|
sheet.addEventListener("pointerup", up);
|
|
1055
1188
|
sheet.addEventListener("pointercancel", up);
|
|
1056
1189
|
window.addEventListener("keydown", key);
|
|
1057
1190
|
const overflow = document.body.style.overflow;
|
|
1058
|
-
document.body.style.overflow = "hidden";
|
|
1191
|
+
if (!container2) document.body.style.overflow = "hidden";
|
|
1059
1192
|
sheet.focus({ preventScroll: true });
|
|
1060
1193
|
return () => {
|
|
1061
|
-
|
|
1062
|
-
|
|
1194
|
+
position.stop();
|
|
1195
|
+
api.current = null;
|
|
1196
|
+
observer.disconnect();
|
|
1063
1197
|
sheet.removeEventListener("pointerdown", down);
|
|
1064
1198
|
sheet.removeEventListener("pointermove", move);
|
|
1065
1199
|
sheet.removeEventListener("pointerup", up);
|
|
1066
1200
|
sheet.removeEventListener("pointercancel", up);
|
|
1067
1201
|
window.removeEventListener("keydown", key);
|
|
1068
|
-
document.body.style.overflow = overflow;
|
|
1202
|
+
if (!container2) document.body.style.overflow = overflow;
|
|
1069
1203
|
};
|
|
1070
|
-
}, [mounted]);
|
|
1204
|
+
}, [mounted, container2, stopsKey]);
|
|
1071
1205
|
if (!mounted || typeof document === "undefined") return null;
|
|
1072
1206
|
return createPortal(
|
|
1073
|
-
/* @__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: [
|
|
1074
1208
|
/* @__PURE__ */ jsx5("div", { ref: scrimRef, className: "lg-sheet__scrim", onClick: () => onClose?.(), "aria-hidden": "true" }),
|
|
1075
1209
|
/* @__PURE__ */ jsxs3(
|
|
1076
1210
|
"div",
|
|
@@ -1080,7 +1214,7 @@ var GlassSheet = ({ open, onClose, intensity = 5, tint, children, "aria-label":
|
|
|
1080
1214
|
"aria-modal": "true",
|
|
1081
1215
|
"aria-label": ariaLabel,
|
|
1082
1216
|
tabIndex: -1,
|
|
1083
|
-
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(" "),
|
|
1084
1218
|
style: tint ? { "--lg-host-tint": tint } : void 0,
|
|
1085
1219
|
children: [
|
|
1086
1220
|
/* @__PURE__ */ jsx5("div", { className: "lg-sheet__grabber-zone", "aria-hidden": "true", children: /* @__PURE__ */ jsx5("span", { className: "lg-sheet__grabber" }) }),
|
|
@@ -1089,24 +1223,263 @@ var GlassSheet = ({ open, onClose, intensity = 5, tint, children, "aria-label":
|
|
|
1089
1223
|
}
|
|
1090
1224
|
)
|
|
1091
1225
|
] }),
|
|
1092
|
-
document.body
|
|
1226
|
+
container2 ?? document.body
|
|
1093
1227
|
);
|
|
1094
1228
|
};
|
|
1095
1229
|
GlassSheet.displayName = "GlassSheet";
|
|
1096
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
|
+
|
|
1097
1470
|
// src/components/GlassNav/GlassNav.tsx
|
|
1098
|
-
import
|
|
1471
|
+
import React7 from "react";
|
|
1099
1472
|
|
|
1100
1473
|
// src/components/internal/LensTrack.tsx
|
|
1101
|
-
import { useRef as
|
|
1474
|
+
import { useRef as useRef7 } from "react";
|
|
1102
1475
|
|
|
1103
1476
|
// src/engine/lensTrack.ts
|
|
1104
|
-
import { useEffect as
|
|
1477
|
+
import { useEffect as useEffect5, useRef as useRef6 } from "react";
|
|
1105
1478
|
function useLensTrack(refs, options) {
|
|
1106
|
-
const latest =
|
|
1479
|
+
const latest = useRef6(options);
|
|
1107
1480
|
latest.current = options;
|
|
1108
|
-
const api =
|
|
1109
|
-
|
|
1481
|
+
const api = useRef6(null);
|
|
1482
|
+
useEffect5(() => {
|
|
1110
1483
|
const bar = refs.bar.current;
|
|
1111
1484
|
const lens = refs.lens.current;
|
|
1112
1485
|
const glass = refs.glass.current;
|
|
@@ -1123,7 +1496,7 @@ function useLensTrack(refs, options) {
|
|
|
1123
1496
|
let gesture = null;
|
|
1124
1497
|
let dropTimer = 0;
|
|
1125
1498
|
let suppressClick = false;
|
|
1126
|
-
const buttons = Array.from(bar.querySelectorAll("[data-lg-item]"));
|
|
1499
|
+
const buttons = Array.from(bar.querySelectorAll(":scope > [data-lg-item]"));
|
|
1127
1500
|
let glyphs = [];
|
|
1128
1501
|
const preview = (index) => {
|
|
1129
1502
|
if (index === void 0) delete bar.dataset.previewing;
|
|
@@ -1146,14 +1519,23 @@ function useLensTrack(refs, options) {
|
|
|
1146
1519
|
select.style.width = `${slot}px`;
|
|
1147
1520
|
select.style.left = `${pad}px`;
|
|
1148
1521
|
glyphs = buttons.flatMap(
|
|
1149
|
-
(button) => Array.from(button.querySelectorAll(".lg-nav__label, .lg-nav__icon > .lg-symbol")).map((node) =>
|
|
1150
|
-
node
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
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
|
+
})
|
|
1157
1539
|
);
|
|
1158
1540
|
};
|
|
1159
1541
|
const paint = () => {
|
|
@@ -1175,8 +1557,24 @@ function useLensTrack(refs, options) {
|
|
|
1175
1557
|
if (lift2 <= 0.02 && !gesture) {
|
|
1176
1558
|
glyph.node.style.removeProperty("--lg-content-tint");
|
|
1177
1559
|
glyph.node.style.removeProperty("transform");
|
|
1560
|
+
glyph.host.style.removeProperty("--lg-content-hide");
|
|
1178
1561
|
continue;
|
|
1179
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
|
+
}
|
|
1180
1578
|
const zoom = latest.current.contentZoom ?? 1;
|
|
1181
1579
|
const ry = H * ky / (2 * zoom);
|
|
1182
1580
|
const rx = H * kx / (2 * zoom);
|
|
@@ -1369,6 +1767,7 @@ function useLensTrack(refs, options) {
|
|
|
1369
1767
|
x.set(current * slot, true);
|
|
1370
1768
|
bar.dataset.ready = "";
|
|
1371
1769
|
observer.observe(bar);
|
|
1770
|
+
const unguard = guardSelection(bar);
|
|
1372
1771
|
bar.addEventListener("pointerdown", onDown);
|
|
1373
1772
|
window.addEventListener("pointermove", onMove);
|
|
1374
1773
|
window.addEventListener("pointerup", onUp);
|
|
@@ -1382,6 +1781,7 @@ function useLensTrack(refs, options) {
|
|
|
1382
1781
|
clearTimeout(dropTimer);
|
|
1383
1782
|
api.current = null;
|
|
1384
1783
|
[x, lift, swell].forEach((s) => s.stop());
|
|
1784
|
+
unguard();
|
|
1385
1785
|
observer.disconnect();
|
|
1386
1786
|
bar.removeEventListener("pointerdown", onDown);
|
|
1387
1787
|
window.removeEventListener("pointermove", onMove);
|
|
@@ -1394,19 +1794,20 @@ function useLensTrack(refs, options) {
|
|
|
1394
1794
|
delete bar.dataset.ready;
|
|
1395
1795
|
delete bar.dataset.lifted;
|
|
1396
1796
|
preview();
|
|
1397
|
-
glyphs.forEach(({ node }) => {
|
|
1797
|
+
glyphs.forEach(({ node, host }) => {
|
|
1398
1798
|
node.style.removeProperty("--lg-content-tint");
|
|
1399
1799
|
node.style.removeProperty("transform");
|
|
1800
|
+
host.style.removeProperty("--lg-content-hide");
|
|
1400
1801
|
});
|
|
1401
1802
|
};
|
|
1402
1803
|
}, [options.count]);
|
|
1403
|
-
|
|
1804
|
+
useEffect5(() => {
|
|
1404
1805
|
api.current?.setIndex(options.index);
|
|
1405
1806
|
}, [options.index]);
|
|
1406
1807
|
}
|
|
1407
1808
|
|
|
1408
1809
|
// src/components/internal/LensTrack.tsx
|
|
1409
|
-
import { jsx as
|
|
1810
|
+
import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
1410
1811
|
function LensTrack({
|
|
1411
1812
|
items,
|
|
1412
1813
|
labels,
|
|
@@ -1418,28 +1819,36 @@ function LensTrack({
|
|
|
1418
1819
|
style,
|
|
1419
1820
|
"aria-label": ariaLabel
|
|
1420
1821
|
}) {
|
|
1421
|
-
const bar =
|
|
1422
|
-
const glass =
|
|
1423
|
-
const lens =
|
|
1424
|
-
const select =
|
|
1822
|
+
const bar = useRef7(null);
|
|
1823
|
+
const glass = useRef7(null);
|
|
1824
|
+
const lens = useRef7(null);
|
|
1825
|
+
const select = useRef7(null);
|
|
1425
1826
|
const strength = Math.max(1, Math.min(10, intensity)) / 5;
|
|
1426
1827
|
const tabbar = variant === "tabbar";
|
|
1427
1828
|
const zoom = tabbar ? 1.14 : 1.1;
|
|
1428
1829
|
useRefraction(glass, { kind: "surface", strength });
|
|
1429
|
-
|
|
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
|
+
);
|
|
1430
1838
|
useLensTrack(
|
|
1431
1839
|
{ bar, glass, lens, select },
|
|
1432
1840
|
{
|
|
1433
1841
|
count: items.length,
|
|
1434
1842
|
index,
|
|
1435
1843
|
onSelect: (next) => onChange?.(next),
|
|
1436
|
-
overhang
|
|
1844
|
+
overhang,
|
|
1437
1845
|
spread: tabbar ? 0.3 : 0.16,
|
|
1438
|
-
contentZoom:
|
|
1846
|
+
contentZoom: zoom,
|
|
1847
|
+
copied: true,
|
|
1439
1848
|
swell: tabbar ? 8 : 14
|
|
1440
1849
|
}
|
|
1441
1850
|
);
|
|
1442
|
-
return /* @__PURE__ */
|
|
1851
|
+
return /* @__PURE__ */ jsxs5(
|
|
1443
1852
|
"div",
|
|
1444
1853
|
{
|
|
1445
1854
|
ref: bar,
|
|
@@ -1449,9 +1858,9 @@ function LensTrack({
|
|
|
1449
1858
|
"data-liquid-glass": "",
|
|
1450
1859
|
style: { ...style, "--lg-count": items.length, "--lg-index": index },
|
|
1451
1860
|
children: [
|
|
1452
|
-
/* @__PURE__ */
|
|
1453
|
-
/* @__PURE__ */
|
|
1454
|
-
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(
|
|
1455
1864
|
"button",
|
|
1456
1865
|
{
|
|
1457
1866
|
type: "button",
|
|
@@ -1465,38 +1874,40 @@ function LensTrack({
|
|
|
1465
1874
|
},
|
|
1466
1875
|
i
|
|
1467
1876
|
)),
|
|
1468
|
-
/* @__PURE__ */
|
|
1877
|
+
/* @__PURE__ */ jsx7("span", { ref: lens, className: "lg-glass lg-track__lens", "data-lg-mirror-bare": "", "aria-hidden": "true" })
|
|
1469
1878
|
]
|
|
1470
1879
|
}
|
|
1471
1880
|
);
|
|
1472
1881
|
}
|
|
1473
1882
|
|
|
1474
1883
|
// src/components/GlassNav/GlassNav.tsx
|
|
1475
|
-
import { jsx as
|
|
1884
|
+
import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1476
1885
|
var GlassNav = ({
|
|
1477
1886
|
items,
|
|
1478
1887
|
activeIndex = 0,
|
|
1479
1888
|
onChange,
|
|
1480
1889
|
intensity = 5,
|
|
1890
|
+
showLabels = true,
|
|
1481
1891
|
className,
|
|
1482
1892
|
style,
|
|
1483
1893
|
"aria-label": ariaLabel = "Tabs"
|
|
1484
1894
|
}) => {
|
|
1485
1895
|
const hasIcons = items.some((item) => item.icon != null);
|
|
1486
|
-
|
|
1896
|
+
const iconsOnly = hasIcons && !showLabels;
|
|
1897
|
+
return /* @__PURE__ */ jsx8(
|
|
1487
1898
|
LensTrack,
|
|
1488
1899
|
{
|
|
1489
1900
|
variant: "tabbar",
|
|
1490
|
-
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(" "),
|
|
1491
1902
|
style,
|
|
1492
1903
|
"aria-label": ariaLabel,
|
|
1493
1904
|
intensity,
|
|
1494
1905
|
index: activeIndex,
|
|
1495
1906
|
onChange,
|
|
1496
1907
|
labels: items.map((item) => item.label),
|
|
1497
|
-
items: items.map((item, i) => /* @__PURE__ */
|
|
1498
|
-
item.icon != null && /* @__PURE__ */
|
|
1499
|
-
/* @__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 })
|
|
1500
1911
|
] }, i))
|
|
1501
1912
|
}
|
|
1502
1913
|
);
|
|
@@ -1504,8 +1915,8 @@ var GlassNav = ({
|
|
|
1504
1915
|
GlassNav.displayName = "GlassNav";
|
|
1505
1916
|
|
|
1506
1917
|
// src/components/GlassSegmented/GlassSegmented.tsx
|
|
1507
|
-
import
|
|
1508
|
-
import { jsx as
|
|
1918
|
+
import React8 from "react";
|
|
1919
|
+
import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1509
1920
|
var GlassSegmented = ({
|
|
1510
1921
|
options,
|
|
1511
1922
|
value,
|
|
@@ -1517,7 +1928,7 @@ var GlassSegmented = ({
|
|
|
1517
1928
|
"aria-label": ariaLabel
|
|
1518
1929
|
}) => {
|
|
1519
1930
|
const normalized = options.map((option) => typeof option === "string" ? { label: option } : option);
|
|
1520
|
-
return /* @__PURE__ */
|
|
1931
|
+
return /* @__PURE__ */ jsx9(
|
|
1521
1932
|
LensTrack,
|
|
1522
1933
|
{
|
|
1523
1934
|
variant: "segmented",
|
|
@@ -1528,9 +1939,9 @@ var GlassSegmented = ({
|
|
|
1528
1939
|
index: value,
|
|
1529
1940
|
onChange,
|
|
1530
1941
|
labels: normalized.map((option) => option.label),
|
|
1531
|
-
items: normalized.map((option, i) => /* @__PURE__ */
|
|
1942
|
+
items: normalized.map((option, i) => /* @__PURE__ */ jsxs7(React8.Fragment, { children: [
|
|
1532
1943
|
option.icon,
|
|
1533
|
-
/* @__PURE__ */
|
|
1944
|
+
/* @__PURE__ */ jsx9("span", { className: "lg-nav__label", children: option.label })
|
|
1534
1945
|
] }, i))
|
|
1535
1946
|
}
|
|
1536
1947
|
);
|
|
@@ -1538,9 +1949,9 @@ var GlassSegmented = ({
|
|
|
1538
1949
|
GlassSegmented.displayName = "GlassSegmented";
|
|
1539
1950
|
|
|
1540
1951
|
// src/components/GlassSlider/GlassSlider.tsx
|
|
1541
|
-
import
|
|
1542
|
-
import { jsx as
|
|
1543
|
-
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(
|
|
1544
1955
|
({
|
|
1545
1956
|
value = 0,
|
|
1546
1957
|
min = 0,
|
|
@@ -1559,22 +1970,23 @@ var GlassSlider = React8.forwardRef(
|
|
|
1559
1970
|
disabled,
|
|
1560
1971
|
...rest
|
|
1561
1972
|
}, forwardedRef) => {
|
|
1562
|
-
const rootRef =
|
|
1563
|
-
const inputRef =
|
|
1564
|
-
const thumbRef =
|
|
1565
|
-
const faceRef =
|
|
1566
|
-
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);
|
|
1567
1979
|
useImperativeHandle4(forwardedRef, () => inputRef.current);
|
|
1568
|
-
|
|
1980
|
+
useEffect6(() => {
|
|
1569
1981
|
const input2 = inputRef.current;
|
|
1570
1982
|
const root = rootRef.current;
|
|
1571
1983
|
const setValue = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value").set;
|
|
1572
1984
|
let drag = null;
|
|
1573
1985
|
const update = (clientX) => {
|
|
1574
1986
|
if (!drag || max <= min) return;
|
|
1575
|
-
const
|
|
1576
|
-
const
|
|
1577
|
-
|
|
1987
|
+
const raw = drag.from + (clientX - drag.x) / drag.travel;
|
|
1988
|
+
const fraction = clamp(raw, 0, 1);
|
|
1989
|
+
pastRef.current = (raw - fraction) * drag.travel;
|
|
1578
1990
|
let next = min + fraction * (max - min);
|
|
1579
1991
|
const increment = Number(step2);
|
|
1580
1992
|
if (step2 !== "any" && Number.isFinite(increment) && increment > 0) {
|
|
@@ -1589,16 +2001,15 @@ var GlassSlider = React8.forwardRef(
|
|
|
1589
2001
|
const down = (event) => {
|
|
1590
2002
|
if (input2.disabled || !event.isPrimary || event.button !== 0 || drag) return;
|
|
1591
2003
|
event.preventDefault();
|
|
1592
|
-
|
|
2004
|
+
delete root.dataset.keyboard;
|
|
2005
|
+
if (event.pointerType !== "touch") input2.focus({ preventScroll: true });
|
|
1593
2006
|
const box = root.getBoundingClientRect();
|
|
1594
2007
|
const inset = showThumb ? 19 * box.width / root.offsetWidth : 0;
|
|
1595
|
-
const
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
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;
|
|
1599
2011
|
root.dataset.dragging = "";
|
|
1600
|
-
|
|
1601
|
-
update(event.clientX);
|
|
2012
|
+
root.setPointerCapture(event.pointerId);
|
|
1602
2013
|
};
|
|
1603
2014
|
const move = (event) => {
|
|
1604
2015
|
if (event.pointerId !== drag?.id) return;
|
|
@@ -1609,33 +2020,36 @@ var GlassSlider = React8.forwardRef(
|
|
|
1609
2020
|
if (!drag) return;
|
|
1610
2021
|
const id = drag.id;
|
|
1611
2022
|
drag = null;
|
|
2023
|
+
pastRef.current = 0;
|
|
1612
2024
|
delete root.dataset.dragging;
|
|
1613
|
-
if (
|
|
2025
|
+
if (root.hasPointerCapture(id)) root.releasePointerCapture(id);
|
|
1614
2026
|
};
|
|
1615
2027
|
const up = (event) => {
|
|
1616
2028
|
if (event.pointerId !== drag?.id) return;
|
|
1617
2029
|
update(event.clientX);
|
|
1618
2030
|
release();
|
|
1619
2031
|
};
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
2032
|
+
const unguard = guardSelection(root);
|
|
2033
|
+
root.addEventListener("pointerdown", down);
|
|
2034
|
+
root.addEventListener("pointermove", move);
|
|
2035
|
+
root.addEventListener("pointerup", up);
|
|
2036
|
+
root.addEventListener("pointercancel", release);
|
|
2037
|
+
root.addEventListener("lostpointercapture", release);
|
|
1625
2038
|
window.addEventListener("blur", release);
|
|
1626
2039
|
return () => {
|
|
1627
2040
|
release();
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
2041
|
+
unguard();
|
|
2042
|
+
root.removeEventListener("pointerdown", down);
|
|
2043
|
+
root.removeEventListener("pointermove", move);
|
|
2044
|
+
root.removeEventListener("pointerup", up);
|
|
2045
|
+
root.removeEventListener("pointercancel", release);
|
|
2046
|
+
root.removeEventListener("lostpointercapture", release);
|
|
1633
2047
|
window.removeEventListener("blur", release);
|
|
1634
2048
|
};
|
|
1635
2049
|
}, [min, max, step2, showThumb]);
|
|
1636
2050
|
const strength = Math.max(1, Math.min(10, intensity)) / 5;
|
|
1637
|
-
const [mirrored, setMirrored] =
|
|
1638
|
-
|
|
2051
|
+
const [mirrored, setMirrored] = React9.useState(false);
|
|
2052
|
+
useEffect6(() => setMirrored(!canRefractBackdrop()), []);
|
|
1639
2053
|
const progress = max > min ? clamp((Number(value) - min) / (max - min), 0, 1) : 0;
|
|
1640
2054
|
useRefraction(
|
|
1641
2055
|
thumbRef,
|
|
@@ -1645,18 +2059,20 @@ var GlassSlider = React8.forwardRef(
|
|
|
1645
2059
|
() => parseFloat(rootRef.current?.style.getPropertyValue("--lg-lift") || "0") > 0.01
|
|
1646
2060
|
);
|
|
1647
2061
|
useRefraction(blockRef, { kind: "surface", strength }, !showThumb);
|
|
1648
|
-
|
|
2062
|
+
useEffect6(() => {
|
|
1649
2063
|
if (!showThumb) return;
|
|
1650
2064
|
const input2 = inputRef.current;
|
|
1651
2065
|
const thumb = thumbRef.current;
|
|
1652
2066
|
const face = faceRef.current;
|
|
1653
2067
|
const root = rootRef.current;
|
|
1654
|
-
const v = { lift: 0, stretch: 0 };
|
|
2068
|
+
const v = { lift: 0, stretch: 0, over: 0 };
|
|
1655
2069
|
const paint = () => {
|
|
1656
2070
|
const s = 0.655 + 0.345 * v.lift;
|
|
1657
|
-
|
|
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)}`;
|
|
1658
2073
|
face.style.opacity = String(1 - clamp(v.lift, 0, 1) * 0.92);
|
|
1659
2074
|
root.style.setProperty("--lg-lift", String(clamp(v.lift, 0, 1)));
|
|
2075
|
+
root.style.setProperty("--lg-over", `${v.over.toFixed(2)}px`);
|
|
1660
2076
|
if (v.lift < 0.01 && lift.target === 0) delete root.dataset.lifted;
|
|
1661
2077
|
};
|
|
1662
2078
|
const lift = createSpring(0, SPRINGS.lift, (x) => {
|
|
@@ -1667,11 +2083,15 @@ var GlassSlider = React8.forwardRef(
|
|
|
1667
2083
|
v.stretch = x;
|
|
1668
2084
|
paint();
|
|
1669
2085
|
});
|
|
2086
|
+
const over = createSpring(0, SPRINGS.release, (x) => {
|
|
2087
|
+
v.over = x;
|
|
2088
|
+
paint();
|
|
2089
|
+
});
|
|
1670
2090
|
paint();
|
|
1671
2091
|
let lastX = 0;
|
|
1672
2092
|
let lastT = 0;
|
|
1673
2093
|
const down = (event) => {
|
|
1674
|
-
if (input2.disabled) return;
|
|
2094
|
+
if (input2.disabled || !event.isPrimary || event.button !== 0) return;
|
|
1675
2095
|
lastX = event.clientX;
|
|
1676
2096
|
lastT = event.timeStamp;
|
|
1677
2097
|
root.dataset.lifted = "";
|
|
@@ -1687,6 +2107,8 @@ var GlassSlider = React8.forwardRef(
|
|
|
1687
2107
|
lastT = event.timeStamp;
|
|
1688
2108
|
stretch.tune(SPRINGS.drag);
|
|
1689
2109
|
stretch.set(clamp(speed * 0.015, 0, 0.035));
|
|
2110
|
+
over.tune(SPRINGS.drag);
|
|
2111
|
+
over.set(rubberband(pastRef.current, 12, 0.5));
|
|
1690
2112
|
};
|
|
1691
2113
|
const up = () => {
|
|
1692
2114
|
if (lift.target === 0) return;
|
|
@@ -1694,29 +2116,33 @@ var GlassSlider = React8.forwardRef(
|
|
|
1694
2116
|
lift.set(0);
|
|
1695
2117
|
stretch.tune(SPRINGS.release);
|
|
1696
2118
|
stretch.set(0);
|
|
2119
|
+
over.tune(SPRINGS.release);
|
|
2120
|
+
over.set(0);
|
|
1697
2121
|
};
|
|
1698
|
-
|
|
2122
|
+
root.addEventListener("pointerdown", down);
|
|
1699
2123
|
window.addEventListener("pointermove", move);
|
|
1700
2124
|
window.addEventListener("pointerup", up);
|
|
1701
2125
|
window.addEventListener("pointercancel", up);
|
|
1702
|
-
|
|
2126
|
+
root.addEventListener("lostpointercapture", up);
|
|
1703
2127
|
window.addEventListener("blur", up);
|
|
1704
2128
|
return () => {
|
|
1705
2129
|
lift.stop();
|
|
1706
2130
|
stretch.stop();
|
|
1707
|
-
|
|
2131
|
+
over.stop();
|
|
2132
|
+
root.removeEventListener("pointerdown", down);
|
|
1708
2133
|
window.removeEventListener("pointermove", move);
|
|
1709
2134
|
window.removeEventListener("pointerup", up);
|
|
1710
2135
|
window.removeEventListener("pointercancel", up);
|
|
1711
|
-
|
|
2136
|
+
root.removeEventListener("lostpointercapture", up);
|
|
1712
2137
|
window.removeEventListener("blur", up);
|
|
1713
2138
|
delete root.dataset.lifted;
|
|
1714
2139
|
};
|
|
1715
2140
|
}, [showThumb]);
|
|
1716
|
-
|
|
2141
|
+
useEffect6(() => {
|
|
1717
2142
|
if (showThumb) return;
|
|
1718
2143
|
const input2 = inputRef.current;
|
|
1719
2144
|
const block = blockRef.current;
|
|
2145
|
+
const root = rootRef.current;
|
|
1720
2146
|
const v = { swell: 0, over: 0 };
|
|
1721
2147
|
const paint = () => {
|
|
1722
2148
|
const w = block.offsetWidth || 1;
|
|
@@ -1735,41 +2161,46 @@ var GlassSlider = React8.forwardRef(
|
|
|
1735
2161
|
});
|
|
1736
2162
|
let active2 = null;
|
|
1737
2163
|
const down = (event) => {
|
|
1738
|
-
if (input2.disabled) return;
|
|
1739
|
-
active2 = { id: event.pointerId
|
|
2164
|
+
if (input2.disabled || !event.isPrimary || event.button !== 0) return;
|
|
2165
|
+
active2 = { id: event.pointerId };
|
|
1740
2166
|
swell.tune(SPRINGS.press);
|
|
1741
2167
|
swell.set(1);
|
|
1742
2168
|
haptic();
|
|
1743
2169
|
};
|
|
1744
2170
|
const move = (event) => {
|
|
1745
2171
|
if (event.pointerId !== active2?.id) return;
|
|
1746
|
-
const { box } = active2;
|
|
1747
|
-
const past = event.clientX < box.left ? event.clientX - box.left : event.clientX > box.right ? event.clientX - box.right : 0;
|
|
1748
2172
|
over.tune(SPRINGS.drag);
|
|
1749
|
-
over.set(rubberband(
|
|
2173
|
+
over.set(rubberband(pastRef.current, 26, 0.6));
|
|
1750
2174
|
};
|
|
1751
|
-
const
|
|
1752
|
-
if (
|
|
2175
|
+
const reset = () => {
|
|
2176
|
+
if (!active2) return;
|
|
1753
2177
|
active2 = null;
|
|
1754
2178
|
swell.tune(SPRINGS.release);
|
|
1755
2179
|
swell.set(0);
|
|
1756
2180
|
over.tune(SPRINGS.release);
|
|
1757
2181
|
over.set(0);
|
|
1758
2182
|
};
|
|
1759
|
-
|
|
2183
|
+
const up = (event) => {
|
|
2184
|
+
if (event.pointerId === active2?.id) reset();
|
|
2185
|
+
};
|
|
2186
|
+
root.addEventListener("pointerdown", down);
|
|
2187
|
+
root.addEventListener("lostpointercapture", reset);
|
|
2188
|
+
window.addEventListener("blur", reset);
|
|
1760
2189
|
window.addEventListener("pointermove", move);
|
|
1761
2190
|
window.addEventListener("pointerup", up);
|
|
1762
2191
|
window.addEventListener("pointercancel", up);
|
|
1763
2192
|
return () => {
|
|
1764
2193
|
swell.stop();
|
|
1765
2194
|
over.stop();
|
|
1766
|
-
|
|
2195
|
+
root.removeEventListener("pointerdown", down);
|
|
2196
|
+
root.removeEventListener("lostpointercapture", reset);
|
|
2197
|
+
window.removeEventListener("blur", reset);
|
|
1767
2198
|
window.removeEventListener("pointermove", move);
|
|
1768
2199
|
window.removeEventListener("pointerup", up);
|
|
1769
2200
|
window.removeEventListener("pointercancel", up);
|
|
1770
2201
|
};
|
|
1771
2202
|
}, [showThumb]);
|
|
1772
|
-
const input = /* @__PURE__ */
|
|
2203
|
+
const input = /* @__PURE__ */ jsx10(
|
|
1773
2204
|
"input",
|
|
1774
2205
|
{
|
|
1775
2206
|
ref: inputRef,
|
|
@@ -1789,7 +2220,7 @@ var GlassSlider = React8.forwardRef(
|
|
|
1789
2220
|
);
|
|
1790
2221
|
const vars = { "--lg-progress": progress, ...tint ? { "--lg-slider-fill": tint } : {}, ...style };
|
|
1791
2222
|
if (!showThumb) {
|
|
1792
|
-
return /* @__PURE__ */
|
|
2223
|
+
return /* @__PURE__ */ jsxs8(
|
|
1793
2224
|
"div",
|
|
1794
2225
|
{
|
|
1795
2226
|
ref: rootRef,
|
|
@@ -1797,16 +2228,16 @@ var GlassSlider = React8.forwardRef(
|
|
|
1797
2228
|
"data-liquid-glass": "",
|
|
1798
2229
|
style: vars,
|
|
1799
2230
|
children: [
|
|
1800
|
-
/* @__PURE__ */
|
|
1801
|
-
/* @__PURE__ */
|
|
1802
|
-
icon && /* @__PURE__ */
|
|
1803
|
-
label2 && /* @__PURE__ */
|
|
1804
|
-
/* @__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)) })
|
|
1805
2236
|
] }),
|
|
1806
|
-
/* @__PURE__ */
|
|
1807
|
-
icon && /* @__PURE__ */
|
|
1808
|
-
label2 && /* @__PURE__ */
|
|
1809
|
-
/* @__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)) })
|
|
1810
2241
|
] }) })
|
|
1811
2242
|
] }),
|
|
1812
2243
|
input
|
|
@@ -1814,7 +2245,7 @@ var GlassSlider = React8.forwardRef(
|
|
|
1814
2245
|
}
|
|
1815
2246
|
);
|
|
1816
2247
|
}
|
|
1817
|
-
return /* @__PURE__ */
|
|
2248
|
+
return /* @__PURE__ */ jsxs8(
|
|
1818
2249
|
"div",
|
|
1819
2250
|
{
|
|
1820
2251
|
ref: rootRef,
|
|
@@ -1823,8 +2254,8 @@ var GlassSlider = React8.forwardRef(
|
|
|
1823
2254
|
"data-mirror": mirrored ? "" : void 0,
|
|
1824
2255
|
style: vars,
|
|
1825
2256
|
children: [
|
|
1826
|
-
/* @__PURE__ */
|
|
1827
|
-
/* @__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" }) }) }),
|
|
1828
2259
|
input
|
|
1829
2260
|
]
|
|
1830
2261
|
}
|
|
@@ -1834,22 +2265,22 @@ var GlassSlider = React8.forwardRef(
|
|
|
1834
2265
|
GlassSlider.displayName = "GlassSlider";
|
|
1835
2266
|
|
|
1836
2267
|
// src/components/GlassSwitch/GlassSwitch.tsx
|
|
1837
|
-
import
|
|
1838
|
-
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";
|
|
1839
2270
|
var SETTLE = springFrom(0.36, 0.68);
|
|
1840
2271
|
var REST = 0.655;
|
|
1841
2272
|
var TRAVEL = 22;
|
|
1842
|
-
var GlassSwitch =
|
|
2273
|
+
var GlassSwitch = React10.forwardRef(
|
|
1843
2274
|
({ checked: checkedProp, defaultChecked = false, onChange, tint, intensity = 5, className, style, disabled, ...rest }, forwardedRef) => {
|
|
1844
|
-
const ref =
|
|
1845
|
-
const thumbRef =
|
|
1846
|
-
const fillRef =
|
|
1847
|
-
const faceRef =
|
|
2275
|
+
const ref = useRef9(null);
|
|
2276
|
+
const thumbRef = useRef9(null);
|
|
2277
|
+
const fillRef = useRef9(null);
|
|
2278
|
+
const faceRef = useRef9(null);
|
|
1848
2279
|
useImperativeHandle5(forwardedRef, () => ref.current);
|
|
1849
|
-
const [inner, setInner] =
|
|
2280
|
+
const [inner, setInner] = useState4(defaultChecked);
|
|
1850
2281
|
const controlled = checkedProp !== void 0;
|
|
1851
2282
|
const checked = controlled ? checkedProp : inner;
|
|
1852
|
-
const latest =
|
|
2283
|
+
const latest = useRef9({ checked, set: (_) => {
|
|
1853
2284
|
}, disabled });
|
|
1854
2285
|
latest.current = {
|
|
1855
2286
|
checked,
|
|
@@ -1859,15 +2290,15 @@ var GlassSwitch = React9.forwardRef(
|
|
|
1859
2290
|
onChange?.(next);
|
|
1860
2291
|
}
|
|
1861
2292
|
};
|
|
1862
|
-
const sync =
|
|
2293
|
+
const sync = useRef9(null);
|
|
1863
2294
|
useRefraction(
|
|
1864
2295
|
thumbRef,
|
|
1865
|
-
{ 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 },
|
|
1866
2297
|
true,
|
|
1867
2298
|
ref,
|
|
1868
2299
|
() => parseFloat(ref.current?.style.getPropertyValue("--lg-lift") || "0") > 0.01
|
|
1869
2300
|
);
|
|
1870
|
-
|
|
2301
|
+
useEffect7(() => {
|
|
1871
2302
|
const el2 = ref.current;
|
|
1872
2303
|
const thumb = thumbRef.current;
|
|
1873
2304
|
const fill = fillRef.current;
|
|
@@ -1878,6 +2309,8 @@ var GlassSwitch = React9.forwardRef(
|
|
|
1878
2309
|
const sy = s * (1 - v.stretch * 0.5);
|
|
1879
2310
|
thumb.style.transform = `translate(${v.x * TRAVEL}px, -50%) scale(${sx}, ${sy})`;
|
|
1880
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`);
|
|
1881
2314
|
el2.style.setProperty("--lg-lift", String(l));
|
|
1882
2315
|
el2.toggleAttribute("data-lifted", l > 0.01);
|
|
1883
2316
|
};
|
|
@@ -1967,6 +2400,7 @@ var GlassSwitch = React9.forwardRef(
|
|
|
1967
2400
|
latest.current.set(next);
|
|
1968
2401
|
sync.current?.(next);
|
|
1969
2402
|
};
|
|
2403
|
+
const unguard = guardSelection(el2);
|
|
1970
2404
|
el2.addEventListener("pointerdown", down);
|
|
1971
2405
|
el2.addEventListener("pointermove", move);
|
|
1972
2406
|
el2.addEventListener("pointerup", up);
|
|
@@ -1975,6 +2409,7 @@ var GlassSwitch = React9.forwardRef(
|
|
|
1975
2409
|
return () => {
|
|
1976
2410
|
clearTimeout(dropTimer);
|
|
1977
2411
|
[position, lift, color].forEach((s) => s.stop());
|
|
2412
|
+
unguard();
|
|
1978
2413
|
el2.removeEventListener("pointerdown", down);
|
|
1979
2414
|
el2.removeEventListener("pointermove", move);
|
|
1980
2415
|
el2.removeEventListener("pointerup", up);
|
|
@@ -1982,10 +2417,10 @@ var GlassSwitch = React9.forwardRef(
|
|
|
1982
2417
|
el2.removeEventListener("click", click);
|
|
1983
2418
|
};
|
|
1984
2419
|
}, []);
|
|
1985
|
-
|
|
2420
|
+
useEffect7(() => {
|
|
1986
2421
|
sync.current?.(checked);
|
|
1987
2422
|
}, [checked]);
|
|
1988
|
-
return /* @__PURE__ */
|
|
2423
|
+
return /* @__PURE__ */ jsxs9(
|
|
1989
2424
|
"button",
|
|
1990
2425
|
{
|
|
1991
2426
|
ref,
|
|
@@ -2002,8 +2437,9 @@ var GlassSwitch = React9.forwardRef(
|
|
|
2002
2437
|
rest.onKeyDown?.(event);
|
|
2003
2438
|
},
|
|
2004
2439
|
children: [
|
|
2005
|
-
/* @__PURE__ */
|
|
2006
|
-
/* @__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" }) })
|
|
2007
2443
|
]
|
|
2008
2444
|
}
|
|
2009
2445
|
);
|
|
@@ -2013,28 +2449,28 @@ GlassSwitch.displayName = "GlassSwitch";
|
|
|
2013
2449
|
|
|
2014
2450
|
// src/filters/LiquidGlassFilter.tsx
|
|
2015
2451
|
import { createContext, useContext } from "react";
|
|
2016
|
-
import { jsx as
|
|
2452
|
+
import { jsx as jsx12, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
2017
2453
|
var GlassFilterContext = createContext(false);
|
|
2018
2454
|
function LiquidGlassFilter({ children }) {
|
|
2019
|
-
return /* @__PURE__ */
|
|
2020
|
-
/* @__PURE__ */
|
|
2455
|
+
return /* @__PURE__ */ jsxs10(GlassFilterContext.Provider, { value: true, children: [
|
|
2456
|
+
/* @__PURE__ */ jsx12(GlassFilterSVG, {}),
|
|
2021
2457
|
children
|
|
2022
2458
|
] });
|
|
2023
2459
|
}
|
|
2024
2460
|
function GlassFilterSVG() {
|
|
2025
|
-
return /* @__PURE__ */
|
|
2461
|
+
return /* @__PURE__ */ jsx12(
|
|
2026
2462
|
"svg",
|
|
2027
2463
|
{
|
|
2028
2464
|
width: "0",
|
|
2029
2465
|
height: "0",
|
|
2030
2466
|
style: { position: "absolute", pointerEvents: "none" },
|
|
2031
2467
|
"aria-hidden": "true",
|
|
2032
|
-
children: /* @__PURE__ */
|
|
2468
|
+
children: /* @__PURE__ */ jsx12("defs", { children: Array.from({ length: 10 }, (_, i) => {
|
|
2033
2469
|
const level = i + 1;
|
|
2034
2470
|
const scale = level * 2;
|
|
2035
2471
|
const freq1 = 0.012 + level * 1e-3;
|
|
2036
2472
|
const freq2 = 0.01 + level * 8e-4;
|
|
2037
|
-
return /* @__PURE__ */
|
|
2473
|
+
return /* @__PURE__ */ jsxs10(
|
|
2038
2474
|
"filter",
|
|
2039
2475
|
{
|
|
2040
2476
|
id: `liquid-glass-refract-${level}`,
|
|
@@ -2044,7 +2480,7 @@ function GlassFilterSVG() {
|
|
|
2044
2480
|
height: "120%",
|
|
2045
2481
|
colorInterpolationFilters: "sRGB",
|
|
2046
2482
|
children: [
|
|
2047
|
-
/* @__PURE__ */
|
|
2483
|
+
/* @__PURE__ */ jsx12(
|
|
2048
2484
|
"feTurbulence",
|
|
2049
2485
|
{
|
|
2050
2486
|
type: "fractalNoise",
|
|
@@ -2054,7 +2490,7 @@ function GlassFilterSVG() {
|
|
|
2054
2490
|
result: "noise"
|
|
2055
2491
|
}
|
|
2056
2492
|
),
|
|
2057
|
-
/* @__PURE__ */
|
|
2493
|
+
/* @__PURE__ */ jsx12(
|
|
2058
2494
|
"feDisplacementMap",
|
|
2059
2495
|
{
|
|
2060
2496
|
in: "SourceGraphic",
|
|
@@ -2151,11 +2587,11 @@ function useGlassEffect(options = {}) {
|
|
|
2151
2587
|
}
|
|
2152
2588
|
|
|
2153
2589
|
// src/hooks/useGlassAnimation.ts
|
|
2154
|
-
import { useCallback, useState as
|
|
2590
|
+
import { useCallback, useState as useState5 } from "react";
|
|
2155
2591
|
function useGlassAnimation() {
|
|
2156
|
-
const [isHovered, setIsHovered] =
|
|
2157
|
-
const [isPressed, setIsPressed] =
|
|
2158
|
-
const [isFocused, setIsFocused] =
|
|
2592
|
+
const [isHovered, setIsHovered] = useState5(false);
|
|
2593
|
+
const [isPressed, setIsPressed] = useState5(false);
|
|
2594
|
+
const [isFocused, setIsFocused] = useState5(false);
|
|
2159
2595
|
const handlers = {
|
|
2160
2596
|
onPointerEnter: useCallback(() => setIsHovered(true), []),
|
|
2161
2597
|
onPointerLeave: useCallback(() => {
|
|
@@ -2173,6 +2609,7 @@ export {
|
|
|
2173
2609
|
GlassButton,
|
|
2174
2610
|
GlassCard,
|
|
2175
2611
|
GlassInput,
|
|
2612
|
+
GlassMenu,
|
|
2176
2613
|
GlassNav,
|
|
2177
2614
|
GlassSegmented,
|
|
2178
2615
|
GlassSheet,
|