UNPKG

mutation-summary

Version:
89 lines 3.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NodeChange = void 0; var NodeChange = /** @class */ (function () { function NodeChange(node, childList, attributes, characterData, oldParentNode, added, attributeOldValues, characterDataOldValue) { if (childList === void 0) { childList = false; } if (attributes === void 0) { attributes = false; } if (characterData === void 0) { characterData = false; } if (oldParentNode === void 0) { oldParentNode = null; } if (added === void 0) { added = false; } if (attributeOldValues === void 0) { attributeOldValues = null; } if (characterDataOldValue === void 0) { characterDataOldValue = null; } this.node = node; this.childList = childList; this.attributes = attributes; this.characterData = characterData; this.oldParentNode = oldParentNode; this.added = added; this.attributeOldValues = attributeOldValues; this.characterDataOldValue = characterDataOldValue; this.isCaseInsensitive = this.node.nodeType === Node.ELEMENT_NODE && this.node instanceof HTMLElement && this.node.ownerDocument instanceof HTMLDocument; } NodeChange.prototype.getAttributeOldValue = function (name) { if (!this.attributeOldValues) return undefined; if (this.isCaseInsensitive) name = name.toLowerCase(); return this.attributeOldValues[name]; }; NodeChange.prototype.getAttributeNamesMutated = function () { var names = []; if (!this.attributeOldValues) return names; for (var name_1 in this.attributeOldValues) { if (this.attributeOldValues.hasOwnProperty(name_1)) { names.push(name_1); } } return names; }; NodeChange.prototype.attributeMutated = function (name, oldValue) { this.attributes = true; this.attributeOldValues = this.attributeOldValues || {}; if (name in this.attributeOldValues) return; this.attributeOldValues[name] = oldValue; }; NodeChange.prototype.characterDataMutated = function (oldValue) { if (this.characterData) return; this.characterData = true; this.characterDataOldValue = oldValue; }; // Note: is it possible to receive a removal followed by a removal. This // can occur if the removed node is added to an non-observed node, that // node is added to the observed area, and then the node removed from // it. NodeChange.prototype.removedFromParent = function (parent) { this.childList = true; if (this.added || this.oldParentNode) this.added = false; else this.oldParentNode = parent; }; NodeChange.prototype.insertedIntoParent = function () { this.childList = true; this.added = true; }; // An node's oldParent is // -its present parent, if its parentNode was not changed. // -null if the first thing that happened to it was an add. // -the node it was removed from if the first thing that happened to it // was a remove. NodeChange.prototype.getOldParent = function () { if (this.childList) { if (this.oldParentNode) return this.oldParentNode; if (this.added) return null; } return this.node.parentNode; }; return NodeChange; }()); exports.NodeChange = NodeChange; //# sourceMappingURL=NodeChange.js.map