/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../../chunks/_rollupPluginBabelHelpers","../../../../../core/has","../../../../../core/Error","../../../../../core/maybe","../../../../../core/urlUtils"],(function(e,t,n,r,a,i){"use strict";function o(e){const t=g(e);return a.isSome(t)?t.toDataURL():""}function s(e){return u.apply(this,arguments)}function u(){return(u=t._asyncToGenerator((function*(e){const t=g(e);if(a.isNone(t))throw new r("imageToArrayBuffer","Unsupported image type");const n=yield c(e),i=yield new Promise((e=>t.toBlob(e,n)));if(!i)throw new r("imageToArrayBuffer","Failed to encode image");return{data:yield i.arrayBuffer(),type:n}}))).apply(this,arguments)}function c(e){return f.apply(this,arguments)}function f(){return(f=t._asyncToGenerator((function*(e){if(!(e instanceof HTMLImageElement))return"image/png";const t=e.src;if(i.isDataProtocol(t)){const{mediaType:e}=i.dataComponents(t);return"image/jpeg"===e?e:"image/png"}return/\.png$/i.test(t)?"image/png":/\.(jpg|jpeg)$/i.test(t)?"image/jpeg":"image/png"}))).apply(this,arguments)}function g(e){if(e instanceof HTMLCanvasElement)return e;if(e instanceof HTMLVideoElement)return null;const t=document.createElement("canvas");t.width=e.width,t.height=e.height;const n=t.getContext("2d");return e instanceof HTMLImageElement?n.drawImage(e,0,0,e.width,e.height):e instanceof ImageData&&n.putImageData(e,0,0),t}function l(e){const t=[],n=new Uint8Array(e);for(let r=0;r<n.length;r++)t.push(String.fromCharCode(n[r]));return"data:application/octet-stream;base64,"+btoa(t.join(""))}function m(e){if(e.byteLength<8)return!1;const t=new Uint8Array(e);return 137===t[0]&&80===t[1]&&78===t[2]&&71===t[3]&&13===t[4]&&10===t[5]&&26===t[6]&&10===t[7]}e.encodeBase64DataUri=l,e.imageToArrayBuffer=s,e.imageToDataURI=o,e.imageTypeToCanvas=g,e.isArrayBufferPNG=m,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
