@oscarpalmer/toretto 0.47.2 → 0.48.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 +0 -1
- package/dist/attribute/index.d.mts +0 -1
- package/dist/attribute/set.attribute.d.mts +0 -1
- package/dist/create.d.mts +1 -2
- package/dist/data.d.mts +0 -1
- package/dist/event/delegation.d.mts +0 -1
- package/dist/event/index.d.mts +6 -3
- package/dist/event/index.mjs +4 -1
- package/dist/find/index.d.mts +0 -1
- package/dist/html/index.mjs +1 -1
- package/dist/index.d.mts +6 -2
- package/dist/index.mjs +5 -14
- package/dist/internal/attribute.d.mts +0 -1
- package/dist/internal/attribute.mjs +1 -1
- package/dist/internal/element-value.mjs +1 -2
- package/dist/internal/is.d.mts +0 -1
- package/dist/is.d.mts +0 -1
- package/dist/models.d.mts +2 -2
- package/dist/property/get.property.d.mts +1 -2
- package/dist/property/set.property.d.mts +1 -2
- package/dist/style.d.mts +1 -2
- package/package.json +2 -2
- package/src/event/index.ts +18 -8
- package/src/internal/element-value.ts +1 -2
package/dist/aria.d.mts
CHANGED
|
@@ -2,7 +2,6 @@ import { Attribute } from "../models.mjs";
|
|
|
2
2
|
import { getAttribute, getAttributes } from "./get.attribute.mjs";
|
|
3
3
|
import { booleanAttributes } from "../internal/attribute.mjs";
|
|
4
4
|
import { setAttribute, setAttributes } from "./set.attribute.mjs";
|
|
5
|
-
|
|
6
5
|
//#region src/attribute/index.d.ts
|
|
7
6
|
/**
|
|
8
7
|
* Is the attribute considered bad and potentially harmful?
|
package/dist/create.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Primitive } from "@oscarpalmer/atoms/models";
|
|
2
|
-
|
|
3
2
|
//#region src/create.d.ts
|
|
4
|
-
type Properties<Target extends Element> = { [Property in keyof Target]?: Target[Property] extends Primitive ? Target[Property] : never };
|
|
3
|
+
type Properties<Target extends Element> = { [Property in keyof Target]?: Target[Property] extends Primitive ? Target[Property] : never; };
|
|
5
4
|
type Styles = Partial<Record<keyof CSSStyleDeclaration, unknown>>;
|
|
6
5
|
/**
|
|
7
6
|
* Creates an _HTML_ element with the specified tag name together with optional properties, attributes, and styles
|
package/dist/data.d.mts
CHANGED
package/dist/event/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { CustomEventListener, RemovableEventListener } from "../models.mjs";
|
|
2
2
|
import { EventPosition } from "@oscarpalmer/atoms/models";
|
|
3
|
-
|
|
4
3
|
//#region src/event/index.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Dispatch an event for a target
|
|
@@ -9,7 +8,9 @@ import { EventPosition } from "@oscarpalmer/atoms/models";
|
|
|
9
8
|
* @param type Type of event
|
|
10
9
|
* @param options Options for event _(bubbles and is cancelable by default)_
|
|
11
10
|
*/
|
|
12
|
-
declare function dispatch<Type extends keyof HTMLElementEventMap>(target: EventTarget, type: Type, options?:
|
|
11
|
+
declare function dispatch<Type extends keyof HTMLElementEventMap, Options extends CustomEventInit>(target: EventTarget, type: Type, options?: Options): Options extends {
|
|
12
|
+
detail: infer Detail;
|
|
13
|
+
} ? CustomEvent<Detail> : Event;
|
|
13
14
|
/**
|
|
14
15
|
* Dispatch an event for a target
|
|
15
16
|
*
|
|
@@ -17,7 +18,9 @@ declare function dispatch<Type extends keyof HTMLElementEventMap>(target: EventT
|
|
|
17
18
|
* @param type Type of event
|
|
18
19
|
* @param options Options for event _(bubbles and is cancelable by default)_
|
|
19
20
|
*/
|
|
20
|
-
declare function dispatch(target: EventTarget, type: string, options?:
|
|
21
|
+
declare function dispatch<Options extends CustomEventInit>(target: EventTarget, type: string, options?: Options): Options extends {
|
|
22
|
+
detail: infer Detail;
|
|
23
|
+
} ? CustomEvent<Detail> : Event;
|
|
21
24
|
/**
|
|
22
25
|
* Get the X- and Y-coordinates from a pointer event
|
|
23
26
|
*
|
package/dist/event/index.mjs
CHANGED
|
@@ -28,7 +28,10 @@ function createEventOptions(options) {
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
function dispatch(target, type, options) {
|
|
31
|
-
if (isEventTarget(target)
|
|
31
|
+
if (!isEventTarget(target) || typeof type !== "string") return;
|
|
32
|
+
const event = createEvent(type, options);
|
|
33
|
+
target.dispatchEvent(event);
|
|
34
|
+
return event;
|
|
32
35
|
}
|
|
33
36
|
/**
|
|
34
37
|
* Get the X- and Y-coordinates from a pointer event
|
package/dist/find/index.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Selector } from "../models.mjs";
|
|
2
2
|
import { findAncestor, findRelatives, getDistance } from "./relative.mjs";
|
|
3
3
|
import { EventPosition } from "@oscarpalmer/atoms/models";
|
|
4
|
-
|
|
5
4
|
//#region src/find/index.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* Find the first element that matches the tag name
|
package/dist/html/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { sanitizeNodes } from "./sanitize.mjs";
|
|
2
|
-
import { isPlainObject } from "@oscarpalmer/atoms/is";
|
|
3
2
|
import { getString } from "@oscarpalmer/atoms/string";
|
|
3
|
+
import { isPlainObject } from "@oscarpalmer/atoms/is";
|
|
4
4
|
import { SizedMap } from "@oscarpalmer/atoms/sized/map";
|
|
5
5
|
//#region src/html/index.ts
|
|
6
6
|
function createHtml(value) {
|
package/dist/index.d.mts
CHANGED
|
@@ -356,7 +356,9 @@ declare function setData(element: Element, key: string, value: unknown): void;
|
|
|
356
356
|
* @param type Type of event
|
|
357
357
|
* @param options Options for event _(bubbles and is cancelable by default)_
|
|
358
358
|
*/
|
|
359
|
-
declare function dispatch<Type extends keyof HTMLElementEventMap>(target: EventTarget, type: Type, options?:
|
|
359
|
+
declare function dispatch<Type extends keyof HTMLElementEventMap, Options extends CustomEventInit>(target: EventTarget, type: Type, options?: Options): Options extends {
|
|
360
|
+
detail: infer Detail;
|
|
361
|
+
} ? CustomEvent<Detail> : Event;
|
|
360
362
|
/**
|
|
361
363
|
* Dispatch an event for a target
|
|
362
364
|
*
|
|
@@ -364,7 +366,9 @@ declare function dispatch<Type extends keyof HTMLElementEventMap>(target: EventT
|
|
|
364
366
|
* @param type Type of event
|
|
365
367
|
* @param options Options for event _(bubbles and is cancelable by default)_
|
|
366
368
|
*/
|
|
367
|
-
declare function dispatch(target: EventTarget, type: string, options?:
|
|
369
|
+
declare function dispatch<Options extends CustomEventInit>(target: EventTarget, type: string, options?: Options): Options extends {
|
|
370
|
+
detail: infer Detail;
|
|
371
|
+
} ? CustomEvent<Detail> : Event;
|
|
368
372
|
/**
|
|
369
373
|
* Get the X- and Y-coordinates from a pointer event
|
|
370
374
|
*
|
package/dist/index.mjs
CHANGED
|
@@ -110,18 +110,6 @@ function words(value) {
|
|
|
110
110
|
}
|
|
111
111
|
const EXPRESSION_WORDS = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
|
|
112
112
|
//#endregion
|
|
113
|
-
//#region node_modules/@oscarpalmer/atoms/dist/is.mjs
|
|
114
|
-
/**
|
|
115
|
-
* Is the value `undefined`, `null`, or stringified as a whitespace-only string?
|
|
116
|
-
*
|
|
117
|
-
* @param value Value to check
|
|
118
|
-
* @returns `true` if the value is nullable or matches a whitespace-only string, otherwise `false`
|
|
119
|
-
*/
|
|
120
|
-
function isNullableOrWhitespace(value) {
|
|
121
|
-
return value == null || EXPRESSION_WHITESPACE$1.test(getString(value));
|
|
122
|
-
}
|
|
123
|
-
const EXPRESSION_WHITESPACE$1 = /^\s*$/;
|
|
124
|
-
//#endregion
|
|
125
113
|
//#region node_modules/@oscarpalmer/atoms/dist/string/index.mjs
|
|
126
114
|
/**
|
|
127
115
|
* Parse a JSON string into its proper value _(or `undefined` if it fails)_
|
|
@@ -621,7 +609,7 @@ function setElementValues(element, first, second, third, callback, style) {
|
|
|
621
609
|
}
|
|
622
610
|
}
|
|
623
611
|
function updateElementValue(element, key, value, set, remove, isBoolean, json) {
|
|
624
|
-
if (
|
|
612
|
+
if (value == null) remove.call(element, key);
|
|
625
613
|
else if (!ignoreSetAttribute(element, key)) set.call(element, key, json ? JSON.stringify(value) : getString(value));
|
|
626
614
|
}
|
|
627
615
|
const CSS_VARIABLE_PREFIX$1 = "--";
|
|
@@ -1061,7 +1049,10 @@ function createEventOptions(options) {
|
|
|
1061
1049
|
};
|
|
1062
1050
|
}
|
|
1063
1051
|
function dispatch(target, type, options) {
|
|
1064
|
-
if (isEventTarget(target)
|
|
1052
|
+
if (!isEventTarget(target) || typeof type !== "string") return;
|
|
1053
|
+
const event = createEvent(type, options);
|
|
1054
|
+
target.dispatchEvent(event);
|
|
1055
|
+
return event;
|
|
1065
1056
|
}
|
|
1066
1057
|
/**
|
|
1067
1058
|
* Get the X- and Y-coordinates from a pointer event
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { updateProperty } from "./property.mjs";
|
|
2
2
|
import { updateElementValue } from "./element-value.mjs";
|
|
3
|
-
import { isPlainObject } from "@oscarpalmer/atoms/is";
|
|
4
3
|
import { getString } from "@oscarpalmer/atoms/string";
|
|
5
4
|
import { kebabCase } from "@oscarpalmer/atoms/string/case";
|
|
5
|
+
import { isPlainObject } from "@oscarpalmer/atoms/is";
|
|
6
6
|
//#region src/internal/attribute.ts
|
|
7
7
|
function badAttributeHandler(name, value) {
|
|
8
8
|
if (typeof name !== "string" || name.trim().length === 0 || typeof value !== "string") return true;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isAttribute } from "./attribute.mjs";
|
|
2
|
-
import { isNullableOrWhitespace } from "@oscarpalmer/atoms/is";
|
|
3
2
|
import { getString } from "@oscarpalmer/atoms/string";
|
|
4
3
|
import { kebabCase } from "@oscarpalmer/atoms/string/case";
|
|
5
4
|
//#region src/internal/element-value.ts
|
|
@@ -35,7 +34,7 @@ function setElementValues(element, first, second, third, callback, style) {
|
|
|
35
34
|
}
|
|
36
35
|
}
|
|
37
36
|
function updateElementValue(element, key, value, set, remove, isBoolean, json) {
|
|
38
|
-
if (
|
|
37
|
+
if (value == null) remove.call(element, key);
|
|
39
38
|
else if (!ignoreSetAttribute(element, key)) set.call(element, key, json ? JSON.stringify(value) : getString(value));
|
|
40
39
|
}
|
|
41
40
|
const CSS_VARIABLE_PREFIX = "--";
|
package/dist/internal/is.d.mts
CHANGED
package/dist/is.d.mts
CHANGED
package/dist/models.d.mts
CHANGED
|
@@ -10,8 +10,8 @@ type AriaAttribute = keyof AriaAttributes;
|
|
|
10
10
|
*
|
|
11
11
|
* _(https://www.w3.org/TR/wai-aria-1.3/#aria-attributes)_
|
|
12
12
|
*/
|
|
13
|
-
type AriaAttributeUnprefixed = keyof { [Key in AriaAttribute as Key extends `aria-${infer Name}` ? Name : never]: string | null };
|
|
14
|
-
type AriaAttributes = { [Key in keyof ARIAMixin as NormalizedName<Key>]: string | null };
|
|
13
|
+
type AriaAttributeUnprefixed = keyof { [Key in AriaAttribute as Key extends `aria-${infer Name}` ? Name : never]: string | null; };
|
|
14
|
+
type AriaAttributes = { [Key in keyof ARIAMixin as NormalizedName<Key>]: string | null; };
|
|
15
15
|
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;
|
|
16
16
|
/**
|
|
17
17
|
* _ARIA_ role for an element
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Primitive } from "@oscarpalmer/atoms/models";
|
|
2
|
-
|
|
3
2
|
//#region src/property/get.property.d.ts
|
|
4
|
-
type GetProperties<Target extends Element> = { [Property in keyof Target as Target[Property] extends Primitive ? Property : never]?: Target[Property] };
|
|
3
|
+
type GetProperties<Target extends Element> = { [Property in keyof Target as Target[Property] extends Primitive ? Property : never]?: Target[Property]; };
|
|
5
4
|
/**
|
|
6
5
|
* Get the values of one or more properties on an element
|
|
7
6
|
*
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { DispatchedAttributeName } from "../attribute/set.attribute.mjs";
|
|
2
2
|
import { Primitive } from "@oscarpalmer/atoms/models";
|
|
3
|
-
|
|
4
3
|
//#region src/property/set.property.d.ts
|
|
5
4
|
type DispatchedPropertyValue<Target extends Element, Property extends DispatchedAttributeName> = Property extends keyof SetProperties<Target> ? SetProperties<Target>[Property] : never;
|
|
6
|
-
type SetProperties<Target extends Element> = { [Property in keyof Target as Target[Property] extends Primitive ? Property : never]?: Target[Property] };
|
|
5
|
+
type SetProperties<Target extends Element> = { [Property in keyof Target as Target[Property] extends Primitive ? Property : never]?: Target[Property]; };
|
|
7
6
|
/**
|
|
8
7
|
* Set the values of one or more properties on an element
|
|
9
8
|
*
|
package/dist/style.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { TextDirection } from "./models.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/style.d.ts
|
|
4
3
|
type CSSStyleValues = Variables & CSSStyleDeclaration;
|
|
5
4
|
type StyleToggler = {
|
|
@@ -13,7 +12,7 @@ type StyleToggler = {
|
|
|
13
12
|
remove(): void;
|
|
14
13
|
};
|
|
15
14
|
type Styles = Partial<Record<keyof CSSStyleValues, unknown>>;
|
|
16
|
-
type Variables<Value extends Record<string, string | undefined> = Record<string, string | undefined>> = { [property in keyof Value as `--${string & property}`]?: string | undefined };
|
|
15
|
+
type Variables<Value extends Record<string, string | undefined> = Record<string, string | undefined>> = { [property in keyof Value as `--${string & property}`]?: string | undefined; };
|
|
17
16
|
/**
|
|
18
17
|
* Get a style from an element
|
|
19
18
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oscarpalmer/toretto",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.48.0",
|
|
4
4
|
"description": "A collection of badass DOM utilities.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dom",
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"@oscarpalmer/atoms": "^0.188.1"
|
|
94
94
|
},
|
|
95
95
|
"devDependencies": {
|
|
96
|
-
"@oxlint/plugins": "^1.
|
|
96
|
+
"@oxlint/plugins": "^1.74",
|
|
97
97
|
"@types/node": "^26.1",
|
|
98
98
|
"@vitest/coverage-istanbul": "^4.1",
|
|
99
99
|
"jsdom": "^29.1",
|
package/src/event/index.ts
CHANGED
|
@@ -32,7 +32,7 @@ function createDispatchOptions(options: EventInit): EventInit {
|
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
function createEvent(type: string, options?: CustomEventInit): Event {
|
|
35
|
+
function createEvent(type: string, options?: CustomEventInit): CustomEvent | Event {
|
|
36
36
|
const hasOptions = isPlainObject(options);
|
|
37
37
|
|
|
38
38
|
if (hasOptions && 'detail' in (options as CustomEventInit)) {
|
|
@@ -61,11 +61,11 @@ function createEventOptions(options?: AddEventListenerOptions): EventOptions {
|
|
|
61
61
|
* @param type Type of event
|
|
62
62
|
* @param options Options for event _(bubbles and is cancelable by default)_
|
|
63
63
|
*/
|
|
64
|
-
export function dispatch<Type extends keyof HTMLElementEventMap>(
|
|
64
|
+
export function dispatch<Type extends keyof HTMLElementEventMap, Options extends CustomEventInit>(
|
|
65
65
|
target: EventTarget,
|
|
66
66
|
type: Type,
|
|
67
|
-
options?:
|
|
68
|
-
):
|
|
67
|
+
options?: Options,
|
|
68
|
+
): Options extends {detail: infer Detail} ? CustomEvent<Detail> : Event;
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* Dispatch an event for a target
|
|
@@ -74,16 +74,26 @@ export function dispatch<Type extends keyof HTMLElementEventMap>(
|
|
|
74
74
|
* @param type Type of event
|
|
75
75
|
* @param options Options for event _(bubbles and is cancelable by default)_
|
|
76
76
|
*/
|
|
77
|
-
export function dispatch
|
|
77
|
+
export function dispatch<Options extends CustomEventInit>(
|
|
78
|
+
target: EventTarget,
|
|
79
|
+
type: string,
|
|
80
|
+
options?: Options,
|
|
81
|
+
): Options extends {detail: infer Detail} ? CustomEvent<Detail> : Event;
|
|
78
82
|
|
|
79
83
|
export function dispatch<Type extends keyof HTMLElementEventMap>(
|
|
80
84
|
target: EventTarget,
|
|
81
85
|
type: Type | string,
|
|
82
86
|
options?: CustomEventInit,
|
|
83
|
-
):
|
|
84
|
-
if (isEventTarget(target)
|
|
85
|
-
|
|
87
|
+
): CustomEvent | Event | undefined {
|
|
88
|
+
if (!isEventTarget(target) || typeof type !== 'string') {
|
|
89
|
+
return;
|
|
86
90
|
}
|
|
91
|
+
|
|
92
|
+
const event = createEvent(type, options);
|
|
93
|
+
|
|
94
|
+
target.dispatchEvent(event);
|
|
95
|
+
|
|
96
|
+
return event;
|
|
87
97
|
}
|
|
88
98
|
|
|
89
99
|
/**
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {isNullableOrWhitespace} from '@oscarpalmer/atoms/is';
|
|
2
1
|
import {getString} from '@oscarpalmer/atoms/string';
|
|
3
2
|
import {kebabCase} from '@oscarpalmer/atoms/string/case';
|
|
4
3
|
import {isAttribute} from './attribute';
|
|
@@ -83,7 +82,7 @@ export function updateElementValue(
|
|
|
83
82
|
isBoolean: boolean,
|
|
84
83
|
json: boolean,
|
|
85
84
|
): void {
|
|
86
|
-
if (
|
|
85
|
+
if (value == null) {
|
|
87
86
|
remove.call(element, key);
|
|
88
87
|
} else if (!ignoreSetAttribute(element, key)) {
|
|
89
88
|
set.call(element, key, json ? JSON.stringify(value) : getString(value));
|