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