@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.js CHANGED
@@ -12245,44 +12245,19 @@ function extractSectionStateCandidate(values, sections) {
12245
12245
  const looksLikeSectionState = Object.keys(raw).some((key) => sectionIds.has(key) || key.startsWith("section_"));
12246
12246
  return looksLikeSectionState ? raw : null;
12247
12247
  }
12248
- function entryIdentityTokens(entry, section) {
12249
- const entryNameKey = section == null ? void 0 : section.entryNameFieldKey;
12250
- const candidates = [
12251
- entry[ENTRY_NAME_KEY],
12252
- entryNameKey ? entry[entryNameKey] : void 0,
12253
- entry.section_title,
12254
- entry.label,
12255
- entry.name
12256
- ];
12257
- return Array.from(new Set(
12258
- candidates.filter((value) => typeof value === "string" && !!value.trim()).map((value) => value.trim().toLowerCase())
12259
- ));
12260
- }
12261
12248
  function mergeRepeatableEntryMeta(target, metaSource, sections) {
12262
12249
  if (!metaSource) return target;
12263
12250
  let changed = false;
12264
12251
  const next = { ...target };
12265
12252
  const repeatableIds = new Set(sections.filter((section) => section.type === "repeatable").map((section) => section.id));
12266
12253
  const isRepeatableStateKey = (key) => repeatableIds.has(key) || Array.from(repeatableIds).some((id) => key.endsWith(`_${id}`));
12267
- const sectionForStateKey = (key) => sections.find((section) => section.type === "repeatable" && (section.id === key || key.endsWith(`_${section.id}`)));
12268
12254
  for (const [key, targetEntries] of Object.entries(target)) {
12269
12255
  if (!isRepeatableStateKey(key) || !Array.isArray(targetEntries)) continue;
12270
12256
  const sourceEntries = metaSource[key];
12271
12257
  if (!Array.isArray(sourceEntries)) continue;
12272
- const section = sectionForStateKey(key);
12273
- const sourceByToken = /* @__PURE__ */ new Map();
12274
- const duplicateTokens = /* @__PURE__ */ new Set();
12275
- for (const sourceEntry of sourceEntries) {
12276
- if (!isRecord(sourceEntry)) continue;
12277
- for (const token of entryIdentityTokens(sourceEntry, section)) {
12278
- if (sourceByToken.has(token)) duplicateTokens.add(token);
12279
- else sourceByToken.set(token, sourceEntry);
12280
- }
12281
- }
12282
- for (const token of duplicateTokens) sourceByToken.delete(token);
12283
12258
  const mergedEntries = targetEntries.map((entry, index) => {
12284
12259
  if (!isRecord(entry)) return entry;
12285
- const sourceEntry = entryIdentityTokens(entry, section).map((token) => sourceByToken.get(token)).find((match) => !!match) ?? sourceEntries[index];
12260
+ const sourceEntry = sourceEntries[index];
12286
12261
  if (!isRecord(sourceEntry)) return entry;
12287
12262
  const id = sourceEntry[ENTRY_ID_KEY];
12288
12263
  const name = sourceEntry[ENTRY_NAME_KEY];
@@ -14681,6 +14656,13 @@ function containsDevanagari(text) {
14681
14656
  }
14682
14657
  return false;
14683
14658
  }
14659
+ function containsSymbol(text) {
14660
+ if (!text) return false;
14661
+ for (const char of text) {
14662
+ if (classifyChar(char) === "symbol") return true;
14663
+ }
14664
+ return false;
14665
+ }
14684
14666
  function isBasicLatinOrLatin1(char) {
14685
14667
  const c = char.codePointAt(0) ?? 0;
14686
14668
  return c <= 591;
@@ -14713,7 +14695,7 @@ function rewriteSvgFontsForJsPDF(svgStr) {
14713
14695
  var _a, _b;
14714
14696
  const parser = new DOMParser();
14715
14697
  const doc = parser.parseFromString(svgStr, "image/svg+xml");
14716
- const textEls = doc.querySelectorAll("text, tspan, textPath");
14698
+ const allTextEls = Array.from(doc.querySelectorAll("text, tspan, textPath"));
14717
14699
  const readStyleToken = (style, prop) => {
14718
14700
  var _a2;
14719
14701
  const match = style.match(new RegExp(`${prop}\\s*:\\s*([^;]+)`, "i"));
@@ -14742,7 +14724,17 @@ function rewriteSvgFontsForJsPDF(svgStr) {
14742
14724
  stylePairs.push(`font-style: normal`);
14743
14725
  return stylePairs.join("; ");
14744
14726
  };
14745
- for (const el of textEls) {
14727
+ const getDepth = (el) => {
14728
+ let depth = 0;
14729
+ let current = el.parentElement;
14730
+ while (current) {
14731
+ depth++;
14732
+ current = current.parentElement;
14733
+ }
14734
+ return depth;
14735
+ };
14736
+ const sourceMeta = /* @__PURE__ */ new Map();
14737
+ for (const el of allTextEls) {
14746
14738
  const inlineStyle = el.getAttribute("style") || "";
14747
14739
  const rawFf = resolveInheritedValue(el, "font-family");
14748
14740
  if (!rawFf) continue;
@@ -14754,12 +14746,21 @@ function rewriteSvgFontsForJsPDF(svgStr) {
14754
14746
  const resolved = resolveFontWeight(weight);
14755
14747
  const isItalic = /italic|oblique/i.test(styleRaw);
14756
14748
  const jsPdfName = getEmbeddedJsPDFFontName(clean, resolved, isItalic);
14749
+ sourceMeta.set(el, { clean, resolved, isItalic, jsPdfName, inlineStyle, weight });
14750
+ }
14751
+ const textEls = allTextEls.sort((a, b) => getDepth(b) - getDepth(a));
14752
+ for (const el of textEls) {
14753
+ if (!el.isConnected) continue;
14754
+ const meta = sourceMeta.get(el);
14755
+ if (!meta) continue;
14756
+ const { clean, resolved, isItalic, jsPdfName, inlineStyle, weight } = meta;
14757
14757
  el.setAttribute("data-source-font-family", clean);
14758
14758
  el.setAttribute("data-source-font-weight", String(resolved));
14759
14759
  el.setAttribute("data-source-font-style", isItalic ? "italic" : "normal");
14760
14760
  const directText = Array.from(el.childNodes).filter((n) => n.nodeType === 3).map((n) => n.textContent || "").join("");
14761
14761
  const hasDevanagari = containsDevanagari(directText);
14762
- if (hasDevanagari && directText.length > 0) {
14762
+ const hasSymbol = containsSymbol(directText);
14763
+ if ((hasDevanagari || hasSymbol) && directText.length > 0) {
14763
14764
  const devanagariWeight = resolveFontWeight(weight);
14764
14765
  const devanagariJsPdfName = getEmbeddedJsPDFFontName(FONT_FALLBACK_DEVANAGARI, devanagariWeight);
14765
14766
  const symbolJsPdfName = isFontAvailable(FONT_FALLBACK_SYMBOLS) ? getEmbeddedJsPDFFontName(FONT_FALLBACK_SYMBOLS, 400) : jsPdfName;
@@ -14767,7 +14768,7 @@ function rewriteSvgFontsForJsPDF(svgStr) {
14767
14768
  for (const node of childNodes) {
14768
14769
  if (node.nodeType !== 3 || !node.textContent) continue;
14769
14770
  const runs = splitIntoRuns(node.textContent);
14770
- if (runs.length <= 1 && ((_b = runs[0]) == null ? void 0 : _b.runType) !== "devanagari") continue;
14771
+ if (runs.length <= 1 && ((_b = runs[0]) == null ? void 0 : _b.runType) === "main") continue;
14771
14772
  const fragment = doc.createDocumentFragment();
14772
14773
  for (const run of runs) {
14773
14774
  const tspan = doc.createElementNS("http://www.w3.org/2000/svg", "tspan");
@@ -14818,6 +14819,8 @@ async function embedFontsInPdf(pdf, fontFamilies, fontBaseUrl) {
14818
14819
  const embedded = /* @__PURE__ */ new Set();
14819
14820
  const weights = [300, 400, 500, 600, 700];
14820
14821
  const tasks = [];
14822
+ fontFamilies.add(FONT_FALLBACK_SYMBOLS);
14823
+ fontFamilies.add(FONT_FALLBACK_DEVANAGARI);
14821
14824
  for (const family of fontFamilies) {
14822
14825
  if (!isFontAvailable(family)) {
14823
14826
  console.warn(`[pdf-fonts] No TTF mapping for "${family}" — will use Helvetica fallback`);
@@ -16283,7 +16286,7 @@ async function assemblePdfFromSvgs(svgResults, options = {}) {
16283
16286
  }
16284
16287
  if (shouldOutlineText) {
16285
16288
  try {
16286
- const { convertAllTextToPath } = await import("./svgTextToPath-CShDi4Ky.js");
16289
+ const { convertAllTextToPath } = await import("./svgTextToPath-BmOzWJsV.js");
16287
16290
  pageSvg = await convertAllTextToPath(pageSvg, fontBaseUrl, { mode: outlineSubMode });
16288
16291
  try {
16289
16292
  dumpSvgTextDiagnostics(pageSvg, i, PARITY_TAG, "STAGE-1b-after-text-to-path-raw");