From 0637c736d60daf8a3eb52a666569cf6748b624b0 Mon Sep 17 00:00:00 2001 From: Jeremy Kahn Date: Mon, 3 Jul 2023 10:07:30 -0500 Subject: [PATCH] feat(easing): export standardEasingFunctions --- src/index.ts | 1 + ...ing-functions.ts => standard-easing-functions.ts} | 12 ++++++------ src/tweenable.ts | 8 +++++--- src/types.ts | 8 ++++---- 4 files changed, 16 insertions(+), 13 deletions(-) rename src/{easing-functions.ts => standard-easing-functions.ts} (93%) diff --git a/src/index.ts b/src/index.ts index 10dfb50a..d9db5cf1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,5 +9,6 @@ export { processTweens, shouldScheduleUpdate, Tweenable, tween } export { interpolate } from './interpolate' export { Scene } from './scene' export { setBezierFunction } from './bezier' +export { standardEasingFunctions } from './standard-easing-functions' export * from './types' diff --git a/src/easing-functions.ts b/src/standard-easing-functions.ts similarity index 93% rename from src/easing-functions.ts rename to src/standard-easing-functions.ts index 3f7c4467..93d57aab 100644 --- a/src/easing-functions.ts +++ b/src/standard-easing-functions.ts @@ -14,13 +14,13 @@ */ /** - * The base set of easing functions availble for use with Shifty tweens. + * The standard set of easing functions availble for use with Shifty tweens. * - * This is distinct from {@link Tweenable.easing}. {@link Tweenable.easing} - * contains everything within `easingFunctions` but also any custom easing - * functions that you have defined. + * This is distinct from `Tweenable`'s {@link Tweenable.easing}. {@link + * Tweenable.easing} contains everything within `easingFunctions` but also any + * custom easing functions that you have defined. */ -export const baseEasingFunctions = { +export const standardEasingFunctions = Object.freeze({ linear: (pos: number) => pos, easeInQuad: (pos: number) => Math.pow(pos, 2), @@ -175,4 +175,4 @@ export const baseEasingFunctions = { easeFrom: (pos: number) => Math.pow(pos, 4), easeTo: (pos: number) => Math.pow(pos, 0.25), -} +}) diff --git a/src/tweenable.ts b/src/tweenable.ts index e693b51c..9be160ab 100644 --- a/src/tweenable.ts +++ b/src/tweenable.ts @@ -1,4 +1,4 @@ -import { baseEasingFunctions } from './easing-functions' +import { standardEasingFunctions } from './standard-easing-functions' import { getCubicBezierTransition } from './bezier' import { Data, @@ -132,7 +132,7 @@ export const tweenProps = ( // easingObjectProp is a string easingFn = Tweenable.easing[easingObjectProp as EasingKey] ?? - baseEasingFunctions.linear + standardEasingFunctions.linear } } @@ -386,7 +386,9 @@ export class Tweenable { * Tweenable.easing['customEasing'] = (pos: number) => Math.pow(pos, 2) * ``` */ - static easing: typeof baseEasingFunctions = Object.create(baseEasingFunctions) + static easing: Record = Object.create( + standardEasingFunctions + ) /** * @ignore diff --git a/src/types.ts b/src/types.ts index 6320bef1..2a84c3fb 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,5 +1,5 @@ import { Tweenable } from './tweenable' -import { baseEasingFunctions } from './easing-functions' +import { standardEasingFunctions } from './standard-easing-functions' /** * Asynchronous scheduling function. By default this is @@ -90,7 +90,7 @@ export interface EasingFunction { /** * A string identifier of an easing curve to use for an animation. */ -export type EasingKey = keyof typeof baseEasingFunctions +export type EasingKey = keyof typeof standardEasingFunctions /** * A map of {@link TweenState} property names to the easing identifier or @@ -179,13 +179,13 @@ export interface TweenableConfig { /** * This value can be one of several different types: * - * - `string`: Name of the {@link baseEasingFunctions} to apply to all properties + * - `string`: Name of the {@link standardEasingFunctions} to apply to all properties * of the tween. * - {@link EasingFunction}: A custom function that computes the rendered * position of the tween for the given normalized (0-1) position of the * tween. * - `Record`: Keys are tween property - * names. Values are the {@link baseEasingFunctions} string IDs to be applied to + * names. Values are the {@link standardEasingFunctions} string IDs to be applied to * each tween property, or a {@link EasingFunction}. Any tween properties not * explicitly included in the `Record` default to `'linear'`. * - `Array.`: The array must contain four `number` values that