pdfmake-acroforms 0.3.4

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 (115) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/LICENSE +21 -0
  3. package/README.md +75 -0
  4. package/build/fonts/Roboto/Roboto-Italic.ttf +0 -0
  5. package/build/fonts/Roboto/Roboto-Medium.ttf +0 -0
  6. package/build/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
  7. package/build/fonts/Roboto/Roboto-Regular.ttf +0 -0
  8. package/build/fonts/Roboto.js +27 -0
  9. package/build/pdfmake.js +67806 -0
  10. package/build/pdfmake.js.map +1 -0
  11. package/build/pdfmake.min.js +3 -0
  12. package/build/pdfmake.min.js.map +1 -0
  13. package/build/standard-fonts/Courier.js +27 -0
  14. package/build/standard-fonts/Helvetica.js +27 -0
  15. package/build/standard-fonts/Symbol.js +21 -0
  16. package/build/standard-fonts/Times.js +27 -0
  17. package/build/standard-fonts/ZapfDingbats.js +21 -0
  18. package/build/vfs_fonts.js +6 -0
  19. package/build-vfs.js +44 -0
  20. package/fonts/Roboto/Roboto-Italic.ttf +0 -0
  21. package/fonts/Roboto/Roboto-Medium.ttf +0 -0
  22. package/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
  23. package/fonts/Roboto/Roboto-Regular.ttf +0 -0
  24. package/fonts/Roboto.js +8 -0
  25. package/js/3rd-party/svg-to-pdfkit/source.js +3823 -0
  26. package/js/3rd-party/svg-to-pdfkit.js +7 -0
  27. package/js/DocMeasure.js +675 -0
  28. package/js/DocPreprocessor.js +258 -0
  29. package/js/DocumentContext.js +310 -0
  30. package/js/ElementWriter.js +399 -0
  31. package/js/LayoutBuilder.js +1202 -0
  32. package/js/Line.js +101 -0
  33. package/js/OutputDocument.js +64 -0
  34. package/js/OutputDocumentServer.js +29 -0
  35. package/js/PDFDocument.js +145 -0
  36. package/js/PageElementWriter.js +164 -0
  37. package/js/PageSize.js +74 -0
  38. package/js/Printer.js +288 -0
  39. package/js/Renderer.js +513 -0
  40. package/js/SVGMeasure.js +92 -0
  41. package/js/StyleContextStack.js +191 -0
  42. package/js/TableProcessor.js +562 -0
  43. package/js/TextBreaker.js +179 -0
  44. package/js/TextDecorator.js +152 -0
  45. package/js/TextInlines.js +212 -0
  46. package/js/URLResolver.js +43 -0
  47. package/js/base.js +59 -0
  48. package/js/browser-extensions/OutputDocumentBrowser.js +82 -0
  49. package/js/browser-extensions/fonts/Roboto.js +38 -0
  50. package/js/browser-extensions/index.js +53 -0
  51. package/js/browser-extensions/pdfMake.js +3 -0
  52. package/js/browser-extensions/standard-fonts/Courier.js +38 -0
  53. package/js/browser-extensions/standard-fonts/Helvetica.js +38 -0
  54. package/js/browser-extensions/standard-fonts/Symbol.js +23 -0
  55. package/js/browser-extensions/standard-fonts/Times.js +38 -0
  56. package/js/browser-extensions/standard-fonts/ZapfDingbats.js +23 -0
  57. package/js/browser-extensions/virtual-fs-cjs.js +3 -0
  58. package/js/columnCalculator.js +148 -0
  59. package/js/helpers/node.js +122 -0
  60. package/js/helpers/tools.js +46 -0
  61. package/js/helpers/variableType.js +59 -0
  62. package/js/index.js +15 -0
  63. package/js/qrEnc.js +721 -0
  64. package/js/standardPageSizes.js +56 -0
  65. package/js/tableLayouts.js +98 -0
  66. package/js/virtual-fs.js +60 -0
  67. package/package.json +94 -0
  68. package/src/3rd-party/svg-to-pdfkit/LICENSE +9 -0
  69. package/src/3rd-party/svg-to-pdfkit/source.js +2745 -0
  70. package/src/3rd-party/svg-to-pdfkit.js +3 -0
  71. package/src/DocMeasure.js +768 -0
  72. package/src/DocPreprocessor.js +289 -0
  73. package/src/DocumentContext.js +345 -0
  74. package/src/ElementWriter.js +468 -0
  75. package/src/LayoutBuilder.js +1366 -0
  76. package/src/Line.js +108 -0
  77. package/src/OutputDocument.js +64 -0
  78. package/src/OutputDocumentServer.js +32 -0
  79. package/src/PDFDocument.js +178 -0
  80. package/src/PageElementWriter.js +191 -0
  81. package/src/PageSize.js +53 -0
  82. package/src/Printer.js +306 -0
  83. package/src/Renderer.js +546 -0
  84. package/src/SVGMeasure.js +109 -0
  85. package/src/StyleContextStack.js +208 -0
  86. package/src/TableProcessor.js +620 -0
  87. package/src/TextBreaker.js +181 -0
  88. package/src/TextDecorator.js +175 -0
  89. package/src/TextInlines.js +229 -0
  90. package/src/URLResolver.js +43 -0
  91. package/src/base.js +70 -0
  92. package/src/browser-extensions/OutputDocumentBrowser.js +80 -0
  93. package/src/browser-extensions/fonts/Roboto.js +27 -0
  94. package/src/browser-extensions/index.js +55 -0
  95. package/src/browser-extensions/pdfMake.js +1 -0
  96. package/src/browser-extensions/standard-fonts/Courier.js +27 -0
  97. package/src/browser-extensions/standard-fonts/Helvetica.js +27 -0
  98. package/src/browser-extensions/standard-fonts/Symbol.js +21 -0
  99. package/src/browser-extensions/standard-fonts/Times.js +27 -0
  100. package/src/browser-extensions/standard-fonts/ZapfDingbats.js +21 -0
  101. package/src/browser-extensions/virtual-fs-cjs.js +1 -0
  102. package/src/columnCalculator.js +154 -0
  103. package/src/helpers/node.js +134 -0
  104. package/src/helpers/tools.js +44 -0
  105. package/src/helpers/variableType.js +50 -0
  106. package/src/index.js +16 -0
  107. package/src/qrEnc.js +796 -0
  108. package/src/standardPageSizes.js +52 -0
  109. package/src/tableLayouts.js +100 -0
  110. package/src/virtual-fs.js +66 -0
  111. package/standard-fonts/Courier.js +8 -0
  112. package/standard-fonts/Helvetica.js +8 -0
  113. package/standard-fonts/Symbol.js +5 -0
  114. package/standard-fonts/Times.js +8 -0
  115. package/standard-fonts/ZapfDingbats.js +5 -0
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+ var _OutputDocument = _interopRequireDefault(require("../OutputDocument"));
6
+ var _fileSaver = require("file-saver");
7
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
8
+ /**
9
+ * @returns {Window}
10
+ */
11
+ const openWindow = () => {
12
+ // we have to open the window immediately and store the reference
13
+ // otherwise popup blockers will stop us
14
+ let win = window.open('', '_blank');
15
+ if (win === null) {
16
+ throw new Error('Open PDF in new window blocked by browser');
17
+ }
18
+ return win;
19
+ };
20
+ class OutputDocumentBrowser extends _OutputDocument.default {
21
+ /**
22
+ * @returns {Promise<Blob>}
23
+ */
24
+ async getBlob() {
25
+ const buffer = await this.getBuffer();
26
+ return new Blob([buffer], {
27
+ type: 'application/pdf'
28
+ });
29
+ }
30
+
31
+ /**
32
+ * @param {string} filename
33
+ * @returns {Promise}
34
+ */
35
+ async download(filename = 'file.pdf') {
36
+ const blob = await this.getBlob();
37
+ (0, _fileSaver.saveAs)(blob, filename);
38
+ }
39
+
40
+ /**
41
+ * @param {Window} win
42
+ * @returns {Promise}
43
+ */
44
+ async open(win = null) {
45
+ if (!win) {
46
+ win = openWindow();
47
+ }
48
+ const blob = await this.getBlob();
49
+ try {
50
+ let urlCreator = window.URL || window.webkitURL;
51
+ let pdfUrl = urlCreator.createObjectURL(blob);
52
+ win.location.href = pdfUrl;
53
+
54
+ /* temporarily disabled
55
+ if (win === window) {
56
+ return;
57
+ } else {
58
+ setTimeout(() => {
59
+ if (win.window === null) { // is closed by AdBlock
60
+ window.location.href = pdfUrl; // open in actual window
61
+ }
62
+ return;
63
+ }, 500);
64
+ }
65
+ */
66
+ } catch (e) {
67
+ win.close();
68
+ throw e;
69
+ }
70
+ }
71
+
72
+ /**
73
+ * @param {Window} win
74
+ * @returns {Promise}
75
+ */
76
+ async print(win = null) {
77
+ const stream = await this.getStream();
78
+ stream.setOpenActionAsPrint();
79
+ await this.open(win);
80
+ }
81
+ }
82
+ var _default = exports.default = OutputDocumentBrowser;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ var fs = require('fs');
4
+ var fontContainer = {
5
+ vfs: {
6
+ 'Roboto-Regular.ttf': {
7
+ data: fs.readFileSync(__dirname + '/../../../fonts/Roboto/Roboto-Regular.ttf', 'base64'),
8
+ encoding: 'base64'
9
+ },
10
+ 'Roboto-Medium.ttf': {
11
+ data: fs.readFileSync(__dirname + '/../../../fonts/Roboto/Roboto-Medium.ttf', 'base64'),
12
+ encoding: 'base64'
13
+ },
14
+ 'Roboto-Italic.ttf': {
15
+ data: fs.readFileSync(__dirname + '/../../../fonts/Roboto/Roboto-Italic.ttf', 'base64'),
16
+ encoding: 'base64'
17
+ },
18
+ 'Roboto-MediumItalic.ttf': {
19
+ data: fs.readFileSync(__dirname + '/../../../fonts/Roboto/Roboto-MediumItalic.ttf', 'base64'),
20
+ encoding: 'base64'
21
+ }
22
+ },
23
+ fonts: {
24
+ Roboto: {
25
+ normal: 'Roboto-Regular.ttf',
26
+ bold: 'Roboto-Medium.ttf',
27
+ italics: 'Roboto-Italic.ttf',
28
+ bolditalics: 'Roboto-MediumItalic.ttf'
29
+ }
30
+ }
31
+ };
32
+ var _global = typeof window === 'object' ? window : typeof global === 'object' ? global : typeof self === 'object' ? self : void 0;
33
+ if (typeof _global.pdfMake !== 'undefined' && typeof _global.pdfMake.addFontContainer !== 'undefined') {
34
+ _global.pdfMake.addFontContainer(fontContainer);
35
+ }
36
+ if (typeof module !== 'undefined') {
37
+ module.exports = fontContainer;
38
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+ var _base = _interopRequireDefault(require("../base"));
6
+ var _OutputDocumentBrowser = _interopRequireDefault(require("./OutputDocumentBrowser"));
7
+ var _URLResolver = _interopRequireDefault(require("../URLResolver"));
8
+ var _fs = _interopRequireDefault(require("fs"));
9
+ var _configurator = _interopRequireDefault(require("core-js/configurator"));
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ // core-js: Polyfills will be used only if natives completely unavailable.
12
+ (0, _configurator.default)({
13
+ useNative: ['Promise']
14
+ });
15
+ let defaultClientFonts = {
16
+ Roboto: {
17
+ normal: 'Roboto-Regular.ttf',
18
+ bold: 'Roboto-Medium.ttf',
19
+ italics: 'Roboto-Italic.ttf',
20
+ bolditalics: 'Roboto-MediumItalic.ttf'
21
+ }
22
+ };
23
+ class pdfmake extends _base.default {
24
+ constructor() {
25
+ super();
26
+ this.urlResolver = () => new _URLResolver.default(this.virtualfs);
27
+ this.fonts = defaultClientFonts;
28
+ }
29
+ addFontContainer(fontContainer) {
30
+ this.addVirtualFileSystem(fontContainer.vfs);
31
+ this.addFonts(fontContainer.fonts);
32
+ }
33
+ addVirtualFileSystem(vfs) {
34
+ for (let key in vfs) {
35
+ if (vfs.hasOwnProperty(key)) {
36
+ let data;
37
+ let encoding;
38
+ if (typeof vfs[key] === 'object') {
39
+ data = vfs[key].data;
40
+ encoding = vfs[key].encoding || 'base64';
41
+ } else {
42
+ data = vfs[key];
43
+ encoding = 'base64';
44
+ }
45
+ _fs.default.writeFileSync(key, data, encoding);
46
+ }
47
+ }
48
+ }
49
+ _transformToDocument(doc) {
50
+ return new _OutputDocumentBrowser.default(doc);
51
+ }
52
+ }
53
+ var _default = exports.default = new pdfmake();
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+
3
+ module.exports = require('./index').default;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ var fs = require('fs');
4
+ var fontContainer = {
5
+ vfs: {
6
+ 'data/Courier.afm': {
7
+ data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Courier.afm', 'utf8'),
8
+ encoding: 'utf8'
9
+ },
10
+ 'data/Courier-Bold.afm': {
11
+ data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Courier-Bold.afm', 'utf8'),
12
+ encoding: 'utf8'
13
+ },
14
+ 'data/Courier-Oblique.afm': {
15
+ data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Courier-Oblique.afm', 'utf8'),
16
+ encoding: 'utf8'
17
+ },
18
+ 'data/Courier-BoldOblique.afm': {
19
+ data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Courier-BoldOblique.afm', 'utf8'),
20
+ encoding: 'utf8'
21
+ }
22
+ },
23
+ fonts: {
24
+ Courier: {
25
+ normal: 'Courier',
26
+ bold: 'Courier-Bold',
27
+ italics: 'Courier-Oblique',
28
+ bolditalics: 'Courier-BoldOblique'
29
+ }
30
+ }
31
+ };
32
+ var _global = typeof window === 'object' ? window : typeof global === 'object' ? global : typeof self === 'object' ? self : void 0;
33
+ if (typeof _global.pdfMake !== 'undefined' && typeof _global.pdfMake.addFontContainer !== 'undefined') {
34
+ _global.pdfMake.addFontContainer(fontContainer);
35
+ }
36
+ if (typeof module !== 'undefined') {
37
+ module.exports = fontContainer;
38
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ var fs = require('fs');
4
+ var fontContainer = {
5
+ vfs: {
6
+ 'data/Helvetica.afm': {
7
+ data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Helvetica.afm', 'utf8'),
8
+ encoding: 'utf8'
9
+ },
10
+ 'data/Helvetica-Bold.afm': {
11
+ data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Helvetica-Bold.afm', 'utf8'),
12
+ encoding: 'utf8'
13
+ },
14
+ 'data/Helvetica-Oblique.afm': {
15
+ data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Helvetica-Oblique.afm', 'utf8'),
16
+ encoding: 'utf8'
17
+ },
18
+ 'data/Helvetica-BoldOblique.afm': {
19
+ data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Helvetica-BoldOblique.afm', 'utf8'),
20
+ encoding: 'utf8'
21
+ }
22
+ },
23
+ fonts: {
24
+ Helvetica: {
25
+ normal: 'Helvetica',
26
+ bold: 'Helvetica-Bold',
27
+ italics: 'Helvetica-Oblique',
28
+ bolditalics: 'Helvetica-BoldOblique'
29
+ }
30
+ }
31
+ };
32
+ var _global = typeof window === 'object' ? window : typeof global === 'object' ? global : typeof self === 'object' ? self : void 0;
33
+ if (typeof _global.pdfMake !== 'undefined' && typeof _global.pdfMake.addFontContainer !== 'undefined') {
34
+ _global.pdfMake.addFontContainer(fontContainer);
35
+ }
36
+ if (typeof module !== 'undefined') {
37
+ module.exports = fontContainer;
38
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ var fs = require('fs');
4
+ var fontContainer = {
5
+ vfs: {
6
+ 'data/Symbol.afm': {
7
+ data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Symbol.afm', 'utf8'),
8
+ encoding: 'utf8'
9
+ }
10
+ },
11
+ fonts: {
12
+ Symbol: {
13
+ normal: 'Symbol'
14
+ }
15
+ }
16
+ };
17
+ var _global = typeof window === 'object' ? window : typeof global === 'object' ? global : typeof self === 'object' ? self : void 0;
18
+ if (typeof _global.pdfMake !== 'undefined' && typeof _global.pdfMake.addFontContainer !== 'undefined') {
19
+ _global.pdfMake.addFontContainer(fontContainer);
20
+ }
21
+ if (typeof module !== 'undefined') {
22
+ module.exports = fontContainer;
23
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ var fs = require('fs');
4
+ var fontContainer = {
5
+ vfs: {
6
+ 'data/Times-Roman.afm': {
7
+ data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Times-Roman.afm', 'utf8'),
8
+ encoding: 'utf8'
9
+ },
10
+ 'data/Times-Bold.afm': {
11
+ data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Times-Bold.afm', 'utf8'),
12
+ encoding: 'utf8'
13
+ },
14
+ 'data/Times-Italic.afm': {
15
+ data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Times-Italic.afm', 'utf8'),
16
+ encoding: 'utf8'
17
+ },
18
+ 'data/Times-BoldItalic.afm': {
19
+ data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Times-BoldItalic.afm', 'utf8'),
20
+ encoding: 'utf8'
21
+ }
22
+ },
23
+ fonts: {
24
+ Times: {
25
+ normal: 'Times-Roman',
26
+ bold: 'Times-Bold',
27
+ italics: 'Times-Italic',
28
+ bolditalics: 'Times-BoldItalic'
29
+ }
30
+ }
31
+ };
32
+ var _global = typeof window === 'object' ? window : typeof global === 'object' ? global : typeof self === 'object' ? self : void 0;
33
+ if (typeof _global.pdfMake !== 'undefined' && typeof _global.pdfMake.addFontContainer !== 'undefined') {
34
+ _global.pdfMake.addFontContainer(fontContainer);
35
+ }
36
+ if (typeof module !== 'undefined') {
37
+ module.exports = fontContainer;
38
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ var fs = require('fs');
4
+ var fontContainer = {
5
+ vfs: {
6
+ 'data/ZapfDingbats.afm': {
7
+ data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/ZapfDingbats.afm', 'utf8'),
8
+ encoding: 'utf8'
9
+ }
10
+ },
11
+ fonts: {
12
+ ZapfDingbats: {
13
+ normal: 'ZapfDingbats'
14
+ }
15
+ }
16
+ };
17
+ var _global = typeof window === 'object' ? window : typeof global === 'object' ? global : typeof self === 'object' ? self : void 0;
18
+ if (typeof _global.pdfMake !== 'undefined' && typeof _global.pdfMake.addFontContainer !== 'undefined') {
19
+ _global.pdfMake.addFontContainer(fontContainer);
20
+ }
21
+ if (typeof module !== 'undefined') {
22
+ module.exports = fontContainer;
23
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+
3
+ module.exports = require('../virtual-fs').default;
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+ var _variableType = require("./helpers/variableType");
6
+ function buildColumnWidths(columns, availableWidth, offsetTotal = 0, tableNode) {
7
+ let autoColumns = [];
8
+ let autoMin = 0;
9
+ let autoMax = 0;
10
+ let starColumns = [];
11
+ let starMaxMin = 0;
12
+ let starMaxMax = 0;
13
+ let fixedColumns = [];
14
+ let initial_availableWidth = availableWidth;
15
+ columns.forEach(column => {
16
+ if (isAutoColumn(column)) {
17
+ autoColumns.push(column);
18
+ autoMin += column._minWidth;
19
+ autoMax += column._maxWidth;
20
+ } else if (isStarColumn(column)) {
21
+ starColumns.push(column);
22
+ starMaxMin = Math.max(starMaxMin, column._minWidth);
23
+ starMaxMax = Math.max(starMaxMax, column._maxWidth);
24
+ } else {
25
+ fixedColumns.push(column);
26
+ }
27
+ });
28
+ fixedColumns.forEach((col, colIndex) => {
29
+ // width specified as %
30
+ if ((0, _variableType.isString)(col.width) && /\d+%/.test(col.width)) {
31
+ // In tables we have to take into consideration the reserved width for paddings and borders
32
+ let reservedWidth = 0;
33
+ if (tableNode) {
34
+ const paddingLeft = tableNode._layout.paddingLeft(colIndex, tableNode);
35
+ const paddingRight = tableNode._layout.paddingRight(colIndex, tableNode);
36
+ const borderLeft = tableNode._layout.vLineWidth(colIndex, tableNode);
37
+ const borderRight = tableNode._layout.vLineWidth(colIndex + 1, tableNode);
38
+ if (colIndex === 0) {
39
+ // first column assumes whole borderLeft and half of border right
40
+ reservedWidth = paddingLeft + paddingRight + borderLeft + borderRight / 2;
41
+ } else if (colIndex === fixedColumns.length - 1) {
42
+ // last column assumes whole borderRight and half of border left
43
+ reservedWidth = paddingLeft + paddingRight + borderLeft / 2 + borderRight;
44
+ } else {
45
+ // Columns in the middle assume half of each border
46
+ reservedWidth = paddingLeft + paddingRight + borderLeft / 2 + borderRight / 2;
47
+ }
48
+ }
49
+ const totalAvailableWidth = initial_availableWidth + offsetTotal;
50
+ col.width = parseFloat(col.width) * totalAvailableWidth / 100 - reservedWidth;
51
+ }
52
+ if (col.width < col._minWidth && col.elasticWidth) {
53
+ col._calcWidth = col._minWidth;
54
+ } else {
55
+ col._calcWidth = col.width;
56
+ }
57
+ availableWidth -= col._calcWidth;
58
+ });
59
+
60
+ // http://www.freesoft.org/CIE/RFC/1942/18.htm
61
+ // http://www.w3.org/TR/CSS2/tables.html#width-layout
62
+ // http://dev.w3.org/csswg/css3-tables-algorithms/Overview.src.htm
63
+ let minW = autoMin + starMaxMin * starColumns.length;
64
+ let maxW = autoMax + starMaxMax * starColumns.length;
65
+ if (minW >= availableWidth) {
66
+ // case 1 - there's no way to fit all columns within available width
67
+ // that's actually pretty bad situation with PDF as we have no horizontal scroll
68
+ // no easy workaround (unless we decide, in the future, to split single words)
69
+ // currently we simply use minWidths for all columns
70
+ autoColumns.forEach(col => {
71
+ col._calcWidth = col._minWidth;
72
+ });
73
+ starColumns.forEach(col => {
74
+ col._calcWidth = starMaxMin; // starMaxMin already contains padding
75
+ });
76
+ } else {
77
+ if (maxW < availableWidth) {
78
+ // case 2 - we can fit rest of the table within available space
79
+ autoColumns.forEach(col => {
80
+ col._calcWidth = col._maxWidth;
81
+ availableWidth -= col._calcWidth;
82
+ });
83
+ } else {
84
+ // maxW is too large, but minW fits within available width
85
+ let W = availableWidth - minW;
86
+ let D = maxW - minW;
87
+ autoColumns.forEach(col => {
88
+ let d = col._maxWidth - col._minWidth;
89
+ col._calcWidth = col._minWidth + d * W / D;
90
+ availableWidth -= col._calcWidth;
91
+ });
92
+ }
93
+ if (starColumns.length > 0) {
94
+ let starSize = availableWidth / starColumns.length;
95
+ starColumns.forEach(col => {
96
+ col._calcWidth = starSize;
97
+ });
98
+ }
99
+ }
100
+ }
101
+ function isAutoColumn(column) {
102
+ return column.width === 'auto';
103
+ }
104
+ function isStarColumn(column) {
105
+ return column.width === null || column.width === undefined || column.width === '*' || column.width === 'star';
106
+ }
107
+
108
+ //TODO: refactor and reuse in measureTable
109
+ function measureMinMax(columns) {
110
+ let result = {
111
+ min: 0,
112
+ max: 0
113
+ };
114
+ let maxStar = {
115
+ min: 0,
116
+ max: 0
117
+ };
118
+ let starCount = 0;
119
+ for (let i = 0, l = columns.length; i < l; i++) {
120
+ let c = columns[i];
121
+ if (isStarColumn(c)) {
122
+ maxStar.min = Math.max(maxStar.min, c._minWidth);
123
+ maxStar.max = Math.max(maxStar.max, c._maxWidth);
124
+ starCount++;
125
+ } else if (isAutoColumn(c)) {
126
+ result.min += c._minWidth;
127
+ result.max += c._maxWidth;
128
+ } else {
129
+ result.min += c.width !== undefined && c.width || c._minWidth;
130
+ result.max += c.width !== undefined && c.width || c._maxWidth;
131
+ }
132
+ }
133
+ if (starCount) {
134
+ result.min += starCount * maxStar.min;
135
+ result.max += starCount * maxStar.max;
136
+ }
137
+ return result;
138
+ }
139
+
140
+ /**
141
+ * Calculates column widths
142
+ */
143
+ var _default = exports.default = {
144
+ buildColumnWidths: buildColumnWidths,
145
+ measureMinMax: measureMinMax,
146
+ isAutoColumn: isAutoColumn,
147
+ isStarColumn: isStarColumn
148
+ };
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.getNodeId = getNodeId;
5
+ exports.getNodeMargin = getNodeMargin;
6
+ exports.stringifyNode = stringifyNode;
7
+ var _variableType = require("./variableType");
8
+ function fontStringify(key, val) {
9
+ if (key === 'font') {
10
+ return 'font';
11
+ }
12
+ return val;
13
+ }
14
+
15
+ /**
16
+ * Convert node to readable string
17
+ *
18
+ * @param {object} node
19
+ * @returns {string}
20
+ */
21
+ function stringifyNode(node) {
22
+ return JSON.stringify(node, fontStringify);
23
+ }
24
+
25
+ /**
26
+ * @param {object} node
27
+ * @returns {?string}
28
+ */
29
+ function getNodeId(node) {
30
+ if (node.id) {
31
+ return node.id;
32
+ }
33
+ if (Array.isArray(node.text)) {
34
+ for (let n of node.text) {
35
+ let nodeId = getNodeId(n);
36
+ if (nodeId) {
37
+ return nodeId;
38
+ }
39
+ }
40
+ }
41
+ return null;
42
+ }
43
+
44
+ /**
45
+ * @param {object} node
46
+ * @param {object} styleStack object is instance of PDFDocument
47
+ * @returns {?Array}
48
+ */
49
+ function getNodeMargin(node, styleStack) {
50
+ function processSingleMargins(node, currentMargin, defaultMargin = 0) {
51
+ if (node.marginLeft !== undefined || node.marginTop !== undefined || node.marginRight !== undefined || node.marginBottom !== undefined) {
52
+ return [node.marginLeft ?? currentMargin[0] ?? defaultMargin, node.marginTop ?? currentMargin[1] ?? defaultMargin, node.marginRight ?? currentMargin[2] ?? defaultMargin, node.marginBottom ?? currentMargin[3] ?? defaultMargin];
53
+ }
54
+ return currentMargin;
55
+ }
56
+ function flattenStyleArray(styleArray, styleStack, visited = new Set()) {
57
+ styleArray = Array.isArray(styleArray) ? styleArray : [styleArray];
58
+
59
+ // style is not valid array of strings
60
+ if (!styleArray.every(item => (0, _variableType.isString)(item))) {
61
+ return {};
62
+ }
63
+ let flattenedStyles = {};
64
+ for (let index = 0; index < styleArray.length; index++) {
65
+ let styleName = styleArray[index];
66
+ let style = styleStack.styleDictionary[styleName];
67
+
68
+ // style not found
69
+ if (style === undefined) {
70
+ continue;
71
+ }
72
+ if (visited.has(styleName)) {
73
+ continue;
74
+ }
75
+ if (style.extends !== undefined) {
76
+ flattenedStyles = {
77
+ ...flattenedStyles,
78
+ ...flattenStyleArray(style.extends, styleStack, new Set([...visited, styleName]))
79
+ };
80
+ }
81
+ if (style.margin !== undefined) {
82
+ flattenedStyles = {
83
+ margin: convertMargin(style.margin)
84
+ };
85
+ continue;
86
+ }
87
+ flattenedStyles = {
88
+ margin: processSingleMargins(style, flattenedStyles.margin ?? {}, undefined)
89
+ };
90
+ }
91
+ return flattenedStyles;
92
+ }
93
+ function convertMargin(margin) {
94
+ if ((0, _variableType.isNumber)(margin)) {
95
+ margin = [margin, margin, margin, margin];
96
+ } else if (Array.isArray(margin)) {
97
+ if (margin.length === 2) {
98
+ margin = [margin[0], margin[1], margin[0], margin[1]];
99
+ }
100
+ }
101
+ return margin;
102
+ }
103
+ let margin = [undefined, undefined, undefined, undefined];
104
+ if (node.style) {
105
+ let styleArray = Array.isArray(node.style) ? node.style : [node.style];
106
+ let flattenedStyleArray = flattenStyleArray(styleArray, styleStack);
107
+ if (flattenedStyleArray) {
108
+ margin = processSingleMargins(flattenedStyleArray, margin);
109
+ }
110
+ if (flattenedStyleArray.margin) {
111
+ margin = convertMargin(flattenedStyleArray.margin);
112
+ }
113
+ }
114
+ margin = processSingleMargins(node, margin);
115
+ if (node.margin !== undefined) {
116
+ margin = convertMargin(node.margin);
117
+ }
118
+ if (margin[0] === undefined && margin[1] === undefined && margin[2] === undefined && margin[3] === undefined) {
119
+ return null;
120
+ }
121
+ return margin;
122
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.convertToDynamicContent = convertToDynamicContent;
5
+ exports.offsetVector = offsetVector;
6
+ exports.pack = pack;
7
+ function pack(...args) {
8
+ let result = {};
9
+ for (let i = 0, l = args.length; i < l; i++) {
10
+ let obj = args[i];
11
+ if (obj) {
12
+ for (let key in obj) {
13
+ if (obj.hasOwnProperty(key)) {
14
+ result[key] = obj[key];
15
+ }
16
+ }
17
+ }
18
+ }
19
+ return result;
20
+ }
21
+ function offsetVector(vector, x, y) {
22
+ switch (vector.type) {
23
+ case 'ellipse':
24
+ case 'rect':
25
+ vector.x += x;
26
+ vector.y += y;
27
+ break;
28
+ case 'line':
29
+ vector.x1 += x;
30
+ vector.x2 += x;
31
+ vector.y1 += y;
32
+ vector.y2 += y;
33
+ break;
34
+ case 'polyline':
35
+ for (let i = 0, l = vector.points.length; i < l; i++) {
36
+ vector.points[i].x += x;
37
+ vector.points[i].y += y;
38
+ }
39
+ break;
40
+ }
41
+ }
42
+ function convertToDynamicContent(staticContent) {
43
+ return () =>
44
+ // copy to new object
45
+ JSON.parse(JSON.stringify(staticContent));
46
+ }