@schalkneethling/css-media-pseudo-polyfill 1.0.6 → 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-BA69lY_2.mjs";
1
+ import { t as polyfill } from "./polyfill-CiJgx85h.mjs";
2
2
  export { polyfill };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as polyfill } from "./polyfill-BA69lY_2.mjs";
1
+ import { t as polyfill } from "./polyfill-CiJgx85h.mjs";
2
2
  //#region src/index.ts
3
3
  if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", () => polyfill());
4
4
  else polyfill();
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schalkneethling/css-media-pseudo-polyfill",
3
- "version": "1.0.6",
3
+ "version": "1.0.11",
4
4
  "description": "A CSS polyfill for media pseudo-classes (:playing, :paused, :seeking, :buffering, :stalled, :muted)",
5
5
  "keywords": [
6
6
  "audio",
@@ -23,7 +23,7 @@
23
23
  "author": "Schalk Neethling",
24
24
  "repository": {
25
25
  "type": "git",
26
- "url": "https://github.com/schalkneethling/css-media-pseudo-polyfill"
26
+ "url": "git+https://github.com/schalkneethling/css-media-pseudo-polyfill.git"
27
27
  },
28
28
  "files": [
29
29
  "dist"
@@ -34,6 +34,16 @@
34
34
  "./fn": "./dist/fn.mjs",
35
35
  "./package.json": "./package.json"
36
36
  },
37
+ "scripts": {
38
+ "build": "vp pack",
39
+ "dev": "vp pack --watch",
40
+ "test": "vp test",
41
+ "test:e2e": "playwright test",
42
+ "typecheck": "tsc --noEmit",
43
+ "release": "bumpp",
44
+ "prepublishOnly": "vp pack",
45
+ "prepare": "vp config"
46
+ },
37
47
  "dependencies": {
38
48
  "css-tree": "^3.1.0"
39
49
  },
@@ -48,12 +58,11 @@
48
58
  "vite-plus": "latest",
49
59
  "vitest": "npm:@voidzero-dev/vite-plus-test@latest"
50
60
  },
51
- "scripts": {
52
- "build": "vp pack",
53
- "dev": "vp pack --watch",
54
- "test": "vp test",
55
- "test:e2e": "playwright test",
56
- "typecheck": "tsc --noEmit",
57
- "release": "bumpp"
61
+ "packageManager": "pnpm@10.32.1",
62
+ "pnpm": {
63
+ "overrides": {
64
+ "vite": "npm:@voidzero-dev/vite-plus-core@latest",
65
+ "vitest": "npm:@voidzero-dev/vite-plus-test@latest"
66
+ }
58
67
  }
59
- }
68
+ }