@alexpeng/dsh-custom-plugin 0.11.0 → 0.13.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.
@@ -1,287 +1,138 @@
1
1
  /**
2
- * WebGL1 backdrop: one full-screen triangle, one fragment shader, no library.
2
+ * WebGL2 light-and-shadow backdrop, built on Paper Shaders.
3
3
  *
4
- * This is the shader tier of `div#vx-bg`. It shares the layer, the motion
5
- * attribute (`data-vx-bg-motion`), the tint (`--vx-bg-tint`), the visibility
6
- * rules and the one-way degradation ladder with the ASCII renderer, but it is
7
- * exclusive with it: the two never coexist, and leaving this tier calls
8
- * `WEBGL_lose_context` so the page never accumulates contexts.
4
+ * The shader tier used to be a hand-written full-screen triangle per style.
5
+ * It is now a thin wrapper around `@paper-design/shaders` (Apache-2.0,
6
+ * https://github.com/paper-design/shaders): each preset is one of their
7
+ * audited fragment shaders, mounted through `ShaderMount`, which owns the
8
+ * WebGL2 context, DPR/size handling, visibility pausing and teardown.
9
9
  *
10
- * The uniform contract is fixed (time, resolution, dpr, surface, ink, speed,
11
- * density, intensity, seed). Surface and ink are the same values the ASCII
12
- * tier uses, so both tiers read correctly on light/dark themes and every
13
- * palette; the ink keeps `inkFor`'s fixed lightness delta and nothing neon or
14
- * highly saturated enters the shader.
10
+ * The page tint (`--vx-bg-tint`) is the shader's background colour, so a
11
+ * palette/theme flip keeps the page hue and only moves the ink. The calm zone
12
+ * is a separate tinted veil over the shell's centre column (`bg-layer.ts`),
13
+ * and the user's 浓度 knob is the wrapper's opacity: the field fades toward the
14
+ * tint without the shader being recompiled.
15
15
  *
16
- * `liquid` also reads the pointer through two extra vec4s (`u_pointer`,
17
- * `u_pulse`): the cursor becomes an eddy that turns the cloud, and a press
18
- * expands a ring from where it landed. `grain` declares `animated:false` and
19
- * never runs a frame loop, so it deliberately ignores both — a static speck
20
- * field that reacts to the mouse would not be static any more.
21
- *
22
- * Styles are self-declared static or animated. A style that does not depend on
23
- * `u_time` draws one frame and never schedules rAF; the caller never has to
24
- * sniff pixels to discover that (readPixels would force a sync far more
25
- * expensive than the frame it saves).
16
+ * A missing WebGL2 context makes `createShaderBackdrop` return null; the
17
+ * caller then falls back to the character tier, exactly like the old WebGL1
18
+ * gate did.
26
19
  * @module @alexpeng/dsh-custom-plugin/client/bg-shader
27
20
  */
28
- import { type BgFocusRect } from './bg-focus.ts';
29
- import { type BgPointerEventLike } from './bg-pointer.ts';
30
- /** Every shader style id. */
31
- export type ShaderStyle = 'liquid' | 'grain';
32
- /** Inclusive numeric bounds for the future settings panel. */
21
+ import type { ShaderMountUniforms } from '@paper-design/shaders';
22
+ /** Every shader style id. Each one is a different Paper Shaders fragment
23
+ * shader, not one field with different knobs. */ export type ShaderStyle = 'mesh' | 'smoke' | 'rays' | 'dither' | 'grain' | 'warp' | 'swirl' | 'metaballs' | 'voronoi' | 'spiral' | 'neuro';
24
+ /** Inclusive numeric bounds for the settings panel. */
33
25
  export interface ShaderRange {
34
26
  readonly min: number;
35
27
  readonly max: number;
36
28
  }
37
- /** Writable bounds per style; defaults sit inside these. */
29
+ /** Writable bounds per style. */
38
30
  export interface ShaderStyleRanges {
39
31
  readonly speed: ShaderRange;
40
- readonly density: ShaderRange;
41
32
  readonly intensity: ShaderRange;
42
- readonly seed: ShaderRange;
43
- readonly fps: ShaderRange;
33
+ readonly opacity: ShaderRange;
44
34
  }
45
- /** Tunables of one style. `animated: false` means "draw one frame, never
46
- * schedule rAF" — a physical property of the shader, not a runtime guess. */
35
+ /** Tunables of one style. `animated: false` means the shader only draws when
36
+ * a uniform changes; Paper's mount handles the rAF stop for speed 0. */
47
37
  export interface ShaderStyleSpec {
48
38
  readonly speed: number;
49
- readonly density: number;
50
39
  readonly intensity: number;
51
- readonly seed: number;
52
- readonly fps: number;
40
+ readonly opacity: number;
53
41
  readonly animated: boolean;
54
- /** Per-style multiplier on the theme's base ΔL (see `inkFor`). The user's
55
- * soft/standard/strong strength choice multiplies this again. */
56
- readonly inkScale: number;
57
42
  readonly ranges: ShaderStyleRanges;
58
43
  }
59
- /**
60
- * Two deliberately different pieces rather than one field with knobs:
61
- * `liquid` is a low-frequency domain-warped ink cloud that drifts; `grain` is
62
- * a fine, static film grain with a soft edge falloff. Both derive their ink
63
- * from the surface brightness, so they work on light, dark and every palette.
64
- */
44
+ /** The shipped styles. `mesh` is the default: a soft, low-contrast field
45
+ * that leaves the copy alone; `dither` is the most graphic one. Defaults are
46
+ * the browser-harness values (1280×822, tint-matched colours, mask on). */
65
47
  export declare const SHADER_STYLES: Record<ShaderStyle, ShaderStyleSpec>;
66
- /** Resolve a stored preset id to a shader style. An ASCII id or any unknown
67
- * string is a stale cross-tier combination and falls back to the default. */
48
+ /** Default style for the shader tier. */
49
+ export declare const DEFAULT_SHADER: ShaderStyle;
50
+ /** Resolve a stored id to a style; ASCII ids and unknown strings fall back. */
68
51
  export declare function resolveShaderStyle(preset: string | undefined): ShaderStyle;
69
- /** Panel overrides for one shader style. Values are clamped into the style's
70
- * own `ranges` before they reach a uniform; `strength` is the user's
71
- * soft/standard/strong multiplier on the ink step (clamped to the ink band). */
72
- export type ShaderParams = Partial<Record<'speed' | 'density' | 'intensity' | 'fps' | 'strength', number>>;
73
- /**
74
- * Resolve overrides against one style. Missing keys fall back to the style
75
- * default, so a style switch never inherits a value it cannot honour. Returns
76
- * the base spec object itself when nothing is overridden.
77
- */
78
- export declare function resolveShaderSpec(style: ShaderStyle, params: ShaderParams): ShaderStyleSpec;
79
- /** Hard bounds the uniform contract promises, independent of a style. */
80
- export declare const SHADER_UNIFORM_RANGES: {
81
- readonly speed: {
82
- readonly min: 0;
83
- readonly max: 2;
84
- };
85
- readonly density: {
86
- readonly min: 0.5;
87
- readonly max: 2;
88
- };
89
- readonly intensity: {
90
- readonly min: 0;
91
- readonly max: 1;
92
- };
93
- readonly seed: {
94
- readonly min: 0;
95
- readonly max: 9999;
96
- };
97
- };
98
- /** Vertex shader for the single full-screen triangle (GLSL ES 1.00). */
99
- export declare const SHADER_VERTEX_SOURCE = "attribute vec2 a_pos;\nvarying vec2 v_uv;\nvoid main() {\n v_uv = a_pos * 0.5 + 0.5;\n gl_Position = vec4(a_pos, 0.0, 1.0);\n}";
100
- /**
101
- * Fragment shaders, one per style. Both end in `mix(u_surface, u_ink, …)` with
102
- * alpha 1: the layer is the opaque page background while it is mounted, which
103
- * is the same contract the ASCII canvas honours with its surface fill.
104
- */
105
- export declare const SHADER_FRAGMENT_SOURCE: Record<ShaderStyle, string>;
106
- /** Numeric values handed to the GPU for one draw. Plain data so the uniform
107
- * mapping is unit-testable without a GL context. */
108
- export interface ShaderUniformValues {
109
- time: number;
110
- width: number;
111
- height: number;
112
- dpr: number;
113
- surface: [number, number, number];
114
- ink: [number, number, number];
115
- speed: number;
116
- density: number;
117
- intensity: number;
118
- seed: number;
119
- /** `[x, y, w, h]` in CSS px; `w <= 0` disables the mask. */
120
- focus: [number, number, number, number];
121
- focusFeather: number;
122
- focusFloor: number;
123
- /** `[x, y, active, speed]` in CSS px; `active <= 0` disables the eddy. */
124
- pointer: [number, number, number, number];
125
- /** `[x, y, age, active]` in CSS px; `active <= 0` disables the ring. */
126
- pulse: [number, number, number, number];
127
- }
128
- /** One pointer sample for the shader. `speed` is 0..1 (already normalised). */
129
- export interface ShaderPointerInput {
130
- x: number;
131
- y: number;
132
- active: boolean;
133
- speed: number;
134
- }
135
- /** One press sample for the shader; `age` is seconds since the press. */
136
- export interface ShaderPulseInput {
137
- x: number;
138
- y: number;
139
- age: number;
140
- }
141
- /** How long a press ring is allowed to expand, in seconds. */
142
- export declare const SHADER_PULSE_LIFE = 2.6;
143
- /** Inputs for {@link shaderUniforms}; `dark` is derived from the surface. */
144
- export interface ShaderUniformInput {
145
- time: number;
146
- width: number;
147
- height: number;
148
- dpr: number;
149
- spec: ShaderStyleSpec;
150
- surface: string;
151
- /** Multiplier applied by the degradation ladder (L2). */
152
- densityScale?: number;
153
- /** Reading-column calm zone from the appearance painter. */
154
- focus?: BgFocusRect | null;
155
- /** Live pointer sample; absent means "no eddy". */
156
- pointer?: ShaderPointerInput | null;
157
- /** Live press sample; absent or expired means "no ring". */
158
- pulse?: ShaderPulseInput | null;
159
- }
160
- /**
161
- * Map runtime state onto the uniform contract. Visibility time is clamped at
162
- * zero; resolution is CSS pixels (never backing pixels); dpr honours the same
163
- * 2× cap as the ASCII tier; density and the other knobs stay inside the
164
- * documented ranges even if a future panel or a hand-edited state file writes
165
- * something else. The ink is `inkFor(surface, dark)` so both tiers use exactly
166
- * the same lightness delta.
167
- */
168
- export declare function shaderUniforms(input: ShaderUniformInput): ShaderUniformValues;
169
- /** The GL call surface this renderer uses (kept structural for tests). */
170
- export interface ShaderGL {
171
- readonly VERTEX_SHADER: number;
172
- readonly FRAGMENT_SHADER: number;
173
- readonly COMPILE_STATUS: number;
174
- readonly LINK_STATUS: number;
175
- readonly ARRAY_BUFFER: number;
176
- readonly STATIC_DRAW: number;
177
- readonly FLOAT: number;
178
- readonly TRIANGLES: number;
179
- readonly COLOR_BUFFER_BIT: number;
180
- createShader(type: number): object | null;
181
- shaderSource(shader: object, source: string): void;
182
- compileShader(shader: object): void;
183
- getShaderParameter(shader: object, pname: number): boolean;
184
- getShaderInfoLog(shader: object): string | null;
185
- deleteShader(shader: object): void;
186
- createProgram(): object | null;
187
- attachShader(program: object, shader: object): void;
188
- linkProgram(program: object): void;
189
- getProgramParameter(program: object, pname: number): boolean;
190
- getProgramInfoLog(program: object): string | null;
191
- deleteProgram(program: object): void;
192
- useProgram(program: object | null): void;
193
- createBuffer(): object | null;
194
- bindBuffer(target: number, buffer: object | null): void;
195
- bufferData(target: number, data: Float32Array, usage: number): void;
196
- deleteBuffer(buffer: object): void;
197
- getAttribLocation(program: object, name: string): number;
198
- enableVertexAttribArray(index: number): void;
199
- vertexAttribPointer(index: number, size: number, type: number, normalized: boolean, stride: number, offset: number): void;
200
- getUniformLocation(program: object, name: string): object | null;
201
- uniform1f(location: object | null, value: number): void;
202
- uniform2f(location: object | null, x: number, y: number): void;
203
- uniform3f(location: object | null, x: number, y: number, z: number): void;
204
- uniform4f(location: object | null, x: number, y: number, z: number, w: number): void;
205
- viewport(x: number, y: number, width: number, height: number): void;
206
- drawArrays(mode: number, first: number, count: number): void;
207
- clearColor(r: number, g: number, b: number, a: number): void;
208
- clear(mask: number): void;
209
- getExtension(name: string): unknown;
210
- getParameter(pname: number): unknown;
211
- }
212
- /** WebGL context attributes the spec fixes. */
213
- export interface ShaderContextAttributes {
214
- readonly alpha: boolean;
215
- readonly antialias: boolean;
216
- readonly depth: boolean;
217
- readonly stencil: boolean;
218
- readonly powerPreference: 'low-power';
219
- }
220
- /** The canvas surface this renderer owns. */
221
- export interface ShaderCanvasLike {
222
- width: number;
223
- height: number;
224
- className: string;
225
- style: {
226
- width: string;
227
- height: string;
228
- };
229
- getContext(contextId: 'webgl', attributes?: ShaderContextAttributes): ShaderGL | null;
230
- addEventListener(type: 'webglcontextlost', listener: (event: ShaderContextLostEvent) => void): void;
231
- removeEventListener(type: 'webglcontextlost', listener: (event: ShaderContextLostEvent) => void): void;
232
- remove(): void;
233
- }
234
- /** The only context-loss field this renderer reads. */
235
- export interface ShaderContextLostEvent {
236
- preventDefault(): void;
237
- }
238
- /** The host element (`div#vx-bg`) as this renderer sees it. */
52
+ /** Panel overrides; every value is clamped into the style's own ranges. */
53
+ export interface ShaderParams {
54
+ readonly speed?: number;
55
+ readonly intensity?: number;
56
+ readonly opacity?: number;
57
+ /** Ink-strength multiplier from `BG_STRENGTH_SCALE`. */
58
+ readonly strength?: number;
59
+ }
60
+ /** Resolved values after merging overrides with the style defaults. */
61
+ export interface ShaderResolved {
62
+ readonly speed: number;
63
+ readonly intensity: number;
64
+ readonly opacity: number;
65
+ readonly strength: number;
66
+ }
67
+ export declare function resolveShaderSpec(style: ShaderStyle, params: ShaderParams): ShaderResolved;
68
+ /** The colour set one shader field is built from. All colours are derived from
69
+ * the page tint and the theme's ink, so the palette never turns neon. */
70
+ export interface ShaderPalette {
71
+ readonly back: string;
72
+ readonly ink: string;
73
+ /** The ink lifted further on dark surfaces; used by small, localised
74
+ * shapes (metaballs) that would otherwise disappear into the dark tint. */
75
+ readonly strongInk: string;
76
+ readonly soft: string;
77
+ readonly mid: string;
78
+ readonly deep: string;
79
+ }
80
+ /** Blend two `#rrggbb` colours; `t = 0` is `a`, `t = 1` is `b`. */
81
+ export declare function mixHex(a: string, b: string, t: number): string;
82
+ /** Theme-aware colours for the shader tier. `strength` scales how far the
83
+ * field colours travel from the tint toward the ink. */
84
+ export declare function shaderPalette(tint: string, dark: boolean, strength: number): ShaderPalette;
85
+ /** Styles whose uniform set carries the shared noise sampler. Keep this in
86
+ * sync with the `u_noiseTexture` branches in `shaderUniformsFor`; the remount
87
+ * retry only runs for these, otherwise noise-free styles would remount on
88
+ * every tick because their uniforms never contain the sampler. */
89
+ export declare const SHADER_NOISE_STYLES: ReadonlySet<ShaderStyle>;
90
+ /** Build one style's uniform set. Exported so a test can pin the mapping
91
+ * between the panel's 强度 knob and each shader's own parameter. */
92
+ export declare function shaderUniformsFor(style: ShaderStyle, palette: ShaderPalette, intensity: number): ShaderMountUniforms;
93
+ /** Host element (`div#vx-bg`) as the shader wrapper sees it. */
239
94
  export interface ShaderHostLike {
240
95
  readonly clientWidth: number;
241
96
  readonly clientHeight: number;
242
97
  getAttribute(name: string): string | null;
243
- appendChild(node: ShaderCanvasLike): unknown;
98
+ appendChild(node: ShaderElementLike): unknown;
244
99
  style: {
245
100
  getPropertyValue(name: string): string;
246
101
  };
247
102
  }
103
+ /** Wrapper element created inside the host. */
104
+ export interface ShaderElementLike {
105
+ readonly clientWidth: number;
106
+ readonly clientHeight: number;
107
+ style: Record<string, string>;
108
+ remove(): void;
109
+ }
248
110
  /** The slice of `Document` this renderer touches. */
249
111
  export interface ShaderDocLike {
250
- createElement(tag: string): ShaderCanvasLike;
251
- addEventListener(type: 'visibilitychange', listener: () => void): void;
252
- removeEventListener(type: 'visibilitychange', listener: () => void): void;
253
- readonly hidden: boolean;
112
+ createElement(tag: string): ShaderElementLike;
254
113
  }
255
- /** The slice of `MediaQueryList` this renderer touches. */
256
- export interface ShaderMediaQueryLike {
257
- readonly matches: boolean;
258
- addEventListener(type: 'change', listener: () => void): void;
259
- removeEventListener(type: 'change', listener: () => void): void;
260
- }
261
- /** The slice of `ResizeObserver` this renderer touches. */
262
- export interface ShaderResizeObserverLike {
263
- observe(target: unknown): void;
264
- disconnect(): void;
265
- }
266
- /** The slice of `Window` this renderer touches. Pointer listeners are optional
267
- * so a minimal test window without them still boots the tier (the eddy is
268
- * simply inert there). */
114
+ /** Kept for the appearance painter's structural typing; the mount owns window
115
+ * access, so only the pixel ratio is read here. */
269
116
  export interface ShaderWinLike {
270
- readonly devicePixelRatio: number;
271
- readonly innerWidth?: number;
272
- readonly innerHeight?: number;
273
- requestAnimationFrame(callback: (now: number) => void): number;
274
- cancelAnimationFrame(handle: number): void;
275
- matchMedia(query: string): ShaderMediaQueryLike;
276
- ResizeObserver?: new (callback: () => void) => ShaderResizeObserverLike;
277
- addEventListener?(type: string, listener: (event: BgPointerEventLike) => void, options?: {
278
- passive?: boolean;
279
- }): void;
280
- removeEventListener?(type: string, listener: (event: BgPointerEventLike) => void, options?: {
281
- passive?: boolean;
282
- }): void;
283
- }
284
- /** Observable renderer state; the live probe and tests read this. */
117
+ readonly devicePixelRatio?: number;
118
+ }
119
+ /** Backing-store pixel cap for the shader tier. A page background does not
120
+ * need the full 8.3M default; 4M keeps 1920×1080 crisp while roughly halving
121
+ * the fill cost on high-DPR screens. */
122
+ export declare const SHADER_MAX_PIXELS = 4000000;
123
+ /** Clamp the renderer's DPR to the device's own ratio (max 2×). Forcing 2× on
124
+ * a 1×/1.25× display only wastes fill rate for a soft background. */
125
+ export declare function resolveShaderDpr(win: ShaderWinLike): number;
126
+ /** The slice of a canvas event target the context-loss watcher needs. */
127
+ export interface ContextLossTarget {
128
+ addEventListener(type: string, listener: (event: Event) => void): void;
129
+ removeEventListener(type: string, listener: (event: Event) => void): void;
130
+ }
131
+ /** Watch for a lost GPU context. The handler prevents the browser's automatic
132
+ * restore (Paper's mount does not reinitialise its resources) and reports once;
133
+ * the returned function detaches the listener. */
134
+ export declare function attachContextLoss(target: ContextLossTarget, onLost: () => void): () => void;
135
+ /** Observable renderer state. */
285
136
  export interface ShaderBackdropStats {
286
137
  level: number;
287
138
  width: number;
@@ -290,7 +141,6 @@ export interface ShaderBackdropStats {
290
141
  alive: boolean;
291
142
  contextLost: boolean;
292
143
  style: ShaderStyle;
293
- /** Actual back-end string from `WEBGL_debug_renderer_info`, when exposed. */
294
144
  renderer: string | null;
295
145
  }
296
146
  /** Options accepted by {@link createShaderBackdrop}. */
@@ -299,31 +149,20 @@ export interface ShaderBackdropOptions {
299
149
  win: ShaderWinLike;
300
150
  host: ShaderHostLike;
301
151
  style?: ShaderStyle;
302
- /** Panel overrides for the boot style; clamps to its `ranges`. */
303
152
  params?: ShaderParams;
304
- /** Called once when the GPU drops this context. The caller falls back to
305
- * ASCII; this renderer never tries to recover on its own. */
153
+ /** Called once when the GPU drops this context; the caller falls back to the
154
+ * character tier. Paper's mount does not recover on its own. */
306
155
  onFallback?: (reason: 'context-lost') => void;
307
156
  }
308
157
  /** Handle owned by the appearance painter. */
309
158
  export interface ShaderBackdrop {
310
159
  sync(): void;
311
- /** Rebuild the program for another style. False means compile failed and
312
- * the previous style is still live, so the caller can fall back. */
160
+ /** Rebuild the mount for another style. False means WebGL2 creation failed
161
+ * and the caller should fall back to the character tier. */
313
162
  setStyle(style: ShaderStyle): boolean;
314
- /** Replace the panel overrides for the current style. Values are clamped
315
- * into that style's `ranges`; a style switch keeps the overrides and
316
- * re-clamps them. Repaints immediately so a dragging slider is visible. */
317
163
  setParams(params: ShaderParams): void;
318
- /** Move the calm zone (the reading column); `null` disables the mask. */
319
- setFocus(rect: BgFocusRect | null): void;
320
164
  destroy(): void;
321
165
  readonly stats: ShaderBackdropStats;
322
166
  }
323
- /**
324
- * Create the shader backdrop and attach its canvas. Returns null when WebGL1
325
- * is unavailable or the program does not compile; in that case the canvas is
326
- * removed and no context is left alive, and the caller falls back to ASCII and
327
- * tells the user.
328
- */
167
+ /** Create the shader tier. Returns null when WebGL2 is unavailable. */
329
168
  export declare function createShaderBackdrop(options: ShaderBackdropOptions): ShaderBackdrop | null;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The ambient layer: a decorative, static colour field below every surface.
3
+ *
4
+ * Glass is only visible when there is something behind it to blur and refract.
5
+ * With a page renderer mounted that is the renderer; with 背景动效 off the page
6
+ * is a flat fill, and a translucent pane over a flat fill looks exactly like an
7
+ * opaque one — the "turning glass on changes nothing" report. This layer is the
8
+ * guarantee that glass always has something to work with. It exists only while
9
+ * glass is on, never while a page renderer is mounted, and it is reverted by the
10
+ * plugin disposer.
11
+ * @module @alexpeng/dsh-custom-plugin/client/glass/ambient
12
+ */
13
+ /** DOM id of the owned ambient node. */
14
+ export declare const AMBIENT_ID = "vx-ambient";
15
+ /** Create or update the layer; a second call only re-paints the background. */
16
+ export declare function mountAmbient(doc: Document, base: string, dark: boolean): HTMLElement | null;
17
+ /** Remove the layer; a missing node is a no-op. */
18
+ export declare function unmountAmbient(doc: Document): void;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * The glass engine: keeps every glass surface in a document on the material the
3
+ * user picked.
4
+ *
5
+ * Three jobs, all of them page-global and therefore reverted by `dispose`:
6
+ *
7
+ * 1. **Tag the host's surfaces.** `host-surfaces.ts` finds them; the engine
8
+ * writes `data-vx-glass="<kind>"` (plus `data-vx-glass-rim` when the
9
+ * element's `::after` is free for our specular rim) so the stylesheet can
10
+ * give each kind its blur budget without knowing a single host class name.
11
+ * 2. **Install the liquid filter.** Liquid needs a per-geometry SVG filter
12
+ * (`liquid-filter.ts`); the engine creates it in one owned `<svg>`, points
13
+ * the surface's `backdrop-filter` at it and rebuilds it when the surface
14
+ * resizes. Frost needs no filter — the stylesheet's blur is enough.
15
+ * 3. **Follow the pointer.** Apple's highlights respond to the light, so the
16
+ * nearest surface gets `--vx-light-x / -y / -angle` from the pointer.
17
+ *
18
+ * Large surfaces (a full-viewport frame, or anything over the pixel budget)
19
+ * stay on the frost blur: a refraction pass over the whole window is the one
20
+ * thing that would cost frames, and Apple's own guidance keeps big persistent
21
+ * surfaces on the regular material.
22
+ * @module @alexpeng/dsh-custom-plugin/client/glass/glass-engine
23
+ */
24
+ import type { Rgba } from './glass-tokens.ts';
25
+ export interface GlassSyncOptions {
26
+ readonly liquid: boolean;
27
+ /** The translucent fills the token set installed, for surface discovery. An
28
+ * empty list means the host's own surfaces are not part of the material. */
29
+ readonly fills: readonly Rgba[];
30
+ readonly dark: boolean;
31
+ /** Whether the host's own surfaces join the material at all. */
32
+ readonly hostSurfaces: boolean;
33
+ }
34
+ /** Plugin-owned surfaces that take the material directly. */
35
+ export declare const PLUGIN_SURFACE_SELECTOR = ".vx-popover, .vx-dialog, .vx-toast, .vx-settings-page.vx-glass-on";
36
+ /** DOM id of the owned filter host. */
37
+ export declare const GLASS_DEFS_ID = "vx-glass-defs";
38
+ /** Above this area a surface keeps the frost blur instead of a lens. */
39
+ export declare const GLASS_MAX_LIQUID_PIXELS = 1200000;
40
+ /**
41
+ * How many surfaces may carry a displacement filter at the same time.
42
+ *
43
+ * Measured in headless Edge: two SVG-filtered backdrops composite fine, a third
44
+ * one stops frame production outright — and the cost is per filter surface, not
45
+ * per pixel, so a small menu on top of a small popover is already too much.
46
+ * That is also Apple's own rule: the lens belongs on floating navigation and
47
+ * overlays, never on a stack of panes. Persistent surfaces (sidebar, panels,
48
+ * cards, inputs) therefore keep the liquid body, blur, rim and pointer
49
+ * highlight and only lose the displacement.
50
+ */
51
+ export declare const GLASS_MAX_LIQUID_SURFACES = 2;
52
+ /**
53
+ * Bring a document in line with the current material. Safe to call on every
54
+ * appearance repaint: identical input re-tags nothing and creates no filter.
55
+ */
56
+ export declare function syncGlassDocument(doc: Document, options: GlassSyncOptions): void;
57
+ /** Revert every page-global effect this engine installed in `doc`. */
58
+ export declare function disposeGlassDocument(doc: Document): void;
@@ -0,0 +1,111 @@
1
+ /**
2
+ * The glass token set: what "glass is on" means for the host's own surfaces.
3
+ *
4
+ * The host paints every surface from `--dsw-*` fill tokens, and the theme
5
+ * runtime applies overrides as inline custom properties on `<body>`, so
6
+ * lowering those fills to a translucent alpha is what makes a surface able to
7
+ * show a blurred / refracted backdrop at all — `backdrop-filter` on an opaque
8
+ * element is invisible by definition, which is why the previous "global glass"
9
+ * switch (a `backdrop-filter` rule on opaque host dialogs and menus) could
10
+ * never change a pixel.
11
+ *
12
+ * Alphas are per material: frost keeps a matte milk tint, liquid is the clearer
13
+ * Apple-style body. Both stay high enough that host copy keeps its contrast over
14
+ * the ambient layer.
15
+ * @module @alexpeng/dsh-custom-plugin/client/glass/glass-tokens
16
+ */
17
+ import { type GlassMode } from '../palette.ts';
18
+ export type { GlassMode };
19
+ /** Palette family the fills are tinted with (null = the host's own colours). */
20
+ export interface GlassFamily {
21
+ readonly base: string;
22
+ readonly tab: string;
23
+ readonly darkBase: string;
24
+ readonly darkTab: string;
25
+ }
26
+ export interface GlassTokenInput {
27
+ readonly mode: GlassMode;
28
+ readonly family: GlassFamily | null;
29
+ /** A page renderer is mounted behind the surfaces. */
30
+ readonly backdrop: boolean;
31
+ /**
32
+ * Whether the host's own surfaces (sidebar, panels, dialogs, menus, cards,
33
+ * inputs) become glass too. With this off only the three content tokens the
34
+ * shell stacks over the page are lowered, which is the minimum that lets the
35
+ * ambient layer or a page renderer reach the eye at all.
36
+ */
37
+ readonly hostSurfaces: boolean;
38
+ }
39
+ /** One resolved colour, used to recognise the surfaces we just re-filled. */
40
+ export interface Rgba {
41
+ readonly r: number;
42
+ readonly g: number;
43
+ readonly b: number;
44
+ readonly a: number;
45
+ }
46
+ export type GlassTokenSet = Record<string, {
47
+ light: string;
48
+ dark: string;
49
+ }>;
50
+ /** Logical surface keys, in the order the host stacks them. */
51
+ export type GlassSurfaceKey = 'base' | 'layer1' | 'layer2' | 'layer3' | 'overlay' | 'sidebar' | 'input' | 'card' | 'settingsCard' | 'toast' | 'tooltip' | 'menu';
52
+ /** The host token each surface key overrides. */
53
+ export declare const GLASS_TOKEN_OF: Record<GlassSurfaceKey, string>;
54
+ /**
55
+ * The host's own fill colours (dsh 0.2.2-rc.5, `dsh-client-ui-theme`
56
+ * design-platform.css). Overriding a token must keep its hue, otherwise turning
57
+ * glass on would recolour the page instead of making it translucent.
58
+ */
59
+ export declare const GLASS_HOST_FILL: Record<GlassSurfaceKey, {
60
+ light: string;
61
+ dark: string;
62
+ }>;
63
+ /**
64
+ * Fill alpha per material, for the surfaces that float above the page. Frost is
65
+ * the matte acrylic pane, liquid the clearer body; both must stay well below
66
+ * 0.85 or the surface reads as an opaque panel and the backdrop disappears
67
+ * again. The first calibration sat at 0.72–0.8 and measured out as "the menu did
68
+ * not change at all", because a 0.72 pane over a smooth ambient is the same
69
+ * colour either way.
70
+ *
71
+ * The three content tokens (`base`, `layer1`, `sidebar`) are not listed here:
72
+ * they always use the calibrated backdrop alphas while glass is on, since the
73
+ * shell stacks them and their product is the page's transmission.
74
+ */
75
+ export declare const GLASS_ALPHA: Record<Exclude<GlassMode, 'off'>, Record<GlassSurfaceKey, number>>;
76
+ /** The mask token the host ships as `none`. Frost keeps the full matte blur;
77
+ * liquid only softens the page a little, because the glass panel in front is
78
+ * clear — blurring the whole backdrop twice (mask + panel lens) is exactly the
79
+ * "设置界面异常模糊" report from the live Desktop. */
80
+ export declare const GLASS_MASK_BLUR: Record<Exclude<GlassMode, 'off'>, string>;
81
+ /**
82
+ * The token override a repaint installs while glass is on, or `null` when glass
83
+ * is off (the painter then keeps its non-glass behaviour).
84
+ */
85
+ export declare function glassTokenSet(input: GlassTokenInput): GlassTokenSet | null;
86
+ /** Parse the `rgba()` / `rgb()` strings this module emits. */
87
+ export declare function parseRgba(value: string): Rgba | null;
88
+ /**
89
+ * Every colour the token set can paint, for the surface scanner: an element
90
+ * whose computed background is one of these is a surface we just made
91
+ * translucent, whatever its class name is.
92
+ */
93
+ export declare function glassFillColors(set: GlassTokenSet | null, dark: boolean): Rgba[];
94
+ /**
95
+ * The ambient layer: soft colour fields over the page tint. Glass needs
96
+ * something to blur and refract; without it a translucent pane over a flat page
97
+ * is indistinguishable from an opaque one, which is exactly the "turning glass
98
+ * on changes nothing" report. The first calibration was deliberately timid and
99
+ * measured out as no change at all on a near-white page (sidebar 0.7 luma, menu
100
+ * 0.3 luma), so the fields are now strong enough to read as a wallpaper: the
101
+ * shell's own fills stay at 50–80% alpha, which keeps body copy legible over
102
+ * them. The layer only exists while glass is on and no page renderer supplies
103
+ * texture of its own.
104
+ */
105
+ export declare function ambientBackground(base: string, dark: boolean): string;
106
+ /**
107
+ * The matte grain of the frost material: monochrome fractal noise, blended as
108
+ * an overlay. It is what separates "frosted" from "blurred white" (the noise
109
+ * layer is part of Microsoft's Acrylic recipe).
110
+ */
111
+ export declare function noiseDataUrl(): string;