pdfmake 0.2.4 → 0.3.0-beta.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.
Files changed (128) hide show
  1. package/CHANGELOG.md +8 -30
  2. package/README.md +8 -6
  3. package/build/pdfmake.js +28921 -26825
  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 +750 -0
  22. package/js/DocPreprocessor.js +285 -0
  23. package/js/DocumentContext.js +306 -0
  24. package/js/ElementWriter.js +377 -0
  25. package/js/LayoutBuilder.js +833 -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 +163 -0
  30. package/js/PageElementWriter.js +161 -0
  31. package/js/PageSize.js +88 -0
  32. package/js/Printer.js +238 -0
  33. package/js/Renderer.js +433 -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 +79 -0
  41. package/js/base.js +69 -0
  42. package/js/browser-extensions/OutputDocumentBrowser.js +131 -0
  43. package/js/browser-extensions/URLBrowserResolver.js +89 -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 +694 -0
  65. package/src/DocPreprocessor.js +258 -0
  66. package/src/DocumentContext.js +309 -0
  67. package/src/ElementWriter.js +368 -0
  68. package/src/LayoutBuilder.js +814 -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 +148 -0
  73. package/src/PageElementWriter.js +156 -0
  74. package/src/PageSize.js +53 -0
  75. package/src/Printer.js +220 -0
  76. package/src/Renderer.js +370 -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 +69 -0
  84. package/src/base.js +61 -0
  85. package/src/browser-extensions/OutputDocumentBrowser.js +117 -0
  86. package/src/browser-extensions/URLBrowserResolver.js +46 -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,285 @@
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.pageReference || node.textReference) {
70
+ return this.preprocessText(node);
71
+ } else {
72
+ throw new Error(`Unrecognized document structure: ${(0, _node.stringifyNode)(node)}`);
73
+ }
74
+ }
75
+
76
+ preprocessColumns(node) {
77
+ let columns = node.columns;
78
+
79
+ for (let i = 0, l = columns.length; i < l; i++) {
80
+ columns[i] = this.preprocessNode(columns[i]);
81
+ }
82
+
83
+ return node;
84
+ }
85
+
86
+ preprocessVerticalContainer(node) {
87
+ let items = node.stack;
88
+
89
+ for (let i = 0, l = items.length; i < l; i++) {
90
+ items[i] = this.preprocessNode(items[i]);
91
+ }
92
+
93
+ return node;
94
+ }
95
+
96
+ preprocessList(node) {
97
+ let items = node.ul || node.ol;
98
+
99
+ for (let i = 0, l = items.length; i < l; i++) {
100
+ items[i] = this.preprocessNode(items[i]);
101
+ }
102
+
103
+ return node;
104
+ }
105
+
106
+ preprocessTable(node) {
107
+ let col;
108
+ let row;
109
+ let cols;
110
+ let rows;
111
+
112
+ for (col = 0, cols = node.table.body[0].length; col < cols; col++) {
113
+ for (row = 0, rows = node.table.body.length; row < rows; row++) {
114
+ let rowData = node.table.body[row];
115
+ let data = rowData[col];
116
+
117
+ if (data !== undefined) {
118
+ if (data === null) {
119
+ // transform to object
120
+ data = '';
121
+ }
122
+
123
+ if (!data._span) {
124
+ rowData[col] = this.preprocessNode(data);
125
+ }
126
+ }
127
+ }
128
+ }
129
+
130
+ return node;
131
+ }
132
+
133
+ preprocessText(node) {
134
+ if (node.tocItem) {
135
+ if (!Array.isArray(node.tocItem)) {
136
+ node.tocItem = [node.tocItem];
137
+ }
138
+
139
+ for (let i = 0, l = node.tocItem.length; i < l; i++) {
140
+ if (!(0, _variableType.isString)(node.tocItem[i])) {
141
+ node.tocItem[i] = '_default_';
142
+ }
143
+
144
+ let tocItemId = node.tocItem[i];
145
+
146
+ if (!this.tocs[tocItemId]) {
147
+ this.tocs[tocItemId] = {
148
+ toc: {
149
+ _items: [],
150
+ _pseudo: true
151
+ }
152
+ };
153
+ }
154
+
155
+ if (!node.id) {
156
+ node.id = `toc-${tocItemId}-${this.tocs[tocItemId].toc._items.length}`;
157
+ }
158
+
159
+ let tocItemRef = {
160
+ _nodeRef: this._getNodeForNodeRef(node),
161
+ _textNodeRef: node
162
+ };
163
+
164
+ this.tocs[tocItemId].toc._items.push(tocItemRef);
165
+ }
166
+ }
167
+
168
+ if (node.id) {
169
+ if (this.nodeReferences[node.id]) {
170
+ if (!this.nodeReferences[node.id]._pseudo) {
171
+ throw new Error(`Node id '${node.id}' already exists`);
172
+ }
173
+
174
+ this.nodeReferences[node.id]._nodeRef = this._getNodeForNodeRef(node);
175
+ this.nodeReferences[node.id]._textNodeRef = node;
176
+ this.nodeReferences[node.id]._pseudo = false;
177
+ } else {
178
+ this.nodeReferences[node.id] = {
179
+ _nodeRef: this._getNodeForNodeRef(node),
180
+ _textNodeRef: node
181
+ };
182
+ }
183
+ }
184
+
185
+ if (node.pageReference) {
186
+ if (!this.nodeReferences[node.pageReference]) {
187
+ this.nodeReferences[node.pageReference] = {
188
+ _nodeRef: {},
189
+ _textNodeRef: {},
190
+ _pseudo: true
191
+ };
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] = {
202
+ _nodeRef: {},
203
+ _pseudo: true
204
+ };
205
+ }
206
+
207
+ node.text = '';
208
+ node.linkToDestination = node.textReference;
209
+ node._textRef = this.nodeReferences[node.textReference];
210
+ }
211
+
212
+ if (node.text && node.text.text) {
213
+ node.text = [this.preprocessNode(node.text)];
214
+ } else if (Array.isArray(node.text)) {
215
+ let isSetParentNode = false;
216
+
217
+ if (this.parentNode === null) {
218
+ this.parentNode = node;
219
+ isSetParentNode = true;
220
+ }
221
+
222
+ for (let i = 0, l = node.text.length; i < l; i++) {
223
+ node.text[i] = this.preprocessNode(node.text[i]);
224
+ }
225
+
226
+ if (isSetParentNode) {
227
+ this.parentNode = null;
228
+ }
229
+ }
230
+
231
+ return node;
232
+ }
233
+
234
+ preprocessToc(node) {
235
+ if (!node.toc.id) {
236
+ node.toc.id = '_default_';
237
+ }
238
+
239
+ node.toc.title = node.toc.title ? this.preprocessNode(node.toc.title) : null;
240
+ node.toc._items = [];
241
+
242
+ if (this.tocs[node.toc.id]) {
243
+ if (!this.tocs[node.toc.id].toc._pseudo) {
244
+ throw new Error(`TOC '${node.toc.id}' already exists`);
245
+ }
246
+
247
+ node.toc._items = this.tocs[node.toc.id].toc._items;
248
+ }
249
+
250
+ this.tocs[node.toc.id] = node;
251
+ return node;
252
+ }
253
+
254
+ preprocessImage(node) {
255
+ if (node.image.type !== undefined && node.image.data !== undefined && node.image.type === 'Buffer' && Array.isArray(node.image.data)) {
256
+ node.image = Buffer.from(node.image.data);
257
+ }
258
+
259
+ return node;
260
+ }
261
+
262
+ preprocessCanvas(node) {
263
+ return node;
264
+ }
265
+
266
+ preprocessSVG(node) {
267
+ return node;
268
+ }
269
+
270
+ preprocessQr(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
+
284
+ var _default = DocPreprocessor;
285
+ 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;