diff --git a/browser/diffDOM.js.map b/browser/diffDOM.js.map
index 56a4fb6..19fc73f 100644
--- a/browser/diffDOM.js.map
+++ b/browser/diffDOM.js.map
@@ -1 +1 @@
-{"version":3,"file":"diffDOM.js","sources":["../src/diffDOM/helpers.ts","../src/diffDOM/dom/fromVirtual.ts","../src/diffDOM/dom/apply.ts","../src/diffDOM/dom/undo.ts","../node_modules/tslib/tslib.es6.js","../src/diffDOM/virtual/helpers.ts","../src/diffDOM/virtual/apply.ts","../src/diffDOM/virtual/fromDOM.ts","../src/diffDOM/virtual/fromString.ts","../src/diffDOM/virtual/diff.ts","../src/diffDOM/index.ts","../src/TraceLogger.ts"],"sourcesContent":["import { elementNodeType } from \"./types\"\n\nexport class Diff {\n constructor(options = {}) {\n Object.entries(options).forEach(([key, value]) => (this[key] = value))\n }\n\n toString() {\n return JSON.stringify(this)\n }\n\n setValue(\n aKey: string | number,\n aValue:\n | string\n | number\n | boolean\n | number[]\n | { [key: string]: string | { [key: string]: string } }\n | elementNodeType,\n ) {\n this[aKey] = aValue\n return this\n }\n}\n\nexport function checkElementType(element, ...elementTypeNames: string[]) {\n if (typeof element === \"undefined\" || element === null) {\n return false\n }\n return elementTypeNames.some(\n (elementTypeName) =>\n // We need to check if the specified type is defined\n // because otherwise instanceof throws an exception.\n typeof element?.ownerDocument?.defaultView?.[elementTypeName] ===\n \"function\" &&\n element instanceof\n element.ownerDocument.defaultView[elementTypeName],\n )\n}\n","import { DiffDOMOptions, elementNodeType, textNodeType } from \"../types\"\nimport { checkElementType } from \"../helpers\"\n\nexport function objToNode(\n objNode: elementNodeType,\n insideSvg: boolean,\n options: DiffDOMOptions,\n) {\n let node: Element | Text | Comment\n if (objNode.nodeName === \"#text\") {\n node = options.document.createTextNode((objNode as textNodeType).data)\n } else if (objNode.nodeName === \"#comment\") {\n node = options.document.createComment((objNode as textNodeType).data)\n } else {\n if (insideSvg) {\n node = options.document.createElementNS(\n \"http://www.w3.org/2000/svg\",\n objNode.nodeName,\n )\n if (objNode.nodeName === \"foreignObject\") {\n insideSvg = false\n }\n } else if (objNode.nodeName.toLowerCase() === \"svg\") {\n node = options.document.createElementNS(\n \"http://www.w3.org/2000/svg\",\n \"svg\",\n )\n insideSvg = true\n } else {\n node = options.document.createElement(objNode.nodeName)\n }\n if (objNode.attributes) {\n Object.entries(objNode.attributes).forEach(([key, value]) =>\n (node as Element).setAttribute(key, value),\n )\n }\n if (objNode.childNodes) {\n node = node as Element\n objNode.childNodes.forEach(\n (childNode: elementNodeType | textNodeType) =>\n node.appendChild(objToNode(childNode, insideSvg, options)),\n )\n }\n if (options.valueDiffing) {\n if (\n objNode.value &&\n checkElementType(\n node,\n \"HTMLButtonElement\",\n \"HTMLDataElement\",\n \"HTMLInputElement\",\n \"HTMLLIElement\",\n \"HTMLMeterElement\",\n \"HTMLOptionElement\",\n \"HTMLProgressElement\",\n \"HTMLParamElement\",\n )\n ) {\n ;(\n node as\n | HTMLButtonElement\n | HTMLDataElement\n | HTMLInputElement\n | HTMLLIElement\n | HTMLMeterElement\n | HTMLOptionElement\n | HTMLProgressElement\n | HTMLParamElement\n ).value = objNode.value\n }\n if (objNode.checked && checkElementType(node, \"HTMLInputElement\")) {\n ;(node as HTMLInputElement).checked = objNode.checked\n }\n if (\n objNode.selected &&\n checkElementType(node, \"HTMLOptionElement\")\n ) {\n ;(node as HTMLOptionElement).selected = objNode.selected\n }\n }\n }\n return node\n}\n","import { DiffDOMOptions, diffType, nodeType } from \"../types\"\nimport { Diff, checkElementType } from \"../helpers\"\n\nimport { objToNode } from \"./fromVirtual\"\n\n// ===== Apply a diff =====\n\nconst getFromRoute = (\n node: Element,\n route: number[],\n): Element | Text | false => {\n route = route.slice()\n while (route.length > 0) {\n const c = route.splice(0, 1)[0]\n node = node.childNodes[c] as Element\n }\n return node\n}\n\nexport function applyDiff(\n tree: Element,\n diff: diffType,\n options: DiffDOMOptions, // {preDiffApply, postDiffApply, textDiff, valueDiffing, _const}\n) {\n const action = diff[options._const.action] as string | number\n const route = diff[options._const.route] as number[]\n let node\n\n if (\n ![options._const.addElement, options._const.addTextElement].includes(\n action,\n )\n ) {\n // For adding nodes, we calculate the route later on. It's different because it includes the position of the newly added item.\n node = getFromRoute(tree, route)\n }\n\n let newNode\n let reference: Element\n let nodeArray\n\n // pre-diff hook\n const info = {\n diff,\n node,\n }\n\n if (options.preDiffApply(info)) {\n return true\n }\n\n switch (action) {\n case options._const.addAttribute:\n if (!node || !checkElementType(node, \"Element\")) {\n return false\n }\n node.setAttribute(\n diff[options._const.name] as string,\n diff[options._const.value] as string,\n )\n break\n case options._const.modifyAttribute:\n if (!node || !checkElementType(node, \"Element\")) {\n return false\n }\n node.setAttribute(\n diff[options._const.name] as string,\n diff[options._const.newValue] as string,\n )\n if (\n checkElementType(node, \"HTMLInputElement\") &&\n diff[options._const.name] === \"value\"\n ) {\n node.value = diff[options._const.newValue] as string\n }\n break\n case options._const.removeAttribute:\n if (!node || !checkElementType(node, \"Element\")) {\n return false\n }\n node.removeAttribute(diff[options._const.name] as string)\n break\n case options._const.modifyTextElement:\n if (!node || !checkElementType(node, \"Text\")) {\n return false\n }\n options.textDiff(\n node,\n node.data,\n diff[options._const.oldValue] as string,\n diff[options._const.newValue] as string,\n )\n if (checkElementType(node.parentNode, \"HTMLTextAreaElement\")) {\n node.parentNode.value = diff[options._const.newValue] as string\n }\n break\n case options._const.modifyValue:\n if (!node || typeof node.value === \"undefined\") {\n return false\n }\n node.value = diff[options._const.newValue]\n break\n case options._const.modifyComment:\n if (!node || !checkElementType(node, \"Comment\")) {\n return false\n }\n options.textDiff(\n node,\n node.data,\n diff[options._const.oldValue] as string,\n diff[options._const.newValue] as string,\n )\n break\n case options._const.modifyChecked:\n if (!node || typeof node.checked === \"undefined\") {\n return false\n }\n node.checked = diff[options._const.newValue]\n break\n case options._const.modifySelected:\n if (!node || typeof node.selected === \"undefined\") {\n return false\n }\n node.selected = diff[options._const.newValue]\n break\n case options._const.replaceElement: {\n const insideSvg =\n (\n diff[options._const.newValue] as nodeType\n ).nodeName.toLowerCase() === \"svg\" ||\n node.parentNode.namespaceURI === \"http://www.w3.org/2000/svg\"\n node.parentNode.replaceChild(\n objToNode(\n diff[options._const.newValue] as nodeType,\n insideSvg,\n options,\n ),\n node,\n )\n break\n }\n case options._const.relocateGroup:\n nodeArray = Array(\n ...new Array(diff[options._const.groupLength]),\n ).map(() =>\n node.removeChild(\n node.childNodes[diff[options._const.from] as number],\n ),\n )\n nodeArray.forEach((childNode, index) => {\n if (index === 0) {\n reference =\n node.childNodes[diff[options._const.to] as number]\n }\n node.insertBefore(childNode, reference || null)\n })\n break\n case options._const.removeElement:\n node.parentNode.removeChild(node)\n break\n case options._const.addElement: {\n const parentRoute = route.slice()\n const c: number = parentRoute.splice(parentRoute.length - 1, 1)[0]\n node = getFromRoute(tree, parentRoute)\n if (!checkElementType(node, \"Element\")) {\n return false\n }\n node.insertBefore(\n objToNode(\n diff[options._const.element] as nodeType,\n node.namespaceURI === \"http://www.w3.org/2000/svg\",\n options,\n ),\n node.childNodes[c] || null,\n )\n break\n }\n case options._const.removeTextElement: {\n if (!node || node.nodeType !== 3) {\n return false\n }\n const parentNode = node.parentNode\n parentNode.removeChild(node)\n if (checkElementType(parentNode, \"HTMLTextAreaElement\")) {\n parentNode.value = \"\"\n }\n break\n }\n case options._const.addTextElement: {\n const parentRoute = route.slice()\n const c: number = parentRoute.splice(parentRoute.length - 1, 1)[0]\n newNode = options.document.createTextNode(\n diff[options._const.value] as string,\n )\n node = getFromRoute(tree, parentRoute)\n if (!node.childNodes) {\n return false\n }\n node.insertBefore(newNode, node.childNodes[c] || null)\n if (checkElementType(node.parentNode, \"HTMLTextAreaElement\")) {\n node.parentNode.value = diff[options._const.value] as string\n }\n break\n }\n default:\n console.log(\"unknown action\")\n }\n\n // if a new node was created, we might be interested in its\n // post diff hook\n options.postDiffApply({\n diff: info.diff,\n node: info.node,\n newNode,\n })\n\n return true\n}\n\nexport function applyDOM(\n tree: Element,\n diffs: (Diff | diffType)[],\n options: DiffDOMOptions,\n) {\n return diffs.every((diff: Diff | diffType) =>\n applyDiff(tree, diff as diffType, options),\n )\n}\n","import { DiffDOMOptions, diffType } from \"../types\"\nimport { Diff } from \"../helpers\"\nimport { applyDiff } from \"./apply\"\n\n// ===== Undo a diff =====\n\nfunction swap(obj: object, p1: string | number, p2: string | number) {\n const tmp = obj[p1]\n obj[p1] = obj[p2]\n obj[p2] = tmp\n}\n\nfunction undoDiff(\n tree: Element,\n diff: diffType,\n options: DiffDOMOptions, // {preDiffApply, postDiffApply, textDiff, valueDiffing, _const}\n) {\n switch (diff[options._const.action]) {\n case options._const.addAttribute:\n diff[options._const.action] = options._const.removeAttribute\n applyDiff(tree, diff, options)\n break\n case options._const.modifyAttribute:\n swap(diff, options._const.oldValue, options._const.newValue)\n applyDiff(tree, diff, options)\n break\n case options._const.removeAttribute:\n diff[options._const.action] = options._const.addAttribute\n applyDiff(tree, diff, options)\n break\n case options._const.modifyTextElement:\n swap(diff, options._const.oldValue, options._const.newValue)\n applyDiff(tree, diff, options)\n break\n case options._const.modifyValue:\n swap(diff, options._const.oldValue, options._const.newValue)\n applyDiff(tree, diff, options)\n break\n case options._const.modifyComment:\n swap(diff, options._const.oldValue, options._const.newValue)\n applyDiff(tree, diff, options)\n break\n case options._const.modifyChecked:\n swap(diff, options._const.oldValue, options._const.newValue)\n applyDiff(tree, diff, options)\n break\n case options._const.modifySelected:\n swap(diff, options._const.oldValue, options._const.newValue)\n applyDiff(tree, diff, options)\n break\n case options._const.replaceElement:\n swap(diff, options._const.oldValue, options._const.newValue)\n applyDiff(tree, diff, options)\n break\n case options._const.relocateGroup:\n swap(diff, options._const.from, options._const.to)\n applyDiff(tree, diff, options)\n break\n case options._const.removeElement:\n diff[options._const.action] = options._const.addElement\n applyDiff(tree, diff, options)\n break\n case options._const.addElement:\n diff[options._const.action] = options._const.removeElement\n applyDiff(tree, diff, options)\n break\n case options._const.removeTextElement:\n diff[options._const.action] = options._const.addTextElement\n applyDiff(tree, diff, options)\n break\n case options._const.addTextElement:\n diff[options._const.action] = options._const.removeTextElement\n applyDiff(tree, diff, options)\n break\n default:\n console.log(\"unknown action\")\n }\n}\n\nexport function undoDOM(\n tree: Element,\n diffs: (diffType | Diff)[],\n options: DiffDOMOptions,\n) {\n diffs = diffs.slice()\n diffs.reverse()\n diffs.forEach((diff: diffType | Diff) => {\n undoDiff(tree, diff as diffType, options)\n })\n}\n","/******************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {\r\n function accept(f) { if (f !== void 0 && typeof f !== \"function\") throw new TypeError(\"Function expected\"); return f; }\r\n var kind = contextIn.kind, key = kind === \"getter\" ? \"get\" : kind === \"setter\" ? \"set\" : \"value\";\r\n var target = !descriptorIn && ctor ? contextIn[\"static\"] ? ctor : ctor.prototype : null;\r\n var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});\r\n var _, done = false;\r\n for (var i = decorators.length - 1; i >= 0; i--) {\r\n var context = {};\r\n for (var p in contextIn) context[p] = p === \"access\" ? {} : contextIn[p];\r\n for (var p in contextIn.access) context.access[p] = contextIn.access[p];\r\n context.addInitializer = function (f) { if (done) throw new TypeError(\"Cannot add initializers after decoration has completed\"); extraInitializers.push(accept(f || null)); };\r\n var result = (0, decorators[i])(kind === \"accessor\" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);\r\n if (kind === \"accessor\") {\r\n if (result === void 0) continue;\r\n if (result === null || typeof result !== \"object\") throw new TypeError(\"Object expected\");\r\n if (_ = accept(result.get)) descriptor.get = _;\r\n if (_ = accept(result.set)) descriptor.set = _;\r\n if (_ = accept(result.init)) initializers.push(_);\r\n }\r\n else if (_ = accept(result)) {\r\n if (kind === \"field\") initializers.push(_);\r\n else descriptor[key] = _;\r\n }\r\n }\r\n if (target) Object.defineProperty(target, contextIn.name, descriptor);\r\n done = true;\r\n};\r\n\r\nexport function __runInitializers(thisArg, initializers, value) {\r\n var useValue = arguments.length > 2;\r\n for (var i = 0; i < initializers.length; i++) {\r\n value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);\r\n }\r\n return useValue ? value : void 0;\r\n};\r\n\r\nexport function __propKey(x) {\r\n return typeof x === \"symbol\" ? x : \"\".concat(x);\r\n};\r\n\r\nexport function __setFunctionName(f, name, prefix) {\r\n if (typeof name === \"symbol\") name = name.description ? \"[\".concat(name.description, \"]\") : \"\";\r\n return Object.defineProperty(f, \"name\", { configurable: true, value: prefix ? \"\".concat(prefix, \" \", name) : name });\r\n};\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n var desc = Object.getOwnPropertyDescriptor(m, k);\r\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\r\n desc = { enumerable: true, get: function() { return m[k]; } };\r\n }\r\n Object.defineProperty(o, k2, desc);\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n\r\nexport function __classPrivateFieldIn(state, receiver) {\r\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\r\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\r\n}\r\n","import {\n diffNodeType,\n elementDiffNodeType,\n elementNodeType,\n nodeType,\n subsetType,\n textDiffNodeType,\n textNodeType,\n} from \"../types\"\nimport { Diff } from \"../helpers\"\nconst elementDescriptors = (el: diffNodeType) => {\n const output = []\n output.push(el.nodeName)\n if (el.nodeName !== \"#text\" && el.nodeName !== \"#comment\") {\n el = el as elementDiffNodeType\n if (el.attributes) {\n if (el.attributes[\"class\"]) {\n output.push(\n `${el.nodeName}.${el.attributes[\"class\"].replace(\n / /g,\n \".\",\n )}`,\n )\n }\n if (el.attributes.id) {\n output.push(`${el.nodeName}#${el.attributes.id}`)\n }\n }\n }\n return output\n}\n\nconst findUniqueDescriptors = (li: diffNodeType[]) => {\n const uniqueDescriptors = {}\n const duplicateDescriptors = {}\n\n li.forEach((node: nodeType) => {\n elementDescriptors(node).forEach((descriptor) => {\n const inUnique = descriptor in uniqueDescriptors\n const inDupes = descriptor in duplicateDescriptors\n if (!inUnique && !inDupes) {\n uniqueDescriptors[descriptor] = true\n } else if (inUnique) {\n delete uniqueDescriptors[descriptor]\n duplicateDescriptors[descriptor] = true\n }\n })\n })\n\n return uniqueDescriptors\n}\n\nexport const uniqueInBoth = (l1: diffNodeType[], l2: diffNodeType[]) => {\n const l1Unique = findUniqueDescriptors(l1)\n const l2Unique = findUniqueDescriptors(l2)\n const inBoth = {}\n\n Object.keys(l1Unique).forEach((key) => {\n if (l2Unique[key]) {\n inBoth[key] = true\n }\n })\n\n return inBoth\n}\n\nexport const removeDone = (tree: elementDiffNodeType) => {\n delete tree.outerDone\n delete tree.innerDone\n delete tree.valueDone\n if (tree.childNodes) {\n return tree.childNodes.every(removeDone)\n } else {\n return true\n }\n}\n\nexport const cleanNode = (diffNode: diffNodeType) => {\n if (Object.prototype.hasOwnProperty.call(diffNode, \"data\")) {\n const textNode: textNodeType = {\n nodeName: diffNode.nodeName === \"#text\" ? \"#text\" : \"#comment\",\n data: (diffNode as textDiffNodeType).data,\n }\n return textNode\n } else {\n const elementNode: elementNodeType = {\n nodeName: diffNode.nodeName,\n }\n diffNode = diffNode as elementDiffNodeType\n if (Object.prototype.hasOwnProperty.call(diffNode, \"attributes\")) {\n elementNode.attributes = { ...diffNode.attributes }\n }\n if (Object.prototype.hasOwnProperty.call(diffNode, \"checked\")) {\n elementNode.checked = diffNode.checked\n }\n if (Object.prototype.hasOwnProperty.call(diffNode, \"value\")) {\n elementNode.value = diffNode.value\n }\n if (Object.prototype.hasOwnProperty.call(diffNode, \"selected\")) {\n elementNode.selected = diffNode.selected\n }\n if (Object.prototype.hasOwnProperty.call(diffNode, \"childNodes\")) {\n elementNode.childNodes = diffNode.childNodes.map((diffChildNode) =>\n cleanNode(diffChildNode),\n )\n }\n return elementNode\n }\n}\n\nexport const isEqual = (e1: diffNodeType, e2: diffNodeType) => {\n if (\n ![\"nodeName\", \"value\", \"checked\", \"selected\", \"data\"].every(\n (element) => {\n if (e1[element] !== e2[element]) {\n return false\n }\n return true\n },\n )\n ) {\n return false\n }\n if (Object.prototype.hasOwnProperty.call(e1, \"data\")) {\n // Comment or Text\n return true\n }\n e1 = e1 as elementDiffNodeType\n e2 = e2 as elementDiffNodeType\n if (Boolean(e1.attributes) !== Boolean(e2.attributes)) {\n return false\n }\n\n if (Boolean(e1.childNodes) !== Boolean(e2.childNodes)) {\n return false\n }\n if (e1.attributes) {\n const e1Attributes = Object.keys(e1.attributes)\n const e2Attributes = Object.keys(e2.attributes)\n\n if (e1Attributes.length !== e2Attributes.length) {\n return false\n }\n if (\n !e1Attributes.every((attribute) => {\n if (\n (e1 as elementDiffNodeType).attributes[attribute] !==\n (e2 as elementDiffNodeType).attributes[attribute]\n ) {\n return false\n }\n return true\n })\n ) {\n return false\n }\n }\n if (e1.childNodes) {\n if (e1.childNodes.length !== e2.childNodes.length) {\n return false\n }\n if (\n !e1.childNodes.every((childNode: nodeType, index: number) =>\n isEqual(childNode, e2.childNodes[index]),\n )\n ) {\n return false\n }\n }\n\n return true\n}\n\nexport const roughlyEqual = (\n e1: diffNodeType,\n e2: diffNodeType,\n uniqueDescriptors: { [key: string]: boolean },\n sameSiblings: boolean,\n preventRecursion = false,\n) => {\n if (!e1 || !e2) {\n return false\n }\n\n if (e1.nodeName !== e2.nodeName) {\n return false\n }\n\n if ([\"#text\", \"#comment\"].includes(e1.nodeName)) {\n // Note that we initially don't care what the text content of a node is,\n // the mere fact that it's the same tag and \"has text\" means it's roughly\n // equal, and then we can find out the true text difference later.\n return preventRecursion\n ? true\n : (e1 as textDiffNodeType).data === (e2 as textDiffNodeType).data\n }\n\n e1 = e1 as elementDiffNodeType\n e2 = e2 as elementDiffNodeType\n\n if (e1.nodeName in uniqueDescriptors) {\n return true\n }\n\n if (e1.attributes && e2.attributes) {\n if (e1.attributes.id) {\n if (e1.attributes.id !== e2.attributes.id) {\n return false\n } else {\n const idDescriptor = `${e1.nodeName}#${e1.attributes.id}`\n if (idDescriptor in uniqueDescriptors) {\n return true\n }\n }\n }\n if (\n e1.attributes[\"class\"] &&\n e1.attributes[\"class\"] === e2.attributes[\"class\"]\n ) {\n const classDescriptor = `${e1.nodeName}.${e1.attributes[\n \"class\"\n ].replace(/ /g, \".\")}`\n if (classDescriptor in uniqueDescriptors) {\n return true\n }\n }\n }\n\n if (sameSiblings) {\n return true\n }\n\n const nodeList1 = e1.childNodes ? e1.childNodes.slice().reverse() : []\n const nodeList2 = e2.childNodes ? e2.childNodes.slice().reverse() : []\n\n if (nodeList1.length !== nodeList2.length) {\n return false\n }\n\n if (preventRecursion) {\n return nodeList1.every(\n (element: nodeType, index: number) =>\n element.nodeName === nodeList2[index].nodeName,\n )\n } else {\n // note: we only allow one level of recursion at any depth. If 'preventRecursion'\n // was not set, we must explicitly force it to true for child iterations.\n const childUniqueDescriptors = uniqueInBoth(nodeList1, nodeList2)\n return nodeList1.every((element: nodeType, index: number) =>\n roughlyEqual(\n element,\n nodeList2[index],\n childUniqueDescriptors,\n true,\n true,\n ),\n )\n }\n}\n\n/**\n * based on https://en.wikibooks.org/wiki/Algorithm_implementation/Strings/Longest_common_substring#JavaScript\n */\nconst findCommonSubsets = (\n c1: diffNodeType[],\n c2: diffNodeType[],\n marked1: boolean[],\n marked2: boolean[],\n) => {\n let lcsSize = 0\n let index: number[] = []\n const c1Length = c1.length\n const c2Length = c2.length\n\n const // set up the matching table\n matches = Array(...new Array(c1Length + 1)).map(() => [])\n\n const uniqueDescriptors = uniqueInBoth(c1, c2)\n\n let // If all of the elements are the same tag, id and class, then we can\n // consider them roughly the same even if they have a different number of\n // children. This will reduce removing and re-adding similar elements.\n subsetsSame = c1Length === c2Length\n\n if (subsetsSame) {\n c1.some((element: nodeType, i: number) => {\n const c1Desc = elementDescriptors(element)\n const c2Desc = elementDescriptors(c2[i])\n if (c1Desc.length !== c2Desc.length) {\n subsetsSame = false\n return true\n }\n c1Desc.some((description, i) => {\n if (description !== c2Desc[i]) {\n subsetsSame = false\n return true\n }\n })\n if (!subsetsSame) {\n return true\n }\n })\n }\n\n // fill the matches with distance values\n for (let c1Index = 0; c1Index < c1Length; c1Index++) {\n const c1Element = c1[c1Index]\n for (let c2Index = 0; c2Index < c2Length; c2Index++) {\n const c2Element = c2[c2Index]\n if (\n !marked1[c1Index] &&\n !marked2[c2Index] &&\n roughlyEqual(\n c1Element,\n c2Element,\n uniqueDescriptors,\n subsetsSame,\n )\n ) {\n matches[c1Index + 1][c2Index + 1] = matches[c1Index][c2Index]\n ? matches[c1Index][c2Index] + 1\n : 1\n if (matches[c1Index + 1][c2Index + 1] >= lcsSize) {\n lcsSize = matches[c1Index + 1][c2Index + 1]\n index = [c1Index + 1, c2Index + 1]\n }\n } else {\n matches[c1Index + 1][c2Index + 1] = 0\n }\n }\n }\n\n if (lcsSize === 0) {\n return false\n }\n\n return {\n oldValue: index[0] - lcsSize,\n newValue: index[1] - lcsSize,\n length: lcsSize,\n }\n}\n\nconst makeBooleanArray = (n: number, v: boolean) =>\n Array(...new Array(n)).map(() => v)\n\n/**\n * Generate arrays that indicate which node belongs to which subset,\n * or whether it's actually an orphan node, existing in only one\n * of the two trees, rather than somewhere in both.\n *\n * So if t1 =