mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
element: fix toInterface for webcomponents
The webcomponents tag can be anything. But we must return them as HTMLElement for HTML documents.
This commit is contained in:
@@ -60,14 +60,24 @@ pub const Element = struct {
|
|||||||
|
|
||||||
pub fn toInterfaceT(comptime T: type, e: *parser.Element) !T {
|
pub fn toInterfaceT(comptime T: type, e: *parser.Element) !T {
|
||||||
const tagname = try parser.elementGetTagName(e) orelse {
|
const tagname = try parser.elementGetTagName(e) orelse {
|
||||||
// in case of null tagname, return the element as it.
|
// If the owner's document is HTML, assume we have an HTMLElement.
|
||||||
|
const doc = try parser.nodeOwnerDocument(parser.elementToNode(e));
|
||||||
|
if (doc != null and !doc.?.is_html) {
|
||||||
|
return .{ .HTMLElement = @as(*parser.ElementHTML, @ptrCast(e)) };
|
||||||
|
}
|
||||||
|
|
||||||
return .{ .Element = e };
|
return .{ .Element = e };
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO SVGElement and MathML are not supported yet.
|
// TODO SVGElement and MathML are not supported yet.
|
||||||
|
|
||||||
const tag = parser.Tag.fromString(tagname) catch {
|
const tag = parser.Tag.fromString(tagname) catch {
|
||||||
// if the tag is invalid, we don't have an HTMLElement.
|
// If the owner's document is HTML, assume we have an HTMLElement.
|
||||||
|
const doc = try parser.nodeOwnerDocument(parser.elementToNode(e));
|
||||||
|
if (doc != null and doc.?.is_html) {
|
||||||
|
return .{ .HTMLElement = @as(*parser.ElementHTML, @ptrCast(e)) };
|
||||||
|
}
|
||||||
|
|
||||||
return .{ .Element = e };
|
return .{ .Element = e };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -61,5 +61,7 @@ test "Browser.webcomponents" {
|
|||||||
},
|
},
|
||||||
|
|
||||||
.{ "main.innerHTML", "<lightpanda-test>connected</lightpanda-test>" },
|
.{ "main.innerHTML", "<lightpanda-test>connected</lightpanda-test>" },
|
||||||
|
.{ "document.createElement('lightpanda-test').dataset", "[object DataSet]" },
|
||||||
|
.{ "document.createElement('lightpanda-test.x').dataset", "[object DataSet]" },
|
||||||
}, .{});
|
}, .{});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user