@tntd/dll 1.0.1 → 1.0.2

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.
@@ -0,0 +1,672 @@
1
+ ;(function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined'
3
+ ? factory(exports)
4
+ : typeof define === 'function' && define.amd
5
+ ? define(['exports'], factory)
6
+ : factory((global.WHATWGFetch = {}))
7
+ })(this, function (exports) {
8
+ 'use strict'
9
+
10
+ var global =
11
+ (typeof globalThis !== 'undefined' && globalThis) ||
12
+ (typeof self !== 'undefined' && self) ||
13
+ (typeof global !== 'undefined' && global)
14
+
15
+ var support = {
16
+ searchParams: 'URLSearchParams' in global,
17
+ iterable: 'Symbol' in global && 'iterator' in Symbol,
18
+ blob:
19
+ 'FileReader' in global &&
20
+ 'Blob' in global &&
21
+ (function () {
22
+ try {
23
+ new Blob()
24
+ return true
25
+ } catch (e) {
26
+ return false
27
+ }
28
+ })(),
29
+ formData: 'FormData' in global,
30
+ arrayBuffer: 'ArrayBuffer' in global,
31
+ }
32
+
33
+ function isDataView(obj) {
34
+ return obj && DataView.prototype.isPrototypeOf(obj)
35
+ }
36
+
37
+ if (support.arrayBuffer) {
38
+ var viewClasses = [
39
+ '[object Int8Array]',
40
+ '[object Uint8Array]',
41
+ '[object Uint8ClampedArray]',
42
+ '[object Int16Array]',
43
+ '[object Uint16Array]',
44
+ '[object Int32Array]',
45
+ '[object Uint32Array]',
46
+ '[object Float32Array]',
47
+ '[object Float64Array]',
48
+ ]
49
+
50
+ var isArrayBufferView =
51
+ ArrayBuffer.isView ||
52
+ function (obj) {
53
+ return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1
54
+ }
55
+ }
56
+
57
+ function normalizeName(name) {
58
+ if (typeof name !== 'string') {
59
+ name = String(name)
60
+ }
61
+ if (/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(name) || name === '') {
62
+ throw new TypeError('Invalid character in header field name: "' + name + '"')
63
+ }
64
+ return name.toLowerCase()
65
+ }
66
+
67
+ function normalizeValue(value) {
68
+ if (typeof value !== 'string') {
69
+ value = String(value)
70
+ }
71
+ return value
72
+ }
73
+
74
+ // Build a destructive iterator for the value list
75
+ function iteratorFor(items) {
76
+ var iterator = {
77
+ next: function () {
78
+ var value = items.shift()
79
+ return { done: value === undefined, value: value }
80
+ },
81
+ }
82
+
83
+ if (support.iterable) {
84
+ iterator[Symbol.iterator] = function () {
85
+ return iterator
86
+ }
87
+ }
88
+
89
+ return iterator
90
+ }
91
+
92
+ function Headers(headers) {
93
+ this.map = {}
94
+
95
+ if (headers instanceof Headers) {
96
+ headers.forEach(function (value, name) {
97
+ this.append(name, value)
98
+ }, this)
99
+ } else if (Array.isArray(headers)) {
100
+ headers.forEach(function (header) {
101
+ this.append(header[0], header[1])
102
+ }, this)
103
+ } else if (headers) {
104
+ Object.getOwnPropertyNames(headers).forEach(function (name) {
105
+ this.append(name, headers[name])
106
+ }, this)
107
+ }
108
+ }
109
+
110
+ Headers.prototype.append = function (name, value) {
111
+ name = normalizeName(name)
112
+ value = normalizeValue(value)
113
+ var oldValue = this.map[name]
114
+ this.map[name] = oldValue ? oldValue + ', ' + value : value
115
+ }
116
+
117
+ Headers.prototype['delete'] = function (name) {
118
+ delete this.map[normalizeName(name)]
119
+ }
120
+
121
+ Headers.prototype.get = function (name) {
122
+ name = normalizeName(name)
123
+ return this.has(name) ? this.map[name] : null
124
+ }
125
+
126
+ Headers.prototype.has = function (name) {
127
+ return this.map.hasOwnProperty(normalizeName(name))
128
+ }
129
+
130
+ Headers.prototype.set = function (name, value) {
131
+ this.map[normalizeName(name)] = normalizeValue(value)
132
+ }
133
+
134
+ Headers.prototype.forEach = function (callback, thisArg) {
135
+ for (var name in this.map) {
136
+ if (this.map.hasOwnProperty(name)) {
137
+ callback.call(thisArg, this.map[name], name, this)
138
+ }
139
+ }
140
+ }
141
+
142
+ Headers.prototype.keys = function () {
143
+ var items = []
144
+ this.forEach(function (value, name) {
145
+ items.push(name)
146
+ })
147
+ return iteratorFor(items)
148
+ }
149
+
150
+ Headers.prototype.values = function () {
151
+ var items = []
152
+ this.forEach(function (value) {
153
+ items.push(value)
154
+ })
155
+ return iteratorFor(items)
156
+ }
157
+
158
+ Headers.prototype.entries = function () {
159
+ var items = []
160
+ this.forEach(function (value, name) {
161
+ items.push([name, value])
162
+ })
163
+ return iteratorFor(items)
164
+ }
165
+
166
+ if (support.iterable) {
167
+ Headers.prototype[Symbol.iterator] = Headers.prototype.entries
168
+ }
169
+
170
+ function consumed(body) {
171
+ if (body.bodyUsed) {
172
+ return Promise.reject(new TypeError('Already read'))
173
+ }
174
+ body.bodyUsed = true
175
+ }
176
+
177
+ function fileReaderReady(reader) {
178
+ return new Promise(function (resolve, reject) {
179
+ reader.onload = function () {
180
+ resolve(reader.result)
181
+ }
182
+ reader.onerror = function () {
183
+ reject(reader.error)
184
+ }
185
+ })
186
+ }
187
+
188
+ function readBlobAsArrayBuffer(blob) {
189
+ var reader = new FileReader()
190
+ var promise = fileReaderReady(reader)
191
+ reader.readAsArrayBuffer(blob)
192
+ return promise
193
+ }
194
+
195
+ function readBlobAsText(blob) {
196
+ var reader = new FileReader()
197
+ var promise = fileReaderReady(reader)
198
+ reader.readAsText(blob)
199
+ return promise
200
+ }
201
+
202
+ function readArrayBufferAsText(buf) {
203
+ var view = new Uint8Array(buf)
204
+ var chars = new Array(view.length)
205
+
206
+ for (var i = 0; i < view.length; i++) {
207
+ chars[i] = String.fromCharCode(view[i])
208
+ }
209
+ return chars.join('')
210
+ }
211
+
212
+ function bufferClone(buf) {
213
+ if (buf.slice) {
214
+ return buf.slice(0)
215
+ } else {
216
+ var view = new Uint8Array(buf.byteLength)
217
+ view.set(new Uint8Array(buf))
218
+ return view.buffer
219
+ }
220
+ }
221
+
222
+ function Body() {
223
+ this.bodyUsed = false
224
+
225
+ this._initBody = function (body) {
226
+ /*
227
+ fetch-mock wraps the Response object in an ES6 Proxy to
228
+ provide useful test harness features such as flush. However, on
229
+ ES5 browsers without fetch or Proxy support pollyfills must be used;
230
+ the proxy-pollyfill is unable to proxy an attribute unless it exists
231
+ on the object before the Proxy is created. This change ensures
232
+ Response.bodyUsed exists on the instance, while maintaining the
233
+ semantic of setting Request.bodyUsed in the constructor before
234
+ _initBody is called.
235
+ */
236
+ this.bodyUsed = this.bodyUsed
237
+ this._bodyInit = body
238
+ if (!body) {
239
+ this._bodyText = ''
240
+ } else if (typeof body === 'string') {
241
+ this._bodyText = body
242
+ } else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
243
+ this._bodyBlob = body
244
+ } else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
245
+ this._bodyFormData = body
246
+ } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
247
+ this._bodyText = body.toString()
248
+ } else if (support.arrayBuffer && support.blob && isDataView(body)) {
249
+ this._bodyArrayBuffer = bufferClone(body.buffer)
250
+ // IE 10-11 can't handle a DataView body.
251
+ this._bodyInit = new Blob([this._bodyArrayBuffer])
252
+ } else if (
253
+ support.arrayBuffer &&
254
+ (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))
255
+ ) {
256
+ this._bodyArrayBuffer = bufferClone(body)
257
+ } else {
258
+ this._bodyText = body = Object.prototype.toString.call(body)
259
+ }
260
+
261
+ if (!this.headers.get('content-type')) {
262
+ if (typeof body === 'string') {
263
+ this.headers.set('content-type', 'text/plain;charset=UTF-8')
264
+ } else if (this._bodyBlob && this._bodyBlob.type) {
265
+ this.headers.set('content-type', this._bodyBlob.type)
266
+ } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
267
+ this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8')
268
+ }
269
+ }
270
+ }
271
+
272
+ if (support.blob) {
273
+ this.blob = function () {
274
+ var rejected = consumed(this)
275
+ if (rejected) {
276
+ return rejected
277
+ }
278
+
279
+ if (this._bodyBlob) {
280
+ return Promise.resolve(this._bodyBlob)
281
+ } else if (this._bodyArrayBuffer) {
282
+ return Promise.resolve(new Blob([this._bodyArrayBuffer]))
283
+ } else if (this._bodyFormData) {
284
+ throw new Error('could not read FormData body as blob')
285
+ } else {
286
+ return Promise.resolve(new Blob([this._bodyText]))
287
+ }
288
+ }
289
+
290
+ this.arrayBuffer = function () {
291
+ if (this._bodyArrayBuffer) {
292
+ var isConsumed = consumed(this)
293
+ if (isConsumed) {
294
+ return isConsumed
295
+ }
296
+ if (ArrayBuffer.isView(this._bodyArrayBuffer)) {
297
+ return Promise.resolve(
298
+ this._bodyArrayBuffer.buffer.slice(
299
+ this._bodyArrayBuffer.byteOffset,
300
+ this._bodyArrayBuffer.byteOffset + this._bodyArrayBuffer.byteLength
301
+ )
302
+ )
303
+ } else {
304
+ return Promise.resolve(this._bodyArrayBuffer)
305
+ }
306
+ } else {
307
+ return this.blob().then(readBlobAsArrayBuffer)
308
+ }
309
+ }
310
+ }
311
+
312
+ this.text = function () {
313
+ var rejected = consumed(this)
314
+ if (rejected) {
315
+ return rejected
316
+ }
317
+
318
+ if (this._bodyBlob) {
319
+ return readBlobAsText(this._bodyBlob)
320
+ } else if (this._bodyArrayBuffer) {
321
+ return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer))
322
+ } else if (this._bodyFormData) {
323
+ throw new Error('could not read FormData body as text')
324
+ } else {
325
+ return Promise.resolve(this._bodyText)
326
+ }
327
+ }
328
+
329
+ if (support.formData) {
330
+ this.formData = function () {
331
+ return this.text().then(decode)
332
+ }
333
+ }
334
+
335
+ this.json = function () {
336
+ return this.text().then(JSON.parse)
337
+ }
338
+
339
+ return this
340
+ }
341
+
342
+ // HTTP methods whose capitalization should be normalized
343
+ var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT']
344
+
345
+ function normalizeMethod(method) {
346
+ var upcased = method.toUpperCase()
347
+ return methods.indexOf(upcased) > -1 ? upcased : method
348
+ }
349
+
350
+ function Request(input, options) {
351
+ if (!(this instanceof Request)) {
352
+ throw new TypeError(
353
+ 'Please use the "new" operator, this DOM object constructor cannot be called as a function.'
354
+ )
355
+ }
356
+
357
+ options = options || {}
358
+ var body = options.body
359
+
360
+ if (input instanceof Request) {
361
+ if (input.bodyUsed) {
362
+ throw new TypeError('Already read')
363
+ }
364
+ this.url = input.url
365
+ this.credentials = input.credentials
366
+ if (!options.headers) {
367
+ this.headers = new Headers(input.headers)
368
+ }
369
+ this.method = input.method
370
+ this.mode = input.mode
371
+ this.signal = input.signal
372
+ if (!body && input._bodyInit != null) {
373
+ body = input._bodyInit
374
+ input.bodyUsed = true
375
+ }
376
+ } else {
377
+ this.url = String(input)
378
+ }
379
+
380
+ this.credentials = options.credentials || this.credentials || 'same-origin'
381
+ if (options.headers || !this.headers) {
382
+ this.headers = new Headers(options.headers)
383
+ }
384
+ this.method = normalizeMethod(options.method || this.method || 'GET')
385
+ this.mode = options.mode || this.mode || null
386
+ this.signal = options.signal || this.signal
387
+ this.referrer = null
388
+
389
+ if ((this.method === 'GET' || this.method === 'HEAD') && body) {
390
+ throw new TypeError('Body not allowed for GET or HEAD requests')
391
+ }
392
+ this._initBody(body)
393
+
394
+ if (this.method === 'GET' || this.method === 'HEAD') {
395
+ if (options.cache === 'no-store' || options.cache === 'no-cache') {
396
+ // Search for a '_' parameter in the query string
397
+ var reParamSearch = /([?&])_=[^&]*/
398
+ if (reParamSearch.test(this.url)) {
399
+ // If it already exists then set the value with the current time
400
+ this.url = this.url.replace(reParamSearch, '$1_=' + new Date().getTime())
401
+ } else {
402
+ // Otherwise add a new '_' parameter to the end with the current time
403
+ var reQueryString = /\?/
404
+ this.url += (reQueryString.test(this.url) ? '&' : '?') + '_=' + new Date().getTime()
405
+ }
406
+ }
407
+ }
408
+ }
409
+
410
+ Request.prototype.clone = function () {
411
+ return new Request(this, { body: this._bodyInit })
412
+ }
413
+
414
+ function decode(body) {
415
+ var form = new FormData()
416
+ body
417
+ .trim()
418
+ .split('&')
419
+ .forEach(function (bytes) {
420
+ if (bytes) {
421
+ var split = bytes.split('=')
422
+ var name = split.shift().replace(/\+/g, ' ')
423
+ var value = split.join('=').replace(/\+/g, ' ')
424
+ form.append(decodeURIComponent(name), decodeURIComponent(value))
425
+ }
426
+ })
427
+ return form
428
+ }
429
+
430
+ function parseHeaders(rawHeaders) {
431
+ var headers = new Headers()
432
+ // Replace instances of \r\n and \n followed by at least one space or horizontal tab with a space
433
+ // https://tools.ietf.org/html/rfc7230#section-3.2
434
+ var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, ' ')
435
+ // Avoiding split via regex to work around a common IE11 bug with the core-js 3.6.0 regex polyfill
436
+ // https://github.com/github/fetch/issues/748
437
+ // https://github.com/zloirock/core-js/issues/751
438
+ preProcessedHeaders
439
+ .split('\r')
440
+ .map(function (header) {
441
+ return header.indexOf('\n') === 0 ? header.substr(1, header.length) : header
442
+ })
443
+ .forEach(function (line) {
444
+ var parts = line.split(':')
445
+ var key = parts.shift().trim()
446
+ if (key) {
447
+ var value = parts.join(':').trim()
448
+ headers.append(key, value)
449
+ }
450
+ })
451
+ return headers
452
+ }
453
+
454
+ Body.call(Request.prototype)
455
+
456
+ function Response(bodyInit, options) {
457
+ if (!(this instanceof Response)) {
458
+ throw new TypeError(
459
+ 'Please use the "new" operator, this DOM object constructor cannot be called as a function.'
460
+ )
461
+ }
462
+ if (!options) {
463
+ options = {}
464
+ }
465
+
466
+ this.type = 'default'
467
+ this.status = options.status === undefined ? 200 : options.status
468
+ this.ok = this.status >= 200 && this.status < 300
469
+ this.statusText = options.statusText === undefined ? '' : '' + options.statusText
470
+ this.headers = new Headers(options.headers)
471
+ this.url = options.url || ''
472
+ this._initBody(bodyInit)
473
+ }
474
+
475
+ Body.call(Response.prototype)
476
+
477
+ Response.prototype.clone = function () {
478
+ return new Response(this._bodyInit, {
479
+ status: this.status,
480
+ statusText: this.statusText,
481
+ headers: new Headers(this.headers),
482
+ url: this.url,
483
+ })
484
+ }
485
+
486
+ Response.error = function () {
487
+ var response = new Response(null, { status: 0, statusText: '' })
488
+ response.type = 'error'
489
+ return response
490
+ }
491
+
492
+ var redirectStatuses = [301, 302, 303, 307, 308]
493
+
494
+ Response.redirect = function (url, status) {
495
+ if (redirectStatuses.indexOf(status) === -1) {
496
+ throw new RangeError('Invalid status code')
497
+ }
498
+
499
+ return new Response(null, { status: status, headers: { location: url } })
500
+ }
501
+
502
+ exports.DOMException = global.DOMException
503
+ try {
504
+ new exports.DOMException()
505
+ } catch (err) {
506
+ exports.DOMException = function (message, name) {
507
+ this.message = message
508
+ this.name = name
509
+ var error = Error(message)
510
+ this.stack = error.stack
511
+ }
512
+ exports.DOMException.prototype = Object.create(Error.prototype)
513
+ exports.DOMException.prototype.constructor = exports.DOMException
514
+ }
515
+
516
+ function fetch(input, init) {
517
+ return new Promise(function (resolve, reject) {
518
+ var request = new Request(input, init)
519
+
520
+ if (request.signal && request.signal.aborted) {
521
+ return reject(new exports.DOMException('Aborted', 'AbortError'))
522
+ }
523
+
524
+ var xhr = new XMLHttpRequest()
525
+
526
+ function abortXhr() {
527
+ xhr.abort()
528
+ }
529
+
530
+ xhr.onload = function () {
531
+ var options = {
532
+ status: xhr.status,
533
+ statusText: xhr.statusText,
534
+ headers: parseHeaders(xhr.getAllResponseHeaders() || ''),
535
+ }
536
+ options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL')
537
+ var body = 'response' in xhr ? xhr.response : xhr.responseText
538
+ setTimeout(function () {
539
+ resolve(new Response(body, options))
540
+ }, 0)
541
+ }
542
+
543
+ xhr.onerror = function () {
544
+ setTimeout(function () {
545
+ reject(new TypeError('Network request failed'))
546
+ }, 0)
547
+ }
548
+
549
+ xhr.ontimeout = function () {
550
+ setTimeout(function () {
551
+ reject(new TypeError('Network request failed'))
552
+ }, 0)
553
+ }
554
+
555
+ xhr.onabort = function () {
556
+ setTimeout(function () {
557
+ reject(new exports.DOMException('Aborted', 'AbortError'))
558
+ }, 0)
559
+ }
560
+
561
+ function fixUrl(url) {
562
+ try {
563
+ return url === '' && global.location.href ? global.location.href : url
564
+ } catch (e) {
565
+ return url
566
+ }
567
+ }
568
+
569
+ xhr.open(request.method, fixUrl(request.url), true)
570
+
571
+ if (request.credentials === 'include') {
572
+ xhr.withCredentials = true
573
+ } else if (request.credentials === 'omit') {
574
+ xhr.withCredentials = false
575
+ }
576
+
577
+ if ('responseType' in xhr) {
578
+ if (support.blob) {
579
+ xhr.responseType = 'blob'
580
+ } else if (
581
+ support.arrayBuffer &&
582
+ request.headers.get('Content-Type') &&
583
+ request.headers.get('Content-Type').indexOf('application/octet-stream') !== -1
584
+ ) {
585
+ xhr.responseType = 'arraybuffer'
586
+ }
587
+ }
588
+
589
+ if (init && typeof init.headers === 'object' && !(init.headers instanceof Headers)) {
590
+ Object.getOwnPropertyNames(init.headers).forEach(function (name) {
591
+ xhr.setRequestHeader(name, normalizeValue(init.headers[name]))
592
+ })
593
+ } else {
594
+ request.headers.forEach(function (value, name) {
595
+ xhr.setRequestHeader(name, value)
596
+ })
597
+ }
598
+
599
+ if (request.signal) {
600
+ request.signal.addEventListener('abort', abortXhr)
601
+
602
+ xhr.onreadystatechange = function () {
603
+ // DONE (success or failure)
604
+ if (xhr.readyState === 4) {
605
+ request.signal.removeEventListener('abort', abortXhr)
606
+ }
607
+ }
608
+ }
609
+
610
+ xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit)
611
+ })
612
+ }
613
+
614
+ fetch.polyfill = true
615
+
616
+ if (!global.fetch) {
617
+ global.fetch = fetch
618
+ global.Headers = Headers
619
+ global.Request = Request
620
+ global.Response = Response
621
+ }
622
+
623
+ exports.Headers = Headers
624
+ exports.Request = Request
625
+ exports.Response = Response
626
+ exports.fetch = fetch
627
+
628
+ Object.defineProperty(exports, '__esModule', { value: true })
629
+ })
630
+
631
+ // Event 兼容性处理
632
+ ;(function () {
633
+ // 检查是否需要 polyfill
634
+ if (typeof window.Event === 'function') return
635
+
636
+ function Event(event, params) {
637
+ params = params || {
638
+ bubbles: false,
639
+ cancelable: false,
640
+ composed: false,
641
+ }
642
+
643
+ var evt = document.createEvent('Event')
644
+ evt.initEvent(event, params.bubbles, params.cancelable)
645
+
646
+ // 添加 composed 属性
647
+ Object.defineProperty(evt, 'composed', {
648
+ enumerable: true,
649
+ configurable: true,
650
+ value: params.composed,
651
+ })
652
+
653
+ return evt
654
+ }
655
+
656
+ // CustomEvent polyfill
657
+ function CustomEvent(event, params) {
658
+ params = params || {
659
+ bubbles: false,
660
+ cancelable: false,
661
+ detail: null,
662
+ }
663
+
664
+ var evt = document.createEvent('CustomEvent')
665
+ evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail)
666
+ return evt
667
+ }
668
+
669
+ // 替换原生构造函数
670
+ window.Event = Event
671
+ window.CustomEvent = CustomEvent
672
+ })()