@zsnout/ithkuil
Version:
A set of tools which can generate and parse romanized Ithkuil text and which can generate Ithkuil script from text and JSON data.
36 lines (35 loc) • 971 B
JavaScript
import { jsx as _jsx } from "@zsnout/ithkuil-jsx/jsx-runtime";
let svg;
/**
* Gets the bounding box of an SVG graphics element.
*
* @param element The node to get the bounding box of.
* @returns The bounding box (in SVG units) of the element.
*/
export function getBBox(element) {
if (!svg) {
svg = (_jsx("svg", {}));
}
const nextSibling = element.nextSibling;
const parent = element.parentNode;
svg.append(element);
document.body.append(svg);
const box = element.getBBox();
svg.remove();
if (parent) {
parent.insertBefore(element, nextSibling);
}
return box;
}
/**
* Gets the bounding box of an SVG element.
*
* @param element The node to get the bounding box of.
* @returns The bounding box (in SVG units) of the element.
*/
export function forceGetBBox(node) {
if (node instanceof SVGGraphicsElement) {
return getBBox(node);
}
return getBBox((_jsx("g", { children: node })));
}