@loaders.gl/polyfills 3.1.0-alpha.4 → 3.1.0-beta.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.
Files changed (140) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +3994 -0
  4. package/dist/es5/bundle.js +1 -1
  5. package/dist/es5/bundle.js.map +1 -1
  6. package/dist/es5/index.js +11 -13
  7. package/dist/es5/index.js.map +1 -1
  8. package/dist/es5/lib/encoding-indexes.js +37 -0
  9. package/dist/es5/lib/encoding-indexes.js.map +1 -0
  10. package/dist/es5/lib/encoding.js +1459 -0
  11. package/dist/es5/lib/encoding.js.map +1 -0
  12. package/dist/{esm/libs/encoding-indexes.js → es5/libs/encoding-indexes-asian.js} +2 -40
  13. package/dist/es5/node/buffer/to-array-buffer.node.js +1 -1
  14. package/dist/es5/node/buffer/to-array-buffer.node.js.map +1 -1
  15. package/dist/es5/node/fetch/fetch.node.js +69 -100
  16. package/dist/es5/node/fetch/fetch.node.js.map +1 -1
  17. package/dist/es5/node/fetch/headers.node.js +73 -112
  18. package/dist/es5/node/fetch/headers.node.js.map +1 -1
  19. package/dist/es5/node/fetch/response.node.js +47 -182
  20. package/dist/es5/node/fetch/response.node.js.map +1 -1
  21. package/dist/es5/node/fetch/utils/decode-data-uri.node.js +10 -18
  22. package/dist/es5/node/fetch/utils/decode-data-uri.node.js.map +1 -1
  23. package/dist/es5/node/fetch/utils/stream-utils.node.js +46 -126
  24. package/dist/es5/node/fetch/utils/stream-utils.node.js.map +1 -1
  25. package/dist/es5/node/file/blob-stream-controller.js +37 -82
  26. package/dist/es5/node/file/blob-stream-controller.js.map +1 -1
  27. package/dist/es5/node/file/blob-stream.js +12 -67
  28. package/dist/es5/node/file/blob-stream.js.map +1 -1
  29. package/dist/es5/node/file/blob.js +100 -209
  30. package/dist/es5/node/file/blob.js.map +1 -1
  31. package/dist/es5/node/file/file-reader.js +40 -147
  32. package/dist/es5/node/file/file-reader.js.map +1 -1
  33. package/dist/es5/node/file/file.js +13 -41
  34. package/dist/es5/node/file/file.js.map +1 -1
  35. package/dist/es5/node/file/readable-stream.js +1 -26
  36. package/dist/es5/node/file/readable-stream.js.map +1 -1
  37. package/dist/es5/node/images/encode-image.node.js +8 -10
  38. package/dist/es5/node/images/encode-image.node.js.map +1 -1
  39. package/dist/es5/node/images/parse-image.node.js +17 -44
  40. package/dist/es5/node/images/parse-image.node.js.map +1 -1
  41. package/dist/es5/promise/all-settled.js +7 -7
  42. package/dist/es5/promise/all-settled.js.map +1 -1
  43. package/dist/es5/utils/globals.js +3 -8
  44. package/dist/es5/utils/globals.js.map +1 -1
  45. package/dist/esm/index.js +2 -2
  46. package/dist/esm/index.js.map +1 -1
  47. package/dist/esm/lib/encoding-indexes.js +30 -0
  48. package/dist/esm/lib/encoding-indexes.js.map +1 -0
  49. package/dist/esm/lib/encoding.js +1450 -0
  50. package/dist/esm/lib/encoding.js.map +1 -0
  51. package/dist/{es5/libs/encoding-indexes.js → esm/libs/encoding-indexes-asian.js} +2 -40
  52. package/dist/esm/node/fetch/fetch.node.js +12 -1
  53. package/dist/esm/node/fetch/fetch.node.js.map +1 -1
  54. package/dist/esm/node/fetch/headers.node.js +1 -1
  55. package/dist/esm/node/fetch/headers.node.js.map +1 -1
  56. package/dist/esm/node/fetch/utils/decode-data-uri.node.js +2 -2
  57. package/dist/esm/node/fetch/utils/decode-data-uri.node.js.map +1 -1
  58. package/dist/esm/node/file/file-reader.js +1 -1
  59. package/dist/esm/node/file/file-reader.js.map +1 -1
  60. package/dist/esm/utils/assert.js +1 -1
  61. package/dist/esm/utils/assert.js.map +1 -1
  62. package/dist/index.d.ts +6 -0
  63. package/dist/index.d.ts.map +1 -0
  64. package/dist/index.js +98 -0
  65. package/dist/lib/encoding-indexes.d.ts +31 -0
  66. package/dist/lib/encoding-indexes.d.ts.map +1 -0
  67. package/dist/lib/encoding-indexes.js +35 -0
  68. package/dist/lib/encoding.d.ts +15 -0
  69. package/dist/lib/encoding.d.ts.map +1 -0
  70. package/dist/lib/encoding.js +2779 -0
  71. package/dist/libs/encoding-indexes-asian.d.ts +10 -0
  72. package/dist/libs/encoding-indexes-asian.d.ts.map +1 -0
  73. package/dist/libs/encoding-indexes-asian.js +14 -0
  74. package/dist/node/buffer/btoa.node.d.ts +3 -0
  75. package/dist/node/buffer/btoa.node.d.ts.map +1 -0
  76. package/dist/node/buffer/btoa.node.js +14 -0
  77. package/dist/node/buffer/to-array-buffer.node.d.ts +2 -0
  78. package/dist/node/buffer/to-array-buffer.node.d.ts.map +1 -0
  79. package/dist/node/buffer/to-array-buffer.node.js +12 -0
  80. package/dist/node/fetch/fetch.node.d.ts +7 -0
  81. package/dist/node/fetch/fetch.node.d.ts.map +1 -0
  82. package/dist/node/fetch/fetch.node.js +117 -0
  83. package/dist/node/fetch/headers.node.d.ts +34 -0
  84. package/dist/node/fetch/headers.node.d.ts.map +1 -0
  85. package/dist/node/fetch/headers.node.js +105 -0
  86. package/dist/node/fetch/response.node.d.ts +22 -0
  87. package/dist/node/fetch/response.node.d.ts.map +1 -0
  88. package/dist/node/fetch/response.node.js +77 -0
  89. package/dist/node/fetch/utils/decode-data-uri.node.d.ts +16 -0
  90. package/dist/node/fetch/utils/decode-data-uri.node.d.ts.map +1 -0
  91. package/dist/node/fetch/utils/decode-data-uri.node.js +63 -0
  92. package/dist/node/fetch/utils/stream-utils.node.d.ts +4 -0
  93. package/dist/node/fetch/utils/stream-utils.node.d.ts.map +1 -0
  94. package/dist/node/fetch/utils/stream-utils.node.js +98 -0
  95. package/dist/node/file/blob-stream-controller.d.ts +29 -0
  96. package/dist/node/file/blob-stream-controller.d.ts.map +1 -0
  97. package/dist/node/file/blob-stream-controller.js +63 -0
  98. package/dist/node/file/blob-stream.d.ts +25 -0
  99. package/dist/node/file/blob-stream.d.ts.map +1 -0
  100. package/dist/node/file/blob-stream.js +37 -0
  101. package/dist/node/file/blob.d.ts +58 -0
  102. package/dist/node/file/blob.d.ts.map +1 -0
  103. package/dist/node/file/blob.js +160 -0
  104. package/dist/node/file/file-reader.d.ts +24 -0
  105. package/dist/node/file/file-reader.d.ts.map +1 -0
  106. package/dist/node/file/file-reader.js +35 -0
  107. package/dist/node/file/file.d.ts +25 -0
  108. package/dist/node/file/file.d.ts.map +1 -0
  109. package/dist/node/file/file.js +37 -0
  110. package/dist/node/file/install-file-polyfills.d.ts +2 -0
  111. package/dist/node/file/install-file-polyfills.d.ts.map +1 -0
  112. package/dist/node/file/install-file-polyfills.js +27 -0
  113. package/dist/node/file/readable-stream.d.ts +4 -0
  114. package/dist/node/file/readable-stream.d.ts.map +1 -0
  115. package/dist/node/file/readable-stream.js +11 -0
  116. package/dist/node/images/encode-image.node.d.ts +20 -0
  117. package/dist/node/images/encode-image.node.d.ts.map +1 -0
  118. package/dist/node/images/encode-image.node.js +41 -0
  119. package/dist/node/images/parse-image.node.d.ts +11 -0
  120. package/dist/node/images/parse-image.node.d.ts.map +1 -0
  121. package/dist/node/images/parse-image.node.js +29 -0
  122. package/dist/promise/all-settled.d.ts +10 -0
  123. package/dist/promise/all-settled.d.ts.map +1 -0
  124. package/dist/promise/all-settled.js +24 -0
  125. package/dist/utils/assert.d.ts +2 -0
  126. package/dist/utils/assert.d.ts.map +1 -0
  127. package/dist/utils/assert.js +9 -0
  128. package/dist/utils/globals.d.ts +4 -0
  129. package/dist/utils/globals.d.ts.map +1 -0
  130. package/dist/utils/globals.js +36 -0
  131. package/package.json +6 -6
  132. package/src/index.ts +2 -2
  133. package/src/lib/encoding-indexes.ts +34 -0
  134. package/{dist/esm/libs/encoding.js → src/lib/encoding.ts} +78 -78
  135. package/src/libs/{encoding-indexes.js → encoding-indexes-asian.js} +2 -40
  136. package/src/node/fetch/fetch.node.ts +19 -2
  137. package/dist/dist.min.js +0 -2
  138. package/dist/dist.min.js.map +0 -1
  139. package/dist/es5/libs/encoding.js +0 -3084
  140. package/src/libs/encoding.js +0 -3084
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/node/file/blob.ts"],"names":["Symbol","toStringTag","BlobPolyfill","init","options","parts","size","part","bytes","TextEncoder","encode","push","byteLength","ArrayBuffer","Uint8Array","isView","buffer","byteOffset","String","type","readType","start","end","offset","Math","max","min","limit","span","blob","blobSize","blobParts","chunk","subarray","_toArrayBuffer","decoder","TextDecoder","text","decode","BlobStream","set","input","toLowerCase","test"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA;;;;;;;;;;sBAsJOA,MAAM,CAACC,W;;IAhJDC,Y;AAWX,0BAAkE;AAAA,QAAtDC,IAAsD,uEAAnC,EAAmC;AAAA,QAA/BC,OAA+B,uEAAJ,EAAI;AAAA;AAAA;AAAA;AAAA;AAChE,SAAKC,KAAL,GAAa,EAAb;AAEA,SAAKC,IAAL,GAAY,CAAZ;;AAHgE,+CAI7CH,IAJ6C;AAAA;;AAAA;AAIhE,0DAAyB;AAAA,YAAdI,IAAc;;AACvB,YAAI,OAAOA,IAAP,KAAgB,QAApB,EAA8B;AAC5B,cAAMC,KAAK,GAAG,IAAIC,WAAJ,GAAkBC,MAAlB,CAAyBH,IAAzB,CAAd;AACA,eAAKF,KAAL,CAAWM,IAAX,CAAgBH,KAAhB;AACA,eAAKF,IAAL,IAAaE,KAAK,CAACI,UAAnB;AACD,SAJD,MAIO,IAAIL,IAAI,YAAYL,YAApB,EAAkC;AAAA;;AACvC,eAAKI,IAAL,IAAaC,IAAI,CAACD,IAAlB;;AAGA,8BAAKD,KAAL,EAAWM,IAAX,qDAAmBJ,IAAI,CAACF,KAAxB;AACD,SALM,MAKA,IAAIE,IAAI,YAAYM,WAApB,EAAiC;AACtC,eAAKR,KAAL,CAAWM,IAAX,CAAgB,IAAIG,UAAJ,CAAeP,IAAf,CAAhB;AACA,eAAKD,IAAL,IAAaC,IAAI,CAACK,UAAlB;AACD,SAHM,MAGA,IAAIL,IAAI,YAAYO,UAApB,EAAgC;AACrC,eAAKT,KAAL,CAA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A5C;AACD","sourcesContent":["// Forked from @gozala's web-blob under MIT license https://github.com/Gozala/web-blob\nimport {BlobStream} from './blob-stream';\n\n/**\n * Forked from @gozala's web-blob under MIT license\n * @see https://github.com/Gozala/web-blob\n */\nexport class BlobPolyfill {\n // implements Blob {\n /** The MIME type of the data contained in the Blob. If type is unknown, string is empty. */\n readonly type: string;\n /** The size, in bytes, of the data contained in the Blob object. */\n size: number;\n private parts: Uint8Array[];\n /**\n * @param [init]\n * @param [options]\n */\n constructor(init: BlobPart[] = [], options: BlobPropertyBag = {}) {\n this.parts = [];\n\n this.size = 0;\n for (const part of init) {\n if (typeof part === 'string') {\n const bytes = new TextEncoder().encode(part);\n this.parts.push(bytes);\n this.size += bytes.byteLength;\n } else if (part instanceof BlobPolyfill) {\n this.size += part.size;\n // @ts-ignore - `parts` is marked private so TS will complain about\n // accessing it.\n this.parts.push(...part.parts);\n } else if (part instanceof ArrayBuffer) {\n this.parts.push(new Uint8Array(part));\n this.size += part.byteLength;\n } else if (part instanceof Uint8Array) {\n this.parts.push(part);\n this.size += part.byteLength;\n } else if (ArrayBuffer.isView(part)) {\n const {buffer, byteOffset, byteLength} = part;\n this.parts.push(new Uint8Array(buffer, byteOffset, byteLength));\n this.size += byteLength;\n } else {\n const bytes = new TextEncoder().encode(String(part));\n this.parts.push(bytes);\n this.size += bytes.byteLength;\n }\n }\n\n /** @private */\n this.type = readType(options.type);\n }\n\n /**\n * Returns a new Blob object containing the data in the specified range of\n * bytes of the blob on which it's called.\n * @param start=0 - An index into the Blob indicating the first\n * byte to include in the new Blob. If you specify a negative value, it's\n * treated as an offset from the end of the Blob toward the beginning. For\n * example, `-10` would be the 10th from last byte in the Blob. The default\n * value is `0`. If you specify a value for start that is larger than the\n * size of the source Blob, the returned Blob has size 0 and contains no\n * data.\n * @param end - An index into the `Blob` indicating the first byte\n * that will *not* be included in the new `Blob` (i.e. the byte exactly at\n * this index is not included). If you specify a negative value, it's treated\n * as an offset from the end of the Blob toward the beginning. For example,\n * `-10` would be the 10th from last byte in the `Blob`. The default value is\n * size.\n * @param type - The content type to assign to the new Blob;\n * this will be the value of its type property. The default value is an empty\n * string.\n */\n slice(start: number = 0, end: number = this.size, type: string = ''): Blob {\n const {size, parts: parts} = this;\n let offset = start < 0 ? Math.max(size + start, 0) : Math.min(start, size);\n\n let limit = end < 0 ? Math.max(size + end, 0) : Math.min(end, size);\n const span = Math.max(limit - offset, 0);\n const blob = new BlobPolyfill([], {type});\n\n if (span === 0) {\n // @ts-ignore\n return blob;\n }\n\n let blobSize = 0;\n const blobParts: Uint8Array[] = [];\n for (const part of parts) {\n const {byteLength} = part;\n if (offset > 0 && byteLength <= offset) {\n offset -= byteLength;\n limit -= byteLength;\n } else {\n const chunk = part.subarray(offset, Math.min(byteLength, limit));\n blobParts.push(chunk);\n blobSize += chunk.byteLength;\n // no longer need to take that into account\n offset = 0;\n\n // don't add the overflow to new blobParts\n if (blobSize >= span) {\n break;\n }\n }\n }\n\n blob.parts = blobParts;\n blob.size = blobSize;\n\n // @ts-ignore\n return blob;\n }\n\n /**\n * Returns a promise that resolves with an ArrayBuffer containing the entire\n * contents of the Blob as binary data.\n */\n // eslint-disable-next-line require-await\n async arrayBuffer(): Promise<ArrayBuffer> {\n return this._toArrayBuffer();\n }\n\n /**\n * Returns a promise that resolves with a USVString containing the entire\n * contents of the Blob interpreted as UTF-8 text.\n */\n // eslint-disable-next-line require-await\n async text(): Promise<string> {\n const decoder = new TextDecoder();\n let text = '';\n for (const part of this.parts) {\n text += decoder.decode(part);\n }\n return text;\n }\n\n /**\n */\n // @ts-ignore\n stream(): BlobStream<any> {\n return new BlobStream<any>(this.parts);\n }\n\n /**\n * @returns {string}\n */\n toString() {\n return '[object Blob]';\n }\n\n get [Symbol.toStringTag]() {\n return 'Blob';\n }\n\n _toArrayBuffer(): ArrayBuffer {\n const buffer = new ArrayBuffer(this.size);\n const bytes = new Uint8Array(buffer);\n let offset = 0;\n for (const part of this.parts) {\n bytes.set(part, offset);\n offset += part.byteLength;\n }\n return buffer;\n }\n}\n\n/**\n */\nfunction readType(input: string = ''): string {\n const type = String(input).toLowerCase();\n return /[^\\u0020-\\u007E]/.test(type) ? '' : type;\n}\n"],"file":"blob.js"}
1
+ {"version":3,"sources":["../../../../src/node/file/blob.ts"],"names":["Symbol","toStringTag","BlobPolyfill","constructor","init","options","parts","size","part","bytes","TextEncoder","encode","push","byteLength","ArrayBuffer","Uint8Array","isView","buffer","byteOffset","String","type","readType","slice","start","end","offset","Math","max","min","limit","span","blob","blobSize","blobParts","chunk","subarray","arrayBuffer","_toArrayBuffer","text","decoder","TextDecoder","decode","stream","BlobStream","toString","set","input","toLowerCase","test"],"mappings":";;;;;;;;;;;AACA;;;;sBAsJOA,MAAM,CAACC,W;;AAhJP,MAAMC,YAAN,CAAmB;AAWxBC,EAAAA,WAAW,CAACC,IAAgB,GAAG,EAApB,EAAwBC,OAAwB,GAAG,EAAnD,EAAuD;AAAA;AAAA;AAAA;AAChE,SAAKC,KAAL,GAAa,EAAb;AAEA,SAAKC,IAAL,GAAY,CAAZ;;AACA,SAAK,MAAMC,IAAX,IAAmBJ,IAAnB,EAAyB;AACvB,UAAI,OAAOI,IAAP,KAAgB,QAApB,EAA8B;AAC5B,cAAMC,KAAK,GAAG,IAAIC,WAAJ,GAAkBC,MAAlB,CAAyBH,IAAzB,CAAd;AACA,aAAKF,KAAL,CAAWM,IAAX,CAAgBH,KAAhB;AACA,aAAKF,IAAL,IAAaE,KAAK,CAACI,UAAnB;AACD,OAJD,MAIO,IAAIL,IAAI,YAAYN,YAApB,EAAkC;AACvC,aAAKK,IAAL,IAAaC,IAAI,CAACD,IAAlB;AAGA,aAAKD,KAAL,CAAWM,IAAX,CAAgB,GAAGJ,IAAI,CAACF,KAAxB;AACD,OALM,MAKA,IAAIE,IAAI,YAAYM,WAApB,EAAiC;AACtC,aAAKR,KAAL,CAAWM,IAAX,CAAgB,IAAIG,UAAJ,CAAeP,IAAf,CAAhB;AACA,aAAKD,IAAL,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,QAAIF,IAAI,GAAG,EAAX;;AACA,SAAK,MAAM9B,IAAX,IAAmB,KAAKF,KAAxB,EAA+B;AAC7BgC,MAAAA,IAAI,IAAIC,OAAO,CAACE,MAAR,CAAejC,IAAf,CAAR;AACD;;AACD,WAAO8B,IAAP;AACD;;AAKDI,EAAAA,MAAM,GAAoB;AACxB,WAAO,IAAIC,sBAAJ,CAAoB,KAAKrC,KAAzB,CAAP;AACD;;AAKDsC,EAAAA,QAAQ,GAAG;AACT,WAAO,eAAP;AACD;;AAED,8BAA2B;AACzB,WAAO,MAAP;AACD;;AAEDP,EAAAA,cAAc,GAAgB;AAC5B,UAAMpB,MAAM,GAAG,IAAIH,WAAJ,CAAgB,KAAKP,IAArB,CAAf;AACA,UAAME,KAAK,GAAG,IAAIM,UAAJ,CAAeE,MAAf,CAAd;AACA,QAAIQ,MAAM,GAAG,CAAb;;AACA,SAAK,MAAMjB,IAAX,IAAmB,KAAKF,KAAxB,EAA+B;AAC7BG,MAAAA,KAAK,CAACoC,GAAN,CAAUrC,IAAV,EAAgBiB,MAAhB;AACAA,MAAAA,MAAM,IAAIjB,IAAI,CAACK,UAAf;AACD;;AACD,WAAOI,MAAP;AACD;;AA7JuB;;;;AAkK1B,SAASI,QAAT,CAAkByB,KAAa,GAAG,EAAlC,EAA8C;AAC5C,QAAM1B,IAAI,GAAGD,MAAM,CAAC2B,KAAD,CAAN,CAAcC,WAAd,EAAb;AACA,SAAO,mBAAmBC,IAAnB,CAAwB5B,IAAxB,IAAgC,EAAhC,GAAqCA,IAA5C;AACD","sourcesContent":["// Forked from @gozala's web-blob under MIT license https://github.com/Gozala/web-blob\nimport {BlobStream} from './blob-stream';\n\n/**\n * Forked from @gozala's web-blob under MIT license\n * @see https://github.com/Gozala/web-blob\n */\nexport class BlobPolyfill {\n // implements Blob {\n /** The MIME type of the data contained in the Blob. If type is unknown, string is empty. */\n readonly type: string;\n /** The size, in bytes, of the data contained in the Blob object. */\n size: number;\n private parts: Uint8Array[];\n /**\n * @param [init]\n * @param [options]\n */\n constructor(init: BlobPart[] = [], options: BlobPropertyBag = {}) {\n this.parts = [];\n\n this.size = 0;\n for (const part of init) {\n if (typeof part === 'string') {\n const bytes = new TextEncoder().encode(part);\n this.parts.push(bytes);\n this.size += bytes.byteLength;\n } else if (part instanceof BlobPolyfill) {\n this.size += part.size;\n // @ts-ignore - `parts` is marked private so TS will complain about\n // accessing it.\n this.parts.push(...part.parts);\n } else if (part instanceof ArrayBuffer) {\n this.parts.push(new Uint8Array(part));\n this.size += part.byteLength;\n } else if (part instanceof Uint8Array) {\n this.parts.push(part);\n this.size += part.byteLength;\n } else if (ArrayBuffer.isView(part)) {\n const {buffer, byteOffset, byteLength} = part;\n this.parts.push(new Uint8Array(buffer, byteOffset, byteLength));\n this.size += byteLength;\n } else {\n const bytes = new TextEncoder().encode(String(part));\n this.parts.push(bytes);\n this.size += bytes.byteLength;\n }\n }\n\n /** @private */\n this.type = readType(options.type);\n }\n\n /**\n * Returns a new Blob object containing the data in the specified range of\n * bytes of the blob on which it's called.\n * @param start=0 - An index into the Blob indicating the first\n * byte to include in the new Blob. If you specify a negative value, it's\n * treated as an offset from the end of the Blob toward the beginning. For\n * example, `-10` would be the 10th from last byte in the Blob. The default\n * value is `0`. If you specify a value for start that is larger than the\n * size of the source Blob, the returned Blob has size 0 and contains no\n * data.\n * @param end - An index into the `Blob` indicating the first byte\n * that will *not* be included in the new `Blob` (i.e. the byte exactly at\n * this index is not included). If you specify a negative value, it's treated\n * as an offset from the end of the Blob toward the beginning. For example,\n * `-10` would be the 10th from last byte in the `Blob`. The default value is\n * size.\n * @param type - The content type to assign to the new Blob;\n * this will be the value of its type property. The default value is an empty\n * string.\n */\n slice(start: number = 0, end: number = this.size, type: string = ''): Blob {\n const {size, parts: parts} = this;\n let offset = start < 0 ? Math.max(size + start, 0) : Math.min(start, size);\n\n let limit = end < 0 ? Math.max(size + end, 0) : Math.min(end, size);\n const span = Math.max(limit - offset, 0);\n const blob = new BlobPolyfill([], {type});\n\n if (span === 0) {\n // @ts-ignore\n return blob;\n }\n\n let blobSize = 0;\n const blobParts: Uint8Array[] = [];\n for (const part of parts) {\n const {byteLength} = part;\n if (offset > 0 && byteLength <= offset) {\n offset -= byteLength;\n limit -= byteLength;\n } else {\n const chunk = part.subarray(offset, Math.min(byteLength, limit));\n blobParts.push(chunk);\n blobSize += chunk.byteLength;\n // no longer need to take that into account\n offset = 0;\n\n // don't add the overflow to new blobParts\n if (blobSize >= span) {\n break;\n }\n }\n }\n\n blob.parts = blobParts;\n blob.size = blobSize;\n\n // @ts-ignore\n return blob;\n }\n\n /**\n * Returns a promise that resolves with an ArrayBuffer containing the entire\n * contents of the Blob as binary data.\n */\n // eslint-disable-next-line require-await\n async arrayBuffer(): Promise<ArrayBuffer> {\n return this._toArrayBuffer();\n }\n\n /**\n * Returns a promise that resolves with a USVString containing the entire\n * contents of the Blob interpreted as UTF-8 text.\n */\n // eslint-disable-next-line require-await\n async text(): Promise<string> {\n const decoder = new TextDecoder();\n let text = '';\n for (const part of this.parts) {\n text += decoder.decode(part);\n }\n return text;\n }\n\n /**\n */\n // @ts-ignore\n stream(): BlobStream<any> {\n return new BlobStream<any>(this.parts);\n }\n\n /**\n * @returns {string}\n */\n toString() {\n return '[object Blob]';\n }\n\n get [Symbol.toStringTag]() {\n return 'Blob';\n }\n\n _toArrayBuffer(): ArrayBuffer {\n const buffer = new ArrayBuffer(this.size);\n const bytes = new Uint8Array(buffer);\n let offset = 0;\n for (const part of this.parts) {\n bytes.set(part, offset);\n offset += part.byteLength;\n }\n return buffer;\n }\n}\n\n/**\n */\nfunction readType(input: string = ''): string {\n const type = String(input).toLowerCase();\n return /[^\\u0020-\\u007E]/.test(type) ? '' : type;\n}\n"],"file":"blob.js"}
@@ -7,21 +7,12 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.FileReaderPolyfill = void 0;
9
9
 
10
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
-
12
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
-
14
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
15
-
16
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
-
18
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
19
11
 
20
12
  var _btoa = require("../buffer/btoa.node");
21
13
 
22
- var FileReaderPolyfill = function () {
23
- function FileReaderPolyfill() {
24
- (0, _classCallCheck2.default)(this, FileReaderPolyfill);
14
+ class FileReaderPolyfill {
15
+ constructor() {
25
16
  (0, _defineProperty2.default)(this, "onload", void 0);
26
17
  (0, _defineProperty2.default)(this, "onabort", void 0);
27
18
  (0, _defineProperty2.default)(this, "onerror", void 0);
@@ -40,150 +31,52 @@ var FileReaderPolyfill = function () {
40
31
  this.onload = null;
41
32
  }
42
33
 
43
- (0, _createClass2.default)(FileReaderPolyfill, [{
44
- key: "abort",
45
- value: function abort() {
46
- return;
47
- }
48
- }, {
49
- key: "readAsArrayBuffer",
50
- value: function () {
51
- var _readAsArrayBuffer = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(blob) {
52
- var arrayBuffer;
53
- return _regenerator.default.wrap(function _callee$(_context) {
54
- while (1) {
55
- switch (_context.prev = _context.next) {
56
- case 0:
57
- _context.next = 2;
58
- return blob.arrayBuffer();
59
-
60
- case 2:
61
- arrayBuffer = _context.sent;
62
-
63
- if (this.onload) {
64
- this.onload({
65
- target: {
66
- result: arrayBuffer
67
- }
68
- });
69
- }
70
-
71
- case 4:
72
- case "end":
73
- return _context.stop();
74
- }
75
- }
76
- }, _callee, this);
77
- }));
78
-
79
- function readAsArrayBuffer(_x) {
80
- return _readAsArrayBuffer.apply(this, arguments);
81
- }
82
-
83
- return readAsArrayBuffer;
84
- }()
85
- }, {
86
- key: "readAsBinaryString",
87
- value: function () {
88
- var _readAsBinaryString = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(blob) {
89
- return _regenerator.default.wrap(function _callee2$(_context2) {
90
- while (1) {
91
- switch (_context2.prev = _context2.next) {
92
- case 0:
93
- throw Error('Not implemented');
94
-
95
- case 1:
96
- case "end":
97
- return _context2.stop();
98
- }
99
- }
100
- }, _callee2);
101
- }));
102
-
103
- function readAsBinaryString(_x2) {
104
- return _readAsBinaryString.apply(this, arguments);
105
- }
106
-
107
- return readAsBinaryString;
108
- }()
109
- }, {
110
- key: "readAsDataURL",
111
- value: function () {
112
- var _readAsDataURL = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee3(blob) {
113
- var text, dataUrl;
114
- return _regenerator.default.wrap(function _callee3$(_context3) {
115
- while (1) {
116
- switch (_context3.prev = _context3.next) {
117
- case 0:
118
- _context3.next = 2;
119
- return blob.text();
120
-
121
- case 2:
122
- text = _context3.sent;
123
- dataUrl = "data://;base64,".concat((0, _btoa.atob)(text));
124
-
125
- if (this.onload) {
126
- this.onload({
127
- target: {
128
- result: dataUrl
129
- }
130
- });
131
- }
34
+ abort() {
35
+ return;
36
+ }
132
37
 
133
- case 5:
134
- case "end":
135
- return _context3.stop();
136
- }
137
- }
138
- }, _callee3, this);
139
- }));
38
+ async readAsArrayBuffer(blob) {
39
+ const arrayBuffer = await blob.arrayBuffer();
140
40
 
141
- function readAsDataURL(_x3) {
142
- return _readAsDataURL.apply(this, arguments);
143
- }
41
+ if (this.onload) {
42
+ this.onload({
43
+ target: {
44
+ result: arrayBuffer
45
+ }
46
+ });
47
+ }
48
+ }
144
49
 
145
- return readAsDataURL;
146
- }()
147
- }, {
148
- key: "readAsText",
149
- value: function () {
150
- var _readAsText = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee4(blob) {
151
- var text;
152
- return _regenerator.default.wrap(function _callee4$(_context4) {
153
- while (1) {
154
- switch (_context4.prev = _context4.next) {
155
- case 0:
156
- _context4.next = 2;
157
- return blob.text();
50
+ async readAsBinaryString(blob) {
51
+ throw Error('Not implemented');
52
+ }
158
53
 
159
- case 2:
160
- text = _context4.sent;
54
+ async readAsDataURL(blob) {
55
+ const text = await blob.text();
56
+ const dataUrl = "data://;base64,".concat((0, _btoa.atob)(text));
161
57
 
162
- if (this.onload) {
163
- this.onload({
164
- target: {
165
- result: text
166
- }
167
- });
168
- }
58
+ if (this.onload) {
59
+ this.onload({
60
+ target: {
61
+ result: dataUrl
62
+ }
63
+ });
64
+ }
65
+ }
169
66
 
170
- case 4:
171
- case "end":
172
- return _context4.stop();
173
- }
174
- }
175
- }, _callee4, this);
176
- }));
67
+ async readAsText(blob) {
68
+ const text = await blob.text();
177
69
 
178
- function readAsText(_x4) {
179
- return _readAsText.apply(this, arguments);
180
- }
70
+ if (this.onload) {
71
+ this.onload({
72
+ target: {
73
+ result: text
74
+ }
75
+ });
76
+ }
77
+ }
181
78
 
182
- return readAsText;
183
- }()
184
- }]);
185
- return FileReaderPolyfill;
186
- }();
79
+ }
187
80
 
188
81
  exports.FileReaderPolyfill = FileReaderPolyfill;
189
82
  //# sourceMappingURL=file-reader.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/node/file/file-reader.ts"],"names":["FileReaderPolyfill","onload","blob","arrayBuffer","target","result","Error","text","dataUrl"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;IAEaA,kB;AAmBX,gCAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACZ,SAAKC,MAAL,GAAc,IAAd;AACD;;;;WAED,iBAAc;AACZ;AACD;;;;yFAED,iBAAwBC,IAAxB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAC4BA,IAAI,CAACC,WAAL,EAD5B;;AAAA;AACQA,gBAAAA,WADR;;AAEE,oBAAI,KAAKF,MAAT,EAAiB;AACf,uBAAKA,MAAL,CAAY;AAACG,oBAAAA,MAAM,EAAE;AAACC,sBAAAA,MAAM,EAAEF;AAAT;AAAT,mBAAZ;AACD;;AAJH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O;;;;;;;;;;;0FAOA,kBAAyBD,IAAzB;AAAA;AAAA;AAAA;AAAA;AAAA,sBACQI,KAAK,CAAC,iBAAD,CADb;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O;;;;;;;;;;;qFAIA,kBAAoBJ,IAApB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBACqBA,IAAI,CAACK,IAAL,EADrB;;AAAA;AACQA,gBAAAA,IADR;AAEQC,gBAAAA,OAFR,4BAEoC,gBAAKD,IAAL,CAFpC;;AAGE,oBAAI,KAAKN,MAAT,EAAiB;AACf,uBAAKA,MAAL,CAAY;AAACG,oBAAAA,MAAM,EAAE;AAACC,sBAAAA,MAAM,EAAEG;AAAT;AAAT,mBAAZ;AACD;;AALH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O;;;;;;;;;;;kFAQA,kBAAiBN,IAAjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBACqBA,IAAI,CAACK,IAAL,EADrB;;AAAA;AACQA,gBAAAA,IADR;;AAEE,oBAAI,KAAKN,MAAT,EAAiB;AACf,uBAAKA,MAAL,CAAY;AAACG,oBAAAA,MAAM,EAAE;AAACC,sBAAAA,MAAM,EAAEE;AAAT;AAAT,mBAAZ;AACD;;AAJH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O","sourcesContent":["import {atob} from '../buffer/btoa.node';\n\nexport class FileReaderPolyfill implements FileReader {\n // onload: ({result: any}) => void;\n onload;\n onabort;\n onerror;\n error;\n onloadstart;\n onloadend;\n onprogress;\n\n readyState;\n result;\n DONE;\n EMPTY;\n LOADING;\n addEventListener;\n removeEventListener;\n dispatchEvent;\n\n constructor() {\n this.onload = null;\n }\n\n abort(): void {\n return;\n }\n\n async readAsArrayBuffer(blob: Blob): Promise<void> {\n const arrayBuffer = await blob.arrayBuffer();\n if (this.onload) {\n this.onload({target: {result: arrayBuffer}});\n }\n }\n\n async readAsBinaryString(blob) {\n throw Error('Not implemented');\n }\n\n async readAsDataURL(blob) {\n const text = await blob.text();\n const dataUrl = `data://;base64,${atob(text)}`;\n if (this.onload) {\n this.onload({target: {result: dataUrl}});\n }\n }\n\n async readAsText(blob) {\n const text = await blob.text();\n if (this.onload) {\n this.onload({target: {result: text}});\n }\n }\n}\n"],"file":"file-reader.js"}
1
+ {"version":3,"sources":["../../../../src/node/file/file-reader.ts"],"names":["FileReaderPolyfill","constructor","onload","abort","readAsArrayBuffer","blob","arrayBuffer","target","result","readAsBinaryString","Error","readAsDataURL","text","dataUrl","readAsText"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAMA,kBAAN,CAA+C;AAmBpDC,EAAAA,WAAW,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACZ,SAAKC,MAAL,GAAc,IAAd;AACD;;AAEDC,EAAAA,KAAK,GAAS;AACZ;AACD;;AAEsB,QAAjBC,iBAAiB,CAACC,IAAD,EAA4B;AACjD,UAAMC,WAAW,GAAG,MAAMD,IAAI,CAACC,WAAL,EAA1B;;AACA,QAAI,KAAKJ,MAAT,EAAiB;AACf,WAAKA,MAAL,CAAY;AAACK,QAAAA,MAAM,EAAE;AAACC,UAAAA,MAAM,EAAEF;AAAT;AAAT,OAAZ;AACD;AACF;;AAEuB,QAAlBG,kBAAkB,CAACJ,IAAD,EAAO;AAC7B,UAAMK,KAAK,CAAC,iBAAD,CAAX;AACD;;AAEkB,QAAbC,aAAa,CAACN,IAAD,EAAO;AACxB,UAAMO,IAAI,GAAG,MAAMP,IAAI,CAACO,IAAL,EAAnB;AACA,UAAMC,OAAO,4BAAqB,gBAAKD,IAAL,CAArB,CAAb;;AACA,QAAI,KAAKV,MAAT,EAAiB;AACf,WAAKA,MAAL,CAAY;AAACK,QAAAA,MAAM,EAAE;AAACC,UAAAA,MAAM,EAAEK;AAAT;AAAT,OAAZ;AACD;AACF;;AAEe,QAAVC,UAAU,CAACT,IAAD,EAAO;AACrB,UAAMO,IAAI,GAAG,MAAMP,IAAI,CAACO,IAAL,EAAnB;;AACA,QAAI,KAAKV,MAAT,EAAiB;AACf,WAAKA,MAAL,CAAY;AAACK,QAAAA,MAAM,EAAE;AAACC,UAAAA,MAAM,EAAEI;AAAT;AAAT,OAAZ;AACD;AACF;;AAnDmD","sourcesContent":["import {atob} from '../buffer/btoa.node';\n\nexport class FileReaderPolyfill implements FileReader {\n // onload: ({result: any}) => void;\n onload;\n onabort;\n onerror;\n error;\n onloadstart;\n onloadend;\n onprogress;\n\n readyState;\n result;\n DONE;\n EMPTY;\n LOADING;\n addEventListener;\n removeEventListener;\n dispatchEvent;\n\n constructor() {\n this.onload = null;\n }\n\n abort(): void {\n return;\n }\n\n async readAsArrayBuffer(blob: Blob): Promise<void> {\n const arrayBuffer = await blob.arrayBuffer();\n if (this.onload) {\n this.onload({target: {result: arrayBuffer}});\n }\n }\n\n async readAsBinaryString(blob) {\n throw Error('Not implemented');\n }\n\n async readAsDataURL(blob) {\n const text = await blob.text();\n const dataUrl = `data://;base64,${atob(text)}`;\n if (this.onload) {\n this.onload({target: {result: dataUrl}});\n }\n }\n\n async readAsText(blob) {\n const text = await blob.text();\n if (this.onload) {\n this.onload({target: {result: text}});\n }\n }\n}\n"],"file":"file-reader.js"}
@@ -7,57 +7,29 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.FilePolyfill = void 0;
9
9
 
10
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
-
12
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
-
14
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
15
-
16
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
17
-
18
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
19
-
20
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
21
-
22
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
23
11
 
24
12
  var _blob = require("./blob");
25
13
 
26
- var _Symbol$toStringTag;
27
-
28
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
29
-
30
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
14
+ let _Symbol$toStringTag;
31
15
 
32
16
  _Symbol$toStringTag = Symbol.toStringTag;
33
17
 
34
- var FilePolyfill = function (_BlobPolyfill) {
35
- (0, _inherits2.default)(FilePolyfill, _BlobPolyfill);
36
-
37
- var _super = _createSuper(FilePolyfill);
38
-
39
- function FilePolyfill(init, name) {
40
- var _this;
18
+ class FilePolyfill extends _blob.BlobPolyfill {
19
+ constructor(init, name, options = {}) {
20
+ super(init, options);
21
+ (0, _defineProperty2.default)(this, "name", '');
22
+ (0, _defineProperty2.default)(this, "webkitRelativePath", '');
23
+ (0, _defineProperty2.default)(this, "lastModified", void 0);
24
+ this.name = String(name).replace(/\//g, ':');
25
+ this.lastModified = (options === null || options === void 0 ? void 0 : options.lastModified) || Date.now();
26
+ }
41
27
 
42
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
43
- (0, _classCallCheck2.default)(this, FilePolyfill);
44
- _this = _super.call(this, init, options);
45
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "name", '');
46
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "webkitRelativePath", '');
47
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "lastModified", void 0);
48
- _this.name = String(name).replace(/\//g, ':');
49
- _this.lastModified = (options === null || options === void 0 ? void 0 : options.lastModified) || Date.now();
50
- return _this;
28
+ get [_Symbol$toStringTag]() {
29
+ return 'File';
51
30
  }
52
31
 
53
- (0, _createClass2.default)(FilePolyfill, [{
54
- key: _Symbol$toStringTag,
55
- get: function get() {
56
- return 'File';
57
- }
58
- }]);
59
- return FilePolyfill;
60
- }(_blob.BlobPolyfill);
32
+ }
61
33
 
62
34
  exports.FilePolyfill = FilePolyfill;
63
35
  //# sourceMappingURL=file.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/node/file/file.ts"],"names":["Symbol","toStringTag","FilePolyfill","init","name","options","String","replace","lastModified","Date","now","BlobPolyfill"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA;;;;;;;;sBAqCOA,MAAM,CAACC,W;;IA9BDC,Y;;;;;AAoBX,wBAAYC,IAAZ,EAA8BC,IAA9B,EAA2E;AAAA;;AAAA,QAA/BC,OAA+B,uEAAJ,EAAI;AAAA;AACzE,8BAAMF,IAAN,EAAYE,OAAZ;AADyE,uFAhB5D,EAgB4D;AAAA,qGAd9C,EAc8C;AAAA;AAKzE,UAAKD,IAAL,GAAYE,MAAM,CAACF,IAAD,CAAN,CAAaG,OAAb,CAAqB,KAArB,EAA4B,GAA5B,CAAZ;AAEA,UAAKC,YAAL,GAAoB,CAAAH,OAAO,SAAP,IAAAA,OAAO,WAAP,YAAAA,OAAO,CAAEG,YAAT,KAAyBC,IAAI,CAACC,GAAL,EAA7C;AAPyE;AAQ1E;;;;SAED,eAA2B;AACzB,aAAO,MAAP;AACD;;;EAhC+BC,kB","sourcesContent":["// Forked from @gozala's web-file under MIT license https://github.com/Gozala/web-file\nimport {BlobPolyfill} from './blob';\n\n/**\n * Forked from @gozala's web-file under MIT license\n * @see https://github.com/Gozala/web-file\n */\n// @ts-ignore\nexport class FilePolyfill extends BlobPolyfill {\n // implements File {\n // public API\n /** The name of the file referenced by the File object. */\n name: string = '';\n /** The path the URL of the File is relative to. */\n webkitRelativePath: string = '';\n\n /**\n * Returns the last modified time of the file, in millisecond since the UNIX\n * epoch (January 1st, 1970 at Midnight).\n */\n lastModified: number;\n\n /**\n * @param init\n * @param name - A USVString representing the file name or the path\n * to the file.\n * @param [options]\n */\n constructor(init: BlobPart[], name: string, options: FilePropertyBag = {}) {\n super(init, options);\n // Per File API spec https://w3c.github.io/FileAPI/#file-constructor\n // Every \"/\" character of file name must be replaced with a \":\".\n /** @private */\n this.name = String(name).replace(/\\//g, ':');\n /** @private */\n this.lastModified = options?.lastModified || Date.now();\n }\n\n get [Symbol.toStringTag]() {\n return 'File';\n }\n}\n"],"file":"file.js"}
1
+ {"version":3,"sources":["../../../../src/node/file/file.ts"],"names":["Symbol","toStringTag","FilePolyfill","BlobPolyfill","constructor","init","name","options","String","replace","lastModified","Date","now"],"mappings":";;;;;;;;;;;AACA;;;;sBAqCOA,MAAM,CAACC,W;;AA9BP,MAAMC,YAAN,SAA2BC,kBAA3B,CAAwC;AAoB7CC,EAAAA,WAAW,CAACC,IAAD,EAAmBC,IAAnB,EAAiCC,OAAwB,GAAG,EAA5D,EAAgE;AACzE,UAAMF,IAAN,EAAYE,OAAZ;AADyE,gDAhB5D,EAgB4D;AAAA,8DAd9C,EAc8C;AAAA;AAKzE,SAAKD,IAAL,GAAYE,MAAM,CAACF,IAAD,CAAN,CAAaG,OAAb,CAAqB,KAArB,EAA4B,GAA5B,CAAZ;AAEA,SAAKC,YAAL,GAAoB,CAAAH,OAAO,SAAP,IAAAA,OAAO,WAAP,YAAAA,OAAO,CAAEG,YAAT,KAAyBC,IAAI,CAACC,GAAL,EAA7C;AACD;;AAED,8BAA2B;AACzB,WAAO,MAAP;AACD;;AAhC4C","sourcesContent":["// Forked from @gozala's web-file under MIT license https://github.com/Gozala/web-file\nimport {BlobPolyfill} from './blob';\n\n/**\n * Forked from @gozala's web-file under MIT license\n * @see https://github.com/Gozala/web-file\n */\n// @ts-ignore\nexport class FilePolyfill extends BlobPolyfill {\n // implements File {\n // public API\n /** The name of the file referenced by the File object. */\n name: string = '';\n /** The path the URL of the File is relative to. */\n webkitRelativePath: string = '';\n\n /**\n * Returns the last modified time of the file, in millisecond since the UNIX\n * epoch (January 1st, 1970 at Midnight).\n */\n lastModified: number;\n\n /**\n * @param init\n * @param name - A USVString representing the file name or the path\n * to the file.\n * @param [options]\n */\n constructor(init: BlobPart[], name: string, options: FilePropertyBag = {}) {\n super(init, options);\n // Per File API spec https://w3c.github.io/FileAPI/#file-constructor\n // Every \"/\" character of file name must be replaced with a \":\".\n /** @private */\n this.name = String(name).replace(/\\//g, ':');\n /** @private */\n this.lastModified = options?.lastModified || Date.now();\n }\n\n get [Symbol.toStringTag]() {\n return 'File';\n }\n}\n"],"file":"file.js"}
@@ -1,40 +1,15 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports.ReadableStreamPolyfill = void 0;
9
7
 
10
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
-
12
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
13
-
14
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
15
-
16
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
17
-
18
8
  var _webStreamsPolyfill = require("web-streams-polyfill");
19
9
 
20
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
21
-
22
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
23
-
24
10
  delete global.ReadableStream;
25
11
 
26
- var ReadableStreamPolyfill = function (_WSPReadableStream) {
27
- (0, _inherits2.default)(ReadableStreamPolyfill, _WSPReadableStream);
28
-
29
- var _super = _createSuper(ReadableStreamPolyfill);
30
-
31
- function ReadableStreamPolyfill() {
32
- (0, _classCallCheck2.default)(this, ReadableStreamPolyfill);
33
- return _super.apply(this, arguments);
34
- }
35
-
36
- return ReadableStreamPolyfill;
37
- }(_webStreamsPolyfill.ReadableStream);
12
+ class ReadableStreamPolyfill extends _webStreamsPolyfill.ReadableStream {}
38
13
 
39
14
  exports.ReadableStreamPolyfill = ReadableStreamPolyfill;
40
15
  //# sourceMappingURL=readable-stream.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/node/file/readable-stream.ts"],"names":["global","ReadableStream","ReadableStreamPolyfill","WSPReadableStream"],"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;AAIA,OAAOA,MAAM,CAACC,cAAd;;IAGaC,sB;;;;;;;;;;;EAAkCC,kC","sourcesContent":["import {ReadableStream as WSPReadableStream} from 'web-streams-polyfill';\n\n// Want a polyfill, but please don't install it\n// @ts-ignore\ndelete global.ReadableStream;\n\n// @ts-ignore\nexport class ReadableStreamPolyfill<T> extends WSPReadableStream<T> implements ReadableStream {}\n"],"file":"readable-stream.js"}
1
+ {"version":3,"sources":["../../../../src/node/file/readable-stream.ts"],"names":["global","ReadableStream","ReadableStreamPolyfill","WSPReadableStream"],"mappings":";;;;;;;AAAA;;AAIA,OAAOA,MAAM,CAACC,cAAd;;AAGO,MAAMC,sBAAN,SAAwCC,kCAAxC,CAAuF","sourcesContent":["import {ReadableStream as WSPReadableStream} from 'web-streams-polyfill';\n\n// Want a polyfill, but please don't install it\n// @ts-ignore\ndelete global.ReadableStream;\n\n// @ts-ignore\nexport class ReadableStreamPolyfill<T> extends WSPReadableStream<T> implements ReadableStream {}\n"],"file":"readable-stream.js"}
@@ -15,20 +15,18 @@ var _ndarray = _interopRequireDefault(require("ndarray"));
15
15
  var _toArrayBuffer = require("../buffer/to-array-buffer.node");
16
16
 
17
17
  function encodeImageToStreamNode(image, options) {
18
- var type = options.type ? options.type.replace('image/', '') : 'jpeg';
19
- var pixels = (0, _ndarray.default)(image.data, [image.width, image.height, 4], [4, image.width * 4, 1], 0);
18
+ const type = options.type ? options.type.replace('image/', '') : 'jpeg';
19
+ const pixels = (0, _ndarray.default)(image.data, [image.width, image.height, 4], [4, image.width * 4, 1], 0);
20
20
  return (0, _savePixels.default)(pixels, type, options);
21
21
  }
22
22
 
23
23
  function encodeImageNode(image, options) {
24
- var imageStream = encodeImageToStreamNode(image, options);
25
- return new Promise(function (resolve) {
26
- var buffers = [];
27
- imageStream.on('data', function (buffer) {
28
- return buffers.push(buffer);
29
- });
30
- imageStream.on('end', function () {
31
- var buffer = Buffer.concat(buffers);
24
+ const imageStream = encodeImageToStreamNode(image, options);
25
+ return new Promise(resolve => {
26
+ const buffers = [];
27
+ imageStream.on('data', buffer => buffers.push(buffer));
28
+ imageStream.on('end', () => {
29
+ const buffer = Buffer.concat(buffers);
32
30
  resolve((0, _toArrayBuffer.bufferToArrayBuffer)(buffer));
33
31
  });
34
32
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/node/images/encode-image.node.ts"],"names":["encodeImageToStreamNode","image","options","type","replace","pixels","data","width","height","encodeImageNode","imageStream","Promise","resolve","buffers","on","buffer","push","Buffer","concat"],"mappings":";;;;;;;;;;AAEA;;AACA;;AACA;;AAYO,SAASA,uBAAT,CACLC,KADK,EAELC,OAFK,EAGL;AAEA,MAAMC,IAAI,GAAGD,OAAO,CAACC,IAAR,GAAeD,OAAO,CAACC,IAAR,CAAaC,OAAb,CAAqB,QAArB,EAA+B,EAA/B,CAAf,GAAoD,MAAjE;AACA,MAAMC,MAAM,GAAG,sBAAQJ,KAAK,CAACK,IAAd,EAAoB,CAACL,KAAK,CAACM,KAAP,EAAcN,KAAK,CAACO,MAApB,EAA4B,CAA5B,CAApB,EAAoD,CAAC,CAAD,EAAIP,KAAK,CAACM,KAAN,GAAc,CAAlB,EAAqB,CAArB,CAApD,EAA6E,CAA7E,CAAf;AAGA,SAAO,yBAAWF,MAAX,EAAmBF,IAAnB,EAAyBD,OAAzB,CAAP;AACD;;AAEM,SAASO,eAAT,CAAyBR,KAAzB,EAAgCC,OAAhC,EAAyC;AAC9C,MAAMQ,WAAW,GAAGV,uBAAuB,CAACC,KAAD,EAAQC,OAAR,CAA3C;AAEA,SAAO,IAAIS,OAAJ,CAAY,UAACC,OAAD,EAAa;AAC9B,QAAMC,OAAc,GAAG,EAAvB;AACAH,IAAAA,WAAW,CAACI,EAAZ,CAAe,MAAf,EAAuB,UAACC,MAAD;AAAA,aAAYF,OAAO,CAACG,IAAR,CAAaD,MAAb,CAAZ;AAAA,KAAvB;AAEAL,IAAAA,WAAW,CAACI,EAAZ,CAAe,KAAf,EAAsB,YAAM;AAC1B,UAAMC,MAAM,GAAGE,MAAM,CAACC,MAAP,CAAcL,OAAd,CAAf;AACAD,MAAAA,OAAO,CAAC,wCAAoBG,MAApB,CAAD,CAAP;AACD,KAHD;AAID,GARM,CAAP;AASD","sourcesContent":["// Use stackgl modules for DOM-less reading and writing of images\n\nimport savePixels from 'save-pixels';\nimport ndarray from 'ndarray';\nimport {bufferToArrayBuffer} from '../buffer/to-array-buffer.node';\n\n/**\n * Returns data bytes representing a compressed image in PNG or JPG format,\n * This data can be saved using file system (f) methods or\n * used in a request.\n * @param image to save\n * @param options\n * @param options.type='png' - png, jpg or image/png, image/jpg are valid\n * @param options.dataURI - Whether to include a data URI header\n * @return {*} bytes\n */\nexport function encodeImageToStreamNode(\n image: {data: any; width: number; height: number},\n options: {type?: string; dataURI?: string}\n) {\n // Support MIME type strings\n const type = options.type ? options.type.replace('image/', '') : 'jpeg';\n const pixels = ndarray(image.data, [image.width, image.height, 4], [4, image.width * 4, 1], 0);\n\n // Note: savePixels returns a stream\n return savePixels(pixels, type, options);\n}\n\nexport function encodeImageNode(image, options) {\n const imageStream = encodeImageToStreamNode(image, options);\n\n return new Promise((resolve) => {\n const buffers: any[] = [];\n imageStream.on('data', (buffer) => buffers.push(buffer));\n // TODO - convert to arraybuffer?\n imageStream.on('end', () => {\n const buffer = Buffer.concat(buffers);\n resolve(bufferToArrayBuffer(buffer));\n });\n });\n}\n"],"file":"encode-image.node.js"}
1
+ {"version":3,"sources":["../../../../src/node/images/encode-image.node.ts"],"names":["encodeImageToStreamNode","image","options","type","replace","pixels","data","width","height","encodeImageNode","imageStream","Promise","resolve","buffers","on","buffer","push","Buffer","concat"],"mappings":";;;;;;;;;;AAEA;;AACA;;AACA;;AAYO,SAASA,uBAAT,CACLC,KADK,EAELC,OAFK,EAGL;AAEA,QAAMC,IAAI,GAAGD,OAAO,CAACC,IAAR,GAAeD,OAAO,CAACC,IAAR,CAAaC,OAAb,CAAqB,QAArB,EAA+B,EAA/B,CAAf,GAAoD,MAAjE;AACA,QAAMC,MAAM,GAAG,sBAAQJ,KAAK,CAACK,IAAd,EAAoB,CAACL,KAAK,CAACM,KAAP,EAAcN,KAAK,CAACO,MAApB,EAA4B,CAA5B,CAApB,EAAoD,CAAC,CAAD,EAAIP,KAAK,CAACM,KAAN,GAAc,CAAlB,EAAqB,CAArB,CAApD,EAA6E,CAA7E,CAAf;AAGA,SAAO,yBAAWF,MAAX,EAAmBF,IAAnB,EAAyBD,OAAzB,CAAP;AACD;;AAEM,SAASO,eAAT,CAAyBR,KAAzB,EAAgCC,OAAhC,EAAyC;AAC9C,QAAMQ,WAAW,GAAGV,uBAAuB,CAACC,KAAD,EAAQC,OAAR,CAA3C;AAEA,SAAO,IAAIS,OAAJ,CAAaC,OAAD,IAAa;AAC9B,UAAMC,OAAc,GAAG,EAAvB;AACAH,IAAAA,WAAW,CAACI,EAAZ,CAAe,MAAf,EAAwBC,MAAD,IAAYF,OAAO,CAACG,IAAR,CAAaD,MAAb,CAAnC;AAEAL,IAAAA,WAAW,CAACI,EAAZ,CAAe,KAAf,EAAsB,MAAM;AAC1B,YAAMC,MAAM,GAAGE,MAAM,CAACC,MAAP,CAAcL,OAAd,CAAf;AACAD,MAAAA,OAAO,CAAC,wCAAoBG,MAApB,CAAD,CAAP;AACD,KAHD;AAID,GARM,CAAP;AASD","sourcesContent":["// Use stackgl modules for DOM-less reading and writing of images\n\nimport savePixels from 'save-pixels';\nimport ndarray from 'ndarray';\nimport {bufferToArrayBuffer} from '../buffer/to-array-buffer.node';\n\n/**\n * Returns data bytes representing a compressed image in PNG or JPG format,\n * This data can be saved using file system (f) methods or\n * used in a request.\n * @param image to save\n * @param options\n * @param options.type='png' - png, jpg or image/png, image/jpg are valid\n * @param options.dataURI - Whether to include a data URI header\n * @return {*} bytes\n */\nexport function encodeImageToStreamNode(\n image: {data: any; width: number; height: number},\n options: {type?: string; dataURI?: string}\n) {\n // Support MIME type strings\n const type = options.type ? options.type.replace('image/', '') : 'jpeg';\n const pixels = ndarray(image.data, [image.width, image.height, 4], [4, image.width * 4, 1], 0);\n\n // Note: savePixels returns a stream\n return savePixels(pixels, type, options);\n}\n\nexport function encodeImageNode(image, options) {\n const imageStream = encodeImageToStreamNode(image, options);\n\n return new Promise((resolve) => {\n const buffers: any[] = [];\n imageStream.on('data', (buffer) => buffers.push(buffer));\n // TODO - convert to arraybuffer?\n imageStream.on('end', () => {\n const buffer = Buffer.concat(buffers);\n resolve(bufferToArrayBuffer(buffer));\n });\n });\n}\n"],"file":"encode-image.node.js"}
@@ -7,55 +7,28 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.parseImageNode = parseImageNode;
9
9
 
10
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
-
12
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
-
14
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
15
-
16
10
  var _getPixels = _interopRequireDefault(require("get-pixels"));
17
11
 
18
12
  var _assert = require("../../utils/assert");
19
13
 
20
14
  var _util = _interopRequireDefault(require("util"));
21
15
 
22
- function parseImageNode(_x, _x2) {
23
- return _parseImageNode.apply(this, arguments);
24
- }
25
-
26
- function _parseImageNode() {
27
- _parseImageNode = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(arrayBuffer, mimeType) {
28
- var getPixelsAsync, buffer, ndarray, shape, layers;
29
- return _regenerator.default.wrap(function _callee$(_context) {
30
- while (1) {
31
- switch (_context.prev = _context.next) {
32
- case 0:
33
- (0, _assert.assert)(mimeType, 'MIMEType is required to parse image under Node.js');
34
- getPixelsAsync = _util.default.promisify(_getPixels.default);
35
- buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);
36
- _context.next = 5;
37
- return getPixelsAsync(buffer, mimeType);
38
-
39
- case 5:
40
- ndarray = _context.sent;
41
- shape = (0, _toConsumableArray2.default)(ndarray.shape);
42
- layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;
43
- return _context.abrupt("return", {
44
- shape: shape,
45
- data: ndarray.data,
46
- width: ndarray.shape[0],
47
- height: ndarray.shape[1],
48
- components: ndarray.shape[2],
49
- layers: layers
50
- });
51
-
52
- case 9:
53
- case "end":
54
- return _context.stop();
55
- }
56
- }
57
- }, _callee);
58
- }));
59
- return _parseImageNode.apply(this, arguments);
16
+ async function parseImageNode(arrayBuffer, mimeType) {
17
+ (0, _assert.assert)(mimeType, 'MIMEType is required to parse image under Node.js');
18
+
19
+ const getPixelsAsync = _util.default.promisify(_getPixels.default);
20
+
21
+ const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);
22
+ const ndarray = await getPixelsAsync(buffer, mimeType);
23
+ const shape = [...ndarray.shape];
24
+ const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;
25
+ return {
26
+ shape,
27
+ data: ndarray.data,
28
+ width: ndarray.shape[0],
29
+ height: ndarray.shape[1],
30
+ components: ndarray.shape[2],
31
+ layers
32
+ };
60
33
  }
61
34
  //# sourceMappingURL=parse-image.node.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/node/images/parse-image.node.ts"],"names":["parseImageNode","arrayBuffer","mimeType","getPixelsAsync","util","promisify","getPixels","buffer","Buffer","from","ndarray","shape","layers","length","shift","data","width","height","components"],"mappings":";;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;SAYsBA,c;;;;;8EAAf,iBAA8BC,WAA9B,EAAwDC,QAAxD;AAAA;AAAA;AAAA;AAAA;AAAA;AACL,gCAAOA,QAAP,EAAiB,mDAAjB;AAIMC,YAAAA,cALD,GAKkBC,cAAKC,SAAL,CAAeC,kBAAf,CALlB;AAOCC,YAAAA,MAPD,GAOUN,WAAW,YAAYO,MAAvB,GAAgCP,WAAhC,GAA8CO,MAAM,CAACC,IAAP,CAAYR,WAAZ,CAPxD;AAAA;AAAA,mBASiBE,cAAc,CAACI,MAAD,EAASL,QAAT,CAT/B;;AAAA;AASCQ,YAAAA,OATD;AAWCC,YAAAA,KAXD,oCAWaD,OAAO,CAACC,KAXrB;AAYCC,YAAAA,MAZD,GAYUF,OAAO,CAACC,KAAR,CAAcE,MAAd,KAAyB,CAAzB,GAA6BH,OAAO,CAACC,KAAR,CAAcG,KAAd,EAA7B,GAAqD,CAZ/D;AAAA,6CAeE;AACLH,cAAAA,KAAK,EAALA,KADK;AAELI,cAAAA,IAAI,EAAEL,OAAO,CAACK,IAFT;AAGLC,cAAAA,KAAK,EAAEN,OAAO,CAACC,KAAR,CAAc,CAAd,CAHF;AAILM,cAAAA,MAAM,EAAEP,OAAO,CAACC,KAAR,CAAc,CAAd,CAJH;AAKLO,cAAAA,UAAU,EAAER,OAAO,CAACC,KAAR,CAAc,CAAd,CALP;AAMLC,cAAAA,MAAM,EAANA;AANK,aAfF;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,G","sourcesContent":["import getPixels from 'get-pixels';\nimport {assert} from '../../utils/assert';\nimport util from 'util';\n\n// Note: These types are also defined in @loaders.gl/images and need to be kept in sync\ntype NDArray = {\n shape: number[];\n data: Uint8Array;\n width: number;\n height: number;\n components: number;\n layers: number[];\n};\n\nexport async function parseImageNode(arrayBuffer: ArrayBuffer, mimeType: string): Promise<NDArray> {\n assert(mimeType, 'MIMEType is required to parse image under Node.js');\n\n // TODO - check if getPixels callback is asynchronous if provided with buffer input\n // if not, parseImage can be a sync function\n const getPixelsAsync = util.promisify(getPixels);\n\n const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);\n\n const ndarray = await getPixelsAsync(buffer, mimeType);\n\n const shape = [...ndarray.shape];\n const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;\n\n // extract width/height etc\n return {\n shape,\n data: ndarray.data,\n width: ndarray.shape[0],\n height: ndarray.shape[1],\n components: ndarray.shape[2],\n layers\n };\n}\n"],"file":"parse-image.node.js"}
1
+ {"version":3,"sources":["../../../../src/node/images/parse-image.node.ts"],"names":["parseImageNode","arrayBuffer","mimeType","getPixelsAsync","util","promisify","getPixels","buffer","Buffer","from","ndarray","shape","layers","length","shift","data","width","height","components"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAYO,eAAeA,cAAf,CAA8BC,WAA9B,EAAwDC,QAAxD,EAA4F;AACjG,sBAAOA,QAAP,EAAiB,mDAAjB;;AAIA,QAAMC,cAAc,GAAGC,cAAKC,SAAL,CAAeC,kBAAf,CAAvB;;AAEA,QAAMC,MAAM,GAAGN,WAAW,YAAYO,MAAvB,GAAgCP,WAAhC,GAA8CO,MAAM,CAACC,IAAP,CAAYR,WAAZ,CAA7D;AAEA,QAAMS,OAAO,GAAG,MAAMP,cAAc,CAACI,MAAD,EAASL,QAAT,CAApC;AAEA,QAAMS,KAAK,GAAG,CAAC,GAAGD,OAAO,CAACC,KAAZ,CAAd;AACA,QAAMC,MAAM,GAAGF,OAAO,CAACC,KAAR,CAAcE,MAAd,KAAyB,CAAzB,GAA6BH,OAAO,CAACC,KAAR,CAAcG,KAAd,EAA7B,GAAqD,CAApE;AAGA,SAAO;AACLH,IAAAA,KADK;AAELI,IAAAA,IAAI,EAAEL,OAAO,CAACK,IAFT;AAGLC,IAAAA,KAAK,EAAEN,OAAO,CAACC,KAAR,CAAc,CAAd,CAHF;AAILM,IAAAA,MAAM,EAAEP,OAAO,CAACC,KAAR,CAAc,CAAd,CAJH;AAKLO,IAAAA,UAAU,EAAER,OAAO,CAACC,KAAR,CAAc,CAAd,CALP;AAMLC,IAAAA;AANK,GAAP;AAQD","sourcesContent":["import getPixels from 'get-pixels';\nimport {assert} from '../../utils/assert';\nimport util from 'util';\n\n// Note: These types are also defined in @loaders.gl/images and need to be kept in sync\ntype NDArray = {\n shape: number[];\n data: Uint8Array;\n width: number;\n height: number;\n components: number;\n layers: number[];\n};\n\nexport async function parseImageNode(arrayBuffer: ArrayBuffer, mimeType: string): Promise<NDArray> {\n assert(mimeType, 'MIMEType is required to parse image under Node.js');\n\n // TODO - check if getPixels callback is asynchronous if provided with buffer input\n // if not, parseImage can be a sync function\n const getPixelsAsync = util.promisify(getPixels);\n\n const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);\n\n const ndarray = await getPixelsAsync(buffer, mimeType);\n\n const shape = [...ndarray.shape];\n const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;\n\n // extract width/height etc\n return {\n shape,\n data: ndarray.data,\n width: ndarray.shape[0],\n height: ndarray.shape[1],\n components: ndarray.shape[2],\n layers\n };\n}\n"],"file":"parse-image.node.js"}
@@ -5,22 +5,22 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.allSettled = allSettled;
7
7
  exports.FULFILLED_STATUS = exports.REJECTED_STATUS = void 0;
8
- var REJECTED_STATUS = 'rejected';
8
+ const REJECTED_STATUS = 'rejected';
9
9
  exports.REJECTED_STATUS = REJECTED_STATUS;
10
- var FULFILLED_STATUS = 'fulfilled';
10
+ const FULFILLED_STATUS = 'fulfilled';
11
11
  exports.FULFILLED_STATUS = FULFILLED_STATUS;
12
12
 
13
13
  function allSettled(promises) {
14
- var mappedPromises = promises.map(function (promise) {
15
- return promise.then(function (value) {
14
+ const mappedPromises = promises.map(promise => {
15
+ return promise.then(value => {
16
16
  return {
17
17
  status: FULFILLED_STATUS,
18
- value: value
18
+ value
19
19
  };
20
- }).catch(function (reason) {
20
+ }).catch(reason => {
21
21
  return {
22
22
  status: REJECTED_STATUS,
23
- reason: reason
23
+ reason
24
24
  };
25
25
  });
26
26
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/promise/all-settled.ts"],"names":["REJECTED_STATUS","FULFILLED_STATUS","allSettled","promises","mappedPromises","map","promise","then","value","status","catch","reason","Promise","all"],"mappings":";;;;;;;AAAO,IAAMA,eAAe,GAAG,UAAxB;;AACA,IAAMC,gBAAgB,GAAG,WAAzB;;;AAQA,SAASC,UAAT,CAAoBC,QAApB,EAA4D;AACjE,MAAMC,cAAc,GAAGD,QAAQ,CAACE,GAAT,CAAa,UAACC,OAAD,EAAa;AAC/C,WAAOA,OAAO,CACXC,IADI,CACC,UAACC,KAAD,EAAW;AACf,aAAO;AAACC,QAAAA,MAAM,EAAER,gBAAT;AAA2BO,QAAAA,KAAK,EAALA;AAA3B,OAAP;AACD,KAHI,EAIJE,KAJI,CAIE,UAACC,MAAD,EAAY;AACjB,aAAO;AAACF,QAAAA,MAAM,EAAET,eAAT;AAA0BW,QAAAA,MAAM,EAANA;AAA1B,OAAP;AACD,KANI,CAAP;AAOD,GARsB,CAAvB;AASA,SAAOC,OAAO,CAACC,GAAR,CAAYT,cAAZ,CAAP;AACD","sourcesContent":["export const REJECTED_STATUS = 'rejected';\nexport const FULFILLED_STATUS = 'fulfilled';\n\n/**\n * Handle list of promises and return all values regardless of results.\n * Polyfill for Promise.allSettled() method.\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled\n * @param promises\n */\nexport function allSettled(promises: Promise<any>[]): Promise<any> {\n const mappedPromises = promises.map((promise) => {\n return promise\n .then((value) => {\n return {status: FULFILLED_STATUS, value};\n })\n .catch((reason) => {\n return {status: REJECTED_STATUS, reason};\n });\n });\n return Promise.all(mappedPromises);\n}\n"],"file":"all-settled.js"}
1
+ {"version":3,"sources":["../../../src/promise/all-settled.ts"],"names":["REJECTED_STATUS","FULFILLED_STATUS","allSettled","promises","mappedPromises","map","promise","then","value","status","catch","reason","Promise","all"],"mappings":";;;;;;;AAAO,MAAMA,eAAe,GAAG,UAAxB;;AACA,MAAMC,gBAAgB,GAAG,WAAzB;;;AAQA,SAASC,UAAT,CAAoBC,QAApB,EAA4D;AACjE,QAAMC,cAAc,GAAGD,QAAQ,CAACE,GAAT,CAAcC,OAAD,IAAa;AAC/C,WAAOA,OAAO,CACXC,IADI,CACEC,KAAD,IAAW;AACf,aAAO;AAACC,QAAAA,MAAM,EAAER,gBAAT;AAA2BO,QAAAA;AAA3B,OAAP;AACD,KAHI,EAIJE,KAJI,CAIGC,MAAD,IAAY;AACjB,aAAO;AAACF,QAAAA,MAAM,EAAET,eAAT;AAA0BW,QAAAA;AAA1B,OAAP;AACD,KANI,CAAP;AAOD,GARsB,CAAvB;AASA,SAAOC,OAAO,CAACC,GAAR,CAAYT,cAAZ,CAAP;AACD","sourcesContent":["export const REJECTED_STATUS = 'rejected';\nexport const FULFILLED_STATUS = 'fulfilled';\n\n/**\n * Handle list of promises and return all values regardless of results.\n * Polyfill for Promise.allSettled() method.\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled\n * @param promises\n */\nexport function allSettled(promises: Promise<any>[]): Promise<any> {\n const mappedPromises = promises.map((promise) => {\n return promise\n .then((value) => {\n return {status: FULFILLED_STATUS, value};\n })\n .catch((reason) => {\n return {status: REJECTED_STATUS, reason};\n });\n });\n return Promise.all(mappedPromises);\n}\n"],"file":"all-settled.js"}
@@ -1,21 +1,16 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports.global = exports.isBrowser = void 0;
9
-
10
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
11
-
12
- var isBrowser = (typeof process === "undefined" ? "undefined" : (0, _typeof2.default)(process)) !== 'object' || String(process) !== '[object process]' || process.browser;
7
+ const isBrowser = typeof process !== 'object' || String(process) !== '[object process]' || process.browser;
13
8
  exports.isBrowser = isBrowser;
14
- var globals = {
9
+ const globals = {
15
10
  self: typeof self !== 'undefined' && self,
16
11
  window: typeof window !== 'undefined' && window,
17
12
  global: typeof global !== 'undefined' && global
18
13
  };
19
- var global_ = globals.global || globals.self || globals.window;
14
+ const global_ = globals.global || globals.self || globals.window;
20
15
  exports.global = global_;
21
16
  //# sourceMappingURL=globals.js.map