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