pdfmake 0.3.0-beta.3 → 0.3.0-beta.5

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 (49) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/build/pdfmake.js +2213 -8630
  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/build/vfs_fonts.js +6 -5
  7. package/js/3rd-party/svg-to-pdfkit/source.js +247 -920
  8. package/js/3rd-party/svg-to-pdfkit.js +0 -3
  9. package/js/DocMeasure.js +6 -139
  10. package/js/DocPreprocessor.js +2 -54
  11. package/js/DocumentContext.js +0 -40
  12. package/js/ElementWriter.js +2 -70
  13. package/js/LayoutBuilder.js +20 -165
  14. package/js/Line.js +6 -25
  15. package/js/OutputDocument.js +15 -24
  16. package/js/OutputDocumentServer.js +0 -6
  17. package/js/PDFDocument.js +1 -46
  18. package/js/PageElementWriter.js +7 -31
  19. package/js/PageSize.js +2 -16
  20. package/js/Printer.js +5 -46
  21. package/js/Renderer.js +11 -98
  22. package/js/SVGMeasure.js +1 -20
  23. package/js/StyleContextStack.js +12 -36
  24. package/js/TableProcessor.js +36 -117
  25. package/js/TextBreaker.js +2 -44
  26. package/js/TextDecorator.js +1 -38
  27. package/js/TextInlines.js +8 -49
  28. package/js/URLResolver.js +0 -13
  29. package/js/base.js +1 -17
  30. package/js/browser-extensions/OutputDocumentBrowser.js +5 -17
  31. package/js/browser-extensions/URLBrowserResolver.js +0 -17
  32. package/js/browser-extensions/fonts/Roboto.js +0 -4
  33. package/js/browser-extensions/index.js +0 -16
  34. package/js/browser-extensions/pdfMake.js +2 -4
  35. package/js/browser-extensions/standard-fonts/Courier.js +0 -4
  36. package/js/browser-extensions/standard-fonts/Helvetica.js +0 -4
  37. package/js/browser-extensions/standard-fonts/Symbol.js +0 -4
  38. package/js/browser-extensions/standard-fonts/Times.js +0 -4
  39. package/js/browser-extensions/standard-fonts/ZapfDingbats.js +0 -4
  40. package/js/columnCalculator.js +6 -18
  41. package/js/helpers/node.js +3 -27
  42. package/js/helpers/tools.js +0 -8
  43. package/js/helpers/variableType.js +4 -9
  44. package/js/index.js +0 -6
  45. package/js/qrEnc.js +126 -215
  46. package/js/tableLayouts.js +1 -28
  47. package/js/virtual-fs.js +3 -19
  48. package/package.json +2 -2
  49. package/src/OutputDocument.js +78 -78
package/js/SVGMeasure.js CHANGED
@@ -2,11 +2,8 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
  exports.default = void 0;
5
-
6
5
  var _xmldoc = _interopRequireDefault(require("xmldoc"));
7
-
8
6
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
-
10
7
  /**
11
8
  * Strip unit postfix, parse number, but return undefined instead of NaN for bad input
12
9
  *
@@ -15,75 +12,59 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
15
12
  */
16
13
  const stripUnits = textVal => {
17
14
  var n = parseFloat(textVal);
18
-
19
15
  if (typeof n !== 'number' || isNaN(n)) {
20
16
  return undefined;
21
17
  }
22
-
23
18
  return n;
24
19
  };
20
+
25
21
  /**
26
22
  * Make sure it's valid XML and the root tage is <svg/>, returns xmldoc DOM
27
23
  *
28
24
  * @param {string} svgString
29
25
  * @returns {object}
30
26
  */
31
-
32
-
33
27
  const parseSVG = svgString => {
34
28
  var doc;
35
-
36
29
  try {
37
30
  doc = new _xmldoc.default.XmlDocument(svgString);
38
31
  } catch (err) {
39
32
  throw new Error('SVGMeasure: ' + err);
40
33
  }
41
-
42
34
  if (doc.name !== "svg") {
43
35
  throw new Error('SVGMeasure: expected <svg> document');
44
36
  }
45
-
46
37
  return doc;
47
38
  };
48
-
49
39
  class SVGMeasure {
50
40
  constructor() {}
51
-
52
41
  measureSVG(svgString) {
53
42
  let doc = parseSVG(svgString);
54
43
  let docWidth = stripUnits(doc.attr.width);
55
44
  let docHeight = stripUnits(doc.attr.height);
56
-
57
45
  if ((docWidth === undefined || docHeight === undefined) && typeof doc.attr.viewBox === 'string') {
58
46
  let viewBoxParts = doc.attr.viewBox.split(/[,\s]+/);
59
-
60
47
  if (viewBoxParts.length !== 4) {
61
48
  throw new Error("Unexpected svg viewbox format, should have 4 entries but found: '" + doc.attr.viewBox + "'");
62
49
  }
63
-
64
50
  if (docWidth === undefined) {
65
51
  docWidth = stripUnits(viewBoxParts[2]);
66
52
  }
67
-
68
53
  if (docHeight === undefined) {
69
54
  docHeight = stripUnits(viewBoxParts[3]);
70
55
  }
71
56
  }
72
-
73
57
  return {
74
58
  width: docWidth,
75
59
  height: docHeight
76
60
  };
77
61
  }
78
-
79
62
  writeDimensions(svgString, dimensions) {
80
63
  let doc = parseSVG(svgString);
81
64
  doc.attr.width = "" + dimensions.width;
82
65
  doc.attr.height = "" + dimensions.height;
83
66
  return doc.toString();
84
67
  }
85
-
86
68
  }
87
-
88
69
  var _default = SVGMeasure;
89
70
  exports.default = _default;
@@ -2,9 +2,7 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
  exports.default = void 0;
5
-
6
5
  var _variableType = require("./helpers/variableType");
7
-
8
6
  /**
9
7
  * Used for style inheritance and style overrides
10
8
  */
@@ -18,13 +16,12 @@ class StyleContextStack {
18
16
  this.defaultStyle = defaultStyle;
19
17
  this.styleOverrides = [];
20
18
  }
19
+
21
20
  /**
22
21
  * Creates cloned version of current stack
23
22
  *
24
23
  * @returns {StyleContextStack} current stack snapshot
25
24
  */
26
-
27
-
28
25
  clone() {
29
26
  let stack = new StyleContextStack(this.styleDictionary, this.defaultStyle);
30
27
  this.styleOverrides.forEach(item => {
@@ -32,30 +29,29 @@ class StyleContextStack {
32
29
  });
33
30
  return stack;
34
31
  }
32
+
35
33
  /**
36
34
  * Pushes style-name or style-overrides-object onto the stack for future evaluation
37
35
  *
38
36
  * @param {string|object} styleNameOrOverride style-name (referring to styleDictionary) or
39
37
  * a new dictionary defining overriding properties
40
38
  */
41
-
42
-
43
39
  push(styleNameOrOverride) {
44
40
  this.styleOverrides.push(styleNameOrOverride);
45
41
  }
42
+
46
43
  /**
47
44
  * Removes last style-name or style-overrides-object from the stack
48
45
  *
49
46
  * @param {number} howMany optional number of elements to be popped (if not specified,
50
47
  * one element will be removed from the stack)
51
48
  */
52
-
53
-
54
49
  pop(howMany = 1) {
55
50
  while (howMany-- > 0) {
56
51
  this.styleOverrides.pop();
57
52
  }
58
53
  }
54
+
59
55
  /**
60
56
  * Creates a set of named styles or/and a style-overrides-object based on the item,
61
57
  * pushes those elements onto the stack for future evaluation and returns the number
@@ -64,15 +60,11 @@ class StyleContextStack {
64
60
  * @param {object} item - an object with optional style property and/or style overrides
65
61
  * @returns {number} the number of items pushed onto the stack
66
62
  */
67
-
68
-
69
63
  autopush(item) {
70
64
  if ((0, _variableType.isString)(item)) {
71
65
  return 0;
72
66
  }
73
-
74
67
  let styleNames = [];
75
-
76
68
  if (item.style) {
77
69
  if (Array.isArray(item.style)) {
78
70
  styleNames = item.style;
@@ -80,18 +72,18 @@ class StyleContextStack {
80
72
  styleNames = [item.style];
81
73
  }
82
74
  }
83
-
84
75
  for (let i = 0, l = styleNames.length; i < l; i++) {
85
76
  this.push(styleNames[i]);
86
77
  }
87
-
88
- let styleProperties = ['font', 'fontSize', 'fontFeatures', 'bold', 'italics', 'alignment', 'color', 'columnGap', 'fillColor', 'fillOpacity', 'decoration', 'decorationStyle', 'decorationColor', 'background', 'lineHeight', 'characterSpacing', 'noWrap', 'markerColor', 'leadingIndent', 'sup', 'sub' //'tableCellPadding'
78
+ let styleProperties = ['font', 'fontSize', 'fontFeatures', 'bold', 'italics', 'alignment', 'color', 'columnGap', 'fillColor', 'fillOpacity', 'decoration', 'decorationStyle', 'decorationColor', 'background', 'lineHeight', 'characterSpacing', 'noWrap', 'markerColor', 'leadingIndent', 'sup', 'sub'
79
+ //'tableCellPadding'
89
80
  // 'cellBorder',
90
81
  // 'headerCellBorder',
91
82
  // 'oddRowCellBorder',
92
83
  // 'evenRowCellBorder',
93
84
  // 'tableBorder'
94
85
  ];
86
+
95
87
  let styleOverrideObject = {};
96
88
  let pushStyleOverrideObject = false;
97
89
  styleProperties.forEach(key => {
@@ -100,13 +92,12 @@ class StyleContextStack {
100
92
  pushStyleOverrideObject = true;
101
93
  }
102
94
  });
103
-
104
95
  if (pushStyleOverrideObject) {
105
96
  this.push(styleOverrideObject);
106
97
  }
107
-
108
98
  return styleNames.length + (pushStyleOverrideObject ? 1 : 0);
109
99
  }
100
+
110
101
  /**
111
102
  * Automatically pushes elements onto the stack, using autopush based on item,
112
103
  * executes callback and then pops elements back. Returns value returned by callback
@@ -115,35 +106,28 @@ class StyleContextStack {
115
106
  * @param {Function} callback to be called between autopush and pop
116
107
  * @returns {object} value returned by callback
117
108
  */
118
-
119
-
120
109
  auto(item, callback) {
121
110
  let pushedItems = this.autopush(item);
122
111
  let result = callback();
123
-
124
112
  if (pushedItems > 0) {
125
113
  this.pop(pushedItems);
126
114
  }
127
-
128
115
  return result;
129
116
  }
117
+
130
118
  /**
131
119
  * Evaluates stack and returns value of a named property
132
120
  *
133
121
  * @param {string} property - property name
134
122
  * @returns {?any} property value or null if not found
135
123
  */
136
-
137
-
138
124
  getProperty(property) {
139
125
  if (this.styleOverrides) {
140
126
  for (let i = this.styleOverrides.length - 1; i >= 0; i--) {
141
127
  let item = this.styleOverrides[i];
142
-
143
128
  if ((0, _variableType.isString)(item)) {
144
129
  // named-style-override
145
130
  let style = this.styleDictionary[item];
146
-
147
131
  if (style && (0, _variableType.isValue)(style[property])) {
148
132
  return style[property];
149
133
  }
@@ -153,9 +137,9 @@ class StyleContextStack {
153
137
  }
154
138
  }
155
139
  }
156
-
157
140
  return this.defaultStyle && this.defaultStyle[property];
158
141
  }
142
+
159
143
  /**
160
144
  * @param {object} item
161
145
  * @param {StyleContextStack} styleContextStack
@@ -163,44 +147,36 @@ class StyleContextStack {
163
147
  * @param {any} defaultValue
164
148
  * @returns {any}
165
149
  */
166
-
167
-
168
150
  static getStyleProperty(item, styleContextStack, property, defaultValue) {
169
151
  let value;
170
-
171
152
  if ((0, _variableType.isValue)(item[property])) {
172
153
  // item defines this property
173
154
  return item[property];
174
155
  }
175
-
176
156
  if (!styleContextStack) {
177
157
  return defaultValue;
178
158
  }
179
-
180
159
  styleContextStack.auto(item, () => {
181
160
  value = styleContextStack.getProperty(property);
182
161
  });
183
162
  return (0, _variableType.isValue)(value) ? value : defaultValue;
184
163
  }
164
+
185
165
  /**
186
166
  * @param {object} source
187
167
  * @param {object} destination
188
168
  * @returns {object}
189
169
  */
190
-
191
-
192
170
  static copyStyle(source = {}, destination = {}) {
193
171
  // TODO: default style to source
172
+
194
173
  for (let key in source) {
195
174
  if (key != 'text' && source.hasOwnProperty(key)) {
196
175
  destination[key] = source[key];
197
176
  }
198
177
  }
199
-
200
178
  return destination;
201
179
  }
202
-
203
180
  }
204
-
205
181
  var _default = StyleContextStack;
206
182
  exports.default = _default;