css: improve CSSOM rule handling and serialization

Refactors `CSSRule` to a union type for better type safety and updates
`CSSStyleRule` to use `CSSStyleProperties`. Adds comprehensive tests for
`insertRule`, `deleteRule`, and `replaceSync`.
This commit is contained in:
Adrià Arrufat
2026-03-12 20:23:59 +09:00
parent ee034943b6
commit f58f6e8d65
6 changed files with 115 additions and 31 deletions

View File

@@ -180,8 +180,6 @@ pub fn getCssText(self: *const CSSStyleDeclaration, page: *Page) ![]const u8 {
}
pub fn setCssText(self: *CSSStyleDeclaration, text: []const u8, page: *Page) !void {
if (self._element == null) return;
// Clear existing properties
var node = self._properties.first;
while (node) |n| {
@@ -197,6 +195,7 @@ pub fn setCssText(self: *CSSStyleDeclaration, text: []const u8, page: *Page) !vo
while (it.next()) |declaration| {
try self.setPropertyImpl(declaration.name, declaration.value, declaration.important, page);
}
try self.syncStyleAttribute(page);
}