@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.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.6";
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
  });
@@ -6192,6 +6196,9 @@ class Utils {
6192
6196
  };
6193
6197
  }
6194
6198
  getMaxZIndexNodeInfoFromPoint($el, deviation) {
6199
+ if (typeof $el === "function") {
6200
+ $el = $el();
6201
+ }
6195
6202
  if (typeof $el === "number") {
6196
6203
  deviation = $el;
6197
6204
  $el = void 0;
@@ -6199,33 +6206,31 @@ class Utils {
6199
6206
  if (typeof deviation !== "number" || Number.isNaN(deviation)) {
6200
6207
  deviation = 10;
6201
6208
  }
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
- ];
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;
6229
6234
  if ($el) {
6230
6235
  delayHandlerElementPostionList.length = 0;
6231
6236
  if (Array.isArray($el)) {
@@ -6237,61 +6242,79 @@ class Utils {
6237
6242
  }
6238
6243
  const positionInfoList = delayHandlerElementPostionList
6239
6244
  .map((position) => {
6240
- let positionNode;
6245
+ let $position;
6241
6246
  let positionX;
6242
6247
  let positionY;
6243
6248
  if (position instanceof HTMLElement) {
6244
- positionNode = position;
6249
+ $position = position;
6245
6250
  const nodeRect = position.getBoundingClientRect();
6246
6251
  positionX = nodeRect.x + nodeRect.width / 2;
6247
6252
  positionY = nodeRect.y + nodeRect.height / 2;
6248
6253
  }
6249
6254
  else {
6250
- positionNode = document.elementFromPoint(position.x, position.y);
6255
+ $position = document.elementFromPoint(position.x, position.y);
6251
6256
  positionX = position.x;
6252
6257
  positionY = position.y;
6253
6258
  }
6254
- const shadowRoot = positionNode?.shadowRoot;
6259
+ const shadowRoot = $position?.shadowRoot;
6255
6260
  if (shadowRoot) {
6256
- positionNode = shadowRoot.elementFromPoint(positionX, positionY);
6261
+ // 处理ShadowRoot
6262
+ $position = shadowRoot.elementFromPoint(positionX, positionY);
6257
6263
  }
6258
- if (positionNode instanceof HTMLStyleElement)
6264
+ if (!($position instanceof HTMLElement))
6259
6265
  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;
6266
+ let $parent = $position;
6269
6267
  let zIndex = 0;
6270
- let maxZIndexNode = null;
6271
- while (parent) {
6272
- 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);
6273
6281
  const nodeZIndex = parseInt(nodeStyle.zIndex);
6274
6282
  if (nodeStyle.position !== "static" && !isNaN(nodeZIndex)) {
6275
6283
  if (nodeZIndex > zIndex) {
6276
6284
  zIndex = nodeZIndex;
6277
- maxZIndexNode = parent;
6285
+ $maxZIndexNode = $parent;
6278
6286
  }
6279
6287
  }
6280
- 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
+ };
6281
6302
  }
6282
6303
  return {
6283
- /** 处理了偏移量后的z-index值 */
6304
+ /** 计算偏移量后的z-index值 */
6284
6305
  zIndex: zIndex + deviation,
6285
- /** 原始z-index值 */
6306
+ /** 获取到的最大的z-index值 */
6286
6307
  originZIndex: zIndex,
6287
6308
  /** 拥有最大z-index的元素 */
6288
- node: maxZIndexNode,
6309
+ node: $maxZIndexNode,
6289
6310
  /** 目标坐标元素 */
6290
- positionNode: positionNode,
6291
- /** x坐标 */
6311
+ positionNode: $position,
6312
+ /** 目标x坐标 */
6292
6313
  positionX: positionX,
6293
- /** y坐标 */
6314
+ /** 目标y坐标 */
6294
6315
  positionY: positionY,
6316
+ /** node位置信息 */
6317
+ rect,
6295
6318
  };
6296
6319
  })
6297
6320
  .filter((it) => it != null);