2022-10-10 20:41:25 +01:00
|
|
|
// @ts-check
|
|
|
|
|
2020-11-04 17:21:05 +00:00
|
|
|
import { supportsPassiveEvents } from 'detect-passive-events';
|
2023-04-03 02:31:39 +01:00
|
|
|
// @ts-expect-error
|
2020-11-16 04:16:39 +00:00
|
|
|
import { forceSingleColumn } from 'mastodon/initial_state';
|
2017-09-19 16:00:29 +01:00
|
|
|
|
2017-09-24 00:25:07 +01:00
|
|
|
const LAYOUT_BREAKPOINT = 630;
|
2017-01-08 10:04:01 +00:00
|
|
|
|
2022-10-10 20:41:25 +01:00
|
|
|
/**
|
|
|
|
* @param {number} width
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2020-11-16 04:16:39 +00:00
|
|
|
export const isMobile = width => width <= LAYOUT_BREAKPOINT;
|
|
|
|
|
2022-10-10 20:41:25 +01:00
|
|
|
/**
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2020-11-16 04:16:39 +00:00
|
|
|
export const layoutFromWindow = () => {
|
|
|
|
if (isMobile(window.innerWidth)) {
|
|
|
|
return 'mobile';
|
|
|
|
} else if (forceSingleColumn) {
|
|
|
|
return 'single-column';
|
|
|
|
} else {
|
|
|
|
return 'multi-column';
|
|
|
|
}
|
2017-01-08 10:04:01 +00:00
|
|
|
};
|
2017-03-07 08:54:57 +00:00
|
|
|
|
2023-04-03 02:31:39 +01:00
|
|
|
// @ts-expect-error
|
2017-03-07 08:54:57 +00:00
|
|
|
const iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
2017-09-19 16:00:29 +01:00
|
|
|
|
2022-10-10 20:41:25 +01:00
|
|
|
const listenerOptions = supportsPassiveEvents ? { passive: true } : false;
|
|
|
|
|
2017-07-27 21:31:59 +01:00
|
|
|
let userTouching = false;
|
|
|
|
|
2020-11-16 04:16:39 +00:00
|
|
|
const touchListener = () => {
|
2017-07-27 21:31:59 +01:00
|
|
|
userTouching = true;
|
2022-10-10 20:41:25 +01:00
|
|
|
|
2023-04-03 02:31:39 +01:00
|
|
|
window.removeEventListener('touchstart', touchListener);
|
2020-11-16 04:16:39 +00:00
|
|
|
};
|
2017-09-19 16:00:29 +01:00
|
|
|
|
|
|
|
window.addEventListener('touchstart', touchListener, listenerOptions);
|
2017-07-27 21:31:59 +01:00
|
|
|
|
2020-11-16 04:16:39 +00:00
|
|
|
export const isUserTouching = () => userTouching;
|
2017-03-07 08:54:57 +00:00
|
|
|
|
2020-11-16 04:16:39 +00:00
|
|
|
export const isIOS = () => iOS;
|