pdfmake 0.3.0-beta.8 → 0.3.0

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