Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / animations / animation_effect_1.lucb

#==============================================================================================
#
#   animation_effect_1 - Animations::AnimationEffect: timing properties, normalization and
#                        the local and active times
#
#   DESCRIPTION:
#       Port of Libraries/LibWeb/Animations/AnimationEffect.cpp (lines 1-460) with the inline
#       members of AnimationEffect.h, by region p4a: the CSS-to-bindings fill mode and
#       direction conversions, getTiming() and getComputedTiming(), the intrinsic iteration
#       duration, converting a time-based animation to a proportional one, normalizing the
#       specified timing, updateTiming(), the animation direction, the end time, local time,
#       active duration and the active time with a fill mode. Part 2 has the phases and
#       progress, the constructor, and AnimationUpdateContext.
#
#       Copyright (c) 2023-2024, Matthew Olsson <mattco@serenityos.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

# mark: Accessors (AnimationEffect.h) ===========================================================

## Ported from Libraries/LibWeb/Animations/AnimationEffect.h:91 Web::Animations::AnimationEffect::start_delay.
pub func animations_animation_effect_start_delay(this: AnimationsAnimationEffect*) -> AnimationsTimeValue:
    return this.m_start_delay

## Ported from Libraries/LibWeb/Animations/AnimationEffect.h:92 Web::Animations::AnimationEffect::set_specified_start_delay.
pub func animations_animation_effect_set_specified_start_delay(this: AnimationsAnimationEffect*, start_delay: f64):
    this.m_specified_start_delay = start_delay

## Ported from Libraries/LibWeb/Animations/AnimationEffect.h:94 Web::Animations::AnimationEffect::end_delay.
pub func animations_animation_effect_end_delay(this: AnimationsAnimationEffect*) -> AnimationsTimeValue:
    return this.m_end_delay

## Ported from Libraries/LibWeb/Animations/AnimationEffect.h:95 Web::Animations::AnimationEffect::set_specified_end_delay.
pub func animations_animation_effect_set_specified_end_delay(this: AnimationsAnimationEffect*, end_delay: f64):
    this.m_specified_end_delay = end_delay

## Ported from Libraries/LibWeb/Animations/AnimationEffect.h:97 Web::Animations::AnimationEffect::fill_mode.
pub func animations_animation_effect_fill_mode(this: AnimationsAnimationEffect*) -> BindFillMode:
    return this.m_fill_mode

## Ported from Libraries/LibWeb/Animations/AnimationEffect.h:98 Web::Animations::AnimationEffect::set_fill_mode.
pub func animations_animation_effect_set_fill_mode(this: AnimationsAnimationEffect*, fill_mode: BindFillMode):
    this.m_fill_mode = fill_mode

## Ported from Libraries/LibWeb/Animations/AnimationEffect.h:100 Web::Animations::AnimationEffect::iteration_start.
pub func animations_animation_effect_iteration_start(this: AnimationsAnimationEffect*) -> f64:
    return this.m_iteration_start

## Ported from Libraries/LibWeb/Animations/AnimationEffect.h:101 Web::Animations::AnimationEffect::set_iteration_start.
pub func animations_animation_effect_set_iteration_start(this: AnimationsAnimationEffect*, iteration_start: f64):
    this.m_iteration_start = iteration_start

## Ported from Libraries/LibWeb/Animations/AnimationEffect.h:103 Web::Animations::AnimationEffect::iteration_count.
pub func animations_animation_effect_iteration_count(this: AnimationsAnimationEffect*) -> f64:
    return this.m_iteration_count

## Ported from Libraries/LibWeb/Animations/AnimationEffect.h:104 Web::Animations::AnimationEffect::set_iteration_count.
pub func animations_animation_effect_set_iteration_count(this: AnimationsAnimationEffect*, iteration_count: f64):
    this.m_iteration_count = iteration_count

## Ported from Libraries/LibWeb/Animations/AnimationEffect.h:106 Web::Animations::AnimationEffect::iteration_duration.
pub func animations_animation_effect_iteration_duration(this: AnimationsAnimationEffect*) -> AnimationsTimeValue:
    return this.m_iteration_duration

## Ported from Libraries/LibWeb/Animations/AnimationEffect.h:107 Web::Animations::AnimationEffect::set_specified_iteration_duration.
pub func animations_animation_effect_set_specified_iteration_duration(this: AnimationsAnimationEffect*, iteration_duration: F64OrString):
    this.m_specified_iteration_duration = iteration_duration

## Ported from Libraries/LibWeb/Animations/AnimationEffect.h:109 Web::Animations::AnimationEffect::playback_direction.
pub func animations_animation_effect_playback_direction(this: AnimationsAnimationEffect*) -> BindPlaybackDirection:
    return this.m_playback_direction

## Ported from Libraries/LibWeb/Animations/AnimationEffect.h:110 Web::Animations::AnimationEffect::set_playback_direction.
pub func animations_animation_effect_set_playback_direction(this: AnimationsAnimationEffect*, playback_direction: BindPlaybackDirection):
    this.m_playback_direction = playback_direction

## Ported from Libraries/LibWeb/Animations/AnimationEffect.h:112 Web::Animations::AnimationEffect::timing_function.
pub func animations_animation_effect_timing_function(this: AnimationsAnimationEffect*) -> const CssEasingFunction*:
    return &this.m_timing_function

## Ported from Libraries/LibWeb/Animations/AnimationEffect.h:113 Web::Animations::AnimationEffect::set_timing_function.
pub func animations_animation_effect_set_timing_function(this: AnimationsAnimationEffect*, value: CssEasingFunction):
    this.m_timing_function = value

## Ported from Libraries/LibWeb/Animations/AnimationEffect.h:115 Web::Animations::AnimationEffect::associated_animation.
pub func animations_animation_effect_associated_animation(this: AnimationsAnimationEffect*) -> AnimationsAnimation*?:
    return this.m_associated_animation

## Ported from Libraries/LibWeb/Animations/AnimationEffect.h:147 Web::Animations::AnimationEffect::previous_phase.
pub func animations_animation_effect_previous_phase(this: AnimationsAnimationEffect*) -> AnimationsAnimationEffectPhase:
    return this.m_previous_phase

## Ported from Libraries/LibWeb/Animations/AnimationEffect.h:148 Web::Animations::AnimationEffect::set_previous_phase.
pub func animations_animation_effect_set_previous_phase(this: AnimationsAnimationEffect*, value: AnimationsAnimationEffectPhase):
    this.m_previous_phase = value

## Ported from Libraries/LibWeb/Animations/AnimationEffect.h:149 Web::Animations::AnimationEffect::previous_current_iteration.
pub func animations_animation_effect_previous_current_iteration(this: AnimationsAnimationEffect*) -> f64:
    return this.m_previous_current_iteration

## Ported from Libraries/LibWeb/Animations/AnimationEffect.h:150 Web::Animations::AnimationEffect::set_previous_current_iteration.
pub func animations_animation_effect_set_previous_current_iteration(this: AnimationsAnimationEffect*, value: f64):
    this.m_previous_current_iteration = value

## Ported from Libraries/LibWeb/Animations/AnimationEffect.h:161 Web::Animations::AnimationEffect::target_properties.
pub func animations_animation_effect_target_properties(this: AnimationsAnimationEffect*) -> const ak.HashTable[css_data.PropertyId, css_data.PropertyIdTraits]*:
    return &this.m_target_properties

## Ported from Libraries/LibWeb/Animations/AnimationEffect.h:163 Web::Animations::AnimationEffect::target (virtual).
pub func animations_animation_effect_target_impl(this: AnimationsAnimationEffect*) -> DomElement*?:
    return none

## Ported from Libraries/LibWeb/Animations/AnimationEffect.h:164 Web::Animations::AnimationEffect::is_keyframe_effect (virtual).
pub func animations_animation_effect_is_keyframe_effect_impl(this: AnimationsAnimationEffect*) -> bool:
    return false

# mark: Conversions and the timing dictionaries =================================================

## Ported from Libraries/LibWeb/Animations/AnimationEffect.cpp:30 Web::Animations::css_fill_mode_to_bindings_fill_mode.
pub func animations_css_fill_mode_to_bindings_fill_mode(mode: css_data.AnimationFillMode) -> BindFillMode:
    match mode:
        .backwards:
            return BindFillMode.backwards
        .both:
            return BindFillMode.both
        .forwards:
            return BindFillMode.forwards
        .none_:
            return BindFillMode.none_
        _:
            trap("VERIFY_NOT_REACHED")

## Ported from Libraries/LibWeb/Animations/AnimationEffect.cpp:46 Web::Animations::css_animation_direction_to_bindings_playback_direction.
pub func animations_css_animation_direction_to_bindings_playback_direction(direction: css_data.AnimationDirection) -> BindPlaybackDirection:
    match direction:
        .alternate:
            return BindPlaybackDirection.alternate
        .alternate_reverse:
            return BindPlaybackDirection.alternate_reverse
        .normal:
            return BindPlaybackDirection.normal
        .reverse:
            return BindPlaybackDirection.reverse
        _:
            trap("VERIFY_NOT_REACHED")

## Ported from Libraries/LibWeb/Animations/AnimationEffect.cpp:62 Web::Animations::EffectTiming::to_optional_effect_timing.
pub func animations_effect_timing_to_optional_effect_timing(this: const AnimationsEffectTiming*) -> AnimationsOptionalEffectTiming:
    var duration: F64OrString = F64OrString.f64_(0.0)
    match this.duration:
        .f64_(value):
            duration = F64OrString.f64_(value)
        .string(value):
            duration = F64OrString.string(value)
        .css_numeric_value(value):
            # NB: We check that this isn't the case in the caller
            _ = value
            trap("VERIFY_NOT_REACHED")
    return AnimationsOptionalEffectTiming(delay = this.delay, end_delay = this.end_delay, fill = this.fill, iteration_start = this.iteration_start, iterations = this.iterations, duration = duration, direction = this.direction, easing = this.easing)

## Ported from Libraries/LibWeb/Animations/AnimationEffect.cpp:81 Web::Animations::AnimationEffect::get_timing.
# https://www.w3.org/TR/web-animations-1/#dom-animationeffect-gettiming
pub func animations_animation_effect_get_timing(this: AnimationsAnimationEffect*) -> AnimationsEffectTiming:
    # 1. Returns the specified timing properties for this animation effect.
    var duration = F64OrCssNumericValueOrString.f64_(0.0)
    match this.m_specified_iteration_duration:
        .f64_(value):
            duration = F64OrCssNumericValueOrString.f64_(value)
        .string(value):
            duration = F64OrCssNumericValueOrString.string(value)
    return AnimationsEffectTiming(delay = this.m_specified_start_delay, end_delay = this.m_specified_end_delay, fill = this.m_fill_mode, iteration_start = this.m_iteration_start, iterations = this.m_iteration_count, duration = duration, direction = this.m_playback_direction, easing = css_easing_function_to_string(&this.m_timing_function))

## Ported from Libraries/LibWeb/Animations/AnimationEffect.cpp:98 Web::Animations::AnimationEffect::get_computed_timing.
# https://www.w3.org/TR/web-animations-1/#dom-animationeffect-getcomputedtiming
# https://drafts.csswg.org/web-animations-2/#dom-animationeffect-getcomputedtiming
pub func animations_animation_effect_get_computed_timing(this: AnimationsAnimationEffect*) -> AnimationsComputedEffectTiming:
    let realm = bind_platform_object_realm(this.bind_platform_object())

    # 1. Returns the calculated timing properties for this animation effect.

    # Note: Although some of the attributes of the object returned by getTiming() and getComputedTiming() are common,
    #       their values may differ in the following ways:

    #     - duration: while getTiming() may return the string auto, getComputedTiming() must return a number
    #       corresponding to the calculated value of the iteration duration as defined in the description of the
    #       duration member of the EffectTiming interface.
    #
    #       If duration is the string auto, this attribute will return the current calculated value of the intrinsic
    #       iteration duration, which may be a expressed as a double representing the duration in milliseconds or a
    #       percentage when the effect is associated with a progress-based timeline.
    var duration = F64OrCssNumericValueOrString.f64_(0.0)
    match animations_time_value_as_css_numberish(this.m_iteration_duration, realm):
        .double_(value):
            duration = F64OrCssNumericValueOrString.f64_(value)
        .css_numeric_value(value):
            duration = F64OrCssNumericValueOrString.css_numeric_value(value)

    #     - fill: likewise, while getTiming() may return the string auto, getComputedTiming() must return the specific
    #       FillMode used for timing calculations as defined in the description of the fill member of the EffectTiming
    #       interface.
    #
    #       In this level of the specification, that simply means that an auto value is replaced by the none FillMode.
    let fill = BindFillMode.none_ if this.m_fill_mode == BindFillMode.auto else this.m_fill_mode

    let effect_timing = AnimationsEffectTiming(delay = this.m_specified_start_delay, end_delay = this.m_specified_end_delay, fill = fill, iteration_start = this.m_iteration_start, iterations = this.m_iteration_count, duration = duration, direction = this.m_playback_direction, easing = css_easing_function_to_string(&this.m_timing_function))

    return AnimationsComputedEffectTiming(effect_timing = effect_timing,
                                          end_time = animations_time_value_as_css_numberish(animations_animation_effect_end_time(this), realm),
                                          active_duration = animations_time_value_as_css_numberish(animations_animation_effect_active_duration(this), realm),
                                          local_time = animations_nullable_css_numberish_from_optional_css_numberish_time(realm, animations_animation_effect_local_time(this)),
                                          progress = animations_animation_effect_transformed_progress(this),
                                          current_iteration = animations_animation_effect_current_iteration(this))

# mark: Normalizing the specified timing ========================================================

## Ported from Libraries/LibWeb/Animations/AnimationEffect.cpp:142 Web::Animations::AnimationEffect::intrinsic_iteration_duration (protected).
# https://drafts.csswg.org/web-animations-2/#intrinsic-iteration-duration
pub func animations_animation_effect_intrinsic_iteration_duration(this: AnimationsAnimationEffect*) -> AnimationsTimeValue:
    # The intrinsic iteration duration is calculated from the first matching condition from below:

    # FIXME: If the animation effect is a group effect,
    #        Follow the procedure in § 2.10.3 The intrinsic iteration duration of a group effect

    # FIXME: If the animation effect is a sequence effect,
    #        Follow the procedure in § 2.10.4.2 The intrinsic iteration duration of a sequence effect

    # If timeline duration is unresolved or iteration count is zero,
    if animations_animation_effect_timeline_duration(this) == none or this.m_iteration_count == 0.0:
        # Return 0
        return animations_time_value_create_zero(animations_animation_effect_associated_timeline(this))

    # Otherwise
    # Return(100% - start delay - end delay) / iteration count
    # Note : Presently start and end delays are zero until such time as percentage based delays are supported.
    let one_hundred_percent = AnimationsTimeValue(type_ = AnimationsTimeValueType.percentage, value = 100.0)

    return animations_time_value_div(animations_time_value_sub(animations_time_value_sub(one_hundred_percent, this.m_start_delay), this.m_end_delay), this.m_iteration_count)

## Ported from Libraries/LibWeb/Animations/AnimationEffect.cpp:174 Web::Animations::AnimationEffect::associated_timeline (protected).
pub func animations_animation_effect_associated_timeline(this: AnimationsAnimationEffect*) -> AnimationsAnimationTimeline*?:
    let animation = this.m_associated_animation else return none

    return animations_animation_timeline(animation)

## Ported from Libraries/LibWeb/Animations/AnimationEffect.cpp:182 Web::Animations::AnimationEffect::timeline_duration (protected).
pub func animations_animation_effect_timeline_duration(this: AnimationsAnimationEffect*) -> AnimationsTimeValue?:
    let timeline = animations_animation_effect_associated_timeline(this) else return none

    return animations_animation_timeline_duration(timeline)

## Ported from Libraries/LibWeb/Animations/AnimationEffect.cpp:192 Web::Animations::AnimationEffect::convert_a_time_based_animation_to_a_proportional_animation (protected).
# https://drafts.csswg.org/web-animations-2/#time-based-animation-to-a-proportional-animation
pub func animations_animation_effect_convert_a_time_based_animation_to_a_proportional_animation(this: AnimationsAnimationEffect*):
    # AD-HOC: We use the specified interation duration instead of the iteration duration here, see
    #         https://github.com/w3c/csswg-drafts/pull/13170
    # If the iteration duration is auto, then perform the following steps.
    var specified_iteration_duration = 0.0
    match this.m_specified_iteration_duration:
        .string(value):
            _ = value
            # Set start delay and end delay to 0, as it is not possible to mix time and proportions.
            # Note: Future versions may allow these properties to be assigned percentages, at which point the delays are
            #       only to be ignored if their values are expressed as times and not as percentages.
            this.m_start_delay = animations_time_value_create_zero(animations_animation_effect_associated_timeline(this))
            this.m_end_delay = animations_time_value_create_zero(animations_animation_effect_associated_timeline(this))

            # AD-HOC: The spec doesn't say what to set iteration duration to in this case so we set it to the intrinsic
            #         iteration duration, see: https://github.com/w3c/csswg-drafts/issues/13220
            this.m_iteration_duration = animations_animation_effect_intrinsic_iteration_duration(this)
            return
        .f64_(value):
            specified_iteration_duration = value

    # Otherwise:

    # NB: The caller asserts that timeline duration is resolved
    let timeline_duration = animations_animation_effect_timeline_duration(this) else trap("VERIFY: the timeline duration is resolved")

    # 1. Let total time be equal to end time
    # AD-HOC: Using end time here only works if we haven't already converted to a proportional animation, we instead
    #         recompute the specified equivalent of "end time", see https://github.com/w3c/csswg-drafts/issues/13230
    let specified_end_time = this.m_specified_start_delay + (specified_iteration_duration * this.m_iteration_count) + this.m_specified_end_delay
    let total_time = 0.0 if specified_end_time < 0.0 else specified_end_time  # AK::max(..., 0)

    # AD-HOC: Avoid a division by zero below, see https://github.com/w3c/csswg-drafts/issues/11276
    if total_time == 0.0:
        this.m_start_delay = animations_time_value_create_zero(animations_animation_effect_associated_timeline(this))
        this.m_iteration_duration = animations_time_value_create_zero(animations_animation_effect_associated_timeline(this))
        this.m_end_delay = animations_time_value_create_zero(animations_animation_effect_associated_timeline(this))
        return

    # 2. Set start delay to be the result of evaluating specified start delay / total time * timeline duration.
    this.m_start_delay = animations_time_value_mul(timeline_duration, this.m_specified_start_delay / total_time)

    # 3. Set iteration duration to be the result of evaluating specified iteration duration / total time * timeline duration.
    this.m_iteration_duration = animations_time_value_mul(timeline_duration, specified_iteration_duration / total_time)

    # 4. Set end delay to be the result of evaluating specified end delay / total time * timeline duration.
    this.m_end_delay = animations_time_value_mul(timeline_duration, this.m_specified_end_delay / total_time)

## Ported from Libraries/LibWeb/Animations/AnimationEffect.cpp:239 Web::Animations::AnimationEffect::normalize_specified_timing.
# https://drafts.csswg.org/web-animations-2/#normalize-specified-timing
pub func animations_animation_effect_normalize_specified_timing(this: AnimationsAnimationEffect*):
    # If timeline duration is resolved:
    if animations_animation_effect_timeline_duration(this) != none:
        # Follow the procedure to convert a time-based animation to a proportional animation
        animations_animation_effect_convert_a_time_based_animation_to_a_proportional_animation(this)
    # Otherwise:
    else:
        # 1. Set start delay = specified start delay
        this.m_start_delay = AnimationsTimeValue(type_ = AnimationsTimeValueType.milliseconds, value = this.m_specified_start_delay)

        # 2. Set end delay = specified end delay
        this.m_end_delay = AnimationsTimeValue(type_ = AnimationsTimeValueType.milliseconds, value = this.m_specified_end_delay)

        # 3. If iteration duration is auto:
        # AD-HOC: We use the specified interation duration instead of the iteration duration here, see
        #         https://github.com/w3c/csswg-drafts/pull/13170
        match this.m_specified_iteration_duration:
            .string(value):
                _ = value
                # Set iteration duration = intrinsic iteration duration
                this.m_iteration_duration = animations_animation_effect_intrinsic_iteration_duration(this)
            # Otherwise:
            .f64_(value):
                # Set iteration duration = specified iteration duration
                this.m_iteration_duration = AnimationsTimeValue(type_ = AnimationsTimeValueType.milliseconds, value = value)

## Ported from Libraries/LibWeb/Animations/AnimationEffect.cpp:272 Web::Animations::AnimationEffect::update_timing.
# https://www.w3.org/TR/web-animations-1/#dom-animationeffect-updatetiming
# https://www.w3.org/TR/web-animations-1/#update-the-timing-properties-of-an-animation-effect
# https://drafts.csswg.org/web-animations-2/#updating-animationeffect-timing
pub func animations_animation_effect_update_timing(this: AnimationsAnimationEffect*, timing: AnimationsOptionalEffectTiming = AnimationsOptionalEffectTiming()) -> !:
    # 1. If the iterationStart member of input exists and is less than zero, throw a TypeError and abort this
    #    procedure.
    if let iteration_start = timing.iteration_start:
        if iteration_start < 0.0:
            return try idl_throw_simple(IdlSimpleExceptionType.type_error, .string_view(ak.sv("Invalid iteration start value")))

    # 2. If the iterations member of input exists, and is less than zero or is the value NaN, throw a TypeError and
    #    abort this procedure.
    if let iterations = timing.iterations:
        if iterations < 0.0 or math.is_nan(iterations):
            return try idl_throw_simple(IdlSimpleExceptionType.type_error, .string_view(ak.sv("Invalid iteration count value")))

    # 3. If the duration member of input exists, and is less than zero or is the value NaN, throw a TypeError and
    #    abort this procedure.
    # Note: "auto", the only valid string value, is treated as 0.
    var has_valid_duration_value = true
    if let duration = timing.duration:
        match duration:
            .f64_(value):
                if value < 0.0 or math.is_nan(value):
                    has_valid_duration_value = false
            .string(value):
                if not ak.string_eq_string_view(&value, ak.sv("auto")):
                    has_valid_duration_value = false
    if not has_valid_duration_value:
        return try idl_throw_simple(IdlSimpleExceptionType.type_error, .string_view(ak.sv("Invalid duration value")))

    # 4. If the easing member of input exists but cannot be parsed using the <easing-function> production
    #    [CSS-EASING-1], throw a TypeError and abort this procedure.
    var easing_value: CssEasingFunction? = none
    if let easing = timing.easing:
        easing_value = animations_animation_effect_parse_easing_string(ak.string_bytes_as_string_view(&easing))
        if easing_value == none:
            return try idl_throw_simple(IdlSimpleExceptionType.type_error, .string_view(ak.sv("Invalid easing function")))

    # 5. Assign each member that exists in input to the corresponding timing property of effect as follows:

    #    - delay → specified start delay
    if let delay = timing.delay:
        this.m_specified_start_delay = delay

    #    - endDelay → specified end delay
    if let end_delay = timing.end_delay:
        this.m_specified_end_delay = end_delay

    #    - fill → fill mode
    if let fill = timing.fill:
        this.m_fill_mode = fill

    #    - iterationStart → iteration start
    if let iteration_start = timing.iteration_start:
        this.m_iteration_start = iteration_start

    #    - iterations → iteration count
    if let iterations = timing.iterations:
        this.m_iteration_count = iterations

    #    - duration → specified iteration duration
    if let duration = timing.duration:
        this.m_specified_iteration_duration = duration

    #    - direction → playback direction
    if let direction = timing.direction:
        this.m_playback_direction = direction

    #    - easing → timing function
    if let easing = easing_value:
        this.m_timing_function = easing

    # 6. Follow the procedure to normalize specified timing.
    animations_animation_effect_normalize_specified_timing(this)

    # AD-HOC: Notify the associated animation that the effect timing has changed.
    if let animation = this.m_associated_animation:
        animations_animation_effect_timing_changed(animation)

## Ported from Libraries/LibWeb/Animations/AnimationEffect.cpp:353 Web::Animations::AnimationEffect::set_associated_animation.
pub func animations_animation_effect_set_associated_animation(this: AnimationsAnimationEffect*, value: AnimationsAnimation*?):
    this.m_associated_animation = value

    # NB: The normalization of the specified timing depends on the timeline of the associated animation.
    animations_animation_effect_normalize_specified_timing(this)

# mark: Direction and times =====================================================================

## Ported from Libraries/LibWeb/Animations/AnimationEffect.cpp:362 Web::Animations::AnimationEffect::animation_direction.
# https://www.w3.org/TR/web-animations-1/#animation-direction
pub func animations_animation_effect_animation_direction(this: AnimationsAnimationEffect*) -> AnimationsAnimationDirection:
    # "backwards" if the effect is associated with an animation and the associated animation’s playback rate is less
    # than zero; in all other cases, the animation direction is "forwards".
    if let animation = this.m_associated_animation:
        if animations_animation_playback_rate(animation) < 0.0:
            return AnimationsAnimationDirection.backwards
    return AnimationsAnimationDirection.forwards

## Ported from Libraries/LibWeb/Animations/AnimationEffect.cpp:372 Web::Animations::AnimationEffect::end_time.
# https://www.w3.org/TR/web-animations-1/#end-time
pub func animations_animation_effect_end_time(this: AnimationsAnimationEffect*) -> AnimationsTimeValue:
    # 1. The end time of an animation effect is the result of evaluating
    #    max(start delay + active duration + end delay, 0).
    let end_time = animations_time_value_add(animations_time_value_add(this.m_start_delay, animations_animation_effect_active_duration(this)), this.m_end_delay)
    return animations_time_value_max(end_time, animations_time_value_create_zero(animations_animation_effect_associated_timeline(this)))

## Ported from Libraries/LibWeb/Animations/AnimationEffect.cpp:380 Web::Animations::AnimationEffect::local_time.
# https://www.w3.org/TR/web-animations-1/#local-time
pub func animations_animation_effect_local_time(this: AnimationsAnimationEffect*) -> AnimationsTimeValue?:
    # The local time of an animation effect at a given moment is based on the first matching condition from the
    # following:

    # -> If the animation effect is associated with an animation,
    if let animation = this.m_associated_animation:
        # the local time is the current time of the animation.
        return animations_animation_current_time(animation)

    # -> Otherwise,
    #    the local time is unresolved.
    return none

## Ported from Libraries/LibWeb/Animations/AnimationEffect.cpp:397 Web::Animations::AnimationEffect::active_duration.
# https://www.w3.org/TR/web-animations-1/#active-duration
pub func animations_animation_effect_active_duration(this: AnimationsAnimationEffect*) -> AnimationsTimeValue:
    # The active duration is calculated as follows:
    #     active duration = iteration duration × iteration count
    # If either the iteration duration or iteration count are zero, the active duration is zero. This clarification is
    # needed since the result of infinity multiplied by zero is undefined according to IEEE 754-2008.
    if this.m_iteration_duration.value == 0.0 or this.m_iteration_count == 0.0:
        return animations_time_value_create_zero(animations_animation_effect_associated_timeline(this))

    return animations_time_value_mul(this.m_iteration_duration, this.m_iteration_count)

## Ported from Libraries/LibWeb/Animations/AnimationEffect.cpp:409 Web::Animations::AnimationEffect::active_time.
pub func animations_animation_effect_active_time(this: AnimationsAnimationEffect*) -> AnimationsTimeValue?:
    return animations_animation_effect_active_time_using_fill(this, this.m_fill_mode)

## Ported from Libraries/LibWeb/Animations/AnimationEffect.cpp:415 Web::Animations::AnimationEffect::active_time_using_fill.
# https://www.w3.org/TR/web-animations-1/#calculating-the-active-time
pub func animations_animation_effect_active_time_using_fill(this: AnimationsAnimationEffect*, fill_mode: BindFillMode) -> AnimationsTimeValue?:
    # The active time is based on the local time and start delay. However, it is only defined when the animation effect
    # should produce an output and hence depends on its fill mode and phase as follows,

    # -> If the animation effect is in the before phase,
    if animations_animation_effect_is_in_the_before_phase(this):
        # The result depends on the first matching condition from the following,

        # -> If the fill mode is backwards or both,
        if fill_mode == BindFillMode.backwards or fill_mode == BindFillMode.both:
            # Return the result of evaluating max(local time - start delay, 0).
            let local_time = animations_animation_effect_local_time(this) else trap("VERIFY: a resolved local time")
            return animations_time_value_max(animations_time_value_sub(local_time, this.m_start_delay), animations_time_value_create_zero(animations_animation_effect_associated_timeline(this)))

        # -> Otherwise,
        #    Return an unresolved time value.
        return none

    # -> If the animation effect is in the active phase,
    if animations_animation_effect_is_in_the_active_phase(this):
        # Return the result of evaluating local time - start delay.
        let local_time = animations_animation_effect_local_time(this) else trap("VERIFY: a resolved local time")
        return animations_time_value_sub(local_time, this.m_start_delay)

    # -> If the animation effect is in the after phase,
    if animations_animation_effect_is_in_the_after_phase(this):
        # The result depends on the first matching condition from the following,

        # -> If the fill mode is forwards or both,
        if fill_mode == BindFillMode.forwards or fill_mode == BindFillMode.both:
            # Return the result of evaluating max(min(local time - start delay, active duration), 0).
            let local_time = animations_animation_effect_local_time(this) else trap("VERIFY: a resolved local time")
            let clamped = animations_time_value_min(animations_time_value_sub(local_time, this.m_start_delay), animations_animation_effect_active_duration(this))
            return animations_time_value_max(clamped, animations_time_value_create_zero(animations_animation_effect_associated_timeline(this)))

        # -> Otherwise,
        #    Return an unresolved time value.
        return none

    # -> Otherwise (the local time is unresolved),
    #    Return an unresolved time value.
    return none