Skip to content

Commit

Permalink
fix: Safari hates TouchEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
akdasa committed Mar 18, 2023
1 parent 029b25f commit 17782a0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@akdasa-studios/shlokas-uikit",
"version": "0.0.17",
"version": "0.0.18",
"files": [
"dist"
],
Expand Down
27 changes: 14 additions & 13 deletions src/CardsDeck.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
:key="item.id"
:class="cardClass"
:style="props.computeStyle(item)"
@touchstart="$event => onEvent($event, 'start', item)"
@touchmove="$event => onEvent($event, 'moving', item)"
@touchend="$event => onEvent($event, 'moved', item)"
@mousedown="$event => onEvent($event, 'start', item)"
@mousemove="$event => onEvent($event, 'moving', item)"
@mouseup="$event => onEvent($event, 'moved', item)"
@touchstart="$event => onEvent($event, 'touch', 'start', item)"
@touchmove="$event => onEvent($event, 'touch', 'moving', item)"
@touchend="$event => onEvent($event, 'touch', 'moved', item)"
@mousedown="$event => onEvent($event, 'mouse', 'start', item)"
@mousemove="$event => onEvent($event, 'mouse', 'moving', item)"
@mouseup="$event => onEvent($event, 'mouse', 'moved', item)"
>
<slot :card="item" />
</div>
Expand Down Expand Up @@ -77,31 +77,32 @@
/* Handlers */
/* -------------------------------------------------------------------------- */
type InteractionEvent = TouchEvent | MouseEvent
type InteractionEventType = 'mouse' | 'touch' // fuck you Safari
type ActionType = 'start' | 'moving' | 'moved'
type Position = [number, number]
function getPosition(event: InteractionEvent): Position {
if (event instanceof TouchEvent) {
function getPosition(event: any, type: InteractionEventType): Position {
if (type === 'touch') {
const touch = event.touches[0] || event.changedTouches[0]
return [touch.pageX, touch.pageY]
} else if (event instanceof MouseEvent) {
} else if (type === 'mouse') {
return [event.clientX, event.clientY]
}
return [0, 0]
}
function onEvent(
event: InteractionEvent,
event: any,
eventType: InteractionEventType,
type: ActionType,
card: Card,
) {
const currentPosition = getPosition(event)
const currentPosition = getPosition(event, eventType)
if (type === 'start') {
startPosition = getPosition(event)
startPosition = getPosition(event, eventType)
} else if (startPosition) {
emit(type as any, card, startPosition, currentPosition)
if (type === 'moved') { startPosition = undefined }
Expand Down

0 comments on commit 17782a0

Please sign in to comment.