mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-15 09:04:04 +02:00
18 lines
502 B
TypeScript
18 lines
502 B
TypeScript
|
// Converts world coordinate to screen coordinates by applying the current
|
||
|
// zoom.
|
||
|
export default function convertToScreenCoordinates(o: any): any {
|
||
|
const pixelRatio = window.devicePixelRatio;
|
||
|
|
||
|
if (typeof o === 'number') return o * pixelRatio;
|
||
|
|
||
|
if (typeof o === 'object' && o !== null) {
|
||
|
o = JSON.parse(JSON.stringify(o));
|
||
|
for (const k of Object.keys(o)) {
|
||
|
o[k] = convertToScreenCoordinates(o[k]);
|
||
|
}
|
||
|
return o;
|
||
|
}
|
||
|
|
||
|
throw new Error(`Cannot convert to screen coordinates: ${typeof o}`);
|
||
|
}
|