@oscarpalmer/toretto 0.45.0 → 0.46.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/attribute/get.attribute.d.mts +2 -0
- package/dist/attribute/get.attribute.mjs +1 -0
- package/dist/attribute/index.d.mts +6 -0
- package/dist/attribute/set.attribute.d.mts +5 -0
- package/dist/create.d.mts +2 -0
- package/dist/data.d.mts +4 -0
- package/dist/event/index.d.mts +9 -1
- package/dist/event/index.mjs +2 -0
- 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 +3 -0
- package/dist/html/index.mjs +1 -0
- package/dist/index.d.mts +90 -8
- package/dist/index.mjs +116 -10
- package/dist/internal/is.d.mts +13 -1
- package/dist/internal/is.mjs +13 -1
- package/dist/is.d.mts +5 -2
- package/dist/is.mjs +3 -2
- package/dist/models.d.mts +1 -8
- package/dist/property/get.property.d.mts +2 -0
- package/dist/property/get.property.mjs +2 -0
- package/dist/property/set.property.d.mts +3 -0
- package/dist/property/set.property.mjs +1 -0
- package/dist/style.d.mts +7 -0
- package/dist/style.mjs +5 -0
- package/dist/touch.d.mts +4 -0
- package/package.json +6 -6
- package/src/attribute/get.attribute.ts +2 -0
- package/src/attribute/index.ts +6 -0
- package/src/attribute/set.attribute.ts +5 -0
- package/src/create.ts +2 -0
- package/src/data.ts +4 -0
- package/src/event/index.ts +10 -1
- 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 +4 -0
- package/src/internal/is.ts +20 -0
- package/src/is.ts +4 -1
- package/src/models.ts +0 -8
- package/src/property/get.property.ts +2 -0
- package/src/property/set.property.ts +3 -0
- package/src/style.ts +7 -0
- package/src/touch.ts +4 -0
package/dist/style.d.mts
CHANGED
|
@@ -16,6 +16,7 @@ type Styles = Partial<Record<keyof CSSStyleValues, unknown>>;
|
|
|
16
16
|
type Variables<Value extends Record<string, string | undefined> = Record<string, string | undefined>> = { [property in keyof Value as `--${string & property}`]?: string | undefined };
|
|
17
17
|
/**
|
|
18
18
|
* Get a style from an element
|
|
19
|
+
*
|
|
19
20
|
* @param element Element to get the style from
|
|
20
21
|
* @param property Style name
|
|
21
22
|
* @param computed Get the computed style? _(defaults to `false`)_
|
|
@@ -24,6 +25,7 @@ type Variables<Value extends Record<string, string | undefined> = Record<string,
|
|
|
24
25
|
declare function getStyle(element: Element, property: keyof CSSStyleValues, computed?: boolean): string | undefined;
|
|
25
26
|
/**
|
|
26
27
|
* Get styles from an element
|
|
28
|
+
*
|
|
27
29
|
* @param element Element to get the styles from
|
|
28
30
|
* @param properties Styles to get
|
|
29
31
|
* @param computed Get the computed styles? _(defaults to `false`)_
|
|
@@ -32,17 +34,20 @@ declare function getStyle(element: Element, property: keyof CSSStyleValues, comp
|
|
|
32
34
|
declare function getStyles<Property extends keyof CSSStyleValues>(element: Element, properties: Property[], computed?: boolean): Record<Property, string | undefined>;
|
|
33
35
|
/**
|
|
34
36
|
* Get the text direction of a node or element _(or document, if element is invalid)_
|
|
37
|
+
*
|
|
35
38
|
* @param node Node or element to get the text direction from
|
|
36
39
|
* @returns Text direction
|
|
37
40
|
*/
|
|
38
41
|
declare function getTextDirection(node: Element | Node): TextDirection;
|
|
39
42
|
/**
|
|
40
43
|
* Get the text direction of the document
|
|
44
|
+
*
|
|
41
45
|
* @returns Text direction
|
|
42
46
|
*/
|
|
43
47
|
declare function getTextDirection(): TextDirection;
|
|
44
48
|
/**
|
|
45
49
|
* Set a style on an element
|
|
50
|
+
*
|
|
46
51
|
* @param element Element to set the style on
|
|
47
52
|
* @param property Style name
|
|
48
53
|
* @param value Style value
|
|
@@ -50,12 +55,14 @@ declare function getTextDirection(): TextDirection;
|
|
|
50
55
|
declare function setStyle(element: Element, property: keyof CSSStyleValues, value?: unknown): void;
|
|
51
56
|
/**
|
|
52
57
|
* Set styles on an element
|
|
58
|
+
*
|
|
53
59
|
* @param element Element to set the styles on
|
|
54
60
|
* @param styles Styles to set
|
|
55
61
|
*/
|
|
56
62
|
declare function setStyles(element: Element, styles: Styles): void;
|
|
57
63
|
/**
|
|
58
64
|
* Toggle styles for an element
|
|
65
|
+
*
|
|
59
66
|
* @param element Element to style
|
|
60
67
|
* @param styles Styles to be set or removed
|
|
61
68
|
* @returns Style toggler
|
package/dist/style.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { getString } from "@oscarpalmer/atoms/string";
|
|
|
5
5
|
//#region src/style.ts
|
|
6
6
|
/**
|
|
7
7
|
* Get a style from an element
|
|
8
|
+
*
|
|
8
9
|
* @param element Element to get the style from
|
|
9
10
|
* @param property Style name
|
|
10
11
|
* @param computed Get the computed style? _(defaults to `false`)_
|
|
@@ -15,6 +16,7 @@ function getStyle(element, property, computed) {
|
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
17
18
|
* Get styles from an element
|
|
19
|
+
*
|
|
18
20
|
* @param element Element to get the styles from
|
|
19
21
|
* @param properties Styles to get
|
|
20
22
|
* @param computed Get the computed styles? _(defaults to `false`)_
|
|
@@ -40,6 +42,7 @@ function getTextDirection(node) {
|
|
|
40
42
|
}
|
|
41
43
|
/**
|
|
42
44
|
* Set a style on an element
|
|
45
|
+
*
|
|
43
46
|
* @param element Element to set the style on
|
|
44
47
|
* @param property Style name
|
|
45
48
|
* @param value Style value
|
|
@@ -49,6 +52,7 @@ function setStyle(element, property, value) {
|
|
|
49
52
|
}
|
|
50
53
|
/**
|
|
51
54
|
* Set styles on an element
|
|
55
|
+
*
|
|
52
56
|
* @param element Element to set the styles on
|
|
53
57
|
* @param styles Styles to set
|
|
54
58
|
*/
|
|
@@ -57,6 +61,7 @@ function setStyles(element, styles) {
|
|
|
57
61
|
}
|
|
58
62
|
/**
|
|
59
63
|
* Toggle styles for an element
|
|
64
|
+
*
|
|
60
65
|
* @param element Element to style
|
|
61
66
|
* @param styles Styles to be set or removed
|
|
62
67
|
* @returns Style toggler
|
package/dist/touch.d.mts
CHANGED
|
@@ -6,10 +6,14 @@ type SupporsTouch = {
|
|
|
6
6
|
readonly value: boolean;
|
|
7
7
|
/**
|
|
8
8
|
* Are touch events supported?
|
|
9
|
+
*
|
|
10
|
+
* @returns `true` if touch events are supported, otherwise `false`
|
|
9
11
|
*/
|
|
10
12
|
get(): boolean;
|
|
11
13
|
/**
|
|
12
14
|
* Re-evaluate if touch events are supported
|
|
15
|
+
*
|
|
16
|
+
* @returns `true` if touch events are supported, otherwise `false`
|
|
13
17
|
*/
|
|
14
18
|
update(): boolean;
|
|
15
19
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oscarpalmer/toretto",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.0",
|
|
4
4
|
"description": "A collection of badass DOM utilities.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dom",
|
|
@@ -86,15 +86,15 @@
|
|
|
86
86
|
"test:leak": "npx vp test run --detect-async-leaks --coverage"
|
|
87
87
|
},
|
|
88
88
|
"dependencies": {
|
|
89
|
-
"@oscarpalmer/atoms": "^0.
|
|
89
|
+
"@oscarpalmer/atoms": "^0.187.2"
|
|
90
90
|
},
|
|
91
91
|
"devDependencies": {
|
|
92
|
-
"@oxlint/plugins": "^1.
|
|
93
|
-
"@types/node": "^25.
|
|
92
|
+
"@oxlint/plugins": "^1.67",
|
|
93
|
+
"@types/node": "^25.9",
|
|
94
94
|
"@vitest/coverage-istanbul": "^4.1",
|
|
95
95
|
"jsdom": "^29.1",
|
|
96
|
-
"tsdown": "^0.
|
|
97
|
-
"typescript": "^
|
|
96
|
+
"tsdown": "^0.22",
|
|
97
|
+
"typescript": "^6",
|
|
98
98
|
"vite": "npm:@voidzero-dev/vite-plus-core@latest",
|
|
99
99
|
"vite-plus": "latest",
|
|
100
100
|
"vitest": "npm:@voidzero-dev/vite-plus-test@latest"
|
|
@@ -21,6 +21,7 @@ export function getAttribute(element: Element, name: DataPrefixedName, parse?: b
|
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Get the value of a specific attribute from an element
|
|
24
|
+
*
|
|
24
25
|
* @param element Element to get attribute from
|
|
25
26
|
* @param name Attribute name
|
|
26
27
|
* @returns Attribute value _(or `undefined`)_
|
|
@@ -35,6 +36,7 @@ export function getAttribute(element: Element, name: string, parseValues?: boole
|
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
38
|
* Get specific attributes from an element
|
|
39
|
+
*
|
|
38
40
|
* @param element Element to get attributes from
|
|
39
41
|
* @param names Attribute names
|
|
40
42
|
* @param parseData Parse data values? _(defaults to `true`)_
|
package/src/attribute/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type {Attribute} from '../models';
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Is the attribute considered bad and potentially harmful?
|
|
12
|
+
*
|
|
12
13
|
* @param attribute Attribute to check
|
|
13
14
|
* @returns `true` if attribute is considered bad
|
|
14
15
|
*/
|
|
@@ -16,6 +17,7 @@ export function isBadAttribute(attribute: Attr | Attribute): boolean;
|
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Is the attribute considered bad and potentially harmful?
|
|
20
|
+
*
|
|
19
21
|
* @param name Attribute name
|
|
20
22
|
* @param value Attribute value
|
|
21
23
|
* @returns `true` if attribute is considered bad
|
|
@@ -28,6 +30,7 @@ export function isBadAttribute(first: unknown, second?: unknown): boolean {
|
|
|
28
30
|
|
|
29
31
|
/**
|
|
30
32
|
* Is the attribute a boolean attribute?
|
|
33
|
+
*
|
|
31
34
|
* @param name Attribute to check
|
|
32
35
|
* @returns `true` if attribute is a boolean attribute
|
|
33
36
|
*/
|
|
@@ -35,6 +38,7 @@ export function isBooleanAttribute(attribute: Attr | Attribute): boolean;
|
|
|
35
38
|
|
|
36
39
|
/**
|
|
37
40
|
* Is the attribute a boolean attribute?
|
|
41
|
+
*
|
|
38
42
|
* @param name Attribute name
|
|
39
43
|
* @returns `true` if attribute is a boolean attribute
|
|
40
44
|
*/
|
|
@@ -48,6 +52,7 @@ export function isBooleanAttribute(first: unknown): boolean {
|
|
|
48
52
|
* Is the attribute an invalid boolean attribute?
|
|
49
53
|
*
|
|
50
54
|
* _(I.e., its value is not empty or the same as its name)_
|
|
55
|
+
*
|
|
51
56
|
* @param attribute Attribute to check
|
|
52
57
|
* @returns `true` if attribute is an invalid boolean attribute
|
|
53
58
|
*/
|
|
@@ -57,6 +62,7 @@ export function isInvalidBooleanAttribute(attribute: Attr | Attribute): boolean;
|
|
|
57
62
|
* Is the attribute an invalid boolean attribute?
|
|
58
63
|
*
|
|
59
64
|
* _(I.e., its value is not empty or the same as its name)_
|
|
65
|
+
*
|
|
60
66
|
* @param name Attribute name
|
|
61
67
|
* @param value Attribute value
|
|
62
68
|
* @returns `true` if attribute is an invalid boolean attribute
|
|
@@ -14,6 +14,7 @@ export type DispatchedAttributeName = 'checked' | 'open' | 'value';
|
|
|
14
14
|
* Set an attribute on an element
|
|
15
15
|
*
|
|
16
16
|
* _(Or remove it, if value is `null` or `undefined`)_
|
|
17
|
+
*
|
|
17
18
|
* @param element Element for attribute
|
|
18
19
|
* @param name Attribute name
|
|
19
20
|
* @param value Attribute value
|
|
@@ -30,6 +31,7 @@ export function setAttribute(
|
|
|
30
31
|
* Set an attribute on an element
|
|
31
32
|
*
|
|
32
33
|
* _(Or remove it, if value is `null` or `undefined`)_
|
|
34
|
+
*
|
|
33
35
|
* @param element Element for attribute
|
|
34
36
|
* @param name Attribute name
|
|
35
37
|
* @param value Attribute value
|
|
@@ -40,6 +42,7 @@ export function setAttribute(element: Element, name: string, value?: unknown): v
|
|
|
40
42
|
* Set an attribute on an element
|
|
41
43
|
*
|
|
42
44
|
* _(Or remove it, if value is `null` or `undefined`)_
|
|
45
|
+
*
|
|
43
46
|
* @param element Element for attribute
|
|
44
47
|
* @param attribute Attribute to set
|
|
45
48
|
* @param dispatch Dispatch event for attribute? _(defaults to `true`)_
|
|
@@ -63,6 +66,7 @@ export function setAttribute(
|
|
|
63
66
|
* Set one or more attributes on an element
|
|
64
67
|
*
|
|
65
68
|
* _(Or remove them, if their value is `null` or `undefined`)_
|
|
69
|
+
*
|
|
66
70
|
* @param element Element for attributes
|
|
67
71
|
* @param attributes Attributes to set
|
|
68
72
|
* @param dispatch Dispatch events for relevant attributes? _(defaults to `true`)_
|
|
@@ -77,6 +81,7 @@ export function setAttributes(
|
|
|
77
81
|
* Set one or more attributes on an element
|
|
78
82
|
*
|
|
79
83
|
* _(Or remove them, if their value is `null` or `undefined`)_
|
|
84
|
+
*
|
|
80
85
|
* @param element Element for attributes
|
|
81
86
|
* @param attributes Attributes to set
|
|
82
87
|
* @param dispatch Dispatch events for relevant attributes? _(defaults to `true`)_
|
package/src/create.ts
CHANGED
|
@@ -17,6 +17,7 @@ type Styles = Partial<Record<keyof CSSStyleDeclaration, unknown>>;
|
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Creates an HTML element with the specified tag name together with optional properties, attributes, and styles
|
|
20
|
+
*
|
|
20
21
|
* @param tag Tag name
|
|
21
22
|
* @param properties Element properties
|
|
22
23
|
* @param attributes Element attributes
|
|
@@ -32,6 +33,7 @@ export function createElement<TagName extends keyof HTMLElementTagNameMap>(
|
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
35
|
* Creates an HTML element with the specified tag name together with optional properties, attributes, and styles
|
|
36
|
+
*
|
|
35
37
|
* @param tag Tag name
|
|
36
38
|
* @param properties Element properties
|
|
37
39
|
* @param attributes Element attributes
|
package/src/data.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {isHTMLOrSVGElement} from './internal/is';
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Get a keyed data value from an element
|
|
12
|
+
*
|
|
12
13
|
* @param element Element to get data from
|
|
13
14
|
* @param key Data key
|
|
14
15
|
* @param parse Parse values? _(defaults to `true`)_
|
|
@@ -18,6 +19,7 @@ export function getData(element: Element, key: string, parse?: boolean): unknown
|
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* Get keyed data values from an element
|
|
22
|
+
*
|
|
21
23
|
* @param element Element to get data from
|
|
22
24
|
* @param keys Keys of the data values to get
|
|
23
25
|
* @param parse Parse values? _(defaults to `true`)_
|
|
@@ -70,6 +72,7 @@ function getName(original: string): string {
|
|
|
70
72
|
|
|
71
73
|
/**
|
|
72
74
|
* Set data values on an element
|
|
75
|
+
*
|
|
73
76
|
* @param element Element to set data on
|
|
74
77
|
* @param data Data to set
|
|
75
78
|
*/
|
|
@@ -77,6 +80,7 @@ export function setData(element: Element, data: PlainObject): void;
|
|
|
77
80
|
|
|
78
81
|
/**
|
|
79
82
|
* Set a data value on an element
|
|
83
|
+
*
|
|
80
84
|
* @param element Element to set data on
|
|
81
85
|
* @param key Data key
|
|
82
86
|
* @param value Data value
|
package/src/event/index.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {noop} from '@oscarpalmer/atoms/function';
|
|
2
2
|
import {isPlainObject} from '@oscarpalmer/atoms/is';
|
|
3
|
+
import type {EventPosition} from '@oscarpalmer/atoms/models';
|
|
3
4
|
import {getBoolean} from '../internal/get-value';
|
|
4
5
|
import {isEventTarget} from '../internal/is';
|
|
5
|
-
import type {CustomEventListener,
|
|
6
|
+
import type {CustomEventListener, RemovableEventListener} from '../models';
|
|
6
7
|
import {
|
|
7
8
|
addDelegatedListener,
|
|
8
9
|
type EventTargetWithListeners,
|
|
@@ -55,6 +56,7 @@ function createEventOptions(options?: AddEventListenerOptions): EventOptions {
|
|
|
55
56
|
|
|
56
57
|
/**
|
|
57
58
|
* Dispatch an event for a target
|
|
59
|
+
*
|
|
58
60
|
* @param target Event target
|
|
59
61
|
* @param type Type of event
|
|
60
62
|
* @param options Options for event _(bubbles and is cancelable by default)_
|
|
@@ -67,6 +69,7 @@ export function dispatch<Type extends keyof HTMLElementEventMap>(
|
|
|
67
69
|
|
|
68
70
|
/**
|
|
69
71
|
* Dispatch an event for a target
|
|
72
|
+
*
|
|
70
73
|
* @param target Event target
|
|
71
74
|
* @param type Type of event
|
|
72
75
|
* @param options Options for event _(bubbles and is cancelable by default)_
|
|
@@ -85,6 +88,7 @@ export function dispatch<Type extends keyof HTMLElementEventMap>(
|
|
|
85
88
|
|
|
86
89
|
/**
|
|
87
90
|
* Get the X- and Y-coordinates from a pointer event
|
|
91
|
+
*
|
|
88
92
|
* @param event Pointer event
|
|
89
93
|
* @returns X- and Y-coordinates
|
|
90
94
|
*/
|
|
@@ -105,6 +109,7 @@ export function getPosition(event: MouseEvent | TouchEvent): EventPosition | und
|
|
|
105
109
|
|
|
106
110
|
/**
|
|
107
111
|
* Remove an event listener
|
|
112
|
+
*
|
|
108
113
|
* @param target Event target
|
|
109
114
|
* @param type Type of event
|
|
110
115
|
* @param listener Event listener
|
|
@@ -119,6 +124,7 @@ export function off(
|
|
|
119
124
|
|
|
120
125
|
/**
|
|
121
126
|
* Remove an event listener
|
|
127
|
+
*
|
|
122
128
|
* @param target Event target
|
|
123
129
|
* @param type Type of event
|
|
124
130
|
* @param listener Event listener
|
|
@@ -133,6 +139,7 @@ export function off(
|
|
|
133
139
|
|
|
134
140
|
/**
|
|
135
141
|
* Remove an event listener
|
|
142
|
+
*
|
|
136
143
|
* @param target Event target
|
|
137
144
|
* @param type Type of event
|
|
138
145
|
* @param listener Event listener
|
|
@@ -161,6 +168,7 @@ export function off(
|
|
|
161
168
|
|
|
162
169
|
/**
|
|
163
170
|
* Add an event listener
|
|
171
|
+
*
|
|
164
172
|
* @param target Event target
|
|
165
173
|
* @param type Type of event
|
|
166
174
|
* @param listener Event listener
|
|
@@ -175,6 +183,7 @@ export function on<Type extends keyof HTMLElementEventMap>(
|
|
|
175
183
|
|
|
176
184
|
/**
|
|
177
185
|
* Add an event listener
|
|
186
|
+
*
|
|
178
187
|
* @param target Event target
|
|
179
188
|
* @param type Type of event
|
|
180
189
|
* @param listener Event listener
|
package/src/find/index.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import type {PlainObject} from '@oscarpalmer/atoms/models';
|
|
1
|
+
import type {EventPosition, PlainObject} from '@oscarpalmer/atoms/models';
|
|
2
|
+
import {isEventPosition} from '../internal/is';
|
|
2
3
|
import type {Selector} from '../models';
|
|
3
4
|
|
|
4
5
|
// #region Functions
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Find the first element that matches the tag name
|
|
9
|
+
*
|
|
8
10
|
* @param tagName Tag name of element to find
|
|
9
11
|
* @param context Context to search within _(defaults to `document`)_
|
|
10
12
|
* @returns Found element or `null`
|
|
@@ -16,6 +18,7 @@ export function findElement<TagName extends keyof HTMLElementTagNameMap>(
|
|
|
16
18
|
|
|
17
19
|
/**
|
|
18
20
|
* Find the first element that matches the selector
|
|
21
|
+
*
|
|
19
22
|
* @param selector Selector to find element for
|
|
20
23
|
* @param context Context to search within _(defaults to `document`)_
|
|
21
24
|
* @returns Found element or `null`
|
|
@@ -120,6 +123,7 @@ function findElementOrElementsFromNodes(
|
|
|
120
123
|
|
|
121
124
|
/**
|
|
122
125
|
* Find elements that match the selector
|
|
126
|
+
*
|
|
123
127
|
* @param tagName tagName to find elements for
|
|
124
128
|
* @param context Context to search within _(defaults to `document`)_
|
|
125
129
|
* @returns Found elements
|
|
@@ -131,6 +135,7 @@ export function findElements(
|
|
|
131
135
|
|
|
132
136
|
/**
|
|
133
137
|
* Find elements that match the selector
|
|
138
|
+
*
|
|
134
139
|
* @param selector Selector to find elements for
|
|
135
140
|
* @param context Context to search within _(defaults to `document`)_
|
|
136
141
|
* @returns Found elements
|
|
@@ -141,11 +146,65 @@ export function findElements(selector: Selector, context?: Selector | null): Ele
|
|
|
141
146
|
return findElementOrElements(selector, context, false) as never;
|
|
142
147
|
}
|
|
143
148
|
|
|
149
|
+
/**
|
|
150
|
+
* Get elements from an event position
|
|
151
|
+
*
|
|
152
|
+
* @param position Event position
|
|
153
|
+
* @returns Elements at the event position
|
|
154
|
+
*/
|
|
155
|
+
export function getElementFromPosition(position: EventPosition): Element[] {
|
|
156
|
+
if (!isEventPosition(position) || typeof document.elementFromPoint !== 'function') {
|
|
157
|
+
return [];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const {x, y} = position;
|
|
161
|
+
|
|
162
|
+
const elements: Element[] = [];
|
|
163
|
+
const events: {value: string; priority: string}[] = [];
|
|
164
|
+
|
|
165
|
+
let current: Element | null;
|
|
166
|
+
|
|
167
|
+
while (true) {
|
|
168
|
+
current = document.elementFromPoint(x, y);
|
|
169
|
+
|
|
170
|
+
if (current == null || elements.indexOf(current) !== -1) {
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (!(current instanceof HTMLElement)) {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
elements.push(current);
|
|
179
|
+
|
|
180
|
+
events.push({
|
|
181
|
+
value: current.style.getPropertyValue(STYLE_POINTER_EVENTS),
|
|
182
|
+
priority: current.style.getPropertyPriority(STYLE_POINTER_EVENTS),
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
current.style.setProperty(STYLE_POINTER_EVENTS, STYLE_NONE, STYLE_IMPORTANT);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const {length} = elements;
|
|
189
|
+
|
|
190
|
+
for (let index = 0; index < length; index += 1) {
|
|
191
|
+
const element = elements[index];
|
|
192
|
+
const event = events[index];
|
|
193
|
+
|
|
194
|
+
if (element instanceof HTMLElement) {
|
|
195
|
+
element.style.setProperty(STYLE_POINTER_EVENTS, event.value ?? '', event.priority);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return elements;
|
|
200
|
+
}
|
|
201
|
+
|
|
144
202
|
/**
|
|
145
203
|
* Get the most specific element under the pointer
|
|
146
204
|
*
|
|
147
205
|
* - Ignores elements with `pointer-events: none` and `visibility: hidden`
|
|
148
206
|
* - _(If `skipIgnore` is `true`, no elements are ignored)_
|
|
207
|
+
*
|
|
149
208
|
* @param skipIgnore Skip ignored elements?
|
|
150
209
|
* @returns Found element or `null`
|
|
151
210
|
*/
|
|
@@ -192,8 +251,12 @@ const QUERY_SELECTOR_SINGLE = 'querySelector';
|
|
|
192
251
|
|
|
193
252
|
const STYLE_HIDDEN = 'hidden';
|
|
194
253
|
|
|
254
|
+
const STYLE_IMPORTANT = 'important';
|
|
255
|
+
|
|
195
256
|
const STYLE_NONE = 'none';
|
|
196
257
|
|
|
258
|
+
const STYLE_POINTER_EVENTS = 'pointer-events';
|
|
259
|
+
|
|
197
260
|
const SUFFIX_HOVER = ':hover';
|
|
198
261
|
|
|
199
262
|
const TAG_HEAD = 'HEAD';
|
package/src/find/relative.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* - If no match is found, `null` is returned
|
|
7
7
|
* - _(If you want to search upwards, downwards, and sideways, use {@link findRelatives})_
|
|
8
|
+
*
|
|
8
9
|
* @param origin Origin to start from
|
|
9
10
|
* @param tagName Tag name to match
|
|
10
11
|
* @returns Found ancestor or `null`
|
|
@@ -19,6 +20,7 @@ export function findAncestor<TagName extends keyof HTMLElementTagNameMap>(
|
|
|
19
20
|
*
|
|
20
21
|
* - If no match is found, `null` is returned
|
|
21
22
|
* - _(If you want to search upwards, downwards, and sideways, use {@link findRelatives})_
|
|
23
|
+
*
|
|
22
24
|
* @param origin Origin to start from
|
|
23
25
|
* @param selector Selector to match
|
|
24
26
|
* @returns Found ancestor or `null`
|
|
@@ -71,6 +73,7 @@ export function findAncestor(
|
|
|
71
73
|
* Finds the closest elements to the origin element that matches the tag name
|
|
72
74
|
*
|
|
73
75
|
* Traverses up, down, and sideways in the _DOM_-tree. _(If you only want to traverse up, use {@link findAncestor})_
|
|
76
|
+
*
|
|
74
77
|
* @param origin Element to start from
|
|
75
78
|
* @param tagName Tag name to match
|
|
76
79
|
* @param context Context to search within
|
|
@@ -86,6 +89,7 @@ export function findRelatives<TagName extends keyof HTMLElementTagNameMap>(
|
|
|
86
89
|
* Finds the closest elements to the origin element that matches the selector
|
|
87
90
|
*
|
|
88
91
|
* Traverses up, down, and sideways in the _DOM_-tree. _(If you only want to traverse up, use {@link findAncestor})_
|
|
92
|
+
*
|
|
89
93
|
* @param origin Element to start from
|
|
90
94
|
* @param selector Selector to match
|
|
91
95
|
* @param context Context to search within
|
|
@@ -144,6 +148,7 @@ export function findRelatives(
|
|
|
144
148
|
|
|
145
149
|
/**
|
|
146
150
|
* Get the distance between two elements _(i.e., the amount of nodes of between them)_
|
|
151
|
+
*
|
|
147
152
|
* @param origin Origin element
|
|
148
153
|
* @param target Target element
|
|
149
154
|
* @returns Distance between elements, or `-1` if distance cannot be calculated
|
package/src/focusable.ts
CHANGED
|
@@ -17,6 +17,7 @@ type InertElement = Element & {inert: boolean};
|
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Get a list of focusable elements within a parent element
|
|
20
|
+
*
|
|
20
21
|
* @param parent Parent element
|
|
21
22
|
* @returns Focusable elements
|
|
22
23
|
*/
|
|
@@ -33,6 +34,7 @@ function getItem(element: Element, tabbable: boolean): ElementWithTabIndex {
|
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
36
|
* Get a list of tabbable elements within a parent element
|
|
37
|
+
*
|
|
36
38
|
* @param parent Parent element
|
|
37
39
|
* @returns Tabbable elements
|
|
38
40
|
*/
|
|
@@ -137,6 +139,7 @@ function isEditable(element: Element): boolean {
|
|
|
137
139
|
|
|
138
140
|
/**
|
|
139
141
|
* Is the element focusable?
|
|
142
|
+
*
|
|
140
143
|
* @param element Element to check
|
|
141
144
|
* @returns `true` if focusable, otherwise `false`
|
|
142
145
|
*/
|
|
@@ -221,6 +224,7 @@ function isSummarised(item: ElementWithTabIndex): boolean {
|
|
|
221
224
|
|
|
222
225
|
/**
|
|
223
226
|
* Is the element tabbable?
|
|
227
|
+
*
|
|
224
228
|
* @param element Element to check
|
|
225
229
|
* @returns `true` if tabbable, otherwise `false`
|
|
226
230
|
*/
|
package/src/html/index.ts
CHANGED
|
@@ -175,12 +175,14 @@ function hasNodes(value: unknown): value is HTMLCollection | NodeList | Node[] {
|
|
|
175
175
|
|
|
176
176
|
/**
|
|
177
177
|
* Create nodes from a template string
|
|
178
|
+
*
|
|
178
179
|
* @returns Created nodes
|
|
179
180
|
*/
|
|
180
181
|
export function html(strings: TemplateStringsArray, ...values: unknown[]): Node[];
|
|
181
182
|
|
|
182
183
|
/**
|
|
183
184
|
* Create nodes from an HTML string or a template element
|
|
185
|
+
*
|
|
184
186
|
* @param value HTML string or id for a template element
|
|
185
187
|
* @param options Options for creating nodes
|
|
186
188
|
* @returns Created nodes
|
|
@@ -189,6 +191,7 @@ export function html(value: string, options?: HtmlOptions): Node[];
|
|
|
189
191
|
|
|
190
192
|
/**
|
|
191
193
|
* Create nodes from a template element
|
|
194
|
+
*
|
|
192
195
|
* @param template Template element
|
|
193
196
|
* @param options Options for creating nodes
|
|
194
197
|
* @returns Created nodes
|
|
@@ -214,6 +217,7 @@ html.clear = (): void => {
|
|
|
214
217
|
|
|
215
218
|
/**
|
|
216
219
|
* Remove cached template element for an HTML string or id
|
|
220
|
+
*
|
|
217
221
|
* @param template HTML string or id for a template element
|
|
218
222
|
*/
|
|
219
223
|
html.remove = (template: string): void => {
|
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
|
*/
|
|
@@ -17,6 +35,7 @@ export function isEventTarget(value: unknown): value is EventTarget {
|
|
|
17
35
|
|
|
18
36
|
/**
|
|
19
37
|
* Is the value an HTML or SVG element?
|
|
38
|
+
*
|
|
20
39
|
* @param value Value to check
|
|
21
40
|
* @returns `true` if it's an HTML or SVG element, otherwise `false`
|
|
22
41
|
*/
|
|
@@ -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
|
@@ -11,14 +11,6 @@ export type Attribute = {
|
|
|
11
11
|
*/
|
|
12
12
|
export type CustomEventListener = (event: CustomEvent) => void;
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* The position of an event
|
|
16
|
-
*/
|
|
17
|
-
export type EventPosition = {
|
|
18
|
-
x: number;
|
|
19
|
-
y: number;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
14
|
/**
|
|
23
15
|
* Event listener that can be removed
|
|
24
16
|
*/
|
|
@@ -16,6 +16,7 @@ type GetProperties<Target extends Element> = {
|
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Get the values of one or more properties on an element
|
|
19
|
+
*
|
|
19
20
|
* @param target Target element
|
|
20
21
|
* @param properties Properties to get
|
|
21
22
|
* @returns Property values
|
|
@@ -45,6 +46,7 @@ export function getProperties<Target extends Element, Property extends keyof Get
|
|
|
45
46
|
|
|
46
47
|
/**
|
|
47
48
|
* Get the value of a property on an element
|
|
49
|
+
*
|
|
48
50
|
* @param target Target element
|
|
49
51
|
* @param property Property to get
|
|
50
52
|
* @returns Property value
|