happy-dom 2.49.1 → 2.51.0
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.
- package/.eslintrc.js +7 -6
- package/.prettierrc.js +2 -1
- package/lib/async-task-manager/AsyncTaskManager.d.ts +65 -0
- package/lib/{window → async-task-manager}/AsyncTaskManager.js +52 -55
- package/lib/async-task-manager/AsyncTaskManager.js.map +1 -0
- package/lib/cookie/CookieUtility.js +1 -4
- package/lib/cookie/CookieUtility.js.map +1 -1
- package/lib/custom-element/CustomElementRegistry.js.map +1 -1
- package/lib/dom-token-list/DOMTokenList.d.ts +0 -4
- package/lib/dom-token-list/DOMTokenList.js +0 -4
- package/lib/dom-token-list/DOMTokenList.js.map +1 -1
- package/lib/fetch/FetchHandler.d.ts +17 -0
- package/lib/fetch/FetchHandler.js +59 -0
- package/lib/fetch/FetchHandler.js.map +1 -0
- package/lib/fetch/Headers.d.ts +7 -0
- package/lib/fetch/Headers.js +53 -0
- package/lib/fetch/Headers.js.map +1 -0
- package/lib/fetch/IAbortSignal.d.ts +16 -0
- package/lib/fetch/IAbortSignal.js +4 -0
- package/lib/fetch/IAbortSignal.js.map +1 -0
- package/lib/fetch/IBody.d.ts +17 -0
- package/lib/{window/IFetchOptions.js → fetch/IBody.js} +1 -1
- package/lib/fetch/IBody.js.map +1 -0
- package/lib/fetch/IHeaders.d.ts +18 -0
- package/lib/fetch/IHeaders.js +3 -0
- package/lib/fetch/IHeaders.js.map +1 -0
- package/lib/fetch/IHeadersInit.d.ts +5 -0
- package/lib/fetch/IHeadersInit.js +3 -0
- package/lib/fetch/IHeadersInit.js.map +1 -0
- package/lib/fetch/IRequest.d.ts +18 -0
- package/lib/fetch/IRequest.js +3 -0
- package/lib/fetch/IRequest.js.map +1 -0
- package/lib/fetch/IRequestInit.d.ts +15 -0
- package/lib/fetch/IRequestInit.js +3 -0
- package/lib/fetch/IRequestInit.js.map +1 -0
- package/lib/fetch/IResponse.d.ts +20 -0
- package/lib/{window → fetch}/IResponse.js +0 -0
- package/lib/{window → fetch}/IResponse.js.map +1 -1
- package/lib/fetch/IResponseInit.d.ts +9 -0
- package/lib/fetch/IResponseInit.js +3 -0
- package/lib/fetch/IResponseInit.js.map +1 -0
- package/lib/fetch/Request.d.ts +69 -0
- package/lib/fetch/Request.js +179 -0
- package/lib/fetch/Request.js.map +1 -0
- package/lib/fetch/ResourceFetchHandler.d.ts +22 -0
- package/lib/fetch/{ResourceFetcher.js → ResourceFetchHandler.js} +19 -26
- package/lib/fetch/ResourceFetchHandler.js.map +1 -0
- package/lib/fetch/Response.d.ts +69 -0
- package/lib/fetch/Response.js +179 -0
- package/lib/fetch/Response.js.map +1 -0
- package/lib/file/Blob.d.ts +8 -1
- package/lib/file/Blob.js +48 -0
- package/lib/file/Blob.js.map +1 -1
- package/lib/file/IBlob.d.ts +10 -0
- package/lib/file/IBlob.js +3 -0
- package/lib/file/IBlob.js.map +1 -0
- package/lib/form-data/IFormData.d.ts +30 -0
- package/lib/form-data/IFormData.js +3 -0
- package/lib/form-data/IFormData.js.map +1 -0
- package/lib/index.d.ts +3 -5
- package/lib/index.js +3 -3
- package/lib/index.js.map +1 -1
- package/lib/location/URL.d.ts +10 -10
- package/lib/location/URL.js +34 -34
- package/lib/location/URL.js.map +1 -1
- package/lib/mutation-observer/MutationObserver.js.map +1 -1
- package/lib/nodes/character-data/CharacterData.d.ts +12 -12
- package/lib/nodes/character-data/CharacterData.js +24 -24
- package/lib/nodes/character-data/CharacterData.js.map +1 -1
- package/lib/nodes/document/Document.d.ts +8 -9
- package/lib/nodes/document/Document.js +9 -8
- package/lib/nodes/document/Document.js.map +1 -1
- package/lib/nodes/document/DocumentReadyStateManager.js.map +1 -1
- package/lib/nodes/html-input-element/HTMLInputElementValueSanitizer.js.map +1 -1
- package/lib/nodes/html-link-element/HTMLLinkElement.js +3 -3
- package/lib/nodes/html-link-element/HTMLLinkElement.js.map +1 -1
- package/lib/nodes/html-script-element/ScriptUtility.js +3 -9
- package/lib/nodes/html-script-element/ScriptUtility.js.map +1 -1
- package/lib/query-selector/SelectorItem.d.ts +8 -1
- package/lib/query-selector/SelectorItem.js +8 -1
- package/lib/query-selector/SelectorItem.js.map +1 -1
- package/lib/window/IWindow.d.ts +20 -16
- package/lib/window/Window.d.ts +59 -12
- package/lib/window/Window.js +117 -70
- package/lib/window/Window.js.map +1 -1
- package/lib/xml-parser/XMLParser.js +1 -4
- package/lib/xml-parser/XMLParser.js.map +1 -1
- package/package.json +22 -21
- package/src/async-task-manager/AsyncTaskManager.ts +128 -0
- package/src/cookie/CookieUtility.ts +1 -4
- package/src/custom-element/CustomElementRegistry.ts +1 -1
- package/src/dom-token-list/DOMTokenList.ts +0 -4
- package/src/fetch/FetchHandler.ts +54 -0
- package/src/fetch/Headers.ts +7 -0
- package/src/fetch/IAbortSignal.ts +34 -0
- package/src/fetch/IBody.ts +18 -0
- package/src/fetch/IHeaders.ts +18 -0
- package/src/fetch/IHeadersInit.ts +5 -0
- package/src/fetch/IRequest.ts +59 -0
- package/src/fetch/IRequestInit.ts +41 -0
- package/src/fetch/IResponse.ts +22 -0
- package/src/fetch/IResponseInit.ts +10 -0
- package/src/fetch/Request.ts +149 -0
- package/src/fetch/ResourceFetchHandler.ts +47 -0
- package/src/fetch/Response.ts +149 -0
- package/src/file/Blob.ts +12 -1
- package/src/file/IBlob.ts +10 -0
- package/src/form-data/IFormData.ts +33 -0
- package/src/index.ts +2 -6
- package/src/location/URL.ts +39 -38
- package/src/mutation-observer/MutationObserver.ts +1 -1
- package/src/nodes/character-data/CharacterData.ts +18 -17
- package/src/nodes/document/Document.ts +12 -9
- package/src/nodes/document/DocumentReadyStateManager.ts +1 -1
- package/src/nodes/html-input-element/HTMLInputElementValueSanitizer.ts +1 -1
- package/src/nodes/html-link-element/HTMLLinkElement.ts +7 -7
- package/src/nodes/html-script-element/ScriptUtility.ts +3 -9
- package/src/query-selector/SelectorItem.ts +12 -4
- package/src/window/IWindow.ts +14 -16
- package/src/window/Window.ts +103 -70
- package/src/xml-parser/XMLParser.ts +1 -4
- package/lib/fetch/ResourceFetcher.d.ts +0 -30
- package/lib/fetch/ResourceFetcher.js.map +0 -1
- package/lib/url-search-params/URLSearchParams.d.ts +0 -87
- package/lib/url-search-params/URLSearchParams.js +0 -196
- package/lib/url-search-params/URLSearchParams.js.map +0 -1
- package/lib/window/AsyncTaskManager.d.ts +0 -54
- package/lib/window/AsyncTaskManager.js.map +0 -1
- package/lib/window/AsyncTaskTypeEnum.d.ts +0 -5
- package/lib/window/AsyncTaskTypeEnum.js +0 -9
- package/lib/window/AsyncTaskTypeEnum.js.map +0 -1
- package/lib/window/IFetchOptions.d.ts +0 -13
- package/lib/window/IFetchOptions.js.map +0 -1
- package/lib/window/IResponse.d.ts +0 -32
- package/src/fetch/ResourceFetcher.ts +0 -55
- package/src/url-search-params/URLSearchParams.ts +0 -198
- package/src/window/AsyncTaskManager.ts +0 -127
- package/src/window/AsyncTaskTypeEnum.ts +0 -5
- package/src/window/IFetchOptions.ts +0 -11
- 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,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 './
|
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 '
|
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,
|
package/src/location/URL.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
const URL_REGEXP =
|
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.
|
@@ -590,32 +590,33 @@ export default class Document extends Node implements IDocument {
|
|
590
590
|
*/
|
591
591
|
public close(): void {}
|
592
592
|
|
593
|
+
/* eslint-disable jsdoc/valid-types */
|
594
|
+
|
593
595
|
/**
|
594
596
|
* Creates an element.
|
595
597
|
*
|
596
|
-
* @param
|
598
|
+
* @param qualifiedName Tag name.
|
597
599
|
* @param [options] Options.
|
598
|
-
* @param options.is
|
600
|
+
* @param [options.is] Tag name of a custom element previously defined via customElements.define().
|
599
601
|
* @returns Element.
|
600
602
|
*/
|
601
|
-
public createElement(
|
602
|
-
return this.createElementNS(NamespaceURI.html,
|
603
|
+
public createElement(qualifiedName: string, options?: { is?: string }): IElement {
|
604
|
+
return this.createElementNS(NamespaceURI.html, qualifiedName, options);
|
603
605
|
}
|
604
606
|
|
605
607
|
/**
|
606
608
|
* Creates an element with the specified namespace URI and qualified name.
|
607
609
|
*
|
608
|
-
* @param
|
610
|
+
* @param namespaceURI Namespace URI.
|
611
|
+
* @param qualifiedName Tag name.
|
609
612
|
* @param [options] Options.
|
610
|
-
* @param
|
611
|
-
* @param qualifiedName
|
612
|
-
* @param options.is
|
613
|
+
* @param [options.is] Tag name of a custom element previously defined via customElements.define().
|
613
614
|
* @returns Element.
|
614
615
|
*/
|
615
616
|
public createElementNS(
|
616
617
|
namespaceURI: string,
|
617
618
|
qualifiedName: string,
|
618
|
-
options?: { is
|
619
|
+
options?: { is?: string }
|
619
620
|
): IElement {
|
620
621
|
const tagName = qualifiedName.toUpperCase();
|
621
622
|
|
@@ -638,6 +639,8 @@ export default class Document extends Node implements IDocument {
|
|
638
639
|
return element;
|
639
640
|
}
|
640
641
|
|
642
|
+
/* eslint-enable jsdoc/valid-types */
|
643
|
+
|
641
644
|
/**
|
642
645
|
* Creates a text node.
|
643
646
|
*
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import Attr from '../../attribute/Attr';
|
2
2
|
import CSSStyleSheet from '../../css/CSSStyleSheet';
|
3
|
-
import
|
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
|
-
|
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
|
-
|
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
|
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
|
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 =
|
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 =
|
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,
|