happy-dom 2.49.2 → 2.51.1

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.

Potentially problematic release.


This version of happy-dom might be problematic. Click here for more details.

Files changed (140) hide show
  1. package/.eslintrc.js +7 -6
  2. package/.prettierrc.js +2 -1
  3. package/lib/async-task-manager/AsyncTaskManager.d.ts +65 -0
  4. package/lib/{window → async-task-manager}/AsyncTaskManager.js +52 -55
  5. package/lib/async-task-manager/AsyncTaskManager.js.map +1 -0
  6. package/lib/cookie/CookieUtility.js +1 -4
  7. package/lib/cookie/CookieUtility.js.map +1 -1
  8. package/lib/custom-element/CustomElementRegistry.js.map +1 -1
  9. package/lib/dom-token-list/DOMTokenList.d.ts +0 -4
  10. package/lib/dom-token-list/DOMTokenList.js +0 -4
  11. package/lib/dom-token-list/DOMTokenList.js.map +1 -1
  12. package/lib/fetch/FetchHandler.d.ts +17 -0
  13. package/lib/fetch/FetchHandler.js +59 -0
  14. package/lib/fetch/FetchHandler.js.map +1 -0
  15. package/lib/fetch/Headers.d.ts +7 -0
  16. package/lib/fetch/Headers.js +53 -0
  17. package/lib/fetch/Headers.js.map +1 -0
  18. package/lib/fetch/IAbortSignal.d.ts +16 -0
  19. package/lib/fetch/IAbortSignal.js +4 -0
  20. package/lib/fetch/IAbortSignal.js.map +1 -0
  21. package/lib/fetch/IBody.d.ts +17 -0
  22. package/lib/{window/IFetchOptions.js → fetch/IBody.js} +1 -1
  23. package/lib/fetch/IBody.js.map +1 -0
  24. package/lib/fetch/IHeaders.d.ts +18 -0
  25. package/lib/fetch/IHeaders.js +3 -0
  26. package/lib/fetch/IHeaders.js.map +1 -0
  27. package/lib/fetch/IHeadersInit.d.ts +5 -0
  28. package/lib/fetch/IHeadersInit.js +3 -0
  29. package/lib/fetch/IHeadersInit.js.map +1 -0
  30. package/lib/fetch/IRequest.d.ts +18 -0
  31. package/lib/fetch/IRequest.js +3 -0
  32. package/lib/fetch/IRequest.js.map +1 -0
  33. package/lib/fetch/IRequestInit.d.ts +15 -0
  34. package/lib/fetch/IRequestInit.js +3 -0
  35. package/lib/fetch/IRequestInit.js.map +1 -0
  36. package/lib/fetch/IResponse.d.ts +20 -0
  37. package/lib/{window → fetch}/IResponse.js +0 -0
  38. package/lib/{window → fetch}/IResponse.js.map +1 -1
  39. package/lib/fetch/IResponseInit.d.ts +9 -0
  40. package/lib/fetch/IResponseInit.js +3 -0
  41. package/lib/fetch/IResponseInit.js.map +1 -0
  42. package/lib/fetch/Request.d.ts +69 -0
  43. package/lib/fetch/Request.js +179 -0
  44. package/lib/fetch/Request.js.map +1 -0
  45. package/lib/fetch/ResourceFetchHandler.d.ts +22 -0
  46. package/lib/fetch/{ResourceFetcher.js → ResourceFetchHandler.js} +19 -26
  47. package/lib/fetch/ResourceFetchHandler.js.map +1 -0
  48. package/lib/fetch/Response.d.ts +69 -0
  49. package/lib/fetch/Response.js +179 -0
  50. package/lib/fetch/Response.js.map +1 -0
  51. package/lib/file/Blob.d.ts +8 -1
  52. package/lib/file/Blob.js +48 -0
  53. package/lib/file/Blob.js.map +1 -1
  54. package/lib/file/IBlob.d.ts +10 -0
  55. package/lib/file/IBlob.js +3 -0
  56. package/lib/file/IBlob.js.map +1 -0
  57. package/lib/form-data/IFormData.d.ts +30 -0
  58. package/lib/form-data/IFormData.js +3 -0
  59. package/lib/form-data/IFormData.js.map +1 -0
  60. package/lib/index.d.ts +3 -5
  61. package/lib/index.js +3 -3
  62. package/lib/index.js.map +1 -1
  63. package/lib/location/URL.d.ts +10 -10
  64. package/lib/location/URL.js +34 -34
  65. package/lib/location/URL.js.map +1 -1
  66. package/lib/mutation-observer/MutationObserver.js.map +1 -1
  67. package/lib/nodes/character-data/CharacterData.d.ts +12 -12
  68. package/lib/nodes/character-data/CharacterData.js +24 -24
  69. package/lib/nodes/character-data/CharacterData.js.map +1 -1
  70. package/lib/nodes/document/Document.d.ts +8 -9
  71. package/lib/nodes/document/Document.js +18 -8
  72. package/lib/nodes/document/Document.js.map +1 -1
  73. package/lib/nodes/document/DocumentReadyStateManager.js.map +1 -1
  74. package/lib/nodes/html-input-element/HTMLInputElementValueSanitizer.js.map +1 -1
  75. package/lib/nodes/html-link-element/HTMLLinkElement.js +3 -3
  76. package/lib/nodes/html-link-element/HTMLLinkElement.js.map +1 -1
  77. package/lib/nodes/html-script-element/ScriptUtility.js +3 -9
  78. package/lib/nodes/html-script-element/ScriptUtility.js.map +1 -1
  79. package/lib/query-selector/SelectorItem.d.ts +8 -1
  80. package/lib/query-selector/SelectorItem.js +8 -1
  81. package/lib/query-selector/SelectorItem.js.map +1 -1
  82. package/lib/window/IWindow.d.ts +20 -16
  83. package/lib/window/Window.d.ts +59 -12
  84. package/lib/window/Window.js +117 -70
  85. package/lib/window/Window.js.map +1 -1
  86. package/lib/xml-parser/XMLParser.js +1 -4
  87. package/lib/xml-parser/XMLParser.js.map +1 -1
  88. package/package.json +22 -21
  89. package/src/async-task-manager/AsyncTaskManager.ts +128 -0
  90. package/src/cookie/CookieUtility.ts +1 -4
  91. package/src/custom-element/CustomElementRegistry.ts +1 -1
  92. package/src/dom-token-list/DOMTokenList.ts +0 -4
  93. package/src/fetch/FetchHandler.ts +54 -0
  94. package/src/fetch/Headers.ts +7 -0
  95. package/src/fetch/IAbortSignal.ts +34 -0
  96. package/src/fetch/IBody.ts +18 -0
  97. package/src/fetch/IHeaders.ts +18 -0
  98. package/src/fetch/IHeadersInit.ts +5 -0
  99. package/src/fetch/IRequest.ts +59 -0
  100. package/src/fetch/IRequestInit.ts +41 -0
  101. package/src/fetch/IResponse.ts +22 -0
  102. package/src/fetch/IResponseInit.ts +10 -0
  103. package/src/fetch/Request.ts +149 -0
  104. package/src/fetch/ResourceFetchHandler.ts +47 -0
  105. package/src/fetch/Response.ts +149 -0
  106. package/src/file/Blob.ts +12 -1
  107. package/src/file/IBlob.ts +10 -0
  108. package/src/form-data/IFormData.ts +33 -0
  109. package/src/index.ts +2 -6
  110. package/src/location/URL.ts +39 -38
  111. package/src/mutation-observer/MutationObserver.ts +1 -1
  112. package/src/nodes/character-data/CharacterData.ts +18 -17
  113. package/src/nodes/document/Document.ts +24 -9
  114. package/src/nodes/document/DocumentReadyStateManager.ts +1 -1
  115. package/src/nodes/html-input-element/HTMLInputElementValueSanitizer.ts +1 -1
  116. package/src/nodes/html-link-element/HTMLLinkElement.ts +7 -7
  117. package/src/nodes/html-script-element/ScriptUtility.ts +3 -9
  118. package/src/query-selector/SelectorItem.ts +12 -4
  119. package/src/window/IWindow.ts +14 -16
  120. package/src/window/Window.ts +103 -70
  121. package/src/xml-parser/XMLParser.ts +1 -4
  122. package/lib/fetch/ResourceFetcher.d.ts +0 -30
  123. package/lib/fetch/ResourceFetcher.js.map +0 -1
  124. package/lib/url-search-params/URLSearchParams.d.ts +0 -87
  125. package/lib/url-search-params/URLSearchParams.js +0 -196
  126. package/lib/url-search-params/URLSearchParams.js.map +0 -1
  127. package/lib/window/AsyncTaskManager.d.ts +0 -54
  128. package/lib/window/AsyncTaskManager.js.map +0 -1
  129. package/lib/window/AsyncTaskTypeEnum.d.ts +0 -5
  130. package/lib/window/AsyncTaskTypeEnum.js +0 -9
  131. package/lib/window/AsyncTaskTypeEnum.js.map +0 -1
  132. package/lib/window/IFetchOptions.d.ts +0 -13
  133. package/lib/window/IFetchOptions.js.map +0 -1
  134. package/lib/window/IResponse.d.ts +0 -32
  135. package/src/fetch/ResourceFetcher.ts +0 -55
  136. package/src/url-search-params/URLSearchParams.ts +0 -198
  137. package/src/window/AsyncTaskManager.ts +0 -127
  138. package/src/window/AsyncTaskTypeEnum.ts +0 -5
  139. package/src/window/IFetchOptions.ts +0 -11
  140. package/src/window/IResponse.ts +0 -34
@@ -0,0 +1,149 @@
1
+ import IResponse from './IResponse';
2
+ import IBlob from '../file/IBlob';
3
+ import IDocument from '../nodes/document/IDocument';
4
+ import * as NodeFetch from 'node-fetch';
5
+
6
+ /**
7
+ * Fetch response.
8
+ */
9
+ export default class Response extends NodeFetch.Response implements IResponse {
10
+ public static _ownerDocument: IDocument = null;
11
+
12
+ /**
13
+ * Returns array buffer.
14
+ *
15
+ * @returns Array buffer.
16
+ */
17
+ public arrayBuffer(): Promise<ArrayBuffer> {
18
+ return new Promise((resolve, reject) => {
19
+ const taskID = this._handlePromiseStart();
20
+ super
21
+ .arrayBuffer()
22
+ .then(this._handlePromiseEnd.bind(this, resolve, reject, taskID))
23
+ .catch(this._handlePromiseError.bind(this, reject));
24
+ });
25
+ }
26
+
27
+ /**
28
+ * Returns blob.
29
+ *
30
+ * @returns Blob.
31
+ */
32
+ public blob(): Promise<IBlob> {
33
+ return new Promise((resolve, reject) => {
34
+ const taskID = this._handlePromiseStart();
35
+ super
36
+ .blob()
37
+ .then(this._handlePromiseEnd.bind(this, resolve, reject, taskID))
38
+ .catch(this._handlePromiseError.bind(this, reject));
39
+ });
40
+ }
41
+
42
+ /**
43
+ * Returns buffer.
44
+ *
45
+ * @returns Buffer.
46
+ */
47
+ public buffer(): Promise<Buffer> {
48
+ return new Promise((resolve, reject) => {
49
+ const taskID = this._handlePromiseStart();
50
+ super
51
+ .buffer()
52
+ .then(this._handlePromiseEnd.bind(this, resolve, reject, taskID))
53
+ .catch(this._handlePromiseError.bind(this, reject));
54
+ });
55
+ }
56
+
57
+ /**
58
+ * Returns json.
59
+ *
60
+ * @returns JSON.
61
+ */
62
+ public json(): Promise<unknown> {
63
+ return new Promise((resolve, reject) => {
64
+ const taskID = this._handlePromiseStart();
65
+ super
66
+ .json()
67
+ .then(this._handlePromiseEnd.bind(this, resolve, reject, taskID))
68
+ .catch(this._handlePromiseError.bind(this, reject));
69
+ });
70
+ }
71
+
72
+ /**
73
+ * Returns json.
74
+ *
75
+ * @returns JSON.
76
+ */
77
+ public text(): Promise<string> {
78
+ return new Promise((resolve, reject) => {
79
+ const taskID = this._handlePromiseStart();
80
+ super
81
+ .text()
82
+ .then(this._handlePromiseEnd.bind(this, resolve, reject, taskID))
83
+ .catch(this._handlePromiseError.bind(this, reject));
84
+ });
85
+ }
86
+
87
+ /**
88
+ * Returns json.
89
+ *
90
+ * @returns JSON.
91
+ */
92
+ public textConverted(): Promise<string> {
93
+ return new Promise((resolve, reject) => {
94
+ const taskID = this._handlePromiseStart();
95
+ super
96
+ .textConverted()
97
+ .then(this._handlePromiseEnd.bind(this, resolve, reject, taskID))
98
+ .catch(this._handlePromiseError.bind(this, reject));
99
+ });
100
+ }
101
+
102
+ /**
103
+ * Handles promise start.
104
+ *
105
+ * @returns Task ID.
106
+ */
107
+ private _handlePromiseStart(): number {
108
+ const taskManager = (<typeof Response>this.constructor)._ownerDocument.defaultView.happyDOM
109
+ .asyncTaskManager;
110
+ return taskManager.startTask();
111
+ }
112
+
113
+ /**
114
+ * Handles promise end.
115
+ *
116
+ * @param resolve Resolve.
117
+ * @param reject Reject.
118
+ * @param taskID Task ID.
119
+ * @param response Response.
120
+ */
121
+ private _handlePromiseEnd(
122
+ resolve: (response: unknown) => void,
123
+ reject: (error: Error) => void,
124
+ taskID: number,
125
+ response: unknown
126
+ ): void {
127
+ const taskManager = (<typeof Response>this.constructor)._ownerDocument.defaultView.happyDOM
128
+ .asyncTaskManager;
129
+ if (taskManager.getTaskCount() === 0) {
130
+ reject(new Error('Failed to complete fetch request. Task was canceled.'));
131
+ } else {
132
+ resolve(response);
133
+ taskManager.endTask(taskID);
134
+ }
135
+ }
136
+
137
+ /**
138
+ * Handles promise error.
139
+ *
140
+ * @param error
141
+ * @param reject
142
+ */
143
+ private _handlePromiseError(reject: (error: Error) => void, error: Error): void {
144
+ const taskManager = (<typeof Response>this.constructor)._ownerDocument.defaultView.happyDOM
145
+ .asyncTaskManager;
146
+ reject(error);
147
+ taskManager.cancelAll(error);
148
+ }
149
+ }
package/src/file/Blob.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import IBlob from './IBlob';
2
+
1
3
  /**
2
4
  * Reference:
3
5
  * https://developer.mozilla.org/en-US/docs/Web/API/Blob.
@@ -5,7 +7,7 @@
5
7
  * Based on:
6
8
  * https://github.com/jsdom/jsdom/blob/master/lib/jsdom/living/file-api/Blob-impl.js (MIT licensed).
7
9
  */
8
- export default class Blob {
10
+ export default class Blob implements IBlob {
9
11
  public readonly _buffer: Buffer = null;
10
12
  public readonly type: string = '';
11
13
 
@@ -108,6 +110,15 @@ export default class Blob {
108
110
  return blob;
109
111
  }
110
112
 
113
+ /**
114
+ * Returns a Promise that resolves to a text.
115
+ *
116
+ * @returns Text.
117
+ */
118
+ public async text(): Promise<string> {
119
+ return this._buffer.toString();
120
+ }
121
+
111
122
  /**
112
123
  * Closes the blob.
113
124
  *
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Reference:
3
+ * https://developer.mozilla.org/en-US/docs/Web/API/Blob.
4
+ */
5
+ export default interface IBlob {
6
+ readonly type: string;
7
+ readonly size: number;
8
+ slice(start?: number, end?: number): IBlob;
9
+ text(): Promise<string>;
10
+ }
@@ -0,0 +1,33 @@
1
+ import Stream from 'stream';
2
+ import HTTP from 'http';
3
+
4
+ interface IHeaders {
5
+ [key: string]: unknown;
6
+ }
7
+
8
+ interface IAppendOptions {
9
+ header?: string | IHeaders;
10
+ knownLength?: number;
11
+ filename?: string;
12
+ filepath?: string;
13
+ contentType?: string;
14
+ }
15
+
16
+ interface ISubmitOptions extends HTTP.RequestOptions {
17
+ protocol?: 'https:' | 'http:';
18
+ }
19
+
20
+ export default interface IFormData extends Stream.Readable {
21
+ append(key: string, value: unknown, options?: IAppendOptions | string): void;
22
+ getHeaders(userHeaders?: IHeaders): { [key: string]: IHeaders };
23
+ submit(
24
+ params: string | ISubmitOptions,
25
+ callback?: (error: Error | null, response: HTTP.IncomingMessage) => void
26
+ ): HTTP.ClientRequest;
27
+ getBuffer(): Buffer;
28
+ setBoundary(boundary: string): void;
29
+ getBoundary(): string;
30
+ getLength(callback: (err: Error | null, length: number) => void): void;
31
+ getLengthSync(): number;
32
+ hasKnownLength(): boolean;
33
+ }
package/src/index.ts CHANGED
@@ -14,9 +14,7 @@ import DOMException from './exception/DOMException';
14
14
  import History from './history/History';
15
15
  import CSSStyleDeclaration from './css/CSSStyleDeclaration';
16
16
  import Screen from './screen/Screen';
17
- import AsyncTaskManager from './window/AsyncTaskManager';
18
- import IResponse from './window/IResponse';
19
- import IFetchOptions from './window/IFetchOptions';
17
+ import AsyncTaskManager from './async-task-manager/AsyncTaskManager';
20
18
  import NodeFilter from './tree-walker/NodeFilter';
21
19
  import Event from './event/Event';
22
20
  import EventTarget from './event/EventTarget';
@@ -101,7 +99,7 @@ import XMLParser from './xml-parser/XMLParser';
101
99
  import XMLSerializer from './xml-serializer/XMLSerializer';
102
100
  import CSSStyleSheet from './css/CSSStyleSheet';
103
101
  import Storage from './storage/Storage';
104
- import URLSearchParams from './url-search-params/URLSearchParams';
102
+ import { URLSearchParams } from 'url';
105
103
  import Selection from './selection/Selection';
106
104
 
107
105
  export {
@@ -123,8 +121,6 @@ export {
123
121
  CSSStyleDeclaration,
124
122
  Screen,
125
123
  AsyncTaskManager,
126
- IResponse,
127
- IFetchOptions,
128
124
  NodeFilter,
129
125
  Event,
130
126
  EventTarget,
@@ -1,4 +1,5 @@
1
- const URL_REGEXP = /(https?:)\/\/([-a-zA-Z0-9@:%._\+~#=]{2,256}[a-z]{2,6})(:[0-9]*)?([-a-zA-Z0-9@:%_\+.~c&//=]*)(\?[^#]*)?(#.*)?/;
1
+ const URL_REGEXP =
2
+ /(https?:)\/\/([-a-zA-Z0-9@:%._\+~#=]{2,256}[a-z]{2,6})(:[0-9]*)?([-a-zA-Z0-9@:%_\+.~c&//=]*)(\?[^#]*)?(#.*)?/;
2
3
  const PATH_REGEXP = /([-a-zA-Z0-9@:%_\+.~c&//=]*)(\?[^#]*)?(#.*)?/;
3
4
 
4
5
  /**
@@ -25,43 +26,6 @@ export default class URL {
25
26
  }
26
27
  }
27
28
 
28
- /**
29
- * Returns the entire URL as a string.
30
- */
31
- public toString(): string {
32
- return this.href;
33
- }
34
-
35
- /**
36
- * Parses an URL.
37
- *
38
- * @param url URL.
39
- */
40
- protected parse(url: string): void {
41
- const match = url.match(URL_REGEXP);
42
-
43
- if (match) {
44
- const hostnamePart = match[2] ? match[2].split('@') : '';
45
- const credentialsPart = hostnamePart.length > 1 ? hostnamePart[0].split(':') : null;
46
-
47
- this.protocol = match[1] || '';
48
- this.hostname = hostnamePart.length > 1 ? hostnamePart[1] : hostnamePart[0];
49
- this.port = match[3] || '';
50
- this.pathname = match[4] || '';
51
- this.search = match[5] || '';
52
- this.hash = match[6] || '';
53
- this.username = credentialsPart ? credentialsPart[0] : '';
54
- this.password = credentialsPart ? credentialsPart[1] : '';
55
- } else {
56
- const pathMatch = url.match(PATH_REGEXP);
57
- if (pathMatch) {
58
- this.pathname = pathMatch[1] || '';
59
- this.search = pathMatch[2] || '';
60
- this.hash = pathMatch[3] || '';
61
- }
62
- }
63
- }
64
-
65
29
  /**
66
30
  * Returns the entire URL as a string.
67
31
  *
@@ -98,4 +62,41 @@ export default class URL {
98
62
  public get host(): string {
99
63
  return this.hostname + this.port;
100
64
  }
65
+
66
+ /**
67
+ * Returns the entire URL as a string.
68
+ */
69
+ public toString(): string {
70
+ return this.href;
71
+ }
72
+
73
+ /**
74
+ * Parses an URL.
75
+ *
76
+ * @param url URL.
77
+ */
78
+ protected parse(url: string): void {
79
+ const match = url.match(URL_REGEXP);
80
+
81
+ if (match) {
82
+ const hostnamePart = match[2] ? match[2].split('@') : '';
83
+ const credentialsPart = hostnamePart.length > 1 ? hostnamePart[0].split(':') : null;
84
+
85
+ this.protocol = match[1] || '';
86
+ this.hostname = hostnamePart.length > 1 ? hostnamePart[1] : hostnamePart[0];
87
+ this.port = match[3] || '';
88
+ this.pathname = match[4] || '';
89
+ this.search = match[5] || '';
90
+ this.hash = match[6] || '';
91
+ this.username = credentialsPart ? credentialsPart[0] : '';
92
+ this.password = credentialsPart ? credentialsPart[1] : '';
93
+ } else {
94
+ const pathMatch = url.match(PATH_REGEXP);
95
+ if (pathMatch) {
96
+ this.pathname = pathMatch[1] || '';
97
+ this.search = pathMatch[2] || '';
98
+ this.hash = pathMatch[3] || '';
99
+ }
100
+ }
101
+ }
101
102
  }
@@ -39,7 +39,7 @@ export default class MutationObserver {
39
39
 
40
40
  options = Object.assign({}, options, {
41
41
  attributeFilter: options.attributeFilter
42
- ? options.attributeFilter.map(name => name.toLowerCase())
42
+ ? options.attributeFilter.map((name) => name.toLowerCase())
43
43
  : null
44
44
  });
45
45
 
@@ -106,6 +106,24 @@ export default abstract class CharacterData extends Node implements ICharacterDa
106
106
  this.textContent = nodeValue;
107
107
  }
108
108
 
109
+ /**
110
+ * Previous element sibling.
111
+ *
112
+ * @returns Element.
113
+ */
114
+ public get previousElementSibling(): IElement {
115
+ return NonDocumentChildNodeUtility.previousElementSibling(this);
116
+ }
117
+
118
+ /**
119
+ * Next element sibling.
120
+ *
121
+ * @returns Element.
122
+ */
123
+ public get nextElementSibling(): IElement {
124
+ return NonDocumentChildNodeUtility.nextElementSibling(this);
125
+ }
126
+
109
127
  /**
110
128
  * Appends the given DOMString to the CharacterData.data string; when this method returns, data contains the concatenated DOMString.
111
129
  *
@@ -155,23 +173,6 @@ export default abstract class CharacterData extends Node implements ICharacterDa
155
173
  public substringData(offset: number, count: number): string {
156
174
  return CharacterDataUtility.substringData(this, offset, count);
157
175
  }
158
- /**
159
- * Previous element sibling.
160
- *
161
- * @returns Element.
162
- */
163
- public get previousElementSibling(): IElement {
164
- return NonDocumentChildNodeUtility.previousElementSibling(this);
165
- }
166
-
167
- /**
168
- * Next element sibling.
169
- *
170
- * @returns Element.
171
- */
172
- public get nextElementSibling(): IElement {
173
- return NonDocumentChildNodeUtility.nextElementSibling(this);
174
- }
175
176
 
176
177
  /**
177
178
  * Removes the object from its parent children list.
@@ -37,6 +37,7 @@ import DocumentReadyStateEnum from './DocumentReadyStateEnum';
37
37
  import DocumentReadyStateManager from './DocumentReadyStateManager';
38
38
  import Location from '../../location/Location';
39
39
  import Selection from '../../selection/Selection';
40
+ import IShadowRoot from '../shadow-root/IShadowRoot';
40
41
 
41
42
  /**
42
43
  * Document.
@@ -240,6 +241,17 @@ export default class Document extends Node implements IDocument {
240
241
  * @returns Active element.
241
242
  */
242
243
  public get activeElement(): IHTMLElement {
244
+ if (this._activeElement) {
245
+ let rootNode: IShadowRoot | IDocument = <IShadowRoot | IDocument>(
246
+ this._activeElement.getRootNode()
247
+ );
248
+ let activeElement: IHTMLElement = this._activeElement;
249
+ while (rootNode !== this) {
250
+ activeElement = <IHTMLElement>(<IShadowRoot>rootNode).host;
251
+ rootNode = <IShadowRoot | IDocument>activeElement.getRootNode();
252
+ }
253
+ return activeElement;
254
+ }
243
255
  return this._activeElement || this.body || this.documentElement || null;
244
256
  }
245
257
 
@@ -590,32 +602,33 @@ export default class Document extends Node implements IDocument {
590
602
  */
591
603
  public close(): void {}
592
604
 
605
+ /* eslint-disable jsdoc/valid-types */
606
+
593
607
  /**
594
608
  * Creates an element.
595
609
  *
596
- * @param tagName Tag name.
610
+ * @param qualifiedName Tag name.
597
611
  * @param [options] Options.
598
- * @param options.is
612
+ * @param [options.is] Tag name of a custom element previously defined via customElements.define().
599
613
  * @returns Element.
600
614
  */
601
- public createElement(tagName: string, options?: { is: string }): IElement {
602
- return this.createElementNS(NamespaceURI.html, tagName, options);
615
+ public createElement(qualifiedName: string, options?: { is?: string }): IElement {
616
+ return this.createElementNS(NamespaceURI.html, qualifiedName, options);
603
617
  }
604
618
 
605
619
  /**
606
620
  * Creates an element with the specified namespace URI and qualified name.
607
621
  *
608
- * @param tagName Tag name.
622
+ * @param namespaceURI Namespace URI.
623
+ * @param qualifiedName Tag name.
609
624
  * @param [options] Options.
610
- * @param namespaceURI
611
- * @param qualifiedName
612
- * @param options.is
625
+ * @param [options.is] Tag name of a custom element previously defined via customElements.define().
613
626
  * @returns Element.
614
627
  */
615
628
  public createElementNS(
616
629
  namespaceURI: string,
617
630
  qualifiedName: string,
618
- options?: { is: string }
631
+ options?: { is?: string }
619
632
  ): IElement {
620
633
  const tagName = qualifiedName.toUpperCase();
621
634
 
@@ -638,6 +651,8 @@ export default class Document extends Node implements IDocument {
638
651
  return element;
639
652
  }
640
653
 
654
+ /* eslint-enable jsdoc/valid-types */
655
+
641
656
  /**
642
657
  * Creates a text node.
643
658
  *
@@ -25,7 +25,7 @@ export default class DocumentReadyStateManager {
25
25
  * @returns Promise.
26
26
  */
27
27
  public whenComplete(): Promise<void> {
28
- return new Promise(resolve => {
28
+ return new Promise((resolve) => {
29
29
  if (this.isComplete) {
30
30
  resolve();
31
31
  } else {
@@ -28,7 +28,7 @@ export default class HTMLInputElementValueSanitizer {
28
28
  if (input.multiple) {
29
29
  return value
30
30
  .split(',')
31
- .map(token => token.trim())
31
+ .map((token) => token.trim())
32
32
  .join(',');
33
33
  }
34
34
  return value.trim().replace(NEW_LINES_REGEXP, '');
@@ -1,6 +1,6 @@
1
1
  import Attr from '../../attribute/Attr';
2
2
  import CSSStyleSheet from '../../css/CSSStyleSheet';
3
- import ResourceFetcher from '../../fetch/ResourceFetcher';
3
+ import ResourceFetchHandler from '../../fetch/ResourceFetchHandler';
4
4
  import HTMLElement from '../html-element/HTMLElement';
5
5
  import Document from '../document/Document';
6
6
  import IHTMLLinkElement from './IHTMLLinkElement';
@@ -199,15 +199,15 @@ export default class HTMLLinkElement extends HTMLElement implements IHTMLLinkEle
199
199
  this.isConnected
200
200
  ) {
201
201
  (<Document>this.ownerDocument)._readyStateManager.startTask();
202
- ResourceFetcher.fetch({ window: this.ownerDocument.defaultView, url: href })
203
- .then(code => {
202
+ ResourceFetchHandler.fetch(this.ownerDocument, href)
203
+ .then((code) => {
204
204
  const styleSheet = new CSSStyleSheet();
205
205
  styleSheet.replaceSync(code);
206
206
  (<CSSStyleSheet>this.sheet) = styleSheet;
207
207
  this.dispatchEvent(new Event('load'));
208
208
  (<Document>this.ownerDocument)._readyStateManager.endTask();
209
209
  })
210
- .catch(error => {
210
+ .catch((error) => {
211
211
  this.dispatchEvent(
212
212
  new ErrorEvent('error', {
213
213
  message: error.message,
@@ -245,15 +245,15 @@ export default class HTMLLinkElement extends HTMLElement implements IHTMLLinkEle
245
245
 
246
246
  if (href !== null && rel && rel.toLowerCase() === 'stylesheet') {
247
247
  (<Document>this.ownerDocument)._readyStateManager.startTask();
248
- ResourceFetcher.fetch({ window: this.ownerDocument.defaultView, url: href })
249
- .then(code => {
248
+ ResourceFetchHandler.fetch(this.ownerDocument, href)
249
+ .then((code) => {
250
250
  const styleSheet = new CSSStyleSheet();
251
251
  styleSheet.replaceSync(code);
252
252
  (<CSSStyleSheet>this.sheet) = styleSheet;
253
253
  this.dispatchEvent(new Event('load'));
254
254
  (<Document>this.ownerDocument)._readyStateManager.endTask();
255
255
  })
256
- .catch(error => {
256
+ .catch((error) => {
257
257
  this.dispatchEvent(
258
258
  new ErrorEvent('error', {
259
259
  message: error.message,
@@ -1,7 +1,7 @@
1
1
  import { Document } from '../..';
2
2
  import Event from '../../event/Event';
3
3
  import ErrorEvent from '../../event/events/ErrorEvent';
4
- import ResourceFetcher from '../../fetch/ResourceFetcher';
4
+ import ResourceFetchHandler from '../../fetch/ResourceFetchHandler';
5
5
  import HTMLScriptElement from './HTMLScriptElement';
6
6
 
7
7
  /**
@@ -22,10 +22,7 @@ export default class ScriptUtility {
22
22
  let code = null;
23
23
  (<Document>element.ownerDocument)._readyStateManager.startTask();
24
24
  try {
25
- code = await ResourceFetcher.fetch({
26
- window: element.ownerDocument.defaultView,
27
- url: src
28
- });
25
+ code = await ResourceFetchHandler.fetch(element.ownerDocument, src);
29
26
  } catch (error) {
30
27
  element.dispatchEvent(
31
28
  new ErrorEvent('error', {
@@ -54,10 +51,7 @@ export default class ScriptUtility {
54
51
  } else {
55
52
  let code = null;
56
53
  try {
57
- code = ResourceFetcher.fetchSync({
58
- window: element.ownerDocument.defaultView,
59
- url: src
60
- });
54
+ code = ResourceFetchHandler.fetchSync(element.ownerDocument, src);
61
55
  } catch (error) {
62
56
  element.dispatchEvent(
63
57
  new ErrorEvent('error', {
@@ -1,7 +1,8 @@
1
1
  import DOMException from '../exception/DOMException';
2
2
  import Element from '../nodes/element/Element';
3
3
 
4
- const ATTRIBUTE_REGEXP = /\[([a-zA-Z0-9-_]+)\]|\[([a-zA-Z0-9-_]+)([~|^$*]{0,1})[ ]*=[ ]*["']{0,1}([^"']+)["']{0,1}\]/g;
4
+ const ATTRIBUTE_REGEXP =
5
+ /\[([a-zA-Z0-9-_]+)\]|\[([a-zA-Z0-9-_]+)([~|^$*]{0,1})[ ]*=[ ]*["']{0,1}([^"']+)["']{0,1}\]/g;
5
6
  const ATTRIBUTE_NAME_REGEXP = /[^a-zA-Z0-9-_$]/;
6
7
  const PSUEDO_REGEXP = /:([a-zA-Z-]+)\(([0-9n+-]+|odd|even)\)|:not\(([^)]+)\)|:([a-zA-Z-]+)/g;
7
8
  const CLASS_REGEXP = /\.([a-zA-Z0-9-_$]+)/g;
@@ -127,13 +128,13 @@ export default class SelectorItem {
127
128
 
128
129
  switch (psuedo.toLowerCase()) {
129
130
  case 'nth-of-type':
130
- children = children.filter(child => child.tagName === element.tagName);
131
+ children = children.filter((child) => child.tagName === element.tagName);
131
132
  break;
132
133
  case 'nth-last-child':
133
134
  children = children.reverse();
134
135
  break;
135
136
  case 'nth-last-of-type':
136
- children = children.filter(child => child.tagName === element.tagName).reverse();
137
+ children = children.filter((child) => child.tagName === element.tagName).reverse();
137
138
  break;
138
139
  }
139
140
 
@@ -285,7 +286,7 @@ export default class SelectorItem {
285
286
  return !!element._attributes[attributeName.toLowerCase()];
286
287
  }
287
288
 
288
- /**
289
+ /** .
289
290
  *
290
291
  * Matches attribute name and value.
291
292
  *
@@ -295,6 +296,13 @@ export default class SelectorItem {
295
296
  * @param [matchType] Match type.
296
297
  * @returns True if it is a match.
297
298
  */
299
+ /**
300
+ *
301
+ * @param element
302
+ * @param attributeName
303
+ * @param attributeValue
304
+ * @param matchType
305
+ */
298
306
  private matchesAttributeNameAndValue(
299
307
  element: Element,
300
308
  attributeName: string,