@loaders.gl/core 3.3.2 → 3.4.0-alpha.2

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 (52) hide show
  1. package/dist/dist.min.js +242 -186
  2. package/dist/es5/lib/api/encode.js.map +1 -1
  3. package/dist/es5/lib/api/load-in-batches.js +2 -2
  4. package/dist/es5/lib/api/load-in-batches.js.map +1 -1
  5. package/dist/es5/lib/api/load.js +2 -2
  6. package/dist/es5/lib/api/load.js.map +1 -1
  7. package/dist/es5/lib/init.js +1 -1
  8. package/dist/es5/lib/init.js.map +1 -1
  9. package/dist/es5/lib/loader-utils/get-fetch-function.js +31 -0
  10. package/dist/es5/lib/loader-utils/get-fetch-function.js.map +1 -0
  11. package/dist/es5/lib/loader-utils/loader-context.js +2 -2
  12. package/dist/es5/lib/loader-utils/loader-context.js.map +1 -1
  13. package/dist/es5/lib/loader-utils/option-utils.js +20 -43
  14. package/dist/es5/lib/loader-utils/option-utils.js.map +1 -1
  15. package/dist/es5/null-loader.js +1 -1
  16. package/dist/es5/null-loader.js.map +1 -1
  17. package/dist/esm/lib/api/encode.js.map +1 -1
  18. package/dist/esm/lib/api/load-in-batches.js +1 -1
  19. package/dist/esm/lib/api/load-in-batches.js.map +1 -1
  20. package/dist/esm/lib/api/load.js +1 -1
  21. package/dist/esm/lib/api/load.js.map +1 -1
  22. package/dist/esm/lib/init.js +1 -1
  23. package/dist/esm/lib/init.js.map +1 -1
  24. package/dist/esm/lib/loader-utils/get-fetch-function.js +25 -0
  25. package/dist/esm/lib/loader-utils/get-fetch-function.js.map +1 -0
  26. package/dist/esm/lib/loader-utils/loader-context.js +1 -1
  27. package/dist/esm/lib/loader-utils/loader-context.js.map +1 -1
  28. package/dist/esm/lib/loader-utils/option-utils.js +2 -20
  29. package/dist/esm/lib/loader-utils/option-utils.js.map +1 -1
  30. package/dist/esm/null-loader.js +1 -1
  31. package/dist/esm/null-loader.js.map +1 -1
  32. package/dist/lib/api/encode.d.ts +5 -5
  33. package/dist/lib/api/encode.d.ts.map +1 -1
  34. package/dist/lib/api/encode.js +1 -0
  35. package/dist/lib/api/load-in-batches.js +2 -2
  36. package/dist/lib/api/load.d.ts.map +1 -1
  37. package/dist/lib/api/load.js +3 -2
  38. package/dist/lib/loader-utils/get-fetch-function.d.ts +9 -0
  39. package/dist/lib/loader-utils/get-fetch-function.d.ts.map +1 -0
  40. package/dist/lib/loader-utils/get-fetch-function.js +31 -0
  41. package/dist/lib/loader-utils/loader-context.js +2 -2
  42. package/dist/lib/loader-utils/option-utils.d.ts +5 -15
  43. package/dist/lib/loader-utils/option-utils.d.ts.map +1 -1
  44. package/dist/lib/loader-utils/option-utils.js +10 -31
  45. package/dist/null-worker.js +1 -1
  46. package/package.json +5 -5
  47. package/src/lib/api/encode.ts +7 -6
  48. package/src/lib/api/load-in-batches.ts +1 -1
  49. package/src/lib/api/load.ts +3 -2
  50. package/src/lib/loader-utils/get-fetch-function.ts +38 -0
  51. package/src/lib/loader-utils/loader-context.ts +1 -1
  52. package/src/lib/loader-utils/option-utils.ts +17 -44
@@ -1,14 +1,16 @@
1
- import type {Loader, LoaderContext, LoaderOptions} from '@loaders.gl/loader-utils';
1
+ // loaders.gl, MIT license
2
+
3
+ import type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';
2
4
  import {isPureObject, isObject} from '../../javascript-utils/is-type';
3
- import {fetchFile} from '../fetch/fetch-file';
4
5
  import {probeLog, NullLog} from './loggers';
5
6
  import {DEFAULT_LOADER_OPTIONS, REMOVED_LOADER_OPTIONS} from './option-defaults';
7
+
6
8
  /**
7
9
  * Global state for loaders.gl. Stored on `global.loaders._state`
8
10
  */
9
11
  type GlobalLoaderState = {
10
12
  loaderRegistry: Loader[];
11
- globalOptions: {[key: string]: any};
13
+ globalOptions: LoaderOptions;
12
14
  };
13
15
 
14
16
  /**
@@ -31,7 +33,7 @@ export function getGlobalLoaderState(): GlobalLoaderState {
31
33
  * NOTE: This use case is not reliable but can help when testing new versions of loaders.gl with existing frameworks
32
34
  * @returns global loader options merged with default loader options
33
35
  */
34
- export const getGlobalLoaderOptions = () => {
36
+ export const getGlobalLoaderOptions = (): LoaderOptions => {
35
37
  const state = getGlobalLoaderState();
36
38
  // Ensure all default loader options from this library are mentioned
37
39
  state.globalOptions = state.globalOptions || {...DEFAULT_LOADER_OPTIONS};
@@ -42,7 +44,7 @@ export const getGlobalLoaderOptions = () => {
42
44
  * Set global loader options
43
45
  * @param options
44
46
  */
45
- export function setGlobalOptions(options: object): void {
47
+ export function setGlobalOptions(options: LoaderOptions): void {
46
48
  const state = getGlobalLoaderState();
47
49
  const globalOptions = getGlobalLoaderOptions();
48
50
  state.globalOptions = normalizeOptionsInternal(globalOptions, options);
@@ -56,11 +58,11 @@ export function setGlobalOptions(options: object): void {
56
58
  * @param url
57
59
  */
58
60
  export function normalizeOptions(
59
- options: object,
61
+ options: LoaderOptions,
60
62
  loader: Loader,
61
63
  loaders?: Loader[],
62
64
  url?: string
63
- ): object {
65
+ ): LoaderOptions {
64
66
  loaders = loaders || [];
65
67
  loaders = Array.isArray(loaders) ? loaders : [loaders];
66
68
 
@@ -68,38 +70,6 @@ export function normalizeOptions(
68
70
  return normalizeOptionsInternal(loader, options, url);
69
71
  }
70
72
 
71
- /**
72
- * Gets the current fetch function from options and context
73
- * @param options
74
- * @param context
75
- */
76
- export function getFetchFunction(
77
- options?: LoaderOptions,
78
- context?: Omit<LoaderContext, 'fetch'> & Partial<Pick<LoaderContext, 'fetch'>>
79
- ) {
80
- const globalOptions = getGlobalLoaderOptions();
81
-
82
- const fetchOptions = options || globalOptions;
83
-
84
- // options.fetch can be a function
85
- if (typeof fetchOptions.fetch === 'function') {
86
- return fetchOptions.fetch;
87
- }
88
-
89
- // options.fetch can be an options object
90
- if (isObject(fetchOptions.fetch)) {
91
- return (url) => fetchFile(url, fetchOptions);
92
- }
93
-
94
- // else refer to context (from parent loader) if available
95
- if (context?.fetch) {
96
- return context?.fetch;
97
- }
98
-
99
- // else return the default fetch function
100
- return fetchFile;
101
- }
102
-
103
73
  // VALIDATE OPTIONS
104
74
 
105
75
  /**
@@ -214,11 +184,14 @@ function mergeNestedFields(mergedOptions, options) {
214
184
  }
215
185
  }
216
186
 
217
- // Harvest information from the url
218
- // TODO - baseUri should be a directory, i.e. remove file component from baseUri
219
- // TODO - extract extension?
220
- // TODO - extract query parameters?
221
- // TODO - should these be injected on context instead of options?
187
+ /**
188
+ * Harvest information from the url
189
+ * @deprecated This is mainly there to support a hack in the GLTFLoader
190
+ * TODO - baseUri should be a directory, i.e. remove file component from baseUri
191
+ * TODO - extract extension?
192
+ * TODO - extract query parameters?
193
+ * TODO - should these be injected on context instead of options?
194
+ */
222
195
  function addUrlOptions(options, url?: string) {
223
196
  if (url && !('baseUri' in options)) {
224
197
  options.baseUri = url;