@oscarpalmer/toretto 0.41.0 → 0.42.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.
Files changed (55) hide show
  1. package/dist/attribute/{get.d.mts → get.attribute.d.mts} +3 -2
  2. package/dist/attribute/{get.mjs → get.attribute.mjs} +4 -3
  3. package/dist/attribute/index.d.mts +3 -16
  4. package/dist/attribute/index.mjs +4 -7
  5. package/dist/attribute/{set.d.mts → set.attribute.d.mts} +4 -4
  6. package/dist/attribute/{set.mjs → set.attribute.mjs} +2 -2
  7. package/dist/create.d.mts +25 -0
  8. package/dist/create.mjs +17 -0
  9. package/dist/data.mjs +7 -7
  10. package/dist/event/delegation.mjs +8 -1
  11. package/dist/html/index.d.mts +23 -26
  12. package/dist/html/index.mjs +85 -18
  13. package/dist/html/sanitize.mjs +6 -5
  14. package/dist/index.d.mts +113 -52
  15. package/dist/index.mjs +510 -361
  16. package/dist/internal/attribute.d.mts +4 -3
  17. package/dist/internal/attribute.mjs +13 -23
  18. package/dist/internal/element-value.d.mts +2 -2
  19. package/dist/internal/element-value.mjs +4 -2
  20. package/dist/internal/get-value.mjs +1 -1
  21. package/dist/internal/property.d.mts +4 -0
  22. package/dist/internal/property.mjs +21 -0
  23. package/dist/property/get.property.d.mts +20 -0
  24. package/dist/property/get.property.mjs +35 -0
  25. package/dist/property/index.d.mts +3 -0
  26. package/dist/property/index.mjs +3 -0
  27. package/dist/property/set.property.d.mts +32 -0
  28. package/dist/property/set.property.mjs +34 -0
  29. package/dist/style.d.mts +12 -7
  30. package/dist/style.mjs +14 -18
  31. package/package.json +12 -5
  32. package/src/attribute/{get.ts → get.attribute.ts} +14 -3
  33. package/src/attribute/index.ts +10 -22
  34. package/src/attribute/{set.ts → set.attribute.ts} +9 -5
  35. package/src/create.ts +81 -0
  36. package/src/data.ts +16 -8
  37. package/src/event/delegation.ts +24 -3
  38. package/src/event/index.ts +9 -3
  39. package/src/find/index.ts +11 -3
  40. package/src/find/relative.ts +4 -0
  41. package/src/focusable.ts +10 -2
  42. package/src/html/index.ts +166 -58
  43. package/src/html/sanitize.ts +14 -11
  44. package/src/index.ts +2 -1
  45. package/src/internal/attribute.ts +23 -42
  46. package/src/internal/element-value.ts +11 -4
  47. package/src/internal/get-value.ts +8 -0
  48. package/src/internal/is.ts +4 -0
  49. package/src/internal/property.ts +42 -0
  50. package/src/is.ts +10 -2
  51. package/src/property/get.property.ts +73 -0
  52. package/src/property/index.ts +2 -0
  53. package/src/property/set.property.ts +102 -0
  54. package/src/style.ts +52 -27
  55. package/src/touch.ts +14 -2
package/dist/index.d.mts CHANGED
@@ -56,7 +56,8 @@ type TextDirection = 'ltr' | 'rtl';
56
56
  */
57
57
  declare const booleanAttributes: readonly string[];
58
58
  //#endregion
59
- //#region src/attribute/get.d.ts
59
+ //#region src/attribute/get.attribute.d.ts
60
+ type DataPrefixedName = `data-${string}`;
60
61
  /**
61
62
  * Get the value of a specific attribute from an element
62
63
  * @param element Element to get attribute from
@@ -64,7 +65,7 @@ declare const booleanAttributes: readonly string[];
64
65
  * @param parse Parse value? _(defaults to `true`)_
65
66
  * @returns Attribute value _(or `undefined`)_
66
67
  */
67
- declare function getAttribute(element: Element, name: `data-${string}`, parse?: boolean): unknown;
68
+ declare function getAttribute(element: Element, name: DataPrefixedName, parse?: boolean): unknown;
68
69
  /**
69
70
  * Get the value of a specific attribute from an element
70
71
  * @param element Element to get attribute from
@@ -81,8 +82,8 @@ declare function getAttribute(element: Element, name: string): unknown;
81
82
  */
82
83
  declare function getAttributes<Key extends string>(element: Element, names: Key[], parseData?: boolean): Record<Key, unknown>;
83
84
  //#endregion
84
- //#region src/attribute/set.d.ts
85
- type DispatchedAttribute = 'checked' | 'open' | 'value';
85
+ //#region src/attribute/set.attribute.d.ts
86
+ type DispatchedAttributeName = 'checked' | 'open' | 'value';
86
87
  /**
87
88
  * Set an attribute on an element
88
89
  *
@@ -92,7 +93,7 @@ type DispatchedAttribute = 'checked' | 'open' | 'value';
92
93
  * @param value Attribute value
93
94
  * @param dispatch Dispatch event for attribute? _(defaults to `true`)_
94
95
  */
95
- declare function setAttribute<Name extends DispatchedAttribute>(element: Element, name: Name, value?: unknown, dispatch?: boolean): void;
96
+ declare function setAttribute(element: Element, name: DispatchedAttributeName, value?: unknown, dispatch?: boolean): void;
96
97
  /**
97
98
  * Set an attribute on an element
98
99
  *
@@ -156,19 +157,6 @@ declare function isBooleanAttribute(attribute: Attr | Attribute): boolean;
156
157
  * @returns `true` if attribute is a boolean attribute
157
158
  */
158
159
  declare function isBooleanAttribute(name: string): boolean;
159
- /**
160
- * Is the attribute empty and not a boolean attribute?
161
- * @param attribute Attribute to check
162
- * @returns `true` if attribute is empty and not a boolean attribute
163
- */
164
- declare function isEmptyNonBooleanAttribute(attribute: Attr | Attribute): boolean;
165
- /**
166
- * Is the attribute empty and not a boolean attribute?
167
- * @param name Attribute name
168
- * @param value Attribute value
169
- * @returns `true` if attribute is empty and not a boolean attribute
170
- */
171
- declare function isEmptyNonBooleanAttribute(name: string, value: string): boolean;
172
160
  /**
173
161
  * Is the attribute an invalid boolean attribute?
174
162
  *
@@ -197,6 +185,32 @@ type PlainObject = Record<PropertyKey, unknown>;
197
185
  *
198
186
  * _(Thanks, type-fest!)_
199
187
  */
188
+ type Primitive = null | undefined | string | number | boolean | symbol | bigint;
189
+ /**
190
+ * Set required keys for a type
191
+ */
192
+ //#endregion
193
+ //#region src/create.d.ts
194
+ type Properties<Target extends Element> = { [Property in keyof Target]?: Target[Property] extends Primitive ? Target[Property] : never };
195
+ type Styles$1 = Partial<Record<keyof CSSStyleDeclaration, unknown>>;
196
+ /**
197
+ * Creates an HTML element with the specified tag name together with optional properties, attributes, and styles
198
+ * @param tag Tag name
199
+ * @param properties Element properties
200
+ * @param attributes Element attributes
201
+ * @param styles Element styles
202
+ * @returns Created element
203
+ */
204
+ declare function createElement<TagName extends keyof HTMLElementTagNameMap>(tag: TagName, properties?: Properties<HTMLElementTagNameMap[TagName]>, attributes?: Record<string, unknown>, styles?: Styles$1): HTMLElementTagNameMap[TagName];
205
+ /**
206
+ * Creates an HTML element with the specified tag name together with optional properties, attributes, and styles
207
+ * @param tag Tag name
208
+ * @param properties Element properties
209
+ * @param attributes Element attributes
210
+ * @param styles Element styles
211
+ * @returns Created element
212
+ */
213
+ declare function createElement(tag: string, properties?: Properties<HTMLElement>, attributes?: Record<string, unknown>, styles?: Styles$1): HTMLUnknownElement;
200
214
  //#endregion
201
215
  //#region src/data.d.ts
202
216
  /**
@@ -398,38 +412,35 @@ declare function isFocusable(element: Element): boolean;
398
412
  declare function isTabbable(element: Element): boolean;
399
413
  //#endregion
400
414
  //#region src/html/index.d.ts
401
- type Html = {
402
- /**
403
- * Create nodes from an HTML string or a template element
404
- * @param value HTML string or id for a template element
405
- * @param options Options for creating nodes
406
- * @returns Created nodes
407
- */
408
- (value: string, options?: HtmlOptions): Node[];
409
- /**
410
- * Create nodes from a template element
411
- * @param template Template element
412
- * @param options Options for creating nodes
413
- * @returns Created nodes
414
- */
415
- (template: HTMLTemplateElement, options?: HtmlOptions): Node[];
416
- /**
417
- * Clear cache of template elements
418
- */
419
- clear(): void;
420
- /**
421
- * Remove cached template element for an HTML string or id
422
- * @param template HTML string or id for a template element
423
- */
424
- remove(template: string): void;
425
- };
426
415
  type HtmlOptions = {
427
416
  /**
428
417
  * Cache template element for the HTML string? _(defaults to `true`)_
429
418
  */
430
419
  cache?: boolean;
431
420
  };
432
- declare const html: Html;
421
+ /**
422
+ * Create nodes from a template string
423
+ * @returns Created nodes
424
+ */
425
+ declare function html(strings: TemplateStringsArray, ...values: unknown[]): Node[];
426
+ /**
427
+ * Create nodes from an HTML string or a template element
428
+ * @param value HTML string or id for a template element
429
+ * @param options Options for creating nodes
430
+ * @returns Created nodes
431
+ */
432
+ declare function html(value: string, options?: HtmlOptions): Node[];
433
+ /**
434
+ * Create nodes from a template element
435
+ * @param template Template element
436
+ * @param options Options for creating nodes
437
+ * @returns Created nodes
438
+ */
439
+ declare function html(template: HTMLTemplateElement, options?: HtmlOptions): Node[];
440
+ declare namespace html {
441
+ var clear: () => void;
442
+ var remove: (template: string) => void;
443
+ }
433
444
  /**
434
445
  * Sanitize one or more nodes, recursively
435
446
  * @param value Node or nodes to sanitize
@@ -473,6 +484,51 @@ declare function isInDocument(node: Node): boolean;
473
484
  */
474
485
  declare function isInDocument(node: Node, document: Document): boolean;
475
486
  //#endregion
487
+ //#region src/property/get.property.d.ts
488
+ type GetProperties<Target extends Element> = { [Property in keyof Target as Target[Property] extends Primitive ? Property : never]?: Target[Property] };
489
+ /**
490
+ * Get the values of one or more properties on an element
491
+ * @param target Target element
492
+ * @param properties Properties to get
493
+ * @returns Property values
494
+ */
495
+ declare function getProperties<Target extends Element, Property extends keyof GetProperties<Target>>(target: Target, properties: Property[]): Pick<GetProperties<Target>, Property>;
496
+ /**
497
+ * Get the value of a property on an element
498
+ * @param target Target element
499
+ * @param property Property to get
500
+ * @returns Property value
501
+ */
502
+ declare function getProperty<Target extends Element, Property extends keyof GetProperties<Target>>(target: Target, property: Property): GetProperties<Target>[Property];
503
+ //#endregion
504
+ //#region src/property/set.property.d.ts
505
+ type DispatchedPropertyValue<Target extends Element, Property extends DispatchedAttributeName> = Property extends keyof SetProperties<Target> ? SetProperties<Target>[Property] : never;
506
+ type SetProperties<Target extends Element> = { [Property in keyof Target as Target[Property] extends Primitive ? Property : never]?: Target[Property] };
507
+ /**
508
+ * Set the values of one or more properties on an element
509
+ *
510
+ * Also updates attributes for boolean/dispatchable properties, and if `dispatch` is `true`, will dispatch events for dispatchable properties
511
+ * @param target Target element
512
+ * @param properties Properties to set
513
+ * @param dispatch Dispatch events for properties? _(defaults to `true`)_
514
+ */
515
+ declare function setProperties<Target extends Element>(target: Target, properties: SetProperties<Target>, dispatch?: boolean): void;
516
+ /**
517
+ * Set the value for a dispatchable property on an element
518
+ * @param target Target element
519
+ * @param property Property to set
520
+ * @param value Value to set
521
+ * @param dispatch Dispatch event for property? _(defaults to `true`)_
522
+ */
523
+ declare function setProperty<Target extends Element, Property extends DispatchedAttributeName>(target: Target, property: Property, value: DispatchedPropertyValue<Target, Property>, dispatch?: boolean): void;
524
+ /**
525
+ * Set the value for a property on an element
526
+ * @param target Target element
527
+ * @param property Property to set
528
+ * @param value Value to set
529
+ */
530
+ declare function setProperty<Target extends Element, Property extends keyof SetProperties<Target>>(target: Target, property: Property, value: SetProperties<Target>[Property]): void;
531
+ //#endregion
476
532
  //#region src/style.d.ts
477
533
  type StyleToggler = {
478
534
  /**
@@ -484,6 +540,7 @@ type StyleToggler = {
484
540
  */
485
541
  remove(): void;
486
542
  };
543
+ type Styles = Partial<Record<keyof CSSStyleDeclaration, unknown>>;
487
544
  /**
488
545
  * Get a style from an element
489
546
  * @param element Element to get the style from
@@ -501,31 +558,35 @@ declare function getStyle(element: Element, property: keyof CSSStyleDeclaration,
501
558
  */
502
559
  declare function getStyles<Property extends keyof CSSStyleDeclaration>(element: Element, properties: Property[], computed?: boolean): Record<Property, string | undefined>;
503
560
  /**
504
- * Get the text direction of an element
505
- * @param element Element to get the text direction from
506
- * @param computed Get the computed text direction? _(defaults to `false`)_
561
+ * Get the text direction of a node or element _(or document, if element is invalid)_
562
+ * @param node Node or element to get the text direction from
563
+ * @returns Text direction
564
+ */
565
+ declare function getTextDirection(node: Element | Node): TextDirection;
566
+ /**
567
+ * Get the text direction of the document
507
568
  * @returns Text direction
508
569
  */
509
- declare function getTextDirection(element: Element, computed?: boolean): TextDirection;
570
+ declare function getTextDirection(): TextDirection;
510
571
  /**
511
572
  * Set a style on an element
512
573
  * @param element Element to set the style on
513
574
  * @param property Style name
514
575
  * @param value Style value
515
576
  */
516
- declare function setStyle(element: Element, property: keyof CSSStyleDeclaration, value?: string): void;
577
+ declare function setStyle(element: Element, property: keyof CSSStyleDeclaration, value?: unknown): void;
517
578
  /**
518
579
  * Set styles on an element
519
580
  * @param element Element to set the styles on
520
581
  * @param styles Styles to set
521
582
  */
522
- declare function setStyles(element: Element, styles: Partial<CSSStyleDeclaration>): void;
583
+ declare function setStyles(element: Element, styles: Styles): void;
523
584
  /**
524
585
  * Toggle styles for an element
525
586
  * @param element Element to style
526
587
  * @param styles Styles to be set or removed
527
588
  * @returns Style toggler
528
589
  */
529
- declare function toggleStyles(element: Element, styles: Partial<CSSStyleDeclaration>): StyleToggler;
590
+ declare function toggleStyles(element: Element, styles: Styles): StyleToggler;
530
591
  //#endregion
531
- export { findElement as $, findElement, findElements as $$, findElements, Attribute, CustomEventListener, EventPosition, RemovableEventListener, Selector, StyleToggler, TextDirection, booleanAttributes, dispatch, findAncestor, findRelatives, getAttribute, getAttributes, getData, getDistance, getElementUnderPointer, getFocusable, getPosition, getStyle, getStyles, getTabbable, getTextDirection, html, isBadAttribute, isBooleanAttribute, isChildNode, isEmptyNonBooleanAttribute, isEventTarget, isFocusable, isHTMLOrSVGElement, isInDocument, isInvalidBooleanAttribute, isTabbable, off, on, sanitize, setAttribute, setAttributes, setData, setStyle, setStyles, supportsTouch, toggleStyles };
592
+ export { findElement as $, findElement, findElements as $$, findElements, Attribute, CustomEventListener, EventPosition, RemovableEventListener, Selector, StyleToggler, TextDirection, booleanAttributes, createElement, dispatch, findAncestor, findRelatives, getAttribute, getAttributes, getData, getDistance, getElementUnderPointer, getFocusable, getPosition, getProperties, getProperty, getStyle, getStyles, getTabbable, getTextDirection, html, isBadAttribute, isBooleanAttribute, isChildNode, isEventTarget, isFocusable, isHTMLOrSVGElement, isInDocument, isInvalidBooleanAttribute, isTabbable, off, on, sanitize, setAttribute, setAttributes, setData, setProperties, setProperty, setStyle, setStyles, supportsTouch, toggleStyles };