/** * `@nifrajs/web/plugins/svg` - import an SVG as a component: `import Icon from "./icon.svg?component"`, * then ``. Props spread onto the root ``, matching the * standard Vite `svgr` workflow. In its OWN module so the SSR preload registers it before any SVG * loads; pass `"dom"` for the client bundle and preload `"ssr"` for the server (both emit the same * isomorphic component). * * SCOPE: emits an **automatic-JSX-runtime** component, so it works out of the box for the frameworks * whose build supplies a `jsxImportSource` - **React and Preact**. Solid (needs `babel-preset-solid`), * Svelte, and Vue are not JSX and are intentionally out of v1; a plain `import "./icon.svg"` (asset URL) * is untouched - only the `?component` marker is intercepted. * * Optimization is optional: pass `svgo` (or install the `svgo` peer) to minify/clean the SVG first. * The transform is regex-based and targets the common icon-set shape (well-formed, self-closed tags); * it camelCases hyphenated + `xlink:`/`xmlns:` attributes, maps `class` → `className`, parses an inline * `style="..."` into an object, and drops XML declarations/comments so the result is valid JSX. */ import type { BunPlugin } from "bun"; /** The subset of the `svgo` API this plugin uses (structural, so no hard dependency on its types). */ export interface SvgOptimizer { optimize(input: string, options?: Record): { readonly data: string; }; } export interface SvgPluginOptions { /** Optimize each SVG first. `true` loads the `svgo` peer; pass an optimizer to inject one (or a stub). */ readonly svgo?: boolean | SvgOptimizer; } export interface SvgToJsxOptions { /** The JSX prop name for `class`. `"className"` for React/Preact; `"class"` for Solid. */ readonly classProp?: string; } /** * Strip the XML declaration, comments, and DOCTYPE from an SVG source by index scan. Shared by every * adapter's SVG-component transform instead of chained regex `replace`s, for two reasons: the lazy * `[\s\S]*?` scans backtrack quadratically on an unterminated marker, and sequential single-pass * replaces can splice removed delimiters back together (`<!DOCTYPE …>` survives them). The * scan removes each block in one forward pass, so neither failure mode exists. An unterminated * marker swallows the rest of the input - the correct reading, matching an XML parser. */ export declare function stripSvgPreamble(xml: string): string; /** Convert an SVG XML string into a JSX-safe `` element with `{...props}` spread on the root. */ export declare function svgToJsx(xml: string, options?: SvgToJsxOptions): string; /** Emit the component module source for a `?component` SVG import. Identical on dom + ssr (isomorphic). */ export declare function svgComponentSource(xml: string, options?: SvgToJsxOptions): string; /** The Bun `onLoad` filter every adapter's SVG-component plugin matches: `*.svg?component`. */ export declare const SVG_COMPONENT_FILTER: RegExp; /** * The SVG-as-component Bun plugin (React/Preact). `generate` is accepted for parity with the other * plugin pairs; the emitted component is the same on `"dom"` and `"ssr"`. */ export declare function svgComponentBunPlugin(_generate: "dom" | "ssr", options?: SvgPluginOptions): BunPlugin; //# sourceMappingURL=svg.d.ts.map