@loaders.gl/polyfills 4.0.0-alpha.5 → 4.0.0-alpha.6

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 (170) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/dist.min.js +268 -55
  3. package/dist/es5/bundle.js +6 -0
  4. package/dist/es5/bundle.js.map +1 -0
  5. package/dist/es5/index.js +103 -0
  6. package/dist/es5/index.js.map +1 -0
  7. package/dist/es5/lib/encoding-indexes.js +37 -0
  8. package/dist/es5/lib/encoding-indexes.js.map +1 -0
  9. package/dist/es5/lib/encoding.js +1214 -0
  10. package/dist/es5/lib/encoding.js.map +1 -0
  11. package/dist/es5/libs/encoding-indexes-asian.js +13 -0
  12. package/dist/es5/node/buffer/btoa.node.js +14 -0
  13. package/dist/es5/node/buffer/btoa.node.js.map +1 -0
  14. package/dist/es5/node/buffer/to-array-buffer.node.js +14 -0
  15. package/dist/es5/node/buffer/to-array-buffer.node.js.map +1 -0
  16. package/dist/es5/node/fetch/fetch-file.node.js +83 -0
  17. package/dist/es5/node/fetch/fetch-file.node.js.map +1 -0
  18. package/dist/es5/node/fetch/fetch.node.js +194 -0
  19. package/dist/es5/node/fetch/fetch.node.js.map +1 -0
  20. package/dist/es5/node/fetch/headers.node.js +151 -0
  21. package/dist/es5/node/fetch/headers.node.js.map +1 -0
  22. package/dist/es5/node/fetch/response.node.js +182 -0
  23. package/dist/es5/node/fetch/response.node.js.map +1 -0
  24. package/dist/es5/node/fetch/utils/decode-data-uri.node.js +58 -0
  25. package/dist/es5/node/fetch/utils/decode-data-uri.node.js.map +1 -0
  26. package/dist/es5/node/fetch/utils/stream-utils.node.js +92 -0
  27. package/dist/es5/node/fetch/utils/stream-utils.node.js.map +1 -0
  28. package/dist/es5/node/file/blob-stream-controller.js +90 -0
  29. package/dist/es5/node/file/blob-stream-controller.js.map +1 -0
  30. package/dist/es5/node/file/blob-stream.js +64 -0
  31. package/dist/es5/node/file/blob-stream.js.map +1 -0
  32. package/dist/es5/node/file/blob.js +212 -0
  33. package/dist/es5/node/file/blob.js.map +1 -0
  34. package/dist/es5/node/file/file-reader.js +153 -0
  35. package/dist/es5/node/file/file-reader.js.map +1 -0
  36. package/dist/es5/node/file/file.js +44 -0
  37. package/dist/es5/node/file/file.js.map +1 -0
  38. package/dist/es5/node/file/install-file-polyfills.js +25 -0
  39. package/dist/es5/node/file/install-file-polyfills.js.map +1 -0
  40. package/dist/es5/node/file/readable-stream.js +27 -0
  41. package/dist/es5/node/file/readable-stream.js.map +1 -0
  42. package/dist/es5/node/images/encode-image.node.js +30 -0
  43. package/dist/es5/node/images/encode-image.node.js.map +1 -0
  44. package/dist/es5/node/images/parse-image.node.js +64 -0
  45. package/dist/es5/node/images/parse-image.node.js.map +1 -0
  46. package/dist/es5/promise/all-settled.js +28 -0
  47. package/dist/es5/promise/all-settled.js.map +1 -0
  48. package/dist/es5/utils/assert.js +12 -0
  49. package/dist/es5/utils/assert.js.map +1 -0
  50. package/dist/es5/utils/globals.js +18 -0
  51. package/dist/es5/utils/globals.js.map +1 -0
  52. package/dist/esm/bundle.js +4 -0
  53. package/dist/esm/bundle.js.map +1 -0
  54. package/dist/esm/index.js +54 -0
  55. package/dist/esm/index.js.map +1 -0
  56. package/dist/esm/lib/encoding-indexes.js +30 -0
  57. package/dist/esm/lib/encoding-indexes.js.map +1 -0
  58. package/dist/esm/lib/encoding.js +1206 -0
  59. package/dist/esm/lib/encoding.js.map +1 -0
  60. package/dist/esm/libs/encoding-indexes-asian.js +13 -0
  61. package/dist/esm/node/buffer/btoa.node.js +7 -0
  62. package/dist/esm/node/buffer/btoa.node.js.map +1 -0
  63. package/dist/esm/node/buffer/to-array-buffer.node.js +8 -0
  64. package/dist/esm/node/buffer/to-array-buffer.node.js.map +1 -0
  65. package/dist/esm/node/fetch/fetch-file.node.js +50 -0
  66. package/dist/esm/node/fetch/fetch-file.node.js.map +1 -0
  67. package/dist/esm/node/fetch/fetch.node.js +126 -0
  68. package/dist/esm/node/fetch/fetch.node.js.map +1 -0
  69. package/dist/esm/node/fetch/headers.node.js +102 -0
  70. package/dist/esm/node/fetch/headers.node.js.map +1 -0
  71. package/dist/esm/node/fetch/response.node.js +67 -0
  72. package/dist/esm/node/fetch/response.node.js.map +1 -0
  73. package/dist/esm/node/fetch/utils/decode-data-uri.node.js +45 -0
  74. package/dist/esm/node/fetch/utils/decode-data-uri.node.js.map +1 -0
  75. package/dist/esm/node/fetch/utils/stream-utils.node.js +43 -0
  76. package/dist/esm/node/fetch/utils/stream-utils.node.js.map +1 -0
  77. package/dist/esm/node/file/blob-stream-controller.js +44 -0
  78. package/dist/esm/node/file/blob-stream-controller.js.map +1 -0
  79. package/dist/esm/node/file/blob-stream.js +20 -0
  80. package/dist/esm/node/file/blob-stream.js.map +1 -0
  81. package/dist/esm/node/file/blob.js +120 -0
  82. package/dist/esm/node/file/blob.js.map +1 -0
  83. package/dist/esm/node/file/file-reader.js +60 -0
  84. package/dist/esm/node/file/file-reader.js.map +1 -0
  85. package/dist/esm/node/file/file.js +19 -0
  86. package/dist/esm/node/file/file.js.map +1 -0
  87. package/dist/esm/node/file/install-file-polyfills.js +19 -0
  88. package/dist/esm/node/file/install-file-polyfills.js.map +1 -0
  89. package/dist/esm/node/file/readable-stream.js +4 -0
  90. package/dist/esm/node/file/readable-stream.js.map +1 -0
  91. package/dist/esm/node/images/encode-image.node.js +20 -0
  92. package/dist/esm/node/images/encode-image.node.js.map +1 -0
  93. package/dist/esm/node/images/parse-image.node.js +29 -0
  94. package/dist/esm/node/images/parse-image.node.js.map +1 -0
  95. package/dist/esm/promise/all-settled.js +19 -0
  96. package/dist/esm/promise/all-settled.js.map +1 -0
  97. package/dist/esm/utils/assert.js +6 -0
  98. package/dist/esm/utils/assert.js.map +1 -0
  99. package/dist/esm/utils/globals.js +9 -0
  100. package/dist/esm/utils/globals.js.map +1 -0
  101. package/dist/index.d.ts +2 -0
  102. package/dist/index.d.ts.map +1 -1
  103. package/dist/index.js +90 -49
  104. package/dist/lib/encoding-indexes.js +34 -29
  105. package/dist/lib/encoding.js +2610 -1281
  106. package/dist/libs/encoding-indexes-asian.d.ts +1 -1
  107. package/dist/libs/encoding-indexes-asian.js +9 -8
  108. package/dist/node/buffer/btoa.node.js +12 -5
  109. package/dist/node/buffer/to-array-buffer.node.js +11 -8
  110. package/dist/node/fetch/fetch-file.node.d.ts +4 -0
  111. package/dist/node/fetch/fetch-file.node.d.ts.map +1 -0
  112. package/dist/node/fetch/fetch-file.node.js +51 -0
  113. package/dist/node/fetch/fetch.node.d.ts +6 -1
  114. package/dist/node/fetch/fetch.node.d.ts.map +1 -1
  115. package/dist/node/fetch/fetch.node.js +128 -111
  116. package/dist/node/fetch/headers.node.d.ts +1 -1
  117. package/dist/node/fetch/headers.node.d.ts.map +1 -1
  118. package/dist/node/fetch/headers.node.js +95 -114
  119. package/dist/node/fetch/response.node.d.ts +2 -2
  120. package/dist/node/fetch/response.node.d.ts.map +1 -1
  121. package/dist/node/fetch/response.node.js +72 -84
  122. package/dist/node/fetch/utils/decode-data-uri.node.js +63 -53
  123. package/dist/node/fetch/utils/stream-utils.node.d.ts +8 -1
  124. package/dist/node/fetch/utils/stream-utils.node.d.ts.map +1 -1
  125. package/dist/node/fetch/utils/stream-utils.node.js +68 -93
  126. package/dist/node/file/blob-stream-controller.js +59 -52
  127. package/dist/node/file/blob-stream.js +36 -25
  128. package/dist/node/file/blob.js +151 -131
  129. package/dist/node/file/file-reader.js +28 -77
  130. package/dist/node/file/file.js +36 -25
  131. package/dist/node/file/install-file-polyfills.js +26 -21
  132. package/dist/node/file/readable-stream.js +10 -3
  133. package/dist/node/images/encode-image.node.js +38 -17
  134. package/dist/node/images/parse-image.node.d.ts +3 -1
  135. package/dist/node/images/parse-image.node.d.ts.map +1 -1
  136. package/dist/node/images/parse-image.node.js +40 -19
  137. package/dist/promise/all-settled.js +22 -17
  138. package/dist/utils/assert.js +8 -5
  139. package/dist/utils/globals.js +34 -7
  140. package/package.json +5 -4
  141. package/src/index.ts +7 -4
  142. package/src/node/fetch/fetch-file.node.ts +51 -0
  143. package/src/node/fetch/fetch.node.ts +64 -30
  144. package/src/node/fetch/headers.node.ts +1 -1
  145. package/src/node/fetch/response.node.ts +4 -2
  146. package/src/node/fetch/utils/stream-utils.node.ts +10 -58
  147. package/src/node/images/parse-image.node.ts +35 -20
  148. package/dist/bundle.js.map +0 -1
  149. package/dist/index.js.map +0 -1
  150. package/dist/lib/encoding-indexes.js.map +0 -1
  151. package/dist/lib/encoding.js.map +0 -1
  152. package/dist/node/buffer/btoa.node.js.map +0 -1
  153. package/dist/node/buffer/to-array-buffer.node.js.map +0 -1
  154. package/dist/node/fetch/fetch.node.js.map +0 -1
  155. package/dist/node/fetch/headers.node.js.map +0 -1
  156. package/dist/node/fetch/response.node.js.map +0 -1
  157. package/dist/node/fetch/utils/decode-data-uri.node.js.map +0 -1
  158. package/dist/node/fetch/utils/stream-utils.node.js.map +0 -1
  159. package/dist/node/file/blob-stream-controller.js.map +0 -1
  160. package/dist/node/file/blob-stream.js.map +0 -1
  161. package/dist/node/file/blob.js.map +0 -1
  162. package/dist/node/file/file-reader.js.map +0 -1
  163. package/dist/node/file/file.js.map +0 -1
  164. package/dist/node/file/install-file-polyfills.js.map +0 -1
  165. package/dist/node/file/readable-stream.js.map +0 -1
  166. package/dist/node/images/encode-image.node.js.map +0 -1
  167. package/dist/node/images/parse-image.node.js.map +0 -1
  168. package/dist/promise/all-settled.js.map +0 -1
  169. package/dist/utils/assert.js.map +0 -1
  170. package/dist/utils/globals.js.map +0 -1
@@ -1,140 +1,160 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
-
3
- let _Symbol$toStringTag;
4
-
5
- import { BlobStream } from './blob-stream';
6
- _Symbol$toStringTag = Symbol.toStringTag;
7
- export class BlobPolyfill {
8
- constructor(init = [], options = {}) {
9
- _defineProperty(this, "type", void 0);
10
-
11
- _defineProperty(this, "size", void 0);
12
-
13
- _defineProperty(this, "parts", void 0);
14
-
15
- this.parts = [];
16
- this.size = 0;
17
-
18
- for (const part of init) {
19
- if (typeof part === 'string') {
20
- const bytes = new TextEncoder().encode(part);
21
- this.parts.push(bytes);
22
- this.size += bytes.byteLength;
23
- } else if (part instanceof BlobPolyfill) {
24
- this.size += part.size;
25
- this.parts.push(...part.parts);
26
- } else if (part instanceof ArrayBuffer) {
27
- this.parts.push(new Uint8Array(part));
28
- this.size += part.byteLength;
29
- } else if (part instanceof Uint8Array) {
30
- this.parts.push(part);
31
- this.size += part.byteLength;
32
- } else if (ArrayBuffer.isView(part)) {
33
- const {
34
- buffer,
35
- byteOffset,
36
- byteLength
37
- } = part;
38
- this.parts.push(new Uint8Array(buffer, byteOffset, byteLength));
39
- this.size += byteLength;
40
- } else {
41
- const bytes = new TextEncoder().encode(String(part));
42
- this.parts.push(bytes);
43
- this.size += bytes.byteLength;
44
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BlobPolyfill = void 0;
4
+ // Forked from @gozala's web-blob under MIT license https://github.com/Gozala/web-blob
5
+ const blob_stream_1 = require("./blob-stream");
6
+ /**
7
+ * Forked from @gozala's web-blob under MIT license
8
+ * @see https://github.com/Gozala/web-blob
9
+ */
10
+ class BlobPolyfill {
11
+ /**
12
+ * @param [init]
13
+ * @param [options]
14
+ */
15
+ constructor(init = [], options = {}) {
16
+ this.parts = [];
17
+ this.size = 0;
18
+ for (const part of init) {
19
+ if (typeof part === 'string') {
20
+ const bytes = new TextEncoder().encode(part);
21
+ this.parts.push(bytes);
22
+ this.size += bytes.byteLength;
23
+ }
24
+ else if (part instanceof BlobPolyfill) {
25
+ this.size += part.size;
26
+ // @ts-ignore - `parts` is marked private so TS will complain about
27
+ // accessing it.
28
+ this.parts.push(...part.parts);
29
+ }
30
+ else if (part instanceof ArrayBuffer) {
31
+ this.parts.push(new Uint8Array(part));
32
+ this.size += part.byteLength;
33
+ }
34
+ else if (part instanceof Uint8Array) {
35
+ this.parts.push(part);
36
+ this.size += part.byteLength;
37
+ }
38
+ else if (ArrayBuffer.isView(part)) {
39
+ const { buffer, byteOffset, byteLength } = part;
40
+ this.parts.push(new Uint8Array(buffer, byteOffset, byteLength));
41
+ this.size += byteLength;
42
+ }
43
+ else {
44
+ const bytes = new TextEncoder().encode(String(part));
45
+ this.parts.push(bytes);
46
+ this.size += bytes.byteLength;
47
+ }
48
+ }
49
+ /** @private */
50
+ this.type = readType(options.type);
51
+ }
52
+ /**
53
+ * Returns a new Blob object containing the data in the specified range of
54
+ * bytes of the blob on which it's called.
55
+ * @param start=0 - An index into the Blob indicating the first
56
+ * byte to include in the new Blob. If you specify a negative value, it's
57
+ * treated as an offset from the end of the Blob toward the beginning. For
58
+ * example, `-10` would be the 10th from last byte in the Blob. The default
59
+ * value is `0`. If you specify a value for start that is larger than the
60
+ * size of the source Blob, the returned Blob has size 0 and contains no
61
+ * data.
62
+ * @param end - An index into the `Blob` indicating the first byte
63
+ * that will *not* be included in the new `Blob` (i.e. the byte exactly at
64
+ * this index is not included). If you specify a negative value, it's treated
65
+ * as an offset from the end of the Blob toward the beginning. For example,
66
+ * `-10` would be the 10th from last byte in the `Blob`. The default value is
67
+ * size.
68
+ * @param type - The content type to assign to the new Blob;
69
+ * this will be the value of its type property. The default value is an empty
70
+ * string.
71
+ */
72
+ slice(start = 0, end = this.size, type = '') {
73
+ const { size, parts: parts } = this;
74
+ let offset = start < 0 ? Math.max(size + start, 0) : Math.min(start, size);
75
+ let limit = end < 0 ? Math.max(size + end, 0) : Math.min(end, size);
76
+ const span = Math.max(limit - offset, 0);
77
+ const blob = new BlobPolyfill([], { type });
78
+ if (span === 0) {
79
+ // @ts-ignore
80
+ return blob;
81
+ }
82
+ let blobSize = 0;
83
+ const blobParts = [];
84
+ for (const part of parts) {
85
+ const { byteLength } = part;
86
+ if (offset > 0 && byteLength <= offset) {
87
+ offset -= byteLength;
88
+ limit -= byteLength;
89
+ }
90
+ else {
91
+ const chunk = part.subarray(offset, Math.min(byteLength, limit));
92
+ blobParts.push(chunk);
93
+ blobSize += chunk.byteLength;
94
+ // no longer need to take that into account
95
+ offset = 0;
96
+ // don't add the overflow to new blobParts
97
+ if (blobSize >= span) {
98
+ break;
99
+ }
100
+ }
101
+ }
102
+ blob.parts = blobParts;
103
+ blob.size = blobSize;
104
+ // @ts-ignore
105
+ return blob;
45
106
  }
46
-
47
- this.type = readType(options.type);
48
- }
49
-
50
- slice(start = 0, end = this.size, type = '') {
51
- const {
52
- size,
53
- parts: parts
54
- } = this;
55
- let offset = start < 0 ? Math.max(size + start, 0) : Math.min(start, size);
56
- let limit = end < 0 ? Math.max(size + end, 0) : Math.min(end, size);
57
- const span = Math.max(limit - offset, 0);
58
- const blob = new BlobPolyfill([], {
59
- type
60
- });
61
-
62
- if (span === 0) {
63
- return blob;
107
+ /**
108
+ * Returns a promise that resolves with an ArrayBuffer containing the entire
109
+ * contents of the Blob as binary data.
110
+ */
111
+ // eslint-disable-next-line require-await
112
+ async arrayBuffer() {
113
+ return this._toArrayBuffer();
64
114
  }
65
-
66
- let blobSize = 0;
67
- const blobParts = [];
68
-
69
- for (const part of parts) {
70
- const {
71
- byteLength
72
- } = part;
73
-
74
- if (offset > 0 && byteLength <= offset) {
75
- offset -= byteLength;
76
- limit -= byteLength;
77
- } else {
78
- const chunk = part.subarray(offset, Math.min(byteLength, limit));
79
- blobParts.push(chunk);
80
- blobSize += chunk.byteLength;
81
- offset = 0;
82
-
83
- if (blobSize >= span) {
84
- break;
115
+ /**
116
+ * Returns a promise that resolves with a USVString containing the entire
117
+ * contents of the Blob interpreted as UTF-8 text.
118
+ */
119
+ // eslint-disable-next-line require-await
120
+ async text() {
121
+ const decoder = new TextDecoder();
122
+ let text = '';
123
+ for (const part of this.parts) {
124
+ text += decoder.decode(part);
85
125
  }
86
- }
126
+ return text;
87
127
  }
88
-
89
- blob.parts = blobParts;
90
- blob.size = blobSize;
91
- return blob;
92
- }
93
-
94
- async arrayBuffer() {
95
- return this._toArrayBuffer();
96
- }
97
-
98
- async text() {
99
- const decoder = new TextDecoder();
100
- let text = '';
101
-
102
- for (const part of this.parts) {
103
- text += decoder.decode(part);
128
+ /**
129
+ */
130
+ // @ts-ignore
131
+ stream() {
132
+ return new blob_stream_1.BlobStream(this.parts);
104
133
  }
105
-
106
- return text;
107
- }
108
-
109
- stream() {
110
- return new BlobStream(this.parts);
111
- }
112
-
113
- toString() {
114
- return '[object Blob]';
115
- }
116
-
117
- get [_Symbol$toStringTag]() {
118
- return 'Blob';
119
- }
120
-
121
- _toArrayBuffer() {
122
- const buffer = new ArrayBuffer(this.size);
123
- const bytes = new Uint8Array(buffer);
124
- let offset = 0;
125
-
126
- for (const part of this.parts) {
127
- bytes.set(part, offset);
128
- offset += part.byteLength;
134
+ /**
135
+ * @returns {string}
136
+ */
137
+ toString() {
138
+ return '[object Blob]';
139
+ }
140
+ get [Symbol.toStringTag]() {
141
+ return 'Blob';
142
+ }
143
+ _toArrayBuffer() {
144
+ const buffer = new ArrayBuffer(this.size);
145
+ const bytes = new Uint8Array(buffer);
146
+ let offset = 0;
147
+ for (const part of this.parts) {
148
+ bytes.set(part, offset);
149
+ offset += part.byteLength;
150
+ }
151
+ return buffer;
129
152
  }
130
-
131
- return buffer;
132
- }
133
-
134
153
  }
135
-
154
+ exports.BlobPolyfill = BlobPolyfill;
155
+ /**
156
+ */
136
157
  function readType(input = '') {
137
- const type = String(input).toLowerCase();
138
- return /[^\u0020-\u007E]/.test(type) ? '' : type;
158
+ const type = String(input).toLowerCase();
159
+ return /[^\u0020-\u007E]/.test(type) ? '' : type;
139
160
  }
140
- //# sourceMappingURL=blob.js.map
@@ -1,84 +1,35 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import { atob } from '../buffer/btoa.node';
3
- export class FileReaderPolyfill {
4
- constructor() {
5
- _defineProperty(this, "onload", void 0);
6
-
7
- _defineProperty(this, "onabort", void 0);
8
-
9
- _defineProperty(this, "onerror", void 0);
10
-
11
- _defineProperty(this, "error", void 0);
12
-
13
- _defineProperty(this, "onloadstart", void 0);
14
-
15
- _defineProperty(this, "onloadend", void 0);
16
-
17
- _defineProperty(this, "onprogress", void 0);
18
-
19
- _defineProperty(this, "readyState", void 0);
20
-
21
- _defineProperty(this, "result", void 0);
22
-
23
- _defineProperty(this, "DONE", void 0);
24
-
25
- _defineProperty(this, "EMPTY", void 0);
26
-
27
- _defineProperty(this, "LOADING", void 0);
28
-
29
- _defineProperty(this, "addEventListener", void 0);
30
-
31
- _defineProperty(this, "removeEventListener", void 0);
32
-
33
- _defineProperty(this, "dispatchEvent", void 0);
34
-
35
- this.onload = null;
36
- }
37
-
38
- abort() {
39
- return;
40
- }
41
-
42
- async readAsArrayBuffer(blob) {
43
- const arrayBuffer = await blob.arrayBuffer();
44
-
45
- if (this.onload) {
46
- this.onload({
47
- target: {
48
- result: arrayBuffer
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileReaderPolyfill = void 0;
4
+ const btoa_node_1 = require("../buffer/btoa.node");
5
+ class FileReaderPolyfill {
6
+ constructor() {
7
+ this.onload = null;
8
+ }
9
+ abort() {
10
+ return;
11
+ }
12
+ async readAsArrayBuffer(blob) {
13
+ const arrayBuffer = await blob.arrayBuffer();
14
+ if (this.onload) {
15
+ this.onload({ target: { result: arrayBuffer } });
49
16
  }
50
- });
51
17
  }
52
- }
53
-
54
- async readAsBinaryString(blob) {
55
- throw Error('Not implemented');
56
- }
57
-
58
- async readAsDataURL(blob) {
59
- const text = await blob.text();
60
- const dataUrl = "data://;base64,".concat(atob(text));
61
-
62
- if (this.onload) {
63
- this.onload({
64
- target: {
65
- result: dataUrl
18
+ async readAsBinaryString(blob) {
19
+ throw Error('Not implemented');
20
+ }
21
+ async readAsDataURL(blob) {
22
+ const text = await blob.text();
23
+ const dataUrl = `data://;base64,${(0, btoa_node_1.atob)(text)}`;
24
+ if (this.onload) {
25
+ this.onload({ target: { result: dataUrl } });
66
26
  }
67
- });
68
27
  }
69
- }
70
-
71
- async readAsText(blob) {
72
- const text = await blob.text();
73
-
74
- if (this.onload) {
75
- this.onload({
76
- target: {
77
- result: text
28
+ async readAsText(blob) {
29
+ const text = await blob.text();
30
+ if (this.onload) {
31
+ this.onload({ target: { result: text } });
78
32
  }
79
- });
80
33
  }
81
- }
82
-
83
34
  }
84
- //# sourceMappingURL=file-reader.js.map
35
+ exports.FileReaderPolyfill = FileReaderPolyfill;
@@ -1,26 +1,37 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
-
3
- let _Symbol$toStringTag;
4
-
5
- import { BlobPolyfill } from './blob';
6
- _Symbol$toStringTag = Symbol.toStringTag;
7
- export class FilePolyfill extends BlobPolyfill {
8
- constructor(init, name, options = {}) {
9
- super(init, options);
10
-
11
- _defineProperty(this, "name", '');
12
-
13
- _defineProperty(this, "webkitRelativePath", '');
14
-
15
- _defineProperty(this, "lastModified", void 0);
16
-
17
- this.name = String(name).replace(/\//g, ':');
18
- this.lastModified = (options === null || options === void 0 ? void 0 : options.lastModified) || Date.now();
19
- }
20
-
21
- get [_Symbol$toStringTag]() {
22
- return 'File';
23
- }
24
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FilePolyfill = void 0;
4
+ // Forked from @gozala's web-file under MIT license https://github.com/Gozala/web-file
5
+ const blob_1 = require("./blob");
6
+ /**
7
+ * Forked from @gozala's web-file under MIT license
8
+ * @see https://github.com/Gozala/web-file
9
+ */
10
+ // @ts-ignore
11
+ class FilePolyfill extends blob_1.BlobPolyfill {
12
+ /**
13
+ * @param init
14
+ * @param name - A USVString representing the file name or the path
15
+ * to the file.
16
+ * @param [options]
17
+ */
18
+ constructor(init, name, options = {}) {
19
+ super(init, options);
20
+ // implements File {
21
+ // public API
22
+ /** The name of the file referenced by the File object. */
23
+ this.name = '';
24
+ /** The path the URL of the File is relative to. */
25
+ this.webkitRelativePath = '';
26
+ // Per File API spec https://w3c.github.io/FileAPI/#file-constructor
27
+ // Every "/" character of file name must be replaced with a ":".
28
+ /** @private */
29
+ this.name = String(name).replace(/\//g, ':');
30
+ /** @private */
31
+ this.lastModified = options?.lastModified || Date.now();
32
+ }
33
+ get [Symbol.toStringTag]() {
34
+ return 'File';
35
+ }
25
36
  }
26
- //# sourceMappingURL=file.js.map
37
+ exports.FilePolyfill = FilePolyfill;
@@ -1,22 +1,27 @@
1
- import { ReadableStreamPolyfill } from './readable-stream';
2
- import { BlobPolyfill } from './blob';
3
- import { FileReaderPolyfill } from './file-reader';
4
- import { FilePolyfill } from './file';
5
- export function installFilePolyfills() {
6
- if (typeof ReadableStream === 'undefined' && global) {
7
- global.ReadableStream = ReadableStreamPolyfill;
8
- }
9
-
10
- if (typeof Blob === 'undefined' && global) {
11
- global.Blob = BlobPolyfill;
12
- }
13
-
14
- if (typeof FileReader === 'undefined' && global) {
15
- global.FileReader = FileReaderPolyfill;
16
- }
17
-
18
- if (typeof File === 'undefined' && global) {
19
- global.File = FilePolyfill;
20
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.installFilePolyfills = void 0;
4
+ const readable_stream_1 = require("./readable-stream");
5
+ const blob_1 = require("./blob");
6
+ const file_reader_1 = require("./file-reader");
7
+ const file_1 = require("./file");
8
+ function installFilePolyfills() {
9
+ if (typeof ReadableStream === 'undefined' && global) {
10
+ // @ts-ignore;
11
+ global.ReadableStream = readable_stream_1.ReadableStreamPolyfill;
12
+ }
13
+ if (typeof Blob === 'undefined' && global) {
14
+ // @ts-ignore;
15
+ global.Blob = blob_1.BlobPolyfill;
16
+ }
17
+ if (typeof FileReader === 'undefined' && global) {
18
+ // @ts-ignore;
19
+ global.FileReader = file_reader_1.FileReaderPolyfill;
20
+ }
21
+ // Install minimal Node.js File polyfill
22
+ if (typeof File === 'undefined' && global) {
23
+ // @ts-ignore;
24
+ global.File = file_1.FilePolyfill;
25
+ }
21
26
  }
22
- //# sourceMappingURL=install-file-polyfills.js.map
27
+ exports.installFilePolyfills = installFilePolyfills;
@@ -1,4 +1,11 @@
1
- import { ReadableStream as WSPReadableStream } from 'web-streams-polyfill';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReadableStreamPolyfill = void 0;
4
+ const web_streams_polyfill_1 = require("web-streams-polyfill");
5
+ // Want a polyfill, but please don't install it
6
+ // @ts-ignore
2
7
  delete global.ReadableStream;
3
- export class ReadableStreamPolyfill extends WSPReadableStream {}
4
- //# sourceMappingURL=readable-stream.js.map
8
+ // @ts-ignore
9
+ class ReadableStreamPolyfill extends web_streams_polyfill_1.ReadableStream {
10
+ }
11
+ exports.ReadableStreamPolyfill = ReadableStreamPolyfill;
@@ -1,20 +1,41 @@
1
- import savePixels from 'save-pixels';
2
- import ndarray from 'ndarray';
3
- import { bufferToArrayBuffer } from '../buffer/to-array-buffer.node';
4
- export function encodeImageToStreamNode(image, options) {
5
- const type = options.type ? options.type.replace('image/', '') : 'jpeg';
6
- const pixels = ndarray(image.data, [image.width, image.height, 4], [4, image.width * 4, 1], 0);
7
- return savePixels(pixels, type, options);
1
+ "use strict";
2
+ // Use stackgl modules for DOM-less reading and writing of images
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.encodeImageNode = exports.encodeImageToStreamNode = void 0;
8
+ const save_pixels_1 = __importDefault(require("save-pixels"));
9
+ const ndarray_1 = __importDefault(require("ndarray"));
10
+ const to_array_buffer_node_1 = require("../buffer/to-array-buffer.node");
11
+ /**
12
+ * Returns data bytes representing a compressed image in PNG or JPG format,
13
+ * This data can be saved using file system (f) methods or
14
+ * used in a request.
15
+ * @param image to save
16
+ * @param options
17
+ * @param options.type='png' - png, jpg or image/png, image/jpg are valid
18
+ * @param options.dataURI - Whether to include a data URI header
19
+ * @return {*} bytes
20
+ */
21
+ function encodeImageToStreamNode(image, options) {
22
+ // Support MIME type strings
23
+ const type = options.type ? options.type.replace('image/', '') : 'jpeg';
24
+ const pixels = (0, ndarray_1.default)(image.data, [image.width, image.height, 4], [4, image.width * 4, 1], 0);
25
+ // Note: savePixels returns a stream
26
+ return (0, save_pixels_1.default)(pixels, type, options);
8
27
  }
9
- export function encodeImageNode(image, options) {
10
- const imageStream = encodeImageToStreamNode(image, options);
11
- return new Promise(resolve => {
12
- const buffers = [];
13
- imageStream.on('data', buffer => buffers.push(buffer));
14
- imageStream.on('end', () => {
15
- const buffer = Buffer.concat(buffers);
16
- resolve(bufferToArrayBuffer(buffer));
28
+ exports.encodeImageToStreamNode = encodeImageToStreamNode;
29
+ function encodeImageNode(image, options) {
30
+ const imageStream = encodeImageToStreamNode(image, options);
31
+ return new Promise((resolve) => {
32
+ const buffers = [];
33
+ imageStream.on('data', (buffer) => buffers.push(buffer));
34
+ // TODO - convert to arraybuffer?
35
+ imageStream.on('end', () => {
36
+ const buffer = Buffer.concat(buffers);
37
+ resolve((0, to_array_buffer_node_1.bufferToArrayBuffer)(buffer));
38
+ });
17
39
  });
18
- });
19
40
  }
20
- //# sourceMappingURL=encode-image.node.js.map
41
+ exports.encodeImageNode = encodeImageNode;
@@ -1,4 +1,6 @@
1
- declare type NDArray = {
1
+ /** Declares which image format mime types this loader polyfill supports */
2
+ export declare const NODE_FORMAT_SUPPORT: string[];
3
+ type NDArray = {
2
4
  shape: number[];
3
5
  data: Uint8Array;
4
6
  width: number;
@@ -1 +1 @@
1
- {"version":3,"file":"parse-image.node.d.ts","sourceRoot":"","sources":["../../../src/node/images/parse-image.node.ts"],"names":[],"mappings":"AAKA,aAAK,OAAO,GAAG;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF,wBAAsB,cAAc,CAAC,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAuBjG"}
1
+ {"version":3,"file":"parse-image.node.d.ts","sourceRoot":"","sources":["../../../src/node/images/parse-image.node.ts"],"names":[],"mappings":"AAIA,2EAA2E;AAC3E,eAAO,MAAM,mBAAmB,UAA2C,CAAC;AAG5E,KAAK,OAAO,GAAG;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF,wBAAsB,cAAc,CAAC,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAQjG"}