Skip to content

Commit

Permalink
0.66.0
Browse files Browse the repository at this point in the history
- string: template
- value
  - clone: map & set
  - merge: option to skip null in arrays
- refactoring
  • Loading branch information
oscarpalmer committed Jul 29, 2024
1 parent 720969f commit e2b7b8d
Show file tree
Hide file tree
Showing 34 changed files with 1,720 additions and 1,399 deletions.
Binary file modified bun.lockb
Binary file not shown.
22 changes: 11 additions & 11 deletions dist/js/array/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,19 @@ function shuffle2(array) {
return shuffled;
}
// src/js/is.ts
function isKey(value) {
return typeof value === "number" || typeof value === "string";
function isKey(value2) {
return typeof value2 === "number" || typeof value2 === "string";
}

// src/js/array/sort.ts
var comparison = function(first, second) {
function comparison(first, second) {
if (typeof first === "number" && typeof second === "number") {
return first - second;
}
const firstAsNumber = Number(first);
const secondAsNumber = Number(second);
return Number.isNaN(firstAsNumber) || Number.isNaN(secondAsNumber) ? String(first).localeCompare(String(second)) : firstAsNumber - secondAsNumber;
};
}
function sort(array2, first, second) {
if (array2.length < 2) {
return array2;
Expand All @@ -203,12 +203,12 @@ function sort(array2, first, second) {
callback: undefined
};
if (isKey(key)) {
returned.callback = (value) => value[key];
returned.callback = (value2) => value2[key];
} else if (typeof key === "function") {
returned.callback = key;
} else if (typeof key?.value === "function" || isKey(key?.value)) {
returned.direction = key?.direction ?? direction;
returned.callback = typeof key.value === "function" ? key.value : (value) => value[key.value];
returned.callback = typeof key.value === "function" ? key.value : (value2) => value2[key.value];
}
return returned;
}).filter((key) => typeof key.callback === "function");
Expand Down Expand Up @@ -245,17 +245,17 @@ function toMap(array2, first, second) {
const map = new Map;
const { length } = array2;
for (let index = 0;index < length; index += 1) {
const value = array2[index];
const key = hasCallback ? callbacks?.key?.(value, index, array2) ?? index : index;
const value2 = array2[index];
const key = hasCallback ? callbacks?.key?.(value2, index, array2) ?? index : index;
if (asArrays) {
const existing = map.get(key);
if (Array.isArray(existing)) {
existing.push(value);
existing.push(value2);
} else {
map.set(key, [value]);
map.set(key, [value2]);
}
} else {
map.set(key, value);
map.set(key, value2);
}
}
return map;
Expand Down
4 changes: 2 additions & 2 deletions dist/js/colour/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ function createHex(original) {
function getHexColour(value) {
return createHex(anyPattern.test(value) ? getNormalisedHex(value) : "000000");
}
var getNormalisedHex = function(value) {
function getNormalisedHex(value) {
const normalised = value.replace(/^#/, "");
return normalised.length === 3 ? normalised.split("").map((character) => character.repeat(2)).join("") : normalised;
};
}
function hexToRgb(value) {
const hex2 = anyPattern.test(value) ? getNormalisedHex(value) : "";
const pairs = groupedPattern.exec(hex2) ?? [];
Expand Down
60 changes: 30 additions & 30 deletions dist/js/element/focusable.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@
function getFocusableElements(parent) {
return getValidElements(parent, getFocusableFilters(), false);
}
var getFocusableFilters = function() {
function getFocusableFilters() {
return [isDisabled, isInert, isHidden, isSummarised];
};
var getItem = function(element, tabbable) {
}
function getItem(element, tabbable) {
return {
element,
tabIndex: tabbable ? getTabIndex(element) : -1
};
};
var getTabbableFilters = function() {
}
function getTabbableFilters() {
return [isNotTabbable, isNotTabbableRadio, ...getFocusableFilters()];
};
}
function getTabbableElements(parent) {
return getValidElements(parent, getTabbableFilters(), true);
}
var getTabIndex = function(element) {
function getTabIndex(element) {
const tabIndex = element?.tabIndex ?? -1;
if (tabIndex < 0 && (/^(audio|details|video)$/i.test(element.tagName) || isEditable(element)) && !hasTabIndex(element)) {
return 0;
}
return tabIndex;
};
var getValidElements = function(parent, filters, tabbable) {
}
function getValidElements(parent, filters, tabbable) {
const items = Array.from(parent.querySelectorAll(selector)).map((element) => getItem(element, tabbable)).filter((item) => !filters.some((filter) => filter(item)));
if (!tabbable) {
return items.map((item) => item.element);
Expand All @@ -44,17 +44,17 @@ var getValidElements = function(parent, filters, tabbable) {
}
}
return [...indiced.flat(), ...zeroed];
};
var hasTabIndex = function(element) {
}
function hasTabIndex(element) {
return !Number.isNaN(Number.parseInt(element.getAttribute("tabindex"), 10));
};
var isDisabled = function(item) {
}
function isDisabled(item) {
if (/^(button|input|select|textarea)$/i.test(item.element.tagName) && isDisabledFromFieldset(item.element)) {
return true;
}
return (item.element.disabled ?? false) || item.element.getAttribute("aria-disabled") === "true";
};
var isDisabledFromFieldset = function(element) {
}
function isDisabledFromFieldset(element) {
let parent = element.parentElement;
while (parent !== null) {
if (parent instanceof HTMLFieldSetElement && parent.disabled) {
Expand All @@ -71,14 +71,14 @@ var isDisabledFromFieldset = function(element) {
parent = parent.parentElement;
}
return false;
};
var isEditable = function(element) {
}
function isEditable(element) {
return /^(|true)$/i.test(element.getAttribute("contenteditable"));
};
}
function isFocusableElement(element) {
return isValidElement(element, getFocusableFilters(), false);
}
var isHidden = function(item) {
function isHidden(item) {
if ((item.element.hidden ?? false) || item.element instanceof HTMLInputElement && item.element.type === "hidden") {
return true;
}
Expand All @@ -93,17 +93,17 @@ var isHidden = function(item) {
}
const { height, width } = item.element.getBoundingClientRect();
return height === 0 && width === 0;
};
var isInert = function(item) {
}
function isInert(item) {
return (item.element.inert ?? false) || /^(|true)$/i.test(item.element.getAttribute("inert")) || item.element.parentElement !== null && isInert({
element: item.element.parentElement,
tabIndex: -1
});
};
var isNotTabbable = function(item) {
}
function isNotTabbable(item) {
return (item.tabIndex ?? -1) < 0;
};
var isNotTabbableRadio = function(item) {
}
function isNotTabbableRadio(item) {
if (!(item.element instanceof HTMLInputElement) || item.element.type !== "radio" || !item.element.name || item.element.checked) {
return false;
}
Expand All @@ -112,17 +112,17 @@ var isNotTabbableRadio = function(item) {
const radios = Array.from(parent.querySelectorAll(`input[type="radio"][name="${realName}"]`));
const checked = radios.find((radio) => radio.checked);
return checked !== undefined && checked !== item.element;
};
var isSummarised = function(item) {
}
function isSummarised(item) {
return item.element instanceof HTMLDetailsElement && Array.from(item.element.children).some((child) => /^summary$/i.test(child.tagName));
};
}
function isTabbableElement(element) {
return isValidElement(element, getTabbableFilters(), true);
}
var isValidElement = function(element, filters, tabbable) {
function isValidElement(element, filters, tabbable) {
const item = getItem(element, tabbable);
return !filters.some((filter) => filter(item));
};
}
var selector = [
'[contenteditable]:not([contenteditable="false"])',
"[tabindex]:not(slot)",
Expand Down
92 changes: 48 additions & 44 deletions dist/js/element/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function getTextDirection(element) {
}

// src/js/element/closest.ts
var calculateDistance = function(origin, target) {
function calculateDistance(origin, target) {
const comparison = origin.compareDocumentPosition(target);
const children = [...origin.parentElement?.children ?? []];
switch (true) {
Expand All @@ -31,7 +31,7 @@ var calculateDistance = function(origin, target) {
default:
return -1;
}
};
}
function closest(origin, selector, context) {
const elements = [...(context ?? document).querySelectorAll(selector)];
const { length } = elements;
Expand All @@ -56,7 +56,7 @@ function closest(origin, selector, context) {
}
return minimum == null ? [] : distances.filter((found) => found.distance === minimum).map((found) => found.element);
}
var traverse = function(from, to) {
function traverse(from, to) {
const children = [...to.children];
if (children.includes(from)) {
return children.indexOf(from) + 1;
Expand All @@ -81,53 +81,55 @@ var traverse = function(from, to) {
parent = parent.parentElement;
}
return -1e6;
};
}
// src/js/string/index.ts
function getString(value) {
if (typeof value === "string") {
return value;
function getString(value2) {
if (typeof value2 === "string") {
return value2;
}
if (typeof value !== "object" || value == null) {
return String(value);
if (typeof value2 !== "object" || value2 == null) {
return String(value2);
}
const valueOff = value.valueOf?.() ?? value;
const valueOff = value2.valueOf?.() ?? value2;
const asString = valueOff?.toString?.() ?? String(valueOff);
return asString.startsWith("[object ") ? JSON.stringify(value) : asString;
return asString.startsWith("[object ") ? JSON.stringify(value2) : asString;
}
function parse(value, reviver) {
function parse(value2, reviver) {
try {
return JSON.parse(value, reviver);
return JSON.parse(value2, reviver);
} catch {
}
}
// src/js/is.ts
function isNullableOrWhitespace(value) {
return value == null || /^\s*$/.test(getString(value));
function isNullableOrWhitespace(value2) {
return value2 == null || /^\s*$/.test(getString(value2));
}
function isPlainObject(value) {
if (typeof value !== "object" || value === null) {
function isPlainObject(value2) {
if (typeof value2 !== "object" || value2 === null) {
return false;
}
const prototype = Object.getPrototypeOf(value);
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
const prototype = Object.getPrototypeOf(value2);
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value2) && !(Symbol.iterator in value2);
}

// src/js/internal/element-value.ts
function setElementValues(element, first, second, callback) {
if (isPlainObject(first)) {
const entries = Object.entries(first);
for (const [key, value] of entries) {
callback(element, key, value);
const { length } = entries;
for (let index = 0;index < length; index += 1) {
const [key, value2] = entries[index];
callback(element, key, value2);
}
} else if (first != null) {
callback(element, first, second);
}
}
function updateElementValue(element, key, value, set, remove, json) {
if (isNullableOrWhitespace(value)) {
function updateElementValue(element, key, value2, set3, remove, json) {
if (isNullableOrWhitespace(value2)) {
remove.call(element, key);
} else {
set.call(element, key, json ? JSON.stringify(value) : String(value));
set3.call(element, key, json ? JSON.stringify(value2) : String(value2));
}
}

Expand All @@ -137,44 +139,46 @@ function getData(element, keys) {
return getDataValue(element, keys);
}
const data = {};
for (const key of keys) {
const { length } = keys;
for (let index = 0;index < length; index += 1) {
const key = keys[index];
data[key] = getDataValue(element, key);
}
return data;
}
var getDataValue = function(element, key) {
const value = element.dataset[key];
if (value != null) {
return parse(value);
function getDataValue(element, key) {
const value2 = element.dataset[key];
if (value2 != null) {
return parse(value2);
}
};
}
function setData(element, first, second) {
setElementValues(element, first, second, updateDataAttribute);
}
var updateDataAttribute = function(element, key, value) {
updateElementValue(element, `data-${key}`, value, element.setAttribute, element.removeAttribute, true);
};
function updateDataAttribute(element, key, value2) {
updateElementValue(element, `data-${key}`, value2, element.setAttribute, element.removeAttribute, true);
}
// src/js/element/find.ts
function findElement(selector, context) {
return findElementOrElements(selector, context, true);
}
var findElementOrElements = function(selector, context, single) {
function findElementOrElements(selector, context, single) {
const callback = single ? document.querySelector : document.querySelectorAll;
const contexts = context == null ? [document] : findElementOrElements(context, undefined, false);
const result = [];
if (typeof selector === "string") {
const { length: length2 } = contexts;
for (let index = 0;index < length2; index += 1) {
const value = callback.call(contexts[index], selector);
const value2 = callback.call(contexts[index], selector);
if (single) {
if (value == null) {
if (value2 == null) {
continue;
}
return value;
return value2;
}
result.push(...Array.from(value));
result.push(...Array.from(value2));
}
return single ? undefined : result.filter((value, index, array2) => array2.indexOf(value) === index);
return single ? undefined : result.filter((value2, index, array2) => array2.indexOf(value2) === index);
}
const nodes = Array.isArray(selector) ? selector : selector instanceof NodeList ? Array.from(selector) : [selector];
const { length } = nodes;
Expand All @@ -186,7 +190,7 @@ var findElementOrElements = function(selector, context, single) {
}
}
return result;
};
}
function findElements(selector, context) {
return findElementOrElements(selector, context, false);
}
Expand Down Expand Up @@ -216,13 +220,13 @@ function findParentElement(origin, selector) {
function setStyles(element, first, second) {
setElementValues(element, first, second, updateStyleProperty);
}
var updateStyleProperty = function(element, key, value) {
updateElementValue(element, key, value, function(key2, value2) {
this.style[key2] = value2;
function updateStyleProperty(element, key, value2) {
updateElementValue(element, key, value2, function(key2, value3) {
this.style[key2] = value3;
}, function(key2) {
this.style[key2] = "";
}, false);
};
}
export {
setStyles,
setData,
Expand Down
Loading

0 comments on commit e2b7b8d

Please sign in to comment.