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