0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 15:23:29 -05:00
Squire/source/Constants.ts
Neil Jenkins fe0dfdf6c4 Squire 2.0
This is a massive refactor to port Squire to TypeScript, fix a bunch of small
bugs and modernise our tooling. The development was done on an internal
repository, so apologies to anyone following externally for the commit dump;
updates from here should come as real commits again.

Co-authored-by: Joe Woods <woods@fastmailteam.com>
2023-01-23 13:18:29 +11:00

52 lines
1.3 KiB
TypeScript

const DOCUMENT_POSITION_PRECEDING = 2; // Node.DOCUMENT_POSITION_PRECEDING
const ELEMENT_NODE = 1; // Node.ELEMENT_NODE;
const TEXT_NODE = 3; // Node.TEXT_NODE;
const DOCUMENT_NODE = 9; // Node.DOCUMENT_NODE;
const DOCUMENT_FRAGMENT_NODE = 11; // Node.DOCUMENT_FRAGMENT_NODE;
const ZWS = '\u200B';
const ua = navigator.userAgent;
const isMac = /Mac OS X/.test(ua);
const isWin = /Windows NT/.test(ua);
const isIOS =
/iP(?:ad|hone|od)/.test(ua) || (isMac && !!navigator.maxTouchPoints);
const isAndroid = /Android/.test(ua);
const isGecko = /Gecko\//.test(ua);
const isLegacyEdge = /Edge\//.test(ua);
const isWebKit = !isLegacyEdge && /WebKit\//.test(ua);
const ctrlKey = isMac || isIOS ? 'Meta-' : 'Ctrl-';
const cantFocusEmptyTextNodes = isWebKit;
const supportsInputEvents =
'onbeforeinput' in document && 'inputType' in new InputEvent('input');
// Use [^ \t\r\n] instead of \S so that nbsp does not count as white-space
const notWS = /[^ \t\r\n]/;
// ---
export {
DOCUMENT_POSITION_PRECEDING,
ELEMENT_NODE,
TEXT_NODE,
DOCUMENT_NODE,
DOCUMENT_FRAGMENT_NODE,
notWS,
ZWS,
ua,
isMac,
isWin,
isIOS,
isAndroid,
isGecko,
isLegacyEdge,
isWebKit,
ctrlKey,
cantFocusEmptyTextNodes,
supportsInputEvents,
};