pdfmake 0.2.1 → 0.3.0-beta.1

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 (130) hide show
  1. package/CHANGELOG.md +8 -14
  2. package/README.md +8 -6
  3. package/build/pdfmake.js +31416 -28217
  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 +3 -3
  14. package/fonts/Roboto/Roboto-Italic.ttf +0 -0
  15. package/fonts/Roboto/Roboto-Medium.ttf +0 -0
  16. package/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
  17. package/fonts/Roboto/Roboto-Regular.ttf +0 -0
  18. package/fonts/Roboto.js +8 -0
  19. package/js/3rd-party/svg-to-pdfkit/source.js +4301 -0
  20. package/js/3rd-party/svg-to-pdfkit.js +11 -0
  21. package/js/DocMeasure.js +750 -0
  22. package/js/DocPreprocessor.js +285 -0
  23. package/js/DocumentContext.js +306 -0
  24. package/js/ElementWriter.js +377 -0
  25. package/js/LayoutBuilder.js +833 -0
  26. package/js/Line.js +125 -0
  27. package/js/OutputDocument.js +86 -0
  28. package/js/OutputDocumentServer.js +34 -0
  29. package/js/PDFDocument.js +163 -0
  30. package/js/PageElementWriter.js +161 -0
  31. package/js/PageSize.js +88 -0
  32. package/js/Printer.js +238 -0
  33. package/js/Renderer.js +433 -0
  34. package/js/SVGMeasure.js +89 -0
  35. package/js/StyleContextStack.js +206 -0
  36. package/js/TableProcessor.js +590 -0
  37. package/js/TextBreaker.js +182 -0
  38. package/js/TextDecorator.js +181 -0
  39. package/js/TextInlines.js +248 -0
  40. package/js/URLResolver.js +79 -0
  41. package/js/base.js +69 -0
  42. package/js/browser-extensions/OutputDocumentBrowser.js +131 -0
  43. package/js/browser-extensions/URLBrowserResolver.js +89 -0
  44. package/js/browser-extensions/fonts/Roboto.js +42 -0
  45. package/js/browser-extensions/index.js +70 -0
  46. package/js/browser-extensions/pdfMake.js +17 -0
  47. package/js/browser-extensions/standard-fonts/Courier.js +42 -0
  48. package/js/browser-extensions/standard-fonts/Helvetica.js +42 -0
  49. package/js/browser-extensions/standard-fonts/Symbol.js +27 -0
  50. package/js/browser-extensions/standard-fonts/Times.js +42 -0
  51. package/js/browser-extensions/standard-fonts/ZapfDingbats.js +27 -0
  52. package/js/browser-extensions/virtual-fs-cjs.js +3 -0
  53. package/js/columnCalculator.js +142 -0
  54. package/js/helpers/node.js +122 -0
  55. package/js/helpers/tools.js +48 -0
  56. package/js/helpers/variableType.js +52 -0
  57. package/js/index.js +21 -0
  58. package/js/qrEnc.js +810 -0
  59. package/js/standardPageSizes.js +57 -0
  60. package/js/tableLayouts.js +127 -0
  61. package/js/virtual-fs.js +77 -0
  62. package/package.json +31 -25
  63. package/src/3rd-party/svg-to-pdfkit/LICENSE +9 -0
  64. package/src/3rd-party/svg-to-pdfkit/source.js +2552 -0
  65. package/src/3rd-party/svg-to-pdfkit.js +3 -0
  66. package/src/DocMeasure.js +694 -0
  67. package/src/DocPreprocessor.js +258 -0
  68. package/src/DocumentContext.js +309 -0
  69. package/src/ElementWriter.js +368 -0
  70. package/src/LayoutBuilder.js +814 -0
  71. package/src/Line.js +114 -0
  72. package/src/OutputDocument.js +78 -0
  73. package/src/OutputDocumentServer.js +26 -0
  74. package/src/PDFDocument.js +148 -0
  75. package/src/PageElementWriter.js +156 -0
  76. package/src/PageSize.js +53 -0
  77. package/src/Printer.js +220 -0
  78. package/src/Renderer.js +370 -0
  79. package/src/SVGMeasure.js +79 -0
  80. package/src/StyleContextStack.js +216 -0
  81. package/src/TableProcessor.js +558 -0
  82. package/src/TextBreaker.js +149 -0
  83. package/src/TextDecorator.js +161 -0
  84. package/src/TextInlines.js +223 -0
  85. package/src/URLResolver.js +69 -0
  86. package/src/base.js +61 -0
  87. package/src/browser-extensions/OutputDocumentBrowser.js +117 -0
  88. package/src/browser-extensions/URLBrowserResolver.js +46 -53
  89. package/src/browser-extensions/fonts/Roboto.js +27 -0
  90. package/src/browser-extensions/index.js +55 -0
  91. package/src/browser-extensions/pdfMake.js +10 -287
  92. package/src/browser-extensions/standard-fonts/Courier.js +27 -0
  93. package/src/browser-extensions/standard-fonts/Helvetica.js +27 -0
  94. package/src/browser-extensions/standard-fonts/Symbol.js +21 -0
  95. package/src/browser-extensions/standard-fonts/Times.js +27 -0
  96. package/src/browser-extensions/standard-fonts/ZapfDingbats.js +21 -0
  97. package/src/browser-extensions/virtual-fs-cjs.js +1 -0
  98. package/src/columnCalculator.js +29 -32
  99. package/src/helpers/node.js +110 -0
  100. package/src/helpers/tools.js +39 -0
  101. package/src/helpers/variableType.js +39 -0
  102. package/src/index.js +16 -0
  103. package/src/qrEnc.js +15 -10
  104. package/src/standardPageSizes.js +1 -3
  105. package/src/tableLayouts.js +100 -0
  106. package/src/virtual-fs.js +66 -0
  107. package/standard-fonts/Courier.js +8 -0
  108. package/standard-fonts/Helvetica.js +9 -0
  109. package/standard-fonts/Symbol.js +5 -0
  110. package/standard-fonts/Times.js +8 -0
  111. package/standard-fonts/ZapfDingbats.js +5 -0
  112. package/src/browser-extensions/virtual-fs.js +0 -55
  113. package/src/docMeasure.js +0 -807
  114. package/src/docPreprocessor.js +0 -255
  115. package/src/documentContext.js +0 -314
  116. package/src/elementWriter.js +0 -322
  117. package/src/fontProvider.js +0 -68
  118. package/src/helpers.js +0 -113
  119. package/src/imageMeasure.js +0 -51
  120. package/src/layoutBuilder.js +0 -807
  121. package/src/line.js +0 -91
  122. package/src/pageElementWriter.js +0 -174
  123. package/src/pdfKitEngine.js +0 -21
  124. package/src/printer.js +0 -685
  125. package/src/styleContextStack.js +0 -179
  126. package/src/svgMeasure.js +0 -70
  127. package/src/tableProcessor.js +0 -542
  128. package/src/textDecorator.js +0 -151
  129. package/src/textTools.js +0 -373
  130. package/src/traversalTracker.js +0 -47
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+
6
+ var _variableType = require("./helpers/variableType");
7
+
8
+ function buildColumnWidths(columns, availableWidth) {
9
+ let autoColumns = [];
10
+ let autoMin = 0;
11
+ let autoMax = 0;
12
+ let starColumns = [];
13
+ let starMaxMin = 0;
14
+ let starMaxMax = 0;
15
+ let fixedColumns = [];
16
+ let initial_availableWidth = availableWidth;
17
+ columns.forEach(column => {
18
+ if (isAutoColumn(column)) {
19
+ autoColumns.push(column);
20
+ autoMin += column._minWidth;
21
+ autoMax += column._maxWidth;
22
+ } else if (isStarColumn(column)) {
23
+ starColumns.push(column);
24
+ starMaxMin = Math.max(starMaxMin, column._minWidth);
25
+ starMaxMax = Math.max(starMaxMax, column._maxWidth);
26
+ } else {
27
+ fixedColumns.push(column);
28
+ }
29
+ });
30
+ fixedColumns.forEach(col => {
31
+ // width specified as %
32
+ if ((0, _variableType.isString)(col.width) && /\d+%/.test(col.width)) {
33
+ col.width = parseFloat(col.width) * initial_availableWidth / 100;
34
+ }
35
+
36
+ if (col.width < col._minWidth && col.elasticWidth) {
37
+ col._calcWidth = col._minWidth;
38
+ } else {
39
+ col._calcWidth = col.width;
40
+ }
41
+
42
+ availableWidth -= col._calcWidth;
43
+ }); // http://www.freesoft.org/CIE/RFC/1942/18.htm
44
+ // http://www.w3.org/TR/CSS2/tables.html#width-layout
45
+ // http://dev.w3.org/csswg/css3-tables-algorithms/Overview.src.htm
46
+
47
+ let minW = autoMin + starMaxMin * starColumns.length;
48
+ let maxW = autoMax + starMaxMax * starColumns.length;
49
+
50
+ if (minW >= availableWidth) {
51
+ // case 1 - there's no way to fit all columns within available width
52
+ // that's actually pretty bad situation with PDF as we have no horizontal scroll
53
+ // no easy workaround (unless we decide, in the future, to split single words)
54
+ // currently we simply use minWidths for all columns
55
+ autoColumns.forEach(col => {
56
+ col._calcWidth = col._minWidth;
57
+ });
58
+ starColumns.forEach(col => {
59
+ col._calcWidth = starMaxMin; // starMaxMin already contains padding
60
+ });
61
+ } else {
62
+ if (maxW < availableWidth) {
63
+ // case 2 - we can fit rest of the table within available space
64
+ autoColumns.forEach(col => {
65
+ col._calcWidth = col._maxWidth;
66
+ availableWidth -= col._calcWidth;
67
+ });
68
+ } else {
69
+ // maxW is too large, but minW fits within available width
70
+ let W = availableWidth - minW;
71
+ let D = maxW - minW;
72
+ autoColumns.forEach(col => {
73
+ let d = col._maxWidth - col._minWidth;
74
+ col._calcWidth = col._minWidth + d * W / D;
75
+ availableWidth -= col._calcWidth;
76
+ });
77
+ }
78
+
79
+ if (starColumns.length > 0) {
80
+ let starSize = availableWidth / starColumns.length;
81
+ starColumns.forEach(col => {
82
+ col._calcWidth = starSize;
83
+ });
84
+ }
85
+ }
86
+ }
87
+
88
+ function isAutoColumn(column) {
89
+ return column.width === 'auto';
90
+ }
91
+
92
+ function isStarColumn(column) {
93
+ return column.width === null || column.width === undefined || column.width === '*' || column.width === 'star';
94
+ } //TODO: refactor and reuse in measureTable
95
+
96
+
97
+ function measureMinMax(columns) {
98
+ let result = {
99
+ min: 0,
100
+ max: 0
101
+ };
102
+ let maxStar = {
103
+ min: 0,
104
+ max: 0
105
+ };
106
+ let starCount = 0;
107
+
108
+ for (let i = 0, l = columns.length; i < l; i++) {
109
+ let c = columns[i];
110
+
111
+ if (isStarColumn(c)) {
112
+ maxStar.min = Math.max(maxStar.min, c._minWidth);
113
+ maxStar.max = Math.max(maxStar.max, c._maxWidth);
114
+ starCount++;
115
+ } else if (isAutoColumn(c)) {
116
+ result.min += c._minWidth;
117
+ result.max += c._maxWidth;
118
+ } else {
119
+ result.min += c.width !== undefined && c.width || c._minWidth;
120
+ result.max += c.width !== undefined && c.width || c._maxWidth;
121
+ }
122
+ }
123
+
124
+ if (starCount) {
125
+ result.min += starCount * maxStar.min;
126
+ result.max += starCount * maxStar.max;
127
+ }
128
+
129
+ return result;
130
+ }
131
+ /**
132
+ * Calculates column widths
133
+ */
134
+
135
+
136
+ var _default = {
137
+ buildColumnWidths: buildColumnWidths,
138
+ measureMinMax: measureMinMax,
139
+ isAutoColumn: isAutoColumn,
140
+ isStarColumn: isStarColumn
141
+ };
142
+ exports.default = _default;
@@ -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
+
8
+ var _variableType = require("./variableType");
9
+
10
+ function fontStringify(key, val) {
11
+ if (key === 'font') {
12
+ return 'font';
13
+ }
14
+
15
+ return val;
16
+ }
17
+ /**
18
+ * Convert node to readable string
19
+ *
20
+ * @param {object} node
21
+ * @returns {string}
22
+ */
23
+
24
+
25
+ function stringifyNode(node) {
26
+ return JSON.stringify(node, fontStringify);
27
+ }
28
+ /**
29
+ * @param {object} node
30
+ * @returns {?string}
31
+ */
32
+
33
+
34
+ function getNodeId(node) {
35
+ if (node.id) {
36
+ return node.id;
37
+ }
38
+
39
+ if (Array.isArray(node.text)) {
40
+ for (let n of node.text) {
41
+ let nodeId = getNodeId(n);
42
+
43
+ if (nodeId) {
44
+ return nodeId;
45
+ }
46
+ }
47
+ }
48
+
49
+ return null;
50
+ }
51
+ /**
52
+ * @param {object} node
53
+ * @param {object} styleStack object is instance of PDFDocument
54
+ * @returns {?Array}
55
+ */
56
+
57
+
58
+ function getNodeMargin(node, styleStack) {
59
+ function processSingleMargins(node, currentMargin) {
60
+ if (node.marginLeft || node.marginTop || node.marginRight || node.marginBottom) {
61
+ return [node.marginLeft || currentMargin[0] || 0, node.marginTop || currentMargin[1] || 0, node.marginRight || currentMargin[2] || 0, node.marginBottom || currentMargin[3] || 0];
62
+ }
63
+
64
+ return currentMargin;
65
+ }
66
+
67
+ function flattenStyleArray(styleArray, styleStack) {
68
+ let flattenedStyles = {};
69
+
70
+ for (let i = styleArray.length - 1; i >= 0; i--) {
71
+ let styleName = styleArray[i];
72
+ let style = styleStack.styleDictionary[styleName];
73
+
74
+ for (let key in style) {
75
+ if (style.hasOwnProperty(key)) {
76
+ flattenedStyles[key] = style[key];
77
+ }
78
+ }
79
+ }
80
+
81
+ return flattenedStyles;
82
+ }
83
+
84
+ function convertMargin(margin) {
85
+ if ((0, _variableType.isNumber)(margin)) {
86
+ margin = [margin, margin, margin, margin];
87
+ } else if (Array.isArray(margin)) {
88
+ if (margin.length === 2) {
89
+ margin = [margin[0], margin[1], margin[0], margin[1]];
90
+ }
91
+ }
92
+
93
+ return margin;
94
+ }
95
+
96
+ let margin = [undefined, undefined, undefined, undefined];
97
+
98
+ if (node.style) {
99
+ let styleArray = Array.isArray(node.style) ? node.style : [node.style];
100
+ let flattenedStyleArray = flattenStyleArray(styleArray, styleStack);
101
+
102
+ if (flattenedStyleArray) {
103
+ margin = processSingleMargins(flattenedStyleArray, margin);
104
+ }
105
+
106
+ if (flattenedStyleArray.margin) {
107
+ margin = convertMargin(flattenedStyleArray.margin);
108
+ }
109
+ }
110
+
111
+ margin = processSingleMargins(node, margin);
112
+
113
+ if (node.margin) {
114
+ margin = convertMargin(node.margin);
115
+ }
116
+
117
+ if (margin[0] === undefined && margin[1] === undefined && margin[2] === undefined && margin[3] === undefined) {
118
+ return null;
119
+ }
120
+
121
+ return margin;
122
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.offsetVector = offsetVector;
5
+ exports.pack = pack;
6
+
7
+ function pack(...args) {
8
+ let result = {};
9
+
10
+ for (let i = 0, l = args.length; i < l; i++) {
11
+ let obj = args[i];
12
+
13
+ if (obj) {
14
+ for (let key in obj) {
15
+ if (obj.hasOwnProperty(key)) {
16
+ result[key] = obj[key];
17
+ }
18
+ }
19
+ }
20
+ }
21
+
22
+ return result;
23
+ }
24
+
25
+ function offsetVector(vector, x, y) {
26
+ switch (vector.type) {
27
+ case 'ellipse':
28
+ case 'rect':
29
+ vector.x += x;
30
+ vector.y += y;
31
+ break;
32
+
33
+ case 'line':
34
+ vector.x1 += x;
35
+ vector.x2 += x;
36
+ vector.y1 += y;
37
+ vector.y2 += y;
38
+ break;
39
+
40
+ case 'polyline':
41
+ for (let i = 0, l = vector.points.length; i < l; i++) {
42
+ vector.points[i].x += x;
43
+ vector.points[i].y += y;
44
+ }
45
+
46
+ break;
47
+ }
48
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.isEmptyObject = isEmptyObject;
5
+ exports.isNumber = isNumber;
6
+ exports.isObject = isObject;
7
+ exports.isString = isString;
8
+ exports.isValue = isValue;
9
+
10
+ /**
11
+ * @param {any} variable
12
+ * @returns {boolean}
13
+ */
14
+ function isString(variable) {
15
+ return typeof variable === 'string' || variable instanceof String;
16
+ }
17
+ /**
18
+ * @param {any} variable
19
+ * @returns {boolean}
20
+ */
21
+
22
+
23
+ function isNumber(variable) {
24
+ return typeof variable === 'number' || variable instanceof Number;
25
+ }
26
+ /**
27
+ * @param {any} variable
28
+ * @returns {boolean}
29
+ */
30
+
31
+
32
+ function isObject(variable) {
33
+ return variable !== null && !Array.isArray(variable) && !isString(variable) && !isNumber(variable) && typeof variable === 'object';
34
+ }
35
+ /**
36
+ * @param {any} variable
37
+ * @returns {boolean}
38
+ */
39
+
40
+
41
+ function isEmptyObject(variable) {
42
+ return isObject(variable) && Object.keys(variable).length === 0;
43
+ }
44
+ /**
45
+ * @param {any} variable
46
+ * @returns {boolean}
47
+ */
48
+
49
+
50
+ function isValue(variable) {
51
+ return variable !== undefined && variable !== null;
52
+ }
package/js/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ const pdfmakeBase = require('./base').default;
4
+
5
+ const OutputDocumentServer = require('./OutputDocumentServer').default;
6
+
7
+ const URLResolver = require('./URLResolver').default;
8
+
9
+ class pdfmake extends pdfmakeBase {
10
+ constructor() {
11
+ super();
12
+ this.urlResolver = new URLResolver(this.virtualfs);
13
+ }
14
+
15
+ _transformToDocument(doc) {
16
+ return new OutputDocumentServer(doc);
17
+ }
18
+
19
+ }
20
+
21
+ module.exports = new pdfmake();