Skip to content

Commit

Permalink
ref: remove comments
Browse files Browse the repository at this point in the history
  • Loading branch information
luisorbaiceta committed Jul 12, 2022
1 parent 6f9b2f9 commit c0bb6fe
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
- uses: actions/checkout@v2
- name: 'Install Node'
uses: actions/setup-node@v2
- name: Install dependencies
run: npm install
- name: "Pack files"
run: npm run prepublish
- uses: mikeal/merge-release@master
Expand Down
9 changes: 6 additions & 3 deletions src/computations.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import type { Reference, PositionVector } from './index'

// return current mouse position relative to reference element in listener
function getMouseOverVector (event: MouseEvent): PositionVector {
const position = getCursorPosition(event, event.currentTarget as HTMLElement)
const dimension = getRefSize(event.currentTarget as HTMLElement)

return {
x: (Math.round((position.x / dimension.x) * 100) / 100),
y: (Math.round((position.y / dimension.y) * 100) / 100),
gx: event.clientX, // global x position
gy: event.clientY // global y position
gx: event.clientX,
gy: event.clientY
}
}

Expand All @@ -20,17 +19,20 @@ function getRefSize (el: Reference) {
y: el.innerHeight
}
}

if (el instanceof Document) {
return {
x: el.body.clientWidth,
y: el.body.clientHeight
}
}

return {
x: el.offsetWidth,
y: el.offsetHeight
}
}

function getCursorPosition (ev: MouseEvent, el: Reference) {
if (el instanceof Window || el instanceof Document) {
return {
Expand All @@ -39,6 +41,7 @@ function getCursorPosition (ev: MouseEvent, el: Reference) {
}
}
const rect = el.getBoundingClientRect()

return {
x: ((ev.clientX - rect.left)),
y: ((ev.clientY - rect.top))
Expand Down
3 changes: 0 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ class Mouser {
}
]

// handle mouse leave for window
if (this.reference instanceof Window) {
this.eventListeners.push({
element: document,
Expand Down Expand Up @@ -124,7 +123,6 @@ class Mouser {
}

private setRestState () {
// memo last global recorded value
this.vector = { ...this.vector, ...this.restState }
this.dispatchEvents(this.vector)
}
Expand All @@ -135,7 +133,6 @@ class Mouser {
})
}

// determine element update based on given rate
private shouldUpdate (): boolean {
let counter = 0
if (this.refreshRate === 0) return true
Expand Down

0 comments on commit c0bb6fe

Please sign in to comment.