@whitesev/utils 2.11.5 → 2.11.7

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