@docengine/pdf-renderer 0.0.0-stage → 0.0.106
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/README.md +10 -3
- package/dist/.tsbuildinfo +1 -0
- package/dist/browser.d.ts +16 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +20 -0
- package/dist/browser.js.map +1 -0
- package/dist/browser.sf-stub.d.ts +9 -0
- package/dist/browser.sf-stub.d.ts.map +1 -0
- package/dist/browser.sf-stub.js +19 -0
- package/dist/browser.sf-stub.js.map +1 -0
- package/dist/document-pdf-definition-browser.d.ts +10 -0
- package/dist/document-pdf-definition-browser.d.ts.map +1 -0
- package/dist/document-pdf-definition-browser.js +9 -0
- package/dist/document-pdf-definition-browser.js.map +1 -0
- package/dist/document-pdf-definition-factory.d.ts +29 -0
- package/dist/document-pdf-definition-factory.d.ts.map +1 -0
- package/dist/document-pdf-definition-factory.js +170 -0
- package/dist/document-pdf-definition-factory.js.map +1 -0
- package/dist/document-pdf-definition-node.d.ts +10 -0
- package/dist/document-pdf-definition-node.d.ts.map +1 -0
- package/dist/document-pdf-definition-node.js +9 -0
- package/dist/document-pdf-definition-node.js.map +1 -0
- package/dist/document-pdf-definition-preview-browser.d.ts +9 -0
- package/dist/document-pdf-definition-preview-browser.d.ts.map +1 -0
- package/dist/document-pdf-definition-preview-browser.js +4 -0
- package/dist/document-pdf-definition-preview-browser.js.map +1 -0
- package/dist/document-pdf-definition-preview-node.d.ts +9 -0
- package/dist/document-pdf-definition-preview-node.d.ts.map +1 -0
- package/dist/document-pdf-definition-preview-node.js +4 -0
- package/dist/document-pdf-definition-preview-node.js.map +1 -0
- package/dist/document-pdf-definition-preview.d.ts +13 -0
- package/dist/document-pdf-definition-preview.d.ts.map +1 -0
- package/dist/document-pdf-definition-preview.js +42 -0
- package/dist/document-pdf-definition-preview.js.map +1 -0
- package/dist/fonts-browser-registry.d.ts +13 -0
- package/dist/fonts-browser-registry.d.ts.map +1 -0
- package/dist/fonts-browser-registry.js +7 -0
- package/dist/fonts-browser-registry.js.map +1 -0
- package/dist/fonts-browser-vfs.d.ts +12 -0
- package/dist/fonts-browser-vfs.d.ts.map +1 -0
- package/dist/fonts-browser-vfs.js +4 -0
- package/dist/fonts-browser-vfs.js.map +1 -0
- package/dist/fonts-browser-vfs.sf-stub.d.ts +5 -0
- package/dist/fonts-browser-vfs.sf-stub.d.ts.map +1 -0
- package/dist/fonts-browser-vfs.sf-stub.js +5 -0
- package/dist/fonts-browser-vfs.sf-stub.js.map +1 -0
- package/dist/fonts-browser.d.ts +22 -0
- package/dist/fonts-browser.d.ts.map +1 -0
- package/dist/fonts-browser.js +22 -0
- package/dist/fonts-browser.js.map +1 -0
- package/dist/fonts-registry.d.ts +17 -0
- package/dist/fonts-registry.d.ts.map +1 -0
- package/dist/fonts-registry.js +83 -0
- package/dist/fonts-registry.js.map +1 -0
- package/dist/fonts-registry.test.d.ts +2 -0
- package/dist/fonts-registry.test.d.ts.map +1 -0
- package/dist/fonts-registry.test.js +22 -0
- package/dist/fonts-registry.test.js.map +1 -0
- package/dist/fonts.d.ts +16 -0
- package/dist/fonts.d.ts.map +1 -0
- package/dist/fonts.js +17 -0
- package/dist/fonts.js.map +1 -0
- package/dist/generate-html.d.ts +33 -0
- package/dist/generate-html.d.ts.map +1 -0
- package/dist/generate-html.js +90 -0
- package/dist/generate-html.js.map +1 -0
- package/dist/generate-html.test.d.ts +2 -0
- package/dist/generate-html.test.d.ts.map +1 -0
- package/dist/generate-html.test.js +270 -0
- package/dist/generate-html.test.js.map +1 -0
- package/dist/generate-pdf-browser.d.ts +14 -0
- package/dist/generate-pdf-browser.d.ts.map +1 -0
- package/dist/generate-pdf-browser.js +55 -0
- package/dist/generate-pdf-browser.js.map +1 -0
- package/dist/generate-pdf.d.ts +10 -0
- package/dist/generate-pdf.d.ts.map +1 -0
- package/dist/generate-pdf.js +36 -0
- package/dist/generate-pdf.js.map +1 -0
- package/dist/html-environment.d.ts +10 -0
- package/dist/html-environment.d.ts.map +1 -0
- package/dist/html-environment.js +30 -0
- package/dist/html-environment.js.map +1 -0
- package/dist/html-text.d.ts +46 -0
- package/dist/html-text.d.ts.map +1 -0
- package/dist/html-text.js +451 -0
- package/dist/html-text.js.map +1 -0
- package/dist/html-text.test.d.ts +2 -0
- package/dist/html-text.test.d.ts.map +1 -0
- package/dist/html-text.test.js +79 -0
- package/dist/html-text.test.js.map +1 -0
- package/dist/image-prefetch.d.ts +7 -0
- package/dist/image-prefetch.d.ts.map +1 -0
- package/dist/image-prefetch.js +50 -0
- package/dist/image-prefetch.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/map-editor-pdf-options.d.ts +13 -0
- package/dist/map-editor-pdf-options.d.ts.map +1 -0
- package/dist/map-editor-pdf-options.js +28 -0
- package/dist/map-editor-pdf-options.js.map +1 -0
- package/dist/map-editor-pdf-options.test.d.ts +2 -0
- package/dist/map-editor-pdf-options.test.d.ts.map +1 -0
- package/dist/map-editor-pdf-options.test.js +16 -0
- package/dist/map-editor-pdf-options.test.js.map +1 -0
- package/dist/merge-document.d.ts +3 -0
- package/dist/merge-document.d.ts.map +1 -0
- package/dist/merge-document.js +29 -0
- package/dist/merge-document.js.map +1 -0
- package/dist/multipage-renderer.d.ts +31 -0
- package/dist/multipage-renderer.d.ts.map +1 -0
- package/dist/multipage-renderer.js +131 -0
- package/dist/multipage-renderer.js.map +1 -0
- package/dist/pdf-horizontal-rule.d.ts +18 -0
- package/dist/pdf-horizontal-rule.d.ts.map +1 -0
- package/dist/pdf-horizontal-rule.js +46 -0
- package/dist/pdf-horizontal-rule.js.map +1 -0
- package/dist/pdf-inline-field-background.d.ts +19 -0
- package/dist/pdf-inline-field-background.d.ts.map +1 -0
- package/dist/pdf-inline-field-background.js +106 -0
- package/dist/pdf-inline-field-background.js.map +1 -0
- package/dist/pdf-inline-field-background.test.d.ts +2 -0
- package/dist/pdf-inline-field-background.test.d.ts.map +1 -0
- package/dist/pdf-inline-field-background.test.js +22 -0
- package/dist/pdf-inline-field-background.test.js.map +1 -0
- package/dist/pdf-renderer.test.d.ts +2 -0
- package/dist/pdf-renderer.test.d.ts.map +1 -0
- package/dist/pdf-renderer.test.js +2614 -0
- package/dist/pdf-renderer.test.js.map +1 -0
- package/dist/pdfmake.sf-stub.d.ts +11 -0
- package/dist/pdfmake.sf-stub.d.ts.map +1 -0
- package/dist/pdfmake.sf-stub.js +16 -0
- package/dist/pdfmake.sf-stub.js.map +1 -0
- package/dist/preview-dom-to-pdf.d.ts +25 -0
- package/dist/preview-dom-to-pdf.d.ts.map +1 -0
- package/dist/preview-dom-to-pdf.js +694 -0
- package/dist/preview-dom-to-pdf.js.map +1 -0
- package/dist/preview-dom-to-pdf.test.d.ts +2 -0
- package/dist/preview-dom-to-pdf.test.d.ts.map +1 -0
- package/dist/preview-dom-to-pdf.test.js +734 -0
- package/dist/preview-dom-to-pdf.test.js.map +1 -0
- package/dist/preview-field-plugins.d.ts +6 -0
- package/dist/preview-field-plugins.d.ts.map +1 -0
- package/dist/preview-field-plugins.js +37 -0
- package/dist/preview-field-plugins.js.map +1 -0
- package/dist/repeatable-section-header.d.ts +39 -0
- package/dist/repeatable-section-header.d.ts.map +1 -0
- package/dist/repeatable-section-header.js +145 -0
- package/dist/repeatable-section-header.js.map +1 -0
- package/dist/repeatable-table-pagination.d.ts +17 -0
- package/dist/repeatable-table-pagination.d.ts.map +1 -0
- package/dist/repeatable-table-pagination.js +255 -0
- package/dist/repeatable-table-pagination.js.map +1 -0
- package/dist/repeatable-table-pagination.test.d.ts +2 -0
- package/dist/repeatable-table-pagination.test.d.ts.map +1 -0
- package/dist/repeatable-table-pagination.test.js +110 -0
- package/dist/repeatable-table-pagination.test.js.map +1 -0
- package/dist/rich-text-pdf-styles.d.ts +15 -0
- package/dist/rich-text-pdf-styles.d.ts.map +1 -0
- package/dist/rich-text-pdf-styles.js +30 -0
- package/dist/rich-text-pdf-styles.js.map +1 -0
- package/dist/segment-renderer.d.ts +26 -0
- package/dist/segment-renderer.d.ts.map +1 -0
- package/dist/segment-renderer.js +1252 -0
- package/dist/segment-renderer.js.map +1 -0
- package/dist/style-mapper.d.ts +32 -0
- package/dist/style-mapper.d.ts.map +1 -0
- package/dist/style-mapper.js +124 -0
- package/dist/style-mapper.js.map +1 -0
- package/dist/style-mapper.test.d.ts +2 -0
- package/dist/style-mapper.test.d.ts.map +1 -0
- package/dist/style-mapper.test.js +77 -0
- package/dist/style-mapper.test.js.map +1 -0
- package/dist/table-column-width.d.ts +20 -0
- package/dist/table-column-width.d.ts.map +1 -0
- package/dist/table-column-width.js +56 -0
- package/dist/table-column-width.js.map +1 -0
- package/dist/table-column-width.test.d.ts +2 -0
- package/dist/table-column-width.test.d.ts.map +1 -0
- package/dist/table-column-width.test.js +40 -0
- package/dist/table-column-width.test.js.map +1 -0
- package/dist/table-layout.d.ts +44 -0
- package/dist/table-layout.d.ts.map +1 -0
- package/dist/table-layout.js +70 -0
- package/dist/table-layout.js.map +1 -0
- package/dist/types.d.ts +73 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/units.d.ts +29 -0
- package/dist/units.d.ts.map +1 -0
- package/dist/units.js +63 -0
- package/dist/units.js.map +1 -0
- package/package.json +36 -6
|
@@ -0,0 +1,694 @@
|
|
|
1
|
+
import { primaryFontFamily } from './fonts-registry.js';
|
|
2
|
+
import { cssFontSizeToPdfPt, DEFAULT_BODY_FONT_PT, cssFontWeightToPdfBold } from './style-mapper.js';
|
|
3
|
+
import { parseCssColor, pdfInlineCodeStyle, pdfMarkStyle, } from './rich-text-pdf-styles.js';
|
|
4
|
+
import { TABLE_PDF_LINE_HEIGHT, resolveVisionTablePdfLayout } from './table-layout.js';
|
|
5
|
+
import { tableColumnWidthsFromColElements } from './table-column-width.js';
|
|
6
|
+
import { finalizePdfInlineParts, htmlToPdfBlocks, plainTextToPdfText, } from './html-text.js';
|
|
7
|
+
import { buildPdfHorizontalRuleBlock, buildPdfSectionBorderRuleBlock, } from './pdf-horizontal-rule.js';
|
|
8
|
+
const HR_SPLIT_RE = /<hr\b[^>]*\/?>/gi;
|
|
9
|
+
export function domInlineStyleToPdf(styleValue, emBasePt) {
|
|
10
|
+
const emBasePx = (emBasePt * 96) / 72;
|
|
11
|
+
const out = {};
|
|
12
|
+
for (const rule of String(styleValue ?? '').split(';')) {
|
|
13
|
+
const colon = rule.indexOf(':');
|
|
14
|
+
if (colon === -1)
|
|
15
|
+
continue;
|
|
16
|
+
const prop = rule.slice(0, colon).trim().toLowerCase();
|
|
17
|
+
const value = rule.slice(colon + 1).trim();
|
|
18
|
+
const lower = value.toLowerCase();
|
|
19
|
+
if (prop === 'font-weight') {
|
|
20
|
+
const bold = cssFontWeightToPdfBold(value);
|
|
21
|
+
if (bold === true)
|
|
22
|
+
out.bold = true;
|
|
23
|
+
else if (bold === false)
|
|
24
|
+
out.bold = false;
|
|
25
|
+
}
|
|
26
|
+
else if (prop === 'font-style' && lower === 'italic') {
|
|
27
|
+
out.italics = true;
|
|
28
|
+
}
|
|
29
|
+
else if (prop === 'text-decoration' || prop === 'text-decoration-line') {
|
|
30
|
+
if (lower.includes('line-through'))
|
|
31
|
+
out.decoration = 'lineThrough';
|
|
32
|
+
else if (lower.includes('underline'))
|
|
33
|
+
out.decoration = 'underline';
|
|
34
|
+
}
|
|
35
|
+
else if (prop === 'font-size') {
|
|
36
|
+
const fontSize = cssFontSizeToPdfPt(value, emBasePx);
|
|
37
|
+
if (fontSize)
|
|
38
|
+
out.fontSize = fontSize;
|
|
39
|
+
}
|
|
40
|
+
else if (prop === 'color') {
|
|
41
|
+
const color = parseCssColor(value);
|
|
42
|
+
if (color)
|
|
43
|
+
out.color = color;
|
|
44
|
+
}
|
|
45
|
+
else if (prop === 'background-color' || prop === 'background') {
|
|
46
|
+
const background = parseCssColor(value);
|
|
47
|
+
if (background)
|
|
48
|
+
out.background = background;
|
|
49
|
+
}
|
|
50
|
+
else if (prop === 'font-family' && value) {
|
|
51
|
+
out.fontFamily = value;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
function elementStyleToPdf(el, ctx) {
|
|
57
|
+
const props = domInlineStyleToPdf(el.getAttribute('style') ?? '', ctx.baseFontSize);
|
|
58
|
+
const fontFamily = el.style?.fontFamily || props.fontFamily;
|
|
59
|
+
if (fontFamily) {
|
|
60
|
+
props.font = ctx.resolveFontName(primaryFontFamily(String(fontFamily)) || String(fontFamily));
|
|
61
|
+
delete props.fontFamily;
|
|
62
|
+
}
|
|
63
|
+
// Keep intentional field displayStyle decorations (underline / strike).
|
|
64
|
+
// Fill-mode highlight underlines live in CSS, not in the inline style attribute,
|
|
65
|
+
// so they are never picked up by domInlineStyleToPdf.
|
|
66
|
+
return props;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Copy field-token styles for PDF serialization.
|
|
70
|
+
* Prefer the token's own inline style (displayStyle); never pull text-decoration
|
|
71
|
+
* from computed styles so fill-mode highlight underlines stay out of the export.
|
|
72
|
+
*/
|
|
73
|
+
function buildFieldTokenStyleAttr(token) {
|
|
74
|
+
const styles = [];
|
|
75
|
+
const inline = token.getAttribute('style') ?? '';
|
|
76
|
+
if (inline.trim()) {
|
|
77
|
+
for (const rule of inline.split(';')) {
|
|
78
|
+
const trimmed = rule.trim();
|
|
79
|
+
if (!trimmed)
|
|
80
|
+
continue;
|
|
81
|
+
styles.push(trimmed);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
let computed = null;
|
|
85
|
+
if (typeof getComputedStyle === 'function') {
|
|
86
|
+
try {
|
|
87
|
+
computed = getComputedStyle(token);
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
computed = null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const hasWeight = styles.some((rule) => rule.toLowerCase().startsWith('font-weight'));
|
|
94
|
+
if (!hasWeight) {
|
|
95
|
+
const weight = token.style?.fontWeight || computed?.fontWeight;
|
|
96
|
+
const bold = cssFontWeightToPdfBold(weight);
|
|
97
|
+
if (bold === true)
|
|
98
|
+
styles.push('font-weight: bold');
|
|
99
|
+
else if (bold === false)
|
|
100
|
+
styles.push('font-weight: normal');
|
|
101
|
+
}
|
|
102
|
+
const hasSize = styles.some((rule) => rule.toLowerCase().startsWith('font-size'));
|
|
103
|
+
if (!hasSize) {
|
|
104
|
+
const fontSize = token.style?.fontSize || computed?.fontSize;
|
|
105
|
+
if (fontSize)
|
|
106
|
+
styles.push(`font-size: ${fontSize}`);
|
|
107
|
+
}
|
|
108
|
+
const hasColor = styles.some((rule) => rule.toLowerCase().startsWith('color:'));
|
|
109
|
+
if (!hasColor) {
|
|
110
|
+
const color = token.style?.color || computed?.color;
|
|
111
|
+
if (color && /^#[0-9a-f]{3,8}$/i.test(color))
|
|
112
|
+
styles.push(`color: ${color}`);
|
|
113
|
+
}
|
|
114
|
+
const hasStyle = styles.some((rule) => rule.toLowerCase().startsWith('font-style'));
|
|
115
|
+
if (!hasStyle) {
|
|
116
|
+
const fontStyle = token.style?.fontStyle || computed?.fontStyle;
|
|
117
|
+
if (fontStyle === 'italic')
|
|
118
|
+
styles.push('font-style: italic');
|
|
119
|
+
}
|
|
120
|
+
const hasBackground = styles.some((rule) => rule.toLowerCase().startsWith('background-color'));
|
|
121
|
+
if (!hasBackground) {
|
|
122
|
+
const bg = token.style?.backgroundColor || computed?.backgroundColor;
|
|
123
|
+
if (bg && bg !== 'transparent' && bg !== 'rgba(0, 0, 0, 0)') {
|
|
124
|
+
styles.push(`background-color: ${bg}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Intentional underline/strike from displayStyle is already on the inline attribute.
|
|
128
|
+
// Do not copy text-decoration from computed style (fill-mode highlight CSS).
|
|
129
|
+
return styles.join('; ');
|
|
130
|
+
}
|
|
131
|
+
function appendTextWithPdfBreaks(doc, target, raw) {
|
|
132
|
+
const text = String(raw ?? '').replace(/\u200B/g, '').replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
133
|
+
if (!text)
|
|
134
|
+
return;
|
|
135
|
+
if (!text.includes('\n')) {
|
|
136
|
+
target.appendChild(doc.createTextNode(text));
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const pieces = text.split('\n');
|
|
140
|
+
pieces.forEach((piece, index) => {
|
|
141
|
+
if (piece)
|
|
142
|
+
target.appendChild(doc.createTextNode(piece));
|
|
143
|
+
if (index < pieces.length - 1)
|
|
144
|
+
target.appendChild(doc.createElement('br'));
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Copy field-token children for PDF HTML serialization.
|
|
149
|
+
* textContent flattens `<br>` / block markup, so HTML addresses become one line.
|
|
150
|
+
*/
|
|
151
|
+
function appendTokenContentsForPdf(source, target) {
|
|
152
|
+
const doc = source.ownerDocument;
|
|
153
|
+
for (const child of [...source.childNodes]) {
|
|
154
|
+
if (child.nodeType === Node.TEXT_NODE) {
|
|
155
|
+
appendTextWithPdfBreaks(doc, target, String(child.textContent ?? ''));
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (child.nodeType !== Node.ELEMENT_NODE)
|
|
159
|
+
continue;
|
|
160
|
+
if (child.tagName === 'BR') {
|
|
161
|
+
target.appendChild(doc.createElement('br'));
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
const clone = child.cloneNode(false);
|
|
165
|
+
appendTokenContentsForPdf(child, clone);
|
|
166
|
+
target.appendChild(clone);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function replaceFieldTokenWithStyledSpan(token) {
|
|
170
|
+
const span = token.ownerDocument.createElement('span');
|
|
171
|
+
const styleAttr = buildFieldTokenStyleAttr(token);
|
|
172
|
+
if (styleAttr)
|
|
173
|
+
span.setAttribute('style', styleAttr);
|
|
174
|
+
appendTokenContentsForPdf(token, span);
|
|
175
|
+
token.replaceWith(span);
|
|
176
|
+
}
|
|
177
|
+
function isHiddenEmptyPreviewToken(el, ctx) {
|
|
178
|
+
// Required empties keep their placeholder in preview/PDF — match CSS:
|
|
179
|
+
// .preview-document--hide-empty .field-token--empty:not(.field-token--required-missing)
|
|
180
|
+
return ctx.hideEmptyInPreview === true
|
|
181
|
+
&& el.classList?.contains('field-token--preview')
|
|
182
|
+
&& el.classList?.contains('field-token--empty')
|
|
183
|
+
&& !el.classList?.contains('field-token--required-missing');
|
|
184
|
+
}
|
|
185
|
+
function findRepeaterTokenInElement(el) {
|
|
186
|
+
if (el.classList?.contains('field-token--repeater'))
|
|
187
|
+
return el;
|
|
188
|
+
const direct = el.querySelector(':scope > .field-token--repeater');
|
|
189
|
+
if (direct)
|
|
190
|
+
return direct;
|
|
191
|
+
// Table cells wrap Child tokens; also check direct child field-token in td/line.
|
|
192
|
+
if (el.tagName === 'TD'
|
|
193
|
+
|| el.classList?.contains('document-align')
|
|
194
|
+
|| el.classList?.contains('preview-document__line')) {
|
|
195
|
+
const nested = el.querySelector('.field-token--repeater');
|
|
196
|
+
if (nested)
|
|
197
|
+
return nested;
|
|
198
|
+
}
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
function convertRepeaterTokenToPdfBlocks(tokenEl, ctx) {
|
|
202
|
+
const nestedPreview = tokenEl.querySelector('.field-token__repeater-preview .preview-document, .field-token__repeater-instance-body .preview-document');
|
|
203
|
+
if (nestedPreview) {
|
|
204
|
+
return previewDomToPdfContent(nestedPreview, ctx);
|
|
205
|
+
}
|
|
206
|
+
const emptyMsg = tokenEl.querySelector('.field-token__repeater-instance-empty');
|
|
207
|
+
if (emptyMsg && !ctx.hideEmptyInPreview) {
|
|
208
|
+
return [{
|
|
209
|
+
text: String(emptyMsg.textContent ?? '').trim(),
|
|
210
|
+
italics: true,
|
|
211
|
+
color: '#888888',
|
|
212
|
+
font: ctx.defaultFont,
|
|
213
|
+
margin: [0, 0, 0, 4],
|
|
214
|
+
}];
|
|
215
|
+
}
|
|
216
|
+
return [];
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Serialize preview section body HTML for htmlToPdfBlocks, preserving structure and field styles.
|
|
220
|
+
*/
|
|
221
|
+
export function serializePreviewBodyHtml(bodyEl, ctx = {}) {
|
|
222
|
+
const clone = bodyEl.cloneNode(true);
|
|
223
|
+
for (const token of clone.querySelectorAll('.field-token--preview')) {
|
|
224
|
+
if (isHiddenEmptyPreviewToken(token, ctx)) {
|
|
225
|
+
token.remove();
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
replaceFieldTokenWithStyledSpan(token);
|
|
229
|
+
}
|
|
230
|
+
return clone.innerHTML;
|
|
231
|
+
}
|
|
232
|
+
function convertSerializedHtmlToPdfBlocks(html, ctx) {
|
|
233
|
+
const source = String(html ?? '');
|
|
234
|
+
if (!source.trim())
|
|
235
|
+
return [];
|
|
236
|
+
const blocks = [];
|
|
237
|
+
const chunks = source.split(HR_SPLIT_RE);
|
|
238
|
+
for (let index = 0; index < chunks.length; index += 1) {
|
|
239
|
+
const chunk = chunks[index].trim();
|
|
240
|
+
if (chunk) {
|
|
241
|
+
for (const block of htmlToPdfBlocks(chunk, {
|
|
242
|
+
baseFontSize: ctx.baseFontSize,
|
|
243
|
+
baseFont: ctx.defaultFont,
|
|
244
|
+
})) {
|
|
245
|
+
const pdfBlock = {
|
|
246
|
+
text: finalizePdfInlineParts(block.parts, { font: ctx.defaultFont }),
|
|
247
|
+
};
|
|
248
|
+
if (block.alignment)
|
|
249
|
+
pdfBlock.alignment = block.alignment;
|
|
250
|
+
if (block.margin)
|
|
251
|
+
pdfBlock.margin = block.margin;
|
|
252
|
+
blocks.push(pdfBlock);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (index < chunks.length - 1) {
|
|
256
|
+
blocks.push(buildPdfHorizontalRuleBlock({ widthPt: ctx.contentWidthPt }));
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return blocks;
|
|
260
|
+
}
|
|
261
|
+
function walkInlineNodes(node, styleStack, ctx, parts) {
|
|
262
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
263
|
+
const text = String(node.textContent ?? '').replace(/\u200B/g, '');
|
|
264
|
+
if (!text)
|
|
265
|
+
return;
|
|
266
|
+
const style = styleStack[styleStack.length - 1] ?? {};
|
|
267
|
+
if (Object.keys(style).length) {
|
|
268
|
+
parts.push({ text, ...style });
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
parts.push(...plainTextToPdfText(text));
|
|
272
|
+
}
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
if (node.nodeType !== Node.ELEMENT_NODE)
|
|
276
|
+
return;
|
|
277
|
+
const el = node;
|
|
278
|
+
if (isHiddenEmptyPreviewToken(el, ctx))
|
|
279
|
+
return;
|
|
280
|
+
if (el.tagName === 'BUTTON' || el.classList?.contains('vision-table__row-remove'))
|
|
281
|
+
return;
|
|
282
|
+
if (el.tagName === 'BR') {
|
|
283
|
+
parts.push('\n');
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
if (el.tagName === 'IMG') {
|
|
287
|
+
const alt = el.getAttribute('alt');
|
|
288
|
+
if (alt) {
|
|
289
|
+
const style = styleStack[styleStack.length - 1] ?? {};
|
|
290
|
+
parts.push(Object.keys(style).length ? { text: alt, ...style } : alt);
|
|
291
|
+
}
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
let pushStyle = {};
|
|
295
|
+
if (el.tagName === 'B' || el.tagName === 'STRONG')
|
|
296
|
+
pushStyle.bold = true;
|
|
297
|
+
else if (el.tagName === 'I' || el.tagName === 'EM')
|
|
298
|
+
pushStyle.italics = true;
|
|
299
|
+
else if (el.tagName === 'U')
|
|
300
|
+
pushStyle.decoration = 'underline';
|
|
301
|
+
else if (el.tagName === 'S' || el.tagName === 'STRIKE')
|
|
302
|
+
pushStyle.decoration = 'lineThrough';
|
|
303
|
+
else if (el.tagName === 'MARK') {
|
|
304
|
+
pushStyle = { ...pdfMarkStyle(), ...elementStyleToPdf(el, ctx) };
|
|
305
|
+
}
|
|
306
|
+
else if (el.tagName === 'CODE') {
|
|
307
|
+
pushStyle = { ...pdfInlineCodeStyle(ctx.baseFontSize), ...elementStyleToPdf(el, ctx) };
|
|
308
|
+
}
|
|
309
|
+
else if (el.tagName === 'SPAN') {
|
|
310
|
+
pushStyle = { ...pushStyle, ...elementStyleToPdf(el, ctx) };
|
|
311
|
+
}
|
|
312
|
+
const nextStack = Object.keys(pushStyle).length
|
|
313
|
+
? [...styleStack, { ...(styleStack[styleStack.length - 1] ?? {}), ...pushStyle }]
|
|
314
|
+
: styleStack;
|
|
315
|
+
for (const child of el.childNodes) {
|
|
316
|
+
walkInlineNodes(child, nextStack, ctx, parts);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
function convertVisionTableFromContainer(containerEl, ctx) {
|
|
320
|
+
const tableEl = containerEl.matches?.('table.vision-table')
|
|
321
|
+
? containerEl
|
|
322
|
+
: containerEl.querySelector('table.vision-table');
|
|
323
|
+
return tableEl ? convertVisionTable(tableEl, ctx) : null;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Emit pdfmake image blocks for each .field-token--image element found in a node.
|
|
327
|
+
* Returns the image blocks emitted.
|
|
328
|
+
*/
|
|
329
|
+
function emitImageTokenBlocks(childEl, ctx) {
|
|
330
|
+
const imageBlocks = [];
|
|
331
|
+
const tokens = childEl.classList?.contains('field-token--image')
|
|
332
|
+
? [childEl]
|
|
333
|
+
: [...childEl.querySelectorAll('.field-token--image')];
|
|
334
|
+
for (const tok of tokens) {
|
|
335
|
+
const imgEl = tok.querySelector('img');
|
|
336
|
+
const src = imgEl?.getAttribute('src') || imgEl?.src || '';
|
|
337
|
+
const dataUrl = src ? ctx.imageMap.get(src) : undefined;
|
|
338
|
+
if (!dataUrl)
|
|
339
|
+
continue;
|
|
340
|
+
const maxWidthStr = tok.style?.getPropertyValue('--field-image-max-width') ||
|
|
341
|
+
tok.getAttribute?.('data-max-width') ||
|
|
342
|
+
'';
|
|
343
|
+
const maxWidth = parseInt(maxWidthStr, 10) || 320;
|
|
344
|
+
imageBlocks.push({ image: dataUrl, width: Math.min(maxWidth, 515), margin: [0, 4, 0, 4] });
|
|
345
|
+
const captionEl = tok.querySelector('.field-token__caption');
|
|
346
|
+
const caption = captionEl?.textContent?.replace(/\u200B/g, '').trim();
|
|
347
|
+
if (caption) {
|
|
348
|
+
imageBlocks.push({ text: caption, fontSize: 9, color: '#666666', margin: [0, 0, 0, 4] });
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return imageBlocks;
|
|
352
|
+
}
|
|
353
|
+
function convertSectionBodyToPdfBlocks(bodyEl, ctx) {
|
|
354
|
+
// Prefer the font explicitly set on the body element (applyDocumentBodyTextStyle sets it
|
|
355
|
+
// from pageSetup.textStyle.fontFamily). Fall back to ctx.bodyFont, then ctx.defaultFont.
|
|
356
|
+
const bodyFontFamily = bodyEl.style?.fontFamily;
|
|
357
|
+
const sectionFont = (bodyFontFamily ? ctx.resolveFontName(bodyFontFamily) : null)
|
|
358
|
+
?? ctx.bodyFont
|
|
359
|
+
?? ctx.defaultFont;
|
|
360
|
+
const blocks = [];
|
|
361
|
+
let proseBatch = [];
|
|
362
|
+
function flushProse() {
|
|
363
|
+
if (!proseBatch.length)
|
|
364
|
+
return;
|
|
365
|
+
const wrapper = bodyEl.ownerDocument.createElement('div');
|
|
366
|
+
for (const node of proseBatch) {
|
|
367
|
+
wrapper.appendChild(node.cloneNode(true));
|
|
368
|
+
}
|
|
369
|
+
blocks.push(...convertSerializedHtmlToPdfBlocks(serializePreviewBodyHtml(wrapper, ctx), { ...ctx, defaultFont: sectionFont }));
|
|
370
|
+
proseBatch = [];
|
|
371
|
+
}
|
|
372
|
+
for (const child of bodyEl.childNodes) {
|
|
373
|
+
if (child.nodeType === Node.ELEMENT_NODE) {
|
|
374
|
+
const childEl = child;
|
|
375
|
+
if (childEl.classList.contains('document-columns')) {
|
|
376
|
+
flushProse();
|
|
377
|
+
const columnBlock = convertColumnsBlock(childEl, ctx);
|
|
378
|
+
if (columnBlock)
|
|
379
|
+
blocks.push(columnBlock);
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
382
|
+
if (childEl.classList.contains('document-table') || childEl.matches('table.vision-table')) {
|
|
383
|
+
flushProse();
|
|
384
|
+
const tableBlock = convertVisionTableFromContainer(childEl, ctx);
|
|
385
|
+
if (tableBlock)
|
|
386
|
+
blocks.push(tableBlock);
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
const repeaterToken = findRepeaterTokenInElement(childEl);
|
|
390
|
+
if (repeaterToken) {
|
|
391
|
+
flushProse();
|
|
392
|
+
if (repeaterToken !== childEl) {
|
|
393
|
+
const preceding = bodyEl.ownerDocument.createDocumentFragment();
|
|
394
|
+
for (const node of childEl.childNodes) {
|
|
395
|
+
if (node === repeaterToken)
|
|
396
|
+
break;
|
|
397
|
+
if (node.nodeType === Node.ELEMENT_NODE && node.contains(repeaterToken))
|
|
398
|
+
break;
|
|
399
|
+
preceding.appendChild(node.cloneNode(true));
|
|
400
|
+
}
|
|
401
|
+
if (preceding.childNodes.length) {
|
|
402
|
+
const wrapper = bodyEl.ownerDocument.createElement('div');
|
|
403
|
+
wrapper.appendChild(preceding);
|
|
404
|
+
blocks.push(...convertSerializedHtmlToPdfBlocks(serializePreviewBodyHtml(wrapper, ctx), { ...ctx, defaultFont: sectionFont }));
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
blocks.push(...convertRepeaterTokenToPdfBlocks(repeaterToken, ctx));
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
// Handle image field tokens: emit as pdfmake image blocks.
|
|
411
|
+
if (ctx.imageMap) {
|
|
412
|
+
const hasImageToken = childEl.classList?.contains('field-token--image')
|
|
413
|
+
|| childEl.querySelector('.field-token--image') !== null;
|
|
414
|
+
if (hasImageToken) {
|
|
415
|
+
// Flush any accumulated prose before the image.
|
|
416
|
+
flushProse();
|
|
417
|
+
// Emit image block(s).
|
|
418
|
+
const imageBlocks = emitImageTokenBlocks(childEl, { imageMap: ctx.imageMap });
|
|
419
|
+
blocks.push(...imageBlocks);
|
|
420
|
+
// If the child also contains non-image text, emit it as prose.
|
|
421
|
+
const textClone = childEl.cloneNode(true);
|
|
422
|
+
for (const tok of textClone.querySelectorAll('.field-token--image')) {
|
|
423
|
+
tok.remove();
|
|
424
|
+
}
|
|
425
|
+
if (textClone.textContent?.replace(/\u200B/g, '').trim()) {
|
|
426
|
+
proseBatch.push(textClone);
|
|
427
|
+
flushProse();
|
|
428
|
+
}
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
proseBatch.push(child);
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
if (child.nodeType === Node.TEXT_NODE) {
|
|
436
|
+
const text = String(child.textContent ?? '').replace(/\u200B/g, '');
|
|
437
|
+
if (!text)
|
|
438
|
+
continue;
|
|
439
|
+
const span = bodyEl.ownerDocument.createElement('span');
|
|
440
|
+
span.textContent = text;
|
|
441
|
+
proseBatch.push(span);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
flushProse();
|
|
445
|
+
return blocks;
|
|
446
|
+
}
|
|
447
|
+
function convertColumnsBlock(columnsEl, ctx) {
|
|
448
|
+
const cols = columnsEl.querySelectorAll(':scope > .document-columns__grid > .document-columns__col, :scope > .document-columns__col');
|
|
449
|
+
const colEls = cols.length
|
|
450
|
+
? cols
|
|
451
|
+
: columnsEl.querySelectorAll('.document-columns__col');
|
|
452
|
+
if (!colEls.length)
|
|
453
|
+
return null;
|
|
454
|
+
const columns = [];
|
|
455
|
+
for (const col of colEls) {
|
|
456
|
+
columns.push({
|
|
457
|
+
width: '*',
|
|
458
|
+
stack: convertSectionBodyToPdfBlocks(col, ctx),
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
if (!columns.some((col) => Array.isArray(col.stack) && col.stack.length))
|
|
462
|
+
return null;
|
|
463
|
+
return { columns, columnGap: 12, margin: [0, 0, 0, 6] };
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Direct tbody rows of this table only (ignore nested vision-tables inside cells).
|
|
467
|
+
*/
|
|
468
|
+
function getOuterTableBodyRows(tableEl) {
|
|
469
|
+
const tbody = tableEl.querySelector(':scope > tbody');
|
|
470
|
+
if (!tbody)
|
|
471
|
+
return [];
|
|
472
|
+
return [...tbody.children].filter((el) => el.tagName === 'TR');
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Direct header cells of this table only.
|
|
476
|
+
*/
|
|
477
|
+
function getOuterTableHeaderCells(tableEl) {
|
|
478
|
+
const theadRow = tableEl.querySelector(':scope > thead > tr');
|
|
479
|
+
if (!theadRow)
|
|
480
|
+
return [];
|
|
481
|
+
return [...theadRow.children].filter((el) => el.tagName === 'TH' || el.tagName === 'TD');
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Direct data cells of a body row only (ignore nested tables inside Child cells).
|
|
485
|
+
*/
|
|
486
|
+
function getOuterTableRowCells(tr) {
|
|
487
|
+
return [...tr.children].filter((el) => el.tagName === 'TD');
|
|
488
|
+
}
|
|
489
|
+
function convertVisionTableCell(td, ctx) {
|
|
490
|
+
if (td.classList.contains('vision-table__row-actions')) {
|
|
491
|
+
return { text: '' };
|
|
492
|
+
}
|
|
493
|
+
const repeaterToken = findRepeaterTokenInElement(td);
|
|
494
|
+
if (repeaterToken) {
|
|
495
|
+
const nestedBlocks = convertRepeaterTokenToPdfBlocks(repeaterToken, ctx);
|
|
496
|
+
return {
|
|
497
|
+
stack: nestedBlocks.length ? nestedBlocks : [{ text: '' }],
|
|
498
|
+
style: 'tableBody',
|
|
499
|
+
lineHeight: TABLE_PDF_LINE_HEIGHT,
|
|
500
|
+
font: ctx.defaultFont,
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
const parts = [];
|
|
504
|
+
walkInlineNodes(td, [{}], ctx, parts);
|
|
505
|
+
const tokenAlign = td.querySelector('.field-token')?.style?.textAlign ?? '';
|
|
506
|
+
const cellAlign = (td.style?.textAlign || tokenAlign || '').trim().toLowerCase();
|
|
507
|
+
const cellBg = parseCssColor(td.style?.backgroundColor
|
|
508
|
+
|| domInlineStyleToPdf(td.getAttribute('style') ?? '', ctx.baseFontSize).background);
|
|
509
|
+
// Prefer full-cell fill; strip text-level background so padding looks filled.
|
|
510
|
+
const cleanedParts = cellBg
|
|
511
|
+
? parts.map((part) => {
|
|
512
|
+
if (!part || typeof part !== 'object')
|
|
513
|
+
return part;
|
|
514
|
+
const next = { ...part };
|
|
515
|
+
delete next.background;
|
|
516
|
+
return next;
|
|
517
|
+
})
|
|
518
|
+
: parts;
|
|
519
|
+
const cell = {
|
|
520
|
+
text: finalizePdfInlineParts(cleanedParts.length ? cleanedParts : [''], {
|
|
521
|
+
font: ctx.defaultFont,
|
|
522
|
+
inlineStyle: { lineHeight: TABLE_PDF_LINE_HEIGHT },
|
|
523
|
+
}),
|
|
524
|
+
style: 'tableBody',
|
|
525
|
+
lineHeight: TABLE_PDF_LINE_HEIGHT,
|
|
526
|
+
font: ctx.defaultFont,
|
|
527
|
+
};
|
|
528
|
+
if (['left', 'center', 'right', 'justify'].includes(cellAlign)) {
|
|
529
|
+
cell.alignment = cellAlign;
|
|
530
|
+
}
|
|
531
|
+
if (cellBg)
|
|
532
|
+
cell.fillColor = cellBg;
|
|
533
|
+
return cell;
|
|
534
|
+
}
|
|
535
|
+
function convertVisionTable(tableEl, ctx) {
|
|
536
|
+
const headerCells = getOuterTableHeaderCells(tableEl);
|
|
537
|
+
const bodyRows = getOuterTableBodyRows(tableEl);
|
|
538
|
+
if (!bodyRows.length)
|
|
539
|
+
return null;
|
|
540
|
+
const headerRow = [];
|
|
541
|
+
for (const th of headerCells) {
|
|
542
|
+
if (th.classList.contains('vision-table__actions-head'))
|
|
543
|
+
continue;
|
|
544
|
+
const text = String(th.textContent ?? '').trim();
|
|
545
|
+
headerRow.push({
|
|
546
|
+
text,
|
|
547
|
+
style: 'tableHeader',
|
|
548
|
+
lineHeight: TABLE_PDF_LINE_HEIGHT,
|
|
549
|
+
...elementStyleToPdf(th, ctx),
|
|
550
|
+
bold: true,
|
|
551
|
+
alignment: 'center',
|
|
552
|
+
font: ctx.defaultFont,
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
const body = [];
|
|
556
|
+
for (const tr of bodyRows) {
|
|
557
|
+
const row = [];
|
|
558
|
+
for (const td of getOuterTableRowCells(tr)) {
|
|
559
|
+
if (td.classList.contains('vision-table__row-actions'))
|
|
560
|
+
continue;
|
|
561
|
+
row.push(convertVisionTableCell(td, ctx));
|
|
562
|
+
}
|
|
563
|
+
if (row.length)
|
|
564
|
+
body.push(row);
|
|
565
|
+
}
|
|
566
|
+
if (!body.length)
|
|
567
|
+
return null;
|
|
568
|
+
const hideHeader = headerRow.length === 0 || tableEl.classList.contains('vision-table--no-header');
|
|
569
|
+
const colCount = hideHeader ? (body[0]?.length ?? 0) : headerRow.length;
|
|
570
|
+
if (!colCount)
|
|
571
|
+
return null;
|
|
572
|
+
const colEls = tableEl.querySelectorAll(':scope > colgroup > col');
|
|
573
|
+
const widths = colEls.length >= colCount
|
|
574
|
+
? tableColumnWidthsFromColElements([...colEls].slice(0, colCount))
|
|
575
|
+
: Array.from({ length: colCount }, () => '*');
|
|
576
|
+
const pdfBody = hideHeader ? body : [headerRow, ...body];
|
|
577
|
+
return {
|
|
578
|
+
table: {
|
|
579
|
+
headerRows: hideHeader ? 0 : 1,
|
|
580
|
+
keepWithHeaderRows: hideHeader ? 0 : 1,
|
|
581
|
+
widths,
|
|
582
|
+
body: pdfBody,
|
|
583
|
+
dontBreakRows: true,
|
|
584
|
+
},
|
|
585
|
+
layout: resolveVisionTablePdfLayout({
|
|
586
|
+
hideBorders: tableEl.classList.contains('vision-table--borderless'),
|
|
587
|
+
}),
|
|
588
|
+
margin: [0, 0, 0, 8],
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
function convertSectionWrap(sectionWrap, ctx) {
|
|
592
|
+
const stack = [];
|
|
593
|
+
const borderTop = sectionWrap.classList?.contains('document-section--border-top') === true;
|
|
594
|
+
const borderBottom = sectionWrap.classList?.contains('document-section--border-bottom') === true;
|
|
595
|
+
if (borderTop) {
|
|
596
|
+
stack.push(buildPdfSectionBorderRuleBlock('top', ctx.contentWidthPt));
|
|
597
|
+
}
|
|
598
|
+
const labelEl = sectionWrap.querySelector('.document-section__header .document-section__label-text');
|
|
599
|
+
const label = String(labelEl?.textContent ?? '').trim();
|
|
600
|
+
if (label) {
|
|
601
|
+
stack.push({
|
|
602
|
+
text: label,
|
|
603
|
+
style: 'sectionHeader',
|
|
604
|
+
bold: true,
|
|
605
|
+
font: ctx.defaultFont,
|
|
606
|
+
...(ctx.sectionHeaderStyle ?? {}),
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
const bodyEl = sectionWrap.querySelector('.preview-document__section');
|
|
610
|
+
if (bodyEl) {
|
|
611
|
+
stack.push(...convertSectionBodyToPdfBlocks(bodyEl, ctx));
|
|
612
|
+
}
|
|
613
|
+
if (borderBottom) {
|
|
614
|
+
stack.push(buildPdfSectionBorderRuleBlock('bottom', ctx.contentWidthPt));
|
|
615
|
+
}
|
|
616
|
+
if (!stack.length)
|
|
617
|
+
return null;
|
|
618
|
+
return { stack, margin: [0, 0, 0, 8] };
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* Tables inside repeatable ("show on each page") sections are rendered in the PDF
|
|
622
|
+
* body; prose/header fields are handled by the repeatable page header instead.
|
|
623
|
+
*/
|
|
624
|
+
function convertRepeatableSectionTables(sectionWrap, ctx) {
|
|
625
|
+
const bodyEl = sectionWrap.querySelector('.preview-document__section');
|
|
626
|
+
if (!bodyEl)
|
|
627
|
+
return [];
|
|
628
|
+
const blocks = [];
|
|
629
|
+
for (const tableWrap of bodyEl.querySelectorAll('.document-table')) {
|
|
630
|
+
const block = convertVisionTableFromContainer(tableWrap, ctx);
|
|
631
|
+
if (block)
|
|
632
|
+
blocks.push(block);
|
|
633
|
+
}
|
|
634
|
+
for (const tableEl of bodyEl.querySelectorAll(':scope > table.vision-table')) {
|
|
635
|
+
const block = convertVisionTable(tableEl, ctx);
|
|
636
|
+
if (block)
|
|
637
|
+
blocks.push(block);
|
|
638
|
+
}
|
|
639
|
+
return blocks;
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Convert a Simple preview root element to pdfmake content blocks.
|
|
643
|
+
*/
|
|
644
|
+
export function previewDomToPdfContent(previewRoot, renderCtx) {
|
|
645
|
+
const content = [];
|
|
646
|
+
const ctx = {
|
|
647
|
+
...renderCtx,
|
|
648
|
+
baseFontSize: Number(renderCtx.baseFontSize) || DEFAULT_BODY_FONT_PT,
|
|
649
|
+
hideEmptyInPreview: previewRoot.classList?.contains('preview-document--hide-empty') === true,
|
|
650
|
+
};
|
|
651
|
+
for (const child of previewRoot.children) {
|
|
652
|
+
if (child.classList.contains('preview-document__section-wrap')) {
|
|
653
|
+
if (child.dataset?.repeatable === 'true') {
|
|
654
|
+
content.push(...convertRepeatableSectionTables(child, ctx));
|
|
655
|
+
continue;
|
|
656
|
+
}
|
|
657
|
+
const block = convertSectionWrap(child, ctx);
|
|
658
|
+
if (block)
|
|
659
|
+
content.push(block);
|
|
660
|
+
continue;
|
|
661
|
+
}
|
|
662
|
+
if (child.classList.contains('preview-document__block')) {
|
|
663
|
+
const table = child.querySelector('table.vision-table');
|
|
664
|
+
if (table) {
|
|
665
|
+
const block = convertVisionTable(table, ctx);
|
|
666
|
+
if (block)
|
|
667
|
+
content.push(block);
|
|
668
|
+
}
|
|
669
|
+
else {
|
|
670
|
+
const blockContent = convertSectionBodyToPdfBlocks(child, ctx);
|
|
671
|
+
if (blockContent.length)
|
|
672
|
+
content.push(...blockContent);
|
|
673
|
+
}
|
|
674
|
+
continue;
|
|
675
|
+
}
|
|
676
|
+
if (child.classList.contains('preview-document__title')) {
|
|
677
|
+
content.push({
|
|
678
|
+
text: String(child.textContent ?? '').trim(),
|
|
679
|
+
style: 'documentTitle',
|
|
680
|
+
margin: [0, 0, 0, 10],
|
|
681
|
+
font: ctx.defaultFont,
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
if (!content.length) {
|
|
686
|
+
const emptyEl = previewRoot.querySelector('.preview-document__empty');
|
|
687
|
+
content.push({
|
|
688
|
+
text: String(emptyEl?.textContent ?? 'No filled content to export.'),
|
|
689
|
+
style: 'empty',
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
return content;
|
|
693
|
+
}
|
|
694
|
+
//# sourceMappingURL=preview-dom-to-pdf.js.map
|