Truly independent web browser
LibWeb: Create SVGAnimateElement for <animate> elements
Andreas Kling5f3a12ae3e7a
diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txtindex ad19cb5bbda..6fd9ef63f6e 100644--- a/Libraries/LibWeb/CMakeLists.txt+++ b/Libraries/LibWeb/CMakeLists.txt@@ -858,6 +858,7 @@ set(SOURCESSVG/SVGAnimatedRect.cppSVG/SVGAnimatedString.cppSVG/SVGAnimatedTransformList.cpp+ SVG/SVGAnimateElement.cppSVG/SVGAnimateMotionElement.cppSVG/SVGAnimationElement.cppSVG/SVGCircleElement.cppdiff --git a/Libraries/LibWeb/DOM/ElementFactory.cpp b/Libraries/LibWeb/DOM/ElementFactory.cppindex f9baf72ff42..a03d85981ea 100644--- a/Libraries/LibWeb/DOM/ElementFactory.cpp+++ b/Libraries/LibWeb/DOM/ElementFactory.cpp@@ -95,6 +95,7 @@#include <LibWeb/MathML/TagNames.h>#include <LibWeb/Namespace.h>#include <LibWeb/SVG/SVGAElement.h>+#include <LibWeb/SVG/SVGAnimateElement.h>#include <LibWeb/SVG/SVGAnimateMotionElement.h>#include <LibWeb/SVG/SVGCircleElement.h>#include <LibWeb/SVG/SVGClipPathElement.h>@@ -521,6 +522,8 @@ static GC::Ref<SVG::SVGElement> create_svg_element(Document& document, Qualifiedif (local_name == SVG::TagNames::svg)return create_element_on_heap<SVG::SVGSVGElement>(document, move(qualified_name));+ if (local_name == SVG::TagNames::animate)+ return create_element_on_heap<SVG::SVGAnimateElement>(document, move(qualified_name));if (local_name == SVG::TagNames::animateMotion)return create_element_on_heap<SVG::SVGAnimateMotionElement>(document, move(qualified_name));// FIXME: Support SVG's mixedCase tag names properly.diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.hindex 6de840bc99d..f72fd50391a 100644--- a/Libraries/LibWeb/Forward.h+++ b/Libraries/LibWeb/Forward.h@@ -1104,6 +1104,7 @@ class SVGAnimatedLengthList;class SVGAnimatedNumber;class SVGAnimatedNumberList;class SVGAnimatedRect;+class SVGAnimateElement;class SVGAnimateMotionElement;class SVGAnimationElement;class SVGCircleElement;diff --git a/Libraries/LibWeb/SVG/SVGAnimateElement.cpp b/Libraries/LibWeb/SVG/SVGAnimateElement.cppnew file mode 100644index 00000000000..4004ff5b141--- /dev/null+++ b/Libraries/LibWeb/SVG/SVGAnimateElement.cpp@@ -0,0 +1,239 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#include <LibWeb/Animations/AnimationEffect.h>+#include <LibWeb/CSS/StyleValues/StyleValue.h>+#include <LibWeb/SVG/AttributeNames.h>+#include <LibWeb/SVG/AttributeParsing.h>+#include <LibWeb/SVG/SVGAnimateElement.h>++namespace Web::SVG {++GC_DEFINE_ALLOCATOR(SVGAnimateElement);++SVGAnimateElement::SVGAnimateElement(DOM::Document& document, DOM::QualifiedName qualified_name)+ : SVGAnimationElement(document, move(qualified_name))+{+}++void SVGAnimateElement::attribute_changed(Utf16FlyString const& name, Optional<Utf16String> const& old_value, Optional<Utf16String> const& value, Optional<Utf16FlyString> const& namespace_)+{+ Base::attribute_changed(name, old_value, value, namespace_);+ if (first_is_one_of(name, AttributeNames::calcMode, AttributeNames::from, AttributeNames::keySplines, AttributeNames::keyTimes, AttributeNames::to, AttributeNames::values) && !namespace_.has_value())+ update_animation();+}++enum class CalcMode : u8 {+ Discrete,+ Linear,+ Paced,+ Spline,+};++// https://svgwg.org/specs/animations/#CalcModeAttribute+static CalcMode calc_mode(SVGAnimateElement const& element)+{+ // The default mode is 'linear', however if the attribute does not support linear interpolation (e.g. for strings),+ // the ‘calcMode’ attribute is ignored and discrete interpolation is used.+ // NB: SMIL Animation ignores a value with any error in its syntax, which leaves the default mode.+ auto calc_mode = element.get_attribute(AttributeNames::calcMode);+ if (!calc_mode.has_value())+ return CalcMode::Linear;+ if (*calc_mode == "discrete"sv)+ return CalcMode::Discrete;+ if (*calc_mode == "paced"sv)+ return CalcMode::Paced;+ if (*calc_mode == "spline"sv)+ return CalcMode::Spline;+ return CalcMode::Linear;+}++// NB: The values, keyTimes and keySplines attributes are lists separated by semicolons, which may end in one.+static Vector<Utf16View> split_semicolon_separated_list(Utf16View list)+{+ // Let values be a list of strings formed by splitting attribute at each U+003B SEMICOLON character.+ auto items = list.split_view(';', SplitBehavior::KeepEmpty);++ // Strip any leading and trailing white space characters from each value of values.+ for (auto& item : items)+ item = item.trim_ascii_whitespace();++ // Remove the final value in values if it is the empty string.+ if (!items.is_empty() && items.last().is_empty())+ items.take_last();+ return items;+}++// https://svgwg.org/specs/animations/#KeyTimesAttribute+static Optional<Vector<double>> parse_key_times(Utf16View attribute, size_t value_count, CalcMode calc_mode)+{+ // For animations specified with a ‘values’ list, the ‘keyTimes’ attribute if specified must have exactly as many+ // values as there are in the ‘values’ attribute. For from/to/by animations, the ‘keyTimes’ attribute if specified+ // must have two values.+ auto items = split_semicolon_separated_list(attribute);+ if (items.size() != value_count)+ return {};++ Vector<double> key_times;+ key_times.ensure_capacity(items.size());+ for (auto item : items) {+ // Each time value in the ‘keyTimes’ list is specified as a floating point value between 0 and 1 (inclusive),+ // representing a proportional offset into the simple duration of the animation element.+ auto key_time = parse_number(item);+ if (!key_time.has_value() || *key_time < 0 || *key_time > 1)+ return {};++ // Each successive time value must be greater than or equal to the preceding time value.+ if (!key_times.is_empty() && *key_time < key_times.last())+ return {};+ key_times.unchecked_append(*key_time);+ }++ // For linear and spline animation, the first time value in the list must be 0, and the last time value in the+ // list must be 1.+ // For discrete animation, the first time value in the list must be 0.+ if (key_times.first() != 0)+ return {};+ if (calc_mode != CalcMode::Discrete && key_times.last() != 1)+ return {};+ return key_times;+}++// https://svgwg.org/specs/animations/#KeySplinesAttribute+static Optional<Vector<CSS::EasingFunction>> parse_key_splines(Utf16View attribute, size_t interval_count)+{+ // Thus, there must be one fewer sets of control points than there are ‘keyTimes’.+ auto items = split_semicolon_separated_list(attribute);+ if (items.size() != interval_count)+ return {};++ Vector<CSS::EasingFunction> key_splines;+ key_splines.ensure_capacity(items.size());+ for (auto item : items) {+ // Each control point description is a set of four values: x1 y1 x2 y2, describing the Bézier control points+ // for one time segment.+ // The values must all be in the range 0 to 1.+ auto control_points = parse_table_values(item);+ if (control_points.size() != 4 || any_of(control_points, [](float value) { return value < 0 || value > 1; }))+ return {};++ // NB: The keyTimes values are the anchor points of a segment, so its control points describe a cubic-bezier()+ // easing function across it.+ auto easing = Animations::AnimationEffect::parse_easing_string(Utf16String::formatted("cubic-bezier({}, {}, {}, {})", control_points[0], control_points[1], control_points[2], control_points[3]));+ if (!easing.has_value())+ return {};+ key_splines.unchecked_append(easing.release_value());+ }+ return key_splines;+}++// https://svgwg.org/specs/animations/#AnimateElement+Vector<Animations::BaseKeyframe> SVGAnimateElement::keyframes(SVGElement const& target, CSS::PropertyID property_id) const+{+ // NB: A missing value stands for the underlying value of the attribute or property, which the keyframe effect+ // takes as its missing start keyframe.+ Vector<RefPtr<CSS::StyleValue const>> values;++ // If a list of ‘values’ is specified, any ‘from’, ‘to’ and ‘by’ attribute values are ignored.+ if (auto values_attribute = get_attribute(AttributeNames::values); values_attribute.has_value()) {+ // Parse each value in values using the rules for parsing the attribute identified by the ‘href’, and+ // ‘attributeName’ attributes.+ // NB: If any values are not legal, the document fragment is in error, so the animation does not apply.+ for (auto item : split_semicolon_separated_list(*values_attribute)) {+ auto value = target.parse_presentation_attribute(property_id, item);+ if (!value)+ return {};+ values.append(move(value));+ }+ } else {+ // FIXME: Support by animations.+ auto to = get_attribute(AttributeNames::to);+ auto to_value = to.has_value() ? target.parse_presentation_attribute(property_id, to->utf16_view()) : nullptr;+ if (!to_value)+ return {};++ // NB: Without a from value, this is a to animation, which animates from the underlying value.+ RefPtr<CSS::StyleValue const> from_value;+ if (auto from = get_attribute(AttributeNames::from); from.has_value()) {+ from_value = target.parse_presentation_attribute(property_id, from->utf16_view());+ if (!from_value)+ return {};+ }+ values = { move(from_value), move(to_value) };+ }+ if (values.is_empty())+ return {};++ // NB: A single value holds for the entire duration, as with a set element.+ if (values.size() == 1)+ return { keyframe(0, property_id, *values.first()), keyframe(1, property_id, *values.first()) };++ auto calc_mode = ::Web::SVG::calc_mode(*this);++ // If the interpolation mode is 'paced', the ‘keyTimes’ attribute is ignored.+ // If the simple duration is indefinite, any ‘keyTimes’ specification will be ignored.+ // FIXME: Pace paced animations evenly rather than interpolating them linearly.+ Optional<Vector<double>> key_times;+ if (auto key_times_attribute = get_attribute(AttributeNames::keyTimes);+ key_times_attribute.has_value() && calc_mode != CalcMode::Paced && !isinf(simple_duration())) {+ // If there are any errors in the ‘keyTimes’ specification (bad values, too many or too few values), the+ // document fragment is in error (see error processing).+ key_times = parse_key_times(*key_times_attribute, values.size(), calc_mode);+ if (!key_times.has_value())+ return {};+ }++ // spline+ // Interpolates from one value in the ‘values’ list to the next according to a time function defined by a cubic+ // Bézier spline. The points of the spline are defined in the ‘keyTimes’ attribute, and the control points for+ // each interval are defined in the ‘keySplines’ attribute.+ Optional<Vector<CSS::EasingFunction>> key_splines;+ if (calc_mode == CalcMode::Spline) {+ // If there are any errors in the ‘keySplines’ specification (bad values, too many or too few values), the+ // document fragment is in error (see error processing).+ // NB: A missing keySplines attribute is an error too, since there must be one set of control points for each+ // interval.+ auto key_splines_attribute = get_attribute(AttributeNames::keySplines);+ if (key_splines_attribute.has_value())+ key_splines = parse_key_splines(*key_splines_attribute, values.size() - 1);+ if (!key_splines.has_value())+ return {};+ }++ // discrete+ // This specifies that the animation function will jump from one value to the next without any interpolation.+ // NB: Without keyTimes, the values of a discrete animation divide the simple duration evenly, each holding for its+ // part of it. Each keyframe steps to the next one only at its end, and a closing keyframe holds the last value+ // until the end of the simple duration.+ // FIXME: Hold the underlying value of a discrete to animation for the first half of the simple duration.+ auto offset_of_value = [&](size_t index) -> double {+ if (key_times.has_value())+ return (*key_times)[index];+ if (calc_mode == CalcMode::Discrete)+ return static_cast<double>(index) / static_cast<double>(values.size());+ return static_cast<double>(index) / static_cast<double>(values.size() - 1);+ };++ Vector<Animations::BaseKeyframe> keyframes;+ keyframes.ensure_capacity(values.size() + 1);+ for (size_t i = 0; i < values.size(); ++i) {+ if (!values[i])+ continue;+ auto value_keyframe = keyframe(offset_of_value(i), property_id, *values[i]);+ if (calc_mode == CalcMode::Discrete)+ value_keyframe.easing = Animations::AnimationEffect::parse_easing_string("step-end"_utf16).release_value();+ else if (key_splines.has_value() && i < key_splines->size())+ value_keyframe.easing = (*key_splines)[i];+ else+ value_keyframe.easing = CSS::EasingFunction::linear();+ keyframes.unchecked_append(move(value_keyframe));+ }+ if (calc_mode == CalcMode::Discrete && keyframes.last().offset != 1)+ keyframes.unchecked_append(keyframe(1, property_id, *values.last()));+ return keyframes;+}++}diff --git a/Libraries/LibWeb/SVG/SVGAnimateElement.h b/Libraries/LibWeb/SVG/SVGAnimateElement.hnew file mode 100644index 00000000000..c2671036cac--- /dev/null+++ b/Libraries/LibWeb/SVG/SVGAnimateElement.h@@ -0,0 +1,25 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#pragma once++#include <LibWeb/SVG/SVGAnimationElement.h>++namespace Web::SVG {++class SVGAnimateElement final : public SVGAnimationElement {+ WEB_WRAPPABLE(SVGAnimateElement, SVGAnimationElement);+ GC_DECLARE_ALLOCATOR(SVGAnimateElement);++private:+ SVGAnimateElement(DOM::Document&, DOM::QualifiedName);++ virtual void attribute_changed(Utf16FlyString const& name, Optional<Utf16String> const& old_value, Optional<Utf16String> const& value, Optional<Utf16FlyString> const& namespace_) override;++ virtual Vector<Animations::BaseKeyframe> keyframes(SVGElement const& target, CSS::PropertyID) const override;+};++}diff --git a/Libraries/LibWeb/SVG/SVGAnimateElement.idl b/Libraries/LibWeb/SVG/SVGAnimateElement.idlnew file mode 100644index 00000000000..0021e229ba3--- /dev/null+++ b/Libraries/LibWeb/SVG/SVGAnimateElement.idl@@ -0,0 +1,4 @@+// https://svgwg.org/specs/animations/#InterfaceSVGAnimateElement+[Exposed=Window]+interface SVGAnimateElement : SVGAnimationElement {+};diff --git a/Libraries/LibWeb/SVG/SVGAnimationElement.h b/Libraries/LibWeb/SVG/SVGAnimationElement.hindex 79fc693d819..bb92d0d5b3e 100644--- a/Libraries/LibWeb/SVG/SVGAnimationElement.h+++ b/Libraries/LibWeb/SVG/SVGAnimationElement.h@@ -47,11 +47,12 @@ protected:static Animations::BaseKeyframe keyframe(double offset, CSS::PropertyID, CSS::StyleValue const&);static void set_keyframe_property(Animations::BaseKeyframe&, CSS::PropertyID, CSS::StyleValue const&);+ double simple_duration() const;+void update_animation();private:GC::Ptr<SMILTimeContainer> time_container();- double simple_duration() const;double repeat_count() const;Bindings::FillMode fill_mode() const;diff --git a/Libraries/LibWeb/SVG/TagNames.h b/Libraries/LibWeb/SVG/TagNames.hindex 7bef665bc44..10dea8e4be2 100644--- a/Libraries/LibWeb/SVG/TagNames.h+++ b/Libraries/LibWeb/SVG/TagNames.h@@ -12,6 +12,7 @@ namespace Web::SVG::TagNames {#define ENUMERATE_SVG_TAGS \__ENUMERATE_SVG_TAG(a, "a") \+ __ENUMERATE_SVG_TAG(animate, "animate") \__ENUMERATE_SVG_TAG(animateMotion, "animateMotion") \__ENUMERATE_SVG_TAG(circle, "circle") \__ENUMERATE_SVG_TAG(clipPath, "clipPath") \diff --git a/Libraries/LibWeb/idl_files.cmake b/Libraries/LibWeb/idl_files.cmakeindex c76bf0c80c1..f2b77d382c7 100644--- a/Libraries/LibWeb/idl_files.cmake+++ b/Libraries/LibWeb/idl_files.cmake@@ -515,6 +515,7 @@ libweb_js_bindings(SVG/SVGAnimatedPreserveAspectRatio)libweb_js_bindings(SVG/SVGAnimatedRect)libweb_js_bindings(SVG/SVGAnimatedString)libweb_js_bindings(SVG/SVGAnimatedTransformList)+libweb_js_bindings(SVG/SVGAnimateElement)libweb_js_bindings(SVG/SVGAnimateMotionElement)libweb_js_bindings(SVG/SVGAnimationElement)libweb_js_bindings(SVG/SVGCircleElement)diff --git a/Tests/LibWeb/Text/expected/SVG/animate-element-values.txt b/Tests/LibWeb/Text/expected/SVG/animate-element-values.txtnew file mode 100644index 00000000000..ec24f2fd117--- /dev/null+++ b/Tests/LibWeb/Text/expected/SVG/animate-element-values.txt@@ -0,0 +1,73 @@+interface: SVGAnimateElement+t=0+ from-to: 0.000+ to: 0.000+ values: 0.000+ key-times: 0.000+ discrete: 0.000+ discrete-key-times: 0.000+ spline: 0.000+ spline-without-key-splines: 1.000+ bad-key-times: 1.000+ bad-value: 1.000+ path: path("M 0 0 L 10 0")+t=1+ from-to: 0.250+ to: 0.250+ values: 0.500+ key-times: 0.333+ discrete: 0.500+ discrete-key-times: 0.000+ spline: 0.949+ spline-without-key-splines: 1.000+ bad-key-times: 1.000+ bad-value: 1.000+ path: path("M 0 0 L 15 10")+t=2+ from-to: 0.500+ to: 0.500+ values: 1.000+ key-times: 0.667+ discrete: 1.000+ discrete-key-times: 0.000+ spline: 0.991+ spline-without-key-splines: 1.000+ bad-key-times: 1.000+ bad-value: 1.000+ path: path("M 0 0 L 20 20")+t=3+ from-to: 0.750+ to: 0.750+ values: 0.750+ key-times: 1.000+ discrete: 0.250+ discrete-key-times: 0.500+ spline: 0.999+ spline-without-key-splines: 1.000+ bad-key-times: 1.000+ bad-value: 1.000+ path: path("M 0 0 L 25 30")+t=3.5+ from-to: 0.875+ to: 0.875+ values: 0.625+ key-times: 0.750+ discrete: 0.250+ discrete-key-times: 0.500+ spline: 1.000+ spline-without-key-splines: 1.000+ bad-key-times: 1.000+ bad-value: 1.000+ path: path("M 0 0 L 27.5 35")+t=4+ from-to: 1.000+ to: 0.000+ values: 1.000+ key-times: 1.000+ discrete: 1.000+ discrete-key-times: 1.000+ spline: 1.000+ spline-without-key-splines: 1.000+ bad-key-times: 1.000+ bad-value: 1.000+ path: path("M 0 0 L 10 0")diff --git a/Tests/LibWeb/Text/expected/all-window-properties.txt b/Tests/LibWeb/Text/expected/all-window-properties.txtindex 38ee5a1549b..24f10f0bfef 100644--- a/Tests/LibWeb/Text/expected/all-window-properties.txt+++ b/Tests/LibWeb/Text/expected/all-window-properties.txt@@ -410,6 +410,7 @@ ResizeObserverSizeResponseSVGAElementSVGAngle+SVGAnimateElementSVGAnimateMotionElementSVGAnimatedAngleSVGAnimatedBooleandiff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/idlharness.window.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/idlharness.window.txtindex f850963239b..4a6892ea3ff 100644--- a/Tests/LibWeb/Text/expected/wpt-import/svg/idlharness.window.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/idlharness.window.txt@@ -2,8 +2,8 @@ Harness status: OKFound 1780 tests-1595 Pass-185 Fail+1610 Pass+170 FailPass idl_test setupPass idl_test validationPass Partial interface Document: original interface defined@@ -1656,21 +1656,21 @@ Fail SVGAnimationElement interface: operation endElement()Fail SVGAnimationElement interface: operation endElementAt(float)Fail SVGAnimationElement interface: attribute requiredExtensionsFail SVGAnimationElement interface: attribute systemLanguage-Fail SVGAnimateElement interface: existence and properties of interface object-Fail SVGAnimateElement interface object length-Fail SVGAnimateElement interface object name-Fail SVGAnimateElement interface: existence and properties of interface prototype object-Fail SVGAnimateElement interface: existence and properties of interface prototype object's "constructor" property-Fail SVGAnimateElement interface: existence and properties of interface prototype object's @@unscopables property-Fail SVGAnimateElement must be primary interface of objects.animate-Fail Stringification of objects.animate-Fail SVGAnimationElement interface: objects.animate must inherit property "targetElement" with the proper type-Fail SVGAnimationElement interface: objects.animate must inherit property "onbegin" with the proper type-Fail SVGAnimationElement interface: objects.animate must inherit property "onend" with the proper type-Fail SVGAnimationElement interface: objects.animate must inherit property "onrepeat" with the proper type-Fail SVGAnimationElement interface: objects.animate must inherit property "getStartTime()" with the proper type-Fail SVGAnimationElement interface: objects.animate must inherit property "getCurrentTime()" with the proper type-Fail SVGAnimationElement interface: objects.animate must inherit property "getSimpleDuration()" with the proper type+Pass SVGAnimateElement interface: existence and properties of interface object+Pass SVGAnimateElement interface object length+Pass SVGAnimateElement interface object name+Pass SVGAnimateElement interface: existence and properties of interface prototype object+Pass SVGAnimateElement interface: existence and properties of interface prototype object's "constructor" property+Pass SVGAnimateElement interface: existence and properties of interface prototype object's @@unscopables property+Pass SVGAnimateElement must be primary interface of objects.animate+Pass Stringification of objects.animate+Pass SVGAnimationElement interface: objects.animate must inherit property "targetElement" with the proper type+Pass SVGAnimationElement interface: objects.animate must inherit property "onbegin" with the proper type+Pass SVGAnimationElement interface: objects.animate must inherit property "onend" with the proper type+Pass SVGAnimationElement interface: objects.animate must inherit property "onrepeat" with the proper type+Pass SVGAnimationElement interface: objects.animate must inherit property "getStartTime()" with the proper type+Pass SVGAnimationElement interface: objects.animate must inherit property "getCurrentTime()" with the proper type+Pass SVGAnimationElement interface: objects.animate must inherit property "getSimpleDuration()" with the proper typeFail SVGAnimationElement interface: objects.animate must inherit property "beginElement()" with the proper typeFail SVGAnimationElement interface: objects.animate must inherit property "beginElementAt(float)" with the proper typeFail SVGAnimationElement interface: calling beginElementAt(float) on objects.animate with too few arguments must throw TypeErrordiff --git a/Tests/LibWeb/Text/input/SVG/animate-element-values.html b/Tests/LibWeb/Text/input/SVG/animate-element-values.htmlnew file mode 100644index 00000000000..cd9618a8de4--- /dev/null+++ b/Tests/LibWeb/Text/input/SVG/animate-element-values.html@@ -0,0 +1,53 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<svg id="svg" width="100" height="100">+ <rect id="from-to" width="10" height="10" opacity="1">+ <animate attributeName="opacity" from="0" to="1" dur="4s"/>+ </rect>+ <rect id="to" width="10" height="10" opacity="0">+ <animate attributeName="opacity" to="1" dur="4s"/>+ </rect>+ <rect id="values" width="10" height="10" opacity="1">+ <animate attributeName="opacity" values="0; 1; 0.5;" dur="4s"/>+ </rect>+ <rect id="key-times" width="10" height="10" opacity="1">+ <animate attributeName="opacity" values="0;1;0.5" keyTimes="0;0.75;1" dur="4s"/>+ </rect>+ <rect id="discrete" width="10" height="10" opacity="1">+ <animate attributeName="opacity" values="0;0.5;1;0.25" calcMode="discrete" dur="4s"/>+ </rect>+ <rect id="discrete-key-times" width="10" height="10" opacity="1">+ <animate attributeName="opacity" values="0;0.5" keyTimes="0;0.75" calcMode="discrete" dur="4s"/>+ </rect>+ <rect id="spline" width="10" height="10" opacity="1">+ <animate attributeName="opacity" values="0;1" keyTimes="0;1" keySplines="0 1 0 1" calcMode="spline" dur="4s"/>+ </rect>+ <rect id="spline-without-key-splines" width="10" height="10" opacity="1">+ <animate attributeName="opacity" values="0;1" calcMode="spline" dur="4s"/>+ </rect>+ <rect id="bad-key-times" width="10" height="10" opacity="1">+ <animate attributeName="opacity" values="0;1" keyTimes="0;0.5" dur="4s"/>+ </rect>+ <rect id="bad-value" width="10" height="10" opacity="1">+ <animate attributeName="opacity" values="0;bogus" dur="4s"/>+ </rect>+ <path id="path" d="M0,0 L10,0">+ <animate attributeName="d" values="M0,0 L10,0;M0,0 L30,40" dur="4s"/>+ </path>+</svg>+<script>+ asyncTest(async done => {+ await new Promise(resolve => window.addEventListener("load", resolve));+ await new Promise(requestAnimationFrame);+ println(`interface: ${Object.getPrototypeOf(document.querySelector("animate")).constructor.name}`);+ svg.pauseAnimations();+ for (const time of [0, 1, 2, 3, 3.5, 4]) {+ svg.setCurrentTime(time);+ println(`t=${time}`);+ for (const rect of document.querySelectorAll("rect"))+ println(` ${rect.id}: ${Number(getComputedStyle(rect).opacity).toFixed(3)}`);+ println(` path: ${getComputedStyle(path).d}`);+ }+ done();+ });+</script>