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