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