summit/frontend/node_modules/@monogrid/gainmap-js/dist/worker.umd.min.cjs

6 lines
2.7 KiB
JavaScript

/**
* @monogrid/gainmap-js v3.4.0
* With ❤️, by MONOGRID <gainmap@monogrid.com>
*/
!function(e){"function"==typeof define&&define.amd?define(e):e()}(function(){"use strict";function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var t,n,r,a={exports:{}};function o(){if(t)return a.exports;function e(e){return!!e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof e.then}return t=1,a.exports=e,a.exports.default=e,a.exports}var s=function(){if(r)return n;r=1;var e=o();return n=function(t){function n(e,t,n,r){function a(t,n){"function"!=typeof self.postMessage?e.ports[0].postMessage(t,n):self.postMessage(t,n)}n?("undefined"!=typeof console&&"error"in console&&console.error("Worker caught an error:",n),a([t,{message:n.message}])):r instanceof o?a([t,null,r.message],r.transferList):a([t,null,r])}function r(e,t){return new o(e,t)}function a(t,a,o,s){var i=function(e,t){try{return{res:e(t,r)}}catch(e){return{err:e}}}(a,s);i.err?n(t,o,i.err):e(i.res)?i.res.then(function(e){n(t,o,null,e)},function(e){n(t,o,e)}):n(t,o,null,i.res)}function o(e,t){this.message=e,this.transferList=t}self.addEventListener("message",function(e){var r=e.data;if(Array.isArray(r)&&2===r.length){var o=r[0],s=r[1];"function"!=typeof t?n(e,o,new Error("Please pass a function into register().")):a(e,t,o,s)}})}}();const i=async e=>{if("undefined"==typeof createImageBitmap)throw new Error("createImageBitmap() not supported.");const{source:t,mimeType:n,quality:r,flipY:a}=e;let o;if((t instanceof Uint8Array||t instanceof Uint8ClampedArray)&&"sourceMimeType"in e)o=new Blob([t],{type:e.sourceMimeType});else{if(!(t instanceof ImageData))throw new Error("Invalid source image");o=t}const s=await createImageBitmap(o),i=s.width,f=s.height;let c;"undefined"!=typeof OffscreenCanvas?c=new OffscreenCanvas(i,f):(c=document.createElement("canvas"),c.width=i,c.height=f);const u=c.getContext("2d");if(!u)throw new Error("Failed to create canvas Context");!0===a&&(u.translate(0,f),u.scale(1,-1)),u.drawImage(s,0,0,i,f);const l=await(async(e,t,n)=>{if("undefined"!=typeof OffscreenCanvas&&e instanceof OffscreenCanvas)return e.convertToBlob({type:t,quality:n});if(e instanceof HTMLCanvasElement)return new Promise((r,a)=>{e.toBlob(e=>{e?r(e):a(new Error("Failed to convert canvas to blob"))},t,n)});throw new Error("Unsupported canvas element")})(c,n,r||.9);return{data:new Uint8Array(await l.arrayBuffer()),mimeType:n,width:i,height:f}};e(s)(async(e,t)=>{if("compress"===e.type)return(async(e,t)=>{const n=await i(e.payload);return t({...n,source:e.payload.source instanceof ImageData?e.payload.source.data:new Uint8ClampedArray(e.payload.source)},[n.data.buffer,e.payload.source instanceof ImageData?e.payload.source.data.buffer:e.payload.source.buffer])})(e,t)})});