@oscarpalmer/toretto 0.27.0 → 0.28.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.
@@ -3,7 +3,7 @@ import type {CustomEventListener, RemovableEventListener} from '../models';
3
3
 
4
4
  //
5
5
 
6
- type DocumentWithListeners = Document &
6
+ type DocumentWithListenerCounts = Document &
7
7
  Partial<{
8
8
  [key: string]: number;
9
9
  }>;
@@ -14,20 +14,20 @@ export type EventTargetWithListeners = EventTarget &
14
14
  }>;
15
15
 
16
16
  function addDelegatedHandler(
17
- document: DocumentWithListeners,
17
+ document: DocumentWithListenerCounts,
18
18
  type: string,
19
19
  name: string,
20
20
  passive: boolean,
21
21
  ): void {
22
- const listeners = `${name}${LISTENERS_SUFFIX}`;
22
+ const count = `${name}${COUNT_SUFFIX}`;
23
23
 
24
- if (document[listeners] != null) {
25
- (document[listeners] as number) += 1;
24
+ if (document[count] != null) {
25
+ (document[count] as number) += 1;
26
26
 
27
27
  return;
28
28
  }
29
29
 
30
- document[listeners] = 1;
30
+ document[count] = 1;
31
31
 
32
32
  document.addEventListener(type, passive ? HANDLER_PASSIVE : HANDLER_ACTIVE, {
33
33
  passive,
@@ -45,7 +45,7 @@ export function addDelegatedListener(
45
45
 
46
46
  target[name]?.add(listener);
47
47
 
48
- addDelegatedHandler(document as DocumentWithListeners, type, name, passive);
48
+ addDelegatedHandler(document as DocumentWithListenerCounts, type, name, passive);
49
49
 
50
50
  return () => {
51
51
  removeDelegatedListener(target, type, name, listener, passive);
@@ -67,18 +67,20 @@ function delegatedEventHandler(this: boolean, event: Event): void {
67
67
  const item = items[index] as EventTargetWithListeners;
68
68
  const listeners = item[key];
69
69
 
70
- if (!(item as unknown as HTMLButtonElement).disabled && listeners != null) {
71
- Object.defineProperty(event, 'currentTarget', {
72
- configurable: true,
73
- value: item,
74
- });
70
+ if ((item as unknown as HTMLButtonElement).disabled || listeners == null) {
71
+ continue;
72
+ }
73
+
74
+ Object.defineProperty(event, 'currentTarget', {
75
+ configurable: true,
76
+ value: item,
77
+ });
75
78
 
76
- for (const listener of listeners) {
77
- (listener as EventListener).call(item, event);
79
+ for (const listener of listeners) {
80
+ (listener as EventListener).call(item, event);
78
81
 
79
- if (event.cancelBubble) {
80
- return;
81
- }
82
+ if (event.cancelBubble) {
83
+ return;
82
84
  }
83
85
  }
84
86
  }
@@ -101,22 +103,19 @@ export function getDelegatedName(
101
103
  }
102
104
 
103
105
  function removeDelegatedHandler(
104
- document: DocumentWithListeners,
106
+ document: DocumentWithListenerCounts,
105
107
  type: string,
106
108
  name: string,
107
109
  passive: boolean,
108
110
  ): void {
109
- const listeners = `${name}${LISTENERS_SUFFIX}`;
111
+ const count = `${name}${COUNT_SUFFIX}`;
110
112
 
111
- (document[listeners] as number) -= 1;
113
+ (document[count] as number) -= 1;
112
114
 
113
- if ((document[listeners] as number) < 1) {
114
- document[listeners] = undefined;
115
+ if ((document[count] as number) < 1) {
116
+ document[count] = undefined;
115
117
 
116
- document.removeEventListener(
117
- type,
118
- passive ? HANDLER_PASSIVE : HANDLER_ACTIVE,
119
- );
118
+ document.removeEventListener(type, passive ? HANDLER_PASSIVE : HANDLER_ACTIVE);
120
119
  }
121
120
  }
122
121
 
@@ -135,22 +134,19 @@ export function removeDelegatedListener(
135
134
 
136
135
  handlers.delete(listener);
137
136
 
138
- if (handlers?.size === 0) {
137
+ if (handlers.size === 0) {
139
138
  target[name] = undefined;
140
139
  }
141
140
 
142
- removeDelegatedHandler(
143
- document as DocumentWithListeners,
144
- type,
145
- name,
146
- passive,
147
- );
141
+ removeDelegatedHandler(document as DocumentWithListenerCounts, type, name, passive);
148
142
 
149
143
  return true;
150
144
  }
151
145
 
152
146
  //
153
147
 
148
+ const COUNT_SUFFIX = '.count';
149
+
154
150
  const EVENT_PREFIX = '@';
155
151
 
156
152
  const EVENT_SUFFIX_ACTIVE = ':active';
@@ -185,5 +181,3 @@ const EVENT_TYPES: Set<string> = new Set([
185
181
  const HANDLER_ACTIVE: EventListener = delegatedEventHandler.bind(false);
186
182
 
187
183
  const HANDLER_PASSIVE: EventListener = delegatedEventHandler.bind(true);
188
-
189
- const LISTENERS_SUFFIX = ':listeners';
@@ -2,11 +2,7 @@ import {noop} from '@oscarpalmer/atoms/function';
2
2
  import {isPlainObject} from '@oscarpalmer/atoms/is';
3
3
  import {getBoolean} from '../internal/get-value';
4
4
  import {isEventTarget} from '../internal/is';
5
- import type {
6
- CustomEventListener,
7
- EventPosition,
8
- RemovableEventListener,
9
- } from '../models';
5
+ import type {CustomEventListener, EventPosition, RemovableEventListener} from '../models';
10
6
  import {
11
7
  addDelegatedListener,
12
8
  type EventTargetWithListeners,
@@ -73,11 +69,7 @@ export function dispatch<Type extends keyof HTMLElementEventMap>(
73
69
  * @param type Type of event
74
70
  * @param options Options for event _(bubbles and is cancelable by default)_
75
71
  */
76
- export function dispatch(
77
- target: EventTarget,
78
- type: string,
79
- options?: CustomEventInit,
80
- ): void;
72
+ export function dispatch(target: EventTarget, type: string, options?: CustomEventInit): void;
81
73
 
82
74
  export function dispatch<Type extends keyof HTMLElementEventMap>(
83
75
  target: EventTarget,
@@ -94,9 +86,7 @@ export function dispatch<Type extends keyof HTMLElementEventMap>(
94
86
  * @param event Pointer event
95
87
  * @returns X- and Y-coordinates
96
88
  */
97
- export function getPosition(
98
- event: MouseEvent | TouchEvent,
99
- ): EventPosition | undefined {
89
+ export function getPosition(event: MouseEvent | TouchEvent): EventPosition | undefined {
100
90
  let x: number | undefined;
101
91
  let y: number | undefined;
102
92
 
@@ -152,11 +142,7 @@ export function off(
152
142
  listener: EventListener | CustomEventListener,
153
143
  options?: EventListenerOptions,
154
144
  ): void {
155
- if (
156
- !isEventTarget(target) ||
157
- typeof type !== 'string' ||
158
- typeof listener !== 'function'
159
- ) {
145
+ if (!isEventTarget(target) || typeof type !== 'string' || typeof listener !== 'function') {
160
146
  return;
161
147
  }
162
148
 
@@ -211,11 +197,7 @@ export function on(
211
197
  listener: EventListener | CustomEventListener,
212
198
  options?: AddEventListenerOptions,
213
199
  ): RemovableEventListener {
214
- if (
215
- !isEventTarget(target) ||
216
- typeof type !== 'string' ||
217
- typeof listener !== 'function'
218
- ) {
200
+ if (!isEventTarget(target) || typeof type !== 'string' || typeof listener !== 'function') {
219
201
  return noop;
220
202
  }
221
203
 
package/src/find/index.ts CHANGED
@@ -7,10 +7,7 @@ import type {Selector} from '../models';
7
7
  * @param context Context to search within _(defaults to `document`)_
8
8
  * @returns Found element or `null`
9
9
  */
10
- export function findElement(
11
- selector: string,
12
- context?: Selector | null,
13
- ): Element | null {
10
+ export function findElement(selector: string, context?: Selector | null): Element | null {
14
11
  return findElementOrElements(selector, context, true) as never;
15
12
  }
16
13
 
@@ -24,17 +21,10 @@ function findElementOrElements(
24
21
  const contexts =
25
22
  context == null
26
23
  ? [document]
27
- : (findElementOrElements(context, undefined, false) as Element[]).filter(
28
- isContext,
29
- );
24
+ : (findElementOrElements(context, undefined, false) as Element[]).filter(isContext);
30
25
 
31
26
  if (typeof selector === 'string') {
32
- return findElementOrElementsForSelector(
33
- selector,
34
- contexts,
35
- callback,
36
- single,
37
- );
27
+ return findElementOrElementsForSelector(selector, contexts, callback, single);
38
28
  }
39
29
 
40
30
  let array: unknown[];
@@ -59,9 +49,10 @@ function findElementOrElementsForSelector(
59
49
  const result: Element[] = [];
60
50
 
61
51
  for (let index = 0; index < length; index += 1) {
62
- const value = (
63
- contexts[index][callback] as (selector: string) => Node | null
64
- )(selector) as Element | Element[] | null;
52
+ const value = (contexts[index][callback] as (selector: string) => Node | null)(selector) as
53
+ | Element
54
+ | Element[]
55
+ | null;
65
56
 
66
57
  if (single) {
67
58
  if (value == null) {
@@ -74,9 +65,7 @@ function findElementOrElementsForSelector(
74
65
  result.push(...Array.from(value as Element[]));
75
66
  }
76
67
 
77
- return single
78
- ? null
79
- : result.filter((value, index, array) => array.indexOf(value) === index);
68
+ return single ? null : result.filter((value, index, array) => array.indexOf(value) === index);
80
69
  }
81
70
 
82
71
  function findElementOrElementsFromNodes(
@@ -104,9 +93,7 @@ function findElementOrElementsFromNodes(
104
93
  element != null &&
105
94
  (context == null ||
106
95
  contexts.length === 0 ||
107
- contexts.some(
108
- context => context === element || context.contains(element),
109
- )) &&
96
+ contexts.some(context => context === element || context.contains(element))) &&
110
97
  !result.includes(element)
111
98
  ) {
112
99
  result.push(element);
@@ -122,10 +109,7 @@ function findElementOrElementsFromNodes(
122
109
  * @param context Context to search within _(defaults to `document`)_
123
110
  * @returns Found elements
124
111
  */
125
- export function findElements(
126
- selector: Selector,
127
- context?: Selector | null,
128
- ): Element[] {
112
+ export function findElements(selector: Selector, context?: Selector | null): Element[] {
129
113
  return findElementOrElements(selector, context, false) as never;
130
114
  }
131
115
 
@@ -2,10 +2,7 @@
2
2
  * - Get the distance between two elements _(i.e., the amount of nodes of between them)_
3
3
  * - If the distance cannot be calculated, `-1` is returned
4
4
  */
5
- function getDistanceBetweenElements(
6
- origin: Element,
7
- target: Element,
8
- ): number | undefined {
5
+ function getDistanceBetweenElements(origin: Element, target: Element): number | undefined {
9
6
  if (origin === target || origin.parentElement === target) {
10
7
  return 0;
11
8
  }
@@ -20,12 +17,7 @@ function getDistanceBetweenElements(
20
17
  const beforeOrInside = !!(comparison & 2 || comparison & 8);
21
18
 
22
19
  if (beforeOrInside || !!(comparison & 4 || comparison & 16)) {
23
- return (
24
- traverse(
25
- beforeOrInside ? origin : target,
26
- beforeOrInside ? target : origin,
27
- ) ?? -1
28
- );
20
+ return traverse(beforeOrInside ? origin : target, beforeOrInside ? target : origin) ?? -1;
29
21
  }
30
22
  }
31
23
 
@@ -137,9 +129,7 @@ export function findRelatives(
137
129
 
138
130
  return minimum == null
139
131
  ? []
140
- : distances
141
- .filter(found => found.distance === minimum)
142
- .map(found => found.element);
132
+ : distances.filter(found => found.distance === minimum).map(found => found.element);
143
133
  }
144
134
 
145
135
  function traverse(from: Element, to: Element): number | undefined {
@@ -161,9 +151,7 @@ function traverse(from: Element, to: Element): number | undefined {
161
151
  const children = [...(parent.children ?? [])];
162
152
 
163
153
  if (children.includes(to)) {
164
- return (
165
- distance + Math.abs(children.indexOf(current) - children.indexOf(to))
166
- );
154
+ return distance + Math.abs(children.indexOf(current) - children.indexOf(to));
167
155
  }
168
156
 
169
157
  index = children.findIndex(child => child.contains(to));
package/src/focusable.ts CHANGED
@@ -41,8 +41,7 @@ function getTabIndex(element: Element): number {
41
41
 
42
42
  if (
43
43
  tabIndex < TABINDEX_BASE &&
44
- (EXPRESSION_SPECIAL_TABINDEX.test(element.tagName) ||
45
- isEditable(element)) &&
44
+ (EXPRESSION_SPECIAL_TABINDEX.test(element.tagName) || isEditable(element)) &&
46
45
  !hasTabIndex(element)
47
46
  ) {
48
47
  return TABINDEX_BASE;
@@ -51,11 +50,7 @@ function getTabIndex(element: Element): number {
51
50
  return tabIndex;
52
51
  }
53
52
 
54
- function getValidElements(
55
- parent: Element,
56
- filters: Filter[],
57
- tabbable: boolean,
58
- ): Element[] {
53
+ function getValidElements(parent: Element, filters: Filter[], tabbable: boolean): Element[] {
59
54
  if (!(parent instanceof Element)) {
60
55
  return [];
61
56
  }
@@ -88,10 +83,7 @@ function getValidElements(
88
83
  if (item.tabIndex === TABINDEX_BASE) {
89
84
  zeroed.push(item.element);
90
85
  } else {
91
- indiced[item.tabIndex] = [
92
- ...(indiced[item.tabIndex] ?? []),
93
- item.element,
94
- ];
86
+ indiced[item.tabIndex] = [...(indiced[item.tabIndex] ?? []), item.element];
95
87
  }
96
88
  }
97
89
 
@@ -99,16 +91,11 @@ function getValidElements(
99
91
  }
100
92
 
101
93
  function hasTabIndex(element: Element): boolean {
102
- return !Number.isNaN(
103
- Number.parseInt(element.getAttribute(ATTRIBUTE_TABINDEX) as string, 10),
104
- );
94
+ return !Number.isNaN(Number.parseInt(element.getAttribute(ATTRIBUTE_TABINDEX) as string, 10));
105
95
  }
106
96
 
107
97
  function isDisabled(item: ElementWithTabIndex): boolean {
108
- if (
109
- EXPRESSION_DISABLEABLE.test(item.element.tagName) &&
110
- isDisabledFromFieldset(item.element)
111
- ) {
98
+ if (EXPRESSION_DISABLEABLE.test(item.element.tagName) && isDisabledFromFieldset(item.element)) {
112
99
  return true;
113
100
  }
114
101
 
@@ -127,10 +114,7 @@ function isDisabledFromFieldset(element: Element): boolean {
127
114
  const child = children[index];
128
115
 
129
116
  if (child instanceof HTMLLegendElement) {
130
- return (
131
- parent.matches(SELECTOR_FIELDSET_DISABLED) ||
132
- !child.contains(element)
133
- );
117
+ return parent.matches(SELECTOR_FIELDSET_DISABLED) || !child.contains(element);
134
118
  }
135
119
  }
136
120
 
@@ -144,9 +128,7 @@ function isDisabledFromFieldset(element: Element): boolean {
144
128
  }
145
129
 
146
130
  function isEditable(element: Element): boolean {
147
- return EXPRESSION_TRUEISH.test(
148
- element.getAttribute(ATTRIBUTE_CONTENTEDITABLE) as string,
149
- );
131
+ return EXPRESSION_TRUEISH.test(element.getAttribute(ATTRIBUTE_CONTENTEDITABLE) as string);
150
132
  }
151
133
 
152
134
  /**
@@ -155,25 +137,20 @@ function isEditable(element: Element): boolean {
155
137
  * @returns `true` if focusable, otherwise `false`
156
138
  */
157
139
  export function isFocusable(element: Element): boolean {
158
- return element instanceof Element
159
- ? isValidElement(element, FILTERS_FOCUSABLE, false)
160
- : false;
140
+ return element instanceof Element ? isValidElement(element, FILTERS_FOCUSABLE, false) : false;
161
141
  }
162
142
 
163
143
  function isHidden(item: ElementWithTabIndex): boolean {
164
144
  if (
165
145
  ((item.element as HTMLElement).hidden ?? false) ||
166
- (item.element instanceof HTMLInputElement &&
167
- item.element.type === STYLE_HIDDEN)
146
+ (item.element instanceof HTMLInputElement && item.element.type === STYLE_HIDDEN)
168
147
  ) {
169
148
  return true;
170
149
  }
171
150
 
172
151
  const isDirectSummary = item.element.matches(SELECTOR_SUMMARY_FIRST);
173
152
 
174
- const nodeUnderDetails = isDirectSummary
175
- ? item.element.parentElement
176
- : item.element;
153
+ const nodeUnderDetails = isDirectSummary ? item.element.parentElement : item.element;
177
154
 
178
155
  if (nodeUnderDetails?.matches(SELECTOR_DETAILS_CLOSED_CHILDREN) ?? false) {
179
156
  return true;
@@ -193,9 +170,7 @@ function isHidden(item: ElementWithTabIndex): boolean {
193
170
  function isInert(item: ElementWithTabIndex): boolean {
194
171
  return (
195
172
  ((item.element as InertElement).inert ?? false) ||
196
- EXPRESSION_TRUEISH.test(
197
- item.element.getAttribute(ATTRIBUTE_INERT) as string,
198
- ) ||
173
+ EXPRESSION_TRUEISH.test(item.element.getAttribute(ATTRIBUTE_INERT) as string) ||
199
174
  (item.element.parentElement != null &&
200
175
  isInert({
201
176
  element: item.element.parentElement,
@@ -218,10 +193,7 @@ function isNotTabbableRadio(item: ElementWithTabIndex): boolean {
218
193
  return false;
219
194
  }
220
195
 
221
- const parent =
222
- item.element.form ??
223
- item.element.getRootNode?.() ??
224
- item.element.ownerDocument;
196
+ const parent = item.element.form ?? item.element.getRootNode?.() ?? item.element.ownerDocument;
225
197
 
226
198
  const realName = CSS?.escape?.(item.element.name) ?? item.element.name;
227
199
 
@@ -239,9 +211,7 @@ function isNotTabbableRadio(item: ElementWithTabIndex): boolean {
239
211
  function isSummarised(item: ElementWithTabIndex): boolean {
240
212
  return (
241
213
  item.element instanceof HTMLDetailsElement &&
242
- [...item.element.children].some(child =>
243
- EXPRESSION_SUMMARY.test(child.tagName),
244
- )
214
+ [...item.element.children].some(child => EXPRESSION_SUMMARY.test(child.tagName))
245
215
  );
246
216
  }
247
217
 
@@ -251,16 +221,10 @@ function isSummarised(item: ElementWithTabIndex): boolean {
251
221
  * @returns `true` if tabbable, otherwise `false`
252
222
  */
253
223
  export function isTabbable(element: Element): boolean {
254
- return element instanceof Element
255
- ? isValidElement(element, FILTERS_TABBABLE, true)
256
- : false;
224
+ return element instanceof Element ? isValidElement(element, FILTERS_TABBABLE, true) : false;
257
225
  }
258
226
 
259
- function isValidElement(
260
- element: Element,
261
- filters: Filter[],
262
- tabbable: boolean,
263
- ): boolean {
227
+ function isValidElement(element: Element, filters: Filter[], tabbable: boolean): boolean {
264
228
  const item = getItem(element, tabbable);
265
229
 
266
230
  return !filters.some(filter => filter(item));
package/src/html.ts CHANGED
@@ -1,9 +1,5 @@
1
1
  import {isPlainObject} from '@oscarpalmer/atoms/is';
2
- import {
3
- getSanitizeOptions,
4
- type SanitizeOptions,
5
- sanitizeNodes,
6
- } from './internal/sanitize';
2
+ import {getSanitizeOptions, type SanitizeOptions, sanitizeNodes} from './internal/sanitize';
7
3
 
8
4
  //
9
5
 
@@ -59,18 +55,13 @@ function createTemplate(html: string, ignore: boolean): HTMLTemplateElement {
59
55
  return template;
60
56
  }
61
57
 
62
- function getHtml(
63
- value: string | HTMLTemplateElement,
64
- options: Options,
65
- ): Node[] {
58
+ function getHtml(value: string | HTMLTemplateElement, options: Options): Node[] {
66
59
  if (typeof value !== 'string' && !(value instanceof HTMLTemplateElement)) {
67
60
  return [];
68
61
  }
69
62
 
70
63
  const template =
71
- value instanceof HTMLTemplateElement
72
- ? value
73
- : getTemplate(value, options.ignoreCache);
64
+ value instanceof HTMLTemplateElement ? value : getTemplate(value, options.ignoreCache);
74
65
 
75
66
  if (template == null) {
76
67
  return [];
@@ -92,8 +83,7 @@ function getHtml(
92
83
  function getOptions(input?: HtmlOptions): Options {
93
84
  const options = isPlainObject(input) ? input : {};
94
85
 
95
- options.ignoreCache =
96
- typeof options.ignoreCache === 'boolean' ? options.ignoreCache : false;
86
+ options.ignoreCache = typeof options.ignoreCache === 'boolean' ? options.ignoreCache : false;
97
87
 
98
88
  options.sanitizeBooleanAttributes =
99
89
  typeof options.sanitizeBooleanAttributes === 'boolean'
@@ -103,10 +93,7 @@ function getOptions(input?: HtmlOptions): Options {
103
93
  return options as Options;
104
94
  }
105
95
 
106
- function getTemplate(
107
- value: string,
108
- ignore: boolean,
109
- ): HTMLTemplateElement | undefined {
96
+ function getTemplate(value: string, ignore: boolean): HTMLTemplateElement | undefined {
110
97
  if (typeof value !== 'string' || value.trim().length === 0) {
111
98
  return;
112
99
  }
@@ -117,22 +104,14 @@ function getTemplate(
117
104
  return template;
118
105
  }
119
106
 
120
- const element = EXPRESSION_ID.test(value)
121
- ? document.querySelector(`#${value}`)
122
- : null;
107
+ const element = EXPRESSION_ID.test(value) ? document.querySelector(`#${value}`) : null;
123
108
 
124
- template =
125
- element instanceof HTMLTemplateElement
126
- ? element
127
- : createTemplate(value, ignore);
109
+ template = element instanceof HTMLTemplateElement ? element : createTemplate(value, ignore);
128
110
 
129
111
  return template;
130
112
  }
131
113
 
132
- const html = ((
133
- value: string | HTMLTemplateElement,
134
- options?: Options,
135
- ): Node[] => {
114
+ const html = ((value: string | HTMLTemplateElement, options?: Options): Node[] => {
136
115
  return getHtml(value, getOptions(options));
137
116
  }) as Html;
138
117
 
@@ -167,14 +146,8 @@ html.remove = (template: string): void => {
167
146
  * @param options Sanitization options
168
147
  * @returns Sanitized nodes
169
148
  */
170
- export function sanitize(
171
- value: Node | Node[],
172
- options?: SanitizeOptions,
173
- ): Node[] {
174
- return sanitizeNodes(
175
- Array.isArray(value) ? value : [value],
176
- getSanitizeOptions(options),
177
- );
149
+ export function sanitize(value: Node | Node[], options?: SanitizeOptions): Node[] {
150
+ return sanitizeNodes(Array.isArray(value) ? value : [value], getSanitizeOptions(options));
178
151
  }
179
152
 
180
153
  //
@@ -28,10 +28,7 @@ export function isBadAttribute(attribute: Attr | Attribute): boolean;
28
28
  */
29
29
  export function isBadAttribute(name: string, value: string): boolean;
30
30
 
31
- export function isBadAttribute(
32
- first: string | Attr | Attribute,
33
- second?: string,
34
- ): boolean {
31
+ export function isBadAttribute(first: string | Attr | Attribute, second?: string): boolean {
35
32
  return isValidAttribute(
36
33
  attribute =>
37
34
  attribute == null ||
@@ -59,9 +56,7 @@ export function isBooleanAttribute(name: string): boolean;
59
56
 
60
57
  export function isBooleanAttribute(value: string | Attr | Attribute): boolean {
61
58
  return isValidAttribute(
62
- attribute =>
63
- attribute != null &&
64
- booleanAttributes.includes(attribute.name.toLowerCase()),
59
+ attribute => attribute != null && booleanAttributes.includes(attribute.name.toLowerCase()),
65
60
  value,
66
61
  '',
67
62
  );
@@ -72,9 +67,7 @@ export function isBooleanAttribute(value: string | Attr | Attribute): boolean {
72
67
  * @param attribute Attribute to check
73
68
  * @returns `true` if attribute is empty and not a boolean attribute
74
69
  */
75
- export function isEmptyNonBooleanAttribute(
76
- attribute: Attr | Attribute,
77
- ): boolean;
70
+ export function isEmptyNonBooleanAttribute(attribute: Attr | Attribute): boolean;
78
71
 
79
72
  /**
80
73
  * Is the attribute empty and not a boolean attribute?
@@ -82,10 +75,7 @@ export function isEmptyNonBooleanAttribute(
82
75
  * @param value Attribute value
83
76
  * @returns `true` if attribute is empty and not a boolean attribute
84
77
  */
85
- export function isEmptyNonBooleanAttribute(
86
- name: string,
87
- value: string,
88
- ): boolean;
78
+ export function isEmptyNonBooleanAttribute(name: string, value: string): boolean;
89
79
 
90
80
  export function isEmptyNonBooleanAttribute(
91
81
  first: string | Attr | Attribute,
@@ -144,9 +134,7 @@ export function isInvalidBooleanAttribute(
144
134
  }
145
135
 
146
136
  export function isProperty(value: unknown): value is Property {
147
- return (
148
- isPlainObject(value) && typeof (value as PlainObject).name === 'string'
149
- );
137
+ return isPlainObject(value) && typeof (value as PlainObject).name === 'string';
150
138
  }
151
139
 
152
140
  function isValidAttribute(
@@ -165,11 +153,7 @@ function isValidAttribute(
165
153
  return callback(attribute);
166
154
  }
167
155
 
168
- function updateAttribute(
169
- element: HTMLOrSVGElement,
170
- name: string,
171
- value: unknown,
172
- ): void {
156
+ function updateAttribute(element: HTMLOrSVGElement, name: string, value: unknown): void {
173
157
  const isBoolean = booleanAttributes.includes(name.toLowerCase());
174
158
 
175
159
  if (isBoolean) {
@@ -183,34 +167,20 @@ function updateAttribute(
183
167
  }
184
168
  }
185
169
 
186
- function updateProperty(
187
- element: HTMLOrSVGElement,
188
- name: string,
189
- value: unknown,
190
- ): void {
170
+ function updateProperty(element: HTMLOrSVGElement, name: string, value: unknown): void {
191
171
  const actual = name.toLowerCase();
192
172
 
193
173
  (element as unknown as PlainObject)[actual] =
194
- value === '' ||
195
- (typeof value === 'string' && value.toLowerCase() === actual) ||
196
- value === true;
174
+ value === '' || (typeof value === 'string' && value.toLowerCase() === actual) || value === true;
197
175
  }
198
176
 
199
- export function updateValue(
200
- element: HTMLOrSVGElement,
201
- first: unknown,
202
- second: unknown,
203
- ): void {
177
+ export function updateValue(element: HTMLOrSVGElement, first: unknown, second: unknown): void {
204
178
  if (!isHTMLOrSVGElement(element)) {
205
179
  return;
206
180
  }
207
181
 
208
182
  if (isProperty(first)) {
209
- updateAttribute(
210
- element,
211
- (first as Attribute).name,
212
- (first as Attribute).value,
213
- );
183
+ updateAttribute(element, (first as Attribute).name, (first as Attribute).value);
214
184
  } else if (typeof first === 'string') {
215
185
  updateAttribute(element, first as string, second);
216
186
  }
@@ -232,11 +202,7 @@ export function updateValues(
232
202
  const entry = entries[index];
233
203
 
234
204
  if (isArray) {
235
- updateAttribute(
236
- element,
237
- (entry[1] as Attribute).name,
238
- (entry[1] as Attribute).value,
239
- );
205
+ updateAttribute(element, (entry[1] as Attribute).name, (entry[1] as Attribute).value);
240
206
  } else {
241
207
  updateAttribute(element, entry[0], entry[1]);
242
208
  }