@sessile/dom 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +373 -0
- package/dist/capabilities.d.ts +75 -0
- package/dist/capabilities.js +336 -0
- package/dist/cssSurface.d.ts +65 -0
- package/dist/cssSurface.js +348 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/refractFilter.d.ts +56 -0
- package/dist/refractFilter.js +349 -0
- package/dist/surfaceController.d.ts +146 -0
- package/dist/surfaceController.js +685 -0
- package/package.json +33 -3
- package/README.md +0 -3
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless Route B3 SVG `<filter>` DOM controller for Chromium liquid-glass refraction.
|
|
3
|
+
*
|
|
4
|
+
* Manages an off-screen SVG filter graph driven by `@sessile/core`'s Stored-PNG
|
|
5
|
+
* displacement map (`createRefractMapBuilder`) and Rec.709 color optics matrix
|
|
6
|
+
* (`buildColorOpticsMatrix`), dynamically switching between single-pass displacement
|
|
7
|
+
* and 3-channel RGB chromatic dispersion while self-masking to the displacement map alpha
|
|
8
|
+
* to avoid rectangular `backdrop-filter` bounds leakage.
|
|
9
|
+
*
|
|
10
|
+
* SPDX-License-Identifier: MPL-2.0
|
|
11
|
+
*/
|
|
12
|
+
import { buildColorOpticsMatrix, createRefractMapBuilder, } from '@sessile/core';
|
|
13
|
+
export const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
14
|
+
const FULL_RES_MAP_THRESHOLD_PX = 128;
|
|
15
|
+
const MIN_ACTIVE_SIZE = 0.01;
|
|
16
|
+
function normalizePositiveOrDefault(value, fallback) {
|
|
17
|
+
return value !== undefined && Number.isFinite(value) && value > 0 ? value : fallback;
|
|
18
|
+
}
|
|
19
|
+
function normalizeNonNegativeOrDefault(value, fallback) {
|
|
20
|
+
return value !== undefined && Number.isFinite(value) && value >= 0 ? value : fallback;
|
|
21
|
+
}
|
|
22
|
+
function normalizeConfig(input, base) {
|
|
23
|
+
const b = base ?? {
|
|
24
|
+
bezel: 0,
|
|
25
|
+
strength: 1.32,
|
|
26
|
+
dispersion: 0,
|
|
27
|
+
falloff: 2.6,
|
|
28
|
+
scaleMultiplier: 1,
|
|
29
|
+
mapScale: 0.5,
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
bezel: normalizeNonNegativeOrDefault(input?.bezel, b.bezel),
|
|
33
|
+
strength: normalizeNonNegativeOrDefault(input?.strength, b.strength),
|
|
34
|
+
dispersion: normalizeNonNegativeOrDefault(input?.dispersion, b.dispersion),
|
|
35
|
+
falloff: normalizeNonNegativeOrDefault(input?.falloff, b.falloff),
|
|
36
|
+
scaleMultiplier: normalizeNonNegativeOrDefault(input?.scaleMultiplier, b.scaleMultiplier),
|
|
37
|
+
mapScale: normalizePositiveOrDefault(input?.mapScale, b.mapScale),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/** Computes automatic lens bezel width (clamped to `[6, 22]` CSS px) from element dimensions. */
|
|
41
|
+
export function computeAutoBezel(width, height) {
|
|
42
|
+
const minDim = Math.max(0, Math.min(width, height));
|
|
43
|
+
return Math.max(6, Math.min(22, minDim * 0.3));
|
|
44
|
+
}
|
|
45
|
+
/** Resolves effective bezel width across all active primitives in an N-primitive glass field. */
|
|
46
|
+
export function resolveFieldBezel(requestedBezel, field) {
|
|
47
|
+
let refW = 0;
|
|
48
|
+
let refH = 0;
|
|
49
|
+
let hasActive = false;
|
|
50
|
+
for (let i = 0; i < field.primitives.length; i++) {
|
|
51
|
+
const p = field.primitives[i];
|
|
52
|
+
if (p.size.width > MIN_ACTIVE_SIZE && p.size.height > MIN_ACTIVE_SIZE) {
|
|
53
|
+
if (p.size.width > refW)
|
|
54
|
+
refW = p.size.width;
|
|
55
|
+
if (p.size.height > refH)
|
|
56
|
+
refH = p.size.height;
|
|
57
|
+
hasActive = true;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (!hasActive) {
|
|
61
|
+
return requestedBezel > 0 ? Math.max(1, requestedBezel) : 6;
|
|
62
|
+
}
|
|
63
|
+
return requestedBezel > 0
|
|
64
|
+
? Math.max(1, Math.min(requestedBezel, refW * 0.5, refH * 0.5))
|
|
65
|
+
: computeAutoBezel(refW, refH);
|
|
66
|
+
}
|
|
67
|
+
/** Creates an imperative SVG `<filter>` controller implementing Route B3 self-masked refraction. */
|
|
68
|
+
export function createRefractFilterController(options) {
|
|
69
|
+
const doc = options.document ?? (typeof document !== 'undefined' ? document : null);
|
|
70
|
+
const id = options.id;
|
|
71
|
+
let config = normalizeConfig(options);
|
|
72
|
+
if (!doc || typeof doc.createElementNS !== 'function') {
|
|
73
|
+
return {
|
|
74
|
+
id,
|
|
75
|
+
svgElement: null,
|
|
76
|
+
mounted: false,
|
|
77
|
+
mount: () => false,
|
|
78
|
+
updateConfig(next) {
|
|
79
|
+
config = normalizeConfig(next, config);
|
|
80
|
+
},
|
|
81
|
+
updateFrame: () => { },
|
|
82
|
+
dispose: () => { },
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const createSvgEl = (tag) => doc.createElementNS(SVG_NS, tag);
|
|
86
|
+
const svgEl = createSvgEl('svg');
|
|
87
|
+
svgEl.setAttribute('aria-hidden', 'true');
|
|
88
|
+
if (svgEl.style) {
|
|
89
|
+
svgEl.style.position = 'fixed';
|
|
90
|
+
svgEl.style.top = '0';
|
|
91
|
+
svgEl.style.left = '0';
|
|
92
|
+
svgEl.style.width = '0';
|
|
93
|
+
svgEl.style.height = '0';
|
|
94
|
+
svgEl.style.overflow = 'hidden';
|
|
95
|
+
svgEl.style.pointerEvents = 'none';
|
|
96
|
+
svgEl.style.opacity = '0';
|
|
97
|
+
}
|
|
98
|
+
const defsEl = createSvgEl('defs');
|
|
99
|
+
const filterEl = createSvgEl('filter');
|
|
100
|
+
filterEl.setAttribute('id', id);
|
|
101
|
+
filterEl.setAttribute('color-interpolation-filters', 'sRGB');
|
|
102
|
+
filterEl.setAttribute('x', '0%');
|
|
103
|
+
filterEl.setAttribute('y', '0%');
|
|
104
|
+
filterEl.setAttribute('width', '100%');
|
|
105
|
+
filterEl.setAttribute('height', '100%');
|
|
106
|
+
const feImageEl = createSvgEl('feImage');
|
|
107
|
+
feImageEl.setAttribute('x', '0');
|
|
108
|
+
feImageEl.setAttribute('y', '0');
|
|
109
|
+
feImageEl.setAttribute('width', '1');
|
|
110
|
+
feImageEl.setAttribute('height', '1');
|
|
111
|
+
feImageEl.setAttribute('preserveAspectRatio', 'none');
|
|
112
|
+
feImageEl.setAttribute('result', 'map');
|
|
113
|
+
const bgBlurEl = createSvgEl('feGaussianBlur');
|
|
114
|
+
bgBlurEl.setAttribute('in', 'SourceGraphic');
|
|
115
|
+
bgBlurEl.setAttribute('stdDeviation', '0');
|
|
116
|
+
bgBlurEl.setAttribute('edgeMode', 'duplicate');
|
|
117
|
+
bgBlurEl.setAttribute('result', 'bgBlur');
|
|
118
|
+
const colorMatrixEl = createSvgEl('feColorMatrix');
|
|
119
|
+
colorMatrixEl.setAttribute('in', 'bgBlur');
|
|
120
|
+
colorMatrixEl.setAttribute('type', 'matrix');
|
|
121
|
+
colorMatrixEl.setAttribute('values', '1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0');
|
|
122
|
+
colorMatrixEl.setAttribute('result', 'bgOptics');
|
|
123
|
+
const refractSmoothEl = createSvgEl('feGaussianBlur');
|
|
124
|
+
refractSmoothEl.setAttribute('in', 'refractRaw');
|
|
125
|
+
refractSmoothEl.setAttribute('stdDeviation', '0.5');
|
|
126
|
+
refractSmoothEl.setAttribute('edgeMode', 'duplicate');
|
|
127
|
+
refractSmoothEl.setAttribute('result', 'refractSmooth');
|
|
128
|
+
const glassOnlyEl = createSvgEl('feComposite');
|
|
129
|
+
glassOnlyEl.setAttribute('in', 'refractSmooth');
|
|
130
|
+
glassOnlyEl.setAttribute('in2', 'map');
|
|
131
|
+
glassOnlyEl.setAttribute('operator', 'in');
|
|
132
|
+
glassOnlyEl.setAttribute('result', 'glassOnly');
|
|
133
|
+
const mergeEl = createSvgEl('feMerge');
|
|
134
|
+
const mergeBaseEl = createSvgEl('feMergeNode');
|
|
135
|
+
mergeBaseEl.setAttribute('in', 'SourceGraphic');
|
|
136
|
+
const mergeGlassEl = createSvgEl('feMergeNode');
|
|
137
|
+
mergeGlassEl.setAttribute('in', 'glassOnly');
|
|
138
|
+
mergeEl.appendChild(mergeBaseEl);
|
|
139
|
+
mergeEl.appendChild(mergeGlassEl);
|
|
140
|
+
filterEl.appendChild(feImageEl);
|
|
141
|
+
filterEl.appendChild(bgBlurEl);
|
|
142
|
+
filterEl.appendChild(colorMatrixEl);
|
|
143
|
+
filterEl.appendChild(refractSmoothEl);
|
|
144
|
+
filterEl.appendChild(glassOnlyEl);
|
|
145
|
+
filterEl.appendChild(mergeEl);
|
|
146
|
+
defsEl.appendChild(filterEl);
|
|
147
|
+
svgEl.appendChild(defsEl);
|
|
148
|
+
let stageNodes = [];
|
|
149
|
+
let dispNodes = [];
|
|
150
|
+
let currentDispersive = null;
|
|
151
|
+
let prevWidth = -1;
|
|
152
|
+
let prevHeight = -1;
|
|
153
|
+
let prevSigma = '';
|
|
154
|
+
let prevMatrix = '';
|
|
155
|
+
let prevScaleKey = '';
|
|
156
|
+
let disposed = false;
|
|
157
|
+
let mapBuilder = null;
|
|
158
|
+
const rebuildDisplacementStage = (dispersive) => {
|
|
159
|
+
if (currentDispersive === dispersive) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
for (let i = 0; i < stageNodes.length; i++) {
|
|
163
|
+
const node = stageNodes[i];
|
|
164
|
+
if (node.parentNode) {
|
|
165
|
+
node.parentNode.removeChild(node);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
stageNodes = [];
|
|
169
|
+
dispNodes = [];
|
|
170
|
+
const appendStageNode = (node) => {
|
|
171
|
+
filterEl.insertBefore(node, refractSmoothEl);
|
|
172
|
+
stageNodes.push(node);
|
|
173
|
+
};
|
|
174
|
+
if (dispersive) {
|
|
175
|
+
const channels = ['R', 'G', 'B'];
|
|
176
|
+
for (let i = 0; i < channels.length; i++) {
|
|
177
|
+
const ch = channels[i];
|
|
178
|
+
const transferEl = createSvgEl('feComponentTransfer');
|
|
179
|
+
transferEl.setAttribute('in', 'bgOptics');
|
|
180
|
+
transferEl.setAttribute('result', `input-${ch}`);
|
|
181
|
+
const funcR = createSvgEl('feFuncR');
|
|
182
|
+
funcR.setAttribute('type', 'linear');
|
|
183
|
+
funcR.setAttribute('slope', ch === 'R' ? '1' : '0');
|
|
184
|
+
const funcG = createSvgEl('feFuncG');
|
|
185
|
+
funcG.setAttribute('type', 'linear');
|
|
186
|
+
funcG.setAttribute('slope', ch === 'G' ? '1' : '0');
|
|
187
|
+
const funcB = createSvgEl('feFuncB');
|
|
188
|
+
funcB.setAttribute('type', 'linear');
|
|
189
|
+
funcB.setAttribute('slope', ch === 'B' ? '1' : '0');
|
|
190
|
+
transferEl.appendChild(funcR);
|
|
191
|
+
transferEl.appendChild(funcG);
|
|
192
|
+
transferEl.appendChild(funcB);
|
|
193
|
+
appendStageNode(transferEl);
|
|
194
|
+
const dispEl = createSvgEl('feDisplacementMap');
|
|
195
|
+
dispEl.setAttribute('in', `input-${ch}`);
|
|
196
|
+
dispEl.setAttribute('in2', 'map');
|
|
197
|
+
dispEl.setAttribute('xChannelSelector', 'R');
|
|
198
|
+
dispEl.setAttribute('yChannelSelector', 'G');
|
|
199
|
+
dispEl.setAttribute('scale', '0');
|
|
200
|
+
dispEl.setAttribute('result', `lens-${ch}`);
|
|
201
|
+
appendStageNode(dispEl);
|
|
202
|
+
dispNodes.push({ element: dispEl, offsetSign: i - 1 });
|
|
203
|
+
}
|
|
204
|
+
const compRg = createSvgEl('feComposite');
|
|
205
|
+
compRg.setAttribute('in', 'lens-R');
|
|
206
|
+
compRg.setAttribute('in2', 'lens-G');
|
|
207
|
+
compRg.setAttribute('operator', 'arithmetic');
|
|
208
|
+
compRg.setAttribute('k1', '0');
|
|
209
|
+
compRg.setAttribute('k2', '1');
|
|
210
|
+
compRg.setAttribute('k3', '1');
|
|
211
|
+
compRg.setAttribute('k4', '0');
|
|
212
|
+
compRg.setAttribute('result', 'rg');
|
|
213
|
+
appendStageNode(compRg);
|
|
214
|
+
const compRgb = createSvgEl('feComposite');
|
|
215
|
+
compRgb.setAttribute('in', 'rg');
|
|
216
|
+
compRgb.setAttribute('in2', 'lens-B');
|
|
217
|
+
compRgb.setAttribute('operator', 'arithmetic');
|
|
218
|
+
compRgb.setAttribute('k1', '0');
|
|
219
|
+
compRgb.setAttribute('k2', '1');
|
|
220
|
+
compRgb.setAttribute('k3', '1');
|
|
221
|
+
compRgb.setAttribute('k4', '0');
|
|
222
|
+
compRgb.setAttribute('result', 'refractRaw');
|
|
223
|
+
appendStageNode(compRgb);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
const dispEl = createSvgEl('feDisplacementMap');
|
|
227
|
+
dispEl.setAttribute('in', 'bgOptics');
|
|
228
|
+
dispEl.setAttribute('in2', 'map');
|
|
229
|
+
dispEl.setAttribute('xChannelSelector', 'R');
|
|
230
|
+
dispEl.setAttribute('yChannelSelector', 'G');
|
|
231
|
+
dispEl.setAttribute('scale', '0');
|
|
232
|
+
dispEl.setAttribute('result', 'refractRaw');
|
|
233
|
+
appendStageNode(dispEl);
|
|
234
|
+
dispNodes.push({ element: dispEl, offsetSign: 0 });
|
|
235
|
+
}
|
|
236
|
+
currentDispersive = dispersive;
|
|
237
|
+
// Force scale re-sync immediately after swapping displacement DOM nodes.
|
|
238
|
+
prevScaleKey = '';
|
|
239
|
+
};
|
|
240
|
+
rebuildDisplacementStage(config.dispersion > 0);
|
|
241
|
+
const mount = (target) => {
|
|
242
|
+
if (disposed)
|
|
243
|
+
return false;
|
|
244
|
+
const resolvedTarget = target ?? options.mountTarget ?? doc.body ?? doc.documentElement;
|
|
245
|
+
if (!resolvedTarget)
|
|
246
|
+
return false;
|
|
247
|
+
if (svgEl.parentNode === resolvedTarget) {
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
250
|
+
resolvedTarget.appendChild(svgEl);
|
|
251
|
+
return true;
|
|
252
|
+
};
|
|
253
|
+
const updateConfig = (next) => {
|
|
254
|
+
if (disposed)
|
|
255
|
+
return;
|
|
256
|
+
config = normalizeConfig(next, config);
|
|
257
|
+
rebuildDisplacementStage(config.dispersion > 0);
|
|
258
|
+
};
|
|
259
|
+
const updateFrame = (frame) => {
|
|
260
|
+
if (disposed)
|
|
261
|
+
return;
|
|
262
|
+
const requestedBezel = frame.bezel !== undefined ? normalizeNonNegativeOrDefault(frame.bezel, config.bezel) : config.bezel;
|
|
263
|
+
const strength = frame.strength !== undefined
|
|
264
|
+
? normalizeNonNegativeOrDefault(frame.strength, config.strength)
|
|
265
|
+
: config.strength;
|
|
266
|
+
const dispersion = frame.dispersion !== undefined
|
|
267
|
+
? normalizeNonNegativeOrDefault(frame.dispersion, config.dispersion)
|
|
268
|
+
: config.dispersion;
|
|
269
|
+
const falloff = frame.falloff !== undefined
|
|
270
|
+
? normalizeNonNegativeOrDefault(frame.falloff, config.falloff)
|
|
271
|
+
: config.falloff;
|
|
272
|
+
const scaleMultiplier = frame.scaleMultiplier !== undefined
|
|
273
|
+
? normalizeNonNegativeOrDefault(frame.scaleMultiplier, config.scaleMultiplier)
|
|
274
|
+
: config.scaleMultiplier;
|
|
275
|
+
const rawMapScale = frame.mapScale !== undefined
|
|
276
|
+
? normalizePositiveOrDefault(frame.mapScale, config.mapScale)
|
|
277
|
+
: config.mapScale;
|
|
278
|
+
rebuildDisplacementStage(dispersion > 0);
|
|
279
|
+
const frameBezel = resolveFieldBezel(requestedBezel, frame.field);
|
|
280
|
+
// Promote half-res maps to 1:1 for compact pills/buttons so rim displacement stays crisp.
|
|
281
|
+
const frameMapScale = rawMapScale === 0.5 && Math.max(frame.bounds.width, frame.bounds.height) <= FULL_RES_MAP_THRESHOLD_PX
|
|
282
|
+
? 1
|
|
283
|
+
: rawMapScale;
|
|
284
|
+
mapBuilder ??= createRefractMapBuilder();
|
|
285
|
+
const mapResult = mapBuilder.build({
|
|
286
|
+
bounds: frame.bounds,
|
|
287
|
+
field: frame.field,
|
|
288
|
+
bezel: frameBezel,
|
|
289
|
+
falloff,
|
|
290
|
+
mapScale: frameMapScale,
|
|
291
|
+
});
|
|
292
|
+
if (mapResult.width !== prevWidth || mapResult.height !== prevHeight) {
|
|
293
|
+
feImageEl.setAttribute('width', String(mapResult.width));
|
|
294
|
+
feImageEl.setAttribute('height', String(mapResult.height));
|
|
295
|
+
prevWidth = mapResult.width;
|
|
296
|
+
prevHeight = mapResult.height;
|
|
297
|
+
}
|
|
298
|
+
if (mapResult.changed) {
|
|
299
|
+
feImageEl.setAttribute('href', mapResult.dataUrl);
|
|
300
|
+
}
|
|
301
|
+
const baseScale = Math.max(0, 2 * frameBezel * strength * scaleMultiplier);
|
|
302
|
+
const scaleKey = `${baseScale.toFixed(2)}:${dispersion}`;
|
|
303
|
+
if (scaleKey !== prevScaleKey) {
|
|
304
|
+
for (let i = 0; i < dispNodes.length; i++) {
|
|
305
|
+
const binding = dispNodes[i];
|
|
306
|
+
const scale = Math.max(0, baseScale + binding.offsetSign * dispersion);
|
|
307
|
+
binding.element.setAttribute('scale', String(scale));
|
|
308
|
+
}
|
|
309
|
+
prevScaleKey = scaleKey;
|
|
310
|
+
}
|
|
311
|
+
const sigma = Number.isFinite(frame.blurSigma) && frame.blurSigma > 0.05
|
|
312
|
+
? frame.blurSigma.toFixed(2)
|
|
313
|
+
: '0';
|
|
314
|
+
if (sigma !== prevSigma) {
|
|
315
|
+
bgBlurEl.setAttribute('stdDeviation', sigma);
|
|
316
|
+
prevSigma = sigma;
|
|
317
|
+
}
|
|
318
|
+
const matrix = buildColorOpticsMatrix(frame.saturate, frame.brightness, frame.contrast, frame.contrastFirst);
|
|
319
|
+
if (matrix !== prevMatrix) {
|
|
320
|
+
colorMatrixEl.setAttribute('values', matrix);
|
|
321
|
+
prevMatrix = matrix;
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
const dispose = () => {
|
|
325
|
+
if (disposed)
|
|
326
|
+
return;
|
|
327
|
+
disposed = true;
|
|
328
|
+
if (svgEl.parentNode) {
|
|
329
|
+
svgEl.parentNode.removeChild(svgEl);
|
|
330
|
+
}
|
|
331
|
+
stageNodes = [];
|
|
332
|
+
dispNodes = [];
|
|
333
|
+
mapBuilder?.reset();
|
|
334
|
+
mapBuilder = null;
|
|
335
|
+
};
|
|
336
|
+
return {
|
|
337
|
+
id,
|
|
338
|
+
get svgElement() {
|
|
339
|
+
return disposed ? null : svgEl;
|
|
340
|
+
},
|
|
341
|
+
get mounted() {
|
|
342
|
+
return !disposed && svgEl.parentNode !== null;
|
|
343
|
+
},
|
|
344
|
+
mount,
|
|
345
|
+
updateConfig,
|
|
346
|
+
updateFrame,
|
|
347
|
+
dispose,
|
|
348
|
+
};
|
|
349
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-agnostic headless 3-layer DOM surface controller for Sessile.
|
|
3
|
+
*
|
|
4
|
+
* Orchestrates three sibling layers around live interactive DOM content:
|
|
5
|
+
* 1. `refractBackdrop` (unclipped Route B3 Chromium SVG `backdrop-filter: url(#id)` layer)
|
|
6
|
+
* 2. `veil` (SDF contour-clipped tint/frosted layer, also serving Safari/Firefox/solid fallback)
|
|
7
|
+
* 3. `overlayCanvas` (transparent WebGL2/2D Canvas perimeter highlight and outer shadow layer)
|
|
8
|
+
*
|
|
9
|
+
* Keeps live DOM interactive text/controls positioned cleanly between `veil` and `overlayCanvas`,
|
|
10
|
+
* applies lazy SVG filter mounting, and reuses preallocated structures on the 60/120fps hot path.
|
|
11
|
+
*
|
|
12
|
+
* SPDX-License-Identifier: MPL-2.0
|
|
13
|
+
*/
|
|
14
|
+
import { type BackdropVeilOptics, type GlassFieldState, type IGlassOverlayRenderer, type OpticalMaterial, type Rect, type RendererCapabilities, type Size, type ThemeMode } from '@sessile/core';
|
|
15
|
+
import { type CapabilityEnv, type FrameScheduler, type SurfaceCapabilities, type SurfaceRenderMode } from './capabilities.ts';
|
|
16
|
+
import { type RefractFilterConfig } from './refractFilter.ts';
|
|
17
|
+
export interface GlassSurfaceElements {
|
|
18
|
+
refractBackdrop?: HTMLElement | null;
|
|
19
|
+
veil?: HTMLElement | null;
|
|
20
|
+
overlayCanvas?: HTMLCanvasElement | null;
|
|
21
|
+
}
|
|
22
|
+
export interface GlassSurfaceZIndex {
|
|
23
|
+
refract?: number | string;
|
|
24
|
+
veil?: number | string;
|
|
25
|
+
overlay?: number | string;
|
|
26
|
+
}
|
|
27
|
+
export interface GlassSurfaceCapabilities extends SurfaceCapabilities {
|
|
28
|
+
overlay: RendererCapabilities;
|
|
29
|
+
}
|
|
30
|
+
export interface GlassSurfaceFrame {
|
|
31
|
+
field: GlassFieldState;
|
|
32
|
+
bounds?: Rect;
|
|
33
|
+
refractBounds?: Rect;
|
|
34
|
+
material?: OpticalMaterial;
|
|
35
|
+
veilOptics?: BackdropVeilOptics;
|
|
36
|
+
opacity?: number;
|
|
37
|
+
theme?: ThemeMode;
|
|
38
|
+
blurBumpPx?: number;
|
|
39
|
+
dpr?: number;
|
|
40
|
+
solidBackground?: string;
|
|
41
|
+
frostedBackground?: string;
|
|
42
|
+
refractTintBackground?: string;
|
|
43
|
+
refraction?: Partial<RefractFilterConfig>;
|
|
44
|
+
}
|
|
45
|
+
export type SurfaceFrameProducer = (dtSec: number, nowMs: number) => GlassSurfaceFrame | boolean | void;
|
|
46
|
+
export interface GlassSurfaceControllerOptions {
|
|
47
|
+
container?: HTMLElement | null;
|
|
48
|
+
elements?: GlassSurfaceElements;
|
|
49
|
+
/** Reference child before which managed backdrop siblings (`refractBackdrop`, `veil`) are inserted. */
|
|
50
|
+
insertBackdropBefore?: Node | null;
|
|
51
|
+
mode?: SurfaceRenderMode;
|
|
52
|
+
theme?: ThemeMode;
|
|
53
|
+
material?: OpticalMaterial;
|
|
54
|
+
refraction?: Partial<RefractFilterConfig>;
|
|
55
|
+
filterId?: string;
|
|
56
|
+
svgMountTarget?: Element | null;
|
|
57
|
+
positioning?: 'absolute' | 'fixed';
|
|
58
|
+
zIndex?: GlassSurfaceZIndex;
|
|
59
|
+
disableRefractOnReducedMotion?: boolean;
|
|
60
|
+
observeResize?: boolean | Element;
|
|
61
|
+
onResize?: (size: Size) => void;
|
|
62
|
+
onCapabilitiesChange?: (capabilities: GlassSurfaceCapabilities) => void;
|
|
63
|
+
document?: Document;
|
|
64
|
+
env?: CapabilityEnv;
|
|
65
|
+
overlayRenderer?: IGlassOverlayRenderer;
|
|
66
|
+
scheduler?: Partial<FrameScheduler>;
|
|
67
|
+
ResizeObserverCtor?: typeof ResizeObserver;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Computes integer-snapped surface overlay bounds expanding the active primitives by
|
|
71
|
+
* outer shadow blur/offset and `smin` blend radius so contours and shadows never clip.
|
|
72
|
+
*/
|
|
73
|
+
export declare function computeAutoSurfaceBounds(field: GlassFieldState, material: OpticalMaterial): Rect;
|
|
74
|
+
/**
|
|
75
|
+
* Computes tight Route B3 refraction backdrop bounds clamped inside `surfaceBounds`
|
|
76
|
+
* while preserving enough padding for multi-primitive `smin` liquid bridges.
|
|
77
|
+
*/
|
|
78
|
+
export declare function computeClampedRefractBounds(field: GlassFieldState, surfaceBounds: Rect): Rect;
|
|
79
|
+
/**
|
|
80
|
+
* Stateful headless controller coordinating the 3-layer DOM glass presentation,
|
|
81
|
+
* Route B3 SVG refraction filter, progressive fallback, resize observation, and rAF loop.
|
|
82
|
+
*/
|
|
83
|
+
export declare class GlassSurfaceController {
|
|
84
|
+
private readonly doc;
|
|
85
|
+
private readonly container;
|
|
86
|
+
private readonly svgMountTarget;
|
|
87
|
+
private readonly filterId;
|
|
88
|
+
private readonly baseRefraction;
|
|
89
|
+
private readonly defaultMaterial;
|
|
90
|
+
private readonly disableRefractOnReducedMotion;
|
|
91
|
+
private readonly onResizeCallback;
|
|
92
|
+
private readonly onCapabilitiesChangeCallback;
|
|
93
|
+
private readonly refractBackdropEl;
|
|
94
|
+
private readonly veilEl;
|
|
95
|
+
private readonly overlayCanvasEl;
|
|
96
|
+
private readonly ownsRefractBackdrop;
|
|
97
|
+
private readonly ownsVeil;
|
|
98
|
+
private readonly ownsOverlayCanvas;
|
|
99
|
+
private prevContainerPosition;
|
|
100
|
+
private prevContainerZIndex;
|
|
101
|
+
private readonly overlayRenderer;
|
|
102
|
+
private overlayCapabilities;
|
|
103
|
+
private surfaceCapabilities;
|
|
104
|
+
private requestedMode;
|
|
105
|
+
private effectiveMode;
|
|
106
|
+
private activeTheme;
|
|
107
|
+
private containerSize;
|
|
108
|
+
private lastRenderedFrame;
|
|
109
|
+
private disposed;
|
|
110
|
+
private refractFilterController;
|
|
111
|
+
private stopReducedMotionObserver;
|
|
112
|
+
private stopResizeObserver;
|
|
113
|
+
private frameLoop;
|
|
114
|
+
private readonly loopScheduler;
|
|
115
|
+
private readonly refractCache;
|
|
116
|
+
private readonly veilCache;
|
|
117
|
+
private readonly overlayCache;
|
|
118
|
+
private readonly shiftedPrimitivesPool;
|
|
119
|
+
private readonly shiftedField;
|
|
120
|
+
constructor(options?: GlassSurfaceControllerOptions);
|
|
121
|
+
private hideRefractBackdrop;
|
|
122
|
+
private ensureRefractFilterController;
|
|
123
|
+
private prepareShiftedField;
|
|
124
|
+
/** Renders one frame across the 3 glass sibling layers and updates overlay highlights. */
|
|
125
|
+
render(frame: GlassSurfaceFrame): void;
|
|
126
|
+
private applyFrostedVeil;
|
|
127
|
+
/** Hides all surface layers and clears the overlay canvas without detaching DOM nodes. */
|
|
128
|
+
clear(): void;
|
|
129
|
+
/** Changes the requested render mode and recomputes the effective downgraded mode. */
|
|
130
|
+
setMode(mode: SurfaceRenderMode): SurfaceRenderMode;
|
|
131
|
+
getMode(): SurfaceRenderMode;
|
|
132
|
+
getEffectiveMode(): SurfaceRenderMode;
|
|
133
|
+
setTheme(theme: ThemeMode): void;
|
|
134
|
+
getTheme(): ThemeMode;
|
|
135
|
+
getCapabilities(): GlassSurfaceCapabilities;
|
|
136
|
+
getContainerSize(): Size | null;
|
|
137
|
+
getElements(): GlassSurfaceElements;
|
|
138
|
+
/** Starts a clamped `requestAnimationFrame` loop driving frames via `produceFrame`. */
|
|
139
|
+
startLoop(produceFrame: SurfaceFrameProducer): void;
|
|
140
|
+
stopLoop(): void;
|
|
141
|
+
isLoopRunning(): boolean;
|
|
142
|
+
/** Disposes observers, rAF loop, SVG filter, overlay renderer, and any managed sibling nodes. */
|
|
143
|
+
dispose(): void;
|
|
144
|
+
}
|
|
145
|
+
/** Factory helper creating a configured `GlassSurfaceController`. */
|
|
146
|
+
export declare function createGlassSurfaceController(options?: GlassSurfaceControllerOptions): GlassSurfaceController;
|