Spaces:
Running
Running
File size: 672 Bytes
30c32c8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
const {inlineSvgFonts} = require('scratch-svg-renderer');
const HAS_FONT_REGEXP = 'font-family(?!="none")';
const getCostumeUrl = asset => {
// If the SVG refers to fonts, they must be inlined in order to display correctly in the img tag.
// Avoid parsing the SVG when possible, since it's expensive.
if (asset.assetType.name === 'ImageVector') {
const svgString = asset.decodeText();
if (svgString.match(HAS_FONT_REGEXP)) {
const svgText = inlineSvgFonts(svgString);
return `data:image/svg+xml;utf8,${encodeURIComponent(svgText)}`;
}
}
return asset.encodeDataURI();
};
module.exports = getCostumeUrl;
|