@@ -29,6 +29,7 @@ const Node = @import("../dom/node.zig").Node;
2929const Element = @import ("../dom/element.zig" ).Element ;
3030const DataSet = @import ("DataSet.zig" );
3131
32+ const StyleSheet = @import ("../cssom/stylesheet.zig" ).StyleSheet ;
3233const CSSStyleDeclaration = @import ("../cssom/css_style_declaration.zig" ).CSSStyleDeclaration ;
3334
3435// HTMLElement interfaces
@@ -1012,6 +1013,18 @@ pub const HTMLStyleElement = struct {
10121013 pub const Self = parser .Style ;
10131014 pub const prototype = * HTMLElement ;
10141015 pub const subtype = .node ;
1016+
1017+ pub fn get_sheet (self : * parser.Style , page : * Page ) ! * StyleSheet {
1018+ const state = try page .getOrCreateNodeState (@alignCast (@ptrCast (self )));
1019+ if (state .style_sheet ) | ss | {
1020+ return ss ;
1021+ }
1022+
1023+ const ss = try page .arena .create (StyleSheet );
1024+ ss .* = .{};
1025+ state .style_sheet = ss ;
1026+ return ss ;
1027+ }
10151028};
10161029
10171030pub const HTMLTableElement = struct {
@@ -1453,6 +1466,18 @@ test "Browser.HTML.HTMLTemplateElement" {
14531466 }, .{});
14541467}
14551468
1469+ test "Browser.HTML.HTMLStyleElement" {
1470+ var runner = try testing .jsRunner (testing .tracking_allocator , .{ .html = "" });
1471+ defer runner .deinit ();
1472+
1473+ try runner .testCases (&.{
1474+ .{ "let s = document.createElement('style')" , null },
1475+ .{ "s.sheet.type" , "text/css" },
1476+ .{ "s.sheet == s.sheet" , "true" },
1477+ .{ "document.createElement('style').sheet == s.sheet" , "false" },
1478+ }, .{});
1479+ }
1480+
14561481const Check = struct {
14571482 input : []const u8 ,
14581483 expected : ? []const u8 = null , // Needed when input != expected
0 commit comments