mphttpx 1.0.1 → 1.0.3

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