-
Notifications
You must be signed in to change notification settings - Fork 42
/
api.ts
96 lines (84 loc) · 2.65 KB
/
api.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
export { nodesFromString } from "./deserialize.ts";
export * from "./dom/node.ts";
export * from "./dom/element.ts";
export * from "./dom/document.ts";
export * from "./dom/document-fragment.ts";
export * from "./dom/dom-parser.ts";
export * from "./dom/elements/html-template-element.ts";
export { disableCodeGeneration as denoDomDisableQuerySelectorCodeGeneration } from "./dom/selectors/selectors.ts";
// Re-export private constructors without constructor signature
import {
CharacterData as ConstructibleCharacterData,
Node as ConstructibleNode,
} from "./dom/node.ts";
import { HTMLDocument as ConstructibleHTMLDocument } from "./dom/document.ts";
import {
Attr as ConstructibleAttr,
Element as ConstructibleElement,
} from "./dom/element.ts";
export const Node:
& Pick<
typeof ConstructibleNode,
keyof typeof ConstructibleNode
>
& Function = ConstructibleNode;
export type Node = ConstructibleNode;
export const HTMLDocument:
& Pick<
typeof ConstructibleHTMLDocument,
keyof typeof ConstructibleHTMLDocument
>
& Function = ConstructibleHTMLDocument;
export type HTMLDocument = ConstructibleHTMLDocument;
export const CharacterData:
& Pick<
typeof ConstructibleCharacterData,
keyof typeof ConstructibleCharacterData
>
& Function = ConstructibleCharacterData;
export type CharacterData = ConstructibleCharacterData;
export const Element:
& Pick<
typeof ConstructibleElement,
keyof typeof ConstructibleElement
>
& Function = ConstructibleElement;
export type Element = ConstructibleElement;
export const Attr:
& Pick<
typeof ConstructibleAttr,
keyof typeof ConstructibleAttr
>
& Function = ConstructibleAttr;
export type Attr = ConstructibleAttr;
export { NodeListPublic as NodeList } from "./dom/node-list.ts";
export { HTMLCollectionPublic as HTMLCollection } from "./dom/html-collection.ts";
import { NodeList } from "./dom/node-list.ts";
import { HTMLCollection } from "./dom/html-collection.ts";
// Prevent childNodes and HTMLCollections from being seen as an arrays
const oldHasInstance = Array[Symbol.hasInstance];
Object.defineProperty(Array, Symbol.hasInstance, {
value(value: any): boolean {
switch (value?.constructor) {
case HTMLCollection:
case NodeList:
return false;
default:
return oldHasInstance.call(this, value);
}
},
configurable: true,
});
const oldIsArray = Array.isArray;
Object.defineProperty(Array, "isArray", {
value: (value: any): boolean => {
switch (value?.constructor) {
case HTMLCollection:
case NodeList:
return false;
default:
return oldIsArray.call(Array, value);
}
},
configurable: true,
});