@oscarpalmer/toretto 0.39.2 → 0.41.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/{types/attribute/get.d.ts → dist/attribute/get.d.mts} +6 -3
- package/dist/attribute/{get.js → get.mjs} +2 -2
- package/{types/attribute/index.d.ts → dist/attribute/index.d.mts} +16 -12
- package/dist/attribute/{index.js → index.mjs} +3 -3
- package/{types/attribute/set.d.ts → dist/attribute/set.d.mts} +10 -7
- package/dist/attribute/{set.js → set.mjs} +2 -2
- package/{types/data.d.ts → dist/data.d.mts} +9 -5
- package/dist/{data.js → data.mjs} +4 -4
- package/dist/event/delegation.d.mts +11 -0
- package/dist/event/{delegation.js → delegation.mjs} +8 -8
- package/{types/event/index.d.ts → dist/event/index.d.mts} +12 -8
- package/dist/event/{index.js → index.mjs} +4 -4
- package/{types/find/index.d.ts → dist/find/index.d.mts} +11 -8
- package/dist/find/{index.js → index.mjs} +7 -7
- package/{types/find/relative.d.ts → dist/find/relative.d.mts} +8 -5
- package/{types/focusable.d.ts → dist/focusable.d.mts} +7 -4
- package/dist/{focusable.js → focusable.mjs} +20 -20
- package/dist/html/index.d.mts +42 -0
- package/dist/html/{index.js → index.mjs} +8 -8
- package/dist/html/sanitize.d.mts +5 -0
- package/dist/html/{sanitize.js → sanitize.mjs} +4 -4
- package/{types/index.d.ts → dist/index.d.mts} +157 -128
- package/dist/{toretto.full.js → index.mjs} +78 -173
- package/dist/internal/attribute.d.mts +15 -0
- package/dist/internal/{attribute.js → attribute.mjs} +14 -14
- package/dist/internal/element-value.d.mts +6 -0
- package/dist/internal/{element-value.js → element-value.mjs} +3 -3
- package/dist/internal/get-value.d.mts +7 -0
- package/dist/internal/{get-value.js → get-value.mjs} +1 -1
- package/{types/internal/is.d.ts → dist/internal/is.d.mts} +5 -2
- package/{types/is.d.ts → dist/is.d.mts} +8 -4
- package/dist/{is.js → is.mjs} +2 -2
- package/dist/models.d.mts +33 -0
- package/dist/models.mjs +1 -0
- package/dist/style.d.mts +58 -0
- package/dist/{style.js → style.mjs} +5 -5
- package/dist/touch.d.mts +21 -0
- package/dist/{touch.js → touch.mjs} +1 -1
- package/package.json +60 -63
- package/src/data.ts +1 -1
- package/src/find/index.ts +1 -1
- package/src/internal/attribute.ts +1 -1
- package/dist/index.js +0 -15
- package/dist/models.js +0 -0
- package/types/event/delegation.d.ts +0 -7
- package/types/html/index.d.ts +0 -40
- package/types/html/sanitize.d.ts +0 -2
- package/types/internal/attribute.d.ts +0 -11
- package/types/internal/element-value.d.ts +0 -3
- package/types/internal/get-value.d.ts +0 -4
- package/types/models.d.ts +0 -30
- package/types/style.d.ts +0 -54
- package/types/touch.d.ts +0 -19
- /package/dist/find/{relative.js → relative.mjs} +0 -0
- /package/dist/internal/{is.js → is.mjs} +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/touch.ts
|
|
1
2
|
function getSupport() {
|
|
2
3
|
if (window == null || navigator == null) return false;
|
|
3
4
|
if ("matchMedia" in window) {
|
|
@@ -28,6 +29,8 @@ const supportsTouch = (() => {
|
|
|
28
29
|
} });
|
|
29
30
|
return instance;
|
|
30
31
|
})();
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region node_modules/@oscarpalmer/atoms/dist/internal/is.mjs
|
|
31
34
|
/**
|
|
32
35
|
* Is the value a number?
|
|
33
36
|
* @param value Value to check
|
|
@@ -47,6 +50,8 @@ function isPlainObject(value) {
|
|
|
47
50
|
const prototype = Object.getPrototypeOf(value);
|
|
48
51
|
return prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null;
|
|
49
52
|
}
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region node_modules/@oscarpalmer/atoms/dist/internal/array/compact.mjs
|
|
50
55
|
function compact(array, strict) {
|
|
51
56
|
if (!Array.isArray(array)) return [];
|
|
52
57
|
if (strict === true) return array.filter(Boolean);
|
|
@@ -58,6 +63,8 @@ function compact(array, strict) {
|
|
|
58
63
|
}
|
|
59
64
|
return compacted;
|
|
60
65
|
}
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region node_modules/@oscarpalmer/atoms/dist/internal/string.mjs
|
|
61
68
|
/**
|
|
62
69
|
* Get the string value from any value
|
|
63
70
|
* @param value Original value
|
|
@@ -88,7 +95,9 @@ function join(value, delimiter) {
|
|
|
88
95
|
function words(value) {
|
|
89
96
|
return typeof value === "string" ? value.match(EXPRESSION_WORDS) ?? [] : [];
|
|
90
97
|
}
|
|
91
|
-
|
|
98
|
+
const EXPRESSION_WORDS = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region node_modules/@oscarpalmer/atoms/dist/is.mjs
|
|
92
101
|
/**
|
|
93
102
|
* Is the value `undefined`, `null`, or a whitespace-only string?
|
|
94
103
|
* @param value Value to check
|
|
@@ -97,7 +106,9 @@ var EXPRESSION_WORDS = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
|
|
|
97
106
|
function isNullableOrWhitespace(value) {
|
|
98
107
|
return value == null || EXPRESSION_WHITESPACE$1.test(getString(value));
|
|
99
108
|
}
|
|
100
|
-
|
|
109
|
+
const EXPRESSION_WHITESPACE$1 = /^\s*$/;
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/internal/is.ts
|
|
101
112
|
/**
|
|
102
113
|
* Is the value an event target?
|
|
103
114
|
* @param value Value to check
|
|
@@ -114,6 +125,8 @@ function isEventTarget(value) {
|
|
|
114
125
|
function isHTMLOrSVGElement(value) {
|
|
115
126
|
return value instanceof HTMLElement || value instanceof SVGElement;
|
|
116
127
|
}
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/is.ts
|
|
117
130
|
/**
|
|
118
131
|
* Is the value a child node?
|
|
119
132
|
* @param value Value to check
|
|
@@ -134,6 +147,8 @@ const CHILD_NODE_TYPES = new Set([
|
|
|
134
147
|
Node.COMMENT_NODE,
|
|
135
148
|
Node.DOCUMENT_TYPE_NODE
|
|
136
149
|
]);
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region src/internal/element-value.ts
|
|
137
152
|
function setElementValue(element, first, second, third, callback) {
|
|
138
153
|
if (!isHTMLOrSVGElement(element)) return;
|
|
139
154
|
if (typeof first === "string") setElementValues(element, first, second, third, callback);
|
|
@@ -161,6 +176,8 @@ function updateElementValue(element, key, value, set, remove, isBoolean, json) {
|
|
|
161
176
|
if (isBoolean ? value == null : isNullableOrWhitespace(value)) remove.call(element, key);
|
|
162
177
|
else set.call(element, key, json ? JSON.stringify(value) : String(value));
|
|
163
178
|
}
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/internal/attribute.ts
|
|
164
181
|
function badAttributeHandler(name, value) {
|
|
165
182
|
if (typeof name !== "string" || name.trim().length === 0 || typeof value !== "string") return true;
|
|
166
183
|
if (EXPRESSION_CLOBBERED_NAME.test(name) && (value in document || value in formElement) || EXPRESSION_EVENT_NAME.test(name)) return true;
|
|
@@ -272,6 +289,8 @@ const elementEvents = {
|
|
|
272
289
|
};
|
|
273
290
|
const formElement = document.createElement("form");
|
|
274
291
|
let textArea;
|
|
292
|
+
//#endregion
|
|
293
|
+
//#region node_modules/@oscarpalmer/atoms/dist/string/index.mjs
|
|
275
294
|
/**
|
|
276
295
|
* Parse a JSON string into its proper value _(or `undefined` if it fails)_
|
|
277
296
|
* @param value JSON string to parse
|
|
@@ -285,6 +304,8 @@ function parse(value, reviver) {
|
|
|
285
304
|
return;
|
|
286
305
|
}
|
|
287
306
|
}
|
|
307
|
+
//#endregion
|
|
308
|
+
//#region node_modules/@oscarpalmer/atoms/dist/internal/number.mjs
|
|
288
309
|
/**
|
|
289
310
|
* Clamp a number between a minimum and maximum value
|
|
290
311
|
* @param value Value to clamp
|
|
@@ -302,14 +323,18 @@ function clamp(value, minimum, maximum, loop) {
|
|
|
302
323
|
if (value < minimum) return loop === true ? maximum : minimum;
|
|
303
324
|
return value > maximum ? loop === true ? minimum : maximum : value;
|
|
304
325
|
}
|
|
326
|
+
//#endregion
|
|
327
|
+
//#region node_modules/@oscarpalmer/atoms/dist/internal/sized.mjs
|
|
305
328
|
function getSizedMaximum(first, second) {
|
|
306
329
|
let actual;
|
|
307
330
|
if (typeof first === "number") actual = first;
|
|
308
331
|
else actual = typeof second === "number" ? second : MAXIMUM_DEFAULT;
|
|
309
332
|
return clamp(actual, 1, MAXIMUM_ABSOLUTE);
|
|
310
333
|
}
|
|
311
|
-
|
|
312
|
-
|
|
334
|
+
const MAXIMUM_ABSOLUTE = 16777216;
|
|
335
|
+
const MAXIMUM_DEFAULT = 1048576;
|
|
336
|
+
//#endregion
|
|
337
|
+
//#region node_modules/@oscarpalmer/atoms/dist/sized/map.mjs
|
|
313
338
|
/**
|
|
314
339
|
* A Map with a maximum size
|
|
315
340
|
*
|
|
@@ -356,6 +381,8 @@ var SizedMap = class extends Map {
|
|
|
356
381
|
return super.set(key, value);
|
|
357
382
|
}
|
|
358
383
|
};
|
|
384
|
+
//#endregion
|
|
385
|
+
//#region node_modules/@oscarpalmer/atoms/dist/function/memoize.mjs
|
|
359
386
|
var Memoized = class {
|
|
360
387
|
#state;
|
|
361
388
|
/**
|
|
@@ -448,8 +475,10 @@ function getMemoizationOptions(input) {
|
|
|
448
475
|
function memoize(callback, options) {
|
|
449
476
|
return new Memoized(callback, getMemoizationOptions(options));
|
|
450
477
|
}
|
|
451
|
-
|
|
452
|
-
|
|
478
|
+
const DEFAULT_CACHE_SIZE = 1024;
|
|
479
|
+
const SEPARATOR = "_";
|
|
480
|
+
//#endregion
|
|
481
|
+
//#region node_modules/@oscarpalmer/atoms/dist/string/case.mjs
|
|
453
482
|
/**
|
|
454
483
|
* Convert a string to camel case _(thisIsCamelCase)_
|
|
455
484
|
* @param value String to convert
|
|
@@ -507,25 +536,27 @@ function toCaseCallback(value) {
|
|
|
507
536
|
}
|
|
508
537
|
return join(cased, delimiters[type]);
|
|
509
538
|
}
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
539
|
+
const CASE_CAMEL = "camel";
|
|
540
|
+
const CASE_KEBAB = "kebab";
|
|
541
|
+
const CASE_PASCAL = "pascal";
|
|
542
|
+
const CASE_SNAKE = "snake";
|
|
543
|
+
const DELIMTER_EMPTY = "";
|
|
544
|
+
const DELIMITER_HYPHEN = "-";
|
|
545
|
+
const DELIMITER_UNDERSCORE = "_";
|
|
546
|
+
const EXPRESSION_CAMEL_CASE = /(\p{Ll})(\p{Lu})/gu;
|
|
547
|
+
const EXPRESSION_ACRONYM = /(\p{Lu}*)(\p{Lu})(\p{Ll}+)/gu;
|
|
548
|
+
const REPLACEMENT_CAMEL_CASE = "$1-$2";
|
|
549
|
+
const S = "s";
|
|
550
|
+
const caseMemoizers = {};
|
|
551
|
+
const delimiters = {
|
|
523
552
|
[CASE_CAMEL]: DELIMTER_EMPTY,
|
|
524
553
|
[CASE_KEBAB]: DELIMITER_HYPHEN,
|
|
525
554
|
[CASE_PASCAL]: DELIMTER_EMPTY,
|
|
526
555
|
[CASE_SNAKE]: DELIMITER_UNDERSCORE
|
|
527
556
|
};
|
|
528
|
-
|
|
557
|
+
let memoizedCapitalize;
|
|
558
|
+
//#endregion
|
|
559
|
+
//#region src/internal/get-value.ts
|
|
529
560
|
function getBoolean(value, defaultValue) {
|
|
530
561
|
return typeof value === "boolean" ? value : defaultValue ?? false;
|
|
531
562
|
}
|
|
@@ -540,6 +571,8 @@ function getStyleValue(element, property, computed) {
|
|
|
540
571
|
return computed ? getComputedStyle(element)[name] : element.style[name];
|
|
541
572
|
}
|
|
542
573
|
const EXPRESSION_DATA_PREFIX = /^data-/i;
|
|
574
|
+
//#endregion
|
|
575
|
+
//#region src/attribute/get.ts
|
|
543
576
|
function getAttribute(element, name, parseValues) {
|
|
544
577
|
if (isHTMLOrSVGElement(element) && typeof name === "string") return getAttributeValue(element, name, parseValues !== false);
|
|
545
578
|
}
|
|
@@ -561,12 +594,16 @@ function getAttributes(element, names, parseData) {
|
|
|
561
594
|
}
|
|
562
595
|
return attributes;
|
|
563
596
|
}
|
|
597
|
+
//#endregion
|
|
598
|
+
//#region src/attribute/set.ts
|
|
564
599
|
function setAttribute(element, first, second, third) {
|
|
565
600
|
setElementValue(element, first, second, third, updateAttribute);
|
|
566
601
|
}
|
|
567
602
|
function setAttributes(element, attributes, dispatch) {
|
|
568
603
|
setElementValues(element, attributes, null, dispatch, updateAttribute);
|
|
569
604
|
}
|
|
605
|
+
//#endregion
|
|
606
|
+
//#region src/attribute/index.ts
|
|
570
607
|
function isBadAttribute(first, second) {
|
|
571
608
|
return _isBadAttribute(first, second, true);
|
|
572
609
|
}
|
|
@@ -579,6 +616,8 @@ function isEmptyNonBooleanAttribute(first, second) {
|
|
|
579
616
|
function isInvalidBooleanAttribute(first, second) {
|
|
580
617
|
return _isInvalidBooleanAttribute(first, second, true);
|
|
581
618
|
}
|
|
619
|
+
//#endregion
|
|
620
|
+
//#region src/data.ts
|
|
582
621
|
function getData(element, keys, parseValues) {
|
|
583
622
|
if (!isHTMLOrSVGElement(element)) return;
|
|
584
623
|
const shouldParse = parseValues !== false;
|
|
@@ -607,163 +646,14 @@ function updateDataAttribute(element, key, value) {
|
|
|
607
646
|
updateElementValue(element, getName(key), value, element.setAttribute, element.removeAttribute, false, true);
|
|
608
647
|
}
|
|
609
648
|
const ATTRIBUTE_DATA_PREFIX = "data-";
|
|
649
|
+
//#endregion
|
|
650
|
+
//#region node_modules/@oscarpalmer/atoms/dist/internal/function/misc.mjs
|
|
610
651
|
/**
|
|
611
652
|
* A function that does nothing, which can be useful, I guess…
|
|
612
653
|
*/
|
|
613
654
|
function noop() {}
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
* @param condition Condition to assert
|
|
617
|
-
* @param message Error message
|
|
618
|
-
* @param error Error constructor
|
|
619
|
-
*/
|
|
620
|
-
function assert(condition, message, error) {
|
|
621
|
-
if (!condition()) throw new (error ?? Error)(message);
|
|
622
|
-
}
|
|
623
|
-
assert.condition = assertCondition;
|
|
624
|
-
assert.defined = assertDefined;
|
|
625
|
-
assert.instanceOf = assertInstanceOf;
|
|
626
|
-
assert.is = assertIs;
|
|
627
|
-
/**
|
|
628
|
-
* Creates an asserter that asserts a condition is true, throwing an error if it is not
|
|
629
|
-
* @param condition Condition to assert
|
|
630
|
-
* @param message Error message
|
|
631
|
-
* @param error Error constructor
|
|
632
|
-
* @returns Asserter
|
|
633
|
-
*/
|
|
634
|
-
function assertCondition(condition, message, error) {
|
|
635
|
-
return (value) => {
|
|
636
|
-
assert(() => condition(value), message, error);
|
|
637
|
-
};
|
|
638
|
-
}
|
|
639
|
-
/**
|
|
640
|
-
* Asserts that a value is defined throwing an error if it is not
|
|
641
|
-
* @param value Value to assert
|
|
642
|
-
* @param message Error message
|
|
643
|
-
*/
|
|
644
|
-
function assertDefined(value, message) {
|
|
645
|
-
assert(() => value != null, message ?? MESSAGE_VALUE_DEFINED);
|
|
646
|
-
}
|
|
647
|
-
/**
|
|
648
|
-
* Creates an asserter that asserts a value is an instance of a constructor, throwing an error if it is not
|
|
649
|
-
* @param constructor Constructor to check against
|
|
650
|
-
* @param message Error message
|
|
651
|
-
* @param error Error constructor
|
|
652
|
-
* @returns Asserter
|
|
653
|
-
*/
|
|
654
|
-
function assertInstanceOf(constructor, message, error) {
|
|
655
|
-
return (value) => {
|
|
656
|
-
assert(() => value instanceof constructor, message, error);
|
|
657
|
-
};
|
|
658
|
-
}
|
|
659
|
-
/**
|
|
660
|
-
* Creates an asserter that asserts a value is of a specific type, throwing an error if it is not
|
|
661
|
-
* @param condition Type guard function to check the value
|
|
662
|
-
* @param message Error message
|
|
663
|
-
* @param error Error constructor
|
|
664
|
-
* @returns Asserter
|
|
665
|
-
*/
|
|
666
|
-
function assertIs(condition, message, error) {
|
|
667
|
-
return (value) => {
|
|
668
|
-
assert(() => condition(value), message, error);
|
|
669
|
-
};
|
|
670
|
-
}
|
|
671
|
-
var MESSAGE_VALUE_DEFINED = "Expected value to be defined";
|
|
672
|
-
/**
|
|
673
|
-
* Create an asynchronous function that can only be called once, rejecting or resolving the same result on subsequent calls
|
|
674
|
-
* @param callback Callback to use once
|
|
675
|
-
* @returns Once callback
|
|
676
|
-
*/
|
|
677
|
-
function asyncOnce(callback) {
|
|
678
|
-
assert(() => typeof callback === "function", MESSAGE_EXPECTATION);
|
|
679
|
-
const state = {
|
|
680
|
-
called: false,
|
|
681
|
-
cleared: false,
|
|
682
|
-
error: false,
|
|
683
|
-
finished: false,
|
|
684
|
-
items: [],
|
|
685
|
-
value: void 0
|
|
686
|
-
};
|
|
687
|
-
const fn = (...parameters) => {
|
|
688
|
-
if (state.cleared) return Promise.reject(new Error(MESSAGE_CLEARED));
|
|
689
|
-
if (state.finished) return state.error ? Promise.reject(state.value) : Promise.resolve(state.value);
|
|
690
|
-
if (state.called) return new Promise((resolve, reject) => {
|
|
691
|
-
state.items.push({
|
|
692
|
-
reject,
|
|
693
|
-
resolve
|
|
694
|
-
});
|
|
695
|
-
});
|
|
696
|
-
state.called = true;
|
|
697
|
-
return new Promise((resolve, reject) => {
|
|
698
|
-
state.items.push({
|
|
699
|
-
reject,
|
|
700
|
-
resolve
|
|
701
|
-
});
|
|
702
|
-
callback(...parameters).then((value) => {
|
|
703
|
-
handleResult(state, value, false);
|
|
704
|
-
}).catch((error) => {
|
|
705
|
-
handleResult(state, error, true);
|
|
706
|
-
});
|
|
707
|
-
});
|
|
708
|
-
};
|
|
709
|
-
Object.defineProperties(fn, {
|
|
710
|
-
called: { get: () => state.called },
|
|
711
|
-
cleared: { get: () => state.cleared },
|
|
712
|
-
error: { get: () => state.error },
|
|
713
|
-
finished: { get: () => state.finished }
|
|
714
|
-
});
|
|
715
|
-
fn.clear = () => {
|
|
716
|
-
if (!state.called || !state.finished || state.cleared) return;
|
|
717
|
-
state.cleared = true;
|
|
718
|
-
state.value = void 0;
|
|
719
|
-
};
|
|
720
|
-
return fn;
|
|
721
|
-
}
|
|
722
|
-
function handleResult(state, value, error) {
|
|
723
|
-
state.error = error;
|
|
724
|
-
state.finished = true;
|
|
725
|
-
state.value = value;
|
|
726
|
-
const items = state.items.splice(0);
|
|
727
|
-
const { length } = items;
|
|
728
|
-
for (let index = 0; index < length; index += 1) {
|
|
729
|
-
const { reject, resolve } = items[index];
|
|
730
|
-
if (error) reject(value);
|
|
731
|
-
else resolve(value);
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
/**
|
|
735
|
-
* Create a function that can only be called once, returning the same value on subsequent calls
|
|
736
|
-
* @param callback Callback to use once
|
|
737
|
-
* @returns Once callback
|
|
738
|
-
*/
|
|
739
|
-
function once(callback) {
|
|
740
|
-
assert(() => typeof callback === "function", MESSAGE_EXPECTATION);
|
|
741
|
-
const state = {
|
|
742
|
-
called: false,
|
|
743
|
-
cleared: false,
|
|
744
|
-
value: void 0
|
|
745
|
-
};
|
|
746
|
-
const fn = (...parameters) => {
|
|
747
|
-
if (state.cleared) throw new Error(MESSAGE_CLEARED);
|
|
748
|
-
if (state.called) return state.value;
|
|
749
|
-
state.called = true;
|
|
750
|
-
state.value = callback(...parameters);
|
|
751
|
-
return state.value;
|
|
752
|
-
};
|
|
753
|
-
Object.defineProperties(fn, {
|
|
754
|
-
called: { get: () => state.called },
|
|
755
|
-
cleared: { get: () => state.cleared }
|
|
756
|
-
});
|
|
757
|
-
fn.clear = () => {
|
|
758
|
-
if (!state.called || state.cleared) return;
|
|
759
|
-
state.cleared = true;
|
|
760
|
-
state.value = void 0;
|
|
761
|
-
};
|
|
762
|
-
return fn;
|
|
763
|
-
}
|
|
764
|
-
once.async = asyncOnce;
|
|
765
|
-
var MESSAGE_CLEARED = "Once has been cleared";
|
|
766
|
-
var MESSAGE_EXPECTATION = "Once expected a function";
|
|
655
|
+
//#endregion
|
|
656
|
+
//#region src/event/delegation.ts
|
|
767
657
|
function addDelegatedHandler(doc, type, name, passive) {
|
|
768
658
|
if (DELEGATED.has(name)) return;
|
|
769
659
|
DELEGATED.add(name);
|
|
@@ -845,6 +735,8 @@ const EVENT_TYPES = new Set([
|
|
|
845
735
|
]);
|
|
846
736
|
const HANDLER_ACTIVE = delegatedEventHandler.bind(false);
|
|
847
737
|
const HANDLER_PASSIVE = delegatedEventHandler.bind(true);
|
|
738
|
+
//#endregion
|
|
739
|
+
//#region src/event/index.ts
|
|
848
740
|
function createDispatchOptions(options) {
|
|
849
741
|
return {
|
|
850
742
|
bubbles: getBoolean(options?.bubbles, true),
|
|
@@ -916,6 +808,8 @@ function on(target, type, listener, options) {
|
|
|
916
808
|
};
|
|
917
809
|
}
|
|
918
810
|
const PROPERTY_DETAIL = "detail";
|
|
811
|
+
//#endregion
|
|
812
|
+
//#region src/find/relative.ts
|
|
919
813
|
function findAncestor(origin, selector) {
|
|
920
814
|
const element = getElement(origin);
|
|
921
815
|
if (element == null || selector == null) return null;
|
|
@@ -992,6 +886,8 @@ function traverse(from, to) {
|
|
|
992
886
|
parent = parent.parentElement;
|
|
993
887
|
}
|
|
994
888
|
}
|
|
889
|
+
//#endregion
|
|
890
|
+
//#region src/find/index.ts
|
|
995
891
|
function findElement(selector, context) {
|
|
996
892
|
return findElementOrElements(selector, context, true);
|
|
997
893
|
}
|
|
@@ -1062,6 +958,8 @@ const STYLE_HIDDEN$1 = "hidden";
|
|
|
1062
958
|
const STYLE_NONE$1 = "none";
|
|
1063
959
|
const SUFFIX_HOVER = ":hover";
|
|
1064
960
|
const TAG_HEAD = "HEAD";
|
|
961
|
+
//#endregion
|
|
962
|
+
//#region src/focusable.ts
|
|
1065
963
|
/**
|
|
1066
964
|
* Get a list of focusable elements within a parent element
|
|
1067
965
|
* @param parent Parent element
|
|
@@ -1223,6 +1121,8 @@ const STYLE_NONE = "none";
|
|
|
1223
1121
|
const TABINDEX_BASE = 0;
|
|
1224
1122
|
const TABINDEX_DEFAULT = -1;
|
|
1225
1123
|
const TYPE_RADIO = "radio";
|
|
1124
|
+
//#endregion
|
|
1125
|
+
//#region src/html/sanitize.ts
|
|
1226
1126
|
function handleElement(element, depth) {
|
|
1227
1127
|
if (depth === 0) {
|
|
1228
1128
|
const removable = element.querySelectorAll(REMOVE_SELECTOR);
|
|
@@ -1280,6 +1180,8 @@ function sanitizeNodes(nodes, depth) {
|
|
|
1280
1180
|
}
|
|
1281
1181
|
const COMMENT_HARMFUL = /<[/\w]/g;
|
|
1282
1182
|
const REMOVE_SELECTOR = "script, toretto-temporary";
|
|
1183
|
+
//#endregion
|
|
1184
|
+
//#region src/html/index.ts
|
|
1283
1185
|
function createHtml(value) {
|
|
1284
1186
|
const parsed = getParser().parseFromString(getHtml(value), PARSE_TYPE_HTML);
|
|
1285
1187
|
parsed.body.normalize();
|
|
@@ -1349,6 +1251,8 @@ const TEMPLATE_TAG = "template";
|
|
|
1349
1251
|
const TEMPORARY_ELEMENT = "<toretto-temporary></toretto-temporary>";
|
|
1350
1252
|
let parser;
|
|
1351
1253
|
let templates = {};
|
|
1254
|
+
//#endregion
|
|
1255
|
+
//#region src/style.ts
|
|
1352
1256
|
/**
|
|
1353
1257
|
* Get a style from an element
|
|
1354
1258
|
* @param element Element to get the style from
|
|
@@ -1448,4 +1352,5 @@ function updateStyleProperty(element, key, value) {
|
|
|
1448
1352
|
}
|
|
1449
1353
|
const ATTRIBUTE_DIRECTION = "dir";
|
|
1450
1354
|
const EXPRESSION_DIRECTION = /^(ltr|rtl)$/i;
|
|
1355
|
+
//#endregion
|
|
1451
1356
|
export { findElement as $, findElement, findElements as $$, findElements, booleanAttributes, dispatch, findAncestor, findRelatives, getAttribute, getAttributes, getData, getDistance, getElementUnderPointer, getFocusable, getPosition, getStyle, getStyles, getTabbable, getTextDirection, html, isBadAttribute, isBooleanAttribute, isChildNode, isEmptyNonBooleanAttribute, isEventTarget, isFocusable, isHTMLOrSVGElement, isInDocument, isInvalidBooleanAttribute, isTabbable, off, on, sanitize, setAttribute, setAttributes, setData, setStyle, setStyles, supportsTouch, toggleStyles };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Attribute } from "../models.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/internal/attribute.d.ts
|
|
4
|
+
declare function isAttribute(value: unknown): value is Attr | Attribute;
|
|
5
|
+
declare function _isBadAttribute(first: unknown, second: unknown, decode: boolean): boolean;
|
|
6
|
+
declare function _isBooleanAttribute(first: unknown, decode: boolean): boolean;
|
|
7
|
+
declare function _isEmptyNonBooleanAttribute(first: unknown, second: unknown, decode: boolean): boolean;
|
|
8
|
+
declare function _isInvalidBooleanAttribute(first: unknown, second: unknown, decode: boolean): boolean;
|
|
9
|
+
declare function updateAttribute(element: Element, name: string, value: unknown, dispatch?: unknown): void;
|
|
10
|
+
/**
|
|
11
|
+
* List of boolean attributes
|
|
12
|
+
*/
|
|
13
|
+
declare const booleanAttributes: readonly string[];
|
|
14
|
+
//#endregion
|
|
15
|
+
export { _isBadAttribute, _isBooleanAttribute, _isEmptyNonBooleanAttribute, _isInvalidBooleanAttribute, booleanAttributes, isAttribute, updateAttribute };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { updateElementValue } from "./element-value.
|
|
1
|
+
import { updateElementValue } from "./element-value.mjs";
|
|
2
2
|
import { isPlainObject } from "@oscarpalmer/atoms/is";
|
|
3
3
|
//#region src/internal/attribute.ts
|
|
4
4
|
function badAttributeHandler(name, value) {
|
|
@@ -63,18 +63,18 @@ function updateProperty(element, name, value, dispatch) {
|
|
|
63
63
|
const event = dispatch !== false && elementEvents[element.tagName]?.[name];
|
|
64
64
|
if (typeof event === "string") element.dispatchEvent(new Event(event, { bubbles: true }));
|
|
65
65
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
66
|
+
const EXPRESSION_CLOBBERED_NAME = /^(id|name)$/i;
|
|
67
|
+
const EXPRESSION_DATA_OR_SCRIPT = /^(?:data|\w+script):/i;
|
|
68
|
+
const EXPRESSION_EVENT_NAME = /^on/i;
|
|
69
|
+
const EXPRESSION_SKIP_NAME = /^(aria-[-\w]+|data-[-\w.\u00B7-\uFFFF]+)$/i;
|
|
70
|
+
const EXPRESSION_SOURCE_NAME = /^src$/i;
|
|
71
|
+
const EXPRESSION_SOURCE_VALUE = /^data:/i;
|
|
72
|
+
const EXPRESSION_URI_VALUE = /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.-]+(?:[^a-z+.\-:]|$))/i;
|
|
73
|
+
const EXPRESSION_WHITESPACE = /[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g;
|
|
74
74
|
/**
|
|
75
75
|
* List of boolean attributes
|
|
76
76
|
*/
|
|
77
|
-
|
|
77
|
+
const booleanAttributes = Object.freeze([
|
|
78
78
|
"async",
|
|
79
79
|
"autofocus",
|
|
80
80
|
"autoplay",
|
|
@@ -100,8 +100,8 @@ var booleanAttributes = Object.freeze([
|
|
|
100
100
|
"reversed",
|
|
101
101
|
"selected"
|
|
102
102
|
]);
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
const booleanAttributesSet = new Set(booleanAttributes);
|
|
104
|
+
const elementEvents = {
|
|
105
105
|
DETAILS: { open: "toggle" },
|
|
106
106
|
INPUT: {
|
|
107
107
|
checked: "change",
|
|
@@ -110,7 +110,7 @@ var elementEvents = {
|
|
|
110
110
|
SELECT: { value: "change" },
|
|
111
111
|
TEXTAREA: { value: "input" }
|
|
112
112
|
};
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
const formElement = document.createElement("form");
|
|
114
|
+
let textArea;
|
|
115
115
|
//#endregion
|
|
116
116
|
export { _isBadAttribute, _isBooleanAttribute, _isEmptyNonBooleanAttribute, _isInvalidBooleanAttribute, booleanAttributes, isAttribute, updateAttribute };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
//#region src/internal/element-value.d.ts
|
|
2
|
+
declare function setElementValue(element: Element, first: unknown, second: unknown, third: unknown, callback: (element: Element, key: string, value: unknown) => void): void;
|
|
3
|
+
declare function setElementValues(element: Element, first: unknown, second: unknown, third: unknown, callback: (element: Element, key: string, value: unknown, dispatch?: unknown) => void): void;
|
|
4
|
+
declare function updateElementValue(element: Element, key: string, value: unknown, set: (key: string, value: string) => void, remove: (key: string) => void, isBoolean: boolean, json: boolean): void;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { setElementValue, setElementValues, updateElementValue };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { isHTMLOrSVGElement } from "./is.
|
|
2
|
-
import "../is.
|
|
3
|
-
import { isAttribute } from "./attribute.
|
|
1
|
+
import { isHTMLOrSVGElement } from "./is.mjs";
|
|
2
|
+
import "../is.mjs";
|
|
3
|
+
import { isAttribute } from "./attribute.mjs";
|
|
4
4
|
import { isNullableOrWhitespace } from "@oscarpalmer/atoms/is";
|
|
5
5
|
//#region src/internal/element-value.ts
|
|
6
6
|
function setElementValue(element, first, second, third, callback) {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/internal/get-value.d.ts
|
|
2
|
+
declare function getBoolean(value: unknown, defaultValue?: boolean): boolean;
|
|
3
|
+
declare function getAttributeValue(element: Element, name: string, parseValue: boolean): unknown;
|
|
4
|
+
declare function getStyleValue(element: Element, property: string, computed: boolean): string | undefined;
|
|
5
|
+
declare const EXPRESSION_DATA_PREFIX: RegExp;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { EXPRESSION_DATA_PREFIX, getAttributeValue, getBoolean, getStyleValue };
|
|
@@ -14,6 +14,6 @@ function getStyleValue(element, property, computed) {
|
|
|
14
14
|
const name = camelCase(property);
|
|
15
15
|
return computed ? getComputedStyle(element)[name] : element.style[name];
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
const EXPRESSION_DATA_PREFIX = /^data-/i;
|
|
18
18
|
//#endregion
|
|
19
19
|
export { EXPRESSION_DATA_PREFIX, getAttributeValue, getBoolean, getStyleValue };
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
//#region src/internal/is.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Is the value an event target?
|
|
3
4
|
* @param value Value to check
|
|
4
5
|
* @returns `true` if it's an event target, otherwise `false`
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
|
+
declare function isEventTarget(value: unknown): value is EventTarget;
|
|
7
8
|
/**
|
|
8
9
|
* Is the value an HTML or SVG element?
|
|
9
10
|
* @param value Value to check
|
|
10
11
|
* @returns `true` if it's an HTML or SVG element, otherwise `false`
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
|
+
declare function isHTMLOrSVGElement(value: unknown): value is HTMLElement | SVGElement;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { isEventTarget, isHTMLOrSVGElement };
|
|
@@ -1,20 +1,24 @@
|
|
|
1
|
+
import { isEventTarget, isHTMLOrSVGElement } from "./internal/is.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/is.d.ts
|
|
1
4
|
/**
|
|
2
5
|
* Is the value a child node?
|
|
3
6
|
* @param value Value to check
|
|
4
7
|
* @returns `true` if it's a child node, otherwise `false`
|
|
5
8
|
*/
|
|
6
|
-
|
|
9
|
+
declare function isChildNode(value: unknown): value is ChildNode;
|
|
7
10
|
/**
|
|
8
11
|
* Is the node inside a document?
|
|
9
12
|
* @param node Node to check
|
|
10
13
|
* @returns `true` if it's inside a document, otherwise `false`
|
|
11
14
|
*/
|
|
12
|
-
|
|
15
|
+
declare function isInDocument(node: Node): boolean;
|
|
13
16
|
/**
|
|
14
17
|
* Is the node inside a specific document?
|
|
15
18
|
* @param node Node to check
|
|
16
19
|
* @param document Document to check within
|
|
17
20
|
* @returns `true` if it's inside the document, otherwise `false`
|
|
18
21
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
declare function isInDocument(node: Node, document: Document): boolean;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { isChildNode, isEventTarget, isHTMLOrSVGElement, isInDocument };
|
package/dist/{is.js → is.mjs}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isEventTarget, isHTMLOrSVGElement } from "./internal/is.
|
|
1
|
+
import { isEventTarget, isHTMLOrSVGElement } from "./internal/is.mjs";
|
|
2
2
|
//#region src/is.ts
|
|
3
3
|
/**
|
|
4
4
|
* Is the value a child node?
|
|
@@ -13,7 +13,7 @@ function isInDocument(node, doc) {
|
|
|
13
13
|
if (!(doc instanceof Document)) return node.ownerDocument?.contains(node) ?? true;
|
|
14
14
|
return node.ownerDocument == null ? node === doc : node.ownerDocument === doc && doc.contains(node);
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
const CHILD_NODE_TYPES = new Set([
|
|
17
17
|
Node.ELEMENT_NODE,
|
|
18
18
|
Node.TEXT_NODE,
|
|
19
19
|
Node.PROCESSING_INSTRUCTION_NODE,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/models.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Attribute for an element
|
|
4
|
+
*/
|
|
5
|
+
type Attribute = {
|
|
6
|
+
name: string;
|
|
7
|
+
value: unknown;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Event listener for custom events
|
|
11
|
+
*/
|
|
12
|
+
type CustomEventListener = (event: CustomEvent) => void;
|
|
13
|
+
/**
|
|
14
|
+
* The position of an event
|
|
15
|
+
*/
|
|
16
|
+
type EventPosition = {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Event listener that can be removed
|
|
22
|
+
*/
|
|
23
|
+
type RemovableEventListener = () => void;
|
|
24
|
+
/**
|
|
25
|
+
* Selector that be searched for
|
|
26
|
+
*/
|
|
27
|
+
type Selector = string | Node | Node[] | NodeList;
|
|
28
|
+
/**
|
|
29
|
+
* Text direction for an element
|
|
30
|
+
*/
|
|
31
|
+
type TextDirection = 'ltr' | 'rtl';
|
|
32
|
+
//#endregion
|
|
33
|
+
export { Attribute, CustomEventListener, EventPosition, RemovableEventListener, Selector, TextDirection };
|
package/dist/models.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|