@loaders.gl/core 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.
- package/dist/core-addons/write-file-browser.js +62 -1
- package/dist/dist.dev.js +366 -332
- package/dist/dist.min.js +15 -0
- package/dist/index.cjs +55 -68
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +20 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -1
- package/dist/iterators/batch-iterators/timed-batch-iterator.js +18 -13
- package/dist/iterators/make-iterator/make-array-buffer-iterator.d.ts +1 -1
- package/dist/iterators/make-iterator/make-array-buffer-iterator.d.ts.map +1 -1
- package/dist/iterators/make-iterator/make-array-buffer-iterator.js +21 -15
- package/dist/iterators/make-iterator/make-blob-iterator.d.ts +1 -1
- package/dist/iterators/make-iterator/make-blob-iterator.d.ts.map +1 -1
- package/dist/iterators/make-iterator/make-blob-iterator.js +18 -10
- package/dist/iterators/make-iterator/make-iterator.d.ts +1 -1
- package/dist/iterators/make-iterator/make-iterator.d.ts.map +1 -1
- package/dist/iterators/make-iterator/make-iterator.js +29 -18
- package/dist/iterators/make-iterator/make-stream-iterator.js +86 -23
- package/dist/iterators/make-iterator/make-string-iterator.d.ts +1 -1
- package/dist/iterators/make-iterator/make-string-iterator.d.ts.map +1 -1
- package/dist/iterators/make-iterator/make-string-iterator.js +20 -10
- package/dist/iterators/make-stream/make-stream.js +47 -29
- package/dist/javascript-utils/is-type.js +25 -19
- package/dist/lib/api/encode-table.js +40 -35
- package/dist/lib/api/encode.js +112 -73
- package/dist/lib/api/load-in-batches.js +35 -21
- package/dist/lib/api/load.js +35 -20
- package/dist/lib/api/loader-options.d.ts +2 -2
- package/dist/lib/api/loader-options.d.ts.map +1 -1
- package/dist/lib/api/loader-options.js +3 -1
- package/dist/lib/api/parse-in-batches.js +105 -69
- package/dist/lib/api/parse-sync.js +42 -33
- package/dist/lib/api/parse.js +73 -61
- package/dist/lib/api/register-loaders.js +23 -14
- package/dist/lib/api/select-loader.js +216 -163
- package/dist/lib/common.js +3 -1
- package/dist/lib/fetch/fetch-error-message.js +17 -12
- package/dist/lib/fetch/fetch-file.js +26 -15
- package/dist/lib/fetch/read-array-buffer.js +30 -15
- package/dist/lib/filesystems/browser-filesystem.js +126 -69
- package/dist/lib/filesystems/read-array-buffer.js +14 -6
- package/dist/lib/init.js +12 -6
- package/dist/lib/loader-utils/check-errors.js +37 -16
- package/dist/lib/loader-utils/get-data.js +110 -88
- package/dist/lib/loader-utils/get-fetch-function.js +24 -13
- package/dist/lib/loader-utils/loader-context.js +50 -31
- package/dist/lib/loader-utils/loggers.js +34 -44
- package/dist/lib/loader-utils/normalize-loader.js +45 -32
- package/dist/lib/loader-utils/option-defaults.js +38 -34
- package/dist/lib/loader-utils/option-utils.d.ts.map +1 -1
- package/dist/lib/loader-utils/option-utils.js +133 -80
- package/dist/lib/progress/fetch-progress.js +54 -47
- package/dist/lib/utils/log.js +4 -4
- package/dist/lib/utils/mime-type-utils.js +34 -11
- package/dist/lib/utils/resource-utils.js +77 -45
- package/dist/lib/utils/response-utils.js +97 -74
- package/dist/lib/utils/url-utils.js +6 -4
- package/dist/null-loader.js +43 -29
- package/dist/workers/null-worker-node.js +3 -1
- package/dist/workers/null-worker.js +3 -1
- package/package.json +7 -7
- package/src/lib/loader-utils/option-utils.ts +3 -1
- package/dist/core-addons/README.md +0 -1
- package/dist/core-addons/write-file-browser.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/iterators/batch-iterators/timed-batch-iterator.js.map +0 -1
- package/dist/iterators/make-iterator/make-array-buffer-iterator.js.map +0 -1
- package/dist/iterators/make-iterator/make-blob-iterator.js.map +0 -1
- package/dist/iterators/make-iterator/make-iterator.js.map +0 -1
- package/dist/iterators/make-iterator/make-stream-iterator.js.map +0 -1
- package/dist/iterators/make-iterator/make-string-iterator.js.map +0 -1
- package/dist/iterators/make-stream/make-stream.js.map +0 -1
- package/dist/javascript-utils/is-type.js.map +0 -1
- package/dist/lib/api/encode-table.js.map +0 -1
- package/dist/lib/api/encode.js.map +0 -1
- package/dist/lib/api/load-in-batches.js.map +0 -1
- package/dist/lib/api/load.js.map +0 -1
- package/dist/lib/api/loader-options.js.map +0 -1
- package/dist/lib/api/parse-in-batches.js.map +0 -1
- package/dist/lib/api/parse-sync.js.map +0 -1
- package/dist/lib/api/parse.js.map +0 -1
- package/dist/lib/api/register-loaders.js.map +0 -1
- package/dist/lib/api/select-loader.js.map +0 -1
- package/dist/lib/common.js.map +0 -1
- package/dist/lib/fetch/fetch-error-message.js.map +0 -1
- package/dist/lib/fetch/fetch-file.js.map +0 -1
- package/dist/lib/fetch/read-array-buffer.js.map +0 -1
- package/dist/lib/filesystems/browser-filesystem.js.map +0 -1
- package/dist/lib/filesystems/read-array-buffer.js.map +0 -1
- package/dist/lib/init.js.map +0 -1
- package/dist/lib/loader-utils/check-errors.js.map +0 -1
- package/dist/lib/loader-utils/get-data.js.map +0 -1
- package/dist/lib/loader-utils/get-fetch-function.js.map +0 -1
- package/dist/lib/loader-utils/loader-context.js.map +0 -1
- package/dist/lib/loader-utils/loggers.js.map +0 -1
- package/dist/lib/loader-utils/normalize-loader.js.map +0 -1
- package/dist/lib/loader-utils/option-defaults.js.map +0 -1
- package/dist/lib/loader-utils/option-utils.js.map +0 -1
- package/dist/lib/progress/fetch-progress.js.map +0 -1
- package/dist/lib/utils/log.js.map +0 -1
- package/dist/lib/utils/mime-type-utils.js.map +0 -1
- package/dist/lib/utils/resource-utils.js.map +0 -1
- package/dist/lib/utils/response-utils.js.map +0 -1
- package/dist/lib/utils/url-utils.js.map +0 -1
- package/dist/null-loader.js.map +0 -1
- package/dist/workers/null-worker-node.js.map +0 -1
- package/dist/workers/null-worker.js.map +0 -1
|
@@ -1,38 +1,57 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { getFetchFunction } from "./get-fetch-function.js";
|
|
2
5
|
import { extractQueryString, stripQueryString } from "../utils/url-utils.js";
|
|
3
6
|
import { path } from '@loaders.gl/loader-utils';
|
|
7
|
+
/**
|
|
8
|
+
* "sub" loaders invoked by other loaders get a "context" injected on `this`
|
|
9
|
+
* The context will inject core methods like `parse` and contain information
|
|
10
|
+
* about loaders and options passed in to the top-level `parse` call.
|
|
11
|
+
*
|
|
12
|
+
* @param context
|
|
13
|
+
* @param options
|
|
14
|
+
* @param previousContext
|
|
15
|
+
*/
|
|
4
16
|
export function getLoaderContext(context, options, parentContext) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
// For recursive calls, we already have a context
|
|
18
|
+
// TODO - add any additional loaders to context?
|
|
19
|
+
if (parentContext) {
|
|
20
|
+
return parentContext;
|
|
21
|
+
}
|
|
22
|
+
const newContext = {
|
|
23
|
+
fetch: getFetchFunction(options, context),
|
|
24
|
+
...context
|
|
25
|
+
};
|
|
26
|
+
// Parse URLs so that subloaders can easily generate correct strings
|
|
27
|
+
if (newContext.url) {
|
|
28
|
+
const baseUrl = stripQueryString(newContext.url);
|
|
29
|
+
newContext.baseUrl = baseUrl;
|
|
30
|
+
newContext.queryString = extractQueryString(newContext.url);
|
|
31
|
+
newContext.filename = path.filename(baseUrl);
|
|
32
|
+
newContext.baseUrl = path.dirname(baseUrl);
|
|
33
|
+
}
|
|
34
|
+
// Recursive loading does not use single loader
|
|
35
|
+
if (!Array.isArray(newContext.loaders)) {
|
|
36
|
+
newContext.loaders = null;
|
|
37
|
+
}
|
|
38
|
+
return newContext;
|
|
23
39
|
}
|
|
40
|
+
// eslint-disable-next-line complexity
|
|
24
41
|
export function getLoadersFromContext(loaders, context) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
candidateLoaders
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
// A single loader (non-array) indicates no selection desired. Force select.
|
|
43
|
+
if (loaders && !Array.isArray(loaders)) {
|
|
44
|
+
return loaders;
|
|
45
|
+
}
|
|
46
|
+
// Create a merged list
|
|
47
|
+
let candidateLoaders;
|
|
48
|
+
if (loaders) {
|
|
49
|
+
candidateLoaders = Array.isArray(loaders) ? loaders : [loaders];
|
|
50
|
+
}
|
|
51
|
+
if (context && context.loaders) {
|
|
52
|
+
const contextLoaders = Array.isArray(context.loaders) ? context.loaders : [context.loaders];
|
|
53
|
+
candidateLoaders = candidateLoaders ? [...candidateLoaders, ...contextLoaders] : contextLoaders;
|
|
54
|
+
}
|
|
55
|
+
// If no loaders, return null to look in globally registered loaders
|
|
56
|
+
return candidateLoaders && candidateLoaders.length ? candidateLoaders : undefined;
|
|
37
57
|
}
|
|
38
|
-
//# sourceMappingURL=loader-context.js.map
|
|
@@ -1,49 +1,39 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
// probe.gl Log compatible loggers
|
|
1
5
|
import { Log } from '@probe.gl/log';
|
|
2
|
-
export const probeLog = new Log({
|
|
3
|
-
|
|
4
|
-
});
|
|
6
|
+
export const probeLog = new Log({ id: 'loaders.gl' });
|
|
7
|
+
// Logs nothing
|
|
5
8
|
export class NullLog {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
log() {
|
|
10
|
+
return () => { };
|
|
11
|
+
}
|
|
12
|
+
info() {
|
|
13
|
+
return () => { };
|
|
14
|
+
}
|
|
15
|
+
warn() {
|
|
16
|
+
return () => { };
|
|
17
|
+
}
|
|
18
|
+
error() {
|
|
19
|
+
return () => { };
|
|
20
|
+
}
|
|
18
21
|
}
|
|
22
|
+
// Logs to console
|
|
19
23
|
export class ConsoleLog {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
warn() {
|
|
37
|
-
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
38
|
-
args[_key3] = arguments[_key3];
|
|
39
|
-
}
|
|
40
|
-
return this.console.warn.bind(this.console, ...args);
|
|
41
|
-
}
|
|
42
|
-
error() {
|
|
43
|
-
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
44
|
-
args[_key4] = arguments[_key4];
|
|
45
|
-
}
|
|
46
|
-
return this.console.error.bind(this.console, ...args);
|
|
47
|
-
}
|
|
24
|
+
constructor() {
|
|
25
|
+
this.console = console; // eslint-disable-line
|
|
26
|
+
}
|
|
27
|
+
log(...args) {
|
|
28
|
+
return this.console.log.bind(this.console, ...args);
|
|
29
|
+
}
|
|
30
|
+
info(...args) {
|
|
31
|
+
return this.console.info.bind(this.console, ...args);
|
|
32
|
+
}
|
|
33
|
+
warn(...args) {
|
|
34
|
+
return this.console.warn.bind(this.console, ...args);
|
|
35
|
+
}
|
|
36
|
+
error(...args) {
|
|
37
|
+
return this.console.error.bind(this.console, ...args);
|
|
38
|
+
}
|
|
48
39
|
}
|
|
49
|
-
//# sourceMappingURL=loggers.js.map
|
|
@@ -1,37 +1,50 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { assert } from '@loaders.gl/loader-utils';
|
|
2
5
|
export function isLoaderObject(loader) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
if (!loader) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
if (Array.isArray(loader)) {
|
|
10
|
+
loader = loader[0];
|
|
11
|
+
}
|
|
12
|
+
const hasExtensions = Array.isArray(loader?.extensions);
|
|
13
|
+
/* Now handled by types and worker loaders do not have these
|
|
14
|
+
let hasParser =
|
|
15
|
+
loader.parseTextSync ||
|
|
16
|
+
loader.parseSync ||
|
|
17
|
+
loader.parse ||
|
|
18
|
+
loader.parseStream || // TODO Remove, Replace with parseInBatches
|
|
19
|
+
loader.parseInBatches;
|
|
20
|
+
*/
|
|
21
|
+
return hasExtensions;
|
|
12
22
|
}
|
|
13
23
|
export function normalizeLoader(loader) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
loader
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
// This error is fairly easy to trigger by mixing up import statements etc
|
|
25
|
+
// So we make an exception and add a developer error message for this case
|
|
26
|
+
// To help new users from getting stuck here
|
|
27
|
+
assert(loader, 'null loader');
|
|
28
|
+
assert(isLoaderObject(loader), 'invalid loader');
|
|
29
|
+
// NORMALIZE [LOADER, OPTIONS] => LOADER
|
|
30
|
+
// If [loader, options], create a new loaders object with options merged in
|
|
31
|
+
let options;
|
|
32
|
+
if (Array.isArray(loader)) {
|
|
33
|
+
options = loader[1];
|
|
34
|
+
loader = loader[0];
|
|
35
|
+
loader = {
|
|
36
|
+
...loader,
|
|
37
|
+
options: { ...loader.options, ...options }
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// NORMALIZE text and binary flags
|
|
41
|
+
// Ensure at least one of text/binary flags are properly set
|
|
42
|
+
// @ts-expect-error
|
|
43
|
+
if (loader?.parseTextSync || loader?.parseText) {
|
|
44
|
+
loader.text = true;
|
|
45
|
+
}
|
|
46
|
+
if (!loader.text) {
|
|
47
|
+
loader.binary = true;
|
|
48
|
+
}
|
|
49
|
+
return loader;
|
|
36
50
|
}
|
|
37
|
-
//# sourceMappingURL=normalize-loader.js.map
|
|
@@ -1,40 +1,44 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { isBrowser } from '@loaders.gl/loader-utils';
|
|
2
5
|
import { ConsoleLog } from "./loggers.js";
|
|
3
6
|
export const DEFAULT_LOADER_OPTIONS = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
7
|
+
// baseUri
|
|
8
|
+
fetch: null,
|
|
9
|
+
mimeType: undefined,
|
|
10
|
+
nothrow: false,
|
|
11
|
+
log: new ConsoleLog(), // A probe.gl compatible (`log.log()()` syntax) that just logs to console
|
|
12
|
+
useLocalLibraries: false,
|
|
13
|
+
CDN: 'https://unpkg.com/@loaders.gl',
|
|
14
|
+
worker: true, // By default, use worker if provided by loader.
|
|
15
|
+
maxConcurrency: 3, // How many worker instances should be created for each loader.
|
|
16
|
+
maxMobileConcurrency: 1, // How many worker instances should be created for each loader on mobile devices.
|
|
17
|
+
reuseWorkers: isBrowser, // By default reuse workers in browser (Node.js refuses to terminate if browsers are running)
|
|
18
|
+
_nodeWorkers: false, // By default do not support node workers
|
|
19
|
+
_workerType: '', // 'test' to use locally generated workers
|
|
20
|
+
limit: 0,
|
|
21
|
+
_limitMB: 0,
|
|
22
|
+
batchSize: 'auto',
|
|
23
|
+
batchDebounceMs: 0,
|
|
24
|
+
metadata: false, // TODO - currently only implemented for parseInBatches, adds initial metadata batch,
|
|
25
|
+
transforms: []
|
|
22
26
|
};
|
|
23
27
|
export const REMOVED_LOADER_OPTIONS = {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
throws: 'nothrow',
|
|
29
|
+
dataType: '(no longer used)',
|
|
30
|
+
uri: 'baseUri',
|
|
31
|
+
// Warn if fetch options are used on top-level
|
|
32
|
+
method: 'fetch.method',
|
|
33
|
+
headers: 'fetch.headers',
|
|
34
|
+
body: 'fetch.body',
|
|
35
|
+
mode: 'fetch.mode',
|
|
36
|
+
credentials: 'fetch.credentials',
|
|
37
|
+
cache: 'fetch.cache',
|
|
38
|
+
redirect: 'fetch.redirect',
|
|
39
|
+
referrer: 'fetch.referrer',
|
|
40
|
+
referrerPolicy: 'fetch.referrerPolicy',
|
|
41
|
+
integrity: 'fetch.integrity',
|
|
42
|
+
keepalive: 'fetch.keepalive',
|
|
43
|
+
signal: 'fetch.signal'
|
|
39
44
|
};
|
|
40
|
-
//# sourceMappingURL=option-defaults.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"option-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/loader-utils/option-utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAKpE;;GAEG;AACH,KAAK,iBAAiB,GAAG;IACvB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,aAAa,EAAE,aAAa,CAAC;CAC9B,CAAC;AAEF;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,iBAAiB,
|
|
1
|
+
{"version":3,"file":"option-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/loader-utils/option-utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAKpE;;GAEG;AACH,KAAK,iBAAiB,GAAG;IACvB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,aAAa,EAAE,aAAa,CAAC;CAC9B,CAAC;AAEF;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,iBAAiB,CAWxD;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,IAAI,aAAa,CAKtD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAK7D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,aAAa,EACtB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,MAAM,EAAE,EAClB,GAAG,CAAC,EAAE,MAAM,GACX,aAAa,CAMf"}
|
|
@@ -1,106 +1,159 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { isPureObject, isObject } from "../../javascript-utils/is-type.js";
|
|
2
5
|
import { probeLog, NullLog } from "./loggers.js";
|
|
3
6
|
import { DEFAULT_LOADER_OPTIONS, REMOVED_LOADER_OPTIONS } from "./option-defaults.js";
|
|
7
|
+
/**
|
|
8
|
+
* Helper for safely accessing global loaders.gl variables
|
|
9
|
+
* Wraps initialization of global variable in function to defeat overly aggressive tree-shakers
|
|
10
|
+
*/
|
|
4
11
|
export function getGlobalLoaderState() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
globalThis.loaders = globalThis.loaders || {};
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
const { loaders } = globalThis;
|
|
16
|
+
// Add _state object to keep separate from modules added to globalThis.loaders
|
|
17
|
+
if (!loaders._state) {
|
|
18
|
+
loaders._state = {};
|
|
19
|
+
}
|
|
20
|
+
return loaders._state;
|
|
11
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Store global loader options on the global object to increase chances of cross loaders-version interoperability
|
|
24
|
+
* NOTE: This use case is not reliable but can help when testing new versions of loaders.gl with existing frameworks
|
|
25
|
+
* @returns global loader options merged with default loader options
|
|
26
|
+
*/
|
|
12
27
|
export function getGlobalLoaderOptions() {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
...DEFAULT_LOADER_OPTIONS
|
|
16
|
-
|
|
17
|
-
return state.globalOptions;
|
|
28
|
+
const state = getGlobalLoaderState();
|
|
29
|
+
// Ensure all default loader options from this library are mentioned
|
|
30
|
+
state.globalOptions = state.globalOptions || { ...DEFAULT_LOADER_OPTIONS };
|
|
31
|
+
return state.globalOptions;
|
|
18
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Set global loader options
|
|
35
|
+
* @param options
|
|
36
|
+
*/
|
|
19
37
|
export function setGlobalOptions(options) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
38
|
+
const state = getGlobalLoaderState();
|
|
39
|
+
const globalOptions = getGlobalLoaderOptions();
|
|
40
|
+
// @ts-expect-error First param looks incorrect
|
|
41
|
+
state.globalOptions = normalizeOptionsInternal(globalOptions, options);
|
|
23
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Merges options with global opts and loader defaults, also injects baseUri
|
|
45
|
+
* @param options
|
|
46
|
+
* @param loader
|
|
47
|
+
* @param loaders
|
|
48
|
+
* @param url
|
|
49
|
+
*/
|
|
24
50
|
export function normalizeOptions(options, loader, loaders, url) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
51
|
+
loaders = loaders || [];
|
|
52
|
+
loaders = Array.isArray(loaders) ? loaders : [loaders];
|
|
53
|
+
validateOptions(options, loaders);
|
|
54
|
+
return normalizeOptionsInternal(loader, options, url);
|
|
29
55
|
}
|
|
56
|
+
// VALIDATE OPTIONS
|
|
57
|
+
/**
|
|
58
|
+
* Warn for unsupported options
|
|
59
|
+
* @param options
|
|
60
|
+
* @param loaders
|
|
61
|
+
*/
|
|
30
62
|
function validateOptions(options, loaders) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
63
|
+
// Check top level options
|
|
64
|
+
validateOptionsObject(options, null, DEFAULT_LOADER_OPTIONS, REMOVED_LOADER_OPTIONS, loaders);
|
|
65
|
+
for (const loader of loaders) {
|
|
66
|
+
// Get the scoped, loader specific options from the user supplied options
|
|
67
|
+
const idOptions = ((options && options[loader.id]) || {});
|
|
68
|
+
// Get scoped, loader specific default and deprecated options from the selected loader
|
|
69
|
+
const loaderOptions = (loader.options && loader.options[loader.id]) || {};
|
|
70
|
+
const deprecatedOptions = (loader.deprecatedOptions && loader.deprecatedOptions[loader.id]) || {};
|
|
71
|
+
// Validate loader specific options
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
validateOptionsObject(idOptions, loader.id, loaderOptions, deprecatedOptions, loaders);
|
|
74
|
+
}
|
|
38
75
|
}
|
|
76
|
+
// eslint-disable-next-line max-params, complexity
|
|
39
77
|
function validateOptionsObject(options, id, defaultOptions, deprecatedOptions, loaders) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
78
|
+
const loaderName = id || 'Top level';
|
|
79
|
+
const prefix = id ? `${id}.` : '';
|
|
80
|
+
for (const key in options) {
|
|
81
|
+
// If top level option value is an object it could options for a loader, so ignore
|
|
82
|
+
const isSubOptions = !id && isObject(options[key]);
|
|
83
|
+
const isBaseUriOption = key === 'baseUri' && !id;
|
|
84
|
+
const isWorkerUrlOption = key === 'workerUrl' && id;
|
|
85
|
+
// <loader>.workerUrl requires special handling as it is now auto-generated and no longer specified as a default option.
|
|
86
|
+
if (!(key in defaultOptions) && !isBaseUriOption && !isWorkerUrlOption) {
|
|
87
|
+
// Issue deprecation warnings
|
|
88
|
+
if (key in deprecatedOptions) {
|
|
89
|
+
probeLog.warn(`${loaderName} loader option \'${prefix}${key}\' no longer supported, use \'${deprecatedOptions[key]}\'`)();
|
|
90
|
+
}
|
|
91
|
+
else if (!isSubOptions) {
|
|
92
|
+
const suggestion = findSimilarOption(key, loaders);
|
|
93
|
+
probeLog.warn(`${loaderName} loader option \'${prefix}${key}\' not recognized. ${suggestion}`)();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
53
96
|
}
|
|
54
|
-
}
|
|
55
97
|
}
|
|
56
98
|
function findSimilarOption(optionKey, loaders) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
99
|
+
const lowerCaseOptionKey = optionKey.toLowerCase();
|
|
100
|
+
let bestSuggestion = '';
|
|
101
|
+
for (const loader of loaders) {
|
|
102
|
+
for (const key in loader.options) {
|
|
103
|
+
if (optionKey === key) {
|
|
104
|
+
return `Did you mean \'${loader.id}.${key}\'?`;
|
|
105
|
+
}
|
|
106
|
+
const lowerCaseKey = key.toLowerCase();
|
|
107
|
+
const isPartialMatch = lowerCaseOptionKey.startsWith(lowerCaseKey) || lowerCaseKey.startsWith(lowerCaseOptionKey);
|
|
108
|
+
if (isPartialMatch) {
|
|
109
|
+
bestSuggestion = bestSuggestion || `Did you mean \'${loader.id}.${key}\'?`;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
69
112
|
}
|
|
70
|
-
|
|
71
|
-
return bestSuggestion;
|
|
113
|
+
return bestSuggestion;
|
|
72
114
|
}
|
|
73
115
|
function normalizeOptionsInternal(loader, options, url) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return mergedOptions;
|
|
116
|
+
const loaderDefaultOptions = loader.options || {};
|
|
117
|
+
const mergedOptions = { ...loaderDefaultOptions };
|
|
118
|
+
addUrlOptions(mergedOptions, url);
|
|
119
|
+
// LOGGING: options.log can be set to `null` to defeat logging
|
|
120
|
+
if (mergedOptions.log === null) {
|
|
121
|
+
mergedOptions.log = new NullLog();
|
|
122
|
+
}
|
|
123
|
+
mergeNestedFields(mergedOptions, getGlobalLoaderOptions());
|
|
124
|
+
mergeNestedFields(mergedOptions, options);
|
|
125
|
+
return mergedOptions;
|
|
85
126
|
}
|
|
127
|
+
// Merge nested options objects
|
|
86
128
|
function mergeNestedFields(mergedOptions, options) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
129
|
+
for (const key in options) {
|
|
130
|
+
// Check for nested options
|
|
131
|
+
// object in options => either no key in defaultOptions or object in defaultOptions
|
|
132
|
+
if (key in options) {
|
|
133
|
+
const value = options[key];
|
|
134
|
+
if (isPureObject(value) && isPureObject(mergedOptions[key])) {
|
|
135
|
+
mergedOptions[key] = {
|
|
136
|
+
...mergedOptions[key],
|
|
137
|
+
...options[key]
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
mergedOptions[key] = options[key];
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// else: No need to merge nested opts, and the initial merge already copied over the nested options
|
|
98
145
|
}
|
|
99
|
-
}
|
|
100
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Harvest information from the url
|
|
149
|
+
* @deprecated This is mainly there to support a hack in the GLTFLoader
|
|
150
|
+
* TODO - baseUri should be a directory, i.e. remove file component from baseUri
|
|
151
|
+
* TODO - extract extension?
|
|
152
|
+
* TODO - extract query parameters?
|
|
153
|
+
* TODO - should these be injected on context instead of options?
|
|
154
|
+
*/
|
|
101
155
|
function addUrlOptions(options, url) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
156
|
+
if (url && !('baseUri' in options)) {
|
|
157
|
+
options.baseUri = url;
|
|
158
|
+
}
|
|
105
159
|
}
|
|
106
|
-
//# sourceMappingURL=option-utils.js.map
|