Skip to content

Commit

Permalink
fix(touch-emulator): rename file
Browse files Browse the repository at this point in the history
  • Loading branch information
haoziqaq committed Jan 9, 2022
1 parent 210748f commit 3a4cbd5
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 136 deletions.
136 changes: 68 additions & 68 deletions packages/varlet-touch-emulator/iife.js
Original file line number Diff line number Diff line change
@@ -1,92 +1,92 @@
const inBrowser = typeof window !== 'undefined'
const supportTouch = inBrowser && 'ontouchstart' in window
let initiated = false
let eventTarget
;(() => {
const inBrowser = typeof window !== 'undefined'
const supportTouch = inBrowser && 'ontouchstart' in window
let initiated = false
let eventTarget

const isMousedown = (eventType) => eventType === 'mousedown'
const isMousedown = (eventType) => eventType === 'mousedown'

const isMousemove = (eventType) => eventType === 'mousemove'
const isMousemove = (eventType) => eventType === 'mousemove'

const isMouseup = (eventType) => eventType === 'mouseup'
const isMouseup = (eventType) => eventType === 'mouseup'

const isUpdateTarget = (eventType) =>
isMousedown(eventType) || !eventTarget || (eventTarget && !eventTarget.dispatchEvent)
const isUpdateTarget = (eventType) =>
isMousedown(eventType) || !eventTarget || (eventTarget && !eventTarget.dispatchEvent)

function Touch(target, identifier, mouseEvent) {
const { clientX, clientY, screenX, screenY, pageX, pageY } = mouseEvent
function Touch(target, identifier, mouseEvent) {
const { clientX, clientY, screenX, screenY, pageX, pageY } = mouseEvent

this.identifier = identifier
this.target = target
this.clientX = clientX
this.clientY = clientY
this.screenX = screenX
this.screenY = screenY
this.pageX = pageX
this.pageY = pageY
}

function updateTouchList(mouseEvent) {
const touchList = createTouchList()

touchList.push(new Touch(eventTarget, 1, mouseEvent))
return touchList
}
this.identifier = identifier
this.target = target
this.clientX = clientX
this.clientY = clientY
this.screenX = screenX
this.screenY = screenY
this.pageX = pageX
this.pageY = pageY
}

function createTouchList() {
const touchList = []
function updateTouchList(mouseEvent) {
const touchList = createTouchList()

touchList.item = function (index) {
return this[index] || null
touchList.push(new Touch(eventTarget, 1, mouseEvent))
return touchList
}

return touchList
}
function createTouchList() {
const touchList = []

function getActiveTouches(mouseEvent) {
const { type } = mouseEvent
if (isMouseup(type)) return createTouchList()
return updateTouchList(mouseEvent)
}
touchList.item = function (index) {
return this[index] || null
}

return touchList
}

function triggerTouch(touchType, mouseEvent) {
const { altKey, ctrlKey, metaKey, shiftKey } = mouseEvent
const touchEvent = document.createEvent('Event')
touchEvent.initEvent(touchType, true, true)
function getActiveTouches(mouseEvent) {
const { type } = mouseEvent
if (isMouseup(type)) return createTouchList()
return updateTouchList(mouseEvent)
}

touchEvent.altKey = altKey
touchEvent.ctrlKey = ctrlKey
touchEvent.metaKey = metaKey
touchEvent.shiftKey = shiftKey
function triggerTouch(touchType, mouseEvent) {
const { altKey, ctrlKey, metaKey, shiftKey } = mouseEvent
const touchEvent = document.createEvent('Event')
touchEvent.initEvent(touchType, true, true)

touchEvent.touches = getActiveTouches(mouseEvent)
touchEvent.targetTouches = getActiveTouches(mouseEvent)
touchEvent.changedTouches = createTouchList(mouseEvent)
touchEvent.altKey = altKey
touchEvent.ctrlKey = ctrlKey
touchEvent.metaKey = metaKey
touchEvent.shiftKey = shiftKey

eventTarget.dispatchEvent(touchEvent)
}
touchEvent.touches = getActiveTouches(mouseEvent)
touchEvent.targetTouches = getActiveTouches(mouseEvent)
touchEvent.changedTouches = createTouchList(mouseEvent)

function onMouse(mouseEvent, touchType) {
const { type, target } = mouseEvent
eventTarget.dispatchEvent(touchEvent)
}

initiated = isMousedown(type) ? true : isMouseup(type) ? false : initiated
function onMouse(mouseEvent, touchType) {
const { type, target } = mouseEvent

if (isMousemove(type) && !initiated) return
initiated = isMousedown(type) ? true : isMouseup(type) ? false : initiated

if (isUpdateTarget(type)) eventTarget = target
if (isMousemove(type) && !initiated) return

triggerTouch(touchType, mouseEvent)
if (isUpdateTarget(type)) eventTarget = target

if (isMouseup(type)) eventTarget = null
}
triggerTouch(touchType, mouseEvent)

function createTouchEmulator() {
window.addEventListener('mousedown', (event) => onMouse(event, 'touchstart'), true)
window.addEventListener('mousemove', (event) => onMouse(event, 'touchmove'), true)
window.addEventListener('mouseup', (event) => onMouse(event, 'touchend'), true)
}
if (isMouseup(type)) eventTarget = null
}

if (inBrowser && !supportTouch) {
createTouchEmulator()
}
function createTouchEmulator() {
window.addEventListener('mousedown', (event) => onMouse(event, 'touchstart'), true)
window.addEventListener('mousemove', (event) => onMouse(event, 'touchmove'), true)
window.addEventListener('mouseup', (event) => onMouse(event, 'touchend'), true)
}

module.exports = {}
if (inBrowser && !supportTouch) {
createTouchEmulator()
}
})()
136 changes: 68 additions & 68 deletions packages/varlet-touch-emulator/index.js
Original file line number Diff line number Diff line change
@@ -1,92 +1,92 @@
;(() => {
const inBrowser = typeof window !== 'undefined'
const supportTouch = inBrowser && 'ontouchstart' in window
let initiated = false
let eventTarget
const inBrowser = typeof window !== 'undefined'
const supportTouch = inBrowser && 'ontouchstart' in window
let initiated = false
let eventTarget

const isMousedown = (eventType) => eventType === 'mousedown'
const isMousedown = (eventType) => eventType === 'mousedown'

const isMousemove = (eventType) => eventType === 'mousemove'
const isMousemove = (eventType) => eventType === 'mousemove'

const isMouseup = (eventType) => eventType === 'mouseup'
const isMouseup = (eventType) => eventType === 'mouseup'

const isUpdateTarget = (eventType) =>
isMousedown(eventType) || !eventTarget || (eventTarget && !eventTarget.dispatchEvent)
const isUpdateTarget = (eventType) =>
isMousedown(eventType) || !eventTarget || (eventTarget && !eventTarget.dispatchEvent)

function Touch(target, identifier, mouseEvent) {
const { clientX, clientY, screenX, screenY, pageX, pageY } = mouseEvent
function Touch(target, identifier, mouseEvent) {
const { clientX, clientY, screenX, screenY, pageX, pageY } = mouseEvent

this.identifier = identifier
this.target = target
this.clientX = clientX
this.clientY = clientY
this.screenX = screenX
this.screenY = screenY
this.pageX = pageX
this.pageY = pageY
}

function updateTouchList(mouseEvent) {
const touchList = createTouchList()
this.identifier = identifier
this.target = target
this.clientX = clientX
this.clientY = clientY
this.screenX = screenX
this.screenY = screenY
this.pageX = pageX
this.pageY = pageY
}

touchList.push(new Touch(eventTarget, 1, mouseEvent))
return touchList
}
function updateTouchList(mouseEvent) {
const touchList = createTouchList()

function createTouchList() {
const touchList = []
touchList.push(new Touch(eventTarget, 1, mouseEvent))
return touchList
}

touchList.item = function (index) {
return this[index] || null
}
function createTouchList() {
const touchList = []

return touchList
touchList.item = function (index) {
return this[index] || null
}

function getActiveTouches(mouseEvent) {
const { type } = mouseEvent
if (isMouseup(type)) return createTouchList()
return updateTouchList(mouseEvent)
}
return touchList
}

function triggerTouch(touchType, mouseEvent) {
const { altKey, ctrlKey, metaKey, shiftKey } = mouseEvent
const touchEvent = document.createEvent('Event')
touchEvent.initEvent(touchType, true, true)
function getActiveTouches(mouseEvent) {
const { type } = mouseEvent
if (isMouseup(type)) return createTouchList()
return updateTouchList(mouseEvent)
}

touchEvent.altKey = altKey
touchEvent.ctrlKey = ctrlKey
touchEvent.metaKey = metaKey
touchEvent.shiftKey = shiftKey
function triggerTouch(touchType, mouseEvent) {
const { altKey, ctrlKey, metaKey, shiftKey } = mouseEvent
const touchEvent = document.createEvent('Event')
touchEvent.initEvent(touchType, true, true)

touchEvent.touches = getActiveTouches(mouseEvent)
touchEvent.targetTouches = getActiveTouches(mouseEvent)
touchEvent.changedTouches = createTouchList(mouseEvent)
touchEvent.altKey = altKey
touchEvent.ctrlKey = ctrlKey
touchEvent.metaKey = metaKey
touchEvent.shiftKey = shiftKey

eventTarget.dispatchEvent(touchEvent)
}
touchEvent.touches = getActiveTouches(mouseEvent)
touchEvent.targetTouches = getActiveTouches(mouseEvent)
touchEvent.changedTouches = createTouchList(mouseEvent)

function onMouse(mouseEvent, touchType) {
const { type, target } = mouseEvent
eventTarget.dispatchEvent(touchEvent)
}

initiated = isMousedown(type) ? true : isMouseup(type) ? false : initiated
function onMouse(mouseEvent, touchType) {
const { type, target } = mouseEvent

if (isMousemove(type) && !initiated) return
initiated = isMousedown(type) ? true : isMouseup(type) ? false : initiated

if (isUpdateTarget(type)) eventTarget = target
if (isMousemove(type) && !initiated) return

triggerTouch(touchType, mouseEvent)
if (isUpdateTarget(type)) eventTarget = target

if (isMouseup(type)) eventTarget = null
}
triggerTouch(touchType, mouseEvent)

function createTouchEmulator() {
window.addEventListener('mousedown', (event) => onMouse(event, 'touchstart'), true)
window.addEventListener('mousemove', (event) => onMouse(event, 'touchmove'), true)
window.addEventListener('mouseup', (event) => onMouse(event, 'touchend'), true)
}
if (isMouseup(type)) eventTarget = null
}

if (inBrowser && !supportTouch) {
createTouchEmulator()
}
})()
function createTouchEmulator() {
window.addEventListener('mousedown', (event) => onMouse(event, 'touchstart'), true)
window.addEventListener('mousemove', (event) => onMouse(event, 'touchmove'), true)
window.addEventListener('mouseup', (event) => onMouse(event, 'touchend'), true)
}

if (inBrowser && !supportTouch) {
createTouchEmulator()
}

module.exports = {}

0 comments on commit 3a4cbd5

Please sign in to comment.