@@ -21,6 +21,10 @@ pub const Html = @import("element/Html.zig");
2121
2222const Element = @This ();
2323
24+ pub const DatasetLookup = std .AutoHashMapUnmanaged (* Element , * DOMStringMap );
25+ pub const StyleLookup = std .AutoHashMapUnmanaged (* Element , * CSSStyleProperties );
26+ pub const ClassListLookup = std .AutoHashMapUnmanaged (* Element , * collections .DOMTokenList );
27+
2428pub const Namespace = enum (u8 ) {
2529 html ,
2630 svg ,
@@ -41,8 +45,6 @@ _type: Type,
4145_proto : * Node ,
4246_namespace : Namespace = .html ,
4347_attributes : ? * Attribute.List = null ,
44- _style : ? * CSSStyleProperties = null ,
45- _class_list : ? * collections.DOMTokenList = null ,
4648
4749pub const Type = union (enum ) {
4850 html : * Html ,
@@ -333,22 +335,22 @@ pub fn getAttributeNamedNodeMap(self: *Element, page: *Page) !*Attribute.NamedNo
333335}
334336
335337pub fn getStyle (self : * Element , page : * Page ) ! * CSSStyleProperties {
336- return self . _style orelse blk : {
337- const s = try CSSStyleProperties . init ( self , page );
338- self . _style = s ;
339- break : blk s ;
340- } ;
338+ const gop = try page . _element_styles . getOrPut ( page . arena , self );
339+ if ( ! gop . found_existing ) {
340+ gop . value_ptr .* = try CSSStyleProperties . init ( self , page ) ;
341+ }
342+ return gop . value_ptr .* ;
341343}
342344
343345pub fn getClassList (self : * Element , page : * Page ) ! * collections.DOMTokenList {
344- return self ._class_list orelse blk : {
345- const cl = try page ._factory .create (collections.DOMTokenList {
346+ const gop = try page ._element_class_lists .getOrPut (page .arena , self );
347+ if (! gop .found_existing ) {
348+ gop .value_ptr .* = try page ._factory .create (collections.DOMTokenList {
346349 ._element = self ,
347350 ._attribute_name = "class" ,
348351 });
349- self ._class_list = cl ;
350- break :blk cl ;
351- };
352+ }
353+ return gop .value_ptr .* ;
352354}
353355
354356pub fn getDataset (self : * Element , page : * Page ) ! * DOMStringMap {
0 commit comments