Open dwarring opened 5 years ago
Some initial thought on what the data-structures might look like.
use NativeCall;
enum Types ( :f, :d, :l, :s, :rgb, :rgba, :hsl, :hsla );
enum Flags ( :important(1), :inherit(2), :initial(4) );
class CSSColor is repr('CStruct') {
# three color channels
has uint32 $.c1;
has uint32 $.c2;
has uint32 $.c3;
has uint32 $.alpha;
}
class CSSValue is repr('CUnion') {
has num64 $.f;
has uint32 $.d;
has long $.l;
has Str $.s;
has CSSColor $.rgb;
has CSSColor $.rgba;
has CSSColor $.hsl;
has CSSColor $.hsla;
}
class CSSProp is repr('CStruct') {
has uint8 $.prop;
has uint8 $.flags;
has CSSProp $.next;
has CSSValue $.value;
has uint8 $.type; # Types enum
has uint8 $.units;
}
class CSSBox is repr('CStruct') {
has uint8 $.prop;
has uint8 $.flags;
has CSSProp $.next;
has CSSProp $.bottom;
has CSSProp $.left;
has CSSProp $.top;
has CSSProp $.right;
}
The beauty is that there is only a finite number of properties, so we only needs arrays, and to map property names to numbers.
I'm pretty sure this can be made to run much faster with the appropriate use of native representations and some C binding code to do some of the heavy lifting in areas such as initialization inheritance and optimisation.