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CAAC,MAAM,IAAI,GAAG,EAC7B,QAAQ,CAAC,IAAI,KAAK,kCAAgC,QAAQ,CAAC,MAAM,cAAS,GAAG,CAAG,CAAC,CAAC,KAElF,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,UAAC,MAAM,EAAI;AAClC,kBAAQ,CAAC,IAAI,GAAG,MAAM,CAAC;AACvB,kBAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;SACxB,CAAC,CAAC;OACN,CAAC,CAAC;;GACJ;CACF,CAAC;;;AAGF,IAAM,gBAAgB,GAAG,KAAK,CAAC,WAAW,CAAC;AAC3C,KAAK,CAAC,WAAW,GAAG,UAAU,OAAO,EAAE,IAAI,EAAE;AAC3C,MAAM,OAAO,GAAG,QAAQ,CAAC;AACzB,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC;AAC7C,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACjC,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;;AAE5D,MAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,IAAI,EAC/F,OAAO,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,KAE5B,OAAO,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;CAC/B,CAAC","file":"jsdom_patches.js","sourcesContent":["// Fix things that JSDOM doesn't do quite right.\n\n\nconst DOM                  = require('./index');\nconst Fetch                = require('../fetch');\nconst resourceLoader       = require('jsdom/lib/jsdom/browser/resource-loader');\nconst Utils                = require('jsdom/lib/jsdom/utils');\nconst URL                  = require('url');\nconst createHTMLCollection = require('jsdom/lib/jsdom/living/html-collection').create;\n\n\nDOM.HTMLDocument.prototype.__defineGetter__('scripts', function() {\n  return createHTMLCollection(this, ()=> this.querySelectorAll('script'));\n});\n\n\n// Default behavior for clicking on links: navigate to new URL if specified.\nDOM.HTMLAnchorElement.prototype._eventDefaults =\n  Object.assign({}, DOM.HTMLElement.prototype._eventDefaults);\nDOM.HTMLAnchorElement.prototype._eventDefaults.click = function(event) {\n  const anchor = event.target;\n  if (!anchor.href)\n    return;\n\n  const window      = anchor.ownerDocument.defaultView;\n  const { browser } = window;\n  // Decide which window to open this link in\n  switch (anchor.target || '_self') {\n    case '_self': {   // navigate same window\n      window.location = anchor.href;\n      break;\n    }\n    case '_parent': { // navigate parent window\n      window.parent.location = anchor.href;\n      break;\n    }\n    case '_top': {    // navigate top window\n      window.top.location = anchor.href;\n      break;\n    }\n    default: { // open named window\n      browser.tabs.open({ name: anchor.target, url: anchor.href });\n      break;\n    }\n  }\n  browser.emit('link', anchor.href, anchor.target || '_self');\n};\n\n\n// Attempt to load the image, this will trigger a 'load' event when succesful\n// jsdom seemed to only queue the 'load' event\nDOM.HTMLImageElement.prototype._attrModified = function(name, value, oldVal) {\n  if (name === 'src' && value && value !== oldVal)\n    resourceLoader.load(this, value);\n  DOM.HTMLElement.prototype._attrModified.call(this, name, value, oldVal);\n};\n\n// Implement getClientRects\nDOM.HTMLElement.prototype.getClientRects = function () {\n  const style = this.style;\n\n  if (style && style.display === 'none') {\n    return [];\n  }\n\n  return [{\n    bottom: 0,\n    height: 0,\n    left: 0,\n    right: 0,\n    top: 0,\n    width: 0\n  }];\n};\n\nObject.defineProperty(DOM.HTMLElement.prototype, 'offsetHeight', {\n  get: function () {\n    return 0;\n  }\n});\n\nObject.defineProperty(DOM.HTMLElement.prototype, 'offsetWidth', {\n  get: function () {\n    return 0;\n  }\n});\n\n\n// Implement insertAdjacentHTML\nDOM.HTMLElement.prototype.insertAdjacentHTML = function(position, html) {\n  const { parentNode }  = this;\n  const container       = this.ownerDocument.createElementNS('http://www.w3.org/1999/xhtml', '_');\n  container.innerHTML   = html;\n\n  switch (position.toLowerCase()) {\n    case 'beforebegin': {\n      while (container.firstChild)\n        parentNode.insertBefore(container.firstChild, this);\n      break;\n    }\n    case 'afterbegin': {\n      let firstChild = this.firstChild;\n      while (container.lastChild)\n        firstChild = this.insertBefore(container.lastChild, firstChild);\n      break;\n    }\n    case 'beforeend': {\n      while (container.firstChild)\n        this.appendChild(container.firstChild);\n      break;\n    }\n    case 'afterend': {\n      let nextSibling = this.nextSibling;\n      while (container.lastChild)\n        nextSibling = parentNode.insertBefore(container.lastChild, nextSibling);\n      break;\n    }\n  }\n};\n\n\n// Implement documentElement.contains\n// e.g., if(document.body.contains(el)) { ... }\n// See https://developer.mozilla.org/en-US/docs/DOM/Node.contains\nDOM.Node.prototype.contains = function(otherNode) {\n  // DDOPSON-2012-08-16 -- This implementation is stolen from Sizzle's\n  // implementation of 'contains' (around line 1402).\n  // We actually can't call Sizzle.contains directly:\n  // * Because we define Node.contains, Sizzle will configure it's own\n  //   \"contains\" method to call us. (it thinks we are a native browser\n  //   implementation of \"contains\")\n  // * Thus, if we called Sizzle.contains, it would form an infinite loop.\n  //   Instead we use Sizzle's fallback implementation of \"contains\" based on\n  //   \"compareDocumentPosition\".\n  return !!(this.compareDocumentPosition(otherNode) & 16);\n};\n\n\n// Support for opacity style property.\nObject.defineProperty(DOM.CSSStyleDeclaration.prototype, 'opacity', {\n  get() {\n    const opacity = this.getPropertyValue('opacity');\n    return Number.isFinite(opacity) ? opacity.toString() : '';\n  },\n\n  set(opacity) {\n    if (opacity === null || opacity === undefined || opacity === '')\n      this.removeProperty('opacity');\n    else {\n      const value = parseFloat(opacity);\n      if (isFinite(value))\n        this._setProperty('opacity', value);\n    }\n  }\n});\n\n\n// Wrap dispatchEvent to support _windowInScope and error handling.\nconst jsdomDispatchEvent = DOM.EventTarget.prototype.dispatchEvent;\nDOM.EventTarget.prototype.dispatchEvent = function(event) {\n  // Could be node, window or document\n  const document = this._ownerDocument || this.document || this;\n  const window   = document.defaultView;\n  // Fail miserably on objects that don't have ownerDocument: nodes and XHR\n  // request have those\n  const { browser } = window;\n  browser.emit('event', event, this);\n\n  const originalInScope = browser._windowInScope;\n  try {\n    // The current window, postMessage and window.close need this\n    browser._windowInScope = window;\n    // Inline event handlers rely on window.event\n    window.event = event;\n    return jsdomDispatchEvent.call(this, event);\n  } finally {\n    delete window.event;\n    browser._windowInScope = originalInScope;\n  }\n};\n\n\n// Fix resource loading to keep track of in-progress requests. Need this to wait\n// for all resources (mainly JavaScript) to complete loading before terminating\n// browser.wait.\nresourceLoader.load = function(element, href, callback) {\n  const document      = element.ownerDocument;\n  const window        = document.defaultView;\n  const tagName       = element.tagName.toLowerCase();\n  const loadResource  = document.implementation._hasFeature('FetchExternalResources', tagName);\n  const url           = resourceLoader.resolveResourceUrl(document, href);\n\n  if (loadResource) {\n    // This guarantees that all scripts are executed in order, must add to the\n    // JSDOM queue before we add to the Zombie event queue.\n    const enqueued = this.enqueue(element, url, callback && callback.bind(element));\n    const request = new Fetch.Request(url);\n    window._eventQueue.http(request, (error, response)=> {\n      // Since this is used by resourceLoader that doesn't check the response,\n      // we're responsible to turn anything other than 2xx/3xx into an error\n      if (error)\n        enqueued(new Error('Network error'));\n      else if (response.status >= 400)\n        enqueued(new Error(`Server returned status code ${response.status} from ${url}`));\n      else\n        response._consume().then((buffer)=> {\n          response.body = buffer;\n          enqueued(null, buffer);\n        });\n    });\n  }\n};\n\n// Fix residual Node bug. See https://github.com/joyent/node/pull/14146\nconst jsdomResolveHref = Utils.resolveHref;\nUtils.resolveHref = function (baseUrl, href) {\n  const pattern = /file:?/;\n  const protocol = URL.parse(baseUrl).protocol;\n  const original = URL.parse(href);\n  const resolved = URL.parse(jsdomResolveHref(baseUrl, href));\n\n  if (!pattern.test(protocol) && pattern.test(original.protocol) && !original.host && resolved.host)\n    return URL.format(original);\n  else\n    return URL.format(resolved);\n};\n"]}