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