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