@oscarpalmer/toretto 0.47.3 → 0.49.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/aria.d.mts +36 -12
- package/dist/aria.mjs +35 -3
- package/dist/attribute/index.d.mts +0 -1
- package/dist/attribute/set.attribute.d.mts +0 -1
- package/dist/create.d.mts +14 -11
- package/dist/create.mjs +20 -4
- package/dist/data.d.mts +22 -7
- package/dist/event/delegation.d.mts +0 -1
- package/dist/event/index.d.mts +6 -3
- package/dist/event/index.mjs +4 -1
- package/dist/find/index.d.mts +0 -1
- package/dist/index.d.mts +114 -41
- package/dist/index.mjs +104 -56
- package/dist/internal/attribute.d.mts +0 -1
- package/dist/internal/is.d.mts +0 -1
- package/dist/is.d.mts +0 -1
- package/dist/models.d.mts +31 -3
- package/dist/property/get.property.d.mts +1 -2
- package/dist/property/set.property.d.mts +1 -2
- package/dist/style.d.mts +9 -13
- package/dist/style.mjs +18 -18
- package/package.json +3 -3
- package/src/aria.ts +102 -22
- package/src/create.ts +45 -30
- package/src/data.ts +25 -7
- package/src/event/index.ts +18 -8
- package/src/models.ts +57 -2
- package/src/style.ts +30 -40
package/dist/aria.d.mts
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { AnyAriaAttribute, AnyAriaBooleanAttribute, AriaRole } from "./models.mjs";
|
|
3
2
|
//#region src/aria.d.ts
|
|
4
|
-
type AnyAriaAttribute =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
value?: string;
|
|
3
|
+
type AriaAttributeItem<Name extends AnyAriaAttribute = AnyAriaAttribute> = {
|
|
4
|
+
name: Name;
|
|
5
|
+
value?: Name extends AnyAriaBooleanAttribute ? boolean | string : string;
|
|
8
6
|
};
|
|
9
7
|
/**
|
|
10
8
|
* Get the value of a specific _ARIA_ attribute from an element
|
|
11
9
|
*
|
|
12
10
|
* @param element Element to get _ARIA_ attribute from
|
|
13
|
-
* @param name _ARIA_ name
|
|
11
|
+
* @param name _ARIA_ attribute name
|
|
14
12
|
* @returns _ARIA_ value _(or `undefined`)_
|
|
15
13
|
*/
|
|
16
|
-
declare function getAria(element: Element,
|
|
14
|
+
declare function getAria(element: Element, name: AnyAriaBooleanAttribute): boolean | string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Get the value of a specific _ARIA_ attribute from an element
|
|
17
|
+
*
|
|
18
|
+
* @param element Element to get _ARIA_ attribute from
|
|
19
|
+
* @param name _ARIA_ attribute name
|
|
20
|
+
* @returns _ARIA_ value _(or `undefined`)_
|
|
21
|
+
*/
|
|
22
|
+
declare function getAria(element: Element, name: AnyAriaAttribute): string | undefined;
|
|
17
23
|
/**
|
|
18
24
|
* Get specific _ARIA_ attributes from an element
|
|
19
25
|
*
|
|
@@ -21,7 +27,7 @@ declare function getAria(element: Element, attribute: AnyAriaAttribute): string
|
|
|
21
27
|
* @param names _ARIA_ attribute names
|
|
22
28
|
* @returns Object of named _ARIA_ attributes
|
|
23
29
|
*/
|
|
24
|
-
declare function getAria<Attribute extends AnyAriaAttribute>(element: Element,
|
|
30
|
+
declare function getAria<Attribute extends AnyAriaAttribute>(element: Element, names: Attribute[]): { [Key in Attribute as Key extends `aria-${infer Name}` ? Name : Key]: Key extends AnyAriaBooleanAttribute ? boolean | string | undefined : string | undefined; };
|
|
25
31
|
/**
|
|
26
32
|
* Get the role of an element
|
|
27
33
|
*
|
|
@@ -38,7 +44,17 @@ declare function getRole(element: Element): string | undefined;
|
|
|
38
44
|
* @param attribute _ARIA_ attribute to set
|
|
39
45
|
* @param value _ARIA_ attribute value
|
|
40
46
|
*/
|
|
41
|
-
declare function setAria(element: Element, attribute:
|
|
47
|
+
declare function setAria(element: Element, attribute: AnyAriaBooleanAttribute, value?: boolean | string): void;
|
|
48
|
+
/**
|
|
49
|
+
* Set an _ARIA_ attribute on an element
|
|
50
|
+
*
|
|
51
|
+
* _(Or remove it, if value is `null` or `undefined`)_
|
|
52
|
+
*
|
|
53
|
+
* @param element Element for _ARIA_ attribute
|
|
54
|
+
* @param attribute _ARIA_ attribute to set
|
|
55
|
+
* @param value _ARIA_ attribute value
|
|
56
|
+
*/
|
|
57
|
+
declare function setAria(element: Element, attribute: AnyAriaAttribute, value?: string): void;
|
|
42
58
|
/**
|
|
43
59
|
* Set one or more _ARIA_ attributes on an element
|
|
44
60
|
*
|
|
@@ -56,7 +72,7 @@ declare function setAria(element: Element, attributes: AriaAttributeItem[]): voi
|
|
|
56
72
|
* @param element Element for _ARIA_ attributes
|
|
57
73
|
* @param attributes _ARIA_ attributes to set
|
|
58
74
|
*/
|
|
59
|
-
declare function setAria(element: Element, attributes:
|
|
75
|
+
declare function setAria(element: Element, attributes: { [Key in AnyAriaAttribute]?: Key extends AnyAriaBooleanAttribute ? boolean | string : string; }): void;
|
|
60
76
|
/**
|
|
61
77
|
* Set the role of an element
|
|
62
78
|
*
|
|
@@ -64,5 +80,13 @@ declare function setAria(element: Element, attributes: Partial<Record<AnyAriaAtt
|
|
|
64
80
|
* @param role Role to set _(or `undefined` to remove it)_
|
|
65
81
|
*/
|
|
66
82
|
declare function setRole(element: Element, role?: AriaRole): void;
|
|
83
|
+
/**
|
|
84
|
+
* List of _ARIA_ attributes that can be treated as boolean values
|
|
85
|
+
*/
|
|
86
|
+
declare const ariaBooleanAttributes: readonly AnyAriaBooleanAttribute[];
|
|
87
|
+
/**
|
|
88
|
+
* Set of _ARIA_ attributes that can be treated as boolean values
|
|
89
|
+
*/
|
|
90
|
+
declare const ariaBooleanAttributesSet: Set<AnyAriaBooleanAttribute>;
|
|
67
91
|
//#endregion
|
|
68
|
-
export { getAria, getRole, setAria, setRole };
|
|
92
|
+
export { ariaBooleanAttributes, ariaBooleanAttributesSet, getAria, getRole, setAria, setRole };
|
package/dist/aria.mjs
CHANGED
|
@@ -12,7 +12,10 @@ function getAria(element, value) {
|
|
|
12
12
|
return arias;
|
|
13
13
|
}
|
|
14
14
|
function getAriaValue(element, attribute) {
|
|
15
|
-
|
|
15
|
+
const name = getName(attribute);
|
|
16
|
+
const value = element.getAttribute(name) ?? void 0;
|
|
17
|
+
if (ariaBooleanAttributesSet.has(name) && typeof value === "string" && EXPRESSION_BOOLEAN.test(value)) return value.toLowerCase() === "true";
|
|
18
|
+
return value;
|
|
16
19
|
}
|
|
17
20
|
function getName(value) {
|
|
18
21
|
return EXPRESSION_ARIA_PREFIX.test(value) ? value : `${ATTRIBUTE_ARIA_PREFIX}${value}`;
|
|
@@ -41,9 +44,38 @@ function setRole(element, role) {
|
|
|
41
44
|
else element.removeAttribute("role");
|
|
42
45
|
}
|
|
43
46
|
function updateAriaAttribute(element, key, value) {
|
|
44
|
-
|
|
47
|
+
const name = getName(key);
|
|
48
|
+
let actual = value;
|
|
49
|
+
if (ariaBooleanAttributesSet.has(name) && typeof value === "string" && EXPRESSION_BOOLEAN.test(value)) actual = value.toLowerCase() === "true";
|
|
50
|
+
updateElementValue(element, name, actual, element.setAttribute, element.removeAttribute, false, false);
|
|
45
51
|
}
|
|
46
52
|
const ATTRIBUTE_ARIA_PREFIX = "aria-";
|
|
47
53
|
const EXPRESSION_ARIA_PREFIX = /^aria-/i;
|
|
54
|
+
const EXPRESSION_BOOLEAN = /^(true|false)$/i;
|
|
55
|
+
/**
|
|
56
|
+
* List of _ARIA_ attributes that can be treated as boolean values
|
|
57
|
+
*/
|
|
58
|
+
const ariaBooleanAttributes = Object.freeze([
|
|
59
|
+
"aria-atomic",
|
|
60
|
+
"aria-busy",
|
|
61
|
+
"aria-checked",
|
|
62
|
+
"aria-current",
|
|
63
|
+
"aria-disabled",
|
|
64
|
+
"aria-expanded",
|
|
65
|
+
"aria-haspopup",
|
|
66
|
+
"aria-hidden",
|
|
67
|
+
"aria-invalid",
|
|
68
|
+
"aria-modal",
|
|
69
|
+
"aria-multiline",
|
|
70
|
+
"aria-multiselectable",
|
|
71
|
+
"aria-pressed",
|
|
72
|
+
"aria-readonly",
|
|
73
|
+
"aria-required",
|
|
74
|
+
"aria-selected"
|
|
75
|
+
]);
|
|
76
|
+
/**
|
|
77
|
+
* Set of _ARIA_ attributes that can be treated as boolean values
|
|
78
|
+
*/
|
|
79
|
+
const ariaBooleanAttributesSet = new Set(ariaBooleanAttributes);
|
|
48
80
|
//#endregion
|
|
49
|
-
export { getAria, getRole, setAria, setRole };
|
|
81
|
+
export { ariaBooleanAttributes, ariaBooleanAttributesSet, getAria, getRole, setAria, setRole };
|
|
@@ -2,7 +2,6 @@ import { Attribute } from "../models.mjs";
|
|
|
2
2
|
import { getAttribute, getAttributes } from "./get.attribute.mjs";
|
|
3
3
|
import { booleanAttributes } from "../internal/attribute.mjs";
|
|
4
4
|
import { setAttribute, setAttributes } from "./set.attribute.mjs";
|
|
5
|
-
|
|
6
5
|
//#region src/attribute/index.d.ts
|
|
7
6
|
/**
|
|
8
7
|
* Is the attribute considered bad and potentially harmful?
|
package/dist/create.d.mts
CHANGED
|
@@ -1,27 +1,30 @@
|
|
|
1
|
+
import { AnyAriaAttribute, AnyAriaBooleanAttribute, CSSValues } from "./models.mjs";
|
|
1
2
|
import { Primitive } from "@oscarpalmer/atoms/models";
|
|
2
|
-
|
|
3
3
|
//#region src/create.d.ts
|
|
4
|
-
type
|
|
5
|
-
|
|
4
|
+
type CreateElementValues<Target extends Element> = {
|
|
5
|
+
aria?: CreateElementValuesAria;
|
|
6
|
+
attribute?: Record<string, unknown>;
|
|
7
|
+
data?: Record<string, unknown>;
|
|
8
|
+
property?: CreateElementValuesProperties<Target>;
|
|
9
|
+
style?: Partial<CSSValues>;
|
|
10
|
+
};
|
|
11
|
+
type CreateElementValuesAria = { [Key in AnyAriaAttribute]?: Key extends AnyAriaBooleanAttribute ? boolean | string : string; };
|
|
12
|
+
type CreateElementValuesProperties<Target extends Element> = { [Property in keyof Target]?: Target[Property] extends Primitive ? Target[Property] : never; };
|
|
6
13
|
/**
|
|
7
14
|
* Creates an _HTML_ element with the specified tag name together with optional properties, attributes, and styles
|
|
8
15
|
*
|
|
9
16
|
* @param tag Tag name
|
|
10
|
-
* @param
|
|
11
|
-
* @param attributes Element attributes
|
|
12
|
-
* @param styles Element styles
|
|
17
|
+
* @param values Element values
|
|
13
18
|
* @returns Created element
|
|
14
19
|
*/
|
|
15
|
-
declare function createElement<TagName extends keyof HTMLElementTagNameMap>(tag: TagName,
|
|
20
|
+
declare function createElement<TagName extends keyof HTMLElementTagNameMap>(tag: TagName, values?: CreateElementValues<HTMLElementTagNameMap[TagName]>): HTMLElementTagNameMap[TagName];
|
|
16
21
|
/**
|
|
17
22
|
* Creates an _HTML_ element with the specified tag name together with optional properties, attributes, and styles
|
|
18
23
|
*
|
|
19
24
|
* @param tag Tag name
|
|
20
|
-
* @param
|
|
21
|
-
* @param attributes Element attributes
|
|
22
|
-
* @param styles Element styles
|
|
25
|
+
* @param values Element values
|
|
23
26
|
* @returns Created element
|
|
24
27
|
*/
|
|
25
|
-
declare function createElement(tag: string,
|
|
28
|
+
declare function createElement(tag: string, values?: CreateElementValues<HTMLElement>): HTMLUnknownElement;
|
|
26
29
|
//#endregion
|
|
27
30
|
export { createElement };
|
package/dist/create.mjs
CHANGED
|
@@ -1,17 +1,33 @@
|
|
|
1
|
+
import { setAria } from "./aria.mjs";
|
|
1
2
|
import { setAttributes } from "./attribute/set.attribute.mjs";
|
|
2
3
|
import "./attribute/index.mjs";
|
|
4
|
+
import { setData } from "./data.mjs";
|
|
3
5
|
import { setProperties } from "./property/set.property.mjs";
|
|
4
6
|
import "./property/index.mjs";
|
|
5
7
|
import { setStyles } from "./style.mjs";
|
|
8
|
+
import { isPlainObject } from "@oscarpalmer/atoms/is";
|
|
6
9
|
//#region src/create.ts
|
|
7
|
-
function createElement(tag,
|
|
10
|
+
function createElement(tag, values) {
|
|
8
11
|
if (typeof tag !== "string") throw new TypeError(MESSAGE);
|
|
9
12
|
const element = document.createElement(tag);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
const { aria, attribute, data, property, style } = getElementValues(values);
|
|
14
|
+
setAria(element, aria ?? {});
|
|
15
|
+
setAttributes(element, attribute ?? {});
|
|
16
|
+
setData(element, data ?? {});
|
|
17
|
+
setProperties(element, property ?? {});
|
|
18
|
+
setStyles(element, style ?? {});
|
|
13
19
|
return element;
|
|
14
20
|
}
|
|
21
|
+
function getElementValues(input) {
|
|
22
|
+
if (!isPlainObject(input)) return {};
|
|
23
|
+
return {
|
|
24
|
+
aria: isPlainObject(input.aria) ? input.aria : void 0,
|
|
25
|
+
attribute: isPlainObject(input.attribute) ? input.attribute : void 0,
|
|
26
|
+
data: isPlainObject(input.data) ? input.data : void 0,
|
|
27
|
+
property: isPlainObject(input.property) ? input.property : void 0,
|
|
28
|
+
style: isPlainObject(input.style) ? input.style : void 0
|
|
29
|
+
};
|
|
30
|
+
}
|
|
15
31
|
const MESSAGE = "Tag name must be a string";
|
|
16
32
|
//#endregion
|
|
17
33
|
export { createElement };
|
package/dist/data.d.mts
CHANGED
|
@@ -1,24 +1,39 @@
|
|
|
1
1
|
import { PlainObject } from "@oscarpalmer/atoms/models";
|
|
2
|
-
|
|
3
2
|
//#region src/data.d.ts
|
|
4
3
|
/**
|
|
5
|
-
* Get a keyed data value from an element
|
|
4
|
+
* Get a keyed data value from an element, without parsing the value
|
|
6
5
|
*
|
|
7
6
|
* @param element Element to get data from
|
|
8
7
|
* @param key Data key
|
|
9
|
-
* @param parse Parse
|
|
8
|
+
* @param parse Parse the value?
|
|
10
9
|
* @returns Data value
|
|
11
10
|
*/
|
|
12
|
-
declare function getData(element: Element, key: string, parse
|
|
11
|
+
declare function getData(element: Element, key: string, parse: false): string | undefined;
|
|
13
12
|
/**
|
|
14
|
-
* Get keyed data
|
|
13
|
+
* Get a keyed data value from an element and parse the value
|
|
14
|
+
*
|
|
15
|
+
* @param element Element to get data from
|
|
16
|
+
* @param key Data key
|
|
17
|
+
* @returns Data value
|
|
18
|
+
*/
|
|
19
|
+
declare function getData(element: Element, key: string): unknown;
|
|
20
|
+
/**
|
|
21
|
+
* Get keyed data values from an element, without parsing the values
|
|
22
|
+
*
|
|
23
|
+
* @param element Element to get data from
|
|
24
|
+
* @param keys Keys of the data values to get
|
|
25
|
+
* @param parse Parse the values?
|
|
26
|
+
* @returns Keyed data values
|
|
27
|
+
*/
|
|
28
|
+
declare function getData<Key extends string>(element: Element, keys: Key[], parse: false): Record<Key, string | undefined>;
|
|
29
|
+
/**
|
|
30
|
+
* Get keyed data values from an element and parse the values
|
|
15
31
|
*
|
|
16
32
|
* @param element Element to get data from
|
|
17
33
|
* @param keys Keys of the data values to get
|
|
18
|
-
* @param parse Parse values? _(defaults to `true`)_
|
|
19
34
|
* @returns Keyed data values
|
|
20
35
|
*/
|
|
21
|
-
declare function getData<Key extends string>(element: Element, keys: Key[]
|
|
36
|
+
declare function getData<Key extends string>(element: Element, keys: Key[]): Record<Key, unknown>;
|
|
22
37
|
/**
|
|
23
38
|
* Set data values on an element
|
|
24
39
|
*
|
package/dist/event/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { CustomEventListener, RemovableEventListener } from "../models.mjs";
|
|
2
2
|
import { EventPosition } from "@oscarpalmer/atoms/models";
|
|
3
|
-
|
|
4
3
|
//#region src/event/index.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Dispatch an event for a target
|
|
@@ -9,7 +8,9 @@ import { EventPosition } from "@oscarpalmer/atoms/models";
|
|
|
9
8
|
* @param type Type of event
|
|
10
9
|
* @param options Options for event _(bubbles and is cancelable by default)_
|
|
11
10
|
*/
|
|
12
|
-
declare function dispatch<Type extends keyof HTMLElementEventMap>(target: EventTarget, type: Type, options?:
|
|
11
|
+
declare function dispatch<Type extends keyof HTMLElementEventMap, Options extends CustomEventInit>(target: EventTarget, type: Type, options?: Options): Options extends {
|
|
12
|
+
detail: infer Detail;
|
|
13
|
+
} ? CustomEvent<Detail> : Event;
|
|
13
14
|
/**
|
|
14
15
|
* Dispatch an event for a target
|
|
15
16
|
*
|
|
@@ -17,7 +18,9 @@ declare function dispatch<Type extends keyof HTMLElementEventMap>(target: EventT
|
|
|
17
18
|
* @param type Type of event
|
|
18
19
|
* @param options Options for event _(bubbles and is cancelable by default)_
|
|
19
20
|
*/
|
|
20
|
-
declare function dispatch(target: EventTarget, type: string, options?:
|
|
21
|
+
declare function dispatch<Options extends CustomEventInit>(target: EventTarget, type: string, options?: Options): Options extends {
|
|
22
|
+
detail: infer Detail;
|
|
23
|
+
} ? CustomEvent<Detail> : Event;
|
|
21
24
|
/**
|
|
22
25
|
* Get the X- and Y-coordinates from a pointer event
|
|
23
26
|
*
|
package/dist/event/index.mjs
CHANGED
|
@@ -28,7 +28,10 @@ function createEventOptions(options) {
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
function dispatch(target, type, options) {
|
|
31
|
-
if (isEventTarget(target)
|
|
31
|
+
if (!isEventTarget(target) || typeof type !== "string") return;
|
|
32
|
+
const event = createEvent(type, options);
|
|
33
|
+
target.dispatchEvent(event);
|
|
34
|
+
return event;
|
|
32
35
|
}
|
|
33
36
|
/**
|
|
34
37
|
* Get the X- and Y-coordinates from a pointer event
|
package/dist/find/index.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Selector } from "../models.mjs";
|
|
2
2
|
import { findAncestor, findRelatives, getDistance } from "./relative.mjs";
|
|
3
3
|
import { EventPosition } from "@oscarpalmer/atoms/models";
|
|
4
|
-
|
|
5
4
|
//#region src/find/index.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* Find the first element that matches the tag name
|
package/dist/index.d.mts
CHANGED
|
@@ -23,6 +23,14 @@ type SupporsTouch = {
|
|
|
23
23
|
declare const supportsTouch: SupporsTouch;
|
|
24
24
|
//#endregion
|
|
25
25
|
//#region src/models.d.ts
|
|
26
|
+
/**
|
|
27
|
+
* Any _ARIA_ attribute for an element _(both prefixed and unprefixed)_
|
|
28
|
+
*/
|
|
29
|
+
type AnyAriaAttribute = AriaAttribute | AriaAttributeUnprefixed;
|
|
30
|
+
/**
|
|
31
|
+
* Any _ARIA_ attribute for an element that can be set to a boolean value _(both prefixed and unprefixed)_
|
|
32
|
+
*/
|
|
33
|
+
type AnyAriaBooleanAttribute = AriaBooleanAttribute | AriaBooleanAttributeUnprefixed;
|
|
26
34
|
/**
|
|
27
35
|
* _ARIA_ attribute for an element
|
|
28
36
|
*
|
|
@@ -34,8 +42,16 @@ type AriaAttribute = keyof AriaAttributes;
|
|
|
34
42
|
*
|
|
35
43
|
* _(https://www.w3.org/TR/wai-aria-1.3/#aria-attributes)_
|
|
36
44
|
*/
|
|
37
|
-
type AriaAttributeUnprefixed = keyof { [Key in AriaAttribute as Key extends `aria-${infer Name}` ? Name : never]:
|
|
38
|
-
type AriaAttributes = { [Key in keyof ARIAMixin as NormalizedName<Key>]:
|
|
45
|
+
type AriaAttributeUnprefixed = keyof { [Key in AriaAttribute as Key extends `aria-${infer Name}` ? Name : never]: unknown; };
|
|
46
|
+
type AriaAttributes = { [Key in keyof ARIAMixin as NormalizedName<Key>]: unknown; };
|
|
47
|
+
/**
|
|
48
|
+
* _ARIA_ attribute for an element that can be set to a boolean value
|
|
49
|
+
*/
|
|
50
|
+
type AriaBooleanAttribute = 'aria-atomic' | 'aria-busy' | 'aria-checked' | 'aria-current' | 'aria-disabled' | 'aria-expanded' | 'aria-haspopup' | 'aria-hidden' | 'aria-invalid' | 'aria-modal' | 'aria-multiline' | 'aria-multiselectable' | 'aria-pressed' | 'aria-readonly' | 'aria-required' | 'aria-selected';
|
|
51
|
+
/**
|
|
52
|
+
* _ARIA_ attribute for an element that can be set to a boolean value, without the `aria-` prefix
|
|
53
|
+
*/
|
|
54
|
+
type AriaBooleanAttributeUnprefixed = keyof { [Key in AriaBooleanAttribute as Key extends `aria-${infer Name}` ? Name : never]: string | null; };
|
|
39
55
|
type NormalizedName<Key extends string> = Key extends `aria${infer Name}` ? Name extends `${infer Part}Element` ? `aria-${Lowercase<Part>}` : Name extends `${infer Part}Elements` ? `aria-${Lowercase<Part>}` : `aria-${Lowercase<Name>}` : never;
|
|
40
56
|
/**
|
|
41
57
|
* _ARIA_ role for an element
|
|
@@ -50,6 +66,18 @@ type Attribute = {
|
|
|
50
66
|
name: string;
|
|
51
67
|
value: unknown;
|
|
52
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* CSS styles for an element
|
|
71
|
+
*/
|
|
72
|
+
type CSSStyles = Record<keyof CSSStyleDeclaration, unknown>;
|
|
73
|
+
/**
|
|
74
|
+
* CSSS values for an element _(both styles and variables)_
|
|
75
|
+
*/
|
|
76
|
+
type CSSValues = CSSVariables & CSSStyles;
|
|
77
|
+
/**
|
|
78
|
+
* CSS variables for an element
|
|
79
|
+
*/
|
|
80
|
+
type CSSVariables<Value extends Record<string, unknown> = Record<string, unknown>> = { [Property in keyof Value as `--${string & Property}`]?: unknown; };
|
|
53
81
|
/**
|
|
54
82
|
* Event listener for custom events
|
|
55
83
|
*/
|
|
@@ -68,19 +96,26 @@ type Selector = string | Node | Node[] | NodeList;
|
|
|
68
96
|
type TextDirection = 'ltr' | 'rtl';
|
|
69
97
|
//#endregion
|
|
70
98
|
//#region src/aria.d.ts
|
|
71
|
-
type AnyAriaAttribute =
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
value?: string;
|
|
99
|
+
type AriaAttributeItem<Name extends AnyAriaAttribute = AnyAriaAttribute> = {
|
|
100
|
+
name: Name;
|
|
101
|
+
value?: Name extends AnyAriaBooleanAttribute ? boolean | string : string;
|
|
75
102
|
};
|
|
76
103
|
/**
|
|
77
104
|
* Get the value of a specific _ARIA_ attribute from an element
|
|
78
105
|
*
|
|
79
106
|
* @param element Element to get _ARIA_ attribute from
|
|
80
|
-
* @param name _ARIA_ name
|
|
107
|
+
* @param name _ARIA_ attribute name
|
|
108
|
+
* @returns _ARIA_ value _(or `undefined`)_
|
|
109
|
+
*/
|
|
110
|
+
declare function getAria(element: Element, name: AnyAriaBooleanAttribute): boolean | string | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* Get the value of a specific _ARIA_ attribute from an element
|
|
113
|
+
*
|
|
114
|
+
* @param element Element to get _ARIA_ attribute from
|
|
115
|
+
* @param name _ARIA_ attribute name
|
|
81
116
|
* @returns _ARIA_ value _(or `undefined`)_
|
|
82
117
|
*/
|
|
83
|
-
declare function getAria(element: Element,
|
|
118
|
+
declare function getAria(element: Element, name: AnyAriaAttribute): string | undefined;
|
|
84
119
|
/**
|
|
85
120
|
* Get specific _ARIA_ attributes from an element
|
|
86
121
|
*
|
|
@@ -88,7 +123,7 @@ declare function getAria(element: Element, attribute: AnyAriaAttribute): string
|
|
|
88
123
|
* @param names _ARIA_ attribute names
|
|
89
124
|
* @returns Object of named _ARIA_ attributes
|
|
90
125
|
*/
|
|
91
|
-
declare function getAria<Attribute extends AnyAriaAttribute>(element: Element,
|
|
126
|
+
declare function getAria<Attribute extends AnyAriaAttribute>(element: Element, names: Attribute[]): { [Key in Attribute as Key extends `aria-${infer Name}` ? Name : Key]: Key extends AnyAriaBooleanAttribute ? boolean | string | undefined : string | undefined; };
|
|
92
127
|
/**
|
|
93
128
|
* Get the role of an element
|
|
94
129
|
*
|
|
@@ -105,7 +140,17 @@ declare function getRole(element: Element): string | undefined;
|
|
|
105
140
|
* @param attribute _ARIA_ attribute to set
|
|
106
141
|
* @param value _ARIA_ attribute value
|
|
107
142
|
*/
|
|
108
|
-
declare function setAria(element: Element, attribute:
|
|
143
|
+
declare function setAria(element: Element, attribute: AnyAriaBooleanAttribute, value?: boolean | string): void;
|
|
144
|
+
/**
|
|
145
|
+
* Set an _ARIA_ attribute on an element
|
|
146
|
+
*
|
|
147
|
+
* _(Or remove it, if value is `null` or `undefined`)_
|
|
148
|
+
*
|
|
149
|
+
* @param element Element for _ARIA_ attribute
|
|
150
|
+
* @param attribute _ARIA_ attribute to set
|
|
151
|
+
* @param value _ARIA_ attribute value
|
|
152
|
+
*/
|
|
153
|
+
declare function setAria(element: Element, attribute: AnyAriaAttribute, value?: string): void;
|
|
109
154
|
/**
|
|
110
155
|
* Set one or more _ARIA_ attributes on an element
|
|
111
156
|
*
|
|
@@ -123,7 +168,7 @@ declare function setAria(element: Element, attributes: AriaAttributeItem[]): voi
|
|
|
123
168
|
* @param element Element for _ARIA_ attributes
|
|
124
169
|
* @param attributes _ARIA_ attributes to set
|
|
125
170
|
*/
|
|
126
|
-
declare function setAria(element: Element, attributes:
|
|
171
|
+
declare function setAria(element: Element, attributes: { [Key in AnyAriaAttribute]?: Key extends AnyAriaBooleanAttribute ? boolean | string : string; }): void;
|
|
127
172
|
/**
|
|
128
173
|
* Set the role of an element
|
|
129
174
|
*
|
|
@@ -131,6 +176,14 @@ declare function setAria(element: Element, attributes: Partial<Record<AnyAriaAtt
|
|
|
131
176
|
* @param role Role to set _(or `undefined` to remove it)_
|
|
132
177
|
*/
|
|
133
178
|
declare function setRole(element: Element, role?: AriaRole): void;
|
|
179
|
+
/**
|
|
180
|
+
* List of _ARIA_ attributes that can be treated as boolean values
|
|
181
|
+
*/
|
|
182
|
+
declare const ariaBooleanAttributes: readonly AnyAriaBooleanAttribute[];
|
|
183
|
+
/**
|
|
184
|
+
* Set of _ARIA_ attributes that can be treated as boolean values
|
|
185
|
+
*/
|
|
186
|
+
declare const ariaBooleanAttributesSet: Set<AnyAriaBooleanAttribute>;
|
|
134
187
|
//#endregion
|
|
135
188
|
//#region src/internal/attribute.d.ts
|
|
136
189
|
/**
|
|
@@ -290,48 +343,67 @@ type PlainObject = Record<PropertyKey, unknown>;
|
|
|
290
343
|
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
291
344
|
//#endregion
|
|
292
345
|
//#region src/create.d.ts
|
|
293
|
-
type
|
|
294
|
-
|
|
346
|
+
type CreateElementValues<Target extends Element> = {
|
|
347
|
+
aria?: CreateElementValuesAria;
|
|
348
|
+
attribute?: Record<string, unknown>;
|
|
349
|
+
data?: Record<string, unknown>;
|
|
350
|
+
property?: CreateElementValuesProperties<Target>;
|
|
351
|
+
style?: Partial<CSSValues>;
|
|
352
|
+
};
|
|
353
|
+
type CreateElementValuesAria = { [Key in AnyAriaAttribute]?: Key extends AnyAriaBooleanAttribute ? boolean | string : string; };
|
|
354
|
+
type CreateElementValuesProperties<Target extends Element> = { [Property in keyof Target]?: Target[Property] extends Primitive ? Target[Property] : never; };
|
|
295
355
|
/**
|
|
296
356
|
* Creates an _HTML_ element with the specified tag name together with optional properties, attributes, and styles
|
|
297
357
|
*
|
|
298
358
|
* @param tag Tag name
|
|
299
|
-
* @param
|
|
300
|
-
* @param attributes Element attributes
|
|
301
|
-
* @param styles Element styles
|
|
359
|
+
* @param values Element values
|
|
302
360
|
* @returns Created element
|
|
303
361
|
*/
|
|
304
|
-
declare function createElement<TagName extends keyof HTMLElementTagNameMap>(tag: TagName,
|
|
362
|
+
declare function createElement<TagName extends keyof HTMLElementTagNameMap>(tag: TagName, values?: CreateElementValues<HTMLElementTagNameMap[TagName]>): HTMLElementTagNameMap[TagName];
|
|
305
363
|
/**
|
|
306
364
|
* Creates an _HTML_ element with the specified tag name together with optional properties, attributes, and styles
|
|
307
365
|
*
|
|
308
366
|
* @param tag Tag name
|
|
309
|
-
* @param
|
|
310
|
-
* @param attributes Element attributes
|
|
311
|
-
* @param styles Element styles
|
|
367
|
+
* @param values Element values
|
|
312
368
|
* @returns Created element
|
|
313
369
|
*/
|
|
314
|
-
declare function createElement(tag: string,
|
|
370
|
+
declare function createElement(tag: string, values?: CreateElementValues<HTMLElement>): HTMLUnknownElement;
|
|
315
371
|
//#endregion
|
|
316
372
|
//#region src/data.d.ts
|
|
317
373
|
/**
|
|
318
|
-
* Get a keyed data value from an element
|
|
374
|
+
* Get a keyed data value from an element, without parsing the value
|
|
319
375
|
*
|
|
320
376
|
* @param element Element to get data from
|
|
321
377
|
* @param key Data key
|
|
322
|
-
* @param parse Parse
|
|
378
|
+
* @param parse Parse the value?
|
|
323
379
|
* @returns Data value
|
|
324
380
|
*/
|
|
325
|
-
declare function getData(element: Element, key: string, parse
|
|
381
|
+
declare function getData(element: Element, key: string, parse: false): string | undefined;
|
|
382
|
+
/**
|
|
383
|
+
* Get a keyed data value from an element and parse the value
|
|
384
|
+
*
|
|
385
|
+
* @param element Element to get data from
|
|
386
|
+
* @param key Data key
|
|
387
|
+
* @returns Data value
|
|
388
|
+
*/
|
|
389
|
+
declare function getData(element: Element, key: string): unknown;
|
|
390
|
+
/**
|
|
391
|
+
* Get keyed data values from an element, without parsing the values
|
|
392
|
+
*
|
|
393
|
+
* @param element Element to get data from
|
|
394
|
+
* @param keys Keys of the data values to get
|
|
395
|
+
* @param parse Parse the values?
|
|
396
|
+
* @returns Keyed data values
|
|
397
|
+
*/
|
|
398
|
+
declare function getData<Key extends string>(element: Element, keys: Key[], parse: false): Record<Key, string | undefined>;
|
|
326
399
|
/**
|
|
327
|
-
* Get keyed data values from an element
|
|
400
|
+
* Get keyed data values from an element and parse the values
|
|
328
401
|
*
|
|
329
402
|
* @param element Element to get data from
|
|
330
403
|
* @param keys Keys of the data values to get
|
|
331
|
-
* @param parse Parse values? _(defaults to `true`)_
|
|
332
404
|
* @returns Keyed data values
|
|
333
405
|
*/
|
|
334
|
-
declare function getData<Key extends string>(element: Element, keys: Key[]
|
|
406
|
+
declare function getData<Key extends string>(element: Element, keys: Key[]): Record<Key, unknown>;
|
|
335
407
|
/**
|
|
336
408
|
* Set data values on an element
|
|
337
409
|
*
|
|
@@ -356,7 +428,9 @@ declare function setData(element: Element, key: string, value: unknown): void;
|
|
|
356
428
|
* @param type Type of event
|
|
357
429
|
* @param options Options for event _(bubbles and is cancelable by default)_
|
|
358
430
|
*/
|
|
359
|
-
declare function dispatch<Type extends keyof HTMLElementEventMap>(target: EventTarget, type: Type, options?:
|
|
431
|
+
declare function dispatch<Type extends keyof HTMLElementEventMap, Options extends CustomEventInit>(target: EventTarget, type: Type, options?: Options): Options extends {
|
|
432
|
+
detail: infer Detail;
|
|
433
|
+
} ? CustomEvent<Detail> : Event;
|
|
360
434
|
/**
|
|
361
435
|
* Dispatch an event for a target
|
|
362
436
|
*
|
|
@@ -364,7 +438,9 @@ declare function dispatch<Type extends keyof HTMLElementEventMap>(target: EventT
|
|
|
364
438
|
* @param type Type of event
|
|
365
439
|
* @param options Options for event _(bubbles and is cancelable by default)_
|
|
366
440
|
*/
|
|
367
|
-
declare function dispatch(target: EventTarget, type: string, options?:
|
|
441
|
+
declare function dispatch<Options extends CustomEventInit>(target: EventTarget, type: string, options?: Options): Options extends {
|
|
442
|
+
detail: infer Detail;
|
|
443
|
+
} ? CustomEvent<Detail> : Event;
|
|
368
444
|
/**
|
|
369
445
|
* Get the X- and Y-coordinates from a pointer event
|
|
370
446
|
*
|
|
@@ -691,7 +767,6 @@ declare function setProperty<Target extends Element, Property extends Dispatched
|
|
|
691
767
|
declare function setProperty<Target extends Element, Property extends keyof SetProperties<Target>>(target: Target, property: Property, value: SetProperties<Target>[Property]): void;
|
|
692
768
|
//#endregion
|
|
693
769
|
//#region src/style.d.ts
|
|
694
|
-
type CSSStyleValues = Variables & CSSStyleDeclaration;
|
|
695
770
|
type StyleToggler = {
|
|
696
771
|
/**
|
|
697
772
|
* Set the provided styles on the element
|
|
@@ -702,26 +777,24 @@ type StyleToggler = {
|
|
|
702
777
|
*/
|
|
703
778
|
remove(): void;
|
|
704
779
|
};
|
|
705
|
-
type Styles = Partial<Record<keyof CSSStyleValues, unknown>>;
|
|
706
|
-
type Variables<Value extends Record<string, string | undefined> = Record<string, string | undefined>> = { [property in keyof Value as `--${string & property}`]?: string | undefined; };
|
|
707
780
|
/**
|
|
708
781
|
* Get a style from an element
|
|
709
782
|
*
|
|
710
783
|
* @param element Element to get the style from
|
|
711
|
-
* @param
|
|
784
|
+
* @param name Style name
|
|
712
785
|
* @param computed Get the computed style? _(defaults to `false`)_
|
|
713
786
|
* @returns Style value
|
|
714
787
|
*/
|
|
715
|
-
declare function getStyle(element: Element,
|
|
788
|
+
declare function getStyle(element: Element, name: keyof CSSValues, computed?: boolean): string | undefined;
|
|
716
789
|
/**
|
|
717
790
|
* Get styles from an element
|
|
718
791
|
*
|
|
719
792
|
* @param element Element to get the styles from
|
|
720
|
-
* @param
|
|
793
|
+
* @param names Styles to get
|
|
721
794
|
* @param computed Get the computed styles? _(defaults to `false`)_
|
|
722
795
|
* @returns Style values
|
|
723
796
|
*/
|
|
724
|
-
declare function getStyles<
|
|
797
|
+
declare function getStyles<Name extends keyof CSSValues>(element: Element, names: Name[], computed?: boolean): Record<Name, string | undefined>;
|
|
725
798
|
/**
|
|
726
799
|
* Get the text direction of a node or element _(or document, if element is invalid)_
|
|
727
800
|
*
|
|
@@ -739,17 +812,17 @@ declare function getTextDirection(): TextDirection;
|
|
|
739
812
|
* Set a style on an element
|
|
740
813
|
*
|
|
741
814
|
* @param element Element to set the style on
|
|
742
|
-
* @param
|
|
815
|
+
* @param name Style name
|
|
743
816
|
* @param value Style value
|
|
744
817
|
*/
|
|
745
|
-
declare function setStyle(element: Element,
|
|
818
|
+
declare function setStyle(element: Element, name: keyof CSSValues, value?: unknown): void;
|
|
746
819
|
/**
|
|
747
820
|
* Set styles on an element
|
|
748
821
|
*
|
|
749
822
|
* @param element Element to set the styles on
|
|
750
823
|
* @param styles Styles to set
|
|
751
824
|
*/
|
|
752
|
-
declare function setStyles(element: Element, styles:
|
|
825
|
+
declare function setStyles(element: Element, styles: Partial<CSSValues>): void;
|
|
753
826
|
/**
|
|
754
827
|
* Toggle styles for an element
|
|
755
828
|
*
|
|
@@ -757,6 +830,6 @@ declare function setStyles(element: Element, styles: Styles): void;
|
|
|
757
830
|
* @param styles Styles to be set or removed
|
|
758
831
|
* @returns Style toggler
|
|
759
832
|
*/
|
|
760
|
-
declare function toggleStyles(element: Element, styles:
|
|
833
|
+
declare function toggleStyles(element: Element, styles: Partial<CSSValues>): StyleToggler;
|
|
761
834
|
//#endregion
|
|
762
|
-
export { findElement as $, findElement, findElements as $$, findElements, AriaAttribute, AriaAttributeUnprefixed, AriaRole, Attribute, CustomEventListener, HtmlOptions, RemovableEventListener, Selector, StyleToggler, TextDirection, booleanAttributes, createElement, dispatch, findAncestor, findRelatives, getAria, getAttribute, getAttributes, getData, getDistance, getElementFromPosition, getElementUnderPointer, getFocusable, getPosition, getProperties, getProperty, getRole, getStyle, getStyles, getTabbable, getTextDirection, html, isBadAttribute, isBooleanAttribute, isChildNode, isEventPosition, isEventTarget, isFocusable, isHTMLOrSVGElement, isInDocument, isInputElement, isInvalidBooleanAttribute, isTabbable, off, on, sanitize, setAria, setAttribute, setAttributes, setData, setProperties, setProperty, setRole, setStyle, setStyles, supportsTouch, toggleStyles };
|
|
835
|
+
export { findElement as $, findElement, findElements as $$, findElements, AnyAriaAttribute, AnyAriaBooleanAttribute, AriaAttribute, AriaAttributeUnprefixed, AriaBooleanAttribute, AriaBooleanAttributeUnprefixed, AriaRole, Attribute, CSSStyles, CSSValues, CSSVariables, CustomEventListener, HtmlOptions, RemovableEventListener, Selector, StyleToggler, TextDirection, ariaBooleanAttributes, ariaBooleanAttributesSet, booleanAttributes, createElement, dispatch, findAncestor, findRelatives, getAria, getAttribute, getAttributes, getData, getDistance, getElementFromPosition, getElementUnderPointer, getFocusable, getPosition, getProperties, getProperty, getRole, getStyle, getStyles, getTabbable, getTextDirection, html, isBadAttribute, isBooleanAttribute, isChildNode, isEventPosition, isEventTarget, isFocusable, isHTMLOrSVGElement, isInDocument, isInputElement, isInvalidBooleanAttribute, isTabbable, off, on, sanitize, setAria, setAttribute, setAttributes, setData, setProperties, setProperty, setRole, setStyle, setStyles, supportsTouch, toggleStyles };
|