satoru-render 1.0.5 → 1.0.7

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/core.js CHANGED
@@ -470,10 +470,39 @@ export class SatoruBase {
470
470
  // Handle regular Uint8Array / ArrayBufferView
471
471
  if (data instanceof Uint8Array ||
472
472
  ArrayBuffer.isView(data)) {
473
- const uint8 = data instanceof Uint8Array
473
+ let finalUint8 = data instanceof Uint8Array
474
474
  ? data
475
475
  : new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
476
- await loadResourceData(r, uint8);
476
+ if (r.type === "css") {
477
+ const cssText = new TextDecoder().decode(finalUint8);
478
+ const isAbsolute = /^[a-z][a-z0-9+.-]*:/i.test(r.url) || r.url.startsWith("data:");
479
+ let cssBaseUrl = r.url;
480
+ if (!isAbsolute && baseUrl) {
481
+ try {
482
+ const base = /^[a-z][a-z0-9+.-]*:\/\//i.test(baseUrl)
483
+ ? baseUrl
484
+ : new URL(`file:///${baseUrl.replace(/\\/g, "/")}`).href;
485
+ cssBaseUrl = new URL(r.url, base).href;
486
+ }
487
+ catch (e) { }
488
+ }
489
+ if (cssBaseUrl) {
490
+ const rewrittenCss = cssText.replace(/url\(['"]?([^'")]+)['"]?\)/g, (match, urlParam) => {
491
+ if (urlParam.startsWith("data:") || /^[a-z][a-z0-9+.-]*:/i.test(urlParam)) {
492
+ return match;
493
+ }
494
+ try {
495
+ const newUrl = new URL(urlParam, cssBaseUrl).href;
496
+ return `url("${newUrl}")`;
497
+ }
498
+ catch (e) {
499
+ return match;
500
+ }
501
+ });
502
+ finalUint8 = new TextEncoder().encode(rewrittenCss);
503
+ }
504
+ }
505
+ await loadResourceData(r, finalUint8);
477
506
  }
478
507
  }
479
508
  catch (e) {
Binary file
package/dist/satoru.wasm CHANGED
Binary file