pdfmake 0.3.0-beta.7 → 0.3.0-beta.8
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 +4 -0
- package/build/pdfmake.js +2654 -2525
- package/build/pdfmake.js.map +1 -1
- package/build/pdfmake.min.js +2 -2
- package/build/pdfmake.min.js.map +1 -1
- package/package.json +1 -1
- package/js/3rd-party/svg-to-pdfkit/source.js +0 -3626
- package/js/3rd-party/svg-to-pdfkit.js +0 -7
- package/js/DocMeasure.js +0 -627
- package/js/DocPreprocessor.js +0 -238
- package/js/DocumentContext.js +0 -265
- package/js/ElementWriter.js +0 -331
- package/js/LayoutBuilder.js +0 -694
- package/js/Line.js +0 -105
- package/js/OutputDocument.js +0 -76
- package/js/OutputDocumentServer.js +0 -27
- package/js/PDFDocument.js +0 -144
- package/js/PageElementWriter.js +0 -140
- package/js/PageSize.js +0 -74
- package/js/Printer.js +0 -291
- package/js/Renderer.js +0 -375
- package/js/SVGMeasure.js +0 -69
- package/js/StyleContextStack.js +0 -180
- package/js/TableProcessor.js +0 -511
- package/js/TextBreaker.js +0 -139
- package/js/TextDecorator.js +0 -143
- package/js/TextInlines.js +0 -206
- package/js/URLResolver.js +0 -73
- package/js/base.js +0 -52
- package/js/browser-extensions/OutputDocumentBrowser.js +0 -118
- package/js/browser-extensions/URLBrowserResolver.js +0 -76
- package/js/browser-extensions/fonts/Roboto.js +0 -38
- package/js/browser-extensions/index.js +0 -53
- package/js/browser-extensions/pdfMake.js +0 -15
- package/js/browser-extensions/standard-fonts/Courier.js +0 -38
- package/js/browser-extensions/standard-fonts/Helvetica.js +0 -38
- package/js/browser-extensions/standard-fonts/Symbol.js +0 -23
- package/js/browser-extensions/standard-fonts/Times.js +0 -38
- package/js/browser-extensions/standard-fonts/ZapfDingbats.js +0 -23
- package/js/browser-extensions/virtual-fs-cjs.js +0 -3
- package/js/columnCalculator.js +0 -129
- package/js/helpers/node.js +0 -98
- package/js/helpers/tools.js +0 -40
- package/js/helpers/variableType.js +0 -47
- package/js/index.js +0 -15
- package/js/qrEnc.js +0 -721
- package/js/standardPageSizes.js +0 -56
- package/js/tableLayouts.js +0 -98
- package/js/virtual-fs.js +0 -60
package/js/DocPreprocessor.js
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
exports.default = void 0;
|
|
5
|
-
var _variableType = require("./helpers/variableType");
|
|
6
|
-
var _node = require("./helpers/node");
|
|
7
|
-
const convertValueToString = value => {
|
|
8
|
-
if ((0, _variableType.isString)(value)) {
|
|
9
|
-
return value.replace(/\t/g, ' '); // expand tab as spaces
|
|
10
|
-
} else if ((0, _variableType.isNumber)(value) || typeof value === 'boolean') {
|
|
11
|
-
return value.toString();
|
|
12
|
-
} else if (!(0, _variableType.isValue)(value) || (0, _variableType.isEmptyObject)(value)) {
|
|
13
|
-
return '';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// TODO: throw exception ?
|
|
17
|
-
|
|
18
|
-
return value;
|
|
19
|
-
};
|
|
20
|
-
class DocPreprocessor {
|
|
21
|
-
preprocessDocument(docStructure) {
|
|
22
|
-
this.parentNode = null;
|
|
23
|
-
this.tocs = [];
|
|
24
|
-
this.nodeReferences = [];
|
|
25
|
-
return this.preprocessNode(docStructure);
|
|
26
|
-
}
|
|
27
|
-
preprocessNode(node) {
|
|
28
|
-
// expand shortcuts and casting values
|
|
29
|
-
if (Array.isArray(node)) {
|
|
30
|
-
node = {
|
|
31
|
-
stack: node
|
|
32
|
-
};
|
|
33
|
-
} else if ((0, _variableType.isString)(node) || (0, _variableType.isNumber)(node) || typeof node === 'boolean' || !(0, _variableType.isValue)(node) || (0, _variableType.isEmptyObject)(node)) {
|
|
34
|
-
// text node defined as value
|
|
35
|
-
node = {
|
|
36
|
-
text: convertValueToString(node)
|
|
37
|
-
};
|
|
38
|
-
} else if ('text' in node) {
|
|
39
|
-
// cast value in text property
|
|
40
|
-
node.text = convertValueToString(node.text);
|
|
41
|
-
}
|
|
42
|
-
if (node.columns) {
|
|
43
|
-
return this.preprocessColumns(node);
|
|
44
|
-
} else if (node.stack) {
|
|
45
|
-
return this.preprocessVerticalContainer(node);
|
|
46
|
-
} else if (node.ul) {
|
|
47
|
-
return this.preprocessList(node);
|
|
48
|
-
} else if (node.ol) {
|
|
49
|
-
return this.preprocessList(node);
|
|
50
|
-
} else if (node.table) {
|
|
51
|
-
return this.preprocessTable(node);
|
|
52
|
-
} else if (node.text !== undefined) {
|
|
53
|
-
return this.preprocessText(node);
|
|
54
|
-
} else if (node.toc) {
|
|
55
|
-
return this.preprocessToc(node);
|
|
56
|
-
} else if (node.image) {
|
|
57
|
-
return this.preprocessImage(node);
|
|
58
|
-
} else if (node.svg) {
|
|
59
|
-
return this.preprocessSVG(node);
|
|
60
|
-
} else if (node.canvas) {
|
|
61
|
-
return this.preprocessCanvas(node);
|
|
62
|
-
} else if (node.qr) {
|
|
63
|
-
return this.preprocessQr(node);
|
|
64
|
-
} else if (node.attachment) {
|
|
65
|
-
return this.preprocessAttachment(node);
|
|
66
|
-
} else if (node.pageReference || node.textReference) {
|
|
67
|
-
return this.preprocessText(node);
|
|
68
|
-
} else {
|
|
69
|
-
throw new Error(`Unrecognized document structure: ${(0, _node.stringifyNode)(node)}`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
preprocessColumns(node) {
|
|
73
|
-
let columns = node.columns;
|
|
74
|
-
for (let i = 0, l = columns.length; i < l; i++) {
|
|
75
|
-
columns[i] = this.preprocessNode(columns[i]);
|
|
76
|
-
}
|
|
77
|
-
return node;
|
|
78
|
-
}
|
|
79
|
-
preprocessVerticalContainer(node) {
|
|
80
|
-
let items = node.stack;
|
|
81
|
-
for (let i = 0, l = items.length; i < l; i++) {
|
|
82
|
-
items[i] = this.preprocessNode(items[i]);
|
|
83
|
-
}
|
|
84
|
-
return node;
|
|
85
|
-
}
|
|
86
|
-
preprocessList(node) {
|
|
87
|
-
let items = node.ul || node.ol;
|
|
88
|
-
for (let i = 0, l = items.length; i < l; i++) {
|
|
89
|
-
items[i] = this.preprocessNode(items[i]);
|
|
90
|
-
}
|
|
91
|
-
return node;
|
|
92
|
-
}
|
|
93
|
-
preprocessTable(node) {
|
|
94
|
-
let col;
|
|
95
|
-
let row;
|
|
96
|
-
let cols;
|
|
97
|
-
let rows;
|
|
98
|
-
for (col = 0, cols = node.table.body[0].length; col < cols; col++) {
|
|
99
|
-
for (row = 0, rows = node.table.body.length; row < rows; row++) {
|
|
100
|
-
let rowData = node.table.body[row];
|
|
101
|
-
let data = rowData[col];
|
|
102
|
-
if (data !== undefined) {
|
|
103
|
-
if (data === null) {
|
|
104
|
-
// transform to object
|
|
105
|
-
data = '';
|
|
106
|
-
}
|
|
107
|
-
if (!data._span) {
|
|
108
|
-
rowData[col] = this.preprocessNode(data);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return node;
|
|
114
|
-
}
|
|
115
|
-
preprocessText(node) {
|
|
116
|
-
if (node.tocItem) {
|
|
117
|
-
if (!Array.isArray(node.tocItem)) {
|
|
118
|
-
node.tocItem = [node.tocItem];
|
|
119
|
-
}
|
|
120
|
-
for (let i = 0, l = node.tocItem.length; i < l; i++) {
|
|
121
|
-
if (!(0, _variableType.isString)(node.tocItem[i])) {
|
|
122
|
-
node.tocItem[i] = '_default_';
|
|
123
|
-
}
|
|
124
|
-
let tocItemId = node.tocItem[i];
|
|
125
|
-
if (!this.tocs[tocItemId]) {
|
|
126
|
-
this.tocs[tocItemId] = {
|
|
127
|
-
toc: {
|
|
128
|
-
_items: [],
|
|
129
|
-
_pseudo: true
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
if (!node.id) {
|
|
134
|
-
node.id = `toc-${tocItemId}-${this.tocs[tocItemId].toc._items.length}`;
|
|
135
|
-
}
|
|
136
|
-
let tocItemRef = {
|
|
137
|
-
_nodeRef: this._getNodeForNodeRef(node),
|
|
138
|
-
_textNodeRef: node
|
|
139
|
-
};
|
|
140
|
-
this.tocs[tocItemId].toc._items.push(tocItemRef);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
if (node.id) {
|
|
144
|
-
if (this.nodeReferences[node.id]) {
|
|
145
|
-
if (!this.nodeReferences[node.id]._pseudo) {
|
|
146
|
-
throw new Error(`Node id '${node.id}' already exists`);
|
|
147
|
-
}
|
|
148
|
-
this.nodeReferences[node.id]._nodeRef = this._getNodeForNodeRef(node);
|
|
149
|
-
this.nodeReferences[node.id]._textNodeRef = node;
|
|
150
|
-
this.nodeReferences[node.id]._pseudo = false;
|
|
151
|
-
} else {
|
|
152
|
-
this.nodeReferences[node.id] = {
|
|
153
|
-
_nodeRef: this._getNodeForNodeRef(node),
|
|
154
|
-
_textNodeRef: node
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
if (node.pageReference) {
|
|
159
|
-
if (!this.nodeReferences[node.pageReference]) {
|
|
160
|
-
this.nodeReferences[node.pageReference] = {
|
|
161
|
-
_nodeRef: {},
|
|
162
|
-
_textNodeRef: {},
|
|
163
|
-
_pseudo: true
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
node.text = '00000';
|
|
167
|
-
node.linkToDestination = node.pageReference;
|
|
168
|
-
node._pageRef = this.nodeReferences[node.pageReference];
|
|
169
|
-
}
|
|
170
|
-
if (node.textReference) {
|
|
171
|
-
if (!this.nodeReferences[node.textReference]) {
|
|
172
|
-
this.nodeReferences[node.textReference] = {
|
|
173
|
-
_nodeRef: {},
|
|
174
|
-
_pseudo: true
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
node.text = '';
|
|
178
|
-
node.linkToDestination = node.textReference;
|
|
179
|
-
node._textRef = this.nodeReferences[node.textReference];
|
|
180
|
-
}
|
|
181
|
-
if (node.text && node.text.text) {
|
|
182
|
-
node.text = [this.preprocessNode(node.text)];
|
|
183
|
-
} else if (Array.isArray(node.text)) {
|
|
184
|
-
let isSetParentNode = false;
|
|
185
|
-
if (this.parentNode === null) {
|
|
186
|
-
this.parentNode = node;
|
|
187
|
-
isSetParentNode = true;
|
|
188
|
-
}
|
|
189
|
-
for (let i = 0, l = node.text.length; i < l; i++) {
|
|
190
|
-
node.text[i] = this.preprocessNode(node.text[i]);
|
|
191
|
-
}
|
|
192
|
-
if (isSetParentNode) {
|
|
193
|
-
this.parentNode = null;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return node;
|
|
197
|
-
}
|
|
198
|
-
preprocessToc(node) {
|
|
199
|
-
if (!node.toc.id) {
|
|
200
|
-
node.toc.id = '_default_';
|
|
201
|
-
}
|
|
202
|
-
node.toc.title = node.toc.title ? this.preprocessNode(node.toc.title) : null;
|
|
203
|
-
node.toc._items = [];
|
|
204
|
-
if (this.tocs[node.toc.id]) {
|
|
205
|
-
if (!this.tocs[node.toc.id].toc._pseudo) {
|
|
206
|
-
throw new Error(`TOC '${node.toc.id}' already exists`);
|
|
207
|
-
}
|
|
208
|
-
node.toc._items = this.tocs[node.toc.id].toc._items;
|
|
209
|
-
}
|
|
210
|
-
this.tocs[node.toc.id] = node;
|
|
211
|
-
return node;
|
|
212
|
-
}
|
|
213
|
-
preprocessImage(node) {
|
|
214
|
-
if (node.image.type !== undefined && node.image.data !== undefined && node.image.type === 'Buffer' && Array.isArray(node.image.data)) {
|
|
215
|
-
node.image = Buffer.from(node.image.data);
|
|
216
|
-
}
|
|
217
|
-
return node;
|
|
218
|
-
}
|
|
219
|
-
preprocessCanvas(node) {
|
|
220
|
-
return node;
|
|
221
|
-
}
|
|
222
|
-
preprocessSVG(node) {
|
|
223
|
-
return node;
|
|
224
|
-
}
|
|
225
|
-
preprocessQr(node) {
|
|
226
|
-
return node;
|
|
227
|
-
}
|
|
228
|
-
preprocessAttachment(node) {
|
|
229
|
-
return node;
|
|
230
|
-
}
|
|
231
|
-
_getNodeForNodeRef(node) {
|
|
232
|
-
if (this.parentNode) {
|
|
233
|
-
return this.parentNode;
|
|
234
|
-
}
|
|
235
|
-
return node;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
var _default = exports.default = DocPreprocessor;
|
package/js/DocumentContext.js
DELETED
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
exports.default = void 0;
|
|
5
|
-
var _variableType = require("./helpers/variableType");
|
|
6
|
-
var _events = require("events");
|
|
7
|
-
/**
|
|
8
|
-
* A store for current x, y positions and available width/height.
|
|
9
|
-
* It facilitates column divisions and vertical sync
|
|
10
|
-
*/
|
|
11
|
-
class DocumentContext extends _events.EventEmitter {
|
|
12
|
-
constructor(pageSize, pageMargins) {
|
|
13
|
-
super();
|
|
14
|
-
this.pages = [];
|
|
15
|
-
this.pageMargins = pageMargins;
|
|
16
|
-
this.x = pageMargins.left;
|
|
17
|
-
this.availableWidth = pageSize.width - pageMargins.left - pageMargins.right;
|
|
18
|
-
this.availableHeight = 0;
|
|
19
|
-
this.page = -1;
|
|
20
|
-
this.snapshots = [];
|
|
21
|
-
this.endingCell = null;
|
|
22
|
-
this.backgroundLength = [];
|
|
23
|
-
this.addPage(pageSize);
|
|
24
|
-
}
|
|
25
|
-
beginColumnGroup() {
|
|
26
|
-
this.snapshots.push({
|
|
27
|
-
x: this.x,
|
|
28
|
-
y: this.y,
|
|
29
|
-
availableHeight: this.availableHeight,
|
|
30
|
-
availableWidth: this.availableWidth,
|
|
31
|
-
page: this.page,
|
|
32
|
-
bottomMost: {
|
|
33
|
-
x: this.x,
|
|
34
|
-
y: this.y,
|
|
35
|
-
availableHeight: this.availableHeight,
|
|
36
|
-
availableWidth: this.availableWidth,
|
|
37
|
-
page: this.page
|
|
38
|
-
},
|
|
39
|
-
endingCell: this.endingCell,
|
|
40
|
-
lastColumnWidth: this.lastColumnWidth
|
|
41
|
-
});
|
|
42
|
-
this.lastColumnWidth = 0;
|
|
43
|
-
}
|
|
44
|
-
beginColumn(width, offset, endingCell) {
|
|
45
|
-
let saved = this.snapshots[this.snapshots.length - 1];
|
|
46
|
-
this.calculateBottomMost(saved);
|
|
47
|
-
this.endingCell = endingCell;
|
|
48
|
-
this.page = saved.page;
|
|
49
|
-
this.x = this.x + this.lastColumnWidth + (offset || 0);
|
|
50
|
-
this.y = saved.y;
|
|
51
|
-
this.availableWidth = width; //saved.availableWidth - offset;
|
|
52
|
-
this.availableHeight = saved.availableHeight;
|
|
53
|
-
this.lastColumnWidth = width;
|
|
54
|
-
}
|
|
55
|
-
calculateBottomMost(destContext) {
|
|
56
|
-
if (this.endingCell) {
|
|
57
|
-
this.saveContextInEndingCell(this.endingCell);
|
|
58
|
-
this.endingCell = null;
|
|
59
|
-
} else {
|
|
60
|
-
destContext.bottomMost = bottomMostContext(this, destContext.bottomMost);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
markEnding(endingCell) {
|
|
64
|
-
this.page = endingCell._columnEndingContext.page;
|
|
65
|
-
this.x = endingCell._columnEndingContext.x;
|
|
66
|
-
this.y = endingCell._columnEndingContext.y;
|
|
67
|
-
this.availableWidth = endingCell._columnEndingContext.availableWidth;
|
|
68
|
-
this.availableHeight = endingCell._columnEndingContext.availableHeight;
|
|
69
|
-
this.lastColumnWidth = endingCell._columnEndingContext.lastColumnWidth;
|
|
70
|
-
}
|
|
71
|
-
saveContextInEndingCell(endingCell) {
|
|
72
|
-
endingCell._columnEndingContext = {
|
|
73
|
-
page: this.page,
|
|
74
|
-
x: this.x,
|
|
75
|
-
y: this.y,
|
|
76
|
-
availableHeight: this.availableHeight,
|
|
77
|
-
availableWidth: this.availableWidth,
|
|
78
|
-
lastColumnWidth: this.lastColumnWidth
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
completeColumnGroup(height) {
|
|
82
|
-
let saved = this.snapshots.pop();
|
|
83
|
-
this.calculateBottomMost(saved);
|
|
84
|
-
this.endingCell = null;
|
|
85
|
-
this.x = saved.x;
|
|
86
|
-
let y = saved.bottomMost.y;
|
|
87
|
-
if (height) {
|
|
88
|
-
if (saved.page === saved.bottomMost.page) {
|
|
89
|
-
if (saved.y + height > y) {
|
|
90
|
-
y = saved.y + height;
|
|
91
|
-
}
|
|
92
|
-
} else {
|
|
93
|
-
y += height;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
this.y = y;
|
|
97
|
-
this.page = saved.bottomMost.page;
|
|
98
|
-
this.availableWidth = saved.availableWidth;
|
|
99
|
-
this.availableHeight = saved.bottomMost.availableHeight;
|
|
100
|
-
if (height) {
|
|
101
|
-
this.availableHeight -= y - saved.bottomMost.y;
|
|
102
|
-
}
|
|
103
|
-
this.lastColumnWidth = saved.lastColumnWidth;
|
|
104
|
-
}
|
|
105
|
-
addMargin(left, right) {
|
|
106
|
-
this.x += left;
|
|
107
|
-
this.availableWidth -= left + (right || 0);
|
|
108
|
-
}
|
|
109
|
-
moveDown(offset) {
|
|
110
|
-
this.y += offset;
|
|
111
|
-
this.availableHeight -= offset;
|
|
112
|
-
return this.availableHeight > 0;
|
|
113
|
-
}
|
|
114
|
-
initializePage() {
|
|
115
|
-
this.y = this.pageMargins.top;
|
|
116
|
-
this.availableHeight = this.getCurrentPage().pageSize.height - this.pageMargins.top - this.pageMargins.bottom;
|
|
117
|
-
this.pageSnapshot().availableWidth = this.getCurrentPage().pageSize.width - this.pageMargins.left - this.pageMargins.right;
|
|
118
|
-
}
|
|
119
|
-
pageSnapshot() {
|
|
120
|
-
if (this.snapshots[0]) {
|
|
121
|
-
return this.snapshots[0];
|
|
122
|
-
} else {
|
|
123
|
-
return this;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
moveTo(x, y) {
|
|
127
|
-
if (x !== undefined && x !== null) {
|
|
128
|
-
this.x = x;
|
|
129
|
-
this.availableWidth = this.getCurrentPage().pageSize.width - this.x - this.pageMargins.right;
|
|
130
|
-
}
|
|
131
|
-
if (y !== undefined && y !== null) {
|
|
132
|
-
this.y = y;
|
|
133
|
-
this.availableHeight = this.getCurrentPage().pageSize.height - this.y - this.pageMargins.bottom;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
moveToRelative(x, y) {
|
|
137
|
-
if (x !== undefined && x !== null) {
|
|
138
|
-
this.x = this.x + x;
|
|
139
|
-
}
|
|
140
|
-
if (y !== undefined && y !== null) {
|
|
141
|
-
this.y = this.y + y;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
beginDetachedBlock() {
|
|
145
|
-
this.snapshots.push({
|
|
146
|
-
x: this.x,
|
|
147
|
-
y: this.y,
|
|
148
|
-
availableHeight: this.availableHeight,
|
|
149
|
-
availableWidth: this.availableWidth,
|
|
150
|
-
page: this.page,
|
|
151
|
-
endingCell: this.endingCell,
|
|
152
|
-
lastColumnWidth: this.lastColumnWidth
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
endDetachedBlock() {
|
|
156
|
-
let saved = this.snapshots.pop();
|
|
157
|
-
this.x = saved.x;
|
|
158
|
-
this.y = saved.y;
|
|
159
|
-
this.availableWidth = saved.availableWidth;
|
|
160
|
-
this.availableHeight = saved.availableHeight;
|
|
161
|
-
this.page = saved.page;
|
|
162
|
-
this.endingCell = saved.endingCell;
|
|
163
|
-
this.lastColumnWidth = saved.lastColumnWidth;
|
|
164
|
-
}
|
|
165
|
-
moveToNextPage(pageOrientation) {
|
|
166
|
-
let nextPageIndex = this.page + 1;
|
|
167
|
-
let prevPage = this.page;
|
|
168
|
-
let prevY = this.y;
|
|
169
|
-
let createNewPage = nextPageIndex >= this.pages.length;
|
|
170
|
-
if (createNewPage) {
|
|
171
|
-
let currentAvailableWidth = this.availableWidth;
|
|
172
|
-
let currentPageOrientation = this.getCurrentPage().pageSize.orientation;
|
|
173
|
-
let pageSize = getPageSize(this.getCurrentPage(), pageOrientation);
|
|
174
|
-
this.addPage(pageSize);
|
|
175
|
-
if (currentPageOrientation === pageSize.orientation) {
|
|
176
|
-
this.availableWidth = currentAvailableWidth;
|
|
177
|
-
}
|
|
178
|
-
} else {
|
|
179
|
-
this.page = nextPageIndex;
|
|
180
|
-
this.initializePage();
|
|
181
|
-
}
|
|
182
|
-
return {
|
|
183
|
-
newPageCreated: createNewPage,
|
|
184
|
-
prevPage: prevPage,
|
|
185
|
-
prevY: prevY,
|
|
186
|
-
y: this.y
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
addPage(pageSize) {
|
|
190
|
-
let page = {
|
|
191
|
-
items: [],
|
|
192
|
-
pageSize: pageSize
|
|
193
|
-
};
|
|
194
|
-
this.pages.push(page);
|
|
195
|
-
this.backgroundLength.push(0);
|
|
196
|
-
this.page = this.pages.length - 1;
|
|
197
|
-
this.initializePage();
|
|
198
|
-
this.emit('pageAdded');
|
|
199
|
-
return page;
|
|
200
|
-
}
|
|
201
|
-
getCurrentPage() {
|
|
202
|
-
if (this.page < 0 || this.page >= this.pages.length) {
|
|
203
|
-
return null;
|
|
204
|
-
}
|
|
205
|
-
return this.pages[this.page];
|
|
206
|
-
}
|
|
207
|
-
getCurrentPosition() {
|
|
208
|
-
let pageSize = this.getCurrentPage().pageSize;
|
|
209
|
-
let innerHeight = pageSize.height - this.pageMargins.top - this.pageMargins.bottom;
|
|
210
|
-
let innerWidth = pageSize.width - this.pageMargins.left - this.pageMargins.right;
|
|
211
|
-
return {
|
|
212
|
-
pageNumber: this.page + 1,
|
|
213
|
-
pageOrientation: pageSize.orientation,
|
|
214
|
-
pageInnerHeight: innerHeight,
|
|
215
|
-
pageInnerWidth: innerWidth,
|
|
216
|
-
left: this.x,
|
|
217
|
-
top: this.y,
|
|
218
|
-
verticalRatio: (this.y - this.pageMargins.top) / innerHeight,
|
|
219
|
-
horizontalRatio: (this.x - this.pageMargins.left) / innerWidth
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
function pageOrientation(pageOrientationString, currentPageOrientation) {
|
|
224
|
-
if (pageOrientationString === undefined) {
|
|
225
|
-
return currentPageOrientation;
|
|
226
|
-
} else if ((0, _variableType.isString)(pageOrientationString) && pageOrientationString.toLowerCase() === 'landscape') {
|
|
227
|
-
return 'landscape';
|
|
228
|
-
} else {
|
|
229
|
-
return 'portrait';
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
const getPageSize = (currentPage, newPageOrientation) => {
|
|
233
|
-
newPageOrientation = pageOrientation(newPageOrientation, currentPage.pageSize.orientation);
|
|
234
|
-
if (newPageOrientation !== currentPage.pageSize.orientation) {
|
|
235
|
-
return {
|
|
236
|
-
orientation: newPageOrientation,
|
|
237
|
-
width: currentPage.pageSize.height,
|
|
238
|
-
height: currentPage.pageSize.width
|
|
239
|
-
};
|
|
240
|
-
} else {
|
|
241
|
-
return {
|
|
242
|
-
orientation: currentPage.pageSize.orientation,
|
|
243
|
-
width: currentPage.pageSize.width,
|
|
244
|
-
height: currentPage.pageSize.height
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
function bottomMostContext(c1, c2) {
|
|
249
|
-
let r;
|
|
250
|
-
if (c1.page > c2.page) {
|
|
251
|
-
r = c1;
|
|
252
|
-
} else if (c2.page > c1.page) {
|
|
253
|
-
r = c2;
|
|
254
|
-
} else {
|
|
255
|
-
r = c1.y > c2.y ? c1 : c2;
|
|
256
|
-
}
|
|
257
|
-
return {
|
|
258
|
-
page: r.page,
|
|
259
|
-
x: r.x,
|
|
260
|
-
y: r.y,
|
|
261
|
-
availableHeight: r.availableHeight,
|
|
262
|
-
availableWidth: r.availableWidth
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
var _default = exports.default = DocumentContext;
|