@thednp/shorty 2.0.0-alpha5 → 2.0.0-alpha7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +7 -5
  2. package/dist/shorty.cjs +1 -1
  3. package/dist/shorty.cjs.map +1 -1
  4. package/dist/shorty.d.ts +1454 -377
  5. package/dist/shorty.js +1 -1
  6. package/dist/shorty.js.map +1 -1
  7. package/dist/shorty.mjs +364 -365
  8. package/dist/shorty.mjs.map +1 -1
  9. package/package.json +10 -9
  10. package/src/boolean/isApple.ts +1 -1
  11. package/src/event/one.ts +1 -1
  12. package/src/get/getBoundingClientRect.ts +1 -1
  13. package/src/get/getElementTransitionDelay.ts +3 -1
  14. package/src/get/getElementTransitionDuration.ts +3 -1
  15. package/src/get/getRectRelativeToOffsetParent.ts +1 -1
  16. package/src/index.ts +5 -4
  17. package/src/interface/{boundingClientRect.ts → boundingClientRect.d.ts} +1 -1
  18. package/src/interface/css4Declaration.d.ts +4 -0
  19. package/src/interface/{customElement.ts → customElement.d.ts} +2 -2
  20. package/src/interface/{navigatorUA.ts → navigatorUA.d.ts} +3 -3
  21. package/src/interface/{offsetRect.ts → offsetRect.d.ts} +1 -1
  22. package/src/interface/originalEvent.d.ts +4 -0
  23. package/src/is/isArray.ts +1 -1
  24. package/src/is/isCanvas.ts +4 -2
  25. package/src/is/isCustomElement.ts +4 -3
  26. package/src/is/isDocument.ts +3 -1
  27. package/src/is/isElement.ts +4 -2
  28. package/src/is/isElementsArray.ts +1 -1
  29. package/src/is/isFunction.ts +1 -1
  30. package/src/is/isHTMLCollection.ts +4 -2
  31. package/src/is/isHTMLElement.ts +4 -2
  32. package/src/is/isHTMLImageElement.ts +4 -2
  33. package/src/is/isMap.ts +4 -2
  34. package/src/is/isMedia.ts +4 -3
  35. package/src/is/isNode.ts +9 -3
  36. package/src/is/isNodeList.ts +4 -2
  37. package/src/is/isNumber.ts +1 -1
  38. package/src/is/isObject.ts +2 -1
  39. package/src/is/isSVGElement.ts +4 -2
  40. package/src/is/isShadowRoot.ts +4 -2
  41. package/src/is/isString.ts +1 -1
  42. package/src/is/isTableElement.ts +4 -4
  43. package/src/is/isWeakMap.ts +4 -2
  44. package/src/is/isWindow.ts +4 -2
  45. package/src/misc/ObjectHasOwn.ts +17 -0
  46. package/src/misc/createCustomEvent.ts +1 -1
  47. package/src/misc/createElement.ts +1 -3
  48. package/src/misc/createElementNS.ts +1 -1
  49. package/src/misc/data.ts +12 -26
  50. package/src/misc/getInstance.ts +9 -0
  51. package/src/misc/setElementStyle.ts +1 -1
  52. package/src/selectors/getCustomElements.ts +1 -1
  53. package/src/selectors/querySelector.ts +6 -5
  54. package/src/strings/userAgentData.ts +1 -1
  55. package/src/interface/css4Declaration.ts +0 -3
  56. package/src/interface/originalEvent.ts +0 -4
package/src/misc/data.ts CHANGED
@@ -1,10 +1,6 @@
1
1
  import isHTMLElement from '../is/isHTMLElement';
2
2
 
3
- type MConstructor<T extends new (...args: any[]) => any> = new (
4
- ...args: ConstructorParameters<T>
5
- ) => InstanceType<T>;
6
-
7
- const componentData = new Map<MConstructor<any>, Map<HTMLElement, InstanceType<any>>>();
3
+ const componentData = new Map<string, Map<HTMLElement, any>>();
8
4
 
9
5
  /**
10
6
  * An interface for web components background data.
@@ -19,19 +15,15 @@ const Data = {
19
15
  * @param component the component's name or a unique key
20
16
  * @param instance the component instance
21
17
  */
22
- set: <T extends MConstructor<T>>(
23
- element: HTMLElement,
24
- component: T,
25
- instance: InstanceType<T>,
26
- ): void => {
18
+ set: <T>(element: HTMLElement, component: string, instance: T): void => {
27
19
  if (!isHTMLElement(element)) return;
28
20
 
29
21
  /* istanbul ignore else */
30
22
  if (!componentData.has(component)) {
31
- componentData.set(component, new Map<HTMLElement, InstanceType<T>>());
23
+ componentData.set(component, new Map<HTMLElement, T>());
32
24
  }
33
25
 
34
- const instanceMap = componentData.get(component) as Map<HTMLElement, InstanceType<T>>;
26
+ const instanceMap = componentData.get(component) as Map<HTMLElement, T>;
35
27
  // not undefined, but defined right above
36
28
  instanceMap.set(element, instance);
37
29
  },
@@ -42,10 +34,8 @@ const Data = {
42
34
  * @param component the component's name or a unique key
43
35
  * @returns all the component instances
44
36
  */
45
- getAllFor: <T extends MConstructor<T>>(
46
- component: T,
47
- ): Map<HTMLElement, InstanceType<T>> | null => {
48
- const instanceMap = componentData.get(component) as Map<HTMLElement, InstanceType<T>>;
37
+ getAllFor: <T>(component: string): Map<HTMLElement, T> | null => {
38
+ const instanceMap = componentData.get(component) as Map<HTMLElement, T>;
49
39
 
50
40
  return instanceMap || null;
51
41
  },
@@ -57,9 +47,11 @@ const Data = {
57
47
  * @param component the component's name or a unique key
58
48
  * @returns the instance
59
49
  */
60
- get: <T extends MConstructor<T>>(element: HTMLElement, component: T): InstanceType<T> | null => {
50
+ get: <T>(element: HTMLElement, component: string): T | null => {
61
51
  if (!isHTMLElement(element) || !component) return null;
62
52
  const instanceMap = Data.getAllFor<T>(component);
53
+ // const instanceMap = componentData.get(component) as Map<HTMLElement, InstanceType<T>>;
54
+
63
55
  const instance = element && instanceMap && instanceMap.get(element);
64
56
 
65
57
  // return (instance as T) || null;
@@ -72,8 +64,10 @@ const Data = {
72
64
  * @param element target element
73
65
  * @param component the component's name or a unique key
74
66
  */
75
- remove: <T extends MConstructor<T>>(element: HTMLElement, component: T): void => {
67
+ remove: <T>(element: HTMLElement, component: string): void => {
76
68
  const instanceMap = Data.getAllFor<T>(component);
69
+ // const instanceMap = componentData.get(component) as Map<HTMLElement, InstanceType<T>>;
70
+
77
71
  if (!instanceMap || !isHTMLElement(element)) return;
78
72
 
79
73
  instanceMap.delete(element);
@@ -85,12 +79,4 @@ const Data = {
85
79
  },
86
80
  };
87
81
 
88
- /**
89
- * An alias for `Data.get()`.
90
- */
91
- export const getInstance = <T extends MConstructor<T>>(
92
- target: HTMLElement,
93
- component: T,
94
- ): InstanceType<T> | null => Data.get<T>(target, component);
95
-
96
82
  export default Data;
@@ -0,0 +1,9 @@
1
+ import Data from './data';
2
+
3
+ /**
4
+ * An alias for `Data.get()`.
5
+ */
6
+ const getInstance = <T>(target: HTMLElement, component: string): T | null =>
7
+ Data.get(target, component);
8
+
9
+ export default getInstance;
@@ -1,7 +1,7 @@
1
1
  import ObjectAssign from './ObjectAssign';
2
2
  import ObjectEntries from './ObjectEntries';
3
- import { CSS4Declaration } from '../interface/css4Declaration';
4
3
  import isString from '../is/isString';
4
+ import type { CSS4Declaration } from '../interface/css4Declaration';
5
5
 
6
6
  /**
7
7
  * Shortcut for multiple uses of `HTMLElement.style.propertyName` method.
@@ -1,6 +1,6 @@
1
- import { CustomElement } from '../interface/customElement';
2
1
  import isCustomElement from '../is/isCustomElement';
3
2
  import getElementsByTagName from './getElementsByTagName';
3
+ import type { CustomElement } from '../interface/customElement';
4
4
 
5
5
  /**
6
6
  * Returns an `Array` of `Node` elements that are registered as
@@ -1,5 +1,6 @@
1
1
  import getDocument from '../get/getDocument';
2
2
  import isNode from '../is/isNode';
3
+ import isHTMLElement from '../is/isHTMLElement';
3
4
 
4
5
  /**
5
6
  * Utility to check if target is typeof `HTMLElement`, `Element`, `Node`
@@ -9,13 +10,13 @@ import isNode from '../is/isNode';
9
10
  * @param parent optional node to look into
10
11
  * @return the `HTMLElement` or `querySelector` result
11
12
  */
12
- const querySelector = (selector: Node | string, parent?: ParentNode): HTMLElement | null => {
13
- if (isNode(selector as Node)) {
14
- return selector as HTMLElement;
13
+ const querySelector = (selector: HTMLElement | string, parent?: ParentNode): HTMLElement | null => {
14
+ if (isHTMLElement(selector)) {
15
+ return selector;
15
16
  }
16
- const lookUp = parent && isNode(parent) ? parent : getDocument();
17
+ const lookUp = isNode(parent) ? parent : getDocument();
17
18
 
18
- return lookUp.querySelector(selector as string);
19
+ return lookUp.querySelector(selector);
19
20
  };
20
21
 
21
22
  export default querySelector;
@@ -1,4 +1,4 @@
1
- import { NavigatorUA } from '../interface/navigatorUA';
1
+ import type { NavigatorUA } from '../interface/navigatorUA';
2
2
 
3
3
  const uaDATA = (navigator as NavigatorUA).userAgentData;
4
4
 
@@ -1,3 +0,0 @@
1
- export interface CSS4Declaration extends Exclude<() => string | symbol, CSSStyleDeclaration> {
2
- [key: string]: string;
3
- }
@@ -1,4 +0,0 @@
1
- export interface OriginalEvent extends CustomEvent<any> {
2
- readonly type: string;
3
- relatedTarget?: EventTarget;
4
- }