@oscarpalmer/toretto 0.45.0 → 0.47.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 +68 -0
- package/dist/aria.mjs +49 -0
- package/dist/attribute/get.attribute.d.mts +3 -0
- package/dist/attribute/get.attribute.mjs +3 -3
- package/dist/attribute/index.d.mts +7 -1
- package/dist/attribute/set.attribute.d.mts +5 -0
- package/dist/attribute/set.attribute.mjs +1 -1
- package/dist/create.d.mts +4 -2
- package/dist/create.mjs +1 -1
- package/dist/data.d.mts +4 -0
- package/dist/data.mjs +1 -2
- package/dist/event/delegation.mjs +3 -4
- package/dist/event/index.d.mts +9 -1
- package/dist/event/index.mjs +3 -2
- package/dist/find/index.d.mts +14 -1
- package/dist/find/index.mjs +36 -1
- package/dist/find/relative.d.mts +5 -0
- package/dist/find/relative.mjs +1 -0
- package/dist/focusable.d.mts +4 -0
- package/dist/focusable.mjs +4 -0
- package/dist/html/index.d.mts +8 -4
- package/dist/html/index.mjs +4 -3
- package/dist/index.d.mts +185 -22
- package/dist/index.mjs +295 -144
- package/dist/internal/attribute.mjs +2 -2
- package/dist/internal/element-value.mjs +2 -4
- package/dist/internal/is.d.mts +15 -3
- package/dist/internal/is.mjs +15 -3
- package/dist/is.d.mts +5 -2
- package/dist/is.mjs +4 -3
- package/dist/models.d.mts +21 -8
- package/dist/property/get.property.d.mts +2 -0
- package/dist/property/get.property.mjs +4 -3
- package/dist/property/set.property.d.mts +3 -0
- package/dist/property/set.property.mjs +3 -4
- package/dist/style.d.mts +7 -0
- package/dist/style.mjs +8 -4
- package/dist/touch.d.mts +4 -0
- package/package.json +10 -6
- package/src/aria.ts +166 -0
- package/src/attribute/get.attribute.ts +5 -3
- package/src/attribute/index.ts +6 -0
- package/src/attribute/set.attribute.ts +5 -0
- package/src/create.ts +5 -3
- package/src/data.ts +11 -6
- package/src/event/delegation.ts +5 -6
- package/src/event/index.ts +11 -8
- package/src/find/index.ts +64 -1
- package/src/find/relative.ts +5 -0
- package/src/focusable.ts +4 -0
- package/src/html/index.ts +11 -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 +22 -2
- package/src/is.ts +4 -1
- package/src/models.ts +122 -8
- package/src/property/get.property.ts +6 -5
- package/src/property/set.property.ts +5 -3
- package/src/style.ts +12 -6
- package/src/touch.ts +4 -0
package/src/internal/is.ts
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
|
+
import type {EventPosition} from '@oscarpalmer/atoms/models';
|
|
2
|
+
|
|
1
3
|
// #region Functions
|
|
2
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Is the value an event position?
|
|
7
|
+
*
|
|
8
|
+
* @param value Value to check
|
|
9
|
+
* @returns `true` if it's an event position, otherwise `false`
|
|
10
|
+
*/
|
|
11
|
+
export function isEventPosition(value: unknown): value is EventPosition {
|
|
12
|
+
return (
|
|
13
|
+
typeof value === 'object' &&
|
|
14
|
+
value != null &&
|
|
15
|
+
typeof (value as EventPosition).x === 'number' &&
|
|
16
|
+
typeof (value as EventPosition).y === 'number'
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
3
20
|
/**
|
|
4
21
|
* Is the value an event target?
|
|
22
|
+
*
|
|
5
23
|
* @param value Value to check
|
|
6
24
|
* @returns `true` if it's an event target, otherwise `false`
|
|
7
25
|
*/
|
|
@@ -16,9 +34,10 @@ export function isEventTarget(value: unknown): value is EventTarget {
|
|
|
16
34
|
}
|
|
17
35
|
|
|
18
36
|
/**
|
|
19
|
-
* Is the value an
|
|
37
|
+
* Is the value an _HTML_ or _SVG_ element?
|
|
38
|
+
*
|
|
20
39
|
* @param value Value to check
|
|
21
|
-
* @returns `true` if it's an
|
|
40
|
+
* @returns `true` if it's an _HTML_ or _SVG_ element, otherwise `false`
|
|
22
41
|
*/
|
|
23
42
|
export function isHTMLOrSVGElement(value: unknown): value is HTMLElement | SVGElement {
|
|
24
43
|
return value instanceof HTMLElement || value instanceof SVGElement;
|
|
@@ -26,6 +45,7 @@ export function isHTMLOrSVGElement(value: unknown): value is HTMLElement | SVGEl
|
|
|
26
45
|
|
|
27
46
|
/**
|
|
28
47
|
* Is the value an input element? _(`<input>`, `<select>`, or `<textarea>`)_
|
|
48
|
+
*
|
|
29
49
|
* @param value Value to check
|
|
30
50
|
* @returns `true` if it's an input element, otherwise `false`
|
|
31
51
|
*/
|
package/src/is.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Is the value a child node?
|
|
5
|
+
*
|
|
5
6
|
* @param value Value to check
|
|
6
7
|
* @returns `true` if it's a child node, otherwise `false`
|
|
7
8
|
*/
|
|
@@ -11,6 +12,7 @@ export function isChildNode(value: unknown): value is ChildNode {
|
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Is the node inside a document?
|
|
15
|
+
*
|
|
14
16
|
* @param node Node to check
|
|
15
17
|
* @returns `true` if it's inside a document, otherwise `false`
|
|
16
18
|
*/
|
|
@@ -18,6 +20,7 @@ export function isInDocument(node: Node): boolean;
|
|
|
18
20
|
|
|
19
21
|
/**
|
|
20
22
|
* Is the node inside a specific document?
|
|
23
|
+
*
|
|
21
24
|
* @param node Node to check
|
|
22
25
|
* @param document Document to check within
|
|
23
26
|
* @returns `true` if it's inside the document, otherwise `false`
|
|
@@ -54,6 +57,6 @@ const CHILD_NODE_TYPES: Set<number> = new Set([
|
|
|
54
57
|
|
|
55
58
|
// #region Exports
|
|
56
59
|
|
|
57
|
-
export {isEventTarget, isHTMLOrSVGElement, isInputElement} from './internal/is';
|
|
60
|
+
export {isEventPosition, isEventTarget, isHTMLOrSVGElement, isInputElement} from './internal/is';
|
|
58
61
|
|
|
59
62
|
// #endregion
|
package/src/models.ts
CHANGED
|
@@ -1,3 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* _ARIA_ attribute for an element
|
|
3
|
+
*
|
|
4
|
+
* _(https://www.w3.org/TR/wai-aria-1.3/#aria-attributes)_
|
|
5
|
+
*/
|
|
6
|
+
export type AriaAttribute = keyof AriaAttributes;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* _ARIA_ attribute for an element without the `aria-` prefix
|
|
10
|
+
*
|
|
11
|
+
* _(https://www.w3.org/TR/wai-aria-1.3/#aria-attributes)_
|
|
12
|
+
*/
|
|
13
|
+
export type AriaAttributeUnprefixed = keyof {
|
|
14
|
+
[Key in AriaAttribute as Key extends `aria-${infer Name}` ? Name : never]: string | null;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type AriaAttributes = {
|
|
18
|
+
[Key in keyof ARIAMixin as NormalizedName<Key>]: string | null;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
type NormalizedName<Key extends string> = Key extends `aria${infer Name}`
|
|
22
|
+
? Name extends `${infer Part}Element`
|
|
23
|
+
? `aria-${Lowercase<Part>}`
|
|
24
|
+
: Name extends `${infer Part}Elements`
|
|
25
|
+
? `aria-${Lowercase<Part>}`
|
|
26
|
+
: `aria-${Lowercase<Name>}`
|
|
27
|
+
: never;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* _ARIA_ role for an element
|
|
31
|
+
*
|
|
32
|
+
* _(https://www.w3.org/TR/wai-aria-1.3/#role_definitions)_
|
|
33
|
+
*/
|
|
34
|
+
export type AriaRole =
|
|
35
|
+
| 'alert'
|
|
36
|
+
| 'alertdialog'
|
|
37
|
+
| 'application'
|
|
38
|
+
| 'article'
|
|
39
|
+
| 'banner'
|
|
40
|
+
| 'blockquote'
|
|
41
|
+
| 'button'
|
|
42
|
+
| 'caption'
|
|
43
|
+
| 'cell'
|
|
44
|
+
| 'checkbox'
|
|
45
|
+
| 'code'
|
|
46
|
+
| 'columnheader'
|
|
47
|
+
| 'combobox'
|
|
48
|
+
| 'comment'
|
|
49
|
+
| 'complementary'
|
|
50
|
+
| 'contentinfo'
|
|
51
|
+
| 'definition'
|
|
52
|
+
| 'deletion'
|
|
53
|
+
| 'dialog'
|
|
54
|
+
| 'directory'
|
|
55
|
+
| 'document'
|
|
56
|
+
| 'emphasis'
|
|
57
|
+
| 'feed'
|
|
58
|
+
| 'figure'
|
|
59
|
+
| 'form'
|
|
60
|
+
| 'generic'
|
|
61
|
+
| 'grid'
|
|
62
|
+
| 'gridcell'
|
|
63
|
+
| 'group'
|
|
64
|
+
| 'heading'
|
|
65
|
+
| 'img'
|
|
66
|
+
| 'insertion'
|
|
67
|
+
| 'link'
|
|
68
|
+
| 'list'
|
|
69
|
+
| 'listbox'
|
|
70
|
+
| 'listitem'
|
|
71
|
+
| 'log'
|
|
72
|
+
| 'main'
|
|
73
|
+
| 'mark'
|
|
74
|
+
| 'marquee'
|
|
75
|
+
| 'math'
|
|
76
|
+
| 'menu'
|
|
77
|
+
| 'menubar'
|
|
78
|
+
| 'menuitem'
|
|
79
|
+
| 'menuitemcheckbox'
|
|
80
|
+
| 'menuitemradio'
|
|
81
|
+
| 'meter'
|
|
82
|
+
| 'navigation'
|
|
83
|
+
| 'none'
|
|
84
|
+
| 'note'
|
|
85
|
+
| 'option'
|
|
86
|
+
| 'paragraph'
|
|
87
|
+
| 'presentation'
|
|
88
|
+
| 'progressbar'
|
|
89
|
+
| 'radio'
|
|
90
|
+
| 'radiogroup'
|
|
91
|
+
| 'region'
|
|
92
|
+
| 'row'
|
|
93
|
+
| 'rowgroup'
|
|
94
|
+
| 'rowheader'
|
|
95
|
+
| 'scrollbar'
|
|
96
|
+
| 'search'
|
|
97
|
+
| 'searchbox'
|
|
98
|
+
| 'sectionfooter'
|
|
99
|
+
| 'sectionheader'
|
|
100
|
+
| 'separator'
|
|
101
|
+
| 'slider'
|
|
102
|
+
| 'spinbutton'
|
|
103
|
+
| 'status'
|
|
104
|
+
| 'strong'
|
|
105
|
+
| 'subscript'
|
|
106
|
+
| 'suggestion'
|
|
107
|
+
| 'superscript'
|
|
108
|
+
| 'switch'
|
|
109
|
+
| 'tab'
|
|
110
|
+
| 'table'
|
|
111
|
+
| 'tablist'
|
|
112
|
+
| 'tabpanel'
|
|
113
|
+
| 'term'
|
|
114
|
+
| 'textbox'
|
|
115
|
+
| 'time'
|
|
116
|
+
| 'timer'
|
|
117
|
+
| 'toolbar'
|
|
118
|
+
| 'tooltip'
|
|
119
|
+
| 'tree'
|
|
120
|
+
| 'treegrid'
|
|
121
|
+
| 'treeitem';
|
|
122
|
+
|
|
1
123
|
/**
|
|
2
124
|
* Attribute for an element
|
|
3
125
|
*/
|
|
@@ -11,14 +133,6 @@ export type Attribute = {
|
|
|
11
133
|
*/
|
|
12
134
|
export type CustomEventListener = (event: CustomEvent) => void;
|
|
13
135
|
|
|
14
|
-
/**
|
|
15
|
-
* The position of an event
|
|
16
|
-
*/
|
|
17
|
-
export type EventPosition = {
|
|
18
|
-
x: number;
|
|
19
|
-
y: number;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
136
|
/**
|
|
23
137
|
* Event listener that can be removed
|
|
24
138
|
*/
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type {Primitive} from '@oscarpalmer/atoms/models';
|
|
2
2
|
import {camelCase} from '@oscarpalmer/atoms/string/case';
|
|
3
|
-
import {isHTMLOrSVGElement} from '../internal/is';
|
|
4
3
|
|
|
5
4
|
// #region Types
|
|
6
5
|
|
|
@@ -16,6 +15,7 @@ type GetProperties<Target extends Element> = {
|
|
|
16
15
|
|
|
17
16
|
/**
|
|
18
17
|
* Get the values of one or more properties on an element
|
|
18
|
+
*
|
|
19
19
|
* @param target Target element
|
|
20
20
|
* @param properties Properties to get
|
|
21
21
|
* @returns Property values
|
|
@@ -26,7 +26,7 @@ export function getProperties<Target extends Element, Property extends keyof Get
|
|
|
26
26
|
): Pick<GetProperties<Target>, Property> {
|
|
27
27
|
const values: Partial<GetProperties<Target>> = {};
|
|
28
28
|
|
|
29
|
-
if (!
|
|
29
|
+
if (!(target instanceof Element && Array.isArray(properties))) {
|
|
30
30
|
return values as Pick<GetProperties<Target>, Property>;
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -45,6 +45,7 @@ export function getProperties<Target extends Element, Property extends keyof Get
|
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* Get the value of a property on an element
|
|
48
|
+
*
|
|
48
49
|
* @param target Target element
|
|
49
50
|
* @param property Property to get
|
|
50
51
|
* @returns Property value
|
|
@@ -53,12 +54,12 @@ export function getProperty<Target extends Element, Property extends keyof GetPr
|
|
|
53
54
|
target: Target,
|
|
54
55
|
property: Property,
|
|
55
56
|
): GetProperties<Target>[Property] {
|
|
56
|
-
if (
|
|
57
|
+
if (target instanceof Element && typeof property === 'string') {
|
|
57
58
|
return getPropertyValue(target, property) as GetProperties<Target>[Property];
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
function getPropertyValue(element:
|
|
62
|
+
function getPropertyValue(element: Element, property: string): unknown {
|
|
62
63
|
let actual = property;
|
|
63
64
|
|
|
64
65
|
if (!(actual in element)) {
|
|
@@ -66,7 +67,7 @@ function getPropertyValue(element: HTMLElement, property: string): unknown {
|
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
if (actual in element) {
|
|
69
|
-
return element[actual as keyof
|
|
70
|
+
return element[actual as keyof Element];
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
|
|
@@ -4,7 +4,6 @@ import {setAttribute} from '../attribute';
|
|
|
4
4
|
import type {DispatchedAttributeName} from '../attribute/set.attribute';
|
|
5
5
|
import {booleanAttributesSet, dispatchedAttributes} from '../internal/attribute';
|
|
6
6
|
import {updateProperty} from '../internal/property';
|
|
7
|
-
import {isHTMLOrSVGElement} from '../is';
|
|
8
7
|
|
|
9
8
|
// #region Types
|
|
10
9
|
|
|
@@ -27,6 +26,7 @@ type SetProperties<Target extends Element> = {
|
|
|
27
26
|
* Set the values of one or more properties on an element
|
|
28
27
|
*
|
|
29
28
|
* Also updates attributes for boolean/dispatchable properties, and if `dispatch` is `true`, will dispatch events for dispatchable properties
|
|
29
|
+
*
|
|
30
30
|
* @param target Target element
|
|
31
31
|
* @param properties Properties to set
|
|
32
32
|
* @param dispatch Dispatch events for properties? _(defaults to `true`)_
|
|
@@ -36,7 +36,7 @@ export function setProperties<Target extends Element>(
|
|
|
36
36
|
properties: SetProperties<Target>,
|
|
37
37
|
dispatch?: boolean,
|
|
38
38
|
): void {
|
|
39
|
-
if (!
|
|
39
|
+
if (!(target instanceof Element) || !isPlainObject(properties)) {
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -52,6 +52,7 @@ export function setProperties<Target extends Element>(
|
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
54
|
* Set the value for a dispatchable property on an element
|
|
55
|
+
*
|
|
55
56
|
* @param target Target element
|
|
56
57
|
* @param property Property to set
|
|
57
58
|
* @param value Value to set
|
|
@@ -66,6 +67,7 @@ export function setProperty<Target extends Element, Property extends DispatchedA
|
|
|
66
67
|
|
|
67
68
|
/**
|
|
68
69
|
* Set the value for a property on an element
|
|
70
|
+
*
|
|
69
71
|
* @param target Target element
|
|
70
72
|
* @param property Property to set
|
|
71
73
|
* @param value Value to set
|
|
@@ -82,7 +84,7 @@ export function setProperty<Target extends Element, Property extends keyof SetPr
|
|
|
82
84
|
value: SetProperties<Target>[Property],
|
|
83
85
|
dispatch?: boolean,
|
|
84
86
|
): void {
|
|
85
|
-
if (
|
|
87
|
+
if (target instanceof Element && typeof property === 'string') {
|
|
86
88
|
setPropertyValue(target, property, value, dispatch !== false);
|
|
87
89
|
}
|
|
88
90
|
}
|
package/src/style.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {getString} from '@oscarpalmer/atoms/string';
|
|
2
2
|
import {setElementValues, updateElementValue} from './internal/element-value';
|
|
3
3
|
import {getStyleValue} from './internal/get-value';
|
|
4
|
-
import {isHTMLOrSVGElement} from './internal/is';
|
|
5
4
|
import type {TextDirection} from './models';
|
|
6
5
|
|
|
7
6
|
// #region Types
|
|
@@ -33,6 +32,7 @@ type Variables<
|
|
|
33
32
|
|
|
34
33
|
/**
|
|
35
34
|
* Get a style from an element
|
|
35
|
+
*
|
|
36
36
|
* @param element Element to get the style from
|
|
37
37
|
* @param property Style name
|
|
38
38
|
* @param computed Get the computed style? _(defaults to `false`)_
|
|
@@ -43,13 +43,14 @@ export function getStyle(
|
|
|
43
43
|
property: keyof CSSStyleValues,
|
|
44
44
|
computed?: boolean,
|
|
45
45
|
): string | undefined {
|
|
46
|
-
if (
|
|
46
|
+
if (element instanceof Element && typeof property === 'string') {
|
|
47
47
|
return getStyleValue(element, property, computed === true);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
52
|
* Get styles from an element
|
|
53
|
+
*
|
|
53
54
|
* @param element Element to get the styles from
|
|
54
55
|
* @param properties Styles to get
|
|
55
56
|
* @param computed Get the computed styles? _(defaults to `false`)_
|
|
@@ -62,7 +63,7 @@ export function getStyles<Property extends keyof CSSStyleValues>(
|
|
|
62
63
|
): Record<Property, string | undefined> {
|
|
63
64
|
const styles = {} as Record<Property, string | undefined>;
|
|
64
65
|
|
|
65
|
-
if (!(
|
|
66
|
+
if (!(element instanceof Element && Array.isArray(properties))) {
|
|
66
67
|
return styles;
|
|
67
68
|
}
|
|
68
69
|
|
|
@@ -81,6 +82,7 @@ export function getStyles<Property extends keyof CSSStyleValues>(
|
|
|
81
82
|
|
|
82
83
|
/**
|
|
83
84
|
* Get the text direction of a node or element _(or document, if element is invalid)_
|
|
85
|
+
*
|
|
84
86
|
* @param node Node or element to get the text direction from
|
|
85
87
|
* @returns Text direction
|
|
86
88
|
*/
|
|
@@ -88,15 +90,16 @@ export function getTextDirection(node: Element | Node): TextDirection;
|
|
|
88
90
|
|
|
89
91
|
/**
|
|
90
92
|
* Get the text direction of the document
|
|
93
|
+
*
|
|
91
94
|
* @returns Text direction
|
|
92
95
|
*/
|
|
93
96
|
export function getTextDirection(): TextDirection;
|
|
94
97
|
|
|
95
98
|
export function getTextDirection(node?: Element | Node): TextDirection {
|
|
96
|
-
let target: HTMLElement
|
|
99
|
+
let target: HTMLElement;
|
|
97
100
|
|
|
98
|
-
if (
|
|
99
|
-
target = node;
|
|
101
|
+
if (node instanceof Element) {
|
|
102
|
+
target = node as HTMLElement;
|
|
100
103
|
} else {
|
|
101
104
|
target =
|
|
102
105
|
node instanceof Node
|
|
@@ -115,6 +118,7 @@ export function getTextDirection(node?: Element | Node): TextDirection {
|
|
|
115
118
|
|
|
116
119
|
/**
|
|
117
120
|
* Set a style on an element
|
|
121
|
+
*
|
|
118
122
|
* @param element Element to set the style on
|
|
119
123
|
* @param property Style name
|
|
120
124
|
* @param value Style value
|
|
@@ -125,6 +129,7 @@ export function setStyle(element: Element, property: keyof CSSStyleValues, value
|
|
|
125
129
|
|
|
126
130
|
/**
|
|
127
131
|
* Set styles on an element
|
|
132
|
+
*
|
|
128
133
|
* @param element Element to set the styles on
|
|
129
134
|
* @param styles Styles to set
|
|
130
135
|
*/
|
|
@@ -134,6 +139,7 @@ export function setStyles(element: Element, styles: Styles): void {
|
|
|
134
139
|
|
|
135
140
|
/**
|
|
136
141
|
* Toggle styles for an element
|
|
142
|
+
*
|
|
137
143
|
* @param element Element to style
|
|
138
144
|
* @param styles Styles to be set or removed
|
|
139
145
|
* @returns Style toggler
|
package/src/touch.ts
CHANGED
|
@@ -11,10 +11,14 @@ type SupporsTouch = {
|
|
|
11
11
|
readonly value: boolean;
|
|
12
12
|
/**
|
|
13
13
|
* Are touch events supported?
|
|
14
|
+
*
|
|
15
|
+
* @returns `true` if touch events are supported, otherwise `false`
|
|
14
16
|
*/
|
|
15
17
|
get(): boolean;
|
|
16
18
|
/**
|
|
17
19
|
* Re-evaluate if touch events are supported
|
|
20
|
+
*
|
|
21
|
+
* @returns `true` if touch events are supported, otherwise `false`
|
|
18
22
|
*/
|
|
19
23
|
update(): boolean;
|
|
20
24
|
};
|