@lifeart/async-dom 2.0.0-alpha.3
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/LICENSE +21 -0
- package/README.md +623 -0
- package/dist/base.d.cts +398 -0
- package/dist/base.d.cts.map +1 -0
- package/dist/base.d.ts +398 -0
- package/dist/base.d.ts.map +1 -0
- package/dist/cli.cjs +528 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +493 -0
- package/dist/cli.js.map +1 -0
- package/dist/debug.d.cts +145 -0
- package/dist/debug.d.cts.map +1 -0
- package/dist/debug.d.ts +145 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/index.cjs +26 -0
- package/dist/index.d.cts +560 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +560 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index2.d.cts +5 -0
- package/dist/index2.d.ts +5 -0
- package/dist/index3.d.cts +882 -0
- package/dist/index3.d.cts.map +1 -0
- package/dist/index3.d.ts +882 -0
- package/dist/index3.d.ts.map +1 -0
- package/dist/main-thread.cjs +5459 -0
- package/dist/main-thread.cjs.map +1 -0
- package/dist/main-thread.js +5429 -0
- package/dist/main-thread.js.map +1 -0
- package/dist/react.cjs +116 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +91 -0
- package/dist/react.d.cts.map +1 -0
- package/dist/react.d.ts +91 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +113 -0
- package/dist/react.js.map +1 -0
- package/dist/resolve-debug.cjs +24 -0
- package/dist/resolve-debug.cjs.map +1 -0
- package/dist/resolve-debug.js +19 -0
- package/dist/resolve-debug.js.map +1 -0
- package/dist/server.cjs +250 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +127 -0
- package/dist/server.d.cts.map +1 -0
- package/dist/server.d.ts +127 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +245 -0
- package/dist/server.js.map +1 -0
- package/dist/svelte.cjs +48 -0
- package/dist/svelte.cjs.map +1 -0
- package/dist/svelte.d.cts +38 -0
- package/dist/svelte.d.cts.map +1 -0
- package/dist/svelte.d.ts +38 -0
- package/dist/svelte.d.ts.map +1 -0
- package/dist/svelte.js +47 -0
- package/dist/svelte.js.map +1 -0
- package/dist/sync-channel.cjs +532 -0
- package/dist/sync-channel.cjs.map +1 -0
- package/dist/sync-channel.js +425 -0
- package/dist/sync-channel.js.map +1 -0
- package/dist/transport.cjs +213 -0
- package/dist/transport.cjs.map +1 -0
- package/dist/transport.d.cts +79 -0
- package/dist/transport.d.cts.map +1 -0
- package/dist/transport.d.ts +79 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +202 -0
- package/dist/transport.js.map +1 -0
- package/dist/vite-plugin.cjs +112 -0
- package/dist/vite-plugin.cjs.map +1 -0
- package/dist/vite-plugin.d.cts +39 -0
- package/dist/vite-plugin.d.cts.map +1 -0
- package/dist/vite-plugin.d.ts +39 -0
- package/dist/vite-plugin.d.ts.map +1 -0
- package/dist/vite-plugin.js +107 -0
- package/dist/vite-plugin.js.map +1 -0
- package/dist/vue.cjs +123 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.d.cts +126 -0
- package/dist/vue.d.cts.map +1 -0
- package/dist/vue.d.ts +126 -0
- package/dist/vue.d.ts.map +1 -0
- package/dist/vue.js +120 -0
- package/dist/vue.js.map +1 -0
- package/dist/worker-thread.cjs +2751 -0
- package/dist/worker-thread.cjs.map +1 -0
- package/dist/worker-thread.js +2692 -0
- package/dist/worker-thread.js.map +1 -0
- package/dist/worker-transport.cjs +136 -0
- package/dist/worker-transport.cjs.map +1 -0
- package/dist/worker-transport.d.cts +162 -0
- package/dist/worker-transport.d.cts.map +1 -0
- package/dist/worker-transport.d.ts +162 -0
- package/dist/worker-transport.d.ts.map +1 -0
- package/dist/worker-transport.js +125 -0
- package/dist/worker-transport.js.map +1 -0
- package/dist/worker.cjs +12 -0
- package/dist/worker.d.cts +2 -0
- package/dist/worker.d.ts +2 -0
- package/dist/worker.js +2 -0
- package/dist/ws-server-transport.cjs +147 -0
- package/dist/ws-server-transport.cjs.map +1 -0
- package/dist/ws-server-transport.d.cts +64 -0
- package/dist/ws-server-transport.d.cts.map +1 -0
- package/dist/ws-server-transport.d.ts +64 -0
- package/dist/ws-server-transport.d.ts.map +1 -0
- package/dist/ws-server-transport.js +142 -0
- package/dist/ws-server-transport.js.map +1 -0
- package/dist/ws-transport.cjs +954 -0
- package/dist/ws-transport.cjs.map +1 -0
- package/dist/ws-transport.js +913 -0
- package/dist/ws-transport.js.map +1 -0
- package/package.json +145 -0
|
@@ -0,0 +1,882 @@
|
|
|
1
|
+
import { c as DomMutation, f as InsertPosition, g as NodeId, i as AppId, t as Transport } from "./base.cjs";
|
|
2
|
+
import { n as DebugOptions } from "./debug.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/platform.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* PlatformHost abstraction for running async-dom in different environments
|
|
8
|
+
* (Web Worker, Node.js, etc.).
|
|
9
|
+
*
|
|
10
|
+
* Only three things need platform abstraction:
|
|
11
|
+
* 1. navigator (userAgent, language, etc.)
|
|
12
|
+
* 2. Error handlers (onerror, onunhandledrejection)
|
|
13
|
+
* 3. beforeunload / shutdown hook
|
|
14
|
+
*/
|
|
15
|
+
interface PlatformHost {
|
|
16
|
+
navigator: {
|
|
17
|
+
userAgent: string;
|
|
18
|
+
language: string;
|
|
19
|
+
languages: readonly string[];
|
|
20
|
+
hardwareConcurrency: number;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Install global error and unhandled rejection handlers.
|
|
24
|
+
* Returns a cleanup function that removes the handlers.
|
|
25
|
+
*/
|
|
26
|
+
installErrorHandlers(onError: (message: string, error?: Error, filename?: string, lineno?: number, colno?: number) => void, onUnhandledRejection: (reason: unknown) => void): () => void;
|
|
27
|
+
/**
|
|
28
|
+
* Register a callback to run before the environment shuts down.
|
|
29
|
+
* Returns a cleanup function that removes the hook.
|
|
30
|
+
*/
|
|
31
|
+
onBeforeUnload(callback: () => void): () => void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Create a PlatformHost for Web Worker environments (uses `self`).
|
|
35
|
+
*/
|
|
36
|
+
declare function createWorkerPlatform(): PlatformHost;
|
|
37
|
+
/**
|
|
38
|
+
* Create a PlatformHost for Node.js environments (uses `process`).
|
|
39
|
+
*/
|
|
40
|
+
declare function createNodePlatform(): PlatformHost;
|
|
41
|
+
/**
|
|
42
|
+
* Auto-detect the current platform and create the appropriate PlatformHost.
|
|
43
|
+
*/
|
|
44
|
+
declare function detectPlatform(): PlatformHost;
|
|
45
|
+
//# sourceMappingURL=platform.d.ts.map
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/core/sync-channel.d.ts
|
|
48
|
+
/**
|
|
49
|
+
* SharedArrayBuffer-based synchronous communication channel.
|
|
50
|
+
*
|
|
51
|
+
* Allows a worker thread to make blocking reads from the main thread
|
|
52
|
+
* using Atomics.wait/notify. Inspired by Partytown's approach.
|
|
53
|
+
*
|
|
54
|
+
* Buffer layout (SharedArrayBuffer):
|
|
55
|
+
* Int32Array view:
|
|
56
|
+
* [0] — signal: 0=idle, 1=request-pending, 2=response-ready
|
|
57
|
+
* [1] — query type enum
|
|
58
|
+
* [2] — request data length (bytes)
|
|
59
|
+
* [3] — response data length (bytes)
|
|
60
|
+
* Uint8Array view at offset 16: request data (JSON-encoded)
|
|
61
|
+
* Uint8Array view at offset 16+REQUEST_REGION_SIZE: response data (JSON-encoded)
|
|
62
|
+
*/
|
|
63
|
+
/** Type of synchronous query that a worker can make to the main thread. */
|
|
64
|
+
declare enum QueryType {
|
|
65
|
+
/** Request element.getBoundingClientRect() result. */
|
|
66
|
+
BoundingRect = 0,
|
|
67
|
+
/** Request window.getComputedStyle() result for a property. */
|
|
68
|
+
ComputedStyle = 1,
|
|
69
|
+
/** Request a DOM node property (e.g., clientWidth, scrollTop). */
|
|
70
|
+
NodeProperty = 2,
|
|
71
|
+
/** Request a window property (e.g., innerWidth). */
|
|
72
|
+
WindowProperty = 3,
|
|
73
|
+
}
|
|
74
|
+
/** A pending query read from the shared buffer by the main-thread host. */
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Worker-side synchronous channel.
|
|
78
|
+
* Uses Atomics.wait to block until the main thread responds.
|
|
79
|
+
*/
|
|
80
|
+
declare class SyncChannel {
|
|
81
|
+
private signal;
|
|
82
|
+
private meta;
|
|
83
|
+
private requestRegion;
|
|
84
|
+
private responseRegion;
|
|
85
|
+
private encoder;
|
|
86
|
+
private decoder;
|
|
87
|
+
private constructor();
|
|
88
|
+
/**
|
|
89
|
+
* Create a new SyncChannel with a fresh SharedArrayBuffer.
|
|
90
|
+
* The returned buffer must be transferred to the worker via postMessage.
|
|
91
|
+
* @param size - Total buffer size in bytes (default: 64KB)
|
|
92
|
+
*/
|
|
93
|
+
static create(size?: number): {
|
|
94
|
+
channel: SyncChannel;
|
|
95
|
+
buffer: SharedArrayBuffer;
|
|
96
|
+
};
|
|
97
|
+
/** Attach to an existing SharedArrayBuffer received from the main thread. */
|
|
98
|
+
static fromBuffer(sab: SharedArrayBuffer): SyncChannel;
|
|
99
|
+
/**
|
|
100
|
+
* Send a synchronous request to the main thread and block until response.
|
|
101
|
+
*
|
|
102
|
+
* Protocol:
|
|
103
|
+
* 1. Write JSON-encoded request data to the request region
|
|
104
|
+
* 2. Set query type and data length in the header via Atomics.store (memory fence)
|
|
105
|
+
* 3. Set signal to SIGNAL_REQUEST and notify the main thread
|
|
106
|
+
* 4. Block with Atomics.wait until signal changes or timeout (100ms per retry, 5 retries max)
|
|
107
|
+
* 5. Read JSON-encoded response from the response region
|
|
108
|
+
*
|
|
109
|
+
* @param queryType - The type of DOM query to execute
|
|
110
|
+
* @param data - JSON-encoded request payload
|
|
111
|
+
* @returns Parsed response object, or null on timeout or parse failure
|
|
112
|
+
*/
|
|
113
|
+
request(queryType: QueryType, data: string): unknown;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Main-thread host for the sync channel.
|
|
117
|
+
* Polls for pending requests and writes responses.
|
|
118
|
+
*/
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/worker-thread/mutation-collector.d.ts
|
|
121
|
+
/** Entry recording a coalesced (eliminated) mutation. */
|
|
122
|
+
interface CoalescedLogEntry {
|
|
123
|
+
action: string;
|
|
124
|
+
key: string;
|
|
125
|
+
timestamp: number;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Collects DOM mutations during synchronous execution and flushes them
|
|
129
|
+
* as a batched message at the end of the current microtask.
|
|
130
|
+
*/
|
|
131
|
+
declare class MutationCollector {
|
|
132
|
+
private appId;
|
|
133
|
+
private queue;
|
|
134
|
+
private scheduled;
|
|
135
|
+
private uidCounter;
|
|
136
|
+
private transport;
|
|
137
|
+
private _coalesceEnabled;
|
|
138
|
+
private _stats;
|
|
139
|
+
private _coalescedLog;
|
|
140
|
+
private _perTypeCoalesced;
|
|
141
|
+
/** Total mutations added (monotonically increasing counter for diff-based tracking). */
|
|
142
|
+
get totalAdded(): number;
|
|
143
|
+
/** Feature 15: Current causal event tag for this flush cycle */
|
|
144
|
+
private _causalEvent;
|
|
145
|
+
getStats(): {
|
|
146
|
+
added: number;
|
|
147
|
+
coalesced: number;
|
|
148
|
+
flushed: number;
|
|
149
|
+
};
|
|
150
|
+
getCoalescedLog(): CoalescedLogEntry[];
|
|
151
|
+
getPerTypeCoalesced(): Record<string, {
|
|
152
|
+
added: number;
|
|
153
|
+
coalesced: number;
|
|
154
|
+
}>;
|
|
155
|
+
constructor(appId: AppId);
|
|
156
|
+
/** Feature 15: Set the causal event for the current mutation cycle. */
|
|
157
|
+
setCausalEvent(event: {
|
|
158
|
+
eventType: string;
|
|
159
|
+
listenerId: string;
|
|
160
|
+
timestamp: number;
|
|
161
|
+
} | null): void;
|
|
162
|
+
/** Feature 15: Get current causal event. */
|
|
163
|
+
getCausalEvent(): {
|
|
164
|
+
eventType: string;
|
|
165
|
+
listenerId: string;
|
|
166
|
+
timestamp: number;
|
|
167
|
+
} | null;
|
|
168
|
+
enableCoalescing(enabled: boolean): void;
|
|
169
|
+
setTransport(transport: Transport): void;
|
|
170
|
+
add(mutation: DomMutation): void;
|
|
171
|
+
private coalesce;
|
|
172
|
+
private _buildKey;
|
|
173
|
+
flush(): void;
|
|
174
|
+
/** Force-flush all pending mutations immediately */
|
|
175
|
+
flushSync(): void;
|
|
176
|
+
/** Get number of pending mutations (useful for testing) */
|
|
177
|
+
get pendingCount(): number;
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=mutation-collector.d.ts.map
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region src/worker-thread/element.d.ts
|
|
182
|
+
/** Union of all virtual node types that can appear in the worker-side DOM tree. */
|
|
183
|
+
type VirtualNode = VirtualElement | VirtualTextNode | VirtualCommentNode;
|
|
184
|
+
/**
|
|
185
|
+
* Virtual DOM element that records mutations via the MutationCollector
|
|
186
|
+
* instead of touching real DOM.
|
|
187
|
+
*
|
|
188
|
+
* Implements a broad subset of the HTMLElement API:
|
|
189
|
+
* - Attributes: setAttribute, getAttribute, removeAttribute, dataset
|
|
190
|
+
* - Children: appendChild, removeChild, insertBefore, replaceChild, etc.
|
|
191
|
+
* - Text/HTML: textContent, innerHTML, outerHTML, insertAdjacentHTML
|
|
192
|
+
* - Input state: value, checked, disabled, selectedIndex (with main-thread sync)
|
|
193
|
+
* - Media state: currentTime, duration, paused, ended, readyState
|
|
194
|
+
* - Events: addEventListener, removeEventListener, on* handlers, dispatchEvent
|
|
195
|
+
* - Layout queries: getBoundingClientRect, clientWidth/Height, etc. (via SyncChannel)
|
|
196
|
+
* - CSS: style proxy, classList, className
|
|
197
|
+
* - Traversal: querySelector, closest, contains, parentNode, children, etc.
|
|
198
|
+
*
|
|
199
|
+
* Every mutating operation emits a DomMutation to the collector. Layout queries
|
|
200
|
+
* use the SyncChannel to synchronously read values from the main thread's DOM.
|
|
201
|
+
*/
|
|
202
|
+
declare class VirtualElement {
|
|
203
|
+
private collector;
|
|
204
|
+
static readonly ELEMENT_NODE = 1;
|
|
205
|
+
static readonly TEXT_NODE = 3;
|
|
206
|
+
static readonly COMMENT_NODE = 8;
|
|
207
|
+
static readonly DOCUMENT_NODE = 9;
|
|
208
|
+
static readonly DOCUMENT_FRAGMENT_NODE = 11;
|
|
209
|
+
readonly _nodeId: NodeId;
|
|
210
|
+
readonly nodeName: string;
|
|
211
|
+
readonly tagName: string;
|
|
212
|
+
readonly nodeType = 1;
|
|
213
|
+
readonly namespaceURI: string;
|
|
214
|
+
parentNode: VirtualElement | null;
|
|
215
|
+
_ownerDocument: VirtualDocument | null;
|
|
216
|
+
childNodes: VirtualNode[];
|
|
217
|
+
private _attributes;
|
|
218
|
+
private _classes;
|
|
219
|
+
private _textContent;
|
|
220
|
+
private _value;
|
|
221
|
+
private _checked;
|
|
222
|
+
private _disabled;
|
|
223
|
+
private _selectedIndex;
|
|
224
|
+
private _datasetProxy;
|
|
225
|
+
style: Record<string, string>;
|
|
226
|
+
classList: VirtualClassList;
|
|
227
|
+
get id(): string;
|
|
228
|
+
set id(value: string);
|
|
229
|
+
get children(): VirtualElement[];
|
|
230
|
+
get childElementCount(): number;
|
|
231
|
+
get firstElementChild(): VirtualElement | null;
|
|
232
|
+
get lastElementChild(): VirtualElement | null;
|
|
233
|
+
get clientWidth(): number;
|
|
234
|
+
get clientHeight(): number;
|
|
235
|
+
get scrollWidth(): number;
|
|
236
|
+
get scrollHeight(): number;
|
|
237
|
+
get offsetWidth(): number;
|
|
238
|
+
get offsetHeight(): number;
|
|
239
|
+
get offsetTop(): number;
|
|
240
|
+
get offsetLeft(): number;
|
|
241
|
+
get scrollTop(): number;
|
|
242
|
+
set scrollTop(v: number);
|
|
243
|
+
get scrollLeft(): number;
|
|
244
|
+
set scrollLeft(v: number);
|
|
245
|
+
/**
|
|
246
|
+
* Synchronously read a numeric DOM property from the main thread via SyncChannel.
|
|
247
|
+
* Returns null if no sync channel is available (e.g., no SharedArrayBuffer support).
|
|
248
|
+
*/
|
|
249
|
+
private _readNodeProperty;
|
|
250
|
+
constructor(tag: string, collector: MutationCollector, id?: NodeId);
|
|
251
|
+
_setNamespaceURI(ns: string): void;
|
|
252
|
+
setAttribute(name: string, value: string): void;
|
|
253
|
+
getAttribute(name: string): string | null;
|
|
254
|
+
hasAttribute(name: string): boolean;
|
|
255
|
+
removeAttribute(name: string): void;
|
|
256
|
+
getAttributeNS(_ns: string | null, name: string): string | null;
|
|
257
|
+
setAttributeNS(_ns: string | null, name: string, value: string): void;
|
|
258
|
+
removeAttributeNS(_ns: string | null, name: string): void;
|
|
259
|
+
get attributes(): {
|
|
260
|
+
length: number;
|
|
261
|
+
item(index: number): {
|
|
262
|
+
name: string;
|
|
263
|
+
value: string;
|
|
264
|
+
} | null;
|
|
265
|
+
};
|
|
266
|
+
appendChild(child: VirtualNode): VirtualNode;
|
|
267
|
+
private _appendSingleChild;
|
|
268
|
+
removeChild(child: VirtualNode): VirtualNode;
|
|
269
|
+
insertBefore(newChild: VirtualNode, refChild: VirtualNode | null): VirtualNode;
|
|
270
|
+
remove(): void;
|
|
271
|
+
append(...nodes: VirtualNode[]): void;
|
|
272
|
+
prepend(...nodes: VirtualNode[]): void;
|
|
273
|
+
replaceWith(...nodes: VirtualNode[]): void;
|
|
274
|
+
before(...nodes: VirtualNode[]): void;
|
|
275
|
+
after(...nodes: VirtualNode[]): void;
|
|
276
|
+
replaceChildren(...nodes: VirtualNode[]): void;
|
|
277
|
+
get textContent(): string;
|
|
278
|
+
set textContent(value: string);
|
|
279
|
+
get innerHTML(): string;
|
|
280
|
+
set innerHTML(value: string);
|
|
281
|
+
get outerHTML(): string;
|
|
282
|
+
get value(): string;
|
|
283
|
+
set value(v: string);
|
|
284
|
+
get checked(): boolean;
|
|
285
|
+
set checked(v: boolean);
|
|
286
|
+
get disabled(): boolean;
|
|
287
|
+
set disabled(v: boolean);
|
|
288
|
+
get selectedIndex(): number;
|
|
289
|
+
set selectedIndex(v: number);
|
|
290
|
+
/**
|
|
291
|
+
* Sync input state from a main-thread event without emitting mutations.
|
|
292
|
+
* Called by VirtualDocument.dispatchEvent to keep the worker's model in sync
|
|
293
|
+
* with real DOM input values after user interaction.
|
|
294
|
+
*/
|
|
295
|
+
_updateInputState(state: {
|
|
296
|
+
value?: string;
|
|
297
|
+
checked?: boolean;
|
|
298
|
+
selectedIndex?: number;
|
|
299
|
+
}): void;
|
|
300
|
+
private _currentTime;
|
|
301
|
+
private _duration;
|
|
302
|
+
private _paused;
|
|
303
|
+
private _ended;
|
|
304
|
+
private _readyState;
|
|
305
|
+
get currentTime(): number;
|
|
306
|
+
set currentTime(v: number);
|
|
307
|
+
get duration(): number;
|
|
308
|
+
get paused(): boolean;
|
|
309
|
+
get ended(): boolean;
|
|
310
|
+
get readyState(): number;
|
|
311
|
+
/** Sync media element state from a main-thread event without emitting mutations. */
|
|
312
|
+
_updateMediaState(state: Record<string, unknown>): void;
|
|
313
|
+
get className(): string;
|
|
314
|
+
set className(value: string);
|
|
315
|
+
/** Map of listenerId -> callback for event dispatch. */
|
|
316
|
+
private _eventListeners;
|
|
317
|
+
/** Map of listenerId -> event name, used to match removeEventListener by name+callback. */
|
|
318
|
+
private _listenerEventNames;
|
|
319
|
+
/** Map of event name -> callback for on* property handlers (e.g., onclick). */
|
|
320
|
+
private _onHandlers;
|
|
321
|
+
/**
|
|
322
|
+
* Register an event listener. Emits an addEventListener mutation so the main thread
|
|
323
|
+
* attaches a real DOM listener that will serialize and forward events back.
|
|
324
|
+
* Supports the `once` option by wrapping the callback with auto-removal.
|
|
325
|
+
*/
|
|
326
|
+
addEventListener(name: string, callback: (e: unknown) => void, options?: AddEventListenerOptions | boolean): void;
|
|
327
|
+
getEventListener(listenerId: string): ((e: unknown) => void) | undefined;
|
|
328
|
+
/** Remove a listener by event name and callback reference. Emits a removeEventListener mutation. */
|
|
329
|
+
removeEventListener(_name: string, callback: (e: unknown) => void): void;
|
|
330
|
+
/** Invoke all listeners matching the event type. Called during bubbling by VirtualDocument.dispatchEvent. */
|
|
331
|
+
_dispatchBubbledEvent(event: {
|
|
332
|
+
type: string;
|
|
333
|
+
immediatePropagationStopped?: boolean;
|
|
334
|
+
}): void;
|
|
335
|
+
/**
|
|
336
|
+
* Recursively clean up this element and all children from the document's registries.
|
|
337
|
+
* Called before emitting removal mutations to prevent memory leaks.
|
|
338
|
+
*/
|
|
339
|
+
_cleanupFromDocument(): void;
|
|
340
|
+
/** Emit a configureEvent mutation to tell the main thread to call preventDefault for this event. */
|
|
341
|
+
preventDefaultFor(eventName: string): void;
|
|
342
|
+
/** Implement on* handler properties (onclick, etc.) by managing a single listener per event name. */
|
|
343
|
+
private _setOnHandler;
|
|
344
|
+
set onclick(cb: ((e: unknown) => void) | null);
|
|
345
|
+
set ondblclick(cb: ((e: unknown) => void) | null);
|
|
346
|
+
set onmouseenter(cb: ((e: unknown) => void) | null);
|
|
347
|
+
set onmouseleave(cb: ((e: unknown) => void) | null);
|
|
348
|
+
set onmousedown(cb: ((e: unknown) => void) | null);
|
|
349
|
+
set onmouseup(cb: ((e: unknown) => void) | null);
|
|
350
|
+
set onmouseover(cb: ((e: unknown) => void) | null);
|
|
351
|
+
set onmousemove(cb: ((e: unknown) => void) | null);
|
|
352
|
+
set onkeydown(cb: ((e: unknown) => void) | null);
|
|
353
|
+
set onkeyup(cb: ((e: unknown) => void) | null);
|
|
354
|
+
set onkeypress(cb: ((e: unknown) => void) | null);
|
|
355
|
+
set onchange(cb: ((e: unknown) => void) | null);
|
|
356
|
+
set oncontextmenu(cb: ((e: unknown) => void) | null);
|
|
357
|
+
set oninput(cb: ((e: unknown) => void) | null);
|
|
358
|
+
set onfocus(cb: ((e: unknown) => void) | null);
|
|
359
|
+
set onblur(cb: ((e: unknown) => void) | null);
|
|
360
|
+
set onsubmit(cb: ((e: unknown) => void) | null);
|
|
361
|
+
get firstChild(): VirtualNode | null;
|
|
362
|
+
get lastChild(): VirtualNode | null;
|
|
363
|
+
get nextSibling(): VirtualNode | null;
|
|
364
|
+
get previousSibling(): VirtualNode | null;
|
|
365
|
+
get parentElement(): VirtualElement | null;
|
|
366
|
+
get ownerDocument(): VirtualDocument | null;
|
|
367
|
+
get isConnected(): boolean;
|
|
368
|
+
getRootNode(): VirtualNode;
|
|
369
|
+
get nextElementSibling(): VirtualElement | null;
|
|
370
|
+
get previousElementSibling(): VirtualElement | null;
|
|
371
|
+
hasChildNodes(): boolean;
|
|
372
|
+
replaceChild(newChild: VirtualNode, oldChild: VirtualNode): VirtualNode;
|
|
373
|
+
normalize(): void;
|
|
374
|
+
dispatchEvent(event: unknown): boolean;
|
|
375
|
+
cloneNode(deep?: boolean): VirtualElement;
|
|
376
|
+
get dataset(): Record<string, string | undefined>;
|
|
377
|
+
insertAdjacentHTML(position: InsertPosition, html: string): void;
|
|
378
|
+
contains(other: VirtualNode | null): boolean;
|
|
379
|
+
querySelector(selector: string): VirtualElement | null;
|
|
380
|
+
querySelectorAll(selector: string): VirtualElement[];
|
|
381
|
+
matches(selector: string): boolean;
|
|
382
|
+
getElementsByTagName(tagName: string): VirtualElement[];
|
|
383
|
+
getElementsByClassName(className: string): VirtualElement[];
|
|
384
|
+
closest(selector: string): VirtualElement | null;
|
|
385
|
+
focus(): void;
|
|
386
|
+
blur(): void;
|
|
387
|
+
play(): void;
|
|
388
|
+
pause(): void;
|
|
389
|
+
load(): void;
|
|
390
|
+
click(): void;
|
|
391
|
+
scrollIntoView(options?: unknown): void;
|
|
392
|
+
select(): void;
|
|
393
|
+
showModal(): void;
|
|
394
|
+
close(): void;
|
|
395
|
+
/**
|
|
396
|
+
* Synchronously query the main thread for this element's bounding rect via SyncChannel.
|
|
397
|
+
* Returns a zero rect if no sync channel is available.
|
|
398
|
+
*/
|
|
399
|
+
getBoundingClientRect(): {
|
|
400
|
+
top: number;
|
|
401
|
+
left: number;
|
|
402
|
+
right: number;
|
|
403
|
+
bottom: number;
|
|
404
|
+
width: number;
|
|
405
|
+
height: number;
|
|
406
|
+
x: number;
|
|
407
|
+
y: number;
|
|
408
|
+
};
|
|
409
|
+
/** Parse a CSS style string (e.g., "color: red; font-size: 14px") and set each property individually. */
|
|
410
|
+
private _parseAndSetStyles;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Virtual text node (nodeType 3). Setting nodeValue emits a setProperty mutation
|
|
414
|
+
* so the main thread updates the real text node.
|
|
415
|
+
*/
|
|
416
|
+
declare class VirtualTextNode {
|
|
417
|
+
readonly _nodeId: NodeId;
|
|
418
|
+
private collector;
|
|
419
|
+
static readonly ELEMENT_NODE = 1;
|
|
420
|
+
static readonly TEXT_NODE = 3;
|
|
421
|
+
static readonly COMMENT_NODE = 8;
|
|
422
|
+
static readonly DOCUMENT_NODE = 9;
|
|
423
|
+
static readonly DOCUMENT_FRAGMENT_NODE = 11;
|
|
424
|
+
readonly nodeType = 3;
|
|
425
|
+
readonly nodeName = "#text";
|
|
426
|
+
parentNode: VirtualElement | null;
|
|
427
|
+
_ownerDocument: VirtualDocument | null;
|
|
428
|
+
private _nodeValue;
|
|
429
|
+
constructor(text: string, _nodeId: NodeId, collector: MutationCollector);
|
|
430
|
+
get parentElement(): VirtualElement | null;
|
|
431
|
+
get nodeValue(): string;
|
|
432
|
+
set nodeValue(value: string);
|
|
433
|
+
get textContent(): string;
|
|
434
|
+
set textContent(value: string);
|
|
435
|
+
get nextSibling(): VirtualNode | null;
|
|
436
|
+
get previousSibling(): VirtualNode | null;
|
|
437
|
+
get childNodes(): VirtualNode[];
|
|
438
|
+
remove(): void;
|
|
439
|
+
cloneNode(_deep?: boolean): VirtualTextNode;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Virtual comment node (nodeType 8). Used primarily as DOM markers by frameworks.
|
|
443
|
+
* Comment nodes do not emit mutations on value changes.
|
|
444
|
+
*/
|
|
445
|
+
declare class VirtualCommentNode {
|
|
446
|
+
readonly _nodeId: NodeId;
|
|
447
|
+
private collector;
|
|
448
|
+
static readonly ELEMENT_NODE = 1;
|
|
449
|
+
static readonly TEXT_NODE = 3;
|
|
450
|
+
static readonly COMMENT_NODE = 8;
|
|
451
|
+
static readonly DOCUMENT_NODE = 9;
|
|
452
|
+
static readonly DOCUMENT_FRAGMENT_NODE = 11;
|
|
453
|
+
readonly nodeType = 8;
|
|
454
|
+
readonly nodeName = "#comment";
|
|
455
|
+
parentNode: VirtualElement | null;
|
|
456
|
+
_ownerDocument: VirtualDocument | null;
|
|
457
|
+
private _nodeValue;
|
|
458
|
+
constructor(text: string, _nodeId: NodeId, collector: MutationCollector);
|
|
459
|
+
get parentElement(): VirtualElement | null;
|
|
460
|
+
get nodeValue(): string;
|
|
461
|
+
set nodeValue(value: string);
|
|
462
|
+
get textContent(): string;
|
|
463
|
+
get nextSibling(): VirtualNode | null;
|
|
464
|
+
get previousSibling(): VirtualNode | null;
|
|
465
|
+
get childNodes(): VirtualNode[];
|
|
466
|
+
remove(): void;
|
|
467
|
+
cloneNode(_deep?: boolean): VirtualCommentNode;
|
|
468
|
+
}
|
|
469
|
+
/** DOMTokenList-compatible classList implementation that delegates to VirtualElement.className. */
|
|
470
|
+
declare class VirtualClassList {
|
|
471
|
+
private element;
|
|
472
|
+
constructor(element: VirtualElement);
|
|
473
|
+
add(...names: string[]): void;
|
|
474
|
+
remove(...names: string[]): void;
|
|
475
|
+
contains(name: string): boolean;
|
|
476
|
+
toggle(name: string, force?: boolean): boolean;
|
|
477
|
+
get length(): number;
|
|
478
|
+
}
|
|
479
|
+
//#endregion
|
|
480
|
+
//#region src/worker-thread/document.d.ts
|
|
481
|
+
/**
|
|
482
|
+
* Virtual Document that exists in a worker thread.
|
|
483
|
+
*
|
|
484
|
+
* Mirrors a subset of the browser's Document API, allowing framework code
|
|
485
|
+
* to call createElement, querySelector, addEventListener, etc. without
|
|
486
|
+
* touching the real DOM. Every mutating operation records a DomMutation via
|
|
487
|
+
* the MutationCollector, which batches and sends them to the main thread.
|
|
488
|
+
*
|
|
489
|
+
* Key subsystems:
|
|
490
|
+
* - Element creation: createElement, createTextNode, createComment
|
|
491
|
+
* - Event dispatch: routes serialized events from the main thread to the
|
|
492
|
+
* correct VirtualElement listener using O(1) listenerId lookup
|
|
493
|
+
* - ID registries: maintains both user-visible id attributes (_ids) and
|
|
494
|
+
* internal NodeId -> VirtualElement mappings (_nodeIdToElement)
|
|
495
|
+
* - Sync channel: optional SharedArrayBuffer channel for blocking DOM queries
|
|
496
|
+
*/
|
|
497
|
+
declare class VirtualDocument {
|
|
498
|
+
readonly body: VirtualElement;
|
|
499
|
+
readonly head: VirtualElement;
|
|
500
|
+
readonly documentElement: VirtualElement;
|
|
501
|
+
readonly nodeType = 9;
|
|
502
|
+
readonly nodeName = "#document";
|
|
503
|
+
/** Collects mutations and batches them for transport to the main thread. */
|
|
504
|
+
readonly collector: MutationCollector;
|
|
505
|
+
/** Reference to the VirtualWindow, providing location/navigator access. */
|
|
506
|
+
_defaultView: unknown;
|
|
507
|
+
/** Optional sync channel for blocking DOM queries (e.g., getBoundingClientRect). */
|
|
508
|
+
_syncChannel: SyncChannel | null;
|
|
509
|
+
private _title;
|
|
510
|
+
private _cookie;
|
|
511
|
+
/** Map of user-visible id attribute -> VirtualElement for getElementById. */
|
|
512
|
+
private _ids;
|
|
513
|
+
/** Map of internal NodeId -> VirtualElement for event target resolution. */
|
|
514
|
+
private _nodeIdToElement;
|
|
515
|
+
/** Document-level event listeners keyed by listenerId. */
|
|
516
|
+
private _listenerMap;
|
|
517
|
+
/** Map of listenerId -> owning VirtualElement for O(1) event dispatch routing. */
|
|
518
|
+
private _listenerToElement;
|
|
519
|
+
private _listenerCounter;
|
|
520
|
+
constructor(appId: AppId);
|
|
521
|
+
/**
|
|
522
|
+
* Create a new virtual element and emit a createNode mutation.
|
|
523
|
+
* The element is registered by NodeId for event target resolution.
|
|
524
|
+
*/
|
|
525
|
+
createElement(tag: string): VirtualElement;
|
|
526
|
+
/** Create a namespaced element (e.g., SVG). Delegates to createElement then sets the namespace. */
|
|
527
|
+
createElementNS(ns: string, tag: string): VirtualElement;
|
|
528
|
+
/** Create a virtual text node and emit a createNode mutation with tag "#text". */
|
|
529
|
+
createTextNode(text: string): VirtualTextNode;
|
|
530
|
+
/** Create a virtual comment node and emit a createComment mutation. */
|
|
531
|
+
createComment(text: string): VirtualCommentNode;
|
|
532
|
+
createDocumentFragment(): VirtualElement;
|
|
533
|
+
getElementById(id: string): VirtualElement | null;
|
|
534
|
+
/**
|
|
535
|
+
* Add a document-level event listener. The listener is stored locally and
|
|
536
|
+
* a mutation is emitted to tell the main thread to attach a real listener.
|
|
537
|
+
*/
|
|
538
|
+
addEventListener(name: string, callback: (e: unknown) => void): void;
|
|
539
|
+
/** Remove a document-level listener by callback reference. Emits a removeEventListener mutation. */
|
|
540
|
+
removeEventListener(_name: string, callback: (e: unknown) => void): void;
|
|
541
|
+
/**
|
|
542
|
+
* Route an event from the main thread to the appropriate listener.
|
|
543
|
+
* Resolves serialized target IDs to actual VirtualElement references.
|
|
544
|
+
*/
|
|
545
|
+
private _resolveTarget;
|
|
546
|
+
/**
|
|
547
|
+
* Route a serialized event from the main thread to the appropriate listener.
|
|
548
|
+
*
|
|
549
|
+
* Flow:
|
|
550
|
+
* 1. Resolve serialized target/currentTarget/relatedTarget IDs to VirtualElement refs
|
|
551
|
+
* 2. Wrap the event data in a VirtualEvent for bubbling support
|
|
552
|
+
* 3. Tag the MutationCollector with causal event info for causality tracking
|
|
553
|
+
* 4. Sync input/media state from the event to the target element
|
|
554
|
+
* 5. Dispatch to document-level listeners, or bubble through the element tree
|
|
555
|
+
*/
|
|
556
|
+
dispatchEvent(listenerId: string, event: unknown): void;
|
|
557
|
+
/** Feature 16: finish performance measurement for an event dispatch */
|
|
558
|
+
private _finishEventPerf;
|
|
559
|
+
/**
|
|
560
|
+
* Register an element by its internal NodeId.
|
|
561
|
+
*/
|
|
562
|
+
registerElement(id: NodeId, element: VirtualElement): void;
|
|
563
|
+
/**
|
|
564
|
+
* Unregister an element by its internal NodeId (called during cleanup on removal).
|
|
565
|
+
*/
|
|
566
|
+
unregisterElement(id: NodeId): void;
|
|
567
|
+
/**
|
|
568
|
+
* Register an element by its user-visible id attribute (distinct from internal NodeId).
|
|
569
|
+
*/
|
|
570
|
+
registerElementById(id: string, element: VirtualElement): void;
|
|
571
|
+
/**
|
|
572
|
+
* Unregister an element by its user-visible id attribute.
|
|
573
|
+
*/
|
|
574
|
+
unregisterElementById(id: string): void;
|
|
575
|
+
/**
|
|
576
|
+
* Register a listener ID to its owning element for O(1) event dispatch.
|
|
577
|
+
*/
|
|
578
|
+
registerListener(listenerId: string, element: VirtualElement): void;
|
|
579
|
+
/**
|
|
580
|
+
* Unregister a listener ID (called on removeEventListener or element cleanup).
|
|
581
|
+
*/
|
|
582
|
+
unregisterListener(listenerId: string): void;
|
|
583
|
+
/** Stub implementation of document.createEvent for legacy API compatibility. */
|
|
584
|
+
createEvent(_type: string): Record<string, unknown>;
|
|
585
|
+
get activeElement(): VirtualElement;
|
|
586
|
+
/** Stub implementation of document.createRange for framework compatibility. */
|
|
587
|
+
createRange(): unknown;
|
|
588
|
+
/** Simplified TreeWalker that pre-collects all descendant nodes for sequential traversal. */
|
|
589
|
+
createTreeWalker(root: VirtualElement, _whatToShow?: number): {
|
|
590
|
+
currentNode: VirtualNode;
|
|
591
|
+
nextNode(): VirtualNode | null;
|
|
592
|
+
};
|
|
593
|
+
querySelector(selector: string): VirtualElement | null;
|
|
594
|
+
querySelectorAll(selector: string): VirtualElement[];
|
|
595
|
+
getElementsByTagName(tagName: string): VirtualElement[];
|
|
596
|
+
getElementsByClassName(className: string): VirtualElement[];
|
|
597
|
+
get title(): string;
|
|
598
|
+
set title(value: string);
|
|
599
|
+
get URL(): string;
|
|
600
|
+
get location(): unknown;
|
|
601
|
+
get cookie(): string;
|
|
602
|
+
set cookie(value: string);
|
|
603
|
+
get readyState(): string;
|
|
604
|
+
get compatMode(): string;
|
|
605
|
+
get characterSet(): string;
|
|
606
|
+
get contentType(): string;
|
|
607
|
+
get visibilityState(): string;
|
|
608
|
+
get hidden(): boolean;
|
|
609
|
+
get childNodes(): VirtualNode[];
|
|
610
|
+
get children(): VirtualElement[];
|
|
611
|
+
get firstChild(): VirtualElement;
|
|
612
|
+
contains(node: unknown): boolean;
|
|
613
|
+
get implementation(): {
|
|
614
|
+
hasFeature(): boolean;
|
|
615
|
+
};
|
|
616
|
+
get defaultView(): unknown;
|
|
617
|
+
get ownerDocument(): VirtualDocument;
|
|
618
|
+
/**
|
|
619
|
+
* Clean up all internal state. Called when the worker DOM instance is being destroyed.
|
|
620
|
+
* Clears element registries, listener maps, and resets counters.
|
|
621
|
+
*/
|
|
622
|
+
destroy(): void;
|
|
623
|
+
/** Serialize the entire virtual DOM tree to a JSON-compatible structure for debugging. */
|
|
624
|
+
toJSON(): unknown;
|
|
625
|
+
private _serializeNode;
|
|
626
|
+
}
|
|
627
|
+
//# sourceMappingURL=document.d.ts.map
|
|
628
|
+
//#endregion
|
|
629
|
+
//#region src/worker-thread/events.d.ts
|
|
630
|
+
/**
|
|
631
|
+
* Virtual event classes that simulate DOM event behavior
|
|
632
|
+
* including bubbling, propagation control, and default prevention.
|
|
633
|
+
*/
|
|
634
|
+
declare class VirtualEvent {
|
|
635
|
+
readonly type: string;
|
|
636
|
+
target: unknown;
|
|
637
|
+
currentTarget: unknown;
|
|
638
|
+
readonly bubbles: boolean;
|
|
639
|
+
readonly cancelable: boolean;
|
|
640
|
+
defaultPrevented: boolean;
|
|
641
|
+
readonly timeStamp: number;
|
|
642
|
+
readonly isTrusted: boolean;
|
|
643
|
+
eventPhase: number;
|
|
644
|
+
private _stopPropagation;
|
|
645
|
+
private _stopImmediatePropagation;
|
|
646
|
+
constructor(type: string, init?: Record<string, unknown>);
|
|
647
|
+
preventDefault(): void;
|
|
648
|
+
stopPropagation(): void;
|
|
649
|
+
stopImmediatePropagation(): void;
|
|
650
|
+
get propagationStopped(): boolean;
|
|
651
|
+
get immediatePropagationStopped(): boolean;
|
|
652
|
+
}
|
|
653
|
+
declare class VirtualCustomEvent extends VirtualEvent {
|
|
654
|
+
readonly detail: unknown;
|
|
655
|
+
constructor(type: string, init?: Record<string, unknown>);
|
|
656
|
+
}
|
|
657
|
+
//# sourceMappingURL=events.d.ts.map
|
|
658
|
+
//#endregion
|
|
659
|
+
//#region src/worker-thread/observers.d.ts
|
|
660
|
+
/**
|
|
661
|
+
* Stub observer classes that prevent crashes when frameworks
|
|
662
|
+
* attempt to use browser observers in a worker context.
|
|
663
|
+
*/
|
|
664
|
+
declare class VirtualMutationObserver {
|
|
665
|
+
constructor(_callback: (mutations: unknown[], observer: unknown) => void);
|
|
666
|
+
observe(_target: unknown, _options?: unknown): void;
|
|
667
|
+
disconnect(): void;
|
|
668
|
+
takeRecords(): unknown[];
|
|
669
|
+
}
|
|
670
|
+
declare class VirtualResizeObserver {
|
|
671
|
+
constructor(_callback: (entries: unknown[], observer: unknown) => void);
|
|
672
|
+
observe(_target: unknown, _options?: unknown): void;
|
|
673
|
+
unobserve(_target: unknown): void;
|
|
674
|
+
disconnect(): void;
|
|
675
|
+
}
|
|
676
|
+
declare class VirtualIntersectionObserver {
|
|
677
|
+
readonly root: null;
|
|
678
|
+
readonly rootMargin = "0px";
|
|
679
|
+
readonly thresholds: readonly number[];
|
|
680
|
+
constructor(_callback: (entries: unknown[], observer: unknown) => void, _options?: unknown);
|
|
681
|
+
observe(_target: unknown): void;
|
|
682
|
+
unobserve(_target: unknown): void;
|
|
683
|
+
disconnect(): void;
|
|
684
|
+
takeRecords(): unknown[];
|
|
685
|
+
}
|
|
686
|
+
//# sourceMappingURL=observers.d.ts.map
|
|
687
|
+
//#endregion
|
|
688
|
+
//#region src/worker-thread/storage.d.ts
|
|
689
|
+
/**
|
|
690
|
+
* Scoped Storage implementation that can optionally sync with
|
|
691
|
+
* the main thread's real localStorage/sessionStorage via the sync channel.
|
|
692
|
+
*
|
|
693
|
+
* Each worker app gets its own isolated storage with a unique prefix.
|
|
694
|
+
* When a sync channel is available, reads/writes are persisted to the
|
|
695
|
+
* real browser storage on the main thread.
|
|
696
|
+
*/
|
|
697
|
+
declare class ScopedStorage {
|
|
698
|
+
private cache;
|
|
699
|
+
private prefix;
|
|
700
|
+
private storageType;
|
|
701
|
+
private getSyncChannel;
|
|
702
|
+
private queryType;
|
|
703
|
+
constructor(prefix: string, storageType: "localStorage" | "sessionStorage", getSyncChannel: () => SyncChannel | null, queryType: QueryType);
|
|
704
|
+
private syncCall;
|
|
705
|
+
get length(): number;
|
|
706
|
+
key(index: number): string | null;
|
|
707
|
+
getItem(key: string): string | null;
|
|
708
|
+
setItem(key: string, value: string): void;
|
|
709
|
+
removeItem(key: string): void;
|
|
710
|
+
clear(): void;
|
|
711
|
+
}
|
|
712
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
713
|
+
//#endregion
|
|
714
|
+
//#region src/worker-thread/index.d.ts
|
|
715
|
+
/**
|
|
716
|
+
* Configuration for {@link createWorkerDom}.
|
|
717
|
+
*
|
|
718
|
+
* All fields are optional — sensible defaults are chosen for standard
|
|
719
|
+
* Web Worker usage.
|
|
720
|
+
*/
|
|
721
|
+
interface WorkerDomConfig {
|
|
722
|
+
/** Explicit app ID. If omitted, a unique ID is generated automatically. */
|
|
723
|
+
appId?: AppId;
|
|
724
|
+
/** Custom transport to use instead of the default `WorkerSelfTransport`. */
|
|
725
|
+
transport?: Transport;
|
|
726
|
+
/** Debug logging options (same as the main-thread `DebugOptions`). */
|
|
727
|
+
debug?: DebugOptions;
|
|
728
|
+
/**
|
|
729
|
+
* Sandbox mode for the worker environment.
|
|
730
|
+
*
|
|
731
|
+
* - `"global"` — Patches `globalThis` so bare references to `document`, `window`, etc.
|
|
732
|
+
* resolve to the virtual DOM objects.
|
|
733
|
+
* - `"eval"` — Enables `window.eval()` with a sandboxed scope that uses the virtual DOM.
|
|
734
|
+
* - `true` — Enables both `"global"` and `"eval"` modes.
|
|
735
|
+
* - `false` (default) — No patching; access virtual DOM explicitly via the returned objects.
|
|
736
|
+
*/
|
|
737
|
+
sandbox?: boolean | "global" | "eval";
|
|
738
|
+
/** Custom platform host for non-browser environments (e.g. Node.js). Auto-detected if omitted. */
|
|
739
|
+
platform?: PlatformHost;
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* The result of calling {@link createWorkerDom}.
|
|
743
|
+
*
|
|
744
|
+
* Provides a virtual `document` and `window` that mirror the real DOM API.
|
|
745
|
+
* All mutations are automatically serialized and sent to the main thread.
|
|
746
|
+
*/
|
|
747
|
+
interface WorkerDomResult {
|
|
748
|
+
/** Virtual document implementing a subset of the DOM `Document` API. */
|
|
749
|
+
document: VirtualDocument;
|
|
750
|
+
/** Virtual window providing `location`, `history`, `screen`, timers, observers, and more. */
|
|
751
|
+
window: WorkerWindow;
|
|
752
|
+
/** Tear down the virtual DOM, cancel timers, and close the transport. */
|
|
753
|
+
destroy: () => void;
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* Virtual `window` object available inside a worker.
|
|
757
|
+
*
|
|
758
|
+
* Provides browser-like globals (`document`, `location`, `history`, `localStorage`,
|
|
759
|
+
* observers, timers, etc.) backed by the virtual DOM and sync-channel reads.
|
|
760
|
+
*/
|
|
761
|
+
interface WorkerWindow {
|
|
762
|
+
/** The virtual document for this worker app. */
|
|
763
|
+
document: VirtualDocument;
|
|
764
|
+
/** Emulated `window.location` that syncs navigation to the main thread. */
|
|
765
|
+
location: WorkerLocation;
|
|
766
|
+
/** Emulated `window.history` that syncs pushState/replaceState to the main thread. */
|
|
767
|
+
history: WorkerHistory;
|
|
768
|
+
/** Screen dimensions (resolved via sync channel when available, fallback 1280x720). */
|
|
769
|
+
screen: {
|
|
770
|
+
width: number;
|
|
771
|
+
height: number;
|
|
772
|
+
};
|
|
773
|
+
/** Viewport width (resolved via sync channel when available, fallback 1280). */
|
|
774
|
+
innerWidth: number;
|
|
775
|
+
/** Viewport height (resolved via sync channel when available, fallback 720). */
|
|
776
|
+
innerHeight: number;
|
|
777
|
+
/** App-scoped localStorage backed by sync channel reads to the real `localStorage`. */
|
|
778
|
+
localStorage: ScopedStorage;
|
|
779
|
+
/** App-scoped in-memory sessionStorage (tied to worker lifecycle). */
|
|
780
|
+
sessionStorage: ScopedStorage;
|
|
781
|
+
/** Add a document-level event listener. */
|
|
782
|
+
addEventListener(name: string, callback: (e: unknown) => void): void;
|
|
783
|
+
/** Remove a document-level event listener. */
|
|
784
|
+
removeEventListener(name: string, callback: (e: unknown) => void): void;
|
|
785
|
+
/** Scroll the main-thread viewport to the given coordinates. */
|
|
786
|
+
scrollTo(x: number, y: number): void;
|
|
787
|
+
/** Read computed style for a virtual element via the sync channel. */
|
|
788
|
+
getComputedStyle(el: unknown): Record<string, string>;
|
|
789
|
+
/** Polyfilled `requestAnimationFrame` using `setTimeout` (~16ms). */
|
|
790
|
+
requestAnimationFrame(cb: (time: number) => void): number;
|
|
791
|
+
/** Cancel a pending `requestAnimationFrame` callback. */
|
|
792
|
+
cancelAnimationFrame(id: number): void;
|
|
793
|
+
/** Virtual `MutationObserver` for observing virtual DOM mutations. */
|
|
794
|
+
MutationObserver: typeof VirtualMutationObserver;
|
|
795
|
+
/** Virtual `ResizeObserver` stub. */
|
|
796
|
+
ResizeObserver: typeof VirtualResizeObserver;
|
|
797
|
+
/** Virtual `IntersectionObserver` stub. */
|
|
798
|
+
IntersectionObserver: typeof VirtualIntersectionObserver;
|
|
799
|
+
setTimeout: typeof setTimeout;
|
|
800
|
+
setInterval: typeof setInterval;
|
|
801
|
+
clearTimeout: typeof clearTimeout;
|
|
802
|
+
clearInterval: typeof clearInterval;
|
|
803
|
+
queueMicrotask: typeof queueMicrotask;
|
|
804
|
+
performance: typeof performance;
|
|
805
|
+
fetch: typeof fetch | undefined;
|
|
806
|
+
URL: typeof URL;
|
|
807
|
+
URLSearchParams: typeof URLSearchParams;
|
|
808
|
+
console: typeof console;
|
|
809
|
+
btoa: typeof btoa;
|
|
810
|
+
atob: typeof atob;
|
|
811
|
+
navigator: PlatformHost["navigator"];
|
|
812
|
+
Event: typeof VirtualEvent;
|
|
813
|
+
CustomEvent: typeof VirtualCustomEvent;
|
|
814
|
+
/** Standard DOM node type constants. */
|
|
815
|
+
Node: {
|
|
816
|
+
ELEMENT_NODE: 1;
|
|
817
|
+
TEXT_NODE: 3;
|
|
818
|
+
COMMENT_NODE: 8;
|
|
819
|
+
DOCUMENT_NODE: 9;
|
|
820
|
+
DOCUMENT_FRAGMENT_NODE: 11;
|
|
821
|
+
};
|
|
822
|
+
HTMLElement: typeof VirtualElement;
|
|
823
|
+
devicePixelRatio: number;
|
|
824
|
+
/** Stub `matchMedia` that always returns `matches: false`. */
|
|
825
|
+
matchMedia: (query: string) => {
|
|
826
|
+
matches: boolean;
|
|
827
|
+
media: string;
|
|
828
|
+
addEventListener: () => void;
|
|
829
|
+
removeEventListener: () => void;
|
|
830
|
+
};
|
|
831
|
+
/** Stub `getSelection` that returns an empty selection. */
|
|
832
|
+
getSelection: () => {
|
|
833
|
+
rangeCount: number;
|
|
834
|
+
getRangeAt: () => null;
|
|
835
|
+
addRange: () => void;
|
|
836
|
+
removeAllRanges: () => void;
|
|
837
|
+
};
|
|
838
|
+
/** Dispatch an event on the virtual document. */
|
|
839
|
+
dispatchEvent: (event: unknown) => boolean;
|
|
840
|
+
/**
|
|
841
|
+
* Evaluate code in a sandboxed scope. Only available when `sandbox` includes `"eval"`.
|
|
842
|
+
* Throws if sandbox eval is not enabled.
|
|
843
|
+
*/
|
|
844
|
+
eval: (code: string) => unknown;
|
|
845
|
+
}
|
|
846
|
+
/** Emulated `Location` object synced from the main thread. Navigation calls generate mutations. */
|
|
847
|
+
interface WorkerLocation {
|
|
848
|
+
hash: string;
|
|
849
|
+
href: string;
|
|
850
|
+
port: string;
|
|
851
|
+
host: string;
|
|
852
|
+
origin: string;
|
|
853
|
+
hostname: string;
|
|
854
|
+
pathname: string;
|
|
855
|
+
protocol: string;
|
|
856
|
+
search: string;
|
|
857
|
+
toString(): string;
|
|
858
|
+
assign(url: string): void;
|
|
859
|
+
replace(url: string): void;
|
|
860
|
+
reload(): void;
|
|
861
|
+
}
|
|
862
|
+
/** Emulated `History` object. `pushState`/`replaceState` calls generate navigation mutations. */
|
|
863
|
+
interface WorkerHistory {
|
|
864
|
+
state: unknown;
|
|
865
|
+
pushState(state: unknown, title: string, url: string): void;
|
|
866
|
+
replaceState(state: unknown, title: string, url: string): void;
|
|
867
|
+
back(): void;
|
|
868
|
+
forward(): void;
|
|
869
|
+
go(delta?: number): void;
|
|
870
|
+
length: number;
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* Creates a virtual DOM environment inside a Web Worker.
|
|
874
|
+
*
|
|
875
|
+
* Returns a `document` and `window` that can be used by frameworks
|
|
876
|
+
* or vanilla JS. All DOM mutations are automatically collected and
|
|
877
|
+
* sent to the main thread for rendering.
|
|
878
|
+
*/
|
|
879
|
+
declare function createWorkerDom(config?: WorkerDomConfig): WorkerDomResult;
|
|
880
|
+
//#endregion
|
|
881
|
+
export { ScopedStorage as a, VirtualElement as c, MutationCollector as d, PlatformHost as f, detectPlatform as h, createWorkerDom as i, VirtualNode as l, createWorkerPlatform as m, WorkerDomResult as n, VirtualDocument as o, createNodePlatform as p, WorkerWindow as r, VirtualCommentNode as s, WorkerDomConfig as t, VirtualTextNode as u };
|
|
882
|
+
//# sourceMappingURL=index3.d.cts.map
|