Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

svg source pure

Package svg is a minimalist and extensible SVG generation library for Gno.

Overview

Package svg is a minimalist and extensible SVG generation library for Gno.

It provides a structured way to create and compose SVG elements such as rectangles, circles, text, paths, and more. The package is designed to be modular and developer-friendly, enabling optional attributes and method chaining for ease of use.

Each SVG element embeds a BaseAttrs struct, which supports common SVG attributes like `id`, `class`, `style`, `fill`, `stroke`, and `transform`.

Canvas objects represent the root SVG container and support global dimensions, viewBox configuration, embedded styles, and element composition.

Example:

Example
 1import "gno.land/p/demo/svg"
 2
 3func Foo() string {
 4	canvas := svg.NewCanvas(200, 200).WithViewBox(0, 0, 200, 200)
 5	canvas.AddStyle(".my-rect", "stroke:black;stroke-width:2")
 6	canvas.Append(
 7		svg.NewRectangle(60, 40, 100, 50, "red").WithClass("my-rect"),
 8		svg.NewCircle(50, 80, 40, "blue"),
 9		&svg.Path{D: `M 10,30
10		A 20,20 0,0,1 50,30
11			A 20,20 0,0,1  90,30
12			Q 90,60 50,90
13			Q 10,60 10,30 z`, Fill: "magenta"},
14		svg.NewText(20, 50, "Hello SVG", "black"),
15	)
16	mysvg := canvas.Base64()
17}

Functions 9

func NewCircle

1func NewCircle(cx, cy, r int, fill string) *Circle
source

func NewRectangle

1func NewRectangle(x, y, width, height int, fill string) *Rectangle
source

func NewText

1func NewText(x, y int, text, fill string) *Text
source

Types 11

type BaseAttrs

struct
 1type BaseAttrs struct {
 2	ID          string
 3	Class       string
 4	Style       string
 5	Stroke      string
 6	StrokeWidth string
 7	Opacity     string
 8	Transform   string
 9	Visibility  string
10}
source

Methods on BaseAttrs

func String

method on BaseAttrs
1func (b BaseAttrs) String() string
source

type Canvas

struct
1type Canvas struct {
2	Width, Height int
3	ViewBox       string
4	Elems         []Elem
5	Style         *avl.Tree
6}
source

Methods on Canvas

func AddStyle

method on Canvas
1func (c *Canvas) AddStyle(key, value string) *Canvas
source

func Append

method on Canvas
1func (c *Canvas) Append(elem ...Elem)
source

func Base64

method on Canvas
1func (c Canvas) Base64() string
source

func Render

method on Canvas
1func (c Canvas) Render(alt string) string
source

Render renders your canvas

func String

method on Canvas
1func (c Canvas) String() string
source

func WithViewBox

method on Canvas
1func (c *Canvas) WithViewBox(x, y, width, height int) *Canvas
source

type Circle

struct
1type Circle struct {
2	CX   int // center X
3	CY   int // center Y
4	R    int // radius
5	Fill string
6	Attr BaseAttrs
7}
source

Methods on Circle

func String

method on Circle
1func (c Circle) String() string
source

func WithClass

method on Circle
1func (c *Circle) WithClass(class string) *Circle
source

type Elem

interface
1type Elem interface{ String() string }
source

type Ellipse

struct
1type Ellipse struct {
2	CX   int // center X
3	CY   int // center Y
4	RX   int // radius X
5	RY   int // radius Y
6	Fill string
7	Attr BaseAttrs
8}
source

Methods on Ellipse

func String

method on Ellipse
1func (e Ellipse) String() string
source

func WithClass

method on Ellipse
1func (e *Ellipse) WithClass(class string) *Ellipse
source

type Group

struct
1type Group struct {
2	Elems []Elem
3	Fill  string
4	Attr  BaseAttrs
5}
source

Methods on Group

func Append

method on Group
1func (g *Group) Append(elem ...Elem)
source

func String

method on Group
1func (g Group) String() string
source

func WithClass

method on Group
1func (g *Group) WithClass(class string) *Group
source

type Path

struct
1type Path struct {
2	D    string
3	Fill string
4	Attr BaseAttrs
5}
source

Methods on Path

func String

method on Path
1func (p Path) String() string
source

func WithClass

method on Path
1func (p *Path) WithClass(class string) *Path
source

type Polygon

struct
1type Polygon struct {
2	Points string
3	Fill   string
4	Attr   BaseAttrs
5}
source

Methods on Polygon

func String

method on Polygon
1func (p Polygon) String() string
source

func WithClass

method on Polygon
1func (p *Polygon) WithClass(class string) *Polygon
source

type Polyline

struct
1type Polyline struct {
2	Points string
3	Fill   string
4	Attr   BaseAttrs
5}
source

Methods on Polyline

func String

method on Polyline
1func (p Polyline) String() string
source

func WithClass

method on Polyline
1func (p *Polyline) WithClass(class string) *Polyline
source

type Rectangle

struct
1type Rectangle struct {
2	X, Y, Width, Height int
3	RX, RY              int // corner radiuses
4	Fill                string
5	Attr                BaseAttrs
6}
source

Methods on Rectangle

func String

method on Rectangle
1func (r Rectangle) String() string
source

func WithClass

method on Rectangle
1func (r *Rectangle) WithClass(class string) *Rectangle
source

type Text

struct
1type Text struct {
2	X, Y       int
3	DX, DY     int // shift text pos horizontally/ vertically
4	Rotate     string
5	Text, Fill string
6	Attr       BaseAttrs
7}
source

Methods on Text

func String

method on Text
1func (c Text) String() string
source

func WithClass

method on Text
1func (c *Text) WithClass(class string) *Text
source

Imports 4

Source Files 5