Prettified all files.

This commit is contained in:
2019-07-18 12:26:39 +02:00
parent 7744b92771
commit 2d400a18ec
125 changed files with 11184 additions and 8154 deletions
+59 -41
View File
@@ -1,12 +1,12 @@
import {Points} from './utils.js'
import {Capabilities} from './capabilities.js'
import { Points } from './utils.js'
import { Capabilities } from './capabilities.js'
export class FrameContainer {
constructor(element) {
this.element = element
this.delegate = new InteractionMapper(element, this,
{ mouseWheelElement: window})
this.delegate = new InteractionMapper(element, this, {
mouseWheelElement: window
})
}
capture(event) {
@@ -30,8 +30,7 @@ export class FrameContainer {
}
export class FrameTarget {
constructor(frame, target, debug=false) {
constructor(frame, target, debug = false) {
this.frame = frame
this.target = target
this.debug = debug
@@ -48,22 +47,30 @@ export class FrameTarget {
bubbles: true,
cancelable: true,
clientX: p.x,
clientY: p.y})
clientY: p.y
})
this.target.dispatchEvent(event)
}
createTouchList(pointMap) {
let touches = []
let doc = this.frame.contentWindow.document
for(let key of pointMap.keys()) {
for (let key of pointMap.keys()) {
let point = pointMap.get(key)
let p = Points.fromPageToNode(this.frame, point)
let touchTarget = doc.elementFromPoint(p.x, p.y)
let touch = new Touch(undefined, touchTarget, key,
p.x, p.y, p.x, p.y)
let touch = new Touch(
undefined,
touchTarget,
key,
p.x,
p.y,
p.x,
p.y
)
touches.push(touch)
}
return new TouchList(...touches)
return new TouchList(...touches)
}
simulateTouchEventChrome(type, point, pointMap) {
@@ -80,8 +87,8 @@ export class FrameTarget {
radiusX: 2.5,
radiusY: 2.5,
rotationAngle: 10,
force: 0.5,
});
force: 0.5
})
const touchEvent = new TouchEvent(type, {
cancelable: true,
@@ -89,47 +96,57 @@ export class FrameTarget {
touches: [touchObj],
targetTouches: [touchObj],
changedTouches: [touchObj],
shiftKey: false,
});
if (this.debug) console.log("simulateTouchEventChrome", touchEvent)
this.target.dispatchEvent(touchEvent);
shiftKey: false
})
if (this.debug) console.log('simulateTouchEventChrome', touchEvent)
this.target.dispatchEvent(touchEvent)
}
simulateTouchEventSafari(type, point, pointMap, touchEventKey='targetTouches') {
simulateTouchEventSafari(
type,
point,
pointMap,
touchEventKey = 'targetTouches'
) {
let p = Points.fromPageToNode(this.frame, point)
let data = { view: this.frame.contentWindow,
let data = {
view: this.frame.contentWindow,
bubbles: true,
cancelable: true,
clientX: p.x,
clientY: p.y}
clientY: p.y
}
data[touchEventKey] = this.createTouchList(pointMap)
let event = new TouchEvent(type, data)
if (this.debug) console.log("simulateTouchEventChrome", touchEvent)
if (this.debug) console.log('simulateTouchEventChrome', touchEvent)
this.target.dispatchEvent(event)
}
simulateTouchEvent(type, point, pointMap, touchEventKey='targetTouches') {
simulateTouchEvent(type, point, pointMap, touchEventKey = 'targetTouches') {
if (Capabilities.isSafari) {
this.simulateTouchEventSafari(type, point, pointMap, touchEventKey)
}
else {
} else {
this.simulateTouchEventChrome(type, point, pointMap)
}
}
isMouseLikeEvent(event) {
return event.type.startsWith('mouse') || event.type.startsWith('pointer')
return (
event.type.startsWith('mouse') || event.type.startsWith('pointer')
)
}
onStart(event, interaction) {
if (this.debug) console.log('onStart', this.frame.parentNode)
for(let [key, point] of interaction.current.entries()) {
for (let [key, point] of interaction.current.entries()) {
if (this.isMouseLikeEvent(event)) {
this.simulateMouseEvent('mousedown', point)
}
else {
this.simulateTouchEvent('touchstart', point,
interaction.current)
} else {
this.simulateTouchEvent(
'touchstart',
point,
interaction.current
)
return
}
}
@@ -137,13 +154,11 @@ export class FrameTarget {
onMove(event, interaction) {
if (this.debug) console.log('onMove')
for(let [key, point] of interaction.current.entries()) {
for (let [key, point] of interaction.current.entries()) {
if (this.isMouseLikeEvent(event)) {
this.simulateMouseEvent('mousemove', point)
}
else {
this.simulateTouchEvent('touchmove', point,
interaction.current)
} else {
this.simulateTouchEvent('touchmove', point, interaction.current)
return
}
}
@@ -151,13 +166,16 @@ export class FrameTarget {
onEnd(event, interaction) {
if (this.debug) console.log('onEnd')
for(let [key, point] of interaction.current.entries()) {
for (let [key, point] of interaction.current.entries()) {
if (this.isMouseLikeEvent(event)) {
this.simulateMouseEvent('mouseend', point)
}
else {
this.simulateTouchEvent('touchend', point,
interaction.ended, 'changedTouches')
} else {
this.simulateTouchEvent(
'touchend',
point,
interaction.ended,
'changedTouches'
)
return
}
}