import { bundledFontFor, fontFaceCss } from './chunk-AYLHMATI.js';
import { renderToStaticMarkup } from 'react-dom/server';

var FONT_FAMILY_ATTR = /font-family="([^"]*)"/g;
function decodeEntities(value) {
  return value.replace(/&quot;/g, '"').replace(/&#x27;|&#39;/g, "'").replace(/&amp;/g, "&");
}
function embeddedFontFaces(markup) {
  const byFamily = /* @__PURE__ */ new Map();
  for (const match of markup.matchAll(FONT_FAMILY_ATTR)) {
    const font = bundledFontFor(decodeEntities(match[1]));
    if (font && !byFamily.has(font.family)) byFamily.set(font.family, fontFaceCss(font));
  }
  if (byFamily.size === 0) return "";
  const rules = [...byFamily.keys()].sort().map((f) => byFamily.get(f)).join("");
  return `<style>${rules}</style>`;
}
function renderToSVGString(element) {
  const markup = renderToStaticMarkup(element);
  if (!markup.startsWith("<svg")) {
    throw new Error(
      "renderToSVGString expected a bare <svg> root. Pass `bare` to the chart or Surface."
    );
  }
  const fonts = embeddedFontFaces(markup);
  if (!fonts) return markup;
  const tagEnd = markup.indexOf(">") + 1;
  return markup.slice(0, tagEnd) + fonts + markup.slice(tagEnd);
}

export { renderToSVGString };
//# sourceMappingURL=server.js.map
//# sourceMappingURL=server.js.map