Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
reececomo committed Apr 24, 2024
1 parent ae77d82 commit 85d3bb2
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 59 deletions.
17 changes: 9 additions & 8 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
{
"root": true,
"rules": {
"newline-before-return": 0,
"prefer-const": 0,
"no-fallthrough": 0,
"@typescript-eslint/indent": 0,
"@typescript-eslint/no-duplicate-enum-values": 0,
"@typescript-eslint/no-inferrable-types": 0,
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/no-empty-function": 0,
"@typescript-eslint/no-empty-interface": 0,
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/no-extra-semi": 0,
"@typescript-eslint/no-inferrable-types": 0,
"@typescript-eslint/no-non-null-assertion": 0,
"@typescript-eslint/no-empty-function": 0,
"@typescript-eslint/no-this-alias": 0,
"@typescript-eslint/unified-signatures": 0,
"@typescript-eslint/indent": 0,
"@typescript-eslint/no-extra-semi": 0,
"newline-before-return": 0,
"no-fallthrough": 0,
"prefer-const": 0,
"@typescript-eslint/explicit-member-accessibility": 1,
"no-trailing-spaces": "warn",
"@typescript-eslint/ban-types": "warn",
Expand Down
83 changes: 41 additions & 42 deletions src/TimingMode.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
/**
* Timing mode function.
*
* @see {TimingMode} for https://easings.net imports
*/
export type TimingModeFn = (progress: number) => number;

/** A number 0 -> 1 */
type Progress = number;

const pow = Math.pow;
const sqrt = Math.sqrt;
const sin = Math.sin;
Expand All @@ -19,7 +9,7 @@ const c3 = c1 + 1;
const c4 = (2 * PI) / 3;
const c5 = (2 * PI) / 4.5;

const _bounceOut = function (x: Progress): number {
const _bounceOut = function (x: number): number {
const n1 = 7.5625;
const d1 = 2.75;

Expand All @@ -37,66 +27,75 @@ const _bounceOut = function (x: Progress): number {
}
};

/**
* Any timing mode function.
*
* @example x => x // Linear, constant-time.
*
* @see {TimingMode}
*/
export type TimingModeFn = (x: number) => number;

/**
* Timing mode functions
* https://easings.net/
*
* @see https://easings.net/
* @see https://raw.githubusercontent.com/ai/easings.net/master/src/easings/easingsFunctions.ts
*/
export const TimingMode = {
linear: (x: Progress): number => x,
easeInQuad: function (x: Progress): number {
linear: (x: number): number => x,
easeInQuad: function (x: number): number {
return x * x;
},
easeOutQuad: function (x: Progress): number {
easeOutQuad: function (x: number): number {
return 1 - (1 - x) * (1 - x);
},
easeInOutQuad: function (x: Progress): number {
easeInOutQuad: function (x: number): number {
return x < 0.5 ? 2 * x * x : 1 - pow(-2 * x + 2, 2) / 2;
},
easeInCubic: function (x: Progress): number {
easeInCubic: function (x: number): number {
return x * x * x;
},
easeOutCubic: function (x: Progress): number {
easeOutCubic: function (x: number): number {
return 1 - pow(1 - x, 3);
},
easeInOutCubic: function (x: Progress): number {
easeInOutCubic: function (x: number): number {
return x < 0.5 ? 4 * x * x * x : 1 - pow(-2 * x + 2, 3) / 2;
},
easeInQuart: function (x: Progress): number {
easeInQuart: function (x: number): number {
return x * x * x * x;
},
easeOutQuart: function (x: Progress): number {
easeOutQuart: function (x: number): number {
return 1 - pow(1 - x, 4);
},
easeInOutQuart: function (x: Progress): number {
easeInOutQuart: function (x: number): number {
return x < 0.5 ? 8 * x * x * x * x : 1 - pow(-2 * x + 2, 4) / 2;
},
easeInQuint: function (x: Progress): number {
easeInQuint: function (x: number): number {
return x * x * x * x * x;
},
easeOutQuint: function (x: Progress): number {
easeOutQuint: function (x: number): number {
return 1 - pow(1 - x, 5);
},
easeInOutQuint: function (x: Progress): number {
easeInOutQuint: function (x: number): number {
return x < 0.5 ? 16 * x * x * x * x * x : 1 - pow(-2 * x + 2, 5) / 2;
},
easeInSine: function (x: Progress): number {
easeInSine: function (x: number): number {
return 1 - cos((x * PI) / 2);
},
easeOutSine: function (x: Progress): number {
easeOutSine: function (x: number): number {
return sin((x * PI) / 2);
},
easeInOutSine: function (x: Progress): number {
easeInOutSine: function (x: number): number {
return -(cos(PI * x) - 1) / 2;
},
easeInExpo: function (x: Progress): number {
easeInExpo: function (x: number): number {
return x === 0 ? 0 : pow(2, 10 * x - 10);
},
easeOutExpo: function (x: Progress): number {
easeOutExpo: function (x: number): number {
return x === 1 ? 1 : 1 - pow(2, -10 * x);
},
easeInOutExpo: function (x: Progress): number {
easeInOutExpo: function (x: number): number {
return x === 0
? 0
: x === 1
Expand All @@ -105,43 +104,43 @@ export const TimingMode = {
? pow(2, 20 * x - 10) / 2
: (2 - pow(2, -20 * x + 10)) / 2;
},
easeInCirc: function (x: Progress): number {
easeInCirc: function (x: number): number {
return 1 - sqrt(1 - pow(x, 2));
},
easeOutCirc: function (x: Progress): number {
easeOutCirc: function (x: number): number {
return sqrt(1 - pow(x - 1, 2));
},
easeInOutCirc: function (x: Progress): number {
easeInOutCirc: function (x: number): number {
return x < 0.5
? (1 - sqrt(1 - pow(2 * x, 2))) / 2
: (sqrt(1 - pow(-2 * x + 2, 2)) + 1) / 2;
},
easeInBack: function (x: Progress): number {
easeInBack: function (x: number): number {
return c3 * x * x * x - c1 * x * x;
},
easeOutBack: function (x: Progress): number {
easeOutBack: function (x: number): number {
return 1 + c3 * pow(x - 1, 3) + c1 * pow(x - 1, 2);
},
easeInOutBack: function (x: Progress): number {
easeInOutBack: function (x: number): number {
return x < 0.5
? (pow(2 * x, 2) * ((c2 + 1) * 2 * x - c2)) / 2
: (pow(2 * x - 2, 2) * ((c2 + 1) * (x * 2 - 2) + c2) + 2) / 2;
},
easeInElastic: function (x: Progress): number {
easeInElastic: function (x: number): number {
return x === 0
? 0
: x === 1
? 1
: -pow(2, 10 * x - 10) * sin((x * 10 - 10.75) * c4);
},
easeOutElastic: function (x: Progress): number {
easeOutElastic: function (x: number): number {
return x === 0
? 0
: x === 1
? 1
: pow(2, -10 * x) * sin((x * 10 - 0.75) * c4) + 1;
},
easeInOutElastic: function (x: Progress): number {
easeInOutElastic: function (x: number): number {
return x === 0
? 0
: x === 1
Expand All @@ -150,11 +149,11 @@ export const TimingMode = {
? -(pow(2, 20 * x - 10) * sin((20 * x - 11.125) * c5)) / 2
: (pow(2, -20 * x + 10) * sin((20 * x - 11.125) * c5)) / 2 + 1;
},
easeInBounce: function (x: Progress): number {
easeInBounce: function (x: number): number {
return 1 - _bounceOut(1 - x);
},
easeOutBounce: _bounceOut,
easeInOutBounce: function (x: Progress): number {
easeInOutBounce: function (x: number): number {
return x < 0.5
? (1 - _bounceOut(1 - 2 * x)) / 2
: (1 + _bounceOut(2 * x - 1)) / 2;
Expand Down
5 changes: 1 addition & 4 deletions src/mixin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ActionTicker } from "./lib/ActionTicker";
import { _ as Action } from "./Action";
import { ActionTicker } from "./lib/ActionTicker";
import { getSpeed } from "./lib/utils/displayobject";

//
Expand All @@ -15,12 +15,10 @@ export function registerGlobalMixin(displayObject: any): void {
const prototype = displayObject.prototype;

// - Properties:

prototype.speed = 1.0;
prototype.isPaused = false;

// - Methods:

prototype.run = function (_action: Action, completion?: () => void): void {
const action = completion ? Action.sequence([_action, Action.run(completion)]) : _action;
ActionTicker.runAction(undefined, this, action);
Expand All @@ -34,7 +32,6 @@ export function registerGlobalMixin(displayObject: any): void {
action: Action,
timeoutBufferMs: number = 100
): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const node = this;
return new Promise(function (resolve, reject) {
const timeLimitMs = timeoutBufferMs + (getSpeed(node) * action.duration * 1_000);
Expand Down
8 changes: 3 additions & 5 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// typealiases

declare global {

/** Time measured in seconds. */
Expand All @@ -8,16 +6,16 @@ declare global {
/** Targeted display node. */
type TargetNode = PIXI.DisplayObject;

/** Targeted display node that has a width/height. */
/** Targeted display node with a width and height. */
type SizedTargetNode = TargetNode & SizeLike;

/** A vector (e.g. PIXI.Point, or any node). */
/** Any vector-like object (e.g. PIXI.Point, or any node). */
interface VectorLike {
x: number;
y: number;
}

/** Any object with a width and height. */
/** Any object with a width and height (e.g. PIXI.Sprite). */
interface SizeLike {
width: number;
height: number;
Expand Down

0 comments on commit 85d3bb2

Please sign in to comment.