UNPKG

emulate-key-in-browser

Version:
31 lines (30 loc) 1.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.findSelectionEnd = exports.findSelectionStart = exports.getValueLength = exports.isTextInputElement = void 0; function isTextInputElement(element) { return (element instanceof HTMLInputElement) || (element instanceof HTMLTextAreaElement); } exports.isTextInputElement = isTextInputElement; function getValueLength(target) { return target.value && target.value.length || 0; } exports.getValueLength = getValueLength; function findSelectionStart(target, valueLength) { if (valueLength === void 0) { valueLength = getValueLength(target); } if (typeof target.selectionStart === 'number') return target.selectionStart; if (typeof target.selectionEnd === 'number') return target.selectionEnd; return valueLength; } exports.findSelectionStart = findSelectionStart; function findSelectionEnd(target, valueLength) { if (valueLength === void 0) { valueLength = getValueLength(target); } if (typeof target.selectionEnd === 'number') return target.selectionEnd; if (typeof target.selectionStart === 'number') return target.selectionStart; return valueLength; } exports.findSelectionEnd = findSelectionEnd;