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/TextBreaker.js CHANGED
@@ -2,15 +2,10 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
  exports.default = void 0;
5
-
6
5
  var _linebreak = _interopRequireDefault(require("@foliojs-fork/linebreak"));
7
-
8
6
  var _variableType = require("./helpers/variableType");
9
-
10
7
  var _StyleContextStack = _interopRequireDefault(require("./StyleContextStack"));
11
-
12
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
9
  /**
15
10
  * @param {string} text
16
11
  * @param {boolean} noWrap
@@ -18,21 +13,17 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
18
13
  */
19
14
  const splitWords = (text, noWrap) => {
20
15
  let words = [];
21
-
22
16
  if (noWrap) {
23
17
  words.push({
24
18
  text: text
25
19
  });
26
20
  return words;
27
21
  }
28
-
29
22
  let breaker = new _linebreak.default(text);
30
23
  let last = 0;
31
24
  let bk;
32
-
33
25
  while (bk = breaker.nextBreak()) {
34
26
  let word = text.slice(last, bk.position);
35
-
36
27
  if (bk.required || word.match(/\r?\n$|\r$/)) {
37
28
  // new line
38
29
  word = word.replace(/\r?\n$|\r$/, '');
@@ -45,71 +36,55 @@ const splitWords = (text, noWrap) => {
45
36
  text: word
46
37
  });
47
38
  }
48
-
49
39
  last = bk.position;
50
40
  }
51
-
52
41
  return words;
53
42
  };
43
+
54
44
  /**
55
45
  * @param {Array} words
56
46
  * @param {boolean} noWrap
57
47
  * @returns {?string}
58
48
  */
59
-
60
-
61
49
  const getFirstWord = (words, noWrap) => {
62
50
  let word = words[0];
63
-
64
51
  if (word === undefined) {
65
52
  return null;
66
53
  }
67
-
68
54
  if (noWrap) {
69
55
  // text was not wrapped, we need only first word
70
56
  let tmpWords = splitWords(word.text, false);
71
-
72
57
  if (tmpWords[0] === undefined) {
73
58
  return null;
74
59
  }
75
-
76
60
  word = tmpWords[0];
77
61
  }
78
-
79
62
  return word.text;
80
63
  };
64
+
81
65
  /**
82
66
  * @param {Array} words
83
67
  * @param {boolean} noWrap
84
68
  * @returns {?string}
85
69
  */
86
-
87
-
88
70
  const getLastWord = (words, noWrap) => {
89
71
  let word = words[words.length - 1];
90
-
91
72
  if (word === undefined) {
92
73
  return null;
93
74
  }
94
-
95
75
  if (word.lineEnd) {
96
76
  return null;
97
77
  }
98
-
99
78
  if (noWrap) {
100
79
  // text was not wrapped, we need only last word
101
80
  let tmpWords = splitWords(word.text, false);
102
-
103
81
  if (tmpWords[tmpWords.length - 1] === undefined) {
104
82
  return null;
105
83
  }
106
-
107
84
  word = tmpWords[tmpWords.length - 1];
108
85
  }
109
-
110
86
  return word.text;
111
87
  };
112
-
113
88
  class TextBreaker {
114
89
  /**
115
90
  * @param {string|Array} texts
@@ -118,65 +93,48 @@ class TextBreaker {
118
93
  */
119
94
  getBreaks(texts, styleContextStack) {
120
95
  let results = [];
121
-
122
96
  if (!Array.isArray(texts)) {
123
97
  texts = [texts];
124
98
  }
125
-
126
99
  let lastWord = null;
127
-
128
100
  for (let i = 0, l = texts.length; i < l; i++) {
129
101
  let item = texts[i];
130
102
  let style = null;
131
103
  let words;
132
-
133
104
  let noWrap = _StyleContextStack.default.getStyleProperty(item || {}, styleContextStack, 'noWrap', false);
134
-
135
105
  if ((0, _variableType.isObject)(item)) {
136
106
  if (item._textRef && item._textRef._textNodeRef.text) {
137
107
  item.text = item._textRef._textNodeRef.text;
138
108
  }
139
-
140
109
  words = splitWords(item.text, noWrap);
141
110
  style = _StyleContextStack.default.copyStyle(item);
142
111
  } else {
143
112
  words = splitWords(item, noWrap);
144
113
  }
145
-
146
114
  if (lastWord && words.length) {
147
115
  let firstWord = getFirstWord(words, noWrap);
148
116
  let wrapWords = splitWords(lastWord + firstWord, false);
149
-
150
117
  if (wrapWords.length === 1) {
151
118
  results[results.length - 1].noNewLine = true;
152
119
  }
153
120
  }
154
-
155
121
  for (let i2 = 0, l2 = words.length; i2 < l2; i2++) {
156
122
  let result = {
157
123
  text: words[i2].text
158
124
  };
159
-
160
125
  if (words[i2].lineEnd) {
161
126
  result.lineEnd = true;
162
127
  }
163
-
164
128
  _StyleContextStack.default.copyStyle(style, result);
165
-
166
129
  results.push(result);
167
130
  }
168
-
169
131
  lastWord = null;
170
-
171
132
  if (i + 1 < l) {
172
133
  lastWord = getLastWord(words, noWrap);
173
134
  }
174
135
  }
175
-
176
136
  return results;
177
137
  }
178
-
179
138
  }
180
-
181
139
  var _default = TextBreaker;
182
140
  exports.default = _default;
@@ -2,30 +2,23 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
  exports.default = void 0;
5
-
6
5
  const groupDecorations = line => {
7
6
  let groups = [];
8
7
  let currentGroup = null;
9
-
10
8
  for (let i = 0, l = line.inlines.length; i < l; i++) {
11
9
  let inline = line.inlines[i];
12
10
  let decoration = inline.decoration;
13
-
14
11
  if (!decoration) {
15
12
  currentGroup = null;
16
13
  continue;
17
14
  }
18
-
19
15
  if (!Array.isArray(decoration)) {
20
16
  decoration = [decoration];
21
17
  }
22
-
23
18
  let color = inline.decorationColor || inline.color || 'black';
24
19
  let style = inline.decorationStyle || 'solid';
25
-
26
20
  for (let ii = 0, ll = decoration.length; ii < ll; ii++) {
27
21
  let decorationItem = decoration[ii];
28
-
29
22
  if (!currentGroup || decorationItem !== currentGroup.decoration || style !== currentGroup.decorationStyle || color !== currentGroup.decorationColor) {
30
23
  currentGroup = {
31
24
  line: line,
@@ -40,68 +33,51 @@ const groupDecorations = line => {
40
33
  }
41
34
  }
42
35
  }
43
-
44
36
  return groups;
45
37
  };
46
-
47
38
  class TextDecorator {
48
39
  constructor(pdfDocument) {
49
40
  this.pdfDocument = pdfDocument;
50
41
  }
51
-
52
42
  drawBackground(line, x, y) {
53
43
  let height = line.getHeight();
54
-
55
44
  for (let i = 0, l = line.inlines.length; i < l; i++) {
56
45
  let inline = line.inlines[i];
57
-
58
46
  if (!inline.background) {
59
47
  continue;
60
48
  }
61
-
62
49
  let color = inline.background;
63
50
  let patternColor = this.pdfDocument.providePattern(inline.background);
64
-
65
51
  if (patternColor !== null) {
66
52
  color = patternColor;
67
53
  }
68
-
69
54
  let justifyShift = inline.justifyShift || 0;
70
55
  this.pdfDocument.fillColor(color).rect(x + inline.x - justifyShift, y, inline.width + justifyShift, height).fill();
71
56
  }
72
57
  }
73
-
74
58
  drawDecorations(line, x, y) {
75
59
  let groups = groupDecorations(line);
76
-
77
60
  for (let i = 0, l = groups.length; i < l; i++) {
78
61
  this._drawDecoration(groups[i], x, y);
79
62
  }
80
63
  }
81
-
82
64
  _drawDecoration(group, x, y) {
83
65
  const maxInline = () => {
84
66
  let max = 0;
85
-
86
67
  for (let i = 0, l = group.inlines.length; i < l; i++) {
87
68
  let inline = group.inlines[i];
88
69
  max = inline.fontSize > max ? i : max;
89
70
  }
90
-
91
71
  return group.inlines[max];
92
72
  };
93
-
94
73
  const width = () => {
95
74
  let sum = 0;
96
-
97
75
  for (let i = 0, l = group.inlines.length; i < l; i++) {
98
76
  let justifyShift = group.inlines[i].justifyShift || 0;
99
77
  sum += group.inlines[i].width + justifyShift;
100
78
  }
101
-
102
79
  return sum;
103
80
  };
104
-
105
81
  let firstInline = group.inlines[0];
106
82
  let biggerInline = maxInline();
107
83
  let totalWidth = width();
@@ -110,26 +86,20 @@ class TextDecorator {
110
86
  let height = biggerInline.height;
111
87
  let descent = height - ascent;
112
88
  let lw = 0.5 + Math.floor(Math.max(biggerInline.fontSize - 8, 0) / 2) * 0.12;
113
-
114
89
  switch (group.decoration) {
115
90
  case 'underline':
116
91
  y += lineAscent + descent * 0.45;
117
92
  break;
118
-
119
93
  case 'overline':
120
94
  y += lineAscent - ascent * 0.85;
121
95
  break;
122
-
123
96
  case 'lineThrough':
124
97
  y += lineAscent - ascent * 0.25;
125
98
  break;
126
-
127
99
  default:
128
100
  throw new Error(`Unkown decoration : ${group.decoration}`);
129
101
  }
130
-
131
102
  this.pdfDocument.save();
132
-
133
103
  if (group.decorationStyle === 'double') {
134
104
  let gap = Math.max(0.5, lw * 2);
135
105
  this.pdfDocument.fillColor(group.decorationColor).rect(x + firstInline.x, y - lw / 2, totalWidth, lw / 2).fill().rect(x + firstInline.x, y + gap - lw / 2, totalWidth, lw / 2).fill();
@@ -138,7 +108,6 @@ class TextDecorator {
138
108
  let rdx = x + firstInline.x;
139
109
  this.pdfDocument.rect(rdx, y, totalWidth, lw).clip();
140
110
  this.pdfDocument.fillColor(group.decorationColor);
141
-
142
111
  for (let i = 0; i < nbDashes; i++) {
143
112
  this.pdfDocument.rect(rdx, y - lw / 2, 3.96, lw).fill();
144
113
  rdx += 3.96 + 2.84;
@@ -148,34 +117,28 @@ class TextDecorator {
148
117
  let rx = x + firstInline.x;
149
118
  this.pdfDocument.rect(rx, y, totalWidth, lw).clip();
150
119
  this.pdfDocument.fillColor(group.decorationColor);
151
-
152
120
  for (let i = 0; i < nbDots; i++) {
153
121
  this.pdfDocument.rect(rx, y - lw / 2, lw, lw).fill();
154
122
  rx += lw * 3;
155
123
  }
156
124
  } else if (group.decorationStyle === 'wavy') {
157
125
  let sh = 0.7,
158
- sv = 1;
126
+ sv = 1;
159
127
  let nbWaves = Math.ceil(totalWidth / (sh * 2)) + 1;
160
128
  let rwx = x + firstInline.x - 1;
161
129
  this.pdfDocument.rect(x + firstInline.x, y - sv, totalWidth, y + sv).clip();
162
130
  this.pdfDocument.lineWidth(0.24);
163
131
  this.pdfDocument.moveTo(rwx, y);
164
-
165
132
  for (let i = 0; i < nbWaves; i++) {
166
133
  this.pdfDocument.bezierCurveTo(rwx + sh, y - sv, rwx + sh * 2, y - sv, rwx + sh * 3, y).bezierCurveTo(rwx + sh * 4, y + sv, rwx + sh * 5, y + sv, rwx + sh * 6, y);
167
134
  rwx += sh * 6;
168
135
  }
169
-
170
136
  this.pdfDocument.stroke(group.decorationColor);
171
137
  } else {
172
138
  this.pdfDocument.fillColor(group.decorationColor).rect(x + firstInline.x, y - lw / 2, totalWidth, lw).fill();
173
139
  }
174
-
175
140
  this.pdfDocument.restore();
176
141
  }
177
-
178
142
  }
179
-
180
143
  var _default = TextDecorator;
181
144
  exports.default = _default;
package/js/TextInlines.js CHANGED
@@ -2,20 +2,16 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
  exports.default = void 0;
5
-
6
5
  var _TextBreaker = _interopRequireDefault(require("./TextBreaker"));
7
-
8
6
  var _StyleContextStack = _interopRequireDefault(require("./StyleContextStack"));
9
-
10
7
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
8
  const LEADING = /^(\s)+/g;
13
9
  const TRAILING = /(\s)+$/g;
10
+
14
11
  /**
15
12
  * @param {Array} array
16
13
  * @returns {Array}
17
14
  */
18
-
19
15
  const flattenTextArray = array => {
20
16
  function flatten(array) {
21
17
  return array.reduce((prev, cur) => {
@@ -24,20 +20,19 @@ const flattenTextArray = array => {
24
20
  return prev.concat(more ? flatten(current) : current);
25
21
  }, []);
26
22
  }
27
-
28
23
  if (!Array.isArray(array)) {
29
24
  array = [array];
30
- } // TODO: Styling in nested text (issue: https://github.com/bpampuch/pdfmake/issues/1174)
25
+ }
31
26
 
27
+ // TODO: Styling in nested text (issue: https://github.com/bpampuch/pdfmake/issues/1174)
32
28
 
33
29
  array = flatten(array);
34
30
  return array;
35
31
  };
32
+
36
33
  /**
37
34
  * Text measurement utility
38
35
  */
39
-
40
-
41
36
  class TextInlines {
42
37
  /**
43
38
  * @param {object} pdfDocument object is instance of PDFDocument
@@ -45,6 +40,7 @@ class TextInlines {
45
40
  constructor(pdfDocument) {
46
41
  this.pdfDocument = pdfDocument;
47
42
  }
43
+
48
44
  /**
49
45
  * Converts an array of strings (or inline-definition-objects) into a collection
50
46
  * of inlines and calculated minWidth/maxWidth and their min/max widths
@@ -53,13 +49,10 @@ class TextInlines {
53
49
  * @param {StyleContextStack} styleContextStack current style stack
54
50
  * @returns {object} collection of inlines, minWidth, maxWidth
55
51
  */
56
-
57
-
58
52
  buildInlines(textArray, styleContextStack) {
59
53
  const getTrimmedWidth = item => {
60
54
  return Math.max(0, item.width - item.leadingCut - item.trailingCut);
61
55
  };
62
-
63
56
  let minWidth = 0;
64
57
  let maxWidth = 0;
65
58
  let currentLineWidth;
@@ -69,7 +62,6 @@ class TextInlines {
69
62
  let measuredText = this.measure(breakedText, styleContextStack);
70
63
  measuredText.forEach(inline => {
71
64
  minWidth = Math.max(minWidth, getTrimmedWidth(inline));
72
-
73
65
  if (!currentLineWidth) {
74
66
  currentLineWidth = {
75
67
  width: 0,
@@ -77,44 +69,34 @@ class TextInlines {
77
69
  trailingCut: 0
78
70
  };
79
71
  }
80
-
81
72
  currentLineWidth.width += inline.width;
82
73
  currentLineWidth.trailingCut = inline.trailingCut;
83
74
  maxWidth = Math.max(maxWidth, getTrimmedWidth(currentLineWidth));
84
-
85
75
  if (inline.lineEnd) {
86
76
  currentLineWidth = null;
87
77
  }
88
78
  });
89
-
90
79
  if (_StyleContextStack.default.getStyleProperty({}, styleContextStack, 'noWrap', false)) {
91
80
  minWidth = maxWidth;
92
81
  }
93
-
94
82
  return {
95
83
  items: measuredText,
96
84
  minWidth: minWidth,
97
85
  maxWidth: maxWidth
98
86
  };
99
87
  }
100
-
101
88
  measure(array, styleContextStack) {
102
89
  if (array.length) {
103
90
  let leadingIndent = _StyleContextStack.default.getStyleProperty(array[0], styleContextStack, 'leadingIndent', 0);
104
-
105
91
  if (leadingIndent) {
106
92
  array[0].leadingCut = -leadingIndent;
107
93
  array[0].leadingIndent = leadingIndent;
108
94
  }
109
95
  }
110
-
111
96
  array.forEach(item => {
112
97
  let font = _StyleContextStack.default.getStyleProperty(item, styleContextStack, 'font', 'Roboto');
113
-
114
98
  let bold = _StyleContextStack.default.getStyleProperty(item, styleContextStack, 'bold', false);
115
-
116
99
  let italics = _StyleContextStack.default.getStyleProperty(item, styleContextStack, 'italics', false);
117
-
118
100
  item.font = this.pdfDocument.provideFont(font, bold, italics);
119
101
  item.alignment = _StyleContextStack.default.getStyleProperty(item, styleContextStack, 'alignment', 'left');
120
102
  item.fontSize = _StyleContextStack.default.getStyleProperty(item, styleContextStack, 'fontSize', 12);
@@ -132,38 +114,27 @@ class TextInlines {
132
114
  item.opacity = _StyleContextStack.default.getStyleProperty(item, styleContextStack, 'opacity', 1);
133
115
  item.sup = _StyleContextStack.default.getStyleProperty(item, styleContextStack, 'sup', false);
134
116
  item.sub = _StyleContextStack.default.getStyleProperty(item, styleContextStack, 'sub', false);
135
-
136
117
  if (item.sup || item.sub) {
137
118
  // font size reduction taken from here: https://en.wikipedia.org/wiki/Subscript_and_superscript#Desktop_publishing
138
119
  item.fontSize *= 0.58;
139
120
  }
140
-
141
121
  let lineHeight = _StyleContextStack.default.getStyleProperty(item, styleContextStack, 'lineHeight', 1);
142
-
143
122
  item.width = this.widthOfText(item.text, item);
144
123
  item.height = item.font.lineHeight(item.fontSize) * lineHeight;
145
-
146
124
  if (!item.leadingCut) {
147
125
  item.leadingCut = 0;
148
126
  }
149
-
150
127
  let preserveLeadingSpaces = _StyleContextStack.default.getStyleProperty(item, styleContextStack, 'preserveLeadingSpaces', false);
151
-
152
128
  if (!preserveLeadingSpaces) {
153
129
  let leadingSpaces = item.text.match(LEADING);
154
-
155
130
  if (leadingSpaces) {
156
131
  item.leadingCut += this.widthOfText(leadingSpaces[0], item);
157
132
  }
158
133
  }
159
-
160
134
  item.trailingCut = 0;
161
-
162
135
  let preserveTrailingSpaces = _StyleContextStack.default.getStyleProperty(item, styleContextStack, 'preserveTrailingSpaces', false);
163
-
164
136
  if (!preserveTrailingSpaces) {
165
137
  let trailingSpaces = item.text.match(TRAILING);
166
-
167
138
  if (trailingSpaces) {
168
139
  item.trailingCut = this.widthOfText(trailingSpaces[0], item);
169
140
  }
@@ -171,6 +142,7 @@ class TextInlines {
171
142
  }, this);
172
143
  return array;
173
144
  }
145
+
174
146
  /**
175
147
  * Width of text
176
148
  *
@@ -178,11 +150,10 @@ class TextInlines {
178
150
  * @param {object} inline
179
151
  * @returns {number}
180
152
  */
181
-
182
-
183
153
  widthOfText(text, inline) {
184
154
  return inline.font.widthOfString(text, inline.fontSize, inline.fontFeatures) + (inline.characterSpacing || 0) * (text.length - 1);
185
155
  }
156
+
186
157
  /**
187
158
  * Returns size of the specified string (without breaking it) using the current style
188
159
  *
@@ -190,24 +161,15 @@ class TextInlines {
190
161
  * @param {object} styleContextStack current style stack
191
162
  * @returns {object} size of the specified string
192
163
  */
193
-
194
-
195
164
  sizeOfText(text, styleContextStack) {
196
165
  //TODO: refactor - extract from measure
197
166
  let fontName = _StyleContextStack.default.getStyleProperty({}, styleContextStack, 'font', 'Roboto');
198
-
199
167
  let fontSize = _StyleContextStack.default.getStyleProperty({}, styleContextStack, 'fontSize', 12);
200
-
201
168
  let fontFeatures = _StyleContextStack.default.getStyleProperty({}, styleContextStack, 'fontFeatures', null);
202
-
203
169
  let bold = _StyleContextStack.default.getStyleProperty({}, styleContextStack, 'bold', false);
204
-
205
170
  let italics = _StyleContextStack.default.getStyleProperty({}, styleContextStack, 'italics', false);
206
-
207
171
  let lineHeight = _StyleContextStack.default.getStyleProperty({}, styleContextStack, 'lineHeight', 1);
208
-
209
172
  let characterSpacing = _StyleContextStack.default.getStyleProperty({}, styleContextStack, 'characterSpacing', 0);
210
-
211
173
  let font = this.pdfDocument.provideFont(fontName, bold, italics);
212
174
  return {
213
175
  width: this.widthOfText(text, {
@@ -223,6 +185,7 @@ class TextInlines {
223
185
  descender: font.descender / 1000 * fontSize
224
186
  };
225
187
  }
188
+
226
189
  /**
227
190
  * Returns size of the specified rotated string (without breaking it) using the current style
228
191
  *
@@ -231,8 +194,6 @@ class TextInlines {
231
194
  * @param {object} styleContextStack current style stack
232
195
  * @returns {object} size of the specified string
233
196
  */
234
-
235
-
236
197
  sizeOfRotatedText(text, angle, styleContextStack) {
237
198
  let angleRad = angle * Math.PI / -180;
238
199
  let size = this.sizeOfText(text, styleContextStack);
@@ -241,8 +202,6 @@ class TextInlines {
241
202
  height: Math.abs(size.width * Math.sin(angleRad)) + Math.abs(size.height * Math.cos(angleRad))
242
203
  };
243
204
  }
244
-
245
205
  }
246
-
247
206
  var _default = TextInlines;
248
207
  exports.default = _default;
package/js/URLResolver.js CHANGED
@@ -2,13 +2,9 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
  exports.default = void 0;
5
-
6
5
  var _http = _interopRequireDefault(require("http"));
7
-
8
6
  var _https = _interopRequireDefault(require("https"));
9
-
10
7
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
8
  const fetchUrl = (url, headers = {}) => {
13
9
  return new Promise((resolve, reject) => {
14
10
  const parsedUrl = new URL(url);
@@ -26,26 +22,21 @@ const fetchUrl = (url, headers = {}) => {
26
22
  });
27
23
  return;
28
24
  }
29
-
30
25
  const ok = res.statusCode >= 200 && res.statusCode < 300;
31
-
32
26
  if (!ok) {
33
27
  reject(new TypeError(`Failed to fetch (status code: ${res.statusCode}, url: "${url}")`));
34
28
  }
35
-
36
29
  const chunks = [];
37
30
  res.on('end', () => resolve(Buffer.concat(chunks)));
38
31
  res.on('data', d => chunks.push(d));
39
32
  }).on('error', reject);
40
33
  });
41
34
  };
42
-
43
35
  class URLResolver {
44
36
  constructor(fs) {
45
37
  this.fs = fs;
46
38
  this.resolving = {};
47
39
  }
48
-
49
40
  resolve(url, headers = {}) {
50
41
  if (!this.resolving[url]) {
51
42
  this.resolving[url] = new Promise((resolve, reject) => {
@@ -67,10 +58,8 @@ class URLResolver {
67
58
  }
68
59
  });
69
60
  }
70
-
71
61
  return this.resolving[url];
72
62
  }
73
-
74
63
  resolved() {
75
64
  return new Promise((resolve, reject) => {
76
65
  Promise.all(Object.values(this.resolving)).then(() => {
@@ -80,8 +69,6 @@ class URLResolver {
80
69
  });
81
70
  });
82
71
  }
83
-
84
72
  }
85
-
86
73
  var _default = URLResolver;
87
74
  exports.default = _default;
package/js/base.js CHANGED
@@ -2,27 +2,21 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
  exports.default = void 0;
5
-
6
5
  var _Printer = _interopRequireDefault(require("./Printer"));
7
-
8
6
  var _virtualFs = _interopRequireDefault(require("./virtual-fs"));
9
-
10
7
  var _tools = require("./helpers/tools");
11
-
12
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
9
  class pdfmake {
15
10
  constructor() {
16
11
  this.virtualfs = _virtualFs.default;
17
12
  this.urlResolver = null;
18
13
  }
14
+
19
15
  /**
20
16
  * @param {object} docDefinition
21
17
  * @param {?object} options
22
18
  * @returns {object}
23
19
  */
24
-
25
-
26
20
  createPdf(docDefinition, options = {}) {
27
21
  options.progressCallback = this.progressCallback;
28
22
  options.tableLayouts = this.tableLayouts;
@@ -30,40 +24,30 @@ class pdfmake {
30
24
  const pdfDocumentPromise = printer.createPdfKitDocument(docDefinition, options);
31
25
  return this._transformToDocument(pdfDocumentPromise);
32
26
  }
33
-
34
27
  setProgressCallback(callback) {
35
28
  this.progressCallback = callback;
36
29
  }
37
-
38
30
  addTableLayouts(tableLayouts) {
39
31
  this.tableLayouts = (0, _tools.pack)(this.tableLayouts, tableLayouts);
40
32
  }
41
-
42
33
  setTableLayouts(tableLayouts) {
43
34
  this.tableLayouts = tableLayouts;
44
35
  }
45
-
46
36
  clearTableLayouts() {
47
37
  this.tableLayouts = {};
48
38
  }
49
-
50
39
  addFonts(fonts) {
51
40
  this.fonts = (0, _tools.pack)(this.fonts, fonts);
52
41
  }
53
-
54
42
  setFonts(fonts) {
55
43
  this.fonts = fonts;
56
44
  }
57
-
58
45
  clearFonts() {
59
46
  this.fonts = {};
60
47
  }
61
-
62
48
  _transformToDocument(doc) {
63
49
  return doc;
64
50
  }
65
-
66
51
  }
67
-
68
52
  var _default = pdfmake;
69
53
  exports.default = _default;