mphttpx 1.0.2 → 1.0.4

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.js CHANGED
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  const polyfill = Symbol("isPolyfill");
4
- const state$9 = Symbol("INTERNAL_STATE");
5
4
  /* eslint-disable no-prototype-builtins */
6
5
  const g = (typeof globalThis !== "undefined" && globalThis) ||
7
6
  (typeof self !== "undefined" && self) ||
@@ -21,13 +20,13 @@ function isPolyfillType(name, value) {
21
20
  && value.isPolyfill.symbol === polyfill
22
21
  && "hierarchy" in value.isPolyfill
23
22
  && Array.isArray(value.isPolyfill.hierarchy)
24
- && value.isPolyfill.hierarchy.includes(name);
23
+ && value.isPolyfill.hierarchy.indexOf(name) > -1;
25
24
  }
26
25
  class MPException extends Error {
27
26
  constructor(message, name) {
28
27
  super();
29
- this.message = message ?? this.message;
30
- this.name = name ?? this.name;
28
+ this.message = message !== null && message !== void 0 ? message : this.message;
29
+ this.name = name !== null && name !== void 0 ? name : this.name;
31
30
  }
32
31
  }
33
32
  function defineStringTag(targetFunc, stringTag) {
@@ -36,6 +35,12 @@ function defineStringTag(targetFunc, stringTag) {
36
35
  value: stringTag,
37
36
  });
38
37
  }
38
+ function objectValues(obj) {
39
+ return Object.keys(obj).map(key => obj[key]);
40
+ }
41
+ function objectEntries(obj) {
42
+ return Object.keys(obj).map(key => [key, obj[key]]);
43
+ }
39
44
 
40
45
  class TextEncoderP {
41
46
  get encoding() { return "utf-8"; }
@@ -136,21 +141,22 @@ function encodeText(input, destination) {
136
141
  }
137
142
  const TextEncoderE = g["TextEncoder"] || TextEncoderP;
138
143
 
139
- const state$8 = Symbol("TextDecoderState");
144
+ var _a$a, _b$3;
145
+ const state$h = Symbol( /* "TextDecoderState" */);
140
146
  class TextDecoderP {
141
147
  constructor(utfLabel = "utf-8", { fatal = false, ignoreBOM = false } = {}) {
142
- if (!UTF8Labels.includes(utfLabel.toLowerCase())) {
148
+ if (UTF8Labels.indexOf(utfLabel.toLowerCase()) === -1) {
143
149
  throw new RangeError("TextDecoder: The encoding label provided ('" + utfLabel + "') is invalid.");
144
150
  }
145
- this[state$8] = new TextDecoderState();
146
- this[state$8].fatal = fatal;
147
- this[state$8].ignoreBOM = ignoreBOM;
151
+ this[state$h] = new TextDecoderState();
152
+ this[state$h].fatal = fatal;
153
+ this[state$h].ignoreBOM = ignoreBOM;
148
154
  }
149
- [state$8];
150
155
  get encoding() { return "utf-8"; }
151
- get fatal() { return this[state$8].fatal; }
152
- get ignoreBOM() { return this[state$8].ignoreBOM; }
156
+ get fatal() { return this[state$h].fatal; }
157
+ get ignoreBOM() { return this[state$h].ignoreBOM; }
153
158
  decode(buffer, { stream = false } = {}) {
159
+ const that = this[state$h];
154
160
  let buf;
155
161
  if (typeof buffer !== "undefined") {
156
162
  if (buffer instanceof Uint8Array) {
@@ -164,28 +170,28 @@ class TextDecoderP {
164
170
  }
165
171
  }
166
172
  else {
167
- if (this[state$8]._partial.length > 0) {
173
+ if (that[_partial].length > 0) {
168
174
  if (this.fatal) {
169
175
  throw new TypeError("TextDecoder: Incomplete UTF-8 sequence.");
170
176
  }
171
177
  else {
172
- this[state$8]._partial = [];
178
+ that[_partial] = [];
173
179
  }
174
180
  }
175
181
  return "";
176
182
  }
177
- if (!this[state$8]._bomSeen && this.ignoreBOM && buf.length >= 3) {
183
+ if (!that[_bomSeen] && this.ignoreBOM && buf.length >= 3) {
178
184
  if (buf[0] === 0xef && buf[1] === 0xbb && buf[2] === 0xbf) {
179
185
  buf = buf.subarray(3);
180
- this[state$8]._bomSeen = true;
186
+ that[_bomSeen] = true;
181
187
  }
182
188
  }
183
- if (this[state$8]._partial.length > 0) {
184
- let merged = new Uint8Array(this[state$8]._partial.length + buf.length);
185
- merged.set(this[state$8]._partial, 0);
186
- merged.set(buf, this[state$8]._partial.length);
189
+ if (that[_partial].length > 0) {
190
+ let merged = new Uint8Array(that[_partial].length + buf.length);
191
+ merged.set(that[_partial], 0);
192
+ merged.set(buf, that[_partial].length);
187
193
  buf = merged;
188
- this[state$8]._partial = [];
194
+ that[_partial] = [];
189
195
  }
190
196
  let end = buf.length;
191
197
  let res = [];
@@ -202,7 +208,7 @@ class TextDecoderP {
202
208
  }
203
209
  i--;
204
210
  }
205
- this[state$8]._partial = Array.from(buf.slice(end)); // save tail
211
+ that[_partial] = Array.from(buf.slice(end)); // save tail
206
212
  buf = buf.slice(0, end);
207
213
  }
208
214
  let i = 0;
@@ -279,128 +285,155 @@ class TextDecoderP {
279
285
  get isPolyfill() { return { symbol: polyfill, hierarchy: ["TextDecoder"] }; }
280
286
  }
281
287
  defineStringTag(TextDecoderP, "TextDecoder");
288
+ const _bomSeen = Symbol();
289
+ const _partial = Symbol();
282
290
  class TextDecoderState {
283
- fatal = false;
284
- ignoreBOM = false;
285
- _bomSeen = false;
286
- _partial = [];
291
+ constructor() {
292
+ this.fatal = false;
293
+ this.ignoreBOM = false;
294
+ this[_a$a] = false;
295
+ this[_b$3] = [];
296
+ }
287
297
  }
298
+ _a$a = _bomSeen, _b$3 = _partial;
288
299
  const UTF8Labels = ["utf-8", "utf8", "unicode-1-1-utf-8"];
289
300
  function getBytesPerSequence(byte) {
290
301
  return (byte > 0xEF) ? 4 : (byte > 0xDF) ? 3 : (byte > 0xBF) ? 2 : 1;
291
302
  }
292
303
  const TextDecoderE = g["TextDecoder"] || TextDecoderP;
293
304
 
305
+ var _a$9, _b$2, _c$1, _d$1, _e$1, _f$1;
306
+ const state$g = Symbol( /* "EventState" */);
294
307
  class EventP {
295
- static NONE = 0;
296
- static CAPTURING_PHASE = 1;
297
- static AT_TARGET = 2;
298
- static BUBBLING_PHASE = 3;
299
308
  constructor(type, eventInitDict) {
300
- this[state$9] = new EventState();
301
- this[state$9].type = String(type);
302
- this[state$9].bubbles = !!eventInitDict?.bubbles;
303
- this[state$9].cancelable = !!eventInitDict?.cancelable;
304
- this[state$9].composed = !!eventInitDict?.composed;
305
- }
306
- [state$9];
307
- get type() { return this[state$9].type; }
308
- get bubbles() { return this[state$9].bubbles; }
309
- get cancelable() { return this[state$9].cancelable; }
310
- get composed() { return this[state$9].composed; }
311
- get target() { return this[state$9].target; }
312
- get currentTarget() { return this[state$9].currentTarget; }
313
- get eventPhase() { return this[state$9].eventPhase; }
314
- NONE = EventP.NONE;
315
- CAPTURING_PHASE = EventP.CAPTURING_PHASE;
316
- AT_TARGET = EventP.AT_TARGET;
317
- BUBBLING_PHASE = EventP.BUBBLING_PHASE;
318
- get srcElement() { return this[state$9].target; }
319
- cancelBubble = false;
320
- get defaultPrevented() { return this[state$9].defaultPrevented; }
321
- get returnValue() { return this[state$9].returnValue; }
309
+ this.NONE = EventP.NONE;
310
+ this.CAPTURING_PHASE = EventP.CAPTURING_PHASE;
311
+ this.AT_TARGET = EventP.AT_TARGET;
312
+ this.BUBBLING_PHASE = EventP.BUBBLING_PHASE;
313
+ this[state$g] = new EventState();
314
+ const that = this[state$g];
315
+ that.type = String(type);
316
+ that.bubbles = !!(eventInitDict === null || eventInitDict === void 0 ? void 0 : eventInitDict.bubbles);
317
+ that.cancelable = !!(eventInitDict === null || eventInitDict === void 0 ? void 0 : eventInitDict.cancelable);
318
+ that.composed = !!(eventInitDict === null || eventInitDict === void 0 ? void 0 : eventInitDict.composed);
319
+ }
320
+ get type() { return this[state$g].type; }
321
+ get bubbles() { return this[state$g].bubbles; }
322
+ get cancelable() { return this[state$g].cancelable; }
323
+ get composed() { return this[state$g].composed; }
324
+ get target() { return this[state$g].target; }
325
+ get currentTarget() { return this[state$g].currentTarget; }
326
+ get eventPhase() { return this[state$g].eventPhase; }
327
+ get srcElement() { return this[state$g].target; }
328
+ get cancelBubble() { return this[state$g].cancelBubble; }
329
+ set cancelBubble(value) { this[state$g].cancelBubble = value; }
330
+ get defaultPrevented() { return this[state$g].defaultPrevented; }
331
+ get returnValue() { return this[state$g].returnValue; }
322
332
  set returnValue(value) { if (!value) {
323
333
  this.preventDefault();
324
334
  } }
325
- get isTrusted() { return this[state$9].isTrusted; }
326
- get timeStamp() { return this[state$9].timeStamp; }
335
+ get isTrusted() { return this[state$g][_isTrusted]; }
336
+ get timeStamp() { return this[state$g].timeStamp; }
327
337
  composedPath() {
328
338
  const path = !!this.target ? [this.target] : [];
329
339
  if (!!this.currentTarget && this.currentTarget !== this.target)
330
340
  path.push(this.currentTarget);
331
341
  return path;
332
342
  }
333
- initEvent = (type, bubbles, cancelable) => {
334
- if (this[state$9]._dispatched)
343
+ initEvent(type, bubbles, cancelable) {
344
+ const that = this[state$g];
345
+ if (that[_dispatched])
335
346
  return;
336
- this[state$9].type = String(type);
337
- this[state$9].bubbles = !!bubbles;
338
- this[state$9].cancelable = !!cancelable;
339
- };
340
- preventDefault = () => {
341
- if (this[state$9]._passive) {
347
+ that.type = String(type);
348
+ that.bubbles = !!bubbles;
349
+ that.cancelable = !!cancelable;
350
+ }
351
+ preventDefault() {
352
+ const that = this[state$g];
353
+ if (that[_passive]) {
342
354
  console.warn(`Ignoring 'preventDefault()' call on event of type '${this.type}' from a listener registered as 'passive'.`);
343
355
  return;
344
356
  }
345
357
  if (this.cancelable) {
346
- this[state$9]._preventDefaultCalled = true;
347
- this[state$9].defaultPrevented = true;
348
- this[state$9].returnValue = false;
358
+ that[_preventDefaultCalled] = true;
359
+ that.defaultPrevented = true;
360
+ that.returnValue = false;
349
361
  }
350
- };
351
- stopImmediatePropagation = () => {
352
- this[state$9]._stopImmediatePropagationCalled = true;
362
+ }
363
+ stopImmediatePropagation() {
364
+ this[state$g][_stopImmediatePropagationCalled] = true;
353
365
  this.cancelBubble = true;
354
- };
366
+ }
355
367
  stopPropagation() {
356
368
  this.cancelBubble = true;
357
369
  }
358
370
  toString() { return "[object Event]"; }
359
371
  get isPolyfill() { return { symbol: polyfill, hierarchy: ["Event"] }; }
360
372
  }
373
+ EventP.NONE = 0;
374
+ EventP.CAPTURING_PHASE = 1;
375
+ EventP.AT_TARGET = 2;
376
+ EventP.BUBBLING_PHASE = 3;
361
377
  defineStringTag(EventP, "Event");
378
+ const _TimeStamp = Symbol();
379
+ const _isTrusted = Symbol();
380
+ const _passive = Symbol();
381
+ const _dispatched = Symbol();
382
+ const _preventDefaultCalled = Symbol();
383
+ const _stopImmediatePropagationCalled = Symbol();
362
384
  class EventState {
363
- static TimeStamp = (new Date()).getTime();
364
- type = "";
365
- bubbles = false;
366
- cancelable = false;
367
- composed = false;
368
- target = null;
369
- currentTarget = null;
370
- eventPhase = EventP.NONE;
371
- defaultPrevented = false;
372
- returnValue = true;
373
- isTrusted = false;
374
- timeStamp = (new Date()).getTime() - EventState.TimeStamp;
375
- _passive = false;
376
- _dispatched = false;
377
- _preventDefaultCalled = false;
378
- _stopImmediatePropagationCalled = false;
385
+ constructor() {
386
+ this.type = "";
387
+ this.bubbles = false;
388
+ this.cancelable = false;
389
+ this.composed = false;
390
+ this.target = null;
391
+ this.currentTarget = null;
392
+ this.eventPhase = EventP.NONE;
393
+ this.cancelBubble = false;
394
+ this.defaultPrevented = false;
395
+ this.returnValue = true;
396
+ this.timeStamp = (new Date()).getTime() - EventState[_TimeStamp];
397
+ this[_b$2] = false;
398
+ this[_c$1] = false;
399
+ this[_d$1] = false;
400
+ this[_e$1] = false;
401
+ this[_f$1] = false;
402
+ }
403
+ }
404
+ _a$9 = _TimeStamp, _b$2 = _isTrusted, _c$1 = _passive, _d$1 = _dispatched, _e$1 = _preventDefaultCalled, _f$1 = _stopImmediatePropagationCalled;
405
+ EventState[_a$9] = (new Date()).getTime();
406
+ function createInnerEvent(target, type, eventInitDict, isTrusted = true) {
407
+ const event = new EventP(type, eventInitDict);
408
+ event[state$g].target = target;
409
+ event[state$g][_isTrusted] = isTrusted;
410
+ return event;
379
411
  }
380
412
  const EventE = g["EventTarget"] ? g["Event"] : EventP;
381
413
 
382
- const state$7 = Symbol("EventTargetState");
414
+ var _a$8;
415
+ const state$f = Symbol( /* "EventTargetState" */);
383
416
  class EventTargetP {
384
417
  constructor() {
385
- this[state$7] = new EventTargetState(this);
418
+ this[state$f] = new EventTargetState(this);
386
419
  }
387
- [state$7];
388
420
  addEventListener(type, callback, options) {
421
+ const that = this[state$f];
389
422
  const executor = new Executor(type, callback);
390
- executor.options.capture = typeof options === "boolean" ? options : !!options?.capture;
391
- if (!this[state$7].executors.some(x => x.equals(executor))) {
423
+ executor.options.capture = typeof options === "boolean" ? options : !!(options === null || options === void 0 ? void 0 : options.capture);
424
+ if (!that[_executors].some(x => x.equals(executor))) {
392
425
  if (typeof options === "object") {
393
426
  const { once, passive, signal } = options;
394
427
  executor.options.once = !!once;
395
428
  executor.options.passive = !!passive;
396
429
  if (signal) {
397
430
  executor.options.signal = signal;
398
- this[state$7].reply(signal, executor);
431
+ reply.call(that, signal, executor);
399
432
  }
400
433
  }
401
- this[state$7].executors.push(executor);
434
+ that[_executors].push(executor);
402
435
  const f = (v) => !!v.options.capture ? 0 : 1;
403
- this[state$7].executors = this[state$7].executors.sort((a, b) => f(a) - f(b));
436
+ that[_executors] = that[_executors].sort((a, b) => f(a) - f(b));
404
437
  }
405
438
  }
406
439
  dispatchEvent(event) {
@@ -410,104 +443,104 @@ class EventTargetP {
410
443
  if (!(event instanceof EventP)) {
411
444
  throw new TypeError("EventTarget.dispatchEvent: Argument 1 does not implement interface Event.");
412
445
  }
413
- const s = event[state$9];
446
+ const s = event[state$g];
414
447
  s.target = this;
415
- s.isTrusted = false;
416
- return this[state$7].fire(event);
448
+ s[_isTrusted] = false;
449
+ return fire.call(this[state$f], event);
417
450
  }
418
451
  removeEventListener(type, callback, options) {
452
+ const that = this[state$f];
419
453
  const executor = new Executor(type, callback);
420
- executor.options.capture = typeof options === "boolean" ? options : !!options?.capture;
421
- if (this[state$7].executors.some(x => x.equals(executor))) {
422
- this[state$7].executors = this[state$7].executors.filter(x => !x.equals(executor));
454
+ executor.options.capture = typeof options === "boolean" ? options : !!(options === null || options === void 0 ? void 0 : options.capture);
455
+ if (that[_executors].some(x => x.equals(executor))) {
456
+ that[_executors] = that[_executors].filter(x => !x.equals(executor));
423
457
  }
424
458
  }
425
459
  toString() { return "[object EventTarget]"; }
426
460
  get isPolyfill() { return { symbol: polyfill, hierarchy: ["EventTarget"] }; }
427
461
  }
428
462
  defineStringTag(EventTargetP, "EventTarget");
463
+ const _executors = Symbol();
429
464
  class EventTargetState {
430
465
  constructor(target) {
466
+ this[_a$8] = [];
431
467
  this.target = target;
432
468
  }
433
- target;
434
- executors = [];
435
- fire(event) {
436
- const s = event[state$9];
437
- if (!event.target)
438
- s.target = this.target;
439
- s.currentTarget = this.target;
440
- s.eventPhase = EventP.AT_TARGET;
441
- s._dispatched = true;
442
- const onceIndexes = [];
443
- for (let i = 0; i < this.executors.length; ++i) {
444
- const executor = this.executors[i];
445
- if (executor.type !== event.type)
446
- continue;
447
- s._passive = !!executor.options.passive;
448
- if (executor.options.once)
449
- onceIndexes.push(i);
450
- try {
451
- const { callback: cb } = executor;
452
- if (typeof cb === "function")
453
- cb.call(this.target, event);
454
- }
455
- catch (e) {
456
- console.error(e);
457
- }
458
- s._passive = false;
459
- if (s._stopImmediatePropagationCalled)
460
- break;
461
- }
462
- if (onceIndexes.length > 0) {
463
- this.executors = this.executors.reduce((acc, cur, index) => {
464
- if (!onceIndexes.includes(index))
465
- acc.push(cur);
466
- return acc;
467
- }, []);
468
- }
469
- s.currentTarget = null;
470
- s.eventPhase = EventP.NONE;
471
- s._dispatched = false;
472
- return !(event.cancelable && s._preventDefaultCalled);
473
- }
474
- reply(signal, executor) {
469
+ }
470
+ _a$8 = _executors;
471
+ function fire(event) {
472
+ const s = event[state$g];
473
+ if (!event.target)
474
+ s.target = this.target;
475
+ s.currentTarget = this.target;
476
+ s.eventPhase = EventP.AT_TARGET;
477
+ s[_dispatched] = true;
478
+ const onceIndexes = [];
479
+ for (let i = 0; i < this[_executors].length; ++i) {
480
+ const executor = this[_executors][i];
481
+ if (executor.type !== event.type)
482
+ continue;
483
+ s[_passive] = !!executor.options.passive;
484
+ if (executor.options.once)
485
+ onceIndexes.push(i);
486
+ const { callback: cb } = executor;
475
487
  try {
476
- const onAbort = () => {
477
- this.executors = this.executors.filter(x => !x.equals(executor));
478
- signal.removeEventListener("abort", onAbort);
479
- };
480
- signal.addEventListener("abort", onAbort);
488
+ if (typeof cb === "function")
489
+ cb.call(this.target, event);
481
490
  }
482
491
  catch (e) {
483
492
  console.error(e);
484
493
  }
494
+ s[_passive] = false;
495
+ if (s[_stopImmediatePropagationCalled])
496
+ break;
485
497
  }
498
+ if (onceIndexes.length > 0) {
499
+ this[_executors] = this[_executors].reduce((acc, cur, index) => {
500
+ if (onceIndexes.indexOf(index) === -1)
501
+ acc.push(cur);
502
+ return acc;
503
+ }, []);
504
+ }
505
+ s.currentTarget = null;
506
+ s.eventPhase = EventP.NONE;
507
+ s[_dispatched] = false;
508
+ return !(event.cancelable && s[_preventDefaultCalled]);
486
509
  }
487
- class Executor {
488
- static extract(cb) {
489
- if (typeof cb === "function") {
490
- return cb;
491
- }
492
- else if (isEventListenerObject(cb)) {
493
- return cb.handleEvent;
494
- }
495
- else {
496
- return cb;
497
- }
510
+ function reply(signal, executor) {
511
+ const onAbort = () => {
512
+ this[_executors] = this[_executors].filter(x => !x.equals(executor));
513
+ signal.removeEventListener("abort", onAbort);
514
+ };
515
+ try {
516
+ signal.addEventListener("abort", onAbort);
498
517
  }
518
+ catch (e) {
519
+ console.error(e);
520
+ }
521
+ }
522
+ class Executor {
499
523
  constructor(type, callback) {
524
+ this.options = {};
500
525
  this.type = String(type);
501
- this.callback = Executor.extract(callback);
526
+ this.callback = extract(callback);
502
527
  }
503
- type;
504
- callback;
505
- options = {};
506
528
  equals(executor) {
507
529
  return Object.is(this.type, executor.type) && Object.is(this.callback, executor.callback)
508
530
  && Object.is(this.options.capture, executor.options.capture);
509
531
  }
510
532
  }
533
+ function extract(cb) {
534
+ if (typeof cb === "function") {
535
+ return cb;
536
+ }
537
+ else if (isEventListenerObject(cb)) {
538
+ return cb.handleEvent;
539
+ }
540
+ else {
541
+ return cb;
542
+ }
543
+ }
511
544
  function isEventListenerObject(cb) {
512
545
  return !!cb && "handleEvent" in cb && typeof cb.handleEvent === "function";
513
546
  }
@@ -525,54 +558,77 @@ function executeFn(cb, ev) {
525
558
  }
526
559
  const EventTargetE = g["EventTarget"] || EventTargetP;
527
560
 
528
- const state$6 = Symbol("CustomEventState");
561
+ const state$e = Symbol( /* "CustomEventState" */);
529
562
  class CustomEventP extends EventP {
530
563
  constructor(type, eventInitDict) {
564
+ var _a;
531
565
  super(type, eventInitDict);
532
- this[state$6] = new CustomEventState();
533
- this[state$6].detail = eventInitDict?.detail ?? null;
566
+ this[state$e] = new CustomEventState();
567
+ this[state$e].detail = (_a = eventInitDict === null || eventInitDict === void 0 ? void 0 : eventInitDict.detail) !== null && _a !== void 0 ? _a : null;
534
568
  }
535
- [state$6];
536
- get detail() { return this[state$6].detail; }
569
+ get detail() { return this[state$e].detail; }
537
570
  initCustomEvent(type, bubbles, cancelable, detail) {
538
- if (this[state$9]._dispatched)
571
+ if (this[state$g][_dispatched])
539
572
  return;
540
573
  this.initEvent(type, bubbles, cancelable);
541
- this[state$6].detail = detail ?? null;
574
+ this[state$e].detail = detail !== null && detail !== void 0 ? detail : null;
542
575
  }
543
576
  toString() { return "[object CustomEvent]"; }
544
577
  get isPolyfill() { return { symbol: polyfill, hierarchy: ["CustomEvent", "Event"] }; }
545
578
  }
546
579
  defineStringTag(CustomEventP, "CustomEvent");
547
580
  class CustomEventState {
548
- detail;
549
581
  }
550
582
  const CustomEventE = g["EventTarget"] ? g["CustomEvent"] : CustomEventP;
551
583
 
552
- const state$5 = Symbol("ProgressEventState");
584
+ const state$d = Symbol( /* "ProgressEventState" */);
553
585
  class ProgressEventP extends EventP {
554
586
  constructor(type, eventInitDict) {
587
+ var _a, _b;
555
588
  super(type, eventInitDict);
556
- this[state$5] = new ProgressEventState();
557
- this[state$5].lengthComputable = !!eventInitDict?.lengthComputable;
558
- this[state$5].loaded = eventInitDict?.loaded ?? 0;
559
- this[state$5].total = eventInitDict?.total ?? 0;
560
- }
561
- [state$5];
562
- get lengthComputable() { return this[state$5].lengthComputable; }
563
- get loaded() { return this[state$5].loaded; }
564
- get total() { return this[state$5].total; }
589
+ this[state$d] = new ProgressEventState();
590
+ const that = this[state$d];
591
+ that.lengthComputable = !!(eventInitDict === null || eventInitDict === void 0 ? void 0 : eventInitDict.lengthComputable);
592
+ that.loaded = (_a = eventInitDict === null || eventInitDict === void 0 ? void 0 : eventInitDict.loaded) !== null && _a !== void 0 ? _a : 0;
593
+ that.total = (_b = eventInitDict === null || eventInitDict === void 0 ? void 0 : eventInitDict.total) !== null && _b !== void 0 ? _b : 0;
594
+ }
595
+ get lengthComputable() { return getValue(this[state$d].lengthComputable); }
596
+ get loaded() { return getValue(this[state$d].loaded); }
597
+ get total() { return getValue(this[state$d].total); }
565
598
  toString() { return "[object ProgressEvent]"; }
566
599
  get isPolyfill() { return { symbol: polyfill, hierarchy: ["ProgressEvent", "Event"] }; }
567
600
  }
568
601
  defineStringTag(ProgressEventP, "ProgressEvent");
569
602
  class ProgressEventState {
570
- lengthComputable = false;
571
- loaded = 0;
572
- total = 0;
603
+ constructor() {
604
+ this.lengthComputable = false;
605
+ this.loaded = 0;
606
+ this.total = 0;
607
+ }
608
+ }
609
+ function getValue(val) {
610
+ return typeof val === "function" ? val() : val;
611
+ }
612
+ function createInnerProgressEvent(target, type, { lengthComputable = false, loaded = 0, total = 0, } = {}) {
613
+ const event = new ProgressEventP(type);
614
+ event[state$d].lengthComputable = lengthComputable;
615
+ event[state$d].loaded = loaded;
616
+ event[state$d].total = total;
617
+ event[state$g].target = target;
618
+ event[state$g][_isTrusted] = true;
619
+ return event;
620
+ }
621
+ function emitProcessEvent(target, type, loaded = 0, total = 0) {
622
+ const event = createInnerProgressEvent(target, type, {
623
+ lengthComputable: () => { return getValue(total) > 0; },
624
+ loaded,
625
+ total,
626
+ });
627
+ fire.call(target[state$f], event);
573
628
  }
574
629
  const ProgressEventE = g["EventTarget"] ? g["ProgressEvent"] : ProgressEventP;
575
630
 
631
+ const state$c = Symbol( /* "BlobState" */);
576
632
  class BlobP {
577
633
  constructor(blobParts = [], options) {
578
634
  if (!Array.isArray(blobParts)) {
@@ -581,7 +637,7 @@ class BlobP {
581
637
  let encoder = null;
582
638
  let chunks = blobParts.reduce((chunks, part) => {
583
639
  if (isPolyfillType("Blob", part)) {
584
- chunks.push(part[state$9]._u8array);
640
+ chunks.push(part[state$c][_u8array]);
585
641
  }
586
642
  else if (part instanceof ArrayBuffer || ArrayBuffer.isView(part)) {
587
643
  chunks.push(convert$1(part));
@@ -594,42 +650,42 @@ class BlobP {
594
650
  }
595
651
  return chunks;
596
652
  }, []);
597
- this[state$9] = new BlobState(concat(chunks));
598
- this[state$9].size = this[state$9]._u8array.length;
599
- const rawType = options?.type || "";
600
- this[state$9].type = /[^\u0020-\u007E]/.test(rawType) ? "" : rawType.toLowerCase();
601
- }
602
- [state$9];
603
- get size() { return this[state$9].size; }
604
- get type() { return this[state$9].type; }
653
+ this[state$c] = new BlobState(concat(chunks));
654
+ const that = this[state$c];
655
+ that.size = that[_u8array].length;
656
+ const rawType = (options === null || options === void 0 ? void 0 : options.type) || "";
657
+ that.type = /[^\u0020-\u007E]/.test(rawType) ? "" : rawType.toLowerCase();
658
+ }
659
+ get size() { return this[state$c].size; }
660
+ get type() { return this[state$c].type; }
605
661
  arrayBuffer() {
606
- return Promise.resolve(clone(this[state$9]._u8array.buffer).buffer);
662
+ return Promise.resolve(clone(this[state$c][_u8array].buffer).buffer);
607
663
  }
608
664
  bytes() {
609
- return Promise.resolve(clone(this[state$9]._u8array.buffer));
665
+ return Promise.resolve(clone(this[state$c][_u8array].buffer));
610
666
  }
611
667
  slice(start, end, contentType) {
612
- const sliced = this[state$9]._u8array.slice(start ?? 0, end ?? this[state$9]._u8array.length);
613
- return new BlobP([sliced], { type: contentType ?? "" });
668
+ const sliced = this[state$c][_u8array].slice(start !== null && start !== void 0 ? start : 0, end !== null && end !== void 0 ? end : this[state$c][_u8array].length);
669
+ return new BlobP([sliced], { type: contentType !== null && contentType !== void 0 ? contentType : "" });
614
670
  }
615
671
  stream() {
616
672
  throw new ReferenceError("ReadableStream is not defined");
617
673
  }
618
674
  text() {
619
675
  const decoder = new TextDecoderP();
620
- return Promise.resolve(decoder.decode(this[state$9]._u8array));
676
+ return Promise.resolve(decoder.decode(this[state$c][_u8array]));
621
677
  }
622
678
  toString() { return "[object Blob]"; }
623
679
  get isPolyfill() { return { symbol: polyfill, hierarchy: ["Blob"] }; }
624
680
  }
625
681
  defineStringTag(BlobP, "Blob");
682
+ const _u8array = Symbol();
626
683
  class BlobState {
627
684
  constructor(buffer) {
628
- this._u8array = buffer;
685
+ this.size = 0;
686
+ this.type = "";
687
+ this[_u8array] = buffer;
629
688
  }
630
- size = 0;
631
- type = "";
632
- _u8array;
633
689
  }
634
690
  function u8array2base64(input) {
635
691
  let byteToCharMap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
@@ -676,151 +732,151 @@ function concat(chunks) {
676
732
  }
677
733
  const BlobE = g["Blob"] || BlobP;
678
734
 
679
- const state$4 = Symbol("FileState");
735
+ const state$b = Symbol( /* "FileState" */);
680
736
  class FileP extends BlobP {
681
737
  constructor(fileBits, fileName, options) {
682
738
  super(fileBits, options);
683
- this[state$4] = new FileState();
684
- this[state$4].lastModified = +(options?.lastModified ? new Date(options.lastModified) : new Date());
685
- this[state$4].name = fileName.replace(/\//g, ":");
739
+ this[state$b] = new FileState();
740
+ this[state$b].lastModified = +((options === null || options === void 0 ? void 0 : options.lastModified) ? new Date(options.lastModified) : new Date());
741
+ this[state$b].name = fileName.replace(/\//g, ":");
686
742
  }
687
- [state$4];
688
- get lastModified() { return this[state$4].lastModified; }
689
- get name() { return this[state$4].name; }
743
+ get lastModified() { return this[state$b].lastModified; }
744
+ get name() { return this[state$b].name; }
690
745
  get webkitRelativePath() { return ""; }
691
746
  toString() { return "[object File]"; }
692
747
  get isPolyfill() { return { symbol: polyfill, hierarchy: ["File", "Blob"] }; }
693
748
  }
694
749
  defineStringTag(FileP, "File");
695
750
  class FileState {
696
- lastModified = 0;
697
- name = "";
751
+ constructor() {
752
+ this.lastModified = 0;
753
+ this.name = "";
754
+ }
698
755
  }
699
756
  const FileE = g["Blob"] ? g["File"] : FileP;
700
757
 
701
- const state$3 = Symbol("FileReaderState");
758
+ var _a$7;
759
+ const state$a = Symbol( /* "FileReaderState" */);
702
760
  class FileReaderP extends EventTargetP {
703
- static EMPTY = 0;
704
- static LOADING = 1;
705
- static DONE = 2;
706
761
  constructor() {
707
762
  super();
708
- this[state$3] = new FileReaderState(this);
709
- }
710
- [state$3];
711
- get readyState() { return this[state$3].readyState; }
712
- get result() { return this[state$3].result; }
713
- EMPTY = 0;
714
- LOADING = 1;
715
- DONE = 2;
716
- get error() { return this[state$3].error; }
763
+ this.EMPTY = 0;
764
+ this.LOADING = 1;
765
+ this.DONE = 2;
766
+ this[state$a] = new FileReaderState(this);
767
+ }
768
+ get readyState() { return this[state$a].readyState; }
769
+ get result() { return this[state$a].result; }
770
+ get error() { return this[state$a].error; }
717
771
  abort() {
718
772
  if (this.readyState === FileReaderP.LOADING) {
719
- this[state$3].readyState = FileReaderP.DONE;
720
- this[state$3].result = null;
721
- this[state$3].emitProcessEvent("abort");
773
+ this[state$a].readyState = FileReaderP.DONE;
774
+ this[state$a].result = null;
775
+ emitProcessEvent(this, "abort");
722
776
  }
723
777
  }
724
- readAsArrayBuffer = (blob) => {
725
- this[state$3].read("readAsArrayBuffer", blob, () => {
726
- this[state$3].result = blob[state$9]._u8array.buffer.slice(0);
778
+ readAsArrayBuffer(blob) {
779
+ read$1.call(this[state$a], "readAsArrayBuffer", blob, () => {
780
+ this[state$a].result = blob[state$c][_u8array].buffer.slice(0);
727
781
  });
728
- };
729
- readAsBinaryString = (blob) => {
730
- this[state$3].read("readAsBinaryString", blob, () => {
731
- this[state$3].result = blob[state$9]._u8array.reduce((acc, cur) => {
782
+ }
783
+ readAsBinaryString(blob) {
784
+ read$1.call(this[state$a], "readAsBinaryString", blob, () => {
785
+ this[state$a].result = blob[state$c][_u8array].reduce((acc, cur) => {
732
786
  acc += String.fromCharCode(cur);
733
787
  return acc;
734
788
  }, "");
735
789
  });
736
- };
737
- readAsDataURL = (blob) => {
738
- this[state$3].read("readAsDataURL", blob, () => {
739
- this[state$3].result = "data:" + blob.type + ";base64," + u8array2base64(blob[state$9]._u8array);
790
+ }
791
+ readAsDataURL(blob) {
792
+ read$1.call(this[state$a], "readAsDataURL", blob, () => {
793
+ this[state$a].result = "data:" + blob.type + ";base64," + u8array2base64(blob[state$c][_u8array]);
740
794
  });
741
- };
742
- readAsText = (blob, encoding) => {
743
- this[state$3].read("readAsText", blob, () => {
744
- this[state$3].result = (new TextDecoderP(encoding)).decode(blob[state$9]._u8array);
795
+ }
796
+ readAsText(blob, encoding) {
797
+ read$1.call(this[state$a], "readAsText", blob, () => {
798
+ this[state$a].result = (new TextDecoderP(encoding)).decode(blob[state$c][_u8array]);
745
799
  });
746
- };
747
- get onabort() { return this[state$3].onabort; }
748
- set onabort(value) { this[state$3].onabort = value; this[state$3].attach("abort"); }
749
- get onerror() { return this[state$3].onerror; }
750
- set onerror(value) { this[state$3].onerror = value; this[state$3].attach("error"); }
751
- get onload() { return this[state$3].onload; }
752
- set onload(value) { this[state$3].onload = value; this[state$3].attach("load"); }
753
- get onloadend() { return this[state$3].onloadend; }
754
- set onloadend(value) { this[state$3].onloadend = value; this[state$3].attach("loadend"); }
755
- get onloadstart() { return this[state$3].onloadstart; }
756
- set onloadstart(value) { this[state$3].onloadstart = value; this[state$3].attach("loadstart"); }
757
- get onprogress() { return this[state$3].onprogress; }
758
- set onprogress(value) { this[state$3].onprogress = value; this[state$3].attach("progress"); }
800
+ }
801
+ get onabort() { return this[state$a].onabort; }
802
+ set onabort(value) { this[state$a].onabort = value; attach$1.call(this[state$a], "abort"); }
803
+ get onerror() { return this[state$a].onerror; }
804
+ set onerror(value) { this[state$a].onerror = value; attach$1.call(this[state$a], "error"); }
805
+ get onload() { return this[state$a].onload; }
806
+ set onload(value) { this[state$a].onload = value; attach$1.call(this[state$a], "load"); }
807
+ get onloadend() { return this[state$a].onloadend; }
808
+ set onloadend(value) { this[state$a].onloadend = value; attach$1.call(this[state$a], "loadend"); }
809
+ get onloadstart() { return this[state$a].onloadstart; }
810
+ set onloadstart(value) { this[state$a].onloadstart = value; attach$1.call(this[state$a], "loadstart"); }
811
+ get onprogress() { return this[state$a].onprogress; }
812
+ set onprogress(value) { this[state$a].onprogress = value; attach$1.call(this[state$a], "progress"); }
759
813
  toString() { return "[object FileReader]"; }
760
814
  get isPolyfill() { return { symbol: polyfill, hierarchy: ["FileReader", "EventTarget"] }; }
761
815
  }
816
+ FileReaderP.EMPTY = 0;
817
+ FileReaderP.LOADING = 1;
818
+ FileReaderP.DONE = 2;
762
819
  defineStringTag(FileReaderP, "FileReader");
820
+ const _handlers$3 = Symbol();
763
821
  class FileReaderState {
764
822
  constructor(target) {
823
+ this.readyState = FileReaderP.EMPTY;
824
+ this.result = null;
825
+ this.error = null;
826
+ this[_a$7] = getHandlers$3.call(this);
827
+ this.onabort = null;
828
+ this.onerror = null;
829
+ this.onload = null;
830
+ this.onloadend = null;
831
+ this.onloadstart = null;
832
+ this.onprogress = null;
765
833
  this.target = target;
766
834
  }
767
- target;
768
- readyState = FileReaderP.EMPTY;
769
- result = null;
770
- error = null;
771
- read(kind, blob, setResult) {
772
- if (!isPolyfillType("Blob", blob)) {
773
- throw new TypeError("Failed to execute '" + kind + "' on 'FileReader': parameter 1 is not of type 'Blob'.");
774
- }
775
- this.error = null;
776
- this.readyState = FileReaderP.LOADING;
777
- this.emitProcessEvent("loadstart", 0, blob.size);
778
- setTimeout(() => {
779
- if (this.readyState === FileReaderP.LOADING) {
780
- this.readyState = FileReaderP.DONE;
781
- try {
782
- setResult();
783
- this.emitProcessEvent("load", blob.size, blob.size);
784
- }
785
- catch (e) {
786
- this.result = null;
787
- this.error = e;
788
- this.emitProcessEvent("error", 0, blob.size);
789
- }
790
- }
791
- this.emitProcessEvent("loadend", !!this.result ? blob.size : 0, blob.size);
792
- });
835
+ }
836
+ _a$7 = _handlers$3;
837
+ function read$1(kind, blob, setResult) {
838
+ if (!isPolyfillType("Blob", blob)) {
839
+ throw new TypeError("Failed to execute '" + kind + "' on 'FileReader': parameter 1 is not of type 'Blob'.");
793
840
  }
794
- emitProcessEvent(type, loaded = 0, total = 0) {
795
- const event = new ProgressEventP(type, {
796
- lengthComputable: total > 0,
797
- loaded,
798
- total,
799
- });
800
- event[state$9].target = this.target;
801
- event[state$9].isTrusted = true;
802
- this.target[state$7].fire(event);
803
- }
804
- attach(type) {
805
- const cb = this[("on" + type)];
806
- const listener = this[("_on" + type)];
807
- attachFn.call(this.target, type, cb, listener);
808
- }
809
- onabort = null;
810
- _onabort = (ev) => { executeFn.call(this.target, this.onabort, ev); };
811
- onerror = null;
812
- _onerror = (ev) => { executeFn.call(this.target, this.onerror, ev); };
813
- onload = null;
814
- _onload = (ev) => { executeFn.call(this.target, this.onload, ev); };
815
- onloadend = null;
816
- _onloadend = (ev) => { executeFn.call(this.target, this.onloadend, ev); };
817
- onloadstart = null;
818
- _onloadstart = (ev) => { executeFn.call(this.target, this.onloadstart, ev); };
819
- onprogress = null;
820
- _onprogress = (ev) => { executeFn.call(this.target, this.onprogress, ev); };
841
+ this.error = null;
842
+ this.readyState = FileReaderP.LOADING;
843
+ emitProcessEvent(this.target, "loadstart", 0, blob.size);
844
+ setTimeout(() => {
845
+ if (this.readyState === FileReaderP.LOADING) {
846
+ this.readyState = FileReaderP.DONE;
847
+ try {
848
+ setResult();
849
+ emitProcessEvent(this.target, "load", blob.size, blob.size);
850
+ }
851
+ catch (e) {
852
+ this.result = null;
853
+ this.error = e;
854
+ emitProcessEvent(this.target, "error", 0, blob.size);
855
+ }
856
+ }
857
+ emitProcessEvent(this.target, "loadend", !!this.result ? blob.size : 0, blob.size);
858
+ });
859
+ }
860
+ function attach$1(type) {
861
+ const fnName = ("on" + type);
862
+ const cb = this[fnName];
863
+ const listener = this[_handlers$3][fnName];
864
+ attachFn.call(this.target, type, cb, listener);
865
+ }
866
+ function getHandlers$3() {
867
+ return {
868
+ onabort: (ev) => { executeFn.call(this.target, this.onabort, ev); },
869
+ onerror: (ev) => { executeFn.call(this.target, this.onerror, ev); },
870
+ onload: (ev) => { executeFn.call(this.target, this.onload, ev); },
871
+ onloadend: (ev) => { executeFn.call(this.target, this.onloadend, ev); },
872
+ onloadstart: (ev) => { executeFn.call(this.target, this.onloadstart, ev); },
873
+ onprogress: (ev) => { executeFn.call(this.target, this.onprogress, ev); },
874
+ };
821
875
  }
822
876
  const FileReaderE = g["Blob"] ? g["FileReader"] : FileReaderP;
823
877
 
878
+ var _a$6;
879
+ const state$9 = Symbol( /* "FormDataState" */);
824
880
  class FormDataP {
825
881
  constructor(form, submitter) {
826
882
  if (form !== void 0) {
@@ -831,20 +887,19 @@ class FormDataP {
831
887
  }
832
888
  this[state$9] = new FormDataState();
833
889
  }
834
- [state$9];
835
890
  append(name, value, filename) {
836
- this[state$9]._data.push(normalizeArgs(name, value, filename));
891
+ this[state$9][_formData].push(normalizeArgs(name, value, filename));
837
892
  }
838
893
  delete(name) {
839
894
  const result = [];
840
895
  name = String(name);
841
- each(this[state$9]._data, entry => {
896
+ each(this[state$9][_formData], entry => {
842
897
  entry[0] !== name && result.push(entry);
843
898
  });
844
- this[state$9]._data = result;
899
+ this[state$9][_formData] = result;
845
900
  }
846
901
  get(name) {
847
- const entries = this[state$9]._data;
902
+ const entries = this[state$9][_formData];
848
903
  name = String(name);
849
904
  for (let i = 0; i < entries.length; ++i) {
850
905
  if (entries[i][0] === name) {
@@ -856,15 +911,15 @@ class FormDataP {
856
911
  getAll(name) {
857
912
  const result = [];
858
913
  name = String(name);
859
- each(this[state$9]._data, data => {
914
+ each(this[state$9][_formData], data => {
860
915
  data[0] === name && result.push(data[1]);
861
916
  });
862
917
  return result;
863
918
  }
864
919
  has(name) {
865
920
  name = String(name);
866
- for (let i = 0; i < this[state$9]._data.length; ++i) {
867
- if (this[state$9]._data[i][0] === name) {
921
+ for (let i = 0; i < this[state$9][_formData].length; ++i) {
922
+ if (this[state$9][_formData][i][0] === name) {
868
923
  return true;
869
924
  }
870
925
  }
@@ -875,13 +930,13 @@ class FormDataP {
875
930
  const result = [];
876
931
  const args = normalizeArgs(name, value, filename);
877
932
  let replace = true;
878
- each(this[state$9]._data, data => {
933
+ each(this[state$9][_formData], data => {
879
934
  data[0] === name
880
935
  ? replace && (replace = !result.push(args))
881
936
  : result.push(data);
882
937
  });
883
938
  replace && result.push(args);
884
- this[state$9]._data = result;
939
+ this[state$9][_formData] = result;
885
940
  }
886
941
  forEach(callbackfn, thisArg) {
887
942
  for (const [name, value] of this) {
@@ -889,13 +944,13 @@ class FormDataP {
889
944
  }
890
945
  }
891
946
  entries() {
892
- return this[state$9]._data.values();
947
+ return this[state$9][_formData].values();
893
948
  }
894
949
  keys() {
895
- return this[state$9]._data.map(x => x[0]).values();
950
+ return this[state$9][_formData].map(x => x[0]).values();
896
951
  }
897
952
  values() {
898
- return this[state$9]._data.map(x => x[1]).values();
953
+ return this[state$9][_formData].map(x => x[1]).values();
899
954
  }
900
955
  [Symbol.iterator]() {
901
956
  return this.entries();
@@ -904,13 +959,16 @@ class FormDataP {
904
959
  get isPolyfill() { return { symbol: polyfill, hierarchy: ["FormData"] }; }
905
960
  }
906
961
  defineStringTag(FormDataP, "FormData");
962
+ const _formData = Symbol();
907
963
  class FormDataState {
908
- _data = [];
964
+ constructor() {
965
+ this[_a$6] = [];
966
+ }
909
967
  toBlob() {
910
968
  const boundary = "----formdata-polyfill-" + Math.random();
911
969
  const p = `--${boundary}\r\nContent-Disposition: form-data; name="`;
912
970
  let chunks = [];
913
- for (const [name, value] of this._data.values()) {
971
+ for (const [name, value] of this[_formData].values()) {
914
972
  if (typeof value === "string") {
915
973
  chunks.push(p + escape(normalizeLinefeeds(name)) + `"\r\n\r\n${normalizeLinefeeds(value)}\r\n`);
916
974
  }
@@ -924,6 +982,7 @@ class FormDataState {
924
982
  });
925
983
  }
926
984
  }
985
+ _a$6 = _formData;
927
986
  function normalizeArgs(name, value, filename) {
928
987
  if (isPolyfillType("Blob", value)) {
929
988
  filename = filename !== undefined
@@ -954,7 +1013,7 @@ function escape(str) {
954
1013
  * @param body - Text in multipart/form-data format (including boundaries and data)
955
1014
  * @returns Parsed FormData object (text fields as strings, files as File objects)
956
1015
  */
957
- function createFormData(body) {
1016
+ function createFormDataFromBody(body, errMsg = "Failed to fetch") {
958
1017
  const formData = new FormDataP();
959
1018
  if (typeof body !== "string" || body.trim() === "") {
960
1019
  return formData;
@@ -963,7 +1022,7 @@ function createFormData(body) {
963
1022
  const firstLineEnd = body.indexOf("\r\n");
964
1023
  if (firstLineEnd === -1) {
965
1024
  // Invalid multipart format: Missing line break in header
966
- throw new TypeError("Failed to fetch");
1025
+ throw new TypeError(errMsg);
967
1026
  }
968
1027
  const boundary = body.substring(2, firstLineEnd).trim();
969
1028
  if (!boundary) {
@@ -977,7 +1036,7 @@ function createFormData(body) {
977
1036
  });
978
1037
  if (parts.length === 0) {
979
1038
  // Invalid multipart format: No parts found
980
- throw new TypeError("Failed to fetch");
1039
+ throw new TypeError(errMsg);
981
1040
  }
982
1041
  // 3. Parse each part
983
1042
  parts.forEach(part => {
@@ -985,7 +1044,7 @@ function createFormData(body) {
985
1044
  const separatorIndex = part.indexOf("\r\n\r\n");
986
1045
  if (separatorIndex === -1) {
987
1046
  // Invalid part format: Missing header-content separator
988
- throw new TypeError("Failed to fetch");
1047
+ throw new TypeError(errMsg);
989
1048
  }
990
1049
  // Extract header (Content-Disposition and Content-Type)
991
1050
  const headerRaw = part.substring(0, separatorIndex).trim();
@@ -996,7 +1055,7 @@ function createFormData(body) {
996
1055
  const contentTypeMatch = headerRaw.match(/Content-Type: ([^\r\n]+)/); // MIME type (optional)
997
1056
  if (!nameMatch || !nameMatch[1]) {
998
1057
  // Invalid part format: Missing field name
999
- throw new TypeError("Failed to fetch");
1058
+ throw new TypeError(errMsg);
1000
1059
  }
1001
1060
  const fieldName = nameMatch[1];
1002
1061
  const isFile = !!filenameMatch; // Whether it's a file field
@@ -1017,7 +1076,7 @@ function createFormData(body) {
1017
1076
  }
1018
1077
  catch (e) {
1019
1078
  // `Failed to process file field "${fieldName}": ${(e as Error).message}`
1020
- throw new TypeError("Failed to fetch");
1079
+ throw new TypeError(errMsg);
1021
1080
  }
1022
1081
  }
1023
1082
  else {
@@ -1030,25 +1089,26 @@ function createFormData(body) {
1030
1089
  }
1031
1090
  const FormDataE = g["FormData"] || FormDataP;
1032
1091
 
1092
+ var _a$5;
1093
+ const state$8 = Symbol( /* "URLSearchParamsState" */);
1033
1094
  class URLSearchParamsP {
1034
1095
  constructor(init) {
1035
1096
  let search = init || "";
1036
1097
  if (isObjectType("URLSearchParams", search)) {
1037
1098
  search = search.toString();
1038
1099
  }
1039
- this[state$9] = new URLSearchParamsState();
1040
- this[state$9]._dict = parseToDict(search);
1100
+ this[state$8] = new URLSearchParamsState();
1101
+ this[state$8][_urlspDict] = parseToDict(search);
1041
1102
  }
1042
- [state$9];
1043
1103
  get size() {
1044
- return Object.values(this[state$9]._dict).reduce((acc, cur) => acc + cur.length, 0);
1104
+ return objectValues(this[state$8][_urlspDict]).reduce((acc, cur) => acc + cur.length, 0);
1045
1105
  }
1046
1106
  append(name, value) {
1047
- appendTo(this[state$9]._dict, name, value);
1107
+ appendTo(this[state$8][_urlspDict], name, value);
1048
1108
  }
1049
1109
  delete(name, value) {
1050
1110
  let dict = {};
1051
- for (let [key, values] of Object.entries(this[state$9]._dict)) {
1111
+ for (let [key, values] of objectEntries(this[state$8][_urlspDict])) {
1052
1112
  if (key === name) {
1053
1113
  if (value !== undefined) {
1054
1114
  let vals = values.filter(x => x !== ("" + value));
@@ -1059,64 +1119,66 @@ class URLSearchParamsP {
1059
1119
  }
1060
1120
  Object.assign(dict, { [key]: values });
1061
1121
  }
1062
- this[state$9]._dict = dict;
1122
+ this[state$8][_urlspDict] = dict;
1063
1123
  }
1064
1124
  get(name) {
1065
- return this.has(name) ? this[state$9]._dict[name][0] ?? null : null;
1125
+ var _b;
1126
+ return this.has(name) ? (_b = this[state$8][_urlspDict][name][0]) !== null && _b !== void 0 ? _b : null : null;
1066
1127
  }
1067
1128
  getAll(name) {
1068
- return this.has(name) ? this[state$9]._dict[name].slice(0) : [];
1129
+ return this.has(name) ? this[state$8][_urlspDict][name].slice(0) : [];
1069
1130
  }
1070
1131
  has(name, value) {
1071
- if (hasOwnProperty(this[state$9]._dict, name)) {
1132
+ if (hasOwnProperty(this[state$8][_urlspDict], name)) {
1072
1133
  if (value !== undefined) {
1073
- return this[state$9]._dict[name].includes(("" + value));
1134
+ return this[state$8][_urlspDict][name].indexOf(("" + value)) > -1;
1074
1135
  }
1075
1136
  return true;
1076
1137
  }
1077
1138
  return false;
1078
1139
  }
1079
1140
  set(name, value) {
1080
- this[state$9]._dict[name] = ["" + value];
1141
+ this[state$8][_urlspDict][name] = ["" + value];
1081
1142
  }
1082
1143
  sort() {
1083
- let keys = Object.keys(this[state$9]._dict);
1144
+ const that = this[state$8];
1145
+ let keys = Object.keys(that[_urlspDict]);
1084
1146
  keys.sort();
1085
1147
  let dict = {};
1086
1148
  for (let key of keys) {
1087
- Object.assign(dict, { [key]: this[state$9]._dict[key] });
1149
+ Object.assign(dict, { [key]: that[_urlspDict][key] });
1088
1150
  }
1089
- this[state$9]._dict = dict;
1151
+ that[_urlspDict] = dict;
1090
1152
  }
1091
1153
  forEach(callbackfn, thisArg) {
1092
- Object.entries(this[state$9]._dict).forEach(([key, values]) => {
1154
+ objectEntries(this[state$8][_urlspDict]).forEach(([key, values]) => {
1093
1155
  values.forEach(value => {
1094
1156
  callbackfn.call(thisArg, value, key, this);
1095
1157
  });
1096
1158
  });
1097
1159
  }
1098
1160
  entries() {
1099
- return Object.entries(this[state$9]._dict)
1161
+ return objectEntries(this[state$8][_urlspDict])
1100
1162
  .map(([key, values]) => {
1101
1163
  return values.map(value => {
1102
1164
  return [key, value];
1103
1165
  });
1104
1166
  })
1105
- .flat()
1167
+ .reduce(flatCb, [])
1106
1168
  .values();
1107
1169
  }
1108
1170
  keys() {
1109
- return Object.keys(this[state$9]._dict).values();
1171
+ return Object.keys(this[state$8][_urlspDict]).values();
1110
1172
  }
1111
1173
  values() {
1112
- return Object.values(this[state$9]._dict).flat().values();
1174
+ return objectValues(this[state$8][_urlspDict]).reduce(flatCb, []).values();
1113
1175
  }
1114
1176
  [Symbol.iterator]() {
1115
1177
  return this.entries();
1116
1178
  }
1117
1179
  toString() {
1118
1180
  let query = [];
1119
- for (let [key, values] of Object.entries(this[state$9]._dict)) {
1181
+ for (let [key, values] of objectEntries(this[state$8][_urlspDict])) {
1120
1182
  let name = encode$1(key);
1121
1183
  for (let val of values) {
1122
1184
  query.push(name + "=" + encode$1(val));
@@ -1127,9 +1189,13 @@ class URLSearchParamsP {
1127
1189
  get isPolyfill() { return { symbol: polyfill, hierarchy: ["URLSearchParams"] }; }
1128
1190
  }
1129
1191
  defineStringTag(URLSearchParamsP, "URLSearchParams");
1192
+ const _urlspDict = Symbol();
1130
1193
  class URLSearchParamsState {
1131
- _dict = {};
1194
+ constructor() {
1195
+ this[_a$5] = {};
1196
+ }
1132
1197
  }
1198
+ _a$5 = _urlspDict;
1133
1199
  function parseToDict(search) {
1134
1200
  let dict = {};
1135
1201
  if (typeof search === "object") {
@@ -1203,26 +1269,34 @@ function decode$1(str) {
1203
1269
  function hasOwnProperty(obj, prop) {
1204
1270
  return Object.prototype.hasOwnProperty.call(obj, prop);
1205
1271
  }
1272
+ function flatCb(acc, cur) {
1273
+ for (const item of cur) {
1274
+ acc.push(item);
1275
+ }
1276
+ return acc;
1277
+ }
1206
1278
  const URLSearchParamsE = g["URLSearchParams"] || URLSearchParamsP;
1207
1279
 
1280
+ var _a$4;
1281
+ const state$7 = Symbol( /* "AbortSignalState" */);
1208
1282
  class AbortSignalP extends EventTargetP {
1209
1283
  static abort(reason) {
1210
1284
  const signal = createAbortSignalP();
1211
- signal[state$9].abort(reason, false);
1285
+ abort.call(signal[state$7], reason, false);
1212
1286
  return signal;
1213
1287
  }
1214
1288
  static any(signals) {
1215
1289
  const signal = createAbortSignalP();
1216
1290
  const abortedSignal = signals.find(x => x.aborted);
1217
1291
  if (abortedSignal) {
1218
- signal[state$9].abort(abortedSignal.reason, false);
1292
+ abort.call(signal[state$7], abortedSignal.reason, false);
1219
1293
  }
1220
1294
  else {
1221
1295
  function abortFn(ev) {
1222
1296
  for (const sig of signals) {
1223
1297
  sig.removeEventListener("abort", abortFn);
1224
1298
  }
1225
- signal[state$9].abort(this.reason, true, ev.isTrusted);
1299
+ abort.call(signal[state$7], this.reason, true, ev.isTrusted);
1226
1300
  }
1227
1301
  for (const sig of signals) {
1228
1302
  sig.addEventListener("abort", abortFn);
@@ -1233,7 +1307,7 @@ class AbortSignalP extends EventTargetP {
1233
1307
  static timeout(milliseconds) {
1234
1308
  const signal = createAbortSignalP();
1235
1309
  setTimeout(() => {
1236
- signal[state$9].abort(new MPException("signal timed out", "TimeoutError"));
1310
+ abort.call(signal[state$7], new MPException("signal timed out", "TimeoutError"));
1237
1311
  }, milliseconds);
1238
1312
  return signal;
1239
1313
  }
@@ -1242,128 +1316,140 @@ class AbortSignalP extends EventTargetP {
1242
1316
  throw new TypeError("Failed to construct 'AbortSignal': Illegal constructor");
1243
1317
  }
1244
1318
  super();
1245
- this[state$9] = new AbortSignalState(this);
1319
+ this[state$7] = new AbortSignalState(this);
1246
1320
  }
1247
- [state$9];
1248
- get aborted() { return this[state$9].aborted; }
1249
- get reason() { return this[state$9].reason; }
1321
+ get aborted() { return this[state$7].aborted; }
1322
+ get reason() { return this[state$7].reason; }
1250
1323
  throwIfAborted() {
1251
1324
  if (this.aborted) {
1252
1325
  throw this.reason;
1253
1326
  }
1254
1327
  }
1255
- get onabort() { return this[state$9].onabort; }
1328
+ get onabort() { return this[state$7].onabort; }
1256
1329
  set onabort(value) {
1257
- this[state$9].onabort = value;
1258
- attachFn.call(this, "abort", value, this[state$9]._onabort);
1330
+ this[state$7].onabort = value;
1331
+ attachFn.call(this, "abort", value, this[state$7][_handlers$2].onabort);
1259
1332
  }
1260
1333
  toString() { return "[object AbortSignal]"; }
1261
1334
  get isPolyfill() { return { symbol: polyfill, hierarchy: ["AbortSignal", "EventTarget"] }; }
1262
1335
  }
1263
1336
  defineStringTag(AbortSignalP, "AbortSignal");
1337
+ const _handlers$2 = Symbol();
1264
1338
  class AbortSignalState {
1265
1339
  constructor(target) {
1340
+ this.aborted = false;
1341
+ this.reason = undefined;
1342
+ this[_a$4] = getHandlers$2.call(this);
1343
+ this.onabort = null;
1266
1344
  this.target = target;
1267
1345
  }
1268
- target;
1269
- aborted = false;
1270
- reason = undefined;
1271
- abort(reason, notify = true, isTrusted = true) {
1272
- if (!this.aborted) {
1273
- this.aborted = true;
1274
- this.reason = reason ?? (new MPException("signal is aborted without reason", "AbortError"));
1275
- if (notify) {
1276
- const evt = new EventP("abort");
1277
- evt[state$9].target = this.target;
1278
- evt[state$9].isTrusted = isTrusted;
1279
- this.target[state$7].fire(evt);
1280
- }
1346
+ }
1347
+ _a$4 = _handlers$2;
1348
+ function abort(reason, notify = true, isTrusted = true) {
1349
+ if (!this.aborted) {
1350
+ this.aborted = true;
1351
+ this.reason = reason !== null && reason !== void 0 ? reason : (new MPException("signal is aborted without reason", "AbortError"));
1352
+ if (notify) {
1353
+ const evt = createInnerEvent(this.target, "abort", undefined, isTrusted);
1354
+ fire.call(this.target[state$f], evt);
1281
1355
  }
1282
1356
  }
1283
- onabort = null;
1284
- _onabort = (ev) => { executeFn.call(this.target, this.onabort, ev); };
1357
+ }
1358
+ function getHandlers$2() {
1359
+ return {
1360
+ onabort: (ev) => { executeFn.call(this.target, this.onabort, ev); },
1361
+ };
1285
1362
  }
1286
1363
  function createAbortSignalP() {
1287
1364
  const instance = Object.create(AbortSignalP.prototype);
1288
- instance[state$7] = new EventTargetState(instance);
1289
- instance[state$9] = new AbortSignalState(instance);
1365
+ instance[state$f] = new EventTargetState(instance);
1366
+ instance[state$7] = new AbortSignalState(instance);
1290
1367
  return instance;
1291
1368
  }
1292
1369
  const AbortSignalE = g["AbortSignal"] || AbortSignalP;
1293
1370
 
1294
- const state$2 = Symbol("AbortControllerState");
1371
+ const state$6 = Symbol( /* "AbortControllerState" */);
1295
1372
  class AbortControllerP {
1296
1373
  constructor() {
1297
- this[state$2] = new AbortControllerState();
1374
+ this[state$6] = new AbortControllerState();
1298
1375
  }
1299
- [state$2];
1300
- get signal() { return this[state$2].signal; }
1376
+ get signal() { return this[state$6].signal; }
1301
1377
  abort(reason) {
1302
- this[state$2].signal[state$9].abort(reason);
1378
+ abort.call(this[state$6].signal[state$7], reason);
1303
1379
  }
1304
1380
  toString() { return "[object AbortController]"; }
1305
1381
  get isPolyfill() { return { symbol: polyfill, hierarchy: ["AbortController"] }; }
1306
1382
  }
1307
1383
  defineStringTag(AbortControllerP, "AbortController");
1308
1384
  class AbortControllerState {
1309
- signal = createAbortSignalP();
1385
+ constructor() {
1386
+ this.signal = createAbortSignalP();
1387
+ }
1310
1388
  }
1311
1389
  const AbortControllerE = g["AbortController"] || AbortControllerP;
1312
1390
 
1391
+ var _a$3;
1392
+ const state$5 = Symbol( /* "XMLHttpRequestEventTargetState" */);
1313
1393
  class XMLHttpRequestEventTargetP extends EventTargetP {
1314
1394
  constructor() {
1315
1395
  if (new.target === XMLHttpRequestEventTargetP) {
1316
1396
  throw new TypeError("Failed to construct 'XMLHttpRequestEventTarget': Illegal constructor");
1317
1397
  }
1318
1398
  super();
1319
- this[state$9] = new XMLHttpRequestEventTargetState(this);
1320
- }
1321
- [state$9];
1322
- get onabort() { return this[state$9].onabort; }
1323
- set onabort(value) { this[state$9].onabort = value; this[state$9].attach("abort"); }
1324
- get onerror() { return this[state$9].onerror; }
1325
- set onerror(value) { this[state$9].onerror = value; this[state$9].attach("error"); }
1326
- get onload() { return this[state$9].onload; }
1327
- set onload(value) { this[state$9].onload = value; this[state$9].attach("load"); }
1328
- get onloadend() { return this[state$9].onloadend; }
1329
- set onloadend(value) { this[state$9].onloadend = value; this[state$9].attach("loadend"); }
1330
- get onloadstart() { return this[state$9].onloadstart; }
1331
- set onloadstart(value) { this[state$9].onloadstart = value; this[state$9].attach("loadstart"); }
1332
- get onprogress() { return this[state$9].onprogress; }
1333
- set onprogress(value) { this[state$9].onprogress = value; this[state$9].attach("progress"); }
1334
- get ontimeout() { return this[state$9].ontimeout; }
1335
- set ontimeout(value) { this[state$9].ontimeout = value; this[state$9].attach("timeout"); }
1399
+ this[state$5] = new XMLHttpRequestEventTargetState(this);
1400
+ }
1401
+ get onabort() { return this[state$5].onabort; }
1402
+ set onabort(value) { this[state$5].onabort = value; attach.call(this[state$5], "abort"); }
1403
+ get onerror() { return this[state$5].onerror; }
1404
+ set onerror(value) { this[state$5].onerror = value; attach.call(this[state$5], "error"); }
1405
+ get onload() { return this[state$5].onload; }
1406
+ set onload(value) { this[state$5].onload = value; attach.call(this[state$5], "load"); }
1407
+ get onloadend() { return this[state$5].onloadend; }
1408
+ set onloadend(value) { this[state$5].onloadend = value; attach.call(this[state$5], "loadend"); }
1409
+ get onloadstart() { return this[state$5].onloadstart; }
1410
+ set onloadstart(value) { this[state$5].onloadstart = value; attach.call(this[state$5], "loadstart"); }
1411
+ get onprogress() { return this[state$5].onprogress; }
1412
+ set onprogress(value) { this[state$5].onprogress = value; attach.call(this[state$5], "progress"); }
1413
+ get ontimeout() { return this[state$5].ontimeout; }
1414
+ set ontimeout(value) { this[state$5].ontimeout = value; attach.call(this[state$5], "timeout"); }
1336
1415
  toString() { return "[object XMLHttpRequestEventTarget]"; }
1337
1416
  get isPolyfill() { return { symbol: polyfill, hierarchy: ["XMLHttpRequestEventTarget", "EventTarget"] }; }
1338
1417
  }
1339
1418
  defineStringTag(XMLHttpRequestEventTargetP, "XMLHttpRequestEventTarget");
1419
+ const _handlers$1 = Symbol();
1340
1420
  class XMLHttpRequestEventTargetState {
1341
1421
  /**
1342
1422
  * @param _target XMLHttpRequestEventTargetP
1343
1423
  */
1344
1424
  constructor(_target) {
1425
+ this[_a$3] = getHandlers$1.call(this);
1426
+ this.onabort = null;
1427
+ this.onerror = null;
1428
+ this.onload = null;
1429
+ this.onloadend = null;
1430
+ this.onloadstart = null;
1431
+ this.onprogress = null;
1432
+ this.ontimeout = null;
1345
1433
  this.target = _target;
1346
1434
  }
1347
- target;
1348
- attach(type) {
1349
- const cb = this[("on" + type)];
1350
- const listener = this[("_on" + type)];
1351
- attachFn.call(this.target, type, cb, listener);
1352
- }
1353
- onabort = null;
1354
- _onabort = (ev) => { executeFn.call(this.target, this.onabort, ev); };
1355
- onerror = null;
1356
- _onerror = (ev) => { executeFn.call(this.target, this.onerror, ev); };
1357
- onload = null;
1358
- _onload = (ev) => { executeFn.call(this.target, this.onload, ev); };
1359
- onloadend = null;
1360
- _onloadend = (ev) => { executeFn.call(this.target, this.onloadend, ev); };
1361
- onloadstart = null;
1362
- _onloadstart = (ev) => { executeFn.call(this.target, this.onloadstart, ev); };
1363
- onprogress = null;
1364
- _onprogress = (ev) => { executeFn.call(this.target, this.onprogress, ev); };
1365
- ontimeout = null;
1366
- _ontimeout = (ev) => { executeFn.call(this.target, this.ontimeout, ev); };
1435
+ }
1436
+ _a$3 = _handlers$1;
1437
+ function attach(type) {
1438
+ const fnName = ("on" + type);
1439
+ const cb = this[fnName];
1440
+ const listener = this[_handlers$1][fnName];
1441
+ attachFn.call(this.target, type, cb, listener);
1442
+ }
1443
+ function getHandlers$1() {
1444
+ return {
1445
+ onabort: (ev) => { executeFn.call(this.target, this.onabort, ev); },
1446
+ onerror: (ev) => { executeFn.call(this.target, this.onerror, ev); },
1447
+ onload: (ev) => { executeFn.call(this.target, this.onload, ev); },
1448
+ onloadend: (ev) => { executeFn.call(this.target, this.onloadend, ev); },
1449
+ onloadstart: (ev) => { executeFn.call(this.target, this.onloadstart, ev); },
1450
+ onprogress: (ev) => { executeFn.call(this.target, this.onprogress, ev); },
1451
+ ontimeout: (ev) => { executeFn.call(this.target, this.ontimeout, ev); },
1452
+ };
1367
1453
  }
1368
1454
 
1369
1455
  class XMLHttpRequestUploadP extends XMLHttpRequestEventTargetP {
@@ -1379,8 +1465,8 @@ class XMLHttpRequestUploadP extends XMLHttpRequestEventTargetP {
1379
1465
  defineStringTag(XMLHttpRequestUploadP, "XMLHttpRequestUpload");
1380
1466
  function createXMLHttpRequestUploadP() {
1381
1467
  const instance = Object.create(XMLHttpRequestUploadP.prototype);
1382
- instance[state$7] = new EventTargetState(instance);
1383
- instance[state$9] = new XMLHttpRequestEventTargetState(instance);
1468
+ instance[state$f] = new EventTargetState(instance);
1469
+ instance[state$5] = new XMLHttpRequestEventTargetState(instance);
1384
1470
  return instance;
1385
1471
  }
1386
1472
 
@@ -1389,22 +1475,23 @@ const mp = (() => {
1389
1475
  let u = "undefined", r = "request", f = "function";
1390
1476
  let mp;
1391
1477
  mp =
1392
- (typeof wx !== u && typeof wx?.[r] === f && wx) || // 微信
1393
- (typeof my !== u && typeof my?.[r] === f && my) || // 支付宝
1394
- (typeof qq !== u && typeof qq?.[r] === f && qq) || // QQ
1395
- (typeof jd !== u && typeof jd?.[r] === f && jd) || // 京东
1396
- (typeof swan !== u && typeof swan?.[r] === f && swan) || // 百度
1397
- (typeof tt !== u && typeof tt?.[r] === f && tt) || // 抖音 | 飞书
1398
- (typeof ks !== u && typeof ks?.[r] === f && ks) || // 快手
1399
- (typeof qh !== u && typeof qh?.[r] === f && qh) || // 360
1478
+ (typeof wx !== u && typeof (wx === null || wx === void 0 ? void 0 : wx[r]) === f && wx) || // 微信
1479
+ (typeof my !== u && typeof (my === null || my === void 0 ? void 0 : my[r]) === f && my) || // 支付宝
1480
+ (typeof qq !== u && typeof (qq === null || qq === void 0 ? void 0 : qq[r]) === f && qq) || // QQ
1481
+ (typeof jd !== u && typeof (jd === null || jd === void 0 ? void 0 : jd[r]) === f && jd) || // 京东
1482
+ (typeof swan !== u && typeof (swan === null || swan === void 0 ? void 0 : swan[r]) === f && swan) || // 百度
1483
+ (typeof tt !== u && typeof (tt === null || tt === void 0 ? void 0 : tt[r]) === f && tt) || // 抖音 | 飞书
1484
+ (typeof ks !== u && typeof (ks === null || ks === void 0 ? void 0 : ks[r]) === f && ks) || // 快手
1485
+ (typeof qh !== u && typeof (qh === null || qh === void 0 ? void 0 : qh[r]) === f && qh) || // 360
1486
+ (typeof xhs !== u && typeof (xhs === null || xhs === void 0 ? void 0 : xhs[r]) === f && xhs) || // 小红书
1400
1487
  undefined;
1401
1488
  if (typeof g["XMLHttpRequest"] === f) {
1402
1489
  return;
1403
1490
  }
1404
1491
  if (mp === undefined)
1405
1492
  mp =
1406
- (typeof uni !== u && typeof uni?.[r] === f && uni) || // UniApp
1407
- (typeof Taro !== u && typeof Taro?.[r] === f && Taro) || // Taro
1493
+ (typeof uni !== u && typeof (uni === null || uni === void 0 ? void 0 : uni[r]) === f && uni) || // UniApp
1494
+ (typeof Taro !== u && typeof (Taro === null || Taro === void 0 ? void 0 : Taro[r]) === f && Taro) || // Taro
1408
1495
  undefined;
1409
1496
  return mp;
1410
1497
  })();
@@ -1422,300 +1509,319 @@ const request = mp ? mp.request : function errorRequest(options) {
1422
1509
  useHttpDNS: false,
1423
1510
  };
1424
1511
  Promise.resolve(err)
1425
- .then(err => { if (options.fail) {
1426
- options.fail(err);
1512
+ .then(err => { try {
1513
+ if (options.fail) {
1514
+ options.fail(err);
1515
+ }
1516
+ }
1517
+ catch (e) {
1518
+ console.warn(e);
1427
1519
  } })
1428
- .finally(() => { if (options.complete) {
1520
+ .then(() => { if (options.complete) {
1429
1521
  options.complete(err);
1430
1522
  } });
1431
1523
  throw new ReferenceError("request is not defined");
1432
1524
  };
1433
1525
 
1434
- const state$1 = Symbol("XMLHttpRequestState");
1526
+ var _a$2, _b$1, _c, _d, _e, _f, _g, _h, _j, _k;
1527
+ const state$4 = Symbol( /* "XMLHttpRequestState" */);
1435
1528
  class XMLHttpRequestP extends XMLHttpRequestEventTargetP {
1436
- static UNSENT = 0;
1437
- static OPENED = 1;
1438
- static HEADERS_RECEIVED = 2;
1439
- static LOADING = 3;
1440
- static DONE = 4;
1441
1529
  constructor() {
1442
1530
  super();
1443
- this[state$1] = new XMLHttpRequestState(this);
1444
- }
1445
- [state$1];
1446
- UNSENT = 0;
1447
- OPENED = 1;
1448
- HEADERS_RECEIVED = 2;
1449
- LOADING = 3;
1450
- DONE = 4;
1451
- get readyState() { return this[state$1].readyState; }
1452
- get response() { return this[state$1].response; }
1531
+ this.UNSENT = 0;
1532
+ this.OPENED = 1;
1533
+ this.HEADERS_RECEIVED = 2;
1534
+ this.LOADING = 3;
1535
+ this.DONE = 4;
1536
+ this[state$4] = new XMLHttpRequestState(this);
1537
+ }
1538
+ get readyState() { return this[state$4].readyState; }
1539
+ get response() { return this[state$4].response; }
1453
1540
  get responseText() { return (!this.responseType || this.responseType === "text") ? this.response : ""; }
1454
- get responseType() { return this[state$1].responseType; }
1455
- set responseType(value) { this[state$1].responseType = value; }
1456
- get responseURL() { return this[state$1].responseURL; }
1541
+ get responseType() { return this[state$4].responseType; }
1542
+ set responseType(value) { this[state$4].responseType = value; }
1543
+ get responseURL() { return this[state$4].responseURL; }
1457
1544
  get responseXML() { return null; }
1458
- get status() { return this[state$1].status; }
1545
+ get status() { return this[state$4].status; }
1459
1546
  get statusText() {
1460
1547
  if (this.readyState === XMLHttpRequestP.UNSENT || this.readyState === XMLHttpRequestP.OPENED)
1461
1548
  return "";
1462
- return this[state$1].statusText || statusTextMap(this.status);
1549
+ return this[state$4].statusText || statusTextMap(this.status);
1463
1550
  }
1464
- get timeout() { return this[state$1].timeout; }
1465
- set timeout(value) { this[state$1].timeout = value; }
1466
- get upload() { return this[state$1].upload; }
1467
- get withCredentials() { return this[state$1].withCredentials; }
1468
- set withCredentials(value) { this[state$1].withCredentials = value; }
1551
+ get timeout() { return this[state$4].timeout; }
1552
+ set timeout(value) { this[state$4].timeout = value; }
1553
+ get upload() { return this[state$4].upload; }
1554
+ get withCredentials() { return this[state$4].withCredentials; }
1555
+ set withCredentials(value) { this[state$4].withCredentials = value; }
1469
1556
  abort() {
1470
- this[state$1].clearRequest();
1557
+ clearRequest.call(this[state$4]);
1471
1558
  }
1472
1559
  getAllResponseHeaders() {
1473
- if (!this[state$1]._resHeaders)
1560
+ if (!this[state$4][_responseHeaders])
1474
1561
  return "";
1475
- return Object.entries(this[state$1]._resHeaders || {}).map(([k, v]) => `${k}: ${v}\r\n`).join("");
1562
+ return objectEntries(this[state$4][_responseHeaders] || {}).map(([k, v]) => `${k}: ${v}\r\n`).join("");
1476
1563
  }
1477
1564
  getResponseHeader(name) {
1478
- if (!this[state$1]._resHeaders)
1565
+ var _l, _m;
1566
+ if (!this[state$4][_responseHeaders])
1479
1567
  return null;
1480
- return Object.entries(this[state$1]._resHeaders || {}).find(x => x[0].toLowerCase() === name.toLowerCase())?.[1] ?? null;
1568
+ const nameKey = name.toLowerCase();
1569
+ return (_m = (_l = objectEntries(this[state$4][_responseHeaders] || {}).find(x => x[0].toLowerCase() === nameKey)) === null || _l === void 0 ? void 0 : _l[1]) !== null && _m !== void 0 ? _m : null;
1481
1570
  }
1482
1571
  open(...args) {
1483
1572
  const [method, url, async = true, username = null, password = null] = args;
1573
+ const that = this[state$4];
1484
1574
  if (args.length < 2) {
1485
1575
  throw new TypeError(`Failed to execute 'open' on 'XMLHttpRequest': 2 arguments required, but only ${args.length} present.`);
1486
1576
  }
1487
1577
  if (!async) {
1488
- console.warn("Synchronous XMLHttpRequest is deprecated because of its detrimental effects to the end user's experience.");
1578
+ console.warn("Synchronous XMLHttpRequest is not supported because of its detrimental effects to the end user's experience.");
1579
+ }
1580
+ clearRequest.call(that, false);
1581
+ that[_method] = normalizeMethod(method);
1582
+ that[_requestURL] = String(url);
1583
+ if (username !== null || password !== null) {
1584
+ const _username = String(username !== null && username !== void 0 ? username : "");
1585
+ const _password = String(password !== null && password !== void 0 ? password : "");
1586
+ if (_username.length > 0 || _password.length > 0) {
1587
+ const auth = `Basic ${u8array2base64((new TextEncoderP()).encode(_username + ":" + _password))}`;
1588
+ this.setRequestHeader("Authorization", auth);
1589
+ }
1590
+ }
1591
+ that[_inAfterOpenBeforeSend] = true;
1592
+ setReadyStateAndNotify.call(that, XMLHttpRequestP.OPENED);
1593
+ }
1594
+ overrideMimeType(mime) {
1595
+ if (this[state$4][_inAfterOpenBeforeSend]) {
1596
+ console.warn(`XMLHttpRequest.overrideMimeType(${mime}) is not implemented: The method will have no effect on response parsing.`);
1489
1597
  }
1490
- this[state$1].clearRequest(false);
1491
- this[state$1]._method = normalizeMethod(method);
1492
- this[state$1]._reqURL = String(url);
1493
- this[state$1]._reqCanSend = true;
1494
- this[state$1].setReadyStateAndNotify(XMLHttpRequestP.OPENED);
1495
1598
  }
1496
- overrideMimeType(mime) { }
1497
1599
  send(body) {
1498
- if (!this[state$1]._reqCanSend || this.readyState !== XMLHttpRequestP.OPENED) {
1600
+ const that = this[state$4];
1601
+ if (!that[_inAfterOpenBeforeSend] || that.readyState !== XMLHttpRequestP.OPENED) {
1499
1602
  throw new MPException("Failed to execute 'send' on 'XMLHttpRequest': The object's state must be OPENED.", "InvalidStateError");
1500
1603
  }
1501
- this[state$1]._reqCanSend = false;
1502
- this[state$1].execRequest(body);
1503
- this[state$1].checkRequestTimeout();
1504
- }
1505
- setRequestHeader(name, value) {
1506
- assignRequestHeader(this[state$1]._reqHeaders, name, value);
1507
- }
1508
- get onreadystatechange() { return this[state$1].onreadystatechange; }
1509
- set onreadystatechange(value) {
1510
- this[state$1].onreadystatechange = value;
1511
- attachFn.call(this, "readystatechange", value, this[state$1]._onreadystatechange);
1512
- }
1513
- toString() { return "[object XMLHttpRequest"; }
1514
- get isPolyfill() { return { symbol: polyfill, hierarchy: ["XMLHttpRequest", "XMLHttpRequestEventTarget", "EventTarget"] }; }
1515
- }
1516
- defineStringTag(XMLHttpRequestP, "XMLHttpRequest");
1517
- class XMLHttpRequestState {
1518
- constructor(target) {
1519
- this.target = target;
1520
- this.upload = createXMLHttpRequestUploadP();
1521
- }
1522
- target;
1523
- readyState = XMLHttpRequestP.UNSENT;
1524
- response = "";
1525
- responseType = "";
1526
- responseURL = "";
1527
- status = 0;
1528
- statusText = "";
1529
- timeout = 0;
1530
- upload;
1531
- withCredentials = false;
1532
- _reqCanSend = false;
1533
- _resetPending = false;
1534
- _timeoutId = 0;
1535
- _reqURL = "";
1536
- _method = "GET";
1537
- _reqHeaders = { Accept: "*/*" };
1538
- _resHeaders = null;
1539
- _resContLen = 0;
1540
- _requestTask = null;
1541
- execRequest(body) {
1542
- const allowsRequestBody = !["GET", "HEAD"].includes(this._method);
1543
- const contentTypeExists = Object.keys(this._reqHeaders).map(x => x.toLowerCase()).includes("Content-Type".toLowerCase());
1544
- const processHeaders = allowsRequestBody && !contentTypeExists;
1545
- const processContentLength = this.upload[state$7].executors.length > 0;
1546
- let headers = { ...this._reqHeaders };
1604
+ that[_inAfterOpenBeforeSend] = false;
1605
+ const allowsRequestBody = ["GET", "HEAD"].indexOf(that[_method]) === -1;
1606
+ const processHeaders = allowsRequestBody && Object.keys(that[_requestHeaders]).map(x => x.toLowerCase()).indexOf("content-type") === -1;
1607
+ const processContentLength = that.upload[state$f][_executors].length > 0;
1608
+ let headers = Object.assign({}, that[_requestHeaders]);
1547
1609
  let contentLength = 0;
1548
- let data = convert(body, processHeaders ? v => { headers["Content-Type"] = v; } : void 0, processContentLength ? v => { contentLength = v; } : void 0);
1549
- this._requestTask = request({
1550
- url: this._reqURL,
1551
- method: this._method,
1610
+ let data = convert(body, processHeaders ? v => { assignRequestHeader(headers, "Content-Type", v); } : void 0, processContentLength ? v => { contentLength = v; } : void 0);
1611
+ that[_requestTask] = request({
1612
+ url: that[_requestURL],
1613
+ method: that[_method],
1552
1614
  header: headers,
1553
1615
  data,
1554
- dataType: this.responseType === "json" ? "json" : "text",
1555
- responseType: this.responseType === "arraybuffer" ? "arraybuffer" : "text",
1556
- success: this.requestSuccess.bind(this),
1557
- fail: this.requestFail.bind(this),
1558
- complete: this.requestComplete.bind(this),
1616
+ dataType: that.responseType === "json" ? "json" : normalizeDataType(that.responseType),
1617
+ responseType: normalizeDataType(that.responseType),
1618
+ success: requestSuccess.bind(that),
1619
+ fail: requestFail.bind(that),
1620
+ complete: requestComplete.bind(that),
1559
1621
  });
1560
- this.emitProcessEvent("loadstart");
1622
+ emitProcessEvent(this, "loadstart");
1561
1623
  if (processContentLength) {
1562
- const hasRequestBody = allowsRequestBody && contentLength > 0;
1624
+ const hasRequestBody = allowsRequestBody && (typeof data === "string" ? data.length > 0 : data.byteLength > 0);
1563
1625
  if (hasRequestBody) {
1564
- this.emitProcessEvent("loadstart", 0, contentLength, this.upload);
1626
+ emitProcessEvent(that.upload, "loadstart", 0, contentLength);
1565
1627
  }
1566
1628
  setTimeout(() => {
1567
- const _aborted = this._reqCanSend || this.readyState !== XMLHttpRequestP.OPENED;
1629
+ const _aborted = that[_inAfterOpenBeforeSend] || that.readyState !== XMLHttpRequestP.OPENED;
1568
1630
  const _contentLength = _aborted ? 0 : contentLength;
1569
1631
  if (_aborted) {
1570
- this.emitProcessEvent("abort", 0, 0, this.upload);
1632
+ emitProcessEvent(that.upload, "abort");
1571
1633
  }
1572
1634
  else {
1573
1635
  if (hasRequestBody) {
1574
- this.emitProcessEvent("load", _contentLength, _contentLength, this.upload);
1636
+ emitProcessEvent(that.upload, "load", _contentLength, _contentLength);
1575
1637
  }
1576
1638
  }
1577
1639
  if (_aborted || hasRequestBody) {
1578
- this.emitProcessEvent("loadend", _contentLength, _contentLength, this.upload);
1640
+ emitProcessEvent(that.upload, "loadend", _contentLength, _contentLength);
1579
1641
  }
1580
1642
  });
1581
1643
  }
1644
+ checkRequestTimeout.call(that);
1582
1645
  }
1583
- requestSuccess({ statusCode, header, data }) {
1584
- this.responseURL = this._reqURL;
1585
- this.status = statusCode;
1586
- this._resHeaders = header;
1587
- this._resContLen = parseInt(this.target.getResponseHeader("Content-Length") || "0");
1588
- if (this.readyState === XMLHttpRequestP.OPENED) {
1589
- this.setReadyStateAndNotify(XMLHttpRequestP.HEADERS_RECEIVED);
1590
- this.setReadyStateAndNotify(XMLHttpRequestP.LOADING);
1591
- setTimeout(() => {
1592
- if (!this._reqCanSend) {
1593
- let l = this._resContLen;
1594
- try {
1595
- this.response = convertBack(this.responseType, data);
1596
- this.emitProcessEvent("load", l, l);
1597
- }
1598
- catch (e) {
1599
- console.error(e);
1600
- this.emitProcessEvent("error");
1601
- }
1602
- }
1603
- });
1604
- }
1646
+ setRequestHeader(name, value) {
1647
+ assignRequestHeader(this[state$4][_requestHeaders], name, value);
1605
1648
  }
1606
- requestFail(err) {
1607
- // Alipay Mini Programs
1608
- // error: 14 --- JSON parse data error
1609
- // error: 19 --- http status error
1610
- // At this point, the error data object will contain three pieces of information
1611
- // returned from the server: status, headers, and data.
1612
- // In the browser's XMLHttpRequest, these two errors (Error 14 and Error 19)
1613
- // differ from those in Alipay Mini Programs and should instead return normally.
1614
- // Therefore, this scenario is also handled here as a successful request response.
1615
- if ("status" in err) {
1616
- this.requestSuccess({ statusCode: err.status, header: err.headers, data: err.data });
1617
- return;
1618
- }
1649
+ get onreadystatechange() { return this[state$4].onreadystatechange; }
1650
+ set onreadystatechange(value) {
1651
+ this[state$4].onreadystatechange = value;
1652
+ attachFn.call(this, "readystatechange", value, this[state$4][_handlers].onreadystatechange);
1653
+ }
1654
+ toString() { return "[object XMLHttpRequest]"; }
1655
+ get isPolyfill() { return { symbol: polyfill, hierarchy: ["XMLHttpRequest", "XMLHttpRequestEventTarget", "EventTarget"] }; }
1656
+ }
1657
+ XMLHttpRequestP.UNSENT = 0;
1658
+ XMLHttpRequestP.OPENED = 1;
1659
+ XMLHttpRequestP.HEADERS_RECEIVED = 2;
1660
+ XMLHttpRequestP.LOADING = 3;
1661
+ XMLHttpRequestP.DONE = 4;
1662
+ defineStringTag(XMLHttpRequestP, "XMLHttpRequest");
1663
+ const _handlers = Symbol();
1664
+ const _inAfterOpenBeforeSend = Symbol();
1665
+ const _resetPending = Symbol();
1666
+ const _timeoutId = Symbol();
1667
+ const _requestURL = Symbol();
1668
+ const _method = Symbol();
1669
+ const _requestHeaders = Symbol();
1670
+ const _responseHeaders = Symbol();
1671
+ const _responseContentLength = Symbol();
1672
+ const _requestTask = Symbol();
1673
+ class XMLHttpRequestState {
1674
+ constructor(target) {
1675
+ this.readyState = XMLHttpRequestP.UNSENT;
1676
+ this.response = "";
1677
+ this.responseType = "";
1678
+ this.responseURL = "";
1619
1679
  this.status = 0;
1620
- this.statusText = "errMsg" in err ? err.errMsg : "errorMessage" in err ? err.errorMessage : "";
1621
- if (!this._reqCanSend && this.readyState !== XMLHttpRequestP.UNSENT && this.readyState !== XMLHttpRequestP.DONE) {
1622
- this.emitProcessEvent("error");
1623
- this.resetRequestTimeout();
1624
- }
1680
+ this.statusText = "";
1681
+ this.timeout = 0;
1682
+ this.withCredentials = false;
1683
+ this[_a$2] = getHandlers.call(this);
1684
+ this.onreadystatechange = null;
1685
+ this[_b$1] = false;
1686
+ this[_c] = false;
1687
+ this[_d] = 0;
1688
+ this[_e] = "";
1689
+ this[_f] = "GET";
1690
+ this[_g] = { Accept: "*/*" };
1691
+ this[_h] = null;
1692
+ this[_j] = 0;
1693
+ this[_k] = null;
1694
+ this.target = target;
1695
+ this.upload = createXMLHttpRequestUploadP();
1625
1696
  }
1626
- requestComplete() {
1627
- this._requestTask = null;
1628
- if (!this._reqCanSend && (this.readyState === XMLHttpRequestP.OPENED || this.readyState === XMLHttpRequestP.LOADING)) {
1629
- this.setReadyStateAndNotify(XMLHttpRequestP.DONE);
1630
- }
1697
+ }
1698
+ _a$2 = _handlers, _b$1 = _inAfterOpenBeforeSend, _c = _resetPending, _d = _timeoutId, _e = _requestURL, _f = _method, _g = _requestHeaders, _h = _responseHeaders, _j = _responseContentLength, _k = _requestTask;
1699
+ function requestSuccess({ statusCode, header, data }) {
1700
+ this.responseURL = this[_requestURL];
1701
+ this.status = statusCode;
1702
+ this[_responseHeaders] = header;
1703
+ const lengthStr = this.target.getResponseHeader("Content-Length");
1704
+ this[_responseContentLength] = () => { return lengthStr ? parseInt(lengthStr) : 0; };
1705
+ if (this.readyState === XMLHttpRequestP.OPENED) {
1706
+ setReadyStateAndNotify.call(this, XMLHttpRequestP.HEADERS_RECEIVED);
1707
+ setReadyStateAndNotify.call(this, XMLHttpRequestP.LOADING);
1631
1708
  setTimeout(() => {
1632
- if (!this._reqCanSend) {
1633
- let l = this._resContLen;
1634
- this.emitProcessEvent("loadend", l, l);
1709
+ if (!this[_inAfterOpenBeforeSend]) {
1710
+ let l = this[_responseContentLength];
1711
+ try {
1712
+ this.response = convertBack(this.responseType, data);
1713
+ emitProcessEvent(this.target, "load", l, l);
1714
+ }
1715
+ catch (e) {
1716
+ console.error(e);
1717
+ emitProcessEvent(this.target, "error");
1718
+ }
1635
1719
  }
1636
1720
  });
1637
1721
  }
1638
- clearRequest(delay = true) {
1639
- const timerFn = delay ? setTimeout : (f) => { f(); };
1640
- this._resetPending = true;
1641
- if (this._requestTask && this.readyState !== XMLHttpRequestP.DONE) {
1642
- if (delay) {
1643
- this.setReadyStateAndNotify(XMLHttpRequestP.DONE);
1644
- }
1645
- timerFn(() => {
1646
- const requestTask = this._requestTask;
1647
- if (requestTask) {
1648
- requestTask.abort();
1649
- }
1650
- if (delay) {
1651
- this.emitProcessEvent("abort");
1652
- }
1653
- if (delay && !requestTask) {
1654
- this.emitProcessEvent("loadend");
1655
- }
1656
- });
1722
+ }
1723
+ function requestFail(err) {
1724
+ // Alipay Mini Programs
1725
+ // error: 14 --- JSON parse data error
1726
+ // error: 19 --- http status error
1727
+ // At this point, the error data object will contain three pieces of information
1728
+ // returned from the server: status, headers, and data.
1729
+ // In the browser's XMLHttpRequest, these two errors (Error 14 and Error 19)
1730
+ // differ from those in Alipay Mini Programs and should instead return normally.
1731
+ // Therefore, this scenario is also handled here as a successful request response.
1732
+ if ("status" in err) {
1733
+ requestSuccess.call(this, { statusCode: err.status, header: err.headers, data: err.data });
1734
+ return;
1735
+ }
1736
+ this.status = 0;
1737
+ this.statusText = "errMsg" in err ? err.errMsg : "errorMessage" in err ? err.errorMessage : "";
1738
+ if (!this[_inAfterOpenBeforeSend] && this.readyState !== XMLHttpRequestP.UNSENT && this.readyState !== XMLHttpRequestP.DONE) {
1739
+ emitProcessEvent(this.target, "error");
1740
+ resetRequestTimeout.call(this);
1741
+ }
1742
+ }
1743
+ function requestComplete() {
1744
+ this[_requestTask] = null;
1745
+ if (!this[_inAfterOpenBeforeSend] && (this.readyState === XMLHttpRequestP.OPENED || this.readyState === XMLHttpRequestP.LOADING)) {
1746
+ setReadyStateAndNotify.call(this, XMLHttpRequestP.DONE);
1747
+ }
1748
+ setTimeout(() => {
1749
+ if (!this[_inAfterOpenBeforeSend]) {
1750
+ let l = this[_responseContentLength];
1751
+ emitProcessEvent(this.target, "loadend", l, l);
1752
+ }
1753
+ });
1754
+ }
1755
+ function clearRequest(delay = true) {
1756
+ const timerFn = delay ? setTimeout : (f) => { f(); };
1757
+ this[_resetPending] = true;
1758
+ if (this[_requestTask] && this.readyState !== XMLHttpRequestP.DONE) {
1759
+ if (delay) {
1760
+ setReadyStateAndNotify.call(this, XMLHttpRequestP.DONE);
1657
1761
  }
1658
1762
  timerFn(() => {
1659
- if (this._resetPending) {
1660
- if (delay) {
1661
- this.readyState = XMLHttpRequestP.UNSENT;
1662
- }
1663
- this.resetXHR();
1763
+ const requestTask = this[_requestTask];
1764
+ if (requestTask) {
1765
+ requestTask.abort();
1766
+ }
1767
+ if (delay) {
1768
+ emitProcessEvent(this.target, "abort");
1769
+ }
1770
+ if (delay && !requestTask) {
1771
+ emitProcessEvent(this.target, "loadend");
1664
1772
  }
1665
1773
  });
1666
1774
  }
1667
- checkRequestTimeout() {
1668
- if (this.timeout) {
1669
- this._timeoutId = setTimeout(() => {
1670
- if (!this.status && this.readyState !== XMLHttpRequestP.DONE) {
1671
- if (this._requestTask)
1672
- this._requestTask.abort();
1673
- this.setReadyStateAndNotify(XMLHttpRequestP.DONE);
1674
- this.emitProcessEvent("timeout");
1675
- }
1676
- }, this.timeout);
1775
+ timerFn(() => {
1776
+ if (this[_resetPending]) {
1777
+ if (delay) {
1778
+ this.readyState = XMLHttpRequestP.UNSENT;
1779
+ }
1780
+ resetXHR.call(this);
1677
1781
  }
1782
+ });
1783
+ }
1784
+ function checkRequestTimeout() {
1785
+ if (this.timeout) {
1786
+ this[_timeoutId] = setTimeout(() => {
1787
+ if (!this.status && this.readyState !== XMLHttpRequestP.DONE) {
1788
+ if (this[_requestTask])
1789
+ this[_requestTask].abort();
1790
+ setReadyStateAndNotify.call(this, XMLHttpRequestP.DONE);
1791
+ emitProcessEvent(this.target, "timeout");
1792
+ }
1793
+ }, this.timeout);
1678
1794
  }
1679
- resetXHR() {
1680
- this._resetPending = false;
1681
- this.resetRequestTimeout();
1682
- this.response = "";
1683
- this.responseURL = "";
1684
- this.status = 0;
1685
- this.statusText = "";
1686
- this._reqHeaders = {};
1687
- this._resHeaders = null;
1688
- this._resContLen = 0;
1689
- }
1690
- resetRequestTimeout() {
1691
- if (this._timeoutId) {
1692
- clearTimeout(this._timeoutId);
1693
- this._timeoutId = 0;
1694
- }
1695
- }
1696
- emitProcessEvent(type, loaded = 0, total = 0, target) {
1697
- const _target = target ?? this.target;
1698
- const _event = new ProgressEventP(type, {
1699
- lengthComputable: total > 0,
1700
- loaded,
1701
- total,
1702
- });
1703
- _event[state$9].target = _target;
1704
- _event[state$9].isTrusted = true;
1705
- _target[state$7].fire(_event);
1795
+ }
1796
+ function resetXHR() {
1797
+ this[_resetPending] = false;
1798
+ resetRequestTimeout.call(this);
1799
+ this.response = "";
1800
+ this.responseURL = "";
1801
+ this.status = 0;
1802
+ this.statusText = "";
1803
+ this[_requestHeaders] = {};
1804
+ this[_responseHeaders] = null;
1805
+ this[_responseContentLength] = 0;
1806
+ }
1807
+ function resetRequestTimeout() {
1808
+ if (this[_timeoutId]) {
1809
+ clearTimeout(this[_timeoutId]);
1810
+ this[_timeoutId] = 0;
1706
1811
  }
1707
- setReadyStateAndNotify(value) {
1708
- const hasChanged = value !== this.readyState;
1709
- this.readyState = value;
1710
- if (hasChanged) {
1711
- const evt = new EventP("readystatechange");
1712
- evt[state$9].target = this.target;
1713
- evt[state$9].isTrusted = true;
1714
- this.target[state$7].fire(evt);
1715
- }
1812
+ }
1813
+ function setReadyStateAndNotify(value) {
1814
+ const hasChanged = value !== this.readyState;
1815
+ this.readyState = value;
1816
+ if (hasChanged) {
1817
+ const evt = createInnerEvent(this.target, "readystatechange");
1818
+ fire.call(this.target[state$f], evt);
1716
1819
  }
1717
- onreadystatechange = null;
1718
- _onreadystatechange = (ev) => { executeFn.call(this.target, this.onreadystatechange, ev); };
1820
+ }
1821
+ function getHandlers() {
1822
+ return {
1823
+ onreadystatechange: (ev) => { executeFn.call(this.target, this.onreadystatechange, ev); },
1824
+ };
1719
1825
  }
1720
1826
  // HTTP methods whose capitalization should be normalized
1721
1827
  const methods = ["CONNECT", "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT", "TRACE"];
@@ -1723,9 +1829,13 @@ function normalizeMethod(method) {
1723
1829
  let upcased = method.toUpperCase();
1724
1830
  return methods.indexOf(upcased) > -1 ? upcased : method;
1725
1831
  }
1832
+ function normalizeDataType(responseType) {
1833
+ return (responseType === "blob" || responseType === "arraybuffer") ? "arraybuffer" : "text";
1834
+ }
1726
1835
  function assignRequestHeader(headers, name, value) {
1836
+ const nameKey = name.toLowerCase();
1727
1837
  for (const key of Object.keys(headers)) {
1728
- if (key.toLowerCase() === name.toLowerCase()) {
1838
+ if (key.toLowerCase() === nameKey) {
1729
1839
  headers[key] = value;
1730
1840
  return;
1731
1841
  }
@@ -1762,14 +1872,14 @@ function convert(body, setContentType, setContentLength) {
1762
1872
  result = body.buffer.slice(body.byteOffset, body.byteOffset + body.byteLength);
1763
1873
  }
1764
1874
  else if (isPolyfillType("Blob", body)) {
1765
- result = body[state$9]._u8array.buffer.slice(0);
1875
+ result = body[state$c][_u8array].buffer.slice(0);
1766
1876
  if (setContentType && body.type) {
1767
1877
  setContentType(body.type);
1768
1878
  }
1769
1879
  }
1770
1880
  else if (isPolyfillType("FormData", body)) {
1771
1881
  const blob = body[state$9].toBlob();
1772
- result = blob[state$9]._u8array.buffer;
1882
+ result = blob[state$c][_u8array].buffer;
1773
1883
  if (setContentType) {
1774
1884
  setContentType(blob.type);
1775
1885
  }
@@ -1781,7 +1891,12 @@ function convert(body, setContentType, setContentLength) {
1781
1891
  result = String(body);
1782
1892
  }
1783
1893
  if (setContentLength) {
1784
- setContentLength((typeof result === "string" ? encode(result) : result).byteLength);
1894
+ if (typeof result === "string") {
1895
+ setContentLength(() => { return encode(result).byteLength; });
1896
+ }
1897
+ else {
1898
+ setContentLength(result.byteLength);
1899
+ }
1785
1900
  }
1786
1901
  return result;
1787
1902
  }
@@ -1871,107 +1986,117 @@ function statusTextMap(val) {
1871
1986
  }
1872
1987
  const XMLHttpRequestE = (typeof XMLHttpRequest !== "undefined" && XMLHttpRequest) || XMLHttpRequestP;
1873
1988
 
1874
- const state = Symbol("BodyState");
1989
+ var _a$1, _b;
1990
+ const state$3 = Symbol( /* "BodyState" */);
1875
1991
  class BodyP {
1876
1992
  constructor() {
1877
1993
  if (new.target === BodyP) {
1878
1994
  throw new TypeError("Failed to construct 'Body': Illegal constructor");
1879
1995
  }
1880
- this[state] = new BodyState();
1996
+ this[state$3] = new BodyState();
1881
1997
  }
1882
- [state];
1883
1998
  get body() {
1884
- if (!this[state]._body) {
1999
+ if (!this[state$3][_body]) {
1885
2000
  return null;
1886
2001
  }
1887
2002
  throw new ReferenceError("ReadableStream is not defined");
1888
2003
  }
1889
- get bodyUsed() { return this[state].bodyUsed; }
2004
+ get bodyUsed() { return this[state$3].bodyUsed; }
1890
2005
  ;
1891
2006
  arrayBuffer() {
1892
2007
  const kind = "arrayBuffer";
1893
- return this[state].consumed(kind) || this[state].read(kind);
2008
+ return consumed.call(this[state$3], kind) || read.call(this[state$3], kind);
1894
2009
  }
1895
2010
  blob() {
1896
2011
  const kind = "blob";
1897
- return this[state].consumed(kind) || this[state].read(kind);
2012
+ return consumed.call(this[state$3], kind) || read.call(this[state$3], kind);
1898
2013
  }
1899
2014
  bytes() {
1900
2015
  const kind = "bytes";
1901
- return this[state].consumed(kind) || this[state].read(kind);
2016
+ return consumed.call(this[state$3], kind) || read.call(this[state$3], kind);
1902
2017
  }
1903
2018
  formData() {
1904
2019
  const kind = "formData";
1905
- return this[state].consumed(kind) || this[state].read(kind);
2020
+ return consumed.call(this[state$3], kind) || read.call(this[state$3], kind);
1906
2021
  }
1907
2022
  json() {
1908
2023
  const kind = "json";
1909
- return this[state].consumed(kind) || this[state].read(kind);
2024
+ return consumed.call(this[state$3], kind) || read.call(this[state$3], kind);
1910
2025
  }
1911
2026
  text() {
1912
2027
  const kind = "text";
1913
- return this[state].consumed(kind) || this[state].read(kind);
2028
+ return consumed.call(this[state$3], kind) || read.call(this[state$3], kind);
1914
2029
  }
1915
2030
  toString() { return "[object Body]"; }
1916
2031
  get isPolyfill() { return { symbol: polyfill, hierarchy: ["Body"] }; }
1917
2032
  }
1918
2033
  defineStringTag(BodyP, "Body");
2034
+ const _name = Symbol();
2035
+ const _body = Symbol();
1919
2036
  class BodyState {
1920
- bodyUsed = false;
1921
- _name = "Body";
1922
- _body = "";
1923
- init(body, headers) {
1924
- if (isObjectType("ReadableStream", body)) {
1925
- throw new ReferenceError("ReadableStream is not defined");
1926
- }
1927
- this._body = convert(body, type => {
1928
- if (headers && !headers.get("Content-Type")) {
1929
- headers.set("Content-Type", type);
1930
- }
1931
- });
2037
+ constructor() {
2038
+ this.bodyUsed = false;
2039
+ this[_a$1] = "Body";
2040
+ this[_b] = "";
1932
2041
  }
1933
- read(kind) {
1934
- return new Promise((resolve, reject) => {
1935
- try {
1936
- if (kind === "arrayBuffer") {
1937
- resolve(convertBack("arraybuffer", this._body));
1938
- }
1939
- else if (kind === "blob") {
1940
- resolve(convertBack("blob", this._body));
1941
- }
1942
- else if (kind === "bytes") {
1943
- let arrayBuffer = convertBack("arraybuffer", this._body);
1944
- resolve(new Uint8Array(arrayBuffer));
1945
- }
1946
- else if (kind === "formData") {
1947
- let text = convertBack("text", this._body);
1948
- resolve(createFormData(text));
1949
- }
1950
- else if (kind === "json") {
1951
- resolve(convertBack("json", this._body));
1952
- }
1953
- else {
1954
- resolve(convertBack("text", this._body));
1955
- }
1956
- }
1957
- catch (e) {
1958
- reject(e);
1959
- }
1960
- });
2042
+ }
2043
+ _a$1 = _name, _b = _body;
2044
+ function initFn(body, headers) {
2045
+ if (isObjectType("ReadableStream", body)) {
2046
+ throw new ReferenceError("ReadableStream is not defined");
1961
2047
  }
1962
- consumed(kind) {
1963
- if (!this._body)
1964
- return;
1965
- if (this.bodyUsed) {
1966
- return Promise.reject(new TypeError(`TypeError: Failed to execute '${kind}' on '${this._name}': body stream already read`));
2048
+ this[_body] = convert(body, type => {
2049
+ if (headers && !headers.get("Content-Type")) {
2050
+ headers.set("Content-Type", type);
2051
+ }
2052
+ });
2053
+ }
2054
+ function read(kind) {
2055
+ return new Promise((resolve, reject) => {
2056
+ try {
2057
+ resolve(readSync.call(this, kind));
2058
+ }
2059
+ catch (e) {
2060
+ reject(e);
1967
2061
  }
1968
- this.bodyUsed = true;
2062
+ });
2063
+ }
2064
+ function readSync(kind) {
2065
+ if (kind === "arrayBuffer") {
2066
+ return convertBack("arraybuffer", this[_body]);
2067
+ }
2068
+ else if (kind === "blob") {
2069
+ return convertBack("blob", this[_body]);
2070
+ }
2071
+ else if (kind === "bytes") {
2072
+ let arrayBuffer = convertBack("arraybuffer", this[_body]);
2073
+ return new Uint8Array(arrayBuffer);
2074
+ }
2075
+ else if (kind === "formData") {
2076
+ let text = convertBack("text", this[_body]);
2077
+ return createFormDataFromBody(text);
2078
+ }
2079
+ else if (kind === "json") {
2080
+ return convertBack("json", this[_body]);
2081
+ }
2082
+ else {
2083
+ return convertBack("text", this[_body]);
1969
2084
  }
1970
2085
  }
2086
+ function consumed(kind) {
2087
+ if (!this[_body])
2088
+ return;
2089
+ if (this.bodyUsed) {
2090
+ return Promise.reject(new TypeError(`TypeError: Failed to execute '${kind}' on '${this[_name]}': body stream already read`));
2091
+ }
2092
+ this.bodyUsed = true;
2093
+ }
1971
2094
 
2095
+ var _a;
2096
+ const state$2 = Symbol( /* "HeadersState" */);
1972
2097
  class HeadersP {
1973
2098
  constructor(init) {
1974
- this[state$9] = new HeadersState();
2099
+ this[state$2] = new HeadersState();
1975
2100
  if (isObjectType("Headers", init)) {
1976
2101
  init.forEach((value, name) => {
1977
2102
  this.append(name, value);
@@ -1989,25 +2114,26 @@ class HeadersP {
1989
2114
  });
1990
2115
  }
1991
2116
  else if (init) {
1992
- Object.entries(init).forEach(([name, value]) => {
2117
+ objectEntries(init).forEach(([name, value]) => {
1993
2118
  this.append(name, value);
1994
2119
  });
1995
2120
  }
1996
2121
  }
1997
- [state$9];
1998
2122
  append(name, value) {
2123
+ var _b;
1999
2124
  let key = normalizeName(name, "append");
2000
2125
  value = normalizeValue(value);
2001
- let oldValue = this[state$9]._map.get(key)?.[1];
2002
- this[state$9]._map.set(key, ["" + name, oldValue ? `${oldValue}, ${value}` : value]);
2126
+ let oldValue = (_b = this[state$2][_headersMap].get(key)) === null || _b === void 0 ? void 0 : _b[1];
2127
+ this[state$2][_headersMap].set(key, ["" + name, oldValue ? `${oldValue}, ${value}` : value]);
2003
2128
  }
2004
2129
  delete(name) {
2005
2130
  let key = normalizeName(name, "delete");
2006
- this[state$9]._map.delete(key);
2131
+ this[state$2][_headersMap].delete(key);
2007
2132
  }
2008
2133
  get(name) {
2134
+ var _b, _c;
2009
2135
  let key = normalizeName(name, "get");
2010
- return this[state$9]._map.get(key)?.[1] ?? null;
2136
+ return (_c = (_b = this[state$2][_headersMap].get(key)) === null || _b === void 0 ? void 0 : _b[1]) !== null && _c !== void 0 ? _c : null;
2011
2137
  }
2012
2138
  getSetCookie() {
2013
2139
  let value = this.get("Set-Cookie");
@@ -2015,11 +2141,11 @@ class HeadersP {
2015
2141
  }
2016
2142
  has(name) {
2017
2143
  let key = normalizeName(name, "has");
2018
- return this[state$9]._map.has(key);
2144
+ return this[state$2][_headersMap].has(key);
2019
2145
  }
2020
2146
  set(name, value) {
2021
2147
  let key = normalizeName(name, "set");
2022
- this[state$9]._map.set(key, ["" + name, normalizeValue(value)]);
2148
+ this[state$2][_headersMap].set(key, ["" + name, normalizeValue(value)]);
2023
2149
  }
2024
2150
  forEach(callbackfn, thisArg) {
2025
2151
  Array.from(this.entries()).forEach(([name, value]) => {
@@ -2027,7 +2153,7 @@ class HeadersP {
2027
2153
  });
2028
2154
  }
2029
2155
  entries() {
2030
- return this[state$9]._map.values();
2156
+ return this[state$2][_headersMap].values();
2031
2157
  }
2032
2158
  keys() {
2033
2159
  return Array.from(this.entries()).map(pair => pair[0]).values();
@@ -2042,9 +2168,13 @@ class HeadersP {
2042
2168
  get isPolyfill() { return { symbol: polyfill, hierarchy: ["Headers"] }; }
2043
2169
  }
2044
2170
  defineStringTag(HeadersP, "Headers");
2171
+ const _headersMap = Symbol();
2045
2172
  class HeadersState {
2046
- _map = new Map();
2173
+ constructor() {
2174
+ this[_a] = new Map();
2175
+ }
2047
2176
  }
2177
+ _a = _headersMap;
2048
2178
  function normalizeName(name, kind = "") {
2049
2179
  if (typeof name !== "string") {
2050
2180
  name = String(name);
@@ -2062,142 +2192,186 @@ function normalizeValue(value) {
2062
2192
  }
2063
2193
  return value;
2064
2194
  }
2195
+ function parseHeaders(rawHeaders) {
2196
+ let headers = new HeadersP();
2197
+ let preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, " ");
2198
+ preProcessedHeaders
2199
+ .split("\r")
2200
+ .map(function (header) {
2201
+ return header.indexOf("\n") === 0 ? header.substring(1, header.length) : header;
2202
+ })
2203
+ .forEach(function (line) {
2204
+ let parts = line.split(":");
2205
+ let key = parts.shift().trim();
2206
+ if (key) {
2207
+ let value = parts.join(":").trim();
2208
+ try {
2209
+ headers.append(key, value);
2210
+ }
2211
+ catch (error) {
2212
+ console.warn("Response " + error.message);
2213
+ }
2214
+ }
2215
+ });
2216
+ return headers;
2217
+ }
2065
2218
  const HeadersE = g["Headers"] || HeadersP;
2066
2219
 
2220
+ const state$1 = Symbol( /* "RequestState" */);
2067
2221
  class RequestP extends BodyP {
2068
2222
  constructor(input, init) {
2069
2223
  super();
2070
- this[state$9] = new RequestState();
2071
- this[state]._name = "Request";
2072
- let options = init ?? {};
2224
+ this[state$1] = new RequestState();
2225
+ const that = this[state$1];
2226
+ this[state$3][_name] = "Request";
2227
+ let options = init !== null && init !== void 0 ? init : {};
2073
2228
  let body = options.body;
2074
2229
  if (isPolyfillType("Request", input)) {
2075
2230
  if (input.bodyUsed) {
2076
2231
  throw new TypeError("Failed to construct 'Request': Cannot construct a Request with a Request object that has already been used.");
2077
2232
  }
2078
- this[state$9].credentials = input.credentials;
2233
+ that.credentials = input.credentials;
2079
2234
  if (!options.headers) {
2080
- this[state$9].headers = new HeadersP(input.headers);
2235
+ that.headers = new HeadersP(input.headers);
2081
2236
  }
2082
- this[state$9].method = input.method;
2083
- this[state$9].mode = input.mode;
2084
- this[state$9].signal = input.signal;
2085
- this[state$9].url = input.url;
2237
+ that.method = input.method;
2238
+ that.mode = input.mode;
2239
+ that.signal = input.signal;
2240
+ that.url = input.url;
2086
2241
  let _input = input;
2087
- if (!body && _input[state]._body !== null) {
2088
- body = _input[state]._body;
2089
- _input[state].bodyUsed = true;
2242
+ if (!body && _input[state$3][_body] !== null) {
2243
+ body = _input[state$3][_body];
2244
+ _input[state$3].bodyUsed = true;
2090
2245
  }
2091
2246
  }
2092
2247
  else {
2093
- this[state$9].url = String(input);
2248
+ that.url = String(input);
2094
2249
  }
2095
2250
  if (options.credentials) {
2096
- this[state$9].credentials = options.credentials;
2251
+ that.credentials = options.credentials;
2097
2252
  }
2098
2253
  if (options.headers) {
2099
- this[state$9].headers = new HeadersP(options.headers);
2254
+ that.headers = new HeadersP(options.headers);
2100
2255
  }
2101
2256
  if (options.method) {
2102
- this[state$9].method = normalizeMethod(options.method);
2257
+ that.method = normalizeMethod(options.method);
2103
2258
  }
2104
2259
  if (options.mode) {
2105
- this[state$9].mode = options.mode;
2260
+ that.mode = options.mode;
2106
2261
  }
2107
2262
  if (options.signal) {
2108
- this[state$9].signal = options.signal;
2263
+ that.signal = options.signal;
2109
2264
  }
2110
2265
  if ((this.method === "GET" || this.method === "HEAD") && body) {
2111
2266
  throw new TypeError("Failed to construct 'Request': Request with GET/HEAD method cannot have body.");
2112
2267
  }
2113
- this[state].init(body, this.headers);
2268
+ initFn.call(this[state$3], body, this.headers);
2114
2269
  if (this.method === "GET" || this.method === "HEAD") {
2115
2270
  if (options.cache === "no-store" || options.cache === "no-cache") {
2116
2271
  // Search for a '_' parameter in the query string
2117
2272
  let reParamSearch = /([?&])_=[^&]*/;
2118
2273
  if (reParamSearch.test(this.url)) {
2119
2274
  // If it already exists then set the value with the current time
2120
- this[state$9].url = this.url.replace(reParamSearch, "$1_=" + (new Date()).getTime());
2275
+ that.url = this.url.replace(reParamSearch, "$1_=" + (new Date()).getTime());
2121
2276
  }
2122
2277
  else {
2123
2278
  // Otherwise add a new '_' parameter to the end with the current time
2124
2279
  let reQueryString = /\?/;
2125
- this[state$9].url += (reQueryString.test(this.url) ? "&" : "?") + "_=" + (new Date()).getTime();
2280
+ that.url += (reQueryString.test(this.url) ? "&" : "?") + "_=" + (new Date()).getTime();
2126
2281
  }
2127
2282
  }
2128
2283
  }
2129
2284
  }
2130
- [state$9];
2131
- get cache() { return this[state$9].cache; }
2132
- get credentials() { return this[state$9].credentials; }
2133
- get destination() { return this[state$9].destination; }
2134
- get headers() { return this[state$9].headers; }
2135
- get integrity() { return this[state$9].integrity; }
2136
- get keepalive() { return this[state$9].keepalive; }
2137
- get method() { return this[state$9].method; }
2138
- get mode() { return this[state$9].mode; }
2139
- get redirect() { return this[state$9].redirect; }
2140
- get referrer() { return this[state$9].referrer; }
2141
- get referrerPolicy() { return this[state$9].referrerPolicy; }
2142
- get signal() { return this[state$9].signal; }
2143
- get url() { return this[state$9].url; }
2285
+ get cache() { return this[state$1].cache; }
2286
+ get credentials() { return this[state$1].credentials; }
2287
+ get destination() { return this[state$1].destination; }
2288
+ get headers() {
2289
+ const that = this[state$1];
2290
+ if (!that.headers) {
2291
+ that.headers = new HeadersP();
2292
+ }
2293
+ return that.headers;
2294
+ }
2295
+ get integrity() { return this[state$1].integrity; }
2296
+ get keepalive() { return this[state$1].keepalive; }
2297
+ get method() { return this[state$1].method; }
2298
+ get mode() { return this[state$1].mode; }
2299
+ get redirect() { return this[state$1].redirect; }
2300
+ get referrer() { return this[state$1].referrer; }
2301
+ get referrerPolicy() { return this[state$1].referrerPolicy; }
2302
+ get signal() {
2303
+ const that = this[state$1];
2304
+ if (!that.signal) {
2305
+ that.signal = (new AbortControllerP()).signal;
2306
+ }
2307
+ return that.signal;
2308
+ }
2309
+ get url() { return this[state$1].url; }
2144
2310
  clone() {
2145
- return new RequestP(this, { body: this[state]._body ?? null });
2311
+ var _a;
2312
+ return new RequestP(this, { body: (_a = this[state$3][_body]) !== null && _a !== void 0 ? _a : null });
2146
2313
  }
2147
2314
  toString() { return "[object Request]"; }
2148
2315
  get isPolyfill() { return { symbol: polyfill, hierarchy: ["Request"] }; }
2149
2316
  }
2150
2317
  defineStringTag(RequestP, "Request");
2151
2318
  class RequestState {
2152
- cache = "default";
2153
- credentials = "same-origin";
2154
- destination = "";
2155
- headers = new HeadersP();
2156
- integrity = "";
2157
- keepalive = false;
2158
- method = "GET";
2159
- mode = "cors";
2160
- redirect = "follow";
2161
- referrer = "about:client";
2162
- referrerPolicy = "";
2163
- signal = (new AbortControllerP()).signal;
2164
- url = "";
2319
+ constructor() {
2320
+ this.cache = "default";
2321
+ this.credentials = "same-origin";
2322
+ this.destination = "";
2323
+ this.integrity = "";
2324
+ this.keepalive = false;
2325
+ this.method = "GET";
2326
+ this.mode = "cors";
2327
+ this.redirect = "follow";
2328
+ this.referrer = "about:client";
2329
+ this.referrerPolicy = "";
2330
+ this.url = "";
2331
+ }
2165
2332
  }
2166
2333
  const RequestE = g["Request"] || RequestP;
2167
2334
 
2335
+ const state = Symbol( /* "ResponseState" */);
2168
2336
  class ResponseP extends BodyP {
2169
2337
  constructor(body, init) {
2170
2338
  super();
2171
- this[state$9] = new ResponseState();
2172
- this[state]._name = "Response";
2173
- let options = init ?? {};
2339
+ this[state] = new ResponseState();
2340
+ const that = this[state];
2341
+ this[state$3][_name] = "Response";
2342
+ let options = init !== null && init !== void 0 ? init : {};
2174
2343
  let status = options.status === undefined ? 200 : options.status;
2175
2344
  if (status < 200 || status > 500) {
2176
2345
  throw new RangeError(`Failed to construct 'Response': The status provided (${+status}) is outside the range [200, 599].`);
2177
2346
  }
2178
2347
  if (options.headers) {
2179
- this[state$9].headers = new HeadersP(options.headers);
2180
- }
2181
- this[state$9].ok = this.status >= 200 && this.status < 300;
2182
- this[state$9].status = status;
2183
- this[state$9].statusText = options.statusText === undefined ? "" : "" + options.statusText;
2184
- this[state].init(body, this.headers);
2185
- }
2186
- [state$9];
2187
- get headers() { return this[state$9].headers; }
2188
- get ok() { return this[state$9].ok; }
2189
- get redirected() { return this[state$9].redirected; }
2190
- get status() { return this[state$9].status; }
2191
- get statusText() { return this[state$9].statusText; }
2192
- get type() { return this[state$9].type; }
2193
- get url() { return this[state$9].url; }
2348
+ that.headers = new HeadersP(options.headers);
2349
+ }
2350
+ that.ok = this.status >= 200 && this.status < 300;
2351
+ that.status = status;
2352
+ that.statusText = options.statusText === undefined ? "" : "" + options.statusText;
2353
+ initFn.call(this[state$3], body, this.headers);
2354
+ }
2355
+ get headers() {
2356
+ const that = this[state];
2357
+ if (!that.headers) {
2358
+ that.headers = new HeadersP();
2359
+ }
2360
+ return that.headers;
2361
+ }
2362
+ get ok() { return this[state].ok; }
2363
+ get redirected() { return this[state].redirected; }
2364
+ get status() { return this[state].status; }
2365
+ get statusText() { return this[state].statusText; }
2366
+ get type() { return this[state].type; }
2367
+ get url() { return this[state].url; }
2194
2368
  clone() {
2195
- const response = new ResponseP(this[state]._body, {
2369
+ const response = new ResponseP(this[state$3][_body], {
2196
2370
  headers: new HeadersP(this.headers),
2197
2371
  status: this.status,
2198
2372
  statusText: this.statusText,
2199
2373
  });
2200
- response[state$9].url = this.url;
2374
+ response[state].url = this.url;
2201
2375
  return response;
2202
2376
  }
2203
2377
  static json(data, init) {
@@ -2205,9 +2379,9 @@ class ResponseP extends BodyP {
2205
2379
  }
2206
2380
  static error() {
2207
2381
  const response = new ResponseP(null, { status: 200, statusText: "" });
2208
- response[state$9].ok = false;
2209
- response[state$9].status = 0;
2210
- response[state$9].type = "error";
2382
+ response[state].ok = false;
2383
+ response[state].status = 0;
2384
+ response[state].type = "error";
2211
2385
  return response;
2212
2386
  }
2213
2387
  static redirect(url, status = 301) {
@@ -2221,13 +2395,14 @@ class ResponseP extends BodyP {
2221
2395
  }
2222
2396
  defineStringTag(ResponseP, "Response");
2223
2397
  class ResponseState {
2224
- headers = new HeadersP();
2225
- ok = true;
2226
- redirected = false;
2227
- status = 200;
2228
- statusText = "";
2229
- type = "default";
2230
- url = "";
2398
+ constructor() {
2399
+ this.ok = true;
2400
+ this.redirected = false;
2401
+ this.status = 200;
2402
+ this.statusText = "";
2403
+ this.type = "default";
2404
+ this.url = "";
2405
+ }
2231
2406
  }
2232
2407
  const ResponseE = g["Response"] || ResponseP;
2233
2408
 
@@ -2243,13 +2418,13 @@ function fetchP(input, init) {
2243
2418
  let xhr = new XMLHttpRequestE();
2244
2419
  xhr.onload = function () {
2245
2420
  let options = {
2246
- headers: xhr instanceof XMLHttpRequestP ? (new HeadersP(xhr[state$1]._resHeaders || undefined)) : parseHeaders(xhr.getAllResponseHeaders() || ""),
2421
+ headers: xhr instanceof XMLHttpRequestP ? (new HeadersP(xhr[state$4][_responseHeaders] || undefined)) : parseHeaders(xhr.getAllResponseHeaders() || ""),
2247
2422
  status: xhr.status,
2248
2423
  statusText: xhr.statusText,
2249
2424
  };
2250
2425
  setTimeout(() => {
2251
2426
  const response = new ResponseP(xhr.response, options);
2252
- response[state$9].url = xhr.responseURL;
2427
+ response[state].url = xhr.responseURL;
2253
2428
  resolve(response);
2254
2429
  });
2255
2430
  };
@@ -2278,7 +2453,7 @@ function fetchP(input, init) {
2278
2453
  if (init && isObjectHeaders(init.headers)) {
2279
2454
  let headers = init.headers;
2280
2455
  let names = [];
2281
- Object.entries(headers).forEach(([name, value]) => {
2456
+ objectEntries(headers).forEach(([name, value]) => {
2282
2457
  names.push(normalizeName(name));
2283
2458
  xhr.setRequestHeader(name, normalizeValue(value));
2284
2459
  });
@@ -2303,35 +2478,12 @@ function fetchP(input, init) {
2303
2478
  }
2304
2479
  };
2305
2480
  }
2306
- xhr.send(request[state]._body);
2481
+ xhr.send(request[state$3][_body]);
2307
2482
  });
2308
2483
  }
2309
2484
  function isObjectHeaders(val) {
2310
2485
  return typeof val === "object" && !isObjectType("Headers", val);
2311
2486
  }
2312
- function parseHeaders(rawHeaders) {
2313
- let headers = new HeadersP();
2314
- let preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, " ");
2315
- preProcessedHeaders
2316
- .split("\r")
2317
- .map(function (header) {
2318
- return header.indexOf("\n") === 0 ? header.substring(1, header.length) : header;
2319
- })
2320
- .forEach(function (line) {
2321
- let parts = line.split(":");
2322
- let key = parts.shift().trim();
2323
- if (key) {
2324
- let value = parts.join(":").trim();
2325
- try {
2326
- headers.append(key, value);
2327
- }
2328
- catch (error) {
2329
- console.warn("Response " + error.message);
2330
- }
2331
- }
2332
- });
2333
- return headers;
2334
- }
2335
2487
  const fetchE = g["fetch"] || fetchP;
2336
2488
 
2337
2489
  exports.AbortController = AbortControllerE;