@whitesev/utils 2.3.8 → 2.4.1

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.
Files changed (56) hide show
  1. package/dist/index.amd.js +379 -268
  2. package/dist/index.amd.js.map +1 -1
  3. package/dist/index.cjs.js +379 -268
  4. package/dist/index.cjs.js.map +1 -1
  5. package/dist/index.esm.js +379 -268
  6. package/dist/index.esm.js.map +1 -1
  7. package/dist/index.iife.js +379 -268
  8. package/dist/index.iife.js.map +1 -1
  9. package/dist/index.system.js +379 -268
  10. package/dist/index.system.js.map +1 -1
  11. package/dist/index.umd.js +379 -268
  12. package/dist/index.umd.js.map +1 -1
  13. package/dist/types/src/Httpx.d.ts +25 -1178
  14. package/dist/types/src/Log.d.ts +1 -19
  15. package/dist/types/src/Progress.d.ts +1 -20
  16. package/dist/types/src/TryCatch.d.ts +2 -11
  17. package/dist/types/src/Utils.d.ts +8 -32
  18. package/dist/types/src/UtilsGMCookie.d.ts +1 -51
  19. package/dist/types/src/UtilsGMMenu.d.ts +1 -50
  20. package/dist/types/src/WindowApi.d.ts +3 -11
  21. package/dist/types/src/types/Httpx.d.ts +1316 -0
  22. package/dist/types/src/types/Log.d.ts +19 -0
  23. package/dist/types/src/types/Progress.d.ts +20 -0
  24. package/dist/types/src/types/TryCatch.d.ts +9 -0
  25. package/dist/types/src/types/UtilsGMCookie.d.ts +55 -0
  26. package/dist/types/src/types/UtilsGMMenu.d.ts +77 -0
  27. package/{src/VueObject.ts → dist/types/src/types/Vue2.d.ts} +28 -15
  28. package/dist/types/src/types/Vue3.d.ts +0 -0
  29. package/dist/types/src/types/WindowApi.d.ts +10 -0
  30. package/dist/types/src/types/global.d.ts +24 -1
  31. package/package.json +1 -1
  32. package/src/GBKEncoder.ts +1 -1
  33. package/src/Httpx.ts +533 -1627
  34. package/src/Log.ts +1 -19
  35. package/src/Progress.ts +1 -20
  36. package/src/TryCatch.ts +2 -12
  37. package/src/Utils.ts +15 -38
  38. package/src/UtilsGMCookie.ts +7 -56
  39. package/src/UtilsGMMenu.ts +5 -78
  40. package/src/WindowApi.ts +4 -11
  41. package/src/types/Event.d.ts +189 -0
  42. package/src/types/Httpx.d.ts +1316 -0
  43. package/src/types/Log.d.ts +19 -0
  44. package/src/types/Progress.d.ts +20 -0
  45. package/src/types/TryCatch.d.ts +9 -0
  46. package/src/types/UtilsGMCookie.d.ts +55 -0
  47. package/src/types/UtilsGMMenu.d.ts +77 -0
  48. package/src/types/Vue2.d.ts +154 -0
  49. package/src/types/Vue3.d.ts +0 -0
  50. package/src/types/WindowApi.d.ts +10 -0
  51. package/{dist/types/src/AjaxHookerType.d.ts → src/types/ajaxHooker.d.ts} +155 -147
  52. package/src/types/global.d.ts +24 -1
  53. package/dist/types/src/Event.d.ts +0 -156
  54. package/dist/types/src/VueObject.d.ts +0 -123
  55. /package/{src/Event.ts → dist/types/src/types/Event.d.ts} +0 -0
  56. /package/{src/AjaxHookerType.ts → dist/types/src/types/ajaxHooker.d.ts} +0 -0
@@ -1718,55 +1718,57 @@ var Utils = (function () {
1718
1718
  /**
1719
1719
  * 根据传入的参数处理获取details配置
1720
1720
  */
1721
- handleBeforeRequestDetails(...args) {
1722
- let result = {};
1721
+ handleBeforeRequestOption(...args) {
1722
+ let option = {};
1723
1723
  if (typeof args[0] === "string") {
1724
1724
  /* 传入的是url,details? */
1725
1725
  let url = args[0];
1726
- result.url = url;
1726
+ option.url = url;
1727
1727
  if (typeof args[1] === "object") {
1728
1728
  /* 处理第二个参数details */
1729
1729
  let details = args[1];
1730
- result = details;
1731
- result.url = url;
1730
+ option = details;
1731
+ option.url = url;
1732
1732
  }
1733
1733
  }
1734
1734
  else {
1735
1735
  /* 传入的是details */
1736
- result = args[0];
1736
+ option = args[0];
1737
1737
  }
1738
- return result;
1738
+ return option;
1739
1739
  },
1740
1740
  /**
1741
1741
  * 获取请求配置
1742
1742
  * @param method 当前请求方法,默认get
1743
- * @param details 请求配置
1743
+ * @param userRequestOption 用户的请求配置
1744
1744
  * @param resolve promise回调
1745
1745
  * @param reject 抛出错误回调
1746
1746
  */
1747
- getDetails(method, details, resolve, reject) {
1747
+ getRequestOption(method, userRequestOption, resolve, reject) {
1748
1748
  let that = this;
1749
- let result = {
1750
- url: details.url || this.context.#defaultDetails.url,
1749
+ let requestOption = {
1750
+ url: userRequestOption.url || this.context.#defaultDetails.url,
1751
1751
  method: (method || "GET").toString().toUpperCase(),
1752
- timeout: details.timeout || this.context.#defaultDetails.timeout,
1753
- responseType: details.responseType || this.context.#defaultDetails.responseType,
1752
+ timeout: userRequestOption.timeout || this.context.#defaultDetails.timeout,
1753
+ responseType: userRequestOption.responseType ||
1754
+ this.context.#defaultDetails.responseType,
1754
1755
  /* 对象使用深拷贝 */
1755
1756
  headers: utils.deepClone(this.context.#defaultDetails.headers),
1756
- data: details.data || this.context.#defaultDetails.data,
1757
- redirect: details.redirect || this.context.#defaultDetails.redirect,
1758
- cookie: details.cookie || this.context.#defaultDetails.cookie,
1759
- cookiePartition: details.cookiePartition ||
1757
+ data: userRequestOption.data || this.context.#defaultDetails.data,
1758
+ redirect: userRequestOption.redirect || this.context.#defaultDetails.redirect,
1759
+ cookie: userRequestOption.cookie || this.context.#defaultDetails.cookie,
1760
+ cookiePartition: userRequestOption.cookiePartition ||
1760
1761
  this.context.#defaultDetails.cookiePartition,
1761
- binary: details.binary || this.context.#defaultDetails.binary,
1762
- nocache: details.nocache || this.context.#defaultDetails.nocache,
1763
- revalidate: details.revalidate || this.context.#defaultDetails.revalidate,
1762
+ binary: userRequestOption.binary || this.context.#defaultDetails.binary,
1763
+ nocache: userRequestOption.nocache || this.context.#defaultDetails.nocache,
1764
+ revalidate: userRequestOption.revalidate ||
1765
+ this.context.#defaultDetails.revalidate,
1764
1766
  /* 对象使用深拷贝 */
1765
- context: utils.deepClone(details.context || this.context.#defaultDetails.context),
1766
- overrideMimeType: details.overrideMimeType ||
1767
+ context: utils.deepClone(userRequestOption.context || this.context.#defaultDetails.context),
1768
+ overrideMimeType: userRequestOption.overrideMimeType ||
1767
1769
  this.context.#defaultDetails.overrideMimeType,
1768
- anonymous: details.anonymous || this.context.#defaultDetails.anonymous,
1769
- fetch: details.fetch || this.context.#defaultDetails.fetch,
1770
+ anonymous: userRequestOption.anonymous || this.context.#defaultDetails.anonymous,
1771
+ fetch: userRequestOption.fetch || this.context.#defaultDetails.fetch,
1770
1772
  /* 对象使用深拷贝 */
1771
1773
  fetchInit: utils.deepClone(this.context.#defaultDetails.fetchInit),
1772
1774
  allowInterceptConfig: {
@@ -1777,153 +1779,243 @@ var Utils = (function () {
1777
1779
  afterResponseError: this.context.#defaultDetails
1778
1780
  .allowInterceptConfig.afterResponseError,
1779
1781
  },
1780
- user: details.user || this.context.#defaultDetails.user,
1781
- password: details.password || this.context.#defaultDetails.password,
1782
+ user: userRequestOption.user || this.context.#defaultDetails.user,
1783
+ password: userRequestOption.password || this.context.#defaultDetails.password,
1782
1784
  onabort(...args) {
1783
- that.context.HttpxCallBack.onAbort(details, resolve, reject, args);
1785
+ that.context.HttpxCallBack.onAbort(userRequestOption, resolve, reject, args);
1784
1786
  },
1785
1787
  onerror(...args) {
1786
- that.context.HttpxCallBack.onError(details, resolve, reject, args);
1788
+ that.context.HttpxCallBack.onError(userRequestOption, resolve, reject, args);
1787
1789
  },
1788
1790
  onloadstart(...args) {
1789
- that.context.HttpxCallBack.onLoadStart(details, args);
1791
+ that.context.HttpxCallBack.onLoadStart(userRequestOption, args);
1790
1792
  },
1791
1793
  onprogress(...args) {
1792
- that.context.HttpxCallBack.onProgress(details, args);
1794
+ that.context.HttpxCallBack.onProgress(userRequestOption, args);
1793
1795
  },
1794
1796
  onreadystatechange(...args) {
1795
- that.context.HttpxCallBack.onReadyStateChange(details, args);
1797
+ that.context.HttpxCallBack.onReadyStateChange(userRequestOption, args);
1796
1798
  },
1797
1799
  ontimeout(...args) {
1798
- that.context.HttpxCallBack.onTimeout(details, resolve, reject, args);
1800
+ that.context.HttpxCallBack.onTimeout(userRequestOption, resolve, reject, args);
1799
1801
  },
1800
1802
  onload(...args) {
1801
- that.context.HttpxCallBack.onLoad(details, resolve, reject, args);
1803
+ that.context.HttpxCallBack.onLoad(userRequestOption, resolve, reject, args);
1802
1804
  },
1803
1805
  };
1804
1806
  // 补全allowInterceptConfig参数
1805
- if (typeof details.allowInterceptConfig === "boolean") {
1806
- Object.keys(result.allowInterceptConfig).forEach((keyName) => {
1807
- result.allowInterceptConfig[keyName] =
1808
- details.allowInterceptConfig;
1807
+ if (typeof userRequestOption.allowInterceptConfig === "boolean") {
1808
+ Object.keys(requestOption.allowInterceptConfig).forEach((keyName) => {
1809
+ Reflect.set(requestOption.allowInterceptConfig, keyName, userRequestOption.allowInterceptConfig);
1809
1810
  });
1810
1811
  }
1811
1812
  else {
1812
- if (typeof details.allowInterceptConfig === "object" &&
1813
- details.allowInterceptConfig != null) {
1814
- Object.keys(details.allowInterceptConfig).forEach((keyName) => {
1815
- let value = details.allowInterceptConfig[keyName];
1816
- if (keyName in
1817
- result.allowInterceptConfig &&
1818
- typeof value === "boolean") {
1819
- result.allowInterceptConfig[keyName] = value;
1813
+ if (typeof userRequestOption.allowInterceptConfig === "object" &&
1814
+ userRequestOption.allowInterceptConfig != null) {
1815
+ Object.keys(userRequestOption.allowInterceptConfig).forEach((keyName) => {
1816
+ let value = Reflect.get(userRequestOption.allowInterceptConfig, keyName);
1817
+ if (typeof value === "boolean" &&
1818
+ Reflect.has(requestOption.allowInterceptConfig, keyName)) {
1819
+ Reflect.set(requestOption.allowInterceptConfig, keyName, value);
1820
1820
  }
1821
1821
  });
1822
1822
  }
1823
1823
  }
1824
1824
  if (typeof this.context.GM_Api.xmlHttpRequest !== "function") {
1825
- result.fetch = true;
1826
- }
1827
- if (typeof result.headers === "object") {
1828
- if (typeof details.headers === "object") {
1829
- Object.keys(details.headers).forEach((keyName, index) => {
1830
- if (keyName in result.headers &&
1831
- details.headers?.[keyName] == null) {
1825
+ // GM函数不存在,强制使用fetch
1826
+ requestOption.fetch = true;
1827
+ }
1828
+ if (typeof requestOption.headers === "object") {
1829
+ if (typeof userRequestOption.headers === "object") {
1830
+ Object.keys(userRequestOption.headers).forEach((keyName, index) => {
1831
+ if (keyName in requestOption.headers &&
1832
+ userRequestOption.headers?.[keyName] == null) {
1832
1833
  /* 在默认的header中存在,且设置它新的值为空,那么就是默认的值 */
1833
- Reflect.deleteProperty(result.headers, keyName);
1834
+ Reflect.deleteProperty(requestOption.headers, keyName);
1834
1835
  }
1835
1836
  else {
1836
- result.headers[keyName] = details?.headers?.[keyName];
1837
+ requestOption.headers[keyName] =
1838
+ userRequestOption?.headers?.[keyName];
1837
1839
  }
1838
1840
  });
1839
1841
  }
1840
1842
  }
1841
1843
  else {
1842
- result.headers = details.headers;
1844
+ /* 默认的headers不是对象,那么就直接使用新的 */
1845
+ Reflect.set(requestOption, "headers", userRequestOption.headers);
1843
1846
  }
1844
- if (typeof result.fetchInit === "object") {
1847
+ if (typeof requestOption.fetchInit === "object") {
1845
1848
  /* 使用assign替换且添加 */
1846
- if (typeof details.fetchInit === "object") {
1847
- Object.keys(details.fetchInit).forEach((keyName, index) => {
1848
- if (keyName in result.fetchInit &&
1849
- details.fetchInit[keyName] == null) {
1849
+ if (typeof userRequestOption.fetchInit === "object") {
1850
+ Object.keys(userRequestOption.fetchInit).forEach((keyName, index) => {
1851
+ if (keyName in requestOption.fetchInit &&
1852
+ userRequestOption.fetchInit[keyName] == null) {
1850
1853
  /* 在默认的fetchInit中存在,且设置它新的值为空,那么就是默认的值 */
1851
- Reflect.deleteProperty(result.fetchInit, keyName);
1854
+ Reflect.deleteProperty(requestOption.fetchInit, keyName);
1852
1855
  }
1853
1856
  else {
1854
- result.fetchInit[keyName] = details.fetchInit[keyName];
1857
+ Reflect.set(requestOption.fetchInit, keyName, Reflect.get(userRequestOption.fetchInit, keyName));
1855
1858
  }
1856
1859
  });
1857
1860
  }
1858
1861
  }
1859
1862
  else {
1860
- result.fetchInit = details.fetchInit;
1863
+ Reflect.set(requestOption, "fetchInit", userRequestOption.fetchInit);
1861
1864
  }
1862
1865
  // 处理新的cookiePartition
1863
- if (typeof result.cookiePartition === "object" &&
1864
- result.cookiePartition != null) {
1865
- if (Reflect.has(result.cookiePartition, "topLevelSite") &&
1866
- typeof result.cookiePartition.topLevelSite !== "string") {
1866
+ if (typeof requestOption.cookiePartition === "object" &&
1867
+ requestOption.cookiePartition != null) {
1868
+ if (Reflect.has(requestOption.cookiePartition, "topLevelSite") &&
1869
+ typeof requestOption.cookiePartition.topLevelSite !== "string") {
1867
1870
  // topLevelSite必须是字符串
1868
- Reflect.deleteProperty(result.cookiePartition, "topLevelSite");
1869
- }
1870
- }
1871
- return result;
1872
- },
1873
- /**
1874
- * 处理发送请求的details,去除值为undefined、空function的值
1875
- * @param details
1876
- */
1877
- handle(details) {
1878
- Object.keys(details).forEach((keyName) => {
1879
- if (details[keyName] == null ||
1880
- (details[keyName] instanceof Function &&
1881
- utils.isNull(details[keyName]))) {
1882
- Reflect.deleteProperty(details, keyName);
1883
- return;
1871
+ Reflect.deleteProperty(requestOption.cookiePartition, "topLevelSite");
1884
1872
  }
1885
- });
1886
- if (utils.isNull(details.url)) {
1887
- throw new TypeError(`Utils.Httpx 参数 url不符合要求: ${details.url}`);
1888
1873
  }
1889
- /* method值统一大写,兼容Via */
1890
- details.method = details.method.toUpperCase();
1891
- /* 判断是否是以http开头,否则主动加上origin */
1874
+ /* 完善请求的url */
1892
1875
  try {
1893
- new URL(details.url);
1876
+ new URL(requestOption.url);
1894
1877
  }
1895
1878
  catch (error) {
1896
- if (details.url.startsWith("//")) {
1897
- details.url = window.location.protocol + details.url;
1879
+ if (requestOption.url.startsWith("//")) {
1880
+ // 补充https:
1881
+ requestOption.url = globalThis.location.protocol + requestOption.url;
1898
1882
  }
1899
- else if (details.url.startsWith("/")) {
1900
- details.url = window.location.origin + details.url;
1883
+ else if (requestOption.url.startsWith("/")) {
1884
+ // 补充origin
1885
+ requestOption.url = globalThis.location.origin + requestOption.url;
1901
1886
  }
1902
1887
  else {
1903
- details.url = window.location.origin + "/" + details.url;
1888
+ // 补充origin+/
1889
+ requestOption.url =
1890
+ globalThis.location.origin + "/" + requestOption.url;
1904
1891
  }
1905
1892
  }
1906
- return details;
1893
+ if (requestOption.fetchInit && !requestOption.fetch) {
1894
+ // 清空fetchInit
1895
+ Reflect.deleteProperty(requestOption, "fetchInit");
1896
+ }
1897
+ // 转换data类型
1898
+ try {
1899
+ /** 是否对数据进行处理 */
1900
+ let processData = userRequestOption.processData ?? true;
1901
+ if (requestOption.data != null && processData) {
1902
+ let method = requestOption.method;
1903
+ if (method === "GET" || method === "HEAD") {
1904
+ // GET类型,data如果有,那么需要转为searchParams
1905
+ let urlObj = new URL(requestOption.url);
1906
+ let urlSearch = "";
1907
+ if (typeof requestOption.data === "string") {
1908
+ urlSearch = requestOption.data;
1909
+ }
1910
+ else if (typeof requestOption.data === "object") {
1911
+ // URLSearchParams参数可以转普通的string:string,包括FormData
1912
+ // @ts-ignore
1913
+ let searchParams = new URLSearchParams(requestOption.data);
1914
+ urlSearch = searchParams.toString();
1915
+ }
1916
+ if (urlSearch != "") {
1917
+ if (urlObj.search === "") {
1918
+ // url没有search参数,直接覆盖
1919
+ urlObj.search = urlSearch;
1920
+ }
1921
+ else {
1922
+ // 有search参数
1923
+ if (urlObj.search.endsWith("&")) {
1924
+ // xxx=xxx&
1925
+ urlObj.search = urlObj.search + urlSearch;
1926
+ }
1927
+ else {
1928
+ // xxx=xxx&xxx=
1929
+ urlObj.search = urlObj.search + "&" + urlSearch;
1930
+ }
1931
+ }
1932
+ }
1933
+ requestOption.url = urlObj.toString();
1934
+ }
1935
+ else if (method === "POST" && requestOption.headers != null) {
1936
+ // POST类型,data如果是FormData,那么需要转为string
1937
+ let headersKeyList = Object.keys(requestOption.headers);
1938
+ let ContentTypeIndex = headersKeyList.findIndex((headerKey) => {
1939
+ return (headerKey.trim().toLowerCase() === "content-type" &&
1940
+ typeof requestOption.headers[headerKey] === "string");
1941
+ });
1942
+ if (ContentTypeIndex !== -1) {
1943
+ let ContentTypeKey = headersKeyList[ContentTypeIndex];
1944
+ let ContentType = requestOption.headers[ContentTypeKey];
1945
+ // 设置了Content-Type
1946
+ if (ContentType.includes("application/json")) {
1947
+ // application/json
1948
+ if (requestOption.data instanceof FormData) {
1949
+ const entries = {};
1950
+ requestOption.data.forEach((value, key) => {
1951
+ entries[key] = value;
1952
+ });
1953
+ requestOption.data = JSON.stringify(entries);
1954
+ }
1955
+ else if (typeof requestOption.data === "object") {
1956
+ requestOption.data = JSON.stringify(requestOption.data);
1957
+ }
1958
+ }
1959
+ else if (ContentType.includes("application/x-www-form-urlencoded")) {
1960
+ // application/x-www-form-urlencoded
1961
+ if (typeof requestOption.data === "object") {
1962
+ requestOption.data = new URLSearchParams(
1963
+ // @ts-ignore
1964
+ requestOption.data).toString();
1965
+ }
1966
+ }
1967
+ else if (ContentType.includes("multipart/form-data")) {
1968
+ // multipart/form-data
1969
+ if (requestOption.data instanceof FormData) {
1970
+ Reflect.deleteProperty(requestOption.headers, ContentTypeKey);
1971
+ }
1972
+ }
1973
+ }
1974
+ }
1975
+ }
1976
+ }
1977
+ catch (error) {
1978
+ console.warn("Httpx ==> 转换data参数错误", error);
1979
+ }
1980
+ return requestOption;
1981
+ },
1982
+ /**
1983
+ * 处理发送请求的配置,去除值为undefined、空function的值
1984
+ * @param option
1985
+ */
1986
+ removeRequestNullOption(option) {
1987
+ Object.keys(option).forEach((keyName) => {
1988
+ if (option[keyName] == null ||
1989
+ (option[keyName] instanceof Function &&
1990
+ utils.isNull(option[keyName]))) {
1991
+ Reflect.deleteProperty(option, keyName);
1992
+ return;
1993
+ }
1994
+ });
1995
+ if (utils.isNull(option.url)) {
1996
+ throw new TypeError(`Utils.Httpx 参数 url不符合要求: ${option.url}`);
1997
+ }
1998
+ return option;
1907
1999
  },
1908
2000
  /**
1909
2001
  * 处理fetch的配置
1910
- * @param details
2002
+ * @param option
1911
2003
  */
1912
- handleFetchDetail(details) {
2004
+ handleFetchOption(option) {
1913
2005
  /**
1914
2006
  * fetch的请求配置
1915
2007
  **/
1916
- let fetchRequestInit = {};
1917
- if ((details.method === "GET" || details.method === "HEAD") &&
1918
- details.data != null) {
2008
+ let fetchRequestOption = {};
2009
+ if ((option.method === "GET" || option.method === "HEAD") &&
2010
+ option.data != null) {
1919
2011
  /* GET 或 HEAD 方法的请求不能包含 body 信息 */
1920
- Reflect.deleteProperty(details, "data");
2012
+ Reflect.deleteProperty(option, "data");
1921
2013
  }
1922
2014
  /* 中止信号控制器 */
1923
2015
  let abortController = new AbortController();
1924
2016
  let signal = abortController.signal;
1925
2017
  signal.onabort = () => {
1926
- details.onabort({
2018
+ option.onabort({
1927
2019
  isFetch: true,
1928
2020
  responseText: "",
1929
2021
  response: null,
@@ -1934,19 +2026,28 @@ var Utils = (function () {
1934
2026
  error: "aborted",
1935
2027
  });
1936
2028
  };
1937
- fetchRequestInit.method = details.method ?? "GET";
1938
- fetchRequestInit.headers = details.headers;
1939
- fetchRequestInit.body = details.data;
1940
- fetchRequestInit.mode = "cors";
1941
- fetchRequestInit.credentials = "include";
1942
- fetchRequestInit.cache = "no-cache";
1943
- fetchRequestInit.redirect = "follow";
1944
- fetchRequestInit.referrerPolicy = "origin-when-cross-origin";
1945
- fetchRequestInit.signal = signal;
1946
- Object.assign(fetchRequestInit, details.fetchInit || {});
2029
+ // 设置请求
2030
+ fetchRequestOption.method = option.method ?? "GET";
2031
+ // 设置请求头
2032
+ fetchRequestOption.headers = option.headers;
2033
+ // 设置请求体
2034
+ fetchRequestOption.body = option.data;
2035
+ // 设置跨域
2036
+ fetchRequestOption.mode = "cors";
2037
+ // 设置包含
2038
+ fetchRequestOption.credentials = "include";
2039
+ // 设置不缓存
2040
+ fetchRequestOption.cache = "no-cache";
2041
+ // 设置始终重定向
2042
+ fetchRequestOption.redirect = "follow";
2043
+ // 设置referer跨域
2044
+ fetchRequestOption.referrerPolicy = "origin-when-cross-origin";
2045
+ // 设置信号中断
2046
+ fetchRequestOption.signal = signal;
2047
+ Object.assign(fetchRequestOption, option.fetchInit || {});
1947
2048
  return {
1948
- fetchDetails: details,
1949
- fetchRequestInit: fetchRequestInit,
2049
+ fetchOption: option,
2050
+ fetchRequestOption: fetchRequestOption,
1950
2051
  abortController: abortController,
1951
2052
  };
1952
2053
  },
@@ -1958,14 +2059,19 @@ var Utils = (function () {
1958
2059
  * @param details 配置
1959
2060
  * @param resolve 回调
1960
2061
  * @param reject 抛出错误
1961
- * @param argumentsList 参数列表
2062
+ * @param argsResult 返回的参数列表
1962
2063
  */
1963
- onAbort(details, resolve, reject, argumentsList) {
2064
+ onAbort(details, resolve, reject, argsResult) {
2065
+ // console.log(argsResult);
1964
2066
  if ("onabort" in details) {
1965
- details.onabort.apply(this, argumentsList);
2067
+ details.onabort.apply(this, argsResult);
1966
2068
  }
1967
2069
  else if ("onabort" in this.context.#defaultDetails) {
1968
- this.context.#defaultDetails.onabort.apply(this, argumentsList);
2070
+ this.context.#defaultDetails.onabort.apply(this, argsResult);
2071
+ }
2072
+ let response = argsResult;
2073
+ if (response.length) {
2074
+ response = response[0];
1969
2075
  }
1970
2076
  if (this.context.HttpxResponseHook.errorResponseCallBack({
1971
2077
  type: "onabort",
@@ -1977,9 +2083,11 @@ var Utils = (function () {
1977
2083
  return;
1978
2084
  }
1979
2085
  resolve({
1980
- status: false,
1981
- data: [...argumentsList],
2086
+ data: response,
2087
+ details: details,
1982
2088
  msg: "请求被取消",
2089
+ status: false,
2090
+ statusCode: -1,
1983
2091
  type: "onabort",
1984
2092
  });
1985
2093
  },
@@ -1988,16 +2096,17 @@ var Utils = (function () {
1988
2096
  * @param details 配置
1989
2097
  * @param resolve 回调
1990
2098
  * @param reject 抛出错误
1991
- * @param argumentsList 响应的参数列表
2099
+ * @param argsResult 返回的参数列表
1992
2100
  */
1993
- onError(details, resolve, reject, argumentsList) {
2101
+ onError(details, resolve, reject, argsResult) {
2102
+ // console.log(argsResult);
1994
2103
  if ("onerror" in details) {
1995
- details.onerror.apply(this, argumentsList);
2104
+ details.onerror.apply(this, argsResult);
1996
2105
  }
1997
2106
  else if ("onerror" in this.context.#defaultDetails) {
1998
- this.context.#defaultDetails.onerror.apply(this, argumentsList);
2107
+ this.context.#defaultDetails.onerror.apply(this, argsResult);
1999
2108
  }
2000
- let response = argumentsList;
2109
+ let response = argsResult;
2001
2110
  if (response.length) {
2002
2111
  response = response[0];
2003
2112
  }
@@ -2011,10 +2120,11 @@ var Utils = (function () {
2011
2120
  return;
2012
2121
  }
2013
2122
  resolve({
2014
- status: false,
2015
2123
  data: response,
2016
2124
  details: details,
2017
2125
  msg: "请求异常",
2126
+ status: false,
2127
+ statusCode: response["status"],
2018
2128
  type: "onerror",
2019
2129
  });
2020
2130
  },
@@ -2023,42 +2133,50 @@ var Utils = (function () {
2023
2133
  * @param details 配置
2024
2134
  * @param resolve 回调
2025
2135
  * @param reject 抛出错误
2026
- * @param argumentsList 参数列表
2136
+ * @param argsResult 返回的参数列表
2027
2137
  */
2028
- onTimeout(details, resolve, reject, argumentsList) {
2138
+ onTimeout(details, resolve, reject, argsResult) {
2139
+ // console.log(argsResult);
2029
2140
  if ("ontimeout" in details) {
2030
- details.ontimeout.apply(this, argumentsList);
2141
+ details.ontimeout.apply(this, argsResult);
2031
2142
  }
2032
2143
  else if ("ontimeout" in this.context.#defaultDetails) {
2033
- this.context.#defaultDetails.ontimeout.apply(this, argumentsList);
2144
+ this.context.#defaultDetails.ontimeout.apply(this, argsResult);
2145
+ }
2146
+ let response = argsResult;
2147
+ if (response.length) {
2148
+ response = response[0];
2034
2149
  }
2035
2150
  if (this.context.HttpxResponseHook.errorResponseCallBack({
2036
2151
  type: "ontimeout",
2037
2152
  error: new TypeError("request timeout"),
2038
- response: (argumentsList || [null])[0],
2153
+ response: (argsResult || [null])[0],
2039
2154
  details: details,
2040
2155
  }) == null) {
2041
2156
  // reject(new TypeError("response is intercept with ontimeout"));
2042
2157
  return;
2043
2158
  }
2044
2159
  resolve({
2045
- status: false,
2046
- data: [...argumentsList],
2160
+ data: response,
2161
+ details: details,
2047
2162
  msg: "请求超时",
2163
+ status: false,
2164
+ statusCode: 0,
2048
2165
  type: "ontimeout",
2049
2166
  });
2050
2167
  },
2051
2168
  /**
2052
2169
  * onloadstart请求开始-触发
2053
2170
  * @param details 配置
2054
- * @param argumentsList 参数列表
2171
+ * @param argsResult 返回的参数列表
2055
2172
  */
2056
- onLoadStart(details, argumentsList) {
2173
+ onLoadStart(details, argsResult) {
2174
+ // console.log(argsResult);
2057
2175
  if ("onloadstart" in details) {
2058
- details.onloadstart.apply(this, argumentsList);
2176
+ details.onloadstart.apply(this, argsResult);
2059
2177
  }
2060
2178
  else if ("onloadstart" in this.context.#defaultDetails) {
2061
- this.context.#defaultDetails.onloadstart.apply(this, argumentsList);
2179
+ this.context.#defaultDetails.onloadstart.apply(this, argsResult);
2062
2180
  }
2063
2181
  },
2064
2182
  /**
@@ -2066,11 +2184,12 @@ var Utils = (function () {
2066
2184
  * @param details 请求的配置
2067
2185
  * @param resolve 回调
2068
2186
  * @param reject 抛出错误
2069
- * @param argumentsList 参数列表
2187
+ * @param argsResult 返回的参数列表
2070
2188
  */
2071
- onLoad(details, resolve, reject, argumentsList) {
2189
+ onLoad(details, resolve, reject, argsResult) {
2190
+ // console.log(argsResult);
2072
2191
  /* X浏览器会因为设置了responseType导致不返回responseText */
2073
- let originResponse = argumentsList[0];
2192
+ let originResponse = argsResult[0];
2074
2193
  /* responseText为空,response不为空的情况 */
2075
2194
  if (utils.isNull(originResponse["responseText"]) &&
2076
2195
  utils.isNotNull(originResponse["response"])) {
@@ -2143,41 +2262,44 @@ var Utils = (function () {
2143
2262
  return;
2144
2263
  }
2145
2264
  resolve({
2146
- status: true,
2147
2265
  data: originResponse,
2148
2266
  details: details,
2149
- msg: "请求完毕",
2267
+ msg: "请求成功",
2268
+ status: true,
2269
+ statusCode: originResponse.status,
2150
2270
  type: "onload",
2151
2271
  });
2152
2272
  }
2153
2273
  else {
2154
- this.context.HttpxCallBack.onError(details, resolve, reject, argumentsList);
2274
+ this.context.HttpxCallBack.onError(details, resolve, reject, argsResult);
2155
2275
  }
2156
2276
  },
2157
2277
  /**
2158
2278
  * onprogress上传进度-触发
2159
2279
  * @param details 配置
2160
- * @param argumentsList 参数列表
2280
+ * @param argsResult 返回的参数列表
2161
2281
  */
2162
- onProgress(details, argumentsList) {
2282
+ onProgress(details, argsResult) {
2283
+ // console.log(argsResult);
2163
2284
  if ("onprogress" in details) {
2164
- details.onprogress.apply(this, argumentsList);
2285
+ details.onprogress.apply(this, argsResult);
2165
2286
  }
2166
2287
  else if ("onprogress" in this.context.#defaultDetails) {
2167
- this.context.#defaultDetails.onprogress.apply(this, argumentsList);
2288
+ this.context.#defaultDetails.onprogress.apply(this, argsResult);
2168
2289
  }
2169
2290
  },
2170
2291
  /**
2171
2292
  * onreadystatechange准备状态改变-触发
2172
2293
  * @param details 配置
2173
- * @param argumentsList 参数列表
2294
+ * @param argsResult 返回的参数列表
2174
2295
  */
2175
- onReadyStateChange(details, argumentsList) {
2296
+ onReadyStateChange(details, argsResult) {
2297
+ // console.log(argsResult);
2176
2298
  if ("onreadystatechange" in details) {
2177
- details.onreadystatechange.apply(this, argumentsList);
2299
+ details.onreadystatechange.apply(this, argsResult);
2178
2300
  }
2179
2301
  else if ("onreadystatechange" in this.context.#defaultDetails) {
2180
- this.context.#defaultDetails.onreadystatechange.apply(this, argumentsList);
2302
+ this.context.#defaultDetails.onreadystatechange.apply(this, argsResult);
2181
2303
  }
2182
2304
  },
2183
2305
  };
@@ -2199,11 +2321,12 @@ var Utils = (function () {
2199
2321
  }
2200
2322
  }
2201
2323
  if (details.fetch) {
2202
- const { fetchDetails, fetchRequestInit, abortController } = this.context.HttpxRequestDetails.handleFetchDetail(details);
2203
- return this.fetch(fetchDetails, fetchRequestInit, abortController);
2324
+ // 使用fetch请求
2325
+ const { fetchOption: fetchOption, fetchRequestOption: fetchRequestOption, abortController, } = this.context.HttpxRequestDetails.handleFetchOption(details);
2326
+ return this.fetch(fetchOption, fetchRequestOption, abortController);
2204
2327
  }
2205
2328
  else {
2206
- Reflect.deleteProperty(details, "fetchInit");
2329
+ // 使用GM_xmlHttpRequest请求
2207
2330
  return this.xmlHttpRequest(details);
2208
2331
  }
2209
2332
  },
@@ -2216,12 +2339,12 @@ var Utils = (function () {
2216
2339
  },
2217
2340
  /**
2218
2341
  * 使用fetch发送请求
2219
- * @param details
2220
- * @param fetchRequestInit
2342
+ * @param option
2343
+ * @param fetchRequestOption
2221
2344
  * @param abortController
2222
2345
  */
2223
- fetch(details, fetchRequestInit, abortController) {
2224
- fetch(details.url, fetchRequestInit)
2346
+ fetch(option, fetchRequestOption, abortController) {
2347
+ fetch(option.url, fetchRequestOption)
2225
2348
  .then(async (fetchResponse) => {
2226
2349
  /** 自定义的response */
2227
2350
  let httpxResponse = {
@@ -2231,15 +2354,16 @@ var Utils = (function () {
2231
2354
  // @ts-ignore
2232
2355
  status: fetchResponse.status,
2233
2356
  statusText: fetchResponse.statusText,
2357
+ // @ts-ignore
2234
2358
  response: void 0,
2235
2359
  responseFetchHeaders: fetchResponse.headers,
2236
2360
  responseHeaders: "",
2237
2361
  // @ts-ignore
2238
2362
  responseText: void 0,
2239
- responseType: details.responseType,
2363
+ responseType: option.responseType,
2240
2364
  responseXML: void 0,
2241
2365
  };
2242
- Object.assign(httpxResponse, details.context || {});
2366
+ Object.assign(httpxResponse, option.context || {});
2243
2367
  // 把headers转为字符串
2244
2368
  for (const [key, value] of fetchResponse.headers.entries()) {
2245
2369
  httpxResponse.responseHeaders += `${key}: ${value}\n`;
@@ -2247,7 +2371,7 @@ var Utils = (function () {
2247
2371
  /** 请求返回的类型 */
2248
2372
  const fetchResponseType = fetchResponse.headers.get("Content-Type");
2249
2373
  /* 如果需要stream,且获取到的是stream,那直接返回 */
2250
- if (details.responseType === "stream" ||
2374
+ if (option.responseType === "stream" ||
2251
2375
  (fetchResponse.headers.has("Content-Type") &&
2252
2376
  fetchResponse.headers
2253
2377
  .get("Content-Type")
@@ -2256,7 +2380,7 @@ var Utils = (function () {
2256
2380
  Reflect.set(httpxResponse, "response", fetchResponse.body);
2257
2381
  Reflect.deleteProperty(httpxResponse, "responseText");
2258
2382
  Reflect.deleteProperty(httpxResponse, "responseXML");
2259
- details.onload(httpxResponse);
2383
+ option.onload(httpxResponse);
2260
2384
  return;
2261
2385
  }
2262
2386
  /** 响应 */
@@ -2285,22 +2409,22 @@ var Utils = (function () {
2285
2409
  let textDecoder = new TextDecoder(encoding);
2286
2410
  responseText = textDecoder.decode(arrayBuffer);
2287
2411
  response = responseText;
2288
- if (details.responseType === "arraybuffer") {
2412
+ if (option.responseType === "arraybuffer") {
2289
2413
  // response返回格式是二进制流
2290
2414
  response = arrayBuffer;
2291
2415
  }
2292
- else if (details.responseType === "blob") {
2416
+ else if (option.responseType === "blob") {
2293
2417
  // response返回格式是blob
2294
2418
  response = new Blob([arrayBuffer]);
2295
2419
  }
2296
- else if (details.responseType === "json" ||
2420
+ else if (option.responseType === "json" ||
2297
2421
  (typeof fetchResponseType === "string" &&
2298
2422
  fetchResponseType.includes("application/json"))) {
2299
2423
  // response返回格式是JSON格式
2300
2424
  response = utils.toJSON(responseText);
2301
2425
  }
2302
- else if (details.responseType === "document" ||
2303
- details.responseType == null) {
2426
+ else if (option.responseType === "document" ||
2427
+ option.responseType == null) {
2304
2428
  // response返回格式是文档格式
2305
2429
  let parser = new DOMParser();
2306
2430
  response = parser.parseFromString(responseText, "text/html");
@@ -2312,15 +2436,15 @@ var Utils = (function () {
2312
2436
  Reflect.set(httpxResponse, "responseText", responseText);
2313
2437
  Reflect.set(httpxResponse, "responseXML", responseXML);
2314
2438
  // 执行回调
2315
- details.onload(httpxResponse);
2439
+ option.onload(httpxResponse);
2316
2440
  })
2317
2441
  .catch((error) => {
2318
2442
  if (error.name === "AbortError") {
2319
2443
  return;
2320
2444
  }
2321
- details.onerror({
2445
+ option.onerror({
2322
2446
  isFetch: true,
2323
- finalUrl: details.url,
2447
+ finalUrl: option.url,
2324
2448
  readyState: 4,
2325
2449
  status: 0,
2326
2450
  statusText: "",
@@ -2329,9 +2453,9 @@ var Utils = (function () {
2329
2453
  error: error,
2330
2454
  });
2331
2455
  });
2332
- details.onloadstart({
2456
+ option.onloadstart({
2333
2457
  isFetch: true,
2334
- finalUrl: details.url,
2458
+ finalUrl: option.url,
2335
2459
  readyState: 1,
2336
2460
  responseHeaders: "",
2337
2461
  responseText: "",
@@ -2386,15 +2510,15 @@ var Utils = (function () {
2386
2510
  #LOG_DETAILS = false;
2387
2511
  /**
2388
2512
  * 实例化,可传入GM_xmlhttpRequest,未传入则使用window.fetch
2389
- * @param __xmlHttpRequest__
2513
+ * @param xmlHttpRequest
2390
2514
  */
2391
- constructor(__xmlHttpRequest__) {
2392
- if (typeof __xmlHttpRequest__ !== "function") {
2515
+ constructor(xmlHttpRequest) {
2516
+ if (typeof xmlHttpRequest !== "function") {
2393
2517
  console.warn("[Httpx-constructor] 未传入GM_xmlhttpRequest函数或传入的GM_xmlhttpRequest不是Function,将默认使用window.fetch");
2394
2518
  }
2395
2519
  this.interceptors.request.context = this;
2396
2520
  this.interceptors.response.context = this;
2397
- this.GM_Api.xmlHttpRequest = __xmlHttpRequest__;
2521
+ this.GM_Api.xmlHttpRequest = xmlHttpRequest;
2398
2522
  }
2399
2523
  /**
2400
2524
  * 覆盖当前配置
@@ -2488,28 +2612,24 @@ var Utils = (function () {
2488
2612
  */
2489
2613
  async get(...args // @ts-ignore
2490
2614
  ) {
2491
- let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
2615
+ let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
2492
2616
  let abortFn = null;
2493
- const promise = new Promise((resolve, reject) => {
2494
- let requestDetails = this.HttpxRequestDetails.getDetails("GET", details, resolve, reject);
2495
- Reflect.deleteProperty(requestDetails, "onprogress");
2496
- // @ts-ignore
2497
- requestDetails = this.HttpxRequestDetails.handle(requestDetails);
2498
- const requestResult = this.HttpxRequest.request(requestDetails);
2617
+ let promise = new globalThis.Promise((resolve, reject) => {
2618
+ let requestOption = this.HttpxRequestDetails.getRequestOption("GET", userRequestOption, resolve, reject);
2619
+ Reflect.deleteProperty(requestOption, "onprogress");
2620
+ this.HttpxRequestDetails.removeRequestNullOption(requestOption);
2621
+ const requestResult = this.HttpxRequest.request(requestOption);
2499
2622
  if (requestResult != null &&
2500
2623
  typeof requestResult.abort === "function") {
2501
2624
  abortFn = requestResult.abort;
2502
2625
  }
2503
2626
  });
2504
- Object.defineProperty(promise, "abort", {
2505
- value: () => {
2506
- return () => {
2507
- if (typeof abortFn === "function") {
2508
- abortFn();
2509
- }
2510
- };
2511
- },
2512
- });
2627
+ // @ts-ignore
2628
+ promise.abort = () => {
2629
+ if (typeof abortFn === "function") {
2630
+ abortFn();
2631
+ }
2632
+ };
2513
2633
  return promise;
2514
2634
  }
2515
2635
  /**
@@ -2517,27 +2637,25 @@ var Utils = (function () {
2517
2637
  */
2518
2638
  async post(...args // @ts-ignore
2519
2639
  ) {
2520
- let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
2640
+ let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
2521
2641
  let abortFn = null;
2522
- const promise = new Promise((resolve, reject) => {
2523
- let requestDetails = this.HttpxRequestDetails.getDetails("POST", details, resolve, reject);
2642
+ let promise = new Promise((resolve, reject) => {
2643
+ let requestOption = this.HttpxRequestDetails.getRequestOption("POST", userRequestOption, resolve, reject);
2524
2644
  // @ts-ignore
2525
- requestDetails = this.HttpxRequestDetails.handle(requestDetails);
2526
- const requestResult = this.HttpxRequest.request(requestDetails);
2645
+ requestOption =
2646
+ this.HttpxRequestDetails.removeRequestNullOption(requestOption);
2647
+ const requestResult = this.HttpxRequest.request(requestOption);
2527
2648
  if (requestResult != null &&
2528
2649
  typeof requestResult.abort === "function") {
2529
2650
  abortFn = requestResult.abort;
2530
2651
  }
2531
2652
  });
2532
- Object.defineProperty(promise, "abort", {
2533
- value: () => {
2534
- return () => {
2535
- if (typeof abortFn === "function") {
2536
- abortFn();
2537
- }
2538
- };
2539
- },
2540
- });
2653
+ // @ts-ignore
2654
+ promise.abort = () => {
2655
+ if (typeof abortFn === "function") {
2656
+ abortFn();
2657
+ }
2658
+ };
2541
2659
  return promise;
2542
2660
  }
2543
2661
  /**
@@ -2545,28 +2663,26 @@ var Utils = (function () {
2545
2663
  */
2546
2664
  async head(...args // @ts-ignore
2547
2665
  ) {
2548
- let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
2666
+ let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
2549
2667
  let abortFn = null;
2550
- const promise = new Promise((resolve, reject) => {
2551
- let requestDetails = this.HttpxRequestDetails.getDetails("HEAD", details, resolve, reject);
2552
- Reflect.deleteProperty(requestDetails, "onprogress");
2668
+ let promise = new Promise((resolve, reject) => {
2669
+ let requestOption = this.HttpxRequestDetails.getRequestOption("HEAD", userRequestOption, resolve, reject);
2670
+ Reflect.deleteProperty(requestOption, "onprogress");
2553
2671
  // @ts-ignore
2554
- requestDetails = this.HttpxRequestDetails.handle(requestDetails);
2555
- const requestResult = this.HttpxRequest.request(requestDetails);
2672
+ requestOption =
2673
+ this.HttpxRequestDetails.removeRequestNullOption(requestOption);
2674
+ const requestResult = this.HttpxRequest.request(requestOption);
2556
2675
  if (requestResult != null &&
2557
2676
  typeof requestResult.abort === "function") {
2558
2677
  abortFn = requestResult.abort;
2559
2678
  }
2560
2679
  });
2561
- Object.defineProperty(promise, "abort", {
2562
- value: () => {
2563
- return () => {
2564
- if (typeof abortFn === "function") {
2565
- abortFn();
2566
- }
2567
- };
2568
- },
2569
- });
2680
+ // @ts-ignore
2681
+ promise.abort = () => {
2682
+ if (typeof abortFn === "function") {
2683
+ abortFn();
2684
+ }
2685
+ };
2570
2686
  return promise;
2571
2687
  }
2572
2688
  /**
@@ -2574,28 +2690,26 @@ var Utils = (function () {
2574
2690
  */
2575
2691
  async options(...args // @ts-ignore
2576
2692
  ) {
2577
- let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
2693
+ let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
2578
2694
  let abortFn = null;
2579
- const promise = new Promise((resolve, reject) => {
2580
- let requestDetails = this.HttpxRequestDetails.getDetails("OPTIONS", details, resolve, reject);
2581
- Reflect.deleteProperty(requestDetails, "onprogress");
2695
+ let promise = new Promise((resolve, reject) => {
2696
+ let requestOption = this.HttpxRequestDetails.getRequestOption("OPTIONS", userRequestOption, resolve, reject);
2697
+ Reflect.deleteProperty(requestOption, "onprogress");
2582
2698
  // @ts-ignore
2583
- requestDetails = this.HttpxRequestDetails.handle(requestDetails);
2584
- const requestResult = this.HttpxRequest.request(requestDetails);
2699
+ requestOption =
2700
+ this.HttpxRequestDetails.removeRequestNullOption(requestOption);
2701
+ const requestResult = this.HttpxRequest.request(requestOption);
2585
2702
  if (requestResult != null &&
2586
2703
  typeof requestResult.abort === "function") {
2587
2704
  abortFn = requestResult.abort;
2588
2705
  }
2589
2706
  });
2590
- Object.defineProperty(promise, "abort", {
2591
- value: () => {
2592
- return () => {
2593
- if (typeof abortFn === "function") {
2594
- abortFn();
2595
- }
2596
- };
2597
- },
2598
- });
2707
+ // @ts-ignore
2708
+ promise.abort = () => {
2709
+ if (typeof abortFn === "function") {
2710
+ abortFn();
2711
+ }
2712
+ };
2599
2713
  return promise;
2600
2714
  }
2601
2715
  /**
@@ -2603,28 +2717,26 @@ var Utils = (function () {
2603
2717
  */
2604
2718
  async delete(...args // @ts-ignore
2605
2719
  ) {
2606
- let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
2720
+ let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
2607
2721
  let abortFn = null;
2608
- const promise = new Promise((resolve, reject) => {
2609
- let requestDetails = this.HttpxRequestDetails.getDetails("DELETE", details, resolve, reject);
2610
- Reflect.deleteProperty(requestDetails, "onprogress");
2722
+ let promise = new Promise((resolve, reject) => {
2723
+ let requestOption = this.HttpxRequestDetails.getRequestOption("DELETE", userRequestOption, resolve, reject);
2724
+ Reflect.deleteProperty(requestOption, "onprogress");
2611
2725
  // @ts-ignore
2612
- requestDetails = this.HttpxRequestDetails.handle(requestDetails);
2613
- const requestResult = this.HttpxRequest.request(requestDetails);
2726
+ requestOption =
2727
+ this.HttpxRequestDetails.removeRequestNullOption(requestOption);
2728
+ const requestResult = this.HttpxRequest.request(requestOption);
2614
2729
  if (requestResult != null &&
2615
2730
  typeof requestResult.abort === "function") {
2616
2731
  abortFn = requestResult.abort;
2617
2732
  }
2618
2733
  });
2619
- Object.defineProperty(promise, "abort", {
2620
- value: () => {
2621
- return () => {
2622
- if (typeof abortFn === "function") {
2623
- abortFn();
2624
- }
2625
- };
2626
- },
2627
- });
2734
+ // @ts-ignore
2735
+ promise.abort = () => {
2736
+ if (typeof abortFn === "function") {
2737
+ abortFn();
2738
+ }
2739
+ };
2628
2740
  return promise;
2629
2741
  }
2630
2742
  /**
@@ -2632,27 +2744,25 @@ var Utils = (function () {
2632
2744
  */
2633
2745
  async put(...args // @ts-ignore
2634
2746
  ) {
2635
- let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
2747
+ let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
2636
2748
  let abortFn = null;
2637
- const promise = new Promise((resolve, reject) => {
2638
- let requestDetails = this.HttpxRequestDetails.getDetails("PUT", details, resolve, reject);
2749
+ let promise = new Promise((resolve, reject) => {
2750
+ let requestOption = this.HttpxRequestDetails.getRequestOption("PUT", userRequestOption, resolve, reject);
2639
2751
  // @ts-ignore
2640
- requestDetails = this.HttpxRequestDetails.handle(requestDetails);
2641
- const requestResult = this.HttpxRequest.request(requestDetails);
2752
+ requestOption =
2753
+ this.HttpxRequestDetails.removeRequestNullOption(requestOption);
2754
+ const requestResult = this.HttpxRequest.request(requestOption);
2642
2755
  if (requestResult != null &&
2643
2756
  typeof requestResult.abort === "function") {
2644
2757
  abortFn = requestResult.abort;
2645
2758
  }
2646
2759
  });
2647
- Object.defineProperty(promise, "abort", {
2648
- value: () => {
2649
- return () => {
2650
- if (typeof abortFn === "function") {
2651
- abortFn();
2652
- }
2653
- };
2654
- },
2655
- });
2760
+ // @ts-ignore
2761
+ promise.abort = () => {
2762
+ if (typeof abortFn === "function") {
2763
+ abortFn();
2764
+ }
2765
+ };
2656
2766
  return promise;
2657
2767
  }
2658
2768
  }
@@ -3957,7 +4067,7 @@ var Utils = (function () {
3957
4067
  this.windowApi = new WindowApi(option);
3958
4068
  }
3959
4069
  /** 版本号 */
3960
- version = "2024.10.19";
4070
+ version = "2024.10.28";
3961
4071
  addStyle(cssText) {
3962
4072
  if (typeof cssText !== "string") {
3963
4073
  throw new Error("Utils.addStyle 参数cssText 必须为String类型");
@@ -6188,7 +6298,8 @@ var Utils = (function () {
6188
6298
  dragSlider(selector, offsetX = this.windowApi.window.innerWidth) {
6189
6299
  let UtilsContext = this;
6190
6300
  function initMouseEvent(eventName, offSetX, offSetY) {
6191
- let win = unsafeWindow || window;
6301
+ // @ts-ignore
6302
+ let win = typeof unsafeWindow === "undefined" ? globalThis : unsafeWindow;
6192
6303
  let mouseEvent = UtilsContext.windowApi.document.createEvent("MouseEvents");
6193
6304
  mouseEvent.initMouseEvent(eventName, true, true, win, 0, offSetX, offSetY, offSetX, offSetY, false, false, false, false, 0, null);
6194
6305
  return mouseEvent;