@pixldocs/canvas-renderer 0.5.91 → 0.5.93

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/index.cjs CHANGED
@@ -12264,44 +12264,19 @@ function extractSectionStateCandidate(values, sections) {
12264
12264
  const looksLikeSectionState = Object.keys(raw).some((key) => sectionIds.has(key) || key.startsWith("section_"));
12265
12265
  return looksLikeSectionState ? raw : null;
12266
12266
  }
12267
- function entryIdentityTokens(entry, section) {
12268
- const entryNameKey = section == null ? void 0 : section.entryNameFieldKey;
12269
- const candidates = [
12270
- entry[ENTRY_NAME_KEY],
12271
- entryNameKey ? entry[entryNameKey] : void 0,
12272
- entry.section_title,
12273
- entry.label,
12274
- entry.name
12275
- ];
12276
- return Array.from(new Set(
12277
- candidates.filter((value) => typeof value === "string" && !!value.trim()).map((value) => value.trim().toLowerCase())
12278
- ));
12279
- }
12280
12267
  function mergeRepeatableEntryMeta(target, metaSource, sections) {
12281
12268
  if (!metaSource) return target;
12282
12269
  let changed = false;
12283
12270
  const next = { ...target };
12284
12271
  const repeatableIds = new Set(sections.filter((section) => section.type === "repeatable").map((section) => section.id));
12285
12272
  const isRepeatableStateKey = (key) => repeatableIds.has(key) || Array.from(repeatableIds).some((id) => key.endsWith(`_${id}`));
12286
- const sectionForStateKey = (key) => sections.find((section) => section.type === "repeatable" && (section.id === key || key.endsWith(`_${section.id}`)));
12287
12273
  for (const [key, targetEntries] of Object.entries(target)) {
12288
12274
  if (!isRepeatableStateKey(key) || !Array.isArray(targetEntries)) continue;
12289
12275
  const sourceEntries = metaSource[key];
12290
12276
  if (!Array.isArray(sourceEntries)) continue;
12291
- const section = sectionForStateKey(key);
12292
- const sourceByToken = /* @__PURE__ */ new Map();
12293
- const duplicateTokens = /* @__PURE__ */ new Set();
12294
- for (const sourceEntry of sourceEntries) {
12295
- if (!isRecord(sourceEntry)) continue;
12296
- for (const token of entryIdentityTokens(sourceEntry, section)) {
12297
- if (sourceByToken.has(token)) duplicateTokens.add(token);
12298
- else sourceByToken.set(token, sourceEntry);
12299
- }
12300
- }
12301
- for (const token of duplicateTokens) sourceByToken.delete(token);
12302
12277
  const mergedEntries = targetEntries.map((entry, index) => {
12303
12278
  if (!isRecord(entry)) return entry;
12304
- const sourceEntry = entryIdentityTokens(entry, section).map((token) => sourceByToken.get(token)).find((match) => !!match) ?? sourceEntries[index];
12279
+ const sourceEntry = sourceEntries[index];
12305
12280
  if (!isRecord(sourceEntry)) return entry;
12306
12281
  const id = sourceEntry[ENTRY_ID_KEY];
12307
12282
  const name = sourceEntry[ENTRY_NAME_KEY];
@@ -14700,6 +14675,13 @@ function containsDevanagari(text) {
14700
14675
  }
14701
14676
  return false;
14702
14677
  }
14678
+ function containsSymbol(text) {
14679
+ if (!text) return false;
14680
+ for (const char of text) {
14681
+ if (classifyChar(char) === "symbol") return true;
14682
+ }
14683
+ return false;
14684
+ }
14703
14685
  function isBasicLatinOrLatin1(char) {
14704
14686
  const c = char.codePointAt(0) ?? 0;
14705
14687
  return c <= 591;
@@ -14732,7 +14714,7 @@ function rewriteSvgFontsForJsPDF(svgStr) {
14732
14714
  var _a, _b;
14733
14715
  const parser = new DOMParser();
14734
14716
  const doc = parser.parseFromString(svgStr, "image/svg+xml");
14735
- const textEls = doc.querySelectorAll("text, tspan, textPath");
14717
+ const allTextEls = Array.from(doc.querySelectorAll("text, tspan, textPath"));
14736
14718
  const readStyleToken = (style, prop) => {
14737
14719
  var _a2;
14738
14720
  const match = style.match(new RegExp(`${prop}\\s*:\\s*([^;]+)`, "i"));
@@ -14761,7 +14743,17 @@ function rewriteSvgFontsForJsPDF(svgStr) {
14761
14743
  stylePairs.push(`font-style: normal`);
14762
14744
  return stylePairs.join("; ");
14763
14745
  };
14764
- for (const el of textEls) {
14746
+ const getDepth = (el) => {
14747
+ let depth = 0;
14748
+ let current = el.parentElement;
14749
+ while (current) {
14750
+ depth++;
14751
+ current = current.parentElement;
14752
+ }
14753
+ return depth;
14754
+ };
14755
+ const sourceMeta = /* @__PURE__ */ new Map();
14756
+ for (const el of allTextEls) {
14765
14757
  const inlineStyle = el.getAttribute("style") || "";
14766
14758
  const rawFf = resolveInheritedValue(el, "font-family");
14767
14759
  if (!rawFf) continue;
@@ -14773,12 +14765,21 @@ function rewriteSvgFontsForJsPDF(svgStr) {
14773
14765
  const resolved = resolveFontWeight(weight);
14774
14766
  const isItalic = /italic|oblique/i.test(styleRaw);
14775
14767
  const jsPdfName = getEmbeddedJsPDFFontName(clean, resolved, isItalic);
14768
+ sourceMeta.set(el, { clean, resolved, isItalic, jsPdfName, inlineStyle, weight });
14769
+ }
14770
+ const textEls = allTextEls.sort((a, b) => getDepth(b) - getDepth(a));
14771
+ for (const el of textEls) {
14772
+ if (!el.isConnected) continue;
14773
+ const meta = sourceMeta.get(el);
14774
+ if (!meta) continue;
14775
+ const { clean, resolved, isItalic, jsPdfName, inlineStyle, weight } = meta;
14776
14776
  el.setAttribute("data-source-font-family", clean);
14777
14777
  el.setAttribute("data-source-font-weight", String(resolved));
14778
14778
  el.setAttribute("data-source-font-style", isItalic ? "italic" : "normal");
14779
14779
  const directText = Array.from(el.childNodes).filter((n) => n.nodeType === 3).map((n) => n.textContent || "").join("");
14780
14780
  const hasDevanagari = containsDevanagari(directText);
14781
- if (hasDevanagari && directText.length > 0) {
14781
+ const hasSymbol = containsSymbol(directText);
14782
+ if ((hasDevanagari || hasSymbol) && directText.length > 0) {
14782
14783
  const devanagariWeight = resolveFontWeight(weight);
14783
14784
  const devanagariJsPdfName = getEmbeddedJsPDFFontName(FONT_FALLBACK_DEVANAGARI, devanagariWeight);
14784
14785
  const symbolJsPdfName = isFontAvailable(FONT_FALLBACK_SYMBOLS) ? getEmbeddedJsPDFFontName(FONT_FALLBACK_SYMBOLS, 400) : jsPdfName;
@@ -14786,7 +14787,7 @@ function rewriteSvgFontsForJsPDF(svgStr) {
14786
14787
  for (const node of childNodes) {
14787
14788
  if (node.nodeType !== 3 || !node.textContent) continue;
14788
14789
  const runs = splitIntoRuns(node.textContent);
14789
- if (runs.length <= 1 && ((_b = runs[0]) == null ? void 0 : _b.runType) !== "devanagari") continue;
14790
+ if (runs.length <= 1 && ((_b = runs[0]) == null ? void 0 : _b.runType) === "main") continue;
14790
14791
  const fragment = doc.createDocumentFragment();
14791
14792
  for (const run of runs) {
14792
14793
  const tspan = doc.createElementNS("http://www.w3.org/2000/svg", "tspan");
@@ -14837,6 +14838,8 @@ async function embedFontsInPdf(pdf, fontFamilies, fontBaseUrl) {
14837
14838
  const embedded = /* @__PURE__ */ new Set();
14838
14839
  const weights = [300, 400, 500, 600, 700];
14839
14840
  const tasks = [];
14841
+ fontFamilies.add(FONT_FALLBACK_SYMBOLS);
14842
+ fontFamilies.add(FONT_FALLBACK_DEVANAGARI);
14840
14843
  for (const family of fontFamilies) {
14841
14844
  if (!isFontAvailable(family)) {
14842
14845
  console.warn(`[pdf-fonts] No TTF mapping for "${family}" — will use Helvetica fallback`);
@@ -16302,7 +16305,7 @@ async function assemblePdfFromSvgs(svgResults, options = {}) {
16302
16305
  }
16303
16306
  if (shouldOutlineText) {
16304
16307
  try {
16305
- const { convertAllTextToPath } = await Promise.resolve().then(() => require("./svgTextToPath-CBcIgtk1.cjs"));
16308
+ const { convertAllTextToPath } = await Promise.resolve().then(() => require("./svgTextToPath-B4SihUQv.cjs"));
16306
16309
  pageSvg = await convertAllTextToPath(pageSvg, fontBaseUrl, { mode: outlineSubMode });
16307
16310
  try {
16308
16311
  dumpSvgTextDiagnostics(pageSvg, i, PARITY_TAG, "STAGE-1b-after-text-to-path-raw");