Merge pull request #807 from lightpanda-io/css-util-iface

add CSS utility interface
This commit is contained in:
Karl Seguin
2025-06-25 07:44:15 +08:00
committed by GitHub
3 changed files with 30 additions and 0 deletions

View File

@@ -23,6 +23,18 @@ const std = @import("std");
const Selector = @import("selector.zig").Selector; const Selector = @import("selector.zig").Selector;
const parser = @import("parser.zig"); const parser = @import("parser.zig");
pub const Interfaces = .{
Css,
};
// https://developer.mozilla.org/en-US/docs/Web/API/CSS
pub const Css = struct {
pub fn _supports(_: *Css, _: []const u8, _: ?[]const u8) bool {
// TODO: Actually respond with which CSS features we support.
return true;
}
};
// parse parse a selector string and returns the parsed result or an error. // parse parse a selector string and returns the parsed result or an error.
pub fn parse(alloc: std.mem.Allocator, s: []const u8, opts: parser.ParseOptions) parser.ParseError!Selector { pub fn parse(alloc: std.mem.Allocator, s: []const u8, opts: parser.ParseOptions) parser.ParseError!Selector {
var p = parser.Parser{ .s = s, .i = 0, .opts = opts }; var p = parser.Parser{ .s = s, .i = 0, .opts = opts };
@@ -174,3 +186,14 @@ test "parse" {
defer s.deinit(alloc); defer s.deinit(alloc);
} }
} }
const testing = @import("../../testing.zig");
test "Browser.HTML.CSS" {
var runner = try testing.jsRunner(testing.tracking_allocator, .{});
defer runner.deinit();
try runner.testCases(&.{
.{ "CSS.supports('display: flex')", "true" },
.{ "CSS.supports('text-decoration-style', 'blink')", "true" },
}, .{});
}

View File

@@ -22,6 +22,7 @@ const WebApis = struct {
pub const Interfaces = generate.Tuple(.{ pub const Interfaces = generate.Tuple(.{
@import("crypto/crypto.zig").Crypto, @import("crypto/crypto.zig").Crypto,
@import("console/console.zig").Console, @import("console/console.zig").Console,
@import("css/css.zig").Interfaces,
@import("cssom/cssom.zig").Interfaces, @import("cssom/cssom.zig").Interfaces,
@import("dom/dom.zig").Interfaces, @import("dom/dom.zig").Interfaces,
@import("encoding/text_encoder.zig").Interfaces, @import("encoding/text_encoder.zig").Interfaces,

View File

@@ -35,6 +35,7 @@ const Performance = @import("../dom/performance.zig").Performance;
const CSSStyleDeclaration = @import("../cssom/css_style_declaration.zig").CSSStyleDeclaration; const CSSStyleDeclaration = @import("../cssom/css_style_declaration.zig").CSSStyleDeclaration;
const CustomElementRegistry = @import("../webcomponents/custom_element_registry.zig").CustomElementRegistry; const CustomElementRegistry = @import("../webcomponents/custom_element_registry.zig").CustomElementRegistry;
const Screen = @import("screen.zig").Screen; const Screen = @import("screen.zig").Screen;
const Css = @import("../css/css.zig").Css;
const storage = @import("../storage/storage.zig"); const storage = @import("../storage/storage.zig");
@@ -62,6 +63,7 @@ pub const Window = struct {
performance: Performance, performance: Performance,
custom_elements: CustomElementRegistry = .{}, custom_elements: CustomElementRegistry = .{},
screen: Screen = .{}, screen: Screen = .{},
css: Css = .{},
pub fn create(target: ?[]const u8, navigator: ?Navigator) !Window { pub fn create(target: ?[]const u8, navigator: ?Navigator) !Window {
var fbs = std.io.fixedBufferStream(""); var fbs = std.io.fixedBufferStream("");
@@ -175,6 +177,10 @@ pub const Window = struct {
return &self.screen; return &self.screen;
} }
pub fn get_CSS(self: *Window) *Css {
return &self.css;
}
pub fn _requestAnimationFrame(self: *Window, cbk: Function, page: *Page) !u32 { pub fn _requestAnimationFrame(self: *Window, cbk: Function, page: *Page) !u32 {
return self.createTimeout(cbk, 5, page, .{ .animation_frame = true }); return self.createTimeout(cbk, 5, page, .{ .animation_frame = true });
} }