Fix bugs with resize grid. Add documentation. Add example code.

This commit is contained in:
Sj-Si 2024-05-23 17:11:49 -04:00
parent ee81dadda8
commit 4a2c806448
7 changed files with 865 additions and 641 deletions

View file

@ -169,6 +169,25 @@ function querySelectorThrowError(selector) {
return elem;
}
const validateArrayType = (arr, type_check_fn) => {
/** Validates that a variable is an array with members of a specified type.
* `type_check_fn` must accept array elements as arguments and return whether
* they match the expected type.
* `arr` will be wrapped in an array if it is not already an array.
*/
isNullOrUndefinedThrowError(type_check_fn);
if (isNullOrUndefined(arr)) {
return [];
}
if (!Array.isArray(arr) && type_check_fn(arr)) {
return [arr];
} else if (Array.isArray(arr) && arr.every((x) => type_check_fn(x))) {
return arr;
} else {
throw new Error('Invalid array types:', arr);
}
};
/** Functions for getting dimensions of elements. */
function getStyle(elem) {
return window.getComputedStyle ? window.getComputedStyle(elem) : elem.currentStyle;