@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.
- package/README.md +7 -5
- package/dist/shorty.cjs +1 -1
- package/dist/shorty.cjs.map +1 -1
- package/dist/shorty.d.ts +1454 -377
- package/dist/shorty.js +1 -1
- package/dist/shorty.js.map +1 -1
- package/dist/shorty.mjs +364 -365
- package/dist/shorty.mjs.map +1 -1
- package/package.json +10 -9
- package/src/boolean/isApple.ts +1 -1
- package/src/event/one.ts +1 -1
- package/src/get/getBoundingClientRect.ts +1 -1
- package/src/get/getElementTransitionDelay.ts +3 -1
- package/src/get/getElementTransitionDuration.ts +3 -1
- package/src/get/getRectRelativeToOffsetParent.ts +1 -1
- package/src/index.ts +5 -4
- package/src/interface/{boundingClientRect.ts → boundingClientRect.d.ts} +1 -1
- package/src/interface/css4Declaration.d.ts +4 -0
- package/src/interface/{customElement.ts → customElement.d.ts} +2 -2
- package/src/interface/{navigatorUA.ts → navigatorUA.d.ts} +3 -3
- package/src/interface/{offsetRect.ts → offsetRect.d.ts} +1 -1
- package/src/interface/originalEvent.d.ts +4 -0
- package/src/is/isArray.ts +1 -1
- package/src/is/isCanvas.ts +4 -2
- package/src/is/isCustomElement.ts +4 -3
- package/src/is/isDocument.ts +3 -1
- package/src/is/isElement.ts +4 -2
- package/src/is/isElementsArray.ts +1 -1
- package/src/is/isFunction.ts +1 -1
- package/src/is/isHTMLCollection.ts +4 -2
- package/src/is/isHTMLElement.ts +4 -2
- package/src/is/isHTMLImageElement.ts +4 -2
- package/src/is/isMap.ts +4 -2
- package/src/is/isMedia.ts +4 -3
- package/src/is/isNode.ts +9 -3
- package/src/is/isNodeList.ts +4 -2
- package/src/is/isNumber.ts +1 -1
- package/src/is/isObject.ts +2 -1
- package/src/is/isSVGElement.ts +4 -2
- package/src/is/isShadowRoot.ts +4 -2
- package/src/is/isString.ts +1 -1
- package/src/is/isTableElement.ts +4 -4
- package/src/is/isWeakMap.ts +4 -2
- package/src/is/isWindow.ts +4 -2
- package/src/misc/ObjectHasOwn.ts +17 -0
- package/src/misc/createCustomEvent.ts +1 -1
- package/src/misc/createElement.ts +1 -3
- package/src/misc/createElementNS.ts +1 -1
- package/src/misc/data.ts +12 -26
- package/src/misc/getInstance.ts +9 -0
- package/src/misc/setElementStyle.ts +1 -1
- package/src/selectors/getCustomElements.ts +1 -1
- package/src/selectors/querySelector.ts +6 -5
- package/src/strings/userAgentData.ts +1 -1
- package/src/interface/css4Declaration.ts +0 -3
- 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
|
-
|
|
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
|
|
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,
|
|
23
|
+
componentData.set(component, new Map<HTMLElement, T>());
|
|
32
24
|
}
|
|
33
25
|
|
|
34
|
-
const instanceMap = componentData.get(component) as Map<HTMLElement,
|
|
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
|
|
46
|
-
component
|
|
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
|
|
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
|
|
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;
|
|
@@ -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:
|
|
13
|
-
if (
|
|
14
|
-
return selector
|
|
13
|
+
const querySelector = (selector: HTMLElement | string, parent?: ParentNode): HTMLElement | null => {
|
|
14
|
+
if (isHTMLElement(selector)) {
|
|
15
|
+
return selector;
|
|
15
16
|
}
|
|
16
|
-
const lookUp =
|
|
17
|
+
const lookUp = isNode(parent) ? parent : getDocument();
|
|
17
18
|
|
|
18
|
-
return lookUp.querySelector(selector
|
|
19
|
+
return lookUp.querySelector(selector);
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
export default querySelector;
|