@oscarpalmer/toretto 0.30.1 → 0.32.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 (42) hide show
  1. package/dist/attribute/index.js +5 -5
  2. package/dist/event/delegation.js +21 -28
  3. package/dist/event/index.js +1 -1
  4. package/dist/find/index.js +3 -3
  5. package/dist/find/relative.js +22 -22
  6. package/dist/html/index.js +11 -8
  7. package/dist/html/sanitize.js +29 -14
  8. package/dist/index.js +2 -2
  9. package/dist/internal/attribute.js +5 -5
  10. package/dist/is.js +3 -3
  11. package/dist/style.js +2 -2
  12. package/dist/toretto.full.js +125 -264
  13. package/package.json +6 -6
  14. package/src/attribute/get.ts +4 -12
  15. package/src/attribute/index.ts +5 -5
  16. package/src/attribute/set.ts +13 -13
  17. package/src/data.ts +7 -16
  18. package/src/event/delegation.ts +24 -52
  19. package/src/event/index.ts +1 -7
  20. package/src/find/index.ts +2 -2
  21. package/src/find/relative.ts +43 -49
  22. package/src/html/index.ts +13 -12
  23. package/src/html/sanitize.ts +58 -31
  24. package/src/internal/attribute.ts +9 -9
  25. package/src/internal/element-value.ts +3 -4
  26. package/src/internal/get-value.ts +5 -8
  27. package/src/internal/is.ts +1 -3
  28. package/src/is.ts +4 -4
  29. package/src/models.ts +0 -5
  30. package/src/style.ts +12 -15
  31. package/types/attribute/get.d.ts +3 -3
  32. package/types/attribute/set.d.ts +9 -9
  33. package/types/data.d.ts +4 -5
  34. package/types/event/delegation.d.ts +1 -1
  35. package/types/find/index.d.ts +1 -1
  36. package/types/find/relative.d.ts +8 -2
  37. package/types/internal/attribute.d.ts +7 -7
  38. package/types/internal/element-value.d.ts +2 -3
  39. package/types/internal/get-value.d.ts +2 -3
  40. package/types/internal/is.d.ts +1 -2
  41. package/types/models.d.ts +0 -4
  42. package/types/style.d.ts +7 -7
@@ -1,27 +1,20 @@
1
+ import {setAttribute} from '../attribute/set';
1
2
  import {
2
- isBadAttribute,
3
- isEmptyNonBooleanAttribute,
4
- isInvalidBooleanAttribute,
3
+ _isBadAttribute,
4
+ _isEmptyNonBooleanAttribute,
5
+ _isInvalidBooleanAttribute,
5
6
  } from '../internal/attribute';
6
7
 
7
- function handleElement(element: Element, depth: number): boolean {
8
- if (isClobbered(element)) {
9
- element.remove();
10
-
11
- return true;
12
- }
13
-
8
+ function handleElement(element: Element, depth: number): void {
14
9
  if (depth === 0) {
15
- const scripts = element.querySelectorAll('script');
10
+ const removable = element.querySelectorAll(REMOVE_SELECTOR);
16
11
 
17
- for (const script of scripts) {
18
- script.remove();
12
+ for (const item of removable) {
13
+ item.remove();
19
14
  }
20
15
  }
21
16
 
22
17
  sanitizeAttributes(element, [...element.attributes]);
23
-
24
- return false;
25
18
  }
26
19
 
27
20
  /**
@@ -29,47 +22,75 @@ function handleElement(element: Element, depth: number): boolean {
29
22
  *
30
23
  * Thanks, DOMPurify _(https://github.com/cure53/DOMPurify)_
31
24
  */
32
- function isClobbered(element: Element): boolean {
25
+ function isClobbered(value: unknown): boolean {
33
26
  return (
34
- element instanceof HTMLFormElement &&
35
- (typeof element.nodeName !== 'string' ||
36
- typeof element.textContent !== 'string' ||
37
- typeof element.removeChild !== 'function' ||
38
- !(element.attributes instanceof NamedNodeMap) ||
39
- typeof element.removeAttribute !== 'function' ||
40
- typeof element.setAttribute !== 'function' ||
41
- typeof element.namespaceURI !== 'string' ||
42
- typeof element.insertBefore !== 'function' ||
43
- typeof element.hasChildNodes !== 'function')
27
+ value instanceof HTMLFormElement &&
28
+ (typeof value.nodeName !== 'string' ||
29
+ typeof value.textContent !== 'string' ||
30
+ typeof value.removeChild !== 'function' ||
31
+ !(value.attributes instanceof NamedNodeMap) ||
32
+ typeof value.removeAttribute !== 'function' ||
33
+ typeof value.setAttribute !== 'function' ||
34
+ typeof value.namespaceURI !== 'string' ||
35
+ typeof value.insertBefore !== 'function' ||
36
+ typeof value.hasChildNodes !== 'function')
44
37
  );
45
38
  }
46
39
 
40
+ function removeNode(node: Node): void {
41
+ if (typeof (node as ChildNode).remove === 'function') {
42
+ (node as ChildNode).remove();
43
+ }
44
+ }
45
+
47
46
  export function sanitizeAttributes(element: Element, attributes: Attr[]): void {
48
47
  const {length} = attributes;
49
48
 
50
49
  for (let index = 0; index < length; index += 1) {
51
50
  const {name, value} = attributes[index];
52
51
 
53
- if (isBadAttribute(name, value, false) || isEmptyNonBooleanAttribute(name, value, false)) {
52
+ if (_isBadAttribute(name, value, false) || _isEmptyNonBooleanAttribute(name, value, false)) {
54
53
  element.removeAttribute(name);
55
- } else if (isInvalidBooleanAttribute(name, value, false)) {
56
- element.setAttribute(name, '');
54
+ } else if (_isInvalidBooleanAttribute(name, value, false)) {
55
+ setAttribute(element, name, true);
57
56
  }
58
57
  }
59
58
  }
60
59
 
61
60
  export function sanitizeNodes(nodes: Node[], depth: number): Node[] {
62
61
  const actual = nodes.filter(node => node instanceof Node);
62
+
63
63
  let {length} = nodes;
64
64
 
65
65
  for (let index = 0; index < length; index += 1) {
66
66
  const node = actual[index];
67
67
 
68
- if (node instanceof Element && handleElement(node, depth)) {
68
+ let remove = isClobbered(node);
69
+
70
+ if (!remove) {
71
+ switch (node.nodeType) {
72
+ case Node.ELEMENT_NODE:
73
+ handleElement(node as Element, depth);
74
+ break;
75
+
76
+ case Node.COMMENT_NODE:
77
+ remove = COMMENT_HARMFUL.test((node as Comment).data);
78
+ break;
79
+
80
+ case Node.DOCUMENT_TYPE_NODE:
81
+ case Node.PROCESSING_INSTRUCTION_NODE:
82
+ remove = true;
83
+ break;
84
+ }
85
+ }
86
+
87
+ if (remove) {
88
+ removeNode(node);
89
+
69
90
  actual.splice(index, 1);
70
91
 
71
- length -= 1;
72
92
  index -= 1;
93
+ length -= 1;
73
94
 
74
95
  continue;
75
96
  }
@@ -81,3 +102,9 @@ export function sanitizeNodes(nodes: Node[], depth: number): Node[] {
81
102
 
82
103
  return nodes;
83
104
  }
105
+
106
+ //
107
+
108
+ const COMMENT_HARMFUL = /<[/\w]/g;
109
+
110
+ const REMOVE_SELECTOR = 'script, toretto-temporary';
@@ -1,7 +1,7 @@
1
1
  import type {PlainObject} from '@oscarpalmer/atoms';
2
2
  import {isPlainObject} from '@oscarpalmer/atoms/is';
3
3
  import {getString} from '@oscarpalmer/atoms/string';
4
- import type {Attribute, HTMLOrSVGElement, Property} from '../models';
4
+ import type {Attribute, Property} from '../models';
5
5
  import {isHTMLOrSVGElement} from './is';
6
6
 
7
7
  function badAttributeHandler(name?: string, value?: string): boolean {
@@ -82,11 +82,11 @@ function isAttribute(value: unknown): value is Attr | Attribute {
82
82
  );
83
83
  }
84
84
 
85
- export function isBadAttribute(first: unknown, second: unknown, decode: boolean): boolean {
85
+ export function _isBadAttribute(first: unknown, second: unknown, decode: boolean): boolean {
86
86
  return handleAttribute(badAttributeHandler, decode, first, second);
87
87
  }
88
88
 
89
- export function isBooleanAttribute(first: unknown, decode: boolean): boolean {
89
+ export function _isBooleanAttribute(first: unknown, decode: boolean): boolean {
90
90
  return handleAttribute(
91
91
  name => booleanAttributesSet.has(name?.toLowerCase() as string),
92
92
  decode,
@@ -95,7 +95,7 @@ export function isBooleanAttribute(first: unknown, decode: boolean): boolean {
95
95
  );
96
96
  }
97
97
 
98
- export function isEmptyNonBooleanAttribute(
98
+ export function _isEmptyNonBooleanAttribute(
99
99
  first: unknown,
100
100
  second: unknown,
101
101
  decode: boolean,
@@ -109,7 +109,7 @@ export function isEmptyNonBooleanAttribute(
109
109
  );
110
110
  }
111
111
 
112
- export function isInvalidBooleanAttribute(
112
+ export function _isInvalidBooleanAttribute(
113
113
  first: unknown,
114
114
  second: unknown,
115
115
  decode: boolean,
@@ -125,7 +125,7 @@ function isValidSourceAttribute(name: string, value: string): boolean {
125
125
  return EXPRESSION_SOURCE_NAME.test(name) && EXPRESSION_SOURCE_VALUE.test(value);
126
126
  }
127
127
 
128
- function updateAttribute(element: HTMLOrSVGElement, name: string, value: unknown): void {
128
+ function updateAttribute(element: Element, name: string, value: unknown): void {
129
129
  const isBoolean = booleanAttributesSet.has(name.toLowerCase());
130
130
 
131
131
  if (isBoolean) {
@@ -139,14 +139,14 @@ function updateAttribute(element: HTMLOrSVGElement, name: string, value: unknown
139
139
  }
140
140
  }
141
141
 
142
- function updateProperty(element: HTMLOrSVGElement, name: string, value: unknown): void {
142
+ function updateProperty(element: Element, name: string, value: unknown): void {
143
143
  const actual = name.toLowerCase();
144
144
 
145
145
  (element as unknown as PlainObject)[actual] =
146
146
  value === '' || (typeof value === 'string' && value.toLowerCase() === actual) || value === true;
147
147
  }
148
148
 
149
- export function updateValue(element: HTMLOrSVGElement, first: unknown, second: unknown): void {
149
+ export function updateValue(element: Element, first: unknown, second: unknown): void {
150
150
  if (!isHTMLOrSVGElement(element)) {
151
151
  return;
152
152
  }
@@ -159,7 +159,7 @@ export function updateValue(element: HTMLOrSVGElement, first: unknown, second: u
159
159
  }
160
160
 
161
161
  export function updateValues(
162
- element: HTMLOrSVGElement,
162
+ element: Element,
163
163
  values: Attribute<unknown>[] | Record<string, unknown>,
164
164
  ): void {
165
165
  if (!isHTMLOrSVGElement(element)) {
@@ -1,13 +1,12 @@
1
1
  import type {PlainObject} from '@oscarpalmer/atoms';
2
2
  import {isNullableOrWhitespace, isPlainObject} from '@oscarpalmer/atoms/is';
3
3
  import {isHTMLOrSVGElement} from '../is';
4
- import type {HTMLOrSVGElement} from '../models';
5
4
 
6
5
  export function setElementValues(
7
- element: HTMLOrSVGElement,
6
+ element: Element,
8
7
  first: PlainObject | string,
9
8
  second: unknown,
10
- callback: (element: HTMLOrSVGElement, key: string, value: unknown) => void,
9
+ callback: (element: Element, key: string, value: unknown) => void,
11
10
  ): void {
12
11
  if (!isHTMLOrSVGElement(element)) {
13
12
  return;
@@ -28,7 +27,7 @@ export function setElementValues(
28
27
  }
29
28
 
30
29
  export function updateElementValue(
31
- element: HTMLOrSVGElement,
30
+ element: Element,
32
31
  key: string,
33
32
  value: unknown,
34
33
  set: (key: string, value: string) => void,
@@ -1,15 +1,10 @@
1
1
  import {camelCase, kebabCase, parse} from '@oscarpalmer/atoms/string';
2
- import type {HTMLOrSVGElement} from '../models';
3
2
 
4
3
  export function getBoolean(value: unknown, defaultValue?: boolean): boolean {
5
4
  return typeof value === 'boolean' ? value : (defaultValue ?? false);
6
5
  }
7
6
 
8
- export function getAttributeValue(
9
- element: HTMLOrSVGElement,
10
- name: string,
11
- parseValue: boolean,
12
- ): unknown {
7
+ export function getAttributeValue(element: Element, name: string, parseValue: boolean): unknown {
13
8
  const normalized = kebabCase(name);
14
9
  const attribute = element.attributes[normalized as keyof NamedNodeMap];
15
10
  const value = attribute instanceof Attr ? attribute.value : undefined;
@@ -20,13 +15,15 @@ export function getAttributeValue(
20
15
  }
21
16
 
22
17
  export function getStyleValue(
23
- element: HTMLOrSVGElement,
18
+ element: Element,
24
19
  property: string,
25
20
  computed: boolean,
26
21
  ): string | undefined {
27
22
  const name = camelCase(property);
28
23
 
29
- return computed ? getComputedStyle(element)[name as never] : element.style[name as never];
24
+ return computed
25
+ ? getComputedStyle(element)[name as never]
26
+ : (element as HTMLElement).style[name as never];
30
27
  }
31
28
 
32
29
  export const EXPRESSION_DATA_PREFIX = /^data-/i;
@@ -1,5 +1,3 @@
1
- import type {HTMLOrSVGElement} from '../models';
2
-
3
1
  /**
4
2
  * Is the value an event target?
5
3
  * @param value Value to check
@@ -20,6 +18,6 @@ export function isEventTarget(value: unknown): value is EventTarget {
20
18
  * @param value Value to check
21
19
  * @returns `true` if it's an HTML or SVG element, otherwise `false`
22
20
  */
23
- export function isHTMLOrSVGElement(value: unknown): value is HTMLOrSVGElement {
21
+ export function isHTMLOrSVGElement(value: unknown): value is HTMLElement | SVGElement {
24
22
  return value instanceof HTMLElement || value instanceof SVGElement;
25
23
  }
package/src/is.ts CHANGED
@@ -22,18 +22,18 @@ export function isInDocument(node: Node): boolean;
22
22
  */
23
23
  export function isInDocument(node: Node, document: Document): boolean;
24
24
 
25
- export function isInDocument(node: Node, document?: Document): boolean {
25
+ export function isInDocument(node: Node, doc?: Document): boolean {
26
26
  if (!(node instanceof Node)) {
27
27
  return false;
28
28
  }
29
29
 
30
- if (!(document instanceof Document)) {
30
+ if (!(doc instanceof Document)) {
31
31
  return node.ownerDocument?.contains(node) ?? true;
32
32
  }
33
33
 
34
34
  return node.ownerDocument == null
35
- ? node === document
36
- : node.ownerDocument === document && document.contains(node);
35
+ ? node === doc
36
+ : node.ownerDocument === doc && doc.contains(node);
37
37
  }
38
38
 
39
39
  //
package/src/models.ts CHANGED
@@ -19,11 +19,6 @@ export type EventPosition = {
19
19
  y: number;
20
20
  };
21
21
 
22
- /**
23
- * Combined type to work with HTML and SVG elements
24
- */
25
- export type HTMLOrSVGElement = HTMLElement | SVGElement;
26
-
27
22
  /**
28
23
  * Property for an element
29
24
  */
package/src/style.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import {setElementValues, updateElementValue} from './internal/element-value';
2
2
  import {getStyleValue} from './internal/get-value';
3
3
  import {isHTMLOrSVGElement} from './internal/is';
4
- import type {HTMLOrSVGElement, TextDirection} from './models';
4
+ import type {TextDirection} from './models';
5
5
 
6
6
  export type StyleToggler = {
7
7
  /**
@@ -22,7 +22,7 @@ export type StyleToggler = {
22
22
  * @returns Style value
23
23
  */
24
24
  export function getStyle(
25
- element: HTMLOrSVGElement,
25
+ element: Element,
26
26
  property: keyof CSSStyleDeclaration,
27
27
  computed?: boolean,
28
28
  ): string | undefined {
@@ -41,7 +41,7 @@ export function getStyle(
41
41
  * @returns Style values
42
42
  */
43
43
  export function getStyles<Property extends keyof CSSStyleDeclaration>(
44
- element: HTMLOrSVGElement,
44
+ element: Element,
45
45
  properties: Property[],
46
46
  computed?: boolean,
47
47
  ): Record<Property, string | undefined> {
@@ -70,7 +70,7 @@ export function getStyles<Property extends keyof CSSStyleDeclaration>(
70
70
  * @param computed Get the computed text direction? _(defaults to `false`)_
71
71
  * @returns Text direction
72
72
  */
73
- export function getTextDirection(element: HTMLOrSVGElement, computed?: boolean): TextDirection {
73
+ export function getTextDirection(element: Element, computed?: boolean): TextDirection {
74
74
  if (!(element instanceof Element)) {
75
75
  return undefined as never;
76
76
  }
@@ -93,7 +93,7 @@ export function getTextDirection(element: HTMLOrSVGElement, computed?: boolean):
93
93
  * @param value Style value
94
94
  */
95
95
  export function setStyle(
96
- element: HTMLOrSVGElement,
96
+ element: Element,
97
97
  property: keyof CSSStyleDeclaration,
98
98
  value?: string,
99
99
  ): void {
@@ -105,7 +105,7 @@ export function setStyle(
105
105
  * @param element Element to set the styles on
106
106
  * @param styles Styles to set
107
107
  */
108
- export function setStyles(element: HTMLOrSVGElement, styles: Partial<CSSStyleDeclaration>): void {
108
+ export function setStyles(element: Element, styles: Partial<CSSStyleDeclaration>): void {
109
109
  setElementValues(element, styles as never, null, updateStyleProperty);
110
110
  }
111
111
 
@@ -115,10 +115,7 @@ export function setStyles(element: HTMLOrSVGElement, styles: Partial<CSSStyleDec
115
115
  * @param styles Styles to be set or removed
116
116
  * @returns Style toggler
117
117
  */
118
- export function toggleStyles(
119
- element: HTMLOrSVGElement,
120
- styles: Partial<CSSStyleDeclaration>,
121
- ): StyleToggler {
118
+ export function toggleStyles(element: Element, styles: Partial<CSSStyleDeclaration>): StyleToggler {
122
119
  function toggle(set: boolean): void {
123
120
  hasSet = set;
124
121
 
@@ -160,16 +157,16 @@ export function toggleStyles(
160
157
  };
161
158
  }
162
159
 
163
- function updateStyleProperty(element: HTMLOrSVGElement, key: string, value: unknown): void {
160
+ function updateStyleProperty(element: Element, key: string, value: unknown): void {
164
161
  updateElementValue(
165
162
  element,
166
163
  key,
167
164
  value,
168
- function (this: HTMLOrSVGElement, property: string, value: string) {
169
- this.style[property as never] = value;
165
+ function (this: Element, property: string, style: string) {
166
+ (this as HTMLElement).style[property as never] = style;
170
167
  },
171
- function (this: HTMLOrSVGElement, property: string) {
172
- this.style[property as never] = '';
168
+ function (this: Element, property: string) {
169
+ (this as HTMLElement).style[property as never] = '';
173
170
  },
174
171
  false,
175
172
  );
@@ -5,14 +5,14 @@
5
5
  * @param parse Parse value? _(defaults to `true`)_
6
6
  * @returns Attribute value _(or `undefined`)_
7
7
  */
8
- export declare function getAttribute(element: HTMLOrSVGElement, name: `data-${string}`, parse?: boolean): unknown;
8
+ export declare function getAttribute(element: Element, name: `data-${string}`, parse?: boolean): unknown;
9
9
  /**
10
10
  * Get the value of a specific attribute from an element
11
11
  * @param element Element to get attribute from
12
12
  * @param name Attribute name
13
13
  * @returns Attribute value _(or `undefined`)_
14
14
  */
15
- export declare function getAttribute(element: HTMLOrSVGElement, name: string): unknown;
15
+ export declare function getAttribute(element: Element, name: string): unknown;
16
16
  /**
17
17
  * Get specific attributes from an element
18
18
  * @param element Element to get attributes from
@@ -20,4 +20,4 @@ export declare function getAttribute(element: HTMLOrSVGElement, name: string): u
20
20
  * @param parseData Parse data values? _(defaults to `true`)_
21
21
  * @returns Object of named attributes
22
22
  */
23
- export declare function getAttributes<Key extends string>(element: HTMLOrSVGElement, names: Key[], parseData?: boolean): Record<Key, unknown>;
23
+ export declare function getAttributes<Key extends string>(element: Element, names: Key[], parseData?: boolean): Record<Key, unknown>;
@@ -1,4 +1,4 @@
1
- import type { Attribute, HTMLOrSVGElement, Property } from '../models';
1
+ import type { Attribute, Property } from '../models';
2
2
  /**
3
3
  * Set an attribute on an element
4
4
  *
@@ -7,7 +7,7 @@ import type { Attribute, HTMLOrSVGElement, Property } from '../models';
7
7
  * @param name Attribute name
8
8
  * @param value Attribute value
9
9
  */
10
- export declare function setAttribute(element: HTMLOrSVGElement, name: string, value?: unknown): void;
10
+ export declare function setAttribute(element: Element, name: string, value?: unknown): void;
11
11
  /**
12
12
  * Set an attribute on an element
13
13
  *
@@ -15,7 +15,7 @@ export declare function setAttribute(element: HTMLOrSVGElement, name: string, va
15
15
  * @param element Element for attribute
16
16
  * @param attribute Attribute to set
17
17
  */
18
- export declare function setAttribute(element: HTMLOrSVGElement, attribute: Attr | Attribute): void;
18
+ export declare function setAttribute(element: Element, attribute: Attr | Attribute): void;
19
19
  /**
20
20
  * Set one or more attributes on an element
21
21
  *
@@ -23,7 +23,7 @@ export declare function setAttribute(element: HTMLOrSVGElement, attribute: Attr
23
23
  * @param element Element for attributes
24
24
  * @param attributes Attributes to set
25
25
  */
26
- export declare function setAttributes(element: HTMLOrSVGElement, attributes: Array<Attr | Attribute>): void;
26
+ export declare function setAttributes(element: Element, attributes: Array<Attr | Attribute>): void;
27
27
  /**
28
28
  * Set one or more attributes on an element
29
29
  *
@@ -31,7 +31,7 @@ export declare function setAttributes(element: HTMLOrSVGElement, attributes: Arr
31
31
  * @param element Element for attributes
32
32
  * @param attributes Attributes to set
33
33
  */
34
- export declare function setAttributes(element: HTMLOrSVGElement, attributes: Record<string, unknown>): void;
34
+ export declare function setAttributes(element: Element, attributes: Record<string, unknown>): void;
35
35
  /**
36
36
  * Set a property on an element
37
37
  *
@@ -40,7 +40,7 @@ export declare function setAttributes(element: HTMLOrSVGElement, attributes: Rec
40
40
  * @param name Property name
41
41
  * @param value Property value
42
42
  */
43
- export declare function setProperty(element: HTMLOrSVGElement, name: string, value: boolean | string): void;
43
+ export declare function setProperty(element: Element, name: string, value: boolean | string): void;
44
44
  /**
45
45
  * Set a property on an element
46
46
  *
@@ -48,7 +48,7 @@ export declare function setProperty(element: HTMLOrSVGElement, name: string, val
48
48
  * @param element Element for property
49
49
  * @param property Property to set
50
50
  */
51
- export declare function setProperty(element: HTMLOrSVGElement, property: Property): void;
51
+ export declare function setProperty(element: Element, property: Property): void;
52
52
  /**
53
53
  * Set one or more properties on an element
54
54
  *
@@ -56,7 +56,7 @@ export declare function setProperty(element: HTMLOrSVGElement, property: Propert
56
56
  * @param element Element for properties
57
57
  * @param properties Properties to set
58
58
  */
59
- export declare function setProperties(element: HTMLOrSVGElement, properties: Property[]): void;
59
+ export declare function setProperties(element: Element, properties: Property[]): void;
60
60
  /**
61
61
  * Set one or more properties on an element
62
62
  *
@@ -64,4 +64,4 @@ export declare function setProperties(element: HTMLOrSVGElement, properties: Pro
64
64
  * @param element Element for properties
65
65
  * @param properties Properties to set
66
66
  */
67
- export declare function setProperties(element: HTMLOrSVGElement, properties: Record<string, unknown>): void;
67
+ export declare function setProperties(element: Element, properties: Record<string, unknown>): void;
package/types/data.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import type { PlainObject } from '@oscarpalmer/atoms';
2
- import type { HTMLOrSVGElement } from './models';
3
2
  /**
4
3
  * Get a keyed data value from an element
5
4
  * @param element Element to get data from
@@ -7,7 +6,7 @@ import type { HTMLOrSVGElement } from './models';
7
6
  * @param parse Parse values? _(defaults to `true`)_
8
7
  * @returns Data value
9
8
  */
10
- export declare function getData(element: HTMLOrSVGElement, key: string, parse?: boolean): unknown;
9
+ export declare function getData(element: Element, key: string, parse?: boolean): unknown;
11
10
  /**
12
11
  * Get keyed data values from an element
13
12
  * @param element Element to get data from
@@ -15,17 +14,17 @@ export declare function getData(element: HTMLOrSVGElement, key: string, parse?:
15
14
  * @param parse Parse values? _(defaults to `true`)_
16
15
  * @returns Keyed data values
17
16
  */
18
- export declare function getData<Key extends string>(element: HTMLOrSVGElement, keys: Key[], parse?: boolean): Record<Key, unknown>;
17
+ export declare function getData<Key extends string>(element: Element, keys: Key[], parse?: boolean): Record<Key, unknown>;
19
18
  /**
20
19
  * Set data values on an element
21
20
  * @param element Element to set data on
22
21
  * @param data Data to set
23
22
  */
24
- export declare function setData(element: HTMLOrSVGElement, data: PlainObject): void;
23
+ export declare function setData(element: Element, data: PlainObject): void;
25
24
  /**
26
25
  * Set a data value on an element
27
26
  * @param element Element to set data on
28
27
  * @param key Data key
29
28
  * @param value Data value
30
29
  */
31
- export declare function setData(element: HTMLOrSVGElement, key: string, value: unknown): void;
30
+ export declare function setData(element: Element, key: string, value: unknown): void;
@@ -4,4 +4,4 @@ export type EventTargetWithListeners = EventTarget & Partial<{
4
4
  }>;
5
5
  export declare function addDelegatedListener(target: EventTargetWithListeners, type: string, name: string, listener: EventListener | CustomEventListener, passive: boolean): RemovableEventListener;
6
6
  export declare function getDelegatedName(target: EventTarget, type: string, options: AddEventListenerOptions): string | undefined;
7
- export declare function removeDelegatedListener(target: EventTargetWithListeners, type: string, name: string, listener: EventListener | CustomEventListener, passive: boolean): boolean;
7
+ export declare function removeDelegatedListener(target: EventTargetWithListeners, name: string, listener: EventListener | CustomEventListener): boolean;
@@ -23,4 +23,4 @@ export declare function findElements(selector: Selector, context?: Selector | nu
23
23
  */
24
24
  export declare function getElementUnderPointer(skipIgnore?: boolean): Element | null;
25
25
  export { findElement as $, findElements as $$ };
26
- export { findAncestor, findRelatives } from './relative';
26
+ export { findAncestor, findRelatives, getDistance } from './relative';
@@ -11,11 +11,17 @@ export declare function findAncestor(origin: Element, selector: string | ((eleme
11
11
  /**
12
12
  * Finds the closest elements to the origin element that matches the selector
13
13
  *
14
- * - Traverses up, down, and sideways in the _DOM_-tree
15
- * - _(If you only want to traverse up, use {@link findAncestor})_
14
+ * Traverses up, down, and sideways in the _DOM_-tree. _(If you only want to traverse up, use {@link findAncestor})_
16
15
  * @param origin Element to start from
17
16
  * @param selector Selector to match
18
17
  * @param context Context to search within
19
18
  * @returns Found elements
20
19
  */
21
20
  export declare function findRelatives(origin: Element, selector: string, context?: Document | Element): Element[];
21
+ /**
22
+ * Get the distance between two elements _(i.e., the amount of nodes of between them)_
23
+ * @param origin Origin element
24
+ * @param target Target element
25
+ * @returns Distance between elements, or `-1` if distance cannot be calculated
26
+ */
27
+ export declare function getDistance(origin: Element, target: Element): number;
@@ -1,11 +1,11 @@
1
- import type { Attribute, HTMLOrSVGElement, Property } from '../models';
2
- export declare function isBadAttribute(first: unknown, second: unknown, decode: boolean): boolean;
3
- export declare function isBooleanAttribute(first: unknown, decode: boolean): boolean;
4
- export declare function isEmptyNonBooleanAttribute(first: unknown, second: unknown, decode: boolean): boolean;
5
- export declare function isInvalidBooleanAttribute(first: unknown, second: unknown, decode: boolean): boolean;
1
+ import type { Attribute, Property } from '../models';
2
+ export declare function _isBadAttribute(first: unknown, second: unknown, decode: boolean): boolean;
3
+ export declare function _isBooleanAttribute(first: unknown, decode: boolean): boolean;
4
+ export declare function _isEmptyNonBooleanAttribute(first: unknown, second: unknown, decode: boolean): boolean;
5
+ export declare function _isInvalidBooleanAttribute(first: unknown, second: unknown, decode: boolean): boolean;
6
6
  export declare function isProperty(value: unknown): value is Property;
7
- export declare function updateValue(element: HTMLOrSVGElement, first: unknown, second: unknown): void;
8
- export declare function updateValues(element: HTMLOrSVGElement, values: Attribute<unknown>[] | Record<string, unknown>): void;
7
+ export declare function updateValue(element: Element, first: unknown, second: unknown): void;
8
+ export declare function updateValues(element: Element, values: Attribute<unknown>[] | Record<string, unknown>): void;
9
9
  /**
10
10
  * List of boolean attributes
11
11
  */
@@ -1,4 +1,3 @@
1
1
  import type { PlainObject } from '@oscarpalmer/atoms';
2
- import type { HTMLOrSVGElement } from '../models';
3
- export declare function setElementValues(element: HTMLOrSVGElement, first: PlainObject | string, second: unknown, callback: (element: HTMLOrSVGElement, key: string, value: unknown) => void): void;
4
- export declare function updateElementValue(element: HTMLOrSVGElement, key: string, value: unknown, set: (key: string, value: string) => void, remove: (key: string) => void, json: boolean): void;
2
+ export declare function setElementValues(element: Element, first: PlainObject | string, second: unknown, callback: (element: Element, key: string, value: unknown) => void): void;
3
+ export declare function updateElementValue(element: Element, key: string, value: unknown, set: (key: string, value: string) => void, remove: (key: string) => void, json: boolean): void;
@@ -1,5 +1,4 @@
1
- import type { HTMLOrSVGElement } from '../models';
2
1
  export declare function getBoolean(value: unknown, defaultValue?: boolean): boolean;
3
- export declare function getAttributeValue(element: HTMLOrSVGElement, name: string, parseValue: boolean): unknown;
4
- export declare function getStyleValue(element: HTMLOrSVGElement, property: string, computed: boolean): string | undefined;
2
+ export declare function getAttributeValue(element: Element, name: string, parseValue: boolean): unknown;
3
+ export declare function getStyleValue(element: Element, property: string, computed: boolean): string | undefined;
5
4
  export declare const EXPRESSION_DATA_PREFIX: RegExp;
@@ -1,4 +1,3 @@
1
- import type { HTMLOrSVGElement } from '../models';
2
1
  /**
3
2
  * Is the value an event target?
4
3
  * @param value Value to check
@@ -10,4 +9,4 @@ export declare function isEventTarget(value: unknown): value is EventTarget;
10
9
  * @param value Value to check
11
10
  * @returns `true` if it's an HTML or SVG element, otherwise `false`
12
11
  */
13
- export declare function isHTMLOrSVGElement(value: unknown): value is HTMLOrSVGElement;
12
+ export declare function isHTMLOrSVGElement(value: unknown): value is HTMLElement | SVGElement;
package/types/models.d.ts CHANGED
@@ -16,10 +16,6 @@ export type EventPosition = {
16
16
  x: number;
17
17
  y: number;
18
18
  };
19
- /**
20
- * Combined type to work with HTML and SVG elements
21
- */
22
- export type HTMLOrSVGElement = HTMLElement | SVGElement;
23
19
  /**
24
20
  * Property for an element
25
21
  */