pdfmake 0.3.2 → 0.3.4
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/CHANGELOG.md +18 -0
- package/LICENSE +21 -21
- package/README.md +75 -78
- package/build/fonts/Roboto/Roboto-Italic.ttf +0 -0
- package/build/fonts/Roboto/Roboto-Medium.ttf +0 -0
- package/build/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
- package/build/fonts/Roboto/Roboto-Regular.ttf +0 -0
- package/build/fonts/Roboto.js +27 -0
- package/build/pdfmake.js +64813 -64584
- package/build/pdfmake.js.map +1 -1
- package/build/pdfmake.min.js +2 -2
- package/build/pdfmake.min.js.map +1 -1
- package/build/standard-fonts/Courier.js +27 -27
- package/build/standard-fonts/Helvetica.js +27 -27
- package/build/standard-fonts/Symbol.js +21 -21
- package/build/standard-fonts/Times.js +27 -27
- package/build/standard-fonts/ZapfDingbats.js +21 -21
- package/build/vfs_fonts.js +5 -5
- package/build-vfs.js +44 -44
- package/fonts/Roboto.js +8 -8
- package/js/3rd-party/svg-to-pdfkit/source.js +1 -1
- package/js/DocMeasure.js +11 -6
- package/js/DocumentContext.js +8 -3
- package/js/ElementWriter.js +42 -16
- package/js/LayoutBuilder.js +144 -78
- package/js/Line.js +16 -16
- package/js/OutputDocument.js +10 -10
- package/js/OutputDocumentServer.js +3 -3
- package/js/PDFDocument.js +3 -3
- package/js/PageElementWriter.js +15 -9
- package/js/Printer.js +28 -28
- package/js/Renderer.js +40 -8
- package/js/SVGMeasure.js +10 -10
- package/js/StyleContextStack.js +74 -51
- package/js/TableProcessor.js +14 -0
- package/js/TextBreaker.js +17 -17
- package/js/TextDecorator.js +12 -3
- package/js/TextInlines.js +34 -33
- package/js/base.js +4 -4
- package/js/browser-extensions/OutputDocumentBrowser.js +24 -24
- package/js/columnCalculator.js +2 -2
- package/js/helpers/node.js +47 -23
- package/js/helpers/variableType.js +18 -18
- package/js/qrEnc.js +38 -38
- package/js/virtual-fs.js +11 -11
- package/package.json +12 -12
- package/src/3rd-party/svg-to-pdfkit/LICENSE +9 -9
- package/src/3rd-party/svg-to-pdfkit/source.js +2745 -2745
- package/src/3rd-party/svg-to-pdfkit.js +3 -3
- package/src/DocMeasure.js +745 -738
- package/src/DocPreprocessor.js +283 -283
- package/src/DocumentContext.js +345 -338
- package/src/ElementWriter.js +441 -417
- package/src/LayoutBuilder.js +1336 -1258
- package/src/Line.js +114 -114
- package/src/OutputDocument.js +64 -64
- package/src/OutputDocumentServer.js +32 -32
- package/src/PDFDocument.js +174 -174
- package/src/PageElementWriter.js +187 -179
- package/src/PageSize.js +53 -53
- package/src/Printer.js +306 -306
- package/src/Renderer.js +445 -409
- package/src/SVGMeasure.js +109 -109
- package/src/StyleContextStack.js +208 -179
- package/src/TableProcessor.js +620 -602
- package/src/TextBreaker.js +168 -168
- package/src/TextDecorator.js +175 -161
- package/src/TextInlines.js +224 -223
- package/src/URLResolver.js +43 -43
- package/src/base.js +70 -70
- package/src/browser-extensions/OutputDocumentBrowser.js +80 -80
- package/src/browser-extensions/fonts/Roboto.js +27 -27
- package/src/browser-extensions/index.js +55 -55
- package/src/browser-extensions/pdfMake.js +1 -1
- package/src/browser-extensions/standard-fonts/Courier.js +27 -27
- package/src/browser-extensions/standard-fonts/Helvetica.js +27 -27
- package/src/browser-extensions/standard-fonts/Symbol.js +21 -21
- package/src/browser-extensions/standard-fonts/Times.js +27 -27
- package/src/browser-extensions/standard-fonts/ZapfDingbats.js +21 -21
- package/src/browser-extensions/virtual-fs-cjs.js +1 -1
- package/src/columnCalculator.js +154 -154
- package/src/helpers/node.js +134 -110
- package/src/helpers/tools.js +44 -44
- package/src/helpers/variableType.js +50 -50
- package/src/index.js +16 -16
- package/src/qrEnc.js +796 -796
- package/src/standardPageSizes.js +52 -52
- package/src/tableLayouts.js +100 -100
- package/src/virtual-fs.js +66 -66
- package/standard-fonts/Courier.js +8 -8
- package/standard-fonts/Helvetica.js +8 -8
- package/standard-fonts/Symbol.js +5 -5
- package/standard-fonts/Times.js +8 -8
- package/standard-fonts/ZapfDingbats.js +5 -5
package/src/DocPreprocessor.js
CHANGED
|
@@ -1,283 +1,283 @@
|
|
|
1
|
-
import { isString, isNumber, isValue, isEmptyObject } from './helpers/variableType';
|
|
2
|
-
import { stringifyNode } from './helpers/node';
|
|
3
|
-
|
|
4
|
-
const convertValueToString = value => {
|
|
5
|
-
if (isString(value)) {
|
|
6
|
-
return value.replace(/\t/g, ' '); // expand tab as spaces
|
|
7
|
-
} else if (isNumber(value) || typeof value === 'boolean') {
|
|
8
|
-
return value.toString();
|
|
9
|
-
} else if (!isValue(value) || isEmptyObject(value)) {
|
|
10
|
-
return '';
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// TODO: throw exception ?
|
|
14
|
-
|
|
15
|
-
return value;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
class DocPreprocessor {
|
|
19
|
-
preprocessDocument(docStructure) {
|
|
20
|
-
this.parentNode = null;
|
|
21
|
-
this.tocs = [];
|
|
22
|
-
this.nodeReferences = [];
|
|
23
|
-
return this.preprocessNode(docStructure, true);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
preprocessBlock(node) {
|
|
27
|
-
this.parentNode = null;
|
|
28
|
-
this.tocs = [];
|
|
29
|
-
this.nodeReferences = [];
|
|
30
|
-
return this.preprocessNode(node);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
preprocessNode(node, isSectionAllowed = false) {
|
|
34
|
-
// expand shortcuts and casting values
|
|
35
|
-
if (Array.isArray(node)) {
|
|
36
|
-
node = { stack: node };
|
|
37
|
-
} else if (isString(node) || isNumber(node) || typeof node === 'boolean' || !isValue(node) || isEmptyObject(node)) { // text node defined as value
|
|
38
|
-
node = { text: convertValueToString(node) };
|
|
39
|
-
} else if ('text' in node) { // cast value in text property
|
|
40
|
-
node.text = convertValueToString(node.text);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (node.section) {
|
|
44
|
-
if (!isSectionAllowed) {
|
|
45
|
-
throw new Error(`Incorrect document structure, section node is only allowed at the root level of document structure: ${stringifyNode(node)}`);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return this.preprocessSection(node);
|
|
49
|
-
} else if (node.columns) {
|
|
50
|
-
return this.preprocessColumns(node);
|
|
51
|
-
} else if (node.stack) {
|
|
52
|
-
return this.preprocessVerticalContainer(node, isSectionAllowed);
|
|
53
|
-
} else if (node.ul) {
|
|
54
|
-
return this.preprocessList(node);
|
|
55
|
-
} else if (node.ol) {
|
|
56
|
-
return this.preprocessList(node);
|
|
57
|
-
} else if (node.table) {
|
|
58
|
-
return this.preprocessTable(node);
|
|
59
|
-
} else if (node.text !== undefined) {
|
|
60
|
-
return this.preprocessText(node);
|
|
61
|
-
} else if (node.toc) {
|
|
62
|
-
return this.preprocessToc(node);
|
|
63
|
-
} else if (node.image) {
|
|
64
|
-
return this.preprocessImage(node);
|
|
65
|
-
} else if (node.svg) {
|
|
66
|
-
return this.preprocessSVG(node);
|
|
67
|
-
} else if (node.canvas) {
|
|
68
|
-
return this.preprocessCanvas(node);
|
|
69
|
-
} else if (node.qr) {
|
|
70
|
-
return this.preprocessQr(node);
|
|
71
|
-
} else if (node.attachment) {
|
|
72
|
-
return this.preprocessAttachment(node);
|
|
73
|
-
} else if (node.pageReference || node.textReference) {
|
|
74
|
-
return this.preprocessText(node);
|
|
75
|
-
} else {
|
|
76
|
-
throw new Error(`Unrecognized document structure: ${stringifyNode(node)}`);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
preprocessSection(node) {
|
|
81
|
-
node.section = this.preprocessNode(node.section);
|
|
82
|
-
|
|
83
|
-
return node;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
preprocessColumns(node) {
|
|
87
|
-
let columns = node.columns;
|
|
88
|
-
|
|
89
|
-
for (let i = 0, l = columns.length; i < l; i++) {
|
|
90
|
-
columns[i] = this.preprocessNode(columns[i]);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return node;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
preprocessVerticalContainer(node, isSectionAllowed) {
|
|
97
|
-
let items = node.stack;
|
|
98
|
-
|
|
99
|
-
for (let i = 0, l = items.length; i < l; i++) {
|
|
100
|
-
items[i] = this.preprocessNode(items[i], isSectionAllowed);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return node;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
preprocessList(node) {
|
|
107
|
-
let items = node.ul || node.ol;
|
|
108
|
-
|
|
109
|
-
for (let i = 0, l = items.length; i < l; i++) {
|
|
110
|
-
items[i] = this.preprocessNode(items[i]);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return node;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
preprocessTable(node) {
|
|
117
|
-
let col;
|
|
118
|
-
let row;
|
|
119
|
-
let cols;
|
|
120
|
-
let rows;
|
|
121
|
-
|
|
122
|
-
for (col = 0, cols = node.table.body[0].length; col < cols; col++) {
|
|
123
|
-
for (row = 0, rows = node.table.body.length; row < rows; row++) {
|
|
124
|
-
let rowData = node.table.body[row];
|
|
125
|
-
let data = rowData[col];
|
|
126
|
-
if (data !== undefined) {
|
|
127
|
-
if (data === null) { // transform to object
|
|
128
|
-
data = '';
|
|
129
|
-
}
|
|
130
|
-
if (!data._span) {
|
|
131
|
-
rowData[col] = this.preprocessNode(data);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return node;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
preprocessText(node) {
|
|
141
|
-
if (node.tocItem) {
|
|
142
|
-
if (!Array.isArray(node.tocItem)) {
|
|
143
|
-
node.tocItem = [node.tocItem];
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
for (let i = 0, l = node.tocItem.length; i < l; i++) {
|
|
147
|
-
if (!isString(node.tocItem[i])) {
|
|
148
|
-
node.tocItem[i] = '_default_';
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
let tocItemId = node.tocItem[i];
|
|
152
|
-
|
|
153
|
-
if (!this.tocs[tocItemId]) {
|
|
154
|
-
this.tocs[tocItemId] = { toc: { _items: [], _pseudo: true } };
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (!node.id) {
|
|
158
|
-
node.id = `toc-${tocItemId}-${this.tocs[tocItemId].toc._items.length}`;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
let tocItemRef = {
|
|
162
|
-
_nodeRef: this._getNodeForNodeRef(node),
|
|
163
|
-
_textNodeRef: node
|
|
164
|
-
};
|
|
165
|
-
this.tocs[tocItemId].toc._items.push(tocItemRef);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
if (node.id) {
|
|
170
|
-
if (this.nodeReferences[node.id]) {
|
|
171
|
-
if (!this.nodeReferences[node.id]._pseudo) {
|
|
172
|
-
throw new Error(`Node id '${node.id}' already exists`);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
this.nodeReferences[node.id]._nodeRef = this._getNodeForNodeRef(node);
|
|
176
|
-
this.nodeReferences[node.id]._textNodeRef = node;
|
|
177
|
-
this.nodeReferences[node.id]._pseudo = false;
|
|
178
|
-
} else {
|
|
179
|
-
this.nodeReferences[node.id] = {
|
|
180
|
-
_nodeRef: this._getNodeForNodeRef(node),
|
|
181
|
-
_textNodeRef: node
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (node.pageReference) {
|
|
187
|
-
if (!this.nodeReferences[node.pageReference]) {
|
|
188
|
-
this.nodeReferences[node.pageReference] = {
|
|
189
|
-
_nodeRef: {},
|
|
190
|
-
_textNodeRef: {},
|
|
191
|
-
_pseudo: true
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
node.text = '00000';
|
|
195
|
-
node.linkToDestination = node.pageReference;
|
|
196
|
-
node._pageRef = this.nodeReferences[node.pageReference];
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
if (node.textReference) {
|
|
200
|
-
if (!this.nodeReferences[node.textReference]) {
|
|
201
|
-
this.nodeReferences[node.textReference] = { _nodeRef: {}, _pseudo: true };
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
node.text = '';
|
|
205
|
-
node.linkToDestination = node.textReference;
|
|
206
|
-
node._textRef = this.nodeReferences[node.textReference];
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
if (node.text && node.text.text) {
|
|
210
|
-
node.text = [this.preprocessNode(node.text)];
|
|
211
|
-
} else if (Array.isArray(node.text)) {
|
|
212
|
-
let isSetParentNode = false;
|
|
213
|
-
if (this.parentNode === null) {
|
|
214
|
-
this.parentNode = node;
|
|
215
|
-
isSetParentNode = true;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
for (let i = 0, l = node.text.length; i < l; i++) {
|
|
219
|
-
node.text[i] = this.preprocessNode(node.text[i]);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (isSetParentNode) {
|
|
223
|
-
this.parentNode = null;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
return node;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
preprocessToc(node) {
|
|
231
|
-
if (!node.toc.id) {
|
|
232
|
-
node.toc.id = '_default_';
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
node.toc.title = node.toc.title ? this.preprocessNode(node.toc.title) : null;
|
|
236
|
-
node.toc._items = [];
|
|
237
|
-
|
|
238
|
-
if (this.tocs[node.toc.id]) {
|
|
239
|
-
if (!this.tocs[node.toc.id].toc._pseudo) {
|
|
240
|
-
throw new Error(`TOC '${node.toc.id}' already exists`);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
node.toc._items = this.tocs[node.toc.id].toc._items;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
this.tocs[node.toc.id] = node;
|
|
247
|
-
|
|
248
|
-
return node;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
preprocessImage(node) {
|
|
252
|
-
if ((node.image.type !== undefined) && (node.image.data !== undefined) && (node.image.type === 'Buffer') && Array.isArray(node.image.data)) {
|
|
253
|
-
node.image = Buffer.from(node.image.data);
|
|
254
|
-
}
|
|
255
|
-
return node;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
preprocessCanvas(node) {
|
|
259
|
-
return node;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
preprocessSVG(node) {
|
|
263
|
-
return node;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
preprocessQr(node) {
|
|
267
|
-
return node;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
preprocessAttachment(node) {
|
|
271
|
-
return node;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
_getNodeForNodeRef(node) {
|
|
275
|
-
if (this.parentNode) {
|
|
276
|
-
return this.parentNode;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
return node;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
export default DocPreprocessor;
|
|
1
|
+
import { isString, isNumber, isValue, isEmptyObject } from './helpers/variableType';
|
|
2
|
+
import { stringifyNode } from './helpers/node';
|
|
3
|
+
|
|
4
|
+
const convertValueToString = value => {
|
|
5
|
+
if (isString(value)) {
|
|
6
|
+
return value.replace(/\t/g, ' '); // expand tab as spaces
|
|
7
|
+
} else if (isNumber(value) || typeof value === 'boolean') {
|
|
8
|
+
return value.toString();
|
|
9
|
+
} else if (!isValue(value) || isEmptyObject(value)) {
|
|
10
|
+
return '';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// TODO: throw exception ?
|
|
14
|
+
|
|
15
|
+
return value;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
class DocPreprocessor {
|
|
19
|
+
preprocessDocument(docStructure) {
|
|
20
|
+
this.parentNode = null;
|
|
21
|
+
this.tocs = [];
|
|
22
|
+
this.nodeReferences = [];
|
|
23
|
+
return this.preprocessNode(docStructure, true);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
preprocessBlock(node) {
|
|
27
|
+
this.parentNode = null;
|
|
28
|
+
this.tocs = [];
|
|
29
|
+
this.nodeReferences = [];
|
|
30
|
+
return this.preprocessNode(node);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
preprocessNode(node, isSectionAllowed = false) {
|
|
34
|
+
// expand shortcuts and casting values
|
|
35
|
+
if (Array.isArray(node)) {
|
|
36
|
+
node = { stack: node };
|
|
37
|
+
} else if (isString(node) || isNumber(node) || typeof node === 'boolean' || !isValue(node) || isEmptyObject(node)) { // text node defined as value
|
|
38
|
+
node = { text: convertValueToString(node) };
|
|
39
|
+
} else if ('text' in node) { // cast value in text property
|
|
40
|
+
node.text = convertValueToString(node.text);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (node.section) {
|
|
44
|
+
if (!isSectionAllowed) {
|
|
45
|
+
throw new Error(`Incorrect document structure, section node is only allowed at the root level of document structure: ${stringifyNode(node)}`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return this.preprocessSection(node);
|
|
49
|
+
} else if (node.columns) {
|
|
50
|
+
return this.preprocessColumns(node);
|
|
51
|
+
} else if (node.stack) {
|
|
52
|
+
return this.preprocessVerticalContainer(node, isSectionAllowed);
|
|
53
|
+
} else if (node.ul) {
|
|
54
|
+
return this.preprocessList(node);
|
|
55
|
+
} else if (node.ol) {
|
|
56
|
+
return this.preprocessList(node);
|
|
57
|
+
} else if (node.table) {
|
|
58
|
+
return this.preprocessTable(node);
|
|
59
|
+
} else if (node.text !== undefined) {
|
|
60
|
+
return this.preprocessText(node);
|
|
61
|
+
} else if (node.toc) {
|
|
62
|
+
return this.preprocessToc(node);
|
|
63
|
+
} else if (node.image) {
|
|
64
|
+
return this.preprocessImage(node);
|
|
65
|
+
} else if (node.svg) {
|
|
66
|
+
return this.preprocessSVG(node);
|
|
67
|
+
} else if (node.canvas) {
|
|
68
|
+
return this.preprocessCanvas(node);
|
|
69
|
+
} else if (node.qr) {
|
|
70
|
+
return this.preprocessQr(node);
|
|
71
|
+
} else if (node.attachment) {
|
|
72
|
+
return this.preprocessAttachment(node);
|
|
73
|
+
} else if (node.pageReference || node.textReference) {
|
|
74
|
+
return this.preprocessText(node);
|
|
75
|
+
} else {
|
|
76
|
+
throw new Error(`Unrecognized document structure: ${stringifyNode(node)}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
preprocessSection(node) {
|
|
81
|
+
node.section = this.preprocessNode(node.section);
|
|
82
|
+
|
|
83
|
+
return node;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
preprocessColumns(node) {
|
|
87
|
+
let columns = node.columns;
|
|
88
|
+
|
|
89
|
+
for (let i = 0, l = columns.length; i < l; i++) {
|
|
90
|
+
columns[i] = this.preprocessNode(columns[i]);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return node;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
preprocessVerticalContainer(node, isSectionAllowed) {
|
|
97
|
+
let items = node.stack;
|
|
98
|
+
|
|
99
|
+
for (let i = 0, l = items.length; i < l; i++) {
|
|
100
|
+
items[i] = this.preprocessNode(items[i], isSectionAllowed);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return node;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
preprocessList(node) {
|
|
107
|
+
let items = node.ul || node.ol;
|
|
108
|
+
|
|
109
|
+
for (let i = 0, l = items.length; i < l; i++) {
|
|
110
|
+
items[i] = this.preprocessNode(items[i]);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return node;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
preprocessTable(node) {
|
|
117
|
+
let col;
|
|
118
|
+
let row;
|
|
119
|
+
let cols;
|
|
120
|
+
let rows;
|
|
121
|
+
|
|
122
|
+
for (col = 0, cols = node.table.body[0].length; col < cols; col++) {
|
|
123
|
+
for (row = 0, rows = node.table.body.length; row < rows; row++) {
|
|
124
|
+
let rowData = node.table.body[row];
|
|
125
|
+
let data = rowData[col];
|
|
126
|
+
if (data !== undefined) {
|
|
127
|
+
if (data === null) { // transform to object
|
|
128
|
+
data = '';
|
|
129
|
+
}
|
|
130
|
+
if (!data._span) {
|
|
131
|
+
rowData[col] = this.preprocessNode(data);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return node;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
preprocessText(node) {
|
|
141
|
+
if (node.tocItem) {
|
|
142
|
+
if (!Array.isArray(node.tocItem)) {
|
|
143
|
+
node.tocItem = [node.tocItem];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
for (let i = 0, l = node.tocItem.length; i < l; i++) {
|
|
147
|
+
if (!isString(node.tocItem[i])) {
|
|
148
|
+
node.tocItem[i] = '_default_';
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
let tocItemId = node.tocItem[i];
|
|
152
|
+
|
|
153
|
+
if (!this.tocs[tocItemId]) {
|
|
154
|
+
this.tocs[tocItemId] = { toc: { _items: [], _pseudo: true } };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (!node.id) {
|
|
158
|
+
node.id = `toc-${tocItemId}-${this.tocs[tocItemId].toc._items.length}`;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
let tocItemRef = {
|
|
162
|
+
_nodeRef: this._getNodeForNodeRef(node),
|
|
163
|
+
_textNodeRef: node
|
|
164
|
+
};
|
|
165
|
+
this.tocs[tocItemId].toc._items.push(tocItemRef);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (node.id) {
|
|
170
|
+
if (this.nodeReferences[node.id]) {
|
|
171
|
+
if (!this.nodeReferences[node.id]._pseudo) {
|
|
172
|
+
throw new Error(`Node id '${node.id}' already exists`);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
this.nodeReferences[node.id]._nodeRef = this._getNodeForNodeRef(node);
|
|
176
|
+
this.nodeReferences[node.id]._textNodeRef = node;
|
|
177
|
+
this.nodeReferences[node.id]._pseudo = false;
|
|
178
|
+
} else {
|
|
179
|
+
this.nodeReferences[node.id] = {
|
|
180
|
+
_nodeRef: this._getNodeForNodeRef(node),
|
|
181
|
+
_textNodeRef: node
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (node.pageReference) {
|
|
187
|
+
if (!this.nodeReferences[node.pageReference]) {
|
|
188
|
+
this.nodeReferences[node.pageReference] = {
|
|
189
|
+
_nodeRef: {},
|
|
190
|
+
_textNodeRef: {},
|
|
191
|
+
_pseudo: true
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
node.text = '00000';
|
|
195
|
+
node.linkToDestination = node.pageReference;
|
|
196
|
+
node._pageRef = this.nodeReferences[node.pageReference];
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (node.textReference) {
|
|
200
|
+
if (!this.nodeReferences[node.textReference]) {
|
|
201
|
+
this.nodeReferences[node.textReference] = { _nodeRef: {}, _pseudo: true };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
node.text = '';
|
|
205
|
+
node.linkToDestination = node.textReference;
|
|
206
|
+
node._textRef = this.nodeReferences[node.textReference];
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (node.text && node.text.text) {
|
|
210
|
+
node.text = [this.preprocessNode(node.text)];
|
|
211
|
+
} else if (Array.isArray(node.text)) {
|
|
212
|
+
let isSetParentNode = false;
|
|
213
|
+
if (this.parentNode === null) {
|
|
214
|
+
this.parentNode = node;
|
|
215
|
+
isSetParentNode = true;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
for (let i = 0, l = node.text.length; i < l; i++) {
|
|
219
|
+
node.text[i] = this.preprocessNode(node.text[i]);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (isSetParentNode) {
|
|
223
|
+
this.parentNode = null;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return node;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
preprocessToc(node) {
|
|
231
|
+
if (!node.toc.id) {
|
|
232
|
+
node.toc.id = '_default_';
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
node.toc.title = node.toc.title ? this.preprocessNode(node.toc.title) : null;
|
|
236
|
+
node.toc._items = [];
|
|
237
|
+
|
|
238
|
+
if (this.tocs[node.toc.id]) {
|
|
239
|
+
if (!this.tocs[node.toc.id].toc._pseudo) {
|
|
240
|
+
throw new Error(`TOC '${node.toc.id}' already exists`);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
node.toc._items = this.tocs[node.toc.id].toc._items;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
this.tocs[node.toc.id] = node;
|
|
247
|
+
|
|
248
|
+
return node;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
preprocessImage(node) {
|
|
252
|
+
if ((node.image.type !== undefined) && (node.image.data !== undefined) && (node.image.type === 'Buffer') && Array.isArray(node.image.data)) {
|
|
253
|
+
node.image = Buffer.from(node.image.data);
|
|
254
|
+
}
|
|
255
|
+
return node;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
preprocessCanvas(node) {
|
|
259
|
+
return node;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
preprocessSVG(node) {
|
|
263
|
+
return node;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
preprocessQr(node) {
|
|
267
|
+
return node;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
preprocessAttachment(node) {
|
|
271
|
+
return node;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
_getNodeForNodeRef(node) {
|
|
275
|
+
if (this.parentNode) {
|
|
276
|
+
return this.parentNode;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return node;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export default DocPreprocessor;
|