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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dist.min.js CHANGED
@@ -4111,6 +4111,7 @@
4111
4111
  }
4112
4112
  if (!isBrowser && !("_parseImageNode" in global_) && import_parse_image.parseImageNode) {
4113
4113
  global_["_parseImageNode"] = import_parse_image.parseImageNode;
4114
+ global_["_imageFormatsNode"] = import_parse_image.NODE_FORMAT_SUPPORT;
4114
4115
  }
4115
4116
  if (!("allSettled" in Promise)) {
4116
4117
  Promise.allSettled = allSettled;
package/dist/es5/index.js CHANGED
@@ -100,6 +100,7 @@ if (!_globals.isBrowser && !('_encodeImageNode' in _globals.global) && _encodeIm
100
100
  }
101
101
  if (!_globals.isBrowser && !('_parseImageNode' in _globals.global) && _parseImage.parseImageNode) {
102
102
  _globals.global['_parseImageNode'] = _parseImage.parseImageNode;
103
+ _globals.global['_imageFormatsNode'] = _parseImage.NODE_FORMAT_SUPPORT;
103
104
  }
104
105
  if (!('allSettled' in Promise)) {
105
106
  Promise.allSettled = _allSettled.allSettled;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["installTextEncoder","isBrowser","global","TextEncoder","installTextDecoder","TextDecoder","base64","atob","btoa","HeadersNode","ResponseNode","fetchNode","DOMParser","encodeImageNode","parseImageNode","Promise","allSettled"],"sources":["../../src/index.ts"],"sourcesContent":["/* eslint-disable dot-notation */\nimport {DOMParser} from '@xmldom/xmldom';\nimport {isBrowser, global} from './utils/globals';\n\nimport {TextDecoder, TextEncoder} from './lib/encoding';\nimport {allSettled} from './promise/all-settled';\n\n// Node specific\nimport * as base64 from './node/buffer/btoa.node';\n\nimport {Headers as HeadersNode} from './node/fetch/headers.node';\nimport {Response as ResponseNode} from './node/fetch/response.node';\nimport {fetchNode as fetchNode} from './node/fetch/fetch.node';\n\nimport {encodeImageNode} from './node/images/encode-image.node';\nimport {parseImageNode} from './node/images/parse-image.node';\n\nexport {ReadableStreamPolyfill} from './node/file/readable-stream';\nexport {BlobPolyfill} from './node/file/blob';\nexport {FileReaderPolyfill} from './node/file/file-reader';\nexport {FilePolyfill} from './node/file/file';\nexport {installFilePolyfills} from './node/file/install-file-polyfills';\nexport {fetchNode as _fetchNode} from './node/fetch/fetch.node';\nexport {fetchFileNode as _fetchFileNode} from './node/fetch/fetch-file.node';\n\n// POLYFILLS: TextEncoder, TextDecoder\n// - Recent Node versions have these classes but virtually no encodings unless special build.\n// - Browser: Edge, IE11 do not have these\n\nconst installTextEncoder = !isBrowser || !('TextEncoder' in global);\nif (installTextEncoder) {\n global['TextEncoder'] = TextEncoder;\n}\n\nconst installTextDecoder = !isBrowser || !('TextDecoder' in global);\nif (installTextDecoder) {\n global['TextDecoder'] = TextDecoder;\n}\n\n// POLYFILLS: btoa, atob\n// - Node: Yes\n// - Browser: No\n\nif (!isBrowser && !('atob' in global) && base64.atob) {\n global['atob'] = base64.atob;\n}\nif (!isBrowser && !('btoa' in global) && base64.btoa) {\n global['btoa'] = base64.btoa;\n}\n\n// POLYFILL: fetch\n// - Node: Yes\n// - Browser: No. For This polyfill is node only, IE11 etc, install external polyfill\n\nif (!isBrowser && !('Headers' in global) && HeadersNode) {\n global['Headers'] = HeadersNode;\n}\n\nif (!isBrowser && !('Response' in global) && ResponseNode) {\n global['Response'] = ResponseNode;\n}\n\nif (!isBrowser && !('fetch' in global) && fetchNode) {\n global['fetch'] = fetchNode;\n}\n\n// POLYFILL: DOMParser\n// - Node: Yes\n// - Browser: No\n\nif (!isBrowser && !('DOMParser' in global) && DOMParser) {\n global['DOMParser'] = DOMParser;\n}\n\n// NODE IMAGE FUNCTIONS:\n// These are not official polyfills but used by the @loaders.gl/images module if installed\n// TODO - is there an appropriate Image API we could polyfill using an adapter?\n\nif (!isBrowser && !('_encodeImageNode' in global) && encodeImageNode) {\n global['_encodeImageNode'] = encodeImageNode;\n}\n\nif (!isBrowser && !('_parseImageNode' in global) && parseImageNode) {\n global['_parseImageNode'] = parseImageNode;\n}\n\nif (!('allSettled' in Promise)) {\n // @ts-ignore\n Promise.allSettled = allSettled;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;AACA;AAEA;AACA;AAGA;AAEA;AACA;AACA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AAA6E;AAAA;;AAM7E,IAAMA,kBAAkB,GAAG,CAACC,kBAAS,IAAI,EAAE,aAAa,IAAIC,eAAM,CAAC;AACnE,IAAIF,kBAAkB,EAAE;EACtBE,eAAM,CAAC,aAAa,CAAC,GAAGC,qBAAW;AACrC;AAEA,IAAMC,kBAAkB,GAAG,CAACH,kBAAS,IAAI,EAAE,aAAa,IAAIC,eAAM,CAAC;AACnE,IAAIE,kBAAkB,EAAE;EACtBF,eAAM,CAAC,aAAa,CAAC,GAAGG,qBAAW;AACrC;;AAMA,IAAI,CAACJ,kBAAS,IAAI,EAAE,MAAM,IAAIC,eAAM,CAAC,IAAII,MAAM,CAACC,IAAI,EAAE;EACpDL,eAAM,CAAC,MAAM,CAAC,GAAGI,MAAM,CAACC,IAAI;AAC9B;AACA,IAAI,CAACN,kBAAS,IAAI,EAAE,MAAM,IAAIC,eAAM,CAAC,IAAII,MAAM,CAACE,IAAI,EAAE;EACpDN,eAAM,CAAC,MAAM,CAAC,GAAGI,MAAM,CAACE,IAAI;AAC9B;;AAMA,IAAI,CAACP,kBAAS,IAAI,EAAE,SAAS,IAAIC,eAAM,CAAC,IAAIO,gBAAW,EAAE;EACvDP,eAAM,CAAC,SAAS,CAAC,GAAGO,gBAAW;AACjC;AAEA,IAAI,CAACR,kBAAS,IAAI,EAAE,UAAU,IAAIC,eAAM,CAAC,IAAIQ,kBAAY,EAAE;EACzDR,eAAM,CAAC,UAAU,CAAC,GAAGQ,kBAAY;AACnC;AAEA,IAAI,CAACT,kBAAS,IAAI,EAAE,OAAO,IAAIC,eAAM,CAAC,IAAIS,gBAAS,EAAE;EACnDT,eAAM,CAAC,OAAO,CAAC,GAAGS,gBAAS;AAC7B;;AAMA,IAAI,CAACV,kBAAS,IAAI,EAAE,WAAW,IAAIC,eAAM,CAAC,IAAIU,iBAAS,EAAE;EACvDV,eAAM,CAAC,WAAW,CAAC,GAAGU,iBAAS;AACjC;;AAMA,IAAI,CAACX,kBAAS,IAAI,EAAE,kBAAkB,IAAIC,eAAM,CAAC,IAAIW,4BAAe,EAAE;EACpEX,eAAM,CAAC,kBAAkB,CAAC,GAAGW,4BAAe;AAC9C;AAEA,IAAI,CAACZ,kBAAS,IAAI,EAAE,iBAAiB,IAAIC,eAAM,CAAC,IAAIY,0BAAc,EAAE;EAClEZ,eAAM,CAAC,iBAAiB,CAAC,GAAGY,0BAAc;AAC5C;AAEA,IAAI,EAAE,YAAY,IAAIC,OAAO,CAAC,EAAE;EAE9BA,OAAO,CAACC,UAAU,GAAGA,sBAAU;AACjC"}
1
+ {"version":3,"file":"index.js","names":["installTextEncoder","isBrowser","global","TextEncoder","installTextDecoder","TextDecoder","base64","atob","btoa","HeadersNode","ResponseNode","fetchNode","DOMParser","encodeImageNode","parseImageNode","NODE_FORMAT_SUPPORT","Promise","allSettled"],"sources":["../../src/index.ts"],"sourcesContent":["/* eslint-disable dot-notation */\nimport {DOMParser} from '@xmldom/xmldom';\nimport {isBrowser, global} from './utils/globals';\n\nimport {TextDecoder, TextEncoder} from './lib/encoding';\nimport {allSettled} from './promise/all-settled';\n\n// Node specific\nimport * as base64 from './node/buffer/btoa.node';\n\nimport {Headers as HeadersNode} from './node/fetch/headers.node';\nimport {Response as ResponseNode} from './node/fetch/response.node';\nimport {fetchNode as fetchNode} from './node/fetch/fetch.node';\n\nimport {encodeImageNode} from './node/images/encode-image.node';\nimport {parseImageNode, NODE_FORMAT_SUPPORT} from './node/images/parse-image.node';\n\nexport {ReadableStreamPolyfill} from './node/file/readable-stream';\nexport {BlobPolyfill} from './node/file/blob';\nexport {FileReaderPolyfill} from './node/file/file-reader';\nexport {FilePolyfill} from './node/file/file';\nexport {installFilePolyfills} from './node/file/install-file-polyfills';\nexport {fetchNode as _fetchNode} from './node/fetch/fetch.node';\nexport {fetchFileNode as _fetchFileNode} from './node/fetch/fetch-file.node';\n\n// POLYFILLS: TextEncoder, TextDecoder\n// - Recent Node versions have these classes but virtually no encodings unless special build.\n// - Browser: Edge, IE11 do not have these\n\nconst installTextEncoder = !isBrowser || !('TextEncoder' in global);\nif (installTextEncoder) {\n global['TextEncoder'] = TextEncoder;\n}\n\nconst installTextDecoder = !isBrowser || !('TextDecoder' in global);\nif (installTextDecoder) {\n global['TextDecoder'] = TextDecoder;\n}\n\n// POLYFILLS: btoa, atob\n// - Node: Yes\n// - Browser: No\n\nif (!isBrowser && !('atob' in global) && base64.atob) {\n global['atob'] = base64.atob;\n}\nif (!isBrowser && !('btoa' in global) && base64.btoa) {\n global['btoa'] = base64.btoa;\n}\n\n// POLYFILL: fetch\n// - Node: Yes\n// - Browser: No. For This polyfill is node only, IE11 etc, install external polyfill\n\nif (!isBrowser && !('Headers' in global) && HeadersNode) {\n global['Headers'] = HeadersNode;\n}\n\nif (!isBrowser && !('Response' in global) && ResponseNode) {\n global['Response'] = ResponseNode;\n}\n\nif (!isBrowser && !('fetch' in global) && fetchNode) {\n global['fetch'] = fetchNode;\n}\n\n// POLYFILL: DOMParser\n// - Node: Yes\n// - Browser: No\n\nif (!isBrowser && !('DOMParser' in global) && DOMParser) {\n global['DOMParser'] = DOMParser;\n}\n\n// NODE IMAGE FUNCTIONS:\n// These are not official polyfills but used by the @loaders.gl/images module if installed\n// TODO - is there an appropriate Image API we could polyfill using an adapter?\n\nif (!isBrowser && !('_encodeImageNode' in global) && encodeImageNode) {\n global['_encodeImageNode'] = encodeImageNode;\n}\n\nif (!isBrowser && !('_parseImageNode' in global) && parseImageNode) {\n global['_parseImageNode'] = parseImageNode;\n global['_imageFormatsNode'] = NODE_FORMAT_SUPPORT;\n}\n\nif (!('allSettled' in Promise)) {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S;AAC7B;;AAMA,IAAI,CAACV,kBAAS,IAAI,EAAE,WAAW,IAAIC,eAAM,CAAC,IAAIU,iBAAS,EAAE;EACvDV,eAAM,CAAC,WAAW,CAAC,GAAGU,iBAAS;AACjC;;AAMA,IAAI,CAACX,kBAAS,IAAI,EAAE,kBAAkB,IAAIC,eAAM,CAAC,IAAIW,4BAAe,EAAE;EACpEX,eAAM,CAAC,kBAAkB,CAAC,GAAGW,4BAAe;AAC9C;AAEA,IAAI,CAACZ,kBAAS,IAAI,EAAE,iBAAiB,IAAIC,eAAM,CAAC,IAAIY,0BAAc,EAAE;EAClEZ,eAAM,CAAC,iBAAiB,CAAC,GAAGY,0BAAc;EAC1CZ,eAAM,CAAC,mBAAmB,CAAC,GAAGa,+BAAmB;AACnD;AAEA,IAAI,EAAE,YAAY,IAAIC,OAAO,CAAC,EAAE;EAE9BA,OAAO,CAACC,UAAU,GAAGA,sBAAU;AACjC"}
@@ -4,11 +4,16 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
+ exports.NODE_FORMAT_SUPPORT = void 0;
7
8
  exports.parseImageNode = parseImageNode;
8
9
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
10
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
11
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
12
  var _getPixels = _interopRequireDefault(require("get-pixels"));
13
+
14
+ var NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];
15
+
16
+ exports.NODE_FORMAT_SUPPORT = NODE_FORMAT_SUPPORT;
12
17
  function parseImageNode(_x, _x2) {
13
18
  return _parseImageNode.apply(this, arguments);
14
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"parse-image.node.js","names":["parseImageNode","arrayBuffer","mimeType","Error","buffer","Buffer","from","getPixelsAsync","ndarray","Promise","resolve","getPixels","err","shape","layers","length","shift","data","Uint8Array","width","height","components"],"sources":["../../../../src/node/images/parse-image.node.ts"],"sourcesContent":["import getPixels from 'get-pixels';\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 if (!mimeType) {\n throw new Error('MIMEType is required to parse image under Node.js');\n }\n\n const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);\n\n const ndarray = await getPixelsAsync(buffer, mimeType);\n\n return ndarray;\n}\n\n// TODO - check if getPixels callback is asynchronous if provided with buffer input\n// if not, parseImage can be a sync function\nfunction getPixelsAsync(buffer: Buffer, mimeType: string): Promise<NDArray> {\n return new Promise<NDArray>((resolve) =>\n getPixels(buffer, mimeType, (err, ndarray) => {\n if (err) {\n throw err;\n }\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 resolve({\n shape,\n data,\n width: ndarray.shape[0],\n height: ndarray.shape[1],\n components: ndarray.shape[2],\n // TODO - error\n layers: layers ? [layers] : []\n });\n })\n );\n}\n"],"mappings":";;;;;;;;;;AAAA;AAAmC,SAYbA,cAAc;EAAA;AAAA;AAAA;EAAA,4EAA7B,iBAA8BC,WAAwB,EAAEC,QAAgB;IAAA;IAAA;MAAA;QAAA;UAAA;YAAA,IACxEA,QAAQ;cAAA;cAAA;YAAA;YAAA,MACL,IAAIC,KAAK,CAAC,mDAAmD,CAAC;UAAA;YAGhEC,MAAM,GAAGH,WAAW,YAAYI,MAAM,GAAGJ,WAAW,GAAGI,MAAM,CAACC,IAAI,CAACL,WAAW,CAAC;YAAA;YAAA,OAE/DM,cAAc,CAACH,MAAM,EAAEF,QAAQ,CAAC;UAAA;YAAhDM,OAAO;YAAA,iCAENA,OAAO;UAAA;UAAA;YAAA;QAAA;MAAA;IAAA;EAAA,CACf;EAAA;AAAA;AAID,SAASD,cAAc,CAACH,MAAc,EAAEF,QAAgB,EAAoB;EAC1E,OAAO,IAAIO,OAAO,CAAU,UAACC,OAAO;IAAA,OAClC,IAAAC,kBAAS,EAACP,MAAM,EAAEF,QAAQ,EAAE,UAACU,GAAG,EAAEJ,OAAO,EAAK;MAC5C,IAAII,GAAG,EAAE;QACP,MAAMA,GAAG;MACX;MAEA,IAAMC,KAAK,oCAAOL,OAAO,CAACK,KAAK,CAAC;MAChC,IAAMC,MAAM,GAAGN,OAAO,CAACK,KAAK,CAACE,MAAM,KAAK,CAAC,GAAGP,OAAO,CAACK,KAAK,CAACG,KAAK,EAAE,GAAG,CAAC;MACrE,IAAMC,IAAI,GAAGT,OAAO,CAACS,IAAI,YAAYZ,MAAM,GAAG,IAAIa,UAAU,CAACV,OAAO,CAACS,IAAI,CAAC,GAAGT,OAAO,CAACS,IAAI;;MAGzFP,OAAO,CAAC;QACNG,KAAK,EAALA,KAAK;QACLI,IAAI,EAAJA,IAAI;QACJE,KAAK,EAAEX,OAAO,CAACK,KAAK,CAAC,CAAC,CAAC;QACvBO,MAAM,EAAEZ,OAAO,CAACK,KAAK,CAAC,CAAC,CAAC;QACxBQ,UAAU,EAAEb,OAAO,CAACK,KAAK,CAAC,CAAC,CAAC;QAE5BC,MAAM,EAAEA,MAAM,GAAG,CAACA,MAAM,CAAC,GAAG;MAC9B,CAAC,CAAC;IACJ,CAAC,CAAC;EAAA,EACH;AACH"}
1
+ {"version":3,"file":"parse-image.node.js","names":["NODE_FORMAT_SUPPORT","parseImageNode","arrayBuffer","mimeType","Error","buffer","Buffer","from","getPixelsAsync","ndarray","Promise","resolve","getPixels","err","shape","layers","length","shift","data","Uint8Array","width","height","components"],"sources":["../../../../src/node/images/parse-image.node.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport getPixels from 'get-pixels';\n\n/** Declares which image format mime types this loader polyfill supports */\nexport const NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];\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 if (!mimeType) {\n throw new Error('MIMEType is required to parse image under Node.js');\n }\n\n const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);\n const ndarray = await getPixelsAsync(buffer, mimeType);\n return ndarray;\n}\n\n// TODO - check if getPixels callback is asynchronous if provided with buffer input\n// if not, parseImage can be a sync function\nfunction getPixelsAsync(buffer: Buffer, mimeType: string): Promise<NDArray> {\n return new Promise<NDArray>((resolve) =>\n getPixels(buffer, mimeType, (err, ndarray) => {\n if (err) {\n throw err;\n }\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 resolve({\n shape,\n data,\n width: ndarray.shape[0],\n height: ndarray.shape[1],\n components: ndarray.shape[2],\n // TODO - error\n layers: layers ? [layers] : []\n });\n })\n );\n}\n"],"mappings":";;;;;;;;;;;AAEA;;AAGO,IAAMA,mBAAmB,GAAG,CAAC,WAAW,EAAE,YAAY,EAAE,WAAW,CAAC;;AAAC;AAAA,SAYtDC,cAAc;EAAA;AAAA;AAAA;EAAA,4EAA7B,iBAA8BC,WAAwB,EAAEC,QAAgB;IAAA;IAAA;MAAA;QAAA;UAAA;YAAA,IACxEA,QAAQ;cAAA;cAAA;YAAA;YAAA,MACL,IAAIC,KAAK,CAAC,mDAAmD,CAAC;UAAA;YAGhEC,MAAM,GAAGH,WAAW,YAAYI,MAAM,GAAGJ,WAAW,GAAGI,MAAM,CAACC,IAAI,CAACL,WAAW,CAAC;YAAA;YAAA,OAC/DM,cAAc,CAACH,MAAM,EAAEF,QAAQ,CAAC;UAAA;YAAhDM,OAAO;YAAA,iCACNA,OAAO;UAAA;UAAA;YAAA;QAAA;MAAA;IAAA;EAAA,CACf;EAAA;AAAA;AAID,SAASD,cAAc,CAACH,MAAc,EAAEF,QAAgB,EAAoB;EAC1E,OAAO,IAAIO,OAAO,CAAU,UAACC,OAAO;IAAA,OAClC,IAAAC,kBAAS,EAACP,MAAM,EAAEF,QAAQ,EAAE,UAACU,GAAG,EAAEJ,OAAO,EAAK;MAC5C,IAAII,GAAG,EAAE;QACP,MAAMA,GAAG;MACX;MAEA,IAAMC,KAAK,oCAAOL,OAAO,CAACK,KAAK,CAAC;MAChC,IAAMC,MAAM,GAAGN,OAAO,CAACK,KAAK,CAACE,MAAM,KAAK,CAAC,GAAGP,OAAO,CAACK,KAAK,CAACG,KAAK,EAAE,GAAG,CAAC;MACrE,IAAMC,IAAI,GAAGT,OAAO,CAACS,IAAI,YAAYZ,MAAM,GAAG,IAAIa,UAAU,CAACV,OAAO,CAACS,IAAI,CAAC,GAAGT,OAAO,CAACS,IAAI;;MAGzFP,OAAO,CAAC;QACNG,KAAK,EAALA,KAAK;QACLI,IAAI,EAAJA,IAAI;QACJE,KAAK,EAAEX,OAAO,CAACK,KAAK,CAAC,CAAC,CAAC;QACvBO,MAAM,EAAEZ,OAAO,CAACK,KAAK,CAAC,CAAC,CAAC;QACxBQ,UAAU,EAAEb,OAAO,CAACK,KAAK,CAAC,CAAC,CAAC;QAE5BC,MAAM,EAAEA,MAAM,GAAG,CAACA,MAAM,CAAC,GAAG;MAC9B,CAAC,CAAC;IACJ,CAAC,CAAC;EAAA,EACH;AACH"}
package/dist/esm/index.js CHANGED
@@ -9,7 +9,7 @@ import { Headers as HeadersNode } from './node/fetch/headers.node';
9
9
  import { Response as ResponseNode } from './node/fetch/response.node';
10
10
  import { fetchNode } from './node/fetch/fetch.node';
11
11
  import { encodeImageNode } from './node/images/encode-image.node';
12
- import { parseImageNode } from './node/images/parse-image.node';
12
+ import { parseImageNode, NODE_FORMAT_SUPPORT } from './node/images/parse-image.node';
13
13
  export { ReadableStreamPolyfill } from './node/file/readable-stream';
14
14
  export { BlobPolyfill } from './node/file/blob';
15
15
  export { FileReaderPolyfill } from './node/file/file-reader';
@@ -53,6 +53,7 @@ if (!isBrowser && !('_encodeImageNode' in global) && encodeImageNode) {
53
53
  }
54
54
  if (!isBrowser && !('_parseImageNode' in global) && parseImageNode) {
55
55
  global['_parseImageNode'] = parseImageNode;
56
+ global['_imageFormatsNode'] = NODE_FORMAT_SUPPORT;
56
57
  }
57
58
  if (!('allSettled' in Promise)) {
58
59
  Promise.allSettled = allSettled;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["DOMParser","isBrowser","global","TextDecoder","TextEncoder","allSettled","base64","Headers","HeadersNode","Response","ResponseNode","fetchNode","encodeImageNode","parseImageNode","ReadableStreamPolyfill","BlobPolyfill","FileReaderPolyfill","FilePolyfill","installFilePolyfills","_fetchNode","fetchFileNode","_fetchFileNode","installTextEncoder","installTextDecoder","atob","btoa","Promise"],"sources":["../../src/index.ts"],"sourcesContent":["/* eslint-disable dot-notation */\nimport {DOMParser} from '@xmldom/xmldom';\nimport {isBrowser, global} from './utils/globals';\n\nimport {TextDecoder, TextEncoder} from './lib/encoding';\nimport {allSettled} from './promise/all-settled';\n\n// Node specific\nimport * as base64 from './node/buffer/btoa.node';\n\nimport {Headers as HeadersNode} from './node/fetch/headers.node';\nimport {Response as ResponseNode} from './node/fetch/response.node';\nimport {fetchNode as fetchNode} from './node/fetch/fetch.node';\n\nimport {encodeImageNode} from './node/images/encode-image.node';\nimport {parseImageNode} from './node/images/parse-image.node';\n\nexport {ReadableStreamPolyfill} from './node/file/readable-stream';\nexport {BlobPolyfill} from './node/file/blob';\nexport {FileReaderPolyfill} from './node/file/file-reader';\nexport {FilePolyfill} from './node/file/file';\nexport {installFilePolyfills} from './node/file/install-file-polyfills';\nexport {fetchNode as _fetchNode} from './node/fetch/fetch.node';\nexport {fetchFileNode as _fetchFileNode} from './node/fetch/fetch-file.node';\n\n// POLYFILLS: TextEncoder, TextDecoder\n// - Recent Node versions have these classes but virtually no encodings unless special build.\n// - Browser: Edge, IE11 do not have these\n\nconst installTextEncoder = !isBrowser || !('TextEncoder' in global);\nif (installTextEncoder) {\n global['TextEncoder'] = TextEncoder;\n}\n\nconst installTextDecoder = !isBrowser || !('TextDecoder' in global);\nif (installTextDecoder) {\n global['TextDecoder'] = TextDecoder;\n}\n\n// POLYFILLS: btoa, atob\n// - Node: Yes\n// - Browser: No\n\nif (!isBrowser && !('atob' in global) && base64.atob) {\n global['atob'] = base64.atob;\n}\nif (!isBrowser && !('btoa' in global) && base64.btoa) {\n global['btoa'] = base64.btoa;\n}\n\n// POLYFILL: fetch\n// - Node: Yes\n// - Browser: No. For This polyfill is node only, IE11 etc, install external polyfill\n\nif (!isBrowser && !('Headers' in global) && HeadersNode) {\n global['Headers'] = HeadersNode;\n}\n\nif (!isBrowser && !('Response' in global) && ResponseNode) {\n global['Response'] = ResponseNode;\n}\n\nif (!isBrowser && !('fetch' in global) && fetchNode) {\n global['fetch'] = fetchNode;\n}\n\n// POLYFILL: DOMParser\n// - Node: Yes\n// - Browser: No\n\nif (!isBrowser && !('DOMParser' in global) && DOMParser) {\n global['DOMParser'] = DOMParser;\n}\n\n// NODE IMAGE FUNCTIONS:\n// These are not official polyfills but used by the @loaders.gl/images module if installed\n// TODO - is there an appropriate Image API we could polyfill using an adapter?\n\nif (!isBrowser && !('_encodeImageNode' in global) && encodeImageNode) {\n global['_encodeImageNode'] = encodeImageNode;\n}\n\nif (!isBrowser && !('_parseImageNode' in global) && parseImageNode) {\n global['_parseImageNode'] = parseImageNode;\n}\n\nif (!('allSettled' in Promise)) {\n // @ts-ignore\n Promise.allSettled = allSettled;\n}\n"],"mappings":";AACA,SAAQA,SAAS,QAAO,gBAAgB;AACxC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CAAC,MAAM,CAAC,GAAGI,MAAM,CAACmB,IAAI;AAC9B;;AAMA,IAAI,CAACxB,SAAS,IAAI,EAAE,SAAS,IAAIC,MAAM,CAAC,IAAIM,WAAW,EAAE;EACvDN,MAAM,CAAC,SAAS,CAAC,GAAGM,WAAW;AACjC;AAEA,IAAI,CAACP,SAAS,IAAI,EAAE,UAAU,IAAIC,MAAM,CAAC,IAAIQ,YAAY,EAAE;EACzDR,MAAM,CAAC,UAAU,CAAC,GAAGQ,YAAY;AACnC;AAEA,IAAI,CAACT,SAAS,IAAI,EAAE,OAAO,IAAIC,MAAM,CAAC,IAAIS,SAAS,EAAE;EACnDT,MAAM,CAAC,OAAO,CAAC,GAAGS,SAAS;AAC7B;;AAMA,IAAI,CAACV,SAAS,IAAI,EAAE,WAAW,IAAIC,MAAM,CAAC,IAAIF,SAAS,EAAE;EACvDE,MAAM,CAAC,WAAW,CAAC,GAAGF,SAAS;AACjC;;AAMA,IAAI,CAACC,SAAS,IAAI,EAAE,kBAAkB,IAAIC,MAAM,CAAC,IAAIU,eAAe,EAAE;EACpEV,MAAM,CAAC,kBAAkB,CAAC,GAAGU,eAAe;AAC9C;AAEA,IAAI,CAACX,SAAS,IAAI,EAAE,iBAAiB,IAAIC,MAAM,CAAC,IAAIW,cAAc,EAAE;EAClEX,MAAM,CAAC,iBAAiB,CAAC,GAAGW,cAAc;AAC5C;AAEA,IAAI,EAAE,YAAY,IAAIa,OAAO,CAAC,EAAE;EAE9BA,OAAO,CAACrB,UAAU,GAAGA,UAAU;AACjC"}
1
+ {"version":3,"file":"index.js","names":["DOMParser","isBrowser","global","TextDecoder","TextEncoder","allSettled","base64","Headers","HeadersNode","Response","ResponseNode","fetchNode","encodeImageNode","parseImageNode","NODE_FORMAT_SUPPORT","ReadableStreamPolyfill","BlobPolyfill","FileReaderPolyfill","FilePolyfill","installFilePolyfills","_fetchNode","fetchFileNode","_fetchFileNode","installTextEncoder","installTextDecoder","atob","btoa","Promise"],"sources":["../../src/index.ts"],"sourcesContent":["/* eslint-disable dot-notation */\nimport {DOMParser} from '@xmldom/xmldom';\nimport {isBrowser, global} from './utils/globals';\n\nimport {TextDecoder, TextEncoder} from './lib/encoding';\nimport {allSettled} from './promise/all-settled';\n\n// Node specific\nimport * as base64 from './node/buffer/btoa.node';\n\nimport {Headers as HeadersNode} from './node/fetch/headers.node';\nimport {Response as ResponseNode} from './node/fetch/response.node';\nimport {fetchNode as fetchNode} from './node/fetch/fetch.node';\n\nimport {encodeImageNode} from './node/images/encode-image.node';\nimport {parseImageNode, NODE_FORMAT_SUPPORT} from './node/images/parse-image.node';\n\nexport {ReadableStreamPolyfill} from './node/file/readable-stream';\nexport {BlobPolyfill} from './node/file/blob';\nexport {FileReaderPolyfill} from './node/file/file-reader';\nexport {FilePolyfill} from './node/file/file';\nexport {installFilePolyfills} from './node/file/install-file-polyfills';\nexport {fetchNode as _fetchNode} from './node/fetch/fetch.node';\nexport {fetchFileNode as _fetchFileNode} from './node/fetch/fetch-file.node';\n\n// POLYFILLS: TextEncoder, TextDecoder\n// - Recent Node versions have these classes but virtually no encodings unless special build.\n// - Browser: Edge, IE11 do not have these\n\nconst installTextEncoder = !isBrowser || !('TextEncoder' in global);\nif (installTextEncoder) {\n global['TextEncoder'] = TextEncoder;\n}\n\nconst installTextDecoder = !isBrowser || !('TextDecoder' in global);\nif (installTextDecoder) {\n global['TextDecoder'] = TextDecoder;\n}\n\n// POLYFILLS: btoa, atob\n// - Node: Yes\n// - Browser: No\n\nif (!isBrowser && !('atob' in global) && base64.atob) {\n global['atob'] = base64.atob;\n}\nif (!isBrowser && !('btoa' in global) && base64.btoa) {\n global['btoa'] = base64.btoa;\n}\n\n// POLYFILL: fetch\n// - Node: Yes\n// - Browser: No. For This polyfill is node only, IE11 etc, install external polyfill\n\nif (!isBrowser && !('Headers' in global) && HeadersNode) {\n global['Headers'] = HeadersNode;\n}\n\nif (!isBrowser && !('Response' in global) && ResponseNode) {\n global['Response'] = ResponseNode;\n}\n\nif (!isBrowser && !('fetch' in global) && fetchNode) {\n global['fetch'] = fetchNode;\n}\n\n// POLYFILL: DOMParser\n// - Node: Yes\n// - Browser: No\n\nif (!isBrowser && !('DOMParser' in global) && DOMParser) {\n global['DOMParser'] = DOMParser;\n}\n\n// NODE IMAGE FUNCTIONS:\n// These are not official polyfills but used by the @loaders.gl/images module if installed\n// TODO - is there an appropriate Image API we could polyfill using an adapter?\n\nif (!isBrowser && !('_encodeImageNode' in global) && encodeImageNode) {\n global['_encodeImageNode'] = encodeImageNode;\n}\n\nif (!isBrowser && !('_parseImageNode' in global) && parseImageNode) {\n global['_parseImageNode'] = parseImageNode;\n global['_imageFormatsNode'] = NODE_FORMAT_SUPPORT;\n}\n\nif (!('allSettled' in Promise)) {\n // @ts-ignore\n Promise.allSettled = allSettled;\n}\n"],"mappings":";AACA,SAAQA,SAAS,QAAO,gBAAgB;AACxC,SAAQC,SAAS,EAAEC,MAAM,QAAO,iBAAiB;AAEjD,SAAQC,WAAW,EAAEC,WAAW,QAAO,gBAAgB;AACvD,SAAQC,UAAU,QAAO,uBAAuB;;AAGhD,OAAO,KAAKC,MAAM,MAAM,yBAAyB;AAEjD,SAAQC,OAAO,IAAIC,WAAW,QAAO,2BAA2B;AAChE,SAAQC,QAAQ,IAAIC,YAAY,QAAO,4BAA4B;AACnE,SAAQC,SAAsB,QAAO,yBAAyB;AAE9D,SAAQC,eAAe,QAAO,iCAAiC;AAC/D,SAAQC,cAAc,EAAEC,mBAAmB,QAAO,gCAAgC;AAElF,SAAQC,sBAAsB,QAAO,6BAA6B;AAClE,SAAQC,YAAY,QAAO,kBAAkB;AAC7C,SAAQC,kBAAkB,QAAO,yBAAyB;AAC1D,SAAQC,YAAY,QAAO,kBAAkB;AAC7C,SAAQC,oBAAoB,QAAO,oCAAoC;AACvE,SAAQR,SAAS,IAAIS,UAAU,QAAO,yBAAyB;AAC/D,SAAQC,aAAa,IAAIC,cAAc,QAAO,8BAA8B;;AAM5E,MAAMC,kBAAkB,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EACpEV,MAAM,CAAC,kBAAkB,CAAC,GAAGU,eAAe;AAC9C;AAEA,IAAI,CAACX,SAAS,IAAI,EAAE,iBAAiB,IAAIC,MAAM,CAAC,IAAIW,cAAc,EAAE;EAClEX,MAAM,CAAC,iBAAiB,CAAC,GAAGW,cAAc;EAC1CX,MAAM,CAAC,mBAAmB,CAAC,GAAGY,mBAAmB;AACnD;AAEA,IAAI,EAAE,YAAY,IAAIa,OAAO,CAAC,EAAE;EAE9BA,OAAO,CAACtB,UAAU,GAAGA,UAAU;AACjC"}
@@ -1,5 +1,9 @@
1
+
2
+
1
3
  import getPixels from 'get-pixels';
2
4
 
5
+ export const NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];
6
+
3
7
  export async function parseImageNode(arrayBuffer, mimeType) {
4
8
  if (!mimeType) {
5
9
  throw new Error('MIMEType is required to parse image under Node.js');
@@ -1 +1 @@
1
- {"version":3,"file":"parse-image.node.js","names":["getPixels","parseImageNode","arrayBuffer","mimeType","Error","buffer","Buffer","from","ndarray","getPixelsAsync","Promise","resolve","err","shape","layers","length","shift","data","Uint8Array","width","height","components"],"sources":["../../../../src/node/images/parse-image.node.ts"],"sourcesContent":["import getPixels from 'get-pixels';\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 if (!mimeType) {\n throw new Error('MIMEType is required to parse image under Node.js');\n }\n\n const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);\n\n const ndarray = await getPixelsAsync(buffer, mimeType);\n\n return ndarray;\n}\n\n// TODO - check if getPixels callback is asynchronous if provided with buffer input\n// if not, parseImage can be a sync function\nfunction getPixelsAsync(buffer: Buffer, mimeType: string): Promise<NDArray> {\n return new Promise<NDArray>((resolve) =>\n getPixels(buffer, mimeType, (err, ndarray) => {\n if (err) {\n throw err;\n }\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 resolve({\n shape,\n data,\n width: ndarray.shape[0],\n height: ndarray.shape[1],\n components: ndarray.shape[2],\n // TODO - error\n layers: layers ? [layers] : []\n });\n })\n );\n}\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,YAAY;;AAYlC,OAAO,eAAeC,cAAc,CAACC,WAAwB,EAAEC,QAAgB,EAAoB;EACjG,IAAI,CAACA,QAAQ,EAAE;IACb,MAAM,IAAIC,KAAK,CAAC,mDAAmD,CAAC;EACtE;EAEA,MAAMC,MAAM,GAAGH,WAAW,YAAYI,MAAM,GAAGJ,WAAW,GAAGI,MAAM,CAACC,IAAI,CAACL,WAAW,CAAC;EAErF,MAAMM,OAAO,GAAG,MAAMC,cAAc,CAACJ,MAAM,EAAEF,QAAQ,CAAC;EAEtD,OAAOK,OAAO;AAChB;;AAIA,SAASC,cAAc,CAACJ,MAAc,EAAEF,QAAgB,EAAoB;EAC1E,OAAO,IAAIO,OAAO,CAAWC,OAAO,IAClCX,SAAS,CAACK,MAAM,EAAEF,QAAQ,EAAE,CAACS,GAAG,EAAEJ,OAAO,KAAK;IAC5C,IAAII,GAAG,EAAE;MACP,MAAMA,GAAG;IACX;IAEA,MAAMC,KAAK,GAAG,CAAC,GAAGL,OAAO,CAACK,KAAK,CAAC;IAChC,MAAMC,MAAM,GAAGN,OAAO,CAACK,KAAK,CAACE,MAAM,KAAK,CAAC,GAAGP,OAAO,CAACK,KAAK,CAACG,KAAK,EAAE,GAAG,CAAC;IACrE,MAAMC,IAAI,GAAGT,OAAO,CAACS,IAAI,YAAYX,MAAM,GAAG,IAAIY,UAAU,CAACV,OAAO,CAACS,IAAI,CAAC,GAAGT,OAAO,CAACS,IAAI;;IAGzFN,OAAO,CAAC;MACNE,KAAK;MACLI,IAAI;MACJE,KAAK,EAAEX,OAAO,CAACK,KAAK,CAAC,CAAC,CAAC;MACvBO,MAAM,EAAEZ,OAAO,CAACK,KAAK,CAAC,CAAC,CAAC;MACxBQ,UAAU,EAAEb,OAAO,CAACK,KAAK,CAAC,CAAC,CAAC;MAE5BC,MAAM,EAAEA,MAAM,GAAG,CAACA,MAAM,CAAC,GAAG;IAC9B,CAAC,CAAC;EACJ,CAAC,CAAC,CACH;AACH"}
1
+ {"version":3,"file":"parse-image.node.js","names":["getPixels","NODE_FORMAT_SUPPORT","parseImageNode","arrayBuffer","mimeType","Error","buffer","Buffer","from","ndarray","getPixelsAsync","Promise","resolve","err","shape","layers","length","shift","data","Uint8Array","width","height","components"],"sources":["../../../../src/node/images/parse-image.node.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport getPixels from 'get-pixels';\n\n/** Declares which image format mime types this loader polyfill supports */\nexport const NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];\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 if (!mimeType) {\n throw new Error('MIMEType is required to parse image under Node.js');\n }\n\n const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);\n const ndarray = await getPixelsAsync(buffer, mimeType);\n return ndarray;\n}\n\n// TODO - check if getPixels callback is asynchronous if provided with buffer input\n// if not, parseImage can be a sync function\nfunction getPixelsAsync(buffer: Buffer, mimeType: string): Promise<NDArray> {\n return new Promise<NDArray>((resolve) =>\n getPixels(buffer, mimeType, (err, ndarray) => {\n if (err) {\n throw err;\n }\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 resolve({\n shape,\n data,\n width: ndarray.shape[0],\n height: ndarray.shape[1],\n components: ndarray.shape[2],\n // TODO - error\n layers: layers ? [layers] : []\n });\n })\n );\n}\n"],"mappings":";;AAEA,OAAOA,SAAS,MAAM,YAAY;;AAGlC,OAAO,MAAMC,mBAAmB,GAAG,CAAC,WAAW,EAAE,YAAY,EAAE,WAAW,CAAC;;AAY3E,OAAO,eAAeC,cAAc,CAACC,WAAwB,EAAEC,QAAgB,EAAoB;EACjG,IAAI,CAACA,QAAQ,EAAE;IACb,MAAM,IAAIC,KAAK,CAAC,mDAAmD,CAAC;EACtE;EAEA,MAAMC,MAAM,GAAGH,WAAW,YAAYI,MAAM,GAAGJ,WAAW,GAAGI,MAAM,CAACC,IAAI,CAACL,WAAW,CAAC;EACrF,MAAMM,OAAO,GAAG,MAAMC,cAAc,CAACJ,MAAM,EAAEF,QAAQ,CAAC;EACtD,OAAOK,OAAO;AAChB;;AAIA,SAASC,cAAc,CAACJ,MAAc,EAAEF,QAAgB,EAAoB;EAC1E,OAAO,IAAIO,OAAO,CAAWC,OAAO,IAClCZ,SAAS,CAACM,MAAM,EAAEF,QAAQ,EAAE,CAACS,GAAG,EAAEJ,OAAO,KAAK;IAC5C,IAAII,GAAG,EAAE;MACP,MAAMA,GAAG;IACX;IAEA,MAAMC,KAAK,GAAG,CAAC,GAAGL,OAAO,CAACK,KAAK,CAAC;IAChC,MAAMC,MAAM,GAAGN,OAAO,CAACK,KAAK,CAACE,MAAM,KAAK,CAAC,GAAGP,OAAO,CAACK,KAAK,CAACG,KAAK,EAAE,GAAG,CAAC;IACrE,MAAMC,IAAI,GAAGT,OAAO,CAACS,IAAI,YAAYX,MAAM,GAAG,IAAIY,UAAU,CAACV,OAAO,CAACS,IAAI,CAAC,GAAGT,OAAO,CAACS,IAAI;;IAGzFN,OAAO,CAAC;MACNE,KAAK;MACLI,IAAI;MACJE,KAAK,EAAEX,OAAO,CAACK,KAAK,CAAC,CAAC,CAAC;MACvBO,MAAM,EAAEZ,OAAO,CAACK,KAAK,CAAC,CAAC,CAAC;MACxBQ,UAAU,EAAEb,OAAO,CAACK,KAAK,CAAC,CAAC,CAAC;MAE5BC,MAAM,EAAEA,MAAM,GAAG,CAACA,MAAM,CAAC,GAAG;IAC9B,CAAC,CAAC;EACJ,CAAC,CAAC,CACH;AACH"}
package/dist/index.js CHANGED
@@ -96,6 +96,7 @@ if (!globals_1.isBrowser && !('_encodeImageNode' in globals_1.global) && encode_
96
96
  }
97
97
  if (!globals_1.isBrowser && !('_parseImageNode' in globals_1.global) && parse_image_node_1.parseImageNode) {
98
98
  globals_1.global['_parseImageNode'] = parse_image_node_1.parseImageNode;
99
+ globals_1.global['_imageFormatsNode'] = parse_image_node_1.NODE_FORMAT_SUPPORT;
99
100
  }
100
101
  if (!('allSettled' in Promise)) {
101
102
  // @ts-ignore
@@ -1,3 +1,5 @@
1
+ /** Declares which image format mime types this loader polyfill supports */
2
+ export declare const NODE_FORMAT_SUPPORT: string[];
1
3
  type NDArray = {
2
4
  shape: number[];
3
5
  data: Uint8Array;
@@ -1 +1 @@
1
- {"version":3,"file":"parse-image.node.d.ts","sourceRoot":"","sources":["../../../src/node/images/parse-image.node.ts"],"names":[],"mappings":"AAGA,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,CAUjG"}
1
+ {"version":3,"file":"parse-image.node.d.ts","sourceRoot":"","sources":["../../../src/node/images/parse-image.node.ts"],"names":[],"mappings":"AAIA,2EAA2E;AAC3E,eAAO,MAAM,mBAAmB,UAA2C,CAAC;AAG5E,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,CAQjG"}
@@ -1,10 +1,13 @@
1
1
  "use strict";
2
+ // loaders.gl, MIT license
2
3
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
5
  };
5
6
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.parseImageNode = void 0;
7
+ exports.parseImageNode = exports.NODE_FORMAT_SUPPORT = void 0;
7
8
  const get_pixels_1 = __importDefault(require("get-pixels"));
9
+ /** Declares which image format mime types this loader polyfill supports */
10
+ exports.NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];
8
11
  async function parseImageNode(arrayBuffer, mimeType) {
9
12
  if (!mimeType) {
10
13
  throw new Error('MIMEType is required to parse image under Node.js');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/polyfills",
3
- "version": "3.3.2",
3
+ "version": "3.4.0-alpha.2",
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": "a37b0af509ca05468aec6e5667d6a427b9c15d29"
109
+ "gitHead": "f1c00c124d8d0c41a138ff40afb0d1a00711bf2e"
110
110
  }
package/src/index.ts CHANGED
@@ -13,7 +13,7 @@ import {Response as ResponseNode} from './node/fetch/response.node';
13
13
  import {fetchNode as fetchNode} from './node/fetch/fetch.node';
14
14
 
15
15
  import {encodeImageNode} from './node/images/encode-image.node';
16
- import {parseImageNode} from './node/images/parse-image.node';
16
+ import {parseImageNode, NODE_FORMAT_SUPPORT} from './node/images/parse-image.node';
17
17
 
18
18
  export {ReadableStreamPolyfill} from './node/file/readable-stream';
19
19
  export {BlobPolyfill} from './node/file/blob';
@@ -82,6 +82,7 @@ if (!isBrowser && !('_encodeImageNode' in global) && encodeImageNode) {
82
82
 
83
83
  if (!isBrowser && !('_parseImageNode' in global) && parseImageNode) {
84
84
  global['_parseImageNode'] = parseImageNode;
85
+ global['_imageFormatsNode'] = NODE_FORMAT_SUPPORT;
85
86
  }
86
87
 
87
88
  if (!('allSettled' in Promise)) {
@@ -1,5 +1,10 @@
1
+ // loaders.gl, MIT license
2
+
1
3
  import getPixels from 'get-pixels';
2
4
 
5
+ /** Declares which image format mime types this loader polyfill supports */
6
+ export const NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];
7
+
3
8
  // Note: These types are also defined in @loaders.gl/images and need to be kept in sync
4
9
  type NDArray = {
5
10
  shape: number[];
@@ -16,9 +21,7 @@ export async function parseImageNode(arrayBuffer: ArrayBuffer, mimeType: string)
16
21
  }
17
22
 
18
23
  const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);
19
-
20
24
  const ndarray = await getPixelsAsync(buffer, mimeType);
21
-
22
25
  return ndarray;
23
26
  }
24
27