of allowed literal tokens. var CSS_LIT_GROUP = [["auto",...],...]; var CSS_REGEX = [/^...$/]; var cssSchema = { "float": { // Describe the kinds of tokens that can appear in the named // property's value and any additional restrictions. cssPropBits: CSS_PROP_BIT_x | CSS_PROP_BIT_y | ..., // Groups of literal values allowed including keywords and specific // numeric values like font-weight:300 cssLitGroup: [CSS_LIT_GROUP[1],CSS_LIT_GROUP[3],CSS_LIT_GROUP[16]], // Schema keys for functions that are allowed (non-transitively). cssFns: [] }, ... // Functions are top-level constructs that have their own filters which // can be applied to their actuals. "rgba()": { ... }, ... };
Program Flow
This class examines a schema and builds a list of all allowed CSS properties, * and each function. It then tries to deduce for each property value and function the set of keywords/literal token values, how to interpret quoted strings, and what to do with loose identifiers that do not match a known keyword.
Once it has collections of keywords/literal-tokens, it tries to group commonly co-occuring literal-tokens together to reduce download size. Finally, it identifies patterns like {@code border-top} and{@code border-bottom} which have identical results.
Finally it builds a javascript parse tree that assigns the {@code css}namespace to an object whose keys are CSS property names, and whose values are data maps similar to the example code above.
"sanitize-css.js" uses this map extensively to sanitize & normalize CSS properties, rewriting URIs as needed.
@author mikesamuel@gmail.com