pdfmake 0.3.0-beta.8 → 0.3.0-beta.9

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 (56) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/build/pdfmake.js +74624 -74535
  3. package/build/pdfmake.js.map +1 -1
  4. package/build/pdfmake.min.js +2 -2
  5. package/build/pdfmake.min.js.map +1 -1
  6. package/js/3rd-party/svg-to-pdfkit/source.js +3626 -0
  7. package/js/3rd-party/svg-to-pdfkit.js +7 -0
  8. package/js/DocMeasure.js +626 -0
  9. package/js/DocPreprocessor.js +238 -0
  10. package/js/DocumentContext.js +258 -0
  11. package/js/ElementWriter.js +331 -0
  12. package/js/LayoutBuilder.js +744 -0
  13. package/js/Line.js +105 -0
  14. package/js/OutputDocument.js +76 -0
  15. package/js/OutputDocumentServer.js +27 -0
  16. package/js/PDFDocument.js +144 -0
  17. package/js/PageElementWriter.js +140 -0
  18. package/js/PageSize.js +74 -0
  19. package/js/Printer.js +291 -0
  20. package/js/Renderer.js +375 -0
  21. package/js/SVGMeasure.js +69 -0
  22. package/js/StyleContextStack.js +164 -0
  23. package/js/TableProcessor.js +522 -0
  24. package/js/TextBreaker.js +139 -0
  25. package/js/TextDecorator.js +143 -0
  26. package/js/TextInlines.js +206 -0
  27. package/js/URLResolver.js +73 -0
  28. package/js/base.js +52 -0
  29. package/js/browser-extensions/OutputDocumentBrowser.js +118 -0
  30. package/js/browser-extensions/URLBrowserResolver.js +76 -0
  31. package/js/browser-extensions/fonts/Roboto.js +38 -0
  32. package/js/browser-extensions/index.js +53 -0
  33. package/js/browser-extensions/pdfMake.js +15 -0
  34. package/js/browser-extensions/standard-fonts/Courier.js +38 -0
  35. package/js/browser-extensions/standard-fonts/Helvetica.js +38 -0
  36. package/js/browser-extensions/standard-fonts/Symbol.js +23 -0
  37. package/js/browser-extensions/standard-fonts/Times.js +38 -0
  38. package/js/browser-extensions/standard-fonts/ZapfDingbats.js +23 -0
  39. package/js/browser-extensions/virtual-fs-cjs.js +3 -0
  40. package/js/columnCalculator.js +148 -0
  41. package/js/helpers/node.js +98 -0
  42. package/js/helpers/tools.js +40 -0
  43. package/js/helpers/variableType.js +59 -0
  44. package/js/index.js +15 -0
  45. package/js/qrEnc.js +721 -0
  46. package/js/standardPageSizes.js +56 -0
  47. package/js/tableLayouts.js +98 -0
  48. package/js/virtual-fs.js +60 -0
  49. package/package.json +1 -1
  50. package/src/DocMeasure.js +7 -6
  51. package/src/DocumentContext.js +6 -13
  52. package/src/LayoutBuilder.js +52 -2
  53. package/src/StyleContextStack.js +3 -44
  54. package/src/TableProcessor.js +22 -6
  55. package/src/columnCalculator.js +24 -3
  56. package/src/helpers/variableType.js +11 -0
@@ -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 _URLBrowserResolver = _interopRequireDefault(require("./URLBrowserResolver"));
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 _URLBrowserResolver.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,15 @@
1
+ "use strict";
2
+
3
+ const isBrowserSupported = () => {
4
+ if (typeof window === 'undefined' || typeof window.navigator === 'undefined') {
5
+ // Enviroment is not browser.
6
+ return true;
7
+ }
8
+
9
+ // Internet Explorer 10 and older is not supported.
10
+ return window.navigator.userAgent.indexOf("MSIE") === -1;
11
+ };
12
+ if (!isBrowserSupported()) {
13
+ throw new Error('pdfmake: Internet Explorer 10 and older is not supported. Upgrade to version 11 or use modern browser.');
14
+ }
15
+ 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/@foliojs-fork/pdfkit/js/data/Courier.afm', 'utf8'),
8
+ encoding: 'utf8'
9
+ },
10
+ 'data/Courier-Bold.afm': {
11
+ data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Courier-Bold.afm', 'utf8'),
12
+ encoding: 'utf8'
13
+ },
14
+ 'data/Courier-Oblique.afm': {
15
+ data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Courier-Oblique.afm', 'utf8'),
16
+ encoding: 'utf8'
17
+ },
18
+ 'data/Courier-BoldOblique.afm': {
19
+ data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/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/@foliojs-fork/pdfkit/js/data/Helvetica.afm', 'utf8'),
8
+ encoding: 'utf8'
9
+ },
10
+ 'data/Helvetica-Bold.afm': {
11
+ data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Helvetica-Bold.afm', 'utf8'),
12
+ encoding: 'utf8'
13
+ },
14
+ 'data/Helvetica-Oblique.afm': {
15
+ data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Helvetica-Oblique.afm', 'utf8'),
16
+ encoding: 'utf8'
17
+ },
18
+ 'data/Helvetica-BoldOblique.afm': {
19
+ data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/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/@foliojs-fork/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/@foliojs-fork/pdfkit/js/data/Times-Roman.afm', 'utf8'),
8
+ encoding: 'utf8'
9
+ },
10
+ 'data/Times-Bold.afm': {
11
+ data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Times-Bold.afm', 'utf8'),
12
+ encoding: 'utf8'
13
+ },
14
+ 'data/Times-Italic.afm': {
15
+ data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Times-Italic.afm', 'utf8'),
16
+ encoding: 'utf8'
17
+ },
18
+ 'data/Times-BoldItalic.afm': {
19
+ data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/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/@foliojs-fork/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,98 @@
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) {
51
+ if (node.marginLeft || node.marginTop || node.marginRight || node.marginBottom) {
52
+ return [node.marginLeft || currentMargin[0] || 0, node.marginTop || currentMargin[1] || 0, node.marginRight || currentMargin[2] || 0, node.marginBottom || currentMargin[3] || 0];
53
+ }
54
+ return currentMargin;
55
+ }
56
+ function flattenStyleArray(styleArray, styleStack) {
57
+ let flattenedStyles = {};
58
+ for (let i = styleArray.length - 1; i >= 0; i--) {
59
+ let styleName = styleArray[i];
60
+ let style = styleStack.styleDictionary[styleName];
61
+ for (let key in style) {
62
+ if (style.hasOwnProperty(key)) {
63
+ flattenedStyles[key] = style[key];
64
+ }
65
+ }
66
+ }
67
+ return flattenedStyles;
68
+ }
69
+ function convertMargin(margin) {
70
+ if ((0, _variableType.isNumber)(margin)) {
71
+ margin = [margin, margin, margin, margin];
72
+ } else if (Array.isArray(margin)) {
73
+ if (margin.length === 2) {
74
+ margin = [margin[0], margin[1], margin[0], margin[1]];
75
+ }
76
+ }
77
+ return margin;
78
+ }
79
+ let margin = [undefined, undefined, undefined, undefined];
80
+ if (node.style) {
81
+ let styleArray = Array.isArray(node.style) ? node.style : [node.style];
82
+ let flattenedStyleArray = flattenStyleArray(styleArray, styleStack);
83
+ if (flattenedStyleArray) {
84
+ margin = processSingleMargins(flattenedStyleArray, margin);
85
+ }
86
+ if (flattenedStyleArray.margin) {
87
+ margin = convertMargin(flattenedStyleArray.margin);
88
+ }
89
+ }
90
+ margin = processSingleMargins(node, margin);
91
+ if (node.margin) {
92
+ margin = convertMargin(node.margin);
93
+ }
94
+ if (margin[0] === undefined && margin[1] === undefined && margin[2] === undefined && margin[3] === undefined) {
95
+ return null;
96
+ }
97
+ return margin;
98
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.offsetVector = offsetVector;
5
+ exports.pack = pack;
6
+ function pack(...args) {
7
+ let result = {};
8
+ for (let i = 0, l = args.length; i < l; i++) {
9
+ let obj = args[i];
10
+ if (obj) {
11
+ for (let key in obj) {
12
+ if (obj.hasOwnProperty(key)) {
13
+ result[key] = obj[key];
14
+ }
15
+ }
16
+ }
17
+ }
18
+ return result;
19
+ }
20
+ function offsetVector(vector, x, y) {
21
+ switch (vector.type) {
22
+ case 'ellipse':
23
+ case 'rect':
24
+ vector.x += x;
25
+ vector.y += y;
26
+ break;
27
+ case 'line':
28
+ vector.x1 += x;
29
+ vector.x2 += x;
30
+ vector.y1 += y;
31
+ vector.y2 += y;
32
+ break;
33
+ case 'polyline':
34
+ for (let i = 0, l = vector.points.length; i < l; i++) {
35
+ vector.points[i].x += x;
36
+ vector.points[i].y += y;
37
+ }
38
+ break;
39
+ }
40
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.isEmptyObject = isEmptyObject;
5
+ exports.isNumber = isNumber;
6
+ exports.isObject = isObject;
7
+ exports.isPositiveInteger = isPositiveInteger;
8
+ exports.isString = isString;
9
+ exports.isValue = isValue;
10
+ /**
11
+ * @param {any} variable
12
+ * @returns {boolean}
13
+ */
14
+ function isString(variable) {
15
+ return typeof variable === 'string' || variable instanceof String;
16
+ }
17
+
18
+ /**
19
+ * @param {any} variable
20
+ * @returns {boolean}
21
+ */
22
+ function isNumber(variable) {
23
+ return typeof variable === 'number' || variable instanceof Number;
24
+ }
25
+
26
+ /**
27
+ * @param {any} variable
28
+ * @returns {boolean}
29
+ */
30
+ function isPositiveInteger(variable) {
31
+ if (!isNumber(variable) || !Number.isInteger(variable) || variable <= 0) {
32
+ return false;
33
+ }
34
+ return true;
35
+ }
36
+
37
+ /**
38
+ * @param {any} variable
39
+ * @returns {boolean}
40
+ */
41
+ function isObject(variable) {
42
+ return variable !== null && !Array.isArray(variable) && !isString(variable) && !isNumber(variable) && typeof variable === 'object';
43
+ }
44
+
45
+ /**
46
+ * @param {any} variable
47
+ * @returns {boolean}
48
+ */
49
+ function isEmptyObject(variable) {
50
+ return isObject(variable) && Object.keys(variable).length === 0;
51
+ }
52
+
53
+ /**
54
+ * @param {any} variable
55
+ * @returns {boolean}
56
+ */
57
+ function isValue(variable) {
58
+ return variable !== undefined && variable !== null;
59
+ }
package/js/index.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ const pdfmakeBase = require('./base').default;
4
+ const OutputDocumentServer = require('./OutputDocumentServer').default;
5
+ const URLResolver = require('./URLResolver').default;
6
+ class pdfmake extends pdfmakeBase {
7
+ constructor() {
8
+ super();
9
+ this.urlResolver = new URLResolver(this.virtualfs);
10
+ }
11
+ _transformToDocument(doc) {
12
+ return new OutputDocumentServer(doc);
13
+ }
14
+ }
15
+ module.exports = new pdfmake();