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GAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,EAAa/C,QAGrB,IAAID,EAAS6C,EAAyBE,GAAY,CAGjD9C,QAAS,CAAC,GAOX,OAHAiD,EAAoBH,GAAU/C,EAAQA,EAAOC,QAAS6C,GAG/C9C,EAAOC,OACf,ECnB0B6C,CAAoB","sources":["webpack://check-if-css-is-disabled/./check-if-css-is-disabled.js","webpack://check-if-css-is-disabled/webpack/bootstrap","webpack://check-if-css-is-disabled/webpack/startup"],"sourcesContent":["module.exports = (params) => {\n  const justCheck = !!params?.justCheck\n  const exemptedIds = params?.exemptedIds || []\n\n  // check if any CSS assets fail to load\n  document.querySelectorAll('link[rel=\"stylesheet\"]').forEach(link => {\n    link.addEventListener('error', handleCssAssetFailingToLoad)\n  })\n\n  // use MutationObserver to attach error event listener to new link tags\n  const observer = new window.MutationObserver((mutationsList) => {\n    for (const mutation of mutationsList) {\n      if (mutation.type === 'childList') {\n        mutation.addedNodes.forEach(node => {\n          if (node.tagName === 'LINK' && node.rel === 'stylesheet') {\n            node.addEventListener('error', handleCssAssetFailingToLoad)\n          }\n        })\n      }\n    }\n  })\n\n  // start observing the document for added nodes\n  observer.observe(document.head, { childList: true, subtree: true })\n\n  function handleCssAssetFailingToLoad (errorEvent) {\n    if (errorEvent) window.linkTagError = true\n\n    // remove all stylesheets if any fail to load, but only if the justCheck flag is falsey\n    if (!justCheck && window.linkTagError) {\n      for (const link of document.querySelectorAll('link[rel=\"stylesheet\"]')) if (!exemptedIds.includes(link.id)) link.remove()\n      for (const style of document.querySelectorAll('style')) if (!exemptedIds.includes(style.id)) style.remove()\n    }\n    if (window.linkTagError) {\n      window.dispatchEvent(new CustomEvent('cssDisabled', {\n        detail: {\n          message: 'At least one stylesheet failed to load. It is unsafe to execute any further JavaScript if the CSS has not loaded properly.'\n        }\n      }))\n      return true\n    } else return !!errorEvent // return true if this function is called by an error event and return false if it is called directly below and no previous error has been logged\n  }\n\n  // test if the browser has explicitly disabled CSS\n  let cssDisabled = false // must be proven otherwise\n  const testElement = document.createElement('div')\n  testElement.style.position = 'absolute'\n  document.body.appendChild(testElement)\n  cssDisabled = document.defaultView.getComputedStyle(testElement, null).getPropertyValue('position') === 'static'\n  document.body.removeChild(testElement)\n\n  // if the justCheck flag is present, we only want to notify the developer that CSS is disabled, not take any actions\n  if (justCheck) {\n    if (cssDisabled) {\n      window.dispatchEvent(new CustomEvent('cssDisabled', {\n        detail: {\n          message: 'CSS is disabled. It is unsafe to execute any further JavaScript if the CSS has not loaded properly.'\n        }\n      }))\n      return true\n    } else return handleCssAssetFailingToLoad()\n  } else { // if the justCheck flag is not present, then stop execution of the JS if CSS is disabled\n    if (cssDisabled || handleCssAssetFailingToLoad()) throw new Error('CSS is disabled. It is unsafe to execute any further JavaScript if the CSS has not loaded properly.')\n    else return false\n  }\n}\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(597);\n"],"names":["module","exports","params","justCheck","exemptedIds","document","querySelectorAll","forEach","link","addEventListener","handleCssAssetFailingToLoad","errorEvent","window","linkTagError","includes","id","remove","style","dispatchEvent","CustomEvent","detail","message","MutationObserver","mutationsList","mutation","type","addedNodes","node","tagName","rel","observe","head","childList","subtree","cssDisabled","testElement","createElement","position","body","appendChild","defaultView","getComputedStyle","getPropertyValue","removeChild","Error","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__"],"sourceRoot":""}