@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 +109 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +109 -13
- package/dist/index.js.map +1 -1
- package/dist/{svgTextToPath-CBcIgtk1.cjs → svgTextToPath-B4SihUQv.cjs} +40 -17
- package/dist/svgTextToPath-B4SihUQv.cjs.map +1 -0
- package/dist/{svgTextToPath-CShDi4Ky.js → svgTextToPath-BmOzWJsV.js} +40 -17
- package/dist/svgTextToPath-BmOzWJsV.js.map +1 -0
- package/package.json +1 -1
- package/dist/svgTextToPath-CBcIgtk1.cjs.map +0 -1
- package/dist/svgTextToPath-CShDi4Ky.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -11646,6 +11646,8 @@ function applyFormDataToConfig(config, mappings, formValues, repeatableSectionsF
|
|
|
11646
11646
|
}
|
|
11647
11647
|
return cloned;
|
|
11648
11648
|
}
|
|
11649
|
+
const ENTRY_ID_KEY = "__entryId";
|
|
11650
|
+
const ENTRY_NAME_KEY = "__entryName";
|
|
11649
11651
|
function hasBaseNodeId(node) {
|
|
11650
11652
|
return node.__baseNodeId != null;
|
|
11651
11653
|
}
|
|
@@ -12225,6 +12227,76 @@ function getRenderableFormSections(schema) {
|
|
|
12225
12227
|
if (!pages.length) return base;
|
|
12226
12228
|
return [...base, ...pages.map(repeatablePageToSection)];
|
|
12227
12229
|
}
|
|
12230
|
+
function isRecord(value) {
|
|
12231
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
12232
|
+
}
|
|
12233
|
+
function getRepeatableEntryMeta(entry, section) {
|
|
12234
|
+
const entryNameKey = section.entryNameFieldKey;
|
|
12235
|
+
const nameCandidate = entry[ENTRY_NAME_KEY] ?? (entryNameKey ? entry[entryNameKey] : void 0) ?? entry.section_title ?? entry.label ?? entry.name;
|
|
12236
|
+
return {
|
|
12237
|
+
id: typeof entry[ENTRY_ID_KEY] === "string" ? entry[ENTRY_ID_KEY] : void 0,
|
|
12238
|
+
name: typeof nameCandidate === "string" ? nameCandidate : void 0
|
|
12239
|
+
};
|
|
12240
|
+
}
|
|
12241
|
+
function extractSectionStateCandidate(values, sections) {
|
|
12242
|
+
if (!isRecord(values)) return null;
|
|
12243
|
+
const raw = isDefaultDataV2(values) && isRecord(values.sectionState) ? values.sectionState : values;
|
|
12244
|
+
const sectionIds = new Set(sections.map((section) => section.id));
|
|
12245
|
+
const looksLikeSectionState = Object.keys(raw).some((key) => sectionIds.has(key) || key.startsWith("section_"));
|
|
12246
|
+
return looksLikeSectionState ? raw : null;
|
|
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
|
+
function mergeRepeatableEntryMeta(target, metaSource, sections) {
|
|
12262
|
+
if (!metaSource) return target;
|
|
12263
|
+
let changed = false;
|
|
12264
|
+
const next = { ...target };
|
|
12265
|
+
const repeatableIds = new Set(sections.filter((section) => section.type === "repeatable").map((section) => section.id));
|
|
12266
|
+
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
|
+
for (const [key, targetEntries] of Object.entries(target)) {
|
|
12269
|
+
if (!isRepeatableStateKey(key) || !Array.isArray(targetEntries)) continue;
|
|
12270
|
+
const sourceEntries = metaSource[key];
|
|
12271
|
+
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
|
+
const mergedEntries = targetEntries.map((entry, index) => {
|
|
12284
|
+
if (!isRecord(entry)) return entry;
|
|
12285
|
+
const sourceEntry = entryIdentityTokens(entry, section).map((token) => sourceByToken.get(token)).find((match) => !!match) ?? sourceEntries[index];
|
|
12286
|
+
if (!isRecord(sourceEntry)) return entry;
|
|
12287
|
+
const id = sourceEntry[ENTRY_ID_KEY];
|
|
12288
|
+
const name = sourceEntry[ENTRY_NAME_KEY];
|
|
12289
|
+
const additions = {};
|
|
12290
|
+
if (typeof id === "string" && id.trim() && typeof entry[ENTRY_ID_KEY] !== "string") additions[ENTRY_ID_KEY] = id;
|
|
12291
|
+
if (typeof name === "string" && name.trim() && typeof entry[ENTRY_NAME_KEY] !== "string") additions[ENTRY_NAME_KEY] = name;
|
|
12292
|
+
if (!Object.keys(additions).length) return entry;
|
|
12293
|
+
changed = true;
|
|
12294
|
+
return { ...entry, ...additions };
|
|
12295
|
+
});
|
|
12296
|
+
next[key] = mergedEntries;
|
|
12297
|
+
}
|
|
12298
|
+
return changed ? next : target;
|
|
12299
|
+
}
|
|
12228
12300
|
function buildRepeatablePagesInputForApply(schema, sectionState) {
|
|
12229
12301
|
var _a;
|
|
12230
12302
|
if (!((_a = schema == null ? void 0 : schema.repeatablePages) == null ? void 0 : _a.length)) return [];
|
|
@@ -12471,6 +12543,7 @@ async function resolveFromForm(options) {
|
|
|
12471
12543
|
} else {
|
|
12472
12544
|
inferredSections = [];
|
|
12473
12545
|
}
|
|
12546
|
+
const defaultFormMetaSectionState = extractSectionStateCandidate(defaultForm == null ? void 0 : defaultForm.values, inferredSections) ?? extractSectionStateCandidate(defaultForm == null ? void 0 : defaultForm.saved_data, inferredSections);
|
|
12474
12547
|
let mergedSectionState = { ...sectionState };
|
|
12475
12548
|
const templateDefaultData = templateRow.default_data;
|
|
12476
12549
|
if (templateDefaultData && isDefaultDataV2(templateDefaultData)) {
|
|
@@ -12481,6 +12554,7 @@ async function resolveFromForm(options) {
|
|
|
12481
12554
|
}
|
|
12482
12555
|
}
|
|
12483
12556
|
}
|
|
12557
|
+
mergedSectionState = mergeRepeatableEntryMeta(mergedSectionState, defaultFormMetaSectionState, inferredSections);
|
|
12484
12558
|
const flatFormData = flattenSectionStateToFormData(mergedSectionState, inferredSections);
|
|
12485
12559
|
const dynamicFields = templateConfig.dynamicFields || [];
|
|
12486
12560
|
const mappings = [];
|
|
@@ -12502,10 +12576,7 @@ async function resolveFromForm(options) {
|
|
|
12502
12576
|
const entries = mergedSectionState[s.id] ?? [];
|
|
12503
12577
|
const nodeId = s.treeNodeId ?? s.id;
|
|
12504
12578
|
const schemaRepeatable = repeatableFromSchemaByBase.get(baseId(nodeId));
|
|
12505
|
-
const entryMeta = entries.map((e) => (
|
|
12506
|
-
id: typeof (e == null ? void 0 : e.__entryId) === "string" ? e.__entryId : void 0,
|
|
12507
|
-
name: typeof (e == null ? void 0 : e.__entryName) === "string" ? e.__entryName : void 0
|
|
12508
|
-
}));
|
|
12579
|
+
const entryMeta = entries.map((e) => getRepeatableEntryMeta(e, s));
|
|
12509
12580
|
return { nodeId, label: s.label, entryCount: Math.max(1, entries.length), entryFilter: schemaRepeatable == null ? void 0 : schemaRepeatable.entryFilter, entryMeta };
|
|
12510
12581
|
});
|
|
12511
12582
|
const nestedRepeatables = inferredSections.filter((s) => s.type === "repeatable" && s.parentId != null).map((s) => {
|
|
@@ -12519,10 +12590,7 @@ async function resolveFromForm(options) {
|
|
|
12519
12590
|
const merged = [];
|
|
12520
12591
|
for (let pi = 0; pi < parentEntries.length; pi++) {
|
|
12521
12592
|
const childEntries = mergedSectionState[`${parentId}_${pi}_${s.id}`] ?? [];
|
|
12522
|
-
const meta = childEntries.map((e) => (
|
|
12523
|
-
id: typeof (e == null ? void 0 : e.__entryId) === "string" ? e.__entryId : void 0,
|
|
12524
|
-
name: typeof (e == null ? void 0 : e.__entryName) === "string" ? e.__entryName : void 0
|
|
12525
|
-
}));
|
|
12593
|
+
const meta = childEntries.map((e) => getRepeatableEntryMeta(e, s));
|
|
12526
12594
|
nestedEntryMeta[`${baseId(parentNodeId)}_${pi + 1}_${baseId(nodeId)}`] = meta;
|
|
12527
12595
|
merged.push(...meta);
|
|
12528
12596
|
}
|
|
@@ -14613,6 +14681,13 @@ function containsDevanagari(text) {
|
|
|
14613
14681
|
}
|
|
14614
14682
|
return false;
|
|
14615
14683
|
}
|
|
14684
|
+
function containsSymbol(text) {
|
|
14685
|
+
if (!text) return false;
|
|
14686
|
+
for (const char of text) {
|
|
14687
|
+
if (classifyChar(char) === "symbol") return true;
|
|
14688
|
+
}
|
|
14689
|
+
return false;
|
|
14690
|
+
}
|
|
14616
14691
|
function isBasicLatinOrLatin1(char) {
|
|
14617
14692
|
const c = char.codePointAt(0) ?? 0;
|
|
14618
14693
|
return c <= 591;
|
|
@@ -14645,7 +14720,7 @@ function rewriteSvgFontsForJsPDF(svgStr) {
|
|
|
14645
14720
|
var _a, _b;
|
|
14646
14721
|
const parser = new DOMParser();
|
|
14647
14722
|
const doc = parser.parseFromString(svgStr, "image/svg+xml");
|
|
14648
|
-
const
|
|
14723
|
+
const allTextEls = Array.from(doc.querySelectorAll("text, tspan, textPath"));
|
|
14649
14724
|
const readStyleToken = (style, prop) => {
|
|
14650
14725
|
var _a2;
|
|
14651
14726
|
const match = style.match(new RegExp(`${prop}\\s*:\\s*([^;]+)`, "i"));
|
|
@@ -14674,7 +14749,17 @@ function rewriteSvgFontsForJsPDF(svgStr) {
|
|
|
14674
14749
|
stylePairs.push(`font-style: normal`);
|
|
14675
14750
|
return stylePairs.join("; ");
|
|
14676
14751
|
};
|
|
14677
|
-
|
|
14752
|
+
const getDepth = (el) => {
|
|
14753
|
+
let depth = 0;
|
|
14754
|
+
let current = el.parentElement;
|
|
14755
|
+
while (current) {
|
|
14756
|
+
depth++;
|
|
14757
|
+
current = current.parentElement;
|
|
14758
|
+
}
|
|
14759
|
+
return depth;
|
|
14760
|
+
};
|
|
14761
|
+
const sourceMeta = /* @__PURE__ */ new Map();
|
|
14762
|
+
for (const el of allTextEls) {
|
|
14678
14763
|
const inlineStyle = el.getAttribute("style") || "";
|
|
14679
14764
|
const rawFf = resolveInheritedValue(el, "font-family");
|
|
14680
14765
|
if (!rawFf) continue;
|
|
@@ -14686,12 +14771,21 @@ function rewriteSvgFontsForJsPDF(svgStr) {
|
|
|
14686
14771
|
const resolved = resolveFontWeight(weight);
|
|
14687
14772
|
const isItalic = /italic|oblique/i.test(styleRaw);
|
|
14688
14773
|
const jsPdfName = getEmbeddedJsPDFFontName(clean, resolved, isItalic);
|
|
14774
|
+
sourceMeta.set(el, { clean, resolved, isItalic, jsPdfName, inlineStyle, weight });
|
|
14775
|
+
}
|
|
14776
|
+
const textEls = allTextEls.sort((a, b) => getDepth(b) - getDepth(a));
|
|
14777
|
+
for (const el of textEls) {
|
|
14778
|
+
if (!el.isConnected) continue;
|
|
14779
|
+
const meta = sourceMeta.get(el);
|
|
14780
|
+
if (!meta) continue;
|
|
14781
|
+
const { clean, resolved, isItalic, jsPdfName, inlineStyle, weight } = meta;
|
|
14689
14782
|
el.setAttribute("data-source-font-family", clean);
|
|
14690
14783
|
el.setAttribute("data-source-font-weight", String(resolved));
|
|
14691
14784
|
el.setAttribute("data-source-font-style", isItalic ? "italic" : "normal");
|
|
14692
14785
|
const directText = Array.from(el.childNodes).filter((n) => n.nodeType === 3).map((n) => n.textContent || "").join("");
|
|
14693
14786
|
const hasDevanagari = containsDevanagari(directText);
|
|
14694
|
-
|
|
14787
|
+
const hasSymbol = containsSymbol(directText);
|
|
14788
|
+
if ((hasDevanagari || hasSymbol) && directText.length > 0) {
|
|
14695
14789
|
const devanagariWeight = resolveFontWeight(weight);
|
|
14696
14790
|
const devanagariJsPdfName = getEmbeddedJsPDFFontName(FONT_FALLBACK_DEVANAGARI, devanagariWeight);
|
|
14697
14791
|
const symbolJsPdfName = isFontAvailable(FONT_FALLBACK_SYMBOLS) ? getEmbeddedJsPDFFontName(FONT_FALLBACK_SYMBOLS, 400) : jsPdfName;
|
|
@@ -14699,7 +14793,7 @@ function rewriteSvgFontsForJsPDF(svgStr) {
|
|
|
14699
14793
|
for (const node of childNodes) {
|
|
14700
14794
|
if (node.nodeType !== 3 || !node.textContent) continue;
|
|
14701
14795
|
const runs = splitIntoRuns(node.textContent);
|
|
14702
|
-
if (runs.length <= 1 && ((_b = runs[0]) == null ? void 0 : _b.runType)
|
|
14796
|
+
if (runs.length <= 1 && ((_b = runs[0]) == null ? void 0 : _b.runType) === "main") continue;
|
|
14703
14797
|
const fragment = doc.createDocumentFragment();
|
|
14704
14798
|
for (const run of runs) {
|
|
14705
14799
|
const tspan = doc.createElementNS("http://www.w3.org/2000/svg", "tspan");
|
|
@@ -14750,6 +14844,8 @@ async function embedFontsInPdf(pdf, fontFamilies, fontBaseUrl) {
|
|
|
14750
14844
|
const embedded = /* @__PURE__ */ new Set();
|
|
14751
14845
|
const weights = [300, 400, 500, 600, 700];
|
|
14752
14846
|
const tasks = [];
|
|
14847
|
+
fontFamilies.add(FONT_FALLBACK_SYMBOLS);
|
|
14848
|
+
fontFamilies.add(FONT_FALLBACK_DEVANAGARI);
|
|
14753
14849
|
for (const family of fontFamilies) {
|
|
14754
14850
|
if (!isFontAvailable(family)) {
|
|
14755
14851
|
console.warn(`[pdf-fonts] No TTF mapping for "${family}" — will use Helvetica fallback`);
|
|
@@ -16215,7 +16311,7 @@ async function assemblePdfFromSvgs(svgResults, options = {}) {
|
|
|
16215
16311
|
}
|
|
16216
16312
|
if (shouldOutlineText) {
|
|
16217
16313
|
try {
|
|
16218
|
-
const { convertAllTextToPath } = await import("./svgTextToPath-
|
|
16314
|
+
const { convertAllTextToPath } = await import("./svgTextToPath-BmOzWJsV.js");
|
|
16219
16315
|
pageSvg = await convertAllTextToPath(pageSvg, fontBaseUrl, { mode: outlineSubMode });
|
|
16220
16316
|
try {
|
|
16221
16317
|
dumpSvgTextDiagnostics(pageSvg, i, PARITY_TAG, "STAGE-1b-after-text-to-path-raw");
|