@schalkneethling/css-media-pseudo-polyfill 1.0.10 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/fn.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as polyfill } from "./polyfill-
|
|
1
|
+
import { t as polyfill } from "./polyfill-CiJgx85h.mjs";
|
|
2
2
|
export { polyfill };
|
package/dist/index.mjs
CHANGED
|
@@ -211,6 +211,21 @@ function rewriteStyleElements(unsupported) {
|
|
|
211
211
|
//#endregion
|
|
212
212
|
//#region src/rewrite-link.ts
|
|
213
213
|
/**
|
|
214
|
+
* Resolve relative url() references in CSS text to absolute URLs, using
|
|
215
|
+
* the stylesheet's own URL as the base. This is necessary because when CSS
|
|
216
|
+
* is fetched from a <link> and re-injected as an inline <style>, the browser
|
|
217
|
+
* resolves url() references relative to the document URL rather than the
|
|
218
|
+
* original stylesheet URL, breaking any relative paths (e.g. url('../images/bg.png')).
|
|
219
|
+
*
|
|
220
|
+
* Data URIs and absolute URLs (https?:, //, /) are left untouched.
|
|
221
|
+
*/
|
|
222
|
+
function resolveUrls(cssText, base) {
|
|
223
|
+
return cssText.replace(/url\(\s*(['"]?)(.*?)\1\s*\)/gi, (match, quote, path) => {
|
|
224
|
+
if (/^(?:data:|https?:|\/)/.test(path)) return match;
|
|
225
|
+
return `url(${quote}${new URL(path, base).href}${quote})`;
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
214
229
|
* Check whether a stylesheet URL is same-origin. The browser resolves
|
|
215
230
|
* relative hrefs to absolute URLs on the HTMLLinkElement.href property,
|
|
216
231
|
* so comparing the origin portion covers both relative paths and
|
|
@@ -243,6 +258,7 @@ async function processLinkSheet(link, unsupported) {
|
|
|
243
258
|
} catch {
|
|
244
259
|
return;
|
|
245
260
|
}
|
|
261
|
+
cssText = resolveUrls(cssText, href);
|
|
246
262
|
const rewritten = rewriteCss(cssText, unsupported);
|
|
247
263
|
link.setAttribute("data-polyfill-rewritten", "");
|
|
248
264
|
if (rewritten === null) return;
|
package/package.json
CHANGED