UNPKG

@angular/platform-server

Version:

Angular - library for using Angular in Node.js

1 lines 1.05 MB
{"version":3,"file":"server-BPmC12ZL.mjs","sources":["../../../../../../external/npm/node_modules/domino/lib/Event.js","../../../../../../external/npm/node_modules/domino/lib/UIEvent.js","../../../../../../external/npm/node_modules/domino/lib/MouseEvent.js","../../../../../../external/npm/node_modules/domino/lib/DOMException.js","../../../../../../external/npm/node_modules/domino/lib/config.js","../../../../../../external/npm/node_modules/domino/lib/utils.js","../../../../../../external/npm/node_modules/domino/lib/EventTarget.js","../../../../../../external/npm/node_modules/domino/lib/LinkedList.js","../../../../../../external/npm/node_modules/domino/lib/NodeUtils.js","../../../../../../external/npm/node_modules/domino/lib/Node.js","../../../../../../external/npm/node_modules/domino/lib/NodeList.es6.js","../../../../../../external/npm/node_modules/domino/lib/NodeList.es5.js","../../../../../../external/npm/node_modules/domino/lib/NodeList.js","../../../../../../external/npm/node_modules/domino/lib/ContainerNode.js","../../../../../../external/npm/node_modules/domino/lib/xmlnames.js","../../../../../../external/npm/node_modules/domino/lib/attributes.js","../../../../../../external/npm/node_modules/domino/lib/FilteredElementList.js","../../../../../../external/npm/node_modules/domino/lib/DOMTokenList.js","../../../../../../external/npm/node_modules/domino/lib/select.js","../../../../../../external/npm/node_modules/domino/lib/ChildNode.js","../../../../../../external/npm/node_modules/domino/lib/NonDocumentTypeChildNode.js","../../../../../../external/npm/node_modules/domino/lib/NamedNodeMap.js","../../../../../../external/npm/node_modules/domino/lib/Element.js","../../../../../../external/npm/node_modules/domino/lib/Leaf.js","../../../../../../external/npm/node_modules/domino/lib/CharacterData.js","../../../../../../external/npm/node_modules/domino/lib/Text.js","../../../../../../external/npm/node_modules/domino/lib/Comment.js","../../../../../../external/npm/node_modules/domino/lib/DocumentFragment.js","../../../../../../external/npm/node_modules/domino/lib/ProcessingInstruction.js","../../../../../../external/npm/node_modules/domino/lib/NodeFilter.js","../../../../../../external/npm/node_modules/domino/lib/NodeTraversal.js","../../../../../../external/npm/node_modules/domino/lib/TreeWalker.js","../../../../../../external/npm/node_modules/domino/lib/NodeIterator.js","../../../../../../external/npm/node_modules/domino/lib/URL.js","../../../../../../external/npm/node_modules/domino/lib/CustomEvent.js","../../../../../../external/npm/node_modules/domino/lib/events.js","../../../../../../external/npm/node_modules/domino/lib/style_parser.js","../../../../../../external/npm/node_modules/domino/lib/CSSStyleDeclaration.js","../../../../../../external/npm/node_modules/domino/lib/URLUtils.js","../../../../../../external/npm/node_modules/domino/lib/defineElement.js","../../../../../../external/npm/node_modules/domino/lib/htmlelts.js","../../../../../../external/npm/node_modules/domino/lib/svg.js","../../../../../../external/npm/node_modules/domino/lib/MutationConstants.js","../../../../../../external/npm/node_modules/domino/lib/Document.js","../../../../../../external/npm/node_modules/domino/lib/DocumentType.js","../../../../../../external/npm/node_modules/domino/lib/HTMLParser.js","../../../../../../external/npm/node_modules/domino/lib/DOMImplementation.js","../../../../../../external/npm/node_modules/domino/lib/Location.js","../../../../../../external/npm/node_modules/domino/lib/NavigatorID.js","../../../../../../external/npm/node_modules/domino/lib/WindowTimers.js","../../../../../../external/npm/node_modules/domino/lib/impl.js","../../../../../../external/npm/node_modules/domino/lib/Window.js","../../../../../../external/npm/node_modules/domino/lib/index.js","../../../../../../packages/platform-server/src/domino_adapter.ts","../../../../../../packages/platform-server/src/tokens.ts","../../../../../../packages/platform-server/src/platform_state.ts","../../../../../../packages/platform-server/src/http.ts","../../../../../../packages/platform-server/src/location.ts","../../../../../../packages/platform-server/src/server_events.ts","../../../../../../packages/platform-server/src/transfer_state.ts","../../../../../../packages/platform-server/src/server.ts"],"sourcesContent":["\"use strict\";\nmodule.exports = Event;\n\nEvent.CAPTURING_PHASE = 1;\nEvent.AT_TARGET = 2;\nEvent.BUBBLING_PHASE = 3;\n\nfunction Event(type, dictionary) {\n // Initialize basic event properties\n this.type = '';\n this.target = null;\n this.currentTarget = null;\n this.eventPhase = Event.AT_TARGET;\n this.bubbles = false;\n this.cancelable = false;\n this.isTrusted = false;\n this.defaultPrevented = false;\n this.timeStamp = Date.now();\n\n // Initialize internal flags\n // XXX: Would it be better to inherit these defaults from the prototype?\n this._propagationStopped = false;\n this._immediatePropagationStopped = false;\n this._initialized = true;\n this._dispatching = false;\n\n // Now initialize based on the constructor arguments (if any)\n if (type) this.type = type;\n if (dictionary) {\n for(var p in dictionary) {\n this[p] = dictionary[p];\n }\n }\n}\n\nEvent.prototype = Object.create(Object.prototype, {\n constructor: { value: Event },\n stopPropagation: { value: function stopPropagation() {\n this._propagationStopped = true;\n }},\n\n stopImmediatePropagation: { value: function stopImmediatePropagation() {\n this._propagationStopped = true;\n this._immediatePropagationStopped = true;\n }},\n\n preventDefault: { value: function preventDefault() {\n if (this.cancelable) this.defaultPrevented = true;\n }},\n\n initEvent: { value: function initEvent(type, bubbles, cancelable) {\n this._initialized = true;\n if (this._dispatching) return;\n\n this._propagationStopped = false;\n this._immediatePropagationStopped = false;\n this.defaultPrevented = false;\n this.isTrusted = false;\n\n this.target = null;\n this.type = type;\n this.bubbles = bubbles;\n this.cancelable = cancelable;\n }},\n\n});\n","\"use strict\";\nvar Event = require('./Event');\n\nmodule.exports = UIEvent;\n\nfunction UIEvent() {\n // Just use the superclass constructor to initialize\n Event.call(this);\n this.view = null; // FF uses the current window\n this.detail = 0;\n}\nUIEvent.prototype = Object.create(Event.prototype, {\n constructor: { value: UIEvent },\n initUIEvent: { value: function(type, bubbles, cancelable, view, detail) {\n this.initEvent(type, bubbles, cancelable);\n this.view = view;\n this.detail = detail;\n }}\n});\n","\"use strict\";\nvar UIEvent = require('./UIEvent');\n\nmodule.exports = MouseEvent;\n\nfunction MouseEvent() {\n // Just use the superclass constructor to initialize\n UIEvent.call(this);\n\n this.screenX = this.screenY = this.clientX = this.clientY = 0;\n this.ctrlKey = this.altKey = this.shiftKey = this.metaKey = false;\n this.button = 0;\n this.buttons = 1;\n this.relatedTarget = null;\n}\nMouseEvent.prototype = Object.create(UIEvent.prototype, {\n constructor: { value: MouseEvent },\n initMouseEvent: { value: function(type, bubbles, cancelable,\n view, detail,\n screenX, screenY, clientX, clientY,\n ctrlKey, altKey, shiftKey, metaKey,\n button, relatedTarget) {\n\n this.initEvent(type, bubbles, cancelable, view, detail);\n this.screenX = screenX;\n this.screenY = screenY;\n this.clientX = clientX;\n this.clientY = clientY;\n this.ctrlKey = ctrlKey;\n this.altKey = altKey;\n this.shiftKey = shiftKey;\n this.metaKey = metaKey;\n this.button = button;\n switch(button) {\n case 0: this.buttons = 1; break;\n case 1: this.buttons = 4; break;\n case 2: this.buttons = 2; break;\n default: this.buttons = 0; break;\n }\n this.relatedTarget = relatedTarget;\n }},\n\n getModifierState: { value: function(key) {\n switch(key) {\n case \"Alt\": return this.altKey;\n case \"Control\": return this.ctrlKey;\n case \"Shift\": return this.shiftKey;\n case \"Meta\": return this.metaKey;\n default: return false;\n }\n }}\n});\n","\"use strict\";\nmodule.exports = DOMException;\n\nvar INDEX_SIZE_ERR = 1;\nvar HIERARCHY_REQUEST_ERR = 3;\nvar WRONG_DOCUMENT_ERR = 4;\nvar INVALID_CHARACTER_ERR = 5;\nvar NO_MODIFICATION_ALLOWED_ERR = 7;\nvar NOT_FOUND_ERR = 8;\nvar NOT_SUPPORTED_ERR = 9;\nvar INVALID_STATE_ERR = 11;\nvar SYNTAX_ERR = 12;\nvar INVALID_MODIFICATION_ERR = 13;\nvar NAMESPACE_ERR = 14;\nvar INVALID_ACCESS_ERR = 15;\nvar TYPE_MISMATCH_ERR = 17;\nvar SECURITY_ERR = 18;\nvar NETWORK_ERR = 19;\nvar ABORT_ERR = 20;\nvar URL_MISMATCH_ERR = 21;\nvar QUOTA_EXCEEDED_ERR = 22;\nvar TIMEOUT_ERR = 23;\nvar INVALID_NODE_TYPE_ERR = 24;\nvar DATA_CLONE_ERR = 25;\n\n// Code to name\nvar names = [\n null, // No error with code 0\n 'INDEX_SIZE_ERR',\n null, // historical\n 'HIERARCHY_REQUEST_ERR',\n 'WRONG_DOCUMENT_ERR',\n 'INVALID_CHARACTER_ERR',\n null, // historical\n 'NO_MODIFICATION_ALLOWED_ERR',\n 'NOT_FOUND_ERR',\n 'NOT_SUPPORTED_ERR',\n 'INUSE_ATTRIBUTE_ERR', // historical\n 'INVALID_STATE_ERR',\n 'SYNTAX_ERR',\n 'INVALID_MODIFICATION_ERR',\n 'NAMESPACE_ERR',\n 'INVALID_ACCESS_ERR',\n null, // historical\n 'TYPE_MISMATCH_ERR',\n 'SECURITY_ERR',\n 'NETWORK_ERR',\n 'ABORT_ERR',\n 'URL_MISMATCH_ERR',\n 'QUOTA_EXCEEDED_ERR',\n 'TIMEOUT_ERR',\n 'INVALID_NODE_TYPE_ERR',\n 'DATA_CLONE_ERR',\n];\n\n// Code to message\n// These strings are from the 13 May 2011 Editor's Draft of DOM Core.\n// http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html\n// Copyright © 2011 W3C® (MIT, ERCIM, Keio), All Rights Reserved.\n// Used under the terms of the W3C Document License:\n// http://www.w3.org/Consortium/Legal/2002/copyright-documents-20021231\nvar messages = [\n null, // No error with code 0\n 'INDEX_SIZE_ERR (1): the index is not in the allowed range',\n null,\n 'HIERARCHY_REQUEST_ERR (3): the operation would yield an incorrect nodes model',\n 'WRONG_DOCUMENT_ERR (4): the object is in the wrong Document, a call to importNode is required',\n 'INVALID_CHARACTER_ERR (5): the string contains invalid characters',\n null,\n 'NO_MODIFICATION_ALLOWED_ERR (7): the object can not be modified',\n 'NOT_FOUND_ERR (8): the object can not be found here',\n 'NOT_SUPPORTED_ERR (9): this operation is not supported',\n 'INUSE_ATTRIBUTE_ERR (10): setAttributeNode called on owned Attribute',\n 'INVALID_STATE_ERR (11): the object is in an invalid state',\n 'SYNTAX_ERR (12): the string did not match the expected pattern',\n 'INVALID_MODIFICATION_ERR (13): the object can not be modified in this way',\n 'NAMESPACE_ERR (14): the operation is not allowed by Namespaces in XML',\n 'INVALID_ACCESS_ERR (15): the object does not support the operation or argument',\n null,\n 'TYPE_MISMATCH_ERR (17): the type of the object does not match the expected type',\n 'SECURITY_ERR (18): the operation is insecure',\n 'NETWORK_ERR (19): a network error occurred',\n 'ABORT_ERR (20): the user aborted an operation',\n 'URL_MISMATCH_ERR (21): the given URL does not match another URL',\n 'QUOTA_EXCEEDED_ERR (22): the quota has been exceeded',\n 'TIMEOUT_ERR (23): a timeout occurred',\n 'INVALID_NODE_TYPE_ERR (24): the supplied node is invalid or has an invalid ancestor for this operation',\n 'DATA_CLONE_ERR (25): the object can not be cloned.'\n];\n\n// Name to code\nvar constants = {\n INDEX_SIZE_ERR: INDEX_SIZE_ERR,\n DOMSTRING_SIZE_ERR: 2, // historical\n HIERARCHY_REQUEST_ERR: HIERARCHY_REQUEST_ERR,\n WRONG_DOCUMENT_ERR: WRONG_DOCUMENT_ERR,\n INVALID_CHARACTER_ERR: INVALID_CHARACTER_ERR,\n NO_DATA_ALLOWED_ERR: 6, // historical\n NO_MODIFICATION_ALLOWED_ERR: NO_MODIFICATION_ALLOWED_ERR,\n NOT_FOUND_ERR: NOT_FOUND_ERR,\n NOT_SUPPORTED_ERR: NOT_SUPPORTED_ERR,\n INUSE_ATTRIBUTE_ERR: 10, // historical\n INVALID_STATE_ERR: INVALID_STATE_ERR,\n SYNTAX_ERR: SYNTAX_ERR,\n INVALID_MODIFICATION_ERR: INVALID_MODIFICATION_ERR,\n NAMESPACE_ERR: NAMESPACE_ERR,\n INVALID_ACCESS_ERR: INVALID_ACCESS_ERR,\n VALIDATION_ERR: 16, // historical\n TYPE_MISMATCH_ERR: TYPE_MISMATCH_ERR,\n SECURITY_ERR: SECURITY_ERR,\n NETWORK_ERR: NETWORK_ERR,\n ABORT_ERR: ABORT_ERR,\n URL_MISMATCH_ERR: URL_MISMATCH_ERR,\n QUOTA_EXCEEDED_ERR: QUOTA_EXCEEDED_ERR,\n TIMEOUT_ERR: TIMEOUT_ERR,\n INVALID_NODE_TYPE_ERR: INVALID_NODE_TYPE_ERR,\n DATA_CLONE_ERR: DATA_CLONE_ERR\n};\n\nfunction DOMException(code) {\n Error.call(this);\n Error.captureStackTrace(this, this.constructor);\n this.code = code;\n this.message = messages[code];\n this.name = names[code];\n}\nDOMException.prototype.__proto__ = Error.prototype;\n\n// Initialize the constants on DOMException and DOMException.prototype\nfor(var c in constants) {\n var v = { value: constants[c] };\n Object.defineProperty(DOMException, c, v);\n Object.defineProperty(DOMException.prototype, c, v);\n}\n","/*\n * This file defines Domino behaviour that can be externally configured.\n * To change these settings, set the relevant global property *before*\n * you call `require(\"domino\")`.\n */\n\nexports.isApiWritable = !globalThis.__domino_frozen__;\n","\"use strict\";\nvar DOMException = require('./DOMException');\nvar ERR = DOMException;\nvar isApiWritable = require(\"./config\").isApiWritable;\n\nexports.NAMESPACE = {\n HTML: 'http://www.w3.org/1999/xhtml',\n XML: 'http://www.w3.org/XML/1998/namespace',\n XMLNS: 'http://www.w3.org/2000/xmlns/',\n MATHML: 'http://www.w3.org/1998/Math/MathML',\n SVG: 'http://www.w3.org/2000/svg',\n XLINK: 'http://www.w3.org/1999/xlink'\n};\n\n//\n// Shortcut functions for throwing errors of various types.\n//\nexports.IndexSizeError = function() { throw new DOMException(ERR.INDEX_SIZE_ERR); };\nexports.HierarchyRequestError = function() { throw new DOMException(ERR.HIERARCHY_REQUEST_ERR); };\nexports.WrongDocumentError = function() { throw new DOMException(ERR.WRONG_DOCUMENT_ERR); };\nexports.InvalidCharacterError = function() { throw new DOMException(ERR.INVALID_CHARACTER_ERR); };\nexports.NoModificationAllowedError = function() { throw new DOMException(ERR.NO_MODIFICATION_ALLOWED_ERR); };\nexports.NotFoundError = function() { throw new DOMException(ERR.NOT_FOUND_ERR); };\nexports.NotSupportedError = function() { throw new DOMException(ERR.NOT_SUPPORTED_ERR); };\nexports.InvalidStateError = function() { throw new DOMException(ERR.INVALID_STATE_ERR); };\nexports.SyntaxError = function() { throw new DOMException(ERR.SYNTAX_ERR); };\nexports.InvalidModificationError = function() { throw new DOMException(ERR.INVALID_MODIFICATION_ERR); };\nexports.NamespaceError = function() { throw new DOMException(ERR.NAMESPACE_ERR); };\nexports.InvalidAccessError = function() { throw new DOMException(ERR.INVALID_ACCESS_ERR); };\nexports.TypeMismatchError = function() { throw new DOMException(ERR.TYPE_MISMATCH_ERR); };\nexports.SecurityError = function() { throw new DOMException(ERR.SECURITY_ERR); };\nexports.NetworkError = function() { throw new DOMException(ERR.NETWORK_ERR); };\nexports.AbortError = function() { throw new DOMException(ERR.ABORT_ERR); };\nexports.UrlMismatchError = function() { throw new DOMException(ERR.URL_MISMATCH_ERR); };\nexports.QuotaExceededError = function() { throw new DOMException(ERR.QUOTA_EXCEEDED_ERR); };\nexports.TimeoutError = function() { throw new DOMException(ERR.TIMEOUT_ERR); };\nexports.InvalidNodeTypeError = function() { throw new DOMException(ERR.INVALID_NODE_TYPE_ERR); };\nexports.DataCloneError = function() { throw new DOMException(ERR.DATA_CLONE_ERR); };\n\nexports.nyi = function() {\n throw new Error(\"NotYetImplemented\");\n};\n\nexports.shouldOverride = function() {\n throw new Error(\"Abstract function; should be overriding in subclass.\");\n};\n\nexports.assert = function(expr, msg) {\n if (!expr) {\n throw new Error(\"Assertion failed: \" + (msg || \"\") + \"\\n\" + new Error().stack);\n }\n};\n\nexports.expose = function(src, c) {\n for (var n in src) {\n Object.defineProperty(c.prototype, n, { value: src[n], writable: isApiWritable });\n }\n};\n\nexports.merge = function(a, b) {\n for (var n in b) {\n a[n] = b[n];\n }\n};\n\n// Compare two nodes based on their document order. This function is intended\n// to be passed to sort(). Assumes that the array being sorted does not\n// contain duplicates. And that all nodes are connected and comparable.\n// Clever code by ppk via jeresig.\nexports.documentOrder = function(n,m) {\n /* jshint bitwise: false */\n return 3 - (n.compareDocumentPosition(m) & 6);\n};\n\nexports.toASCIILowerCase = function(s) {\n return s.replace(/[A-Z]+/g, function(c) {\n return c.toLowerCase();\n });\n};\n\nexports.toASCIIUpperCase = function(s) {\n return s.replace(/[a-z]+/g, function(c) {\n return c.toUpperCase();\n });\n};\n","\"use strict\";\nvar Event = require('./Event');\nvar MouseEvent = require('./MouseEvent');\nvar utils = require('./utils');\n\nmodule.exports = EventTarget;\n\nfunction EventTarget() {}\n\nEventTarget.prototype = {\n // XXX\n // See WebIDL §4.8 for details on object event handlers\n // and how they should behave. We actually have to accept\n // any object to addEventListener... Can't type check it.\n // on registration.\n\n // XXX:\n // Capturing event listeners are sort of rare. I think I can optimize\n // them so that dispatchEvent can skip the capturing phase (or much of\n // it). Each time a capturing listener is added, increment a flag on\n // the target node and each of its ancestors. Decrement when removed.\n // And update the counter when nodes are added and removed from the\n // tree as well. Then, in dispatch event, the capturing phase can\n // abort if it sees any node with a zero count.\n addEventListener: function addEventListener(type, listener, capture) {\n if (!listener) return;\n if (capture === undefined) capture = false;\n if (!this._listeners) this._listeners = Object.create(null);\n if (!this._listeners[type]) this._listeners[type] = [];\n var list = this._listeners[type];\n\n // If this listener has already been registered, just return\n for(var i = 0, n = list.length; i < n; i++) {\n var l = list[i];\n if (l.listener === listener && l.capture === capture)\n return;\n }\n\n // Add an object to the list of listeners\n var obj = { listener: listener, capture: capture };\n if (typeof listener === 'function') obj.f = listener;\n list.push(obj);\n },\n\n removeEventListener: function removeEventListener(type,\n listener,\n capture) {\n if (capture === undefined) capture = false;\n if (this._listeners) {\n var list = this._listeners[type];\n if (list) {\n // Find the listener in the list and remove it\n for(var i = 0, n = list.length; i < n; i++) {\n var l = list[i];\n if (l.listener === listener && l.capture === capture) {\n if (list.length === 1) {\n this._listeners[type] = undefined;\n }\n else {\n list.splice(i, 1);\n }\n return;\n }\n }\n }\n }\n },\n\n // This is the public API for dispatching untrusted public events.\n // See _dispatchEvent for the implementation\n dispatchEvent: function dispatchEvent(event) {\n // Dispatch an untrusted event\n return this._dispatchEvent(event, false);\n },\n\n //\n // See DOMCore §4.4\n // XXX: I'll probably need another version of this method for\n // internal use, one that does not set isTrusted to false.\n // XXX: see Document._dispatchEvent: perhaps that and this could\n // call a common internal function with different settings of\n // a trusted boolean argument\n //\n // XXX:\n // The spec has changed in how to deal with handlers registered\n // on idl or content attributes rather than with addEventListener.\n // Used to say that they always ran first. That's how webkit does it\n // Spec now says that they run in a position determined by\n // when they were first set. FF does it that way. See:\n // http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#event-handlers\n //\n _dispatchEvent: function _dispatchEvent(event, trusted) {\n if (typeof trusted !== 'boolean') trusted = false;\n function invoke(target, event) {\n var type = event.type, phase = event.eventPhase;\n event.currentTarget = target;\n\n // If there was an individual handler defined, invoke it first\n // XXX: see comment above: this shouldn't always be first.\n if (phase !== Event.CAPTURING_PHASE &&\n target._handlers && target._handlers[type])\n {\n var handler = target._handlers[type];\n var rv;\n if (typeof handler === 'function') {\n rv=handler.call(event.currentTarget, event);\n }\n else {\n var f = handler.handleEvent;\n if (typeof f !== 'function')\n throw new TypeError('handleEvent property of ' +\n 'event handler object is' +\n 'not a function.');\n rv=f.call(handler, event);\n }\n\n switch(event.type) {\n case 'mouseover':\n if (rv === true) // Historical baggage\n event.preventDefault();\n break;\n case 'beforeunload':\n // XXX: eventually we need a special case here\n /* falls through */\n default:\n if (rv === false)\n event.preventDefault();\n break;\n }\n }\n\n // Now invoke list list of listeners for this target and type\n var list = target._listeners && target._listeners[type];\n if (!list) return;\n list = list.slice();\n for(var i = 0, n = list.length; i < n; i++) {\n if (event._immediatePropagationStopped) return;\n var l = list[i];\n if ((phase === Event.CAPTURING_PHASE && !l.capture) ||\n (phase === Event.BUBBLING_PHASE && l.capture))\n continue;\n if (l.f) {\n l.f.call(event.currentTarget, event);\n }\n else {\n var fn = l.listener.handleEvent;\n if (typeof fn !== 'function')\n throw new TypeError('handleEvent property of event listener object is not a function.');\n fn.call(l.listener, event);\n }\n }\n }\n\n if (!event._initialized || event._dispatching) utils.InvalidStateError();\n event.isTrusted = trusted;\n\n // Begin dispatching the event now\n event._dispatching = true;\n event.target = this;\n\n // Build the list of targets for the capturing and bubbling phases\n // XXX: we'll eventually have to add Window to this list.\n var ancestors = [];\n for(var n = this.parentNode; n; n = n.parentNode)\n ancestors.push(n);\n\n // Capturing phase\n event.eventPhase = Event.CAPTURING_PHASE;\n for(var i = ancestors.length-1; i >= 0; i--) {\n invoke(ancestors[i], event);\n if (event._propagationStopped) break;\n }\n\n // At target phase\n if (!event._propagationStopped) {\n event.eventPhase = Event.AT_TARGET;\n invoke(this, event);\n }\n\n // Bubbling phase\n if (event.bubbles && !event._propagationStopped) {\n event.eventPhase = Event.BUBBLING_PHASE;\n for(var ii = 0, nn = ancestors.length; ii < nn; ii++) {\n invoke(ancestors[ii], event);\n if (event._propagationStopped) break;\n }\n }\n\n event._dispatching = false;\n event.eventPhase = Event.AT_TARGET;\n event.currentTarget = null;\n\n // Deal with mouse events and figure out when\n // a click has happened\n if (trusted && !event.defaultPrevented && event instanceof MouseEvent) {\n switch(event.type) {\n case 'mousedown':\n this._armed = {\n x: event.clientX,\n y: event.clientY,\n t: event.timeStamp\n };\n break;\n case 'mouseout':\n case 'mouseover':\n this._armed = null;\n break;\n case 'mouseup':\n if (this._isClick(event)) this._doClick(event);\n this._armed = null;\n break;\n }\n }\n\n\n\n return !event.defaultPrevented;\n },\n\n // Determine whether a click occurred\n // XXX We don't support double clicks for now\n _isClick: function(event) {\n return (this._armed !== null &&\n event.type === 'mouseup' &&\n event.isTrusted &&\n event.button === 0 &&\n event.timeStamp - this._armed.t < 1000 &&\n Math.abs(event.clientX - this._armed.x) < 10 &&\n Math.abs(event.clientY - this._armed.Y) < 10);\n },\n\n // Clicks are handled like this:\n // http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#interactive-content-0\n //\n // Note that this method is similar to the HTMLElement.click() method\n // The event argument must be the trusted mouseup event\n _doClick: function(event) {\n if (this._click_in_progress) return;\n this._click_in_progress = true;\n\n // Find the nearest enclosing element that is activatable\n // An element is activatable if it has a\n // _post_click_activation_steps hook\n var activated = this;\n while(activated && !activated._post_click_activation_steps)\n activated = activated.parentNode;\n\n if (activated && activated._pre_click_activation_steps) {\n activated._pre_click_activation_steps();\n }\n\n var click = this.ownerDocument.createEvent('MouseEvent');\n click.initMouseEvent('click', true, true,\n this.ownerDocument.defaultView, 1,\n event.screenX, event.screenY,\n event.clientX, event.clientY,\n event.ctrlKey, event.altKey,\n event.shiftKey, event.metaKey,\n event.button, null);\n\n var result = this._dispatchEvent(click, true);\n\n if (activated) {\n if (result) {\n // This is where hyperlinks get followed, for example.\n if (activated._post_click_activation_steps)\n activated._post_click_activation_steps(click);\n }\n else {\n if (activated._cancelled_activation_steps)\n activated._cancelled_activation_steps();\n }\n }\n },\n\n //\n // An event handler is like an event listener, but it registered\n // by setting an IDL or content attribute like onload or onclick.\n // There can only be one of these at a time for any event type.\n // This is an internal method for the attribute accessors and\n // content attribute handlers that need to register events handlers.\n // The type argument is the same as in addEventListener().\n // The handler argument is the same as listeners in addEventListener:\n // it can be a function or an object. Pass null to remove any existing\n // handler. Handlers are always invoked before any listeners of\n // the same type. They are not invoked during the capturing phase\n // of event dispatch.\n //\n _setEventHandler: function _setEventHandler(type, handler) {\n if (!this._handlers) this._handlers = Object.create(null);\n this._handlers[type] = handler;\n },\n\n _getEventHandler: function _getEventHandler(type) {\n return (this._handlers && this._handlers[type]) || null;\n }\n\n};\n","\"use strict\";\nvar utils = require('./utils');\n\nvar LinkedList = module.exports = {\n // basic validity tests on a circular linked list a\n valid: function(a) {\n utils.assert(a, \"list falsy\");\n utils.assert(a._previousSibling, \"previous falsy\");\n utils.assert(a._nextSibling, \"next falsy\");\n // xxx check that list is actually circular\n return true;\n },\n // insert a before b\n insertBefore: function(a, b) {\n utils.assert(LinkedList.valid(a) && LinkedList.valid(b));\n var a_first = a, a_last = a._previousSibling;\n var b_first = b, b_last = b._previousSibling;\n a_first._previousSibling = b_last;\n a_last._nextSibling = b_first;\n b_last._nextSibling = a_first;\n b_first._previousSibling = a_last;\n utils.assert(LinkedList.valid(a) && LinkedList.valid(b));\n },\n // replace a single node a with a list b (which could be null)\n replace: function(a, b) {\n utils.assert(LinkedList.valid(a) && (b===null || LinkedList.valid(b)));\n if (b!==null) {\n LinkedList.insertBefore(b, a);\n }\n LinkedList.remove(a);\n utils.assert(LinkedList.valid(a) && (b===null || LinkedList.valid(b)));\n },\n // remove single node a from its list\n remove: function(a) {\n utils.assert(LinkedList.valid(a));\n var prev = a._previousSibling;\n if (prev === a) { return; }\n var next = a._nextSibling;\n prev._nextSibling = next;\n next._previousSibling = prev;\n a._previousSibling = a._nextSibling = a;\n utils.assert(LinkedList.valid(a));\n }\n};\n","\"use strict\";\nmodule.exports = {\n // NOTE: The `serializeOne()` function used to live on the `Node.prototype`\n // as a private method `Node#_serializeOne(child)`, however that requires\n // a megamorphic property access `this._serializeOne` just to get to the\n // method, and this is being done on lots of different `Node` subclasses,\n // which puts a lot of pressure on V8's megamorphic stub cache. So by\n // moving the helper off of the `Node.prototype` and into a separate\n // function in this helper module, we get a monomorphic property access\n // `NodeUtils.serializeOne` to get to the function and reduce pressure\n // on the megamorphic stub cache.\n // See https://github.com/fgnass/domino/pull/142 for more information.\n serializeOne: serializeOne,\n\n // Export util functions so that we can run extra test for them.\n // Note: we prefix function names with `ɵ`, similar to what we do\n // with internal functions in Angular packages.\n ɵescapeMatchingClosingTag: escapeMatchingClosingTag,\n ɵescapeClosingCommentTag: escapeClosingCommentTag,\n ɵescapeProcessingInstructionContent: escapeProcessingInstructionContent\n};\n\nvar utils = require('./utils');\nvar NAMESPACE = utils.NAMESPACE;\n\nvar hasRawContent = {\n STYLE: true,\n SCRIPT: true,\n XMP: true,\n IFRAME: true,\n NOEMBED: true,\n NOFRAMES: true,\n PLAINTEXT: true\n};\n\nvar emptyElements = {\n area: true,\n base: true,\n basefont: true,\n bgsound: true,\n br: true,\n col: true,\n embed: true,\n frame: true,\n hr: true,\n img: true,\n input: true,\n keygen: true,\n link: true,\n meta: true,\n param: true,\n source: true,\n track: true,\n wbr: true\n};\n\nvar extraNewLine = {\n /* Removed in https://github.com/whatwg/html/issues/944\n pre: true,\n textarea: true,\n listing: true\n */\n};\n\nconst ESCAPE_REGEXP = /[&<>\\u00A0]/g;\nconst ESCAPE_ATTR_REGEXP = /[&\"<>\\u00A0]/g;\n\nfunction escape(s) {\n if (!ESCAPE_REGEXP.test(s)) {\n // nothing to do, fast path\n return s;\n }\n\n return s.replace(ESCAPE_REGEXP, (c) => {\n switch (c) {\n case \"&\":\n return \"&amp;\";\n case \"<\":\n return \"&lt;\";\n case \">\":\n return \"&gt;\";\n case \"\\u00A0\":\n return \"&nbsp;\";\n }\n });\n}\n\nfunction escapeAttr(s) {\n if (!ESCAPE_ATTR_REGEXP.test(s)) {\n // nothing to do, fast path\n return s;\n }\n\n return s.replace(ESCAPE_ATTR_REGEXP, (c) => {\n switch (c) {\n case \"<\":\n return \"&lt;\";\n case \">\":\n return \"&gt;\";\n case \"&\":\n return \"&amp;\";\n case '\"':\n return \"&quot;\";\n case \"\\u00A0\":\n return \"&nbsp;\";\n }\n });\n}\n\nfunction attrname(a) {\n var ns = a.namespaceURI;\n if (!ns)\n return a.localName;\n if (ns === NAMESPACE.XML)\n return 'xml:' + a.localName;\n if (ns === NAMESPACE.XLINK)\n return 'xlink:' + a.localName;\n\n if (ns === NAMESPACE.XMLNS) {\n if (a.localName === 'xmlns') return 'xmlns';\n else return 'xmlns:' + a.localName;\n }\n return a.name;\n}\n\n/**\n * Escapes matching closing tag in a raw text.\n *\n * For example, given `<style>#text(</style><script></script>)</style>`,\n * the parent tag would by \"style\" and the raw text is\n * \"</style><script></script>\". If we come across a matching closing tag\n * (in out case `</style>`) - replace `<` with `&lt;` to avoid unexpected\n * and unsafe behavior after de-serialization.\n */\nfunction escapeMatchingClosingTag(rawText, parentTag) {\n const parentClosingTag = '</' + parentTag;\n if (!rawText.toLowerCase().includes(parentClosingTag)) {\n return rawText; // fast path\n }\n const result = [...rawText];\n const matches = rawText.matchAll(new RegExp(parentClosingTag, 'ig'));\n for (const match of matches) {\n result[match.index] = '&lt;';\n }\n return result.join('');\n}\n\nconst CLOSING_COMMENT_REGEXP = /--!?>/;\n\n/**\n * Escapes closing comment tag in a comment content.\n *\n * For example, given `#comment('-->')`, the content of a comment would be\n * updated to `--&gt;` to avoid unexpected and unsafe behavior after\n * de-serialization.\n */\nfunction escapeClosingCommentTag(rawContent) {\n if (!CLOSING_COMMENT_REGEXP.test(rawContent)) {\n return rawContent; // fast path\n }\n return rawContent.replace(/(--\\!?)>/g, '$1&gt;');\n}\n\n/**\n * Escapes processing instruction content by replacing `>` with `&gt`.\n */\nfunction escapeProcessingInstructionContent(rawContent) {\n return rawContent.includes('>')\n ? rawContent.replaceAll('>', '&gt;')\n : rawContent;\n}\n\nfunction serializeOne(kid, parent) {\n var s = '';\n switch(kid.nodeType) {\n case 1: //ELEMENT_NODE\n var ns = kid.namespaceURI;\n var html = ns === NAMESPACE.HTML;\n var tagname = (html || ns === NAMESPACE.SVG || ns === NAMESPACE.MATHML) ? kid.localName : kid.tagName;\n\n s += '<' + tagname;\n\n for(var j = 0, k = kid._numattrs; j < k; j++) {\n var a = kid._attr(j);\n s += ' ' + attrname(a);\n if (a.value !== undefined) s += '=\"' + escapeAttr(a.value) + '\"';\n }\n s += '>';\n\n if (!(html && emptyElements[tagname])) {\n var ss = kid.serialize();\n // If an element can have raw content, this content may\n // potentially require escaping to avoid XSS.\n if (hasRawContent[tagname.toUpperCase()]) {\n ss = escapeMatchingClosingTag(ss, tagname);\n }\n if (html && extraNewLine[tagname] && ss.charAt(0)==='\\n') s += '\\n';\n // Serialize children and add end tag for all others\n s += ss;\n s += '</' + tagname + '>';\n }\n break;\n case 3: //TEXT_NODE\n case 4: //CDATA_SECTION_NODE\n var parenttag;\n if (parent.nodeType === 1 /*ELEMENT_NODE*/ &&\n parent.namespaceURI === NAMESPACE.HTML)\n parenttag = parent.tagName;\n else\n parenttag = '';\n\n if (hasRawContent[parenttag] ||\n (parenttag==='NOSCRIPT' && parent.ownerDocument._scripting_enabled)) {\n s += kid.data;\n } else {\n s += escape(kid.data);\n }\n break;\n case 8: //COMMENT_NODE\n s += '<!--' + escapeClosingCommentTag(kid.data) + '-->';\n break;\n case 7: //PROCESSING_INSTRUCTION_NODE\n const content = escapeProcessingInstructionContent(kid.data);\n s += '<?' + kid.target + ' ' + content + '?>';\n break;\n case 10: //DOCUMENT_TYPE_NODE\n s += '<!DOCTYPE ' + kid.name;\n\n if (false) {\n // Latest HTML serialization spec omits the public/system ID\n if (kid.publicID) {\n s += ' PUBLIC \"' + kid.publicId + '\"';\n }\n\n if (kid.systemId) {\n s += ' \"' + kid.systemId + '\"';\n }\n }\n\n s += '>';\n break;\n default:\n utils.InvalidStateError();\n }\n return s;\n}\n","\"use strict\";\nmodule.exports = Node;\n\nvar EventTarget = require('./EventTarget');\nvar LinkedList = require('./LinkedList');\nvar NodeUtils = require('./NodeUtils');\nvar utils = require('./utils');\n\n// All nodes have a nodeType and an ownerDocument.\n// Once inserted, they also have a parentNode.\n// This is an abstract class; all nodes in a document are instances\n// of a subtype, so all the properties are defined by more specific\n// constructors.\nfunction Node() {\n EventTarget.call(this);\n this.parentNode = null;\n this._nextSibling = this._previousSibling = this;\n this._index = undefined;\n}\n\nvar ELEMENT_NODE = Node.ELEMENT_NODE = 1;\nvar ATTRIBUTE_NODE = Node.ATTRIBUTE_NODE = 2;\nvar TEXT_NODE = Node.TEXT_NODE = 3;\nvar CDATA_SECTION_NODE = Node.CDATA_SECTION_NODE = 4;\nvar ENTITY_REFERENCE_NODE = Node.ENTITY_REFERENCE_NODE = 5;\nvar ENTITY_NODE = Node.ENTITY_NODE = 6;\nvar PROCESSING_INSTRUCTION_NODE = Node.PROCESSING_INSTRUCTION_NODE = 7;\nvar COMMENT_NODE = Node.COMMENT_NODE = 8;\nvar DOCUMENT_NODE = Node.DOCUMENT_NODE = 9;\nvar DOCUMENT_TYPE_NODE = Node.DOCUMENT_TYPE_NODE = 10;\nvar DOCUMENT_FRAGMENT_NODE = Node.DOCUMENT_FRAGMENT_NODE = 11;\nvar NOTATION_NODE = Node.NOTATION_NODE = 12;\n\nvar DOCUMENT_POSITION_DISCONNECTED = Node.DOCUMENT_POSITION_DISCONNECTED = 0x01;\nvar DOCUMENT_POSITION_PRECEDING = Node.DOCUMENT_POSITION_PRECEDING = 0x02;\nvar DOCUMENT_POSITION_FOLLOWING = Node.DOCUMENT_POSITION_FOLLOWING = 0x04;\nvar DOCUMENT_POSITION_CONTAINS = Node.DOCUMENT_POSITION_CONTAINS = 0x08;\nvar DOCUMENT_POSITION_CONTAINED_BY = Node.DOCUMENT_POSITION_CONTAINED_BY = 0x10;\nvar DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20;\n\nNode.prototype = Object.create(EventTarget.prototype, {\n\n // Node that are not inserted into the tree inherit a null parent\n\n // XXX: the baseURI attribute is defined by dom core, but\n // a correct implementation of it requires HTML features, so\n // we'll come back to this later.\n baseURI: { get: utils.nyi },\n\n parentElement: { get: function() {\n return (this.parentNode && this.parentNode.nodeType===ELEMENT_NODE) ? this.parentNode : null;\n }},\n\n hasChildNodes: { value: utils.shouldOverride },\n\n firstChild: { get: utils.shouldOverride },\n\n lastChild: { get: utils.shouldOverride },\n\n isConnected: {\n get: function () {\n let node = this;\n while (node != null) {\n if (node.nodeType === Node.DOCUMENT_NODE) {\n return true;\n }\n\n node = node.parentNode;\n if (node != null && node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {\n node = node.host;\n }\n }\n return false;\n },\n },\n\n previousSibling: { get: function() {\n var parent = this.parentNode;\n if (!parent) return null;\n if (this === parent.firstChild) return null;\n return this._previousSibling;\n }},\n\n nextSibling: { get: function() {\n var parent = this.parentNode, next = this._nextSibling;\n if (!parent) return null;\n if (next === parent.firstChild) return null;\n return next;\n }},\n\n textContent: {\n // Should override for DocumentFragment/Element/Attr/Text/PI/Comment\n get: function() { return null; },\n set: function(v) { /* do nothing */ },\n },\n\n innerText: {\n // Should override for DocumentFragment/Element/Attr/Text/PI/Comment\n get: function() { return null; },\n set: function(v) { /* do nothing */ },\n },\n\n _countChildrenOfType: { value: function(type) {\n var sum = 0;\n for (var kid = this.firstChild; kid !== null; kid = kid.nextSibling) {\n if (kid.nodeType === type) sum++;\n }\n return sum;\n }},\n\n _ensureInsertValid: { value: function _ensureInsertValid(node, child, isPreinsert) {\n var parent = this, i, kid;\n if (!node.nodeType) throw new TypeError('not a node');\n // 1. If parent is not a Document, DocumentFragment, or Element\n // node, throw a HierarchyRequestError.\n switch (parent.nodeType) {\n case DOCUMENT_NODE:\n case DOCUMENT_FRAGMENT_NODE:\n case ELEMENT_NODE:\n break;\n default: utils.HierarchyRequestError();\n }\n // 2. If node is a host-including inclusive ancestor of parent,\n // throw a HierarchyRequestError.\n if (node.isAncestor(parent)) utils.HierarchyRequestError();\n // 3. If child is not null and its parent is not parent, then\n // throw a NotFoundError. (replaceChild omits the 'child is not null'\n // and throws a TypeError here if child is null.)\n if (child !== null || !isPreinsert) {\n if (child.parentNode !== parent) utils.NotFoundError();\n }\n // 4. If node is not a DocumentFragment, DocumentType, Element,\n // Text, ProcessingInstruction, or Comment node, throw a\n // HierarchyRequestError.\n switch (node.nodeType) {\n case DOCUMENT_FRAGMENT_NODE:\n case DOCUMENT_TYPE_NODE:\n case ELEMENT_NODE:\n case TEXT_NODE:\n case PROCESSING_INSTRUCTION_NODE:\n case COMMENT_NODE:\n break;\n default: utils.HierarchyRequestError();\n }\n // 5. If either node is a Text node and parent is a document, or\n // node is a doctype and parent is not a document, throw a\n // HierarchyRequestError.\n // 6. If parent is a document, and any of the statements below, switched\n // on node, are true, throw a HierarchyRequestError.\n if (parent.nodeType === DOCUMENT_NODE) {\n switch (node.nodeType) {\n case TEXT_NODE:\n utils.HierarchyRequestError();\n break;\n case DOCUMENT_FRAGMENT_NODE:\n // 6a1. If node has more than one element child or has a Text\n // node child.\n if (node._countChildrenOfType(TEXT_NODE) > 0)\n utils.HierarchyRequestError();\n switch (node._countChildrenOfType(ELEMENT_NODE)) {\n case 0:\n break;\n case 1:\n // 6a2. Otherwise, if node has one element child and either\n // parent has an element child, child is a doctype, or child\n // is not null and a doctype is following child. [preinsert]\n // 6a2. Otherwise, if node has one element child and either\n // parent has an element child that is not child or a\n // doctype is following child. [replaceWith]\n if (child !== null /* always true here for replaceWith */) {\n if (isPreinsert && child.nodeType === DOCUMENT_TYPE_NODE)\n utils.HierarchyRequestError();\n for (kid = child.nextSibling; kid !== null; kid = kid.nextSibling) {\n if (kid.nodeType === DOCUMENT_TYPE_NODE)\n utils.HierarchyRequestError();\n }\n }\n i = parent._countChildrenOfType(ELEMENT_NODE);\n if (isPreinsert) {\n // \"parent has an element child\"\n if (i > 0)\n utils.HierarchyRequestError();\n } else {\n // \"parent has an element child that is not child\"\n if (i > 1 || (i === 1 && child.nodeType !== ELEMENT_NODE))\n utils.HierarchyRequestError();\n }\n break;\n default: // 6a1, continued. (more than one Element child)\n utils.HierarchyRequestError();\n }\n break;\n case ELEMENT_NODE:\n // 6b. parent has an element child, child is a doctype, or\n // child is not null and a doctype is following child. [preinsert]\n // 6b. parent has an element child that is not child or a\n // doctype is following child. [replaceWith]\n if (child !== null /* always true here for replaceWith */) {\n if (isPreinsert && child.nodeType === DOCUMENT_TYPE_NODE)\n utils.HierarchyRequestError();\n for (kid = child.nextSibling; kid !== null; kid = kid.nextSibling) {\n if (kid.nodeType === DOCUMENT_TYPE_NODE)\n utils.HierarchyRequestError();\n }\n }\n i = parent._countChildrenOfType(ELEMENT_NODE);\n if (isPreinsert) {\n // \"parent has an element child\"\n if (i > 0)\n utils.HierarchyRequestError();\n } else {\n // \"parent has an element child that is not child\"\n if (i > 1 || (i === 1 && child.nodeType !== ELEMENT_NODE))\n utils.HierarchyRequestError();\n }\n break;\n case DOCUMENT_TYPE_NODE:\n // 6c. parent has a doctype child, child is non-null and an\n // element is preceding child, or child is null and parent has\n // an element child. [preinsert]\n // 6c. parent has a doctype child that is not child, or an\n // element is preceding child. [replaceWith]\n if (child === null) {\n if (parent._countChildrenOfType(ELEMENT_NODE))\n utils.HierarchyRequestError();\n } else {\n // child is always non-null for [replaceWith] case\n for (kid = parent.firstChild; kid !== null; kid = kid.nextSibling) {\n if (kid === child) break;\n if (kid.nodeType === ELEMENT_NODE)\n utils.HierarchyRequestError();\n }\n }\n i = parent._countChildrenOfType(DOCUMENT_TYPE_NODE);\n if (isPreinsert) {\n // \"parent has an doctype child\"\n if (i > 0)\n utils.HierarchyRequestError();\n } else {\n // \"parent has an doctype child that is not child\"\n if (i > 1 || (i === 1 && child.nodeType !== DOCUMENT_TYPE_NODE))\n utils.HierarchyRequestError();\n }\n break;\n }\n } else {\n // 5, continued: (parent is not a document)\n if (node.nodeType === DOCUMENT_TYPE_NODE) utils.HierarchyRequestError();\n }\n }},\n\n insertBefore: { value: function insertBefore(node, child) {\n var parent = this;\n // 1. Ensure pre-insertion validity\n parent._ensureInsertValid(node, child, true);\n // 2. Let reference child be child.\n var refChild = child;\n // 3. If reference child is node, set it to node's next sibling\n if (refChild === node) { refChild = node.nextSibling; }\n // 4. Adopt node into parent's node document.\n parent.doc.adoptNode(node);\n // 5. Insert node into parent before reference child.\n node._insertOrReplace(parent, refChild, false);\n // 6. Return node\n return node;\n }},\n\n\n appendChild: { value: function(child) {\n // This invokes _appendChild after doing validity checks.\n return this.insertBefore(child, null);\n }},\n\n _appendChild: { value: function(child) {\n child._insertOrReplace(this, null, false);\n }},\n\n removeChild: { value: function removeChild(child) {\n var parent = this;\n if (!child.nodeType) throw new TypeError('not a node');\n if (child.parentNode !== parent) utils.NotFoundError();\n child.remove();\n return child;\n }},\n\n // To replace a `child` with `node` within a `parent` (this)\n replaceChild: { value: function replaceChild(node, child) {\n var parent = this;\n // Ensure validity (slight differences from pre-insertion check)\n parent._ensureInsertValid(node, child, false);\n // Adopt node into parent's node document.\n if (node.doc !== parent.doc) {\n // XXX adoptNode has side-effect of removing node from its parent\n // and generating a mutation event, thus causing the _insertOrReplace\n // to generate two deletes and an insert instead of a 'move'\n // event. It looks like the new MutationObserver stuff avoids\n // this problem, but for now let's only adopt (ie, remove `node`\n // from its parent) here if we need to.\n parent.doc.adoptNode(node);\n }\n // Do the replace.\n node._insertOrReplace(parent, child, true);\n return child;\n }},\n\n // See: http://ejohn.org/blog/comparing-document-position/\n contains: { value: function contains(node) {\n if (node === null) { return false; }\n if (this === node) { return true; /* inclusive descendant */ }\n /* jshint bitwise: false */\n return (this.compareDocumentPosition(node) &\n DOCUMENT_POSITION_CONTAINED_BY) !== 0;\n }},\n\n compareDocumentPosition: { value: function compareDocumentPosition(that){\n // Basic algorithm for finding the relative position of two nodes.\n // Make a list the ancestors of each node, starting with the\n // document element and proceeding down to the nodes themselves.\n // Then, loop through the lists, looking for the first element\n // that differs. The order of those two elements give the\n // order of their descendant nodes. Or, if one list is a prefix\n // of the other one, then that node contains the other.\n\n if (this === that) return 0;\n\n // If they're not owned by the same document or if one is rooted\n // and one is not, then they're disconnected.\n if (this.doc !== that.doc ||\n this.rooted !== that.rooted)\n return (DOCUMENT_POSITION_DISCONNECTED +\n DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC);\n\n // Get arrays of ancestors for this and that\n var these = [], those = [];\n for(var n = this; n !== null; n = n.parentNode) these.push(n);\n for(n = that; n !== null; n = n.parentNode) those.push(n);\n these.reverse(); // So we start with the outermost\n those.reverse();\n\n if (these[0] !== those[0]) // No common ancestor\n return (DOCUMENT_POSITION_DISCONNECTED +\n DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC);\n\n n = Math.min(these.length, those.length);\n for(var i = 1; i < n; i++) {\n if (these[i] !== those[i]) {\n // We found two different ancestors, so compare\n // their positions\n if