UNPKG

astro

Version:

Astro is a modern site builder with web best practices, performance, and DX front-of-mind.

40 lines (39 loc) 1.17 kB
import { createComponent, render, spreadAttributes, unescapeHTML } from "../runtime/server/index.js"; function createSvgComponent({ meta, attributes, children }) { const Component = createComponent((_, props) => { const normalizedProps = normalizeProps(attributes, props); return render`<svg${spreadAttributes(normalizedProps)}>${unescapeHTML(children)}</svg>`; }); if (import.meta.env.DEV) { makeNonEnumerable(Component); Object.defineProperty(Component, Symbol.for("nodejs.util.inspect.custom"), { value: (_, opts, inspect) => inspect(meta, opts) }); } return Object.assign(Component, meta); } const ATTRS_TO_DROP = ["xmlns", "xmlns:xlink", "version"]; const DEFAULT_ATTRS = {}; function dropAttributes(attributes) { for (const attr of ATTRS_TO_DROP) { delete attributes[attr]; } return attributes; } function normalizeProps(attributes, props) { return dropAttributes({ ...DEFAULT_ATTRS, ...attributes, ...props }); } function makeNonEnumerable(object) { for (const property in object) { Object.defineProperty(object, property, { enumerable: false }); } } export { createSvgComponent, dropAttributes };