@oscarpalmer/toretto 0.39.2 → 0.40.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} +85 -23
- 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/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,10 +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() {}
|
|
655
|
+
//#endregion
|
|
656
|
+
//#region node_modules/@oscarpalmer/atoms/dist/function/assert.mjs
|
|
614
657
|
/**
|
|
615
658
|
* Asserts that a condition is true, throwing an error if it is not
|
|
616
659
|
* @param condition Condition to assert
|
|
@@ -668,7 +711,9 @@ function assertIs(condition, message, error) {
|
|
|
668
711
|
assert(() => condition(value), message, error);
|
|
669
712
|
};
|
|
670
713
|
}
|
|
671
|
-
|
|
714
|
+
const MESSAGE_VALUE_DEFINED = "Expected value to be defined";
|
|
715
|
+
//#endregion
|
|
716
|
+
//#region node_modules/@oscarpalmer/atoms/dist/function/once.mjs
|
|
672
717
|
/**
|
|
673
718
|
* Create an asynchronous function that can only be called once, rejecting or resolving the same result on subsequent calls
|
|
674
719
|
* @param callback Callback to use once
|
|
@@ -762,8 +807,10 @@ function once(callback) {
|
|
|
762
807
|
return fn;
|
|
763
808
|
}
|
|
764
809
|
once.async = asyncOnce;
|
|
765
|
-
|
|
766
|
-
|
|
810
|
+
const MESSAGE_CLEARED = "Once has been cleared";
|
|
811
|
+
const MESSAGE_EXPECTATION = "Once expected a function";
|
|
812
|
+
//#endregion
|
|
813
|
+
//#region src/event/delegation.ts
|
|
767
814
|
function addDelegatedHandler(doc, type, name, passive) {
|
|
768
815
|
if (DELEGATED.has(name)) return;
|
|
769
816
|
DELEGATED.add(name);
|
|
@@ -845,6 +892,8 @@ const EVENT_TYPES = new Set([
|
|
|
845
892
|
]);
|
|
846
893
|
const HANDLER_ACTIVE = delegatedEventHandler.bind(false);
|
|
847
894
|
const HANDLER_PASSIVE = delegatedEventHandler.bind(true);
|
|
895
|
+
//#endregion
|
|
896
|
+
//#region src/event/index.ts
|
|
848
897
|
function createDispatchOptions(options) {
|
|
849
898
|
return {
|
|
850
899
|
bubbles: getBoolean(options?.bubbles, true),
|
|
@@ -916,6 +965,8 @@ function on(target, type, listener, options) {
|
|
|
916
965
|
};
|
|
917
966
|
}
|
|
918
967
|
const PROPERTY_DETAIL = "detail";
|
|
968
|
+
//#endregion
|
|
969
|
+
//#region src/find/relative.ts
|
|
919
970
|
function findAncestor(origin, selector) {
|
|
920
971
|
const element = getElement(origin);
|
|
921
972
|
if (element == null || selector == null) return null;
|
|
@@ -992,6 +1043,8 @@ function traverse(from, to) {
|
|
|
992
1043
|
parent = parent.parentElement;
|
|
993
1044
|
}
|
|
994
1045
|
}
|
|
1046
|
+
//#endregion
|
|
1047
|
+
//#region src/find/index.ts
|
|
995
1048
|
function findElement(selector, context) {
|
|
996
1049
|
return findElementOrElements(selector, context, true);
|
|
997
1050
|
}
|
|
@@ -1062,6 +1115,8 @@ const STYLE_HIDDEN$1 = "hidden";
|
|
|
1062
1115
|
const STYLE_NONE$1 = "none";
|
|
1063
1116
|
const SUFFIX_HOVER = ":hover";
|
|
1064
1117
|
const TAG_HEAD = "HEAD";
|
|
1118
|
+
//#endregion
|
|
1119
|
+
//#region src/focusable.ts
|
|
1065
1120
|
/**
|
|
1066
1121
|
* Get a list of focusable elements within a parent element
|
|
1067
1122
|
* @param parent Parent element
|
|
@@ -1223,6 +1278,8 @@ const STYLE_NONE = "none";
|
|
|
1223
1278
|
const TABINDEX_BASE = 0;
|
|
1224
1279
|
const TABINDEX_DEFAULT = -1;
|
|
1225
1280
|
const TYPE_RADIO = "radio";
|
|
1281
|
+
//#endregion
|
|
1282
|
+
//#region src/html/sanitize.ts
|
|
1226
1283
|
function handleElement(element, depth) {
|
|
1227
1284
|
if (depth === 0) {
|
|
1228
1285
|
const removable = element.querySelectorAll(REMOVE_SELECTOR);
|
|
@@ -1280,6 +1337,8 @@ function sanitizeNodes(nodes, depth) {
|
|
|
1280
1337
|
}
|
|
1281
1338
|
const COMMENT_HARMFUL = /<[/\w]/g;
|
|
1282
1339
|
const REMOVE_SELECTOR = "script, toretto-temporary";
|
|
1340
|
+
//#endregion
|
|
1341
|
+
//#region src/html/index.ts
|
|
1283
1342
|
function createHtml(value) {
|
|
1284
1343
|
const parsed = getParser().parseFromString(getHtml(value), PARSE_TYPE_HTML);
|
|
1285
1344
|
parsed.body.normalize();
|
|
@@ -1349,6 +1408,8 @@ const TEMPLATE_TAG = "template";
|
|
|
1349
1408
|
const TEMPORARY_ELEMENT = "<toretto-temporary></toretto-temporary>";
|
|
1350
1409
|
let parser;
|
|
1351
1410
|
let templates = {};
|
|
1411
|
+
//#endregion
|
|
1412
|
+
//#region src/style.ts
|
|
1352
1413
|
/**
|
|
1353
1414
|
* Get a style from an element
|
|
1354
1415
|
* @param element Element to get the style from
|
|
@@ -1448,4 +1509,5 @@ function updateStyleProperty(element, key, value) {
|
|
|
1448
1509
|
}
|
|
1449
1510
|
const ATTRIBUTE_DIRECTION = "dir";
|
|
1450
1511
|
const EXPRESSION_DIRECTION = /^(ltr|rtl)$/i;
|
|
1512
|
+
//#endregion
|
|
1451
1513
|
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 {};
|
package/dist/style.d.mts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { TextDirection } from "./models.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/style.d.ts
|
|
4
|
+
type StyleToggler = {
|
|
5
|
+
/**
|
|
6
|
+
* Set the provided styles on the element
|
|
7
|
+
*/
|
|
8
|
+
set(): void;
|
|
9
|
+
/**
|
|
10
|
+
* Remove the provided styles from the element _(and sets any previous styles)_
|
|
11
|
+
*/
|
|
12
|
+
remove(): void;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Get a style from an element
|
|
16
|
+
* @param element Element to get the style from
|
|
17
|
+
* @param property Style name
|
|
18
|
+
* @param computed Get the computed style? _(defaults to `false`)_
|
|
19
|
+
* @returns Style value
|
|
20
|
+
*/
|
|
21
|
+
declare function getStyle(element: Element, property: keyof CSSStyleDeclaration, computed?: boolean): string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Get styles from an element
|
|
24
|
+
* @param element Element to get the styles from
|
|
25
|
+
* @param properties Styles to get
|
|
26
|
+
* @param computed Get the computed styles? _(defaults to `false`)_
|
|
27
|
+
* @returns Style values
|
|
28
|
+
*/
|
|
29
|
+
declare function getStyles<Property extends keyof CSSStyleDeclaration>(element: Element, properties: Property[], computed?: boolean): Record<Property, string | undefined>;
|
|
30
|
+
/**
|
|
31
|
+
* Get the text direction of an element
|
|
32
|
+
* @param element Element to get the text direction from
|
|
33
|
+
* @param computed Get the computed text direction? _(defaults to `false`)_
|
|
34
|
+
* @returns Text direction
|
|
35
|
+
*/
|
|
36
|
+
declare function getTextDirection(element: Element, computed?: boolean): TextDirection;
|
|
37
|
+
/**
|
|
38
|
+
* Set a style on an element
|
|
39
|
+
* @param element Element to set the style on
|
|
40
|
+
* @param property Style name
|
|
41
|
+
* @param value Style value
|
|
42
|
+
*/
|
|
43
|
+
declare function setStyle(element: Element, property: keyof CSSStyleDeclaration, value?: string): void;
|
|
44
|
+
/**
|
|
45
|
+
* Set styles on an element
|
|
46
|
+
* @param element Element to set the styles on
|
|
47
|
+
* @param styles Styles to set
|
|
48
|
+
*/
|
|
49
|
+
declare function setStyles(element: Element, styles: Partial<CSSStyleDeclaration>): void;
|
|
50
|
+
/**
|
|
51
|
+
* Toggle styles for an element
|
|
52
|
+
* @param element Element to style
|
|
53
|
+
* @param styles Styles to be set or removed
|
|
54
|
+
* @returns Style toggler
|
|
55
|
+
*/
|
|
56
|
+
declare function toggleStyles(element: Element, styles: Partial<CSSStyleDeclaration>): StyleToggler;
|
|
57
|
+
//#endregion
|
|
58
|
+
export { StyleToggler, getStyle, getStyles, getTextDirection, setStyle, setStyles, toggleStyles };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { isHTMLOrSVGElement } from "./internal/is.mjs";
|
|
2
|
+
import { setElementValues, updateElementValue } from "./internal/element-value.mjs";
|
|
3
|
+
import { getStyleValue } from "./internal/get-value.mjs";
|
|
4
4
|
//#region src/style.ts
|
|
5
5
|
/**
|
|
6
6
|
* Get a style from an element
|
|
@@ -99,7 +99,7 @@ function updateStyleProperty(element, key, value) {
|
|
|
99
99
|
this.style[property] = "";
|
|
100
100
|
}, false, false);
|
|
101
101
|
}
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
const ATTRIBUTE_DIRECTION = "dir";
|
|
103
|
+
const EXPRESSION_DIRECTION = /^(ltr|rtl)$/i;
|
|
104
104
|
//#endregion
|
|
105
105
|
export { getStyle, getStyles, getTextDirection, setStyle, setStyles, toggleStyles };
|
package/dist/touch.d.mts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/touch.d.ts
|
|
2
|
+
type SupporsTouch = {
|
|
3
|
+
/**
|
|
4
|
+
* Are touch events supported?
|
|
5
|
+
*/
|
|
6
|
+
readonly value: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Are touch events supported?
|
|
9
|
+
*/
|
|
10
|
+
get(): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Re-evaluate if touch events are supported
|
|
13
|
+
*/
|
|
14
|
+
update(): boolean;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Does the device support touch events?
|
|
18
|
+
*/
|
|
19
|
+
declare const supportsTouch: SupporsTouch;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { supportsTouch as default };
|