{"version":3,"sources":["../../../../../../src/build/webpack/loaders/next-style-loader/runtime/injectStylesIntoStyleTag.ts"],"sourcesContent":["/// \n\nconst isOldIE = (function isOldIE() {\n let memo: any\n\n return function memorize() {\n if (typeof memo === 'undefined') {\n // Test for IE <= 9 as proposed by Browserhacks\n // @see http://browserhacks.com/#hack-e71d8692f65334173fee715c222cb805\n // Tests for existence of standard globals is to allow style-loader\n // to operate correctly into non-standard environments\n // @see https://github.com/webpack-contrib/style-loader/issues/177\n memo = Boolean(window && document && document.all && !window.atob)\n }\n\n return memo\n }\n})()\n\nconst getTargetElement = (function () {\n const memo: any = {}\n\n return function memorize(target: any) {\n if (typeof memo[target] === 'undefined') {\n let styleTarget: any = document.querySelector(target)\n\n // Special case to return head of iframe instead of iframe itself\n if (\n window.HTMLIFrameElement &&\n styleTarget instanceof window.HTMLIFrameElement\n ) {\n try {\n // This will throw an exception if access to iframe is blocked\n // due to cross-origin restrictions\n styleTarget = (styleTarget as any).contentDocument.head\n } catch (e) {\n // istanbul ignore next\n styleTarget = null\n }\n }\n\n memo[target] = styleTarget\n }\n\n return memo[target]\n }\n})()\n\nconst stylesInDom: any = []\n\nfunction getIndexByIdentifier(identifier: any) {\n let result = -1\n\n for (let i = 0; i < stylesInDom.length; i++) {\n if (stylesInDom[i].identifier === identifier) {\n result = i\n break\n }\n }\n\n return result\n}\n\nfunction modulesToDom(list: any, options: any) {\n const idCountMap: any = {}\n const identifiers = []\n\n for (let i = 0; i < list.length; i++) {\n const item = list[i]\n const id = options.base ? item[0] + options.base : item[0]\n const count = idCountMap[id] || 0\n const identifier = id + ' ' + count.toString()\n\n idCountMap[id] = count + 1\n\n const index = getIndexByIdentifier(identifier)\n const obj = {\n css: item[1],\n media: item[2],\n sourceMap: item[3],\n }\n\n if (index !== -1) {\n stylesInDom[index].references++\n stylesInDom[index].updater(obj)\n } else {\n stylesInDom.push({\n identifier: identifier,\n updater: addStyle(obj, options),\n references: 1,\n })\n }\n\n identifiers.push(identifier)\n }\n\n return identifiers\n}\n\nfunction insertStyleElement(options: any) {\n const style = document.createElement('style')\n const attributes = options.attributes || {}\n\n if (typeof attributes.nonce === 'undefined') {\n const nonce =\n typeof __webpack_nonce__ !== 'undefined' ? __webpack_nonce__ : null\n\n if (nonce) {\n attributes.nonce = nonce\n }\n }\n\n Object.keys(attributes).forEach(function (key) {\n style.setAttribute(key, attributes[key])\n })\n\n if (typeof options.insert === 'function') {\n options.insert(style)\n } else {\n const target = getTargetElement(options.insert || 'head')\n\n if (!target) {\n throw new Error(\n \"Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.\"\n )\n }\n\n target.appendChild(style)\n }\n\n return style\n}\n\nfunction removeStyleElement(style: any) {\n // istanbul ignore if\n if (style.parentNode === null) {\n return false\n }\n\n style.parentNode.removeChild(style)\n}\n\n/* istanbul ignore next */\nconst replaceText = (function replaceText() {\n const textStore: any = []\n\n return function replace(index: any, replacement: any) {\n textStore[index] = replacement\n\n return textStore.filter(Boolean).join('\\n')\n }\n})()\n\nfunction applyToSingletonTag(style: any, index: any, remove: any, obj: any) {\n const css = remove\n ? ''\n : obj.media\n ? '@media ' + obj.media + ' {' + obj.css + '}'\n : obj.css\n\n // For old IE\n /* istanbul ignore if */\n if (style.styleSheet) {\n style.styleSheet.cssText = replaceText(index, css)\n } else {\n const cssNode = document.createTextNode(css)\n const childNodes = style.childNodes\n\n if (childNodes[index]) {\n style.removeChild(childNodes[index])\n }\n\n if (childNodes.length) {\n style.insertBefore(cssNode, childNodes[index])\n } else {\n style.appendChild(cssNode)\n }\n }\n}\n\nfunction applyToTag(style: any, _options: any, obj: any) {\n let css = obj.css\n const media = obj.media\n const sourceMap = obj.sourceMap\n\n if (media) {\n style.setAttribute('media', media)\n } else {\n style.removeAttribute('media')\n }\n\n if (sourceMap && typeof btoa !== 'undefined') {\n css +=\n '\\n/*# sourceMappingURL=data:application/json;base64,' +\n btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))) +\n ' */'\n }\n\n // For old IE\n /* istanbul ignore if */\n if (style.styleSheet) {\n style.styleSheet.cssText = css\n } else {\n while (style.firstChild) {\n style.removeChild(style.firstChild)\n }\n\n style.appendChild(document.createTextNode(css))\n }\n}\n\nlet singleton: any = null\nlet singletonCounter = 0\n\nfunction addStyle(obj: any, options: any) {\n let style: any\n let update: any\n let remove: any\n\n if (options.singleton) {\n const styleIndex = singletonCounter++\n\n style = singleton || (singleton = insertStyleElement(options))\n\n update = applyToSingletonTag.bind(null, style, styleIndex, false)\n remove = applyToSingletonTag.bind(null, style, styleIndex, true)\n } else {\n style = insertStyleElement(options)\n\n update = applyToTag.bind(null, style, options)\n remove = function () {\n removeStyleElement(style)\n }\n }\n\n update(obj)\n\n return function updateStyle(newObj: any) {\n if (newObj) {\n if (\n newObj.css === obj.css &&\n newObj.media === obj.media &&\n newObj.sourceMap === obj.sourceMap\n ) {\n return\n }\n\n update((obj = newObj))\n } else {\n remove()\n }\n }\n}\n\nmodule.exports = function (list: any, options: any) {\n options = options || {}\n\n // Force single-tag solution on IE6-9, which has a hard limit on the # of