@cardenelabs/dragon 0.40.0 → 0.41.1

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/export.js CHANGED
@@ -6247,6 +6247,10 @@ var LAUNCH_TEXT = {
6247
6247
  install: `Install playwright-core with ${INSTALL_ADD} and Chromium with ${INSTALL_CHROMIUM}`
6248
6248
  }
6249
6249
  };
6250
+ var FONT_TEXT = {
6251
+ ja: (faces) => `\u66F8\u304D\u51FA\u3057\u306B\u57CB\u3081\u308B\u5B57\u306E file \u3092 Chromium \u304C\u8AAD\u3081\u306A\u3044 (${faces.join("\u3001")})`,
6252
+ en: (faces) => `Chromium cannot read the font files embedded in the export (${faces.join("; ")})`
6253
+ };
6250
6254
  async function launch(lang) {
6251
6255
  const text2 = LAUNCH_TEXT[lang];
6252
6256
  let chromium;
@@ -6265,7 +6269,7 @@ function sizeOf(svg) {
6265
6269
  const [, width = "0", height = "0"] = /^<svg\b[^>]*?\swidth="(\d+)"\s+height="(\d+)"/.exec(svg) ?? [];
6266
6270
  return { width: Number(width), height: Number(height) };
6267
6271
  }
6268
- async function stage(browser, svg, fontCss, body) {
6272
+ async function stage(browser, svg, fontCss, body, lang) {
6269
6273
  const { width, height } = sizeOf(svg);
6270
6274
  const page = await browser.newPage({ viewport: { width, height }, deviceScaleFactor: SCALE });
6271
6275
  const paused = svg.replace(/^<svg\b/, '<svg style="--play:paused;--at:0"');
@@ -6278,12 +6282,17 @@ async function stage(browser, svg, fontCss, body) {
6278
6282
  });
6279
6283
  await page.goto("http://localhost/");
6280
6284
  await page.waitForFunction(() => "__tools" in window);
6281
- await page.evaluate(async () => {
6282
- const loads = [];
6283
- document.fonts.forEach((face) => loads.push(face.load()));
6284
- await Promise.all(loads);
6285
+ const unreadable = await page.evaluate(async () => {
6286
+ const faces = [];
6287
+ document.fonts.forEach((face) => faces.push(face));
6288
+ const loads = await Promise.allSettled(faces.map((face) => face.load()));
6285
6289
  await document.fonts.ready;
6290
+ return faces.filter((_, i) => loads[i]?.status === "rejected").map((face) => `"${face.family.replace(/^["']|["']$/g, "")}" ${face.unicodeRange}`);
6286
6291
  });
6292
+ if (unreadable.length) {
6293
+ await page.close();
6294
+ throw new Error(FONT_TEXT[lang](unreadable));
6295
+ }
6287
6296
  return { page, width, height };
6288
6297
  }
6289
6298
  async function at(page, t) {
@@ -6444,6 +6453,16 @@ function ranges(list) {
6444
6453
  });
6445
6454
  }
6446
6455
  var hex = (code) => `U+${code.toString(16).toUpperCase()}`;
6456
+ var shapeless = (char) => /^[\s\p{Cf}\p{Cc}]$/u.test(char);
6457
+ function shapedIn(span) {
6458
+ for (const [from, to] of span) {
6459
+ for (let code = from; code <= to; code++) {
6460
+ const char = String.fromCodePoint(code);
6461
+ if (!shapeless(char)) return char;
6462
+ }
6463
+ }
6464
+ return void 0;
6465
+ }
6447
6466
  function charsOf(texts) {
6448
6467
  return [.../* @__PURE__ */ new Set([...texts.join("")])].filter((char) => char !== "\n" && char !== "\r" && char !== " ").sort();
6449
6468
  }
@@ -6459,8 +6478,9 @@ async function fontFaces(chars) {
6459
6478
  return span.some(([from, to]) => code >= from && code <= to);
6460
6479
  });
6461
6480
  if (!own.length) return "";
6481
+ const filler = own.every(shapeless) ? shapedIn(span) ?? "" : "";
6462
6482
  const file = join$1(base, "files", `${name}-${key.replace(/[[\]]/g, "")}-wght-normal.woff2`);
6463
- const woff2 = await subsetFont(await readFile(file), own.join(""), { targetFormat: "woff2", variationAxes: { wght: WEIGHT } });
6483
+ const woff2 = await subsetFont(await readFile(file), own.join("") + filler, { targetFormat: "woff2", variationAxes: { wght: WEIGHT } });
6464
6484
  const unicode = own.map((char) => hex(char.codePointAt(0) ?? 0)).join(",");
6465
6485
  return `@font-face{font-family:"${family}";font-style:normal;font-display:block;font-weight:${WEIGHT.min} ${WEIGHT.max};src:url(data:font/woff2;base64,${woff2.toString("base64")}) format("woff2");unicode-range:${unicode}}`;
6466
6486
  });
@@ -6521,13 +6541,13 @@ async function exportDiagram(input, options) {
6521
6541
  const browser = await launch(lang);
6522
6542
  try {
6523
6543
  if (formats.includes("png")) {
6524
- const fixed = await stage(browser, rendered.svg, fontCss, "");
6544
+ const fixed = await stage(browser, rendered.svg, fontCss, "", lang);
6525
6545
  outputs.push(["png", await still(fixed, timeline.stills[timeline.stills.length - 1] ?? 0)]);
6526
6546
  }
6527
6547
  if (mp4 || gif) {
6528
6548
  const fps = mp4 ? options.fps ?? DEFAULTS.fps : options.gifFps ?? DEFAULTS.gifFps;
6529
6549
  const gifEvery = gif ? Math.max(1, Math.round(fps / (options.gifFps ?? DEFAULTS.gifFps))) : 0;
6530
- const shot = await film(await stage(browser, videoSvg, fontCss, `${vars};background:var(--bg)`), {
6550
+ const shot = await film(await stage(browser, videoSvg, fontCss, `${vars};background:var(--bg)`, lang), {
6531
6551
  total: timeline.total,
6532
6552
  fps,
6533
6553
  mp4,