@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
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
|
});
|
|
@@ -6202,33 +6206,31 @@ class Utils {
|
|
|
6202
6206
|
if (typeof deviation !== "number" || Number.isNaN(deviation)) {
|
|
6203
6207
|
deviation = 10;
|
|
6204
6208
|
}
|
|
6205
|
-
|
|
6206
|
-
|
|
6207
|
-
|
|
6208
|
-
|
|
6209
|
-
const
|
|
6210
|
-
|
|
6211
|
-
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
|
|
6217
|
-
|
|
6218
|
-
|
|
6219
|
-
|
|
6220
|
-
|
|
6221
|
-
|
|
6222
|
-
|
|
6223
|
-
|
|
6224
|
-
|
|
6225
|
-
|
|
6226
|
-
|
|
6227
|
-
|
|
6228
|
-
|
|
6229
|
-
|
|
6230
|
-
center,
|
|
6231
|
-
];
|
|
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;
|
|
6232
6234
|
if ($el) {
|
|
6233
6235
|
delayHandlerElementPostionList.length = 0;
|
|
6234
6236
|
if (Array.isArray($el)) {
|
|
@@ -6240,61 +6242,79 @@ class Utils {
|
|
|
6240
6242
|
}
|
|
6241
6243
|
const positionInfoList = delayHandlerElementPostionList
|
|
6242
6244
|
.map((position) => {
|
|
6243
|
-
let
|
|
6245
|
+
let $position;
|
|
6244
6246
|
let positionX;
|
|
6245
6247
|
let positionY;
|
|
6246
6248
|
if (position instanceof HTMLElement) {
|
|
6247
|
-
|
|
6249
|
+
$position = position;
|
|
6248
6250
|
const nodeRect = position.getBoundingClientRect();
|
|
6249
6251
|
positionX = nodeRect.x + nodeRect.width / 2;
|
|
6250
6252
|
positionY = nodeRect.y + nodeRect.height / 2;
|
|
6251
6253
|
}
|
|
6252
6254
|
else {
|
|
6253
|
-
|
|
6255
|
+
$position = document.elementFromPoint(position.x, position.y);
|
|
6254
6256
|
positionX = position.x;
|
|
6255
6257
|
positionY = position.y;
|
|
6256
6258
|
}
|
|
6257
|
-
const shadowRoot =
|
|
6259
|
+
const shadowRoot = $position?.shadowRoot;
|
|
6258
6260
|
if (shadowRoot) {
|
|
6259
|
-
|
|
6261
|
+
// 处理ShadowRoot
|
|
6262
|
+
$position = shadowRoot.elementFromPoint(positionX, positionY);
|
|
6260
6263
|
}
|
|
6261
|
-
if (
|
|
6264
|
+
if (!($position instanceof HTMLElement))
|
|
6262
6265
|
return;
|
|
6263
|
-
|
|
6264
|
-
return;
|
|
6265
|
-
if (positionNode instanceof HTMLMetaElement)
|
|
6266
|
-
return;
|
|
6267
|
-
if (positionNode instanceof HTMLHeadElement)
|
|
6268
|
-
return;
|
|
6269
|
-
if (!(positionNode instanceof HTMLElement))
|
|
6270
|
-
return;
|
|
6271
|
-
let parent = positionNode;
|
|
6266
|
+
let $parent = $position;
|
|
6272
6267
|
let zIndex = 0;
|
|
6273
|
-
let maxZIndexNode = null;
|
|
6274
|
-
|
|
6275
|
-
|
|
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);
|
|
6276
6281
|
const nodeZIndex = parseInt(nodeStyle.zIndex);
|
|
6277
6282
|
if (nodeStyle.position !== "static" && !isNaN(nodeZIndex)) {
|
|
6278
6283
|
if (nodeZIndex > zIndex) {
|
|
6279
6284
|
zIndex = nodeZIndex;
|
|
6280
|
-
maxZIndexNode = parent;
|
|
6285
|
+
$maxZIndexNode = $parent;
|
|
6281
6286
|
}
|
|
6282
6287
|
}
|
|
6283
|
-
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
|
+
};
|
|
6284
6302
|
}
|
|
6285
6303
|
return {
|
|
6286
|
-
/**
|
|
6304
|
+
/** 计算偏移量后的z-index值 */
|
|
6287
6305
|
zIndex: zIndex + deviation,
|
|
6288
|
-
/**
|
|
6306
|
+
/** 获取到的最大的z-index值 */
|
|
6289
6307
|
originZIndex: zIndex,
|
|
6290
6308
|
/** 拥有最大z-index的元素 */
|
|
6291
|
-
node: maxZIndexNode,
|
|
6309
|
+
node: $maxZIndexNode,
|
|
6292
6310
|
/** 目标坐标元素 */
|
|
6293
|
-
positionNode:
|
|
6294
|
-
/** x坐标 */
|
|
6311
|
+
positionNode: $position,
|
|
6312
|
+
/** 目标x坐标 */
|
|
6295
6313
|
positionX: positionX,
|
|
6296
|
-
/** y坐标 */
|
|
6314
|
+
/** 目标y坐标 */
|
|
6297
6315
|
positionY: positionY,
|
|
6316
|
+
/** node位置信息 */
|
|
6317
|
+
rect,
|
|
6298
6318
|
};
|
|
6299
6319
|
})
|
|
6300
6320
|
.filter((it) => it != null);
|