satoru-render 1.0.5 → 1.0.6

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.
@@ -601,7 +601,30 @@ var SatoruBase = class {
601
601
  }
602
602
  return;
603
603
  }
604
- if (data instanceof Uint8Array || ArrayBuffer.isView(data)) await loadResourceData(r, data instanceof Uint8Array ? data : new Uint8Array(data.buffer, data.byteOffset, data.byteLength));
604
+ if (data instanceof Uint8Array || ArrayBuffer.isView(data)) {
605
+ let finalUint8 = data instanceof Uint8Array ? data : new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
606
+ if (r.type === "css") {
607
+ const cssText = new TextDecoder().decode(finalUint8);
608
+ const isAbsolute = /^[a-z][a-z0-9+.-]*:/i.test(r.url) || r.url.startsWith("data:");
609
+ let cssBaseUrl = r.url;
610
+ if (!isAbsolute && baseUrl) try {
611
+ const base = /^[a-z][a-z0-9+.-]*:\/\//i.test(baseUrl) ? baseUrl : new URL(`file:///${baseUrl.replace(/\\/g, "/")}`).href;
612
+ cssBaseUrl = new URL(r.url, base).href;
613
+ } catch (e) {}
614
+ if (cssBaseUrl) {
615
+ const rewrittenCss = cssText.replace(/url\(['"]?([^'")]+)['"]?\)/g, (match, urlParam) => {
616
+ if (urlParam.startsWith("data:") || /^[a-z][a-z0-9+.-]*:/i.test(urlParam)) return match;
617
+ try {
618
+ return `url("${new URL(urlParam, cssBaseUrl).href}")`;
619
+ } catch (e) {
620
+ return match;
621
+ }
622
+ });
623
+ finalUint8 = new TextEncoder().encode(rewrittenCss);
624
+ }
625
+ }
626
+ await loadResourceData(r, finalUint8);
627
+ }
605
628
  } catch (e) {
606
629
  console.warn(`Failed to resolve resource: ${r.url}`, e);
607
630
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "satoru-render",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "High-fidelity HTML/CSS to SVG/PNG/PDF converter running in WebAssembly",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",