@oscarpalmer/toretto 0.38.0 → 0.39.1

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,6 @@
1
1
  import { getAttributeValue } from "../internal/get-value.js";
2
2
  import { isHTMLOrSVGElement } from "../internal/is.js";
3
+ //#region src/attribute/get.ts
3
4
  function getAttribute(element, name, parseValues) {
4
5
  if (isHTMLOrSVGElement(element) && typeof name === "string") return getAttributeValue(element, name, parseValues !== false);
5
6
  }
@@ -21,4 +22,5 @@ function getAttributes(element, names, parseData) {
21
22
  }
22
23
  return attributes;
23
24
  }
25
+ //#endregion
24
26
  export { getAttribute, getAttributes };
@@ -1,6 +1,7 @@
1
1
  import { getAttribute, getAttributes } from "./get.js";
2
2
  import { _isBadAttribute, _isBooleanAttribute, _isEmptyNonBooleanAttribute, _isInvalidBooleanAttribute, booleanAttributes } from "../internal/attribute.js";
3
3
  import { setAttribute, setAttributes } from "./set.js";
4
+ //#region src/attribute/index.ts
4
5
  function isBadAttribute(first, second) {
5
6
  return _isBadAttribute(first, second, true);
6
7
  }
@@ -13,4 +14,5 @@ function isEmptyNonBooleanAttribute(first, second) {
13
14
  function isInvalidBooleanAttribute(first, second) {
14
15
  return _isInvalidBooleanAttribute(first, second, true);
15
16
  }
17
+ //#endregion
16
18
  export { booleanAttributes, getAttribute, getAttributes, isBadAttribute, isBooleanAttribute, isEmptyNonBooleanAttribute, isInvalidBooleanAttribute, setAttribute, setAttributes };
@@ -1,9 +1,11 @@
1
1
  import { setElementValue, setElementValues } from "../internal/element-value.js";
2
2
  import { updateAttribute } from "../internal/attribute.js";
3
+ //#region src/attribute/set.ts
3
4
  function setAttribute(element, first, second, third) {
4
5
  setElementValue(element, first, second, third, updateAttribute);
5
6
  }
6
7
  function setAttributes(element, attributes, dispatch) {
7
8
  setElementValues(element, attributes, null, dispatch, updateAttribute);
8
9
  }
10
+ //#endregion
9
11
  export { setAttribute, setAttributes };
package/dist/data.js CHANGED
@@ -3,6 +3,7 @@ import { isHTMLOrSVGElement } from "./internal/is.js";
3
3
  import { setElementValues, updateElementValue } from "./internal/element-value.js";
4
4
  import { parse } from "@oscarpalmer/atoms/string";
5
5
  import { kebabCase } from "@oscarpalmer/atoms/string/case";
6
+ //#region src/data.ts
6
7
  function getData(element, keys, parseValues) {
7
8
  if (!isHTMLOrSVGElement(element)) return;
8
9
  const shouldParse = parseValues !== false;
@@ -31,4 +32,5 @@ function updateDataAttribute(element, key, value) {
31
32
  updateElementValue(element, getName(key), value, element.setAttribute, element.removeAttribute, false, true);
32
33
  }
33
34
  var ATTRIBUTE_DATA_PREFIX = "data-";
35
+ //#endregion
34
36
  export { getData, setData };
@@ -1,4 +1,5 @@
1
1
  import { isEventTarget } from "../internal/is.js";
2
+ //#region src/event/delegation.ts
2
3
  function addDelegatedHandler(doc, type, name, passive) {
3
4
  if (DELEGATED.has(name)) return;
4
5
  DELEGATED.add(name);
@@ -80,4 +81,5 @@ var EVENT_TYPES = new Set([
80
81
  ]);
81
82
  var HANDLER_ACTIVE = delegatedEventHandler.bind(false);
82
83
  var HANDLER_PASSIVE = delegatedEventHandler.bind(true);
84
+ //#endregion
83
85
  export { addDelegatedListener, getDelegatedName, removeDelegatedListener };
@@ -3,6 +3,7 @@ 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";
6
+ //#region src/event/index.ts
6
7
  function createDispatchOptions(options) {
7
8
  return {
8
9
  bubbles: getBoolean(options?.bubbles, true),
@@ -74,4 +75,5 @@ function on(target, type, listener, options) {
74
75
  };
75
76
  }
76
77
  var PROPERTY_DETAIL = "detail";
78
+ //#endregion
77
79
  export { dispatch, getPosition, off, on };
@@ -1,4 +1,5 @@
1
1
  import { findAncestor, findRelatives, getDistance } from "./relative.js";
2
+ //#region src/find/index.ts
2
3
  function findElement(selector, context) {
3
4
  return findElementOrElements(selector, context, true);
4
5
  }
@@ -69,4 +70,5 @@ var STYLE_HIDDEN = "hidden";
69
70
  var STYLE_NONE = "none";
70
71
  var SUFFIX_HOVER = ":hover";
71
72
  var TAG_HEAD = "HEAD";
73
+ //#endregion
72
74
  export { findElement as $, findElement, findElements as $$, findElements, findAncestor, findRelatives, getDistance, getElementUnderPointer };
@@ -1,3 +1,4 @@
1
+ //#region src/find/relative.ts
1
2
  function findAncestor(origin, selector) {
2
3
  const element = getElement(origin);
3
4
  if (element == null || selector == null) return null;
@@ -74,4 +75,5 @@ function traverse(from, to) {
74
75
  parent = parent.parentElement;
75
76
  }
76
77
  }
78
+ //#endregion
77
79
  export { findAncestor, findRelatives, getDistance };
package/dist/focusable.js CHANGED
@@ -1,3 +1,4 @@
1
+ //#region src/focusable.ts
1
2
  /**
2
3
  * Get a list of focusable elements within a parent element
3
4
  * @param parent Parent element
@@ -159,4 +160,5 @@ var STYLE_NONE = "none";
159
160
  var TABINDEX_BASE = 0;
160
161
  var TABINDEX_DEFAULT = -1;
161
162
  var TYPE_RADIO = "radio";
163
+ //#endregion
162
164
  export { getFocusable, getTabbable, isFocusable, isTabbable };
@@ -1,5 +1,6 @@
1
1
  import { sanitizeNodes } from "./sanitize.js";
2
2
  import { isPlainObject } from "@oscarpalmer/atoms/is";
3
+ //#region src/html/index.ts
3
4
  function createHtml(value) {
4
5
  const parsed = getParser().parseFromString(getHtml(value), PARSE_TYPE_HTML);
5
6
  parsed.body.normalize();
@@ -69,4 +70,5 @@ var TEMPLATE_TAG = "template";
69
70
  var TEMPORARY_ELEMENT = "<toretto-temporary></toretto-temporary>";
70
71
  var parser;
71
72
  var templates = {};
73
+ //#endregion
72
74
  export { html, sanitize };
@@ -1,5 +1,6 @@
1
1
  import { _isBadAttribute, _isEmptyNonBooleanAttribute, _isInvalidBooleanAttribute } from "../internal/attribute.js";
2
2
  import { setAttribute } from "../attribute/set.js";
3
+ //#region src/html/sanitize.ts
3
4
  function handleElement(element, depth) {
4
5
  if (depth === 0) {
5
6
  const removable = element.querySelectorAll(REMOVE_SELECTOR);
@@ -57,4 +58,5 @@ function sanitizeNodes(nodes, depth) {
57
58
  }
58
59
  var COMMENT_HARMFUL = /<[/\w]/g;
59
60
  var REMOVE_SELECTOR = "script, toretto-temporary";
61
+ //#endregion
60
62
  export { sanitizeAttributes, sanitizeNodes };
@@ -1,5 +1,6 @@
1
1
  import { updateElementValue } from "./element-value.js";
2
2
  import { isPlainObject } from "@oscarpalmer/atoms/is";
3
+ //#region src/internal/attribute.ts
3
4
  function badAttributeHandler(name, value) {
4
5
  if (typeof name !== "string" || name.trim().length === 0 || typeof value !== "string") return true;
5
6
  if (EXPRESSION_CLOBBERED_NAME.test(name) && (value in document || value in formElement) || EXPRESSION_EVENT_NAME.test(name)) return true;
@@ -73,7 +74,7 @@ var EXPRESSION_WHITESPACE = /[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F
73
74
  /**
74
75
  * List of boolean attributes
75
76
  */
76
- const booleanAttributes = Object.freeze([
77
+ var booleanAttributes = Object.freeze([
77
78
  "async",
78
79
  "autofocus",
79
80
  "autoplay",
@@ -111,4 +112,5 @@ var elementEvents = {
111
112
  };
112
113
  var formElement = document.createElement("form");
113
114
  var textArea;
115
+ //#endregion
114
116
  export { _isBadAttribute, _isBooleanAttribute, _isEmptyNonBooleanAttribute, _isInvalidBooleanAttribute, booleanAttributes, isAttribute, updateAttribute };
@@ -2,6 +2,7 @@ import { isHTMLOrSVGElement } from "./is.js";
2
2
  import "../is.js";
3
3
  import { isAttribute } from "./attribute.js";
4
4
  import { isNullableOrWhitespace } from "@oscarpalmer/atoms/is";
5
+ //#region src/internal/element-value.ts
5
6
  function setElementValue(element, first, second, third, callback) {
6
7
  if (!isHTMLOrSVGElement(element)) return;
7
8
  if (typeof first === "string") setElementValues(element, first, second, third, callback);
@@ -29,4 +30,5 @@ function updateElementValue(element, key, value, set, remove, isBoolean, json) {
29
30
  if (isBoolean ? value == null : isNullableOrWhitespace(value)) remove.call(element, key);
30
31
  else set.call(element, key, json ? JSON.stringify(value) : String(value));
31
32
  }
33
+ //#endregion
32
34
  export { setElementValue, setElementValues, updateElementValue };
@@ -1,5 +1,6 @@
1
1
  import { parse } from "@oscarpalmer/atoms/string";
2
2
  import { camelCase, kebabCase } from "@oscarpalmer/atoms/string/case";
3
+ //#region src/internal/get-value.ts
3
4
  function getBoolean(value, defaultValue) {
4
5
  return typeof value === "boolean" ? value : defaultValue ?? false;
5
6
  }
@@ -13,5 +14,6 @@ function getStyleValue(element, property, computed) {
13
14
  const name = camelCase(property);
14
15
  return computed ? getComputedStyle(element)[name] : element.style[name];
15
16
  }
16
- const EXPRESSION_DATA_PREFIX = /^data-/i;
17
+ var EXPRESSION_DATA_PREFIX = /^data-/i;
18
+ //#endregion
17
19
  export { EXPRESSION_DATA_PREFIX, getAttributeValue, getBoolean, getStyleValue };
@@ -1,3 +1,4 @@
1
+ //#region src/internal/is.ts
1
2
  /**
2
3
  * Is the value an event target?
3
4
  * @param value Value to check
@@ -14,4 +15,5 @@ function isEventTarget(value) {
14
15
  function isHTMLOrSVGElement(value) {
15
16
  return value instanceof HTMLElement || value instanceof SVGElement;
16
17
  }
18
+ //#endregion
17
19
  export { isEventTarget, isHTMLOrSVGElement };
package/dist/is.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { isEventTarget, isHTMLOrSVGElement } from "./internal/is.js";
2
+ //#region src/is.ts
2
3
  /**
3
4
  * Is the value a child node?
4
5
  * @param value Value to check
@@ -19,4 +20,5 @@ var CHILD_NODE_TYPES = new Set([
19
20
  Node.COMMENT_NODE,
20
21
  Node.DOCUMENT_TYPE_NODE
21
22
  ]);
23
+ //#endregion
22
24
  export { isChildNode, isEventTarget, isHTMLOrSVGElement, isInDocument };
package/dist/style.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { getStyleValue } from "./internal/get-value.js";
2
2
  import { isHTMLOrSVGElement } from "./internal/is.js";
3
3
  import { setElementValues, updateElementValue } from "./internal/element-value.js";
4
+ //#region src/style.ts
4
5
  /**
5
6
  * Get a style from an element
6
7
  * @param element Element to get the style from
@@ -100,4 +101,5 @@ function updateStyleProperty(element, key, value) {
100
101
  }
101
102
  var ATTRIBUTE_DIRECTION = "dir";
102
103
  var EXPRESSION_DIRECTION = /^(ltr|rtl)$/i;
104
+ //#endregion
103
105
  export { getStyle, getStyles, getTextDirection, setStyle, setStyles, toggleStyles };
@@ -373,7 +373,7 @@ var Memoized = class {
373
373
  constructor(callback, options) {
374
374
  const cache = new SizedMap(options.cacheSize);
375
375
  const getter = (...parameters) => {
376
- const key = options.cacheKey?.(...parameters) ?? (parameters.length === 1 ? parameters[0] : join(parameters.map(getString), "_"));
376
+ const key = options.cacheKey?.(...parameters) ?? (parameters.length === 1 ? parameters[0] : join(parameters.map(getString), SEPARATOR));
377
377
  if (cache.has(key)) return cache.get(key);
378
378
  const value = callback(...parameters);
379
379
  cache.set(key, value);
@@ -449,13 +449,14 @@ function memoize(callback, options) {
449
449
  return new Memoized(callback, getMemoizationOptions(options));
450
450
  }
451
451
  var DEFAULT_CACHE_SIZE = 1024;
452
+ var SEPARATOR = "_";
452
453
  /**
453
454
  * Convert a string to camel case _(thisIsCamelCase)_
454
455
  * @param value String to convert
455
456
  * @returns Camel-cased string
456
457
  */
457
458
  function camelCase(value) {
458
- return toCase("camel", value, true, false);
459
+ return toCase(CASE_CAMEL, value, true, false);
459
460
  }
460
461
  /**
461
462
  * Capitalize the first letter of a string _(and lowercase the rest)_
@@ -473,7 +474,7 @@ function capitalize(value) {
473
474
  * @returns Kebab-cased string
474
475
  */
475
476
  function kebabCase(value) {
476
- return toCase("kebab", value, false, false);
477
+ return toCase(CASE_KEBAB, value, false, false);
477
478
  }
478
479
  function toCase(type, value, capitalizeAny, capitalizeFirst) {
479
480
  caseMemoizers[type] ??= memoize(toCaseCallback.bind({
@@ -491,7 +492,7 @@ function toCaseCallback(value) {
491
492
  const partsLength = parts.length;
492
493
  const cased = [];
493
494
  for (let partIndex = 0; partIndex < partsLength; partIndex += 1) {
494
- const items = parts[partIndex].replace(EXPRESSION_ACRONYM, (full, one, two, three) => three === "s" ? full : `${one}-${two}${three}`).replace(EXPRESSION_CAMEL_CASE, REPLACEMENT_CAMEL_CASE).split("-");
495
+ const items = parts[partIndex].replace(EXPRESSION_ACRONYM, (full, one, two, three) => three === S ? full : `${one}-${two}${three}`).replace(EXPRESSION_CAMEL_CASE, REPLACEMENT_CAMEL_CASE).split("-");
495
496
  const itemsLength = items.length;
496
497
  const partResult = [];
497
498
  let itemCount = 0;
@@ -506,16 +507,24 @@ function toCaseCallback(value) {
506
507
  }
507
508
  return join(cased, delimiters[type]);
508
509
  }
509
- var caseMemoizers = {};
510
- var delimiters = {
511
- camel: "",
512
- kebab: "-",
513
- pascal: "",
514
- snake: "_"
515
- };
510
+ var CASE_CAMEL = "camel";
511
+ var CASE_KEBAB = "kebab";
512
+ var CASE_PASCAL = "pascal";
513
+ var CASE_SNAKE = "snake";
514
+ var DELIMTER_EMPTY = "";
515
+ var DELIMITER_HYPHEN = "-";
516
+ var DELIMITER_UNDERSCORE = "_";
516
517
  var EXPRESSION_CAMEL_CASE = /(\p{Ll})(\p{Lu})/gu;
517
518
  var EXPRESSION_ACRONYM = /(\p{Lu}*)(\p{Lu})(\p{Ll}+)/gu;
518
519
  var REPLACEMENT_CAMEL_CASE = "$1-$2";
520
+ var S = "s";
521
+ var caseMemoizers = {};
522
+ var delimiters = {
523
+ [CASE_CAMEL]: DELIMTER_EMPTY,
524
+ [CASE_KEBAB]: DELIMITER_HYPHEN,
525
+ [CASE_PASCAL]: DELIMTER_EMPTY,
526
+ [CASE_SNAKE]: DELIMITER_UNDERSCORE
527
+ };
519
528
  var memoizedCapitalize;
520
529
  function getBoolean(value, defaultValue) {
521
530
  return typeof value === "boolean" ? value : defaultValue ?? false;
@@ -572,6 +581,159 @@ const ATTRIBUTE_DATA_PREFIX = "data-";
572
581
  * A function that does nothing, which can be useful, I guess…
573
582
  */
574
583
  function noop() {}
584
+ /**
585
+ * Asserts that a condition is true, throwing an error if it is not
586
+ * @param condition Condition to assert
587
+ * @param message Error message
588
+ * @param error Error constructor
589
+ */
590
+ function assert(condition, message, error) {
591
+ if (!condition()) throw new (error ?? Error)(message);
592
+ }
593
+ assert.condition = assertCondition;
594
+ assert.defined = assertDefined;
595
+ assert.instanceOf = assertInstanceOf;
596
+ assert.is = assertIs;
597
+ /**
598
+ * Creates an asserter that asserts a condition is true, throwing an error if it is not
599
+ * @param condition Condition to assert
600
+ * @param message Error message
601
+ * @param error Error constructor
602
+ * @returns Asserter
603
+ */
604
+ function assertCondition(condition, message, error) {
605
+ return (value) => {
606
+ assert(() => condition(value), message, error);
607
+ };
608
+ }
609
+ /**
610
+ * Asserts that a value is defined throwing an error if it is not
611
+ * @param value Value to assert
612
+ * @param message Error message
613
+ */
614
+ function assertDefined(value, message) {
615
+ assert(() => value != null, message ?? MESSAGE_VALUE_DEFINED);
616
+ }
617
+ /**
618
+ * Creates an asserter that asserts a value is an instance of a constructor, throwing an error if it is not
619
+ * @param constructor Constructor to check against
620
+ * @param message Error message
621
+ * @param error Error constructor
622
+ * @returns Asserter
623
+ */
624
+ function assertInstanceOf(constructor, message, error) {
625
+ return (value) => {
626
+ assert(() => value instanceof constructor, message, error);
627
+ };
628
+ }
629
+ /**
630
+ * Creates an asserter that asserts a value is of a specific type, throwing an error if it is not
631
+ * @param condition Type guard function to check the value
632
+ * @param message Error message
633
+ * @param error Error constructor
634
+ * @returns Asserter
635
+ */
636
+ function assertIs(condition, message, error) {
637
+ return (value) => {
638
+ assert(() => condition(value), message, error);
639
+ };
640
+ }
641
+ var MESSAGE_VALUE_DEFINED = "Expected value to be defined";
642
+ /**
643
+ * Create an asynchronous function that can only be called once, rejecting or resolving the same result on subsequent calls
644
+ * @param callback Callback to use once
645
+ * @returns Once callback
646
+ */
647
+ function asyncOnce(callback) {
648
+ assert(() => typeof callback === "function", MESSAGE_EXPECTATION);
649
+ const state = {
650
+ called: false,
651
+ cleared: false,
652
+ error: false,
653
+ finished: false,
654
+ items: [],
655
+ value: void 0
656
+ };
657
+ const fn = (...parameters) => {
658
+ if (state.cleared) return Promise.reject(new Error(MESSAGE_CLEARED));
659
+ if (state.finished) return state.error ? Promise.reject(state.value) : Promise.resolve(state.value);
660
+ if (state.called) return new Promise((resolve, reject) => {
661
+ state.items.push({
662
+ reject,
663
+ resolve
664
+ });
665
+ });
666
+ state.called = true;
667
+ return new Promise((resolve, reject) => {
668
+ state.items.push({
669
+ reject,
670
+ resolve
671
+ });
672
+ callback(...parameters).then((value) => {
673
+ handleResult(state, value, false);
674
+ }).catch((error) => {
675
+ handleResult(state, error, true);
676
+ });
677
+ });
678
+ };
679
+ Object.defineProperties(fn, {
680
+ called: { get: () => state.called },
681
+ cleared: { get: () => state.cleared },
682
+ error: { get: () => state.error },
683
+ finished: { get: () => state.finished }
684
+ });
685
+ fn.clear = () => {
686
+ if (!state.called || !state.finished || state.cleared) return;
687
+ state.cleared = true;
688
+ state.value = void 0;
689
+ };
690
+ return fn;
691
+ }
692
+ function handleResult(state, value, error) {
693
+ state.error = error;
694
+ state.finished = true;
695
+ state.value = value;
696
+ const items = state.items.splice(0);
697
+ const { length } = items;
698
+ for (let index = 0; index < length; index += 1) {
699
+ const { reject, resolve } = items[index];
700
+ if (error) reject(value);
701
+ else resolve(value);
702
+ }
703
+ }
704
+ /**
705
+ * Create a function that can only be called once, returning the same value on subsequent calls
706
+ * @param callback Callback to use once
707
+ * @returns Once callback
708
+ */
709
+ function once(callback) {
710
+ assert(() => typeof callback === "function", MESSAGE_EXPECTATION);
711
+ const state = {
712
+ called: false,
713
+ cleared: false,
714
+ value: void 0
715
+ };
716
+ const fn = (...parameters) => {
717
+ if (state.cleared) throw new Error(MESSAGE_CLEARED);
718
+ if (state.called) return state.value;
719
+ state.called = true;
720
+ state.value = callback(...parameters);
721
+ return state.value;
722
+ };
723
+ Object.defineProperties(fn, {
724
+ called: { get: () => state.called },
725
+ cleared: { get: () => state.cleared }
726
+ });
727
+ fn.clear = () => {
728
+ if (!state.called || state.cleared) return;
729
+ state.cleared = true;
730
+ state.value = void 0;
731
+ };
732
+ return fn;
733
+ }
734
+ once.async = asyncOnce;
735
+ var MESSAGE_CLEARED = "Once has been cleared";
736
+ var MESSAGE_EXPECTATION = "Once expected a function";
575
737
  function addDelegatedHandler(doc, type, name, passive) {
576
738
  if (DELEGATED.has(name)) return;
577
739
  DELEGATED.add(name);
package/dist/touch.js CHANGED
@@ -1,3 +1,4 @@
1
+ //#region src/touch.ts
1
2
  function getSupport() {
2
3
  if (window == null || navigator == null) return false;
3
4
  if ("matchMedia" in window) {
@@ -28,4 +29,5 @@ var supportsTouch = (() => {
28
29
  } });
29
30
  return instance;
30
31
  })();
32
+ //#endregion
31
33
  export { supportsTouch as default };
package/package.json CHANGED
@@ -4,26 +4,27 @@
4
4
  "url": "https://oscarpalmer.se"
5
5
  },
6
6
  "dependencies": {
7
- "@oscarpalmer/atoms": "^0.157"
7
+ "@oscarpalmer/atoms": "^0.162"
8
8
  },
9
9
  "description": "A collection of badass DOM utilities.",
10
10
  "devDependencies": {
11
- "@types/node": "^25.3",
11
+ "@types/node": "^25.4",
12
12
  "@vitest/coverage-istanbul": "^4",
13
+ "dts-bundle-generator": "^9.5",
13
14
  "jsdom": "^28.1",
14
- "oxfmt": "^0.36",
15
- "oxlint": "^1.51",
16
- "rolldown": "1.0.0-rc.7",
15
+ "oxfmt": "^0.39",
16
+ "oxlint": "^1.54",
17
+ "rolldown": "1.0.0-rc.9",
17
18
  "tslib": "^2.8",
18
19
  "typescript": "^5.9",
19
- "vite": "8.0.0-beta.16",
20
+ "vite": "8.0.0-beta.17",
20
21
  "vitest": "^4"
21
22
  },
22
23
  "exports": {
23
24
  "./package.json": "./package.json",
24
25
  ".": {
25
26
  "types": "./types/index.d.ts",
26
- "default": "./dist/index.js"
27
+ "default": "./dist/toretto.full.js"
27
28
  },
28
29
  "./attribute": {
29
30
  "types": "./types/attribute/index.d.ts",
@@ -84,7 +85,7 @@
84
85
  "url": "git+https://github.com/oscarpalmer/toretto.git"
85
86
  },
86
87
  "scripts": {
87
- "build": "npm run clean && npx vite build && npm run rolldown:build && npx tsc",
88
+ "build": "npm run clean && npx vite build && npm run rolldown:build && npx tsc && npx dts-bundle-generator --config ./dts.config.ts --silent",
88
89
  "clean": "rm -rf ./dist && rm -rf ./types && rm -f ./tsconfig.tsbuildinfo",
89
90
  "rolldown:build": "npx rolldown -c",
90
91
  "rolldown:watch": "npx rolldown -c ./rolldown.config.js --watch",
@@ -93,5 +94,5 @@
93
94
  },
94
95
  "type": "module",
95
96
  "types": "types/index.d.ts",
96
- "version": "0.38.0"
97
+ "version": "0.39.1"
97
98
  }
package/src/find/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type {PlainObject} from '@oscarpalmer/atoms/models';
1
+ import type {PlainObject} from '@oscarpalmer/atoms';
2
2
  import type {Selector} from '../models';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import type {PlainObject} from '@oscarpalmer/atoms/models';
1
+ import type {PlainObject} from '@oscarpalmer/atoms';
2
2
  import {isPlainObject} from '@oscarpalmer/atoms/is';
3
3
  import type {Attribute} from '../models';
4
4
  import {updateElementValue} from './element-value';
package/types/index.d.ts CHANGED
@@ -1,11 +1,428 @@
1
- import supportsTouch from './touch';
2
- export { isBadAttribute, isBooleanAttribute, isEmptyNonBooleanAttribute, isInvalidBooleanAttribute, } from './attribute/index';
3
- export * from './data';
4
- export * from './event/index';
5
- export * from './find/index';
6
- export * from './focusable';
7
- export * from './html/index';
8
- export * from './is';
9
- export * from './models';
10
- export * from './style';
11
- export { supportsTouch };
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ export type SupporsTouch = {
4
+ /**
5
+ * Are touch events supported?
6
+ */
7
+ readonly value: boolean;
8
+ /**
9
+ * Are touch events supported?
10
+ */
11
+ get(): boolean;
12
+ /**
13
+ * Re-evaluate if touch events are supported
14
+ */
15
+ update(): boolean;
16
+ };
17
+ /**
18
+ * Does the device support touch events?
19
+ */
20
+ export declare const supportsTouch: SupporsTouch;
21
+ /**
22
+ * Attribute for an element
23
+ */
24
+ export type Attribute = {
25
+ name: string;
26
+ value: unknown;
27
+ };
28
+ /**
29
+ * Event listener for custom events
30
+ */
31
+ export type CustomEventListener = (event: CustomEvent) => void;
32
+ /**
33
+ * The position of an event
34
+ */
35
+ export type EventPosition = {
36
+ x: number;
37
+ y: number;
38
+ };
39
+ /**
40
+ * Event listener that can be removed
41
+ */
42
+ export type RemovableEventListener = () => void;
43
+ /**
44
+ * Selector that be searched for
45
+ */
46
+ export type Selector = string | Node | Node[] | NodeList;
47
+ /**
48
+ * Text direction for an element
49
+ */
50
+ export type TextDirection = "ltr" | "rtl";
51
+ /**
52
+ * Is the attribute considered bad and potentially harmful?
53
+ * @param attribute Attribute to check
54
+ * @returns `true` if attribute is considered bad
55
+ */
56
+ export declare function isBadAttribute(attribute: Attr | Attribute): boolean;
57
+ /**
58
+ * Is the attribute considered bad and potentially harmful?
59
+ * @param name Attribute name
60
+ * @param value Attribute value
61
+ * @returns `true` if attribute is considered bad
62
+ */
63
+ export declare function isBadAttribute(name: string, value: string): boolean;
64
+ /**
65
+ * Is the attribute a boolean attribute?
66
+ * @param name Attribute to check
67
+ * @returns `true` if attribute is a boolean attribute
68
+ */
69
+ export declare function isBooleanAttribute(attribute: Attr | Attribute): boolean;
70
+ /**
71
+ * Is the attribute a boolean attribute?
72
+ * @param name Attribute name
73
+ * @returns `true` if attribute is a boolean attribute
74
+ */
75
+ export declare function isBooleanAttribute(name: string): boolean;
76
+ /**
77
+ * Is the attribute empty and not a boolean attribute?
78
+ * @param attribute Attribute to check
79
+ * @returns `true` if attribute is empty and not a boolean attribute
80
+ */
81
+ export declare function isEmptyNonBooleanAttribute(attribute: Attr | Attribute): boolean;
82
+ /**
83
+ * Is the attribute empty and not a boolean attribute?
84
+ * @param name Attribute name
85
+ * @param value Attribute value
86
+ * @returns `true` if attribute is empty and not a boolean attribute
87
+ */
88
+ export declare function isEmptyNonBooleanAttribute(name: string, value: string): boolean;
89
+ /**
90
+ * Is the attribute an invalid boolean attribute?
91
+ *
92
+ * _(I.e., its value is not empty or the same as its name)_
93
+ * @param attribute Attribute to check
94
+ * @returns `true` if attribute is an invalid boolean attribute
95
+ */
96
+ export declare function isInvalidBooleanAttribute(attribute: Attr | Attribute): boolean;
97
+ /**
98
+ * Is the attribute an invalid boolean attribute?
99
+ *
100
+ * _(I.e., its value is not empty or the same as its name)_
101
+ * @param name Attribute name
102
+ * @param value Attribute value
103
+ * @returns `true` if attribute is an invalid boolean attribute
104
+ */
105
+ export declare function isInvalidBooleanAttribute(name: string, value: string): boolean;
106
+ /**
107
+ * A generic object
108
+ */
109
+ export type PlainObject = Record<PropertyKey, unknown>;
110
+ /**
111
+ * Get a keyed data value from an element
112
+ * @param element Element to get data from
113
+ * @param key Data key
114
+ * @param parse Parse values? _(defaults to `true`)_
115
+ * @returns Data value
116
+ */
117
+ export declare function getData(element: Element, key: string, parse?: boolean): unknown;
118
+ /**
119
+ * Get keyed data values from an element
120
+ * @param element Element to get data from
121
+ * @param keys Keys of the data values to get
122
+ * @param parse Parse values? _(defaults to `true`)_
123
+ * @returns Keyed data values
124
+ */
125
+ export declare function getData<Key extends string>(element: Element, keys: Key[], parse?: boolean): Record<Key, unknown>;
126
+ /**
127
+ * Set data values on an element
128
+ * @param element Element to set data on
129
+ * @param data Data to set
130
+ */
131
+ export declare function setData(element: Element, data: PlainObject): void;
132
+ /**
133
+ * Set a data value on an element
134
+ * @param element Element to set data on
135
+ * @param key Data key
136
+ * @param value Data value
137
+ */
138
+ export declare function setData(element: Element, key: string, value: unknown): void;
139
+ /**
140
+ * Dispatch an event for a target
141
+ * @param target Event target
142
+ * @param type Type of event
143
+ * @param options Options for event _(bubbles and is cancelable by default)_
144
+ */
145
+ export declare function dispatch<Type extends keyof HTMLElementEventMap>(target: EventTarget, type: Type, options?: CustomEventInit): void;
146
+ /**
147
+ * Dispatch an event for a target
148
+ * @param target Event target
149
+ * @param type Type of event
150
+ * @param options Options for event _(bubbles and is cancelable by default)_
151
+ */
152
+ export declare function dispatch(target: EventTarget, type: string, options?: CustomEventInit): void;
153
+ /**
154
+ * Get the X- and Y-coordinates from a pointer event
155
+ * @param event Pointer event
156
+ * @returns X- and Y-coordinates
157
+ */
158
+ export declare function getPosition(event: MouseEvent | TouchEvent): EventPosition | undefined;
159
+ /**
160
+ * Remove an event listener
161
+ * @param target Event target
162
+ * @param type Type of event
163
+ * @param listener Event listener
164
+ * @param options Options for event
165
+ */
166
+ export declare function off(target: EventTarget, type: keyof HTMLElementEventMap, listener: EventListener | CustomEventListener, options?: EventListenerOptions): void;
167
+ /**
168
+ * Remove an event listener
169
+ * @param target Event target
170
+ * @param type Type of event
171
+ * @param listener Event listener
172
+ * @param options Options for event
173
+ */
174
+ export declare function off(target: EventTarget, type: string, listener: EventListener | CustomEventListener, options?: EventListenerOptions): void;
175
+ /**
176
+ * Add an event listener
177
+ * @param target Event target
178
+ * @param type Type of event
179
+ * @param listener Event listener
180
+ * @param options Options for event _(passive by default)_
181
+ */
182
+ export declare function on<Type extends keyof HTMLElementEventMap>(target: EventTarget, type: Type, listener: (event: HTMLElementEventMap[Type]) => void, options?: AddEventListenerOptions): RemovableEventListener;
183
+ /**
184
+ * Add an event listener
185
+ * @param target Event target
186
+ * @param type Type of event
187
+ * @param listener Event listener
188
+ * @param options Options for event _(passive by default)_
189
+ */
190
+ export declare function on(target: EventTarget, type: string, listener: EventListener | CustomEventListener, options?: AddEventListenerOptions): RemovableEventListener;
191
+ /**
192
+ * Find the closest ancestor element that matches the tag name
193
+ *
194
+ * - If no match is found, `null` is returned
195
+ * - _(If you want to search upwards, downwards, and sideways, use {@link findRelatives})_
196
+ * @param origin Origin to start from
197
+ * @param tagName Tag name to match
198
+ * @returns Found ancestor or `null`
199
+ */
200
+ export declare function findAncestor<TagName extends keyof HTMLElementTagNameMap>(origin: Element | Event | EventTarget, tagName: TagName): HTMLElementTagNameMap[TagName] | null;
201
+ /**
202
+ * Find the closest ancestor element that matches the selector _(string or callback)_
203
+ *
204
+ * - If no match is found, `null` is returned
205
+ * - _(If you want to search upwards, downwards, and sideways, use {@link findRelatives})_
206
+ * @param origin Origin to start from
207
+ * @param selector Selector to match
208
+ * @returns Found ancestor or `null`
209
+ */
210
+ export declare function findAncestor(origin: Element | Event | EventTarget, selector: string | ((element: Element) => boolean)): Element | null;
211
+ /**
212
+ * Finds the closest elements to the origin element that matches the tag name
213
+ *
214
+ * Traverses up, down, and sideways in the _DOM_-tree. _(If you only want to traverse up, use {@link findAncestor})_
215
+ * @param origin Element to start from
216
+ * @param tagName Tag name to match
217
+ * @param context Context to search within
218
+ * @returns Found elements
219
+ */
220
+ export declare function findRelatives<TagName extends keyof HTMLElementTagNameMap>(origin: Element, tagName: TagName, context?: Document | Element): HTMLElementTagNameMap[TagName][];
221
+ /**
222
+ * Finds the closest elements to the origin element that matches the selector
223
+ *
224
+ * Traverses up, down, and sideways in the _DOM_-tree. _(If you only want to traverse up, use {@link findAncestor})_
225
+ * @param origin Element to start from
226
+ * @param selector Selector to match
227
+ * @param context Context to search within
228
+ * @returns Found elements
229
+ */
230
+ export declare function findRelatives(origin: Element, selector: string, context?: Document | Element): Element[];
231
+ /**
232
+ * Get the distance between two elements _(i.e., the amount of nodes of between them)_
233
+ * @param origin Origin element
234
+ * @param target Target element
235
+ * @returns Distance between elements, or `-1` if distance cannot be calculated
236
+ */
237
+ export declare function getDistance(origin: Element, target: Element): number;
238
+ /**
239
+ * Find the first element that matches the tag name
240
+ * @param tagName Tag name of element to find
241
+ * @param context Context to search within _(defaults to `document`)_
242
+ * @returns Found element or `null`
243
+ */
244
+ export declare function findElement<TagName extends keyof HTMLElementTagNameMap>(tagName: TagName, context?: Selector | null): HTMLElementTagNameMap[TagName] | null;
245
+ /**
246
+ * Find the first element that matches the selector
247
+ * @param selector Selector to find element for
248
+ * @param context Context to search within _(defaults to `document`)_
249
+ * @returns Found element or `null`
250
+ */
251
+ export declare function findElement(selector: string, context?: Selector | null): Element | null;
252
+ /**
253
+ * Find elements that match the selector
254
+ * @param tagName tagName to find elements for
255
+ * @param context Context to search within _(defaults to `document`)_
256
+ * @returns Found elements
257
+ */
258
+ export declare function findElements(tagName: keyof HTMLElementTagNameMap, context?: Selector | null): HTMLElementTagNameMap[typeof tagName][];
259
+ /**
260
+ * Find elements that match the selector
261
+ * @param selector Selector to find elements for
262
+ * @param context Context to search within _(defaults to `document`)_
263
+ * @returns Found elements
264
+ */
265
+ export declare function findElements(selector: Selector, context?: Selector | null): Element[];
266
+ /**
267
+ * Get the most specific element under the pointer
268
+ *
269
+ * - Ignores elements with `pointer-events: none` and `visibility: hidden`
270
+ * - _(If `skipIgnore` is `true`, no elements are ignored)_
271
+ * @param skipIgnore Skip ignored elements?
272
+ * @returns Found element or `null`
273
+ */
274
+ export declare function getElementUnderPointer(skipIgnore?: boolean): Element | null;
275
+ /**
276
+ * Get a list of focusable elements within a parent element
277
+ * @param parent Parent element
278
+ * @returns Focusable elements
279
+ */
280
+ export declare function getFocusable(parent: Element): Element[];
281
+ /**
282
+ * Get a list of tabbable elements within a parent element
283
+ * @param parent Parent element
284
+ * @returns Tabbable elements
285
+ */
286
+ export declare function getTabbable(parent: Element): Element[];
287
+ /**
288
+ * Is the element focusable?
289
+ * @param element Element to check
290
+ * @returns `true` if focusable, otherwise `false`
291
+ */
292
+ export declare function isFocusable(element: Element): boolean;
293
+ /**
294
+ * Is the element tabbable?
295
+ * @param element Element to check
296
+ * @returns `true` if tabbable, otherwise `false`
297
+ */
298
+ export declare function isTabbable(element: Element): boolean;
299
+ export type Html = {
300
+ /**
301
+ * Create nodes from an HTML string or a template element
302
+ * @param value HTML string or id for a template element
303
+ * @param options Options for creating nodes
304
+ * @returns Created nodes
305
+ */
306
+ (value: string, options?: HtmlOptions): Node[];
307
+ /**
308
+ * Create nodes from a template element
309
+ * @param template Template element
310
+ * @param options Options for creating nodes
311
+ * @returns Created nodes
312
+ */
313
+ (template: HTMLTemplateElement, options?: HtmlOptions): Node[];
314
+ /**
315
+ * Clear cache of template elements
316
+ */
317
+ clear(): void;
318
+ /**
319
+ * Remove cached template element for an HTML string or id
320
+ * @param template HTML string or id for a template element
321
+ */
322
+ remove(template: string): void;
323
+ };
324
+ export type HtmlOptions = {
325
+ /**
326
+ * Cache template element for the HTML string? _(defaults to `true`)_
327
+ */
328
+ cache?: boolean;
329
+ };
330
+ export declare const html: Html;
331
+ /**
332
+ * Sanitize one or more nodes, recursively
333
+ * @param value Node or nodes to sanitize
334
+ * @param options Sanitization options
335
+ * @returns Sanitized nodes
336
+ */
337
+ export declare function sanitize(value: Node | Node[]): Node[];
338
+ /**
339
+ * Is the value an event target?
340
+ * @param value Value to check
341
+ * @returns `true` if it's an event target, otherwise `false`
342
+ */
343
+ export declare function isEventTarget(value: unknown): value is EventTarget;
344
+ /**
345
+ * Is the value an HTML or SVG element?
346
+ * @param value Value to check
347
+ * @returns `true` if it's an HTML or SVG element, otherwise `false`
348
+ */
349
+ export declare function isHTMLOrSVGElement(value: unknown): value is HTMLElement | SVGElement;
350
+ /**
351
+ * Is the value a child node?
352
+ * @param value Value to check
353
+ * @returns `true` if it's a child node, otherwise `false`
354
+ */
355
+ export declare function isChildNode(value: unknown): value is ChildNode;
356
+ /**
357
+ * Is the node inside a document?
358
+ * @param node Node to check
359
+ * @returns `true` if it's inside a document, otherwise `false`
360
+ */
361
+ export declare function isInDocument(node: Node): boolean;
362
+ /**
363
+ * Is the node inside a specific document?
364
+ * @param node Node to check
365
+ * @param document Document to check within
366
+ * @returns `true` if it's inside the document, otherwise `false`
367
+ */
368
+ export declare function isInDocument(node: Node, document: Document): boolean;
369
+ export type StyleToggler = {
370
+ /**
371
+ * Set the provided styles on the element
372
+ */
373
+ set(): void;
374
+ /**
375
+ * Remove the provided styles from the element _(and sets any previous styles)_
376
+ */
377
+ remove(): void;
378
+ };
379
+ /**
380
+ * Get a style from an element
381
+ * @param element Element to get the style from
382
+ * @param property Style name
383
+ * @param computed Get the computed style? _(defaults to `false`)_
384
+ * @returns Style value
385
+ */
386
+ export declare function getStyle(element: Element, property: keyof CSSStyleDeclaration, computed?: boolean): string | undefined;
387
+ /**
388
+ * Get styles from an element
389
+ * @param element Element to get the styles from
390
+ * @param properties Styles to get
391
+ * @param computed Get the computed styles? _(defaults to `false`)_
392
+ * @returns Style values
393
+ */
394
+ export declare function getStyles<Property extends keyof CSSStyleDeclaration>(element: Element, properties: Property[], computed?: boolean): Record<Property, string | undefined>;
395
+ /**
396
+ * Get the text direction of an element
397
+ * @param element Element to get the text direction from
398
+ * @param computed Get the computed text direction? _(defaults to `false`)_
399
+ * @returns Text direction
400
+ */
401
+ export declare function getTextDirection(element: Element, computed?: boolean): TextDirection;
402
+ /**
403
+ * Set a style on an element
404
+ * @param element Element to set the style on
405
+ * @param property Style name
406
+ * @param value Style value
407
+ */
408
+ export declare function setStyle(element: Element, property: keyof CSSStyleDeclaration, value?: string): void;
409
+ /**
410
+ * Set styles on an element
411
+ * @param element Element to set the styles on
412
+ * @param styles Styles to set
413
+ */
414
+ export declare function setStyles(element: Element, styles: Partial<CSSStyleDeclaration>): void;
415
+ /**
416
+ * Toggle styles for an element
417
+ * @param element Element to style
418
+ * @param styles Styles to be set or removed
419
+ * @returns Style toggler
420
+ */
421
+ export declare function toggleStyles(element: Element, styles: Partial<CSSStyleDeclaration>): StyleToggler;
422
+
423
+ export {
424
+ findElement as $,
425
+ findElements as $$,
426
+ };
427
+
428
+ export {};