Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[web-animations-2] Specify Animation progress API #9937

Merged
merged 3 commits into from
Feb 29, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion web-animations-2/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,34 @@ Add the following sentence:

</div>

### Calculating the progress of an animation ### {#the-progress-of-an-animation}

An animation's <dfn export for=animation>progress</dfn> is the ratio of its
[=animation/current time=] to its [=associated effect end=].

<div algorithm="calculate animation progress">
The [=animation/progress=] of an [=animation=], |animation|, is calculated as follows:

<dl class=switch>

: If <em>any</em> of the following are true:
* |animation| does not have an [=animation/associated effect=], or
* |animation|'s [=associated effect end=] is zero, or
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making these edits. Two follow-up questions that occurred to me:

  1. If the associated effect end is zero, should the progress be 1 (or 0 if the current time is negative)? It seems odd that it's unresolved here but maybe I'm just not remembering how all this works?
  2. Just to check, should we be clamping the progress to [0, 1]? I assume we shouldn't but I guess it depends on how we expect this property to be used? The answer to this will likely affect how we define the behavior for zero-duration animations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making these edits. Two follow-up questions that occurred to me:

  1. If the associated effect end is zero, should the progress be 1 (or 0 if the current time is negative)? It seems odd that it's unresolved here but maybe I'm just not remembering how all this works?

I agree, it more accurately reflects the animated progress to return a value here.

  1. Just to check, should we be clamping the progress to [0, 1]? I assume we shouldn't but I guess it depends on how we expect this property to be used? The answer to this will likely affect how we define the behavior for zero-duration animations.

It seems like it's more useful to allow progresses outside of the [0, 1] range, as especially for 0 it matters to know whether the effect is active or not. That said, allowing values outside of [0, 1] makes it more complicated for how to handle the 0 duration case. Perhaps we should use +/- infinity depending on whether you're before or after the start time?

@bramus @fantasai any thoughts here?

Copy link
Contributor

@flackr flackr Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking further on this, it may be simpler to restrict to [0, 1] and encourage authors to combine with the phase of the animation which seems like another thing that's not too easy to get today. Restricting to the [0, 1] range makes the answer to edge cases much easier to reason about, e.g. what we should do for a 0 duration effect.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think you're right. Ultimately, though, it probably depends on how we expect the API to be used.

We could mimic the behaviour of progress on ComputedEffectTiming and use the fill mode and phase of the root animation effect to make progress be unresolved when the root effect is not in effect but that might be a bit of a layering violation?

For reference, I believe ComputedEffectTiming.progress is mostly in the range [0, 1] but can extend outside that range due to easing functions.

I guess it comes back to reviewing these issues and seeing what would work best in each of those cases (quoting #8799):

In #8669, #8765 and #8201 there seems to be a common desire to have more convenient APIs for getting some representation of progress.

* |animation|'s [=animation/current time=] is an [=unresolved=] time value,
::
|animation|'s [=animation/progress=] is null.
: If |animation|'s [=associated effect end=] is infinite,
|animation|'s [=animation/progress=] is zero.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the author tell if we're active (after the start time) or inactive (before the start time)?

: Otherwise,
::
<blockquote>
<code><a for="animation">progress</a> = [=animation/current time=] / |animation|'s [=associated effect end=]
</code>
</blockquote>

</dl>
</div>


<h3 id="animation-effects">Animation effects</h3>

Expand Down Expand Up @@ -2390,7 +2418,7 @@ Update the attribute type for currentTime.
<h3 id="the-animation-interface">The <code>Animation</code> interface</h3>

Update the startTime and currentTime of the Animation interface, and add
rangeStart and rangeEnd as follows:
rangeStart, rangeEnd, and progress as follows:

<pre class="idl">
[Exposed=Window]
Expand All @@ -2399,6 +2427,7 @@ partial interface Animation {
attribute CSSNumberish? currentTime;
attribute (TimelineRangeOffset or CSSNumericValue or CSSKeywordValue or DOMString) rangeStart;
attribute (TimelineRangeOffset or CSSNumericValue or CSSKeywordValue or DOMString) rangeEnd;
readonly attribute double? progress;
};
</pre>

Expand Down Expand Up @@ -2443,6 +2472,10 @@ Add:
> <a href="#dom-keyframeanimationoptions-rangeend">rangeEnd</a>.
> When reading the attribute, the returned value is either a
> {{TimelineRangeOffset}} or the {{DOMString}} "normal".
>
> : <dfn attribute for=Animation>progress</dfn>
> :: Specifies the [=animation/progress=] of the <a>animation</a> as a proportion of its
> [=associated effect end=].
</div>

<h3 id="the-animationeffect-interface">The <code>AnimationEffect</code> interface</h3>
Expand Down