Web Animations CSS Integration

Editor’s Draft,

This version:
none
Feedback:
public-fx@w3.org with subject line “[web-animations-css] … message topic …” (archives)
Issue Tracking:
Inline In Spec
Editor:

Abstract

This specification defines mappings between [CSS3-ANIMATIONS], [CSS3-TRANSITIONS] and the [WEB-ANIMATIONS] model.

Status of this document

This is a public copy of the editors' draft. It is provided for discussion only and may change at any moment. Its publication here does not imply endorsement of its contents by W3C. Don’t cite this document other than as work in progress.

The contents of this draft are intended to be incorporated into Level 2 of both the CSS Animations and CSS Transitions specifications as these specifications are drafted.

The (archived) public mailing list public-fx@w3.org (see instructions) is preferred for discussion of this specification. When sending e-mail, please put the text “web-animations-css” in the subject, preferably like this: “[web-animations-css] …summary of comment…

This document was produced by the CSS Working Group (part of the Style Activity) and the SVG Working Group (part of the Graphics Activity).

This document was produced by groups operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures (CSS) and a public list of any patent disclosures (SVG) made in connection with the deliverables of each group; these pages also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

Table of Contents

1. Introduction

[CSS3-ANIMATIONS] and [CSS3-TRANSITIONS] provide models for defining declarative animations via CSS. [SVG12] provides a model for defining declarative animations via SVG. However, the three specifications do not define or present a unified animation model.

To solve this problem, the [WEB-ANIMATIONS] specification defines a comprehensive animation model that is capable of supporting [CSS3-ANIMATIONS], [CSS3-TRANSITIONS] and [SVG12].

This document describes how [CSS3-ANIMATIONS] and [CSS3-TRANSITIONS] are supported by the [WEB-ANIMATIONS] model.

2. CSS Transitions

For CSS Transitions, mappings into the Web Animations model are established pairwise for a specific CSS property, the transitioning property, on a specific element, the transitioning element.

When a CSS Transition is started for the transitioning property of a transitioning element, an Animation is constructed and associated with a Player on the document timeline, configured with a custom player priority which ensures that the Player sorts before Players created through the Web Animations API and those generated for CSS Animations. The Animation is configured as follows:

Note, changes to the values of the transition-delay, transition-duration, and transition-timing-function have no effect on a transition once it has started.

When a transition affecting the transitioning property of a transitioning element is removed or interrupted the cancel method of the corresponding Player is called.

When a transition affecting the transitioning property of a transitioning element is reversed the cancel method of the corresponding Player is called and a new Player is generated as if the transition had just begun.

2.1. CSS Transitions events

The transitionend event is triggered to fire each time the corresponding Animation enters the after phase during a sample.

3. CSS Animations

3.1. The CSSKeyframesMap mapping

This feature is at risk.

[MapClass(String, AnimationEffect)]
interface CSSKeyframesMap {
};

partial interface Document {
    readonly attribute CSSKeyframesMap keyframes;
};

3.1.1. The CSSKeyframesMap interface

The CSSKeyframesMap interface defines a map type that can be used to store sequences of Keyframes indexed by Strings.

3.1.2. Document.keyframes

The keyframes attribute on the Document interface references a map of type CSSKeyframesMap.

Note: The CSSKeyframesMap enables animations created using the Web Animations API to re-use the keyframe rules declared by CSS, and for animations declared by CSS to act on AnimationEffects created through the API.

Note: The processing defined in this section does not alter the way in which keyframes rules are selected when CSS animations are started, unless a name is explicitly overridden by setting its value in the map.

When a new @keyframes rule name is encountered in a style sheet, the action taken depends upon the current value stored against the name in the keyframes map.

If the current value has never been set, or has only been set due to style changes:
The keyframes defined by the @keyframes rule are converted into a KeyframeEffect (see §3.1.3 Converting a CSS Keyframes rule into a KeyframeEffect), then stored against the name in the keyframes map.
Otherwise:
The rule is ignored.

Should the KeyframeEffects generated by @keyframes rules be read-only?

When the used @keyframes rule associated with a given name changes due to a change in a style sheet, the action taken depends upon the current value stored against the name in the keyframes map.

If the current value has only been set due to style changes:
The keyframes defined by the new rule are converted into a KeyframeEffect (see §3.1.3 Converting a CSS Keyframes rule into a KeyframeEffect), then stored against the name in the keyframes map.
Otherwise:
The change is ignored.

When the last @keyframes rule for a given name is removed from a style sheet, the action taken depends upon the current value stored against the name in the keyframes map.

If the current value has only been set due to style changes:
The value referenced by the @keyframes name is cleared from the keyframes map.
Otherwise:
The removal is ignored.

3.1.3. Converting a CSS Keyframes rule into a KeyframeEffect

A CSS @keyframes rule keyframes is converted into a KeyframeEffect using the following process:

  1. Initialize an empty list keyframeList.
  2. For each keyframe in keyframes:
    1. Create a new dictionary newKeyframe.
    2. Set newKeyframe’s offset to the offset defined by keyframe.
    3. If keyframe defines an animation-timing-function, set newKeyframe’s easing to the defined animation-timing-function.
    4. For each property defined in keyframe:
      1. Set newKeyframe[property] to the value associated with that property in keyframe
      2. Add property to referencedProperties.
  3. Add newKeyframe to keyframeList.
  4. Remove keyframes with duplicated offsets from keyframeListsuch that only the last keyframe to specify a given offset remains.
  5. Construct a new KeyframeEffect, providing keyframeList as the frames parameter.

3.2. Web Animations Instantiation

For CSS Animations, mappings into the Web Animations model are established pairwise between a specific AnimationEffect, the animating effect, and a specific element, the animating element.

When a CSS Animation is to be started, the value of animation-name is used as an index into the keyframes map, and the matching AnimationEffect (if any) is used to instantiate the animating effect by following the procedure defined below (see §3.4 Instantiating the animating effect ).

When a CSS Animation is started an Animation is constructed and associated with a Player on the Document Timeline. The animation is configured as follows:

Deal with animation-play-state

Explain where we need to cancel the Player for a css animation.

3.3. CSS Animations Events

The animationstart event is triggered to fire each time the corresponding Animation enters the active phase or after phase during a sample.

The animationiteration event is triggered to fire, on each sample where all of the following conditions are met:

  1. the corresponding Animation is in the active phase
  2. the corresponding Animation was in the active phase on the last sample
  3. the corresponding Animation has a current iteration which is different to the current iteration of the last sample.

The animationend event is triggered to fire each time the corresponding Animation enters the after phase during a sample.

3.4. Instantiating the animating effect

The animating effect is instantiated from an AnimationEffect (the reference effect) stored in the keyframes attribute using the following process:

turn this into boring old specificese

If the reference effect is a KeyframeEffect which was converted from a CSS @keyframes rule using the process defined in §3.1.3 Converting a CSS Keyframes rule into a KeyframeEffect:
  1. The result effect is created as a clone of the reference effect.
  2. Convert "add" keyframes at an offset of 0 and 1 by snapshotting their referenced properties from the computed style of the animating element, then changing the keyframe to a "replace" keyframe.
  3. Set the easing of all keyframes which do not have an easing to the value of animation-timing-function.
Otherwise
The animating effect is the reference effect.

4. Exposure in the Web Animations API

Players generated by CSS Animations and CSS Transitions are accessible via getAnimationPlayers with the restriction that source will point to a read-only TimedItem which disallows changes to its specified timing and effect.

Note: The Player remains fully functional. The source, playbackRate, currentTime, startTime and play control methods will be live and function as normal.

REMOVE ME: Definitions that should be resolved by Web Animations

animation player document timeline target element start delay iteration duration timing function animation effect keyframe animation effect keyframes after phase custom player priority cancel getanimationplayers TimedItem source specified timing effect playbackRate currentTime keyframeEffect offset animationEffect sample easing iteration count direction fill mode current iteration active phase

Conformance

Document conventions

Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.

All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]

Examples in this specification are introduced with the words "for example" or are set apart from the normative text with class="example", like this:

This is an example of an informative example.

Informative notes begin with the word "Note" and are set apart from the normative text with class="note", like this:

Note, this is an informative note.

Advisements are normative sections styled to evoke special attention and are set apart from other normative text with <strong class="advisement">, like this: UAs MUST provide an accessible alternative.

Conformance classes

Conformance to this specification is defined for three conformance classes:

style sheet
A CSS style sheet.
renderer
A UA that interprets the semantics of a style sheet and renders documents that use them.
authoring tool
A UA that writes a style sheet.

A style sheet is conformant to this specification if all of its statements that use syntax defined in this module are valid according to the generic CSS grammar and the individual grammars of each feature defined in this module.

A renderer is conformant to this specification if, in addition to interpreting the style sheet as defined by the appropriate specifications, it supports all the features defined by this specification by parsing them correctly and rendering the document accordingly. However, the inability of a UA to correctly render a document due to limitations of the device does not make the UA non-conformant. (For example, a UA is not required to render color on a monochrome monitor.)

An authoring tool is conformant to this specification if it writes style sheets that are syntactically correct according to the generic CSS grammar and the individual grammars of each feature in this module, and meet all other conformance requirements of style sheets as described in this module.

Partial implementations

So that authors can exploit the forward-compatible parsing rules to assign fallback values, CSS renderers must treat as invalid (and ignore as appropriate) any at-rules, properties, property values, keywords, and other syntactic constructs for which they have no usable level of support. In particular, user agents must not selectively ignore unsupported component values and honor supported values in a single multi-value property declaration: if any value is considered invalid (as unsupported values must be), CSS requires that the entire declaration be ignored.

Experimental implementations

To avoid clashes with future CSS features, the CSS2.1 specification reserves a prefixed syntax for proprietary and experimental extensions to CSS.

Prior to a specification reaching the Candidate Recommendation stage in the W3C process, all implementations of a CSS feature are considered experimental. The CSS Working Group recommends that implementations use a vendor-prefixed syntax for such features, including those in W3C Working Drafts. This avoids incompatibilities with future changes in the draft.

Non-experimental implementations

Once a specification reaches the Candidate Recommendation stage, non-experimental implementations are possible, and implementors should release an unprefixed implementation of any CR-level feature they can demonstrate to be correctly implemented according to spec.

To establish and maintain the interoperability of CSS across implementations, the CSS Working Group requests that non-experimental CSS renderers submit an implementation report (and, if necessary, the testcases used for that implementation report) to the W3C before releasing an unprefixed implementation of any CSS features. Testcases submitted to W3C are subject to review and correction by the CSS Working Group.

Further information on submitting testcases and implementation reports can be found from on the CSS Working Group’s website at http://www.w3.org/Style/CSS/Test/. Questions should be directed to the public-css-testsuite@w3.org mailing list.

References

Normative References

[rfc2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://tools.ietf.org/html/rfc2119

Informative References

[SVG12]
Dean Jackson; Craig Northway. Scalable Vector Graphics (SVG) Full 1.2 Specification. 13 April 2005. WD. URL: http://www.w3.org/TR/SVG12
[css3-animations]
Dean Jackson; et al. CSS Animations. 19 February 2013. WD. URL: http://www.w3.org/TR/css3-animations/
[css3-transitions]
Dean Jackson; et al. CSS Transitions. 19 November 2013. WD. URL: http://www.w3.org/TR/css3-transitions/
[web-animations]
Brian Birtles; et al. Web Animations 1.0. 5 June 2014. WD. URL: http://www.w3.org/TR/web-animations/

Index

IDL Index

//FIXME: figure out the appropriate thing to do here and remove this!

interface String { };

[MapClass(String, AnimationEffect)]
interface CSSKeyframesMap {
};

partial interface Document {
    readonly attribute CSSKeyframesMap keyframes;
};

Issues Index

This feature is at risk.
Should the KeyframeEffects generated by @keyframes rules be read-only?
Deal with animation-play-state
Explain where we need to cancel the Player for a css animation.
turn this into boring old specificese