Builtin Library
README.md
svg
Inline vector graphics widget. Wraps a single svg node that
rasterizes an SVG document at the element's display resolution, so it
stays crisp from a 16px line icon to a 600px chart. Sizing comes from
style.width / style.height; opts.fit chooses the viewBox mapping.
Exports
svg(source: string?, opts: SvgOpts?) -> WidgetNode— module returns the builder function directly.
Options:
id: string?— widget id.style: table?— passes through to the underlying node; supplywidth/heighthere, andcolorto inkfill="currentColor".fit: string?— viewBox mapping:"meet"(default, uniform + letterbox),"none"/"stretch"(fill both axes),"slice"(uniform + crop).preserveAspectRatiokeywords (e.g."xMidYMid meet") are accepted too.src: string?— render a.svgtexture-asset reference instead of an inlinesourcestring.
Usage
local Z = require("@builtin::modules.zui")
-- Inline document; currentColor inks the element's CSS color.
Z.svg("<svg viewBox='0 0 24 24'><path d='M4 12h16' stroke='currentColor' stroke-width='2'/></svg>", {
style = { width = 24, height = 24, color = "#3b82f6" },
})
-- From a .svg asset file.
Z.svg(nil, { src = "@builtin::icons.logo", style = { width = 64, height = 64 } })
Notes
- Stateless — returns a fresh widget table each call.
fill="currentColor"resolves to the element's CSScolor;fill/strokegradients, the full path grammar, basic shapes,viewBox,preserveAspectRatio, and<g>grouping all render.- Pass either an inline
sourcestring oropts.src—sourceis the document text,srcpoints at a.svgasset file. - Rasterization happens at the resolved display size, so scaling the widget re-renders sharp rather than sampling a fixed bitmap.