UNPKG

uinix-ui

Version:

A minimal configurable framework-agnostic UI system to build UI systems. Your system, your rules 🤘.

31 lines (26 loc) • 597 B
import {toH} from 'hast-to-hyperscript'; import {parse} from 'svg-parser'; export {parseSvgElement}; /** * @typedef {import('../types.js').H} HH */ /** * Renders an SVG string with the provided `h` element and returns an SVG element. * * @template {HH} H * @param {object} options * @param {H} options.h * @param {string} [options.svg] * @returns {ReturnType<H> | null} */ const parseSvgElement = ({h, svg}) => { if (!svg) { return null; } try { return toH(h, parse(svg)); } catch { // Swallow error and return null if SVG fails to parse. return null; } };