satoru-render 1.0.4 → 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.
@@ -442,7 +442,8 @@ var SatoruBase = class {
442
442
  cropHeight: options.crop?.height ?? 0,
443
443
  fitPositionX: options.fitPosition?.x ?? .5,
444
444
  fitPositionY: options.fitPosition?.y ?? .5,
445
- backgroundColor: this.parseColor(options.backgroundColor)
445
+ backgroundColor: this.parseColor(options.backgroundColor),
446
+ mediaType: options.mediaType === "print" ? 1 : 0
446
447
  });
447
448
  if (!result) {
448
449
  if (options.format === "svg") return "";
@@ -600,7 +601,30 @@ var SatoruBase = class {
600
601
  }
601
602
  return;
602
603
  }
603
- 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
+ }
604
628
  } catch (e) {
605
629
  console.warn(`Failed to resolve resource: ${r.url}`, e);
606
630
  }
@@ -634,7 +658,8 @@ var SatoruBase = class {
634
658
  cropHeight: options.crop?.height ?? 0,
635
659
  fitPositionX: options.fitPosition?.x ?? .5,
636
660
  fitPositionY: options.fitPosition?.y ?? .5,
637
- backgroundColor: this.parseColor(options.backgroundColor)
661
+ backgroundColor: this.parseColor(options.backgroundColor),
662
+ mediaType: options.mediaType === "print" ? 1 : 0
638
663
  });
639
664
  if (!result) {
640
665
  if (format === "svg") return "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "satoru-render",
3
- "version": "1.0.4",
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",