snell-glass 0.1.1 → 0.1.3
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/AGENTS.md +5 -0
- package/README.md +3 -1
- package/dist/{chunk-ELZYSC4V.js → chunk-72ENH7CW.js} +84 -4
- package/dist/chunk-72ENH7CW.js.map +1 -0
- package/dist/index.cjs +83 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/react.cjs +83 -3
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-ELZYSC4V.js.map +0 -1
package/AGENTS.md
CHANGED
|
@@ -27,7 +27,12 @@ Before you finish, look at what sits behind every glass you add, and handle each
|
|
|
27
27
|
| DOM in 3D perspective | not drawn: render it to a `<canvas>` |
|
|
28
28
|
| content that must NOT show through | add `data-glass-ignore` (skips the element and its subtree) |
|
|
29
29
|
|
|
30
|
+
Tagging a whole article with `data-glass-text` is fine: images and `data-glass-box` fills nested inside it are
|
|
31
|
+
still drawn, under its text.
|
|
32
|
+
|
|
30
33
|
A glass never captures its own element or children (they sit on top of it), so tagging them only matters to other glasses.
|
|
34
|
+
Another glass underneath shows as a frosted stand-in of its shape (light or dark by its `tone`), not refracted; tag
|
|
35
|
+
its label with `data-glass-text` if the words should show through too.
|
|
31
36
|
|
|
32
37
|
## Install and use
|
|
33
38
|
|
package/README.md
CHANGED
|
@@ -77,6 +77,7 @@ be.
|
|
|
77
77
|
| `<video>` | Automatically, live | Same-origin, or CORS as for images |
|
|
78
78
|
| An element's background colour or `linear-gradient()` | When tagged | Add `data-glass-box` to that element |
|
|
79
79
|
| Text | When tagged | Add `data-glass-text` to the element (or a container) holding it |
|
|
80
|
+
| Another glass underneath | Automatically | Drawn as a frosted stand-in of its shape; tag its label to show the words |
|
|
80
81
|
| `background-image: url(…)`, radial/conic gradients | No | Use an `<img>` / `<canvas>`, or a [custom painter](#custom-painters) |
|
|
81
82
|
| Borders, `box-shadow`, SVG, icon fonts | No | A custom painter, or accept that they don't show |
|
|
82
83
|
| CSS filters other than `brightness()`, blend modes | Ignored | Drawn unfiltered |
|
|
@@ -103,7 +104,8 @@ Only content inside the `backdrop` option (default `document.body`) is considere
|
|
|
103
104
|
```
|
|
104
105
|
|
|
105
106
|
`data-glass-text` on a container draws all the text inside it, so tag a section's heading block once rather than
|
|
106
|
-
every line.
|
|
107
|
+
every line. Images, canvases, videos and `data-glass-box` fills inside it (a code block, a callout) are drawn
|
|
108
|
+
under that text. Glass over a big, mostly-plain page costs little; the price is paid per tagged element that sits
|
|
107
109
|
behind a glass.
|
|
108
110
|
|
|
109
111
|
### Troubleshooting
|
|
@@ -297,6 +297,8 @@ var paintText = (ctx, host, view) => {
|
|
|
297
297
|
ctx.restore();
|
|
298
298
|
}
|
|
299
299
|
};
|
|
300
|
+
var glassTones = /* @__PURE__ */ new WeakMap();
|
|
301
|
+
var registerGlassTone = (element, tone) => glassTones.set(element, tone);
|
|
300
302
|
var scene = {
|
|
301
303
|
entries: [],
|
|
302
304
|
bg: "#ffffff",
|
|
@@ -313,10 +315,41 @@ var rebuildScene = () => {
|
|
|
313
315
|
const selector = [BASE_SELECTOR, ...[...painters].map((p) => p.selector)].join(", ");
|
|
314
316
|
const behind = [];
|
|
315
317
|
const front = [];
|
|
318
|
+
const textEntries = /* @__PURE__ */ new Map();
|
|
316
319
|
document.querySelectorAll(selector).forEach((node) => {
|
|
317
320
|
if (node.closest("[data-glass-ignore]")) return;
|
|
318
|
-
if (node instanceof HTMLCanvasElement && node.hasAttribute("data-snell-surface"))
|
|
319
|
-
|
|
321
|
+
if (node instanceof HTMLCanvasElement && node.hasAttribute("data-snell-surface")) {
|
|
322
|
+
const host = node.parentElement;
|
|
323
|
+
if (host && !host.closest("[data-glass-ignore]")) {
|
|
324
|
+
const isBehind2 = stackSide(host) ?? false;
|
|
325
|
+
const list = isBehind2 ? behind : front;
|
|
326
|
+
const first = list.findIndex((e) => host.contains(e.node));
|
|
327
|
+
const standIn = { node: host, kind: "glass", clips: clipsFrom(host.parentElement), behind: isBehind2 };
|
|
328
|
+
if (first < 0) list.push(standIn);
|
|
329
|
+
else list.splice(first, 0, standIn);
|
|
330
|
+
}
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
const textHost = node.parentElement?.closest("[data-glass-text]");
|
|
334
|
+
if (textHost) {
|
|
335
|
+
const host = textEntries.get(textHost);
|
|
336
|
+
if (!host) return;
|
|
337
|
+
const nested = [];
|
|
338
|
+
const clips2 = clipsFrom(node.parentElement);
|
|
339
|
+
const isBehind2 = host.entry.behind;
|
|
340
|
+
if (node instanceof HTMLImageElement) nested.push({ node, kind: "image", clips: clips2, behind: isBehind2 });
|
|
341
|
+
else if (node instanceof HTMLCanvasElement) nested.push({ node, kind: "canvas", clips: clips2, behind: isBehind2 });
|
|
342
|
+
else if (node instanceof HTMLVideoElement) nested.push({ node, kind: "video", clips: clips2, behind: isBehind2 });
|
|
343
|
+
else if (node.hasAttribute("data-glass-box")) {
|
|
344
|
+
const box = boxStyleOf(node);
|
|
345
|
+
if (box) nested.push({ node, kind: "box", clips: clips2, behind: isBehind2, box });
|
|
346
|
+
}
|
|
347
|
+
for (const item of nested) {
|
|
348
|
+
if (item.kind !== "box") item.radius = parseFloat(getComputedStyle(node).borderTopLeftRadius) || 0;
|
|
349
|
+
host.list.splice(host.list.indexOf(host.entry), 0, item);
|
|
350
|
+
}
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
320
353
|
let entry = null;
|
|
321
354
|
const clips = clipsFrom(node.parentElement);
|
|
322
355
|
const isBehind = stackSide(node) ?? false;
|
|
@@ -335,7 +368,11 @@ var rebuildScene = () => {
|
|
|
335
368
|
if (entry && (entry.kind === "image" || entry.kind === "canvas" || entry.kind === "video")) {
|
|
336
369
|
entry.radius = parseFloat(getComputedStyle(node).borderTopLeftRadius) || 0;
|
|
337
370
|
}
|
|
338
|
-
if (entry)
|
|
371
|
+
if (entry) {
|
|
372
|
+
const list = isBehind ? behind : front;
|
|
373
|
+
list.push(entry);
|
|
374
|
+
if (entry.kind === "text") textEntries.set(node, { list, entry });
|
|
375
|
+
}
|
|
339
376
|
});
|
|
340
377
|
scene.entries = behind.concat(front);
|
|
341
378
|
const bg = getComputedStyle(document.body).backgroundColor;
|
|
@@ -412,6 +449,11 @@ var collectBackdrop = (glass, scope, background, left, top, width, height) => {
|
|
|
412
449
|
if (entry.kind === "video" && node.readyState < 2) return;
|
|
413
450
|
const chain = chainOf(node);
|
|
414
451
|
if (chain.opacity <= 0.01 || chain.warp) return;
|
|
452
|
+
if (entry.kind === "glass") {
|
|
453
|
+
const ownZ = chainOf(glass).z;
|
|
454
|
+
const later = glass.compareDocumentPosition(node) & Node.DOCUMENT_POSITION_FOLLOWING;
|
|
455
|
+
if (chain.z > ownZ || chain.z === ownZ && later && !node.contains(glass)) return;
|
|
456
|
+
}
|
|
415
457
|
items.push({ entry, rect, chain, order });
|
|
416
458
|
});
|
|
417
459
|
items.sort((a, b) => Number(b.entry.behind) - Number(a.entry.behind) || a.chain.z - b.chain.z || a.order - b.order);
|
|
@@ -425,6 +467,7 @@ var collectBackdrop = (glass, scope, background, left, top, width, height) => {
|
|
|
425
467
|
parts.push(Math.round(chain.opacity * 1e3), Math.round(chain.brightness * 1e3), chain.z);
|
|
426
468
|
if (entry.kind === "image") parts.push(node.currentSrc || node.src);
|
|
427
469
|
if (entry.kind === "box") parts.push(entry.box.key);
|
|
470
|
+
if (entry.kind === "glass") parts.push(glassTones.get(node)?.() ?? "light", getComputedStyle(node).borderTopLeftRadius);
|
|
428
471
|
if (entry.kind === "text") parts.push(node.textContent?.length ?? 0);
|
|
429
472
|
if ((entry.kind === "text" || entry.kind === "box") && animatingInside(node)) parts.push("anim", frameStamp());
|
|
430
473
|
if (entry.painter?.signature) parts.push(entry.painter.signature(node));
|
|
@@ -446,6 +489,40 @@ var clipOwnRadius = (ctx, node, frame, at, radius) => {
|
|
|
446
489
|
roundRect(ctx, at.x, at.y, at.w, at.h, radiusIn(node, frame, radius));
|
|
447
490
|
ctx.clip();
|
|
448
491
|
};
|
|
492
|
+
var paintGlassStandIn = (ctx, node, rect) => {
|
|
493
|
+
const frame = frameOf(node, rect);
|
|
494
|
+
const at = inFrame(ctx, frame);
|
|
495
|
+
const css = getComputedStyle(node).borderTopLeftRadius.split(" ")[0] ?? "";
|
|
496
|
+
const w = node.offsetWidth || rect.width;
|
|
497
|
+
const h = node.offsetHeight || rect.height;
|
|
498
|
+
const cssPx = css.endsWith("%") ? parseFloat(css) / 100 * Math.min(w, h) : parseFloat(css) || 0;
|
|
499
|
+
const r = radiusIn(node, frame, cssPx);
|
|
500
|
+
const dark = glassTones.get(node)?.() === "dark";
|
|
501
|
+
const shape = () => {
|
|
502
|
+
ctx.beginPath();
|
|
503
|
+
roundRect(ctx, at.x, at.y, at.w, at.h, r);
|
|
504
|
+
};
|
|
505
|
+
ctx.save();
|
|
506
|
+
shape();
|
|
507
|
+
ctx.shadowColor = dark ? "rgba(0, 0, 0, 0.35)" : "rgba(20, 20, 20, 0.16)";
|
|
508
|
+
ctx.shadowBlur = 18;
|
|
509
|
+
ctx.shadowOffsetY = 6;
|
|
510
|
+
const fill = ctx.createLinearGradient(0, at.y, 0, at.y + at.h);
|
|
511
|
+
if (dark) {
|
|
512
|
+
fill.addColorStop(0, "rgba(58, 58, 62, 0.82)");
|
|
513
|
+
fill.addColorStop(1, "rgba(28, 28, 32, 0.88)");
|
|
514
|
+
} else {
|
|
515
|
+
fill.addColorStop(0, "rgba(255, 255, 255, 0.86)");
|
|
516
|
+
fill.addColorStop(1, "rgba(246, 246, 248, 0.74)");
|
|
517
|
+
}
|
|
518
|
+
ctx.fillStyle = fill;
|
|
519
|
+
ctx.fill();
|
|
520
|
+
ctx.restore();
|
|
521
|
+
shape();
|
|
522
|
+
ctx.lineWidth = 1;
|
|
523
|
+
ctx.strokeStyle = dark ? "rgba(255, 255, 255, 0.16)" : "rgba(255, 255, 255, 0.95)";
|
|
524
|
+
ctx.stroke();
|
|
525
|
+
};
|
|
449
526
|
var paintBackdrop = (ctx, backdrop, scaleX, scaleY) => {
|
|
450
527
|
const { left, top, width, height } = backdrop.view;
|
|
451
528
|
ctx.setTransform(scaleX, 0, 0, scaleY, -left * scaleX, -top * scaleY);
|
|
@@ -476,6 +553,8 @@ var paintBackdrop = (ctx, backdrop, scaleX, scaleY) => {
|
|
|
476
553
|
ctx.fillStyle = gradient;
|
|
477
554
|
ctx.fill();
|
|
478
555
|
}
|
|
556
|
+
} else if (kind === "glass") {
|
|
557
|
+
paintGlassStandIn(ctx, node, rect);
|
|
479
558
|
} else if (kind === "text") {
|
|
480
559
|
paintText(ctx, node, view);
|
|
481
560
|
} else if (kind === "canvas") {
|
|
@@ -746,6 +825,7 @@ var createGlass = (element, initial = {}) => {
|
|
|
746
825
|
canvas.style.cssText = "position:absolute;left:0;top:0;width:100%;height:100%;pointer-events:none;z-index:-1;border-radius:inherit;";
|
|
747
826
|
element.prepend(canvas);
|
|
748
827
|
const tone = () => options.tone ?? DEFAULTS.tone;
|
|
828
|
+
registerGlassTone(element, tone);
|
|
749
829
|
const applyFallback = (on) => {
|
|
750
830
|
const t = tone();
|
|
751
831
|
element.style.background = on ? FALLBACK[t].background : "transparent";
|
|
@@ -1091,4 +1171,4 @@ export {
|
|
|
1091
1171
|
invalidateBackdrop,
|
|
1092
1172
|
createGlass
|
|
1093
1173
|
};
|
|
1094
|
-
//# sourceMappingURL=chunk-
|
|
1174
|
+
//# sourceMappingURL=chunk-72ENH7CW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/backdrop.ts","../src/shader.ts","../src/glass.ts"],"sourcesContent":["/**\n * The backdrop: WebGL can't read what the browser composited under an element,\n * so everything behind a glass is repainted into a 2D canvas the shader samples.\n *\n * Sources, all inside the backdrop root (document.body by default):\n * - <img> (same-origin, or crossorigin=\"anonymous\" from a host that allows it)\n * - <canvas> and <video> (live: re-captured on a clock)\n * - [data-glass-box]: an element's background color, linear gradients and radius\n * - [data-glass-text]: the text inside, drawn word by word where the browser laid it out\n * - anything a registered painter claims (see registerPainter)\n *\n * Elements with [data-glass-ignore] (and everything inside them) are skipped.\n */\n\n// ---------------------------------------------------------------- painters\n\nexport type PainterContext = {\n /** Draw in page (CSS px, viewport) coordinates; the transform is already set. */\n ctx: CanvasRenderingContext2D;\n /** The element the painter claimed. */\n element: HTMLElement;\n /** Its border box on screen. */\n rect: DOMRect;\n};\n\nexport type Painter = {\n /** CSS selector for the elements this painter draws. */\n selector: string;\n /** Draws one element into the capture. */\n paint: (context: PainterContext) => void;\n /**\n * What the drawing depends on besides the element's position and size. The\n * capture is redrawn when it changes. Omit if only position matters.\n */\n signature?: (element: HTMLElement) => string;\n /** True if the element changes on its own every frame (re-captured on the live clock). */\n live?: boolean;\n};\n\nconst painters = new Set<Painter>();\n\n/** Teach the glass to draw something it can't on its own. Returns an unregister function. */\nexport const registerPainter = (painter: Painter) => {\n painters.add(painter);\n scene.dirty = true;\n return () => {\n painters.delete(painter);\n scene.dirty = true;\n };\n};\n\n// ---------------------------------------------------------------- geometry\n\nexport const intersects = (rect: DOMRect, left: number, top: number, right: number, bottom: number) =>\n rect.right > left && rect.left < right && rect.bottom > top && rect.top < bottom;\n\n// Quarter-pixel rounding for fingerprints: sub-pixel jitter shouldn't force a redraw.\nconst q = (n: number) => Math.round(n * 4);\n\n// A cross-origin bitmap taints the capture, and the next texture upload throws.\nconst readableImage = (img: HTMLImageElement) => {\n // A CORS-mode image only finishes loading if its host allowed it, so it can't taint.\n if (img.crossOrigin === 'anonymous' || img.crossOrigin === 'use-credentials') return true;\n const src = img.currentSrc || img.src;\n if (src.startsWith('data:') || src.startsWith('blob:')) return true;\n try {\n return new URL(src, window.location.href).origin === window.location.origin;\n } catch {\n return false;\n }\n};\n\ntype ChainInfo = {\n opacity: number;\n brightness: number;\n /** z-index of the nearest ancestor that sets one, so stacked items paint in order */\n z: number;\n /** Outermost ancestor turned far in 3D, or mirrored: those can't be drawn flat */\n warp: boolean;\n /** Product of the 2D scales up the chain, and whether any ancestor turns in 3D */\n scale: number;\n tilt: boolean;\n /** The 2D linear part of every transform up the chain (a, b, c, d), for rotated or skewed items */\n lin: [number, number, number, number];\n};\n\nconst ROOT_CHAIN: ChainInfo = { opacity: 1, brightness: 1, z: 0, warp: false, scale: 1, tilt: false, lin: [1, 0, 0, 1] };\n\n// Screen-space linear map = parent's map × the element's own.\nconst mul = (p: ChainInfo['lin'], a: number, b: number, c: number, d: number): ChainInfo['lin'] => [\n p[0] * a + p[2] * b,\n p[1] * a + p[3] * b,\n p[0] * c + p[2] * d,\n p[1] * c + p[3] * d\n];\n\n// Ancestor walks, memoized for one capture. Items share most of their ancestors,\n// so each element's computed style is read once per frame, not once per walk.\nconst chainCache = new Map<Element, ChainInfo>();\nexport const resetFrameCache = () => chainCache.clear();\n\nconst chainOf = (el: Element | null): ChainInfo => {\n if (!el) return ROOT_CHAIN;\n const cached = chainCache.get(el);\n if (cached) return cached;\n const parent = chainOf(el.parentElement);\n const style = getComputedStyle(el);\n let scale = parent.scale;\n let tilt = parent.tilt;\n let lin = parent.lin;\n let ownWarp = false;\n const transform = style.transform;\n if (transform && transform !== 'none') {\n const m = new DOMMatrix(transform);\n if (m.is2D) {\n const next = Math.hypot(m.a, m.b);\n if (next > 0.001) scale *= next;\n if (m.a * m.d - m.b * m.c < 0) ownWarp = true;\n lin = mul(lin, m.a, m.b, m.c, m.d);\n } else {\n tilt = true;\n // How far the X/Y axes turn out of the screen, ignoring uniform scale.\n const turnX = Math.abs(m.m11) / (Math.hypot(m.m11, m.m12, m.m13) || 1);\n const turnY = Math.abs(m.m22) / (Math.hypot(m.m21, m.m22, m.m23) || 1);\n if (turnX < 0.95 || turnY < 0.95) ownWarp = true;\n }\n }\n let info: ChainInfo;\n if (el === document.body || el === document.documentElement) {\n info = { ...ROOT_CHAIN, scale, tilt, lin };\n } else {\n let opacity = parent.opacity;\n const o = parseFloat(style.opacity);\n if (Number.isFinite(o)) opacity *= o;\n let brightness = parent.brightness;\n if (style.filter && style.filter !== 'none') {\n const match = /brightness\\(([\\d.]+)(%?)\\)/.exec(style.filter);\n if (match) brightness *= parseFloat(match[1]) / (match[2] ? 100 : 1);\n }\n info = {\n opacity,\n brightness,\n z: style.zIndex !== 'auto' ? Number(style.zIndex) || 0 : parent.z,\n warp: parent.warp || ownWarp,\n scale,\n tilt,\n lin\n };\n }\n chainCache.set(el, info);\n return info;\n};\n\n// Where to draw an element. An affine transform keeps the element's centre at\n// the centre of its on-screen box, so a rotated or skewed item is its layout\n// size, mapped by the chain's 2D matrix around that centre. Exact for any 2D\n// transform. A gentle 3D tilt (which inflates the bounds) is drawn flat at its\n// scaled layout size, so the picture doesn't jump in size as it tilts.\ntype Frame = { cx: number; cy: number; w: number; h: number; m: ChainInfo['lin'] | null };\n\nconst frameOf = (el: Element, rect = el.getBoundingClientRect()): Frame => {\n const chain = chainOf(el);\n const cx = rect.left + rect.width / 2;\n const cy = rect.top + rect.height / 2;\n const layoutW = el instanceof HTMLElement ? el.offsetWidth : 0;\n const layoutH = el instanceof HTMLElement ? el.offsetHeight : 0;\n if (chain.tilt) {\n if (!layoutW) return { cx, cy, w: rect.width, h: rect.height, m: null };\n return { cx, cy, w: layoutW * chain.scale, h: layoutH * chain.scale, m: null };\n }\n const [a, b, c, d] = chain.lin;\n // Axis-aligned (only scaled or not transformed at all): the box on screen is exact.\n if (Math.abs(b) < 1e-4 && Math.abs(c) < 1e-4) return { cx, cy, w: rect.width, h: rect.height, m: null };\n if (!layoutW || !layoutH) return { cx, cy, w: rect.width, h: rect.height, m: null };\n return { cx, cy, w: layoutW, h: layoutH, m: [a, b, c, d] };\n};\n\n/** Runs draw(x, y, w, h) in the element's own frame (rotated if it is). Call inside save/restore. */\nconst inFrame = (ctx: CanvasRenderingContext2D, f: Frame) => {\n if (f.m) {\n ctx.translate(f.cx, f.cy);\n ctx.transform(f.m[0], f.m[1], f.m[2], f.m[3], 0, 0);\n return { x: -f.w / 2, y: -f.h / 2, w: f.w, h: f.h };\n }\n return { x: f.cx - f.w / 2, y: f.cy - f.h / 2, w: f.w, h: f.h };\n};\n\n// CSS radii are in layout px; scale them when the frame is drawn at screen size.\nconst radiusIn = (el: Element, f: Frame, radius: number) => {\n const fit = f.m || !(el instanceof HTMLElement) || !el.offsetWidth ? 1 : f.w / el.offsetWidth;\n return Math.max(0, Math.min(radius * fit, f.w / 2, f.h / 2));\n};\n\n// ---------------------------------------------------------------- clipping\n\ntype ClipCandidate = { node: HTMLElement; radius: number };\n\n// Every ancestor that hides overflow. Memoized per scene rebuild.\nconst clipMemo = new Map<HTMLElement, ClipCandidate[]>();\nconst clipsFrom = (node: HTMLElement | null): ClipCandidate[] => {\n if (!node || node === document.body) return [];\n const cached = clipMemo.get(node);\n if (cached) return cached;\n const style = getComputedStyle(node);\n const clips = /hidden|clip/.test(style.overflowX) || /hidden|clip/.test(style.overflowY);\n const outer = clipsFrom(node.parentElement);\n const found = clips ? [{ node, radius: parseFloat(style.borderTopLeftRadius) || 0 }, ...outer] : outer;\n clipMemo.set(node, found);\n return found;\n};\n\n// Intersects the canvas clip with each overflow box that actually cuts into the item.\nconst applyClips = (ctx: CanvasRenderingContext2D, candidates: ClipCandidate[], box: DOMRect) => {\n for (const { node, radius } of candidates) {\n const outer = node.getBoundingClientRect();\n const inset = Math.min(radius, outer.width / 2, outer.height / 2);\n if (\n box.left >= outer.left + inset &&\n box.right <= outer.right - inset &&\n box.top >= outer.top + inset &&\n box.bottom <= outer.bottom - inset\n )\n continue;\n // The clip path is built in the box's own frame, then the transform goes\n // back; the clip stays.\n const base = ctx.getTransform();\n const frame = frameOf(node, outer);\n const at = inFrame(ctx, frame);\n ctx.beginPath();\n roundRect(ctx, at.x, at.y, at.w, at.h, radiusIn(node, frame, radius));\n ctx.setTransform(base);\n ctx.clip();\n }\n};\n\nconst roundRect = (ctx: CanvasRenderingContext2D, x: number, y: number, w: number, h: number, r: number) => {\n if (ctx.roundRect) {\n ctx.roundRect(x, y, w, h, r);\n return;\n }\n // Safari before 16.\n const rr = Math.min(r, w / 2, h / 2);\n ctx.moveTo(x + rr, y);\n ctx.arcTo(x + w, y, x + w, y + h, rr);\n ctx.arcTo(x + w, y + h, x, y + h, rr);\n ctx.arcTo(x, y + h, x, y, rr);\n ctx.arcTo(x, y, x + w, y, rr);\n ctx.closePath();\n};\n\n// Something fixed behind the page (a negative z-index) paints under everything,\n// whatever its document order. The outermost non-zero z-index decides.\nconst behindMemo = new Map<HTMLElement, boolean | null>();\nconst stackSide = (node: HTMLElement | null): boolean | null => {\n if (!node || node === document.documentElement) return null;\n const cached = behindMemo.get(node);\n if (cached !== undefined) return cached;\n let side = stackSide(node.parentElement);\n if (side === null) {\n const z = getComputedStyle(node).zIndex;\n const n = z === 'auto' ? 0 : Number(z);\n side = n < 0 ? true : n > 0 ? false : null;\n }\n behindMemo.set(node, side);\n return side;\n};\n\n// ---------------------------------------------------------------- CSS backgrounds\n\nconst splitTop = (value: string) => {\n const parts: string[] = [];\n let depth = 0;\n let start = 0;\n for (let i = 0; i < value.length; i++) {\n const ch = value[i];\n if (ch === '(') depth++;\n else if (ch === ')') depth--;\n else if (ch === ',' && depth === 0) {\n parts.push(value.slice(start, i).trim());\n start = i + 1;\n }\n }\n parts.push(value.slice(start).trim());\n return parts;\n};\n\ntype LinearSpec = {\n /** Degrees (CSS: 0 = to top, clockwise), or a corner like [1, -1] for \"to right top\" */\n angle: number | [number, number];\n stops: { color: string; at: number | null }[];\n};\n\nconst linearCache = new Map<string, LinearSpec | null>();\n\n// Parses one computed linear-gradient() layer. Only %-positioned (or unpositioned)\n// stops are supported; anything else returns null and the layer is skipped.\nconst parseLinear = (layer: string): LinearSpec | null => {\n if (linearCache.has(layer)) return linearCache.get(layer)!;\n let spec: LinearSpec | null = null;\n const match = /^linear-gradient\\((.*)\\)$/.exec(layer);\n if (match) {\n const args = splitTop(match[1]);\n let angle: LinearSpec['angle'] = 180;\n const head = args[0];\n const deg = /^(-?[\\d.]+)(deg|turn|rad)$/.exec(head);\n if (deg) {\n const n = parseFloat(deg[1]);\n angle = deg[2] === 'turn' ? n * 360 : deg[2] === 'rad' ? (n * 180) / Math.PI : n;\n args.shift();\n } else if (head.startsWith('to ')) {\n const words = head.slice(3).split(/\\s+/);\n const sx = words.includes('right') ? 1 : words.includes('left') ? -1 : 0;\n const sy = words.includes('bottom') ? 1 : words.includes('top') ? -1 : 0;\n angle = sx && sy ? [sx, sy] : sx ? (sx > 0 ? 90 : 270) : sy > 0 ? 180 : 0;\n args.shift();\n }\n const stops: LinearSpec['stops'] = [];\n let ok = true;\n for (const arg of args) {\n const pos = /\\s(-?[\\d.]+)%$/.exec(arg);\n const color = pos ? arg.slice(0, pos.index).trim() : arg;\n if (!pos && /\\d(px|em|rem)$/.test(arg)) ok = false;\n stops.push({ color, at: pos ? parseFloat(pos[1]) / 100 : null });\n }\n if (ok && stops.length >= 2) {\n if (stops[0].at == null) stops[0].at = 0;\n if (stops[stops.length - 1].at == null) stops[stops.length - 1].at = 1;\n for (let i = 1; i < stops.length - 1; i++) {\n if (stops[i].at != null) continue;\n let j = i;\n while (stops[j].at == null) j++;\n const from = stops[i - 1].at!;\n const to = stops[j].at!;\n for (let k = i; k < j; k++) stops[k].at = from + ((to - from) * (k - i + 1)) / (j - i + 1);\n }\n spec = { angle, stops };\n }\n }\n linearCache.set(layer, spec);\n return spec;\n};\n\nconst makeLinear = (ctx: CanvasRenderingContext2D, spec: LinearSpec, x: number, y: number, w: number, h: number) => {\n let dx: number;\n let dy: number;\n if (Array.isArray(spec.angle)) {\n const [sx, sy] = spec.angle;\n const n = Math.hypot(w, h) || 1;\n dx = (sx * h) / n;\n dy = (sy * w) / n;\n } else {\n const rad = (spec.angle * Math.PI) / 180;\n dx = Math.sin(rad);\n dy = -Math.cos(rad);\n }\n const half = (Math.abs(w * dx) + Math.abs(h * dy)) / 2;\n const cx = x + w / 2;\n const cy = y + h / 2;\n const gradient = ctx.createLinearGradient(cx - dx * half, cy - dy * half, cx + dx * half, cy + dy * half);\n for (const stop of spec.stops) {\n try {\n gradient.addColorStop(Math.max(0, Math.min(1, stop.at ?? 0)), stop.color);\n } catch {\n return null;\n }\n }\n return gradient;\n};\n\ntype BoxStyle = { color: string | null; layers: LinearSpec[]; radius: number; key: string };\n\nconst boxStyleOf = (el: HTMLElement): BoxStyle | null => {\n const style = getComputedStyle(el);\n const bg = style.backgroundColor;\n const color = bg && bg !== 'transparent' && !/rgba\\(.*,\\s*0\\)$/.test(bg) ? bg : null;\n const image = style.backgroundImage;\n const layers =\n image && image !== 'none' && !image.includes('url(')\n ? splitTop(image)\n .map(parseLinear)\n .filter((spec): spec is LinearSpec => spec != null)\n .reverse()\n : [];\n if (!color && layers.length === 0) return null;\n const radius = parseFloat(style.borderTopLeftRadius) || 0;\n return { color, layers, radius, key: `${bg}|${image}|${radius}` };\n};\n\n// ---------------------------------------------------------------- text\n\nconst fontOf = (style: CSSStyleDeclaration) =>\n `${style.fontStyle} ${style.fontWeight} ${style.fontSize} ${style.fontFamily}`;\n\nconst transformText = (text: string, mode: string) =>\n mode === 'uppercase' ? text.toUpperCase() : mode === 'lowercase' ? text.toLowerCase() : text;\n\nconst textRange = typeof document !== 'undefined' ? document.createRange() : null;\n\n// Draws the text inside an element word by word, at the boxes the browser laid\n// each word out in, so it lines up with the real text (wrapping, alignment and all).\nconst paintText = (\n ctx: CanvasRenderingContext2D,\n host: HTMLElement,\n view: { left: number; top: number; right: number; bottom: number }\n) => {\n if (!textRange) return;\n const walker = document.createTreeWalker(host, NodeFilter.SHOW_TEXT);\n const canSpace = 'letterSpacing' in ctx;\n for (let node = walker.nextNode(); node; node = walker.nextNode()) {\n const text = node.nodeValue ?? '';\n const parent = node.parentElement;\n if (!parent || !text.trim()) continue;\n const style = getComputedStyle(parent);\n if (style.visibility === 'hidden') continue;\n const chain = chainOf(parent);\n if (chain.opacity <= 0.01) continue;\n ctx.save();\n ctx.globalAlpha = Math.min(1, chain.opacity);\n ctx.font = fontOf(style);\n const fill = style.webkitTextFillColor;\n ctx.fillStyle = fill && fill !== style.color && !/rgba\\(.*,\\s*0\\)$/.test(fill) ? fill : style.color;\n ctx.textBaseline = 'alphabetic';\n ctx.textAlign = 'left';\n if (canSpace) (ctx as CanvasRenderingContext2D & { letterSpacing: string }).letterSpacing = style.letterSpacing === 'normal' ? '0px' : style.letterSpacing;\n const metrics = ctx.measureText('Hg');\n const ascent = metrics.fontBoundingBoxAscent ?? metrics.actualBoundingBoxAscent;\n const descent = metrics.fontBoundingBoxDescent ?? metrics.actualBoundingBoxDescent;\n const words = /\\S+/g;\n for (let match = words.exec(text); match; match = words.exec(text)) {\n textRange.setStart(node, match.index);\n textRange.setEnd(node, match.index + match[0].length);\n const rects = textRange.getClientRects();\n const rect = rects[0];\n if (!rect || !intersects(rect, view.left, view.top, view.right, view.bottom)) continue;\n // A range's box is the font's content area; the baseline sits ascent below\n // its top, centred if the box is taller than the font.\n const y = rect.top + (rect.height - (ascent + descent)) / 2 + ascent;\n ctx.fillText(transformText(match[0], style.textTransform), rect.left, y);\n }\n ctx.restore();\n }\n};\n\n// ---------------------------------------------------------------- scene\n\ntype Kind = 'image' | 'canvas' | 'video' | 'box' | 'text' | 'painter' | 'glass';\n\n// Every glass's tone, by its element, so other glasses can draw a stand-in for it.\nconst glassTones = new WeakMap<HTMLElement, () => 'light' | 'dark'>();\nexport const registerGlassTone = (element: HTMLElement, tone: () => 'light' | 'dark') => glassTones.set(element, tone);\n\ntype SceneEntry = {\n node: HTMLElement;\n kind: Kind;\n clips: ClipCandidate[];\n behind: boolean;\n box?: BoxStyle;\n painter?: Painter;\n /** Own corner radius (layout px) of an image, canvas or video, so it's drawn rounded like on screen. */\n radius?: number;\n};\n\n// Everything the capture needs that only changes when the DOM does. Shared by\n// every glass, rebuilt on mutation (and at most once a second as a safety net).\nconst scene = {\n entries: [] as SceneEntry[],\n bg: '#ffffff',\n dirty: true,\n builtAt: 0,\n observer: null as MutationObserver | null,\n users: 0\n};\n\nconst SCENE_TTL_MS = 1000;\nconst BASE_SELECTOR = 'img, canvas, video, [data-glass-box], [data-glass-text]';\n\nconst rebuildScene = () => {\n clipMemo.clear();\n behindMemo.clear();\n const selector = [BASE_SELECTOR, ...[...painters].map((p) => p.selector)].join(', ');\n const behind: SceneEntry[] = [];\n const front: SceneEntry[] = [];\n // Text containers already drawn, so what's nested in one can go underneath it.\n const textEntries = new Map<Element, { list: SceneEntry[]; entry: SceneEntry }>();\n document.querySelectorAll<HTMLElement>(selector).forEach((node) => {\n if (node.closest('[data-glass-ignore]')) return;\n // Another glass: its WebGL surface can't be read in step with this one, so it's\n // drawn as a frosted stand-in of its shape (a glass never draws itself).\n if (node instanceof HTMLCanvasElement && node.hasAttribute('data-snell-surface')) {\n const host = node.parentElement;\n if (host && !host.closest('[data-glass-ignore]')) {\n const isBehind = stackSide(host) ?? false;\n const list = isBehind ? behind : front;\n // Below the glass's own tagged text or boxes, which were collected first\n // when the host itself is tagged.\n const first = list.findIndex((e) => host.contains(e.node));\n const standIn: SceneEntry = { node: host, kind: 'glass', clips: clipsFrom(host.parentElement), behind: isBehind };\n if (first < 0) list.push(standIn);\n else list.splice(first, 0, standIn);\n }\n return;\n }\n // Inside a text container its words are already drawn by that container,\n // but its own fill or media isn't: add those just below the container's text\n // (a code block's background, an inline image), never its words again.\n const textHost = node.parentElement?.closest('[data-glass-text]');\n if (textHost) {\n const host = textEntries.get(textHost);\n if (!host) return;\n const nested: SceneEntry[] = [];\n const clips = clipsFrom(node.parentElement);\n const isBehind = host.entry.behind;\n if (node instanceof HTMLImageElement) nested.push({ node, kind: 'image', clips, behind: isBehind });\n else if (node instanceof HTMLCanvasElement) nested.push({ node, kind: 'canvas', clips, behind: isBehind });\n else if (node instanceof HTMLVideoElement) nested.push({ node, kind: 'video', clips, behind: isBehind });\n else if (node.hasAttribute('data-glass-box')) {\n const box = boxStyleOf(node);\n if (box) nested.push({ node, kind: 'box', clips, behind: isBehind, box });\n }\n for (const item of nested) {\n if (item.kind !== 'box') item.radius = parseFloat(getComputedStyle(node).borderTopLeftRadius) || 0;\n host.list.splice(host.list.indexOf(host.entry), 0, item);\n }\n return;\n }\n let entry: SceneEntry | null = null;\n const clips = clipsFrom(node.parentElement);\n const isBehind = stackSide(node) ?? false;\n const painter = [...painters].find((p) => node.matches(p.selector));\n if (painter) entry = { node, kind: 'painter', clips, behind: isBehind, painter };\n else if (node instanceof HTMLImageElement) entry = { node, kind: 'image', clips, behind: isBehind };\n else if (node instanceof HTMLCanvasElement) entry = { node, kind: 'canvas', clips, behind: isBehind };\n else if (node instanceof HTMLVideoElement) entry = { node, kind: 'video', clips, behind: isBehind };\n else {\n // A box can also hold text: its background first, then its words.\n if (node.hasAttribute('data-glass-box')) {\n const box = boxStyleOf(node);\n if (box) (isBehind ? behind : front).push({ node, kind: 'box', clips, behind: isBehind, box });\n }\n if (node.hasAttribute('data-glass-text')) entry = { node, kind: 'text', clips, behind: isBehind };\n }\n if (entry && (entry.kind === 'image' || entry.kind === 'canvas' || entry.kind === 'video')) {\n entry.radius = parseFloat(getComputedStyle(node).borderTopLeftRadius) || 0;\n }\n if (entry) {\n const list = isBehind ? behind : front;\n list.push(entry);\n if (entry.kind === 'text') textEntries.set(node, { list, entry });\n }\n });\n scene.entries = behind.concat(front);\n const bg = getComputedStyle(document.body).backgroundColor;\n const rootBg = getComputedStyle(document.documentElement).backgroundColor;\n const opaque = (c: string) => c && c !== 'transparent' && !/rgba\\(.*,\\s*0\\)$/.test(c);\n scene.bg = opaque(bg) ? bg : opaque(rootBg) ? rootBg : '#ffffff';\n clipMemo.clear();\n behindMemo.clear();\n scene.dirty = false;\n scene.builtAt = performance.now();\n};\n\nexport const retainScene = () => {\n scene.users += 1;\n if (scene.observer) return;\n scene.observer = new MutationObserver(() => {\n scene.dirty = true;\n });\n scene.observer.observe(document.body, {\n childList: true,\n subtree: true,\n characterData: true,\n attributes: true,\n // Not style/class: animations change those every frame. Style-only changes\n // (a new background on a box) are picked up by the once-a-second rebuild.\n attributeFilter: ['src', 'data-glass-box', 'data-glass-text', 'data-glass-ignore']\n });\n scene.dirty = true;\n};\n\nexport const releaseScene = () => {\n scene.users = Math.max(0, scene.users - 1);\n if (scene.users > 0 || !scene.observer) return;\n scene.observer.disconnect();\n scene.observer = null;\n scene.entries = [];\n};\n\n/** Forces the glass to re-read the page structure (rarely needed; DOM changes are observed). */\nexport const invalidateBackdrop = () => {\n scene.dirty = true;\n};\n\nconst ensureScene = () => {\n if (scene.dirty || performance.now() - scene.builtAt > SCENE_TTL_MS) rebuildScene();\n};\n\n// ---------------------------------------------------------------- capture\n\ntype VisibleItem = { entry: SceneEntry; rect: DOMRect; chain: ChainInfo; order: number };\n\nexport type Backdrop = {\n view: { left: number; top: number; width: number; height: number };\n items: VisibleItem[];\n background: string;\n /** Changes whenever the painted result would; equal strings mean the last capture still holds */\n signature: string;\n /** Something under the glass changes on its own (canvas, video, live painter) */\n live: boolean;\n};\n\nconst animatingInside = (node: HTMLElement) => {\n if (typeof node.getAnimations !== 'function') return false;\n try {\n return node.getAnimations({ subtree: true }).some((a) => a.playState === 'running');\n } catch {\n return false;\n }\n};\n\n// One value per animation frame, shared by every glass rendering in it.\nlet stamp = 0;\nlet stampAt = -1;\nconst frameStamp = () => {\n const now = performance.now();\n if (now - stampAt > 4) {\n stamp++;\n stampAt = now;\n }\n return stamp;\n};\n\n// The cheap half of a capture: what overlaps the glass, in paint order, plus a\n// fingerprint of everything that affects the picture. No pixels are touched.\nexport const collectBackdrop = (\n glass: HTMLElement,\n scope: Element,\n background: string | undefined,\n left: number,\n top: number,\n width: number,\n height: number\n): Backdrop => {\n const right = left + width;\n const bottom = top + height;\n ensureScene();\n const items: VisibleItem[] = [];\n scene.entries.forEach((entry, order) => {\n const { node } = entry;\n if (!node.isConnected || glass.contains(node) || !scope.contains(node)) return;\n const rect = node.getBoundingClientRect();\n if (rect.width < 1 || rect.height < 1 || !intersects(rect, left, top, right, bottom)) return;\n if (entry.kind === 'image') {\n const img = node as HTMLImageElement;\n if (!(img.complete && img.naturalWidth > 0 && readableImage(img))) return;\n }\n if (entry.kind === 'video' && (node as HTMLVideoElement).readyState < 2) return;\n const chain = chainOf(node);\n if (chain.opacity <= 0.01 || chain.warp) return;\n // Only glasses underneath this one show through it: lower in the stack, or\n // level with it and earlier in the page.\n if (entry.kind === 'glass') {\n const ownZ = chainOf(glass).z;\n const later = glass.compareDocumentPosition(node) & Node.DOCUMENT_POSITION_FOLLOWING;\n if (chain.z > ownZ || (chain.z === ownZ && later && !node.contains(glass))) return;\n }\n items.push({ entry, rect, chain, order });\n });\n items.sort((a, b) => Number(b.entry.behind) - Number(a.entry.behind) || a.chain.z - b.chain.z || a.order - b.order);\n\n const bg = background ?? scene.bg;\n let live = false;\n const parts: (string | number)[] = [bg, q(left), q(top), q(width), q(height)];\n for (const { entry, rect, chain, order } of items) {\n const { node } = entry;\n if (entry.kind === 'canvas' || entry.kind === 'video' || entry.painter?.live) live = true;\n parts.push(order, entry.kind, q(rect.left), q(rect.top), q(rect.width), q(rect.height));\n parts.push(Math.round(chain.opacity * 1000), Math.round(chain.brightness * 1000), chain.z);\n if (entry.kind === 'image') parts.push((node as HTMLImageElement).currentSrc || (node as HTMLImageElement).src);\n if (entry.kind === 'box') parts.push(entry.box!.key);\n if (entry.kind === 'glass') parts.push(glassTones.get(node)?.() ?? 'light', getComputedStyle(node).borderTopLeftRadius);\n if (entry.kind === 'text') parts.push(node.textContent?.length ?? 0);\n // Text and boxes are fingerprinted by their own box, but what's inside can\n // move without it (letters animating in, a gradient transition). While any\n // CSS or Web Animation runs inside, the fingerprint changes every frame so the\n // capture follows it.\n if ((entry.kind === 'text' || entry.kind === 'box') && animatingInside(node)) parts.push('anim', frameStamp());\n if (entry.painter?.signature) parts.push(entry.painter.signature(node));\n }\n return { view: { left, top, width, height }, items, background: bg, signature: parts.join('|'), live };\n};\n\n// The part of the bitmap an object-fit: cover image actually shows.\nconst sourceRect = (img: HTMLImageElement, boxW: number, boxH: number) => {\n const nw = img.naturalWidth;\n const nh = img.naturalHeight;\n if (getComputedStyle(img).objectFit !== 'cover' || boxW <= 0 || boxH <= 0) return { sx: 0, sy: 0, sw: nw, sh: nh };\n const scale = Math.max(boxW / nw, boxH / nh);\n const sw = boxW / scale;\n const sh = boxH / scale;\n return { sx: (nw - sw) / 2, sy: (nh - sh) / 2, sw, sh };\n};\n\n// Clips to a media element's own rounded corners, in its frame (call after inFrame).\nconst clipOwnRadius = (\n ctx: CanvasRenderingContext2D,\n node: Element,\n frame: Frame,\n at: { x: number; y: number; w: number; h: number },\n radius: number | undefined\n) => {\n if (!radius) return;\n ctx.beginPath();\n roundRect(ctx, at.x, at.y, at.w, at.h, radiusIn(node, frame, radius));\n ctx.clip();\n};\n\n// What another glass looks like from behind this one: its rounded shape, frosted\n// in its tone, with a bright rim and a soft drop shadow. Not refracted, but close\n// enough at a glance, and it never depends on the order glasses render in.\nconst paintGlassStandIn = (ctx: CanvasRenderingContext2D, node: HTMLElement, rect: DOMRect) => {\n const frame = frameOf(node, rect);\n const at = inFrame(ctx, frame);\n const css = getComputedStyle(node).borderTopLeftRadius.split(' ')[0] ?? '';\n const w = node.offsetWidth || rect.width;\n const h = node.offsetHeight || rect.height;\n const cssPx = css.endsWith('%') ? (parseFloat(css) / 100) * Math.min(w, h) : parseFloat(css) || 0;\n const r = radiusIn(node, frame, cssPx);\n const dark = glassTones.get(node)?.() === 'dark';\n\n const shape = () => {\n ctx.beginPath();\n roundRect(ctx, at.x, at.y, at.w, at.h, r);\n };\n ctx.save();\n shape();\n ctx.shadowColor = dark ? 'rgba(0, 0, 0, 0.35)' : 'rgba(20, 20, 20, 0.16)';\n ctx.shadowBlur = 18;\n ctx.shadowOffsetY = 6;\n const fill = ctx.createLinearGradient(0, at.y, 0, at.y + at.h);\n if (dark) {\n fill.addColorStop(0, 'rgba(58, 58, 62, 0.82)');\n fill.addColorStop(1, 'rgba(28, 28, 32, 0.88)');\n } else {\n fill.addColorStop(0, 'rgba(255, 255, 255, 0.86)');\n fill.addColorStop(1, 'rgba(246, 246, 248, 0.74)');\n }\n ctx.fillStyle = fill;\n ctx.fill();\n ctx.restore();\n shape();\n ctx.lineWidth = 1;\n ctx.strokeStyle = dark ? 'rgba(255, 255, 255, 0.16)' : 'rgba(255, 255, 255, 0.95)';\n ctx.stroke();\n};\n\n// The expensive half: repaints the backdrop into the 2D capture.\nexport const paintBackdrop = (ctx: CanvasRenderingContext2D, backdrop: Backdrop, scaleX: number, scaleY: number) => {\n const { left, top, width, height } = backdrop.view;\n ctx.setTransform(scaleX, 0, 0, scaleY, -left * scaleX, -top * scaleY);\n ctx.clearRect(left, top, width, height);\n ctx.fillStyle = backdrop.background;\n ctx.fillRect(left, top, width, height);\n const view = { left, top, right: left + width, bottom: top + height };\n\n const canFilter = 'filter' in ctx;\n for (const { entry, rect, chain } of backdrop.items) {\n const { node, clips, box, kind, painter } = entry;\n ctx.save();\n ctx.globalAlpha = Math.max(0, Math.min(1, chain.opacity));\n if (canFilter && Math.abs(chain.brightness - 1) > 0.01) ctx.filter = `brightness(${chain.brightness})`;\n applyClips(ctx, clips, rect);\n try {\n if (kind === 'box' && box) {\n const frame = frameOf(node, rect);\n const at = inFrame(ctx, frame);\n ctx.beginPath();\n roundRect(ctx, at.x, at.y, at.w, at.h, radiusIn(node, frame, box.radius));\n if (box.color) {\n ctx.fillStyle = box.color;\n ctx.fill();\n }\n for (const layer of box.layers) {\n const gradient = makeLinear(ctx, layer, at.x, at.y, at.w, at.h);\n if (!gradient) continue;\n ctx.fillStyle = gradient;\n ctx.fill();\n }\n } else if (kind === 'glass') {\n paintGlassStandIn(ctx, node, rect);\n } else if (kind === 'text') {\n paintText(ctx, node, view);\n } else if (kind === 'canvas') {\n const frame = frameOf(node, rect);\n const at = inFrame(ctx, frame);\n clipOwnRadius(ctx, node, frame, at, entry.radius);\n ctx.drawImage(node as HTMLCanvasElement, at.x, at.y, at.w, at.h);\n } else if (kind === 'video') {\n const video = node as HTMLVideoElement;\n const frame = frameOf(node, rect);\n const at = inFrame(ctx, frame);\n clipOwnRadius(ctx, node, frame, at, entry.radius);\n const fit = getComputedStyle(video).objectFit;\n if (fit === 'cover' && video.videoWidth > 0) {\n const s = Math.max(at.w / video.videoWidth, at.h / video.videoHeight);\n const sw = at.w / s;\n const sh = at.h / s;\n ctx.drawImage(video, (video.videoWidth - sw) / 2, (video.videoHeight - sh) / 2, sw, sh, at.x, at.y, at.w, at.h);\n } else {\n ctx.drawImage(video, at.x, at.y, at.w, at.h);\n }\n } else if (kind === 'image') {\n const img = node as HTMLImageElement;\n const frame = frameOf(node, rect);\n const at = inFrame(ctx, frame);\n clipOwnRadius(ctx, node, frame, at, entry.radius);\n const { sx, sy, sw, sh } = sourceRect(img, img.offsetWidth, img.offsetHeight);\n ctx.drawImage(img, sx, sy, sw, sh, at.x, at.y, at.w, at.h);\n } else if (kind === 'painter' && painter) {\n painter.paint({ ctx, element: node, rect });\n }\n } catch {\n // One bad source (a broken image, a painter that threw) shouldn't stop the rest.\n }\n ctx.restore();\n }\n};\n","// One full-screen triangle; the fragment shader does all the work.\nexport const VERT = `#version 300 es\nvoid main() {\n vec2 corner = vec2(gl_VertexID == 1 ? 3.0 : -1.0, gl_VertexID == 2 ? 3.0 : -1.0);\n gl_Position = vec4(corner, 0.0, 1.0);\n}\n`;\n\n// The glass is modelled as a slab with a flat top and a rounded bezel.\n// Passes 0 and 1 blur the captured backdrop (a separable gaussian) for frost.\n// Pass 2 bends each pixel's view ray through the bezel with Snell's law, so the\n// middle stays nearly undistorted and the bending is all in the rounded edge.\n// Lighting is a fresnel sheen, a hairline rim and a second inner reflection,\n// all brightest on the side facing the light.\nexport const FRAG = `#version 300 es\nprecision highp float;\nuniform sampler2D uTex;\nuniform sampler2D uSharp;\nuniform vec2 uSize;\nuniform vec2 uBufSize;\nuniform vec2 uPad;\n// Size of the output canvas. It can be bigger than the glass (sized in steps,\n// anchored top-left), so rows are measured from its top.\nuniform vec2 uCanvas;\nuniform float uPass;\nuniform float uSigma;\nuniform int uTaps;\nuniform float uFrost;\nuniform float uBezel;\nuniform float uRadius;\nuniform float uDepth;\nuniform float uDpr;\nuniform float uTone;\nuniform vec2 uLight;\nuniform float uIor;\nuniform float uDispersion;\nuniform float uSaturation;\nuniform float uWash;\nuniform float uShine;\nout vec4 outColor;\n\nfloat sdRoundBox(vec2 p, vec2 b, float r) {\n vec2 q = abs(p) - b + r;\n return length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - r;\n}\n\nvec3 sampleAt(sampler2D tex, vec2 topDown) {\n vec2 uv = vec2(topDown.x, uBufSize.y - topDown.y) / uBufSize;\n return texture(tex, uv).rgb;\n}\n\nvec3 blur(vec2 topDown, vec2 axis) {\n float stepPx = (2.0 * uSigma) / float(uTaps);\n vec3 acc = vec3(0.0);\n float wsum = 0.0;\n for (int i = -uTaps; i <= uTaps; i++) {\n float x = float(i) * stepPx;\n float w = exp(-(x * x) / (2.0 * uSigma * uSigma));\n acc += sampleAt(uTex, topDown + axis * x) * w;\n wsum += w;\n }\n return acc / wsum;\n}\n\nvoid main() {\n if (uPass < 1.5) {\n vec2 topDown = vec2(gl_FragCoord.x, uBufSize.y - gl_FragCoord.y);\n outColor = vec4(blur(topDown, uPass < 0.5 ? vec2(1.0, 0.0) : vec2(0.0, 1.0)), 1.0);\n return;\n }\n\n vec2 glassPx = vec2(gl_FragCoord.x, uCanvas.y - gl_FragCoord.y);\n vec2 c = glassPx - uSize * 0.5;\n vec2 halfSize = uSize * 0.5;\n float rad = min(min(halfSize.x, halfSize.y), uRadius);\n float d = sdRoundBox(c, halfSize, rad);\n float cover = clamp(0.5 - d, 0.0, 1.0);\n if (cover <= 0.0) {\n outColor = vec4(0.0);\n return;\n }\n\n // Outward direction of the silhouette, from the distance field.\n float e = 0.5;\n vec2 grad = vec2(\n sdRoundBox(c + vec2(e, 0.0), halfSize, rad) - sdRoundBox(c - vec2(e, 0.0), halfSize, rad),\n sdRoundBox(c + vec2(0.0, e), halfSize, rad) - sdRoundBox(c - vec2(0.0, e), halfSize, rad)\n );\n vec2 out2 = length(grad) > 1e-5 ? normalize(grad) : vec2(0.0, -1.0);\n\n // Squircle bezel: h(t) = (1 - (1 - t)^4)^(1/4), t = 0 at the rim, 1 where the top goes flat.\n float bezel = max(min(uBezel, rad), 1.0);\n float t = clamp(-d / bezel, 0.0, 1.0);\n float s = 1.0 - t;\n float s3 = s * s * s;\n float slope = min(s3 * pow(max(1.0 - s3 * s, 1e-4), -0.75), 10.0);\n vec3 n = normalize(vec3(out2 * slope * (uDepth / bezel) * 0.65, 1.0));\n\n // A ray looking straight down bends at the curved top (Snell's law) and lands\n // on the page uDepth below. On a convex bezel it is pulled toward the middle.\n vec3 r = refract(vec3(0.0, 0.0, -1.0), n, 1.0 / uIor);\n vec2 shift = r.xy / max(-r.z, 0.25) * uDepth;\n float reach = bezel * 2.0;\n if (length(shift) > reach) shift = normalize(shift) * reach;\n\n // Red bends less than blue: split the channels along the same ray.\n vec2 at = glassPx + uPad;\n vec3 sharp = vec3(\n sampleAt(uSharp, at + shift * (1.0 + uDispersion)).r,\n sampleAt(uSharp, at + shift).g,\n sampleAt(uSharp, at + shift * (1.0 - uDispersion)).b\n );\n // Frost fades between the sharp page and the blur (always made at the full\n // radius), so easing it never needs a fresh blur. The rim keeps some detail.\n vec3 soft = uFrost > 0.001 ? sampleAt(uTex, at + shift) : sharp;\n float edge = 1.0 - smoothstep(0.0, 1.0, t);\n vec3 col = mix(soft, sharp, mix(1.0, 0.15 * edge, uFrost));\n\n float luma = dot(col, vec3(0.2126, 0.7152, 0.0722));\n col = mix(vec3(luma), col, uSaturation);\n\n // Vertical wash: white at the top fading toward the bottom (light), or a\n // smoky tint (dark), so a label on the glass stays readable.\n float y = clamp(glassPx.y / uSize.y, 0.0, 1.0);\n if (uTone < 0.5) {\n col = mix(col, vec3(1.0), clamp((0.2 + 0.06 * uFrost + 0.78 * pow(1.0 - y, 0.85)) * uWash, 0.0, 1.0));\n } else {\n col = mix(col, vec3(0.02), clamp((0.25 + 0.5 * pow(1.0 - y, 1.3)) * uWash, 0.0, 1.0));\n }\n\n // Lighting. uLight points from the glass toward the light (it can follow the pointer).\n vec2 lightDir = normalize(uLight);\n float fres = pow(1.0 - n.z, 2.0);\n float facing = dot(out2, lightDir);\n float key = pow(max(facing, 0.0), 2.0);\n float fill = pow(max(-facing, 0.0), 2.0) * 0.12;\n float light = (uTone < 0.5 ? 1.0 : 0.55) * uShine;\n col += vec3(fres * (key + fill) * 0.3 * light);\n col += vec3(fres * pow(max(facing, 0.0), 18.0) * 0.35 * light);\n // Hairline rim: bright all round, brightest on the side facing the light.\n float line = exp(-max(-d, 0.0) / (0.6 * uDpr));\n float lit = 0.5 + 0.5 * facing;\n float rim = (uTone < 0.5 ? mix(0.25, 0.8, lit * lit) : mix(0.08, 0.45, lit * lit)) * uShine;\n col = mix(col, vec3(1.0), clamp(line * rim, 0.0, 1.0));\n // Thick glass catches a second, softer reflection a few px inside the rim,\n // with a faint dark seam between the two. Only on the lit side.\n float inset = -d / uDpr;\n float band = exp(-pow((inset - 6.0) / 3.0, 2.0));\n float seam = exp(-pow((inset - 2.6) / 1.2, 2.0));\n col = mix(col, vec3(1.0), clamp(band * pow(max(facing, 0.0), 1.5) * (uTone < 0.5 ? 0.2 : 0.1) * uShine, 0.0, 1.0));\n col *= 1.0 - seam * (uTone < 0.5 ? 0.10 : 0.18) * (1.0 - 0.5 * lit);\n\n outColor = vec4(clamp(col, 0.0, 1.0) * cover, cover);\n}\n`;\n","import {\n collectBackdrop,\n paintBackdrop,\n registerGlassTone,\n releaseScene,\n resetFrameCache,\n retainScene\n} from './backdrop';\nimport { FRAG, VERT } from './shader';\n\nexport type GlassOptions = {\n /** 'light' washes the top with white; 'dark' with a smoky tint. Default 'light'. */\n tone?: 'light' | 'dark';\n /** Corner radius in CSS px. Default: the element's own border-radius (animations included). */\n radius?: number;\n /** 0 = clear, 1 = fully frosted. Fractions blend, so it can be animated. Default 0. */\n frost?: number;\n /** Frost blur radius (gaussian sigma) in CSS px. Default 9. */\n blur?: number;\n /** Index of refraction. 1 = no bending; glass is ~1.5. Default 1.5. */\n ior?: number;\n /** How far red and blue split at the edge (chromatic aberration). Default 0.14. */\n dispersion?: number;\n /** Thickness of the slab in CSS px: how far the edge reaches for what it shows. Default 50. */\n depth?: number;\n /** Width of the rounded edge in CSS px, where all the bending happens. Default 36. */\n bezel?: number;\n /** Strength of the top-down white (or dark) wash, 0..~1.5. Default 0.35. */\n wash?: number;\n /** Colour saturation of what's seen through the glass. Default 1.1. */\n saturation?: number;\n /** Strength of the rim light and sheen. Default 1. */\n shine?: number;\n /** How much the light turns toward the pointer, 0..1. Default 0.8 (0 with reduced motion). */\n lightFollow?: number;\n /** Stops rendering and keeps the last frame. */\n paused?: boolean;\n /** Only things inside this element are seen through the glass. Default document.body. */\n backdrop?: Element | null;\n /** Colour under everything. Default: the page background. */\n background?: string;\n /** How often (ms) a live source under the glass (canvas, video) is re-captured. Default 33. */\n liveInterval?: number;\n};\n\nexport type Glass = {\n readonly element: HTMLElement;\n /** True once WebGL drew its first frame (false where WebGL2 is unavailable). */\n readonly ready: boolean;\n /** Changes options; takes effect on the next frame. */\n set: (options: Partial<GlassOptions>) => void;\n /**\n * Renders now. Call it right after moving or resizing the element inside your\n * own requestAnimationFrame callback, so the glass matches it in the same frame.\n */\n render: () => void;\n /** Stops rendering and removes everything the glass added. */\n destroy: () => void;\n};\n\nconst DEFAULTS = {\n tone: 'light' as const,\n frost: 0,\n blur: 9,\n ior: 1.5,\n dispersion: 0.14,\n depth: 50,\n bezel: 36,\n wash: 0.35,\n saturation: 1.1,\n shine: 1,\n lightFollow: 0.8,\n liveInterval: 33\n};\n\n// Padding only has to cover the blur's reach, since refraction pulls inward.\nconst PAD_CSS = 24;\nconst MAX_TAPS = 12;\n// GPU buffers and the canvas grow and shrink in steps of this many device px, so\n// a glass that changes size every frame reuses them instead of reallocating.\n// Safari in particular is slow to resize WebGL canvases.\nconst ALLOC_STEP = 128;\nconst BLUR_ROWS_STEP = 64;\nconst SHRINK_AFTER_FRAMES = 30;\nconst stepUp = (n: number, step: number) => Math.ceil(n / step) * step;\nconst LIGHT_DIR: [number, number] = [-0.55, -0.85];\nconst LIGHT_EASE = 0.12;\n\n// One shared pointer listener; every glass reads the last position.\nconst pointer = { x: NaN, y: NaN, users: 0 };\nconst onPointerMove = (event: PointerEvent) => {\n pointer.x = event.clientX;\n pointer.y = event.clientY;\n};\nconst retainPointer = () => {\n if (pointer.users++ === 0) window.addEventListener('pointermove', onPointerMove, { passive: true });\n};\nconst releasePointer = () => {\n if (--pointer.users === 0) window.removeEventListener('pointermove', onPointerMove);\n};\n\nconst compile = (gl: WebGL2RenderingContext, type: number, source: string) => {\n const shader = gl.createShader(type);\n if (!shader) return null;\n gl.shaderSource(shader, source);\n gl.compileShader(shader);\n if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n console.warn('[snell-glass] shader failed to compile:', gl.getShaderInfoLog(shader));\n gl.deleteShader(shader);\n return null;\n }\n return shader;\n};\n\n// Until WebGL draws (or where it can't), a plain CSS glass stands in.\nconst FALLBACK = {\n light: {\n background:\n 'linear-gradient(180deg, rgba(255,255,255,0.55) 0%, rgba(255,255,255,0.25) 50%, rgba(255,255,255,0.1) 100%)',\n boxShadow:\n 'inset 0 1px 0 rgba(255,255,255,0.9), inset 0 0 0 1px rgba(255,255,255,0.55), 0 8px 28px rgba(0,0,0,0.12)'\n },\n dark: {\n background: 'linear-gradient(180deg, rgba(0,0,0,0.5) 0%, rgba(0,0,0,0.25) 50%, rgba(0,0,0,0.15) 100%)',\n boxShadow:\n 'inset 0 1px 0 rgba(255,255,255,0.25), inset 0 0 0 1px rgba(255,255,255,0.14), 0 8px 28px rgba(0,0,0,0.3)'\n }\n};\nconst SHADOW = {\n light: '0 6px 22px rgba(0,0,0,0.12), 0 1px 3px rgba(0,0,0,0.08)',\n dark: '0 6px 22px rgba(0,0,0,0.32), 0 1px 3px rgba(0,0,0,0.2)'\n};\n\n/** Turns an element into liquid glass. Its children stay on top of the glass. */\nexport const createGlass = (element: HTMLElement, initial: GlassOptions = {}): Glass => {\n let options: GlassOptions = { ...initial };\n const reducedMotion =\n typeof window !== 'undefined' && window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;\n\n // --- DOM: a canvas behind the children, and a CSS stand-in until it draws.\n const saved = {\n position: element.style.position,\n isolation: element.style.isolation,\n background: element.style.background,\n boxShadow: element.style.boxShadow,\n backdropFilter: element.style.backdropFilter,\n webkitBackdropFilter: element.style.getPropertyValue('-webkit-backdrop-filter'),\n borderRadius: element.style.borderRadius\n };\n // A radius option shapes the element too, so its shadow and clipping match the glass.\n const applyRadius = () => {\n element.style.borderRadius = options.radius != null ? `${options.radius}px` : saved.borderRadius;\n };\n applyRadius();\n if (getComputedStyle(element).position === 'static') element.style.position = 'relative';\n element.style.isolation = 'isolate';\n const canvas = document.createElement('canvas');\n canvas.setAttribute('aria-hidden', 'true');\n canvas.setAttribute('data-snell-surface', '');\n canvas.style.cssText =\n 'position:absolute;left:0;top:0;width:100%;height:100%;pointer-events:none;z-index:-1;border-radius:inherit;';\n element.prepend(canvas);\n\n const tone = () => options.tone ?? DEFAULTS.tone;\n registerGlassTone(element, tone);\n const applyFallback = (on: boolean) => {\n const t = tone();\n element.style.background = on ? FALLBACK[t].background : 'transparent';\n element.style.boxShadow = on ? FALLBACK[t].boxShadow : SHADOW[t];\n const filter = on ? 'blur(6px) saturate(1.4)' : 'none';\n element.style.backdropFilter = filter;\n element.style.setProperty('-webkit-backdrop-filter', filter);\n };\n applyFallback(true);\n\n let ready = false;\n let running = true;\n let raf = 0;\n\n const restoreDom = () => {\n canvas.remove();\n element.style.position = saved.position;\n element.style.isolation = saved.isolation;\n element.style.background = saved.background;\n element.style.boxShadow = saved.boxShadow;\n element.style.backdropFilter = saved.backdropFilter;\n element.style.setProperty('-webkit-backdrop-filter', saved.webkitBackdropFilter);\n element.style.borderRadius = saved.borderRadius;\n };\n\n const gl = canvas.getContext('webgl2', { alpha: true, premultipliedAlpha: true, antialias: false });\n const fail = (): Glass => ({\n element,\n ready: false,\n set: (next) => {\n options = { ...options, ...next };\n applyRadius();\n applyFallback(true);\n },\n render: () => {},\n destroy: () => {\n running = false;\n restoreDom();\n }\n });\n if (!gl) return fail();\n\n const vs = compile(gl, gl.VERTEX_SHADER, VERT);\n const fs = compile(gl, gl.FRAGMENT_SHADER, FRAG);\n const program = gl.createProgram();\n if (!vs || !fs || !program) return fail();\n gl.attachShader(program, vs);\n gl.attachShader(program, fs);\n gl.linkProgram(program);\n if (!gl.getProgramParameter(program, gl.LINK_STATUS)) return fail();\n\n const backdropTex = gl.createTexture()!;\n const blurA = gl.createTexture()!;\n const blurB = gl.createTexture()!;\n const fboA = gl.createFramebuffer()!;\n const fboB = gl.createFramebuffer()!;\n let capture = document.createElement('canvas');\n let captureCtx = capture.getContext('2d');\n if (!captureCtx) return fail();\n\n const uniform = (name: string) => gl.getUniformLocation(program, name);\n const loc = {\n tex: uniform('uTex'),\n sharp: uniform('uSharp'),\n size: uniform('uSize'),\n buf: uniform('uBufSize'),\n pad: uniform('uPad'),\n canvas: uniform('uCanvas'),\n pass: uniform('uPass'),\n sigma: uniform('uSigma'),\n taps: uniform('uTaps'),\n frost: uniform('uFrost'),\n bezel: uniform('uBezel'),\n radius: uniform('uRadius'),\n depth: uniform('uDepth'),\n dpr: uniform('uDpr'),\n tone: uniform('uTone'),\n light: uniform('uLight'),\n ior: uniform('uIor'),\n dispersion: uniform('uDispersion'),\n saturation: uniform('uSaturation'),\n wash: uniform('uWash'),\n shine: uniform('uShine')\n };\n\n const bindLinear = (unit: number, tex: WebGLTexture) => {\n gl.activeTexture(gl.TEXTURE0 + unit);\n gl.bindTexture(gl.TEXTURE_2D, tex);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n };\n\n const allocTarget = (tex: WebGLTexture, fbo: WebGLFramebuffer, w: number, h: number) => {\n bindLinear(0, tex);\n gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, w, h, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);\n gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);\n gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);\n };\n\n gl.disable(gl.BLEND);\n gl.useProgram(program);\n gl.uniform1i(loc.tex, 0);\n gl.uniform1i(loc.sharp, 1);\n\n let lightX = LIGHT_DIR[0];\n let lightY = LIGHT_DIR[1];\n let bufW = 0;\n let bufH = 0;\n let smallFrames = 0;\n let lastEaseAt = 0;\n let lastSignature = '';\n let lastLiveAt = 0;\n let captureVersion = 0;\n let lastBlurKey = '';\n let lastDrawKey = '';\n let lastTone = '';\n\n const render = () => {\n if (!running || gl.isContextLost() || options.paused) return;\n resetFrameCache();\n const rect = element.getBoundingClientRect();\n if (rect.width < 2 || rect.height < 2 || !captureCtx) return;\n if (rect.bottom <= 0 || rect.right <= 0 || rect.top >= window.innerHeight || rect.left >= window.innerWidth) return;\n\n const o = { ...DEFAULTS, ...options };\n const computed = getComputedStyle(element);\n // Undo the element's own `scale` (a squash while it moves): the glass is sized\n // by its unscaled box and the canvas scales along with the element.\n const [ownSx = 1, ownSy = ownSx] = (element.style.scale || '1').split(/\\s+/).map(Number);\n const sx = Number.isFinite(ownSx) && ownSx > 0 ? ownSx : 1;\n const sy = Number.isFinite(ownSy) && ownSy > 0 ? ownSy : 1;\n const [originX = 0, originY = 0] = computed.transformOrigin.split(' ').map(parseFloat);\n const cssW = rect.width / sx;\n const cssH = rect.height / sy;\n const boxLeft = rect.left - originX * (1 - sx);\n const boxTop = rect.top - originY * (1 - sy);\n const dpr = Math.min(window.devicePixelRatio || 1, 2);\n const glassW = Math.max(1, Math.round(cssW * dpr));\n const glassH = Math.max(1, Math.round(cssH * dpr));\n const scaleX = glassW / cssW;\n const scaleY = glassH / cssH;\n const frost = Math.min(1, Math.max(0, o.frost));\n const padCss = Math.max(PAD_CSS, Math.ceil(2 * o.blur) + 4);\n const padX = Math.round(padCss * scaleX);\n const padY = Math.round(padCss * scaleY);\n const needW = glassW + padX * 2;\n const needH = glassH + padY * 2;\n\n // Grow at once; shrink only after the glass has stayed small for a while.\n const tooSmall = needW > bufW || needH > bufH || canvas.width < glassW || canvas.height < glassH;\n const tooBig = needW < bufW / 2 || needH < bufH / 2;\n smallFrames = tooBig ? smallFrames + 1 : 0;\n if (tooSmall || smallFrames > SHRINK_AFTER_FRAMES) {\n // A growing glass gets headroom, so it reallocates a few times, not every frame.\n const maxW = window.innerWidth * dpr + padX * 2;\n const maxH = window.innerHeight * dpr + padY * 2;\n const roomW = tooSmall && bufW ? Math.min(maxW, needW * 2.2) : needW;\n const roomH = tooSmall && bufH ? Math.min(maxH, needH * 2.2) : needH;\n bufW = stepUp(Math.max(needW, roomW), ALLOC_STEP);\n bufH = stepUp(Math.max(needH, roomH), ALLOC_STEP);\n allocTarget(blurA, fboA, bufW, bufH);\n allocTarget(blurB, fboB, bufW, bufH);\n smallFrames = 0;\n lastBlurKey = '';\n lastSignature = '';\n // The canvas only covers the glass, anchored top-left; the shader draws the shape.\n canvas.width = bufW - padX * 2;\n canvas.height = bufH - padY * 2;\n canvas.style.width = `${canvas.width / dpr}px`;\n canvas.style.height = `${canvas.height / dpr}px`;\n canvas.style.borderRadius = '0';\n lastDrawKey = '';\n }\n\n // Mostly-frosted glass is mostly blur: half resolution looks the same at a\n // quarter of the repaint and upload cost.\n const captureScale = frost > 0.5 ? 0.5 : 1;\n const capW = Math.max(1, Math.round(bufW * captureScale));\n const capH = Math.max(1, Math.round(bufH * captureScale));\n if (capture.width !== capW || capture.height !== capH) {\n capture.width = capW;\n capture.height = capH;\n }\n // Capture the whole allocated area, not just the glass: while the glass grows\n // inside it, the capture stays valid.\n const padCssX = padX / scaleX;\n const padCssY = padY / scaleY;\n const scope = o.backdrop ?? document.body;\n const backdrop = collectBackdrop(\n element,\n scope,\n o.background,\n boxLeft - padCssX,\n boxTop - padCssY,\n bufW / scaleX,\n bufH / scaleY\n );\n const signature = `${capW}x${capH}|${bufW}x${bufH}|${padX},${padY}|${backdrop.signature}`;\n const now = performance.now();\n const recapture =\n signature !== lastSignature || (backdrop.live && now - lastLiveAt >= o.liveInterval);\n if (recapture) {\n paintBackdrop(captureCtx, backdrop, scaleX * captureScale, scaleY * captureScale);\n gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);\n bindLinear(0, backdropTex);\n try {\n gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, capture);\n } catch (error) {\n // A tainted source slipped through: start over with a clean canvas.\n console.warn('[snell-glass] backdrop upload failed:', error);\n capture = document.createElement('canvas');\n captureCtx = capture.getContext('2d');\n lastSignature = '';\n return;\n }\n lastSignature = signature;\n if (backdrop.live) lastLiveAt = now;\n captureVersion++;\n }\n\n // Ease the light toward the pointer, keeping some of the top-left bias.\n const ease = now - lastEaseAt > 8;\n if (ease) lastEaseAt = now;\n const follow = reducedMotion ? 0 : Math.min(1, Math.max(0, o.lightFollow));\n let targetX = LIGHT_DIR[0];\n let targetY = LIGHT_DIR[1];\n if (follow > 0 && Number.isFinite(pointer.x)) {\n const dx = pointer.x - (boxLeft + cssW / 2);\n const dy = pointer.y - (boxTop + cssH / 2);\n const len = Math.hypot(dx, dy);\n if (len > 1) {\n targetX = LIGHT_DIR[0] * (1 - follow) + (dx / len) * follow;\n targetY = LIGHT_DIR[1] * (1 - follow) + (dy / len) * follow;\n }\n }\n if (ease) {\n lightX += (targetX - lightX) * LIGHT_EASE;\n lightY += (targetY - lightY) * LIGHT_EASE;\n }\n if (Math.hypot(lightX, lightY) < 0.05) lightY -= 0.1;\n\n const sigmaPx = o.blur * dpr;\n const taps = Math.max(3, Math.min(MAX_TAPS, Math.ceil((2 * sigmaPx) / 1.25)));\n const blurRows = Math.min(bufH - padY * 2, stepUp(glassH, BLUR_ROWS_STEP));\n const blurKey = `${captureVersion}|${bufW}x${bufH}|${padX},${padY}|${glassW}|${blurRows}|${sigmaPx.toFixed(3)}|${taps}`;\n // Computed border-radius can stay a percentage (50% for a circle): resolve it\n // against the box. Elliptical radii (\"40px 20px\") use the first value.\n const cssRadius = computed.borderTopLeftRadius.split(' ')[0] ?? '';\n const cssRadiusPx = cssRadius.endsWith('%')\n ? (parseFloat(cssRadius) / 100) * Math.min(cssW, cssH)\n : parseFloat(cssRadius);\n const cornerCss = o.radius ?? (Number.isFinite(cssRadiusPx) && cssRadiusPx > 0 ? cssRadiusPx : 0);\n const drawKey = [\n blurKey,\n glassW,\n glassH,\n frost.toFixed(4),\n lightX.toFixed(3),\n lightY.toFixed(3),\n cornerCss.toFixed(2),\n o.tone,\n o.ior,\n o.dispersion,\n o.depth,\n o.bezel,\n o.wash,\n o.saturation,\n o.shine\n ].join('|');\n if (o.tone !== lastTone) {\n lastTone = o.tone;\n if (ready) applyFallback(false);\n }\n if (drawKey === lastDrawKey) return;\n const reblur = frost > 0 && blurKey !== lastBlurKey;\n\n gl.useProgram(program);\n gl.uniform2f(loc.size, glassW, glassH);\n gl.uniform2f(loc.buf, bufW, bufH);\n gl.uniform2f(loc.pad, padX, padY);\n gl.uniform2f(loc.canvas, canvas.width, canvas.height);\n gl.uniform1f(loc.sigma, sigmaPx);\n gl.uniform1i(loc.taps, taps);\n gl.uniform1f(loc.frost, frost);\n gl.uniform1f(loc.bezel, o.bezel * dpr);\n gl.uniform1f(loc.radius, cornerCss * dpr);\n gl.uniform1f(loc.depth, o.depth * dpr);\n gl.uniform1f(loc.dpr, dpr);\n gl.uniform1f(loc.tone, o.tone === 'dark' ? 1 : 0);\n gl.uniform2f(loc.light, lightX, lightY);\n gl.uniform1f(loc.ior, Math.max(1, o.ior));\n gl.uniform1f(loc.dispersion, o.dispersion);\n gl.uniform1f(loc.saturation, o.saturation);\n gl.uniform1f(loc.wash, o.wash);\n gl.uniform1f(loc.shine, o.shine);\n\n // The final pass only reads the blur inside the glass (refraction pulls\n // inward), so the passes are scissored to the glass plus the blur's reach.\n if (reblur) {\n const reach = Math.min(padY, Math.ceil(2 * sigmaPx) + 2);\n const rowsBottom = bufH - padY - blurRows;\n gl.viewport(0, 0, bufW, bufH);\n gl.enable(gl.SCISSOR_TEST);\n gl.bindFramebuffer(gl.FRAMEBUFFER, fboA);\n gl.scissor(padX - 2, Math.max(0, rowsBottom - reach), glassW + 4, blurRows + reach * 2);\n gl.uniform1f(loc.pass, 0);\n bindLinear(0, backdropTex);\n gl.drawArrays(gl.TRIANGLES, 0, 3);\n gl.bindFramebuffer(gl.FRAMEBUFFER, fboB);\n gl.scissor(padX - 2, Math.max(0, rowsBottom - 2), glassW + 4, blurRows + 4);\n gl.uniform1f(loc.pass, 1);\n bindLinear(0, blurA);\n gl.drawArrays(gl.TRIANGLES, 0, 3);\n gl.disable(gl.SCISSOR_TEST);\n lastBlurKey = blurKey;\n }\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n gl.viewport(0, 0, canvas.width, canvas.height);\n gl.uniform1f(loc.pass, 2);\n bindLinear(0, blurB);\n bindLinear(1, backdropTex);\n gl.drawArrays(gl.TRIANGLES, 0, 3);\n lastDrawKey = drawKey;\n\n if (!ready) {\n ready = true;\n applyFallback(false);\n }\n };\n\n const frame = () => {\n if (!running) return;\n raf = requestAnimationFrame(frame);\n render();\n };\n\n // A lost context (GPU reset, too many contexts on the page): show the CSS glass.\n const onLost = () => {\n ready = false;\n applyFallback(true);\n };\n canvas.addEventListener('webglcontextlost', onLost);\n\n retainScene();\n retainPointer();\n raf = requestAnimationFrame(frame);\n\n const glass: Glass = {\n element,\n get ready() {\n return ready;\n },\n set: (next) => {\n const radiusChanged = 'radius' in next && next.radius !== options.radius;\n options = { ...options, ...next };\n if (radiusChanged) applyRadius();\n },\n render,\n destroy: () => {\n if (!running) return;\n running = false;\n cancelAnimationFrame(raf);\n canvas.removeEventListener('webglcontextlost', onLost);\n releaseScene();\n releasePointer();\n gl.deleteProgram(program);\n gl.deleteShader(vs);\n gl.deleteShader(fs);\n gl.deleteTexture(backdropTex);\n gl.deleteTexture(blurA);\n gl.deleteTexture(blurB);\n gl.deleteFramebuffer(fboA);\n gl.deleteFramebuffer(fboB);\n restoreDom();\n }\n };\n return glass;\n};\n"],"mappings":";AAuCA,IAAM,WAAW,oBAAI,IAAa;AAG3B,IAAM,kBAAkB,CAAC,YAAqB;AACnD,WAAS,IAAI,OAAO;AACpB,QAAM,QAAQ;AACd,SAAO,MAAM;AACX,aAAS,OAAO,OAAO;AACvB,UAAM,QAAQ;AAAA,EAChB;AACF;AAIO,IAAM,aAAa,CAAC,MAAe,MAAc,KAAa,OAAe,WAClF,KAAK,QAAQ,QAAQ,KAAK,OAAO,SAAS,KAAK,SAAS,OAAO,KAAK,MAAM;AAG5E,IAAM,IAAI,CAAC,MAAc,KAAK,MAAM,IAAI,CAAC;AAGzC,IAAM,gBAAgB,CAAC,QAA0B;AAE/C,MAAI,IAAI,gBAAgB,eAAe,IAAI,gBAAgB,kBAAmB,QAAO;AACrF,QAAM,MAAM,IAAI,cAAc,IAAI;AAClC,MAAI,IAAI,WAAW,OAAO,KAAK,IAAI,WAAW,OAAO,EAAG,QAAO;AAC/D,MAAI;AACF,WAAO,IAAI,IAAI,KAAK,OAAO,SAAS,IAAI,EAAE,WAAW,OAAO,SAAS;AAAA,EACvE,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAgBA,IAAM,aAAwB,EAAE,SAAS,GAAG,YAAY,GAAG,GAAG,GAAG,MAAM,OAAO,OAAO,GAAG,MAAM,OAAO,KAAK,CAAC,GAAG,GAAG,GAAG,CAAC,EAAE;AAGvH,IAAM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.restore();
|
|
326
326
|
}
|
|
327
327
|
};
|
|
328
|
+
var glassTones = /* @__PURE__ */ new WeakMap();
|
|
329
|
+
var registerGlassTone = (element, tone) => glassTones.set(element, tone);
|
|
328
330
|
var scene = {
|
|
329
331
|
entries: [],
|
|
330
332
|
bg: "#ffffff",
|
|
@@ -341,10 +343,41 @@ var rebuildScene = () => {
|
|
|
341
343
|
const selector = [BASE_SELECTOR, ...[...painters].map((p) => p.selector)].join(", ");
|
|
342
344
|
const behind = [];
|
|
343
345
|
const front = [];
|
|
346
|
+
const textEntries = /* @__PURE__ */ new Map();
|
|
344
347
|
document.querySelectorAll(selector).forEach((node) => {
|
|
345
348
|
if (node.closest("[data-glass-ignore]")) return;
|
|
346
|
-
if (node instanceof HTMLCanvasElement && node.hasAttribute("data-snell-surface"))
|
|
347
|
-
|
|
349
|
+
if (node instanceof HTMLCanvasElement && node.hasAttribute("data-snell-surface")) {
|
|
350
|
+
const host = node.parentElement;
|
|
351
|
+
if (host && !host.closest("[data-glass-ignore]")) {
|
|
352
|
+
const isBehind2 = stackSide(host) ?? false;
|
|
353
|
+
const list = isBehind2 ? behind : front;
|
|
354
|
+
const first = list.findIndex((e) => host.contains(e.node));
|
|
355
|
+
const standIn = { node: host, kind: "glass", clips: clipsFrom(host.parentElement), behind: isBehind2 };
|
|
356
|
+
if (first < 0) list.push(standIn);
|
|
357
|
+
else list.splice(first, 0, standIn);
|
|
358
|
+
}
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
const textHost = node.parentElement?.closest("[data-glass-text]");
|
|
362
|
+
if (textHost) {
|
|
363
|
+
const host = textEntries.get(textHost);
|
|
364
|
+
if (!host) return;
|
|
365
|
+
const nested = [];
|
|
366
|
+
const clips2 = clipsFrom(node.parentElement);
|
|
367
|
+
const isBehind2 = host.entry.behind;
|
|
368
|
+
if (node instanceof HTMLImageElement) nested.push({ node, kind: "image", clips: clips2, behind: isBehind2 });
|
|
369
|
+
else if (node instanceof HTMLCanvasElement) nested.push({ node, kind: "canvas", clips: clips2, behind: isBehind2 });
|
|
370
|
+
else if (node instanceof HTMLVideoElement) nested.push({ node, kind: "video", clips: clips2, behind: isBehind2 });
|
|
371
|
+
else if (node.hasAttribute("data-glass-box")) {
|
|
372
|
+
const box = boxStyleOf(node);
|
|
373
|
+
if (box) nested.push({ node, kind: "box", clips: clips2, behind: isBehind2, box });
|
|
374
|
+
}
|
|
375
|
+
for (const item of nested) {
|
|
376
|
+
if (item.kind !== "box") item.radius = parseFloat(getComputedStyle(node).borderTopLeftRadius) || 0;
|
|
377
|
+
host.list.splice(host.list.indexOf(host.entry), 0, item);
|
|
378
|
+
}
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
348
381
|
let entry = null;
|
|
349
382
|
const clips = clipsFrom(node.parentElement);
|
|
350
383
|
const isBehind = stackSide(node) ?? false;
|
|
@@ -363,7 +396,11 @@ var rebuildScene = () => {
|
|
|
363
396
|
if (entry && (entry.kind === "image" || entry.kind === "canvas" || entry.kind === "video")) {
|
|
364
397
|
entry.radius = parseFloat(getComputedStyle(node).borderTopLeftRadius) || 0;
|
|
365
398
|
}
|
|
366
|
-
if (entry)
|
|
399
|
+
if (entry) {
|
|
400
|
+
const list = isBehind ? behind : front;
|
|
401
|
+
list.push(entry);
|
|
402
|
+
if (entry.kind === "text") textEntries.set(node, { list, entry });
|
|
403
|
+
}
|
|
367
404
|
});
|
|
368
405
|
scene.entries = behind.concat(front);
|
|
369
406
|
const bg = getComputedStyle(document.body).backgroundColor;
|
|
@@ -440,6 +477,11 @@ var collectBackdrop = (glass, scope, background, left, top, width, height) => {
|
|
|
440
477
|
if (entry.kind === "video" && node.readyState < 2) return;
|
|
441
478
|
const chain = chainOf(node);
|
|
442
479
|
if (chain.opacity <= 0.01 || chain.warp) return;
|
|
480
|
+
if (entry.kind === "glass") {
|
|
481
|
+
const ownZ = chainOf(glass).z;
|
|
482
|
+
const later = glass.compareDocumentPosition(node) & Node.DOCUMENT_POSITION_FOLLOWING;
|
|
483
|
+
if (chain.z > ownZ || chain.z === ownZ && later && !node.contains(glass)) return;
|
|
484
|
+
}
|
|
443
485
|
items.push({ entry, rect, chain, order });
|
|
444
486
|
});
|
|
445
487
|
items.sort((a, b) => Number(b.entry.behind) - Number(a.entry.behind) || a.chain.z - b.chain.z || a.order - b.order);
|
|
@@ -453,6 +495,7 @@ var collectBackdrop = (glass, scope, background, left, top, width, height) => {
|
|
|
453
495
|
parts.push(Math.round(chain.opacity * 1e3), Math.round(chain.brightness * 1e3), chain.z);
|
|
454
496
|
if (entry.kind === "image") parts.push(node.currentSrc || node.src);
|
|
455
497
|
if (entry.kind === "box") parts.push(entry.box.key);
|
|
498
|
+
if (entry.kind === "glass") parts.push(glassTones.get(node)?.() ?? "light", getComputedStyle(node).borderTopLeftRadius);
|
|
456
499
|
if (entry.kind === "text") parts.push(node.textContent?.length ?? 0);
|
|
457
500
|
if ((entry.kind === "text" || entry.kind === "box") && animatingInside(node)) parts.push("anim", frameStamp());
|
|
458
501
|
if (entry.painter?.signature) parts.push(entry.painter.signature(node));
|
|
@@ -474,6 +517,40 @@ var clipOwnRadius = (ctx, node, frame, at, radius) => {
|
|
|
474
517
|
roundRect(ctx, at.x, at.y, at.w, at.h, radiusIn(node, frame, radius));
|
|
475
518
|
ctx.clip();
|
|
476
519
|
};
|
|
520
|
+
var paintGlassStandIn = (ctx, node, rect) => {
|
|
521
|
+
const frame = frameOf(node, rect);
|
|
522
|
+
const at = inFrame(ctx, frame);
|
|
523
|
+
const css = getComputedStyle(node).borderTopLeftRadius.split(" ")[0] ?? "";
|
|
524
|
+
const w = node.offsetWidth || rect.width;
|
|
525
|
+
const h = node.offsetHeight || rect.height;
|
|
526
|
+
const cssPx = css.endsWith("%") ? parseFloat(css) / 100 * Math.min(w, h) : parseFloat(css) || 0;
|
|
527
|
+
const r = radiusIn(node, frame, cssPx);
|
|
528
|
+
const dark = glassTones.get(node)?.() === "dark";
|
|
529
|
+
const shape = () => {
|
|
530
|
+
ctx.beginPath();
|
|
531
|
+
roundRect(ctx, at.x, at.y, at.w, at.h, r);
|
|
532
|
+
};
|
|
533
|
+
ctx.save();
|
|
534
|
+
shape();
|
|
535
|
+
ctx.shadowColor = dark ? "rgba(0, 0, 0, 0.35)" : "rgba(20, 20, 20, 0.16)";
|
|
536
|
+
ctx.shadowBlur = 18;
|
|
537
|
+
ctx.shadowOffsetY = 6;
|
|
538
|
+
const fill = ctx.createLinearGradient(0, at.y, 0, at.y + at.h);
|
|
539
|
+
if (dark) {
|
|
540
|
+
fill.addColorStop(0, "rgba(58, 58, 62, 0.82)");
|
|
541
|
+
fill.addColorStop(1, "rgba(28, 28, 32, 0.88)");
|
|
542
|
+
} else {
|
|
543
|
+
fill.addColorStop(0, "rgba(255, 255, 255, 0.86)");
|
|
544
|
+
fill.addColorStop(1, "rgba(246, 246, 248, 0.74)");
|
|
545
|
+
}
|
|
546
|
+
ctx.fillStyle = fill;
|
|
547
|
+
ctx.fill();
|
|
548
|
+
ctx.restore();
|
|
549
|
+
shape();
|
|
550
|
+
ctx.lineWidth = 1;
|
|
551
|
+
ctx.strokeStyle = dark ? "rgba(255, 255, 255, 0.16)" : "rgba(255, 255, 255, 0.95)";
|
|
552
|
+
ctx.stroke();
|
|
553
|
+
};
|
|
477
554
|
var paintBackdrop = (ctx, backdrop, scaleX, scaleY) => {
|
|
478
555
|
const { left, top, width, height } = backdrop.view;
|
|
479
556
|
ctx.setTransform(scaleX, 0, 0, scaleY, -left * scaleX, -top * scaleY);
|
|
@@ -504,6 +581,8 @@ var paintBackdrop = (ctx, backdrop, scaleX, scaleY) => {
|
|
|
504
581
|
ctx.fillStyle = gradient;
|
|
505
582
|
ctx.fill();
|
|
506
583
|
}
|
|
584
|
+
} else if (kind === "glass") {
|
|
585
|
+
paintGlassStandIn(ctx, node, rect);
|
|
507
586
|
} else if (kind === "text") {
|
|
508
587
|
paintText(ctx, node, view);
|
|
509
588
|
} else if (kind === "canvas") {
|
|
@@ -774,6 +853,7 @@ var createGlass = (element, initial = {}) => {
|
|
|
774
853
|
canvas.style.cssText = "position:absolute;left:0;top:0;width:100%;height:100%;pointer-events:none;z-index:-1;border-radius:inherit;";
|
|
775
854
|
element.prepend(canvas);
|
|
776
855
|
const tone = () => options.tone ?? DEFAULTS.tone;
|
|
856
|
+
registerGlassTone(element, tone);
|
|
777
857
|
const applyFallback = (on) => {
|
|
778
858
|
const t = tone();
|
|
779
859
|
element.style.background = on ? FALLBACK[t].background : "transparent";
|