Socket
Socket
Sign inDemoInstall

simple-dom

Package Overview
Dependencies
0
Maintainers
6
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.1 to 1.2.0

lib/simple-dom.d.ts

889

dist/simple-dom.js

@@ -7,527 +7,504 @@ (function (global, factory) {

function Node(nodeType, nodeName, nodeValue) {
this.nodeType = nodeType;
this.nodeName = nodeName;
this.nodeValue = nodeValue;
this.childNodes = new ChildNodes(this);
this.parentNode = null;
this.previousSibling = null;
this.nextSibling = null;
this.firstChild = null;
this.lastChild = null;
}
Node.prototype._cloneNode = function() {
return new Node(this.nodeType, this.nodeName, this.nodeValue);
var Node = function Node(nodeType, nodeName, nodeValue) {
this.nodeType = nodeType;
this.nodeName = nodeName;
this.nodeValue = nodeValue;
this.parentNode = null;
this.previousSibling = null;
this.nextSibling = null;
this.firstChild = null;
this.lastChild = null;
this._childNodes = undefined;
};
Node.prototype.cloneNode = function(deep) {
var node = this._cloneNode();
if (deep) {
var child = this.firstChild, nextChild = child;
while (nextChild) {
nextChild = child.nextSibling;
node.appendChild(child.cloneNode(true));
child = nextChild;
var prototypeAccessors = { childNodes: { configurable: true } };
prototypeAccessors.childNodes.get = function () {
var children = this._childNodes;
if (children === undefined) {
children = this._childNodes = new ChildNodes(this);
}
}
return node;
return children;
};
Node.prototype.appendChild = function(node) {
if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
insertFragment(node, this, this.lastChild, null);
Node.prototype.cloneNode = function cloneNode (deep) {
var node = this._cloneNode();
if (deep) {
var child = this.firstChild;
var nextChild = child;
while (child !== null) {
nextChild = child.nextSibling;
node.appendChild(child.cloneNode(true));
child = nextChild;
}
}
return node;
}
if (node.parentNode) { node.parentNode.removeChild(node); }
node.parentNode = this;
var refNode = this.lastChild;
if (refNode === null) {
this.firstChild = node;
this.lastChild = node;
} else {
node.previousSibling = refNode;
refNode.nextSibling = node;
this.lastChild = node;
}
return node;
};
function insertFragment(fragment, newParent, before, after) {
if (!fragment.firstChild) { return; }
var firstChild = fragment.firstChild;
var lastChild = firstChild;
var node = firstChild;
firstChild.previousSibling = before;
if (before) {
before.nextSibling = firstChild;
} else {
newParent.firstChild = firstChild;
}
while (node) {
node.parentNode = newParent;
lastChild = node;
node = node.nextSibling;
}
lastChild.nextSibling = after;
if (after) {
after.previousSibling = lastChild;
} else {
newParent.lastChild = lastChild;
}
}
Node.prototype.insertBefore = function(node, refNode) {
if (refNode == null) {
return this.appendChild(node);
}
if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
insertFragment(node, this, refNode ? refNode.previousSibling : null, refNode);
return;
}
if (node.parentNode) { node.parentNode.removeChild(node); }
node.parentNode = this;
var previousSibling = refNode.previousSibling;
if (previousSibling) {
previousSibling.nextSibling = node;
node.previousSibling = previousSibling;
} else {
node.previousSibling = null;
}
refNode.previousSibling = node;
node.nextSibling = refNode;
if (this.firstChild === refNode) {
this.firstChild = node;
}
Node.prototype.appendChild = function appendChild (node) {
if (node.nodeType === 11 /* DOCUMENT_FRAGMENT_NODE */) {
insertFragment(node, this, this.lastChild, null);
return node;
}
if (node.parentNode) {
node.parentNode.removeChild(node);
}
node.parentNode = this;
var refNode = this.lastChild;
if (refNode === null) {
this.firstChild = node;
this.lastChild = node;
}
else {
node.previousSibling = refNode;
refNode.nextSibling = node;
this.lastChild = node;
}
return node;
};
Node.prototype.removeChild = function(refNode) {
if (this.firstChild === refNode) {
this.firstChild = refNode.nextSibling;
}
if (this.lastChild === refNode) {
this.lastChild = refNode.previousSibling;
}
if (refNode.previousSibling) {
refNode.previousSibling.nextSibling = refNode.nextSibling;
}
if (refNode.nextSibling) {
refNode.nextSibling.previousSibling = refNode.previousSibling;
}
refNode.parentNode = null;
refNode.nextSibling = null;
refNode.previousSibling = null;
Node.prototype.insertBefore = function insertBefore (node, refNode) {
if (refNode == null) {
return this.appendChild(node);
}
if (node.nodeType === 11 /* DOCUMENT_FRAGMENT_NODE */) {
insertFragment(node, this, refNode ? refNode.previousSibling : null, refNode);
return;
}
if (node.parentNode) {
node.parentNode.removeChild(node);
}
node.parentNode = this;
var previousSibling = refNode.previousSibling;
if (previousSibling) {
previousSibling.nextSibling = node;
node.previousSibling = previousSibling;
}
else {
node.previousSibling = null;
}
refNode.previousSibling = node;
node.nextSibling = refNode;
if (this.firstChild === refNode) {
this.firstChild = node;
}
};
Node.ELEMENT_NODE = 1;
Node.ATTRIBUTE_NODE = 2;
Node.TEXT_NODE = 3;
Node.CDATA_SECTION_NODE = 4;
Node.ENTITY_REFERENCE_NODE = 5;
Node.ENTITY_NODE = 6;
Node.PROCESSING_INSTRUCTION_NODE = 7;
Node.COMMENT_NODE = 8;
Node.DOCUMENT_NODE = 9;
Node.DOCUMENT_TYPE_NODE = 10;
Node.DOCUMENT_FRAGMENT_NODE = 11;
Node.NOTATION_NODE = 12;
function ChildNodes(node) {
this.node = node;
}
ChildNodes.prototype.item = function(index) {
var child = this.node.firstChild;
for (var i = 0; child && index !== i; i++) {
child = child.nextSibling;
}
return child;
Node.prototype.removeChild = function removeChild (refNode) {
if (this.firstChild === refNode) {
this.firstChild = refNode.nextSibling;
}
if (this.lastChild === refNode) {
this.lastChild = refNode.previousSibling;
}
if (refNode.previousSibling) {
refNode.previousSibling.nextSibling = refNode.nextSibling;
}
if (refNode.nextSibling) {
refNode.nextSibling.previousSibling = refNode.previousSibling;
}
refNode.parentNode = null;
refNode.nextSibling = null;
refNode.previousSibling = null;
};
Node.prototype._cloneNode = function _cloneNode () {
return new Node(this.nodeType, this.nodeName, this.nodeValue);
};
function Element(tagName) {
tagName = tagName.toUpperCase();
Object.defineProperties( Node.prototype, prototypeAccessors );
this.nodeConstructor(1, tagName, null);
this.attributes = [];
this.tagName = tagName;
Node.ELEMENT_NODE = 1 /* ELEMENT_NODE */;
Node.ATTRIBUTE_NODE = 2 /* ATTRIBUTE_NODE */;
Node.TEXT_NODE = 3 /* TEXT_NODE */;
Node.CDATA_SECTION_NODE = 4 /* CDATA_SECTION_NODE */;
Node.ENTITY_REFERENCE_NODE = 5 /* ENTITY_REFERENCE_NODE */;
Node.ENTITY_NODE = 6 /* ENTITY_NODE */;
Node.PROCESSING_INSTRUCTION_NODE = 7 /* PROCESSING_INSTRUCTION_NODE */;
Node.COMMENT_NODE = 8 /* COMMENT_NODE */;
Node.DOCUMENT_NODE = 9 /* DOCUMENT_NODE */;
Node.DOCUMENT_TYPE_NODE = 10 /* DOCUMENT_TYPE_NODE */;
Node.DOCUMENT_FRAGMENT_NODE = 11 /* DOCUMENT_FRAGMENT_NODE */;
Node.NOTATION_NODE = 12 /* NOTATION_NODE */;
function insertFragment(fragment, newParent, before, after) {
if (!fragment.firstChild) {
return;
}
var firstChild = fragment.firstChild;
var lastChild = firstChild;
var node = firstChild;
firstChild.previousSibling = before;
if (before) {
before.nextSibling = firstChild;
}
else {
newParent.firstChild = firstChild;
}
while (node) {
node.parentNode = newParent;
lastChild = node;
node = node.nextSibling;
}
lastChild.nextSibling = after;
if (after) {
after.previousSibling = lastChild;
}
else {
newParent.lastChild = lastChild;
}
}
Element.prototype = Object.create(Node.prototype);
Element.prototype.constructor = Element;
Element.prototype.nodeConstructor = Node;
Element.prototype._cloneNode = function() {
var node = new Element(this.tagName);
node.attributes = this.attributes.map(function(attr) {
return { name: attr.name, value: attr.value, specified: attr.specified };
});
return node;
var ChildNodes = function ChildNodes(node) {
this.node = node;
};
Element.prototype.getAttribute = function(_name) {
var attributes = this.attributes;
var name = _name.toLowerCase();
var attr;
for (var i=0, l=attributes.length; i<l; i++) {
attr = attributes[i];
if (attr.name === name) {
return attr.value;
ChildNodes.prototype.item = function item (index) {
var child = this.node.firstChild;
for (var i = 0; child && index !== i; i++) {
child = child.nextSibling;
}
}
return '';
return child;
};
Element.prototype.setAttribute = function(_name, _value) {
var attributes = this.attributes;
var name = _name.toLowerCase();
var value;
if (typeof _value === 'string') {
value = _value;
} else {
value = '' + _value;
}
var attr;
for (var i=0, l=attributes.length; i<l; i++) {
attr = attributes[i];
if (attr.name === name) {
attr.value = value;
return;
var Element = (function (Node$$1) {
function Element(tagName) {
Node$$1.call(this, 1 /* ELEMENT_NODE */, tagName.toUpperCase(), null);
this.attributes = [];
this.tagName = this.nodeName;
}
}
attributes.push({
name: name,
value: value,
specified: true // serializer compat with old IE
});
};
Element.prototype.removeAttribute = function(name) {
var attributes = this.attributes;
for (var i=0, l=attributes.length; i<l; i++) {
var attr = attributes[i];
if (attr.name === name) {
attributes.splice(i, 1);
return;
}
}
};
if ( Node$$1 ) Element.__proto__ = Node$$1;
Element.prototype = Object.create( Node$$1 && Node$$1.prototype );
Element.prototype.constructor = Element;
Element.prototype.getAttribute = function getAttribute (name) {
var attributes = this.attributes;
var n = name.toLowerCase();
var attr;
for (var i = 0, l = attributes.length; i < l; i++) {
attr = attributes[i];
if (attr.name === n) {
return attr.value;
}
}
return '';
};
Element.prototype.setAttribute = function setAttribute (name, value) {
var attributes = this.attributes;
var n = name.toLowerCase();
var v;
if (typeof value === 'string') {
v = value;
}
else {
v = '' + value;
}
var attr;
for (var i = 0, l = attributes.length; i < l; i++) {
attr = attributes[i];
if (attr.name === n) {
attr.value = v;
return;
}
}
attributes.push({
name: n,
specified: true,
value: v,
});
};
Element.prototype.removeAttribute = function removeAttribute (name) {
var n = name.toLowerCase();
var attributes = this.attributes;
for (var i = 0, l = attributes.length; i < l; i++) {
var attr = attributes[i];
if (attr.name === n) {
attributes.splice(i, 1);
return;
}
}
};
Element.prototype._cloneNode = function _cloneNode () {
var this$1 = this;
function DocumentFragment() {
this.nodeConstructor(11, '#document-fragment', null);
}
var node = new Element(this.tagName);
var attrs = node.attributes = [];
for (var i = 0, list = this$1.attributes; i < list.length; i += 1) {
var attr = list[i];
DocumentFragment.prototype._cloneNode = function() {
return new DocumentFragment();
};
attrs.push({ name: attr.name, specified: attr.specified, value: attr.value });
}
return node;
};
DocumentFragment.prototype = Object.create(Node.prototype);
DocumentFragment.prototype.constructor = DocumentFragment;
DocumentFragment.prototype.nodeConstructor = Node;
return Element;
}(Node));
function Text(text) {
this.nodeConstructor(3, '#text', text);
}
var DocumentFragment = (function (Node$$1) {
function DocumentFragment() {
Node$$1.call(this, 11 /* DOCUMENT_FRAGMENT_NODE */, '#document-fragment', null);
}
Text.prototype._cloneNode = function() {
return new Text(this.nodeValue);
};
if ( Node$$1 ) DocumentFragment.__proto__ = Node$$1;
DocumentFragment.prototype = Object.create( Node$$1 && Node$$1.prototype );
DocumentFragment.prototype.constructor = DocumentFragment;
DocumentFragment.prototype._cloneNode = function _cloneNode () {
return new DocumentFragment();
};
Text.prototype = Object.create(Node.prototype);
Text.prototype.constructor = Text;
Text.prototype.nodeConstructor = Node;
return DocumentFragment;
}(Node));
function Comment(text) {
this.nodeConstructor(8, '#comment', text);
}
var Comment = (function (Node$$1) {
function Comment(text) {
Node$$1.call(this, 8 /* COMMENT_NODE */, '#comment', text);
}
Comment.prototype._cloneNode = function() {
return new Comment(this.nodeValue);
};
if ( Node$$1 ) Comment.__proto__ = Node$$1;
Comment.prototype = Object.create( Node$$1 && Node$$1.prototype );
Comment.prototype.constructor = Comment;
Comment.prototype._cloneNode = function _cloneNode () {
return new Comment(this.nodeValue);
};
Comment.prototype = Object.create(Node.prototype);
Comment.prototype.constructor = Comment;
Comment.prototype.nodeConstructor = Node;
return Comment;
}(Node));
function RawHTMLSection(text) {
this.nodeConstructor(-1, "#raw-html-section", text);
}
var RawHTMLSection = (function (Node$$1) {
function RawHTMLSection(text) {
Node$$1.call(this, -1 /* RAW */, "#raw-html-section", text);
}
RawHTMLSection.prototype = Object.create(Node.prototype);
RawHTMLSection.prototype.constructor = RawHTMLSection;
RawHTMLSection.prototype.nodeConstructor = Node;
if ( Node$$1 ) RawHTMLSection.__proto__ = Node$$1;
RawHTMLSection.prototype = Object.create( Node$$1 && Node$$1.prototype );
RawHTMLSection.prototype.constructor = RawHTMLSection;
function Document() {
this.nodeConstructor(9, '#document', null);
this.documentElement = new Element('html');
this.head = new Element('head');
this.body = new Element('body');
this.documentElement.appendChild(this.head);
this.documentElement.appendChild(this.body);
this.appendChild(this.documentElement);
}
return RawHTMLSection;
}(Node));
Document.prototype = Object.create(Node.prototype);
Document.prototype.constructor = Document;
Document.prototype.nodeConstructor = Node;
var Text = (function (Node$$1) {
function Text(text) {
Node$$1.call(this, 3 /* TEXT_NODE */, '#text', text);
}
Document.prototype.createElement = function(tagName) {
return new Element(tagName);
};
if ( Node$$1 ) Text.__proto__ = Node$$1;
Text.prototype = Object.create( Node$$1 && Node$$1.prototype );
Text.prototype.constructor = Text;
Text.prototype._cloneNode = function _cloneNode () {
return new Text(this.nodeValue);
};
Document.prototype.createTextNode = function(text) {
return new Text(text);
};
return Text;
}(Node));
Document.prototype.createComment = function(text) {
return new Comment(text);
};
var Document = (function (Node$$1) {
function Document() {
Node$$1.call(this, 9, '#document', null);
this.documentElement = new Element('html');
this.head = new Element('head');
this.body = new Element('body');
this.documentElement.appendChild(this.head);
this.documentElement.appendChild(this.body);
this.appendChild(this.documentElement);
}
Document.prototype.createRawHTMLSection = function(text) {
return new RawHTMLSection(text);
};
if ( Node$$1 ) Document.__proto__ = Node$$1;
Document.prototype = Object.create( Node$$1 && Node$$1.prototype );
Document.prototype.constructor = Document;
Document.prototype.createElement = function createElement (tagName) {
return new Element(tagName);
};
Document.prototype.createTextNode = function createTextNode (text) {
return new Text(text);
};
Document.prototype.createComment = function createComment (text) {
return new Comment(text);
};
Document.prototype.createRawHTMLSection = function createRawHTMLSection (text) {
return new RawHTMLSection(text);
};
Document.prototype.createDocumentFragment = function createDocumentFragment () {
return new DocumentFragment();
};
Document.prototype.createDocumentFragment = function() {
return new DocumentFragment();
};
return Document;
}(Node));
function HTMLParser(tokenize, document, voidMap) {
this.tokenize = tokenize;
this.document = document;
this.voidMap = voidMap;
this.parentStack = [];
}
HTMLParser.prototype.isVoid = function(element) {
return this.voidMap[element.nodeName] === true;
var HTMLParser = function HTMLParser(tokenize, document, voidMap) {
this.tokenize = tokenize;
this.document = document;
this.voidMap = voidMap;
this.tokenize = tokenize;
this.document = document;
this.voidMap = voidMap;
this.parentStack = [];
};
HTMLParser.prototype.pushElement = function(token) {
var el = this.document.createElement(token.tagName);
for (var i=0;i<token.attributes.length;i++) {
var attr = token.attributes[i];
el.setAttribute(attr[0], attr[1]);
}
if (this.isVoid(el)) {
return this.appendChild(el);
}
this.parentStack.push(el);
HTMLParser.prototype.isVoid = function isVoid (element) {
return this.voidMap[element.nodeName] === true;
};
HTMLParser.prototype.pushElement = function pushElement (token) {
var el = this.document.createElement(token.tagName);
for (var i = 0, list = token.attributes; i < list.length; i += 1) {
var attr = list[i];
HTMLParser.prototype.popElement = function(token) {
var el = this.parentStack.pop();
if (el.nodeName !== token.tagName.toUpperCase()) {
throw new Error('unbalanced tag');
}
this.appendChild(el);
el.setAttribute(attr[0], attr[1]);
}
if (this.isVoid(el)) {
return this.appendChild(el);
}
this.parentStack.push(el);
};
HTMLParser.prototype.appendText = function(token) {
var text = this.document.createTextNode(token.chars);
this.appendChild(text);
HTMLParser.prototype.popElement = function popElement (token) {
var el = this.parentStack.pop();
if (el.nodeName !== token.tagName.toUpperCase()) {
throw new Error('unbalanced tag');
}
this.appendChild(el);
};
HTMLParser.prototype.appendComment = function(token) {
var comment = this.document.createComment(token.chars);
this.appendChild(comment);
HTMLParser.prototype.appendText = function appendText (token) {
this.appendChild(this.document.createTextNode(token.chars));
};
HTMLParser.prototype.appendChild = function(node) {
var parentNode = this.parentStack[this.parentStack.length-1];
parentNode.appendChild(node);
HTMLParser.prototype.appendComment = function appendComment (token) {
this.appendChild(this.document.createComment(token.chars));
};
HTMLParser.prototype.appendChild = function appendChild (node) {
var parentNode = this.parentStack[this.parentStack.length - 1];
parentNode.appendChild(node);
};
HTMLParser.prototype.parse = function parse (html) {
var this$1 = this;
HTMLParser.prototype.parse = function(html/*, context*/) {
// TODO use context for namespaceURI issues
var fragment = this.document.createDocumentFragment();
this.parentStack.push(fragment);
var tokens = this.tokenize(html);
for (var i=0, l=tokens.length; i<l; i++) {
var token = tokens[i];
switch (token.type) {
case 'StartTag':
this.pushElement(token);
break;
case 'EndTag':
this.popElement(token);
break;
case 'Chars':
this.appendText(token);
break;
case 'Comment':
this.appendComment(token);
break;
var fragment = this.document.createDocumentFragment();
this.parentStack.push(fragment);
var tokens = this.tokenize(html);
for (var i = 0, l = tokens.length; i < l; i++) {
var token = tokens[i];
switch (token.type) {
case 'StartTag':
this$1.pushElement(token);
break;
case 'EndTag':
this$1.popElement(token);
break;
case 'Chars':
this$1.appendText(token);
break;
case 'Comment':
this$1.appendComment(token);
break;
}
}
}
return this.parentStack.pop();
return this.parentStack.pop();
};
var ESC = {
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
'&': '&amp;'
'"': '&quot;',
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
};
function matcher(char) {
if (ESC[char] === undefined) {
return char;
}
return ESC[char];
if (ESC[char] === undefined) {
return char;
}
return ESC[char];
}
function HTMLSerializer(voidMap) {
this.voidMap = voidMap;
}
HTMLSerializer.prototype.openTag = function(element) {
return '<' + element.nodeName.toLowerCase() + this.attributes(element.attributes) + '>';
var HTMLSerializer = function HTMLSerializer(voidMap) {
this.voidMap = voidMap;
};
HTMLSerializer.prototype.closeTag = function(element) {
return '</' + element.nodeName.toLowerCase() + '>';
HTMLSerializer.prototype.openTag = function openTag (element) {
return '<' + element.nodeName.toLowerCase() + this.attributes(element.attributes) + '>';
};
HTMLSerializer.prototype.isVoid = function(element) {
return this.voidMap[element.nodeName] === true;
HTMLSerializer.prototype.closeTag = function closeTag (element) {
return '</' + element.nodeName.toLowerCase() + '>';
};
HTMLSerializer.prototype.attributes = function(namedNodeMap) {
var buffer = '';
for (var i=0, l=namedNodeMap.length; i<l; i++) {
buffer += this.attr(namedNodeMap[i]);
}
return buffer;
HTMLSerializer.prototype.isVoid = function isVoid (element) {
return this.voidMap[element.nodeName] === true;
};
HTMLSerializer.prototype.attributes = function attributes (namedNodeMap) {
var this$1 = this;
HTMLSerializer.prototype.escapeAttrValue = function(attrValue) {
if (attrValue.indexOf('&') > -1 || attrValue.indexOf('"') > -1) {
return attrValue.replace(/[&"]/g, matcher);
}
return attrValue;
var buffer = '';
for (var i = 0, l = namedNodeMap.length; i < l; i++) {
buffer += this$1.attr(namedNodeMap[i]);
}
return buffer;
};
HTMLSerializer.prototype.attr = function(attr) {
if (!attr.specified) {
return '';
}
if (attr.value) {
return ' ' + attr.name + '="' + this.escapeAttrValue(attr.value) + '"';
}
return ' ' + attr.name;
HTMLSerializer.prototype.escapeAttrValue = function escapeAttrValue (attrValue) {
if (attrValue.indexOf('&') > -1 || attrValue.indexOf('"') > -1) {
return attrValue.replace(/[&"]/g, matcher);
}
return attrValue;
};
HTMLSerializer.prototype.escapeText = function(textNodeValue) {
if (textNodeValue.indexOf('>') > -1 ||
textNodeValue.indexOf('<') > -1 ||
textNodeValue.indexOf('&') > -1
) {
return textNodeValue.replace(/[&<>]/g, matcher);
}
return textNodeValue;
HTMLSerializer.prototype.attr = function attr (attr$1) {
if (!attr$1.specified) {
return '';
}
if (attr$1.value) {
return ' ' + attr$1.name + '="' + this.escapeAttrValue(attr$1.value) + '"';
}
return ' ' + attr$1.name;
};
HTMLSerializer.prototype.text = function(text) {
return this.escapeText(text.nodeValue);
HTMLSerializer.prototype.escapeText = function escapeText (textNodeValue) {
if (textNodeValue.indexOf('>') > -1 ||
textNodeValue.indexOf('<') > -1 ||
textNodeValue.indexOf('&') > -1) {
return textNodeValue.replace(/[&<>]/g, matcher);
}
return textNodeValue;
};
HTMLSerializer.prototype.rawHTMLSection = function(text) {
return text.nodeValue;
HTMLSerializer.prototype.text = function text (text$1) {
return this.escapeText(text$1.nodeValue);
};
HTMLSerializer.prototype.comment = function(comment) {
return '<!--'+comment.nodeValue+'-->';
HTMLSerializer.prototype.rawHTMLSection = function rawHTMLSection (text) {
return text.nodeValue;
};
HTMLSerializer.prototype.comment = function comment (comment$1) {
return '<!--' + comment$1.nodeValue + '-->';
};
HTMLSerializer.prototype.serializeChildren = function serializeChildren (node) {
var this$1 = this;
HTMLSerializer.prototype.serializeChildren = function(node) {
var buffer = '';
var next = node.firstChild;
if (next) {
buffer += this.serialize(next);
while(next = next.nextSibling) {
buffer += this.serialize(next);
var buffer = '';
var next = node.firstChild;
while (next !== null) {
buffer += this$1.serialize(next);
next = next.nextSibling;
}
}
return buffer;
return buffer;
};
HTMLSerializer.prototype.serialize = function(node) {
var buffer = '';
// open
switch (node.nodeType) {
case 1:
buffer += this.openTag(node);
break;
case 3:
buffer += this.text(node);
break;
case -1:
buffer += this.rawHTMLSection(node);
break;
case 8:
buffer += this.comment(node);
break;
default:
break;
}
buffer += this.serializeChildren(node);
if (node.nodeType === 1 && !this.isVoid(node)) {
buffer += this.closeTag(node);
}
return buffer;
HTMLSerializer.prototype.serialize = function serialize (node) {
var buffer = '';
// open
switch (node.nodeType) {
case 1:
buffer += this.openTag(node);
break;
case 3:
buffer += this.text(node);
break;
case -1:
buffer += this.rawHTMLSection(node);
break;
case 8:
buffer += this.comment(node);
break;
default:
break;
}
buffer += this.serializeChildren(node);
if (node.nodeType === 1 && !this.isVoid(node)) {
buffer += this.closeTag(node);
}
return buffer;
};
var voidMap = {
AREA: true,
BASE: true,
BR: true,
COL: true,
COMMAND: true,
EMBED: true,
HR: true,
IMG: true,
INPUT: true,
KEYGEN: true,
LINK: true,
META: true,
PARAM: true,
SOURCE: true,
TRACK: true,
WBR: true
AREA: true,
BASE: true,
BR: true,
COL: true,
COMMAND: true,
EMBED: true,
HR: true,
IMG: true,
INPUT: true,
KEYGEN: true,
LINK: true,
META: true,
PARAM: true,
SOURCE: true,
TRACK: true,
WBR: true,
};

@@ -534,0 +511,0 @@

@@ -8,1 +8,2 @@ export { default as Node } from './simple-dom/document/node';

export { default as voidMap } from './simple-dom/void-map';
//# sourceMappingURL=simple-dom.js.map

@@ -0,42 +1,33 @@

import Comment from './document/comment';
import DocumentFragment from './document/document-fragment';
import Element from './document/element';
import Node from './document/node';
import Element from './document/element';
import RawHTMLSection from './document/raw-html-section';
import Text from './document/text';
import Comment from './document/comment';
import RawHTMLSection from './document/raw-html-section';
import DocumentFragment from './document/document-fragment';
function Document() {
this.nodeConstructor(9, '#document', null);
this.documentElement = new Element('html');
this.head = new Element('head');
this.body = new Element('body');
this.documentElement.appendChild(this.head);
this.documentElement.appendChild(this.body);
this.appendChild(this.documentElement);
export default class Document extends Node {
constructor() {
super(9, '#document', null);
this.documentElement = new Element('html');
this.head = new Element('head');
this.body = new Element('body');
this.documentElement.appendChild(this.head);
this.documentElement.appendChild(this.body);
this.appendChild(this.documentElement);
}
createElement(tagName) {
return new Element(tagName);
}
createTextNode(text) {
return new Text(text);
}
createComment(text) {
return new Comment(text);
}
createRawHTMLSection(text) {
return new RawHTMLSection(text);
}
createDocumentFragment() {
return new DocumentFragment();
}
}
Document.prototype = Object.create(Node.prototype);
Document.prototype.constructor = Document;
Document.prototype.nodeConstructor = Node;
Document.prototype.createElement = function(tagName) {
return new Element(tagName);
};
Document.prototype.createTextNode = function(text) {
return new Text(text);
};
Document.prototype.createComment = function(text) {
return new Comment(text);
};
Document.prototype.createRawHTMLSection = function(text) {
return new RawHTMLSection(text);
};
Document.prototype.createDocumentFragment = function() {
return new DocumentFragment();
};
export default Document;
//# sourceMappingURL=document.js.map
import Node from './node';
function Comment(text) {
this.nodeConstructor(8, '#comment', text);
export default class Comment extends Node {
constructor(text) {
super(8 /* COMMENT_NODE */, '#comment', text);
}
_cloneNode() {
return new Comment(this.nodeValue);
}
}
Comment.prototype._cloneNode = function() {
return new Comment(this.nodeValue);
};
Comment.prototype = Object.create(Node.prototype);
Comment.prototype.constructor = Comment;
Comment.prototype.nodeConstructor = Node;
export default Comment;
//# sourceMappingURL=comment.js.map
import Node from './node';
function DocumentFragment() {
this.nodeConstructor(11, '#document-fragment', null);
export default class DocumentFragment extends Node {
constructor() {
super(11 /* DOCUMENT_FRAGMENT_NODE */, '#document-fragment', null);
}
_cloneNode() {
return new DocumentFragment();
}
}
DocumentFragment.prototype._cloneNode = function() {
return new DocumentFragment();
};
DocumentFragment.prototype = Object.create(Node.prototype);
DocumentFragment.prototype.constructor = DocumentFragment;
DocumentFragment.prototype.nodeConstructor = Node;
export default DocumentFragment;
//# sourceMappingURL=document-fragment.js.map
import Node from './node';
function Element(tagName) {
tagName = tagName.toUpperCase();
this.nodeConstructor(1, tagName, null);
this.attributes = [];
this.tagName = tagName;
}
Element.prototype = Object.create(Node.prototype);
Element.prototype.constructor = Element;
Element.prototype.nodeConstructor = Node;
Element.prototype._cloneNode = function() {
var node = new Element(this.tagName);
node.attributes = this.attributes.map(function(attr) {
return { name: attr.name, value: attr.value, specified: attr.specified };
});
return node;
};
Element.prototype.getAttribute = function(_name) {
var attributes = this.attributes;
var name = _name.toLowerCase();
var attr;
for (var i=0, l=attributes.length; i<l; i++) {
attr = attributes[i];
if (attr.name === name) {
return attr.value;
export default class Element extends Node {
constructor(tagName) {
super(1 /* ELEMENT_NODE */, tagName.toUpperCase(), null);
this.attributes = [];
this.tagName = this.nodeName;
}
}
return '';
};
Element.prototype.setAttribute = function(_name, _value) {
var attributes = this.attributes;
var name = _name.toLowerCase();
var value;
if (typeof _value === 'string') {
value = _value;
} else {
value = '' + _value;
}
var attr;
for (var i=0, l=attributes.length; i<l; i++) {
attr = attributes[i];
if (attr.name === name) {
attr.value = value;
return;
getAttribute(name) {
const attributes = this.attributes;
const n = name.toLowerCase();
let attr;
for (let i = 0, l = attributes.length; i < l; i++) {
attr = attributes[i];
if (attr.name === n) {
return attr.value;
}
}
return '';
}
}
attributes.push({
name: name,
value: value,
specified: true // serializer compat with old IE
});
};
Element.prototype.removeAttribute = function(name) {
var attributes = this.attributes;
for (var i=0, l=attributes.length; i<l; i++) {
var attr = attributes[i];
if (attr.name === name) {
attributes.splice(i, 1);
return;
setAttribute(name, value) {
const attributes = this.attributes;
const n = name.toLowerCase();
let v;
if (typeof value === 'string') {
v = value;
}
else {
v = '' + value;
}
let attr;
for (let i = 0, l = attributes.length; i < l; i++) {
attr = attributes[i];
if (attr.name === n) {
attr.value = v;
return;
}
}
attributes.push({
name: n,
specified: true,
value: v,
});
}
}
};
export default Element;
removeAttribute(name) {
const n = name.toLowerCase();
const attributes = this.attributes;
for (let i = 0, l = attributes.length; i < l; i++) {
const attr = attributes[i];
if (attr.name === n) {
attributes.splice(i, 1);
return;
}
}
}
_cloneNode() {
const node = new Element(this.tagName);
const attrs = node.attributes = [];
for (const attr of this.attributes) {
attrs.push({ name: attr.name, specified: attr.specified, value: attr.value });
}
return node;
}
}
//# sourceMappingURL=element.js.map

@@ -1,160 +0,152 @@

function Node(nodeType, nodeName, nodeValue) {
this.nodeType = nodeType;
this.nodeName = nodeName;
this.nodeValue = nodeValue;
this.childNodes = new ChildNodes(this);
this.parentNode = null;
this.previousSibling = null;
this.nextSibling = null;
this.firstChild = null;
this.lastChild = null;
export default class Node {
constructor(nodeType, nodeName, nodeValue) {
this.nodeType = nodeType;
this.nodeName = nodeName;
this.nodeValue = nodeValue;
this.parentNode = null;
this.previousSibling = null;
this.nextSibling = null;
this.firstChild = null;
this.lastChild = null;
this._childNodes = undefined;
}
get childNodes() {
let children = this._childNodes;
if (children === undefined) {
children = this._childNodes = new ChildNodes(this);
}
return children;
}
cloneNode(deep) {
const node = this._cloneNode();
if (deep) {
let child = this.firstChild;
let nextChild = child;
while (child !== null) {
nextChild = child.nextSibling;
node.appendChild(child.cloneNode(true));
child = nextChild;
}
}
return node;
}
appendChild(node) {
if (node.nodeType === 11 /* DOCUMENT_FRAGMENT_NODE */) {
insertFragment(node, this, this.lastChild, null);
return node;
}
if (node.parentNode) {
node.parentNode.removeChild(node);
}
node.parentNode = this;
const refNode = this.lastChild;
if (refNode === null) {
this.firstChild = node;
this.lastChild = node;
}
else {
node.previousSibling = refNode;
refNode.nextSibling = node;
this.lastChild = node;
}
return node;
}
insertBefore(node, refNode) {
if (refNode == null) {
return this.appendChild(node);
}
if (node.nodeType === 11 /* DOCUMENT_FRAGMENT_NODE */) {
insertFragment(node, this, refNode ? refNode.previousSibling : null, refNode);
return;
}
if (node.parentNode) {
node.parentNode.removeChild(node);
}
node.parentNode = this;
const previousSibling = refNode.previousSibling;
if (previousSibling) {
previousSibling.nextSibling = node;
node.previousSibling = previousSibling;
}
else {
node.previousSibling = null;
}
refNode.previousSibling = node;
node.nextSibling = refNode;
if (this.firstChild === refNode) {
this.firstChild = node;
}
}
removeChild(refNode) {
if (this.firstChild === refNode) {
this.firstChild = refNode.nextSibling;
}
if (this.lastChild === refNode) {
this.lastChild = refNode.previousSibling;
}
if (refNode.previousSibling) {
refNode.previousSibling.nextSibling = refNode.nextSibling;
}
if (refNode.nextSibling) {
refNode.nextSibling.previousSibling = refNode.previousSibling;
}
refNode.parentNode = null;
refNode.nextSibling = null;
refNode.previousSibling = null;
}
_cloneNode() {
return new Node(this.nodeType, this.nodeName, this.nodeValue);
}
}
Node.prototype._cloneNode = function() {
return new Node(this.nodeType, this.nodeName, this.nodeValue);
};
Node.prototype.cloneNode = function(deep) {
var node = this._cloneNode();
if (deep) {
var child = this.firstChild, nextChild = child;
while (nextChild) {
nextChild = child.nextSibling;
node.appendChild(child.cloneNode(true));
child = nextChild;
Node.ELEMENT_NODE = 1 /* ELEMENT_NODE */;
Node.ATTRIBUTE_NODE = 2 /* ATTRIBUTE_NODE */;
Node.TEXT_NODE = 3 /* TEXT_NODE */;
Node.CDATA_SECTION_NODE = 4 /* CDATA_SECTION_NODE */;
Node.ENTITY_REFERENCE_NODE = 5 /* ENTITY_REFERENCE_NODE */;
Node.ENTITY_NODE = 6 /* ENTITY_NODE */;
Node.PROCESSING_INSTRUCTION_NODE = 7 /* PROCESSING_INSTRUCTION_NODE */;
Node.COMMENT_NODE = 8 /* COMMENT_NODE */;
Node.DOCUMENT_NODE = 9 /* DOCUMENT_NODE */;
Node.DOCUMENT_TYPE_NODE = 10 /* DOCUMENT_TYPE_NODE */;
Node.DOCUMENT_FRAGMENT_NODE = 11 /* DOCUMENT_FRAGMENT_NODE */;
Node.NOTATION_NODE = 12 /* NOTATION_NODE */;
function insertFragment(fragment, newParent, before, after) {
if (!fragment.firstChild) {
return;
}
}
return node;
};
Node.prototype.appendChild = function(node) {
if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
insertFragment(node, this, this.lastChild, null);
return node;
}
if (node.parentNode) { node.parentNode.removeChild(node); }
node.parentNode = this;
var refNode = this.lastChild;
if (refNode === null) {
this.firstChild = node;
this.lastChild = node;
} else {
node.previousSibling = refNode;
refNode.nextSibling = node;
this.lastChild = node;
}
return node;
};
function insertFragment(fragment, newParent, before, after) {
if (!fragment.firstChild) { return; }
var firstChild = fragment.firstChild;
var lastChild = firstChild;
var node = firstChild;
firstChild.previousSibling = before;
if (before) {
before.nextSibling = firstChild;
} else {
newParent.firstChild = firstChild;
}
while (node) {
node.parentNode = newParent;
lastChild = node;
node = node.nextSibling;
}
lastChild.nextSibling = after;
if (after) {
after.previousSibling = lastChild;
} else {
newParent.lastChild = lastChild;
}
const firstChild = fragment.firstChild;
let lastChild = firstChild;
let node = firstChild;
firstChild.previousSibling = before;
if (before) {
before.nextSibling = firstChild;
}
else {
newParent.firstChild = firstChild;
}
while (node) {
node.parentNode = newParent;
lastChild = node;
node = node.nextSibling;
}
lastChild.nextSibling = after;
if (after) {
after.previousSibling = lastChild;
}
else {
newParent.lastChild = lastChild;
}
}
Node.prototype.insertBefore = function(node, refNode) {
if (refNode == null) {
return this.appendChild(node);
}
if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
insertFragment(node, this, refNode ? refNode.previousSibling : null, refNode);
return;
}
if (node.parentNode) { node.parentNode.removeChild(node); }
node.parentNode = this;
var previousSibling = refNode.previousSibling;
if (previousSibling) {
previousSibling.nextSibling = node;
node.previousSibling = previousSibling;
} else {
node.previousSibling = null;
}
refNode.previousSibling = node;
node.nextSibling = refNode;
if (this.firstChild === refNode) {
this.firstChild = node;
}
};
Node.prototype.removeChild = function(refNode) {
if (this.firstChild === refNode) {
this.firstChild = refNode.nextSibling;
}
if (this.lastChild === refNode) {
this.lastChild = refNode.previousSibling;
}
if (refNode.previousSibling) {
refNode.previousSibling.nextSibling = refNode.nextSibling;
}
if (refNode.nextSibling) {
refNode.nextSibling.previousSibling = refNode.previousSibling;
}
refNode.parentNode = null;
refNode.nextSibling = null;
refNode.previousSibling = null;
};
Node.ELEMENT_NODE = 1;
Node.ATTRIBUTE_NODE = 2;
Node.TEXT_NODE = 3;
Node.CDATA_SECTION_NODE = 4;
Node.ENTITY_REFERENCE_NODE = 5;
Node.ENTITY_NODE = 6;
Node.PROCESSING_INSTRUCTION_NODE = 7;
Node.COMMENT_NODE = 8;
Node.DOCUMENT_NODE = 9;
Node.DOCUMENT_TYPE_NODE = 10;
Node.DOCUMENT_FRAGMENT_NODE = 11;
Node.NOTATION_NODE = 12;
function ChildNodes(node) {
this.node = node;
class ChildNodes {
constructor(node) {
this.node = node;
}
item(index) {
let child = this.node.firstChild;
for (let i = 0; child && index !== i; i++) {
child = child.nextSibling;
}
return child;
}
}
ChildNodes.prototype.item = function(index) {
var child = this.node.firstChild;
for (var i = 0; child && index !== i; i++) {
child = child.nextSibling;
}
return child;
};
export default Node;
//# sourceMappingURL=node.js.map
import Node from './node';
function RawHTMLSection(text) {
this.nodeConstructor(-1, "#raw-html-section", text);
export default class RawHTMLSection extends Node {
constructor(text) {
super(-1 /* RAW */, "#raw-html-section", text);
}
}
RawHTMLSection.prototype = Object.create(Node.prototype);
RawHTMLSection.prototype.constructor = RawHTMLSection;
RawHTMLSection.prototype.nodeConstructor = Node;
export default RawHTMLSection;
//# sourceMappingURL=raw-html-section.js.map
import Node from './node';
function Text(text) {
this.nodeConstructor(3, '#text', text);
export default class Text extends Node {
constructor(text) {
super(3 /* TEXT_NODE */, '#text', text);
}
_cloneNode() {
return new Text(this.nodeValue);
}
}
Text.prototype._cloneNode = function() {
return new Text(this.nodeValue);
};
Text.prototype = Object.create(Node.prototype);
Text.prototype.constructor = Text;
Text.prototype.nodeConstructor = Node;
export default Text;
//# sourceMappingURL=text.js.map

@@ -1,79 +0,65 @@

function HTMLParser(tokenize, document, voidMap) {
this.tokenize = tokenize;
this.document = document;
this.voidMap = voidMap;
this.parentStack = [];
export default class HTMLParser {
constructor(tokenize, document, voidMap) {
this.tokenize = tokenize;
this.document = document;
this.voidMap = voidMap;
this.tokenize = tokenize;
this.document = document;
this.voidMap = voidMap;
this.parentStack = [];
}
isVoid(element) {
return this.voidMap[element.nodeName] === true;
}
pushElement(token) {
const el = this.document.createElement(token.tagName);
for (const attr of token.attributes) {
el.setAttribute(attr[0], attr[1]);
}
if (this.isVoid(el)) {
return this.appendChild(el);
}
this.parentStack.push(el);
}
popElement(token) {
const el = this.parentStack.pop();
if (el.nodeName !== token.tagName.toUpperCase()) {
throw new Error('unbalanced tag');
}
this.appendChild(el);
}
appendText(token) {
this.appendChild(this.document.createTextNode(token.chars));
}
appendComment(token) {
this.appendChild(this.document.createComment(token.chars));
}
appendChild(node) {
const parentNode = this.parentStack[this.parentStack.length - 1];
parentNode.appendChild(node);
}
parse(html) {
const fragment = this.document.createDocumentFragment();
this.parentStack.push(fragment);
const tokens = this.tokenize(html);
for (let i = 0, l = tokens.length; i < l; i++) {
const token = tokens[i];
switch (token.type) {
case 'StartTag':
this.pushElement(token);
break;
case 'EndTag':
this.popElement(token);
break;
case 'Chars':
this.appendText(token);
break;
case 'Comment':
this.appendComment(token);
break;
}
}
return this.parentStack.pop();
}
}
HTMLParser.prototype.isVoid = function(element) {
return this.voidMap[element.nodeName] === true;
};
HTMLParser.prototype.pushElement = function(token) {
var el = this.document.createElement(token.tagName);
for (var i=0;i<token.attributes.length;i++) {
var attr = token.attributes[i];
el.setAttribute(attr[0], attr[1]);
}
if (this.isVoid(el)) {
return this.appendChild(el);
}
this.parentStack.push(el);
};
HTMLParser.prototype.popElement = function(token) {
var el = this.parentStack.pop();
if (el.nodeName !== token.tagName.toUpperCase()) {
throw new Error('unbalanced tag');
}
this.appendChild(el);
};
HTMLParser.prototype.appendText = function(token) {
var text = this.document.createTextNode(token.chars);
this.appendChild(text);
};
HTMLParser.prototype.appendComment = function(token) {
var comment = this.document.createComment(token.chars);
this.appendChild(comment);
};
HTMLParser.prototype.appendChild = function(node) {
var parentNode = this.parentStack[this.parentStack.length-1];
parentNode.appendChild(node);
};
HTMLParser.prototype.parse = function(html/*, context*/) {
// TODO use context for namespaceURI issues
var fragment = this.document.createDocumentFragment();
this.parentStack.push(fragment);
var tokens = this.tokenize(html);
for (var i=0, l=tokens.length; i<l; i++) {
var token = tokens[i];
switch (token.type) {
case 'StartTag':
this.pushElement(token);
break;
case 'EndTag':
this.popElement(token);
break;
case 'Chars':
this.appendText(token);
break;
case 'Comment':
this.appendComment(token);
break;
}
}
return this.parentStack.pop();
};
export default HTMLParser;
//# sourceMappingURL=html-parser.js.map

@@ -1,124 +0,100 @@

var ESC = {
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
'&': '&amp;'
const ESC = {
'"': '&quot;',
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
};
function matcher(char) {
if (ESC[char] === undefined) {
return char;
}
return ESC[char];
if (ESC[char] === undefined) {
return char;
}
return ESC[char];
}
function HTMLSerializer(voidMap) {
this.voidMap = voidMap;
export default class HTMLSerializer {
constructor(voidMap) {
this.voidMap = voidMap;
}
openTag(element) {
return '<' + element.nodeName.toLowerCase() + this.attributes(element.attributes) + '>';
}
closeTag(element) {
return '</' + element.nodeName.toLowerCase() + '>';
}
isVoid(element) {
return this.voidMap[element.nodeName] === true;
}
attributes(namedNodeMap) {
let buffer = '';
for (let i = 0, l = namedNodeMap.length; i < l; i++) {
buffer += this.attr(namedNodeMap[i]);
}
return buffer;
}
escapeAttrValue(attrValue) {
if (attrValue.indexOf('&') > -1 || attrValue.indexOf('"') > -1) {
return attrValue.replace(/[&"]/g, matcher);
}
return attrValue;
}
attr(attr) {
if (!attr.specified) {
return '';
}
if (attr.value) {
return ' ' + attr.name + '="' + this.escapeAttrValue(attr.value) + '"';
}
return ' ' + attr.name;
}
escapeText(textNodeValue) {
if (textNodeValue.indexOf('>') > -1 ||
textNodeValue.indexOf('<') > -1 ||
textNodeValue.indexOf('&') > -1) {
return textNodeValue.replace(/[&<>]/g, matcher);
}
return textNodeValue;
}
text(text) {
return this.escapeText(text.nodeValue);
}
rawHTMLSection(text) {
return text.nodeValue;
}
comment(comment) {
return '<!--' + comment.nodeValue + '-->';
}
serializeChildren(node) {
let buffer = '';
let next = node.firstChild;
while (next !== null) {
buffer += this.serialize(next);
next = next.nextSibling;
}
return buffer;
}
serialize(node) {
let buffer = '';
// open
switch (node.nodeType) {
case 1:
buffer += this.openTag(node);
break;
case 3:
buffer += this.text(node);
break;
case -1:
buffer += this.rawHTMLSection(node);
break;
case 8:
buffer += this.comment(node);
break;
default:
break;
}
buffer += this.serializeChildren(node);
if (node.nodeType === 1 && !this.isVoid(node)) {
buffer += this.closeTag(node);
}
return buffer;
}
}
HTMLSerializer.prototype.openTag = function(element) {
return '<' + element.nodeName.toLowerCase() + this.attributes(element.attributes) + '>';
};
HTMLSerializer.prototype.closeTag = function(element) {
return '</' + element.nodeName.toLowerCase() + '>';
};
HTMLSerializer.prototype.isVoid = function(element) {
return this.voidMap[element.nodeName] === true;
};
HTMLSerializer.prototype.attributes = function(namedNodeMap) {
var buffer = '';
for (var i=0, l=namedNodeMap.length; i<l; i++) {
buffer += this.attr(namedNodeMap[i]);
}
return buffer;
};
HTMLSerializer.prototype.escapeAttrValue = function(attrValue) {
if (attrValue.indexOf('&') > -1 || attrValue.indexOf('"') > -1) {
return attrValue.replace(/[&"]/g, matcher);
}
return attrValue;
};
HTMLSerializer.prototype.attr = function(attr) {
if (!attr.specified) {
return '';
}
if (attr.value) {
return ' ' + attr.name + '="' + this.escapeAttrValue(attr.value) + '"';
}
return ' ' + attr.name;
};
HTMLSerializer.prototype.escapeText = function(textNodeValue) {
if (textNodeValue.indexOf('>') > -1 ||
textNodeValue.indexOf('<') > -1 ||
textNodeValue.indexOf('&') > -1
) {
return textNodeValue.replace(/[&<>]/g, matcher);
}
return textNodeValue;
};
HTMLSerializer.prototype.text = function(text) {
return this.escapeText(text.nodeValue);
};
HTMLSerializer.prototype.rawHTMLSection = function(text) {
return text.nodeValue;
};
HTMLSerializer.prototype.comment = function(comment) {
return '<!--'+comment.nodeValue+'-->';
};
HTMLSerializer.prototype.serializeChildren = function(node) {
var buffer = '';
var next = node.firstChild;
if (next) {
buffer += this.serialize(next);
while(next = next.nextSibling) {
buffer += this.serialize(next);
}
}
return buffer;
};
HTMLSerializer.prototype.serialize = function(node) {
var buffer = '';
// open
switch (node.nodeType) {
case 1:
buffer += this.openTag(node);
break;
case 3:
buffer += this.text(node);
break;
case -1:
buffer += this.rawHTMLSection(node);
break;
case 8:
buffer += this.comment(node);
break;
default:
break;
}
buffer += this.serializeChildren(node);
if (node.nodeType === 1 && !this.isVoid(node)) {
buffer += this.closeTag(node);
}
return buffer;
};
export default HTMLSerializer;
//# sourceMappingURL=html-serializer.js.map
export default {
AREA: true,
BASE: true,
BR: true,
COL: true,
COMMAND: true,
EMBED: true,
HR: true,
IMG: true,
INPUT: true,
KEYGEN: true,
LINK: true,
META: true,
PARAM: true,
SOURCE: true,
TRACK: true,
WBR: true
};
AREA: true,
BASE: true,
BR: true,
COL: true,
COMMAND: true,
EMBED: true,
HR: true,
IMG: true,
INPUT: true,
KEYGEN: true,
LINK: true,
META: true,
PARAM: true,
SOURCE: true,
TRACK: true,
WBR: true,
};
//# sourceMappingURL=void-map.js.map
{
"name": "simple-dom",
"version": "1.1.1",
"version": "1.2.0",
"description": "A simple JS DOM.",

@@ -8,10 +8,13 @@ "main": "dist/simple-dom.js",

"jsnext:main": "lib/simple-dom.js",
"types": "lib/simple-dom.d.ts",
"files": [
"lib",
"dist"
"dist",
"src"
],
"scripts": {
"prepublish": "npm run build",
"build": "node bin/build.js",
"build": "tsc && rollup -c rollup.config.js && rollup -c rollup.config.test.js",
"test": "testem ci",
"lint": "tslint -p tsconfig.json",
"bench": "npm run build && node ./benches/serialize.js"

@@ -32,9 +35,12 @@ },

"devDependencies": {
"do-you-even-bench": "^1.0.4",
"qunit-extras": "^3.0.0",
"do-you-even-bench": "^1.0.5",
"qunitjs": "^2.4.0",
"rollup": "^0.45.2",
"rollup": "^0.49.2",
"rollup-plugin-buble": "^0.16.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"simple-html-tokenizer": "^0.4.1",
"testem": "^1.4.0"
"testem": "^1.18.4",
"tslint": "^5.7.0",
"typescript": "^2.5.2"
}
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc