@oscarpalmer/toretto 0.13.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} +56 -50
- package/dist/attribute.js +58 -71
- package/dist/data.cjs +37 -0
- package/dist/data.js +17 -59
- package/dist/event.cjs +62 -0
- package/dist/event.js +21 -29
- package/dist/{find.mjs → find.cjs} +29 -25
- package/dist/find.js +26 -22
- package/dist/{focusable.mjs → focusable.cjs} +47 -37
- package/dist/focusable.js +44 -34
- package/dist/{html.mjs → html.cjs} +14 -15
- package/dist/html.js +22 -103
- package/dist/index.cjs +48 -0
- package/dist/index.js +45 -661
- package/dist/internal/{element-value.mjs → element-value.cjs} +9 -10
- package/dist/internal/element-value.js +10 -34
- 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 +11 -55
- package/dist/style.cjs +48 -0
- package/dist/style.js +23 -60
- package/package.json +99 -60
- package/src/attribute.ts +6 -13
- package/src/data.ts +1 -1
- package/src/event.ts +9 -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 -58
- 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,6 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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([
|
|
6
|
+
"async",
|
|
7
|
+
"autofocus",
|
|
8
|
+
"autoplay",
|
|
9
|
+
"checked",
|
|
10
|
+
"controls",
|
|
11
|
+
"default",
|
|
12
|
+
"defer",
|
|
13
|
+
"disabled",
|
|
14
|
+
"formnovalidate",
|
|
15
|
+
"hidden",
|
|
16
|
+
"inert",
|
|
17
|
+
"ismap",
|
|
18
|
+
"itemscope",
|
|
19
|
+
"loop",
|
|
20
|
+
"multiple",
|
|
21
|
+
"muted",
|
|
22
|
+
"nomodule",
|
|
23
|
+
"novalidate",
|
|
24
|
+
"open",
|
|
25
|
+
"playsinline",
|
|
26
|
+
"readonly",
|
|
27
|
+
"required",
|
|
28
|
+
"reversed",
|
|
29
|
+
"selected"
|
|
30
|
+
]);
|
|
31
|
+
const onPrefix = /^on/i;
|
|
32
|
+
const sourcePrefix = /^(href|src|xlink:href)$/i;
|
|
33
|
+
const valuePrefix = /(data:text\/html|javascript:)/i;
|
|
4
34
|
function isBadAttribute(attribute) {
|
|
5
35
|
return onPrefix.test(attribute.name) || sourcePrefix.test(attribute.name) && valuePrefix.test(attribute.value);
|
|
6
36
|
}
|
|
@@ -15,7 +45,7 @@ function isInvalidBooleanAttribute(attribute) {
|
|
|
15
45
|
return true;
|
|
16
46
|
}
|
|
17
47
|
const normalised = attribute.value.toLowerCase().trim();
|
|
18
|
-
return !(normalised.length === 0 || normalised === attribute.name
|
|
48
|
+
return !(normalised.length === 0 || normalised === attribute.name);
|
|
19
49
|
}
|
|
20
50
|
function setAttribute(element, first, second) {
|
|
21
51
|
updateValue(element, first, second, updateAttribute);
|
|
@@ -36,21 +66,24 @@ function updateAttribute(element, name, value) {
|
|
|
36
66
|
} else if (value == null) {
|
|
37
67
|
element.removeAttribute(name);
|
|
38
68
|
} else {
|
|
39
|
-
element.setAttribute(
|
|
69
|
+
element.setAttribute(
|
|
70
|
+
name,
|
|
71
|
+
typeof value === "string" ? value : string.getString(value)
|
|
72
|
+
);
|
|
40
73
|
}
|
|
41
74
|
}
|
|
42
75
|
function updateProperty(element, name, value, validate) {
|
|
43
76
|
const actual = validate ?? true ? name.toLowerCase() : name;
|
|
44
77
|
if (actual === "hidden") {
|
|
45
|
-
element.hidden =
|
|
78
|
+
element.hidden = value === "" || value === true;
|
|
46
79
|
} else {
|
|
47
80
|
element[actual] = value === "" || typeof value === "string" && value.toLowerCase() === actual || value === true;
|
|
48
81
|
}
|
|
49
82
|
}
|
|
50
83
|
function updateValue(element, first, second, callback) {
|
|
51
|
-
if (isPlainObject(first) && typeof first
|
|
84
|
+
if (is.isPlainObject(first) && typeof (first == null ? void 0 : first.name) === "string") {
|
|
52
85
|
callback(element, first.name, first.value);
|
|
53
|
-
} else
|
|
86
|
+
} else {
|
|
54
87
|
callback(element, first, second);
|
|
55
88
|
}
|
|
56
89
|
}
|
|
@@ -58,52 +91,25 @@ function updateValues(element, values, callback) {
|
|
|
58
91
|
const isArray = Array.isArray(values);
|
|
59
92
|
const entries = Object.entries(values);
|
|
60
93
|
const { length } = entries;
|
|
61
|
-
for (let index = 0;index < length; index += 1) {
|
|
94
|
+
for (let index = 0; index < length; index += 1) {
|
|
62
95
|
const entry = entries[index];
|
|
63
96
|
if (isArray) {
|
|
64
|
-
(callback ?? updateAttribute)(
|
|
97
|
+
(callback ?? updateAttribute)(
|
|
98
|
+
element,
|
|
99
|
+
entry[1].name,
|
|
100
|
+
entry[1].value
|
|
101
|
+
);
|
|
65
102
|
} else {
|
|
66
103
|
(callback ?? updateAttribute)(element, entry[0], entry[1]);
|
|
67
104
|
}
|
|
68
105
|
}
|
|
69
106
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
"formnovalidate",
|
|
80
|
-
"hidden",
|
|
81
|
-
"inert",
|
|
82
|
-
"ismap",
|
|
83
|
-
"itemscope",
|
|
84
|
-
"loop",
|
|
85
|
-
"multiple",
|
|
86
|
-
"muted",
|
|
87
|
-
"nomodule",
|
|
88
|
-
"novalidate",
|
|
89
|
-
"open",
|
|
90
|
-
"playsinline",
|
|
91
|
-
"readonly",
|
|
92
|
-
"required",
|
|
93
|
-
"reversed",
|
|
94
|
-
"selected"
|
|
95
|
-
]);
|
|
96
|
-
var onPrefix = /^on/i;
|
|
97
|
-
var sourcePrefix = /^(href|src|xlink:href)$/i;
|
|
98
|
-
var valuePrefix = /(data:text\/html|javascript:)/i;
|
|
99
|
-
export {
|
|
100
|
-
setProperty,
|
|
101
|
-
setProperties,
|
|
102
|
-
setAttributes,
|
|
103
|
-
setAttribute,
|
|
104
|
-
isInvalidBooleanAttribute,
|
|
105
|
-
isEmptyNonBooleanAttribute,
|
|
106
|
-
isBooleanAttribute,
|
|
107
|
-
isBadAttribute,
|
|
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,25 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
import { isPlainObject } from "@oscarpalmer/atoms/is";
|
|
2
|
+
import { getString } from "@oscarpalmer/atoms/string";
|
|
3
|
+
const booleanAttributes = Object.freeze([
|
|
4
|
+
"async",
|
|
5
|
+
"autofocus",
|
|
6
|
+
"autoplay",
|
|
7
|
+
"checked",
|
|
8
|
+
"controls",
|
|
9
|
+
"default",
|
|
10
|
+
"defer",
|
|
11
|
+
"disabled",
|
|
12
|
+
"formnovalidate",
|
|
13
|
+
"hidden",
|
|
14
|
+
"inert",
|
|
15
|
+
"ismap",
|
|
16
|
+
"itemscope",
|
|
17
|
+
"loop",
|
|
18
|
+
"multiple",
|
|
19
|
+
"muted",
|
|
20
|
+
"nomodule",
|
|
21
|
+
"novalidate",
|
|
22
|
+
"open",
|
|
23
|
+
"playsinline",
|
|
24
|
+
"readonly",
|
|
25
|
+
"required",
|
|
26
|
+
"reversed",
|
|
27
|
+
"selected"
|
|
28
|
+
]);
|
|
29
|
+
const onPrefix = /^on/i;
|
|
30
|
+
const sourcePrefix = /^(href|src|xlink:href)$/i;
|
|
31
|
+
const valuePrefix = /(data:text\/html|javascript:)/i;
|
|
23
32
|
function isBadAttribute(attribute) {
|
|
24
33
|
return onPrefix.test(attribute.name) || sourcePrefix.test(attribute.name) && valuePrefix.test(attribute.value);
|
|
25
34
|
}
|
|
@@ -34,7 +43,7 @@ function isInvalidBooleanAttribute(attribute) {
|
|
|
34
43
|
return true;
|
|
35
44
|
}
|
|
36
45
|
const normalised = attribute.value.toLowerCase().trim();
|
|
37
|
-
return !(normalised.length === 0 || normalised === attribute.name
|
|
46
|
+
return !(normalised.length === 0 || normalised === attribute.name);
|
|
38
47
|
}
|
|
39
48
|
function setAttribute(element, first, second) {
|
|
40
49
|
updateValue(element, first, second, updateAttribute);
|
|
@@ -48,28 +57,31 @@ function setProperty(element, first, second) {
|
|
|
48
57
|
function setProperties(element, properties) {
|
|
49
58
|
updateValues(element, properties, updateProperty);
|
|
50
59
|
}
|
|
51
|
-
function updateAttribute(element, name,
|
|
60
|
+
function updateAttribute(element, name, value) {
|
|
52
61
|
const normalised = name.toLowerCase();
|
|
53
62
|
if (booleanAttributes.includes(normalised)) {
|
|
54
|
-
updateProperty(element, name,
|
|
55
|
-
} else if (
|
|
63
|
+
updateProperty(element, name, value, false);
|
|
64
|
+
} else if (value == null) {
|
|
56
65
|
element.removeAttribute(name);
|
|
57
66
|
} else {
|
|
58
|
-
element.setAttribute(
|
|
67
|
+
element.setAttribute(
|
|
68
|
+
name,
|
|
69
|
+
typeof value === "string" ? value : getString(value)
|
|
70
|
+
);
|
|
59
71
|
}
|
|
60
72
|
}
|
|
61
|
-
function updateProperty(element, name,
|
|
73
|
+
function updateProperty(element, name, value, validate) {
|
|
62
74
|
const actual = validate ?? true ? name.toLowerCase() : name;
|
|
63
75
|
if (actual === "hidden") {
|
|
64
|
-
element.hidden =
|
|
76
|
+
element.hidden = value === "" || value === true;
|
|
65
77
|
} else {
|
|
66
|
-
element[actual] =
|
|
78
|
+
element[actual] = value === "" || typeof value === "string" && value.toLowerCase() === actual || value === true;
|
|
67
79
|
}
|
|
68
80
|
}
|
|
69
81
|
function updateValue(element, first, second, callback) {
|
|
70
|
-
if (isPlainObject(first) && typeof first
|
|
82
|
+
if (isPlainObject(first) && typeof (first == null ? void 0 : first.name) === "string") {
|
|
71
83
|
callback(element, first.name, first.value);
|
|
72
|
-
} else
|
|
84
|
+
} else {
|
|
73
85
|
callback(element, first, second);
|
|
74
86
|
}
|
|
75
87
|
}
|
|
@@ -77,52 +89,27 @@ function updateValues(element, values, callback) {
|
|
|
77
89
|
const isArray = Array.isArray(values);
|
|
78
90
|
const entries = Object.entries(values);
|
|
79
91
|
const { length } = entries;
|
|
80
|
-
for (let index = 0;index < length; index += 1) {
|
|
92
|
+
for (let index = 0; index < length; index += 1) {
|
|
81
93
|
const entry = entries[index];
|
|
82
94
|
if (isArray) {
|
|
83
|
-
(callback ?? updateAttribute)(
|
|
95
|
+
(callback ?? updateAttribute)(
|
|
96
|
+
element,
|
|
97
|
+
entry[1].name,
|
|
98
|
+
entry[1].value
|
|
99
|
+
);
|
|
84
100
|
} else {
|
|
85
101
|
(callback ?? updateAttribute)(element, entry[0], entry[1]);
|
|
86
102
|
}
|
|
87
103
|
}
|
|
88
104
|
}
|
|
89
|
-
var booleanAttributes = Object.freeze([
|
|
90
|
-
"async",
|
|
91
|
-
"autofocus",
|
|
92
|
-
"autoplay",
|
|
93
|
-
"checked",
|
|
94
|
-
"controls",
|
|
95
|
-
"default",
|
|
96
|
-
"defer",
|
|
97
|
-
"disabled",
|
|
98
|
-
"formnovalidate",
|
|
99
|
-
"hidden",
|
|
100
|
-
"inert",
|
|
101
|
-
"ismap",
|
|
102
|
-
"itemscope",
|
|
103
|
-
"loop",
|
|
104
|
-
"multiple",
|
|
105
|
-
"muted",
|
|
106
|
-
"nomodule",
|
|
107
|
-
"novalidate",
|
|
108
|
-
"open",
|
|
109
|
-
"playsinline",
|
|
110
|
-
"readonly",
|
|
111
|
-
"required",
|
|
112
|
-
"reversed",
|
|
113
|
-
"selected"
|
|
114
|
-
]);
|
|
115
|
-
var onPrefix = /^on/i;
|
|
116
|
-
var sourcePrefix = /^(href|src|xlink:href)$/i;
|
|
117
|
-
var valuePrefix = /(data:text\/html|javascript:)/i;
|
|
118
105
|
export {
|
|
119
|
-
|
|
120
|
-
setProperties,
|
|
121
|
-
setAttributes,
|
|
122
|
-
setAttribute,
|
|
123
|
-
isInvalidBooleanAttribute,
|
|
124
|
-
isEmptyNonBooleanAttribute,
|
|
125
|
-
isBooleanAttribute,
|
|
106
|
+
booleanAttributes,
|
|
126
107
|
isBadAttribute,
|
|
127
|
-
|
|
108
|
+
isBooleanAttribute,
|
|
109
|
+
isEmptyNonBooleanAttribute,
|
|
110
|
+
isInvalidBooleanAttribute,
|
|
111
|
+
setAttribute,
|
|
112
|
+
setAttributes,
|
|
113
|
+
setProperties,
|
|
114
|
+
setProperty
|
|
128
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,79 +1,37 @@
|
|
|
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(value2) {
|
|
14
|
-
if (typeof value2 === "string") {
|
|
15
|
-
return value2;
|
|
16
|
-
}
|
|
17
|
-
if (typeof value2 !== "object" || value2 == null) {
|
|
18
|
-
return String(value2);
|
|
19
|
-
}
|
|
20
|
-
const valueOff = value2.valueOf?.() ?? value2;
|
|
21
|
-
const asString = valueOff?.toString?.() ?? String(valueOff);
|
|
22
|
-
return asString.startsWith("[object ") ? JSON.stringify(value2) : asString;
|
|
23
|
-
}
|
|
24
|
-
function parse(value2, reviver) {
|
|
25
|
-
try {
|
|
26
|
-
return JSON.parse(value2, reviver);
|
|
27
|
-
} catch {
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
// src/internal/element-value.ts
|
|
31
|
-
function setElementValues(element, first, second, callback) {
|
|
32
|
-
if (isPlainObject(first)) {
|
|
33
|
-
const entries = Object.entries(first);
|
|
34
|
-
const { length } = entries;
|
|
35
|
-
for (let index = 0;index < length; index += 1) {
|
|
36
|
-
const [key, value2] = entries[index];
|
|
37
|
-
callback(element, key, value2);
|
|
38
|
-
}
|
|
39
|
-
} else if (first != null) {
|
|
40
|
-
callback(element, first, second);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
function updateElementValue(element, key, value2, set3, remove, json) {
|
|
44
|
-
if (isNullableOrWhitespace(value2)) {
|
|
45
|
-
remove.call(element, key);
|
|
46
|
-
} else {
|
|
47
|
-
set3.call(element, key, json ? JSON.stringify(value2) : String(value2));
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// src/data.ts
|
|
1
|
+
import { parse } from "@oscarpalmer/atoms/string";
|
|
2
|
+
import { setElementValues, updateElementValue } from "./internal/element-value.js";
|
|
52
3
|
function getData(element, keys) {
|
|
53
4
|
if (typeof keys === "string") {
|
|
54
5
|
return getDataValue(element, keys);
|
|
55
6
|
}
|
|
56
7
|
const { length } = keys;
|
|
57
8
|
const data = {};
|
|
58
|
-
for (let index = 0;index < length; index += 1) {
|
|
9
|
+
for (let index = 0; index < length; index += 1) {
|
|
59
10
|
const key = keys[index];
|
|
60
11
|
data[key] = getDataValue(element, key);
|
|
61
12
|
}
|
|
62
13
|
return data;
|
|
63
14
|
}
|
|
64
15
|
function getDataValue(element, key) {
|
|
65
|
-
const
|
|
66
|
-
if (
|
|
67
|
-
return parse(
|
|
16
|
+
const value = element.dataset[key];
|
|
17
|
+
if (value != null) {
|
|
18
|
+
return parse(value);
|
|
68
19
|
}
|
|
69
20
|
}
|
|
70
21
|
function setData(element, first, second) {
|
|
71
22
|
setElementValues(element, first, second, updateDataAttribute);
|
|
72
23
|
}
|
|
73
|
-
function updateDataAttribute(element, key,
|
|
74
|
-
updateElementValue(
|
|
24
|
+
function updateDataAttribute(element, key, value) {
|
|
25
|
+
updateElementValue(
|
|
26
|
+
element,
|
|
27
|
+
`data-${key}`,
|
|
28
|
+
value,
|
|
29
|
+
element.setAttribute,
|
|
30
|
+
element.removeAttribute,
|
|
31
|
+
true
|
|
32
|
+
);
|
|
75
33
|
}
|
|
76
34
|
export {
|
|
77
|
-
|
|
78
|
-
|
|
35
|
+
getData,
|
|
36
|
+
setData
|
|
79
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 value2 !== "object" || value2 === null) {
|
|
4
|
-
return false;
|
|
5
|
-
}
|
|
6
|
-
const prototype = Object.getPrototypeOf(value2);
|
|
7
|
-
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value2) && !(Symbol.iterator in value2);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// src/internal/get-value.ts
|
|
11
|
-
function getBoolean(value2, defaultValue) {
|
|
12
|
-
return typeof value2 === "boolean" ? value2 : 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,32 +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
|
|
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
|
|
38
29
|
};
|
|
39
30
|
}
|
|
40
31
|
function dispatch(target, type, options) {
|
|
41
32
|
target.dispatchEvent(createEvent(type, options));
|
|
42
33
|
}
|
|
43
34
|
function getPosition(event) {
|
|
35
|
+
var _a, _b;
|
|
44
36
|
let x;
|
|
45
37
|
let y;
|
|
46
38
|
if (event instanceof MouseEvent) {
|
|
47
39
|
x = event.clientX;
|
|
48
40
|
y = event.clientY;
|
|
49
41
|
} else if (event instanceof TouchEvent) {
|
|
50
|
-
x = event.touches[0]
|
|
51
|
-
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;
|
|
52
44
|
}
|
|
53
|
-
return typeof x === "number" && typeof y === "number" ? { x, y } :
|
|
45
|
+
return typeof x === "number" && typeof y === "number" ? { x, y } : void 0;
|
|
54
46
|
}
|
|
55
47
|
function off(target, type, listener, options) {
|
|
56
48
|
target.removeEventListener(type, listener, createEventOptions(options));
|
|
@@ -63,8 +55,8 @@ function on(target, type, listener, options) {
|
|
|
63
55
|
};
|
|
64
56
|
}
|
|
65
57
|
export {
|
|
66
|
-
|
|
67
|
-
off,
|
|
58
|
+
dispatch,
|
|
68
59
|
getPosition,
|
|
69
|
-
|
|
60
|
+
off,
|
|
61
|
+
on
|
|
70
62
|
};
|