json-joy
Version:
Collection of libraries for building collaborative editing apps.
20 lines • 759 B
JavaScript
export const getCursorPosition = typeof document !== 'undefined' && document.caretPositionFromPoint
? (x, y) => {
const range = document.caretPositionFromPoint(x, y);
return range ? [range.offsetNode, range.offset] : null;
}
: (x, y) => {
const range = document.caretRangeFromPoint(x, y);
return range ? [range.startContainer, range.startOffset] : null;
};
export const unit = (event) => event.metaKey ? 'vline' : event.altKey || event.ctrlKey ? 'word' : '';
export const getDomain = (url) => url.match(/^(?:[^:/]+:)?(?:\/{1,5})?(([^/$ .]+)\.([^/$ ]+))/i)?.[1];
export const parseUrl = (url) => {
try {
return new URL(url);
}
catch {
return;
}
};
//# sourceMappingURL=util.js.map