@oscarpalmer/toretto 0.43.0 → 0.45.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/data.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import { isHTMLOrSVGElement } from "./internal/is.mjs";
2
2
  import { setElementValues, updateElementValue } from "./internal/element-value.mjs";
3
3
  import { EXPRESSION_DATA_PREFIX } from "./internal/get-value.mjs";
4
- import { camelCase, kebabCase } from "@oscarpalmer/atoms/string/case";
5
4
  import { parse } from "@oscarpalmer/atoms/string";
5
+ import { camelCase, kebabCase } from "@oscarpalmer/atoms/string/case";
6
6
  //#region src/data.ts
7
7
  function getData(element, keys, parseValues) {
8
8
  if (!isHTMLOrSVGElement(element)) return;
package/dist/index.d.mts CHANGED
@@ -462,6 +462,12 @@ declare function isEventTarget(value: unknown): value is EventTarget;
462
462
  * @returns `true` if it's an HTML or SVG element, otherwise `false`
463
463
  */
464
464
  declare function isHTMLOrSVGElement(value: unknown): value is HTMLElement | SVGElement;
465
+ /**
466
+ * Is the value an input element? _(`<input>`, `<select>`, or `<textarea>`)_
467
+ * @param value Value to check
468
+ * @returns `true` if it's an input element, otherwise `false`
469
+ */
470
+ declare function isInputElement(value: unknown): value is HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
465
471
  //#endregion
466
472
  //#region src/is.d.ts
467
473
  /**
@@ -591,4 +597,4 @@ declare function setStyles(element: Element, styles: Styles): void;
591
597
  */
592
598
  declare function toggleStyles(element: Element, styles: Styles): StyleToggler;
593
599
  //#endregion
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 };
600
+ 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, isInputElement, isInvalidBooleanAttribute, isTabbable, off, on, sanitize, setAttribute, setAttributes, setData, setProperties, setProperty, setStyle, setStyles, supportsTouch, toggleStyles };
package/dist/index.mjs CHANGED
@@ -105,6 +105,21 @@ function isNullableOrWhitespace(value) {
105
105
  }
106
106
  const EXPRESSION_WHITESPACE$1 = /^\s*$/;
107
107
  //#endregion
108
+ //#region node_modules/@oscarpalmer/atoms/dist/string/index.mjs
109
+ /**
110
+ * Parse a JSON string into its proper value _(or `undefined` if it fails)_
111
+ * @param value JSON string to parse
112
+ * @param reviver Reviver function to transform the parsed values
113
+ * @returns Parsed value or `undefined` if parsing fails
114
+ */
115
+ function parse(value, reviver) {
116
+ try {
117
+ return JSON.parse(value, reviver);
118
+ } catch {
119
+ return;
120
+ }
121
+ }
122
+ //#endregion
108
123
  //#region node_modules/@oscarpalmer/atoms/dist/internal/number.mjs
109
124
  /**
110
125
  * Clamp a number between a minimum and maximum value
@@ -382,6 +397,14 @@ function isEventTarget(value) {
382
397
  function isHTMLOrSVGElement(value) {
383
398
  return value instanceof HTMLElement || value instanceof SVGElement;
384
399
  }
400
+ /**
401
+ * Is the value an input element? _(`<input>`, `<select>`, or `<textarea>`)_
402
+ * @param value Value to check
403
+ * @returns `true` if it's an input element, otherwise `false`
404
+ */
405
+ function isInputElement(value) {
406
+ return value instanceof HTMLInputElement || value instanceof HTMLSelectElement || value instanceof HTMLTextAreaElement;
407
+ }
385
408
  //#endregion
386
409
  //#region src/is.ts
387
410
  /**
@@ -406,6 +429,10 @@ const CHILD_NODE_TYPES = new Set([
406
429
  ]);
407
430
  //#endregion
408
431
  //#region src/internal/element-value.ts
432
+ function ignoreSetAttribute(element, name) {
433
+ if (element instanceof HTMLTextAreaElement && name === "value") return true;
434
+ return false;
435
+ }
409
436
  function normalizeKey(key, style) {
410
437
  return style && key.startsWith(CSS_VARIABLE_PREFIX$1) ? key : kebabCase(key);
411
438
  }
@@ -435,16 +462,21 @@ function setElementValues(element, first, second, third, callback, style) {
435
462
  }
436
463
  function updateElementValue(element, key, value, set, remove, isBoolean, json) {
437
464
  if (isBoolean ? value == null : isNullableOrWhitespace(value)) remove.call(element, key);
438
- else set.call(element, key, json ? JSON.stringify(value) : String(value));
465
+ else if (!ignoreSetAttribute(element, key)) set.call(element, key, json ? JSON.stringify(value) : getString(value));
439
466
  }
440
467
  const CSS_VARIABLE_PREFIX$1 = "--";
441
468
  //#endregion
442
469
  //#region src/internal/property.ts
470
+ function getPropertyValue$1(element, name, value) {
471
+ if (isInputElement(element) && name === "value") return getString(value);
472
+ return value;
473
+ }
443
474
  function updateProperty(element, name, value, dispatch) {
444
475
  let property = name;
445
476
  if (!(property in element)) property = camelCase(name);
446
- if (!(property in element) || Object.is(element[property], value)) return;
447
- element[property] = value;
477
+ const next = getPropertyValue$1(element, name, value);
478
+ if (!(property in element) || Object.is(element[property], next)) return;
479
+ element[property] = next;
448
480
  const event = dispatch && elementEvents[element.tagName]?.[property];
449
481
  if (typeof event === "string") element.dispatchEvent(new Event(event, {
450
482
  bubbles: true,
@@ -485,7 +517,7 @@ function handleAttribute(callback, decode, first, second) {
485
517
  let value;
486
518
  if (isAttribute(first)) {
487
519
  name = first.name;
488
- value = String(first.value);
520
+ value = getString(first.value);
489
521
  } else if (typeof first === "string" && typeof second === "string") {
490
522
  name = first;
491
523
  value = second;
@@ -562,21 +594,6 @@ const dispatchedAttributes = new Set([
562
594
  const formElement = document.createElement("form");
563
595
  let textArea;
564
596
  //#endregion
565
- //#region node_modules/@oscarpalmer/atoms/dist/string/index.mjs
566
- /**
567
- * Parse a JSON string into its proper value _(or `undefined` if it fails)_
568
- * @param value JSON string to parse
569
- * @param reviver Reviver function to transform the parsed values
570
- * @returns Parsed value or `undefined` if parsing fails
571
- */
572
- function parse(value, reviver) {
573
- try {
574
- return JSON.parse(value, reviver);
575
- } catch {
576
- return;
577
- }
578
- }
579
- //#endregion
580
597
  //#region src/internal/get-value.ts
581
598
  function getBoolean(value, defaultValue) {
582
599
  return typeof value === "boolean" ? value : defaultValue ?? false;
@@ -725,8 +742,8 @@ function toggleStyles(element, styles) {
725
742
  }
726
743
  function updateStyleProperty(element, key, value) {
727
744
  updateElementValue(element, key, value, function(property, style) {
728
- if (property.startsWith(VARIABLE_PREFIX)) this.style.setProperty(property, String(style));
729
- else this.style[property] = String(style);
745
+ if (property.startsWith(VARIABLE_PREFIX)) this.style.setProperty(property, getString(style));
746
+ else this.style[property] = getString(style);
730
747
  }, function(property) {
731
748
  if (property.startsWith(VARIABLE_PREFIX)) this.style.removeProperty(property);
732
749
  else this.style[property] = "";
@@ -1514,4 +1531,4 @@ const templates = new SizedMap(128);
1514
1531
  let parser;
1515
1532
  window.templates = templates;
1516
1533
  //#endregion
1517
- export { findElement as $, findElement, findElements as $$, findElements, 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 };
1534
+ export { findElement as $, findElement, findElements as $$, findElements, 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, isInputElement, isInvalidBooleanAttribute, isTabbable, off, on, sanitize, setAttribute, setAttributes, setData, setProperties, setProperty, setStyle, setStyles, supportsTouch, toggleStyles };
@@ -1,6 +1,7 @@
1
1
  import { updateElementValue } from "./element-value.mjs";
2
2
  import { updateProperty } from "./property.mjs";
3
3
  import { isPlainObject } from "@oscarpalmer/atoms/is";
4
+ import { getString } from "@oscarpalmer/atoms/string";
4
5
  import { kebabCase } from "@oscarpalmer/atoms/string/case";
5
6
  //#region src/internal/attribute.ts
6
7
  function badAttributeHandler(name, value) {
@@ -26,7 +27,7 @@ function handleAttribute(callback, decode, first, second) {
26
27
  let value;
27
28
  if (isAttribute(first)) {
28
29
  name = first.name;
29
- value = String(first.value);
30
+ value = getString(first.value);
30
31
  } else if (typeof first === "string" && typeof second === "string") {
31
32
  name = first;
32
33
  value = second;
@@ -2,8 +2,13 @@ import { isHTMLOrSVGElement } from "./is.mjs";
2
2
  import "../is.mjs";
3
3
  import { isAttribute } from "./attribute.mjs";
4
4
  import { isNullableOrWhitespace } from "@oscarpalmer/atoms/is";
5
+ import { getString } from "@oscarpalmer/atoms/string";
5
6
  import { kebabCase } from "@oscarpalmer/atoms/string/case";
6
7
  //#region src/internal/element-value.ts
8
+ function ignoreSetAttribute(element, name) {
9
+ if (element instanceof HTMLTextAreaElement && name === "value") return true;
10
+ return false;
11
+ }
7
12
  function normalizeKey(key, style) {
8
13
  return style && key.startsWith(CSS_VARIABLE_PREFIX) ? key : kebabCase(key);
9
14
  }
@@ -33,7 +38,7 @@ function setElementValues(element, first, second, third, callback, style) {
33
38
  }
34
39
  function updateElementValue(element, key, value, set, remove, isBoolean, json) {
35
40
  if (isBoolean ? value == null : isNullableOrWhitespace(value)) remove.call(element, key);
36
- else set.call(element, key, json ? JSON.stringify(value) : String(value));
41
+ else if (!ignoreSetAttribute(element, key)) set.call(element, key, json ? JSON.stringify(value) : getString(value));
37
42
  }
38
43
  const CSS_VARIABLE_PREFIX = "--";
39
44
  //#endregion
@@ -1,5 +1,5 @@
1
- import { camelCase, kebabCase } from "@oscarpalmer/atoms/string/case";
2
1
  import { parse } from "@oscarpalmer/atoms/string";
2
+ import { camelCase, kebabCase } from "@oscarpalmer/atoms/string/case";
3
3
  //#region src/internal/get-value.ts
4
4
  function getBoolean(value, defaultValue) {
5
5
  return typeof value === "boolean" ? value : defaultValue ?? false;
@@ -11,5 +11,11 @@ declare function isEventTarget(value: unknown): value is EventTarget;
11
11
  * @returns `true` if it's an HTML or SVG element, otherwise `false`
12
12
  */
13
13
  declare function isHTMLOrSVGElement(value: unknown): value is HTMLElement | SVGElement;
14
+ /**
15
+ * Is the value an input element? _(`<input>`, `<select>`, or `<textarea>`)_
16
+ * @param value Value to check
17
+ * @returns `true` if it's an input element, otherwise `false`
18
+ */
19
+ declare function isInputElement(value: unknown): value is HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
14
20
  //#endregion
15
- export { isEventTarget, isHTMLOrSVGElement };
21
+ export { isEventTarget, isHTMLOrSVGElement, isInputElement };
@@ -15,5 +15,13 @@ function isEventTarget(value) {
15
15
  function isHTMLOrSVGElement(value) {
16
16
  return value instanceof HTMLElement || value instanceof SVGElement;
17
17
  }
18
+ /**
19
+ * Is the value an input element? _(`<input>`, `<select>`, or `<textarea>`)_
20
+ * @param value Value to check
21
+ * @returns `true` if it's an input element, otherwise `false`
22
+ */
23
+ function isInputElement(value) {
24
+ return value instanceof HTMLInputElement || value instanceof HTMLSelectElement || value instanceof HTMLTextAreaElement;
25
+ }
18
26
  //#endregion
19
- export { isEventTarget, isHTMLOrSVGElement };
27
+ export { isEventTarget, isHTMLOrSVGElement, isInputElement };
@@ -1,10 +1,17 @@
1
+ import { isInputElement } from "./is.mjs";
2
+ import { getString } from "@oscarpalmer/atoms/string";
1
3
  import { camelCase } from "@oscarpalmer/atoms/string/case";
2
4
  //#region src/internal/property.ts
5
+ function getPropertyValue(element, name, value) {
6
+ if (isInputElement(element) && name === "value") return getString(value);
7
+ return value;
8
+ }
3
9
  function updateProperty(element, name, value, dispatch) {
4
10
  let property = name;
5
11
  if (!(property in element)) property = camelCase(name);
6
- if (!(property in element) || Object.is(element[property], value)) return;
7
- element[property] = value;
12
+ const next = getPropertyValue(element, name, value);
13
+ if (!(property in element) || Object.is(element[property], next)) return;
14
+ element[property] = next;
8
15
  const event = dispatch && elementEvents[element.tagName]?.[property];
9
16
  if (typeof event === "string") element.dispatchEvent(new Event(event, {
10
17
  bubbles: true,
package/dist/is.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { isEventTarget, isHTMLOrSVGElement } from "./internal/is.mjs";
1
+ import { isEventTarget, isHTMLOrSVGElement, isInputElement } from "./internal/is.mjs";
2
2
 
3
3
  //#region src/is.d.ts
4
4
  /**
@@ -21,4 +21,4 @@ declare function isInDocument(node: Node): boolean;
21
21
  */
22
22
  declare function isInDocument(node: Node, document: Document): boolean;
23
23
  //#endregion
24
- export { isChildNode, isEventTarget, isHTMLOrSVGElement, isInDocument };
24
+ export { isChildNode, isEventTarget, isHTMLOrSVGElement, isInDocument, isInputElement };
package/dist/is.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { isEventTarget, isHTMLOrSVGElement } from "./internal/is.mjs";
1
+ import { isEventTarget, isHTMLOrSVGElement, isInputElement } from "./internal/is.mjs";
2
2
  //#region src/is.ts
3
3
  /**
4
4
  * Is the value a child node?
@@ -21,4 +21,4 @@ const CHILD_NODE_TYPES = new Set([
21
21
  Node.DOCUMENT_TYPE_NODE
22
22
  ]);
23
23
  //#endregion
24
- export { isChildNode, isEventTarget, isHTMLOrSVGElement, isInDocument };
24
+ export { isChildNode, isEventTarget, isHTMLOrSVGElement, isInDocument, isInputElement };
package/dist/style.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { isHTMLOrSVGElement } from "./internal/is.mjs";
2
2
  import { setElementValues, updateElementValue } from "./internal/element-value.mjs";
3
3
  import { getStyleValue } from "./internal/get-value.mjs";
4
+ import { getString } from "@oscarpalmer/atoms/string";
4
5
  //#region src/style.ts
5
6
  /**
6
7
  * Get a style from an element
@@ -89,8 +90,8 @@ function toggleStyles(element, styles) {
89
90
  }
90
91
  function updateStyleProperty(element, key, value) {
91
92
  updateElementValue(element, key, value, function(property, style) {
92
- if (property.startsWith(VARIABLE_PREFIX)) this.style.setProperty(property, String(style));
93
- else this.style[property] = String(style);
93
+ if (property.startsWith(VARIABLE_PREFIX)) this.style.setProperty(property, getString(style));
94
+ else this.style[property] = getString(style);
94
95
  }, function(property) {
95
96
  if (property.startsWith(VARIABLE_PREFIX)) this.style.removeProperty(property);
96
97
  else this.style[property] = "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oscarpalmer/toretto",
3
- "version": "0.43.0",
3
+ "version": "0.45.0",
4
4
  "description": "A collection of badass DOM utilities.",
5
5
  "keywords": [
6
6
  "dom",
@@ -1,5 +1,6 @@
1
1
  import {isPlainObject} from '@oscarpalmer/atoms/is';
2
2
  import type {PlainObject} from '@oscarpalmer/atoms/models';
3
+ import {getString} from '@oscarpalmer/atoms/string';
3
4
  import {kebabCase} from '@oscarpalmer/atoms/string/case';
4
5
  import type {Attribute} from '../models';
5
6
  import {updateElementValue} from './element-value';
@@ -65,7 +66,7 @@ function handleAttribute(
65
66
 
66
67
  if (isAttribute(first)) {
67
68
  name = first.name;
68
- value = String(first.value);
69
+ value = getString(first.value);
69
70
  } else if (typeof first === 'string' && typeof second === 'string') {
70
71
  name = first;
71
72
  value = second;
@@ -1,10 +1,19 @@
1
1
  import {isNullableOrWhitespace} from '@oscarpalmer/atoms/is';
2
+ import {getString} from '@oscarpalmer/atoms/string';
2
3
  import {kebabCase} from '@oscarpalmer/atoms/string/case';
3
4
  import {isHTMLOrSVGElement} from '../is';
4
5
  import {isAttribute} from './attribute';
5
6
 
6
7
  // #region Functions
7
8
 
9
+ function ignoreSetAttribute(element: Element, name: string): boolean {
10
+ if (element instanceof HTMLTextAreaElement && name === 'value') {
11
+ return true;
12
+ }
13
+
14
+ return false;
15
+ }
16
+
8
17
  function normalizeKey(key: string, style?: boolean): string {
9
18
  return style && key.startsWith(CSS_VARIABLE_PREFIX) ? key : kebabCase(key);
10
19
  }
@@ -77,8 +86,8 @@ export function updateElementValue(
77
86
  ): void {
78
87
  if (isBoolean ? value == null : isNullableOrWhitespace(value)) {
79
88
  remove.call(element, key);
80
- } else {
81
- set.call(element, key, json ? JSON.stringify(value) : String(value));
89
+ } else if (!ignoreSetAttribute(element, key)) {
90
+ set.call(element, key, json ? JSON.stringify(value) : getString(value));
82
91
  }
83
92
  }
84
93
 
@@ -24,4 +24,19 @@ export function isHTMLOrSVGElement(value: unknown): value is HTMLElement | SVGEl
24
24
  return value instanceof HTMLElement || value instanceof SVGElement;
25
25
  }
26
26
 
27
+ /**
28
+ * Is the value an input element? _(`<input>`, `<select>`, or `<textarea>`)_
29
+ * @param value Value to check
30
+ * @returns `true` if it's an input element, otherwise `false`
31
+ */
32
+ export function isInputElement(
33
+ value: unknown,
34
+ ): value is HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement {
35
+ return (
36
+ value instanceof HTMLInputElement ||
37
+ value instanceof HTMLSelectElement ||
38
+ value instanceof HTMLTextAreaElement
39
+ );
40
+ }
41
+
27
42
  // #endregion
@@ -1,8 +1,18 @@
1
1
  import type {PlainObject} from '@oscarpalmer/atoms/models';
2
+ import {getString} from '@oscarpalmer/atoms/string';
2
3
  import {camelCase} from '@oscarpalmer/atoms/string/case';
4
+ import {isInputElement} from './is';
3
5
 
4
6
  // #region Functions
5
7
 
8
+ function getPropertyValue(element: Element, name: string, value: unknown): unknown {
9
+ if (isInputElement(element) && name === 'value') {
10
+ return getString(value);
11
+ }
12
+
13
+ return value;
14
+ }
15
+
6
16
  export function updateProperty(
7
17
  element: Element,
8
18
  name: string,
@@ -15,11 +25,13 @@ export function updateProperty(
15
25
  property = camelCase(name);
16
26
  }
17
27
 
18
- if (!(property in element) || Object.is((element as unknown as PlainObject)[property], value)) {
28
+ const next = getPropertyValue(element, name, value);
29
+
30
+ if (!(property in element) || Object.is((element as unknown as PlainObject)[property], next)) {
19
31
  return;
20
32
  }
21
33
 
22
- (element as unknown as PlainObject)[property] = value;
34
+ (element as unknown as PlainObject)[property] = next;
23
35
 
24
36
  const event = dispatch && elementEvents[element.tagName]?.[property];
25
37
 
package/src/is.ts CHANGED
@@ -54,6 +54,6 @@ const CHILD_NODE_TYPES: Set<number> = new Set([
54
54
 
55
55
  // #region Exports
56
56
 
57
- export {isEventTarget, isHTMLOrSVGElement} from './internal/is';
57
+ export {isEventTarget, isHTMLOrSVGElement, isInputElement} from './internal/is';
58
58
 
59
59
  // #endregion
package/src/style.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import {getString} from '@oscarpalmer/atoms/string';
1
2
  import {setElementValues, updateElementValue} from './internal/element-value';
2
3
  import {getStyleValue} from './internal/get-value';
3
4
  import {isHTMLOrSVGElement} from './internal/is';
@@ -187,9 +188,9 @@ function updateStyleProperty(element: Element, key: string, value: unknown): voi
187
188
  value,
188
189
  function (this: Element, property: string, style: unknown) {
189
190
  if (property.startsWith(VARIABLE_PREFIX)) {
190
- (this as HTMLElement).style.setProperty(property, String(style));
191
+ (this as HTMLElement).style.setProperty(property, getString(style));
191
192
  } else {
192
- (this as HTMLElement).style[property as never] = String(style);
193
+ (this as HTMLElement).style[property as never] = getString(style);
193
194
  }
194
195
  },
195
196
  function (this: Element, property: string) {