@loaders.gl/loader-utils 4.2.0-alpha.4 → 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 (144) hide show
  1. package/dist/index.cjs +66 -84
  2. package/dist/index.cjs.map +7 -0
  3. package/dist/index.d.ts +46 -46
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +18 -1
  6. package/dist/json-loader.d.ts +1 -1
  7. package/dist/json-loader.d.ts.map +1 -1
  8. package/dist/json-loader.js +19 -13
  9. package/dist/lib/binary-utils/array-buffer-utils.js +75 -46
  10. package/dist/lib/binary-utils/dataview-copy-utils.d.ts +1 -1
  11. package/dist/lib/binary-utils/dataview-copy-utils.d.ts.map +1 -1
  12. package/dist/lib/binary-utils/dataview-copy-utils.js +75 -34
  13. package/dist/lib/binary-utils/get-first-characters.js +39 -21
  14. package/dist/lib/binary-utils/memory-conversion-utils.js +38 -23
  15. package/dist/lib/binary-utils/memory-copy-utils.js +49 -20
  16. package/dist/lib/env-utils/assert.js +7 -4
  17. package/dist/lib/env-utils/globals.js +15 -7
  18. package/dist/lib/file-provider/data-view-file.d.ts +1 -1
  19. package/dist/lib/file-provider/data-view-file.d.ts.map +1 -1
  20. package/dist/lib/file-provider/data-view-file.js +58 -29
  21. package/dist/lib/file-provider/file-handle-file.d.ts +1 -1
  22. package/dist/lib/file-provider/file-handle-file.d.ts.map +1 -1
  23. package/dist/lib/file-provider/file-handle-file.js +96 -58
  24. package/dist/lib/file-provider/file-provider.js +8 -3
  25. package/dist/lib/files/blob-file.d.ts +1 -1
  26. package/dist/lib/files/blob-file.d.ts.map +1 -1
  27. package/dist/lib/files/blob-file.js +24 -23
  28. package/dist/lib/files/file.js +3 -1
  29. package/dist/lib/files/http-file.d.ts +1 -1
  30. package/dist/lib/files/http-file.d.ts.map +1 -1
  31. package/dist/lib/files/http-file.js +91 -71
  32. package/dist/lib/files/node-file-facade.d.ts +1 -1
  33. package/dist/lib/files/node-file-facade.d.ts.map +1 -1
  34. package/dist/lib/files/node-file-facade.js +37 -29
  35. package/dist/lib/files/sources.js +150 -1
  36. package/dist/lib/filesystems/filesystem.d.ts +1 -1
  37. package/dist/lib/filesystems/filesystem.d.ts.map +1 -1
  38. package/dist/lib/filesystems/filesystem.js +3 -1
  39. package/dist/lib/filesystems/node-filesystem-facade.d.ts +3 -3
  40. package/dist/lib/filesystems/node-filesystem-facade.d.ts.map +1 -1
  41. package/dist/lib/filesystems/node-filesystem-facade.js +41 -31
  42. package/dist/lib/iterators/async-iteration.js +39 -24
  43. package/dist/lib/iterators/text-iterators.js +46 -39
  44. package/dist/lib/node/buffer.browser.js +15 -3
  45. package/dist/lib/node/buffer.js +30 -16
  46. package/dist/lib/node/fs.browser.js +0 -1
  47. package/dist/lib/node/promisify.js +10 -4
  48. package/dist/lib/node/stream.browser.js +0 -1
  49. package/dist/lib/node/stream.js +4 -1
  50. package/dist/lib/option-utils/merge-loader-options.d.ts +1 -1
  51. package/dist/lib/option-utils/merge-loader-options.d.ts.map +1 -1
  52. package/dist/lib/option-utils/merge-loader-options.js +25 -17
  53. package/dist/lib/parser-utils/parse-json.js +9 -6
  54. package/dist/lib/path-utils/file-aliases.js +29 -13
  55. package/dist/lib/path-utils/get-cwd.js +6 -7
  56. package/dist/lib/path-utils/path.js +149 -105
  57. package/dist/lib/request-utils/request-scheduler.d.ts +2 -1
  58. package/dist/lib/request-utils/request-scheduler.d.ts.map +1 -1
  59. package/dist/lib/request-utils/request-scheduler.js +130 -102
  60. package/dist/lib/sources/data-source.js +48 -38
  61. package/dist/lib/sources/image-source.d.ts +3 -3
  62. package/dist/lib/sources/image-source.d.ts.map +1 -1
  63. package/dist/lib/sources/image-source.js +11 -3
  64. package/dist/lib/sources/image-tile-source.d.ts +3 -3
  65. package/dist/lib/sources/image-tile-source.d.ts.map +1 -1
  66. package/dist/lib/sources/image-tile-source.js +3 -1
  67. package/dist/lib/sources/tile-source-adapter.d.ts +2 -2
  68. package/dist/lib/sources/tile-source-adapter.d.ts.map +1 -1
  69. package/dist/lib/sources/tile-source-adapter.js +43 -36
  70. package/dist/lib/sources/tile-source.js +3 -1
  71. package/dist/lib/sources/utils/image-type.js +0 -1
  72. package/dist/lib/sources/utils/utils.js +31 -17
  73. package/dist/lib/sources/vector-tile-source.d.ts +2 -2
  74. package/dist/lib/sources/vector-tile-source.d.ts.map +1 -1
  75. package/dist/lib/sources/vector-tile-source.js +3 -1
  76. package/dist/lib/worker-loader-utils/create-loader-worker.d.ts +1 -1
  77. package/dist/lib/worker-loader-utils/create-loader-worker.d.ts.map +1 -1
  78. package/dist/lib/worker-loader-utils/create-loader-worker.js +87 -87
  79. package/dist/lib/worker-loader-utils/encode-with-worker.d.ts +1 -1
  80. package/dist/lib/worker-loader-utils/encode-with-worker.d.ts.map +1 -1
  81. package/dist/lib/worker-loader-utils/encode-with-worker.js +13 -8
  82. package/dist/lib/worker-loader-utils/parse-with-worker.d.ts +1 -1
  83. package/dist/lib/worker-loader-utils/parse-with-worker.d.ts.map +1 -1
  84. package/dist/lib/worker-loader-utils/parse-with-worker.js +68 -55
  85. package/dist/loader-types.d.ts +2 -2
  86. package/dist/loader-types.d.ts.map +1 -1
  87. package/dist/loader-types.js +26 -10
  88. package/dist/service-types.d.ts +1 -1
  89. package/dist/service-types.d.ts.map +1 -1
  90. package/dist/service-types.js +3 -1
  91. package/dist/types.js +1 -1
  92. package/dist/workers/json-worker.js +0 -1
  93. package/dist/writer-types.js +3 -1
  94. package/package.json +6 -4
  95. package/src/lib/request-utils/request-scheduler.ts +17 -8
  96. package/dist/index.js.map +0 -1
  97. package/dist/json-loader.js.map +0 -1
  98. package/dist/lib/binary-utils/array-buffer-utils.js.map +0 -1
  99. package/dist/lib/binary-utils/dataview-copy-utils.js.map +0 -1
  100. package/dist/lib/binary-utils/get-first-characters.js.map +0 -1
  101. package/dist/lib/binary-utils/memory-conversion-utils.js.map +0 -1
  102. package/dist/lib/binary-utils/memory-copy-utils.js.map +0 -1
  103. package/dist/lib/env-utils/assert.js.map +0 -1
  104. package/dist/lib/env-utils/globals.js.map +0 -1
  105. package/dist/lib/file-provider/data-view-file.js.map +0 -1
  106. package/dist/lib/file-provider/file-handle-file.js.map +0 -1
  107. package/dist/lib/file-provider/file-provider.js.map +0 -1
  108. package/dist/lib/files/blob-file.js.map +0 -1
  109. package/dist/lib/files/file.js.map +0 -1
  110. package/dist/lib/files/http-file.js.map +0 -1
  111. package/dist/lib/files/node-file-facade.js.map +0 -1
  112. package/dist/lib/files/sources.js.map +0 -1
  113. package/dist/lib/filesystems/filesystem.js.map +0 -1
  114. package/dist/lib/filesystems/node-filesystem-facade.js.map +0 -1
  115. package/dist/lib/iterators/async-iteration.js.map +0 -1
  116. package/dist/lib/iterators/text-iterators.js.map +0 -1
  117. package/dist/lib/node/buffer.browser.js.map +0 -1
  118. package/dist/lib/node/buffer.js.map +0 -1
  119. package/dist/lib/node/fs.browser.js.map +0 -1
  120. package/dist/lib/node/promisify.js.map +0 -1
  121. package/dist/lib/node/stream.browser.js.map +0 -1
  122. package/dist/lib/node/stream.js.map +0 -1
  123. package/dist/lib/option-utils/merge-loader-options.js.map +0 -1
  124. package/dist/lib/parser-utils/parse-json.js.map +0 -1
  125. package/dist/lib/path-utils/file-aliases.js.map +0 -1
  126. package/dist/lib/path-utils/get-cwd.js.map +0 -1
  127. package/dist/lib/path-utils/path.js.map +0 -1
  128. package/dist/lib/request-utils/request-scheduler.js.map +0 -1
  129. package/dist/lib/sources/data-source.js.map +0 -1
  130. package/dist/lib/sources/image-source.js.map +0 -1
  131. package/dist/lib/sources/image-tile-source.js.map +0 -1
  132. package/dist/lib/sources/tile-source-adapter.js.map +0 -1
  133. package/dist/lib/sources/tile-source.js.map +0 -1
  134. package/dist/lib/sources/utils/image-type.js.map +0 -1
  135. package/dist/lib/sources/utils/utils.js.map +0 -1
  136. package/dist/lib/sources/vector-tile-source.js.map +0 -1
  137. package/dist/lib/worker-loader-utils/create-loader-worker.js.map +0 -1
  138. package/dist/lib/worker-loader-utils/encode-with-worker.js.map +0 -1
  139. package/dist/lib/worker-loader-utils/parse-with-worker.js.map +0 -1
  140. package/dist/loader-types.js.map +0 -1
  141. package/dist/service-types.js.map +0 -1
  142. package/dist/types.js.map +0 -1
  143. package/dist/workers/json-worker.js.map +0 -1
  144. package/dist/writer-types.js.map +0 -1
@@ -1,48 +1,89 @@
1
+ // loaders./gl, MIT license
1
2
  import { padToNBytes } from "./memory-copy-utils.js";
3
+ /**
4
+ * Helper function that pads a string with spaces to fit a certain byte alignment
5
+ * @param string
6
+ * @param byteAlignment
7
+ * @returns
8
+ *
9
+ * @todo PERFORMANCE IDEA: No need to copy string twice...
10
+ */
2
11
  export function padStringToByteAlignment(string, byteAlignment) {
3
- const length = string.length;
4
- const paddedLength = Math.ceil(length / byteAlignment) * byteAlignment;
5
- const padding = paddedLength - length;
6
- let whitespace = '';
7
- for (let i = 0; i < padding; ++i) {
8
- whitespace += ' ';
9
- }
10
- return string + whitespace;
12
+ const length = string.length;
13
+ const paddedLength = Math.ceil(length / byteAlignment) * byteAlignment; // Round up to the required alignment
14
+ const padding = paddedLength - length;
15
+ let whitespace = '';
16
+ for (let i = 0; i < padding; ++i) {
17
+ whitespace += ' ';
18
+ }
19
+ return string + whitespace;
11
20
  }
21
+ /**
22
+ *
23
+ * @param dataView
24
+ * @param byteOffset
25
+ * @param string
26
+ * @param byteLength
27
+ * @returns
28
+ */
12
29
  export function copyStringToDataView(dataView, byteOffset, string, byteLength) {
13
- if (dataView) {
14
- for (let i = 0; i < byteLength; i++) {
15
- dataView.setUint8(byteOffset + i, string.charCodeAt(i));
30
+ if (dataView) {
31
+ for (let i = 0; i < byteLength; i++) {
32
+ dataView.setUint8(byteOffset + i, string.charCodeAt(i));
33
+ }
16
34
  }
17
- }
18
- return byteOffset + byteLength;
35
+ return byteOffset + byteLength;
19
36
  }
20
37
  export function copyBinaryToDataView(dataView, byteOffset, binary, byteLength) {
21
- if (dataView) {
22
- for (let i = 0; i < byteLength; i++) {
23
- dataView.setUint8(byteOffset + i, binary[i]);
38
+ if (dataView) {
39
+ for (let i = 0; i < byteLength; i++) {
40
+ dataView.setUint8(byteOffset + i, binary[i]);
41
+ }
24
42
  }
25
- }
26
- return byteOffset + byteLength;
43
+ return byteOffset + byteLength;
27
44
  }
45
+ /**
46
+ * Copy sourceBuffer to dataView with some padding
47
+ *
48
+ * @param dataView - destination data container. If null - only new offset is calculated
49
+ * @param byteOffset - destination byte offset to copy to
50
+ * @param sourceBuffer - source data buffer
51
+ * @param padding - pad the resulting array to multiple of "padding" bytes. Additional bytes are filled with 0x20 (ASCII space)
52
+ *
53
+ * @return new byteOffset of resulting dataView
54
+ */
28
55
  export function copyPaddedArrayBufferToDataView(dataView, byteOffset, sourceBuffer, padding) {
29
- const paddedLength = padToNBytes(sourceBuffer.byteLength, padding);
30
- const padLength = paddedLength - sourceBuffer.byteLength;
31
- if (dataView) {
32
- const targetArray = new Uint8Array(dataView.buffer, dataView.byteOffset + byteOffset, sourceBuffer.byteLength);
33
- const sourceArray = new Uint8Array(sourceBuffer);
34
- targetArray.set(sourceArray);
35
- for (let i = 0; i < padLength; ++i) {
36
- dataView.setUint8(byteOffset + sourceBuffer.byteLength + i, 0x20);
56
+ const paddedLength = padToNBytes(sourceBuffer.byteLength, padding);
57
+ const padLength = paddedLength - sourceBuffer.byteLength;
58
+ if (dataView) {
59
+ // Copy array
60
+ const targetArray = new Uint8Array(dataView.buffer, dataView.byteOffset + byteOffset, sourceBuffer.byteLength);
61
+ const sourceArray = new Uint8Array(sourceBuffer);
62
+ targetArray.set(sourceArray);
63
+ // Add PADDING
64
+ for (let i = 0; i < padLength; ++i) {
65
+ // json chunk is padded with spaces (ASCII 0x20)
66
+ dataView.setUint8(byteOffset + sourceBuffer.byteLength + i, 0x20);
67
+ }
37
68
  }
38
- }
39
- byteOffset += paddedLength;
40
- return byteOffset;
69
+ byteOffset += paddedLength;
70
+ return byteOffset;
41
71
  }
72
+ /**
73
+ * Copy string to dataView with some padding
74
+ *
75
+ * @param {DataView | null} dataView - destination data container. If null - only new offset is calculated
76
+ * @param {number} byteOffset - destination byte offset to copy to
77
+ * @param {string} string - source string
78
+ * @param {number} padding - pad the resulting array to multiple of "padding" bytes. Additional bytes are filled with 0x20 (ASCII space)
79
+ *
80
+ * @return new byteOffset of resulting dataView
81
+ */
42
82
  export function copyPaddedStringToDataView(dataView, byteOffset, string, padding) {
43
- const textEncoder = new TextEncoder();
44
- const stringBuffer = textEncoder.encode(string);
45
- byteOffset = copyPaddedArrayBufferToDataView(dataView, byteOffset, stringBuffer, padding);
46
- return byteOffset;
83
+ const textEncoder = new TextEncoder();
84
+ // PERFORMANCE IDEA: We encode twice, once to get size and once to store
85
+ // PERFORMANCE IDEA: Use TextEncoder.encodeInto() to avoid temporary copy
86
+ const stringBuffer = textEncoder.encode(string);
87
+ byteOffset = copyPaddedArrayBufferToDataView(dataView, byteOffset, stringBuffer, padding);
88
+ return byteOffset;
47
89
  }
48
- //# sourceMappingURL=dataview-copy-utils.js.map
@@ -1,24 +1,42 @@
1
- export function getFirstCharacters(data) {
2
- let length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5;
3
- if (typeof data === 'string') {
4
- return data.slice(0, length);
5
- } else if (ArrayBuffer.isView(data)) {
6
- return getMagicString(data.buffer, data.byteOffset, length);
7
- } else if (data instanceof ArrayBuffer) {
8
- const byteOffset = 0;
9
- return getMagicString(data, byteOffset, length);
10
- }
11
- return '';
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ /**
5
+ * Get the first characters from a binary file (interpret the first bytes as an ASCII string)
6
+ * @param data
7
+ * @param length
8
+ * @returns
9
+ */
10
+ export function getFirstCharacters(data, length = 5) {
11
+ if (typeof data === 'string') {
12
+ return data.slice(0, length);
13
+ }
14
+ else if (ArrayBuffer.isView(data)) {
15
+ // Typed Arrays can have offsets into underlying buffer
16
+ return getMagicString(data.buffer, data.byteOffset, length);
17
+ }
18
+ else if (data instanceof ArrayBuffer) {
19
+ const byteOffset = 0;
20
+ return getMagicString(data, byteOffset, length);
21
+ }
22
+ return '';
12
23
  }
24
+ /**
25
+ * Gets a magic string from a "file"
26
+ * Typically used to check or detect file format
27
+ * @param arrayBuffer
28
+ * @param byteOffset
29
+ * @param length
30
+ * @returns
31
+ */
13
32
  export function getMagicString(arrayBuffer, byteOffset, length) {
14
- if (arrayBuffer.byteLength <= byteOffset + length) {
15
- return '';
16
- }
17
- const dataView = new DataView(arrayBuffer);
18
- let magic = '';
19
- for (let i = 0; i < length; i++) {
20
- magic += String.fromCharCode(dataView.getUint8(byteOffset + i));
21
- }
22
- return magic;
33
+ if (arrayBuffer.byteLength <= byteOffset + length) {
34
+ return '';
35
+ }
36
+ const dataView = new DataView(arrayBuffer);
37
+ let magic = '';
38
+ for (let i = 0; i < length; i++) {
39
+ magic += String.fromCharCode(dataView.getUint8(byteOffset + i));
40
+ }
41
+ return magic;
23
42
  }
24
- //# sourceMappingURL=get-first-characters.js.map
@@ -1,31 +1,46 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
1
4
  import * as node from "../node/buffer.js";
5
+ /**
6
+ * Check for Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)
7
+ */
2
8
  export function isBuffer(value) {
3
- return value && typeof value === 'object' && value.isBuffer;
9
+ return value && typeof value === 'object' && value.isBuffer;
4
10
  }
11
+ /**
12
+ * Converts to Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser)
13
+ * @todo better data type
14
+ */
5
15
  export function toBuffer(data) {
6
- return node.toBuffer ? node.toBuffer(data) : data;
16
+ return node.toBuffer ? node.toBuffer(data) : data;
7
17
  }
18
+ /**
19
+ * Convert an object to an array buffer
20
+ */
8
21
  export function toArrayBuffer(data) {
9
- if (isBuffer(data)) {
10
- return node.toArrayBuffer(data);
11
- }
12
- if (data instanceof ArrayBuffer) {
13
- return data;
14
- }
15
- if (ArrayBuffer.isView(data)) {
16
- if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
17
- return data.buffer;
22
+ // Note: Should be called first, Buffers can trigger other detections below
23
+ if (isBuffer(data)) {
24
+ return node.toArrayBuffer(data);
18
25
  }
19
- return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
20
- }
21
- if (typeof data === 'string') {
22
- const text = data;
23
- const uint8Array = new TextEncoder().encode(text);
24
- return uint8Array.buffer;
25
- }
26
- if (data && typeof data === 'object' && data._toArrayBuffer) {
27
- return data._toArrayBuffer();
28
- }
29
- throw new Error('toArrayBuffer');
26
+ if (data instanceof ArrayBuffer) {
27
+ return data;
28
+ }
29
+ // Careful - Node Buffers look like Uint8Arrays (keep after isBuffer)
30
+ if (ArrayBuffer.isView(data)) {
31
+ if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
32
+ return data.buffer;
33
+ }
34
+ return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
35
+ }
36
+ if (typeof data === 'string') {
37
+ const text = data;
38
+ const uint8Array = new TextEncoder().encode(text);
39
+ return uint8Array.buffer;
40
+ }
41
+ // HACK to support Blob polyfill
42
+ if (data && typeof data === 'object' && data._toArrayBuffer) {
43
+ return data._toArrayBuffer();
44
+ }
45
+ throw new Error('toArrayBuffer');
30
46
  }
31
- //# sourceMappingURL=memory-conversion-utils.js.map
@@ -1,26 +1,55 @@
1
1
  import { assert } from "../env-utils/assert.js";
2
+ /**
3
+ * Calculate new size of an arrayBuffer to be aligned to an n-byte boundary
4
+ * This function increases `byteLength` by the minimum delta,
5
+ * allowing the total length to be divided by `padding`
6
+ * @param byteLength
7
+ * @param padding
8
+ */
2
9
  export function padToNBytes(byteLength, padding) {
3
- assert(byteLength >= 0);
4
- assert(padding > 0);
5
- return byteLength + (padding - 1) & ~(padding - 1);
10
+ assert(byteLength >= 0); // `Incorrect 'byteLength' value: ${byteLength}`
11
+ assert(padding > 0); // `Incorrect 'padding' value: ${padding}`
12
+ return (byteLength + (padding - 1)) & ~(padding - 1);
6
13
  }
7
- export function copyArrayBuffer(targetBuffer, sourceBuffer, byteOffset) {
8
- let byteLength = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : sourceBuffer.byteLength;
9
- const targetArray = new Uint8Array(targetBuffer, byteOffset, byteLength);
10
- const sourceArray = new Uint8Array(sourceBuffer);
11
- targetArray.set(sourceArray);
12
- return targetBuffer;
14
+ /**
15
+ * Creates a new Uint8Array based on two different ArrayBuffers
16
+ * @param targetBuffer The first buffer.
17
+ * @param sourceBuffer The second buffer.
18
+ * @return The new ArrayBuffer created out of the two.
19
+ */
20
+ export function copyArrayBuffer(targetBuffer, sourceBuffer, byteOffset, byteLength = sourceBuffer.byteLength) {
21
+ const targetArray = new Uint8Array(targetBuffer, byteOffset, byteLength);
22
+ const sourceArray = new Uint8Array(sourceBuffer);
23
+ targetArray.set(sourceArray);
24
+ return targetBuffer;
13
25
  }
26
+ /**
27
+ * Copy from source to target at the targetOffset
28
+ *
29
+ * @param source - The data to copy
30
+ * @param target - The destination to copy data into
31
+ * @param targetOffset - The start offset into target to place the copied data
32
+ * @returns the new offset taking into account proper padding
33
+ */
14
34
  export function copyToArray(source, target, targetOffset) {
15
- let sourceArray;
16
- if (source instanceof ArrayBuffer) {
17
- sourceArray = new Uint8Array(source);
18
- } else {
19
- const srcByteOffset = source.byteOffset;
20
- const srcByteLength = source.byteLength;
21
- sourceArray = new Uint8Array(source.buffer || source.arrayBuffer, srcByteOffset, srcByteLength);
22
- }
23
- target.set(sourceArray, targetOffset);
24
- return targetOffset + padToNBytes(sourceArray.byteLength, 4);
35
+ let sourceArray;
36
+ if (source instanceof ArrayBuffer) {
37
+ sourceArray = new Uint8Array(source);
38
+ }
39
+ else {
40
+ // Pack buffer onto the big target array
41
+ //
42
+ // 'source.data.buffer' could be a view onto a larger buffer.
43
+ // We MUST use this constructor to ensure the byteOffset and byteLength is
44
+ // set to correct values from 'source.data' and not the underlying
45
+ // buffer for target.set() to work properly.
46
+ const srcByteOffset = source.byteOffset;
47
+ const srcByteLength = source.byteLength;
48
+ // In gltf parser it is set as "arrayBuffer" instead of "buffer"
49
+ // https://github.com/visgl/loaders.gl/blob/1e3a82a0a65d7b6a67b1e60633453e5edda2960a/modules/gltf/src/lib/parse-gltf.js#L85
50
+ sourceArray = new Uint8Array(source.buffer || source.arrayBuffer, srcByteOffset, srcByteLength);
51
+ }
52
+ // Pack buffer onto the big target array
53
+ target.set(sourceArray, targetOffset);
54
+ return targetOffset + padToNBytes(sourceArray.byteLength, 4);
25
55
  }
26
- //# sourceMappingURL=memory-copy-utils.js.map
@@ -1,6 +1,9 @@
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
+ */
1
5
  export function assert(condition, message) {
2
- if (!condition) {
3
- throw new Error(message || 'loader assertion failed.');
4
- }
6
+ if (!condition) {
7
+ throw new Error(message || 'loader assertion failed.');
8
+ }
5
9
  }
6
- //# sourceMappingURL=assert.js.map
@@ -1,16 +1,24 @@
1
+ // Purpose: include this in your module to avoid
2
+ // dependencies on micro modules like 'global' and 'is-browser';
3
+ /* eslint-disable no-restricted-globals */
1
4
  const globals = {
2
- self: typeof self !== 'undefined' && self,
3
- window: typeof window !== 'undefined' && window,
4
- global: typeof global !== 'undefined' && global,
5
- document: typeof document !== 'undefined' && document
5
+ self: typeof self !== 'undefined' && self,
6
+ window: typeof window !== 'undefined' && window,
7
+ global: typeof global !== 'undefined' && global,
8
+ document: typeof document !== 'undefined' && document
6
9
  };
7
10
  const self_ = globals.self || globals.window || globals.global || {};
8
11
  const window_ = globals.window || globals.self || globals.global || {};
9
12
  const global_ = globals.global || globals.self || globals.window || {};
10
13
  const document_ = globals.document || {};
11
14
  export { self_ as self, window_ as window, global_ as global, document_ as document };
12
- export const isBrowser = Boolean(typeof process !== 'object' || String(process) !== '[object process]' || process.browser);
15
+ /** true if running in a browser */
16
+ export const isBrowser =
17
+ // @ts-ignore process does not exist on browser
18
+ Boolean(typeof process !== 'object' || String(process) !== '[object process]' || process.browser);
19
+ /** true if running in a worker thread */
13
20
  export const isWorker = typeof importScripts === 'function';
21
+ // Extract node major version
14
22
  const matches = typeof process !== 'undefined' && process.version && /v([0-9]*)/.exec(process.version);
15
- export const nodeVersion = matches && parseFloat(matches[1]) || 0;
16
- //# sourceMappingURL=globals.js.map
23
+ /** Major Node version (as a number) */
24
+ export const nodeVersion = (matches && parseFloat(matches[1])) || 0;
@@ -1,4 +1,4 @@
1
- import { FileProvider } from './file-provider';
1
+ import { FileProvider } from "./file-provider.js";
2
2
  /**
3
3
  * Provides file data using DataView
4
4
  * @deprecated - will be replaced with ReadableFile
@@ -1 +1 @@
1
- {"version":3,"file":"data-view-file.d.ts","sourceRoot":"","sources":["../../../src/lib/file-provider/data-view-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAc7C;;;GAGG;AACH,qBAAa,YAAa,YAAW,YAAY;IAC/C,+CAA+C;IAC/C,OAAO,CAAC,IAAI,CAAW;gBAEX,IAAI,EAAE,QAAQ;IAIpB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAE9B;;;OAGG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI/C;;;OAGG;IACG,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIhD;;;OAGG;IACG,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIhD;;;OAGG;IACG,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAInD;;;;OAIG;IACG,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAIzE,yCAAyC;IACzC,IAAI,MAAM,WAET;CACF"}
1
+ {"version":3,"file":"data-view-file.d.ts","sourceRoot":"","sources":["../../../src/lib/file-provider/data-view-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,2BAAwB;AAc7C;;;GAGG;AACH,qBAAa,YAAa,YAAW,YAAY;IAC/C,+CAA+C;IAC/C,OAAO,CAAC,IAAI,CAAW;gBAEX,IAAI,EAAE,QAAQ;IAIpB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAE9B;;;OAGG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI/C;;;OAGG;IACG,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIhD;;;OAGG;IACG,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIhD;;;OAGG;IACG,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAInD;;;;OAIG;IACG,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAIzE,yCAAyC;IACzC,IAAI,MAAM,WAET;CACF"}
@@ -1,32 +1,61 @@
1
- const toNumber = bigint => {
2
- if (bigint > Number.MAX_SAFE_INTEGER) {
3
- throw new Error('Offset is out of bounds');
4
- }
5
- return Number(bigint);
1
+ /**
2
+ * Checks if bigint can be converted to number and convert it if possible
3
+ * @param bigint bigint to be converted
4
+ * @returns number
5
+ */
6
+ const toNumber = (bigint) => {
7
+ if (bigint > Number.MAX_SAFE_INTEGER) {
8
+ throw new Error('Offset is out of bounds');
9
+ }
10
+ return Number(bigint);
6
11
  };
12
+ /**
13
+ * Provides file data using DataView
14
+ * @deprecated - will be replaced with ReadableFile
15
+ */
7
16
  export class DataViewFile {
8
- constructor(file) {
9
- this.file = void 0;
10
- this.file = file;
11
- }
12
- async destroy() {}
13
- async getUint8(offset) {
14
- return this.file.getUint8(toNumber(offset));
15
- }
16
- async getUint16(offset) {
17
- return this.file.getUint16(toNumber(offset), true);
18
- }
19
- async getUint32(offset) {
20
- return this.file.getUint32(toNumber(offset), true);
21
- }
22
- async getBigUint64(offset) {
23
- return this.file.getBigUint64(toNumber(offset), true);
24
- }
25
- async slice(startOffset, endOffset) {
26
- return this.file.buffer.slice(toNumber(startOffset), toNumber(endOffset));
27
- }
28
- get length() {
29
- return BigInt(this.file.byteLength);
30
- }
17
+ constructor(file) {
18
+ this.file = file;
19
+ }
20
+ async destroy() { }
21
+ /**
22
+ * Gets an unsigned 8-bit integer at the specified byte offset from the start of the file.
23
+ * @param offset The offset, in bytes, from the start of the file where to read the data.
24
+ */
25
+ async getUint8(offset) {
26
+ return this.file.getUint8(toNumber(offset));
27
+ }
28
+ /**
29
+ * Gets an unsigned 16-bit intege at the specified byte offset from the start of the file.
30
+ * @param offset The offset, in bytes, from the start of the file where to read the data.
31
+ */
32
+ async getUint16(offset) {
33
+ return this.file.getUint16(toNumber(offset), true);
34
+ }
35
+ /**
36
+ * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
37
+ * @param offset The offset, in bytes, from the start of the file where to read the data.
38
+ */
39
+ async getUint32(offset) {
40
+ return this.file.getUint32(toNumber(offset), true);
41
+ }
42
+ /**
43
+ * Gets an unsigned 64-bit integer at the specified byte offset from the start of the file.
44
+ * @param offset The offset, in bytes, from the start of the file where to read the data.
45
+ */
46
+ async getBigUint64(offset) {
47
+ return this.file.getBigUint64(toNumber(offset), true);
48
+ }
49
+ /**
50
+ * returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.
51
+ * @param startOffset The offset, in bytes, from the start of the file where to start reading the data.
52
+ * @param endOffset The offset, in bytes, from the start of the file where to end reading the data.
53
+ */
54
+ async slice(startOffset, endOffset) {
55
+ return this.file.buffer.slice(toNumber(startOffset), toNumber(endOffset));
56
+ }
57
+ /** the length (in bytes) of the data. */
58
+ get length() {
59
+ return BigInt(this.file.byteLength);
60
+ }
31
61
  }
32
- //# sourceMappingURL=data-view-file.js.map
@@ -1,4 +1,4 @@
1
- import { FileProvider } from './file-provider';
1
+ import { FileProvider } from "./file-provider.js";
2
2
  /**
3
3
  * Provides file data using node fs library
4
4
  * @deprecated - will be replaced with ReadableFile
@@ -1 +1 @@
1
- {"version":3,"file":"file-handle-file.d.ts","sourceRoot":"","sources":["../../../src/lib/file-provider/file-handle-file.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAG7C;;;GAGG;AACH,qBAAa,cAAe,YAAW,YAAY;IACjD,iDAAiD;IACjD,OAAO,CAAC,IAAI,CAAW;IAEvB,kCAAkC;gBACtB,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,OAAe;IAIjD;;;OAGG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7C;;;OAGG;IACG,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/C,iBAAiB;IACX,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B;;;OAGG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IASxD;;;OAGG;IACG,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IASzD;;;OAGG;IACG,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IASzD;;;OAGG;IACG,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAS5D;;;;OAIG;IACG,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IASzE;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;CACF"}
1
+ {"version":3,"file":"file-handle-file.d.ts","sourceRoot":"","sources":["../../../src/lib/file-provider/file-handle-file.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAAC,2BAAwB;AAG7C;;;GAGG;AACH,qBAAa,cAAe,YAAW,YAAY;IACjD,iDAAiD;IACjD,OAAO,CAAC,IAAI,CAAW;IAEvB,kCAAkC;gBACtB,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,OAAe;IAIjD;;;OAGG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7C;;;OAGG;IACG,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/C,iBAAiB;IACX,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B;;;OAGG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IASxD;;;OAGG;IACG,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IASzD;;;OAGG;IACG,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IASzD;;;OAGG;IACG,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAS5D;;;;OAIG;IACG,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IASzE;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;CACF"}