@cardenelabs/dragon 0.41.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/cli.js CHANGED
@@ -6285,6 +6285,10 @@ var LAUNCH_TEXT = {
6285
6285
  install: `Install playwright-core with ${INSTALL_ADD} and Chromium with ${INSTALL_CHROMIUM}`
6286
6286
  }
6287
6287
  };
6288
+ var FONT_TEXT = {
6289
+ ja: (faces) => `\u66F8\u304D\u51FA\u3057\u306B\u57CB\u3081\u308B\u5B57\u306E file \u3092 Chromium \u304C\u8AAD\u3081\u306A\u3044 (${faces.join("\u3001")})`,
6290
+ en: (faces) => `Chromium cannot read the font files embedded in the export (${faces.join("; ")})`
6291
+ };
6288
6292
  async function launch(lang) {
6289
6293
  const text2 = LAUNCH_TEXT[lang];
6290
6294
  let chromium;
@@ -6303,7 +6307,7 @@ function sizeOf(svg) {
6303
6307
  const [, width = "0", height = "0"] = /^<svg\b[^>]*?\swidth="(\d+)"\s+height="(\d+)"/.exec(svg) ?? [];
6304
6308
  return { width: Number(width), height: Number(height) };
6305
6309
  }
6306
- async function stage(browser, svg, fontCss, body) {
6310
+ async function stage(browser, svg, fontCss, body, lang) {
6307
6311
  const { width, height } = sizeOf(svg);
6308
6312
  const page = await browser.newPage({ viewport: { width, height }, deviceScaleFactor: SCALE });
6309
6313
  const paused = svg.replace(/^<svg\b/, '<svg style="--play:paused;--at:0"');
@@ -6316,12 +6320,17 @@ async function stage(browser, svg, fontCss, body) {
6316
6320
  });
6317
6321
  await page.goto("http://localhost/");
6318
6322
  await page.waitForFunction(() => "__tools" in window);
6319
- await page.evaluate(async () => {
6320
- const loads = [];
6321
- document.fonts.forEach((face) => loads.push(face.load()));
6322
- await Promise.all(loads);
6323
+ const unreadable = await page.evaluate(async () => {
6324
+ const faces = [];
6325
+ document.fonts.forEach((face) => faces.push(face));
6326
+ const loads = await Promise.allSettled(faces.map((face) => face.load()));
6323
6327
  await document.fonts.ready;
6328
+ return faces.filter((_, i) => loads[i]?.status === "rejected").map((face) => `"${face.family.replace(/^["']|["']$/g, "")}" ${face.unicodeRange}`);
6324
6329
  });
6330
+ if (unreadable.length) {
6331
+ await page.close();
6332
+ throw new Error(FONT_TEXT[lang](unreadable));
6333
+ }
6325
6334
  return { page, width, height };
6326
6335
  }
6327
6336
  async function at(page, t) {
@@ -6482,6 +6491,16 @@ function ranges(list2) {
6482
6491
  });
6483
6492
  }
6484
6493
  var hex = (code) => `U+${code.toString(16).toUpperCase()}`;
6494
+ var shapeless = (char) => /^[\s\p{Cf}\p{Cc}]$/u.test(char);
6495
+ function shapedIn(span) {
6496
+ for (const [from, to] of span) {
6497
+ for (let code = from; code <= to; code++) {
6498
+ const char = String.fromCodePoint(code);
6499
+ if (!shapeless(char)) return char;
6500
+ }
6501
+ }
6502
+ return void 0;
6503
+ }
6485
6504
  function charsOf(texts) {
6486
6505
  return [.../* @__PURE__ */ new Set([...texts.join("")])].filter((char) => char !== "\n" && char !== "\r" && char !== " ").sort();
6487
6506
  }
@@ -6497,8 +6516,9 @@ async function fontFaces(chars) {
6497
6516
  return span.some(([from, to]) => code >= from && code <= to);
6498
6517
  });
6499
6518
  if (!own.length) return "";
6519
+ const filler = own.every(shapeless) ? shapedIn(span) ?? "" : "";
6500
6520
  const file = join$1(base, "files", `${name}-${key.replace(/[[\]]/g, "")}-wght-normal.woff2`);
6501
- const woff2 = await subsetFont(await readFile(file), own.join(""), { targetFormat: "woff2", variationAxes: { wght: WEIGHT } });
6521
+ const woff2 = await subsetFont(await readFile(file), own.join("") + filler, { targetFormat: "woff2", variationAxes: { wght: WEIGHT } });
6502
6522
  const unicode = own.map((char) => hex(char.codePointAt(0) ?? 0)).join(",");
6503
6523
  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}}`;
6504
6524
  });
@@ -6559,13 +6579,13 @@ async function exportDiagram(input, options) {
6559
6579
  const browser = await launch(lang);
6560
6580
  try {
6561
6581
  if (formats.includes("png")) {
6562
- const fixed = await stage(browser, rendered.svg, fontCss, "");
6582
+ const fixed = await stage(browser, rendered.svg, fontCss, "", lang);
6563
6583
  outputs.push(["png", await still(fixed, timeline.stills[timeline.stills.length - 1] ?? 0)]);
6564
6584
  }
6565
6585
  if (mp4 || gif) {
6566
6586
  const fps = mp4 ? options.fps ?? DEFAULTS.fps : options.gifFps ?? DEFAULTS.gifFps;
6567
6587
  const gifEvery = gif ? Math.max(1, Math.round(fps / (options.gifFps ?? DEFAULTS.gifFps))) : 0;
6568
- const shot = await film(await stage(browser, videoSvg, fontCss, `${vars};background:var(--bg)`), {
6588
+ const shot = await film(await stage(browser, videoSvg, fontCss, `${vars};background:var(--bg)`, lang), {
6569
6589
  total: timeline.total,
6570
6590
  fps,
6571
6591
  mp4,