From c7d43395d9b3842b8265d7bd36d1a3267f637981 Mon Sep 17 00:00:00 2001 From: Yehonatan Daniv Date: Thu, 28 Nov 2024 10:49:03 +0200 Subject: [PATCH] Pointer add config.noThrottle (#4) * Added config.noThrottle * 0.2.1 --- dist/index.cjs | 10 ++++++---- docs/reference/index.html | 7 +++++++ package.json | 12 ++++++------ src/Pointer.js | 10 ++++++---- types.d.ts | 1 + 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/dist/index.cjs b/dist/index.cjs index a2b1fde..ea63a89 100644 --- a/dist/index.cjs +++ b/dist/index.cjs @@ -332,9 +332,11 @@ class Pointer { this.effect = null; this._nextTick = null; - const trigger = frameThrottle(() => { - this.tick(); - }); + const trigger = this.config.noThrottle + ? () => { this.tick(); } + : frameThrottle(() => { + this.tick(); + }); // in no root then use the viewport's size this.config.rect = this.config.root @@ -383,7 +385,6 @@ class Pointer { * Handle animation frame work. */ tick () { - // update effect this.effect.tick(this.progress); } @@ -435,6 +436,7 @@ class Pointer { * @property {PointerScene[]} scenes list of effect scenes to perform during pointermove. * @property {HTMLElement} [root] element to use as hit area for pointermove events. Defaults to entire viewport. * @property {{width: number, height: number}} [rect] created automatically on Pointer construction. + * @property {boolean} [noThrottle] whether to disable throttling the effect by framerate. */ /** diff --git a/docs/reference/index.html b/docs/reference/index.html index 1252a6b..4b45d54 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -846,6 +846,13 @@

+
+ noThrottle (boolean?) + : whether to disable throttling the effect by framerate. + + +
+ diff --git a/package.json b/package.json index 0a84c3d..aab4ab8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kuliso", - "version": "0.2.0", + "version": "0.2.1", "sideeffects": true, "description": "Tiny library for performant pointer-driven or gyroscope-driven effects", "main": "dist/index.cjs", @@ -31,12 +31,12 @@ }, "homepage": "https://github.com/wix-incubator/kuliso#readme", "devDependencies": { - "@rollup/plugin-node-resolve": "^15.2.3", - "ava": "^5.3.1", - "c8": "^8.0.1", - "documentation": "^14.0.2", + "@rollup/plugin-node-resolve": "^15.3.0", + "ava": "^6.2.0", + "c8": "^10.1.2", + "documentation": "^14.0.3", "http-server": "^14.1.1", - "rollup": "^4.6.0", + "rollup": "^4.27.4", "rollup-plugin-filesize": "^10.0.0", "rollup-plugin-progress": "^1.1.2" } diff --git a/src/Pointer.js b/src/Pointer.js index bc935bd..1896ace 100644 --- a/src/Pointer.js +++ b/src/Pointer.js @@ -21,9 +21,11 @@ export class Pointer { this.effect = null; this._nextTick = null; - const trigger = frameThrottle(() => { - this.tick(); - }); + const trigger = this.config.noThrottle + ? () => { this.tick(); } + : frameThrottle(() => { + this.tick(); + }); // in no root then use the viewport's size this.config.rect = this.config.root @@ -72,7 +74,6 @@ export class Pointer { * Handle animation frame work. */ tick () { - // update effect this.effect.tick(this.progress); } @@ -124,6 +125,7 @@ export class Pointer { * @property {PointerScene[]} scenes list of effect scenes to perform during pointermove. * @property {HTMLElement} [root] element to use as hit area for pointermove events. Defaults to entire viewport. * @property {{width: number, height: number}} [rect] created automatically on Pointer construction. + * @property {boolean} [noThrottle] whether to disable throttling the effect by framerate. */ /** diff --git a/types.d.ts b/types.d.ts index f180019..e1bcd0e 100644 --- a/types.d.ts +++ b/types.d.ts @@ -1,6 +1,7 @@ declare type PointerConfig = { scenes: PointerScene; root?: HTMLElement; + noThrottle?: boolean; } declare type PointerScene = {