package mml
import "github.com/d2lang/mathjax-go/internal/ordered"
type Property = any
type inheritValue struct {}
var Inherit Property = inheritValue {}
func isInherit(value Property ) bool {
_ , ok := value .(inheritValue )
return ok
}
func IsInherit (value Property ) bool { return isInherit (value ) }
type Attributes struct {
explicit *ordered .Map [Property ]
inherited *ordered .Map [Property ]
defaults *ordered .Map [Property ]
global *ordered .Map [Property ]
}
func NewAttributes (defaults , global *ordered .Map [Property ]) *Attributes {
return &Attributes {
explicit : ordered .New [Property ](),
inherited : ordered .New [Property ](),
defaults : defaults .Clone (),
global : global .Clone (),
}
}
func (a *Attributes ) Set (name string , value Property ) { a .explicit .Set (name , value ) }
func (a *Attributes ) SetList (list *ordered .Map [Property ]) {
list .Range (func (name string , value Property ) bool {
a .Set (name , value )
return true
})
}
func lookup(layers []*ordered .Map [Property ], name string ) (Property , bool ) {
for _ , layer := range layers {
if value , ok := layer .Get (name ); ok {
return value , true
}
}
return nil , false
}
func (a *Attributes ) Get (name string ) (Property , bool ) {
value , ok := lookup ([]*ordered .Map [Property ]{a .explicit , a .inherited , a .defaults , a .global }, name )
if ok && isInherit (value ) {
return a .global .Get (name )
}
return value , ok
}
func (a *Attributes ) GetExplicit (name string ) (Property , bool ) { return a .explicit .Get (name ) }
func (a *Attributes ) SetInherited (name string , value Property ) { a .inherited .Set (name , value ) }
func (a *Attributes ) GetInherited (name string ) (Property , bool ) {
return lookup ([]*ordered .Map [Property ]{a .inherited , a .defaults , a .global }, name )
}
func (a *Attributes ) GetDefault (name string ) (Property , bool ) {
return lookup ([]*ordered .Map [Property ]{a .defaults , a .global }, name )
}
func (a *Attributes ) IsSet (name string ) bool {
return a .explicit .Has (name ) || a .inherited .Has (name )
}
func (a *Attributes ) HasDefault (name string ) bool {
return a .defaults .Has (name ) || a .global .Has (name )
}
func (a *Attributes ) ExplicitNames () []string { return a .explicit .Keys () }
func (a *Attributes ) InheritedNames () []string { return a .inherited .Keys () }
func (a *Attributes ) DefaultNames () []string { return a .defaults .Keys () }
func (a *Attributes ) GlobalNames () []string { return a .global .Keys () }
func (a *Attributes ) Explicit () *ordered .Map [Property ] { return a .explicit }
func (a *Attributes ) Inherited () *ordered .Map [Property ] { return a .inherited }
func (a *Attributes ) Defaults () *ordered .Map [Property ] { return a .defaults }
func (a *Attributes ) Globals () *ordered .Map [Property ] { return a .global }
func (a *Attributes ) Clone () *Attributes {
if a == nil {
return NewAttributes (nil , nil )
}
return &Attributes {
explicit : a .explicit .Clone (),
inherited : a .inherited .Clone (),
defaults : a .defaults .Clone (),
global : a .global .Clone (),
}
}
The pages are generated with Golds v0.8.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .