@whitesev/utils 2.11.5 → 2.11.6
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 +158 -24
- 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 +158 -24
- 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 +158 -24
- 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 +158 -24
- 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 +158 -24
- 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 +158 -24
- 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 +61 -1
- package/package.json +1 -1
- package/src/Utils.ts +222 -20
package/dist/index.system.js
CHANGED
|
@@ -242,7 +242,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
242
242
|
const setInterval$1 = (...args) => loadOrReturnBroker().setInterval(...args);
|
|
243
243
|
const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
|
|
244
244
|
|
|
245
|
-
const version = "2.11.
|
|
245
|
+
const version = "2.11.6";
|
|
246
246
|
|
|
247
247
|
/* eslint-disable */
|
|
248
248
|
// ==UserScript==
|
|
@@ -6078,15 +6078,9 @@ System.register('Utils', [], (function (exports) {
|
|
|
6078
6078
|
}
|
|
6079
6079
|
return diffValue;
|
|
6080
6080
|
}
|
|
6081
|
-
/**
|
|
6082
|
-
* 获取最大值
|
|
6083
|
-
* @example
|
|
6084
|
-
* Utils.getMaxValue([{1:123},{2:345},{3:456}],(index,value)=>{return parseInt(index)})
|
|
6085
|
-
* > 2
|
|
6086
|
-
*/
|
|
6087
6081
|
getMaxValue(...args) {
|
|
6088
6082
|
const result = [...args];
|
|
6089
|
-
|
|
6083
|
+
const newResult = [];
|
|
6090
6084
|
if (result.length === 0) {
|
|
6091
6085
|
return void 0;
|
|
6092
6086
|
}
|
|
@@ -6095,13 +6089,20 @@ System.register('Utils', [], (function (exports) {
|
|
|
6095
6089
|
const data = result[0];
|
|
6096
6090
|
const handleDataFunc = result[1];
|
|
6097
6091
|
Object.keys(data).forEach((keyName) => {
|
|
6098
|
-
newResult
|
|
6092
|
+
newResult.push(handleDataFunc(keyName, data[keyName]));
|
|
6093
|
+
});
|
|
6094
|
+
}
|
|
6095
|
+
else if (result.length === 2 && Array.isArray(result[0]) && typeof result[1] === "function") {
|
|
6096
|
+
const data = result[0];
|
|
6097
|
+
const handleDataFunc = result[1];
|
|
6098
|
+
data.forEach((value, index, __data__) => {
|
|
6099
|
+
newResult.push(handleDataFunc(value, index, __data__));
|
|
6099
6100
|
});
|
|
6100
6101
|
}
|
|
6101
6102
|
else {
|
|
6102
6103
|
result.forEach((item) => {
|
|
6103
6104
|
if (!isNaN(parseFloat(item))) {
|
|
6104
|
-
newResult
|
|
6105
|
+
newResult.push(parseFloat(item));
|
|
6105
6106
|
}
|
|
6106
6107
|
});
|
|
6107
6108
|
}
|
|
@@ -6110,7 +6111,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
6110
6111
|
else {
|
|
6111
6112
|
result[0].forEach((item) => {
|
|
6112
6113
|
if (!isNaN(parseFloat(item))) {
|
|
6113
|
-
newResult
|
|
6114
|
+
newResult.push(parseFloat(item));
|
|
6114
6115
|
}
|
|
6115
6116
|
});
|
|
6116
6117
|
return Math.max(...newResult);
|
|
@@ -6129,45 +6130,61 @@ System.register('Utils', [], (function (exports) {
|
|
|
6129
6130
|
let maxZIndexNode = null;
|
|
6130
6131
|
/**
|
|
6131
6132
|
* 元素是否可见
|
|
6133
|
+
* @param $el
|
|
6132
6134
|
* @param $css
|
|
6133
6135
|
*/
|
|
6134
|
-
function isVisibleNode($css) {
|
|
6135
|
-
|
|
6136
|
+
function isVisibleNode($el, $css) {
|
|
6137
|
+
let flag = true;
|
|
6138
|
+
if (typeof $el.checkVisibility === "function") {
|
|
6139
|
+
flag = $el.checkVisibility();
|
|
6140
|
+
}
|
|
6141
|
+
else {
|
|
6142
|
+
flag =
|
|
6143
|
+
$css.position !== "static" && $css.display !== "none" && $css.visibility !== "hidden" && $css.opacity !== "0";
|
|
6144
|
+
}
|
|
6145
|
+
if (flag) {
|
|
6146
|
+
// css样式上可见
|
|
6147
|
+
// 再判断宽高
|
|
6148
|
+
const rect = $el.getBoundingClientRect();
|
|
6149
|
+
// 确保该元素的中心点在屏幕内
|
|
6150
|
+
flag = rect.width > 0 && rect.height > 0 && rect.x > 0 && rect.y > 0;
|
|
6151
|
+
}
|
|
6152
|
+
return flag;
|
|
6136
6153
|
}
|
|
6137
6154
|
/**
|
|
6138
6155
|
* 查询元素的z-index
|
|
6139
6156
|
* 并比较值是否是已获取的最大值
|
|
6140
|
-
* @param $
|
|
6157
|
+
* @param $el
|
|
6141
6158
|
*/
|
|
6142
|
-
function queryMaxZIndex($
|
|
6159
|
+
function queryMaxZIndex($el) {
|
|
6143
6160
|
if (typeof ignoreCallBack === "function") {
|
|
6144
|
-
const ignoreResult = ignoreCallBack($
|
|
6161
|
+
const ignoreResult = ignoreCallBack($el);
|
|
6145
6162
|
if (typeof ignoreResult === "boolean" && !ignoreResult) {
|
|
6146
6163
|
return;
|
|
6147
6164
|
}
|
|
6148
6165
|
}
|
|
6149
6166
|
/** 元素的样式 */
|
|
6150
|
-
const nodeStyle = that.windowApi.window.getComputedStyle($
|
|
6167
|
+
const nodeStyle = that.windowApi.window.getComputedStyle($el);
|
|
6151
6168
|
/* 不对position为static和display为none的元素进行获取它们的z-index */
|
|
6152
|
-
if (isVisibleNode(nodeStyle)) {
|
|
6169
|
+
if (isVisibleNode($el, nodeStyle)) {
|
|
6153
6170
|
const nodeZIndex = parseInt(nodeStyle.zIndex);
|
|
6154
6171
|
if (!isNaN(nodeZIndex)) {
|
|
6155
6172
|
if (nodeZIndex > zIndex) {
|
|
6156
6173
|
// 赋值到全局
|
|
6157
6174
|
zIndex = nodeZIndex;
|
|
6158
|
-
maxZIndexNode = $
|
|
6175
|
+
maxZIndexNode = $el;
|
|
6159
6176
|
}
|
|
6160
6177
|
}
|
|
6161
6178
|
// 判断shadowRoot
|
|
6162
|
-
if ($
|
|
6163
|
-
$
|
|
6179
|
+
if ($el.shadowRoot != null && $el instanceof ShadowRoot) {
|
|
6180
|
+
$el.shadowRoot.querySelectorAll("*").forEach(($shadowEle) => {
|
|
6164
6181
|
queryMaxZIndex($shadowEle);
|
|
6165
6182
|
});
|
|
6166
6183
|
}
|
|
6167
6184
|
}
|
|
6168
6185
|
}
|
|
6169
|
-
target.querySelectorAll("*").forEach(($
|
|
6170
|
-
queryMaxZIndex($
|
|
6186
|
+
target.querySelectorAll("*").forEach(($elItem) => {
|
|
6187
|
+
queryMaxZIndex($elItem);
|
|
6171
6188
|
});
|
|
6172
6189
|
zIndex += deviation;
|
|
6173
6190
|
if (zIndex >= maxZIndexCompare) {
|
|
@@ -6179,6 +6196,124 @@ System.register('Utils', [], (function (exports) {
|
|
|
6179
6196
|
zIndex: zIndex,
|
|
6180
6197
|
};
|
|
6181
6198
|
}
|
|
6199
|
+
getMaxZIndexNodeInfoFromPoint($el, deviation) {
|
|
6200
|
+
if (typeof $el === "number") {
|
|
6201
|
+
deviation = $el;
|
|
6202
|
+
$el = void 0;
|
|
6203
|
+
}
|
|
6204
|
+
if (typeof deviation !== "number" || Number.isNaN(deviation)) {
|
|
6205
|
+
deviation = 10;
|
|
6206
|
+
}
|
|
6207
|
+
const leftTop = {
|
|
6208
|
+
x: globalThis.innerWidth * (1 / 8),
|
|
6209
|
+
y: globalThis.innerHeight * (1 / 8),
|
|
6210
|
+
};
|
|
6211
|
+
const leftBottom = {
|
|
6212
|
+
x: globalThis.innerWidth * (1 / 8),
|
|
6213
|
+
y: globalThis.innerHeight * (7 / 8),
|
|
6214
|
+
};
|
|
6215
|
+
const rightTop = {
|
|
6216
|
+
x: globalThis.innerWidth * (7 / 8),
|
|
6217
|
+
y: globalThis.innerHeight * (1 / 8),
|
|
6218
|
+
};
|
|
6219
|
+
const rightBottom = {
|
|
6220
|
+
x: globalThis.innerWidth * (7 / 8),
|
|
6221
|
+
y: globalThis.innerHeight * (7 / 8),
|
|
6222
|
+
};
|
|
6223
|
+
const center = {
|
|
6224
|
+
x: globalThis.innerWidth / 2,
|
|
6225
|
+
y: globalThis.innerHeight / 2,
|
|
6226
|
+
};
|
|
6227
|
+
const delayHandlerElementPostionList = [
|
|
6228
|
+
leftTop,
|
|
6229
|
+
leftBottom,
|
|
6230
|
+
rightTop,
|
|
6231
|
+
rightBottom,
|
|
6232
|
+
center,
|
|
6233
|
+
];
|
|
6234
|
+
if ($el) {
|
|
6235
|
+
delayHandlerElementPostionList.length = 0;
|
|
6236
|
+
if (Array.isArray($el)) {
|
|
6237
|
+
delayHandlerElementPostionList.push(...$el);
|
|
6238
|
+
}
|
|
6239
|
+
else {
|
|
6240
|
+
delayHandlerElementPostionList.push($el);
|
|
6241
|
+
}
|
|
6242
|
+
}
|
|
6243
|
+
const positionInfoList = delayHandlerElementPostionList
|
|
6244
|
+
.map((position) => {
|
|
6245
|
+
let positionNode;
|
|
6246
|
+
let positionX;
|
|
6247
|
+
let positionY;
|
|
6248
|
+
if (position instanceof HTMLElement) {
|
|
6249
|
+
positionNode = position;
|
|
6250
|
+
const nodeRect = position.getBoundingClientRect();
|
|
6251
|
+
positionX = nodeRect.x + nodeRect.width / 2;
|
|
6252
|
+
positionY = nodeRect.y + nodeRect.height / 2;
|
|
6253
|
+
}
|
|
6254
|
+
else {
|
|
6255
|
+
positionNode = document.elementFromPoint(position.x, position.y);
|
|
6256
|
+
positionX = position.x;
|
|
6257
|
+
positionY = position.y;
|
|
6258
|
+
}
|
|
6259
|
+
const shadowRoot = positionNode?.shadowRoot;
|
|
6260
|
+
if (shadowRoot) {
|
|
6261
|
+
positionNode = shadowRoot.elementFromPoint(positionX, positionY);
|
|
6262
|
+
}
|
|
6263
|
+
if (positionNode instanceof HTMLStyleElement)
|
|
6264
|
+
return;
|
|
6265
|
+
if (positionNode instanceof HTMLScriptElement)
|
|
6266
|
+
return;
|
|
6267
|
+
if (positionNode instanceof HTMLMetaElement)
|
|
6268
|
+
return;
|
|
6269
|
+
if (positionNode instanceof HTMLHeadElement)
|
|
6270
|
+
return;
|
|
6271
|
+
if (!(positionNode instanceof HTMLElement))
|
|
6272
|
+
return;
|
|
6273
|
+
let parent = positionNode;
|
|
6274
|
+
let zIndex = 0;
|
|
6275
|
+
let maxZIndexNode = null;
|
|
6276
|
+
while (parent) {
|
|
6277
|
+
const nodeStyle = globalThis.getComputedStyle(parent);
|
|
6278
|
+
const nodeZIndex = parseInt(nodeStyle.zIndex);
|
|
6279
|
+
if (nodeStyle.position !== "static" && !isNaN(nodeZIndex)) {
|
|
6280
|
+
if (nodeZIndex > zIndex) {
|
|
6281
|
+
zIndex = nodeZIndex;
|
|
6282
|
+
maxZIndexNode = parent;
|
|
6283
|
+
}
|
|
6284
|
+
}
|
|
6285
|
+
parent = parent.parentElement;
|
|
6286
|
+
}
|
|
6287
|
+
return {
|
|
6288
|
+
/** 处理了偏移量后的z-index值 */
|
|
6289
|
+
zIndex: zIndex + deviation,
|
|
6290
|
+
/** 原始z-index值 */
|
|
6291
|
+
originZIndex: zIndex,
|
|
6292
|
+
/** 拥有最大z-index的元素 */
|
|
6293
|
+
node: maxZIndexNode,
|
|
6294
|
+
/** 目标坐标元素 */
|
|
6295
|
+
positionNode: positionNode,
|
|
6296
|
+
/** x坐标 */
|
|
6297
|
+
positionX: positionX,
|
|
6298
|
+
/** y坐标 */
|
|
6299
|
+
positionY: positionY,
|
|
6300
|
+
};
|
|
6301
|
+
})
|
|
6302
|
+
.filter((it) => it != null);
|
|
6303
|
+
// 降序排序
|
|
6304
|
+
positionInfoList.sort((a, b) => {
|
|
6305
|
+
if (a.zIndex < b.zIndex) {
|
|
6306
|
+
return 1;
|
|
6307
|
+
}
|
|
6308
|
+
else if (a.zIndex > b.zIndex) {
|
|
6309
|
+
return -1;
|
|
6310
|
+
}
|
|
6311
|
+
else {
|
|
6312
|
+
return 0;
|
|
6313
|
+
}
|
|
6314
|
+
});
|
|
6315
|
+
return positionInfoList;
|
|
6316
|
+
}
|
|
6182
6317
|
getMaxZIndex(deviation = 1, target = this.windowApi.document, ignoreCallBack) {
|
|
6183
6318
|
return this.getMaxZIndexNodeInfo(deviation, target, ignoreCallBack).zIndex;
|
|
6184
6319
|
}
|
|
@@ -6732,7 +6867,6 @@ System.register('Utils', [], (function (exports) {
|
|
|
6732
6867
|
"is",
|
|
6733
6868
|
"jquery",
|
|
6734
6869
|
"keydown",
|
|
6735
|
-
"keypress",
|
|
6736
6870
|
"keyup",
|
|
6737
6871
|
"last",
|
|
6738
6872
|
"load",
|