@zakisheriff/liquid-glass 0.1.2 → 0.2.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/dist/index.mjs CHANGED
@@ -1,74 +1,763 @@
1
+ "use client";
2
+
1
3
  // src/components/GlassButton/GlassButton.tsx
2
- import React2, { useMemo } from "react";
4
+ import React, { useImperativeHandle, useRef } from "react";
3
5
 
4
- // src/filters/LiquidGlassFilter.tsx
5
- import { createContext, useContext } from "react";
6
- import { jsx, jsxs } from "react/jsx-runtime";
7
- var GlassFilterContext = createContext(false);
8
- function useGlassFilterMounted() {
9
- return useContext(GlassFilterContext);
6
+ // src/engine/press.ts
7
+ import { useEffect } from "react";
8
+
9
+ // src/engine/spring.ts
10
+ var active = /* @__PURE__ */ new Set();
11
+ var frame = 0;
12
+ var last = 0;
13
+ function step(s, dt) {
14
+ const x = s.value - s.target;
15
+ const v = s.velocity;
16
+ const half = s.c / 2;
17
+ const disc = half * half - s.k;
18
+ if (Math.abs(disc) < 1e-6) {
19
+ const decay = Math.exp(-half * dt);
20
+ const b = v + half * x;
21
+ s.value = s.target + decay * (x + b * dt);
22
+ s.velocity = decay * (v - half * b * dt);
23
+ } else if (disc > 0) {
24
+ const root = Math.sqrt(disc);
25
+ const r1 = -half + root;
26
+ const r2 = -half - root;
27
+ const a = (v - r2 * x) / (r1 - r2);
28
+ const b = x - a;
29
+ const e1 = Math.exp(r1 * dt);
30
+ const e2 = Math.exp(r2 * dt);
31
+ s.value = s.target + a * e1 + b * e2;
32
+ s.velocity = a * r1 * e1 + b * r2 * e2;
33
+ } else {
34
+ const w = Math.sqrt(-disc);
35
+ const decay = Math.exp(-half * dt);
36
+ const cos = Math.cos(w * dt);
37
+ const sin = Math.sin(w * dt);
38
+ s.value = s.target + decay * (x * cos + (v + half * x) / w * sin);
39
+ s.velocity = decay * (v * cos - (half * v + s.k * x) / w * sin);
40
+ }
10
41
  }
11
- function LiquidGlassFilter({ children }) {
12
- return /* @__PURE__ */ jsxs(GlassFilterContext.Provider, { value: true, children: [
13
- /* @__PURE__ */ jsx(GlassFilterSVG, {}),
14
- children
15
- ] });
42
+ function loop(time) {
43
+ frame = 0;
44
+ const dt = Math.min(0.064, Math.max(0, (time - last) / 1e3));
45
+ last = time;
46
+ for (const s of active) {
47
+ step(s, dt);
48
+ if (Math.abs(s.value - s.target) < 1e-4 && Math.abs(s.velocity) < 1e-3) {
49
+ s.value = s.target;
50
+ s.velocity = 0;
51
+ active.delete(s);
52
+ }
53
+ s.onUpdate(s.value, s.velocity);
54
+ }
55
+ if (active.size) frame = requestAnimationFrame(loop);
16
56
  }
17
- function GlassFilterSVG() {
18
- return /* @__PURE__ */ jsx(
19
- "svg",
20
- {
21
- width: "0",
22
- height: "0",
23
- style: { position: "absolute", pointerEvents: "none" },
24
- "aria-hidden": "true",
25
- children: /* @__PURE__ */ jsx("defs", { children: Array.from({ length: 10 }, (_, i) => {
26
- const level = i + 1;
27
- const scale = level * 2;
28
- const freq1 = 0.012 + level * 1e-3;
29
- const freq2 = 0.01 + level * 8e-4;
30
- return /* @__PURE__ */ jsxs(
31
- "filter",
32
- {
33
- id: `liquid-glass-refract-${level}`,
34
- x: "-10%",
35
- y: "-10%",
36
- width: "120%",
37
- height: "120%",
38
- colorInterpolationFilters: "sRGB",
39
- children: [
40
- /* @__PURE__ */ jsx(
41
- "feTurbulence",
42
- {
43
- type: "fractalNoise",
44
- baseFrequency: `${freq1} ${freq2}`,
45
- numOctaves: 3,
46
- seed: 42,
47
- result: "noise"
48
- }
49
- ),
50
- /* @__PURE__ */ jsx(
51
- "feDisplacementMap",
52
- {
53
- in: "SourceGraphic",
54
- in2: "noise",
55
- scale,
56
- xChannelSelector: "R",
57
- yChannelSelector: "G"
58
- }
59
- )
60
- ]
61
- },
62
- level
63
- );
64
- }) })
57
+ function wake() {
58
+ if (frame) return;
59
+ last = performance.now();
60
+ frame = requestAnimationFrame(loop);
61
+ }
62
+ function prefersReducedMotion() {
63
+ return typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
64
+ }
65
+ function createSpring(initial, config, onUpdate) {
66
+ const s = {
67
+ value: initial,
68
+ target: initial,
69
+ velocity: 0,
70
+ k: config.stiffness,
71
+ c: config.damping,
72
+ onUpdate
73
+ };
74
+ return {
75
+ get value() {
76
+ return s.value;
77
+ },
78
+ get velocity() {
79
+ return s.velocity;
80
+ },
81
+ get target() {
82
+ return s.target;
83
+ },
84
+ set(target, instant = false) {
85
+ s.target = target;
86
+ if (instant || prefersReducedMotion() || typeof document !== "undefined" && document.hidden) {
87
+ s.value = target;
88
+ s.velocity = 0;
89
+ active.delete(s);
90
+ onUpdate(s.value, 0);
91
+ return;
92
+ }
93
+ active.add(s);
94
+ wake();
95
+ },
96
+ tune(next) {
97
+ s.k = next.stiffness;
98
+ s.c = next.damping;
99
+ },
100
+ impulse(velocity) {
101
+ s.velocity += velocity;
102
+ active.add(s);
103
+ wake();
104
+ },
105
+ stop() {
106
+ active.delete(s);
107
+ }
108
+ };
109
+ }
110
+ function springFrom(response, dampingFraction) {
111
+ const w = 2 * Math.PI / response;
112
+ return { stiffness: w * w, damping: 2 * dampingFraction * w };
113
+ }
114
+ var SPRINGS = {
115
+ /** Finger down: quick, almost no overshoot. */
116
+ press: springFrom(0.22, 0.86),
117
+ /** Finger up: soft settle with the gentle jelly wobble. */
118
+ release: springFrom(0.42, 0.5),
119
+ /** Following the finger during a drag. */
120
+ drag: springFrom(0.12, 0.92),
121
+ /** Sliding into a new slot after release. */
122
+ snap: springFrom(0.36, 0.72),
123
+ /** Lens inflating out of a selection pill. */
124
+ lift: springFrom(0.26, 0.78),
125
+ /** Lens deflating back into a pill: visibly wobbly. */
126
+ settle: springFrom(0.45, 0.46),
127
+ /** Colour cross-fades. */
128
+ fade: springFrom(0.3, 1)
129
+ };
130
+ function rubberband(offset, dimension, constant = 0.55) {
131
+ const sign = Math.sign(offset);
132
+ const x = Math.abs(offset);
133
+ return sign * (1 - 1 / (x * constant / dimension + 1)) * dimension;
134
+ }
135
+ var clamp = (value, min, max) => Math.min(max, Math.max(min, value));
136
+
137
+ // src/engine/press.ts
138
+ var FOLLOW = springFrom(0.2, 0.82);
139
+ function usePress(ref, options = {}) {
140
+ const { grow, lean = 10, stretch = 0.2, disabled = false } = options;
141
+ useEffect(() => {
142
+ const el2 = ref.current;
143
+ if (!el2 || disabled) return;
144
+ const v = { sx: 1, sy: 1, tx: 0, ty: 0 };
145
+ const paint = () => {
146
+ el2.style.scale = `${v.sx} ${v.sy}`;
147
+ el2.style.translate = `${v.tx}px ${v.ty}px`;
148
+ };
149
+ const springs = ["sx", "sy", "tx", "ty"].map(
150
+ (key) => createSpring(key[0] === "s" ? 1 : 0, SPRINGS.release, (value) => {
151
+ v[key] = value;
152
+ paint();
153
+ })
154
+ );
155
+ const to = (targets, feel) => springs.forEach((s, i) => {
156
+ s.tune(feel);
157
+ s.set(targets[i]);
158
+ });
159
+ let pointer = null;
160
+ const light = (event, box) => {
161
+ el2.style.setProperty("--lg-x", `${(event.clientX - box.left) / box.width * 100}%`);
162
+ el2.style.setProperty("--lg-y", `${(event.clientY - box.top) / box.height * 100}%`);
163
+ };
164
+ const track = (event) => {
165
+ if (!pointer) return;
166
+ const { box, base } = pointer;
167
+ light(event, box);
168
+ const dx = event.clientX - pointer.x;
169
+ 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
+ const dist = Math.hypot(dx, dy);
173
+ const pull = 1 - 1 / (1 + dist / 55);
174
+ const k = stretch * pull;
175
+ const cx = dist ? (dx / dist) ** 2 : 0;
176
+ const cy = dist ? (dy / dist) ** 2 : 0;
177
+ to([base * (1 + k * cx - k * 0.5 * cy), base * (1 + k * cy - k * 0.5 * cx), tx, ty], FOLLOW);
178
+ };
179
+ const move = (event) => {
180
+ if (event.pointerId === pointer?.id) track(event);
181
+ };
182
+ const up = (event) => {
183
+ if (event && event.pointerId !== pointer?.id) return;
184
+ pointer = null;
185
+ delete el2.dataset.pressed;
186
+ window.removeEventListener("pointermove", move);
187
+ window.removeEventListener("pointerup", up);
188
+ window.removeEventListener("pointercancel", up);
189
+ to([1, 1, 0, 0], SPRINGS.release);
190
+ };
191
+ const down = (event) => {
192
+ if (!event.isPrimary || event.button !== 0 || pointer) return;
193
+ if (el2.disabled || el2.getAttribute("aria-disabled") === "true") return;
194
+ const box = el2.getBoundingClientRect();
195
+ const w = el2.offsetWidth || 1;
196
+ const h = el2.offsetHeight || 1;
197
+ const natural = Math.min(0.22, Math.max(0.07, 9 / Math.sqrt(w * h)));
198
+ const amount = (grow ?? natural) * (event.pointerType === "mouse" ? 0.75 : 1);
199
+ const base = 1 + amount;
200
+ pointer = { id: event.pointerId, x: event.clientX, y: event.clientY, box, base };
201
+ el2.dataset.pressed = "";
202
+ light(event, box);
203
+ to([base, base, 0, 0], SPRINGS.press);
204
+ window.addEventListener("pointermove", move);
205
+ window.addEventListener("pointerup", up);
206
+ window.addEventListener("pointercancel", up);
207
+ };
208
+ const blur = () => up();
209
+ el2.addEventListener("pointerdown", down);
210
+ window.addEventListener("blur", blur);
211
+ return () => {
212
+ up();
213
+ springs.forEach((s) => s.stop());
214
+ el2.removeEventListener("pointerdown", down);
215
+ window.removeEventListener("blur", blur);
216
+ el2.style.removeProperty("scale");
217
+ el2.style.removeProperty("translate");
218
+ };
219
+ }, [ref, grow, lean, stretch, disabled]);
220
+ }
221
+
222
+ // src/engine/refraction.ts
223
+ import { useEffect as useEffect2 } from "react";
224
+
225
+ // src/engine/mirror.ts
226
+ var SELF = "data-lg-mirror-self";
227
+ function clone(source) {
228
+ const root = source.cloneNode(true);
229
+ const originals = [source, ...Array.from(source.querySelectorAll("*"))];
230
+ const copies = [root, ...Array.from(root.querySelectorAll("*"))];
231
+ const pairs = [];
232
+ originals.forEach((original, i) => {
233
+ const copy = copies[i];
234
+ if (!copy) return;
235
+ copy.removeAttribute("id");
236
+ copy.removeAttribute("tabindex");
237
+ if (copy instanceof HTMLImageElement) copy.loading = "eager";
238
+ pairs.push({ original, copy, css: original.style.cssText, cls: original.className.toString() });
239
+ });
240
+ root.querySelectorAll(`[${SELF}], .lg-mirror, [data-lg-mirror-skip], input, textarea, select`).forEach((n) => n.remove());
241
+ root.setAttribute("inert", "");
242
+ root.setAttribute("aria-hidden", "true");
243
+ return { root, pairs };
244
+ }
245
+ var alpha = (color) => {
246
+ const m = color.match(/rgba?\(([^)]+)\)/);
247
+ if (!m) return color === "transparent" ? 0 : 1;
248
+ const parts = m[1].split(/[\s,/]+/).filter(Boolean);
249
+ return parts.length > 3 ? parseFloat(parts[3]) : 1;
250
+ };
251
+ function backdropChain(glass, source) {
252
+ const chain = [];
253
+ for (let node = glass.parentElement; node; node = node.parentElement) {
254
+ if (node === source || source.contains(node)) continue;
255
+ const cs = getComputedStyle(node);
256
+ const image = cs.backgroundImage !== "none";
257
+ const a = alpha(cs.backgroundColor);
258
+ if (image || a > 0) chain.unshift(node);
259
+ if (image || a >= 1) break;
260
+ }
261
+ return chain;
262
+ }
263
+ var BACKGROUND = ["background-color", "background-image", "background-size", "background-position", "background-repeat", "border-radius"];
264
+ function mirrorBackdrop(glass, source, filter, padding) {
265
+ const layer = document.createElement("div");
266
+ layer.className = "lg-mirror";
267
+ layer.setAttribute("aria-hidden", "true");
268
+ glass.setAttribute(SELF, "");
269
+ glass.prepend(layer);
270
+ const viewport = document.createElement("div");
271
+ viewport.className = "lg-mirror__viewport";
272
+ layer.append(viewport);
273
+ let copy = clone(source);
274
+ let under = [];
275
+ const buildUnder = () => {
276
+ under.forEach((u) => u.copy.remove());
277
+ under = backdropChain(glass, source).map((original) => {
278
+ const div = document.createElement("div");
279
+ const cs = getComputedStyle(original);
280
+ for (const name of BACKGROUND) div.style.setProperty(name, cs.getPropertyValue(name));
281
+ div.style.position = "absolute";
282
+ div.style.left = "0px";
283
+ div.style.top = "0px";
284
+ div.style.transformOrigin = "0 0";
285
+ return { original, copy: div, placed: "" };
286
+ });
287
+ viewport.prepend(...under.map((u) => u.copy));
288
+ };
289
+ viewport.append(copy.root);
290
+ buildUnder();
291
+ let stopped = false;
292
+ let frame2 = 0;
293
+ let visible = true;
294
+ let placed = "";
295
+ let pad = 0;
296
+ const place = (from, g, sgx, sgy) => {
297
+ const sw = from.offsetWidth;
298
+ const sh = from.offsetHeight;
299
+ if (!sw || !sh) return null;
300
+ const s = from.getBoundingClientRect();
301
+ const kx = s.width / sw / sgx;
302
+ const ky = s.height / sh / sgy;
303
+ const px = (s.left - g.left) / sgx + pad;
304
+ const py = (s.top - g.top) / sgy + pad;
305
+ return { sw, sh, key: `${sw}|${sh}|${px.toFixed(2)}|${py.toFixed(2)}|${kx.toFixed(4)}|${ky.toFixed(4)}`, transform: `translate(${px}px, ${py}px) scale(${kx}, ${ky})` };
306
+ };
307
+ const align = () => {
308
+ const nextPad = padding();
309
+ if (nextPad !== pad) {
310
+ pad = nextPad;
311
+ viewport.style.inset = `${-pad}px`;
312
+ under.forEach((u) => u.placed = "");
313
+ placed = "";
314
+ }
315
+ const gw = glass.offsetWidth;
316
+ const gh = glass.offsetHeight;
317
+ if (!gw || !gh) return;
318
+ const g = glass.getBoundingClientRect();
319
+ const sgx = g.width / gw;
320
+ const sgy = g.height / gh;
321
+ for (const u of under) {
322
+ const at2 = place(u.original, g, sgx, sgy);
323
+ if (!at2 || at2.key === u.placed) continue;
324
+ u.placed = at2.key;
325
+ u.copy.style.width = `${at2.sw}px`;
326
+ u.copy.style.height = `${at2.sh}px`;
327
+ u.copy.style.transform = at2.transform;
328
+ }
329
+ const at = place(source, g, sgx, sgy);
330
+ if (!at) return;
331
+ const { sw, sh } = at;
332
+ const next = at.key;
333
+ if (next === placed) return;
334
+ placed = next;
335
+ const root = copy.root;
336
+ root.style.position = "absolute";
337
+ root.style.left = "0px";
338
+ root.style.top = "0px";
339
+ root.style.margin = "0px";
340
+ root.style.width = `${sw}px`;
341
+ root.style.height = `${sh}px`;
342
+ root.style.scale = "none";
343
+ root.style.translate = "none";
344
+ root.style.transformOrigin = "0 0";
345
+ root.style.transform = at.transform;
346
+ };
347
+ const sync = () => {
348
+ for (const pair of copy.pairs) {
349
+ const css = pair.original.style.cssText;
350
+ const cls = pair.original.className.toString();
351
+ if (css !== pair.css) {
352
+ pair.css = css;
353
+ if (pair.copy !== copy.root) pair.copy.style.cssText = css;
354
+ else {
355
+ pair.copy.style.cssText = css;
356
+ placed = "";
357
+ }
358
+ }
359
+ if (cls !== pair.cls) {
360
+ pair.cls = cls;
361
+ pair.copy.className = cls;
362
+ }
65
363
  }
364
+ };
365
+ const applyFilter = () => {
366
+ const value = filter();
367
+ if (layer.style.filter !== value) layer.style.filter = value;
368
+ };
369
+ const tick = () => {
370
+ frame2 = 0;
371
+ if (stopped) return;
372
+ if (visible && !document.hidden) {
373
+ applyFilter();
374
+ sync();
375
+ align();
376
+ }
377
+ frame2 = requestAnimationFrame(tick);
378
+ };
379
+ frame2 = requestAnimationFrame(tick);
380
+ let pending = 0;
381
+ const recopy = () => {
382
+ pending = 0;
383
+ if (stopped) return;
384
+ const next = clone(source);
385
+ copy.root.replaceWith(next.root);
386
+ copy = next;
387
+ placed = "";
388
+ buildUnder();
389
+ align();
390
+ };
391
+ const mutations = new MutationObserver((records) => {
392
+ if (records.every((r) => layer.contains(r.target) || r.target === layer || r.target === glass)) return;
393
+ const structural = records.some((r) => r.type !== "attributes" && !layer.contains(r.target));
394
+ if (structural && !pending) pending = requestAnimationFrame(recopy);
395
+ });
396
+ mutations.observe(source, { childList: true, characterData: true, subtree: true });
397
+ const io = typeof IntersectionObserver === "function" ? new IntersectionObserver((entries) => {
398
+ visible = entries.some((e) => e.isIntersecting);
399
+ }) : null;
400
+ io?.observe(glass);
401
+ return () => {
402
+ stopped = true;
403
+ cancelAnimationFrame(frame2);
404
+ cancelAnimationFrame(pending);
405
+ mutations.disconnect();
406
+ io?.disconnect();
407
+ layer.remove();
408
+ glass.removeAttribute(SELF);
409
+ };
410
+ }
411
+
412
+ // src/engine/refraction.ts
413
+ var SVG_NS = "http://www.w3.org/2000/svg";
414
+ var cache = /* @__PURE__ */ new Map();
415
+ var defs = null;
416
+ var counter = 0;
417
+ function el(name, attrs) {
418
+ const node = document.createElementNS(SVG_NS, name);
419
+ for (const key in attrs) node.setAttribute(key, String(attrs[key]));
420
+ return node;
421
+ }
422
+ function container() {
423
+ if (defs?.isConnected) return defs;
424
+ const root = el("svg", { width: 0, height: 0, "aria-hidden": "true", "data-liquid-glass-defs": "" });
425
+ root.style.cssText = "position:absolute;width:0;height:0;overflow:hidden;pointer-events:none";
426
+ defs = el("defs", {});
427
+ root.append(defs);
428
+ document.body.append(root);
429
+ return defs;
430
+ }
431
+ function canRefractBackdrop() {
432
+ if (typeof navigator === "undefined") return false;
433
+ const ua = navigator.userAgent;
434
+ return /Chrom(e|ium)\/|Edg\//.test(ua) && !/CriOS|FxiOS|EdgiOS/.test(ua);
435
+ }
436
+ function bevelProfile(bezel, thickness, ior) {
437
+ const N = 256;
438
+ const out = new Float32Array(N);
439
+ for (let i = 0; i < N; i++) {
440
+ const t = Math.max(2e-3, i / (N - 1));
441
+ const q = 1 - t;
442
+ const base = 1 - q ** 4;
443
+ const height = base ** 0.25;
444
+ const slope = q ** 3 / Math.max(1e-4, base ** 0.75);
445
+ const incident = Math.atan(slope);
446
+ const refracted = Math.asin(Math.sin(incident) / ior);
447
+ out[i] = Math.tan(incident - refracted) * thickness * (0.35 + 0.65 * height);
448
+ }
449
+ return (distance) => {
450
+ if (distance < 0 || distance >= bezel) return 0;
451
+ const f = distance / bezel * (N - 1);
452
+ const i = Math.floor(f);
453
+ const a = out[i];
454
+ const b = out[Math.min(i + 1, N - 1)];
455
+ return a + (b - a) * (f - i);
456
+ };
457
+ }
458
+ function bake(width, height, radius, shape, pad = 0) {
459
+ const W = width + pad * 2;
460
+ const H = height + pad * 2;
461
+ let density = Math.min(typeof devicePixelRatio === "number" ? devicePixelRatio : 1, 2);
462
+ while (W * H * density * density > 4e5 && density > 0.35) density *= 0.75;
463
+ const cw = Math.max(1, Math.ceil(W * density));
464
+ const ch = Math.max(1, Math.ceil(H * density));
465
+ const lens = shape.kind === "lens";
466
+ const shift = bevelProfile(shape.bezel, shape.thickness, shape.ior);
467
+ const magnify = lens ? 1 - 1 / Math.max(1, shape.zoom) : 0;
468
+ const direction = lens ? 1 : -1;
469
+ const dx = new Float32Array(cw * ch);
470
+ const dy = new Float32Array(cw * ch);
471
+ const rimA = new Float32Array(cw * ch);
472
+ const rimHue = new Float32Array(cw * ch);
473
+ const inside = new Float32Array(cw * ch);
474
+ let max = 1e-4;
475
+ const hw = width / 2;
476
+ const hh = height / 2;
477
+ const px1 = 1 / density;
478
+ for (let y = 0; y < ch; y++) {
479
+ for (let x = 0; x < cw; x++) {
480
+ const px = (x + 0.5) * W / cw - W / 2;
481
+ const py = (y + 0.5) * H / ch - H / 2;
482
+ const qx = Math.abs(px) - (hw - radius);
483
+ const qy = Math.abs(py) - (hh - radius);
484
+ const ox = Math.max(qx, 0);
485
+ const oy = Math.max(qy, 0);
486
+ const len = Math.hypot(ox, oy);
487
+ const d = radius - (len + Math.min(Math.max(qx, qy), 0));
488
+ let nx;
489
+ let ny;
490
+ if (len > 0) {
491
+ nx = ox / len * Math.sign(px);
492
+ ny = oy / len * Math.sign(py);
493
+ } else if (qx > qy) {
494
+ nx = Math.sign(px);
495
+ ny = 0;
496
+ } else {
497
+ nx = 0;
498
+ ny = Math.sign(py);
499
+ }
500
+ const i = y * cw + x;
501
+ const s = shift(d) * shape.strength * direction;
502
+ const vx = nx * s;
503
+ const vy = ny * s;
504
+ dx[i] = vx;
505
+ dy[i] = vy;
506
+ const m = Math.max(Math.abs(vx), Math.abs(vy));
507
+ if (m > max) max = m;
508
+ inside[i] = clamp(d / px1 + 0.5, 0, 1);
509
+ if (d >= -px1) {
510
+ const facing = -(nx + ny) * Math.SQRT1_2;
511
+ const light = 0.22 + 0.78 * Math.abs(facing) ** 2.2 * (facing > 0 ? 1 : 0.62);
512
+ const line = Math.exp(-(((d - 0.55) / 0.55) ** 2));
513
+ const inner = Math.exp(-((d / (shape.bezel * 0.55)) ** 2)) * 0.14;
514
+ const edgeAA = clamp(d / px1 + 1, 0, 1);
515
+ rimA[i] = clamp((line * (lens ? 0.95 : 0.7) + inner) * light * edgeAA, 0, 1);
516
+ rimHue[i] = Math.atan2(ny, nx);
517
+ }
518
+ }
519
+ }
520
+ const canvas = document.createElement("canvas");
521
+ canvas.width = cw;
522
+ canvas.height = ch;
523
+ const ctx = canvas.getContext("2d");
524
+ const field = ctx.createImageData(cw, ch);
525
+ for (let i = 0; i < cw * ch; i++) {
526
+ const o = i * 4;
527
+ field.data[o] = Math.round(127.5 + dx[i] / max * 127.5);
528
+ field.data[o + 1] = Math.round(127.5 + dy[i] / max * 127.5);
529
+ field.data[o + 2] = 128;
530
+ field.data[o + 3] = 255;
531
+ }
532
+ ctx.putImageData(field, 0, 0);
533
+ const map = canvas.toDataURL();
534
+ const reach = Math.max(W, H) / 2;
535
+ let zoomMap = "";
536
+ if (magnify) {
537
+ const ramp = ctx.createImageData(cw, ch);
538
+ for (let y = 0; y < ch; y++) {
539
+ for (let x = 0; x < cw; x++) {
540
+ const o = (y * cw + x) * 4;
541
+ const px = (x + 0.5) * W / cw - W / 2;
542
+ const py = (y + 0.5) * H / ch - H / 2;
543
+ ramp.data[o] = Math.round(127.5 - px / reach * 127.5);
544
+ ramp.data[o + 1] = Math.round(127.5 - py / reach * 127.5);
545
+ ramp.data[o + 2] = 128;
546
+ ramp.data[o + 3] = 255;
547
+ }
548
+ }
549
+ ctx.putImageData(ramp, 0, 0);
550
+ zoomMap = canvas.toDataURL();
551
+ }
552
+ const shine = ctx.createImageData(cw, ch);
553
+ for (let i = 0; i < cw * ch; i++) {
554
+ const o = i * 4;
555
+ let r = 255;
556
+ let g = 255;
557
+ let b = 255;
558
+ if (lens && shape.dispersion > 0) {
559
+ const h = rimHue[i];
560
+ const k = 0.14 * shape.dispersion;
561
+ r = 255 * (1 - k + k * (0.5 + 0.5 * Math.cos(h)));
562
+ g = 255 * (1 - k + k * (0.5 + 0.5 * Math.cos(h - 2.1)));
563
+ b = 255 * (1 - k + k * (0.5 + 0.5 * Math.cos(h + 2.1)));
564
+ }
565
+ shine.data[o] = r;
566
+ shine.data[o + 1] = g;
567
+ shine.data[o + 2] = b;
568
+ shine.data[o + 3] = Math.round(rimA[i] * 255);
569
+ }
570
+ ctx.putImageData(shine, 0, 0);
571
+ const rim = canvas.toDataURL();
572
+ const shapeMask = ctx.createImageData(cw, ch);
573
+ for (let i = 0; i < cw * ch; i++) {
574
+ const o = i * 4;
575
+ shapeMask.data[o] = shapeMask.data[o + 1] = shapeMask.data[o + 2] = 255;
576
+ shapeMask.data[o + 3] = Math.round(inside[i] * 255);
577
+ }
578
+ ctx.putImageData(shapeMask, 0, 0);
579
+ const mask = canvas.toDataURL();
580
+ const id = `lg-refract-${++counter}`;
581
+ const box = { x: 0, y: 0, width: W, height: H };
582
+ const filter = el("filter", {
583
+ id,
584
+ // Generous region: the rim samples content from beyond the glass edge.
585
+ x: -0.5,
586
+ y: -0.5,
587
+ width: 2,
588
+ height: 2,
589
+ "color-interpolation-filters": "sRGB"
590
+ });
591
+ filter.append(el("feImage", { href: map, ...box, preserveAspectRatio: "none", result: "field" }));
592
+ let source = "SourceGraphic";
593
+ if (zoomMap) {
594
+ filter.append(
595
+ el("feImage", { href: zoomMap, ...box, preserveAspectRatio: "none", result: "zoom" }),
596
+ el("feDisplacementMap", {
597
+ in: "SourceGraphic",
598
+ in2: "zoom",
599
+ scale: 2 * reach * magnify,
600
+ xChannelSelector: "R",
601
+ yChannelSelector: "G",
602
+ result: "magnified"
603
+ })
604
+ );
605
+ source = "magnified";
606
+ }
607
+ const scale = max * 2;
608
+ if (shape.dispersion > 0) {
609
+ const spread = 0.16 * shape.dispersion;
610
+ const channels = [
611
+ ["r", 1 + spread, "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0"],
612
+ ["g", 1, "0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0"],
613
+ ["b", 1 - spread, "0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0"]
614
+ ];
615
+ for (const [name, factor, matrix] of channels) {
616
+ filter.append(
617
+ el("feDisplacementMap", {
618
+ in: source,
619
+ in2: "field",
620
+ scale: scale * factor,
621
+ xChannelSelector: "R",
622
+ yChannelSelector: "G",
623
+ result: `${name}-ray`
624
+ }),
625
+ el("feColorMatrix", { in: `${name}-ray`, type: "matrix", values: matrix, result: name })
626
+ );
627
+ }
628
+ filter.append(
629
+ el("feComposite", { in: "r", in2: "g", operator: "arithmetic", k2: 1, k3: 1, result: "rg" }),
630
+ el("feComposite", { in: "rg", in2: "b", operator: "arithmetic", k2: 1, k3: 1, result: "bent" })
631
+ );
632
+ } else {
633
+ filter.append(
634
+ el("feDisplacementMap", {
635
+ in: source,
636
+ in2: "field",
637
+ scale,
638
+ xChannelSelector: "R",
639
+ yChannelSelector: "G",
640
+ result: "bent"
641
+ })
642
+ );
643
+ }
644
+ filter.append(
645
+ el("feImage", { href: mask, ...box, preserveAspectRatio: "none", result: "shape" }),
646
+ el("feComposite", { in: "bent", in2: "shape", operator: "in" })
66
647
  );
648
+ container().append(filter);
649
+ return { filter: `url(#${id})`, rim: `url("${rim}")` };
650
+ }
651
+ function resolve(shape, width, height) {
652
+ const kind = shape.kind ?? "surface";
653
+ const short = Math.min(width, height);
654
+ const lens = kind === "lens";
655
+ return {
656
+ kind,
657
+ bezel: shape.bezel ?? (lens ? short * 0.32 : clamp(short * 0.2, 5, 16)),
658
+ thickness: shape.thickness ?? (lens ? short * 0.55 : clamp(short * 0.32, 8, 26)),
659
+ ior: shape.ior ?? 1.5,
660
+ zoom: shape.zoom ?? (lens ? 1.16 : 1),
661
+ dispersion: shape.dispersion ?? (lens ? 1 : 0),
662
+ strength: shape.strength ?? 1
663
+ };
664
+ }
665
+ function glassFor(width, height, radius, shape = {}, pad = 0) {
666
+ const w = Math.round(width);
667
+ const h = Math.round(height);
668
+ const r = Math.min(w / 2, h / 2, Math.max(0, radius));
669
+ const full = resolve(shape, w, h);
670
+ const key = [w, h, Math.round(r * 2) / 2, full.kind, full.bezel.toFixed(1), full.thickness.toFixed(1), full.ior, full.zoom, full.dispersion, full.strength, pad].join("|");
671
+ let baked = cache.get(key);
672
+ if (!baked) {
673
+ baked = bake(w, h, r, full, pad);
674
+ cache.set(key, baked);
675
+ }
676
+ return baked;
677
+ }
678
+ function idle(callback) {
679
+ if (typeof requestIdleCallback === "function") {
680
+ const handle2 = requestIdleCallback(callback, { timeout: 120 });
681
+ return () => cancelIdleCallback(handle2);
682
+ }
683
+ const handle = setTimeout(callback, 16);
684
+ return () => clearTimeout(handle);
685
+ }
686
+ function cornerRadius(element, width, height) {
687
+ const value = getComputedStyle(element).borderTopLeftRadius;
688
+ const n = parseFloat(value);
689
+ if (!Number.isFinite(n)) return 0;
690
+ return value.endsWith("%") ? Math.min(width, height) * n / 100 : n;
691
+ }
692
+ function useRefraction(ref, shape = {}, enabled = true, mirror) {
693
+ const signature = JSON.stringify(shape);
694
+ useEffect2(() => {
695
+ const element = ref.current;
696
+ if (!element || !enabled) return;
697
+ const live = canRefractBackdrop();
698
+ let cancel;
699
+ let filter = "";
700
+ let pad = 0;
701
+ const fit = () => {
702
+ const width = element.offsetWidth;
703
+ const height = element.offsetHeight;
704
+ if (!width || !height) return;
705
+ const radius = cornerRadius(element, width, height);
706
+ const baked = glassFor(width, height, radius, shape);
707
+ filter = baked.filter;
708
+ if (!live && mirror?.current) pad = Math.ceil(Math.min(width, height) * 0.45 + 6);
709
+ if (live) element.style.setProperty("--lg-filter", baked.filter);
710
+ element.style.setProperty("--lg-rim", baked.rim);
711
+ };
712
+ const observer = new ResizeObserver(() => {
713
+ cancel?.();
714
+ cancel = idle(fit);
715
+ });
716
+ observer.observe(element);
717
+ fit();
718
+ const source = mirror?.current;
719
+ const unmirror = !live && source ? mirrorBackdrop(element, source, () => filter, () => pad) : void 0;
720
+ return () => {
721
+ cancel?.();
722
+ unmirror?.();
723
+ observer.disconnect();
724
+ element.style.removeProperty("--lg-filter");
725
+ element.style.removeProperty("--lg-rim");
726
+ };
727
+ }, [ref, signature, enabled, mirror]);
728
+ }
729
+
730
+ // src/engine/haptics.ts
731
+ var label = null;
732
+ var isIOS = () => typeof navigator !== "undefined" && (/iP(hone|ad|od)/.test(navigator.userAgent) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1);
733
+ function haptic() {
734
+ if (typeof window === "undefined") return;
735
+ if (!matchMedia("(pointer: coarse)").matches) return;
736
+ try {
737
+ if (typeof navigator.vibrate === "function" && !isIOS()) {
738
+ navigator.vibrate(8);
739
+ return;
740
+ }
741
+ if (!isIOS()) return;
742
+ if (!label?.isConnected) {
743
+ label = document.createElement("label");
744
+ label.setAttribute("aria-hidden", "true");
745
+ label.style.cssText = "position:fixed;width:1px;height:1px;overflow:hidden;opacity:0;pointer-events:none;left:-9px;top:-9px";
746
+ const input = document.createElement("input");
747
+ input.type = "checkbox";
748
+ input.setAttribute("switch", "");
749
+ input.tabIndex = -1;
750
+ label.append(input);
751
+ document.body.append(label);
752
+ }
753
+ label.click();
754
+ } catch {
755
+ }
67
756
  }
68
757
 
69
758
  // src/components/GlassButton/GlassButton.tsx
70
- import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
71
- var GlassButton = React2.forwardRef(
759
+ import { jsx, jsxs } from "react/jsx-runtime";
760
+ var GlassButton = React.forwardRef(
72
761
  ({
73
762
  intensity = 5,
74
763
  tint,
@@ -76,191 +765,74 @@ var GlassButton = React2.forwardRef(
76
765
  thickness = 1,
77
766
  size = "md",
78
767
  variant = "default",
768
+ icon,
79
769
  className,
80
770
  style,
81
771
  children,
772
+ type = "button",
773
+ onPointerDown,
82
774
  ...rest
83
- }, ref) => {
84
- const isFilterMounted = useGlassFilterMounted();
85
- const clampedIntensity = Math.max(1, Math.min(10, Math.round(intensity)));
86
- const glassStyle = useMemo(() => {
87
- const filterId = `liquid-glass-refract-${clampedIntensity}`;
88
- const vars = {
89
- "--glass-blur": `${clampedIntensity * 2.4}px`,
90
- "--glass-border-width": `${thickness}px`,
91
- "--glass-refraction-filter": `url(#${filterId})`
92
- };
93
- if (tint) {
94
- vars["--glass-tint"] = tint;
775
+ }, forwardedRef) => {
776
+ const ref = useRef(null);
777
+ useImperativeHandle(forwardedRef, () => ref.current);
778
+ const level = Math.max(1, Math.min(10, intensity));
779
+ const height = size === "sm" ? 36 : size === "lg" ? 52 : 44;
780
+ usePress(ref, { disabled: rest.disabled });
781
+ useRefraction(ref, {
782
+ kind: "surface",
783
+ strength: level / 5,
784
+ bezel: Math.min(height * 0.36, 22) * Math.max(0.5, thickness)
785
+ });
786
+ const iconOnly = icon != null && (children == null || children === false);
787
+ const kind = variant === "ghost" ? "clear" : variant;
788
+ const classes = ["lg-glass", "lg-button", `lg-button--${size}`, `lg-button--${kind}`, className].filter(Boolean).join(" ");
789
+ return /* @__PURE__ */ jsxs(
790
+ "button",
791
+ {
792
+ ref,
793
+ type,
794
+ className: classes,
795
+ "data-liquid-glass": "",
796
+ "data-icon-only": iconOnly ? "" : void 0,
797
+ "data-shimmer": shimmer ? "" : void 0,
798
+ style: tint ? { "--lg-tint": tint, ...style } : style,
799
+ onPointerDown: (event) => {
800
+ if (!rest.disabled) haptic();
801
+ onPointerDown?.(event);
802
+ },
803
+ ...rest,
804
+ children: [
805
+ icon != null && /* @__PURE__ */ jsx("span", { className: "lg-button__icon", children: icon }),
806
+ !iconOnly && children != null && /* @__PURE__ */ jsx("span", { className: "lg-button__label", children })
807
+ ]
95
808
  }
96
- return vars;
97
- }, [clampedIntensity, tint, thickness]);
98
- const rootClasses = [
99
- "lg-root",
100
- "lg-button",
101
- `lg-button--${size}`,
102
- `lg-button--${variant}`,
103
- shimmer ? "lg-button--shimmer" : "",
104
- className ?? ""
105
- ].filter(Boolean).join(" ");
106
- const freq1 = 0.012 + clampedIntensity * 1e-3;
107
- const freq2 = 0.01 + clampedIntensity * 8e-4;
108
- const scale = clampedIntensity * 2;
109
- return /* @__PURE__ */ jsxs2("div", { className: rootClasses, "data-liquid-glass": true, style: { ...glassStyle, ...style }, children: [
110
- !isFilterMounted && /* @__PURE__ */ jsx2(
111
- "svg",
112
- {
113
- width: "0",
114
- height: "0",
115
- style: { position: "absolute", pointerEvents: "none" },
116
- "aria-hidden": "true",
117
- children: /* @__PURE__ */ jsx2("defs", { children: /* @__PURE__ */ jsxs2(
118
- "filter",
119
- {
120
- id: `liquid-glass-refract-${clampedIntensity}`,
121
- x: "-10%",
122
- y: "-10%",
123
- width: "120%",
124
- height: "120%",
125
- colorInterpolationFilters: "sRGB",
126
- children: [
127
- /* @__PURE__ */ jsx2(
128
- "feTurbulence",
129
- {
130
- type: "fractalNoise",
131
- baseFrequency: `${freq1} ${freq2}`,
132
- numOctaves: 3,
133
- seed: 42,
134
- result: "noise"
135
- }
136
- ),
137
- /* @__PURE__ */ jsx2(
138
- "feDisplacementMap",
139
- {
140
- in: "SourceGraphic",
141
- in2: "noise",
142
- scale,
143
- xChannelSelector: "R",
144
- yChannelSelector: "G"
145
- }
146
- )
147
- ]
148
- }
149
- ) })
150
- }
151
- ),
152
- /* @__PURE__ */ jsx2(
153
- "button",
154
- {
155
- ref,
156
- className: "lg-surface",
157
- ...rest,
158
- children: /* @__PURE__ */ jsx2("span", { className: "lg-content", children })
159
- }
160
- ),
161
- /* @__PURE__ */ jsx2("div", { className: "lg-backdrop-surface", "aria-hidden": "true" }),
162
- /* @__PURE__ */ jsx2("div", { className: "lg-shadow", "aria-hidden": "true" })
163
- ] });
809
+ );
164
810
  }
165
811
  );
166
812
  GlassButton.displayName = "GlassButton";
167
813
 
168
814
  // src/components/GlassCard/GlassCard.tsx
169
- import React3, { useMemo as useMemo2 } from "react";
170
- import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
171
- var GlassCard = React3.forwardRef(
172
- ({
173
- intensity = 5,
174
- tint,
175
- shimmer = true,
176
- thickness = 1,
177
- padding = "24px",
178
- radius = "20px",
179
- className,
180
- style,
181
- children,
182
- ...rest
183
- }, ref) => {
184
- const isFilterMounted = useGlassFilterMounted();
185
- const clampedIntensity = Math.max(1, Math.min(10, Math.round(intensity)));
186
- const glassStyle = useMemo2(() => {
187
- const filterId = `liquid-glass-refract-${clampedIntensity}`;
188
- const vars = {
189
- "--glass-blur": `${clampedIntensity * 2.4}px`,
190
- "--glass-border-width": `${thickness}px`,
191
- "--glass-radius": radius,
192
- "--glass-padding": padding,
193
- "--glass-refraction-filter": `url(#${filterId})`
194
- };
195
- if (tint) {
196
- vars["--glass-tint"] = tint;
197
- }
198
- return vars;
199
- }, [clampedIntensity, tint, thickness, radius, padding]);
200
- const rootClasses = [
201
- "lg-root",
202
- "lg-card",
203
- shimmer ? "lg-card--shimmer" : "",
204
- className ?? ""
205
- ].filter(Boolean).join(" ");
206
- const freq1 = 0.012 + clampedIntensity * 1e-3;
207
- const freq2 = 0.01 + clampedIntensity * 8e-4;
208
- const scale = clampedIntensity * 2;
209
- return /* @__PURE__ */ jsxs3(
815
+ import React2, { useImperativeHandle as useImperativeHandle2, useRef as useRef2 } from "react";
816
+ import { jsx as jsx2 } from "react/jsx-runtime";
817
+ var GlassCard = React2.forwardRef(
818
+ ({ intensity = 5, tint, shimmer: _shimmer, thickness = 1, padding = "24px", radius = "28px", variant = "regular", className, style, children, ...rest }, forwardedRef) => {
819
+ const ref = useRef2(null);
820
+ useImperativeHandle2(forwardedRef, () => ref.current);
821
+ useRefraction(ref, {
822
+ kind: "surface",
823
+ strength: Math.max(1, Math.min(10, intensity)) / 5,
824
+ bezel: 16 * Math.max(0.5, thickness),
825
+ thickness: 22 * Math.max(0.5, thickness)
826
+ });
827
+ return /* @__PURE__ */ jsx2(
210
828
  "div",
211
829
  {
212
830
  ref,
213
- className: rootClasses,
214
- "data-liquid-glass": true,
215
- style: { ...glassStyle, ...style },
831
+ className: ["lg-glass", "lg-card", `lg-card--${variant}`, className].filter(Boolean).join(" "),
832
+ "data-liquid-glass": "",
833
+ style: { padding, borderRadius: radius, ...tint ? { "--lg-card-tint": tint } : {}, ...style },
216
834
  ...rest,
217
- children: [
218
- !isFilterMounted && /* @__PURE__ */ jsx3(
219
- "svg",
220
- {
221
- width: "0",
222
- height: "0",
223
- style: { position: "absolute", pointerEvents: "none" },
224
- "aria-hidden": "true",
225
- children: /* @__PURE__ */ jsx3("defs", { children: /* @__PURE__ */ jsxs3(
226
- "filter",
227
- {
228
- id: `liquid-glass-refract-${clampedIntensity}`,
229
- x: "-10%",
230
- y: "-10%",
231
- width: "120%",
232
- height: "120%",
233
- colorInterpolationFilters: "sRGB",
234
- children: [
235
- /* @__PURE__ */ jsx3(
236
- "feTurbulence",
237
- {
238
- type: "fractalNoise",
239
- baseFrequency: `${freq1} ${freq2}`,
240
- numOctaves: 3,
241
- seed: 42,
242
- result: "noise"
243
- }
244
- ),
245
- /* @__PURE__ */ jsx3(
246
- "feDisplacementMap",
247
- {
248
- in: "SourceGraphic",
249
- in2: "noise",
250
- scale,
251
- xChannelSelector: "R",
252
- yChannelSelector: "G"
253
- }
254
- )
255
- ]
256
- }
257
- ) })
258
- }
259
- ),
260
- /* @__PURE__ */ jsx3("div", { className: "lg-surface lg-card__surface", children: /* @__PURE__ */ jsx3("div", { className: "lg-content lg-card__content", children }) }),
261
- /* @__PURE__ */ jsx3("div", { className: "lg-backdrop-surface lg-card__backdrop-surface", "aria-hidden": "true" }),
262
- /* @__PURE__ */ jsx3("div", { className: "lg-shadow", "aria-hidden": "true" })
263
- ]
835
+ children
264
836
  }
265
837
  );
266
838
  }
@@ -268,336 +840,963 @@ var GlassCard = React3.forwardRef(
268
840
  GlassCard.displayName = "GlassCard";
269
841
 
270
842
  // src/components/GlassInput/GlassInput.tsx
271
- import React4, { useMemo as useMemo3, useId, useState, useCallback } from "react";
272
- import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
273
- var GlassInput = React4.forwardRef(
274
- ({
275
- intensity = 5,
276
- tint,
277
- placeholder,
278
- value,
279
- onChange,
280
- label,
281
- className,
282
- style,
283
- id: externalId,
284
- ...rest
285
- }, ref) => {
286
- const autoId = useId();
287
- const inputId = externalId ?? autoId;
843
+ import React3, { useImperativeHandle as useImperativeHandle3, useRef as useRef3, useState } from "react";
844
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
845
+ var Magnifier = /* @__PURE__ */ jsxs2("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", "aria-hidden": "true", children: [
846
+ /* @__PURE__ */ jsx3("circle", { cx: "8.5", cy: "8.5", r: "5.75" }),
847
+ /* @__PURE__ */ jsx3("path", { d: "m13 13 4 4" })
848
+ ] });
849
+ var ClearGlyph = /* @__PURE__ */ jsxs2("svg", { viewBox: "0 0 20 20", "aria-hidden": "true", children: [
850
+ /* @__PURE__ */ jsx3("circle", { cx: "10", cy: "10", r: "9", fill: "currentColor" }),
851
+ /* @__PURE__ */ jsx3("path", { d: "m7 7 6 6m0-6-6 6", stroke: "var(--lg-clear-x, #fff)", strokeWidth: 1.7, strokeLinecap: "round" })
852
+ ] });
853
+ var GlassInput = React3.forwardRef(
854
+ ({ intensity = 5, tint, label: label2, icon, trailing, onClear, className, style, value, onChange, type = "text", disabled, onFocus, onBlur, ...rest }, forwardedRef) => {
855
+ const fieldRef = useRef3(null);
856
+ const inputRef = useRef3(null);
857
+ useImperativeHandle3(forwardedRef, () => inputRef.current);
288
858
  const [focused, setFocused] = useState(false);
289
- const [hasValue, setHasValue] = useState(() => Boolean(value));
290
- const isFilterMounted = useGlassFilterMounted();
291
- const clampedIntensity = Math.max(1, Math.min(10, Math.round(intensity)));
292
- const handleFocus = useCallback(
293
- (e) => {
294
- setFocused(true);
295
- rest.onFocus?.(e);
296
- },
297
- [rest.onFocus]
298
- );
299
- const handleBlur = useCallback(
300
- (e) => {
301
- setFocused(false);
302
- rest.onBlur?.(e);
303
- },
304
- [rest.onBlur]
305
- );
306
- const handleChange = useCallback(
307
- (e) => {
308
- setHasValue(e.target.value.length > 0);
309
- onChange?.(e);
310
- },
311
- [onChange]
312
- );
313
- const glassStyle = useMemo3(() => {
314
- const filterId = `liquid-glass-refract-${clampedIntensity}`;
315
- const vars = {
316
- "--glass-blur": `${clampedIntensity * 2.4}px`,
317
- "--glass-border-width": "1px",
318
- "--glass-refraction-filter": `url(#${filterId})`
319
- };
320
- if (tint) {
321
- vars["--glass-tint"] = tint;
859
+ const [inner, setInner] = useState("");
860
+ const current = value ?? inner;
861
+ useRefraction(fieldRef, { kind: "surface", strength: Math.max(1, Math.min(10, intensity)) / 5 });
862
+ usePress(fieldRef, { grow: 0.03, lean: 3, stretch: 0.03, disabled });
863
+ const leading = icon ?? (type === "search" ? Magnifier : null);
864
+ const clear = () => {
865
+ if (onClear) onClear();
866
+ else {
867
+ const input = inputRef.current;
868
+ const setter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")?.set;
869
+ setter?.call(input, "");
870
+ input.dispatchEvent(new Event("input", { bubbles: true }));
322
871
  }
323
- return vars;
324
- }, [clampedIntensity, tint]);
325
- const rootClasses = [
326
- "lg-root",
327
- "lg-input",
328
- focused ? "lg-input--focused" : "",
329
- hasValue || value ? "lg-input--has-value" : "",
330
- className ?? ""
331
- ].filter(Boolean).join(" ");
332
- const freq1 = 0.012 + clampedIntensity * 1e-3;
333
- const freq2 = 0.01 + clampedIntensity * 8e-4;
334
- const scale = clampedIntensity * 2;
335
- return /* @__PURE__ */ jsxs4("div", { className: rootClasses, "data-liquid-glass": true, style: { ...glassStyle, ...style }, children: [
336
- !isFilterMounted && /* @__PURE__ */ jsx4(
337
- "svg",
338
- {
339
- width: "0",
340
- height: "0",
341
- style: { position: "absolute", pointerEvents: "none" },
342
- "aria-hidden": "true",
343
- children: /* @__PURE__ */ jsx4("defs", { children: /* @__PURE__ */ jsxs4(
344
- "filter",
345
- {
346
- id: `liquid-glass-refract-${clampedIntensity}`,
347
- x: "-10%",
348
- y: "-10%",
349
- width: "120%",
350
- height: "120%",
351
- colorInterpolationFilters: "sRGB",
352
- children: [
353
- /* @__PURE__ */ jsx4(
354
- "feTurbulence",
355
- {
356
- type: "fractalNoise",
357
- baseFrequency: `${freq1} ${freq2}`,
358
- numOctaves: 3,
359
- seed: 42,
360
- result: "noise"
361
- }
362
- ),
363
- /* @__PURE__ */ jsx4(
364
- "feDisplacementMap",
365
- {
366
- in: "SourceGraphic",
367
- in2: "noise",
368
- scale,
369
- xChannelSelector: "R",
370
- yChannelSelector: "G"
371
- }
372
- )
373
- ]
374
- }
375
- ) })
376
- }
377
- ),
378
- /* @__PURE__ */ jsx4("div", { className: "lg-surface lg-input__surface", children: /* @__PURE__ */ jsxs4("div", { className: "lg-content lg-input__content", children: [
379
- label && /* @__PURE__ */ jsx4("label", { className: "lg-input__label", htmlFor: inputId, children: label }),
380
- /* @__PURE__ */ jsx4(
381
- "input",
382
- {
383
- ref,
384
- id: inputId,
385
- className: "lg-input__field",
386
- type: "text",
387
- placeholder: label ? void 0 : placeholder,
388
- value,
389
- onChange: handleChange,
390
- onFocus: handleFocus,
391
- onBlur: handleBlur,
392
- ...rest
393
- }
394
- )
395
- ] }) }),
396
- /* @__PURE__ */ jsx4("div", { className: "lg-backdrop-surface lg-input__backdrop-surface", "aria-hidden": "true" }),
397
- /* @__PURE__ */ jsx4("div", { className: "lg-shadow", "aria-hidden": "true" })
398
- ] });
872
+ inputRef.current?.focus();
873
+ };
874
+ return /* @__PURE__ */ jsxs2(
875
+ "label",
876
+ {
877
+ className: ["lg-input", className].filter(Boolean).join(" "),
878
+ "data-liquid-glass": "",
879
+ style: tint ? { "--lg-input-tint": tint, ...style } : style,
880
+ children: [
881
+ label2 && /* @__PURE__ */ jsx3("span", { className: "lg-input__label", children: label2 }),
882
+ /* @__PURE__ */ jsxs2("div", { ref: fieldRef, className: "lg-glass lg-input__field", "data-focused": focused ? "" : void 0, children: [
883
+ leading && /* @__PURE__ */ jsx3("span", { className: "lg-input__icon", children: leading }),
884
+ /* @__PURE__ */ jsx3(
885
+ "input",
886
+ {
887
+ ref: inputRef,
888
+ type,
889
+ value: current,
890
+ disabled,
891
+ onChange: (event) => {
892
+ if (value === void 0) setInner(event.target.value);
893
+ onChange?.(event);
894
+ },
895
+ onFocus: (event) => {
896
+ setFocused(true);
897
+ onFocus?.(event);
898
+ },
899
+ onBlur: (event) => {
900
+ setFocused(false);
901
+ onBlur?.(event);
902
+ },
903
+ ...rest
904
+ }
905
+ ),
906
+ current && !disabled ? /* @__PURE__ */ jsx3(
907
+ "button",
908
+ {
909
+ type: "button",
910
+ className: "lg-input__clear",
911
+ "aria-label": "Clear",
912
+ onPointerDown: (event) => event.preventDefault(),
913
+ onClick: clear,
914
+ children: ClearGlyph
915
+ }
916
+ ) : trailing && /* @__PURE__ */ jsx3("span", { className: "lg-input__icon lg-input__trailing", children: trailing })
917
+ ] })
918
+ ]
919
+ }
920
+ );
399
921
  }
400
922
  );
401
923
  GlassInput.displayName = "GlassInput";
402
924
 
403
925
  // src/components/GlassSheet/GlassSheet.tsx
404
- import { useEffect, useState as useState2, useCallback as useCallback2, useMemo as useMemo4, useRef } from "react";
405
- import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
406
- var GlassSheet = ({
407
- open,
408
- onClose,
409
- intensity = 5,
410
- tint,
411
- children
412
- }) => {
926
+ import { useEffect as useEffect3, useRef as useRef4, useState as useState2 } from "react";
927
+ import { createPortal } from "react-dom";
928
+ import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
929
+ var OPEN = springFrom(0.42, 0.86);
930
+ var CLOSE = springFrom(0.34, 1);
931
+ var GlassSheet = ({ open, onClose, intensity = 5, tint, children, "aria-label": ariaLabel }) => {
413
932
  const [mounted, setMounted] = useState2(open);
414
- const [visible, setVisible] = useState2(false);
415
- const sheetRef = useRef(null);
416
- const isFilterMounted = useGlassFilterMounted();
417
- const clampedIntensity = Math.max(1, Math.min(10, Math.round(intensity)));
418
- useEffect(() => {
419
- if (open) {
420
- setMounted(true);
421
- requestAnimationFrame(() => {
422
- requestAnimationFrame(() => setVisible(true));
423
- });
424
- } else {
425
- setVisible(false);
426
- }
933
+ const sheetRef = useRef4(null);
934
+ const scrimRef = useRef4(null);
935
+ const progress = useRef4(null);
936
+ const closeRef = useRef4(onClose);
937
+ closeRef.current = onClose;
938
+ useEffect3(() => {
939
+ if (open) setMounted(true);
940
+ else progress.current?.set(0);
427
941
  }, [open]);
428
- const handleTransitionEnd = useCallback2(() => {
429
- if (!open) setMounted(false);
430
- }, [open]);
431
- useEffect(() => {
432
- if (!open) return;
433
- const onKeyDown = (e) => {
434
- if (e.key === "Escape") onClose?.();
942
+ useRefraction(sheetRef, { kind: "surface", strength: Math.max(1, Math.min(10, intensity)) / 5, bezel: 20, thickness: 28 }, mounted);
943
+ useEffect3(() => {
944
+ if (!mounted) return;
945
+ const sheet = sheetRef.current;
946
+ const scrim = scrimRef.current;
947
+ let height = sheet.offsetHeight || 400;
948
+ let drag = 0;
949
+ const paint = (p) => {
950
+ const y = (1 - p) * (height + 24) + drag;
951
+ sheet.style.transform = `translateY(${y}px)`;
952
+ scrim.style.opacity = String(clamp(p, 0, 1) * clamp(1 - drag / height, 0, 1));
953
+ };
954
+ const spring = createSpring(0, OPEN, (p) => {
955
+ paint(p);
956
+ if (p <= 1e-3 && spring.target === 0) setMounted(false);
957
+ });
958
+ progress.current = {
959
+ ...spring,
960
+ set(target, instant) {
961
+ spring.tune(target ? OPEN : CLOSE);
962
+ spring.set(target, instant);
963
+ }
964
+ };
965
+ paint(0);
966
+ requestAnimationFrame(() => {
967
+ height = sheet.offsetHeight || height;
968
+ if (open) progress.current?.set(1);
969
+ });
970
+ let gesture = null;
971
+ const down = (event) => {
972
+ const target = event.target;
973
+ if (!target.closest(".lg-sheet__grabber-zone") && sheet.scrollTop > 0) return;
974
+ if (target.closest('input, textarea, button, a, [role="slider"], [role="switch"]')) return;
975
+ gesture = { id: event.pointerId, y: event.clientY, t: event.timeStamp, v: 0 };
976
+ sheet.setPointerCapture(event.pointerId);
977
+ };
978
+ const move = (event) => {
979
+ if (event.pointerId !== gesture?.id) return;
980
+ const dy = event.clientY - gesture.y;
981
+ const dt = Math.max(1, event.timeStamp - gesture.t);
982
+ gesture.v = (dy - drag) / dt;
983
+ gesture.t = event.timeStamp;
984
+ drag = dy > 0 ? dy : rubberband(dy, height, 0.3);
985
+ paint(spring.value);
986
+ };
987
+ const up = (event) => {
988
+ if (event.pointerId !== gesture?.id) return;
989
+ const flick = gesture.v > 0.6;
990
+ gesture = null;
991
+ const settle = createSpring(drag, SPRINGS.snap, (value) => {
992
+ drag = value;
993
+ paint(spring.value);
994
+ });
995
+ if (flick || drag > height * 0.3) {
996
+ settle.stop();
997
+ const p = 1 - clamp(drag / (height + 24), 0, 1);
998
+ drag = 0;
999
+ spring.set(p, true);
1000
+ closeRef.current?.();
1001
+ } else {
1002
+ settle.set(0);
1003
+ }
1004
+ };
1005
+ const key = (event) => {
1006
+ if (event.key === "Escape") closeRef.current?.();
1007
+ };
1008
+ sheet.addEventListener("pointerdown", down);
1009
+ sheet.addEventListener("pointermove", move);
1010
+ sheet.addEventListener("pointerup", up);
1011
+ sheet.addEventListener("pointercancel", up);
1012
+ window.addEventListener("keydown", key);
1013
+ const overflow = document.body.style.overflow;
1014
+ document.body.style.overflow = "hidden";
1015
+ sheet.focus({ preventScroll: true });
1016
+ return () => {
1017
+ spring.stop();
1018
+ progress.current = null;
1019
+ sheet.removeEventListener("pointerdown", down);
1020
+ sheet.removeEventListener("pointermove", move);
1021
+ sheet.removeEventListener("pointerup", up);
1022
+ sheet.removeEventListener("pointercancel", up);
1023
+ window.removeEventListener("keydown", key);
1024
+ document.body.style.overflow = overflow;
435
1025
  };
436
- window.addEventListener("keydown", onKeyDown);
437
- return () => window.removeEventListener("keydown", onKeyDown);
438
- }, [open, onClose]);
439
- useEffect(() => {
440
- if (mounted) {
441
- const prev = document.body.style.overflow;
442
- document.body.style.overflow = "hidden";
443
- return () => {
444
- document.body.style.overflow = prev;
445
- };
446
- }
447
1026
  }, [mounted]);
448
- const glassStyle = useMemo4(() => {
449
- const filterId = `liquid-glass-refract-${clampedIntensity}`;
450
- const vars = {
451
- "--glass-blur": `${clampedIntensity * 2.4}px`,
452
- "--glass-border-width": "1px",
453
- "--glass-refraction-filter": `url(#${filterId})`
1027
+ if (!mounted || typeof document === "undefined") return null;
1028
+ return createPortal(
1029
+ /* @__PURE__ */ jsxs3("div", { className: "lg-sheet-layer", "data-liquid-glass": "", children: [
1030
+ /* @__PURE__ */ jsx4("div", { ref: scrimRef, className: "lg-sheet__scrim", onClick: () => onClose?.(), "aria-hidden": "true" }),
1031
+ /* @__PURE__ */ jsxs3(
1032
+ "div",
1033
+ {
1034
+ ref: sheetRef,
1035
+ role: "dialog",
1036
+ "aria-modal": "true",
1037
+ "aria-label": ariaLabel,
1038
+ tabIndex: -1,
1039
+ className: "lg-glass lg-sheet",
1040
+ style: tint ? { "--lg-card-tint": tint } : void 0,
1041
+ children: [
1042
+ /* @__PURE__ */ jsx4("div", { className: "lg-sheet__grabber-zone", "aria-hidden": "true", children: /* @__PURE__ */ jsx4("span", { className: "lg-sheet__grabber" }) }),
1043
+ /* @__PURE__ */ jsx4("div", { className: "lg-sheet__content", children })
1044
+ ]
1045
+ }
1046
+ )
1047
+ ] }),
1048
+ document.body
1049
+ );
1050
+ };
1051
+ GlassSheet.displayName = "GlassSheet";
1052
+
1053
+ // src/components/GlassNav/GlassNav.tsx
1054
+ import React6 from "react";
1055
+
1056
+ // src/components/internal/LensTrack.tsx
1057
+ import { useRef as useRef6 } from "react";
1058
+
1059
+ // src/engine/lensTrack.ts
1060
+ import { useEffect as useEffect4, useRef as useRef5 } from "react";
1061
+ function useLensTrack(refs, options) {
1062
+ const latest = useRef5(options);
1063
+ latest.current = options;
1064
+ const api = useRef5(null);
1065
+ useEffect4(() => {
1066
+ const bar = refs.bar.current;
1067
+ const lens = refs.lens.current;
1068
+ const tint = refs.tint.current;
1069
+ const row = refs.row.current;
1070
+ const glass = refs.glass.current;
1071
+ if (!bar || !lens || !tint || !row || !glass) return;
1072
+ let slot = 0;
1073
+ let height = 0;
1074
+ let pad = 0;
1075
+ let barHeight = 0;
1076
+ const state = { x: 0, lift: 0, swell: 0, squash: 0 };
1077
+ let current = latest.current.index;
1078
+ let gesture = null;
1079
+ let suppressClick = false;
1080
+ const measure = () => {
1081
+ const style = getComputedStyle(bar);
1082
+ pad = parseFloat(style.paddingLeft) || 0;
1083
+ slot = (bar.clientWidth - pad - (parseFloat(style.paddingRight) || 0)) / latest.current.count;
1084
+ height = lens.offsetHeight;
1085
+ barHeight = bar.offsetHeight;
454
1086
  };
455
- if (tint) {
456
- vars["--glass-tint"] = tint;
1087
+ const paint = () => {
1088
+ const { x: x2, lift: lift2, swell: swell2, squash } = state;
1089
+ const { overhang, spread } = latest.current;
1090
+ const liftH = barHeight + overhang - height;
1091
+ const sx = 1 + spread * lift2 + squash;
1092
+ const sy = 1 + liftH / height * lift2 - squash * 0.6;
1093
+ const transform = `translateX(${x2}px) scale(${sx}, ${sy})`;
1094
+ lens.style.transform = transform;
1095
+ tint.style.transform = transform;
1096
+ row.style.transform = `scale(${1 / sx}, ${1 / sy}) translate(${(sx - 1) * slot / 2 - x2}px, ${(sy - 1) * height / 2}px)`;
1097
+ const grow = 1 + latest.current.swell / Math.max(bar.offsetWidth, 1) * swell2;
1098
+ bar.style.scale = `${grow}`;
1099
+ lens.style.setProperty("--lg-lift", String(clamp(lift2, 0, 1)));
1100
+ bar.style.setProperty("--lg-lift", String(clamp(lift2, 0, 1)));
1101
+ if (!gesture && lift2 < 0.02) delete bar.dataset.lifted;
1102
+ };
1103
+ const x = createSpring(current * slot, SPRINGS.snap, (value, velocity) => {
1104
+ state.x = value;
1105
+ state.squash = clamp(Math.abs(velocity) / 4200, 0, 0.16);
1106
+ paint();
1107
+ });
1108
+ const lift = createSpring(0, SPRINGS.lift, (value) => {
1109
+ state.lift = value;
1110
+ paint();
1111
+ });
1112
+ const swell = createSpring(0, SPRINGS.press, (value) => {
1113
+ state.swell = value;
1114
+ paint();
1115
+ });
1116
+ const place = (index, instant = false) => {
1117
+ current = index;
1118
+ if (!gesture) {
1119
+ x.tune(SPRINGS.snap);
1120
+ x.set(index * slot, instant);
1121
+ }
1122
+ };
1123
+ const position = (clientX) => {
1124
+ if (!gesture) return 0;
1125
+ const raw = gesture.anchor + clientX - gesture.startX;
1126
+ const max = slot * (latest.current.count - 1);
1127
+ if (raw < 0) return rubberband(raw, slot, 0.5);
1128
+ if (raw > max) return max + rubberband(raw - max, slot, 0.5);
1129
+ return raw;
1130
+ };
1131
+ const light = (clientX, box) => {
1132
+ glass.style.setProperty("--lg-x", `${clamp((clientX - box.left) / box.width * 100, 0, 100)}%`);
1133
+ lens.style.setProperty("--lg-x", `${clamp((clientX - box.left - pad - state.x) / slot * 100, 0, 100)}%`);
1134
+ };
1135
+ const itemAt = (event) => {
1136
+ const target = event.target.closest("[data-lg-item]");
1137
+ return target && bar.contains(target) ? Number(target.dataset.lgItem) : -1;
1138
+ };
1139
+ const onDown = (event) => {
1140
+ if (!event.isPrimary || event.button !== 0 || gesture) return;
1141
+ const index = itemAt(event);
1142
+ if (index < 0) return;
1143
+ measure();
1144
+ const box = bar.getBoundingClientRect();
1145
+ gesture = { id: event.pointerId, startX: event.clientX, anchor: index * slot, moved: false, box, hovered: index };
1146
+ suppressClick = false;
1147
+ bar.dataset.lifted = "";
1148
+ lens.dataset.pressed = "";
1149
+ light(event.clientX, box);
1150
+ haptic();
1151
+ lift.tune(SPRINGS.lift);
1152
+ lift.set(1);
1153
+ swell.tune(SPRINGS.press);
1154
+ swell.set(1);
1155
+ x.tune(SPRINGS.snap);
1156
+ x.set(index * slot);
1157
+ };
1158
+ const onMove = (event) => {
1159
+ if (event.pointerId !== gesture?.id) return;
1160
+ if (!gesture.moved && Math.abs(event.clientX - gesture.startX) > 5) {
1161
+ gesture.moved = true;
1162
+ try {
1163
+ bar.setPointerCapture(event.pointerId);
1164
+ } catch {
1165
+ }
1166
+ }
1167
+ light(event.clientX, gesture.box);
1168
+ if (!gesture.moved) return;
1169
+ const at = position(event.clientX);
1170
+ x.tune(SPRINGS.drag);
1171
+ x.set(at);
1172
+ const hovered = clamp(Math.round(at / slot), 0, latest.current.count - 1);
1173
+ if (hovered !== gesture.hovered) {
1174
+ gesture.hovered = hovered;
1175
+ haptic();
1176
+ }
1177
+ };
1178
+ const finish = (event, commit) => {
1179
+ if (event.pointerId !== gesture?.id) return;
1180
+ const { moved, box } = gesture;
1181
+ const at = moved ? position(event.clientX) : gesture.anchor;
1182
+ const index = clamp(Math.round(at / slot), 0, latest.current.count - 1);
1183
+ gesture = null;
1184
+ delete lens.dataset.pressed;
1185
+ if (bar.hasPointerCapture?.(event.pointerId)) bar.releasePointerCapture(event.pointerId);
1186
+ const inside = event.clientY >= box.top - 30 && event.clientY <= box.bottom + 30;
1187
+ lift.tune(SPRINGS.settle);
1188
+ lift.set(0);
1189
+ swell.tune(SPRINGS.release);
1190
+ swell.set(0);
1191
+ x.tune(SPRINGS.snap);
1192
+ if (commit && (moved || inside)) {
1193
+ suppressClick = true;
1194
+ current = index;
1195
+ x.set(index * slot);
1196
+ if (index !== latest.current.index) latest.current.onSelect(index);
1197
+ } else {
1198
+ x.set(current * slot);
1199
+ }
1200
+ };
1201
+ const onUp = (event) => finish(event, true);
1202
+ const onCancel = (event) => finish(event, false);
1203
+ const onClick = (event) => {
1204
+ if (suppressClick && event.detail !== 0) {
1205
+ suppressClick = false;
1206
+ event.preventDefault();
1207
+ event.stopPropagation();
1208
+ return;
1209
+ }
1210
+ const target = event.target.closest("[data-lg-item]");
1211
+ if (!target) return;
1212
+ const index = Number(target.dataset.lgItem);
1213
+ if (index !== latest.current.index) latest.current.onSelect(index);
1214
+ };
1215
+ const onKey = (event) => {
1216
+ const keys = ["ArrowLeft", "ArrowRight", "Home", "End"];
1217
+ if (!keys.includes(event.key)) return;
1218
+ event.preventDefault();
1219
+ const { count, index } = latest.current;
1220
+ const next = event.key === "Home" ? 0 : event.key === "End" ? count - 1 : (index + (event.key === "ArrowRight" ? 1 : count - 1)) % count;
1221
+ latest.current.onSelect(next);
1222
+ bar.querySelector(`[data-lg-item="${next}"]`)?.focus();
1223
+ };
1224
+ const onTouchMove = (event) => {
1225
+ if (gesture?.moved && event.cancelable) event.preventDefault();
1226
+ };
1227
+ const observer = new ResizeObserver(() => {
1228
+ measure();
1229
+ if (!gesture) x.set(current * slot, true);
1230
+ });
1231
+ measure();
1232
+ x.set(current * slot, true);
1233
+ bar.dataset.ready = "";
1234
+ observer.observe(bar);
1235
+ bar.addEventListener("pointerdown", onDown);
1236
+ window.addEventListener("pointermove", onMove);
1237
+ window.addEventListener("pointerup", onUp);
1238
+ window.addEventListener("pointercancel", onCancel);
1239
+ bar.addEventListener("click", onClick, true);
1240
+ bar.addEventListener("keydown", onKey);
1241
+ bar.addEventListener("touchmove", onTouchMove, { passive: false });
1242
+ api.current = { setIndex: place };
1243
+ return () => {
1244
+ api.current = null;
1245
+ [x, lift, swell].forEach((s) => s.stop());
1246
+ observer.disconnect();
1247
+ bar.removeEventListener("pointerdown", onDown);
1248
+ window.removeEventListener("pointermove", onMove);
1249
+ window.removeEventListener("pointerup", onUp);
1250
+ window.removeEventListener("pointercancel", onCancel);
1251
+ bar.removeEventListener("click", onClick, true);
1252
+ bar.removeEventListener("keydown", onKey);
1253
+ bar.removeEventListener("touchmove", onTouchMove);
1254
+ delete bar.dataset.ready;
1255
+ delete bar.dataset.lifted;
1256
+ };
1257
+ }, [options.count]);
1258
+ useEffect4(() => {
1259
+ api.current?.setIndex(options.index);
1260
+ }, [options.index]);
1261
+ }
1262
+
1263
+ // src/components/internal/LensTrack.tsx
1264
+ import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
1265
+ function LensTrack({
1266
+ items,
1267
+ labels,
1268
+ index,
1269
+ onChange,
1270
+ variant,
1271
+ intensity = 5,
1272
+ className,
1273
+ style,
1274
+ "aria-label": ariaLabel
1275
+ }) {
1276
+ const bar = useRef6(null);
1277
+ const glass = useRef6(null);
1278
+ const lens = useRef6(null);
1279
+ const tint = useRef6(null);
1280
+ const row = useRef6(null);
1281
+ const strength = Math.max(1, Math.min(10, intensity)) / 5;
1282
+ useRefraction(glass, { kind: "surface", strength });
1283
+ useRefraction(lens, { kind: "lens", strength, zoom: variant === "tabbar" ? 1.14 : 1.1 }, true, bar);
1284
+ const tabbar = variant === "tabbar";
1285
+ useLensTrack(
1286
+ { bar, glass, lens, tint, row },
1287
+ {
1288
+ count: items.length,
1289
+ index,
1290
+ onSelect: (next) => onChange?.(next),
1291
+ overhang: tabbar ? 8 : 14,
1292
+ spread: tabbar ? 0.22 : 0.3,
1293
+ swell: tabbar ? 10 : 22
457
1294
  }
458
- return vars;
459
- }, [clampedIntensity, tint]);
460
- const freq1 = 0.012 + clampedIntensity * 1e-3;
461
- const freq2 = 0.01 + clampedIntensity * 8e-4;
462
- const scale = clampedIntensity * 2;
463
- if (!mounted) return null;
464
- return /* @__PURE__ */ jsxs5(
1295
+ );
1296
+ return /* @__PURE__ */ jsxs4(
465
1297
  "div",
466
1298
  {
467
- className: `lg-sheet-overlay${visible ? " lg-sheet-overlay--visible" : ""}`,
468
- onTransitionEnd: handleTransitionEnd,
469
- role: "dialog",
470
- "aria-modal": "true",
1299
+ ref: bar,
1300
+ role: "tablist",
1301
+ "aria-label": ariaLabel,
1302
+ className: ["lg-track", `lg-track--${variant}`, className].filter(Boolean).join(" "),
1303
+ "data-liquid-glass": "",
1304
+ style: { ...style, "--lg-count": items.length, "--lg-index": index },
471
1305
  children: [
472
- /* @__PURE__ */ jsx5("div", { className: "lg-sheet-backdrop", onClick: onClose, "aria-hidden": "true" }),
473
- /* @__PURE__ */ jsxs5(
474
- "div",
1306
+ /* @__PURE__ */ jsx5("span", { ref: glass, className: "lg-glass lg-track__glass", "aria-hidden": "true" }),
1307
+ items.map((item, i) => /* @__PURE__ */ jsx5(
1308
+ "button",
475
1309
  {
476
- ref: sheetRef,
477
- className: `lg-root lg-sheet${visible ? " lg-sheet--visible" : ""}`,
478
- "data-liquid-glass": true,
479
- style: glassStyle,
480
- children: [
481
- !isFilterMounted && /* @__PURE__ */ jsx5(
482
- "svg",
483
- {
484
- width: "0",
485
- height: "0",
486
- style: { position: "absolute", pointerEvents: "none" },
487
- "aria-hidden": "true",
488
- children: /* @__PURE__ */ jsx5("defs", { children: /* @__PURE__ */ jsxs5(
489
- "filter",
490
- {
491
- id: `liquid-glass-refract-${clampedIntensity}`,
492
- x: "-10%",
493
- y: "-10%",
494
- width: "120%",
495
- height: "120%",
496
- colorInterpolationFilters: "sRGB",
497
- children: [
498
- /* @__PURE__ */ jsx5(
499
- "feTurbulence",
500
- {
501
- type: "fractalNoise",
502
- baseFrequency: `${freq1} ${freq2}`,
503
- numOctaves: 3,
504
- seed: 42,
505
- result: "noise"
506
- }
507
- ),
508
- /* @__PURE__ */ jsx5(
509
- "feDisplacementMap",
510
- {
511
- in: "SourceGraphic",
512
- in2: "noise",
513
- scale,
514
- xChannelSelector: "R",
515
- yChannelSelector: "G"
516
- }
517
- )
518
- ]
519
- }
520
- ) })
521
- }
522
- ),
523
- /* @__PURE__ */ jsxs5("div", { className: "lg-surface lg-sheet__surface", children: [
524
- /* @__PURE__ */ jsx5("div", { className: "lg-sheet__handle", "aria-hidden": "true", children: /* @__PURE__ */ jsx5("span", { className: "lg-sheet__handle-bar" }) }),
525
- /* @__PURE__ */ jsx5("div", { className: "lg-content lg-sheet__content", children })
526
- ] }),
527
- /* @__PURE__ */ jsx5("div", { className: "lg-backdrop-surface lg-sheet__backdrop-surface", "aria-hidden": "true" }),
528
- /* @__PURE__ */ jsx5("div", { className: "lg-shadow lg-sheet__shadow", "aria-hidden": "true" })
529
- ]
530
- }
531
- )
1310
+ type: "button",
1311
+ role: "tab",
1312
+ "data-lg-item": i,
1313
+ "aria-selected": i === index,
1314
+ "aria-label": labels[i],
1315
+ tabIndex: i === index ? 0 : -1,
1316
+ className: "lg-track__item",
1317
+ children: item
1318
+ },
1319
+ i
1320
+ )),
1321
+ /* @__PURE__ */ jsx5("span", { ref: tint, className: "lg-track__tint", "aria-hidden": "true", children: /* @__PURE__ */ jsx5("span", { ref: row, className: "lg-track__row", children: items.map((item, i) => /* @__PURE__ */ jsx5("span", { className: "lg-track__copy", children: item }, i)) }) }),
1322
+ /* @__PURE__ */ jsx5("span", { ref: lens, className: "lg-glass lg-track__lens", "aria-hidden": "true", children: /* @__PURE__ */ jsx5("span", { className: "lg-track__pill" }) })
532
1323
  ]
533
1324
  }
534
1325
  );
535
- };
536
- GlassSheet.displayName = "GlassSheet";
1326
+ }
537
1327
 
538
1328
  // src/components/GlassNav/GlassNav.tsx
539
- import { useMemo as useMemo5, useRef as useRef2, useState as useState3, useEffect as useEffect2, useLayoutEffect, useCallback as useCallback3 } from "react";
540
- import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
541
- var useIsomorphicLayoutEffect = typeof window === "undefined" ? useEffect2 : useLayoutEffect;
1329
+ import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
542
1330
  var GlassNav = ({
543
1331
  items,
544
1332
  activeIndex = 0,
545
1333
  onChange,
546
- intensity = 5
1334
+ intensity = 5,
1335
+ className,
1336
+ style,
1337
+ "aria-label": ariaLabel = "Tabs"
547
1338
  }) => {
548
- const navRef = useRef2(null);
549
- const itemRefs = useRef2([]);
550
- const isFilterMounted = useGlassFilterMounted();
551
- const clampedIntensity = Math.max(1, Math.min(10, Math.round(intensity)));
552
- const [indicatorStyle, setIndicatorStyle] = useState3({});
553
- const updateIndicator = useCallback3(() => {
554
- const el = itemRefs.current[activeIndex];
555
- const parent = navRef.current;
556
- const surface = parent?.parentElement;
557
- if (!el || !parent || !surface) return;
558
- const surfaceRect = surface.getBoundingClientRect();
559
- const rect = el.getBoundingClientRect();
560
- setIndicatorStyle({
561
- width: `${rect.width}px`,
562
- height: `${rect.height}px`,
563
- transform: `translateX(${rect.left - surfaceRect.left}px)`
564
- });
565
- }, [activeIndex]);
566
- useIsomorphicLayoutEffect(() => {
567
- updateIndicator();
568
- window.addEventListener("resize", updateIndicator);
569
- return () => window.removeEventListener("resize", updateIndicator);
570
- }, [updateIndicator, items.length]);
571
- const glassStyle = useMemo5(() => {
572
- const filterId = `liquid-glass-refract-${clampedIntensity}`;
573
- return {
574
- "--glass-blur": `${clampedIntensity * 2.4}px`,
575
- "--glass-border-width": "1px",
576
- "--glass-refraction-filter": `url(#${filterId})`
577
- };
578
- }, [clampedIntensity]);
579
- const freq1 = 0.012 + clampedIntensity * 1e-3;
580
- const freq2 = 0.01 + clampedIntensity * 8e-4;
581
- const scale = clampedIntensity * 2;
582
- return /* @__PURE__ */ jsxs6("div", { className: "lg-root lg-nav", "data-liquid-glass": true, style: glassStyle, children: [
583
- !isFilterMounted && /* @__PURE__ */ jsx6(
584
- "svg",
1339
+ const hasIcons = items.some((item) => item.icon != null);
1340
+ return /* @__PURE__ */ jsx6(
1341
+ LensTrack,
1342
+ {
1343
+ variant: "tabbar",
1344
+ className: ["lg-nav", hasIcons ? "" : "lg-track--labels-only", className].filter(Boolean).join(" "),
1345
+ style,
1346
+ "aria-label": ariaLabel,
1347
+ intensity,
1348
+ index: activeIndex,
1349
+ onChange,
1350
+ labels: items.map((item) => item.label),
1351
+ items: items.map((item, i) => /* @__PURE__ */ jsxs5(React6.Fragment, { children: [
1352
+ item.icon != null && /* @__PURE__ */ jsx6("span", { className: "lg-nav__icon", children: item.icon }),
1353
+ /* @__PURE__ */ jsx6("span", { className: "lg-nav__label", children: item.label })
1354
+ ] }, i))
1355
+ }
1356
+ );
1357
+ };
1358
+ GlassNav.displayName = "GlassNav";
1359
+
1360
+ // src/components/GlassSegmented/GlassSegmented.tsx
1361
+ import React7 from "react";
1362
+ import { jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
1363
+ var GlassSegmented = ({
1364
+ options,
1365
+ value,
1366
+ onChange,
1367
+ size = "md",
1368
+ intensity = 5,
1369
+ className,
1370
+ style,
1371
+ "aria-label": ariaLabel
1372
+ }) => {
1373
+ const normalized = options.map((option) => typeof option === "string" ? { label: option } : option);
1374
+ return /* @__PURE__ */ jsx7(
1375
+ LensTrack,
1376
+ {
1377
+ variant: "segmented",
1378
+ className: [size === "sm" ? "lg-track--sm" : "", className].filter(Boolean).join(" "),
1379
+ style,
1380
+ "aria-label": ariaLabel,
1381
+ intensity,
1382
+ index: value,
1383
+ onChange,
1384
+ labels: normalized.map((option) => option.label),
1385
+ items: normalized.map((option, i) => /* @__PURE__ */ jsxs6(React7.Fragment, { children: [
1386
+ option.icon,
1387
+ /* @__PURE__ */ jsx7("span", { children: option.label })
1388
+ ] }, i))
1389
+ }
1390
+ );
1391
+ };
1392
+ GlassSegmented.displayName = "GlassSegmented";
1393
+
1394
+ // src/components/GlassSlider/GlassSlider.tsx
1395
+ import React8, { useEffect as useEffect5, useImperativeHandle as useImperativeHandle4, useRef as useRef7 } from "react";
1396
+ import { jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
1397
+ var GlassSlider = React8.forwardRef(
1398
+ ({
1399
+ value = 0,
1400
+ min = 0,
1401
+ max = 100,
1402
+ step: step2 = 1,
1403
+ intensity = 5,
1404
+ tint,
1405
+ shimmer: _shimmer,
1406
+ thickness: _thickness,
1407
+ showThumb = true,
1408
+ icon,
1409
+ label: label2,
1410
+ onChange,
1411
+ className,
1412
+ style,
1413
+ disabled,
1414
+ ...rest
1415
+ }, forwardedRef) => {
1416
+ const rootRef = useRef7(null);
1417
+ const inputRef = useRef7(null);
1418
+ const thumbRef = useRef7(null);
1419
+ const faceRef = useRef7(null);
1420
+ const blockRef = useRef7(null);
1421
+ useImperativeHandle4(forwardedRef, () => inputRef.current);
1422
+ const strength = Math.max(1, Math.min(10, intensity)) / 5;
1423
+ const progress = max > min ? clamp((Number(value) - min) / (max - min), 0, 1) : 0;
1424
+ useRefraction(thumbRef, { kind: "lens", zoom: 1.95, strength, dispersion: 0.6 }, showThumb, rootRef);
1425
+ useRefraction(blockRef, { kind: "surface", strength }, !showThumb);
1426
+ useEffect5(() => {
1427
+ if (!showThumb) return;
1428
+ const input2 = inputRef.current;
1429
+ const thumb = thumbRef.current;
1430
+ const face = faceRef.current;
1431
+ const root = rootRef.current;
1432
+ const v = { lift: 0, stretch: 0 };
1433
+ const paint = () => {
1434
+ const s = 0.655 + 0.345 * v.lift;
1435
+ thumb.style.scale = `${s * (1 + v.stretch)} ${s * (1 - v.stretch * 0.5)}`;
1436
+ face.style.opacity = String(1 - clamp(v.lift, 0, 1) * 0.92);
1437
+ root.style.setProperty("--lg-lift", String(clamp(v.lift, 0, 1)));
1438
+ };
1439
+ const lift = createSpring(0, SPRINGS.lift, (x) => {
1440
+ v.lift = x;
1441
+ paint();
1442
+ });
1443
+ const stretch = createSpring(0, SPRINGS.release, (x) => {
1444
+ v.stretch = x;
1445
+ paint();
1446
+ });
1447
+ paint();
1448
+ let lastX = 0;
1449
+ let lastT = 0;
1450
+ const down = (event) => {
1451
+ if (input2.disabled) return;
1452
+ lastX = event.clientX;
1453
+ lastT = event.timeStamp;
1454
+ lift.tune(SPRINGS.lift);
1455
+ lift.set(1);
1456
+ haptic();
1457
+ };
1458
+ const move = (event) => {
1459
+ if (lift.target !== 1) return;
1460
+ const dt = Math.max(1, event.timeStamp - lastT);
1461
+ const speed = Math.abs(event.clientX - lastX) / dt;
1462
+ lastX = event.clientX;
1463
+ lastT = event.timeStamp;
1464
+ stretch.tune(SPRINGS.drag);
1465
+ stretch.set(clamp(speed * 0.015, 0, 0.035));
1466
+ };
1467
+ const up = () => {
1468
+ if (lift.target === 0) return;
1469
+ lift.tune(SPRINGS.settle);
1470
+ lift.set(0);
1471
+ stretch.tune(SPRINGS.release);
1472
+ stretch.set(0);
1473
+ };
1474
+ input2.addEventListener("pointerdown", down);
1475
+ window.addEventListener("pointermove", move);
1476
+ window.addEventListener("pointerup", up);
1477
+ window.addEventListener("pointercancel", up);
1478
+ input2.addEventListener("blur", up);
1479
+ return () => {
1480
+ lift.stop();
1481
+ stretch.stop();
1482
+ input2.removeEventListener("pointerdown", down);
1483
+ window.removeEventListener("pointermove", move);
1484
+ window.removeEventListener("pointerup", up);
1485
+ window.removeEventListener("pointercancel", up);
1486
+ input2.removeEventListener("blur", up);
1487
+ };
1488
+ }, [showThumb]);
1489
+ useEffect5(() => {
1490
+ if (showThumb) return;
1491
+ const input2 = inputRef.current;
1492
+ const block = blockRef.current;
1493
+ const v = { swell: 0, over: 0 };
1494
+ const paint = () => {
1495
+ const w = block.offsetWidth || 1;
1496
+ const grow = 1 + 10 / Math.max(w, 1) * v.swell;
1497
+ const stretchX = 1 + Math.abs(v.over) / w;
1498
+ block.style.scale = `${grow * stretchX} ${grow * (1 - Math.abs(v.over) / w / 2)}`;
1499
+ block.style.translate = `${v.over / 2}px 0`;
1500
+ };
1501
+ const swell = createSpring(0, SPRINGS.press, (x) => {
1502
+ v.swell = x;
1503
+ paint();
1504
+ });
1505
+ const over = createSpring(0, SPRINGS.release, (x) => {
1506
+ v.over = x;
1507
+ paint();
1508
+ });
1509
+ let active2 = null;
1510
+ const down = (event) => {
1511
+ if (input2.disabled) return;
1512
+ active2 = { id: event.pointerId, box: block.getBoundingClientRect() };
1513
+ swell.tune(SPRINGS.press);
1514
+ swell.set(1);
1515
+ haptic();
1516
+ };
1517
+ const move = (event) => {
1518
+ if (event.pointerId !== active2?.id) return;
1519
+ const { box } = active2;
1520
+ const past = event.clientX < box.left ? event.clientX - box.left : event.clientX > box.right ? event.clientX - box.right : 0;
1521
+ over.tune(SPRINGS.drag);
1522
+ over.set(rubberband(past, 26, 0.6));
1523
+ };
1524
+ const up = (event) => {
1525
+ if (event.pointerId !== active2?.id) return;
1526
+ active2 = null;
1527
+ swell.tune(SPRINGS.release);
1528
+ swell.set(0);
1529
+ over.tune(SPRINGS.release);
1530
+ over.set(0);
1531
+ };
1532
+ input2.addEventListener("pointerdown", down);
1533
+ window.addEventListener("pointermove", move);
1534
+ window.addEventListener("pointerup", up);
1535
+ window.addEventListener("pointercancel", up);
1536
+ return () => {
1537
+ swell.stop();
1538
+ over.stop();
1539
+ input2.removeEventListener("pointerdown", down);
1540
+ window.removeEventListener("pointermove", move);
1541
+ window.removeEventListener("pointerup", up);
1542
+ window.removeEventListener("pointercancel", up);
1543
+ };
1544
+ }, [showThumb]);
1545
+ const input = /* @__PURE__ */ jsx8(
1546
+ "input",
1547
+ {
1548
+ ref: inputRef,
1549
+ type: "range",
1550
+ min,
1551
+ max,
1552
+ step: step2,
1553
+ value,
1554
+ disabled,
1555
+ "aria-label": rest["aria-label"] ?? label2,
1556
+ onChange: (event) => onChange?.(Number(event.currentTarget.value)),
1557
+ onKeyDown: () => rootRef.current?.setAttribute("data-keyboard", ""),
1558
+ onPointerDown: () => rootRef.current?.removeAttribute("data-keyboard"),
1559
+ className: "lg-slider__input",
1560
+ ...rest
1561
+ }
1562
+ );
1563
+ const vars = { "--lg-progress": progress, ...tint ? { "--lg-slider-fill": tint } : {}, ...style };
1564
+ if (!showThumb) {
1565
+ return /* @__PURE__ */ jsxs7(
1566
+ "div",
1567
+ {
1568
+ ref: rootRef,
1569
+ className: ["lg-slider", "lg-slider--block", className].filter(Boolean).join(" "),
1570
+ "data-liquid-glass": "",
1571
+ style: vars,
1572
+ children: [
1573
+ /* @__PURE__ */ jsxs7("div", { ref: blockRef, className: "lg-glass lg-slider__block", children: [
1574
+ /* @__PURE__ */ jsxs7("span", { className: "lg-slider__block-content", "aria-hidden": "true", children: [
1575
+ icon && /* @__PURE__ */ jsx8("span", { className: "lg-slider__icon", children: icon }),
1576
+ label2 && /* @__PURE__ */ jsx8("span", { className: "lg-slider__label", children: label2 }),
1577
+ /* @__PURE__ */ jsx8("span", { className: "lg-slider__value", children: Number(value) })
1578
+ ] }),
1579
+ /* @__PURE__ */ jsx8("span", { className: "lg-slider__block-fill", "aria-hidden": "true", children: /* @__PURE__ */ jsxs7("span", { className: "lg-slider__block-content lg-slider__block-content--lit", children: [
1580
+ icon && /* @__PURE__ */ jsx8("span", { className: "lg-slider__icon", children: icon }),
1581
+ label2 && /* @__PURE__ */ jsx8("span", { className: "lg-slider__label", children: label2 }),
1582
+ /* @__PURE__ */ jsx8("span", { className: "lg-slider__value", children: Number(value) })
1583
+ ] }) })
1584
+ ] }),
1585
+ input
1586
+ ]
1587
+ }
1588
+ );
1589
+ }
1590
+ return /* @__PURE__ */ jsxs7("div", { ref: rootRef, className: ["lg-slider", className].filter(Boolean).join(" "), "data-liquid-glass": "", style: vars, children: [
1591
+ /* @__PURE__ */ jsx8("span", { className: "lg-slider__rail", "aria-hidden": "true", children: /* @__PURE__ */ jsx8("span", { className: "lg-slider__fill" }) }),
1592
+ /* @__PURE__ */ jsx8("span", { className: "lg-slider__thumb-slot", "aria-hidden": "true", children: /* @__PURE__ */ jsx8("span", { ref: thumbRef, className: "lg-glass lg-slider__thumb", children: /* @__PURE__ */ jsx8("span", { ref: faceRef, className: "lg-slider__face" }) }) }),
1593
+ input
1594
+ ] });
1595
+ }
1596
+ );
1597
+ GlassSlider.displayName = "GlassSlider";
1598
+
1599
+ // src/components/GlassSwitch/GlassSwitch.tsx
1600
+ import React9, { useEffect as useEffect6, useImperativeHandle as useImperativeHandle5, useRef as useRef8, useState as useState3 } from "react";
1601
+ import { jsx as jsx9, jsxs as jsxs8 } from "react/jsx-runtime";
1602
+ var REST = 0.655;
1603
+ var TRAVEL = 22;
1604
+ var GlassSwitch = React9.forwardRef(
1605
+ ({ checked: checkedProp, defaultChecked = false, onChange, tint, intensity = 5, className, style, disabled, ...rest }, forwardedRef) => {
1606
+ const ref = useRef8(null);
1607
+ const thumbRef = useRef8(null);
1608
+ const fillRef = useRef8(null);
1609
+ const faceRef = useRef8(null);
1610
+ useImperativeHandle5(forwardedRef, () => ref.current);
1611
+ const [inner, setInner] = useState3(defaultChecked);
1612
+ const controlled = checkedProp !== void 0;
1613
+ const checked = controlled ? checkedProp : inner;
1614
+ const latest = useRef8({ checked, set: (_) => {
1615
+ }, disabled });
1616
+ latest.current = {
1617
+ checked,
1618
+ disabled,
1619
+ set: (next) => {
1620
+ if (!controlled) setInner(next);
1621
+ onChange?.(next);
1622
+ }
1623
+ };
1624
+ const sync = useRef8(null);
1625
+ useRefraction(thumbRef, { kind: "lens", zoom: 1.45, strength: Math.max(1, Math.min(10, intensity)) / 5 }, true, ref);
1626
+ useEffect6(() => {
1627
+ const el2 = ref.current;
1628
+ const thumb = thumbRef.current;
1629
+ const fill = fillRef.current;
1630
+ const face = faceRef.current;
1631
+ const v = { x: checked ? 1 : 0, lift: 0, stretch: 0 };
1632
+ const paint = () => {
1633
+ const s = REST + (1 - REST) * v.lift;
1634
+ const sx = s * (1 + v.stretch);
1635
+ const sy = s * (1 - v.stretch * 0.5);
1636
+ thumb.style.transform = `translate(${v.x * TRAVEL}px, -50%) scale(${sx}, ${sy})`;
1637
+ const l = clamp(v.lift, 0, 1);
1638
+ face.style.opacity = String(1 - l * 0.92);
1639
+ el2.style.setProperty("--lg-lift", String(l));
1640
+ };
1641
+ const position = createSpring(v.x, SPRINGS.snap, (value, velocity) => {
1642
+ v.x = value;
1643
+ v.stretch = clamp(Math.abs(velocity) / 40, 0, 0.14);
1644
+ paint();
1645
+ });
1646
+ const lift = createSpring(0, SPRINGS.lift, (value) => {
1647
+ v.lift = value;
1648
+ paint();
1649
+ });
1650
+ const color = createSpring(checked ? 1 : 0, SPRINGS.fade, (value) => {
1651
+ fill.style.opacity = String(clamp(value, 0, 1));
1652
+ });
1653
+ fill.style.opacity = checked ? "1" : "0";
1654
+ paint();
1655
+ sync.current = (value) => {
1656
+ position.tune(SPRINGS.snap);
1657
+ position.set(value ? 1 : 0);
1658
+ color.set(value ? 1 : 0);
1659
+ };
1660
+ let gesture = null;
1661
+ let dropTimer = 0;
1662
+ let ignoreClick = false;
1663
+ const drop = (delay) => {
1664
+ clearTimeout(dropTimer);
1665
+ dropTimer = window.setTimeout(() => {
1666
+ lift.tune(SPRINGS.settle);
1667
+ lift.set(0);
1668
+ }, delay);
1669
+ };
1670
+ const down = (event) => {
1671
+ if (!event.isPrimary || event.button !== 0 || latest.current.disabled) return;
1672
+ clearTimeout(dropTimer);
1673
+ gesture = { id: event.pointerId, x: event.clientX, from: latest.current.checked ? 1 : 0, moved: false, at: performance.now() };
1674
+ try {
1675
+ el2.setPointerCapture(event.pointerId);
1676
+ } catch {
1677
+ }
1678
+ lift.tune(SPRINGS.lift);
1679
+ lift.set(1);
1680
+ haptic();
1681
+ };
1682
+ const move = (event) => {
1683
+ if (event.pointerId !== gesture?.id) return;
1684
+ const dx = event.clientX - gesture.x;
1685
+ if (!gesture.moved && Math.abs(dx) < 3) return;
1686
+ gesture.moved = true;
1687
+ const raw = gesture.from + dx / TRAVEL;
1688
+ const over = raw < 0 ? rubberband(raw * TRAVEL, TRAVEL, 0.6) / TRAVEL : raw > 1 ? 1 + rubberband((raw - 1) * TRAVEL, TRAVEL, 0.6) / TRAVEL : raw;
1689
+ position.tune(SPRINGS.drag);
1690
+ position.set(over);
1691
+ const on = raw > 0.5;
1692
+ if (color.target === 1 !== on) haptic();
1693
+ color.set(on ? 1 : 0);
1694
+ };
1695
+ const up = (event) => {
1696
+ if (event.pointerId !== gesture?.id) return;
1697
+ const { from, x, moved, at } = gesture;
1698
+ gesture = null;
1699
+ ignoreClick = true;
1700
+ const next = moved ? from + (event.clientX - x) / TRAVEL > 0.5 : !latest.current.checked;
1701
+ position.tune(SPRINGS.snap);
1702
+ position.set(next ? 1 : 0);
1703
+ color.set(next ? 1 : 0);
1704
+ if (next !== latest.current.checked) latest.current.set(next);
1705
+ drop(moved ? 0 : Math.max(0, 200 - (performance.now() - at)));
1706
+ };
1707
+ const cancel = (event) => {
1708
+ if (event.pointerId !== gesture?.id) return;
1709
+ gesture = null;
1710
+ sync.current?.(latest.current.checked);
1711
+ drop(0);
1712
+ };
1713
+ const click = (event) => {
1714
+ if (ignoreClick) {
1715
+ ignoreClick = false;
1716
+ return;
1717
+ }
1718
+ if (latest.current.disabled) return;
1719
+ event.preventDefault();
1720
+ const next = !latest.current.checked;
1721
+ lift.set(1);
1722
+ drop(220);
1723
+ latest.current.set(next);
1724
+ sync.current?.(next);
1725
+ };
1726
+ el2.addEventListener("pointerdown", down);
1727
+ el2.addEventListener("pointermove", move);
1728
+ el2.addEventListener("pointerup", up);
1729
+ el2.addEventListener("pointercancel", cancel);
1730
+ el2.addEventListener("click", click);
1731
+ return () => {
1732
+ clearTimeout(dropTimer);
1733
+ [position, lift, color].forEach((s) => s.stop());
1734
+ el2.removeEventListener("pointerdown", down);
1735
+ el2.removeEventListener("pointermove", move);
1736
+ el2.removeEventListener("pointerup", up);
1737
+ el2.removeEventListener("pointercancel", cancel);
1738
+ el2.removeEventListener("click", click);
1739
+ };
1740
+ }, []);
1741
+ useEffect6(() => {
1742
+ sync.current?.(checked);
1743
+ }, [checked]);
1744
+ return /* @__PURE__ */ jsxs8(
1745
+ "button",
585
1746
  {
586
- width: "0",
587
- height: "0",
588
- style: { position: "absolute", pointerEvents: "none" },
589
- "aria-hidden": "true",
590
- children: /* @__PURE__ */ jsx6("defs", { children: /* @__PURE__ */ jsxs6(
1747
+ ref,
1748
+ type: "button",
1749
+ role: "switch",
1750
+ "aria-checked": checked,
1751
+ disabled,
1752
+ className: ["lg-switch", className].filter(Boolean).join(" "),
1753
+ "data-liquid-glass": "",
1754
+ style: tint ? { "--lg-switch-on": tint, ...style } : style,
1755
+ ...rest,
1756
+ children: [
1757
+ /* @__PURE__ */ jsx9("span", { ref: fillRef, className: "lg-switch__fill", "aria-hidden": "true" }),
1758
+ /* @__PURE__ */ jsx9("span", { ref: thumbRef, className: "lg-glass lg-switch__thumb", "aria-hidden": "true", children: /* @__PURE__ */ jsx9("span", { ref: faceRef, className: "lg-switch__face" }) })
1759
+ ]
1760
+ }
1761
+ );
1762
+ }
1763
+ );
1764
+ GlassSwitch.displayName = "GlassSwitch";
1765
+
1766
+ // src/filters/LiquidGlassFilter.tsx
1767
+ import { createContext, useContext } from "react";
1768
+ import { jsx as jsx10, jsxs as jsxs9 } from "react/jsx-runtime";
1769
+ var GlassFilterContext = createContext(false);
1770
+ function LiquidGlassFilter({ children }) {
1771
+ return /* @__PURE__ */ jsxs9(GlassFilterContext.Provider, { value: true, children: [
1772
+ /* @__PURE__ */ jsx10(GlassFilterSVG, {}),
1773
+ children
1774
+ ] });
1775
+ }
1776
+ function GlassFilterSVG() {
1777
+ return /* @__PURE__ */ jsx10(
1778
+ "svg",
1779
+ {
1780
+ width: "0",
1781
+ height: "0",
1782
+ style: { position: "absolute", pointerEvents: "none" },
1783
+ "aria-hidden": "true",
1784
+ children: /* @__PURE__ */ jsx10("defs", { children: Array.from({ length: 10 }, (_, i) => {
1785
+ const level = i + 1;
1786
+ const scale = level * 2;
1787
+ const freq1 = 0.012 + level * 1e-3;
1788
+ const freq2 = 0.01 + level * 8e-4;
1789
+ return /* @__PURE__ */ jsxs9(
591
1790
  "filter",
592
1791
  {
593
- id: `liquid-glass-refract-${clampedIntensity}`,
1792
+ id: `liquid-glass-refract-${level}`,
594
1793
  x: "-10%",
595
1794
  y: "-10%",
596
1795
  width: "120%",
597
1796
  height: "120%",
598
1797
  colorInterpolationFilters: "sRGB",
599
1798
  children: [
600
- /* @__PURE__ */ jsx6(
1799
+ /* @__PURE__ */ jsx10(
601
1800
  "feTurbulence",
602
1801
  {
603
1802
  type: "fractalNoise",
@@ -607,7 +1806,7 @@ var GlassNav = ({
607
1806
  result: "noise"
608
1807
  }
609
1808
  ),
610
- /* @__PURE__ */ jsx6(
1809
+ /* @__PURE__ */ jsx10(
611
1810
  "feDisplacementMap",
612
1811
  {
613
1812
  in: "SourceGraphic",
@@ -618,169 +1817,16 @@ var GlassNav = ({
618
1817
  }
619
1818
  )
620
1819
  ]
621
- }
622
- ) })
623
- }
624
- ),
625
- /* @__PURE__ */ jsxs6("div", { className: "lg-surface lg-nav__surface", children: [
626
- /* @__PURE__ */ jsx6("div", { className: "lg-nav__indicator", style: indicatorStyle, "aria-hidden": "true" }),
627
- /* @__PURE__ */ jsx6("nav", { ref: navRef, className: "lg-content lg-nav__content", role: "tablist", children: items.map((item, i) => /* @__PURE__ */ jsxs6(
628
- "button",
629
- {
630
- ref: (el) => {
631
- itemRefs.current[i] = el;
632
1820
  },
633
- role: "tab",
634
- "aria-selected": i === activeIndex,
635
- className: `lg-nav__item${i === activeIndex ? " lg-nav__item--active" : ""}`,
636
- onClick: () => onChange?.(i),
637
- type: "button",
638
- children: [
639
- item.icon && /* @__PURE__ */ jsx6("span", { className: "lg-nav__icon", children: item.icon }),
640
- /* @__PURE__ */ jsx6("span", { className: "lg-nav__label", children: item.label })
641
- ]
642
- },
643
- i
644
- )) })
645
- ] }),
646
- /* @__PURE__ */ jsx6("div", { className: "lg-backdrop-surface lg-nav__backdrop-surface", "aria-hidden": "true" }),
647
- /* @__PURE__ */ jsx6("div", { className: "lg-shadow", "aria-hidden": "true" })
648
- ] });
649
- };
650
- GlassNav.displayName = "GlassNav";
651
-
652
- // src/components/GlassSlider/GlassSlider.tsx
653
- import React7, { useMemo as useMemo6 } from "react";
654
- import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
655
- var GlassSlider = React7.forwardRef(
656
- ({
657
- intensity = 5,
658
- tint,
659
- shimmer = true,
660
- thickness = 1,
661
- showThumb = true,
662
- icon,
663
- label,
664
- value = 0,
665
- min = 0,
666
- max = 100,
667
- onChange,
668
- className,
669
- style,
670
- ...rest
671
- }, ref) => {
672
- const isFilterMounted = useGlassFilterMounted();
673
- const clampedIntensity = Math.max(1, Math.min(10, Math.round(intensity)));
674
- const numValue = Number(value);
675
- const numMin = Number(min);
676
- const numMax = Number(max);
677
- const percentage = numMax > numMin ? (numValue - numMin) / (numMax - numMin) * 100 : 0;
678
- const ratio = numMax > numMin ? (numValue - numMin) / (numMax - numMin) : 0;
679
- const glassStyle = useMemo6(() => {
680
- const filterId = `liquid-glass-refract-${clampedIntensity}`;
681
- const vars = {
682
- "--glass-blur": `${clampedIntensity * 2.4}px`,
683
- "--glass-border-width": `${thickness}px`,
684
- "--glass-refraction-filter": `url(#${filterId})`,
685
- "--slider-percentage": `${percentage}%`,
686
- "--slider-ratio": ratio
687
- };
688
- if (tint) {
689
- vars["--glass-tint"] = tint;
690
- }
691
- return vars;
692
- }, [clampedIntensity, tint, thickness, percentage, ratio]);
693
- const rootClasses = [
694
- "lg-root",
695
- "lg-slider",
696
- shimmer ? "lg-slider--shimmer" : "",
697
- showThumb ? "lg-slider--with-thumb" : "lg-slider--no-thumb",
698
- className ?? ""
699
- ].filter(Boolean).join(" ");
700
- const handleChange = (e) => {
701
- if (onChange) {
702
- onChange(Number(e.target.value));
703
- }
704
- };
705
- const freq1 = 0.012 + clampedIntensity * 1e-3;
706
- const freq2 = 0.01 + clampedIntensity * 8e-4;
707
- const scale = clampedIntensity * 2;
708
- return /* @__PURE__ */ jsxs7("div", { className: rootClasses, "data-liquid-glass": true, style: { ...glassStyle, ...style }, children: [
709
- !isFilterMounted && /* @__PURE__ */ jsx7(
710
- "svg",
711
- {
712
- width: "0",
713
- height: "0",
714
- style: { position: "absolute", pointerEvents: "none" },
715
- "aria-hidden": "true",
716
- children: /* @__PURE__ */ jsx7("defs", { children: /* @__PURE__ */ jsxs7(
717
- "filter",
718
- {
719
- id: `liquid-glass-refract-${clampedIntensity}`,
720
- x: "-10%",
721
- y: "-10%",
722
- width: "120%",
723
- height: "120%",
724
- colorInterpolationFilters: "sRGB",
725
- children: [
726
- /* @__PURE__ */ jsx7(
727
- "feTurbulence",
728
- {
729
- type: "fractalNoise",
730
- baseFrequency: `${freq1} ${freq2}`,
731
- numOctaves: 3,
732
- seed: 42,
733
- result: "noise"
734
- }
735
- ),
736
- /* @__PURE__ */ jsx7(
737
- "feDisplacementMap",
738
- {
739
- in: "SourceGraphic",
740
- in2: "noise",
741
- scale,
742
- xChannelSelector: "R",
743
- yChannelSelector: "G"
744
- }
745
- )
746
- ]
747
- }
748
- ) })
749
- }
750
- ),
751
- /* @__PURE__ */ jsxs7("div", { className: "lg-slider-track", children: [
752
- /* @__PURE__ */ jsx7("div", { className: "lg-backdrop-surface", "aria-hidden": "true" }),
753
- /* @__PURE__ */ jsx7("div", { style: { position: "absolute", inset: 0, overflow: "hidden", borderRadius: "inherit", zIndex: 2, pointerEvents: "none" }, children: /* @__PURE__ */ jsx7("div", { className: "lg-slider-fill", "aria-hidden": "true" }) }),
754
- /* @__PURE__ */ jsx7("div", { className: "lg-shadow", "aria-hidden": "true" }),
755
- /* @__PURE__ */ jsxs7("div", { className: "lg-slider-content", children: [
756
- /* @__PURE__ */ jsxs7("div", { style: { display: "flex", alignItems: "center", gap: "8px" }, children: [
757
- icon && /* @__PURE__ */ jsx7("span", { className: "lg-slider-icon", children: icon }),
758
- label && /* @__PURE__ */ jsx7("span", { className: "lg-slider-label", children: label })
759
- ] }),
760
- /* @__PURE__ */ jsx7("span", { className: "lg-slider-value-text", children: numValue })
761
- ] }),
762
- showThumb && /* @__PURE__ */ jsx7("div", { className: "lg-slider-thumb", "aria-hidden": "true" }),
763
- /* @__PURE__ */ jsx7(
764
- "input",
765
- {
766
- type: "range",
767
- ref,
768
- min,
769
- max,
770
- value,
771
- onChange: handleChange,
772
- className: "lg-slider-input",
773
- ...rest
774
- }
775
- )
776
- ] })
777
- ] });
778
- }
779
- );
780
- GlassSlider.displayName = "GlassSlider";
1821
+ level
1822
+ );
1823
+ }) })
1824
+ }
1825
+ );
1826
+ }
781
1827
 
782
1828
  // src/hooks/useGlassEffect.ts
783
- import { useMemo as useMemo7 } from "react";
1829
+ import { useMemo } from "react";
784
1830
  function parseTintColor(tint) {
785
1831
  const defaults = { h: 0, s: 0, l: 100, a: 0.1 };
786
1832
  if (!tint) return defaults;
@@ -832,7 +1878,7 @@ function useGlassEffect(options = {}) {
832
1878
  thickness,
833
1879
  blur
834
1880
  } = options;
835
- return useMemo7(() => {
1881
+ return useMemo(() => {
836
1882
  const clampedIntensity = Math.max(1, Math.min(10, Math.round(intensity)));
837
1883
  const filterId = `liquid-glass-refract-${clampedIntensity}`;
838
1884
  const style = {
@@ -857,21 +1903,21 @@ function useGlassEffect(options = {}) {
857
1903
  }
858
1904
 
859
1905
  // src/hooks/useGlassAnimation.ts
860
- import { useCallback as useCallback4, useState as useState4 } from "react";
1906
+ import { useCallback, useState as useState4 } from "react";
861
1907
  function useGlassAnimation() {
862
1908
  const [isHovered, setIsHovered] = useState4(false);
863
1909
  const [isPressed, setIsPressed] = useState4(false);
864
1910
  const [isFocused, setIsFocused] = useState4(false);
865
1911
  const handlers = {
866
- onPointerEnter: useCallback4(() => setIsHovered(true), []),
867
- onPointerLeave: useCallback4(() => {
1912
+ onPointerEnter: useCallback(() => setIsHovered(true), []),
1913
+ onPointerLeave: useCallback(() => {
868
1914
  setIsHovered(false);
869
1915
  setIsPressed(false);
870
1916
  }, []),
871
- onPointerDown: useCallback4(() => setIsPressed(true), []),
872
- onPointerUp: useCallback4(() => setIsPressed(false), []),
873
- onFocus: useCallback4(() => setIsFocused(true), []),
874
- onBlur: useCallback4(() => setIsFocused(false), [])
1917
+ onPointerDown: useCallback(() => setIsPressed(true), []),
1918
+ onPointerUp: useCallback(() => setIsPressed(false), []),
1919
+ onFocus: useCallback(() => setIsFocused(true), []),
1920
+ onBlur: useCallback(() => setIsFocused(false), [])
875
1921
  };
876
1922
  return { isHovered, isPressed, isFocused, handlers };
877
1923
  }
@@ -880,10 +1926,19 @@ export {
880
1926
  GlassCard,
881
1927
  GlassInput,
882
1928
  GlassNav,
1929
+ GlassSegmented,
883
1930
  GlassSheet,
884
1931
  GlassSlider,
1932
+ GlassSwitch,
885
1933
  LiquidGlassFilter,
1934
+ SPRINGS,
1935
+ canRefractBackdrop,
1936
+ createSpring,
1937
+ haptic,
1938
+ springFrom,
886
1939
  useGlassAnimation,
887
- useGlassEffect
1940
+ useGlassEffect,
1941
+ usePress,
1942
+ useRefraction
888
1943
  };
889
1944
  //# sourceMappingURL=index.mjs.map