@mtkruto/node 0.1.200 → 0.1.201
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.
- package/esm/client/4_client.d.ts +5 -8
- package/esm/client/4_client.js +5 -14
- package/package.json +1 -1
- package/script/client/4_client.d.ts +5 -8
- package/script/client/4_client.js +5 -14
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.d.ts +0 -83
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.js +0 -203
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.d.ts +0 -50
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.js +0 -274
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.d.ts +0 -47
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.js +0 -51
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.d.ts +0 -66
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.js +0 -191
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Node.d.ts +0 -168
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Node.js +0 -385
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Parser.d.ts +0 -159
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Parser.js +0 -431
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.d.ts +0 -181
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.js +0 -1046
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/mod.d.ts +0 -42
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/mod.js +0 -52
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.d.ts +0 -11
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.js +0 -122
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.d.ts +0 -1
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.js +0 -24
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.d.ts +0 -46
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.js +0 -121
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.d.ts +0 -31
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.js +0 -30
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.d.ts +0 -2128
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.js +0 -2127
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.d.ts +0 -109
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.js +0 -108
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.d.ts +0 -8
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.js +0 -1
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.d.ts +0 -90
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.js +0 -95
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.d.ts +0 -50
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.js +0 -128
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.d.ts +0 -46
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.js +0 -110
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.d.ts +0 -42
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.js +0 -120
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.d.ts +0 -6
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.js +0 -6
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.d.ts +0 -54
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.js +0 -110
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.d.ts +0 -40
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.js +0 -75
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.d.ts +0 -58
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.js +0 -101
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.d.ts +0 -83
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.js +0 -207
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.d.ts +0 -50
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.js +0 -301
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.d.ts +0 -47
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.js +0 -55
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.d.ts +0 -66
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.js +0 -222
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/Node.d.ts +0 -168
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/Node.js +0 -404
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/Parser.d.ts +0 -159
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/Parser.js +0 -438
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.d.ts +0 -181
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.js +0 -1052
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/mod.d.ts +0 -42
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/mod.js +0 -88
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.d.ts +0 -11
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.js +0 -128
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.d.ts +0 -1
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.js +0 -30
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.d.ts +0 -46
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.js +0 -129
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.d.ts +0 -31
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.js +0 -32
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.d.ts +0 -2128
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.js +0 -2129
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.d.ts +0 -109
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.js +0 -110
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.d.ts +0 -8
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.js +0 -3
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.d.ts +0 -90
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.js +0 -114
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.d.ts +0 -50
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.js +0 -134
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.d.ts +0 -46
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.js +0 -118
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.d.ts +0 -42
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.js +0 -129
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.d.ts +0 -6
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.js +0 -22
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.d.ts +0 -54
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.js +0 -119
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.d.ts +0 -40
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.js +0 -86
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.d.ts +0 -58
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.js +0 -112
package/esm/client/4_client.d.ts
CHANGED
|
@@ -235,27 +235,24 @@ export declare class Client<C extends Context = Context> extends Composer<C> {
|
|
|
235
235
|
[handleMigrationError](err: Migrate): Promise<void>;
|
|
236
236
|
disconnect(): Promise<void>;
|
|
237
237
|
/**
|
|
238
|
-
*
|
|
238
|
+
* Authorizes the client with one of the following:
|
|
239
239
|
*
|
|
240
240
|
* - Bot token (`string`)
|
|
241
|
-
* - Exported authorization (`types.AuthExportedAuthorization`)
|
|
242
241
|
* - User authorization handlers (`AuthorizeUserParams`)
|
|
243
242
|
*
|
|
244
|
-
* if the current auth key doesn't throw AUTH_KEY_UNREGISTERED when calling [updates.getState](
|
|
243
|
+
* if the current auth key doesn't throw AUTH_KEY_UNREGISTERED when calling [updates.getState](1).
|
|
245
244
|
*
|
|
246
245
|
* Notes:
|
|
247
246
|
* 1. Requires the `apiId` and `apiHash` paramters to be passed when constructing the client.
|
|
248
247
|
* 2. Reconnects the client to the appropriate DC in case of MIGRATE_X errors.
|
|
249
|
-
* 3. The parameters passed to the [initConnection][1] call can be configured with the last parameter of the constructor.
|
|
250
248
|
*
|
|
251
|
-
* [1]: https://core.telegram.org/method/
|
|
252
|
-
* [2]: https://core.telegram.org/method/updates.getState
|
|
249
|
+
* [1]: https://core.telegram.org/method/updates.getState
|
|
253
250
|
*/
|
|
254
|
-
authorize(params?: string |
|
|
251
|
+
authorize(params?: string | AuthorizeUserParams): Promise<void>;
|
|
255
252
|
/**
|
|
256
253
|
* Same as calling `.connect()` followed by `.authorize(params)`.
|
|
257
254
|
*/
|
|
258
|
-
start(params?: string |
|
|
255
|
+
start(params?: string | AuthorizeUserParams): Promise<void>;
|
|
259
256
|
/**
|
|
260
257
|
* Invokes a function waiting and returning its reply if the second parameter is not `true`. Requires the client
|
|
261
258
|
* to be connected.
|
package/esm/client/4_client.js
CHANGED
|
@@ -681,8 +681,7 @@ export class Client extends Composer {
|
|
|
681
681
|
if (ctx.error instanceof AuthKeyUnregistered && dcId) {
|
|
682
682
|
try {
|
|
683
683
|
const exportedAuth = await this.api.auth.exportAuthorization({ dc_id: dcId });
|
|
684
|
-
await client.
|
|
685
|
-
// throw 1;
|
|
684
|
+
await client.api.auth.importAuthorization(exportedAuth);
|
|
686
685
|
return true;
|
|
687
686
|
}
|
|
688
687
|
catch (err) {
|
|
@@ -863,21 +862,18 @@ export class Client extends Composer {
|
|
|
863
862
|
__classPrivateFieldGet(this, _Client_pingLoopAbortController, "f")?.abort();
|
|
864
863
|
}
|
|
865
864
|
/**
|
|
866
|
-
*
|
|
865
|
+
* Authorizes the client with one of the following:
|
|
867
866
|
*
|
|
868
867
|
* - Bot token (`string`)
|
|
869
|
-
* - Exported authorization (`types.AuthExportedAuthorization`)
|
|
870
868
|
* - User authorization handlers (`AuthorizeUserParams`)
|
|
871
869
|
*
|
|
872
|
-
* if the current auth key doesn't throw AUTH_KEY_UNREGISTERED when calling [updates.getState](
|
|
870
|
+
* if the current auth key doesn't throw AUTH_KEY_UNREGISTERED when calling [updates.getState](1).
|
|
873
871
|
*
|
|
874
872
|
* Notes:
|
|
875
873
|
* 1. Requires the `apiId` and `apiHash` paramters to be passed when constructing the client.
|
|
876
874
|
* 2. Reconnects the client to the appropriate DC in case of MIGRATE_X errors.
|
|
877
|
-
* 3. The parameters passed to the [initConnection][1] call can be configured with the last parameter of the constructor.
|
|
878
875
|
*
|
|
879
|
-
* [1]: https://core.telegram.org/method/
|
|
880
|
-
* [2]: https://core.telegram.org/method/updates.getState
|
|
876
|
+
* [1]: https://core.telegram.org/method/updates.getState
|
|
881
877
|
*/
|
|
882
878
|
async authorize(params) {
|
|
883
879
|
try {
|
|
@@ -929,11 +925,6 @@ export class Client extends Composer {
|
|
|
929
925
|
await __classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("authorize");
|
|
930
926
|
return;
|
|
931
927
|
}
|
|
932
|
-
if (params instanceof types.auth.ExportedAuthorization) {
|
|
933
|
-
await this.api.auth.importAuthorization({ id: params.id, bytes: params.bytes });
|
|
934
|
-
__classPrivateFieldGet(this, _Client_Lauthorize, "f").debug("authorization imported");
|
|
935
|
-
return;
|
|
936
|
-
}
|
|
937
928
|
auth: while (true) {
|
|
938
929
|
try {
|
|
939
930
|
let phone;
|
|
@@ -1074,7 +1065,7 @@ export class Client extends Composer {
|
|
|
1074
1065
|
inputPeer.access_hash = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getUserAccessHash).call(this, inputPeer.user_id);
|
|
1075
1066
|
}
|
|
1076
1067
|
}
|
|
1077
|
-
|
|
1068
|
+
if ((inputPeer instanceof types.InputPeerUser || inputPeer instanceof types.InputPeerChannel && inputPeer.access_hash == 0n) && await this.storage.getAccountType() == "user") {
|
|
1078
1069
|
throw new AccessError(`Cannot access the chat ${id} because there is no access hash for it.`);
|
|
1079
1070
|
}
|
|
1080
1071
|
return inputPeer;
|
package/package.json
CHANGED
|
@@ -235,27 +235,24 @@ export declare class Client<C extends Context = Context> extends Composer<C> {
|
|
|
235
235
|
[handleMigrationError](err: Migrate): Promise<void>;
|
|
236
236
|
disconnect(): Promise<void>;
|
|
237
237
|
/**
|
|
238
|
-
*
|
|
238
|
+
* Authorizes the client with one of the following:
|
|
239
239
|
*
|
|
240
240
|
* - Bot token (`string`)
|
|
241
|
-
* - Exported authorization (`types.AuthExportedAuthorization`)
|
|
242
241
|
* - User authorization handlers (`AuthorizeUserParams`)
|
|
243
242
|
*
|
|
244
|
-
* if the current auth key doesn't throw AUTH_KEY_UNREGISTERED when calling [updates.getState](
|
|
243
|
+
* if the current auth key doesn't throw AUTH_KEY_UNREGISTERED when calling [updates.getState](1).
|
|
245
244
|
*
|
|
246
245
|
* Notes:
|
|
247
246
|
* 1. Requires the `apiId` and `apiHash` paramters to be passed when constructing the client.
|
|
248
247
|
* 2. Reconnects the client to the appropriate DC in case of MIGRATE_X errors.
|
|
249
|
-
* 3. The parameters passed to the [initConnection][1] call can be configured with the last parameter of the constructor.
|
|
250
248
|
*
|
|
251
|
-
* [1]: https://core.telegram.org/method/
|
|
252
|
-
* [2]: https://core.telegram.org/method/updates.getState
|
|
249
|
+
* [1]: https://core.telegram.org/method/updates.getState
|
|
253
250
|
*/
|
|
254
|
-
authorize(params?: string |
|
|
251
|
+
authorize(params?: string | AuthorizeUserParams): Promise<void>;
|
|
255
252
|
/**
|
|
256
253
|
* Same as calling `.connect()` followed by `.authorize(params)`.
|
|
257
254
|
*/
|
|
258
|
-
start(params?: string |
|
|
255
|
+
start(params?: string | AuthorizeUserParams): Promise<void>;
|
|
259
256
|
/**
|
|
260
257
|
* Invokes a function waiting and returning its reply if the second parameter is not `true`. Requires the client
|
|
261
258
|
* to be connected.
|
|
@@ -685,8 +685,7 @@ class Client extends Composer {
|
|
|
685
685
|
if (ctx.error instanceof _4_errors_js_1.AuthKeyUnregistered && dcId) {
|
|
686
686
|
try {
|
|
687
687
|
const exportedAuth = await this.api.auth.exportAuthorization({ dc_id: dcId });
|
|
688
|
-
await client.
|
|
689
|
-
// throw 1;
|
|
688
|
+
await client.api.auth.importAuthorization(exportedAuth);
|
|
690
689
|
return true;
|
|
691
690
|
}
|
|
692
691
|
catch (err) {
|
|
@@ -867,21 +866,18 @@ class Client extends Composer {
|
|
|
867
866
|
__classPrivateFieldGet(this, _Client_pingLoopAbortController, "f")?.abort();
|
|
868
867
|
}
|
|
869
868
|
/**
|
|
870
|
-
*
|
|
869
|
+
* Authorizes the client with one of the following:
|
|
871
870
|
*
|
|
872
871
|
* - Bot token (`string`)
|
|
873
|
-
* - Exported authorization (`types.AuthExportedAuthorization`)
|
|
874
872
|
* - User authorization handlers (`AuthorizeUserParams`)
|
|
875
873
|
*
|
|
876
|
-
* if the current auth key doesn't throw AUTH_KEY_UNREGISTERED when calling [updates.getState](
|
|
874
|
+
* if the current auth key doesn't throw AUTH_KEY_UNREGISTERED when calling [updates.getState](1).
|
|
877
875
|
*
|
|
878
876
|
* Notes:
|
|
879
877
|
* 1. Requires the `apiId` and `apiHash` paramters to be passed when constructing the client.
|
|
880
878
|
* 2. Reconnects the client to the appropriate DC in case of MIGRATE_X errors.
|
|
881
|
-
* 3. The parameters passed to the [initConnection][1] call can be configured with the last parameter of the constructor.
|
|
882
879
|
*
|
|
883
|
-
* [1]: https://core.telegram.org/method/
|
|
884
|
-
* [2]: https://core.telegram.org/method/updates.getState
|
|
880
|
+
* [1]: https://core.telegram.org/method/updates.getState
|
|
885
881
|
*/
|
|
886
882
|
async authorize(params) {
|
|
887
883
|
try {
|
|
@@ -933,11 +929,6 @@ class Client extends Composer {
|
|
|
933
929
|
await __classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("authorize");
|
|
934
930
|
return;
|
|
935
931
|
}
|
|
936
|
-
if (params instanceof _2_tl_js_1.types.auth.ExportedAuthorization) {
|
|
937
|
-
await this.api.auth.importAuthorization({ id: params.id, bytes: params.bytes });
|
|
938
|
-
__classPrivateFieldGet(this, _Client_Lauthorize, "f").debug("authorization imported");
|
|
939
|
-
return;
|
|
940
|
-
}
|
|
941
932
|
auth: while (true) {
|
|
942
933
|
try {
|
|
943
934
|
let phone;
|
|
@@ -1078,7 +1069,7 @@ class Client extends Composer {
|
|
|
1078
1069
|
inputPeer.access_hash = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getUserAccessHash).call(this, inputPeer.user_id);
|
|
1079
1070
|
}
|
|
1080
1071
|
}
|
|
1081
|
-
|
|
1072
|
+
if ((inputPeer instanceof _2_tl_js_1.types.InputPeerUser || inputPeer instanceof _2_tl_js_1.types.InputPeerChannel && inputPeer.access_hash == 0n) && await this.storage.getAccountType() == "user") {
|
|
1082
1073
|
throw new _0_errors_js_1.AccessError(`Cannot access the chat ${id} because there is no access hash for it.`);
|
|
1083
1074
|
}
|
|
1084
1075
|
return inputPeer;
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { Node, Element, Document, NodeWithChildren, DataNode } from './Node.js';
|
|
2
|
-
export interface DomHandlerOptions {
|
|
3
|
-
/**
|
|
4
|
-
* Add a `startIndex` property to nodes.
|
|
5
|
-
* When the parser is used in a non-streaming fashion, `startIndex` is an integer
|
|
6
|
-
* indicating the position of the start of the node in the document.
|
|
7
|
-
*
|
|
8
|
-
* @default false
|
|
9
|
-
*/
|
|
10
|
-
withStartIndices?: boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Add an `endIndex` property to nodes.
|
|
13
|
-
* When the parser is used in a non-streaming fashion, `endIndex` is an integer
|
|
14
|
-
* indicating the position of the end of the node in the document.
|
|
15
|
-
*
|
|
16
|
-
* @default false
|
|
17
|
-
*/
|
|
18
|
-
withEndIndices?: boolean;
|
|
19
|
-
/**
|
|
20
|
-
* Replace all whitespace with single spaces.
|
|
21
|
-
*
|
|
22
|
-
* **Note:** Enabling this might break your markup.
|
|
23
|
-
*
|
|
24
|
-
* @default false
|
|
25
|
-
* @deprecated
|
|
26
|
-
*/
|
|
27
|
-
normalizeWhitespace?: boolean;
|
|
28
|
-
/**
|
|
29
|
-
* Treat the markup as XML.
|
|
30
|
-
*
|
|
31
|
-
* @default false
|
|
32
|
-
*/
|
|
33
|
-
xmlMode?: boolean;
|
|
34
|
-
}
|
|
35
|
-
interface ParserInterface {
|
|
36
|
-
startIndex: number | null;
|
|
37
|
-
endIndex: number | null;
|
|
38
|
-
}
|
|
39
|
-
type Callback = (error: Error | null, dom: Node[]) => void;
|
|
40
|
-
type ElementCallback = (element: Element) => void;
|
|
41
|
-
export declare class DomHandler {
|
|
42
|
-
/** The elements of the DOM */
|
|
43
|
-
dom: Node[];
|
|
44
|
-
/** The root element for the DOM */
|
|
45
|
-
root: Document;
|
|
46
|
-
/** Called once parsing has completed. */
|
|
47
|
-
private readonly callback;
|
|
48
|
-
/** Settings for the handler. */
|
|
49
|
-
private readonly options;
|
|
50
|
-
/** Callback whenever a tag is closed. */
|
|
51
|
-
private readonly elementCB;
|
|
52
|
-
/** Indicated whether parsing has been completed. */
|
|
53
|
-
private done;
|
|
54
|
-
/** Stack of open tags. */
|
|
55
|
-
protected tagStack: NodeWithChildren[];
|
|
56
|
-
/** A data node that is still being written to. */
|
|
57
|
-
protected lastNode: DataNode | null;
|
|
58
|
-
/** Reference to the parser instance. Used for location information. */
|
|
59
|
-
private parser;
|
|
60
|
-
/**
|
|
61
|
-
* @param callback Called once parsing has completed.
|
|
62
|
-
* @param options Settings for the handler.
|
|
63
|
-
* @param elementCB Callback whenever a tag is closed.
|
|
64
|
-
*/
|
|
65
|
-
constructor(callback?: Callback | null, options?: DomHandlerOptions | null, elementCB?: ElementCallback);
|
|
66
|
-
onparserinit(parser: ParserInterface): void;
|
|
67
|
-
onreset(): void;
|
|
68
|
-
onend(): void;
|
|
69
|
-
onerror(error: Error): void;
|
|
70
|
-
onclosetag(): void;
|
|
71
|
-
onopentag(name: string, attribs: {
|
|
72
|
-
[key: string]: string;
|
|
73
|
-
}): void;
|
|
74
|
-
ontext(data: string): void;
|
|
75
|
-
oncomment(data: string): void;
|
|
76
|
-
oncommentend(): void;
|
|
77
|
-
oncdatastart(): void;
|
|
78
|
-
oncdataend(): void;
|
|
79
|
-
onprocessinginstruction(name: string, data: string): void;
|
|
80
|
-
protected handleCallback(error: Error | null): void;
|
|
81
|
-
protected addNode(node: Node): void;
|
|
82
|
-
}
|
|
83
|
-
export default DomHandler;
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import { Element, Document, NodeWithChildren, Comment, Text, ProcessingInstruction, } from './Node.js';
|
|
2
|
-
import { ElementType } from './ElementType.js';
|
|
3
|
-
const reWhitespace = /\s+/g;
|
|
4
|
-
// Default options
|
|
5
|
-
const defaultOpts = {
|
|
6
|
-
normalizeWhitespace: false,
|
|
7
|
-
withStartIndices: false,
|
|
8
|
-
withEndIndices: false,
|
|
9
|
-
};
|
|
10
|
-
export class DomHandler {
|
|
11
|
-
/**
|
|
12
|
-
* @param callback Called once parsing has completed.
|
|
13
|
-
* @param options Settings for the handler.
|
|
14
|
-
* @param elementCB Callback whenever a tag is closed.
|
|
15
|
-
*/
|
|
16
|
-
constructor(callback, options, elementCB) {
|
|
17
|
-
/** The elements of the DOM */
|
|
18
|
-
Object.defineProperty(this, "dom", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
configurable: true,
|
|
21
|
-
writable: true,
|
|
22
|
-
value: []
|
|
23
|
-
});
|
|
24
|
-
/** The root element for the DOM */
|
|
25
|
-
Object.defineProperty(this, "root", {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
configurable: true,
|
|
28
|
-
writable: true,
|
|
29
|
-
value: new Document(this.dom)
|
|
30
|
-
});
|
|
31
|
-
/** Called once parsing has completed. */
|
|
32
|
-
Object.defineProperty(this, "callback", {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
configurable: true,
|
|
35
|
-
writable: true,
|
|
36
|
-
value: void 0
|
|
37
|
-
});
|
|
38
|
-
/** Settings for the handler. */
|
|
39
|
-
Object.defineProperty(this, "options", {
|
|
40
|
-
enumerable: true,
|
|
41
|
-
configurable: true,
|
|
42
|
-
writable: true,
|
|
43
|
-
value: void 0
|
|
44
|
-
});
|
|
45
|
-
/** Callback whenever a tag is closed. */
|
|
46
|
-
Object.defineProperty(this, "elementCB", {
|
|
47
|
-
enumerable: true,
|
|
48
|
-
configurable: true,
|
|
49
|
-
writable: true,
|
|
50
|
-
value: void 0
|
|
51
|
-
});
|
|
52
|
-
/** Indicated whether parsing has been completed. */
|
|
53
|
-
Object.defineProperty(this, "done", {
|
|
54
|
-
enumerable: true,
|
|
55
|
-
configurable: true,
|
|
56
|
-
writable: true,
|
|
57
|
-
value: false
|
|
58
|
-
});
|
|
59
|
-
/** Stack of open tags. */
|
|
60
|
-
Object.defineProperty(this, "tagStack", {
|
|
61
|
-
enumerable: true,
|
|
62
|
-
configurable: true,
|
|
63
|
-
writable: true,
|
|
64
|
-
value: [this.root]
|
|
65
|
-
});
|
|
66
|
-
/** A data node that is still being written to. */
|
|
67
|
-
Object.defineProperty(this, "lastNode", {
|
|
68
|
-
enumerable: true,
|
|
69
|
-
configurable: true,
|
|
70
|
-
writable: true,
|
|
71
|
-
value: null
|
|
72
|
-
});
|
|
73
|
-
/** Reference to the parser instance. Used for location information. */
|
|
74
|
-
Object.defineProperty(this, "parser", {
|
|
75
|
-
enumerable: true,
|
|
76
|
-
configurable: true,
|
|
77
|
-
writable: true,
|
|
78
|
-
value: null
|
|
79
|
-
});
|
|
80
|
-
// Make it possible to skip arguments, for backwards-compatibility
|
|
81
|
-
if (typeof options === 'function') {
|
|
82
|
-
elementCB = options;
|
|
83
|
-
options = defaultOpts;
|
|
84
|
-
}
|
|
85
|
-
if (typeof callback === 'object') {
|
|
86
|
-
options = callback;
|
|
87
|
-
callback = undefined;
|
|
88
|
-
}
|
|
89
|
-
this.callback = callback ?? null;
|
|
90
|
-
this.options = options ?? defaultOpts;
|
|
91
|
-
this.elementCB = elementCB ?? null;
|
|
92
|
-
}
|
|
93
|
-
onparserinit(parser) {
|
|
94
|
-
this.parser = parser;
|
|
95
|
-
}
|
|
96
|
-
// Resets the handler back to starting state
|
|
97
|
-
onreset() {
|
|
98
|
-
this.dom = [];
|
|
99
|
-
this.root = new Document(this.dom);
|
|
100
|
-
this.done = false;
|
|
101
|
-
this.tagStack = [this.root];
|
|
102
|
-
this.lastNode = null;
|
|
103
|
-
this.parser = this.parser ?? null;
|
|
104
|
-
}
|
|
105
|
-
// Signals the handler that parsing is done
|
|
106
|
-
onend() {
|
|
107
|
-
if (this.done)
|
|
108
|
-
return;
|
|
109
|
-
this.done = true;
|
|
110
|
-
this.parser = null;
|
|
111
|
-
this.handleCallback(null);
|
|
112
|
-
}
|
|
113
|
-
onerror(error) {
|
|
114
|
-
this.handleCallback(error);
|
|
115
|
-
}
|
|
116
|
-
onclosetag() {
|
|
117
|
-
this.lastNode = null;
|
|
118
|
-
const elem = this.tagStack.pop();
|
|
119
|
-
if (this.options.withEndIndices) {
|
|
120
|
-
elem.endIndex = this.parser.endIndex;
|
|
121
|
-
}
|
|
122
|
-
if (this.elementCB)
|
|
123
|
-
this.elementCB(elem);
|
|
124
|
-
}
|
|
125
|
-
onopentag(name, attribs) {
|
|
126
|
-
const type = this.options.xmlMode ? ElementType.Tag : undefined;
|
|
127
|
-
const element = new Element(name, attribs, undefined, type);
|
|
128
|
-
this.addNode(element);
|
|
129
|
-
this.tagStack.push(element);
|
|
130
|
-
}
|
|
131
|
-
ontext(data) {
|
|
132
|
-
const { normalizeWhitespace } = this.options;
|
|
133
|
-
const { lastNode } = this;
|
|
134
|
-
if (lastNode && lastNode.type === ElementType.Text) {
|
|
135
|
-
if (normalizeWhitespace) {
|
|
136
|
-
lastNode.data = (lastNode.data + data).replace(reWhitespace, ' ');
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
lastNode.data += data;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
if (normalizeWhitespace) {
|
|
144
|
-
data = data.replace(reWhitespace, ' ');
|
|
145
|
-
}
|
|
146
|
-
const node = new Text(data);
|
|
147
|
-
this.addNode(node);
|
|
148
|
-
this.lastNode = node;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
oncomment(data) {
|
|
152
|
-
if (this.lastNode && this.lastNode.type === ElementType.Comment) {
|
|
153
|
-
this.lastNode.data += data;
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
const node = new Comment(data);
|
|
157
|
-
this.addNode(node);
|
|
158
|
-
this.lastNode = node;
|
|
159
|
-
}
|
|
160
|
-
oncommentend() {
|
|
161
|
-
this.lastNode = null;
|
|
162
|
-
}
|
|
163
|
-
oncdatastart() {
|
|
164
|
-
const text = new Text('');
|
|
165
|
-
const node = new NodeWithChildren(ElementType.CDATA, [text]);
|
|
166
|
-
this.addNode(node);
|
|
167
|
-
text.parent = node;
|
|
168
|
-
this.lastNode = text;
|
|
169
|
-
}
|
|
170
|
-
oncdataend() {
|
|
171
|
-
this.lastNode = null;
|
|
172
|
-
}
|
|
173
|
-
onprocessinginstruction(name, data) {
|
|
174
|
-
const node = new ProcessingInstruction(name, data);
|
|
175
|
-
this.addNode(node);
|
|
176
|
-
}
|
|
177
|
-
handleCallback(error) {
|
|
178
|
-
if (typeof this.callback === 'function') {
|
|
179
|
-
this.callback(error, this.dom);
|
|
180
|
-
}
|
|
181
|
-
else if (error) {
|
|
182
|
-
throw error;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
addNode(node) {
|
|
186
|
-
const parent = this.tagStack[this.tagStack.length - 1];
|
|
187
|
-
const previousSibling = parent.children[parent.children.length - 1];
|
|
188
|
-
if (this.options.withStartIndices) {
|
|
189
|
-
node.startIndex = this.parser.startIndex;
|
|
190
|
-
}
|
|
191
|
-
if (this.options.withEndIndices) {
|
|
192
|
-
node.endIndex = this.parser.endIndex;
|
|
193
|
-
}
|
|
194
|
-
parent.children.push(node);
|
|
195
|
-
if (previousSibling) {
|
|
196
|
-
node.prev = previousSibling;
|
|
197
|
-
previousSibling.next = node;
|
|
198
|
-
}
|
|
199
|
-
node.parent = parent;
|
|
200
|
-
this.lastNode = null;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
export default DomHandler;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { Node } from './Node.js';
|
|
2
|
-
/**
|
|
3
|
-
* Mixed-case SVG and MathML tags & attributes
|
|
4
|
-
* recognized by the HTML parser.
|
|
5
|
-
*
|
|
6
|
-
* @see https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inforeign
|
|
7
|
-
*/
|
|
8
|
-
export declare const elementNames: Map<string, string>;
|
|
9
|
-
export declare const attributeNames: Map<string, string>;
|
|
10
|
-
export interface DomSerializerOptions {
|
|
11
|
-
/**
|
|
12
|
-
* Print an empty attribute's value.
|
|
13
|
-
*
|
|
14
|
-
* @default xmlMode
|
|
15
|
-
* @example With <code>emptyAttrs: false</code>: <code><input checked></code>
|
|
16
|
-
* @example With <code>emptyAttrs: true</code>: <code><input checked=""></code>
|
|
17
|
-
*/
|
|
18
|
-
emptyAttrs?: boolean;
|
|
19
|
-
/**
|
|
20
|
-
* Print self-closing tags for tags without contents.
|
|
21
|
-
*
|
|
22
|
-
* @default xmlMode
|
|
23
|
-
* @example With <code>selfClosingTags: false</code>: <code><foo></foo></code>
|
|
24
|
-
* @example With <code>selfClosingTags: true</code>: <code><foo /></code>
|
|
25
|
-
*/
|
|
26
|
-
selfClosingTags?: boolean;
|
|
27
|
-
/**
|
|
28
|
-
* Treat the input as an XML document; enables the `emptyAttrs` and `selfClosingTags` options.
|
|
29
|
-
*
|
|
30
|
-
* If the value is `"foreign"`, it will try to correct mixed-case attribute names.
|
|
31
|
-
*
|
|
32
|
-
* @default false
|
|
33
|
-
*/
|
|
34
|
-
xmlMode?: boolean | 'foreign';
|
|
35
|
-
/**
|
|
36
|
-
* Encode characters that are either reserved in HTML or XML, or are outside of the ASCII range.
|
|
37
|
-
*
|
|
38
|
-
* @default true
|
|
39
|
-
*/
|
|
40
|
-
decodeEntities?: boolean;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Renders a DOM node or an array of DOM nodes to a string.
|
|
44
|
-
*
|
|
45
|
-
* Can be thought of as the equivalent of the `outerHTML` of the passed node(s).
|
|
46
|
-
*
|
|
47
|
-
* @param node Node to be rendered.
|
|
48
|
-
* @param options Changes serialization behavior
|
|
49
|
-
*/
|
|
50
|
-
export default function render(node: Node | ArrayLike<Node>, options?: DomSerializerOptions): string;
|