pdfmake 0.2.19 → 0.2.21

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pdfmake",
3
- "version": "0.2.19",
3
+ "version": "0.2.21",
4
4
  "description": "Client/server side PDF printing in pure JavaScript",
5
5
  "main": "src/printer.js",
6
6
  "browser": "build/pdfmake.js",
@@ -10,40 +10,40 @@
10
10
  "dependencies": {
11
11
  "@foliojs-fork/linebreak": "^1.1.2",
12
12
  "@foliojs-fork/pdfkit": "^0.15.3",
13
- "iconv-lite": "^0.6.3",
14
- "xmldoc": "^2.0.0"
13
+ "iconv-lite": "^0.7.1",
14
+ "xmldoc": "^2.0.3"
15
15
  },
16
16
  "devDependencies": {
17
- "@babel/cli": "^7.27.0",
18
- "@babel/core": "^7.26.10",
19
- "@babel/plugin-transform-modules-commonjs": "^7.26.3",
20
- "@babel/preset-env": "^7.26.9",
21
- "@eslint/js": "^9.25.1",
17
+ "@babel/cli": "^7.28.3",
18
+ "@babel/core": "^7.28.5",
19
+ "@babel/plugin-transform-modules-commonjs": "^7.27.1",
20
+ "@babel/preset-env": "^7.28.5",
21
+ "@eslint/js": "^9.39.2",
22
22
  "assert": "^2.1.0",
23
23
  "babel-loader": "^10.0.0",
24
24
  "brfs": "^2.0.2",
25
25
  "browserify-zlib": "^0.2.0",
26
26
  "buffer": "^6.0.3",
27
27
  "core-js": "3.19.0",
28
- "eslint": "^9.25.1",
29
- "eslint-plugin-jsdoc": "^50.6.11",
28
+ "eslint": "^9.39.2",
29
+ "eslint-plugin-jsdoc": "^61.5.0",
30
30
  "expose-loader": "^5.0.1",
31
31
  "file-saver": "^2.0.5",
32
- "globals": "^16.0.0",
33
- "mocha": "^11.1.0",
32
+ "globals": "^16.5.0",
33
+ "mocha": "^11.7.5",
34
34
  "npm-run-all": "^4.1.5",
35
35
  "process": "^0.11.10",
36
- "rewire": "^7.0.0",
36
+ "rewire": "^9.0.1",
37
37
  "shx": "^0.4.0",
38
- "sinon": "^20.0.0",
38
+ "sinon": "^21.0.1",
39
39
  "source-map-loader": "^5.0.0",
40
40
  "stream-browserify": "^3.0.0",
41
41
  "string-replace-webpack-plugin": "^0.1.3",
42
42
  "svg-to-pdfkit": "^0.1.8",
43
- "terser-webpack-plugin": "^5.3.14",
43
+ "terser-webpack-plugin": "^5.3.16",
44
44
  "transform-loader": "^0.2.4",
45
45
  "util": "^0.12.5",
46
- "webpack": "^5.99.7",
46
+ "webpack": "^5.104.1",
47
47
  "webpack-cli": "^6.0.1"
48
48
  },
49
49
  "engines": {
@@ -66,9 +66,17 @@ LayoutBuilder.prototype.layoutDocument = function (docStructure, fontProvider, s
66
66
  return false;
67
67
  }
68
68
 
69
- linearNodeList = linearNodeList.filter(function (node) {
70
- return node.positions.length > 0;
71
- });
69
+ const hasRenderableContent = node => {
70
+ if (!node || node.positions.length === 0) {
71
+ return false;
72
+ }
73
+ if (node.text === '' && !node.listMarker) {
74
+ return false;
75
+ }
76
+ return true;
77
+ };
78
+
79
+ linearNodeList = linearNodeList.filter(hasRenderableContent);
72
80
 
73
81
  linearNodeList.forEach(function (node) {
74
82
  var nodeInfo = {};
@@ -1043,6 +1051,27 @@ LayoutBuilder.prototype.buildNextLine = function (textNode) {
1043
1051
  return newInline;
1044
1052
  }
1045
1053
 
1054
+ function findMaxFitLength(text, maxWidth, measureFn) {
1055
+ let low = 1;
1056
+ let high = text.length;
1057
+ let bestFit = 1;
1058
+
1059
+ while (low <= high) {
1060
+ const mid = Math.floor((low + high) / 2);
1061
+ const part = text.substring(0, mid);
1062
+ const width = measureFn(part);
1063
+
1064
+ if (width <= maxWidth) {
1065
+ bestFit = mid;
1066
+ low = mid + 1;
1067
+ } else {
1068
+ high = mid - 1;
1069
+ }
1070
+ }
1071
+
1072
+ return bestFit;
1073
+ }
1074
+
1046
1075
  if (!textNode._inlines || textNode._inlines.length === 0) {
1047
1076
  return null;
1048
1077
  }
@@ -1058,11 +1087,9 @@ LayoutBuilder.prototype.buildNextLine = function (textNode) {
1058
1087
  isForceContinue = false;
1059
1088
 
1060
1089
  if (!inline.noWrap && inline.text.length > 1 && inline.width > line.getAvailableWidth()) {
1061
- var widthPerChar = inline.width / inline.text.length;
1062
- var maxChars = Math.floor(line.getAvailableWidth() / widthPerChar);
1063
- if (maxChars < 1) {
1064
- maxChars = 1;
1065
- }
1090
+ var maxChars = findMaxFitLength(inline.text, line.getAvailableWidth(), function (txt) {
1091
+ return textTools.widthOfString(txt, inline.font, inline.fontSize, inline.characterSpacing, inline.fontFeatures)
1092
+ });
1066
1093
  if (maxChars < inline.text.length) {
1067
1094
  var newInline = cloneInline(inline);
1068
1095
 
package/src/textTools.js CHANGED
@@ -118,8 +118,19 @@ TextTools.prototype.widthOfString = function (text, font, fontSize, characterSpa
118
118
  return widthOfString(text, font, fontSize, characterSpacing, fontFeatures);
119
119
  };
120
120
 
121
- function splitWords(text, noWrap) {
121
+ function splitWords(text, noWrap, breakAll) {
122
+ if (breakAll === undefined) {
123
+ breakAll = false;
124
+ }
125
+
122
126
  var results = [];
127
+
128
+ if (text === undefined || text === null) {
129
+ text = '';
130
+ } else {
131
+ text = String(text);
132
+ }
133
+
123
134
  text = text.replace(/\t/g, ' ');
124
135
 
125
136
  if (noWrap) {
@@ -127,6 +138,19 @@ function splitWords(text, noWrap) {
127
138
  return results;
128
139
  }
129
140
 
141
+ if (text.length === 0) {
142
+ results.push({ text: '' });
143
+ return results;
144
+ }
145
+ if (breakAll) {
146
+ return text.split('').map(c => {
147
+ if(c.match(/^\n$|^\r$/)) { // new line
148
+ return { text: '', lineEnd: true };
149
+ }
150
+ return { text: c };
151
+ });
152
+ }
153
+
130
154
  var breaker = new LineBreaker(text);
131
155
  var last = 0;
132
156
  var bk;
@@ -205,15 +229,16 @@ function normalizeTextArray(array, styleContextStack) {
205
229
  var style = null;
206
230
  var words;
207
231
 
232
+ var breakAll = getStyleProperty(item || {}, styleContextStack, 'wordBreak', 'normal') === 'break-all';
208
233
  var noWrap = getStyleProperty(item || {}, styleContextStack, 'noWrap', false);
209
234
  if (isObject(item)) {
210
235
  if (item._textRef && item._textRef._textNodeRef.text) {
211
236
  item.text = item._textRef._textNodeRef.text;
212
237
  }
213
- words = splitWords(normalizeString(item.text), noWrap);
238
+ words = splitWords(normalizeString(item.text), noWrap, breakAll);
214
239
  style = copyStyle(item);
215
240
  } else {
216
- words = splitWords(normalizeString(item), noWrap);
241
+ words = splitWords(normalizeString(item), noWrap, breakAll);
217
242
  }
218
243
 
219
244
  if (lastWord && words.length) {