polyfill-library 4.0.0 → 4.1.0
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/CHANGELOG.md +4 -2042
- package/package.json +1 -2
- package/polyfills/__dist/Element.prototype.remove/meta.json +1 -1
- package/polyfills/__dist/Element.prototype.remove/min.js +1 -1
- package/polyfills/__dist/Element.prototype.remove/raw.js +11 -0
- package/polyfills/__dist/EventSource/meta.json +1 -1
- package/polyfills/__dist/EventSource/min.js +1 -1
- package/polyfills/__dist/EventSource/raw.js +1075 -1048
- package/polyfills/__dist/HTMLCollection.prototype.@@iterator/meta.json +1 -0
- package/polyfills/__dist/HTMLCollection.prototype.@@iterator/min.js +1 -0
- package/polyfills/__dist/HTMLCollection.prototype.@@iterator/raw.js +6 -0
- package/polyfills/__dist/aliases.json +1 -1
@@ -1,1050 +1,1077 @@
|
|
1
1
|
|
2
2
|
// EventSource
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
if (
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
if (
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
this.
|
203
|
-
this.
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
}
|
322
|
-
|
323
|
-
}
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
xhr
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
}
|
381
|
-
|
382
|
-
//
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
if ("
|
389
|
-
xhr.
|
390
|
-
|
391
|
-
};
|
392
|
-
}
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
}
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
}
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
}
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
}
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
}
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
var
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
function
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
var
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
var
|
808
|
-
if (
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
if (state
|
854
|
-
if (
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
if (
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
}
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
3
|
+
(function(undefined) {
|
4
|
+
if (!("EventSource"in self&&"function"==typeof self.EventSource
|
5
|
+
)) {
|
6
|
+
// EventSource
|
7
|
+
/** @license
|
8
|
+
* eventsource.js
|
9
|
+
* Available under MIT License (MIT)
|
10
|
+
* https://github.com/Yaffle/EventSource/
|
11
|
+
*
|
12
|
+
* The MIT License (MIT)
|
13
|
+
*
|
14
|
+
* Copyright (c) 2012 vic99999@yandex.ru
|
15
|
+
*
|
16
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
17
|
+
* of this software and associated documentation files (the "Software"), to deal
|
18
|
+
* in the Software without restriction, including without limitation the rights
|
19
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
20
|
+
* copies of the Software, and to permit persons to whom the Software is
|
21
|
+
* furnished to do so, subject to the following conditions:
|
22
|
+
*
|
23
|
+
* The above copyright notice and this permission notice shall be included in all
|
24
|
+
* copies or substantial portions of the Software.
|
25
|
+
*
|
26
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
27
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
28
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
29
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
30
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
31
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
32
|
+
* SOFTWARE.
|
33
|
+
*/
|
34
|
+
|
35
|
+
/*jslint indent: 2, vars: true, plusplus: true */
|
36
|
+
/*global setTimeout, clearTimeout */
|
37
|
+
|
38
|
+
(function (global) {
|
39
|
+
"use strict";
|
40
|
+
|
41
|
+
var setTimeout = global.setTimeout;
|
42
|
+
var clearTimeout = global.clearTimeout;
|
43
|
+
var XMLHttpRequest = global.XMLHttpRequest;
|
44
|
+
var XDomainRequest = global.XDomainRequest;
|
45
|
+
var ActiveXObject = global.ActiveXObject;
|
46
|
+
var NativeEventSource = global.EventSource;
|
47
|
+
|
48
|
+
var document = global.document;
|
49
|
+
var Promise = global.Promise;
|
50
|
+
var fetch = global.fetch;
|
51
|
+
var Response = global.Response;
|
52
|
+
var TextDecoder = global.TextDecoder;
|
53
|
+
var TextEncoder = global.TextEncoder;
|
54
|
+
var AbortController = global.AbortController;
|
55
|
+
|
56
|
+
if (typeof window !== "undefined" && typeof document !== "undefined" && !("readyState" in document) && document.body == null) { // Firefox 2
|
57
|
+
document.readyState = "loading";
|
58
|
+
window.addEventListener("load", function (event) {
|
59
|
+
document.readyState = "complete";
|
60
|
+
}, false);
|
61
|
+
}
|
62
|
+
|
63
|
+
if (XMLHttpRequest == null && ActiveXObject != null) { // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest_in_IE6
|
64
|
+
XMLHttpRequest = function () {
|
65
|
+
return new ActiveXObject("Microsoft.XMLHTTP");
|
66
|
+
};
|
67
|
+
}
|
68
|
+
|
69
|
+
if (Object.create == undefined) {
|
70
|
+
Object.create = function (C) {
|
71
|
+
function F(){}
|
72
|
+
F.prototype = C;
|
73
|
+
return new F();
|
74
|
+
};
|
75
|
+
}
|
76
|
+
|
77
|
+
if (!Date.now) {
|
78
|
+
Date.now = function now() {
|
79
|
+
return new Date().getTime();
|
80
|
+
};
|
81
|
+
}
|
82
|
+
|
83
|
+
// see #118 (Promise#finally with polyfilled Promise)
|
84
|
+
// see #123 (data URLs crash Edge)
|
85
|
+
// see #125 (CSP violations)
|
86
|
+
// see pull/#138
|
87
|
+
// => No way to polyfill Promise#finally
|
88
|
+
|
89
|
+
if (AbortController == undefined) {
|
90
|
+
var originalFetch2 = fetch;
|
91
|
+
fetch = function (url, options) {
|
92
|
+
var signal = options.signal;
|
93
|
+
return originalFetch2(url, {headers: options.headers, credentials: options.credentials, cache: options.cache}).then(function (response) {
|
94
|
+
var reader = response.body.getReader();
|
95
|
+
signal._reader = reader;
|
96
|
+
if (signal._aborted) {
|
97
|
+
signal._reader.cancel();
|
98
|
+
}
|
99
|
+
return {
|
100
|
+
status: response.status,
|
101
|
+
statusText: response.statusText,
|
102
|
+
headers: response.headers,
|
103
|
+
body: {
|
104
|
+
getReader: function () {
|
105
|
+
return reader;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
};
|
109
|
+
});
|
110
|
+
};
|
111
|
+
AbortController = function () {
|
112
|
+
this.signal = {
|
113
|
+
_reader: null,
|
114
|
+
_aborted: false
|
115
|
+
};
|
116
|
+
this.abort = function () {
|
117
|
+
if (this.signal._reader != null) {
|
118
|
+
this.signal._reader.cancel();
|
119
|
+
}
|
120
|
+
this.signal._aborted = true;
|
121
|
+
};
|
122
|
+
};
|
123
|
+
}
|
124
|
+
|
125
|
+
function TextDecoderPolyfill() {
|
126
|
+
this.bitsNeeded = 0;
|
127
|
+
this.codePoint = 0;
|
128
|
+
}
|
129
|
+
|
130
|
+
TextDecoderPolyfill.prototype.decode = function (octets) {
|
131
|
+
function valid(codePoint, shift, octetsCount) {
|
132
|
+
if (octetsCount === 1) {
|
133
|
+
return codePoint >= 0x0080 >> shift && codePoint << shift <= 0x07FF;
|
134
|
+
}
|
135
|
+
if (octetsCount === 2) {
|
136
|
+
return codePoint >= 0x0800 >> shift && codePoint << shift <= 0xD7FF || codePoint >= 0xE000 >> shift && codePoint << shift <= 0xFFFF;
|
137
|
+
}
|
138
|
+
if (octetsCount === 3) {
|
139
|
+
return codePoint >= 0x010000 >> shift && codePoint << shift <= 0x10FFFF;
|
140
|
+
}
|
141
|
+
throw new Error();
|
142
|
+
}
|
143
|
+
function octetsCount(bitsNeeded, codePoint) {
|
144
|
+
if (bitsNeeded === 6 * 1) {
|
145
|
+
return codePoint >> 6 > 15 ? 3 : codePoint > 31 ? 2 : 1;
|
146
|
+
}
|
147
|
+
if (bitsNeeded === 6 * 2) {
|
148
|
+
return codePoint > 15 ? 3 : 2;
|
149
|
+
}
|
150
|
+
if (bitsNeeded === 6 * 3) {
|
151
|
+
return 3;
|
152
|
+
}
|
153
|
+
throw new Error();
|
154
|
+
}
|
155
|
+
var REPLACER = 0xFFFD;
|
156
|
+
var string = "";
|
157
|
+
var bitsNeeded = this.bitsNeeded;
|
158
|
+
var codePoint = this.codePoint;
|
159
|
+
for (var i = 0; i < octets.length; i += 1) {
|
160
|
+
var octet = octets[i];
|
161
|
+
if (bitsNeeded !== 0) {
|
162
|
+
if (octet < 128 || octet > 191 || !valid(codePoint << 6 | octet & 63, bitsNeeded - 6, octetsCount(bitsNeeded, codePoint))) {
|
163
|
+
bitsNeeded = 0;
|
164
|
+
codePoint = REPLACER;
|
165
|
+
string += String.fromCharCode(codePoint);
|
166
|
+
}
|
167
|
+
}
|
168
|
+
if (bitsNeeded === 0) {
|
169
|
+
if (octet >= 0 && octet <= 127) {
|
170
|
+
bitsNeeded = 0;
|
171
|
+
codePoint = octet;
|
172
|
+
} else if (octet >= 192 && octet <= 223) {
|
173
|
+
bitsNeeded = 6 * 1;
|
174
|
+
codePoint = octet & 31;
|
175
|
+
} else if (octet >= 224 && octet <= 239) {
|
176
|
+
bitsNeeded = 6 * 2;
|
177
|
+
codePoint = octet & 15;
|
178
|
+
} else if (octet >= 240 && octet <= 247) {
|
179
|
+
bitsNeeded = 6 * 3;
|
180
|
+
codePoint = octet & 7;
|
181
|
+
} else {
|
182
|
+
bitsNeeded = 0;
|
183
|
+
codePoint = REPLACER;
|
184
|
+
}
|
185
|
+
if (bitsNeeded !== 0 && !valid(codePoint, bitsNeeded, octetsCount(bitsNeeded, codePoint))) {
|
186
|
+
bitsNeeded = 0;
|
187
|
+
codePoint = REPLACER;
|
188
|
+
}
|
189
|
+
} else {
|
190
|
+
bitsNeeded -= 6;
|
191
|
+
codePoint = codePoint << 6 | octet & 63;
|
192
|
+
}
|
193
|
+
if (bitsNeeded === 0) {
|
194
|
+
if (codePoint <= 0xFFFF) {
|
195
|
+
string += String.fromCharCode(codePoint);
|
196
|
+
} else {
|
197
|
+
string += String.fromCharCode(0xD800 + (codePoint - 0xFFFF - 1 >> 10));
|
198
|
+
string += String.fromCharCode(0xDC00 + (codePoint - 0xFFFF - 1 & 0x3FF));
|
199
|
+
}
|
200
|
+
}
|
201
|
+
}
|
202
|
+
this.bitsNeeded = bitsNeeded;
|
203
|
+
this.codePoint = codePoint;
|
204
|
+
return string;
|
205
|
+
};
|
206
|
+
|
207
|
+
// Firefox < 38 throws an error with stream option
|
208
|
+
var supportsStreamOption = function () {
|
209
|
+
try {
|
210
|
+
return new TextDecoder().decode(new TextEncoder().encode("test"), {stream: true}) === "test";
|
211
|
+
} catch (error) {
|
212
|
+
console.debug("TextDecoder does not support streaming option. Using polyfill instead: " + error);
|
213
|
+
}
|
214
|
+
return false;
|
215
|
+
};
|
216
|
+
|
217
|
+
// IE, Edge
|
218
|
+
if (TextDecoder == undefined || TextEncoder == undefined || !supportsStreamOption()) {
|
219
|
+
TextDecoder = TextDecoderPolyfill;
|
220
|
+
}
|
221
|
+
|
222
|
+
var k = function () {
|
223
|
+
};
|
224
|
+
|
225
|
+
function XHRWrapper(xhr) {
|
226
|
+
this.withCredentials = false;
|
227
|
+
this.readyState = 0;
|
228
|
+
this.status = 0;
|
229
|
+
this.statusText = "";
|
230
|
+
this.responseText = "";
|
231
|
+
this.onprogress = k;
|
232
|
+
this.onload = k;
|
233
|
+
this.onerror = k;
|
234
|
+
this.onreadystatechange = k;
|
235
|
+
this._contentType = "";
|
236
|
+
this._xhr = xhr;
|
237
|
+
this._sendTimeout = 0;
|
238
|
+
this._abort = k;
|
239
|
+
}
|
240
|
+
|
241
|
+
XHRWrapper.prototype.open = function (method, url) {
|
242
|
+
this._abort(true);
|
243
|
+
|
244
|
+
var that = this;
|
245
|
+
var xhr = this._xhr;
|
246
|
+
var state = 1;
|
247
|
+
var timeout = 0;
|
248
|
+
|
249
|
+
this._abort = function (silent) {
|
250
|
+
if (that._sendTimeout !== 0) {
|
251
|
+
clearTimeout(that._sendTimeout);
|
252
|
+
that._sendTimeout = 0;
|
253
|
+
}
|
254
|
+
if (state === 1 || state === 2 || state === 3) {
|
255
|
+
state = 4;
|
256
|
+
xhr.onload = k;
|
257
|
+
xhr.onerror = k;
|
258
|
+
xhr.onabort = k;
|
259
|
+
xhr.onprogress = k;
|
260
|
+
xhr.onreadystatechange = k;
|
261
|
+
// IE 8 - 9: XDomainRequest#abort() does not fire any event
|
262
|
+
// Opera < 10: XMLHttpRequest#abort() does not fire any event
|
263
|
+
xhr.abort();
|
264
|
+
if (timeout !== 0) {
|
265
|
+
clearTimeout(timeout);
|
266
|
+
timeout = 0;
|
267
|
+
}
|
268
|
+
if (!silent) {
|
269
|
+
that.readyState = 4;
|
270
|
+
that.onabort(null);
|
271
|
+
that.onreadystatechange();
|
272
|
+
}
|
273
|
+
}
|
274
|
+
state = 0;
|
275
|
+
};
|
276
|
+
|
277
|
+
var onStart = function () {
|
278
|
+
if (state === 1) {
|
279
|
+
//state = 2;
|
280
|
+
var status = 0;
|
281
|
+
var statusText = "";
|
282
|
+
var contentType = undefined;
|
283
|
+
if (!("contentType" in xhr)) {
|
284
|
+
try {
|
285
|
+
status = xhr.status;
|
286
|
+
statusText = xhr.statusText;
|
287
|
+
contentType = xhr.getResponseHeader("Content-Type");
|
288
|
+
} catch (error) {
|
289
|
+
// IE < 10 throws exception for `xhr.status` when xhr.readyState === 2 || xhr.readyState === 3
|
290
|
+
// Opera < 11 throws exception for `xhr.status` when xhr.readyState === 2
|
291
|
+
// https://bugs.webkit.org/show_bug.cgi?id=29121
|
292
|
+
status = 0;
|
293
|
+
statusText = "";
|
294
|
+
contentType = undefined;
|
295
|
+
// Firefox < 14, Chrome ?, Safari ?
|
296
|
+
// https://bugs.webkit.org/show_bug.cgi?id=29658
|
297
|
+
// https://bugs.webkit.org/show_bug.cgi?id=77854
|
298
|
+
}
|
299
|
+
} else {
|
300
|
+
status = 200;
|
301
|
+
statusText = "OK";
|
302
|
+
contentType = xhr.contentType;
|
303
|
+
}
|
304
|
+
if (status !== 0) {
|
305
|
+
state = 2;
|
306
|
+
that.readyState = 2;
|
307
|
+
that.status = status;
|
308
|
+
that.statusText = statusText;
|
309
|
+
that._contentType = contentType;
|
310
|
+
that.onreadystatechange();
|
311
|
+
}
|
312
|
+
}
|
313
|
+
};
|
314
|
+
var onProgress = function () {
|
315
|
+
onStart();
|
316
|
+
if (state === 2 || state === 3) {
|
317
|
+
state = 3;
|
318
|
+
var responseText = "";
|
319
|
+
try {
|
320
|
+
responseText = xhr.responseText;
|
321
|
+
} catch (error) {
|
322
|
+
// IE 8 - 9 with XMLHttpRequest
|
323
|
+
}
|
324
|
+
that.readyState = 3;
|
325
|
+
that.responseText = responseText;
|
326
|
+
that.onprogress();
|
327
|
+
}
|
328
|
+
};
|
329
|
+
var onFinish = function (type, event) {
|
330
|
+
if (event == null || event.preventDefault == null) {
|
331
|
+
event = {
|
332
|
+
preventDefault: k
|
333
|
+
};
|
334
|
+
}
|
335
|
+
// Firefox 52 fires "readystatechange" (xhr.readyState === 4) without final "readystatechange" (xhr.readyState === 3)
|
336
|
+
// IE 8 fires "onload" without "onprogress"
|
337
|
+
onProgress();
|
338
|
+
if (state === 1 || state === 2 || state === 3) {
|
339
|
+
state = 4;
|
340
|
+
if (timeout !== 0) {
|
341
|
+
clearTimeout(timeout);
|
342
|
+
timeout = 0;
|
343
|
+
}
|
344
|
+
that.readyState = 4;
|
345
|
+
if (type === "load") {
|
346
|
+
that.onload(event);
|
347
|
+
} else if (type === "error") {
|
348
|
+
that.onerror(event);
|
349
|
+
} else if (type === "abort") {
|
350
|
+
that.onabort(event);
|
351
|
+
} else {
|
352
|
+
throw new TypeError();
|
353
|
+
}
|
354
|
+
that.onreadystatechange();
|
355
|
+
}
|
356
|
+
};
|
357
|
+
var onReadyStateChange = function (event) {
|
358
|
+
if (xhr != undefined) { // Opera 12
|
359
|
+
if (xhr.readyState === 4) {
|
360
|
+
if (!("onload" in xhr) || !("onerror" in xhr) || !("onabort" in xhr)) {
|
361
|
+
onFinish(xhr.responseText === "" ? "error" : "load", event);
|
362
|
+
}
|
363
|
+
} else if (xhr.readyState === 3) {
|
364
|
+
if (!("onprogress" in xhr)) { // testing XMLHttpRequest#responseText too many times is too slow in IE 11
|
365
|
+
// and in Firefox 3.6
|
366
|
+
onProgress();
|
367
|
+
}
|
368
|
+
} else if (xhr.readyState === 2) {
|
369
|
+
onStart();
|
370
|
+
}
|
371
|
+
}
|
372
|
+
};
|
373
|
+
var onTimeout = function () {
|
374
|
+
timeout = setTimeout(function () {
|
375
|
+
onTimeout();
|
376
|
+
}, 500);
|
377
|
+
if (xhr.readyState === 3) {
|
378
|
+
onProgress();
|
379
|
+
}
|
380
|
+
};
|
381
|
+
|
382
|
+
// XDomainRequest#abort removes onprogress, onerror, onload
|
383
|
+
if ("onload" in xhr) {
|
384
|
+
xhr.onload = function (event) {
|
385
|
+
onFinish("load", event);
|
386
|
+
};
|
387
|
+
}
|
388
|
+
if ("onerror" in xhr) {
|
389
|
+
xhr.onerror = function (event) {
|
390
|
+
onFinish("error", event);
|
391
|
+
};
|
392
|
+
}
|
393
|
+
// improper fix to match Firefox behaviour, but it is better than just ignore abort
|
394
|
+
// see https://bugzilla.mozilla.org/show_bug.cgi?id=768596
|
395
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=880200
|
396
|
+
// https://code.google.com/p/chromium/issues/detail?id=153570
|
397
|
+
// IE 8 fires "onload" without "onprogress
|
398
|
+
if ("onabort" in xhr) {
|
399
|
+
xhr.onabort = function (event) {
|
400
|
+
onFinish("abort", event);
|
401
|
+
};
|
402
|
+
}
|
403
|
+
|
404
|
+
if ("onprogress" in xhr) {
|
405
|
+
xhr.onprogress = onProgress;
|
406
|
+
}
|
407
|
+
|
408
|
+
// IE 8 - 9 (XMLHTTPRequest)
|
409
|
+
// Opera < 12
|
410
|
+
// Firefox < 3.5
|
411
|
+
// Firefox 3.5 - 3.6 - ? < 9.0
|
412
|
+
// onprogress is not fired sometimes or delayed
|
413
|
+
// see also #64 (significant lag in IE 11)
|
414
|
+
if ("onreadystatechange" in xhr) {
|
415
|
+
xhr.onreadystatechange = function (event) {
|
416
|
+
onReadyStateChange(event);
|
417
|
+
};
|
418
|
+
}
|
419
|
+
|
420
|
+
if ("contentType" in xhr || !("ontimeout" in XMLHttpRequest.prototype)) {
|
421
|
+
url += (url.indexOf("?") === -1 ? "?" : "&") + "padding=true";
|
422
|
+
}
|
423
|
+
xhr.open(method, url, true);
|
424
|
+
|
425
|
+
if ("readyState" in xhr) {
|
426
|
+
// workaround for Opera 12 issue with "progress" events
|
427
|
+
// #91 (XMLHttpRequest onprogress not fired for streaming response in Edge 14-15-?)
|
428
|
+
timeout = setTimeout(function () {
|
429
|
+
onTimeout();
|
430
|
+
}, 0);
|
431
|
+
}
|
432
|
+
};
|
433
|
+
XHRWrapper.prototype.abort = function () {
|
434
|
+
this._abort(false);
|
435
|
+
};
|
436
|
+
XHRWrapper.prototype.getResponseHeader = function (name) {
|
437
|
+
return this._contentType;
|
438
|
+
};
|
439
|
+
XHRWrapper.prototype.setRequestHeader = function (name, value) {
|
440
|
+
var xhr = this._xhr;
|
441
|
+
if ("setRequestHeader" in xhr) {
|
442
|
+
xhr.setRequestHeader(name, value);
|
443
|
+
}
|
444
|
+
};
|
445
|
+
XHRWrapper.prototype.getAllResponseHeaders = function () {
|
446
|
+
// XMLHttpRequest#getAllResponseHeaders returns null for CORS requests in Firefox 3.6.28
|
447
|
+
return this._xhr.getAllResponseHeaders != undefined ? this._xhr.getAllResponseHeaders() || "" : "";
|
448
|
+
};
|
449
|
+
XHRWrapper.prototype.send = function () {
|
450
|
+
// loading indicator in Safari < ? (6), Chrome < 14, Firefox
|
451
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=736723
|
452
|
+
if ((!("ontimeout" in XMLHttpRequest.prototype) || (!("sendAsBinary" in XMLHttpRequest.prototype) && !("mozAnon" in XMLHttpRequest.prototype))) &&
|
453
|
+
document != undefined &&
|
454
|
+
document.readyState != undefined &&
|
455
|
+
document.readyState !== "complete") {
|
456
|
+
var that = this;
|
457
|
+
that._sendTimeout = setTimeout(function () {
|
458
|
+
that._sendTimeout = 0;
|
459
|
+
that.send();
|
460
|
+
}, 4);
|
461
|
+
return;
|
462
|
+
}
|
463
|
+
|
464
|
+
var xhr = this._xhr;
|
465
|
+
// withCredentials should be set after "open" for Safari and Chrome (< 19 ?)
|
466
|
+
if ("withCredentials" in xhr) {
|
467
|
+
xhr.withCredentials = this.withCredentials;
|
468
|
+
}
|
469
|
+
try {
|
470
|
+
// xhr.send(); throws "Not enough arguments" in Firefox 3.0
|
471
|
+
xhr.send(undefined);
|
472
|
+
} catch (error1) {
|
473
|
+
// Safari 5.1.7, Opera 12
|
474
|
+
throw error1;
|
475
|
+
}
|
476
|
+
};
|
477
|
+
|
478
|
+
function toLowerCase(name) {
|
479
|
+
return name.replace(/[A-Z]/g, function (c) {
|
480
|
+
return String.fromCharCode(c.charCodeAt(0) + 0x20);
|
481
|
+
});
|
482
|
+
}
|
483
|
+
|
484
|
+
function HeadersPolyfill(all) {
|
485
|
+
// Get headers: implemented according to mozilla's example code: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getAllResponseHeaders#Example
|
486
|
+
var map = Object.create(null);
|
487
|
+
var array = all.split("\r\n");
|
488
|
+
for (var i = 0; i < array.length; i += 1) {
|
489
|
+
var line = array[i];
|
490
|
+
var parts = line.split(": ");
|
491
|
+
var name = parts.shift();
|
492
|
+
var value = parts.join(": ");
|
493
|
+
map[toLowerCase(name)] = value;
|
494
|
+
}
|
495
|
+
this._map = map;
|
496
|
+
}
|
497
|
+
HeadersPolyfill.prototype.get = function (name) {
|
498
|
+
return this._map[toLowerCase(name)];
|
499
|
+
};
|
500
|
+
|
501
|
+
if (XMLHttpRequest != null && XMLHttpRequest.HEADERS_RECEIVED == null) { // IE < 9, Firefox 3.6
|
502
|
+
XMLHttpRequest.HEADERS_RECEIVED = 2;
|
503
|
+
}
|
504
|
+
|
505
|
+
function XHRTransport() {
|
506
|
+
}
|
507
|
+
|
508
|
+
XHRTransport.prototype.open = function (xhr, onStartCallback, onProgressCallback, onFinishCallback, url, withCredentials, headers) {
|
509
|
+
xhr.open("GET", url);
|
510
|
+
var offset = 0;
|
511
|
+
xhr.onprogress = function () {
|
512
|
+
var responseText = xhr.responseText;
|
513
|
+
var chunk = responseText.slice(offset);
|
514
|
+
offset += chunk.length;
|
515
|
+
onProgressCallback(chunk);
|
516
|
+
};
|
517
|
+
xhr.onerror = function (event) {
|
518
|
+
event.preventDefault();
|
519
|
+
onFinishCallback(new Error("NetworkError"));
|
520
|
+
};
|
521
|
+
xhr.onload = function () {
|
522
|
+
onFinishCallback(null);
|
523
|
+
};
|
524
|
+
xhr.onabort = function () {
|
525
|
+
onFinishCallback(null);
|
526
|
+
};
|
527
|
+
xhr.onreadystatechange = function () {
|
528
|
+
if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
|
529
|
+
var status = xhr.status;
|
530
|
+
var statusText = xhr.statusText;
|
531
|
+
var contentType = xhr.getResponseHeader("Content-Type");
|
532
|
+
var headers = xhr.getAllResponseHeaders();
|
533
|
+
onStartCallback(status, statusText, contentType, new HeadersPolyfill(headers));
|
534
|
+
}
|
535
|
+
};
|
536
|
+
xhr.withCredentials = withCredentials;
|
537
|
+
for (var name in headers) {
|
538
|
+
if (Object.prototype.hasOwnProperty.call(headers, name)) {
|
539
|
+
xhr.setRequestHeader(name, headers[name]);
|
540
|
+
}
|
541
|
+
}
|
542
|
+
xhr.send();
|
543
|
+
return xhr;
|
544
|
+
};
|
545
|
+
|
546
|
+
function HeadersWrapper(headers) {
|
547
|
+
this._headers = headers;
|
548
|
+
}
|
549
|
+
HeadersWrapper.prototype.get = function (name) {
|
550
|
+
return this._headers.get(name);
|
551
|
+
};
|
552
|
+
|
553
|
+
function FetchTransport() {
|
554
|
+
}
|
555
|
+
|
556
|
+
FetchTransport.prototype.open = function (xhr, onStartCallback, onProgressCallback, onFinishCallback, url, withCredentials, headers) {
|
557
|
+
var reader = null;
|
558
|
+
var controller = new AbortController();
|
559
|
+
var signal = controller.signal;
|
560
|
+
var textDecoder = new TextDecoder();
|
561
|
+
fetch(url, {
|
562
|
+
headers: headers,
|
563
|
+
credentials: withCredentials ? "include" : "same-origin",
|
564
|
+
signal: signal,
|
565
|
+
cache: "no-store"
|
566
|
+
}).then(function (response) {
|
567
|
+
reader = response.body.getReader();
|
568
|
+
onStartCallback(response.status, response.statusText, response.headers.get("Content-Type"), new HeadersWrapper(response.headers));
|
569
|
+
// see https://github.com/promises-aplus/promises-spec/issues/179
|
570
|
+
return new Promise(function (resolve, reject) {
|
571
|
+
var readNextChunk = function () {
|
572
|
+
reader.read().then(function (result) {
|
573
|
+
if (result.done) {
|
574
|
+
//Note: bytes in textDecoder are ignored
|
575
|
+
resolve(undefined);
|
576
|
+
} else {
|
577
|
+
var chunk = textDecoder.decode(result.value, {stream: true});
|
578
|
+
onProgressCallback(chunk);
|
579
|
+
readNextChunk();
|
580
|
+
}
|
581
|
+
})["catch"](function (error) {
|
582
|
+
reject(error);
|
583
|
+
});
|
584
|
+
};
|
585
|
+
readNextChunk();
|
586
|
+
});
|
587
|
+
})["catch"](function (error) {
|
588
|
+
if (error.name === "AbortError") {
|
589
|
+
return undefined;
|
590
|
+
} else {
|
591
|
+
return error;
|
592
|
+
}
|
593
|
+
}).then(function (error) {
|
594
|
+
onFinishCallback(error);
|
595
|
+
});
|
596
|
+
return {
|
597
|
+
abort: function () {
|
598
|
+
if (reader != null) {
|
599
|
+
reader.cancel(); // https://bugzilla.mozilla.org/show_bug.cgi?id=1583815
|
600
|
+
}
|
601
|
+
controller.abort();
|
602
|
+
}
|
603
|
+
};
|
604
|
+
};
|
605
|
+
|
606
|
+
function EventTarget() {
|
607
|
+
this._listeners = Object.create(null);
|
608
|
+
}
|
609
|
+
|
610
|
+
function throwError(e) {
|
611
|
+
setTimeout(function () {
|
612
|
+
throw e;
|
613
|
+
}, 0);
|
614
|
+
}
|
615
|
+
|
616
|
+
EventTarget.prototype.dispatchEvent = function (event) {
|
617
|
+
event.target = this;
|
618
|
+
var typeListeners = this._listeners[event.type];
|
619
|
+
if (typeListeners != undefined) {
|
620
|
+
var length = typeListeners.length;
|
621
|
+
for (var i = 0; i < length; i += 1) {
|
622
|
+
var listener = typeListeners[i];
|
623
|
+
try {
|
624
|
+
if (typeof listener.handleEvent === "function") {
|
625
|
+
listener.handleEvent(event);
|
626
|
+
} else {
|
627
|
+
listener.call(this, event);
|
628
|
+
}
|
629
|
+
} catch (e) {
|
630
|
+
throwError(e);
|
631
|
+
}
|
632
|
+
}
|
633
|
+
}
|
634
|
+
};
|
635
|
+
EventTarget.prototype.addEventListener = function (type, listener) {
|
636
|
+
type = String(type);
|
637
|
+
var listeners = this._listeners;
|
638
|
+
var typeListeners = listeners[type];
|
639
|
+
if (typeListeners == undefined) {
|
640
|
+
typeListeners = [];
|
641
|
+
listeners[type] = typeListeners;
|
642
|
+
}
|
643
|
+
var found = false;
|
644
|
+
for (var i = 0; i < typeListeners.length; i += 1) {
|
645
|
+
if (typeListeners[i] === listener) {
|
646
|
+
found = true;
|
647
|
+
}
|
648
|
+
}
|
649
|
+
if (!found) {
|
650
|
+
typeListeners.push(listener);
|
651
|
+
}
|
652
|
+
};
|
653
|
+
EventTarget.prototype.removeEventListener = function (type, listener) {
|
654
|
+
type = String(type);
|
655
|
+
var listeners = this._listeners;
|
656
|
+
var typeListeners = listeners[type];
|
657
|
+
if (typeListeners != undefined) {
|
658
|
+
var filtered = [];
|
659
|
+
for (var i = 0; i < typeListeners.length; i += 1) {
|
660
|
+
if (typeListeners[i] !== listener) {
|
661
|
+
filtered.push(typeListeners[i]);
|
662
|
+
}
|
663
|
+
}
|
664
|
+
if (filtered.length === 0) {
|
665
|
+
delete listeners[type];
|
666
|
+
} else {
|
667
|
+
listeners[type] = filtered;
|
668
|
+
}
|
669
|
+
}
|
670
|
+
};
|
671
|
+
|
672
|
+
function Event(type) {
|
673
|
+
this.type = type;
|
674
|
+
this.target = undefined;
|
675
|
+
}
|
676
|
+
|
677
|
+
function MessageEvent(type, options) {
|
678
|
+
Event.call(this, type);
|
679
|
+
this.data = options.data;
|
680
|
+
this.lastEventId = options.lastEventId;
|
681
|
+
}
|
682
|
+
|
683
|
+
MessageEvent.prototype = Object.create(Event.prototype);
|
684
|
+
|
685
|
+
function ConnectionEvent(type, options) {
|
686
|
+
Event.call(this, type);
|
687
|
+
this.status = options.status;
|
688
|
+
this.statusText = options.statusText;
|
689
|
+
this.headers = options.headers;
|
690
|
+
}
|
691
|
+
|
692
|
+
ConnectionEvent.prototype = Object.create(Event.prototype);
|
693
|
+
|
694
|
+
function ErrorEvent(type, options) {
|
695
|
+
Event.call(this, type);
|
696
|
+
this.error = options.error;
|
697
|
+
}
|
698
|
+
|
699
|
+
ErrorEvent.prototype = Object.create(Event.prototype);
|
700
|
+
|
701
|
+
var WAITING = -1;
|
702
|
+
var CONNECTING = 0;
|
703
|
+
var OPEN = 1;
|
704
|
+
var CLOSED = 2;
|
705
|
+
|
706
|
+
var AFTER_CR = -1;
|
707
|
+
var FIELD_START = 0;
|
708
|
+
var FIELD = 1;
|
709
|
+
var VALUE_START = 2;
|
710
|
+
var VALUE = 3;
|
711
|
+
|
712
|
+
var contentTypeRegExp = /^text\/event\-stream(;.*)?$/i;
|
713
|
+
|
714
|
+
var MINIMUM_DURATION = 1000;
|
715
|
+
var MAXIMUM_DURATION = 18000000;
|
716
|
+
|
717
|
+
var parseDuration = function (value, def) {
|
718
|
+
var n = value == null ? def : parseInt(value, 10);
|
719
|
+
if (n !== n) {
|
720
|
+
n = def;
|
721
|
+
}
|
722
|
+
return clampDuration(n);
|
723
|
+
};
|
724
|
+
var clampDuration = function (n) {
|
725
|
+
return Math.min(Math.max(n, MINIMUM_DURATION), MAXIMUM_DURATION);
|
726
|
+
};
|
727
|
+
|
728
|
+
var fire = function (that, f, event) {
|
729
|
+
try {
|
730
|
+
if (typeof f === "function") {
|
731
|
+
f.call(that, event);
|
732
|
+
}
|
733
|
+
} catch (e) {
|
734
|
+
throwError(e);
|
735
|
+
}
|
736
|
+
};
|
737
|
+
|
738
|
+
function EventSourcePolyfill(url, options) {
|
739
|
+
EventTarget.call(this);
|
740
|
+
options = options || {};
|
741
|
+
|
742
|
+
this.onopen = undefined;
|
743
|
+
this.onmessage = undefined;
|
744
|
+
this.onerror = undefined;
|
745
|
+
|
746
|
+
this.url = undefined;
|
747
|
+
this.readyState = undefined;
|
748
|
+
this.withCredentials = undefined;
|
749
|
+
this.headers = undefined;
|
750
|
+
|
751
|
+
this._close = undefined;
|
752
|
+
|
753
|
+
start(this, url, options);
|
754
|
+
}
|
755
|
+
|
756
|
+
function getBestXHRTransport() {
|
757
|
+
return (XMLHttpRequest != undefined && ("withCredentials" in XMLHttpRequest.prototype)) || XDomainRequest == undefined
|
758
|
+
? new XMLHttpRequest()
|
759
|
+
: new XDomainRequest();
|
760
|
+
}
|
761
|
+
|
762
|
+
var isFetchSupported = fetch != undefined && Response != undefined && "body" in Response.prototype;
|
763
|
+
|
764
|
+
function start(es, url, options) {
|
765
|
+
url = String(url);
|
766
|
+
var withCredentials = Boolean(options.withCredentials);
|
767
|
+
var lastEventIdQueryParameterName = options.lastEventIdQueryParameterName || "lastEventId";
|
768
|
+
|
769
|
+
var initialRetry = clampDuration(1000);
|
770
|
+
var heartbeatTimeout = parseDuration(options.heartbeatTimeout, 45000);
|
771
|
+
|
772
|
+
var lastEventId = "";
|
773
|
+
var retry = initialRetry;
|
774
|
+
var wasActivity = false;
|
775
|
+
var textLength = 0;
|
776
|
+
var headers = options.headers || {};
|
777
|
+
var TransportOption = options.Transport;
|
778
|
+
var xhr = isFetchSupported && TransportOption == undefined ? undefined : new XHRWrapper(TransportOption != undefined ? new TransportOption() : getBestXHRTransport());
|
779
|
+
var transport = TransportOption != null && typeof TransportOption !== "string" ? new TransportOption() : (xhr == undefined ? new FetchTransport() : new XHRTransport());
|
780
|
+
var abortController = undefined;
|
781
|
+
var timeout = 0;
|
782
|
+
var currentState = WAITING;
|
783
|
+
var dataBuffer = "";
|
784
|
+
var lastEventIdBuffer = "";
|
785
|
+
var eventTypeBuffer = "";
|
786
|
+
|
787
|
+
var textBuffer = "";
|
788
|
+
var state = FIELD_START;
|
789
|
+
var fieldStart = 0;
|
790
|
+
var valueStart = 0;
|
791
|
+
|
792
|
+
var onStart = function (status, statusText, contentType, headers) {
|
793
|
+
if (currentState === CONNECTING) {
|
794
|
+
if (status === 200 && contentType != undefined && contentTypeRegExp.test(contentType)) {
|
795
|
+
currentState = OPEN;
|
796
|
+
wasActivity = Date.now();
|
797
|
+
retry = initialRetry;
|
798
|
+
es.readyState = OPEN;
|
799
|
+
var event = new ConnectionEvent("open", {
|
800
|
+
status: status,
|
801
|
+
statusText: statusText,
|
802
|
+
headers: headers
|
803
|
+
});
|
804
|
+
es.dispatchEvent(event);
|
805
|
+
fire(es, es.onopen, event);
|
806
|
+
} else {
|
807
|
+
var message = "";
|
808
|
+
if (status !== 200) {
|
809
|
+
if (statusText) {
|
810
|
+
statusText = statusText.replace(/\s+/g, " ");
|
811
|
+
}
|
812
|
+
message = "EventSource's response has a status " + status + " " + statusText + " that is not 200. Aborting the connection.";
|
813
|
+
} else {
|
814
|
+
message = "EventSource's response has a Content-Type specifying an unsupported type: " + (contentType == undefined ? "-" : contentType.replace(/\s+/g, " ")) + ". Aborting the connection.";
|
815
|
+
}
|
816
|
+
close();
|
817
|
+
var event = new ConnectionEvent("error", {
|
818
|
+
status: status,
|
819
|
+
statusText: statusText,
|
820
|
+
headers: headers
|
821
|
+
});
|
822
|
+
es.dispatchEvent(event);
|
823
|
+
fire(es, es.onerror, event);
|
824
|
+
console.error(message);
|
825
|
+
}
|
826
|
+
}
|
827
|
+
};
|
828
|
+
|
829
|
+
var onProgress = function (textChunk) {
|
830
|
+
if (currentState === OPEN) {
|
831
|
+
var n = -1;
|
832
|
+
for (var i = 0; i < textChunk.length; i += 1) {
|
833
|
+
var c = textChunk.charCodeAt(i);
|
834
|
+
if (c === "\n".charCodeAt(0) || c === "\r".charCodeAt(0)) {
|
835
|
+
n = i;
|
836
|
+
}
|
837
|
+
}
|
838
|
+
var chunk = (n !== -1 ? textBuffer : "") + textChunk.slice(0, n + 1);
|
839
|
+
textBuffer = (n === -1 ? textBuffer : "") + textChunk.slice(n + 1);
|
840
|
+
if (textChunk !== "") {
|
841
|
+
wasActivity = Date.now();
|
842
|
+
textLength += textChunk.length;
|
843
|
+
}
|
844
|
+
for (var position = 0; position < chunk.length; position += 1) {
|
845
|
+
var c = chunk.charCodeAt(position);
|
846
|
+
if (state === AFTER_CR && c === "\n".charCodeAt(0)) {
|
847
|
+
state = FIELD_START;
|
848
|
+
} else {
|
849
|
+
if (state === AFTER_CR) {
|
850
|
+
state = FIELD_START;
|
851
|
+
}
|
852
|
+
if (c === "\r".charCodeAt(0) || c === "\n".charCodeAt(0)) {
|
853
|
+
if (state !== FIELD_START) {
|
854
|
+
if (state === FIELD) {
|
855
|
+
valueStart = position + 1;
|
856
|
+
}
|
857
|
+
var field = chunk.slice(fieldStart, valueStart - 1);
|
858
|
+
var value = chunk.slice(valueStart + (valueStart < position && chunk.charCodeAt(valueStart) === " ".charCodeAt(0) ? 1 : 0), position);
|
859
|
+
if (field === "data") {
|
860
|
+
dataBuffer += "\n";
|
861
|
+
dataBuffer += value;
|
862
|
+
} else if (field === "id") {
|
863
|
+
lastEventIdBuffer = value;
|
864
|
+
} else if (field === "event") {
|
865
|
+
eventTypeBuffer = value;
|
866
|
+
} else if (field === "retry") {
|
867
|
+
initialRetry = parseDuration(value, initialRetry);
|
868
|
+
retry = initialRetry;
|
869
|
+
} else if (field === "heartbeatTimeout") {
|
870
|
+
heartbeatTimeout = parseDuration(value, heartbeatTimeout);
|
871
|
+
if (timeout !== 0) {
|
872
|
+
clearTimeout(timeout);
|
873
|
+
timeout = setTimeout(function () {
|
874
|
+
onTimeout();
|
875
|
+
}, heartbeatTimeout);
|
876
|
+
}
|
877
|
+
}
|
878
|
+
}
|
879
|
+
if (state === FIELD_START) {
|
880
|
+
if (dataBuffer !== "") {
|
881
|
+
lastEventId = lastEventIdBuffer;
|
882
|
+
if (eventTypeBuffer === "") {
|
883
|
+
eventTypeBuffer = "message";
|
884
|
+
}
|
885
|
+
var event = new MessageEvent(eventTypeBuffer, {
|
886
|
+
data: dataBuffer.slice(1),
|
887
|
+
lastEventId: lastEventIdBuffer
|
888
|
+
});
|
889
|
+
es.dispatchEvent(event);
|
890
|
+
if (eventTypeBuffer === "open") {
|
891
|
+
fire(es, es.onopen, event);
|
892
|
+
} else if (eventTypeBuffer === "message") {
|
893
|
+
fire(es, es.onmessage, event);
|
894
|
+
} else if (eventTypeBuffer === "error") {
|
895
|
+
fire(es, es.onerror, event);
|
896
|
+
}
|
897
|
+
if (currentState === CLOSED) {
|
898
|
+
return;
|
899
|
+
}
|
900
|
+
}
|
901
|
+
dataBuffer = "";
|
902
|
+
eventTypeBuffer = "";
|
903
|
+
}
|
904
|
+
state = c === "\r".charCodeAt(0) ? AFTER_CR : FIELD_START;
|
905
|
+
} else {
|
906
|
+
if (state === FIELD_START) {
|
907
|
+
fieldStart = position;
|
908
|
+
state = FIELD;
|
909
|
+
}
|
910
|
+
if (state === FIELD) {
|
911
|
+
if (c === ":".charCodeAt(0)) {
|
912
|
+
valueStart = position + 1;
|
913
|
+
state = VALUE_START;
|
914
|
+
}
|
915
|
+
} else if (state === VALUE_START) {
|
916
|
+
state = VALUE;
|
917
|
+
}
|
918
|
+
}
|
919
|
+
}
|
920
|
+
}
|
921
|
+
}
|
922
|
+
};
|
923
|
+
|
924
|
+
var onFinish = function (error) {
|
925
|
+
if (currentState === OPEN || currentState === CONNECTING) {
|
926
|
+
currentState = WAITING;
|
927
|
+
if (timeout !== 0) {
|
928
|
+
clearTimeout(timeout);
|
929
|
+
timeout = 0;
|
930
|
+
}
|
931
|
+
timeout = setTimeout(function () {
|
932
|
+
onTimeout();
|
933
|
+
}, retry);
|
934
|
+
retry = clampDuration(Math.min(initialRetry * 16, retry * 2));
|
935
|
+
|
936
|
+
es.readyState = CONNECTING;
|
937
|
+
var event = new ErrorEvent("error", {error: error});
|
938
|
+
es.dispatchEvent(event);
|
939
|
+
fire(es, es.onerror, event);
|
940
|
+
if (error != undefined) {
|
941
|
+
console.error(error);
|
942
|
+
}
|
943
|
+
}
|
944
|
+
};
|
945
|
+
|
946
|
+
var close = function () {
|
947
|
+
currentState = CLOSED;
|
948
|
+
if (abortController != undefined) {
|
949
|
+
abortController.abort();
|
950
|
+
abortController = undefined;
|
951
|
+
}
|
952
|
+
if (timeout !== 0) {
|
953
|
+
clearTimeout(timeout);
|
954
|
+
timeout = 0;
|
955
|
+
}
|
956
|
+
es.readyState = CLOSED;
|
957
|
+
};
|
958
|
+
|
959
|
+
var onTimeout = function () {
|
960
|
+
timeout = 0;
|
961
|
+
|
962
|
+
if (currentState !== WAITING) {
|
963
|
+
if (!wasActivity && abortController != undefined) {
|
964
|
+
onFinish(new Error("No activity within " + heartbeatTimeout + " milliseconds." + " " + (currentState === CONNECTING ? "No response received." : textLength + " chars received.") + " " + "Reconnecting."));
|
965
|
+
if (abortController != undefined) {
|
966
|
+
abortController.abort();
|
967
|
+
abortController = undefined;
|
968
|
+
}
|
969
|
+
} else {
|
970
|
+
var nextHeartbeat = Math.max((wasActivity || Date.now()) + heartbeatTimeout - Date.now(), 1);
|
971
|
+
wasActivity = false;
|
972
|
+
timeout = setTimeout(function () {
|
973
|
+
onTimeout();
|
974
|
+
}, nextHeartbeat);
|
975
|
+
}
|
976
|
+
return;
|
977
|
+
}
|
978
|
+
|
979
|
+
wasActivity = false;
|
980
|
+
textLength = 0;
|
981
|
+
timeout = setTimeout(function () {
|
982
|
+
onTimeout();
|
983
|
+
}, heartbeatTimeout);
|
984
|
+
|
985
|
+
currentState = CONNECTING;
|
986
|
+
dataBuffer = "";
|
987
|
+
eventTypeBuffer = "";
|
988
|
+
lastEventIdBuffer = lastEventId;
|
989
|
+
textBuffer = "";
|
990
|
+
fieldStart = 0;
|
991
|
+
valueStart = 0;
|
992
|
+
state = FIELD_START;
|
993
|
+
|
994
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=428916
|
995
|
+
// Request header field Last-Event-ID is not allowed by Access-Control-Allow-Headers.
|
996
|
+
var requestURL = url;
|
997
|
+
if (url.slice(0, 5) !== "data:" && url.slice(0, 5) !== "blob:") {
|
998
|
+
if (lastEventId !== "") {
|
999
|
+
// Remove the lastEventId parameter if it's already part of the request URL.
|
1000
|
+
var i = url.indexOf("?");
|
1001
|
+
requestURL = i === -1 ? url : url.slice(0, i + 1) + url.slice(i + 1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g, function (p, paramName) {
|
1002
|
+
return paramName === lastEventIdQueryParameterName ? '' : p;
|
1003
|
+
});
|
1004
|
+
// Append the current lastEventId to the request URL.
|
1005
|
+
requestURL += (url.indexOf("?") === -1 ? "?" : "&") + lastEventIdQueryParameterName +"=" + encodeURIComponent(lastEventId);
|
1006
|
+
}
|
1007
|
+
}
|
1008
|
+
var withCredentials = es.withCredentials;
|
1009
|
+
var requestHeaders = {};
|
1010
|
+
requestHeaders["Accept"] = "text/event-stream";
|
1011
|
+
var headers = es.headers;
|
1012
|
+
if (headers != undefined) {
|
1013
|
+
for (var name in headers) {
|
1014
|
+
if (Object.prototype.hasOwnProperty.call(headers, name)) {
|
1015
|
+
requestHeaders[name] = headers[name];
|
1016
|
+
}
|
1017
|
+
}
|
1018
|
+
}
|
1019
|
+
try {
|
1020
|
+
abortController = transport.open(xhr, onStart, onProgress, onFinish, requestURL, withCredentials, requestHeaders);
|
1021
|
+
} catch (error) {
|
1022
|
+
close();
|
1023
|
+
throw error;
|
1024
|
+
}
|
1025
|
+
};
|
1026
|
+
|
1027
|
+
es.url = url;
|
1028
|
+
es.readyState = CONNECTING;
|
1029
|
+
es.withCredentials = withCredentials;
|
1030
|
+
es.headers = headers;
|
1031
|
+
es._close = close;
|
1032
|
+
|
1033
|
+
onTimeout();
|
1034
|
+
}
|
1035
|
+
|
1036
|
+
EventSourcePolyfill.prototype = Object.create(EventTarget.prototype);
|
1037
|
+
EventSourcePolyfill.prototype.CONNECTING = CONNECTING;
|
1038
|
+
EventSourcePolyfill.prototype.OPEN = OPEN;
|
1039
|
+
EventSourcePolyfill.prototype.CLOSED = CLOSED;
|
1040
|
+
EventSourcePolyfill.prototype.close = function () {
|
1041
|
+
this._close();
|
1042
|
+
};
|
1043
|
+
|
1044
|
+
EventSourcePolyfill.CONNECTING = CONNECTING;
|
1045
|
+
EventSourcePolyfill.OPEN = OPEN;
|
1046
|
+
EventSourcePolyfill.CLOSED = CLOSED;
|
1047
|
+
EventSourcePolyfill.prototype.withCredentials = undefined;
|
1048
|
+
|
1049
|
+
var R = NativeEventSource
|
1050
|
+
if (XMLHttpRequest != undefined && (NativeEventSource == undefined || !("withCredentials" in NativeEventSource.prototype))) {
|
1051
|
+
// Why replace a native EventSource ?
|
1052
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=444328
|
1053
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=831392
|
1054
|
+
// https://code.google.com/p/chromium/issues/detail?id=260144
|
1055
|
+
// https://code.google.com/p/chromium/issues/detail?id=225654
|
1056
|
+
// ...
|
1057
|
+
R = EventSourcePolyfill;
|
1058
|
+
}
|
1059
|
+
|
1060
|
+
(function (factory) {
|
1061
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
1062
|
+
var v = factory(exports);
|
1063
|
+
if (v !== undefined) module.exports = v;
|
1064
|
+
}
|
1065
|
+
else if (typeof define === "function" && define.amd) {
|
1066
|
+
define(["exports"], factory);
|
1067
|
+
}
|
1068
|
+
else {
|
1069
|
+
factory(global);
|
1070
|
+
}
|
1071
|
+
})(function (exports) {
|
1072
|
+
exports.EventSourcePolyfill = EventSourcePolyfill;
|
1073
|
+
exports.NativeEventSource = NativeEventSource;
|
1074
|
+
exports.EventSource = R;
|
1075
|
+
});
|
1076
|
+
}(typeof globalThis === 'undefined' ? (typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : this) : globalThis));
|
1077
|
+
}}).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
|