Skip to content

Commit 8bd7c8d

Browse files
authored
Merge pull request #807 from lightpanda-io/css-util-iface
add CSS utility interface
2 parents 269dcf0 + c0fc3a1 commit 8bd7c8d

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/browser/css/css.zig

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ const std = @import("std");
2323
const Selector = @import("selector.zig").Selector;
2424
const parser = @import("parser.zig");
2525

26+
pub const Interfaces = .{
27+
Css,
28+
};
29+
30+
// https://developer.mozilla.org/en-US/docs/Web/API/CSS
31+
pub const Css = struct {
32+
pub fn _supports(_: *Css, _: []const u8, _: ?[]const u8) bool {
33+
// TODO: Actually respond with which CSS features we support.
34+
return true;
35+
}
36+
};
37+
2638
// parse parse a selector string and returns the parsed result or an error.
2739
pub fn parse(alloc: std.mem.Allocator, s: []const u8, opts: parser.ParseOptions) parser.ParseError!Selector {
2840
var p = parser.Parser{ .s = s, .i = 0, .opts = opts };
@@ -174,3 +186,14 @@ test "parse" {
174186
defer s.deinit(alloc);
175187
}
176188
}
189+
190+
const testing = @import("../../testing.zig");
191+
test "Browser.HTML.CSS" {
192+
var runner = try testing.jsRunner(testing.tracking_allocator, .{});
193+
defer runner.deinit();
194+
195+
try runner.testCases(&.{
196+
.{ "CSS.supports('display: flex')", "true" },
197+
.{ "CSS.supports('text-decoration-style', 'blink')", "true" },
198+
}, .{});
199+
}

src/browser/env.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const WebApis = struct {
2222
pub const Interfaces = generate.Tuple(.{
2323
@import("crypto/crypto.zig").Crypto,
2424
@import("console/console.zig").Console,
25+
@import("css/css.zig").Interfaces,
2526
@import("cssom/cssom.zig").Interfaces,
2627
@import("dom/dom.zig").Interfaces,
2728
@import("encoding/text_encoder.zig").Interfaces,

src/browser/html/window.zig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const Performance = @import("../dom/performance.zig").Performance;
3535
const CSSStyleDeclaration = @import("../cssom/css_style_declaration.zig").CSSStyleDeclaration;
3636
const CustomElementRegistry = @import("../webcomponents/custom_element_registry.zig").CustomElementRegistry;
3737
const Screen = @import("screen.zig").Screen;
38+
const Css = @import("../css/css.zig").Css;
3839

3940
const storage = @import("../storage/storage.zig");
4041

@@ -62,6 +63,7 @@ pub const Window = struct {
6263
performance: Performance,
6364
custom_elements: CustomElementRegistry = .{},
6465
screen: Screen = .{},
66+
css: Css = .{},
6567

6668
pub fn create(target: ?[]const u8, navigator: ?Navigator) !Window {
6769
var fbs = std.io.fixedBufferStream("");
@@ -175,6 +177,10 @@ pub const Window = struct {
175177
return &self.screen;
176178
}
177179

180+
pub fn get_CSS(self: *Window) *Css {
181+
return &self.css;
182+
}
183+
178184
pub fn _requestAnimationFrame(self: *Window, cbk: Function, page: *Page) !u32 {
179185
return self.createTimeout(cbk, 5, page, .{ .animation_frame = true });
180186
}

0 commit comments

Comments
 (0)