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