svg

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 2 Imported by: 0

README

svg

Svg managment api for TinyWasm App

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Icon

func Icon(iconID string, classes ...string) *dom.Element

Icon creates an <svg><use href="#iconID"></svg> sprite reference. This is the canonical way to use an icon from the sprite sheet in Render().

Example:

Icon("home", "nav-icon")
// → <svg aria-hidden='true' focusable='false' class='nav-icon'><use href='#home'></use></svg>

func Svg

func Svg(children ...any) *dom.Element

Svg builds an <svg> element.

func Use

func Use(children ...any) *dom.Element

Use builds a <use> element for referencing sprite symbols.

Types

type Sprite

type Sprite struct {
	// contains filtered or unexported fields
}

Sprite holds SVG icon definitions for server-side sprite sheet injection. Build with New() and chain Add() calls. assetmin injects Sprite.String() inline at the top of <body>.

func New

func New() *Sprite

New creates an empty Sprite.

func (*Sprite) Add

func (s *Sprite) Add(id, content string, viewBox ...string) *Sprite

Add registers an icon. id: referenced in Icon("id") and <use href="#id"> content: inner SVG (NOT the wrapping <svg> tag) — must use fill="currentColor" viewBox: optional, defaults to "0 0 16 16"

func (*Sprite) Merge

func (s *Sprite) Merge(other *Sprite) *Sprite

Merge adds all icons from other into s. Used by assetmin to accumulate icons from multiple components into one master sprite.

func (*Sprite) String

func (s *Sprite) String() string

String renders the sprite as inline SVG with all <symbol> elements. Called by assetmin to inject at the top of <body>.

type SvgProvider

type SvgProvider interface {
	IconSvg() *Sprite
}

SvgProvider is an optional capability: components that expose SVG icons for the global sprite sheet injected inline in <body> during SSR.

Implement in a component's svg.go file (//go:build !wasm).

Example in mycomponent/svg.go:

//go:build !wasm
package mycomponent
import "github.com/tinywasm/svg"

func (c *MyComponent) IconSvg() *svg.Sprite {
    return svg.New().
        Add("my-icon", `<path fill="currentColor" d="M0 0l16 16z"/>`)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL