pdfmake 0.2.13 → 0.3.0-beta.10

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 (136) hide show
  1. package/CHANGELOG.md +23 -41
  2. package/README.md +11 -7
  3. package/build/pdfmake.js +22291 -23202
  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/eslint.config.mjs +52 -0
  15. package/fonts/Roboto/Roboto-Italic.ttf +0 -0
  16. package/fonts/Roboto/Roboto-Medium.ttf +0 -0
  17. package/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
  18. package/fonts/Roboto/Roboto-Regular.ttf +0 -0
  19. package/fonts/Roboto.js +8 -0
  20. package/js/3rd-party/svg-to-pdfkit/source.js +3626 -0
  21. package/js/3rd-party/svg-to-pdfkit.js +7 -0
  22. package/js/DocMeasure.js +626 -0
  23. package/js/DocPreprocessor.js +238 -0
  24. package/js/DocumentContext.js +288 -0
  25. package/js/ElementWriter.js +342 -0
  26. package/js/LayoutBuilder.js +881 -0
  27. package/js/Line.js +105 -0
  28. package/js/OutputDocument.js +76 -0
  29. package/js/OutputDocumentServer.js +27 -0
  30. package/js/PDFDocument.js +144 -0
  31. package/js/PageElementWriter.js +140 -0
  32. package/js/PageSize.js +74 -0
  33. package/js/Printer.js +291 -0
  34. package/js/Renderer.js +375 -0
  35. package/js/SVGMeasure.js +69 -0
  36. package/js/StyleContextStack.js +164 -0
  37. package/js/TableProcessor.js +524 -0
  38. package/js/TextBreaker.js +139 -0
  39. package/js/TextDecorator.js +143 -0
  40. package/js/TextInlines.js +206 -0
  41. package/js/URLResolver.js +73 -0
  42. package/js/base.js +52 -0
  43. package/js/browser-extensions/OutputDocumentBrowser.js +118 -0
  44. package/js/browser-extensions/URLBrowserResolver.js +76 -0
  45. package/js/browser-extensions/fonts/Roboto.js +38 -0
  46. package/js/browser-extensions/index.js +53 -0
  47. package/js/browser-extensions/pdfMake.js +3 -0
  48. package/js/browser-extensions/standard-fonts/Courier.js +38 -0
  49. package/js/browser-extensions/standard-fonts/Helvetica.js +38 -0
  50. package/js/browser-extensions/standard-fonts/Symbol.js +23 -0
  51. package/js/browser-extensions/standard-fonts/Times.js +38 -0
  52. package/js/browser-extensions/standard-fonts/ZapfDingbats.js +23 -0
  53. package/js/browser-extensions/virtual-fs-cjs.js +3 -0
  54. package/js/columnCalculator.js +148 -0
  55. package/js/helpers/node.js +98 -0
  56. package/js/helpers/tools.js +40 -0
  57. package/js/helpers/variableType.js +59 -0
  58. package/js/index.js +15 -0
  59. package/js/qrEnc.js +721 -0
  60. package/js/standardPageSizes.js +56 -0
  61. package/js/tableLayouts.js +98 -0
  62. package/js/virtual-fs.js +60 -0
  63. package/package.json +34 -28
  64. package/src/3rd-party/svg-to-pdfkit.js +2 -2
  65. package/src/DocMeasure.js +707 -0
  66. package/src/DocPreprocessor.js +264 -0
  67. package/src/DocumentContext.js +324 -0
  68. package/src/ElementWriter.js +405 -0
  69. package/src/LayoutBuilder.js +997 -0
  70. package/src/Line.js +114 -0
  71. package/src/OutputDocument.js +78 -0
  72. package/src/OutputDocumentServer.js +26 -0
  73. package/src/PDFDocument.js +174 -0
  74. package/src/PageElementWriter.js +160 -0
  75. package/src/PageSize.js +53 -0
  76. package/src/Printer.js +306 -0
  77. package/src/Renderer.js +405 -0
  78. package/src/SVGMeasure.js +79 -0
  79. package/src/StyleContextStack.js +175 -0
  80. package/src/TableProcessor.js +580 -0
  81. package/src/TextBreaker.js +149 -0
  82. package/src/TextDecorator.js +161 -0
  83. package/src/TextInlines.js +223 -0
  84. package/src/URLResolver.js +77 -0
  85. package/src/base.js +61 -0
  86. package/src/browser-extensions/OutputDocumentBrowser.js +117 -0
  87. package/src/browser-extensions/URLBrowserResolver.js +45 -57
  88. package/src/browser-extensions/fonts/Roboto.js +27 -0
  89. package/src/browser-extensions/index.js +55 -0
  90. package/src/browser-extensions/pdfMake.js +1 -329
  91. package/src/browser-extensions/standard-fonts/Courier.js +27 -0
  92. package/src/browser-extensions/standard-fonts/Helvetica.js +27 -0
  93. package/src/browser-extensions/standard-fonts/Symbol.js +21 -0
  94. package/src/browser-extensions/standard-fonts/Times.js +27 -0
  95. package/src/browser-extensions/standard-fonts/ZapfDingbats.js +21 -0
  96. package/src/browser-extensions/virtual-fs-cjs.js +1 -0
  97. package/src/columnCalculator.js +35 -38
  98. package/src/helpers/node.js +110 -0
  99. package/src/helpers/tools.js +39 -0
  100. package/src/helpers/variableType.js +50 -0
  101. package/src/index.js +16 -0
  102. package/src/qrEnc.js +15 -10
  103. package/src/standardPageSizes.js +1 -3
  104. package/src/tableLayouts.js +100 -0
  105. package/src/virtual-fs.js +66 -0
  106. package/standard-fonts/Courier.js +8 -0
  107. package/standard-fonts/Helvetica.js +9 -0
  108. package/standard-fonts/Symbol.js +5 -0
  109. package/standard-fonts/Times.js +8 -0
  110. package/standard-fonts/ZapfDingbats.js +5 -0
  111. package/.idea/codeStyles/Project.xml +0 -7
  112. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  113. package/.idea/inspectionProfiles/Project_Default.xml +0 -6
  114. package/.idea/misc.xml +0 -6
  115. package/.idea/modules.xml +0 -8
  116. package/.idea/pdfmake.iml +0 -11
  117. package/.idea/vcs.xml +0 -6
  118. package/src/browser-extensions/virtual-fs.js +0 -55
  119. package/src/docMeasure.js +0 -810
  120. package/src/docPreprocessor.js +0 -255
  121. package/src/documentContext.js +0 -328
  122. package/src/elementWriter.js +0 -333
  123. package/src/fontProvider.js +0 -68
  124. package/src/helpers.js +0 -138
  125. package/src/imageMeasure.js +0 -55
  126. package/src/layoutBuilder.js +0 -989
  127. package/src/line.js +0 -91
  128. package/src/pageElementWriter.js +0 -174
  129. package/src/pdfKitEngine.js +0 -21
  130. package/src/printer.js +0 -710
  131. package/src/styleContextStack.js +0 -138
  132. package/src/svgMeasure.js +0 -70
  133. package/src/tableProcessor.js +0 -584
  134. package/src/textDecorator.js +0 -157
  135. package/src/textTools.js +0 -373
  136. package/src/traversalTracker.js +0 -47
@@ -0,0 +1,238 @@
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;
@@ -0,0 +1,288 @@
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.backgroundLength = [];
22
+ this.addPage(pageSize);
23
+ }
24
+ beginColumnGroup(marginXTopParent) {
25
+ this.snapshots.push({
26
+ x: this.x,
27
+ y: this.y,
28
+ availableHeight: this.availableHeight,
29
+ availableWidth: this.availableWidth,
30
+ page: this.page,
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
+ resetMarginXTopParent() {
46
+ this.marginXTopParent = null;
47
+ }
48
+ beginColumn(width, offset, endingCell) {
49
+ let saved = this.snapshots[this.snapshots.length - 1];
50
+ this.calculateBottomMost(saved, endingCell);
51
+ this.page = saved.page;
52
+ this.x = this.x + this.lastColumnWidth + (offset || 0);
53
+ this.y = saved.y;
54
+ this.availableWidth = width; //saved.availableWidth - offset;
55
+ this.availableHeight = saved.availableHeight;
56
+ this.lastColumnWidth = width;
57
+ }
58
+ calculateBottomMost(destContext, endingCell) {
59
+ if (endingCell) {
60
+ this.saveContextInEndingCell(endingCell);
61
+ } else {
62
+ destContext.bottomMost = bottomMostContext(this, destContext.bottomMost);
63
+ }
64
+ }
65
+ markEnding(endingCell, originalXOffset, discountY) {
66
+ this.page = endingCell._columnEndingContext.page;
67
+ this.x = endingCell._columnEndingContext.x + originalXOffset;
68
+ this.y = endingCell._columnEndingContext.y - discountY;
69
+ this.availableWidth = endingCell._columnEndingContext.availableWidth;
70
+ this.availableHeight = endingCell._columnEndingContext.availableHeight;
71
+ this.lastColumnWidth = endingCell._columnEndingContext.lastColumnWidth;
72
+ }
73
+ saveContextInEndingCell(endingCell) {
74
+ endingCell._columnEndingContext = {
75
+ page: this.page,
76
+ x: this.x,
77
+ y: this.y,
78
+ availableHeight: this.availableHeight,
79
+ availableWidth: this.availableWidth,
80
+ lastColumnWidth: this.lastColumnWidth
81
+ };
82
+ }
83
+ completeColumnGroup(height, endingCell) {
84
+ let saved = this.snapshots.pop();
85
+ this.calculateBottomMost(saved, endingCell);
86
+ this.x = saved.x;
87
+ let y = saved.bottomMost.y;
88
+ if (height) {
89
+ if (saved.page === saved.bottomMost.page) {
90
+ if (saved.y + height > y) {
91
+ y = saved.y + height;
92
+ }
93
+ } else {
94
+ y += height;
95
+ }
96
+ }
97
+ this.y = y;
98
+ this.page = saved.bottomMost.page;
99
+ this.availableWidth = saved.availableWidth;
100
+ this.availableHeight = saved.bottomMost.availableHeight;
101
+ if (height) {
102
+ this.availableHeight -= y - saved.bottomMost.y;
103
+ }
104
+ this.lastColumnWidth = saved.lastColumnWidth;
105
+ }
106
+ addMargin(left, right) {
107
+ this.x += left;
108
+ this.availableWidth -= left + (right || 0);
109
+ }
110
+ moveDown(offset) {
111
+ this.y += offset;
112
+ this.availableHeight -= offset;
113
+ return this.availableHeight > 0;
114
+ }
115
+ initializePage() {
116
+ this.y = this.pageMargins.top;
117
+ this.availableHeight = this.getCurrentPage().pageSize.height - this.pageMargins.top - this.pageMargins.bottom;
118
+ const {
119
+ pageCtx,
120
+ isSnapshot
121
+ } = this.pageSnapshot();
122
+ pageCtx.availableWidth = this.getCurrentPage().pageSize.width - this.pageMargins.left - this.pageMargins.right;
123
+ if (isSnapshot && this.marginXTopParent) {
124
+ pageCtx.availableWidth -= this.marginXTopParent[0];
125
+ pageCtx.availableWidth -= this.marginXTopParent[1];
126
+ }
127
+ }
128
+ pageSnapshot() {
129
+ if (this.snapshots[0]) {
130
+ return {
131
+ pageCtx: this.snapshots[0],
132
+ isSnapshot: true
133
+ };
134
+ } else {
135
+ return {
136
+ pageCtx: this,
137
+ isSnapshot: false
138
+ };
139
+ }
140
+ }
141
+ moveTo(x, y) {
142
+ if (x !== undefined && x !== null) {
143
+ this.x = x;
144
+ this.availableWidth = this.getCurrentPage().pageSize.width - this.x - this.pageMargins.right;
145
+ }
146
+ if (y !== undefined && y !== null) {
147
+ this.y = y;
148
+ this.availableHeight = this.getCurrentPage().pageSize.height - this.y - this.pageMargins.bottom;
149
+ }
150
+ }
151
+ moveToRelative(x, y) {
152
+ if (x !== undefined && x !== null) {
153
+ this.x = this.x + x;
154
+ }
155
+ if (y !== undefined && y !== null) {
156
+ this.y = this.y + y;
157
+ }
158
+ }
159
+ beginDetachedBlock() {
160
+ this.snapshots.push({
161
+ x: this.x,
162
+ y: this.y,
163
+ availableHeight: this.availableHeight,
164
+ availableWidth: this.availableWidth,
165
+ page: this.page,
166
+ lastColumnWidth: this.lastColumnWidth
167
+ });
168
+ }
169
+ endDetachedBlock() {
170
+ let saved = this.snapshots.pop();
171
+ this.x = saved.x;
172
+ this.y = saved.y;
173
+ this.availableWidth = saved.availableWidth;
174
+ this.availableHeight = saved.availableHeight;
175
+ this.page = saved.page;
176
+ this.lastColumnWidth = saved.lastColumnWidth;
177
+ }
178
+ moveToNextPage(pageOrientation) {
179
+ let nextPageIndex = this.page + 1;
180
+ let prevPage = this.page;
181
+ let prevY = this.y;
182
+
183
+ // If we are in a column group
184
+ if (this.snapshots.length > 0) {
185
+ let lastSnapshot = this.snapshots[this.snapshots.length - 1];
186
+ // We have to update prevY accordingly by also taking into consideration
187
+ // the 'y' of cells that don't break page
188
+ if (lastSnapshot.bottomMost && lastSnapshot.bottomMost.y) {
189
+ prevY = Math.max(this.y, lastSnapshot.bottomMost.y);
190
+ }
191
+ }
192
+ let createNewPage = nextPageIndex >= this.pages.length;
193
+ if (createNewPage) {
194
+ let currentAvailableWidth = this.availableWidth;
195
+ let currentPageOrientation = this.getCurrentPage().pageSize.orientation;
196
+ let pageSize = getPageSize(this.getCurrentPage(), pageOrientation);
197
+ this.addPage(pageSize);
198
+ if (currentPageOrientation === pageSize.orientation) {
199
+ this.availableWidth = currentAvailableWidth;
200
+ }
201
+ } else {
202
+ this.page = nextPageIndex;
203
+ this.initializePage();
204
+ }
205
+ return {
206
+ newPageCreated: createNewPage,
207
+ prevPage: prevPage,
208
+ prevY: prevY,
209
+ y: this.y
210
+ };
211
+ }
212
+ addPage(pageSize) {
213
+ let page = {
214
+ items: [],
215
+ pageSize: pageSize
216
+ };
217
+ this.pages.push(page);
218
+ this.backgroundLength.push(0);
219
+ this.page = this.pages.length - 1;
220
+ this.initializePage();
221
+ this.emit('pageAdded');
222
+ return page;
223
+ }
224
+ getCurrentPage() {
225
+ if (this.page < 0 || this.page >= this.pages.length) {
226
+ return null;
227
+ }
228
+ return this.pages[this.page];
229
+ }
230
+ getCurrentPosition() {
231
+ let pageSize = this.getCurrentPage().pageSize;
232
+ let innerHeight = pageSize.height - this.pageMargins.top - this.pageMargins.bottom;
233
+ let innerWidth = pageSize.width - this.pageMargins.left - this.pageMargins.right;
234
+ return {
235
+ pageNumber: this.page + 1,
236
+ pageOrientation: pageSize.orientation,
237
+ pageInnerHeight: innerHeight,
238
+ pageInnerWidth: innerWidth,
239
+ left: this.x,
240
+ top: this.y,
241
+ verticalRatio: (this.y - this.pageMargins.top) / innerHeight,
242
+ horizontalRatio: (this.x - this.pageMargins.left) / innerWidth
243
+ };
244
+ }
245
+ }
246
+ function pageOrientation(pageOrientationString, currentPageOrientation) {
247
+ if (pageOrientationString === undefined) {
248
+ return currentPageOrientation;
249
+ } else if ((0, _variableType.isString)(pageOrientationString) && pageOrientationString.toLowerCase() === 'landscape') {
250
+ return 'landscape';
251
+ } else {
252
+ return 'portrait';
253
+ }
254
+ }
255
+ const getPageSize = (currentPage, newPageOrientation) => {
256
+ newPageOrientation = pageOrientation(newPageOrientation, currentPage.pageSize.orientation);
257
+ if (newPageOrientation !== currentPage.pageSize.orientation) {
258
+ return {
259
+ orientation: newPageOrientation,
260
+ width: currentPage.pageSize.height,
261
+ height: currentPage.pageSize.width
262
+ };
263
+ } else {
264
+ return {
265
+ orientation: currentPage.pageSize.orientation,
266
+ width: currentPage.pageSize.width,
267
+ height: currentPage.pageSize.height
268
+ };
269
+ }
270
+ };
271
+ function bottomMostContext(c1, c2) {
272
+ let r;
273
+ if (c1.page > c2.page) {
274
+ r = c1;
275
+ } else if (c2.page > c1.page) {
276
+ r = c2;
277
+ } else {
278
+ r = c1.y > c2.y ? c1 : c2;
279
+ }
280
+ return {
281
+ page: r.page,
282
+ x: r.x,
283
+ y: r.y,
284
+ availableHeight: r.availableHeight,
285
+ availableWidth: r.availableWidth
286
+ };
287
+ }
288
+ var _default = exports.default = DocumentContext;