@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
|
@@ -1,397 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ASCII character backdrop: the renderer that lives inside `div#vx-bg`.
|
|
3
|
-
*
|
|
4
|
-
* The hot loop never builds strings. Each piece writes one ramp level per
|
|
5
|
-
* cell into a reused `Uint8Array`, and the renderer blits a pre-baked glyph
|
|
6
|
-
* atlas with `drawImage` only — one atlas per (theme, font, dpr, tile size),
|
|
7
|
-
* rebuilt on demand and never per frame. That is what keeps a 15 fps field of
|
|
8
|
-
* ~10k cells free of per-frame allocations and `fillText` metric work.
|
|
9
|
-
*
|
|
10
|
-
* Motion is read from the layer's `data-vx-bg-motion` attribute and the
|
|
11
|
-
* surface from `--vx-bg-tint`; page visibility and the reduced-motion media
|
|
12
|
-
* query are observed here as well. Degradation follows a fixed ladder —
|
|
13
|
-
* frame rate → density → mono → dither → static frame → off — and never
|
|
14
|
-
* climbs back on its own inside one session.
|
|
15
|
-
*
|
|
16
|
-
* Phase 3a ships the ASCII system presets — `flow`, `rain`, `ocean`,
|
|
17
|
-
* `starfield`, `ripple`, plus the zero-rAF `static` tier. Each preset is its
|
|
18
|
-
* own piece (falling trails, horizontal swells, sparse stars, concentric
|
|
19
|
-
* rings), not the flow field with different knobs. Switching presets reuses
|
|
20
|
-
* the canvas and the grid buffer; the atlas is rebuilt only when the ramp,
|
|
21
|
-
* ink, theme or cell geometry changes.
|
|
22
|
-
* @module @alexpeng/dsh-custom-plugin/client/bg-ascii
|
|
23
|
-
*/
|
|
24
|
-
import { type BgFocusRect } from './bg-focus.ts';
|
|
25
|
-
import { type AsciiPiece } from './bg-field.ts';
|
|
26
|
-
import { type BgPointerEventLike } from './bg-pointer.ts';
|
|
27
|
-
export { FLOW_LEVEL_FLOOR, quantizeLevel } from './bg-field.ts';
|
|
28
|
-
export type { AsciiInput, AsciiPiece } from './bg-field.ts';
|
|
29
|
-
export { createOceanPiece } from './bg-ocean.ts';
|
|
30
|
-
/** Upper bound for the backing-store scale. */
|
|
31
|
-
export declare const DPR_CAP = 2;
|
|
32
|
-
/** Hard grid caps: beyond these the cell size grows instead of the grid. */
|
|
33
|
-
export declare const MAX_COLS = 240;
|
|
34
|
-
/** Hard grid caps: beyond these the cell size grows instead of the grid. */
|
|
35
|
-
export declare const MAX_ROWS = 96;
|
|
36
|
-
/** Monospace stack; `ui-monospace` resolves locally, so nothing is fetched. */
|
|
37
|
-
export declare const MONO_STACK = "ui-monospace, SFMono-Regular, Menlo, Consolas, \"Cascadia Mono\", \"DejaVu Sans Mono\", monospace";
|
|
38
|
-
/** Glyph ramps. Only guaranteed-monospace ASCII; CJK and box drawing are
|
|
39
|
-
* deliberately excluded because their advance is not 0.6 em in every face. */
|
|
40
|
-
export type AsciiCharset = 'classic' | 'blocks' | 'dots';
|
|
41
|
-
/** Glyph ramps ordered by increasing ink density. */
|
|
42
|
-
export declare const CHARSET: Record<AsciiCharset, string>;
|
|
43
|
-
/** Every ASCII piece id. `static` is the zero-rAF tier. */
|
|
44
|
-
export type AsciiPreset = 'flow' | 'rain' | 'ocean' | 'starfield' | 'ripple' | 'static';
|
|
45
|
-
/** Inclusive numeric bounds a future settings panel may write. */
|
|
46
|
-
export interface AsciiRange {
|
|
47
|
-
readonly min: number;
|
|
48
|
-
readonly max: number;
|
|
49
|
-
}
|
|
50
|
-
/** Writable bounds per preset; defaults above sit inside these. */
|
|
51
|
-
export interface AsciiPresetRanges {
|
|
52
|
-
readonly density: AsciiRange;
|
|
53
|
-
readonly speed: AsciiRange;
|
|
54
|
-
readonly fps: AsciiRange;
|
|
55
|
-
readonly fontPx: AsciiRange;
|
|
56
|
-
readonly opacity: AsciiRange;
|
|
57
|
-
}
|
|
58
|
-
/** Tunables of one preset. */
|
|
59
|
-
export interface AsciiPresetSpec {
|
|
60
|
-
readonly density: number;
|
|
61
|
-
readonly speed: number;
|
|
62
|
-
readonly fps: number;
|
|
63
|
-
readonly charset: AsciiCharset;
|
|
64
|
-
readonly dither: boolean;
|
|
65
|
-
readonly opacity: number;
|
|
66
|
-
readonly fontPx: number;
|
|
67
|
-
/** Per-piece ink multiplier on the theme's base ΔL. The dense `blocks`
|
|
68
|
-
* pieces need none (1.0); the `dots` pieces carry far less ink per cell, so
|
|
69
|
-
* they lift the ink to reach the same perceived strength. Also multiplied by
|
|
70
|
-
* the user's soft/standard/strong strength choice. */
|
|
71
|
-
readonly inkScale: number;
|
|
72
|
-
/** The piece consumes pointer input and may mark interaction cells in the
|
|
73
|
-
* emphasis buffer. `flow` and `ocean` opt in today; `static` deliberately
|
|
74
|
-
* does not, so its one frame stays deterministic. */
|
|
75
|
-
readonly interactive?: boolean;
|
|
76
|
-
/** Shape-aware rendering: a cell on a contour swaps its ramp glyph for a
|
|
77
|
-
* directional stroke of similar ink weight (the MIT `glyph-graphics` idea).
|
|
78
|
-
* The `dots` pieces and `rain` keep their plain ramp. */
|
|
79
|
-
readonly shapeAware?: boolean;
|
|
80
|
-
readonly ranges: AsciiPresetRanges;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* System presets. `flow` is the default animated tier; `static` draws one
|
|
84
|
-
* deterministic flow frame (zero rAF). The other four are genuinely different
|
|
85
|
-
* pieces: vertical falling trails, horizontal swells, sparse parallax stars
|
|
86
|
-
* and concentric rings. `density` varies the cell size, so only `flow` and
|
|
87
|
-
* `static` share one baked atlas today.
|
|
88
|
-
*
|
|
89
|
-
* `inkScale` is the per-piece visibility calibration (measurements in
|
|
90
|
-
* AGENTS.md, 2026-11-08, 1280×822 dpr 1.5, reading column over the composited
|
|
91
|
-
* page): a dot glyph carries ~1/6 of a block glyph's ink, so the dots pieces
|
|
92
|
-
* need a bigger per-cell step to be seen at all, and the sparse starfield
|
|
93
|
-
* needs a brighter point rather than more area. These numbers are measured,
|
|
94
|
-
* not taste: `flow` at 1.0 reads 0.15% mean ink mass / 2.99% peak; `ocean` at
|
|
95
|
-
* 1.4 with density 0.65 reads 0.17% / 4.37%; `ripple` at 1.25 reads 0.11% /
|
|
96
|
-
* 3.11%; `starfield` at 1.6 reads a 5.15% star peak while staying <0.4%
|
|
97
|
-
* covered; `rain` stays at 1.1 because its 13.3% inter-frame change (the
|
|
98
|
-
* highest of the six) is what carries it, not its ink mass.
|
|
99
|
-
*/
|
|
100
|
-
export declare const ASCII_PRESETS: Record<AsciiPreset, AsciiPresetSpec>;
|
|
101
|
-
/** Resolve a stored preset id to an ASCII piece. A shader-tier id (or any
|
|
102
|
-
* unknown string) is a stale combination and falls back to `flow`. */
|
|
103
|
-
export declare function resolveAsciiPreset(preset: string | undefined): AsciiPreset;
|
|
104
|
-
/** Panel overrides for one ASCII preset. Every value is clamped into the
|
|
105
|
-
* preset's own `ranges` before it is used, so an out-of-range value (a stale
|
|
106
|
-
* state file, a slider crossing a preset switch) never reaches the grid.
|
|
107
|
-
* `strength` is the user's soft/standard/strong multiplier, applied on top of
|
|
108
|
-
* the piece's own `inkScale`; it is clamped to the ink scale band, not to a
|
|
109
|
-
* preset range. */
|
|
110
|
-
export type AsciiParams = Partial<Record<'density' | 'speed' | 'fps' | 'fontPx' | 'opacity' | 'strength', number>>;
|
|
111
|
-
/**
|
|
112
|
-
* Resolve overrides against one preset. Missing or invalid keys fall back to
|
|
113
|
-
* the preset's own default, so a preset switch never inherits a value the new
|
|
114
|
-
* piece cannot honour. The returned `inkScale` is the piece's calibrated value
|
|
115
|
-
* times the user's strength multiplier. Returns the base spec object itself
|
|
116
|
-
* when nothing is overridden (no allocation until the user actually moves a
|
|
117
|
-
* slider).
|
|
118
|
-
*/
|
|
119
|
-
export declare function resolveAsciiSpec(preset: AsciiPreset, params: AsciiParams): AsciiPresetSpec;
|
|
120
|
-
/** Resize debounce before the grid is rebuilt. */
|
|
121
|
-
export declare const RESIZE_DEBOUNCE_MS = 150;
|
|
122
|
-
/** Frames per degradation statistics window. */
|
|
123
|
-
export declare const LADDER_WINDOW = 60;
|
|
124
|
-
/** A window is "over budget" above this multiple of the frame budget. */
|
|
125
|
-
export declare const LADDER_OVER_BUDGET = 1.6;
|
|
126
|
-
/** Consecutive bad windows before one ladder step. */
|
|
127
|
-
export declare const LADDER_BAD_WINDOWS = 2;
|
|
128
|
-
/** Last rung: 0 full … 5 static frame, 6 no glyphs (surface only). */
|
|
129
|
-
export declare const DEGRADE_MAX = 6;
|
|
130
|
-
/** Inside the calm zone, cells an interactive piece marks as part of the
|
|
131
|
-
* effect (a ripple crest, a fish) keep this fraction of the ramp instead of
|
|
132
|
-
* the zone's 0.15 floor. Raised 0.5 → 0.65 on 2026-11-11: the user asked for
|
|
133
|
-
* the pointer response to read more clearly, and a user-caused ripple may sit
|
|
134
|
-
* nearer the column's own contrast than the ambient texture — the ambient
|
|
135
|
-
* stays at the 0.15 floor, so only what the hand just did gets brighter. */
|
|
136
|
-
export declare const EFFECT_FOCUS_FLOOR = 0.65;
|
|
137
|
-
/**
|
|
138
|
-
* Measure the cell in CSS pixels. `measureText` ignores the current
|
|
139
|
-
* transform, so the probe needs no dpr scaling: 50 glyphs cancel the
|
|
140
|
-
* sub-pixel rounding of a single advance. Row height is 1.15 em, leaving
|
|
141
|
-
* roughly 0.18 em above and below the ink so rows never touch.
|
|
142
|
-
*/
|
|
143
|
-
export declare function measureCell(ctx: AsciiCtxLike, fontPx: number): {
|
|
144
|
-
cellW: number;
|
|
145
|
-
cellH: number;
|
|
146
|
-
};
|
|
147
|
-
/** A surface counts as dark below this weighted brightness (0..255). */
|
|
148
|
-
export declare function isDarkSurface(hex: string): boolean;
|
|
149
|
-
/**
|
|
150
|
-
* The `flow` piece: a slowly drifting value-noise field. `t` is already
|
|
151
|
-
* scaled by the preset speed. Dithering only makes sense on short ramps;
|
|
152
|
-
* at 16 levels it adds noise instead of removing banding.
|
|
153
|
-
*
|
|
154
|
-
* The field is lifted by {@link FLOW_LEVEL_FLOOR} before quantisation. That
|
|
155
|
-
* lift is the round-1 visibility fix, and it is a *coverage* fix, not an ink
|
|
156
|
-
* fix: value noise spends most of its area near 0.5, which quantises onto the
|
|
157
|
-
* `blocks` ramp's mid glyphs (`+` / `*`) — measured at 12 px those carry only
|
|
158
|
-
* 5.5% / 4.4% of a cell's ink area, against 12% for `#`, 17% for `%` and 23%
|
|
159
|
-
* for `@`. Raising the ink ΔL further does nothing to that (the ink is already
|
|
160
|
-
* near-black and the surface halves it), while the lift moves the typical cell
|
|
161
|
-
* from `+` to `#`-`%`, i.e. 2–3× the ink mass on screen.
|
|
162
|
-
*/
|
|
163
|
-
export declare function createFlowPiece(levels: number, dither: boolean, interactive?: boolean): AsciiPiece;
|
|
164
|
-
/**
|
|
165
|
-
* The `rain` piece: falling columns. Each column owns a phase, a fall speed
|
|
166
|
-
* and a trail length derived from its index; roughly one column in seven is
|
|
167
|
-
* dormant, so the rain reads as patchy weather rather than a curtain. The
|
|
168
|
-
* head is the brightest cell and the trail fades quadratically behind it.
|
|
169
|
-
*
|
|
170
|
-
* The pointer bends whole columns sideways instead of editing individual
|
|
171
|
-
* drops: a drag is wind (displacement scaled by pointer speed and falling off
|
|
172
|
-
* with distance), and simply resting on the page parts the curtain into a
|
|
173
|
-
* tunnel around the cursor. A press pushes the nearby columns away and
|
|
174
|
-
* brightens only their heads for a moment — the trail itself is untouched.
|
|
175
|
-
* With no input every weight stays at zero, so the frame is bit-identical to
|
|
176
|
-
* the pre-interaction rain.
|
|
177
|
-
*/
|
|
178
|
-
export declare function createRainPiece(levels: number, dither: boolean): AsciiPiece;
|
|
179
|
-
/**
|
|
180
|
-
* The `starfield` piece: sparse stars on a mostly blank field, drifting and
|
|
181
|
-
* twinkling slowly. The cells below the star thresholds stay at level 0, so
|
|
182
|
-
* the blit loop skips them and the tier is the cheapest. The thresholds are
|
|
183
|
-
* calibrated (see `ASCII_PRESETS.starfield`), and the field is split into
|
|
184
|
-
* three depth layers that drift at different speeds — far 0.05 rows/s, mid
|
|
185
|
-
* 0.10, near 0.18 — so the picture has parallax without a second canvas.
|
|
186
|
-
* The pointer shifts those layers by up to 15 px (≈1 cell horizontally) in
|
|
187
|
-
* proportion to its distance from the page centre, eased at 0.12 per frame.
|
|
188
|
-
*
|
|
189
|
-
* The pointer cannot make a sparse field denser without breaking its
|
|
190
|
-
* character, so direct interaction is light: a press scatters a burst of live
|
|
191
|
-
* stars and a drag drops a thin trail. Dwelling adds the slower cue — stars
|
|
192
|
-
* inside a 150 px ellipse brighten, and after about a second a small cluster
|
|
193
|
-
* of near-miss cells has accumulated; both fade out in roughly a second once
|
|
194
|
-
* the pointer leaves, leaving the baseline bit-identical.
|
|
195
|
-
*/
|
|
196
|
-
export declare function createStarfieldPiece(levels: number, _dither: boolean): AsciiPiece;
|
|
197
|
-
/**
|
|
198
|
-
* The `ripple` piece: concentric rings from three fixed origins, plus rings
|
|
199
|
-
* the pointer drops. Each ring decays with distance from its origin, keeping
|
|
200
|
-
* the field low-contrast — crests brighten, troughs fall back toward the base,
|
|
201
|
-
* nothing saturates. Dithering stays off: the stipple would break the contour
|
|
202
|
-
* lines the rings are read through.
|
|
203
|
-
*
|
|
204
|
-
* A press drops one strong ring where it lands; its amplitude and speed grow
|
|
205
|
-
* with the pointer velocity, so a flick throws a harder splash than a resting
|
|
206
|
-
* click. A drag leaves a trail of weak ones about every 0.22 s and every five
|
|
207
|
-
* cells, so the pointer moves like a fingertip across water. Slots are a fixed
|
|
208
|
-
* ring buffer — no allocation per drop, no growth with drag length.
|
|
209
|
-
*/
|
|
210
|
-
export declare function createRipplePiece(levels: number, dither: boolean): AsciiPiece;
|
|
211
|
-
/** Pick the piece for one preset. `static` reuses the flow field at t=0. */
|
|
212
|
-
export declare function createPresetPiece(preset: AsciiPreset, levels: number, dither: boolean): AsciiPiece;
|
|
213
|
-
/** Structural canvas surface needed by the renderer and by tests. */
|
|
214
|
-
export interface AsciiCtxLike {
|
|
215
|
-
font: string;
|
|
216
|
-
textAlign: string;
|
|
217
|
-
textBaseline: string;
|
|
218
|
-
globalAlpha: number;
|
|
219
|
-
fillStyle: string;
|
|
220
|
-
imageSmoothingEnabled: boolean;
|
|
221
|
-
measureText(text: string): {
|
|
222
|
-
width: number;
|
|
223
|
-
};
|
|
224
|
-
fillText(text: string, x: number, y: number): void;
|
|
225
|
-
fillRect(x: number, y: number, width: number, height: number): void;
|
|
226
|
-
setTransform(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
|
227
|
-
drawImage(image: AsciiCanvasLike, sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number): void;
|
|
228
|
-
}
|
|
229
|
-
/** Structural canvas surface needed by the renderer and by tests. */
|
|
230
|
-
export interface AsciiCanvasLike {
|
|
231
|
-
width: number;
|
|
232
|
-
height: number;
|
|
233
|
-
className: string;
|
|
234
|
-
style: {
|
|
235
|
-
width: string;
|
|
236
|
-
height: string;
|
|
237
|
-
};
|
|
238
|
-
getContext(contextId: '2d'): AsciiCtxLike | null;
|
|
239
|
-
remove(): void;
|
|
240
|
-
}
|
|
241
|
-
/** The host element (`div#vx-bg`) as the renderer sees it. */
|
|
242
|
-
export interface AsciiHostLike {
|
|
243
|
-
readonly clientWidth: number;
|
|
244
|
-
readonly clientHeight: number;
|
|
245
|
-
getAttribute(name: string): string | null;
|
|
246
|
-
appendChild(node: AsciiCanvasLike): unknown;
|
|
247
|
-
style: {
|
|
248
|
-
getPropertyValue(name: string): string;
|
|
249
|
-
};
|
|
250
|
-
/** Optional viewport offset. The page host sits at 0,0; the conversation
|
|
251
|
-
* host is a fixed layer over the column, so pointer CSS px must be shifted
|
|
252
|
-
* into host-local coordinates before they become grid cells. */
|
|
253
|
-
getBoundingClientRect?(): {
|
|
254
|
-
readonly left: number;
|
|
255
|
-
readonly top: number;
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
/** The slice of `Document` this renderer touches. */
|
|
259
|
-
export interface AsciiDocLike {
|
|
260
|
-
createElement(tag: string): AsciiCanvasLike;
|
|
261
|
-
addEventListener(type: 'visibilitychange', listener: () => void): void;
|
|
262
|
-
removeEventListener(type: 'visibilitychange', listener: () => void): void;
|
|
263
|
-
readonly hidden: boolean;
|
|
264
|
-
}
|
|
265
|
-
/** The slice of `MediaQueryList` this renderer touches. */
|
|
266
|
-
export interface AsciiMediaQueryLike {
|
|
267
|
-
readonly matches: boolean;
|
|
268
|
-
addEventListener(type: 'change', listener: () => void): void;
|
|
269
|
-
removeEventListener(type: 'change', listener: () => void): void;
|
|
270
|
-
}
|
|
271
|
-
/** The slice of `ResizeObserver` this renderer touches. */
|
|
272
|
-
export interface AsciiResizeObserverLike {
|
|
273
|
-
observe(target: unknown): void;
|
|
274
|
-
disconnect(): void;
|
|
275
|
-
}
|
|
276
|
-
/** The slice of `Window` this renderer touches. The pointer methods are
|
|
277
|
-
* optional so a minimal fake window (and a host without PointerEvent) simply
|
|
278
|
-
* leaves interaction off instead of failing to boot. */
|
|
279
|
-
export interface AsciiWinLike {
|
|
280
|
-
readonly devicePixelRatio: number;
|
|
281
|
-
readonly innerWidth?: number;
|
|
282
|
-
readonly innerHeight?: number;
|
|
283
|
-
requestAnimationFrame(callback: (now: number) => void): number;
|
|
284
|
-
cancelAnimationFrame(handle: number): void;
|
|
285
|
-
matchMedia(query: string): AsciiMediaQueryLike;
|
|
286
|
-
ResizeObserver?: new (callback: () => void) => AsciiResizeObserverLike;
|
|
287
|
-
addEventListener?: (type: string, listener: (event: BgPointerEventLike) => void, options?: {
|
|
288
|
-
passive?: boolean;
|
|
289
|
-
}) => void;
|
|
290
|
-
removeEventListener?: (type: string, listener: (event: BgPointerEventLike) => void, options?: {
|
|
291
|
-
passive?: boolean;
|
|
292
|
-
}) => void;
|
|
293
|
-
}
|
|
294
|
-
/** One baked glyph atlas: the ramp tiles followed by optional directional
|
|
295
|
-
* extras, already coloured and faded. */
|
|
296
|
-
export interface Atlas {
|
|
297
|
-
canvas: AsciiCanvasLike;
|
|
298
|
-
/** Tile size in CSS px (the destination unit). */
|
|
299
|
-
tileW: number;
|
|
300
|
-
tileH: number;
|
|
301
|
-
/** Tile size in backing px (the source unit). */
|
|
302
|
-
pxW: number;
|
|
303
|
-
pxH: number;
|
|
304
|
-
glyphs: string[];
|
|
305
|
-
/** 1 when the glyph is a space; the draw loop skips those tiles. */
|
|
306
|
-
empty: Uint8Array;
|
|
307
|
-
/** (level × 5 + direction) → tile index, or null for a plain ramp atlas. */
|
|
308
|
-
chart: Uint8Array | null;
|
|
309
|
-
}
|
|
310
|
-
/** Inputs for {@link buildAtlas}; the canvas factory keeps tests DOM-free. */
|
|
311
|
-
export interface AtlasOptions {
|
|
312
|
-
createCanvas: () => AsciiCanvasLike;
|
|
313
|
-
chars: string;
|
|
314
|
-
ink: string;
|
|
315
|
-
dark: boolean;
|
|
316
|
-
dpr: number;
|
|
317
|
-
tileW: number;
|
|
318
|
-
tileH: number;
|
|
319
|
-
fontPx: number;
|
|
320
|
-
opacity: number;
|
|
321
|
-
/** Which ramp this is; selects the directional extras. */
|
|
322
|
-
charset?: AsciiCharset;
|
|
323
|
-
/** Bake the directional extras and the chart. */
|
|
324
|
-
shape?: boolean;
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* Bake one coloured tile per ramp level, plus optional directional extras.
|
|
328
|
-
* Level 0 is the blank glyph and the last ramp level is the densest one in
|
|
329
|
-
* **both** themes — pieces write levels, not glyphs, so a level must mean the
|
|
330
|
-
* same thing whichever ink the theme picks. Empty tiles are marked for the
|
|
331
|
-
* draw loop. Per-level alpha is baked here too, which is why the hot loop
|
|
332
|
-
* never touches `globalAlpha`.
|
|
333
|
-
*/
|
|
334
|
-
export declare function buildAtlas(options: AtlasOptions): Atlas | null;
|
|
335
|
-
/** Rolling degradation statistics. Fields stay mutable: no per-window alloc. */
|
|
336
|
-
export interface LadderState {
|
|
337
|
-
level: number;
|
|
338
|
-
badWindows: number;
|
|
339
|
-
sum: number;
|
|
340
|
-
count: number;
|
|
341
|
-
}
|
|
342
|
-
/** Fresh ladder pinned to rung 0. */
|
|
343
|
-
export declare function createLadder(): LadderState;
|
|
344
|
-
/**
|
|
345
|
-
* Feed one accepted draw interval. A window closes every
|
|
346
|
-
* {@link LADDER_WINDOW} frames; two consecutive over-budget windows step the
|
|
347
|
-
* ladder down one rung. A good window clears one bad window, so a single
|
|
348
|
-
* spike never degrades. Returns true when a step happened.
|
|
349
|
-
*/
|
|
350
|
-
export declare function observeFrame(state: LadderState, interval: number, budget: number): boolean;
|
|
351
|
-
/** Observable renderer state; tests and the live probe read this. */
|
|
352
|
-
export interface AsciiBackdropStats {
|
|
353
|
-
level: number;
|
|
354
|
-
cols: number;
|
|
355
|
-
rows: number;
|
|
356
|
-
frames: number;
|
|
357
|
-
atlasBuilds: number;
|
|
358
|
-
/** Cells the last frame marked as interaction effects (ripple crests, fish). */
|
|
359
|
-
emphasisCells: number;
|
|
360
|
-
/** Cells the last frame drew as overlay glyphs (small fish directions). */
|
|
361
|
-
overlayCells: number;
|
|
362
|
-
alive: boolean;
|
|
363
|
-
}
|
|
364
|
-
/** Options accepted by {@link createAsciiBackdrop}. */
|
|
365
|
-
export interface AsciiBackdropOptions {
|
|
366
|
-
doc: AsciiDocLike;
|
|
367
|
-
win: AsciiWinLike;
|
|
368
|
-
host: AsciiHostLike;
|
|
369
|
-
preset?: AsciiPreset;
|
|
370
|
-
/** Panel overrides for the boot preset; clamps to its `ranges`. */
|
|
371
|
-
params?: AsciiParams;
|
|
372
|
-
}
|
|
373
|
-
/** Handle owned by the appearance painter. */
|
|
374
|
-
export interface AsciiBackdrop {
|
|
375
|
-
/** Re-read motion + tint and paint/resume/stop accordingly. */
|
|
376
|
-
sync(): void;
|
|
377
|
-
/** Switch piece; resets the ladder to rung 0 and repaints immediately. The
|
|
378
|
-
* canvas and level buffer survive; the atlas is reused when its key (ramp,
|
|
379
|
-
* ink, theme, dpr, cell size, font, opacity) is unchanged. */
|
|
380
|
-
setPreset(preset: AsciiPreset): void;
|
|
381
|
-
/** Replace the panel overrides for the current preset. Values are clamped
|
|
382
|
-
* into that preset's `ranges`; a preset switch keeps the overrides and
|
|
383
|
-
* re-clamps them. Repaints immediately so a dragging slider is visible. */
|
|
384
|
-
setParams(params: AsciiParams): void;
|
|
385
|
-
/** Move the calm zone (the reading column). `null` disables the mask. The
|
|
386
|
-
* per-cell caps are rebuilt only when the zone or the grid actually moves. */
|
|
387
|
-
setFocus(rect: BgFocusRect | null): void;
|
|
388
|
-
/** Stop everything and free the canvas, listeners, arrays and atlases. */
|
|
389
|
-
destroy(): void;
|
|
390
|
-
readonly stats: AsciiBackdropStats;
|
|
391
|
-
}
|
|
392
|
-
/**
|
|
393
|
-
* Create the renderer and attach its canvas to the layer. The caller mounts
|
|
394
|
-
* `div#vx-bg` first (so the motion attribute and tint already exist), then
|
|
395
|
-
* calls {@link AsciiBackdrop.sync}.
|
|
396
|
-
*/
|
|
397
|
-
export declare function createAsciiBackdrop(options: AsciiBackdropOptions): AsciiBackdrop;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared field primitives for the ASCII backdrop pieces.
|
|
3
|
-
*
|
|
4
|
-
* A piece writes one ramp level per cell into a caller-owned `Uint8Array` and
|
|
5
|
-
* never allocates in its hot loop. Interaction is injected through
|
|
6
|
-
* {@link AsciiInput}; pieces that draw something other than water (fish
|
|
7
|
-
* glyphs) write a slot into the optional `overlay` buffer, and pieces whose
|
|
8
|
-
* cells must stay readable inside the calm zone mark them in `emphasis`.
|
|
9
|
-
*
|
|
10
|
-
* Keeping these types here (rather than in `bg-ascii.ts`) lets `bg-ocean.ts`
|
|
11
|
-
* depend on the contract without importing the renderer, so there is no
|
|
12
|
-
* module cycle between the piece and the canvas that hosts it.
|
|
13
|
-
* @module @alexpeng/dsh-custom-plugin/client/bg-field
|
|
14
|
-
*/
|
|
15
|
-
/** One frame is one ramp-level index per cell. The extra arguments are
|
|
16
|
-
* optional so the four older pieces and their tests keep compiling. */
|
|
17
|
-
export type AsciiPiece = (t: number, out: Uint8Array, cols: number, rows: number, input?: AsciiInput, emphasis?: Uint8Array, overlay?: Uint8Array) => void;
|
|
18
|
-
/** Pointer state in grid coordinates. The renderer maps CSS pixels onto cells
|
|
19
|
-
* once per frame, so a piece never touches the DOM or the event object. */
|
|
20
|
-
export interface AsciiInput {
|
|
21
|
-
/** Pointer position in cells. */
|
|
22
|
-
x: number;
|
|
23
|
-
y: number;
|
|
24
|
-
/** The pointer has been seen and has not left the window. */
|
|
25
|
-
active: boolean;
|
|
26
|
-
/** Primary button held down. */
|
|
27
|
-
down: boolean;
|
|
28
|
-
/** Smoothed velocity in cells per second. */
|
|
29
|
-
vx: number;
|
|
30
|
-
vy: number;
|
|
31
|
-
/** Increments once per press; a piece reacts to a change. */
|
|
32
|
-
pulseId: number;
|
|
33
|
-
pulseX: number;
|
|
34
|
-
pulseY: number;
|
|
35
|
-
}
|
|
36
|
-
/** Glyphs a piece may place through the overlay buffer. Index 0 is "none";
|
|
37
|
-
* 1–8 are single-cell direction marks for the small fish, 9–13 are the body,
|
|
38
|
-
* edge, head and tail cells of a koi. */
|
|
39
|
-
export declare const OVERLAY_GLYPHS: readonly string[];
|
|
40
|
-
/** Lowest field value the `flow` / `static` piece may emit, as a fraction of
|
|
41
|
-
* the ramp. 0.45 keeps the darkest cell around the middle of the ramp instead
|
|
42
|
-
* of the blank space glyph: the ink *area* per cell, not the ink darkness, is
|
|
43
|
-
* what the eye reads through the 0.5-alpha content surface. */
|
|
44
|
-
export declare const FLOW_LEVEL_FLOOR = 0.45;
|
|
45
|
-
/** Contrast and gamma stay internal: exposed knobs made every preset look
|
|
46
|
-
* worse. Values are deliberate no-ops until a preset needs them. */
|
|
47
|
-
export declare const CONTRAST = 1;
|
|
48
|
-
export declare const GAMMA = 1;
|
|
49
|
-
/** Bayer 4×4 ordered dither matrix (row-major). */
|
|
50
|
-
export declare const BAYER4: Uint8Array<ArrayBuffer>;
|
|
51
|
-
/** Quantize a 0..1 field value to a ramp index. Clamping lives here so a
|
|
52
|
-
* piece can never write outside the atlas. */
|
|
53
|
-
export declare function quantizeLevel(value: number, levels: number): number;
|
|
54
|
-
/** 32-bit integer hash → 0..1. `Math.imul` keeps the multiplications honest;
|
|
55
|
-
* plain `*` would lose the low bits once the product passes 2^53. */
|
|
56
|
-
export declare function hash2(x: number, y: number): number;
|
|
57
|
-
/** Smooth value noise; one octave is enough for a decorative drift field. */
|
|
58
|
-
export declare function valueNoise(x: number, y: number): number;
|
|
59
|
-
/** Shared tail of every piece: clamp, optional Bayer dither, quantize. */
|
|
60
|
-
export declare function shade(out: Uint8Array, i: number, v: number, levels: number, dither: boolean, row: number, col: number): void;
|
|
@@ -1,31 +0,0 @@
|
|
|
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;
|
|
@@ -1,107 +0,0 @@
|
|
|
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;
|
|
@@ -1,57 +0,0 @@
|
|
|
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;
|