@base-web-kits/base-tools-web 1.1.5 → 1.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/base-tools-web.umd.global.js +337 -264
- package/dist/base-tools-web.umd.global.js.map +1 -1
- package/dist/index.cjs +345 -1269
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +343 -1265
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
- package/src/web/network/request.ts +1 -1
|
@@ -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
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
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
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
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
|
-
}
|
|
795
|
-
|
|
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
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
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
|
-
|
|
812
|
-
|
|
813
|
-
const
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
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
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
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
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
}
|
|
840
|
-
|
|
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
|
-
|
|
845
|
-
|
|
846
|
-
const
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
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
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
const
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
});
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
)
|
|
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, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
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
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
(
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
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
|
-
|
|
917
|
-
|
|
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
|
|
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
|
|
947
|
-
selection
|
|
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
|
|
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()
|
|
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
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
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
|
|
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]
|
|
1244
|
+
if (old) return ((_a = old[1]) != null ? _a : old[2]).trim().replace(/[\r\n]+/g, "");
|
|
1181
1245
|
return "";
|
|
1182
1246
|
}
|
|
1183
|
-
|
|
1184
|
-
return
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
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
|
-
|
|
1211
|
-
return
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
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
|
|
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
|
|
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
|
|
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 =
|
|
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,
|
|
@@ -1788,7 +1858,7 @@ var baseToolsWeb = (() => {
|
|
|
1788
1858
|
fillBody = fillData;
|
|
1789
1859
|
}
|
|
1790
1860
|
}
|
|
1791
|
-
const logConfig = {
|
|
1861
|
+
const logConfig = __spreadProps(__spreadValues({}, config), { data: fillData, header: fillHeader, url: fillUrl });
|
|
1792
1862
|
const startTime = Date.now();
|
|
1793
1863
|
const isCache = cacheTime && cacheTime > 0;
|
|
1794
1864
|
const cacheKey = isCache ? JSON.stringify({ url: fillUrl, data: fillData }) : "";
|
|
@@ -1807,32 +1877,32 @@ var baseToolsWeb = (() => {
|
|
|
1807
1877
|
}
|
|
1808
1878
|
}
|
|
1809
1879
|
const appConfig2 = getBaseToolsConfig();
|
|
1810
|
-
if (showLoading) appConfig2.showLoading
|
|
1880
|
+
if (showLoading) (_a = appConfig2.showLoading) == null ? void 0 : _a.call(appConfig2);
|
|
1811
1881
|
let isTimeout = false;
|
|
1812
1882
|
const timeoutId = setTimeout(() => {
|
|
1813
1883
|
isTimeout = true;
|
|
1814
1884
|
controller.abort();
|
|
1815
1885
|
}, timeout);
|
|
1816
1886
|
try {
|
|
1817
|
-
const response =
|
|
1887
|
+
const response = yield fetch(fillUrl, {
|
|
1818
1888
|
method,
|
|
1819
1889
|
headers: fillHeader,
|
|
1820
1890
|
body: fillBody,
|
|
1821
1891
|
signal
|
|
1822
1892
|
});
|
|
1823
1893
|
if (!response.ok) {
|
|
1824
|
-
if (showLoading) appConfig2.hideLoading
|
|
1894
|
+
if (showLoading) (_b = appConfig2.hideLoading) == null ? void 0 : _b.call(appConfig2);
|
|
1825
1895
|
throw new Error(`HTTP Error ${response.status}: ${response.statusText}`);
|
|
1826
1896
|
}
|
|
1827
1897
|
if (enableChunked) {
|
|
1828
|
-
if (showLoading) appConfig2.hideLoading
|
|
1829
|
-
const res2 =
|
|
1898
|
+
if (showLoading) (_c = appConfig2.hideLoading) == null ? void 0 : _c.call(appConfig2);
|
|
1899
|
+
const res2 = yield handleStreamResponse(response, chunkCallback);
|
|
1830
1900
|
logRequestInfo({ status: "success", config: logConfig, startTime, res: res2 });
|
|
1831
1901
|
resolve(res2);
|
|
1832
1902
|
return;
|
|
1833
1903
|
}
|
|
1834
|
-
const resData =
|
|
1835
|
-
if (showLoading) appConfig2.hideLoading
|
|
1904
|
+
const resData = yield parseResponse(response, responseType);
|
|
1905
|
+
if (showLoading) (_d = appConfig2.hideLoading) == null ? void 0 : _d.call(appConfig2);
|
|
1836
1906
|
const res = responseInterceptor ? responseInterceptor(resData) : resData;
|
|
1837
1907
|
const code = getObjectValue(res, codeKey);
|
|
1838
1908
|
const scode = successKey ? getObjectValue(res, successKey) : code;
|
|
@@ -1845,28 +1915,28 @@ var baseToolsWeb = (() => {
|
|
|
1845
1915
|
resolve(getResult(res, resKey));
|
|
1846
1916
|
} else if (isRelogin) {
|
|
1847
1917
|
reject(res);
|
|
1848
|
-
appConfig2.toLogin
|
|
1918
|
+
(_e = appConfig2.toLogin) == null ? void 0 : _e.call(appConfig2);
|
|
1849
1919
|
} else {
|
|
1850
|
-
if (toastError && msg) appConfig2.toast
|
|
1920
|
+
if (toastError && msg) (_f = appConfig2.toast) == null ? void 0 : _f.call(appConfig2, { status: "fail", msg });
|
|
1851
1921
|
reject(res);
|
|
1852
1922
|
}
|
|
1853
1923
|
} catch (e) {
|
|
1854
1924
|
const status = "fail";
|
|
1855
1925
|
const isAbortError = e instanceof DOMException && e.name === "AbortError";
|
|
1856
1926
|
if (isAbortError && isTimeout) {
|
|
1857
|
-
if (toastError) appConfig2.toast
|
|
1927
|
+
if (toastError) (_g = appConfig2.toast) == null ? void 0 : _g.call(appConfig2, { status, msg: "\u8BF7\u6C42\u8D85\u65F6" });
|
|
1858
1928
|
const timeoutError = new Error("Request Timeout");
|
|
1859
1929
|
logRequestInfo({ status, config: logConfig, startTime, e: timeoutError });
|
|
1860
1930
|
reject(timeoutError);
|
|
1861
1931
|
return;
|
|
1862
1932
|
}
|
|
1863
|
-
if (!isAbortError && toastError) appConfig2.toast
|
|
1933
|
+
if (!isAbortError && toastError) (_h = appConfig2.toast) == null ? void 0 : _h.call(appConfig2, { status, msg: "\u7F51\u7EDC\u8BF7\u6C42\u5931\u8D25" });
|
|
1864
1934
|
logRequestInfo({ status, config: logConfig, startTime, e });
|
|
1865
1935
|
reject(e);
|
|
1866
1936
|
} finally {
|
|
1867
1937
|
if (timeoutId) clearTimeout(timeoutId);
|
|
1868
1938
|
}
|
|
1869
|
-
};
|
|
1939
|
+
});
|
|
1870
1940
|
execute();
|
|
1871
1941
|
});
|
|
1872
1942
|
promise.task = task;
|
|
@@ -1880,7 +1950,7 @@ var baseToolsWeb = (() => {
|
|
|
1880
1950
|
const { url, data, header, method, extraLog } = config;
|
|
1881
1951
|
const endTime = Date.now();
|
|
1882
1952
|
const fmt = "YYYY-MM-DD HH:mm:ss.SSS";
|
|
1883
|
-
const info = {
|
|
1953
|
+
const info = __spreadValues({
|
|
1884
1954
|
name: "request",
|
|
1885
1955
|
status,
|
|
1886
1956
|
url,
|
|
@@ -1890,9 +1960,8 @@ var baseToolsWeb = (() => {
|
|
|
1890
1960
|
fromCache,
|
|
1891
1961
|
startTime: toDayjs(startTime).format(fmt),
|
|
1892
1962
|
endTime: toDayjs(endTime).format(fmt),
|
|
1893
|
-
duration: endTime - startTime
|
|
1894
|
-
|
|
1895
|
-
};
|
|
1963
|
+
duration: endTime - startTime
|
|
1964
|
+
}, extraLog);
|
|
1896
1965
|
if (status === "success") {
|
|
1897
1966
|
info.res = cloneDeep(res);
|
|
1898
1967
|
log("info", info);
|
|
@@ -1914,33 +1983,37 @@ var baseToolsWeb = (() => {
|
|
|
1914
1983
|
}
|
|
1915
1984
|
return cached.res;
|
|
1916
1985
|
}
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
chunkCallback
|
|
1986
|
+
function handleStreamResponse(response, chunkCallback) {
|
|
1987
|
+
return __async(this, null, function* () {
|
|
1988
|
+
if (!response.body) throw new Error("Response body is null");
|
|
1989
|
+
const reader = response.body.getReader();
|
|
1990
|
+
while (true) {
|
|
1991
|
+
const { done, value } = yield reader.read();
|
|
1992
|
+
if (done) break;
|
|
1993
|
+
if (chunkCallback && value) {
|
|
1994
|
+
chunkCallback({ data: value.buffer });
|
|
1995
|
+
}
|
|
1925
1996
|
}
|
|
1926
|
-
|
|
1927
|
-
|
|
1997
|
+
return "Stream Finished";
|
|
1998
|
+
});
|
|
1928
1999
|
}
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
2000
|
+
function parseResponse(response, responseType) {
|
|
2001
|
+
return __async(this, null, function* () {
|
|
2002
|
+
let resData;
|
|
2003
|
+
if (responseType === "arraybuffer") {
|
|
2004
|
+
resData = yield response.arrayBuffer();
|
|
2005
|
+
} else if (responseType === "text") {
|
|
2006
|
+
resData = yield response.text();
|
|
2007
|
+
} else {
|
|
2008
|
+
const text = yield response.text();
|
|
2009
|
+
try {
|
|
2010
|
+
resData = JSON.parse(text);
|
|
2011
|
+
} catch (e) {
|
|
2012
|
+
resData = text;
|
|
2013
|
+
}
|
|
1941
2014
|
}
|
|
1942
|
-
|
|
1943
|
-
|
|
2015
|
+
return resData;
|
|
2016
|
+
});
|
|
1944
2017
|
}
|
|
1945
2018
|
function toSearchParams(data) {
|
|
1946
2019
|
const params = new URLSearchParams();
|
|
@@ -2012,7 +2085,7 @@ var baseToolsWeb = (() => {
|
|
|
2012
2085
|
return parsed[WK.val];
|
|
2013
2086
|
}
|
|
2014
2087
|
return parsed;
|
|
2015
|
-
} catch {
|
|
2088
|
+
} catch (e) {
|
|
2016
2089
|
return raw;
|
|
2017
2090
|
}
|
|
2018
2091
|
}
|