@alexpeng/dsh-custom-plugin 0.12.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.
package/lib/index.js CHANGED
@@ -95,6 +95,8 @@ const MERMAID_SCRIPT_PATH = "/custom-plugin/mermaid.js";
95
95
  const BG_FX_ASCII_PRESETS = [
96
96
  "sharks",
97
97
  "jellyfish",
98
+ "robots",
99
+ "dog",
98
100
  "reef",
99
101
  "night",
100
102
  "turtle",
@@ -118,12 +120,16 @@ const BG_FX_SHADER_STYLES = [
118
120
  "dither",
119
121
  "grain",
120
122
  "warp",
121
- "swirl"
123
+ "swirl",
124
+ "metaballs",
125
+ "voronoi",
126
+ "spiral",
127
+ "neuro"
122
128
  ];
123
129
  /** Default configuration (also the composition-layer default). */
124
130
  const DEFAULT_CONFIG = {
125
131
  bg: "天青灰",
126
- bgFx: "none",
132
+ bgFx: "ascii",
127
133
  bgFxPreset: "sharks",
128
134
  bgAsciiPreset: "sharks",
129
135
  bgShaderPreset: "mesh",
@@ -392,8 +398,10 @@ function normalizeCfg(raw) {
392
398
  if (typeof value === "string") cfg[key] = value;
393
399
  }
394
400
  }
395
- if (typeof src.bgFx === "boolean") cfg.bgFx = src.bgFx ? "ascii" : "none";
396
- if (cfg.bgFx !== "none" && cfg.bgFx !== "ascii" && cfg.bgFx !== "shader") cfg.bgFx = "none";
401
+ if (src.bgFx !== void 0) {
402
+ if (typeof src.bgFx === "boolean") cfg.bgFx = src.bgFx ? "ascii" : "none";
403
+ else if (src.bgFx !== "none" && src.bgFx !== "ascii" && src.bgFx !== "shader") cfg.bgFx = "none";
404
+ }
397
405
  const shaderTier = cfg.bgFx === "shader";
398
406
  const isAsciiPreset = (value) => typeof value === "string" && BG_FX_ASCII_PRESETS.includes(value);
399
407
  const isShaderPreset = (value) => typeof value === "string" && BG_FX_SHADER_STYLES.includes(value);
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Shell-column measurement for the calm zone. The shell is a three-column
3
+ * grid (sidebar | centre | right panel) with hashed class names, so the centre
4
+ * column is found geometrically instead of by selector:
5
+ *
6
+ * - walk up from the composer to the nearest ancestor that spans ≥75% of the
7
+ * viewport and is ≥60% of its height — the shell frame;
8
+ * - inside it, the direct child that contains the composer is the centre
9
+ * column; at least one tall narrow sibling (sidebar/rail or right panel)
10
+ * must exist, otherwise there is no chrome to protect and the caller keeps
11
+ * the old single-rect behaviour;
12
+ * - the centre column must be at least 320×240 so a transient layout (or a
13
+ * hidden panel) cannot become the calm-zone bounds.
14
+ *
15
+ * The observer-driven veil needs the centre element, not only its rectangle;
16
+ * both wrappers below share the same walk.
17
+ *
18
+ * The DOM is injected structurally so the rule is unit-testable without jsdom.
19
+ */
20
+ /** Rectangle in CSS pixels, top-left origin, viewport coordinates. */
21
+ export interface BgColumnRect {
22
+ x: number;
23
+ y: number;
24
+ w: number;
25
+ h: number;
26
+ }
27
+ /** Minimal DOM node surface the measurement needs. */
28
+ export interface ColumnNodeLike {
29
+ getBoundingClientRect(): {
30
+ left: number;
31
+ top: number;
32
+ width: number;
33
+ height: number;
34
+ };
35
+ readonly parentElement: ColumnNodeLike | null;
36
+ readonly children: ArrayLike<ColumnNodeLike>;
37
+ contains(other: ColumnNodeLike): boolean;
38
+ }
39
+ /** Minimal document surface; only the body is used as the walk sentinel. */
40
+ export interface ColumnDocLike {
41
+ readonly body: ColumnNodeLike;
42
+ }
43
+ /** The centre column's DOM node, for a `ResizeObserver` that tracks its
44
+ * geometry frame-by-frame. */
45
+ export declare function findCenterColumnElement(doc: ColumnDocLike, anchor: ColumnNodeLike, viewportWidth: number, viewportHeight: number): ColumnNodeLike | null;
46
+ export declare function measureCenterColumn(doc: ColumnDocLike, anchor: ColumnNodeLike, viewportWidth: number, viewportHeight: number): BgColumnRect | null;
@@ -125,3 +125,52 @@ export type BgLayerMountVerdict = Extract<BgLayerVerdict, {
125
125
  export declare function mountBgLayer(doc: BgLayerDocLike, verdict: BgLayerMountVerdict, tint: string): BgLayerElementLike;
126
126
  /** Remove the layer; a missing node is a no-op (fresh install / already off). */
127
127
  export declare function unmountBgLayer(doc: BgLayerDocLike): void;
128
+ /**
129
+ * Publish the calm veil's fill base on the layer. Dark mode reads it instead of
130
+ * the page tint, so the veil can fill with the scene's own visible base and
131
+ * only reduce local contrast (see `sceneVeilBase`); using the page tint over a
132
+ * bright lagoon is what turned the rectangle into a dark slab. Light mode keeps
133
+ * reading `--vx-bg-tint`, so setting this variable there is a harmless no-op.
134
+ */
135
+ export declare function setBgVeilBase(doc: BgLayerDocLike, base: string): void;
136
+ /** Per-scene calm-veil recipe. Strings keep one helper usable from the scene
137
+ * wrapper (which owns the family) and the shader fallback in the client. */
138
+ export interface BgVeilLook {
139
+ readonly alpha: string;
140
+ readonly blur: string;
141
+ readonly feather: string;
142
+ }
143
+ /**
144
+ * Apply the active scene family's veil recipe. The values are set inline on the
145
+ * veil, so they win over the stylesheet defaults; light mode uses the same
146
+ * 44% / 15px / 16px recipe as before, dark mode narrows the ambient blur so
147
+ * fireflies and other small lights survive, keeps ink glyphs legible, and
148
+ * leaves bright paintings with the wider feather.
149
+ */
150
+ export declare function setBgVeilLook(doc: BgLayerDocLike, look: BgVeilLook): void;
151
+ /** DOM id of the rectangular content veil inside the background layer. */
152
+ export declare const BG_VEIL_ID = "vx-bg-veil";
153
+ /** The veil's rectangle, viewport CSS px. */
154
+ export interface BgVeilRect {
155
+ x: number;
156
+ y: number;
157
+ w: number;
158
+ h: number;
159
+ }
160
+ /**
161
+ * The veil is one tinted DOM box over the shell's centre column. It replaces
162
+ * the canvas alpha mask: the faded region is always the same rectangle as the
163
+ * column (no diagonal/rounded feather shape), it can cover the whole column
164
+ * including the header/blank top, and its geometry is a CSS transition target
165
+ * so opening or closing a sidebar slides the faded area instead of flashing a
166
+ * new mask image.
167
+ */
168
+ export declare function ensureBgVeil(doc: BgLayerDocLike): BgLayerElementLike | null;
169
+ /**
170
+ * Place/hide the veil. The first placement is instant (`data-ready` is set in
171
+ * the next frame, after the geometry has been painted); later moves animate
172
+ * through the CSS transition. Outside the rectangle the background stays at
173
+ * full strength, which is what keeps the sidebars, logo and right panel from
174
+ * losing their texture.
175
+ */
176
+ export declare function applyBgVeil(doc: BgLayerDocLike, rect: BgVeilRect | null, visible: boolean): void;
@@ -11,19 +11,17 @@
11
11
  * glyphs darken/lighten it.
12
12
  * - `lagoon` scenes are full-canvas paintings with their own authored colours
13
13
  * (reef/night/turtle/manta/…). They cannot be re-paletted, so the wrapper
14
- * keeps them at the preset's own opacity over the page tint and lets the
15
- * calm-zone mask dim the reading column.
14
+ * keeps them at the preset's own opacity over the page tint.
16
15
  *
17
- * The calm zone is applied as a CSS `mask-image` built from the same
18
- * `focusWeight` geometry the old renderer used (`bg-focus.ts`), regenerated
19
- * only when the zone actually moves. DPR, visibility pausing, reduced motion
20
- * and resize are owned by the scene runtime inside `ascii-things`.
16
+ * The calm zone is a separate tinted veil over the shell's centre column
17
+ * (`bg-layer.ts`), not a canvas mask: the renderer does not know where the
18
+ * content is. DPR, visibility pausing, reduced motion and resize are owned by
19
+ * the scene runtime inside `ascii-things`.
21
20
  * @module @alexpeng/dsh-custom-plugin/client/bg-scene
22
21
  */
23
22
  import type { Palette } from 'ascii-things';
24
- import type { BgFocusRect } from './bg-focus.ts';
25
23
  /** Scene ids the character tier can mount. */
26
- export type ScenePreset = 'sharks' | 'jellyfish' | 'reef' | 'night' | 'turtle' | 'manta' | 'dolphin' | 'seahorse' | 'hammerhead' | 'tang' | 'koi' | 'starlings' | 'fireflies' | 'city' | 'servers';
24
+ export type ScenePreset = 'sharks' | 'jellyfish' | 'robots' | 'dog' | 'reef' | 'night' | 'turtle' | 'manta' | 'dolphin' | 'seahorse' | 'hammerhead' | 'tang' | 'koi' | 'starlings' | 'fireflies' | 'city' | 'servers';
27
25
  /** Scene family: palette-driven ink, a full-colour lagoon painting, or a dark
28
26
  * ambient scene (koi pond, starlings, city…). */
29
27
  export type SceneKind = 'ink' | 'lagoon' | 'ambient';
@@ -54,6 +52,13 @@ export interface SceneSpec {
54
52
  /** Ambient paintings are authored on a dark backdrop and only make sense on
55
53
  * a dark page; the wrapper falls back to `sharks` in light mode. */
56
54
  readonly theme?: 'dark';
55
+ /** Average colour of the authored canvas, sampled before the page tint and
56
+ * the wrapper opacity are applied (headless Edge, ascii-things 1.1.1,
57
+ * 2026-12-06). Dark mode fills the calm veil with this colour instead of the
58
+ * page tint, so the rectangle only lowers local contrast and never shifts
59
+ * the scene's luminance. Ink scenes omit it: their `screen` composite leaves
60
+ * the tint itself as the visible base. */
61
+ readonly veilBase?: string;
57
62
  readonly ranges: SceneRanges;
58
63
  }
59
64
  /** The shipped scene list. Every entry is a distinct scene from ascii-things —
@@ -97,20 +102,65 @@ export interface SceneLook {
97
102
  readonly blend: 'multiply' | 'screen' | 'normal';
98
103
  readonly filter: string;
99
104
  }
105
+ /**
106
+ * Target luma of the *visible* scene base in dark mode, after the wrapper
107
+ * opacity and the exposure are applied. 88 keeps the bright lagoon paintings
108
+ * readable as colour on a dark page instead of nearly black, while the
109
+ * content column still lands below the old bright lagoon sides and the veil
110
+ * base matches the scene so no rectangle appears. Tune this one number, not
111
+ * the veil alpha, when the dark aquarium needs to be brighter or dimmer.
112
+ */
113
+ export declare const DARK_SCENE_TARGET_LUMA = 88;
114
+ /** Dark-mode brightness lift for the near-black ambient scenes. Fireflies and
115
+ * the other night paintings are mostly black with tiny lights; at the shell's
116
+ * 40% transmission they read as an empty page. The lift makes the lights
117
+ * survive without turning the background into a lit panel. */
118
+ export declare const DARK_AMBIENT_BOOST = 1.35;
100
119
  /** Visual treatment for one scene. Ink scenes always follow the theme;
101
120
  * lagoons keep their authored colour unless the user turns on 单色印刷, which
102
121
  * grayscales them and lets the page tint supply the duotone. Ambient scenes
103
- * are dark-only and composite normally. */
104
- export declare function sceneLook(spec: SceneSpec, dark: boolean, lagoonInk: boolean, opacity: number): SceneLook;
122
+ * are dark-only and composite normally.
123
+ *
124
+ * `exposure` is the dark-mode global dim computed by {@link sceneExposure}. It
125
+ * is applied to the canvas itself, never to the calm veil: a rectangular veil
126
+ * that dims a bright painting is exactly what made the content column read as
127
+ * a pasted dark slab. */
128
+ export declare function sceneLook(spec: SceneSpec, dark: boolean, lagoonInk: boolean, opacity: number, exposure?: number): SceneLook;
129
+ /** Per-family calm-veil recipe. The veil lowers local contrast behind the
130
+ * transcript; it must not erase the scene. Glyph scenes draw at 8–14px, so a
131
+ * backdrop blur of even a few pixels merges neighbouring characters into flat
132
+ * blobs (the reported "背景动效全部糊没了") — ink and ambient scenes keep 0px
133
+ * and the tint does the calming. Only the painted lagoons, whose texture is
134
+ * much larger than a glyph, keep a small softening pass. The dark ambient
135
+ * scenes get the lightest tint so fireflies and other small lights survive. */
136
+ export interface SceneVeilLook {
137
+ readonly alpha: string;
138
+ readonly blur: string;
139
+ readonly feather: string;
140
+ }
141
+ export declare function sceneVeilLook(kind: SceneKind, dark: boolean): SceneVeilLook;
142
+ /**
143
+ * Dark-mode exposure for a scene, derived from its sampled canvas base and the
144
+ * resolved opacity. Ink scenes leave the tint as their base, ambient scenes
145
+ * already sit below the target, and the dark lagoon variant is dark enough, so
146
+ * all three return 1. Bright lagoon paintings are dimmed *globally* here; the
147
+ * calm veil must never be the thing that darkens the content column.
148
+ */
149
+ export declare function sceneExposure(spec: SceneSpec, tint: string, dark: boolean, opacity: number): number;
150
+ /**
151
+ * The colour the dark calm veil fills with: the scene's own visible base
152
+ * (authored average → exposure → opacity × tint), not the page tint. Matching
153
+ * the base is what makes the veil only reduce local contrast; using the page
154
+ * tint instead turns it into a dark slab over bright lagoons and a light grey
155
+ * panel over near-black ambient scenes.
156
+ */
157
+ export declare function sceneVeilBase(spec: SceneSpec, tint: string, dark: boolean, opacity: number, exposure?: number): string;
105
158
  /**
106
159
  * Build the palette the ink scenes render with. The page tint supplies the
107
160
  * ink hue (through `inkFor`'s lightness step), and the five fish levels become
108
161
  * alphas of that single colour, so the scene stays monochrome and theme-aware.
109
162
  */
110
163
  export declare function scenePalette(tint: string, dark: boolean, strength: number): Palette;
111
- /** Build a quarter-resolution alpha mask as a data URL. Thin wrapper over the
112
- * shared calm-zone builder so both open-source renderers use one geometry. */
113
- export declare function buildSceneMask(doc: SceneDocLike, rect: BgFocusRect, width: number, height: number, scale?: number): string | null;
114
164
  /** The slice of a canvas element this module touches. */
115
165
  export interface SceneCanvasLike {
116
166
  width: number;
@@ -162,8 +212,11 @@ export interface SceneBackdrop {
162
212
  setPreset(preset: ScenePreset): void;
163
213
  setParams(params: SceneParams): void;
164
214
  setLagoonInk(on: boolean): void;
165
- setFocus(rect: BgFocusRect | null): void;
166
215
  setTint(tint: string, dark: boolean): void;
216
+ /** Visible scene base for the dark calm veil (see {@link sceneVeilBase}). */
217
+ veilBase(): string;
218
+ /** Per-family veil recipe for the current theme (see {@link sceneVeilLook}). */
219
+ veilLook(): SceneVeilLook;
167
220
  destroy(): void;
168
221
  }
169
222
  /** Create the scene canvas and mount the active ascii-things engine. */
@@ -9,9 +9,9 @@
9
9
  *
10
10
  * The page tint (`--vx-bg-tint`) is the shader's background colour, so a
11
11
  * palette/theme flip keeps the page hue and only moves the ink. The calm zone
12
- * is a CSS `mask-image` built from the same geometry as the scene tier
13
- * (`bg-focus.ts`), and the user's 浓度 knob is the wrapper's opacity: the
14
- * field fades toward the tint without the shader being recompiled.
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
16
  * A missing WebGL2 context makes `createShaderBackdrop` return null; the
17
17
  * caller then falls back to the character tier, exactly like the old WebGL1
@@ -19,10 +19,8 @@
19
19
  * @module @alexpeng/dsh-custom-plugin/client/bg-shader
20
20
  */
21
21
  import type { ShaderMountUniforms } from '@paper-design/shaders';
22
- import { FOCUS_FEATHER_PX, FOCUS_FLOOR, type BgFocusRect } from './bg-focus.ts';
23
22
  /** Every shader style id. Each one is a different Paper Shaders fragment
24
- * shader, not one field with different knobs. */
25
- export type ShaderStyle = 'mesh' | 'smoke' | 'rays' | 'dither' | 'grain' | 'warp' | 'swirl';
23
+ * shader, not one field with different knobs. */ export type ShaderStyle = 'mesh' | 'smoke' | 'rays' | 'dither' | 'grain' | 'warp' | 'swirl' | 'metaballs' | 'voronoi' | 'spiral' | 'neuro';
26
24
  /** Inclusive numeric bounds for the settings panel. */
27
25
  export interface ShaderRange {
28
26
  readonly min: number;
@@ -43,7 +41,7 @@ export interface ShaderStyleSpec {
43
41
  readonly animated: boolean;
44
42
  readonly ranges: ShaderStyleRanges;
45
43
  }
46
- /** The five shipped styles. `mesh` is the default: a soft, low-contrast field
44
+ /** The shipped styles. `mesh` is the default: a soft, low-contrast field
47
45
  * that leaves the copy alone; `dither` is the most graphic one. Defaults are
48
46
  * the browser-harness values (1280×822, tint-matched colours, mask on). */
49
47
  export declare const SHADER_STYLES: Record<ShaderStyle, ShaderStyleSpec>;
@@ -72,6 +70,9 @@ export declare function resolveShaderSpec(style: ShaderStyle, params: ShaderPara
72
70
  export interface ShaderPalette {
73
71
  readonly back: string;
74
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;
75
76
  readonly soft: string;
76
77
  readonly mid: string;
77
78
  readonly deep: string;
@@ -81,6 +82,11 @@ export declare function mixHex(a: string, b: string, t: number): string;
81
82
  /** Theme-aware colours for the shader tier. `strength` scales how far the
82
83
  * field colours travel from the tint toward the ink. */
83
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>;
84
90
  /** Build one style's uniform set. Exported so a test can pin the mapping
85
91
  * between the panel's 强度 knob and each shader's own parameter. */
86
92
  export declare function shaderUniformsFor(style: ShaderStyle, palette: ShaderPalette, intensity: number): ShaderMountUniforms;
@@ -155,13 +161,8 @@ export interface ShaderBackdrop {
155
161
  * and the caller should fall back to the character tier. */
156
162
  setStyle(style: ShaderStyle): boolean;
157
163
  setParams(params: ShaderParams): void;
158
- /** Move the calm zone (the reading column); `null` disables the mask. */
159
- setFocus(rect: BgFocusRect | null): void;
160
164
  destroy(): void;
161
165
  readonly stats: ShaderBackdropStats;
162
166
  }
163
167
  /** Create the shader tier. Returns null when WebGL2 is unavailable. */
164
168
  export declare function createShaderBackdrop(options: ShaderBackdropOptions): ShaderBackdrop | null;
165
- /** Re-exported so the panel can mention the calm-zone constants without
166
- * importing the focus module twice. */
167
- export { FOCUS_FEATHER_PX, FOCUS_FLOOR };
@@ -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;
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Host surface discovery for the glass materials.
3
+ *
4
+ * The shell paints its surfaces from CSS Modules, so every class name is a
5
+ * build hash (`mP3x-q_frame`, `_surface_1w4el_1`, …) and no stylesheet can
6
+ * target them. What *is* stable is the colour: while glass is on, the plugin
7
+ * lowers the host fill tokens to known translucent alphas, so an element whose
8
+ * computed background is one of those colours is a surface we just made
9
+ * translucent — whatever its class is. Floating surfaces are found by role
10
+ * instead, because they appear and disappear at runtime.
11
+ *
12
+ * Discovery is therefore version-agnostic and needs no host source change.
13
+ * @module @alexpeng/dsh-custom-plugin/client/glass/host-surfaces
14
+ */
15
+ import type { Rgba } from './glass-tokens.ts';
16
+ /** What a tagged surface is, which decides its blur budget and optics. */
17
+ export type HostGlassKind = 'surface' | 'sidebar' | 'panel' | 'dialog' | 'menu' | 'tooltip' | 'toast' | 'card' | 'input';
18
+ export interface HostGlassTarget {
19
+ readonly el: HTMLElement;
20
+ readonly kind: HostGlassKind;
21
+ /** Floating layers (dialog / menu / tooltip) may sit on top of another
22
+ * glass surface; everything else must not stack glass on glass. */
23
+ readonly floating: boolean;
24
+ }
25
+ export interface HostViewport {
26
+ readonly width: number;
27
+ readonly height: number;
28
+ }
29
+ /** Role / attribute selectors the shell's floating layers carry. */
30
+ export declare const HOST_FLOATING_SELECTORS: Array<{
31
+ selector: string;
32
+ kind: HostGlassKind;
33
+ }>;
34
+ /** Viewport sampling grid. Big surfaces are hit by many points; small cards by
35
+ * at least one, and the cost stays at ~130 hit tests instead of a full-tree
36
+ * computed-style walk. */
37
+ export declare const HOST_SCAN_COLUMNS = 14;
38
+ export declare const HOST_SCAN_ROWS = 9;
39
+ /**
40
+ * Parse a computed `background-color`. Chromium returns `rgb()` / `rgba()` for
41
+ * legacy colours and `color(srgb …)` for `color-mix()` results; anything else
42
+ * (oklch, a gradient keyword, an empty value) is reported as unknown so the
43
+ * caller never matches a surface it cannot reason about.
44
+ */
45
+ export declare function parseCssColor(value: string): Rgba | null;
46
+ /** Whether a surface colour is one of the fills the token set installed. */
47
+ export declare function matchesFill(color: Rgba, fills: readonly Rgba[]): boolean;
48
+ /**
49
+ * Whether a discovered surface keeps the material. Frost leaves a surface that
50
+ * already carries its own backdrop filter alone (the shell's menu material),
51
+ * but that check must not run on a surface we tagged in an earlier pass: our
52
+ * own `[data-vx-glass]` rule supplies the blur, so reading the computed filter
53
+ * would classify it as "host-provided" and untag it again. That exact
54
+ * re-scan flipped the sidebar and centre panel off 250 ms after they came on.
55
+ */
56
+ export declare function keepsHostSurface(alreadyTagged: boolean, liquid: boolean, selfBackdropFilter: string): boolean;
57
+ /**
58
+ * Whether a surface of this kind suppresses the glass of the surfaces nested
59
+ * inside it. This is the "no glass on glass" rule for one pane inside another:
60
+ * a card inside a glass panel does not need its own backdrop pass. The
61
+ * full-window frame is the exception — it deliberately carries no filter
62
+ * (kind `surface`), so it must never silence the sidebar and the centre panel
63
+ * inside it. That exact case removed every real surface on Desktop 0.2.2-rc.5.
64
+ */
65
+ export declare function suppressesDescendants(kind: HostGlassKind): boolean;
66
+ /**
67
+ * Remove surfaces that sit inside another glass surface. The map is keyed by
68
+ * element, so the parent walk is the only DOM part; the decision itself is
69
+ * `suppressesDescendants`.
70
+ */
71
+ export declare function dropNestedSurfaces<T extends {
72
+ kind: HostGlassKind;
73
+ floating: boolean;
74
+ }>(accepted: Map<Element, T>, parentOf: (el: Element) => Element | null): void;
75
+ export declare function classifyContainer(rect: {
76
+ width: number;
77
+ height: number;
78
+ }, viewport: HostViewport, hasTextbox: boolean): HostGlassKind | null;
79
+ /**
80
+ * Whether an ancestor truncates the backdrop the surface could sample. This is
81
+ * the most common reason a `backdrop-filter` "does nothing": the element is
82
+ * inside a `filter` / `opacity` / `mask` / `clip-path` / `mix-blend-mode`
83
+ * ancestor, so the sampled region stops there. An ancestor's own
84
+ * `backdrop-filter` also establishes a root, but that is the glass-on-glass
85
+ * case we deliberately keep (the child still refracts the parent pane).
86
+ */
87
+ export declare function backdropRootBlocked(el: HTMLElement, view: Window): boolean;
88
+ export interface HostScanOptions {
89
+ readonly doc: Document;
90
+ readonly viewport: HostViewport;
91
+ readonly fills: readonly Rgba[];
92
+ /** Elements the scanner must ignore (plugin-owned subtrees and layers). */
93
+ readonly ignore?: (el: Element) => boolean;
94
+ }
95
+ /** Every glass surface currently in the document, floating ones included. */
96
+ export declare function scanHostSurfaces(options: HostScanOptions): HostGlassTarget[];