This commit is contained in:
Iliyan Angelov
2025-09-14 23:24:25 +03:00
commit c67067a2a4
71311 changed files with 6800714 additions and 0 deletions

View File

@@ -0,0 +1 @@
export declare function buildTimeValue(value: string): string;

View File

@@ -0,0 +1,44 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.buildTimeValue = buildTimeValue;
function buildTimeValue(value) {
const onlyDigitsValue = value.replace(/\D/g, '');
if (onlyDigitsValue.length < 2) {
return value;
}
const firstDigit = parseInt(onlyDigitsValue[0], 10);
const secondDigit = parseInt(onlyDigitsValue[1], 10);
if (firstDigit >= 3 || firstDigit === 2 && secondDigit >= 4) {
let index;
if (firstDigit >= 3) {
index = 1;
} else {
index = 2;
}
return build(onlyDigitsValue, index);
}
if (value.length === 2) {
return value;
}
return build(onlyDigitsValue, 2);
}
function build(onlyDigitsValue, index) {
const hours = onlyDigitsValue.slice(0, index);
const validHours = Math.min(parseInt(hours, 10), 23);
const minuteCharacters = onlyDigitsValue.slice(index);
const parsedMinutes = parseInt(minuteCharacters, 10);
const validMinutes = Math.min(parsedMinutes, 59);
return `${validHours.toString().padStart(2, '0')}:${validMinutes.toString().padStart(2, '0')}`;
}

View File

@@ -0,0 +1,7 @@
export declare function calculateNewValue(newEntry: string, element: HTMLElement, value?: string, selectionRange?: {
selectionStart: number | null;
selectionEnd: number | null;
}, deleteContent?: 'backward' | 'forward'): {
newValue: string;
newSelectionStart: number;
};

View File

@@ -0,0 +1,48 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.calculateNewValue = calculateNewValue;
var _selectionRange = require("./selectionRange");
var _getValue2 = require("./getValue");
var _isValidDateValue = require("./isValidDateValue");
var _isValidInputTimeValue = require("./isValidInputTimeValue");
function calculateNewValue(newEntry, element, value = (() => {
var _getValue;
return (_getValue = (0, _getValue2.getValue)(element)) != null ? _getValue :
/* istanbul ignore next */
'';
})(), selectionRange = (0, _selectionRange.getSelectionRange)(element), deleteContent) {
const selectionStart = selectionRange.selectionStart === null ? value.length : selectionRange.selectionStart;
const selectionEnd = selectionRange.selectionEnd === null ? value.length : selectionRange.selectionEnd;
const prologEnd = Math.max(0, selectionStart === selectionEnd && deleteContent === 'backward' ? selectionStart - 1 : selectionStart);
const prolog = value.substring(0, prologEnd);
const epilogStart = Math.min(value.length, selectionStart === selectionEnd && deleteContent === 'forward' ? selectionEnd + 1 : selectionEnd);
const epilog = value.substring(epilogStart, value.length);
let newValue = `${prolog}${newEntry}${epilog}`;
const newSelectionStart = prologEnd + newEntry.length;
if (element.type === 'date' && !(0, _isValidDateValue.isValidDateValue)(element, newValue)) {
newValue = value;
}
if (element.type === 'time' && !(0, _isValidInputTimeValue.isValidInputTimeValue)(element, newValue)) {
if ((0, _isValidInputTimeValue.isValidInputTimeValue)(element, newEntry)) {
newValue = newEntry;
} else {
newValue = value;
}
}
return {
newValue,
newSelectionStart
};
}

View File

@@ -0,0 +1,2 @@
export declare function isCursorAtEnd(element: Element): boolean;
export declare function isCursorAtStart(element: Element): boolean;

View File

@@ -0,0 +1,35 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isCursorAtEnd = isCursorAtEnd;
exports.isCursorAtStart = isCursorAtStart;
var _selectionRange = require("./selectionRange");
var _getValue2 = require("./getValue");
function isCursorAtEnd(element) {
var _getValue;
const {
selectionStart,
selectionEnd
} = (0, _selectionRange.getSelectionRange)(element);
return selectionStart === selectionEnd && (selectionStart != null ? selectionStart :
/* istanbul ignore next */
0) === ((_getValue = (0, _getValue2.getValue)(element)) != null ? _getValue :
/* istanbul ignore next */
'').length;
}
function isCursorAtStart(element) {
const {
selectionStart,
selectionEnd
} = (0, _selectionRange.getSelectionRange)(element);
return selectionStart === selectionEnd && (selectionStart != null ? selectionStart :
/* istanbul ignore next */
0) === 0;
}

View File

@@ -0,0 +1 @@
export declare function getValue(element: Element | null): string | null;

View File

@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getValue = getValue;
var _isContentEditable = require("./isContentEditable");
function getValue(element) {
// istanbul ignore if
if (!element) {
return null;
}
if ((0, _isContentEditable.isContentEditable)(element)) {
return element.textContent;
}
return element.value;
}

View File

@@ -0,0 +1,10 @@
declare enum unreliableValueInputTypes {
'number' = "number"
}
/**
* Check if an empty IDL value on the element could mean a derivation of displayed value and IDL value
*/
export declare function hasUnreliableEmptyValue(element: Element): element is HTMLInputElement & {
type: unreliableValueInputTypes;
};
export {};

View File

@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.hasUnreliableEmptyValue = hasUnreliableEmptyValue;
var _isElementType = require("../misc/isElementType");
var unreliableValueInputTypes;
/**
* Check if an empty IDL value on the element could mean a derivation of displayed value and IDL value
*/
(function (unreliableValueInputTypes) {
unreliableValueInputTypes["number"] = "number";
})(unreliableValueInputTypes || (unreliableValueInputTypes = {}));
function hasUnreliableEmptyValue(element) {
return (0, _isElementType.isElementType)(element, 'input') && Boolean(unreliableValueInputTypes[element.type]);
}

View File

@@ -0,0 +1,3 @@
export declare function isContentEditable(element: Element): element is HTMLElement & {
contenteditable: 'true';
};

View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isContentEditable = isContentEditable;
//jsdom is not supporting isContentEditable
function isContentEditable(element) {
return element.hasAttribute('contenteditable') && (element.getAttribute('contenteditable') == 'true' || element.getAttribute('contenteditable') == '');
}

View File

@@ -0,0 +1,24 @@
import { isContentEditable } from './isContentEditable';
declare type GuardedType<T> = T extends (x: any) => x is infer R ? R : never;
export declare function isEditable(element: Element): element is GuardedType<typeof isContentEditable> | GuardedType<typeof isEditableInput> | (HTMLTextAreaElement & {
readOnly: false;
});
export declare enum editableInputTypes {
'text' = "text",
'date' = "date",
'datetime-local' = "datetime-local",
'email' = "email",
'month' = "month",
'number' = "number",
'password' = "password",
'search' = "search",
'tel' = "tel",
'time' = "time",
'url' = "url",
'week' = "week"
}
export declare function isEditableInput(element: Element): element is HTMLInputElement & {
readOnly: false;
type: editableInputTypes;
};
export {};

View File

@@ -0,0 +1,42 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.editableInputTypes = void 0;
exports.isEditable = isEditable;
exports.isEditableInput = isEditableInput;
var _isElementType = require("../misc/isElementType");
var _isContentEditable = require("./isContentEditable");
function isEditable(element) {
return isEditableInput(element) || (0, _isElementType.isElementType)(element, 'textarea', {
readOnly: false
}) || (0, _isContentEditable.isContentEditable)(element);
}
let editableInputTypes;
exports.editableInputTypes = editableInputTypes;
(function (editableInputTypes) {
editableInputTypes["text"] = "text";
editableInputTypes["date"] = "date";
editableInputTypes["datetime-local"] = "datetime-local";
editableInputTypes["email"] = "email";
editableInputTypes["month"] = "month";
editableInputTypes["number"] = "number";
editableInputTypes["password"] = "password";
editableInputTypes["search"] = "search";
editableInputTypes["tel"] = "tel";
editableInputTypes["time"] = "time";
editableInputTypes["url"] = "url";
editableInputTypes["week"] = "week";
})(editableInputTypes || (exports.editableInputTypes = editableInputTypes = {}));
function isEditableInput(element) {
return (0, _isElementType.isElementType)(element, 'input', {
readOnly: false
}) && Boolean(editableInputTypes[element.type]);
}

View File

@@ -0,0 +1,3 @@
export declare function isValidDateValue(element: HTMLInputElement & {
type: 'date';
}, value: string): boolean;

View File

@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isValidDateValue = isValidDateValue;
function isValidDateValue(element, value) {
const clone = element.cloneNode();
clone.value = value;
return clone.value === value;
}

View File

@@ -0,0 +1,3 @@
export declare function isValidInputTimeValue(element: HTMLInputElement & {
type: 'time';
}, timeValue: string): boolean;

View File

@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isValidInputTimeValue = isValidInputTimeValue;
function isValidInputTimeValue(element, timeValue) {
const clone = element.cloneNode();
clone.value = timeValue;
return clone.value === timeValue;
}

View File

@@ -0,0 +1 @@
export declare function getSpaceUntilMaxLength(element: Element): number | undefined;

View File

@@ -0,0 +1,50 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getSpaceUntilMaxLength = getSpaceUntilMaxLength;
var _isElementType = require("../misc/isElementType");
var _getValue = require("./getValue");
var maxLengthSupportedTypes;
(function (maxLengthSupportedTypes) {
maxLengthSupportedTypes["email"] = "email";
maxLengthSupportedTypes["password"] = "password";
maxLengthSupportedTypes["search"] = "search";
maxLengthSupportedTypes["telephone"] = "telephone";
maxLengthSupportedTypes["text"] = "text";
maxLengthSupportedTypes["url"] = "url";
})(maxLengthSupportedTypes || (maxLengthSupportedTypes = {}));
function getSpaceUntilMaxLength(element) {
const value = (0, _getValue.getValue)(element);
/* istanbul ignore if */
if (value === null) {
return undefined;
}
const maxLength = getSanitizedMaxLength(element);
return maxLength ? maxLength - value.length : undefined;
} // can't use .maxLength property because of a jsdom bug:
// https://github.com/jsdom/jsdom/issues/2927
function getSanitizedMaxLength(element) {
var _element$getAttribute;
if (!supportsMaxLength(element)) {
return undefined;
}
const attr = (_element$getAttribute = element.getAttribute('maxlength')) != null ? _element$getAttribute : '';
return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : undefined;
}
function supportsMaxLength(element) {
return (0, _isElementType.isElementType)(element, 'textarea') || (0, _isElementType.isElementType)(element, 'input') && Boolean(maxLengthSupportedTypes[element.type]);
}

View File

@@ -0,0 +1,16 @@
declare enum selectionSupportType {
'text' = "text",
'search' = "search",
'url' = "url",
'tel' = "tel",
'password' = "password"
}
export declare function hasSelectionSupport(element: Element): element is HTMLTextAreaElement | (HTMLInputElement & {
type: selectionSupportType;
});
export declare function getSelectionRange(element: Element): {
selectionStart: number | null;
selectionEnd: number | null;
};
export declare function setSelectionRange(element: Element, newSelectionStart: number, newSelectionEnd: number): void;
export {};

View File

@@ -0,0 +1,104 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getSelectionRange = getSelectionRange;
exports.hasSelectionSupport = hasSelectionSupport;
exports.setSelectionRange = setSelectionRange;
var _isElementType = require("../misc/isElementType");
// https://github.com/jsdom/jsdom/blob/c2fb8ff94917a4d45e2398543f5dd2a8fed0bdab/lib/jsdom/living/nodes/HTMLInputElement-impl.js#L45
var selectionSupportType;
(function (selectionSupportType) {
selectionSupportType["text"] = "text";
selectionSupportType["search"] = "search";
selectionSupportType["url"] = "url";
selectionSupportType["tel"] = "tel";
selectionSupportType["password"] = "password";
})(selectionSupportType || (selectionSupportType = {}));
const InputSelection = Symbol('inputSelection');
function hasSelectionSupport(element) {
return (0, _isElementType.isElementType)(element, 'textarea') || (0, _isElementType.isElementType)(element, 'input') && Boolean(selectionSupportType[element.type]);
}
function getSelectionRange(element) {
if (hasSelectionSupport(element)) {
return {
selectionStart: element.selectionStart,
selectionEnd: element.selectionEnd
};
}
if ((0, _isElementType.isElementType)(element, 'input')) {
var _InputSelection;
return (_InputSelection = element[InputSelection]) != null ? _InputSelection : {
selectionStart: null,
selectionEnd: null
};
}
const selection = element.ownerDocument.getSelection(); // there should be no editing if the focusNode is outside of element
// TODO: properly handle selection ranges
if (selection != null && selection.rangeCount && element.contains(selection.focusNode)) {
const range = selection.getRangeAt(0);
return {
selectionStart: range.startOffset,
selectionEnd: range.endOffset
};
} else {
return {
selectionStart: null,
selectionEnd: null
};
}
}
function setSelectionRange(element, newSelectionStart, newSelectionEnd) {
const {
selectionStart,
selectionEnd
} = getSelectionRange(element);
if (selectionStart === newSelectionStart && selectionEnd === newSelectionEnd) {
return;
}
if (hasSelectionSupport(element)) {
element.setSelectionRange(newSelectionStart, newSelectionEnd);
}
if ((0, _isElementType.isElementType)(element, 'input')) {
;
element[InputSelection] = {
selectionStart: newSelectionStart,
selectionEnd: newSelectionEnd
};
} // Moving the selection inside <input> or <textarea> does not alter the document Selection.
if ((0, _isElementType.isElementType)(element, 'input') || (0, _isElementType.isElementType)(element, 'textarea')) {
return;
}
const range = element.ownerDocument.createRange();
range.selectNodeContents(element); // istanbul ignore else
if (element.firstChild) {
range.setStart(element.firstChild, newSelectionStart);
range.setEnd(element.firstChild, newSelectionEnd);
}
const selection = element.ownerDocument.getSelection(); // istanbul ignore else
if (selection) {
selection.removeAllRanges();
selection.addRange(range);
}
}