json-joy
Version:
Collection of libraries for building collaborative editing apps.
26 lines (25 loc) • 953 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseUrl = exports.getDomain = exports.unit = exports.getCursorPosition = void 0;
exports.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;
};
const unit = (event) => event.metaKey ? 'vline' : event.altKey || event.ctrlKey ? 'word' : '';
exports.unit = unit;
const getDomain = (url) => url.match(/^(?:[^:\/]+:)?(?:\/{1,5})?(([^\/$ \.]+)\.([^\/$ ]+))/i)?.[1];
exports.getDomain = getDomain;
const parseUrl = (url) => {
try {
return new URL(url);
}
catch {
return;
}
};
exports.parseUrl = parseUrl;