@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.cjs CHANGED
@@ -1,8 +1,25 @@
1
1
  "use strict";
2
2
  var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __spreadValues = (a, b) => {
12
+ for (var prop in b || (b = {}))
13
+ if (__hasOwnProp.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ if (__getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(b)) {
17
+ if (__propIsEnum.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ }
20
+ return a;
21
+ };
22
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
6
23
  var __export = (target, all) => {
7
24
  for (var name in all)
8
25
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,6 +33,26 @@ var __copyProps = (to, from, except, desc) => {
16
33
  return to;
17
34
  };
18
35
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
+ var __async = (__this, __arguments, generator) => {
37
+ return new Promise((resolve, reject) => {
38
+ var fulfilled = (value) => {
39
+ try {
40
+ step(generator.next(value));
41
+ } catch (e) {
42
+ reject(e);
43
+ }
44
+ };
45
+ var rejected = (value) => {
46
+ try {
47
+ step(generator.throw(value));
48
+ } catch (e) {
49
+ reject(e);
50
+ }
51
+ };
52
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
53
+ step((generator = generator.apply(__this, __arguments)).next());
54
+ });
55
+ };
19
56
 
20
57
  // src/web/index.ts
21
58
  var index_exports = {};
@@ -73,160 +110,180 @@ __export(index_exports, {
73
110
  module.exports = __toCommonJS(index_exports);
74
111
 
75
112
  // src/web/clipboard/index.ts
76
- async function copyText(text) {
77
- if (typeof text !== "string") text = String(text ?? "");
78
- if (navigator.clipboard && typeof navigator.clipboard.writeText === "function") {
79
- try {
80
- await navigator.clipboard.writeText(text);
81
- return;
82
- } catch (e) {
113
+ function copyText(text) {
114
+ return __async(this, null, function* () {
115
+ if (typeof text !== "string") text = String(text != null ? text : "");
116
+ if (navigator.clipboard && typeof navigator.clipboard.writeText === "function") {
117
+ try {
118
+ yield navigator.clipboard.writeText(text);
119
+ return;
120
+ } catch (e) {
121
+ }
83
122
  }
84
- }
85
- return new Promise((resolve, reject) => {
86
- try {
87
- const textarea = document.createElement("textarea");
88
- textarea.value = text;
89
- textarea.setAttribute("readonly", "");
90
- textarea.style.position = "fixed";
91
- textarea.style.top = "0";
92
- textarea.style.right = "-9999px";
93
- textarea.style.opacity = "0";
94
- textarea.style.pointerEvents = "none";
95
- document.body.appendChild(textarea);
96
- textarea.focus();
97
- textarea.select();
98
- textarea.setSelectionRange(0, textarea.value.length);
99
- const ok = document.execCommand("copy");
100
- document.body.removeChild(textarea);
101
- if (ok) {
102
- resolve();
103
- } else {
104
- reject(new Error("Copy failed: clipboard unavailable"));
123
+ return new Promise((resolve, reject) => {
124
+ try {
125
+ const textarea = document.createElement("textarea");
126
+ textarea.value = text;
127
+ textarea.setAttribute("readonly", "");
128
+ textarea.style.position = "fixed";
129
+ textarea.style.top = "0";
130
+ textarea.style.right = "-9999px";
131
+ textarea.style.opacity = "0";
132
+ textarea.style.pointerEvents = "none";
133
+ document.body.appendChild(textarea);
134
+ textarea.focus();
135
+ textarea.select();
136
+ textarea.setSelectionRange(0, textarea.value.length);
137
+ const ok = document.execCommand("copy");
138
+ document.body.removeChild(textarea);
139
+ if (ok) {
140
+ resolve();
141
+ } else {
142
+ reject(new Error("Copy failed: clipboard unavailable"));
143
+ }
144
+ } catch (e) {
145
+ reject(e);
105
146
  }
106
- } catch (e) {
107
- reject(e);
147
+ });
148
+ });
149
+ }
150
+ function copyHtml(html) {
151
+ return __async(this, null, function* () {
152
+ const s = String(html != null ? html : "");
153
+ if (canWriteClipboard()) {
154
+ const plain = htmlToText(s);
155
+ yield writeClipboard({
156
+ "text/html": new Blob([s], { type: "text/html" }),
157
+ "text/plain": new Blob([plain], { type: "text/plain" })
158
+ });
159
+ return;
108
160
  }
161
+ return execCopyFromHtml(s);
109
162
  });
110
163
  }
111
- async function copyHtml(html) {
112
- const s = String(html ?? "");
113
- if (canWriteClipboard()) {
114
- const plain = htmlToText(s);
115
- await writeClipboard({
116
- "text/html": new Blob([s], { type: "text/html" }),
117
- "text/plain": new Blob([plain], { type: "text/plain" })
118
- });
119
- return;
120
- }
121
- return execCopyFromHtml(s);
122
- }
123
- async function copyNode(node) {
124
- if (canWriteClipboard()) {
125
- const { html: html2, text } = nodeToHtmlText(node);
126
- await writeClipboard({
127
- "text/html": new Blob([html2], { type: "text/html" }),
128
- "text/plain": new Blob([text], { type: "text/plain" })
129
- });
130
- return;
131
- }
132
- const { html } = nodeToHtmlText(node);
133
- return execCopyFromHtml(html);
134
- }
135
- async function copyImage(image) {
136
- const blob = await toImageBlob(image);
137
- if (!blob) throw new Error("Unsupported image source");
138
- if (canWriteClipboard()) {
139
- const type = blob.type || "image/png";
140
- await writeClipboard({ [type]: blob });
141
- return;
142
- }
143
- throw new Error("Clipboard image write not supported");
144
- }
145
- async function copyUrl(url) {
146
- const s = String(url ?? "");
147
- if (canWriteClipboard()) {
148
- await writeClipboard({
149
- "text/uri-list": new Blob([s], { type: "text/uri-list" }),
150
- "text/plain": new Blob([s], { type: "text/plain" })
151
- });
152
- return;
153
- }
154
- await copyText(s);
164
+ function copyNode(node) {
165
+ return __async(this, null, function* () {
166
+ if (canWriteClipboard()) {
167
+ const { html: html2, text } = nodeToHtmlText(node);
168
+ yield writeClipboard({
169
+ "text/html": new Blob([html2], { type: "text/html" }),
170
+ "text/plain": new Blob([text], { type: "text/plain" })
171
+ });
172
+ return;
173
+ }
174
+ const { html } = nodeToHtmlText(node);
175
+ return execCopyFromHtml(html);
176
+ });
155
177
  }
156
- async function copyBlob(blob) {
157
- if (canWriteClipboard()) {
158
- const type = blob.type || "application/octet-stream";
159
- await writeClipboard({ [type]: blob });
160
- return;
161
- }
162
- throw new Error("Clipboard blob write not supported");
163
- }
164
- async function copyRtf(rtf) {
165
- const s = String(rtf ?? "");
166
- if (canWriteClipboard()) {
167
- const plain = s.replace(/\\par[\s]?/g, "\n").replace(/\{[^}]*\}/g, "").replace(/\\[a-zA-Z]+[0-9'-]*/g, "").replace(/\r?\n/g, "\n").trim();
168
- await writeClipboard({
169
- "text/rtf": new Blob([s], { type: "text/rtf" }),
170
- "text/plain": new Blob([plain], { type: "text/plain" })
171
- });
172
- return;
173
- }
174
- await copyText(s);
175
- }
176
- async function copyTable(rows) {
177
- const data = Array.isArray(rows) ? rows : [];
178
- const escapeHtml = (t) => t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
179
- const html = (() => {
180
- const trs = data.map((r) => `<tr>${r.map((c) => `<td>${escapeHtml(String(c))}</td>`).join("")}</tr>`).join("");
181
- return `<table>${trs}</table>`;
182
- })();
183
- const tsv = data.map((r) => r.map((c) => String(c)).join(" ")).join("\n");
184
- const csv = data.map(
185
- (r) => r.map((c) => {
186
- const s = String(c);
187
- const needQuote = /[",\n]/.test(s);
188
- const escaped = s.replace(/"/g, '""');
189
- return needQuote ? `"${escaped}"` : escaped;
190
- }).join(",")
191
- ).join("\n");
192
- if (canWriteClipboard()) {
193
- await writeClipboard({
194
- "text/html": new Blob([html], { type: "text/html" }),
195
- "text/tab-separated-values": new Blob([tsv], { type: "text/tab-separated-values" }),
196
- "text/csv": new Blob([csv], { type: "text/csv" }),
197
- "text/plain": new Blob([tsv], { type: "text/plain" })
198
- });
199
- return;
200
- }
201
- await copyText(tsv);
202
- }
203
- async function toImageBlob(image) {
204
- if (image instanceof Blob) return image;
205
- if (image instanceof HTMLCanvasElement)
206
- return await new Promise((resolve, reject) => {
207
- image.toBlob(
208
- (b) => b ? resolve(b) : reject(new Error("Canvas toBlob failed")),
209
- "image/png"
210
- );
211
- });
212
- const isBitmap = typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap;
213
- if (isBitmap) {
214
- const cnv = document.createElement("canvas");
215
- cnv.width = image.width;
216
- cnv.height = image.height;
217
- const ctx = cnv.getContext("2d");
218
- ctx?.drawImage(image, 0, 0);
219
- return await new Promise((resolve, reject) => {
220
- cnv.toBlob((b) => b ? resolve(b) : reject(new Error("Canvas toBlob failed")), "image/png");
221
- });
222
- }
223
- return null;
178
+ function copyImage(image) {
179
+ return __async(this, null, function* () {
180
+ const blob = yield toImageBlob(image);
181
+ if (!blob) throw new Error("Unsupported image source");
182
+ if (canWriteClipboard()) {
183
+ const type = blob.type || "image/png";
184
+ yield writeClipboard({ [type]: blob });
185
+ return;
186
+ }
187
+ throw new Error("Clipboard image write not supported");
188
+ });
189
+ }
190
+ function copyUrl(url) {
191
+ return __async(this, null, function* () {
192
+ const s = String(url != null ? url : "");
193
+ if (canWriteClipboard()) {
194
+ yield writeClipboard({
195
+ "text/uri-list": new Blob([s], { type: "text/uri-list" }),
196
+ "text/plain": new Blob([s], { type: "text/plain" })
197
+ });
198
+ return;
199
+ }
200
+ yield copyText(s);
201
+ });
202
+ }
203
+ function copyBlob(blob) {
204
+ return __async(this, null, function* () {
205
+ if (canWriteClipboard()) {
206
+ const type = blob.type || "application/octet-stream";
207
+ yield writeClipboard({ [type]: blob });
208
+ return;
209
+ }
210
+ throw new Error("Clipboard blob write not supported");
211
+ });
212
+ }
213
+ function copyRtf(rtf) {
214
+ return __async(this, null, function* () {
215
+ const s = String(rtf != null ? rtf : "");
216
+ if (canWriteClipboard()) {
217
+ const plain = s.replace(/\\par[\s]?/g, "\n").replace(/\{[^}]*\}/g, "").replace(/\\[a-zA-Z]+[0-9'-]*/g, "").replace(/\r?\n/g, "\n").trim();
218
+ yield writeClipboard({
219
+ "text/rtf": new Blob([s], { type: "text/rtf" }),
220
+ "text/plain": new Blob([plain], { type: "text/plain" })
221
+ });
222
+ return;
223
+ }
224
+ yield copyText(s);
225
+ });
226
+ }
227
+ function copyTable(rows) {
228
+ return __async(this, null, function* () {
229
+ const data = Array.isArray(rows) ? rows : [];
230
+ const escapeHtml = (t) => t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
231
+ const html = (() => {
232
+ const trs = data.map((r) => `<tr>${r.map((c) => `<td>${escapeHtml(String(c))}</td>`).join("")}</tr>`).join("");
233
+ return `<table>${trs}</table>`;
234
+ })();
235
+ const tsv = data.map((r) => r.map((c) => String(c)).join(" ")).join("\n");
236
+ const csv = data.map(
237
+ (r) => r.map((c) => {
238
+ const s = String(c);
239
+ const needQuote = /[",\n]/.test(s);
240
+ const escaped = s.replace(/"/g, '""');
241
+ return needQuote ? `"${escaped}"` : escaped;
242
+ }).join(",")
243
+ ).join("\n");
244
+ if (canWriteClipboard()) {
245
+ yield writeClipboard({
246
+ "text/html": new Blob([html], { type: "text/html" }),
247
+ "text/tab-separated-values": new Blob([tsv], { type: "text/tab-separated-values" }),
248
+ "text/csv": new Blob([csv], { type: "text/csv" }),
249
+ "text/plain": new Blob([tsv], { type: "text/plain" })
250
+ });
251
+ return;
252
+ }
253
+ yield copyText(tsv);
254
+ });
255
+ }
256
+ function toImageBlob(image) {
257
+ return __async(this, null, function* () {
258
+ if (image instanceof Blob) return image;
259
+ if (image instanceof HTMLCanvasElement)
260
+ return yield new Promise((resolve, reject) => {
261
+ image.toBlob(
262
+ (b) => b ? resolve(b) : reject(new Error("Canvas toBlob failed")),
263
+ "image/png"
264
+ );
265
+ });
266
+ const isBitmap = typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap;
267
+ if (isBitmap) {
268
+ const cnv = document.createElement("canvas");
269
+ cnv.width = image.width;
270
+ cnv.height = image.height;
271
+ const ctx = cnv.getContext("2d");
272
+ ctx == null ? void 0 : ctx.drawImage(image, 0, 0);
273
+ return yield new Promise((resolve, reject) => {
274
+ cnv.toBlob((b) => b ? resolve(b) : reject(new Error("Canvas toBlob failed")), "image/png");
275
+ });
276
+ }
277
+ return null;
278
+ });
224
279
  }
225
280
  function canWriteClipboard() {
226
281
  return !!(navigator.clipboard && typeof navigator.clipboard.write === "function" && typeof ClipboardItem !== "undefined");
227
282
  }
228
- async function writeClipboard(items) {
229
- await navigator.clipboard.write([new ClipboardItem(items)]);
283
+ function writeClipboard(items) {
284
+ return __async(this, null, function* () {
285
+ yield navigator.clipboard.write([new ClipboardItem(items)]);
286
+ });
230
287
  }
231
288
  function htmlToText(html) {
232
289
  const div = document.createElement("div");
@@ -234,9 +291,10 @@ function htmlToText(html) {
234
291
  return div.textContent || "";
235
292
  }
236
293
  function nodeToHtmlText(node) {
294
+ var _a;
237
295
  const container = document.createElement("div");
238
296
  container.appendChild(node.cloneNode(true));
239
- const html = node instanceof Element ? node.outerHTML ?? container.innerHTML : container.innerHTML;
297
+ const html = node instanceof Element ? (_a = node.outerHTML) != null ? _a : container.innerHTML : container.innerHTML;
240
298
  const text = container.textContent || "";
241
299
  return { html, text };
242
300
  }
@@ -255,11 +313,11 @@ function execCopyFromHtml(html) {
255
313
  const selection = window.getSelection();
256
314
  const range = document.createRange();
257
315
  range.selectNodeContents(div);
258
- selection?.removeAllRanges();
259
- selection?.addRange(range);
316
+ selection == null ? void 0 : selection.removeAllRanges();
317
+ selection == null ? void 0 : selection.addRange(range);
260
318
  const ok = document.execCommand("copy");
261
319
  document.body.removeChild(div);
262
- selection?.removeAllRanges();
320
+ selection == null ? void 0 : selection.removeAllRanges();
263
321
  if (ok) {
264
322
  resolve();
265
323
  } else {
@@ -288,10 +346,11 @@ function setCookie(name, value, days) {
288
346
  document.cookie = `${name}=${encodeURIComponent(value)}; ${expires}`;
289
347
  }
290
348
  function getCookie(name) {
349
+ var _a;
291
350
  const value = `; ${document.cookie}`;
292
351
  const parts = value.split(`; ${name}=`);
293
352
  if (parts.length === 2) {
294
- const v = parts.pop()?.split(";").shift();
353
+ const v = (_a = parts.pop()) == null ? void 0 : _a.split(";").shift();
295
354
  return v ? decodeURIComponent(v) : null;
296
355
  }
297
356
  return null;
@@ -435,80 +494,87 @@ function unlockBodyScroll() {
435
494
  }
436
495
 
437
496
  // src/web/network/load.ts
438
- async function download(url, fileName = "") {
439
- if (!url) return;
440
- let blobUrl = "";
441
- let needRevoke = false;
442
- try {
443
- if (url instanceof Blob) {
444
- blobUrl = URL.createObjectURL(url);
445
- needRevoke = true;
446
- } else if (url.includes(";base64,")) {
447
- blobUrl = url;
448
- } else {
449
- if (fileName) {
450
- const res = await fetch(url);
451
- if (!res.ok) throw new Error(`fetch error ${res.status}\uFF1A${url}`);
452
- const blob = await res.blob();
453
- blobUrl = URL.createObjectURL(blob);
497
+ function download(url, fileName = "") {
498
+ return __async(this, null, function* () {
499
+ if (!url) return;
500
+ let blobUrl = "";
501
+ let needRevoke = false;
502
+ try {
503
+ if (url instanceof Blob) {
504
+ blobUrl = URL.createObjectURL(url);
454
505
  needRevoke = true;
455
- } else {
506
+ } else if (url.includes(";base64,")) {
456
507
  blobUrl = url;
508
+ } else {
509
+ if (fileName) {
510
+ const res = yield fetch(url);
511
+ if (!res.ok) throw new Error(`fetch error ${res.status}\uFF1A${url}`);
512
+ const blob = yield res.blob();
513
+ blobUrl = URL.createObjectURL(blob);
514
+ needRevoke = true;
515
+ } else {
516
+ blobUrl = url;
517
+ }
518
+ }
519
+ const a = document.createElement("a");
520
+ a.href = blobUrl;
521
+ a.download = fileName;
522
+ document.body.appendChild(a);
523
+ a.click();
524
+ document.body.removeChild(a);
525
+ } finally {
526
+ if (needRevoke) {
527
+ setTimeout(() => URL.revokeObjectURL(blobUrl), 100);
457
528
  }
458
529
  }
459
- const a = document.createElement("a");
460
- a.href = blobUrl;
461
- a.download = fileName;
462
- document.body.appendChild(a);
463
- a.click();
464
- document.body.removeChild(a);
465
- } finally {
466
- if (needRevoke) {
467
- setTimeout(() => URL.revokeObjectURL(blobUrl), 100);
468
- }
469
- }
530
+ });
470
531
  }
471
- async function parseAxiosBlob(res) {
472
- const { data, headers, status, statusText, config } = res;
473
- if (status < 200 || status >= 300) throw new Error(`${status}\uFF0C${statusText}\uFF1A${config.url}`);
474
- if (data.type.includes("application/json")) {
475
- const txt = await data.text();
476
- throw JSON.parse(txt);
477
- }
478
- const fileName = getDispositionFileName(headers["content-disposition"]);
479
- return { blob: data, fileName };
532
+ function parseAxiosBlob(res) {
533
+ return __async(this, null, function* () {
534
+ const { data, headers, status, statusText, config } = res;
535
+ if (status < 200 || status >= 300) throw new Error(`${status}\uFF0C${statusText}\uFF1A${config.url}`);
536
+ if (data.type.includes("application/json")) {
537
+ const txt = yield data.text();
538
+ throw JSON.parse(txt);
539
+ }
540
+ const fileName = getDispositionFileName(headers["content-disposition"]);
541
+ return { blob: data, fileName };
542
+ });
480
543
  }
481
544
  function getDispositionFileName(disposition) {
545
+ var _a;
482
546
  if (!disposition) return "";
483
547
  const rfc5987 = /filename\*\s*=\s*([^']*)''([^;]*)/i.exec(disposition);
484
- if (rfc5987?.[2]) {
548
+ if (rfc5987 == null ? void 0 : rfc5987[2]) {
485
549
  try {
486
550
  return decodeURIComponent(rfc5987[2].trim()).replace(/[\r\n]+/g, "");
487
- } catch {
551
+ } catch (e) {
488
552
  return rfc5987[2].trim().replace(/[\r\n]+/g, "");
489
553
  }
490
554
  }
491
555
  const old = /filename\s*=\s*(?:"([^"]*)"|([^";]*))(?=;|$)/i.exec(disposition);
492
- if (old) return (old[1] ?? old[2]).trim().replace(/[\r\n]+/g, "");
556
+ if (old) return ((_a = old[1]) != null ? _a : old[2]).trim().replace(/[\r\n]+/g, "");
493
557
  return "";
494
558
  }
495
- async function loadJs(src, attrs) {
496
- return new Promise((resolve, reject) => {
497
- if (hasJs(src)) return resolve();
498
- const script = document.createElement("script");
499
- script.type = "text/javascript";
500
- script.src = src;
501
- if (attrs) {
502
- const keys = Object.keys(attrs);
503
- keys.forEach((key) => {
504
- const v = attrs[key];
505
- if (v === null || v === void 0 || v === false) return;
506
- script.setAttribute(key, typeof v === "boolean" ? "" : v);
507
- });
508
- }
509
- script.onload = () => resolve();
510
- script.onerror = (e) => reject(e);
511
- document.head.appendChild(script);
559
+ function loadJs(src, attrs) {
560
+ return __async(this, null, function* () {
561
+ return new Promise((resolve, reject) => {
562
+ if (hasJs(src)) return resolve();
563
+ const script = document.createElement("script");
564
+ script.type = "text/javascript";
565
+ script.src = src;
566
+ if (attrs) {
567
+ const keys = Object.keys(attrs);
568
+ keys.forEach((key) => {
569
+ const v = attrs[key];
570
+ if (v === null || v === void 0 || v === false) return;
571
+ script.setAttribute(key, typeof v === "boolean" ? "" : v);
572
+ });
573
+ }
574
+ script.onload = () => resolve();
575
+ script.onerror = (e) => reject(e);
576
+ document.head.appendChild(script);
577
+ });
512
578
  });
513
579
  }
514
580
  function hasJs(src) {
@@ -519,23 +585,25 @@ function hasJs(src) {
519
585
  return src2 && new URL(src2, document.baseURI).href === target;
520
586
  });
521
587
  }
522
- async function loadCss(href, attrs) {
523
- return new Promise((resolve, reject) => {
524
- if (hasCss(href)) return resolve();
525
- const link = document.createElement("link");
526
- link.rel = "stylesheet";
527
- link.href = href;
528
- if (attrs) {
529
- const keys = Object.keys(attrs);
530
- keys.forEach((key) => {
531
- const v = attrs[key];
532
- if (v === null || v === void 0) return;
533
- link.setAttribute(key, String(v));
534
- });
535
- }
536
- link.onload = () => resolve();
537
- link.onerror = (e) => reject(e);
538
- document.head.appendChild(link);
588
+ function loadCss(href, attrs) {
589
+ return __async(this, null, function* () {
590
+ return new Promise((resolve, reject) => {
591
+ if (hasCss(href)) return resolve();
592
+ const link = document.createElement("link");
593
+ link.rel = "stylesheet";
594
+ link.href = href;
595
+ if (attrs) {
596
+ const keys = Object.keys(attrs);
597
+ keys.forEach((key) => {
598
+ const v = attrs[key];
599
+ if (v === null || v === void 0) return;
600
+ link.setAttribute(key, String(v));
601
+ });
602
+ }
603
+ link.onload = () => resolve();
604
+ link.onerror = (e) => reject(e);
605
+ document.head.appendChild(link);
606
+ });
539
607
  });
540
608
  }
541
609
  function hasCss(href) {
@@ -572,7 +640,8 @@ function request(config) {
572
640
  }
573
641
  };
574
642
  const promise = new Promise((resolve, reject) => {
575
- const execute = async () => {
643
+ const execute = () => __async(null, null, function* () {
644
+ var _a, _b, _c, _d, _e, _f, _g, _h;
576
645
  const {
577
646
  url,
578
647
  data,
@@ -618,7 +687,7 @@ function request(config) {
618
687
  fillBody = fillData;
619
688
  }
620
689
  }
621
- const logConfig = { ...config, data: fillData, header: fillHeader, url: fillUrl };
690
+ const logConfig = __spreadProps(__spreadValues({}, config), { data: fillData, header: fillHeader, url: fillUrl });
622
691
  const startTime = Date.now();
623
692
  const isCache = cacheTime && cacheTime > 0;
624
693
  const cacheKey = isCache ? JSON.stringify({ url: fillUrl, data: fillData }) : "";
@@ -637,32 +706,32 @@ function request(config) {
637
706
  }
638
707
  }
639
708
  const appConfig2 = getBaseToolsConfig();
640
- if (showLoading) appConfig2.showLoading?.();
709
+ if (showLoading) (_a = appConfig2.showLoading) == null ? void 0 : _a.call(appConfig2);
641
710
  let isTimeout = false;
642
711
  const timeoutId = setTimeout(() => {
643
712
  isTimeout = true;
644
713
  controller.abort();
645
714
  }, timeout);
646
715
  try {
647
- const response = await fetch(fillUrl, {
716
+ const response = yield fetch(fillUrl, {
648
717
  method,
649
718
  headers: fillHeader,
650
719
  body: fillBody,
651
720
  signal
652
721
  });
653
722
  if (!response.ok) {
654
- if (showLoading) appConfig2.hideLoading?.();
723
+ if (showLoading) (_b = appConfig2.hideLoading) == null ? void 0 : _b.call(appConfig2);
655
724
  throw new Error(`HTTP Error ${response.status}: ${response.statusText}`);
656
725
  }
657
726
  if (enableChunked) {
658
- if (showLoading) appConfig2.hideLoading?.();
659
- const res2 = await handleStreamResponse(response, chunkCallback);
727
+ if (showLoading) (_c = appConfig2.hideLoading) == null ? void 0 : _c.call(appConfig2);
728
+ const res2 = yield handleStreamResponse(response, chunkCallback);
660
729
  logRequestInfo({ status: "success", config: logConfig, startTime, res: res2 });
661
730
  resolve(res2);
662
731
  return;
663
732
  }
664
- const resData = await parseResponse(response, responseType);
665
- if (showLoading) appConfig2.hideLoading?.();
733
+ const resData = yield parseResponse(response, responseType);
734
+ if (showLoading) (_d = appConfig2.hideLoading) == null ? void 0 : _d.call(appConfig2);
666
735
  const res = responseInterceptor ? responseInterceptor(resData) : resData;
667
736
  const code = (0, import_base_tools_ts.getObjectValue)(res, codeKey);
668
737
  const scode = successKey ? (0, import_base_tools_ts.getObjectValue)(res, successKey) : code;
@@ -675,28 +744,28 @@ function request(config) {
675
744
  resolve(getResult(res, resKey));
676
745
  } else if (isRelogin) {
677
746
  reject(res);
678
- appConfig2.toLogin?.();
747
+ (_e = appConfig2.toLogin) == null ? void 0 : _e.call(appConfig2);
679
748
  } else {
680
- if (toastError && msg) appConfig2.toast?.({ status: "fail", msg });
749
+ if (toastError && msg) (_f = appConfig2.toast) == null ? void 0 : _f.call(appConfig2, { status: "fail", msg });
681
750
  reject(res);
682
751
  }
683
752
  } catch (e) {
684
753
  const status = "fail";
685
754
  const isAbortError = e instanceof DOMException && e.name === "AbortError";
686
755
  if (isAbortError && isTimeout) {
687
- if (toastError) appConfig2.toast?.({ status, msg: "\u8BF7\u6C42\u8D85\u65F6" });
756
+ if (toastError) (_g = appConfig2.toast) == null ? void 0 : _g.call(appConfig2, { status, msg: "\u8BF7\u6C42\u8D85\u65F6" });
688
757
  const timeoutError = new Error("Request Timeout");
689
758
  logRequestInfo({ status, config: logConfig, startTime, e: timeoutError });
690
759
  reject(timeoutError);
691
760
  return;
692
761
  }
693
- if (!isAbortError && toastError) appConfig2.toast?.({ status, msg: "\u7F51\u7EDC\u8BF7\u6C42\u5931\u8D25" });
762
+ if (!isAbortError && toastError) (_h = appConfig2.toast) == null ? void 0 : _h.call(appConfig2, { status, msg: "\u7F51\u7EDC\u8BF7\u6C42\u5931\u8D25" });
694
763
  logRequestInfo({ status, config: logConfig, startTime, e });
695
764
  reject(e);
696
765
  } finally {
697
766
  if (timeoutId) clearTimeout(timeoutId);
698
767
  }
699
- };
768
+ });
700
769
  execute();
701
770
  });
702
771
  promise.task = task;
@@ -710,7 +779,7 @@ function logRequestInfo(options) {
710
779
  const { url, data, header, method, extraLog } = config;
711
780
  const endTime = Date.now();
712
781
  const fmt = "YYYY-MM-DD HH:mm:ss.SSS";
713
- const info = {
782
+ const info = __spreadValues({
714
783
  name: "request",
715
784
  status,
716
785
  url,
@@ -720,9 +789,8 @@ function logRequestInfo(options) {
720
789
  fromCache,
721
790
  startTime: (0, import_base_tools_ts.toDayjs)(startTime).format(fmt),
722
791
  endTime: (0, import_base_tools_ts.toDayjs)(endTime).format(fmt),
723
- duration: endTime - startTime,
724
- ...extraLog
725
- };
792
+ duration: endTime - startTime
793
+ }, extraLog);
726
794
  if (status === "success") {
727
795
  info.res = (0, import_base_tools_ts.cloneDeep)(res);
728
796
  log("info", info);
@@ -744,33 +812,37 @@ function checkCache(cacheKey) {
744
812
  }
745
813
  return cached.res;
746
814
  }
747
- async function handleStreamResponse(response, chunkCallback) {
748
- if (!response.body) throw new Error("Response body is null");
749
- const reader = response.body.getReader();
750
- while (true) {
751
- const { done, value } = await reader.read();
752
- if (done) break;
753
- if (chunkCallback && value) {
754
- chunkCallback({ data: value.buffer });
815
+ function handleStreamResponse(response, chunkCallback) {
816
+ return __async(this, null, function* () {
817
+ if (!response.body) throw new Error("Response body is null");
818
+ const reader = response.body.getReader();
819
+ while (true) {
820
+ const { done, value } = yield reader.read();
821
+ if (done) break;
822
+ if (chunkCallback && value) {
823
+ chunkCallback({ data: value.buffer });
824
+ }
755
825
  }
756
- }
757
- return "Stream Finished";
758
- }
759
- async function parseResponse(response, responseType) {
760
- let resData;
761
- if (responseType === "arraybuffer") {
762
- resData = await response.arrayBuffer();
763
- } else if (responseType === "text") {
764
- resData = await response.text();
765
- } else {
766
- const text = await response.text();
767
- try {
768
- resData = JSON.parse(text);
769
- } catch {
770
- resData = text;
826
+ return "Stream Finished";
827
+ });
828
+ }
829
+ function parseResponse(response, responseType) {
830
+ return __async(this, null, function* () {
831
+ let resData;
832
+ if (responseType === "arraybuffer") {
833
+ resData = yield response.arrayBuffer();
834
+ } else if (responseType === "text") {
835
+ resData = yield response.text();
836
+ } else {
837
+ const text = yield response.text();
838
+ try {
839
+ resData = JSON.parse(text);
840
+ } catch (e) {
841
+ resData = text;
842
+ }
771
843
  }
772
- }
773
- return resData;
844
+ return resData;
845
+ });
774
846
  }
775
847
  function toSearchParams(data) {
776
848
  const params = new URLSearchParams();
@@ -842,7 +914,7 @@ function getLocalStorage(key) {
842
914
  return parsed[WK.val];
843
915
  }
844
916
  return parsed;
845
- } catch {
917
+ } catch (e) {
846
918
  return raw;
847
919
  }
848
920
  }