update
This commit is contained in:
+4
-2
@@ -1,7 +1,9 @@
|
||||
import Node from './node';
|
||||
import NodeType from './type';
|
||||
import HTMLElement from './html';
|
||||
export default class CommentNode extends Node {
|
||||
constructor(value: string);
|
||||
rawText: string;
|
||||
constructor(rawText: string, parentNode: HTMLElement);
|
||||
/**
|
||||
* Node Type declaration.
|
||||
* @type {Number}
|
||||
@@ -12,5 +14,5 @@ export default class CommentNode extends Node {
|
||||
* @return {string} text content
|
||||
*/
|
||||
get text(): string;
|
||||
toString(): string;
|
||||
toString(): `<!--${string}-->`;
|
||||
}
|
||||
|
||||
+7
-5
@@ -3,10 +3,12 @@ var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
@@ -20,14 +22,14 @@ var node_1 = __importDefault(require("./node"));
|
||||
var type_1 = __importDefault(require("./type"));
|
||||
var CommentNode = /** @class */ (function (_super) {
|
||||
__extends(CommentNode, _super);
|
||||
function CommentNode(value) {
|
||||
var _this = _super.call(this) || this;
|
||||
function CommentNode(rawText, parentNode) {
|
||||
var _this = _super.call(this, parentNode) || this;
|
||||
_this.rawText = rawText;
|
||||
/**
|
||||
* Node Type declaration.
|
||||
* @type {Number}
|
||||
*/
|
||||
_this.nodeType = type_1.default.COMMENT_NODE;
|
||||
_this.rawText = value;
|
||||
return _this;
|
||||
}
|
||||
Object.defineProperty(CommentNode.prototype, "text", {
|
||||
@@ -38,7 +40,7 @@ var CommentNode = /** @class */ (function (_super) {
|
||||
get: function () {
|
||||
return this.rawText;
|
||||
},
|
||||
enumerable: true,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
CommentNode.prototype.toString = function () {
|
||||
|
||||
+59
-29
@@ -1,7 +1,5 @@
|
||||
import Node from './node';
|
||||
import NodeType from './type';
|
||||
import TextNode from './text';
|
||||
import Matcher from '../matcher';
|
||||
export interface KeyAttributes {
|
||||
id?: string;
|
||||
class?: string;
|
||||
@@ -13,6 +11,21 @@ export interface RawAttributes {
|
||||
[key: string]: string;
|
||||
}
|
||||
export declare type InsertPosition = 'beforebegin' | 'afterbegin' | 'beforeend' | 'afterend';
|
||||
declare class DOMTokenList {
|
||||
private _set;
|
||||
private _afterUpdate;
|
||||
private _validate;
|
||||
constructor(valuesInit?: string[], afterUpdate?: ((t: DOMTokenList) => void));
|
||||
add(c: string): void;
|
||||
replace(c1: string, c2: string): void;
|
||||
remove(c: string): void;
|
||||
toggle(c: string): void;
|
||||
contains(c: string): boolean;
|
||||
get length(): number;
|
||||
values(): IterableIterator<string>;
|
||||
get value(): string[];
|
||||
toString(): string;
|
||||
}
|
||||
/**
|
||||
* HTMLElement, which contains a set of children.
|
||||
*
|
||||
@@ -23,17 +36,22 @@ export declare type InsertPosition = 'beforebegin' | 'afterbegin' | 'beforeend'
|
||||
* @extends {Node}
|
||||
*/
|
||||
export default class HTMLElement extends Node {
|
||||
tagName: string;
|
||||
private rawAttrs;
|
||||
parentNode: Node;
|
||||
private _attrs;
|
||||
private _rawAttrs;
|
||||
rawTagName: string;
|
||||
id: string;
|
||||
classNames: string[];
|
||||
classList: DOMTokenList;
|
||||
/**
|
||||
* Node Type declaration.
|
||||
*/
|
||||
nodeType: NodeType;
|
||||
/**
|
||||
* Quote attribute values
|
||||
* @param attr attribute value
|
||||
* @returns {string} quoted value
|
||||
*/
|
||||
private quoteAttribute;
|
||||
/**
|
||||
* Creates an instance of HTMLElement.
|
||||
* @param keyAttrs id and class attribute
|
||||
@@ -41,7 +59,11 @@ export default class HTMLElement extends Node {
|
||||
*
|
||||
* @memberof HTMLElement
|
||||
*/
|
||||
constructor(tagName: string, keyAttrs: KeyAttributes, rawAttrs?: string, parentNode?: Node);
|
||||
constructor(tagName: string, keyAttrs: KeyAttributes, rawAttrs: string, parentNode: HTMLElement | null);
|
||||
/**
|
||||
* Remove current element
|
||||
*/
|
||||
remove(): void;
|
||||
/**
|
||||
* Remove Child element from childNodes array
|
||||
* @param {HTMLElement} node node to remove
|
||||
@@ -53,11 +75,15 @@ export default class HTMLElement extends Node {
|
||||
* @param {HTMLElement} newNode new node
|
||||
*/
|
||||
exchangeChild(oldNode: Node, newNode: Node): void;
|
||||
get tagName(): string;
|
||||
get localName(): string;
|
||||
/**
|
||||
* Get escpaed (as-it) text value of current node and its children.
|
||||
* @return {string} text content
|
||||
*/
|
||||
get rawText(): string;
|
||||
get textContent(): string;
|
||||
set textContent(val: string);
|
||||
/**
|
||||
* Get unescaped text value of current node and its children.
|
||||
* @return {string} text content
|
||||
@@ -70,7 +96,9 @@ export default class HTMLElement extends Node {
|
||||
get structuredText(): string;
|
||||
toString(): string;
|
||||
get innerHTML(): string;
|
||||
set innerHTML(content: string);
|
||||
set_content(content: string | Node | Node[], options?: Options): void;
|
||||
replaceWith(...nodes: (string | Node)[]): void;
|
||||
get outerHTML(): string;
|
||||
/**
|
||||
* Trim element from right (in block) after seeing pattern in a TextNode.
|
||||
@@ -91,17 +119,20 @@ export default class HTMLElement extends Node {
|
||||
/**
|
||||
* Query CSS selector to find matching nodes.
|
||||
* @param {string} selector Simplified CSS selector
|
||||
* @param {Matcher} selector A Matcher instance
|
||||
* @return {HTMLElement[]} matching elements
|
||||
*/
|
||||
querySelectorAll(selector: string | Matcher): HTMLElement[];
|
||||
querySelectorAll(selector: string): HTMLElement[];
|
||||
/**
|
||||
* Query CSS Selector to find matching node.
|
||||
* @param {string} selector Simplified CSS selector
|
||||
* @param {Matcher} selector A Matcher instance
|
||||
* @return {HTMLElement} matching node
|
||||
*/
|
||||
querySelector(selector: string | Matcher): HTMLElement;
|
||||
querySelector(selector: string): HTMLElement;
|
||||
/**
|
||||
* traverses the Element and its parents (heading toward the document root) until it finds a node that matches the provided selector string. Will return itself or the matching ancestor. If no such element exists, it returns null.
|
||||
* @param selector a DOMString containing a selector list
|
||||
*/
|
||||
closest(selector: string): Node;
|
||||
/**
|
||||
* Append a child node to childNodes
|
||||
* @param {Node} node node to append
|
||||
@@ -120,9 +151,11 @@ export default class HTMLElement extends Node {
|
||||
get lastChild(): Node;
|
||||
/**
|
||||
* Get attributes
|
||||
* @access private
|
||||
* @return {Object} parsed and unescaped attributes
|
||||
*/
|
||||
get attributes(): Attributes;
|
||||
get attrs(): Attributes;
|
||||
get attributes(): Record<string, string>;
|
||||
/**
|
||||
* Get escaped (as-it) attributes
|
||||
* @return {Object} parsed attributes
|
||||
@@ -147,13 +180,16 @@ export default class HTMLElement extends Node {
|
||||
*/
|
||||
setAttributes(attributes: Attributes): void;
|
||||
insertAdjacentHTML(where: InsertPosition, html: string): void;
|
||||
get nextSibling(): Node;
|
||||
get nextElementSibling(): HTMLElement;
|
||||
get classNames(): string;
|
||||
}
|
||||
export interface Options {
|
||||
lowerCaseTagName?: boolean;
|
||||
script?: boolean;
|
||||
style?: boolean;
|
||||
pre?: boolean;
|
||||
comment?: boolean;
|
||||
lowerCaseTagName: boolean;
|
||||
comment: boolean;
|
||||
blockTextElements: {
|
||||
[tag: string]: boolean;
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Parses HTML and returns a root element
|
||||
@@ -161,16 +197,10 @@ export interface Options {
|
||||
* @param {string} data html
|
||||
* @return {HTMLElement} root element
|
||||
*/
|
||||
export declare function parse(data: string, options?: Options): HTMLElement & {
|
||||
valid: boolean;
|
||||
};
|
||||
export declare function parse(data: string, options?: Options & {
|
||||
noFix: false;
|
||||
}): HTMLElement & {
|
||||
valid: boolean;
|
||||
};
|
||||
export declare function parse(data: string, options?: Options & {
|
||||
noFix: true;
|
||||
}): (HTMLElement | TextNode) & {
|
||||
valid: boolean;
|
||||
};
|
||||
export declare function base_parse(data: string, options?: Partial<Options>): HTMLElement[];
|
||||
/**
|
||||
* Parses HTML and returns a root element
|
||||
* Parse a chuck of HTML source.
|
||||
*/
|
||||
export declare function parse(data: string, options?: Partial<Options>): HTMLElement;
|
||||
export {};
|
||||
|
||||
+687
-263
File diff suppressed because it is too large
Load Diff
+9
-3
@@ -1,11 +1,17 @@
|
||||
import NodeType from './type';
|
||||
import HTMLElement from './html';
|
||||
/**
|
||||
* Node Class as base class for TextNode and HTMLElement.
|
||||
*/
|
||||
export default abstract class Node {
|
||||
nodeType: NodeType;
|
||||
parentNode: HTMLElement;
|
||||
abstract nodeType: NodeType;
|
||||
childNodes: Node[];
|
||||
text: string;
|
||||
rawText: string;
|
||||
abstract text: string;
|
||||
abstract rawText: string;
|
||||
abstract toString(): string;
|
||||
constructor(parentNode?: HTMLElement);
|
||||
get innerText(): string;
|
||||
get textContent(): string;
|
||||
set textContent(val: string);
|
||||
}
|
||||
|
||||
+20
-1
@@ -4,9 +4,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
* Node Class as base class for TextNode and HTMLElement.
|
||||
*/
|
||||
var Node = /** @class */ (function () {
|
||||
function Node() {
|
||||
function Node(parentNode) {
|
||||
if (parentNode === void 0) { parentNode = null; }
|
||||
this.parentNode = parentNode;
|
||||
this.childNodes = [];
|
||||
}
|
||||
Object.defineProperty(Node.prototype, "innerText", {
|
||||
get: function () {
|
||||
return this.rawText;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Node.prototype, "textContent", {
|
||||
get: function () {
|
||||
return this.rawText;
|
||||
},
|
||||
set: function (val) {
|
||||
this.rawText = val;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
return Node;
|
||||
}());
|
||||
exports.default = Node;
|
||||
|
||||
+8
-1
@@ -1,16 +1,23 @@
|
||||
import NodeType from './type';
|
||||
import Node from './node';
|
||||
import HTMLElement from './html';
|
||||
/**
|
||||
* TextNode to contain a text element in DOM tree.
|
||||
* @param {string} value [description]
|
||||
*/
|
||||
export default class TextNode extends Node {
|
||||
constructor(value: string);
|
||||
rawText: string;
|
||||
constructor(rawText: string, parentNode: HTMLElement);
|
||||
/**
|
||||
* Node Type declaration.
|
||||
* @type {Number}
|
||||
*/
|
||||
nodeType: NodeType;
|
||||
private _trimmedText?;
|
||||
/**
|
||||
* Returns text with all whitespace trimmed except single leading/trailing non-breaking space
|
||||
*/
|
||||
get trimmedText(): string;
|
||||
/**
|
||||
* Get unescaped text value of current node and its children.
|
||||
* @return {string} text content
|
||||
|
||||
+47
-6
@@ -3,10 +3,12 @@ var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
@@ -24,16 +26,55 @@ var node_1 = __importDefault(require("./node"));
|
||||
*/
|
||||
var TextNode = /** @class */ (function (_super) {
|
||||
__extends(TextNode, _super);
|
||||
function TextNode(value) {
|
||||
var _this = _super.call(this) || this;
|
||||
function TextNode(rawText, parentNode) {
|
||||
var _this = _super.call(this, parentNode) || this;
|
||||
_this.rawText = rawText;
|
||||
/**
|
||||
* Node Type declaration.
|
||||
* @type {Number}
|
||||
*/
|
||||
_this.nodeType = type_1.default.TEXT_NODE;
|
||||
_this.rawText = value;
|
||||
return _this;
|
||||
}
|
||||
Object.defineProperty(TextNode.prototype, "trimmedText", {
|
||||
/**
|
||||
* Returns text with all whitespace trimmed except single leading/trailing non-breaking space
|
||||
*/
|
||||
get: function () {
|
||||
if (this._trimmedText !== undefined)
|
||||
return this._trimmedText;
|
||||
var text = this.rawText;
|
||||
var i = 0;
|
||||
var startPos;
|
||||
var endPos;
|
||||
while (i >= 0 && i < text.length) {
|
||||
if (/\S/.test(text[i])) {
|
||||
if (startPos === undefined) {
|
||||
startPos = i;
|
||||
i = text.length;
|
||||
}
|
||||
else {
|
||||
endPos = i;
|
||||
i = void 0;
|
||||
}
|
||||
}
|
||||
if (startPos === undefined)
|
||||
i++;
|
||||
else
|
||||
i--;
|
||||
}
|
||||
if (startPos === undefined)
|
||||
startPos = 0;
|
||||
if (endPos === undefined)
|
||||
endPos = text.length - 1;
|
||||
var hasLeadingSpace = startPos > 0 && /[^\S\r\n]/.test(text[startPos - 1]);
|
||||
var hasTrailingSpace = endPos < (text.length - 1) && /[^\S\r\n]/.test(text[endPos + 1]);
|
||||
this._trimmedText = (hasLeadingSpace ? ' ' : '') + text.slice(startPos, endPos + 1) + (hasTrailingSpace ? ' ' : '');
|
||||
return this._trimmedText;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(TextNode.prototype, "text", {
|
||||
/**
|
||||
* Get unescaped text value of current node and its children.
|
||||
@@ -42,7 +83,7 @@ var TextNode = /** @class */ (function (_super) {
|
||||
get: function () {
|
||||
return this.rawText;
|
||||
},
|
||||
enumerable: true,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(TextNode.prototype, "isWhitespace", {
|
||||
@@ -53,7 +94,7 @@ var TextNode = /** @class */ (function (_super) {
|
||||
get: function () {
|
||||
return /^(\s| )*$/.test(this.rawText);
|
||||
},
|
||||
enumerable: true,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
TextNode.prototype.toString = function () {
|
||||
|
||||
Reference in New Issue
Block a user