Skip to content

Commit

Permalink
Fix for IE arguments issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Rycochet committed Apr 10, 2020
1 parent 726955c commit 9933bba
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 117 deletions.
22 changes: 12 additions & 10 deletions src/Velocity/easing/bezier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
*/

// Typedefs
import {VelocityEasingFn} from "../../../velocity.d";
import { VelocityEasingFn } from "../../../velocity.d";

// Project
import {registerEasing} from "./easings";
import { registerEasing } from "./easings";

/**
* Fix to a range of <code>0 <= num <= 1</code>.
Expand Down Expand Up @@ -39,7 +39,7 @@ function getSlope(aT, aA1, aA2) {
return 3 * A(aA1, aA2) * aT * aT + 2 * B(aA1, aA2) * aT + C(aA1);
}

export function generateBezier(mX1: number, mY1: number, mX2: number, mY2: number): VelocityEasingFn {
export function generateBezier(...args: [number, number, number, number]): VelocityEasingFn {
const NEWTON_ITERATIONS = 4,
NEWTON_MIN_SLOPE = 0.001,
SUBDIVISION_PRECISION = 0.0000001,
Expand All @@ -48,21 +48,23 @@ export function generateBezier(mX1: number, mY1: number, mX2: number, mY2: numbe
kSampleStepSize = 1 / (kSplineTableSize - 1),
float32ArraySupported = "Float32Array" in window;

/* Must contain four arguments. */
if (arguments.length !== 4) {
/* Must contain four args. */
if (args.length !== 4) {
return;
}

/* Arguments must be numbers. */
/* Args must be numbers. */
for (let i = 0; i < 4; ++i) {
if (typeof arguments[i] !== "number" || isNaN(arguments[i]) || !isFinite(arguments[i])) {
if (typeof args[i] !== "number" || isNaN(args[i]) || !isFinite(args[i])) {
return;
}
}

/* X values must be in the [0, 1] range. */
mX1 = fixRange(mX1);
mX2 = fixRange(mX2);
const mX1 = fixRange(args[0]);
const mY1 = args[1];
const mX2 = fixRange(args[2]);
const mY2 = args[3];

const mSampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize);

Expand Down Expand Up @@ -155,7 +157,7 @@ export function generateBezier(mX1: number, mY1: number, mX2: number, mY2: numbe
};

(f as any).getControlPoints = () => {
return [{x: mX1, y: mY1}, {x: mX2, y: mY2}];
return [{ x: mX1, y: mY1 }, { x: mX2, y: mY2 }];
};
f.toString = () => {
return str;
Expand Down
14 changes: 7 additions & 7 deletions src/Velocity/normalizations/normalizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
*/

// Typedefs
import {HTMLorSVGElement, VelocityNormalizationsFn} from "../../../velocity.d";
import { HTMLorSVGElement, VelocityNormalizationsFn } from "../../../velocity.d";

// Project
import {isFunction, isString} from "../../types";
import {registerAction} from "../actions/actions";
import {Data} from "../data";
import {ClassConstructor, constructorCache, constructors, NoCacheNormalizations, Normalizations, NormalizationUnits} from "./normalizationsObject";
import { isFunction, isString } from "../../types";
import { registerAction } from "../actions/actions";
import { Data } from "../data";
import { ClassConstructor, constructorCache, constructors, NoCacheNormalizations, Normalizations, NormalizationUnits } from "./normalizationsObject";

/**
* Used to register a normalization. This should never be called by users
Expand Down Expand Up @@ -60,7 +60,7 @@ export function registerNormalization(
index = constructors.indexOf(constructorCache.get(constructor));
} else {
for (const property in window) {
if (window[property] === constructor) {
if ((window[property] as any) === constructor) {
index = constructors.indexOf(property);
if (index < 0) {
index = constructors.push(property) - 1;
Expand Down Expand Up @@ -105,7 +105,7 @@ export function hasNormalization(args?: [ClassConstructor | string, string]): bo
index = constructors.indexOf(constructorCache.get(constructor));
} else {
for (const property in window) {
if (window[property] === constructor) {
if ((window[property] as any) === constructor) {
index = constructors.indexOf(property);
break;
}
Expand Down
32 changes: 16 additions & 16 deletions src/velocity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ import {
} from "./../velocity.d";

// Project
import {defineProperty} from "./utility";
import {Actions as ActionsObject} from "./Velocity/actions/actions";
import {defaults as DefaultObject} from "./Velocity/defaults";
import {Easings as EasingsObject} from "./Velocity/easing/easings";
import {patch as patchFn} from "./Velocity/patch";
import {SequencesObject} from "./Velocity/sequencesObject";
import {State as StateObject} from "./Velocity/state";
import {Velocity as VelocityFn} from "./velocityFn";
import { defineProperty } from "./utility";
import { Actions as ActionsObject } from "./Velocity/actions/actions";
import { defaults as DefaultObject } from "./Velocity/defaults";
import { Easings as EasingsObject } from "./Velocity/easing/easings";
import { patch as patchFn } from "./Velocity/patch";
import { SequencesObject } from "./Velocity/sequencesObject";
import { State as StateObject } from "./Velocity/state";
import { Velocity as VelocityFn } from "./velocityFn";

// Build the entire library, even optional bits.
import "./Velocity/_all";

// Constants
import {VERSION} from "../version";
import { VERSION } from "../version";
const Velocity: VelocityPublic = VelocityFn as any;

/**
Expand All @@ -40,17 +40,17 @@ namespace VelocityStatic {
* All external method calls should be using actions rather than sub-calls
* of Velocity itself.
*/
export const Actions: {[name: string]: VelocityActionFn} = ActionsObject;
export const Actions: { [name: string]: VelocityActionFn } = ActionsObject;

/**
* Our known easing functions.
*/
export const Easings: {[name: string]: VelocityEasingFn} = EasingsObject;
export const Easings: { [name: string]: VelocityEasingFn } = EasingsObject;

/**
* The currently registered sequences.
*/
export const Sequences: {[name: string]: SequenceList} = SequencesObject;
export const Sequences: { [name: string]: SequenceList } = SequencesObject;

/**
* Current internal state of Velocity.
Expand All @@ -60,7 +60,7 @@ namespace VelocityStatic {
/**
* Velocity option defaults, which can be overriden by the user.
*/
export const defaults: StrictVelocityOptions & {reset?: () => void} = DefaultObject as any;
export const defaults: StrictVelocityOptions & { reset?: () => void } = DefaultObject as any;

/**
* Used to patch any object to allow Velocity chaining. In order to chain an
Expand Down Expand Up @@ -144,8 +144,8 @@ if (window) {
* both act on wrapped DOM elements and stand alone for targeting raw DOM
* elements.
*/
const jQuery: {fn: any} = (window as any).jQuery,
Zepto: {fn: any} = (window as any).Zepto;
const jQuery: { fn: any } = (window as any).jQuery,
Zepto: { fn: any } = (window as any).Zepto;

patchFn(window, true);
patchFn(Element && Element.prototype);
Expand All @@ -170,7 +170,7 @@ for (const property in VelocityStatic) {
return VelocityStatic[property];
},
set(value) {
VelocityStatic[property] = value;
(VelocityStatic[property] as any) = value;
},
}, true);
break;
Expand Down
34 changes: 15 additions & 19 deletions src/velocityFn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@ import {
} from "./../velocity.d";

// Project
import {isBoolean, isFunction, isNode, isNumber, isPlainObject, isString, isVelocityResult, isWrapped} from "./types";
import {cloneArray, defineProperty, getValue} from "./utility";
import {Data} from "./Velocity/data";
import { isBoolean, isFunction, isNode, isNumber, isPlainObject, isString, isVelocityResult, isWrapped } from "./types";
import { cloneArray, defineProperty, getValue } from "./utility";
import { Data } from "./Velocity/data";
import {
validateBegin, validateComplete, validateDelay, validateDuration, validateEasing,
validateLoop, validateProgress, validateQueue, validateRepeat, validateSpeed, validateSync,
} from "./Velocity/options";
import {patch as patchFn} from "./Velocity/patch";
import {queue} from "./Velocity/queue";
import {expandSequence} from "./Velocity/sequences";
import {tick} from "./Velocity/tick";
import {expandProperties} from "./Velocity/tweens";
import { patch as patchFn } from "./Velocity/patch";
import { queue } from "./Velocity/queue";
import { expandSequence } from "./Velocity/sequences";
import { tick } from "./Velocity/tick";
import { expandProperties } from "./Velocity/tweens";

import {Actions as ActionsObject} from "./Velocity/actions/actions";
import {defaults as DefaultObject} from "./Velocity/defaults";
import {SequencesObject} from "./Velocity/sequencesObject";
import {State as StateObject} from "./Velocity/state";
import { Actions as ActionsObject } from "./Velocity/actions/actions";
import { defaults as DefaultObject } from "./Velocity/defaults";
import { SequencesObject } from "./Velocity/sequencesObject";
import { State as StateObject } from "./Velocity/state";

let globalPromise: PromiseConstructor;

try {
globalPromise = Promise;
} catch {/**/}
} catch {/**/ }

const noPromiseOption = ", if that is deliberate then pass `promiseRejectEmpty:false` as an option";

Expand Down Expand Up @@ -68,16 +68,12 @@ export function Velocity(this: VelocityElements, propertyMap: string | Propertie
export function Velocity(this: VelocityElements, propertyMap: string | Properties<VelocityProperty>, easing?: string | number[], complete?: () => void): VelocityResult;
export function Velocity(this: VelocityElements, propertyMap: string | Properties<VelocityProperty>, duration?: number | "fast" | "normal" | "slow", easing?: string | number[], complete?: () => void): VelocityResult;
/* tslint:enable:max-line-length */
export function Velocity(this: VelocityElements | void, ...argsList: any[]): VelocityResult {
export function Velocity(this: VelocityElements | void, ...args: any[]): VelocityResult {
const
/**
* A shortcut to the default options.
*/
defaults = DefaultObject,
/**
* Shortcut to arguments for file size.
*/
args = arguments,
/**
* Cache of the first argument - this is used often enough to be saved.
*/
Expand Down Expand Up @@ -134,7 +130,7 @@ export function Velocity(this: VelocityElements | void, ...argsList: any[]): Vel
// Used when there was an issue with one or more of the Velocity arguments
rejecter: (reason: any) => void;

//console.log(`Velocity`, _arguments)
//console.log(`Velocity`, args)
// First get the elements, and the animations connected to the last call if
// this is chained.
// TODO: Clean this up a bit
Expand Down
10 changes: 5 additions & 5 deletions test/src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import "qunit";

import Velocity, {ElementData, VelocityOptions, VelocityProperties} from "velocity-animate";
import Velocity, { ElementData, VelocityOptions, VelocityProperties } from "velocity-animate";

declare global {
interface QUnit {
Expand Down Expand Up @@ -78,7 +78,7 @@ let asyncCount = 0;

QUnit.config.reorder = false;

export function applyStartValues(element: HTMLElement, startValues: {[name: string]: string}) {
export function applyStartValues(element: HTMLElement, startValues: { [name: string]: string }) {
$.each(startValues, (property, startValue) => {
element.style[property] = startValue;
});
Expand All @@ -96,7 +96,7 @@ export function getPropertyValue(element: HTMLElement, property: string): string
return Velocity(element, "style", property);
}

export function getTarget(startValues?: {[name: string]: string}): HTMLDivElement {
export function getTarget(startValues?: { [name: string]: string }): HTMLDivElement {
const div = document.createElement("div") as HTMLDivElement;

div.className = "target";
Expand All @@ -119,9 +119,9 @@ export function once(func): typeof func {
let done: boolean,
result: any;

return function(this: any) {
return function(this: any, ...args: any[]) {
if (!done) {
result = func.apply(this, arguments);
result = func.apply(this, args);
func = done = true; // Don't care about type, just let the GC collect if possible
}

Expand Down
6 changes: 5 additions & 1 deletion test/test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/test.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 9933bba

Please sign in to comment.