@oscarpalmer/toretto 0.46.0 → 0.47.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 +68 -0
- package/dist/aria.mjs +49 -0
- package/dist/attribute/get.attribute.d.mts +1 -0
- package/dist/attribute/get.attribute.mjs +2 -3
- package/dist/attribute/index.d.mts +1 -1
- package/dist/attribute/set.attribute.mjs +1 -1
- package/dist/create.d.mts +2 -2
- package/dist/create.mjs +1 -1
- package/dist/data.mjs +1 -2
- package/dist/event/delegation.mjs +3 -4
- package/dist/event/index.mjs +1 -2
- package/dist/html/index.d.mts +5 -4
- package/dist/html/index.mjs +3 -3
- package/dist/index.d.mts +99 -18
- package/dist/index.mjs +184 -139
- package/dist/internal/attribute.mjs +2 -2
- package/dist/internal/element-value.mjs +2 -4
- package/dist/internal/is.d.mts +2 -2
- package/dist/internal/is.mjs +2 -2
- package/dist/is.mjs +1 -1
- package/dist/models.d.mts +21 -1
- package/dist/property/get.property.mjs +2 -3
- package/dist/property/set.property.mjs +2 -4
- package/dist/style.mjs +3 -4
- package/package.json +8 -4
- package/src/aria.ts +166 -0
- package/src/attribute/get.attribute.ts +3 -3
- package/src/create.ts +3 -3
- package/src/data.ts +7 -6
- package/src/event/delegation.ts +5 -6
- package/src/event/index.ts +1 -7
- package/src/html/index.ts +7 -9
- package/src/index.ts +1 -0
- package/src/internal/attribute.ts +4 -2
- package/src/internal/element-value.ts +2 -3
- package/src/internal/is.ts +2 -2
- package/src/models.ts +122 -0
- package/src/property/get.property.ts +4 -5
- package/src/property/set.property.ts +2 -3
- package/src/style.ts +5 -6
package/dist/aria.d.mts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { AriaAttribute, AriaAttributeUnprefixed, AriaRole } from "./models.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/aria.d.ts
|
|
4
|
+
type AnyAriaAttribute = AriaAttribute | AriaAttributeUnprefixed;
|
|
5
|
+
type AriaAttributeItem = {
|
|
6
|
+
name: AnyAriaAttribute;
|
|
7
|
+
value?: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Get the value of a specific _ARIA_ attribute from an element
|
|
11
|
+
*
|
|
12
|
+
* @param element Element to get _ARIA_ attribute from
|
|
13
|
+
* @param name _ARIA_ name
|
|
14
|
+
* @returns _ARIA_ value _(or `undefined`)_
|
|
15
|
+
*/
|
|
16
|
+
declare function getAria(element: Element, attribute: AnyAriaAttribute): string | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Get specific _ARIA_ attributes from an element
|
|
19
|
+
*
|
|
20
|
+
* @param element Element to get _ARIA_ attributes from
|
|
21
|
+
* @param names _ARIA_ attribute names
|
|
22
|
+
* @returns Object of named _ARIA_ attributes
|
|
23
|
+
*/
|
|
24
|
+
declare function getAria<Attribute extends AnyAriaAttribute>(element: Element, attributes: Attribute[]): Record<Attribute, string | undefined>;
|
|
25
|
+
/**
|
|
26
|
+
* Get the role of an element
|
|
27
|
+
*
|
|
28
|
+
* @param element Element to get role from
|
|
29
|
+
* @returns Element role _(or `undefined`)_
|
|
30
|
+
*/
|
|
31
|
+
declare function getRole(element: Element): unknown;
|
|
32
|
+
/**
|
|
33
|
+
* Set an _ARIA_ attribute on an element
|
|
34
|
+
*
|
|
35
|
+
* _(Or remove it, if value is `null` or `undefined`)_
|
|
36
|
+
*
|
|
37
|
+
* @param element Element for _ARIA_ attribute
|
|
38
|
+
* @param attribute _ARIA_ attribute to set
|
|
39
|
+
* @param value _ARIA_ attribute value
|
|
40
|
+
*/
|
|
41
|
+
declare function setAria(element: Element, attribute: AnyAriaAttribute, value?: unknown): void;
|
|
42
|
+
/**
|
|
43
|
+
* Set one or more _ARIA_ attributes on an element
|
|
44
|
+
*
|
|
45
|
+
* _(Or remove them, if their value is `null` or `undefined`)_
|
|
46
|
+
*
|
|
47
|
+
* @param element Element for _ARIA_ attributes
|
|
48
|
+
* @param attributes _ARIA_ attributes to set
|
|
49
|
+
*/
|
|
50
|
+
declare function setAria(element: Element, attributes: AriaAttributeItem[]): void;
|
|
51
|
+
/**
|
|
52
|
+
* Set one or more _ARIA_ attributes on an element
|
|
53
|
+
*
|
|
54
|
+
* _(Or remove them, if their value is `null` or `undefined`)_
|
|
55
|
+
*
|
|
56
|
+
* @param element Element for _ARIA_ attributes
|
|
57
|
+
* @param attributes _ARIA_ attributes to set
|
|
58
|
+
*/
|
|
59
|
+
declare function setAria(element: Element, attributes: Partial<Record<AnyAriaAttribute, unknown>>): void;
|
|
60
|
+
/**
|
|
61
|
+
* Set the role of an element
|
|
62
|
+
*
|
|
63
|
+
* @param element Element for role
|
|
64
|
+
* @param role Role to set _(or `undefined` to remove it)_
|
|
65
|
+
*/
|
|
66
|
+
declare function setRole(element: Element, role?: AriaRole): void;
|
|
67
|
+
//#endregion
|
|
68
|
+
export { getAria, getRole, setAria, setRole };
|
package/dist/aria.mjs
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { setElementValues, updateElementValue } from "./internal/element-value.mjs";
|
|
2
|
+
//#region src/aria.ts
|
|
3
|
+
function getAria(element, value) {
|
|
4
|
+
if (!(element instanceof Element)) return Array.isArray(value) ? {} : void 0;
|
|
5
|
+
if (!Array.isArray(value)) return typeof value === "string" ? getAriaValue(element, value) : void 0;
|
|
6
|
+
const arias = {};
|
|
7
|
+
const { length } = value;
|
|
8
|
+
for (let index = 0; index < length; index += 1) {
|
|
9
|
+
const attribute = value[index];
|
|
10
|
+
if (typeof attribute === "string") arias[attribute.replace(ATTRIBUTE_ARIA_PREFIX, "")] = getAriaValue(element, attribute);
|
|
11
|
+
}
|
|
12
|
+
return arias;
|
|
13
|
+
}
|
|
14
|
+
function getAriaValue(element, attribute) {
|
|
15
|
+
return element.getAttribute(getName(attribute)) ?? void 0;
|
|
16
|
+
}
|
|
17
|
+
function getName(value) {
|
|
18
|
+
return EXPRESSION_ARIA_PREFIX.test(value) ? value : `${ATTRIBUTE_ARIA_PREFIX}${value}`;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Get the role of an element
|
|
22
|
+
*
|
|
23
|
+
* @param element Element to get role from
|
|
24
|
+
* @returns Element role _(or `undefined`)_
|
|
25
|
+
*/
|
|
26
|
+
function getRole(element) {
|
|
27
|
+
if (element instanceof Element) return element.getAttribute("role") ?? void 0;
|
|
28
|
+
}
|
|
29
|
+
function setAria(element, first, second) {
|
|
30
|
+
setElementValues(element, first, second, null, updateAriaAttribute);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Set the role of an element
|
|
34
|
+
*
|
|
35
|
+
* @param element Element for role
|
|
36
|
+
* @param role Role to set _(or `undefined` to remove it)_
|
|
37
|
+
*/
|
|
38
|
+
function setRole(element, role) {
|
|
39
|
+
if (!(element instanceof Element)) return;
|
|
40
|
+
if (typeof role === "string") element.setAttribute("role", role);
|
|
41
|
+
else element.removeAttribute("role");
|
|
42
|
+
}
|
|
43
|
+
function updateAriaAttribute(element, key, value) {
|
|
44
|
+
updateElementValue(element, getName(key), value, element.setAttribute, element.removeAttribute, false, false);
|
|
45
|
+
}
|
|
46
|
+
const ATTRIBUTE_ARIA_PREFIX = "aria-";
|
|
47
|
+
const EXPRESSION_ARIA_PREFIX = /^aria-/i;
|
|
48
|
+
//#endregion
|
|
49
|
+
export { getAria, getRole, setAria, setRole };
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { isHTMLOrSVGElement } from "../internal/is.mjs";
|
|
2
1
|
import { getAttributeValue } from "../internal/get-value.mjs";
|
|
3
2
|
import { kebabCase } from "@oscarpalmer/atoms/string/case";
|
|
4
3
|
//#region src/attribute/get.attribute.ts
|
|
5
4
|
function getAttribute(element, name, parseValues) {
|
|
6
|
-
if (
|
|
5
|
+
if (element instanceof Element && typeof name === "string") return getAttributeValue(element, kebabCase(name), parseValues !== false);
|
|
7
6
|
}
|
|
8
7
|
/**
|
|
9
8
|
* Get specific attributes from an element
|
|
@@ -15,7 +14,7 @@ function getAttribute(element, name, parseValues) {
|
|
|
15
14
|
*/
|
|
16
15
|
function getAttributes(element, names, parseData) {
|
|
17
16
|
const attributes = {};
|
|
18
|
-
if (!(
|
|
17
|
+
if (!(element instanceof Element && Array.isArray(names))) return attributes;
|
|
19
18
|
const shouldParse = parseData !== false;
|
|
20
19
|
const { length } = names;
|
|
21
20
|
for (let index = 0; index < length; index += 1) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getAttribute, getAttributes } from "./get.attribute.mjs";
|
|
2
1
|
import { Attribute } from "../models.mjs";
|
|
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
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { setElementValue, setElementValues } from "../internal/element-value.mjs";
|
|
2
1
|
import { updateAttribute } from "../internal/attribute.mjs";
|
|
2
|
+
import { setElementValue, setElementValues } from "../internal/element-value.mjs";
|
|
3
3
|
//#region src/attribute/set.attribute.ts
|
|
4
4
|
function setAttribute(element, first, second, third) {
|
|
5
5
|
setElementValue(element, first, second, third, updateAttribute);
|
package/dist/create.d.mts
CHANGED
|
@@ -4,7 +4,7 @@ import { Primitive } from "@oscarpalmer/atoms/models";
|
|
|
4
4
|
type Properties<Target extends Element> = { [Property in keyof Target]?: Target[Property] extends Primitive ? Target[Property] : never };
|
|
5
5
|
type Styles = Partial<Record<keyof CSSStyleDeclaration, unknown>>;
|
|
6
6
|
/**
|
|
7
|
-
* Creates an
|
|
7
|
+
* Creates an _HTML_ element with the specified tag name together with optional properties, attributes, and styles
|
|
8
8
|
*
|
|
9
9
|
* @param tag Tag name
|
|
10
10
|
* @param properties Element properties
|
|
@@ -14,7 +14,7 @@ type Styles = Partial<Record<keyof CSSStyleDeclaration, unknown>>;
|
|
|
14
14
|
*/
|
|
15
15
|
declare function createElement<TagName extends keyof HTMLElementTagNameMap>(tag: TagName, properties?: Properties<HTMLElementTagNameMap[TagName]>, attributes?: Record<string, unknown>, styles?: Styles): HTMLElementTagNameMap[TagName];
|
|
16
16
|
/**
|
|
17
|
-
* Creates an
|
|
17
|
+
* Creates an _HTML_ element with the specified tag name together with optional properties, attributes, and styles
|
|
18
18
|
*
|
|
19
19
|
* @param tag Tag name
|
|
20
20
|
* @param properties Element properties
|
package/dist/create.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { setAttributes } from "./attribute/set.attribute.mjs";
|
|
2
2
|
import "./attribute/index.mjs";
|
|
3
|
-
import { setStyles } from "./style.mjs";
|
|
4
3
|
import { setProperties } from "./property/set.property.mjs";
|
|
5
4
|
import "./property/index.mjs";
|
|
5
|
+
import { setStyles } from "./style.mjs";
|
|
6
6
|
//#region src/create.ts
|
|
7
7
|
function createElement(tag, properties, attributes, styles) {
|
|
8
8
|
if (typeof tag !== "string") throw new TypeError(MESSAGE);
|
package/dist/data.mjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { isHTMLOrSVGElement } from "./internal/is.mjs";
|
|
2
1
|
import { setElementValues, updateElementValue } from "./internal/element-value.mjs";
|
|
3
2
|
import { EXPRESSION_DATA_PREFIX } from "./internal/get-value.mjs";
|
|
4
3
|
import { parse } from "@oscarpalmer/atoms/string";
|
|
5
4
|
import { camelCase, kebabCase } from "@oscarpalmer/atoms/string/case";
|
|
6
5
|
//#region src/data.ts
|
|
7
6
|
function getData(element, keys, parseValues) {
|
|
8
|
-
if (!
|
|
7
|
+
if (!(element instanceof Element)) return;
|
|
9
8
|
const noParse = parseValues === false;
|
|
10
9
|
if (typeof keys === "string") {
|
|
11
10
|
const value = element.dataset[camelCase(keys)];
|
|
@@ -14,7 +14,7 @@ function addDelegatedListener(target, type, name, listener, passive) {
|
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
function delegatedEventHandler(event) {
|
|
17
|
-
const key =
|
|
17
|
+
const key = `@${event.type}${this ? EVENT_SUFFIX_PASSIVE : EVENT_SUFFIX_ACTIVE}`;
|
|
18
18
|
const items = event.composedPath();
|
|
19
19
|
const { length } = items;
|
|
20
20
|
let cancelled = false;
|
|
@@ -49,7 +49,7 @@ function delegatedEventHandler(event) {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
function getDelegatedName(target, type, options) {
|
|
52
|
-
if (isEventTarget(target) && EVENT_TYPES.has(type) && !options.capture && !options.once && options.signal == null) return
|
|
52
|
+
if (isEventTarget(target) && EVENT_TYPES.has(type) && !options.capture && !options.once && options.signal == null) return `@${type}${options.passive ? EVENT_SUFFIX_PASSIVE : EVENT_SUFFIX_ACTIVE}`;
|
|
53
53
|
}
|
|
54
54
|
function removeDelegatedListener(target, name, listener) {
|
|
55
55
|
const handlers = target[name];
|
|
@@ -59,10 +59,9 @@ function removeDelegatedListener(target, name, listener) {
|
|
|
59
59
|
return true;
|
|
60
60
|
}
|
|
61
61
|
const DELEGATED = /* @__PURE__ */ new Set();
|
|
62
|
-
const EVENT_PREFIX = "@";
|
|
63
62
|
const EVENT_SUFFIX_ACTIVE = ":active";
|
|
64
63
|
const EVENT_SUFFIX_PASSIVE = ":passive";
|
|
65
|
-
const EVENT_TYPES = new Set([
|
|
64
|
+
const EVENT_TYPES = /* @__PURE__ */ new Set([
|
|
66
65
|
"beforeinput",
|
|
67
66
|
"click",
|
|
68
67
|
"dblclick",
|
package/dist/event/index.mjs
CHANGED
|
@@ -13,7 +13,7 @@ function createDispatchOptions(options) {
|
|
|
13
13
|
}
|
|
14
14
|
function createEvent(type, options) {
|
|
15
15
|
const hasOptions = isPlainObject(options);
|
|
16
|
-
if (hasOptions &&
|
|
16
|
+
if (hasOptions && "detail" in options) return new CustomEvent(type, {
|
|
17
17
|
...createDispatchOptions(options),
|
|
18
18
|
detail: options?.detail
|
|
19
19
|
});
|
|
@@ -76,6 +76,5 @@ function on(target, type, listener, options) {
|
|
|
76
76
|
target.removeEventListener(type, listener, extended);
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
|
-
const PROPERTY_DETAIL = "detail";
|
|
80
79
|
//#endregion
|
|
81
80
|
export { dispatch, getPosition, off, on };
|
package/dist/html/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//#region src/html/index.d.ts
|
|
2
2
|
type HtmlOptions = {
|
|
3
3
|
/**
|
|
4
|
-
* Cache template element for the
|
|
4
|
+
* Cache template element for the _HTML_ string? _(defaults to `true`)_
|
|
5
5
|
*/
|
|
6
6
|
cache?: boolean;
|
|
7
7
|
};
|
|
@@ -12,9 +12,9 @@ type HtmlOptions = {
|
|
|
12
12
|
*/
|
|
13
13
|
declare function html(strings: TemplateStringsArray, ...values: unknown[]): Node[];
|
|
14
14
|
/**
|
|
15
|
-
* Create nodes from an
|
|
15
|
+
* Create nodes from an _HTML_ string or a template element
|
|
16
16
|
*
|
|
17
|
-
* @param value
|
|
17
|
+
* @param value _HTML_ string or ID for a template element
|
|
18
18
|
* @param options Options for creating nodes
|
|
19
19
|
* @returns Created nodes
|
|
20
20
|
*/
|
|
@@ -33,10 +33,11 @@ declare namespace html {
|
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
35
|
* Sanitize one or more nodes, recursively
|
|
36
|
+
*
|
|
36
37
|
* @param value Node or nodes to sanitize
|
|
37
38
|
* @param options Sanitization options
|
|
38
39
|
* @returns Sanitized nodes
|
|
39
40
|
*/
|
|
40
41
|
declare function sanitize(value: Node | Node[]): Node[];
|
|
41
42
|
//#endregion
|
|
42
|
-
export { html, sanitize };
|
|
43
|
+
export { HtmlOptions, html, sanitize };
|
package/dist/html/index.mjs
CHANGED
|
@@ -96,9 +96,9 @@ html.clear = () => {
|
|
|
96
96
|
templates.clear();
|
|
97
97
|
};
|
|
98
98
|
/**
|
|
99
|
-
* Remove cached template element for an
|
|
99
|
+
* Remove cached template element for an _HTML_ string or _ID_
|
|
100
100
|
*
|
|
101
|
-
* @param template
|
|
101
|
+
* @param template _HTML_ string or ID for a template element
|
|
102
102
|
*/
|
|
103
103
|
html.remove = (template) => {
|
|
104
104
|
templates.delete(template);
|
|
@@ -121,6 +121,7 @@ function replaceComments(origin, replacements) {
|
|
|
121
121
|
}
|
|
122
122
|
/**
|
|
123
123
|
* Sanitize one or more nodes, recursively
|
|
124
|
+
*
|
|
124
125
|
* @param value Node or nodes to sanitize
|
|
125
126
|
* @param options Sanitization options
|
|
126
127
|
* @returns Sanitized nodes
|
|
@@ -137,6 +138,5 @@ const TEMPLATE_TAG = "template";
|
|
|
137
138
|
const TEMPORARY_ELEMENT = "<toretto-temporary></toretto-temporary>";
|
|
138
139
|
const templates = new SizedMap(128);
|
|
139
140
|
let parser;
|
|
140
|
-
window.templates = templates;
|
|
141
141
|
//#endregion
|
|
142
142
|
export { html, sanitize };
|
package/dist/index.d.mts
CHANGED
|
@@ -23,6 +23,26 @@ type SupporsTouch = {
|
|
|
23
23
|
declare const supportsTouch: SupporsTouch;
|
|
24
24
|
//#endregion
|
|
25
25
|
//#region src/models.d.ts
|
|
26
|
+
/**
|
|
27
|
+
* _ARIA_ attribute for an element
|
|
28
|
+
*
|
|
29
|
+
* _(https://www.w3.org/TR/wai-aria-1.3/#aria-attributes)_
|
|
30
|
+
*/
|
|
31
|
+
type AriaAttribute = keyof AriaAttributes;
|
|
32
|
+
/**
|
|
33
|
+
* _ARIA_ attribute for an element without the `aria-` prefix
|
|
34
|
+
*
|
|
35
|
+
* _(https://www.w3.org/TR/wai-aria-1.3/#aria-attributes)_
|
|
36
|
+
*/
|
|
37
|
+
type AriaAttributeUnprefixed = keyof { [Key in AriaAttribute as Key extends `aria-${infer Name}` ? Name : never]: string | null; };
|
|
38
|
+
type AriaAttributes = { [Key in keyof ARIAMixin as NormalizedName<Key>]: string | null; };
|
|
39
|
+
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
|
+
/**
|
|
41
|
+
* _ARIA_ role for an element
|
|
42
|
+
*
|
|
43
|
+
* _(https://www.w3.org/TR/wai-aria-1.3/#role_definitions)_
|
|
44
|
+
*/
|
|
45
|
+
type AriaRole = 'alert' | 'alertdialog' | 'application' | 'article' | 'banner' | 'blockquote' | 'button' | 'caption' | 'cell' | 'checkbox' | 'code' | 'columnheader' | 'combobox' | 'comment' | 'complementary' | 'contentinfo' | 'definition' | 'deletion' | 'dialog' | 'directory' | 'document' | 'emphasis' | 'feed' | 'figure' | 'form' | 'generic' | 'grid' | 'gridcell' | 'group' | 'heading' | 'img' | 'insertion' | 'link' | 'list' | 'listbox' | 'listitem' | 'log' | 'main' | 'mark' | 'marquee' | 'math' | 'menu' | 'menubar' | 'menuitem' | 'menuitemcheckbox' | 'menuitemradio' | 'meter' | 'navigation' | 'none' | 'note' | 'option' | 'paragraph' | 'presentation' | 'progressbar' | 'radio' | 'radiogroup' | 'region' | 'row' | 'rowgroup' | 'rowheader' | 'scrollbar' | 'search' | 'searchbox' | 'sectionfooter' | 'sectionheader' | 'separator' | 'slider' | 'spinbutton' | 'status' | 'strong' | 'subscript' | 'suggestion' | 'superscript' | 'switch' | 'tab' | 'table' | 'tablist' | 'tabpanel' | 'term' | 'textbox' | 'time' | 'timer' | 'toolbar' | 'tooltip' | 'tree' | 'treegrid' | 'treeitem';
|
|
26
46
|
/**
|
|
27
47
|
* Attribute for an element
|
|
28
48
|
*/
|
|
@@ -47,6 +67,71 @@ type Selector = string | Node | Node[] | NodeList;
|
|
|
47
67
|
*/
|
|
48
68
|
type TextDirection = 'ltr' | 'rtl';
|
|
49
69
|
//#endregion
|
|
70
|
+
//#region src/aria.d.ts
|
|
71
|
+
type AnyAriaAttribute = AriaAttribute | AriaAttributeUnprefixed;
|
|
72
|
+
type AriaAttributeItem = {
|
|
73
|
+
name: AnyAriaAttribute;
|
|
74
|
+
value?: string;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Get the value of a specific _ARIA_ attribute from an element
|
|
78
|
+
*
|
|
79
|
+
* @param element Element to get _ARIA_ attribute from
|
|
80
|
+
* @param name _ARIA_ name
|
|
81
|
+
* @returns _ARIA_ value _(or `undefined`)_
|
|
82
|
+
*/
|
|
83
|
+
declare function getAria(element: Element, attribute: AnyAriaAttribute): string | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Get specific _ARIA_ attributes from an element
|
|
86
|
+
*
|
|
87
|
+
* @param element Element to get _ARIA_ attributes from
|
|
88
|
+
* @param names _ARIA_ attribute names
|
|
89
|
+
* @returns Object of named _ARIA_ attributes
|
|
90
|
+
*/
|
|
91
|
+
declare function getAria<Attribute extends AnyAriaAttribute>(element: Element, attributes: Attribute[]): Record<Attribute, string | undefined>;
|
|
92
|
+
/**
|
|
93
|
+
* Get the role of an element
|
|
94
|
+
*
|
|
95
|
+
* @param element Element to get role from
|
|
96
|
+
* @returns Element role _(or `undefined`)_
|
|
97
|
+
*/
|
|
98
|
+
declare function getRole(element: Element): unknown;
|
|
99
|
+
/**
|
|
100
|
+
* Set an _ARIA_ attribute on an element
|
|
101
|
+
*
|
|
102
|
+
* _(Or remove it, if value is `null` or `undefined`)_
|
|
103
|
+
*
|
|
104
|
+
* @param element Element for _ARIA_ attribute
|
|
105
|
+
* @param attribute _ARIA_ attribute to set
|
|
106
|
+
* @param value _ARIA_ attribute value
|
|
107
|
+
*/
|
|
108
|
+
declare function setAria(element: Element, attribute: AnyAriaAttribute, value?: unknown): void;
|
|
109
|
+
/**
|
|
110
|
+
* Set one or more _ARIA_ attributes on an element
|
|
111
|
+
*
|
|
112
|
+
* _(Or remove them, if their value is `null` or `undefined`)_
|
|
113
|
+
*
|
|
114
|
+
* @param element Element for _ARIA_ attributes
|
|
115
|
+
* @param attributes _ARIA_ attributes to set
|
|
116
|
+
*/
|
|
117
|
+
declare function setAria(element: Element, attributes: AriaAttributeItem[]): void;
|
|
118
|
+
/**
|
|
119
|
+
* Set one or more _ARIA_ attributes on an element
|
|
120
|
+
*
|
|
121
|
+
* _(Or remove them, if their value is `null` or `undefined`)_
|
|
122
|
+
*
|
|
123
|
+
* @param element Element for _ARIA_ attributes
|
|
124
|
+
* @param attributes _ARIA_ attributes to set
|
|
125
|
+
*/
|
|
126
|
+
declare function setAria(element: Element, attributes: Partial<Record<AnyAriaAttribute, unknown>>): void;
|
|
127
|
+
/**
|
|
128
|
+
* Set the role of an element
|
|
129
|
+
*
|
|
130
|
+
* @param element Element for role
|
|
131
|
+
* @param role Role to set _(or `undefined` to remove it)_
|
|
132
|
+
*/
|
|
133
|
+
declare function setRole(element: Element, role?: AriaRole): void;
|
|
134
|
+
//#endregion
|
|
50
135
|
//#region src/internal/attribute.d.ts
|
|
51
136
|
/**
|
|
52
137
|
* List of boolean attributes
|
|
@@ -57,6 +142,7 @@ declare const booleanAttributes: readonly string[];
|
|
|
57
142
|
type DataPrefixedName = `data-${string}`;
|
|
58
143
|
/**
|
|
59
144
|
* Get the value of a specific attribute from an element
|
|
145
|
+
*
|
|
60
146
|
* @param element Element to get attribute from
|
|
61
147
|
* @param name Attribute name
|
|
62
148
|
* @param parse Parse value? _(defaults to `true`)_
|
|
@@ -193,9 +279,6 @@ type EventPosition = {
|
|
|
193
279
|
x: number;
|
|
194
280
|
y: number;
|
|
195
281
|
};
|
|
196
|
-
/**
|
|
197
|
-
* A generic async callback function
|
|
198
|
-
*/
|
|
199
282
|
/**
|
|
200
283
|
* A generic object
|
|
201
284
|
*/
|
|
@@ -206,15 +289,12 @@ type PlainObject = Record<PropertyKey, unknown>;
|
|
|
206
289
|
* _(Thanks, type-fest!)_
|
|
207
290
|
*/
|
|
208
291
|
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
209
|
-
/**
|
|
210
|
-
* Set required keys for a type
|
|
211
|
-
*/
|
|
212
292
|
//#endregion
|
|
213
293
|
//#region src/create.d.ts
|
|
214
|
-
type Properties<Target extends Element> = { [Property in keyof Target]?: Target[Property] extends Primitive ? Target[Property] : never };
|
|
294
|
+
type Properties<Target extends Element> = { [Property in keyof Target]?: Target[Property] extends Primitive ? Target[Property] : never; };
|
|
215
295
|
type Styles$1 = Partial<Record<keyof CSSStyleDeclaration, unknown>>;
|
|
216
296
|
/**
|
|
217
|
-
* Creates an
|
|
297
|
+
* Creates an _HTML_ element with the specified tag name together with optional properties, attributes, and styles
|
|
218
298
|
*
|
|
219
299
|
* @param tag Tag name
|
|
220
300
|
* @param properties Element properties
|
|
@@ -224,7 +304,7 @@ type Styles$1 = Partial<Record<keyof CSSStyleDeclaration, unknown>>;
|
|
|
224
304
|
*/
|
|
225
305
|
declare function createElement<TagName extends keyof HTMLElementTagNameMap>(tag: TagName, properties?: Properties<HTMLElementTagNameMap[TagName]>, attributes?: Record<string, unknown>, styles?: Styles$1): HTMLElementTagNameMap[TagName];
|
|
226
306
|
/**
|
|
227
|
-
* Creates an
|
|
307
|
+
* Creates an _HTML_ element with the specified tag name together with optional properties, attributes, and styles
|
|
228
308
|
*
|
|
229
309
|
* @param tag Tag name
|
|
230
310
|
* @param properties Element properties
|
|
@@ -468,7 +548,7 @@ declare function isTabbable(element: Element): boolean;
|
|
|
468
548
|
//#region src/html/index.d.ts
|
|
469
549
|
type HtmlOptions = {
|
|
470
550
|
/**
|
|
471
|
-
* Cache template element for the
|
|
551
|
+
* Cache template element for the _HTML_ string? _(defaults to `true`)_
|
|
472
552
|
*/
|
|
473
553
|
cache?: boolean;
|
|
474
554
|
};
|
|
@@ -479,9 +559,9 @@ type HtmlOptions = {
|
|
|
479
559
|
*/
|
|
480
560
|
declare function html(strings: TemplateStringsArray, ...values: unknown[]): Node[];
|
|
481
561
|
/**
|
|
482
|
-
* Create nodes from an
|
|
562
|
+
* Create nodes from an _HTML_ string or a template element
|
|
483
563
|
*
|
|
484
|
-
* @param value
|
|
564
|
+
* @param value _HTML_ string or ID for a template element
|
|
485
565
|
* @param options Options for creating nodes
|
|
486
566
|
* @returns Created nodes
|
|
487
567
|
*/
|
|
@@ -500,6 +580,7 @@ declare namespace html {
|
|
|
500
580
|
}
|
|
501
581
|
/**
|
|
502
582
|
* Sanitize one or more nodes, recursively
|
|
583
|
+
*
|
|
503
584
|
* @param value Node or nodes to sanitize
|
|
504
585
|
* @param options Sanitization options
|
|
505
586
|
* @returns Sanitized nodes
|
|
@@ -522,10 +603,10 @@ declare function isEventPosition(value: unknown): value is EventPosition;
|
|
|
522
603
|
*/
|
|
523
604
|
declare function isEventTarget(value: unknown): value is EventTarget;
|
|
524
605
|
/**
|
|
525
|
-
* Is the value an
|
|
606
|
+
* Is the value an _HTML_ or _SVG_ element?
|
|
526
607
|
*
|
|
527
608
|
* @param value Value to check
|
|
528
|
-
* @returns `true` if it's an
|
|
609
|
+
* @returns `true` if it's an _HTML_ or _SVG_ element, otherwise `false`
|
|
529
610
|
*/
|
|
530
611
|
declare function isHTMLOrSVGElement(value: unknown): value is HTMLElement | SVGElement;
|
|
531
612
|
/**
|
|
@@ -561,7 +642,7 @@ declare function isInDocument(node: Node): boolean;
|
|
|
561
642
|
declare function isInDocument(node: Node, document: Document): boolean;
|
|
562
643
|
//#endregion
|
|
563
644
|
//#region src/property/get.property.d.ts
|
|
564
|
-
type GetProperties<Target extends Element> = { [Property in keyof Target as Target[Property] extends Primitive ? Property : never]?: Target[Property] };
|
|
645
|
+
type GetProperties<Target extends Element> = { [Property in keyof Target as Target[Property] extends Primitive ? Property : never]?: Target[Property]; };
|
|
565
646
|
/**
|
|
566
647
|
* Get the values of one or more properties on an element
|
|
567
648
|
*
|
|
@@ -581,7 +662,7 @@ declare function getProperty<Target extends Element, Property extends keyof GetP
|
|
|
581
662
|
//#endregion
|
|
582
663
|
//#region src/property/set.property.d.ts
|
|
583
664
|
type DispatchedPropertyValue<Target extends Element, Property extends DispatchedAttributeName> = Property extends keyof SetProperties<Target> ? SetProperties<Target>[Property] : never;
|
|
584
|
-
type SetProperties<Target extends Element> = { [Property in keyof Target as Target[Property] extends Primitive ? Property : never]?: Target[Property] };
|
|
665
|
+
type SetProperties<Target extends Element> = { [Property in keyof Target as Target[Property] extends Primitive ? Property : never]?: Target[Property]; };
|
|
585
666
|
/**
|
|
586
667
|
* Set the values of one or more properties on an element
|
|
587
668
|
*
|
|
@@ -623,7 +704,7 @@ type StyleToggler = {
|
|
|
623
704
|
remove(): void;
|
|
624
705
|
};
|
|
625
706
|
type Styles = Partial<Record<keyof CSSStyleValues, unknown>>;
|
|
626
|
-
type Variables<Value extends Record<string, string | undefined> = Record<string, string | undefined>> = { [property in keyof Value as `--${string & property}`]?: string | undefined };
|
|
707
|
+
type Variables<Value extends Record<string, string | undefined> = Record<string, string | undefined>> = { [property in keyof Value as `--${string & property}`]?: string | undefined; };
|
|
627
708
|
/**
|
|
628
709
|
* Get a style from an element
|
|
629
710
|
*
|
|
@@ -679,4 +760,4 @@ declare function setStyles(element: Element, styles: Styles): void;
|
|
|
679
760
|
*/
|
|
680
761
|
declare function toggleStyles(element: Element, styles: Styles): StyleToggler;
|
|
681
762
|
//#endregion
|
|
682
|
-
export { findElement as $, findElement, findElements as $$, findElements, Attribute, CustomEventListener, RemovableEventListener, Selector, StyleToggler, TextDirection, booleanAttributes, createElement, dispatch, findAncestor, findRelatives, getAttribute, getAttributes, getData, getDistance, getElementFromPosition, getElementUnderPointer, getFocusable, getPosition, getProperties, getProperty, getStyle, getStyles, getTabbable, getTextDirection, html, isBadAttribute, isBooleanAttribute, isChildNode, isEventPosition, isEventTarget, isFocusable, isHTMLOrSVGElement, isInDocument, isInputElement, isInvalidBooleanAttribute, isTabbable, off, on, sanitize, setAttribute, setAttributes, setData, setProperties, setProperty, setStyle, setStyles, supportsTouch, toggleStyles };
|
|
763
|
+
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 };
|