add CSSStyleProperties array set support

This commit is contained in:
Pierre Tachoire
2026-02-19 09:52:05 +01:00
parent 8d51383fb2
commit fdd52c17d7
2 changed files with 35 additions and 1 deletions

View File

@@ -121,6 +121,29 @@
} }
</script> </script>
<script id="propertyAssignment">
{
const div = $('#test-div');
div.style.cssText = '';
// camelCase assignment
div.style.opacity = '0.5';
testing.expectEqual('0.5', div.style.opacity);
// bracket notation assignment
div.style['filter'] = 'blur(5px)';
testing.expectEqual('blur(5px)', div.style.filter);
// numeric value coerced to string
div.style.opacity = 1;
testing.expectEqual('1', div.style.opacity);
// assigning method names should be ignored (not intercepted)
div.style.setProperty('color', 'blue');
testing.expectEqual('blue', div.style.color);
}
</script>
<script id="prototypeChainCheck"> <script id="prototypeChainCheck">
{ {
const div = $('#test-div'); const div = $('#test-div');

View File

@@ -37,6 +37,14 @@ pub fn asCSSStyleDeclaration(self: *CSSStyleProperties) *CSSStyleDeclaration {
return self._proto; return self._proto;
} }
pub fn setNamed(self: *CSSStyleProperties, name: []const u8, value: []const u8, page: *Page) !void {
if (method_names.has(name)) {
return error.NotHandled;
}
const dash_case = camelCaseToDashCase(name, &page.buf);
try self._proto.setProperty(dash_case, value, null, page);
}
pub fn getNamed(self: *CSSStyleProperties, name: []const u8, page: *Page) ![]const u8 { pub fn getNamed(self: *CSSStyleProperties, name: []const u8, page: *Page) ![]const u8 {
if (method_names.has(name)) { if (method_names.has(name)) {
return error.NotHandled; return error.NotHandled;
@@ -108,6 +116,9 @@ fn isKnownCSSProperty(dash_case: []const u8) bool {
.{ "display", {} }, .{ "display", {} },
.{ "visibility", {} }, .{ "visibility", {} },
.{ "opacity", {} }, .{ "opacity", {} },
.{ "filter", {} },
.{ "transform", {} },
.{ "transition", {} },
.{ "position", {} }, .{ "position", {} },
.{ "top", {} }, .{ "top", {} },
.{ "bottom", {} }, .{ "bottom", {} },
@@ -201,5 +212,5 @@ pub const JsApi = struct {
pub var class_id: bridge.ClassId = undefined; pub var class_id: bridge.ClassId = undefined;
}; };
pub const @"[]" = bridge.namedIndexed(CSSStyleProperties.getNamed, null, null, .{}); pub const @"[]" = bridge.namedIndexed(CSSStyleProperties.getNamed, CSSStyleProperties.setNamed, null, .{});
}; };