/*!
 * SR7 in-editor Image Editor — vendored, patched build of mini-photo-editor (xdadda)
 * Upstream: https://github.com/xdadda/mini-photo-editor  ·  License: MIT (c) 2025 xdadda
 * Engine: @xdadda/mini-gl (WebGL2) + @xdadda/mini + @xdadda/mini-exif. No WASM.
 * Global: MiniImgEditor -> { Editor, render, centerCanvas }. Lazy-loaded on first "Edit Image" click.
 *
 * This file is GENERATED (vite, IIFE) and shipped UNMINIFIED so it stays editable during dev;
 * the _DIST gulp build (tools/imgeditor in BackEnd.singles) terser-minifies it for release.
 * NOTE: a full rebuild OVERWRITES this file — durable changes belong in the source, styling in
 * admin/assets/css/imgeditor.css. To rebuild, from a clone of the upstream repo:
 *   - repoint file: deps to npm: @xdadda/mini@^0.2.16, @xdadda/mini-gl@^0.1.19
 *   - src/components/histogram.js: import worker with '...?worker&inline'
 *   - add src/srentry.js re-exporting { render } from '@xdadda/mini' + { Editor, centerCanvas } from './app.js'
 *   - SR7 patches: one-click headless save returning a dataURL (downloadImage.js); drop GitHub/Cancel/
 *     Split-View/credit + the whole footer; Save (sr-button primary) + Presets (sr-button clean) live
 *     at the bottom of the sidebar (.sr_mpe_actions); reset glyph -> #Preset_Rotation; expose
 *     input.onReady({getParams,applyParams}); remove Heal/Recipes/Blender sections.
 *   - Size: filter LUT PNGs are EXTERNALIZED (not inlined) — _filters.js loads them from input.assetBase
 *     (admin/assets/images/filters/) on demand; the unused logo import is removed. Keeps the bundle ~135KB
 *     (gzip ~43KB) instead of ~445KB. Build IIFE inlines any imported asset, so never re-add asset imports.
 *   - vite build, format 'iife', global name 'MiniImgEditor'. SR7 theming lives in admin/assets/css/imgeditor.css.
 *
 * MIT License — Copyright (c) 2025 xdadda. Permission is hereby granted, free of charge, to any
 * person obtaining a copy of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction. The Software is provided "as is", without warranty of any kind.
 */
var MiniImgEditor=function(e){"use strict";var t=Object.defineProperty,n=(e,n,r)=>((e,n,r)=>n in e?t(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r)(e,"symbol"!=typeof n?n+"":n,r);function r(e,t,n,r){let i=n.length,o=/[:,@]\S*=/.exec(e);if(!o)return console.error("MiNi: attribute is missing :@ prefix",e),!1;if(o?.length>1)return console.error('MiNi: attribute is missing "${}"',e),!1;if(!e.endsWith(o[0]+'"'))return console.error("MiNi: attribute "+o[0]+' is missing "${}"'),!1;const a=o[0][0],s=o[0].slice(1,-1);n.push({type:a,key:s,v:t});const l=e.lastIndexOf(s);return'"'===(e=e.substring(0,l-1)+e.substring(l-1).replace(a+s,s+i)).slice(-1)?r.push(""):r.push('""'),e}function i(e,...t){let n=[...e];function i(e){let i=[],o=[],a=!1;for(let e=0;e<t.length;e++){const s=t[e],l=n[e],c=l.lastIndexOf("<"),u=l.lastIndexOf(">");a=-1!==c&&c>u||a,a=!(-1!==u&&u>c)&&a;const f=o.length;if("function"==typeof s||s instanceof Promise||s?.signal)if(a){const t=r(n[e],s,o,i);t?n[e]=t:console.error("MiNi: unknown attribute type",n[e],s)}else o.push({type:"node",key:f,v:s}),i[e]=`\x3c!--rx${f}--\x3e`;else Array.isArray(s)?(i[e]="",s.forEach((t,n)=>{"function"==typeof t?(o.push({type:"node",key:f+":"+n,v:t}),i[e]+=`\x3c!--rx${f}:${n}--\x3e`):i[e]+=t})):!1===s||void 0===s?(a&&'"'===n[e].slice(-1)&&(n[e]=n[e].replace(/\s(\S+)$/,'"')),i.push("")):i.push(s)}let s=function(e,t){let n=e[0];for(let r=0;r<t.length;r++)n+=t[r]+e[r+1];return n.replace(/\s+/g," ")}(n,i);return s=s.replace(/(?=\/\*).*?(?:\*\/)/g,""),{html:s.trim(),reactarray:o}}return i.html=!0,i}let o,a,s=null,l=0,c=[],u=!1;function f(e,t){const n=new p(e,t?.effect,t?.label);return t?.equals&&(n.equals=t.equals),n.signal=!0,n}function d(e,t){return e===t}let p=class{constructor(e,t,r){n(this,"_value"),n(this,"fn"),n(this,"observers",null),n(this,"sources",null),n(this,"state"),n(this,"effect"),n(this,"label"),n(this,"cleanups",[]),n(this,"equals",d),"function"==typeof e?(this.fn=e,this._value=void 0,this.effect=t||!1,this.state=2,t&&(c.push(this),a?.(this))):(this.fn=void 0,this._value=e,this.state=0,this.effect=!1),r&&(this.label=r)}get value(){return this.get()}set value(e){this.set(e)}get(){return o&&(!s&&o.sources&&o.sources[l]==this?l++:s?s.push(this):s=[this]),this.fn&&this.updateIfNecessary(),this._value}set(e){if("function"==typeof e){const t=e;t!==this.fn&&this.stale(2),this.fn=t}else{this.fn&&(this.removeParentObservers(0),this.sources=null,this.fn=void 0);const t=e;if(!this.equals(this._value,t)){if(this.observers)for(let e=0;e<this.observers.length;e++)this.observers[e].stale(2);this._value=t}}}stale(e){if(this.state<e&&(0===this.state&&this.effect&&(c.push(this),a?.(this)),this.state=e,this.observers))for(let e=0;e<this.observers.length;e++)this.observers[e].stale(1)}update(){const e=this._value,t=o,n=s,r=l;o=this,s=null,l=0;try{if(this.cleanups.length&&(this.cleanups.forEach(e=>e(this._value)),this.cleanups=[]),this._value=this.fn(),s){if(this.removeParentObservers(l),this.sources&&l>0){this.sources.length=l+s.length;for(let e=0;e<s.length;e++)this.sources[l+e]=s[e]}else this.sources=s;for(let e=l;e<this.sources.length;e++){const t=this.sources[e];t.observers?t.observers.push(this):t.observers=[this]}}else this.sources&&l<this.sources.length&&(this.removeParentObservers(l),this.sources.length=l)}finally{s=n,o=t,l=r}if(!this.equals(e,this._value)&&this.observers)for(let e=0;e<this.observers.length;e++){this.observers[e].state=2}this.state=0}updateIfNecessary(){if(1===this.state)for(const e of this.sources)if(e.updateIfNecessary(),2===this.state)break;2===this.state&&this.update(),this.state=0}removeParentObservers(e){if(this.sources)for(let t=e;t<this.sources.length;t++){const e=this.sources[t],n=e.observers.findIndex(e=>e===this);e.observers[n]=e.observers[e.observers.length-1],e.observers.pop()}}};function h(e){const t=o,n=s,r=l;o=void 0,s=null,l=0;const i=e();return s=n,o=t,l=r,i}function v(){u||(u=!0,queueMicrotask(()=>{u=!1,function(){for(let e=0;e<c.length;e++)c[e].get();c.length=0}()}))}function g(e){if(e.nodeType){let t=[e];return t.parent=e.parentNode,t.next=e.nextSibling,t.prev=e.previousSibling,t.fragment=!0,t}return Array.isArray(e)&&!e.fragment?!!e[0]&&(e[0].before(document.createTextNode("")),e[e.length-1].after(document.createTextNode("")),e.parent=e[0].parentNode,e.prev=e[0].previousSibling,e.next=e[e.length-1].nextSibling,e.fragment=!0,e):(console.error("MiNi: unknown input for createFragment"),!1)}function m(e){if(e.prev||e.next||!e.parent){if(e.prev?.nextSibling===e.next)return e;{let t=e.prev?.nextSibling||e.next?.parentElement?.firstChild||e.parent?.firstChild;if(!t)return;for(;t!==e.next;){if(!t)return console.error("MiNi: clearFragment missing node",e);const n=t.nextSibling;t.remove(),t=n}}}else e.parent.textContent="";return e.length&&e.splice(0,e.length),e}!function(e=v){a=e}();let x=[];function b(e){x.push(e)}let y=[];function w(e){y.push(e)}function C(e,t=[]){return e.unmount&&(t.push(e.unmount),delete e.unmount),Object.getOwnPropertySymbols(e).forEach(n=>{e[n]?.frag&&C(e[n],t)}),t.flat().reverse()}function _(e,t){const n=document.createComment("rx");let r=new Array(e.length);r=r.fill(0).map(()=>n.cloneNode()),t.frag=function(e,t){return e.fragment&&Array.isArray(e)&&Array.isArray(t)?(t.prev=e.prev,t.next=e.next,t.parent=e.parent,m(e),t.next?t.next.before(...t):t.parent.append(...t),t.fragment=!0):console.error("MiNi: replaceFragments unknown input",e,t),t}(t.frag,r);for(let n=0;n<e.length;n++)$(r[n],()=>e[n],t)}function S(e){Object.getOwnPropertySymbols(e).forEach(t=>{e[t]?.frag&&(e[t].stale=!0,S(e[t]),delete e[t])})}function $(e,t,n){const r=Symbol("$comp");if(n[r]={},e.before(document.createTextNode("")),e.after(document.createTextNode("")),n[r].frag=g(e),t._map)return t(n,r);f(async()=>{if(!n[r])return;if(n.stale||n[r].stale)return delete n[r];const e=x.length,i=y.length,o=C(n[r]);o.length&&o.forEach(e=>"function"==typeof e&&e()),S(n[r]);let a=t();if(a instanceof Promise&&(a=await a),n[r]){if(x.length>e){const t=x.length-e;n[r].mount=x.splice(-t,t)}if(y.length>i){const e=y.length-i;n[r].unmount=y.splice(-e,e)}if("function"==typeof a&&a?._map)return a(n,r);if(t._loader&&(n[r].loader=!0),t._suspense){if(!n[r])return;n[r].suspense=!0,function(e){const t=Object.getOwnPropertySymbols(e).filter(t=>e[t]?.loader)?.[0];if(!t)return;m(e[t].frag),delete e[t]}(n),delete t._suspense}a="function"!=typeof a||a?.html?a:h(a),function(e,t){if(t)if(t.hidden&&(t.hidden=!1),e?.html)M(t.frag,e,t),t.mount&&setTimeout(()=>{t.mount?.forEach(e=>e()),t.mount=void 0},0);else if(Array.isArray(e))_(e,t),t.mount&&setTimeout(()=>{t.mount?.forEach(e=>e()),t.mount=void 0},0);else if(!1===e||""===e)m(t.frag),t.hidden=!0;else{let n=t.frag.prev.nextSibling;if(3!==n.nodeType){const e=document.createTextNode("");n.replaceWith(e),n=e}void 0!==e&&n.data!==e&&(n.data=e)}}(a,n[r])}},{effect:!0})}function k(e,t,n,r){const i=Symbol("$attr");r[i]={},r[i].frag=g(e);const o=f(n);f(()=>{if(!r[i])return;if(r.stale||r[i].stale)return delete r[i];let a=o.value;"value"===t?a.signal?e.value=a.value:e.value=a:"ref"===t?(e.removeAttribute(t),n.signal&&(n.value=e)):function(e,t,n){!0===n?e.setAttribute(t,t):!1===n?e.removeAttribute(t):!1!==n&&null!=n&&e.setAttribute(t,n)}(e,t,a)},{effect:!0})}function E(e,t){return document.createTreeWalker(e,128,{acceptNode:e=>e.textContent===t?1:2}).nextNode()}function M(e,t,n={0:{}}){if(!e)return console.error("MiNi: renderClient missing node element");if(e.nodeType&&(e=g(e)),"function"==typeof t&&!t.html&&(t=h(t)),"function"==typeof t&&t.html&&(t=h(t)),void 0===t.html)return console.error("MiNi: unknown input to renderClient",t);const{html:r,reactarray:i}=t,o=document.createElement("template");o.innerHTML=r;const a=e.prev?.parentNode||e.parent;for(let e=0;e<i.length;e++){let t,{type:r,key:s,v:l}=i[e];switch(r){case"node":t=E(o.content,"rx"+s),t?"function"==typeof l?$(t,l,n):l instanceof Promise?console.error("MiNi: wrap async component in ()=>{}"):!0===l.html?t=M(t,l,n):console.error("MiNi: unknown node value",l):console.error("MiNi: cannot find placeholder","rx"+s,a);break;case"@":case":":t=o.content.querySelector(`[${s+e}]`),t?(t.removeAttribute(s+e),":"===r?k(t,s,l,n):"@"===r?t.addEventListener(s.toLowerCase(),l,"onwheel"===s?{passive:!1}:{}):console.error("MiNi: unknown special attr",r,e)):console.error("MiNi: cannot find attribute",s+e)}}return m(e),e.next?e.next.before(o.content):a?.appendChild(o.content),e.destroy=()=>{const t=C(n);t.length&&t.forEach(e=>"function"==typeof e&&e()),S(n),m(e)},e}async function L(e,t,n){if(e.appendChild(document.createElement("div")),"function"!=typeof t)return console.error("MiNi: render 2nd arg must be a function");let r={0:{}};try{const o=await M(e.children[0],i`${()=>t()}`,r);return n&&console.log("rootowner",r),o}catch(e){console.error("MiNi: render",e)}}function T({content:e,buttons:t,onCancel:n,onClose:r,type:o,placeholder:a="",width:s}){const l="10000000-1000-4000-8000-100000000000".replace(/[018]/g,e=>(+e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>+e/4).toString(16));function c(e){e.preventDefault(),e.stopPropagation(),n(document.getElementById(l))}function u(e){"Escape"===e.key?c(e):"Enter"===e.key&&function(e){if(e.preventDefault(),e.stopPropagation(),r)r(document.getElementById(l),document.getElementById("_in"+l).value)}(e)}return b(()=>{"prompt"===o?setTimeout(()=>{document.getElementById("_in"+l)?.focus()},10):t&&setTimeout(()=>{document.getElementById("_btn"+l)?.focus()},10)}),i`<div id="${l}" aria-busy="true" class='alert' @click="${c}"><div class='alert-message' @click="${e=>e.stopPropagation()}" @keyup="${u}"><div class="msg" style="${s?"width:"+s+"px;":""}">${e} ${"prompt"===o&&`<br/><input type='text' id='_in${l}' @keyup="${u}" placeholder="${a||""}"/>`}</div><div>${t?.map((e,t)=>()=>i`<button id="${e.focus?"_btn"+l:""}" @click="${t=>function(e,t){e.preventDefault(),e.stopPropagation(),t(document.getElementById(l),document.getElementById("_in"+l)?.value)}(t,e.onClick)}" tabindex="${t+1}" >${e.label}</button>`)}</div></div></div>`}async function A(e,t){return await new Promise((n,r)=>{const i=document.body.querySelector("div"),o=document.createElement("div");function a(e){e.parentElement.remove(),n(!1)}i.appendChild(o),L(o,()=>T({content:e,buttons:[{label:"OK",onClick:a,focus:!0}],onCancel:a,type:"alert",width:t}))})}const B={};let I;function R(...e){let t;if(!I){const e=window._ctx_||{url:window.location.pathname};I=U(t=>({...B,...e}))}if(t=I,!e||!e.length)return t.getState();if(1===e.length){if("string"==typeof e[0])return t.getState()[e[0]];if("object"==typeof e[0])return t.setState(e[0]);console.error("MiNi: unknown store argument")}else{if(2===e.length){if("string"!=typeof e[0])return console.error("MiNi: unknown store argument");if("function"==typeof e[1]){const n=t.getState()[e[0]];e[1]=e[1](n)}return t.setState({[e[0]]:e[1]})}console.error("MiNi: store has too many arguments")}}const P=e=>{let t;const n=(e,n)=>{const r="function"==typeof e?e(t):e;Object.is(r,t)||(t=n??("object"!=typeof r||null===r)?r:Object.assign({},t,r))},r=()=>t,i={setState:n,getState:r,getInitialState:()=>o},o=t=e(n,r,i);return i},U=e=>e?P(e):P;var F=Uint8Array,D=Uint16Array,N=Int32Array,G=new F([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),O=new F([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),z=new F([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),j=function(e,t){for(var n=new D(31),r=0;r<31;++r)n[r]=t+=1<<e[r-1];var i=new N(n[30]);for(r=1;r<30;++r)for(var o=n[r];o<n[r+1];++o)i[o]=o-n[r]<<5|r;return{b:n,r:i}},X=j(G,2),W=X.b,V=X.r;W[28]=258,V[258]=28;for(var H=j(O,0).b,Y=new D(32768),Z=0;Z<32768;++Z){var q=(43690&Z)>>1|(21845&Z)<<1;q=(61680&(q=(52428&q)>>2|(13107&q)<<2))>>4|(3855&q)<<4,Y[Z]=((65280&q)>>8|(255&q)<<8)>>1}var K=function(e,t,n){for(var r=e.length,i=0,o=new D(t);i<r;++i)e[i]&&++o[e[i]-1];var a,s=new D(t);for(i=1;i<t;++i)s[i]=s[i-1]+o[i-1]<<1;if(n){a=new D(1<<t);var l=15-t;for(i=0;i<r;++i)if(e[i])for(var c=i<<4|e[i],u=t-e[i],f=s[e[i]-1]++<<u,d=f|(1<<u)-1;f<=d;++f)a[Y[f]>>l]=c}else for(a=new D(r),i=0;i<r;++i)e[i]&&(a[i]=Y[s[e[i]-1]++]>>15-e[i]);return a},J=new F(288);for(Z=0;Z<144;++Z)J[Z]=8;for(Z=144;Z<256;++Z)J[Z]=9;for(Z=256;Z<280;++Z)J[Z]=7;for(Z=280;Z<288;++Z)J[Z]=8;var Q=new F(32);for(Z=0;Z<32;++Z)Q[Z]=5;var ee=K(J,9,1),te=K(Q,5,1),ne=function(e){for(var t=e[0],n=1;n<e.length;++n)e[n]>t&&(t=e[n]);return t},re=function(e,t,n){var r=t/8|0;return(e[r]|e[r+1]<<8)>>(7&t)&n},ie=function(e,t){var n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(7&t)},oe=function(e){return(e+7)/8|0},ae=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],se=function(e,t,n){var r=new Error(t||ae[e]);if(r.code=e,Error.captureStackTrace&&Error.captureStackTrace(r,se),!n)throw r;return r},le=function(e,t,n,r){var i=e.length;if(!i||t.f&&!t.l)return n||new F(0);var o=!n,a=o||2!=t.i,s=t.i;o&&(n=new F(3*i));var l=function(e){var t=n.length;if(e>t){var r=new F(Math.max(2*t,e));r.set(n),n=r}},c=t.f||0,u=t.p||0,f=t.b||0,d=t.l,p=t.d,h=t.m,v=t.n,g=8*i;do{if(!d){c=re(e,u,1);var m=re(e,u+1,3);if(u+=3,!m){var x=e[(L=oe(u)+4)-4]|e[L-3]<<8,b=L+x;if(b>i){s&&se(0);break}a&&l(f+x),n.set(e.subarray(L,b),f),t.b=f+=x,t.p=u=8*b,t.f=c;continue}if(1==m)d=ee,p=te,h=9,v=5;else if(2==m){var y=re(e,u,31)+257,w=re(e,u+10,15)+4,C=y+re(e,u+5,31)+1;u+=14;for(var _=new F(C),S=new F(19),$=0;$<w;++$)S[z[$]]=re(e,u+3*$,7);u+=3*w;var k=ne(S),E=(1<<k)-1,M=K(S,k,1);for($=0;$<C;){var L,T=M[re(e,u,E)];if(u+=15&T,(L=T>>4)<16)_[$++]=L;else{var A=0,B=0;for(16==L?(B=3+re(e,u,3),u+=2,A=_[$-1]):17==L?(B=3+re(e,u,7),u+=3):18==L&&(B=11+re(e,u,127),u+=7);B--;)_[$++]=A}}var I=_.subarray(0,y),R=_.subarray(y);h=ne(I),v=ne(R),d=K(I,h,1),p=K(R,v,1)}else se(1);if(u>g){s&&se(0);break}}a&&l(f+131072);for(var P=(1<<h)-1,U=(1<<v)-1,D=u;;D=u){var N=(A=d[ie(e,u)&P])>>4;if((u+=15&A)>g){s&&se(0);break}if(A||se(2),N<256)n[f++]=N;else{if(256==N){D=u,d=null;break}var j=N-254;if(N>264){var X=G[$=N-257];j=re(e,u,(1<<X)-1)+W[$],u+=X}var V=p[ie(e,u)&U],Y=V>>4;V||se(3),u+=15&V;R=H[Y];if(Y>3){X=O[Y];R+=ie(e,u)&(1<<X)-1,u+=X}if(u>g){s&&se(0);break}a&&l(f+131072);var Z=f+j;if(f<R){var q=0-R,J=Math.min(R,Z);for(q+f<0&&se(3);f<J;++f)n[f]=r[q+f]}for(;f<Z;++f)n[f]=n[f-R]}}t.l=d,t.p=D,t.b=f,t.f=c,d&&(c=1,t.m=h,t.d=p,t.n=v)}while(!c);return f!=n.length&&o?function(e,t,n){return(null==n||n>e.length)&&(n=e.length),new F(e.subarray(t,n))}(n,0,f):n.subarray(0,f)},ce=new F(0);function ue(e,t){var n,r,i=function(e){31==e[0]&&139==e[1]&&8==e[2]||se(6,"invalid gzip data");var t=e[3],n=10;4&t&&(n+=2+(e[10]|e[11]<<8));for(var r=(t>>3&1)+(t>>4&1);r>0;r-=!e[n++]);return n+(2&t)}(e);return i+8>e.length&&se(6,"invalid gzip data"),le(e.subarray(i,-8),{i:2},new F((r=(n=e).length,(n[r-4]|n[r-3]<<8|n[r-2]<<16|n[r-1]<<24)>>>0)),t)}function fe(e,t){return le(e.subarray(((8!=(15&(n=e)[0])||n[0]>>4>7||(n[0]<<8|n[1])%31)&&se(6,"invalid zlib data"),1==(n[1]>>5&1)&&se(6,"invalid zlib data: "+(32&n[1]?"need":"unexpected")+" dictionary"),2+(n[1]>>3&4)),-4),{i:2},t,t);var n}function de(e,t){return 31==e[0]&&139==e[1]&&8==e[2]?ue(e,t):8!=(15&e[0])||e[0]>>4>7||(e[0]<<8|e[1])%31?function(e,t){return le(e,{i:2},t,t)}(e,t):fe(e,t)}var pe="undefined"!=typeof TextDecoder&&new TextDecoder;try{pe.decode(ce,{stream:!0})}catch(e){}function he(e,t,n){for(var r="",i=t;i<t+n;i++)r+=String.fromCharCode(e.getUint8(i));return r}function ve(e){return new Uint8Array([e>>24&255,e>>16&255,e>>8&255,255&e])}function ge(e){return new Uint8Array([e>>8&255,255&e])}function me(e){return Uint8Array.from(Array.from(e).map(e=>e.charCodeAt(0)))}function xe(...e){const t=new Uint8Array(e.reduce((e,t)=>e+t.byteLength,0));return e.reduce((e,n)=>(t.set(new Uint8Array(n),e),e+n.byteLength),0),t.buffer}function be(e,t){if(!document)return console.error("[MiNi exif]: download file is browser only");if(!t)return console.error("[MiNi exif]: download missing output filename");if(!(e&&(e instanceof ArrayBuffer||e instanceof Blob)))return console.error("[MiNi exif]: download wrong data input");let n;e instanceof ArrayBuffer&&(n=new Blob([e]));var r=document.createElement("a");r.href=URL.createObjectURL(n),r.download=t,r.click()}var ye={256:"ImageWidth",257:"ImageHeight",34665:"ExifIFDPointer",34675:"ICCProfileIFDPointer",34853:"GPSInfoIFDPointer",258:"BitsPerSample",259:"Compression",262:"PhotometricInterpretation",274:"Orientation",277:"SamplesPerPixel",284:"PlanarConfiguration",530:"YCbCrSubSampling",531:"YCbCrPositioning",282:"XResolution",283:"YResolution",296:"ResolutionUnit",273:"StripOffsets",278:"RowsPerStrip",279:"StripByteCounts",513:"JPEGInterchangeFormat",514:"JPEGInterchangeFormatLength",301:"TransferFunction",318:"WhitePoint",319:"PrimaryChromaticities",529:"YCbCrCoefficients",532:"ReferenceBlackWhite",306:"DateTime",270:"ImageDescription",271:"Make",272:"Model",305:"Software",315:"Artist",316:"HostComputer",33432:"Copyright"},we={36864:"ExifVersion",40960:"FlashpixVersion",40961:"ColorSpace",40962:"PixelXDimension",40963:"PixelYDimension",37121:"ComponentsConfiguration",37122:"CompressedBitsPerPixel",40964:"RelatedSoundFile",36867:"DateTimeOriginal",36868:"DateTimeDigitized",37520:"SubsecTime",37521:"SubsecTimeOriginal",37522:"SubsecTimeDigitized",33434:"ExposureTime",33437:"FNumber",34850:"ExposureProgram",34852:"SpectralSensitivity",34855:"ISOSpeedRatings",34856:"OECF",37377:"ShutterSpeedValue",37378:"ApertureValue",37379:"BrightnessValue",37380:"ExposureBias",37381:"MaxApertureValue",37382:"SubjectDistance",37383:"MeteringMode",37384:"LightSource",37385:"Flash",37396:"SubjectArea",37386:"FocalLength",41483:"FlashEnergy",41484:"SpatialFrequencyResponse",41486:"FocalPlaneXResolution",41487:"FocalPlaneYResolution",41488:"FocalPlaneResolutionUnit",41492:"SubjectLocation",41493:"ExposureIndex",41495:"SensingMethod",41728:"FileSource",41729:"SceneType",41730:"CFAPattern",41985:"CustomRendered",41986:"ExposureMode",41987:"WhiteBalance",41988:"DigitalZoomRation",41989:"FocalLengthIn35mmFilm",41990:"SceneCaptureType",41991:"GainControl",41992:"Contrast",41993:"Saturation",41994:"Sharpness",41995:"DeviceSettingDescription",41996:"SubjectDistanceRange",42035:"LensMake",42036:"LensModel",42016:"ImageUniqueID"},Ce={0:"GPSVersionID",1:"GPSLatitudeRef",2:"GPSLatitude",3:"GPSLongitudeRef",4:"GPSLongitude",5:"GPSAltitudeRef",6:"GPSAltitude",7:"GPSTimeStamp",8:"GPSSatellites",9:"GPSStatus",10:"GPSMeasureMode",11:"GPSDOP",12:"GPSSpeedRef",13:"GPSSpeed",14:"GPSTrackRef",15:"GPSTrack",16:"GPSImgDirectionRef",17:"GPSImgDirection",18:"GPSMapDatum",19:"GPSDestLatitudeRef",20:"GPSDestLatitude",21:"GPSDestLongitudeRef",22:"GPSDestLongitude",23:"GPSDestBearingRef",24:"GPSDestBearing",25:"GPSDestDistanceRef",26:"GPSDestDistance",27:"GPSProcessingMethod",28:"GPSAreaInformation",29:"GPSDateStamp",30:"GPSDifferential"},_e={ExposureMode:{0:"Auto",1:"Manual",2:"Auto Bracket"},ExposureProgram:{0:"Not defined",1:"Manual",2:"Normal program",3:"Aperture priority",4:"Shutter priority",5:"Creative program",6:"Action program",7:"Portrait mode",8:"Landscape mode"},MeteringMode:{0:"Unknown",1:"Average",2:"CenterWeightedAverage",3:"Spot",4:"MultiSpot",5:"Pattern",6:"Partial",255:"Other"},LightSource:{0:"Unknown",1:"Daylight",2:"Fluorescent",3:"Tungsten (incandescent light)",4:"Flash",9:"Fine weather",10:"Cloudy weather",11:"Shade",12:"Daylight fluorescent (D 5700 - 7100K)",13:"Day white fluorescent (N 4600 - 5400K)",14:"Cool white fluorescent (W 3900 - 4500K)",15:"White fluorescent (WW 3200 - 3700K)",17:"Standard light A",18:"Standard light B",19:"Standard light C",20:"D55",21:"D65",22:"D75",23:"D50",24:"ISO studio tungsten",255:"Other"},Flash:{0:"Flash did not fire",1:"Flash fired",5:"Strobe return light not detected",7:"Strobe return light detected",9:"Flash fired, compulsory flash mode",13:"Flash fired, compulsory flash mode, return light not detected",15:"Flash fired, compulsory flash mode, return light detected",16:"Flash did not fire, compulsory flash mode",24:"Flash did not fire, auto mode",25:"Flash fired, auto mode",29:"Flash fired, auto mode, return light not detected",31:"Flash fired, auto mode, return light detected",32:"No flash function",65:"Flash fired, red-eye reduction mode",69:"Flash fired, red-eye reduction mode, return light not detected",71:"Flash fired, red-eye reduction mode, return light detected",73:"Flash fired, compulsory flash mode, red-eye reduction mode",77:"Flash fired, compulsory flash mode, red-eye reduction mode, return light not detected",79:"Flash fired, compulsory flash mode, red-eye reduction mode, return light detected",89:"Flash fired, auto mode, red-eye reduction mode",93:"Flash fired, auto mode, return light not detected, red-eye reduction mode",95:"Flash fired, auto mode, return light detected, red-eye reduction mode"},SensingMethod:{1:"Not defined",2:"One-chip color area sensor",3:"Two-chip color area sensor",4:"Three-chip color area sensor",5:"Color sequential area sensor",7:"Trilinear sensor",8:"Color sequential linear sensor"},SceneCaptureType:{0:"Standard",1:"Landscape",2:"Portrait",3:"Night scene"},SceneType:{1:"Directly photographed"},CustomRendered:{0:"Normal process",1:"Custom process"},WhiteBalance:{0:"Auto white balance",1:"Manual white balance"},GainControl:{0:"None",1:"Low gain up",2:"High gain up",3:"Low gain down",4:"High gain down"},Contrast:{0:"Normal",1:"Soft",2:"Hard"},Saturation:{0:"Normal",1:"Low saturation",2:"High saturation"},Sharpness:{0:"Normal",1:"Soft",2:"Hard"},SubjectDistanceRange:{0:"Unknown",1:"Macro",2:"Close view",3:"Distant view"},FileSource:{3:"DSC"},Components:{0:"",1:"Y",2:"Cb",3:"Cr",4:"R",5:"G",6:"B"},ColorSpace:{1:"sRGB",2:"Adobe RGB",65533:"Wide Gamut RGB",65534:"ICC Profile",65535:"Uncalibrated"}};function Se(e,t,n,r,i){var o,a,s,l=e.getUint16(n,!i),c={};for(s=0;s<l;s++){o=n+12*s+2;(a=r[e.getUint16(o,!i)])&&(c[a]=$e(e,o,t,n,i))}return c}function $e(e,t,n,r,i){var o,a,s,l,c,u,f=e.getUint16(t+2,!i),d=e.getUint32(t+4,!i),p=e.getUint32(t+8,!i)+n;switch(f){case 1:case 7:if(1==d)o=t+8,s=e.getUint8(o,!i);else for(o=d>4?p:t+8,a=[],l=0;l<d;l++)a[l]=e.getUint8(o+l);break;case 2:(a=he(e,o=d>4?p:t+8,d-1)).length;break;case 3:if(1==d)o=t+8,s=e.getUint16(o,!i);else for(o=d>2?p:t+8,a=[],l=0;l<d;l++)a[l]=e.getUint16(o+2*l,!i);break;case 4:if(1==d)o=t+8,s=e.getUint32(o,!i);else for(o=p,a=[],l=0;l<d;l++)a[l]=e.getUint32(o+4*l,!i);break;case 9:if(1==d)o=t+8,s=e.getInt32(o,!i);else for(o=p,a=[],l=0;l<d;l++)a[l]=e.getInt32(o+4*l,!i);break;case 5:if(1==d)o=p,c=e.getUint32(o,!i),u=e.getUint32(o+4,!i),(s=new Number(c/u)).numerator=c,s.denominator=u;else for(o=p,a=[],l=0;l<d;l++)c=e.getUint32(o+8*l,!i),u=e.getUint32(o+4+8*l,!i),a[l]=new Number(c/u),a[l].numerator=c,a[l].denominator=u;break;case 10:if(1==d)o=p,c=e.getInt32(o,!i),u=e.getInt32(o+4,!i),(s=new Number(c/u)).numerator=c,s.denominator=u;else for(o=p,a=[],l=0;l<d;l++)c=e.getInt32(o+8*l,!i),u=e.getInt32(o+4+8*l,!i),a[l]=new Number(c/u),a[l].numerator=c,a[l].denominator=u}if(f)return{value:a||s,offset:o-n,type:f}}function ke(e,t=0){if(!(e instanceof ArrayBuffer))return console.error("[MiNi exif]: input must be an ArrayBuffer");var n,r,i,o,a;const s=new DataView(e);if(18761==s.getUint16(t))n=!1;else{if(19789!=s.getUint16(t))return console.error("[MiNi exif]: Not valid TIFF data! (no 0x4949 or 0x4D4D)"),!1;n=!0}if(42!=s.getUint16(t+2,!n))return console.error("[MiNi exif]: Not valid TIFF data! (no 0x002A)"),!1;var l=s.getUint32(t+4,!n);if(l<8)return console.error("[MiNi exif]: Not valid TIFF data! (First offset less than 8)",s.getUint32(tiffOffset+4,!n)),!1;if((r={tiff:Se(s,t,t+l,ye,n)}).tiff.ExifIFDPointer){for(i in o=Se(s,t,t+r.tiff.ExifIFDPointer.value,we,n))switch(i){case"LightSource":case"Flash":case"MeteringMode":case"ExposureMode":case"ExposureProgram":case"SensingMethod":case"SceneCaptureType":case"SceneType":case"CustomRendered":case"WhiteBalance":case"GainControl":case"Contrast":case"Saturation":case"Sharpness":case"SubjectDistanceRange":case"FileSource":case"ColorSpace":o[i].hvalue=_e[i][o[i].value];break;case"ExposureTime":o[i].hvalue=o[i].value.numerator+"/"+o[i].value.denominator;break;case"ShutterSpeedValue":o[i].hvalue="1/"+Math.round(Math.pow(2,o[i].value));break;case"ExifVersion":case"FlashpixVersion":o[i].hvalue=String.fromCharCode(o[i].value[0],o[i].value[1],o[i].value[2],o[i].value[3]);break;case"ApertureValue":case"BrightnessValue":o[i].hvalue=Math.round(1e3*o[i].value)/1e3;break;case"ComponentsConfiguration":o[i].hvalue=_e.Components[o[i].value[0]]+_e.Components[o[i].value[1]]+_e.Components[o[i].value[2]]+_e.Components[o[i].value[3]]}r.exif=o,delete r.tiff.ExifIFDPointer}if(r.tiff.GPSInfoIFDPointer){for(i in a=Se(s,t,t+r.tiff.GPSInfoIFDPointer.value,Ce,n))switch(i){case"GPSVersionID":a[i].hvalue=a[i].value[0]+"."+a[i].value[1]+"."+a[i].value[2]+"."+a[i].value[3];break;case"GPSLatitude":a[i].hvalue=a[i].value[0]+a[i].value[1]/60+a[i].value[2]/3600,a[i].hvalue=("N"===a.GPSLatitudeRef.value?1:-1)*a[i].hvalue;break;case"GPSLongitude":a[i].hvalue=a[i].value[0]+a[i].value[1]/60+a[i].value[2]/3600,a[i].hvalue=("E"===a.GPSLongitudeRef.value?1:-1)*a[i].hvalue;break;case"GPSTimeStamp":a[i].hvalue=a[i].value[0].toString().padStart(2,"0")+":"+a[i].value[1].toString().padStart(2,"0")+":"+a[i].value[2].toString().padStart(2,"0")+" UTC"}r.gps=a,delete r.tiff.GPSInfoIFDPointer}return r}function Ee(e,t,n,r,i,o){if(!(e&&n&&r&&i&&t))return!1;const a=["exif","tiff","gps"];if(!a.includes(n))return console.error("[MiNi exif]: area must be one of",a);if(!e[n][r])return console.error("[MiNi exif]: '"+n+"/"+r+"' not present");if(!t)return!1;if(o){if(typeof i!=typeof o)return console.error("[MiNi exif]: newvalue type mismatch vs newvalue2",i,o);if(Array.isArray(i)){let e=[];for(let t=0;t<i.length;t++){let n=new Number(i[t]/o[t]);n.numerator=i[t],n.denominator=o[t],e.push(n)}i=e}else{let e=new Number(i/o);e.numerator=i,e.denominator=o,i=e}}const s=e[n][r],l=s.value.length||1;if(typeof i!=typeof s.value)return console.error("[MiNi exif]: newvalue type mismatch vs oldvalue",s.value,i);if(l>1&&(!i.length||i.length<1||i.length>l))return console.error("[MiNi exif]: newvalue too long",s.value,i);if(l>1&&i.length<l)if(Array.isArray(s.value))for(let e=0;e<l-i.length;e++)i.push(0);else{if("string"!=typeof s.value)return console.error("[MiNi exif]: unknown type",s.value,i);i=i.concat(" ".repeat(l-i.length))}const c=new DataView(t);let u,f;if(18761==c.getUint16(0)?u=!1:19789==c.getUint16(0)&&(u=!0),void 0===u)return console.error("[MiNi exif]: exif_raw corrupted");const d=s.type,p=s.offset;switch(d){case 1:case 7:if(1==l)c.setUint8(p,i,!u);else for(f=0;f<l;f++)c.setUint8(p+f,i[f],!u);break;case 2:for(f=0;f<l;f++)c.setUint8(p+f,i.charCodeAt(f),!u);break;case 3:if(1==l)c.setUint16(p,i,!u);else for(f=0;f<l;f++)c.setUint16(p+f,i[f],!u);break;case 4:if(1==l)c.setUint32(p,i,!u);else for(f=0;f<l;f++)c.setUint32(p+f,i[f],!u);break;case 9:if(1==l)c.setInt32(p,i,!u);else for(f=0;f<l;f++)c.setInt32(p+f,i[f],!u);break;case 5:if(1==l)c.setUint32(p,i.numerator,!u),c.setUint32(p+4,i.denominator,!u);else for(f=0;f<l;f++)c.setUint32(p+8*f,i[f].numerator,!u),c.setUint32(p+4+8*f,i[f].denominator,!u);break;case 10:if(1==l)c.setInt32(p,i.numerator,!u),c.setInt32(p+4,i.denominator,!u);else for(f=0;f<l;f++)c.setInt32(p+8*f,i[f].numerator,!u),c.setInt32(p+4+8*f,i[f].denominator,!u)}return t}function Me(e,t=0){if(!(e instanceof ArrayBuffer))return console.error("[MiNi exif]: input must be an ArrayBuffer");const n=new DataView(e);if(1633907568!==n.getUint32(t+36))return console.error("[MiNi exif]: ICC missing valid signature");const r=he(n,t+16,4),i=n.getUint32(t+128);let o=t+128+4,a={ColorSpace:r};for(let e=0;e<i;e++){let e=he(n,o,4),r=n.getUint32(o+4),i=n.getUint32(o+8);if("desc"===e){e="ColorProfile";const o=he(n,t+r,4);let s=[];if("mluc"===o){const e=n.getUint32(t+r+8);if(12!==n.getUint32(t+r+12))return console.error("[MiNi exif]: ICC with invalid mluc");const i=t+r+16;for(let o=0;o<e;o++){const e=n.getUint32(i+12*o+4),a=n.getUint32(i+12*o+8);s.push(he(n,t+r+a,e).replaceAll("\0",""))}r+=28}else"desc"===o&&(i=n.getUint32(t+r+8),s.push(he(n,t+r+12,i).replaceAll("\0","")));a[e]=s}o+=12}return a}function Le(e){if(!(e instanceof ArrayBuffer))return console.error("[MiNi exif]: input must be an ArrayBuffer");const t=e.byteLength,n=new DataView(e);if(65496!==n.getUint16(0))return console.error("[MiNi exif]: data is not JPG");let r=[],i=null,o=2;for(r.push({marker:"0xFFD8",data:e.slice(0,2)});65498!=i;){let a=o;i=n.getUint16(a);const s=n.getUint16(a+2),l=i.toString(16).toUpperCase().padStart(6,"0x");65498!=i?r.push({marker:l,data:e.slice(o,o+2+s)}):r.push({marker:l,data:e.slice(o,t)}),o+=2+s}return r}function Te(e){const t=Le(e);let n,r;const i=t.filter(e=>"0xFFE1"===e.marker);i?.length&&i.forEach(e=>{"Exif"===String.fromCharCode(...new Uint8Array(e.data.slice(4,8)))?n=e:r=e});const o=function(e,t){const n="ICC_PROFILE\0";t||(t=Le(e));const r=t.find(e=>"0xFFE2"===e.marker);return r?String.fromCharCode(...new Uint8Array(r.data.slice(4,16)))!==n?(console.error("[MiNi exif]: ICC_PROFILE missing"),null):r:null}(e,t);return{exif:n?.data,icc:o?.data,xml:r?.data}}function Ae(e,t){if(!e)return console.error("[MiNi exif]: please load file first");if(!t)return console.error("[MiNi exif]: exif data missing");const n=Le(e).filter(e=>"0xFFE1"!==e.marker),r=function(e){return xe(ge(65505).buffer,ge(e.byteLength+8).buffer,me("Exif\0\0").buffer,e)}(t);return xe(n[0].data,r,...n.slice(1).map(e=>e.data))}function Be(e){let t,n,r,i,o,a=e;function s(){if(a){const{exif:e,icc:i,xml:o}=Te(a);t=e,n=i,r=o}if(t?(i=ke(t,10),o=t.slice(10)):(i=null,o=null),n&&(i={...i,icc:Me(n,18)}),r){const e=(new TextDecoder).decode(r.slice(4));i={...i,xml:e}}}return s(),{load:e=>{a=e,s()},remove:()=>(a=function(e){return e?xe(...Le(e).filter(e=>"0xFFE1"!==e.marker).map(e=>e.data)):console.error("[MiNi exif]: please load file first")}(a),s(),a),read:()=>({...i,format:"JPG"}),extract:()=>o,image:()=>a,replace:e=>(a=Ae(a,e),s(),a),download:e=>be(a,e),patch:e=>{function t(e){if(!(e instanceof Object))return console.error("[MiNi exif]: patch wrong input",e);{const{area:t,field:n,value:r,value2:a}=e;if(!t||!n||void 0===r)return console.error("[MiNi exif]: patch missing input",t,n,r);o=Ee(i,o,t,n,r,a)}}if(!i)return console.error("[MiNi exif]: no exif data");e instanceof Array?e.forEach(e=>t(e)):e instanceof Object&&t(e),a=Ae(a,o),s()}}}let Ie;function Re(e,t,n){const r=e.getUint32(t),i=he(e,t+4,4),o=t+8,a=e.getUint32(t+8+r);return{len:r,type:i,data:n.slice(t,t+12+r),dataoffset:o,crc:a}}function Pe(e){return e.data.slice(8,-4)}function Ue(e,t){const n=e.byteLength;let r=xe(ve(e.byteLength).buffer,me(t).buffer,e);const i=function(e){if(!Ie){Ie=new Uint32Array(256);for(let e=0;e<256;e++){let t=e;for(let e=0;e<8;e++)1&t?t=3988292384^t>>>1:t>>>=1;Ie[e]=t}}for(var t=-1,n=new Uint8Array(e),r=0;r<e.byteLength;r++)t=t>>>8^Ie[255&(t^n[r])];return(-1^t)>>>0}(r.slice(4));return r=xe(r,ve(i).buffer),{len:n,type:t,data:r,crc:i}}function Fe(e){if(!(e instanceof ArrayBuffer))return console.error("[MiNi exif]: input must be an ArrayBuffer");const t=e.byteLength,n=new DataView(e);if(2303741511!==n.getUint32(0)||218765834!==n.getUint32(4))return console.error("[MiNi exif]: data is not PNG");let r=8,i=[{len:8,type:"",data:e.slice(0,8),dataoffset:0,crc:0}];for(;r<t;){const t=Re(n,r,e);i.push(t),r+=12+t.len}return i}function De(e){const t=Fe(e);let n=t.find(e=>"eXIf"===e.type);n&&(n=Pe(n));let r=function(e,t){t||(t=Fe(e));const n=t.find(e=>"iCCP"===e.type);return n?Pe(n):null}(e,t);if(r){let e=!0,t=0,n=new Uint8Array(r);for(;0!==e;)e=n[t++];t++,n=n.slice(t),r=de(new Uint8Array(n))?.buffer}let i=function(e,t){t||(t=Fe(e));let n=null;const r=t.filter(e=>"iTXt"===e.type);return r?.length&&r.forEach(e=>{const t=Pe(e);"XML"===String.fromCharCode(...new Uint8Array(t.slice(0,3)))&&(n=t)}),n}(e,t);return{exif:n,icc:r,xml:i}}function Ne(e,t){if(!e)return console.error("[MiNi exif]: please load file first");if(!t)return console.error("[MiNi exif]: exif data missing");const n=Fe(e).filter(e=>"eXIf"!==e.type&&"iTXt"!==e.type),r=Ue(t,"eXIf");return xe(...n.slice(0,2).map(e=>e.data),r.data,...n.slice(2).map(e=>e.data))}function Ge(e){let t,n,r,i,o,a=e;function s(){if(a){const{exif:e,icc:i,xml:o}=De(a);t=e,n=i,r=o}if(t?(i=ke(t,0),o=t.slice(0)):(i=null,o=null),n&&(i={...i,icc:Me(n,0)}),r){const e=(new TextDecoder).decode(r);i={...i,xml:e}}}return s(),{load:e=>{a=e,s()},remove:()=>(a=function(e){return e?xe(...Fe(e).filter(e=>"eXIf"!==e.type&&"iTXt"!==e.type).map(e=>e.data)):console.error("[MiNi exif]: please load file first")}(a),s(),a),read:()=>({...i,format:"PNG"}),extract:()=>o,image:()=>a,replace:e=>(a=Ne(a,e),s(),a),download:e=>be(a,e),patch:e=>{function t(e){if(!(e instanceof Object))return console.error("[MiNi exif]: patch input wrong",e);{const{area:t,field:n,value:r,value2:a}=e;if(!t||!n||void 0===r)return console.error("[MiNi exif]: patch input missing",t,n,r);o=Ee(i,o,t,n,r,a)}}if(!i)return console.error("[MiNi exif]: no exif data");e instanceof Array?e.forEach(e=>t(e)):e instanceof Object&&t(e),a=Ne(a,o),s()}}}function Oe(e,t){const{length:n,contentOffset:r}=function(e,t){const n=e.getUint32(t);return 0===n?{length:e.byteLength-t,contentOffset:t+4+4}:1===n&&0===e.getUint32(t+8)?{length:e.getUint32(t+12),contentOffset:t+4+4+8}:{length:n,contentOffset:t+4+4}}(e,t);return n<8?void 0:{type:e.getUint32(t+4),length:n,str:he(e,t+4,4),contentOffset:r}}function ze(e,t){let n={},r=t.length-8,i=t.contentOffset;for(;r>0;){const t=he(e,i+4,4),o=e.getUint32(i);n[t]={length:o,str:t,contentOffset:i+8},i+=o,r-=o}return n}function je(e,t,n){if(!e)return console.error("[MiNi exif]: please load file first");if(!t)return console.error("[MiNi exif]: exif data missing");const r=n.offset,i=n.data.byteLength;return xe(e.slice(0,r),t,e.slice(r+i))}function Xe(e){let t,n,r,i,o,a=e;function s(){if(a){const{exif:e,icc:o,xml:s,_format:l}=function(e){if(!(e instanceof ArrayBuffer))return console.error("[MiNi exif]: input must be an ArrayBuffer");e.byteLength;const t=new DataView(e);if(1718909296!==t.getUint32(4)&&1751476579!==t.getUint32(8)||1718909296!==t.getUint32(4)&&1635150182!==t.getUint32(8))return console.error("[MiNi exif]: data is not HEIC/AVIF");let n={};n=1751476579===t.getUint32(8)?{_format:"HEIC"}:{_format:"AVIF"};let r,i,o=0,a={},s={};for(;o+4+4<=t.byteLength;){const n=Oe(t,o);if(void 0===n)break;if("meta"!==n.str){if("iinf"===n.str){let e=t.getUint32(n.contentOffset+2),o=n.contentOffset+8+2;for(let n=0;n<e;n++)if(1165519206===t.getUint32(o+12)?r=t.getUint32(o+8):1835625829===t.getUint32(o+12)&&(i=t.getUint32(o+8)),n+1<e)for(o+=16;1768842853!==t.getUint32(o)&&o<2e4;)o++}else if("iloc"===n.str){t.getUint32(n.contentOffset+2);const e=t.getUint16(n.contentOffset+6),r=(n.length-16)/e,i=n.contentOffset+8;for(let n=0;n<e;n++)if(16===r){const e=t.getUint32(i+n*r),o=t.getUint32(i+n*r+8),a=t.getUint32(i+n*r+12);s[e]={id:e,off:o,size:a,type:"heic"}}else if(18===r){const e=t.getUint32(i+n*r);let o=t.getUint32(i+n*r+4);o||(o=t.getUint32(i+n*r+10));const a=t.getUint32(i+n*r+14);s[e]={id:e,off:o,size:a,type:"avif"}}else console.error("[MiNi exif]: unknown iloc block length",r)}else if("iprp"===n.str){const r=ze(t,n);if(r.ipco){const n=ze(t,r.ipco);if(n.colr){const r=he(t,n.colr.contentOffset,4);if("prof"===r||"rICC"===r){const t=n.colr.contentOffset+4;a={offset:t,data:e.slice(t,t+n.colr.length-8)}}}}}o+=n.length}else o+=12}if(r&&s[r]){const{off:i,size:o,type:a}=s[r];if("heic"===a){const r=t.getUint32(i),a=e.slice(i+4+r,i+4+r+o-4-r);n.exif={data:a,offset:i+4+r}}else if("avif"===a){const r=t.getUint32(i),a=e.slice(i+4+r,i+4+r+o-4-r);n.exif={data:a,offset:i+4+r}}}if(i&&s[i]){const{off:t,size:r,type:o}=s[i];if("heic"===o){const i=e.slice(t,t+r);n.xml={data:i,offset:t}}else if("avif"===o){const i=e.slice(t,t+r);n.xml={data:i,offset:t}}}return n.icc=a,n}(a);n=e,r=o,i=s,t=l}!function(){if(n?.data?(o=ke(n.data,0),o={...o,format:t}):o=null,r?.data&&(o={...o,icc:Me(r.data,0)}),i){const e=(new TextDecoder).decode(i.data);o={...o,xml:e}}}()}return s(),{load:e=>{a=e,s()},read:()=>o,extract:()=>n.data,image:()=>a,download:e=>be(a,e),replace:e=>e.byteLength!==n.data.byteLength?console.error("[MiNi exif]: new exif length must be "+n.data.byteLength+" bytes"):(a=je(a,e,n),s(),a),patch:e=>{function t(e){if(!(e instanceof Object))return console.error("[MiNi exif]: patch wrong input",e);{const{area:t,field:r,value:i,value2:a}=e;if(!t||!r||void 0===i)return console.error("[MiNi exif]: patch missing input",t,r,i);n.data=Ee(o,n.data,t,r,i,a)}}if(!o)return console.error("[MiNi exif]: no exif data");e instanceof Array?e.forEach(e=>t(e)):e instanceof Object&&t(e),a=je(a,n.data,n),s()}}}function We(e,t){const{length:n,contentOffset:r}=function(e,t){const n=e.getUint32(t);return 0===n?{length:e.byteLength-t,contentOffset:t+4+4}:1===n&&0===e.getUint32(t+8)?{length:e.getUint32(t+12),contentOffset:t+4+4+8}:{length:n,contentOffset:t+4+4}}(e,t);return n<8?void 0:{type:e.getUint32(t+4),length:n,str:he(e,t+4,4),contentOffset:r}}function Ve(e,t){let n={},r=t.length-8,i=t.contentOffset;for(;r>0;){const t=he(e,i+4,4),o=e.getUint32(i);n[t]={length:o,str:t,contentOffset:i+8},i+=o,r-=o}return n}function He(e,t=!1){if(!(e instanceof ArrayBuffer))return console.error("[MiNi exif]: input must be an ArrayBuffer");const n=new DataView(e);return 65496===n.getUint16(0)?Be(e):2303741511===n.getUint32(0)&&218765834===n.getUint32(4)?Ge(e):1718909296!==n.getUint32(4)||1751476579!==n.getUint32(8)&&1635150182!==n.getUint32(8)?t||1718909296===n.getUint32(4)&&1903435808===n.getUint32(8)?function(e){if(!(e instanceof ArrayBuffer))return console.error("[MiNi exif]: input must be an ArrayBuffer");e.byteLength;const t=new DataView(e);if(1718909296!==t.getUint32(4)||1903435808!==t.getUint32(8))return console.error("[MiNi exif]: data is not QuickTime");let n=0,r=[],i=[];for(;n+4+4<=t.byteLength;){const e=We(t,n);if(void 0===e)break;if("meta"!==e.str){if("moov"===e.str){const n=Ve(t,e);if(n.meta){const e=Ve(t,n.meta);let o;if(e.keys){let n=e.keys.contentOffset;e.length,o=t.getUint32(n+4),n+=8;for(let e=0;e<o;e++){const e=t.getUint32(n);if(1835299937!==t.getUint32(n+4))continue;const i=he(t,n+8,e-8);r.push(i),n+=e}r=r.map(e=>e.replace("com.apple.quicktime.",""))}if(e.ilst){let n=e.ilst.contentOffset;for(let e=0;e<o;e++){const e=t.getUint32(n),r=t.getUint32(n+8);if(1684108385!==t.getUint32(n+12))continue;const o=he(t,n+16+8,r-8-8);i.push({value:o,offset:n+16+8,type:2}),n+=e}}}}n+=e.length}else n+=12}let o={};if(r.length&&i.length){let e=r.reduce((e,t,n)=>(e[t]=i[n],e),{});if(o.meta=e,o.meta["location.ISO6709"]){const e=o.meta["location.ISO6709"].value;o.gps={GPSLatitude:{value:parseFloat(e)},GPSLongitude:{value:parseFloat(e.slice(8))},GPSAltitude:{value:parseFloat(e.slice(17))}}}}return o}(e):void console.error("[MiNi exif]: unknown format"):Xe(e)}var Ye={projection:function(e,t){return[2/e,0,0,0,2/t,0,-1,-1,1]},translation:function(e,t){return[1,0,0,0,1,0,e,t,1]},rotation:function(e){var t=Math.cos(e),n=Math.sin(e);return[t,-n,0,n,t,0,0,0,1]},scaling:function(e,t){return[e,0,0,0,t,0,0,0,1]},multiply:function(e,t){var n=e[0],r=e[1],i=e[2],o=e[3],a=e[4],s=e[5],l=e[6],c=e[7],u=e[8],f=t[0],d=t[1],p=t[2],h=t[3],v=t[4],g=t[5],m=t[6],x=t[7],b=t[8];return[f*n+d*o+p*l,f*r+d*a+p*c,f*i+d*s+p*u,h*n+v*o+g*l,h*r+v*a+g*c,h*i+v*s+g*u,m*n+x*o+b*l,m*r+x*a+b*c,m*i+x*s+b*u]}};function Ze(e){var t=e.length;this.xa=[],this.ya=[],this.u=[],this.y2=[],e.sort(function(e,t){return e[0]-t[0]});for(var n=0;n<t;n++)this.xa.push(e[n][0]),this.ya.push(e[n][1]);this.u[0]=0,this.y2[0]=0;for(n=1;n<t-1;++n){var r=this.xa[n+1]-this.xa[n-1],i=(this.xa[n]-this.xa[n-1])/r,o=i*this.y2[n-1]+2;this.y2[n]=(i-1)/o;var a=(this.ya[n+1]-this.ya[n])/(this.xa[n+1]-this.xa[n])-(this.ya[n]-this.ya[n-1])/(this.xa[n]-this.xa[n-1]);this.u[n]=(6*a/r-i*this.u[n-1])/o}this.y2[t-1]=0;for(n=t-2;n>=0;--n)this.y2[n]=this.y2[n]*this.y2[n+1]+this.u[n]}function qe(e){for(var t=new Ze(e),n=[],r=0;r<256;r++)n.push(Ke(0,Math.floor(256*t.at(r/255)),255));return n}function Ke(e,t,n){return Math.max(e,Math.min(t,n))}function Je(e,t,n,r,i,o,a,s){var l=n-i,c=r-o,u=a-i,f=s-o,d=e-n+i-a,p=t-r+o-s,h=l*f-u*c,v=(d*f-u*p)/h,g=(l*p-d*c)/h;return[n-e+v*n,r-t+v*r,v,a-e+g*a,s-t+g*s,g,e,t,1]}function Qe(e){var t=e[0],n=e[1],r=e[2],i=e[3],o=e[4],a=e[5],s=e[6],l=e[7],c=e[8],u=t*o*c-t*a*l-n*i*c+n*a*s+r*i*l-r*o*s;return[(o*c-a*l)/u,(r*l-n*c)/u,(n*a-r*o)/u,(a*s-i*c)/u,(t*c-r*s)/u,(r*i-t*a)/u,(i*l-o*s)/u,(n*s-t*l)/u,(t*o-n*i)/u]}function et(e,t,n=3){let r=[];for(var i=0;i<n;i++){r.push([]);for(var o=0;o<n;o++){r[i].push(0);for(var a=0;a<n;a++)e[i]&&t[a]&&(r[i][o]+=e[i][a]*t[a][o])}}return r}Ze.prototype.at=function(e){for(var t=0,n=this.ya.length-1;n-t>1;){var r=n+t>>1;this.xa[r]>e?n=r:t=r}var i=this.xa[n]-this.xa[t],o=(this.xa[n]-e)/i,a=(e-this.xa[t])/i;return o*this.ya[t]+a*this.ya[n]+((o*o*o-o)*this.y2[t]+(a*a*a-a)*this.y2[n])*(i*i)/6};const tt=Object.freeze(Object.defineProperty({__proto__:null,filterAdjustments:function(e,t){const{gl:n}=e;let{brightness:r=0,contrast:i=0,saturation:o=0,exposure:a=0,temperature:s=0,gamma:l=0,clarity:c=0,vibrance:u=0,vignette:f=0,tint:d=0,sepia:p=0}=t;r/=4,i=(i+1)/2+.5,o+=1,a=(1+(a>0?3*a:1.5*a))/2+.5,l+=1,s*=2,d*=2;let h={brightness:[[1,0,0,0,r],[0,1,0,0,r],[0,0,1,0,r],[0,0,0,1,0]],contrast:[[i,0,0,0,.5*(1-i)],[0,i,0,0,.5*(1-i)],[0,0,i,0,.5*(1-i)],[0,0,0,1,0]],saturation:[[.213+.787*o,.715-.715*o,.072-.072*o,0,0],[.213-.213*o,.715+.285*o,.072-.072*o,0,0],[.213-.213*o,.715-.715*o,.072+.928*o,0,0],[0,0,0,1,0]],exposure:[[a,0,0,0,0],[0,a,0,0,0],[0,0,a,0,0],[0,0,0,1,0]],temperature:s>0?[[1+.1*s,0,0,0,0],[0,1,0,0,0],[0,0,1+.1*-s,0,0],[0,0,0,1,0]]:[[1+.15*s,0,0,0,0],[0,1+.05*s,0,0,0],[0,0,1+.15*-s,0,0],[0,0,0,1,0]],tint:[[1,0,0,0,0],[0,1+.1*d,0,0,0],[0,0,1,0,0],[0,0,0,1,0]],sepia:[[1-.607*p,.769*p,.189*p,0,0],[.349*p,1-.314*p,.168*p,0,0],[.272*p,.534*p,1-.869*p,0,0],[0,0,0,1,0]],identity:[[1,0,0,0,0],[0,1,0,0,0],[0,0,1,0,0],[0,0,0,1,0]]},v=h.identity,g=[0,0,0,0];v=et(v,h.brightness,4),g=[0,1,2,3].map(e=>g[e]+h.brightness[e][4]),v=et(v,h.contrast,4),g=[0,1,2,3].map(e=>g[e]+h.contrast[e][4]),v=et(v,h.saturation,4),v=et(v,h.exposure,4),v=et(v,h.temperature,4),v=et(v,h.tint,4),v=et(v,h.sepia,4);let m=c>=0?[0,-1*c,0,-1*c,1+4*c,-1*c,0,-1*c,0]:[-1*c,-2*c,-1*c,-2*c,1+-3*c,-2*c,-1*c,-2*c,-1*c],x=m.reduce((e,t)=>e+t,0);x=x<=0?1:x,m=[m];const b=v.flat(),y=g,w=[n.canvas.width,n.canvas.height],C=u,_=f,S=m,$=x,k=[0,0];e._.$adj=e._.$adj||new it(n,null,"#version 300 es\n        precision highp float;\n\n        in vec2 texCoord;\n        uniform sampler2D _texture;\n        out vec4 outColor;\n\n        uniform vec2 uTextureSize;\n        uniform mat4 uColorMatrix;\n        uniform vec4 uColorOffset;\n        uniform float uClarityKernel[9];\n        uniform float uClarityKernelWeight;\n        uniform float uColorGamma;\n        uniform float uVibrance;\n        uniform float uColorVignette;\n        uniform vec2 uVignettePos;\n        uniform float vibrance;\n\n        vec4 applyGamma(vec4 c, float g) {\n            c.r = pow(c.r, g);\n            c.g = pow(c.g, g);\n            c.b = pow(c.b, g);\n            return c;\n        }\n        vec4 applyVibrance(vec4 c, float v){\n          float max = max(c.r, max(c.g, c.b));\n          float avg = (c.r + c.g + c.b) / 3.0;\n          float amt = (abs(max - avg) * 2.0) * -v;\n          c.r += max != c.r ? (max - c.r) * amt : 0.00;\n          c.g += max != c.g ? (max - c.g) * amt : 0.00;\n          c.b += max != c.b ? (max - c.b) * amt : 0.00;\n          return c;\n        }\n        vec4 applyColorMatrix(vec4 c, mat4 m, vec4 o) {\n            vec4 res = (c * m) + (o * c.a);\n            res = clamp(res, 0.0, 1.0);\n            return res;\n        }\n        vec4 applyConvolutionMatrix(vec4 c, float k0, float k1, float k2, float k3, float k4, float k5, float k6, float k7, float k8, float w) {\n          vec2 pixel = vec2(1) / uTextureSize;\n          vec4 colorSum = texture(_texture, texCoord - pixel) * k0 + texture(_texture, texCoord + pixel * vec2(0.0, -1.0)) * k1 + texture(_texture, texCoord + pixel * vec2(1.0, -1.0)) * k2 + texture(_texture, texCoord + pixel * vec2(-1.0, 0.0)) * k3 + texture(_texture, texCoord) * k4 + texture(_texture, texCoord + pixel * vec2(1.0, 0.0)) * k5 + texture(_texture, texCoord + pixel * vec2(-1.0, 1.0)) * k6 + texture(_texture, texCoord + pixel * vec2(0.0, 1.0)) * k7 + texture(_texture, texCoord + pixel) * k8;\n          vec4 color = vec4(clamp((colorSum / w), 0.0, 1.0).rgb, c.a);\n          return color;\n        }\n\n        vec4 applyVignette2(vec4 c, vec2 pos, float v, vec2 upos){\n          #define inner .20\n          #define outer 1.1\n          #define curvature .65\n          vec2 curve = pow(abs(pos),vec2(1./curvature));\n          float edge = pow(length(curve),curvature);\n          float scale = 1.-abs(upos.x);\n          float vignette = 1.-v*smoothstep(inner*scale,outer*scale,edge);\n          vec4 color = vec4(c.rgb *= vignette , c.a);\n          return color;\n        }\n\n        vec4 vignette3(vec4 c, vec2 pos, float radius)\n        {\n            float ambientlight = 0.14;\n            float circle = length(pos) - radius;\n            float v = 1.0 - smoothstep(0.0, 0.4f, circle) + ambientlight;\n            return vec4(c.rgb*v,c.a);\n        }\n\n        void main() {\n          vec4 color = texture(_texture, texCoord);\n          if (uClarityKernelWeight != -1.0) { \n            color = applyConvolutionMatrix(color, uClarityKernel[0], uClarityKernel[1], uClarityKernel[2], uClarityKernel[3], uClarityKernel[4], uClarityKernel[5], uClarityKernel[6], uClarityKernel[7], uClarityKernel[8], uClarityKernelWeight); \n          } \n          color = applyGamma(color, uColorGamma);\n          color = applyVibrance(color, uVibrance);\n          color = applyColorMatrix(color, uColorMatrix, uColorOffset);\n          if (uColorVignette != 0.0) {\n            vec2 pos = texCoord.xy*2.-1. - uVignettePos;\n            //color = vignette3(color, pos, uColorVignette);\n            color = applyVignette2(color, pos, uColorVignette, uVignettePos);\n          }\n          outColor = color;\n        }\n      "),e.runFilter(e._.$adj,{uColorMatrix:b,uColorOffset:y,uColorGamma:1/l,uClarityKernel:S,uClarityKernelWeight:$,uTextureSize:w,uVibrance:C,uColorVignette:_,uVignettePos:k})},filterBlend:function(e,t,n){const{gl:r}=e;e._.$blend=e._.$blend||new it(r,null,"#version 300 es\n        precision highp float;\n\n        in vec2 texCoord;\n        uniform sampler2D _texture;\n        out vec4 outColor;\n\n        uniform sampler2D map;\n        uniform float filterStrength;\n\n        vec4 fromLinear(vec4 linearRGB) {\n            bvec3 cutoff = lessThan(linearRGB.rgb, vec3(0.0031308));\n            vec3 higher = vec3(1.055)*pow(linearRGB.rgb, vec3(1.0/2.4)) - vec3(0.055);\n            vec3 lower = linearRGB.rgb * vec3(12.92);\n            return vec4(mix(higher, lower, cutoff), linearRGB.a);\n        }\n        vec4 toLinear(vec4 sRGB) {\n            bvec3 cutoff = lessThan(sRGB.rgb, vec3(0.04045));\n            vec3 higher = pow((sRGB.rgb + vec3(0.055))/vec3(1.055), vec3(2.4));\n            vec3 lower = sRGB.rgb/vec3(12.92);\n            return vec4(mix(higher, lower, cutoff), sRGB.a);\n        }\n\n        void main(){\n          vec4 color = texture(_texture, texCoord);\n          vec4 texc = texture(map, texCoord);\n          color = toLinear(color);\n          texc = toLinear(texc);\n          color = mix(color, texc, filterStrength);\n          color = fromLinear(color);\n          outColor = color;\n        }"),e._.$blendtxt=e._.$blendtxt||new ot(r),e._.$blendtxt.loadImage(t),e._.$blendtxt.use(1),e.runFilter(e._.$blend,{filterStrength:n??1,map:{unit:1}})},filterBloom:function(e,t){const{gl:n}=e,r=[n.canvas.width,n.canvas.height];e._.$bloom=e._.$bloom||new it(n,null,"#version 300 es\n        precision highp float;\n\n        in vec2 texCoord;\n        uniform sampler2D _texture;\n        out vec4 outColor;\n\n        uniform vec2 uResolution;\n        uniform float filterStrength;\n\n\n        vec4 BlurColor (in vec2 Coord, in sampler2D Tex, in float MipBias)\n        {\n            vec2 TexelSize = MipBias/uResolution.xy;\n            vec4  Color = texture(Tex, Coord, MipBias);\n            Color += texture(Tex, Coord + vec2(TexelSize.x,0.0), MipBias);      \n            Color += texture(Tex, Coord + vec2(-TexelSize.x,0.0), MipBias);     \n            Color += texture(Tex, Coord + vec2(0.0,TexelSize.y), MipBias);      \n            Color += texture(Tex, Coord + vec2(0.0,-TexelSize.y), MipBias);     \n            Color += texture(Tex, Coord + vec2(TexelSize.x,TexelSize.y), MipBias);      \n            Color += texture(Tex, Coord + vec2(-TexelSize.x,TexelSize.y), MipBias);     \n            Color += texture(Tex, Coord + vec2(TexelSize.x,-TexelSize.y), MipBias);     \n            Color += texture(Tex, Coord + vec2(-TexelSize.x,-TexelSize.y), MipBias);    \n            return Color/9.0;\n        }\n\n        void main() {\n          float Threshold = 0.4;\n          float Intensity = filterStrength*1.0;\n          float BlurSize = 3.0 * Intensity;\n\n          vec4 color = texture(_texture, texCoord);\n          vec4 Highlight = clamp(BlurColor(texCoord.xy, _texture, BlurSize)-Threshold,0.0,1.0)*1.0/(1.0-Threshold);\n          outColor = 1.0-(1.0-color)*(1.0-Highlight*Intensity); //Screen Blend Mode\n        }\n  "),e.runFilter(e._.$bloom,{filterStrength:t,uResolution:r})},filterBlurBokeh:function(e,t){const{gl:n}=e;let{bokehstrength:r=.5,bokehlensin:i=0,bokehlensout:o=.5,centerX:a=0,centerY:s=0}=t||{};e._.$lensblur=e._.$lensblur||new it(n,null,"#version 300 es\n        //Bokeh disc. by David Hoskins.\n        //https://www.shadertoy.com/view/4d2Xzw\n        precision highp float;\n\n        in vec2 texCoord;\n        uniform sampler2D _texture;\n        out vec4 outColor;\n\n        uniform float bokehstrength;\n        uniform float bokehlensin;\n        uniform float bokehlensout;\n        uniform float centerX;\n        uniform float centerY;\n\n        #define GOLDEN_ANGLE 2.39996323\n        #define ITERATIONS 512\n        const mat2 rot = mat2(cos(GOLDEN_ANGLE), sin(GOLDEN_ANGLE), -sin(GOLDEN_ANGLE), cos(GOLDEN_ANGLE));\n        vec3 Bokeh(sampler2D tex, vec2 uv, float radius)\n        {\n          vec3 acc = vec3(0), div = acc;\n            float r = 1.;\n            vec2 vangle = vec2(0.0,radius*.01 / sqrt(float(ITERATIONS)));\n            \n          for (int j = 0; j < ITERATIONS; j++)\n            {  \n                // the approx increase in the scale of sqrt(0, 1, 2, 3...)\n                r += 1. / r;\n              vangle = rot * vangle;\n                vec3 col = texture(tex, uv + (r-1.) * vangle).xyz; /// ... Sample the image\n                //col = col * col *1.8; // ... Contrast it for better highlights - leave this out elsewhere.\n            vec3 bokeh = pow(col, vec3(4));\n            acc += col * bokeh;\n            div += bokeh;\n          }\n          return acc / div;\n        }\n\n\n        void main() {\n            vec4 color = texture(_texture, texCoord);\n            vec4 bcolor = vec4(Bokeh(_texture, texCoord, bokehstrength), 1.);\n    \n            //vignette used to control alpha\n            //to blur inside circle smoothstep(lensin, lensout, dist)\n            //to blur outside circle smoothstep(lensout, lensin, dist)\n            float dist = distance(texCoord.xy, vec2(centerX,centerY));\n            float vigfin = pow(1.-smoothstep(max(0.001,bokehlensout), bokehlensin, dist),2.);\n\n            outColor = mix( color, bcolor, vigfin);\n        }\n      "),e.runFilter(e._.$lensblur,{bokehstrength:r,bokehlensin:i,bokehlensout:o,centerX:a,centerY:s})},filterBlurGaussian:function(e,t){const{gl:n}=e;let{gaussianstrength:r=.5,gaussianlensin:i=0,gaussianlensout:o=.5,centerX:a=0,centerY:s=0}=t||{};const l=[n.canvas.width,n.canvas.height];e._.$gaussianblur=e._.$gaussianblur||new it(n,null,"#version 300 es\n        //https://www.shadertoy.com/view/XdfGDH\n        precision highp float;\n\n        in vec2 texCoord;\n        uniform sampler2D _texture;\n        out vec4 outColor;\n\n        uniform vec2 uResolution;\n        uniform float gaussianstrength;\n        uniform float gaussianlensin;\n        uniform float gaussianlensout;\n        uniform float centerX;\n        uniform float centerY;\n\n        float normpdf(in float x, in float sigma)\n        {\n          return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n        }\n\n        void main() {\n            vec4 color = texture(_texture, texCoord);\n\n            //declare stuff\n            const int mSize = 11;\n            const int kSize = (mSize-1)/2;\n            float kernel[mSize];\n            vec3 final_colour = vec3(0.0);\n            \n            //create the 1-D kernel\n            float sigma = 7.0*gaussianstrength;\n            float Z = 0.0;\n            for (int j = 0; j <= kSize; ++j)\n            {\n              kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j), sigma);\n            }\n            \n            //get the normalization factor (as the gaussian has been clamped)\n            for (int j = 0; j < mSize; ++j)\n            {\n              Z += kernel[j];\n            }\n            \n            //read out the texels\n            for (int i=-kSize; i <= kSize; ++i)\n            {\n              for (int j=-kSize; j <= kSize; ++j)\n              {\n                final_colour += kernel[kSize+j]*kernel[kSize+i]*texture(_texture, (texCoord.xy+vec2(float(i),float(j))/uResolution)).rgb;\n              }\n            }\n            \n            //vignette used to control alpha\n            //to blur inside circle smoothstep(lensin, lensout, dist)\n            //to blur outside circle smoothstep(lensout, lensin, dist)\n            float dist = distance(texCoord.xy, vec2(centerX,centerY));\n            float vigfin = pow(1.-smoothstep(max(0.001,gaussianlensout), gaussianlensin, dist),2.);\n\n            outColor = mix( color, vec4(final_colour/(Z*Z), 1.0), vigfin);\n        }\n      "),e.runFilter(e._.$gaussianblur,{gaussianstrength:r,gaussianlensin:i,gaussianlensout:o,centerX:a,centerY:s,uResolution:l})},filterCurves:function(e,t){if(t.every(e=>null===e))return;t[0]||(t[0]=[[0,0],[1,1]]);let n=t[1]||t[0],r=t[2]||t[0],i=t[3]||t[0];if(n=qe(n),r=qe(r),i=qe(i),256!==n.length||256!==r.length||256!==i.length)return console.error("curves: input unknown");t=[];for(var o=0;o<256;o++)t.splice(t.length,0,n[o],r[o],i[o],255);const{gl:a}=e;e._.$curvestexture=e._.$curvestexture||new ot(a),e._.$curvestexture.initFromBytes(256,1,t,a.RGBA),e._.$curvestexture.use(2),e._.$curves=e._.$curves||new it(a,null,"#version 300 es\n        precision highp float;\n\n        in vec2 texCoord;\n        uniform sampler2D _texture;\n        out vec4 outColor;\n\n        uniform sampler2D curvemap;\n\n        void main() {\n            vec4 color = texture(_texture, texCoord);\n            color.r = texture(curvemap, vec2(color.r)).r;\n            color.g = texture(curvemap, vec2(color.g)).g;\n            color.b = texture(curvemap, vec2(color.b)).b;\n            outColor = color;\n        }\n      "),e.runFilter(e._.$curves,{curvemap:{unit:2}})},filterHighlightsShadows:function(e,t,n){const{gl:r}=e;e._.$sg=e._.$sg||new it(r,null,"#version 300 es\n        precision highp float;\n\n        in vec2 texCoord;\n        uniform sampler2D _texture;\n        out vec4 outColor;\n\n        uniform float shadows;\n        uniform float highlights;\n\n        const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721);\n\n        void main() {\n          vec4 color = texture(_texture, texCoord);\n\n          float luminance = dot(color.rgb, luminanceWeighting);\n          float shadow = clamp((pow(luminance, 1.0/shadows) + (-0.76)*pow(luminance, 2.0/shadows)) - luminance, 0.0, 1.0);\n          float highlight = clamp((1.0 - (pow(1.0-luminance, 1.0/(2.0-highlights)) + (-0.8)*pow(1.0-luminance, 2.0/(2.0-highlights)))) - luminance, -1.0, 0.0);\n          vec3 result = vec3(0.0, 0.0, 0.0) + (luminance + shadow + highlight) * ((color.rgb - vec3(0.0, 0.0, 0.0))/luminance );\n\n          // blend toward white if highlights is more than 1\n          float contrastedLuminance = ((luminance - 0.5) * 1.5) + 0.5;\n          float whiteInterp = contrastedLuminance*contrastedLuminance*contrastedLuminance;\n          float whiteTarget = clamp(highlights, 0.0, 2.0) - 1.0;\n          result = mix(result, vec3(1.0), whiteInterp*whiteTarget);\n\n          // blend toward black if shadows is less than 1\n          float invContrastedLuminance = 1.0 - contrastedLuminance;\n          float blackInterp = invContrastedLuminance*invContrastedLuminance*invContrastedLuminance;\n          float blackTarget = 1.0 - clamp(shadows, 0.0, 1.0);\n          result = mix(result, vec3(0.0), blackInterp*blackTarget);\n\n          outColor = vec4(result, color.a);\n        }\n  "),e.runFilter(e._.$sg,{highlights:t+1,shadows:n/2+1})},filterInsta:function(e,t,n){const{gl:r}=e;n+=1;const i="\n    vec3 fromLinear(vec3 linearRGB) {\n        bvec3 cutoff = lessThan(linearRGB.rgb, vec3(0.0031308));\n        vec3 higher = vec3(1.055)*pow(linearRGB.rgb, vec3(1.0/2.4)) - vec3(0.055);\n        vec3 lower = linearRGB.rgb * vec3(12.92);\n        return vec3(mix(higher, lower, cutoff));\n    }\n    vec3 toLinear(vec3 sRGB) {\n        bvec3 cutoff = lessThan(sRGB.rgb, vec3(0.04045));\n        vec3 higher = pow((sRGB.rgb + vec3(0.055))/vec3(1.055), vec3(2.4));\n        vec3 lower = sRGB.rgb/vec3(12.92);\n        return vec3(mix(higher, lower, cutoff));\n    }";if("1"===t.type){const o=`#version 300 es\n        precision highp float;\n\n        in vec2 texCoord;\n        uniform sampler2D _texture;\n        out vec4 outColor;\n\n        uniform sampler2D map;\n        uniform float filterStrength;\n\n        ${i}\n\n        vec4 lut(vec4 color) {\n          vec3 texel = color.rgb;\n          texel = fromLinear(texel);\n          float size = 33.0;\n          float sliceSize = 1.0 / size;\n          float slicePixelSize = sliceSize / size;\n          float sliceInnerSize = slicePixelSize * (size - 1.0);\n          float xOffset = 0.5 * sliceSize + texel.x * (1.0 - sliceSize);\n          float yOffset = 0.5 * slicePixelSize + texel.y * sliceInnerSize;\n          float zOffset = texel.z * (size - 1.0);\n          float zSlice0 = floor(zOffset);\n          float zSlice1 = zSlice0 + 1.0;\n          float s0 = yOffset + (zSlice0 * sliceSize);\n          float s1 = yOffset + (zSlice1 * sliceSize);\n          vec4 slice0Color = texture(map, vec2(xOffset, s0));\n          vec4 slice1Color = texture(map, vec2(xOffset, s1));\n          texel =  mix(slice0Color, slice1Color, zOffset - zSlice0).rgb;\n          texel = toLinear(texel);\n          return vec4(texel, color.a);\n        }\n\n        void main() {\n          vec4 color = texture(_texture, texCoord);\n          outColor = color * (1.0 - filterStrength) + lut(color) * filterStrength;\n        }\n    `;e._.$insta1=e._.$insta1||new it(r,null,o),e._.$instatxt1=e._.$instatxt1||new ot(r),e._.$instatxt1.loadImage(t.map1,r.RGBA),e._.$instatxt1.use(1),e.runFilter(e._.$insta1,{filterStrength:n??1,map:{unit:1}})}else if("2"===t.type){const o=`#version 300 es\n        precision highp float;\n        precision highp int;\n        \n        in vec2 texCoord;\n        uniform sampler2D _texture;\n        out vec4 outColor;\n\n        uniform sampler2D map;\n        uniform sampler2D map2;\n        uniform float filterStrength;\n\n        ${i}\n\n        vec4 lut(vec4 color) {\n          vec3 texel = color.rgb;\n          texel = fromLinear(texel);\n          texel.r = texture(map, vec2(texel.r, 0.5)).r;\n          texel.g = texture(map, vec2(texel.g, 0.5)).g;\n          texel.b = texture(map, vec2(texel.b, 0.5)).b;\n          float luma = dot(vec3(0.2126, 0.7152, 0.0722), texel);\n          float shadowCoeff = 0.35 * max(0.0, 1.0 - luma);\n          texel = mix(texel, max(vec3(0.0), 2.0 * texel - 1.0), shadowCoeff);\n          texel = mix(texel, vec3(luma), -0.3);\n          texel.r = texture(map2, vec2(texel.r, 0.5)).r;\n          texel.g = texture(map2, vec2(texel.g, 0.5)).g;\n          texel.b = texture(map2, vec2(texel.b, 0.5)).b;\n          texel = toLinear(texel);\n          return vec4(texel, color.a);\n        }\n\n        void main() {\n          vec4 color = texture(_texture, texCoord);\n          color = color * (1.0 - filterStrength) + lut(color) * filterStrength;\n          outColor = color;\n        }\n    `;e._.$insta2=e._.$insta2||new it(r,null,o),e._.$instatxt1=e._.$instatxt1||new ot(r),e._.$instatxt2=e._.$instatxt2||new ot(r),e._.$instatxt1.loadImage(t.map1,r.RGBA),e._.$instatxt2.loadImage(t.map2,r.RGBA),e._.$instatxt1.use(1),e._.$instatxt2.use(2),e.runFilter(e._.$insta2,{filterStrength:n??1,map:{unit:1},map2:{unit:2}})}else if("3"===t.type){const o=`#version 300 es\n        precision highp float;\n        precision highp int;\n        \n        in vec2 texCoord;\n        uniform sampler2D _texture;\n        out vec4 outColor;\n\n        uniform sampler2D map;\n        uniform sampler2D mapLgg;\n        uniform float filterStrength;\n\n        ${i}\n\n        vec4 lut(vec4 color) {\n          vec3 texel = color.rgb;\n          texel = fromLinear(texel);\n          texel = min(texel * 1.1343, vec3(1.0));\n          texel.r = texture(map, vec2(texel.r, 0.5)).r;\n          texel.g = texture(map, vec2(texel.g, 0.5)).g;\n          texel.b = texture(map, vec2(texel.b, 0.5)).b;\n          vec3 shadowColor = vec3(0.956862, 0.0, 0.83529);\n          float luma = dot(vec3(0.309, 0.609, 0.082), texel);\n          vec3 shadowBlend = 2.0 * shadowColor * texel;\n          float shadowAmount = 0.6 * max(0.0, (1.0 - 4.0 * luma));\n          texel = mix(texel, shadowBlend, shadowAmount);\n          vec3 lgg;\n          lgg.r = texture(mapLgg, vec2(texel.r, 0.5)).r;\n          lgg.g = texture(mapLgg, vec2(texel.g, 0.5)).g;\n          lgg.b = texture(mapLgg, vec2(texel.b, 0.5)).b;\n          texel = mix(texel, lgg, min(1.0, 0.8 + luma));\n          texel = toLinear(texel);\n          return vec4(texel, color.a);\n        }\n\n        void main() {\n          vec4 color = texture(_texture, texCoord);\n          outColor = color * (1.0 - filterStrength) + lut(color) * filterStrength;\n        }\n    `;e._.$insta3=e._.$insta3||new it(r,null,o),e._.$instatxt1=e._.$instatxt1||new ot(r,0,0,r.RGBA,r.UNSIGNED_BYTE),e._.$instatxt1.loadImage(t.map1,r.RGBA),e._.$instatxt2=e._.$instatxt2||new ot(r,0,0,r.RGBA,r.UNSIGNED_BYTE),e._.$instatxt2.loadImage(t.map2,r.RGBA),e._.$instatxt1.use(1),e._.$instatxt2.use(2),e.runFilter(e._.$insta3,{filterStrength:n??1,map:{unit:1},mapLgg:{unit:2}})}else if("4"===t.type){const o=`#version 300 es\n        precision highp float;\n        precision highp int;\n        \n        in vec2 texCoord;\n        uniform sampler2D _texture;\n        out vec4 outColor;\n\n        uniform sampler2D map;\n        uniform sampler2D map2;\n        uniform float filterStrength;\n\n        ${i}\n\n        vec4 lut(vec4 color) {\n          vec3 texel = color.rgb;\n          texel = fromLinear(texel);\n          texel.r = texture(map, vec2(texel.r, 0.5)).r;\n          texel.g = texture(map, vec2(texel.g, 0.5)).g;\n          texel.b = texture(map, vec2(texel.b, 0.5)).b;\n          vec3 desat = vec3(dot(vec3(0.7, 0.2, 0.1), texel));\n          texel = mix(texel, desat, 0.79);\n          texel = vec3(min(1.0, 1.2 * dot(vec3(0.2, 0.7, 0.1), texel)));\n          texel.r = texture(map2, vec2(texel.r, 0.5)).r;\n          texel.g = texture(map2, vec2(texel.g, 0.5)).g;\n          texel.b = texture(map2, vec2(texel.b, 0.5)).b;\n          texel = toLinear(texel);\n          return vec4(texel, color.a);\n        }\n\n        void main() {\n          vec4 color = texture(_texture, texCoord);\n          outColor = color * (1.0 - filterStrength) + lut(color) * filterStrength;\n        }\n    `;e._.$insta4=e._.$insta4||new it(r,null,o),e._.$instatxt1=e._.$instatxt1||new ot(r,0,0,r.RGBA,r.UNSIGNED_BYTE),e._.$instatxt1.loadImage(t.map1,r.RGBA),e._.$instatxt2=e._.$instatxt2||new ot(r,0,0,r.RGBA,r.UNSIGNED_BYTE),e._.$instatxt2.loadImage(t.map2,r.RGBA),e._.$instatxt1.use(1),e._.$instatxt2.use(2),e.runFilter(e._.$insta4,{filterStrength:n??1,map:{unit:1},map2:{unit:2}})}else if("MTX"===t.type){const i="#version 300 es\n        precision highp float;\n        precision highp int;\n        \n        in vec2 texCoord;\n        uniform sampler2D _texture;\n        out vec4 outColor;\n\n        uniform float filterStrength;\n        uniform mat4 uColorMatrix;\n        uniform vec4 uColorOffset;\n\n        vec4 applyColorMatrix(vec4 c, mat4 m, vec4 o) {\n            vec4 res = (c * m) + (o * c.a);\n            res = clamp(res, 0.0, 1.0);\n            return res;\n        }\n\n        void main() {\n          vec4 color = texture(_texture, texCoord);\n          color = applyColorMatrix(color, uColorMatrix, uColorOffset);\n          outColor = color;\n        }\n    ";let o={identity:[[1,0,0,0,0],[0,1,0,0,0],[0,0,1,0,0],[0,0,0,1,0]],polaroid:[[1+.438*n,-.062*n,-.062*n,0,0],[-.122*n,1+.378*n,-.122*n,0,0],[-.016*n,-.016*n,1+.483*n,0,0],[0,0,0,1,0]],kodachrome:[[(1+.1285582396593525*n)*((n/2+1)/2+.5),-.3967382283601348*n,-.03992559172921793*n,0,.06372958762196503*n],[-.16404339962244616*n,(1+.0835251566291304*n)*((n/2+1)/2+.5),-.05498805115633132*n,0,.024732407896706204*n],[-.16786010706155763*n,-.5603416277695248*n,(1+.6014850761964943*n)*((n/2+1)/2+.5),0,.03562982807460946*n],[0,0,0,1,0]],browni:[[(1-.4002976502*n)*((n/1.5+1)/2+.5),.34553243048391263*n,-.2708298674538042*n,0,.09486385711201746*n],[-.037703249837783157*n,(1-.1390422412*n)*((n/1.5+1)/2+.5),.15059552388459913*n,0,-.07393682996638255*n],[.24113635128153335*n,-.07441037908422492*n,(1-.5502781794*n)*((n/1.5+1)/2+.5),0,-.015124150555182566*n],[0,0,0,1,0]],vintage:[[(1-.3720654364*n)*((n/1.5+1)/2+.5),.3202183420819367*n,-.03965408211312453*n,0,.009651285835294123*n],[.02578397704808868*n,(1-.3558811356*n)*((n/1.5+1)/2+.5),.03259127616149294*n,0,.007462829176470591*n],[.0466055556782719*n,-.0851232987247891*n,(1-.4758351981*n)*((n/1.5+1)/2+.5),0,.005159190588235296*n],[0,0,0,1,0]]},a=o.identity,s=[0,0,0,0];n&&(a=function(e,t,n=3){let r=[];for(var i=0;i<n;i++){r.push([]);for(var o=0;o<n;o++){r[i].push(0);for(var a=0;a<n;a++)e[i]&&t[a]&&(r[i][o]+=e[i][a]*t[a][o])}}return r}(a,o[t.mtx],4)),n&&(s=[0,1,2,3].map(e=>s[e]+o[t.mtx][e][4])),e._.$insta5=e._.$insta5||new it(r,null,i);const l=a.flat(),c=s;e.runFilter(e._.$insta5,{uColorMatrix:l,uColorOffset:c})}},filterMatrix:function(e,t){const{gl:n,img:r}=e;t=t||{translateX:0,translateY:0,angle:0,scale:0,flipv:0,fliph:0};let{translateX:i,translateY:o,angle:a,scale:s,flipv:l,fliph:c}=t;s+=1;let u=[s,s];const f=[Math.round(n.canvas.width*i*100)/100,Math.round(n.canvas.height*o*100)/100];if(n.canvas.width===e.height){const e=r.width/r.height;u[0]*=e,u[1]/=e}const d=Ye.projection(n.canvas.width,n.canvas.height),p=Ye.translation(f[0],f[1]),h=Ye.rotation(-a*Math.PI/180),v=Ye.scaling(u[0]*(-c||1),u[1]*(-l||1));let g=[1,0,0,0,1,0,0,0,1];g=Ye.multiply(g,d),g=Ye.multiply(g,p),g=Ye.multiply(g,Ye.translation(n.canvas.width/2,n.canvas.height/2)),g=Ye.multiply(g,h),g=Ye.multiply(g,v),g=Ye.multiply(g,Ye.translation(-n.canvas.width/2,-n.canvas.height/2)),g=Ye.multiply(g,Ye.scaling(n.canvas.width,n.canvas.height)),e._.$matrix=e._.$matrix||new it(n,"#version 300 es\n        in vec2 vertex;\n        uniform mat3 matrix;\n        out vec2 texCoord;\n        void main() {\n          texCoord = vertex;\n          gl_Position = vec4((matrix * vec3(vertex, 1)).xy, 0, 1);\n        }\n      ","#version 300 es\n        precision highp float;\n        in vec2 texCoord;\n        uniform sampler2D _texture;\n        out vec4 outColor;   \n        void main() {\n          outColor = texture(_texture, vec2(texCoord.x, texCoord.y));\n        }\n      "),e.runFilter(e._.$matrix,{matrix:g})},filterNoise:function(e,t){const{gl:n}=e,r=[n.canvas.width,n.canvas.height];e._.$noise=e._.$noise||new it(n,null,"#version 300 es\n        precision highp float;\n\n        in vec2 texCoord;\n        uniform sampler2D _texture;\n        out vec4 outColor;\n\n        uniform vec2 uResolution;\n        uniform float filterStrength;\n\n        #define SIGMA 10.0\n        #define BSIGMA 0.1\n        #define MSIZE 15\n\n        float normpdf(in float x, in float sigma)\n        {\n          return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n        }\n\n        float normpdf3(in vec3 v, in float sigma)\n        {\n          return 0.39894*exp(-0.5*dot(v,v)/(sigma*sigma))/sigma;\n        }\n\n        vec4 applyFilter(vec4 c, sampler2D _texture, vec2 texCoord) {\n\n          const int kSize = (MSIZE-1)/2;\n          float kernel[MSIZE] = float[MSIZE](0.031225216, 0.033322271, 0.035206333, 0.036826804, 0.038138565, 0.039104044, 0.039695028, 0.039894000, 0.039695028, 0.039104044, 0.038138565, 0.036826804, 0.035206333, 0.033322271, 0.031225216);\n          vec3 final_colour = vec3(0.0);\n          \n          vec3 cc;\n          float factor;\n          float Z = 0.0;\n          float bZ = 1.0/normpdf(0.0, BSIGMA);\n          for (int i=-kSize; i <= kSize; ++i)\n          {\n            for (int j=-kSize; j <= kSize; ++j)\n            {\n              cc = texture(_texture, (texCoord.xy+vec2(float(i),float(j))/uResolution)).rgb;\n              factor = normpdf3(cc-c.rgb, BSIGMA)*bZ*kernel[kSize+j]*kernel[kSize+i];\n              Z += factor;\n              final_colour += factor*cc;\n            }\n          }\n          \n          return vec4(final_colour/Z, 1.0);\n        }\n\n        void main() {\n          vec4 color = texture(_texture, texCoord);\n          color = color * (1.0 - filterStrength) + applyFilter(color, _texture, texCoord) * filterStrength;\n          outColor = color;\n        }\n  "),e.runFilter(e._.$noise,{filterStrength:t,uResolution:r})},filterPerspective:function(e,t,n,r,i){t=t.flat(),n=n.flat();var o=Je.apply(null,n),a=Je.apply(null,t),s=function(e,t){return[e[0]*t[0]+e[1]*t[3]+e[2]*t[6],e[0]*t[1]+e[1]*t[4]+e[2]*t[7],e[0]*t[2]+e[1]*t[5]+e[2]*t[8],e[3]*t[0]+e[4]*t[3]+e[5]*t[6],e[3]*t[1]+e[4]*t[4]+e[5]*t[7],e[3]*t[2]+e[4]*t[5]+e[5]*t[8],e[6]*t[0]+e[7]*t[3]+e[8]*t[6],e[6]*t[1]+e[7]*t[4]+e[8]*t[7],e[6]*t[2]+e[7]*t[5]+e[8]*t[8]]}(Qe(o),a);return function(e,t,n,r){const{gl:i,img:o}=e;if(e._.$warp=e._.$warp||new it(i,null,"#version 300 es\n            precision highp float;\n\n            in vec2 texCoord;\n            uniform sampler2D _texture;\n            uniform vec2 uResolution;\n            uniform mat3 matrix;\n            uniform bool useTextureSpace;\n            out vec4 outColor;\n\n            void main() {\n                vec2 coord = texCoord * uResolution;\n                if (useTextureSpace) coord = coord / uResolution * 2.0 - 1.0;\n                vec3 warp = matrix * vec3(coord, 1.0);\n                coord = warp.xy / warp.z;\n                if (useTextureSpace) coord = (coord * 0.5 + 0.5) * uResolution;\n                vec4 color = texture(_texture, coord / uResolution);\n                vec2 clampedCoord = clamp(coord, vec2(0.0), uResolution);\n                if (coord != clampedCoord) {\n                    //color.a *= max(0.0, 1.0 - length(coord - clampedCoord));\n                    color.a = 0.;\n                }\n                outColor = color;\n            }\n          "),4==(t=Array.prototype.concat.apply([],t)).length)t=[t[0],t[1],0,t[2],t[3],0,0,0,1];else if(9!=t.length)throw"can only warp with 2x2 or 3x3 matrix";const a=[i.canvas.width,i.canvas.height];e.runFilter(e._.$warp,{matrix:n?Qe(t):t,uResolution:a,useTextureSpace:0|r})}(e,s,r,i)}},Symbol.toStringTag,{value:"Module"}));function nt(e,t,n){let r=e.getContext("webgl2",{antialias:!1,premultipliedAlpha:!0});if(!r)return console.error("webgl2 not supported!");"display-p3"===n?(r.drawingBufferColorSpace="display-p3",r.unpackColorSpace="display-p3"):(r.drawingBufferColorSpace="srgb",r.unpackColorSpace="srgb");const i={width:0,height:0,gl:r,img:t,destroy:function(){l?.length&&l.forEach(e=>e.destroy()),h&&h.destroy(),o.destroy(),delete i.img_cropped},loadImage:function(){c=h||o,d(a,null)},paintCanvas:function(){c&&c.use(),r.bindFramebuffer(r.FRAMEBUFFER,null),s.drawRect()},crop:function({left:e,top:t,width:n,height:o}){const s=new Uint8Array(n*o*4);d(a,{}),r.readPixels(e,t,n,o,r.RGBA,r.UNSIGNED_BYTE,s);const l=r.unpackColorSpace,c=new ImageData(new Uint8ClampedArray(s.buffer),n,o,{colorSpace:l});h=new ot(r),h.loadImage(c),r.canvas.width=i.width=v.width=n,r.canvas.height=i.height=v.height=o,f(),i.img_cropped=at(c,l)},resetCrop:function(){h&&(h.destroy(),h=null,v.width=v.height=0,r.canvas.width=i.width=p.width||t.naturalWidth,r.canvas.height=i.height=p.height||t.naturalHeight,delete i.img_cropped,f())},resize:function(e,t){r.canvas.width=i.width=p.width=e,r.canvas.height=i.height=p.height=t,f()},resetResize:function(){p.width&&(p.width=p.height=0,r.canvas.width=i.width=v.width||t.naturalWidth,r.canvas.height=i.height=v.height||t.naturalHeight,f())},captureImage:function(e,t){d(a,{});const{width:n,height:i}=r.canvas,o=new Uint8Array(n*i*4);r.readPixels(0,0,n,i,r.RGBA,r.UNSIGNED_BYTE,o);const s=r.unpackColorSpace;return at(new ImageData(new Uint8ClampedArray(o.buffer),n,i,{colorSpace:s}),s,e,t)},readPixels:function(){d(a,{});const{width:e,height:t}=r.canvas,n=new Uint8Array(e*t*4);return r.readPixels(0,0,e,t,r.RGBA,r.UNSIGNED_BYTE,n),n},runFilter:d,setupFiltersTextures:f,_:{}};r.canvas.width=i.width=t.naturalWidth,r.canvas.height=i.height=t.naturalHeight;const o=new ot(r);o.loadImage(t);const a=new it(r),s=new it(r,null,rt);let l,c,u=0;function f(){l?.length&&l.forEach(e=>e.destroy()),l=[];for(var e=0;e<2;++e){const e=new ot(r,r.canvas.width,r.canvas.height);l.push(e)}}function d(e,t){t&&e.uniforms(t),c&&c.use(),l[u%2].drawTo(),e.drawRect(),c=l[u%2],u++}f();let p={width:0,height:0};let h,v={width:0,height:0};return Object.keys(tt).forEach(e=>i[e]=function(e){return function(...t){e(i,...t)}}(tt[e])),i}const rt="#version 300 es\n        precision highp float;\n        in vec2 texCoord;\n        uniform sampler2D _texture;\n        out vec4 outColor;\n\n        vec4 fromLinear(vec4 linearRGB) {\n            bvec3 cutoff = lessThan(linearRGB.rgb, vec3(0.0031308));\n            vec3 higher = vec3(1.055)*pow(linearRGB.rgb, vec3(1.0/2.4)) - vec3(0.055);\n            vec3 lower = linearRGB.rgb * vec3(12.92);\n            return vec4(mix(higher, lower, cutoff), linearRGB.a);\n        }\n\n        void main() {\n            vec4 color = texture(_texture, vec2(texCoord.x, 1.0 - texCoord.y));\n            //outColor = color;\n            outColor = fromLinear(color);\n        }";function it(e,t,n){const r=e.createProgram();let i;function o(e,t,n){var r=e.createShader(t);if(e.shaderSource(r,n),e.compileShader(r),!e.getShaderParameter(r,e.COMPILE_STATUS))throw"compile error: "+e.getShaderInfoLog(r);return r}return e.attachShader(r,o(e,e.VERTEX_SHADER,t||"#version 300 es\n        in vec2 vertex;\n        out vec2 texCoord;\n\n        void main() {\n          texCoord = vertex;\n          gl_Position = vec4(vertex * 2.0 - 1.0, 0.0, 1.0);\n        }\n      ")),e.attachShader(r,o(e,e.FRAGMENT_SHADER,n||"#version 300 es\n        precision highp float;\n\n        in vec2 texCoord;\n        uniform sampler2D _texture;\n        out vec4 outColor;   \n\n        void main() {\n          outColor = texture(_texture, texCoord);\n        }\n      ")),e.linkProgram(r),{drawRect:function(t=!0,n,o,a,s){const l=e.getParameter(e.VIEWPORT);n=void 0!==n?(n-l[0])/l[2]:0,o=void 0!==o?(o-l[1])/l[3]:0,a=void 0!==a?(a-l[0])/l[2]:1,s=void 0!==s?(s-l[1])/l[3]:1,e.useProgram(r),e.vertexBuffer=e.vertexBuffer||e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,e.vertexBuffer),e.bufferData(e.ARRAY_BUFFER,new Float32Array([n,o,n,s,a,o,a,s]),e.STATIC_DRAW),i||(i=e.getAttribLocation(r,"vertex"),e.enableVertexAttribArray(i)),e.vertexAttribPointer(i,2,e.FLOAT,!1,0,0),t&&(e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT|e.GL_DEPTH_BUFFER_BIT)),e.drawArrays(e.TRIANGLE_STRIP,0,4)},uniforms:function(t={}){e.useProgram(r);for(let n in t){const i=e.getUniformLocation(r,n);if(null===i)continue;let o=t[n];if(Array.isArray(o))switch(o.length){case 1:Array.isArray(o[0])&&(o=o[0]),e.uniform1fv(i,new Float32Array(o));break;case 2:e.uniform2fv(i,new Float32Array(o));break;case 3:e.uniform3fv(i,new Float32Array(o));break;case 4:e.uniform4fv(i,new Float32Array(o));break;case 9:e.uniformMatrix3fv(i,!1,new Float32Array(o));break;case 16:e.uniformMatrix4fv(i,!1,new Float32Array(o));break;default:throw"dont't know how to load uniform \""+n+'" of length '+o.length}else if(o?.unit)e.uniform1i(i,o.unit);else{if("number"!=typeof o)throw'attempted to set uniform "'+n+'" to invalid value '+(o||"undefined").toString();e.uniform1f(i,o)}}}}}function ot(e,t,n){let r=t,i=n,o=e.createTexture();e.bindTexture(e.TEXTURE_2D,o),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE);const a=e.SRGB8_ALPHA8;return t&&n&&e.texImage2D(e.TEXTURE_2D,0,a,t,n,0,e.RGBA,e.UNSIGNED_BYTE,null),{use:function(t=0){if(!o)return console.error("texture has been destroyed");e.activeTexture(e.TEXTURE0+t),e.bindTexture(e.TEXTURE_2D,o)},destroy:function(){e.deleteTexture(o),o=null},drawTo:function(){if(!o)return console.error("texture has been destroyed");if(e.framebuffer=e.framebuffer||e.createFramebuffer(),e.bindFramebuffer(e.FRAMEBUFFER,e.framebuffer),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,o,0),e.checkFramebufferStatus(e.FRAMEBUFFER)!==e.FRAMEBUFFER_COMPLETE)throw new Error("incomplete framebuffer");e.viewport(0,0,r,i)},loadImage:function(t,n){if(!o)return console.error("texture has been destroyed");r=t.naturalWidth,i=t.naturalHeight,e.bindTexture(e.TEXTURE_2D,o);let a=n||e.SRGB8_ALPHA8;e.texImage2D(e.TEXTURE_2D,0,a,e.RGBA,e.UNSIGNED_BYTE,t)},initFromBytes:function(t,n,a,s){r=t,i=n,e.bindTexture(e.TEXTURE_2D,o);let l=s||e.SRGB8_ALPHA8;e.texImage2D(e.TEXTURE_2D,0,l,t,n,0,e.RGBA,e.UNSIGNED_BYTE,new Uint8Array(a))}}}function at(e,t,n,r){const i=document.createElement("canvas");var o=i.getContext("2d",{colorSpace:t});i.width=e.width,i.height=e.height,o.putImageData(e,0,0);var a=new Image;return a.src=i.toDataURL(n,r),a}function st({el:e,onStart:t,onMove:n,onEnd:r,onZoom:i,onPinch:o,disableleave:a=!1}){const s=[];let l,c,u=0,f=!0;const d=e=>{2===e.touches.length&&e.preventDefault()},p=n=>{(n=>{s.push(n),t&&t({el:e,ev:n}),l=n.clientX,c=n.clientY,f=!0})(n)},h=t=>(t=>{if(!s.length)return;const r=s.findIndex(e=>e.pointerId===t.pointerId);if(s[r]=t,1===s.length)n&&n({el:e,ev:t,x:t.clientX-l,y:t.clientY-c}),l=t.clientX,c=t.clientY;else if(2===s.length){const n=Math.abs(s[0].x-s[1].x);if(u>0){let r=n-u;f&&(f=!1,r*=-1),t.preventDefault(),o&&o({el:e,ev0:s[0],ev1:s[1],diff:r})}u=n}})(t),v=t=>{(t=>{if(!s.length)return;const n=s.findIndex(e=>e.pointerId===t.pointerId);s.splice(n,1),r&&r({el:e,ev:t})})(t)},g=t=>i&&i({el:e,ev:t,zoom:t.deltaY/100});return e.addEventListener("pointerdown",p),e.addEventListener("pointermove",h),e.addEventListener("pointerup",v),a||(e.addEventListener("pointercancel",v),e.addEventListener("pointerout",v)),e.addEventListener("pointerleave",v),e.addEventListener("touchstart",d),i&&e.addEventListener("wheel",g,{passive:!1}),()=>{e.removeEventListener("pointerdown",p),e.removeEventListener("pointermove",h),e.removeEventListener("pointerup",v),a||(e.removeEventListener("pointercancel",v),e.removeEventListener("pointerout",v)),e.removeEventListener("pointerleave",v),e.removeEventListener("touchstart",d),i&&e.removeEventListener("wheel",g)}}function lt(e,t,n,r,i,o){e.style.transformOrigin||(e.style.transformOrigin="0 0");let a=e.style.transform.match(/translate\((.*?)\)/)?.[1].split(",").map(e=>parseFloat(e))||[0,0],s=e.style.transform.match(/scale\((.*?)\)/)?.[1].split(",").map(e=>parseFloat(e))[0]||1;var l={x:0,y:0},c={x:0,y:0};c.x=t.x-e.parentElement.offsetLeft,c.y=t.y-e.parentElement.offsetTop,(n=Math.max(-1,Math.min(1,n/10)))&&(l.x=(c.x-a[0])/s,l.y=(c.y-a[1])/s,s+=n*r*s,s=Math.max(i,Math.min(o,s)),a[0]=-l.x*s+c.x,a[1]=-l.y*s+c.y,e.style.transform="translate("+a[0]+"px,"+a[1]+"px) scale("+s+","+s+")")}function ct(e,t){const n=st({el:t,onMove:n=>{const r=document.elementFromPoint(n.ev.pageX,n.ev.pageY);if(r===e||r===t)return;const i=n.el.style.transform.match(/translate\((.*?)\)/)?.[1].split(",").map(e=>parseFloat(e))||[0,0],o=n.el.parentElement.style.transform.match(/scale\((.*?)\)/)?.[1].split(",").map(e=>parseFloat(e))[0]||1;i[0]+=n.x/o,i[1]+=n.y/o,n.el.style.transform=`translate(${i[0]}px,${i[1]}px)`}}),r=st({el:e,onZoom:n=>{const r=n.ev;r.preventDefault();const i={x:r.pageX,y:r.pageY},o=document.elementFromPoint(i.x,i.y);if(o!==e&&o!==t){var a=r.wheelDelta||r.detail;lt(n.el,i,a,.06,.9,8)}},onPinch:n=>{const r=n.ev0,i=n.ev1,o={x:(r.pageX+i.pageX)/2,y:(r.pageY+i.pageY)/2},a=document.elementFromPoint(o.x,o.y);if(a!==e&&a!==t){var s=n.diff;lt(n.el,o,s,.1,.9,8)}}});return()=>{n(),r()}}const ut=new Map;function ft(e,t,n=100){if(ut.has(e));else{const r=setTimeout(()=>{t(),ut.delete(e)},n);ut.set(e,r)}}async function dt(e,t=null){try{if(!e)return;const n=new FileReader;await new Promise(e=>n.onload=e,n.readAsArrayBuffer(e));const{name:r,size:i,type:o,lastModified:a}=e,s=new Blob([n.result],{type:o}),l=new Image;l.src=URL.createObjectURL(s),await l.decode(),t&&t(n.result,{name:r,size:i,type:o,lastModified:a},l)}catch(e){console.error(e),await A("Unknown format")}}function pt(e){var t=-1;do{e/=1024,t++}while(e>1024);return Math.max(e,.1).toFixed(1)+[" kB"," MB"," GB"," TB","PB","EB","ZB","YB"][t]}function ht(e="auto",t=!1){R("thememode")||R("thememode",f(e)),e&&root.classList.add(e);const n={auto:"✻",dark:"☾",light:"✺"};return i`<div>
      <a style="rotate: -90deg;" :title="${()=>R("thememode").value}" @click="${()=>function(e){const t=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",n="dark"===t?"light":"dark",r=R("thememode").value;"auto"===r?(root.classList.add(n),root.classList.remove(t),R("thememode").value=n):r===n?(root.classList.add(t),root.classList.remove(n),R("thememode").value=t):e||r!==t?e&&r===t&&(root.classList.add(n),root.classList.remove(r),R("thememode").value=n):(root.classList.remove(n),root.classList.remove(t),R("thememode").value="auto")}(t)}">
        ${()=>n[R("thememode").value]}
      </a>
  </div>`}var vt=/iPhone/i,gt=/iPod/i,mt=/iPad/i,xt=/\biOS-universal(?:.+)Mac\b/i,bt=/\bAndroid(?:.+)Mobile\b/i,yt=/Android/i,wt=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,Ct=/Silk/i,_t=/Windows Phone/i,St=/\bWindows(?:.+)ARM\b/i,$t=/BlackBerry/i,kt=/BB10/i,Et=/Opera Mini/i,Mt=/\b(CriOS|Chrome)(?:.+)Mobile/i,Lt=/Mobile(?:.+)Firefox\b/i,Tt=function(e){return void 0!==e&&"MacIntel"===e.platform&&"number"==typeof e.maxTouchPoints&&e.maxTouchPoints>1&&"undefined"==typeof MSStream};function At(e){var t={userAgent:"",platform:"",maxTouchPoints:0};e||"undefined"==typeof navigator?"string"==typeof e?t.userAgent=e:e&&e.userAgent&&(t={userAgent:e.userAgent,platform:e.platform,maxTouchPoints:e.maxTouchPoints||0}):t={userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints||0};var n=t.userAgent,r=n.split("[FBAN");void 0!==r[1]&&(n=r[0]),void 0!==(r=n.split("Twitter"))[1]&&(n=r[0]);var i=function(e){return function(t){return t.test(e)}}(n),o={apple:{phone:i(vt)&&!i(_t),ipod:i(gt),tablet:!i(vt)&&(i(mt)||Tt(t))&&!i(_t),universal:i(xt),device:(i(vt)||i(gt)||i(mt)||i(xt)||Tt(t))&&!i(_t)},amazon:{phone:i(wt),tablet:!i(wt)&&i(Ct),device:i(wt)||i(Ct)},android:{phone:!i(_t)&&i(wt)||!i(_t)&&i(bt),tablet:!i(_t)&&!i(wt)&&!i(bt)&&(i(Ct)||i(yt)),device:!i(_t)&&(i(wt)||i(Ct)||i(bt)||i(yt))||i(/\bokhttp\b/i)},windows:{phone:i(_t),tablet:i(St),device:i(_t)||i(St)},other:{blackberry:i($t),blackberry10:i(kt),opera:i(Et),firefox:i(Lt),chrome:i(Mt),device:i($t)||i(kt)||i(Et)||i(Lt)||i(Mt)},any:!1,phone:!1,tablet:!1};return o.any=o.apple.device||o.android.device||o.windows.device||o.other.device,o.phone=o.apple.phone||o.android.phone||o.windows.phone,o.tablet=o.apple.tablet||o.android.tablet||o.windows.tablet,o}const Bt='(function() {\n  "use strict";\n  let canvas, ctx, drawing;\n  self.onmessage = async (event) => {\n    if (event.data.init && !canvas) {\n      const { width, height } = event.data;\n      canvas = new OffscreenCanvas(width, height);\n      ctx = canvas.getContext("2d");\n      drawing = false;\n    } else if (event.data.pixels) {\n      if (drawing) return;\n      drawing = true;\n      const data = event.data.pixels;\n      DrawHistogram(data, ctx);\n      createImageBitmap(canvas).then((t) => {\n        postMessage({ bitmap: t });\n        drawing = false;\n      });\n    }\n  };\n  const histogram = [\n    new Uint32Array(256),\n    //RED\n    new Uint32Array(256),\n    //GREEN\n    new Uint32Array(256)\n    //BLUE\n  ];\n  function DrawHistogram(data, ctx2) {\n    function Draw(color, colorarray, width2, height2, max2) {\n      ctx2.beginPath();\n      ctx2.moveTo(0, height2);\n      let x = 0;\n      for (let c = 0; c < 256; c++) {\n        const h = Math.round(colorarray[c] * height2 / max2);\n        x = Math.round(c * width2 / 255);\n        ctx2.lineTo(x, height2 - h);\n      }\n      ctx2.lineTo(x, height2);\n      ctx2.fillStyle = color;\n      ctx2.fill();\n      ctx2.closePath();\n    }\n    histogram[0].fill(0);\n    histogram[1].fill(0);\n    histogram[2].fill(0);\n    const max = [0, 0, 0];\n    for (let i = 0; i < data.length; ++i) {\n      const pixel = data[i], col = i % 4;\n      if (col < 3 && pixel > 2 && pixel < 253) {\n        ++histogram[col][pixel];\n        if (histogram[col][pixel] > max[col]) ++max[col];\n      }\n    }\n    const { width, height } = ctx2.canvas;\n    ctx2.clearRect(0, 0, width, height);\n    ctx2.globalCompositeOperation = "lighter";\n    ctx2.globalAlpha = 1;\n    Draw("#c13119", histogram[0], width, height, max[0]);\n    Draw("#0c9427", histogram[1], width, height, max[1]);\n    Draw("#1e73be", histogram[2], width, height, max[2]);\n  }\n})();\n',It="undefined"!=typeof self&&self.Blob&&new Blob([Bt],{type:"text/javascript;charset=utf-8"});function Rt(e){let t;try{if(t=It&&(self.URL||self.webkitURL).createObjectURL(It),!t)throw"";const n=new Worker(t,{name:e?.name});return n.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),n}catch(t){return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(Bt),{name:e?.name})}finally{t&&(self.URL||self.webkitURL).revokeObjectURL(t)}}function Pt(e,t){let n,r,o,a;b(()=>{!async function(){try{r=new OffscreenCanvas(10,10),r.width=350,o=r.getContext("2d",{colorSpace:e,willReadFrequently:!0}),a=document.getElementById("histogram").getContext("2d"),s=new Rt,s.onmessage=async e=>{e.data.bitmap?(a.clearRect(0,0,a.canvas.width,a.canvas.height),a.drawImage(e.data.bitmap,0,0),l=!1):console.log(e.data)},s.onerror=e=>{throw console.error(`Worker error: ${e.message}`),e},s.postMessage({init:!0,width:a.canvas.width,height:a.canvas.height})}catch(e){console.error(e)}}(),t&&t(c),n&&n(),n=st({el:histo,onMove:({ev:e,x:t,y:n,el:r})=>{e.stopPropagation();const i=r.style.transform.match(/translate\((.*?)\)/)?.[1].split(",").map(e=>parseFloat(e))||[0,0];i[0]+=t/1,i[1]+=n/1,r.style.transform=`translate(${i[0]}px,${i[1]}px)`}})}),w(()=>{s.terminate(),n()});let s,l=!1;async function c(){if(s&&!l){l=!0,r.height=r.width/(canvas.width/canvas.height),o.drawImage(canvas,0,0,canvas.width,canvas.height,0,0,r.width,r.height);const e=o?.getImageData(0,0,o.canvas.width,o.canvas.height).data;s.postMessage({pixels:e})}}return i`
      <div id="histo" style="position:absolute;left:10px;width:260px;height:100px;background-color:grey;padding:5px;cursor:pointer;">
        <div style="position:absolute;color:grey;right:40px;font-size:80%;">${e}</div>
        <canvas id="histogram" width="256" height="150" style="width:100%;height:100%;background-color: #121212;"></canvas>
      </div>
  `}function Ut(e,t,n,r,o){b(()=>{!function(i){i||(r=.5);splitview.src=e.src,splitview.width=e.width,splitview.height=e.height,splitview_container.style.width=t,splitview_container.style.height=n,splitview_container.style.aspectRatio="auto "+e.width+"/"+e.height,splitview.style.clipPath=`inset(0px ${100*(1-r)}% 0px 0px)`,splitview_bar.style.left=`calc(${100*r}% - 5px)`}(r),splitview_container.addEventListener("pointerdown",l)}),w(()=>{splitview_container.removeEventListener("pointerdown",l)});let a,s=!1;function l(e){s=!0,splitview_container.setPointerCapture(e.pointerId),splitview_container.addEventListener("pointermove",u),splitview_container.addEventListener("pointerup",c),a=e.clientX}function c(e){s=!1,splitview_container.releasePointerCapture(e.pointerId),splitview_container.removeEventListener("pointermove",u),splitview_container.removeEventListener("pointerup",c),o&&o(r)}function u(e){if(s){e.preventDefault(),e.stopPropagation();const t=1/splitview_container.clientWidth,n=zoomable.style.transform.match(/scale\((.*?)\)/)?.[1].split(",").map(e=>parseFloat(e))[0]||1;r+=(e.clientX-a)*t/n,a=e.clientX,r=Math.max(.1,Math.min(.9,r)),splitview.style.clipPath=`inset(0px ${100*(1-r)}% 0px 0px)`,splitview_bar.style.left=`calc(${100*r}% - 5px)`}}return i`
    <div id="splitview_container">
      <img id="splitview"></img>
      <div id="splitview_bar"></div>
    </div>
  `}function Ft(e,t,n,r){return i`
        <button id="clickdrop_btn" 
            @click="${async function(){try{const e=await async function(e){let t=document.createElement("input");try{t.setAttribute("hidden",""),t.type="file",t.value=null,e&&(t.accept=e),document.body.appendChild(t);const n=await new Promise(e=>{t.onchange=e,t.oncancel=e,t.click()});if(t.remove(),"cancel"===n.type)return;return n.target.files[0]||await A("Unsupported file format!")}catch(e){await A("Error opening file"),console.error(e)}}(t);if(!e)return;n(e)}catch(e){console.error(e)}}}"             
            @drop="${function(e){let r;if(e.preventDefault(),e.target.style.borderColor="",e.dataTransfer.items){const n=e.dataTransfer.items[0];if(!n.type.match("^"+t.split(",").map(e=>"^"+e).join("|")))return A("unknown format");r=n.getAsFile()}else r=e.dataTransfer.files[0];n(r)}}"
            @dragover="${function(e){e.preventDefault();const t=e.target;t.style.borderColor||(t.style.borderColor="darkorange")}}"
            @dragleave="${function(e){e.preventDefault();const t=e.target;t.style.borderColor&&(t.style.borderColor="")}}"
            style="${r||""}"
        >
          ${e}
        </button>

  `}async function Dt(e,t,n,r){const o=e.value,a=o.file.name;if(r)try{const e=/png|webp|gif/i.test(o?.file?.type||"")||/\.(png|webp|gif)$/i.test(a)?"png":"jpeg",t=n.captureImage("image/"+e,"jpeg"===e?.92:void 0);return r(a,t?.src||null,e)}catch(e){return console.error("mini-img-editor export failed:",e),r(a,null,null)}const s=f(a.split(".")[0]),l=f("jpeg"),c=f("0.9");function u(e){l.value=e.target.value}if(await async function(e,t){return await new Promise((n,r)=>{const i=document.body.querySelector("div"),o=document.createElement("div");function a(e){e.parentElement.remove(),n(!0)}function s(e){e.parentElement.remove(),n(!1)}i.appendChild(o),L(o,()=>T({content:e,buttons:[{label:"Cancel",onClick:s},{label:"OK",onClick:a,focus:!0}],onCancel:s,type:"confirm",width:t}))})}(()=>i`
          <div style="margin:10px 0">
                 <div style="height:38px;">${r?"Save ":"Download "}image</div>

                  <div style="display:flex;flex-direction:column;font-size:14px;">
                    <div>
                      <input style="width:225px;font-size:14px;" type="text" :value="${()=>s.value}" @change="${e=>s.value=e.target.value}" disabled="${!!r}">
                      <select style="width:60px;height:29px;font-size:14px;" @change="${u}">
                        <option value='jpeg' selected>jpeg</option>
                        <option value='png'>png</option>
                      </select>
                    </div>
                   <div style="height:60px;display:flex;justify-content: space-between;align-items: center;">
                      ${()=>"jpeg"===l.value&&i`
                        <div style="display:flex;align-items: center;"> 
                          <label style="color:gray;margin-right:10px;">Quality</label>
                          <input type="range" min="0.1" max="1.0" step="0.1" :value="${()=>c.value}" @input="${e=>c.value=e.target.value}">
                          <span style="width:30px;text-align:right;">${()=>c.value.padEnd(3,".0")}</span>
                        </div>
                      `}
                    </div>
                  </div>
          </div>`)){const e=t.extract();let i=n.captureImage("image/"+l.value,"jpeg"===l.value&&parseFloat(c.value)).src;const u=He(await async function(e){return e.split(",")[0].match(/:(.*?);/)[1],fetch(e).then(function(e){return e.arrayBuffer()})}(i));if(e&&(u.replace(e),o?.tiff?.Orientation&&u.patch({area:"tiff",field:"Orientation",value:1})),s.value+="."+l._value,r)r(a,new Blob([u.image()]),l._value);else{At(window.navigator).any?(async(e,t)=>{const n={files:[new File([t],e,{type:t.type})]};try{if(!navigator.canShare||!navigator.canShare(n))throw new Error("Can't share data.");await navigator.share(n)}catch(e){"Share canceled"!==e.message&&console.error(e.name,">",e.message)}})(s.value,new Blob([u.image()])):u.download(s.value)}}}const Nt='<svg style="width:60%;" viewBox="0 0 256 256"  xmlns="http://www.w3.org/2000/svg">\n<path d="M40.2407 220.5L102.5 112.324L102.5 220.5H40.2407Z"  stroke-width="13" stroke-linejoin="round" fill="transparent"/>\n<path d="M211.759 220.5L149.5 112.324L149.5 220.5H211.759Z"  stroke-width="13" stroke-linejoin="round" fill="transparent"/>\n<line x1="78" y1="59.5" x2="174" y2="59.5"  stroke-width="13"/>\n<path d="M45.3896 63.5218C42.6395 61.3491 42.6395 57.1783 45.3896 55.0056L69.8741 35.6614C73.4324 32.8501 78.6648 35.3846 78.6648 39.9195L78.6648 78.6079C78.6648 83.1428 73.4324 85.6773 69.8741 82.8659L45.3896 63.5218Z" />\n<path d="M207.163 55.0056C209.913 57.1783 209.913 61.349 207.163 63.5217L182.679 82.8659C179.12 85.6772 173.888 83.1428 173.888 78.6078L173.888 39.9195C173.888 35.3846 179.12 32.8501 182.679 35.6614L207.163 55.0056Z" />\n</svg>';function Gt(e,t,n,r){let o=t.slice(0);const{top:a,left:s}=e.getBoundingClientRect();let l,c,u=e.offsetWidth,f=e.offsetHeight,d=!1;function p(e,t,n){return Math.max(e,Math.min(n,t))}function h(e){var t=p(0,e.offsetX/u,1),n=p(0,e.offsetY/f,1);o[c]=[t,n]}function v(e){d=!1,c=void 0,mousecontainer.releasePointerCapture(e.pointerId),mousecontainer.removeEventListener("pointermove",m),mousecontainer.removeEventListener("pointerup",v)}function g(e){d=!0;const t=document.elementFromPoint(e.x,e.y);t.id.startsWith("mouse")&&(c=parseInt(t.id.replace("mouse",""))),mousecontainer.setPointerCapture(e.pointerId),mousecontainer.addEventListener("pointermove",m),mousecontainer.addEventListener("pointerup",v);const{left:n,top:r}=t.getBoundingClientRect();h(e)}function m(e){d&&void 0!==c&&(h(e),ft("mouse",()=>x(),20))}function x(){document.getElementById("mouse0")&&(o.forEach((e,t)=>{const n=document.getElementById("mouse"+t),r=e[0]*u-n.offsetWidth/2+"px",i=e[1]*f-n.offsetHeight/2+"px";n.style.left!==r&&(n.style.left=r),n.style.top!==i&&(n.style.top=i)}),n&&n(o,l))}return b(()=>{mousecontainer.addEventListener("pointerdown",g),l=mousecanvas.getContext("2d"),x()}),w(()=>{mousecontainer.removeEventListener("pointerdown",g)}),i`
      <style>
        #mousecontainer{position: fixed;top:${a}px;left:${s}px;width:${u}px;height:${f}px;}
        #mousecanvas{overflow:hidden;border:0px solid white;}
        .point{position:absolute;width: ${45}px;height: ${45}px;background-color:white; border-radius: 50%;cursor:pointer;border: 15px solid transparent;background-clip: padding-box;box-sizing: border-box;}
      </style>
      <div id="mousecontainer" @dblclick="${function(){o=r?r(o):t.slice(0),x()}}">
        <canvas id="mousecanvas" width="${u}" height="${f}"></canvas>
        ${o?.map((e,t)=>i`
            <div id="mouse${t}" style="left:${e[0]*u-22.5}px;top:${e[1]*f-22.5}px;" class="point" ></div>
          `)}
      </div>
  `}function Ot(e,t,n,r,o,a,s){return i`
    <div class="section" id="${e}" :style="${()=>n.value===e&&`height:${t}px;`}" :selected="${()=>n.value===e}" @click="${t=>{t.stopPropagation(),n.value=e}}">
        <div class="section_header" >
          ${!!o&&i`<a id="btn_skip_${e}" class="section_skip" @click="${function(t){t.preventDefault(),t.stopPropagation();const n=document.getElementById("btn_skip_"+e),i=document.getElementById(e),a=document.getElementById(e+"_content");r[e].$skip?(r[e].$skip=!1,n?.removeAttribute("disabled"),i?.removeAttribute("skipped"),a?.classList.remove("skip"),i.style.opacity="",o(!0)):(r[e].$skip=!0,n?.setAttribute("disabled",!0),i?.setAttribute("skipped",!0),a?.classList.add("skip"),o(!1))}}" title="toggle">\u2609</a>`}
          <b class="section_label">${e}</b>
          ${!!a&&i`<a id="btn_reset_${e}" class="reset_btn" @click="${function(){r[e]?.$skip||a&&a(e)}}" disabled title="reset"><svg class="reset_svg" viewBox="0 0 20 23.565"><use xlink:href="#Preset_Rotation"></use></svg></a>`}
        </div>

        ${()=>n.value===e&&i`
          <div id="${e}_content" class="section_content ${r[e]?.$skip?"skip":""}" @click="${e=>e.stopPropagation()}">
            <div class="section_scroll">
              <hr>
              <button class="close_btn" @click="${()=>n.value=""}">X</button>
              ${s}
            </div>
          </div>
        `}
    </div>`}function zt(e,t,n,r,o){let a,s;function l(e){const n=document.getElementById("crop"),r=document.getElementById("croprect");n.style.width=Math.round(canvas.getBoundingClientRect().width)+"px",n.style.height=Math.round(canvas.getBoundingClientRect().height)+"px",t.crop.ar&&(r.style.aspectRatio=t.crop.ar),r.style.inset="0",t.crop.currentcrop=0}function c(e){"v"===e?(t.trs.flipv=!t.trs.flipv,t.trs.flipv?flipv.setAttribute("selected",!0):flipv.removeAttribute("selected")):(t.trs.fliph=!t.trs.fliph,t.trs.fliph?fliph.setAttribute("selected",!0):fliph.removeAttribute("selected")),u(),n()}function u(){0===Object.values(t.trs).reduce((e,t)=>e+t,0)&&0===Object.values(t.crop).reduce((e,t)=>e+t,0)&&0==t.perspective2.modified&&0===t.resizer.width?btn_reset_composition.setAttribute("disabled",!0):btn_reset_composition.removeAttribute("disabled")}f(()=>{"composition"===e.value?(a=r(),a.resetCrop(),p[1]=a.gl.canvas.width/a.gl.canvas.height,p[2]=1/p[1],v(),n(),s=e.value):"composition"===s&&(y(),s=void 0,async function(){const e=t;if(!croprect)return;crop.style.display="";const r=canvas.width/crop.offsetWidth;e.crop.glcrop={left:Math.round(croprect.offsetLeft*r),top:Math.round(croprect.offsetTop*r),width:Math.round(croprect.offsetWidth*r),height:Math.round(croprect.offsetHeight*r)},n(),o()}())},{effect:!0});const d=["free","pic","1:pic","1:1","4:3","16:9","3:4","9:16"];let p=[0,0,0,1,4/3,16/9,3/4,9/16];function h(e){y(),t.crop.arindex=e,t.crop.ar=p[e],croprect&&(croprect.style.aspectRatio=p[e]);const n=document.getElementById("aspects");n&&(n.querySelector("[selected]")?.removeAttribute("selected"),n.querySelector("#ar_"+e)?.setAttribute("selected",!0)),u()}function v(){const{width:e,height:n}=a;t.crop.canvas_angle%180?(a.gl.canvas.width=n,a.gl.canvas.height=e):(a.gl.canvas.width=e,a.gl.canvas.height=n),a.setupFiltersTextures(),o()}function g(e){const r=e.target.value,i=this.id.split("_");t[i[0]][i[1]]=parseFloat(r);const o=document.getElementById("trs_"+i[1]),a=document.getElementById("trs_"+i[1]+"_");if(o&&o!==this&&(o.value=r),a&&a!==this&&(a.value=r),"angle"===i[1]){const e=parseFloat(Math.abs(r))*Math.PI/180,n=canvas.width*Math.cos(e)+canvas.height*Math.sin(e),i=canvas.width*Math.sin(e)+canvas.height*Math.cos(e),o=Math.max(n/canvas.width-1,i/canvas.height-1);t.trs.scale=o,u()}n()}function m(e){const n=document.getElementById(e);if(!n)return;const r=e.split("_");n.value=t[r[0]][r[1]];const i=document.getElementById(e+"_");i&&(i.value=n.value)}function x(){if(!this)return;const e=this.id.split("_");t[e[0]][e[1]]=0,m(this.id),"angle"===e[1]&&(t.trs.scale=0),u(),n()}let b=f(!1);function y(){const e=document.getElementById("crop");e&&(e.style.display=""),b.value=!1}function w(){b.value?y():async function(){b.value=t.perspective2,crop.style.display="none"}()}function C(){t.perspective2.before&&(t.perspective2.after=0,b.value=!1,b.value=t.perspective2)}const _=f(100);function S(e,r){resize_width.value=t.resizer.width=e,resize_height.value=t.resizer.height=r,a.resize(e,r),_.value=Math.round(e/a.img.width*1e3)/10,v(),l(),u(),n()}function $(){const e=p[1],t=Math.max(100,this.value);S(t,Math.floor(t/e))}function k(){const e=p[1],t=Math.max(100,this.value);S(Math.floor(t*e),t)}return i`
    ${Ot("composition",235,e,t,null,function(){if(!document.getElementById("croprect"))return;Object.keys(t.crop).forEach(e=>{t.crop[e]=0}),h(0),v(),Object.keys(t.trs).forEach(e=>{t.trs[e]=0,m("trs_"+e)}),Object.keys(t.perspective2).forEach(e=>{t.perspective2[e]=0});const e=document.getElementById("fliph"),r=document.getElementById("flipv");e.removeAttribute("selected"),r.removeAttribute("selected"),y(),l(),a.resetResize(),t.resizer.width=0,t.resizer.height=0,resize_width.value=a.width,resize_height.value=a.height,_.value=100,u(),n()},()=>i`
            <style>
              .crop_btn {
                width: 38px;
                color: white;
                padding: 0;
                margin: 2px;
                border-radius:50%;
                fill: white;
                stroke: white;
                font-size: 12px;
              }
              .close_btn {display:none !important;}
            </style>

            <button class="done_btn" @click="${()=>e.value=""}">done</button>
              <div style="display:flex;justify-content: space-around;align-items: center;">
                <div class="rangelabel">rotation</div>
                <input id="trs_angle" type="range" value="${t.trs.angle}" min=-45 max=45 step=0.25 @input="${g}" @dblclick="${x}">
                <input id="trs_angle_" type="number" class="rangenumb" value="${t.trs.angle}" min=-45 max=45 step=0.25 @input="${g}">
              </div>
              <div class="crop_btns">
                <button id="fliph" class="crop_btn" title="flip x" selected="${!!t.trs.fliph}" @click="${()=>c("h")}">${Nt}</button>
                <button id="flipv" class="crop_btn" title="flip y" selected="${!!t.trs.flipv}" @click="${()=>c("v")}" style="rotate: 270deg;transform:translate(3px,0px)">${Nt}</button>
                <button class="crop_btn" title="rotate left" @click="${()=>{return e=-90,t.crop.canvas_angle=(t.crop.canvas_angle+e)%360,v(),crop.style.width=Math.round(canvas.getBoundingClientRect().width)+"px",crop.style.height=Math.round(canvas.getBoundingClientRect().height)+"px",croprect.style.inset="0",y(),u(),void n();var e}}">${'<svg style="width:60%;" viewBox="0 0 256 256"  xmlns="http://www.w3.org/2000/svg">\n<rect x="54.8183" y="90.0903" width="120.743" height="120.743" rx="14.2449"  stroke-width="17.6366" fill="transparent"/>\n<path d="M221.004 115.176L221.004 89.1424C221.004 63.8095 200.046 43.2732 174.193 43.2732L149.101 43.2732" stroke-width="17.6366" stroke-linecap="round" fill="transparent"/>\n<path d="M131.428 47.5313C128.678 45.3586 128.678 41.1878 131.428 39.0151L155.912 19.671C159.471 16.8597 164.703 19.3941 164.703 23.929L164.703 62.6174C164.703 67.1523 159.471 69.6868 155.912 66.8755L131.428 47.5313Z" />\n</svg>'}</button>
                <button class="crop_btn" title="perspective" :selected="${()=>!!b.value}" @click="${w}" style="transform:translate(0px,3px)">${'<svg style="width:50%;" viewBox="0 0 56 56" xmlns="http://www.w3.org/2000/svg"><g stroke-width="0"></g><g  stroke-linecap="round" stroke-linejoin="round"></g><g ><path d="M 5.4648 42.5781 C 7.5272 42.5781 9.3085 41.3594 10.1757 39.6016 L 45.4724 49.9609 C 46.0820 52.2109 48.1211 53.875 50.5585 53.875 C 53.4179 53.875 55.7852 51.5313 55.7852 48.6484 C 55.7852 46.4687 54.4489 44.5937 52.5505 43.7969 L 51.5665 20.2422 C 53.5820 19.5156 55.0350 17.5703 55.0350 15.2969 C 55.0350 12.4140 52.6681 10.0703 49.8083 10.0703 C 47.9099 10.0703 46.2227 11.1016 45.3083 12.625 L 25.7851 7.2578 C 25.7851 4.4922 23.4179 2.1250 20.5585 2.1250 C 17.6757 2.1250 15.3085 4.4922 15.3085 7.3750 C 15.3085 8.9219 15.9882 10.3281 17.0897 11.2891 L 6.2148 32.1484 C 5.9804 32.1016 5.7226 32.1016 5.4648 32.1016 C 2.5819 32.1016 .2148 34.4453 .2148 37.3281 C .2148 40.2109 2.5819 42.5781 5.4648 42.5781 Z M 20.5585 12.625 C 22.2694 12.625 23.8163 11.7578 24.7772 10.4453 L 44.5820 15.9062 C 44.8398 17.9922 46.3163 19.7266 48.2852 20.3125 L 49.1056 43.5859 C 47.5585 44.0547 46.2928 45.2031 45.6836 46.6797 L 10.5976 36.3672 C 10.4101 35.3828 9.9413 34.4687 9.2851 33.7656 L 20.1601 12.6016 C 20.2772 12.6016 20.4179 12.625 20.5585 12.625 Z"></path></g></svg>'}</button>
              </div>
            ${()=>b.value&&i`              
              ${()=>!b.value.before&&i`<div style="text-align:center;color:darksalmon;">position corners AND <button @click="${C}">lock rect</button></div>`}
              ${()=>!!b.value.before&&i`<div style="text-align:center;color:darksalmon;">drag corners</div>`}
              ${function(e,t,n){let r=[[.25,.25],[.75,.25],[.75,.75],[.25,.75]],o=t?.after||t?.before||r,a=0;t?.before&&(a=1);let s=!0;return i`
      <style>
        #mousecanvas{border: 1px solid white;background-image: repeating-linear-gradient(#ccc 0 1px, transparent 1px 100%), repeating-linear-gradient(90deg, #ccc 0 1px, transparent 1px 100%);background-size: 9.99% 9.99%;}
      </style>
      ${Gt(e,o,function(e,r){r.clearRect(0,0,mousecanvas.width,mousecanvas.height),r.lineWidth=3,r.strokeStyle="red",r.beginPath();for(var i=0;i<4;i++){const t=e[i][0]*mousecanvas.width,n=e[i][1]*mousecanvas.height;r.lineTo(t,n)}r.closePath(),r.stroke(),s?s=!1:t.modified||(t.modified=!0),a?(t.after=e,n&&n()):t.before=e},function(e){return t.modified=!1,r})}
  `}(canvas,b.value,()=>{u(),n()})}
            `}

            
              <div class="sr--mt--10 rangelabel">crop ratio</div>
              <div style="text-align:left;" id="aspects">
                ${d.map((e,n)=>i`
                  <button id="ar_${n}" @click="${()=>h(n)}" class="crop_btn" selected="${n===t.crop.arindex}" @dblclick="${l}">${e}</button>
                `)}
              </div>            
              <div class="sr--mt--20 sr--mb--10 rangelabel">image size</div>
              <div style="display:flex;justify-content: space-around;align-items: center;">                
                <input id="resize_width" type="number" value="${canvas.width}" style="text-align:center;width:80px;margin-right:10px;" @change="${$}"> 
                x 
                <input id="resize_height" type="number" value="${canvas.height}" style="text-align:center;width:80px;margin-left:10px;" @change="${k}">
              </div>
              <sr-sp h="10"></sr-sp>


      `)}



  `}function jt(e,t,n){const r={lights:190,colors:150,effects:105};function o(e){!function(e){for(const n of Object.keys(t[e]))t[e][n]=0,c(e+"_"+n)}(e),n(),a(e)}function a(e){const n=document.getElementById("btn_reset_"+e);n&&(!function(e){return 0===Object.values(t[e]).reduce((e,t)=>e+t,0)}(e)?n.removeAttribute("disabled"):n.setAttribute("disabled",!0))}function s(e){ft("param",()=>l.call(this,e),30)}function l(e){const r=e.target.value,i=this.id.split("_");t[i[0]][i[1]]=parseFloat(r),c(this.id),n(),a(i[0])}function c(e){const n=document.getElementById(e);if(!n)return;const r=e.split("_");n.value=t[r[0]][r[1]],3===r.length?n.previousElementSibling.value=n.value:n.nextElementSibling.value=n.value}function u(){if(!this)return;const e=this.id.split("_");t[e[0]][e[1]]=0,c(this.id),n(),a(e[0])}return f(()=>{null===e.value&&["lights","colors","effects"].forEach(e=>a(e))},{effect:!0}),i`
    ${["lights","colors","effects"].map(a=>i`

        ${Ot(a,r[a],e,t,n,o,()=>i`${Object.keys(t[a]).filter(e=>!e.startsWith("$")).map(e=>i`
                          /* RANGE INPUTS */
                          <div style="display:flex;justify-content: space-around;align-items: center;">
                            <div class="rangelabel">${e}</div>
                            <input id="${a+"_"+e}"      type="range"  style="width:130px;"  value="${t[a][e]}" min=-1 max=1 step=0.01 @input="${s}" @dblclick="${u}">
                            <input id="${a+"_"+e+"_"}"  type="number" class="rangenumb"     value="${t[a][e]}" min=-1 max=1 step=0.01 @input="${s}">
                          </div>

                      `)}
            `)}



    `)}
  `}function Xt(e,t,n){let r=t.curve,o={space:0,numpoints:5,curvepoints:t.curve?.curvepoints||null,modifiedflag:null,resetFn:null};function a(e,t){o.curvepoints=t.map((t,n)=>t&&e[n]),0===o.curvepoints.reduce((e,t)=>e+t,0)?r.curvepoints=0:r.curvepoints=o.curvepoints,function(){if(!document.getElementById("btn_reset_curve"))return;0===o?.curvepoints?.reduce((e,t)=>e+t,0)?btn_reset_curve?.setAttribute("disabled",!0):btn_reset_curve?.removeAttribute("disabled")}(),n()}return f(()=>{null===e.value&&t.curve?.curvepoints&&(r=t.curve,a(r.curvepoints,[!0,!0,!0,!0]))},{effect:!0}),i`
    ${Ot("curve",190,e,t,n,function(){o.resetFn&&o.resetFn()},()=>i`<div class="cc_container">
              ${()=>function(e,t){const n=256,r=f(e?.numpoints||5);let o,a,s,l=e?.space||0,c=e?.curvepoints||new Array(4).fill(null),u=new Array(4);function d(e){c[e]=[];for(let t=0;t<r._value;t++){const n=t/(r._value-1);c[e].push([n,n])}u[e]=null}function p(t){t="string"==typeof t?t:this?.id;const n=document.getElementById(t);n&&(cccolors.getElementsByClassName("selected")[0]?.classList.remove("selected"),n.classList.add("selected"),l=parseInt(t.replace("space","")),e.space=l,c[l]||d(l),_())}c.forEach((e,t)=>{u[t]=!!e||null}),c[l]?.length||d(l),b(()=>{curvecontainer.addEventListener("pointerdown",m),o=curvescanvas.offsetWidth,a=curvescanvas.offsetHeight,s=curvescanvas.getContext("2d"),p("space"+l),e.resetFn=()=>{e.space=0,e.curvepoints=null,l=0,c=new Array(4).fill(null),p("space"+l)}}),w(()=>{curvecontainer.removeEventListener("pointerdown",m)});let h,v=!1;function g(e){v=!1,curvecontainer.releasePointerCapture(e.pointerId),curvecontainer.removeEventListener("pointermove",C),curvecontainer.removeEventListener("pointerup",g),h=void 0}function m(e){v=!0,curvecontainer.setPointerCapture(e.pointerId),curvecontainer.addEventListener("pointermove",C),curvecontainer.addEventListener("pointerup",g),o=curvescanvas.offsetWidth,a=curvescanvas.offsetHeight;const t=document.elementFromPoint(e.x,e.y);t.id.startsWith("pt")&&(h=parseInt(t.id.replace("pt",""))),u[l]=!0,y(e)}function x(e,t,n){return Math.max(e,Math.min(n,t))}function y(e){const t=h?c[l][h-1][0]+.1:0,n=h<r._value-1?c[l][h+1][0]-.1:1;var i=x(t,e.offsetX/o,n),s=x(0,1-e.offsetY/a,1);c[l][h]=[i,s]}function C(e){v&&void 0!==h&&(y(e),ft("curve",()=>_(),20))}function _(){if(!c?.[l])return;c[l].forEach((e,t)=>{const n=document.getElementById("pt"+t);n.style.left=e[0]*o-22.5+"px",n.style.bottom=e[1]*a-22.5+"px"});const e=c[l].map(e=>e[0]),r=c[l].map(e=>e[1]),i=new Ze(c[l]);let f;s.clearRect(0,0,n,n),s.lineWidth=4,s.strokeStyle="#4B4947",s.beginPath();for(var d=0;d<n;d++)f=d<e[0]*n?r[0]:d>e[e.length-1]*n?r[r.length-1]:x(0,i.at(d/255),1),s.lineTo(d,(1-f)*n);s.stroke(),s.fillStyle="white",t&&t(c,u)}return i`
      <style>
        #curvecontainer{position: relative;width:200px;height: 120px;margin:auto;background-image: radial-gradient(#5b5b5b 1px, transparent 0);background-size: 10% 10%;border-radius: 10px;border: 1px solid #5b5b5b;}
        #curvescanvas{width:inherit;height: inherit;overflow:hidden;border:0px solid white;}
        .point{position:absolute;background-color: white; width: ${45}px;height: ${45}px; border-radius: 50%;cursor:pointer;border: 17px solid transparent;background-clip: padding-box;box-sizing: border-box;}
      </style>
      <div id="cccolors" style="display:flex;flex-direction:row; max-width:275px;">
        <div style="width:60px;">
          <button id="space0" @click="${p}" class="clrspace selected" style="border-color:white;" title="all colors"></button>
          <button id="space1" @click="${p}" class="clrspace" style="border-color:#c13119;" title="red"></button>
          <button id="space2" @click="${p}" class="clrspace" style="border-color:#0c9427;" title="green"></button>
          <button id="space3" @click="${p}" class="clrspace" style="border-color:#1e73be;" title="blue"></button>
        </div>
        <div id="curvecontainer" @dblclick="${function(){d(l),_()}}">
          <canvas id="curvescanvas" width=${n} height=${n}></canvas>
          ${()=>r.value&&c[l]?.map((e,t)=>i`
              <div id="pt${t}" class="point"></div>
            `)}
        </div>
      </div>
  `}(o,a)}
          </div>`)}
  `}const Wt=[{type:"1",label:"aden",map1:"LUT_aden.png"},{type:"1",label:"crema",map1:"LUT_crema.png"},{type:"2",label:"clarendon",map1:"LUT_clarendon1.png",map2:"LUT_clarendon2.png"},{type:"3",label:"gingham",map1:"LUT_gingham1.png",map2:"LUT_gingham_lgg.png"},{type:"1",label:"juno",map1:"LUT_juno.png"},{type:"1",label:"lark",map1:"LUT_lark.png"},{type:"1",label:"ludwig",map1:"LUT_ludwig.png"},{type:"4",label:"moon",map1:"LUT_moon1.png",map2:"LUT_moon2.png"},{type:"1",label:"reyes",map1:"LUT_reyes.png"},{type:"MTX",label:"polaroid",mtx:"polaroid"},{type:"MTX",label:"kodak",mtx:"kodachrome"},{type:"MTX",label:"browni",mtx:"browni"},{type:"MTX",label:"vintage",mtx:"vintage"}];async function Vt(e){const t=new Image;return t.src=e,await t.decode(),t}function Ht(e,t,n,r=""){const o=t.filters;let a=f(!1);async function s(e){a.value!==e?(a.value=e,btn_reset_filters?.removeAttribute("disabled"),await async function(e){const t=document.getElementById("loader");t&&setTimeout(()=>t.style.display="",20);const n=Wt[parseInt(e)];n.map1&&"string"==typeof n.map1&&(n.map1=await Vt(r+n.map1)),n.map2&&"string"==typeof n.map2&&(n.map2=await Vt(r+n.map2));const{type:i,mtx:a,map1:s,map2:l,label:c}=n;o.opt={type:i,mtx:a,map1:s,map2:l,label:c},t&&(t.style.display="none")}(e),n()):l()}function l(){btn_reset_filters?.setAttribute("disabled",!0),a.value=!1,o.opt=0,n()}return f(async()=>{if(null===e.value&&t.filters?.label){s(Wt.findIndex(e=>e.label===t.filters.label))}},{effect:!0}),i`
    <style>.btn_insta{width:70px;color: light-dark(white, white); font-size: 12px;}</style>
    <style type="text/css">@keyframes animate { 0.00% {animation-timing-function: cubic-bezier(0.51,0.03,0.89,0.56);transform: translate(0.00px,0.00px) rotate(0.00deg) scale(1.00, 1.00) skew(0deg, 0.00deg) ;opacity: 1.00;}52.00% {animation-timing-function: cubic-bezier(0.17,0.39,0.55,0.91);transform: translate(0.00px,0.00px) rotate(211.13deg) ;}100.00% {animation-timing-function: cubic-bezier(0.17,0.39,0.55,0.91);transform: translate(0.00px,0.00px) rotate(360.00deg) ;} }</style>

    ${Ot("filters",235,e,t,n,l,()=>i`<div id="loader" style="width:23px;fill: orange;display:none;position:absolute;top:-30px;">${'<svg xml:space="preserve" viewBox="0 0 100 100" y="0" x="0" xmlns="http://www.w3.org/2000/svg" id="圖層_1" version="1.1" style="margin: initial; display: block; shape-rendering: auto; background: transparent;" preserveAspectRatio="xMidYMid"><g class="ldl-scale" style="transform-origin: 50% 50%; transform: rotate(0deg) scale(0.8, 0.8);"><g class="ldl-ani" style="transform-box: view-box; opacity: 1; transform-origin: 50px 50px; transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); animation: 1s linear 0s infinite normal forwards running animate;"><g class="ldl-layer"><g class="ldl-ani" style="transform-box: view-box;"><path fill="inherit" d="M89.982 48.757h-.002a40.04 40.04 0 0 0-2.246-12.003l-.125-.332a40.721 40.721 0 0 0-.574-1.517l-.334-.774a33.907 33.907 0 0 0-.487-1.112l-.078-.168c-.166-.355-.344-.705-.531-1.075l-.187-.367c-.13-.249-.266-.495-.404-.744l-1.44-2.406a38.537 38.537 0 0 0-.666-1.001l-1.74-2.292L59.423 62.63h28.506l.406-1.328c.048-.151.095-.303.137-.451a40.634 40.634 0 0 0 .717-2.97 36.2 36.2 0 0 0 .187-.96c.112-.631.202-1.266.284-1.905l.042-.314c.029-.208.057-.415.077-.619.107-1.026.174-1.96.201-2.843l.02-1.137-.018-1.346z"  ></path></g></g><g class="ldl-layer"><g class="ldl-ani" style="transform-box: view-box;"><path fill="inherit" d="M58.024 89.163l1.838-.429c.358-.091.714-.187 1.073-.288.58-.165 1.156-.346 1.728-.536l.178-.059c.285-.094.569-.189.847-.29.607-.22 1.204-.463 1.797-.711l.27-.11c.199-.081.398-.161.598-.251a41.757 41.757 0 0 0 2.686-1.315l.21-.115c.214-.116.404-.225.584-.331l1.229-.729a40.14 40.14 0 0 0 4.94-3.618 40.837 40.837 0 0 0 2.129-1.971l.121-.113a40.584 40.584 0 0 0 4.588-5.474l.121-.175c.208-.303.411-.61.688-1.037l2.006-3.501c.161-.315.324-.641.412-.844l1.029-2.795H43.77l14.254 24.692z"  ></path></g></g><g class="ldl-layer"><g class="ldl-ani" style="transform-box: view-box;"><path fill="inherit" d="M20.094 76.527l.955 1.023c.106.115.21.229.318.341a41.011 41.011 0 0 0 2.12 2.022l.196.174c.208.186.418.37.631.549.49.412.995.806 1.503 1.192l.244.19c.169.131.337.263.51.388A40.702 40.702 0 0 0 28.934 84l1.219.724c.187.11.376.219.584.334l.337.178c.759.407 1.536.776 2.445 1.194.106.054.213.107.311.149a39.841 39.841 0 0 0 8.692 2.698l.157.032c.622.115 1.244.217 1.859.303l.564.066c.501.063 1.002.125 1.499.168l.183.017c.391.03.78.054 1.269.08l.359.017c.272.011.542.018.91.024l.697.009.854-.014c.246-.005.495-.011.736-.021l.432-.02c.391-.021.78-.045 1.321-.088l2.649-.483L34.347 51.84 20.094 76.527zm26.815 11.795v.002-.002z"  ></path></g></g><g class="ldl-layer"><g class="ldl-ani" style="transform-box: view-box;"><path fill="inherit" d="M79.906 23.463l-.961-1.029a13.335 13.335 0 0 0-.326-.349 39.14 39.14 0 0 0-2.12-2.021l-.116-.103c-.228-.202-.454-.404-.685-.598a38.415 38.415 0 0 0-1.539-1.219l-.234-.183c-.16-.125-.32-.249-.489-.373a40.813 40.813 0 0 0-2.371-1.601l-2.148-1.239a40.129 40.129 0 0 0-11.527-4.055 39.84 39.84 0 0 0-3.868-.537 1.465 1.465 0 0 0-.22-.023l-2.452-.123-.05 1.115-.127-1.118-1.544.003c-.246.005-.494.011-.75.021l-.424.021a37.51 37.51 0 0 0-1.174.077l-2.908.296 21.78 37.725 14.253-24.687z"  ></path></g></g><g class="ldl-layer"><g class="ldl-ani" style="transform-box: view-box;"><path fill="inherit" d="M41.974 10.828l-1.372.32c-.157.035-.314.069-.468.109a41.654 41.654 0 0 0-2.807.826l-.161.054a42.89 42.89 0 0 0-.85.291c-.613.222-1.221.468-1.819.718l-.263.107c-.195.08-.389.158-.581.244-.936.417-1.776.827-2.576 1.254l-2.137 1.235c-3.491 2.154-6.615 4.828-9.369 8.043-.285.334-.561.667-.844 1.022l-.214.276a36.63 36.63 0 0 0-.7.918l-.308.427c-.198.278-.386.54-.605.866l-1.832 2.984-.127.228c-.103.184-.204.37-.312.575l-.254.489c-.172.341-.343.682-.507 1.026l-1.207 2.676H56.23L41.974 10.828z"  ></path></g></g><g class="ldl-layer"><g class="ldl-ani" style="transform-box: view-box;"><path fill="inherit" d="M12.071 37.361l-.404 1.322c-.048.155-.097.309-.139.457a39.505 39.505 0 0 0-.691 2.848l-.038.18c-.062.302-.124.604-.175.903a40.32 40.32 0 0 0-.284 1.906l-.042.309c-.029.208-.057.417-.077.62a38.802 38.802 0 0 0-.201 2.854l-.014.376c-.006.234-.006.441-.006.649l.02 1.444c.13 4.087.884 8.123 2.247 12.01l.137.37c.18.492.361.984.554 1.459l.281.653c.177.421.355.841.545 1.245l.08.172c.166.35.34.697.513 1.037l1.401 2.514c.136.226.273.454.432.705l.217.335c.216.331.43.661.663.993l1.678 2.412 21.81-37.774H12.071z"  ></path></g></g></g></g></svg>'}</div>
              ${Wt.map((e,t)=>i`
                <button class="btn_insta" @click="${()=>s(t)}" :selected="${()=>a.value===t}">${e.label}</button>
                `)}            
      `)}
  `}function Yt(e,t,n){const r={bokehstrength:0,bokehlensout:.5,gaussianstrength:0,centerX:.5,centerY:.5};s("blur")||l("blur");const o=f(!1);function a(e){t.blur.centerX=e[0][0],t.blur.centerY=e[0][1],n()}function s(e){for(const n of Object.keys(r))if(!(n in t[e])||t[e][n]!==r[n])return!1;return!0}function l(e){for(const n of Object.keys(r))t[e][n]!==r[n]&&(t[e][n]=r[n],p(e+"_"+n))}function c(e){const t=document.getElementById("btn_reset_"+e);t&&(s(e)?t.setAttribute("disabled",!0):t.removeAttribute("disabled"))}function u(e){ft("param",()=>d.call(this,e),30)}function d(e){const r=e.target.value,i=this.id.split("_");t[i[0]][i[1]]=parseFloat(r),p(this.id),n(),c(i[0])}function p(e){const n=document.getElementById(e);if(!n)return;const r=e.split("_");n.value=t[r[0]][r[1]],3===r.length?n.previousElementSibling.value=n.value:n.nextElementSibling.value=n.value}function h(){if(!this)return;const e=this.id.split("_");t[e[0]][e[1]]=0,p(this.id),n(),c(e[0])}return f(()=>{"blur"===e.value?(o.value=[[t.blur.centerX,t.blur.centerY]],Kt()):(o.value=!1,null===e.value&&c("blur"))},{effect:!0}),i`
    ${Ot("blur",125,e,t,function(e){e&&Kt(),n()},function(e){l(e),n(),c(e),o.value=!1,o.value=[[t.blur.centerX,t.blur.centerY]]},()=>i` /* mouse canvas */
                <style>.point{background-color:red !important;border:2px solid darkorange;}</style>
                ${()=>o.value&&Gt(canvas,o.value,a)}

                ${["bokehstrength","gaussianstrength","bokehlensout"].filter(e=>!e.startsWith("$")).map((e,n)=>i`
                    /* RANGE INPUTS */
                    <div style="display:flex;justify-content: space-around;align-items: center;">
                      <div class="rangelabel">${["bokeh strength","gauss strength","cirble radius"][n]}</div>
                      <input id="${"blur_"+e}"      type="range"  style="width:130px;"  value="${t.blur[e]}" min=0 max=1 step=0.01 @input="${u}" @dblclick="${h}">
                      <input id="${"blur_"+e+"_"}"  type="number" class="rangenumb"     value="${t.blur[e]}" min=0 max=1 step=0.01 @input="${u}">
                    </div>

                `)}
                <div class="infolabel">center red dot</div>
      `)}
  `}function Zt(e,t,n,r,o){const a=f([]);let s=!1;async function l(){if(o&&o.get){try{const e=await o.get();a.value=Array.isArray(e)?e:[]}catch(e){a.value=[]}s=!0}else a.value=[]}async function c(){const e=document.getElementById("sr7_preset_name"),t=(e&&e.value||"").trim();if(!t||!o||!o.save)return;await o.save(t,n())&&(e&&(e.value=""),s=!1,l())}return f(()=>{"presets"!==e.value||s||l()},{effect:!0}),i`
    ${Ot("presets",250,e,t,null,null,()=>i`
      <div class="sr7_presets">
        <div class="sr7_preset_save">
          <input id="sr7_preset_name" type="text" placeholder="Preset name" autocomplete="off">
          <button class="sr7_preset_savebtn" @click="${c}">Save Current</button>
        </div>
        <div class="sr7_preset_list_title">Saved Presets</div>
        <div class="sr7_preset_list">
          ${()=>0===a.value.length?i`<div class="sr7_preset_empty">No presets saved yet</div>`:a.value.map(e=>i`
                <div class="sr7_preset_row" @click="${()=>function(e){e&&r(e.params||{})}(e)}">
                  <span class="sr7_preset_name">${e.title||e.value}</span>
                  <span class="sr7_preset_del" title="delete" @click="${t=>{t.stopPropagation(),async function(e){if(!o||!o.delete)return;await o.delete(e)&&(s=!1,l())}(e.value)}}">×</span>
                </div>
              `)}
        </div>
      </div>
    `)}
  `}const qt={appname:"MiNi PhotoEditor"};function Kt(){const e=document.getElementById("canvas"),t=document.getElementById("editor"),n=e.width/e.height;t.offsetWidth/n>t.offsetHeight?(e.style.height="99%",e.style.width=""):(e.style.width="99%",e.style.height=""),zoomable.style.transform="",pannable.style.transform=""}return e.Editor=function(e=!1){R(qt);let t,n,r,o=!0;!1===e?.sample&&(o=!1);const a=f(!1),s=f();let l={trs:{translateX:0,translateY:0,angle:0,scale:0,flipv:0,fliph:0},crop:{currentcrop:0,glcrop:0,canvas_angle:0,ar:0,arindex:0},lights:{brightness:0,exposure:0,gamma:0,contrast:0,shadows:0,highlights:0,bloom:0},colors:{temperature:0,tint:0,vibrance:0,saturation:0,sepia:0},effects:{clarity:0,noise:0,vignette:0},curve:{curvepoints:0},filters:{opt:0,mix:0},perspective:{quad:0,modified:0},perspective2:{before:0,after:0,modified:0},blender:{blendmap:0,blendmix:.5},resizer:{width:0,height:0},blur:{bokehstrength:0,bokehlensout:.5,gaussianstrength:0,gaussianlensout:.5,centerX:.5,centerY:.5},heal:{healmask:0}};async function c(e,t){if(e)try{let n,r,i,o={name:t};if("string"==typeof e&&e.startsWith("http")){const t=await fetch(e);if(200!==t.status)return console.error(await t.json());n=await t.arrayBuffer()}else if(e instanceof Image){const t=await fetch(e.src);if(t.error)return console.error(t.error);n=await t.arrayBuffer(),i=e}else if(e instanceof ArrayBuffer)n=e;else{if(!(e instanceof Blob))return console.error("Unknown data type");r=e,n=await e.arrayBuffer()}o.size=n.byteLength,r||(r=new Blob([n])),i||(i=new Image,i.src=URL.createObjectURL(r),await i.decode()),u(n,o,i)}catch(e){console.error(e),await A(`<div style="margin:10px;text-wrap: auto;">${e}</div>`),history.back()}}async function u(e,n,r){if(a._value&&function(){_.value=null,T(),P(),B=.5;for(const e in l)for(const t in l[e])l[e][t]=0}(),t=void 0,function(e){try{const t=new Uint8Array(e,0,12);return 255===t[0]&&216===t[1]||73===t[0]&&73===t[1]&&42===t[2]&&0===t[3]||77===t[0]&&77===t[1]&&0===t[2]&&42===t[3]||102===t[4]&&116===t[5]&&121===t[6]&&112===t[7]}catch(e){return!1}}(e))try{t=await He(e)}catch(e){console.error(e)}let i=t?.read();i||(i={}),i.xml&&(i.xml=i.xml.slice(i.xml.indexOf("<")).replace(/ +(?= )/g,"").replace(/\r\n|\n|\r/gm,"")),i.file={...n,hsize:pt(n.size),width:r?.width||r?.videoWidth||"-",height:r?.height||r?.videoHeight||"-"},i.img=r,i.colorspace=i.icc?.ColorProfile?.[0].includes("P3")?"display-p3":"srgb",a.value=i}async function d(){if(n.loadImage(),(k||l.crop.glcrop)&&(l.trs.angle+=l.crop.canvas_angle,n.filterMatrix(l.trs),l.trs.angle-=l.crop.canvas_angle,l.perspective2.after)){let e=l.perspective2.before.map(e=>[e[0]*canvas.width,e[1]*canvas.height]),t=l.perspective2.after.map(e=>[e[0]*canvas.width,e[1]*canvas.height]);n.filterPerspective(e,t,!1,!1)}if(l.crop.glcrop)return n.crop(l.crop.glcrop),l.crop.glcrop=0,d();!l.blender.$skip&&l.blender.blendmap&&n.filterBlend(l.blender.blendmap,l.blender.blendmix);let e={};l.lights.$skip||(e={...e,...l.lights}),l.colors.$skip||(e={...e,...l.colors}),l.effects.$skip||(e={...e,...l.effects}),n.filterAdjustments({...e}),e.bloom&&n.filterBloom(e.bloom),e.noise&&n.filterNoise(e.noise),(e.shadows||e.highlights)&&n.filterHighlightsShadows(e.highlights||0,-e.shadows||0),!l.curve.$skip&&l.curve.curvepoints&&n.filterCurves(l.curve.curvepoints),!l.filters.$skip&&l.filters.opt&&n.filterInsta(l.filters.opt,l.filters.mix),!l.blur.$skip&&l.blur.bokehstrength&&n.filterBlurBokeh(l.blur),!l.blur.$skip&&l.blur.gaussianstrength&&(l.blur.gaussianlensout=l.blur.bokehlensout,n.filterBlurGaussian(l.blur)),n.paintCanvas(),$&&$()}e?.data&&c(e.data,e.name),f(()=>{if(s.value){const e=a._value;try{n?.destroy&&n.destroy(),n=nt(document.getElementById("canvas"),e.img,e.colorspace),l._minigl=n,r&&r(),r=ct(zoomable,pannable),d(),Kt()}catch(e){console.error(e)}}},{effect:!0});const p=["lights","colors","effects","blur","curve"];function h(){const e={};for(const t of p)if(l[t]){e[t]={};for(const n in l[t])n.startsWith("$")||"_minigl"===n||(e[t][n]=l[t][n])}return e.transform={angle:l.trs.angle,scale:l.trs.scale,flipv:l.trs.flipv?1:0,fliph:l.trs.fliph?1:0,canvas_angle:l.crop.canvas_angle},JSON.parse(JSON.stringify(e))}function v(e){if(e){for(const t of p)if(e[t]&&l[t])for(const n in e[t])n in l[t]&&(l[t][n]=e[t][n]);var t;_.value="",(t=e.transform)&&(parseFloat(t.angle)||parseFloat(t.scale)||parseFloat(t.flipv)||parseFloat(t.fliph)||parseFloat(t.canvas_angle))?function(e){if(!n)return;n.resetCrop();const t=parseFloat(e.canvas_angle)||0,r=n.width,i=n.height;Math.abs(t)%180?(n.gl.canvas.width=i,n.gl.canvas.height=r):(n.gl.canvas.width=r,n.gl.canvas.height=i),n.setupFiltersTextures(),l.trs.translateX=0,l.trs.translateY=0,l.trs.angle=parseFloat(e.angle)||0,l.trs.scale=parseFloat(e.scale)||0,l.trs.flipv=!!parseFloat(e.flipv),l.trs.fliph=!!parseFloat(e.fliph),l.crop.canvas_angle=t,l.crop.glcrop={left:0,top:0,width:n.gl.canvas.width,height:n.gl.canvas.height},d(),Kt()}(e.transform):d()}}function g(e){e?.preventDefault(),Kt()}e?.onReady&&e.onReady({getParams:h,applyParams:v,save:function(){_.value="",Dt(a,t,n,e?.cb||null)}});let m=0;function x(e){if(e.preventDefault(),m&&Date.now()-m<200)return g(e);m=Date.now()}function y(e){e.preventDefault(),_.value=""}async function C(e){e?.stopPropagation();const t=a.value;await A(()=>i`
          <div style="text-align:left;font-size:12px;max-height:50vh;overflow:auto;">
            <div class="section">FILE</div>
              <div>name: ${t.file.name}</div>
              <div>size: ${t.file.width} x ${t.file.height} (${t.file.hsize})</div>
              <div>date: ${t.exif?.DateTimeOriginal?.value||new Date(t.file.lastModified).toLocaleString("en-UK")}</div>
              <div>prof: ${t.colorspace}</div>

            ${t.tiff&&i`<div class="section">TIFF</div>`}
            ${t.tiff&&Object.entries(t.tiff).sort((e,t)=>e[0]?.toString().localeCompare(t[0]?.toString())).map(e=>i`
                  <div>${e[0]}: ${e[1].hvalue||e[1].value}</div>
                `)}

            ${t.gps&&i`<div class="section">GPS</div>`}
            ${()=>t.gps&&function(e){let t;return b(async()=>{t=new maplibregl.Map({container:"map",style:"https://basemaps.cartocdn.com/gl/positron-gl-style/style.json",center:e,zoom:9}),(new maplibregl.Marker).setLngLat(e).addTo(t)}),w(()=>{t?.remove()}),i`
      <style>#map{height: 180px;width:180px;color:black;border-radius: 15px;margin:10px auto;}</style>
      <style>.maplibregl-ctrl-attrib{display:none;}</style>
      <div id="map"></div>
    `}([t.gps.GPSLongitude.hvalue,t.gps.GPSLatitude.hvalue])}

            ${t.exif&&i`<div class="section">EXIF</div>`}
            ${t.exif&&Object.entries(t.exif).sort((e,t)=>e[0]?.toString().localeCompare(t[0]?.toString())).map(e=>i`
                  <div>${e[0]}: ${e[1].hvalue||e[1].value}</div>
                `)}

          </div>`,400)}const _=f();let S=null;f(()=>{"composition"===_.value?(P(),T(),Kt(),k=!0,btn_info.setAttribute("disabled",!0),btn_histo.setAttribute("disabled",!0),r&&r()):"composition"===S&&(k=!1,btn_info.removeAttribute("disabled"),btn_histo.removeAttribute("disabled"),r=ct(zoomable,pannable)),S=_.value},{effect:!0});let $,k=!1;function E(){0===Object.values(l.trs).reduce((e,t)=>e+t,0)&&0===Object.values(l.crop).reduce((e,t)=>e+t,0)&&0==l.perspective2.modified&&0===l.resizer.width?btn_reset_composition.setAttribute("disabled",!0):btn_reset_composition.removeAttribute("disabled")}const M=f(!1);function L(e){e?.stopPropagation(),k||(M.value?M.value=!1:M.value=!0)}function T(){M.value=!1}let B;const I=f(!1);function P(){I.value=!1}function U(e){B=e}async function F(){await A(e=>i`
          <div style="position:relative;height:250px;overflow:auto;">
            <img id="snail.jpg" @click="${D}" style="cursor:pointer;position:absolute;top:50px;left:20px;border-radius:10px;" src="/samples/snail-8577681_1280.jpg" title="jpg" width=130>
            <img id="seagull.png" @click="${D}" style="cursor:pointer;position:absolute;top:50px;left:160px;border-radius:10px;" src="/samples/seagull-8547189_1280.png" title="png" width=150>
            <img id="water.jpg" @click="${D}" style="cursor:pointer;position:absolute;top:145px;left:160px;border-radius:10px;" src="/samples/water-8100724_1280.jpg" title="jpg" width=150>
            <img id="perspective.jpg" @click="${D}" style="cursor:pointer;position:absolute;top:50px;left:320px;border-radius:10px;" src="/samples/perspective2.jpg" title="jpg" width=137>
          </div>
      `,460)}function D(){c(this.src,this.id),root.lastElementChild.remove()}return i`
  <div class="minieditor">
    <div class="app" >


      /******** LOADING PAGE ********/
      ${()=>!a.value&&!e.data&&i`
        <div class="main" style="justify-content: center;">
            <img src="" width=130 alt="logo"/>
            <h1> ${R("appname")} </h1>
            <div>
              ${Ft("click or drop<br> to load file","image/*",e=>dt(e,u),"height: 120px;")}
              ${o&&i`<button style="height: 80px;width:80px;" @click="${F}">sample images</button>`}
            </div>
            <div style="font-size:13px;color:gray;margin-top:20px;"><i>100% private and offline!</i></div>
        </div>
      `}

      /******** IMGEDITOR PAGE ********/
      ${()=>a.value&&i`

        ${e?'<div class="header" style="backdrop-filter: unset;"></div>':i`
          <div class="header">
            <div class="banner">
              <img src="" width=30 alt="logo"/> ${R("appname")}
            </div>
            <div></div>
            <div style="display:flex;">
              <div class="btn_fullscreen">${()=>function(e=null){return At(window.navigator).apple.phone?i`<div></div>`:(e&&document.addEventListener("fullscreenchange",function(t){document.fullscreenElement?e&&e(!0):e&&e(!1)}),i`
    <div><a @click="${async function(){document.fullscreenElement?document.exitFullscreen&&await document.exitFullscreen():await document.documentElement.requestFullscreen()}}">\u26F6</a></div>
  `)}(null)}</div>
              <div class="btn_theme">${()=>ht("dark",!0)}</div>
            </div>
          </div>
        `}

        <div class="main">

            <div class="container">

              <div id="editor" class="editor">
                <div id="zoomable" @dblclick="${g}" @click="${x}">
                  <div id="pannable">

                    /******** PAINT CANVAS *******/
                    <canvas :ref="${s}" id="canvas" class="checkered"></canvas>

                    /******** SPLIT VIEW *******/
                    ${()=>I.value&&Ut(void 0,canvas.style.width,canvas.style.height,B,U)}                    
                    
                    /******** CROP CANVAS *******/
                    ${()=>"composition"===_.value&&function(e,t,n){const r=t.crop;t.trs;const o=f(!0);b(()=>{_(r.currentcrop),crop.addEventListener("pointerdown",y)}),w(()=>{crop.removeEventListener("pointerdown",y)});let a,s,l,c,u,d,p,h=!1;const v=50,g=100;function m(e){h=!1,crop.releasePointerCapture(e.pointerId),crop.removeEventListener("pointermove",C),crop.removeEventListener("pointerup",m),x(),r.currentcrop=p,n&&n(p)}function x(){p=croprect.getBoundingClientRect();const{offsetTop:e,offsetLeft:t,offsetHeight:n,offsetWidth:r}=croprect;p={...JSON.parse(JSON.stringify(p)),offsetTop:e,offsetLeft:t,offsetHeight:n,offsetWidth:r},p.offsetBottom=d.height-e-n,p.offsetRight=d.width-t-r}function y(e){h=!0,crop.setPointerCapture(e.pointerId),crop.addEventListener("pointermove",C),crop.addEventListener("pointerup",m),r.ar?(croprect.style.aspectRatio=r.ar,o.value=!1):(croprect.style.aspectRatio="",o.value=!0),a={x:e.x,y:e.y},d=crop.getBoundingClientRect(),x();const t=e=>e>=0&&e<=v;s=t(a.x-p.left+10),l=t(p.right-a.x+10),c=t(a.y-p.top+10),u=t(p.bottom-a.y+10),croprect.style.top=croprect.offsetTop+"px",croprect.style.bottom=d.height-croprect.offsetTop-croprect.offsetHeight+"px",croprect.style.left=croprect.offsetLeft+"px",croprect.style.right=d.width-croprect.offsetLeft-croprect.offsetWidth+"px"}function C(e){if(h){let t=function(e,t,n){return Math.max(e,Math.min(t,n))},n=e.x-a.x,r=e.y-a.y,i=croprect.style.aspectRatio;const o=i.split("/")[0]/i.split("/")[1];c&&(i?(l||s)&&(croprect.style.top="auto",croprect.style.bottom=d.height-croprect.offsetTop-croprect.offsetHeight+"px"):croprect.style.top=t(0,p.offsetTop+r,p.offsetTop+p.offsetHeight-g)+"px"),u&&(i?(l||s)&&(croprect.style.top=croprect.offsetTop+"px",croprect.style.bottom="auto"):croprect.style.bottom=t(0,p.offsetBottom-r,p.offsetBottom+p.offsetHeight-g)+"px"),s&&(croprect.style.left=i?c?t(Math.max(0,d.width-p.offsetRight-(p.offsetTop+p.offsetHeight)*o),p.offsetLeft+n,p.offsetLeft+p.offsetWidth-g)+"px":t(Math.max(0,d.width-p.offsetRight-(d.height-p.offsetTop)*o),p.offsetLeft+n,p.offsetLeft+p.offsetWidth-g)+"px":t(0,p.offsetLeft+n,p.offsetLeft+p.offsetWidth-g)+"px"),l&&(croprect.style.right=i?c?t(Math.max(0,d.width-p.offsetLeft-(p.offsetTop+p.offsetHeight)*o),p.offsetRight-n,p.offsetRight+p.offsetWidth-g)+"px":t(Math.max(0,d.width-p.offsetLeft-(d.height-p.offsetTop)*o),p.offsetRight-n,p.offsetRight+p.offsetWidth-g)+"px":t(0,p.offsetRight-n,p.offsetRight+p.offsetWidth-g)+"px"),c||u||s||l||(croprect.style.top=t(0,p.offsetTop+r,d.height-p.offsetHeight)+"px",croprect.style.bottom=t(0,p.offsetBottom-r,d.height-p.offsetHeight)+"px",croprect.style.left=t(0,p.offsetLeft+n,d.width-p.offsetWidth)+"px",croprect.style.right=t(0,p.offsetRight-n,d.width-p.offsetWidth)+"px")}}function _(t){const i=document.getElementById("crop");if(i.style.width=Math.round(e.offsetWidth)+"px",i.style.height=Math.round(e.offsetHeight)+"px",r.ar?croprect.style.aspectRatio=r.ar:croprect.style.aspectRatio="",t){const e=t;croprect.style.inset=`${e.offsetTop}px ${e.offsetRight}px ${e.offsetBottom}px ${e.offsetLeft}px`}else croprect.style.inset="0",r.currentcrop=0;n&&n(t||0)}let S=0;return i`
      <div id="crop" @dblclick="${()=>_()}" @click="${function(e){if(e.preventDefault(),S&&Date.now()-S<200)return _();S=Date.now()}}" style="width:${e?.offsetWidth}px;height:${e?.offsetHeight}px">
       <div id="croprect" style="inset:0;">
          <div class="cropcorner" id="top_left" ></div>
          <div class="cropcorner" id="top_right" ></div>
          <div class="cropcorner" id="bottom_left" ></div>
          <div class="cropcorner" id="bottom_right" ></div>
          ${()=>o.value&&i`
            <div class="cropcorner" id="left" ></div>
            <div class="cropcorner" id="right" ></div>
            <div class="cropcorner" id="top" ></div>
            <div class="cropcorner" id="bottom" ></div>
          `}
        </div>
      </div>
  `}(canvas,l,E)}


                  </div>
                </div>
              </div>

              <div class="sidebar" @click="${y}">

                <div class="menubuttons">
                  ${!e?.data&&i`
                    <div style="display: flex;align-items: center;justify-content: center;">
                      ${Ft("open","image/*",e=>dt(e,u),"width:105px;height:30px;")}
                    </div>
                  `}
                  <div style="display: flex;align-items: center;justify-content: center;">
                    <button style="width:70px;height:30px;fill:white;" id="btn_info" @click="${C}" title="file info"><div style="scale:0.35;margin-top: -15px;">${'<svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">\r\n  <path d="M10 3a7 7 0 100 14 7 7 0 000-14zm-9 7a9 9 0 1118 0 9 9 0 01-18 0zm8-4a1 1 0 011-1h.01a1 1 0 110 2H10a1 1 0 01-1-1zm.01 8a1 1 0 102 0V9a1 1 0 10-2 0v5z"/>\r\n</svg>'}</div></button>
                    <button style="width:70px;height:30px;fill:white;" id="btn_histo" @click="${L}" :selected="${()=>M.value}" tile="histogram"><div style="scale:0.4;margin-top: -15px;">${'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">\r\n<path fill-rule="evenodd" clip-rule="evenodd" d="M12 6C12 5.44772 11.5523 5 11 5C10.4477 5 10 5.44772 10 6V16C10 16.5523 10.4477 17 11 17C11.5523 17 12 16.5523 12 16V6ZM9 9C9 8.44772 8.55228 8 8 8C7.44772 8 7 8.44772 7 9V16C7 16.5523 7.44772 17 8 17C8.55228 17 9 16.5523 9 16V9ZM15 9C15 8.44772 14.5523 8 14 8C13.4477 8 13 8.44772 13 9V16C13 16.5523 13.4477 17 14 17C14.5523 17 15 16.5523 15 16V9ZM18 13C18 12.4477 17.5523 12 17 12C16.4477 12 16 12.4477 16 13V16C16 16.5523 16.4477 17 17 17C17.5523 17 18 16.5523 18 16V13ZM6 15C6 14.4477 5.55228 14 5 14C4.44772 14 4 14.4477 4 15V16C4 16.5523 4.44772 17 5 17C5.55228 17 6 16.5523 6 16V15ZM21 15C21 14.4477 20.5523 14 20 14C19.4477 14 19 14.4477 19 15V16C19 16.5523 19.4477 17 20 17C20.5523 17 21 16.5523 21 16V15ZM4 18C3.44772 18 3 18.4477 3 19C3 19.5523 3.44772 20 4 20H21C21.5523 20 22 19.5523 22 19C22 18.4477 21.5523 18 21 18H4Z"/>\r\n</svg>'}</div></button>
                  </div>
                </div>
                <div class="menusections">

                  /******** COMPOSITION *******/
                  ${zt(_,l,d,()=>n,Kt)}

                  /******** PERSPECTIVE *******/

                  /******** ADJUSTMENTS *******/
                  ${jt(_,l,d)}

                  /******** COLOR CURVE *******/
                  ${Xt(_,l,d)}

                  /******** FILTERS *******/
                  ${Ht(_,l,d,e?.assetBase)}

                  /******** BLUR *******/
                  ${Yt(_,l,d)}

                  /******** PRESETS *******/
                  ${Zt(_,l,h,v,e?.presets)}

                </div>

                ${!!e?.data&&i`
                <div class="sr_mpe_actions">
                <sr-button clean="" class="sr--cta sr--cta--big sr--mr--10" data-action="B.popUp.hide">Cancel</sr-button>
                  <sr-button primary class="sr--cta sr--cta--big" id="btn_download" data-action="B.imgEditor.save">Save and Replace</sr-button>
                </div>
                `}

              </div>
            </div>

            /******** HISTOGRAM *******/
            ${()=>M.value&&Pt(a._value.colorspace,e=>{$=e,d()})}

        </div>
      `}

    </div>
  </div>
  `},e.centerCanvas=Kt,e.render=L,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),e}({});