Merge pull request #732 from lightpanda-io/intersection_observer_threshold

IntersectionObserver's threshold option should be an union
This commit is contained in:
Karl Seguin
2025-05-30 21:28:18 +08:00
committed by GitHub

View File

@@ -51,7 +51,7 @@ pub const IntersectionObserver = struct {
var options = IntersectionObserverOptions{ var options = IntersectionObserverOptions{
.root = parser.documentToNode(parser.documentHTMLToDocument(page.window.document)), .root = parser.documentToNode(parser.documentHTMLToDocument(page.window.document)),
.rootMargin = "0px 0px 0px 0px", .rootMargin = "0px 0px 0px 0px",
.threshold = &.{0.0}, .threshold = .{ .single = 0.0 },
}; };
if (options_) |*o| { if (options_) |*o| {
if (o.root) |root| { if (o.root) |root| {
@@ -107,7 +107,12 @@ pub const IntersectionObserver = struct {
const IntersectionObserverOptions = struct { const IntersectionObserverOptions = struct {
root: ?*parser.Node, // Element or Document root: ?*parser.Node, // Element or Document
rootMargin: ?[]const u8, rootMargin: ?[]const u8,
threshold: ?[]const f32, threshold: ?Threshold,
const Threshold = union(enum) {
single: f32,
list: []const f32,
};
}; };
// https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserverEntry // https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserverEntry