You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
193 lines
5.9 KiB
193 lines
5.9 KiB
"use strict";
|
|
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]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
var nodeTypes = new Map([
|
|
["tag" /* Tag */, 1],
|
|
["script" /* Script */, 1],
|
|
["style" /* Style */, 1],
|
|
["directive" /* Directive */, 1],
|
|
["text" /* Text */, 3],
|
|
["cdata" /* CDATA */, 4],
|
|
["comment" /* Comment */, 8]
|
|
]);
|
|
// This object will be used as the prototype for Nodes when creating a
|
|
// DOM-Level-1-compliant structure.
|
|
var Node = /** @class */ (function () {
|
|
/**
|
|
*
|
|
* @param type The type of the node.
|
|
*/
|
|
function Node(type) {
|
|
this.type = type;
|
|
/** Parent of the node */
|
|
this.parent = null;
|
|
/** Previous sibling */
|
|
this.prev = null;
|
|
/** Next sibling */
|
|
this.next = null;
|
|
/** The start index of the node. Requires `withStartIndices` on the handler to be `true. */
|
|
this.startIndex = null;
|
|
/** The end index of the node. Requires `withEndIndices` on the handler to be `true. */
|
|
this.endIndex = null;
|
|
}
|
|
Object.defineProperty(Node.prototype, "nodeType", {
|
|
// Read-only aliases
|
|
get: function () {
|
|
return nodeTypes.get(this.type) || 1;
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
Object.defineProperty(Node.prototype, "parentNode", {
|
|
// Read-write aliases for properties
|
|
get: function () {
|
|
return this.parent || null;
|
|
},
|
|
set: function (parent) {
|
|
this.parent = parent;
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
Object.defineProperty(Node.prototype, "previousSibling", {
|
|
get: function () {
|
|
return this.prev || null;
|
|
},
|
|
set: function (prev) {
|
|
this.prev = prev;
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
Object.defineProperty(Node.prototype, "nextSibling", {
|
|
get: function () {
|
|
return this.next || null;
|
|
},
|
|
set: function (next) {
|
|
this.next = next;
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
return Node;
|
|
}());
|
|
exports.Node = Node;
|
|
var DataNode = /** @class */ (function (_super) {
|
|
__extends(DataNode, _super);
|
|
/**
|
|
*
|
|
* @param type The type of the node
|
|
* @param data The content of the data node
|
|
*/
|
|
function DataNode(type, data) {
|
|
var _this = _super.call(this, type) || this;
|
|
_this.data = data;
|
|
return _this;
|
|
}
|
|
Object.defineProperty(DataNode.prototype, "nodeValue", {
|
|
get: function () {
|
|
return this.data;
|
|
},
|
|
set: function (data) {
|
|
this.data = data;
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
return DataNode;
|
|
}(Node));
|
|
exports.DataNode = DataNode;
|
|
var ProcessingInstruction = /** @class */ (function (_super) {
|
|
__extends(ProcessingInstruction, _super);
|
|
function ProcessingInstruction(name, data) {
|
|
var _this = _super.call(this, "directive" /* Directive */, data) || this;
|
|
_this.name = name;
|
|
return _this;
|
|
}
|
|
return ProcessingInstruction;
|
|
}(DataNode));
|
|
exports.ProcessingInstruction = ProcessingInstruction;
|
|
var NodeWithChildren = /** @class */ (function (_super) {
|
|
__extends(NodeWithChildren, _super);
|
|
/**
|
|
*
|
|
* @param type Type of the node.
|
|
* @param children Children of the node. Only certain node types can have children.
|
|
*/
|
|
function NodeWithChildren(type, children) {
|
|
var _this = _super.call(this, type) || this;
|
|
_this.children = children;
|
|
return _this;
|
|
}
|
|
Object.defineProperty(NodeWithChildren.prototype, "firstChild", {
|
|
// Aliases
|
|
get: function () {
|
|
return this.children[0] || null;
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
Object.defineProperty(NodeWithChildren.prototype, "lastChild", {
|
|
get: function () {
|
|
return this.children[this.children.length - 1] || null;
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
Object.defineProperty(NodeWithChildren.prototype, "childNodes", {
|
|
get: function () {
|
|
return this.children;
|
|
},
|
|
set: function (children) {
|
|
this.children = children;
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
return NodeWithChildren;
|
|
}(Node));
|
|
exports.NodeWithChildren = NodeWithChildren;
|
|
var Element = /** @class */ (function (_super) {
|
|
__extends(Element, _super);
|
|
/**
|
|
*
|
|
* @param name Name of the tag, eg. `div`, `span`
|
|
* @param attribs Object mapping attribute names to attribute values
|
|
*/
|
|
function Element(name, attribs) {
|
|
var _this = _super.call(this, name === "script"
|
|
? "script" /* Script */
|
|
: name === "style"
|
|
? "style" /* Style */
|
|
: "tag" /* Tag */, []) || this;
|
|
_this.name = name;
|
|
_this.attribs = attribs;
|
|
_this.attribs = attribs;
|
|
return _this;
|
|
}
|
|
Object.defineProperty(Element.prototype, "tagName", {
|
|
// DOM Level 1 aliases
|
|
get: function () {
|
|
return this.name;
|
|
},
|
|
set: function (name) {
|
|
this.name = name;
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
return Element;
|
|
}(NodeWithChildren));
|
|
exports.Element = Element;
|