@base-web-kits/base-tools-web 1.1.6 → 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/dist/index.js CHANGED
@@ -1,158 +1,218 @@
1
- // src/web/clipboard/index.ts
2
- async function copyText(text) {
3
- if (typeof text !== "string") text = String(text ?? "");
4
- if (navigator.clipboard && typeof navigator.clipboard.writeText === "function") {
5
- try {
6
- await navigator.clipboard.writeText(text);
7
- return;
8
- } catch (e) {
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
9
16
  }
10
- }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __async = (__this, __arguments, generator) => {
11
21
  return new Promise((resolve, reject) => {
12
- try {
13
- const textarea = document.createElement("textarea");
14
- textarea.value = text;
15
- textarea.setAttribute("readonly", "");
16
- textarea.style.position = "fixed";
17
- textarea.style.top = "0";
18
- textarea.style.right = "-9999px";
19
- textarea.style.opacity = "0";
20
- textarea.style.pointerEvents = "none";
21
- document.body.appendChild(textarea);
22
- textarea.focus();
23
- textarea.select();
24
- textarea.setSelectionRange(0, textarea.value.length);
25
- const ok = document.execCommand("copy");
26
- document.body.removeChild(textarea);
27
- if (ok) {
28
- resolve();
29
- } else {
30
- reject(new Error("Copy failed: clipboard unavailable"));
22
+ var fulfilled = (value) => {
23
+ try {
24
+ step(generator.next(value));
25
+ } catch (e) {
26
+ reject(e);
27
+ }
28
+ };
29
+ var rejected = (value) => {
30
+ try {
31
+ step(generator.throw(value));
32
+ } catch (e) {
33
+ reject(e);
34
+ }
35
+ };
36
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
37
+ step((generator = generator.apply(__this, __arguments)).next());
38
+ });
39
+ };
40
+
41
+ // src/web/clipboard/index.ts
42
+ function copyText(text) {
43
+ return __async(this, null, function* () {
44
+ if (typeof text !== "string") text = String(text != null ? text : "");
45
+ if (navigator.clipboard && typeof navigator.clipboard.writeText === "function") {
46
+ try {
47
+ yield navigator.clipboard.writeText(text);
48
+ return;
49
+ } catch (e) {
31
50
  }
32
- } catch (e) {
33
- reject(e);
34
51
  }
52
+ return new Promise((resolve, reject) => {
53
+ try {
54
+ const textarea = document.createElement("textarea");
55
+ textarea.value = text;
56
+ textarea.setAttribute("readonly", "");
57
+ textarea.style.position = "fixed";
58
+ textarea.style.top = "0";
59
+ textarea.style.right = "-9999px";
60
+ textarea.style.opacity = "0";
61
+ textarea.style.pointerEvents = "none";
62
+ document.body.appendChild(textarea);
63
+ textarea.focus();
64
+ textarea.select();
65
+ textarea.setSelectionRange(0, textarea.value.length);
66
+ const ok = document.execCommand("copy");
67
+ document.body.removeChild(textarea);
68
+ if (ok) {
69
+ resolve();
70
+ } else {
71
+ reject(new Error("Copy failed: clipboard unavailable"));
72
+ }
73
+ } catch (e) {
74
+ reject(e);
75
+ }
76
+ });
35
77
  });
36
78
  }
37
- async function copyHtml(html) {
38
- const s = String(html ?? "");
39
- if (canWriteClipboard()) {
40
- const plain = htmlToText(s);
41
- await writeClipboard({
42
- "text/html": new Blob([s], { type: "text/html" }),
43
- "text/plain": new Blob([plain], { type: "text/plain" })
44
- });
45
- return;
46
- }
47
- return execCopyFromHtml(s);
48
- }
49
- async function copyNode(node) {
50
- if (canWriteClipboard()) {
51
- const { html: html2, text } = nodeToHtmlText(node);
52
- await writeClipboard({
53
- "text/html": new Blob([html2], { type: "text/html" }),
54
- "text/plain": new Blob([text], { type: "text/plain" })
55
- });
56
- return;
57
- }
58
- const { html } = nodeToHtmlText(node);
59
- return execCopyFromHtml(html);
60
- }
61
- async function copyImage(image) {
62
- const blob = await toImageBlob(image);
63
- if (!blob) throw new Error("Unsupported image source");
64
- if (canWriteClipboard()) {
65
- const type = blob.type || "image/png";
66
- await writeClipboard({ [type]: blob });
67
- return;
68
- }
69
- throw new Error("Clipboard image write not supported");
70
- }
71
- async function copyUrl(url) {
72
- const s = String(url ?? "");
73
- if (canWriteClipboard()) {
74
- await writeClipboard({
75
- "text/uri-list": new Blob([s], { type: "text/uri-list" }),
76
- "text/plain": new Blob([s], { type: "text/plain" })
77
- });
78
- return;
79
- }
80
- await copyText(s);
79
+ function copyHtml(html) {
80
+ return __async(this, null, function* () {
81
+ const s = String(html != null ? html : "");
82
+ if (canWriteClipboard()) {
83
+ const plain = htmlToText(s);
84
+ yield writeClipboard({
85
+ "text/html": new Blob([s], { type: "text/html" }),
86
+ "text/plain": new Blob([plain], { type: "text/plain" })
87
+ });
88
+ return;
89
+ }
90
+ return execCopyFromHtml(s);
91
+ });
81
92
  }
82
- async function copyBlob(blob) {
83
- if (canWriteClipboard()) {
84
- const type = blob.type || "application/octet-stream";
85
- await writeClipboard({ [type]: blob });
86
- return;
87
- }
88
- throw new Error("Clipboard blob write not supported");
89
- }
90
- async function copyRtf(rtf) {
91
- const s = String(rtf ?? "");
92
- if (canWriteClipboard()) {
93
- const plain = s.replace(/\\par[\s]?/g, "\n").replace(/\{[^}]*\}/g, "").replace(/\\[a-zA-Z]+[0-9'-]*/g, "").replace(/\r?\n/g, "\n").trim();
94
- await writeClipboard({
95
- "text/rtf": new Blob([s], { type: "text/rtf" }),
96
- "text/plain": new Blob([plain], { type: "text/plain" })
97
- });
98
- return;
99
- }
100
- await copyText(s);
101
- }
102
- async function copyTable(rows) {
103
- const data = Array.isArray(rows) ? rows : [];
104
- const escapeHtml = (t) => t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
105
- const html = (() => {
106
- const trs = data.map((r) => `<tr>${r.map((c) => `<td>${escapeHtml(String(c))}</td>`).join("")}</tr>`).join("");
107
- return `<table>${trs}</table>`;
108
- })();
109
- const tsv = data.map((r) => r.map((c) => String(c)).join(" ")).join("\n");
110
- const csv = data.map(
111
- (r) => r.map((c) => {
112
- const s = String(c);
113
- const needQuote = /[",\n]/.test(s);
114
- const escaped = s.replace(/"/g, '""');
115
- return needQuote ? `"${escaped}"` : escaped;
116
- }).join(",")
117
- ).join("\n");
118
- if (canWriteClipboard()) {
119
- await writeClipboard({
120
- "text/html": new Blob([html], { type: "text/html" }),
121
- "text/tab-separated-values": new Blob([tsv], { type: "text/tab-separated-values" }),
122
- "text/csv": new Blob([csv], { type: "text/csv" }),
123
- "text/plain": new Blob([tsv], { type: "text/plain" })
124
- });
125
- return;
126
- }
127
- await copyText(tsv);
128
- }
129
- async function toImageBlob(image) {
130
- if (image instanceof Blob) return image;
131
- if (image instanceof HTMLCanvasElement)
132
- return await new Promise((resolve, reject) => {
133
- image.toBlob(
134
- (b) => b ? resolve(b) : reject(new Error("Canvas toBlob failed")),
135
- "image/png"
136
- );
137
- });
138
- const isBitmap = typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap;
139
- if (isBitmap) {
140
- const cnv = document.createElement("canvas");
141
- cnv.width = image.width;
142
- cnv.height = image.height;
143
- const ctx = cnv.getContext("2d");
144
- ctx?.drawImage(image, 0, 0);
145
- return await new Promise((resolve, reject) => {
146
- cnv.toBlob((b) => b ? resolve(b) : reject(new Error("Canvas toBlob failed")), "image/png");
147
- });
148
- }
149
- return null;
93
+ function copyNode(node) {
94
+ return __async(this, null, function* () {
95
+ if (canWriteClipboard()) {
96
+ const { html: html2, text } = nodeToHtmlText(node);
97
+ yield writeClipboard({
98
+ "text/html": new Blob([html2], { type: "text/html" }),
99
+ "text/plain": new Blob([text], { type: "text/plain" })
100
+ });
101
+ return;
102
+ }
103
+ const { html } = nodeToHtmlText(node);
104
+ return execCopyFromHtml(html);
105
+ });
106
+ }
107
+ function copyImage(image) {
108
+ return __async(this, null, function* () {
109
+ const blob = yield toImageBlob(image);
110
+ if (!blob) throw new Error("Unsupported image source");
111
+ if (canWriteClipboard()) {
112
+ const type = blob.type || "image/png";
113
+ yield writeClipboard({ [type]: blob });
114
+ return;
115
+ }
116
+ throw new Error("Clipboard image write not supported");
117
+ });
118
+ }
119
+ function copyUrl(url) {
120
+ return __async(this, null, function* () {
121
+ const s = String(url != null ? url : "");
122
+ if (canWriteClipboard()) {
123
+ yield writeClipboard({
124
+ "text/uri-list": new Blob([s], { type: "text/uri-list" }),
125
+ "text/plain": new Blob([s], { type: "text/plain" })
126
+ });
127
+ return;
128
+ }
129
+ yield copyText(s);
130
+ });
131
+ }
132
+ function copyBlob(blob) {
133
+ return __async(this, null, function* () {
134
+ if (canWriteClipboard()) {
135
+ const type = blob.type || "application/octet-stream";
136
+ yield writeClipboard({ [type]: blob });
137
+ return;
138
+ }
139
+ throw new Error("Clipboard blob write not supported");
140
+ });
141
+ }
142
+ function copyRtf(rtf) {
143
+ return __async(this, null, function* () {
144
+ const s = String(rtf != null ? rtf : "");
145
+ if (canWriteClipboard()) {
146
+ const plain = s.replace(/\\par[\s]?/g, "\n").replace(/\{[^}]*\}/g, "").replace(/\\[a-zA-Z]+[0-9'-]*/g, "").replace(/\r?\n/g, "\n").trim();
147
+ yield writeClipboard({
148
+ "text/rtf": new Blob([s], { type: "text/rtf" }),
149
+ "text/plain": new Blob([plain], { type: "text/plain" })
150
+ });
151
+ return;
152
+ }
153
+ yield copyText(s);
154
+ });
155
+ }
156
+ function copyTable(rows) {
157
+ return __async(this, null, function* () {
158
+ const data = Array.isArray(rows) ? rows : [];
159
+ const escapeHtml = (t) => t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
160
+ const html = (() => {
161
+ const trs = data.map((r) => `<tr>${r.map((c) => `<td>${escapeHtml(String(c))}</td>`).join("")}</tr>`).join("");
162
+ return `<table>${trs}</table>`;
163
+ })();
164
+ const tsv = data.map((r) => r.map((c) => String(c)).join(" ")).join("\n");
165
+ const csv = data.map(
166
+ (r) => r.map((c) => {
167
+ const s = String(c);
168
+ const needQuote = /[",\n]/.test(s);
169
+ const escaped = s.replace(/"/g, '""');
170
+ return needQuote ? `"${escaped}"` : escaped;
171
+ }).join(",")
172
+ ).join("\n");
173
+ if (canWriteClipboard()) {
174
+ yield writeClipboard({
175
+ "text/html": new Blob([html], { type: "text/html" }),
176
+ "text/tab-separated-values": new Blob([tsv], { type: "text/tab-separated-values" }),
177
+ "text/csv": new Blob([csv], { type: "text/csv" }),
178
+ "text/plain": new Blob([tsv], { type: "text/plain" })
179
+ });
180
+ return;
181
+ }
182
+ yield copyText(tsv);
183
+ });
184
+ }
185
+ function toImageBlob(image) {
186
+ return __async(this, null, function* () {
187
+ if (image instanceof Blob) return image;
188
+ if (image instanceof HTMLCanvasElement)
189
+ return yield new Promise((resolve, reject) => {
190
+ image.toBlob(
191
+ (b) => b ? resolve(b) : reject(new Error("Canvas toBlob failed")),
192
+ "image/png"
193
+ );
194
+ });
195
+ const isBitmap = typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap;
196
+ if (isBitmap) {
197
+ const cnv = document.createElement("canvas");
198
+ cnv.width = image.width;
199
+ cnv.height = image.height;
200
+ const ctx = cnv.getContext("2d");
201
+ ctx == null ? void 0 : ctx.drawImage(image, 0, 0);
202
+ return yield new Promise((resolve, reject) => {
203
+ cnv.toBlob((b) => b ? resolve(b) : reject(new Error("Canvas toBlob failed")), "image/png");
204
+ });
205
+ }
206
+ return null;
207
+ });
150
208
  }
151
209
  function canWriteClipboard() {
152
210
  return !!(navigator.clipboard && typeof navigator.clipboard.write === "function" && typeof ClipboardItem !== "undefined");
153
211
  }
154
- async function writeClipboard(items) {
155
- await navigator.clipboard.write([new ClipboardItem(items)]);
212
+ function writeClipboard(items) {
213
+ return __async(this, null, function* () {
214
+ yield navigator.clipboard.write([new ClipboardItem(items)]);
215
+ });
156
216
  }
157
217
  function htmlToText(html) {
158
218
  const div = document.createElement("div");
@@ -160,9 +220,10 @@ function htmlToText(html) {
160
220
  return div.textContent || "";
161
221
  }
162
222
  function nodeToHtmlText(node) {
223
+ var _a;
163
224
  const container = document.createElement("div");
164
225
  container.appendChild(node.cloneNode(true));
165
- const html = node instanceof Element ? node.outerHTML ?? container.innerHTML : container.innerHTML;
226
+ const html = node instanceof Element ? (_a = node.outerHTML) != null ? _a : container.innerHTML : container.innerHTML;
166
227
  const text = container.textContent || "";
167
228
  return { html, text };
168
229
  }
@@ -181,11 +242,11 @@ function execCopyFromHtml(html) {
181
242
  const selection = window.getSelection();
182
243
  const range = document.createRange();
183
244
  range.selectNodeContents(div);
184
- selection?.removeAllRanges();
185
- selection?.addRange(range);
245
+ selection == null ? void 0 : selection.removeAllRanges();
246
+ selection == null ? void 0 : selection.addRange(range);
186
247
  const ok = document.execCommand("copy");
187
248
  document.body.removeChild(div);
188
- selection?.removeAllRanges();
249
+ selection == null ? void 0 : selection.removeAllRanges();
189
250
  if (ok) {
190
251
  resolve();
191
252
  } else {
@@ -214,10 +275,11 @@ function setCookie(name, value, days) {
214
275
  document.cookie = `${name}=${encodeURIComponent(value)}; ${expires}`;
215
276
  }
216
277
  function getCookie(name) {
278
+ var _a;
217
279
  const value = `; ${document.cookie}`;
218
280
  const parts = value.split(`; ${name}=`);
219
281
  if (parts.length === 2) {
220
- const v = parts.pop()?.split(";").shift();
282
+ const v = (_a = parts.pop()) == null ? void 0 : _a.split(";").shift();
221
283
  return v ? decodeURIComponent(v) : null;
222
284
  }
223
285
  return null;
@@ -361,80 +423,87 @@ function unlockBodyScroll() {
361
423
  }
362
424
 
363
425
  // src/web/network/load.ts
364
- async function download(url, fileName = "") {
365
- if (!url) return;
366
- let blobUrl = "";
367
- let needRevoke = false;
368
- try {
369
- if (url instanceof Blob) {
370
- blobUrl = URL.createObjectURL(url);
371
- needRevoke = true;
372
- } else if (url.includes(";base64,")) {
373
- blobUrl = url;
374
- } else {
375
- if (fileName) {
376
- const res = await fetch(url);
377
- if (!res.ok) throw new Error(`fetch error ${res.status}\uFF1A${url}`);
378
- const blob = await res.blob();
379
- blobUrl = URL.createObjectURL(blob);
426
+ function download(url, fileName = "") {
427
+ return __async(this, null, function* () {
428
+ if (!url) return;
429
+ let blobUrl = "";
430
+ let needRevoke = false;
431
+ try {
432
+ if (url instanceof Blob) {
433
+ blobUrl = URL.createObjectURL(url);
380
434
  needRevoke = true;
381
- } else {
435
+ } else if (url.includes(";base64,")) {
382
436
  blobUrl = url;
437
+ } else {
438
+ if (fileName) {
439
+ const res = yield fetch(url);
440
+ if (!res.ok) throw new Error(`fetch error ${res.status}\uFF1A${url}`);
441
+ const blob = yield res.blob();
442
+ blobUrl = URL.createObjectURL(blob);
443
+ needRevoke = true;
444
+ } else {
445
+ blobUrl = url;
446
+ }
447
+ }
448
+ const a = document.createElement("a");
449
+ a.href = blobUrl;
450
+ a.download = fileName;
451
+ document.body.appendChild(a);
452
+ a.click();
453
+ document.body.removeChild(a);
454
+ } finally {
455
+ if (needRevoke) {
456
+ setTimeout(() => URL.revokeObjectURL(blobUrl), 100);
383
457
  }
384
458
  }
385
- const a = document.createElement("a");
386
- a.href = blobUrl;
387
- a.download = fileName;
388
- document.body.appendChild(a);
389
- a.click();
390
- document.body.removeChild(a);
391
- } finally {
392
- if (needRevoke) {
393
- setTimeout(() => URL.revokeObjectURL(blobUrl), 100);
394
- }
395
- }
459
+ });
396
460
  }
397
- async function parseAxiosBlob(res) {
398
- const { data, headers, status, statusText, config } = res;
399
- if (status < 200 || status >= 300) throw new Error(`${status}\uFF0C${statusText}\uFF1A${config.url}`);
400
- if (data.type.includes("application/json")) {
401
- const txt = await data.text();
402
- throw JSON.parse(txt);
403
- }
404
- const fileName = getDispositionFileName(headers["content-disposition"]);
405
- return { blob: data, fileName };
461
+ function parseAxiosBlob(res) {
462
+ return __async(this, null, function* () {
463
+ const { data, headers, status, statusText, config } = res;
464
+ if (status < 200 || status >= 300) throw new Error(`${status}\uFF0C${statusText}\uFF1A${config.url}`);
465
+ if (data.type.includes("application/json")) {
466
+ const txt = yield data.text();
467
+ throw JSON.parse(txt);
468
+ }
469
+ const fileName = getDispositionFileName(headers["content-disposition"]);
470
+ return { blob: data, fileName };
471
+ });
406
472
  }
407
473
  function getDispositionFileName(disposition) {
474
+ var _a;
408
475
  if (!disposition) return "";
409
476
  const rfc5987 = /filename\*\s*=\s*([^']*)''([^;]*)/i.exec(disposition);
410
- if (rfc5987?.[2]) {
477
+ if (rfc5987 == null ? void 0 : rfc5987[2]) {
411
478
  try {
412
479
  return decodeURIComponent(rfc5987[2].trim()).replace(/[\r\n]+/g, "");
413
- } catch {
480
+ } catch (e) {
414
481
  return rfc5987[2].trim().replace(/[\r\n]+/g, "");
415
482
  }
416
483
  }
417
484
  const old = /filename\s*=\s*(?:"([^"]*)"|([^";]*))(?=;|$)/i.exec(disposition);
418
- if (old) return (old[1] ?? old[2]).trim().replace(/[\r\n]+/g, "");
485
+ if (old) return ((_a = old[1]) != null ? _a : old[2]).trim().replace(/[\r\n]+/g, "");
419
486
  return "";
420
487
  }
421
- async function loadJs(src, attrs) {
422
- return new Promise((resolve, reject) => {
423
- if (hasJs(src)) return resolve();
424
- const script = document.createElement("script");
425
- script.type = "text/javascript";
426
- script.src = src;
427
- if (attrs) {
428
- const keys = Object.keys(attrs);
429
- keys.forEach((key) => {
430
- const v = attrs[key];
431
- if (v === null || v === void 0 || v === false) return;
432
- script.setAttribute(key, typeof v === "boolean" ? "" : v);
433
- });
434
- }
435
- script.onload = () => resolve();
436
- script.onerror = (e) => reject(e);
437
- document.head.appendChild(script);
488
+ function loadJs(src, attrs) {
489
+ return __async(this, null, function* () {
490
+ return new Promise((resolve, reject) => {
491
+ if (hasJs(src)) return resolve();
492
+ const script = document.createElement("script");
493
+ script.type = "text/javascript";
494
+ script.src = src;
495
+ if (attrs) {
496
+ const keys = Object.keys(attrs);
497
+ keys.forEach((key) => {
498
+ const v = attrs[key];
499
+ if (v === null || v === void 0 || v === false) return;
500
+ script.setAttribute(key, typeof v === "boolean" ? "" : v);
501
+ });
502
+ }
503
+ script.onload = () => resolve();
504
+ script.onerror = (e) => reject(e);
505
+ document.head.appendChild(script);
506
+ });
438
507
  });
439
508
  }
440
509
  function hasJs(src) {
@@ -445,23 +514,25 @@ function hasJs(src) {
445
514
  return src2 && new URL(src2, document.baseURI).href === target;
446
515
  });
447
516
  }
448
- async function loadCss(href, attrs) {
449
- return new Promise((resolve, reject) => {
450
- if (hasCss(href)) return resolve();
451
- const link = document.createElement("link");
452
- link.rel = "stylesheet";
453
- link.href = href;
454
- if (attrs) {
455
- const keys = Object.keys(attrs);
456
- keys.forEach((key) => {
457
- const v = attrs[key];
458
- if (v === null || v === void 0) return;
459
- link.setAttribute(key, String(v));
460
- });
461
- }
462
- link.onload = () => resolve();
463
- link.onerror = (e) => reject(e);
464
- document.head.appendChild(link);
517
+ function loadCss(href, attrs) {
518
+ return __async(this, null, function* () {
519
+ return new Promise((resolve, reject) => {
520
+ if (hasCss(href)) return resolve();
521
+ const link = document.createElement("link");
522
+ link.rel = "stylesheet";
523
+ link.href = href;
524
+ if (attrs) {
525
+ const keys = Object.keys(attrs);
526
+ keys.forEach((key) => {
527
+ const v = attrs[key];
528
+ if (v === null || v === void 0) return;
529
+ link.setAttribute(key, String(v));
530
+ });
531
+ }
532
+ link.onload = () => resolve();
533
+ link.onerror = (e) => reject(e);
534
+ document.head.appendChild(link);
535
+ });
465
536
  });
466
537
  }
467
538
  function hasCss(href) {
@@ -505,7 +576,8 @@ function request(config) {
505
576
  }
506
577
  };
507
578
  const promise = new Promise((resolve, reject) => {
508
- const execute = async () => {
579
+ const execute = () => __async(null, null, function* () {
580
+ var _a, _b, _c, _d, _e, _f, _g, _h;
509
581
  const {
510
582
  url,
511
583
  data,
@@ -551,7 +623,7 @@ function request(config) {
551
623
  fillBody = fillData;
552
624
  }
553
625
  }
554
- const logConfig = { ...config, data: fillData, header: fillHeader, url: fillUrl };
626
+ const logConfig = __spreadProps(__spreadValues({}, config), { data: fillData, header: fillHeader, url: fillUrl });
555
627
  const startTime = Date.now();
556
628
  const isCache = cacheTime && cacheTime > 0;
557
629
  const cacheKey = isCache ? JSON.stringify({ url: fillUrl, data: fillData }) : "";
@@ -570,32 +642,32 @@ function request(config) {
570
642
  }
571
643
  }
572
644
  const appConfig2 = getBaseToolsConfig();
573
- if (showLoading) appConfig2.showLoading?.();
645
+ if (showLoading) (_a = appConfig2.showLoading) == null ? void 0 : _a.call(appConfig2);
574
646
  let isTimeout = false;
575
647
  const timeoutId = setTimeout(() => {
576
648
  isTimeout = true;
577
649
  controller.abort();
578
650
  }, timeout);
579
651
  try {
580
- const response = await fetch(fillUrl, {
652
+ const response = yield fetch(fillUrl, {
581
653
  method,
582
654
  headers: fillHeader,
583
655
  body: fillBody,
584
656
  signal
585
657
  });
586
658
  if (!response.ok) {
587
- if (showLoading) appConfig2.hideLoading?.();
659
+ if (showLoading) (_b = appConfig2.hideLoading) == null ? void 0 : _b.call(appConfig2);
588
660
  throw new Error(`HTTP Error ${response.status}: ${response.statusText}`);
589
661
  }
590
662
  if (enableChunked) {
591
- if (showLoading) appConfig2.hideLoading?.();
592
- const res2 = await handleStreamResponse(response, chunkCallback);
663
+ if (showLoading) (_c = appConfig2.hideLoading) == null ? void 0 : _c.call(appConfig2);
664
+ const res2 = yield handleStreamResponse(response, chunkCallback);
593
665
  logRequestInfo({ status: "success", config: logConfig, startTime, res: res2 });
594
666
  resolve(res2);
595
667
  return;
596
668
  }
597
- const resData = await parseResponse(response, responseType);
598
- if (showLoading) appConfig2.hideLoading?.();
669
+ const resData = yield parseResponse(response, responseType);
670
+ if (showLoading) (_d = appConfig2.hideLoading) == null ? void 0 : _d.call(appConfig2);
599
671
  const res = responseInterceptor ? responseInterceptor(resData) : resData;
600
672
  const code = getObjectValue(res, codeKey);
601
673
  const scode = successKey ? getObjectValue(res, successKey) : code;
@@ -608,28 +680,28 @@ function request(config) {
608
680
  resolve(getResult(res, resKey));
609
681
  } else if (isRelogin) {
610
682
  reject(res);
611
- appConfig2.toLogin?.();
683
+ (_e = appConfig2.toLogin) == null ? void 0 : _e.call(appConfig2);
612
684
  } else {
613
- if (toastError && msg) appConfig2.toast?.({ status: "fail", msg });
685
+ if (toastError && msg) (_f = appConfig2.toast) == null ? void 0 : _f.call(appConfig2, { status: "fail", msg });
614
686
  reject(res);
615
687
  }
616
688
  } catch (e) {
617
689
  const status = "fail";
618
690
  const isAbortError = e instanceof DOMException && e.name === "AbortError";
619
691
  if (isAbortError && isTimeout) {
620
- if (toastError) appConfig2.toast?.({ status, msg: "\u8BF7\u6C42\u8D85\u65F6" });
692
+ if (toastError) (_g = appConfig2.toast) == null ? void 0 : _g.call(appConfig2, { status, msg: "\u8BF7\u6C42\u8D85\u65F6" });
621
693
  const timeoutError = new Error("Request Timeout");
622
694
  logRequestInfo({ status, config: logConfig, startTime, e: timeoutError });
623
695
  reject(timeoutError);
624
696
  return;
625
697
  }
626
- if (!isAbortError && toastError) appConfig2.toast?.({ status, msg: "\u7F51\u7EDC\u8BF7\u6C42\u5931\u8D25" });
698
+ if (!isAbortError && toastError) (_h = appConfig2.toast) == null ? void 0 : _h.call(appConfig2, { status, msg: "\u7F51\u7EDC\u8BF7\u6C42\u5931\u8D25" });
627
699
  logRequestInfo({ status, config: logConfig, startTime, e });
628
700
  reject(e);
629
701
  } finally {
630
702
  if (timeoutId) clearTimeout(timeoutId);
631
703
  }
632
- };
704
+ });
633
705
  execute();
634
706
  });
635
707
  promise.task = task;
@@ -643,7 +715,7 @@ function logRequestInfo(options) {
643
715
  const { url, data, header, method, extraLog } = config;
644
716
  const endTime = Date.now();
645
717
  const fmt = "YYYY-MM-DD HH:mm:ss.SSS";
646
- const info = {
718
+ const info = __spreadValues({
647
719
  name: "request",
648
720
  status,
649
721
  url,
@@ -653,9 +725,8 @@ function logRequestInfo(options) {
653
725
  fromCache,
654
726
  startTime: toDayjs(startTime).format(fmt),
655
727
  endTime: toDayjs(endTime).format(fmt),
656
- duration: endTime - startTime,
657
- ...extraLog
658
- };
728
+ duration: endTime - startTime
729
+ }, extraLog);
659
730
  if (status === "success") {
660
731
  info.res = cloneDeep(res);
661
732
  log("info", info);
@@ -677,33 +748,37 @@ function checkCache(cacheKey) {
677
748
  }
678
749
  return cached.res;
679
750
  }
680
- async function handleStreamResponse(response, chunkCallback) {
681
- if (!response.body) throw new Error("Response body is null");
682
- const reader = response.body.getReader();
683
- while (true) {
684
- const { done, value } = await reader.read();
685
- if (done) break;
686
- if (chunkCallback && value) {
687
- chunkCallback({ data: value.buffer });
751
+ function handleStreamResponse(response, chunkCallback) {
752
+ return __async(this, null, function* () {
753
+ if (!response.body) throw new Error("Response body is null");
754
+ const reader = response.body.getReader();
755
+ while (true) {
756
+ const { done, value } = yield reader.read();
757
+ if (done) break;
758
+ if (chunkCallback && value) {
759
+ chunkCallback({ data: value.buffer });
760
+ }
688
761
  }
689
- }
690
- return "Stream Finished";
691
- }
692
- async function parseResponse(response, responseType) {
693
- let resData;
694
- if (responseType === "arraybuffer") {
695
- resData = await response.arrayBuffer();
696
- } else if (responseType === "text") {
697
- resData = await response.text();
698
- } else {
699
- const text = await response.text();
700
- try {
701
- resData = JSON.parse(text);
702
- } catch {
703
- resData = text;
762
+ return "Stream Finished";
763
+ });
764
+ }
765
+ function parseResponse(response, responseType) {
766
+ return __async(this, null, function* () {
767
+ let resData;
768
+ if (responseType === "arraybuffer") {
769
+ resData = yield response.arrayBuffer();
770
+ } else if (responseType === "text") {
771
+ resData = yield response.text();
772
+ } else {
773
+ const text = yield response.text();
774
+ try {
775
+ resData = JSON.parse(text);
776
+ } catch (e) {
777
+ resData = text;
778
+ }
704
779
  }
705
- }
706
- return resData;
780
+ return resData;
781
+ });
707
782
  }
708
783
  function toSearchParams(data) {
709
784
  const params = new URLSearchParams();
@@ -775,7 +850,7 @@ function getLocalStorage(key) {
775
850
  return parsed[WK.val];
776
851
  }
777
852
  return parsed;
778
- } catch {
853
+ } catch (e) {
779
854
  return raw;
780
855
  }
781
856
  }