-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscreen-to-client-page.ts
46 lines (38 loc) · 1.12 KB
/
screen-to-client-page.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// see https://lists.w3.org/Archives/Public/www-style/2016Dec/0052.html
// see https://github.com/w3c/csswg-drafts/issues/809
import _ from 'lodash-firecloud';
import clientCoords from './client';
import pageCoords from './page';
import screenCoords from './screen';
import windowCoords from './window';
type ScreenXY = {
screenX: number;
screenY: number;
};
type ClientPageXY = {
clientX: number;
clientY: number;
pageX: number;
pageY: number;
};
// current screen, not virtual screen
export let screenToClientPage = function({screenX, screenY}: ScreenXY): ClientPageXY {
let pageZoomFactor = pageCoords.zoomFactor();
let screenOsZoomFactor = screenCoords.osZoomFactor();
let absoluteZoomFactor = pageZoomFactor * screenOsZoomFactor;
let clientX = _.round((
screenX -
windowCoords.x() -
clientCoords.x()) / absoluteZoomFactor);
let clientY = _.round((
screenY -
windowCoords.y() -
clientCoords.y()) / absoluteZoomFactor);
return {
clientX,
clientY,
pageX: clientX + clientCoords.scroll.x(),
pageY: clientY + clientCoords.scroll.y()
};
};
export default screenToClientPage;