@loaders.gl/polyfills 4.2.0-alpha.3 → 4.2.0-alpha.5

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 (81) hide show
  1. package/dist/buffer/btoa.node.js +5 -3
  2. package/dist/buffer/to-array-buffer.node.js +6 -6
  3. package/dist/crypto/node-hash.js +41 -45
  4. package/dist/fetch/decode-data-uri.js +56 -41
  5. package/dist/fetch/fetch-polyfill.d.ts +1 -1
  6. package/dist/fetch/fetch-polyfill.d.ts.map +1 -1
  7. package/dist/fetch/fetch-polyfill.js +118 -103
  8. package/dist/fetch/headers-polyfill.js +90 -89
  9. package/dist/fetch/response-polyfill.d.ts +1 -1
  10. package/dist/fetch/response-polyfill.d.ts.map +1 -1
  11. package/dist/fetch/response-polyfill.js +65 -57
  12. package/dist/fetch/utils/decode-data-uri.node.js +56 -41
  13. package/dist/file/blob-stream-controller.js +54 -38
  14. package/dist/file/blob-stream.d.ts +1 -1
  15. package/dist/file/blob-stream.d.ts.map +1 -1
  16. package/dist/file/blob-stream.js +29 -15
  17. package/dist/file/blob.d.ts +1 -1
  18. package/dist/file/blob.d.ts.map +1 -1
  19. package/dist/file/blob.js +146 -109
  20. package/dist/file/file-reader.js +22 -50
  21. package/dist/file/file.js +30 -15
  22. package/dist/file/install-blob-polyfills.js +6 -5
  23. package/dist/file/install-file-polyfills.js +11 -8
  24. package/dist/file/readable-stream.js +5 -2
  25. package/dist/filesystems/fetch-node.js +78 -68
  26. package/dist/filesystems/node-file.js +119 -87
  27. package/dist/filesystems/node-filesystem.d.ts +1 -1
  28. package/dist/filesystems/node-filesystem.d.ts.map +1 -1
  29. package/dist/filesystems/node-filesystem.js +39 -35
  30. package/dist/filesystems/stream-utils.node.js +88 -55
  31. package/dist/images/encode-image-node.js +25 -12
  32. package/dist/images/encode-image.node.js +25 -12
  33. package/dist/images/parse-image-node.js +30 -23
  34. package/dist/images/parse-image.node.js +30 -23
  35. package/dist/index.browser.js +8 -3
  36. package/dist/index.cjs +13 -65091
  37. package/dist/index.cjs.map +7 -0
  38. package/dist/index.d.ts +4 -4
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +45 -15
  41. package/dist/libs/encoding-indexes-asian.js +6 -7
  42. package/dist/load-library/require-utils.node.js +70 -44
  43. package/dist/streams/make-node-stream.js +48 -46
  44. package/dist/text-encoder/encoding-indexes.js +31 -28
  45. package/dist/text-encoder/text-encoder.js +2604 -1033
  46. package/dist/utils/assert.js +3 -4
  47. package/dist/utils/is-browser.js +7 -2
  48. package/package.json +10 -8
  49. package/dist/buffer/btoa.node.js.map +0 -1
  50. package/dist/buffer/to-array-buffer.node.js.map +0 -1
  51. package/dist/crypto/node-hash.js.map +0 -1
  52. package/dist/dist.dev.js +0 -45
  53. package/dist/fetch/decode-data-uri.js.map +0 -1
  54. package/dist/fetch/fetch-polyfill.js.map +0 -1
  55. package/dist/fetch/headers-polyfill.js.map +0 -1
  56. package/dist/fetch/response-polyfill.js.map +0 -1
  57. package/dist/fetch/utils/decode-data-uri.node.js.map +0 -1
  58. package/dist/file/blob-stream-controller.js.map +0 -1
  59. package/dist/file/blob-stream.js.map +0 -1
  60. package/dist/file/blob.js.map +0 -1
  61. package/dist/file/file-reader.js.map +0 -1
  62. package/dist/file/file.js.map +0 -1
  63. package/dist/file/install-blob-polyfills.js.map +0 -1
  64. package/dist/file/install-file-polyfills.js.map +0 -1
  65. package/dist/file/readable-stream.js.map +0 -1
  66. package/dist/filesystems/fetch-node.js.map +0 -1
  67. package/dist/filesystems/node-file.js.map +0 -1
  68. package/dist/filesystems/node-filesystem.js.map +0 -1
  69. package/dist/filesystems/stream-utils.node.js.map +0 -1
  70. package/dist/images/encode-image-node.js.map +0 -1
  71. package/dist/images/encode-image.node.js.map +0 -1
  72. package/dist/images/parse-image-node.js.map +0 -1
  73. package/dist/images/parse-image.node.js.map +0 -1
  74. package/dist/index.browser.js.map +0 -1
  75. package/dist/index.js.map +0 -1
  76. package/dist/load-library/require-utils.node.js.map +0 -1
  77. package/dist/streams/make-node-stream.js.map +0 -1
  78. package/dist/text-encoder/encoding-indexes.js.map +0 -1
  79. package/dist/text-encoder/text-encoder.js.map +0 -1
  80. package/dist/utils/assert.js.map +0 -1
  81. package/dist/utils/is-browser.js.map +0 -1
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["index.browser.js"],
4
+ "sourcesContent": ["// loaders.gl\n// SPDX-License-Identifier: MIT\nexport function installFilePolyfills() { }\n// Dummy export to avoid import errors in browser tests\nexport const NodeFileSystem = null;\nexport function fetchNode(path, options) {\n throw new Error('fetchNode not available in browser');\n}\n// Ensure process and process.env are defined, as Node code tends to crash on these\n// @ts-ignore\nglobalThis.process = globalThis.process || {};\n// @ts-ignore\nglobalThis.process.env = globalThis.process.env || {};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,SAAS,uBAAuB;AAAE;AAElC,IAAM,iBAAiB;AACvB,SAAS,UAAU,MAAM,SAAS;AACrC,QAAM,IAAI,MAAM,oCAAoC;AACxD;AAGA,WAAW,UAAU,WAAW,WAAW,CAAC;AAE5C,WAAW,QAAQ,MAAM,WAAW,QAAQ,OAAO,CAAC;",
6
+ "names": []
7
+ }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export declare const nodeVersion: number;
2
- export { Blob_ as Blob } from './file/install-blob-polyfills';
3
- export { File_ as File } from './file/install-file-polyfills';
4
- export { makeNodeStream } from './streams/make-node-stream';
5
- export { installFilePolyfills } from './file/install-file-polyfills';
2
+ export { Blob_ as Blob } from "./file/install-blob-polyfills.js";
3
+ export { File_ as File } from "./file/install-file-polyfills.js";
4
+ export { makeNodeStream } from "./streams/make-node-stream.js";
5
+ export { installFilePolyfills } from "./file/install-file-polyfills.js";
6
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,WAAW,QAAwC,CAAC;AAMjE,OAAO,EAAC,KAAK,IAAI,IAAI,EAAC,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAC,KAAK,IAAI,IAAI,EAAC,MAAM,+BAA+B,CAAC;AAY5D,OAAO,EAAC,cAAc,EAAC,MAAM,4BAA4B,CAAC;AA8D1D,OAAO,EAAC,oBAAoB,EAAC,MAAM,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,WAAW,QAAwC,CAAC;AAMjE,OAAO,EAAC,KAAK,IAAI,IAAI,EAAC,yCAAsC;AAC5D,OAAO,EAAC,KAAK,IAAI,IAAI,EAAC,yCAAsC;AAY5D,OAAO,EAAC,cAAc,EAAC,sCAAmC;AA8D1D,OAAO,EAAC,oBAAoB,EAAC,yCAAsC"}
package/dist/index.js CHANGED
@@ -1,62 +1,92 @@
1
+ /* eslint-disable dot-notation */
1
2
  import { isBrowser } from "./utils/is-browser.js";
2
3
  import { TextDecoder, TextEncoder } from "./text-encoder/text-encoder.js";
4
+ // Node specific
3
5
  import { atob, btoa } from "./buffer/btoa.node.js";
4
6
  import { encodeImageNode } from "./images/encode-image-node.js";
5
7
  import { parseImageNode, NODE_FORMAT_SUPPORT } from "./images/parse-image-node.js";
8
+ // FILESYSTEM POLYFILLS
6
9
  import { NodeFile } from "./filesystems/node-file.js";
7
10
  import { NodeFileSystem } from "./filesystems/node-filesystem.js";
8
11
  import { fetchNode } from "./filesystems/fetch-node.js";
9
12
  import { NodeHash } from "./crypto/node-hash.js";
13
+ // NODE VERSION
10
14
  import { versions } from 'node:process';
11
15
  export const nodeVersion = parseInt(versions.node.split('.')[0]);
16
+ // STREAM POLYFILLS
12
17
  import { makeNodeStream } from "./streams/make-node-stream.js";
18
+ // BLOB AND FILE POLYFILLS
13
19
  export { Blob_ as Blob } from "./file/install-blob-polyfills.js";
14
20
  export { File_ as File } from "./file/install-file-polyfills.js";
15
21
  if (isBrowser) {
16
- console.error('loaders.gl: The @loaders.gl/polyfills should only be used in Node.js environments');
22
+ // eslint-disable-next-line no-console
23
+ console.error('loaders.gl: The @loaders.gl/polyfills should only be used in Node.js environments');
17
24
  }
18
25
  globalThis.loaders = globalThis.loaders || {};
26
+ // STREAM POLYFILLS
19
27
  export { makeNodeStream } from "./streams/make-node-stream.js";
20
28
  globalThis.loaders.makeNodeStream = makeNodeStream;
29
+ // FILESYSTEM POLYFILLS
21
30
  globalThis.loaders.NodeFile = NodeFile;
22
31
  globalThis.loaders.NodeFileSystem = NodeFileSystem;
23
32
  globalThis.loaders.fetchNode = fetchNode;
33
+ // CRYPTO POLYFILLS
24
34
  globalThis.loaders.NodeHash = NodeHash;
35
+ // POLYFILLS: TextEncoder, TextDecoder
36
+ // - Recent Node versions have these classes but virtually no encodings unless special build.
37
+ // - Browser: Edge, IE11 do not have these
25
38
  if (!globalThis.TextEncoder) {
26
- globalThis.TextEncoder = TextEncoder;
39
+ // @ts-expect-error
40
+ globalThis.TextEncoder = TextEncoder;
27
41
  }
28
42
  if (!globalThis.TextDecoder) {
29
- globalThis.TextDecoder = TextDecoder;
43
+ // @ts-expect-error
44
+ globalThis.TextDecoder = TextDecoder;
30
45
  }
46
+ // POLYFILLS: btoa, atob
47
+ // - Node: Yes
48
+ // - Browser: No
31
49
  if (!('atob' in globalThis) && atob) {
32
- globalThis['atob'] = atob;
50
+ globalThis['atob'] = atob;
33
51
  }
34
52
  if (!('btoa' in globalThis) && btoa) {
35
- globalThis['btoa'] = btoa;
53
+ globalThis['btoa'] = btoa;
36
54
  }
55
+ // NODE IMAGE FUNCTIONS:
56
+ // These are not official polyfills but used by the @loaders.gl/images module if installed
57
+ // TODO - is there an appropriate Image API we could polyfill using an adapter?
37
58
  globalThis.loaders.encodeImageNode = encodeImageNode;
38
59
  globalThis.loaders.parseImageNode = parseImageNode;
39
60
  globalThis.loaders.imageFormatsNode = NODE_FORMAT_SUPPORT;
61
+ // Deprecated, remove after republish
40
62
  globalThis._parseImageNode = parseImageNode;
41
63
  globalThis._imageFormatsNode = NODE_FORMAT_SUPPORT;
64
+ // LOAD LIBRARY
42
65
  import { readFileAsArrayBuffer, readFileAsText, requireFromFile, requireFromString } from "./load-library/require-utils.node.js";
43
66
  globalThis.loaders.readFileAsArrayBuffer = readFileAsArrayBuffer;
44
67
  globalThis.loaders.readFileAsText = readFileAsText;
45
68
  globalThis.loaders.requireFromFile = requireFromFile;
46
69
  globalThis.loaders.requireFromString = requireFromString;
47
70
  export { installFilePolyfills } from "./file/install-file-polyfills.js";
71
+ // DEPRECATED POLYFILL:
72
+ // - Node v18+: No, not needed
73
+ // - Node v16 and lower: Yes
74
+ // - Browsers (evergreen): Not needed.
75
+ // - IE11: No. This polyfill is node only, install external polyfill
48
76
  import { Headers as HeadersNode } from "./fetch/headers-polyfill.js";
49
77
  import { Response as ResponseNode } from "./fetch/response-polyfill.js";
50
78
  import { fetchNode as fetchNodePolyfill } from "./fetch/fetch-polyfill.js";
51
79
  if (nodeVersion < 18) {
52
- if (!('Headers' in globalThis) && HeadersNode) {
53
- globalThis.Headers = HeadersNode;
54
- }
55
- if (!('Response' in globalThis) && ResponseNode) {
56
- globalThis.Response = ResponseNode;
57
- }
58
- if (!('fetch' in globalThis) && fetchNodePolyfill) {
59
- globalThis.fetch = fetchNodePolyfill;
60
- }
80
+ if (!('Headers' in globalThis) && HeadersNode) {
81
+ // @ts-ignore
82
+ globalThis.Headers = HeadersNode;
83
+ }
84
+ if (!('Response' in globalThis) && ResponseNode) {
85
+ // @ts-ignore
86
+ globalThis.Response = ResponseNode;
87
+ }
88
+ if (!('fetch' in globalThis) && fetchNodePolyfill) {
89
+ // @ts-ignore
90
+ globalThis.fetch = fetchNodePolyfill;
91
+ }
61
92
  }
62
- //# sourceMappingURL=index.js.map