@whitesev/utils 2.0.2 → 2.1.0

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.cjs.js CHANGED
@@ -226,45 +226,16 @@ class GBKEncoder {
226
226
  }
227
227
  }
228
228
 
229
- const UtilsCoreDefaultEnv = {
230
- document: document,
231
- window: window,
232
- globalThis: globalThis,
233
- self: self,
234
- top: top,
235
- };
236
- const UtilsCoreEnv = {
237
- document: document,
238
- window: window,
239
- globalThis: globalThis,
240
- self: self,
241
- top: top,
242
- };
243
- const UtilsCore = {
244
- init(option) {
245
- if (!option) {
246
- option = Object.assign({}, UtilsCoreDefaultEnv);
247
- }
248
- Object.assign(UtilsCoreEnv, option);
249
- },
250
- get document() {
251
- return UtilsCoreEnv.document;
252
- },
253
- get window() {
254
- return UtilsCoreEnv.window;
255
- },
256
- get globalThis() {
257
- return UtilsCoreEnv.globalThis;
258
- },
259
- get self() {
260
- return UtilsCoreEnv.self;
261
- },
262
- get top() {
263
- return UtilsCoreEnv.top;
264
- },
265
- };
266
-
267
229
  class UtilsGMCookie {
230
+ windowApi = {
231
+ window: window,
232
+ document: document,
233
+ };
234
+ constructor(windowApiOption) {
235
+ if (windowApiOption) {
236
+ this.windowApi = Object.assign({}, windowApiOption);
237
+ }
238
+ }
268
239
  /**
269
240
  * 获取单个cookie
270
241
  * @param cookieName cookie名
@@ -273,7 +244,7 @@ class UtilsGMCookie {
273
244
  if (typeof cookieName !== "string") {
274
245
  throw new TypeError("Utils.GMCookie.get 参数cookieName 必须为字符串");
275
246
  }
276
- let cookies = UtilsCore.document.cookie.split(";");
247
+ let cookies = this.windowApi.document.cookie.split(";");
277
248
  let findValue = void 0;
278
249
  for (const cookieItem of cookies) {
279
250
  let item = cookieItem.trim();
@@ -283,7 +254,7 @@ class UtilsGMCookie {
283
254
  let itemValue = decodeURIComponent(itemSplit.join(""));
284
255
  if (itemName === cookieName) {
285
256
  findValue = {
286
- domain: UtilsCore.globalThis.location.hostname,
257
+ domain: this.windowApi.window.location.hostname,
287
258
  expirationDate: null,
288
259
  hostOnly: true,
289
260
  httpOnly: false,
@@ -313,13 +284,13 @@ class UtilsGMCookie {
313
284
  let resultData = [];
314
285
  try {
315
286
  let details = {
316
- url: UtilsCore.globalThis.location.href,
317
- domain: UtilsCore.globalThis.location.hostname,
287
+ url: this.windowApi.window.location.href,
288
+ domain: this.windowApi.window.location.hostname,
318
289
  name: "",
319
290
  path: "/",
320
291
  };
321
292
  details = utils.assign(details, paramDetails);
322
- let cookies = UtilsCore.document.cookie.split(";");
293
+ let cookies = this.windowApi.document.cookie.split(";");
323
294
  cookies.forEach((item) => {
324
295
  item = item.trim();
325
296
  let itemSplit = item.split("=");
@@ -331,7 +302,7 @@ class UtilsGMCookie {
331
302
  : new RegExp("^" + details.name, "g");
332
303
  if (itemName.match(nameRegexp)) {
333
304
  resultData.push({
334
- domain: UtilsCore.globalThis.location.hostname,
305
+ domain: this.windowApi.window.location.hostname,
335
306
  expirationDate: null,
336
307
  hostOnly: true,
337
308
  httpOnly: false,
@@ -364,13 +335,13 @@ class UtilsGMCookie {
364
335
  }
365
336
  let resultData = [];
366
337
  let details = {
367
- url: UtilsCore.globalThis.location.href,
368
- domain: UtilsCore.globalThis.location.hostname,
338
+ url: this.windowApi.window.location.href,
339
+ domain: this.windowApi.window.location.hostname,
369
340
  name: "",
370
341
  path: "/",
371
342
  };
372
343
  details = utils.assign(details, paramDetails);
373
- let cookies = UtilsCore.document.cookie.split(";");
344
+ let cookies = this.windowApi.document.cookie.split(";");
374
345
  cookies.forEach((item) => {
375
346
  item = item.trim();
376
347
  let itemSplit = item.split("=");
@@ -382,7 +353,7 @@ class UtilsGMCookie {
382
353
  : new RegExp("^" + details.name, "g");
383
354
  if (itemName.match(nameRegexp)) {
384
355
  resultData.push({
385
- domain: UtilsCore.globalThis.location.hostname,
356
+ domain: this.windowApi.window.location.hostname,
386
357
  expirationDate: null,
387
358
  hostOnly: true,
388
359
  httpOnly: false,
@@ -405,10 +376,10 @@ class UtilsGMCookie {
405
376
  set(paramDetails, callback = (error) => { }) {
406
377
  try {
407
378
  let details = {
408
- url: UtilsCore.window.location.href,
379
+ url: this.windowApi.window.location.href,
409
380
  name: "",
410
381
  value: "",
411
- domain: UtilsCore.window.location.hostname,
382
+ domain: this.windowApi.window.location.hostname,
412
383
  path: "/",
413
384
  secure: true,
414
385
  httpOnly: false,
@@ -427,7 +398,7 @@ class UtilsGMCookie {
427
398
  ";expires=" +
428
399
  new Date(life).toGMTString() +
429
400
  "; path=/";
430
- UtilsCore.document.cookie = cookieStr;
401
+ this.windowApi.document.cookie = cookieStr;
431
402
  callback();
432
403
  }
433
404
  catch (error) {
@@ -442,14 +413,14 @@ class UtilsGMCookie {
442
413
  delete(paramDetails, callback = (error) => { }) {
443
414
  try {
444
415
  let details = {
445
- url: UtilsCore.window.location.href,
416
+ url: this.windowApi.window.location.href,
446
417
  name: "",
447
418
  // @ts-ignore
448
419
  firstPartyDomain: "",
449
420
  };
450
421
  details = utils.assign(details, paramDetails);
451
422
  let cookieStr = details.name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
452
- UtilsCore.document.cookie = cookieStr;
423
+ this.windowApi.document.cookie = cookieStr;
453
424
  callback();
454
425
  }
455
426
  catch (error) {
@@ -1219,7 +1190,7 @@ class GMMenu {
1219
1190
  }
1220
1191
  /* 不刷新网页就刷新菜单 */
1221
1192
  if (menuOption.autoReload) {
1222
- UtilsCore.window.location.reload();
1193
+ window.location.reload();
1223
1194
  }
1224
1195
  else {
1225
1196
  that.context.update();
@@ -1538,8 +1509,8 @@ class Hooks {
1538
1509
  * 生成uuid
1539
1510
  */
1540
1511
  const GenerateUUID = function () {
1541
- if (typeof UtilsCore.globalThis?.crypto?.randomUUID === "function") {
1542
- return UtilsCore.globalThis.crypto.randomUUID();
1512
+ if (typeof window?.crypto?.randomUUID === "function") {
1513
+ return window.crypto.randomUUID();
1543
1514
  }
1544
1515
  else {
1545
1516
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (charStr) {
@@ -1911,14 +1882,13 @@ class Httpx {
1911
1882
  }
1912
1883
  catch (error) {
1913
1884
  if (details.url.startsWith("//")) {
1914
- details.url = UtilsCore.globalThis.location.protocol + details.url;
1885
+ details.url = window.location.protocol + details.url;
1915
1886
  }
1916
1887
  else if (details.url.startsWith("/")) {
1917
- details.url = UtilsCore.globalThis.location.origin + details.url;
1888
+ details.url = window.location.origin + details.url;
1918
1889
  }
1919
1890
  else {
1920
- details.url =
1921
- UtilsCore.globalThis.location.origin + "/" + details.url;
1891
+ details.url = window.location.origin + "/" + details.url;
1922
1892
  }
1923
1893
  }
1924
1894
  return details;
@@ -2544,10 +2514,10 @@ class indexedDB {
2544
2514
  // @ts-ignore
2545
2515
  #slqVersion = "1";
2546
2516
  /* 监听IndexDB */
2547
- #indexedDB = UtilsCore.window.indexedDB ||
2548
- UtilsCore.window.mozIndexedDB ||
2549
- UtilsCore.window.webkitIndexedDB ||
2550
- UtilsCore.window.msIndexedDB;
2517
+ #indexedDB = window.indexedDB ||
2518
+ window.mozIndexedDB ||
2519
+ window.webkitIndexedDB ||
2520
+ window.msIndexedDB;
2551
2521
  /* 缓存数据库,避免同一个页面重复创建和销毁 */
2552
2522
  #db = {};
2553
2523
  // @ts-ignore
@@ -2977,7 +2947,7 @@ class Log {
2977
2947
  * @param _GM_info_ 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}},或者直接是一个字符串
2978
2948
  * @param console 可指定console对象为unsafeWindow下的console或者是油猴window下的console
2979
2949
  */
2980
- constructor(_GM_info_, console = UtilsCore.window.console) {
2950
+ constructor(_GM_info_, console = window.console) {
2981
2951
  if (typeof _GM_info_ === "string") {
2982
2952
  this.tag = _GM_info_;
2983
2953
  }
@@ -3238,14 +3208,12 @@ class Progress {
3238
3208
  /* 元素高度 */
3239
3209
  this.#height = this.#config.canvasNode.height;
3240
3210
  /* 清除锯齿 */
3241
- if (UtilsCore.window.devicePixelRatio) {
3211
+ if (window.devicePixelRatio) {
3242
3212
  this.#config.canvasNode.style.width = this.#width + "px";
3243
3213
  this.#config.canvasNode.style.height = this.#height + "px";
3244
- this.#config.canvasNode.height =
3245
- this.#height * UtilsCore.window.devicePixelRatio;
3246
- this.#config.canvasNode.width =
3247
- this.#width * UtilsCore.window.devicePixelRatio;
3248
- this.#ctx.scale(UtilsCore.window.devicePixelRatio, UtilsCore.window.devicePixelRatio);
3214
+ this.#config.canvasNode.height = this.#height * window.devicePixelRatio;
3215
+ this.#config.canvasNode.width = this.#width * window.devicePixelRatio;
3216
+ this.#ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
3249
3217
  }
3250
3218
  /* 设置线宽 */
3251
3219
  this.#ctx.lineWidth = this.#config.lineWidth;
@@ -3514,9 +3482,44 @@ class UtilsDictionary {
3514
3482
  }
3515
3483
  }
3516
3484
 
3485
+ class UtilsWindowApi {
3486
+ /** 默认的配置 */
3487
+ defaultApi = {
3488
+ document: document,
3489
+ window: window,
3490
+ globalThis: globalThis,
3491
+ self: self,
3492
+ top: top,
3493
+ };
3494
+ /** 使用的配置 */
3495
+ api;
3496
+ constructor(option) {
3497
+ if (!option) {
3498
+ option = Object.assign({}, this.defaultApi);
3499
+ }
3500
+ this.api = Object.assign({}, option);
3501
+ }
3502
+ get document() {
3503
+ return this.api.document;
3504
+ }
3505
+ get window() {
3506
+ return this.api.window;
3507
+ }
3508
+ get globalThis() {
3509
+ return this.api.globalThis;
3510
+ }
3511
+ get self() {
3512
+ return this.api.self;
3513
+ }
3514
+ get top() {
3515
+ return this.api.top;
3516
+ }
3517
+ }
3518
+
3517
3519
  class Utils {
3520
+ windowApi;
3518
3521
  constructor(option) {
3519
- UtilsCore.init(option);
3522
+ this.windowApi = new UtilsWindowApi(option);
3520
3523
  }
3521
3524
  /** 版本号 */
3522
3525
  version = "2024.7.20";
@@ -3524,24 +3527,24 @@ class Utils {
3524
3527
  if (typeof cssText !== "string") {
3525
3528
  throw new Error("Utils.addStyle 参数cssText 必须为String类型");
3526
3529
  }
3527
- let cssNode = UtilsCore.document.createElement("style");
3530
+ let cssNode = this.windowApi.document.createElement("style");
3528
3531
  cssNode.setAttribute("type", "text/css");
3529
3532
  cssNode.innerHTML = cssText;
3530
- if (UtilsCore.document.head) {
3533
+ if (this.windowApi.document.head) {
3531
3534
  /* 插入head最后 */
3532
- UtilsCore.document.head.appendChild(cssNode);
3535
+ this.windowApi.document.head.appendChild(cssNode);
3533
3536
  }
3534
- else if (UtilsCore.document.body) {
3537
+ else if (this.windowApi.document.body) {
3535
3538
  /* 插入body后 */
3536
- UtilsCore.document.body.appendChild(cssNode);
3539
+ this.windowApi.document.body.appendChild(cssNode);
3537
3540
  }
3538
- else if (UtilsCore.document.documentElement.childNodes.length === 0) {
3541
+ else if (this.windowApi.document.documentElement.childNodes.length === 0) {
3539
3542
  /* 插入#html第一个元素后 */
3540
- UtilsCore.document.documentElement.appendChild(cssNode);
3543
+ this.windowApi.document.documentElement.appendChild(cssNode);
3541
3544
  }
3542
3545
  else {
3543
3546
  /* 插入head前面 */
3544
- UtilsCore.document.documentElement.insertBefore(cssNode, UtilsCore.document.documentElement.childNodes[0]);
3547
+ this.windowApi.document.documentElement.insertBefore(cssNode, this.windowApi.document.documentElement.childNodes[0]);
3545
3548
  }
3546
3549
  return cssNode;
3547
3550
  }
@@ -3672,7 +3675,7 @@ class Utils {
3672
3675
  let elementPosXRight = Number(element.getBoundingClientRect().right); /* 要检测的元素的相对屏幕的横坐标最右边 */
3673
3676
  let elementPosYTop = Number(element.getBoundingClientRect().top); /* 要检测的元素的相对屏幕的纵坐标最上边 */
3674
3677
  let elementPosYBottom = Number(element.getBoundingClientRect().bottom); /* 要检测的元素的相对屏幕的纵坐标最下边 */
3675
- let clickNodeHTML = UtilsCore.window.event.target
3678
+ let clickNodeHTML = this.windowApi.window.event.target
3676
3679
  .innerHTML;
3677
3680
  if (mouseClickPosX >= elementPosXLeft &&
3678
3681
  mouseClickPosX <= elementPosXRight &&
@@ -3801,18 +3804,18 @@ class Utils {
3801
3804
  }
3802
3805
  if (isIFrame) {
3803
3806
  /* 使用iframe */
3804
- const iframeElement = UtilsCore.document.createElement("iframe");
3807
+ const iframeElement = this.windowApi.document.createElement("iframe");
3805
3808
  iframeElement.style.display = "none";
3806
3809
  iframeElement.src = base64Data;
3807
- UtilsCore.document.body.appendChild(iframeElement);
3810
+ this.windowApi.document.body.appendChild(iframeElement);
3808
3811
  setTimeout(() => {
3809
3812
  iframeElement.contentWindow.document.execCommand("SaveAs", true, fileName);
3810
- UtilsCore.document.body.removeChild(iframeElement);
3813
+ this.windowApi.document.body.removeChild(iframeElement);
3811
3814
  }, 100);
3812
3815
  }
3813
3816
  else {
3814
3817
  /* 使用A标签 */
3815
- const linkElement = UtilsCore.document.createElement("a");
3818
+ const linkElement = this.windowApi.document.createElement("a");
3816
3819
  linkElement.setAttribute("target", "_blank");
3817
3820
  linkElement.download = fileName;
3818
3821
  linkElement.href = base64Data;
@@ -3822,13 +3825,13 @@ class Utils {
3822
3825
  findWebPageVisibleText(str = "", caseSensitive = false) {
3823
3826
  let TRange = null;
3824
3827
  let strFound;
3825
- if (UtilsCore.globalThis.find) {
3828
+ if (this.windowApi.globalThis.find) {
3826
3829
  /* CODE FOR BROWSERS THAT SUPPORT window.find */
3827
- let windowFind = UtilsCore.self.find;
3830
+ let windowFind = this.windowApi.self.find;
3828
3831
  strFound = windowFind(str, caseSensitive, true, true, false);
3829
3832
  if (strFound &&
3830
- UtilsCore.self.getSelection &&
3831
- !UtilsCore.self.getSelection().anchorNode) {
3833
+ this.windowApi.self.getSelection &&
3834
+ !this.windowApi.self.getSelection().anchorNode) {
3832
3835
  strFound = windowFind(str, caseSensitive, true, true, false);
3833
3836
  }
3834
3837
  if (!strFound) {
@@ -3847,7 +3850,7 @@ class Utils {
3847
3850
  TRange.select();
3848
3851
  }
3849
3852
  if (TRange == null || strFound == 0) {
3850
- TRange = UtilsCore.self.document.body.createTextRange();
3853
+ TRange = this.windowApi.self.document.body.createTextRange();
3851
3854
  strFound = TRange.findText(str);
3852
3855
  if (strFound)
3853
3856
  TRange.select();
@@ -4223,8 +4226,8 @@ class Utils {
4223
4226
  let maxZIndexCompare = 2 * Math.pow(10, 9);
4224
4227
  // 当前页面最大的z-index
4225
4228
  let zIndex = 0;
4226
- UtilsCore.document.querySelectorAll("*").forEach(($ele, index) => {
4227
- let nodeStyle = UtilsCore.window.getComputedStyle($ele);
4229
+ this.windowApi.document.querySelectorAll("*").forEach(($ele, index) => {
4230
+ let nodeStyle = this.windowApi.window.getComputedStyle($ele);
4228
4231
  /* 不对position为static和display为none的元素进行获取它们的z-index */
4229
4232
  if (nodeStyle.position !== "static" && nodeStyle.display !== "none") {
4230
4233
  let nodeZIndex = parseInt(nodeStyle.zIndex);
@@ -4438,7 +4441,7 @@ class Utils {
4438
4441
  if (url.trim() === "") {
4439
4442
  throw new TypeError("url不能为空字符串或纯空格");
4440
4443
  }
4441
- return `thunder://${UtilsCore.globalThis.btoa("AA" + url + "ZZ")}`;
4444
+ return `thunder://${this.windowApi.globalThis.btoa("AA" + url + "ZZ")}`;
4442
4445
  }
4443
4446
  /**
4444
4447
  * 对于GM_cookie的兼容写法,当无法使用GM_cookie时可以使用这个,但是并不完全兼容,有些写不出来且限制了httponly是无法访问的
@@ -4653,21 +4656,21 @@ class Utils {
4653
4656
  return Boolean(target.toString().match(/^function .*\(\) { \[native code\] }$/));
4654
4657
  }
4655
4658
  isNearBottom(nearValue = 50) {
4656
- var scrollTop = UtilsCore.window.pageYOffset ||
4657
- UtilsCore.document.documentElement.scrollTop;
4658
- var windowHeight = UtilsCore.window.innerHeight ||
4659
- UtilsCore.document.documentElement.clientHeight;
4660
- var documentHeight = UtilsCore.document.documentElement.scrollHeight;
4659
+ var scrollTop = this.windowApi.window.pageYOffset ||
4660
+ this.windowApi.document.documentElement.scrollTop;
4661
+ var windowHeight = this.windowApi.window.innerHeight ||
4662
+ this.windowApi.document.documentElement.clientHeight;
4663
+ var documentHeight = this.windowApi.document.documentElement.scrollHeight;
4661
4664
  return scrollTop + windowHeight >= documentHeight - nearValue;
4662
4665
  }
4663
4666
  isDOM(target) {
4664
4667
  return target instanceof Node;
4665
4668
  }
4666
4669
  isFullscreenEnabled() {
4667
- return !!(UtilsCore.document.fullscreenEnabled ||
4668
- UtilsCore.document.webkitFullScreenEnabled ||
4669
- UtilsCore.document.mozFullScreenEnabled ||
4670
- UtilsCore.document.msFullScreenEnabled);
4670
+ return !!(this.windowApi.document.fullscreenEnabled ||
4671
+ this.windowApi.document.webkitFullScreenEnabled ||
4672
+ this.windowApi.document.mozFullScreenEnabled ||
4673
+ this.windowApi.document.msFullScreenEnabled);
4671
4674
  }
4672
4675
  isJQuery(target) {
4673
4676
  let result = false;
@@ -4900,7 +4903,7 @@ class Utils {
4900
4903
  return result;
4901
4904
  }
4902
4905
  isThemeDark() {
4903
- return UtilsCore.globalThis.matchMedia("(prefers-color-scheme: dark)")
4906
+ return this.windowApi.globalThis.matchMedia("(prefers-color-scheme: dark)")
4904
4907
  .matches;
4905
4908
  }
4906
4909
  isVisible(element, inView = false) {
@@ -4914,17 +4917,17 @@ class Utils {
4914
4917
  }
4915
4918
  let result = true;
4916
4919
  for (const domItem of needCheckDomList) {
4917
- let domDisplay = UtilsCore.window.getComputedStyle(domItem);
4920
+ let domDisplay = this.windowApi.window.getComputedStyle(domItem);
4918
4921
  if (domDisplay.display === "none") {
4919
4922
  result = false;
4920
4923
  }
4921
4924
  else {
4922
4925
  let domClientRect = domItem.getBoundingClientRect();
4923
4926
  if (inView) {
4924
- let viewportWidth = UtilsCore.window.innerWidth ||
4925
- UtilsCore.document.documentElement.clientWidth;
4926
- let viewportHeight = UtilsCore.window.innerHeight ||
4927
- UtilsCore.document.documentElement.clientHeight;
4927
+ let viewportWidth = this.windowApi.window.innerWidth ||
4928
+ this.windowApi.document.documentElement.clientWidth;
4929
+ let viewportHeight = this.windowApi.window.innerHeight ||
4930
+ this.windowApi.document.documentElement.clientHeight;
4928
4931
  result = !(domClientRect.right < 0 ||
4929
4932
  domClientRect.left > viewportWidth ||
4930
4933
  domClientRect.bottom < 0 ||
@@ -4944,10 +4947,10 @@ class Utils {
4944
4947
  isWebView_Via() {
4945
4948
  let result = true;
4946
4949
  let UtilsContext = this;
4947
- if (typeof UtilsCore.top.window.via === "object") {
4948
- for (const key in Object.values(UtilsCore.top.window.via)) {
4949
- if (Reflect.has(UtilsCore.top.window.via, key)) {
4950
- let objValueFunc = UtilsCore.top.window.via[key];
4950
+ if (typeof this.windowApi.top.window.via === "object") {
4951
+ for (const key in Object.values(this.windowApi.top.window.via)) {
4952
+ if (Reflect.has(this.windowApi.top.window.via, key)) {
4953
+ let objValueFunc = this.windowApi.top.window.via[key];
4951
4954
  if (typeof objValueFunc === "function" &&
4952
4955
  UtilsContext.isNativeFunc(objValueFunc)) {
4953
4956
  result = true;
@@ -4967,10 +4970,10 @@ class Utils {
4967
4970
  isWebView_X() {
4968
4971
  let result = true;
4969
4972
  let UtilsContext = this;
4970
- if (typeof UtilsCore.top.window.mbrowser === "object") {
4971
- for (const key in Object.values(UtilsCore.top.window.mbrowser)) {
4972
- if (Reflect.has(UtilsCore.top.window.mbrowser, key)) {
4973
- let objValueFunc = UtilsCore.top.window.mbrowser[key];
4973
+ if (typeof this.windowApi.top.window.mbrowser === "object") {
4974
+ for (const key in Object.values(this.windowApi.top.window.mbrowser)) {
4975
+ if (Reflect.has(this.windowApi.top.window.mbrowser, key)) {
4976
+ let objValueFunc = this.windowApi.top.window.mbrowser[key];
4974
4977
  if (typeof objValueFunc === "function" &&
4975
4978
  UtilsContext.isNativeFunc(objValueFunc)) {
4976
4979
  result = true;
@@ -5142,9 +5145,9 @@ class Utils {
5142
5145
  immediate: false,
5143
5146
  };
5144
5147
  observer_config = UtilsContext.assign(default_obverser_config, observer_config);
5145
- let windowMutationObserver = UtilsCore.window.MutationObserver ||
5146
- UtilsCore.window.webkitMutationObserver ||
5147
- UtilsCore.window.MozMutationObserver;
5148
+ let windowMutationObserver = this.windowApi.window.MutationObserver ||
5149
+ this.windowApi.window.webkitMutationObserver ||
5150
+ this.windowApi.window.MozMutationObserver;
5148
5151
  // 观察者对象
5149
5152
  let mutationObserver = new windowMutationObserver(function (mutations, observer) {
5150
5153
  if (typeof observer_config.callback === "function") {
@@ -5180,13 +5183,13 @@ class Utils {
5180
5183
  * let utils = Utils.noConflict();
5181
5184
  * > ...
5182
5185
  */
5183
- noConflict = function () {
5184
- if (UtilsCore.window.Utils) {
5185
- Reflect.deleteProperty(UtilsCore.window, "Utils");
5186
+ noConflict() {
5187
+ if (this.windowApi.window.Utils) {
5188
+ Reflect.deleteProperty(this.windowApi.window, "Utils");
5186
5189
  }
5187
- UtilsCore.window.Utils = utils;
5190
+ this.windowApi.window.Utils = utils;
5188
5191
  return utils;
5189
- };
5192
+ }
5190
5193
  noConflictFunc(needReleaseObject, needReleaseName, functionNameList = [], release = true) {
5191
5194
  let UtilsContext = this;
5192
5195
  if (typeof needReleaseObject !== "object") {
@@ -5203,11 +5206,12 @@ class Utils {
5203
5206
  * 释放所有
5204
5207
  */
5205
5208
  function releaseAll() {
5206
- if (typeof UtilsCore.window[needReleaseKey] !== "undefined") {
5209
+ if (typeof UtilsContext.windowApi.window[needReleaseKey] !==
5210
+ "undefined") {
5207
5211
  /* 已存在 */
5208
5212
  return;
5209
5213
  }
5210
- UtilsCore.window[needReleaseKey] =
5214
+ UtilsContext.windowApi.window[needReleaseKey] =
5211
5215
  UtilsContext.deepClone(needReleaseObject);
5212
5216
  Object.values(needReleaseObject).forEach((value) => {
5213
5217
  if (typeof value === "function") {
@@ -5222,11 +5226,12 @@ class Utils {
5222
5226
  Array.from(functionNameList).forEach((item) => {
5223
5227
  Object.values(needReleaseObject).forEach((value) => {
5224
5228
  if (typeof value === "function") {
5225
- if (typeof UtilsCore.window[needReleaseKey] === "undefined") {
5226
- UtilsCore.window[needReleaseKey] = {};
5229
+ if (typeof UtilsContext.windowApi.window[needReleaseKey] ===
5230
+ "undefined") {
5231
+ UtilsContext.windowApi.window[needReleaseKey] = {};
5227
5232
  }
5228
5233
  if (item === value.name) {
5229
- UtilsCore.window[needReleaseKey][value.name] = needReleaseObject[value.name];
5234
+ UtilsContext.windowApi.window[needReleaseKey][value.name] = needReleaseObject[value.name];
5230
5235
  needReleaseObject[value.name] = () => { };
5231
5236
  }
5232
5237
  }
@@ -5237,26 +5242,29 @@ class Utils {
5237
5242
  * 恢复所有
5238
5243
  */
5239
5244
  function recoveryAll() {
5240
- if (typeof UtilsCore.window[needReleaseKey] === "undefined") {
5245
+ if (typeof UtilsContext.windowApi.window[needReleaseKey] ===
5246
+ "undefined") {
5241
5247
  /* 未存在 */
5242
5248
  return;
5243
5249
  }
5244
- Object.assign(needReleaseObject, UtilsCore.window[needReleaseKey]);
5245
- Reflect.deleteProperty(UtilsCore.window, "needReleaseKey");
5250
+ Object.assign(needReleaseObject, UtilsContext.windowApi.window[needReleaseKey]);
5251
+ Reflect.deleteProperty(UtilsContext.windowApi.window, "needReleaseKey");
5246
5252
  }
5247
5253
  /**
5248
5254
  * 恢复单个
5249
5255
  */
5250
5256
  function recoveryOne() {
5251
- if (typeof UtilsCore.window[needReleaseKey] === "undefined") {
5257
+ if (typeof UtilsContext.windowApi.window[needReleaseKey] ===
5258
+ "undefined") {
5252
5259
  /* 未存在 */
5253
5260
  return;
5254
5261
  }
5255
5262
  Array.from(functionNameList).forEach((item) => {
5256
- if (UtilsCore.window[needReleaseKey][item]) {
5257
- needReleaseObject[item] = UtilsCore.window[needReleaseKey][item];
5258
- Reflect.deleteProperty(UtilsCore.window[needReleaseKey], item);
5259
- if (Object.keys(UtilsCore.window[needReleaseKey]).length === 0) {
5263
+ if (UtilsContext.windowApi.window[needReleaseKey][item]) {
5264
+ needReleaseObject[item] = UtilsContext.windowApi.window[needReleaseKey][item];
5265
+ Reflect.deleteProperty(UtilsContext.windowApi.window[needReleaseKey], item);
5266
+ if (Object.keys(UtilsContext.windowApi.window[needReleaseKey])
5267
+ .length === 0) {
5260
5268
  Reflect.deleteProperty(window, needReleaseKey);
5261
5269
  }
5262
5270
  }
@@ -5462,7 +5470,7 @@ class Utils {
5462
5470
  return isNegative ? -reversedNum : reversedNum;
5463
5471
  }
5464
5472
  selectElementText(element, childTextNode, startIndex, endIndex) {
5465
- let range = UtilsCore.document.createRange();
5473
+ let range = this.windowApi.document.createRange();
5466
5474
  range.selectNodeContents(element);
5467
5475
  if (childTextNode) {
5468
5476
  if (childTextNode.nodeType !== Node.TEXT_NODE) {
@@ -5473,7 +5481,7 @@ class Utils {
5473
5481
  range.setEnd(childTextNode, endIndex);
5474
5482
  }
5475
5483
  }
5476
- let selection = UtilsCore.globalThis.getSelection();
5484
+ let selection = this.windowApi.globalThis.getSelection();
5477
5485
  if (selection) {
5478
5486
  selection.removeAllRanges();
5479
5487
  selection.addRange(range);
@@ -5501,6 +5509,7 @@ class Utils {
5501
5509
  else {
5502
5510
  textType = "text/plain";
5503
5511
  }
5512
+ let UtilsContext = this;
5504
5513
  class UtilsClipboard {
5505
5514
  #resolve;
5506
5515
  #copyData;
@@ -5555,15 +5564,15 @@ class Utils {
5555
5564
  */
5556
5565
  copyTextByTextArea() {
5557
5566
  try {
5558
- let copyElement = UtilsCore.document.createElement("textarea");
5567
+ let copyElement = UtilsContext.windowApi.document.createElement("textarea");
5559
5568
  copyElement.value = this.#copyData;
5560
5569
  copyElement.setAttribute("type", "text");
5561
5570
  copyElement.setAttribute("style", "opacity:0;position:absolute;");
5562
5571
  copyElement.setAttribute("readonly", "readonly");
5563
- UtilsCore.document.body.appendChild(copyElement);
5572
+ UtilsContext.windowApi.document.body.appendChild(copyElement);
5564
5573
  copyElement.select();
5565
- UtilsCore.document.execCommand("copy");
5566
- UtilsCore.document.body.removeChild(copyElement);
5574
+ UtilsContext.windowApi.document.execCommand("copy");
5575
+ UtilsContext.windowApi.document.body.removeChild(copyElement);
5567
5576
  return true;
5568
5577
  }
5569
5578
  catch (error) {
@@ -5640,11 +5649,11 @@ class Utils {
5640
5649
  }
5641
5650
  return new Promise((resolve) => {
5642
5651
  const utilsClipboard = new UtilsClipboard(resolve, data, textType);
5643
- if (UtilsCore.document.hasFocus()) {
5652
+ if (UtilsContext.windowApi.document.hasFocus()) {
5644
5653
  utilsClipboard.init();
5645
5654
  }
5646
5655
  else {
5647
- UtilsCore.window.addEventListener("focus", () => {
5656
+ UtilsContext.windowApi.window.addEventListener("focus", () => {
5648
5657
  utilsClipboard.init();
5649
5658
  }, { once: true });
5650
5659
  }
@@ -5674,15 +5683,16 @@ class Utils {
5674
5683
  }, delayTime);
5675
5684
  });
5676
5685
  }
5677
- dragSlider(selector, offsetX = UtilsCore.window.innerWidth) {
5686
+ dragSlider(selector, offsetX = this.windowApi.window.innerWidth) {
5687
+ let UtilsContext = this;
5678
5688
  function initMouseEvent(eventName, offSetX, offSetY) {
5679
5689
  let win = unsafeWindow || window;
5680
- let mouseEvent = UtilsCore.document.createEvent("MouseEvents");
5690
+ let mouseEvent = UtilsContext.windowApi.document.createEvent("MouseEvents");
5681
5691
  mouseEvent.initMouseEvent(eventName, true, true, win, 0, offSetX, offSetY, offSetX, offSetY, false, false, false, false, 0, null);
5682
5692
  return mouseEvent;
5683
5693
  }
5684
5694
  let sliderElement = typeof selector === "string"
5685
- ? UtilsCore.document.querySelector(selector)
5695
+ ? this.windowApi.document.querySelector(selector)
5686
5696
  : selector;
5687
5697
  if (!(sliderElement instanceof Node) ||
5688
5698
  !(sliderElement instanceof Element)) {
@@ -5694,7 +5704,7 @@ class Utils {
5694
5704
  sliderElement.dispatchEvent(initMouseEvent("mouseleave", x1, y1));
5695
5705
  sliderElement.dispatchEvent(initMouseEvent("mouseout", x1, y1));
5696
5706
  }
5697
- enterFullScreen(element = UtilsCore.document.documentElement, options) {
5707
+ enterFullScreen(element = this.windowApi.document.documentElement, options) {
5698
5708
  try {
5699
5709
  if (element.requestFullscreen) {
5700
5710
  element.requestFullscreen(options);
@@ -5716,18 +5726,18 @@ class Utils {
5716
5726
  console.error(err);
5717
5727
  }
5718
5728
  }
5719
- exitFullScreen(element = UtilsCore.document.documentElement) {
5720
- if (UtilsCore.document.exitFullscreen) {
5721
- return UtilsCore.document.exitFullscreen();
5729
+ exitFullScreen(element = this.windowApi.document.documentElement) {
5730
+ if (this.windowApi.document.exitFullscreen) {
5731
+ return this.windowApi.document.exitFullscreen();
5722
5732
  }
5723
- else if (UtilsCore.document.msExitFullscreen) {
5724
- return UtilsCore.document.msExitFullscreen();
5733
+ else if (this.windowApi.document.msExitFullscreen) {
5734
+ return this.windowApi.document.msExitFullscreen();
5725
5735
  }
5726
- else if (UtilsCore.document.mozCancelFullScreen) {
5727
- return UtilsCore.document.mozCancelFullScreen();
5736
+ else if (this.windowApi.document.mozCancelFullScreen) {
5737
+ return this.windowApi.document.mozCancelFullScreen();
5728
5738
  }
5729
- else if (UtilsCore.document.webkitCancelFullScreen) {
5730
- return UtilsCore.document.webkitCancelFullScreen();
5739
+ else if (this.windowApi.document.webkitCancelFullScreen) {
5740
+ return this.windowApi.document.webkitCancelFullScreen();
5731
5741
  }
5732
5742
  else {
5733
5743
  return new Promise((resolve, reject) => {
@@ -5903,7 +5913,7 @@ class Utils {
5903
5913
  UtilsContext.tryCatch()
5904
5914
  .error(() => {
5905
5915
  try {
5906
- result = UtilsCore.window.eval("(" + data + ")");
5916
+ result = UtilsContext.windowApi.window.eval("(" + data + ")");
5907
5917
  }
5908
5918
  catch (error2) {
5909
5919
  if (typeof errorCallBack === "function") {
@@ -5980,11 +5990,11 @@ class Utils {
5980
5990
  waitNode(...args) {
5981
5991
  // 过滤掉undefined
5982
5992
  args = args.filter((arg) => arg !== void 0);
5983
- let that = this;
5993
+ let UtilsContext = this;
5984
5994
  // 选择器
5985
5995
  let selector = args[0];
5986
5996
  // 父元素(监听的元素)
5987
- let parent = UtilsCore.document;
5997
+ let parent = UtilsContext.windowApi.document;
5988
5998
  // 超时时间
5989
5999
  let timeout = 0;
5990
6000
  if (typeof args[0] !== "string" && !Array.isArray(args[0])) {
@@ -6046,7 +6056,7 @@ class Utils {
6046
6056
  return parent.querySelector(selector);
6047
6057
  }
6048
6058
  }
6049
- var observer = that.mutationObserver(parent, {
6059
+ var observer = UtilsContext.mutationObserver(parent, {
6050
6060
  config: {
6051
6061
  subtree: true,
6052
6062
  childList: true,
@@ -6079,11 +6089,11 @@ class Utils {
6079
6089
  waitAnyNode(...args) {
6080
6090
  // 过滤掉undefined
6081
6091
  args = args.filter((arg) => arg !== void 0);
6082
- let that = this;
6092
+ let UtilsContext = this;
6083
6093
  // 选择器
6084
6094
  let selectorList = args[0];
6085
6095
  // 父元素(监听的元素)
6086
- let parent = UtilsCore.document;
6096
+ let parent = UtilsContext.windowApi.document;
6087
6097
  // 超时时间
6088
6098
  let timeout = 0;
6089
6099
  if (typeof args[0] !== "object" && !Array.isArray(args[0])) {
@@ -6128,18 +6138,18 @@ class Utils {
6128
6138
  throw new TypeError("Utils.waitAnyNode 参数个数错误");
6129
6139
  }
6130
6140
  let promiseList = selectorList.map((selector) => {
6131
- return that.waitNode(selector, parent, timeout);
6141
+ return UtilsContext.waitNode(selector, parent, timeout);
6132
6142
  });
6133
6143
  return Promise.any(promiseList);
6134
6144
  }
6135
6145
  waitNodeList(...args) {
6136
6146
  // 过滤掉undefined
6137
6147
  args = args.filter((arg) => arg !== void 0);
6138
- let that = this;
6148
+ let UtilsContext = this;
6139
6149
  // 选择器数组
6140
6150
  let selector = args[0];
6141
6151
  // 父元素(监听的元素)
6142
- let parent = UtilsCore.document;
6152
+ let parent = UtilsContext.windowApi.document;
6143
6153
  // 超时时间
6144
6154
  let timeout = 0;
6145
6155
  if (typeof args[0] !== "string" && !Array.isArray(args[0])) {
@@ -6204,7 +6214,7 @@ class Utils {
6204
6214
  }
6205
6215
  }
6206
6216
  }
6207
- var observer = that.mutationObserver(parent, {
6217
+ var observer = UtilsContext.mutationObserver(parent, {
6208
6218
  config: {
6209
6219
  subtree: true,
6210
6220
  childList: true,
@@ -6238,11 +6248,11 @@ class Utils {
6238
6248
  waitAnyNodeList(...args) {
6239
6249
  // 过滤掉undefined
6240
6250
  args = args.filter((arg) => arg !== void 0);
6241
- let that = this;
6251
+ let UtilsContext = this;
6242
6252
  // 选择器数组
6243
6253
  let selectorList = args[0];
6244
6254
  // 父元素(监听的元素)
6245
- let parent = UtilsCore.document;
6255
+ let parent = UtilsContext.windowApi.document;
6246
6256
  // 超时时间
6247
6257
  let timeout = 0;
6248
6258
  if (!Array.isArray(args[0])) {
@@ -6287,7 +6297,7 @@ class Utils {
6287
6297
  throw new TypeError("Utils.waitAnyNodeList 参数个数错误");
6288
6298
  }
6289
6299
  let promiseList = selectorList.map((selector) => {
6290
- return that.waitNodeList(selector, parent, timeout);
6300
+ return UtilsContext.waitNodeList(selector, parent, timeout);
6291
6301
  });
6292
6302
  return Promise.any(promiseList);
6293
6303
  }
@@ -6490,12 +6500,12 @@ class Utils {
6490
6500
  if (text.startsWith("//")) {
6491
6501
  /* //www.baidu.com/xxxxxxx */
6492
6502
  /* 没有protocol,加上 */
6493
- text = UtilsCore.globalThis.location.protocol + text;
6503
+ text = this.windowApi.globalThis.location.protocol + text;
6494
6504
  }
6495
6505
  else if (text.startsWith("/")) {
6496
6506
  /* /xxx/info?xxx=xxx */
6497
6507
  /* 没有Origin,加上 */
6498
- text = UtilsCore.globalThis.location.origin + text;
6508
+ text = this.windowApi.globalThis.location.origin + text;
6499
6509
  }
6500
6510
  return new URL(text);
6501
6511
  }