@pixldocs/canvas-renderer 0.5.90 → 0.5.92

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
@@ -11665,6 +11665,8 @@ function applyFormDataToConfig(config, mappings, formValues, repeatableSectionsF
11665
11665
  }
11666
11666
  return cloned;
11667
11667
  }
11668
+ const ENTRY_ID_KEY = "__entryId";
11669
+ const ENTRY_NAME_KEY = "__entryName";
11668
11670
  function hasBaseNodeId(node) {
11669
11671
  return node.__baseNodeId != null;
11670
11672
  }
@@ -12244,6 +12246,76 @@ function getRenderableFormSections(schema) {
12244
12246
  if (!pages.length) return base;
12245
12247
  return [...base, ...pages.map(repeatablePageToSection)];
12246
12248
  }
12249
+ function isRecord(value) {
12250
+ return !!value && typeof value === "object" && !Array.isArray(value);
12251
+ }
12252
+ function getRepeatableEntryMeta(entry, section) {
12253
+ const entryNameKey = section.entryNameFieldKey;
12254
+ const nameCandidate = entry[ENTRY_NAME_KEY] ?? (entryNameKey ? entry[entryNameKey] : void 0) ?? entry.section_title ?? entry.label ?? entry.name;
12255
+ return {
12256
+ id: typeof entry[ENTRY_ID_KEY] === "string" ? entry[ENTRY_ID_KEY] : void 0,
12257
+ name: typeof nameCandidate === "string" ? nameCandidate : void 0
12258
+ };
12259
+ }
12260
+ function extractSectionStateCandidate(values, sections) {
12261
+ if (!isRecord(values)) return null;
12262
+ const raw = isDefaultDataV2(values) && isRecord(values.sectionState) ? values.sectionState : values;
12263
+ const sectionIds = new Set(sections.map((section) => section.id));
12264
+ const looksLikeSectionState = Object.keys(raw).some((key) => sectionIds.has(key) || key.startsWith("section_"));
12265
+ return looksLikeSectionState ? raw : null;
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
+ function mergeRepeatableEntryMeta(target, metaSource, sections) {
12281
+ if (!metaSource) return target;
12282
+ let changed = false;
12283
+ const next = { ...target };
12284
+ const repeatableIds = new Set(sections.filter((section) => section.type === "repeatable").map((section) => section.id));
12285
+ 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
+ for (const [key, targetEntries] of Object.entries(target)) {
12288
+ if (!isRepeatableStateKey(key) || !Array.isArray(targetEntries)) continue;
12289
+ const sourceEntries = metaSource[key];
12290
+ 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
+ const mergedEntries = targetEntries.map((entry, index) => {
12303
+ if (!isRecord(entry)) return entry;
12304
+ const sourceEntry = entryIdentityTokens(entry, section).map((token) => sourceByToken.get(token)).find((match) => !!match) ?? sourceEntries[index];
12305
+ if (!isRecord(sourceEntry)) return entry;
12306
+ const id = sourceEntry[ENTRY_ID_KEY];
12307
+ const name = sourceEntry[ENTRY_NAME_KEY];
12308
+ const additions = {};
12309
+ if (typeof id === "string" && id.trim() && typeof entry[ENTRY_ID_KEY] !== "string") additions[ENTRY_ID_KEY] = id;
12310
+ if (typeof name === "string" && name.trim() && typeof entry[ENTRY_NAME_KEY] !== "string") additions[ENTRY_NAME_KEY] = name;
12311
+ if (!Object.keys(additions).length) return entry;
12312
+ changed = true;
12313
+ return { ...entry, ...additions };
12314
+ });
12315
+ next[key] = mergedEntries;
12316
+ }
12317
+ return changed ? next : target;
12318
+ }
12247
12319
  function buildRepeatablePagesInputForApply(schema, sectionState) {
12248
12320
  var _a;
12249
12321
  if (!((_a = schema == null ? void 0 : schema.repeatablePages) == null ? void 0 : _a.length)) return [];
@@ -12490,6 +12562,7 @@ async function resolveFromForm(options) {
12490
12562
  } else {
12491
12563
  inferredSections = [];
12492
12564
  }
12565
+ const defaultFormMetaSectionState = extractSectionStateCandidate(defaultForm == null ? void 0 : defaultForm.values, inferredSections) ?? extractSectionStateCandidate(defaultForm == null ? void 0 : defaultForm.saved_data, inferredSections);
12493
12566
  let mergedSectionState = { ...sectionState };
12494
12567
  const templateDefaultData = templateRow.default_data;
12495
12568
  if (templateDefaultData && isDefaultDataV2(templateDefaultData)) {
@@ -12500,6 +12573,7 @@ async function resolveFromForm(options) {
12500
12573
  }
12501
12574
  }
12502
12575
  }
12576
+ mergedSectionState = mergeRepeatableEntryMeta(mergedSectionState, defaultFormMetaSectionState, inferredSections);
12503
12577
  const flatFormData = flattenSectionStateToFormData(mergedSectionState, inferredSections);
12504
12578
  const dynamicFields = templateConfig.dynamicFields || [];
12505
12579
  const mappings = [];
@@ -12521,10 +12595,7 @@ async function resolveFromForm(options) {
12521
12595
  const entries = mergedSectionState[s.id] ?? [];
12522
12596
  const nodeId = s.treeNodeId ?? s.id;
12523
12597
  const schemaRepeatable = repeatableFromSchemaByBase.get(baseId(nodeId));
12524
- const entryMeta = entries.map((e) => ({
12525
- id: typeof (e == null ? void 0 : e.__entryId) === "string" ? e.__entryId : void 0,
12526
- name: typeof (e == null ? void 0 : e.__entryName) === "string" ? e.__entryName : void 0
12527
- }));
12598
+ const entryMeta = entries.map((e) => getRepeatableEntryMeta(e, s));
12528
12599
  return { nodeId, label: s.label, entryCount: Math.max(1, entries.length), entryFilter: schemaRepeatable == null ? void 0 : schemaRepeatable.entryFilter, entryMeta };
12529
12600
  });
12530
12601
  const nestedRepeatables = inferredSections.filter((s) => s.type === "repeatable" && s.parentId != null).map((s) => {
@@ -12538,10 +12609,7 @@ async function resolveFromForm(options) {
12538
12609
  const merged = [];
12539
12610
  for (let pi = 0; pi < parentEntries.length; pi++) {
12540
12611
  const childEntries = mergedSectionState[`${parentId}_${pi}_${s.id}`] ?? [];
12541
- const meta = childEntries.map((e) => ({
12542
- id: typeof (e == null ? void 0 : e.__entryId) === "string" ? e.__entryId : void 0,
12543
- name: typeof (e == null ? void 0 : e.__entryName) === "string" ? e.__entryName : void 0
12544
- }));
12612
+ const meta = childEntries.map((e) => getRepeatableEntryMeta(e, s));
12545
12613
  nestedEntryMeta[`${baseId(parentNodeId)}_${pi + 1}_${baseId(nodeId)}`] = meta;
12546
12614
  merged.push(...meta);
12547
12615
  }
@@ -14632,6 +14700,13 @@ function containsDevanagari(text) {
14632
14700
  }
14633
14701
  return false;
14634
14702
  }
14703
+ function containsSymbol(text) {
14704
+ if (!text) return false;
14705
+ for (const char of text) {
14706
+ if (classifyChar(char) === "symbol") return true;
14707
+ }
14708
+ return false;
14709
+ }
14635
14710
  function isBasicLatinOrLatin1(char) {
14636
14711
  const c = char.codePointAt(0) ?? 0;
14637
14712
  return c <= 591;
@@ -14664,7 +14739,7 @@ function rewriteSvgFontsForJsPDF(svgStr) {
14664
14739
  var _a, _b;
14665
14740
  const parser = new DOMParser();
14666
14741
  const doc = parser.parseFromString(svgStr, "image/svg+xml");
14667
- const textEls = doc.querySelectorAll("text, tspan, textPath");
14742
+ const allTextEls = Array.from(doc.querySelectorAll("text, tspan, textPath"));
14668
14743
  const readStyleToken = (style, prop) => {
14669
14744
  var _a2;
14670
14745
  const match = style.match(new RegExp(`${prop}\\s*:\\s*([^;]+)`, "i"));
@@ -14693,7 +14768,17 @@ function rewriteSvgFontsForJsPDF(svgStr) {
14693
14768
  stylePairs.push(`font-style: normal`);
14694
14769
  return stylePairs.join("; ");
14695
14770
  };
14696
- for (const el of textEls) {
14771
+ const getDepth = (el) => {
14772
+ let depth = 0;
14773
+ let current = el.parentElement;
14774
+ while (current) {
14775
+ depth++;
14776
+ current = current.parentElement;
14777
+ }
14778
+ return depth;
14779
+ };
14780
+ const sourceMeta = /* @__PURE__ */ new Map();
14781
+ for (const el of allTextEls) {
14697
14782
  const inlineStyle = el.getAttribute("style") || "";
14698
14783
  const rawFf = resolveInheritedValue(el, "font-family");
14699
14784
  if (!rawFf) continue;
@@ -14705,12 +14790,21 @@ function rewriteSvgFontsForJsPDF(svgStr) {
14705
14790
  const resolved = resolveFontWeight(weight);
14706
14791
  const isItalic = /italic|oblique/i.test(styleRaw);
14707
14792
  const jsPdfName = getEmbeddedJsPDFFontName(clean, resolved, isItalic);
14793
+ sourceMeta.set(el, { clean, resolved, isItalic, jsPdfName, inlineStyle, weight });
14794
+ }
14795
+ const textEls = allTextEls.sort((a, b) => getDepth(b) - getDepth(a));
14796
+ for (const el of textEls) {
14797
+ if (!el.isConnected) continue;
14798
+ const meta = sourceMeta.get(el);
14799
+ if (!meta) continue;
14800
+ const { clean, resolved, isItalic, jsPdfName, inlineStyle, weight } = meta;
14708
14801
  el.setAttribute("data-source-font-family", clean);
14709
14802
  el.setAttribute("data-source-font-weight", String(resolved));
14710
14803
  el.setAttribute("data-source-font-style", isItalic ? "italic" : "normal");
14711
14804
  const directText = Array.from(el.childNodes).filter((n) => n.nodeType === 3).map((n) => n.textContent || "").join("");
14712
14805
  const hasDevanagari = containsDevanagari(directText);
14713
- if (hasDevanagari && directText.length > 0) {
14806
+ const hasSymbol = containsSymbol(directText);
14807
+ if ((hasDevanagari || hasSymbol) && directText.length > 0) {
14714
14808
  const devanagariWeight = resolveFontWeight(weight);
14715
14809
  const devanagariJsPdfName = getEmbeddedJsPDFFontName(FONT_FALLBACK_DEVANAGARI, devanagariWeight);
14716
14810
  const symbolJsPdfName = isFontAvailable(FONT_FALLBACK_SYMBOLS) ? getEmbeddedJsPDFFontName(FONT_FALLBACK_SYMBOLS, 400) : jsPdfName;
@@ -14718,7 +14812,7 @@ function rewriteSvgFontsForJsPDF(svgStr) {
14718
14812
  for (const node of childNodes) {
14719
14813
  if (node.nodeType !== 3 || !node.textContent) continue;
14720
14814
  const runs = splitIntoRuns(node.textContent);
14721
- if (runs.length <= 1 && ((_b = runs[0]) == null ? void 0 : _b.runType) !== "devanagari") continue;
14815
+ if (runs.length <= 1 && ((_b = runs[0]) == null ? void 0 : _b.runType) === "main") continue;
14722
14816
  const fragment = doc.createDocumentFragment();
14723
14817
  for (const run of runs) {
14724
14818
  const tspan = doc.createElementNS("http://www.w3.org/2000/svg", "tspan");
@@ -14769,6 +14863,8 @@ async function embedFontsInPdf(pdf, fontFamilies, fontBaseUrl) {
14769
14863
  const embedded = /* @__PURE__ */ new Set();
14770
14864
  const weights = [300, 400, 500, 600, 700];
14771
14865
  const tasks = [];
14866
+ fontFamilies.add(FONT_FALLBACK_SYMBOLS);
14867
+ fontFamilies.add(FONT_FALLBACK_DEVANAGARI);
14772
14868
  for (const family of fontFamilies) {
14773
14869
  if (!isFontAvailable(family)) {
14774
14870
  console.warn(`[pdf-fonts] No TTF mapping for "${family}" — will use Helvetica fallback`);
@@ -16234,7 +16330,7 @@ async function assemblePdfFromSvgs(svgResults, options = {}) {
16234
16330
  }
16235
16331
  if (shouldOutlineText) {
16236
16332
  try {
16237
- const { convertAllTextToPath } = await Promise.resolve().then(() => require("./svgTextToPath-CBcIgtk1.cjs"));
16333
+ const { convertAllTextToPath } = await Promise.resolve().then(() => require("./svgTextToPath-B4SihUQv.cjs"));
16238
16334
  pageSvg = await convertAllTextToPath(pageSvg, fontBaseUrl, { mode: outlineSubMode });
16239
16335
  try {
16240
16336
  dumpSvgTextDiagnostics(pageSvg, i, PARITY_TAG, "STAGE-1b-after-text-to-path-raw");