@sessile/dom 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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;