@base-web-kits/base-tools-web 1.1.6 → 1.1.10

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.
@@ -2,10 +2,27 @@
2
2
  var baseToolsWeb = (() => {
3
3
  var __create = Object.create;
4
4
  var __defProp = Object.defineProperty;
5
+ var __defProps = Object.defineProperties;
5
6
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
8
  var __getOwnPropNames = Object.getOwnPropertyNames;
9
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
10
  var __getProtoOf = Object.getPrototypeOf;
8
11
  var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
13
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14
+ var __spreadValues = (a, b) => {
15
+ for (var prop in b || (b = {}))
16
+ if (__hasOwnProp.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ if (__getOwnPropSymbols)
19
+ for (var prop of __getOwnPropSymbols(b)) {
20
+ if (__propIsEnum.call(b, prop))
21
+ __defNormalProp(a, prop, b[prop]);
22
+ }
23
+ return a;
24
+ };
25
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
9
26
  var __commonJS = (cb, mod) => function __require() {
10
27
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
11
28
  };
@@ -30,6 +47,26 @@ var baseToolsWeb = (() => {
30
47
  mod
31
48
  ));
32
49
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
50
+ var __async = (__this, __arguments, generator) => {
51
+ return new Promise((resolve, reject) => {
52
+ var fulfilled = (value) => {
53
+ try {
54
+ step(generator.next(value));
55
+ } catch (e) {
56
+ reject(e);
57
+ }
58
+ };
59
+ var rejected = (value) => {
60
+ try {
61
+ step(generator.throw(value));
62
+ } catch (e) {
63
+ reject(e);
64
+ }
65
+ };
66
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
67
+ step((generator = generator.apply(__this, __arguments)).next());
68
+ });
69
+ };
33
70
 
34
71
  // node_modules/.pnpm/dayjs@1.11.19/node_modules/dayjs/dayjs.min.js
35
72
  var require_dayjs_min = __commonJS({
@@ -761,160 +798,180 @@ var baseToolsWeb = (() => {
761
798
  });
762
799
 
763
800
  // src/web/clipboard/index.ts
764
- async function copyText(text) {
765
- if (typeof text !== "string") text = String(text ?? "");
766
- if (navigator.clipboard && typeof navigator.clipboard.writeText === "function") {
767
- try {
768
- await navigator.clipboard.writeText(text);
769
- return;
770
- } catch (e) {
801
+ function copyText(text) {
802
+ return __async(this, null, function* () {
803
+ if (typeof text !== "string") text = String(text != null ? text : "");
804
+ if (navigator.clipboard && typeof navigator.clipboard.writeText === "function") {
805
+ try {
806
+ yield navigator.clipboard.writeText(text);
807
+ return;
808
+ } catch (e) {
809
+ }
771
810
  }
772
- }
773
- return new Promise((resolve, reject) => {
774
- try {
775
- const textarea = document.createElement("textarea");
776
- textarea.value = text;
777
- textarea.setAttribute("readonly", "");
778
- textarea.style.position = "fixed";
779
- textarea.style.top = "0";
780
- textarea.style.right = "-9999px";
781
- textarea.style.opacity = "0";
782
- textarea.style.pointerEvents = "none";
783
- document.body.appendChild(textarea);
784
- textarea.focus();
785
- textarea.select();
786
- textarea.setSelectionRange(0, textarea.value.length);
787
- const ok = document.execCommand("copy");
788
- document.body.removeChild(textarea);
789
- if (ok) {
790
- resolve();
791
- } else {
792
- reject(new Error("Copy failed: clipboard unavailable"));
811
+ return new Promise((resolve, reject) => {
812
+ try {
813
+ const textarea = document.createElement("textarea");
814
+ textarea.value = text;
815
+ textarea.setAttribute("readonly", "");
816
+ textarea.style.position = "fixed";
817
+ textarea.style.top = "0";
818
+ textarea.style.right = "-9999px";
819
+ textarea.style.opacity = "0";
820
+ textarea.style.pointerEvents = "none";
821
+ document.body.appendChild(textarea);
822
+ textarea.focus();
823
+ textarea.select();
824
+ textarea.setSelectionRange(0, textarea.value.length);
825
+ const ok = document.execCommand("copy");
826
+ document.body.removeChild(textarea);
827
+ if (ok) {
828
+ resolve();
829
+ } else {
830
+ reject(new Error("Copy failed: clipboard unavailable"));
831
+ }
832
+ } catch (e) {
833
+ reject(e);
793
834
  }
794
- } catch (e) {
795
- reject(e);
835
+ });
836
+ });
837
+ }
838
+ function copyHtml(html) {
839
+ return __async(this, null, function* () {
840
+ const s = String(html != null ? html : "");
841
+ if (canWriteClipboard()) {
842
+ const plain = htmlToText(s);
843
+ yield writeClipboard({
844
+ "text/html": new Blob([s], { type: "text/html" }),
845
+ "text/plain": new Blob([plain], { type: "text/plain" })
846
+ });
847
+ return;
796
848
  }
849
+ return execCopyFromHtml(s);
797
850
  });
798
851
  }
799
- async function copyHtml(html) {
800
- const s = String(html ?? "");
801
- if (canWriteClipboard()) {
802
- const plain = htmlToText(s);
803
- await writeClipboard({
804
- "text/html": new Blob([s], { type: "text/html" }),
805
- "text/plain": new Blob([plain], { type: "text/plain" })
806
- });
807
- return;
808
- }
809
- return execCopyFromHtml(s);
852
+ function copyNode(node) {
853
+ return __async(this, null, function* () {
854
+ if (canWriteClipboard()) {
855
+ const { html: html2, text } = nodeToHtmlText(node);
856
+ yield writeClipboard({
857
+ "text/html": new Blob([html2], { type: "text/html" }),
858
+ "text/plain": new Blob([text], { type: "text/plain" })
859
+ });
860
+ return;
861
+ }
862
+ const { html } = nodeToHtmlText(node);
863
+ return execCopyFromHtml(html);
864
+ });
810
865
  }
811
- async function copyNode(node) {
812
- if (canWriteClipboard()) {
813
- const { html: html2, text } = nodeToHtmlText(node);
814
- await writeClipboard({
815
- "text/html": new Blob([html2], { type: "text/html" }),
816
- "text/plain": new Blob([text], { type: "text/plain" })
817
- });
818
- return;
819
- }
820
- const { html } = nodeToHtmlText(node);
821
- return execCopyFromHtml(html);
866
+ function copyImage(image) {
867
+ return __async(this, null, function* () {
868
+ const blob = yield toImageBlob(image);
869
+ if (!blob) throw new Error("Unsupported image source");
870
+ if (canWriteClipboard()) {
871
+ const type = blob.type || "image/png";
872
+ yield writeClipboard({ [type]: blob });
873
+ return;
874
+ }
875
+ throw new Error("Clipboard image write not supported");
876
+ });
822
877
  }
823
- async function copyImage(image) {
824
- const blob = await toImageBlob(image);
825
- if (!blob) throw new Error("Unsupported image source");
826
- if (canWriteClipboard()) {
827
- const type = blob.type || "image/png";
828
- await writeClipboard({ [type]: blob });
829
- return;
830
- }
831
- throw new Error("Clipboard image write not supported");
878
+ function copyUrl(url) {
879
+ return __async(this, null, function* () {
880
+ const s = String(url != null ? url : "");
881
+ if (canWriteClipboard()) {
882
+ yield writeClipboard({
883
+ "text/uri-list": new Blob([s], { type: "text/uri-list" }),
884
+ "text/plain": new Blob([s], { type: "text/plain" })
885
+ });
886
+ return;
887
+ }
888
+ yield copyText(s);
889
+ });
832
890
  }
833
- async function copyUrl(url) {
834
- const s = String(url ?? "");
835
- if (canWriteClipboard()) {
836
- await writeClipboard({
837
- "text/uri-list": new Blob([s], { type: "text/uri-list" }),
838
- "text/plain": new Blob([s], { type: "text/plain" })
839
- });
840
- return;
841
- }
842
- await copyText(s);
891
+ function copyBlob(blob) {
892
+ return __async(this, null, function* () {
893
+ if (canWriteClipboard()) {
894
+ const type = blob.type || "application/octet-stream";
895
+ yield writeClipboard({ [type]: blob });
896
+ return;
897
+ }
898
+ throw new Error("Clipboard blob write not supported");
899
+ });
843
900
  }
844
- async function copyBlob(blob) {
845
- if (canWriteClipboard()) {
846
- const type = blob.type || "application/octet-stream";
847
- await writeClipboard({ [type]: blob });
848
- return;
849
- }
850
- throw new Error("Clipboard blob write not supported");
901
+ function copyRtf(rtf) {
902
+ return __async(this, null, function* () {
903
+ const s = String(rtf != null ? rtf : "");
904
+ if (canWriteClipboard()) {
905
+ const plain = s.replace(/\\par[\s]?/g, "\n").replace(/\{[^}]*\}/g, "").replace(/\\[a-zA-Z]+[0-9'-]*/g, "").replace(/\r?\n/g, "\n").trim();
906
+ yield writeClipboard({
907
+ "text/rtf": new Blob([s], { type: "text/rtf" }),
908
+ "text/plain": new Blob([plain], { type: "text/plain" })
909
+ });
910
+ return;
911
+ }
912
+ yield copyText(s);
913
+ });
851
914
  }
852
- async function copyRtf(rtf) {
853
- const s = String(rtf ?? "");
854
- if (canWriteClipboard()) {
855
- const plain = s.replace(/\\par[\s]?/g, "\n").replace(/\{[^}]*\}/g, "").replace(/\\[a-zA-Z]+[0-9'-]*/g, "").replace(/\r?\n/g, "\n").trim();
856
- await writeClipboard({
857
- "text/rtf": new Blob([s], { type: "text/rtf" }),
858
- "text/plain": new Blob([plain], { type: "text/plain" })
859
- });
860
- return;
861
- }
862
- await copyText(s);
863
- }
864
- async function copyTable(rows) {
865
- const data = Array.isArray(rows) ? rows : [];
866
- const escapeHtml = (t) => t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
867
- const html = (() => {
868
- const trs = data.map((r) => `<tr>${r.map((c) => `<td>${escapeHtml(String(c))}</td>`).join("")}</tr>`).join("");
869
- return `<table>${trs}</table>`;
870
- })();
871
- const tsv = data.map((r) => r.map((c) => String(c)).join(" ")).join("\n");
872
- const csv = data.map(
873
- (r) => r.map((c) => {
874
- const s = String(c);
875
- const needQuote = /[",\n]/.test(s);
876
- const escaped = s.replace(/"/g, '""');
877
- return needQuote ? `"${escaped}"` : escaped;
878
- }).join(",")
879
- ).join("\n");
880
- if (canWriteClipboard()) {
881
- await writeClipboard({
882
- "text/html": new Blob([html], { type: "text/html" }),
883
- "text/tab-separated-values": new Blob([tsv], { type: "text/tab-separated-values" }),
884
- "text/csv": new Blob([csv], { type: "text/csv" }),
885
- "text/plain": new Blob([tsv], { type: "text/plain" })
886
- });
887
- return;
888
- }
889
- await copyText(tsv);
915
+ function copyTable(rows) {
916
+ return __async(this, null, function* () {
917
+ const data = Array.isArray(rows) ? rows : [];
918
+ const escapeHtml = (t) => t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
919
+ const html = (() => {
920
+ const trs = data.map((r) => `<tr>${r.map((c) => `<td>${escapeHtml(String(c))}</td>`).join("")}</tr>`).join("");
921
+ return `<table>${trs}</table>`;
922
+ })();
923
+ const tsv = data.map((r) => r.map((c) => String(c)).join(" ")).join("\n");
924
+ const csv = data.map(
925
+ (r) => r.map((c) => {
926
+ const s = String(c);
927
+ const needQuote = /[",\n]/.test(s);
928
+ const escaped = s.replace(/"/g, '""');
929
+ return needQuote ? `"${escaped}"` : escaped;
930
+ }).join(",")
931
+ ).join("\n");
932
+ if (canWriteClipboard()) {
933
+ yield writeClipboard({
934
+ "text/html": new Blob([html], { type: "text/html" }),
935
+ "text/tab-separated-values": new Blob([tsv], { type: "text/tab-separated-values" }),
936
+ "text/csv": new Blob([csv], { type: "text/csv" }),
937
+ "text/plain": new Blob([tsv], { type: "text/plain" })
938
+ });
939
+ return;
940
+ }
941
+ yield copyText(tsv);
942
+ });
890
943
  }
891
- async function toImageBlob(image) {
892
- if (image instanceof Blob) return image;
893
- if (image instanceof HTMLCanvasElement)
894
- return await new Promise((resolve, reject) => {
895
- image.toBlob(
896
- (b) => b ? resolve(b) : reject(new Error("Canvas toBlob failed")),
897
- "image/png"
898
- );
899
- });
900
- const isBitmap = typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap;
901
- if (isBitmap) {
902
- const cnv = document.createElement("canvas");
903
- cnv.width = image.width;
904
- cnv.height = image.height;
905
- const ctx = cnv.getContext("2d");
906
- ctx?.drawImage(image, 0, 0);
907
- return await new Promise((resolve, reject) => {
908
- cnv.toBlob((b) => b ? resolve(b) : reject(new Error("Canvas toBlob failed")), "image/png");
909
- });
910
- }
911
- return null;
944
+ function toImageBlob(image) {
945
+ return __async(this, null, function* () {
946
+ if (image instanceof Blob) return image;
947
+ if (image instanceof HTMLCanvasElement)
948
+ return yield new Promise((resolve, reject) => {
949
+ image.toBlob(
950
+ (b) => b ? resolve(b) : reject(new Error("Canvas toBlob failed")),
951
+ "image/png"
952
+ );
953
+ });
954
+ const isBitmap = typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap;
955
+ if (isBitmap) {
956
+ const cnv = document.createElement("canvas");
957
+ cnv.width = image.width;
958
+ cnv.height = image.height;
959
+ const ctx = cnv.getContext("2d");
960
+ ctx == null ? void 0 : ctx.drawImage(image, 0, 0);
961
+ return yield new Promise((resolve, reject) => {
962
+ cnv.toBlob((b) => b ? resolve(b) : reject(new Error("Canvas toBlob failed")), "image/png");
963
+ });
964
+ }
965
+ return null;
966
+ });
912
967
  }
913
968
  function canWriteClipboard() {
914
969
  return !!(navigator.clipboard && typeof navigator.clipboard.write === "function" && typeof ClipboardItem !== "undefined");
915
970
  }
916
- async function writeClipboard(items) {
917
- await navigator.clipboard.write([new ClipboardItem(items)]);
971
+ function writeClipboard(items) {
972
+ return __async(this, null, function* () {
973
+ yield navigator.clipboard.write([new ClipboardItem(items)]);
974
+ });
918
975
  }
919
976
  function htmlToText(html) {
920
977
  const div = document.createElement("div");
@@ -922,9 +979,10 @@ var baseToolsWeb = (() => {
922
979
  return div.textContent || "";
923
980
  }
924
981
  function nodeToHtmlText(node) {
982
+ var _a;
925
983
  const container = document.createElement("div");
926
984
  container.appendChild(node.cloneNode(true));
927
- const html = node instanceof Element ? node.outerHTML ?? container.innerHTML : container.innerHTML;
985
+ const html = node instanceof Element ? (_a = node.outerHTML) != null ? _a : container.innerHTML : container.innerHTML;
928
986
  const text = container.textContent || "";
929
987
  return { html, text };
930
988
  }
@@ -943,11 +1001,11 @@ var baseToolsWeb = (() => {
943
1001
  const selection = window.getSelection();
944
1002
  const range = document.createRange();
945
1003
  range.selectNodeContents(div);
946
- selection?.removeAllRanges();
947
- selection?.addRange(range);
1004
+ selection == null ? void 0 : selection.removeAllRanges();
1005
+ selection == null ? void 0 : selection.addRange(range);
948
1006
  const ok = document.execCommand("copy");
949
1007
  document.body.removeChild(div);
950
- selection?.removeAllRanges();
1008
+ selection == null ? void 0 : selection.removeAllRanges();
951
1009
  if (ok) {
952
1010
  resolve();
953
1011
  } else {
@@ -976,10 +1034,11 @@ var baseToolsWeb = (() => {
976
1034
  document.cookie = `${name}=${encodeURIComponent(value)}; ${expires}`;
977
1035
  }
978
1036
  function getCookie(name) {
1037
+ var _a;
979
1038
  const value = `; ${document.cookie}`;
980
1039
  const parts = value.split(`; ${name}=`);
981
1040
  if (parts.length === 2) {
982
- const v = parts.pop()?.split(";").shift();
1041
+ const v = (_a = parts.pop()) == null ? void 0 : _a.split(";").shift();
983
1042
  return v ? decodeURIComponent(v) : null;
984
1043
  }
985
1044
  return null;
@@ -1123,80 +1182,87 @@ var baseToolsWeb = (() => {
1123
1182
  }
1124
1183
 
1125
1184
  // src/web/network/load.ts
1126
- async function download(url, fileName = "") {
1127
- if (!url) return;
1128
- let blobUrl = "";
1129
- let needRevoke = false;
1130
- try {
1131
- if (url instanceof Blob) {
1132
- blobUrl = URL.createObjectURL(url);
1133
- needRevoke = true;
1134
- } else if (url.includes(";base64,")) {
1135
- blobUrl = url;
1136
- } else {
1137
- if (fileName) {
1138
- const res = await fetch(url);
1139
- if (!res.ok) throw new Error(`fetch error ${res.status}\uFF1A${url}`);
1140
- const blob = await res.blob();
1141
- blobUrl = URL.createObjectURL(blob);
1185
+ function download(url, fileName = "") {
1186
+ return __async(this, null, function* () {
1187
+ if (!url) return;
1188
+ let blobUrl = "";
1189
+ let needRevoke = false;
1190
+ try {
1191
+ if (url instanceof Blob) {
1192
+ blobUrl = URL.createObjectURL(url);
1142
1193
  needRevoke = true;
1143
- } else {
1194
+ } else if (url.includes(";base64,")) {
1144
1195
  blobUrl = url;
1196
+ } else {
1197
+ if (fileName) {
1198
+ const res = yield fetch(url);
1199
+ if (!res.ok) throw new Error(`fetch error ${res.status}\uFF1A${url}`);
1200
+ const blob = yield res.blob();
1201
+ blobUrl = URL.createObjectURL(blob);
1202
+ needRevoke = true;
1203
+ } else {
1204
+ blobUrl = url;
1205
+ }
1206
+ }
1207
+ const a = document.createElement("a");
1208
+ a.href = blobUrl;
1209
+ a.download = fileName;
1210
+ document.body.appendChild(a);
1211
+ a.click();
1212
+ document.body.removeChild(a);
1213
+ } finally {
1214
+ if (needRevoke) {
1215
+ setTimeout(() => URL.revokeObjectURL(blobUrl), 100);
1145
1216
  }
1146
1217
  }
1147
- const a = document.createElement("a");
1148
- a.href = blobUrl;
1149
- a.download = fileName;
1150
- document.body.appendChild(a);
1151
- a.click();
1152
- document.body.removeChild(a);
1153
- } finally {
1154
- if (needRevoke) {
1155
- setTimeout(() => URL.revokeObjectURL(blobUrl), 100);
1156
- }
1157
- }
1218
+ });
1158
1219
  }
1159
- async function parseAxiosBlob(res) {
1160
- const { data, headers, status, statusText, config } = res;
1161
- if (status < 200 || status >= 300) throw new Error(`${status}\uFF0C${statusText}\uFF1A${config.url}`);
1162
- if (data.type.includes("application/json")) {
1163
- const txt = await data.text();
1164
- throw JSON.parse(txt);
1165
- }
1166
- const fileName = getDispositionFileName(headers["content-disposition"]);
1167
- return { blob: data, fileName };
1220
+ function parseAxiosBlob(res) {
1221
+ return __async(this, null, function* () {
1222
+ const { data, headers, status, statusText, config } = res;
1223
+ if (status < 200 || status >= 300) throw new Error(`${status}\uFF0C${statusText}\uFF1A${config.url}`);
1224
+ if (data.type.includes("application/json")) {
1225
+ const txt = yield data.text();
1226
+ throw JSON.parse(txt);
1227
+ }
1228
+ const fileName = getDispositionFileName(headers["content-disposition"]);
1229
+ return { blob: data, fileName };
1230
+ });
1168
1231
  }
1169
1232
  function getDispositionFileName(disposition) {
1233
+ var _a;
1170
1234
  if (!disposition) return "";
1171
1235
  const rfc5987 = /filename\*\s*=\s*([^']*)''([^;]*)/i.exec(disposition);
1172
- if (rfc5987?.[2]) {
1236
+ if (rfc5987 == null ? void 0 : rfc5987[2]) {
1173
1237
  try {
1174
1238
  return decodeURIComponent(rfc5987[2].trim()).replace(/[\r\n]+/g, "");
1175
- } catch {
1239
+ } catch (e) {
1176
1240
  return rfc5987[2].trim().replace(/[\r\n]+/g, "");
1177
1241
  }
1178
1242
  }
1179
1243
  const old = /filename\s*=\s*(?:"([^"]*)"|([^";]*))(?=;|$)/i.exec(disposition);
1180
- if (old) return (old[1] ?? old[2]).trim().replace(/[\r\n]+/g, "");
1244
+ if (old) return ((_a = old[1]) != null ? _a : old[2]).trim().replace(/[\r\n]+/g, "");
1181
1245
  return "";
1182
1246
  }
1183
- async function loadJs(src, attrs) {
1184
- return new Promise((resolve, reject) => {
1185
- if (hasJs(src)) return resolve();
1186
- const script = document.createElement("script");
1187
- script.type = "text/javascript";
1188
- script.src = src;
1189
- if (attrs) {
1190
- const keys = Object.keys(attrs);
1191
- keys.forEach((key) => {
1192
- const v = attrs[key];
1193
- if (v === null || v === void 0 || v === false) return;
1194
- script.setAttribute(key, typeof v === "boolean" ? "" : v);
1195
- });
1196
- }
1197
- script.onload = () => resolve();
1198
- script.onerror = (e) => reject(e);
1199
- document.head.appendChild(script);
1247
+ function loadJs(src, attrs) {
1248
+ return __async(this, null, function* () {
1249
+ return new Promise((resolve, reject) => {
1250
+ if (hasJs(src)) return resolve();
1251
+ const script = document.createElement("script");
1252
+ script.type = "text/javascript";
1253
+ script.src = src;
1254
+ if (attrs) {
1255
+ const keys = Object.keys(attrs);
1256
+ keys.forEach((key) => {
1257
+ const v = attrs[key];
1258
+ if (v === null || v === void 0 || v === false) return;
1259
+ script.setAttribute(key, typeof v === "boolean" ? "" : v);
1260
+ });
1261
+ }
1262
+ script.onload = () => resolve();
1263
+ script.onerror = (e) => reject(e);
1264
+ document.head.appendChild(script);
1265
+ });
1200
1266
  });
1201
1267
  }
1202
1268
  function hasJs(src) {
@@ -1207,23 +1273,25 @@ var baseToolsWeb = (() => {
1207
1273
  return src2 && new URL(src2, document.baseURI).href === target;
1208
1274
  });
1209
1275
  }
1210
- async function loadCss(href, attrs) {
1211
- return new Promise((resolve, reject) => {
1212
- if (hasCss(href)) return resolve();
1213
- const link = document.createElement("link");
1214
- link.rel = "stylesheet";
1215
- link.href = href;
1216
- if (attrs) {
1217
- const keys = Object.keys(attrs);
1218
- keys.forEach((key) => {
1219
- const v = attrs[key];
1220
- if (v === null || v === void 0) return;
1221
- link.setAttribute(key, String(v));
1222
- });
1223
- }
1224
- link.onload = () => resolve();
1225
- link.onerror = (e) => reject(e);
1226
- document.head.appendChild(link);
1276
+ function loadCss(href, attrs) {
1277
+ return __async(this, null, function* () {
1278
+ return new Promise((resolve, reject) => {
1279
+ if (hasCss(href)) return resolve();
1280
+ const link = document.createElement("link");
1281
+ link.rel = "stylesheet";
1282
+ link.href = href;
1283
+ if (attrs) {
1284
+ const keys = Object.keys(attrs);
1285
+ keys.forEach((key) => {
1286
+ const v = attrs[key];
1287
+ if (v === null || v === void 0) return;
1288
+ link.setAttribute(key, String(v));
1289
+ });
1290
+ }
1291
+ link.onload = () => resolve();
1292
+ link.onerror = (e) => reject(e);
1293
+ document.head.appendChild(link);
1294
+ });
1227
1295
  });
1228
1296
  }
1229
1297
  function hasCss(href) {
@@ -1327,7 +1395,7 @@ var baseToolsWeb = (() => {
1327
1395
 
1328
1396
  // node_modules/.pnpm/es-toolkit@1.42.0/node_modules/es-toolkit/dist/object/cloneDeepWith.mjs
1329
1397
  function cloneDeepWithImpl(valueToClone, keyToClone, objectToClone, stack = /* @__PURE__ */ new Map(), cloneValue = void 0) {
1330
- const cloned = cloneValue?.(valueToClone, keyToClone, objectToClone, stack);
1398
+ const cloned = cloneValue == null ? void 0 : cloneValue(valueToClone, keyToClone, objectToClone, stack);
1331
1399
  if (cloned !== void 0) {
1332
1400
  return cloned;
1333
1401
  }
@@ -1539,10 +1607,11 @@ var baseToolsWeb = (() => {
1539
1607
 
1540
1608
  // node_modules/.pnpm/es-toolkit@1.42.0/node_modules/es-toolkit/dist/compat/_internal/toKey.mjs
1541
1609
  function toKey(value) {
1610
+ var _a;
1542
1611
  if (typeof value === "string" || typeof value === "symbol") {
1543
1612
  return value;
1544
1613
  }
1545
- if (Object.is(value?.valueOf?.(), -0)) {
1614
+ if (Object.is((_a = value == null ? void 0 : value.valueOf) == null ? void 0 : _a.call(value), -0)) {
1546
1615
  return "-0";
1547
1616
  }
1548
1617
  return String(value);
@@ -1668,7 +1737,7 @@ var baseToolsWeb = (() => {
1668
1737
  if (Array.isArray(path)) {
1669
1738
  return getWithPath(object, path, defaultValue);
1670
1739
  }
1671
- if (Object.is(path?.valueOf(), -0)) {
1740
+ if (Object.is(path == null ? void 0 : path.valueOf(), -0)) {
1672
1741
  path = "-0";
1673
1742
  } else {
1674
1743
  path = String(path);
@@ -1742,7 +1811,8 @@ var baseToolsWeb = (() => {
1742
1811
  }
1743
1812
  };
1744
1813
  const promise = new Promise((resolve, reject) => {
1745
- const execute = async () => {
1814
+ const execute = () => __async(null, null, function* () {
1815
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1746
1816
  const {
1747
1817
  url,
1748
1818
  data,
@@ -1766,11 +1836,12 @@ var baseToolsWeb = (() => {
1766
1836
  const isObjectData = isPlainObject(data);
1767
1837
  const isArrayData = !isObjectData && Array.isArray(data);
1768
1838
  const fillData = isObjectData ? pickBy(data, (val) => val !== void 0) : data;
1769
- const fillHeader = header ? pickBy(header, (val) => !!val) : {};
1839
+ const emptyValue = [void 0, null, ""];
1840
+ const fillHeader = header ? pickBy(header, (val) => !emptyValue.includes(val)) : {};
1770
1841
  const contentTypeKey = Object.keys(fillHeader).find(
1771
1842
  (k) => k.toLowerCase() === "content-type"
1772
1843
  );
1773
- const contentType = contentTypeKey ? fillHeader[contentTypeKey].toLowerCase() : "";
1844
+ const contentType = contentTypeKey ? String(fillHeader[contentTypeKey]).toLowerCase() : "";
1774
1845
  if (!isGet && fillData && (isObjectData || isArrayData) && !contentType) {
1775
1846
  fillHeader["Content-Type"] = "application/json";
1776
1847
  }
@@ -1788,7 +1859,7 @@ var baseToolsWeb = (() => {
1788
1859
  fillBody = fillData;
1789
1860
  }
1790
1861
  }
1791
- const logConfig = { ...config, data: fillData, header: fillHeader, url: fillUrl };
1862
+ const logConfig = __spreadProps(__spreadValues({}, config), { data: fillData, header: fillHeader, url: fillUrl });
1792
1863
  const startTime = Date.now();
1793
1864
  const isCache = cacheTime && cacheTime > 0;
1794
1865
  const cacheKey = isCache ? JSON.stringify({ url: fillUrl, data: fillData }) : "";
@@ -1807,32 +1878,32 @@ var baseToolsWeb = (() => {
1807
1878
  }
1808
1879
  }
1809
1880
  const appConfig2 = getBaseToolsConfig();
1810
- if (showLoading) appConfig2.showLoading?.();
1881
+ if (showLoading) (_a = appConfig2.showLoading) == null ? void 0 : _a.call(appConfig2);
1811
1882
  let isTimeout = false;
1812
1883
  const timeoutId = setTimeout(() => {
1813
1884
  isTimeout = true;
1814
1885
  controller.abort();
1815
1886
  }, timeout);
1816
1887
  try {
1817
- const response = await fetch(fillUrl, {
1888
+ const response = yield fetch(fillUrl, {
1818
1889
  method,
1819
1890
  headers: fillHeader,
1820
1891
  body: fillBody,
1821
1892
  signal
1822
1893
  });
1823
1894
  if (!response.ok) {
1824
- if (showLoading) appConfig2.hideLoading?.();
1895
+ if (showLoading) (_b = appConfig2.hideLoading) == null ? void 0 : _b.call(appConfig2);
1825
1896
  throw new Error(`HTTP Error ${response.status}: ${response.statusText}`);
1826
1897
  }
1827
1898
  if (enableChunked) {
1828
- if (showLoading) appConfig2.hideLoading?.();
1829
- const res2 = await handleStreamResponse(response, chunkCallback);
1899
+ if (showLoading) (_c = appConfig2.hideLoading) == null ? void 0 : _c.call(appConfig2);
1900
+ const res2 = yield handleStreamResponse(response, chunkCallback);
1830
1901
  logRequestInfo({ status: "success", config: logConfig, startTime, res: res2 });
1831
1902
  resolve(res2);
1832
1903
  return;
1833
1904
  }
1834
- const resData = await parseResponse(response, responseType);
1835
- if (showLoading) appConfig2.hideLoading?.();
1905
+ const resData = yield parseResponse(response, responseType);
1906
+ if (showLoading) (_d = appConfig2.hideLoading) == null ? void 0 : _d.call(appConfig2);
1836
1907
  const res = responseInterceptor ? responseInterceptor(resData) : resData;
1837
1908
  const code = getObjectValue(res, codeKey);
1838
1909
  const scode = successKey ? getObjectValue(res, successKey) : code;
@@ -1845,28 +1916,28 @@ var baseToolsWeb = (() => {
1845
1916
  resolve(getResult(res, resKey));
1846
1917
  } else if (isRelogin) {
1847
1918
  reject(res);
1848
- appConfig2.toLogin?.();
1919
+ (_e = appConfig2.toLogin) == null ? void 0 : _e.call(appConfig2);
1849
1920
  } else {
1850
- if (toastError && msg) appConfig2.toast?.({ status: "fail", msg });
1921
+ if (toastError && msg) (_f = appConfig2.toast) == null ? void 0 : _f.call(appConfig2, { status: "fail", msg });
1851
1922
  reject(res);
1852
1923
  }
1853
1924
  } catch (e) {
1854
1925
  const status = "fail";
1855
1926
  const isAbortError = e instanceof DOMException && e.name === "AbortError";
1856
1927
  if (isAbortError && isTimeout) {
1857
- if (toastError) appConfig2.toast?.({ status, msg: "\u8BF7\u6C42\u8D85\u65F6" });
1928
+ if (toastError) (_g = appConfig2.toast) == null ? void 0 : _g.call(appConfig2, { status, msg: "\u8BF7\u6C42\u8D85\u65F6" });
1858
1929
  const timeoutError = new Error("Request Timeout");
1859
1930
  logRequestInfo({ status, config: logConfig, startTime, e: timeoutError });
1860
1931
  reject(timeoutError);
1861
1932
  return;
1862
1933
  }
1863
- if (!isAbortError && toastError) appConfig2.toast?.({ status, msg: "\u7F51\u7EDC\u8BF7\u6C42\u5931\u8D25" });
1934
+ if (!isAbortError && toastError) (_h = appConfig2.toast) == null ? void 0 : _h.call(appConfig2, { status, msg: "\u7F51\u7EDC\u8BF7\u6C42\u5931\u8D25" });
1864
1935
  logRequestInfo({ status, config: logConfig, startTime, e });
1865
1936
  reject(e);
1866
1937
  } finally {
1867
1938
  if (timeoutId) clearTimeout(timeoutId);
1868
1939
  }
1869
- };
1940
+ });
1870
1941
  execute();
1871
1942
  });
1872
1943
  promise.task = task;
@@ -1880,7 +1951,7 @@ var baseToolsWeb = (() => {
1880
1951
  const { url, data, header, method, extraLog } = config;
1881
1952
  const endTime = Date.now();
1882
1953
  const fmt = "YYYY-MM-DD HH:mm:ss.SSS";
1883
- const info = {
1954
+ const info = __spreadValues({
1884
1955
  name: "request",
1885
1956
  status,
1886
1957
  url,
@@ -1890,9 +1961,8 @@ var baseToolsWeb = (() => {
1890
1961
  fromCache,
1891
1962
  startTime: toDayjs(startTime).format(fmt),
1892
1963
  endTime: toDayjs(endTime).format(fmt),
1893
- duration: endTime - startTime,
1894
- ...extraLog
1895
- };
1964
+ duration: endTime - startTime
1965
+ }, extraLog);
1896
1966
  if (status === "success") {
1897
1967
  info.res = cloneDeep(res);
1898
1968
  log("info", info);
@@ -1914,33 +1984,37 @@ var baseToolsWeb = (() => {
1914
1984
  }
1915
1985
  return cached.res;
1916
1986
  }
1917
- async function handleStreamResponse(response, chunkCallback) {
1918
- if (!response.body) throw new Error("Response body is null");
1919
- const reader = response.body.getReader();
1920
- while (true) {
1921
- const { done, value } = await reader.read();
1922
- if (done) break;
1923
- if (chunkCallback && value) {
1924
- chunkCallback({ data: value.buffer });
1987
+ function handleStreamResponse(response, chunkCallback) {
1988
+ return __async(this, null, function* () {
1989
+ if (!response.body) throw new Error("Response body is null");
1990
+ const reader = response.body.getReader();
1991
+ while (true) {
1992
+ const { done, value } = yield reader.read();
1993
+ if (done) break;
1994
+ if (chunkCallback && value) {
1995
+ chunkCallback({ data: value.buffer });
1996
+ }
1925
1997
  }
1926
- }
1927
- return "Stream Finished";
1998
+ return "Stream Finished";
1999
+ });
1928
2000
  }
1929
- async function parseResponse(response, responseType) {
1930
- let resData;
1931
- if (responseType === "arraybuffer") {
1932
- resData = await response.arrayBuffer();
1933
- } else if (responseType === "text") {
1934
- resData = await response.text();
1935
- } else {
1936
- const text = await response.text();
1937
- try {
1938
- resData = JSON.parse(text);
1939
- } catch {
1940
- resData = text;
2001
+ function parseResponse(response, responseType) {
2002
+ return __async(this, null, function* () {
2003
+ let resData;
2004
+ if (responseType === "arraybuffer") {
2005
+ resData = yield response.arrayBuffer();
2006
+ } else if (responseType === "text") {
2007
+ resData = yield response.text();
2008
+ } else {
2009
+ const text = yield response.text();
2010
+ try {
2011
+ resData = JSON.parse(text);
2012
+ } catch (e) {
2013
+ resData = text;
2014
+ }
1941
2015
  }
1942
- }
1943
- return resData;
2016
+ return resData;
2017
+ });
1944
2018
  }
1945
2019
  function toSearchParams(data) {
1946
2020
  const params = new URLSearchParams();
@@ -2012,7 +2086,7 @@ var baseToolsWeb = (() => {
2012
2086
  return parsed[WK.val];
2013
2087
  }
2014
2088
  return parsed;
2015
- } catch {
2089
+ } catch (e) {
2016
2090
  return raw;
2017
2091
  }
2018
2092
  }