@oscarpalmer/toretto 0.39.1 → 0.39.2
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/index.js +4 -1
- package/dist/toretto.full.js +31 -1
- package/package.json +1 -1
- package/src/index.ts +5 -0
- package/types/index.d.ts +74 -0
package/dist/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { isEventTarget, isHTMLOrSVGElement } from "./internal/is.js";
|
|
2
|
+
import { getAttribute, getAttributes } from "./attribute/get.js";
|
|
2
3
|
import { isChildNode, isInDocument } from "./is.js";
|
|
4
|
+
import { booleanAttributes } from "./internal/attribute.js";
|
|
5
|
+
import { setAttribute, setAttributes } from "./attribute/set.js";
|
|
3
6
|
import { isBadAttribute, isBooleanAttribute, isEmptyNonBooleanAttribute, isInvalidBooleanAttribute } from "./attribute/index.js";
|
|
4
7
|
import { getData, setData } from "./data.js";
|
|
5
8
|
import { dispatch, getPosition, off, on } from "./event/index.js";
|
|
@@ -9,4 +12,4 @@ import { getFocusable, getTabbable, isFocusable, isTabbable } from "./focusable.
|
|
|
9
12
|
import { html, sanitize } from "./html/index.js";
|
|
10
13
|
import supportsTouch from "./touch.js";
|
|
11
14
|
import { getStyle, getStyles, getTextDirection, setStyle, setStyles, toggleStyles } from "./style.js";
|
|
12
|
-
export { findElement as $, findElement, findElements as $$, findElements, dispatch, findAncestor, findRelatives, getData, getDistance, getElementUnderPointer, getFocusable, getPosition, getStyle, getStyles, getTabbable, getTextDirection, html, isBadAttribute, isBooleanAttribute, isChildNode, isEmptyNonBooleanAttribute, isEventTarget, isFocusable, isHTMLOrSVGElement, isInDocument, isInvalidBooleanAttribute, isTabbable, off, on, sanitize, setData, setStyle, setStyles, supportsTouch, toggleStyles };
|
|
15
|
+
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 };
|
package/dist/toretto.full.js
CHANGED
|
@@ -529,14 +529,44 @@ var memoizedCapitalize;
|
|
|
529
529
|
function getBoolean(value, defaultValue) {
|
|
530
530
|
return typeof value === "boolean" ? value : defaultValue ?? false;
|
|
531
531
|
}
|
|
532
|
+
function getAttributeValue(element, name, parseValue) {
|
|
533
|
+
const normalized = kebabCase(name);
|
|
534
|
+
const attribute = element.attributes[normalized];
|
|
535
|
+
const value = attribute instanceof Attr ? attribute.value : void 0;
|
|
536
|
+
return EXPRESSION_DATA_PREFIX.test(normalized) && typeof value === "string" && parseValue ? parse(value) ?? value : value;
|
|
537
|
+
}
|
|
532
538
|
function getStyleValue(element, property, computed) {
|
|
533
539
|
const name = camelCase(property);
|
|
534
540
|
return computed ? getComputedStyle(element)[name] : element.style[name];
|
|
535
541
|
}
|
|
536
542
|
const EXPRESSION_DATA_PREFIX = /^data-/i;
|
|
543
|
+
function getAttribute(element, name, parseValues) {
|
|
544
|
+
if (isHTMLOrSVGElement(element) && typeof name === "string") return getAttributeValue(element, name, parseValues !== false);
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Get specific attributes from an element
|
|
548
|
+
* @param element Element to get attributes from
|
|
549
|
+
* @param names Attribute names
|
|
550
|
+
* @param parseData Parse data values? _(defaults to `true`)_
|
|
551
|
+
* @returns Object of named attributes
|
|
552
|
+
*/
|
|
553
|
+
function getAttributes(element, names, parseData) {
|
|
554
|
+
const attributes = {};
|
|
555
|
+
if (!(isHTMLOrSVGElement(element) && Array.isArray(names))) return attributes;
|
|
556
|
+
const shouldParse = parseData !== false;
|
|
557
|
+
const { length } = names;
|
|
558
|
+
for (let index = 0; index < length; index += 1) {
|
|
559
|
+
const name = names[index];
|
|
560
|
+
if (typeof name === "string") attributes[name] = getAttributeValue(element, name, shouldParse);
|
|
561
|
+
}
|
|
562
|
+
return attributes;
|
|
563
|
+
}
|
|
537
564
|
function setAttribute(element, first, second, third) {
|
|
538
565
|
setElementValue(element, first, second, third, updateAttribute);
|
|
539
566
|
}
|
|
567
|
+
function setAttributes(element, attributes, dispatch) {
|
|
568
|
+
setElementValues(element, attributes, null, dispatch, updateAttribute);
|
|
569
|
+
}
|
|
540
570
|
function isBadAttribute(first, second) {
|
|
541
571
|
return _isBadAttribute(first, second, true);
|
|
542
572
|
}
|
|
@@ -1418,4 +1448,4 @@ function updateStyleProperty(element, key, value) {
|
|
|
1418
1448
|
}
|
|
1419
1449
|
const ATTRIBUTE_DIRECTION = "dir";
|
|
1420
1450
|
const EXPRESSION_DIRECTION = /^(ltr|rtl)$/i;
|
|
1421
|
-
export { findElement as $, findElement, findElements as $$, findElements, dispatch, findAncestor, findRelatives, getData, getDistance, getElementUnderPointer, getFocusable, getPosition, getStyle, getStyles, getTabbable, getTextDirection, html, isBadAttribute, isBooleanAttribute, isChildNode, isEmptyNonBooleanAttribute, isEventTarget, isFocusable, isHTMLOrSVGElement, isInDocument, isInvalidBooleanAttribute, isTabbable, off, on, sanitize, setData, setStyle, setStyles, supportsTouch, toggleStyles };
|
|
1451
|
+
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 };
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import supportsTouch from './touch';
|
|
2
2
|
|
|
3
3
|
export {
|
|
4
|
+
booleanAttributes,
|
|
5
|
+
getAttribute,
|
|
6
|
+
getAttributes,
|
|
4
7
|
isBadAttribute,
|
|
5
8
|
isBooleanAttribute,
|
|
6
9
|
isEmptyNonBooleanAttribute,
|
|
7
10
|
isInvalidBooleanAttribute,
|
|
11
|
+
setAttribute,
|
|
12
|
+
setAttributes,
|
|
8
13
|
} from './attribute/index';
|
|
9
14
|
export * from './data';
|
|
10
15
|
export * from './event/index';
|
package/types/index.d.ts
CHANGED
|
@@ -48,6 +48,80 @@ export type Selector = string | Node | Node[] | NodeList;
|
|
|
48
48
|
* Text direction for an element
|
|
49
49
|
*/
|
|
50
50
|
export type TextDirection = "ltr" | "rtl";
|
|
51
|
+
/**
|
|
52
|
+
* List of boolean attributes
|
|
53
|
+
*/
|
|
54
|
+
export declare const booleanAttributes: readonly string[];
|
|
55
|
+
/**
|
|
56
|
+
* Get the value of a specific attribute from an element
|
|
57
|
+
* @param element Element to get attribute from
|
|
58
|
+
* @param name Attribute name
|
|
59
|
+
* @param parse Parse value? _(defaults to `true`)_
|
|
60
|
+
* @returns Attribute value _(or `undefined`)_
|
|
61
|
+
*/
|
|
62
|
+
export declare function getAttribute(element: Element, name: `data-${string}`, parse?: boolean): unknown;
|
|
63
|
+
/**
|
|
64
|
+
* Get the value of a specific attribute from an element
|
|
65
|
+
* @param element Element to get attribute from
|
|
66
|
+
* @param name Attribute name
|
|
67
|
+
* @returns Attribute value _(or `undefined`)_
|
|
68
|
+
*/
|
|
69
|
+
export declare function getAttribute(element: Element, name: string): unknown;
|
|
70
|
+
/**
|
|
71
|
+
* Get specific attributes from an element
|
|
72
|
+
* @param element Element to get attributes from
|
|
73
|
+
* @param names Attribute names
|
|
74
|
+
* @param parseData Parse data values? _(defaults to `true`)_
|
|
75
|
+
* @returns Object of named attributes
|
|
76
|
+
*/
|
|
77
|
+
export declare function getAttributes<Key extends string>(element: Element, names: Key[], parseData?: boolean): Record<Key, unknown>;
|
|
78
|
+
export type DispatchedAttribute = "checked" | "open" | "value";
|
|
79
|
+
/**
|
|
80
|
+
* Set an attribute on an element
|
|
81
|
+
*
|
|
82
|
+
* _(Or remove it, if value is `null` or `undefined`)_
|
|
83
|
+
* @param element Element for attribute
|
|
84
|
+
* @param name Attribute name
|
|
85
|
+
* @param value Attribute value
|
|
86
|
+
* @param dispatch Dispatch event for attribute? _(defaults to `true`)_
|
|
87
|
+
*/
|
|
88
|
+
export declare function setAttribute<Name extends DispatchedAttribute>(element: Element, name: Name, value?: unknown, dispatch?: boolean): void;
|
|
89
|
+
/**
|
|
90
|
+
* Set an attribute on an element
|
|
91
|
+
*
|
|
92
|
+
* _(Or remove it, if value is `null` or `undefined`)_
|
|
93
|
+
* @param element Element for attribute
|
|
94
|
+
* @param name Attribute name
|
|
95
|
+
* @param value Attribute value
|
|
96
|
+
*/
|
|
97
|
+
export declare function setAttribute(element: Element, name: string, value?: unknown): void;
|
|
98
|
+
/**
|
|
99
|
+
* Set an attribute on an element
|
|
100
|
+
*
|
|
101
|
+
* _(Or remove it, if value is `null` or `undefined`)_
|
|
102
|
+
* @param element Element for attribute
|
|
103
|
+
* @param attribute Attribute to set
|
|
104
|
+
* @param dispatch Dispatch event for attribute? _(defaults to `true`)_
|
|
105
|
+
*/
|
|
106
|
+
export declare function setAttribute(element: Element, attribute: Attr | Attribute, dispatch?: boolean): void;
|
|
107
|
+
/**
|
|
108
|
+
* Set one or more attributes on an element
|
|
109
|
+
*
|
|
110
|
+
* _(Or remove them, if their value is `null` or `undefined`)_
|
|
111
|
+
* @param element Element for attributes
|
|
112
|
+
* @param attributes Attributes to set
|
|
113
|
+
* @param dispatch Dispatch events for relevant attributes? _(defaults to `true`)_
|
|
114
|
+
*/
|
|
115
|
+
export declare function setAttributes(element: Element, attributes: Array<Attr | Attribute>, dispatch?: boolean): void;
|
|
116
|
+
/**
|
|
117
|
+
* Set one or more attributes on an element
|
|
118
|
+
*
|
|
119
|
+
* _(Or remove them, if their value is `null` or `undefined`)_
|
|
120
|
+
* @param element Element for attributes
|
|
121
|
+
* @param attributes Attributes to set
|
|
122
|
+
* @param dispatch Dispatch events for relevant attributes? _(defaults to `true`)_
|
|
123
|
+
*/
|
|
124
|
+
export declare function setAttributes(element: Element, attributes: Record<string, unknown>, dispatch?: boolean): void;
|
|
51
125
|
/**
|
|
52
126
|
* Is the attribute considered bad and potentially harmful?
|
|
53
127
|
* @param attribute Attribute to check
|