// Package tokencheck is the shared half of every component's // "...UseDefinedTokens" test: each var(--rst-*) a component stylesheet // reads must be defined by the pinned rastrillo's tokens.css plus // estilo's theme. AGENTS.md's two-pin case, for components. package tokencheck import ( "regexp" "amadan.net/oficina/estilo.git/theme" "github.com/carlosframework/rastrillo/ui" ) var ( definition = regexp.MustCompile(`(--rst-[a-z0-9-]+)\s*:`) reference = regexp.MustCompile(`var\(\s*(--rst-[a-z0-9-]+)`) ) // Undefined returns the rastrillo tokens css reads that neither // ui.TokensCSS() nor theme.CSS() defines, and how many references it // read in total, so a caller can refuse a stylesheet that reads none // (a check over nothing passes vacuously). func Undefined(css []byte) (missing []string, references int) { defined := map[string]bool{} for _, m := range definition.FindAllSubmatch(append(append([]byte{}, ui.TokensCSS()...), theme.CSS()...), -1) { defined[string(m[1])] = true } for _, m := range reference.FindAllSubmatch(css, -1) { references++ if !defined[string(m[1])] { missing = append(missing, string(m[1])) } } return missing, references }