larry babby and threejs for glsl

This commit is contained in:
Sam
2024-06-24 21:24:00 +12:00
parent 87d5dc634d
commit 907ebae4c0
6474 changed files with 1279596 additions and 8 deletions

View File

@@ -0,0 +1,30 @@
import { optionalImport } from '../helpers.mjs';
/** Minify SVG with SVGO */
export default async function minifySvg(tree, options, svgoOptions = {}) {
const svgo = await optionalImport('svgo');
if (!svgo) return tree;
tree.match({tag: 'svg'}, node => {
let svgStr = tree.render(node, { closingSingleTag: 'slash', quoteAllAttributes: true });
try {
const result = svgo.optimize(svgStr, svgoOptions);
node.tag = false;
node.attrs = {};
// result.data is a string, we need to cast it to an array
node.content = [result.data];
return node;
} catch (error) {
console.error('htmlnano fails to minify the svg:');
console.error(error);
if (error.name === 'SvgoParserError') {
console.error(error.toString());
}
// We return the node as-is
return node;
}
});
return tree;
}