Skip to content

Commit 4cf3ab6

Browse files
authored
Fix parsing corrupt PNG images in the addImage method (#3880)
- remove atob and btoa dependencies and use native implementations for node build, as well - replace built-in PNG parser with the fast-png 3rd party dependency - consistently support 16bit color spaces - fix compression being applied with compression="NONE" in some cases
1 parent 7c51caa commit 4cf3ab6

28 files changed

+2268
-2246
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"rollup-plugin-license": "^2.1.0",
6868
"rollup-plugin-node-resolve": "4.2.3",
6969
"rollup-plugin-preprocess": "0.0.4",
70-
"rollup-plugin-terser": "^6.1.0",
70+
"@rollup/plugin-terser": "^0.4.4",
7171
"typescript": "^3.9.6"
7272
},
7373
"license": "MIT",

package-lock.json

Lines changed: 1785 additions & 1154 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@
2424
},
2525
"dependencies": {
2626
"@babel/runtime": "^7.26.9",
27-
"atob": "^2.1.2",
28-
"btoa": "^1.2.1",
29-
"fflate": "^0.8.1"
27+
"fflate": "^0.8.1",
28+
"fast-png": "^6.2.0"
3029
},
3130
"optionalDependencies": {
3231
"canvg": "^3.0.11",
@@ -40,6 +39,7 @@
4039
"@babel/preset-env": "^7.10.4",
4140
"@rollup/plugin-babel": "^5.3.0",
4241
"@rollup/plugin-replace": "^2.3.3",
42+
"@rollup/plugin-terser": "^0.4.4",
4343
"@rollup/plugin-typescript": "^8.0.0",
4444
"@types/jasmine": "^3.5.11",
4545
"@types/node": "^20.16.5",
@@ -82,7 +82,6 @@
8282
"rollup-plugin-license": "^2.1.0",
8383
"rollup-plugin-node-resolve": "5.2.0",
8484
"rollup-plugin-preprocess": "0.0.4",
85-
"rollup-plugin-terser": "^6.1.0",
8685
"typescript": "^5.6.2",
8786
"yarpm": "^0.2.1"
8887
},

rollup.config.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { terser } from "rollup-plugin-terser";
1+
import terser from "@rollup/plugin-terser";
22
import { babel } from "@rollup/plugin-babel";
33
import RollupPluginPreprocess from "rollup-plugin-preprocess";
44
import resolve from "rollup-plugin-node-resolve";
@@ -37,6 +37,19 @@ const umdExternals = matchSubmodules([
3737
...Object.keys(pkg.peerDependencies || {}),
3838
...Object.keys(pkg.optionalDependencies || {})
3939
]);
40+
41+
const terserOptions = {
42+
ecma: 2023,
43+
module: true,
44+
compress: {
45+
ecma: 2023,
46+
passes: 2
47+
},
48+
mangle: {
49+
safari10: true
50+
}
51+
};
52+
4053
const externals = matchSubmodules([
4154
...Object.keys(pkg.dependencies || {}),
4255
...Object.keys(pkg.peerDependencies || {}),
@@ -57,7 +70,7 @@ const umd = {
5770
file: "dist/jspdf.umd.min.js",
5871
format: "umd",
5972
name: "jspdf",
60-
plugins: [terser({})],
73+
plugins: [terser(terserOptions)],
6174
exports: "named",
6275
sourcemap: true
6376
}
@@ -88,7 +101,7 @@ const es = {
88101
format: "es",
89102
name: "jspdf",
90103
sourcemap: true,
91-
plugins: [terser({})]
104+
plugins: [terser(terserOptions)]
92105
}
93106
],
94107
external: externals,
@@ -117,7 +130,7 @@ const node = {
117130
name: "jspdf",
118131
exports: "named",
119132
sourcemap: true,
120-
plugins: [terser({})]
133+
plugins: [terser(terserOptions)]
121134
}
122135
],
123136
external: externals,
@@ -136,7 +149,7 @@ const umdPolyfills = {
136149
file: "dist/polyfills.umd.js",
137150
format: "umd",
138151
name: "jspdf-polyfills",
139-
plugins: [terser({})]
152+
plugins: [terser(terserOptions)]
140153
}
141154
],
142155
external: [],
@@ -159,7 +172,7 @@ const esPolyfills = {
159172
file: "dist/polyfills.es.js",
160173
format: "es",
161174
name: "jspdf-polyfills",
162-
plugins: [terser({})]
175+
plugins: [terser(terserOptions)]
163176
}
164177
],
165178
external: externals,

src/libs/AtobBtoa.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
import { globalObject } from "./globalObject.js";
22

3-
var atob, btoa;
4-
5-
(function() {
6-
// @if MODULE_FORMAT!='cjs'
7-
atob = globalObject.atob.bind(globalObject);
8-
btoa = globalObject.btoa.bind(globalObject);
9-
return;
10-
// @endif
11-
12-
// @if MODULE_FORMAT='cjs'
13-
atob = require("atob");
14-
btoa = require("btoa");
15-
// @endif
16-
})();
3+
const atob = globalObject.atob.bind(globalObject);
4+
const btoa = globalObject.btoa.bind(globalObject);
175

186
export { atob, btoa };

src/libs/fast-png.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { decode } from "fast-png";

0 commit comments

Comments
 (0)