@oscarpalmer/toretto 0.27.0 → 0.28.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/event/delegation.js +18 -19
- package/dist/toretto.full.js +49 -89
- package/package.json +5 -4
- package/src/attribute/set.ts +10 -44
- package/src/data.ts +3 -15
- package/src/event/delegation.ts +29 -35
- package/src/event/index.ts +5 -23
- package/src/find/index.ts +10 -26
- package/src/find/relative.ts +4 -16
- package/src/focusable.ts +15 -51
- package/src/html.ts +10 -37
- package/src/internal/attribute.ts +11 -45
- package/src/internal/element-value.ts +0 -1
- package/src/internal/get-value.ts +2 -6
- package/src/internal/sanitize.ts +3 -14
- package/src/is.ts +1 -1
- package/src/style.ts +4 -18
- package/src/touch.ts +2 -6
package/dist/event/delegation.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { isEventTarget } from "../internal/is.js";
|
|
2
2
|
function addDelegatedHandler(document$1, type, name, passive) {
|
|
3
|
-
const
|
|
4
|
-
if (document$1[
|
|
5
|
-
document$1[
|
|
3
|
+
const count = `${name}${COUNT_SUFFIX}`;
|
|
4
|
+
if (document$1[count] != null) {
|
|
5
|
+
document$1[count] += 1;
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
8
|
-
document$1[
|
|
8
|
+
document$1[count] = 1;
|
|
9
9
|
document$1.addEventListener(type, passive ? HANDLER_PASSIVE : HANDLER_ACTIVE, { passive });
|
|
10
10
|
}
|
|
11
11
|
function addDelegatedListener(target, type, name, listener, passive) {
|
|
@@ -27,15 +27,14 @@ function delegatedEventHandler(event) {
|
|
|
27
27
|
for (let index = 0; index < length; index += 1) {
|
|
28
28
|
const item = items[index];
|
|
29
29
|
const listeners = item[key];
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
30
|
+
if (item.disabled || listeners == null) continue;
|
|
31
|
+
Object.defineProperty(event, "currentTarget", {
|
|
32
|
+
configurable: true,
|
|
33
|
+
value: item
|
|
34
|
+
});
|
|
35
|
+
for (const listener of listeners) {
|
|
36
|
+
listener.call(item, event);
|
|
37
|
+
if (event.cancelBubble) return;
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
40
|
}
|
|
@@ -43,10 +42,10 @@ function getDelegatedName(target, type, options) {
|
|
|
43
42
|
if (isEventTarget(target) && EVENT_TYPES.has(type) && !options.capture && !options.once && options.signal == null) return `${EVENT_PREFIX}${type}${options.passive ? EVENT_SUFFIX_PASSIVE : EVENT_SUFFIX_ACTIVE}`;
|
|
44
43
|
}
|
|
45
44
|
function removeDelegatedHandler(document$1, type, name, passive) {
|
|
46
|
-
const
|
|
47
|
-
document$1[
|
|
48
|
-
if (document$1[
|
|
49
|
-
document$1[
|
|
45
|
+
const count = `${name}${COUNT_SUFFIX}`;
|
|
46
|
+
document$1[count] -= 1;
|
|
47
|
+
if (document$1[count] < 1) {
|
|
48
|
+
document$1[count] = void 0;
|
|
50
49
|
document$1.removeEventListener(type, passive ? HANDLER_PASSIVE : HANDLER_ACTIVE);
|
|
51
50
|
}
|
|
52
51
|
}
|
|
@@ -54,10 +53,11 @@ function removeDelegatedListener(target, type, name, listener, passive) {
|
|
|
54
53
|
const handlers = target[name];
|
|
55
54
|
if (handlers == null || !handlers.has(listener)) return false;
|
|
56
55
|
handlers.delete(listener);
|
|
57
|
-
if (handlers
|
|
56
|
+
if (handlers.size === 0) target[name] = void 0;
|
|
58
57
|
removeDelegatedHandler(document, type, name, passive);
|
|
59
58
|
return true;
|
|
60
59
|
}
|
|
60
|
+
var COUNT_SUFFIX = ".count";
|
|
61
61
|
var EVENT_PREFIX = "@";
|
|
62
62
|
var EVENT_SUFFIX_ACTIVE = ":active";
|
|
63
63
|
var EVENT_SUFFIX_PASSIVE = ":passive";
|
|
@@ -87,5 +87,4 @@ var EVENT_TYPES = new Set([
|
|
|
87
87
|
]);
|
|
88
88
|
var HANDLER_ACTIVE = delegatedEventHandler.bind(false);
|
|
89
89
|
var HANDLER_PASSIVE = delegatedEventHandler.bind(true);
|
|
90
|
-
var LISTENERS_SUFFIX = ":listeners";
|
|
91
90
|
export { addDelegatedListener, getDelegatedName, removeDelegatedListener };
|
package/dist/toretto.full.js
CHANGED
|
@@ -12,12 +12,10 @@ function getSupport() {
|
|
|
12
12
|
if ('ontouchstart' in window) {
|
|
13
13
|
return true;
|
|
14
14
|
}
|
|
15
|
-
if (typeof navigator.maxTouchPoints === 'number' &&
|
|
16
|
-
navigator.maxTouchPoints > 0) {
|
|
15
|
+
if (typeof navigator.maxTouchPoints === 'number' && navigator.maxTouchPoints > 0) {
|
|
17
16
|
return true;
|
|
18
17
|
}
|
|
19
|
-
if (typeof navigator.msMaxTouchPoints ===
|
|
20
|
-
'number' &&
|
|
18
|
+
if (typeof navigator.msMaxTouchPoints === 'number' &&
|
|
21
19
|
navigator.msMaxTouchPoints > 0) {
|
|
22
20
|
return true;
|
|
23
21
|
}
|
|
@@ -67,6 +65,7 @@ function compact(array, strict) {
|
|
|
67
65
|
function getString(value) {
|
|
68
66
|
if (typeof value === "string") return value;
|
|
69
67
|
if (value == null) return "";
|
|
68
|
+
if (typeof value === "function") return getString(value());
|
|
70
69
|
if (typeof value !== "object") return String(value);
|
|
71
70
|
const asString = String(value.valueOf?.() ?? value);
|
|
72
71
|
return asString.startsWith("[object ") ? JSON.stringify(value) : asString;
|
|
@@ -161,8 +160,7 @@ function isBadAttribute(first, second) {
|
|
|
161
160
|
EXPRESSION_VALUE_PREFIX.test(String(attribute.value))), first, second);
|
|
162
161
|
}
|
|
163
162
|
function isBooleanAttribute(value) {
|
|
164
|
-
return isValidAttribute(attribute => attribute != null &&
|
|
165
|
-
booleanAttributes.includes(attribute.name.toLowerCase()), value, '');
|
|
163
|
+
return isValidAttribute(attribute => attribute != null && booleanAttributes.includes(attribute.name.toLowerCase()), value, '');
|
|
166
164
|
}
|
|
167
165
|
function isEmptyNonBooleanAttribute(first, second) {
|
|
168
166
|
return isValidAttribute(attribute => attribute != null &&
|
|
@@ -182,7 +180,7 @@ function isInvalidBooleanAttribute(first, second) {
|
|
|
182
180
|
}, first, second);
|
|
183
181
|
}
|
|
184
182
|
function isProperty(value) {
|
|
185
|
-
return
|
|
183
|
+
return isPlainObject(value) && typeof value.name === 'string';
|
|
186
184
|
}
|
|
187
185
|
function isValidAttribute(callback, first, second) {
|
|
188
186
|
let attribute;
|
|
@@ -209,9 +207,7 @@ function updateAttribute(element, name, value) {
|
|
|
209
207
|
function updateProperty(element, name, value) {
|
|
210
208
|
const actual = name.toLowerCase();
|
|
211
209
|
element[actual] =
|
|
212
|
-
value === '' ||
|
|
213
|
-
(typeof value === 'string' && value.toLowerCase() === actual) ||
|
|
214
|
-
value === true;
|
|
210
|
+
value === '' || (typeof value === 'string' && value.toLowerCase() === actual) || value === true;
|
|
215
211
|
}
|
|
216
212
|
function updateValue(element, first, second) {
|
|
217
213
|
if (!isHTMLOrSVGElement(element)) {
|
|
@@ -282,17 +278,13 @@ function getAttributeValue(element, name, parseValue) {
|
|
|
282
278
|
const normalized = kebabCase(name);
|
|
283
279
|
const attribute = element.attributes[normalized];
|
|
284
280
|
const value = attribute instanceof Attr ? attribute.value : undefined;
|
|
285
|
-
return EXPRESSION_DATA_PREFIX.test(normalized) &&
|
|
286
|
-
typeof value === 'string' &&
|
|
287
|
-
parseValue
|
|
281
|
+
return EXPRESSION_DATA_PREFIX.test(normalized) && typeof value === 'string' && parseValue
|
|
288
282
|
? (parse(value) ?? value)
|
|
289
283
|
: value;
|
|
290
284
|
}
|
|
291
285
|
function getStyleValue(element, property, computed) {
|
|
292
286
|
const name = camelCase(property);
|
|
293
|
-
return computed
|
|
294
|
-
? getComputedStyle(element)[name]
|
|
295
|
-
: element.style[name];
|
|
287
|
+
return computed ? getComputedStyle(element)[name] : element.style[name];
|
|
296
288
|
}
|
|
297
289
|
const EXPRESSION_DATA_PREFIX = /^data-/i;
|
|
298
290
|
|
|
@@ -381,7 +373,6 @@ function setElementValues(element, first, second, callback) {
|
|
|
381
373
|
callback(element, first, second);
|
|
382
374
|
}
|
|
383
375
|
}
|
|
384
|
-
// biome-ignore lint/nursery/useMaxParams: Internal function, so it's fine
|
|
385
376
|
function updateElementValue(element, key, value, set, remove, json) {
|
|
386
377
|
if (isNullableOrWhitespace(value)) {
|
|
387
378
|
remove.call(element, key);
|
|
@@ -449,12 +440,12 @@ calculate().then((value) => {
|
|
|
449
440
|
});
|
|
450
441
|
|
|
451
442
|
function addDelegatedHandler(document, type, name, passive) {
|
|
452
|
-
const
|
|
453
|
-
if (document[
|
|
454
|
-
document[
|
|
443
|
+
const count = `${name}${COUNT_SUFFIX}`;
|
|
444
|
+
if (document[count] != null) {
|
|
445
|
+
document[count] += 1;
|
|
455
446
|
return;
|
|
456
447
|
}
|
|
457
|
-
document[
|
|
448
|
+
document[count] = 1;
|
|
458
449
|
document.addEventListener(type, passive ? HANDLER_PASSIVE : HANDLER_ACTIVE, {
|
|
459
450
|
passive,
|
|
460
451
|
});
|
|
@@ -478,16 +469,17 @@ function delegatedEventHandler(event) {
|
|
|
478
469
|
for (let index = 0; index < length; index += 1) {
|
|
479
470
|
const item = items[index];
|
|
480
471
|
const listeners = item[key];
|
|
481
|
-
if (
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
472
|
+
if (item.disabled || listeners == null) {
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
Object.defineProperty(event, 'currentTarget', {
|
|
476
|
+
configurable: true,
|
|
477
|
+
value: item,
|
|
478
|
+
});
|
|
479
|
+
for (const listener of listeners) {
|
|
480
|
+
listener.call(item, event);
|
|
481
|
+
if (event.cancelBubble) {
|
|
482
|
+
return;
|
|
491
483
|
}
|
|
492
484
|
}
|
|
493
485
|
}
|
|
@@ -502,10 +494,10 @@ function getDelegatedName(target, type, options) {
|
|
|
502
494
|
}
|
|
503
495
|
}
|
|
504
496
|
function removeDelegatedHandler(document, type, name, passive) {
|
|
505
|
-
const
|
|
506
|
-
document[
|
|
507
|
-
if (document[
|
|
508
|
-
document[
|
|
497
|
+
const count = `${name}${COUNT_SUFFIX}`;
|
|
498
|
+
document[count] -= 1;
|
|
499
|
+
if (document[count] < 1) {
|
|
500
|
+
document[count] = undefined;
|
|
509
501
|
document.removeEventListener(type, passive ? HANDLER_PASSIVE : HANDLER_ACTIVE);
|
|
510
502
|
}
|
|
511
503
|
}
|
|
@@ -515,13 +507,14 @@ function removeDelegatedListener(target, type, name, listener, passive) {
|
|
|
515
507
|
return false;
|
|
516
508
|
}
|
|
517
509
|
handlers.delete(listener);
|
|
518
|
-
if (handlers
|
|
510
|
+
if (handlers.size === 0) {
|
|
519
511
|
target[name] = undefined;
|
|
520
512
|
}
|
|
521
513
|
removeDelegatedHandler(document, type, name, passive);
|
|
522
514
|
return true;
|
|
523
515
|
}
|
|
524
516
|
//
|
|
517
|
+
const COUNT_SUFFIX = '.count';
|
|
525
518
|
const EVENT_PREFIX = '@';
|
|
526
519
|
const EVENT_SUFFIX_ACTIVE = ':active';
|
|
527
520
|
const EVENT_SUFFIX_PASSIVE = ':passive';
|
|
@@ -551,7 +544,6 @@ const EVENT_TYPES = new Set([
|
|
|
551
544
|
]);
|
|
552
545
|
const HANDLER_ACTIVE = delegatedEventHandler.bind(false);
|
|
553
546
|
const HANDLER_PASSIVE = delegatedEventHandler.bind(true);
|
|
554
|
-
const LISTENERS_SUFFIX = ':listeners';
|
|
555
547
|
|
|
556
548
|
//
|
|
557
549
|
function createDispatchOptions(options) {
|
|
@@ -610,9 +602,7 @@ function getPosition(event) {
|
|
|
610
602
|
* @param options Options for event
|
|
611
603
|
*/
|
|
612
604
|
function off(target, type, listener, options) {
|
|
613
|
-
if (!isEventTarget(target) ||
|
|
614
|
-
typeof type !== 'string' ||
|
|
615
|
-
typeof listener !== 'function') {
|
|
605
|
+
if (!isEventTarget(target) || typeof type !== 'string' || typeof listener !== 'function') {
|
|
616
606
|
return;
|
|
617
607
|
}
|
|
618
608
|
const extended = createEventOptions(options);
|
|
@@ -623,9 +613,7 @@ function off(target, type, listener, options) {
|
|
|
623
613
|
}
|
|
624
614
|
}
|
|
625
615
|
function on(target, type, listener, options) {
|
|
626
|
-
if (!isEventTarget(target) ||
|
|
627
|
-
typeof type !== 'string' ||
|
|
628
|
-
typeof listener !== 'function') {
|
|
616
|
+
if (!isEventTarget(target) || typeof type !== 'string' || typeof listener !== 'function') {
|
|
629
617
|
return noop;
|
|
630
618
|
}
|
|
631
619
|
const extended = createEventOptions(options);
|
|
@@ -659,7 +647,7 @@ function getDistanceBetweenElements(origin, target) {
|
|
|
659
647
|
}
|
|
660
648
|
const beforeOrInside = !!(comparison & 2 || comparison & 8);
|
|
661
649
|
if (beforeOrInside || !!(comparison & 4 || comparison & 16)) {
|
|
662
|
-
return
|
|
650
|
+
return traverse(beforeOrInside ? origin : target, beforeOrInside ? target : origin) ?? -1;
|
|
663
651
|
}
|
|
664
652
|
}
|
|
665
653
|
/**
|
|
@@ -742,9 +730,7 @@ function findRelatives(origin, selector, context) {
|
|
|
742
730
|
}
|
|
743
731
|
return minimum == null
|
|
744
732
|
? []
|
|
745
|
-
: distances
|
|
746
|
-
.filter(found => found.distance === minimum)
|
|
747
|
-
.map(found => found.element);
|
|
733
|
+
: distances.filter(found => found.distance === minimum).map(found => found.element);
|
|
748
734
|
}
|
|
749
735
|
function traverse(from, to) {
|
|
750
736
|
let index = [...to.children].indexOf(from);
|
|
@@ -760,7 +746,7 @@ function traverse(from, to) {
|
|
|
760
746
|
}
|
|
761
747
|
const children = [...(parent.children ?? [])];
|
|
762
748
|
if (children.includes(to)) {
|
|
763
|
-
return
|
|
749
|
+
return distance + Math.abs(children.indexOf(current) - children.indexOf(to));
|
|
764
750
|
}
|
|
765
751
|
index = children.findIndex(child => child.contains(to));
|
|
766
752
|
if (index > -1) {
|
|
@@ -814,9 +800,7 @@ function findElementOrElementsForSelector(selector, contexts, callback, single)
|
|
|
814
800
|
}
|
|
815
801
|
result.push(...Array.from(value));
|
|
816
802
|
}
|
|
817
|
-
return single
|
|
818
|
-
? null
|
|
819
|
-
: result.filter((value, index, array) => array.indexOf(value) === index);
|
|
803
|
+
return single ? null : result.filter((value, index, array) => array.indexOf(value) === index);
|
|
820
804
|
}
|
|
821
805
|
function findElementOrElementsFromNodes(array, context, contexts) {
|
|
822
806
|
const result = [];
|
|
@@ -914,8 +898,7 @@ function getTabbable(parent) {
|
|
|
914
898
|
function getTabIndex(element) {
|
|
915
899
|
const tabIndex = element?.tabIndex ?? TABINDEX_DEFAULT;
|
|
916
900
|
if (tabIndex < TABINDEX_BASE &&
|
|
917
|
-
(EXPRESSION_SPECIAL_TABINDEX.test(element.tagName) ||
|
|
918
|
-
isEditable(element)) &&
|
|
901
|
+
(EXPRESSION_SPECIAL_TABINDEX.test(element.tagName) || isEditable(element)) &&
|
|
919
902
|
!hasTabIndex(element)) {
|
|
920
903
|
return TABINDEX_BASE;
|
|
921
904
|
}
|
|
@@ -946,10 +929,7 @@ function getValidElements(parent, filters, tabbable) {
|
|
|
946
929
|
zeroed.push(item.element);
|
|
947
930
|
}
|
|
948
931
|
else {
|
|
949
|
-
indiced[item.tabIndex] = [
|
|
950
|
-
...(indiced[item.tabIndex] ?? []),
|
|
951
|
-
item.element,
|
|
952
|
-
];
|
|
932
|
+
indiced[item.tabIndex] = [...(indiced[item.tabIndex] ?? []), item.element];
|
|
953
933
|
}
|
|
954
934
|
}
|
|
955
935
|
return [...indiced.flat(), ...zeroed];
|
|
@@ -958,8 +938,7 @@ function hasTabIndex(element) {
|
|
|
958
938
|
return !Number.isNaN(Number.parseInt(element.getAttribute(ATTRIBUTE_TABINDEX), 10));
|
|
959
939
|
}
|
|
960
940
|
function isDisabled(item) {
|
|
961
|
-
if (EXPRESSION_DISABLEABLE.test(item.element.tagName) &&
|
|
962
|
-
isDisabledFromFieldset(item.element)) {
|
|
941
|
+
if (EXPRESSION_DISABLEABLE.test(item.element.tagName) && isDisabledFromFieldset(item.element)) {
|
|
963
942
|
return true;
|
|
964
943
|
}
|
|
965
944
|
return item.element.disabled ?? false;
|
|
@@ -973,8 +952,7 @@ function isDisabledFromFieldset(element) {
|
|
|
973
952
|
for (let index = 0; index < length; index += 1) {
|
|
974
953
|
const child = children[index];
|
|
975
954
|
if (child instanceof HTMLLegendElement) {
|
|
976
|
-
return
|
|
977
|
-
!child.contains(element));
|
|
955
|
+
return parent.matches(SELECTOR_FIELDSET_DISABLED) || !child.contains(element);
|
|
978
956
|
}
|
|
979
957
|
}
|
|
980
958
|
return true;
|
|
@@ -992,20 +970,15 @@ function isEditable(element) {
|
|
|
992
970
|
* @returns `true` if focusable, otherwise `false`
|
|
993
971
|
*/
|
|
994
972
|
function isFocusable(element) {
|
|
995
|
-
return element instanceof Element
|
|
996
|
-
? isValidElement(element, FILTERS_FOCUSABLE, false)
|
|
997
|
-
: false;
|
|
973
|
+
return element instanceof Element ? isValidElement(element, FILTERS_FOCUSABLE, false) : false;
|
|
998
974
|
}
|
|
999
975
|
function isHidden(item) {
|
|
1000
976
|
if ((item.element.hidden ?? false) ||
|
|
1001
|
-
(item.element instanceof HTMLInputElement &&
|
|
1002
|
-
item.element.type === STYLE_HIDDEN)) {
|
|
977
|
+
(item.element instanceof HTMLInputElement && item.element.type === STYLE_HIDDEN)) {
|
|
1003
978
|
return true;
|
|
1004
979
|
}
|
|
1005
980
|
const isDirectSummary = item.element.matches(SELECTOR_SUMMARY_FIRST);
|
|
1006
|
-
const nodeUnderDetails = isDirectSummary
|
|
1007
|
-
? item.element.parentElement
|
|
1008
|
-
: item.element;
|
|
981
|
+
const nodeUnderDetails = isDirectSummary ? item.element.parentElement : item.element;
|
|
1009
982
|
if (nodeUnderDetails?.matches(SELECTOR_DETAILS_CLOSED_CHILDREN) ?? false) {
|
|
1010
983
|
return true;
|
|
1011
984
|
}
|
|
@@ -1033,9 +1006,7 @@ function isNotTabbableRadio(item) {
|
|
|
1033
1006
|
item.element.checked) {
|
|
1034
1007
|
return false;
|
|
1035
1008
|
}
|
|
1036
|
-
const parent = item.element.form ??
|
|
1037
|
-
item.element.getRootNode?.() ??
|
|
1038
|
-
item.element.ownerDocument;
|
|
1009
|
+
const parent = item.element.form ?? item.element.getRootNode?.() ?? item.element.ownerDocument;
|
|
1039
1010
|
const realName = CSS?.escape?.(item.element.name) ?? item.element.name;
|
|
1040
1011
|
const radios = [
|
|
1041
1012
|
...parent.querySelectorAll(`${SELECTOR_RADIO_PREFIX}${realName}${SELECTOR_RADIO_SUFFIX}`),
|
|
@@ -1053,9 +1024,7 @@ function isSummarised(item) {
|
|
|
1053
1024
|
* @returns `true` if tabbable, otherwise `false`
|
|
1054
1025
|
*/
|
|
1055
1026
|
function isTabbable(element) {
|
|
1056
|
-
return element instanceof Element
|
|
1057
|
-
? isValidElement(element, FILTERS_TABBABLE, true)
|
|
1058
|
-
: false;
|
|
1027
|
+
return element instanceof Element ? isValidElement(element, FILTERS_TABBABLE, true) : false;
|
|
1059
1028
|
}
|
|
1060
1029
|
function isValidElement(element, filters, tabbable) {
|
|
1061
1030
|
const item = getItem(element, tabbable);
|
|
@@ -1122,8 +1091,7 @@ function sanitizeAttributes(element, attributes, options) {
|
|
|
1122
1091
|
if (isBadAttribute(attribute) || isEmptyNonBooleanAttribute(attribute)) {
|
|
1123
1092
|
element.removeAttribute(attribute.name);
|
|
1124
1093
|
}
|
|
1125
|
-
else if (options.sanitizeBooleanAttributes &&
|
|
1126
|
-
isInvalidBooleanAttribute(attribute)) {
|
|
1094
|
+
else if (options.sanitizeBooleanAttributes && isInvalidBooleanAttribute(attribute)) {
|
|
1127
1095
|
element.setAttribute(attribute.name, '');
|
|
1128
1096
|
}
|
|
1129
1097
|
}
|
|
@@ -1160,9 +1128,7 @@ function getHtml(value, options) {
|
|
|
1160
1128
|
if (typeof value !== 'string' && !(value instanceof HTMLTemplateElement)) {
|
|
1161
1129
|
return [];
|
|
1162
1130
|
}
|
|
1163
|
-
const template = value instanceof HTMLTemplateElement
|
|
1164
|
-
? value
|
|
1165
|
-
: getTemplate(value, options.ignoreCache);
|
|
1131
|
+
const template = value instanceof HTMLTemplateElement ? value : getTemplate(value, options.ignoreCache);
|
|
1166
1132
|
if (template == null) {
|
|
1167
1133
|
return [];
|
|
1168
1134
|
}
|
|
@@ -1176,8 +1142,7 @@ function getHtml(value, options) {
|
|
|
1176
1142
|
}
|
|
1177
1143
|
function getOptions(input) {
|
|
1178
1144
|
const options = isPlainObject(input) ? input : {};
|
|
1179
|
-
options.ignoreCache =
|
|
1180
|
-
typeof options.ignoreCache === 'boolean' ? options.ignoreCache : false;
|
|
1145
|
+
options.ignoreCache = typeof options.ignoreCache === 'boolean' ? options.ignoreCache : false;
|
|
1181
1146
|
options.sanitizeBooleanAttributes =
|
|
1182
1147
|
typeof options.sanitizeBooleanAttributes === 'boolean'
|
|
1183
1148
|
? options.sanitizeBooleanAttributes
|
|
@@ -1192,13 +1157,8 @@ function getTemplate(value, ignore) {
|
|
|
1192
1157
|
if (template != null) {
|
|
1193
1158
|
return template;
|
|
1194
1159
|
}
|
|
1195
|
-
const element = EXPRESSION_ID.test(value)
|
|
1196
|
-
|
|
1197
|
-
: null;
|
|
1198
|
-
template =
|
|
1199
|
-
element instanceof HTMLTemplateElement
|
|
1200
|
-
? element
|
|
1201
|
-
: createTemplate(value, ignore);
|
|
1160
|
+
const element = EXPRESSION_ID.test(value) ? document.querySelector(`#${value}`) : null;
|
|
1161
|
+
template = element instanceof HTMLTemplateElement ? element : createTemplate(value, ignore);
|
|
1202
1162
|
return template;
|
|
1203
1163
|
}
|
|
1204
1164
|
const html = ((value, options) => {
|
package/package.json
CHANGED
|
@@ -4,20 +4,21 @@
|
|
|
4
4
|
"url": "https://oscarpalmer.se"
|
|
5
5
|
},
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@oscarpalmer/atoms": "^0.
|
|
7
|
+
"@oscarpalmer/atoms": "^0.115"
|
|
8
8
|
},
|
|
9
9
|
"description": "A collection of badass DOM utilities.",
|
|
10
10
|
"devDependencies": {
|
|
11
|
-
"@biomejs/biome": "^2.3",
|
|
12
11
|
"@rollup/plugin-node-resolve": "^16",
|
|
13
12
|
"@rollup/plugin-typescript": "^12.3",
|
|
14
13
|
"@types/node": "^24.10",
|
|
15
14
|
"@vitest/coverage-istanbul": "^4",
|
|
16
15
|
"jsdom": "^27.2",
|
|
16
|
+
"oxfmt": "^0.16",
|
|
17
|
+
"oxlint": "^1.31",
|
|
17
18
|
"rollup": "^4.53",
|
|
18
19
|
"tslib": "^2.8",
|
|
19
20
|
"typescript": "^5.9",
|
|
20
|
-
"vite": "
|
|
21
|
+
"vite": "8.0.0-beta.0",
|
|
21
22
|
"vitest": "^4"
|
|
22
23
|
},
|
|
23
24
|
"exports": {
|
|
@@ -92,5 +93,5 @@
|
|
|
92
93
|
},
|
|
93
94
|
"type": "module",
|
|
94
95
|
"types": "types/index.d.ts",
|
|
95
|
-
"version": "0.
|
|
96
|
+
"version": "0.28.0"
|
|
96
97
|
}
|
package/src/attribute/set.ts
CHANGED
|
@@ -9,11 +9,7 @@ import type {Attribute, HTMLOrSVGElement, Property} from '../models';
|
|
|
9
9
|
* @param name Attribute name
|
|
10
10
|
* @param value Attribute value
|
|
11
11
|
*/
|
|
12
|
-
export function setAttribute(
|
|
13
|
-
element: HTMLOrSVGElement,
|
|
14
|
-
name: string,
|
|
15
|
-
value?: unknown,
|
|
16
|
-
): void;
|
|
12
|
+
export function setAttribute(element: HTMLOrSVGElement, name: string, value?: unknown): void;
|
|
17
13
|
|
|
18
14
|
/**
|
|
19
15
|
* Set an attribute on an element
|
|
@@ -22,16 +18,9 @@ export function setAttribute(
|
|
|
22
18
|
* @param element Element for attribute
|
|
23
19
|
* @param attribute Attribute to set
|
|
24
20
|
*/
|
|
25
|
-
export function setAttribute(
|
|
26
|
-
element: HTMLOrSVGElement,
|
|
27
|
-
attribute: Attr | Attribute,
|
|
28
|
-
): void;
|
|
21
|
+
export function setAttribute(element: HTMLOrSVGElement, attribute: Attr | Attribute): void;
|
|
29
22
|
|
|
30
|
-
export function setAttribute(
|
|
31
|
-
element: HTMLOrSVGElement,
|
|
32
|
-
first: unknown,
|
|
33
|
-
second?: unknown,
|
|
34
|
-
): void {
|
|
23
|
+
export function setAttribute(element: HTMLOrSVGElement, first: unknown, second?: unknown): void {
|
|
35
24
|
updateValue(element, first, second);
|
|
36
25
|
}
|
|
37
26
|
|
|
@@ -42,10 +31,7 @@ export function setAttribute(
|
|
|
42
31
|
* @param element Element for attributes
|
|
43
32
|
* @param attributes Attributes to set
|
|
44
33
|
*/
|
|
45
|
-
export function setAttributes(
|
|
46
|
-
element: HTMLOrSVGElement,
|
|
47
|
-
attributes: Array<Attr | Attribute>,
|
|
48
|
-
): void;
|
|
34
|
+
export function setAttributes(element: HTMLOrSVGElement, attributes: Array<Attr | Attribute>): void;
|
|
49
35
|
|
|
50
36
|
/**
|
|
51
37
|
* Set one or more attributes on an element
|
|
@@ -54,10 +40,7 @@ export function setAttributes(
|
|
|
54
40
|
* @param element Element for attributes
|
|
55
41
|
* @param attributes Attributes to set
|
|
56
42
|
*/
|
|
57
|
-
export function setAttributes(
|
|
58
|
-
element: HTMLOrSVGElement,
|
|
59
|
-
attributes: Record<string, unknown>,
|
|
60
|
-
): void;
|
|
43
|
+
export function setAttributes(element: HTMLOrSVGElement, attributes: Record<string, unknown>): void;
|
|
61
44
|
|
|
62
45
|
export function setAttributes(
|
|
63
46
|
element: HTMLOrSVGElement,
|
|
@@ -74,11 +57,7 @@ export function setAttributes(
|
|
|
74
57
|
* @param name Property name
|
|
75
58
|
* @param value Property value
|
|
76
59
|
*/
|
|
77
|
-
export function setProperty(
|
|
78
|
-
element: HTMLOrSVGElement,
|
|
79
|
-
name: string,
|
|
80
|
-
value: boolean | string,
|
|
81
|
-
): void;
|
|
60
|
+
export function setProperty(element: HTMLOrSVGElement, name: string, value: boolean | string): void;
|
|
82
61
|
|
|
83
62
|
/**
|
|
84
63
|
* Set a property on an element
|
|
@@ -87,16 +66,9 @@ export function setProperty(
|
|
|
87
66
|
* @param element Element for property
|
|
88
67
|
* @param property Property to set
|
|
89
68
|
*/
|
|
90
|
-
export function setProperty(
|
|
91
|
-
element: HTMLOrSVGElement,
|
|
92
|
-
property: Property,
|
|
93
|
-
): void;
|
|
69
|
+
export function setProperty(element: HTMLOrSVGElement, property: Property): void;
|
|
94
70
|
|
|
95
|
-
export function setProperty(
|
|
96
|
-
element: HTMLOrSVGElement,
|
|
97
|
-
first: unknown,
|
|
98
|
-
second?: unknown,
|
|
99
|
-
): void {
|
|
71
|
+
export function setProperty(element: HTMLOrSVGElement, first: unknown, second?: unknown): void {
|
|
100
72
|
updateValue(element, first, second);
|
|
101
73
|
}
|
|
102
74
|
|
|
@@ -107,10 +79,7 @@ export function setProperty(
|
|
|
107
79
|
* @param element Element for properties
|
|
108
80
|
* @param properties Properties to set
|
|
109
81
|
*/
|
|
110
|
-
export function setProperties(
|
|
111
|
-
element: HTMLOrSVGElement,
|
|
112
|
-
properties: Property[],
|
|
113
|
-
): void;
|
|
82
|
+
export function setProperties(element: HTMLOrSVGElement, properties: Property[]): void;
|
|
114
83
|
|
|
115
84
|
/**
|
|
116
85
|
* Set one or more properties on an element
|
|
@@ -119,10 +88,7 @@ export function setProperties(
|
|
|
119
88
|
* @param element Element for properties
|
|
120
89
|
* @param properties Properties to set
|
|
121
90
|
*/
|
|
122
|
-
export function setProperties(
|
|
123
|
-
element: HTMLOrSVGElement,
|
|
124
|
-
properties: Record<string, unknown>,
|
|
125
|
-
): void;
|
|
91
|
+
export function setProperties(element: HTMLOrSVGElement, properties: Record<string, unknown>): void;
|
|
126
92
|
|
|
127
93
|
export function setProperties(
|
|
128
94
|
element: HTMLOrSVGElement,
|
package/src/data.ts
CHANGED
|
@@ -12,11 +12,7 @@ import type {HTMLOrSVGElement} from './models';
|
|
|
12
12
|
* @param parse Parse values? _(defaults to `true`)_
|
|
13
13
|
* @returns Data value
|
|
14
14
|
*/
|
|
15
|
-
export function getData(
|
|
16
|
-
element: HTMLOrSVGElement,
|
|
17
|
-
key: string,
|
|
18
|
-
parse?: boolean,
|
|
19
|
-
): unknown;
|
|
15
|
+
export function getData(element: HTMLOrSVGElement, key: string, parse?: boolean): unknown;
|
|
20
16
|
|
|
21
17
|
/**
|
|
22
18
|
* Get keyed data values from an element
|
|
@@ -87,11 +83,7 @@ export function setData(element: HTMLOrSVGElement, data: PlainObject): void;
|
|
|
87
83
|
* @param key Data key
|
|
88
84
|
* @param value Data value
|
|
89
85
|
*/
|
|
90
|
-
export function setData(
|
|
91
|
-
element: HTMLOrSVGElement,
|
|
92
|
-
key: string,
|
|
93
|
-
value: unknown,
|
|
94
|
-
): void;
|
|
86
|
+
export function setData(element: HTMLOrSVGElement, key: string, value: unknown): void;
|
|
95
87
|
|
|
96
88
|
export function setData(
|
|
97
89
|
element: HTMLOrSVGElement,
|
|
@@ -101,11 +93,7 @@ export function setData(
|
|
|
101
93
|
setElementValues(element, first, second, updateDataAttribute);
|
|
102
94
|
}
|
|
103
95
|
|
|
104
|
-
function updateDataAttribute(
|
|
105
|
-
element: HTMLOrSVGElement,
|
|
106
|
-
key: string,
|
|
107
|
-
value: unknown,
|
|
108
|
-
): void {
|
|
96
|
+
function updateDataAttribute(element: HTMLOrSVGElement, key: string, value: unknown): void {
|
|
109
97
|
updateElementValue(
|
|
110
98
|
element,
|
|
111
99
|
getName(key),
|