blank project
This commit is contained in:
28
node_modules/astro/dist/assets/utils/svg.js
generated
vendored
Normal file
28
node_modules/astro/dist/assets/utils/svg.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
import { parse, renderSync } from "ultrahtml";
|
||||
import { dropAttributes } from "../runtime.js";
|
||||
function parseSvg(contents) {
|
||||
const root = parse(contents);
|
||||
const svgNode = root.children.find(
|
||||
({ name, type }) => type === 1 && name === "svg"
|
||||
);
|
||||
if (!svgNode) {
|
||||
throw new Error("SVG file does not contain an <svg> element");
|
||||
}
|
||||
const { attributes, children } = svgNode;
|
||||
const body = renderSync({ ...root, children });
|
||||
return { attributes, body };
|
||||
}
|
||||
function makeSvgComponent(meta, contents) {
|
||||
const file = typeof contents === "string" ? contents : contents.toString("utf-8");
|
||||
const { attributes, body: children } = parseSvg(file);
|
||||
const props = {
|
||||
meta,
|
||||
attributes: dropAttributes(attributes),
|
||||
children
|
||||
};
|
||||
return `import { createSvgComponent } from 'astro/assets/runtime';
|
||||
export default createSvgComponent(${JSON.stringify(props)})`;
|
||||
}
|
||||
export {
|
||||
makeSvgComponent
|
||||
};
|
||||
Reference in New Issue
Block a user