@loaders.gl/polyfills 4.2.0-alpha.4 → 4.2.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 (93) 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 +46 -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 +91 -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 +73 -57
  12. package/dist/fetch/utils/decode-data-uri.node.js +56 -41
  13. package/dist/file/blob-stream-controller.js +55 -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 +30 -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 +152 -109
  20. package/dist/file/file-reader.js +38 -50
  21. package/dist/file/file.js +35 -15
  22. package/dist/file/install-blob-polyfills.js +6 -5
  23. package/dist/file/install-file-polyfills.d.ts +3 -2
  24. package/dist/file/install-file-polyfills.d.ts.map +1 -1
  25. package/dist/file/install-file-polyfills.js +11 -8
  26. package/dist/file/readable-stream.js +5 -2
  27. package/dist/filesystems/fetch-node.d.ts.map +1 -1
  28. package/dist/filesystems/fetch-node.js +80 -68
  29. package/dist/filesystems/node-file.d.ts.map +1 -1
  30. package/dist/filesystems/node-file.js +129 -87
  31. package/dist/filesystems/node-filesystem.d.ts +1 -1
  32. package/dist/filesystems/node-filesystem.d.ts.map +1 -1
  33. package/dist/filesystems/node-filesystem.js +39 -35
  34. package/dist/filesystems/stream-utils.node.js +88 -55
  35. package/dist/images/encode-image-node.js +25 -12
  36. package/dist/images/encode-image.node.js +25 -12
  37. package/dist/images/parse-image-node.js +30 -23
  38. package/dist/images/parse-image.node.js +30 -23
  39. package/dist/index.browser.js +8 -3
  40. package/dist/index.cjs +13 -65091
  41. package/dist/index.cjs.map +7 -0
  42. package/dist/index.d.ts +4 -4
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +46 -15
  45. package/dist/libs/encoding-indexes-asian.js +6 -7
  46. package/dist/load-library/require-utils.node.js +70 -44
  47. package/dist/streams/make-node-stream.d.ts.map +1 -1
  48. package/dist/streams/make-node-stream.js +52 -46
  49. package/dist/text-encoder/encoding-indexes.js +31 -28
  50. package/dist/text-encoder/text-encoder.js +2604 -1033
  51. package/dist/utils/assert.js +3 -4
  52. package/dist/utils/is-browser.js +7 -2
  53. package/package.json +13 -11
  54. package/src/fetch/response-polyfill.ts +2 -0
  55. package/src/filesystems/fetch-node.ts +2 -0
  56. package/src/filesystems/node-file.ts +4 -0
  57. package/src/filesystems/node-filesystem.ts +1 -0
  58. package/src/index.ts +1 -0
  59. package/src/load-library/require-utils.node.ts +1 -1
  60. package/src/streams/make-node-stream.ts +3 -2
  61. package/dist/buffer/btoa.node.js.map +0 -1
  62. package/dist/buffer/to-array-buffer.node.js.map +0 -1
  63. package/dist/crypto/node-hash.js.map +0 -1
  64. package/dist/dist.dev.js +0 -45
  65. package/dist/fetch/decode-data-uri.js.map +0 -1
  66. package/dist/fetch/fetch-polyfill.js.map +0 -1
  67. package/dist/fetch/headers-polyfill.js.map +0 -1
  68. package/dist/fetch/response-polyfill.js.map +0 -1
  69. package/dist/fetch/utils/decode-data-uri.node.js.map +0 -1
  70. package/dist/file/blob-stream-controller.js.map +0 -1
  71. package/dist/file/blob-stream.js.map +0 -1
  72. package/dist/file/blob.js.map +0 -1
  73. package/dist/file/file-reader.js.map +0 -1
  74. package/dist/file/file.js.map +0 -1
  75. package/dist/file/install-blob-polyfills.js.map +0 -1
  76. package/dist/file/install-file-polyfills.js.map +0 -1
  77. package/dist/file/readable-stream.js.map +0 -1
  78. package/dist/filesystems/fetch-node.js.map +0 -1
  79. package/dist/filesystems/node-file.js.map +0 -1
  80. package/dist/filesystems/node-filesystem.js.map +0 -1
  81. package/dist/filesystems/stream-utils.node.js.map +0 -1
  82. package/dist/images/encode-image-node.js.map +0 -1
  83. package/dist/images/encode-image.node.js.map +0 -1
  84. package/dist/images/parse-image-node.js.map +0 -1
  85. package/dist/images/parse-image.node.js.map +0 -1
  86. package/dist/index.browser.js.map +0 -1
  87. package/dist/index.js.map +0 -1
  88. package/dist/load-library/require-utils.node.js.map +0 -1
  89. package/dist/streams/make-node-stream.js.map +0 -1
  90. package/dist/text-encoder/encoding-indexes.js.map +0 -1
  91. package/dist/text-encoder/text-encoder.js.map +0 -1
  92. package/dist/utils/assert.js.map +0 -1
  93. 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":"AAqBA,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,93 @@
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
14
+ // @ts-expect-error
10
15
  import { versions } from 'node:process';
11
16
  export const nodeVersion = parseInt(versions.node.split('.')[0]);
17
+ // STREAM POLYFILLS
12
18
  import { makeNodeStream } from "./streams/make-node-stream.js";
19
+ // BLOB AND FILE POLYFILLS
13
20
  export { Blob_ as Blob } from "./file/install-blob-polyfills.js";
14
21
  export { File_ as File } from "./file/install-file-polyfills.js";
15
22
  if (isBrowser) {
16
- console.error('loaders.gl: The @loaders.gl/polyfills should only be used in Node.js environments');
23
+ // eslint-disable-next-line no-console
24
+ console.error('loaders.gl: The @loaders.gl/polyfills should only be used in Node.js environments');
17
25
  }
18
26
  globalThis.loaders = globalThis.loaders || {};
27
+ // STREAM POLYFILLS
19
28
  export { makeNodeStream } from "./streams/make-node-stream.js";
20
29
  globalThis.loaders.makeNodeStream = makeNodeStream;
30
+ // FILESYSTEM POLYFILLS
21
31
  globalThis.loaders.NodeFile = NodeFile;
22
32
  globalThis.loaders.NodeFileSystem = NodeFileSystem;
23
33
  globalThis.loaders.fetchNode = fetchNode;
34
+ // CRYPTO POLYFILLS
24
35
  globalThis.loaders.NodeHash = NodeHash;
36
+ // POLYFILLS: TextEncoder, TextDecoder
37
+ // - Recent Node versions have these classes but virtually no encodings unless special build.
38
+ // - Browser: Edge, IE11 do not have these
25
39
  if (!globalThis.TextEncoder) {
26
- globalThis.TextEncoder = TextEncoder;
40
+ // @ts-expect-error
41
+ globalThis.TextEncoder = TextEncoder;
27
42
  }
28
43
  if (!globalThis.TextDecoder) {
29
- globalThis.TextDecoder = TextDecoder;
44
+ // @ts-expect-error
45
+ globalThis.TextDecoder = TextDecoder;
30
46
  }
47
+ // POLYFILLS: btoa, atob
48
+ // - Node: Yes
49
+ // - Browser: No
31
50
  if (!('atob' in globalThis) && atob) {
32
- globalThis['atob'] = atob;
51
+ globalThis['atob'] = atob;
33
52
  }
34
53
  if (!('btoa' in globalThis) && btoa) {
35
- globalThis['btoa'] = btoa;
54
+ globalThis['btoa'] = btoa;
36
55
  }
56
+ // NODE IMAGE FUNCTIONS:
57
+ // These are not official polyfills but used by the @loaders.gl/images module if installed
58
+ // TODO - is there an appropriate Image API we could polyfill using an adapter?
37
59
  globalThis.loaders.encodeImageNode = encodeImageNode;
38
60
  globalThis.loaders.parseImageNode = parseImageNode;
39
61
  globalThis.loaders.imageFormatsNode = NODE_FORMAT_SUPPORT;
62
+ // Deprecated, remove after republish
40
63
  globalThis._parseImageNode = parseImageNode;
41
64
  globalThis._imageFormatsNode = NODE_FORMAT_SUPPORT;
65
+ // LOAD LIBRARY
42
66
  import { readFileAsArrayBuffer, readFileAsText, requireFromFile, requireFromString } from "./load-library/require-utils.node.js";
43
67
  globalThis.loaders.readFileAsArrayBuffer = readFileAsArrayBuffer;
44
68
  globalThis.loaders.readFileAsText = readFileAsText;
45
69
  globalThis.loaders.requireFromFile = requireFromFile;
46
70
  globalThis.loaders.requireFromString = requireFromString;
47
71
  export { installFilePolyfills } from "./file/install-file-polyfills.js";
72
+ // DEPRECATED POLYFILL:
73
+ // - Node v18+: No, not needed
74
+ // - Node v16 and lower: Yes
75
+ // - Browsers (evergreen): Not needed.
76
+ // - IE11: No. This polyfill is node only, install external polyfill
48
77
  import { Headers as HeadersNode } from "./fetch/headers-polyfill.js";
49
78
  import { Response as ResponseNode } from "./fetch/response-polyfill.js";
50
79
  import { fetchNode as fetchNodePolyfill } from "./fetch/fetch-polyfill.js";
51
80
  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
- }
81
+ if (!('Headers' in globalThis) && HeadersNode) {
82
+ // @ts-ignore
83
+ globalThis.Headers = HeadersNode;
84
+ }
85
+ if (!('Response' in globalThis) && ResponseNode) {
86
+ // @ts-ignore
87
+ globalThis.Response = ResponseNode;
88
+ }
89
+ if (!('fetch' in globalThis) && fetchNodePolyfill) {
90
+ // @ts-ignore
91
+ globalThis.fetch = fetchNodePolyfill;
92
+ }
61
93
  }
62
- //# sourceMappingURL=index.js.map