Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@loaders.gl/images

Package Overview
Dependencies
Maintainers
9
Versions
329
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@loaders.gl/images - npm Package Compare versions

Comparing version 1.2.0-beta.2 to 1.2.0-beta.3

19

dist/dist.js

@@ -100,5 +100,5 @@ (function webpackUniversalModuleDefinition(root, factory) {

/***/ "../../node_modules/process/browser.js":
/*!**********************************************************************!*\
!*** /Users/ib/Documents/loaders.gl/node_modules/process/browser.js ***!
\**********************************************************************/
/*!*************************************************************************!*\
!*** /Users/missx/Documents/loaders.gl/node_modules/process/browser.js ***!
\*************************************************************************/
/*! no static exports found */

@@ -827,3 +827,3 @@ /***/ (function(module, exports) {

return parseToImageBitmap(arrayBuffer);
return parseToImageBitmap(arrayBuffer, options);
}

@@ -834,7 +834,7 @@

// https://medium.com/dailyjs/image-loading-with-image-decode-b03652e7d2d2
async function loadImage(url, options) {
async function loadImage(url, options = {}) {
if (typeof Image === 'undefined') {
const response = await fetch(url, options);
const arrayBuffer = await response.arrayBuffer();
return parseImage(arrayBuffer);
return parseImage(arrayBuffer, options);
}

@@ -848,3 +848,3 @@ return await loadToHTMLImage(url, options);

// https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap#Browser_compatibility
function parseToImageBitmap(arrayBuffer) {
function parseToImageBitmap(arrayBuffer, options) {
if (typeof createImageBitmap === 'undefined') {

@@ -855,3 +855,6 @@ throw new Error('parseImage');

const blob = new Blob([new Uint8Array(arrayBuffer)]);
return createImageBitmap(blob);
return createImageBitmap(blob, {
imageOrientation: options.imageOrientation || 'none',
premultiplyAlpha: options.premultiplyAlpha || 'default'
});
}

@@ -858,0 +861,0 @@

@@ -1,1 +0,1 @@

!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(window,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t,n){"use strict";(function(e,r){n.d(t,"a",function(){return i});"object"!=typeof e||"[object process]"!==String(e)||e.browser;const o={self:"undefined"!=typeof self&&self,window:"undefined"!=typeof window&&window,global:void 0!==r&&r},i=o.global||o.self||o.window}).call(this,n(3),n(1))},function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){(function(t){const r=n(4),o="undefined"==typeof window?t:window;o.loaders=o.loaders||{},e.exports=Object.assign(o.loaders,r)}).call(this,n(1))},function(e,t){var n,r,o=e.exports={};function i(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function u(e){if(n===setTimeout)return setTimeout(e,0);if((n===i||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:i}catch(e){n=i}try{r="function"==typeof clearTimeout?clearTimeout:a}catch(e){r=a}}();var c,s=[],f=!1,l=-1;function d(){f&&c&&(f=!1,c.length?s=c.concat(s):l=-1,s.length&&g())}function g(){if(!f){var e=u(d);f=!0;for(var t=s.length;t;){for(c=s,s=[];++l<t;)c&&c[l].run();l=-1,t=s.length}c=null,f=!1,function(e){if(r===clearTimeout)return clearTimeout(e);if((r===a||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(e);try{r(e)}catch(t){try{return r.call(null,e)}catch(t){return r.call(this,e)}}}(e)}}function p(e,t){this.fun=e,this.array=t}function m(){}o.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];s.push(new p(e,t)),1!==s.length||f||u(g)},p.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=m,o.addListener=m,o.once=m,o.off=m,o.removeListener=m,o.removeAllListeners=m,o.emit=m,o.prependListener=m,o.prependOnceListener=m,o.listeners=function(e){return[]},o.binding=function(e){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(e){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}},function(e,t,n){"use strict";n.r(t);var r=n(0);const o=!1,i=!0,a=new Map([["image/png",{test:function(e){return e.byteLength>=24&&2303741511===e.getUint32(0,o)},getSize:function(e){return{width:e.getUint32(16,o),height:e.getUint32(20,o)}}}],["image/jpeg",{test:function(e){return e.byteLength>=2&&65496===e.getUint16(0,o)},getSize:function(e){if(e.byteLength<2||65496!==e.getUint16(0,o))return null;const{tableMarkers:t,sofMarkers:n}=function(){const e=new Set([65499,65476,65484,65501,65534]);for(let t=65504;t<65520;++t)e.add(t);const t=new Set([65472,65473,65474,65475,65477,65478,65479,65481,65482,65483,65485,65486,65487,65502]);return{tableMarkers:e,sofMarkers:t}}();let r=2;for(;r<e.byteLength;){const i=e.getUint16(r,o);if(n.has(i))return{height:e.getUint16(r+5,o),width:e.getUint16(r+7,o)};if(!t.has(i))return null;r+=2,r+=e.getUint16(r,o)}return null}}],["image/gif",{test:function(e){return e.byteLength>=10&&1195984440===e.getUint32(0,o)},getSize:function(e){return{width:e.getUint16(6,i),height:e.getUint16(8,i)}}}],["image/bmp",{test:function(e){return e.byteLength>=2&&16973===e.getUint16(0,o)},getSize:function(e){return{width:e.getUint32(18,i),height:e.getUint32(22,i)}}}]]);const u=`Invalid MIME type. Supported MIME types are: ${Array.from(a.keys()).join(", ")}`;function c(e,t){if(t){const{test:n}=d(t);return n(g(e))}return Boolean(s(e))}function s(e){const t=g(e);for(const[e,{test:n}]of a.entries())if(n(t))return e;return null}function f(e,t=null){t=t||s(e);const{getSize:n}=d(t),r=n(g(e));if(!r)throw new Error(`invalid image data for type: ${t}`);return r}function l(e,t=null){const n=f(e,t=t||s(e));return n.mimeType=t,n}function d(e){const t=a.get(e);if(!t)throw new Error(u);return t}function g(e){if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return new DataView(e.buffer||e);throw new Error("toDataView")}const p=r.a._parseImageNode||"undefined"!=typeof ImageBitmap;function m(e,t){if(r.a._parseImageNode){const{mimeType:n}=l(e);return r.a._parseImageNode(e,n,t)}return h(e)}async function w(e,t){if("undefined"==typeof Image){const n=await fetch(e,t);return m(await n.arrayBuffer())}return await y(e,t)}function h(e){if("undefined"==typeof createImageBitmap)throw new Error("parseImage");const t=new Blob([new Uint8Array(e)]);return createImageBitmap(t)}async function y(e,t){let n;if(/\.svg((\?|#).*)?$/.test(e)){const r=await fetch(e,t),o=await r.text();n=`data:image/svg+xml;base64,${btoa(o)}`}else n=await e;return await new Promise((r,o)=>{try{const i=new Image;i.onload=()=>r(i),i.onerror=t=>o(new Error(`Could not load image ${e}: ${t}`)),i.crossOrigin=t&&t.crossOrigin||"anonymous",i.src=n}catch(e){o(e)}})}const b=["png","jpg","jpeg","gif","webp","bmp","ico","svg"];var v={name:"Images",extensions:b,parse:p&&m,loadAndParse:!p&&w};const I={extensions:b,parse:h},T={extensions:b,loadAndParse:y};var j={name:"Images",extensions:["jpeg"],encode:function(e,t){if(r.a._encodeImageNode)return r.a._encodeImageNode(e,t);if(e instanceof HTMLCanvasElement)return e.toDataURL(t);!function(e,t){if(!e)throw new Error(t||"@loaders.gl/images assertion failed.")}(e instanceof Image,"getImageData accepts image or canvas");const n=document.createElement("canvas");n.width=e.width,n.height=e.height,n.getContext("2d").drawImage(e,0,0);const o=n.toDataURL(t||"png").replace(/^data:image\/(png|jpg);base64,/,"");return Promise.resolve(o)},DEFAULT_OPTIONS:{type:"png"}};function L(e,{mimeType:t="image/jpeg"}){const n=new Blob([e],{type:t}),r=(window.URL||window.webkitURL).createObjectURL(n);return new Promise((e,t)=>{const n=new Image;return n.onload=()=>e(n),n.onerror=t,n.src=r,n})}n.d(t,"ImageLoader",function(){return v}),n.d(t,"HTMLImageLoader",function(){return T}),n.d(t,"ImageBitmapLoader",function(){return I}),n.d(t,"ImageWriter",function(){return j}),n.d(t,"loadImage",function(){return w}),n.d(t,"isImage",function(){return c}),n.d(t,"getImageMetadata",function(){return l}),n.d(t,"getImageMIMEType",function(){return s}),n.d(t,"getImageSize",function(){return f}),n.d(t,"decodeImage",function(){return L})}])});
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(window,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t,n){"use strict";(function(e,r){n.d(t,"a",function(){return i});"object"!=typeof e||"[object process]"!==String(e)||e.browser;const o={self:"undefined"!=typeof self&&self,window:"undefined"!=typeof window&&window,global:void 0!==r&&r},i=o.global||o.self||o.window}).call(this,n(3),n(1))},function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){(function(t){const r=n(4),o="undefined"==typeof window?t:window;o.loaders=o.loaders||{},e.exports=Object.assign(o.loaders,r)}).call(this,n(1))},function(e,t){var n,r,o=e.exports={};function i(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function u(e){if(n===setTimeout)return setTimeout(e,0);if((n===i||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:i}catch(e){n=i}try{r="function"==typeof clearTimeout?clearTimeout:a}catch(e){r=a}}();var c,s=[],f=!1,l=-1;function d(){f&&c&&(f=!1,c.length?s=c.concat(s):l=-1,s.length&&g())}function g(){if(!f){var e=u(d);f=!0;for(var t=s.length;t;){for(c=s,s=[];++l<t;)c&&c[l].run();l=-1,t=s.length}c=null,f=!1,function(e){if(r===clearTimeout)return clearTimeout(e);if((r===a||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(e);try{r(e)}catch(t){try{return r.call(null,e)}catch(t){return r.call(this,e)}}}(e)}}function p(e,t){this.fun=e,this.array=t}function m(){}o.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];s.push(new p(e,t)),1!==s.length||f||u(g)},p.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=m,o.addListener=m,o.once=m,o.off=m,o.removeListener=m,o.removeAllListeners=m,o.emit=m,o.prependListener=m,o.prependOnceListener=m,o.listeners=function(e){return[]},o.binding=function(e){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(e){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}},function(e,t,n){"use strict";n.r(t);var r=n(0);const o=!1,i=!0,a=new Map([["image/png",{test:function(e){return e.byteLength>=24&&2303741511===e.getUint32(0,o)},getSize:function(e){return{width:e.getUint32(16,o),height:e.getUint32(20,o)}}}],["image/jpeg",{test:function(e){return e.byteLength>=2&&65496===e.getUint16(0,o)},getSize:function(e){if(e.byteLength<2||65496!==e.getUint16(0,o))return null;const{tableMarkers:t,sofMarkers:n}=function(){const e=new Set([65499,65476,65484,65501,65534]);for(let t=65504;t<65520;++t)e.add(t);const t=new Set([65472,65473,65474,65475,65477,65478,65479,65481,65482,65483,65485,65486,65487,65502]);return{tableMarkers:e,sofMarkers:t}}();let r=2;for(;r<e.byteLength;){const i=e.getUint16(r,o);if(n.has(i))return{height:e.getUint16(r+5,o),width:e.getUint16(r+7,o)};if(!t.has(i))return null;r+=2,r+=e.getUint16(r,o)}return null}}],["image/gif",{test:function(e){return e.byteLength>=10&&1195984440===e.getUint32(0,o)},getSize:function(e){return{width:e.getUint16(6,i),height:e.getUint16(8,i)}}}],["image/bmp",{test:function(e){return e.byteLength>=2&&16973===e.getUint16(0,o)},getSize:function(e){return{width:e.getUint32(18,i),height:e.getUint32(22,i)}}}]]);const u=`Invalid MIME type. Supported MIME types are: ${Array.from(a.keys()).join(", ")}`;function c(e,t){if(t){const{test:n}=d(t);return n(g(e))}return Boolean(s(e))}function s(e){const t=g(e);for(const[e,{test:n}]of a.entries())if(n(t))return e;return null}function f(e,t=null){t=t||s(e);const{getSize:n}=d(t),r=n(g(e));if(!r)throw new Error(`invalid image data for type: ${t}`);return r}function l(e,t=null){const n=f(e,t=t||s(e));return n.mimeType=t,n}function d(e){const t=a.get(e);if(!t)throw new Error(u);return t}function g(e){if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return new DataView(e.buffer||e);throw new Error("toDataView")}const p=r.a._parseImageNode||"undefined"!=typeof ImageBitmap;function m(e,t){if(r.a._parseImageNode){const{mimeType:n}=l(e);return r.a._parseImageNode(e,n,t)}return h(e,t)}async function w(e,t={}){if("undefined"==typeof Image){const n=await fetch(e,t);return m(await n.arrayBuffer(),t)}return await y(e,t)}function h(e,t){if("undefined"==typeof createImageBitmap)throw new Error("parseImage");const n=new Blob([new Uint8Array(e)]);return createImageBitmap(n,{imageOrientation:t.imageOrientation||"none",premultiplyAlpha:t.premultiplyAlpha||"default"})}async function y(e,t){let n;if(/\.svg((\?|#).*)?$/.test(e)){const r=await fetch(e,t),o=await r.text();n=`data:image/svg+xml;base64,${btoa(o)}`}else n=await e;return await new Promise((r,o)=>{try{const i=new Image;i.onload=()=>r(i),i.onerror=t=>o(new Error(`Could not load image ${e}: ${t}`)),i.crossOrigin=t&&t.crossOrigin||"anonymous",i.src=n}catch(e){o(e)}})}const b=["png","jpg","jpeg","gif","webp","bmp","ico","svg"];var v={name:"Images",extensions:b,parse:p&&m,loadAndParse:!p&&w};const I={extensions:b,parse:h},T={extensions:b,loadAndParse:y};var j={name:"Images",extensions:["jpeg"],encode:function(e,t){if(r.a._encodeImageNode)return r.a._encodeImageNode(e,t);if(e instanceof HTMLCanvasElement)return e.toDataURL(t);!function(e,t){if(!e)throw new Error(t||"@loaders.gl/images assertion failed.")}(e instanceof Image,"getImageData accepts image or canvas");const n=document.createElement("canvas");n.width=e.width,n.height=e.height,n.getContext("2d").drawImage(e,0,0);const o=n.toDataURL(t||"png").replace(/^data:image\/(png|jpg);base64,/,"");return Promise.resolve(o)},DEFAULT_OPTIONS:{type:"png"}};function L(e,{mimeType:t="image/jpeg"}){const n=new Blob([e],{type:t}),r=(window.URL||window.webkitURL).createObjectURL(n);return new Promise((e,t)=>{const n=new Image;return n.onload=()=>e(n),n.onerror=t,n.src=r,n})}n.d(t,"ImageLoader",function(){return v}),n.d(t,"HTMLImageLoader",function(){return T}),n.d(t,"ImageBitmapLoader",function(){return I}),n.d(t,"ImageWriter",function(){return j}),n.d(t,"loadImage",function(){return w}),n.d(t,"isImage",function(){return c}),n.d(t,"getImageMetadata",function(){return l}),n.d(t,"getImageMIMEType",function(){return s}),n.d(t,"getImageSize",function(){return f}),n.d(t,"decodeImage",function(){return L})}])});

@@ -33,6 +33,6 @@ "use strict";

return parseToImageBitmap(arrayBuffer);
return parseToImageBitmap(arrayBuffer, options);
}
function loadImage(_x, _x2) {
function loadImage(_x) {
return _loadImage.apply(this, arguments);

@@ -42,4 +42,7 @@ }

function _loadImage() {
_loadImage = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(url, options) {
var response, arrayBuffer;
_loadImage = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(url) {
var options,
response,
arrayBuffer,
_args = arguments;
return _regenerator["default"].wrap(function _callee$(_context) {

@@ -49,27 +52,29 @@ while (1) {

case 0:
options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
if (!(typeof Image === 'undefined')) {
_context.next = 8;
_context.next = 9;
break;
}
_context.next = 3;
_context.next = 4;
return fetch(url, options);
case 3:
case 4:
response = _context.sent;
_context.next = 6;
_context.next = 7;
return response.arrayBuffer();
case 6:
case 7:
arrayBuffer = _context.sent;
return _context.abrupt("return", parseImage(arrayBuffer));
return _context.abrupt("return", parseImage(arrayBuffer, options));
case 8:
_context.next = 10;
case 9:
_context.next = 11;
return loadToHTMLImage(url, options);
case 10:
case 11:
return _context.abrupt("return", _context.sent);
case 11:
case 12:
case "end":

@@ -84,3 +89,3 @@ return _context.stop();

function parseToImageBitmap(arrayBuffer) {
function parseToImageBitmap(arrayBuffer, options) {
if (typeof createImageBitmap === 'undefined') {

@@ -91,6 +96,9 @@ throw new Error('parseImage');

var blob = new Blob([new Uint8Array(arrayBuffer)]);
return createImageBitmap(blob);
return createImageBitmap(blob, {
imageOrientation: options.imageOrientation || 'none',
premultiplyAlpha: options.premultiplyAlpha || 'default'
});
}
function loadToHTMLImage(_x3, _x4) {
function loadToHTMLImage(_x2, _x3) {
return _loadToHTMLImage.apply(this, arguments);

@@ -97,0 +105,0 @@ }

@@ -1,4 +0,4 @@

const moduleExports = require('./index');
var moduleExports = require('./index');
const _global = typeof window === 'undefined' ? global : window;
var _global = typeof window === 'undefined' ? global : window;

@@ -5,0 +5,0 @@ _global.loaders = _global.loaders || {};

import { canParseImage, parseImage, loadImage, parseToImageBitmap, loadToHTMLImage } from './lib/parse-image';
const EXTENSIONS = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'ico', 'svg'];
var EXTENSIONS = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'ico', 'svg'];
export default {

@@ -9,7 +9,7 @@ name: 'Images',

};
export const ImageBitmapLoader = {
export var ImageBitmapLoader = {
extensions: EXTENSIONS,
parse: parseToImageBitmap
};
export const HTMLImageLoader = {
export var HTMLImageLoader = {
extensions: EXTENSIONS,

@@ -16,0 +16,0 @@ loadAndParse: loadToHTMLImage

@@ -9,14 +9,14 @@ import assert from '../utils/assert';

if (image instanceof HTMLCanvasElement) {
const canvas = image;
return canvas.toDataURL(type);
var _canvas = image;
return _canvas.toDataURL(type);
}
assert(image instanceof Image, 'getImageData accepts image or canvas');
const canvas = document.createElement('canvas');
var canvas = document.createElement('canvas');
canvas.width = image.width;
canvas.height = image.height;
canvas.getContext('2d').drawImage(image, 0, 0);
const data = canvas.toDataURL(type || 'png').replace(/^data:image\/(png|jpg);base64,/, '');
var data = canvas.toDataURL(type || 'png').replace(/^data:image\/(png|jpg);base64,/, '');
return Promise.resolve(data);
}
//# sourceMappingURL=encode-image.js.map
import { mimeTypeMap } from './image-parsers';
const ERR_INVALID_MIME_TYPE = "Invalid MIME type. Supported MIME types are: ".concat(Array.from(mimeTypeMap.keys()).join(', '));
var ERR_INVALID_MIME_TYPE = "Invalid MIME type. Supported MIME types are: ".concat(Array.from(mimeTypeMap.keys()).join(', '));
export function isImage(arrayBuffer, mimeType) {
if (mimeType) {
const {
var {
test
} = getImageTypeHandlers(mimeType);
const dataView = toDataView(arrayBuffer);
var dataView = toDataView(arrayBuffer);
return test(dataView);

@@ -15,5 +15,5 @@ }

export function getImageMIMEType(arrayBuffer) {
const dataView = toDataView(arrayBuffer);
var dataView = toDataView(arrayBuffer);
for (const [mimeType, {
for (var [mimeType, {
test

@@ -29,9 +29,9 @@ }] of mimeTypeMap.entries()) {

export function getImageSize(arrayBuffer) {
let mimeType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
var mimeType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
mimeType = mimeType || getImageMIMEType(arrayBuffer);
const {
var {
getSize
} = getImageTypeHandlers(mimeType);
const dataView = toDataView(arrayBuffer);
const size = getSize(dataView);
var dataView = toDataView(arrayBuffer);
var size = getSize(dataView);

@@ -45,5 +45,5 @@ if (!size) {

export function getImageMetadata(arrayBuffer) {
let mimeType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
var mimeType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
mimeType = mimeType || getImageMIMEType(arrayBuffer);
const metadata = getImageSize(arrayBuffer, mimeType);
var metadata = getImageSize(arrayBuffer, mimeType);
metadata.mimeType = mimeType;

@@ -54,3 +54,3 @@ return metadata;

function getImageTypeHandlers(mimeType) {
const handlers = mimeTypeMap.get(mimeType);
var handlers = mimeTypeMap.get(mimeType);

@@ -57,0 +57,0 @@ if (!handlers) {

@@ -1,4 +0,4 @@

const BIG_ENDIAN = false;
const LITTLE_ENDIAN = true;
export const mimeTypeMap = new Map([['image/png', {
var BIG_ENDIAN = false;
var LITTLE_ENDIAN = true;
export var mimeTypeMap = new Map([['image/png', {
test: isPng,

@@ -59,10 +59,10 @@ getSize: getPngSize

const {
var {
tableMarkers,
sofMarkers
} = getJpegMarkers();
let i = 2;
var i = 2;
while (i < dataView.byteLength) {
const marker = dataView.getUint16(i, BIG_ENDIAN);
var marker = dataView.getUint16(i, BIG_ENDIAN);

@@ -88,9 +88,9 @@ if (sofMarkers.has(marker)) {

function getJpegMarkers() {
const tableMarkers = new Set([0xffdb, 0xffc4, 0xffcc, 0xffdd, 0xfffe]);
var tableMarkers = new Set([0xffdb, 0xffc4, 0xffcc, 0xffdd, 0xfffe]);
for (let i = 0xffe0; i < 0xfff0; ++i) {
for (var i = 0xffe0; i < 0xfff0; ++i) {
tableMarkers.add(i);
}
const sofMarkers = new Set([0xffc0, 0xffc1, 0xffc2, 0xffc3, 0xffc5, 0xffc6, 0xffc7, 0xffc9, 0xffca, 0xffcb, 0xffcd, 0xffce, 0xffcf, 0xffde]);
var sofMarkers = new Set([0xffc0, 0xffc1, 0xffc2, 0xffc3, 0xffc5, 0xffc6, 0xffc7, 0xffc9, 0xffca, 0xffcb, 0xffcd, 0xffce, 0xffcf, 0xffde]);
return {

@@ -97,0 +97,0 @@ tableMarkers,

export function decodeImage(arrayBufferOrView, _ref) {
let {
var {
mimeType = 'image/jpeg'
} = _ref;
const blob = new Blob([arrayBufferOrView], {
var blob = new Blob([arrayBufferOrView], {
type: mimeType
});
const urlCreator = window.URL || window.webkitURL;
const imageUrl = urlCreator.createObjectURL(blob);
var urlCreator = window.URL || window.webkitURL;
var imageUrl = urlCreator.createObjectURL(blob);
return new Promise((resolve, reject) => {
const image = new Image();
var image = new Image();

@@ -21,10 +21,10 @@ image.onload = () => resolve(image);

export function getImagePixelData(image) {
let width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
let height = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
var height = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
width = width || image.width;
height = height || image.height;
const canvas = document.createElement('canvas');
var canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext('2d');
var ctx = canvas.getContext('2d');
ctx.drawImage(image, 0, 0, width, height);

@@ -31,0 +31,0 @@ return ctx.getImageData(0, 0, width, height);

import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import { global } from '../utils/globals';
import { getImageMetadata } from './get-image-metadata';
export const canParseImage = global._parseImageNode || typeof ImageBitmap !== 'undefined';
export var canParseImage = global._parseImageNode || typeof ImageBitmap !== 'undefined';
export function parseImage(arrayBuffer, options) {
if (global._parseImageNode) {
const {
var {
mimeType

@@ -13,5 +13,5 @@ } = getImageMetadata(arrayBuffer);

return parseToImageBitmap(arrayBuffer);
return parseToImageBitmap(arrayBuffer, options);
}
export function loadImage(_x, _x2) {
export function loadImage(_x) {
return _loadImage.apply(this, arguments);

@@ -21,7 +21,9 @@ }

function _loadImage() {
_loadImage = _asyncToGenerator(function* (url, options) {
_loadImage = _asyncToGenerator(function* (url) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (typeof Image === 'undefined') {
const response = yield fetch(url, options);
const arrayBuffer = yield response.arrayBuffer();
return parseImage(arrayBuffer);
var response = yield fetch(url, options);
var arrayBuffer = yield response.arrayBuffer();
return parseImage(arrayBuffer, options);
}

@@ -34,3 +36,3 @@

export function parseToImageBitmap(arrayBuffer) {
export function parseToImageBitmap(arrayBuffer, options) {
if (typeof createImageBitmap === 'undefined') {

@@ -40,6 +42,9 @@ throw new Error('parseImage');

const blob = new Blob([new Uint8Array(arrayBuffer)]);
return createImageBitmap(blob);
var blob = new Blob([new Uint8Array(arrayBuffer)]);
return createImageBitmap(blob, {
imageOrientation: options.imageOrientation || 'none',
premultiplyAlpha: options.premultiplyAlpha || 'default'
});
}
export function loadToHTMLImage(_x3, _x4) {
export function loadToHTMLImage(_x2, _x3) {
return _loadToHTMLImage.apply(this, arguments);

@@ -50,7 +55,7 @@ }

_loadToHTMLImage = _asyncToGenerator(function* (url, options) {
let src;
var src;
if (/\.svg((\?|#).*)?$/.test(url)) {
const response = yield fetch(url, options);
const xml = yield response.text();
var response = yield fetch(url, options);
var xml = yield response.text();
src = "data:image/svg+xml;base64,".concat(btoa(xml));

@@ -63,3 +68,3 @@ } else {

try {
const image = new Image();
var image = new Image();

@@ -66,0 +71,0 @@ image.onload = () => resolve(image);

@@ -1,3 +0,3 @@

const isBrowser = typeof process !== 'object' || String(process) !== '[object process]' || process.browser;
const globals = {
var isBrowser = typeof process !== 'object' || String(process) !== '[object process]' || process.browser;
var globals = {
self: typeof self !== 'undefined' && self,

@@ -7,4 +7,4 @@ window: typeof window !== 'undefined' && window,

};
const global_ = globals.global || globals.self || globals.window;
var global_ = globals.global || globals.self || globals.window;
export { isBrowser, global_ as global };
//# sourceMappingURL=globals.js.map

@@ -14,5 +14,5 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";

return parseToImageBitmap(arrayBuffer);
return parseToImageBitmap(arrayBuffer, options);
}
export function loadImage(_x, _x2) {
export function loadImage(_x) {
return _loadImage.apply(this, arguments);

@@ -22,4 +22,7 @@ }

function _loadImage() {
_loadImage = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(url, options) {
var response, arrayBuffer;
_loadImage = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(url) {
var options,
response,
arrayBuffer,
_args = arguments;
return _regeneratorRuntime.wrap(function _callee$(_context) {

@@ -29,27 +32,29 @@ while (1) {

case 0:
options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
if (!(typeof Image === 'undefined')) {
_context.next = 8;
_context.next = 9;
break;
}
_context.next = 3;
_context.next = 4;
return fetch(url, options);
case 3:
case 4:
response = _context.sent;
_context.next = 6;
_context.next = 7;
return response.arrayBuffer();
case 6:
case 7:
arrayBuffer = _context.sent;
return _context.abrupt("return", parseImage(arrayBuffer));
return _context.abrupt("return", parseImage(arrayBuffer, options));
case 8:
_context.next = 10;
case 9:
_context.next = 11;
return loadToHTMLImage(url, options);
case 10:
case 11:
return _context.abrupt("return", _context.sent);
case 11:
case 12:
case "end":

@@ -64,3 +69,3 @@ return _context.stop();

export function parseToImageBitmap(arrayBuffer) {
export function parseToImageBitmap(arrayBuffer, options) {
if (typeof createImageBitmap === 'undefined') {

@@ -71,5 +76,8 @@ throw new Error('parseImage');

var blob = new Blob([new Uint8Array(arrayBuffer)]);
return createImageBitmap(blob);
return createImageBitmap(blob, {
imageOrientation: options.imageOrientation || 'none',
premultiplyAlpha: options.premultiplyAlpha || 'default'
});
}
export function loadToHTMLImage(_x3, _x4) {
export function loadToHTMLImage(_x2, _x3) {
return _loadToHTMLImage.apply(this, arguments);

@@ -76,0 +84,0 @@ }

{
"name": "@loaders.gl/images",
"version": "1.2.0-beta.2",
"version": "1.2.0-beta.3",
"description": "Framework-independent loaders and writers for images (PNG, JPG, ...)",

@@ -34,3 +34,3 @@ "license": "MIT",

},
"gitHead": "82626f4ecad7c816c70780376d661f267b6c523e"
"gitHead": "39442622efe0e06323db958c53c9805fc9b7699d"
}

@@ -14,3 +14,3 @@ /* global Image, Blob, createImageBitmap, btoa, fetch */

return parseToImageBitmap(arrayBuffer);
return parseToImageBitmap(arrayBuffer, options);
}

@@ -21,7 +21,7 @@

// https://medium.com/dailyjs/image-loading-with-image-decode-b03652e7d2d2
export async function loadImage(url, options) {
export async function loadImage(url, options = {}) {
if (typeof Image === 'undefined') {
const response = await fetch(url, options);
const arrayBuffer = await response.arrayBuffer();
return parseImage(arrayBuffer);
return parseImage(arrayBuffer, options);
}

@@ -35,3 +35,3 @@ return await loadToHTMLImage(url, options);

// https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap#Browser_compatibility
export function parseToImageBitmap(arrayBuffer) {
export function parseToImageBitmap(arrayBuffer, options) {
if (typeof createImageBitmap === 'undefined') {

@@ -42,3 +42,6 @@ throw new Error('parseImage');

const blob = new Blob([new Uint8Array(arrayBuffer)]);
return createImageBitmap(blob);
return createImageBitmap(blob, {
imageOrientation: options.imageOrientation || 'none',
premultiplyAlpha: options.premultiplyAlpha || 'default'
});
}

@@ -45,0 +48,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc