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