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