Documentation
¶
Index ¶
- Constants
- type Definition
- type Node
- type Sprite
- func (s *Sprite) AddFile(id, svgFile string) error
- func (s *Sprite) AddRaw(id, content, viewBox string)
- func (s *Sprite) Append() model.Fielder
- func (s *Sprite) At(i int) model.Fielder
- func (s *Sprite) DecodeFields(r model.FieldReader)
- func (s *Sprite) EncodeFields(w model.FieldWriter)
- func (s *Sprite) Has(id string) bool
- func (s *Sprite) IDs() []string
- func (s *Sprite) Icons() []Definition
- func (s *Sprite) IsNil() bool
- func (s *Sprite) Len() int
- func (s *Sprite) MarshalJSON() ([]byte, error)
- func (s *Sprite) Pointers() []any
- func (s *Sprite) Schema() []model.Field
- func (s *Sprite) String() string
- func (s *Sprite) UnmarshalJSON(b []byte) error
Constants ¶
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 ¶
Definition holds the data needed to build a <symbol>.
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
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
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 ¶
AddRaw adds a raw symbol to the sprite. Used for assetmin's raw .svg file/favicon path.
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
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
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) MarshalJSON ¶
MarshalJSON serializes the Sprite to JSON using tinywasm/json.
func (*Sprite) 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 ¶
UnmarshalJSON deserializes the Sprite from JSON using tinywasm/json.