@whitesev/utils 2.11.7 → 2.11.8
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/index.amd.js +91 -71
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +91 -71
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +91 -71
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +91 -71
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +91 -71
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +91 -71
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/Utils.d.ts +20 -15
- package/dist/types/src/types/env.d.ts +2 -0
- package/package.json +1 -1
- package/src/Utils.ts +110 -82
- package/src/types/env.d.ts +2 -0
|
@@ -351,17 +351,26 @@ declare class Utils {
|
|
|
351
351
|
/**
|
|
352
352
|
* 获取页面的坐标中最大的z-index的元素信息
|
|
353
353
|
*
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
* + 左上角(宽: 1/8,高: 1/8)
|
|
357
|
-
* + 右上角(宽: 7/8,高: 1/8)
|
|
358
|
-
* + 左下角(宽: 1/8,高: 7/8)
|
|
359
|
-
* + 右下角(宽: 7/8,高: 7/8)
|
|
360
|
-
* + 中间(宽: 1/2,高: 1/2)
|
|
354
|
+
* 矩阵坐标计算
|
|
361
355
|
* @param $el 仅检测目标元素最大的z-index(自动往上层找)
|
|
362
356
|
* @param deviation 将对所有获取到的z-index处理偏移量(增加或减少),默认为10
|
|
357
|
+
* @example
|
|
358
|
+
* Utils.getMaxZIndexNodeInfoFromPoint(document.querySelector("a"));
|
|
359
|
+
* @example
|
|
360
|
+
* Utils.getMaxZIndexNodeInfoFromPoint(document.querySelector("a"), 20);
|
|
361
|
+
* @example
|
|
362
|
+
* Utils.getMaxZIndexNodeInfoFromPoint([document.querySelector("a"), document.querySelector("div")]);
|
|
363
|
+
* @example
|
|
364
|
+
* Utils.getMaxZIndexNodeInfoFromPoint({x: 500, y: 500});
|
|
365
|
+
* @example
|
|
366
|
+
* Utils.getMaxZIndexNodeInfoFromPoint({x: 500, y: 500}, 20);
|
|
367
|
+
* @example
|
|
368
|
+
* Utils.getMaxZIndexNodeInfoFromPoint(() => {x: 500, y: 500}, 20);
|
|
363
369
|
*/
|
|
364
|
-
getMaxZIndexNodeInfoFromPoint($el?: IFunction<HTMLElement |
|
|
370
|
+
getMaxZIndexNodeInfoFromPoint($el?: IFunction<IArray<HTMLElement> | IArray<{
|
|
371
|
+
x: number;
|
|
372
|
+
y: number;
|
|
373
|
+
}>>, deviation?: number): {
|
|
365
374
|
/** 处理了偏移量后的z-index值 */
|
|
366
375
|
zIndex: number;
|
|
367
376
|
/** 原始z-index值 */
|
|
@@ -378,14 +387,10 @@ declare class Utils {
|
|
|
378
387
|
/**
|
|
379
388
|
* 获取页面的坐标中最大的z-index的元素信息
|
|
380
389
|
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
* + 左上角(宽: 1/8,高: 1/8)
|
|
384
|
-
* + 右上角(宽: 7/8,高: 1/8)
|
|
385
|
-
* + 左下角(宽: 1/8,高: 7/8)
|
|
386
|
-
* + 右下角(宽: 7/8,高: 7/8)
|
|
387
|
-
* + 中间(宽: 1/2,高: 1/2)
|
|
390
|
+
* 矩阵坐标计算
|
|
388
391
|
* @param deviation 将对所有获取到的z-index处理偏移量(增加或减少)
|
|
392
|
+
* @example
|
|
393
|
+
* Utils.getMaxZIndexNodeInfoFromPoint(20);
|
|
389
394
|
*/
|
|
390
395
|
getMaxZIndexNodeInfoFromPoint(deviation: IFunction<number>): {
|
|
391
396
|
/** 处理了偏移量后的z-index值 */
|
package/package.json
CHANGED
package/src/Utils.ts
CHANGED
|
@@ -817,30 +817,33 @@ class Utils {
|
|
|
817
817
|
* 元素是否可见
|
|
818
818
|
* @param $el
|
|
819
819
|
* @param $css
|
|
820
|
+
* @returns
|
|
821
|
+
* + true 可见
|
|
822
|
+
* + false 不可见
|
|
820
823
|
*/
|
|
821
|
-
function
|
|
824
|
+
const isVisibleNode = function ($css: CSSStyleDeclaration, $el: Element): boolean {
|
|
822
825
|
let flag = true;
|
|
823
|
-
if (
|
|
824
|
-
flag =
|
|
826
|
+
if (!($el instanceof HTMLElement)) {
|
|
827
|
+
flag = false;
|
|
825
828
|
} else {
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
829
|
+
if (typeof $el.checkVisibility === "function") {
|
|
830
|
+
flag = $el.checkVisibility();
|
|
831
|
+
} else {
|
|
832
|
+
flag =
|
|
833
|
+
$css.position !== "static" &&
|
|
834
|
+
$css.display !== "none" &&
|
|
835
|
+
$css.visibility !== "hidden" &&
|
|
836
|
+
$css.opacity !== "0";
|
|
837
|
+
}
|
|
835
838
|
}
|
|
836
839
|
return flag;
|
|
837
|
-
}
|
|
840
|
+
};
|
|
838
841
|
/**
|
|
839
842
|
* 查询元素的z-index
|
|
840
843
|
* 并比较值是否是已获取的最大值
|
|
841
844
|
* @param $el
|
|
842
845
|
*/
|
|
843
|
-
function
|
|
846
|
+
const queryMaxZIndex = function ($el: Element) {
|
|
844
847
|
if (typeof ignoreCallBack === "function") {
|
|
845
848
|
const ignoreResult = ignoreCallBack($el);
|
|
846
849
|
if (typeof ignoreResult === "boolean" && !ignoreResult) {
|
|
@@ -848,9 +851,9 @@ class Utils {
|
|
|
848
851
|
}
|
|
849
852
|
}
|
|
850
853
|
/** 元素的样式 */
|
|
851
|
-
const nodeStyle = that.windowApi.
|
|
854
|
+
const nodeStyle = that.windowApi.globalThis.getComputedStyle($el);
|
|
852
855
|
/* 不对position为static和display为none的元素进行获取它们的z-index */
|
|
853
|
-
if (isVisibleNode($el
|
|
856
|
+
if (isVisibleNode(nodeStyle, $el)) {
|
|
854
857
|
const nodeZIndex = parseInt(nodeStyle.zIndex);
|
|
855
858
|
if (!isNaN(nodeZIndex)) {
|
|
856
859
|
if (nodeZIndex > zIndex) {
|
|
@@ -866,7 +869,7 @@ class Utils {
|
|
|
866
869
|
});
|
|
867
870
|
}
|
|
868
871
|
}
|
|
869
|
-
}
|
|
872
|
+
};
|
|
870
873
|
target.querySelectorAll("*").forEach(($elItem) => {
|
|
871
874
|
queryMaxZIndex($elItem);
|
|
872
875
|
});
|
|
@@ -883,18 +886,24 @@ class Utils {
|
|
|
883
886
|
/**
|
|
884
887
|
* 获取页面的坐标中最大的z-index的元素信息
|
|
885
888
|
*
|
|
886
|
-
*
|
|
887
|
-
*
|
|
888
|
-
* + 左上角(宽: 1/8,高: 1/8)
|
|
889
|
-
* + 右上角(宽: 7/8,高: 1/8)
|
|
890
|
-
* + 左下角(宽: 1/8,高: 7/8)
|
|
891
|
-
* + 右下角(宽: 7/8,高: 7/8)
|
|
892
|
-
* + 中间(宽: 1/2,高: 1/2)
|
|
889
|
+
* 矩阵坐标计算
|
|
893
890
|
* @param $el 仅检测目标元素最大的z-index(自动往上层找)
|
|
894
891
|
* @param deviation 将对所有获取到的z-index处理偏移量(增加或减少),默认为10
|
|
892
|
+
* @example
|
|
893
|
+
* Utils.getMaxZIndexNodeInfoFromPoint(document.querySelector("a"));
|
|
894
|
+
* @example
|
|
895
|
+
* Utils.getMaxZIndexNodeInfoFromPoint(document.querySelector("a"), 20);
|
|
896
|
+
* @example
|
|
897
|
+
* Utils.getMaxZIndexNodeInfoFromPoint([document.querySelector("a"), document.querySelector("div")]);
|
|
898
|
+
* @example
|
|
899
|
+
* Utils.getMaxZIndexNodeInfoFromPoint({x: 500, y: 500});
|
|
900
|
+
* @example
|
|
901
|
+
* Utils.getMaxZIndexNodeInfoFromPoint({x: 500, y: 500}, 20);
|
|
902
|
+
* @example
|
|
903
|
+
* Utils.getMaxZIndexNodeInfoFromPoint(() => {x: 500, y: 500}, 20);
|
|
895
904
|
*/
|
|
896
905
|
getMaxZIndexNodeInfoFromPoint(
|
|
897
|
-
$el?: IFunction<HTMLElement |
|
|
906
|
+
$el?: IFunction<IArray<HTMLElement> | IArray<{ x: number; y: number }>>,
|
|
898
907
|
deviation?: number
|
|
899
908
|
): {
|
|
900
909
|
/** 处理了偏移量后的z-index值 */
|
|
@@ -913,14 +922,10 @@ class Utils {
|
|
|
913
922
|
/**
|
|
914
923
|
* 获取页面的坐标中最大的z-index的元素信息
|
|
915
924
|
*
|
|
916
|
-
*
|
|
917
|
-
*
|
|
918
|
-
* + 左上角(宽: 1/8,高: 1/8)
|
|
919
|
-
* + 右上角(宽: 7/8,高: 1/8)
|
|
920
|
-
* + 左下角(宽: 1/8,高: 7/8)
|
|
921
|
-
* + 右下角(宽: 7/8,高: 7/8)
|
|
922
|
-
* + 中间(宽: 1/2,高: 1/2)
|
|
925
|
+
* 矩阵坐标计算
|
|
923
926
|
* @param deviation 将对所有获取到的z-index处理偏移量(增加或减少)
|
|
927
|
+
* @example
|
|
928
|
+
* Utils.getMaxZIndexNodeInfoFromPoint(20);
|
|
924
929
|
*/
|
|
925
930
|
getMaxZIndexNodeInfoFromPoint(deviation: IFunction<number>): {
|
|
926
931
|
/** 处理了偏移量后的z-index值 */
|
|
@@ -937,7 +942,7 @@ class Utils {
|
|
|
937
942
|
positionY: number;
|
|
938
943
|
}[];
|
|
939
944
|
getMaxZIndexNodeInfoFromPoint(
|
|
940
|
-
$el?: IFunction<HTMLElement |
|
|
945
|
+
$el?: IFunction<IArray<HTMLElement> | number | IArray<{ x: number; y: number }>>,
|
|
941
946
|
deviation?: number
|
|
942
947
|
): {
|
|
943
948
|
/** 处理了偏移量后的z-index值 */
|
|
@@ -963,33 +968,34 @@ class Utils {
|
|
|
963
968
|
if (typeof deviation !== "number" || Number.isNaN(deviation)) {
|
|
964
969
|
deviation = 10;
|
|
965
970
|
}
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
const
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
971
|
+
/** 坐标偏移 */
|
|
972
|
+
const positionDistance = 10;
|
|
973
|
+
const defaultCalcPostion: {
|
|
974
|
+
x: number;
|
|
975
|
+
y: number;
|
|
976
|
+
}[] = [];
|
|
977
|
+
const maxPostionX = globalThis.innerWidth;
|
|
978
|
+
const maxPostionY = globalThis.innerHeight;
|
|
979
|
+
const gridXCount = 8;
|
|
980
|
+
const gridYCount = 8;
|
|
981
|
+
for (let i = 0; i < gridXCount; i++) {
|
|
982
|
+
for (let j = 0; j < gridYCount; j++) {
|
|
983
|
+
const positionX = globalThis.innerWidth * (i / gridXCount) + positionDistance;
|
|
984
|
+
const positionY = globalThis.innerHeight * (j / gridYCount) + positionDistance;
|
|
985
|
+
const position: (typeof defaultCalcPostion)[0] = {
|
|
986
|
+
x: positionX,
|
|
987
|
+
y: positionY,
|
|
988
|
+
};
|
|
989
|
+
if (position.x > maxPostionX) {
|
|
990
|
+
position.x = maxPostionX;
|
|
991
|
+
}
|
|
992
|
+
if (position.y > maxPostionY) {
|
|
993
|
+
position.y = maxPostionY;
|
|
994
|
+
}
|
|
995
|
+
defaultCalcPostion.push(position);
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
const delayHandlerElementPostionList: ({ x: number; y: number } | HTMLElement)[] = defaultCalcPostion;
|
|
993
999
|
if ($el) {
|
|
994
1000
|
delayHandlerElementPostionList.length = 0;
|
|
995
1001
|
if (Array.isArray($el)) {
|
|
@@ -1000,55 +1006,77 @@ class Utils {
|
|
|
1000
1006
|
}
|
|
1001
1007
|
const positionInfoList = delayHandlerElementPostionList
|
|
1002
1008
|
.map((position) => {
|
|
1003
|
-
let
|
|
1009
|
+
let $position: Element | null;
|
|
1004
1010
|
let positionX: number;
|
|
1005
1011
|
let positionY: number;
|
|
1006
1012
|
if (position instanceof HTMLElement) {
|
|
1007
|
-
|
|
1013
|
+
$position = position;
|
|
1008
1014
|
const nodeRect = position.getBoundingClientRect();
|
|
1009
1015
|
positionX = nodeRect.x + nodeRect.width / 2;
|
|
1010
1016
|
positionY = nodeRect.y + nodeRect.height / 2;
|
|
1011
1017
|
} else {
|
|
1012
|
-
|
|
1018
|
+
$position = document.elementFromPoint(position.x, position.y);
|
|
1013
1019
|
positionX = position.x;
|
|
1014
1020
|
positionY = position.y;
|
|
1015
1021
|
}
|
|
1016
|
-
const shadowRoot =
|
|
1022
|
+
const shadowRoot = $position?.shadowRoot;
|
|
1017
1023
|
if (shadowRoot) {
|
|
1018
|
-
|
|
1024
|
+
// 处理ShadowRoot
|
|
1025
|
+
$position = shadowRoot.elementFromPoint(positionX, positionY);
|
|
1019
1026
|
}
|
|
1020
|
-
if (
|
|
1021
|
-
|
|
1022
|
-
if (positionNode instanceof HTMLMetaElement) return;
|
|
1023
|
-
if (positionNode instanceof HTMLHeadElement) return;
|
|
1024
|
-
if (!(positionNode instanceof HTMLElement)) return;
|
|
1025
|
-
let parent: HTMLElement | null = positionNode;
|
|
1027
|
+
if (!($position instanceof HTMLElement)) return;
|
|
1028
|
+
let $parent: HTMLElement | null = $position;
|
|
1026
1029
|
let zIndex = 0;
|
|
1027
|
-
let maxZIndexNode: HTMLElement | null = null;
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
+
let $maxZIndexNode: HTMLElement | null = null;
|
|
1031
|
+
let rect = {
|
|
1032
|
+
x: 0,
|
|
1033
|
+
y: 0,
|
|
1034
|
+
width: 0,
|
|
1035
|
+
height: 0,
|
|
1036
|
+
top: 0,
|
|
1037
|
+
right: 0,
|
|
1038
|
+
bottom: 0,
|
|
1039
|
+
left: 0,
|
|
1040
|
+
} as Omit<DOMRect, "toJSON">;
|
|
1041
|
+
while ($parent) {
|
|
1042
|
+
const nodeStyle = globalThis.getComputedStyle($parent);
|
|
1030
1043
|
const nodeZIndex = parseInt(nodeStyle.zIndex);
|
|
1031
1044
|
if (nodeStyle.position !== "static" && !isNaN(nodeZIndex)) {
|
|
1032
1045
|
if (nodeZIndex > zIndex) {
|
|
1033
1046
|
zIndex = nodeZIndex;
|
|
1034
|
-
maxZIndexNode = parent;
|
|
1047
|
+
$maxZIndexNode = $parent;
|
|
1035
1048
|
}
|
|
1036
1049
|
}
|
|
1037
|
-
parent = parent.parentElement;
|
|
1050
|
+
$parent = $parent.parentElement;
|
|
1051
|
+
}
|
|
1052
|
+
if ($maxZIndexNode) {
|
|
1053
|
+
const maxRect = $maxZIndexNode.getBoundingClientRect();
|
|
1054
|
+
rect = {
|
|
1055
|
+
x: maxRect.x,
|
|
1056
|
+
y: maxRect.y,
|
|
1057
|
+
width: maxRect.width,
|
|
1058
|
+
height: maxRect.height,
|
|
1059
|
+
top: maxRect.top,
|
|
1060
|
+
right: maxRect.right,
|
|
1061
|
+
bottom: maxRect.bottom,
|
|
1062
|
+
left: maxRect.left,
|
|
1063
|
+
};
|
|
1038
1064
|
}
|
|
1039
1065
|
return {
|
|
1040
|
-
/**
|
|
1066
|
+
/** 计算偏移量后的z-index值 */
|
|
1041
1067
|
zIndex: zIndex + deviation,
|
|
1042
|
-
/**
|
|
1068
|
+
/** 获取到的最大的z-index值 */
|
|
1043
1069
|
originZIndex: zIndex,
|
|
1044
1070
|
/** 拥有最大z-index的元素 */
|
|
1045
|
-
node: maxZIndexNode,
|
|
1071
|
+
node: $maxZIndexNode,
|
|
1046
1072
|
/** 目标坐标元素 */
|
|
1047
|
-
positionNode:
|
|
1048
|
-
/** x坐标 */
|
|
1073
|
+
positionNode: $position,
|
|
1074
|
+
/** 目标x坐标 */
|
|
1049
1075
|
positionX: positionX,
|
|
1050
|
-
/** y坐标 */
|
|
1076
|
+
/** 目标y坐标 */
|
|
1051
1077
|
positionY: positionY,
|
|
1078
|
+
/** node位置信息 */
|
|
1079
|
+
rect,
|
|
1052
1080
|
};
|
|
1053
1081
|
})
|
|
1054
1082
|
.filter((it) => it != null);
|