@oscarpalmer/toretto 0.26.1 → 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.
@@ -1,5 +1,5 @@
1
- import { isHTMLOrSVGElement } from "../internal/is.js";
2
1
  import { getAttributeValue } from "../internal/get-value.js";
2
+ import { isHTMLOrSVGElement } from "../internal/is.js";
3
3
  function getAttribute(element, name, parseValues) {
4
4
  if (isHTMLOrSVGElement(element) && typeof name === "string") return getAttributeValue(element, name, parseValues !== false);
5
5
  }
@@ -1,4 +1,4 @@
1
- import { booleanAttributes, isBadAttribute, isBooleanAttribute, isEmptyNonBooleanAttribute, isInvalidBooleanAttribute } from "../internal/attribute.js";
2
1
  import { getAttribute, getAttributes } from "./get.js";
2
+ import { booleanAttributes, isBadAttribute, isBooleanAttribute, isEmptyNonBooleanAttribute, isInvalidBooleanAttribute } from "../internal/attribute.js";
3
3
  import { setAttribute, setAttributes, setProperties, setProperty } from "./set.js";
4
4
  export { booleanAttributes, getAttribute, getAttributes, isBadAttribute, isBooleanAttribute, isEmptyNonBooleanAttribute, isInvalidBooleanAttribute, setAttribute, setAttributes, setProperties, setProperty };
@@ -1,14 +1,14 @@
1
- import { updateAttribute, updateProperty, updateValue, updateValues } from "./update.js";
1
+ import { updateValue, updateValues } from "../internal/attribute.js";
2
2
  function setAttribute(element, first, second) {
3
- updateValue(element, first, second, updateAttribute);
3
+ updateValue(element, first, second);
4
4
  }
5
5
  function setAttributes(element, attributes) {
6
6
  updateValues(element, attributes);
7
7
  }
8
8
  function setProperty(element, first, second) {
9
- updateValue(element, first, second, updateProperty);
9
+ updateValue(element, first, second);
10
10
  }
11
11
  function setProperties(element, properties) {
12
- updateValues(element, properties, updateProperty);
12
+ updateValues(element, properties);
13
13
  }
14
14
  export { setAttribute, setAttributes, setProperties, setProperty };
package/dist/data.js CHANGED
@@ -1,6 +1,6 @@
1
+ import { EXPRESSION_DATA_PREFIX } from "./internal/get-value.js";
1
2
  import { isHTMLOrSVGElement } from "./internal/is.js";
2
3
  import { setElementValues, updateElementValue } from "./internal/element-value.js";
3
- import { EXPRESSION_DATA_PREFIX } from "./internal/get-value.js";
4
4
  import { kebabCase, parse } from "@oscarpalmer/atoms/string";
5
5
  function getData(element, keys, parseValues) {
6
6
  if (!isHTMLOrSVGElement(element)) return;
@@ -1,11 +1,11 @@
1
1
  import { isEventTarget } from "../internal/is.js";
2
2
  function addDelegatedHandler(document$1, type, name, passive) {
3
- const listeners = `${name}${LISTENERS_SUFFIX}`;
4
- if (document$1[listeners] != null) {
5
- document$1[listeners] += 1;
3
+ const count = `${name}${COUNT_SUFFIX}`;
4
+ if (document$1[count] != null) {
5
+ document$1[count] += 1;
6
6
  return;
7
7
  }
8
- document$1[listeners] = 1;
8
+ document$1[count] = 1;
9
9
  document$1.addEventListener(type, passive ? HANDLER_PASSIVE : HANDLER_ACTIVE, { passive });
10
10
  }
11
11
  function addDelegatedListener(target, type, name, listener, passive) {
@@ -27,15 +27,14 @@ function delegatedEventHandler(event) {
27
27
  for (let index = 0; index < length; index += 1) {
28
28
  const item = items[index];
29
29
  const listeners = item[key];
30
- if (!item.disabled && listeners != null) {
31
- Object.defineProperty(event, "currentTarget", {
32
- configurable: true,
33
- value: item
34
- });
35
- for (const listener of listeners) {
36
- listener.call(item, event);
37
- if (event.cancelBubble) return;
38
- }
30
+ if (item.disabled || listeners == null) continue;
31
+ Object.defineProperty(event, "currentTarget", {
32
+ configurable: true,
33
+ value: item
34
+ });
35
+ for (const listener of listeners) {
36
+ listener.call(item, event);
37
+ if (event.cancelBubble) return;
39
38
  }
40
39
  }
41
40
  }
@@ -43,10 +42,10 @@ function getDelegatedName(target, type, options) {
43
42
  if (isEventTarget(target) && EVENT_TYPES.has(type) && !options.capture && !options.once && options.signal == null) return `${EVENT_PREFIX}${type}${options.passive ? EVENT_SUFFIX_PASSIVE : EVENT_SUFFIX_ACTIVE}`;
44
43
  }
45
44
  function removeDelegatedHandler(document$1, type, name, passive) {
46
- const listeners = `${name}${LISTENERS_SUFFIX}`;
47
- document$1[listeners] -= 1;
48
- if (document$1[listeners] < 1) {
49
- document$1[listeners] = void 0;
45
+ const count = `${name}${COUNT_SUFFIX}`;
46
+ document$1[count] -= 1;
47
+ if (document$1[count] < 1) {
48
+ document$1[count] = void 0;
50
49
  document$1.removeEventListener(type, passive ? HANDLER_PASSIVE : HANDLER_ACTIVE);
51
50
  }
52
51
  }
@@ -54,10 +53,11 @@ function removeDelegatedListener(target, type, name, listener, passive) {
54
53
  const handlers = target[name];
55
54
  if (handlers == null || !handlers.has(listener)) return false;
56
55
  handlers.delete(listener);
57
- if (handlers?.size === 0) target[name] = void 0;
56
+ if (handlers.size === 0) target[name] = void 0;
58
57
  removeDelegatedHandler(document, type, name, passive);
59
58
  return true;
60
59
  }
60
+ var COUNT_SUFFIX = ".count";
61
61
  var EVENT_PREFIX = "@";
62
62
  var EVENT_SUFFIX_ACTIVE = ":active";
63
63
  var EVENT_SUFFIX_PASSIVE = ":passive";
@@ -87,5 +87,4 @@ var EVENT_TYPES = new Set([
87
87
  ]);
88
88
  var HANDLER_ACTIVE = delegatedEventHandler.bind(false);
89
89
  var HANDLER_PASSIVE = delegatedEventHandler.bind(true);
90
- var LISTENERS_SUFFIX = ":listeners";
91
90
  export { addDelegatedListener, getDelegatedName, removeDelegatedListener };
@@ -1,5 +1,5 @@
1
- import { isEventTarget } from "../internal/is.js";
2
1
  import { getBoolean } from "../internal/get-value.js";
2
+ import { isEventTarget } from "../internal/is.js";
3
3
  import { addDelegatedListener, getDelegatedName, removeDelegatedListener } from "./delegation.js";
4
4
  import { isPlainObject } from "@oscarpalmer/atoms/is";
5
5
  import { noop } from "@oscarpalmer/atoms/function";
package/dist/index.js CHANGED
@@ -1,15 +1,15 @@
1
- import touch_default from "./touch.js";
2
1
  import { isEventTarget, isHTMLOrSVGElement } from "./internal/is.js";
3
- import { isChildNode, isInDocument } from "./is.js";
4
- import { getStyle, getStyles, getTextDirection, setStyle, setStyles, toggleStyles } from "./style.js";
5
- import { booleanAttributes, isBadAttribute, isBooleanAttribute, isEmptyNonBooleanAttribute, isInvalidBooleanAttribute } from "./internal/attribute.js";
6
2
  import { getAttribute, getAttributes } from "./attribute/get.js";
3
+ import { booleanAttributes, isBadAttribute, isBooleanAttribute, isEmptyNonBooleanAttribute, isInvalidBooleanAttribute } from "./internal/attribute.js";
7
4
  import { setAttribute, setAttributes, setProperties, setProperty } from "./attribute/set.js";
8
5
  import "./attribute/index.js";
6
+ import { isChildNode, isInDocument } from "./is.js";
9
7
  import { getData, setData } from "./data.js";
10
8
  import { dispatch, getPosition, off, on } from "./event/index.js";
11
9
  import { findAncestor, findRelatives } from "./find/relative.js";
12
10
  import { $ as findElement, $$ as findElements, getElementUnderPointer } from "./find/index.js";
13
11
  import { getFocusable, getTabbable, isFocusable, isTabbable } from "./focusable.js";
14
12
  import { html, sanitize } from "./html.js";
13
+ import touch_default from "./touch.js";
14
+ import { getStyle, getStyles, getTextDirection, setStyle, setStyles, toggleStyles } from "./style.js";
15
15
  export { findElement as $, findElement, findElements as $$, findElements, booleanAttributes, dispatch, findAncestor, findRelatives, getAttribute, getAttributes, getData, getElementUnderPointer, getFocusable, getPosition, getStyle, getStyles, getTabbable, getTextDirection, html, isBadAttribute, isBooleanAttribute, isChildNode, isEmptyNonBooleanAttribute, isEventTarget, isFocusable, isHTMLOrSVGElement, isInDocument, isInvalidBooleanAttribute, isTabbable, off, on, sanitize, setAttribute, setAttributes, setData, setProperties, setProperty, setStyle, setStyles, touch_default as supportsTouch, toggleStyles };
@@ -1,3 +1,5 @@
1
+ import { isHTMLOrSVGElement } from "./is.js";
2
+ import { getString } from "@oscarpalmer/atoms/string";
1
3
  import { isPlainObject } from "@oscarpalmer/atoms/is";
2
4
  function isAttribute(value) {
3
5
  return value instanceof Attr || isPlainObject(value) && typeof value.name === "string" && typeof value.value === "string";
@@ -19,6 +21,9 @@ function isInvalidBooleanAttribute(first, second) {
19
21
  return !(normalized.length === 0 || normalized === attribute.name);
20
22
  }, first, second);
21
23
  }
24
+ function isProperty(value) {
25
+ return isPlainObject(value) && typeof value.name === "string";
26
+ }
22
27
  function isValidAttribute(callback, first, second) {
23
28
  let attribute;
24
29
  if (isAttribute(first)) attribute = first;
@@ -28,6 +33,32 @@ function isValidAttribute(callback, first, second) {
28
33
  };
29
34
  return callback(attribute);
30
35
  }
36
+ function updateAttribute(element, name, value) {
37
+ const isBoolean = booleanAttributes.includes(name.toLowerCase());
38
+ if (isBoolean) updateProperty(element, name, value);
39
+ if (isBoolean ? value !== true : value == null) element.removeAttribute(name);
40
+ else element.setAttribute(name, isBoolean ? "" : getString(value));
41
+ }
42
+ function updateProperty(element, name, value) {
43
+ const actual = name.toLowerCase();
44
+ element[actual] = value === "" || typeof value === "string" && value.toLowerCase() === actual || value === true;
45
+ }
46
+ function updateValue(element, first, second) {
47
+ if (!isHTMLOrSVGElement(element)) return;
48
+ if (isProperty(first)) updateAttribute(element, first.name, first.value);
49
+ else if (typeof first === "string") updateAttribute(element, first, second);
50
+ }
51
+ function updateValues(element, values) {
52
+ if (!isHTMLOrSVGElement(element)) return;
53
+ const isArray = Array.isArray(values);
54
+ const entries = Object.entries(values);
55
+ const { length } = entries;
56
+ for (let index = 0; index < length; index += 1) {
57
+ const entry = entries[index];
58
+ if (isArray) updateAttribute(element, entry[1].name, entry[1].value);
59
+ else updateAttribute(element, entry[0], entry[1]);
60
+ }
61
+ }
31
62
  var EXPRESSION_ON_PREFIX = /^on/i;
32
63
  var EXPRESSION_SOURCE_PREFIX = /^(href|src|xlink:href)$/i;
33
64
  var EXPRESSION_VALUE_PREFIX = /(data:text\/html|javascript:)/i;
@@ -57,4 +88,4 @@ const booleanAttributes = Object.freeze([
57
88
  "reversed",
58
89
  "selected"
59
90
  ]);
60
- export { booleanAttributes, isBadAttribute, isBooleanAttribute, isEmptyNonBooleanAttribute, isInvalidBooleanAttribute };
91
+ export { booleanAttributes, isBadAttribute, isBooleanAttribute, isEmptyNonBooleanAttribute, isInvalidBooleanAttribute, isProperty, updateValue, updateValues };
package/dist/style.js CHANGED
@@ -1,6 +1,6 @@
1
+ import { getStyleValue } from "./internal/get-value.js";
1
2
  import { isHTMLOrSVGElement } from "./internal/is.js";
2
3
  import { setElementValues, updateElementValue } from "./internal/element-value.js";
3
- import { getStyleValue } from "./internal/get-value.js";
4
4
  function getStyle(element, property, computed) {
5
5
  if (!isHTMLOrSVGElement(element) || typeof property !== "string") return;
6
6
  return getStyleValue(element, property, computed === true);