Skip to content

Commit

Permalink
feat(easing): export standardEasingFunctions
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyckahn committed Jul 3, 2023
1 parent 532042e commit 0637c73
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
12 changes: 6 additions & 6 deletions src/easing-functions.ts → src/standard-easing-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -175,4 +175,4 @@ export const baseEasingFunctions = {
easeFrom: (pos: number) => Math.pow(pos, 4),

easeTo: (pos: number) => Math.pow(pos, 0.25),
}
})
8 changes: 5 additions & 3 deletions src/tweenable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { baseEasingFunctions } from './easing-functions'
import { standardEasingFunctions } from './standard-easing-functions'
import { getCubicBezierTransition } from './bezier'
import {
Data,
Expand Down Expand Up @@ -132,7 +132,7 @@ export const tweenProps = <T extends TweenRawState>(
// easingObjectProp is a string
easingFn =
Tweenable.easing[easingObjectProp as EasingKey] ??
baseEasingFunctions.linear
standardEasingFunctions.linear
}
}

Expand Down Expand Up @@ -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<string, EasingFunction> = Object.create(
standardEasingFunctions
)

/**
* @ignore
Expand Down
8 changes: 4 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<string, string | EasingFunction>`: 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.<number>`: The array must contain four `number` values that
Expand Down

0 comments on commit 0637c73

Please sign in to comment.