Skip to content

Commit 99b401a

Browse files
authored
Merge pull request #3225 from metabrainz/dependabot/npm_and_yarn/canvg-4.0.3
Bump canvg from 4.0.1 to 4.0.3
2 parents 63f0161 + af06295 commit 99b401a

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

frontend/js/src/explore/art-creator/utils.tsx

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Canvg, RenderingContext2D, presets } from "canvg";
22

3+
const offscreenPreset = presets.offscreen();
34
export async function svgToBlob(
45
width: number,
56
height: number,
@@ -20,24 +21,29 @@ export async function svgToBlob(
2021
if (!ctx) {
2122
throw new Error("No canvas context");
2223
}
23-
const v = await Canvg.fromString(
24-
ctx as RenderingContext2D,
25-
svgString,
26-
presets.offscreen()
27-
);
24+
const v = Canvg.fromString(ctx as RenderingContext2D, svgString, {
25+
...offscreenPreset,
26+
// Overwrite the Canvg typescript types here, replace once this Canvg ticket is resolved:
27+
// https://github.com/canvg/canvg/issues/1754
28+
createCanvas: offscreenPreset.createCanvas as () => OffscreenCanvas & {
29+
getContext(contextId: "2d"): OffscreenCanvasRenderingContext2D;
30+
},
31+
});
2832

2933
// Render only first frame, ignoring animations and mouse.
3034
await v.render();
3135

3236
let blob;
3337
if ("OffscreenCanvas" in window) {
34-
blob = await (canvas as OffscreenCanvas).convertToBlob({
38+
canvas = canvas as OffscreenCanvas;
39+
blob = await canvas.convertToBlob({
3540
type: encodeType,
3641
});
3742
} else {
3843
blob = await new Promise<Blob | null>((done, err) => {
3944
try {
40-
(canvas as HTMLCanvasElement).toBlob(done, encodeType);
45+
canvas = canvas as HTMLCanvasElement;
46+
canvas.toBlob(done, encodeType);
4147
} catch (error) {
4248
err(error);
4349
}

package-lock.json

+8-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"@tanstack/react-query-devtools": "^5.28.6",
5959
"@types/react-datetime-picker": "^3.4.1",
6060
"blobs": "^2.3.0-beta.2",
61-
"canvg": "^4.0.1",
61+
"canvg": "^4.0.3",
6262
"core-js": "^3.26.1",
6363
"d3-array": "~2.3.3",
6464
"d3-format": "^1.4.4",
@@ -133,6 +133,7 @@
133133
"@types/jest": "^29.5.3",
134134
"@types/less": "^3.0.3",
135135
"@types/lodash": "^4.14.149",
136+
"@types/offscreencanvas": "^2019.7.3",
136137
"@types/react": "^18.0.25",
137138
"@types/react-dom": "^18.0.8",
138139
"@types/react-helmet": "^6.1.11",

0 commit comments

Comments
 (0)