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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
import * as _ from './utils'
export class Element extends Node {
constructor() {
super()
if (_.INTERNALS.has(new.target)) {
const internals = _.internalsOf(new.target, 'Element', 'localName')
_.INTERNALS.set(this, {
attributes: {},
localName: (internals as unknown as Element).localName,
ownerDocument: this.ownerDocument,
shadowInit: null as unknown as ShadowRootInit,
shadowRoot: null as unknown as ShadowRoot,
} as ElementInternals)
}
}
hasAttribute(name: string): boolean {
void name
return false
}
getAttribute(name: string): string | null {
return null
}
setAttribute(name: string, value: string): void {
void name
void value
}
removeAttribute(name: string): void {
void name
}
attachShadow(init: Partial<ShadowRootInit>) {
if (arguments.length < 1)
throw new TypeError(
`Failed to execute 'attachShadow' on 'Element': 1 argument required, but only 0 present.`
)
if (init !== Object(init))
throw new TypeError(
`Failed to execute 'attachShadow' on 'Element': The provided value is not of type 'ShadowRootInit'.`
)
if (init.mode !== 'open' && init.mode !== 'closed')
throw new TypeError(
`Failed to execute 'attachShadow' on 'Element': Failed to read the 'mode' property from 'ShadowRootInit': The provided value '${init.mode}' is not a valid enum value of type ShadowRootMode.`
)
const internals = _.internalsOf<ElementInternals>(
this,
'Element',
'attachShadow'
)
if (internals.shadowRoot) throw new Error('The operation is not supported.')
internals.shadowInit = internals.shadowInit || {
mode: init.mode,
delegatesFocus: Boolean(init.delegatesFocus),
}
internals.shadowRoot =
internals.shadowRoot ||
(/^open$/.test(internals.shadowInit.mode as string)
? (Object.setPrototypeOf(
new EventTarget(),
ShadowRoot.prototype
) as ShadowRoot)
: null)
return internals.shadowRoot
}
get assignedSlot(): HTMLSlotElement | null {
return null
}
get innerHTML(): string {
_.internalsOf<ElementInternals>(this, 'Element', 'innerHTML')
return ''
}
set innerHTML(value) {
_.internalsOf<ElementInternals>(this, 'Element', 'innerHTML')
void value
}
get shadowRoot(): ShadowRoot | null {
const internals = _.internalsOf<ElementInternals>(
this,
'Element',
'shadowRoot'
)
return Object(internals.shadowInit).mode === 'open'
? internals.shadowRoot
: null
}
get localName(): string {
return _.internalsOf<ElementInternals>(this, 'Element', 'localName')
.localName as string
}
get nodeName(): string {
return (
_.internalsOf<ElementInternals>(this, 'Element', 'nodeName')
.localName as string
).toUpperCase()
}
get tagName(): string {
return (
_.internalsOf<ElementInternals>(this, 'Element', 'tagName')
.localName as string
).toUpperCase()
}
}
export class HTMLElement extends Element {}
export class HTMLBodyElement extends HTMLElement {}
export class HTMLDivElement extends HTMLElement {}
export class HTMLHeadElement extends HTMLElement {}
export class HTMLHtmlElement extends HTMLElement {}
export class HTMLSpanElement extends HTMLElement {}
export class HTMLStyleElement extends HTMLElement {}
export class HTMLTemplateElement extends HTMLElement {}
export class HTMLUnknownElement extends HTMLElement {}
_.allowStringTag(Element)
_.allowStringTag(HTMLElement)
_.allowStringTag(HTMLBodyElement)
_.allowStringTag(HTMLDivElement)
_.allowStringTag(HTMLHeadElement)
_.allowStringTag(HTMLHtmlElement)
_.allowStringTag(HTMLSpanElement)
_.allowStringTag(HTMLStyleElement)
_.allowStringTag(HTMLTemplateElement)
_.allowStringTag(HTMLUnknownElement)
export interface ElementInternals {
attributes: { [name: string]: string }
localName?: string
shadowRoot: ShadowRoot | null
shadowInit: ShadowRootInit | void
}
export interface ShadowRootInit {
mode: 'open' | 'closed'
delegatesFocus: boolean
}
|