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