@oscarpalmer/toretto 0.48.0 → 0.49.1
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 -11
- package/dist/aria.mjs +35 -3
- package/dist/create.d.mts +14 -10
- package/dist/create.mjs +20 -4
- package/dist/data.d.mts +22 -6
- package/dist/data.mjs +9 -9
- package/dist/index.d.mts +108 -39
- package/dist/index.mjs +108 -59
- package/dist/internal/attribute.mjs +1 -1
- package/dist/internal/element-value.d.mts +1 -1
- package/dist/internal/element-value.mjs +6 -2
- package/dist/models.d.mts +31 -3
- package/dist/style.d.mts +9 -12
- package/dist/style.mjs +19 -19
- package/package.json +3 -3
- package/src/aria.ts +100 -26
- package/src/create.ts +45 -30
- package/src/data.ts +41 -21
- package/src/internal/attribute.ts +0 -1
- package/src/internal/element-value.ts +9 -2
- package/src/models.ts +57 -2
- package/src/style.ts +30 -41
package/dist/aria.d.mts
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyAriaAttribute, AnyAriaBooleanAttribute, AriaRole } from "./models.mjs";
|
|
2
2
|
//#region src/aria.d.ts
|
|
3
|
-
type AnyAriaAttribute =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
value?: string;
|
|
3
|
+
type AriaAttributeItem<Name extends AnyAriaAttribute = AnyAriaAttribute> = {
|
|
4
|
+
name: Name;
|
|
5
|
+
value?: Name extends AnyAriaBooleanAttribute ? boolean | string : string;
|
|
7
6
|
};
|
|
8
7
|
/**
|
|
9
8
|
* Get the value of a specific _ARIA_ attribute from an element
|
|
10
9
|
*
|
|
11
10
|
* @param element Element to get _ARIA_ attribute from
|
|
12
|
-
* @param name _ARIA_ name
|
|
11
|
+
* @param name _ARIA_ attribute name
|
|
13
12
|
* @returns _ARIA_ value _(or `undefined`)_
|
|
14
13
|
*/
|
|
15
|
-
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;
|
|
16
23
|
/**
|
|
17
24
|
* Get specific _ARIA_ attributes from an element
|
|
18
25
|
*
|
|
@@ -20,7 +27,7 @@ declare function getAria(element: Element, attribute: AnyAriaAttribute): string
|
|
|
20
27
|
* @param names _ARIA_ attribute names
|
|
21
28
|
* @returns Object of named _ARIA_ attributes
|
|
22
29
|
*/
|
|
23
|
-
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; };
|
|
24
31
|
/**
|
|
25
32
|
* Get the role of an element
|
|
26
33
|
*
|
|
@@ -37,7 +44,17 @@ declare function getRole(element: Element): string | undefined;
|
|
|
37
44
|
* @param attribute _ARIA_ attribute to set
|
|
38
45
|
* @param value _ARIA_ attribute value
|
|
39
46
|
*/
|
|
40
|
-
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;
|
|
41
58
|
/**
|
|
42
59
|
* Set one or more _ARIA_ attributes on an element
|
|
43
60
|
*
|
|
@@ -55,7 +72,7 @@ declare function setAria(element: Element, attributes: AriaAttributeItem[]): voi
|
|
|
55
72
|
* @param element Element for _ARIA_ attributes
|
|
56
73
|
* @param attributes _ARIA_ attributes to set
|
|
57
74
|
*/
|
|
58
|
-
declare function setAria(element: Element, attributes:
|
|
75
|
+
declare function setAria(element: Element, attributes: Record<string, unknown>): void;
|
|
59
76
|
/**
|
|
60
77
|
* Set the role of an element
|
|
61
78
|
*
|
|
@@ -63,5 +80,13 @@ declare function setAria(element: Element, attributes: Partial<Record<AnyAriaAtt
|
|
|
63
80
|
* @param role Role to set _(or `undefined` to remove it)_
|
|
64
81
|
*/
|
|
65
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>;
|
|
66
91
|
//#endregion
|
|
67
|
-
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);
|
|
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 };
|
package/dist/create.d.mts
CHANGED
|
@@ -1,26 +1,30 @@
|
|
|
1
|
+
import { AnyAriaAttribute, AnyAriaBooleanAttribute, CSSValues } from "./models.mjs";
|
|
1
2
|
import { Primitive } from "@oscarpalmer/atoms/models";
|
|
2
3
|
//#region src/create.d.ts
|
|
3
|
-
type
|
|
4
|
-
|
|
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; };
|
|
5
13
|
/**
|
|
6
14
|
* Creates an _HTML_ element with the specified tag name together with optional properties, attributes, and styles
|
|
7
15
|
*
|
|
8
16
|
* @param tag Tag name
|
|
9
|
-
* @param
|
|
10
|
-
* @param attributes Element attributes
|
|
11
|
-
* @param styles Element styles
|
|
17
|
+
* @param values Element values
|
|
12
18
|
* @returns Created element
|
|
13
19
|
*/
|
|
14
|
-
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];
|
|
15
21
|
/**
|
|
16
22
|
* Creates an _HTML_ element with the specified tag name together with optional properties, attributes, and styles
|
|
17
23
|
*
|
|
18
24
|
* @param tag Tag name
|
|
19
|
-
* @param
|
|
20
|
-
* @param attributes Element attributes
|
|
21
|
-
* @param styles Element styles
|
|
25
|
+
* @param values Element values
|
|
22
26
|
* @returns Created element
|
|
23
27
|
*/
|
|
24
|
-
declare function createElement(tag: string,
|
|
28
|
+
declare function createElement(tag: string, values?: CreateElementValues<HTMLElement>): HTMLUnknownElement;
|
|
25
29
|
//#endregion
|
|
26
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,23 +1,39 @@
|
|
|
1
1
|
import { PlainObject } from "@oscarpalmer/atoms/models";
|
|
2
2
|
//#region src/data.d.ts
|
|
3
3
|
/**
|
|
4
|
-
* Get a keyed data value from an element
|
|
4
|
+
* Get a keyed data value from an element, without parsing the value
|
|
5
5
|
*
|
|
6
6
|
* @param element Element to get data from
|
|
7
7
|
* @param key Data key
|
|
8
|
-
* @param parse Parse
|
|
8
|
+
* @param parse Parse the value?
|
|
9
9
|
* @returns Data value
|
|
10
10
|
*/
|
|
11
|
-
declare function getData(element: Element, key: string, parse
|
|
11
|
+
declare function getData(element: Element, key: string, parse: false): string | undefined;
|
|
12
12
|
/**
|
|
13
|
-
* 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
|
|
14
31
|
*
|
|
15
32
|
* @param element Element to get data from
|
|
16
33
|
* @param keys Keys of the data values to get
|
|
17
|
-
* @param parse Parse values? _(defaults to `true`)_
|
|
18
34
|
* @returns Keyed data values
|
|
19
35
|
*/
|
|
20
|
-
declare function getData<Key extends string>(element: Element, keys: Key[]
|
|
36
|
+
declare function getData<Key extends string>(element: Element, keys: Key[]): Record<Key, unknown>;
|
|
21
37
|
/**
|
|
22
38
|
* Set data values on an element
|
|
23
39
|
*
|
package/dist/data.mjs
CHANGED
|
@@ -6,21 +6,21 @@ import { camelCase, kebabCase } from "@oscarpalmer/atoms/string/case";
|
|
|
6
6
|
function getData(element, keys, parseValues) {
|
|
7
7
|
if (!(element instanceof Element)) return;
|
|
8
8
|
const noParse = parseValues === false;
|
|
9
|
-
if (typeof keys === "string")
|
|
10
|
-
const value = element.dataset[camelCase(keys)];
|
|
11
|
-
if (value === void 0) return;
|
|
12
|
-
return noParse ? value : parse(value);
|
|
13
|
-
}
|
|
9
|
+
if (typeof keys === "string") return getDataValue(element, keys, noParse);
|
|
14
10
|
const { length } = keys;
|
|
15
11
|
const data = {};
|
|
16
12
|
for (let index = 0; index < length; index += 1) {
|
|
17
13
|
const key = keys[index];
|
|
18
|
-
|
|
19
|
-
if (value == null) data[key] = void 0;
|
|
20
|
-
else data[key] = noParse ? value : parse(value);
|
|
14
|
+
data[key] = getDataValue(element, key, noParse);
|
|
21
15
|
}
|
|
22
16
|
return data;
|
|
23
17
|
}
|
|
18
|
+
function getDataValue(element, key, noParse) {
|
|
19
|
+
const value = element.dataset[camelCase(key)];
|
|
20
|
+
if (value == null) return;
|
|
21
|
+
if (noParse) return value;
|
|
22
|
+
return parse(value) ?? value;
|
|
23
|
+
}
|
|
24
24
|
function getName(original) {
|
|
25
25
|
return `${ATTRIBUTE_DATA_PREFIX}${kebabCase(original.replace(EXPRESSION_DATA_PREFIX, ""))}`;
|
|
26
26
|
}
|
|
@@ -28,7 +28,7 @@ function setData(element, first, second) {
|
|
|
28
28
|
setElementValues(element, first, second, null, updateDataAttribute);
|
|
29
29
|
}
|
|
30
30
|
function updateDataAttribute(element, key, value) {
|
|
31
|
-
updateElementValue(element, getName(key), value, element.setAttribute, element.removeAttribute,
|
|
31
|
+
updateElementValue(element, getName(key), value, element.setAttribute, element.removeAttribute, true);
|
|
32
32
|
}
|
|
33
33
|
const ATTRIBUTE_DATA_PREFIX = "data-";
|
|
34
34
|
//#endregion
|
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: Record<string, unknown>): 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
|
*
|
|
@@ -695,7 +767,6 @@ declare function setProperty<Target extends Element, Property extends Dispatched
|
|
|
695
767
|
declare function setProperty<Target extends Element, Property extends keyof SetProperties<Target>>(target: Target, property: Property, value: SetProperties<Target>[Property]): void;
|
|
696
768
|
//#endregion
|
|
697
769
|
//#region src/style.d.ts
|
|
698
|
-
type CSSStyleValues = Variables & CSSStyleDeclaration;
|
|
699
770
|
type StyleToggler = {
|
|
700
771
|
/**
|
|
701
772
|
* Set the provided styles on the element
|
|
@@ -706,26 +777,24 @@ type StyleToggler = {
|
|
|
706
777
|
*/
|
|
707
778
|
remove(): void;
|
|
708
779
|
};
|
|
709
|
-
type Styles = Partial<Record<keyof CSSStyleValues, unknown>>;
|
|
710
|
-
type Variables<Value extends Record<string, string | undefined> = Record<string, string | undefined>> = { [property in keyof Value as `--${string & property}`]?: string | undefined; };
|
|
711
780
|
/**
|
|
712
781
|
* Get a style from an element
|
|
713
782
|
*
|
|
714
783
|
* @param element Element to get the style from
|
|
715
|
-
* @param
|
|
784
|
+
* @param name Style name
|
|
716
785
|
* @param computed Get the computed style? _(defaults to `false`)_
|
|
717
786
|
* @returns Style value
|
|
718
787
|
*/
|
|
719
|
-
declare function getStyle(element: Element,
|
|
788
|
+
declare function getStyle(element: Element, name: keyof CSSValues, computed?: boolean): string | undefined;
|
|
720
789
|
/**
|
|
721
790
|
* Get styles from an element
|
|
722
791
|
*
|
|
723
792
|
* @param element Element to get the styles from
|
|
724
|
-
* @param
|
|
793
|
+
* @param names Styles to get
|
|
725
794
|
* @param computed Get the computed styles? _(defaults to `false`)_
|
|
726
795
|
* @returns Style values
|
|
727
796
|
*/
|
|
728
|
-
declare function getStyles<
|
|
797
|
+
declare function getStyles<Name extends keyof CSSValues>(element: Element, names: Name[], computed?: boolean): Record<Name, string | undefined>;
|
|
729
798
|
/**
|
|
730
799
|
* Get the text direction of a node or element _(or document, if element is invalid)_
|
|
731
800
|
*
|
|
@@ -743,17 +812,17 @@ declare function getTextDirection(): TextDirection;
|
|
|
743
812
|
* Set a style on an element
|
|
744
813
|
*
|
|
745
814
|
* @param element Element to set the style on
|
|
746
|
-
* @param
|
|
815
|
+
* @param name Style name
|
|
747
816
|
* @param value Style value
|
|
748
817
|
*/
|
|
749
|
-
declare function setStyle(element: Element,
|
|
818
|
+
declare function setStyle(element: Element, name: keyof CSSValues, value?: unknown): void;
|
|
750
819
|
/**
|
|
751
820
|
* Set styles on an element
|
|
752
821
|
*
|
|
753
822
|
* @param element Element to set the styles on
|
|
754
823
|
* @param styles Styles to set
|
|
755
824
|
*/
|
|
756
|
-
declare function setStyles(element: Element, styles:
|
|
825
|
+
declare function setStyles(element: Element, styles: Partial<CSSValues>): void;
|
|
757
826
|
/**
|
|
758
827
|
* Toggle styles for an element
|
|
759
828
|
*
|
|
@@ -761,6 +830,6 @@ declare function setStyles(element: Element, styles: Styles): void;
|
|
|
761
830
|
* @param styles Styles to be set or removed
|
|
762
831
|
* @returns Style toggler
|
|
763
832
|
*/
|
|
764
|
-
declare function toggleStyles(element: Element, styles:
|
|
833
|
+
declare function toggleStyles(element: Element, styles: Partial<CSSValues>): StyleToggler;
|
|
765
834
|
//#endregion
|
|
766
|
-
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 };
|