@alexpeng/dsh-custom-plugin 0.10.0 → 0.12.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/CHANGELOG.md +92 -0
- package/NOTICE +17 -44
- package/README.i18n.yaml +2 -2
- package/README.md +7 -4
- package/README.zh.md +7 -4
- package/lib/client.js +10390 -3808
- package/lib/client.js.map +1 -1
- package/lib/index.js +41 -13
- package/lib/types/client/bg-focus.d.ts +23 -6
- package/lib/types/client/bg-layer.d.ts +7 -32
- package/lib/types/client/bg-params.d.ts +19 -9
- package/lib/types/client/bg-scene.d.ts +170 -0
- package/lib/types/client/bg-shader.d.ts +103 -265
- package/lib/types/client/palette.d.ts +2 -0
- package/lib/types/client/styles.d.ts +1 -1
- package/lib/types/client/ui/appearance-controls.d.ts +1 -0
- package/lib/types/protocol.d.ts +32 -19
- package/package.json +4 -2
- package/lib/types/balance.d.ts +0 -44
- package/lib/types/client/bg-ascii.d.ts +0 -397
- package/lib/types/client/bg-field.d.ts +0 -60
- package/lib/types/client/bg-ocean.d.ts +0 -31
- package/lib/types/client/bg-pointer.d.ts +0 -107
- package/lib/types/client/bg-wake.d.ts +0 -57
package/lib/index.js
CHANGED
|
@@ -90,22 +90,43 @@ function mountOnce(packageName, fn) {
|
|
|
90
90
|
const CUSTOM_PLUGIN_API_PREFIX = "/api/custom-plugin";
|
|
91
91
|
/** Path the host serves the fetched Mermaid engine at (script src). */
|
|
92
92
|
const MERMAID_SCRIPT_PATH = "/custom-plugin/mermaid.js";
|
|
93
|
-
/**
|
|
93
|
+
/** Character-tier scene ids; every one is an open-source `ascii-things`
|
|
94
|
+
* preset. Keep in sync with `SCENE_PRESETS` in `client/bg-scene.ts`. */
|
|
94
95
|
const BG_FX_ASCII_PRESETS = [
|
|
95
|
-
"
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
"
|
|
99
|
-
"
|
|
100
|
-
"
|
|
96
|
+
"sharks",
|
|
97
|
+
"jellyfish",
|
|
98
|
+
"reef",
|
|
99
|
+
"night",
|
|
100
|
+
"turtle",
|
|
101
|
+
"manta",
|
|
102
|
+
"dolphin",
|
|
103
|
+
"seahorse",
|
|
104
|
+
"hammerhead",
|
|
105
|
+
"tang",
|
|
106
|
+
"koi",
|
|
107
|
+
"starlings",
|
|
108
|
+
"fireflies",
|
|
109
|
+
"city",
|
|
110
|
+
"servers"
|
|
111
|
+
];
|
|
112
|
+
/** Shader-tier style ids; every one is a Paper Shaders fragment shader.
|
|
113
|
+
* Keep in sync with `SHADER_STYLES` in `client/bg-shader.ts`. */
|
|
114
|
+
const BG_FX_SHADER_STYLES = [
|
|
115
|
+
"mesh",
|
|
116
|
+
"smoke",
|
|
117
|
+
"rays",
|
|
118
|
+
"dither",
|
|
119
|
+
"grain",
|
|
120
|
+
"warp",
|
|
121
|
+
"swirl"
|
|
101
122
|
];
|
|
102
|
-
/** Shader style ids; keep in sync with `SHADER_STYLES` in `client/bg-shader.ts`. */
|
|
103
|
-
const BG_FX_SHADER_STYLES = ["liquid", "grain"];
|
|
104
123
|
/** Default configuration (also the composition-layer default). */
|
|
105
124
|
const DEFAULT_CONFIG = {
|
|
106
125
|
bg: "天青灰",
|
|
107
126
|
bgFx: "none",
|
|
108
|
-
bgFxPreset: "
|
|
127
|
+
bgFxPreset: "sharks",
|
|
128
|
+
bgAsciiPreset: "sharks",
|
|
129
|
+
bgShaderPreset: "mesh",
|
|
109
130
|
bgStrength: "standard",
|
|
110
131
|
bgDensity: -1,
|
|
111
132
|
bgSpeed: -1,
|
|
@@ -114,6 +135,7 @@ const DEFAULT_CONFIG = {
|
|
|
114
135
|
bgOpacity: -1,
|
|
115
136
|
bgIntensity: -1,
|
|
116
137
|
bgFocus: true,
|
|
138
|
+
bgLagoonInk: false,
|
|
117
139
|
weather: "none",
|
|
118
140
|
glass: true,
|
|
119
141
|
glassMode: "frost",
|
|
@@ -373,10 +395,16 @@ function normalizeCfg(raw) {
|
|
|
373
395
|
if (typeof src.bgFx === "boolean") cfg.bgFx = src.bgFx ? "ascii" : "none";
|
|
374
396
|
if (cfg.bgFx !== "none" && cfg.bgFx !== "ascii" && cfg.bgFx !== "shader") cfg.bgFx = "none";
|
|
375
397
|
const shaderTier = cfg.bgFx === "shader";
|
|
398
|
+
const isAsciiPreset = (value) => typeof value === "string" && BG_FX_ASCII_PRESETS.includes(value);
|
|
399
|
+
const isShaderPreset = (value) => typeof value === "string" && BG_FX_SHADER_STYLES.includes(value);
|
|
400
|
+
const legacy = src.bgFxPreset;
|
|
401
|
+
if (src.bgAsciiPreset === void 0 && isAsciiPreset(legacy)) cfg.bgAsciiPreset = legacy;
|
|
402
|
+
if (src.bgShaderPreset === void 0 && isShaderPreset(legacy)) cfg.bgShaderPreset = legacy;
|
|
403
|
+
if (!isAsciiPreset(cfg.bgAsciiPreset)) cfg.bgAsciiPreset = "sharks";
|
|
404
|
+
if (!isShaderPreset(cfg.bgShaderPreset)) cfg.bgShaderPreset = "mesh";
|
|
376
405
|
const allowed = shaderTier ? BG_FX_SHADER_STYLES : BG_FX_ASCII_PRESETS;
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
if (typeof preset !== "string" || !allowed.includes(preset)) cfg.bgFxPreset = fallback;
|
|
406
|
+
const remembered = shaderTier ? cfg.bgShaderPreset : cfg.bgAsciiPreset;
|
|
407
|
+
if (typeof cfg.bgFxPreset !== "string" || !allowed.includes(cfg.bgFxPreset)) cfg.bgFxPreset = remembered;
|
|
380
408
|
if (cfg.bgStrength !== "soft" && cfg.bgStrength !== "standard" && cfg.bgStrength !== "strong") cfg.bgStrength = "standard";
|
|
381
409
|
for (const key of [
|
|
382
410
|
"bgDensity",
|
|
@@ -54,10 +54,27 @@ export declare function sameFocusRect(a: BgFocusRect | null, b: BgFocusRect | nu
|
|
|
54
54
|
*/
|
|
55
55
|
export declare function focusWeight(px: number, py: number, rect: BgFocusRect, feather: number, floor: number): number;
|
|
56
56
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
57
|
+
* Build the calm zone as a quarter-resolution alpha mask (a data URL).
|
|
58
|
+
*
|
|
59
|
+
* Both open-source renderers paint into their own canvas, so the per-cell caps
|
|
60
|
+
* the level renderer used to apply are replaced by a CSS `mask-image`: the
|
|
61
|
+
* reading column fades to {@link FOCUS_FLOOR}, the gutters stay at full
|
|
62
|
+
* strength. Building it at 1/4 resolution keeps a resize-time rebuild cheap
|
|
63
|
+
* (≈10k pixels at 1280×822) and the browser scales it smoothly.
|
|
62
64
|
*/
|
|
63
|
-
export
|
|
65
|
+
export interface FocusMaskDocLike {
|
|
66
|
+
createElement(tag: string): {
|
|
67
|
+
width: number;
|
|
68
|
+
height: number;
|
|
69
|
+
getContext(type: string): {
|
|
70
|
+
createImageData(w: number, h: number): {
|
|
71
|
+
data: Uint8ClampedArray;
|
|
72
|
+
};
|
|
73
|
+
putImageData(image: {
|
|
74
|
+
data: Uint8ClampedArray;
|
|
75
|
+
}, x: number, y: number): void;
|
|
76
|
+
} | null;
|
|
77
|
+
toDataURL(): string;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export declare function buildFocusMask(doc: FocusMaskDocLike, rect: BgFocusRect, width: number, height: number, scale?: number): string | null;
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
* surfaces locally and native dialogs at z1000 paint above it.
|
|
14
14
|
*
|
|
15
15
|
* Phase 1 owns the layer, its config path and the degradation gates; Phase 2
|
|
16
|
-
*
|
|
16
|
+
* mounts the open-source scene/shader backdrops inside this node
|
|
17
|
+
* (`bg-scene.ts` and `bg-shader.ts`).
|
|
17
18
|
* @module @alexpeng/dsh-custom-plugin/client/bg-layer
|
|
18
19
|
*/
|
|
19
20
|
/** DOM id of the owned background layer. */
|
|
@@ -35,7 +36,8 @@ export type BgLayerVerdict = {
|
|
|
35
36
|
readonly motion: BgLayerMotion;
|
|
36
37
|
};
|
|
37
38
|
/** Capability facts for the two renderer tiers. `webgl` is the result of the
|
|
38
|
-
* cached
|
|
39
|
+
* cached WebGL2 probe (Paper Shaders requires WebGL2); `canvas2d` is required
|
|
40
|
+
* by the character tier. */
|
|
39
41
|
export interface BgFxCaps extends BgLayerCaps {
|
|
40
42
|
readonly webgl: boolean;
|
|
41
43
|
}
|
|
@@ -49,10 +51,10 @@ export type BgFxVerdict = {
|
|
|
49
51
|
readonly tier: 'ascii' | 'shader';
|
|
50
52
|
};
|
|
51
53
|
/**
|
|
52
|
-
* Gate for the full `bgFx` enum. The requested shader tier needs
|
|
54
|
+
* Gate for the full `bgFx` enum. The requested shader tier needs WebGL2; when
|
|
53
55
|
* the probe failed but a 2D context exists, the same layer mounts with the
|
|
54
|
-
*
|
|
55
|
-
* the plain tint. When neither context exists there is nothing to draw, and
|
|
56
|
+
* character tier so the page keeps an animated background instead of dropping
|
|
57
|
+
* to the plain tint. When neither context exists there is nothing to draw, and
|
|
56
58
|
* the caller leaves the body fill in place.
|
|
57
59
|
*/
|
|
58
60
|
export declare function decideBgFxLayer(mode: 'none' | 'ascii' | 'shader', caps: BgFxCaps): BgFxVerdict;
|
|
@@ -123,30 +125,3 @@ export type BgLayerMountVerdict = Extract<BgLayerVerdict, {
|
|
|
123
125
|
export declare function mountBgLayer(doc: BgLayerDocLike, verdict: BgLayerMountVerdict, tint: string): BgLayerElementLike;
|
|
124
126
|
/** Remove the layer; a missing node is a no-op (fresh install / already off). */
|
|
125
127
|
export declare function unmountBgLayer(doc: BgLayerDocLike): void;
|
|
126
|
-
/**
|
|
127
|
-
* Where the active preset paints.
|
|
128
|
-
*
|
|
129
|
-
* `ocean` is the first piece that is mounted *inside* the conversation column
|
|
130
|
-
* (see `ColumnBgAnchor`): the shell's conversation surface is opaque, so a
|
|
131
|
-
* body-level layer behind it is invisible in the chat. Other presets keep the
|
|
132
|
-
* page-level layer. Keeping the decision pure makes it testable and keeps the
|
|
133
|
-
* painter and the React anchor from disagreeing.
|
|
134
|
-
*/
|
|
135
|
-
export type BgLayerScope = 'page' | 'conversation';
|
|
136
|
-
export declare function bgLayerScope(bgFx: string | undefined, bgFxPreset: string | undefined): BgLayerScope;
|
|
137
|
-
/** One ancestor of the slot anchor, reduced to what the host picker reads. */
|
|
138
|
-
export interface ColumnHostCandidate {
|
|
139
|
-
readonly className: string;
|
|
140
|
-
readonly height: number;
|
|
141
|
-
readonly opaque: boolean;
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Pick the conversation column host from an anchor's ancestor chain, ordered
|
|
145
|
-
* nearest-first. The reference implementation (`dsh-ascii-ocean`) looks for
|
|
146
|
-
* the AppFrame centre column class and then takes the outermost ancestor that
|
|
147
|
-
* still fills it, which is the node that owns the column's background. The
|
|
148
|
-
* fallback is the outermost ancestor with an opaque background.
|
|
149
|
-
*
|
|
150
|
-
* Returns the index into `chain`, or -1 when nothing is usable.
|
|
151
|
-
*/
|
|
152
|
-
export declare function pickColumnHost(chain: readonly ColumnHostCandidate[]): number;
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* themselves — this module never duplicates a bound.
|
|
10
10
|
* @module @alexpeng/dsh-custom-plugin/client/bg-params
|
|
11
11
|
*/
|
|
12
|
-
import { type
|
|
12
|
+
import { type SceneParams, type ScenePreset } from './bg-scene.ts';
|
|
13
13
|
import { type ShaderParams, type ShaderStyle } from './bg-shader.ts';
|
|
14
14
|
import { type BgFxPreset, type BgStrength, type CustomPluginConfig } from '../protocol.ts';
|
|
15
15
|
/** Stored value meaning "follow the active preset's own default". */
|
|
@@ -32,13 +32,25 @@ export interface BgParamMeta {
|
|
|
32
32
|
readonly decimals: number;
|
|
33
33
|
}
|
|
34
34
|
export declare const BG_PARAM_META: Record<BgParamKey, BgParamMeta>;
|
|
35
|
-
/** Knobs the
|
|
35
|
+
/** Knobs the character tier exposes, in render order. The scene runtime owns
|
|
36
|
+
* frame pacing and glyph size, so only the knobs it can honour are shown. */
|
|
36
37
|
export declare const BG_ASCII_PARAM_KEYS: readonly BgParamKey[];
|
|
37
|
-
/** Knobs the shader tier exposes, in render order
|
|
38
|
+
/** Knobs the shader tier exposes, in render order. */
|
|
38
39
|
export declare const BG_SHADER_PARAM_KEYS: readonly BgParamKey[];
|
|
39
40
|
/** Which sliders a tier shows. `none` shows none, so the panel can hide the
|
|
40
41
|
* whole block instead of rendering disabled rows. */
|
|
41
|
-
export declare function panelParamKeys(tier: BgTier): readonly BgParamKey[];
|
|
42
|
+
export declare function panelParamKeys(tier: BgTier, preset?: BgFxPreset): readonly BgParamKey[];
|
|
43
|
+
/** `单色印刷` only makes sense on a full-colour lagoon painting. */
|
|
44
|
+
export declare function showsLagoonInk(tier: BgTier, preset: BgFxPreset): boolean;
|
|
45
|
+
/** One caption + its preset buttons in the panel. */
|
|
46
|
+
export interface PresetGroup {
|
|
47
|
+
readonly id: 'ink' | 'lagoon' | 'ambient' | 'shader';
|
|
48
|
+
readonly label: string;
|
|
49
|
+
readonly presets: readonly BgFxPreset[];
|
|
50
|
+
}
|
|
51
|
+
/** Presets grouped by family. The dark-only ambient group disappears in light
|
|
52
|
+
* mode; the panel shows a note if the stored preset is hidden by the theme. */
|
|
53
|
+
export declare function presetGroups(tier: BgTier, dark: boolean): readonly PresetGroup[];
|
|
42
54
|
/** Read the tier from a config snapshot; unknown modes are `none`. */
|
|
43
55
|
export declare function tierFromCfg(cfg: CustomPluginConfig): BgTier;
|
|
44
56
|
/**
|
|
@@ -96,11 +108,9 @@ export declare function clampInto(value: number, min: number, max: number): numb
|
|
|
96
108
|
export declare function setParamInCfg(cfg: CustomPluginConfig, tier: BgTier, preset: BgFxPreset, key: BgParamKey, value: number): CustomPluginConfig;
|
|
97
109
|
/** Clear every override so each preset's own defaults apply again. */
|
|
98
110
|
export declare function resetBgParams(cfg: CustomPluginConfig): CustomPluginConfig;
|
|
99
|
-
/**
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
export declare function asciiParamsFromCfg(cfg: CustomPluginConfig, preset: AsciiPreset): AsciiParams;
|
|
103
|
-
/** Shader renderer overrides for the current config. */
|
|
111
|
+
/** Character-tier renderer overrides for the current config. */
|
|
112
|
+
export declare function asciiParamsFromCfg(cfg: CustomPluginConfig, preset: ScenePreset): SceneParams;
|
|
113
|
+
/** Shader-tier renderer overrides for the current config. */
|
|
104
114
|
export declare function shaderParamsFromCfg(cfg: CustomPluginConfig, style: ShaderStyle): ShaderParams;
|
|
105
115
|
/** Timer surface the debounced saver needs; injectable for tests. */
|
|
106
116
|
export interface DebounceTimers {
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Open-source ASCII scene backdrop.
|
|
3
|
+
*
|
|
4
|
+
* The character tier no longer hand-draws its pictures: each preset is a real
|
|
5
|
+
* scene from `ascii-things` (MIT, https://github.com/chuma-beep/ascii-things).
|
|
6
|
+
* Two families share this wrapper:
|
|
7
|
+
*
|
|
8
|
+
* - `ink` scenes (sharks, jellyfish) accept a palette, so they are rendered in
|
|
9
|
+
* the theme's own ink: a white canvas composited with `multiply` on light,
|
|
10
|
+
* a black one with `screen` on dark. The page tint never moves — only the
|
|
11
|
+
* glyphs darken/lighten it.
|
|
12
|
+
* - `lagoon` scenes are full-canvas paintings with their own authored colours
|
|
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.
|
|
16
|
+
*
|
|
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`.
|
|
21
|
+
* @module @alexpeng/dsh-custom-plugin/client/bg-scene
|
|
22
|
+
*/
|
|
23
|
+
import type { Palette } from 'ascii-things';
|
|
24
|
+
import type { BgFocusRect } from './bg-focus.ts';
|
|
25
|
+
/** 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';
|
|
27
|
+
/** Scene family: palette-driven ink, a full-colour lagoon painting, or a dark
|
|
28
|
+
* ambient scene (koi pond, starlings, city…). */
|
|
29
|
+
export type SceneKind = 'ink' | 'lagoon' | 'ambient';
|
|
30
|
+
/** Inclusive slider bounds a scene preset exposes. */
|
|
31
|
+
export interface SceneRange {
|
|
32
|
+
readonly min: number;
|
|
33
|
+
readonly max: number;
|
|
34
|
+
}
|
|
35
|
+
/** Writable bounds per scene preset. */
|
|
36
|
+
export interface SceneRanges {
|
|
37
|
+
readonly density: SceneRange;
|
|
38
|
+
readonly speed: SceneRange;
|
|
39
|
+
readonly opacity: SceneRange;
|
|
40
|
+
}
|
|
41
|
+
/** One scene's authored defaults. `columns` is the art-direction target at
|
|
42
|
+
* density 0.65; the density slider scales it. */
|
|
43
|
+
export interface SceneSpec {
|
|
44
|
+
readonly kind: SceneKind;
|
|
45
|
+
readonly variant?: 'reef' | 'night' | 'turtle' | 'manta' | 'seahorse' | 'dolphin' | 'hammerhead' | 'tang';
|
|
46
|
+
readonly columns: number;
|
|
47
|
+
readonly speed: number;
|
|
48
|
+
readonly opacity: number;
|
|
49
|
+
/** Ink multiplier for the palette-driven scenes; lagoons carry their own. */
|
|
50
|
+
readonly inkScale: number;
|
|
51
|
+
/** Backing-store pixel-ratio cap: full 2× for the crisp ink scenes, 1.5× for
|
|
52
|
+
* the painted/ambient scenes where the extra pixels buy little. */
|
|
53
|
+
readonly maxDpr: number;
|
|
54
|
+
/** Ambient paintings are authored on a dark backdrop and only make sense on
|
|
55
|
+
* a dark page; the wrapper falls back to `sharks` in light mode. */
|
|
56
|
+
readonly theme?: 'dark';
|
|
57
|
+
readonly ranges: SceneRanges;
|
|
58
|
+
}
|
|
59
|
+
/** The shipped scene list. Every entry is a distinct scene from ascii-things —
|
|
60
|
+
* not one field with different knobs. */
|
|
61
|
+
export declare const SCENE_PRESETS: Record<ScenePreset, SceneSpec>;
|
|
62
|
+
/** Scene id fallback for a stale preset in the character tier. */
|
|
63
|
+
export declare const DEFAULT_SCENE: ScenePreset;
|
|
64
|
+
/** Resolve a stored id to a scene; unknown ids fall back to sharks. */
|
|
65
|
+
export declare function resolveScenePreset(preset: string | undefined): ScenePreset;
|
|
66
|
+
/** Theme gate for the dark-only ambient paintings. The stored preset is kept
|
|
67
|
+
* (so returning to dark restores it); only the renderer substitutes `sharks`
|
|
68
|
+
* while the page is light. */
|
|
69
|
+
export declare function scenePresetForTheme(preset: ScenePreset, dark: boolean): ScenePreset;
|
|
70
|
+
/** Scene params written by the panel; every field is already clamped. */
|
|
71
|
+
export interface SceneParams {
|
|
72
|
+
readonly density?: number;
|
|
73
|
+
readonly speed?: number;
|
|
74
|
+
readonly opacity?: number;
|
|
75
|
+
/** Ink-strength multiplier from `BG_STRENGTH_SCALE`. */
|
|
76
|
+
readonly strength?: number;
|
|
77
|
+
}
|
|
78
|
+
/** Resolved values after merging overrides with the preset's defaults. */
|
|
79
|
+
export interface SceneResolved {
|
|
80
|
+
readonly columns: number;
|
|
81
|
+
readonly speed: number;
|
|
82
|
+
readonly opacity: number;
|
|
83
|
+
readonly strength: number;
|
|
84
|
+
}
|
|
85
|
+
/** Merge panel overrides onto the preset defaults. Pure and testable. */
|
|
86
|
+
export declare function resolveSceneSpec(preset: ScenePreset, params: SceneParams): SceneResolved;
|
|
87
|
+
/** True when two resolved scene states would render identically, so a slider
|
|
88
|
+
* event that lands on the same quantised value does not touch the engine. */
|
|
89
|
+
export declare function sameSceneResolved(a: SceneResolved, b: SceneResolved): boolean;
|
|
90
|
+
/** Build the `setOptions` payload for a resolved-state change. Returning null
|
|
91
|
+
* means "nothing to send". The palette is attached only when an ink scene's
|
|
92
|
+
* strength actually changed, so dragging density/speed never rebuilds it. */
|
|
93
|
+
export declare function sceneSetOptionsPatch(prev: SceneResolved, next: SceneResolved, kind: SceneKind, palette: Palette): Record<string, unknown> | null;
|
|
94
|
+
/** How the scene canvas composites over the page tint. */
|
|
95
|
+
export interface SceneLook {
|
|
96
|
+
readonly opacity: number;
|
|
97
|
+
readonly blend: 'multiply' | 'screen' | 'normal';
|
|
98
|
+
readonly filter: string;
|
|
99
|
+
}
|
|
100
|
+
/** Visual treatment for one scene. Ink scenes always follow the theme;
|
|
101
|
+
* lagoons keep their authored colour unless the user turns on 单色印刷, which
|
|
102
|
+
* 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;
|
|
105
|
+
/**
|
|
106
|
+
* Build the palette the ink scenes render with. The page tint supplies the
|
|
107
|
+
* ink hue (through `inkFor`'s lightness step), and the five fish levels become
|
|
108
|
+
* alphas of that single colour, so the scene stays monochrome and theme-aware.
|
|
109
|
+
*/
|
|
110
|
+
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
|
+
/** The slice of a canvas element this module touches. */
|
|
115
|
+
export interface SceneCanvasLike {
|
|
116
|
+
width: number;
|
|
117
|
+
height: number;
|
|
118
|
+
readonly clientWidth: number;
|
|
119
|
+
readonly clientHeight: number;
|
|
120
|
+
style: Record<string, string>;
|
|
121
|
+
getContext(type: string): SceneCtxLike | null;
|
|
122
|
+
remove(): void;
|
|
123
|
+
}
|
|
124
|
+
/** The slice of a 2D context the mask builder needs. */
|
|
125
|
+
export interface SceneCtxLike {
|
|
126
|
+
createImageData(w: number, h: number): {
|
|
127
|
+
data: Uint8ClampedArray;
|
|
128
|
+
};
|
|
129
|
+
putImageData(image: {
|
|
130
|
+
data: Uint8ClampedArray;
|
|
131
|
+
}, x: number, y: number): void;
|
|
132
|
+
}
|
|
133
|
+
/** The slice of `document` this module touches. */
|
|
134
|
+
export interface SceneDocLike {
|
|
135
|
+
createElement(tag: string): SceneCanvasLike & {
|
|
136
|
+
toDataURL(): string;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/** The layer host (`div#vx-bg`). */
|
|
140
|
+
export interface SceneHostLike {
|
|
141
|
+
appendChild(node: unknown): unknown;
|
|
142
|
+
style: Record<string, string>;
|
|
143
|
+
getAttribute?: (name: string) => string | null;
|
|
144
|
+
}
|
|
145
|
+
/** Read the plugin's motion attribute so the scene tier pauses exactly like
|
|
146
|
+
* the shader tier when the page is hidden or reduced motion is requested. */
|
|
147
|
+
export declare function sceneMotion(host: SceneHostLike): 'animated' | 'paused' | 'static';
|
|
148
|
+
/** Options for {@link createSceneBackdrop}. */
|
|
149
|
+
export interface SceneBackdropOptions {
|
|
150
|
+
readonly doc: SceneDocLike;
|
|
151
|
+
readonly host: SceneHostLike;
|
|
152
|
+
readonly preset: ScenePreset;
|
|
153
|
+
readonly params: SceneParams;
|
|
154
|
+
readonly tint: string;
|
|
155
|
+
readonly dark: boolean;
|
|
156
|
+
/** 单色印刷 for lagoon paintings; ignored by ink/ambient scenes. */
|
|
157
|
+
readonly lagoonInk?: boolean;
|
|
158
|
+
}
|
|
159
|
+
/** The mounted scene renderer. */
|
|
160
|
+
export interface SceneBackdrop {
|
|
161
|
+
sync(): void;
|
|
162
|
+
setPreset(preset: ScenePreset): void;
|
|
163
|
+
setParams(params: SceneParams): void;
|
|
164
|
+
setLagoonInk(on: boolean): void;
|
|
165
|
+
setFocus(rect: BgFocusRect | null): void;
|
|
166
|
+
setTint(tint: string, dark: boolean): void;
|
|
167
|
+
destroy(): void;
|
|
168
|
+
}
|
|
169
|
+
/** Create the scene canvas and mount the active ascii-things engine. */
|
|
170
|
+
export declare function createSceneBackdrop(options: SceneBackdropOptions): SceneBackdrop;
|