@loaders.gl/polyfills 3.3.0 → 3.4.0-alpha.1
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/es5/node/images/parse-image.node.js +18 -30
- package/dist/es5/node/images/parse-image.node.js.map +1 -1
- package/dist/esm/node/images/parse-image.node.js +16 -23
- package/dist/esm/node/images/parse-image.node.js.map +1 -1
- package/dist/lib/encoding.js +1 -1
- package/dist/node/images/parse-image.node.d.ts.map +1 -1
- package/dist/node/images/parse-image.node.js +18 -26
- package/package.json +2 -2
- package/src/node/images/parse-image.node.ts +20 -31
|
@@ -9,29 +9,38 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
|
|
|
9
9
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
10
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
11
|
var _getPixels = _interopRequireDefault(require("get-pixels"));
|
|
12
|
+
var _assert = require("../../utils/assert");
|
|
13
|
+
var _util = _interopRequireDefault(require("util"));
|
|
12
14
|
function parseImageNode(_x, _x2) {
|
|
13
15
|
return _parseImageNode.apply(this, arguments);
|
|
14
16
|
}
|
|
15
17
|
function _parseImageNode() {
|
|
16
18
|
_parseImageNode = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(arrayBuffer, mimeType) {
|
|
17
|
-
var buffer, ndarray;
|
|
19
|
+
var getPixelsAsync, buffer, ndarray, shape, layers, data;
|
|
18
20
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
19
21
|
while (1) {
|
|
20
22
|
switch (_context.prev = _context.next) {
|
|
21
23
|
case 0:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
throw new Error('MIMEType is required to parse image under Node.js');
|
|
27
|
-
case 2:
|
|
24
|
+
(0, _assert.assert)(mimeType, 'MIMEType is required to parse image under Node.js');
|
|
25
|
+
|
|
26
|
+
getPixelsAsync = _util.default.promisify(_getPixels.default);
|
|
28
27
|
buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);
|
|
29
28
|
_context.next = 5;
|
|
30
29
|
return getPixelsAsync(buffer, mimeType);
|
|
31
30
|
case 5:
|
|
32
31
|
ndarray = _context.sent;
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
shape = (0, _toConsumableArray2.default)(ndarray.shape);
|
|
33
|
+
layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;
|
|
34
|
+
data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;
|
|
35
|
+
return _context.abrupt("return", {
|
|
36
|
+
shape: shape,
|
|
37
|
+
data: data,
|
|
38
|
+
width: ndarray.shape[0],
|
|
39
|
+
height: ndarray.shape[1],
|
|
40
|
+
components: ndarray.shape[2],
|
|
41
|
+
layers: layers
|
|
42
|
+
});
|
|
43
|
+
case 10:
|
|
35
44
|
case "end":
|
|
36
45
|
return _context.stop();
|
|
37
46
|
}
|
|
@@ -40,25 +49,4 @@ function _parseImageNode() {
|
|
|
40
49
|
}));
|
|
41
50
|
return _parseImageNode.apply(this, arguments);
|
|
42
51
|
}
|
|
43
|
-
function getPixelsAsync(buffer, mimeType) {
|
|
44
|
-
return new Promise(function (resolve) {
|
|
45
|
-
return (0, _getPixels.default)(buffer, mimeType, function (err, ndarray) {
|
|
46
|
-
if (err) {
|
|
47
|
-
throw err;
|
|
48
|
-
}
|
|
49
|
-
var shape = (0, _toConsumableArray2.default)(ndarray.shape);
|
|
50
|
-
var layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;
|
|
51
|
-
var data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;
|
|
52
|
-
|
|
53
|
-
resolve({
|
|
54
|
-
shape: shape,
|
|
55
|
-
data: data,
|
|
56
|
-
width: ndarray.shape[0],
|
|
57
|
-
height: ndarray.shape[1],
|
|
58
|
-
components: ndarray.shape[2],
|
|
59
|
-
layers: layers ? [layers] : []
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
52
|
//# sourceMappingURL=parse-image.node.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-image.node.js","names":["parseImageNode","arrayBuffer","mimeType","
|
|
1
|
+
{"version":3,"file":"parse-image.node.js","names":["parseImageNode","arrayBuffer","mimeType","assert","getPixelsAsync","util","promisify","getPixels","buffer","Buffer","from","ndarray","shape","layers","length","shift","data","Uint8Array","width","height","components"],"sources":["../../../../src/node/images/parse-image.node.ts"],"sourcesContent":["import getPixels from 'get-pixels';\nimport {assert} from '../../utils/assert';\nimport util from 'util';\n\n// Note: These types are also defined in @loaders.gl/images and need to be kept in sync\ntype NDArray = {\n shape: number[];\n data: Uint8Array;\n width: number;\n height: number;\n components: number;\n layers: number[];\n};\n\nexport async function parseImageNode(arrayBuffer: ArrayBuffer, mimeType: string): Promise<NDArray> {\n assert(mimeType, 'MIMEType is required to parse image under Node.js');\n\n // TODO - check if getPixels callback is asynchronous if provided with buffer input\n // if not, parseImage can be a sync function\n const getPixelsAsync = util.promisify(getPixels);\n\n const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);\n\n const ndarray = await getPixelsAsync(buffer, mimeType);\n\n const shape = [...ndarray.shape];\n const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;\n const data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;\n\n // extract width/height etc\n return {\n shape,\n data,\n width: ndarray.shape[0],\n height: ndarray.shape[1],\n components: ndarray.shape[2],\n layers\n };\n}\n"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AAAwB,SAYFA,cAAc;EAAA;AAAA;AAAA;EAAA,4EAA7B,iBAA8BC,WAAwB,EAAEC,QAAgB;IAAA;IAAA;MAAA;QAAA;UAAA;YAC7E,IAAAC,cAAM,EAACD,QAAQ,EAAE,mDAAmD,CAAC;;YAI/DE,cAAc,GAAGC,aAAI,CAACC,SAAS,CAACC,kBAAS,CAAC;YAE1CC,MAAM,GAAGP,WAAW,YAAYQ,MAAM,GAAGR,WAAW,GAAGQ,MAAM,CAACC,IAAI,CAACT,WAAW,CAAC;YAAA;YAAA,OAE/DG,cAAc,CAACI,MAAM,EAAEN,QAAQ,CAAC;UAAA;YAAhDS,OAAO;YAEPC,KAAK,oCAAOD,OAAO,CAACC,KAAK;YACzBC,MAAM,GAAGF,OAAO,CAACC,KAAK,CAACE,MAAM,KAAK,CAAC,GAAGH,OAAO,CAACC,KAAK,CAACG,KAAK,EAAE,GAAG,CAAC;YAC/DC,IAAI,GAAGL,OAAO,CAACK,IAAI,YAAYP,MAAM,GAAG,IAAIQ,UAAU,CAACN,OAAO,CAACK,IAAI,CAAC,GAAGL,OAAO,CAACK,IAAI;YAAA,iCAGlF;cACLJ,KAAK,EAALA,KAAK;cACLI,IAAI,EAAJA,IAAI;cACJE,KAAK,EAAEP,OAAO,CAACC,KAAK,CAAC,CAAC,CAAC;cACvBO,MAAM,EAAER,OAAO,CAACC,KAAK,CAAC,CAAC,CAAC;cACxBQ,UAAU,EAAET,OAAO,CAACC,KAAK,CAAC,CAAC,CAAC;cAC5BC,MAAM,EAANA;YACF,CAAC;UAAA;UAAA;YAAA;QAAA;MAAA;IAAA;EAAA,CACF;EAAA;AAAA"}
|
|
@@ -1,31 +1,24 @@
|
|
|
1
1
|
import getPixels from 'get-pixels';
|
|
2
|
+
import { assert } from '../../utils/assert';
|
|
3
|
+
import util from 'util';
|
|
2
4
|
|
|
3
5
|
export async function parseImageNode(arrayBuffer, mimeType) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
assert(mimeType, 'MIMEType is required to parse image under Node.js');
|
|
7
|
+
|
|
8
|
+
const getPixelsAsync = util.promisify(getPixels);
|
|
7
9
|
const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);
|
|
8
10
|
const ndarray = await getPixelsAsync(buffer, mimeType);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function getPixelsAsync(buffer, mimeType) {
|
|
13
|
-
return new Promise(resolve => getPixels(buffer, mimeType, (err, ndarray) => {
|
|
14
|
-
if (err) {
|
|
15
|
-
throw err;
|
|
16
|
-
}
|
|
17
|
-
const shape = [...ndarray.shape];
|
|
18
|
-
const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;
|
|
19
|
-
const data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;
|
|
11
|
+
const shape = [...ndarray.shape];
|
|
12
|
+
const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;
|
|
13
|
+
const data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;
|
|
20
14
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}));
|
|
15
|
+
return {
|
|
16
|
+
shape,
|
|
17
|
+
data,
|
|
18
|
+
width: ndarray.shape[0],
|
|
19
|
+
height: ndarray.shape[1],
|
|
20
|
+
components: ndarray.shape[2],
|
|
21
|
+
layers
|
|
22
|
+
};
|
|
30
23
|
}
|
|
31
24
|
//# sourceMappingURL=parse-image.node.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-image.node.js","names":["getPixels","
|
|
1
|
+
{"version":3,"file":"parse-image.node.js","names":["getPixels","assert","util","parseImageNode","arrayBuffer","mimeType","getPixelsAsync","promisify","buffer","Buffer","from","ndarray","shape","layers","length","shift","data","Uint8Array","width","height","components"],"sources":["../../../../src/node/images/parse-image.node.ts"],"sourcesContent":["import getPixels from 'get-pixels';\nimport {assert} from '../../utils/assert';\nimport util from 'util';\n\n// Note: These types are also defined in @loaders.gl/images and need to be kept in sync\ntype NDArray = {\n shape: number[];\n data: Uint8Array;\n width: number;\n height: number;\n components: number;\n layers: number[];\n};\n\nexport async function parseImageNode(arrayBuffer: ArrayBuffer, mimeType: string): Promise<NDArray> {\n assert(mimeType, 'MIMEType is required to parse image under Node.js');\n\n // TODO - check if getPixels callback is asynchronous if provided with buffer input\n // if not, parseImage can be a sync function\n const getPixelsAsync = util.promisify(getPixels);\n\n const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);\n\n const ndarray = await getPixelsAsync(buffer, mimeType);\n\n const shape = [...ndarray.shape];\n const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;\n const data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;\n\n // extract width/height etc\n return {\n shape,\n data,\n width: ndarray.shape[0],\n height: ndarray.shape[1],\n components: ndarray.shape[2],\n layers\n };\n}\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,YAAY;AAClC,SAAQC,MAAM,QAAO,oBAAoB;AACzC,OAAOC,IAAI,MAAM,MAAM;;AAYvB,OAAO,eAAeC,cAAc,CAACC,WAAwB,EAAEC,QAAgB,EAAoB;EACjGJ,MAAM,CAACI,QAAQ,EAAE,mDAAmD,CAAC;;EAIrE,MAAMC,cAAc,GAAGJ,IAAI,CAACK,SAAS,CAACP,SAAS,CAAC;EAEhD,MAAMQ,MAAM,GAAGJ,WAAW,YAAYK,MAAM,GAAGL,WAAW,GAAGK,MAAM,CAACC,IAAI,CAACN,WAAW,CAAC;EAErF,MAAMO,OAAO,GAAG,MAAML,cAAc,CAACE,MAAM,EAAEH,QAAQ,CAAC;EAEtD,MAAMO,KAAK,GAAG,CAAC,GAAGD,OAAO,CAACC,KAAK,CAAC;EAChC,MAAMC,MAAM,GAAGF,OAAO,CAACC,KAAK,CAACE,MAAM,KAAK,CAAC,GAAGH,OAAO,CAACC,KAAK,CAACG,KAAK,EAAE,GAAG,CAAC;EACrE,MAAMC,IAAI,GAAGL,OAAO,CAACK,IAAI,YAAYP,MAAM,GAAG,IAAIQ,UAAU,CAACN,OAAO,CAACK,IAAI,CAAC,GAAGL,OAAO,CAACK,IAAI;;EAGzF,OAAO;IACLJ,KAAK;IACLI,IAAI;IACJE,KAAK,EAAEP,OAAO,CAACC,KAAK,CAAC,CAAC,CAAC;IACvBO,MAAM,EAAER,OAAO,CAACC,KAAK,CAAC,CAAC,CAAC;IACxBQ,UAAU,EAAET,OAAO,CAACC,KAAK,CAAC,CAAC,CAAC;IAC5BC;EACF,CAAC;AACH"}
|
package/dist/lib/encoding.js
CHANGED
|
@@ -11,7 +11,7 @@ exports.TextDecoder = exports.TextEncoder = void 0;
|
|
|
11
11
|
// See LICENSE.md for more information.
|
|
12
12
|
const encoding_indexes_1 = __importDefault(require("./encoding-indexes"));
|
|
13
13
|
// Note: Aaian character indices add half a megabyte to bundle. Ignore, since we really only want the built-in UTF8...
|
|
14
|
-
// import indexes from './encoding-indexes-asian';
|
|
14
|
+
// import indexes from './encoding-indexes-asian.js';
|
|
15
15
|
global['encoding-indexes'] = encoding_indexes_1.default || {};
|
|
16
16
|
//
|
|
17
17
|
// Utilities
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-image.node.d.ts","sourceRoot":"","sources":["../../../src/node/images/parse-image.node.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-image.node.d.ts","sourceRoot":"","sources":["../../../src/node/images/parse-image.node.ts"],"names":[],"mappings":"AAKA,KAAK,OAAO,GAAG;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF,wBAAsB,cAAc,CAAC,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAwBjG"}
|
|
@@ -5,34 +5,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.parseImageNode = void 0;
|
|
7
7
|
const get_pixels_1 = __importDefault(require("get-pixels"));
|
|
8
|
+
const assert_1 = require("../../utils/assert");
|
|
9
|
+
const util_1 = __importDefault(require("util"));
|
|
8
10
|
async function parseImageNode(arrayBuffer, mimeType) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
(0, assert_1.assert)(mimeType, 'MIMEType is required to parse image under Node.js');
|
|
12
|
+
// TODO - check if getPixels callback is asynchronous if provided with buffer input
|
|
13
|
+
// if not, parseImage can be a sync function
|
|
14
|
+
const getPixelsAsync = util_1.default.promisify(get_pixels_1.default);
|
|
12
15
|
const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);
|
|
13
16
|
const ndarray = await getPixelsAsync(buffer, mimeType);
|
|
14
|
-
|
|
17
|
+
const shape = [...ndarray.shape];
|
|
18
|
+
const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;
|
|
19
|
+
const data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;
|
|
20
|
+
// extract width/height etc
|
|
21
|
+
return {
|
|
22
|
+
shape,
|
|
23
|
+
data,
|
|
24
|
+
width: ndarray.shape[0],
|
|
25
|
+
height: ndarray.shape[1],
|
|
26
|
+
components: ndarray.shape[2],
|
|
27
|
+
layers
|
|
28
|
+
};
|
|
15
29
|
}
|
|
16
30
|
exports.parseImageNode = parseImageNode;
|
|
17
|
-
// TODO - check if getPixels callback is asynchronous if provided with buffer input
|
|
18
|
-
// if not, parseImage can be a sync function
|
|
19
|
-
function getPixelsAsync(buffer, mimeType) {
|
|
20
|
-
return new Promise((resolve) => (0, get_pixels_1.default)(buffer, mimeType, (err, ndarray) => {
|
|
21
|
-
if (err) {
|
|
22
|
-
throw err;
|
|
23
|
-
}
|
|
24
|
-
const shape = [...ndarray.shape];
|
|
25
|
-
const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;
|
|
26
|
-
const data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;
|
|
27
|
-
// extract width/height etc
|
|
28
|
-
resolve({
|
|
29
|
-
shape,
|
|
30
|
-
data,
|
|
31
|
-
width: ndarray.shape[0],
|
|
32
|
-
height: ndarray.shape[1],
|
|
33
|
-
components: ndarray.shape[2],
|
|
34
|
-
// TODO - error
|
|
35
|
-
layers: layers ? [layers] : []
|
|
36
|
-
});
|
|
37
|
-
}));
|
|
38
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/polyfills",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0-alpha.1",
|
|
4
4
|
"description": "Polyfills for TextEncoder/TextDecoder",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -106,5 +106,5 @@
|
|
|
106
106
|
"through": "^2.3.8",
|
|
107
107
|
"web-streams-polyfill": "^3.0.0"
|
|
108
108
|
},
|
|
109
|
-
"gitHead": "
|
|
109
|
+
"gitHead": "4085b0323050e4361614471319a1fb4729547bbf"
|
|
110
110
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import getPixels from 'get-pixels';
|
|
2
|
+
import {assert} from '../../utils/assert';
|
|
3
|
+
import util from 'util';
|
|
2
4
|
|
|
3
5
|
// Note: These types are also defined in @loaders.gl/images and need to be kept in sync
|
|
4
6
|
type NDArray = {
|
|
@@ -11,40 +13,27 @@ type NDArray = {
|
|
|
11
13
|
};
|
|
12
14
|
|
|
13
15
|
export async function parseImageNode(arrayBuffer: ArrayBuffer, mimeType: string): Promise<NDArray> {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
assert(mimeType, 'MIMEType is required to parse image under Node.js');
|
|
17
|
+
|
|
18
|
+
// TODO - check if getPixels callback is asynchronous if provided with buffer input
|
|
19
|
+
// if not, parseImage can be a sync function
|
|
20
|
+
const getPixelsAsync = util.promisify(getPixels);
|
|
17
21
|
|
|
18
22
|
const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);
|
|
19
23
|
|
|
20
24
|
const ndarray = await getPixelsAsync(buffer, mimeType);
|
|
21
25
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;
|
|
36
|
-
const data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;
|
|
37
|
-
|
|
38
|
-
// extract width/height etc
|
|
39
|
-
resolve({
|
|
40
|
-
shape,
|
|
41
|
-
data,
|
|
42
|
-
width: ndarray.shape[0],
|
|
43
|
-
height: ndarray.shape[1],
|
|
44
|
-
components: ndarray.shape[2],
|
|
45
|
-
// TODO - error
|
|
46
|
-
layers: layers ? [layers] : []
|
|
47
|
-
});
|
|
48
|
-
})
|
|
49
|
-
);
|
|
26
|
+
const shape = [...ndarray.shape];
|
|
27
|
+
const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;
|
|
28
|
+
const data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;
|
|
29
|
+
|
|
30
|
+
// extract width/height etc
|
|
31
|
+
return {
|
|
32
|
+
shape,
|
|
33
|
+
data,
|
|
34
|
+
width: ndarray.shape[0],
|
|
35
|
+
height: ndarray.shape[1],
|
|
36
|
+
components: ndarray.shape[2],
|
|
37
|
+
layers
|
|
38
|
+
};
|
|
50
39
|
}
|