mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Added type definitions for moveto (#29362)
This commit is contained in:
parent
93761156bb
commit
1038a88306
96
types/moveto/index.d.ts
vendored
Normal file
96
types/moveto/index.d.ts
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
// Type definitions for moveto 1.7
|
||||
// Project: https://github.com/hsnaydd/moveTo
|
||||
// Definitions by: Rostislav Shermenyov <https://github.com/shermendev>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare class MoveTo {
|
||||
/**
|
||||
* MoveTo Constructor
|
||||
* @param options Options
|
||||
* @param easeFunctions Custom ease functions
|
||||
*/
|
||||
constructor(
|
||||
options?: MoveTo.MoveToOptions,
|
||||
easeFunctions?: MoveTo.MoveToEaseFunctionsObject
|
||||
);
|
||||
/**
|
||||
* Options
|
||||
*/
|
||||
options: MoveTo.MoveToOptions;
|
||||
/**
|
||||
* Custom ease functions
|
||||
*/
|
||||
easeFunctions: MoveTo.MoveToEaseFunctionsObject;
|
||||
/**
|
||||
* Start scroll animation from current position to the anchor point
|
||||
* @param target Target element/position to be scrolled. Target position is the scrolling distance. It must be negative if the upward movement is desired
|
||||
* @param options Custom options
|
||||
*/
|
||||
move(target: HTMLElement | number, options?: MoveTo.MoveToOptions): void;
|
||||
/**
|
||||
* Register a dom element as trigger
|
||||
* @param dom The trigger element for starting to scroll when on click
|
||||
* @param callback Callback function to be run after the scroll complete. This will overwrite the callback option
|
||||
* @return Unregister function
|
||||
*/
|
||||
registerTrigger(
|
||||
dom: HTMLElement,
|
||||
callback?: MoveTo.callbackType
|
||||
): MoveTo.unregisterTriggerType;
|
||||
/**
|
||||
* Adds custom ease function
|
||||
* @param name Ease function name
|
||||
* @param fn Ease function
|
||||
*/
|
||||
addEaseFunction(name: string, fn: MoveTo.MoveToEaseFunction): void;
|
||||
}
|
||||
|
||||
declare namespace MoveTo {
|
||||
type unregisterTriggerType = () => void;
|
||||
|
||||
/**
|
||||
* Callback function to be run after the scroll complete.
|
||||
*/
|
||||
type callbackType = (target: HTMLElement | number) => void;
|
||||
|
||||
interface MoveToOptions {
|
||||
/**
|
||||
* The tolerance of the target to be scrolled, can be negative or positive
|
||||
*/
|
||||
tolerance?: number;
|
||||
/**
|
||||
* Duration of scrolling, in milliseconds
|
||||
*/
|
||||
duration?: number;
|
||||
/**
|
||||
* Ease function name
|
||||
*/
|
||||
easing?: string;
|
||||
/**
|
||||
* The function to be run after scrolling complete. Target passes as the first argument
|
||||
*/
|
||||
callback?: callbackType;
|
||||
}
|
||||
|
||||
interface MoveToEaseFunctionsObject {
|
||||
[key: string]: MoveToEaseFunction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Easing Function
|
||||
* @param t Current time
|
||||
* @param b Start value
|
||||
* @param c Change in value
|
||||
* @param d Duration
|
||||
* @return Calculated value
|
||||
*/
|
||||
type MoveToEaseFunction = (
|
||||
t: number,
|
||||
b: number,
|
||||
c: number,
|
||||
d: number
|
||||
) => number;
|
||||
}
|
||||
|
||||
export = MoveTo;
|
||||
export as namespace MoveTo;
|
||||
36
types/moveto/moveto-tests.ts
Normal file
36
types/moveto/moveto-tests.ts
Normal file
@ -0,0 +1,36 @@
|
||||
const options: MoveTo.MoveToOptions = {
|
||||
tolerance: 70,
|
||||
duration: 300,
|
||||
easing: "easeOutQuart",
|
||||
callback: () => {}
|
||||
};
|
||||
|
||||
const easeFunctions: MoveTo.MoveToEaseFunctionsObject = {
|
||||
fun1: () => 123,
|
||||
fun2: t => t,
|
||||
fun3: (t, b) => t + b,
|
||||
fun4: (t, b, c) => t + b + c,
|
||||
fun5: (t, b, c, d) => t + b + c + d
|
||||
};
|
||||
|
||||
const a = new MoveTo();
|
||||
const b = new MoveTo(options);
|
||||
|
||||
const moveToInstance = new MoveTo(options, easeFunctions);
|
||||
|
||||
moveToInstance.move(123);
|
||||
|
||||
const element = document.getElementById("#anchor");
|
||||
|
||||
if (element) {
|
||||
moveToInstance.move(element, options);
|
||||
|
||||
const unregister = moveToInstance.registerTrigger(element, () => {});
|
||||
|
||||
unregister();
|
||||
}
|
||||
|
||||
console.log(moveToInstance.options);
|
||||
console.log(moveToInstance.easeFunctions);
|
||||
|
||||
moveToInstance.addEaseFunction("ease-out", (t, b, c, d) => t + b + c + d);
|
||||
24
types/moveto/tsconfig.json
Normal file
24
types/moveto/tsconfig.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"moveto-tests.ts"
|
||||
]
|
||||
}
|
||||
3
types/moveto/tslint.json
Normal file
3
types/moveto/tslint.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user