@loaders.gl/images 3.1.3 → 4.0.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/bundle.js +2 -2
- package/dist/bundle.js.map +1 -0
- package/dist/image-loader.js +20 -39
- package/dist/image-loader.js.map +1 -0
- package/dist/image-writer.js +16 -19
- package/dist/image-writer.js.map +1 -0
- package/dist/index.js +8 -27
- package/dist/index.js.map +1 -0
- package/dist/lib/category-api/binary-image-api.js +102 -125
- package/dist/lib/category-api/binary-image-api.js.map +1 -0
- package/dist/lib/category-api/image-format.js +37 -56
- package/dist/lib/category-api/image-format.js.map +1 -0
- package/dist/lib/category-api/image-type.js +38 -44
- package/dist/lib/category-api/image-type.js.map +1 -0
- package/dist/lib/category-api/parsed-image-api.js +57 -62
- package/dist/lib/category-api/parsed-image-api.js.map +1 -0
- package/dist/lib/encoders/encode-image.js +60 -73
- package/dist/lib/encoders/encode-image.js.map +1 -0
- package/dist/lib/parsers/parse-image.js +49 -54
- package/dist/lib/parsers/parse-image.js.map +1 -0
- package/dist/lib/parsers/parse-to-image-bitmap.js +35 -53
- package/dist/lib/parsers/parse-to-image-bitmap.js.map +1 -0
- package/dist/lib/parsers/parse-to-image.js +30 -43
- package/dist/lib/parsers/parse-to-image.js.map +1 -0
- package/dist/lib/parsers/parse-to-node-image.js +10 -13
- package/dist/lib/parsers/parse-to-node-image.js.map +1 -0
- package/dist/lib/parsers/svg-utils.js +26 -36
- package/dist/lib/parsers/svg-utils.js.map +1 -0
- package/dist/lib/texture-api/async-deep-map.js +32 -49
- package/dist/lib/texture-api/async-deep-map.js.map +1 -0
- package/dist/lib/texture-api/deep-load.js +8 -13
- package/dist/lib/texture-api/deep-load.js.map +1 -0
- package/dist/lib/texture-api/generate-url.js +21 -19
- package/dist/lib/texture-api/generate-url.js.map +1 -0
- package/dist/lib/texture-api/load-image.js +47 -42
- package/dist/lib/texture-api/load-image.js.map +1 -0
- package/dist/lib/utils/version.js +2 -7
- package/dist/lib/utils/version.js.map +1 -0
- package/dist/types.js +2 -2
- package/dist/{es5/types.js.map → types.js.map} +0 -0
- package/package.json +5 -5
- package/dist/es5/bundle.js +0 -7
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/image-loader.js +0 -40
- package/dist/es5/image-loader.js.map +0 -1
- package/dist/es5/image-writer.js +0 -27
- package/dist/es5/image-writer.js.map +0 -1
- package/dist/es5/index.js +0 -86
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/category-api/binary-image-api.js +0 -126
- package/dist/es5/lib/category-api/binary-image-api.js.map +0 -1
- package/dist/es5/lib/category-api/image-format.js +0 -51
- package/dist/es5/lib/category-api/image-format.js.map +0 -1
- package/dist/es5/lib/category-api/image-type.js +0 -51
- package/dist/es5/lib/category-api/image-type.js.map +0 -1
- package/dist/es5/lib/category-api/parsed-image-api.js +0 -83
- package/dist/es5/lib/category-api/parsed-image-api.js.map +0 -1
- package/dist/es5/lib/encoders/encode-image.js +0 -131
- package/dist/es5/lib/encoders/encode-image.js.map +0 -1
- package/dist/es5/lib/parsers/parse-image.js +0 -102
- package/dist/es5/lib/parsers/parse-image.js.map +0 -1
- package/dist/es5/lib/parsers/parse-to-image-bitmap.js +0 -127
- package/dist/es5/lib/parsers/parse-to-image-bitmap.js.map +0 -1
- package/dist/es5/lib/parsers/parse-to-image.js +0 -110
- package/dist/es5/lib/parsers/parse-to-image.js.map +0 -1
- package/dist/es5/lib/parsers/parse-to-node-image.js +0 -48
- package/dist/es5/lib/parsers/parse-to-node-image.js.map +0 -1
- package/dist/es5/lib/parsers/svg-utils.js +0 -43
- package/dist/es5/lib/parsers/svg-utils.js.map +0 -1
- package/dist/es5/lib/texture-api/async-deep-map.js +0 -177
- package/dist/es5/lib/texture-api/async-deep-map.js.map +0 -1
- package/dist/es5/lib/texture-api/deep-load.js +0 -81
- package/dist/es5/lib/texture-api/deep-load.js.map +0 -1
- package/dist/es5/lib/texture-api/generate-url.js +0 -34
- package/dist/es5/lib/texture-api/generate-url.js.map +0 -1
- package/dist/es5/lib/texture-api/load-image.js +0 -173
- package/dist/es5/lib/texture-api/load-image.js.map +0 -1
- package/dist/es5/lib/utils/version.js +0 -9
- package/dist/es5/lib/utils/version.js.map +0 -1
- package/dist/es5/types.js +0 -2
- package/dist/esm/bundle.js +0 -5
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/image-loader.js +0 -24
- package/dist/esm/image-loader.js.map +0 -1
- package/dist/esm/image-writer.js +0 -17
- package/dist/esm/image-writer.js.map +0 -1
- package/dist/esm/index.js +0 -8
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/category-api/binary-image-api.js +0 -118
- package/dist/esm/lib/category-api/binary-image-api.js.map +0 -1
- package/dist/esm/lib/category-api/image-format.js +0 -44
- package/dist/esm/lib/category-api/image-format.js.map +0 -1
- package/dist/esm/lib/category-api/image-type.js +0 -42
- package/dist/esm/lib/category-api/image-type.js.map +0 -1
- package/dist/esm/lib/category-api/parsed-image-api.js +0 -64
- package/dist/esm/lib/category-api/parsed-image-api.js.map +0 -1
- package/dist/esm/lib/encoders/encode-image.js +0 -69
- package/dist/esm/lib/encoders/encode-image.js.map +0 -1
- package/dist/esm/lib/parsers/parse-image.js +0 -52
- package/dist/esm/lib/parsers/parse-image.js.map +0 -1
- package/dist/esm/lib/parsers/parse-to-image-bitmap.js +0 -43
- package/dist/esm/lib/parsers/parse-to-image-bitmap.js.map +0 -1
- package/dist/esm/lib/parsers/parse-to-image.js +0 -34
- package/dist/esm/lib/parsers/parse-to-image.js.map +0 -1
- package/dist/esm/lib/parsers/parse-to-node-image.js +0 -11
- package/dist/esm/lib/parsers/parse-to-node-image.js.map +0 -1
- package/dist/esm/lib/parsers/svg-utils.js +0 -32
- package/dist/esm/lib/parsers/svg-utils.js.map +0 -1
- package/dist/esm/lib/texture-api/async-deep-map.js +0 -39
- package/dist/esm/lib/texture-api/async-deep-map.js.map +0 -1
- package/dist/esm/lib/texture-api/deep-load.js +0 -10
- package/dist/esm/lib/texture-api/deep-load.js.map +0 -1
- package/dist/esm/lib/texture-api/generate-url.js +0 -22
- package/dist/esm/lib/texture-api/generate-url.js.map +0 -1
- package/dist/esm/lib/texture-api/load-image.js +0 -52
- package/dist/esm/lib/texture-api/load-image.js.map +0 -1
- package/dist/esm/lib/utils/version.js +0 -2
- package/dist/esm/lib/utils/version.js.map +0 -1
- package/dist/esm/types.js +0 -2
- package/dist/esm/types.js.map +0 -1
|
@@ -1,47 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const objectUrl = typeof blobOrDataUrl !== 'string' && URL.createObjectURL(blobOrDataUrl);
|
|
13
|
-
try {
|
|
14
|
-
return await loadToImage(objectUrl || blobOrDataUrl, options);
|
|
15
|
-
}
|
|
16
|
-
finally {
|
|
17
|
-
if (objectUrl) {
|
|
18
|
-
URL.revokeObjectURL(objectUrl);
|
|
19
|
-
}
|
|
1
|
+
import { getBlobOrSVGDataUrl } from './svg-utils';
|
|
2
|
+
export default async function parseToImage(arrayBuffer, options, url) {
|
|
3
|
+
const blobOrDataUrl = getBlobOrSVGDataUrl(arrayBuffer, url);
|
|
4
|
+
const URL = self.URL || self.webkitURL;
|
|
5
|
+
const objectUrl = typeof blobOrDataUrl !== 'string' && URL.createObjectURL(blobOrDataUrl);
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
return await loadToImage(objectUrl || blobOrDataUrl, options);
|
|
9
|
+
} finally {
|
|
10
|
+
if (objectUrl) {
|
|
11
|
+
URL.revokeObjectURL(objectUrl);
|
|
20
12
|
}
|
|
13
|
+
}
|
|
21
14
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
15
|
+
export async function loadToImage(url, options) {
|
|
16
|
+
const image = new Image();
|
|
17
|
+
image.src = url;
|
|
18
|
+
|
|
19
|
+
if (options.image && options.image.decode && image.decode) {
|
|
20
|
+
await image.decode();
|
|
21
|
+
return image;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return await new Promise((resolve, reject) => {
|
|
25
|
+
try {
|
|
26
|
+
image.onload = () => resolve(image);
|
|
27
|
+
|
|
28
|
+
image.onerror = err => reject(new Error("Could not load image ".concat(url, ": ").concat(err)));
|
|
29
|
+
} catch (error) {
|
|
30
|
+
reject(error);
|
|
35
31
|
}
|
|
36
|
-
|
|
37
|
-
return await new Promise((resolve, reject) => {
|
|
38
|
-
try {
|
|
39
|
-
image.onload = () => resolve(image);
|
|
40
|
-
image.onerror = (err) => reject(new Error(`Could not load image ${url}: ${err}`));
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
reject(error);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
32
|
+
});
|
|
46
33
|
}
|
|
47
|
-
|
|
34
|
+
//# sourceMappingURL=parse-to-image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/parsers/parse-to-image.ts"],"names":["getBlobOrSVGDataUrl","parseToImage","arrayBuffer","options","url","blobOrDataUrl","URL","self","webkitURL","objectUrl","createObjectURL","loadToImage","revokeObjectURL","image","Image","src","decode","Promise","resolve","reject","onload","onerror","err","Error","error"],"mappings":"AACA,SAAQA,mBAAR,QAAkC,aAAlC;AAGA,eAAe,eAAeC,YAAf,CACbC,WADa,EAEbC,OAFa,EAGbC,GAHa,EAIc;AAK3B,QAAMC,aAAa,GAAGL,mBAAmB,CAACE,WAAD,EAAcE,GAAd,CAAzC;AACA,QAAME,GAAG,GAAGC,IAAI,CAACD,GAAL,IAAYC,IAAI,CAACC,SAA7B;AACA,QAAMC,SAAS,GAAG,OAAOJ,aAAP,KAAyB,QAAzB,IAAqCC,GAAG,CAACI,eAAJ,CAAoBL,aAApB,CAAvD;;AACA,MAAI;AACF,WAAO,MAAMM,WAAW,CAACF,SAAS,IAAIJ,aAAd,EAA6BF,OAA7B,CAAxB;AACD,GAFD,SAEU;AACR,QAAIM,SAAJ,EAAe;AACbH,MAAAA,GAAG,CAACM,eAAJ,CAAoBH,SAApB;AACD;AACF;AACF;AAED,OAAO,eAAeE,WAAf,CAA2BP,GAA3B,EAAgCD,OAAhC,EAAoE;AACzE,QAAMU,KAAK,GAAG,IAAIC,KAAJ,EAAd;AACAD,EAAAA,KAAK,CAACE,GAAN,GAAYX,GAAZ;;AASA,MAAID,OAAO,CAACU,KAAR,IAAiBV,OAAO,CAACU,KAAR,CAAcG,MAA/B,IAAyCH,KAAK,CAACG,MAAnD,EAA2D;AACzD,UAAMH,KAAK,CAACG,MAAN,EAAN;AACA,WAAOH,KAAP;AACD;;AAGD,SAAO,MAAM,IAAII,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;AAC5C,QAAI;AACFN,MAAAA,KAAK,CAACO,MAAN,GAAe,MAAMF,OAAO,CAACL,KAAD,CAA5B;;AACAA,MAAAA,KAAK,CAACQ,OAAN,GAAiBC,GAAD,IAASH,MAAM,CAAC,IAAII,KAAJ,gCAAkCnB,GAAlC,eAA0CkB,GAA1C,EAAD,CAA/B;AACD,KAHD,CAGE,OAAOE,KAAP,EAAc;AACdL,MAAAA,MAAM,CAACK,KAAD,CAAN;AACD;AACF,GAPY,CAAb;AAQD","sourcesContent":["import type {ImageLoaderOptions} from '../../image-loader';\nimport {getBlobOrSVGDataUrl} from './svg-utils';\n\n// Parses html image from array buffer\nexport default async function parseToImage(\n arrayBuffer: ArrayBuffer,\n options: ImageLoaderOptions,\n url?: string\n): Promise<HTMLImageElement> {\n // Note: image parsing requires conversion to Blob (for createObjectURL).\n // Potentially inefficient for not using `response.blob()` (and for File / Blob inputs)...\n // But presumably not worth adding 'blob' flag to loader objects?\n\n const blobOrDataUrl = getBlobOrSVGDataUrl(arrayBuffer, url);\n const URL = self.URL || self.webkitURL;\n const objectUrl = typeof blobOrDataUrl !== 'string' && URL.createObjectURL(blobOrDataUrl);\n try {\n return await loadToImage(objectUrl || blobOrDataUrl, options);\n } finally {\n if (objectUrl) {\n URL.revokeObjectURL(objectUrl);\n }\n }\n}\n\nexport async function loadToImage(url, options): Promise<HTMLImageElement> {\n const image = new Image();\n image.src = url;\n\n // The `image.onload()` callback does not guarantee that the image has been decoded\n // so a main thread \"freeze\" can be incurred when using the image for the first time.\n // `Image.decode()` returns a promise that completes when image is decoded.\n\n // https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decode\n // Note: When calling `img.decode()`, we do not need to wait for `img.onload()`\n // Note: `HTMLImageElement.decode()` is not available in Edge and IE11\n if (options.image && options.image.decode && image.decode) {\n await image.decode();\n return image;\n }\n\n // Create a promise that tracks onload/onerror callbacks\n return await new Promise((resolve, reject) => {\n try {\n image.onload = () => resolve(image);\n image.onerror = (err) => reject(new Error(`Could not load image ${url}: ${err}`));\n } catch (error) {\n reject(error);\n }\n });\n}\n"],"file":"parse-to-image.js"}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
(0, loader_utils_1.assert)(_parseImageNode); // '@loaders.gl/polyfills not installed'
|
|
11
|
-
// @ts-expect-error TODO should we throw error in this case?
|
|
12
|
-
return await _parseImageNode(arrayBuffer, mimeType);
|
|
1
|
+
import { assert } from '@loaders.gl/loader-utils';
|
|
2
|
+
import { getBinaryImageMetadata } from '../category-api/binary-image-api';
|
|
3
|
+
export default async function parseToNodeImage(arrayBuffer, options) {
|
|
4
|
+
const {
|
|
5
|
+
mimeType
|
|
6
|
+
} = getBinaryImageMetadata(arrayBuffer) || {};
|
|
7
|
+
const _parseImageNode = globalThis._parseImageNode;
|
|
8
|
+
assert(_parseImageNode);
|
|
9
|
+
return await _parseImageNode(arrayBuffer, mimeType);
|
|
13
10
|
}
|
|
14
|
-
|
|
11
|
+
//# sourceMappingURL=parse-to-node-image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/parsers/parse-to-node-image.ts"],"names":["assert","getBinaryImageMetadata","parseToNodeImage","arrayBuffer","options","mimeType","_parseImageNode","globalThis"],"mappings":"AAEA,SAAQA,MAAR,QAAqB,0BAArB;AACA,SAAQC,sBAAR,QAAqC,kCAArC;AAgBA,eAAe,eAAeC,gBAAf,CACbC,WADa,EAEbC,OAFa,EAGW;AACxB,QAAM;AAACC,IAAAA;AAAD,MAAaJ,sBAAsB,CAACE,WAAD,CAAtB,IAAuC,EAA1D;AAGA,QAAMG,eAA+B,GAAGC,UAAU,CAACD,eAAnD;AACAN,EAAAA,MAAM,CAACM,eAAD,CAAN;AAGA,SAAO,MAAMA,eAAe,CAACH,WAAD,EAAcE,QAAd,CAA5B;AACD","sourcesContent":["import type {ImageLoaderOptions} from '../../image-loader';\nimport type {ImageDataType} from '../../types';\nimport {assert} from '@loaders.gl/loader-utils';\nimport {getBinaryImageMetadata} from '../category-api/binary-image-api';\n\n// Note: These types should be consistent with loaders.gl/polyfills\n\ntype NDArray = {\n shape: number[];\n data: Uint8Array;\n width: number;\n height: number;\n components: number;\n layers: number[];\n};\n\ntype ParseImageNode = (arrayBuffer: ArrayBuffer, mimeType: string) => Promise<NDArray>;\n\n// Use polyfills if installed to parsed image using get-pixels\nexport default async function parseToNodeImage(\n arrayBuffer: ArrayBuffer,\n options: ImageLoaderOptions\n): Promise<ImageDataType> {\n const {mimeType} = getBinaryImageMetadata(arrayBuffer) || {};\n\n // @ts-ignore\n const _parseImageNode: ParseImageNode = globalThis._parseImageNode;\n assert(_parseImageNode); // '@loaders.gl/polyfills not installed'\n\n // @ts-expect-error TODO should we throw error in this case?\n return await _parseImageNode(arrayBuffer, mimeType);\n}\n"],"file":"parse-to-node-image.js"}
|
|
@@ -1,42 +1,32 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// SVG parsing has limitations, e.g:
|
|
3
|
-
// https://bugs.chromium.org/p/chromium/issues/detail?id=606319
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.getBlob = exports.getBlobOrSVGDataUrl = exports.isSVG = void 0;
|
|
6
1
|
const SVG_DATA_URL_PATTERN = /^data:image\/svg\+xml/;
|
|
7
2
|
const SVG_URL_PATTERN = /\.svg((\?|#).*)?$/;
|
|
8
|
-
function isSVG(url) {
|
|
9
|
-
|
|
3
|
+
export function isSVG(url) {
|
|
4
|
+
return url && (SVG_DATA_URL_PATTERN.test(url) || SVG_URL_PATTERN.test(url));
|
|
10
5
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
throw new Error(error.message);
|
|
25
|
-
}
|
|
26
|
-
// base64 encoding is safer. utf-8 fails in some browsers
|
|
27
|
-
const src = `data:image/svg+xml;base64,${btoa(xmlText)}`;
|
|
28
|
-
return src;
|
|
6
|
+
export function getBlobOrSVGDataUrl(arrayBuffer, url) {
|
|
7
|
+
if (isSVG(url)) {
|
|
8
|
+
const textDecoder = new TextDecoder();
|
|
9
|
+
let xmlText = textDecoder.decode(arrayBuffer);
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
if (typeof unescape === 'function' && typeof encodeURIComponent === 'function') {
|
|
13
|
+
xmlText = unescape(encodeURIComponent(xmlText));
|
|
14
|
+
}
|
|
15
|
+
} catch (error) {
|
|
16
|
+
throw new Error(error.message);
|
|
29
17
|
}
|
|
30
|
-
|
|
18
|
+
|
|
19
|
+
const src = "data:image/svg+xml;base64,".concat(btoa(xmlText));
|
|
20
|
+
return src;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return getBlob(arrayBuffer, url);
|
|
31
24
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
// TODO - how to determine mime type? Param? Sniff here?
|
|
40
|
-
return new Blob([new Uint8Array(arrayBuffer)]); // MIME type not needed?
|
|
25
|
+
export function getBlob(arrayBuffer, url) {
|
|
26
|
+
if (isSVG(url)) {
|
|
27
|
+
throw new Error('SVG cannot be parsed directly to imagebitmap');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return new Blob([new Uint8Array(arrayBuffer)]);
|
|
41
31
|
}
|
|
42
|
-
|
|
32
|
+
//# sourceMappingURL=svg-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/parsers/svg-utils.ts"],"names":["SVG_DATA_URL_PATTERN","SVG_URL_PATTERN","isSVG","url","test","getBlobOrSVGDataUrl","arrayBuffer","textDecoder","TextDecoder","xmlText","decode","unescape","encodeURIComponent","error","Error","message","src","btoa","getBlob","Blob","Uint8Array"],"mappings":"AAGA,MAAMA,oBAAoB,GAAG,uBAA7B;AACA,MAAMC,eAAe,GAAG,mBAAxB;AAEA,OAAO,SAASC,KAAT,CAAeC,GAAf,EAAoB;AACzB,SAAOA,GAAG,KAAKH,oBAAoB,CAACI,IAArB,CAA0BD,GAA1B,KAAkCF,eAAe,CAACG,IAAhB,CAAqBD,GAArB,CAAvC,CAAV;AACD;AAED,OAAO,SAASE,mBAAT,CAA6BC,WAA7B,EAAuDH,GAAvD,EAAoF;AACzF,MAAID,KAAK,CAACC,GAAD,CAAT,EAAgB;AAEd,UAAMI,WAAW,GAAG,IAAIC,WAAJ,EAApB;AACA,QAAIC,OAAO,GAAGF,WAAW,CAACG,MAAZ,CAAmBJ,WAAnB,CAAd;;AAEA,QAAI;AACF,UAAI,OAAOK,QAAP,KAAoB,UAApB,IAAkC,OAAOC,kBAAP,KAA8B,UAApE,EAAgF;AAC9EH,QAAAA,OAAO,GAAGE,QAAQ,CAACC,kBAAkB,CAACH,OAAD,CAAnB,CAAlB;AACD;AACF,KAJD,CAIE,OAAOI,KAAP,EAAc;AACd,YAAM,IAAIC,KAAJ,CAAWD,KAAD,CAAiBE,OAA3B,CAAN;AACD;;AAED,UAAMC,GAAG,uCAAgCC,IAAI,CAACR,OAAD,CAApC,CAAT;AACA,WAAOO,GAAP;AACD;;AACD,SAAOE,OAAO,CAACZ,WAAD,EAAcH,GAAd,CAAd;AACD;AAED,OAAO,SAASe,OAAT,CAAiBZ,WAAjB,EAA2CH,GAA3C,EAA+D;AACpE,MAAID,KAAK,CAACC,GAAD,CAAT,EAAgB;AAGd,UAAM,IAAIW,KAAJ,CAAU,8CAAV,CAAN;AACD;;AAED,SAAO,IAAIK,IAAJ,CAAS,CAAC,IAAIC,UAAJ,CAAed,WAAf,CAAD,CAAT,CAAP;AACD","sourcesContent":["// SVG parsing has limitations, e.g:\n// https://bugs.chromium.org/p/chromium/issues/detail?id=606319\n\nconst SVG_DATA_URL_PATTERN = /^data:image\\/svg\\+xml/;\nconst SVG_URL_PATTERN = /\\.svg((\\?|#).*)?$/;\n\nexport function isSVG(url) {\n return url && (SVG_DATA_URL_PATTERN.test(url) || SVG_URL_PATTERN.test(url));\n}\n\nexport function getBlobOrSVGDataUrl(arrayBuffer: ArrayBuffer, url?: string): Blob | string {\n if (isSVG(url)) {\n // Prepare a properly tagged data URL, and load using normal mechanism\n const textDecoder = new TextDecoder();\n let xmlText = textDecoder.decode(arrayBuffer);\n // TODO Escape in browser to support e.g. Chinese characters\n try {\n if (typeof unescape === 'function' && typeof encodeURIComponent === 'function') {\n xmlText = unescape(encodeURIComponent(xmlText));\n }\n } catch (error) {\n throw new Error((error as Error).message);\n }\n // base64 encoding is safer. utf-8 fails in some browsers\n const src = `data:image/svg+xml;base64,${btoa(xmlText)}`;\n return src;\n }\n return getBlob(arrayBuffer, url);\n}\n\nexport function getBlob(arrayBuffer: ArrayBuffer, url?: string): Blob {\n if (isSVG(url)) {\n // https://bugs.chromium.org/p/chromium/issues/detail?id=606319\n // return new Blob([new Uint8Array(arrayBuffer)], {type: 'image/svg+xml'});\n throw new Error('SVG cannot be parsed directly to imagebitmap');\n }\n // TODO - how to determine mime type? Param? Sniff here?\n return new Blob([new Uint8Array(arrayBuffer)]); // MIME type not needed?\n}\n"],"file":"svg-utils.js"}
|
|
@@ -1,56 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
/*
|
|
3
|
-
Asynchronously maps a deep structure of values (e.g. objects and arrays of urls).
|
|
1
|
+
const isObject = value => value && typeof value === 'object';
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
[CUBE_FACE_FRONT]: [
|
|
8
|
-
"image-front-0.jpg",
|
|
9
|
-
"image-front-1.jpg",
|
|
10
|
-
"image-front-2.jpg",
|
|
11
|
-
],
|
|
12
|
-
[CUBE_MAP_BACK]: [
|
|
13
|
-
...
|
|
14
|
-
]
|
|
3
|
+
export async function asyncDeepMap(tree, func, options = {}) {
|
|
4
|
+
return await mapSubtree(tree, func, options);
|
|
15
5
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
async function mapSubtree(object, func, options) {
|
|
28
|
-
if (Array.isArray(object)) {
|
|
29
|
-
return await mapArray(object, func, options);
|
|
30
|
-
}
|
|
31
|
-
if (isObject(object)) {
|
|
32
|
-
return await mapObject(object, func, options);
|
|
33
|
-
}
|
|
34
|
-
// TODO - ignore non-urls, non-arraybuffers?
|
|
35
|
-
const url = object;
|
|
36
|
-
return await func(url, options);
|
|
6
|
+
export async function mapSubtree(object, func, options) {
|
|
7
|
+
if (Array.isArray(object)) {
|
|
8
|
+
return await mapArray(object, func, options);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (isObject(object)) {
|
|
12
|
+
return await mapObject(object, func, options);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const url = object;
|
|
16
|
+
return await func(url, options);
|
|
37
17
|
}
|
|
38
|
-
|
|
39
|
-
// HELPERS
|
|
18
|
+
|
|
40
19
|
async function mapObject(object, func, options) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
20
|
+
const promises = [];
|
|
21
|
+
const values = {};
|
|
22
|
+
|
|
23
|
+
for (const key in object) {
|
|
24
|
+
const url = object[key];
|
|
25
|
+
const promise = mapSubtree(url, func, options).then(value => {
|
|
26
|
+
values[key] = value;
|
|
27
|
+
});
|
|
28
|
+
promises.push(promise);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
await Promise.all(promises);
|
|
32
|
+
return values;
|
|
52
33
|
}
|
|
34
|
+
|
|
53
35
|
async function mapArray(urlArray, func, options = {}) {
|
|
54
|
-
|
|
55
|
-
|
|
36
|
+
const promises = urlArray.map(url => mapSubtree(url, func, options));
|
|
37
|
+
return await Promise.all(promises);
|
|
56
38
|
}
|
|
39
|
+
//# sourceMappingURL=async-deep-map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/texture-api/async-deep-map.ts"],"names":["isObject","value","asyncDeepMap","tree","func","options","mapSubtree","object","Array","isArray","mapArray","mapObject","url","promises","values","key","promise","then","push","Promise","all","urlArray","map"],"mappings":"AAgBA,MAAMA,QAAQ,GAAIC,KAAD,IAAWA,KAAK,IAAI,OAAOA,KAAP,KAAiB,QAAtD;;AAKA,OAAO,eAAeC,YAAf,CAA4BC,IAA5B,EAAkCC,IAAlC,EAAwCC,OAAO,GAAG,EAAlD,EAAsD;AAC3D,SAAO,MAAMC,UAAU,CAACH,IAAD,EAAOC,IAAP,EAAaC,OAAb,CAAvB;AACD;AAED,OAAO,eAAeC,UAAf,CAA0BC,MAA1B,EAAkCH,IAAlC,EAAwCC,OAAxC,EAAiD;AACtD,MAAIG,KAAK,CAACC,OAAN,CAAcF,MAAd,CAAJ,EAA2B;AACzB,WAAO,MAAMG,QAAQ,CAACH,MAAD,EAASH,IAAT,EAAeC,OAAf,CAArB;AACD;;AAED,MAAIL,QAAQ,CAACO,MAAD,CAAZ,EAAsB;AACpB,WAAO,MAAMI,SAAS,CAACJ,MAAD,EAASH,IAAT,EAAeC,OAAf,CAAtB;AACD;;AAGD,QAAMO,GAAG,GAAGL,MAAZ;AACA,SAAO,MAAMH,IAAI,CAACQ,GAAD,EAAMP,OAAN,CAAjB;AACD;;AAID,eAAeM,SAAf,CAAyBJ,MAAzB,EAAiCH,IAAjC,EAAuCC,OAAvC,EAAgD;AAC9C,QAAMQ,QAAwB,GAAG,EAAjC;AACA,QAAMC,MAAM,GAAG,EAAf;;AAEA,OAAK,MAAMC,GAAX,IAAkBR,MAAlB,EAA0B;AACxB,UAAMK,GAAG,GAAGL,MAAM,CAACQ,GAAD,CAAlB;AACA,UAAMC,OAAO,GAAGV,UAAU,CAACM,GAAD,EAAMR,IAAN,EAAYC,OAAZ,CAAV,CAA+BY,IAA/B,CAAqChB,KAAD,IAAW;AAC7Da,MAAAA,MAAM,CAACC,GAAD,CAAN,GAAcd,KAAd;AACD,KAFe,CAAhB;AAGAY,IAAAA,QAAQ,CAACK,IAAT,CAAcF,OAAd;AACD;;AAED,QAAMG,OAAO,CAACC,GAAR,CAAYP,QAAZ,CAAN;AAEA,SAAOC,MAAP;AACD;;AAED,eAAeJ,QAAf,CAAwBW,QAAxB,EAAkCjB,IAAlC,EAAwCC,OAAO,GAAG,EAAlD,EAAsD;AACpD,QAAMQ,QAAQ,GAAGQ,QAAQ,CAACC,GAAT,CAAcV,GAAD,IAASN,UAAU,CAACM,GAAD,EAAMR,IAAN,EAAYC,OAAZ,CAAhC,CAAjB;AACA,SAAO,MAAMc,OAAO,CAACC,GAAR,CAAYP,QAAZ,CAAb;AACD","sourcesContent":["/*\nAsynchronously maps a deep structure of values (e.g. objects and arrays of urls).\n\nE.g. a mipmapped cubemap\n{\n [CUBE_FACE_FRONT]: [\n \"image-front-0.jpg\",\n \"image-front-1.jpg\",\n \"image-front-2.jpg\",\n ],\n [CUBE_MAP_BACK]: [\n ...\n ]\n}\n*/\n\nconst isObject = (value) => value && typeof value === 'object';\n\n// Loads a deep structure of urls (objects and arrays of urls)\n// Returns an object with six key-value pairs containing the images (or image mip arrays)\n// for each cube face\nexport async function asyncDeepMap(tree, func, options = {}) {\n return await mapSubtree(tree, func, options);\n}\n\nexport async function mapSubtree(object, func, options) {\n if (Array.isArray(object)) {\n return await mapArray(object, func, options);\n }\n\n if (isObject(object)) {\n return await mapObject(object, func, options);\n }\n\n // TODO - ignore non-urls, non-arraybuffers?\n const url = object;\n return await func(url, options);\n}\n\n// HELPERS\n\nasync function mapObject(object, func, options) {\n const promises: Promise<any>[] = [];\n const values = {};\n\n for (const key in object) {\n const url = object[key];\n const promise = mapSubtree(url, func, options).then((value) => {\n values[key] = value;\n });\n promises.push(promise);\n }\n\n await Promise.all(promises);\n\n return values;\n}\n\nasync function mapArray(urlArray, func, options = {}) {\n const promises = urlArray.map((url) => mapSubtree(url, func, options));\n return await Promise.all(promises);\n}\n"],"file":"async-deep-map.js"}
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const async_deep_map_1 = require("./async-deep-map");
|
|
5
|
-
async function deepLoad(urlTree, load, options) {
|
|
6
|
-
return await (0, async_deep_map_1.asyncDeepMap)(urlTree, (url) => shallowLoad(url, load, options));
|
|
1
|
+
import { asyncDeepMap } from './async-deep-map';
|
|
2
|
+
export async function deepLoad(urlTree, load, options) {
|
|
3
|
+
return await asyncDeepMap(urlTree, url => shallowLoad(url, load, options));
|
|
7
4
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
13
|
-
return await load(arrayBuffer, options);
|
|
5
|
+
export async function shallowLoad(url, load, options) {
|
|
6
|
+
const response = await fetch(url, options.fetch);
|
|
7
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
8
|
+
return await load(arrayBuffer, options);
|
|
14
9
|
}
|
|
15
|
-
|
|
10
|
+
//# sourceMappingURL=deep-load.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/texture-api/deep-load.ts"],"names":["asyncDeepMap","deepLoad","urlTree","load","options","url","shallowLoad","response","fetch","arrayBuffer"],"mappings":"AAAA,SAAQA,YAAR,QAA2B,kBAA3B;AAEA,OAAO,eAAeC,QAAf,CAAwBC,OAAxB,EAAiCC,IAAjC,EAAuCC,OAAvC,EAAgD;AACrD,SAAO,MAAMJ,YAAY,CAACE,OAAD,EAAWG,GAAD,IAASC,WAAW,CAACD,GAAD,EAAMF,IAAN,EAAYC,OAAZ,CAA9B,CAAzB;AACD;AAED,OAAO,eAAeE,WAAf,CAA2BD,GAA3B,EAAgCF,IAAhC,EAAsCC,OAAtC,EAA+C;AAEpD,QAAMG,QAAQ,GAAG,MAAMC,KAAK,CAACH,GAAD,EAAMD,OAAO,CAACI,KAAd,CAA5B;AACA,QAAMC,WAAW,GAAG,MAAMF,QAAQ,CAACE,WAAT,EAA1B;AACA,SAAO,MAAMN,IAAI,CAACM,WAAD,EAAcL,OAAd,CAAjB;AACD","sourcesContent":["import {asyncDeepMap} from './async-deep-map';\n\nexport async function deepLoad(urlTree, load, options) {\n return await asyncDeepMap(urlTree, (url) => shallowLoad(url, load, options));\n}\n\nexport async function shallowLoad(url, load, options) {\n // console.error('loading', url);\n const response = await fetch(url, options.fetch);\n const arrayBuffer = await response.arrayBuffer();\n return await load(arrayBuffer, options);\n}\n"],"file":"deep-load.js"}
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import { resolvePath, assert } from '@loaders.gl/loader-utils';
|
|
2
|
+
export function generateUrl(getUrl, options, urlOptions) {
|
|
3
|
+
let url = getUrl;
|
|
4
|
+
|
|
5
|
+
if (typeof getUrl === 'function') {
|
|
6
|
+
url = getUrl({ ...options,
|
|
7
|
+
...urlOptions
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
assert(typeof url === 'string');
|
|
12
|
+
const {
|
|
13
|
+
baseUrl
|
|
14
|
+
} = options;
|
|
15
|
+
|
|
16
|
+
if (baseUrl) {
|
|
17
|
+
url = baseUrl[baseUrl.length - 1] === '/' ? "".concat(baseUrl).concat(url) : "".concat(baseUrl, "/").concat(url);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return resolvePath(url);
|
|
19
21
|
}
|
|
20
|
-
|
|
22
|
+
//# sourceMappingURL=generate-url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/texture-api/generate-url.ts"],"names":["resolvePath","assert","generateUrl","getUrl","options","urlOptions","url","baseUrl","length"],"mappings":"AAAA,SAAQA,WAAR,EAAqBC,MAArB,QAAkC,0BAAlC;AAGA,OAAO,SAASC,WAAT,CAAqBC,MAArB,EAA6BC,OAA7B,EAAsCC,UAAtC,EAAkD;AAEvD,MAAIC,GAAG,GAAGH,MAAV;;AACA,MAAI,OAAOA,MAAP,KAAkB,UAAtB,EAAkC;AAChCG,IAAAA,GAAG,GAAGH,MAAM,CAAC,EAAC,GAAGC,OAAJ;AAAa,SAAGC;AAAhB,KAAD,CAAZ;AACD;;AACDJ,EAAAA,MAAM,CAAC,OAAOK,GAAP,KAAe,QAAhB,CAAN;AAGA,QAAM;AAACC,IAAAA;AAAD,MAAYH,OAAlB;;AACA,MAAIG,OAAJ,EAAa;AACXD,IAAAA,GAAG,GAAGC,OAAO,CAACA,OAAO,CAACC,MAAR,GAAiB,CAAlB,CAAP,KAAgC,GAAhC,aAAyCD,OAAzC,SAAmDD,GAAnD,cAA8DC,OAA9D,cAAyED,GAAzE,CAAN;AACD;;AAED,SAAON,WAAW,CAACM,GAAD,CAAlB;AACD","sourcesContent":["import {resolvePath, assert} from '@loaders.gl/loader-utils';\n\n// Generate a url by calling getUrl with mix of options, applying options.baseUrl\nexport function generateUrl(getUrl, options, urlOptions) {\n // Get url\n let url = getUrl;\n if (typeof getUrl === 'function') {\n url = getUrl({...options, ...urlOptions});\n }\n assert(typeof url === 'string');\n\n // Apply options.baseUrl\n const {baseUrl} = options;\n if (baseUrl) {\n url = baseUrl[baseUrl.length - 1] === '/' ? `${baseUrl}${url}` : `${baseUrl}/${url}`;\n }\n\n return resolvePath(url);\n}\n"],"file":"generate-url.js"}
|
|
@@ -1,47 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const parsed_image_api_1 = require("../category-api/parsed-image-api");
|
|
10
|
-
const generate_url_1 = require("./generate-url");
|
|
11
|
-
const deep_load_1 = require("./deep-load");
|
|
12
|
-
async function loadImage(getUrl, options = {}) {
|
|
13
|
-
const imageUrls = await getImageUrls(getUrl, options);
|
|
14
|
-
return await (0, deep_load_1.deepLoad)(imageUrls, parse_image_1.default, options);
|
|
1
|
+
import { assert } from '@loaders.gl/loader-utils';
|
|
2
|
+
import parseImage from '../parsers/parse-image';
|
|
3
|
+
import { getImageSize } from '../category-api/parsed-image-api';
|
|
4
|
+
import { generateUrl } from './generate-url';
|
|
5
|
+
import { deepLoad, shallowLoad } from './deep-load';
|
|
6
|
+
export async function loadImage(getUrl, options = {}) {
|
|
7
|
+
const imageUrls = await getImageUrls(getUrl, options);
|
|
8
|
+
return await deepLoad(imageUrls, parseImage, options);
|
|
15
9
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return mipLevels !== 0
|
|
20
|
-
? await getMipmappedImageUrls(getUrl, mipLevels, options, urlOptions)
|
|
21
|
-
: (0, generate_url_1.generateUrl)(getUrl, options, urlOptions);
|
|
10
|
+
export async function getImageUrls(getUrl, options, urlOptions = {}) {
|
|
11
|
+
const mipLevels = options && options.image && options.image.mipLevels || 0;
|
|
12
|
+
return mipLevels !== 0 ? await getMipmappedImageUrls(getUrl, mipLevels, options, urlOptions) : generateUrl(getUrl, options, urlOptions);
|
|
22
13
|
}
|
|
23
|
-
|
|
14
|
+
|
|
24
15
|
async function getMipmappedImageUrls(getUrl, mipLevels, options, urlOptions) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
16
|
+
const urls = [];
|
|
17
|
+
|
|
18
|
+
if (mipLevels === 'auto') {
|
|
19
|
+
const url = generateUrl(getUrl, options, { ...urlOptions,
|
|
20
|
+
lod: 0
|
|
21
|
+
});
|
|
22
|
+
const image = await shallowLoad(url, parseImage, options);
|
|
23
|
+
const {
|
|
24
|
+
width,
|
|
25
|
+
height
|
|
26
|
+
} = getImageSize(image);
|
|
27
|
+
mipLevels = getMipLevels({
|
|
28
|
+
width,
|
|
29
|
+
height
|
|
30
|
+
});
|
|
31
|
+
urls.push(url);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
assert(mipLevels > 0);
|
|
35
|
+
|
|
36
|
+
for (let mipLevel = urls.length; mipLevel < mipLevels; ++mipLevel) {
|
|
37
|
+
const url = generateUrl(getUrl, options, { ...urlOptions,
|
|
38
|
+
lod: mipLevel
|
|
39
|
+
});
|
|
40
|
+
urls.push(url);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return urls;
|
|
42
44
|
}
|
|
43
|
-
|
|
44
|
-
function getMipLevels({
|
|
45
|
-
|
|
45
|
+
|
|
46
|
+
export function getMipLevels({
|
|
47
|
+
width,
|
|
48
|
+
height
|
|
49
|
+
}) {
|
|
50
|
+
return 1 + Math.floor(Math.log2(Math.max(width, height)));
|
|
46
51
|
}
|
|
47
|
-
|
|
52
|
+
//# sourceMappingURL=load-image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/texture-api/load-image.ts"],"names":["assert","parseImage","getImageSize","generateUrl","deepLoad","shallowLoad","loadImage","getUrl","options","imageUrls","getImageUrls","urlOptions","mipLevels","image","getMipmappedImageUrls","urls","url","lod","width","height","getMipLevels","push","mipLevel","length","Math","floor","log2","max"],"mappings":"AAAA,SAAQA,MAAR,QAAqB,0BAArB;AACA,OAAOC,UAAP,MAAuB,wBAAvB;AACA,SAAQC,YAAR,QAA2B,kCAA3B;AACA,SAAQC,WAAR,QAA0B,gBAA1B;AACA,SAAQC,QAAR,EAAkBC,WAAlB,QAAoC,aAApC;AAEA,OAAO,eAAeC,SAAf,CAAyBC,MAAzB,EAAiCC,OAAO,GAAG,EAA3C,EAA+C;AACpD,QAAMC,SAAS,GAAG,MAAMC,YAAY,CAACH,MAAD,EAASC,OAAT,CAApC;AACA,SAAO,MAAMJ,QAAQ,CAACK,SAAD,EAAYR,UAAZ,EAAwBO,OAAxB,CAArB;AACD;AAED,OAAO,eAAeE,YAAf,CAA4BH,MAA5B,EAAoCC,OAApC,EAA6CG,UAAU,GAAG,EAA1D,EAA8D;AACnE,QAAMC,SAAS,GAAIJ,OAAO,IAAIA,OAAO,CAACK,KAAnB,IAA4BL,OAAO,CAACK,KAAR,CAAcD,SAA3C,IAAyD,CAA3E;AACA,SAAOA,SAAS,KAAK,CAAd,GACH,MAAME,qBAAqB,CAACP,MAAD,EAASK,SAAT,EAAoBJ,OAApB,EAA6BG,UAA7B,CADxB,GAEHR,WAAW,CAACI,MAAD,EAASC,OAAT,EAAkBG,UAAlB,CAFf;AAGD;;AAED,eAAeG,qBAAf,CAAqCP,MAArC,EAA6CK,SAA7C,EAAwDJ,OAAxD,EAAiEG,UAAjE,EAA6E;AAC3E,QAAMI,IAAc,GAAG,EAAvB;;AAGA,MAAIH,SAAS,KAAK,MAAlB,EAA0B;AACxB,UAAMI,GAAG,GAAGb,WAAW,CAACI,MAAD,EAASC,OAAT,EAAkB,EAAC,GAAGG,UAAJ;AAAgBM,MAAAA,GAAG,EAAE;AAArB,KAAlB,CAAvB;AACA,UAAMJ,KAAK,GAAG,MAAMR,WAAW,CAACW,GAAD,EAAMf,UAAN,EAAkBO,OAAlB,CAA/B;AAEA,UAAM;AAACU,MAAAA,KAAD;AAAQC,MAAAA;AAAR,QAAkBjB,YAAY,CAACW,KAAD,CAApC;AACAD,IAAAA,SAAS,GAAGQ,YAAY,CAAC;AAACF,MAAAA,KAAD;AAAQC,MAAAA;AAAR,KAAD,CAAxB;AAGAJ,IAAAA,IAAI,CAACM,IAAL,CAAUL,GAAV;AACD;;AAGDhB,EAAAA,MAAM,CAACY,SAAS,GAAG,CAAb,CAAN;;AAEA,OAAK,IAAIU,QAAQ,GAAGP,IAAI,CAACQ,MAAzB,EAAiCD,QAAQ,GAAGV,SAA5C,EAAuD,EAAEU,QAAzD,EAAmE;AACjE,UAAMN,GAAG,GAAGb,WAAW,CAACI,MAAD,EAASC,OAAT,EAAkB,EAAC,GAAGG,UAAJ;AAAgBM,MAAAA,GAAG,EAAEK;AAArB,KAAlB,CAAvB;AACAP,IAAAA,IAAI,CAACM,IAAL,CAAUL,GAAV;AACD;;AAED,SAAOD,IAAP;AACD;;AAGD,OAAO,SAASK,YAAT,CAAsB;AAACF,EAAAA,KAAD;AAAQC,EAAAA;AAAR,CAAtB,EAAuC;AAC5C,SAAO,IAAIK,IAAI,CAACC,KAAL,CAAWD,IAAI,CAACE,IAAL,CAAUF,IAAI,CAACG,GAAL,CAAST,KAAT,EAAgBC,MAAhB,CAAV,CAAX,CAAX;AACD","sourcesContent":["import {assert} from '@loaders.gl/loader-utils';\nimport parseImage from '../parsers/parse-image';\nimport {getImageSize} from '../category-api/parsed-image-api';\nimport {generateUrl} from './generate-url';\nimport {deepLoad, shallowLoad} from './deep-load';\n\nexport async function loadImage(getUrl, options = {}) {\n const imageUrls = await getImageUrls(getUrl, options);\n return await deepLoad(imageUrls, parseImage, options);\n}\n\nexport async function getImageUrls(getUrl, options, urlOptions = {}) {\n const mipLevels = (options && options.image && options.image.mipLevels) || 0;\n return mipLevels !== 0\n ? await getMipmappedImageUrls(getUrl, mipLevels, options, urlOptions)\n : generateUrl(getUrl, options, urlOptions);\n}\n\nasync function getMipmappedImageUrls(getUrl, mipLevels, options, urlOptions) {\n const urls: string[] = [];\n\n // If no mip levels supplied, we need to load the level 0 image and calculate based on size\n if (mipLevels === 'auto') {\n const url = generateUrl(getUrl, options, {...urlOptions, lod: 0});\n const image = await shallowLoad(url, parseImage, options);\n\n const {width, height} = getImageSize(image);\n mipLevels = getMipLevels({width, height});\n\n // TODO - push image and make `deepLoad` pass through non-url values, avoid loading twice?\n urls.push(url);\n }\n\n // We now know how many mipLevels we need, remaining image urls can now be constructed\n assert(mipLevels > 0);\n\n for (let mipLevel = urls.length; mipLevel < mipLevels; ++mipLevel) {\n const url = generateUrl(getUrl, options, {...urlOptions, lod: mipLevel});\n urls.push(url);\n }\n\n return urls;\n}\n\n// Calculates number of mipmaps based on texture size (log2)\nexport function getMipLevels({width, height}) {\n return 1 + Math.floor(Math.log2(Math.max(width, height)));\n}\n"],"file":"load-image.js"}
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
exports.VERSION = void 0;
|
|
4
|
-
// Version constant cannot be imported, it needs to correspond to the build version of **this** module.
|
|
5
|
-
// __VERSION__ is injected by babel-plugin-version-inline
|
|
6
|
-
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
7
|
-
exports.VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
1
|
+
export const VERSION = typeof "4.0.0-alpha.5" !== 'undefined' ? "4.0.0-alpha.5" : 'latest';
|
|
2
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/utils/version.ts"],"names":["VERSION"],"mappings":"AAGA,OAAO,MAAMA,OAAO,GAAG,2BAAuB,WAAvB,qBAAmD,QAAnE","sourcesContent":["// Version constant cannot be imported, it needs to correspond to the build version of **this** module.\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nexport const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n"],"file":"version.js"}
|
package/dist/types.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=types.js.map
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/images",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.5",
|
|
4
4
|
"description": "Framework-independent loaders and writers for images (PNG, JPG, ...)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"PLY"
|
|
20
20
|
],
|
|
21
21
|
"types": "dist/index.d.ts",
|
|
22
|
-
"main": "dist/
|
|
23
|
-
"module": "dist/
|
|
22
|
+
"main": "dist/index.js",
|
|
23
|
+
"module": "dist/index.js",
|
|
24
24
|
"sideEffects": false,
|
|
25
25
|
"files": [
|
|
26
26
|
"src",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"build-bundle": "esbuild src/bundle.ts --outfile=dist/dist.min.js --bundle --minify --sourcemap"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@loaders.gl/loader-utils": "
|
|
35
|
+
"@loaders.gl/loader-utils": "4.0.0-alpha.5"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "7a71a54bdf1ddf985cc3af3db90b82e7fa97d025"
|
|
38
38
|
}
|
package/dist/es5/bundle.js
DELETED
package/dist/es5/bundle.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bundle.ts"],"names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"mappings":";;AACA,IAAMA,aAAa,GAAGC,OAAO,CAAC,SAAD,CAA7B;;AACAC,UAAU,CAACC,OAAX,GAAqBD,UAAU,CAACC,OAAX,IAAsB,EAA3C;AACAC,MAAM,CAACC,OAAP,GAAiBC,MAAM,CAACC,MAAP,CAAcL,UAAU,CAACC,OAAzB,EAAkCH,aAAlC,CAAjB","sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.loaders = globalThis.loaders || {};\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"file":"bundle.js"}
|
package/dist/es5/image-loader.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports._typecheckImageLoader = exports.ImageLoader = void 0;
|
|
9
|
-
|
|
10
|
-
var _version = require("./lib/utils/version");
|
|
11
|
-
|
|
12
|
-
var _parseImage = _interopRequireDefault(require("./lib/parsers/parse-image"));
|
|
13
|
-
|
|
14
|
-
var _binaryImageApi = require("./lib/category-api/binary-image-api");
|
|
15
|
-
|
|
16
|
-
var EXTENSIONS = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'ico', 'svg'];
|
|
17
|
-
var MIME_TYPES = ['image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/bmp', 'image/vnd.microsoft.icon', 'image/svg+xml'];
|
|
18
|
-
var DEFAULT_IMAGE_LOADER_OPTIONS = {
|
|
19
|
-
image: {
|
|
20
|
-
type: 'auto',
|
|
21
|
-
decode: true
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
var ImageLoader = {
|
|
25
|
-
id: 'image',
|
|
26
|
-
module: 'images',
|
|
27
|
-
name: 'Images',
|
|
28
|
-
version: _version.VERSION,
|
|
29
|
-
mimeTypes: MIME_TYPES,
|
|
30
|
-
extensions: EXTENSIONS,
|
|
31
|
-
parse: _parseImage.default,
|
|
32
|
-
tests: [function (arrayBuffer) {
|
|
33
|
-
return Boolean((0, _binaryImageApi.getBinaryImageMetadata)(new DataView(arrayBuffer)));
|
|
34
|
-
}],
|
|
35
|
-
options: DEFAULT_IMAGE_LOADER_OPTIONS
|
|
36
|
-
};
|
|
37
|
-
exports.ImageLoader = ImageLoader;
|
|
38
|
-
var _typecheckImageLoader = ImageLoader;
|
|
39
|
-
exports._typecheckImageLoader = _typecheckImageLoader;
|
|
40
|
-
//# sourceMappingURL=image-loader.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/image-loader.ts"],"names":["EXTENSIONS","MIME_TYPES","DEFAULT_IMAGE_LOADER_OPTIONS","image","type","decode","ImageLoader","id","module","name","version","VERSION","mimeTypes","extensions","parse","parseImage","tests","arrayBuffer","Boolean","DataView","options","_typecheckImageLoader"],"mappings":";;;;;;;;;AACA;;AACA;;AACA;;AAEA,IAAMA,UAAU,GAAG,CAAC,KAAD,EAAQ,KAAR,EAAe,MAAf,EAAuB,KAAvB,EAA8B,MAA9B,EAAsC,KAAtC,EAA6C,KAA7C,EAAoD,KAApD,CAAnB;AACA,IAAMC,UAAU,GAAG,CACjB,WADiB,EAEjB,YAFiB,EAGjB,WAHiB,EAIjB,YAJiB,EAKjB,WALiB,EAMjB,0BANiB,EAOjB,eAPiB,CAAnB;AAkBA,IAAMC,4BAAgD,GAAG;AACvDC,EAAAA,KAAK,EAAE;AACLC,IAAAA,IAAI,EAAE,MADD;AAELC,IAAAA,MAAM,EAAE;AAFH;AADgD,CAAzD;AAYO,IAAMC,WAAW,GAAG;AACzBC,EAAAA,EAAE,EAAE,OADqB;AAEzBC,EAAAA,MAAM,EAAE,QAFiB;AAGzBC,EAAAA,IAAI,EAAE,QAHmB;AAIzBC,EAAAA,OAAO,EAAEC,gBAJgB;AAKzBC,EAAAA,SAAS,EAAEX,UALc;AAMzBY,EAAAA,UAAU,EAAEb,UANa;AAOzBc,EAAAA,KAAK,EAAEC,mBAPkB;AASzBC,EAAAA,KAAK,EAAE,CAAC,UAACC,WAAD;AAAA,WAAiBC,OAAO,CAAC,4CAAuB,IAAIC,QAAJ,CAAaF,WAAb,CAAvB,CAAD,CAAxB;AAAA,GAAD,CATkB;AAUzBG,EAAAA,OAAO,EAAElB;AAVgB,CAApB;;AAaA,IAAMmB,qBAAuC,GAAGf,WAAhD","sourcesContent":["import type {LoaderOptions, LoaderWithParser} from '@loaders.gl/loader-utils';\nimport {VERSION} from './lib/utils/version';\nimport parseImage from './lib/parsers/parse-image';\nimport {getBinaryImageMetadata} from './lib/category-api/binary-image-api';\n\nconst EXTENSIONS = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'ico', 'svg'];\nconst MIME_TYPES = [\n 'image/png',\n 'image/jpeg',\n 'image/gif',\n 'image/webp',\n 'image/bmp',\n 'image/vnd.microsoft.icon',\n 'image/svg+xml'\n];\n\nexport type ImageLoaderOptions = LoaderOptions & {\n image?: {\n type?: 'auto' | 'data' | 'imagebitmap' | 'image';\n decode?: boolean;\n };\n imagebitmap?: ImageBitmapOptions;\n};\n\nconst DEFAULT_IMAGE_LOADER_OPTIONS: ImageLoaderOptions = {\n image: {\n type: 'auto',\n decode: true // if format is HTML\n }\n // imagebitmap: {} - passes (platform dependent) parameters to ImageBitmap constructor\n};\n\n/**\n * Loads a platform-specific image type\n * Note: This type can be used as input data to WebGL texture creation\n */\nexport const ImageLoader = {\n id: 'image',\n module: 'images',\n name: 'Images',\n version: VERSION,\n mimeTypes: MIME_TYPES,\n extensions: EXTENSIONS,\n parse: parseImage,\n // TODO: byteOffset, byteLength;\n tests: [(arrayBuffer) => Boolean(getBinaryImageMetadata(new DataView(arrayBuffer)))],\n options: DEFAULT_IMAGE_LOADER_OPTIONS\n};\n\nexport const _typecheckImageLoader: LoaderWithParser = ImageLoader;\n"],"file":"image-loader.js"}
|