Upgrade to fabric 6 (#29334)
Upgrade fabric to latest v6 beta. It works for our use case, even thought it does not fix the upstream issue https://github.com/fabricjs/fabric.js/issues/9679 that https://github.com/go-gitea/gitea/issues/29326 relates to. (cherry picked from commit c4b0cb4d0d527793296cf801e611f77666f86551) Conflicts: public/assets/img/favicon.svg public/assets/img/logo.svg
This commit is contained in:
parent
c432f141bb
commit
643d66ee0e
2 changed files with 12 additions and 19 deletions
2
Makefile
2
Makefile
|
@ -1009,7 +1009,7 @@ generate-gitignore:
|
||||||
|
|
||||||
.PHONY: generate-images
|
.PHONY: generate-images
|
||||||
generate-images: | node_modules
|
generate-images: | node_modules
|
||||||
npm install --no-save --no-package-lock fabric@5 imagemin-zopfli@7
|
npm install --no-save fabric@6.0.0-beta19 imagemin-zopfli@7
|
||||||
node build/generate-images.js $(TAGS)
|
node build/generate-images.js $(TAGS)
|
||||||
|
|
||||||
.PHONY: generate-manpage
|
.PHONY: generate-manpage
|
||||||
|
|
|
@ -1,20 +1,13 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
import imageminZopfli from 'imagemin-zopfli';
|
import imageminZopfli from 'imagemin-zopfli';
|
||||||
import {optimize} from 'svgo';
|
import {optimize} from 'svgo';
|
||||||
import {fabric} from 'fabric';
|
import {loadSVGFromString, Canvas, Rect, util} from 'fabric/node';
|
||||||
import {readFile, writeFile} from 'node:fs/promises';
|
import {readFile, writeFile} from 'node:fs/promises';
|
||||||
|
import {argv, exit} from 'node:process';
|
||||||
|
|
||||||
function exit(err) {
|
function doExit(err) {
|
||||||
if (err) console.error(err);
|
if (err) console.error(err);
|
||||||
process.exit(err ? 1 : 0);
|
exit(err ? 1 : 0);
|
||||||
}
|
|
||||||
|
|
||||||
function loadSvg(svg) {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
fabric.loadSVGFromString(svg, (objects, options) => {
|
|
||||||
resolve({objects, options});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function generate(svg, path, {size, bg}) {
|
async function generate(svg, path, {size, bg}) {
|
||||||
|
@ -35,14 +28,14 @@ async function generate(svg, path, {size, bg}) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const {objects, options} = await loadSvg(svg);
|
const {objects, options} = await loadSVGFromString(svg);
|
||||||
const canvas = new fabric.Canvas();
|
const canvas = new Canvas();
|
||||||
canvas.setDimensions({width: size, height: size});
|
canvas.setDimensions({width: size, height: size});
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
ctx.scale(options.width ? (size / options.width) : 1, options.height ? (size / options.height) : 1);
|
ctx.scale(options.width ? (size / options.width) : 1, options.height ? (size / options.height) : 1);
|
||||||
|
|
||||||
if (bg) {
|
if (bg) {
|
||||||
canvas.add(new fabric.Rect({
|
canvas.add(new Rect({
|
||||||
left: 0,
|
left: 0,
|
||||||
top: 0,
|
top: 0,
|
||||||
height: size * (1 / (size / options.height)),
|
height: size * (1 / (size / options.height)),
|
||||||
|
@ -51,7 +44,7 @@ async function generate(svg, path, {size, bg}) {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
canvas.add(fabric.util.groupSVGElements(objects, options));
|
canvas.add(util.groupSVGElements(objects, options));
|
||||||
canvas.renderAll();
|
canvas.renderAll();
|
||||||
|
|
||||||
let png = Buffer.from([]);
|
let png = Buffer.from([]);
|
||||||
|
@ -64,7 +57,7 @@ async function generate(svg, path, {size, bg}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const gitea = process.argv.slice(2).includes('gitea');
|
const gitea = argv.slice(2).includes('gitea');
|
||||||
const logoSvg = await readFile(new URL('../assets/logo.svg', import.meta.url), 'utf8');
|
const logoSvg = await readFile(new URL('../assets/logo.svg', import.meta.url), 'utf8');
|
||||||
const faviconSvg = await readFile(new URL('../assets/favicon.svg', import.meta.url), 'utf8');
|
const faviconSvg = await readFile(new URL('../assets/favicon.svg', import.meta.url), 'utf8');
|
||||||
|
|
||||||
|
@ -80,7 +73,7 @@ async function main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
exit(await main());
|
doExit(await main());
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
exit(err);
|
doExit(err);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue