package tss import "os" import "git.tebibyte.media/tomo/tomo" import "git.tebibyte.media/tomo/tomo/event" type Sheet struct { Variables map[string] ValueList Rules []Rule flat bool } type Rule struct { Selector Selector Attrs map[string] []ValueList } type Selector struct { Package string Object string Tags []string } type ValueList []Value type Value interface { value () } type ValueNumber int func (ValueNumber) value () { } type ValueColor uint32 func (ValueColor) value () { } func (value ValueColor) RGBA () (r, g, b, a uint32) { // extract components bits := uint32(value) r = (bits & 0xF000) >> 24 g = (bits & 0x0F00) >> 16 b = (bits & 0x00F0) >> 8 a = (bits & 0x000A) // extend to 16 bits per channel r = r << 8 | r g = g << 8 | g b = b << 8 | b a = a << 8 | a // alpha premultiply r = (r * a) / 256 g = (g * a) / 256 b = (b * a) / 256 return } type ValueString string func (ValueString) value () { } type ValueKeyword string func (ValueKeyword) value () { } type ValueVariable string func (ValueVariable) value () { } type ValueCut struct { } func (ValueCut) value () { } // LoadFile loads the stylesheet from the specified file. This may return a // parse.Error, so use parse.Format to print it. func LoadFile (name string) (*tomo.Style, event.Cookie, error) { // TODO check cache for gobbed sheet. if the cache is nonexistent or // invalid, then open/load/cache. file, err := os.Open(name) if err != nil { return nil, nil, err } defer file.Close() sheet, err := Parse(Lex(name, file)) if err != nil { return nil, nil, err } return BuildStyle(sheet) }