Skip to content

Lightpanda: the headless browser designed for AI and automation

Fix license header

Karl Seguin51d63098fd0a
diff --git a/src/browser/frame/node_factory.zig b/src/browser/frame/node_factory.zig
index 6fd085403..5049a3dbc 100644
--- a/src/browser/frame/node_factory.zig
+++ b/src/browser/frame/node_factory.zig
@@ -938,13 +938,10 @@ pub fn createElementNS(frame: *Frame, namespace: Element.Namespace, name: []cons
asUint("foreignObject") => return createSvgElementT(frame, Graphics.ForeignObject, name, attribute_iterator, .{ ._proto = undefined }),
else => {},
},
- 14 => {
- if (std.mem.eql(u8, name, "linearGradient")) {
- return createSvgElementT(frame, Element.Svg.GradientElement.LinearGradient, name, attribute_iterator, .{ ._proto = undefined });
- }
- if (std.mem.eql(u8, name, "radialGradient")) {
- return createSvgElementT(frame, Element.Svg.GradientElement.RadialGradient, name, attribute_iterator, .{ ._proto = undefined });
- }
+ 14 => switch (@as(u112, @bitCast(name[0..14].*))) {
+ asUint("linearGradient") => return createSvgElementT(frame, Element.Svg.GradientElement.LinearGradient, name, attribute_iterator, .{ ._proto = undefined }),
+ asUint("radialGradient") => return createSvgElementT(frame, Element.Svg.GradientElement.RadialGradient, name, attribute_iterator, .{ ._proto = undefined }),
+ else => {},
},
else => {},
}
diff --git a/src/browser/tests/element/svg/resources.html b/src/browser/tests/element/svg/resources.html
index aadb8b233..8030a75e8 100644
--- a/src/browser/tests/element/svg/resources.html
+++ b/src/browser/tests/element/svg/resources.html
@@ -28,6 +28,12 @@
testing.expectEqual(true, $('#pattern') instanceof SVGPatternElement);
testing.expectEqual(true, $('#stop') instanceof SVGStopElement);
+ // SVG_UNIT_TYPE_* constants live on SVGUnitTypes, not the element interfaces.
+ testing.expectEqual('undefined', typeof SVGClipPathElement.SVG_UNIT_TYPE_USERSPACEONUSE);
+ testing.expectEqual('undefined', typeof SVGMaskElement.SVG_UNIT_TYPE_OBJECTBOUNDINGBOX);
+ testing.expectEqual(2, SVGGradientElement.SVG_SPREADMETHOD_REFLECT);
+ testing.expectEqual(2, SVGMarkerElement.SVG_MARKERUNITS_STROKEWIDTH);
+
const ns = 'http://www.w3.org/2000/svg';
testing.expectEqual(true, document.createElementNS(ns, 'linearGradient') instanceof SVGLinearGradientElement);
testing.expectEqual(false, document.createElementNS(ns, 'lineargradient') instanceof SVGLinearGradientElement);
@@ -48,8 +54,10 @@
testing.expectError('TypeError', () => { linear.gradientUnits.baseVal = 99; });
testing.expectEqual(2, linear.spreadMethod.baseVal);
+ // Enumerated values match exactly: whitespace padding makes the value
+ // unrecognized, and both engines then report the initial value.
linear.setAttribute('spreadMethod', ' \treflect\n');
- testing.expectEqual(2, linear.spreadMethod.baseVal);
+ testing.expectEqual(1, linear.spreadMethod.baseVal);
testing.expectEqual('#base', linear.href.baseVal);
linear.href.baseVal = '#other';
testing.expectEqual('#other', linear.getAttribute('href'));
@@ -80,19 +88,21 @@
}
</script>
-<script id=radialFallbacks>
+<script id=radialDefaults>
{
+ // fx/fy reflect only their own attribute: the rendering-time fallback to
+ // cx/cy is not visible through the DOM, which reports the 50% default.
const radial = $('#radial');
testing.expectEqual(true, radial.fx === radial.fx);
- testing.expectEqual('20%', radial.fx.baseVal.valueAsString);
- testing.expectEqual('30%', radial.fy.baseVal.valueAsString);
+ testing.expectEqual('50%', radial.fx.baseVal.valueAsString);
+ testing.expectEqual('50%', radial.fy.baseVal.valueAsString);
radial.setAttribute('cx', '40%');
- testing.expectEqual('40%', radial.fx.baseVal.valueAsString);
+ testing.expectEqual('50%', radial.fx.baseVal.valueAsString);
radial.fx.baseVal.valueAsString = '15%';
- radial.setAttribute('cx', '60%');
testing.expectEqual('15%', radial.fx.baseVal.valueAsString);
+ testing.expectEqual('15%', radial.getAttribute('fx'));
radial.removeAttribute('fx');
- testing.expectEqual('60%', radial.fx.baseVal.valueAsString);
+ testing.expectEqual('50%', radial.fx.baseVal.valueAsString);
testing.expectEqual('50%', radial.r.baseVal.valueAsString);
testing.expectEqual('0%', radial.fr.baseVal.valueAsString);
radial.setAttribute('r', 'invalid');
diff --git a/src/browser/webapi/element/svg/ClipPath.zig b/src/browser/webapi/element/svg/ClipPath.zig
index d80155d1e..cf7835229 100644
--- a/src/browser/webapi/element/svg/ClipPath.zig
+++ b/src/browser/webapi/element/svg/ClipPath.zig
@@ -1,14 +1,32 @@
-// Copyright (C) 2023-2026 Lightpanda (Selecy SAS)
-// SPDX-License-Identifier: AGPL-3.0-or-later
+// Copyright (C) 2023-2026 Lightpanda (Selecy SAS)
+//
+// Francis Bouvier <[email protected]>
+// Pierre Tachoire <[email protected]>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
const js = @import("../../../js/js.zig");
const Frame = @import("../../../Frame.zig");
+
const Node = @import("../../Node.zig");
const Element = @import("../../Element.zig");
-const Svg = @import("../Svg.zig");
+
const AnimatedEnumeration = @import("../../svg/AnimatedEnumeration.zig");
const AnimatedTransformList = @import("../../svg/AnimatedTransformList.zig");
+const Svg = @import("../Svg.zig");
+
const ClipPath = @This();
_proto: *Svg,
@@ -34,9 +52,6 @@ pub const JsApi = struct {
pub const prototype_chain = bridge.prototypeChain();
pub var class_id: bridge.ClassId = undefined;
};
- pub const SVG_UNIT_TYPE_UNKNOWN = bridge.property(0, .{ .template = true });
- pub const SVG_UNIT_TYPE_USERSPACEONUSE = bridge.property(1, .{ .template = true });
- pub const SVG_UNIT_TYPE_OBJECTBOUNDINGBOX = bridge.property(2, .{ .template = true });
pub const clipPathUnits = bridge.accessor(ClipPath.getClipPathUnits, null, .{});
pub const transform = bridge.accessor(ClipPath.getTransform, null, .{});
};
diff --git a/src/browser/webapi/element/svg/GradientElement.zig b/src/browser/webapi/element/svg/GradientElement.zig
index a36f350d4..0b133d052 100644
--- a/src/browser/webapi/element/svg/GradientElement.zig
+++ b/src/browser/webapi/element/svg/GradientElement.zig
@@ -1,15 +1,33 @@
-// Copyright (C) 2023-2026 Lightpanda (Selecy SAS)
-// SPDX-License-Identifier: AGPL-3.0-or-later
+// Copyright (C) 2023-2026 Lightpanda (Selecy SAS)
+//
+// Francis Bouvier <[email protected]>
+// Pierre Tachoire <[email protected]>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
const js = @import("../../../js/js.zig");
const Frame = @import("../../../Frame.zig");
+
const Node = @import("../../Node.zig");
const Element = @import("../../Element.zig");
-const Svg = @import("../Svg.zig");
+
const AnimatedEnumeration = @import("../../svg/AnimatedEnumeration.zig");
const AnimatedString = @import("../../svg/AnimatedString.zig");
const AnimatedTransformList = @import("../../svg/AnimatedTransformList.zig");
+const Svg = @import("../Svg.zig");
+
pub const LinearGradient = @import("LinearGradient.zig");
pub const RadialGradient = @import("RadialGradient.zig");
@@ -64,9 +82,6 @@ pub const JsApi = struct {
pub var class_id: bridge.ClassId = undefined;
};
- pub const SVG_UNIT_TYPE_UNKNOWN = bridge.property(0, .{ .template = true });
- pub const SVG_UNIT_TYPE_USERSPACEONUSE = bridge.property(1, .{ .template = true });
- pub const SVG_UNIT_TYPE_OBJECTBOUNDINGBOX = bridge.property(2, .{ .template = true });
pub const SVG_SPREADMETHOD_UNKNOWN = bridge.property(0, .{ .template = true });
pub const SVG_SPREADMETHOD_PAD = bridge.property(1, .{ .template = true });
pub const SVG_SPREADMETHOD_REFLECT = bridge.property(2, .{ .template = true });
diff --git a/src/browser/webapi/element/svg/LinearGradient.zig b/src/browser/webapi/element/svg/LinearGradient.zig
index 8f79d3e2c..b52b8ec5b 100644
--- a/src/browser/webapi/element/svg/LinearGradient.zig
+++ b/src/browser/webapi/element/svg/LinearGradient.zig
@@ -1,11 +1,29 @@
-// Copyright (C) 2023-2026 Lightpanda (Selecy SAS)
-// SPDX-License-Identifier: AGPL-3.0-or-later
+// Copyright (C) 2023-2026 Lightpanda (Selecy SAS)
+//
+// Francis Bouvier <[email protected]>
+// Pierre Tachoire <[email protected]>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
const js = @import("../../../js/js.zig");
const Frame = @import("../../../Frame.zig");
+
const Node = @import("../../Node.zig");
const Element = @import("../../Element.zig");
+
const AnimatedLength = @import("../../svg/AnimatedLength.zig");
+
const GradientElement = @import("GradientElement.zig");
const LinearGradient = @This();
diff --git a/src/browser/webapi/element/svg/Marker.zig b/src/browser/webapi/element/svg/Marker.zig
index 6e9c580a8..0af753726 100644
--- a/src/browser/webapi/element/svg/Marker.zig
+++ b/src/browser/webapi/element/svg/Marker.zig
@@ -1,14 +1,32 @@
-// Copyright (C) 2023-2026 Lightpanda (Selecy SAS)
-// SPDX-License-Identifier: AGPL-3.0-or-later
+// Copyright (C) 2023-2026 Lightpanda (Selecy SAS)
+//
+// Francis Bouvier <[email protected]>
+// Pierre Tachoire <[email protected]>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
const js = @import("../../../js/js.zig");
const Frame = @import("../../../Frame.zig");
+
const Node = @import("../../Node.zig");
const Element = @import("../../Element.zig");
-const Svg = @import("../Svg.zig");
+
const AnimatedEnumeration = @import("../../svg/AnimatedEnumeration.zig");
const AnimatedLength = @import("../../svg/AnimatedLength.zig");
+const Svg = @import("../Svg.zig");
+
const Marker = @This();
_proto: *Svg,
diff --git a/src/browser/webapi/element/svg/Mask.zig b/src/browser/webapi/element/svg/Mask.zig
index 4b397505f..f124c7dd7 100644
--- a/src/browser/webapi/element/svg/Mask.zig
+++ b/src/browser/webapi/element/svg/Mask.zig
@@ -1,14 +1,32 @@
-// Copyright (C) 2023-2026 Lightpanda (Selecy SAS)
-// SPDX-License-Identifier: AGPL-3.0-or-later
+// Copyright (C) 2023-2026 Lightpanda (Selecy SAS)
+//
+// Francis Bouvier <[email protected]>
+// Pierre Tachoire <[email protected]>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
const js = @import("../../../js/js.zig");
const Frame = @import("../../../Frame.zig");
+
const Node = @import("../../Node.zig");
const Element = @import("../../Element.zig");
-const Svg = @import("../Svg.zig");
+
const AnimatedEnumeration = @import("../../svg/AnimatedEnumeration.zig");
const AnimatedLength = @import("../../svg/AnimatedLength.zig");
+const Svg = @import("../Svg.zig");
+
const Mask = @This();
_proto: *Svg,
@@ -45,9 +63,6 @@ pub const JsApi = struct {
pub const prototype_chain = bridge.prototypeChain();
pub var class_id: bridge.ClassId = undefined;
};
- pub const SVG_UNIT_TYPE_UNKNOWN = bridge.property(0, .{ .template = true });
- pub const SVG_UNIT_TYPE_USERSPACEONUSE = bridge.property(1, .{ .template = true });
- pub const SVG_UNIT_TYPE_OBJECTBOUNDINGBOX = bridge.property(2, .{ .template = true });
pub const x = bridge.accessor(Mask.getX, null, .{});
pub const y = bridge.accessor(Mask.getY, null, .{});
pub const width = bridge.accessor(Mask.getWidth, null, .{});
diff --git a/src/browser/webapi/element/svg/Pattern.zig b/src/browser/webapi/element/svg/Pattern.zig
index 0f2a614bf..5940de529 100644
--- a/src/browser/webapi/element/svg/Pattern.zig
+++ b/src/browser/webapi/element/svg/Pattern.zig
@@ -1,16 +1,34 @@
-// Copyright (C) 2023-2026 Lightpanda (Selecy SAS)
-// SPDX-License-Identifier: AGPL-3.0-or-later
+// Copyright (C) 2023-2026 Lightpanda (Selecy SAS)
+//
+// Francis Bouvier <[email protected]>
+// Pierre Tachoire <[email protected]>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
const js = @import("../../../js/js.zig");
const Frame = @import("../../../Frame.zig");
+
const Node = @import("../../Node.zig");
const Element = @import("../../Element.zig");
-const Svg = @import("../Svg.zig");
+
const AnimatedEnumeration = @import("../../svg/AnimatedEnumeration.zig");
const AnimatedLength = @import("../../svg/AnimatedLength.zig");
const AnimatedString = @import("../../svg/AnimatedString.zig");
const AnimatedTransformList = @import("../../svg/AnimatedTransformList.zig");
+const Svg = @import("../Svg.zig");
+
const Pattern = @This();
_proto: *Svg,
@@ -53,9 +71,6 @@ pub const JsApi = struct {
pub const prototype_chain = bridge.prototypeChain();
pub var class_id: bridge.ClassId = undefined;
};
- pub const SVG_UNIT_TYPE_UNKNOWN = bridge.property(0, .{ .template = true });
- pub const SVG_UNIT_TYPE_USERSPACEONUSE = bridge.property(1, .{ .template = true });
- pub const SVG_UNIT_TYPE_OBJECTBOUNDINGBOX = bridge.property(2, .{ .template = true });
pub const x = bridge.accessor(Pattern.getX, null, .{});
pub const y = bridge.accessor(Pattern.getY, null, .{});
pub const width = bridge.accessor(Pattern.getWidth, null, .{});
diff --git a/src/browser/webapi/element/svg/RadialGradient.zig b/src/browser/webapi/element/svg/RadialGradient.zig
index ef8522545..110be6d0d 100644
--- a/src/browser/webapi/element/svg/RadialGradient.zig
+++ b/src/browser/webapi/element/svg/RadialGradient.zig
@@ -1,11 +1,29 @@
-// Copyright (C) 2023-2026 Lightpanda (Selecy SAS)
-// SPDX-License-Identifier: AGPL-3.0-or-later
+// Copyright (C) 2023-2026 Lightpanda (Selecy SAS)
+//
+// Francis Bouvier <[email protected]>
+// Pierre Tachoire <[email protected]>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
const js = @import("../../../js/js.zig");
const Frame = @import("../../../Frame.zig");
+
const Node = @import("../../Node.zig");
const Element = @import("../../Element.zig");
+
const AnimatedLength = @import("../../svg/AnimatedLength.zig");
+
const GradientElement = @import("GradientElement.zig");
const RadialGradient = @This();
diff --git a/src/browser/webapi/element/svg/Stop.zig b/src/browser/webapi/element/svg/Stop.zig
index 1ca7a1059..8389bd72d 100644
--- a/src/browser/webapi/element/svg/Stop.zig
+++ b/src/browser/webapi/element/svg/Stop.zig
@@ -1,13 +1,31 @@
-// Copyright (C) 2023-2026 Lightpanda (Selecy SAS)
-// SPDX-License-Identifier: AGPL-3.0-or-later
+// Copyright (C) 2023-2026 Lightpanda (Selecy SAS)
+//
+// Francis Bouvier <[email protected]>
+// Pierre Tachoire <[email protected]>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
const js = @import("../../../js/js.zig");
const Frame = @import("../../../Frame.zig");
+
const Node = @import("../../Node.zig");
const Element = @import("../../Element.zig");
-const Svg = @import("../Svg.zig");
+
const AnimatedNumber = @import("../../svg/AnimatedNumber.zig");
+const Svg = @import("../Svg.zig");
+
const Stop = @This();
_proto: *Svg,
diff --git a/src/browser/webapi/svg/AnimatedEnumeration.zig b/src/browser/webapi/svg/AnimatedEnumeration.zig
index 0a042e77c..ee2334861 100644
--- a/src/browser/webapi/svg/AnimatedEnumeration.zig
+++ b/src/browser/webapi/svg/AnimatedEnumeration.zig
@@ -1,5 +1,20 @@
-// Copyright (C) 2023-2026 Lightpanda (Selecy SAS)
-// SPDX-License-Identifier: AGPL-3.0-or-later
+// Copyright (C) 2023-2026 Lightpanda (Selecy SAS)
+//
+// Francis Bouvier <[email protected]>
+// Pierre Tachoire <[email protected]>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
const std = @import("std");
const lp = @import("lightpanda");
@@ -44,18 +59,17 @@ pub const Kind = enum {
pattern_units,
pattern_content_units,
- fn attributeName(self: Kind, frame: *Frame) !lp.String {
- const name = switch (self) {
- .clip_path_units => "clipPathUnits",
- .gradient_units => "gradientUnits",
- .spread_method => "spreadMethod",
- .marker_units => "markerUnits",
- .mask_units => "maskUnits",
- .mask_content_units => "maskContentUnits",
- .pattern_units => "patternUnits",
- .pattern_content_units => "patternContentUnits",
+ fn attributeName(self: Kind) lp.String {
+ return switch (self) {
+ .clip_path_units => .wrap("clipPathUnits"),
+ .gradient_units => .wrap("gradientUnits"),
+ .spread_method => .wrap("spreadMethod"),
+ .marker_units => .wrap("markerUnits"),
+ .mask_units => .wrap("maskUnits"),
+ .mask_content_units => .wrap("maskContentUnits"),
+ .pattern_units => .wrap("patternUnits"),
+ .pattern_content_units => .wrap("patternContentUnits"),
};
- return lp.String.init(frame.arena, name, .{ .dupe = false });
}
fn entries(self: Kind) []const Entry {
@@ -92,7 +106,7 @@ pub fn getOrCreate(element: *Element, kind: Kind, frame: *Frame) !*AnimatedEnume
errdefer _ = frame._svg_animated_enumerations.remove(key);
gop.value_ptr.* = try create(
element,
- try kind.attributeName(frame),
+ kind.attributeName(),
kind.entries(),
kind.defaultValue(),
frame,
@@ -117,18 +131,19 @@ pub fn create(
}
pub fn getBaseVal(self: *const AnimatedEnumeration) u16 {
+ // Keywords match exactly — Chrome and Firefox reject even whitespace-padded
+ // values, and both answer an unrecognized value with the initial value.
const raw = self._element.getAttributeSafe(self._attr_name) orelse return self._default_value;
- const trimmed = std.mem.trim(u8, raw, " \t\r\n\x0c");
for (self._entries) |entry| {
- if (std.mem.eql(u8, trimmed, entry.keyword)) return entry.value;
+ if (std.mem.eql(u8, raw, entry.keyword)) return entry.value;
}
- return 0;
+ return self._default_value;
}
pub fn setBaseVal(self: *AnimatedEnumeration, value: u16, frame: *Frame) !void {
for (self._entries) |entry| {
if (entry.value == value) {
- try self._element.setAttributeSafe(self._attr_name, lp.String.wrap(entry.keyword), frame);
+ try self._element.setAttributeSafe(self._attr_name, .wrap(entry.keyword), frame);
return;
}
}
diff --git a/src/browser/webapi/svg/AnimatedLength.zig b/src/browser/webapi/svg/AnimatedLength.zig
index bab50c803..68cc11fd9 100644
--- a/src/browser/webapi/svg/AnimatedLength.zig
+++ b/src/browser/webapi/svg/AnimatedLength.zig
@@ -174,14 +174,6 @@ pub const Kind = enum {
else => .number,
};
}
-
- fn fallbackAttributeName(self: Kind) ?lp.String {
- return switch (self) {
- .radial_gradient_fx => comptime .wrap("cx"),
- .radial_gradient_fy => comptime .wrap("cy"),
- else => null,
- };
- }
};
pub const Key = struct {
@@ -205,7 +197,6 @@ pub fn getOrCreate(element: *Element, kind: Kind, frame: *Frame) !*AnimatedLengt
kind.direction(),
kind.defaultValue(),
kind.defaultUnit(),
- kind.fallbackAttributeName(),
frame,
);
}
@@ -227,7 +218,6 @@ pub fn createConfigured(
direction: Length.Direction,
default_value: f64,
default_unit: Length.Unit,
- fallback_attr_name: ?lp.String,
frame: *Frame,
) !*AnimatedLength {
const base_val = try Length.reflectedConfigured(
@@ -236,7 +226,6 @@ pub fn createConfigured(
direction,
default_value,
default_unit,
- fallback_attr_name,
false,
frame,
);
@@ -246,7 +235,6 @@ pub fn createConfigured(
direction,
default_value,
default_unit,
- fallback_attr_name,
true,
frame,
);
diff --git a/src/browser/webapi/svg/AnimatedTransformList.zig b/src/browser/webapi/svg/AnimatedTransformList.zig
index 04a26992d..4c6f55988 100644
--- a/src/browser/webapi/svg/AnimatedTransformList.zig
+++ b/src/browser/webapi/svg/AnimatedTransformList.zig
@@ -24,13 +24,12 @@ pub const Kind = enum {
gradient_transform,
pattern_transform,
- fn attributeName(self: Kind, frame: *Frame) !lp.String {
- const name = switch (self) {
- .transform => "transform",
- .gradient_transform => "gradientTransform",
- .pattern_transform => "patternTransform",
+ fn attributeName(self: Kind) lp.String {
+ return switch (self) {
+ .transform => .wrap("transform"),
+ .gradient_transform => .wrap("gradientTransform"),
+ .pattern_transform => .wrap("patternTransform"),
};
- return lp.String.init(frame.arena, name, .{ .dupe = false });
}
};
@@ -46,7 +45,7 @@ pub fn getOrCreate(element: *Element, kind: Kind, frame: *Frame) !*AnimatedTrans
const gop = try frame._svg_animated_transform_lists.getOrPut(frame.arena, key);
if (!gop.found_existing) {
errdefer _ = frame._svg_animated_transform_lists.remove(key);
- gop.value_ptr.* = try createForAttribute(element, try kind.attributeName(frame), frame);
+ gop.value_ptr.* = try createForAttribute(element, kind.attributeName(), frame);
}
return gop.value_ptr.*;
}
diff --git a/src/browser/webapi/svg/Length.zig b/src/browser/webapi/svg/Length.zig
index 84f94fc02..b33d2acad 100644
--- a/src/browser/webapi/svg/Length.zig
+++ b/src/browser/webapi/svg/Length.zig
@@ -34,7 +34,6 @@ _direction: Direction = .unspecified,
_read_only: bool = false,
_default_value: f64 = 0,
_default_unit: Unit = .number,
-_fallback_attr_name: ?String = null,
pub const Direction = enum {
horizontal,
@@ -77,11 +76,9 @@ pub fn reflectedConfigured(
direction: Direction,
default_value: f64,
default_unit: Unit,
- fallback_attr_name: ?String,
read_only: bool,
frame: *Frame,
) !*Length {
- try ensureFinite(default_value);
return frame._factory.create(Length{
._element = element,
._attr_name = attr_name,
@@ -89,7 +86,6 @@ pub fn reflectedConfigured(
._read_only = read_only,
._default_value = default_value,
._default_unit = default_unit,
- ._fallback_attr_name = fallback_attr_name,
});
}
@@ -180,10 +176,7 @@ fn ensureFinite(value: f64) !void {
fn syncFromAttribute(self: *Length) void {
const element = self._element orelse return;
- const raw = element.getAttributeSafe(self._attr_name) orelse raw: {
- if (self._fallback_attr_name) |fallback_attr_name| {
- if (element.getAttributeSafe(fallback_attr_name)) |fallback| break :raw fallback;
- }
+ const raw = element.getAttributeSafe(self._attr_name) orelse {
self._value = self._default_value;
self._unit = self._default_unit;
return;