@alexpeng/dsh-custom-plugin 0.9.3 → 0.10.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 +1687 -866
- package/NOTICE +71 -0
- package/README.i18n.yaml +7 -7
- package/README.md +344 -335
- package/README.zh.md +309 -302
- package/lib/client.js +9458 -2063
- package/lib/client.js.map +1 -1
- package/lib/index.js +233 -99
- package/lib/types/balance.d.ts +44 -0
- package/lib/types/client/api.d.ts +13 -8
- package/lib/types/client/bg-ascii.d.ts +397 -0
- package/lib/types/client/bg-field.d.ts +60 -0
- package/lib/types/client/bg-focus.d.ts +63 -0
- package/lib/types/client/bg-layer.d.ts +152 -0
- package/lib/types/client/bg-ocean.d.ts +31 -0
- package/lib/types/client/bg-params.d.ts +142 -0
- package/lib/types/client/bg-pointer.d.ts +107 -0
- package/lib/types/client/bg-shader.d.ts +329 -0
- package/lib/types/client/bg-wake.d.ts +57 -0
- package/lib/types/client/custom.d.ts +4 -1
- package/lib/types/client/index.d.ts +1 -1
- package/lib/types/client/palette.d.ts +100 -0
- package/lib/types/client/panel-bounds.d.ts +65 -0
- package/lib/types/client/styles.d.ts +9 -4
- package/lib/types/client/ui/anchor.d.ts +55 -0
- package/lib/types/client/ui/appearance-controls.d.ts +24 -0
- package/lib/types/client/ui/command-model.d.ts +28 -0
- package/lib/types/client/ui/folders-model.d.ts +31 -0
- package/lib/types/client/ui/index-bridge.d.ts +6 -0
- package/lib/types/client/ui/overlays.d.ts +66 -0
- package/lib/types/client/ui/primitives.d.ts +93 -0
- package/lib/types/client/ui/prompt-model.d.ts +37 -0
- package/lib/types/host-service.d.ts +68 -15
- package/lib/types/pricing.d.ts +8 -4
- package/lib/types/protocol.d.ts +48 -2
- package/lib/types/usage.d.ts +8 -4
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +106 -105
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ocean` 2.0: a living water surface instead of two fixed sine swells.
|
|
3
|
+
*
|
|
4
|
+
* Three layers make the scene:
|
|
5
|
+
* 1. a divergence-free current (the curl of a drifting stream function) that
|
|
6
|
+
* moves the whole surface without piling water into one corner;
|
|
7
|
+
* 2. a {@link BgWakeField} wave tank. Pointer drags, clicks and fish wakes
|
|
8
|
+
* inject height impulses that propagate, interfere and fade — the water
|
|
9
|
+
* remembers what touched it;
|
|
10
|
+
* 3. eighteen small fish plus two large koi. Steering is boids-lite
|
|
11
|
+
* (alignment / cohesion / separation / mill); the pointer pushes them
|
|
12
|
+
* away and a click startles the school, which then regroups.
|
|
13
|
+
*
|
|
14
|
+
* The piece writes only ramp levels plus two optional per-cell buffers:
|
|
15
|
+
* `emphasis` marks interaction cells so the renderer may keep them visible at
|
|
16
|
+
* a reduced strength inside the calm zone, and `overlay` carries the fish
|
|
17
|
+
* glyphs (direction marks for the small fish, body/edge/head/tail cells for
|
|
18
|
+
* the koi). The renderer draws those with `fillText` after the atlas blit, so
|
|
19
|
+
* no second atlas is needed.
|
|
20
|
+
*
|
|
21
|
+
* The flow-field constants are re-derived for grid cells; the stream-function
|
|
22
|
+
* form follows `stackedlol/ascii-sharks` (MIT, see NOTICE). No code from the
|
|
23
|
+
* `dsh-ascii-ocean` plugin is copied — its LICENSE file has no licence text.
|
|
24
|
+
* @module @alexpeng/dsh-custom-plugin/client/bg-ocean
|
|
25
|
+
*/
|
|
26
|
+
import { type AsciiPiece } from './bg-field.ts';
|
|
27
|
+
/**
|
|
28
|
+
* Create the ocean piece. The returned function owns its wake tank and fish
|
|
29
|
+
* arrays; they are rebuilt only when the grid changes, never per frame.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createOceanPiece(levels: number, dither: boolean): AsciiPiece;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The background-motion panel's pure half: which knobs a tier exposes, how a
|
|
3
|
+
* stored flat value maps onto a preset's declared `ranges`, and the debounced
|
|
4
|
+
* saver the sliders use.
|
|
5
|
+
*
|
|
6
|
+
* Everything here is React-free and DOM-free on purpose. The panel component
|
|
7
|
+
* only renders; all clamping, fallback and timing rules live in functions a
|
|
8
|
+
* node test can call directly. The two renderer modules own the `ranges`
|
|
9
|
+
* themselves — this module never duplicates a bound.
|
|
10
|
+
* @module @alexpeng/dsh-custom-plugin/client/bg-params
|
|
11
|
+
*/
|
|
12
|
+
import { type AsciiParams, type AsciiPreset } from './bg-ascii.ts';
|
|
13
|
+
import { type ShaderParams, type ShaderStyle } from './bg-shader.ts';
|
|
14
|
+
import { type BgFxPreset, type BgStrength, type CustomPluginConfig } from '../protocol.ts';
|
|
15
|
+
/** Stored value meaning "follow the active preset's own default". */
|
|
16
|
+
export declare const BG_PARAM_UNSET = -1;
|
|
17
|
+
/** Slider debounce: one POST per pause, not one per input event. */
|
|
18
|
+
export declare const BG_PARAM_SAVE_MS = 320;
|
|
19
|
+
/** The three-tier value space of `bgFx`. */
|
|
20
|
+
export type BgTier = 'none' | 'ascii' | 'shader';
|
|
21
|
+
/** Every knob the panel can render. */
|
|
22
|
+
export type BgParamKey = 'density' | 'speed' | 'fps' | 'fontPx' | 'opacity' | 'intensity';
|
|
23
|
+
/** The flat config field that stores one knob. */
|
|
24
|
+
export type BgParamCfgKey = 'bgDensity' | 'bgSpeed' | 'bgFps' | 'bgFontPx' | 'bgOpacity' | 'bgIntensity';
|
|
25
|
+
/** Presentation metadata for one slider row. */
|
|
26
|
+
export interface BgParamMeta {
|
|
27
|
+
readonly key: BgParamKey;
|
|
28
|
+
readonly cfgKey: BgParamCfgKey;
|
|
29
|
+
readonly label: string;
|
|
30
|
+
readonly unit: string;
|
|
31
|
+
readonly step: number;
|
|
32
|
+
readonly decimals: number;
|
|
33
|
+
}
|
|
34
|
+
export declare const BG_PARAM_META: Record<BgParamKey, BgParamMeta>;
|
|
35
|
+
/** Knobs the ASCII tier exposes, in render order. */
|
|
36
|
+
export declare const BG_ASCII_PARAM_KEYS: readonly BgParamKey[];
|
|
37
|
+
/** Knobs the shader tier exposes, in render order (no font/opacity there). */
|
|
38
|
+
export declare const BG_SHADER_PARAM_KEYS: readonly BgParamKey[];
|
|
39
|
+
/** Which sliders a tier shows. `none` shows none, so the panel can hide the
|
|
40
|
+
* whole block instead of rendering disabled rows. */
|
|
41
|
+
export declare function panelParamKeys(tier: BgTier): readonly BgParamKey[];
|
|
42
|
+
/** Read the tier from a config snapshot; unknown modes are `none`. */
|
|
43
|
+
export declare function tierFromCfg(cfg: CustomPluginConfig): BgTier;
|
|
44
|
+
/**
|
|
45
|
+
* Ink-strength multipliers on top of each piece's calibrated ink step.
|
|
46
|
+
*
|
|
47
|
+
* Re-scaled on 2026-11-11: the user found the old `standard` (1.0×) too dark,
|
|
48
|
+
* so the default moved to the value he had been using as 柔和 (0.62×) and the
|
|
49
|
+
* whole ladder was shifted down — 柔和 0.45× / 标准 0.62× / 强烈 0.9×. They
|
|
50
|
+
* scale only the ink's lightness step; the grid geometry, speed and frame
|
|
51
|
+
* pacing are untouched.
|
|
52
|
+
*/
|
|
53
|
+
export declare const BG_STRENGTH_SCALE: Record<BgStrength, number>;
|
|
54
|
+
/** Presentation order and labels of the three strength choices. The labels
|
|
55
|
+
* are 柔和 / 标准 / 强烈 (2026-11-11): the first step keeps its original name
|
|
56
|
+
* and the top step is 强烈; the stored values and scales never moved. */
|
|
57
|
+
export declare const BG_STRENGTH_META: ReadonlyArray<{
|
|
58
|
+
readonly value: BgStrength;
|
|
59
|
+
readonly label: string;
|
|
60
|
+
}>;
|
|
61
|
+
/** Read the strength from a config snapshot; unknown values are 'soft'. */
|
|
62
|
+
export declare function strengthFromCfg(cfg: CustomPluginConfig): BgStrength;
|
|
63
|
+
/** Write the strength into a config snapshot (shallow copy, like every panel
|
|
64
|
+
* edit). The value space is closed, so an unknown input lands on 'standard'. */
|
|
65
|
+
export declare function setStrengthInCfg(cfg: CustomPluginConfig, value: BgStrength): CustomPluginConfig;
|
|
66
|
+
/**
|
|
67
|
+
* Pick the preset a tier can mount. Switching tiers with a preset id from the
|
|
68
|
+
* other tier (or a hand-edited unknown value) lands on that tier's default
|
|
69
|
+
* instead of mounting a piece the renderer does not know.
|
|
70
|
+
*/
|
|
71
|
+
export declare function presetForTier(tier: BgTier, preset: string | undefined): BgFxPreset;
|
|
72
|
+
/** Inclusive slider bounds for one knob, or null when the tier has no such
|
|
73
|
+
* knob. Reads the active preset's own `ranges` — never a local copy. */
|
|
74
|
+
export declare function paramRange(tier: BgTier, preset: BgFxPreset, key: BgParamKey): {
|
|
75
|
+
min: number;
|
|
76
|
+
max: number;
|
|
77
|
+
} | null;
|
|
78
|
+
/** The preset's own value for a knob. */
|
|
79
|
+
export declare function paramDefault(tier: BgTier, preset: BgFxPreset, key: BgParamKey): number;
|
|
80
|
+
/** True when the stored value is a real override (anything but the sentinel). */
|
|
81
|
+
export declare function paramConfigured(cfg: CustomPluginConfig, key: BgParamKey): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* The value a slider should display: the stored override clamped into the
|
|
84
|
+
* current preset's range, or that preset's default when unset. An unknown
|
|
85
|
+
* preset already resolved to the tier default upstream.
|
|
86
|
+
*/
|
|
87
|
+
export declare function effectiveParam(cfg: CustomPluginConfig, tier: BgTier, preset: BgFxPreset, key: BgParamKey): number;
|
|
88
|
+
/** Clamp a number into an inclusive band. Non-finite values take the minimum,
|
|
89
|
+
* which is the conservative choice for every knob here. */
|
|
90
|
+
export declare function clampInto(value: number, min: number, max: number): number;
|
|
91
|
+
/**
|
|
92
|
+
* Write one slider value into a config snapshot: clamp first, then overwrite
|
|
93
|
+
* the flat field. The cfg object is shallow-copied, matching every other panel
|
|
94
|
+
* edit, so the store can diff and subscribers re-render once.
|
|
95
|
+
*/
|
|
96
|
+
export declare function setParamInCfg(cfg: CustomPluginConfig, tier: BgTier, preset: BgFxPreset, key: BgParamKey, value: number): CustomPluginConfig;
|
|
97
|
+
/** Clear every override so each preset's own defaults apply again. */
|
|
98
|
+
export declare function resetBgParams(cfg: CustomPluginConfig): CustomPluginConfig;
|
|
99
|
+
/** ASCII renderer overrides for the current config. All five knobs are
|
|
100
|
+
* resolved, so a preset switch is handled by passing the new preset too; the
|
|
101
|
+
* strength multiplier rides along as `strength`. */
|
|
102
|
+
export declare function asciiParamsFromCfg(cfg: CustomPluginConfig, preset: AsciiPreset): AsciiParams;
|
|
103
|
+
/** Shader renderer overrides for the current config. */
|
|
104
|
+
export declare function shaderParamsFromCfg(cfg: CustomPluginConfig, style: ShaderStyle): ShaderParams;
|
|
105
|
+
/** Timer surface the debounced saver needs; injectable for tests. */
|
|
106
|
+
export interface DebounceTimers {
|
|
107
|
+
set(callback: () => void, delayMs: number): unknown;
|
|
108
|
+
clear(handle: unknown): void;
|
|
109
|
+
}
|
|
110
|
+
/** Handle returned by {@link createDebouncedSaver}. */
|
|
111
|
+
export interface DebouncedSaver {
|
|
112
|
+
/** (Re)start the timer; a burst of calls still fires `save` once. */
|
|
113
|
+
push(): void;
|
|
114
|
+
/** Drop the pending call, e.g. when "restore defaults" saves immediately. */
|
|
115
|
+
cancel(): void;
|
|
116
|
+
isPending(): boolean;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* One timer per burst: every slider input restarts it, and only the pause
|
|
120
|
+
* after the last event POSTs. The save reads the live store when it fires, so
|
|
121
|
+
* the debounced write always carries the final value.
|
|
122
|
+
*/
|
|
123
|
+
export declare function createDebouncedSaver(save: () => void, delayMs: number, timers?: DebounceTimers): DebouncedSaver;
|
|
124
|
+
/** The slice the appearance tab subscribes to. Kept as one named function so
|
|
125
|
+
* a test can pin the scope: the tab never subscribes to turns, toasts, usage
|
|
126
|
+
* or any other per-turn field. */
|
|
127
|
+
export declare function selectAppearanceSlice(state: {
|
|
128
|
+
cfg: CustomPluginConfig;
|
|
129
|
+
dark: boolean;
|
|
130
|
+
}): {
|
|
131
|
+
cfg: CustomPluginConfig;
|
|
132
|
+
dark: boolean;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* The one-line note the panel shows when the active preset draws exactly one
|
|
136
|
+
* frame and never animates. Switching to such a preset looks like "nothing
|
|
137
|
+
* happened" because the still picture is the whole point, so the panel says so
|
|
138
|
+
* in place instead of firing a toast. Returns null for every animated preset.
|
|
139
|
+
*/
|
|
140
|
+
export declare function presetStillNote(tier: BgTier, preset: BgFxPreset): string | null;
|
|
141
|
+
/** Every preset id the active tier can show, in panel order. */
|
|
142
|
+
export declare function tierPresets(tier: BgTier): readonly BgFxPreset[];
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Passive pointer state for the background pieces.
|
|
3
|
+
*
|
|
4
|
+
* The backdrop canvas deliberately carries `pointer-events:none` and sits
|
|
5
|
+
* below the content surfaces, so it can never receive a pointer event itself.
|
|
6
|
+
* A window-level listener is the only way to know where the pointer is, and it
|
|
7
|
+
* must be *passive*: the background is decoration, never allowed to delay a
|
|
8
|
+
* scroll, a selection or a click. Nothing here starts a frame — the renderer
|
|
9
|
+
* calls {@link syncBgPointer} once per existing frame, so interaction adds no
|
|
10
|
+
* second rAF loop.
|
|
11
|
+
*
|
|
12
|
+
* Two rules make the pointer read as weight instead of a teleporting cursor:
|
|
13
|
+
* the position follows the raw sample with a short time constant
|
|
14
|
+
* ({@link POINTER_POS_TAU_MS}) and the velocity with a slightly longer one
|
|
15
|
+
* ({@link POINTER_VEL_TAU_MS}). Both are advanced by the event handlers *and*
|
|
16
|
+
* by `syncBgPointer` against one monotonic clock, so the easing is frame-rate
|
|
17
|
+
* independent instead of depending on how often the browser delivers moves.
|
|
18
|
+
* While the pointer rests the velocity is damped out and is exactly zero after
|
|
19
|
+
* {@link POINTER_IDLE_MS}, so an inertia field cannot keep blowing on a stale
|
|
20
|
+
* sample; a drift slower than {@link POINTER_DEAD_SPEED} reports no force at
|
|
21
|
+
* all, which is what keeps a hand resting on the mouse from stirring the page.
|
|
22
|
+
* @module @alexpeng/dsh-custom-plugin/client/bg-pointer
|
|
23
|
+
*/
|
|
24
|
+
/** The slice of `PointerEvent` this module reads. Structural so tests can
|
|
25
|
+
* dispatch plain objects and the DOM needs no cast at the call site. */
|
|
26
|
+
export interface BgPointerEventLike {
|
|
27
|
+
clientX: number;
|
|
28
|
+
clientY: number;
|
|
29
|
+
pointerType?: string;
|
|
30
|
+
button?: number;
|
|
31
|
+
}
|
|
32
|
+
/** The slice of a `Window`-shaped target this module touches. */
|
|
33
|
+
export interface BgPointerTargetLike {
|
|
34
|
+
addEventListener(type: string, listener: (event: BgPointerEventLike) => void, options?: {
|
|
35
|
+
passive?: boolean;
|
|
36
|
+
}): void;
|
|
37
|
+
removeEventListener(type: string, listener: (event: BgPointerEventLike) => void, options?: {
|
|
38
|
+
passive?: boolean;
|
|
39
|
+
}): void;
|
|
40
|
+
}
|
|
41
|
+
/** Mutable state the renderer reads once per frame. */
|
|
42
|
+
export interface BgPointerState {
|
|
43
|
+
/** Eased position in CSS pixels, heading for `targetX` / `targetY`. */
|
|
44
|
+
x: number;
|
|
45
|
+
y: number;
|
|
46
|
+
/** A pointer has been seen and has not left the window since. */
|
|
47
|
+
active: boolean;
|
|
48
|
+
/** Primary button held down. */
|
|
49
|
+
down: boolean;
|
|
50
|
+
/** Reported smoothed velocity in CSS pixels per second. Zero below the dead
|
|
51
|
+
* speed and after {@link POINTER_IDLE_MS} of no input. */
|
|
52
|
+
vx: number;
|
|
53
|
+
vy: number;
|
|
54
|
+
/** Increments once per primary press. */
|
|
55
|
+
pulseId: number;
|
|
56
|
+
/** Press position in CSS pixels (raw, never eased: a click lands where the
|
|
57
|
+
* user clicked). */
|
|
58
|
+
pulseX: number;
|
|
59
|
+
pulseY: number;
|
|
60
|
+
/** Raw position the eased one is heading for, CSS pixels. */
|
|
61
|
+
targetX: number;
|
|
62
|
+
targetY: number;
|
|
63
|
+
/** Smoothed velocity at the last accepted move, before the idle damping;
|
|
64
|
+
* `vx` / `vy` are derived from it on every frame. */
|
|
65
|
+
rawVx: number;
|
|
66
|
+
rawVy: number;
|
|
67
|
+
/** Clock reading of the last accepted input, ms. -1 until the first one,
|
|
68
|
+
* and again after the pointer leaves. */
|
|
69
|
+
lastInputAt: number;
|
|
70
|
+
/** Clock reading of the last eased-position step, ms. */
|
|
71
|
+
lastPosAt: number;
|
|
72
|
+
}
|
|
73
|
+
/** Time constant of the position follow. At a 110 Hz pointer this is the
|
|
74
|
+
* `lerp ≈ 0.15` feel the interaction round settled on; because the step is
|
|
75
|
+
* time-based it stays the same at 60 Hz or 1000 Hz. */
|
|
76
|
+
export declare const POINTER_POS_TAU_MS = 70;
|
|
77
|
+
/** Time constant of the velocity smoothing. Longer than the position: force
|
|
78
|
+
* should ramp, not spike, when the hand changes direction. */
|
|
79
|
+
export declare const POINTER_VEL_TAU_MS = 90;
|
|
80
|
+
/** Below this speed the reported velocity is zero: a slow drift must not
|
|
81
|
+
* stir the fog, bend the rain or spin the eddy. The onset is a smoothstep up
|
|
82
|
+
* to twice this value, so crossing it never steps the force. */
|
|
83
|
+
export declare const POINTER_DEAD_SPEED = 80;
|
|
84
|
+
/** No input for this long and every interaction value is zero. */
|
|
85
|
+
export declare const POINTER_IDLE_MS = 1500;
|
|
86
|
+
/** One monotonic clock for the listeners and the frame-time sync. Exported so
|
|
87
|
+
* a test or a harness can drive both sides on the same clock. */
|
|
88
|
+
export declare function bgPointerClock(): number;
|
|
89
|
+
/** A fresh, inactive state. The struct is reused for the life of a renderer. */
|
|
90
|
+
export declare function createBgPointerState(): BgPointerState;
|
|
91
|
+
/** Reset in place (destroy / preset switch); no allocation. */
|
|
92
|
+
export declare function resetBgPointerState(state: BgPointerState): void;
|
|
93
|
+
/**
|
|
94
|
+
* Advance interaction time once per rendered frame. Called by both tiers
|
|
95
|
+
* before they read the pointer: the eased position keeps converging after the
|
|
96
|
+
* last event, the velocity damps out while the pointer rests, and after
|
|
97
|
+
* {@link POINTER_IDLE_MS} every value is exactly zero with the position
|
|
98
|
+
* snapped onto the target. A renderer that is not drawing never calls this,
|
|
99
|
+
* so a paused page cannot be woken up by the pointer.
|
|
100
|
+
*/
|
|
101
|
+
export declare function syncBgPointer(state: BgPointerState, now?: number): void;
|
|
102
|
+
/**
|
|
103
|
+
* Attach the passive listeners. Touch moves are ignored (the user is
|
|
104
|
+
* scrolling); a touch tap still counts as a press. Returns the disposer, which
|
|
105
|
+
* removes exactly the listeners it added.
|
|
106
|
+
*/
|
|
107
|
+
export declare function attachBgPointer(target: BgPointerTargetLike, state: BgPointerState, clock?: () => number): () => void;
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebGL1 backdrop: one full-screen triangle, one fragment shader, no library.
|
|
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.
|
|
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.
|
|
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).
|
|
26
|
+
* @module @alexpeng/dsh-custom-plugin/client/bg-shader
|
|
27
|
+
*/
|
|
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. */
|
|
33
|
+
export interface ShaderRange {
|
|
34
|
+
readonly min: number;
|
|
35
|
+
readonly max: number;
|
|
36
|
+
}
|
|
37
|
+
/** Writable bounds per style; defaults sit inside these. */
|
|
38
|
+
export interface ShaderStyleRanges {
|
|
39
|
+
readonly speed: ShaderRange;
|
|
40
|
+
readonly density: ShaderRange;
|
|
41
|
+
readonly intensity: ShaderRange;
|
|
42
|
+
readonly seed: ShaderRange;
|
|
43
|
+
readonly fps: ShaderRange;
|
|
44
|
+
}
|
|
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. */
|
|
47
|
+
export interface ShaderStyleSpec {
|
|
48
|
+
readonly speed: number;
|
|
49
|
+
readonly density: number;
|
|
50
|
+
readonly intensity: number;
|
|
51
|
+
readonly seed: number;
|
|
52
|
+
readonly fps: number;
|
|
53
|
+
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
|
+
readonly ranges: ShaderStyleRanges;
|
|
58
|
+
}
|
|
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
|
+
*/
|
|
65
|
+
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. */
|
|
68
|
+
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. */
|
|
239
|
+
export interface ShaderHostLike {
|
|
240
|
+
readonly clientWidth: number;
|
|
241
|
+
readonly clientHeight: number;
|
|
242
|
+
getAttribute(name: string): string | null;
|
|
243
|
+
appendChild(node: ShaderCanvasLike): unknown;
|
|
244
|
+
style: {
|
|
245
|
+
getPropertyValue(name: string): string;
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
/** The slice of `Document` this renderer touches. */
|
|
249
|
+
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;
|
|
254
|
+
}
|
|
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). */
|
|
269
|
+
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. */
|
|
285
|
+
export interface ShaderBackdropStats {
|
|
286
|
+
level: number;
|
|
287
|
+
width: number;
|
|
288
|
+
height: number;
|
|
289
|
+
frames: number;
|
|
290
|
+
alive: boolean;
|
|
291
|
+
contextLost: boolean;
|
|
292
|
+
style: ShaderStyle;
|
|
293
|
+
/** Actual back-end string from `WEBGL_debug_renderer_info`, when exposed. */
|
|
294
|
+
renderer: string | null;
|
|
295
|
+
}
|
|
296
|
+
/** Options accepted by {@link createShaderBackdrop}. */
|
|
297
|
+
export interface ShaderBackdropOptions {
|
|
298
|
+
doc: ShaderDocLike;
|
|
299
|
+
win: ShaderWinLike;
|
|
300
|
+
host: ShaderHostLike;
|
|
301
|
+
style?: ShaderStyle;
|
|
302
|
+
/** Panel overrides for the boot style; clamps to its `ranges`. */
|
|
303
|
+
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. */
|
|
306
|
+
onFallback?: (reason: 'context-lost') => void;
|
|
307
|
+
}
|
|
308
|
+
/** Handle owned by the appearance painter. */
|
|
309
|
+
export interface ShaderBackdrop {
|
|
310
|
+
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. */
|
|
313
|
+
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
|
+
setParams(params: ShaderParams): void;
|
|
318
|
+
/** Move the calm zone (the reading column); `null` disables the mask. */
|
|
319
|
+
setFocus(rect: BgFocusRect | null): void;
|
|
320
|
+
destroy(): void;
|
|
321
|
+
readonly stats: ShaderBackdropStats;
|
|
322
|
+
}
|
|
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
|
+
*/
|
|
329
|
+
export declare function createShaderBackdrop(options: ShaderBackdropOptions): ShaderBackdrop | null;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small height-field wave tank shared by interactive pieces.
|
|
3
|
+
*
|
|
4
|
+
* Diffusion alone only blurs an impulse; it never makes a ripple travel. This
|
|
5
|
+
* is a two-buffer wave equation instead: height `h` and vertical velocity `v`
|
|
6
|
+
* are advanced with a five-point Laplacian, damped, then swapped. A ring
|
|
7
|
+
* injection therefore expands, interferes with the next ring and dies out on
|
|
8
|
+
* its own — the property that makes dragging a finger on the water read as
|
|
9
|
+
* water rather than as a moving spotlight.
|
|
10
|
+
*
|
|
11
|
+
* Both passes are O(cols × rows), allocation-free, and the field is rebuilt
|
|
12
|
+
* only when the grid actually changes.
|
|
13
|
+
* @module @alexpeng/dsh-custom-plugin/client/bg-wake
|
|
14
|
+
*/
|
|
15
|
+
/** Wave coupling. Above ~0.5 the explicit scheme is unstable in 2D. */
|
|
16
|
+
export declare const WAKE_C2 = 0.28;
|
|
17
|
+
/** Per-step velocity damping (energy loss). */
|
|
18
|
+
export declare const WAKE_DAMPING = 0.975;
|
|
19
|
+
/** Per-step height decay (slow return to flat water). */
|
|
20
|
+
export declare const WAKE_DECAY = 0.993;
|
|
21
|
+
/** Clamp so a burst of injections can never make the surface explode. */
|
|
22
|
+
export declare const WAKE_MAX = 1.4;
|
|
23
|
+
/** Two height buffers and two velocity buffers, all `cols × rows`. */
|
|
24
|
+
export interface BgWakeField {
|
|
25
|
+
cols: number;
|
|
26
|
+
rows: number;
|
|
27
|
+
height: Float32Array;
|
|
28
|
+
nextHeight: Float32Array;
|
|
29
|
+
velocity: Float32Array;
|
|
30
|
+
nextVelocity: Float32Array;
|
|
31
|
+
}
|
|
32
|
+
/** Allocate a flat field. */
|
|
33
|
+
export declare function createWakeField(cols: number, rows: number): BgWakeField;
|
|
34
|
+
/** Resize in place. Returns true when the grid changed and the caller must
|
|
35
|
+
* treat the surface as freshly flat. */
|
|
36
|
+
export declare function resizeWakeField(field: BgWakeField, cols: number, rows: number): boolean;
|
|
37
|
+
/** Drop every wave but keep the buffers. */
|
|
38
|
+
export declare function clearWake(field: BgWakeField): void;
|
|
39
|
+
/**
|
|
40
|
+
* Advance one step. The outer one-cell border is absorbing (zeroed) so the
|
|
41
|
+
* viewport edge does not act like a bathtub wall and bounce rings back.
|
|
42
|
+
*/
|
|
43
|
+
export declare function stepWake(field: BgWakeField): void;
|
|
44
|
+
/**
|
|
45
|
+
* A soft circular depression (pointer drag). `radius` and `x/y` are in cells.
|
|
46
|
+
* The write is clamped to the field and never allocates.
|
|
47
|
+
*/
|
|
48
|
+
export declare function injectWake(field: BgWakeField, x: number, y: number, radius: number, strength: number): void;
|
|
49
|
+
/**
|
|
50
|
+
* A ring impulse (a click). The profile is a Gaussian band around `radius`;
|
|
51
|
+
* `strength` may be negative for the rebound half of a splash.
|
|
52
|
+
*/
|
|
53
|
+
export declare function injectWakeRing(field: BgWakeField, x: number, y: number, radius: number, width: number, strength: number): void;
|
|
54
|
+
/** A small wake behind a swimming fish. */
|
|
55
|
+
export declare function injectWakeTrail(field: BgWakeField, x: number, y: number, strength: number): void;
|
|
56
|
+
/** Nearest-cell height sample (used by fish steering and tests). */
|
|
57
|
+
export declare function sampleWake(field: BgWakeField, x: number, y: number): number;
|