You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
8.1 KiB

4 years ago
{"ast":null,"code":"/**\n * When source maps are enabled, `style-loader` uses a link element with a data-uri to\n * embed the css on the page. This breaks all relative urls because now they are relative to a\n * bundle instead of the current page.\n *\n * One solution is to only use full urls, but that may be impossible.\n *\n * Instead, this function \"fixes\" the relative urls to be absolute according to the current page location.\n *\n * A rudimentary test suite is located at `test/fixUrls.js` and can be run via the `npm test` command.\n *\n */\nmodule.exports = function (css) {\n // get current location\n var location = typeof window !== \"undefined\" && window.location;\n\n if (!location) {\n throw new Error(\"fixUrls requires window.location\");\n } // blank or null?\n\n\n if (!css || typeof css !== \"string\") {\n return css;\n }\n\n var baseUrl = location.protocol + \"//\" + location.host;\n var currentDir = baseUrl + location.pathname.replace(/\\/[^\\/]*$/, \"/\"); // convert each url(...)\n\n /*\n This regular expression is just a way to recursively match brackets within\n a string.\n \t /url\\s*\\( = Match on the word \"url\" with any whitespace after it and then a parens\n ( = Start a capturing group\n (?: = Start a non-capturing group\n [^)(] = Match anything that isn't a parentheses\n | = OR\n \\( = Match a start parentheses\n (?: = Start another non-capturing groups\n [^)(]+ = Match anything that isn't a parentheses\n | = OR\n \\( = Match a start parentheses\n [^)(]* = Match anything that isn't a parentheses\n \\) = Match a end parentheses\n ) = End Group\n *\\) = Match anything and then a close parens\n ) = Close non-capturing group\n * = Match anything\n ) = Close capturing group\n \\) = Match a close parens\n \t /gi = Get all matches, not the first. Be case insensitive.\n */\n\n var fixedCss = css.replace(/url\\s*\\(((?:[^)(]|\\((?:[^)(]+|\\([^)(]*\\))*\\))*)\\)/gi, function (fullMatch, origUrl) {\n // strip quotes (if they exist)\n var unquotedOrigUrl = origUrl.trim().replace(/^\"(.*)\"$/, function (o, $1) {\n return $1;\n }).replace(/^'(.*)'$/, function (o, $1) {\n return $1;\n }); // already a full url? no change\n\n if (/^(#|data:|http:\\/\\/|https:\\/\\/|file:\\/\\/\\/|\\s*$)/i.test(unquotedOrigUrl)) {\n return fullMatch;\n } // convert the url to a full url\n\n\n var newUrl;\n\n if (unquotedOrigUrl.indexOf(\"//\") === 0) {\n //TODO: should we add protocol?\n newUrl = unquotedOrigUrl;\n } else if (unquotedOrigUrl.indexOf(\"/\") === 0) {\n // path should be relative to the base url\n newUrl = baseUrl + unquotedOrigUrl; // already starts with '/'\n } else {\n // path should be relative to current directory\n newUrl = currentDir + unquotedOrigUrl.replace(/^\\.\\//, \"\"); // Strip leading './'\n } // send back the fixed url(...)\n\n\n return \"url(\" + JSON.stringify(newUrl) + \")\";\n }); // send back the fixed css\n\n return fixedCss;\n};","map":{"version":3,"sources":["C:/Users/user/Documents/myapp/node_modules/style-loader/lib/urls.js"],"names":["module","exports","css","location","window","Error","baseUrl","protocol","host","currentDir","pathname","replace","fixedCss","fullMatch","origUrl","unquotedOrigUrl","trim","o","$1","test","newUrl","indexOf","JSON","stringify"],"mappings":"AACA;;;;;;;;;;;;AAaAA,MAAM,CAACC,OAAP,GAAiB,UAAUC,GAAV,EAAe;AAC9B;AACA,MAAIC,QAAQ,GAAG,OAAOC,MAAP,KAAkB,WAAlB,IAAiCA,MAAM,CAACD,QAAvD;;AAEA,MAAI,CAACA,QAAL,EAAe;AACb,UAAM,IAAIE,KAAJ,CAAU,kCAAV,CAAN;AACD,GAN6B,CAQ/B;;;AACA,MAAI,CAACH,GAAD,IAAQ,OAAOA,GAAP,KAAe,QAA3B,EAAqC;AACnC,WAAOA,GAAP;AACA;;AAED,MAAII,OAAO,GAAGH,QAAQ,CAACI,QAAT,GAAoB,IAApB,GAA2BJ,QAAQ,CAACK,IAAlD;AACA,MAAIC,UAAU,GAAGH,OAAO,GAAGH,QAAQ,CAACO,QAAT,CAAkBC,OAAlB,CAA0B,WAA1B,EAAuC,GAAvC,CAA3B,CAd8B,CAgB/B;;AACA;;;;;;;;;;;;;;;;;;;;;;;;