@pixldocs/canvas-renderer 0.5.131 → 0.5.133

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.
@@ -5712,7 +5712,8 @@ function applyTextBackground(obj, cfg) {
5712
5712
  const dataAttrs = `data-blur="${blur.toFixed(3)}" data-ox="${ox.toFixed(3)}" data-oy="${oy.toFixed(3)}" data-bx="${bx.toFixed(3)}" data-by="${by.toFixed(3)}" data-bw="${bw.toFixed(3)}" data-bh="${bh.toFixed(3)}" data-color="${escapeXmlAttr(shadowColor)}"`;
5713
5713
  const wrapShadow = (markup) => blur <= 0 ? `<g transform="translate(${ox.toFixed(3)} ${oy.toFixed(3)})">${markup}</g>` : `<g class="__pdShadowRaster" ${dataAttrs}>${markup}</g>`;
5714
5714
  if (hasBg && (bg == null ? void 0 : bg.shadowAffectsBg) !== false) {
5715
- const shadowBgPath = `<path d="${bgD}" fill="${escapeXmlAttr(shadowColor)}" />`;
5715
+ const shadowOpacityAttr = bgOpacity < 1 ? ` fill-opacity="${bgOpacity}"` : "";
5716
+ const shadowBgPath = `<path d="${bgD}" fill="${escapeXmlAttr(shadowColor)}"${shadowOpacityAttr} />`;
5716
5717
  bgShadowMarker = wrapShadow(shadowBgPath);
5717
5718
  }
5718
5719
  if ((bg == null ? void 0 : bg.shadowAffectsText) !== false) {
@@ -14013,7 +14014,8 @@ async function fetchGoogleFontTTF(fontFamily, weight, isItalic = false) {
14013
14014
  async function fetchFontshareTTF(fontFamily, weight, isItalic = false) {
14014
14015
  const cacheKey = `fs:${fontFamily}:${weight}:${isItalic ? "i" : "n"}`;
14015
14016
  if (ttfCache.has(cacheKey)) return ttfCache.get(cacheKey);
14016
- if (fontshareNotFound.has(fontFamily)) return null;
14017
+ const notFoundKey = remoteVariantKey(fontFamily, weight, isItalic);
14018
+ if (fontshareNotFound.has(notFoundKey)) return null;
14017
14019
  const slug = fontFamily.trim().toLowerCase().replace(/\s+/g, "-");
14018
14020
  const proxyBytes = await fetchTtfViaProxy(fontFamily, weight, isItalic, "fontshare");
14019
14021
  if (proxyBytes) {
@@ -14026,13 +14028,13 @@ async function fetchFontshareTTF(fontFamily, weight, isItalic = false) {
14026
14028
  const cssUrl = `https://api.fontshare.com/v2/css?f[]=${slug}@${weight}${styleSuffix}&display=swap`;
14027
14029
  const cssRes = await fetch(cssUrl);
14028
14030
  if (!cssRes.ok) {
14029
- if (cssRes.status === 400 || cssRes.status === 404) fontshareNotFound.add(fontFamily);
14031
+ if (cssRes.status === 400 || cssRes.status === 404) fontshareNotFound.add(notFoundKey);
14030
14032
  return null;
14031
14033
  }
14032
14034
  const css = await cssRes.text();
14033
14035
  const ttMatch = css.match(/url\(([^)]+)\)\s+format\(['"]?truetype['"]?\)/i);
14034
14036
  if (!ttMatch) {
14035
- fontshareNotFound.add(fontFamily);
14037
+ fontshareNotFound.add(notFoundKey);
14036
14038
  return null;
14037
14039
  }
14038
14040
  let ttfUrl = ttMatch[1].replace(/['"]/g, "").trim();
@@ -14079,11 +14081,38 @@ async function embedFontWithGoogleFallback(pdf, fontName, weight = 400, fontBase
14079
14081
  if (ok) return true;
14080
14082
  }
14081
14083
  const resolved = resolveFontWeight(weight);
14082
- const fsB64 = await fetchFontshareTTF(fontName, resolved, isItalic);
14083
- if (fsB64) return registerJsPdfFont(pdf, fontName, resolved, isItalic, fsB64);
14084
- const b64 = await fetchGoogleFontTTF(fontName, resolved, isItalic);
14085
- if (b64) return registerJsPdfFont(pdf, fontName, resolved, isItalic, b64);
14086
- return false;
14084
+ const weightLadder = [resolved];
14085
+ for (const w of [400, 500, 700, 600, 300]) {
14086
+ if (!weightLadder.includes(w)) weightLadder.push(w);
14087
+ }
14088
+ const tryFetch = async (w, italic) => {
14089
+ const fs = await fetchFontshareTTF(fontName, w, italic);
14090
+ if (fs) return fs;
14091
+ const g = await fetchGoogleFontTTF(fontName, w, italic);
14092
+ return g;
14093
+ };
14094
+ let b64 = null;
14095
+ let usedItalic = isItalic;
14096
+ let usedWeight = resolved;
14097
+ for (const w of weightLadder) {
14098
+ b64 = await tryFetch(w, isItalic);
14099
+ if (b64) {
14100
+ usedWeight = w;
14101
+ break;
14102
+ }
14103
+ }
14104
+ if (!b64 && isItalic) {
14105
+ for (const w of weightLadder) {
14106
+ b64 = await tryFetch(w, false);
14107
+ if (b64) {
14108
+ usedItalic = false;
14109
+ usedWeight = w;
14110
+ break;
14111
+ }
14112
+ }
14113
+ }
14114
+ if (!b64) return false;
14115
+ return registerJsPdfFont(pdf, fontName, usedWeight, usedItalic, b64);
14087
14116
  }
14088
14117
  async function embedFontsForConfig(pdf, config, fontBaseUrl) {
14089
14118
  const fontKeys = /* @__PURE__ */ new Set();
@@ -16185,7 +16214,7 @@ class PixldocsRenderer {
16185
16214
  await this.waitForCanvasScene(container, cloned, i);
16186
16215
  }
16187
16216
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
16188
- const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-C96oIwLP.js");
16217
+ const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-BQO8W14A.js");
16189
16218
  const prepared = preparePagesForExport(
16190
16219
  cloned.pages,
16191
16220
  canvasWidth,
@@ -18178,7 +18207,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
18178
18207
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
18179
18208
  sanitizeSvgTreeForPdf(svgToDraw);
18180
18209
  try {
18181
- const { bakeTextAnchorPositionsFromLiveSvg } = await import("./vectorPdfExport-C96oIwLP.js");
18210
+ const { bakeTextAnchorPositionsFromLiveSvg } = await import("./vectorPdfExport-BQO8W14A.js");
18182
18211
  await bakeTextAnchorPositionsFromLiveSvg(svgToDraw);
18183
18212
  } catch (e) {
18184
18213
  console.warn("[canvas-renderer][pdf-export] anchor-bake pass failed (continuing):", e);
@@ -18295,7 +18324,7 @@ async function assemblePdfFromSvgs(svgResults, options = {}) {
18295
18324
  const hasGradient = !!((_b = (_a = page.backgroundGradient) == null ? void 0 : _a.stops) == null ? void 0 : _b.length);
18296
18325
  drawPageBackground(pdf, i, page.width, page.height, page.backgroundColor, page.backgroundGradient);
18297
18326
  const shouldStripBg = stripPageBackground ?? hasGradient;
18298
- const textMode = options.textMode ?? (options.outlineText === true ? "pixel-perfect" : "selectable");
18327
+ const textMode = options.textMode ?? (options.outlineText === true ? "pixel-perfect" : "auto");
18299
18328
  const shouldOutlineText = textMode === "pixel-perfect" || textMode === "auto";
18300
18329
  const outlineSubMode = textMode === "auto" ? "complex-only" : "all";
18301
18330
  let pageSvg = page.svg;
@@ -18309,7 +18338,7 @@ async function assemblePdfFromSvgs(svgResults, options = {}) {
18309
18338
  }
18310
18339
  if (shouldOutlineText) {
18311
18340
  try {
18312
- const { convertAllTextToPath } = await import("./svgTextToPath-DMx9Buca.js");
18341
+ const { convertAllTextToPath } = await import("./svgTextToPath-DG7rcbDE.js");
18313
18342
  pageSvg = await convertAllTextToPath(pageSvg, fontBaseUrl, { mode: outlineSubMode });
18314
18343
  try {
18315
18344
  dumpSvgTextDiagnostics(pageSvg, i, PARITY_TAG, "STAGE-1b-after-text-to-path-raw");
@@ -18523,4 +18552,4 @@ export {
18523
18552
  collectFontDescriptorsFromConfig as y,
18524
18553
  collectFontsFromConfig as z
18525
18554
  };
18526
- //# sourceMappingURL=index-ft7TuZPu.js.map
18555
+ //# sourceMappingURL=index-DMkFzgNL.js.map