package svg

Import Path
	github.com/pancsta/d2/lib/svg (on go.dev)

Dependency Relation
	imports 10 packages, and imported by 10 packages


Package-Level Type Names (total 6)
/* sort by: | */
Attribute is an SVG attribute whose name has been validated and whose value is escaped when rendered. Its fields are intentionally private so callers cannot accidentally construct an unescaped attribute fragment. Name returns the validated attribute name. Values remain private so they cannot be serialized without escaping. func Attr(name, value string) Attribute func FloatAttr(name string, value float64) Attribute func HrefAttributes(value string) []Attribute func IntAttr(name string, value int) Attribute func ParseAttributes(fragment string) ([]Attribute, error) func CompactEmptyElement(name string, attributes ...Attribute) string func EmptyElement(name string, attributes ...Attribute) string func OpenElement(name string, attributes ...Attribute) string func RenderAttributes(attributes ...Attribute) string func github.com/pancsta/d2/d2renderers/d2sketch.ConnectionWithAttributes(connection d2target.Connection, path string, attributes []Attribute) (string, error) func github.com/pancsta/d2/d2themes.(*ThemableElement).AddAttributes(attributes ...Attribute)
Fragment is content that is already safe to place between SVG element tags. Use Text for untrusted strings and TrustedFragment only for renderer-generated SVG. ( Fragment) String() string Fragment : expvar.Var Fragment : fmt.Stringer func Join(fragments ...Fragment) Fragment func Text(value string) Fragment func TrustedFragment(value string) Fragment func Join(fragments ...Fragment) Fragment func github.com/pancsta/d2/d2themes.(*ThemableElement).SetInnerSVG(content Fragment)
ID is an identifier that is safe to use both as an XML id and in an unquoted local IRI such as url(#identifier). ( ID) String() string ID : expvar.Var ID : fmt.Stringer func EncodedID(value string) ID func LiteralID(value string) ID func ParseLocalIRI(value string) (ID, error) func ScopedID(prefix, component, suffix string) ID func LocalIRI(id ID) string func github.com/pancsta/d2/d2themes.(*ThemableElement).SetClipPathID(id ID) func github.com/pancsta/d2/d2themes.(*ThemableElement).SetMaskID(id ID)
PathCommand contains absolute path geometry. End is used by move, line, and cubic commands. Control1 and Control2 are additionally used by cubic commands. Control1 geo.Point Control2 geo.Point End geo.Point Kind PathCommandKind func (*SvgPathContext).PathCommands() []PathCommand func github.com/pancsta/d2/lib/shape.GetPathCommands(s shape.Shape) [][]PathCommand func github.com/pancsta/d2/lib/shape.PathCommandProvider.GetPathCommands() [][]PathCommand
PathCommandKind identifies one of the renderer-neutral path operations produced by SvgPathContext. SvgPathContext normalizes horizontal and vertical SVG commands to PathCommandLine so consumers only need to handle absolute move, line, cubic, and close operations. const PathCommandClose const PathCommandCubic const PathCommandLine const PathCommandMove
Commands []string Current *geo.Point Path []geo.Intersectable ScaleX float64 ScaleY float64 Start *geo.Point TopLeft *geo.Point (*SvgPathContext) Absolute(x, y float64) *geo.Point (*SvgPathContext) C(isLowerCase bool, x1, y1, x2, y2, x3, y3 float64) (*SvgPathContext) H(isLowerCase bool, x float64) (*SvgPathContext) L(isLowerCase bool, x, y float64) PathCommands returns a defensive copy of the absolute typed path commands. (*SvgPathContext) PathData() string (*SvgPathContext) Relative(base *geo.Point, dx, dy float64) *geo.Point (*SvgPathContext) StartAt(p *geo.Point) (*SvgPathContext) V(isLowerCase bool, y float64) (*SvgPathContext) Z() func NewSVGPathContext(tl *geo.Point, sx, sy float64) *SvgPathContext
Package-Level Functions (total 27)
Attr constructs an SVG attribute. The name must be a static XML attribute name and must not be an event-handler attribute. Invalid names panic because attribute names are a programmer-controlled part of the renderer, never diagram input.
Given control points p1, p2, p3, p4, calculate the segment of this bezier curve from t0 -> t1 where {0 <= t0 < t1 <= 1}. Uses De Casteljau's algorithm, referenced: https://stackoverflow.com/questions/11703283/cubic-bezier-curve-segment/11704152#11704152
CompactEmptyElement is equivalent to EmptyElement but preserves the compact `/>` syntax used by older renderer output.
func EmptyElement(name string, attributes ...Attribute) string
EncodedID encodes an arbitrary non-empty value using SVGID's stable base32 representation.
EscapeAttribute escapes a value for use in a double-quoted XML attribute. Single quotes are left unchanged because they cannot terminate that context. XML attribute whitespace is escaped so parsing preserves the original value.
func FloatAttr(name string, value float64) Attribute
FormatFloat serializes an SVG coordinate with the same six decimal places as %f, but omits redundant trailing zeros. Keeping the original rounding is important: formatting the full float or reducing precision changes geometry.
func GetStrokeDashAttributes(strokeWidth, dashGapSize float64) (float64, float64)
HrefAttributes returns the SVG 2 href attribute and its SVG 1.1 compatibility equivalent. This function only serializes the URL; callers must continue to apply the appropriate link or asset policy first.
func IntAttr(name string, value int) Attribute
IsSupportedExternalDoctype reports whether directive is the encoding/xml token for one canonical W3C SVG 1.0 or SVG 1.1 external DOCTYPE declaration in document's raw prolog. Requiring both inputs prevents encoding/xml's directive normalization from widening the accepted raw syntax. It accepts no internal subset and performs no DTD resolution. Callers remain responsible for enforcing that the declaration occurs at most once and before the root.
func Join(fragments ...Fragment) Fragment
LiteralID constructs an ID from a renderer-generated value. It panics if the value contains syntax that could change the meaning of a local IRI.
LocalIRI returns an SVG local-resource reference for id.
OpenElement and EmptyElement serialize element boundaries while validating the renderer-controlled tag name.
ParseAttributes converts the legacy textual attribute-list form into typed attributes. It rejects malformed XML, duplicate attributes, and event handlers instead of copying the fragment into renderer output.
ParseLocalIRI validates the deprecated textual local-reference form.
RenderAttributes serializes attributes in the supplied order. The returned string is empty or begins with one space, so it can be appended directly to an opening element name.
ScopedID builds a stable identifier from trusted prefix/suffix strings and an arbitrary component. Ordinary safe components retain their spelling. Unsafe values and values beginning with the reserved encoding prefix are base32 encoded, keeping the mapping injective without changing common IDs.
Splits an SVG path into two SVG paths, with the first path being ~{percentage}% of the path
func SVGID(text string) string
func Text(value string) Fragment