From 295fefafaf639ac1743c86c7201f2387be379aee Mon Sep 17 00:00:00 2001 From: Andrei Horodinca Date: Mon, 5 Nov 2018 15:43:06 +0100 Subject: [PATCH 1/7] Add types for smooth-scroll --- types/smooth-scroll/index.d.ts | 62 +++++++++++++++++++ types/smooth-scroll/package.json | 6 ++ .../test/smooth-scroll-global.test.ts | 34 ++++++++++ .../smooth-scroll/test/smooth-scroll.test.ts | 36 +++++++++++ types/smooth-scroll/tsconfig.json | 19 ++++++ types/smooth-scroll/tslint.json | 1 + 6 files changed, 158 insertions(+) create mode 100644 types/smooth-scroll/index.d.ts create mode 100644 types/smooth-scroll/package.json create mode 100644 types/smooth-scroll/test/smooth-scroll-global.test.ts create mode 100644 types/smooth-scroll/test/smooth-scroll.test.ts create mode 100644 types/smooth-scroll/tsconfig.json create mode 100644 types/smooth-scroll/tslint.json diff --git a/types/smooth-scroll/index.d.ts b/types/smooth-scroll/index.d.ts new file mode 100644 index 0000000000..a5aa54fd24 --- /dev/null +++ b/types/smooth-scroll/index.d.ts @@ -0,0 +1,62 @@ +// Type definitions for smooth-scroll 14.2 +// Project: https://github.com/cferdinandi/smooth-scroll +// Definitions by: Andrei Horodinca +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export as namespace SmoothScroll; + +export = SmoothScroll; + +declare namespace SmoothScroll { + type Easing = + | "Linear" + | "easeInQuad" + | "easeInCubic" + | "easeInQuart" + | "easeInQuint" + | "easeInOutQuad" + | "easeInOutCubic" + | "easeInOutQuart" + | "easeInOutQuint" + | "easeOutQuad" + | "easeOutCubic" + | "easeOutQuart" + | "easeOutQuint"; + + interface Options { + // Selectors + ignore?: string; + header?: string; + topOnEmptyHash?: boolean; + + // Speed & Easing + speed?: number; + clip?: boolean; + offset?: number | ((anchor?: Node | number, toggle?: Node) => number); + easing?: Easing; + customEasing?: (time: number) => number; + + // History + updateURL?: boolean; + popstate?: boolean; + + // Custom Events + emitEvents?: boolean; + } +} + +declare class SmoothScroll { + constructor(selector?: string, options?: SmoothScroll.Options); + + init(options?: SmoothScroll.Options): void; + + destroy(): void; + + animateScroll( + anchor: Node | number, + toggle?: Node, + options?: SmoothScroll.Options + ): void; + + cancelScroll(noEvent?: boolean): void; +} diff --git a/types/smooth-scroll/package.json b/types/smooth-scroll/package.json new file mode 100644 index 0000000000..2e88ca597e --- /dev/null +++ b/types/smooth-scroll/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "smooth-scroll": "^14.2.1" + } +} diff --git a/types/smooth-scroll/test/smooth-scroll-global.test.ts b/types/smooth-scroll/test/smooth-scroll-global.test.ts new file mode 100644 index 0000000000..b34568b993 --- /dev/null +++ b/types/smooth-scroll/test/smooth-scroll-global.test.ts @@ -0,0 +1,34 @@ +// Initialize and destroy SmoothScroll +const example1 = new SmoothScroll('a[href*="#"]', { + ignore: ".ignore", + header: '[data-scroll="header"]', + topOnEmptyHash: false, + speed: 1000, + clip: true, + offset: () => 10, + easing: "easeInCubic", + customEasing: () => 50, + updateURL: false, + popstate: false, + emitEvents: false +}); +example1.destroy(); + +// Scrolling to an anchor +const example2 = () => { + const scroll = new SmoothScroll(); + const anchor: Node = document.querySelector("#bazinga"); + scroll.animateScroll(anchor, null, { speed: 1000 }); +}; + +// Scrolling to a specific Y-position +const example3 = () => { + const scroll = new SmoothScroll('a[href*="#"]'); + scroll.animateScroll(750); +}; + +// Cancel scroll +const example4 = () => { + const scroll = new SmoothScroll(); + scroll.cancelScroll(); +}; diff --git a/types/smooth-scroll/test/smooth-scroll.test.ts b/types/smooth-scroll/test/smooth-scroll.test.ts new file mode 100644 index 0000000000..7db0b4cc2c --- /dev/null +++ b/types/smooth-scroll/test/smooth-scroll.test.ts @@ -0,0 +1,36 @@ +import * as SmoothScroll from "smooth-scroll"; + +// Initialize and destroy SmoothScroll +const example1 = new SmoothScroll('a[href*="#"]', { + ignore: ".ignore", + header: '[data-scroll="header"]', + topOnEmptyHash: false, + speed: 1000, + clip: true, + offset: () => 10, + easing: "easeInCubic", + customEasing: () => 50, + updateURL: false, + popstate: false, + emitEvents: false +}); +example1.destroy(); + +// Scrolling to an anchor +const example2 = () => { + const scroll = new SmoothScroll(); + const anchor: Node = document.querySelector("#bazinga"); + scroll.animateScroll(anchor, null, { speed: 1000 }); +}; + +// Scrolling to a specific Y-position +const example3 = () => { + const scroll = new SmoothScroll('a[href*="#"]'); + scroll.animateScroll(750); +}; + +// Cancel scroll +const example4 = () => { + const scroll = new SmoothScroll(); + scroll.cancelScroll(); +}; diff --git a/types/smooth-scroll/tsconfig.json b/types/smooth-scroll/tsconfig.json new file mode 100644 index 0000000000..563ed576a9 --- /dev/null +++ b/types/smooth-scroll/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "test/smooth-scroll-global.test.ts", + "test/smooth-scroll.test.ts" + ] +} diff --git a/types/smooth-scroll/tslint.json b/types/smooth-scroll/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/smooth-scroll/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 0b67d27091874a2818872ce872be75c9435e161c Mon Sep 17 00:00:00 2001 From: Andrei Horodinca Date: Mon, 5 Nov 2018 15:45:39 +0100 Subject: [PATCH 2/7] Update types/smooth-scroll/tsconfig.json --- types/smooth-scroll/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/types/smooth-scroll/tsconfig.json b/types/smooth-scroll/tsconfig.json index 563ed576a9..7f7cf35c9f 100644 --- a/types/smooth-scroll/tsconfig.json +++ b/types/smooth-scroll/tsconfig.json @@ -5,6 +5,7 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, + "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": ["../"], "types": [], From 514d334a540e4cc9b4ea079943655ac08c08d81f Mon Sep 17 00:00:00 2001 From: Andrei Horodinca Date: Mon, 5 Nov 2018 16:35:09 +0100 Subject: [PATCH 3/7] Remove package.json --- types/smooth-scroll/package.json | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 types/smooth-scroll/package.json diff --git a/types/smooth-scroll/package.json b/types/smooth-scroll/package.json deleted file mode 100644 index 2e88ca597e..0000000000 --- a/types/smooth-scroll/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "private": true, - "dependencies": { - "smooth-scroll": "^14.2.1" - } -} From 7c2ccbf62fbe6c1c94d7947223b2ee6b80d98931 Mon Sep 17 00:00:00 2001 From: Andrei Horodinca Date: Mon, 5 Nov 2018 16:46:21 +0100 Subject: [PATCH 4/7] Add dom lib --- types/smooth-scroll/index.d.ts | 11 ++++++++--- types/smooth-scroll/test/smooth-scroll-global.test.ts | 2 +- types/smooth-scroll/test/smooth-scroll.test.ts | 2 +- types/smooth-scroll/tsconfig.json | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/types/smooth-scroll/index.d.ts b/types/smooth-scroll/index.d.ts index a5aa54fd24..9a0b86696f 100644 --- a/types/smooth-scroll/index.d.ts +++ b/types/smooth-scroll/index.d.ts @@ -32,7 +32,12 @@ declare namespace SmoothScroll { // Speed & Easing speed?: number; clip?: boolean; - offset?: number | ((anchor?: Node | number, toggle?: Node) => number); + offset?: + | number + | (( + anchor?: Element | number | null, + toggle?: Element | null + ) => number); easing?: Easing; customEasing?: (time: number) => number; @@ -53,8 +58,8 @@ declare class SmoothScroll { destroy(): void; animateScroll( - anchor: Node | number, - toggle?: Node, + anchor: Element | number | null, + toggle?: Element | null, options?: SmoothScroll.Options ): void; diff --git a/types/smooth-scroll/test/smooth-scroll-global.test.ts b/types/smooth-scroll/test/smooth-scroll-global.test.ts index b34568b993..e230635f9e 100644 --- a/types/smooth-scroll/test/smooth-scroll-global.test.ts +++ b/types/smooth-scroll/test/smooth-scroll-global.test.ts @@ -17,7 +17,7 @@ example1.destroy(); // Scrolling to an anchor const example2 = () => { const scroll = new SmoothScroll(); - const anchor: Node = document.querySelector("#bazinga"); + const anchor = document.querySelector("#bazinga"); scroll.animateScroll(anchor, null, { speed: 1000 }); }; diff --git a/types/smooth-scroll/test/smooth-scroll.test.ts b/types/smooth-scroll/test/smooth-scroll.test.ts index 7db0b4cc2c..894790f744 100644 --- a/types/smooth-scroll/test/smooth-scroll.test.ts +++ b/types/smooth-scroll/test/smooth-scroll.test.ts @@ -19,7 +19,7 @@ example1.destroy(); // Scrolling to an anchor const example2 = () => { const scroll = new SmoothScroll(); - const anchor: Node = document.querySelector("#bazinga"); + const anchor = document.querySelector("#bazinga"); scroll.animateScroll(anchor, null, { speed: 1000 }); }; diff --git a/types/smooth-scroll/tsconfig.json b/types/smooth-scroll/tsconfig.json index 7f7cf35c9f..8d1fa8372b 100644 --- a/types/smooth-scroll/tsconfig.json +++ b/types/smooth-scroll/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "module": "commonjs", - "lib": ["es6"], + "lib": ["es6", "dom"], "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, From 34ea6caa86b3b2f9be4650997565696dddfd6609 Mon Sep 17 00:00:00 2001 From: Andrei Horodinca Date: Mon, 5 Nov 2018 16:53:13 +0100 Subject: [PATCH 5/7] Add TypeScript version --- types/smooth-scroll/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/smooth-scroll/index.d.ts b/types/smooth-scroll/index.d.ts index 9a0b86696f..87f90cc298 100644 --- a/types/smooth-scroll/index.d.ts +++ b/types/smooth-scroll/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/cferdinandi/smooth-scroll // Definitions by: Andrei Horodinca // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 export as namespace SmoothScroll; From 45869d63aefe8ca99e390e443afb7292f6be5b69 Mon Sep 17 00:00:00 2001 From: Andrei Horodinca Date: Tue, 6 Nov 2018 09:21:55 +0100 Subject: [PATCH 6/7] Update import --- types/smooth-scroll/test/smooth-scroll.test.ts | 2 +- types/smooth-scroll/tsconfig.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/types/smooth-scroll/test/smooth-scroll.test.ts b/types/smooth-scroll/test/smooth-scroll.test.ts index 894790f744..cb29191943 100644 --- a/types/smooth-scroll/test/smooth-scroll.test.ts +++ b/types/smooth-scroll/test/smooth-scroll.test.ts @@ -1,4 +1,4 @@ -import * as SmoothScroll from "smooth-scroll"; +import SmoothScroll from "smooth-scroll"; // Initialize and destroy SmoothScroll const example1 = new SmoothScroll('a[href*="#"]', { diff --git a/types/smooth-scroll/tsconfig.json b/types/smooth-scroll/tsconfig.json index 8d1fa8372b..a6ebdde30b 100644 --- a/types/smooth-scroll/tsconfig.json +++ b/types/smooth-scroll/tsconfig.json @@ -10,7 +10,8 @@ "typeRoots": ["../"], "types": [], "noEmit": true, - "forceConsistentCasingInFileNames": true + "forceConsistentCasingInFileNames": true, + "esModuleInterop": true }, "files": [ "index.d.ts", From e034387d69edb9f20b6413ecd10b5ec214773d0b Mon Sep 17 00:00:00 2001 From: Andrei Horodinca Date: Tue, 6 Nov 2018 09:33:38 +0100 Subject: [PATCH 7/7] Update import --- types/smooth-scroll/test/smooth-scroll.test.ts | 2 +- types/smooth-scroll/tsconfig.json | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/types/smooth-scroll/test/smooth-scroll.test.ts b/types/smooth-scroll/test/smooth-scroll.test.ts index cb29191943..a64b8bd2d0 100644 --- a/types/smooth-scroll/test/smooth-scroll.test.ts +++ b/types/smooth-scroll/test/smooth-scroll.test.ts @@ -1,4 +1,4 @@ -import SmoothScroll from "smooth-scroll"; +import SmoothScroll = require("smooth-scroll"); // Initialize and destroy SmoothScroll const example1 = new SmoothScroll('a[href*="#"]', { diff --git a/types/smooth-scroll/tsconfig.json b/types/smooth-scroll/tsconfig.json index a6ebdde30b..8d1fa8372b 100644 --- a/types/smooth-scroll/tsconfig.json +++ b/types/smooth-scroll/tsconfig.json @@ -10,8 +10,7 @@ "typeRoots": ["../"], "types": [], "noEmit": true, - "forceConsistentCasingInFileNames": true, - "esModuleInterop": true + "forceConsistentCasingInFileNames": true }, "files": [ "index.d.ts",