very-happy-dom 0.0.7

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.
Files changed (36) hide show
  1. package/README.md +251 -0
  2. package/dist/apis/BrowserAPIs.d.ts +93 -0
  3. package/dist/apis/Clipboard.d.ts +24 -0
  4. package/dist/apis/FileAPI.d.ts +56 -0
  5. package/dist/browser/Browser.d.ts +23 -0
  6. package/dist/browser/BrowserContext.d.ts +21 -0
  7. package/dist/browser/BrowserFrame.d.ts +25 -0
  8. package/dist/browser/BrowserPage.d.ts +82 -0
  9. package/dist/browser/CookieContainer.d.ts +25 -0
  10. package/dist/events/CustomEvent.d.ts +14 -0
  11. package/dist/events/VirtualEvent.d.ts +16 -0
  12. package/dist/http/XMLHttpRequest.d.ts +66 -0
  13. package/dist/index.d.ts +45 -0
  14. package/dist/index.js +3792 -0
  15. package/dist/network/RequestInterceptor.d.ts +31 -0
  16. package/dist/network/WebSocket.d.ts +47 -0
  17. package/dist/nodes/VirtualCommentNode.d.ts +10 -0
  18. package/dist/nodes/VirtualDocument.d.ts +50 -0
  19. package/dist/nodes/VirtualElement.d.ts +43 -0
  20. package/dist/nodes/VirtualNode.d.ts +47 -0
  21. package/dist/nodes/VirtualTextNode.d.ts +10 -0
  22. package/dist/observers/IntersectionObserver.d.ts +49 -0
  23. package/dist/observers/MutationObserver.d.ts +37 -0
  24. package/dist/observers/ResizeObserver.d.ts +41 -0
  25. package/dist/parsers/html-parser.d.ts +5 -0
  26. package/dist/selectors/engine.d.ts +132 -0
  27. package/dist/storage/Storage.d.ts +14 -0
  28. package/dist/timers/TimerManager.d.ts +21 -0
  29. package/dist/webcomponents/CustomElementRegistry.d.ts +22 -0
  30. package/dist/webcomponents/ShadowRoot.d.ts +23 -0
  31. package/dist/window/DetachedWindowAPI.d.ts +19 -0
  32. package/dist/window/GlobalWindow.d.ts +15 -0
  33. package/dist/window/Window.d.ts +93 -0
  34. package/dist/xpath/XPathEvaluator.d.ts +16 -0
  35. package/dist/xpath/XPathResult.d.ts +32 -0
  36. package/package.json +55 -0
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Network Request Interception
3
+ * Allows intercepting, modifying, and mocking network requests
4
+ */
5
+ export declare interface InterceptedRequest {
6
+ url: string
7
+ method: string
8
+ headers: Record<string, string>
9
+ postData?: string | null
10
+ resourceType: string
11
+ continue: (overrides?: { url?: string, method?: string, headers?: Record<string, string>, postData?: string }) => void
12
+ abort: (errorCode?: string) => void
13
+ respond: (response: { status: number, headers?: Record<string, string>, body: string | ArrayBuffer }) => void
14
+ }
15
+ export declare interface RequestInterceptionHandler {
16
+ (request: InterceptedRequest): void | Promise<void>
17
+ }
18
+ /**
19
+ * Request Interceptor manages network request interception
20
+ */
21
+ export declare class RequestInterceptor {
22
+ private _enabled: any;
23
+ private _handlers: any;
24
+ private _originalFetch: typeof fetch;
25
+ constructor();
26
+ enable(): void;
27
+ disable(): void;
28
+ addHandler(handler: RequestInterceptionHandler): void;
29
+ removeHandler(handler: RequestInterceptionHandler): void;
30
+ clear(): void;
31
+ }
@@ -0,0 +1,47 @@
1
+ declare interface MessageEvent extends Event {
2
+ data: any
3
+ origin: string
4
+ lastEventId: string
5
+ source: any
6
+ ports: any[]
7
+ }
8
+ declare interface CloseEvent extends Event {
9
+ code: number
10
+ reason: string
11
+ wasClean: boolean
12
+ }
13
+ declare type EventListener = (event: Event | MessageEvent | CloseEvent) => void
14
+ export declare class VeryHappyWebSocket {
15
+ static readonly CONNECTING: number;
16
+ static readonly OPEN: number;
17
+ static readonly CLOSING: number;
18
+ static readonly CLOSED: number;
19
+ readyState: WebSocketReadyState;
20
+ url: string;
21
+ protocol: any;
22
+ extensions: any;
23
+ binaryType: 'blob' | 'arraybuffer';
24
+ bufferedAmount: any;
25
+ onopen: ((event: Event) => void) | null;
26
+ onmessage: ((event: MessageEvent) => void) | null;
27
+ onerror: ((event: Event) => void) | null;
28
+ onclose: ((event: CloseEvent) => void) | null;
29
+ private _ws: WebSocket | null;
30
+ private _eventListeners: any;
31
+ constructor(url: string, protocols?: string | string[]);
32
+ send(data: string | ArrayBuffer | Blob): void;
33
+ close(code?: number, reason?: string): void;
34
+ addEventListener(type: string, listener: EventListener): void;
35
+ removeEventListener(type: string, listener: EventListener): void;
36
+ dispatchEvent(event: Event | MessageEvent | CloseEvent): boolean;
37
+ }
38
+ /**
39
+ * WebSocket implementation
40
+ * Wraps Bun's native WebSocket for browser-like API
41
+ */
42
+ export declare enum WebSocketReadyState {
43
+ CONNECTING = 0,
44
+ OPEN = 1,
45
+ CLOSING = 2,
46
+ CLOSED = 3,
47
+ }
@@ -0,0 +1,10 @@
1
+ import type { NodeType, VirtualNode } from './VirtualNode';
2
+ export declare class VirtualCommentNode implements VirtualNode {
3
+ nodeType: NodeType;
4
+ nodeName: string;
5
+ nodeValue: string;
6
+ attributes: Map<string, string>;
7
+ children: VirtualNode[];
8
+ parentNode: VirtualNode | null;
9
+ constructor(text: string);
10
+ }
@@ -0,0 +1,50 @@
1
+ import { parseHTML } from '../parsers/html-parser';
2
+ import { VirtualCommentNode } from './VirtualCommentNode';
3
+ import { VirtualElement } from './VirtualElement';
4
+ import { VirtualTextNode } from './VirtualTextNode';
5
+ import { XPathResultType } from '../xpath/XPathResult';
6
+ import type { History, HistoryState, Location, NodeType, VirtualNode } from './VirtualNode';
7
+ import type { XPathResult } from '../xpath/XPathResult';
8
+ /**
9
+ * Factory function to create a new virtual document
10
+ */
11
+ export declare function createDocument(): VirtualDocument;
12
+ export declare class VirtualDocument implements VirtualNode {
13
+ nodeType: NodeType;
14
+ nodeName: string;
15
+ nodeValue: string | null;
16
+ attributes: Map<string, string>;
17
+ children: VirtualNode[];
18
+ parentNode: VirtualNode | null;
19
+ documentElement: VirtualElement | null;
20
+ head: VirtualElement | null;
21
+ body: VirtualElement | null;
22
+ location: Location;
23
+ history: History;
24
+ title: any;
25
+ private _historyStack: HistoryState[];
26
+ private _historyIndex: any;
27
+ private _eventListeners: any;
28
+ private _xpathEvaluator: any;
29
+ private _cookies: Record<string, string>;
30
+ constructor();
31
+ private _updateLocation(url: string): void;
32
+ appendChild(child: VirtualNode): VirtualNode;
33
+ createElement(tagName: string): VirtualElement;
34
+ createTextNode(text: string): VirtualTextNode;
35
+ createComment(text: string): VirtualCommentNode;
36
+ createDocumentFragment(): VirtualElement;
37
+ querySelector(selector: string): VirtualElement | null;
38
+ querySelectorAll(selector: string): VirtualElement[];
39
+ getElementById(id: string): VirtualElement | null;
40
+ getElementsByTagName(tagName: string): VirtualElement[];
41
+ getElementsByClassName(className: string): VirtualElement[];
42
+ parseHTML(html: string): void;
43
+ write(html: string): void;
44
+ getComputedStyle(element: VirtualElement): any;
45
+ addEventListener(type: string, listener: (event: any) => void): void;
46
+ removeEventListener(type: string, listener: (event: any) => void): void;
47
+ dispatchEvent(event: any): boolean;
48
+ evaluate(expression: string, contextNode?: VirtualNode, resolver?: any, type?: XPathResultType, result?: XPathResult | null): XPathResult;
49
+ createExpression(expression: string, resolver?: any): any;
50
+ }
@@ -0,0 +1,43 @@
1
+ import { ShadowRoot } from '../webcomponents/ShadowRoot';
2
+ import { VirtualEvent } from '../events/VirtualEvent';
3
+ import type { EventListener, EventListenerOptions, NodeType, VirtualNode } from './VirtualNode';
4
+ import type { ShadowRootInit } from '../webcomponents/ShadowRoot';
5
+ export declare class VirtualElement implements VirtualNode {
6
+ nodeType: NodeType;
7
+ nodeName: string;
8
+ nodeValue: string | null;
9
+ tagName: string;
10
+ attributes: Map<string, string>;
11
+ childNodes: VirtualNode[];
12
+ parentNode: VirtualNode | null;
13
+ shadowRoot: ShadowRoot | null;
14
+ private eventListeners: Map<string, EventListener[]>;
15
+ private _customValidity: string;
16
+ private _internalStyles: Map<string, string>;
17
+ constructor(tagName: string);
18
+ getAttribute(name: string): string | null;
19
+ setAttribute(name: string, value: string): void;
20
+ removeAttribute(name: string): void;
21
+ hasAttribute(name: string): boolean;
22
+ appendChild(child: VirtualNode): VirtualNode;
23
+ removeChild(child: VirtualNode): VirtualNode;
24
+ insertBefore(newNode: VirtualNode, referenceNode: VirtualNode | null): VirtualNode;
25
+ replaceChild(newNode: VirtualNode, oldNode: VirtualNode): VirtualNode;
26
+ cloneNode(deep?: any): VirtualElement;
27
+ closest(selector: string): VirtualElement | null;
28
+ private _serializeNode(node: VirtualNode): string;
29
+ private _updateStyleAttribute(): void;
30
+ setCustomValidity(message: string): void;
31
+ checkValidity(): boolean;
32
+ reportValidity(): boolean;
33
+ querySelector(selector: string): VirtualElement | null;
34
+ querySelectorAll(selector: string): VirtualElement[];
35
+ matches(selector: string): boolean;
36
+ addEventListener(type: string, listener: (event: VirtualEvent) => void, options?: EventListenerOptions | boolean): void;
37
+ removeEventListener(type: string, listener: (event: VirtualEvent) => void, options?: EventListenerOptions | boolean): void;
38
+ dispatchEvent(event: any): boolean;
39
+ private _invokeEventListeners(element: VirtualElement, event: VirtualEvent, capture: boolean): void;
40
+ click(): void;
41
+ isVisible(): boolean;
42
+ attachShadow(init: ShadowRootInit): ShadowRoot;
43
+ }
@@ -0,0 +1,47 @@
1
+ export declare interface VirtualNode {
2
+ nodeType: NodeType
3
+ nodeName: string
4
+ nodeValue: string | null
5
+ attributes: Map<string, string>
6
+ children: VirtualNode[]
7
+ parentNode: VirtualNode | null
8
+ textContent: string
9
+ }
10
+ export declare interface EventListenerOptions {
11
+ capture?: boolean
12
+ once?: boolean
13
+ passive?: boolean
14
+ }
15
+ export declare interface EventListener {
16
+ listener: (event: any) => void
17
+ options: EventListenerOptions
18
+ }
19
+ export declare interface Location {
20
+ href: string
21
+ protocol: string
22
+ host: string
23
+ hostname: string
24
+ port: string
25
+ pathname: string
26
+ search: string
27
+ hash: string
28
+ origin: string
29
+ assign: (url: string) => void
30
+ replace: (url: string) => void
31
+ reload: () => void
32
+ }
33
+ export declare interface HistoryState {
34
+ state: any
35
+ title: string
36
+ url: string
37
+ }
38
+ export declare interface History {
39
+ length: number
40
+ state: any
41
+ pushState: (state: any, title: string, url?: string) => void
42
+ replaceState: (state: any, title: string, url?: string) => void
43
+ back: () => void
44
+ forward: () => void
45
+ go: (delta: number) => void
46
+ }
47
+ export type NodeType = 'element' | 'text' | 'comment' | 'document'
@@ -0,0 +1,10 @@
1
+ import type { NodeType, VirtualNode } from './VirtualNode';
2
+ export declare class VirtualTextNode implements VirtualNode {
3
+ nodeType: NodeType;
4
+ nodeName: string;
5
+ nodeValue: string;
6
+ attributes: Map<string, string>;
7
+ children: VirtualNode[];
8
+ parentNode: VirtualNode | null;
9
+ constructor(text: string);
10
+ }
@@ -0,0 +1,49 @@
1
+ import type { VirtualElement } from '../nodes/VirtualElement';
2
+ export declare interface IntersectionObserverInit {
3
+ root?: VirtualElement | null
4
+ rootMargin?: string
5
+ threshold?: number | number[]
6
+ }
7
+ export declare interface IntersectionObserverEntry {
8
+ boundingClientRect: DOMRectReadOnly
9
+ intersectionRatio: number
10
+ intersectionRect: DOMRectReadOnly
11
+ isIntersecting: boolean
12
+ rootBounds: DOMRectReadOnly | null
13
+ target: VirtualElement
14
+ time: number
15
+ }
16
+ declare interface DOMRectReadOnly {
17
+ x: number
18
+ y: number
19
+ width: number
20
+ height: number
21
+ top: number
22
+ right: number
23
+ bottom: number
24
+ left: number
25
+ }
26
+ export type IntersectionObserverCallback = (
27
+ entries: IntersectionObserverEntry[],
28
+ observer: IntersectionObserver
29
+ ) => void
30
+ /**
31
+ * IntersectionObserver implementation
32
+ * Note: This is a simplified implementation for testing
33
+ * It simulates intersection behavior without actual viewport calculations
34
+ */
35
+ export declare class IntersectionObserver {
36
+ root: VirtualElement | null;
37
+ rootMargin: string;
38
+ thresholds: number[];
39
+ private _callback: IntersectionObserverCallback;
40
+ private _observedElements: any;
41
+ constructor(callback: IntersectionObserverCallback, options?: IntersectionObserverInit);
42
+ observe(target: VirtualElement): void;
43
+ unobserve(target: VirtualElement): void;
44
+ disconnect(): void;
45
+ takeRecords(): IntersectionObserverEntry[];
46
+ private _createEntry(target: VirtualElement, isIntersecting: boolean): IntersectionObserverEntry;
47
+ private _getBoundingClientRect(_element: VirtualElement): DOMRectReadOnly;
48
+ private _createEmptyRect(): DOMRectReadOnly;
49
+ }
@@ -0,0 +1,37 @@
1
+ import type { VirtualNode } from '../nodes/VirtualNode';
2
+ export declare interface MutationObserverInit {
3
+ childList?: boolean
4
+ attributes?: boolean
5
+ characterData?: boolean
6
+ subtree?: boolean
7
+ attributeOldValue?: boolean
8
+ characterDataOldValue?: boolean
9
+ attributeFilter?: string[]
10
+ }
11
+ export declare interface MutationRecord {
12
+ type: 'childList' | 'attributes' | 'characterData'
13
+ target: VirtualNode
14
+ addedNodes: VirtualNode[]
15
+ removedNodes: VirtualNode[]
16
+ previousSibling: VirtualNode | null
17
+ nextSibling: VirtualNode | null
18
+ attributeName: string | null
19
+ attributeNamespace: string | null
20
+ oldValue: string | null
21
+ }
22
+ export type MutationCallback = (mutations: MutationRecord[], observer: MutationObserver) => void
23
+ /**
24
+ * MutationObserver implementation
25
+ * Note: This is a simplified implementation for testing
26
+ * It doesn't actually observe live changes, but provides the API
27
+ */
28
+ export declare class MutationObserver {
29
+ private _callback: MutationCallback;
30
+ private _records: MutationRecord[];
31
+ private _observing: any;
32
+ constructor(callback: MutationCallback);
33
+ observe(_target: VirtualNode, _options?: MutationObserverInit): void;
34
+ disconnect(): void;
35
+ takeRecords(): MutationRecord[];
36
+ _addRecord(record: MutationRecord): void;
37
+ }
@@ -0,0 +1,41 @@
1
+ import type { VirtualElement } from '../nodes/VirtualElement';
2
+ export declare interface ResizeObserverSize {
3
+ inlineSize: number
4
+ blockSize: number
5
+ }
6
+ export declare interface ResizeObserverEntry {
7
+ target: VirtualElement
8
+ contentRect: DOMRectReadOnly
9
+ borderBoxSize: ReadonlyArray<ResizeObserverSize>
10
+ contentBoxSize: ReadonlyArray<ResizeObserverSize>
11
+ devicePixelContentBoxSize: ReadonlyArray<ResizeObserverSize>
12
+ }
13
+ declare interface DOMRectReadOnly {
14
+ x: number
15
+ y: number
16
+ width: number
17
+ height: number
18
+ top: number
19
+ right: number
20
+ bottom: number
21
+ left: number
22
+ }
23
+ export type ResizeObserverCallback = (
24
+ entries: ResizeObserverEntry[],
25
+ observer: ResizeObserver
26
+ ) => void
27
+ /**
28
+ * ResizeObserver implementation
29
+ * Note: This is a simplified implementation for testing
30
+ * It simulates resize behavior without actual size calculations
31
+ */
32
+ export declare class ResizeObserver {
33
+ private _callback: ResizeObserverCallback;
34
+ private _observedElements: any;
35
+ constructor(callback: ResizeObserverCallback);
36
+ observe(target: VirtualElement, _options?: { box?: 'content-box' | 'border-box' | 'device-pixel-content-box' }): void;
37
+ unobserve(target: VirtualElement): void;
38
+ disconnect(): void;
39
+ private _createEntry(target: VirtualElement): ResizeObserverEntry;
40
+ private _getContentRect(_element: VirtualElement): DOMRectReadOnly;
41
+ }
@@ -0,0 +1,5 @@
1
+ import type { VirtualNode } from '../nodes/VirtualNode';
2
+ /**
3
+ * Parse HTML string into virtual DOM nodes
4
+ */
5
+ export declare function parseHTML(html: string): VirtualNode[];
@@ -0,0 +1,132 @@
1
+ import type { VirtualElement } from '../nodes/VirtualElement';
2
+ import type { VirtualNode } from '../nodes/VirtualNode';
3
+ /**
4
+ * Finds the first element matching the CSS selector starting from the given root node.
5
+ *
6
+ * @param root - The root node to search from (inclusive)
7
+ * @param selector - CSS selector string (supports tags, classes, IDs, attributes, pseudo-classes, and combinators)
8
+ * @returns The first matching VirtualElement, or null if no match is found
9
+ * @throws {Error} If selector syntax is invalid
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const element = querySelectorEngine(document, 'div.container > p#intro')
14
+ * ```
15
+ */
16
+ export declare function querySelectorEngine(root: VirtualNode, selector: string): VirtualElement | null;
17
+ /**
18
+ * Finds all elements matching the CSS selector starting from the given root node.
19
+ * Traverses the DOM tree depth-first and returns matching elements in document order.
20
+ *
21
+ * @param root - The root node to search from (inclusive)
22
+ * @param selector - CSS selector string supporting:
23
+ * - Tag selectors: `div`, `span`
24
+ * - Class selectors: `.class-name`
25
+ * - ID selectors: `#element-id`
26
+ * - Attribute selectors: `[attr]`, `[attr="value"]`, `[attr^="value"]`, `[attr$="value"]`, `[attr*="value"]`, `[attr~="word"]`
27
+ * - Pseudo-classes: `:first-child`, `:last-child`, `:first-of-type`, `:last-of-type`, `:only-child`, `:only-of-type`, `:nth-child()`, `:nth-last-child()`, `:nth-of-type()`, `:nth-last-of-type()`, `:not()`, `:disabled`, `:enabled`, `:checked`, `:empty`
28
+ * - Combinators: ` ` (descendant), `>` (child), `+` (adjacent sibling), `~` (general sibling)
29
+ * @returns Array of all matching VirtualElements in document order
30
+ * @throws {Error} If selector syntax is invalid
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const buttons = querySelectorAllEngine(document, 'button[type="submit"]:not(:disabled)')
35
+ * ```
36
+ */
37
+ export declare function querySelectorAllEngine(root: VirtualNode, selector: string): VirtualElement[];
38
+ /**
39
+ * Checks if a CSS selector contains any combinators (>, +, ~, or space).
40
+ * This helps optimize selector matching by using simpler logic for simple selectors.
41
+ *
42
+ * @param selector - CSS selector string to analyze
43
+ * @returns True if the selector contains any combinator characters
44
+ * @internal
45
+ */
46
+ export declare function hasCombinators(selector: string): boolean;
47
+ /**
48
+ * Tests if an element matches a complex selector containing combinators.
49
+ * Uses right-to-left matching (starting from the element itself) for efficiency.
50
+ *
51
+ * @param element - The element to test
52
+ * @param selector - Complex CSS selector with combinators
53
+ * @param root - Root node to limit ancestor traversal
54
+ * @returns True if the element matches the complex selector
55
+ * @internal
56
+ */
57
+ export declare function matchesComplexSelector(element: VirtualElement, selector: string, root: VirtualNode): boolean;
58
+ /**
59
+ * Parses a complex CSS selector into individual selector parts and their combinators.
60
+ * Handles nested pseudo-classes and attribute selectors correctly.
61
+ *
62
+ * @param selector - Complex CSS selector to parse
63
+ * @returns Array of selector parts with their following combinators
64
+ * @internal
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * parseComplexSelector('div > p.intro')
69
+ * // Returns: [{ selector: 'div', combinator: '>' }, { selector: 'p.intro', combinator: null }]
70
+ * ```
71
+ */
72
+ export declare function parseComplexSelector(selector: string): Array<{ selector: string, combinator: string | null }>;
73
+ /**
74
+ * Tests if an element matches a simple selector (without combinators).
75
+ * Supports tag names, IDs, classes, attributes, and pseudo-classes.
76
+ *
77
+ * @param element - The element to test
78
+ * @param selector - Simple CSS selector (no combinators)
79
+ * @returns True if the element matches all parts of the selector
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * matchesSimpleSelector(element, 'button.primary[disabled]')
84
+ * ```
85
+ */
86
+ export declare function matchesSimpleSelector(element: VirtualElement, selector: string): boolean;
87
+ /**
88
+ * Tests if an element matches a pseudo-class selector.
89
+ *
90
+ * Supported pseudo-classes:
91
+ * - `:first-child` - First element child of parent
92
+ * - `:last-child` - Last element child of parent
93
+ * - `:first-of-type` - First element of its type among siblings
94
+ * - `:last-of-type` - Last element of its type among siblings
95
+ * - `:only-child` - Only element child of parent
96
+ * - `:only-of-type` - Only element of its type among siblings
97
+ * - `:nth-child(n)` - Nth element child (supports 'odd', 'even', numbers, and An+B notation like '2n+1')
98
+ * - `:nth-last-child(n)` - Nth element child from the end
99
+ * - `:nth-of-type(n)` - Nth element of its type (supports An+B notation)
100
+ * - `:nth-last-of-type(n)` - Nth element of its type from the end
101
+ * - `:not(selector)` - Elements that don't match the selector
102
+ * - `:disabled` - Elements with disabled attribute
103
+ * - `:enabled` - Elements without disabled attribute
104
+ * - `:checked` - Elements with checked attribute
105
+ * - `:empty` - Elements with no children
106
+ *
107
+ * @param element - The element to test
108
+ * @param pseudo - Pseudo-class selector (e.g., ':first-child', ':nth-child(2n+1)')
109
+ * @returns True if the element matches the pseudo-class
110
+ */
111
+ export declare function matchesPseudoClass(element: VirtualElement, pseudo: string): boolean;
112
+ /**
113
+ * Tests if an element matches an attribute selector.
114
+ *
115
+ * Supported attribute selectors:
116
+ * - `[attr]` - Has attribute
117
+ * - `[attr="value"]` - Exact match
118
+ * - `[attr^="value"]` - Starts with
119
+ * - `[attr$="value"]` - Ends with
120
+ * - `[attr*="value"]` - Contains substring
121
+ * - `[attr~="word"]` - Contains word (space-separated)
122
+ *
123
+ * @param element - The element to test
124
+ * @param attrSelector - Attribute selector content (without the brackets)
125
+ * @returns True if the element's attribute matches the selector
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * matchesAttributeSelector(element, 'href^="https"') // Tests [href^="https"]
130
+ * ```
131
+ */
132
+ export declare function matchesAttributeSelector(element: VirtualElement, attrSelector: string): boolean;
@@ -0,0 +1,14 @@
1
+ // Create Proxy to support bracket notation
2
+ export declare function createStorage(): Storage;
3
+ /**
4
+ * Storage implementation for localStorage and sessionStorage
5
+ * Compatible with Web Storage API
6
+ */
7
+ export declare class Storage {
8
+ private _data: Map<string, string>;
9
+ key(index: number): string | null;
10
+ getItem(key: string): string | null;
11
+ setItem(key: string, value: string): void;
12
+ removeItem(key: string): void;
13
+ clear(): void;
14
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * TimerManager handles setTimeout, setInterval, and requestAnimationFrame
3
+ * Tracks pending timers for waitUntilComplete() integration
4
+ */
5
+ export declare class TimerManager {
6
+ private _timeouts: any;
7
+ private _intervals: any;
8
+ private _animationFrames: any;
9
+ private _nextId: any;
10
+ private _aborted: any;
11
+ setTimeout(callback: (...args: any[]) => void, delay?: number, args: any[]): number;
12
+ clearTimeout(id: number): void;
13
+ setInterval(callback: (...args: any[]) => void, delay?: number, args: any[]): number;
14
+ clearInterval(id: number): void;
15
+ requestAnimationFrame(callback: (time: number) => void): number;
16
+ cancelAnimationFrame(id: number): void;
17
+ hasPendingTimers(): boolean;
18
+ waitForTimers(): Promise<void>;
19
+ clearAll(): void;
20
+ abort(): void;
21
+ }
@@ -0,0 +1,22 @@
1
+ import { VirtualElement } from '../nodes/VirtualElement';
2
+ export declare interface CustomElementConstructor {
3
+ new (): HTMLElement
4
+ }
5
+ declare interface ElementDefinitionOptions {
6
+ extends?: string
7
+ }
8
+ export declare class CustomElementRegistry {
9
+ private _definitions: any;
10
+ private _whenDefinedPromises: any;
11
+ define(name: string, constructor: CustomElementConstructor, _options?: ElementDefinitionOptions): void;
12
+ get(name: string): CustomElementConstructor | undefined;
13
+ whenDefined(name: string): Promise<CustomElementConstructor>;
14
+ upgrade(_root: Node): void;
15
+ }
16
+ // Simplified HTMLElement for custom elements
17
+ export declare class HTMLElement extends VirtualElement {
18
+ connectedCallback(): void;
19
+ disconnectedCallback(): void;
20
+ attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
21
+ adoptedCallback(): void;
22
+ }
@@ -0,0 +1,23 @@
1
+ import type { VirtualElement } from '../nodes/VirtualElement';
2
+ import type { VirtualNode } from '../nodes/VirtualNode';
3
+ export declare interface ShadowRootInit {
4
+ mode: ShadowRootMode
5
+ delegatesFocus?: boolean
6
+ }
7
+ export type ShadowRootMode = 'open' | 'closed'
8
+ /**
9
+ * ShadowRoot represents a shadow DOM tree
10
+ */
11
+ export declare class ShadowRoot {
12
+ mode: ShadowRootMode;
13
+ delegatesFocus: boolean;
14
+ host: VirtualElement;
15
+ innerHTML: any;
16
+ children: VirtualNode[];
17
+ constructor(host: VirtualElement, init: ShadowRootInit);
18
+ querySelector(selector: string): VirtualElement | null;
19
+ querySelectorAll(selector: string): VirtualElement[];
20
+ appendChild(child: VirtualNode): VirtualNode;
21
+ removeChild(child: VirtualNode): VirtualNode;
22
+ getElementById(id: string): VirtualElement | null;
23
+ }
@@ -0,0 +1,19 @@
1
+ import type { Window } from './Window';
2
+ /**
3
+ * DetachedWindowAPI provides an API for communicating with a detached Window
4
+ * A Window is considered detached when created directly (e.g. new Window())
5
+ * instead of through the Browser API
6
+ */
7
+ export declare class DetachedWindowAPI {
8
+ private _window: Window;
9
+ private _pendingOperations: Set<Promise<any>>;
10
+ private _aborted: any;
11
+ constructor(window: Window);
12
+ close(): Promise<void>;
13
+ waitUntilComplete(): Promise<void>;
14
+ abort(): Promise<void>;
15
+ setURL(url: string): void;
16
+ setViewport(options: { width?: number, height?: number }): void;
17
+ _trackOperation(operation: Promise<any>): void;
18
+ _isAborted(): boolean;
19
+ }
@@ -0,0 +1,15 @@
1
+ import { Window } from './Window';
2
+ import type { WindowOptions } from './Window';
3
+ /**
4
+ * GlobalWindow represents a window instance running in the global scope
5
+ * instead of an isolated VM context
6
+ *
7
+ * This is useful for setting up a test environment in its own Node process
8
+ * Compatible with Happy DOM's GlobalWindow API
9
+ */
10
+ export declare class GlobalWindow extends Window {
11
+ constructor(options?: WindowOptions);
12
+ setGlobal(key: string, value: any): void;
13
+ getGlobal(key: string): any;
14
+ close(): Promise<void>;
15
+ }