@whitesev/utils 2.3.7 → 2.4.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.
Files changed (57) hide show
  1. package/dist/index.amd.js +415 -289
  2. package/dist/index.amd.js.map +1 -1
  3. package/dist/index.cjs.js +415 -289
  4. package/dist/index.cjs.js.map +1 -1
  5. package/dist/index.esm.js +415 -289
  6. package/dist/index.esm.js.map +1 -1
  7. package/dist/index.iife.js +415 -289
  8. package/dist/index.iife.js.map +1 -1
  9. package/dist/index.system.js +415 -289
  10. package/dist/index.system.js.map +1 -1
  11. package/dist/index.umd.js +415 -289
  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 +535 -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 +44 -66
  38. package/src/UtilsGMCookie.ts +7 -56
  39. package/src/UtilsGMMenu.ts +5 -78
  40. package/src/WindowApi.ts +4 -11
  41. package/src/indexedDB.ts +12 -10
  42. package/src/types/Event.d.ts +189 -0
  43. package/src/types/Httpx.d.ts +1316 -0
  44. package/src/types/Log.d.ts +19 -0
  45. package/src/types/Progress.d.ts +20 -0
  46. package/src/types/TryCatch.d.ts +9 -0
  47. package/src/types/UtilsGMCookie.d.ts +55 -0
  48. package/src/types/UtilsGMMenu.d.ts +77 -0
  49. package/src/types/Vue2.d.ts +154 -0
  50. package/src/types/Vue3.d.ts +0 -0
  51. package/src/types/WindowApi.d.ts +10 -0
  52. package/{dist/types/src/AjaxHookerType.d.ts → src/types/ajaxHooker.d.ts} +155 -147
  53. package/src/types/global.d.ts +24 -1
  54. package/dist/types/src/Event.d.ts +0 -156
  55. package/dist/types/src/VueObject.d.ts +0 -123
  56. /package/{src/Event.ts → dist/types/src/types/Event.d.ts} +0 -0
  57. /package/{src/AjaxHookerType.ts → dist/types/src/types/ajaxHooker.d.ts} +0 -0
package/dist/index.esm.js CHANGED
@@ -1715,55 +1715,57 @@ class Httpx {
1715
1715
  /**
1716
1716
  * 根据传入的参数处理获取details配置
1717
1717
  */
1718
- handleBeforeRequestDetails(...args) {
1719
- let result = {};
1718
+ handleBeforeRequestOption(...args) {
1719
+ let option = {};
1720
1720
  if (typeof args[0] === "string") {
1721
1721
  /* 传入的是url,details? */
1722
1722
  let url = args[0];
1723
- result.url = url;
1723
+ option.url = url;
1724
1724
  if (typeof args[1] === "object") {
1725
1725
  /* 处理第二个参数details */
1726
1726
  let details = args[1];
1727
- result = details;
1728
- result.url = url;
1727
+ option = details;
1728
+ option.url = url;
1729
1729
  }
1730
1730
  }
1731
1731
  else {
1732
1732
  /* 传入的是details */
1733
- result = args[0];
1733
+ option = args[0];
1734
1734
  }
1735
- return result;
1735
+ return option;
1736
1736
  },
1737
1737
  /**
1738
1738
  * 获取请求配置
1739
1739
  * @param method 当前请求方法,默认get
1740
- * @param details 请求配置
1740
+ * @param userRequestOption 用户的请求配置
1741
1741
  * @param resolve promise回调
1742
1742
  * @param reject 抛出错误回调
1743
1743
  */
1744
- getDetails(method, details, resolve, reject) {
1744
+ getRequestOption(method, userRequestOption, resolve, reject) {
1745
1745
  let that = this;
1746
- let result = {
1747
- url: details.url || this.context.#defaultDetails.url,
1746
+ let requestOption = {
1747
+ url: userRequestOption.url || this.context.#defaultDetails.url,
1748
1748
  method: (method || "GET").toString().toUpperCase(),
1749
- timeout: details.timeout || this.context.#defaultDetails.timeout,
1750
- responseType: details.responseType || this.context.#defaultDetails.responseType,
1749
+ timeout: userRequestOption.timeout || this.context.#defaultDetails.timeout,
1750
+ responseType: userRequestOption.responseType ||
1751
+ this.context.#defaultDetails.responseType,
1751
1752
  /* 对象使用深拷贝 */
1752
1753
  headers: utils.deepClone(this.context.#defaultDetails.headers),
1753
- data: details.data || this.context.#defaultDetails.data,
1754
- redirect: details.redirect || this.context.#defaultDetails.redirect,
1755
- cookie: details.cookie || this.context.#defaultDetails.cookie,
1756
- cookiePartition: details.cookiePartition ||
1754
+ data: userRequestOption.data || this.context.#defaultDetails.data,
1755
+ redirect: userRequestOption.redirect || this.context.#defaultDetails.redirect,
1756
+ cookie: userRequestOption.cookie || this.context.#defaultDetails.cookie,
1757
+ cookiePartition: userRequestOption.cookiePartition ||
1757
1758
  this.context.#defaultDetails.cookiePartition,
1758
- binary: details.binary || this.context.#defaultDetails.binary,
1759
- nocache: details.nocache || this.context.#defaultDetails.nocache,
1760
- revalidate: details.revalidate || this.context.#defaultDetails.revalidate,
1759
+ binary: userRequestOption.binary || this.context.#defaultDetails.binary,
1760
+ nocache: userRequestOption.nocache || this.context.#defaultDetails.nocache,
1761
+ revalidate: userRequestOption.revalidate ||
1762
+ this.context.#defaultDetails.revalidate,
1761
1763
  /* 对象使用深拷贝 */
1762
- context: utils.deepClone(details.context || this.context.#defaultDetails.context),
1763
- overrideMimeType: details.overrideMimeType ||
1764
+ context: utils.deepClone(userRequestOption.context || this.context.#defaultDetails.context),
1765
+ overrideMimeType: userRequestOption.overrideMimeType ||
1764
1766
  this.context.#defaultDetails.overrideMimeType,
1765
- anonymous: details.anonymous || this.context.#defaultDetails.anonymous,
1766
- fetch: details.fetch || this.context.#defaultDetails.fetch,
1767
+ anonymous: userRequestOption.anonymous || this.context.#defaultDetails.anonymous,
1768
+ fetch: userRequestOption.fetch || this.context.#defaultDetails.fetch,
1767
1769
  /* 对象使用深拷贝 */
1768
1770
  fetchInit: utils.deepClone(this.context.#defaultDetails.fetchInit),
1769
1771
  allowInterceptConfig: {
@@ -1774,153 +1776,243 @@ class Httpx {
1774
1776
  afterResponseError: this.context.#defaultDetails
1775
1777
  .allowInterceptConfig.afterResponseError,
1776
1778
  },
1777
- user: details.user || this.context.#defaultDetails.user,
1778
- password: details.password || this.context.#defaultDetails.password,
1779
+ user: userRequestOption.user || this.context.#defaultDetails.user,
1780
+ password: userRequestOption.password || this.context.#defaultDetails.password,
1779
1781
  onabort(...args) {
1780
- that.context.HttpxCallBack.onAbort(details, resolve, reject, args);
1782
+ that.context.HttpxCallBack.onAbort(userRequestOption, resolve, reject, args);
1781
1783
  },
1782
1784
  onerror(...args) {
1783
- that.context.HttpxCallBack.onError(details, resolve, reject, args);
1785
+ that.context.HttpxCallBack.onError(userRequestOption, resolve, reject, args);
1784
1786
  },
1785
1787
  onloadstart(...args) {
1786
- that.context.HttpxCallBack.onLoadStart(details, args);
1788
+ that.context.HttpxCallBack.onLoadStart(userRequestOption, args);
1787
1789
  },
1788
1790
  onprogress(...args) {
1789
- that.context.HttpxCallBack.onProgress(details, args);
1791
+ that.context.HttpxCallBack.onProgress(userRequestOption, args);
1790
1792
  },
1791
1793
  onreadystatechange(...args) {
1792
- that.context.HttpxCallBack.onReadyStateChange(details, args);
1794
+ that.context.HttpxCallBack.onReadyStateChange(userRequestOption, args);
1793
1795
  },
1794
1796
  ontimeout(...args) {
1795
- that.context.HttpxCallBack.onTimeout(details, resolve, reject, args);
1797
+ that.context.HttpxCallBack.onTimeout(userRequestOption, resolve, reject, args);
1796
1798
  },
1797
1799
  onload(...args) {
1798
- that.context.HttpxCallBack.onLoad(details, resolve, reject, args);
1800
+ that.context.HttpxCallBack.onLoad(userRequestOption, resolve, reject, args);
1799
1801
  },
1800
1802
  };
1801
1803
  // 补全allowInterceptConfig参数
1802
- if (typeof details.allowInterceptConfig === "boolean") {
1803
- Object.keys(result.allowInterceptConfig).forEach((keyName) => {
1804
- result.allowInterceptConfig[keyName] =
1805
- details.allowInterceptConfig;
1804
+ if (typeof userRequestOption.allowInterceptConfig === "boolean") {
1805
+ Object.keys(requestOption.allowInterceptConfig).forEach((keyName) => {
1806
+ Reflect.set(requestOption.allowInterceptConfig, keyName, userRequestOption.allowInterceptConfig);
1806
1807
  });
1807
1808
  }
1808
1809
  else {
1809
- if (typeof details.allowInterceptConfig === "object" &&
1810
- details.allowInterceptConfig != null) {
1811
- Object.keys(details.allowInterceptConfig).forEach((keyName) => {
1812
- let value = details.allowInterceptConfig[keyName];
1813
- if (keyName in
1814
- result.allowInterceptConfig &&
1815
- typeof value === "boolean") {
1816
- result.allowInterceptConfig[keyName] = value;
1810
+ if (typeof userRequestOption.allowInterceptConfig === "object" &&
1811
+ userRequestOption.allowInterceptConfig != null) {
1812
+ Object.keys(userRequestOption.allowInterceptConfig).forEach((keyName) => {
1813
+ let value = Reflect.get(userRequestOption.allowInterceptConfig, keyName);
1814
+ if (typeof value === "boolean" &&
1815
+ Reflect.has(requestOption.allowInterceptConfig, keyName)) {
1816
+ Reflect.set(requestOption.allowInterceptConfig, keyName, value);
1817
1817
  }
1818
1818
  });
1819
1819
  }
1820
1820
  }
1821
1821
  if (typeof this.context.GM_Api.xmlHttpRequest !== "function") {
1822
- result.fetch = true;
1823
- }
1824
- if (typeof result.headers === "object") {
1825
- if (typeof details.headers === "object") {
1826
- Object.keys(details.headers).forEach((keyName, index) => {
1827
- if (keyName in result.headers &&
1828
- details.headers?.[keyName] == null) {
1822
+ // GM函数不存在,强制使用fetch
1823
+ requestOption.fetch = true;
1824
+ }
1825
+ if (typeof requestOption.headers === "object") {
1826
+ if (typeof userRequestOption.headers === "object") {
1827
+ Object.keys(userRequestOption.headers).forEach((keyName, index) => {
1828
+ if (keyName in requestOption.headers &&
1829
+ userRequestOption.headers?.[keyName] == null) {
1829
1830
  /* 在默认的header中存在,且设置它新的值为空,那么就是默认的值 */
1830
- Reflect.deleteProperty(result.headers, keyName);
1831
+ Reflect.deleteProperty(requestOption.headers, keyName);
1831
1832
  }
1832
1833
  else {
1833
- result.headers[keyName] = details?.headers?.[keyName];
1834
+ requestOption.headers[keyName] =
1835
+ userRequestOption?.headers?.[keyName];
1834
1836
  }
1835
1837
  });
1836
1838
  }
1837
1839
  }
1838
1840
  else {
1839
- result.headers = details.headers;
1841
+ /* 默认的headers不是对象,那么就直接使用新的 */
1842
+ Reflect.set(requestOption, "headers", userRequestOption.headers);
1840
1843
  }
1841
- if (typeof result.fetchInit === "object") {
1844
+ if (typeof requestOption.fetchInit === "object") {
1842
1845
  /* 使用assign替换且添加 */
1843
- if (typeof details.fetchInit === "object") {
1844
- Object.keys(details.fetchInit).forEach((keyName, index) => {
1845
- if (keyName in result.fetchInit &&
1846
- details.fetchInit[keyName] == null) {
1846
+ if (typeof userRequestOption.fetchInit === "object") {
1847
+ Object.keys(userRequestOption.fetchInit).forEach((keyName, index) => {
1848
+ if (keyName in requestOption.fetchInit &&
1849
+ userRequestOption.fetchInit[keyName] == null) {
1847
1850
  /* 在默认的fetchInit中存在,且设置它新的值为空,那么就是默认的值 */
1848
- Reflect.deleteProperty(result.fetchInit, keyName);
1851
+ Reflect.deleteProperty(requestOption.fetchInit, keyName);
1849
1852
  }
1850
1853
  else {
1851
- result.fetchInit[keyName] = details.fetchInit[keyName];
1854
+ Reflect.set(requestOption.fetchInit, keyName, Reflect.get(userRequestOption.fetchInit, keyName));
1852
1855
  }
1853
1856
  });
1854
1857
  }
1855
1858
  }
1856
1859
  else {
1857
- result.fetchInit = details.fetchInit;
1860
+ Reflect.set(requestOption, "fetchInit", userRequestOption.fetchInit);
1858
1861
  }
1859
1862
  // 处理新的cookiePartition
1860
- if (typeof result.cookiePartition === "object" &&
1861
- result.cookiePartition != null) {
1862
- if (Reflect.has(result.cookiePartition, "topLevelSite") &&
1863
- typeof result.cookiePartition.topLevelSite !== "string") {
1863
+ if (typeof requestOption.cookiePartition === "object" &&
1864
+ requestOption.cookiePartition != null) {
1865
+ if (Reflect.has(requestOption.cookiePartition, "topLevelSite") &&
1866
+ typeof requestOption.cookiePartition.topLevelSite !== "string") {
1864
1867
  // topLevelSite必须是字符串
1865
- Reflect.deleteProperty(result.cookiePartition, "topLevelSite");
1868
+ Reflect.deleteProperty(requestOption.cookiePartition, "topLevelSite");
1866
1869
  }
1867
1870
  }
1868
- return result;
1869
- },
1870
- /**
1871
- * 处理发送请求的details,去除值为undefined、空function的值
1872
- * @param details
1873
- */
1874
- handle(details) {
1875
- Object.keys(details).forEach((keyName) => {
1876
- if (details[keyName] == null ||
1877
- (details[keyName] instanceof Function &&
1878
- utils.isNull(details[keyName]))) {
1879
- Reflect.deleteProperty(details, keyName);
1880
- return;
1881
- }
1882
- });
1883
- if (utils.isNull(details.url)) {
1884
- throw new TypeError(`Utils.Httpx 参数 url不符合要求: ${details.url}`);
1885
- }
1886
- /* method值统一大写,兼容Via */
1887
- details.method = details.method.toUpperCase();
1888
- /* 判断是否是以http开头,否则主动加上origin */
1871
+ /* 完善请求的url */
1889
1872
  try {
1890
- new URL(details.url);
1873
+ new URL(requestOption.url);
1891
1874
  }
1892
1875
  catch (error) {
1893
- if (details.url.startsWith("//")) {
1894
- details.url = window.location.protocol + details.url;
1876
+ if (requestOption.url.startsWith("//")) {
1877
+ // 补充https:
1878
+ requestOption.url = globalThis.location.protocol + requestOption.url;
1895
1879
  }
1896
- else if (details.url.startsWith("/")) {
1897
- details.url = window.location.origin + details.url;
1880
+ else if (requestOption.url.startsWith("/")) {
1881
+ // 补充origin
1882
+ requestOption.url = globalThis.location.origin + requestOption.url;
1898
1883
  }
1899
1884
  else {
1900
- details.url = window.location.origin + "/" + details.url;
1885
+ // 补充origin+/
1886
+ requestOption.url =
1887
+ globalThis.location.origin + "/" + requestOption.url;
1901
1888
  }
1902
1889
  }
1903
- return details;
1890
+ if (requestOption.fetchInit && !requestOption.fetch) {
1891
+ // 清空fetchInit
1892
+ Reflect.deleteProperty(requestOption, "fetchInit");
1893
+ }
1894
+ // 转换data类型
1895
+ try {
1896
+ /** 是否对数据进行处理 */
1897
+ let processData = userRequestOption.processData ?? true;
1898
+ if (requestOption.data != null && processData) {
1899
+ let method = requestOption.method;
1900
+ if (method === "GET" || method === "HEAD") {
1901
+ // GET类型,data如果有,那么需要转为searchParams
1902
+ let urlObj = new URL(requestOption.url);
1903
+ let urlSearch = "";
1904
+ if (typeof requestOption.data === "string") {
1905
+ urlSearch = requestOption.data;
1906
+ }
1907
+ else if (typeof requestOption.data === "object") {
1908
+ // URLSearchParams参数可以转普通的string:string,包括FormData
1909
+ // @ts-ignore
1910
+ let searchParams = new URLSearchParams(requestOption.data);
1911
+ urlSearch = searchParams.toString();
1912
+ }
1913
+ if (urlSearch != "") {
1914
+ if (urlObj.search === "") {
1915
+ // url没有search参数,直接覆盖
1916
+ urlObj.search = urlSearch;
1917
+ }
1918
+ else {
1919
+ // 有search参数
1920
+ if (urlObj.search.endsWith("&")) {
1921
+ // xxx=xxx&
1922
+ urlObj.search = urlObj.search + urlSearch;
1923
+ }
1924
+ else {
1925
+ // xxx=xxx&xxx=
1926
+ urlObj.search = urlObj.search + "&" + urlSearch;
1927
+ }
1928
+ }
1929
+ }
1930
+ requestOption.url = urlObj.toString();
1931
+ }
1932
+ else if (method === "POST" && requestOption.headers != null) {
1933
+ // POST类型,data如果是FormData,那么需要转为string
1934
+ let headersKeyList = Object.keys(requestOption.headers);
1935
+ let ContentTypeIndex = headersKeyList.findIndex((headerKey) => {
1936
+ return (headerKey.trim().toLowerCase() === "content-type" &&
1937
+ typeof requestOption.headers[headerKey] === "string");
1938
+ });
1939
+ if (ContentTypeIndex !== -1) {
1940
+ let ContentTypeKey = headersKeyList[ContentTypeIndex];
1941
+ // 设置了Content-Type
1942
+ let ContentType = requestOption.headers[ContentTypeIndex].toLowerCase();
1943
+ if (ContentType.includes("application/json")) {
1944
+ // application/json
1945
+ if (requestOption.data instanceof FormData) {
1946
+ const entries = {};
1947
+ requestOption.data.forEach((value, key) => {
1948
+ entries[key] = value;
1949
+ });
1950
+ requestOption.data = JSON.stringify(entries);
1951
+ }
1952
+ else if (typeof requestOption.data === "object") {
1953
+ requestOption.data = JSON.stringify(requestOption.data);
1954
+ }
1955
+ }
1956
+ else if (ContentType.includes("application/x-www-form-urlencoded")) {
1957
+ // application/x-www-form-urlencoded
1958
+ if (typeof requestOption.data === "object") {
1959
+ requestOption.data = new URLSearchParams(
1960
+ // @ts-ignore
1961
+ requestOption.data).toString();
1962
+ }
1963
+ }
1964
+ else if (ContentType.includes("multipart/form-data")) {
1965
+ // multipart/form-data
1966
+ if (requestOption.data instanceof FormData) {
1967
+ Reflect.deleteProperty(requestOption.headers, ContentTypeKey);
1968
+ }
1969
+ }
1970
+ }
1971
+ }
1972
+ }
1973
+ }
1974
+ catch (error) {
1975
+ console.warn("Httpx ==> 转换data参数错误", error);
1976
+ }
1977
+ return requestOption;
1978
+ },
1979
+ /**
1980
+ * 处理发送请求的配置,去除值为undefined、空function的值
1981
+ * @param option
1982
+ */
1983
+ removeRequestNullOption(option) {
1984
+ Object.keys(option).forEach((keyName) => {
1985
+ if (option[keyName] == null ||
1986
+ (option[keyName] instanceof Function &&
1987
+ utils.isNull(option[keyName]))) {
1988
+ Reflect.deleteProperty(option, keyName);
1989
+ return;
1990
+ }
1991
+ });
1992
+ if (utils.isNull(option.url)) {
1993
+ throw new TypeError(`Utils.Httpx 参数 url不符合要求: ${option.url}`);
1994
+ }
1995
+ return option;
1904
1996
  },
1905
1997
  /**
1906
1998
  * 处理fetch的配置
1907
- * @param details
1999
+ * @param option
1908
2000
  */
1909
- handleFetchDetail(details) {
2001
+ handleFetchOption(option) {
1910
2002
  /**
1911
2003
  * fetch的请求配置
1912
2004
  **/
1913
- let fetchRequestInit = {};
1914
- if ((details.method === "GET" || details.method === "HEAD") &&
1915
- details.data != null) {
2005
+ let fetchRequestOption = {};
2006
+ if ((option.method === "GET" || option.method === "HEAD") &&
2007
+ option.data != null) {
1916
2008
  /* GET 或 HEAD 方法的请求不能包含 body 信息 */
1917
- Reflect.deleteProperty(details, "data");
2009
+ Reflect.deleteProperty(option, "data");
1918
2010
  }
1919
2011
  /* 中止信号控制器 */
1920
2012
  let abortController = new AbortController();
1921
2013
  let signal = abortController.signal;
1922
2014
  signal.onabort = () => {
1923
- details.onabort({
2015
+ option.onabort({
1924
2016
  isFetch: true,
1925
2017
  responseText: "",
1926
2018
  response: null,
@@ -1931,19 +2023,28 @@ class Httpx {
1931
2023
  error: "aborted",
1932
2024
  });
1933
2025
  };
1934
- fetchRequestInit.method = details.method ?? "GET";
1935
- fetchRequestInit.headers = details.headers;
1936
- fetchRequestInit.body = details.data;
1937
- fetchRequestInit.mode = "cors";
1938
- fetchRequestInit.credentials = "include";
1939
- fetchRequestInit.cache = "no-cache";
1940
- fetchRequestInit.redirect = "follow";
1941
- fetchRequestInit.referrerPolicy = "origin-when-cross-origin";
1942
- fetchRequestInit.signal = signal;
1943
- Object.assign(fetchRequestInit, details.fetchInit || {});
2026
+ // 设置请求
2027
+ fetchRequestOption.method = option.method ?? "GET";
2028
+ // 设置请求头
2029
+ fetchRequestOption.headers = option.headers;
2030
+ // 设置请求体
2031
+ fetchRequestOption.body = option.data;
2032
+ // 设置跨域
2033
+ fetchRequestOption.mode = "cors";
2034
+ // 设置包含
2035
+ fetchRequestOption.credentials = "include";
2036
+ // 设置不缓存
2037
+ fetchRequestOption.cache = "no-cache";
2038
+ // 设置始终重定向
2039
+ fetchRequestOption.redirect = "follow";
2040
+ // 设置referer跨域
2041
+ fetchRequestOption.referrerPolicy = "origin-when-cross-origin";
2042
+ // 设置信号中断
2043
+ fetchRequestOption.signal = signal;
2044
+ Object.assign(fetchRequestOption, option.fetchInit || {});
1944
2045
  return {
1945
- fetchDetails: details,
1946
- fetchRequestInit: fetchRequestInit,
2046
+ fetchOption: option,
2047
+ fetchRequestOption: fetchRequestOption,
1947
2048
  abortController: abortController,
1948
2049
  };
1949
2050
  },
@@ -1955,14 +2056,19 @@ class Httpx {
1955
2056
  * @param details 配置
1956
2057
  * @param resolve 回调
1957
2058
  * @param reject 抛出错误
1958
- * @param argumentsList 参数列表
2059
+ * @param argsResult 返回的参数列表
1959
2060
  */
1960
- onAbort(details, resolve, reject, argumentsList) {
2061
+ onAbort(details, resolve, reject, argsResult) {
2062
+ // console.log(argsResult);
1961
2063
  if ("onabort" in details) {
1962
- details.onabort.apply(this, argumentsList);
2064
+ details.onabort.apply(this, argsResult);
1963
2065
  }
1964
2066
  else if ("onabort" in this.context.#defaultDetails) {
1965
- this.context.#defaultDetails.onabort.apply(this, argumentsList);
2067
+ this.context.#defaultDetails.onabort.apply(this, argsResult);
2068
+ }
2069
+ let response = argsResult;
2070
+ if (response.length) {
2071
+ response = response[0];
1966
2072
  }
1967
2073
  if (this.context.HttpxResponseHook.errorResponseCallBack({
1968
2074
  type: "onabort",
@@ -1974,9 +2080,11 @@ class Httpx {
1974
2080
  return;
1975
2081
  }
1976
2082
  resolve({
1977
- status: false,
1978
- data: [...argumentsList],
2083
+ data: response,
2084
+ details: details,
1979
2085
  msg: "请求被取消",
2086
+ status: false,
2087
+ statusCode: -1,
1980
2088
  type: "onabort",
1981
2089
  });
1982
2090
  },
@@ -1985,16 +2093,17 @@ class Httpx {
1985
2093
  * @param details 配置
1986
2094
  * @param resolve 回调
1987
2095
  * @param reject 抛出错误
1988
- * @param argumentsList 响应的参数列表
2096
+ * @param argsResult 返回的参数列表
1989
2097
  */
1990
- onError(details, resolve, reject, argumentsList) {
2098
+ onError(details, resolve, reject, argsResult) {
2099
+ // console.log(argsResult);
1991
2100
  if ("onerror" in details) {
1992
- details.onerror.apply(this, argumentsList);
2101
+ details.onerror.apply(this, argsResult);
1993
2102
  }
1994
2103
  else if ("onerror" in this.context.#defaultDetails) {
1995
- this.context.#defaultDetails.onerror.apply(this, argumentsList);
2104
+ this.context.#defaultDetails.onerror.apply(this, argsResult);
1996
2105
  }
1997
- let response = argumentsList;
2106
+ let response = argsResult;
1998
2107
  if (response.length) {
1999
2108
  response = response[0];
2000
2109
  }
@@ -2008,10 +2117,11 @@ class Httpx {
2008
2117
  return;
2009
2118
  }
2010
2119
  resolve({
2011
- status: false,
2012
2120
  data: response,
2013
2121
  details: details,
2014
2122
  msg: "请求异常",
2123
+ status: false,
2124
+ statusCode: response["status"],
2015
2125
  type: "onerror",
2016
2126
  });
2017
2127
  },
@@ -2020,42 +2130,50 @@ class Httpx {
2020
2130
  * @param details 配置
2021
2131
  * @param resolve 回调
2022
2132
  * @param reject 抛出错误
2023
- * @param argumentsList 参数列表
2133
+ * @param argsResult 返回的参数列表
2024
2134
  */
2025
- onTimeout(details, resolve, reject, argumentsList) {
2135
+ onTimeout(details, resolve, reject, argsResult) {
2136
+ // console.log(argsResult);
2026
2137
  if ("ontimeout" in details) {
2027
- details.ontimeout.apply(this, argumentsList);
2138
+ details.ontimeout.apply(this, argsResult);
2028
2139
  }
2029
2140
  else if ("ontimeout" in this.context.#defaultDetails) {
2030
- this.context.#defaultDetails.ontimeout.apply(this, argumentsList);
2141
+ this.context.#defaultDetails.ontimeout.apply(this, argsResult);
2142
+ }
2143
+ let response = argsResult;
2144
+ if (response.length) {
2145
+ response = response[0];
2031
2146
  }
2032
2147
  if (this.context.HttpxResponseHook.errorResponseCallBack({
2033
2148
  type: "ontimeout",
2034
2149
  error: new TypeError("request timeout"),
2035
- response: (argumentsList || [null])[0],
2150
+ response: (argsResult || [null])[0],
2036
2151
  details: details,
2037
2152
  }) == null) {
2038
2153
  // reject(new TypeError("response is intercept with ontimeout"));
2039
2154
  return;
2040
2155
  }
2041
2156
  resolve({
2042
- status: false,
2043
- data: [...argumentsList],
2157
+ data: response,
2158
+ details: details,
2044
2159
  msg: "请求超时",
2160
+ status: false,
2161
+ statusCode: 0,
2045
2162
  type: "ontimeout",
2046
2163
  });
2047
2164
  },
2048
2165
  /**
2049
2166
  * onloadstart请求开始-触发
2050
2167
  * @param details 配置
2051
- * @param argumentsList 参数列表
2168
+ * @param argsResult 返回的参数列表
2052
2169
  */
2053
- onLoadStart(details, argumentsList) {
2170
+ onLoadStart(details, argsResult) {
2171
+ // console.log(argsResult);
2054
2172
  if ("onloadstart" in details) {
2055
- details.onloadstart.apply(this, argumentsList);
2173
+ details.onloadstart.apply(this, argsResult);
2056
2174
  }
2057
2175
  else if ("onloadstart" in this.context.#defaultDetails) {
2058
- this.context.#defaultDetails.onloadstart.apply(this, argumentsList);
2176
+ this.context.#defaultDetails.onloadstart.apply(this, argsResult);
2059
2177
  }
2060
2178
  },
2061
2179
  /**
@@ -2063,11 +2181,12 @@ class Httpx {
2063
2181
  * @param details 请求的配置
2064
2182
  * @param resolve 回调
2065
2183
  * @param reject 抛出错误
2066
- * @param argumentsList 参数列表
2184
+ * @param argsResult 返回的参数列表
2067
2185
  */
2068
- onLoad(details, resolve, reject, argumentsList) {
2186
+ onLoad(details, resolve, reject, argsResult) {
2187
+ // console.log(argsResult);
2069
2188
  /* X浏览器会因为设置了responseType导致不返回responseText */
2070
- let originResponse = argumentsList[0];
2189
+ let originResponse = argsResult[0];
2071
2190
  /* responseText为空,response不为空的情况 */
2072
2191
  if (utils.isNull(originResponse["responseText"]) &&
2073
2192
  utils.isNotNull(originResponse["response"])) {
@@ -2140,41 +2259,44 @@ class Httpx {
2140
2259
  return;
2141
2260
  }
2142
2261
  resolve({
2143
- status: true,
2144
2262
  data: originResponse,
2145
2263
  details: details,
2146
- msg: "请求完毕",
2264
+ msg: "请求成功",
2265
+ status: true,
2266
+ statusCode: originResponse.status,
2147
2267
  type: "onload",
2148
2268
  });
2149
2269
  }
2150
2270
  else {
2151
- this.context.HttpxCallBack.onError(details, resolve, reject, argumentsList);
2271
+ this.context.HttpxCallBack.onError(details, resolve, reject, argsResult);
2152
2272
  }
2153
2273
  },
2154
2274
  /**
2155
2275
  * onprogress上传进度-触发
2156
2276
  * @param details 配置
2157
- * @param argumentsList 参数列表
2277
+ * @param argsResult 返回的参数列表
2158
2278
  */
2159
- onProgress(details, argumentsList) {
2279
+ onProgress(details, argsResult) {
2280
+ // console.log(argsResult);
2160
2281
  if ("onprogress" in details) {
2161
- details.onprogress.apply(this, argumentsList);
2282
+ details.onprogress.apply(this, argsResult);
2162
2283
  }
2163
2284
  else if ("onprogress" in this.context.#defaultDetails) {
2164
- this.context.#defaultDetails.onprogress.apply(this, argumentsList);
2285
+ this.context.#defaultDetails.onprogress.apply(this, argsResult);
2165
2286
  }
2166
2287
  },
2167
2288
  /**
2168
2289
  * onreadystatechange准备状态改变-触发
2169
2290
  * @param details 配置
2170
- * @param argumentsList 参数列表
2291
+ * @param argsResult 返回的参数列表
2171
2292
  */
2172
- onReadyStateChange(details, argumentsList) {
2293
+ onReadyStateChange(details, argsResult) {
2294
+ // console.log(argsResult);
2173
2295
  if ("onreadystatechange" in details) {
2174
- details.onreadystatechange.apply(this, argumentsList);
2296
+ details.onreadystatechange.apply(this, argsResult);
2175
2297
  }
2176
2298
  else if ("onreadystatechange" in this.context.#defaultDetails) {
2177
- this.context.#defaultDetails.onreadystatechange.apply(this, argumentsList);
2299
+ this.context.#defaultDetails.onreadystatechange.apply(this, argsResult);
2178
2300
  }
2179
2301
  },
2180
2302
  };
@@ -2196,11 +2318,12 @@ class Httpx {
2196
2318
  }
2197
2319
  }
2198
2320
  if (details.fetch) {
2199
- const { fetchDetails, fetchRequestInit, abortController } = this.context.HttpxRequestDetails.handleFetchDetail(details);
2200
- return this.fetch(fetchDetails, fetchRequestInit, abortController);
2321
+ // 使用fetch请求
2322
+ const { fetchOption: fetchOption, fetchRequestOption: fetchRequestOption, abortController, } = this.context.HttpxRequestDetails.handleFetchOption(details);
2323
+ return this.fetch(fetchOption, fetchRequestOption, abortController);
2201
2324
  }
2202
2325
  else {
2203
- Reflect.deleteProperty(details, "fetchInit");
2326
+ // 使用GM_xmlHttpRequest请求
2204
2327
  return this.xmlHttpRequest(details);
2205
2328
  }
2206
2329
  },
@@ -2213,12 +2336,12 @@ class Httpx {
2213
2336
  },
2214
2337
  /**
2215
2338
  * 使用fetch发送请求
2216
- * @param details
2217
- * @param fetchRequestInit
2339
+ * @param option
2340
+ * @param fetchRequestOption
2218
2341
  * @param abortController
2219
2342
  */
2220
- fetch(details, fetchRequestInit, abortController) {
2221
- fetch(details.url, fetchRequestInit)
2343
+ fetch(option, fetchRequestOption, abortController) {
2344
+ fetch(option.url, fetchRequestOption)
2222
2345
  .then(async (fetchResponse) => {
2223
2346
  /** 自定义的response */
2224
2347
  let httpxResponse = {
@@ -2228,15 +2351,16 @@ class Httpx {
2228
2351
  // @ts-ignore
2229
2352
  status: fetchResponse.status,
2230
2353
  statusText: fetchResponse.statusText,
2354
+ // @ts-ignore
2231
2355
  response: void 0,
2232
2356
  responseFetchHeaders: fetchResponse.headers,
2233
2357
  responseHeaders: "",
2234
2358
  // @ts-ignore
2235
2359
  responseText: void 0,
2236
- responseType: details.responseType,
2360
+ responseType: option.responseType,
2237
2361
  responseXML: void 0,
2238
2362
  };
2239
- Object.assign(httpxResponse, details.context || {});
2363
+ Object.assign(httpxResponse, option.context || {});
2240
2364
  // 把headers转为字符串
2241
2365
  for (const [key, value] of fetchResponse.headers.entries()) {
2242
2366
  httpxResponse.responseHeaders += `${key}: ${value}\n`;
@@ -2244,7 +2368,7 @@ class Httpx {
2244
2368
  /** 请求返回的类型 */
2245
2369
  const fetchResponseType = fetchResponse.headers.get("Content-Type");
2246
2370
  /* 如果需要stream,且获取到的是stream,那直接返回 */
2247
- if (details.responseType === "stream" ||
2371
+ if (option.responseType === "stream" ||
2248
2372
  (fetchResponse.headers.has("Content-Type") &&
2249
2373
  fetchResponse.headers
2250
2374
  .get("Content-Type")
@@ -2253,7 +2377,7 @@ class Httpx {
2253
2377
  Reflect.set(httpxResponse, "response", fetchResponse.body);
2254
2378
  Reflect.deleteProperty(httpxResponse, "responseText");
2255
2379
  Reflect.deleteProperty(httpxResponse, "responseXML");
2256
- details.onload(httpxResponse);
2380
+ option.onload(httpxResponse);
2257
2381
  return;
2258
2382
  }
2259
2383
  /** 响应 */
@@ -2282,22 +2406,22 @@ class Httpx {
2282
2406
  let textDecoder = new TextDecoder(encoding);
2283
2407
  responseText = textDecoder.decode(arrayBuffer);
2284
2408
  response = responseText;
2285
- if (details.responseType === "arraybuffer") {
2409
+ if (option.responseType === "arraybuffer") {
2286
2410
  // response返回格式是二进制流
2287
2411
  response = arrayBuffer;
2288
2412
  }
2289
- else if (details.responseType === "blob") {
2413
+ else if (option.responseType === "blob") {
2290
2414
  // response返回格式是blob
2291
2415
  response = new Blob([arrayBuffer]);
2292
2416
  }
2293
- else if (details.responseType === "json" ||
2417
+ else if (option.responseType === "json" ||
2294
2418
  (typeof fetchResponseType === "string" &&
2295
2419
  fetchResponseType.includes("application/json"))) {
2296
2420
  // response返回格式是JSON格式
2297
2421
  response = utils.toJSON(responseText);
2298
2422
  }
2299
- else if (details.responseType === "document" ||
2300
- details.responseType == null) {
2423
+ else if (option.responseType === "document" ||
2424
+ option.responseType == null) {
2301
2425
  // response返回格式是文档格式
2302
2426
  let parser = new DOMParser();
2303
2427
  response = parser.parseFromString(responseText, "text/html");
@@ -2309,15 +2433,15 @@ class Httpx {
2309
2433
  Reflect.set(httpxResponse, "responseText", responseText);
2310
2434
  Reflect.set(httpxResponse, "responseXML", responseXML);
2311
2435
  // 执行回调
2312
- details.onload(httpxResponse);
2436
+ option.onload(httpxResponse);
2313
2437
  })
2314
2438
  .catch((error) => {
2315
2439
  if (error.name === "AbortError") {
2316
2440
  return;
2317
2441
  }
2318
- details.onerror({
2442
+ option.onerror({
2319
2443
  isFetch: true,
2320
- finalUrl: details.url,
2444
+ finalUrl: option.url,
2321
2445
  readyState: 4,
2322
2446
  status: 0,
2323
2447
  statusText: "",
@@ -2326,9 +2450,9 @@ class Httpx {
2326
2450
  error: error,
2327
2451
  });
2328
2452
  });
2329
- details.onloadstart({
2453
+ option.onloadstart({
2330
2454
  isFetch: true,
2331
- finalUrl: details.url,
2455
+ finalUrl: option.url,
2332
2456
  readyState: 1,
2333
2457
  responseHeaders: "",
2334
2458
  responseText: "",
@@ -2383,15 +2507,15 @@ class Httpx {
2383
2507
  #LOG_DETAILS = false;
2384
2508
  /**
2385
2509
  * 实例化,可传入GM_xmlhttpRequest,未传入则使用window.fetch
2386
- * @param __xmlHttpRequest__
2510
+ * @param xmlHttpRequest
2387
2511
  */
2388
- constructor(__xmlHttpRequest__) {
2389
- if (typeof __xmlHttpRequest__ !== "function") {
2512
+ constructor(xmlHttpRequest) {
2513
+ if (typeof xmlHttpRequest !== "function") {
2390
2514
  console.warn("[Httpx-constructor] 未传入GM_xmlhttpRequest函数或传入的GM_xmlhttpRequest不是Function,将默认使用window.fetch");
2391
2515
  }
2392
2516
  this.interceptors.request.context = this;
2393
2517
  this.interceptors.response.context = this;
2394
- this.GM_Api.xmlHttpRequest = __xmlHttpRequest__;
2518
+ this.GM_Api.xmlHttpRequest = xmlHttpRequest;
2395
2519
  }
2396
2520
  /**
2397
2521
  * 覆盖当前配置
@@ -2485,28 +2609,24 @@ class Httpx {
2485
2609
  */
2486
2610
  async get(...args // @ts-ignore
2487
2611
  ) {
2488
- let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
2612
+ let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
2489
2613
  let abortFn = null;
2490
- const promise = new Promise((resolve, reject) => {
2491
- let requestDetails = this.HttpxRequestDetails.getDetails("GET", details, resolve, reject);
2492
- Reflect.deleteProperty(requestDetails, "onprogress");
2493
- // @ts-ignore
2494
- requestDetails = this.HttpxRequestDetails.handle(requestDetails);
2495
- const requestResult = this.HttpxRequest.request(requestDetails);
2614
+ let promise = new globalThis.Promise((resolve, reject) => {
2615
+ let requestOption = this.HttpxRequestDetails.getRequestOption("GET", userRequestOption, resolve, reject);
2616
+ Reflect.deleteProperty(requestOption, "onprogress");
2617
+ this.HttpxRequestDetails.removeRequestNullOption(requestOption);
2618
+ const requestResult = this.HttpxRequest.request(requestOption);
2496
2619
  if (requestResult != null &&
2497
2620
  typeof requestResult.abort === "function") {
2498
2621
  abortFn = requestResult.abort;
2499
2622
  }
2500
2623
  });
2501
- Object.defineProperty(promise, "abort", {
2502
- value: () => {
2503
- return () => {
2504
- if (typeof abortFn === "function") {
2505
- abortFn();
2506
- }
2507
- };
2508
- },
2509
- });
2624
+ // @ts-ignore
2625
+ promise.abort = () => {
2626
+ if (typeof abortFn === "function") {
2627
+ abortFn();
2628
+ }
2629
+ };
2510
2630
  return promise;
2511
2631
  }
2512
2632
  /**
@@ -2514,27 +2634,25 @@ class Httpx {
2514
2634
  */
2515
2635
  async post(...args // @ts-ignore
2516
2636
  ) {
2517
- let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
2637
+ let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
2518
2638
  let abortFn = null;
2519
- const promise = new Promise((resolve, reject) => {
2520
- let requestDetails = this.HttpxRequestDetails.getDetails("POST", details, resolve, reject);
2639
+ let promise = new Promise((resolve, reject) => {
2640
+ let requestOption = this.HttpxRequestDetails.getRequestOption("POST", userRequestOption, resolve, reject);
2521
2641
  // @ts-ignore
2522
- requestDetails = this.HttpxRequestDetails.handle(requestDetails);
2523
- const requestResult = this.HttpxRequest.request(requestDetails);
2642
+ requestOption =
2643
+ this.HttpxRequestDetails.removeRequestNullOption(requestOption);
2644
+ const requestResult = this.HttpxRequest.request(requestOption);
2524
2645
  if (requestResult != null &&
2525
2646
  typeof requestResult.abort === "function") {
2526
2647
  abortFn = requestResult.abort;
2527
2648
  }
2528
2649
  });
2529
- Object.defineProperty(promise, "abort", {
2530
- value: () => {
2531
- return () => {
2532
- if (typeof abortFn === "function") {
2533
- abortFn();
2534
- }
2535
- };
2536
- },
2537
- });
2650
+ // @ts-ignore
2651
+ promise.abort = () => {
2652
+ if (typeof abortFn === "function") {
2653
+ abortFn();
2654
+ }
2655
+ };
2538
2656
  return promise;
2539
2657
  }
2540
2658
  /**
@@ -2542,28 +2660,26 @@ class Httpx {
2542
2660
  */
2543
2661
  async head(...args // @ts-ignore
2544
2662
  ) {
2545
- let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
2663
+ let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
2546
2664
  let abortFn = null;
2547
- const promise = new Promise((resolve, reject) => {
2548
- let requestDetails = this.HttpxRequestDetails.getDetails("HEAD", details, resolve, reject);
2549
- Reflect.deleteProperty(requestDetails, "onprogress");
2665
+ let promise = new Promise((resolve, reject) => {
2666
+ let requestOption = this.HttpxRequestDetails.getRequestOption("HEAD", userRequestOption, resolve, reject);
2667
+ Reflect.deleteProperty(requestOption, "onprogress");
2550
2668
  // @ts-ignore
2551
- requestDetails = this.HttpxRequestDetails.handle(requestDetails);
2552
- const requestResult = this.HttpxRequest.request(requestDetails);
2669
+ requestOption =
2670
+ this.HttpxRequestDetails.removeRequestNullOption(requestOption);
2671
+ const requestResult = this.HttpxRequest.request(requestOption);
2553
2672
  if (requestResult != null &&
2554
2673
  typeof requestResult.abort === "function") {
2555
2674
  abortFn = requestResult.abort;
2556
2675
  }
2557
2676
  });
2558
- Object.defineProperty(promise, "abort", {
2559
- value: () => {
2560
- return () => {
2561
- if (typeof abortFn === "function") {
2562
- abortFn();
2563
- }
2564
- };
2565
- },
2566
- });
2677
+ // @ts-ignore
2678
+ promise.abort = () => {
2679
+ if (typeof abortFn === "function") {
2680
+ abortFn();
2681
+ }
2682
+ };
2567
2683
  return promise;
2568
2684
  }
2569
2685
  /**
@@ -2571,28 +2687,26 @@ class Httpx {
2571
2687
  */
2572
2688
  async options(...args // @ts-ignore
2573
2689
  ) {
2574
- let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
2690
+ let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
2575
2691
  let abortFn = null;
2576
- const promise = new Promise((resolve, reject) => {
2577
- let requestDetails = this.HttpxRequestDetails.getDetails("OPTIONS", details, resolve, reject);
2578
- Reflect.deleteProperty(requestDetails, "onprogress");
2692
+ let promise = new Promise((resolve, reject) => {
2693
+ let requestOption = this.HttpxRequestDetails.getRequestOption("OPTIONS", userRequestOption, resolve, reject);
2694
+ Reflect.deleteProperty(requestOption, "onprogress");
2579
2695
  // @ts-ignore
2580
- requestDetails = this.HttpxRequestDetails.handle(requestDetails);
2581
- const requestResult = this.HttpxRequest.request(requestDetails);
2696
+ requestOption =
2697
+ this.HttpxRequestDetails.removeRequestNullOption(requestOption);
2698
+ const requestResult = this.HttpxRequest.request(requestOption);
2582
2699
  if (requestResult != null &&
2583
2700
  typeof requestResult.abort === "function") {
2584
2701
  abortFn = requestResult.abort;
2585
2702
  }
2586
2703
  });
2587
- Object.defineProperty(promise, "abort", {
2588
- value: () => {
2589
- return () => {
2590
- if (typeof abortFn === "function") {
2591
- abortFn();
2592
- }
2593
- };
2594
- },
2595
- });
2704
+ // @ts-ignore
2705
+ promise.abort = () => {
2706
+ if (typeof abortFn === "function") {
2707
+ abortFn();
2708
+ }
2709
+ };
2596
2710
  return promise;
2597
2711
  }
2598
2712
  /**
@@ -2600,28 +2714,26 @@ class Httpx {
2600
2714
  */
2601
2715
  async delete(...args // @ts-ignore
2602
2716
  ) {
2603
- let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
2717
+ let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
2604
2718
  let abortFn = null;
2605
- const promise = new Promise((resolve, reject) => {
2606
- let requestDetails = this.HttpxRequestDetails.getDetails("DELETE", details, resolve, reject);
2607
- Reflect.deleteProperty(requestDetails, "onprogress");
2719
+ let promise = new Promise((resolve, reject) => {
2720
+ let requestOption = this.HttpxRequestDetails.getRequestOption("DELETE", userRequestOption, resolve, reject);
2721
+ Reflect.deleteProperty(requestOption, "onprogress");
2608
2722
  // @ts-ignore
2609
- requestDetails = this.HttpxRequestDetails.handle(requestDetails);
2610
- const requestResult = this.HttpxRequest.request(requestDetails);
2723
+ requestOption =
2724
+ this.HttpxRequestDetails.removeRequestNullOption(requestOption);
2725
+ const requestResult = this.HttpxRequest.request(requestOption);
2611
2726
  if (requestResult != null &&
2612
2727
  typeof requestResult.abort === "function") {
2613
2728
  abortFn = requestResult.abort;
2614
2729
  }
2615
2730
  });
2616
- Object.defineProperty(promise, "abort", {
2617
- value: () => {
2618
- return () => {
2619
- if (typeof abortFn === "function") {
2620
- abortFn();
2621
- }
2622
- };
2623
- },
2624
- });
2731
+ // @ts-ignore
2732
+ promise.abort = () => {
2733
+ if (typeof abortFn === "function") {
2734
+ abortFn();
2735
+ }
2736
+ };
2625
2737
  return promise;
2626
2738
  }
2627
2739
  /**
@@ -2629,27 +2741,25 @@ class Httpx {
2629
2741
  */
2630
2742
  async put(...args // @ts-ignore
2631
2743
  ) {
2632
- let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
2744
+ let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
2633
2745
  let abortFn = null;
2634
- const promise = new Promise((resolve, reject) => {
2635
- let requestDetails = this.HttpxRequestDetails.getDetails("PUT", details, resolve, reject);
2746
+ let promise = new Promise((resolve, reject) => {
2747
+ let requestOption = this.HttpxRequestDetails.getRequestOption("PUT", userRequestOption, resolve, reject);
2636
2748
  // @ts-ignore
2637
- requestDetails = this.HttpxRequestDetails.handle(requestDetails);
2638
- const requestResult = this.HttpxRequest.request(requestDetails);
2749
+ requestOption =
2750
+ this.HttpxRequestDetails.removeRequestNullOption(requestOption);
2751
+ const requestResult = this.HttpxRequest.request(requestOption);
2639
2752
  if (requestResult != null &&
2640
2753
  typeof requestResult.abort === "function") {
2641
2754
  abortFn = requestResult.abort;
2642
2755
  }
2643
2756
  });
2644
- Object.defineProperty(promise, "abort", {
2645
- value: () => {
2646
- return () => {
2647
- if (typeof abortFn === "function") {
2648
- abortFn();
2649
- }
2650
- };
2651
- },
2652
- });
2757
+ // @ts-ignore
2758
+ promise.abort = () => {
2759
+ if (typeof abortFn === "function") {
2760
+ abortFn();
2761
+ }
2762
+ };
2653
2763
  return promise;
2654
2764
  }
2655
2765
  }
@@ -2680,6 +2790,10 @@ class indexedDB {
2680
2790
  code: 401,
2681
2791
  msg: "操作失败",
2682
2792
  },
2793
+ empty: {
2794
+ code: 201,
2795
+ msg: "操作成功,但是没有数据",
2796
+ },
2683
2797
  openFailed: { code: 91001, msg: "打开数据库失败" },
2684
2798
  saveFailed: { code: 91002, msg: "保存数据失败" },
2685
2799
  getFailed: { code: 91003, msg: "获取数据失败" },
@@ -2868,11 +2982,11 @@ class indexedDB {
2868
2982
  /* result 返回的是 {key: string, value: any} */
2869
2983
  /* 键值对存储 */
2870
2984
  let data = result ? result.value : void 0;
2871
- if (data) {
2985
+ if (data == null) {
2872
2986
  resolve({
2873
2987
  success: true,
2874
- code: that.#statusCode.operationSuccess.code,
2875
- msg: that.#statusCode.operationSuccess.msg,
2988
+ code: that.#statusCode.empty.code,
2989
+ msg: that.#statusCode.empty.msg,
2876
2990
  data: data,
2877
2991
  event: event,
2878
2992
  result: result,
@@ -2880,10 +2994,10 @@ class indexedDB {
2880
2994
  }
2881
2995
  else {
2882
2996
  resolve({
2883
- success: false,
2884
- code: that.#statusCode.operationFailed.code,
2885
- msg: that.#statusCode.operationFailed.msg,
2886
- data: void 0,
2997
+ success: true,
2998
+ code: that.#statusCode.operationSuccess.code,
2999
+ msg: that.#statusCode.operationSuccess.msg,
3000
+ data: data,
2887
3001
  event: event,
2888
3002
  result: result,
2889
3003
  });
@@ -3950,7 +4064,7 @@ class Utils {
3950
4064
  this.windowApi = new WindowApi(option);
3951
4065
  }
3952
4066
  /** 版本号 */
3953
- version = "2024.10.19";
4067
+ version = "2024.10.28";
3954
4068
  addStyle(cssText) {
3955
4069
  if (typeof cssText !== "string") {
3956
4070
  throw new Error("Utils.addStyle 参数cssText 必须为String类型");
@@ -4097,22 +4211,33 @@ class Utils {
4097
4211
  if (!UtilsContext.isDOM(element)) {
4098
4212
  throw new Error("Utils.checkUserClickInNode 参数 targetNode 必须为 Element|Node 类型");
4099
4213
  }
4100
- let mouseClickPosX = Number(window.event.clientX.toString()); /* 鼠标相对屏幕横坐标 */
4101
- let mouseClickPosY = Number(window.event.clientY.toString()); /* 鼠标相对屏幕纵坐标 */
4102
- let elementPosXLeft = Number(element.getBoundingClientRect().left); /* 要检测的元素的相对屏幕的横坐标最左边 */
4103
- let elementPosXRight = Number(element.getBoundingClientRect().right); /* 要检测的元素的相对屏幕的横坐标最右边 */
4104
- let elementPosYTop = Number(element.getBoundingClientRect().top); /* 要检测的元素的相对屏幕的纵坐标最上边 */
4105
- let elementPosYBottom = Number(element.getBoundingClientRect().bottom); /* 要检测的元素的相对屏幕的纵坐标最下边 */
4106
- let clickNodeHTML = this.windowApi.window.event.target
4107
- .innerHTML;
4108
- if (mouseClickPosX >= elementPosXLeft &&
4109
- mouseClickPosX <= elementPosXRight &&
4110
- mouseClickPosY >= elementPosYTop &&
4111
- mouseClickPosY <= elementPosYBottom) {
4214
+ let clickEvent = UtilsContext.windowApi.window.event;
4215
+ let touchEvent = UtilsContext.windowApi.window.event;
4216
+ let $click = clickEvent?.composedPath()?.[0];
4217
+ // 点击的x坐标
4218
+ let clickPosX = clickEvent?.clientX != null
4219
+ ? clickEvent.clientX
4220
+ : touchEvent.touches[0].clientX;
4221
+ // 点击的y坐标
4222
+ let clickPosY = clickEvent?.clientY != null
4223
+ ? clickEvent.clientY
4224
+ : touchEvent.touches[0].clientY;
4225
+ let {
4226
+ /* 要检测的元素的相对屏幕的横坐标最左边 */
4227
+ left: elementPosXLeft,
4228
+ /* 要检测的元素的相对屏幕的横坐标最右边 */
4229
+ right: elementPosXRight,
4230
+ /* 要检测的元素的相对屏幕的纵坐标最上边 */
4231
+ top: elementPosYTop,
4232
+ /* 要检测的元素的相对屏幕的纵坐标最下边 */
4233
+ bottom: elementPosYBottom, } = element.getBoundingClientRect();
4234
+ if (clickPosX >= elementPosXLeft &&
4235
+ clickPosX <= elementPosXRight &&
4236
+ clickPosY >= elementPosYTop &&
4237
+ clickPosY <= elementPosYBottom) {
4112
4238
  return true;
4113
4239
  }
4114
- else if (clickNodeHTML &&
4115
- element.innerHTML.includes(clickNodeHTML)) {
4240
+ else if (($click && element.contains($click)) || $click == element) {
4116
4241
  /* 这种情况是应对在界面中隐藏的元素,getBoundingClientRect获取的都是0 */
4117
4242
  return true;
4118
4243
  }
@@ -6170,7 +6295,8 @@ class Utils {
6170
6295
  dragSlider(selector, offsetX = this.windowApi.window.innerWidth) {
6171
6296
  let UtilsContext = this;
6172
6297
  function initMouseEvent(eventName, offSetX, offSetY) {
6173
- let win = unsafeWindow || window;
6298
+ // @ts-ignore
6299
+ let win = typeof unsafeWindow === "undefined" ? globalThis : unsafeWindow;
6174
6300
  let mouseEvent = UtilsContext.windowApi.document.createEvent("MouseEvents");
6175
6301
  mouseEvent.initMouseEvent(eventName, true, true, win, 0, offSetX, offSetY, offSetX, offSetY, false, false, false, false, 0, null);
6176
6302
  return mouseEvent;