satoru-render 1.0.9 → 1.0.10

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.
@@ -250,14 +250,18 @@ let LogLevel = /* @__PURE__ */ function(LogLevel) {
250
250
  }({});
251
251
  //#endregion
252
252
  //#region src/core.ts
253
+ const emojiUrl = "https://cdn.jsdelivr.net/npm/@fontsource/noto-color-emoji/files/noto-color-emoji-emoji-400-normal.woff2";
253
254
  const DEFAULT_FONT_MAP = {
254
255
  "sans-serif": "https://fonts.googleapis.com/css2?family=Noto+Sans+JP",
255
256
  serif: "https://fonts.googleapis.com/css2?family=Noto+Serif+JP",
256
257
  monospace: "https://fonts.googleapis.com/css2?family=M+PLUS+1+Code",
257
258
  cursive: "https://fonts.googleapis.com/css2?family=Yuji+Syuku",
258
259
  fantasy: "https://fonts.googleapis.com/css2?family=Reggae+One",
259
- emoji: "https://cdn.jsdelivr.net/npm/@fontsource/noto-color-emoji/files/noto-color-emoji-emoji-400-normal.woff2",
260
- "Noto Color Emoji": "https://cdn.jsdelivr.net/npm/@fontsource/noto-color-emoji/files/noto-color-emoji-emoji-400-normal.woff2"
260
+ "Noto Color Emoji": emojiUrl,
261
+ emoji: emojiUrl,
262
+ "Noto Emoji": emojiUrl,
263
+ notocoloremoji: emojiUrl,
264
+ notoemoji: emojiUrl
261
265
  };
262
266
  /**
263
267
  * Parse unicode-range string into an array of [start, end] codepoint ranges.
@@ -455,6 +459,15 @@ var SatoruBase = class {
455
459
  async destroyInstance(inst) {
456
460
  (await this.getModule()).destroy_instance(inst);
457
461
  }
462
+ async loadFont(name, data) {
463
+ const mod = await this.getModule();
464
+ const inst = mod.create_instance();
465
+ try {
466
+ mod.load_font(inst, name, data);
467
+ } finally {
468
+ mod.destroy_instance(inst);
469
+ }
470
+ }
458
471
  async loadFallbackFont(data) {
459
472
  const mod = await this.getModule();
460
473
  const inst = mod.create_instance();
@@ -528,10 +541,6 @@ var SatoruBase = class {
528
541
  const instancePtr = mod.create_instance();
529
542
  mod.set_font_map(instancePtr, this.currentFontMap);
530
543
  try {
531
- if (fonts) for (const f of fonts) mod.load_font(instancePtr, f.name, f.data);
532
- if (options.fallbackFonts) for (const data of options.fallbackFonts) mod.load_fallback_font(instancePtr, data);
533
- if (images) for (const img of images) mod.load_image(instancePtr, img.name, img.url, img.width ?? 0, img.height ?? 0);
534
- if (css) mod.scan_css(instancePtr, css);
535
544
  const defaultResolver = (r) => this.resolveDefaultResource(r, baseUrl, options.userAgent);
536
545
  const resolver = options.resolveResource ? async (r) => {
537
546
  return await options.resolveResource(r, defaultResolver);
@@ -547,6 +556,20 @@ var SatoruBase = class {
547
556
  }
548
557
  return result;
549
558
  };
559
+ if (this.currentFontMap["notocoloremoji"]) {
560
+ const emojiUrl = this.currentFontMap["notocoloremoji"];
561
+ const res = await cachedResolver({
562
+ type: "font",
563
+ url: emojiUrl,
564
+ name: "notocoloremoji"
565
+ });
566
+ if (res && res instanceof Uint8Array) mod.load_font(instancePtr, "notocoloremoji", res);
567
+ else if (res && "fonts" in res) for (const f of res.fonts) mod.load_font(instancePtr, "notocoloremoji", f.data);
568
+ }
569
+ if (fonts) for (const f of fonts) mod.load_font(instancePtr, f.name, f.data);
570
+ if (options.fallbackFonts) for (const data of options.fallbackFonts) mod.load_fallback_font(instancePtr, data);
571
+ if (images) for (const img of images) mod.load_image(instancePtr, img.name, img.url, img.width ?? 0, img.height ?? 0);
572
+ if (css) mod.scan_css(instancePtr, css);
550
573
  const loadResourceData = (r, uint8) => {
551
574
  if (r.type === "image" && typeof createImageBitmap !== "undefined" && typeof OffscreenCanvas !== "undefined") return (async () => {
552
575
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "satoru-render",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
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",