@glass-sdk/liquid-glass 0.0.1 → 0.0.2

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.
Files changed (109) hide show
  1. package/README.md +133 -494
  2. package/dist/core/concentric.js +86 -0
  3. package/dist/core/materials.js +41 -0
  4. package/dist/core/morph-path.js +206 -0
  5. package/dist/core/optics.js +7 -0
  6. package/dist/core/progressive.js +35 -0
  7. package/dist/{concentric-COCiG9DQ.js → core/shape.js} +1 -85
  8. package/dist/core/spring.js +78 -0
  9. package/dist/core/union.js +117 -0
  10. package/dist/core.js +6 -9
  11. package/dist/dom/compose-layers.js +54 -0
  12. package/dist/dom/compound-field.js +23 -0
  13. package/dist/dom/control-motion.js +101 -0
  14. package/dist/dom/engine.js +7 -0
  15. package/dist/dom/exit-handoff.js +14 -0
  16. package/dist/dom/filter-bounds.js +87 -0
  17. package/dist/dom/filter-budget.js +45 -0
  18. package/dist/dom/filter-groups.js +38 -0
  19. package/dist/dom/filter-paint-root.js +41 -0
  20. package/dist/dom/filter-patch.js +129 -0
  21. package/dist/dom/filter-reach.js +36 -0
  22. package/dist/dom/filter-stages.js +7 -0
  23. package/dist/dom/fixed-shape.js +20 -0
  24. package/dist/dom/foreground.js +36 -0
  25. package/dist/dom/interaction.js +129 -0
  26. package/dist/dom/lens-layers.js +163 -0
  27. package/dist/dom/map-blend.js +8 -0
  28. package/dist/dom/map-encoder.js +47 -0
  29. package/dist/dom/map-encoder.worker.js +16 -0
  30. package/dist/dom/map-encoding.js +17 -0
  31. package/dist/dom/map-image.js +34 -0
  32. package/dist/dom/map-store.js +189 -0
  33. package/dist/dom/maps.js +131 -0
  34. package/dist/dom/material-graph.js +52 -0
  35. package/dist/dom/morph.js +296 -0
  36. package/dist/dom/page-zoom.js +46 -0
  37. package/dist/dom/png.js +105 -0
  38. package/dist/dom/progressive.js +299 -0
  39. package/dist/dom/renderer.js +6 -0
  40. package/dist/dom/sampling-bounds.js +22 -0
  41. package/dist/dom/selection.js +106 -0
  42. package/dist/dom/shape-layout.js +199 -0
  43. package/dist/dom/shared-backdrop.js +41 -0
  44. package/dist/dom/ticker.js +103 -0
  45. package/dist/dom/warm.js +108 -0
  46. package/dist/dom.js +694 -2
  47. package/dist/gpu/geometry.js +9 -0
  48. package/dist/gpu/maps.js +8 -0
  49. package/dist/gpu/planes.js +4 -0
  50. package/dist/gpu.js +213 -2
  51. package/dist/index.js +10 -932
  52. package/dist/react/button.js +23 -0
  53. package/dist/react/control-thumb.js +50 -0
  54. package/dist/react/menu.js +159 -0
  55. package/dist/react/merged-ref.js +18 -0
  56. package/dist/react/progressive.js +73 -0
  57. package/dist/react/scene.js +122 -0
  58. package/dist/react/shape.js +93 -0
  59. package/dist/react/surface.js +69 -0
  60. package/dist/react/tabs.js +94 -0
  61. package/dist/react/toolbar.js +145 -0
  62. package/dist/react/value-control-motion.js +9 -0
  63. package/dist/react/value-controls.js +176 -0
  64. package/dist/styles.css +19 -0
  65. package/dist/types/core/optics.d.ts +0 -1
  66. package/dist/types/core/spring.d.ts +1 -1
  67. package/dist/types/dom/compose-layers.d.ts +15 -0
  68. package/dist/types/dom/compound-field.d.ts +35 -0
  69. package/dist/types/dom/engine.d.ts +9 -0
  70. package/dist/types/dom/exit-handoff.d.ts +7 -0
  71. package/dist/types/dom/filter-bounds.d.ts +1 -1
  72. package/dist/types/dom/filter-budget.d.ts +20 -0
  73. package/dist/types/dom/filter-groups.d.ts +25 -0
  74. package/dist/types/dom/filter-paint-root.d.ts +9 -0
  75. package/dist/types/dom/filter-patch.d.ts +3 -8
  76. package/dist/types/dom/filter-reach.d.ts +23 -0
  77. package/dist/types/dom/filter-stages.d.ts +5 -0
  78. package/dist/types/dom/index.d.ts +3 -0
  79. package/dist/types/dom/lens-layers.d.ts +68 -0
  80. package/dist/types/dom/map-blend.d.ts +22 -0
  81. package/dist/types/dom/map-encoding.d.ts +1 -1
  82. package/dist/types/dom/map-image.d.ts +5 -2
  83. package/dist/types/dom/maps.d.ts +5 -5
  84. package/dist/types/dom/material-graph.d.ts +22 -0
  85. package/dist/types/dom/morph.d.ts +8 -0
  86. package/dist/types/dom/page-zoom.d.ts +18 -0
  87. package/dist/types/dom/png.d.ts +2 -0
  88. package/dist/types/dom/progressive.d.ts +29 -1
  89. package/dist/types/dom/renderer.d.ts +4 -0
  90. package/dist/types/dom/sampling-bounds.d.ts +10 -0
  91. package/dist/types/dom/shared-backdrop.d.ts +19 -0
  92. package/dist/types/dom/warm.d.ts +4 -1
  93. package/dist/types/gpu/geometry.d.ts +17 -0
  94. package/dist/types/gpu/index.d.ts +4 -16
  95. package/dist/types/gpu/planes.d.ts +2 -0
  96. package/dist/types/react/button.d.ts +11 -0
  97. package/dist/types/react/index.d.ts +14 -149
  98. package/dist/types/react/menu.d.ts +29 -0
  99. package/dist/types/react/progressive.d.ts +15 -0
  100. package/dist/types/react/scene.d.ts +35 -0
  101. package/dist/types/react/surface.d.ts +35 -0
  102. package/dist/types/react/tabs.d.ts +29 -0
  103. package/dist/types/react/toolbar.d.ts +21 -0
  104. package/package.json +1 -1
  105. package/dist/dom-CKc8vDTR.js +0 -2532
  106. package/dist/gpu-Co5Y89mh.js +0 -244
  107. package/dist/map-encoder.worker-DO1drw0Y.js +0 -16
  108. package/dist/materials-DVPgteZ9.js +0 -234
  109. package/dist/types/dom/progressive-maps.d.ts +0 -6
@@ -0,0 +1,145 @@
1
+ "use client";
2
+ import { GlassShape as e } from "./shape.js";
3
+ import { GlassSurface as t } from "./surface.js";
4
+ import { useMergedRef as n } from "./merged-ref.js";
5
+ import { Children as r, Fragment as i, cloneElement as a, isValidElement as o, useCallback as s, useEffect as c, useLayoutEffect as l, useRef as u, useState as d } from "react";
6
+ import { jsx as f } from "react/jsx-runtime";
7
+ import { Toolbar as p } from "@base-ui/react/toolbar";
8
+ //#region src/react/toolbar.tsx
9
+ function m({ material: e, appearance: t, radius: n = "capsule", refraction: s, tint: l, interactive: m = !0, motion: _, className: v = "", style: y, children: x, ...S }) {
10
+ let C = u(!1);
11
+ c(() => {
12
+ C.current = !0;
13
+ }, []);
14
+ let w = u(/* @__PURE__ */ new Map()), T = u(/* @__PURE__ */ new Map()), [E, D] = d(/* @__PURE__ */ new Map()), O = [], k = (e, t = "") => {
15
+ r.forEach(r.toArray(e), (e) => {
16
+ o(e) && e.type === i ? k(e.props.children, `${t}${e.key}/`) : O.push(o(e) ? a(e, { key: `${t}${e.key}` }) : e);
17
+ });
18
+ };
19
+ k(x);
20
+ let A = [], j = /* @__PURE__ */ new Map(), M = [], N = (r, i, a, o) => /* @__PURE__ */ f(g, {
21
+ index: i,
22
+ settled: C,
23
+ material: e,
24
+ appearance: t,
25
+ radius: n,
26
+ refraction: s,
27
+ tint: l,
28
+ interactive: m,
29
+ motion: _,
30
+ orientation: S.orientation ?? "horizontal",
31
+ ghost: o,
32
+ register: (e) => {
33
+ e ? w.current.set(r, e) : w.current.delete(r);
34
+ },
35
+ onExited: () => D((e) => {
36
+ if (!e.has(r)) return e;
37
+ let t = new Map(e);
38
+ return t.delete(r), t;
39
+ }),
40
+ children: a
41
+ }, r), P = () => {
42
+ if (!M.length) return;
43
+ let e = `cluster-${j.size}`;
44
+ j.set(e, M), A.push(N(e, j.size - 1, M)), M = [];
45
+ };
46
+ for (let e of O) o(e) && e.type === b ? (P(), A.push(e)) : M.push(e);
47
+ P();
48
+ let F = h(j, E, T, w, S.orientation !== "vertical");
49
+ (F.size !== E.size || [...F.keys()].some((e) => !E.has(e))) && queueMicrotask(() => D(F));
50
+ for (let [e, t] of F) A.push(N(e, j.size, t.children, t.box));
51
+ return /* @__PURE__ */ f(p.Root, {
52
+ "aria-label": "Toolbar",
53
+ ...S,
54
+ style: y,
55
+ className: `lg-toolbar ${v}`,
56
+ "data-segmented": A.length > 1 ? "" : void 0,
57
+ children: A
58
+ });
59
+ }
60
+ function h(e, t, n, r, i) {
61
+ let a = new Map(t);
62
+ for (let t of a.keys()) e.has(t) && a.delete(t);
63
+ if (i) for (let [t, i] of n.current) {
64
+ let n = r.current.get(t);
65
+ if (e.has(t) || a.has(t) || !n) continue;
66
+ let o = n.offsetParent;
67
+ a.set(t, {
68
+ children: i,
69
+ box: {
70
+ left: n.offsetLeft - (o?.clientLeft ?? 0),
71
+ top: n.offsetTop - (o?.clientTop ?? 0),
72
+ width: n.offsetWidth,
73
+ height: n.offsetHeight
74
+ }
75
+ });
76
+ }
77
+ return n.current = e, a;
78
+ }
79
+ function g({ index: e, settled: r, orientation: i, children: a, ghost: o, register: c, onExited: p, ...m }) {
80
+ let [h] = d(() => r.current && e > 0), g = s(() => {
81
+ let e = _.current?.previousElementSibling ?? null;
82
+ for (; e && (!e.classList.contains("lg-toolbar-cluster") || e.hasAttribute("data-ending-style"));) e = e.previousElementSibling;
83
+ return e;
84
+ }, []), _ = u(null), v = u({
85
+ register: c,
86
+ onExited: p
87
+ });
88
+ l(() => {
89
+ v.current = {
90
+ register: c,
91
+ onExited: p
92
+ };
93
+ });
94
+ let y = s((e) => {
95
+ if (v.current.register(e), !e) return;
96
+ let t = () => v.current.onExited();
97
+ return e.addEventListener("glass:exited", t), () => {
98
+ e.removeEventListener("glass:exited", t), v.current.register(null);
99
+ };
100
+ }, []);
101
+ return /* @__PURE__ */ f(t, {
102
+ ...m,
103
+ ref: n(_, y),
104
+ fluid: !0,
105
+ morphFrom: e > 0 ? g : void 0,
106
+ morphEnter: h,
107
+ morph: "detach",
108
+ neck: o ? 0 : void 0,
109
+ className: "lg-toolbar-cluster",
110
+ "data-orientation": i,
111
+ "data-ending-style": o ? "" : void 0,
112
+ "aria-hidden": o ? !0 : void 0,
113
+ inert: o ? !0 : void 0,
114
+ style: o ? {
115
+ position: "absolute",
116
+ left: o.left,
117
+ top: o.top,
118
+ width: o.width,
119
+ height: o.height,
120
+ pointerEvents: "none"
121
+ } : void 0,
122
+ children: a
123
+ });
124
+ }
125
+ function _({ className: t, size: n = "icon", ...r }) {
126
+ return /* @__PURE__ */ f(e, {
127
+ radius: n === "icon" ? "circle" : "capsule",
128
+ render: /* @__PURE__ */ f(p.Button, {
129
+ ...r,
130
+ "data-size": n,
131
+ className: (e) => `lg-toolbar-button ${typeof t == "function" ? t(e) : t ?? ""}`
132
+ })
133
+ });
134
+ }
135
+ var v = p.Link, y = p.Group;
136
+ function b({ sizing: e = "flexible", className: t = "", ...n }) {
137
+ return /* @__PURE__ */ f("span", {
138
+ ...n,
139
+ "aria-hidden": "true",
140
+ className: `lg-toolbar-spacer ${t}`,
141
+ "data-sizing": e
142
+ });
143
+ }
144
+ //#endregion
145
+ export { m as GlassToolbar, _ as GlassToolbarButton, y as GlassToolbarGroup, v as GlassToolbarLink, b as GlassToolbarSpacer };
@@ -0,0 +1,9 @@
1
+ "use client";
2
+ //#region src/react/value-control-motion.ts
3
+ function e(e, t) {
4
+ if (!e.oppositeHalf) return t >= e.left + e.width / 2 !== e.rtl;
5
+ let n = (t - e.x) * (e.rtl ? -1 : 1);
6
+ return e.start === 0 ? n > e.width * .4 : n >= -e.width * .4;
7
+ }
8
+ //#endregion
9
+ export { e as switchDragState };
@@ -0,0 +1,176 @@
1
+ "use client";
2
+ import { GlassShape as e } from "./shape.js";
3
+ import { useGlassForeground as t } from "./scene.js";
4
+ import { useMergedRef as n } from "./merged-ref.js";
5
+ import { switchDragState as r } from "./value-control-motion.js";
6
+ import { ControlThumb as i } from "./control-thumb.js";
7
+ import { useEffect as a, useRef as o, useState as s } from "react";
8
+ import { jsx as c, jsxs as l } from "react/jsx-runtime";
9
+ import { Slider as u } from "@base-ui/react/slider";
10
+ import { Switch as d } from "@base-ui/react/switch";
11
+ //#region src/react/value-controls.tsx
12
+ function f({ material: r, appearance: o, tint: d, refraction: f, radius: p = "capsule", motion: m, interactive: h = !0, className: g = "", style: _, ticks: v = !1, min: y = 0, max: b = 100, step: x = .1, thumbProps: S, "aria-label": C, "aria-labelledby": w, ...T }) {
13
+ if (!Number.isFinite(y) || !Number.isFinite(b) || b <= y || !Number.isFinite(b - y) || !Number.isFinite(x) || x <= 0) throw RangeError("GlassSlider requires finite min < max and a positive finite step.");
14
+ let E = (b - y) / x;
15
+ if (v && (E < 1 || E > 100 || Math.abs(E - Math.round(E)) > 1e-7)) throw RangeError("Ticked sliders require 1–100 evenly divided intervals.");
16
+ let D = t(), O = n(T.ref, D), { className: k = "", ...A } = S ?? {}, [j, M] = s(!1);
17
+ return a(() => {
18
+ if (!j) return;
19
+ let e = () => M(!1);
20
+ return window.addEventListener("pointerup", e), window.addEventListener("pointercancel", e), window.addEventListener("blur", e), () => {
21
+ window.removeEventListener("pointerup", e), window.removeEventListener("pointercancel", e), window.removeEventListener("blur", e);
22
+ };
23
+ }, [j]), /* @__PURE__ */ c(u.Root, {
24
+ defaultValue: y,
25
+ ...T,
26
+ ref: O,
27
+ min: y,
28
+ max: b,
29
+ step: x,
30
+ className: `lg-slider ${g}`,
31
+ style: {
32
+ "--lg-accent": d ?? "#8e8e93",
33
+ ..._
34
+ },
35
+ "data-ticks": v ? "" : void 0,
36
+ children: /* @__PURE__ */ l(u.Control, {
37
+ className: "lg-slider-control",
38
+ onPointerDownCapture: (e) => {
39
+ !e.defaultPrevented && e.button === 0 && M(!0);
40
+ },
41
+ onPointerUp: () => M(!1),
42
+ onPointerCancel: () => M(!1),
43
+ onLostPointerCapture: () => M(!1),
44
+ children: [
45
+ /* @__PURE__ */ c(e, {
46
+ radius: "capsule",
47
+ render: /* @__PURE__ */ c(u.Track, {}),
48
+ className: "lg-slider-track",
49
+ children: /* @__PURE__ */ c(e, {
50
+ radius: "capsule",
51
+ render: /* @__PURE__ */ c(u.Indicator, {}),
52
+ className: "lg-slider-fill"
53
+ })
54
+ }),
55
+ v && /* @__PURE__ */ c("div", {
56
+ className: "lg-slider-ticks",
57
+ "aria-hidden": "true",
58
+ children: Array.from({ length: Math.round(E) + 1 }, (e, t) => /* @__PURE__ */ c("span", {}, t))
59
+ }),
60
+ /* @__PURE__ */ c(u.Thumb, {
61
+ "aria-label": C,
62
+ "aria-labelledby": w,
63
+ ...A,
64
+ render: (e, t) => /* @__PURE__ */ c(i, {
65
+ ...e,
66
+ motion: m,
67
+ interactive: h,
68
+ pressed: j || t.dragging,
69
+ options: {
70
+ material: r,
71
+ appearance: o,
72
+ radius: p,
73
+ refraction: f
74
+ },
75
+ className: `lg-slider-thumb ${typeof k == "function" ? k(t) : k}`
76
+ })
77
+ })
78
+ ]
79
+ })
80
+ });
81
+ }
82
+ function p({ material: a, appearance: u, tint: f, refraction: p, radius: m = "capsule", motion: h, interactive: g = !0, className: _ = "", style: v, ...y }) {
83
+ let b = t(), x = n(y.ref, b), [S, C] = s(!1), [w, T] = s(null), E = o(null), D = o(!1);
84
+ return /* @__PURE__ */ l(d.Root, {
85
+ ...y,
86
+ ref: x,
87
+ nativeButton: !1,
88
+ className: `lg-switch ${_}`,
89
+ style: {
90
+ "--lg-accent": f ?? "#8e8e93",
91
+ ...v
92
+ },
93
+ render: (e, t) => /* @__PURE__ */ c("span", {
94
+ ...e,
95
+ role: "switch",
96
+ "aria-checked": t.checked,
97
+ tabIndex: e.tabIndex ?? 0,
98
+ style: {
99
+ ...e.style,
100
+ "--lg-switch-position": w ?? +!!t.checked
101
+ },
102
+ "data-presentation-checked": w === null ? void 0 : w === 1 ? "true" : "false",
103
+ onPointerDown: (n) => {
104
+ if (e.onPointerDown?.(n), n.defaultPrevented || y.readOnly || n.button !== 0) return;
105
+ D.current = !1;
106
+ let r = getComputedStyle(n.currentTarget).direction === "rtl", i = +!!t.checked, a = n.currentTarget.getBoundingClientRect(), o = n.clientX >= a.left + a.width / 2 !== r;
107
+ E.current = {
108
+ id: n.pointerId,
109
+ x: n.clientX,
110
+ start: i,
111
+ current: i,
112
+ left: a.left,
113
+ width: a.width,
114
+ rtl: r,
115
+ oppositeHalf: o !== t.checked,
116
+ moved: !1
117
+ }, n.currentTarget.setPointerCapture(n.pointerId), T(i), C(!0);
118
+ },
119
+ onPointerMove: (t) => {
120
+ e.onPointerMove?.(t);
121
+ let n = E.current;
122
+ if (!n || n.id !== t.pointerId || t.defaultPrevented) return;
123
+ let i = t.clientX - n.x;
124
+ n.moved ||= Math.abs(i) > 3, n.current = Number(r(n, t.clientX)), n.moved && T(n.current);
125
+ },
126
+ onPointerUp: (n) => {
127
+ e.onPointerUp?.(n);
128
+ let r = E.current;
129
+ r && r.id === n.pointerId && (E.current = null, n.currentTarget.hasPointerCapture(n.pointerId) && n.currentTarget.releasePointerCapture(n.pointerId), r.moved && (!n.defaultPrevented && r.current >= .5 !== t.checked && n.currentTarget.click(), D.current = !0), T(null), C(!1));
130
+ },
131
+ onPointerCancel: (t) => {
132
+ e.onPointerCancel?.(t), E.current = null, D.current = !0, T(null), C(!1);
133
+ },
134
+ onLostPointerCapture: (t) => {
135
+ e.onLostPointerCapture?.(t), E.current && (E.current = null, D.current = !0, T(null), C(!1));
136
+ },
137
+ onClickCapture: (t) => {
138
+ if (D.current) {
139
+ D.current = !1, t.preventDefault(), t.stopPropagation();
140
+ return;
141
+ }
142
+ e.onClickCapture?.(t);
143
+ },
144
+ onKeyDown: (t) => {
145
+ e.onKeyDown?.(t), D.current = !1, !t.defaultPrevented && !y.readOnly && (t.key === " " || t.key === "Enter") && C(!0);
146
+ },
147
+ onKeyUp: (t) => {
148
+ e.onKeyUp?.(t), C(!1);
149
+ },
150
+ onBlur: (t) => {
151
+ e.onBlur?.(t), C(!1);
152
+ }
153
+ }),
154
+ children: [/* @__PURE__ */ c(e, {
155
+ radius: "capsule",
156
+ render: /* @__PURE__ */ c("span", {}),
157
+ className: "lg-switch-track",
158
+ "aria-hidden": "true"
159
+ }), /* @__PURE__ */ c(d.Thumb, { render: (e) => /* @__PURE__ */ c(i, {
160
+ ...e,
161
+ tag: "span",
162
+ pressed: S,
163
+ motion: h,
164
+ interactive: g,
165
+ options: {
166
+ material: a,
167
+ appearance: u,
168
+ radius: m,
169
+ refraction: p
170
+ },
171
+ className: "lg-switch-thumb"
172
+ }) })]
173
+ });
174
+ }
175
+ //#endregion
176
+ export { f as GlassSlider, p as GlassSwitch };
package/dist/styles.css CHANGED
@@ -9,6 +9,20 @@
9
9
  width: 100%;
10
10
  height: 100%;
11
11
  }
12
+ :where(.lg-content[data-layout="scroll"]) { overflow: auto; }
13
+ :where([data-glass-blur-host]) { display: contents; }
14
+ /* Gecko blurs this wrapper on the GPU, so glass copies the content unblurred. */
15
+ :where([data-glass-blur-host][data-glass-blur-active]) { display: block; position: absolute; inset: 0; width: 100%; height: 100%; }
16
+ :where([data-glass-blur-host][data-glass-blur-active][data-layout="flow"]) { position: relative; inset: auto; height: auto; }
17
+ :where(.lg-scroll-paint-root) { position: absolute; inset: 0; overflow: visible; }
18
+ :where(.lg-scroll-paint-root > foreignObject) { overflow: visible; }
19
+ /* Gecko draws each surface's glass in a layer beneath its children. */
20
+ .lg-glass-layer {
21
+ position: absolute;
22
+ z-index: -1;
23
+ pointer-events: none;
24
+ background-repeat: no-repeat;
25
+ }
12
26
  :where(.lg-surface) {
13
27
  position: relative;
14
28
  background: transparent;
@@ -179,6 +193,11 @@
179
193
  :where(.lg-surface[data-glass-morph]) > * {
180
194
  opacity: calc(var(--lg-morph, 1) * var(--lg-glass-ready, 1));
181
195
  filter: blur(calc((1 - var(--lg-morph, 1)) * 6px));
196
+ /* Keep animated text blur on its own layer: WebKit can otherwise flash
197
+ unpainted pixels while the containing outline changes. This hint does
198
+ not replace an author's transform and expires with the morph. */
199
+ will-change: transform;
200
+ backface-visibility: hidden;
182
201
  }
183
202
  /* Glass that has become another surface: its material is drawn by that
184
203
  surface, and its own content withdraws as the glass leaves it. */
@@ -1,2 +1 @@
1
- /** Reference arithmetic retained from the accepted Liquid Glass experiment. */
2
1
  export declare function edgeDisplacement(distance: number, amount: number, inverseHeight: number): number;
@@ -1,4 +1,4 @@
1
- /** A spring described the way SwiftUI describes one: perceptual duration in
1
+ /** Perceptual spring duration in
2
2
  * seconds and bounce from 0 (critically damped) to just under 1. */
3
3
  export interface SpringOptions {
4
4
  duration: number;
@@ -0,0 +1,15 @@
1
+ import type { FilterBounds } from "./filter-bounds.js";
2
+ export interface SparseCompositionUnit {
3
+ /** Stable identity of this material unit. */
4
+ id: string;
5
+ mask: string;
6
+ /** Material, outline and light, in their source-over paint order. */
7
+ layers: readonly string[];
8
+ /** Union of every member's output bounds, including outline padding. */
9
+ bounds: FilterBounds;
10
+ }
11
+ /** Replace the source in disjoint rectangular regions. Each region keeps
12
+ * the exact sequential alpha composition, but its intermediate buffers only
13
+ * cover nearby surfaces. Erasing rectangles instead of derived material
14
+ * alpha avoids rewalking the optical graph when WebKit computes outsets. */
15
+ export declare function composeSparseLayers(units: readonly SparseCompositionUnit[], result?: string, source?: string): string;
@@ -0,0 +1,35 @@
1
+ import type { MaterialOptions } from "../core/materials.js";
2
+ import type { FilterBounds } from "./filter-bounds.js";
3
+ import type { MapPlane } from "./map-image.js";
4
+ interface FieldSurface {
5
+ element: Element;
6
+ options: MaterialOptions;
7
+ maps?: unknown;
8
+ x: number;
9
+ y: number;
10
+ w: number;
11
+ h: number;
12
+ opacity: number;
13
+ baseOpacity?: number;
14
+ }
15
+ interface FieldContext<T> {
16
+ source(surface: T): Element | undefined;
17
+ nested(surface: T): boolean;
18
+ refraction(surface: T): number;
19
+ reach(surface: T): number;
20
+ }
21
+ export declare const fieldTouches: (a: Pick<FieldSurface, "x" | "y" | "w" | "h">, b: Pick<FieldSurface, "x" | "y" | "w" | "h">, reach?: number) => boolean;
22
+ /** A detached popup and its source can share one optical field when they
23
+ * have the same opaque material. Moving the source to the popup's paint
24
+ * position must not change any intervening surface's sampled backdrop. */
25
+ export declare function compoundSources<T extends FieldSurface>(ordered: readonly T[], context: FieldContext<T>): Map<T, T>;
26
+ interface FieldMember {
27
+ serial: number;
28
+ opacity: number;
29
+ baseOpacity?: number;
30
+ }
31
+ /** Draw one plane of a compound field: the source's glass, faded as the
32
+ * popup absorbs it, under the popup's. A field's alpha is its coverage, so
33
+ * fading and merging fields also merges the shapes the material fills. */
34
+ export declare function compoundFieldImage<T extends FieldMember>(source: T, popup: T, plane: MapPlane, result: string, box: FilterBounds, image: (member: T, plane: MapPlane, result: string) => string): string;
35
+ export {};
@@ -0,0 +1,9 @@
1
+ /** Rendering engine, which decides how SVG filters on HTML are painted:
2
+ * Chromium on the GPU, WebKit and Gecko mostly in software. */
3
+ /** iOS browser brands can report a different vendor while still using WebKit. */
4
+ export declare function isWebKit(agent: Pick<Navigator, "vendor" | "userAgent">): boolean;
5
+ export declare const webkit: boolean;
6
+ /** Gecko caps a filter chain at 64 operations and renders graphs with images
7
+ * or displacement in software. */
8
+ export declare const gecko: boolean;
9
+ export declare const chromium: boolean;
@@ -0,0 +1,7 @@
1
+ /** Once a replacement starts entering, its sibling no longer owns the
2
+ * submenu slot. Finish the old return before painting the new glass. */
3
+ export declare function finishRetainedExit(parent: Element): void;
4
+ /** A submenu's newest outgoing sibling keeps its return animation. Older
5
+ * exits have already been superseded: finish them before another panel
6
+ * starts returning, rather than accumulating overlapping optical layers. */
7
+ export declare function retainLatestExit(parent: Element, complete: () => void): () => void;
@@ -22,7 +22,7 @@ export declare function crossedSides(width: number, height: number, regions: rea
22
22
  * content needs none. Each tile is a named result a surface merges into its
23
23
  * own cropped backdrop, so no full-size extended copy of the source is ever
24
24
  * built or re-evaluated. */
25
- export declare function edgeTiles(width: number, height: number, bounds: FilterBounds, prefix: string, sides: EdgeSides): {
25
+ export declare function edgeTiles(width: number, height: number, bounds: FilterBounds, prefix: string, sides: EdgeSides, source?: string): {
26
26
  markup: string;
27
27
  names: Record<string, string>;
28
28
  };
@@ -0,0 +1,20 @@
1
+ export { isWebKit, webkit } from "./engine.js";
2
+ /** WebKit paints CSS reference filters in software and adds up the outsets of
3
+ * every blur and displacement primitive in an element's filters: along a
4
+ * chain of `url()` filters, and across the branches of one filter's graph,
5
+ * whose walk folds only one level at a time and sums what it leaves behind.
6
+ * It then clamps the whole filter buffer to 4096 × 4096 device pixels, and
7
+ * past that clamp draws the result stretched, so glass lands away from its
8
+ * surface. Keeping the sum of outsets inside the budget keeps the geometry
9
+ * exact; the material only softens on scenes that would otherwise overflow. */
10
+ /** Outsets WebKit charges for one Gaussian blur of this sigma, in the blur's own pixels. */
11
+ export declare const blurOutsets: (sigma: number) => number;
12
+ /** Factor to apply to every blur sigma and displacement amount so a filtered
13
+ * box of `width` × `height` device pixels with `outsets` device pixels of
14
+ * accumulated outsets stays inside WebKit's buffer clamp. 1 when it already fits. */
15
+ export declare function filterBudgetFactor(width: number, height: number, outsets: number): number;
16
+ /** Largest outsets, in device pixels, a `width` × `height` device-pixel box can take before the clamp. */
17
+ export declare function outsetBudget(width: number, height: number): number;
18
+ /** Mirror WebKit's depth-first outset fold. Shared inputs are visited again
19
+ * at each use, so counting each blur once underestimates branched graphs. */
20
+ export declare function filterGraphOutsets(markup: string, width?: number, height?: number): number;
@@ -0,0 +1,25 @@
1
+ import type { FilterBounds } from "./filter-bounds.js";
2
+ interface LensBox {
3
+ x: number;
4
+ y: number;
5
+ w: number;
6
+ h: number;
7
+ }
8
+ /** Displacement images are opaque through their two-pixel border. Their
9
+ * padded boxes must not overlap, even when the visible glass does not. */
10
+ export declare function mapBoxesOverlap(a: LensBox, b: LensBox): boolean;
11
+ export interface BranchRegions {
12
+ output: FilterBounds;
13
+ crop: FilterBounds;
14
+ sampled: FilterBounds;
15
+ }
16
+ /** Group compatible, independent surfaces only when sharing their material
17
+ * reduces the pixels processed by its primitives. Map images keep their
18
+ * original area; merging four planes adds four passes over the union box.
19
+ * This keeps distant small lenses from creating a scene-sized software pass.
20
+ * Callers separately check the extra branches against WebKit's outset budget. */
21
+ export declare function clusterFilterBranches<T>(members: readonly T[], regions: (member: T) => BranchRegions, stages: {
22
+ output: number;
23
+ sampled: number;
24
+ }): T[][];
25
+ export {};
@@ -0,0 +1,9 @@
1
+ /** Keep WebKit's CSS reference filter in its target's own paint coordinates.
2
+ * Acquire before applying the filter, and release when that filter is removed.
3
+ * A shared target can be claimed by both scene and foreground filtering.
4
+ */
5
+ export declare function acquireFilterPaintRoot(element: HTMLElement): () => void;
6
+ /** Keep popup mounting from changing the scene's composited backing in WebKit.
7
+ * Opacity preserves the containing block of fixed-position descendants.
8
+ */
9
+ export declare function acquireSceneCompositingLayer(element: HTMLElement): () => void;
@@ -1,9 +1,4 @@
1
- /** Keep SVG filters as retained elements. Each frame's markup is parsed into
2
- * an inert template and compared with the live filters: matching filters only
3
- * have changed attributes written, so image primitives keep their loaded
4
- * images and filter references stay valid. Rebuilding filter markup instead
5
- * makes every image reload asynchronously, which shows as the material
6
- * blinking for a frame whenever a surface animates. Image primitives name
7
- * their map with a short `data-map` token, resolved to its URL only when the
8
- * map changes. */
1
+ /** Retain filter primitives and their loaded images across geometry changes.
2
+ * The last description also owns the attribute values, avoiding live DOM
3
+ * collection reads and redundant writes. Exact repeats do no parsing at all. */
9
4
  export declare function patchFilters(defs: Element, markup: readonly string[], resolve: (token: string) => string | undefined): (id: string) => string;
@@ -0,0 +1,23 @@
1
+ import type { FilterBounds } from "./filter-bounds.js";
2
+ /** WebKit filters a partial repaint of an HTML element over the dirty rect
3
+ * grown by the element's filter outsets, then grows that region by the
4
+ * outsets again. A primitive whose subregion misses the region yields no
5
+ * image, which fails the whole filter, so the repainted area paints blank:
6
+ * hovering a link far from every lens erases it. The filter must reach
7
+ * from any point of the element to every primitive it evaluates. */
8
+ /** Outsets, in user units, that let any repaint inside a `width` × `height`
9
+ * element reach every primitive subregion of `markup` and every `extra` box. */
10
+ export declare function repaintReach(markup: string, width: number, height: number, extra?: readonly FilterBounds[]): number;
11
+ /** Add `outsets` to the filter's last merge with transparent images that
12
+ * only move pixels. As siblings in that merge they raise its outsets to at
13
+ * least `outsets` instead of adding to the branches beside them.
14
+ *
15
+ * Offsets are cheap copies but stay within half the element, so their
16
+ * shifted image always overlaps the region. A layer WebKit splits into tiles
17
+ * filters each tile over the tile grown by its outsets once, which needs more
18
+ * reach than that; `tiled` pads with blurs of a transparent flood instead,
19
+ * whose outsets grow without moving anything. */
20
+ export declare function padRepaintReach(markup: string, outsets: number, width: number, height: number, tiled?: boolean): string;
21
+ /** A tile grows its own rectangle by the outsets once rather than twice,
22
+ * so it needs about twice the outsets of a whole-layer repaint. */
23
+ export declare const tiledReach = 2;
@@ -0,0 +1,5 @@
1
+ /** Count this library's generated SVG primitives, excluding their child
2
+ * transfer functions and merge inputs. Gecko's operation cap counts the
3
+ * descriptions before expanding merge inputs into GPU operations. */
4
+ export declare function filterPrimitiveCount(markup: string): number;
5
+ export { gecko } from "./engine.js";
@@ -45,6 +45,9 @@ export interface SurfaceOptions extends MaterialOptions {
45
45
  morphEnter?: boolean;
46
46
  }
47
47
  export interface GlassSceneController {
48
+ /** Optional transparent, nested filter hosts in inner-to-outer order.
49
+ * Gecko uses separate hosts for graphs exceeding its operation limit;
50
+ * reserve the final host for progressive blur. */
48
51
  setContent(element: HTMLElement | null): void;
49
52
  addSurface(element: HTMLElement, options?: SurfaceOptions): () => void;
50
53
  /** Live DOM above the backdrop that must pass through overlapping glass. */
@@ -0,0 +1,68 @@
1
+ import type { MaterialOptions } from "../core/materials.js";
2
+ import type { PlacedMap } from "./map-blend.js";
3
+ import type { MaterialMaps } from "./maps.js";
4
+ import type { ProgressiveRegion } from "./progressive.js";
5
+ /** A surface's border box on screen and the scale its transforms apply. */
6
+ export interface LayerFrame {
7
+ left: number;
8
+ top: number;
9
+ sx: number;
10
+ sy: number;
11
+ clientLeft: number;
12
+ clientTop: number;
13
+ }
14
+ export interface LayerLens {
15
+ serial: number;
16
+ element: HTMLElement;
17
+ options: MaterialOptions;
18
+ maps: MaterialMaps;
19
+ /** Prepared shapes blended in motion, in content coordinates. */
20
+ place?: {
21
+ a: PlacedMap;
22
+ b: PlacedMap;
23
+ mix: number;
24
+ };
25
+ /** Drawn glass in content coordinates. */
26
+ x: number;
27
+ y: number;
28
+ w: number;
29
+ h: number;
30
+ opacity: number;
31
+ /** Displacement travel in CSS pixels. */
32
+ refraction: number;
33
+ /** Glass this surface sits inside, innermost first. */
34
+ parents: readonly LayerLens[];
35
+ /** Earlier glass, not an ancestor, close enough to be refracted. */
36
+ beneath: readonly LayerLens[];
37
+ frame: LayerFrame;
38
+ }
39
+ interface Box {
40
+ left: number;
41
+ top: number;
42
+ width: number;
43
+ height: number;
44
+ }
45
+ /** Gecko renders an SVG filter with images or displacement in software and,
46
+ * once it falls back, rasterizes it again on every paint of the page,
47
+ * whatever changed. A filter over a whole content layer then costs its full
48
+ * area on every frame of any animation anywhere.
49
+ *
50
+ * Here each surface draws its own glass instead. A layer inside the surface,
51
+ * beneath its children, paints a live `-moz-element()` copy of the content
52
+ * (and of the glass under it) and refracts only that. The content layer
53
+ * itself stays unfiltered on the GPU. An unchanged layer is never
54
+ * rasterized again, and a moving one costs only its own area. */
55
+ export declare function createLensLayers(root: HTMLElement): {
56
+ /** `blur` is the scene's progressive blur when it is drawn on a host
57
+ * around the content rather than on the content: layers then blur their
58
+ * own copy of the content the same way, so they never render the whole
59
+ * blurred content to sample a small part of it. */
60
+ update(lenses: readonly LayerLens[], content: HTMLElement, contentRect: Box, blur?: {
61
+ left: number;
62
+ top: number;
63
+ regions: readonly ProgressiveRegion[];
64
+ }): void;
65
+ owns(node: Node): boolean;
66
+ dispose(): void;
67
+ };
68
+ export {};
@@ -0,0 +1,22 @@
1
+ import type { MapPlane } from "./map-image.js";
2
+ import type { MaterialMaps } from "./maps.js";
3
+ export interface PlacedMap {
4
+ maps: MaterialMaps;
5
+ x: number;
6
+ y: number;
7
+ w: number;
8
+ h: number;
9
+ }
10
+ /** Emit an animation's material map, retaining both inputs unless they name
11
+ * the same pixels at the same position. This cuts redundant Gecko filter
12
+ * operations during map preparation and at the end of a spring. */
13
+ export declare function blendMapImage(plane: MapPlane, result: string, placement: {
14
+ a: PlacedMap;
15
+ b: PlacedMap;
16
+ mix: number;
17
+ }, bounds: {
18
+ x: number;
19
+ y: number;
20
+ w: number;
21
+ h: number;
22
+ }, collapseIdentical?: boolean): string;