Skip to content

Commit

Permalink
style: prettier formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Wurielle authored and actions-user committed Oct 12, 2024
1 parent 3ed5f60 commit f1b0ba2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 48 deletions.
24 changes: 12 additions & 12 deletions apps/app/src/modules/vue-hitboxes/NvHitbox.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div ref="componentRef" :data-hitbox-id="id">
<slot/>
<slot />
</div>
</template>
<script lang="ts" setup>
Expand Down Expand Up @@ -37,17 +37,17 @@ const onHitboxUpdate = () => {
}
}
const updateHitbox = throttle(
() => {
if (componentRef.value) {
const bounds = componentRef.value.getBoundingClientRect()
hitboxes.value.x = bounds.x * pixelRatio.value
hitboxes.value.y = bounds.y * pixelRatio.value
hitboxes.value.w = bounds.width * pixelRatio.value
hitboxes.value.h = bounds.height * pixelRatio.value
}
},
250,
{ leading: true, trailing: true },
() => {
if (componentRef.value) {
const bounds = componentRef.value.getBoundingClientRect()
hitboxes.value.x = bounds.x * pixelRatio.value
hitboxes.value.y = bounds.y * pixelRatio.value
hitboxes.value.w = bounds.width * pixelRatio.value
hitboxes.value.h = bounds.height * pixelRatio.value
}
},
250,
{ leading: true, trailing: true },
)
useIntersectionObserver(componentRef, updateHitbox)
Expand Down
72 changes: 36 additions & 36 deletions apps/app/src/modules/vue-hitboxes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,43 @@ import { useDevicePixelRatio } from '@vueuse/core'
export const hitboxClass = 'hitbox'

const onElementChange = (element: Element, callback: () => any) => {
const resizeObserver = new ResizeObserver(callback)
const intersectionObserver = new IntersectionObserver(callback)
const mutationObserver = new MutationObserver(callback)
resizeObserver.observe(element)
intersectionObserver.observe(element)
mutationObserver.observe(element, { attributes: true })
window.addEventListener('resize', callback)
window.addEventListener('focus', callback)
return () => {
resizeObserver.unobserve(element)
intersectionObserver.unobserve(element)
mutationObserver.disconnect()
window.removeEventListener('resize', callback)
window.removeEventListener('focus', callback)
}
const resizeObserver = new ResizeObserver(callback)
const intersectionObserver = new IntersectionObserver(callback)
const mutationObserver = new MutationObserver(callback)
resizeObserver.observe(element)
intersectionObserver.observe(element)
mutationObserver.observe(element, { attributes: true })
window.addEventListener('resize', callback)
window.addEventListener('focus', callback)
return () => {
resizeObserver.unobserve(element)
intersectionObserver.unobserve(element)
mutationObserver.disconnect()
window.removeEventListener('resize', callback)
window.removeEventListener('focus', callback)
}
}
export const watchHitbox = (selector: string) => {
ready(selector, (element: Element) => {
const id = uuid()
const hitboxesStore = useHitboxesStore()
const { pixelRatio } = useDevicePixelRatio()
const updateHitboxes = throttle(() => {
if (element) {
const { x, y, width: w, height: h } = element.getBoundingClientRect()
hitboxesStore.addHitbox({
id,
x: x * pixelRatio.value,
y: y * pixelRatio.value,
w: w * pixelRatio.value,
h: h * pixelRatio.value,
})
} else {
hitboxesStore.removeHitbox(id)
}
}, 250)
onElementChange(element, updateHitboxes)
})
ready(selector, (element: Element) => {
const id = uuid()
const hitboxesStore = useHitboxesStore()
const { pixelRatio } = useDevicePixelRatio()
const updateHitboxes = throttle(() => {
if (element) {
const { x, y, width: w, height: h } = element.getBoundingClientRect()
hitboxesStore.addHitbox({
id,
x: x * pixelRatio.value,
y: y * pixelRatio.value,
w: w * pixelRatio.value,
h: h * pixelRatio.value,
})
} else {
hitboxesStore.removeHitbox(id)
}
}, 250)
onElementChange(element, updateHitboxes)
})
}

watchHitbox(`.${ hitboxClass }`)
watchHitbox(`.${hitboxClass}`)

0 comments on commit f1b0ba2

Please sign in to comment.