@oscarpalmer/toretto 0.14.0 → 0.15.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.mjs → attribute.cjs} +31 -25
- package/dist/attribute.js +28 -42
- package/dist/data.cjs +37 -0
- package/dist/data.js +13 -56
- package/dist/event.cjs +62 -0
- package/dist/event.js +21 -30
- package/dist/{find.mjs → find.cjs} +29 -25
- package/dist/find.js +26 -22
- package/dist/{focusable.mjs → focusable.cjs} +31 -21
- package/dist/focusable.js +28 -18
- package/dist/{html.mjs → html.cjs} +14 -15
- package/dist/html.js +17 -98
- package/dist/index.cjs +48 -0
- package/dist/index.js +45 -663
- package/dist/internal/{element-value.mjs → element-value.cjs} +9 -10
- package/dist/internal/element-value.js +7 -32
- package/dist/internal/get-value.cjs +6 -0
- package/dist/internal/get-value.js +0 -1
- package/dist/is.cjs +15 -0
- package/dist/is.js +4 -4
- package/dist/models.cjs +1 -0
- package/dist/models.js +1 -0
- package/dist/sanitise.cjs +31 -0
- package/dist/sanitise.js +4 -48
- package/dist/style.cjs +48 -0
- package/dist/style.js +20 -58
- package/package.json +101 -69
- package/src/attribute.ts +6 -13
- package/src/data.ts +1 -1
- package/src/event.ts +8 -5
- package/src/find.ts +7 -6
- package/src/html.ts +3 -7
- package/src/index.ts +10 -10
- package/src/internal/element-value.ts +2 -2
- package/src/is.ts +5 -3
- package/src/sanitise.ts +1 -1
- package/src/style.ts +2 -2
- package/types/attribute.d.cts +63 -0
- package/types/attribute.d.ts +1 -1
- package/types/data.d.cts +54 -0
- package/types/data.d.ts +1 -1
- package/types/event.d.cts +36 -0
- package/types/event.d.ts +1 -1
- package/types/find.d.cts +44 -0
- package/types/find.d.ts +1 -1
- package/types/focusable.d.cts +20 -0
- package/types/html.d.cts +24 -0
- package/types/html.d.ts +1 -1
- package/types/index.d.cts +55 -54
- package/types/index.d.ts +10 -10
- package/types/internal/element-value.d.cts +40 -0
- package/types/internal/element-value.d.ts +1 -1
- package/types/internal/get-value.d.cts +5 -0
- package/types/is.d.cts +26 -0
- package/types/is.d.ts +1 -1
- package/types/models.d.cts +24 -0
- package/types/sanitise.d.cts +16 -0
- package/types/style.d.cts +26 -0
- package/types/style.d.ts +1 -1
- package/dist/data.mjs +0 -31
- package/dist/event.mjs +0 -59
- package/dist/index.mjs +0 -11
- package/dist/internal/get-value.mjs +0 -7
- package/dist/is.mjs +0 -15
- package/dist/models.mjs +0 -0
- package/dist/sanitise.mjs +0 -36
- package/dist/style.mjs +0 -41
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const is = require("@oscarpalmer/atoms/is");
|
|
4
|
+
const string = require("@oscarpalmer/atoms/string");
|
|
5
|
+
const booleanAttributes = Object.freeze([
|
|
5
6
|
"async",
|
|
6
7
|
"autofocus",
|
|
7
8
|
"autoplay",
|
|
@@ -27,9 +28,9 @@ var booleanAttributes = Object.freeze([
|
|
|
27
28
|
"reversed",
|
|
28
29
|
"selected"
|
|
29
30
|
]);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
const onPrefix = /^on/i;
|
|
32
|
+
const sourcePrefix = /^(href|src|xlink:href)$/i;
|
|
33
|
+
const valuePrefix = /(data:text\/html|javascript:)/i;
|
|
33
34
|
function isBadAttribute(attribute) {
|
|
34
35
|
return onPrefix.test(attribute.name) || sourcePrefix.test(attribute.name) && valuePrefix.test(attribute.value);
|
|
35
36
|
}
|
|
@@ -44,7 +45,7 @@ function isInvalidBooleanAttribute(attribute) {
|
|
|
44
45
|
return true;
|
|
45
46
|
}
|
|
46
47
|
const normalised = attribute.value.toLowerCase().trim();
|
|
47
|
-
return !(normalised.length === 0 || normalised === attribute.name
|
|
48
|
+
return !(normalised.length === 0 || normalised === attribute.name);
|
|
48
49
|
}
|
|
49
50
|
function setAttribute(element, first, second) {
|
|
50
51
|
updateValue(element, first, second, updateAttribute);
|
|
@@ -65,21 +66,24 @@ function updateAttribute(element, name, value) {
|
|
|
65
66
|
} else if (value == null) {
|
|
66
67
|
element.removeAttribute(name);
|
|
67
68
|
} else {
|
|
68
|
-
element.setAttribute(
|
|
69
|
+
element.setAttribute(
|
|
70
|
+
name,
|
|
71
|
+
typeof value === "string" ? value : string.getString(value)
|
|
72
|
+
);
|
|
69
73
|
}
|
|
70
74
|
}
|
|
71
75
|
function updateProperty(element, name, value, validate) {
|
|
72
76
|
const actual = validate ?? true ? name.toLowerCase() : name;
|
|
73
77
|
if (actual === "hidden") {
|
|
74
|
-
element.hidden =
|
|
78
|
+
element.hidden = value === "" || value === true;
|
|
75
79
|
} else {
|
|
76
80
|
element[actual] = value === "" || typeof value === "string" && value.toLowerCase() === actual || value === true;
|
|
77
81
|
}
|
|
78
82
|
}
|
|
79
83
|
function updateValue(element, first, second, callback) {
|
|
80
|
-
if (isPlainObject(first) && typeof first
|
|
84
|
+
if (is.isPlainObject(first) && typeof (first == null ? void 0 : first.name) === "string") {
|
|
81
85
|
callback(element, first.name, first.value);
|
|
82
|
-
} else
|
|
86
|
+
} else {
|
|
83
87
|
callback(element, first, second);
|
|
84
88
|
}
|
|
85
89
|
}
|
|
@@ -87,23 +91,25 @@ function updateValues(element, values, callback) {
|
|
|
87
91
|
const isArray = Array.isArray(values);
|
|
88
92
|
const entries = Object.entries(values);
|
|
89
93
|
const { length } = entries;
|
|
90
|
-
for (let index = 0;index < length; index += 1) {
|
|
94
|
+
for (let index = 0; index < length; index += 1) {
|
|
91
95
|
const entry = entries[index];
|
|
92
96
|
if (isArray) {
|
|
93
|
-
(callback ?? updateAttribute)(
|
|
97
|
+
(callback ?? updateAttribute)(
|
|
98
|
+
element,
|
|
99
|
+
entry[1].name,
|
|
100
|
+
entry[1].value
|
|
101
|
+
);
|
|
94
102
|
} else {
|
|
95
103
|
(callback ?? updateAttribute)(element, entry[0], entry[1]);
|
|
96
104
|
}
|
|
97
105
|
}
|
|
98
106
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
booleanAttributes
|
|
109
|
-
};
|
|
107
|
+
exports.booleanAttributes = booleanAttributes;
|
|
108
|
+
exports.isBadAttribute = isBadAttribute;
|
|
109
|
+
exports.isBooleanAttribute = isBooleanAttribute;
|
|
110
|
+
exports.isEmptyNonBooleanAttribute = isEmptyNonBooleanAttribute;
|
|
111
|
+
exports.isInvalidBooleanAttribute = isInvalidBooleanAttribute;
|
|
112
|
+
exports.setAttribute = setAttribute;
|
|
113
|
+
exports.setAttributes = setAttributes;
|
|
114
|
+
exports.setProperties = setProperties;
|
|
115
|
+
exports.setProperty = setProperty;
|
package/dist/attribute.js
CHANGED
|
@@ -1,27 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return value;
|
|
5
|
-
}
|
|
6
|
-
if (typeof value !== "object" || value == null) {
|
|
7
|
-
return String(value);
|
|
8
|
-
}
|
|
9
|
-
const valueOff = value.valueOf?.() ?? value;
|
|
10
|
-
const asString = valueOff?.toString?.() ?? String(valueOff);
|
|
11
|
-
return asString.startsWith("[object ") ? JSON.stringify(value) : asString;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// node_modules/@oscarpalmer/atoms/dist/js/is.mjs
|
|
15
|
-
function isPlainObject(value) {
|
|
16
|
-
if (typeof value !== "object" || value === null) {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
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);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// src/attribute.ts
|
|
24
|
-
var booleanAttributes = Object.freeze([
|
|
1
|
+
import { isPlainObject } from "@oscarpalmer/atoms/is";
|
|
2
|
+
import { getString } from "@oscarpalmer/atoms/string";
|
|
3
|
+
const booleanAttributes = Object.freeze([
|
|
25
4
|
"async",
|
|
26
5
|
"autofocus",
|
|
27
6
|
"autoplay",
|
|
@@ -47,9 +26,9 @@ var booleanAttributes = Object.freeze([
|
|
|
47
26
|
"reversed",
|
|
48
27
|
"selected"
|
|
49
28
|
]);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
29
|
+
const onPrefix = /^on/i;
|
|
30
|
+
const sourcePrefix = /^(href|src|xlink:href)$/i;
|
|
31
|
+
const valuePrefix = /(data:text\/html|javascript:)/i;
|
|
53
32
|
function isBadAttribute(attribute) {
|
|
54
33
|
return onPrefix.test(attribute.name) || sourcePrefix.test(attribute.name) && valuePrefix.test(attribute.value);
|
|
55
34
|
}
|
|
@@ -64,7 +43,7 @@ function isInvalidBooleanAttribute(attribute) {
|
|
|
64
43
|
return true;
|
|
65
44
|
}
|
|
66
45
|
const normalised = attribute.value.toLowerCase().trim();
|
|
67
|
-
return !(normalised.length === 0 || normalised === attribute.name
|
|
46
|
+
return !(normalised.length === 0 || normalised === attribute.name);
|
|
68
47
|
}
|
|
69
48
|
function setAttribute(element, first, second) {
|
|
70
49
|
updateValue(element, first, second, updateAttribute);
|
|
@@ -85,21 +64,24 @@ function updateAttribute(element, name, value) {
|
|
|
85
64
|
} else if (value == null) {
|
|
86
65
|
element.removeAttribute(name);
|
|
87
66
|
} else {
|
|
88
|
-
element.setAttribute(
|
|
67
|
+
element.setAttribute(
|
|
68
|
+
name,
|
|
69
|
+
typeof value === "string" ? value : getString(value)
|
|
70
|
+
);
|
|
89
71
|
}
|
|
90
72
|
}
|
|
91
73
|
function updateProperty(element, name, value, validate) {
|
|
92
74
|
const actual = validate ?? true ? name.toLowerCase() : name;
|
|
93
75
|
if (actual === "hidden") {
|
|
94
|
-
element.hidden =
|
|
76
|
+
element.hidden = value === "" || value === true;
|
|
95
77
|
} else {
|
|
96
78
|
element[actual] = value === "" || typeof value === "string" && value.toLowerCase() === actual || value === true;
|
|
97
79
|
}
|
|
98
80
|
}
|
|
99
81
|
function updateValue(element, first, second, callback) {
|
|
100
|
-
if (isPlainObject(first) && typeof first
|
|
82
|
+
if (isPlainObject(first) && typeof (first == null ? void 0 : first.name) === "string") {
|
|
101
83
|
callback(element, first.name, first.value);
|
|
102
|
-
} else
|
|
84
|
+
} else {
|
|
103
85
|
callback(element, first, second);
|
|
104
86
|
}
|
|
105
87
|
}
|
|
@@ -107,23 +89,27 @@ function updateValues(element, values, callback) {
|
|
|
107
89
|
const isArray = Array.isArray(values);
|
|
108
90
|
const entries = Object.entries(values);
|
|
109
91
|
const { length } = entries;
|
|
110
|
-
for (let index = 0;index < length; index += 1) {
|
|
92
|
+
for (let index = 0; index < length; index += 1) {
|
|
111
93
|
const entry = entries[index];
|
|
112
94
|
if (isArray) {
|
|
113
|
-
(callback ?? updateAttribute)(
|
|
95
|
+
(callback ?? updateAttribute)(
|
|
96
|
+
element,
|
|
97
|
+
entry[1].name,
|
|
98
|
+
entry[1].value
|
|
99
|
+
);
|
|
114
100
|
} else {
|
|
115
101
|
(callback ?? updateAttribute)(element, entry[0], entry[1]);
|
|
116
102
|
}
|
|
117
103
|
}
|
|
118
104
|
}
|
|
119
105
|
export {
|
|
120
|
-
|
|
121
|
-
setProperties,
|
|
122
|
-
setAttributes,
|
|
123
|
-
setAttribute,
|
|
124
|
-
isInvalidBooleanAttribute,
|
|
125
|
-
isEmptyNonBooleanAttribute,
|
|
126
|
-
isBooleanAttribute,
|
|
106
|
+
booleanAttributes,
|
|
127
107
|
isBadAttribute,
|
|
128
|
-
|
|
108
|
+
isBooleanAttribute,
|
|
109
|
+
isEmptyNonBooleanAttribute,
|
|
110
|
+
isInvalidBooleanAttribute,
|
|
111
|
+
setAttribute,
|
|
112
|
+
setAttributes,
|
|
113
|
+
setProperties,
|
|
114
|
+
setProperty
|
|
129
115
|
};
|
package/dist/data.cjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const string = require("@oscarpalmer/atoms/string");
|
|
4
|
+
const internal_elementValue = require("./internal/element-value.cjs");
|
|
5
|
+
function getData(element, keys) {
|
|
6
|
+
if (typeof keys === "string") {
|
|
7
|
+
return getDataValue(element, keys);
|
|
8
|
+
}
|
|
9
|
+
const { length } = keys;
|
|
10
|
+
const data = {};
|
|
11
|
+
for (let index = 0; index < length; index += 1) {
|
|
12
|
+
const key = keys[index];
|
|
13
|
+
data[key] = getDataValue(element, key);
|
|
14
|
+
}
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
function getDataValue(element, key) {
|
|
18
|
+
const value = element.dataset[key];
|
|
19
|
+
if (value != null) {
|
|
20
|
+
return string.parse(value);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function setData(element, first, second) {
|
|
24
|
+
internal_elementValue.setElementValues(element, first, second, updateDataAttribute);
|
|
25
|
+
}
|
|
26
|
+
function updateDataAttribute(element, key, value) {
|
|
27
|
+
internal_elementValue.updateElementValue(
|
|
28
|
+
element,
|
|
29
|
+
`data-${key}`,
|
|
30
|
+
value,
|
|
31
|
+
element.setAttribute,
|
|
32
|
+
element.removeAttribute,
|
|
33
|
+
true
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
exports.getData = getData;
|
|
37
|
+
exports.setData = setData;
|
package/dist/data.js
CHANGED
|
@@ -1,62 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return value == null || /^\s*$/.test(getString(value));
|
|
4
|
-
}
|
|
5
|
-
function isPlainObject(value) {
|
|
6
|
-
if (typeof value !== "object" || value === null) {
|
|
7
|
-
return false;
|
|
8
|
-
}
|
|
9
|
-
const prototype = Object.getPrototypeOf(value);
|
|
10
|
-
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
11
|
-
}
|
|
12
|
-
// node_modules/@oscarpalmer/atoms/dist/js/string/index.mjs
|
|
13
|
-
function getString(value) {
|
|
14
|
-
if (typeof value === "string") {
|
|
15
|
-
return value;
|
|
16
|
-
}
|
|
17
|
-
if (typeof value !== "object" || value == null) {
|
|
18
|
-
return String(value);
|
|
19
|
-
}
|
|
20
|
-
const valueOff = value.valueOf?.() ?? value;
|
|
21
|
-
const asString = valueOff?.toString?.() ?? String(valueOff);
|
|
22
|
-
return asString.startsWith("[object ") ? JSON.stringify(value) : asString;
|
|
23
|
-
}
|
|
24
|
-
function parse(value, reviver) {
|
|
25
|
-
try {
|
|
26
|
-
return JSON.parse(value, reviver);
|
|
27
|
-
} catch {
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// src/internal/element-value.ts
|
|
32
|
-
function setElementValues(element, first, second, callback) {
|
|
33
|
-
if (isPlainObject(first)) {
|
|
34
|
-
const entries = Object.entries(first);
|
|
35
|
-
const { length } = entries;
|
|
36
|
-
for (let index = 0;index < length; index += 1) {
|
|
37
|
-
const [key, value] = entries[index];
|
|
38
|
-
callback(element, key, value);
|
|
39
|
-
}
|
|
40
|
-
} else if (first != null) {
|
|
41
|
-
callback(element, first, second);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
function updateElementValue(element, key, value, set2, remove, json) {
|
|
45
|
-
if (isNullableOrWhitespace(value)) {
|
|
46
|
-
remove.call(element, key);
|
|
47
|
-
} else {
|
|
48
|
-
set2.call(element, key, json ? JSON.stringify(value) : String(value));
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// src/data.ts
|
|
1
|
+
import { parse } from "@oscarpalmer/atoms/string";
|
|
2
|
+
import { setElementValues, updateElementValue } from "./internal/element-value.js";
|
|
53
3
|
function getData(element, keys) {
|
|
54
4
|
if (typeof keys === "string") {
|
|
55
5
|
return getDataValue(element, keys);
|
|
56
6
|
}
|
|
57
7
|
const { length } = keys;
|
|
58
8
|
const data = {};
|
|
59
|
-
for (let index = 0;index < length; index += 1) {
|
|
9
|
+
for (let index = 0; index < length; index += 1) {
|
|
60
10
|
const key = keys[index];
|
|
61
11
|
data[key] = getDataValue(element, key);
|
|
62
12
|
}
|
|
@@ -72,9 +22,16 @@ function setData(element, first, second) {
|
|
|
72
22
|
setElementValues(element, first, second, updateDataAttribute);
|
|
73
23
|
}
|
|
74
24
|
function updateDataAttribute(element, key, value) {
|
|
75
|
-
updateElementValue(
|
|
25
|
+
updateElementValue(
|
|
26
|
+
element,
|
|
27
|
+
`data-${key}`,
|
|
28
|
+
value,
|
|
29
|
+
element.setAttribute,
|
|
30
|
+
element.removeAttribute,
|
|
31
|
+
true
|
|
32
|
+
);
|
|
76
33
|
}
|
|
77
34
|
export {
|
|
78
|
-
|
|
79
|
-
|
|
35
|
+
getData,
|
|
36
|
+
setData
|
|
80
37
|
};
|
package/dist/event.cjs
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const is = require("@oscarpalmer/atoms/is");
|
|
4
|
+
const internal_getValue = require("./internal/get-value.cjs");
|
|
5
|
+
function createDispatchOptions(options) {
|
|
6
|
+
return {
|
|
7
|
+
bubbles: internal_getValue.getBoolean(options == null ? void 0 : options.bubbles),
|
|
8
|
+
cancelable: internal_getValue.getBoolean(options == null ? void 0 : options.cancelable),
|
|
9
|
+
composed: internal_getValue.getBoolean(options == null ? void 0 : options.composed)
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function createEvent(type, options) {
|
|
13
|
+
const hasOptions = is.isPlainObject(options);
|
|
14
|
+
if (hasOptions && "detail" in options) {
|
|
15
|
+
return new CustomEvent(type, {
|
|
16
|
+
...createDispatchOptions(options),
|
|
17
|
+
detail: options == null ? void 0 : options.detail
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return new Event(
|
|
21
|
+
type,
|
|
22
|
+
createDispatchOptions(hasOptions ? options : {})
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
function createEventOptions(options) {
|
|
26
|
+
return {
|
|
27
|
+
capture: internal_getValue.getBoolean(options == null ? void 0 : options.capture),
|
|
28
|
+
once: internal_getValue.getBoolean(options == null ? void 0 : options.once),
|
|
29
|
+
passive: internal_getValue.getBoolean(options == null ? void 0 : options.passive, true),
|
|
30
|
+
signal: options == null ? void 0 : options.signal
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function dispatch(target, type, options) {
|
|
34
|
+
target.dispatchEvent(createEvent(type, options));
|
|
35
|
+
}
|
|
36
|
+
function getPosition(event) {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
let x;
|
|
39
|
+
let y;
|
|
40
|
+
if (event instanceof MouseEvent) {
|
|
41
|
+
x = event.clientX;
|
|
42
|
+
y = event.clientY;
|
|
43
|
+
} else if (event instanceof TouchEvent) {
|
|
44
|
+
x = (_a = event.touches[0]) == null ? void 0 : _a.clientX;
|
|
45
|
+
y = (_b = event.touches[0]) == null ? void 0 : _b.clientY;
|
|
46
|
+
}
|
|
47
|
+
return typeof x === "number" && typeof y === "number" ? { x, y } : void 0;
|
|
48
|
+
}
|
|
49
|
+
function off(target, type, listener, options) {
|
|
50
|
+
target.removeEventListener(type, listener, createEventOptions(options));
|
|
51
|
+
}
|
|
52
|
+
function on(target, type, listener, options) {
|
|
53
|
+
const extended = createEventOptions(options);
|
|
54
|
+
target.addEventListener(type, listener, extended);
|
|
55
|
+
return () => {
|
|
56
|
+
target.removeEventListener(type, listener, extended);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
exports.dispatch = dispatch;
|
|
60
|
+
exports.getPosition = getPosition;
|
|
61
|
+
exports.off = off;
|
|
62
|
+
exports.on = on;
|
package/dist/event.js
CHANGED
|
@@ -1,23 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (typeof value !== "object" || value === null) {
|
|
4
|
-
return false;
|
|
5
|
-
}
|
|
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;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// src/event.ts
|
|
1
|
+
import { isPlainObject } from "@oscarpalmer/atoms/is";
|
|
2
|
+
import { getBoolean } from "./internal/get-value.js";
|
|
16
3
|
function createDispatchOptions(options) {
|
|
17
4
|
return {
|
|
18
|
-
bubbles: getBoolean(options
|
|
19
|
-
cancelable: getBoolean(options
|
|
20
|
-
composed: getBoolean(options
|
|
5
|
+
bubbles: getBoolean(options == null ? void 0 : options.bubbles),
|
|
6
|
+
cancelable: getBoolean(options == null ? void 0 : options.cancelable),
|
|
7
|
+
composed: getBoolean(options == null ? void 0 : options.composed)
|
|
21
8
|
};
|
|
22
9
|
}
|
|
23
10
|
function createEvent(type, options) {
|
|
@@ -25,33 +12,37 @@ function createEvent(type, options) {
|
|
|
25
12
|
if (hasOptions && "detail" in options) {
|
|
26
13
|
return new CustomEvent(type, {
|
|
27
14
|
...createDispatchOptions(options),
|
|
28
|
-
detail: options
|
|
15
|
+
detail: options == null ? void 0 : options.detail
|
|
29
16
|
});
|
|
30
17
|
}
|
|
31
|
-
return new Event(
|
|
18
|
+
return new Event(
|
|
19
|
+
type,
|
|
20
|
+
createDispatchOptions(hasOptions ? options : {})
|
|
21
|
+
);
|
|
32
22
|
}
|
|
33
23
|
function createEventOptions(options) {
|
|
34
24
|
return {
|
|
35
|
-
capture: getBoolean(options
|
|
36
|
-
once: getBoolean(options
|
|
37
|
-
passive: getBoolean(options
|
|
38
|
-
signal: options
|
|
25
|
+
capture: getBoolean(options == null ? void 0 : options.capture),
|
|
26
|
+
once: getBoolean(options == null ? void 0 : options.once),
|
|
27
|
+
passive: getBoolean(options == null ? void 0 : options.passive, true),
|
|
28
|
+
signal: options == null ? void 0 : options.signal
|
|
39
29
|
};
|
|
40
30
|
}
|
|
41
31
|
function dispatch(target, type, options) {
|
|
42
32
|
target.dispatchEvent(createEvent(type, options));
|
|
43
33
|
}
|
|
44
34
|
function getPosition(event) {
|
|
35
|
+
var _a, _b;
|
|
45
36
|
let x;
|
|
46
37
|
let y;
|
|
47
38
|
if (event instanceof MouseEvent) {
|
|
48
39
|
x = event.clientX;
|
|
49
40
|
y = event.clientY;
|
|
50
41
|
} else if (event instanceof TouchEvent) {
|
|
51
|
-
x = event.touches[0]
|
|
52
|
-
y = event.touches[0]
|
|
42
|
+
x = (_a = event.touches[0]) == null ? void 0 : _a.clientX;
|
|
43
|
+
y = (_b = event.touches[0]) == null ? void 0 : _b.clientY;
|
|
53
44
|
}
|
|
54
|
-
return typeof x === "number" && typeof y === "number" ? { x, y } :
|
|
45
|
+
return typeof x === "number" && typeof y === "number" ? { x, y } : void 0;
|
|
55
46
|
}
|
|
56
47
|
function off(target, type, listener, options) {
|
|
57
48
|
target.removeEventListener(type, listener, createEventOptions(options));
|
|
@@ -64,8 +55,8 @@ function on(target, type, listener, options) {
|
|
|
64
55
|
};
|
|
65
56
|
}
|
|
66
57
|
export {
|
|
67
|
-
|
|
68
|
-
off,
|
|
58
|
+
dispatch,
|
|
69
59
|
getPosition,
|
|
70
|
-
|
|
60
|
+
off,
|
|
61
|
+
on
|
|
71
62
|
};
|
|
@@ -1,27 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
3
|
function getDistanceBetweenElements(origin, target) {
|
|
4
|
+
var _a;
|
|
3
5
|
if (origin === target || origin.parentElement === target) {
|
|
4
6
|
return 0;
|
|
5
7
|
}
|
|
6
8
|
const comparison = origin.compareDocumentPosition(target);
|
|
7
|
-
const children = [...origin.parentElement
|
|
9
|
+
const children = [...((_a = origin.parentElement) == null ? void 0 : _a.children) ?? []];
|
|
10
|
+
if (children.includes(target)) {
|
|
11
|
+
return Math.abs(children.indexOf(origin) - children.indexOf(target));
|
|
12
|
+
}
|
|
8
13
|
switch (true) {
|
|
9
|
-
case children.includes(target):
|
|
10
|
-
return Math.abs(children.indexOf(origin) - children.indexOf(target));
|
|
11
14
|
case !!(comparison & 2 || comparison & 8):
|
|
12
15
|
return traverse(origin, target);
|
|
13
16
|
case !!(comparison & 4 || comparison & 16):
|
|
14
17
|
return traverse(target, origin);
|
|
15
18
|
default:
|
|
16
|
-
return
|
|
19
|
+
return Number.NaN;
|
|
17
20
|
}
|
|
18
21
|
}
|
|
19
22
|
function findAncestor(origin, selector) {
|
|
23
|
+
var _a;
|
|
20
24
|
if (origin == null || selector == null) {
|
|
21
25
|
return null;
|
|
22
26
|
}
|
|
23
27
|
if (typeof selector === "string") {
|
|
24
|
-
if (origin.matches
|
|
28
|
+
if ((_a = origin.matches) == null ? void 0 : _a.call(origin, selector)) {
|
|
25
29
|
return origin;
|
|
26
30
|
}
|
|
27
31
|
return origin.closest(selector);
|
|
@@ -43,11 +47,11 @@ function findElement(selector, context) {
|
|
|
43
47
|
}
|
|
44
48
|
function findElementOrElements(selector, context, single) {
|
|
45
49
|
const callback = single ? document.querySelector : document.querySelectorAll;
|
|
46
|
-
const contexts = context == null ? [document] : findElementOrElements(context,
|
|
50
|
+
const contexts = context == null ? [document] : findElementOrElements(context, void 0, false);
|
|
47
51
|
const result = [];
|
|
48
52
|
if (typeof selector === "string") {
|
|
49
53
|
const { length: length2 } = contexts;
|
|
50
|
-
for (let index = 0;index < length2; index += 1) {
|
|
54
|
+
for (let index = 0; index < length2; index += 1) {
|
|
51
55
|
const value = callback.call(contexts[index], selector);
|
|
52
56
|
if (single) {
|
|
53
57
|
if (value == null) {
|
|
@@ -57,14 +61,16 @@ function findElementOrElements(selector, context, single) {
|
|
|
57
61
|
}
|
|
58
62
|
result.push(...Array.from(value));
|
|
59
63
|
}
|
|
60
|
-
return single ?
|
|
64
|
+
return single ? void 0 : result.filter((value, index, array) => array.indexOf(value) === index);
|
|
61
65
|
}
|
|
62
66
|
const nodes = Array.isArray(selector) ? selector : selector instanceof NodeList ? Array.from(selector) : [selector];
|
|
63
67
|
const { length } = nodes;
|
|
64
|
-
for (let index = 0;index < length; index += 1) {
|
|
68
|
+
for (let index = 0; index < length; index += 1) {
|
|
65
69
|
const node = nodes[index];
|
|
66
|
-
const element = node instanceof Document ? node.body : node instanceof Element ? node :
|
|
67
|
-
if (element != null && (context == null || contexts.length === 0 || contexts.some(
|
|
70
|
+
const element = node instanceof Document ? node.body : node instanceof Element ? node : void 0;
|
|
71
|
+
if (element != null && (context == null || contexts.length === 0 || contexts.some(
|
|
72
|
+
(context2) => context2 === element || context2.contains(element)
|
|
73
|
+
)) && !result.includes(element)) {
|
|
68
74
|
result.push(element);
|
|
69
75
|
}
|
|
70
76
|
}
|
|
@@ -84,7 +90,7 @@ function findRelatives(origin, selector, context) {
|
|
|
84
90
|
}
|
|
85
91
|
const distances = [];
|
|
86
92
|
let minimum = null;
|
|
87
|
-
for (let index = 0;index < length; index += 1) {
|
|
93
|
+
for (let index = 0; index < length; index += 1) {
|
|
88
94
|
const element = elements[index];
|
|
89
95
|
const distance = getDistanceBetweenElements(origin, element);
|
|
90
96
|
if (distance < 0) {
|
|
@@ -104,7 +110,7 @@ function getElementUnderPointer(skipIgnore) {
|
|
|
104
110
|
const elements = [...document.querySelectorAll(":hover")];
|
|
105
111
|
const { length } = elements;
|
|
106
112
|
const returned = [];
|
|
107
|
-
for (let index = 0;index < length; index += 1) {
|
|
113
|
+
for (let index = 0; index < length; index += 1) {
|
|
108
114
|
const element = elements[index];
|
|
109
115
|
if (/^head$/i.test(element.tagName)) {
|
|
110
116
|
continue;
|
|
@@ -140,15 +146,13 @@ function traverse(from, to) {
|
|
|
140
146
|
distance += 1;
|
|
141
147
|
parent = parent.parentElement;
|
|
142
148
|
}
|
|
143
|
-
return
|
|
149
|
+
return Number.NaN;
|
|
144
150
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
findElement as $
|
|
154
|
-
};
|
|
151
|
+
exports.$ = findElement;
|
|
152
|
+
exports.$$ = findElements;
|
|
153
|
+
exports.findAncestor = findAncestor;
|
|
154
|
+
exports.findElement = findElement;
|
|
155
|
+
exports.findElements = findElements;
|
|
156
|
+
exports.findRelatives = findRelatives;
|
|
157
|
+
exports.getDistanceBetweenElements = getDistanceBetweenElements;
|
|
158
|
+
exports.getElementUnderPointer = getElementUnderPointer;
|