@oscarpalmer/toretto 0.12.1 → 0.14.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/attribute.js +79 -53
- package/dist/attribute.mjs +68 -43
- package/dist/data.js +20 -19
- package/dist/data.mjs +2 -2
- package/dist/event.js +13 -17
- package/dist/event.mjs +6 -14
- package/dist/find.js +3 -2
- package/dist/find.mjs +3 -2
- package/dist/focusable.js +20 -20
- package/dist/focusable.mjs +20 -20
- package/dist/html.js +32 -32
- package/dist/html.mjs +4 -4
- package/dist/index.js +163 -127
- package/dist/index.mjs +1 -0
- package/dist/internal/element-value.js +19 -18
- package/dist/internal/element-value.mjs +1 -1
- package/dist/internal/get-value.js +7 -0
- package/dist/internal/get-value.mjs +7 -0
- package/dist/is.js +15 -0
- package/dist/is.mjs +15 -0
- package/dist/sanitise.js +20 -20
- package/dist/sanitise.mjs +8 -8
- package/dist/style.js +24 -23
- package/dist/style.mjs +1 -1
- package/package.json +22 -8
- package/src/attribute.ts +127 -34
- package/src/data.ts +9 -8
- package/src/event.ts +14 -29
- package/src/find.ts +8 -3
- package/src/focusable.ts +1 -4
- package/src/html.ts +3 -3
- package/src/index.ts +1 -1
- package/src/internal/element-value.ts +4 -3
- package/src/internal/get-value.ts +3 -0
- package/src/is.ts +49 -0
- package/src/models.ts +10 -1
- package/src/style.ts +9 -9
- package/types/attribute.d.ts +23 -7
- package/types/data.d.ts +5 -4
- package/types/event.d.ts +4 -9
- package/types/find.d.ts +4 -0
- package/types/html.d.ts +3 -3
- package/types/index.d.cts +69 -25
- package/types/index.d.ts +1 -0
- package/types/internal/element-value.d.ts +3 -2
- package/types/internal/get-value.d.ts +1 -0
- package/types/is.d.ts +22 -0
- package/types/models.d.ts +7 -1
- package/types/style.d.ts +5 -5
package/dist/attribute.js
CHANGED
|
@@ -1,25 +1,55 @@
|
|
|
1
1
|
// node_modules/@oscarpalmer/atoms/dist/js/string/index.mjs
|
|
2
|
-
function getString(
|
|
3
|
-
if (typeof
|
|
4
|
-
return
|
|
2
|
+
function getString(value) {
|
|
3
|
+
if (typeof value === "string") {
|
|
4
|
+
return value;
|
|
5
5
|
}
|
|
6
|
-
if (typeof
|
|
7
|
-
return String(
|
|
6
|
+
if (typeof value !== "object" || value == null) {
|
|
7
|
+
return String(value);
|
|
8
8
|
}
|
|
9
|
-
const valueOff =
|
|
9
|
+
const valueOff = value.valueOf?.() ?? value;
|
|
10
10
|
const asString = valueOff?.toString?.() ?? String(valueOff);
|
|
11
|
-
return asString.startsWith("[object ") ? JSON.stringify(
|
|
11
|
+
return asString.startsWith("[object ") ? JSON.stringify(value) : asString;
|
|
12
12
|
}
|
|
13
|
+
|
|
13
14
|
// node_modules/@oscarpalmer/atoms/dist/js/is.mjs
|
|
14
|
-
function isPlainObject(
|
|
15
|
-
if (typeof
|
|
15
|
+
function isPlainObject(value) {
|
|
16
|
+
if (typeof value !== "object" || value === null) {
|
|
16
17
|
return false;
|
|
17
18
|
}
|
|
18
|
-
const prototype = Object.getPrototypeOf(
|
|
19
|
-
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in
|
|
19
|
+
const prototype = Object.getPrototypeOf(value);
|
|
20
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
// src/attribute.ts
|
|
24
|
+
var booleanAttributes = Object.freeze([
|
|
25
|
+
"async",
|
|
26
|
+
"autofocus",
|
|
27
|
+
"autoplay",
|
|
28
|
+
"checked",
|
|
29
|
+
"controls",
|
|
30
|
+
"default",
|
|
31
|
+
"defer",
|
|
32
|
+
"disabled",
|
|
33
|
+
"formnovalidate",
|
|
34
|
+
"hidden",
|
|
35
|
+
"inert",
|
|
36
|
+
"ismap",
|
|
37
|
+
"itemscope",
|
|
38
|
+
"loop",
|
|
39
|
+
"multiple",
|
|
40
|
+
"muted",
|
|
41
|
+
"nomodule",
|
|
42
|
+
"novalidate",
|
|
43
|
+
"open",
|
|
44
|
+
"playsinline",
|
|
45
|
+
"readonly",
|
|
46
|
+
"required",
|
|
47
|
+
"reversed",
|
|
48
|
+
"selected"
|
|
49
|
+
]);
|
|
50
|
+
var onPrefix = /^on/i;
|
|
51
|
+
var sourcePrefix = /^(href|src|xlink:href)$/i;
|
|
52
|
+
var valuePrefix = /(data:text\/html|javascript:)/i;
|
|
23
53
|
function isBadAttribute(attribute) {
|
|
24
54
|
return onPrefix.test(attribute.name) || sourcePrefix.test(attribute.name) && valuePrefix.test(attribute.value);
|
|
25
55
|
}
|
|
@@ -37,62 +67,58 @@ function isInvalidBooleanAttribute(attribute) {
|
|
|
37
67
|
return !(normalised.length === 0 || normalised === attribute.name || attribute.name === "hidden" && normalised === "until-found");
|
|
38
68
|
}
|
|
39
69
|
function setAttribute(element, first, second) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
70
|
+
updateValue(element, first, second, updateAttribute);
|
|
71
|
+
}
|
|
72
|
+
function setAttributes(element, attributes) {
|
|
73
|
+
updateValues(element, attributes);
|
|
74
|
+
}
|
|
75
|
+
function setProperty(element, first, second) {
|
|
76
|
+
updateValue(element, first, second, updateProperty);
|
|
77
|
+
}
|
|
78
|
+
function setProperties(element, properties) {
|
|
79
|
+
updateValues(element, properties, updateProperty);
|
|
45
80
|
}
|
|
46
|
-
function
|
|
47
|
-
|
|
81
|
+
function updateAttribute(element, name, value) {
|
|
82
|
+
const normalised = name.toLowerCase();
|
|
83
|
+
if (booleanAttributes.includes(normalised)) {
|
|
84
|
+
updateProperty(element, name, value, false);
|
|
85
|
+
} else if (value == null) {
|
|
48
86
|
element.removeAttribute(name);
|
|
49
87
|
} else {
|
|
50
|
-
element.setAttribute(name, typeof
|
|
88
|
+
element.setAttribute(name, typeof value === "string" ? value : getString(value));
|
|
51
89
|
}
|
|
52
90
|
}
|
|
53
|
-
function
|
|
54
|
-
const
|
|
55
|
-
|
|
91
|
+
function updateProperty(element, name, value, validate) {
|
|
92
|
+
const actual = validate ?? true ? name.toLowerCase() : name;
|
|
93
|
+
if (actual === "hidden") {
|
|
94
|
+
element.hidden = typeof value === "string" && value.toLowerCase() === "until-found" ? "until-found" : value === "" || value === true;
|
|
95
|
+
} else {
|
|
96
|
+
element[actual] = value === "" || typeof value === "string" && value.toLowerCase() === actual || value === true;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function updateValue(element, first, second, callback) {
|
|
100
|
+
if (isPlainObject(first) && typeof first?.name === "string") {
|
|
101
|
+
callback(element, first.name, first.value);
|
|
102
|
+
} else if (typeof first === "string") {
|
|
103
|
+
callback(element, first, second);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function updateValues(element, values, callback) {
|
|
107
|
+
const isArray = Array.isArray(values);
|
|
108
|
+
const entries = Object.entries(values);
|
|
56
109
|
const { length } = entries;
|
|
57
110
|
for (let index = 0;index < length; index += 1) {
|
|
58
111
|
const entry = entries[index];
|
|
59
112
|
if (isArray) {
|
|
60
|
-
|
|
113
|
+
(callback ?? updateAttribute)(element, entry[1].name, entry[1].value);
|
|
61
114
|
} else {
|
|
62
|
-
|
|
115
|
+
(callback ?? updateAttribute)(element, entry[0], entry[1]);
|
|
63
116
|
}
|
|
64
117
|
}
|
|
65
118
|
}
|
|
66
|
-
var booleanAttributes = Object.freeze([
|
|
67
|
-
"async",
|
|
68
|
-
"autofocus",
|
|
69
|
-
"autoplay",
|
|
70
|
-
"checked",
|
|
71
|
-
"controls",
|
|
72
|
-
"default",
|
|
73
|
-
"defer",
|
|
74
|
-
"disabled",
|
|
75
|
-
"formnovalidate",
|
|
76
|
-
"hidden",
|
|
77
|
-
"inert",
|
|
78
|
-
"ismap",
|
|
79
|
-
"itemscope",
|
|
80
|
-
"loop",
|
|
81
|
-
"multiple",
|
|
82
|
-
"muted",
|
|
83
|
-
"nomodule",
|
|
84
|
-
"novalidate",
|
|
85
|
-
"open",
|
|
86
|
-
"playsinline",
|
|
87
|
-
"readonly",
|
|
88
|
-
"required",
|
|
89
|
-
"reversed",
|
|
90
|
-
"selected"
|
|
91
|
-
]);
|
|
92
|
-
var onPrefix = /^on/i;
|
|
93
|
-
var sourcePrefix = /^(href|src|xlink:href)$/i;
|
|
94
|
-
var valuePrefix = /(data:text\/html|javascript:)/i;
|
|
95
119
|
export {
|
|
120
|
+
setProperty,
|
|
121
|
+
setProperties,
|
|
96
122
|
setAttributes,
|
|
97
123
|
setAttribute,
|
|
98
124
|
isInvalidBooleanAttribute,
|
package/dist/attribute.mjs
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
// src/attribute.ts
|
|
2
|
-
import {isPlainObject} from "@oscarpalmer/atoms/is";
|
|
3
|
-
import {getString} from "@oscarpalmer/atoms/string";
|
|
2
|
+
import { isPlainObject } from "@oscarpalmer/atoms/is";
|
|
3
|
+
import { getString } from "@oscarpalmer/atoms/string";
|
|
4
|
+
var booleanAttributes = Object.freeze([
|
|
5
|
+
"async",
|
|
6
|
+
"autofocus",
|
|
7
|
+
"autoplay",
|
|
8
|
+
"checked",
|
|
9
|
+
"controls",
|
|
10
|
+
"default",
|
|
11
|
+
"defer",
|
|
12
|
+
"disabled",
|
|
13
|
+
"formnovalidate",
|
|
14
|
+
"hidden",
|
|
15
|
+
"inert",
|
|
16
|
+
"ismap",
|
|
17
|
+
"itemscope",
|
|
18
|
+
"loop",
|
|
19
|
+
"multiple",
|
|
20
|
+
"muted",
|
|
21
|
+
"nomodule",
|
|
22
|
+
"novalidate",
|
|
23
|
+
"open",
|
|
24
|
+
"playsinline",
|
|
25
|
+
"readonly",
|
|
26
|
+
"required",
|
|
27
|
+
"reversed",
|
|
28
|
+
"selected"
|
|
29
|
+
]);
|
|
30
|
+
var onPrefix = /^on/i;
|
|
31
|
+
var sourcePrefix = /^(href|src|xlink:href)$/i;
|
|
32
|
+
var valuePrefix = /(data:text\/html|javascript:)/i;
|
|
4
33
|
function isBadAttribute(attribute) {
|
|
5
34
|
return onPrefix.test(attribute.name) || sourcePrefix.test(attribute.name) && valuePrefix.test(attribute.value);
|
|
6
35
|
}
|
|
@@ -18,62 +47,58 @@ function isInvalidBooleanAttribute(attribute) {
|
|
|
18
47
|
return !(normalised.length === 0 || normalised === attribute.name || attribute.name === "hidden" && normalised === "until-found");
|
|
19
48
|
}
|
|
20
49
|
function setAttribute(element, first, second) {
|
|
21
|
-
|
|
22
|
-
setAttributeValue(element, first.name, first.value);
|
|
23
|
-
} else if (typeof first === "string") {
|
|
24
|
-
setAttributeValue(element, first, second);
|
|
25
|
-
}
|
|
50
|
+
updateValue(element, first, second, updateAttribute);
|
|
26
51
|
}
|
|
27
|
-
function
|
|
28
|
-
|
|
52
|
+
function setAttributes(element, attributes) {
|
|
53
|
+
updateValues(element, attributes);
|
|
54
|
+
}
|
|
55
|
+
function setProperty(element, first, second) {
|
|
56
|
+
updateValue(element, first, second, updateProperty);
|
|
57
|
+
}
|
|
58
|
+
function setProperties(element, properties) {
|
|
59
|
+
updateValues(element, properties, updateProperty);
|
|
60
|
+
}
|
|
61
|
+
function updateAttribute(element, name, value) {
|
|
62
|
+
const normalised = name.toLowerCase();
|
|
63
|
+
if (booleanAttributes.includes(normalised)) {
|
|
64
|
+
updateProperty(element, name, value, false);
|
|
65
|
+
} else if (value == null) {
|
|
29
66
|
element.removeAttribute(name);
|
|
30
67
|
} else {
|
|
31
68
|
element.setAttribute(name, typeof value === "string" ? value : getString(value));
|
|
32
69
|
}
|
|
33
70
|
}
|
|
34
|
-
function
|
|
35
|
-
const
|
|
36
|
-
|
|
71
|
+
function updateProperty(element, name, value, validate) {
|
|
72
|
+
const actual = validate ?? true ? name.toLowerCase() : name;
|
|
73
|
+
if (actual === "hidden") {
|
|
74
|
+
element.hidden = typeof value === "string" && value.toLowerCase() === "until-found" ? "until-found" : value === "" || value === true;
|
|
75
|
+
} else {
|
|
76
|
+
element[actual] = value === "" || typeof value === "string" && value.toLowerCase() === actual || value === true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function updateValue(element, first, second, callback) {
|
|
80
|
+
if (isPlainObject(first) && typeof first?.name === "string") {
|
|
81
|
+
callback(element, first.name, first.value);
|
|
82
|
+
} else if (typeof first === "string") {
|
|
83
|
+
callback(element, first, second);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function updateValues(element, values, callback) {
|
|
87
|
+
const isArray = Array.isArray(values);
|
|
88
|
+
const entries = Object.entries(values);
|
|
37
89
|
const { length } = entries;
|
|
38
90
|
for (let index = 0;index < length; index += 1) {
|
|
39
91
|
const entry = entries[index];
|
|
40
92
|
if (isArray) {
|
|
41
|
-
|
|
93
|
+
(callback ?? updateAttribute)(element, entry[1].name, entry[1].value);
|
|
42
94
|
} else {
|
|
43
|
-
|
|
95
|
+
(callback ?? updateAttribute)(element, entry[0], entry[1]);
|
|
44
96
|
}
|
|
45
97
|
}
|
|
46
98
|
}
|
|
47
|
-
var booleanAttributes = Object.freeze([
|
|
48
|
-
"async",
|
|
49
|
-
"autofocus",
|
|
50
|
-
"autoplay",
|
|
51
|
-
"checked",
|
|
52
|
-
"controls",
|
|
53
|
-
"default",
|
|
54
|
-
"defer",
|
|
55
|
-
"disabled",
|
|
56
|
-
"formnovalidate",
|
|
57
|
-
"hidden",
|
|
58
|
-
"inert",
|
|
59
|
-
"ismap",
|
|
60
|
-
"itemscope",
|
|
61
|
-
"loop",
|
|
62
|
-
"multiple",
|
|
63
|
-
"muted",
|
|
64
|
-
"nomodule",
|
|
65
|
-
"novalidate",
|
|
66
|
-
"open",
|
|
67
|
-
"playsinline",
|
|
68
|
-
"readonly",
|
|
69
|
-
"required",
|
|
70
|
-
"reversed",
|
|
71
|
-
"selected"
|
|
72
|
-
]);
|
|
73
|
-
var onPrefix = /^on/i;
|
|
74
|
-
var sourcePrefix = /^(href|src|xlink:href)$/i;
|
|
75
|
-
var valuePrefix = /(data:text\/html|javascript:)/i;
|
|
76
99
|
export {
|
|
100
|
+
setProperty,
|
|
101
|
+
setProperties,
|
|
77
102
|
setAttributes,
|
|
78
103
|
setAttribute,
|
|
79
104
|
isInvalidBooleanAttribute,
|
package/dist/data.js
CHANGED
|
@@ -10,41 +10,42 @@ function isPlainObject(value) {
|
|
|
10
10
|
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
11
11
|
}
|
|
12
12
|
// node_modules/@oscarpalmer/atoms/dist/js/string/index.mjs
|
|
13
|
-
function getString(
|
|
14
|
-
if (typeof
|
|
15
|
-
return
|
|
13
|
+
function getString(value) {
|
|
14
|
+
if (typeof value === "string") {
|
|
15
|
+
return value;
|
|
16
16
|
}
|
|
17
|
-
if (typeof
|
|
18
|
-
return String(
|
|
17
|
+
if (typeof value !== "object" || value == null) {
|
|
18
|
+
return String(value);
|
|
19
19
|
}
|
|
20
|
-
const valueOff =
|
|
20
|
+
const valueOff = value.valueOf?.() ?? value;
|
|
21
21
|
const asString = valueOff?.toString?.() ?? String(valueOff);
|
|
22
|
-
return asString.startsWith("[object ") ? JSON.stringify(
|
|
22
|
+
return asString.startsWith("[object ") ? JSON.stringify(value) : asString;
|
|
23
23
|
}
|
|
24
|
-
function parse(
|
|
24
|
+
function parse(value, reviver) {
|
|
25
25
|
try {
|
|
26
|
-
return JSON.parse(
|
|
26
|
+
return JSON.parse(value, reviver);
|
|
27
27
|
} catch {
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
+
|
|
30
31
|
// src/internal/element-value.ts
|
|
31
32
|
function setElementValues(element, first, second, callback) {
|
|
32
33
|
if (isPlainObject(first)) {
|
|
33
34
|
const entries = Object.entries(first);
|
|
34
35
|
const { length } = entries;
|
|
35
36
|
for (let index = 0;index < length; index += 1) {
|
|
36
|
-
const [key,
|
|
37
|
-
callback(element, key,
|
|
37
|
+
const [key, value] = entries[index];
|
|
38
|
+
callback(element, key, value);
|
|
38
39
|
}
|
|
39
40
|
} else if (first != null) {
|
|
40
41
|
callback(element, first, second);
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
|
-
function updateElementValue(element, key,
|
|
44
|
-
if (isNullableOrWhitespace(
|
|
44
|
+
function updateElementValue(element, key, value, set2, remove, json) {
|
|
45
|
+
if (isNullableOrWhitespace(value)) {
|
|
45
46
|
remove.call(element, key);
|
|
46
47
|
} else {
|
|
47
|
-
|
|
48
|
+
set2.call(element, key, json ? JSON.stringify(value) : String(value));
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
|
|
@@ -62,16 +63,16 @@ function getData(element, keys) {
|
|
|
62
63
|
return data;
|
|
63
64
|
}
|
|
64
65
|
function getDataValue(element, key) {
|
|
65
|
-
const
|
|
66
|
-
if (
|
|
67
|
-
return parse(
|
|
66
|
+
const value = element.dataset[key];
|
|
67
|
+
if (value != null) {
|
|
68
|
+
return parse(value);
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
function setData(element, first, second) {
|
|
71
72
|
setElementValues(element, first, second, updateDataAttribute);
|
|
72
73
|
}
|
|
73
|
-
function updateDataAttribute(element, key,
|
|
74
|
-
updateElementValue(element, `data-${key}`,
|
|
74
|
+
function updateDataAttribute(element, key, value) {
|
|
75
|
+
updateElementValue(element, `data-${key}`, value, element.setAttribute, element.removeAttribute, true);
|
|
75
76
|
}
|
|
76
77
|
export {
|
|
77
78
|
setData,
|
package/dist/data.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/data.ts
|
|
2
|
-
import {parse} from "@oscarpalmer/atoms/string";
|
|
3
|
-
import {setElementValues, updateElementValue} from "./internal/element-value";
|
|
2
|
+
import { parse } from "@oscarpalmer/atoms/string";
|
|
3
|
+
import { setElementValues, updateElementValue } from "./internal/element-value";
|
|
4
4
|
function getData(element, keys) {
|
|
5
5
|
if (typeof keys === "string") {
|
|
6
6
|
return getDataValue(element, keys);
|
package/dist/event.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
// node_modules/@oscarpalmer/atoms/dist/js/is.mjs
|
|
2
|
-
function isPlainObject(
|
|
3
|
-
if (typeof
|
|
2
|
+
function isPlainObject(value) {
|
|
3
|
+
if (typeof value !== "object" || value === null) {
|
|
4
4
|
return false;
|
|
5
5
|
}
|
|
6
|
-
const prototype = Object.getPrototypeOf(
|
|
7
|
-
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in
|
|
6
|
+
const prototype = Object.getPrototypeOf(value);
|
|
7
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// src/internal/get-value.ts
|
|
11
|
+
function getBoolean(value, defaultValue) {
|
|
12
|
+
return typeof value === "boolean" ? value : defaultValue ?? false;
|
|
8
13
|
}
|
|
9
14
|
|
|
10
15
|
// src/event.ts
|
|
@@ -26,25 +31,16 @@ function createEvent(type, options) {
|
|
|
26
31
|
return new Event(type, createDispatchOptions(hasOptions ? options : {}));
|
|
27
32
|
}
|
|
28
33
|
function createEventOptions(options) {
|
|
29
|
-
if (isPlainObject(options)) {
|
|
30
|
-
return {
|
|
31
|
-
capture: getBoolean(options.capture),
|
|
32
|
-
once: getBoolean(options.once),
|
|
33
|
-
passive: getBoolean(options.passive, true)
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
34
|
return {
|
|
37
|
-
capture: getBoolean(options),
|
|
38
|
-
once:
|
|
39
|
-
passive: true
|
|
35
|
+
capture: getBoolean(options?.capture),
|
|
36
|
+
once: getBoolean(options?.once),
|
|
37
|
+
passive: getBoolean(options?.passive, true),
|
|
38
|
+
signal: options?.signal
|
|
40
39
|
};
|
|
41
40
|
}
|
|
42
41
|
function dispatch(target, type, options) {
|
|
43
42
|
target.dispatchEvent(createEvent(type, options));
|
|
44
43
|
}
|
|
45
|
-
function getBoolean(value2, defaultValue) {
|
|
46
|
-
return typeof value2 === "boolean" ? value2 : defaultValue ?? false;
|
|
47
|
-
}
|
|
48
44
|
function getPosition(event) {
|
|
49
45
|
let x;
|
|
50
46
|
let y;
|
package/dist/event.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/event.ts
|
|
2
|
-
import {isPlainObject} from "@oscarpalmer/atoms/is";
|
|
2
|
+
import { isPlainObject } from "@oscarpalmer/atoms/is";
|
|
3
|
+
import { getBoolean } from "./internal/get-value";
|
|
3
4
|
function createDispatchOptions(options) {
|
|
4
5
|
return {
|
|
5
6
|
bubbles: getBoolean(options?.bubbles),
|
|
@@ -18,25 +19,16 @@ function createEvent(type, options) {
|
|
|
18
19
|
return new Event(type, createDispatchOptions(hasOptions ? options : {}));
|
|
19
20
|
}
|
|
20
21
|
function createEventOptions(options) {
|
|
21
|
-
if (isPlainObject(options)) {
|
|
22
|
-
return {
|
|
23
|
-
capture: getBoolean(options.capture),
|
|
24
|
-
once: getBoolean(options.once),
|
|
25
|
-
passive: getBoolean(options.passive, true)
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
22
|
return {
|
|
29
|
-
capture: getBoolean(options),
|
|
30
|
-
once:
|
|
31
|
-
passive: true
|
|
23
|
+
capture: getBoolean(options?.capture),
|
|
24
|
+
once: getBoolean(options?.once),
|
|
25
|
+
passive: getBoolean(options?.passive, true),
|
|
26
|
+
signal: options?.signal
|
|
32
27
|
};
|
|
33
28
|
}
|
|
34
29
|
function dispatch(target, type, options) {
|
|
35
30
|
target.dispatchEvent(createEvent(type, options));
|
|
36
31
|
}
|
|
37
|
-
function getBoolean(value, defaultValue) {
|
|
38
|
-
return typeof value === "boolean" ? value : defaultValue ?? false;
|
|
39
|
-
}
|
|
40
32
|
function getPosition(event) {
|
|
41
33
|
let x;
|
|
42
34
|
let y;
|
package/dist/find.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/find.ts
|
|
2
|
-
function
|
|
2
|
+
function getDistanceBetweenElements(origin, target) {
|
|
3
3
|
if (origin === target || origin.parentElement === target) {
|
|
4
4
|
return 0;
|
|
5
5
|
}
|
|
@@ -86,7 +86,7 @@ function findRelatives(origin, selector, context) {
|
|
|
86
86
|
let minimum = null;
|
|
87
87
|
for (let index = 0;index < length; index += 1) {
|
|
88
88
|
const element = elements[index];
|
|
89
|
-
const distance =
|
|
89
|
+
const distance = getDistanceBetweenElements(origin, element);
|
|
90
90
|
if (distance < 0) {
|
|
91
91
|
continue;
|
|
92
92
|
}
|
|
@@ -144,6 +144,7 @@ function traverse(from, to) {
|
|
|
144
144
|
}
|
|
145
145
|
export {
|
|
146
146
|
getElementUnderPointer,
|
|
147
|
+
getDistanceBetweenElements,
|
|
147
148
|
findRelatives,
|
|
148
149
|
findElements,
|
|
149
150
|
findElement,
|
package/dist/find.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/find.ts
|
|
2
|
-
function
|
|
2
|
+
function getDistanceBetweenElements(origin, target) {
|
|
3
3
|
if (origin === target || origin.parentElement === target) {
|
|
4
4
|
return 0;
|
|
5
5
|
}
|
|
@@ -86,7 +86,7 @@ function findRelatives(origin, selector, context) {
|
|
|
86
86
|
let minimum = null;
|
|
87
87
|
for (let index = 0;index < length; index += 1) {
|
|
88
88
|
const element = elements[index];
|
|
89
|
-
const distance =
|
|
89
|
+
const distance = getDistanceBetweenElements(origin, element);
|
|
90
90
|
if (distance < 0) {
|
|
91
91
|
continue;
|
|
92
92
|
}
|
|
@@ -144,6 +144,7 @@ function traverse(from, to) {
|
|
|
144
144
|
}
|
|
145
145
|
export {
|
|
146
146
|
getElementUnderPointer,
|
|
147
|
+
getDistanceBetweenElements,
|
|
147
148
|
findRelatives,
|
|
148
149
|
findElements,
|
|
149
150
|
findElement,
|
package/dist/focusable.js
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
// src/focusable.ts
|
|
2
|
+
var focusableFilters = [isDisabled, isInert, isHidden, isSummarised];
|
|
3
|
+
var selector = [
|
|
4
|
+
'[contenteditable]:not([contenteditable="false"])',
|
|
5
|
+
"[tabindex]:not(slot)",
|
|
6
|
+
"a[href]",
|
|
7
|
+
"audio[controls]",
|
|
8
|
+
"button",
|
|
9
|
+
"details",
|
|
10
|
+
"details > summary:first-of-type",
|
|
11
|
+
"input",
|
|
12
|
+
"select",
|
|
13
|
+
"textarea",
|
|
14
|
+
"video[controls]"
|
|
15
|
+
].map((selector2) => `${selector2}:not([inert])`).join(",");
|
|
16
|
+
var tabbableFilters = [
|
|
17
|
+
isNotTabbable,
|
|
18
|
+
isNotTabbableRadio,
|
|
19
|
+
...focusableFilters
|
|
20
|
+
];
|
|
2
21
|
function getFocusable(parent) {
|
|
3
22
|
return getValidElements(parent, focusableFilters, false);
|
|
4
23
|
}
|
|
@@ -54,7 +73,7 @@ function isDisabled(item) {
|
|
|
54
73
|
if (/^(button|input|select|textarea)$/i.test(item.element.tagName) && isDisabledFromFieldset(item.element)) {
|
|
55
74
|
return true;
|
|
56
75
|
}
|
|
57
|
-
return
|
|
76
|
+
return item.element.disabled ?? false;
|
|
58
77
|
}
|
|
59
78
|
function isDisabledFromFieldset(element) {
|
|
60
79
|
let parent = element.parentElement;
|
|
@@ -125,25 +144,6 @@ function isValidElement(element, filters, tabbable) {
|
|
|
125
144
|
const item = getItem(element, tabbable);
|
|
126
145
|
return !filters.some((filter) => filter(item));
|
|
127
146
|
}
|
|
128
|
-
var focusableFilters = [isDisabled, isInert, isHidden, isSummarised];
|
|
129
|
-
var selector = [
|
|
130
|
-
'[contenteditable]:not([contenteditable="false"])',
|
|
131
|
-
"[tabindex]:not(slot)",
|
|
132
|
-
"a[href]",
|
|
133
|
-
"audio[controls]",
|
|
134
|
-
"button",
|
|
135
|
-
"details",
|
|
136
|
-
"details > summary:first-of-type",
|
|
137
|
-
"input",
|
|
138
|
-
"select",
|
|
139
|
-
"textarea",
|
|
140
|
-
"video[controls]"
|
|
141
|
-
].map((selector2) => `${selector2}:not([inert])`).join(",");
|
|
142
|
-
var tabbableFilters = [
|
|
143
|
-
isNotTabbable,
|
|
144
|
-
isNotTabbableRadio,
|
|
145
|
-
...focusableFilters
|
|
146
|
-
];
|
|
147
147
|
export {
|
|
148
148
|
isTabbable,
|
|
149
149
|
isFocusable,
|
package/dist/focusable.mjs
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
// src/focusable.ts
|
|
2
|
+
var focusableFilters = [isDisabled, isInert, isHidden, isSummarised];
|
|
3
|
+
var selector = [
|
|
4
|
+
'[contenteditable]:not([contenteditable="false"])',
|
|
5
|
+
"[tabindex]:not(slot)",
|
|
6
|
+
"a[href]",
|
|
7
|
+
"audio[controls]",
|
|
8
|
+
"button",
|
|
9
|
+
"details",
|
|
10
|
+
"details > summary:first-of-type",
|
|
11
|
+
"input",
|
|
12
|
+
"select",
|
|
13
|
+
"textarea",
|
|
14
|
+
"video[controls]"
|
|
15
|
+
].map((selector2) => `${selector2}:not([inert])`).join(",");
|
|
16
|
+
var tabbableFilters = [
|
|
17
|
+
isNotTabbable,
|
|
18
|
+
isNotTabbableRadio,
|
|
19
|
+
...focusableFilters
|
|
20
|
+
];
|
|
2
21
|
function getFocusable(parent) {
|
|
3
22
|
return getValidElements(parent, focusableFilters, false);
|
|
4
23
|
}
|
|
@@ -54,7 +73,7 @@ function isDisabled(item) {
|
|
|
54
73
|
if (/^(button|input|select|textarea)$/i.test(item.element.tagName) && isDisabledFromFieldset(item.element)) {
|
|
55
74
|
return true;
|
|
56
75
|
}
|
|
57
|
-
return
|
|
76
|
+
return item.element.disabled ?? false;
|
|
58
77
|
}
|
|
59
78
|
function isDisabledFromFieldset(element) {
|
|
60
79
|
let parent = element.parentElement;
|
|
@@ -125,25 +144,6 @@ function isValidElement(element, filters, tabbable) {
|
|
|
125
144
|
const item = getItem(element, tabbable);
|
|
126
145
|
return !filters.some((filter) => filter(item));
|
|
127
146
|
}
|
|
128
|
-
var focusableFilters = [isDisabled, isInert, isHidden, isSummarised];
|
|
129
|
-
var selector = [
|
|
130
|
-
'[contenteditable]:not([contenteditable="false"])',
|
|
131
|
-
"[tabindex]:not(slot)",
|
|
132
|
-
"a[href]",
|
|
133
|
-
"audio[controls]",
|
|
134
|
-
"button",
|
|
135
|
-
"details",
|
|
136
|
-
"details > summary:first-of-type",
|
|
137
|
-
"input",
|
|
138
|
-
"select",
|
|
139
|
-
"textarea",
|
|
140
|
-
"video[controls]"
|
|
141
|
-
].map((selector2) => `${selector2}:not([inert])`).join(",");
|
|
142
|
-
var tabbableFilters = [
|
|
143
|
-
isNotTabbable,
|
|
144
|
-
isNotTabbableRadio,
|
|
145
|
-
...focusableFilters
|
|
146
|
-
];
|
|
147
147
|
export {
|
|
148
148
|
isTabbable,
|
|
149
149
|
isFocusable,
|