@oscarpalmer/toretto 0.41.0 → 0.43.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.d.mts → get.attribute.d.mts} +3 -2
- package/dist/attribute/{get.mjs → get.attribute.mjs} +4 -3
- package/dist/attribute/index.d.mts +3 -16
- package/dist/attribute/index.mjs +4 -7
- package/dist/attribute/{set.d.mts → set.attribute.d.mts} +4 -4
- package/dist/attribute/{set.mjs → set.attribute.mjs} +2 -2
- package/dist/create.d.mts +25 -0
- package/dist/create.mjs +17 -0
- package/dist/data.mjs +7 -7
- package/dist/event/delegation.mjs +8 -1
- package/dist/html/index.d.mts +23 -26
- package/dist/html/index.mjs +85 -18
- package/dist/html/sanitize.mjs +6 -5
- package/dist/index.d.mts +117 -54
- package/dist/index.mjs +541 -380
- package/dist/internal/attribute.d.mts +4 -3
- package/dist/internal/attribute.mjs +13 -23
- package/dist/internal/element-value.d.mts +2 -2
- package/dist/internal/element-value.mjs +12 -6
- package/dist/internal/get-value.mjs +3 -1
- package/dist/internal/property.d.mts +4 -0
- package/dist/internal/property.mjs +24 -0
- package/dist/property/get.property.d.mts +20 -0
- package/dist/property/get.property.mjs +35 -0
- package/dist/property/index.d.mts +3 -0
- package/dist/property/index.mjs +3 -0
- package/dist/property/set.property.d.mts +32 -0
- package/dist/property/set.property.mjs +32 -0
- package/dist/style.d.mts +16 -9
- package/dist/style.mjs +22 -21
- package/package.json +14 -6
- package/src/attribute/{get.ts → get.attribute.ts} +14 -3
- package/src/attribute/index.ts +10 -22
- package/src/attribute/{set.ts → set.attribute.ts} +9 -5
- package/src/create.ts +81 -0
- package/src/data.ts +16 -8
- package/src/event/delegation.ts +24 -3
- package/src/event/index.ts +9 -3
- package/src/find/index.ts +11 -3
- package/src/find/relative.ts +4 -0
- package/src/focusable.ts +10 -2
- package/src/html/index.ts +166 -58
- package/src/html/sanitize.ts +14 -11
- package/src/index.ts +2 -1
- package/src/internal/attribute.ts +23 -42
- package/src/internal/element-value.ts +25 -6
- package/src/internal/get-value.ts +14 -0
- package/src/internal/is.ts +4 -0
- package/src/internal/property.ts +42 -0
- package/src/is.ts +10 -2
- package/src/property/get.property.ts +73 -0
- package/src/property/index.ts +2 -0
- package/src/property/set.property.ts +103 -0
- package/src/style.ts +81 -36
- 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:
|
|
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
|
|
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
|
|
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
|
-
|
|
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,7 +484,53 @@ 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
|
|
533
|
+
type CSSStyleValues = Variables & CSSStyleDeclaration;
|
|
477
534
|
type StyleToggler = {
|
|
478
535
|
/**
|
|
479
536
|
* Set the provided styles on the element
|
|
@@ -484,6 +541,8 @@ type StyleToggler = {
|
|
|
484
541
|
*/
|
|
485
542
|
remove(): void;
|
|
486
543
|
};
|
|
544
|
+
type Styles = Partial<Record<keyof CSSStyleValues, unknown>>;
|
|
545
|
+
type Variables<Value extends Record<string, string | undefined> = Record<string, string | undefined>> = { [property in keyof Value as `--${string & property}`]?: string | undefined };
|
|
487
546
|
/**
|
|
488
547
|
* Get a style from an element
|
|
489
548
|
* @param element Element to get the style from
|
|
@@ -491,7 +550,7 @@ type StyleToggler = {
|
|
|
491
550
|
* @param computed Get the computed style? _(defaults to `false`)_
|
|
492
551
|
* @returns Style value
|
|
493
552
|
*/
|
|
494
|
-
declare function getStyle(element: Element, property: keyof
|
|
553
|
+
declare function getStyle(element: Element, property: keyof CSSStyleValues, computed?: boolean): string | undefined;
|
|
495
554
|
/**
|
|
496
555
|
* Get styles from an element
|
|
497
556
|
* @param element Element to get the styles from
|
|
@@ -499,33 +558,37 @@ declare function getStyle(element: Element, property: keyof CSSStyleDeclaration,
|
|
|
499
558
|
* @param computed Get the computed styles? _(defaults to `false`)_
|
|
500
559
|
* @returns Style values
|
|
501
560
|
*/
|
|
502
|
-
declare function getStyles<Property extends keyof
|
|
561
|
+
declare function getStyles<Property extends keyof CSSStyleValues>(element: Element, properties: Property[], computed?: boolean): Record<Property, string | undefined>;
|
|
562
|
+
/**
|
|
563
|
+
* Get the text direction of a node or element _(or document, if element is invalid)_
|
|
564
|
+
* @param node Node or element to get the text direction from
|
|
565
|
+
* @returns Text direction
|
|
566
|
+
*/
|
|
567
|
+
declare function getTextDirection(node: Element | Node): TextDirection;
|
|
503
568
|
/**
|
|
504
|
-
* Get the text direction of
|
|
505
|
-
* @param element Element to get the text direction from
|
|
506
|
-
* @param computed Get the computed text direction? _(defaults to `false`)_
|
|
569
|
+
* Get the text direction of the document
|
|
507
570
|
* @returns Text direction
|
|
508
571
|
*/
|
|
509
|
-
declare function getTextDirection(
|
|
572
|
+
declare function getTextDirection(): TextDirection;
|
|
510
573
|
/**
|
|
511
574
|
* Set a style on an element
|
|
512
575
|
* @param element Element to set the style on
|
|
513
576
|
* @param property Style name
|
|
514
577
|
* @param value Style value
|
|
515
578
|
*/
|
|
516
|
-
declare function setStyle(element: Element, property: keyof
|
|
579
|
+
declare function setStyle(element: Element, property: keyof CSSStyleValues, value?: unknown): void;
|
|
517
580
|
/**
|
|
518
581
|
* Set styles on an element
|
|
519
582
|
* @param element Element to set the styles on
|
|
520
583
|
* @param styles Styles to set
|
|
521
584
|
*/
|
|
522
|
-
declare function setStyles(element: Element, styles:
|
|
585
|
+
declare function setStyles(element: Element, styles: Styles): void;
|
|
523
586
|
/**
|
|
524
587
|
* Toggle styles for an element
|
|
525
588
|
* @param element Element to style
|
|
526
589
|
* @param styles Styles to be set or removed
|
|
527
590
|
* @returns Style toggler
|
|
528
591
|
*/
|
|
529
|
-
declare function toggleStyles(element: Element, styles:
|
|
592
|
+
declare function toggleStyles(element: Element, styles: Styles): StyleToggler;
|
|
530
593
|
//#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,
|
|
594
|
+
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 };
|