Skip to content

Commit

Permalink
Added movementX/Y to redispatched event (#9)
Browse files Browse the repository at this point in the history
* Added movementX/Y to redispatched event

* 0.4.1

* Updated build and docs
  • Loading branch information
ydaniv authored Jan 13, 2025
1 parent da566fe commit cd6a238
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
27 changes: 26 additions & 1 deletion dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ class Pointer {
this.previousProgress = { ...this.progress };
this.currentProgress = null;

this._measure = (event) => {
const _measure = (event) => {
Object.assign(this.previousProgress, this.currentProgress || this.progress);

this.progress.x = this.config.root ? event.offsetX : event.x;
Expand All @@ -382,6 +382,31 @@ class Pointer {
this.progress.vy = event.movementY;
this._nextTick = trigger();
};

const dpr = window.devicePixelRatio;

if (this.config.root) {
this._measure = (e) => {
if (e.target !== this.config.root) {
const event = new PointerEvent('pointermove', {
bubbles: true,
cancelable: true,
clientX: e.x * dpr,
clientY: e.y * dpr,
movementX: e.movementX,
movementY: e.movementY,
});

e.stopPropagation();

this.config.root.dispatchEvent(event);
} else {
_measure(e);
}
};
} else {
this._measure = _measure;
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset='utf-8'>
<title>kuliso 0.3.0 | Documentation</title>
<title>kuliso 0.4.1 | Documentation</title>
<meta name='description' content='Tiny library for performant pointer-driven or gyroscope-driven effects'>
<meta name='viewport' content='width=device-width,initial-scale=1'>
<link href='assets/bass.css' rel='stylesheet'>
Expand All @@ -15,7 +15,7 @@
<div id='split-left' class='overflow-auto fs0 height-viewport-100'>
<div class='py1 px2'>
<h3 class='mb0 no-anchor'>kuliso</h3>
<div class='mb1'><code>0.3.0</code></div>
<div class='mb1'><code>0.4.1</code></div>
<input
placeholder='Filter'
id='filter-input'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kuliso",
"version": "0.4.0",
"version": "0.4.1",
"sideeffects": true,
"description": "Tiny library for performant pointer-driven or gyroscope-driven effects",
"main": "dist/index.cjs",
Expand Down
4 changes: 3 additions & 1 deletion src/Pointer.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ export class Pointer {
bubbles: true,
cancelable: true,
clientX: e.x * dpr,
clientY: e.y * dpr
clientY: e.y * dpr,
movementX: e.movementX,
movementY: e.movementY,
});

e.stopPropagation();
Expand Down

0 comments on commit cd6a238

Please sign in to comment.