pdfmake 0.2.4 → 0.3.0-beta.2

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