@loaders.gl/loader-utils 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 (126) hide show
  1. package/dist/es5/index.js +46 -48
  2. package/dist/es5/index.js.map +1 -1
  3. package/dist/es5/json-loader.js +5 -33
  4. package/dist/es5/json-loader.js.map +1 -1
  5. package/dist/es5/lib/binary-utils/array-buffer-utils.js +23 -58
  6. package/dist/es5/lib/binary-utils/array-buffer-utils.js.map +1 -1
  7. package/dist/es5/lib/binary-utils/binary-copy-utils.js +7 -7
  8. package/dist/es5/lib/binary-utils/binary-copy-utils.js.map +1 -1
  9. package/dist/es5/lib/binary-utils/buffer-utils.js +4 -10
  10. package/dist/es5/lib/binary-utils/buffer-utils.js.map +1 -1
  11. package/dist/es5/lib/binary-utils/encode-utils.js +7 -7
  12. package/dist/es5/lib/binary-utils/encode-utils.js.map +1 -1
  13. package/dist/es5/lib/binary-utils/get-first-characters.js +5 -7
  14. package/dist/es5/lib/binary-utils/get-first-characters.js.map +1 -1
  15. package/dist/es5/lib/binary-utils/memory-copy-utils.js +6 -7
  16. package/dist/es5/lib/binary-utils/memory-copy-utils.js.map +1 -1
  17. package/dist/es5/lib/env-utils/globals.js +9 -14
  18. package/dist/es5/lib/env-utils/globals.js.map +1 -1
  19. package/dist/es5/lib/filesystems/node-filesystem.js +50 -243
  20. package/dist/es5/lib/filesystems/node-filesystem.js.map +1 -1
  21. package/dist/es5/lib/iterators/async-iteration.js +27 -242
  22. package/dist/es5/lib/iterators/async-iteration.js.map +1 -1
  23. package/dist/es5/lib/iterators/text-iterators.js +35 -410
  24. package/dist/es5/lib/iterators/text-iterators.js.map +1 -1
  25. package/dist/es5/lib/node/buffer.js +4 -4
  26. package/dist/es5/lib/node/buffer.js.map +1 -1
  27. package/dist/es5/lib/node/fs.js +20 -51
  28. package/dist/es5/lib/node/fs.js.map +1 -1
  29. package/dist/es5/lib/node/util.js +3 -5
  30. package/dist/es5/lib/node/util.js.map +1 -1
  31. package/dist/es5/lib/path-utils/file-aliases.js +4 -4
  32. package/dist/es5/lib/path-utils/file-aliases.js.map +1 -1
  33. package/dist/es5/lib/path-utils/path.js +5 -9
  34. package/dist/es5/lib/path-utils/path.js.map +1 -1
  35. package/dist/es5/lib/request-utils/request-scheduler.js +96 -124
  36. package/dist/es5/lib/request-utils/request-scheduler.js.map +1 -1
  37. package/dist/es5/lib/worker-loader-utils/create-loader-worker.js +63 -132
  38. package/dist/es5/lib/worker-loader-utils/create-loader-worker.js.map +1 -1
  39. package/dist/es5/lib/worker-loader-utils/parse-with-worker.js +51 -111
  40. package/dist/es5/lib/worker-loader-utils/parse-with-worker.js.map +1 -1
  41. package/dist/esm/json-loader.js +1 -1
  42. package/dist/esm/json-loader.js.map +1 -1
  43. package/dist/esm/lib/parser-utils/parse-json.js +1 -1
  44. package/dist/esm/lib/parser-utils/parse-json.js.map +1 -1
  45. package/dist/esm/lib/path-utils/file-aliases.js +1 -1
  46. package/dist/esm/lib/path-utils/file-aliases.js.map +1 -1
  47. package/dist/esm/lib/path-utils/path.js +2 -2
  48. package/dist/esm/lib/path-utils/path.js.map +1 -1
  49. package/dist/esm/lib/worker-loader-utils/create-loader-worker.js +1 -1
  50. package/dist/esm/lib/worker-loader-utils/create-loader-worker.js.map +1 -1
  51. package/dist/esm/lib/worker-loader-utils/parse-with-worker.js +2 -2
  52. package/dist/esm/lib/worker-loader-utils/parse-with-worker.js.map +1 -1
  53. package/dist/index.d.ts +27 -0
  54. package/dist/index.d.ts.map +1 -0
  55. package/dist/index.js +111 -0
  56. package/dist/json-loader.d.ts +22 -0
  57. package/dist/json-loader.d.ts.map +1 -0
  58. package/dist/json-loader.js +28 -0
  59. package/dist/lib/binary-utils/array-buffer-utils.d.ts +31 -0
  60. package/dist/lib/binary-utils/array-buffer-utils.d.ts.map +1 -0
  61. package/dist/lib/binary-utils/array-buffer-utils.js +115 -0
  62. package/dist/lib/binary-utils/binary-copy-utils.d.ts +24 -0
  63. package/dist/lib/binary-utils/binary-copy-utils.d.ts.map +1 -0
  64. package/dist/lib/binary-utils/binary-copy-utils.js +51 -0
  65. package/dist/lib/binary-utils/buffer-utils.d.ts +16 -0
  66. package/dist/lib/binary-utils/buffer-utils.d.ts.map +1 -0
  67. package/dist/lib/binary-utils/buffer-utils.js +50 -0
  68. package/dist/lib/binary-utils/encode-utils.d.ts +4 -0
  69. package/dist/lib/binary-utils/encode-utils.d.ts.map +1 -0
  70. package/dist/lib/binary-utils/encode-utils.js +35 -0
  71. package/dist/lib/binary-utils/get-first-characters.d.ts +3 -0
  72. package/dist/lib/binary-utils/get-first-characters.d.ts.map +1 -0
  73. package/dist/lib/binary-utils/get-first-characters.js +30 -0
  74. package/dist/lib/binary-utils/memory-copy-utils.d.ts +25 -0
  75. package/dist/lib/binary-utils/memory-copy-utils.d.ts.map +1 -0
  76. package/dist/lib/binary-utils/memory-copy-utils.js +61 -0
  77. package/dist/lib/env-utils/assert.d.ts +6 -0
  78. package/dist/lib/env-utils/assert.d.ts.map +1 -0
  79. package/dist/lib/env-utils/assert.js +13 -0
  80. package/dist/lib/env-utils/globals.d.ts +15 -0
  81. package/dist/lib/env-utils/globals.d.ts.map +1 -0
  82. package/dist/lib/env-utils/globals.js +30 -0
  83. package/dist/lib/filesystems/node-filesystem.d.ts +38 -0
  84. package/dist/lib/filesystems/node-filesystem.d.ts.map +1 -0
  85. package/dist/lib/filesystems/node-filesystem.js +69 -0
  86. package/dist/lib/iterators/async-iteration.d.ts +20 -0
  87. package/dist/lib/iterators/async-iteration.d.ts.map +1 -0
  88. package/dist/lib/iterators/async-iteration.js +53 -0
  89. package/dist/lib/iterators/text-iterators.d.ts +19 -0
  90. package/dist/lib/iterators/text-iterators.d.ts.map +1 -0
  91. package/dist/lib/iterators/text-iterators.js +61 -0
  92. package/dist/lib/node/buffer.d.ts +10 -0
  93. package/dist/lib/node/buffer.d.ts.map +1 -0
  94. package/dist/lib/node/buffer.js +36 -0
  95. package/dist/lib/node/fs.d.ts +26 -0
  96. package/dist/lib/node/fs.d.ts.map +1 -0
  97. package/dist/lib/node/fs.js +42 -0
  98. package/dist/lib/node/util.d.ts +5 -0
  99. package/dist/lib/node/util.d.ts.map +1 -0
  100. package/dist/lib/node/util.js +25 -0
  101. package/dist/lib/parser-utils/parse-json.d.ts +5 -0
  102. package/dist/lib/parser-utils/parse-json.d.ts.map +1 -0
  103. package/dist/lib/parser-utils/parse-json.js +16 -0
  104. package/dist/lib/path-utils/file-aliases.d.ts +17 -0
  105. package/dist/lib/path-utils/file-aliases.d.ts.map +1 -0
  106. package/dist/lib/path-utils/file-aliases.js +47 -0
  107. package/dist/lib/path-utils/path.d.ts +16 -0
  108. package/dist/lib/path-utils/path.d.ts.map +1 -0
  109. package/dist/lib/path-utils/path.js +40 -0
  110. package/dist/lib/request-utils/request-scheduler.d.ts +62 -0
  111. package/dist/lib/request-utils/request-scheduler.d.ts.map +1 -0
  112. package/dist/lib/request-utils/request-scheduler.js +142 -0
  113. package/dist/lib/worker-loader-utils/create-loader-worker.d.ts +7 -0
  114. package/dist/lib/worker-loader-utils/create-loader-worker.d.ts.map +1 -0
  115. package/dist/lib/worker-loader-utils/create-loader-worker.js +97 -0
  116. package/dist/lib/worker-loader-utils/parse-with-worker.d.ts +15 -0
  117. package/dist/lib/worker-loader-utils/parse-with-worker.d.ts.map +1 -0
  118. package/dist/lib/worker-loader-utils/parse-with-worker.js +73 -0
  119. package/dist/types.d.ts +207 -0
  120. package/dist/types.d.ts.map +1 -0
  121. package/dist/types.js +3 -0
  122. package/dist/workers/json-worker.d.ts +2 -0
  123. package/dist/workers/json-worker.d.ts.map +1 -0
  124. package/dist/workers/json-worker.js +5 -0
  125. package/package.json +5 -8
  126. package/src/lib/worker-loader-utils/parse-with-worker.ts +6 -5
@@ -0,0 +1,22 @@
1
+ import type { LoaderWithParser } from './types';
2
+ /**
3
+ * A JSON Micro loader (minimal bundle size)
4
+ * Alternative to `@loaders.gl/json`
5
+ */
6
+ export declare const JSONLoader: {
7
+ name: string;
8
+ id: string;
9
+ module: string;
10
+ version: any;
11
+ extensions: string[];
12
+ mimeTypes: string[];
13
+ category: string;
14
+ text: boolean;
15
+ parseTextSync: typeof parseTextSync;
16
+ parse: (arrayBuffer: any) => Promise<any>;
17
+ options: {};
18
+ };
19
+ declare function parseTextSync(text: any): any;
20
+ export declare const _typecheckJSONLoader: LoaderWithParser;
21
+ export {};
22
+ //# sourceMappingURL=json-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-loader.d.ts","sourceRoot":"","sources":["../src/json-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,SAAS,CAAC;AAM9C;;;GAGG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;CAYtB,CAAC;AAGF,iBAAS,aAAa,CAAC,IAAI,KAAA,OAE1B;AAED,eAAO,MAAM,oBAAoB,EAAE,gBAA6B,CAAC"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports._typecheckJSONLoader = exports.JSONLoader = void 0;
4
+ // __VERSION__ is injected by babel-plugin-version-inline
5
+ // @ts-ignore TS2304: Cannot find name '__VERSION__'.
6
+ const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
7
+ /**
8
+ * A JSON Micro loader (minimal bundle size)
9
+ * Alternative to `@loaders.gl/json`
10
+ */
11
+ exports.JSONLoader = {
12
+ name: 'JSON',
13
+ id: 'json',
14
+ module: 'json',
15
+ version: VERSION,
16
+ extensions: ['json', 'geojson'],
17
+ mimeTypes: ['application/json'],
18
+ category: 'json',
19
+ text: true,
20
+ parseTextSync,
21
+ parse: async (arrayBuffer) => parseTextSync(new TextDecoder().decode(arrayBuffer)),
22
+ options: {}
23
+ };
24
+ // TODO - deprecated
25
+ function parseTextSync(text) {
26
+ return JSON.parse(text);
27
+ }
28
+ exports._typecheckJSONLoader = exports.JSONLoader;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Convert an object to an array buffer
3
+ */
4
+ export declare function toArrayBuffer(data: any): ArrayBuffer;
5
+ /**
6
+ * compare two binary arrays for equality
7
+ * @param {ArrayBuffer} a
8
+ * @param {ArrayBuffer} b
9
+ * @param {number} byteLength
10
+ */
11
+ export declare function compareArrayBuffers(arrayBuffer1: ArrayBuffer, arrayBuffer2: ArrayBuffer, byteLength?: number): boolean;
12
+ /**
13
+ * Concatenate a sequence of ArrayBuffers
14
+ * @return A concatenated ArrayBuffer
15
+ */
16
+ export declare function concatenateArrayBuffers(...sources: (ArrayBuffer | Uint8Array)[]): ArrayBuffer;
17
+ /**
18
+ * Concatenate arbitrary count of typed arrays
19
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays
20
+ * @param {...*} arrays - list of arrays. All arrays should be the same type
21
+ * @return A concatenated TypedArray
22
+ */
23
+ export declare function concatenateTypedArrays<T>(...typedArrays: T[]): T;
24
+ /**
25
+ * Copy a view of an ArrayBuffer into new ArrayBuffer with byteOffset = 0
26
+ * @param arrayBuffer
27
+ * @param byteOffset
28
+ * @param byteLength
29
+ */
30
+ export declare function sliceArrayBuffer(arrayBuffer: ArrayBuffer, byteOffset: number, byteLength?: number): ArrayBuffer;
31
+ //# sourceMappingURL=array-buffer-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array-buffer-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-utils/array-buffer-utils.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,GAAG,GAAG,WAAW,CA8BpD;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,WAAW,EACzB,YAAY,EAAE,WAAW,EACzB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAaT;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,OAAO,EAAE,CAAC,WAAW,GAAG,UAAU,CAAC,EAAE,GAAG,WAAW,CAqB7F;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,GAAG,WAAW,EAAE,CAAC,EAAE,GAAG,CAAC,CAoBhE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,MAAM,GAClB,WAAW,CAOb"}
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sliceArrayBuffer = exports.concatenateTypedArrays = exports.concatenateArrayBuffers = exports.compareArrayBuffers = exports.toArrayBuffer = void 0;
4
+ const buffer_utils_1 = require("./buffer-utils");
5
+ /**
6
+ * Convert an object to an array buffer
7
+ */
8
+ function toArrayBuffer(data) {
9
+ // Note: Should be called first, Buffers can trigger other detections below
10
+ if ((0, buffer_utils_1.isBuffer)(data)) {
11
+ return (0, buffer_utils_1.bufferToArrayBuffer)(data);
12
+ }
13
+ if (data instanceof ArrayBuffer) {
14
+ return data;
15
+ }
16
+ // Careful - Node Buffers look like Uint8Arrays (keep after isBuffer)
17
+ if (ArrayBuffer.isView(data)) {
18
+ if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
19
+ return data.buffer;
20
+ }
21
+ return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
22
+ }
23
+ if (typeof data === 'string') {
24
+ const text = data;
25
+ const uint8Array = new TextEncoder().encode(text);
26
+ return uint8Array.buffer;
27
+ }
28
+ // HACK to support Blob polyfill
29
+ if (data && typeof data === 'object' && data._toArrayBuffer) {
30
+ return data._toArrayBuffer();
31
+ }
32
+ throw new Error('toArrayBuffer');
33
+ }
34
+ exports.toArrayBuffer = toArrayBuffer;
35
+ /**
36
+ * compare two binary arrays for equality
37
+ * @param {ArrayBuffer} a
38
+ * @param {ArrayBuffer} b
39
+ * @param {number} byteLength
40
+ */
41
+ function compareArrayBuffers(arrayBuffer1, arrayBuffer2, byteLength) {
42
+ byteLength = byteLength || arrayBuffer1.byteLength;
43
+ if (arrayBuffer1.byteLength < byteLength || arrayBuffer2.byteLength < byteLength) {
44
+ return false;
45
+ }
46
+ const array1 = new Uint8Array(arrayBuffer1);
47
+ const array2 = new Uint8Array(arrayBuffer2);
48
+ for (let i = 0; i < array1.length; ++i) {
49
+ if (array1[i] !== array2[i]) {
50
+ return false;
51
+ }
52
+ }
53
+ return true;
54
+ }
55
+ exports.compareArrayBuffers = compareArrayBuffers;
56
+ /**
57
+ * Concatenate a sequence of ArrayBuffers
58
+ * @return A concatenated ArrayBuffer
59
+ */
60
+ function concatenateArrayBuffers(...sources) {
61
+ // Make sure all inputs are wrapped in typed arrays
62
+ const sourceArrays = sources.map((source2) => source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2);
63
+ // Get length of all inputs
64
+ const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);
65
+ // Allocate array with space for all inputs
66
+ const result = new Uint8Array(byteLength);
67
+ // Copy the subarrays
68
+ let offset = 0;
69
+ for (const sourceArray of sourceArrays) {
70
+ result.set(sourceArray, offset);
71
+ offset += sourceArray.byteLength;
72
+ }
73
+ // We work with ArrayBuffers, discard the typed array wrapper
74
+ return result.buffer;
75
+ }
76
+ exports.concatenateArrayBuffers = concatenateArrayBuffers;
77
+ /**
78
+ * Concatenate arbitrary count of typed arrays
79
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays
80
+ * @param {...*} arrays - list of arrays. All arrays should be the same type
81
+ * @return A concatenated TypedArray
82
+ */
83
+ function concatenateTypedArrays(...typedArrays) {
84
+ // @ts-ignore
85
+ const arrays = typedArrays;
86
+ // @ts-ignore
87
+ const TypedArrayConstructor = (arrays && arrays.length > 1 && arrays[0].constructor) || null;
88
+ if (!TypedArrayConstructor) {
89
+ throw new Error('"concatenateTypedArrays" - incorrect quantity of arguments or arguments have incompatible data types');
90
+ }
91
+ const sumLength = arrays.reduce((acc, value) => acc + value.length, 0);
92
+ // @ts-ignore typescript does not like dynamic constructors
93
+ const result = new TypedArrayConstructor(sumLength);
94
+ let offset = 0;
95
+ for (const array of arrays) {
96
+ result.set(array, offset);
97
+ offset += array.length;
98
+ }
99
+ return result;
100
+ }
101
+ exports.concatenateTypedArrays = concatenateTypedArrays;
102
+ /**
103
+ * Copy a view of an ArrayBuffer into new ArrayBuffer with byteOffset = 0
104
+ * @param arrayBuffer
105
+ * @param byteOffset
106
+ * @param byteLength
107
+ */
108
+ function sliceArrayBuffer(arrayBuffer, byteOffset, byteLength) {
109
+ const subArray = byteLength !== undefined
110
+ ? new Uint8Array(arrayBuffer).subarray(byteOffset, byteOffset + byteLength)
111
+ : new Uint8Array(arrayBuffer).subarray(byteOffset);
112
+ const arrayCopy = new Uint8Array(subArray);
113
+ return arrayCopy.buffer;
114
+ }
115
+ exports.sliceArrayBuffer = sliceArrayBuffer;
@@ -0,0 +1,24 @@
1
+ import { TypedArray } from '../../types';
2
+ /**
3
+ * Copy sourceBuffer to dataView with some padding
4
+ *
5
+ * @param {DataView | null} dataView - destination data container. If null - only new offset is calculated
6
+ * @param {number} byteOffset - destination byte offset to copy to
7
+ * @param {Array | TypedArray} sourceBuffer - source data buffer
8
+ * @param {number} padding - pad the resulting array to multiple of "padding" bytes. Additional bytes are filled with 0x20 (ASCII space)
9
+ *
10
+ * @return new byteOffset of resulting dataView
11
+ */
12
+ export declare function copyPaddedArrayBufferToDataView(dataView: DataView | null, byteOffset: number, sourceBuffer: TypedArray, padding: number): number;
13
+ /**
14
+ * Copy string to dataView with some padding
15
+ *
16
+ * @param {DataView | null} dataView - destination data container. If null - only new offset is calculated
17
+ * @param {number} byteOffset - destination byte offset to copy to
18
+ * @param {string} string - source string
19
+ * @param {number} padding - pad the resulting array to multiple of "padding" bytes. Additional bytes are filled with 0x20 (ASCII space)
20
+ *
21
+ * @return new byteOffset of resulting dataView
22
+ */
23
+ export declare function copyPaddedStringToDataView(dataView: DataView | null, byteOffset: number, string: string, padding: number): number;
24
+ //# sourceMappingURL=binary-copy-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binary-copy-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-utils/binary-copy-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AAGvC;;;;;;;;;GASG;AACH,wBAAgB,+BAA+B,CAC7C,QAAQ,EAAE,QAAQ,GAAG,IAAI,EACzB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,UAAU,EACxB,OAAO,EAAE,MAAM,UAuBhB;AAED;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,QAAQ,GAAG,IAAI,EACzB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GACd,MAAM,CASR"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.copyPaddedStringToDataView = exports.copyPaddedArrayBufferToDataView = void 0;
4
+ const memory_copy_utils_1 = require("./memory-copy-utils");
5
+ /**
6
+ * Copy sourceBuffer to dataView with some padding
7
+ *
8
+ * @param {DataView | null} dataView - destination data container. If null - only new offset is calculated
9
+ * @param {number} byteOffset - destination byte offset to copy to
10
+ * @param {Array | TypedArray} sourceBuffer - source data buffer
11
+ * @param {number} padding - pad the resulting array to multiple of "padding" bytes. Additional bytes are filled with 0x20 (ASCII space)
12
+ *
13
+ * @return new byteOffset of resulting dataView
14
+ */
15
+ function copyPaddedArrayBufferToDataView(dataView, byteOffset, sourceBuffer, padding) {
16
+ const paddedLength = (0, memory_copy_utils_1.padToNBytes)(sourceBuffer.byteLength, padding);
17
+ const padLength = paddedLength - sourceBuffer.byteLength;
18
+ if (dataView) {
19
+ // Copy array
20
+ const targetArray = new Uint8Array(dataView.buffer, dataView.byteOffset + byteOffset, sourceBuffer.byteLength);
21
+ const sourceArray = new Uint8Array(sourceBuffer);
22
+ targetArray.set(sourceArray);
23
+ // Add PADDING
24
+ for (let i = 0; i < padLength; ++i) {
25
+ // json chunk is padded with spaces (ASCII 0x20)
26
+ dataView.setUint8(byteOffset + sourceBuffer.byteLength + i, 0x20);
27
+ }
28
+ }
29
+ byteOffset += paddedLength;
30
+ return byteOffset;
31
+ }
32
+ exports.copyPaddedArrayBufferToDataView = copyPaddedArrayBufferToDataView;
33
+ /**
34
+ * Copy string to dataView with some padding
35
+ *
36
+ * @param {DataView | null} dataView - destination data container. If null - only new offset is calculated
37
+ * @param {number} byteOffset - destination byte offset to copy to
38
+ * @param {string} string - source string
39
+ * @param {number} padding - pad the resulting array to multiple of "padding" bytes. Additional bytes are filled with 0x20 (ASCII space)
40
+ *
41
+ * @return new byteOffset of resulting dataView
42
+ */
43
+ function copyPaddedStringToDataView(dataView, byteOffset, string, padding) {
44
+ const textEncoder = new TextEncoder();
45
+ // PERFORMANCE IDEA: We encode twice, once to get size and once to store
46
+ // PERFORMANCE IDEA: Use TextEncoder.encodeInto() to avoid temporary copy
47
+ const stringBuffer = textEncoder.encode(string);
48
+ byteOffset = copyPaddedArrayBufferToDataView(dataView, byteOffset, stringBuffer, padding);
49
+ return byteOffset;
50
+ }
51
+ exports.copyPaddedStringToDataView = copyPaddedStringToDataView;
@@ -0,0 +1,16 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * Check for Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)
4
+ */
5
+ export declare function isBuffer(value: any): boolean;
6
+ /**
7
+ * Converts to Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)
8
+ * @todo better data type
9
+ */
10
+ export declare function toBuffer(data: any): Buffer;
11
+ /**
12
+ * Converts Node.js `Buffer` to `ArrayBuffer` (without triggering bundler to include Buffer polyfill on browser)
13
+ * @todo better data type
14
+ */
15
+ export declare function bufferToArrayBuffer(buffer: any): ArrayBuffer;
16
+ //# sourceMappingURL=buffer-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buffer-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-utils/buffer-utils.ts"],"names":[],"mappings":";AAEA;;GAEG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAE5C;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CAE1C;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,GAAG,GAAG,WAAW,CAM5D"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.bufferToArrayBuffer = exports.toBuffer = exports.isBuffer = void 0;
23
+ const node = __importStar(require("../node/buffer"));
24
+ /**
25
+ * Check for Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)
26
+ */
27
+ function isBuffer(value) {
28
+ return value && typeof value === 'object' && value.isBuffer;
29
+ }
30
+ exports.isBuffer = isBuffer;
31
+ /**
32
+ * Converts to Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)
33
+ * @todo better data type
34
+ */
35
+ function toBuffer(data) {
36
+ return node.toBuffer ? node.toBuffer(data) : data;
37
+ }
38
+ exports.toBuffer = toBuffer;
39
+ /**
40
+ * Converts Node.js `Buffer` to `ArrayBuffer` (without triggering bundler to include Buffer polyfill on browser)
41
+ * @todo better data type
42
+ */
43
+ function bufferToArrayBuffer(buffer) {
44
+ if (isBuffer(buffer)) {
45
+ const typedArray = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.length);
46
+ return typedArray.slice().buffer;
47
+ }
48
+ return buffer;
49
+ }
50
+ exports.bufferToArrayBuffer = bufferToArrayBuffer;
@@ -0,0 +1,4 @@
1
+ export declare function padStringToByteAlignment(string: any, byteAlignment: any): string;
2
+ export declare function copyStringToDataView(dataView: any, byteOffset: any, string: any, byteLength: any): any;
3
+ export declare function copyBinaryToDataView(dataView: any, byteOffset: any, binary: any, byteLength: any): any;
4
+ //# sourceMappingURL=encode-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-utils/encode-utils.ts"],"names":[],"mappings":"AAIA,wBAAgB,wBAAwB,CAAC,MAAM,KAAA,EAAE,aAAa,KAAA,UAS7D;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,KAAA,EAAE,UAAU,KAAA,EAAE,MAAM,KAAA,EAAE,UAAU,KAAA,OAO5E;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,KAAA,EAAE,UAAU,KAAA,EAAE,MAAM,KAAA,EAAE,UAAU,KAAA,OAO5E"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ // Note: These were broken out from gltf loader...
3
+ // eslint-disable-next-line complexity
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.copyBinaryToDataView = exports.copyStringToDataView = exports.padStringToByteAlignment = void 0;
6
+ // PERFORMANCE IDEA: No need to copy string twice...
7
+ function padStringToByteAlignment(string, byteAlignment) {
8
+ const length = string.length;
9
+ const paddedLength = Math.ceil(length / byteAlignment) * byteAlignment; // Round up to the required alignment
10
+ const padding = paddedLength - length;
11
+ let whitespace = '';
12
+ for (let i = 0; i < padding; ++i) {
13
+ whitespace += ' ';
14
+ }
15
+ return string + whitespace;
16
+ }
17
+ exports.padStringToByteAlignment = padStringToByteAlignment;
18
+ function copyStringToDataView(dataView, byteOffset, string, byteLength) {
19
+ if (dataView) {
20
+ for (let i = 0; i < byteLength; i++) {
21
+ dataView.setUint8(byteOffset + i, string.charCodeAt(i));
22
+ }
23
+ }
24
+ return byteOffset + byteLength;
25
+ }
26
+ exports.copyStringToDataView = copyStringToDataView;
27
+ function copyBinaryToDataView(dataView, byteOffset, binary, byteLength) {
28
+ if (dataView) {
29
+ for (let i = 0; i < byteLength; i++) {
30
+ dataView.setUint8(byteOffset + i, binary[i]);
31
+ }
32
+ }
33
+ return byteOffset + byteLength;
34
+ }
35
+ exports.copyBinaryToDataView = copyBinaryToDataView;
@@ -0,0 +1,3 @@
1
+ export declare function getFirstCharacters(data: any, length?: number): string;
2
+ export declare function getMagicString(arrayBuffer: ArrayBuffer, byteOffset: number, length: number): string;
3
+ //# sourceMappingURL=get-first-characters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-first-characters.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-utils/get-first-characters.ts"],"names":[],"mappings":"AAAA,wBAAgB,kBAAkB,CAAC,IAAI,KAAA,EAAE,MAAM,SAAI,GAAG,MAAM,CAW3D;AAED,wBAAgB,cAAc,CAC5B,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,MAAM,CAUR"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMagicString = exports.getFirstCharacters = void 0;
4
+ function getFirstCharacters(data, length = 5) {
5
+ if (typeof data === 'string') {
6
+ return data.slice(0, length);
7
+ }
8
+ else if (ArrayBuffer.isView(data)) {
9
+ // Typed Arrays can have offsets into underlying buffer
10
+ return getMagicString(data.buffer, data.byteOffset, length);
11
+ }
12
+ else if (data instanceof ArrayBuffer) {
13
+ const byteOffset = 0;
14
+ return getMagicString(data, byteOffset, length);
15
+ }
16
+ return '';
17
+ }
18
+ exports.getFirstCharacters = getFirstCharacters;
19
+ function getMagicString(arrayBuffer, byteOffset, length) {
20
+ if (arrayBuffer.byteLength <= byteOffset + length) {
21
+ return '';
22
+ }
23
+ const dataView = new DataView(arrayBuffer);
24
+ let magic = '';
25
+ for (let i = 0; i < length; i++) {
26
+ magic += String.fromCharCode(dataView.getUint8(byteOffset + i));
27
+ }
28
+ return magic;
29
+ }
30
+ exports.getMagicString = getMagicString;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Calculate new size of an arrayBuffer to be aligned to an n-byte boundary
3
+ * This function increases `byteLength` by the minimum delta,
4
+ * allowing the total length to be divided by `padding`
5
+ * @param byteLength
6
+ * @param padding
7
+ */
8
+ export declare function padToNBytes(byteLength: number, padding: number): number;
9
+ /**
10
+ * Creates a new Uint8Array based on two different ArrayBuffers
11
+ * @param targetBuffer The first buffer.
12
+ * @param sourceBuffer The second buffer.
13
+ * @return The new ArrayBuffer created out of the two.
14
+ */
15
+ export declare function copyArrayBuffer(targetBuffer: ArrayBuffer, sourceBuffer: ArrayBuffer, byteOffset: number, byteLength?: number): ArrayBuffer;
16
+ /**
17
+ * Copy from source to target at the targetOffset
18
+ *
19
+ * @param source - The data to copy
20
+ * @param target - The destination to copy data into
21
+ * @param targetOffset - The start offset into target to place the copied data
22
+ * @returns the new offset taking into account proper padding
23
+ */
24
+ export declare function copyToArray(source: ArrayBuffer | any, target: any, targetOffset: number): number;
25
+ //# sourceMappingURL=memory-copy-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-copy-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-utils/memory-copy-utils.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAIvE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,YAAY,EAAE,WAAW,EACzB,YAAY,EAAE,WAAW,EACzB,UAAU,EAAE,MAAM,EAClB,UAAU,GAAE,MAAgC,GAC3C,WAAW,CAKb;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,GAAG,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAuBhG"}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.copyToArray = exports.copyArrayBuffer = exports.padToNBytes = void 0;
4
+ const assert_1 = require("../env-utils/assert");
5
+ /**
6
+ * Calculate new size of an arrayBuffer to be aligned to an n-byte boundary
7
+ * This function increases `byteLength` by the minimum delta,
8
+ * allowing the total length to be divided by `padding`
9
+ * @param byteLength
10
+ * @param padding
11
+ */
12
+ function padToNBytes(byteLength, padding) {
13
+ (0, assert_1.assert)(byteLength >= 0); // `Incorrect 'byteLength' value: ${byteLength}`
14
+ (0, assert_1.assert)(padding > 0); // `Incorrect 'padding' value: ${padding}`
15
+ return (byteLength + (padding - 1)) & ~(padding - 1);
16
+ }
17
+ exports.padToNBytes = padToNBytes;
18
+ /**
19
+ * Creates a new Uint8Array based on two different ArrayBuffers
20
+ * @param targetBuffer The first buffer.
21
+ * @param sourceBuffer The second buffer.
22
+ * @return The new ArrayBuffer created out of the two.
23
+ */
24
+ function copyArrayBuffer(targetBuffer, sourceBuffer, byteOffset, byteLength = sourceBuffer.byteLength) {
25
+ const targetArray = new Uint8Array(targetBuffer, byteOffset, byteLength);
26
+ const sourceArray = new Uint8Array(sourceBuffer);
27
+ targetArray.set(sourceArray);
28
+ return targetBuffer;
29
+ }
30
+ exports.copyArrayBuffer = copyArrayBuffer;
31
+ /**
32
+ * Copy from source to target at the targetOffset
33
+ *
34
+ * @param source - The data to copy
35
+ * @param target - The destination to copy data into
36
+ * @param targetOffset - The start offset into target to place the copied data
37
+ * @returns the new offset taking into account proper padding
38
+ */
39
+ function copyToArray(source, target, targetOffset) {
40
+ let sourceArray;
41
+ if (source instanceof ArrayBuffer) {
42
+ sourceArray = new Uint8Array(source);
43
+ }
44
+ else {
45
+ // Pack buffer onto the big target array
46
+ //
47
+ // 'source.data.buffer' could be a view onto a larger buffer.
48
+ // We MUST use this constructor to ensure the byteOffset and byteLength is
49
+ // set to correct values from 'source.data' and not the underlying
50
+ // buffer for target.set() to work properly.
51
+ const srcByteOffset = source.byteOffset;
52
+ const srcByteLength = source.byteLength;
53
+ // In gltf parser it is set as "arrayBuffer" instead of "buffer"
54
+ // https://github.com/visgl/loaders.gl/blob/1e3a82a0a65d7b6a67b1e60633453e5edda2960a/modules/gltf/src/lib/parse-gltf.js#L85
55
+ sourceArray = new Uint8Array(source.buffer || source.arrayBuffer, srcByteOffset, srcByteLength);
56
+ }
57
+ // Pack buffer onto the big target array
58
+ target.set(sourceArray, targetOffset);
59
+ return targetOffset + padToNBytes(sourceArray.byteLength, 4);
60
+ }
61
+ exports.copyToArray = copyToArray;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Throws an `Error` with the optional `message` if `condition` is falsy
3
+ * @note Replacement for the external assert method to reduce bundle size
4
+ */
5
+ export declare function assert(condition: any, message?: string): void;
6
+ //# sourceMappingURL=assert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../../src/lib/env-utils/assert.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,MAAM,CAAC,SAAS,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAI7D"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assert = void 0;
4
+ /**
5
+ * Throws an `Error` with the optional `message` if `condition` is falsy
6
+ * @note Replacement for the external assert method to reduce bundle size
7
+ */
8
+ function assert(condition, message) {
9
+ if (!condition) {
10
+ throw new Error(message || 'loader assertion failed.');
11
+ }
12
+ }
13
+ exports.assert = assert;
@@ -0,0 +1,15 @@
1
+ declare type obj = {
2
+ [key: string]: any;
3
+ };
4
+ declare const self_: obj;
5
+ declare const window_: obj;
6
+ declare const global_: obj;
7
+ declare const document_: obj;
8
+ export { self_ as self, window_ as window, global_ as global, document_ as document };
9
+ /** true if running in a browser */
10
+ export declare const isBrowser: boolean;
11
+ /** true if running in a worker thread */
12
+ export declare const isWorker: boolean;
13
+ /** Major Node version (as a number) */
14
+ export declare const nodeVersion: number;
15
+ //# sourceMappingURL=globals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globals.d.ts","sourceRoot":"","sources":["../../../src/lib/env-utils/globals.ts"],"names":[],"mappings":"AAWA,aAAK,GAAG,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAC,CAAC;AAChC,QAAA,MAAM,KAAK,EAAE,GAA4D,CAAC;AAC1E,QAAA,MAAM,OAAO,EAAE,GAA4D,CAAC;AAC5E,QAAA,MAAM,OAAO,EAAE,GAA4D,CAAC;AAC5E,QAAA,MAAM,SAAS,EAAE,GAA4B,CAAC;AAE9C,OAAO,EAAC,KAAK,IAAI,IAAI,EAAE,OAAO,IAAI,MAAM,EAAE,OAAO,IAAI,MAAM,EAAE,SAAS,IAAI,QAAQ,EAAC,CAAC;AAEpF,mCAAmC;AACnC,eAAO,MAAM,SAAS,EAAE,OAE2E,CAAC;AAEpG,yCAAyC;AACzC,eAAO,MAAM,QAAQ,EAAE,OAA6C,CAAC;AAKrE,uCAAuC;AACvC,eAAO,MAAM,WAAW,EAAE,MAAiD,CAAC"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ // Purpose: include this in your module to avoid
3
+ // dependencies on micro modules like 'global' and 'is-browser';
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.nodeVersion = exports.isWorker = exports.isBrowser = exports.document = exports.global = exports.window = exports.self = void 0;
6
+ /* eslint-disable no-restricted-globals */
7
+ const globals = {
8
+ self: typeof self !== 'undefined' && self,
9
+ window: typeof window !== 'undefined' && window,
10
+ global: typeof global !== 'undefined' && global,
11
+ document: typeof document !== 'undefined' && document
12
+ };
13
+ const self_ = globals.self || globals.window || globals.global || {};
14
+ exports.self = self_;
15
+ const window_ = globals.window || globals.self || globals.global || {};
16
+ exports.window = window_;
17
+ const global_ = globals.global || globals.self || globals.window || {};
18
+ exports.global = global_;
19
+ const document_ = globals.document || {};
20
+ exports.document = document_;
21
+ /** true if running in a browser */
22
+ exports.isBrowser =
23
+ // @ts-ignore process does not exist on browser
24
+ Boolean(typeof process !== 'object' || String(process) !== '[object process]' || process.browser);
25
+ /** true if running in a worker thread */
26
+ exports.isWorker = typeof importScripts === 'function';
27
+ // Extract node major version
28
+ const matches = typeof process !== 'undefined' && process.version && /v([0-9]*)/.exec(process.version);
29
+ /** Major Node version (as a number) */
30
+ exports.nodeVersion = (matches && parseFloat(matches[1])) || 0;
@@ -0,0 +1,38 @@
1
+ /// <reference types="node" />
2
+ import * as fs from '../node/fs';
3
+ import { IFileSystem, IRandomAccessReadFileSystem } from '../../types';
4
+ declare type Stat = {
5
+ size: number;
6
+ isDirectory: () => boolean;
7
+ info?: fs.Stats;
8
+ };
9
+ declare type ReadOptions = {
10
+ buffer?: Buffer;
11
+ offset?: number;
12
+ length?: number;
13
+ position?: number;
14
+ };
15
+ /**
16
+ * FileSystem pass-through for Node.js
17
+ * Compatible with BrowserFileSystem.
18
+ * @param options
19
+ */
20
+ export default class NodeFileSystem implements IFileSystem, IRandomAccessReadFileSystem {
21
+ constructor(options: {
22
+ [key: string]: any;
23
+ });
24
+ readdir(dirname?: string, options?: {}): Promise<any[]>;
25
+ stat(path: string, options?: {}): Promise<Stat>;
26
+ fetch(path: string, options: {
27
+ [key: string]: any;
28
+ }): Promise<any>;
29
+ open(path: string, flags: string | number, mode?: any): Promise<number>;
30
+ close(fd: number): Promise<void>;
31
+ fstat(fd: number): Promise<Stat>;
32
+ read(fd: number, { buffer, offset, length, position }: ReadOptions): Promise<{
33
+ bytesRead: number;
34
+ buffer: Buffer;
35
+ }>;
36
+ }
37
+ export {};
38
+ //# sourceMappingURL=node-filesystem.d.ts.map