@whitesev/utils 2.11.6 → 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 +94 -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 +94 -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 +94 -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 +94 -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 +94 -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 +94 -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 +21 -16
- package/dist/types/src/types/env.d.ts +6 -0
- package/package.json +1 -1
- package/src/Utils.ts +114 -83
- package/src/types/env.d.ts +6 -0
package/dist/index.esm.js
CHANGED
|
@@ -237,7 +237,7 @@ const clearTimeout$1 = (timerId) => loadOrReturnBroker().clearTimeout(timerId);
|
|
|
237
237
|
const setInterval$1 = (...args) => loadOrReturnBroker().setInterval(...args);
|
|
238
238
|
const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
|
|
239
239
|
|
|
240
|
-
const version = "2.11.
|
|
240
|
+
const version = "2.11.8";
|
|
241
241
|
|
|
242
242
|
/* eslint-disable */
|
|
243
243
|
// ==UserScript==
|
|
@@ -6127,31 +6127,35 @@ class Utils {
|
|
|
6127
6127
|
* 元素是否可见
|
|
6128
6128
|
* @param $el
|
|
6129
6129
|
* @param $css
|
|
6130
|
+
* @returns
|
|
6131
|
+
* + true 可见
|
|
6132
|
+
* + false 不可见
|
|
6130
6133
|
*/
|
|
6131
|
-
function
|
|
6134
|
+
const isVisibleNode = function ($css, $el) {
|
|
6132
6135
|
let flag = true;
|
|
6133
|
-
if (
|
|
6134
|
-
flag =
|
|
6136
|
+
if (!($el instanceof HTMLElement)) {
|
|
6137
|
+
flag = false;
|
|
6135
6138
|
}
|
|
6136
6139
|
else {
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6140
|
+
if (typeof $el.checkVisibility === "function") {
|
|
6141
|
+
flag = $el.checkVisibility();
|
|
6142
|
+
}
|
|
6143
|
+
else {
|
|
6144
|
+
flag =
|
|
6145
|
+
$css.position !== "static" &&
|
|
6146
|
+
$css.display !== "none" &&
|
|
6147
|
+
$css.visibility !== "hidden" &&
|
|
6148
|
+
$css.opacity !== "0";
|
|
6149
|
+
}
|
|
6146
6150
|
}
|
|
6147
6151
|
return flag;
|
|
6148
|
-
}
|
|
6152
|
+
};
|
|
6149
6153
|
/**
|
|
6150
6154
|
* 查询元素的z-index
|
|
6151
6155
|
* 并比较值是否是已获取的最大值
|
|
6152
6156
|
* @param $el
|
|
6153
6157
|
*/
|
|
6154
|
-
function
|
|
6158
|
+
const queryMaxZIndex = function ($el) {
|
|
6155
6159
|
if (typeof ignoreCallBack === "function") {
|
|
6156
6160
|
const ignoreResult = ignoreCallBack($el);
|
|
6157
6161
|
if (typeof ignoreResult === "boolean" && !ignoreResult) {
|
|
@@ -6159,9 +6163,9 @@ class Utils {
|
|
|
6159
6163
|
}
|
|
6160
6164
|
}
|
|
6161
6165
|
/** 元素的样式 */
|
|
6162
|
-
const nodeStyle = that.windowApi.
|
|
6166
|
+
const nodeStyle = that.windowApi.globalThis.getComputedStyle($el);
|
|
6163
6167
|
/* 不对position为static和display为none的元素进行获取它们的z-index */
|
|
6164
|
-
if (isVisibleNode($el
|
|
6168
|
+
if (isVisibleNode(nodeStyle, $el)) {
|
|
6165
6169
|
const nodeZIndex = parseInt(nodeStyle.zIndex);
|
|
6166
6170
|
if (!isNaN(nodeZIndex)) {
|
|
6167
6171
|
if (nodeZIndex > zIndex) {
|
|
@@ -6177,7 +6181,7 @@ class Utils {
|
|
|
6177
6181
|
});
|
|
6178
6182
|
}
|
|
6179
6183
|
}
|
|
6180
|
-
}
|
|
6184
|
+
};
|
|
6181
6185
|
target.querySelectorAll("*").forEach(($elItem) => {
|
|
6182
6186
|
queryMaxZIndex($elItem);
|
|
6183
6187
|
});
|
|
@@ -6192,6 +6196,9 @@ class Utils {
|
|
|
6192
6196
|
};
|
|
6193
6197
|
}
|
|
6194
6198
|
getMaxZIndexNodeInfoFromPoint($el, deviation) {
|
|
6199
|
+
if (typeof $el === "function") {
|
|
6200
|
+
$el = $el();
|
|
6201
|
+
}
|
|
6195
6202
|
if (typeof $el === "number") {
|
|
6196
6203
|
deviation = $el;
|
|
6197
6204
|
$el = void 0;
|
|
@@ -6199,33 +6206,31 @@ class Utils {
|
|
|
6199
6206
|
if (typeof deviation !== "number" || Number.isNaN(deviation)) {
|
|
6200
6207
|
deviation = 10;
|
|
6201
6208
|
}
|
|
6202
|
-
|
|
6203
|
-
|
|
6204
|
-
|
|
6205
|
-
|
|
6206
|
-
const
|
|
6207
|
-
|
|
6208
|
-
|
|
6209
|
-
|
|
6210
|
-
|
|
6211
|
-
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
|
|
6217
|
-
|
|
6218
|
-
|
|
6219
|
-
|
|
6220
|
-
|
|
6221
|
-
|
|
6222
|
-
|
|
6223
|
-
|
|
6224
|
-
|
|
6225
|
-
|
|
6226
|
-
|
|
6227
|
-
center,
|
|
6228
|
-
];
|
|
6209
|
+
/** 坐标偏移 */
|
|
6210
|
+
const positionDistance = 10;
|
|
6211
|
+
const defaultCalcPostion = [];
|
|
6212
|
+
const maxPostionX = globalThis.innerWidth;
|
|
6213
|
+
const maxPostionY = globalThis.innerHeight;
|
|
6214
|
+
const gridXCount = 8;
|
|
6215
|
+
const gridYCount = 8;
|
|
6216
|
+
for (let i = 0; i < gridXCount; i++) {
|
|
6217
|
+
for (let j = 0; j < gridYCount; j++) {
|
|
6218
|
+
const positionX = globalThis.innerWidth * (i / gridXCount) + positionDistance;
|
|
6219
|
+
const positionY = globalThis.innerHeight * (j / gridYCount) + positionDistance;
|
|
6220
|
+
const position = {
|
|
6221
|
+
x: positionX,
|
|
6222
|
+
y: positionY,
|
|
6223
|
+
};
|
|
6224
|
+
if (position.x > maxPostionX) {
|
|
6225
|
+
position.x = maxPostionX;
|
|
6226
|
+
}
|
|
6227
|
+
if (position.y > maxPostionY) {
|
|
6228
|
+
position.y = maxPostionY;
|
|
6229
|
+
}
|
|
6230
|
+
defaultCalcPostion.push(position);
|
|
6231
|
+
}
|
|
6232
|
+
}
|
|
6233
|
+
const delayHandlerElementPostionList = defaultCalcPostion;
|
|
6229
6234
|
if ($el) {
|
|
6230
6235
|
delayHandlerElementPostionList.length = 0;
|
|
6231
6236
|
if (Array.isArray($el)) {
|
|
@@ -6237,61 +6242,79 @@ class Utils {
|
|
|
6237
6242
|
}
|
|
6238
6243
|
const positionInfoList = delayHandlerElementPostionList
|
|
6239
6244
|
.map((position) => {
|
|
6240
|
-
let
|
|
6245
|
+
let $position;
|
|
6241
6246
|
let positionX;
|
|
6242
6247
|
let positionY;
|
|
6243
6248
|
if (position instanceof HTMLElement) {
|
|
6244
|
-
|
|
6249
|
+
$position = position;
|
|
6245
6250
|
const nodeRect = position.getBoundingClientRect();
|
|
6246
6251
|
positionX = nodeRect.x + nodeRect.width / 2;
|
|
6247
6252
|
positionY = nodeRect.y + nodeRect.height / 2;
|
|
6248
6253
|
}
|
|
6249
6254
|
else {
|
|
6250
|
-
|
|
6255
|
+
$position = document.elementFromPoint(position.x, position.y);
|
|
6251
6256
|
positionX = position.x;
|
|
6252
6257
|
positionY = position.y;
|
|
6253
6258
|
}
|
|
6254
|
-
const shadowRoot =
|
|
6259
|
+
const shadowRoot = $position?.shadowRoot;
|
|
6255
6260
|
if (shadowRoot) {
|
|
6256
|
-
|
|
6261
|
+
// 处理ShadowRoot
|
|
6262
|
+
$position = shadowRoot.elementFromPoint(positionX, positionY);
|
|
6257
6263
|
}
|
|
6258
|
-
if (
|
|
6264
|
+
if (!($position instanceof HTMLElement))
|
|
6259
6265
|
return;
|
|
6260
|
-
|
|
6261
|
-
return;
|
|
6262
|
-
if (positionNode instanceof HTMLMetaElement)
|
|
6263
|
-
return;
|
|
6264
|
-
if (positionNode instanceof HTMLHeadElement)
|
|
6265
|
-
return;
|
|
6266
|
-
if (!(positionNode instanceof HTMLElement))
|
|
6267
|
-
return;
|
|
6268
|
-
let parent = positionNode;
|
|
6266
|
+
let $parent = $position;
|
|
6269
6267
|
let zIndex = 0;
|
|
6270
|
-
let maxZIndexNode = null;
|
|
6271
|
-
|
|
6272
|
-
|
|
6268
|
+
let $maxZIndexNode = null;
|
|
6269
|
+
let rect = {
|
|
6270
|
+
x: 0,
|
|
6271
|
+
y: 0,
|
|
6272
|
+
width: 0,
|
|
6273
|
+
height: 0,
|
|
6274
|
+
top: 0,
|
|
6275
|
+
right: 0,
|
|
6276
|
+
bottom: 0,
|
|
6277
|
+
left: 0,
|
|
6278
|
+
};
|
|
6279
|
+
while ($parent) {
|
|
6280
|
+
const nodeStyle = globalThis.getComputedStyle($parent);
|
|
6273
6281
|
const nodeZIndex = parseInt(nodeStyle.zIndex);
|
|
6274
6282
|
if (nodeStyle.position !== "static" && !isNaN(nodeZIndex)) {
|
|
6275
6283
|
if (nodeZIndex > zIndex) {
|
|
6276
6284
|
zIndex = nodeZIndex;
|
|
6277
|
-
maxZIndexNode = parent;
|
|
6285
|
+
$maxZIndexNode = $parent;
|
|
6278
6286
|
}
|
|
6279
6287
|
}
|
|
6280
|
-
parent = parent.parentElement;
|
|
6288
|
+
$parent = $parent.parentElement;
|
|
6289
|
+
}
|
|
6290
|
+
if ($maxZIndexNode) {
|
|
6291
|
+
const maxRect = $maxZIndexNode.getBoundingClientRect();
|
|
6292
|
+
rect = {
|
|
6293
|
+
x: maxRect.x,
|
|
6294
|
+
y: maxRect.y,
|
|
6295
|
+
width: maxRect.width,
|
|
6296
|
+
height: maxRect.height,
|
|
6297
|
+
top: maxRect.top,
|
|
6298
|
+
right: maxRect.right,
|
|
6299
|
+
bottom: maxRect.bottom,
|
|
6300
|
+
left: maxRect.left,
|
|
6301
|
+
};
|
|
6281
6302
|
}
|
|
6282
6303
|
return {
|
|
6283
|
-
/**
|
|
6304
|
+
/** 计算偏移量后的z-index值 */
|
|
6284
6305
|
zIndex: zIndex + deviation,
|
|
6285
|
-
/**
|
|
6306
|
+
/** 获取到的最大的z-index值 */
|
|
6286
6307
|
originZIndex: zIndex,
|
|
6287
6308
|
/** 拥有最大z-index的元素 */
|
|
6288
|
-
node: maxZIndexNode,
|
|
6309
|
+
node: $maxZIndexNode,
|
|
6289
6310
|
/** 目标坐标元素 */
|
|
6290
|
-
positionNode:
|
|
6291
|
-
/** x坐标 */
|
|
6311
|
+
positionNode: $position,
|
|
6312
|
+
/** 目标x坐标 */
|
|
6292
6313
|
positionX: positionX,
|
|
6293
|
-
/** y坐标 */
|
|
6314
|
+
/** 目标y坐标 */
|
|
6294
6315
|
positionY: positionY,
|
|
6316
|
+
/** node位置信息 */
|
|
6317
|
+
rect,
|
|
6295
6318
|
};
|
|
6296
6319
|
})
|
|
6297
6320
|
.filter((it) => it != null);
|