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