@oscarpalmer/toretto 0.13.0 → 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 +48 -47
- package/dist/attribute.mjs +31 -31
- package/dist/data.js +20 -19
- package/dist/data.mjs +2 -2
- package/dist/event.js +8 -7
- package/dist/event.mjs +4 -3
- package/dist/focusable.js +19 -19
- package/dist/focusable.mjs +19 -19
- package/dist/html.js +32 -32
- package/dist/html.mjs +4 -4
- package/dist/index.js +114 -112
- package/dist/internal/element-value.js +19 -18
- package/dist/internal/element-value.mjs +1 -1
- 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 +14 -7
- package/src/event.ts +1 -0
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
|
}
|
|
@@ -48,22 +78,22 @@ function setProperty(element, first, second) {
|
|
|
48
78
|
function setProperties(element, properties) {
|
|
49
79
|
updateValues(element, properties, updateProperty);
|
|
50
80
|
}
|
|
51
|
-
function updateAttribute(element, name,
|
|
81
|
+
function updateAttribute(element, name, value) {
|
|
52
82
|
const normalised = name.toLowerCase();
|
|
53
83
|
if (booleanAttributes.includes(normalised)) {
|
|
54
|
-
updateProperty(element, name,
|
|
55
|
-
} else if (
|
|
84
|
+
updateProperty(element, name, value, false);
|
|
85
|
+
} else if (value == null) {
|
|
56
86
|
element.removeAttribute(name);
|
|
57
87
|
} else {
|
|
58
|
-
element.setAttribute(name, typeof
|
|
88
|
+
element.setAttribute(name, typeof value === "string" ? value : getString(value));
|
|
59
89
|
}
|
|
60
90
|
}
|
|
61
|
-
function updateProperty(element, name,
|
|
91
|
+
function updateProperty(element, name, value, validate) {
|
|
62
92
|
const actual = validate ?? true ? name.toLowerCase() : name;
|
|
63
93
|
if (actual === "hidden") {
|
|
64
|
-
element.hidden = typeof
|
|
94
|
+
element.hidden = typeof value === "string" && value.toLowerCase() === "until-found" ? "until-found" : value === "" || value === true;
|
|
65
95
|
} else {
|
|
66
|
-
element[actual] =
|
|
96
|
+
element[actual] = value === "" || typeof value === "string" && value.toLowerCase() === actual || value === true;
|
|
67
97
|
}
|
|
68
98
|
}
|
|
69
99
|
function updateValue(element, first, second, callback) {
|
|
@@ -86,35 +116,6 @@ function updateValues(element, values, callback) {
|
|
|
86
116
|
}
|
|
87
117
|
}
|
|
88
118
|
}
|
|
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
119
|
export {
|
|
119
120
|
setProperty,
|
|
120
121
|
setProperties,
|
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
|
}
|
|
@@ -67,35 +96,6 @@ function updateValues(element, values, callback) {
|
|
|
67
96
|
}
|
|
68
97
|
}
|
|
69
98
|
}
|
|
70
|
-
var booleanAttributes = Object.freeze([
|
|
71
|
-
"async",
|
|
72
|
-
"autofocus",
|
|
73
|
-
"autoplay",
|
|
74
|
-
"checked",
|
|
75
|
-
"controls",
|
|
76
|
-
"default",
|
|
77
|
-
"defer",
|
|
78
|
-
"disabled",
|
|
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
99
|
export {
|
|
100
100
|
setProperty,
|
|
101
101
|
setProperties,
|
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,15 +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
8
|
}
|
|
9
9
|
|
|
10
10
|
// src/internal/get-value.ts
|
|
11
|
-
function getBoolean(
|
|
12
|
-
return typeof
|
|
11
|
+
function getBoolean(value, defaultValue) {
|
|
12
|
+
return typeof value === "boolean" ? value : defaultValue ?? false;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
// src/event.ts
|
|
@@ -34,7 +34,8 @@ function createEventOptions(options) {
|
|
|
34
34
|
return {
|
|
35
35
|
capture: getBoolean(options?.capture),
|
|
36
36
|
once: getBoolean(options?.once),
|
|
37
|
-
passive: getBoolean(options?.passive, true)
|
|
37
|
+
passive: getBoolean(options?.passive, true),
|
|
38
|
+
signal: options?.signal
|
|
38
39
|
};
|
|
39
40
|
}
|
|
40
41
|
function dispatch(target, type, options) {
|
package/dist/event.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/event.ts
|
|
2
|
-
import {isPlainObject} from "@oscarpalmer/atoms/is";
|
|
3
|
-
import {getBoolean} from "./internal/get-value";
|
|
2
|
+
import { isPlainObject } from "@oscarpalmer/atoms/is";
|
|
3
|
+
import { getBoolean } from "./internal/get-value";
|
|
4
4
|
function createDispatchOptions(options) {
|
|
5
5
|
return {
|
|
6
6
|
bubbles: getBoolean(options?.bubbles),
|
|
@@ -22,7 +22,8 @@ function createEventOptions(options) {
|
|
|
22
22
|
return {
|
|
23
23
|
capture: getBoolean(options?.capture),
|
|
24
24
|
once: getBoolean(options?.once),
|
|
25
|
-
passive: getBoolean(options?.passive, true)
|
|
25
|
+
passive: getBoolean(options?.passive, true),
|
|
26
|
+
signal: options?.signal
|
|
26
27
|
};
|
|
27
28
|
}
|
|
28
29
|
function dispatch(target, type, options) {
|
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
|
}
|
|
@@ -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
|
}
|
|
@@ -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/html.js
CHANGED
|
@@ -1,26 +1,13 @@
|
|
|
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
8
|
}
|
|
9
9
|
|
|
10
10
|
// src/attribute.ts
|
|
11
|
-
function isBadAttribute(attribute) {
|
|
12
|
-
return onPrefix.test(attribute.name) || sourcePrefix.test(attribute.name) && valuePrefix.test(attribute.value);
|
|
13
|
-
}
|
|
14
|
-
function isEmptyNonBooleanAttribute(attribute) {
|
|
15
|
-
return !booleanAttributes.includes(attribute.name) && attribute.value.trim().length === 0;
|
|
16
|
-
}
|
|
17
|
-
function isInvalidBooleanAttribute(attribute) {
|
|
18
|
-
if (!booleanAttributes.includes(attribute.name)) {
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
const normalised = attribute.value.toLowerCase().trim();
|
|
22
|
-
return !(normalised.length === 0 || normalised === attribute.name || attribute.name === "hidden" && normalised === "until-found");
|
|
23
|
-
}
|
|
24
11
|
var booleanAttributes = Object.freeze([
|
|
25
12
|
"async",
|
|
26
13
|
"autofocus",
|
|
@@ -50,21 +37,34 @@ var booleanAttributes = Object.freeze([
|
|
|
50
37
|
var onPrefix = /^on/i;
|
|
51
38
|
var sourcePrefix = /^(href|src|xlink:href)$/i;
|
|
52
39
|
var valuePrefix = /(data:text\/html|javascript:)/i;
|
|
40
|
+
function isBadAttribute(attribute) {
|
|
41
|
+
return onPrefix.test(attribute.name) || sourcePrefix.test(attribute.name) && valuePrefix.test(attribute.value);
|
|
42
|
+
}
|
|
43
|
+
function isEmptyNonBooleanAttribute(attribute) {
|
|
44
|
+
return !booleanAttributes.includes(attribute.name) && attribute.value.trim().length === 0;
|
|
45
|
+
}
|
|
46
|
+
function isInvalidBooleanAttribute(attribute) {
|
|
47
|
+
if (!booleanAttributes.includes(attribute.name)) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
const normalised = attribute.value.toLowerCase().trim();
|
|
51
|
+
return !(normalised.length === 0 || normalised === attribute.name || attribute.name === "hidden" && normalised === "until-found");
|
|
52
|
+
}
|
|
53
53
|
|
|
54
54
|
// src/sanitise.ts
|
|
55
|
-
function sanitise(
|
|
56
|
-
return sanitiseNodes(Array.isArray(
|
|
55
|
+
function sanitise(value, options) {
|
|
56
|
+
return sanitiseNodes(Array.isArray(value) ? value : [value], {
|
|
57
57
|
sanitiseBooleanAttributes: options?.sanitiseBooleanAttributes ?? true
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
function sanitiseAttributes(element, attributes, options) {
|
|
61
61
|
const { length } = attributes;
|
|
62
62
|
for (let index = 0;index < length; index += 1) {
|
|
63
|
-
const
|
|
64
|
-
if (isBadAttribute(
|
|
65
|
-
element.removeAttribute(
|
|
66
|
-
} else if (options.sanitiseBooleanAttributes && isInvalidBooleanAttribute(
|
|
67
|
-
element.setAttribute(
|
|
63
|
+
const attribute = attributes[index];
|
|
64
|
+
if (isBadAttribute(attribute) || isEmptyNonBooleanAttribute(attribute)) {
|
|
65
|
+
element.removeAttribute(attribute.name);
|
|
66
|
+
} else if (options.sanitiseBooleanAttributes && isInvalidBooleanAttribute(attribute)) {
|
|
67
|
+
element.setAttribute(attribute.name, "");
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -81,28 +81,29 @@ function sanitiseNodes(nodes, options) {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
// src/html.ts
|
|
84
|
+
var templates = {};
|
|
84
85
|
function createTemplate(html) {
|
|
85
86
|
const template2 = document.createElement("template");
|
|
86
87
|
template2.innerHTML = html;
|
|
87
88
|
templates[html] = template2;
|
|
88
89
|
return template2;
|
|
89
90
|
}
|
|
90
|
-
function getTemplate(
|
|
91
|
-
if (
|
|
91
|
+
function getTemplate(value) {
|
|
92
|
+
if (value.trim().length === 0) {
|
|
92
93
|
return;
|
|
93
94
|
}
|
|
94
95
|
let template2;
|
|
95
|
-
if (/^[\w-]+$/.test(
|
|
96
|
-
template2 = document.querySelector(`#${
|
|
96
|
+
if (/^[\w-]+$/.test(value)) {
|
|
97
|
+
template2 = document.querySelector(`#${value}`);
|
|
97
98
|
}
|
|
98
99
|
if (template2 instanceof HTMLTemplateElement) {
|
|
99
100
|
return template2;
|
|
100
101
|
}
|
|
101
|
-
return templates[
|
|
102
|
+
return templates[value] ?? createTemplate(value);
|
|
102
103
|
}
|
|
103
|
-
function html(
|
|
104
|
+
function html(value, sanitisation) {
|
|
104
105
|
const options = sanitisation == null || sanitisation === true ? {} : isPlainObject(sanitisation) ? { ...sanitisation } : null;
|
|
105
|
-
const template2 =
|
|
106
|
+
const template2 = value instanceof HTMLTemplateElement ? value : typeof value === "string" ? getTemplate(value) : null;
|
|
106
107
|
if (template2 == null) {
|
|
107
108
|
return [];
|
|
108
109
|
}
|
|
@@ -115,7 +116,6 @@ function html(value2, sanitisation) {
|
|
|
115
116
|
cloned.normalize();
|
|
116
117
|
return options != null ? sanitise([...cloned.childNodes], options) : [...cloned.childNodes];
|
|
117
118
|
}
|
|
118
|
-
var templates = {};
|
|
119
119
|
export {
|
|
120
120
|
html
|
|
121
121
|
};
|
package/dist/html.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/html.ts
|
|
2
|
-
import {isPlainObject} from "@oscarpalmer/atoms/is";
|
|
3
|
-
import {sanitise
|
|
2
|
+
import { isPlainObject } from "@oscarpalmer/atoms/is";
|
|
3
|
+
import { sanitise } from "./sanitise";
|
|
4
|
+
var templates = {};
|
|
4
5
|
function createTemplate(html) {
|
|
5
6
|
const template = document.createElement("template");
|
|
6
7
|
template.innerHTML = html;
|
|
@@ -33,9 +34,8 @@ function html(value, sanitisation) {
|
|
|
33
34
|
scripts[index].remove();
|
|
34
35
|
}
|
|
35
36
|
cloned.normalize();
|
|
36
|
-
return options != null ?
|
|
37
|
+
return options != null ? sanitise([...cloned.childNodes], options) : [...cloned.childNodes];
|
|
37
38
|
}
|
|
38
|
-
var templates = {};
|
|
39
39
|
export {
|
|
40
40
|
html
|
|
41
41
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,34 +1,64 @@
|
|
|
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
|
-
function parse(
|
|
13
|
+
function parse(value, reviver) {
|
|
14
14
|
try {
|
|
15
|
-
return JSON.parse(
|
|
15
|
+
return JSON.parse(value, reviver);
|
|
16
16
|
} catch {
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
+
|
|
19
20
|
// node_modules/@oscarpalmer/atoms/dist/js/is.mjs
|
|
20
|
-
function isNullableOrWhitespace(
|
|
21
|
-
return
|
|
21
|
+
function isNullableOrWhitespace(value) {
|
|
22
|
+
return value == null || /^\s*$/.test(getString(value));
|
|
22
23
|
}
|
|
23
|
-
function isPlainObject(
|
|
24
|
-
if (typeof
|
|
24
|
+
function isPlainObject(value) {
|
|
25
|
+
if (typeof value !== "object" || value === null) {
|
|
25
26
|
return false;
|
|
26
27
|
}
|
|
27
|
-
const prototype = Object.getPrototypeOf(
|
|
28
|
-
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in
|
|
28
|
+
const prototype = Object.getPrototypeOf(value);
|
|
29
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
// src/attribute.ts
|
|
33
|
+
var booleanAttributes = Object.freeze([
|
|
34
|
+
"async",
|
|
35
|
+
"autofocus",
|
|
36
|
+
"autoplay",
|
|
37
|
+
"checked",
|
|
38
|
+
"controls",
|
|
39
|
+
"default",
|
|
40
|
+
"defer",
|
|
41
|
+
"disabled",
|
|
42
|
+
"formnovalidate",
|
|
43
|
+
"hidden",
|
|
44
|
+
"inert",
|
|
45
|
+
"ismap",
|
|
46
|
+
"itemscope",
|
|
47
|
+
"loop",
|
|
48
|
+
"multiple",
|
|
49
|
+
"muted",
|
|
50
|
+
"nomodule",
|
|
51
|
+
"novalidate",
|
|
52
|
+
"open",
|
|
53
|
+
"playsinline",
|
|
54
|
+
"readonly",
|
|
55
|
+
"required",
|
|
56
|
+
"reversed",
|
|
57
|
+
"selected"
|
|
58
|
+
]);
|
|
59
|
+
var onPrefix = /^on/i;
|
|
60
|
+
var sourcePrefix = /^(href|src|xlink:href)$/i;
|
|
61
|
+
var valuePrefix = /(data:text\/html|javascript:)/i;
|
|
32
62
|
function isBadAttribute(attribute) {
|
|
33
63
|
return onPrefix.test(attribute.name) || sourcePrefix.test(attribute.name) && valuePrefix.test(attribute.value);
|
|
34
64
|
}
|
|
@@ -57,22 +87,22 @@ function setProperty(element, first, second) {
|
|
|
57
87
|
function setProperties(element, properties) {
|
|
58
88
|
updateValues(element, properties, updateProperty);
|
|
59
89
|
}
|
|
60
|
-
function updateAttribute(element, name,
|
|
90
|
+
function updateAttribute(element, name, value) {
|
|
61
91
|
const normalised = name.toLowerCase();
|
|
62
92
|
if (booleanAttributes.includes(normalised)) {
|
|
63
|
-
updateProperty(element, name,
|
|
64
|
-
} else if (
|
|
93
|
+
updateProperty(element, name, value, false);
|
|
94
|
+
} else if (value == null) {
|
|
65
95
|
element.removeAttribute(name);
|
|
66
96
|
} else {
|
|
67
|
-
element.setAttribute(name, typeof
|
|
97
|
+
element.setAttribute(name, typeof value === "string" ? value : getString(value));
|
|
68
98
|
}
|
|
69
99
|
}
|
|
70
|
-
function updateProperty(element, name,
|
|
100
|
+
function updateProperty(element, name, value, validate) {
|
|
71
101
|
const actual = validate ?? true ? name.toLowerCase() : name;
|
|
72
102
|
if (actual === "hidden") {
|
|
73
|
-
element.hidden = typeof
|
|
103
|
+
element.hidden = typeof value === "string" && value.toLowerCase() === "until-found" ? "until-found" : value === "" || value === true;
|
|
74
104
|
} else {
|
|
75
|
-
element[actual] =
|
|
105
|
+
element[actual] = value === "" || typeof value === "string" && value.toLowerCase() === actual || value === true;
|
|
76
106
|
}
|
|
77
107
|
}
|
|
78
108
|
function updateValue(element, first, second, callback) {
|
|
@@ -95,53 +125,24 @@ function updateValues(element, values, callback) {
|
|
|
95
125
|
}
|
|
96
126
|
}
|
|
97
127
|
}
|
|
98
|
-
var booleanAttributes = Object.freeze([
|
|
99
|
-
"async",
|
|
100
|
-
"autofocus",
|
|
101
|
-
"autoplay",
|
|
102
|
-
"checked",
|
|
103
|
-
"controls",
|
|
104
|
-
"default",
|
|
105
|
-
"defer",
|
|
106
|
-
"disabled",
|
|
107
|
-
"formnovalidate",
|
|
108
|
-
"hidden",
|
|
109
|
-
"inert",
|
|
110
|
-
"ismap",
|
|
111
|
-
"itemscope",
|
|
112
|
-
"loop",
|
|
113
|
-
"multiple",
|
|
114
|
-
"muted",
|
|
115
|
-
"nomodule",
|
|
116
|
-
"novalidate",
|
|
117
|
-
"open",
|
|
118
|
-
"playsinline",
|
|
119
|
-
"readonly",
|
|
120
|
-
"required",
|
|
121
|
-
"reversed",
|
|
122
|
-
"selected"
|
|
123
|
-
]);
|
|
124
|
-
var onPrefix = /^on/i;
|
|
125
|
-
var sourcePrefix = /^(href|src|xlink:href)$/i;
|
|
126
|
-
var valuePrefix = /(data:text\/html|javascript:)/i;
|
|
127
128
|
// src/internal/element-value.ts
|
|
128
129
|
function setElementValues(element, first, second, callback) {
|
|
129
130
|
if (isPlainObject(first)) {
|
|
130
131
|
const entries = Object.entries(first);
|
|
131
132
|
const { length } = entries;
|
|
132
133
|
for (let index = 0;index < length; index += 1) {
|
|
133
|
-
const [key,
|
|
134
|
-
callback(element, key,
|
|
134
|
+
const [key, value] = entries[index];
|
|
135
|
+
callback(element, key, value);
|
|
135
136
|
}
|
|
136
137
|
} else if (first != null) {
|
|
137
138
|
callback(element, first, second);
|
|
138
139
|
}
|
|
139
140
|
}
|
|
140
|
-
function updateElementValue(element, key,
|
|
141
|
-
if (isNullableOrWhitespace(
|
|
141
|
+
function updateElementValue(element, key, value, set2, remove, json) {
|
|
142
|
+
if (isNullableOrWhitespace(value)) {
|
|
142
143
|
remove.call(element, key);
|
|
143
144
|
} else {
|
|
144
|
-
|
|
145
|
+
set2.call(element, key, json ? JSON.stringify(value) : String(value));
|
|
145
146
|
}
|
|
146
147
|
}
|
|
147
148
|
|
|
@@ -159,20 +160,20 @@ function getData(element, keys) {
|
|
|
159
160
|
return data;
|
|
160
161
|
}
|
|
161
162
|
function getDataValue(element, key) {
|
|
162
|
-
const
|
|
163
|
-
if (
|
|
164
|
-
return parse(
|
|
163
|
+
const value = element.dataset[key];
|
|
164
|
+
if (value != null) {
|
|
165
|
+
return parse(value);
|
|
165
166
|
}
|
|
166
167
|
}
|
|
167
168
|
function setData(element, first, second) {
|
|
168
169
|
setElementValues(element, first, second, updateDataAttribute);
|
|
169
170
|
}
|
|
170
|
-
function updateDataAttribute(element, key,
|
|
171
|
-
updateElementValue(element, `data-${key}`,
|
|
171
|
+
function updateDataAttribute(element, key, value) {
|
|
172
|
+
updateElementValue(element, `data-${key}`, value, element.setAttribute, element.removeAttribute, true);
|
|
172
173
|
}
|
|
173
174
|
// src/internal/get-value.ts
|
|
174
|
-
function getBoolean(
|
|
175
|
-
return typeof
|
|
175
|
+
function getBoolean(value, defaultValue) {
|
|
176
|
+
return typeof value === "boolean" ? value : defaultValue ?? false;
|
|
176
177
|
}
|
|
177
178
|
|
|
178
179
|
// src/event.ts
|
|
@@ -197,7 +198,8 @@ function createEventOptions(options) {
|
|
|
197
198
|
return {
|
|
198
199
|
capture: getBoolean(options?.capture),
|
|
199
200
|
once: getBoolean(options?.once),
|
|
200
|
-
passive: getBoolean(options?.passive, true)
|
|
201
|
+
passive: getBoolean(options?.passive, true),
|
|
202
|
+
signal: options?.signal
|
|
201
203
|
};
|
|
202
204
|
}
|
|
203
205
|
function dispatch(target, type, options) {
|
|
@@ -275,16 +277,16 @@ function findElementOrElements(selector, context, single) {
|
|
|
275
277
|
if (typeof selector === "string") {
|
|
276
278
|
const { length: length2 } = contexts;
|
|
277
279
|
for (let index = 0;index < length2; index += 1) {
|
|
278
|
-
const
|
|
280
|
+
const value = callback.call(contexts[index], selector);
|
|
279
281
|
if (single) {
|
|
280
|
-
if (
|
|
282
|
+
if (value == null) {
|
|
281
283
|
continue;
|
|
282
284
|
}
|
|
283
|
-
return
|
|
285
|
+
return value;
|
|
284
286
|
}
|
|
285
|
-
result.push(...Array.from(
|
|
287
|
+
result.push(...Array.from(value));
|
|
286
288
|
}
|
|
287
|
-
return single ? undefined : result.filter((
|
|
289
|
+
return single ? undefined : result.filter((value, index, array) => array.indexOf(value) === index);
|
|
288
290
|
}
|
|
289
291
|
const nodes = Array.isArray(selector) ? selector : selector instanceof NodeList ? Array.from(selector) : [selector];
|
|
290
292
|
const { length } = nodes;
|
|
@@ -370,6 +372,25 @@ function traverse(from, to) {
|
|
|
370
372
|
return -1e6;
|
|
371
373
|
}
|
|
372
374
|
// src/focusable.ts
|
|
375
|
+
var focusableFilters = [isDisabled, isInert, isHidden, isSummarised];
|
|
376
|
+
var selector = [
|
|
377
|
+
'[contenteditable]:not([contenteditable="false"])',
|
|
378
|
+
"[tabindex]:not(slot)",
|
|
379
|
+
"a[href]",
|
|
380
|
+
"audio[controls]",
|
|
381
|
+
"button",
|
|
382
|
+
"details",
|
|
383
|
+
"details > summary:first-of-type",
|
|
384
|
+
"input",
|
|
385
|
+
"select",
|
|
386
|
+
"textarea",
|
|
387
|
+
"video[controls]"
|
|
388
|
+
].map((selector2) => `${selector2}:not([inert])`).join(",");
|
|
389
|
+
var tabbableFilters = [
|
|
390
|
+
isNotTabbable,
|
|
391
|
+
isNotTabbableRadio,
|
|
392
|
+
...focusableFilters
|
|
393
|
+
];
|
|
373
394
|
function getFocusable(parent) {
|
|
374
395
|
return getValidElements(parent, focusableFilters, false);
|
|
375
396
|
}
|
|
@@ -496,39 +517,20 @@ function isValidElement(element, filters, tabbable) {
|
|
|
496
517
|
const item = getItem(element, tabbable);
|
|
497
518
|
return !filters.some((filter2) => filter2(item));
|
|
498
519
|
}
|
|
499
|
-
var focusableFilters = [isDisabled, isInert, isHidden, isSummarised];
|
|
500
|
-
var selector = [
|
|
501
|
-
'[contenteditable]:not([contenteditable="false"])',
|
|
502
|
-
"[tabindex]:not(slot)",
|
|
503
|
-
"a[href]",
|
|
504
|
-
"audio[controls]",
|
|
505
|
-
"button",
|
|
506
|
-
"details",
|
|
507
|
-
"details > summary:first-of-type",
|
|
508
|
-
"input",
|
|
509
|
-
"select",
|
|
510
|
-
"textarea",
|
|
511
|
-
"video[controls]"
|
|
512
|
-
].map((selector2) => `${selector2}:not([inert])`).join(",");
|
|
513
|
-
var tabbableFilters = [
|
|
514
|
-
isNotTabbable,
|
|
515
|
-
isNotTabbableRadio,
|
|
516
|
-
...focusableFilters
|
|
517
|
-
];
|
|
518
520
|
// src/sanitise.ts
|
|
519
|
-
function sanitise(
|
|
520
|
-
return sanitiseNodes(Array.isArray(
|
|
521
|
+
function sanitise(value, options) {
|
|
522
|
+
return sanitiseNodes(Array.isArray(value) ? value : [value], {
|
|
521
523
|
sanitiseBooleanAttributes: options?.sanitiseBooleanAttributes ?? true
|
|
522
524
|
});
|
|
523
525
|
}
|
|
524
526
|
function sanitiseAttributes(element, attributes, options) {
|
|
525
527
|
const { length } = attributes;
|
|
526
528
|
for (let index = 0;index < length; index += 1) {
|
|
527
|
-
const
|
|
528
|
-
if (isBadAttribute(
|
|
529
|
-
element.removeAttribute(
|
|
530
|
-
} else if (options.sanitiseBooleanAttributes && isInvalidBooleanAttribute(
|
|
531
|
-
element.setAttribute(
|
|
529
|
+
const attribute = attributes[index];
|
|
530
|
+
if (isBadAttribute(attribute) || isEmptyNonBooleanAttribute(attribute)) {
|
|
531
|
+
element.removeAttribute(attribute.name);
|
|
532
|
+
} else if (options.sanitiseBooleanAttributes && isInvalidBooleanAttribute(attribute)) {
|
|
533
|
+
element.setAttribute(attribute.name, "");
|
|
532
534
|
}
|
|
533
535
|
}
|
|
534
536
|
}
|
|
@@ -545,28 +547,29 @@ function sanitiseNodes(nodes, options) {
|
|
|
545
547
|
}
|
|
546
548
|
|
|
547
549
|
// src/html.ts
|
|
550
|
+
var templates = {};
|
|
548
551
|
function createTemplate(html) {
|
|
549
552
|
const template2 = document.createElement("template");
|
|
550
553
|
template2.innerHTML = html;
|
|
551
554
|
templates[html] = template2;
|
|
552
555
|
return template2;
|
|
553
556
|
}
|
|
554
|
-
function getTemplate(
|
|
555
|
-
if (
|
|
557
|
+
function getTemplate(value) {
|
|
558
|
+
if (value.trim().length === 0) {
|
|
556
559
|
return;
|
|
557
560
|
}
|
|
558
561
|
let template2;
|
|
559
|
-
if (/^[\w-]+$/.test(
|
|
560
|
-
template2 = document.querySelector(`#${
|
|
562
|
+
if (/^[\w-]+$/.test(value)) {
|
|
563
|
+
template2 = document.querySelector(`#${value}`);
|
|
561
564
|
}
|
|
562
565
|
if (template2 instanceof HTMLTemplateElement) {
|
|
563
566
|
return template2;
|
|
564
567
|
}
|
|
565
|
-
return templates[
|
|
568
|
+
return templates[value] ?? createTemplate(value);
|
|
566
569
|
}
|
|
567
|
-
function html(
|
|
570
|
+
function html(value, sanitisation) {
|
|
568
571
|
const options = sanitisation == null || sanitisation === true ? {} : isPlainObject(sanitisation) ? { ...sanitisation } : null;
|
|
569
|
-
const template2 =
|
|
572
|
+
const template2 = value instanceof HTMLTemplateElement ? value : typeof value === "string" ? getTemplate(value) : null;
|
|
570
573
|
if (template2 == null) {
|
|
571
574
|
return [];
|
|
572
575
|
}
|
|
@@ -579,13 +582,12 @@ function html(value2, sanitisation) {
|
|
|
579
582
|
cloned.normalize();
|
|
580
583
|
return options != null ? sanitise([...cloned.childNodes], options) : [...cloned.childNodes];
|
|
581
584
|
}
|
|
582
|
-
var templates = {};
|
|
583
585
|
// src/is.ts
|
|
584
|
-
function isChildNode(
|
|
585
|
-
return
|
|
586
|
+
function isChildNode(value, ignoreDocumentType) {
|
|
587
|
+
return value instanceof CharacterData || (value instanceof DocumentType ? ignoreDocumentType !== true : false) || value instanceof Element;
|
|
586
588
|
}
|
|
587
|
-
function isHTMLOrSVGElement(
|
|
588
|
-
return
|
|
589
|
+
function isHTMLOrSVGElement(value) {
|
|
590
|
+
return value instanceof HTMLElement || value instanceof SVGElement;
|
|
589
591
|
}
|
|
590
592
|
function isInDocument(node, document2) {
|
|
591
593
|
return document2 == null ? node.ownerDocument?.contains(node) ?? false : node.ownerDocument === document2 && document2.contains(node);
|
|
@@ -610,15 +612,15 @@ function getTextDirection(element) {
|
|
|
610
612
|
}
|
|
611
613
|
return getComputedStyle?.(element)?.direction === "rtl" ? "rtl" : "ltr";
|
|
612
614
|
}
|
|
613
|
-
function setStyle(element, property,
|
|
614
|
-
setElementValues(element, property,
|
|
615
|
+
function setStyle(element, property, value) {
|
|
616
|
+
setElementValues(element, property, value, updateStyleProperty);
|
|
615
617
|
}
|
|
616
618
|
function setStyles(element, styles) {
|
|
617
619
|
setElementValues(element, styles, null, updateStyleProperty);
|
|
618
620
|
}
|
|
619
|
-
function updateStyleProperty(element, key,
|
|
620
|
-
updateElementValue(element, key,
|
|
621
|
-
this.style[property] =
|
|
621
|
+
function updateStyleProperty(element, key, value) {
|
|
622
|
+
updateElementValue(element, key, value, function(property, value2) {
|
|
623
|
+
this.style[property] = value2;
|
|
622
624
|
}, function(property) {
|
|
623
625
|
this.style[property] = "";
|
|
624
626
|
}, false);
|
|
@@ -1,25 +1,26 @@
|
|
|
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 isNullableOrWhitespace(
|
|
15
|
-
return
|
|
15
|
+
function isNullableOrWhitespace(value) {
|
|
16
|
+
return value == null || /^\s*$/.test(getString(value));
|
|
16
17
|
}
|
|
17
|
-
function isPlainObject(
|
|
18
|
-
if (typeof
|
|
18
|
+
function isPlainObject(value) {
|
|
19
|
+
if (typeof value !== "object" || value === null) {
|
|
19
20
|
return false;
|
|
20
21
|
}
|
|
21
|
-
const prototype = Object.getPrototypeOf(
|
|
22
|
-
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in
|
|
22
|
+
const prototype = Object.getPrototypeOf(value);
|
|
23
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
// src/internal/element-value.ts
|
|
@@ -28,18 +29,18 @@ function setElementValues(element, first, second, callback) {
|
|
|
28
29
|
const entries = Object.entries(first);
|
|
29
30
|
const { length } = entries;
|
|
30
31
|
for (let index = 0;index < length; index += 1) {
|
|
31
|
-
const [key,
|
|
32
|
-
callback(element, key,
|
|
32
|
+
const [key, value] = entries[index];
|
|
33
|
+
callback(element, key, value);
|
|
33
34
|
}
|
|
34
35
|
} else if (first != null) {
|
|
35
36
|
callback(element, first, second);
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
|
-
function updateElementValue(element, key,
|
|
39
|
-
if (isNullableOrWhitespace(
|
|
39
|
+
function updateElementValue(element, key, value, set2, remove, json) {
|
|
40
|
+
if (isNullableOrWhitespace(value)) {
|
|
40
41
|
remove.call(element, key);
|
|
41
42
|
} else {
|
|
42
|
-
|
|
43
|
+
set2.call(element, key, json ? JSON.stringify(value) : String(value));
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
export {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/internal/element-value.ts
|
|
2
|
-
import {isNullableOrWhitespace, isPlainObject} from "@oscarpalmer/atoms/is";
|
|
2
|
+
import { isNullableOrWhitespace, isPlainObject } from "@oscarpalmer/atoms/is";
|
|
3
3
|
function setElementValues(element, first, second, callback) {
|
|
4
4
|
if (isPlainObject(first)) {
|
|
5
5
|
const entries = Object.entries(first);
|
package/dist/sanitise.js
CHANGED
|
@@ -1,17 +1,4 @@
|
|
|
1
1
|
// src/attribute.ts
|
|
2
|
-
function isBadAttribute(attribute) {
|
|
3
|
-
return onPrefix.test(attribute.name) || sourcePrefix.test(attribute.name) && valuePrefix.test(attribute.value);
|
|
4
|
-
}
|
|
5
|
-
function isEmptyNonBooleanAttribute(attribute) {
|
|
6
|
-
return !booleanAttributes.includes(attribute.name) && attribute.value.trim().length === 0;
|
|
7
|
-
}
|
|
8
|
-
function isInvalidBooleanAttribute(attribute) {
|
|
9
|
-
if (!booleanAttributes.includes(attribute.name)) {
|
|
10
|
-
return true;
|
|
11
|
-
}
|
|
12
|
-
const normalised = attribute.value.toLowerCase().trim();
|
|
13
|
-
return !(normalised.length === 0 || normalised === attribute.name || attribute.name === "hidden" && normalised === "until-found");
|
|
14
|
-
}
|
|
15
2
|
var booleanAttributes = Object.freeze([
|
|
16
3
|
"async",
|
|
17
4
|
"autofocus",
|
|
@@ -41,21 +28,34 @@ var booleanAttributes = Object.freeze([
|
|
|
41
28
|
var onPrefix = /^on/i;
|
|
42
29
|
var sourcePrefix = /^(href|src|xlink:href)$/i;
|
|
43
30
|
var valuePrefix = /(data:text\/html|javascript:)/i;
|
|
31
|
+
function isBadAttribute(attribute) {
|
|
32
|
+
return onPrefix.test(attribute.name) || sourcePrefix.test(attribute.name) && valuePrefix.test(attribute.value);
|
|
33
|
+
}
|
|
34
|
+
function isEmptyNonBooleanAttribute(attribute) {
|
|
35
|
+
return !booleanAttributes.includes(attribute.name) && attribute.value.trim().length === 0;
|
|
36
|
+
}
|
|
37
|
+
function isInvalidBooleanAttribute(attribute) {
|
|
38
|
+
if (!booleanAttributes.includes(attribute.name)) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
const normalised = attribute.value.toLowerCase().trim();
|
|
42
|
+
return !(normalised.length === 0 || normalised === attribute.name || attribute.name === "hidden" && normalised === "until-found");
|
|
43
|
+
}
|
|
44
44
|
|
|
45
45
|
// src/sanitise.ts
|
|
46
|
-
function sanitise(
|
|
47
|
-
return sanitiseNodes(Array.isArray(
|
|
46
|
+
function sanitise(value, options) {
|
|
47
|
+
return sanitiseNodes(Array.isArray(value) ? value : [value], {
|
|
48
48
|
sanitiseBooleanAttributes: options?.sanitiseBooleanAttributes ?? true
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
function sanitiseAttributes(element, attributes, options) {
|
|
52
52
|
const { length } = attributes;
|
|
53
53
|
for (let index = 0;index < length; index += 1) {
|
|
54
|
-
const
|
|
55
|
-
if (isBadAttribute(
|
|
56
|
-
element.removeAttribute(
|
|
57
|
-
} else if (options.sanitiseBooleanAttributes && isInvalidBooleanAttribute(
|
|
58
|
-
element.setAttribute(
|
|
54
|
+
const attribute = attributes[index];
|
|
55
|
+
if (isBadAttribute(attribute) || isEmptyNonBooleanAttribute(attribute)) {
|
|
56
|
+
element.removeAttribute(attribute.name);
|
|
57
|
+
} else if (options.sanitiseBooleanAttributes && isInvalidBooleanAttribute(attribute)) {
|
|
58
|
+
element.setAttribute(attribute.name, "");
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
}
|
package/dist/sanitise.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/sanitise.ts
|
|
2
2
|
import {
|
|
3
|
-
isBadAttribute,
|
|
4
|
-
isEmptyNonBooleanAttribute,
|
|
5
|
-
isInvalidBooleanAttribute
|
|
3
|
+
isBadAttribute,
|
|
4
|
+
isEmptyNonBooleanAttribute,
|
|
5
|
+
isInvalidBooleanAttribute
|
|
6
6
|
} from "./attribute";
|
|
7
7
|
function sanitise(value, options) {
|
|
8
8
|
return sanitiseNodes(Array.isArray(value) ? value : [value], {
|
|
@@ -12,11 +12,11 @@ function sanitise(value, options) {
|
|
|
12
12
|
function sanitiseAttributes(element, attributes, options) {
|
|
13
13
|
const { length } = attributes;
|
|
14
14
|
for (let index = 0;index < length; index += 1) {
|
|
15
|
-
const
|
|
16
|
-
if (isBadAttribute(
|
|
17
|
-
element.removeAttribute(
|
|
18
|
-
} else if (options.sanitiseBooleanAttributes && isInvalidBooleanAttribute(
|
|
19
|
-
element.setAttribute(
|
|
15
|
+
const attribute = attributes[index];
|
|
16
|
+
if (isBadAttribute(attribute) || isEmptyNonBooleanAttribute(attribute)) {
|
|
17
|
+
element.removeAttribute(attribute.name);
|
|
18
|
+
} else if (options.sanitiseBooleanAttributes && isInvalidBooleanAttribute(attribute)) {
|
|
19
|
+
element.setAttribute(attribute.name, "");
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
}
|
package/dist/style.js
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
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 isNullableOrWhitespace(
|
|
15
|
-
return
|
|
15
|
+
function isNullableOrWhitespace(value) {
|
|
16
|
+
return value == null || /^\s*$/.test(getString(value));
|
|
16
17
|
}
|
|
17
|
-
function isPlainObject(
|
|
18
|
-
if (typeof
|
|
18
|
+
function isPlainObject(value) {
|
|
19
|
+
if (typeof value !== "object" || value === null) {
|
|
19
20
|
return false;
|
|
20
21
|
}
|
|
21
|
-
const prototype = Object.getPrototypeOf(
|
|
22
|
-
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in
|
|
22
|
+
const prototype = Object.getPrototypeOf(value);
|
|
23
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
// src/internal/element-value.ts
|
|
@@ -28,18 +29,18 @@ function setElementValues(element, first, second, callback) {
|
|
|
28
29
|
const entries = Object.entries(first);
|
|
29
30
|
const { length } = entries;
|
|
30
31
|
for (let index = 0;index < length; index += 1) {
|
|
31
|
-
const [key,
|
|
32
|
-
callback(element, key,
|
|
32
|
+
const [key, value] = entries[index];
|
|
33
|
+
callback(element, key, value);
|
|
33
34
|
}
|
|
34
35
|
} else if (first != null) {
|
|
35
36
|
callback(element, first, second);
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
|
-
function updateElementValue(element, key,
|
|
39
|
-
if (isNullableOrWhitespace(
|
|
39
|
+
function updateElementValue(element, key, value, set2, remove, json) {
|
|
40
|
+
if (isNullableOrWhitespace(value)) {
|
|
40
41
|
remove.call(element, key);
|
|
41
42
|
} else {
|
|
42
|
-
|
|
43
|
+
set2.call(element, key, json ? JSON.stringify(value) : String(value));
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
|
|
@@ -63,15 +64,15 @@ function getTextDirection(element) {
|
|
|
63
64
|
}
|
|
64
65
|
return getComputedStyle?.(element)?.direction === "rtl" ? "rtl" : "ltr";
|
|
65
66
|
}
|
|
66
|
-
function setStyle(element, property,
|
|
67
|
-
setElementValues(element, property,
|
|
67
|
+
function setStyle(element, property, value) {
|
|
68
|
+
setElementValues(element, property, value, updateStyleProperty);
|
|
68
69
|
}
|
|
69
70
|
function setStyles(element, styles) {
|
|
70
71
|
setElementValues(element, styles, null, updateStyleProperty);
|
|
71
72
|
}
|
|
72
|
-
function updateStyleProperty(element, key,
|
|
73
|
-
updateElementValue(element, key,
|
|
74
|
-
this.style[property] =
|
|
73
|
+
function updateStyleProperty(element, key, value) {
|
|
74
|
+
updateElementValue(element, key, value, function(property, value2) {
|
|
75
|
+
this.style[property] = value2;
|
|
75
76
|
}, function(property) {
|
|
76
77
|
this.style[property] = "";
|
|
77
78
|
}, false);
|
package/dist/style.mjs
CHANGED
package/package.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
},
|
|
9
9
|
"description": "A collection of badass DOM utilities.",
|
|
10
10
|
"devDependencies": {
|
|
11
|
-
"@biomejs/biome": "^1.9.
|
|
11
|
+
"@biomejs/biome": "^1.9.4",
|
|
12
12
|
"@happy-dom/global-registrator": "^15.7.4",
|
|
13
|
-
"@types/bun": "^1.1.
|
|
14
|
-
"bun": "^1.1.
|
|
13
|
+
"@types/bun": "^1.1.12",
|
|
14
|
+
"bun": "^1.1.33",
|
|
15
15
|
"dts-bundle-generator": "^9.5.1",
|
|
16
16
|
"type-fest": "^4.26.1",
|
|
17
|
-
"typescript": "^5.6.
|
|
17
|
+
"typescript": "^5.6.3"
|
|
18
18
|
},
|
|
19
19
|
"exports": {
|
|
20
20
|
".": {
|
|
@@ -87,8 +87,15 @@
|
|
|
87
87
|
"require": "./dist/style.js"
|
|
88
88
|
}
|
|
89
89
|
},
|
|
90
|
-
"files": [
|
|
91
|
-
|
|
90
|
+
"files": [
|
|
91
|
+
"dist",
|
|
92
|
+
"src",
|
|
93
|
+
"types"
|
|
94
|
+
],
|
|
95
|
+
"keywords": [
|
|
96
|
+
"dom",
|
|
97
|
+
"utility"
|
|
98
|
+
],
|
|
92
99
|
"license": "MIT",
|
|
93
100
|
"main": "dist/index.js",
|
|
94
101
|
"module": "dist/index.mjs",
|
|
@@ -109,5 +116,5 @@
|
|
|
109
116
|
},
|
|
110
117
|
"type": "module",
|
|
111
118
|
"types": "types/index.d.cts",
|
|
112
|
-
"version": "0.
|
|
119
|
+
"version": "0.14.0"
|
|
113
120
|
}
|