@loaders.gl/core 4.3.0-alpha.1 → 4.3.0-alpha.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.
- package/dist/dist.dev.js +81 -15
- package/dist/dist.min.js +3 -3
- package/dist/index.cjs +57 -8
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/lib/api/create-data-source.d.ts +13 -0
- package/dist/lib/api/create-data-source.d.ts.map +1 -0
- package/dist/lib/api/create-data-source.js +38 -0
- package/dist/lib/api/select-loader.d.ts.map +1 -1
- package/dist/lib/api/select-loader.js +1 -2
- package/dist/lib/api/select-source.d.ts +8 -0
- package/dist/lib/api/select-source.d.ts.map +1 -0
- package/dist/lib/api/select-source.js +31 -0
- package/dist/lib/init.js +2 -2
- package/dist/null-loader.js +1 -1
- package/dist/null-worker-node.js +1 -1
- package/dist/null-worker.js +1 -1
- package/package.json +5 -5
- package/src/index.ts +4 -0
- package/src/lib/api/create-data-source.ts +50 -0
- package/src/lib/api/select-loader.ts +1 -2
- package/src/lib/api/select-source.ts +44 -0
- package/src/lib/init.ts +1 -1
- package/dist/lib/utils/log.d.ts +0 -3
- package/dist/lib/utils/log.d.ts.map +0 -1
- package/dist/lib/utils/log.js +0 -5
- package/src/lib/utils/log.ts +0 -7
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export { loadInBatches } from "./lib/api/load-in-batches.js";
|
|
|
13
13
|
export { encodeTable, encodeTableAsText, encodeTableInBatches } from "./lib/api/encode-table.js";
|
|
14
14
|
export { encode, encodeSync, encodeInBatches, encodeURLtoURL } from "./lib/api/encode.js";
|
|
15
15
|
export { encodeText, encodeTextSync } from "./lib/api/encode.js";
|
|
16
|
+
export { createDataSource } from "./lib/api/create-data-source.js";
|
|
17
|
+
export { selectSource as _selectSource } from "./lib/api/select-source.js";
|
|
16
18
|
export { setPathPrefix, getPathPrefix, resolvePath } from '@loaders.gl/loader-utils';
|
|
17
19
|
export { RequestScheduler } from '@loaders.gl/loader-utils';
|
|
18
20
|
export { makeIterator } from "./iterators/make-iterator/make-iterator.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,YAAY,EACV,MAAM,EACN,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,MAAM,EACN,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,IAAI,EACJ,UAAU,EACV,sBAAsB,EACvB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAC,SAAS,EAAC,kCAA+B;AACjD,OAAO,EAAC,UAAU,EAAC,mCAAgC;AAEnD,OAAO,EAAC,eAAe,EAAC,yCAAsC;AAK9D,OAAO,EAAC,gBAAgB,EAAE,gBAAgB,EAAC,oCAAiC;AAC5E,OAAO,EAAC,eAAe,EAAC,sCAAmC;AAC3D,OAAO,EAAC,YAAY,EAAE,gBAAgB,EAAC,mCAAgC;AAGvE,OAAO,EAAC,KAAK,EAAC,2BAAwB;AACtC,OAAO,EAAC,SAAS,EAAC,gCAA6B;AAC/C,OAAO,EAAC,cAAc,EAAC,sCAAmC;AAE1D,OAAO,EAAC,IAAI,EAAC,0BAAuB;AACpC,OAAO,EAAC,aAAa,EAAC,qCAAkC;AAGxD,OAAO,EAAC,WAAW,EAAE,iBAAiB,EAAE,oBAAoB,EAAC,kCAA+B;AAC5F,OAAO,EAAC,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,cAAc,EAAC,4BAAyB;AACrF,OAAO,EAAC,UAAU,EAAE,cAAc,EAAC,4BAAyB;AAG5D,OAAO,EAAC,aAAa,EAAE,aAAa,EAAE,WAAW,EAAC,MAAM,0BAA0B,CAAC;AACnF,OAAO,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CA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AC,OAAO,EAAE,4BAA4B,EAAC,MAAM,0BAA0B,CAAC;AAE/E,OAAO,EACL,uBAAuB,EACvB,uBAAuB,EACvB,gBAAgB,EAChB,wBAAwB,EACzB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACL,YAAY,EACZ,SAAS,EACT,UAAU,EACV,eAAe,EACf,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EACjB,sCAAmC"}
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,9 @@ export { loadInBatches } from "./lib/api/load-in-batches.js";
|
|
|
21
21
|
export { encodeTable, encodeTableAsText, encodeTableInBatches } from "./lib/api/encode-table.js";
|
|
22
22
|
export { encode, encodeSync, encodeInBatches, encodeURLtoURL } from "./lib/api/encode.js";
|
|
23
23
|
export { encodeText, encodeTextSync } from "./lib/api/encode.js";
|
|
24
|
+
// SERVICES AND SOURCES
|
|
25
|
+
export { createDataSource } from "./lib/api/create-data-source.js";
|
|
26
|
+
export { selectSource as _selectSource } from "./lib/api/select-source.js";
|
|
24
27
|
// CORE UTILS SHARED WITH LOADERS (RE-EXPORTED FROM LOADER-UTILS)
|
|
25
28
|
export { setPathPrefix, getPathPrefix, resolvePath } from '@loaders.gl/loader-utils';
|
|
26
29
|
export { RequestScheduler } from '@loaders.gl/loader-utils';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DataSourceProps } from '@loaders.gl/loader-utils';
|
|
2
|
+
import { DataSource, Source } from '@loaders.gl/loader-utils';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a source from a service
|
|
5
|
+
* If type is not supplied, will try to automatically detect the the
|
|
6
|
+
* @param url URL to the data source
|
|
7
|
+
* @param type type of source. if not known, set to 'auto'
|
|
8
|
+
* @returns an DataSource instance
|
|
9
|
+
*/
|
|
10
|
+
export declare function createDataSource<DataSourcePropsT extends DataSourceProps = DataSourceProps, DataSourceT extends DataSource = DataSource>(data: string | Blob, sources: Source[], props: DataSourcePropsT & {
|
|
11
|
+
type?: string;
|
|
12
|
+
}): DataSourceT;
|
|
13
|
+
//# sourceMappingURL=create-data-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-data-source.d.ts","sourceRoot":"","sources":["../../../src/lib/api/create-data-source.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAC,UAAU,EAAE,MAAM,EAAC,MAAM,0BAA0B,CAAC;AAE5D;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,gBAAgB,SAAS,eAAe,GAAG,eAAe,EAC1D,WAAW,SAAS,UAAU,GAAG,UAAU,EAC3C,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,gBAAgB,GAAG;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAC,GAAG,WAAW,CAQhG"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
/**
|
|
5
|
+
* Creates a source from a service
|
|
6
|
+
* If type is not supplied, will try to automatically detect the the
|
|
7
|
+
* @param url URL to the data source
|
|
8
|
+
* @param type type of source. if not known, set to 'auto'
|
|
9
|
+
* @returns an DataSource instance
|
|
10
|
+
*/
|
|
11
|
+
export function createDataSource(data, sources, props) {
|
|
12
|
+
const { type = 'auto' } = props;
|
|
13
|
+
const source = type === 'auto' ? selectSource(data, sources) : getSourceOfType(type, sources);
|
|
14
|
+
if (!source) {
|
|
15
|
+
throw new Error('Not a valid image source type');
|
|
16
|
+
}
|
|
17
|
+
return source.createDataSource(data, props);
|
|
18
|
+
}
|
|
19
|
+
// TODO - use selectSource...
|
|
20
|
+
/** Guess service type from URL */
|
|
21
|
+
function selectSource(url, sources) {
|
|
22
|
+
for (const service of sources) {
|
|
23
|
+
// @ts-expect-error
|
|
24
|
+
if (service.testURL && service.testURL(url)) {
|
|
25
|
+
return service;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
/** Guess service type from URL */
|
|
31
|
+
function getSourceOfType(type, sources) {
|
|
32
|
+
for (const service of sources) {
|
|
33
|
+
if (service.type === type) {
|
|
34
|
+
return service;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-loader.d.ts","sourceRoot":"","sources":["../../../src/lib/api/select-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,aAAa,EAAE,aAAa,EAAE,MAAM,EAAC,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"select-loader.d.ts","sourceRoot":"","sources":["../../../src/lib/api/select-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,aAAa,EAAE,aAAa,EAAE,MAAM,EAAC,MAAM,0BAA0B,CAAC;AAgBnF;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,QAAQ,GAAG,IAAI,GAAG,WAAW,GAAG,MAAM,EAC5C,OAAO,GAAE,MAAM,EAAE,GAAG,MAAW,EAC/B,OAAO,CAAC,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAwBxB;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,QAAQ,GAAG,IAAI,GAAG,WAAW,GAAG,MAAM,EAC5C,OAAO,GAAE,MAAM,EAAE,GAAG,MAAW,EAC/B,OAAO,CAAC,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,aAAa,GACtB,MAAM,GAAG,IAAI,CAmCf"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
// loaders.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
import { compareArrayBuffers, path } from '@loaders.gl/loader-utils';
|
|
4
|
+
import { compareArrayBuffers, path, log } from '@loaders.gl/loader-utils';
|
|
5
5
|
import { normalizeLoader } from "../loader-utils/normalize-loader.js";
|
|
6
|
-
import { log } from "../utils/log.js";
|
|
7
6
|
import { getResourceUrl, getResourceMIMEType } from "../utils/resource-utils.js";
|
|
8
7
|
import { compareMIMETypes } from "../utils/mime-type-utils.js";
|
|
9
8
|
import { getRegisteredLoaders } from "./register-loaders.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Source } from '@loaders.gl/loader-utils';
|
|
2
|
+
/** Guess service type from URL */
|
|
3
|
+
export declare function selectSource(url: string | Blob, sources: Source[], options?: {
|
|
4
|
+
/** Provide id of a source to select that source. Omit or provide 'auto' to test the source*/
|
|
5
|
+
type?: string;
|
|
6
|
+
nothrow?: boolean;
|
|
7
|
+
}): Source | null;
|
|
8
|
+
//# sourceMappingURL=select-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select-source.d.ts","sourceRoot":"","sources":["../../../src/lib/api/select-source.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,0BAA0B,CAAC;AAErD,kCAAkC;AAClC,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,GAAG,IAAI,EAClB,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,CAAC,EAAE;IACR,6FAA6F;IAC7F,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GACA,MAAM,GAAG,IAAI,CAkBf"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
/** Guess service type from URL */
|
|
5
|
+
export function selectSource(url, sources, options) {
|
|
6
|
+
const type = options?.type || 'auto';
|
|
7
|
+
let selectedSource = null;
|
|
8
|
+
if (type === 'auto') {
|
|
9
|
+
for (const source of sources) {
|
|
10
|
+
if (typeof url === 'string' && source.testURL && source.testURL(url)) {
|
|
11
|
+
return source;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
selectedSource = getSourceOfType(type, sources);
|
|
17
|
+
}
|
|
18
|
+
if (!selectedSource && !options?.nothrow) {
|
|
19
|
+
throw new Error('Not a valid image source type');
|
|
20
|
+
}
|
|
21
|
+
return selectedSource;
|
|
22
|
+
}
|
|
23
|
+
/** Guess service type from URL */
|
|
24
|
+
function getSourceOfType(type, sources) {
|
|
25
|
+
for (const service of sources) {
|
|
26
|
+
if (service.type === type) {
|
|
27
|
+
return service;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
package/dist/lib/init.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// loaders.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
import { log } from
|
|
4
|
+
import { log } from '@loaders.gl/loader-utils';
|
|
5
5
|
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
6
|
-
const version = typeof "4.
|
|
6
|
+
const version = typeof "4.3.0-alpha.2" !== 'undefined' ? "4.3.0-alpha.2" : '';
|
|
7
7
|
// @ts-ignore
|
|
8
8
|
if (!globalThis.loaders) {
|
|
9
9
|
log.log(1, `loaders.gl ${version}`)();
|
package/dist/null-loader.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
// __VERSION__ is injected by babel-plugin-version-inline
|
|
5
5
|
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
6
|
-
const VERSION = typeof "4.
|
|
6
|
+
const VERSION = typeof "4.3.0-alpha.2" !== 'undefined' ? "4.3.0-alpha.2" : 'latest';
|
|
7
7
|
/**
|
|
8
8
|
* Loads any data and returns null (or optionally passes through data unparsed)
|
|
9
9
|
*/
|
package/dist/null-worker-node.js
CHANGED
package/dist/null-worker.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/core",
|
|
3
|
-
"version": "4.3.0-alpha.
|
|
3
|
+
"version": "4.3.0-alpha.3",
|
|
4
4
|
"description": "The core API for working with loaders.gl loaders and writers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -55,10 +55,10 @@
|
|
|
55
55
|
"build-worker-node": "esbuild src/workers/null-worker.ts --outfile=dist/null-worker-node.js --bundle --platform=node --target=node16 --define:__VERSION__=\\\"$npm_package_version\\\""
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@loaders.gl/loader-utils": "4.3.0-alpha.
|
|
59
|
-
"@loaders.gl/schema": "4.3.0-alpha.
|
|
60
|
-
"@loaders.gl/worker-utils": "4.3.0-alpha.
|
|
58
|
+
"@loaders.gl/loader-utils": "4.3.0-alpha.3",
|
|
59
|
+
"@loaders.gl/schema": "4.3.0-alpha.3",
|
|
60
|
+
"@loaders.gl/worker-utils": "4.3.0-alpha.3",
|
|
61
61
|
"@probe.gl/log": "^4.0.2"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "3213679d79e6ff2814d48fd3337acfa446c74099"
|
|
64
64
|
}
|
package/src/index.ts
CHANGED
|
@@ -46,6 +46,10 @@ export {encodeTable, encodeTableAsText, encodeTableInBatches} from './lib/api/en
|
|
|
46
46
|
export {encode, encodeSync, encodeInBatches, encodeURLtoURL} from './lib/api/encode';
|
|
47
47
|
export {encodeText, encodeTextSync} from './lib/api/encode';
|
|
48
48
|
|
|
49
|
+
// SERVICES AND SOURCES
|
|
50
|
+
export {createDataSource} from './lib/api/create-data-source';
|
|
51
|
+
export {selectSource as _selectSource} from './lib/api/select-source';
|
|
52
|
+
|
|
49
53
|
// CORE UTILS SHARED WITH LOADERS (RE-EXPORTED FROM LOADER-UTILS)
|
|
50
54
|
export {setPathPrefix, getPathPrefix, resolvePath} from '@loaders.gl/loader-utils';
|
|
51
55
|
export {RequestScheduler} from '@loaders.gl/loader-utils';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {DataSourceProps} from '@loaders.gl/loader-utils';
|
|
6
|
+
import {DataSource, Source} from '@loaders.gl/loader-utils';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Creates a source from a service
|
|
10
|
+
* If type is not supplied, will try to automatically detect the the
|
|
11
|
+
* @param url URL to the data source
|
|
12
|
+
* @param type type of source. if not known, set to 'auto'
|
|
13
|
+
* @returns an DataSource instance
|
|
14
|
+
*/
|
|
15
|
+
export function createDataSource<
|
|
16
|
+
DataSourcePropsT extends DataSourceProps = DataSourceProps,
|
|
17
|
+
DataSourceT extends DataSource = DataSource
|
|
18
|
+
>(data: string | Blob, sources: Source[], props: DataSourcePropsT & {type?: string}): DataSourceT {
|
|
19
|
+
const {type = 'auto'} = props;
|
|
20
|
+
const source = type === 'auto' ? selectSource(data, sources) : getSourceOfType(type, sources);
|
|
21
|
+
|
|
22
|
+
if (!source) {
|
|
23
|
+
throw new Error('Not a valid image source type');
|
|
24
|
+
}
|
|
25
|
+
return source.createDataSource(data, props) as DataSourceT;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// TODO - use selectSource...
|
|
29
|
+
|
|
30
|
+
/** Guess service type from URL */
|
|
31
|
+
function selectSource(url: string | Blob, sources: Source[]): Source | null {
|
|
32
|
+
for (const service of sources) {
|
|
33
|
+
// @ts-expect-error
|
|
34
|
+
if (service.testURL && service.testURL(url)) {
|
|
35
|
+
return service;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Guess service type from URL */
|
|
43
|
+
function getSourceOfType(type: string, sources: Source[]): Source | null {
|
|
44
|
+
for (const service of sources) {
|
|
45
|
+
if (service.type === type) {
|
|
46
|
+
return service;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import type {LoaderContext, LoaderOptions, Loader} from '@loaders.gl/loader-utils';
|
|
6
|
-
import {compareArrayBuffers, path} from '@loaders.gl/loader-utils';
|
|
6
|
+
import {compareArrayBuffers, path, log} from '@loaders.gl/loader-utils';
|
|
7
7
|
import {normalizeLoader} from '../loader-utils/normalize-loader';
|
|
8
|
-
import {log} from '../utils/log';
|
|
9
8
|
import {getResourceUrl, getResourceMIMEType} from '../utils/resource-utils';
|
|
10
9
|
import {compareMIMETypes} from '../utils/mime-type-utils';
|
|
11
10
|
import {getRegisteredLoaders} from './register-loaders';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {Source} from '@loaders.gl/loader-utils';
|
|
6
|
+
|
|
7
|
+
/** Guess service type from URL */
|
|
8
|
+
export function selectSource(
|
|
9
|
+
url: string | Blob,
|
|
10
|
+
sources: Source[],
|
|
11
|
+
options?: {
|
|
12
|
+
/** Provide id of a source to select that source. Omit or provide 'auto' to test the source*/
|
|
13
|
+
type?: string;
|
|
14
|
+
nothrow?: boolean;
|
|
15
|
+
}
|
|
16
|
+
): Source | null {
|
|
17
|
+
const type = options?.type || 'auto';
|
|
18
|
+
let selectedSource: Source | null = null;
|
|
19
|
+
if (type === 'auto') {
|
|
20
|
+
for (const source of sources) {
|
|
21
|
+
if (typeof url === 'string' && source.testURL && source.testURL(url)) {
|
|
22
|
+
return source;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
selectedSource = getSourceOfType(type, sources);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!selectedSource && !options?.nothrow) {
|
|
30
|
+
throw new Error('Not a valid image source type');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return selectedSource;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Guess service type from URL */
|
|
37
|
+
function getSourceOfType(type: string, sources: Source[]): Source | null {
|
|
38
|
+
for (const service of sources) {
|
|
39
|
+
if (service.type === type) {
|
|
40
|
+
return service;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
package/src/lib/init.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {log} from '
|
|
5
|
+
import {log} from '@loaders.gl/loader-utils';
|
|
6
6
|
|
|
7
7
|
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
8
8
|
const version = typeof __VERSION__ !== 'undefined' ? __VERSION__ : '';
|
package/dist/lib/utils/log.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/log.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,GAAG,EAAC,MAAM,eAAe,CAAC;AAElC,eAAO,MAAM,GAAG,KAA8B,CAAC"}
|
package/dist/lib/utils/log.js
DELETED