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

[css-easing-2] Provide JavaScript API for CSS easing functions #6261

Open
mattgperry opened this issue May 2, 2021 · 4 comments
Open

[css-easing-2] Provide JavaScript API for CSS easing functions #6261

mattgperry opened this issue May 2, 2021 · 4 comments
Labels
css-easing-2 Current Work

Comments

@mattgperry
Copy link

With new proposals for complex easing functions, the amount of API surface JavaScript animation libraries are duplicating is to increase.

This is a waste of bundle size when these functions are already present in the browser. This cubic-bezier implementation alone can cost 1kb minified, so I'm eager that when new easing curves appear there's already requirement for them to be available to JS authors.

It would also ensure browser-based animation authoring tools like Framer could use the current browser's exact implementation when displaying and editing easing curves.

Proposal

A new Easing namespace, which contains access to the specced easing curves:

// cubic-bezier
const curve = Easing.cubicBezier(.17,.67,.83,.67)
const easedProgress = curve(0.5)

// steps
const stepped = Easing.steps(4, "end")
const easedProgress = stepped(0.5)

This would also allow the composition of easing functions:

stepped(curve(0.5))

And their usage outside of the Web Animations API, for instance drawing visualisations:

Screenshot of Framer's bezier editing tool

@mattgperry mattgperry changed the title [css-easing-2] Permit direct JS access to easing functions [css-easing-2] Provide JavaScript API for easing functions May 2, 2021
@mattgperry mattgperry changed the title [css-easing-2] Provide JavaScript API for easing functions [css-easing-2] Provide JavaScript API for CSS easing functions May 2, 2021
@Loirooriol
Copy link
Contributor

Maybe inside CSS, though? CSS.easing.cubicBezier(.17,.67,.83,.67)

@mattgperry
Copy link
Author

Yep! Not precious over the namespace, gotta make that clear 😀

@Jamesernator
Copy link

Jamesernator commented May 2, 2021

These are probably a good candidate for typed OM, CSS transforms already have something similar in that you can get out a matrix with new CSSTranslate(CSS.px(3), CSS.px(5)).toMatrix().

I'm not entirely sure why there's only a few functions available in typed OM, but it'd make sense to have something like that for easing:

const easing = new CSSEasingCubicBezier(CSS.number(.17),CSS.number(.67),CSS.number(.83),CSS.number(.67));
console.log(easing.valueAt(0.5));

@tabatkins
Copy link
Member

I'm not entirely sure why there's only a few functions available in typed OM,

Because CSS is a big beast, and the design of Typed OM allows for us to define things gradually. ^_^

But yeah, Typed OM definitely needs the easing functions as values at some point, and when we do, having a convenience method that lets you explicitly evaluate it at a given progress value makes a ton of sense.

@fantasai fantasai added the css-easing-2 Current Work label Jun 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css-easing-2 Current Work
Projects
None yet
Development

No branches or pull requests

5 participants