@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.cjs CHANGED
@@ -6291,6 +6291,10 @@ var LAUNCH_TEXT = {
6291
6291
  install: `Install playwright-core with ${INSTALL_ADD} and Chromium with ${INSTALL_CHROMIUM}`
6292
6292
  }
6293
6293
  };
6294
+ var FONT_TEXT = {
6295
+ ja: (faces) => `\u66F8\u304D\u51FA\u3057\u306B\u57CB\u3081\u308B\u5B57\u306E file \u3092 Chromium \u304C\u8AAD\u3081\u306A\u3044 (${faces.join("\u3001")})`,
6296
+ en: (faces) => `Chromium cannot read the font files embedded in the export (${faces.join("; ")})`
6297
+ };
6294
6298
  async function launch(lang) {
6295
6299
  const text2 = LAUNCH_TEXT[lang];
6296
6300
  let chromium;
@@ -6309,7 +6313,7 @@ function sizeOf(svg) {
6309
6313
  const [, width = "0", height = "0"] = /^<svg\b[^>]*?\swidth="(\d+)"\s+height="(\d+)"/.exec(svg) ?? [];
6310
6314
  return { width: Number(width), height: Number(height) };
6311
6315
  }
6312
- async function stage(browser, svg, fontCss, body) {
6316
+ async function stage(browser, svg, fontCss, body, lang) {
6313
6317
  const { width, height } = sizeOf(svg);
6314
6318
  const page = await browser.newPage({ viewport: { width, height }, deviceScaleFactor: SCALE });
6315
6319
  const paused = svg.replace(/^<svg\b/, '<svg style="--play:paused;--at:0"');
@@ -6322,12 +6326,17 @@ async function stage(browser, svg, fontCss, body) {
6322
6326
  });
6323
6327
  await page.goto("http://localhost/");
6324
6328
  await page.waitForFunction(() => "__tools" in window);
6325
- await page.evaluate(async () => {
6326
- const loads = [];
6327
- document.fonts.forEach((face) => loads.push(face.load()));
6328
- await Promise.all(loads);
6329
+ const unreadable = await page.evaluate(async () => {
6330
+ const faces = [];
6331
+ document.fonts.forEach((face) => faces.push(face));
6332
+ const loads = await Promise.allSettled(faces.map((face) => face.load()));
6329
6333
  await document.fonts.ready;
6334
+ return faces.filter((_, i) => loads[i]?.status === "rejected").map((face) => `"${face.family.replace(/^["']|["']$/g, "")}" ${face.unicodeRange}`);
6330
6335
  });
6336
+ if (unreadable.length) {
6337
+ await page.close();
6338
+ throw new Error(FONT_TEXT[lang](unreadable));
6339
+ }
6331
6340
  return { page, width, height };
6332
6341
  }
6333
6342
  async function at(page, t) {
@@ -6488,6 +6497,16 @@ function ranges(list2) {
6488
6497
  });
6489
6498
  }
6490
6499
  var hex = (code) => `U+${code.toString(16).toUpperCase()}`;
6500
+ var shapeless = (char) => /^[\s\p{Cf}\p{Cc}]$/u.test(char);
6501
+ function shapedIn(span) {
6502
+ for (const [from, to] of span) {
6503
+ for (let code = from; code <= to; code++) {
6504
+ const char = String.fromCodePoint(code);
6505
+ if (!shapeless(char)) return char;
6506
+ }
6507
+ }
6508
+ return void 0;
6509
+ }
6491
6510
  function charsOf(texts) {
6492
6511
  return [.../* @__PURE__ */ new Set([...texts.join("")])].filter((char) => char !== "\n" && char !== "\r" && char !== " ").sort();
6493
6512
  }
@@ -6503,8 +6522,9 @@ async function fontFaces(chars) {
6503
6522
  return span.some(([from, to]) => code >= from && code <= to);
6504
6523
  });
6505
6524
  if (!own.length) return "";
6525
+ const filler = own.every(shapeless) ? shapedIn(span) ?? "" : "";
6506
6526
  const file = path$1.join(base, "files", `${name}-${key.replace(/[[\]]/g, "")}-wght-normal.woff2`);
6507
- const woff2 = await subsetFont(await promises.readFile(file), own.join(""), { targetFormat: "woff2", variationAxes: { wght: WEIGHT } });
6527
+ const woff2 = await subsetFont(await promises.readFile(file), own.join("") + filler, { targetFormat: "woff2", variationAxes: { wght: WEIGHT } });
6508
6528
  const unicode = own.map((char) => hex(char.codePointAt(0) ?? 0)).join(",");
6509
6529
  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}}`;
6510
6530
  });
@@ -6565,13 +6585,13 @@ async function exportDiagram(input, options) {
6565
6585
  const browser = await launch(lang);
6566
6586
  try {
6567
6587
  if (formats.includes("png")) {
6568
- const fixed = await stage(browser, rendered.svg, fontCss, "");
6588
+ const fixed = await stage(browser, rendered.svg, fontCss, "", lang);
6569
6589
  outputs.push(["png", await still(fixed, timeline.stills[timeline.stills.length - 1] ?? 0)]);
6570
6590
  }
6571
6591
  if (mp4 || gif) {
6572
6592
  const fps = mp4 ? options.fps ?? DEFAULTS.fps : options.gifFps ?? DEFAULTS.gifFps;
6573
6593
  const gifEvery = gif ? Math.max(1, Math.round(fps / (options.gifFps ?? DEFAULTS.gifFps))) : 0;
6574
- const shot = await film(await stage(browser, videoSvg, fontCss, `${vars};background:var(--bg)`), {
6594
+ const shot = await film(await stage(browser, videoSvg, fontCss, `${vars};background:var(--bg)`, lang), {
6575
6595
  total: timeline.total,
6576
6596
  fps,
6577
6597
  mp4,