@holtjs/stage 0.0.1 → 0.4.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 +82 -0
- package/LICENSE +201 -0
- package/NOTICE +13 -0
- package/README.md +173 -0
- package/dist/audio.d.ts +159 -0
- package/dist/audio.js +781 -0
- package/dist/ecs.d.ts +172 -0
- package/dist/ecs.js +537 -0
- package/dist/flex.d.ts +113 -0
- package/dist/flex.js +426 -0
- package/dist/game-C6NrnZ7-.d.ts +1799 -0
- package/dist/game-CbmA4myj.js +5899 -0
- package/dist/headless.d.ts +154 -0
- package/dist/headless.js +356 -0
- package/dist/hit.d.ts +63 -0
- package/dist/hit.js +185 -0
- package/dist/index.d.ts +314 -0
- package/dist/index.js +49 -0
- package/dist/joystick.d.ts +233 -0
- package/dist/joystick.js +763 -0
- package/dist/kernel.d.ts +2 -0
- package/dist/kernel.js +639 -0
- package/dist/nav.d.ts +119 -0
- package/dist/nav.js +342 -0
- package/dist/particles.d.ts +219 -0
- package/dist/particles.js +478 -0
- package/dist/renderer-webgpu-Bvvi5jN8.js +2618 -0
- package/dist/renderer-webgpu.d.ts +2 -0
- package/dist/renderer-webgpu.js +1 -0
- package/dist/spatial.d.ts +70 -0
- package/dist/spatial.js +165 -0
- package/dist/surfaces.d.ts +209 -0
- package/dist/surfaces.js +567 -0
- package/dist/trace.d.ts +2 -0
- package/dist/trace.js +247 -0
- package/dist/tween-BiF1FUvc.d.ts +93 -0
- package/dist/tween.d.ts +2 -0
- package/dist/tween.js +316 -0
- package/dist/types-DRFB0Klc.js +168 -0
- package/llms.txt +40 -0
- package/package.json +118 -1
- package/skills/stage/SKILL.md +272 -0
- package/skills/stage/references/subpaths.md +82 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { $ as WebGpuCanvasContextLike, Q as WebGpuBootstrapResult, X as RendererWebGpuOptions, Y as RendererWebGpu, Z as RequestWebGpuOptions, et as WebGpuDeviceLike, tt as requestWebGpuDevice } from "./game-C6NrnZ7-.js";
|
|
2
|
+
export { RendererWebGpu, RendererWebGpuOptions, RequestWebGpuOptions, WebGpuBootstrapResult, WebGpuCanvasContextLike, WebGpuDeviceLike, requestWebGpuDevice };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as RendererWebGpu, n as requestWebGpuDevice } from "./renderer-webgpu-Bvvi5jN8.js";
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export interface Vec2 {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
}
|
|
5
|
+
export interface SpatialHashBuffers {
|
|
6
|
+
readonly cols: number;
|
|
7
|
+
readonly rows: number;
|
|
8
|
+
readonly cellSize: number;
|
|
9
|
+
readonly originX: number;
|
|
10
|
+
readonly originY: number;
|
|
11
|
+
readonly cellStart: Int32Array;
|
|
12
|
+
readonly cellItems: Int32Array;
|
|
13
|
+
readonly cellOf: Int32Array;
|
|
14
|
+
readonly cursor: Int32Array;
|
|
15
|
+
}
|
|
16
|
+
export interface SpatialHashOptions {
|
|
17
|
+
/** World width covered by the grid (in world units, e.g. px or tiles). */
|
|
18
|
+
width: number;
|
|
19
|
+
/** World height covered by the grid. */
|
|
20
|
+
height: number;
|
|
21
|
+
/** Side length of one grid cell (choose >= typical query / separation diameter). */
|
|
22
|
+
cellSize: number;
|
|
23
|
+
/** Maximum number of indexed entities. */
|
|
24
|
+
maxItems: number;
|
|
25
|
+
/** Optional world-space minimum X (default 0). */
|
|
26
|
+
originX?: number;
|
|
27
|
+
/** Optional world-space minimum Y (default 0). */
|
|
28
|
+
originY?: number;
|
|
29
|
+
}
|
|
30
|
+
/** Allocate plain, structuredClone-friendly TypedArray buffers for a uniform spatial hash. */
|
|
31
|
+
export declare function createSpatialHashBuffers(opts: SpatialHashOptions): SpatialHashBuffers;
|
|
32
|
+
/**
|
|
33
|
+
* Rebuild a CSR uniform spatial hash in O(count + cols * rows) with zero heap allocations.
|
|
34
|
+
* Preserves deterministic ascending-index order inside each cell.
|
|
35
|
+
*/
|
|
36
|
+
export declare function rebuildSpatialHash(cellStart: Int32Array, cellItems: Int32Array, cellOf: Int32Array, cursor: Int32Array, xs: ArrayLike<number>, ys: ArrayLike<number>, count: number, cellSize: number, cols: number, rows: number, originX?: number, originY?: number): void;
|
|
37
|
+
/**
|
|
38
|
+
* Visit every entity index in the `(2 * cellRadius + 1)^2` cells around `(x, y)`.
|
|
39
|
+
* Stops early as soon as `visitor(index)` returns `true`.
|
|
40
|
+
*/
|
|
41
|
+
export declare function querySpatialNeighborhood(cellStart: Int32Array, cellItems: Int32Array, x: number, y: number, cellSize: number, cols: number, rows: number, visitor: (index: number) => boolean | void, cellRadius?: number, originX?: number, originY?: number): void;
|
|
42
|
+
/**
|
|
43
|
+
* Visit every entity index within Euclidean `radius` of `(x, y)` using the spatial hash.
|
|
44
|
+
* Stops early when `visitor(index, distSq)` returns `true`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function querySpatialRadius(cellStart: Int32Array, cellItems: Int32Array, xs: ArrayLike<number>, ys: ArrayLike<number>, x: number, y: number, radius: number, cellSize: number, cols: number, rows: number, visitor: (index: number, distSq: number) => boolean | void, originX?: number, originY?: number): void;
|
|
47
|
+
/**
|
|
48
|
+
* Visit every entity index whose cell overlaps the world-space rectangle `[minX, maxX] x [minY, maxY]`.
|
|
49
|
+
* Stops early when `visitor(index)` returns `true`.
|
|
50
|
+
*/
|
|
51
|
+
export declare function querySpatialRect(cellStart: Int32Array, cellItems: Int32Array, minX: number, minY: number, maxX: number, maxY: number, cellSize: number, cols: number, rows: number, visitor: (index: number) => boolean | void, originX?: number, originY?: number): void;
|
|
52
|
+
/**
|
|
53
|
+
* Accumulate deterministic pairwise neighbor separation vector for entity `selfIndex` at `(x, y)`
|
|
54
|
+
* against all neighbors closer than `minDist` in the surrounding `(2 * cellRadius + 1)^2` cells.
|
|
55
|
+
* Writes result into `out` with zero heap allocation.
|
|
56
|
+
*/
|
|
57
|
+
export declare function accumulateSpatialSeparation(cellStart: Int32Array, cellItems: Int32Array, xs: ArrayLike<number>, ys: ArrayLike<number>, selfIndex: number, x: number, y: number, minDist: number, cellSize: number, cols: number, rows: number, out: Vec2, cellRadius?: number, originX?: number, originY?: number): Vec2;
|
|
58
|
+
/** Ergonomic stateful wrapper over `SpatialHashBuffers` for games, world plugins, and Mods. */
|
|
59
|
+
export declare class SpatialHashGrid {
|
|
60
|
+
readonly buffers: SpatialHashBuffers;
|
|
61
|
+
constructor(opts: SpatialHashOptions);
|
|
62
|
+
get cols(): number;
|
|
63
|
+
get rows(): number;
|
|
64
|
+
get cellSize(): number;
|
|
65
|
+
rebuild(count: number, xs: ArrayLike<number>, ys: ArrayLike<number>): void;
|
|
66
|
+
queryNeighborhood(x: number, y: number, visitor: (index: number) => boolean | void, cellRadius?: number): void;
|
|
67
|
+
queryRadius(x: number, y: number, radius: number, xs: ArrayLike<number>, ys: ArrayLike<number>, visitor: (index: number, distSq: number) => boolean | void): void;
|
|
68
|
+
queryRect(minX: number, minY: number, maxX: number, maxY: number, visitor: (index: number) => boolean | void): void;
|
|
69
|
+
accumulateSeparation(selfIndex: number, x: number, y: number, minDist: number, xs: ArrayLike<number>, ys: ArrayLike<number>, out: Vec2, cellRadius?: number): Vec2;
|
|
70
|
+
}
|
package/dist/spatial.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// src/spatial.ts
|
|
2
|
+
const clampCell = (v, hi) => !(v > 0) ? 0 : v > hi ? hi : v;
|
|
3
|
+
/** Allocate plain, structuredClone-friendly TypedArray buffers for a uniform spatial hash. */
|
|
4
|
+
function createSpatialHashBuffers(opts) {
|
|
5
|
+
const cellSize = Math.max(1e-6, opts.cellSize);
|
|
6
|
+
const cols = Math.max(1, Math.ceil(opts.width / cellSize));
|
|
7
|
+
const rows = Math.max(1, Math.ceil(opts.height / cellSize));
|
|
8
|
+
const nCells = cols * rows;
|
|
9
|
+
const maxItems = Math.max(1, Math.floor(opts.maxItems));
|
|
10
|
+
return {
|
|
11
|
+
cols,
|
|
12
|
+
rows,
|
|
13
|
+
cellSize,
|
|
14
|
+
originX: opts.originX ?? 0,
|
|
15
|
+
originY: opts.originY ?? 0,
|
|
16
|
+
cellStart: new Int32Array(nCells + 1),
|
|
17
|
+
cellItems: new Int32Array(maxItems),
|
|
18
|
+
cellOf: new Int32Array(maxItems),
|
|
19
|
+
cursor: new Int32Array(nCells)
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Rebuild a CSR uniform spatial hash in O(count + cols * rows) with zero heap allocations.
|
|
24
|
+
* Preserves deterministic ascending-index order inside each cell.
|
|
25
|
+
*/
|
|
26
|
+
function rebuildSpatialHash(cellStart, cellItems, cellOf, cursor, xs, ys, count, cellSize, cols, rows, originX = 0, originY = 0) {
|
|
27
|
+
const nCells = cols * rows;
|
|
28
|
+
cellStart.fill(0, 0, nCells + 1);
|
|
29
|
+
const n = Math.max(0, Math.min(count | 0, cellItems.length, cellOf.length));
|
|
30
|
+
const maxX = cols - 1;
|
|
31
|
+
const maxY = rows - 1;
|
|
32
|
+
for (let i = 0; i < n; i++) {
|
|
33
|
+
const gx = clampCell(Math.floor((xs[i] - originX) / cellSize), maxX);
|
|
34
|
+
const c = clampCell(Math.floor((ys[i] - originY) / cellSize), maxY) * cols + gx;
|
|
35
|
+
cellOf[i] = c;
|
|
36
|
+
cellStart[c + 1]++;
|
|
37
|
+
}
|
|
38
|
+
for (let c = 0; c < nCells; c++) cellStart[c + 1] += cellStart[c];
|
|
39
|
+
cursor.set(cellStart.subarray(0, nCells));
|
|
40
|
+
for (let i = 0; i < n; i++) cellItems[cursor[cellOf[i]]++] = i;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Visit every entity index in the `(2 * cellRadius + 1)^2` cells around `(x, y)`.
|
|
44
|
+
* Stops early as soon as `visitor(index)` returns `true`.
|
|
45
|
+
*/
|
|
46
|
+
function querySpatialNeighborhood(cellStart, cellItems, x, y, cellSize, cols, rows, visitor, cellRadius = 1, originX = 0, originY = 0) {
|
|
47
|
+
const cx = Math.floor((x - originX) / cellSize);
|
|
48
|
+
const cy = Math.floor((y - originY) / cellSize);
|
|
49
|
+
const gy0 = Math.max(0, cy - cellRadius);
|
|
50
|
+
const gy1 = Math.min(rows - 1, cy + cellRadius);
|
|
51
|
+
const gx0 = Math.max(0, cx - cellRadius);
|
|
52
|
+
const gx1 = Math.min(cols - 1, cx + cellRadius);
|
|
53
|
+
for (let gy = gy0; gy <= gy1; gy++) for (let gx = gx0; gx <= gx1; gx++) {
|
|
54
|
+
const c = gy * cols + gx;
|
|
55
|
+
for (let k = cellStart[c], end = cellStart[c + 1]; k < end; k++) if (visitor(cellItems[k])) return;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Visit every entity index within Euclidean `radius` of `(x, y)` using the spatial hash.
|
|
60
|
+
* Stops early when `visitor(index, distSq)` returns `true`.
|
|
61
|
+
*/
|
|
62
|
+
function querySpatialRadius(cellStart, cellItems, xs, ys, x, y, radius, cellSize, cols, rows, visitor, originX = 0, originY = 0) {
|
|
63
|
+
if (!(radius >= 0)) return;
|
|
64
|
+
const r2 = radius * radius;
|
|
65
|
+
const gx0 = Math.max(0, Math.floor((x - radius - originX) / cellSize));
|
|
66
|
+
const gx1 = Math.min(cols - 1, Math.floor((x + radius - originX) / cellSize));
|
|
67
|
+
const gy0 = Math.max(0, Math.floor((y - radius - originY) / cellSize));
|
|
68
|
+
const gy1 = Math.min(rows - 1, Math.floor((y + radius - originY) / cellSize));
|
|
69
|
+
for (let gy = gy0; gy <= gy1; gy++) for (let gx = gx0; gx <= gx1; gx++) {
|
|
70
|
+
const c = gy * cols + gx;
|
|
71
|
+
for (let k = cellStart[c], end = cellStart[c + 1]; k < end; k++) {
|
|
72
|
+
const j = cellItems[k];
|
|
73
|
+
const dx = xs[j] - x;
|
|
74
|
+
const dy = ys[j] - y;
|
|
75
|
+
const q = dx * dx + dy * dy;
|
|
76
|
+
if (q <= r2 && visitor(j, q)) return;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Visit every entity index whose cell overlaps the world-space rectangle `[minX, maxX] x [minY, maxY]`.
|
|
82
|
+
* Stops early when `visitor(index)` returns `true`.
|
|
83
|
+
*/
|
|
84
|
+
function querySpatialRect(cellStart, cellItems, minX, minY, maxX, maxY, cellSize, cols, rows, visitor, originX = 0, originY = 0) {
|
|
85
|
+
const gx0 = Math.max(0, Math.floor((minX - originX) / cellSize));
|
|
86
|
+
const gx1 = Math.min(cols - 1, Math.floor((maxX - originX) / cellSize));
|
|
87
|
+
const gy0 = Math.max(0, Math.floor((minY - originY) / cellSize));
|
|
88
|
+
const gy1 = Math.min(rows - 1, Math.floor((maxY - originY) / cellSize));
|
|
89
|
+
for (let gy = gy0; gy <= gy1; gy++) for (let gx = gx0; gx <= gx1; gx++) {
|
|
90
|
+
const c = gy * cols + gx;
|
|
91
|
+
for (let k = cellStart[c], end = cellStart[c + 1]; k < end; k++) if (visitor(cellItems[k])) return;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Accumulate deterministic pairwise neighbor separation vector for entity `selfIndex` at `(x, y)`
|
|
96
|
+
* against all neighbors closer than `minDist` in the surrounding `(2 * cellRadius + 1)^2` cells.
|
|
97
|
+
* Writes result into `out` with zero heap allocation.
|
|
98
|
+
*/
|
|
99
|
+
function accumulateSpatialSeparation(cellStart, cellItems, xs, ys, selfIndex, x, y, minDist, cellSize, cols, rows, out, cellRadius = 1, originX = 0, originY = 0) {
|
|
100
|
+
let sx = 0;
|
|
101
|
+
let sy = 0;
|
|
102
|
+
const r2 = minDist * minDist;
|
|
103
|
+
const cx = Math.floor((x - originX) / cellSize);
|
|
104
|
+
const cy = Math.floor((y - originY) / cellSize);
|
|
105
|
+
const gy0 = Math.max(0, cy - cellRadius);
|
|
106
|
+
const gy1 = Math.min(rows - 1, cy + cellRadius);
|
|
107
|
+
const gx0 = Math.max(0, cx - cellRadius);
|
|
108
|
+
const gx1 = Math.min(cols - 1, cx + cellRadius);
|
|
109
|
+
for (let gy = gy0; gy <= gy1; gy++) for (let gx = gx0; gx <= gx1; gx++) {
|
|
110
|
+
const c = gy * cols + gx;
|
|
111
|
+
for (let k = cellStart[c], end = cellStart[c + 1]; k < end; k++) {
|
|
112
|
+
const j = cellItems[k];
|
|
113
|
+
if (j === selfIndex) continue;
|
|
114
|
+
const dx = x - xs[j];
|
|
115
|
+
const dy = y - ys[j];
|
|
116
|
+
const q = dx * dx + dy * dy;
|
|
117
|
+
if (q < r2 && q > 1e-6) {
|
|
118
|
+
const dd = Math.sqrt(q);
|
|
119
|
+
const f = (minDist - dd) / dd;
|
|
120
|
+
sx += dx * f;
|
|
121
|
+
sy += dy * f;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
out.x = sx;
|
|
126
|
+
out.y = sy;
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
/** Ergonomic stateful wrapper over `SpatialHashBuffers` for games, world plugins, and Mods. */
|
|
130
|
+
var SpatialHashGrid = class {
|
|
131
|
+
buffers;
|
|
132
|
+
constructor(opts) {
|
|
133
|
+
this.buffers = createSpatialHashBuffers(opts);
|
|
134
|
+
}
|
|
135
|
+
get cols() {
|
|
136
|
+
return this.buffers.cols;
|
|
137
|
+
}
|
|
138
|
+
get rows() {
|
|
139
|
+
return this.buffers.rows;
|
|
140
|
+
}
|
|
141
|
+
get cellSize() {
|
|
142
|
+
return this.buffers.cellSize;
|
|
143
|
+
}
|
|
144
|
+
rebuild(count, xs, ys) {
|
|
145
|
+
const b = this.buffers;
|
|
146
|
+
rebuildSpatialHash(b.cellStart, b.cellItems, b.cellOf, b.cursor, xs, ys, count, b.cellSize, b.cols, b.rows, b.originX, b.originY);
|
|
147
|
+
}
|
|
148
|
+
queryNeighborhood(x, y, visitor, cellRadius = 1) {
|
|
149
|
+
const b = this.buffers;
|
|
150
|
+
querySpatialNeighborhood(b.cellStart, b.cellItems, x, y, b.cellSize, b.cols, b.rows, visitor, cellRadius, b.originX, b.originY);
|
|
151
|
+
}
|
|
152
|
+
queryRadius(x, y, radius, xs, ys, visitor) {
|
|
153
|
+
const b = this.buffers;
|
|
154
|
+
querySpatialRadius(b.cellStart, b.cellItems, xs, ys, x, y, radius, b.cellSize, b.cols, b.rows, visitor, b.originX, b.originY);
|
|
155
|
+
}
|
|
156
|
+
queryRect(minX, minY, maxX, maxY, visitor) {
|
|
157
|
+
const b = this.buffers;
|
|
158
|
+
querySpatialRect(b.cellStart, b.cellItems, minX, minY, maxX, maxY, b.cellSize, b.cols, b.rows, visitor, b.originX, b.originY);
|
|
159
|
+
}
|
|
160
|
+
accumulateSeparation(selfIndex, x, y, minDist, xs, ys, out, cellRadius = 1) {
|
|
161
|
+
const b = this.buffers;
|
|
162
|
+
return accumulateSpatialSeparation(b.cellStart, b.cellItems, xs, ys, selfIndex, x, y, minDist, b.cellSize, b.cols, b.rows, out, cellRadius, b.originX, b.originY);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
export { SpatialHashGrid, accumulateSpatialSeparation, createSpatialHashBuffers, querySpatialNeighborhood, querySpatialRadius, querySpatialRect, rebuildSpatialHash };
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
export declare const SURFACE_BAND: {
|
|
2
|
+
/** Base world / canvas input (movement, interaction, camera zoom). */
|
|
3
|
+
readonly world: 100;
|
|
4
|
+
/** Passive non-blocking HUD cards & contextual hints. */
|
|
5
|
+
readonly hud: 200;
|
|
6
|
+
/** Active workspaces, docked editors & fullscreen modes. */
|
|
7
|
+
readonly workspace: 400;
|
|
8
|
+
/** Guided coach-mark tours (map-scoped or global). */
|
|
9
|
+
readonly tour: 500;
|
|
10
|
+
/** Blocking dialogs, modals, drawers & floating windows. */
|
|
11
|
+
readonly modal: 600;
|
|
12
|
+
/** Non-modal floating popovers, panels & sheets. */
|
|
13
|
+
readonly popover: 700;
|
|
14
|
+
/** Transient menus, dropdowns, select lists & inline pickers. */
|
|
15
|
+
readonly menu: 800;
|
|
16
|
+
/** Blocking confirmation dialogs & critical alerts. */
|
|
17
|
+
readonly confirm: 900;
|
|
18
|
+
/** Full-screen opaque loading, transition & connection-failure covers. */
|
|
19
|
+
readonly cover: 950;
|
|
20
|
+
/** Raw key capture (e.g. keybinding recorder). */
|
|
21
|
+
readonly capture: 1000;
|
|
22
|
+
};
|
|
23
|
+
export type SurfaceBandName = keyof typeof SURFACE_BAND;
|
|
24
|
+
export type SurfaceBand = SurfaceBandName | number;
|
|
25
|
+
export type SurfaceScope = 'global' | 'map';
|
|
26
|
+
export type SurfaceBarrier = 'none' | 'modal' | 'fullscreen';
|
|
27
|
+
export interface SurfaceCancelContext {
|
|
28
|
+
/** True when focus or event target is inside an editable control (input, textarea, native select, contenteditable). */
|
|
29
|
+
readonly inEditable: boolean;
|
|
30
|
+
/** True when Ctrl, Meta, or Alt is held alongside Escape. */
|
|
31
|
+
readonly hasModifier: boolean;
|
|
32
|
+
/** True on auto-repeat keydown events. */
|
|
33
|
+
readonly repeat: boolean;
|
|
34
|
+
/** Underlying DOM KeyboardEvent when triggered from keyboard, or null for synthetic/hardware Back triggers. */
|
|
35
|
+
readonly event: KeyboardEvent | null;
|
|
36
|
+
}
|
|
37
|
+
export interface SurfaceKeyContext {
|
|
38
|
+
/** True when focus or event target is inside an editable control. */
|
|
39
|
+
readonly inEditable: boolean;
|
|
40
|
+
/** True when Ctrl, Meta, or Alt is held. */
|
|
41
|
+
readonly hasModifier: boolean;
|
|
42
|
+
/** True on auto-repeat keydown events. */
|
|
43
|
+
readonly repeat: boolean;
|
|
44
|
+
/** Event phase: `'keydown'` or `'keyup'`. */
|
|
45
|
+
readonly type: 'keydown' | 'keyup';
|
|
46
|
+
/** Underlying DOM KeyboardEvent (or null in headless tests). */
|
|
47
|
+
readonly event: KeyboardEvent | null;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Result from `onCancel`:
|
|
51
|
+
* - `true` or `void` (`undefined`): consumed; stop routing and suppress default/propagation.
|
|
52
|
+
* - `'yield'`: stop routing without consuming the DOM event so an editable control owned by this surface handles it.
|
|
53
|
+
* - `false`: declined; continue walking down ONLY if this surface's `barrier` is `'none'`.
|
|
54
|
+
*/
|
|
55
|
+
export type SurfaceCancelResult = boolean | 'yield' | void;
|
|
56
|
+
/**
|
|
57
|
+
* Result from `onKey`:
|
|
58
|
+
* - `true` or `void` (`undefined`): consumed (`preventDefault` + `stopPropagation` + `stopImmediatePropagation`).
|
|
59
|
+
* - `'stop'`: stop propagation to lower DOM/bubble listeners (`stopPropagation` only, preserving sibling capture listeners).
|
|
60
|
+
* - `'yield'`: stop walking the surface tree without touching the DOM event.
|
|
61
|
+
* - `false`: not handled; continue walking down ONLY if this surface's `barrier` is `'none'` (or `passthroughKey` matched).
|
|
62
|
+
*/
|
|
63
|
+
export type SurfaceKeyResult = boolean | 'stop' | 'yield' | void;
|
|
64
|
+
export interface SurfaceFocusContext {
|
|
65
|
+
/** `1` for Tab (forward), `-1` for Shift+Tab (backward). */
|
|
66
|
+
readonly dir: 1 | -1;
|
|
67
|
+
/** True when Ctrl, Meta, or Alt is held alongside Tab. */
|
|
68
|
+
readonly hasModifier: boolean;
|
|
69
|
+
/** Underlying DOM KeyboardEvent (or null in headless tests). */
|
|
70
|
+
readonly event: KeyboardEvent | null;
|
|
71
|
+
/** Live active-element getter for the dispatching window's document (cross-realm safe for Document PiP and reflects focus restoration by higher handlers / `beforeCycle`). */
|
|
72
|
+
readonly getActiveElement?: () => Element | null;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Result from `onFocusCycle`:
|
|
76
|
+
* - `true` or `void` (`undefined`): handled; stop walking and consume the Tab event.
|
|
77
|
+
* - `'yield'`: stop walking without consuming the DOM event (let native focus or menu handle Tab).
|
|
78
|
+
* - `false`: declined; continue walking down ONLY if this surface's `barrier` is `'none'`.
|
|
79
|
+
*/
|
|
80
|
+
export type SurfaceFocusResult = boolean | 'yield' | void;
|
|
81
|
+
export interface SurfaceNodeInput {
|
|
82
|
+
/** Stable identifier (optional; auto-generated if omitted). Re-registering an existing ID updates & raises it. */
|
|
83
|
+
id?: string;
|
|
84
|
+
/** Semantic stacking band or explicit numeric priority (higher renders on top and receives input first). */
|
|
85
|
+
band: SurfaceBand;
|
|
86
|
+
/**
|
|
87
|
+
* Viewport scope:
|
|
88
|
+
* - `'global'` (default): top-level DOM or dedicated Stage2D canvas above the map.
|
|
89
|
+
* - `'map'`: rendered on the map scene's `UiRoot`; automatically occluded whenever any active `'global'`
|
|
90
|
+
* surface declares `barrier: 'fullscreen'`.
|
|
91
|
+
*/
|
|
92
|
+
scope?: SurfaceScope;
|
|
93
|
+
/** Optional parent surface ID; when missing or inactive, this child surface is automatically inactive. */
|
|
94
|
+
parent?: string;
|
|
95
|
+
/**
|
|
96
|
+
* Input & visual occlusion barrier:
|
|
97
|
+
* - `'none'` (default): non-blocking floating card, popover, menu, or docked panel.
|
|
98
|
+
* - `'modal'`: blocks all lower surfaces from receiving cancel/key input & focus.
|
|
99
|
+
* - `'fullscreen'`: blocks all lower input AND marks lower surfaces visually occluded.
|
|
100
|
+
*/
|
|
101
|
+
barrier?: SurfaceBarrier | (() => SurfaceBarrier);
|
|
102
|
+
/** Optional live readiness gate; when false the surface is inactive without removing it. */
|
|
103
|
+
enabled?: () => boolean;
|
|
104
|
+
/** Semantic `ui.cancel` handler (Escape, Android/HarmonyOS Back, Gamepad B). */
|
|
105
|
+
onCancel?: (ctx: SurfaceCancelContext) => SurfaceCancelResult;
|
|
106
|
+
/** Unified keyboard shortcut / world-input handler (`_shortcut_input` / `_unhandled_input`). */
|
|
107
|
+
onKey?: (ctx: SurfaceKeyContext) => SurfaceKeyResult;
|
|
108
|
+
/** Unified keyboard focus-cycle (`Tab` / `Shift+Tab`) handler (`ui_focus_next` / `ui_focus_prev`), respecting Barriers. */
|
|
109
|
+
onFocusCycle?: (ctx: SurfaceFocusContext) => SurfaceFocusResult;
|
|
110
|
+
/** Whether `onCancel` intercepts while an editable field has focus (default: `priority >= SURFACE_BAND.menu`). */
|
|
111
|
+
allowCancelInEditable?: boolean;
|
|
112
|
+
/** Whether `onCancel` accepts Ctrl / Meta / Alt modifiers (default: `false`). */
|
|
113
|
+
allowCancelModifiers?: boolean;
|
|
114
|
+
/** Whether `onKey` runs while an editable field has focus (default: `false`). */
|
|
115
|
+
allowKeyInEditable?: boolean;
|
|
116
|
+
/** Optional allowlist of keys that pass through this surface's barrier (e.g. voice mute `M` / push-to-talk `Space`). */
|
|
117
|
+
passthroughKey?: (e: KeyboardEvent) => boolean;
|
|
118
|
+
}
|
|
119
|
+
export interface SurfaceNodeInfo {
|
|
120
|
+
readonly id: string;
|
|
121
|
+
readonly priority: number;
|
|
122
|
+
readonly seq: number;
|
|
123
|
+
readonly scope: SurfaceScope;
|
|
124
|
+
readonly barrier: SurfaceBarrier;
|
|
125
|
+
readonly parent: string | null;
|
|
126
|
+
}
|
|
127
|
+
export interface SurfaceCancelDispatchResult {
|
|
128
|
+
readonly handled: boolean;
|
|
129
|
+
readonly id: string | null;
|
|
130
|
+
readonly blockedBy: string | null;
|
|
131
|
+
}
|
|
132
|
+
export interface SurfaceKeyDispatchResult {
|
|
133
|
+
readonly handled: boolean;
|
|
134
|
+
readonly preventDefault: boolean;
|
|
135
|
+
readonly id: string | null;
|
|
136
|
+
readonly blockedBy: string | null;
|
|
137
|
+
}
|
|
138
|
+
export interface SurfaceFocusDispatchResult {
|
|
139
|
+
readonly handled: boolean;
|
|
140
|
+
readonly id: string | null;
|
|
141
|
+
readonly blockedBy: string | null;
|
|
142
|
+
}
|
|
143
|
+
export interface SurfaceTree {
|
|
144
|
+
/** Register (or update & raise) a surface node; returns an idempotent token-safe disposer. */
|
|
145
|
+
register(input: SurfaceNodeInput): () => void;
|
|
146
|
+
/** Remove a surface by ID. Returns true if an entry existed. */
|
|
147
|
+
unregister(id: string): boolean;
|
|
148
|
+
/** Move an existing surface to the top (highest recency) of its band. Returns true if found. */
|
|
149
|
+
raise(id: string): boolean;
|
|
150
|
+
/** True when `id` is currently registered (regardless of `enabled()`). */
|
|
151
|
+
has(id: string): boolean;
|
|
152
|
+
/** True when `id` is registered, enabled, has an active parent chain, and is not globally occluded. */
|
|
153
|
+
isActive(id: string): boolean;
|
|
154
|
+
/** Ordered snapshot of all registered surfaces (highest priority / most recent first). */
|
|
155
|
+
entries(): ReadonlyArray<SurfaceNodeInfo>;
|
|
156
|
+
/** Ordered snapshot of currently active surfaces (highest priority / most recent first). */
|
|
157
|
+
active(): ReadonlyArray<SurfaceNodeInfo>;
|
|
158
|
+
/** Topmost active `'modal'` or `'fullscreen'` barrier (or null when none is active). */
|
|
159
|
+
topBarrier(opts?: {
|
|
160
|
+
scope?: SurfaceScope;
|
|
161
|
+
fullscreenOnly?: boolean;
|
|
162
|
+
}): SurfaceNodeInfo | null;
|
|
163
|
+
/** True when any active higher barrier (or global fullscreen barrier for `'map'` surfaces) blocks `id`. */
|
|
164
|
+
isBlocked(id: string): boolean;
|
|
165
|
+
/** True when any active `'fullscreen'` barrier covers `id` (or covers the map when `id` is omitted). */
|
|
166
|
+
isOccluded(id?: string): boolean;
|
|
167
|
+
/** True when any active `'modal'` or `'fullscreen'` barrier above `SURFACE_BAND.world` blocks map world input. */
|
|
168
|
+
isWorldBlocked(): boolean;
|
|
169
|
+
/** True when any active higher surface (optionally filtered by `minBand` / `barriersOnly`) sits above `id`. */
|
|
170
|
+
hasHigherSurface(id: string, opts?: {
|
|
171
|
+
minBand?: SurfaceBand;
|
|
172
|
+
barriersOnly?: boolean;
|
|
173
|
+
}): boolean;
|
|
174
|
+
/** True when an active cancel handler is eligible for this context without invoking it (used for repeat suppression). */
|
|
175
|
+
hasEligibleCancel(ctx: Pick<SurfaceCancelContext, 'inEditable' | 'hasModifier'>): boolean;
|
|
176
|
+
/** Dispatch semantic `ui.cancel` (Escape / Back) top-down, stopping at consumed handlers or active barriers. */
|
|
177
|
+
dispatchCancel(ctx: SurfaceCancelContext): SurfaceCancelDispatchResult;
|
|
178
|
+
/** Dispatch a non-cancel keyboard event top-down (`_shortcut_input` -> `_unhandled_input`), respecting barriers. */
|
|
179
|
+
dispatchKey(ctx: SurfaceKeyContext): SurfaceKeyDispatchResult;
|
|
180
|
+
/** Dispatch semantic `ui_focus_next` / `ui_focus_prev` (`Tab` / `Shift+Tab`) top-down, respecting barriers. */
|
|
181
|
+
dispatchFocus(ctx: SurfaceFocusContext): SurfaceFocusDispatchResult;
|
|
182
|
+
/** Subscribe to structural changes (`register`, `unregister`, `raise`, `clear`). */
|
|
183
|
+
subscribe(fn: () => void): () => void;
|
|
184
|
+
/** Remove all registered surfaces (useful for teardown & unit tests). */
|
|
185
|
+
clear(): void;
|
|
186
|
+
}
|
|
187
|
+
export declare function resolveSurfacePriority(band: SurfaceBand): number;
|
|
188
|
+
export interface SurfaceDomEntry {
|
|
189
|
+
readonly id: string;
|
|
190
|
+
readonly priority: number;
|
|
191
|
+
readonly seq: number;
|
|
192
|
+
/** Number of consecutive DOM z-index slots reserved for this surface and its offset companions (default 1). */
|
|
193
|
+
readonly span?: number;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Canonical pure mapping from `SURFACE_BAND` priority to base root-DOM `z-index`.
|
|
197
|
+
* Allocates strictly disjoint z-index ranges across bands so DOM companions and overlays
|
|
198
|
+
* never interleave across semantic priority boundaries.
|
|
199
|
+
*/
|
|
200
|
+
export declare function surfacePriorityToDomZ(priority: number): number;
|
|
201
|
+
/**
|
|
202
|
+
* Compute strictly monotonic root-DOM `z-index` assignments for active surfaces from their
|
|
203
|
+
* `(priority, seq)` order (ascending = back to front). Ties within the same band advance
|
|
204
|
+
* by the previous surface's `span` (clamped within `[base, cap]` so cross-band monotonicity holds).
|
|
205
|
+
*/
|
|
206
|
+
export declare function computeSurfaceDomZ(entries: ReadonlyArray<SurfaceDomEntry>): Map<string, number>;
|
|
207
|
+
export declare function createSurfaceTree(opts?: {
|
|
208
|
+
onError?: (id: string, err: unknown) => void;
|
|
209
|
+
}): SurfaceTree;
|