[csswg-drafts] [web-animations-2] Allow Animation constructor to take an object of properties as second param (#11146)

ydaniv has just created a new issue for https://github.com/w3c/csswg-drafts:

== [web-animations-2] Allow Animation constructor to take an object of properties as second param ==
Currently the [`Animation()` constructor](https://drafts.csswg.org/web-animations-1/#dom-animation-animation) is defined as:

> `Animation (effect, timeline)`
> ...
> `timeline`
An optional value which, if present, specifies the timeline with which to associate the newly-created animation. If missing, the default document timeline of the Document associated with the Window that is the current global object is used.

This doesn't leave any declarative way to set any of the other `Animation`'s attributes.
These attributes are:

- `rangeStart` and `rangeEnd`
- `id`

And of course we can add to that: 

- `timeline` 

And we're also in the process of adding:

- [`trigger`](#8942)

---------------

### Proposal

Allow the second param to be an object containing all the `Animation`-related properties, so they can be set declaratively in a single expression.

Example:

```javascript
const animation = new Animation(keyframeEffect, {
  id: 'some-anim-5',
  trigger: new AnimationTrigger({
    type: 'alternate',
    timeline: new ViewTimeline({ subject })
  })
});
```

Or:

```javascript
const animation = new Animation(keyframeEffect, {
  rangeStart: 'entry 50%',
  rangeEnd: 'exit 50%',
  timeline: new ViewTimeline({ subject })
});
```

I can also see possible future extensions, but the above should already allow a much  more convenient and coherent API.

cc @flackr @birtles @bramus 

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/11146 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Saturday, 2 November 2024 13:02:42 UTC