pdfmake 0.3.0-beta.1 → 0.3.0-beta.11

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 (77) hide show
  1. package/.idea/workspace.xml +20 -0
  2. package/CHANGELOG.md +65 -1
  3. package/LICENSE +1 -1
  4. package/README.md +3 -1
  5. package/build/pdfmake.js +65069 -73247
  6. package/build/pdfmake.js.map +1 -1
  7. package/build/pdfmake.min.js +2 -2
  8. package/build/pdfmake.min.js.map +1 -1
  9. package/build/vfs_fonts.js +4 -4
  10. package/eslint.config.mjs +52 -0
  11. package/fonts/Roboto/Roboto-Italic.ttf +0 -0
  12. package/fonts/Roboto/Roboto-Medium.ttf +0 -0
  13. package/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
  14. package/fonts/Roboto/Roboto-Regular.ttf +0 -0
  15. package/js/3rd-party/svg-to-pdfkit/source.js +247 -922
  16. package/js/3rd-party/svg-to-pdfkit.js +2 -6
  17. package/js/DocMeasure.js +24 -148
  18. package/js/DocPreprocessor.js +8 -55
  19. package/js/DocumentContext.js +44 -62
  20. package/js/ElementWriter.js +42 -74
  21. package/js/LayoutBuilder.js +225 -177
  22. package/js/Line.js +7 -27
  23. package/js/OutputDocument.js +6 -16
  24. package/js/OutputDocumentServer.js +2 -9
  25. package/js/PDFDocument.js +24 -43
  26. package/js/PageElementWriter.js +14 -35
  27. package/js/PageSize.js +3 -17
  28. package/js/Printer.js +102 -49
  29. package/js/Renderer.js +37 -95
  30. package/js/SVGMeasure.js +3 -23
  31. package/js/StyleContextStack.js +13 -55
  32. package/js/TableProcessor.js +94 -136
  33. package/js/TextBreaker.js +4 -47
  34. package/js/TextDecorator.js +3 -41
  35. package/js/TextInlines.js +10 -52
  36. package/js/URLResolver.js +18 -24
  37. package/js/base.js +3 -20
  38. package/js/browser-extensions/OutputDocumentBrowser.js +7 -20
  39. package/js/browser-extensions/URLBrowserResolver.js +7 -20
  40. package/js/browser-extensions/fonts/Roboto.js +0 -4
  41. package/js/browser-extensions/index.js +2 -19
  42. package/js/browser-extensions/pdfMake.js +0 -14
  43. package/js/browser-extensions/standard-fonts/Courier.js +0 -4
  44. package/js/browser-extensions/standard-fonts/Helvetica.js +0 -4
  45. package/js/browser-extensions/standard-fonts/Symbol.js +0 -4
  46. package/js/browser-extensions/standard-fonts/Times.js +0 -4
  47. package/js/browser-extensions/standard-fonts/ZapfDingbats.js +0 -4
  48. package/js/columnCalculator.js +30 -24
  49. package/js/helpers/node.js +3 -27
  50. package/js/helpers/tools.js +0 -8
  51. package/js/helpers/variableType.js +15 -8
  52. package/js/index.js +0 -6
  53. package/js/qrEnc.js +133 -222
  54. package/js/standardPageSizes.js +2 -3
  55. package/js/tableLayouts.js +4 -33
  56. package/js/virtual-fs.js +4 -21
  57. package/package.json +25 -22
  58. package/src/DocMeasure.js +19 -6
  59. package/src/DocPreprocessor.js +6 -0
  60. package/src/DocumentContext.js +35 -20
  61. package/src/ElementWriter.js +45 -5
  62. package/src/LayoutBuilder.js +201 -18
  63. package/src/OutputDocument.js +1 -1
  64. package/src/PDFDocument.js +27 -1
  65. package/src/PageElementWriter.js +6 -2
  66. package/src/Printer.js +93 -7
  67. package/src/Renderer.js +35 -0
  68. package/src/StyleContextStack.js +3 -44
  69. package/src/TableProcessor.js +64 -20
  70. package/src/TextDecorator.js +1 -1
  71. package/src/URLResolver.js +16 -8
  72. package/src/browser-extensions/URLBrowserResolver.js +6 -3
  73. package/src/browser-extensions/index.js +1 -1
  74. package/src/browser-extensions/pdfMake.js +0 -14
  75. package/src/columnCalculator.js +24 -3
  76. package/src/helpers/variableType.js +11 -0
  77. package/src/qrEnc.js +5 -3
@@ -4,83 +4,68 @@ exports.__esModule = true;
4
4
  exports.getNodeId = getNodeId;
5
5
  exports.getNodeMargin = getNodeMargin;
6
6
  exports.stringifyNode = stringifyNode;
7
-
8
7
  var _variableType = require("./variableType");
9
-
10
8
  function fontStringify(key, val) {
11
9
  if (key === 'font') {
12
10
  return 'font';
13
11
  }
14
-
15
12
  return val;
16
13
  }
14
+
17
15
  /**
18
16
  * Convert node to readable string
19
17
  *
20
18
  * @param {object} node
21
19
  * @returns {string}
22
20
  */
23
-
24
-
25
21
  function stringifyNode(node) {
26
22
  return JSON.stringify(node, fontStringify);
27
23
  }
24
+
28
25
  /**
29
26
  * @param {object} node
30
27
  * @returns {?string}
31
28
  */
32
-
33
-
34
29
  function getNodeId(node) {
35
30
  if (node.id) {
36
31
  return node.id;
37
32
  }
38
-
39
33
  if (Array.isArray(node.text)) {
40
34
  for (let n of node.text) {
41
35
  let nodeId = getNodeId(n);
42
-
43
36
  if (nodeId) {
44
37
  return nodeId;
45
38
  }
46
39
  }
47
40
  }
48
-
49
41
  return null;
50
42
  }
43
+
51
44
  /**
52
45
  * @param {object} node
53
46
  * @param {object} styleStack object is instance of PDFDocument
54
47
  * @returns {?Array}
55
48
  */
56
-
57
-
58
49
  function getNodeMargin(node, styleStack) {
59
50
  function processSingleMargins(node, currentMargin) {
60
51
  if (node.marginLeft || node.marginTop || node.marginRight || node.marginBottom) {
61
52
  return [node.marginLeft || currentMargin[0] || 0, node.marginTop || currentMargin[1] || 0, node.marginRight || currentMargin[2] || 0, node.marginBottom || currentMargin[3] || 0];
62
53
  }
63
-
64
54
  return currentMargin;
65
55
  }
66
-
67
56
  function flattenStyleArray(styleArray, styleStack) {
68
57
  let flattenedStyles = {};
69
-
70
58
  for (let i = styleArray.length - 1; i >= 0; i--) {
71
59
  let styleName = styleArray[i];
72
60
  let style = styleStack.styleDictionary[styleName];
73
-
74
61
  for (let key in style) {
75
62
  if (style.hasOwnProperty(key)) {
76
63
  flattenedStyles[key] = style[key];
77
64
  }
78
65
  }
79
66
  }
80
-
81
67
  return flattenedStyles;
82
68
  }
83
-
84
69
  function convertMargin(margin) {
85
70
  if ((0, _variableType.isNumber)(margin)) {
86
71
  margin = [margin, margin, margin, margin];
@@ -89,34 +74,25 @@ function getNodeMargin(node, styleStack) {
89
74
  margin = [margin[0], margin[1], margin[0], margin[1]];
90
75
  }
91
76
  }
92
-
93
77
  return margin;
94
78
  }
95
-
96
79
  let margin = [undefined, undefined, undefined, undefined];
97
-
98
80
  if (node.style) {
99
81
  let styleArray = Array.isArray(node.style) ? node.style : [node.style];
100
82
  let flattenedStyleArray = flattenStyleArray(styleArray, styleStack);
101
-
102
83
  if (flattenedStyleArray) {
103
84
  margin = processSingleMargins(flattenedStyleArray, margin);
104
85
  }
105
-
106
86
  if (flattenedStyleArray.margin) {
107
87
  margin = convertMargin(flattenedStyleArray.margin);
108
88
  }
109
89
  }
110
-
111
90
  margin = processSingleMargins(node, margin);
112
-
113
91
  if (node.margin) {
114
92
  margin = convertMargin(node.margin);
115
93
  }
116
-
117
94
  if (margin[0] === undefined && margin[1] === undefined && margin[2] === undefined && margin[3] === undefined) {
118
95
  return null;
119
96
  }
120
-
121
97
  return margin;
122
98
  }
@@ -3,13 +3,10 @@
3
3
  exports.__esModule = true;
4
4
  exports.offsetVector = offsetVector;
5
5
  exports.pack = pack;
6
-
7
6
  function pack(...args) {
8
7
  let result = {};
9
-
10
8
  for (let i = 0, l = args.length; i < l; i++) {
11
9
  let obj = args[i];
12
-
13
10
  if (obj) {
14
11
  for (let key in obj) {
15
12
  if (obj.hasOwnProperty(key)) {
@@ -18,10 +15,8 @@ function pack(...args) {
18
15
  }
19
16
  }
20
17
  }
21
-
22
18
  return result;
23
19
  }
24
-
25
20
  function offsetVector(vector, x, y) {
26
21
  switch (vector.type) {
27
22
  case 'ellipse':
@@ -29,20 +24,17 @@ function offsetVector(vector, x, y) {
29
24
  vector.x += x;
30
25
  vector.y += y;
31
26
  break;
32
-
33
27
  case 'line':
34
28
  vector.x1 += x;
35
29
  vector.x2 += x;
36
30
  vector.y1 += y;
37
31
  vector.y2 += y;
38
32
  break;
39
-
40
33
  case 'polyline':
41
34
  for (let i = 0, l = vector.points.length; i < l; i++) {
42
35
  vector.points[i].x += x;
43
36
  vector.points[i].y += y;
44
37
  }
45
-
46
38
  break;
47
39
  }
48
40
  }
@@ -4,9 +4,9 @@ exports.__esModule = true;
4
4
  exports.isEmptyObject = isEmptyObject;
5
5
  exports.isNumber = isNumber;
6
6
  exports.isObject = isObject;
7
+ exports.isPositiveInteger = isPositiveInteger;
7
8
  exports.isString = isString;
8
9
  exports.isValue = isValue;
9
-
10
10
  /**
11
11
  * @param {any} variable
12
12
  * @returns {boolean}
@@ -14,39 +14,46 @@ exports.isValue = isValue;
14
14
  function isString(variable) {
15
15
  return typeof variable === 'string' || variable instanceof String;
16
16
  }
17
+
17
18
  /**
18
19
  * @param {any} variable
19
20
  * @returns {boolean}
20
21
  */
21
-
22
-
23
22
  function isNumber(variable) {
24
23
  return typeof variable === 'number' || variable instanceof Number;
25
24
  }
25
+
26
26
  /**
27
27
  * @param {any} variable
28
28
  * @returns {boolean}
29
29
  */
30
+ function isPositiveInteger(variable) {
31
+ if (!isNumber(variable) || !Number.isInteger(variable) || variable <= 0) {
32
+ return false;
33
+ }
34
+ return true;
35
+ }
30
36
 
31
-
37
+ /**
38
+ * @param {any} variable
39
+ * @returns {boolean}
40
+ */
32
41
  function isObject(variable) {
33
42
  return variable !== null && !Array.isArray(variable) && !isString(variable) && !isNumber(variable) && typeof variable === 'object';
34
43
  }
44
+
35
45
  /**
36
46
  * @param {any} variable
37
47
  * @returns {boolean}
38
48
  */
39
-
40
-
41
49
  function isEmptyObject(variable) {
42
50
  return isObject(variable) && Object.keys(variable).length === 0;
43
51
  }
52
+
44
53
  /**
45
54
  * @param {any} variable
46
55
  * @returns {boolean}
47
56
  */
48
-
49
-
50
57
  function isValue(variable) {
51
58
  return variable !== undefined && variable !== null;
52
59
  }
package/js/index.js CHANGED
@@ -1,21 +1,15 @@
1
1
  "use strict";
2
2
 
3
3
  const pdfmakeBase = require('./base').default;
4
-
5
4
  const OutputDocumentServer = require('./OutputDocumentServer').default;
6
-
7
5
  const URLResolver = require('./URLResolver').default;
8
-
9
6
  class pdfmake extends pdfmakeBase {
10
7
  constructor() {
11
8
  super();
12
9
  this.urlResolver = new URLResolver(this.virtualfs);
13
10
  }
14
-
15
11
  _transformToDocument(doc) {
16
12
  return new OutputDocumentServer(doc);
17
13
  }
18
-
19
14
  }
20
-
21
15
  module.exports = new pdfmake();