@oscarpalmer/atoms 0.64.0 → 0.66.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/js/array/index.js +11 -11
- package/dist/js/array/sort.mjs +2 -2
- package/dist/js/colour/hex.mjs +2 -2
- package/dist/js/colour/index.js +2 -2
- package/dist/js/colour/index.mjs +1 -1
- package/dist/js/element/closest.mjs +4 -4
- package/dist/js/element/data.mjs +7 -5
- package/dist/js/element/find.mjs +2 -2
- package/dist/js/element/focusable.js +30 -30
- package/dist/js/element/focusable.mjs +30 -30
- package/dist/js/element/index.js +48 -44
- package/dist/js/element/style.mjs +2 -2
- package/dist/js/emitter.js +6 -6
- package/dist/js/emitter.mjs +6 -6
- package/dist/js/index.js +1097 -1041
- package/dist/js/internal/element-value.mjs +3 -1
- package/dist/js/internal/value-handle.mjs +2 -2
- package/dist/js/is.js +38 -34
- package/dist/js/is.mjs +8 -4
- package/dist/js/logger.js +2 -2
- package/dist/js/logger.mjs +2 -2
- package/dist/js/query.js +40 -39
- package/dist/js/query.mjs +6 -6
- package/dist/js/queue.js +4 -3
- package/dist/js/queue.mjs +4 -3
- package/dist/js/string/case.mjs +2 -2
- package/dist/js/string/index.js +67 -17
- package/dist/js/string/index.mjs +1 -0
- package/dist/js/string/template.mjs +21 -0
- package/dist/js/timer.js +8 -8
- package/dist/js/timer.mjs +8 -8
- package/dist/js/value/clone.mjs +27 -9
- package/dist/js/value/diff.mjs +3 -3
- package/dist/js/value/equal.mjs +28 -22
- package/dist/js/value/index.js +141 -112
- package/dist/js/value/index.mjs +1 -1
- package/dist/js/value/merge.mjs +7 -2
- package/dist/js/value/smush.mjs +2 -2
- package/dist/js/value/unsmush.mjs +2 -2
- package/package.json +7 -3
- package/src/js/colour/index.ts +1 -1
- package/src/js/element/data.ts +4 -1
- package/src/js/internal/element-value.ts +4 -1
- package/src/js/is.ts +10 -9
- package/src/js/models.ts +0 -2
- package/src/js/queue.ts +4 -3
- package/src/js/string/index.ts +2 -0
- package/src/js/string/template.ts +42 -0
- package/src/js/value/clone.ts +27 -2
- package/src/js/value/diff.ts +1 -1
- package/src/js/value/equal.ts +27 -11
- package/src/js/value/get.ts +2 -1
- package/src/js/value/index.ts +12 -11
- package/src/js/value/merge.ts +19 -3
- package/src/js/value/smush.ts +2 -1
- package/types/colour/index.d.ts +1 -1
- package/types/index.d.cts +746 -283
- package/types/models.d.ts +0 -1
- package/types/string/index.d.ts +1 -0
- package/types/string/template.d.ts +13 -0
- package/types/value/get.d.ts +2 -1
- package/types/value/merge.d.ts +9 -1
- package/types/value/smush.d.ts +2 -1
package/dist/js/array/index.js
CHANGED
|
@@ -176,19 +176,19 @@ function shuffle2(array) {
|
|
|
176
176
|
return shuffled;
|
|
177
177
|
}
|
|
178
178
|
// src/js/is.ts
|
|
179
|
-
function isKey(
|
|
180
|
-
return typeof
|
|
179
|
+
function isKey(value2) {
|
|
180
|
+
return typeof value2 === "number" || typeof value2 === "string";
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
// src/js/array/sort.ts
|
|
184
|
-
|
|
184
|
+
function comparison(first, second) {
|
|
185
185
|
if (typeof first === "number" && typeof second === "number") {
|
|
186
186
|
return first - second;
|
|
187
187
|
}
|
|
188
188
|
const firstAsNumber = Number(first);
|
|
189
189
|
const secondAsNumber = Number(second);
|
|
190
190
|
return Number.isNaN(firstAsNumber) || Number.isNaN(secondAsNumber) ? String(first).localeCompare(String(second)) : firstAsNumber - secondAsNumber;
|
|
191
|
-
}
|
|
191
|
+
}
|
|
192
192
|
function sort(array2, first, second) {
|
|
193
193
|
if (array2.length < 2) {
|
|
194
194
|
return array2;
|
|
@@ -203,12 +203,12 @@ function sort(array2, first, second) {
|
|
|
203
203
|
callback: undefined
|
|
204
204
|
};
|
|
205
205
|
if (isKey(key)) {
|
|
206
|
-
returned.callback = (
|
|
206
|
+
returned.callback = (value2) => value2[key];
|
|
207
207
|
} else if (typeof key === "function") {
|
|
208
208
|
returned.callback = key;
|
|
209
209
|
} else if (typeof key?.value === "function" || isKey(key?.value)) {
|
|
210
210
|
returned.direction = key?.direction ?? direction;
|
|
211
|
-
returned.callback = typeof key.value === "function" ? key.value : (
|
|
211
|
+
returned.callback = typeof key.value === "function" ? key.value : (value2) => value2[key.value];
|
|
212
212
|
}
|
|
213
213
|
return returned;
|
|
214
214
|
}).filter((key) => typeof key.callback === "function");
|
|
@@ -245,17 +245,17 @@ function toMap(array2, first, second) {
|
|
|
245
245
|
const map = new Map;
|
|
246
246
|
const { length } = array2;
|
|
247
247
|
for (let index = 0;index < length; index += 1) {
|
|
248
|
-
const
|
|
249
|
-
const key = hasCallback ? callbacks?.key?.(
|
|
248
|
+
const value2 = array2[index];
|
|
249
|
+
const key = hasCallback ? callbacks?.key?.(value2, index, array2) ?? index : index;
|
|
250
250
|
if (asArrays) {
|
|
251
251
|
const existing = map.get(key);
|
|
252
252
|
if (Array.isArray(existing)) {
|
|
253
|
-
existing.push(
|
|
253
|
+
existing.push(value2);
|
|
254
254
|
} else {
|
|
255
|
-
map.set(key, [
|
|
255
|
+
map.set(key, [value2]);
|
|
256
256
|
}
|
|
257
257
|
} else {
|
|
258
|
-
map.set(key,
|
|
258
|
+
map.set(key, value2);
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
261
|
return map;
|
package/dist/js/array/sort.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// src/js/array/sort.ts
|
|
2
2
|
import {isKey} from "../is";
|
|
3
|
-
|
|
3
|
+
function comparison(first, second) {
|
|
4
4
|
if (typeof first === "number" && typeof second === "number") {
|
|
5
5
|
return first - second;
|
|
6
6
|
}
|
|
7
7
|
const firstAsNumber = Number(first);
|
|
8
8
|
const secondAsNumber = Number(second);
|
|
9
9
|
return Number.isNaN(firstAsNumber) || Number.isNaN(secondAsNumber) ? String(first).localeCompare(String(second)) : firstAsNumber - secondAsNumber;
|
|
10
|
-
}
|
|
10
|
+
}
|
|
11
11
|
function sort(array, first, second) {
|
|
12
12
|
if (array.length < 2) {
|
|
13
13
|
return array;
|
package/dist/js/colour/hex.mjs
CHANGED
|
@@ -28,10 +28,10 @@ function createHex(original) {
|
|
|
28
28
|
function getHexColour(value) {
|
|
29
29
|
return createHex(anyPattern.test(value) ? getNormalisedHex(value) : "000000");
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
function getNormalisedHex(value) {
|
|
32
32
|
const normalised = value.replace(/^#/, "");
|
|
33
33
|
return normalised.length === 3 ? normalised.split("").map((character) => character.repeat(2)).join("") : normalised;
|
|
34
|
-
}
|
|
34
|
+
}
|
|
35
35
|
function hexToRgb(value) {
|
|
36
36
|
const hex = anyPattern.test(value) ? getNormalisedHex(value) : "";
|
|
37
37
|
const pairs = groupedPattern.exec(hex) ?? [];
|
package/dist/js/colour/index.js
CHANGED
|
@@ -171,10 +171,10 @@ function createHex(original) {
|
|
|
171
171
|
function getHexColour(value) {
|
|
172
172
|
return createHex(anyPattern.test(value) ? getNormalisedHex(value) : "000000");
|
|
173
173
|
}
|
|
174
|
-
|
|
174
|
+
function getNormalisedHex(value) {
|
|
175
175
|
const normalised = value.replace(/^#/, "");
|
|
176
176
|
return normalised.length === 3 ? normalised.split("").map((character) => character.repeat(2)).join("") : normalised;
|
|
177
|
-
}
|
|
177
|
+
}
|
|
178
178
|
function hexToRgb(value) {
|
|
179
179
|
const hex2 = anyPattern.test(value) ? getNormalisedHex(value) : "";
|
|
180
180
|
const pairs = groupedPattern.exec(hex2) ?? [];
|
package/dist/js/colour/index.mjs
CHANGED
|
@@ -13,9 +13,9 @@ function getForegroundColour(value) {
|
|
|
13
13
|
}
|
|
14
14
|
import {getHexColour, hexToRgb} from "./hex";
|
|
15
15
|
import {hslToRgb} from "./hsl";
|
|
16
|
-
import {rgbToHex, rgbToHsl} from "./rgb";
|
|
17
16
|
|
|
18
17
|
export * from "./models";
|
|
18
|
+
import {rgbToHex, rgbToHsl} from "./rgb";
|
|
19
19
|
export {
|
|
20
20
|
rgbToHsl,
|
|
21
21
|
rgbToHex,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/js/element/closest.ts
|
|
2
|
-
|
|
2
|
+
function calculateDistance(origin, target) {
|
|
3
3
|
const comparison = origin.compareDocumentPosition(target);
|
|
4
4
|
const children = [...origin.parentElement?.children ?? []];
|
|
5
5
|
switch (true) {
|
|
@@ -12,7 +12,7 @@ var calculateDistance = function(origin, target) {
|
|
|
12
12
|
default:
|
|
13
13
|
return -1;
|
|
14
14
|
}
|
|
15
|
-
}
|
|
15
|
+
}
|
|
16
16
|
function closest(origin, selector, context) {
|
|
17
17
|
const elements = [...(context ?? document).querySelectorAll(selector)];
|
|
18
18
|
const { length } = elements;
|
|
@@ -37,7 +37,7 @@ function closest(origin, selector, context) {
|
|
|
37
37
|
}
|
|
38
38
|
return minimum == null ? [] : distances.filter((found) => found.distance === minimum).map((found) => found.element);
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
function traverse(from, to) {
|
|
41
41
|
const children = [...to.children];
|
|
42
42
|
if (children.includes(from)) {
|
|
43
43
|
return children.indexOf(from) + 1;
|
|
@@ -62,7 +62,7 @@ var traverse = function(from, to) {
|
|
|
62
62
|
parent = parent.parentElement;
|
|
63
63
|
}
|
|
64
64
|
return -1e6;
|
|
65
|
-
}
|
|
65
|
+
}
|
|
66
66
|
export {
|
|
67
67
|
closest
|
|
68
68
|
};
|
package/dist/js/element/data.mjs
CHANGED
|
@@ -6,23 +6,25 @@ function getData(element, keys) {
|
|
|
6
6
|
return getDataValue(element, keys);
|
|
7
7
|
}
|
|
8
8
|
const data = {};
|
|
9
|
-
|
|
9
|
+
const { length } = keys;
|
|
10
|
+
for (let index = 0;index < length; index += 1) {
|
|
11
|
+
const key = keys[index];
|
|
10
12
|
data[key] = getDataValue(element, key);
|
|
11
13
|
}
|
|
12
14
|
return data;
|
|
13
15
|
}
|
|
14
|
-
|
|
16
|
+
function getDataValue(element, key) {
|
|
15
17
|
const value = element.dataset[key];
|
|
16
18
|
if (value != null) {
|
|
17
19
|
return parse(value);
|
|
18
20
|
}
|
|
19
|
-
}
|
|
21
|
+
}
|
|
20
22
|
function setData(element, first, second) {
|
|
21
23
|
setElementValues(element, first, second, updateDataAttribute);
|
|
22
24
|
}
|
|
23
|
-
|
|
25
|
+
function updateDataAttribute(element, key, value) {
|
|
24
26
|
updateElementValue(element, `data-${key}`, value, element.setAttribute, element.removeAttribute, true);
|
|
25
|
-
}
|
|
27
|
+
}
|
|
26
28
|
export {
|
|
27
29
|
setData,
|
|
28
30
|
getData
|
package/dist/js/element/find.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
function findElement(selector, context) {
|
|
3
3
|
return findElementOrElements(selector, context, true);
|
|
4
4
|
}
|
|
5
|
-
|
|
5
|
+
function findElementOrElements(selector, context, single) {
|
|
6
6
|
const callback = single ? document.querySelector : document.querySelectorAll;
|
|
7
7
|
const contexts = context == null ? [document] : findElementOrElements(context, undefined, false);
|
|
8
8
|
const result = [];
|
|
@@ -30,7 +30,7 @@ var findElementOrElements = function(selector, context, single) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
return result;
|
|
33
|
-
}
|
|
33
|
+
}
|
|
34
34
|
function findElements(selector, context) {
|
|
35
35
|
return findElementOrElements(selector, context, false);
|
|
36
36
|
}
|
|
@@ -2,29 +2,29 @@
|
|
|
2
2
|
function getFocusableElements(parent) {
|
|
3
3
|
return getValidElements(parent, getFocusableFilters(), false);
|
|
4
4
|
}
|
|
5
|
-
|
|
5
|
+
function getFocusableFilters() {
|
|
6
6
|
return [isDisabled, isInert, isHidden, isSummarised];
|
|
7
|
-
}
|
|
8
|
-
|
|
7
|
+
}
|
|
8
|
+
function getItem(element, tabbable) {
|
|
9
9
|
return {
|
|
10
10
|
element,
|
|
11
11
|
tabIndex: tabbable ? getTabIndex(element) : -1
|
|
12
12
|
};
|
|
13
|
-
}
|
|
14
|
-
|
|
13
|
+
}
|
|
14
|
+
function getTabbableFilters() {
|
|
15
15
|
return [isNotTabbable, isNotTabbableRadio, ...getFocusableFilters()];
|
|
16
|
-
}
|
|
16
|
+
}
|
|
17
17
|
function getTabbableElements(parent) {
|
|
18
18
|
return getValidElements(parent, getTabbableFilters(), true);
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
function getTabIndex(element) {
|
|
21
21
|
const tabIndex = element?.tabIndex ?? -1;
|
|
22
22
|
if (tabIndex < 0 && (/^(audio|details|video)$/i.test(element.tagName) || isEditable(element)) && !hasTabIndex(element)) {
|
|
23
23
|
return 0;
|
|
24
24
|
}
|
|
25
25
|
return tabIndex;
|
|
26
|
-
}
|
|
27
|
-
|
|
26
|
+
}
|
|
27
|
+
function getValidElements(parent, filters, tabbable) {
|
|
28
28
|
const items = Array.from(parent.querySelectorAll(selector)).map((element) => getItem(element, tabbable)).filter((item) => !filters.some((filter) => filter(item)));
|
|
29
29
|
if (!tabbable) {
|
|
30
30
|
return items.map((item) => item.element);
|
|
@@ -44,17 +44,17 @@ var getValidElements = function(parent, filters, tabbable) {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
return [...indiced.flat(), ...zeroed];
|
|
47
|
-
}
|
|
48
|
-
|
|
47
|
+
}
|
|
48
|
+
function hasTabIndex(element) {
|
|
49
49
|
return !Number.isNaN(Number.parseInt(element.getAttribute("tabindex"), 10));
|
|
50
|
-
}
|
|
51
|
-
|
|
50
|
+
}
|
|
51
|
+
function isDisabled(item) {
|
|
52
52
|
if (/^(button|input|select|textarea)$/i.test(item.element.tagName) && isDisabledFromFieldset(item.element)) {
|
|
53
53
|
return true;
|
|
54
54
|
}
|
|
55
55
|
return (item.element.disabled ?? false) || item.element.getAttribute("aria-disabled") === "true";
|
|
56
|
-
}
|
|
57
|
-
|
|
56
|
+
}
|
|
57
|
+
function isDisabledFromFieldset(element) {
|
|
58
58
|
let parent = element.parentElement;
|
|
59
59
|
while (parent !== null) {
|
|
60
60
|
if (parent instanceof HTMLFieldSetElement && parent.disabled) {
|
|
@@ -71,14 +71,14 @@ var isDisabledFromFieldset = function(element) {
|
|
|
71
71
|
parent = parent.parentElement;
|
|
72
72
|
}
|
|
73
73
|
return false;
|
|
74
|
-
}
|
|
75
|
-
|
|
74
|
+
}
|
|
75
|
+
function isEditable(element) {
|
|
76
76
|
return /^(|true)$/i.test(element.getAttribute("contenteditable"));
|
|
77
|
-
}
|
|
77
|
+
}
|
|
78
78
|
function isFocusableElement(element) {
|
|
79
79
|
return isValidElement(element, getFocusableFilters(), false);
|
|
80
80
|
}
|
|
81
|
-
|
|
81
|
+
function isHidden(item) {
|
|
82
82
|
if ((item.element.hidden ?? false) || item.element instanceof HTMLInputElement && item.element.type === "hidden") {
|
|
83
83
|
return true;
|
|
84
84
|
}
|
|
@@ -93,17 +93,17 @@ var isHidden = function(item) {
|
|
|
93
93
|
}
|
|
94
94
|
const { height, width } = item.element.getBoundingClientRect();
|
|
95
95
|
return height === 0 && width === 0;
|
|
96
|
-
}
|
|
97
|
-
|
|
96
|
+
}
|
|
97
|
+
function isInert(item) {
|
|
98
98
|
return (item.element.inert ?? false) || /^(|true)$/i.test(item.element.getAttribute("inert")) || item.element.parentElement !== null && isInert({
|
|
99
99
|
element: item.element.parentElement,
|
|
100
100
|
tabIndex: -1
|
|
101
101
|
});
|
|
102
|
-
}
|
|
103
|
-
|
|
102
|
+
}
|
|
103
|
+
function isNotTabbable(item) {
|
|
104
104
|
return (item.tabIndex ?? -1) < 0;
|
|
105
|
-
}
|
|
106
|
-
|
|
105
|
+
}
|
|
106
|
+
function isNotTabbableRadio(item) {
|
|
107
107
|
if (!(item.element instanceof HTMLInputElement) || item.element.type !== "radio" || !item.element.name || item.element.checked) {
|
|
108
108
|
return false;
|
|
109
109
|
}
|
|
@@ -112,17 +112,17 @@ var isNotTabbableRadio = function(item) {
|
|
|
112
112
|
const radios = Array.from(parent.querySelectorAll(`input[type="radio"][name="${realName}"]`));
|
|
113
113
|
const checked = radios.find((radio) => radio.checked);
|
|
114
114
|
return checked !== undefined && checked !== item.element;
|
|
115
|
-
}
|
|
116
|
-
|
|
115
|
+
}
|
|
116
|
+
function isSummarised(item) {
|
|
117
117
|
return item.element instanceof HTMLDetailsElement && Array.from(item.element.children).some((child) => /^summary$/i.test(child.tagName));
|
|
118
|
-
}
|
|
118
|
+
}
|
|
119
119
|
function isTabbableElement(element) {
|
|
120
120
|
return isValidElement(element, getTabbableFilters(), true);
|
|
121
121
|
}
|
|
122
|
-
|
|
122
|
+
function isValidElement(element, filters, tabbable) {
|
|
123
123
|
const item = getItem(element, tabbable);
|
|
124
124
|
return !filters.some((filter) => filter(item));
|
|
125
|
-
}
|
|
125
|
+
}
|
|
126
126
|
var selector = [
|
|
127
127
|
'[contenteditable]:not([contenteditable="false"])',
|
|
128
128
|
"[tabindex]:not(slot)",
|
|
@@ -2,29 +2,29 @@
|
|
|
2
2
|
function getFocusableElements(parent) {
|
|
3
3
|
return getValidElements(parent, getFocusableFilters(), false);
|
|
4
4
|
}
|
|
5
|
-
|
|
5
|
+
function getFocusableFilters() {
|
|
6
6
|
return [isDisabled, isInert, isHidden, isSummarised];
|
|
7
|
-
}
|
|
8
|
-
|
|
7
|
+
}
|
|
8
|
+
function getItem(element, tabbable) {
|
|
9
9
|
return {
|
|
10
10
|
element,
|
|
11
11
|
tabIndex: tabbable ? getTabIndex(element) : -1
|
|
12
12
|
};
|
|
13
|
-
}
|
|
14
|
-
|
|
13
|
+
}
|
|
14
|
+
function getTabbableFilters() {
|
|
15
15
|
return [isNotTabbable, isNotTabbableRadio, ...getFocusableFilters()];
|
|
16
|
-
}
|
|
16
|
+
}
|
|
17
17
|
function getTabbableElements(parent) {
|
|
18
18
|
return getValidElements(parent, getTabbableFilters(), true);
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
function getTabIndex(element) {
|
|
21
21
|
const tabIndex = element?.tabIndex ?? -1;
|
|
22
22
|
if (tabIndex < 0 && (/^(audio|details|video)$/i.test(element.tagName) || isEditable(element)) && !hasTabIndex(element)) {
|
|
23
23
|
return 0;
|
|
24
24
|
}
|
|
25
25
|
return tabIndex;
|
|
26
|
-
}
|
|
27
|
-
|
|
26
|
+
}
|
|
27
|
+
function getValidElements(parent, filters, tabbable) {
|
|
28
28
|
const items = Array.from(parent.querySelectorAll(selector)).map((element) => getItem(element, tabbable)).filter((item) => !filters.some((filter) => filter(item)));
|
|
29
29
|
if (!tabbable) {
|
|
30
30
|
return items.map((item) => item.element);
|
|
@@ -44,17 +44,17 @@ var getValidElements = function(parent, filters, tabbable) {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
return [...indiced.flat(), ...zeroed];
|
|
47
|
-
}
|
|
48
|
-
|
|
47
|
+
}
|
|
48
|
+
function hasTabIndex(element) {
|
|
49
49
|
return !Number.isNaN(Number.parseInt(element.getAttribute("tabindex"), 10));
|
|
50
|
-
}
|
|
51
|
-
|
|
50
|
+
}
|
|
51
|
+
function isDisabled(item) {
|
|
52
52
|
if (/^(button|input|select|textarea)$/i.test(item.element.tagName) && isDisabledFromFieldset(item.element)) {
|
|
53
53
|
return true;
|
|
54
54
|
}
|
|
55
55
|
return (item.element.disabled ?? false) || item.element.getAttribute("aria-disabled") === "true";
|
|
56
|
-
}
|
|
57
|
-
|
|
56
|
+
}
|
|
57
|
+
function isDisabledFromFieldset(element) {
|
|
58
58
|
let parent = element.parentElement;
|
|
59
59
|
while (parent !== null) {
|
|
60
60
|
if (parent instanceof HTMLFieldSetElement && parent.disabled) {
|
|
@@ -71,14 +71,14 @@ var isDisabledFromFieldset = function(element) {
|
|
|
71
71
|
parent = parent.parentElement;
|
|
72
72
|
}
|
|
73
73
|
return false;
|
|
74
|
-
}
|
|
75
|
-
|
|
74
|
+
}
|
|
75
|
+
function isEditable(element) {
|
|
76
76
|
return /^(|true)$/i.test(element.getAttribute("contenteditable"));
|
|
77
|
-
}
|
|
77
|
+
}
|
|
78
78
|
function isFocusableElement(element) {
|
|
79
79
|
return isValidElement(element, getFocusableFilters(), false);
|
|
80
80
|
}
|
|
81
|
-
|
|
81
|
+
function isHidden(item) {
|
|
82
82
|
if ((item.element.hidden ?? false) || item.element instanceof HTMLInputElement && item.element.type === "hidden") {
|
|
83
83
|
return true;
|
|
84
84
|
}
|
|
@@ -93,17 +93,17 @@ var isHidden = function(item) {
|
|
|
93
93
|
}
|
|
94
94
|
const { height, width } = item.element.getBoundingClientRect();
|
|
95
95
|
return height === 0 && width === 0;
|
|
96
|
-
}
|
|
97
|
-
|
|
96
|
+
}
|
|
97
|
+
function isInert(item) {
|
|
98
98
|
return (item.element.inert ?? false) || /^(|true)$/i.test(item.element.getAttribute("inert")) || item.element.parentElement !== null && isInert({
|
|
99
99
|
element: item.element.parentElement,
|
|
100
100
|
tabIndex: -1
|
|
101
101
|
});
|
|
102
|
-
}
|
|
103
|
-
|
|
102
|
+
}
|
|
103
|
+
function isNotTabbable(item) {
|
|
104
104
|
return (item.tabIndex ?? -1) < 0;
|
|
105
|
-
}
|
|
106
|
-
|
|
105
|
+
}
|
|
106
|
+
function isNotTabbableRadio(item) {
|
|
107
107
|
if (!(item.element instanceof HTMLInputElement) || item.element.type !== "radio" || !item.element.name || item.element.checked) {
|
|
108
108
|
return false;
|
|
109
109
|
}
|
|
@@ -112,17 +112,17 @@ var isNotTabbableRadio = function(item) {
|
|
|
112
112
|
const radios = Array.from(parent.querySelectorAll(`input[type="radio"][name="${realName}"]`));
|
|
113
113
|
const checked = radios.find((radio) => radio.checked);
|
|
114
114
|
return checked !== undefined && checked !== item.element;
|
|
115
|
-
}
|
|
116
|
-
|
|
115
|
+
}
|
|
116
|
+
function isSummarised(item) {
|
|
117
117
|
return item.element instanceof HTMLDetailsElement && Array.from(item.element.children).some((child) => /^summary$/i.test(child.tagName));
|
|
118
|
-
}
|
|
118
|
+
}
|
|
119
119
|
function isTabbableElement(element) {
|
|
120
120
|
return isValidElement(element, getTabbableFilters(), true);
|
|
121
121
|
}
|
|
122
|
-
|
|
122
|
+
function isValidElement(element, filters, tabbable) {
|
|
123
123
|
const item = getItem(element, tabbable);
|
|
124
124
|
return !filters.some((filter) => filter(item));
|
|
125
|
-
}
|
|
125
|
+
}
|
|
126
126
|
var selector = [
|
|
127
127
|
'[contenteditable]:not([contenteditable="false"])',
|
|
128
128
|
"[tabindex]:not(slot)",
|
package/dist/js/element/index.js
CHANGED
|
@@ -18,7 +18,7 @@ function getTextDirection(element) {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
// src/js/element/closest.ts
|
|
21
|
-
|
|
21
|
+
function calculateDistance(origin, target) {
|
|
22
22
|
const comparison = origin.compareDocumentPosition(target);
|
|
23
23
|
const children = [...origin.parentElement?.children ?? []];
|
|
24
24
|
switch (true) {
|
|
@@ -31,7 +31,7 @@ var calculateDistance = function(origin, target) {
|
|
|
31
31
|
default:
|
|
32
32
|
return -1;
|
|
33
33
|
}
|
|
34
|
-
}
|
|
34
|
+
}
|
|
35
35
|
function closest(origin, selector, context) {
|
|
36
36
|
const elements = [...(context ?? document).querySelectorAll(selector)];
|
|
37
37
|
const { length } = elements;
|
|
@@ -56,7 +56,7 @@ function closest(origin, selector, context) {
|
|
|
56
56
|
}
|
|
57
57
|
return minimum == null ? [] : distances.filter((found) => found.distance === minimum).map((found) => found.element);
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
function traverse(from, to) {
|
|
60
60
|
const children = [...to.children];
|
|
61
61
|
if (children.includes(from)) {
|
|
62
62
|
return children.indexOf(from) + 1;
|
|
@@ -81,53 +81,55 @@ var traverse = function(from, to) {
|
|
|
81
81
|
parent = parent.parentElement;
|
|
82
82
|
}
|
|
83
83
|
return -1e6;
|
|
84
|
-
}
|
|
84
|
+
}
|
|
85
85
|
// src/js/string/index.ts
|
|
86
|
-
function getString(
|
|
87
|
-
if (typeof
|
|
88
|
-
return
|
|
86
|
+
function getString(value2) {
|
|
87
|
+
if (typeof value2 === "string") {
|
|
88
|
+
return value2;
|
|
89
89
|
}
|
|
90
|
-
if (typeof
|
|
91
|
-
return String(
|
|
90
|
+
if (typeof value2 !== "object" || value2 == null) {
|
|
91
|
+
return String(value2);
|
|
92
92
|
}
|
|
93
|
-
const valueOff =
|
|
93
|
+
const valueOff = value2.valueOf?.() ?? value2;
|
|
94
94
|
const asString = valueOff?.toString?.() ?? String(valueOff);
|
|
95
|
-
return asString.startsWith("[object ") ? JSON.stringify(
|
|
95
|
+
return asString.startsWith("[object ") ? JSON.stringify(value2) : asString;
|
|
96
96
|
}
|
|
97
|
-
function parse(
|
|
97
|
+
function parse(value2, reviver) {
|
|
98
98
|
try {
|
|
99
|
-
return JSON.parse(
|
|
99
|
+
return JSON.parse(value2, reviver);
|
|
100
100
|
} catch {
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
// src/js/is.ts
|
|
104
|
-
function isNullableOrWhitespace(
|
|
105
|
-
return
|
|
104
|
+
function isNullableOrWhitespace(value2) {
|
|
105
|
+
return value2 == null || /^\s*$/.test(getString(value2));
|
|
106
106
|
}
|
|
107
|
-
function isPlainObject(
|
|
108
|
-
if (typeof
|
|
107
|
+
function isPlainObject(value2) {
|
|
108
|
+
if (typeof value2 !== "object" || value2 === null) {
|
|
109
109
|
return false;
|
|
110
110
|
}
|
|
111
|
-
const prototype = Object.getPrototypeOf(
|
|
112
|
-
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in
|
|
111
|
+
const prototype = Object.getPrototypeOf(value2);
|
|
112
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value2) && !(Symbol.iterator in value2);
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
// src/js/internal/element-value.ts
|
|
116
116
|
function setElementValues(element, first, second, callback) {
|
|
117
117
|
if (isPlainObject(first)) {
|
|
118
118
|
const entries = Object.entries(first);
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
const { length } = entries;
|
|
120
|
+
for (let index = 0;index < length; index += 1) {
|
|
121
|
+
const [key, value2] = entries[index];
|
|
122
|
+
callback(element, key, value2);
|
|
121
123
|
}
|
|
122
124
|
} else if (first != null) {
|
|
123
125
|
callback(element, first, second);
|
|
124
126
|
}
|
|
125
127
|
}
|
|
126
|
-
function updateElementValue(element, key,
|
|
127
|
-
if (isNullableOrWhitespace(
|
|
128
|
+
function updateElementValue(element, key, value2, set3, remove, json) {
|
|
129
|
+
if (isNullableOrWhitespace(value2)) {
|
|
128
130
|
remove.call(element, key);
|
|
129
131
|
} else {
|
|
130
|
-
|
|
132
|
+
set3.call(element, key, json ? JSON.stringify(value2) : String(value2));
|
|
131
133
|
}
|
|
132
134
|
}
|
|
133
135
|
|
|
@@ -137,44 +139,46 @@ function getData(element, keys) {
|
|
|
137
139
|
return getDataValue(element, keys);
|
|
138
140
|
}
|
|
139
141
|
const data = {};
|
|
140
|
-
|
|
142
|
+
const { length } = keys;
|
|
143
|
+
for (let index = 0;index < length; index += 1) {
|
|
144
|
+
const key = keys[index];
|
|
141
145
|
data[key] = getDataValue(element, key);
|
|
142
146
|
}
|
|
143
147
|
return data;
|
|
144
148
|
}
|
|
145
|
-
|
|
146
|
-
const
|
|
147
|
-
if (
|
|
148
|
-
return parse(
|
|
149
|
+
function getDataValue(element, key) {
|
|
150
|
+
const value2 = element.dataset[key];
|
|
151
|
+
if (value2 != null) {
|
|
152
|
+
return parse(value2);
|
|
149
153
|
}
|
|
150
|
-
}
|
|
154
|
+
}
|
|
151
155
|
function setData(element, first, second) {
|
|
152
156
|
setElementValues(element, first, second, updateDataAttribute);
|
|
153
157
|
}
|
|
154
|
-
|
|
155
|
-
updateElementValue(element, `data-${key}`,
|
|
156
|
-
}
|
|
158
|
+
function updateDataAttribute(element, key, value2) {
|
|
159
|
+
updateElementValue(element, `data-${key}`, value2, element.setAttribute, element.removeAttribute, true);
|
|
160
|
+
}
|
|
157
161
|
// src/js/element/find.ts
|
|
158
162
|
function findElement(selector, context) {
|
|
159
163
|
return findElementOrElements(selector, context, true);
|
|
160
164
|
}
|
|
161
|
-
|
|
165
|
+
function findElementOrElements(selector, context, single) {
|
|
162
166
|
const callback = single ? document.querySelector : document.querySelectorAll;
|
|
163
167
|
const contexts = context == null ? [document] : findElementOrElements(context, undefined, false);
|
|
164
168
|
const result = [];
|
|
165
169
|
if (typeof selector === "string") {
|
|
166
170
|
const { length: length2 } = contexts;
|
|
167
171
|
for (let index = 0;index < length2; index += 1) {
|
|
168
|
-
const
|
|
172
|
+
const value2 = callback.call(contexts[index], selector);
|
|
169
173
|
if (single) {
|
|
170
|
-
if (
|
|
174
|
+
if (value2 == null) {
|
|
171
175
|
continue;
|
|
172
176
|
}
|
|
173
|
-
return
|
|
177
|
+
return value2;
|
|
174
178
|
}
|
|
175
|
-
result.push(...Array.from(
|
|
179
|
+
result.push(...Array.from(value2));
|
|
176
180
|
}
|
|
177
|
-
return single ? undefined : result.filter((
|
|
181
|
+
return single ? undefined : result.filter((value2, index, array2) => array2.indexOf(value2) === index);
|
|
178
182
|
}
|
|
179
183
|
const nodes = Array.isArray(selector) ? selector : selector instanceof NodeList ? Array.from(selector) : [selector];
|
|
180
184
|
const { length } = nodes;
|
|
@@ -186,7 +190,7 @@ var findElementOrElements = function(selector, context, single) {
|
|
|
186
190
|
}
|
|
187
191
|
}
|
|
188
192
|
return result;
|
|
189
|
-
}
|
|
193
|
+
}
|
|
190
194
|
function findElements(selector, context) {
|
|
191
195
|
return findElementOrElements(selector, context, false);
|
|
192
196
|
}
|
|
@@ -216,13 +220,13 @@ function findParentElement(origin, selector) {
|
|
|
216
220
|
function setStyles(element, first, second) {
|
|
217
221
|
setElementValues(element, first, second, updateStyleProperty);
|
|
218
222
|
}
|
|
219
|
-
|
|
220
|
-
updateElementValue(element, key,
|
|
221
|
-
this.style[key2] =
|
|
223
|
+
function updateStyleProperty(element, key, value2) {
|
|
224
|
+
updateElementValue(element, key, value2, function(key2, value3) {
|
|
225
|
+
this.style[key2] = value3;
|
|
222
226
|
}, function(key2) {
|
|
223
227
|
this.style[key2] = "";
|
|
224
228
|
}, false);
|
|
225
|
-
}
|
|
229
|
+
}
|
|
226
230
|
export {
|
|
227
231
|
setStyles,
|
|
228
232
|
setData,
|
|
@@ -3,13 +3,13 @@ import {setElementValues, updateElementValue} from "../internal/element-value";
|
|
|
3
3
|
function setStyles(element, first, second) {
|
|
4
4
|
setElementValues(element, first, second, updateStyleProperty);
|
|
5
5
|
}
|
|
6
|
-
|
|
6
|
+
function updateStyleProperty(element, key, value) {
|
|
7
7
|
updateElementValue(element, key, value, function(key2, value2) {
|
|
8
8
|
this.style[key2] = value2;
|
|
9
9
|
}, function(key2) {
|
|
10
10
|
this.style[key2] = "";
|
|
11
11
|
}, false);
|
|
12
|
-
}
|
|
12
|
+
}
|
|
13
13
|
export {
|
|
14
14
|
setStyles
|
|
15
15
|
};
|