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