sprite

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const EmptyWrapper = `<svg aria-hidden="true" style="display:none"></svg>`

EmptyWrapper is the markup a sprite with zero icons renders as. The document that injects a sprite needs a stable insertion point, so an empty sprite must still emit its wrapper. Composing this outside forces every consumer to duplicate the markup — which is exactly what assetmin used to do.

Variables

This section is empty.

Functions

This section is empty.

Types

type Definition

type Definition struct {
	Icon    svg.Icon
	ViewBox string
	Body    string
}

Definition holds the data needed to build a <symbol>.

func Define

func Define(icon svg.Icon, viewBox string, body ...Node) Definition

Define creates a reusable icon definition.

type Node

type Node string

Node is internal typed markup for a symbol's body.

func Path

func Path(d string) Node

Path renders <path fill="currentColor" d="<d>"/>.

func Raw

func Raw(s string) Node

Raw is an escape hatch for markup that Path does not express.

type Sprite

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

Sprite holds SVG icon definitions for server-side sprite sheet injection.

func MergeAll added in v0.1.21

func MergeAll(sprites ...*Sprite) *Sprite

MergeAll merges sprites in order, keeping the first occurrence of each icon ID. This is the single home of the ecosystem's deduplication policy: consumers merging per package or per module call here instead of reimplementing it.

The caller decides the ORDER (sitec sorts by module name so the result is stable across scans); this function owns the POLICY.

nil entries are ignored. The result is always a fresh, non-nil *Sprite: no argument is mutated and no argument's pointer is returned.

func NewSprite

func NewSprite(icons ...Definition) *Sprite

NewSprite constructs a *Sprite from typed icons.

func (*Sprite) AddFile added in v0.1.3

func (s *Sprite) AddFile(id, svgFile string) error

AddFile adds a whole .svg file (as read from disk) to the sprite as a <symbol>. The viewBox is taken from the file's root <svg> element, and only its inner markup becomes the symbol body — keeping the root tag would nest an <svg> inside the <symbol>, which is not valid sprite markup.

A file with no viewBox is rejected: nothing can recover the coordinate system the drawing was authored in, and defaulting to one clips or misaligns it.

func (*Sprite) AddRaw

func (s *Sprite) AddRaw(id, content, viewBox string)

AddRaw adds a raw symbol to the sprite. Used for assetmin's raw .svg file/favicon path.

func (*Sprite) Append

func (s *Sprite) Append() model.Fielder

Append appends a new Definition to the sprite and returns its Fielder.

func (*Sprite) At

func (s *Sprite) At(i int) model.Fielder

At returns the Fielder at index i.

func (*Sprite) DecodeFields

func (s *Sprite) DecodeFields(r model.FieldReader)

DecodeFields decodes the sprite fields.

func (*Sprite) EncodeFields

func (s *Sprite) EncodeFields(w model.FieldWriter)

EncodeFields encodes the sprite fields.

func (*Sprite) Has added in v0.1.21

func (s *Sprite) Has(id string) bool

Has reports whether the sprite already contains an icon with that ID. A nil sprite contains nothing.

func (*Sprite) IDs added in v0.1.21

func (s *Sprite) IDs() []string

IDs returns the icon IDs held, in insertion order. A nil sprite returns nil.

func (*Sprite) Icons added in v0.1.8

func (s *Sprite) Icons() []Definition

Icons returns a copy of the sprite's typed icon definitions. Callers that need to inspect or recombine icons (e.g. assetmin merging per-module sprites) read this instead of round-tripping through String().

func (*Sprite) IsNil

func (s *Sprite) IsNil() bool

IsNil reports whether the sprite is nil.

func (*Sprite) Len

func (s *Sprite) Len() int

Len returns the number of icons in the sprite.

func (*Sprite) MarshalJSON

func (s *Sprite) MarshalJSON() ([]byte, error)

MarshalJSON serializes the Sprite to JSON using tinywasm/json.

func (*Sprite) Merge

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

Merge returns a NEW sprite holding s's icons followed by other's, keeping the first occurrence of each ID. It never mutates s or other, and never returns a pointer it was given: the caller always gets a sprite of its own.

The previous version appended in place and returned `other` unchanged when the receiver was nil. That aliased the first package's cached sprite, and the next merge corrupted it — icons duplicated on some rebuilds and whole modules' symbols stopped appearing once the consumer deduped downstream.

func (*Sprite) Pointers

func (s *Sprite) Pointers() []any

Pointers returns pointers to fields.

func (*Sprite) Schema

func (s *Sprite) Schema() []model.Field

Schema returns the model schema.

func (*Sprite) String

func (s *Sprite) String() string

String renders the sprite as inline SVG with all <symbol> elements. A sprite with zero icons renders EmptyWrapper, not an empty string: the document that injects it needs a stable insertion point. A nil sprite renders "" — there is no sprite to speak of.

func (*Sprite) UnmarshalJSON

func (s *Sprite) UnmarshalJSON(b []byte) error

UnmarshalJSON deserializes the Sprite from JSON using tinywasm/json.

Jump to

Keyboard shortcuts

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