mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-20 12:38:50 +00:00
Try karmatic! +test reorg
This commit is contained in:
61
test/lib/finger.js
Normal file
61
test/lib/finger.js
Normal file
@@ -0,0 +1,61 @@
|
||||
let touchPoints = [];
|
||||
let idCnt = 0;
|
||||
|
||||
class Finger {
|
||||
constructor (point, page) {
|
||||
this._point = point;
|
||||
this._page = page;
|
||||
}
|
||||
|
||||
move (x, y) {
|
||||
if (!this._point) return;
|
||||
Object.assign(this._point, {
|
||||
x: Math.floor(x),
|
||||
y: Math.floor(y)
|
||||
});
|
||||
this._page.touchscreen._client.send('Input.dispatchTouchEvent', {
|
||||
type: 'touchMove',
|
||||
touchPoints,
|
||||
modifiers: this._page._keyboard._modifiers
|
||||
});
|
||||
}
|
||||
|
||||
up () {
|
||||
if (!this._point) return;
|
||||
const idx = touchPoints.indexOf(this._point);
|
||||
touchPoints = touchPoints.splice(idx, 1);
|
||||
this._point = null;
|
||||
if (touchPoints.length === 0) {
|
||||
this._page.touchscreen._client.send('Input.dispatchTouchEvent', {
|
||||
type: 'touchEnd',
|
||||
modifiers: this._page._keyboard._modifiers
|
||||
});
|
||||
} else {
|
||||
this._page.touchscreen._client.send('Input.dispatchTouchEvent', {
|
||||
type: 'touchMove',
|
||||
touchPoints,
|
||||
modifiers: this._page._keyboard._modifiers
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function fingerDown (page, x, y) {
|
||||
const id = idCnt++;
|
||||
const point = {
|
||||
x: Math.round(x),
|
||||
y: Math.round(y),
|
||||
id
|
||||
};
|
||||
touchPoints.push(point);
|
||||
page.touchscreen._client.send('Input.dispatchTouchEvent', {
|
||||
type: 'touchStart',
|
||||
touchPoints,
|
||||
modifiers: page._keyboard._modifiers
|
||||
});
|
||||
return new Finger(point, page);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
fingerDown
|
||||
};
|
||||
Reference in New Issue
Block a user