@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
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { isTag } from '../Node.js';
|
|
2
|
-
const emptyArray = [];
|
|
3
|
-
/**
|
|
4
|
-
* Get a node's children.
|
|
5
|
-
*
|
|
6
|
-
* @param elem Node to get the children of.
|
|
7
|
-
* @returns `elem`'s children, or an empty array.
|
|
8
|
-
*/
|
|
9
|
-
export function getChildren(elem) {
|
|
10
|
-
return elem.children ?? emptyArray;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Get a node's parent.
|
|
14
|
-
*
|
|
15
|
-
* @param elem Node to get the parent of.
|
|
16
|
-
* @returns `elem`'s parent node.
|
|
17
|
-
*/
|
|
18
|
-
export function getParent(elem) {
|
|
19
|
-
return elem.parent || null;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Gets an elements siblings, including the element itself.
|
|
23
|
-
*
|
|
24
|
-
* Attempts to get the children through the element's parent first.
|
|
25
|
-
* If we don't have a parent (the element is a root node),
|
|
26
|
-
* we walk the element's `prev` & `next` to get all remaining nodes.
|
|
27
|
-
*
|
|
28
|
-
* @param elem Element to get the siblings of.
|
|
29
|
-
* @returns `elem`'s siblings.
|
|
30
|
-
*/
|
|
31
|
-
export function getSiblings(elem) {
|
|
32
|
-
const parent = getParent(elem);
|
|
33
|
-
if (parent != null)
|
|
34
|
-
return getChildren(parent);
|
|
35
|
-
const siblings = [elem];
|
|
36
|
-
let { prev, next } = elem;
|
|
37
|
-
while (prev != null) {
|
|
38
|
-
siblings.unshift(prev);
|
|
39
|
-
({ prev } = prev);
|
|
40
|
-
}
|
|
41
|
-
while (next != null) {
|
|
42
|
-
siblings.push(next);
|
|
43
|
-
({ next } = next);
|
|
44
|
-
}
|
|
45
|
-
return siblings;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Gets an attribute from an element.
|
|
49
|
-
*
|
|
50
|
-
* @param elem Element to check.
|
|
51
|
-
* @param name Attribute name to retrieve.
|
|
52
|
-
* @returns The element's attribute value, or `undefined`.
|
|
53
|
-
*/
|
|
54
|
-
export function getAttributeValue(elem, name) {
|
|
55
|
-
return elem.attribs?.[name];
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Checks whether an element has an attribute.
|
|
59
|
-
*
|
|
60
|
-
* @param elem Element to check.
|
|
61
|
-
* @param name Attribute name to look for.
|
|
62
|
-
* @returns Returns whether `elem` has the attribute `name`.
|
|
63
|
-
*/
|
|
64
|
-
export function hasAttrib(elem, name) {
|
|
65
|
-
return (elem.attribs != null &&
|
|
66
|
-
Object.prototype.hasOwnProperty.call(elem.attribs, name) &&
|
|
67
|
-
elem.attribs[name] != null);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Get the tag name of an element.
|
|
71
|
-
*
|
|
72
|
-
* @param elem The element to get the name for.
|
|
73
|
-
* @returns The tag name of `elem`.
|
|
74
|
-
*/
|
|
75
|
-
export function getName(elem) {
|
|
76
|
-
return elem.name;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Returns the next element sibling of a node.
|
|
80
|
-
*
|
|
81
|
-
* @param elem The element to get the next sibling of.
|
|
82
|
-
* @returns `elem`'s next sibling that is a tag.
|
|
83
|
-
*/
|
|
84
|
-
export function nextElementSibling(elem) {
|
|
85
|
-
let { next } = elem;
|
|
86
|
-
while (next !== null && !isTag(next))
|
|
87
|
-
({ next } = next);
|
|
88
|
-
return next;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Returns the previous element sibling of a node.
|
|
92
|
-
*
|
|
93
|
-
* @param elem The element to get the previous sibling of.
|
|
94
|
-
* @returns `elem`'s previous sibling that is a tag.
|
|
95
|
-
*/
|
|
96
|
-
export function prevElementSibling(elem) {
|
|
97
|
-
let { prev } = elem;
|
|
98
|
-
while (prev !== null && !isTag(prev))
|
|
99
|
-
({ prev } = prev);
|
|
100
|
-
return prev;
|
|
101
|
-
}
|
|
@@ -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,207 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DomHandler = void 0;
|
|
4
|
-
const Node_js_1 = require("./Node.js");
|
|
5
|
-
const ElementType_js_1 = require("./ElementType.js");
|
|
6
|
-
const reWhitespace = /\s+/g;
|
|
7
|
-
// Default options
|
|
8
|
-
const defaultOpts = {
|
|
9
|
-
normalizeWhitespace: false,
|
|
10
|
-
withStartIndices: false,
|
|
11
|
-
withEndIndices: false,
|
|
12
|
-
};
|
|
13
|
-
class DomHandler {
|
|
14
|
-
/**
|
|
15
|
-
* @param callback Called once parsing has completed.
|
|
16
|
-
* @param options Settings for the handler.
|
|
17
|
-
* @param elementCB Callback whenever a tag is closed.
|
|
18
|
-
*/
|
|
19
|
-
constructor(callback, options, elementCB) {
|
|
20
|
-
/** The elements of the DOM */
|
|
21
|
-
Object.defineProperty(this, "dom", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
configurable: true,
|
|
24
|
-
writable: true,
|
|
25
|
-
value: []
|
|
26
|
-
});
|
|
27
|
-
/** The root element for the DOM */
|
|
28
|
-
Object.defineProperty(this, "root", {
|
|
29
|
-
enumerable: true,
|
|
30
|
-
configurable: true,
|
|
31
|
-
writable: true,
|
|
32
|
-
value: new Node_js_1.Document(this.dom)
|
|
33
|
-
});
|
|
34
|
-
/** Called once parsing has completed. */
|
|
35
|
-
Object.defineProperty(this, "callback", {
|
|
36
|
-
enumerable: true,
|
|
37
|
-
configurable: true,
|
|
38
|
-
writable: true,
|
|
39
|
-
value: void 0
|
|
40
|
-
});
|
|
41
|
-
/** Settings for the handler. */
|
|
42
|
-
Object.defineProperty(this, "options", {
|
|
43
|
-
enumerable: true,
|
|
44
|
-
configurable: true,
|
|
45
|
-
writable: true,
|
|
46
|
-
value: void 0
|
|
47
|
-
});
|
|
48
|
-
/** Callback whenever a tag is closed. */
|
|
49
|
-
Object.defineProperty(this, "elementCB", {
|
|
50
|
-
enumerable: true,
|
|
51
|
-
configurable: true,
|
|
52
|
-
writable: true,
|
|
53
|
-
value: void 0
|
|
54
|
-
});
|
|
55
|
-
/** Indicated whether parsing has been completed. */
|
|
56
|
-
Object.defineProperty(this, "done", {
|
|
57
|
-
enumerable: true,
|
|
58
|
-
configurable: true,
|
|
59
|
-
writable: true,
|
|
60
|
-
value: false
|
|
61
|
-
});
|
|
62
|
-
/** Stack of open tags. */
|
|
63
|
-
Object.defineProperty(this, "tagStack", {
|
|
64
|
-
enumerable: true,
|
|
65
|
-
configurable: true,
|
|
66
|
-
writable: true,
|
|
67
|
-
value: [this.root]
|
|
68
|
-
});
|
|
69
|
-
/** A data node that is still being written to. */
|
|
70
|
-
Object.defineProperty(this, "lastNode", {
|
|
71
|
-
enumerable: true,
|
|
72
|
-
configurable: true,
|
|
73
|
-
writable: true,
|
|
74
|
-
value: null
|
|
75
|
-
});
|
|
76
|
-
/** Reference to the parser instance. Used for location information. */
|
|
77
|
-
Object.defineProperty(this, "parser", {
|
|
78
|
-
enumerable: true,
|
|
79
|
-
configurable: true,
|
|
80
|
-
writable: true,
|
|
81
|
-
value: null
|
|
82
|
-
});
|
|
83
|
-
// Make it possible to skip arguments, for backwards-compatibility
|
|
84
|
-
if (typeof options === 'function') {
|
|
85
|
-
elementCB = options;
|
|
86
|
-
options = defaultOpts;
|
|
87
|
-
}
|
|
88
|
-
if (typeof callback === 'object') {
|
|
89
|
-
options = callback;
|
|
90
|
-
callback = undefined;
|
|
91
|
-
}
|
|
92
|
-
this.callback = callback ?? null;
|
|
93
|
-
this.options = options ?? defaultOpts;
|
|
94
|
-
this.elementCB = elementCB ?? null;
|
|
95
|
-
}
|
|
96
|
-
onparserinit(parser) {
|
|
97
|
-
this.parser = parser;
|
|
98
|
-
}
|
|
99
|
-
// Resets the handler back to starting state
|
|
100
|
-
onreset() {
|
|
101
|
-
this.dom = [];
|
|
102
|
-
this.root = new Node_js_1.Document(this.dom);
|
|
103
|
-
this.done = false;
|
|
104
|
-
this.tagStack = [this.root];
|
|
105
|
-
this.lastNode = null;
|
|
106
|
-
this.parser = this.parser ?? null;
|
|
107
|
-
}
|
|
108
|
-
// Signals the handler that parsing is done
|
|
109
|
-
onend() {
|
|
110
|
-
if (this.done)
|
|
111
|
-
return;
|
|
112
|
-
this.done = true;
|
|
113
|
-
this.parser = null;
|
|
114
|
-
this.handleCallback(null);
|
|
115
|
-
}
|
|
116
|
-
onerror(error) {
|
|
117
|
-
this.handleCallback(error);
|
|
118
|
-
}
|
|
119
|
-
onclosetag() {
|
|
120
|
-
this.lastNode = null;
|
|
121
|
-
const elem = this.tagStack.pop();
|
|
122
|
-
if (this.options.withEndIndices) {
|
|
123
|
-
elem.endIndex = this.parser.endIndex;
|
|
124
|
-
}
|
|
125
|
-
if (this.elementCB)
|
|
126
|
-
this.elementCB(elem);
|
|
127
|
-
}
|
|
128
|
-
onopentag(name, attribs) {
|
|
129
|
-
const type = this.options.xmlMode ? ElementType_js_1.ElementType.Tag : undefined;
|
|
130
|
-
const element = new Node_js_1.Element(name, attribs, undefined, type);
|
|
131
|
-
this.addNode(element);
|
|
132
|
-
this.tagStack.push(element);
|
|
133
|
-
}
|
|
134
|
-
ontext(data) {
|
|
135
|
-
const { normalizeWhitespace } = this.options;
|
|
136
|
-
const { lastNode } = this;
|
|
137
|
-
if (lastNode && lastNode.type === ElementType_js_1.ElementType.Text) {
|
|
138
|
-
if (normalizeWhitespace) {
|
|
139
|
-
lastNode.data = (lastNode.data + data).replace(reWhitespace, ' ');
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
lastNode.data += data;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
if (normalizeWhitespace) {
|
|
147
|
-
data = data.replace(reWhitespace, ' ');
|
|
148
|
-
}
|
|
149
|
-
const node = new Node_js_1.Text(data);
|
|
150
|
-
this.addNode(node);
|
|
151
|
-
this.lastNode = node;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
oncomment(data) {
|
|
155
|
-
if (this.lastNode && this.lastNode.type === ElementType_js_1.ElementType.Comment) {
|
|
156
|
-
this.lastNode.data += data;
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
const node = new Node_js_1.Comment(data);
|
|
160
|
-
this.addNode(node);
|
|
161
|
-
this.lastNode = node;
|
|
162
|
-
}
|
|
163
|
-
oncommentend() {
|
|
164
|
-
this.lastNode = null;
|
|
165
|
-
}
|
|
166
|
-
oncdatastart() {
|
|
167
|
-
const text = new Node_js_1.Text('');
|
|
168
|
-
const node = new Node_js_1.NodeWithChildren(ElementType_js_1.ElementType.CDATA, [text]);
|
|
169
|
-
this.addNode(node);
|
|
170
|
-
text.parent = node;
|
|
171
|
-
this.lastNode = text;
|
|
172
|
-
}
|
|
173
|
-
oncdataend() {
|
|
174
|
-
this.lastNode = null;
|
|
175
|
-
}
|
|
176
|
-
onprocessinginstruction(name, data) {
|
|
177
|
-
const node = new Node_js_1.ProcessingInstruction(name, data);
|
|
178
|
-
this.addNode(node);
|
|
179
|
-
}
|
|
180
|
-
handleCallback(error) {
|
|
181
|
-
if (typeof this.callback === 'function') {
|
|
182
|
-
this.callback(error, this.dom);
|
|
183
|
-
}
|
|
184
|
-
else if (error) {
|
|
185
|
-
throw error;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
addNode(node) {
|
|
189
|
-
const parent = this.tagStack[this.tagStack.length - 1];
|
|
190
|
-
const previousSibling = parent.children[parent.children.length - 1];
|
|
191
|
-
if (this.options.withStartIndices) {
|
|
192
|
-
node.startIndex = this.parser.startIndex;
|
|
193
|
-
}
|
|
194
|
-
if (this.options.withEndIndices) {
|
|
195
|
-
node.endIndex = this.parser.endIndex;
|
|
196
|
-
}
|
|
197
|
-
parent.children.push(node);
|
|
198
|
-
if (previousSibling) {
|
|
199
|
-
node.prev = previousSibling;
|
|
200
|
-
previousSibling.next = node;
|
|
201
|
-
}
|
|
202
|
-
node.parent = parent;
|
|
203
|
-
this.lastNode = null;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
exports.DomHandler = DomHandler;
|
|
207
|
-
exports.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;
|