@oscarpalmer/toretto 0.47.3 → 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 CHANGED
@@ -1,5 +1,4 @@
1
1
  import { AriaAttribute, AriaAttributeUnprefixed, AriaRole } from "./models.mjs";
2
-
3
2
  //#region src/aria.d.ts
4
3
  type AnyAriaAttribute = AriaAttribute | AriaAttributeUnprefixed;
5
4
  type AriaAttributeItem = {
@@ -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?
@@ -1,5 +1,4 @@
1
1
  import { Attribute } from "../models.mjs";
2
-
3
2
  //#region src/attribute/set.attribute.d.ts
4
3
  type DispatchedAttributeName = 'checked' | 'open' | 'value';
5
4
  /**
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
@@ -1,5 +1,4 @@
1
1
  import { PlainObject } from "@oscarpalmer/atoms/models";
2
-
3
2
  //#region src/data.d.ts
4
3
  /**
5
4
  * Get a keyed data value from an element
@@ -1,5 +1,4 @@
1
1
  import { CustomEventListener, RemovableEventListener } from "../models.mjs";
2
-
3
2
  //#region src/event/delegation.d.ts
4
3
  type EventTargetWithListeners = EventTarget & Partial<{
5
4
  [key: string]: Set<EventListener | CustomEventListener>;
@@ -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?: CustomEventInit): void;
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?: CustomEventInit): void;
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
  *
@@ -28,7 +28,10 @@ function createEventOptions(options) {
28
28
  };
29
29
  }
30
30
  function dispatch(target, type, options) {
31
- if (isEventTarget(target) && typeof type === "string") target.dispatchEvent(createEvent(type, options));
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
@@ -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/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?: CustomEventInit): void;
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?: CustomEventInit): void;
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
@@ -1049,7 +1049,10 @@ function createEventOptions(options) {
1049
1049
  };
1050
1050
  }
1051
1051
  function dispatch(target, type, options) {
1052
- if (isEventTarget(target) && typeof type === "string") target.dispatchEvent(createEvent(type, options));
1052
+ if (!isEventTarget(target) || typeof type !== "string") return;
1053
+ const event = createEvent(type, options);
1054
+ target.dispatchEvent(event);
1055
+ return event;
1053
1056
  }
1054
1057
  /**
1055
1058
  * Get the X- and Y-coordinates from a pointer event
@@ -1,5 +1,4 @@
1
1
  import { Attribute } from "../models.mjs";
2
-
3
2
  //#region src/internal/attribute.d.ts
4
3
  declare function isAttribute(value: unknown): value is Attr | Attribute;
5
4
  declare function _isBadAttribute(first: unknown, second: unknown, decode: boolean): boolean;
@@ -1,5 +1,4 @@
1
1
  import { EventPosition } from "@oscarpalmer/atoms/models";
2
-
3
2
  //#region src/internal/is.d.ts
4
3
  /**
5
4
  * Is the value an event position?
package/dist/is.d.mts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { isEventPosition, isEventTarget, isHTMLOrSVGElement, isInputElement } from "./internal/is.mjs";
2
-
3
2
  //#region src/is.d.ts
4
3
  /**
5
4
  * Is the value a child node?
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.47.3",
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.73",
96
+ "@oxlint/plugins": "^1.74",
97
97
  "@types/node": "^26.1",
98
98
  "@vitest/coverage-istanbul": "^4.1",
99
99
  "jsdom": "^29.1",
@@ -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?: CustomEventInit,
68
- ): void;
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(target: EventTarget, type: string, options?: CustomEventInit): void;
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
- ): void {
84
- if (isEventTarget(target) && typeof type === 'string') {
85
- target.dispatchEvent(createEvent(type, options));
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
  /**