@codingfactory/mediables-vue 2.11.0 → 2.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{PixiFrameExporter-D9swI3PO.js → PixiFrameExporter-BUVwcHDX.js} +2 -2
- package/dist/{PixiFrameExporter-D9swI3PO.js.map → PixiFrameExporter-BUVwcHDX.js.map} +1 -1
- package/dist/{PixiFrameExporter-apC6SqIv.cjs → PixiFrameExporter-Cqb0nLT4.cjs} +2 -2
- package/dist/{PixiFrameExporter-apC6SqIv.cjs.map → PixiFrameExporter-Cqb0nLT4.cjs.map} +1 -1
- package/dist/composables/useImageEditorModal.d.ts +30 -0
- package/dist/{editor-CYj5y5bp.js → editor-Bj9-m03S.js} +1180 -941
- package/dist/editor-Bj9-m03S.js.map +1 -0
- package/dist/editor-DaM6IN3r.cjs +2 -0
- package/dist/editor-DaM6IN3r.cjs.map +1 -0
- package/dist/{index-BFYtEc-Y.js → index-BXf0oOKg.js} +3945 -3903
- package/dist/index-BXf0oOKg.js.map +1 -0
- package/dist/{index-CAPdRZVb.cjs → index-DyZIdWLm.cjs} +23 -23
- package/dist/index-DyZIdWLm.cjs.map +1 -0
- package/dist/mediables-vanilla.cjs +1 -1
- package/dist/mediables-vanilla.mjs +1 -1
- package/dist/mediables-vue.cjs +1 -1
- package/dist/mediables-vue.mjs +2 -2
- package/dist/style.css +1 -1
- package/dist/types/editor.d.ts +8 -0
- package/package.json +1 -1
- package/dist/editor-BTwIhrcA.cjs +0 -2
- package/dist/editor-BTwIhrcA.cjs.map +0 -1
- package/dist/editor-CYj5y5bp.js.map +0 -1
- package/dist/index-BFYtEc-Y.js.map +0 -1
- package/dist/index-CAPdRZVb.cjs.map +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var st=Object.defineProperty;var at=(s,e,t)=>e in s?st(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var oe=(s,e,t)=>at(s,typeof e!="symbol"?e+"":e,t);const ot=require("pixi-filters"),nt=require("pixi.js");function Ee(s){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const i=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(e,t,i.get?i:{enumerable:!0,get:()=>s[t]})}}return e.default=s,Object.freeze(e)}const y=Ee(ot),T=Ee(nt);class G{constructor(){this._events=new Map}on(e,t){return this._events.has(e)||this._events.set(e,new Set),this._events.get(e).add(t),()=>this.off(e,t)}off(e,t){const i=this._events.get(e);i&&i.delete(t)}emit(e,...t){const i=this._events.get(e);i&&i.forEach(r=>{try{r(...t)}catch{}})}once(e,t){const i=(...r)=>{this.off(e,i),t(...r)};return this.on(e,i)}removeAllListeners(e){e?this._events.delete(e):this._events.clear()}}class lt extends G{constructor(){super(),this._state={hasImage:!1,imageUrl:null,mode:"filters",zoom:1,fitScale:1,activeFilters:new Set,filterValues:{},selectedFilter:null,selectedCategory:"adjust",crop:{shape:"free",aspect:"free",rect:null,dirty:!1},transform:{rotation:0},theme:"auto",isDarkMode:!1,isSaving:!1}}get(e){if(e.includes(".")){const t=e.split(".");let i=this._state;for(const r of t){if(i==null)return;i=i[r]}return i}return this._state[e]}set(e,t){const i=this.get(e);if(e.includes(".")){const r=e.split("."),a=r.pop();let o=this._state;for(const n of r)o[n]===void 0&&(o[n]={}),o=o[n];o[a]=t}else this._state[e]=t;this.emit(`change:${e}`,{value:t,old:i}),this.emit("change",{key:e,value:t,old:i})}getAll(){return{...this._state}}getSerializableState(){var i;const e=[];if(this._state.activeFilters)for(const r of this._state.activeFilters){const a=this._state.filterValues[r];e.push({id:r,enabled:!0,values:a?{...a}:{}})}const t=this._state.crop;return{version:1,crop:{rect:t!=null&&t.rect?{...t.rect}:null,aspectRatio:(t==null?void 0:t.aspect)||"free",shape:(t==null?void 0:t.shape)||"free"},transform:{rotation:Number((i=this._state.transform)==null?void 0:i.rotation)||0},filters:e}}toggleFilter(e,t){const i=new Set(this._state.activeFilters);t?i.add(e):(i.delete(e),delete this._state.filterValues[e]),this.set("activeFilters",i)}setFilterValue(e,t,i){this._state.filterValues[e]||(this._state.filterValues[e]={}),this._state.filterValues[e][t]=i,this.emit("change:filterValue",{filterId:e,controlId:t,value:i}),this.emit("change:filterValues",this._state.filterValues)}getFilterValues(e){return this._state.filterValues[e]||{}}initFilterValues(e,t){this._state.filterValues[e]||(this._state.filterValues[e]={}),t.forEach(i=>{i.id in this._state.filterValues[e]||(this._state.filterValues[e][i.id]=i.default)}),this.emit("change:filterValues",this._state.filterValues)}resetFilters(){this._state.activeFilters=new Set,this._state.filterValues={},this._state.selectedFilter=null,this.emit("change:activeFilters",{value:this._state.activeFilters}),this.emit("change:filterValues",this._state.filterValues),this.emit("change:selectedFilter",{value:null}),this.emit("filtersReset")}detectTheme(){if(this._state.theme==="auto"){const e=window.matchMedia("(prefers-color-scheme: dark)").matches;this.set("isDarkMode",e)}else this.set("isDarkMode",this._state.theme==="dark")}}function Ie(){return new lt}class Be extends G{constructor(){super(),this.app=null,this.sprite=null,this.originalTexture=null,this.baseTexture=null,this.fitScale=1,this.zoom=1,this._container=null,this._lastExportDimensions=null,this._mountPromise=null}get isReady(){var e;return!!((e=this.app)!=null&&e.renderer)}_getCssSize(){var r,a,o,n,l,c;const e=(a=(r=this.app)==null?void 0:r.renderer)==null?void 0:a.canvas,t=(e==null?void 0:e.clientWidth)??((n=(o=this.app)==null?void 0:o.screen)==null?void 0:n.width)??0,i=(e==null?void 0:e.clientHeight)??((c=(l=this.app)==null?void 0:l.screen)==null?void 0:c.height)??0;return{w:t,h:i}}render(){var e,t;try{(e=this.app)!=null&&e.renderer&&((t=this.app)!=null&&t.stage)&&this.app.renderer.render(this.app.stage)}catch{}}_waitForNextFrame(e=32){return new Promise(t=>{if(typeof window>"u"){t();return}let i=!1,r=0;const a=()=>{i||(i=!0,window.clearTimeout(r),t())};if(r=window.setTimeout(a,e),typeof window.requestAnimationFrame=="function"){window.requestAnimationFrame(()=>a());return}a()})}getFitScaleFor(e){if(!this.app||!e)return 1;const{w:t,h:i}=this._getCssSize();if(t<=1||i<=1)return 1;let r=Math.min(t/e.width,i/e.height)*.9;return(!Number.isFinite(r)||r<=0)&&(r=1),r}applyViewTransform(e={}){if(!this.app||!this.sprite||!this.originalTexture)return;const t=this.fitScale*this.zoom,{w:i,h:r}=this._getCssSize(),a=e.keepCenter?{x:this.sprite.x+this.sprite.width/2,y:this.sprite.y+this.sprite.height/2}:e.center??{x:i/2,y:r/2};this.sprite.width=this.originalTexture.width*t,this.sprite.height=this.originalTexture.height*t,this.sprite.x=a.x-this.sprite.width/2,this.sprite.y=a.y-this.sprite.height/2,this.render()}setZoom(e,t={}){this.zoom=Math.max(.1,Math.min(8,e)),this.applyViewTransform({keepCenter:t.keepCenter??!0}),this.emit("zoomChange",this.zoom)}fitToScreen(){this.originalTexture&&(this.fitScale=this.getFitScaleFor(this.originalTexture),this.setZoom(1,{keepCenter:!1}))}async mount(e,t=16777215,i={}){if(!e)return;this._container=e;const r=async()=>{var d;const a=window.PIXI;if(!a)throw new Error("PIXI.js not found. Please ensure PIXI is loaded globally.");(d=a.Assets)!=null&&d.setPreferences&&a.Assets.setPreferences({crossOrigin:"anonymous"});const o=e.clientWidth||600,n=e.clientHeight||400,l=typeof i.backgroundAlpha=="number"?i.backgroundAlpha:1;this.app=new a.Application,await this.app.init({width:o,height:n,backgroundColor:t,backgroundAlpha:l,antialias:!0,autoDensity:!0,resolution:window.devicePixelRatio||1}),e.appendChild(this.app.canvas);const c=this.app.canvas;c.classList.add("pixi-canvas"),c.style.width="100%",c.style.height="100%",c.style.transform="translateZ(0)",c.style.willChange="transform",c.setAttribute("role","img"),c.setAttribute("aria-label","Image editor canvas — use toolbar controls to edit the image"),this.emit("mounted",{width:o,height:n})};this._mountPromise=r(),await this._mountPromise}async loadTexture(e){var l,c,d;if(this._mountPromise&&await this._mountPromise,!((l=this.app)!=null&&l.renderer))return!1;const t=window.PIXI,i=await this._loadImageElement(e);if(!i||!((c=this.app)!=null&&c.renderer))return!1;const r=t.Texture.from(i);if(!r)return!1;this.originalTexture=r,this.baseTexture=r,this.sprite&&(this.app.stage.removeChild(this.sprite),this.sprite.destroy()),this.sprite=new t.Sprite(r),this.app.stage.addChild(this.sprite),this.fitScale=this.getFitScaleFor(r),this.zoom=1;const{w:a,h:o}=this._getCssSize();if(this.applyViewTransform({center:{x:a/2,y:o/2}}),await this._waitForNextFrame(),!((d=this.app)!=null&&d.renderer))return!1;const n=this.getFitScaleFor(r);return Math.abs(n-this.fitScale)/Math.max(1e-6,n)>.02&&(this.fitScale=n,this.applyViewTransform({center:{x:a/2,y:o/2}})),this.render(),this.emit("textureLoaded",{width:r.width,height:r.height}),!0}_normalizeDegrees(e){if(!Number.isFinite(e))return 0;const t=e%360;return t<0?t+360:t}getRotatedBounds(e,t,i){const r=this._normalizeDegrees(i);if(r===0)return{width:Math.max(1,Math.round(e)),height:Math.max(1,Math.round(t))};const a=r*Math.PI/180,o=Math.abs(Math.cos(a)),n=Math.abs(Math.sin(a)),l=o<1e-10?0:o,c=n<1e-10?0:n;return{width:Math.max(1,Math.ceil(e*l+t*c)),height:Math.max(1,Math.ceil(e*c+t*l))}}rotateBy(e){var g,x,P;const t=this._normalizeDegrees(e);if(t===0)return!0;if(!((g=this.app)!=null&&g.renderer)||!this.originalTexture||!this.sprite)return!1;const i=window.PIXI,r=Math.round(this.originalTexture.width),a=Math.round(this.originalTexture.height);if(r<=0||a<=0)return!1;const{width:o,height:n}=this.getRotatedBounds(r,a,t),l=t*Math.PI/180,c=new i.Container,d=new i.Sprite(this.originalTexture);(P=(x=d.anchor)==null?void 0:x.set)==null||P.call(x,.5),d.x=o/2,d.y=n/2,d.rotation=l,c.addChild(d);const h=i.RenderTexture.create({width:o,height:n,resolution:1});try{this.app.renderer.render({container:c,target:h,clear:!0,clearColor:[0,0,0,0]})}catch{return h.destroy(!0),!1}finally{c.removeChildren(),d.destroy({children:!1,texture:!1,textureSource:!1}),c.destroy({children:!1})}const u=this.originalTexture,p=Array.isArray(this.sprite.filters)?[...this.sprite.filters]:null;u&&u!==this.baseTexture&&u.destroy(!0),this.originalTexture=h,this._lastExportDimensions=null,this.app.stage.removeChild(this.sprite),this.sprite.destroy({children:!1,texture:!1,textureSource:!1});const b=new i.Sprite(h);return p!=null&&p.length&&(b.filters=p),this.app.stage.addChild(b),this.sprite=b,this.fitScale=this.getFitScaleFor(h),this.zoom=1,this.applyViewTransform({keepCenter:!1}),this.render(),this.emit("textureRotated",{width:o,height:n,degrees:t}),!0}exportImage(e="png",t=.92,i=0,r=!0,a=0){var E;if(!((E=this.app)!=null&&E.renderer)||!this.originalTexture||!this.sprite)return null;const o=window.PIXI,n=Math.round(this.originalTexture.width),l=Math.round(this.originalTexture.height);if(n<=0||l<=0)return null;const c=this.sprite.width,d=this.sprite.height;if(c<=0||d<=0)return null;const h=c/n,u=h>0?1/h:1,p=[];if(Array.isArray(this.sprite.filters)){for(const _ of this.sprite.filters)if(_)if(typeof _.createExportFilter=="function"){const C=_.createExportFilter({previewToNativeScale:u});C&&p.push(C)}else p.push(_)}let b=0;for(const _ of p){const C=typeof _.getExportPadding=="function"?Number(_.getExportPadding())||0:typeof _._exportPadding=="number"?_._exportPadding:typeof _.padding=="number"?_.padding:0;C>0&&(b+=C)}const g=Math.max(Math.ceil(b),64),x=_=>{var F,w;const C=Math.ceil(n+2*_),M=Math.ceil(l+2*_),k=new o.Container,A=new o.Sprite(this.originalTexture);A.x=_,A.y=_,A.scale.set(1,1),p.length>0&&(A.filters=p,A.filterArea=new o.Rectangle(0,0,n,l)),k.addChild(A);const B=o.RenderTexture.create({width:C,height:M,resolution:1});try{this.app.renderer.render({container:k,target:B,clear:!0,clearColor:[0,0,0,0]});const S=(w=(F=this.app.renderer.extract)==null?void 0:F.canvas)==null?void 0:w.call(F,B);return S?{canvas:S,width:C,height:M,margin:_}:null}finally{A.filters=null,k.removeChildren(),A.destroy({children:!1,texture:!1,textureSource:!1}),k.destroy({children:!1}),B.destroy(!0)}},P=(_,C,M)=>{const k=typeof _.getContext=="function"?_.getContext("2d"):null;if(!k)return null;let A;try{A=k.getImageData(0,0,C,M).data}catch{return null}const B=1;let F=C,w=M,S=-1,Q=-1;const ye=4,Je=C*ye;for(let Y=0;Y<M;Y++){const rt=Y*Je;for(let D=0;D<C;D++)A[rt+D*ye+3]>=B&&(D<F&&(F=D),D>S&&(S=D),Y<w&&(w=Y),Y>Q&&(Q=Y))}if(S<0)return null;const et=S-F+1,tt=Q-w+1,it=F===0||w===0||S===C-1||Q===M-1;return{x:F,y:w,width:et,height:tt,touchesEdge:it}};let v=null;try{let _=x(g);if(!_)return null;let C=P(_.canvas,_.width,_.height);if(!C)return null;if(C.touchesEdge&&g<n&&g<l){const F=Math.max(g*4,256),w=x(F);if(w){const S=P(w.canvas,w.width,w.height);S&&!S.touchesEdge?(_=w,C=S):(_=w,C=S??C)}}let M=C.width,k=C.height;if(i>0){const F=Math.max(M,k);let w=i/F;r&&(w=Math.min(1,w)),M=Math.max(1,Math.round(M*w)),k=Math.max(1,Math.round(k*w))}if(a>0&&M*k>a){const F=Math.sqrt(a/(M*k));M=Math.max(1,Math.floor(M*F)),k=Math.max(1,Math.floor(k*F))}const A=document.createElement("canvas");A.width=M,A.height=k;const B=A.getContext("2d");return B?(B.drawImage(_.canvas,C.x,C.y,C.width,C.height,0,0,M,k),v=A.toDataURL(`image/${e}`,t),this._lastExportDimensions={width:M,height:k},v||null):null}catch{return null}}getExportDimensions(){var o;if(this._lastExportDimensions)return{...this._lastExportDimensions};const e=this.originalTexture,t=Math.round((e==null?void 0:e.width)||0),i=Math.round((e==null?void 0:e.height)||0);let r=0;const a=(o=this.sprite)==null?void 0:o.filters;if(Array.isArray(a))for(const n of a){if(!n)continue;const l=typeof n._exportPadding=="number"?n._exportPadding:typeof n.padding=="number"?n.padding:0;l>r&&(r=l)}return{width:t+2*r,height:i+2*r}}async exportBlob(e="png",t=.92){const i=this.exportImage(e,t);if(!i)return null;const a=await(await fetch(i)).blob(),o=this.getExportDimensions();return{blob:a,width:o.width,height:o.height}}resizeTo(e){var r;if(!((r=this.app)!=null&&r.renderer)||!e)return;const t=e.clientWidth,i=e.clientHeight;if(!(t===Math.round(this.app.screen.width)&&i===Math.round(this.app.screen.height))&&!(t<=0||i<=0)&&(this.app.renderer.resize(t,i),this.originalTexture&&this.sprite)){const a={x:this.sprite.x+this.sprite.width/2,y:this.sprite.y+this.sprite.height/2};this.fitScale=this.getFitScaleFor(this.originalTexture),this.applyViewTransform({center:a})}}setBackgroundColor(e){var t,i;(i=(t=this.app)==null?void 0:t.renderer)!=null&&i.background&&(this.app.renderer.background.color=e)}_loadImageElement(e){return new Promise(t=>{const i=new Image;typeof e=="string"&&/^https?:\/\//.test(e)&&(i.crossOrigin="anonymous"),i.onload=()=>t(i),i.onerror=()=>{t(null)},i.src=e})}destroy(){if(this._mountPromise=null,this.app){try{this.app.destroy(!0,{children:!0,texture:!0})}catch{}this.app=null}this.sprite=null,this.originalTexture=null,this.baseTexture=null,this._container=null,this.removeAllListeners()}}const de='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="48" d="M328 112L184 256l144 144"/></svg>',ue='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="48" d="M184 112l144 144-144 144"/></svg>',ct='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M221.09 64a157.09 157.09 0 10157.09 157.09A157.1 157.1 0 00221.09 64z"/><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M338.29 338.29L448 448M256 184v74m-37-37h74"/></svg>',ht='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M221.09 64a157.09 157.09 0 10157.09 157.09A157.1 157.1 0 00221.09 64z"/><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M338.29 338.29L448 448M184 221h74"/></svg>',dt='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M432 320v112H320M80 192V80h112M320 80h112v112M192 432H80V320"/></svg>',ut='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M262.29 192.31a64 64 0 1057.4 57.4 64.13 64.13 0 00-57.4-57.4z"/><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M416.39 256a154.34 154.34 0 01-1.53 20.79l45.21 35.46a10.81 10.81 0 012.45 13.75l-42.77 74a10.81 10.81 0 01-13.14 4.59l-44.9-18.08a16.11 16.11 0 00-15.17 1.75A164.48 164.48 0 01325 400.8a15.94 15.94 0 00-8.82 12.14l-6.73 47.89a11.08 11.08 0 01-10.68 9.17h-85.54a11.11 11.11 0 01-10.69-8.87l-6.72-47.82a16.07 16.07 0 00-9-12.22 155.3 155.3 0 01-21.46-12.57 16 16 0 00-15.11-1.71l-44.89 18.07a10.81 10.81 0 01-13.14-4.58l-42.77-74a10.8 10.8 0 012.45-13.75l38.21-30a16.05 16.05 0 006-14.08c-.36-4.17-.58-8.33-.58-12.5s.21-8.27.58-12.35a16 16 0 00-6.07-13.94l-38.19-30A10.81 10.81 0 0149.48 186l42.77-74a10.81 10.81 0 0113.14-4.59l44.9 18.08a16.11 16.11 0 0015.17-1.75A164.48 164.48 0 01187 111.2a15.94 15.94 0 008.82-12.14l6.73-47.89A11.08 11.08 0 01213.23 42h85.54a11.11 11.11 0 0110.69 8.87l6.72 47.82a16.07 16.07 0 009 12.22 155.3 155.3 0 0121.46 12.57 16 16 0 0015.11 1.71l44.89-18.07a10.81 10.81 0 0113.14 4.58l42.77 74a10.8 10.8 0 01-2.45 13.75l-38.21 30a16.05 16.05 0 00-6.05 14.08c.33 4.14.55 8.3.55 12.47z"/></svg>',pt='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M400 320c0 88.37-55.63 144-144 144s-144-55.63-144-144c0-94.83 103.23-222.85 134.89-259.88a12 12 0 0118.23 0C296.77 97.15 400 225.17 400 320z"/><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M344 328a72 72 0 01-72 72"/></svg>',ft='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-miterlimit="10" stroke-width="32" d="M430.11 347.9c-6.6-6.1-16.3-7.6-24.6-9-11.5-1.9-15.9-4-22.6-10-14.3-12.7-14.3-31.1 0-43.8l30.3-26.9c46.4-41 46.4-108.2 0-149.2-34.2-30.1-80.1-45-127.8-45-55.7 0-113.9 20.3-158.8 60.1-83.5 73.8-83.5 194.7 0 268.5 41.5 36.7 97.5 55 152.9 55.4h1.7c55.4 0 110-17.9 148.8-52.4 14.4-12.7 11.99-36.6.1-47.7z"/><circle cx="144" cy="208" r="32"/><circle cx="152" cy="311" r="32"/><circle cx="224" cy="144" r="32"/><circle cx="256" cy="367" r="32"/><circle cx="328" cy="144" r="32"/></svg>',mt='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M259.92 262.91L216.4 149.77a9 9 0 00-16.8 0l-43.52 113.14a9 9 0 01-5.17 5.17L37.77 311.6a9 9 0 000 16.8l113.14 43.52a9 9 0 015.17 5.17l43.52 113.14a9 9 0 0016.8 0l43.52-113.14a9 9 0 015.17-5.17l113.14-43.52a9 9 0 000-16.8l-113.14-43.52a9 9 0 01-5.17-5.17zM108 68L88 16 68 68 16 88l52 20 20 52 20-52 52-20-52-20zM426.67 117.33L400 48l-26.67 69.33L304 144l69.33 26.67L400 240l26.67-69.33L496 144l-69.33-26.67z"/></svg>',gt='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M176 112l80-80 80 80M255.98 32l.02 448M176 400l80 80 80-80M400 176l80 80-80 80M112 176l-80 80 80 80M32 256h448"/></svg>',bt='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M315.27 33L96 304h128l-31.51 173.23a2.36 2.36 0 002.33 2.77h0a2.36 2.36 0 001.89-.95L416 208H288l31.66-173.25a2.45 2.45 0 00-2.44-2.75h0a2.42 2.42 0 00-1.95 1z"/></svg>',Xe='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M144 48v272a48 48 0 0048 48h272"/><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M368 464V192a48 48 0 00-48-48H48"/></svg>',yt='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M380.93 57.37A32 32 0 00358.3 48H94.22A46.21 46.21 0 0048 94.22v323.56A46.21 46.21 0 0094.22 464h323.56A46.36 46.36 0 00464 417.78V153.7a32 32 0 00-9.37-22.63zM256 416a64 64 0 1164-64 63.92 63.92 0 01-64 64zm48-224H112a16 16 0 01-16-16v-64a16 16 0 0116-16h192a16 16 0 0116 16v64a16 16 0 01-16 16z"/></svg>',se='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M368 368L144 144M368 144L144 368"/></svg>',Oe='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M320 146s24.36-12-64-12a160 160 0 10160 160"/><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M256 58l80 80-80 80"/></svg>',_t='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M176 112l-64 64 64 64"/><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M112 176h176a112 112 0 110 224H160"/></svg>',xt='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M336 112l64 64-64 64"/><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M400 176H224a112 112 0 100 224h128"/></svg>',Ct='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M112 112l20 320c.95 18.49 14.4 32 32 32h184c17.67 0 30.87-13.51 32-32l20-320"/><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="32" d="M80 112h352"/><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M192 112V72h0a23.93 23.93 0 0124-24h80a23.93 23.93 0 0124 24h0v40M256 176v224M184 176l8 224M328 176l-8 224"/></svg>',wt='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M64 192v-72a40 40 0 0140-40h75.89a40 40 0 0122.19 6.72l27.84 18.56a40 40 0 0022.19 6.72H408a40 40 0 0140 40v40"/><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M479.9 226.55L463.68 392a40 40 0 01-39.93 40H88.25a40 40 0 01-39.93-40L32.1 226.55A32 32 0 0164 192h384.1a32 32 0 0131.8 34.55z"/></svg>',ie='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M416 128L192 384l-96-96"/></svg>',St='<svg viewBox="0 0 512 512" width="20" height="20"><rect x="64" y="64" width="384" height="384" rx="48" fill="none" stroke="currentColor" stroke-linejoin="round" stroke-width="32"/></svg>',vt='<svg viewBox="0 0 512 512" width="20" height="20"><circle cx="256" cy="256" r="208" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"/></svg>',Mt='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M80 96h64l64 320h64l64-160h96"/></svg>',_e='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="32" d="M256 48v48M256 416v48M403.08 108.92l-33.94 33.94M142.86 369.14l-33.94 33.94M464 256h-48M96 256H48M403.08 403.08l-33.94-33.94M142.86 142.86l-33.94-33.94"/><circle cx="256" cy="256" r="80" fill="none" stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="32"/></svg>',xe='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M160 136c0-30.62 4.51-61.61 16-88C99.57 81.27 48 159.32 48 248c0 119.29 96.71 216 216 216 88.68 0 166.73-51.57 200-128-26.39 11.49-57.38 16-88 16-119.29 0-216-96.71-216-216z"/></svg>',kt='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M436 80H76a44.05 44.05 0 00-44 44v264a44.05 44.05 0 0044 44h360a44.05 44.05 0 0044-44V124a44.05 44.05 0 00-44-44z"/><circle cx="256" cy="256" r="80" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"/><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M220 80v56M292 80v56M220 376v56M292 376v56M80 144h56M80 224h56M80 304h56M376 144h56M376 224h56M376 304h56"/></svg>',ae=[{id:"adjust",name:"Adjust",icon:ut,registryCategories:["adjust","advanced"]},{id:"blur",name:"Blur",icon:pt,registryCategories:["blur"]},{id:"color",name:"Color",icon:ft,registryCategories:["color"]},{id:"effects",name:"Effects",icon:mt,registryCategories:["effects"]},{id:"distortion",name:"Distortion",icon:gt,registryCategories:["distortion"]},{id:"light",name:"Light",icon:bt,registryCategories:["light"]},{id:"stylize",name:"Stylize",icon:kt,registryCategories:["stylize"]},{id:"crop",name:"Crop",icon:Xe}],Pt=Object.fromEntries(ae.filter(s=>Array.isArray(s.registryCategories)&&s.registryCategories.length>0).map(s=>[s.id,s.registryCategories])),Ye=Object.fromEntries(ae.filter(s=>Array.isArray(s.registryCategories)).flatMap(s=>s.registryCategories.map(e=>[e,s.id])));function Ft(s){return Pt[s]||[s]}class De extends G{constructor(e,t){super(),this.state=e,this.renderer=t,this.instances={},this._filterRegistry=null}setRegistry(e){this._filterRegistry=e}getFilterDef(e){return this._filterRegistry?this._filterRegistry.getFilter(e):null}getAllFilters(){var e;return((e=this._filterRegistry)==null?void 0:e.getAllFilters())||[]}getFiltersByCategory(e){if(!this._filterRegistry)return[];const t=Ft(e),i=[],r=new Set;for(const a of t){const o=this._filterRegistry.getFiltersByCategory(a)||[];for(const n of o)r.has(n.id)||(r.add(n.id),i.push(n))}return i}_normalizeValue(e){return Array.isArray(e)?e.length>0&&typeof e[0]=="object"?e:Number(e[0]??0):typeof e=="string"?e.startsWith("#")?e:e.trim()===""?0:Number(e):e}_getDeepProp(e,t){if(!e||!t)return;if(!t.includes(".")&&!t.includes("["))return e[t];const i=t.replace(/\[(\d+)\]/g,".$1").split(".").filter(Boolean);let r=e;for(const a of i){if(r==null)return;r=r[a]}return r}_setDeepProp(e,t,i){if(!e||!t)return;if(!t.includes(".")&&!t.includes("[")){e[t]=i;return}const r=t.replace(/\[(\d+)\]/g,".$1").split(".").filter(Boolean);let a=e;for(let n=0;n<r.length-1;n++){const l=r[n];if(!(l in a)||(a=a[l],a==null))return}const o=r[r.length-1];a[o]=i}initializeValues(e){const t=this.getFilterDef(e);if(!t)return;const i=this.state.getFilterValues(e),r=new Set((t.controls||[]).map(a=>a.id));if(t.defaultParams)for(const[a,o]of Object.entries(t.defaultParams))!r.has(a)&&!(a in i)&&this.state.setFilterValue(e,a,o);t.controls&&t.controls.forEach(a=>{a.id in i||this.state.setFilterValue(e,a.id,a.default)})}resetValues(e){const t=this.getFilterDef(e);if(!t)return;const i=new Set((t.controls||[]).map(r=>r.id));if(t.defaultParams)for(const[r,a]of Object.entries(t.defaultParams))i.has(r)||this.state.setFilterValue(e,r,a);t.controls&&t.controls.forEach(r=>{this.state.setFilterValue(e,r.id,r.default)})}toggle(e,t){this.state.toggleFilter(e,t),t?this.initializeValues(e):delete this.instances[e],this.applyFilters(),this.emit("filterToggled",{filterId:e,enabled:t})}updateValue(e,t,i){const r=this._normalizeValue(i),a=this.getFilterDef(e),o=a==null?void 0:a.controls.find(h=>h.id===t),n=!o&&(t.includes("[")||t.includes("."));n||this.state.setFilterValue(e,t,r);const l=this.instances[e];if(!l)return!1;const c=(o==null?void 0:o.property)||t;if(typeof l.updateUIParam=="function"){if(l.updateUIParam(c,r),n&&typeof l.getSerializableParams=="function"){const h=l.getSerializableParams();for(const[u,p]of Object.entries(h))this.state.setFilterValue(e,u,p)}return!0}const d=this._getDeepProp(l,c);return typeof d=="function"?!1:l.uniforms&&c in l.uniforms?(l.uniforms[c]=r,!0):d!==void 0?(this._setDeepProp(l,c,r),!0):!1}performFilterAction(e,t){const i=this.instances[e];if(!(!i||typeof i.updateUIParam!="function")){if(i.updateUIParam(t,!0),typeof i.getSerializableParams=="function"){const r=i.getSerializableParams();for(const[a,o]of Object.entries(r))this.state.setFilterValue(e,a,o)}this.applyFilters(),this.emit("filterActionPerformed",{filterId:e,action:t})}}applyFilters(){const e=this.renderer.sprite;if(!e)return;for(const a in this.instances)delete this.instances[a];const t=[],i=[];this.state.get("activeFilters").forEach(a=>{try{const o=this.getFilterDef(a);if(!o||!o.createFilter||typeof o.createFilter!="function")return;const n=this.state.getFilterValues(a),l=o.defaultParams?{...o.defaultParams}:{};o.controls&&Array.isArray(o.controls)&&o.controls.forEach(p=>{const b=p.property||p.id;l[b]=n[p.id]??p.default});const c=new Set((o.controls||[]).map(p=>p.id));for(const[p,b]of Object.entries(n))c.has(p)||(l[p]=b);const d=this.renderer.sprite,h=this.renderer.originalTexture;l._sourceWidth=Math.round((h==null?void 0:h.width)||(d==null?void 0:d.width)||0),l._sourceHeight=Math.round((h==null?void 0:h.height)||(d==null?void 0:d.height)||0);const u=o.createFilter(l);u&&(t.push(u),this.instances[a]=u)}catch{i.push(a)}});try{e.filters=null,e.filters=t.length?t:null,this.renderer.render(),this.emit("filtersApplied",{count:t.length,failed:i})}catch(a){try{e.filters=null,this.renderer.render()}catch{}this.emit("filtersError",{error:a,failedFilters:i})}i.length>0}resetAll(){for(const e in this.instances)delete this.instances[e];this.state.resetFilters(),this.renderer.sprite&&(this.renderer.sprite.filters=null),this.renderer.render(),this.emit("filtersReset")}getInstance(e){return this.instances[e]||null}}const U=class U extends G{constructor(e,t){super(),this.state=e,this.renderer=t,this._overlayCanvas=null,this._isDragging=!1,this._dragStart=null,this._dragMode=null,this._startRect=null,this._hoverMode=null,this._lastAutoZoomCheck=0,this.HANDLE_SIZE=14,this.EDGE_HIT_PAD=10,this._onPointerDown=this._handlePointerDown.bind(this),this._onPointerMove=this._handlePointerMove.bind(this),this._onPointerUp=this._handlePointerUp.bind(this)}setOverlayCanvas(e){this._overlayCanvas=e}_getAspectRatio(e){if(!e||e==="free")return null;const t={"1:1":1,"4:3":4/3,"16:9":16/9,"3:2":3/2,"2:3":2/3};if(t[e]!==void 0)return t[e];const i=e.split(":");if(i.length===2){const r=parseFloat(i[0]),a=parseFloat(i[1]);if(Number.isFinite(r)&&Number.isFinite(a)&&a>0)return r/a}return null}applyAspectRatio(){const e=this.state.get("crop.rect"),t=this.state.get("crop.aspect");if(!e||t==="free")return;const i=this._getAspectRatio(t);if(!i)return;const r=e.width/e.height;Math.abs(r-i)<.01||(r>i?e.width=e.height*i:e.height=e.width/i,this.state.set("crop.rect",e))}constrainCropRect(){const e=this.state.get("crop.rect");if(!e)return;const t=this.renderer.sprite,i=this.renderer.app;if(!t||!i)return;const r=this.state.get("crop.shape"),a={x:0,y:0,w:i.screen.width,h:i.screen.height};if(e.x=Math.max(a.x,Math.min(e.x,a.x+a.w-e.width)),e.y=Math.max(a.y,Math.min(e.y,a.y+a.h-e.height)),e.width=Math.min(e.width,a.w),e.height=Math.min(e.height,a.h),r!=="free"||this.state.get("crop.aspect")==="1:1"){const o=Math.min(e.width,e.height);e.width=o,e.height=o}this.state.set("crop.rect",e)}static calcAutoZoom(e,t,i,r,a,o,n){if(!e||!r||!a||!o)return null;const l=e.width>t,c=e.height>i;if(!l&&!c)return null;const d=U.AUTO_ZOOM_PADDING;let h=n;if(l){const u=e.width/(d*r*o);h=Math.min(h,u)}if(c){const u=e.height/(d*a*o);h=Math.min(h,u)}return h=Math.max(.1,h),h>=n-.01?null:h}_checkAutoZoom(){if(!this.state.get("autoZoomOnCropOverflow"))return;const e=Date.now();if(e-this._lastAutoZoomCheck<U.AUTO_ZOOM_THROTTLE_MS)return;this._lastAutoZoomCheck=e;const t=this.state.get("crop.rect"),i=this.renderer.sprite,r=this.renderer.originalTexture;if(!t||!i||!r)return;const a=U.calcAutoZoom(t,i.width,i.height,r.width,r.height,this.renderer.fitScale,this.renderer.zoom);a!==null&&this.renderer.setZoom(a,{keepCenter:!0})}drawOverlay(){const e=this._overlayCanvas;if(!e)return;const t=this.renderer.app;if(!t)return;const i=t.canvas,r=i.clientWidth,a=i.clientHeight,o=window.devicePixelRatio||1;(e.width!==Math.max(1,Math.floor(r*o))||e.height!==Math.max(1,Math.floor(a*o)))&&(e.width=Math.max(1,Math.floor(r*o)),e.height=Math.max(1,Math.floor(a*o)),e.style.width=r+"px",e.style.height=a+"px");const n=e.getContext("2d");if(!n)return;n.setTransform(o,0,0,o,0,0),n.clearRect(0,0,r,a),n.fillStyle="rgba(0, 0, 0, 0.5)",n.fillRect(0,0,r,a);const l=this.state.get("crop.rect");if(!l)return;const c=this.state.get("crop.shape");if(n.save(),c==="circle"){const x=l.x+l.width/2,P=l.y+l.height/2,v=Math.min(l.width,l.height)/2;n.beginPath(),n.arc(x,P,v,0,Math.PI*2),n.clip()}else n.beginPath(),n.rect(l.x,l.y,l.width,l.height),n.clip();n.clearRect(l.x,l.y,l.width,l.height),n.restore(),n.strokeStyle="#ffffff",n.lineWidth=2,n.setLineDash([5,5]),c==="circle"?(n.beginPath(),n.arc(l.x+l.width/2,l.y+l.height/2,Math.min(l.width,l.height)/2,0,Math.PI*2),n.stroke()):n.strokeRect(l.x,l.y,l.width,l.height),n.setLineDash([]),n.strokeStyle="rgba(255,255,255,0.3)",n.lineWidth=1;const d=l.width/3,h=l.height/3;for(let x=1;x<=2;x++)n.beginPath(),n.moveTo(l.x+d*x,l.y),n.lineTo(l.x+d*x,l.y+l.height),n.stroke(),n.beginPath(),n.moveTo(l.x,l.y+h*x),n.lineTo(l.x+l.width,l.y+h*x),n.stroke();const u=this.HANDLE_SIZE,p=[{x:l.x,y:l.y,m:"resize-nw"},{x:l.x+l.width,y:l.y,m:"resize-ne"},{x:l.x,y:l.y+l.height,m:"resize-sw"},{x:l.x+l.width,y:l.y+l.height,m:"resize-se"}],b=[{x:l.x+l.width/2,y:l.y,m:"n"},{x:l.x+l.width/2,y:l.y+l.height,m:"s"},{x:l.x,y:l.y+l.height/2,m:"w"},{x:l.x+l.width,y:l.y+l.height/2,m:"e"}],g=[...p,...b];for(const x of g){const P=this._hoverMode===x.m,v=P?u+4:u;n.beginPath(),n.rect(x.x-v/2,x.y-v/2,v,v),n.fillStyle=P?"#4da3ff":"#ffffff",n.strokeStyle="rgba(0,0,0,0.6)",n.lineWidth=1,n.fill(),n.stroke()}}_hitHandle(e,t){const i=this.state.get("crop.rect");if(!i)return null;const r=(a,o,n,l,c)=>Math.abs(a-n)<=c&&Math.abs(o-l)<=c;return r(e,t,i.x,i.y,this.HANDLE_SIZE)?"resize-nw":r(e,t,i.x+i.width,i.y,this.HANDLE_SIZE)?"resize-ne":r(e,t,i.x,i.y+i.height,this.HANDLE_SIZE)?"resize-sw":r(e,t,i.x+i.width,i.y+i.height,this.HANDLE_SIZE)?"resize-se":Math.abs(t-i.y)<=this.EDGE_HIT_PAD&&e>=i.x&&e<=i.x+i.width?"n":Math.abs(t-(i.y+i.height))<=this.EDGE_HIT_PAD&&e>=i.x&&e<=i.x+i.width?"s":Math.abs(e-i.x)<=this.EDGE_HIT_PAD&&t>=i.y&&t<=i.y+i.height?"w":Math.abs(e-(i.x+i.width))<=this.EDGE_HIT_PAD&&t>=i.y&&t<=i.y+i.height?"e":e>=i.x&&e<=i.x+i.width&&t>=i.y&&t<=i.y+i.height?"move":null}_handlePointerDown(e){const t=this.state.get("crop.rect");if(!t)return;const i=e.global;this._dragMode=this._hitHandle(i.x,i.y),this._dragMode&&(this._isDragging=!0,this._dragStart={x:i.x,y:i.y},this._startRect={...t},this._lastAutoZoomCheck=0)}_handlePointerMove(e){var l,c,d,h;const t=this.renderer.app;if(!t)return;const i=e.global;if(!this._isDragging||!this._dragStart||!this._startRect){this._hoverMode=this._hitHandle(i.x,i.y),t.stage.cursor=this._hoverMode==="move"?"move":this._hoverMode==="n"||this._hoverMode==="s"?"ns-resize":this._hoverMode==="e"||this._hoverMode==="w"?"ew-resize":(l=this._hoverMode)!=null&&l.endsWith("nw")||(c=this._hoverMode)!=null&&c.endsWith("se")?"nwse-resize":(d=this._hoverMode)!=null&&d.endsWith("ne")||(h=this._hoverMode)!=null&&h.endsWith("sw")?"nesw-resize":"crosshair",this.drawOverlay();return}const r=this.state.get("crop.rect");if(!r)return;const a=i.x-this._dragStart.x,o=i.y-this._dragStart.y;switch(this._dragMode){case"move":r.x=this._startRect.x+a,r.y=this._startRect.y+o;break;case"n":r.y=this._startRect.y+o,r.height=this._startRect.height-o;break;case"s":r.height=this._startRect.height+o;break;case"w":r.x=this._startRect.x+a,r.width=this._startRect.width-a;break;case"e":r.width=this._startRect.width+a;break;case"resize-nw":r.x=this._startRect.x+a,r.y=this._startRect.y+o,r.width=this._startRect.width-a,r.height=this._startRect.height-o;break;case"resize-ne":r.y=this._startRect.y+o,r.width=this._startRect.width+a,r.height=this._startRect.height-o;break;case"resize-sw":r.x=this._startRect.x+a,r.width=this._startRect.width-a,r.height=this._startRect.height+o;break;case"resize-se":r.width=this._startRect.width+a,r.height=this._startRect.height+o;break}r.width=Math.max(50,r.width),r.height=Math.max(50,r.height),this.state.set("crop.rect",r),this.state.set("crop.dirty",!0),this.state.get("crop.shape")==="circle"&&this.state.get("crop.aspect")!=="1:1"&&this.state.set("crop.aspect","1:1"),this.applyAspectRatio(),this._dragMode!=="move"&&this._checkAutoZoom(),this.constrainCropRect(),this.drawOverlay()}_handlePointerUp(){this._isDragging=!1,this._dragMode=null,this._dragStart=null,this._startRect=null}enable(){const e=this.renderer.app,t=this.renderer.sprite;if(!e||!t)return;let i=this.state.get("crop.rect");if(!i){this.state.get("crop.shape")==="circle"&&this.state.set("crop.aspect","1:1");const o=this.state.get("crop.aspect"),n=this._getAspectRatio(o);let l,c;if(n){const u=t.width*.9,p=t.height*.9;u/p>n?(c=p,l=c*n):(l=u,c=l/n)}else{const u=Math.min(e.screen.width,e.screen.height)*.7;l=u,c=u}const d=t.x+(t.width-l)/2,h=t.y+(t.height-c)/2;i={x:d,y:h,width:l,height:c},this.state.set("crop.rect",i),o!=="free"&&this.constrainCropRect()}this.state.set("crop.dirty",!1);const r=e.stage;r.eventMode="static",r.hitArea=e.screen,r.cursor="crosshair",r.on("pointerdown",this._onPointerDown),r.on("pointermove",this._onPointerMove),r.on("pointerup",this._onPointerUp),r.on("pointerupoutside",this._onPointerUp),this.state.set("mode","crop"),this.drawOverlay(),this.emit("enabled")}disable(){const e=this.renderer.app;if(!e)return;const t=e.stage;if(t.off("pointerdown",this._onPointerDown),t.off("pointermove",this._onPointerMove),t.off("pointerup",this._onPointerUp),t.off("pointerupoutside",this._onPointerUp),t.eventMode="auto",t.cursor="default",this.state.set("crop.rect",null),this.state.set("crop.dirty",!1),this._overlayCanvas){const i=this._overlayCanvas.getContext("2d");i==null||i.clearRect(0,0,this._overlayCanvas.width,this._overlayCanvas.height)}this.state.set("mode","filters"),this.emit("disabled")}apply(){const e=this.renderer.app,t=this.renderer.sprite,i=this.renderer.originalTexture,r=this.state.get("crop.rect");if(!r||!t||!e||!i)return null;const a=window.PIXI,o=this.renderer.zoom,n=i.width/t.width,l=i.height/t.height,c=(r.x-t.x)*n,d=(r.y-t.y)*l;let h=Math.round(Math.max(1,r.width*n)),u=Math.round(Math.max(1,r.height*l)),p=Math.round(c),b=Math.round(d);if(h<=0||u<=0)return null;const g=new a.Container,x=new a.Sprite(i);if(this.state.get("crop.shape")==="circle"){const B=Math.round(Math.max(h,u)),F=p+h/2,w=b+u/2;p=Math.round(F-B/2),b=Math.round(w-B/2),h=u=B;const S=new a.Graphics;typeof S.circle=="function"&&typeof S.fill=="function"?S.circle(h/2,u/2,h/2).fill(16777215):(S.beginFill(16777215,1),S.drawCircle(h/2,u/2,h/2),S.endFill()),x.mask=S,g.addChild(S)}x.x=-p,x.y=-b,g.addChild(x);const v=a.RenderTexture.create({width:h,height:u});e.renderer.render({container:g,target:v,clear:!0}),g.destroy({children:!0});const E=this.renderer.originalTexture;E&&E!==this.renderer.baseTexture&&E.destroy(!0),this.renderer.originalTexture=v,e.stage.removeChild(t),t.destroy();const z=new a.Sprite(v);e.stage.addChild(z),this.renderer.sprite=z,this.renderer.fitScale=this.renderer.getFitScaleFor(v),this.renderer.setZoom(o,{keepCenter:!1}),this.renderer.applyViewTransform(),this.renderer.render();const _=this.state.get("crop.appliedRect"),M=_&&Number.isFinite(_.x)&&Number.isFinite(_.y)&&Number.isFinite(_.width)&&Number.isFinite(_.height)?{x:Math.round(_.x+p),y:Math.round(_.y+b),width:h,height:u}:{x:p,y:b,width:h,height:u},k=this.state.get("crop.shape")||"free",A=this.state.get("crop.aspect")||"free";return this.disable(),this.state.set("crop.appliedRect",M),this.state.set("crop.appliedShape",k),this.state.set("crop.appliedAspect",A),this.state.set("crop.dirty",!1),this.emit("applied",{width:h,height:u}),{texture:v,preservedZoom:o}}applyFromPixelRect(e,t="free"){const i=this.renderer.app,r=this.renderer.sprite,a=this.renderer.originalTexture;if(!e||!r||!i||!a)return null;const o=window.PIXI,n=this.renderer.zoom;let l=Math.round(Math.max(1,e.width)),c=Math.round(Math.max(1,e.height)),d=Math.round(e.x),h=Math.round(e.y);if(l<=0||c<=0)return null;const u=new o.Container,p=new o.Sprite(a);if(t==="circle"){const P=Math.round(Math.max(l,c)),v=d+l/2,E=h+c/2;d=Math.round(v-P/2),h=Math.round(E-P/2),l=c=P;const z=new o.Graphics;typeof z.circle=="function"&&typeof z.fill=="function"?z.circle(l/2,c/2,l/2).fill(16777215):(z.beginFill(16777215,1),z.drawCircle(l/2,c/2,l/2),z.endFill()),p.mask=z,u.addChild(z)}p.x=-d,p.y=-h,u.addChild(p);const b=o.RenderTexture.create({width:l,height:c});i.renderer.render({container:u,target:b,clear:!0}),u.destroy({children:!0});const g=this.renderer.originalTexture;g&&g!==this.renderer.baseTexture&&g.destroy(!0),this.renderer.originalTexture=b,i.stage.removeChild(r),r.destroy();const x=new o.Sprite(b);return i.stage.addChild(x),this.renderer.sprite=x,this.renderer.fitScale=this.renderer.getFitScaleFor(b),this.renderer.setZoom(n,{keepCenter:!1}),this.renderer.applyViewTransform(),this.renderer.render(),{texture:b,preservedZoom:n}}cancel(){this.disable(),this.emit("cancelled")}setShape(e){this.state.get("lockCropShape")||(this.state.set("crop.shape",e),this.state.set("crop.dirty",!0),(e==="circle"||e==="square")&&this.state.set("crop.aspect","1:1"),this.applyAspectRatio(),this.constrainCropRect(),this.drawOverlay())}setAspect(e){if(this.state.get("lockAspectRatio"))return;if(this.state.get("crop.shape")!=="free"){if(this.state.get("lockCropShape"))return;this.state.set("crop.shape","free")}this.state.set("crop.aspect",e),this.state.set("crop.dirty",!0),this.applyAspectRatio(),this.constrainCropRect(),this.drawOverlay()}};oe(U,"AUTO_ZOOM_PADDING",1.1),oe(U,"AUTO_ZOOM_THROTTLE_MS",100);let re=U;class Le{constructor(e={}){this._endpoint=e.endpoint||"/api/v1/media/remove-bg",this._fallbackEndpoint=e.fallbackEndpoint||null}async removeBackground(e,t={}){const i=typeof e=="string"?await this._dataUrlToBlob(e):e,r=new FormData;r.append("file",i,"image.png"),r.append("tier",t.tier||"balanced"),t.model&&r.append("model",t.model),t.alpha_matting&&(r.append("alpha_matting","true"),r.append("alpha_f",String(t.alpha_f??10)),r.append("alpha_fr",String(t.alpha_fr??15)),r.append("alpha_erode_size",String(t.alpha_erode_size??10)));let a,o;try{a=await fetch(this._endpoint,{method:"POST",body:r,credentials:"include"})}catch(c){o=c}if((!a||!a.ok)&&this._fallbackEndpoint)try{a=await fetch(this._fallbackEndpoint,{method:"POST",body:r})}catch(c){o||(o=c)}if(!a)throw o||new Error("Network error: Unable to connect to background removal service");if(!a.ok){let c=`Background removal failed (HTTP ${a.status})`;try{const d=await a.text();d&&(c+=`: ${d}`)}catch{}throw new Error(c)}const n=await a.blob();return{dataUrl:await this._blobToDataUrl(n),model:a.headers.get("X-Model-Used")||"unknown",processMs:a.headers.get("X-Process-Ms")||"0"}}async _dataUrlToBlob(e){if(e.startsWith("data:")){const[i,r]=e.split(","),a=i.match(/:(.*?);/),o=a?a[1]:"image/png",n=atob(r),l=new Uint8Array(n.length);for(let c=0;c<n.length;c++)l[c]=n.charCodeAt(c);return new Blob([l],{type:o})}return(await fetch(e)).blob()}_blobToDataUrl(e){return new Promise((t,i)=>{const r=new FileReader;r.onload=()=>t(r.result),r.onerror=()=>i(new Error("Failed to read blob as data URL")),r.readAsDataURL(e)})}async isAvailable(){try{return(await fetch(this._endpoint,{method:"OPTIONS",credentials:"include"})).ok}catch{if(this._fallbackEndpoint)try{return(await fetch(this._fallbackEndpoint,{method:"OPTIONS"})).ok}catch{}return!1}}}function f(s,e={},...t){const i=document.createElement(s);for(const[r,a]of Object.entries(e))if(a!=null)if(r==="className")i.className=a;else if(r==="style"&&typeof a=="object")Object.assign(i.style,a);else if(r.startsWith("on")&&typeof a=="function"){const o=r.slice(2).toLowerCase();i.addEventListener(o,a)}else r==="dataset"&&typeof a=="object"?Object.assign(i.dataset,a):i.setAttribute(r,a);for(const r of t)typeof r=="string"?i.appendChild(document.createTextNode(r)):r instanceof HTMLElement&&i.appendChild(r);return i}function pe({id:s,label:e,min:t=0,max:i=1,step:r=.01,value:a=.5,onChange:o}){const n=s.includes("-")?s.split("-").slice(1).join("-"):s,l=f("div",{className:"slider-control slider-wrapper","data-control":n,"data-testid":`slider-${n}`}),c=f("div",{className:"slider-header"},f("label",{for:s,className:"slider-label"},e),f("span",{className:"slider-value",id:`${s}-value`},ne(a))),d=f("input",{type:"range",id:s,className:"slider-input",min:String(t),max:String(i),step:String(r),value:String(a),onInput:h=>{const u=parseFloat(h.target.value),p=l.querySelector(".slider-value");p&&(p.textContent=ne(u)),o==null||o(u)}});return l.appendChild(c),l.appendChild(d),l.setValue=h=>{d.value=String(h);const u=l.querySelector(".slider-value");u&&(u.textContent=ne(h))},l}function ne(s){return Number.isInteger(s)?String(s):s.toFixed(2)}function fe({id:s,label:e,checked:t=!1,onChange:i}){const r=f("div",{className:"toggle-control"}),a=f("label",{className:"toggle-label",for:s},e),o=f("input",{type:"checkbox",id:s,className:"toggle-input",checked:t?"checked":void 0,onChange:c=>i==null?void 0:i(c.target.checked)}),n=f("div",{className:"toggle-switch",onClick:c=>{c.target!==o&&(o.checked=!o.checked,i==null||i(o.checked))}}),l=f("span",{className:"toggle-slider"});return n.appendChild(o),n.appendChild(l),r.appendChild(a),r.appendChild(n),r.setChecked=c=>{o.checked=c},r}function me({id:s,label:e,value:t="#000000",onChange:i}){const r=f("div",{className:"color-control"}),a=f("label",{className:"color-label",for:s},e),o=f("input",{type:"color",id:s,className:"color-input",value:t,onInput:n=>i==null?void 0:i(n.target.value)});return r.appendChild(a),r.appendChild(o),r.setValue=n=>{o.value=n},r}function ge({id:s,label:e,value:t="",placeholder:i="",onCommit:r}){const a=f("div",{className:"text-control","data-control":s,"data-testid":`text-${s}`}),o=f("label",{className:"text-label",for:s},e);let n=t;const l=f("input",{type:"text",id:s,className:"text-input",value:t,placeholder:i,onKeyDown:d=>{d.key==="Enter"&&(d.preventDefault(),c(),l.blur())},onBlur:()=>c()});function c(){const d=l.value;d!==n&&(n=d,r==null||r(d))}return a.appendChild(o),a.appendChild(l),a.setValue=d=>{const h=d==null?"":String(d);l.value=h,n=h},a}function be({id:s,label:e,options:t=[],value:i,onChange:r}){const a=f("div",{className:"select-control"}),o=f("label",{className:"select-label",for:s},e),n=f("select",{id:s,className:"select-input",onChange:l=>r==null?void 0:r(l.target.value)});for(const l of t){const c=f("option",{value:l.value},l.label);l.value===i&&(c.selected=!0),n.appendChild(c)}return a.appendChild(o),a.appendChild(n),a.setValue=l=>{n.value=l},a}function R({label:s,className:e="",onClick:t,icon:i=null,disabled:r=!1}){const a=f("button",{type:"button",className:`btn ${e}`.trim(),onClick:t,disabled:r?"disabled":void 0});if(i){const o=f("span",{className:"btn-icon"});o.innerHTML=i;const n=o.querySelector("svg");n&&n.setAttribute("aria-hidden","true"),a.appendChild(o)}return s&&a.appendChild(document.createTextNode(s)),a}function N({icon:s,title:e,className:t="",onClick:i,disabled:r=!1,testId:a=null,ariaLabel:o=null}){const n={type:"button",className:`icon-btn ${t}`.trim(),title:e,"aria-label":o||e,onClick:i,disabled:r?"disabled":void 0};a&&(n.dataset={testid:a});const l=f("button",n);l.innerHTML=s;const c=l.querySelector("svg");return c&&c.setAttribute("aria-hidden","true"),l}function te({label:s,icon:e,active:t=!1,onClick:i}){const r=f("button",{type:"button",className:`chip ${t?"active":""}`.trim(),onClick:i});if(e){const a=f("span",{className:"chip-icon"});a.innerHTML=e;const o=a.querySelector("svg");o&&o.setAttribute("aria-hidden","true"),r.appendChild(a)}return r.appendChild(f("span",{className:"chip-label"},s)),r.setActive=a=>{r.classList.toggle("active",a)},r}class Ve{constructor(e,t){this.state=e,this.editor=t,this.element=null,this._unsubscribers=[]}render(){this.element=f("div",{className:"editor-toolbar"});const e=f("div",{className:"toolbar-section toolbar-left"}),t=N({icon:wt,title:"Open Image",className:"toolbar-btn",testId:"btn-open-image",ariaLabel:"Open image file",onClick:()=>this.editor.openFilePicker()});e.appendChild(t);const i=f("div",{className:"toolbar-section toolbar-center"}),r=N({icon:ht,title:"Zoom Out",className:"toolbar-btn",testId:"btn-zoom-out",ariaLabel:"Zoom out",onClick:()=>{const h=this.state.get("zoom");this.editor.setZoom(h-.25)}});this._zoomLabel=f("span",{className:"zoom-label","aria-live":"polite","aria-atomic":"true",role:"status"},"100%");const a=N({icon:ct,title:"Zoom In",className:"toolbar-btn",testId:"btn-zoom-in",ariaLabel:"Zoom in",onClick:()=>{const h=this.state.get("zoom");this.editor.setZoom(h+.25)}}),o=N({icon:dt,title:"Fit to Screen",className:"toolbar-btn",testId:"btn-fit-screen",ariaLabel:"Fit to screen",onClick:()=>this.editor.fitToScreen()});i.appendChild(r),i.appendChild(this._zoomLabel),i.appendChild(a),i.appendChild(o);const n=f("div",{className:"toolbar-section toolbar-right"});this._themeBtn=N({icon:this.state.get("isDarkMode")?_e:xe,title:"Toggle Theme",className:"toolbar-btn toolbar-btn-theme",testId:"btn-toggle-theme",ariaLabel:"Toggle theme",onClick:()=>this.editor.toggleTheme()}),this._cropBtn=N({icon:Xe,title:"Crop",className:"toolbar-btn toolbar-btn-crop",testId:"btn-crop",ariaLabel:"Crop image",onClick:()=>{this.state.get("mode")==="crop"?this.editor.setMode("filters"):this.editor.setMode("crop")}});const l=N({icon:Oe,title:"Reset All",className:"toolbar-btn",testId:"btn-reset-all",ariaLabel:"Reset all changes",onClick:()=>this.editor.resetAll()}),c=N({icon:yt,title:"Save Image",className:"toolbar-btn toolbar-btn-primary",testId:"btn-save-edit",ariaLabel:"Save image",onClick:()=>this.editor.save()}),d=N({icon:se,title:"Close",className:"toolbar-btn",testId:"btn-cancel-edit",ariaLabel:"Close editor",onClick:()=>this.editor.close()});return n.appendChild(this._themeBtn),n.appendChild(this._cropBtn),n.appendChild(l),n.appendChild(c),n.appendChild(d),this.element.appendChild(e),this.element.appendChild(i),this.element.appendChild(n),this._subscribeToState(),this.element}_subscribeToState(){const e=this.state.on("change:zoom",({value:r})=>{this._zoomLabel.textContent=`${Math.round(r*100)}%`});this._unsubscribers.push(e);const t=this.state.on("change:isDarkMode",({value:r})=>{this._themeBtn.innerHTML=r?_e:xe});this._unsubscribers.push(t);const i=this.state.on("change:mode",({value:r})=>{this._cropBtn&&this._cropBtn.classList.toggle("toolbar-btn-primary",r==="crop")});this._unsubscribers.push(i)}updateZoom(e){this._zoomLabel&&(this._zoomLabel.textContent=`${Math.round(e*100)}%`)}destroy(){var e;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],(e=this.element)==null||e.remove(),this.element=null}}const J=ae;class At{constructor(e,t){this.state=e,this.editor=t,this.element=null,this._chips=new Map,this._scrollIndex=0,this._unsubscribers=[]}render(e){this._onSelect=e,this.element=f("div",{className:"category-carousel-container","data-testid":"category-carousel"}),this._leftBtn=N({icon:de,title:"Previous categories",className:"carousel-nav carousel-nav-left",onClick:()=>this._scrollLeft()}),this._carousel=f("div",{className:"category-carousel"}),J.forEach(i=>{const r=te({label:i.name,icon:i.icon,active:this.state.get("selectedCategory")===i.id,onClick:()=>this._selectCategory(i.id)});r.dataset.categoryId=i.id,r.dataset.category=i.id,r.dataset.testid=`category-${i.id}`,this._chips.set(i.id,r),this._carousel.appendChild(r)}),this._rightBtn=N({icon:ue,title:"Next categories",className:"carousel-nav carousel-nav-right",onClick:()=>this._scrollRight()}),this._pagination=f("div",{className:"carousel-pagination",role:"tablist","aria-label":"Category pages"});const t=Math.ceil(J.length/3);for(let i=0;i<t;i++){const r=f("button",{type:"button",className:`pagination-dot ${i===0?"active":""}`,role:"tab","aria-label":`Page ${i+1} of ${t}`,"aria-selected":i===0?"true":"false",onClick:()=>this._scrollToPage(i)});this._pagination.appendChild(r)}return this.element.appendChild(this._leftBtn),this.element.appendChild(this._carousel),this.element.appendChild(this._rightBtn),this.element.appendChild(this._pagination),this._subscribeToState(),this._updateNavButtons(),this.element}_subscribeToState(){const e=this.state.on("change:selectedCategory",({value:t})=>{this._chips.forEach((i,r)=>{i.setActive(r===t)})});this._unsubscribers.push(e)}_selectCategory(e){var r;this.state.set("selectedCategory",e);const t=this.state.get("mode");e==="crop"?t!=="crop"&&this.editor.setMode("crop"):t!=="filters"&&this.editor.setMode("filters");const i=this._chips.get(e);i&&this._carousel&&i.scrollIntoView({behavior:"smooth",inline:"center",block:"nearest"}),(r=this._onSelect)==null||r.call(this,e)}_scrollLeft(){this._scrollIndex>0&&(this._scrollIndex--,this._scrollCarousel())}_scrollRight(){this._scrollIndex<J.length-3&&(this._scrollIndex++,this._scrollCarousel())}_scrollToPage(e){this._scrollIndex=e*3,this._scrollCarousel()}_scrollCarousel(){if(this._carousel){const e=this._carousel.querySelector(".chip"),t=(e==null?void 0:e.clientWidth)||100;this._carousel.scrollTo({left:this._scrollIndex*(t+8),behavior:"smooth"})}this._updateNavButtons(),this._updatePagination()}_updateNavButtons(){this._leftBtn&&(this._leftBtn.disabled=this._scrollIndex===0),this._rightBtn&&(this._rightBtn.disabled=this._scrollIndex>=J.length-3)}_updatePagination(){if(this._pagination){const e=this._pagination.querySelectorAll(".pagination-dot"),t=Math.floor(this._scrollIndex/3);e.forEach((i,r)=>{const a=r===t;i.classList.toggle("active",a),i.setAttribute("aria-selected",a?"true":"false")})}}setSelected(e){this._selectCategory(e)}destroy(){var e;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],this._chips.clear(),(e=this.element)==null||e.remove(),this.element=null}}class Nt{constructor(e,t){this.state=e,this.filterManager=t,this.element=null,this._filterCards=new Map,this._scrollIndex=0,this._unsubscribers=[],this._onToggle=null,this._onSelect=null}render({onToggle:e,onSelect:t}){return this._onToggle=e,this._onSelect=t,this.element=f("div",{className:"filter-carousel-container"}),this._leftBtn=N({icon:de,title:"Previous filters",className:"carousel-nav carousel-nav-left",onClick:()=>this._scrollLeft()}),this._carousel=f("div",{className:"filter-carousel"}),this._rightBtn=N({icon:ue,title:"Next filters",className:"carousel-nav carousel-nav-right",onClick:()=>this._scrollRight()}),this.element.appendChild(this._leftBtn),this.element.appendChild(this._carousel),this.element.appendChild(this._rightBtn),this._subscribeToState(),this._renderFilters(),this.element}_subscribeToState(){const e=this.state.on("change:selectedCategory",()=>{this._renderFilters()});this._unsubscribers.push(e);const t=this.state.on("change:activeFilters",()=>{this._updateActiveStates()});this._unsubscribers.push(t);const i=this.state.on("change:selectedFilter",()=>{this._updateSelectedState()});this._unsubscribers.push(i)}_renderFilters(){this._carousel.innerHTML="",this._filterCards.clear(),this._scrollIndex=0;const e=this.state.get("selectedCategory");if(e==="crop")return;const t=this.filterManager.getFiltersByCategory(e),i=this.state.get("activeFilters"),r=this.state.get("selectedFilter");t.forEach(a=>{const o=this._createFilterCard(a,{isActive:i.has(a.id),isSelected:r===a.id});this._filterCards.set(a.id,o),this._carousel.appendChild(o)}),this._updateNavButtons()}_createFilterCard(e,{isActive:t,isSelected:i}){const r=f("div",{className:`filter-card ${t?"active":""} ${i?"selected":""}`,"data-filter":e.id,"data-testid":`filter-${e.id}`,onClick:()=>this._handleCardClick(e.id)}),a=f("div",{className:"filter-preview"}),o=f("span",{className:"filter-preview-text"},e.name.charAt(0));a.appendChild(o);const n=f("span",{className:"filter-name",title:e.name},e.name),l=f("button",{className:`filter-toggle ${t?"active":""}`,onClick:c=>{var u;c.stopPropagation();const h=!this.state.get("activeFilters").has(e.id);this._handleToggle(e.id,h),h&&(this.state.set("selectedFilter",e.id),(u=this._onSelect)==null||u.call(this,e.id))}});return l.innerHTML=t?ie:"",r.appendChild(a),r.appendChild(n),r.appendChild(l),r._toggle=l,r._isActive=t,r}_handleCardClick(e){var i;this.state.get("activeFilters").has(e)||this._handleToggle(e,!0),this.state.set("selectedFilter",e),(i=this._onSelect)==null||i.call(this,e)}_handleToggle(e,t){var i;(i=this._onToggle)==null||i.call(this,e,t)}_updateActiveStates(){const e=this.state.get("activeFilters");this._filterCards.forEach((t,i)=>{const r=e.has(i);t.classList.toggle("active",r),t._toggle.classList.toggle("active",r),t._toggle.innerHTML=r?ie:"",t._isActive=r})}_updateSelectedState(){const e=this.state.get("selectedFilter");this._filterCards.forEach((t,i)=>{t.classList.toggle("selected",i===e)})}_scrollLeft(){this._scrollIndex>0&&(this._scrollIndex--,this._scrollCarousel())}_scrollRight(){const e=Math.max(0,this._filterCards.size-3);this._scrollIndex<e&&(this._scrollIndex++,this._scrollCarousel())}_scrollCarousel(){if(this._carousel){const e=this._carousel.querySelector(".filter-card"),t=(e==null?void 0:e.clientWidth)||120;this._carousel.scrollTo({left:this._scrollIndex*(t+8),behavior:"smooth"})}this._updateNavButtons()}_updateNavButtons(){const e=Math.max(0,this._filterCards.size-3);this._leftBtn&&(this._leftBtn.disabled=this._scrollIndex===0),this._rightBtn&&(this._rightBtn.disabled=this._scrollIndex>=e)}destroy(){var e;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],this._filterCards.clear(),(e=this.element)==null||e.remove(),this.element=null}}class zt{constructor(e,t){this.state=e,this.filterManager=t,this.element=null,this._controls=new Map,this._onChange=null,this._onReset=null,this._onAction=null,this._unsubscribers=[]}render({onChange:e,onReset:t,onAction:i}){return this._onChange=e,this._onReset=t,this._onAction=i,this.element=f("div",{className:"filter-adjustments"}),this._subscribeToState(),this._renderControls(),this.element}_subscribeToState(){const e=this.state.on("change:selectedFilter",()=>{this._renderControls()});this._unsubscribers.push(e);const t=this.state.on("change:filterValues",()=>{this._updateValues()});this._unsubscribers.push(t)}_renderControls(){this.element.innerHTML="",this._controls.clear();const e=this.state.get("selectedFilter");if(!e){this.element.appendChild(f("div",{className:"no-filter-selected"},"Select a filter to adjust"));return}const t=this.filterManager.getFilterDef(e);if(!t){this.element.appendChild(f("div",{className:"no-filter-selected"},"Filter not found"));return}const i=f("div",{className:"adjustments-header"});i.appendChild(f("span",{className:"adjustments-title"},t.name)),i.appendChild(R({label:"Reset",className:"btn-text",onClick:()=>this._handleReset(e)})),this.element.appendChild(i);const r=f("div",{className:"adjustments-grid"}),a=this.state.getFilterValues(e);(t.controls||[]).forEach(n=>{const l=a[n.id]??n.default,c=this._createControl(e,n,l);c&&(this._controls.set(n.id,c),r.appendChild(c))});const o=this.filterManager.getInstance(e);if(o&&typeof o.getDynamicControls=="function"){let n=[];try{n=o.getDynamicControls()||[]}catch{}n.forEach(l=>{const c=l.property||l.id,d=a[c]??l.default,h=this._createControl(e,l,d);h&&(this._controls.set(l.id,h),r.appendChild(h))})}this.element.appendChild(r)}_createControl(e,t,i){if(t.hidden)return null;const r=t.label||t.id,a=this._normalizeControlType(t.type),o=t.property||t.id;switch(a){case"slider":return pe({id:`${e}-${t.id}`,label:r,min:t.min??0,max:t.max??1,step:t.step??.01,value:typeof i=="number"?i:t.default??0,onChange:c=>this._handleChange(e,o,c)});case"toggle":return fe({id:`${e}-${t.id}`,label:r,checked:!!i,onChange:c=>this._handleChange(e,o,c)});case"color":return me({id:`${e}-${t.id}`,label:r,value:typeof i=="string"&&i.startsWith("#")?i:t.default||"#000000",onChange:c=>this._handleChange(e,o,c)});case"select":const n=this._normalizeOptions(t.options);return be({id:`${e}-${t.id}`,label:r,options:n,value:i??t.default,onChange:c=>this._handleChange(e,o,c)});case"text":return ge({id:`${e}-${t.id}`,label:r,value:typeof i=="string"?i:t.default??"",placeholder:t.placeholder||"",onCommit:c=>this._handleChange(e,o,c)});case"button":const l=f("div",{className:"button-control"});return l.appendChild(R({label:r,className:"btn-secondary",onClick:()=>this._handleAction(e,t.action||t.id)})),l;default:return null}}_normalizeControlType(e){return{slider:"slider",range:"slider",toggle:"toggle",checkbox:"toggle",color:"color",select:"select",dropdown:"select",button:"button",text:"text"}[e]||e}_normalizeOptions(e){return!e||!Array.isArray(e)?[]:e.map(t=>typeof t=="object"&&t.value!==void 0?{value:t.value,label:t.label||String(t.value)}:typeof t=="string"?{value:t,label:t}:typeof t=="number"?{value:t,label:String(t)}:{value:t,label:String(t)})}_handleChange(e,t,i){var r;(r=this._onChange)==null||r.call(this,e,t,i)}_handleReset(e){var t;(t=this._onReset)==null||t.call(this,e),this._renderControls()}_handleAction(e,t){var i;(i=this._onAction)==null||i.call(this,e,t),this._renderControls()}_updateValues(){const e=this.state.get("selectedFilter");if(!e)return;const t=this.state.getFilterValues(e),i=this.filterManager.getFilterDef(e);i&&i.controls.forEach(r=>{const a=this._controls.get(r.id);if(a&&typeof a.setValue=="function"){const o=t[r.id]??r.default;a.setValue(o)}})}show(){this.element&&(this.element.style.display="")}hide(){this.element&&(this.element.style.display="none")}destroy(){var e;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],this._controls.clear(),(e=this.element)==null||e.remove(),this.element=null}}class Rt{constructor(e,t){this.state=e,this.filterManager=t,this._drawer=null,this._body=null,this._titleEl=null,this._isOpen=!1,this._currentFilterId=null,this._controls=new Map,this._onChange=null,this._onReset=null,this._onRemove=null,this._onAction=null,this._container=null}build(e,{onChange:t,onReset:i,onRemove:r,onAction:a}){this._onChange=t,this._onReset=i,this._onRemove=r,this._onAction=a,this._container=e,this._drawer=f("div",{className:"mobile-filter-drawer"});const o=f("div",{className:"drawer-header"});this._titleEl=f("span",{className:"drawer-title"},"Filter");const n=f("div",{className:"drawer-header-actions"}),l=R({label:"Reset",className:"btn-text",onClick:()=>{var h;this._currentFilterId&&((h=this._onReset)==null||h.call(this,this._currentFilterId),this._renderControls())}}),c=R({label:"Remove",className:"btn-text btn-danger",onClick:()=>{var h;this._currentFilterId&&((h=this._onRemove)==null||h.call(this,this._currentFilterId),this.close())}}),d=N({icon:se,title:"Close",className:"btn-icon-sm",ariaLabel:"Close drawer",onClick:()=>this.close()});n.appendChild(l),n.appendChild(c),n.appendChild(d),o.appendChild(this._titleEl),o.appendChild(n),this._drawer.appendChild(o),this._body=f("div",{className:"drawer-body"}),this._drawer.appendChild(this._body),e.appendChild(this._drawer)}open(e){this._isOpen&&this._currentFilterId===e||(this._currentFilterId=e,this._renderControls(),this._isOpen||(this._isOpen=!0,this._sizeToContainer(),this._animateOpen()))}close(){this._isOpen&&(this._isOpen=!1,this._animateClose(),this._currentFilterId=null)}get isOpen(){return this._isOpen}_sizeToContainer(){if(!this._container||!this._drawer)return;const e=this._container.offsetHeight;e>0&&(this._drawer.style.height=e+"px")}_animateOpen(){this._drawer.style.transition="none",this._drawer.style.transform="translateY(100%)",this._drawer.offsetHeight,this._drawer.style.transition="transform 0.25s cubic-bezier(0.33, 1, 0.68, 1)",this._drawer.style.transform="translateY(0)"}_animateClose(){this._drawer.style.transition="transform 0.2s cubic-bezier(0.32, 0, 0.67, 0)",this._drawer.style.transform="translateY(100%)"}_renderControls(){if(this._body.innerHTML="",this._controls.clear(),!this._currentFilterId)return;const e=this.filterManager.getFilterDef(this._currentFilterId);if(!e)return;this._titleEl.textContent=e.name;const t=f("div",{className:"adjustments-grid"}),i=this.state.getFilterValues(this._currentFilterId);(e.controls||[]).forEach(a=>{if(a.hidden)return;const o=this._createControl(this._currentFilterId,a,i[a.id]??a.default);o&&(this._controls.set(a.id,o),t.appendChild(o))});const r=this.filterManager.getInstance(this._currentFilterId);if(r&&typeof r.getDynamicControls=="function"){let a=[];try{a=r.getDynamicControls()||[]}catch{}a.forEach(o=>{const n=o.property||o.id,l=i[n]??o.default,c=this._createControl(this._currentFilterId,o,l);c&&(this._controls.set(o.id,c),t.appendChild(c))})}this._body.appendChild(t)}_createControl(e,t,i){if(t.hidden)return null;const r=t.label||t.id,a=this._normalizeControlType(t.type),o=t.property||t.id;switch(a){case"slider":return pe({id:`drawer-${e}-${t.id}`,label:r,min:t.min??0,max:t.max??1,step:t.step??.01,value:typeof i=="number"?i:t.default??0,onChange:n=>{var l;return(l=this._onChange)==null?void 0:l.call(this,e,o,n)}});case"toggle":return fe({id:`drawer-${e}-${t.id}`,label:r,checked:!!i,onChange:n=>{var l;return(l=this._onChange)==null?void 0:l.call(this,e,o,n)}});case"color":return me({id:`drawer-${e}-${t.id}`,label:r,value:typeof i=="string"&&i.startsWith("#")?i:t.default||"#000000",onChange:n=>{var l;return(l=this._onChange)==null?void 0:l.call(this,e,o,n)}});case"select":{const n=this._normalizeOptions(t.options);return be({id:`drawer-${e}-${t.id}`,label:r,options:n,value:i??t.default,onChange:l=>{var c;return(c=this._onChange)==null?void 0:c.call(this,e,o,l)}})}case"text":return ge({id:`drawer-${e}-${t.id}`,label:r,value:typeof i=="string"?i:t.default??"",placeholder:t.placeholder||"",onCommit:n=>{var l;return(l=this._onChange)==null?void 0:l.call(this,e,o,n)}});case"button":{const n=f("div",{className:"button-control"});return n.appendChild(R({label:r,className:"btn-secondary",onClick:()=>{var l;(l=this._onAction)==null||l.call(this,e,t.action||t.id),this._renderControls()}})),n}default:return null}}_normalizeControlType(e){return{slider:"slider",range:"slider",toggle:"toggle",checkbox:"toggle",color:"color",select:"select",dropdown:"select",button:"button",text:"text"}[e]||e}_normalizeOptions(e){return!e||!Array.isArray(e)?[]:e.map(t=>typeof t=="object"&&t.value!==void 0?{value:t.value,label:t.label||String(t.value)}:typeof t=="string"?{value:t,label:t}:typeof t=="number"?{value:t,label:String(t)}:{value:t,label:String(t)})}destroy(){var e;this._controls.clear(),(e=this._drawer)==null||e.remove(),this._drawer=null,this._isOpen=!1,this._currentFilterId=null,this._container=null}}class Tt{constructor(e,t){this.state=e,this.filterManager=t,this.element=null,this._scrollContainer=null,this._chips=new Map,this._unsubscribers=[],this._onToggle=null,this._onSelect=null}render({onToggle:e,onSelect:t}){return this._onToggle=e,this._onSelect=t,this.element=f("div",{className:"mobile-active-filters","data-testid":"mobile-active-filters"}),this._scrollContainer=f("div",{className:"mobile-active-filters-scroll"}),this.element.appendChild(this._scrollContainer),this._subscribeToState(),this._renderChips(),this.element}_subscribeToState(){const e=this.state.on("change:activeFilters",()=>{this._renderChips()});this._unsubscribers.push(e);const t=this.state.on("change:selectedFilter",()=>{this._updateSelectedState()});this._unsubscribers.push(t)}_renderChips(){this._scrollContainer.innerHTML="",this._chips.clear();const e=this.state.get("activeFilters");if(!e||e.size===0){const t=f("div",{className:"active-filter-placeholder"},"No active filters");this._scrollContainer.appendChild(t);return}e.forEach(t=>{const i=this.filterManager.getFilterDef(t);if(!i)return;const r=this._createChip(t,i);this._chips.set(t,r),this._scrollContainer.appendChild(r)}),this._updateSelectedState()}_createChip(e,t){const i=f("div",{className:"active-filter-chip","data-filter-id":e,"data-testid":`active-chip-${e}`}),r=f("span",{className:"active-filter-chip-label",onClick:o=>{var n;o.stopPropagation(),(n=this._onSelect)==null||n.call(this,e)}},t.name),a=f("button",{className:"active-filter-chip-check","aria-label":`Remove ${t.name} filter`,onClick:o=>{var n;o.stopPropagation(),(n=this._onToggle)==null||n.call(this,e,!1)}});return a.innerHTML='<svg width="10" height="10" viewBox="0 0 12 12"><path d="M2 6l3 3 5-5" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/></svg>',i.appendChild(r),i.appendChild(a),i}_updateSelectedState(){const e=this.state.get("selectedFilter");this._chips.forEach((t,i)=>{t.classList.toggle("selected",i===e)})}destroy(){var e;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],this._chips.clear(),(e=this.element)==null||e.remove(),this.element=null}}const Et=[{id:"free",name:"Free",icon:Mt},{id:"square",name:"Square",icon:St},{id:"circle",name:"Circle",icon:vt}],It=[{id:"free",name:"Free"},{id:"1:1",name:"1:1"},{id:"4:3",name:"4:3"},{id:"16:9",name:"16:9"},{id:"3:2",name:"3:2"},{id:"2:3",name:"2:3"}],Bt=[{id:"0",label:"0°",angle:0},{id:"90",label:"90°",angle:90},{id:"180",label:"180°",angle:180},{id:"270",label:"270°",angle:270}];function q(s){if(!Number.isFinite(Number(s)))return 0;const e=Number(s)%360;return e<0?e+360:e}class Ue{constructor(e,t,i=null){this.state=e,this.cropManager=t,this.editor=i,this.element=null,this._shapeChips=new Map,this._aspectChips=new Map,this._rotationPresetChips=new Map,this._rotationRange=null,this._rotationNumber=null,this._rotationValue=null,this._unsubscribers=[]}_applyCropAndReturnToFilters(){this.cropManager.apply()===null&&typeof this.cropManager.disable=="function"&&this.cropManager.disable(),this.state.set("selectedCategory","adjust")}render(){this.element=f("div",{className:"crop-controls","data-testid":"crop-controls"}),this.element.appendChild(this._renderRotationSection());const e=f("div",{className:"crop-section"});e.appendChild(f("label",{className:"section-label"},"Shape"));const t=f("div",{className:"chip-row"}),i=this.state.get("crop.shape");Et.forEach(c=>{const d=te({label:c.name,icon:c.icon,active:i===c.id,onClick:()=>this._selectShape(c.id)});d.dataset.shape=c.id,d.dataset.testid=`crop-shape-${c.id}`,this._shapeChips.set(c.id,d),t.appendChild(d)}),e.appendChild(t),this.element.appendChild(e),this.state.get("lockCropShape")&&(e.style.display="none"),this._shapeSection=e,this._aspectSection=f("div",{className:"crop-section"}),this._aspectSection.appendChild(f("label",{className:"section-label"},"Aspect Ratio"));const r=f("div",{className:"chip-row aspect-row"}),a=this.state.get("crop.aspect");It.forEach(c=>{const d=te({label:c.name,active:a===c.id,onClick:()=>this._selectAspect(c.id)});d.dataset.ratio=c.id,d.dataset.testid=`crop-ratio-${c.id}`,this._aspectChips.set(c.id,d),r.appendChild(d)}),this._aspectSection.appendChild(r),this.element.appendChild(this._aspectSection),this._updateAspectVisibility();const o=f("div",{className:"crop-actions"}),n=R({label:"Cancel",className:"btn-secondary crop-cancel-btn",icon:se,onClick:()=>this.cropManager.cancel()});n.dataset.testid="cancel-crop";const l=R({label:"Apply Crop",className:"btn-primary crop-apply-btn",icon:ie,onClick:()=>this._applyCropAndReturnToFilters()});return l.dataset.testid="apply-crop",o.appendChild(n),o.appendChild(l),this.element.appendChild(o),this._subscribeToState(),this.element}_renderRotationSection(){const e=f("div",{className:"crop-section rotation-section"});e.appendChild(f("label",{className:"section-label"},"Rotate"));const t=f("div",{className:"rotation-action-row"}),i=R({label:"Left 90°",className:"btn-secondary rotation-action-btn",icon:_t,onClick:()=>this._rotateBy(-90)});i.dataset.testid="rotate-left-90";const r=R({label:"Right 90°",className:"btn-secondary rotation-action-btn",icon:xt,onClick:()=>this._rotateBy(90)});r.dataset.testid="rotate-right-90";const a=R({label:"Rotate 180°",className:"btn-secondary rotation-action-btn",onClick:()=>this._rotateBy(180)});a.dataset.testid="rotate-180";const o=R({label:"Rotate 270°",className:"btn-secondary rotation-action-btn",onClick:()=>this._rotateBy(270)});o.dataset.testid="rotate-270",t.appendChild(i),t.appendChild(r),t.appendChild(a),t.appendChild(o),e.appendChild(t);const n=f("div",{className:"chip-row rotation-preset-row"}),l=q(this.state.get("transform.rotation")??0);Bt.forEach(p=>{const b=te({label:p.label,active:Math.round(l)===p.angle,onClick:()=>this._setRotation(p.angle)});b.dataset.angle=p.id,b.dataset.testid=`rotation-preset-${p.id}`,this._rotationPresetChips.set(p.id,b),n.appendChild(b)}),e.appendChild(n);const c=f("div",{className:"rotation-arbitrary"}),d=f("div",{className:"rotation-angle-header"},f("label",{className:"rotation-angle-label",for:"image-editor-rotation-angle"},"Angle"),f("span",{className:"rotation-angle-value"},this._formatAngle(l)));this._rotationValue=d.querySelector(".rotation-angle-value"),this._rotationRange=f("input",{id:"image-editor-rotation-angle",type:"range",className:"slider-input rotation-range",min:"0",max:"360",step:"1",value:String(Math.round(l)),"aria-label":"Rotation angle",onInput:p=>this._previewAngleValue(p.target.value),onChange:p=>this._setRotation(Number(p.target.value))}),this._rotationNumber=f("input",{type:"number",className:"text-input rotation-number-input",min:"-360",max:"360",step:"1",value:this._formatPlainAngle(l),"aria-label":"Rotation angle in degrees",onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),this._setRotation(Number(p.target.value)),p.target.blur())},onBlur:p=>this._setRotation(Number(p.target.value))});const h=f("div",{className:"rotation-angle-row"},this._rotationRange,this._rotationNumber);c.appendChild(d),c.appendChild(h);const u=R({label:"Reset rotation",className:"btn-text rotation-reset-btn",onClick:()=>this._setRotation(0)});return u.dataset.testid="reset-rotation",c.appendChild(u),e.appendChild(c),e}_subscribeToState(){const e=this.state.on("change:crop.shape",({value:r})=>{this._shapeChips.forEach((a,o)=>{a.setActive(o===r)}),this._updateAspectVisibility()});this._unsubscribers.push(e);const t=this.state.on("change:crop.aspect",({value:r})=>{this._aspectChips.forEach((a,o)=>{a.setActive(o===r)})});this._unsubscribers.push(t);const i=this.state.on("change:transform.rotation",({value:r})=>{this._syncRotationControls(r)});this._unsubscribers.push(i)}_rotateBy(e){var i,r;((r=(i=this.editor)==null?void 0:i.rotateBy)==null?void 0:r.call(i,e))!==!1&&this._syncRotationControls(this.state.get("transform.rotation")??0)}_setRotation(e){var r,a;const t=q(e);if(((a=(r=this.editor)==null?void 0:r.setRotationAngle)==null?void 0:a.call(r,t))===!1){this._syncRotationControls(this.state.get("transform.rotation")??0);return}this._syncRotationControls(t)}_previewAngleValue(e){const t=q(Number(e));this._rotationValue&&(this._rotationValue.textContent=this._formatAngle(t)),this._rotationNumber&&(this._rotationNumber.value=this._formatPlainAngle(t)),this._refreshPresetChips(t)}_syncRotationControls(e){const t=q(e);this._rotationValue&&(this._rotationValue.textContent=this._formatAngle(t)),this._rotationRange&&(this._rotationRange.value=String(Math.round(t))),this._rotationNumber&&(this._rotationNumber.value=this._formatPlainAngle(t)),this._refreshPresetChips(t)}_refreshPresetChips(e){const t=Math.round(q(e))%360;this._rotationPresetChips.forEach((i,r)=>{i.setActive(Number(r)===t)})}_formatAngle(e){return`${this._formatPlainAngle(e)}°`}_formatPlainAngle(e){const t=q(e);return Number.isInteger(t)?String(t):t.toFixed(1)}_selectShape(e){this.cropManager.setShape(e)}_selectAspect(e){this.cropManager.setAspect(e)}_updateAspectVisibility(){const e=this.state.get("crop.shape"),t=this.state.get("lockAspectRatio");this._aspectSection&&(this._aspectSection.style.display=e==="free"&&!t?"":"none")}show(){this.element&&(this.element.style.display="")}hide(){this.element&&(this.element.style.display="none")}destroy(){var e;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],this._shapeChips.clear(),this._aspectChips.clear(),this._rotationPresetChips.clear(),(e=this.element)==null||e.remove(),this.element=null}}class Xt{constructor(e,t){this.state=e,this.filterManager=t,this.element=null,this._filterItems=new Map,this._unsubscribers=[],this._onRemove=null,this._onReset=null,this._onClearAll=null,this._onUpdateValue=null,this._onSelect=null}render({onRemove:e,onReset:t,onClearAll:i,onUpdateValue:r,onSelect:a}){this._onRemove=e,this._onReset=t,this._onClearAll=i,this._onUpdateValue=r,this._onSelect=a,this.element=f("div",{className:"active-filters-panel","data-testid":"active-filters-panel"});const o=f("div",{className:"panel-header"});o.appendChild(f("h3",{className:"panel-title"},"Active Filters"));const n=R({label:"Clear All",className:"btn-text btn-danger",onClick:()=>this._handleClearAll()});return n.dataset.testid="clear-all-filters",o.appendChild(n),this.element.appendChild(o),this._listContainer=f("div",{className:"active-filters-list"}),this.element.appendChild(this._listContainer),this._subscribeToState(),this._renderFilterList(),this.element}_subscribeToState(){const e=this.state.on("change:activeFilters",()=>{this._renderFilterList()});this._unsubscribers.push(e);const t=this.state.on("change:filterValues",()=>{this._updateValuesDisplay()});this._unsubscribers.push(t);const i=this.state.on("change:selectedFilter",()=>{this._updateSelectedState()});this._unsubscribers.push(i)}_updateSelectedState(){const e=this.state.get("selectedFilter");this._filterItems.forEach((t,i)=>{t.classList.toggle("selected",i===e)})}_renderFilterList(){this._listContainer.innerHTML="",this._filterItems.clear();const e=this.state.get("activeFilters");if(e.size===0){this._listContainer.appendChild(f("div",{className:"no-filters-message"},"No filters active"));return}e.forEach(t=>{const i=this.filterManager.getFilterDef(t);if(!i)return;const r=this._createFilterItem(t,i);this._filterItems.set(t,r),this._listContainer.appendChild(r)})}_createFilterItem(e,t){const r=this.state.get("selectedFilter")===e,a=f("div",{className:`active-filter-item ${r?"selected":""}`,"data-active-filter":e,"data-testid":`active-filter-${e}`,onClick:p=>{p.target.closest(".filter-item-actions")||this._handleSelect(e)}}),o=f("div",{className:"filter-item-header"}),n=f("span",{className:"filter-item-name"},t.name),l=f("div",{className:"filter-item-actions"}),c=N({icon:Oe,title:"Reset filter",className:"btn-icon-sm",onClick:()=>this._handleReset(e)}),d=N({icon:Ct,title:"Remove filter",className:"btn-icon-sm btn-danger",onClick:()=>this._handleRemove(e)});l.appendChild(c),l.appendChild(d),o.appendChild(n),o.appendChild(l),a.appendChild(o);const h=this.state.getFilterValues(e),u=f("div",{className:"filter-item-summary"});return u.textContent=this._getValuesSummary(t,h),a.appendChild(u),a._summaryEl=u,a}_normalizeControlType(e){return{slider:"slider",range:"slider",toggle:"toggle",checkbox:"toggle",color:"color",select:"select",dropdown:"select",button:"button"}[e]||e}_getValuesSummary(e,t){if(!e.controls||!Array.isArray(e.controls))return"Default values";const i=[];return e.controls.forEach(r=>{const a=this._normalizeControlType(r.type);if(a==="button")return;const o=r.label||r.id,n=t[r.id]??r.default;n!==r.default&&(a==="slider"?i.push(`${o}: ${this._formatValue(n)}`):a==="toggle"?n&&i.push(o):a==="color"?i.push(`${o}: ${n}`):a==="select"&&i.push(`${o}: ${n}`))}),i.length>0?i.join(", "):"Default values"}_formatValue(e){return typeof e!="number"||Number.isInteger(e)?String(e):e.toFixed(2)}_updateValuesDisplay(){this._filterItems.forEach((e,t)=>{const i=this.filterManager.getFilterDef(t);if(!i||!e._summaryEl)return;const r=this.state.getFilterValues(t);e._summaryEl.textContent=this._getValuesSummary(i,r)})}_handleRemove(e){var t;(t=this._onRemove)==null||t.call(this,e)}_handleReset(e){var t;(t=this._onReset)==null||t.call(this,e)}_handleClearAll(){var e;(e=this._onClearAll)==null||e.call(this)}_handleSelect(e){var t;this.state.set("selectedFilter",e),(t=this._onSelect)==null||t.call(this,e)}show(){this.element&&(this.element.style.display="")}hide(){this.element&&(this.element.style.display="none")}destroy(){var e;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],this._filterItems.clear(),(e=this.element)==null||e.remove(),this.element=null}}const $={name:"free",initialMode:"filters",cropShape:"free",aspectRatio:"free",autoZoomOnCropOverflow:!1,lockCropShape:!1,lockAspectRatio:!1,showFilters:!0,showCropControls:!0,maxExportWidth:void 0,maxExportHeight:void 0},le={free:{...$},avatar:{...$,name:"avatar",initialMode:"crop",cropShape:"circle",aspectRatio:"1:1",autoZoomOnCropOverflow:!0,lockCropShape:!0,lockAspectRatio:!0},banner:{...$,name:"banner",initialMode:"crop",cropShape:"square",aspectRatio:"16:9",autoZoomOnCropOverflow:!1,lockCropShape:!1,lockAspectRatio:!0},cover:{...$,name:"cover",initialMode:"crop",cropShape:"free",aspectRatio:"24:5",autoZoomOnCropOverflow:!0,lockCropShape:!0,lockAspectRatio:!0},product:{...$,name:"product",initialMode:"filters",cropShape:"square",aspectRatio:"1:1",autoZoomOnCropOverflow:!1,lockCropShape:!1,lockAspectRatio:!1}};function je(s){if(!s)return{...le.free};if(typeof s=="object"&&s!==null)return{...$,...s};const e=le[s];return e?{...e}:{...le.free}}function Z(s){if(!Number.isFinite(Number(s)))return 0;const e=Number(s)%360;return e<0?e+360:e}function Ot(s,e){const t=Z(s);return(Z(e)-t+540)%360-180}class Yt extends G{constructor(e,t={}){var a,o,n;if(super(),!e)throw new Error("VanillaImageEditor: container element is required");this._container=e,this._destroyed=!1,this._loadVersion=0,this._objectUrls=new Set;const i=t.preset?je(t.preset):null,r=i?{initialMode:i.initialMode==="crop"?"crop":"adjust",cropShape:i.cropShape,initialAspectRatio:i.aspectRatio}:{};this._options={theme:"auto",initialImage:null,initialMode:"adjust",cropShape:"free",initialAspectRatio:"free",backgroundRemoval:{enabled:!0,endpoint:"/api/v1/media/remove-bg",fallbackEndpoint:null},...r,...t},this._preset=i,this._state=Ie(),this._state.set("theme",this._options.theme),this._state.set("crop.shape",this._options.cropShape),this._state.set("crop.aspect",this._options.initialAspectRatio),this._preset&&(this._state.set("lockCropShape",!!this._preset.lockCropShape),this._state.set("lockAspectRatio",!!this._preset.lockAspectRatio),this._state.set("showFilters",this._preset.showFilters!==!1),this._state.set("showCropControls",this._preset.showCropControls!==!1),this._state.set("autoZoomOnCropOverflow",!!this._preset.autoZoomOnCropOverflow)),this._renderer=new Be,this._filterManager=new De(this._state,this._renderer),this._cropManager=new re(this._state,this._renderer),this._removeBgManager=null,((a=this._options.backgroundRemoval)==null?void 0:a.enabled)!==!1&&(this._removeBgManager=new Le({endpoint:(o=this._options.backgroundRemoval)==null?void 0:o.endpoint,fallbackEndpoint:(n=this._options.backgroundRemoval)==null?void 0:n.fallbackEndpoint})),this._loadingOverlay=null,this._isMobile=typeof window<"u"?window.innerWidth<=768:!1,this._toolbar=null,this._categoryCarousel=null,this._filterCarousel=null,this._filterAdjustments=null,this._mobileFilterDrawer=null,this._mobileActiveFilters=null,this._cropControls=null,this._activeFiltersPanel=null,this._editorEl=null,this._canvasContainer=null,this._cropOverlay=null,this._controlsSection=null,this._filterControlsEl=null,this._fileInput=null,this._resizeObserver=null,this._init()}async _init(){this._state.detectTheme(),this._buildDOM(),await this._renderer.mount(this._canvasContainer,this._state.get("isDarkMode")?657930:16777215),this._cropManager.setOverlayCanvas(this._cropOverlay),this._initUI(),this._setupResizeObserver(),this._setupWindowResize(),this._subscribeToState(),this._options.initialImage&&await this.loadImage(this._options.initialImage),this.emit("ready")}_buildDOM(){this._container.innerHTML="",this._editorEl=f("div",{className:`vanilla-image-editor ${this._state.get("isDarkMode")?"dark":"light"}`});const e=f("div",{className:"editor-toolbar-container"});this._editorEl.appendChild(e),this._toolbarContainer=e;const t=f("div",{className:"editor-content"}),i=f("div",{className:"canvas-section"});this._canvasContainer=f("div",{className:"canvas-container"}),this._cropOverlay=f("canvas",{className:"crop-overlay","aria-hidden":"true"}),i.appendChild(this._canvasContainer),i.appendChild(this._cropOverlay),t.appendChild(i),this._controlsSection=f("div",{className:"controls-section"}),t.appendChild(this._controlsSection),this._editorEl.appendChild(t),this._fileInput=f("input",{type:"file",accept:"image/*",className:"hidden-file-input","aria-label":"Choose image file to edit",onChange:r=>this._handleFileSelect(r)}),this._editorEl.appendChild(this._fileInput),this._container.appendChild(this._editorEl)}_initUI(){this._toolbar=new Ve(this._state,this),this._toolbarContainer.appendChild(this._toolbar.render()),this._filterControlsEl=f("div",{className:"filter-controls-container"}),this._categoryCarousel=new At(this._state,this),this._filterControlsEl.appendChild(this._categoryCarousel.render(r=>{}));const e=f("div",{className:"filter-layout"}),t=f("div",{className:"filter-left-column"});this._filterCarousel=new Nt(this._state,this._filterManager),t.appendChild(this._filterCarousel.render({onToggle:(r,a)=>this._handleFilterToggle(r,a),onSelect:r=>{this._handleFilterSelect(r),this._isMobile&&this._mobileFilterDrawer&&this._mobileFilterDrawer.open(r)}})),this._filterAdjustments=new zt(this._state,this._filterManager),t.appendChild(this._filterAdjustments.render({onChange:(r,a,o)=>this._handleFilterChange(r,a,o),onReset:r=>this._handleFilterReset(r),onAction:(r,a)=>this._handleFilterAction(r,a)})),e.appendChild(t);const i=f("div",{className:"filter-right-column"});this._activeFiltersPanel=new Xt(this._state,this._filterManager),i.appendChild(this._activeFiltersPanel.render({onRemove:r=>this._handleFilterToggle(r,!1),onReset:r=>this._handleFilterReset(r),onClearAll:()=>this.resetAll(),onSelect:r=>this._handleFilterSelect(r)})),e.appendChild(i),this._filterControlsEl.appendChild(e),this._mobileActiveFilters=new Tt(this._state,this._filterManager),this._filterControlsEl.appendChild(this._mobileActiveFilters.render({onToggle:(r,a)=>this._handleFilterToggle(r,a),onSelect:r=>{this._handleFilterSelect(r),this._isMobile&&this._mobileFilterDrawer&&this._mobileFilterDrawer.open(r)}})),this._cropControls=new Ue(this._state,this._cropManager,this),this._cropControlsEl=this._cropControls.render(),this._cropControlsEl.style.display="none",this._controlsSection.appendChild(this._filterControlsEl),this._controlsSection.appendChild(this._cropControlsEl),this._mobileFilterDrawer=new Rt(this._state,this._filterManager),this._mobileFilterDrawer.build(this._controlsSection,{onChange:(r,a,o)=>this._handleFilterChange(r,a,o),onReset:r=>this._handleFilterReset(r),onRemove:r=>{this._handleFilterToggle(r,!1),this._state.set("selectedFilter",null)},onAction:(r,a)=>this._handleFilterAction(r,a)})}_setupResizeObserver(){let e=null;this._resizeObserver=new ResizeObserver(()=>{clearTimeout(e),e=setTimeout(()=>{this._canvasContainer&&(this._renderer.resizeTo(this._canvasContainer),this._state.get("mode")==="crop"&&this._cropManager.drawOverlay())},50)}),this._resizeObserver.observe(this._canvasContainer)}_setupWindowResize(){this._handleWindowResize=()=>{var e;this._isMobile=window.innerWidth<=768,!this._isMobile&&((e=this._mobileFilterDrawer)!=null&&e.isOpen)&&this._mobileFilterDrawer.close()},window.addEventListener("resize",this._handleWindowResize)}_subscribeToState(){this._state.on("change:mode",({value:e})=>{this._updateModeUI(e),e==="filters"&&this._filterManager.applyFilters()}),this._state.on("change:isDarkMode",({value:e})=>{this._editorEl.classList.toggle("dark",e),this._editorEl.classList.toggle("light",!e),this._renderer.setBackgroundColor(e?657930:16777215)}),this._state.on("change:hasImage",({value:e})=>{this._editorEl.classList.toggle("has-image",e)}),this._renderer.on("zoomChange",e=>{this._state.set("zoom",e)})}_updateModeUI(e){var t;e==="crop"?(this._filterControlsEl.style.display="none",this._cropControlsEl.style.display="",(t=this._mobileFilterDrawer)!=null&&t.isOpen&&this._mobileFilterDrawer.close()):(this._filterControlsEl.style.display="",this._cropControlsEl.style.display="none")}async _handleFileSelect(e){var i;const t=(i=e.target.files)==null?void 0:i[0];t&&await this.loadImage(t),this._fileInput.value=""}_handleFilterToggle(e,t){this._filterManager.toggle(e,t)}_handleFilterSelect(e){this._state.set("selectedFilter",e)}_handleFilterChange(e,t,i){this._filterManager.updateValue(e,t,i)||this._filterManager.applyFilters(),this._renderer.render()}_handleFilterReset(e){this._filterManager.resetValues(e),this._filterManager.applyFilters()}_handleFilterAction(e,t){this._filterManager.performFilterAction(e,t)}setFilterRegistry(e){this._filterManager.setRegistry(e)}async loadImage(e,t={}){if(this._destroyed)return;const i=++this._loadVersion;let r=e;this._resetEditorState(),e instanceof Blob&&(r=URL.createObjectURL(e),this._objectUrls.add(r));const a=await this._renderer.loadTexture(r);if(!(this._destroyed||this._loadVersion!==i)){if(!a){this.emit("error",new Error("Failed to load image"));return}this._state.set("hasImage",!0),this._state.set("imageUrl",r),t.state&&this._hydrateState(t.state),this._options.initialMode==="crop"&&this.setMode("crop"),this.emit("imageLoaded",{url:r})}}_resetEditorState(){this._filterManager.resetAll(),this._state.set("crop.rect",null),this._state.set("crop.appliedRect",null),this._state.set("crop.appliedShape",null),this._state.set("crop.appliedAspect",null),this._state.set("crop.dirty",!1),this._state.set("crop.shape",this._options.cropShape||"free"),this._state.set("crop.aspect",this._options.initialAspectRatio||"free"),this._state.set("transform.rotation",0),this._state.get("mode")==="crop"&&(this._cropManager.disable(),this._state.set("mode","filters"))}_hydrateState(e){var i;if(!e||e.version!==1)return;const t=Z(((i=e.transform)==null?void 0:i.rotation)??0);if(t!==0&&this._renderer.rotateBy(t)&&this._state.set("transform.rotation",t),e.crop){const r=e.crop.shape||"free",a=e.crop.aspectRatio||"free";e.crop.rect&&(this._cropManager.applyFromPixelRect(e.crop.rect,r),this._state.set("crop.appliedRect",{...e.crop.rect}),this._state.set("crop.appliedShape",r),this._state.set("crop.appliedAspect",a)),this._state.set("crop.shape",r),this._state.set("crop.aspect",a)}if(Array.isArray(e.filters)){let r=null;for(const a of e.filters)if(a.enabled&&(r===null&&(r=a.id),this._state.toggleFilter(a.id,!0),this._filterManager.initializeValues(a.id),a.values))for(const[o,n]of Object.entries(a.values))this._state.setFilterValue(a.id,o,n);if(r!==null){this._state.set("selectedFilter",r);const a=this._filterManager.getFilterDef(r);if(typeof(a==null?void 0:a.category)=="string"){const o=Ye[a.category]??a.category;this._state.set("selectedCategory",o)}}this._filterManager.applyFilters()}}openFilePicker(){var e;(e=this._fileInput)==null||e.click()}exportImage(e="png",t=.92,i={}){const r=this._state.get("crop.rect"),a=this._state.get("crop.dirty")!==!1||this._state.get("mode")!=="crop";return r&&a&&!this._cropManager.apply()?null:this._renderer.exportImage(e,t,i.maxEdge??0,i.dontUpscale!==!1,i.maxPixels??0)}save(){if(this._state.get("hasImage")){this._state.set("isSaving",!0);try{const e=this.exportImage("png",.92);if(!e)throw new Error("Failed to export image");const t=this._renderer.originalTexture,i={width:Math.round((t==null?void 0:t.width)||0),height:Math.round((t==null?void 0:t.height)||0)},r=document.createElement("a");r.href=e,r.download=`edited-image-${Date.now()}.png`,document.body.appendChild(r),r.click(),document.body.removeChild(r),this.emit("save",{imageData:e,dimensions:i,state:this.getSerializableState()})}catch(e){this.emit("error",{error:e})}finally{this._state.set("isSaving",!1)}}}getSerializableState(){const e=this._state.get("activeFilters"),t=[];if(e)for(const o of e){const n=this._state.getFilterValues(o);t.push({id:o,enabled:!0,values:{...n}})}const i=this._state.get("crop.appliedRect"),r=this._state.get("crop.rect"),a=i||r;return{version:1,crop:{rect:a?{...a}:null,aspectRatio:this._state.get("crop.appliedAspect")||this._state.get("crop.aspect")||"free",shape:this._state.get("crop.appliedShape")||this._state.get("crop.shape")||"free"},transform:{rotation:Z(this._state.get("transform.rotation")??0)},filters:t}}close(){this.emit("cancel")}setZoom(e){this._renderer.setZoom(e)}fitToScreen(){this._renderer.fitToScreen()}resetAll(){this._filterManager.resetAll()}rotateBy(e){const t=this._state.get("transform.rotation")??0;return this.setRotationAngle(Number(t)+Number(e))}setRotationAngle(e){if(!this._state.get("hasImage"))return!1;const t=Z(this._state.get("transform.rotation")??0),i=Z(e),r=Ot(t,i),a=this._state.get("mode")==="crop";if(Math.abs(r)>.001){if(a&&this._cropManager.disable(),!this._renderer.rotateBy(r))return a&&this._cropManager.enable(),!1;this._filterManager.applyFilters(),this._state.set("crop.rect",null),this._state.set("crop.dirty",!1),a&&this._cropManager.enable()}return this._state.set("transform.rotation",i),this.emit("transformChanged",{rotation:i}),!0}resetRotation(){return this.setRotationAngle(0)}toggleTheme(){const e=this._state.get("isDarkMode");this._state.set("isDarkMode",!e)}setTheme(e){this._state.set("theme",e),this._state.detectTheme()}setMode(e){e==="crop"?this._cropManager.enable():this._cropManager.disable(),this._state.set("mode",e)}getState(){return this._state.getAll()}async removeBackground(e={}){if(!this._removeBgManager)throw new Error("Background removal is not enabled");if(!this._state.get("hasImage"))throw new Error("No image loaded");this._state.set("isProcessing",!0),this._showLoadingOverlay("Removing background...");try{const t=this.exportImage("png");if(!t)throw new Error("Failed to export image for background removal");const i=await this._removeBgManager.removeBackground(t,e);return await this.loadImage(i.dataUrl),this.emit("background-removed",{model:i.model,processMs:i.processMs}),{model:i.model,processMs:i.processMs}}catch(t){throw this.emit("error",{error:t,context:"background-removal"}),t}finally{this._state.set("isProcessing",!1),this._hideLoadingOverlay()}}async isBackgroundRemovalAvailable(){return this._removeBgManager?this._removeBgManager.isAvailable():!1}_showLoadingOverlay(e){var i;if(!this._loadingOverlay)this._loadingOverlay=f("div",{className:"editor-loading-overlay"},[f("div",{className:"editor-loading-spinner"}),f("div",{className:"editor-loading-text"},e)]);else{const r=this._loadingOverlay.querySelector(".editor-loading-text");r&&(r.textContent=e)}const t=(i=this._canvasContainer)==null?void 0:i.parentElement;t&&!this._loadingOverlay.parentElement&&t.appendChild(this._loadingOverlay)}_hideLoadingOverlay(){var e;(e=this._loadingOverlay)==null||e.remove()}destroy(){var e,t,i,r,a,o,n,l,c,d;this._destroyed=!0;for(const h of this._objectUrls)try{URL.revokeObjectURL(h)}catch{}this._objectUrls.clear(),(e=this._resizeObserver)==null||e.disconnect(),this._renderer.destroy(),this._cropManager.disable(),this._handleWindowResize&&window.removeEventListener("resize",this._handleWindowResize),(t=this._toolbar)==null||t.destroy(),(i=this._categoryCarousel)==null||i.destroy(),(r=this._filterCarousel)==null||r.destroy(),(a=this._filterAdjustments)==null||a.destroy(),(o=this._mobileFilterDrawer)==null||o.destroy(),(n=this._mobileActiveFilters)==null||n.destroy(),(l=this._cropControls)==null||l.destroy(),(c=this._activeFiltersPanel)==null||c.destroy(),(d=this._editorEl)==null||d.remove(),this._container=null,this._state=null,this.emit("destroyed"),this.removeAllListeners()}}const I=new Map,j=new Map;function Dt(s,e){return!Array.isArray(s.mediaTargets)||s.mediaTargets.length===0?!0:s.mediaTargets.includes(e)}function m(s){var e;return I.has(s.id),I.set(s.id,s),j.has(s.category)||j.set(s.category,[]),(e=j.get(s.category))==null||e.push(s.id),s}function qe(s){return I.get(s)}function K(){return Array.from(I.values())}function He(){K().map(t=>t.id),Object.entries(y).filter(t=>/Filter$/.test(t[0])&&typeof t[1]=="function").forEach(([t,i])=>{const r=t.replace(/Filter$/,"").replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();I.has(r)||m({id:r,name:t.replace(/Filter$/,""),category:"unlisted",mediaTargets:["image"],defaultParams:{},controls:[],createFilter:(a={})=>{try{return new i(a)}catch{return null}}})})}function $e(s){return(j.get(s)||[]).map(t=>I.get(t)).filter(Boolean)}function We(){return Array.from(j.keys())}function Lt(s){return I.has(s)}function Vt(s){const e=I.get(s);if(!e)return!1;I.delete(s);const t=j.get(e.category);if(t){const i=t.indexOf(s);i!==-1&&t.splice(i,1),t.length===0&&j.delete(e.category)}return!0}function Ut(s,e){const t=I.get(s);return t?Dt(t,e):!1}function Ze(){return Array.from(I.values()).map(s=>({id:s.id,name:s.name,category:s.category,controls:s.controls}))}if(typeof window<"u"){window.__DEBUG_FILTERS_LIST=Array.from(I.keys()),window.getAllFilters=K,window.getFilter=qe,window.getFiltersByCategory=$e,window.getRegisteredFilters=Ze;const s=m;window.registerFilter=e=>{const t=s(e);return window.__DEBUG_FILTERS_LIST=Array.from(I.keys()),t}}typeof window<"u"&&(window.initializeFilterRegistry=window.initializeFilterRegistry||function(){return[]});const{AdjustmentFilter:jt}=y,{ColorMatrixFilter:qt}=T,X={gamma:1,saturation:1,contrast:1,brightness:1,red:1,green:1,blue:1,alpha:1},Ht=new Set(["gamma","saturation","contrast","brightness","red","green","blue","alpha"]);function O(s,e){if(typeof s=="number"&&Number.isFinite(s))return s;if(typeof s=="string"){const t=Number(s);if(Number.isFinite(t))return t}return e}function Ce(s){return Ht.has(s)}function $t(s){return{gamma:O(s.gamma,X.gamma),saturation:O(s.saturation,X.saturation),contrast:O(s.contrast,X.contrast),brightness:O(s.brightness,X.brightness),red:O(s.red,X.red),green:O(s.green,X.green),blue:O(s.blue,X.blue),alpha:O(s.alpha,X.alpha)}}function we(s,e){s.reset(),s.brightness(e.brightness,!0),s.contrast(e.contrast,!0),s.saturate(e.saturation,!0)}m({id:"adjustment",name:"Adjustment",category:"adjust",description:"Adjust basic image properties like brightness, contrast, and saturation",createFilter:s=>{try{const e=$t(s??{}),t={...e};try{const i=new jt(t),r=i;return r._customParams={...e},r.updateUIParam=function(o,n){try{if(!Ce(o))return;const l=this._customParams??{...X},c=O(n,l[o]);l[o]=c,this._customParams=l;const d=this;o in d&&(d[o]=c)}catch{}},i}catch{const r=new qt,a=r;return a._customParams={...e},we(r,e),a.updateUIParam=function(n,l){try{if(!Ce(n))return;const c=this._customParams??{...X},d=O(l,c[n]);c[n]=d,this._customParams=c,we(this,c)}catch{}},r}}catch{return null}},defaultParams:{gamma:1,saturation:1,contrast:1,brightness:1,red:1,green:1,blue:1,alpha:1},controls:[{id:"brightness",type:"slider",label:"Brightness",property:"brightness",min:0,max:5,step:.01,default:1},{id:"contrast",type:"slider",label:"Contrast",property:"contrast",min:0,max:5,step:.01,default:1},{id:"saturation",type:"slider",label:"Saturation",property:"saturation",min:0,max:5,step:.01,default:1},{id:"gamma",type:"slider",label:"Gamma",property:"gamma",min:0,max:5,step:.01,default:1},{id:"red",type:"slider",label:"Red",property:"red",min:0,max:5,step:.01,default:1},{id:"green",type:"slider",label:"Green",property:"green",min:0,max:5,step:.01,default:1},{id:"blue",type:"slider",label:"Blue",property:"blue",min:0,max:5,step:.01,default:1},{id:"alpha",type:"slider",label:"Alpha",property:"alpha",min:0,max:1,step:.01,default:1}]});const{ColorMatrixFilter:Wt}=T,V={brightness:1,contrast:1,saturation:1,hue:0,sepia:0,negative:!1},Zt=new Set(["brightness","contrast","saturation","hue","sepia","negative"]);function Gt(s){return Zt.has(s)}function W(s,e){if(typeof s=="number"&&Number.isFinite(s))return s;if(typeof s=="string"){const t=Number(s);if(Number.isFinite(t))return t}return e}function Ge(s,e){if(typeof s=="boolean")return s;if(typeof s=="string"){if(s==="true")return!0;if(s==="false")return!1}return e}function Kt(s){return{brightness:W(s.brightness,V.brightness),contrast:W(s.contrast,V.contrast),saturation:W(s.saturation,V.saturation),hue:W(s.hue,V.hue),sepia:W(s.sepia,V.sepia),negative:Ge(s.negative,V.negative)}}function Se(s,e){s.reset(),e.brightness!==1&&s.brightness(e.brightness,!0),e.contrast!==1&&s.contrast(e.contrast,!0),e.saturation!==1&&s.saturate(e.saturation,!0),e.hue!==0&&s.hue(e.hue,!0),e.sepia>0&&s.sepia(!0),e.negative&&s.negative(!0)}m({id:"adjustment-advanced",name:"Advanced Adjustment",category:"adjust",description:"Comprehensive image adjustments including brightness, contrast, saturation, hue, and more",createFilter:s=>{try{const e=Kt(s??{}),t=new Wt,i=t;return i._customParams={...e},Se(t,e),i.updateUIParam=function(a,o){try{if(!Gt(a))return;const n=this._customParams??{...V};if(a==="negative")n.negative=Ge(o,n.negative);else{const l=a;n[l]=W(o,n[l])}this._customParams=n,Se(this,n)}catch{}},t}catch{return null}},defaultParams:{brightness:1,contrast:1,saturation:1,hue:0,sepia:0,negative:!1},controls:[{id:"brightness",type:"slider",label:"Brightness",property:"brightness",min:0,max:2,step:.01,default:1},{id:"contrast",type:"slider",label:"Contrast",property:"contrast",min:0,max:2,step:.01,default:1},{id:"saturation",type:"slider",label:"Saturation",property:"saturation",min:0,max:2,step:.01,default:1},{id:"hue",type:"slider",label:"Hue Rotation",property:"hue",min:0,max:360,step:1,default:0},{id:"sepia",type:"slider",label:"Sepia",property:"sepia",min:0,max:1,step:.01,default:0},{id:"negative",type:"toggle",label:"Negative",property:"negative",default:!1}]});const ve=s=>Math.max(0,Math.min(1,s));m({id:"alpha",name:"Alpha",category:"adjust",description:"Adjust the opacity of the image",createFilter:s=>{const e=ve(s.alpha!==void 0?Number(s.alpha):1),t=new T.AlphaFilter(e);return t.updateUIParam=function(i,r){i==="alpha"&&(this.alpha=ve(Number(r)))},t},defaultParams:{alpha:1},controls:[{id:"alpha",type:"slider",label:"Opacity",property:"alpha",min:0,max:1,step:.01,default:1}]});m({id:"blur",name:"Blur",category:"blur",description:"Apply a smooth blur effect to the entire image",createFilter:s=>{try{const e=new T.BlurFilter({strength:s.blur||8,quality:s.quality||4});return e._customParams={...s},e.updateUIParam=function(t,i){const r=this._customParams||{};switch(this._customParams=r,r[t]=i,t){case"blur":this.strength=i;break;case"quality":this.quality=i;break;default:t in this&&(this[t]=i);break}return!0},e}catch{return null}},defaultParams:{blur:8,quality:4},controls:[{id:"blur",type:"slider",label:"Blur",property:"blur",min:0,max:100,step:.1,default:8},{id:"quality",type:"slider",label:"Quality",property:"quality",min:1,max:10,step:1,default:4}]});function Me(s,e){typeof s.reset=="function"&&s.reset(),e.brightness!==1&&s.brightness(e.brightness,!1),e.contrast!==1&&s.contrast(e.contrast,!1),e.saturation!==1&&s.saturate(e.saturation,!1),e.hue!==0&&s.hue(e.hue,!1),e.sepia&&s.sepia(!1),e.negative&&s.negative(!1)}function ke(s){return{brightness:Number(s.brightness??1),contrast:Number(s.contrast??1),saturation:Number(s.saturation??1),hue:Number(s.hue??0),sepia:!!s.sepia,negative:!!s.negative}}m({id:"color-matrix",name:"Color Matrix",category:"advanced",description:"Advanced color adjustments including sepia, hue rotation, and negative",createFilter:s=>{const e=T.ColorMatrixFilter;if(!e)return null;const t=new e,i=ke(s);return t._customParams={...i},Me(t,i),t.updateUIParam=function(r,a){const o=this._customParams??ke({});switch(r){case"brightness":case"contrast":case"saturation":case"hue":o[r]=Number(a);break;case"sepia":case"negative":o[r]=!!a;break;default:return}this._customParams=o,Me(this,o)},t},defaultParams:{brightness:1,contrast:1,saturation:1,hue:0,sepia:!1,negative:!1},controls:[{id:"brightness",type:"slider",label:"Brightness",property:"brightness",min:0,max:5,step:.1,default:1},{id:"contrast",type:"slider",label:"Contrast",property:"contrast",min:0,max:5,step:.1,default:1},{id:"saturation",type:"slider",label:"Saturation",property:"saturation",min:0,max:5,step:.1,default:1},{id:"hue",type:"slider",label:"Hue Rotation",property:"hue",min:-180,max:180,step:1,default:0},{id:"sepia",type:"toggle",label:"Sepia",property:"sepia",default:!1},{id:"negative",type:"toggle",label:"Negative",property:"negative",default:!1}]});const{ColorOverlayFilter:Qt}=y;m({id:"colorOverlay",name:"Color Overlay",category:"color",description:"Apply a colored tint or overlay to the entire image",createFilter:s=>{try{let e=16711680;s.color&&(typeof s.color=="string"?e=parseInt(s.color.replace("#","0x"),16):typeof s.color=="number"&&(e=s.color));const t=new Qt({color:e,alpha:s.alpha||.5});return t._customParams={...s},t.updateUIParam=function(i,r){const a=this._customParams||{};switch(this._customParams=a,a[i]=r,i){case"color":let o;typeof r=="string"?o=parseInt(r.replace("#","0x"),16):o=Number(r),this.color=o,this.uniforms&&(this.uniforms.uColor=o);break;case"alpha":this.alpha=Number(r),this.uniforms&&(this.uniforms.uAlpha=Number(r));break;default:i in this&&(this[i]=r);break}return!0},t}catch{return null}},defaultParams:{color:"#ff0000",alpha:.5},controls:[{id:"color",type:"color",label:"Color",property:"color",default:"#ff0000"},{id:"alpha",type:"slider",label:"Opacity",property:"alpha",min:0,max:1,step:.01,default:.5}]});m({id:"drop-shadow",name:"Drop Shadow",category:"effects",description:"Add a soft drop shadow to the image",createFilter:s=>{try{const e=s.color?s.color.replace("#","0x"):"0x000000",t=s.distance!==void 0?s.distance:5,i=s.angle!==void 0?s.angle:90,r=s.blur!==void 0?s.blur:2,a=s.quality!==void 0?s.quality:3,o={x:t*Math.cos(i*Math.PI/180),y:t*Math.sin(i*Math.PI/180)},n=new y.DropShadowFilter({offset:o,color:parseInt(e,16),alpha:s.alpha!==void 0?s.alpha:.5,blur:r,quality:a,shadowOnly:s.shadowOnly!==void 0?s.shadowOnly:!1,pixelSize:{x:s.pixelSizeX!==void 0?s.pixelSizeX:1,y:s.pixelSizeY!==void 0?s.pixelSizeY:1}}),l=(h,u,p,b)=>{const g=h*u*2,x=Math.sqrt(p*p+b*b);return Math.ceil(g+x+2)};n._exportPadding=l(r,a,o.x,o.y),n.padding=Math.max(n.padding??0,n._exportPadding),n._customParams={...s,_offset:o,_distance:t,_angle:i};const c=(h,u)=>{const p=Number(h._distance??h.distance??5)*u,b=Number(h._angle??h.angle??90),g=Number(h.blur??2)*u,x=Number(h.quality??3),P={x:p*Math.cos(b*Math.PI/180),y:p*Math.sin(b*Math.PI/180)},v=h.color?String(h.color).replace("#","0x"):"0x000000",E=new y.DropShadowFilter({offset:P,color:parseInt(v,16),alpha:h.alpha!==void 0?Number(h.alpha):.5,blur:g,quality:x,shadowOnly:h.shadowOnly!==void 0?!!h.shadowOnly:!1,pixelSize:{x:h.pixelSizeX!==void 0?Number(h.pixelSizeX):1,y:h.pixelSizeY!==void 0?Number(h.pixelSizeY):1}}),z=l(g,x,P.x,P.y);return E._exportPadding=z,E.padding=Math.max(E.padding??0,z),E};n.createExportFilter=function(h={}){const u=Number.isFinite(h.previewToNativeScale)?Math.max(1,Number(h.previewToNativeScale)):1,p=this._customParams||s;return c(p,u)},n.getExportPadding=function(){return Number(this._exportPadding||this.padding||0)};const d=h=>{var x;const u=((x=h._customParams)==null?void 0:x._offset)??{x:0,y:0},p=Number(h.blur??0),b=Number(h.quality??1),g=l(p,b,u.x,u.y);h._exportPadding=g,h.padding=Math.max(h.padding??0,g)};return n.updateUIParam=function(h,u){try{const p=this._customParams||{};switch(this._customParams=p,p[h]=u,h){case"color":typeof u=="string"&&(this.color=parseInt(u.replace("#","0x"),16));break;case"alpha":this.alpha=Number(u);break;case"blur":this.blur=Number(u),d(this);break;case"quality":this.quality=Number(u),d(this);break;case"shadowOnly":this.shadowOnly=!!u;break;case"pixelSizeX":this.pixelSizeX=Number(u),p.pixelSizeX=Number(u);break;case"pixelSizeY":this.pixelSizeY=Number(u),p.pixelSizeY=Number(u);break;case"distance":case"angle":{h==="distance"?(p._distance=Number(u),p.distance=Number(u)):(p._angle=Number(u),p.angle=Number(u));const b={x:p._distance*Math.cos(p._angle*Math.PI/180),y:p._distance*Math.sin(p._angle*Math.PI/180)};p._offset=b,this.offset=b,d(this);break}default:h in this&&(this[h]=u);break}return!0}catch{return this._customParams&&(this._customParams[h]=u),!1}},n}catch{return null}},defaultParams:{alpha:.5,blur:2,color:"#000000",distance:5,angle:90,quality:3,shadowOnly:!1,pixelSizeX:1,pixelSizeY:1},controls:[{id:"alpha",type:"slider",label:"Opacity",property:"alpha",min:0,max:1,step:.01,default:.5},{id:"blur",type:"slider",label:"Blur",property:"blur",min:0,max:20,step:.1,default:2},{id:"color",type:"color",label:"Color",property:"color",default:"#000000"},{id:"distance",type:"slider",label:"Distance",property:"distance",min:0,max:50,step:1,default:5},{id:"angle",type:"slider",label:"Angle",property:"angle",min:0,max:360,step:1,default:90},{id:"quality",type:"slider",label:"Quality",property:"quality",min:0,max:20,step:1,default:3},{id:"shadowOnly",type:"toggle",label:"Shadow Only",property:"shadowOnly",default:!1},{id:"pixelSizeX",type:"slider",label:"Pixel Size X",property:"pixelSizeX",min:.5,max:8,step:.5,default:1},{id:"pixelSizeY",type:"slider",label:"Pixel Size Y",property:"pixelSizeY",min:.5,max:8,step:.5,default:1}]});const{ColorMatrixFilter:Jt}=T;m({id:"grayscale",name:"Grayscale",category:"color",description:"Convert the image to black and white with adjustable intensity",createFilter:s=>{try{const e=new Jt;e._customParams={...s};const t=s.intensity!==void 0?s.intensity:1;return Pe(e,t),e.updateUIParam=function(i,r){const a=this._customParams||{};switch(this._customParams=a,a[i]=r,i){case"intensity":Pe(this,r);break;default:i in this&&(this[i]=r);break}return!0},e}catch{return null}},defaultParams:{intensity:.35},controls:[{id:"intensity",type:"slider",label:"Intensity",property:"intensity",min:0,max:1,step:.01,default:.35}]});function Pe(s,e){s.reset(),s.greyscale(e)}const{HslAdjustmentFilter:ei}=y;m({id:"hsl-adjustment",name:"HSL Adjustment",category:"color",description:"Control hue, saturation, and lightness independently",createFilter:s=>{try{const e=new ei({hue:s.hue!==void 0?s.hue:0,saturation:s.saturation!==void 0?s.saturation:0,lightness:s.lightness!==void 0?s.lightness:0,colorize:s.colorize!==void 0?s.colorize:!1,alpha:s.alpha!==void 0?s.alpha:1});return e._customParams={...s},e.updateUIParam=function(t,i){try{const r=this._customParams||{};switch(this._customParams=r,r[t]=i,t){case"hue":this.hue=Number(i),this.uniforms&&(this.uniforms.uHue=Number(i));break;case"saturation":this.saturation=Number(i),this.uniforms&&(this.uniforms.uSaturation=Number(i));break;case"lightness":this.lightness=Number(i),this.uniforms&&(this.uniforms.uLightness=Number(i));break;case"colorize":this.colorize=!!i,this.uniforms&&(this.uniforms.uColorize=i?1:0);break;case"alpha":this.alpha=Number(i),this.uniforms&&(this.uniforms.uAlpha=Number(i));break;default:t in this&&(this[t]=i);break}return!0}catch{return this._customParams&&(this._customParams[t]=i),!1}},e}catch{return null}},defaultParams:{hue:0,saturation:0,lightness:0,colorize:!1,alpha:1},controls:[{id:"hue",type:"slider",label:"Hue",property:"hue",min:-180,max:180,step:1,default:0},{id:"saturation",type:"slider",label:"Saturation",property:"saturation",min:-1,max:1,step:.01,default:0},{id:"lightness",type:"slider",label:"Lightness",property:"lightness",min:-1,max:1,step:.01,default:0},{id:"colorize",type:"toggle",label:"Colorize",property:"colorize",default:!1},{id:"alpha",type:"slider",label:"Alpha",property:"alpha",min:0,max:1,step:.01,default:1}]});const{KawaseBlurFilter:ti}=y;m({id:"kawase-blur",name:"Kawase Blur",category:"blur",description:"A more optimized blur algorithm that is faster than standard blur",createFilter:s=>{try{const e=new ti({strength:s.strength||4,quality:s.quality||3,clamp:s.clamp||!1,pixelSize:s.pixelSize||1});return e._customParams={...s},e.updateUIParam=function(t,i){const r=this._customParams||{};switch(this._customParams=r,r[t]=i,t){case"strength":this.strength=i;break;case"quality":this.quality=i;break;case"clamp":this.clamp=i;break;case"pixelSize":typeof i=="number"?this.pixelSize=i:typeof i=="object"&&i!==null&&"x"in i&&"y"in i&&(this.pixelSize=i);break;case"pixelSizeX":this.pixelSizeX=i;break;case"pixelSizeY":this.pixelSizeY=i;break;default:t in this&&(this[t]=i);break}return!0},e}catch{return null}},defaultParams:{strength:4,quality:3,clamp:!1,pixelSize:1},controls:[{id:"strength",type:"slider",label:"Strength",property:"strength",min:0,max:20,step:.1,default:4},{id:"quality",type:"slider",label:"Quality",property:"quality",min:1,max:20,step:1,default:3},{id:"clamp",type:"toggle",label:"Clamp Edges",property:"clamp",default:!1},{id:"pixelSize",type:"slider",label:"Pixel Size",property:"pixelSize",min:.5,max:10,step:.5,default:1},{id:"pixelSizeX",type:"slider",label:"Pixel Size X",property:"pixelSizeX",min:0,max:10,step:.1,default:1},{id:"pixelSizeY",type:"slider",label:"Pixel Size Y",property:"pixelSizeY",min:0,max:10,step:.1,default:1}]});const{MotionBlurFilter:ii}=y;m({id:"motion-blur",name:"Motion Blur",category:"blur",description:"Creates a directional blur effect simulating motion",createFilter:s=>{try{const e=new ii({velocity:{x:s.velocityX!==void 0?s.velocityX:0,y:s.velocityY!==void 0?s.velocityY:0},kernelSize:s.kernelSize||5,offset:s.offset!==void 0?s.offset:0});return e._customParams={...s},e.updateUIParam=function(t,i){const r=this._customParams||{};switch(this._customParams=r,r[t]=i,t){case"velocityX":this.velocityX=i;break;case"velocityY":this.velocityY=i;break;case"kernelSize":this.kernelSize=i;break;case"offset":this.offset=i;break;default:t in this&&(this[t]=i);break}return!0},e}catch{return null}},defaultParams:{velocityX:0,velocityY:0,kernelSize:5,offset:0},controls:[{id:"velocityX",type:"slider",label:"Velocity X",property:"velocityX",min:-90,max:90,step:1,default:0},{id:"velocityY",type:"slider",label:"Velocity Y",property:"velocityY",min:-90,max:90,step:1,default:0},{id:"kernelSize",type:"select",label:"Kernel Size",property:"kernelSize",options:[{label:"3",value:3},{label:"5",value:5},{label:"7",value:7},{label:"9",value:9},{label:"11",value:11},{label:"13",value:13},{label:"15",value:15},{label:"17",value:17},{label:"19",value:19},{label:"21",value:21},{label:"23",value:23},{label:"25",value:25}],default:5},{id:"offset",type:"slider",label:"Offset",property:"offset",min:-150,max:150,step:1,default:0}]});const{RadialBlurFilter:ri}=y;m({id:"radial-blur",name:"Radial Blur",category:"blur",description:"Creates a circular blur effect emanating from a center point",createFilter:s=>{try{const e=new ri({angle:s.angle??20,center:{x:s.centerX??0,y:s.centerY??0},kernelSize:s.kernelSize??15,radius:s.radius??300});return e._customParams={centerX:s.centerX??0,centerY:s.centerY??0},e.updateUIParam=function(t,i){try{switch(t){case"angle":this.angle=Number(i);break;case"centerX":this._customParams.centerX=Number(i),this.center={x:Number(i),y:this._customParams.centerY};break;case"centerY":this._customParams.centerY=Number(i),this.center={x:this._customParams.centerX,y:Number(i)};break;case"kernelSize":this.kernelSize=Number(i);break;case"radius":this.radius=Number(i);break;default:}}catch{}},e}catch{return null}},defaultParams:{angle:20,centerX:0,centerY:0,kernelSize:15,radius:300},controls:[{id:"angle",type:"slider",label:"Angle",property:"angle",min:-180,max:180,step:1,default:20},{id:"centerX",type:"slider",label:"Center X",property:"centerX",min:-1,max:1,step:.01,default:0},{id:"centerY",type:"slider",label:"Center Y",property:"centerY",min:-1,max:1,step:.01,default:0},{id:"kernelSize",type:"select",label:"Kernel Size",property:"kernelSize",options:[{label:"3",value:3},{label:"5",value:5},{label:"7",value:7},{label:"9",value:9},{label:"11",value:11},{label:"13",value:13},{label:"15",value:15},{label:"17",value:17},{label:"19",value:19},{label:"21",value:21},{label:"23",value:23},{label:"25",value:25}],default:15},{id:"radius",type:"slider",label:"Radius",property:"radius",min:-1,max:1e3,step:10,default:300}]});const{TiltShiftFilter:si}=y;m({id:"tilt-shift",name:"Tilt Shift",category:"blur",description:"Creates a depth-of-field effect simulating miniature photography",createFilter:s=>{try{const e=typeof s.blur=="number"?s.blur:100,t=typeof s.gradientBlur=="number"?s.gradientBlur:600,i=typeof s.startX=="number"?s.startX:0,r=typeof s.startY=="number"?s.startY:.5,a=typeof s.endX=="number"?s.endX:1,o=typeof s.endY=="number"?s.endY:.5,n=new si({blur:Number(e),gradientBlur:Number(t),start:{x:Number(i),y:Number(r)},end:{x:Number(a),y:Number(o)}});return n._customParams={blur:e,gradientBlur:t,startX:i,startY:r,endX:a,endY:o},n.updateUIParam=function(l,c){try{const d=Number(c),h=this._customParams||{};switch(this._customParams=h,h[l]=d,l){case"blur":this.blur=d;break;case"gradientBlur":this.gradientBlur=d;break;case"startX":this.start&&typeof this.start=="object"&&(this.start.x=d);break;case"startY":this.start&&typeof this.start=="object"&&(this.start.y=d);break;case"endX":this.end&&typeof this.end=="object"&&(this.end.x=d);break;case"endY":this.end&&typeof this.end=="object"&&(this.end.y=d);break;default:l in this&&(this[l]=d);break}}catch{}},n}catch{return null}},defaultParams:{blur:100,gradientBlur:600,startX:0,startY:.5,endX:1,endY:.5},controls:[{id:"blur",type:"slider",label:"Blur Strength",property:"blur",min:0,max:200,step:1,default:100},{id:"gradientBlur",type:"slider",label:"Gradient Width",property:"gradientBlur",min:0,max:1e3,step:10,default:600},{id:"startX",type:"slider",label:"Start X",property:"startX",min:0,max:1,step:.01,default:0},{id:"startY",type:"slider",label:"Start Y",property:"startY",min:0,max:1,step:.01,default:.5},{id:"endX",type:"slider",label:"End X",property:"endX",min:0,max:1,step:.01,default:1},{id:"endY",type:"slider",label:"End Y",property:"endY",min:0,max:1,step:.01,default:.5}]});const{ZoomBlurFilter:ai}=y;m({id:"zoom-blur",name:"Zoom Blur",category:"blur",description:"Creates a zoom blur effect from a center point",createFilter:s=>{try{const e=new ai({strength:s.strength||.1,center:{x:s.centerX!==void 0?s.centerX:.5,y:s.centerY!==void 0?s.centerY:.5},innerRadius:s.innerRadius||80,radius:s.radius!==void 0?s.radius:-1,maxKernelSize:s.maxKernelSize||32});return e._customParams={...s},e.updateUIParam=function(t,i){const r=this._customParams||{};switch(this._customParams=r,r[t]=i,t){case"strength":this.strength=i;break;case"centerX":this.centerX=i;break;case"centerY":this.centerY=i;break;case"innerRadius":this.innerRadius=i;break;case"radius":this.radius=i;break;default:t in this&&(this[t]=i);break}return!0},e}catch{return null}},defaultParams:{strength:.1,centerX:.5,centerY:.5,innerRadius:80,radius:-1,maxKernelSize:32},controls:[{id:"strength",type:"slider",label:"Strength",property:"strength",min:0,max:.5,step:.01,default:.1},{id:"centerX",type:"slider",label:"Center X",property:"centerX",min:0,max:1,step:.01,default:.5},{id:"centerY",type:"slider",label:"Center Y",property:"centerY",min:0,max:1,step:.01,default:.5},{id:"innerRadius",type:"slider",label:"Inner Radius",property:"innerRadius",min:0,max:1e3,step:1,default:80},{id:"radius",type:"slider",label:"Outer Radius",property:"radius",min:-1,max:1e3,step:10,default:-1},{id:"maxKernelSize",type:"select",label:"Quality",property:"maxKernelSize",options:[{label:"Low",value:16},{label:"Medium",value:32},{label:"High",value:48},{label:"Very High",value:64}],default:32}]});const{ColorGradientFilter:Fe}=y;function Ke(s){return parseInt(s.replace("#","0x"),16)}function oi(s){return"#"+s.toString(16).padStart(6,"0")}function Ae(s){return{offset:Number(s.offset),color:typeof s.color=="string"?Ke(s.color):Number(s.color),alpha:Number(s.alpha)}}function Ne(s){return{offset:s.offset,color:typeof s.color=="number"?oi(s.color):s.color,alpha:s.alpha}}m({id:"color-gradient",name:"Color Gradient",category:"color",description:"Applies a linear, radial or conic color gradient over the image with multiple color stops",createFilter:s=>{let t=(s.colorStops||[{offset:0,color:"#ff0000",alpha:1},{offset:1,color:"#0000ff",alpha:1}]).map(Ae);t.length<2&&(t=[{offset:0,color:16711680,alpha:1},{offset:1,color:255,alpha:1}]),t.sort((r,a)=>r.offset-a.offset);const i=new Fe({type:s.gradientType,stops:t,angle:s.angle,alpha:s.alpha,maxColors:s.maxColors||0,replace:s.replace});return i._customParams={cssGradient:s.cssGradient||""},i.getSerializableParams=function(){var a;const r=Array.isArray(this.stops)?this.stops.map(Ne):[];return{gradientType:this.type,colorStops:r,angle:this.angle,alpha:this.alpha,maxColors:this.maxColors,replace:this.replace,cssGradient:((a=this._customParams)==null?void 0:a.cssGradient)??""}},i.getColorStopsForUI=function(){return Array.isArray(this.stops)?this.stops.map(Ne):[]},i.getDynamicControls=function(){const r=this.getColorStopsForUI(),a=[];return r.forEach((o,n)=>{a.push({id:`colorStop-${n}-color`,type:"color",label:`Stop ${n+1} Color`,property:`colorStops[${n}].color`,default:o.color}),a.push({id:`colorStop-${n}-offset`,type:"slider",label:`Stop ${n+1} Position`,property:`colorStops[${n}].offset`,min:0,max:1,step:.01,default:o.offset}),a.push({id:`colorStop-${n}-alpha`,type:"slider",label:`Stop ${n+1} Alpha`,property:`colorStops[${n}].alpha`,min:0,max:1,step:.01,default:o.alpha})}),a},i.handleButtonAction=function(r){(r==="addColorStop"||r==="removeColorStop")&&this.updateUIParam(r,!0)},i.updateUIParam=function(r,a){const o=this._customParams??{};switch(this._customParams=o,r){case"gradientType":this.type=Number(a);return;case"angle":case"alpha":case"maxColors":this[r]=Number(a);return;case"replace":this.replace=!!a;return;case"addColorStop":{const n=Array.isArray(this.stops)?[...this.stops]:[],l=Math.floor(Math.random()*255)<<16|Math.floor(Math.random()*255)<<8|Math.floor(Math.random()*255);if(n.length>0)for(const d of n)d.offset*=.8;n.push({offset:1,color:l,alpha:1}),n.sort((c,d)=>c.offset-d.offset),this.stops=n;return}case"removeColorStop":{const n=Array.isArray(this.stops)?[...this.stops]:[];n.length>2&&(n.pop(),this.stops=n);return}case"cssGradient":{const n=typeof a=="string"?a.trim():"";if(o.cssGradient=n,!n)return;try{const l=new Fe({css:n});this.type=l.type,this.angle=l.angle,this.stops=[...l.stops]}catch{}return}case"colorStops":{if(!Array.isArray(a))return;const n=a.map(Ae);n.sort((l,c)=>l.offset-c.offset),this.stops=n;return}default:{const n=/^colorStops\[(\d+)\]\.(offset|color|alpha)$/.exec(r);if(n){const[,l,c]=n,d=Number(l),h=Array.isArray(this.stops)?[...this.stops]:[];if(d<0||d>=h.length)return;c==="color"?h[d].color=typeof a=="string"?Ke(a):Number(a):(c==="offset"||c==="alpha")&&(h[d][c]=Number(a)),this.stops=h}}}},i},defaultParams:{gradientType:0,colorStops:[{offset:0,color:"#ff0000",alpha:1},{offset:1,color:"#0000ff",alpha:1}],cssGradient:"",angle:90,alpha:.75,maxColors:0,replace:!1},controls:[{id:"gradientType",type:"select",label:"Gradient Type",property:"gradientType",options:[{label:"Linear",value:0},{label:"Radial",value:1},{label:"Conic",value:2}],default:0},{id:"angle",type:"slider",label:"Angle",property:"angle",min:0,max:360,step:1,default:90},{id:"alpha",type:"slider",label:"Overall Alpha",property:"alpha",min:0,max:1,step:.01,default:.75},{id:"maxColors",type:"slider",label:"Max Colors",property:"maxColors",min:0,max:24,step:1,default:0},{id:"replace",type:"toggle",label:"Replace Original Colors",property:"replace",default:!1},{id:"addColorStop",type:"button",label:"Add New Color Stop",action:"addColorStop"},{id:"removeColorStop",type:"button",label:"Remove Last Color Stop",action:"removeColorStop"},{id:"cssGradient",type:"text",label:"CSS Gradient",property:"cssGradient",default:"",placeholder:"e.g. linear-gradient(to right, red, blue)"}]});m({id:"color-map",name:"Color Map",category:"color",description:"Maps colors using a reference texture as a lookup table",createFilter:s=>{try{const e=y.ColorMapFilter;if(!e)return null;let t=null;s.texturePath?t=T.Texture.from(s.texturePath):t=T.Texture.from("/examples/filters-main/examples/images/colormap.png");const i=new e({colorMap:t,nearest:s.nearest,mix:s.mix});return i._customParams={...s},i.updateUIParam=function(r,a){const o=this._customParams||{};switch(this._customParams=o,o[r]=a,r){case"texturePath":a&&(this.colorMap=T.Texture.from(a));break;case"mix":this.mix=a;break;case"nearest":this.nearest=a;break;default:r in this&&(this[r]=a);break}return!0},i}catch{return null}},defaultParams:{texturePath:"",mix:1,nearest:!1},controls:[{id:"texturePath",type:"select",label:"Color Map",property:"texturePath",options:[{label:"Default",value:"/examples/filters-main/examples/images/colormap.png"},{label:"Grayscale",value:"/examples/filters-main/examples/images/colormap-grayscale.png"},{label:"Sepia",value:"/examples/filters-main/examples/images/colormap-sepia.png"}],default:"/examples/filters-main/examples/images/colormap.png"},{id:"mix",type:"slider",label:"Mix",property:"mix",min:0,max:1,step:.01,default:1},{id:"nearest",type:"toggle",label:"Nearest Neighbor Sampling",property:"nearest",default:!1}]});const ni=y.ColorReplaceFilter;m({id:"color-replace",name:"Color Replace",category:"color",description:"Replaces a specific color in the image with another color",createFilter:s=>{try{let e=16711680;s.originalColor&&(typeof s.originalColor=="string"?e=parseInt(s.originalColor.replace("#","0x"),16):typeof s.originalColor=="number"&&(e=s.originalColor));let t=255;s.targetColor&&(typeof s.targetColor=="string"?t=parseInt(s.targetColor.replace("#","0x"),16):typeof s.targetColor=="number"&&(t=s.targetColor));const i=new ni({originalColor:e,targetColor:t,tolerance:s.tolerance||.4});return i._customParams={...s},i.updateUIParam=function(r,a){const o=this._customParams||{};switch(this._customParams=o,o[r]=a,r){case"originalColor":typeof a=="string"?this.originalColor=parseInt(a.replace("#","0x"),16):typeof a=="number"&&(this.originalColor=a);break;case"targetColor":typeof a=="string"?this.targetColor=parseInt(a.replace("#","0x"),16):typeof a=="number"&&(this.targetColor=a);break;case"tolerance":this.tolerance=a;break;default:r in this&&(this[r]=a);break}return!0},i}catch{return null}},defaultParams:{originalColor:"#ff0000",targetColor:"#0000ff",tolerance:.4},controls:[{id:"originalColor",type:"color",label:"Original Color",property:"originalColor",default:"#ff0000"},{id:"targetColor",type:"color",label:"Target Color",property:"targetColor",default:"#0000ff"},{id:"tolerance",type:"slider",label:"Tolerance",property:"tolerance",min:0,max:1,step:.01,default:.4}]});const li=y.MultiColorReplaceFilter;m({id:"multi-color-replace",name:"Multi-Color Replace",category:"color",description:"Replaces multiple colors in the image with different target colors",createFilter:s=>{try{const e=[];if(s.originalColor1&&s.targetColor1){const i=typeof s.originalColor1=="string"?parseInt(s.originalColor1.replace("#","0x"),16):s.originalColor1,r=typeof s.targetColor1=="string"?parseInt(s.targetColor1.replace("#","0x"),16):s.targetColor1;e.push([i,r])}if(s.originalColor2&&s.targetColor2){const i=typeof s.originalColor2=="string"?parseInt(s.originalColor2.replace("#","0x"),16):s.originalColor2,r=typeof s.targetColor2=="string"?parseInt(s.targetColor2.replace("#","0x"),16):s.targetColor2;e.push([i,r])}if(s.enableThirdPair&&s.originalColor3&&s.targetColor3){const i=typeof s.originalColor3=="string"?parseInt(s.originalColor3.replace("#","0x"),16):s.originalColor3,r=typeof s.targetColor3=="string"?parseInt(s.targetColor3.replace("#","0x"),16):s.targetColor3;e.push([i,r])}const t=new li(e,s.tolerance||.05,3);return t._customParams={...s},t.updateUIParam=function(i,r){const a=this._customParams||{};if(this._customParams=a,a[i]=r,i==="originalColor1"||i==="targetColor1"||i==="originalColor2"||i==="targetColor2"||i==="originalColor3"||i==="targetColor3"||i==="enableThirdPair"){const o=[];if(a.originalColor1&&a.targetColor1){const n=typeof a.originalColor1=="string"?parseInt(a.originalColor1.replace("#","0x"),16):a.originalColor1,l=typeof a.targetColor1=="string"?parseInt(a.targetColor1.replace("#","0x"),16):a.targetColor1;o.push([n,l])}if(a.originalColor2&&a.targetColor2){const n=typeof a.originalColor2=="string"?parseInt(a.originalColor2.replace("#","0x"),16):a.originalColor2,l=typeof a.targetColor2=="string"?parseInt(a.targetColor2.replace("#","0x"),16):a.targetColor2;o.push([n,l])}if(a.enableThirdPair&&a.originalColor3&&a.targetColor3){const n=typeof a.originalColor3=="string"?parseInt(a.originalColor3.replace("#","0x"),16):a.originalColor3,l=typeof a.targetColor3=="string"?parseInt(a.targetColor3.replace("#","0x"),16):a.targetColor3;o.push([n,l])}this.replacements=o,this.refresh()}else i==="tolerance"?this.tolerance=r:i in this&&(this[i]=r);return!0},t}catch{return null}},defaultParams:{originalColor1:"#ff0000",targetColor1:"#0000ff",originalColor2:"#00ff00",targetColor2:"#ffff00",enableThirdPair:!1,originalColor3:"#ff00ff",targetColor3:"#00ffff",tolerance:.05},controls:[{id:"originalColor1",type:"color",label:"Original Color 1",property:"originalColor1",default:"#ff0000"},{id:"targetColor1",type:"color",label:"Target Color 1",property:"targetColor1",default:"#0000ff"},{id:"originalColor2",type:"color",label:"Original Color 2",property:"originalColor2",default:"#00ff00"},{id:"targetColor2",type:"color",label:"Target Color 2",property:"targetColor2",default:"#ffff00"},{id:"enableThirdPair",type:"toggle",label:"Enable Third Color Pair",property:"enableThirdPair",default:!1},{id:"originalColor3",type:"color",label:"Original Color 3",property:"originalColor3",default:"#ff00ff"},{id:"targetColor3",type:"color",label:"Target Color 3",property:"targetColor3",default:"#00ffff"},{id:"tolerance",type:"slider",label:"Tolerance",property:"tolerance",min:0,max:.5,step:.01,default:.05}]});const{RGBSplitFilter:ci}=y;m({id:"rgb-split",name:"RGB Split",category:"color",description:"Shifts the red, green, and blue channels to create a retro 3D or glitch effect",createFilter:s=>{try{const e={x:s.redX!==void 0?s.redX:-10,y:s.redY!==void 0?s.redY:0},t={x:s.greenX!==void 0?s.greenX:0,y:s.greenY!==void 0?s.greenY:10},i={x:s.blueX!==void 0?s.blueX:0,y:s.blueY!==void 0?s.blueY:0},r=new ci({red:e,green:t,blue:i});return r._customParams={...s},r.updateUIParam=function(a,o){try{const n=this._customParams||{};switch(this._customParams=n,n[a]=o,a){case"redX":this.redX=Number(o);break;case"redY":this.redY=Number(o);break;case"greenX":this.greenX=Number(o);break;case"greenY":this.greenY=Number(o);break;case"blueX":this.blueX=Number(o);break;case"blueY":this.blueY=Number(o);break;default:a in this&&(this[a]=o);break}return!0}catch{return this._customParams&&(this._customParams[a]=o),!1}},r}catch{return null}},defaultParams:{redX:-10,redY:0,greenX:0,greenY:10,blueX:0,blueY:0},controls:[{id:"redX",type:"slider",label:"Red X Offset",property:"redX",min:-20,max:20,step:1,default:-10},{id:"redY",type:"slider",label:"Red Y Offset",property:"redY",min:-20,max:20,step:1,default:0},{id:"greenX",type:"slider",label:"Green X Offset",property:"greenX",min:-20,max:20,step:1,default:0},{id:"greenY",type:"slider",label:"Green Y Offset",property:"greenY",min:-20,max:20,step:1,default:10},{id:"blueX",type:"slider",label:"Blue X Offset",property:"blueX",min:-20,max:20,step:1,default:0},{id:"blueY",type:"slider",label:"Blue Y Offset",property:"blueY",min:-20,max:20,step:1,default:0}]});const{AdvancedBloomFilter:hi}=y;m({id:"advanced-bloom",name:"Advanced Bloom",category:"light",description:"Adds a sophisticated bloom/glow effect with fine-grained control",createFilter:s=>{try{const e=new hi({threshold:s.threshold||.5,bloomScale:s.bloomScale||1,brightness:s.brightness||1,blur:s.blur||8,quality:s.quality||4,pixelSize:{x:s.pixelSizeX||1,y:s.pixelSizeY||1}});return e._customParams={pixelSizeX:s.pixelSizeX||1,pixelSizeY:s.pixelSizeY||1},e.updateUIParam=function(t,i){try{const r=this._customParams||{};switch(this._customParams=r,r[t]=i,t){case"threshold":this.threshold=Number(i);break;case"bloomScale":this.bloomScale=Number(i);break;case"brightness":this.brightness=Number(i);break;case"blur":this.blur=Number(i);break;case"quality":this.quality=Number(i);break;case"pixelSizeX":r.pixelSizeX=Number(i),this.pixelSize={x:Number(i),y:r.pixelSizeY};break;case"pixelSizeY":r.pixelSizeY=Number(i),this.pixelSize={x:r.pixelSizeX,y:Number(i)};break;default:t in this&&(this[t]=i);break}}catch{}},e}catch{return null}},defaultParams:{threshold:.5,bloomScale:1,brightness:1,blur:8,quality:4,pixelSizeX:1,pixelSizeY:1},controls:[{id:"threshold",type:"slider",label:"Threshold",property:"threshold",min:0,max:1,step:.01,default:.5},{id:"bloomScale",type:"slider",label:"Bloom Intensity",property:"bloomScale",min:0,max:3,step:.1,default:1},{id:"brightness",type:"slider",label:"Brightness",property:"brightness",min:0,max:3,step:.1,default:1},{id:"blur",type:"slider",label:"Blur Strength",property:"blur",min:0,max:20,step:1,default:8},{id:"quality",type:"slider",label:"Quality",property:"quality",min:1,max:10,step:1,default:4},{id:"pixelSizeX",type:"slider",label:"Pixel Size X",property:"pixelSizeX",min:.5,max:10,step:.5,default:1},{id:"pixelSizeY",type:"slider",label:"Pixel Size Y",property:"pixelSizeY",min:.5,max:10,step:.5,default:1}]});const di=y.AsciiFilter;m({id:"ascii",name:"ASCII",category:"stylize",description:"Convert image to ASCII text characters",createFilter:s=>{try{const e=typeof s.size=="number"?s.size:8;let t=s.color;typeof t=="string"&&t.startsWith("#")&&(t=parseInt(t.replace("#","0x"),16));const i=s.replaceColor===!0,r=new di({size:e,color:t,replaceColor:i});return r._customParams={size:e,color:t,replaceColor:i},r.updateUIParam=function(a,o){try{const n=this._customParams||{};switch(this._customParams=n,n[a]=o,a){case"size":this.size=Number(o);break;case"color":typeof o=="string"&&o.startsWith("#")?(n.color=o,this.color=parseInt(o.replace("#","0x"),16)):this.color=o;break;case"replaceColor":this.replaceColor=!!o;break;default:a in this&&(this[a]=o);break}}catch{}},r}catch{return null}},defaultParams:{size:8,color:"#ffffff",replaceColor:!1},controls:[{id:"size",type:"slider",label:"Character Size",property:"size",min:2,max:20,step:1,default:8},{id:"color",type:"color",label:"Character Color",property:"color",default:"#ffffff"},{id:"replaceColor",type:"toggle",label:"Replace Original Colors",property:"replaceColor",default:!1}]});const ui=y.BackdropBlurFilter;m({id:"backdrop-blur",name:"Backdrop Blur",category:"blur",description:"Blurs what is behind the object, creating a glass-like effect",createFilter:s=>{try{const e=new ui({strength:s.strength||20,quality:s.quality||4,resolution:s.resolution||.5,kernelSize:s.kernelSize||9});return e._customParams={...s},e.updateUIParam=function(t,i){try{const r=this._customParams||{};switch(this._customParams=r,r[t]=i,t){case"strength":this.strength=Number(i),this.blur=Number(i)/4;break;case"quality":this.quality=Number(i);break;case"resolution":this.resolution=Number(i);break;case"kernelSize":const a=Number(i);this.blurXFilter&&this.blurYFilter?(this.blurXFilter.kernelSize=a,this.blurYFilter.kernelSize=a):this.kernelSize=a;break;default:t in this&&(this[t]=i);break}}catch{}},e}catch{return null}},defaultParams:{strength:20,quality:4,resolution:.5,kernelSize:9},controls:[{id:"strength",type:"slider",label:"Strength",property:"strength",min:0,max:50,step:1,default:20},{id:"quality",type:"slider",label:"Quality",property:"quality",min:1,max:10,step:1,default:4},{id:"resolution",type:"slider",label:"Resolution",property:"resolution",min:.1,max:1,step:.1,default:.5},{id:"kernelSize",type:"select",label:"Kernel Size",property:"kernelSize",options:[{label:"5",value:5},{label:"7",value:7},{label:"9",value:9},{label:"11",value:11},{label:"13",value:13},{label:"15",value:15}],default:9}]});const{BevelFilter:pi}=y;m({id:"bevel",name:"Bevel",category:"effects",description:"Add a 3D-like beveled edge effect to the image",createFilter:s=>{try{const e=s.lightColor?s.lightColor.replace("#","0x"):"0xffffff",t=s.shadowColor?s.shadowColor.replace("#","0x"):"0x000000",i=new pi({rotation:s.rotation!==void 0?s.rotation:45,thickness:s.thickness!==void 0?s.thickness:2,lightColor:parseInt(e,16),lightAlpha:s.lightAlpha!==void 0?s.lightAlpha:.7,shadowColor:parseInt(t,16),shadowAlpha:s.shadowAlpha!==void 0?s.shadowAlpha:.7});return i._customParams={...s},i.updateUIParam=function(r,a){try{const o=this._customParams||{};switch(this._customParams=o,o[r]=a,r){case"rotation":this.rotation=Number(a);break;case"thickness":this.thickness=Number(a);break;case"lightColor":if(typeof a=="string"){const n=parseInt(a.replace("#","0x"),16);this.lightColor=n}break;case"lightAlpha":this.lightAlpha=Number(a);break;case"shadowColor":if(typeof a=="string"){const n=parseInt(a.replace("#","0x"),16);this.shadowColor=n}break;case"shadowAlpha":this.shadowAlpha=Number(a);break;default:r in this&&(this[r]=a);break}return!0}catch{return this._customParams&&(this._customParams[r]=a),!1}},i}catch{return null}},defaultParams:{rotation:45,thickness:2,lightColor:"#ffffff",lightAlpha:.7,shadowColor:"#000000",shadowAlpha:.7},controls:[{id:"rotation",type:"slider",label:"Angle",property:"rotation",min:0,max:360,step:1,default:45},{id:"thickness",type:"slider",label:"Thickness",property:"thickness",min:0,max:10,step:.1,default:2},{id:"lightColor",type:"color",label:"Light Color",property:"lightColor",default:"#ffffff"},{id:"lightAlpha",type:"slider",label:"Light Opacity",property:"lightAlpha",min:0,max:1,step:.01,default:.7},{id:"shadowColor",type:"color",label:"Shadow Color",property:"shadowColor",default:"#000000"},{id:"shadowAlpha",type:"slider",label:"Shadow Opacity",property:"shadowAlpha",min:0,max:1,step:.01,default:.7}]});const{BloomFilter:fi}=y;m({id:"bloom",name:"Bloom/Glow",category:"light",description:"Add a subtle glow effect to bright areas of the image",createFilter:s=>{try{const e=typeof s.strengthX=="number"?s.strengthX:2,t=typeof s.strengthY=="number"?s.strengthY:2,i=typeof s.quality=="number"?s.quality:4,r=typeof s.resolution=="number"?s.resolution:1,a=typeof s.kernelSize=="number"?s.kernelSize:5,o=new fi({strength:{x:Number(e),y:Number(t)},quality:Number(i),resolution:Number(r),kernelSize:Number(a)});return o._customParams={strengthX:e,strengthY:t,quality:i,resolution:r,kernelSize:a},o.updateUIParam=function(n,l){var c,d;try{const h=Number(l),u=this._customParams||{};switch(this._customParams=u,u[n]=h,n){case"strengthX":this.strength&&typeof this.strength=="object"&&(this.strength.x=h,(c=this._updateStrength)==null||c.call(this));break;case"strengthY":this.strength&&typeof this.strength=="object"&&(this.strength.y=h,(d=this._updateStrength)==null||d.call(this));break;case"quality":this.quality=h;break;case"resolution":this.resolution=h;break;case"kernelSize":this.kernelSize=h;break;default:n in this&&(this[n]=h);break}}catch{}},o}catch{return null}},defaultParams:{strengthX:2,strengthY:2,quality:4,resolution:1,kernelSize:5},controls:[{id:"strengthX",type:"slider",label:"Horizontal Strength",property:"strengthX",min:0,max:20,step:.1,default:2},{id:"strengthY",type:"slider",label:"Vertical Strength",property:"strengthY",min:0,max:20,step:.1,default:2},{id:"quality",type:"slider",label:"Quality",property:"quality",min:1,max:10,step:1,default:4},{id:"kernelSize",type:"select",label:"Kernel Size",property:"kernelSize",options:[{label:"5",value:5},{label:"7",value:7},{label:"9",value:9},{label:"11",value:11},{label:"13",value:13},{label:"15",value:15}],default:5}]});const{BulgePinchFilter:ze}=y,ce=s=>{const e=Math.max(0,Number(s)||0);return Math.ceil(e+2)};m({id:"bulge-pinch",name:"Bulge/Pinch",category:"distortion",description:"Creates a bulge or pinch effect in a circular area",createFilter:s=>{try{const e=s.centerX??.5,t=s.centerY??.5,i=s.radius??100,r=s.strength??1,a=new ze({center:{x:e,y:t},radius:i,strength:r}),o=ce(i);a.padding=Math.max(a.padding??0,o),a._exportPadding=o,a._customParams={...s};const n=l=>{var h;const c=Number(((h=l._customParams)==null?void 0:h.radius)??l.radius??0),d=ce(c);l._exportPadding=d,l.padding=Math.max(l.padding??0,d)};return a.updateUIParam=function(l,c){const d=this._customParams||{};switch(this._customParams=d,d[l]=c,l){case"centerX":this.center||(this.center={x:.5,y:.5}),this.center.x=c;break;case"centerY":this.center||(this.center={x:.5,y:.5}),this.center.y=c;break;case"radius":this.radius=Number(c),n(this);break;case"strength":this.strength=Number(c);break;default:l in this&&(this[l]=c);break}return!0},a.createExportFilter=function(l={}){const c=Number.isFinite(l.previewToNativeScale)?Math.max(1,Number(l.previewToNativeScale)):1,d=this._customParams||s,h=Number(d.radius??100)*c,u=new ze({center:{x:Number(d.centerX??.5),y:Number(d.centerY??.5)},radius:h,strength:Number(d.strength??1)}),p=ce(h);return u._exportPadding=p,u.padding=Math.max(u.padding??0,p),u},a.getExportPadding=function(){return Number(this._exportPadding||this.padding||0)},a}catch{return null}},defaultParams:{centerX:.5,centerY:.5,radius:100,strength:1},controls:[{id:"centerX",type:"slider",label:"Center X",property:"centerX",min:0,max:1,step:.01,default:.5},{id:"centerY",type:"slider",label:"Center Y",property:"centerY",min:0,max:1,step:.01,default:.5},{id:"radius",type:"slider",label:"Radius",property:"radius",min:0,max:1e3,step:1,default:100},{id:"strength",type:"slider",label:"Strength",property:"strength",min:-1,max:1,step:.01,default:1}]});const{ConvolutionFilter:mi}=y,H={normal:[0,0,0,0,1,0,0,0,0],gaussianBlur:[.045,.122,.045,.122,.332,.122,.045,.122,.045],boxBlur:[1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9],edgeDetection:[-1,-1,-1,-1,8,-1,-1,-1,-1],edgeEnhance:[0,0,0,-1,1,0,0,0,0],emboss:[-2,-1,0,-1,1,1,0,1,2],sharpen:[0,-1,0,-1,5,-1,0,-1,0],sobelHorizontal:[1,2,1,0,0,0,-1,-2,-1],sobelVertical:[1,0,-1,2,0,-2,1,0,-1]};m({id:"convolution",name:"Convolution Matrix",category:"effects",description:"Apply custom image effects using matrix convolution",createFilter:s=>{try{let e;if(s.customMatrix)e=[s.m00,s.m01,s.m02,s.m10,s.m11,s.m12,s.m20,s.m21,s.m22];else{const i=s.preset;e=H[i]||H.normal}const t=new mi(e,s.width||200,s.height||200);return t._customParams={...s},t.updateUIParam=function(i,r){const a=this._customParams||{};switch(this._customParams=a,a[i]=r,i){case"preset":if(!a.customMatrix){const o=r;H[o]&&(this.matrix=H[o])}break;case"customMatrix":if(r){const o=this.matrix;a.m00=o[0],a.m01=o[1],a.m02=o[2],a.m10=o[3],a.m11=o[4],a.m12=o[5],a.m20=o[6],a.m21=o[7],a.m22=o[8]}else{const o=a.preset;this.matrix=H[o]||H.normal}break;case"m00":case"m01":case"m02":case"m10":case"m11":case"m12":case"m20":case"m21":case"m22":if(a.customMatrix){const o=[...this.matrix],l={m00:0,m01:1,m02:2,m10:3,m11:4,m12:5,m20:6,m21:7,m22:8}[i];l!==void 0&&(o[l]=r,this.matrix=o)}break;case"width":this.width=r;break;case"height":this.height=r;break;default:i in this&&(this[i]=r);break}},t}catch{return null}},defaultParams:{preset:"normal",customMatrix:!1,m00:0,m01:0,m02:0,m10:0,m11:1,m12:0,m20:0,m21:0,m22:0,width:200,height:200},controls:[{id:"preset",type:"select",label:"Effect Preset",property:"preset",options:[{value:"normal",label:"Normal"},{value:"gaussianBlur",label:"Gaussian Blur"},{value:"boxBlur",label:"Box Blur"},{value:"edgeDetection",label:"Edge Detection"},{value:"edgeEnhance",label:"Edge Enhance"},{value:"emboss",label:"Emboss"},{value:"sharpen",label:"Sharpen"},{value:"sobelHorizontal",label:"Sobel Horizontal"},{value:"sobelVertical",label:"Sobel Vertical"}],default:"normal"},{id:"customMatrix",type:"toggle",label:"Use Custom Matrix",property:"customMatrix",default:!1},{id:"width",type:"slider",label:"Width",property:"width",min:50,max:500,step:10,default:200},{id:"height",type:"slider",label:"Height",property:"height",min:50,max:500,step:10,default:200},{id:"m00",type:"slider",label:"Matrix [0,0]",property:"m00",min:-5,max:5,step:.1,default:0},{id:"m01",type:"slider",label:"Matrix [0,1]",property:"m01",min:-5,max:5,step:.1,default:0},{id:"m02",type:"slider",label:"Matrix [0,2]",property:"m02",min:-5,max:5,step:.1,default:0},{id:"m10",type:"slider",label:"Matrix [1,0]",property:"m10",min:-5,max:5,step:.1,default:0},{id:"m11",type:"slider",label:"Matrix [1,1]",property:"m11",min:-5,max:5,step:.1,default:1},{id:"m12",type:"slider",label:"Matrix [1,2]",property:"m12",min:-5,max:5,step:.1,default:0},{id:"m20",type:"slider",label:"Matrix [2,0]",property:"m20",min:-5,max:5,step:.1,default:0},{id:"m21",type:"slider",label:"Matrix [2,1]",property:"m21",min:-5,max:5,step:.1,default:0},{id:"m22",type:"slider",label:"Matrix [2,2]",property:"m22",min:-5,max:5,step:.1,default:0}]});const{CrossHatchFilter:gi}=y;m({id:"cross-hatch",name:"Cross Hatch",category:"stylize",description:"Creates a crosshatching effect like in a pencil drawing",createFilter:s=>{try{const e=new gi;return e.updateUIParam=function(t,i){return!0},e}catch{return null}},defaultParams:{},controls:[]});m({id:"crt",name:"CRT Screen",category:"stylize",description:"Simulates an old CRT screen with scan lines and noise",createFilter:s=>{try{const e={lineWidth:typeof s.lineWidth=="number"?s.lineWidth:1,noise:typeof s.noise=="number"?s.noise:.3,curvature:typeof s.curvature=="number"?s.curvature:1,lineContrast:typeof s.lineContrast=="number"?s.lineContrast:.25,verticalLine:s.verticalLine===!0,noiseSize:typeof s.noiseSize=="number"?s.noiseSize:1,vignetting:typeof s.vignetting=="number"?s.vignetting:.3,vignettingAlpha:typeof s.vignettingAlpha=="number"?s.vignettingAlpha:1,vignettingBlur:typeof s.vignettingBlur=="number"?s.vignettingBlur:.3,time:typeof s.time=="number"?s.time:0,seed:typeof s.seed=="number"?s.seed:Math.random()},t=new y.CRTFilter(e);return t._customParams={...e},t.updateUIParam=function(i,r){try{const a=this._customParams||{};switch(this._customParams=a,a[i]=r,i){case"lineWidth":this.lineWidth=Number(r);break;case"noise":this.noise=Number(r);break;case"curvature":this.curvature=Number(r);break;case"lineContrast":this.lineContrast=Number(r);break;case"verticalLine":this.verticalLine=!!r;break;case"noiseSize":this.noiseSize=Number(r);break;case"vignetting":this.vignetting=Number(r);break;case"vignettingAlpha":this.vignettingAlpha=Number(r);break;case"vignettingBlur":this.vignettingBlur=Number(r);break;case"time":this.time=Number(r);break;case"seed":this.seed=Number(r);break;default:i in this&&(this[i]=r);break}}catch{}},t}catch{return null}},defaultParams:{lineWidth:1,noise:.3,curvature:1,lineContrast:.25,verticalLine:!1,noiseSize:1,vignetting:.3,vignettingAlpha:1,vignettingBlur:.3,time:0,seed:1},controls:[{id:"lineWidth",type:"slider",label:"Scan Line Width",property:"lineWidth",min:0,max:5,step:.1,default:1},{id:"noise",type:"slider",label:"Noise Amount",property:"noise",min:0,max:1,step:.01,default:.3},{id:"curvature",type:"slider",label:"Screen Curvature",property:"curvature",min:0,max:10,step:.1,default:1},{id:"lineContrast",type:"slider",label:"Line Contrast",property:"lineContrast",min:0,max:1,step:.01,default:.25},{id:"verticalLine",type:"toggle",label:"Vertical Lines",property:"verticalLine",default:!1},{id:"noiseSize",type:"slider",label:"Noise Size",property:"noiseSize",min:.5,max:5,step:.1,default:1},{id:"vignetting",type:"slider",label:"Vignette Size",property:"vignetting",min:0,max:1,step:.01,default:.3},{id:"vignettingAlpha",type:"slider",label:"Vignette Opacity",property:"vignettingAlpha",min:0,max:1,step:.01,default:1},{id:"vignettingBlur",type:"slider",label:"Vignette Blur",property:"vignettingBlur",min:0,max:1,step:.01,default:.3},{id:"time",type:"slider",label:"Animation Time",property:"time",min:0,max:10,step:.1,default:0}]});const bi=T.DisplacementFilter,yi=T.Sprite,he=T.Texture;m({id:"displacement",name:"Displacement Map",category:"distortion",description:"Distorts the image using a displacement map texture",createFilter:s=>{try{const e=s.mapTexture||"/assets/images/displacement_map.png";let t;try{t=he.from(e),t.source.addressMode="repeat"}catch{const o=document.createElement("canvas");o.width=256,o.height=256;const n=o.getContext("2d");if(n){n.fillStyle="#ffffff",n.fillRect(0,0,o.width,o.height),n.fillStyle="#000000";for(let l=0;l<10;l++)for(let c=0;c<10;c++)(l+c)%2===0&&n.fillRect(l*25,c*25,25,25)}t=he.from(o)}const i=new yi(t),r=new bi(i,s.scale||50);return r.scale.x=s.scaleX||50,r.scale.y=s.scaleY||50,r._customParams={...s},r._displacementSprite=i,r.updateUIParam=function(a,o){const n=this._customParams||{};switch(this._customParams=n,n[a]=o,a){case"scaleX":this.scale.x=o;break;case"scaleY":this.scale.y=o;break;case"mapTexture":try{const l=this._displacementSprite;if(l){const c=he.from(o);c.source.addressMode="repeat",l.texture=c}}catch{}break;default:a in this?this[a]=o:a in this.scale&&(this.scale[a]=o);break}return!0},r}catch{return null}},defaultParams:{mapTexture:"/assets/images/displacement_map.png",scale:50,scaleX:50,scaleY:50},controls:[{id:"mapTexture",type:"select",label:"Displacement Map",property:"mapTexture",options:[{label:"Default",value:"/assets/images/displacement_map.png"},{label:"Clouds",value:"/assets/images/clouds.png"},{label:"Ripple",value:"/assets/images/ripple.png"}],default:"/assets/images/displacement_map.png"},{id:"scaleX",type:"slider",label:"Scale X",property:"scaleX",min:1,max:200,step:1,default:50},{id:"scaleY",type:"slider",label:"Scale Y",property:"scaleY",min:1,max:200,step:1,default:50}]});m({id:"dot",name:"Dot Screen",category:"stylize",description:"Simulates a halftone printing pattern with dots",createFilter:s=>{try{const e={scale:typeof s.scale=="number"?s.scale:1,angle:typeof s.angle=="number"?s.angle:5,grayscale:s.grayscale===!0},t=new y.DotFilter(e);return t._customParams={...e},t.updateUIParam=function(i,r){try{const a=this._customParams||{};switch(this._customParams=a,a[i]=r,i){case"scale":this.scale=Number(r);break;case"angle":this.angle=Number(r);break;case"grayscale":this.grayscale=!!r;break;default:i in this&&(this[i]=r);break}}catch{}},t}catch{return null}},defaultParams:{scale:1,angle:5,grayscale:!0},controls:[{id:"scale",type:"slider",label:"Dot Scale",property:"scale",min:.5,max:10,step:.1,default:1},{id:"angle",type:"slider",label:"Dot Angle",property:"angle",min:0,max:10,step:.1,default:5},{id:"grayscale",type:"toggle",label:"Grayscale",property:"grayscale",default:!0}]});const{EmbossFilter:_i}=y;m({id:"emboss",name:"Emboss",category:"stylize",description:"Creates an embossed relief effect",createFilter:s=>{try{const e=typeof s.strength=="number"?s.strength:5,t=new _i(e);return t._customParams={strength:e},t.updateUIParam=function(i,r){try{const a=this._customParams||{};switch(this._customParams=a,a[i]=r,i){case"strength":const o=Number(r);a.strength=o,this.strength=o;break;default:i in this&&(this[i]=r);break}}catch{}},t}catch{return null}},defaultParams:{strength:5},controls:[{id:"strength",type:"slider",label:"Strength",property:"strength",min:0,max:20,step:.5,default:5}]});const{GlitchFilter:xi}=y,L={TRANSPARENT:0,ORIGINAL:1,LOOP:2,CLAMP:3,MIRROR:4};m({id:"glitch",name:"Glitch",category:"effects",description:"Apply digital distortion and glitch effects",createFilter:s=>{try{const e={x:s.redX,y:s.redY},t={x:s.greenX,y:s.greenY},i={x:s.blueX,y:s.blueY},r=new xi({slices:s.slices,offset:s.offset,direction:s.direction,fillMode:s.fillMode,seed:s.seed,average:s.average,minSize:s.minSize,sampleSize:s.sampleSize,red:e,green:t,blue:i});r.animating=s.animating||!1,r._customParams={...s},typeof r.refresh=="function"&&r.refresh();let a=null;const o=()=>{r.animating&&(r.seed=Math.random()),a=requestAnimationFrame(o)};return r.animating&&(a=requestAnimationFrame(o)),r._stopAnimation=()=>{a!==null&&(cancelAnimationFrame(a),a=null)},r.updateUIParam=function(n,l){const c=this._customParams||{};switch(this._customParams=c,c[n]=l,n){case"animating":this.animating=l,l&&!a&&(a=requestAnimationFrame(o));break;case"slices":this.slices=Math.round(l);break;case"redX":case"redY":const d=this.red;n==="redX"?d.x=l:d.y=l,this.red=d;break;case"greenX":case"greenY":const h=this.green;n==="greenX"?h.x=l:h.y=l,this.green=h;break;case"blueX":case"blueY":const u=this.blue;n==="blueX"?u.x=l:u.y=l,this.blue=u;break;case"seed":this.animating||(this.seed=l);break;case"randomizeSeed":l&&!c.animating&&(this.seed=Math.random());break;case"refresh":if(l)try{this.refresh()}catch{}break;case"offset":case"direction":case"fillMode":case"average":case"minSize":case"sampleSize":n in this&&(this[n]=l);break;default:n in this&&(this[n]=l);break}},r}catch{return null}},defaultParams:{slices:10,offset:100,direction:0,fillMode:L.LOOP,seed:.5,average:!1,minSize:8,sampleSize:512,redX:2,redY:2,greenX:-10,greenY:4,blueX:10,blueY:-4,animating:!1,randomizeSeed:!1,refresh:!1},controls:[{id:"animating",type:"toggle",label:"Animate Automatically",property:"animating",default:!1},{id:"slices",type:"slider",label:"Slices",property:"slices",min:2,max:20,step:1,default:10},{id:"offset",type:"slider",label:"Offset Amount",property:"offset",min:-400,max:400,step:1,default:100},{id:"direction",type:"slider",label:"Direction",property:"direction",min:-180,max:180,step:1,default:0},{id:"fillMode",type:"select",label:"Fill Mode",property:"fillMode",options:[{value:L.TRANSPARENT,label:"Transparent"},{value:L.ORIGINAL,label:"Original"},{value:L.LOOP,label:"Loop"},{value:L.CLAMP,label:"Clamp"},{value:L.MIRROR,label:"Mirror"}],default:L.LOOP},{id:"seed",type:"slider",label:"Seed",property:"seed",min:0,max:1,step:.01,default:.5},{id:"randomizeSeed",type:"button",label:"Randomize Seed",action:"randomizeSeed"},{id:"refresh",type:"button",label:"Refresh Filter",action:"refresh"},{id:"average",type:"toggle",label:"Average Slices",property:"average",default:!1},{id:"redX",type:"slider",label:"Red X Offset",property:"redX",min:-50,max:50,step:.5,default:2},{id:"redY",type:"slider",label:"Red Y Offset",property:"redY",min:-50,max:50,step:.5,default:2},{id:"greenX",type:"slider",label:"Green X Offset",property:"greenX",min:-50,max:50,step:.5,default:-10},{id:"greenY",type:"slider",label:"Green Y Offset",property:"greenY",min:-50,max:50,step:.5,default:4},{id:"blueX",type:"slider",label:"Blue X Offset",property:"blueX",min:-50,max:50,step:.5,default:10},{id:"blueY",type:"slider",label:"Blue Y Offset",property:"blueY",min:-50,max:50,step:.5,default:-4}]});const{GlowFilter:Ci}=y;m({id:"glow",name:"Glow",category:"light",description:"Adds a customizable glow effect around the image",createFilter:s=>{try{const e=parseInt(s.color.replace("#","0x"),16),t=new Ci({distance:s.distance||10,outerStrength:s.outerStrength||4,innerStrength:s.innerStrength||0,color:e,alpha:s.alpha??1,quality:s.quality||.1,knockout:s.knockout||!1});return t._customParams={color:s.color||"#ffffff",...s},t.updateUIParam=function(i,r){try{const a=this._customParams||{};switch(this._customParams=a,a[i]=r,i){case"distance":this.distance=Number(r);break;case"outerStrength":this.outerStrength=Number(r);break;case"innerStrength":this.innerStrength=Number(r);break;case"color":a.color=r,this.color=parseInt(r.replace("#","0x"),16);break;case"alpha":this.alpha=Number(r);break;case"quality":this.quality=Number(r);break;case"knockout":this.knockout=!!r;break;default:i in this&&(this[i]=r);break}}catch{}},t}catch{return null}},defaultParams:{distance:10,outerStrength:4,innerStrength:0,color:"#ffffff",alpha:1,quality:.1,knockout:!1},controls:[{id:"distance",type:"slider",label:"Distance",property:"distance",min:0,max:20,step:1,default:10},{id:"outerStrength",type:"slider",label:"Outer Strength",property:"outerStrength",min:0,max:20,step:.1,default:4},{id:"innerStrength",type:"slider",label:"Inner Strength",property:"innerStrength",min:0,max:20,step:.1,default:0},{id:"color",type:"color",label:"Color",property:"color",default:"#ffffff"},{id:"alpha",type:"slider",label:"Alpha",property:"alpha",min:0,max:1,step:.01,default:1},{id:"quality",type:"slider",label:"Quality",property:"quality",min:.01,max:1,step:.01,default:.1},{id:"knockout",type:"toggle",label:"Show Glow Only",property:"knockout",default:!1}]});const{GodrayFilter:wi}=y;m({id:"godray",name:"Godray",category:"light",description:"Creates volumetric light-ray effects (crepuscular rays)",createFilter:s=>{try{const e=new wi({angle:s.angle||30,parallel:s.parallel??!0,center:{x:s.centerX||0,y:s.centerY||0},gain:s.gain||.5,lacunarity:s.lacunarity||2.5,time:s.time||0,alpha:s.alpha||1});return e._customParams={centerX:s.centerX||0,centerY:s.centerY||0,...s},e.updateUIParam=function(t,i){try{const r=this._customParams||{};switch(this._customParams=r,r[t]=i,t){case"angle":this.angle=Number(i);break;case"parallel":this.parallel=!!i;break;case"centerX":r.centerX=Number(i),this.center={x:Number(i),y:r.centerY};break;case"centerY":r.centerY=Number(i),this.center={x:r.centerX,y:Number(i)};break;case"gain":this.gain=Number(i);break;case"lacunarity":this.lacunarity=Number(i);break;case"time":this.time=Number(i);break;case"alpha":this.alpha=Number(i);break;default:t in this&&(this[t]=i);break}}catch{}},e}catch{return null}},defaultParams:{angle:30,parallel:!0,centerX:0,centerY:0,gain:.5,lacunarity:2.5,time:0,alpha:1},controls:[{id:"angle",type:"slider",label:"Angle",property:"angle",min:0,max:360,step:1,default:30},{id:"parallel",type:"toggle",label:"Parallel Rays",property:"parallel",default:!0},{id:"centerX",type:"slider",label:"Light Source X",property:"centerX",min:-1,max:1,step:.01,default:0},{id:"centerY",type:"slider",label:"Light Source Y",property:"centerY",min:-1,max:1,step:.01,default:0},{id:"gain",type:"slider",label:"Gain/Intensity",property:"gain",min:0,max:1,step:.01,default:.5},{id:"lacunarity",type:"slider",label:"Density",property:"lacunarity",min:.1,max:10,step:.1,default:2.5},{id:"time",type:"slider",label:"Time",property:"time",min:0,max:10,step:.1,default:0},{id:"alpha",type:"slider",label:"Alpha",property:"alpha",min:0,max:1,step:.01,default:1}]});const Si=y.SimpleLightmapFilter,Re=T.Texture;m({id:"lightmap",name:"Lightmap",category:"light",description:"Applies lighting effects using a reference texture as a light map",createFilter:s=>{try{const e=s.textureType||"default",t=s.color||"#000000",i=typeof s.alpha=="number"?s.alpha:1,r=document.createElement("canvas");r.width=256,r.height=256;const a=r.getContext("2d");if(!a)throw new Error("Canvas 2D context not available");if(e==="spotlight"){a.fillStyle="black",a.fillRect(0,0,256,256);const c=a.createRadialGradient(128,128,5,128,128,80);c.addColorStop(0,"white"),c.addColorStop(.5,"rgba(255, 255, 255, 0.5)"),c.addColorStop(1,"rgba(0, 0, 0, 0)"),a.fillStyle=c,a.beginPath(),a.arc(128,128,100,0,Math.PI*2),a.fill()}else if(e==="softlight"){const c=a.createLinearGradient(0,0,256,256);c.addColorStop(0,"white"),c.addColorStop(.3,"rgba(220, 220, 220, 1)"),c.addColorStop(.7,"rgba(150, 150, 150, 1)"),c.addColorStop(1,"rgba(80, 80, 80, 1)"),a.fillStyle=c,a.fillRect(0,0,256,256)}else{const c=a.createRadialGradient(128,128,10,128,128,160);c.addColorStop(0,"white"),c.addColorStop(.3,"rgba(220, 220, 220, 1)"),c.addColorStop(.6,"rgba(150, 150, 150, 1)"),c.addColorStop(1,"black"),a.fillStyle=c,a.fillRect(0,0,256,256)}const o=Re.from(r);let n;try{typeof t=="string"&&t.startsWith("#")?n=parseInt(t.replace("#","0x"),16):n=0}catch{n=0}const l=new Si(o,n,i);return l._customParams={textureType:e,color:t,alpha:i},l.updateUIParam=function(c,d){try{const h=this._customParams||{};switch(this._customParams=h,h[c]=d,c){case"textureType":h.textureType=d;const u=document.createElement("canvas");u.width=256,u.height=256;const p=u.getContext("2d");if(p){if(d==="spotlight"){p.fillStyle="black",p.fillRect(0,0,256,256);const g=p.createRadialGradient(128,128,5,128,128,80);g.addColorStop(0,"white"),g.addColorStop(.5,"rgba(255, 255, 255, 0.5)"),g.addColorStop(1,"rgba(0, 0, 0, 0)"),p.fillStyle=g,p.beginPath(),p.arc(128,128,100,0,Math.PI*2),p.fill()}else if(d==="softlight"){const g=p.createLinearGradient(0,0,256,256);g.addColorStop(0,"white"),g.addColorStop(.3,"rgba(220, 220, 220, 1)"),g.addColorStop(.7,"rgba(150, 150, 150, 1)"),g.addColorStop(1,"rgba(80, 80, 80, 1)"),p.fillStyle=g,p.fillRect(0,0,256,256)}else{const g=p.createRadialGradient(128,128,10,128,128,160);g.addColorStop(0,"white"),g.addColorStop(.3,"rgba(220, 220, 220, 1)"),g.addColorStop(.6,"rgba(150, 150, 150, 1)"),g.addColorStop(1,"black"),p.fillStyle=g,p.fillRect(0,0,256,256)}const b=Re.from(u);if(this.lightMap=b,this.enabled!==void 0){const g=this.enabled;this.enabled=!1,setTimeout(()=>{this.enabled=g},0)}}break;case"color":h.color=d;try{typeof d=="string"&&d.startsWith("#")?this.color=parseInt(d.replace("#","0x"),16):this.color=0}catch{this.color=0}break;case"alpha":this.alpha=Number(d);break;default:c in this&&(this[c]=d);break}}catch{}},l}catch{return null}},defaultParams:{textureType:"default",color:"#000000",alpha:1},controls:[{id:"textureType",type:"select",label:"Light Map Type",property:"textureType",options:[{label:"Default",value:"default"},{label:"Spotlight",value:"spotlight"},{label:"Soft Light",value:"softlight"}],default:"default"},{id:"color",type:"color",label:"Ambient Color",property:"color",default:"#000000"},{id:"alpha",type:"slider",label:"Intensity",property:"alpha",min:0,max:1,step:.01,default:1}]});const{NoiseFilter:vi}=T;m({id:"noise",name:"Noise",category:"effects",description:"Add random noise to the image",createFilter:s=>{try{const e=new vi({noise:s.noise||.5,seed:s.seed||Math.random()});e.animating=s.animating||!1,e._customParams={...s};let t=null;const i=()=>{e.animating&&(e.seed=Math.random()),t=requestAnimationFrame(i)};return e.animating&&(t=requestAnimationFrame(i)),e._stopAnimation=()=>{t!==null&&(cancelAnimationFrame(t),t=null)},e.updateUIParam=function(r,a){const o=this._customParams||{};switch(this._customParams=o,o[r]=a,r){case"animating":this.animating=a,a&&!t&&(t=requestAnimationFrame(i));break;case"noise":this.noise=Math.max(0,Math.min(1,a));break;case"seed":this.animating||(this.seed=a);break;case"randomizeSeed":a&&(this.seed=Math.random());break;default:r in this&&(this[r]=a);break}},e}catch{return null}},defaultParams:{noise:.5,seed:.5,animating:!1,randomizeSeed:!1},controls:[{id:"animating",type:"toggle",label:"Animate Noise",property:"animating",default:!1},{id:"noise",type:"slider",label:"Noise Amount",property:"noise",min:0,max:1,step:.01,default:.5},{id:"seed",type:"slider",label:"Random Seed",property:"seed",min:0,max:1,step:.01,default:.5},{id:"randomizeSeed",type:"button",label:"Randomize Seed",action:"randomizeSeed"}]});const{OldFilmFilter:Mi}=y;m({id:"old-film",name:"Old Film",category:"effects",description:"Apply a vintage film effect with scratches and grain",createFilter:s=>{try{const e=new Mi({sepia:s.sepia,noise:s.noise,noiseSize:s.noiseSize,scratch:s.scratch,scratchDensity:s.scratchDensity,scratchWidth:s.scratchWidth,vignetting:s.vignetting,vignettingAlpha:s.vignettingAlpha,vignettingBlur:s.vignettingBlur,seed:s.seed||Math.random()});e.animating=s.animating||!1,e._customParams={...s};let t=null;const i=()=>{e.animating&&(e.seed=Math.random()),t=requestAnimationFrame(i)};return e.animating&&(t=requestAnimationFrame(i)),e._stopAnimation=()=>{t!==null&&(cancelAnimationFrame(t),t=null)},e.updateUIParam=function(r,a){const o=this._customParams||{};switch(this._customParams=o,o[r]=a,r){case"animating":this.animating=a,a&&!t&&(t=requestAnimationFrame(i));break;case"seed":this.animating||(this.seed=a);break;case"randomizeSeed":a&&(this.seed=Math.random());break;case"sepia":case"noise":case"noiseSize":case"scratch":case"scratchDensity":case"scratchWidth":case"vignetting":case"vignettingAlpha":case"vignettingBlur":r in this&&(this[r]=a);break;default:r in this&&(this[r]=a);break}},e}catch{return null}},defaultParams:{sepia:.3,noise:.3,noiseSize:1,scratch:.5,scratchDensity:.3,scratchWidth:1,vignetting:.3,vignettingAlpha:1,vignettingBlur:.3,seed:.5,animating:!1,randomizeSeed:!1},controls:[{id:"animating",type:"toggle",label:"Animate Film",property:"animating",default:!1},{id:"sepia",type:"slider",label:"Sepia Tone",property:"sepia",min:0,max:1,step:.01,default:.3},{id:"noise",type:"slider",label:"Noise Amount",property:"noise",min:0,max:1,step:.01,default:.3},{id:"noiseSize",type:"slider",label:"Noise Size",property:"noiseSize",min:1,max:10,step:.1,default:1},{id:"scratch",type:"slider",label:"Scratch Amount",property:"scratch",min:-1,max:1,step:.01,default:.5},{id:"scratchDensity",type:"slider",label:"Scratch Density",property:"scratchDensity",min:0,max:1,step:.01,default:.3},{id:"scratchWidth",type:"slider",label:"Scratch Width",property:"scratchWidth",min:1,max:20,step:1,default:1},{id:"vignetting",type:"slider",label:"Vignette Size",property:"vignetting",min:0,max:1,step:.01,default:.3},{id:"vignettingAlpha",type:"slider",label:"Vignette Opacity",property:"vignettingAlpha",min:0,max:1,step:.01,default:1},{id:"vignettingBlur",type:"slider",label:"Vignette Blur",property:"vignettingBlur",min:0,max:1,step:.01,default:.3},{id:"seed",type:"slider",label:"Random Seed",property:"seed",min:0,max:1,step:.01,default:.5},{id:"randomizeSeed",type:"button",label:"Randomize Seed",action:"randomizeSeed"}]});const{OutlineFilter:ki}=y;m({id:"outline",name:"Outline",category:"effects",description:"Add an outline or stroke around the image",createFilter:s=>{try{let e=s.color;typeof e=="string"&&(e=parseInt(e.replace("#","0x"),16));const t=new ki({thickness:s.thickness||4,color:e,alpha:s.alpha||1,quality:s.quality||.1,knockout:s.knockout||!1});return t._customParams={...s},t.updateUIParam=function(i,r){const a=this._customParams||{};switch(this._customParams=a,a[i]=r,i){case"thickness":this.thickness=Math.max(0,r);break;case"color":typeof r=="string"?(this.color=parseInt(r.replace("#","0x"),16),a.color=r):this.color=r;break;case"alpha":this.alpha=Math.max(0,Math.min(1,r));break;case"quality":this.quality=Math.max(.01,Math.min(1,r));break;case"knockout":this.knockout=!!r;break;default:i in this&&(this[i]=r);break}},t}catch{return null}},defaultParams:{thickness:4,color:"#000000",alpha:1,quality:.1,knockout:!1},controls:[{id:"thickness",type:"slider",label:"Thickness",property:"thickness",min:0,max:20,step:.1,default:4},{id:"color",type:"color",label:"Color",property:"color",default:"#000000"},{id:"alpha",type:"slider",label:"Alpha",property:"alpha",min:0,max:1,step:.01,default:1},{id:"quality",type:"slider",label:"Quality",property:"quality",min:.01,max:1,step:.01,default:.1,tooltip:"Higher values give better quality but slower performance"},{id:"knockout",type:"toggle",label:"Outline Only",property:"knockout",default:!1,tooltip:"Only show the outline, not the image content"}]});const{PixelateFilter:Pi}=y;m({id:"pixelate",name:"Pixelate",category:"effects",description:"Create a pixelated or mosaic effect",createFilter:s=>{try{const e=new Pi(s.useUniform?Math.max(4,s.size||10):[Math.max(4,s.sizeX||10),Math.max(4,s.sizeY||10)]);return e._customParams={...s},e.updateUIParam=function(t,i){const r=this._customParams||{};switch(this._customParams=r,r[t]=i,t){case"useUniform":if(r.useUniform=i,i){const a=Math.round((this.sizeX+this.sizeY)/2);this.size=Math.max(4,a),r.size=a}else{const a=Array.isArray(this.size)?this.size[0]:this.size;this.sizeX=Math.max(4,a),this.sizeY=Math.max(4,a),r.sizeX=this.sizeX,r.sizeY=this.sizeY}break;case"size":r.useUniform&&(this.size=Math.max(4,i));break;case"sizeX":r.useUniform||(this.sizeX=Math.max(4,i));break;case"sizeY":r.useUniform||(this.sizeY=Math.max(4,i));break;default:t in this&&(this[t]=i);break}},e}catch{return null}},defaultParams:{useUniform:!0,size:10,sizeX:10,sizeY:10},controls:[{id:"useUniform",type:"toggle",label:"Uniform Pixels",property:"useUniform",default:!0,tooltip:"Use the same size for both X and Y dimensions"},{id:"size",type:"slider",label:"Pixel Size",property:"size",min:4,max:40,step:1,default:10,tooltip:"Size of the pixels in both dimensions"},{id:"sizeX",type:"slider",label:"Horizontal Size",property:"sizeX",min:4,max:40,step:1,default:10,tooltip:"Size of the pixels in the horizontal direction"},{id:"sizeY",type:"slider",label:"Vertical Size",property:"sizeY",min:4,max:40,step:1,default:10,tooltip:"Size of the pixels in the vertical direction"}]});const{ReflectionFilter:Fi}=y;m({id:"reflection",name:"Reflection",category:"distortion",description:"Creates a water reflection effect with configurable waves",createFilter:s=>{try{const e={mirror:s.mirror??!0,boundary:s.boundary??.5,amplitude:new Float32Array([s.amplitudeStart??0,s.amplitudeEnd??20]),waveLength:new Float32Array([s.wavelengthStart??30,s.wavelengthEnd??100]),alpha:new Float32Array([s.alphaStart??1,s.alphaEnd??1]),time:s.time??0},t=new Fi(e);return t._customParams={...s},t.animating=s.animating??!1,t.updateUIParam=function(i,r){const a=this._customParams||{};switch(this._customParams=a,a[i]=r,i){case"mirror":case"boundary":case"time":this[i]=r;break;case"amplitudeStart":Array.isArray(this.amplitude)||(this.amplitude=[0,this._customParams.amplitudeEnd||20]),this.amplitude[0]=r;break;case"amplitudeEnd":Array.isArray(this.amplitude)||(this.amplitude=[this._customParams.amplitudeStart||0,20]),this.amplitude[1]=r;break;case"wavelengthStart":Array.isArray(this.waveLength)||(this.waveLength=[30,this._customParams.wavelengthEnd||100]),this.waveLength[0]=r;break;case"wavelengthEnd":Array.isArray(this.waveLength)||(this.waveLength=[this._customParams.wavelengthStart||30,100]),this.waveLength[1]=r;break;case"alphaStart":Array.isArray(this.alpha)||(this.alpha=[1,this._customParams.alphaEnd||1]),this.alpha[0]=r;break;case"alphaEnd":Array.isArray(this.alpha)||(this.alpha=[this._customParams.alphaStart||1,1]),this.alpha[1]=r;break;case"animating":this.animating=r;break;default:i in this&&(this[i]=r);break}return!0},t}catch{return null}},defaultParams:{mirror:!0,boundary:.5,amplitudeStart:0,amplitudeEnd:20,wavelengthStart:30,wavelengthEnd:100,alphaStart:1,alphaEnd:1,time:0,animating:!1},controls:[{id:"mirror",type:"toggle",label:"Mirror Image",property:"mirror",default:!0},{id:"boundary",type:"slider",label:"Boundary Line",property:"boundary",min:0,max:1,step:.01,default:.5},{id:"amplitudeStart",type:"slider",label:"Wave Height (Start)",property:"amplitudeStart",min:0,max:50,step:1,default:0},{id:"amplitudeEnd",type:"slider",label:"Wave Height (End)",property:"amplitudeEnd",min:0,max:50,step:1,default:20},{id:"wavelengthStart",type:"slider",label:"Wave Length (Start)",property:"wavelengthStart",min:10,max:200,step:1,default:30},{id:"wavelengthEnd",type:"slider",label:"Wave Length (End)",property:"wavelengthEnd",min:10,max:200,step:1,default:100},{id:"alphaStart",type:"slider",label:"Opacity (Start)",property:"alphaStart",min:0,max:1,step:.01,default:1},{id:"alphaEnd",type:"slider",label:"Opacity (End)",property:"alphaEnd",min:0,max:1,step:.01,default:1},{id:"time",type:"slider",label:"Animation Time",property:"time",min:0,max:10,step:.1,default:0},{id:"animating",type:"toggle",label:"Auto Animate",property:"animating",default:!1}]});const{ShockwaveFilter:Ai}=y;m({id:"shockwave",name:"Shockwave",category:"distortion",description:"Creates a rippling shockwave or blast wave effect",createFilter:s=>{try{const e=s.centerX??.5,t=s.centerY??.5,i={x:e,y:t},r=s.amplitude??30,a=s.wavelength??160,o=s.speed??500,n=s.brightness??1,l=s.radius??-1,c=s.time??0,d=new Ai({center:i,amplitude:r,wavelength:a,speed:o,brightness:n,radius:l,time:c});return d._customParams={...s},d.animating=s.animating??!1,d.updateUIParam=function(h,u){const p=this._customParams||{};switch(this._customParams=p,p[h]=u,h){case"centerX":this.center||(this.center={x:.5,y:.5}),this.center.x=u;break;case"centerY":this.center||(this.center={x:.5,y:.5}),this.center.y=u;break;case"amplitude":case"wavelength":case"speed":case"brightness":case"radius":case"time":this[h]=u;break;case"animating":this.animating=u;break;default:h in this&&(this[h]=u);break}return!0},d}catch{return null}},defaultParams:{centerX:.5,centerY:.5,amplitude:30,wavelength:160,speed:500,brightness:1,radius:-1,time:0,animating:!1},controls:[{id:"centerX",type:"slider",label:"Center X",property:"centerX",min:0,max:1,step:.01,default:.5},{id:"centerY",type:"slider",label:"Center Y",property:"centerY",min:0,max:1,step:.01,default:.5},{id:"amplitude",type:"slider",label:"Amplitude",property:"amplitude",min:0,max:100,step:1,default:30},{id:"wavelength",type:"slider",label:"Wavelength",property:"wavelength",min:10,max:500,step:1,default:160},{id:"speed",type:"slider",label:"Speed",property:"speed",min:1,max:1e3,step:10,default:500},{id:"brightness",type:"slider",label:"Brightness",property:"brightness",min:0,max:5,step:.1,default:1},{id:"radius",type:"slider",label:"Max Radius",property:"radius",min:-1,max:1e3,step:10,default:-1},{id:"time",type:"slider",label:"Time",property:"time",min:0,max:5,step:.1,default:0},{id:"animating",type:"toggle",label:"Auto Animate",property:"animating",default:!1}]});const{SimplexNoiseFilter:Ni}=y;m({id:"simplex-noise",name:"Simplex Noise",category:"effects",description:"Apply procedural noise to create texture effects",createFilter:s=>{try{const e=s.animating?0:s.offsetZ||0,t=new Ni({strength:s.strength,noiseScale:s.noiseScale,offsetX:s.offsetX,offsetY:s.offsetY,offsetZ:e,step:s.step});t.animating=s.animating||!1,t.animationSpeed=s.animationSpeed||.01,t._customParams={...s};let i=null,r=0;const a=()=>{t.animating&&(r+=t.animationSpeed,t.offsetZ=r),i=requestAnimationFrame(a)};return t.animating&&(i=requestAnimationFrame(a)),t._stopAnimation=()=>{i!==null&&(cancelAnimationFrame(i),i=null)},t.updateUIParam=function(o,n){const l=this._customParams||{};switch(this._customParams=l,l[o]=n,o){case"animating":this.animating=n,n&&!i&&(i=requestAnimationFrame(a));break;case"animationSpeed":this.animationSpeed=n;break;case"offsetZ":this.animating||(this.offsetZ=n);break;case"randomizeSeed":if(n){const c=()=>Math.random()*100-50;this.offsetX=c(),this.offsetY=c(),this.offsetZ=c(),l.offsetX=this.offsetX,l.offsetY=this.offsetY,l.offsetZ=this.offsetZ}break;case"strength":case"noiseScale":case"offsetX":case"offsetY":case"step":o in this&&(this[o]=n);break;default:o in this&&(this[o]=n);break}},t}catch{return null}},defaultParams:{strength:.5,noiseScale:10,offsetX:0,offsetY:0,offsetZ:0,step:-1,animating:!1,animationSpeed:.01,randomizeSeed:!1},controls:[{id:"strength",type:"slider",label:"Noise Strength",property:"strength",min:0,max:1,step:.01,default:.5},{id:"noiseScale",type:"slider",label:"Noise Scale",property:"noiseScale",min:1,max:50,step:.5,default:10},{id:"offsetX",type:"slider",label:"X Offset",property:"offsetX",min:-50,max:50,step:.5,default:0},{id:"offsetY",type:"slider",label:"Y Offset",property:"offsetY",min:-50,max:50,step:.5,default:0},{id:"offsetZ",type:"slider",label:"Z Offset",property:"offsetZ",min:-50,max:50,step:.5,default:0},{id:"step",type:"slider",label:"Step Threshold",property:"step",min:-1,max:1,step:.01,default:-1,tooltip:"Values above 0 create a blocky effect"},{id:"animating",type:"toggle",label:"Animate Noise",property:"animating",default:!1},{id:"animationSpeed",type:"slider",label:"Animation Speed",property:"animationSpeed",min:.001,max:.05,step:.001,default:.01},{id:"randomizeSeed",type:"button",label:"Randomize Pattern",action:"randomizeSeed"}]});const{TwistFilter:zi}=y,Qe=s=>Math.ceil(Math.max(0,Number(s)||0)+2),Te=(s,e=1)=>{const t=Math.max(1,Number(s._sourceWidth??0)),i=Math.max(1,Number(s._sourceHeight??0)),r=Math.min(t,i),a=Number(s.centerX??.5),o=Number(s.centerY??.5),n=Number(s.radius??.25),l=Number(s.angle??4),c=a*t*e,d=o*i*e,h=n*r*e,u=new zi({offset:{x:c,y:d},radius:h,angle:l}),p=Qe(h);return u.padding=Math.max(u.padding??0,p),u._exportPadding=p,u};m({id:"twist",name:"Twist",category:"distortion",description:"Creates a twisting distortion effect around a central point",createFilter:s=>{try{const e={centerX:s.centerX??.5,centerY:s.centerY??.5,radius:s.radius??.25,angle:s.angle??4,_sourceWidth:s._sourceWidth,_sourceHeight:s._sourceHeight},t=Te(e,1);return t._customParams={...e},t.updateUIParam=function(i,r){const a=this._customParams||{};this._customParams=a,a[i]=r;const o=Math.max(1,Number(a._sourceWidth??0)),n=Math.max(1,Number(a._sourceHeight??0)),l=Math.min(o,n),c=Number(a.centerX??.5),d=Number(a.centerY??.5),h=Number(a.radius??.25),u=Number(a.angle??4);this.offset&&(this.offset.x=c*o,this.offset.y=d*n),this.radius=h*l,this.angle=u;const p=Qe(this.radius);return this._exportPadding=p,this.padding=Math.max(this.padding??0,p),!0},t.createExportFilter=function(i={}){const r=Number.isFinite(i.previewToNativeScale)?Math.max(1,Number(i.previewToNativeScale)):1,a=this._customParams||e;return Te(a,r)},t.getExportPadding=function(){return Number(this._exportPadding||this.padding||0)},t}catch{return null}},defaultParams:{centerX:.5,centerY:.5,radius:.25,angle:4},controls:[{id:"angle",type:"slider",label:"Angle",property:"angle",min:-10,max:10,step:.1,default:4,tooltip:"Amount of twisting (positive is clockwise)"},{id:"radius",type:"slider",label:"Radius",property:"radius",min:.05,max:.75,step:.01,default:.25,tooltip:"Size of the twist effect (relative to image)"},{id:"centerX",type:"slider",label:"Center X",property:"centerX",min:0,max:1,step:.01,default:.5,tooltip:"Horizontal position of twist center"},{id:"centerY",type:"slider",label:"Center Y",property:"centerY",min:0,max:1,step:.01,default:.5,tooltip:"Vertical position of twist center"}]});const{AdjustmentFilter:Ri}=y;function ee(s){const e=typeof s=="string"?parseInt(s.replace("#","0x"),16):s;return[(e>>16&255)/255,(e>>8&255)/255,(e&255)/255]}class Ti extends Ri{constructor(e={}){super({brightness:1,contrast:1,saturation:1,alpha:1}),this._radius=.8,this._strength=1,this._colorRgb=[0,0,0],this._colorValue="#000000",this._radius=e.radius??.8,this._strength=e.strength??1,e.color!==void 0&&(typeof e.color=="string"?(this._colorValue=e.color,this._colorRgb=ee(e.color)):(this._colorValue="#"+e.color.toString(16).padStart(6,"0"),this._colorRgb=ee(e.color))),this.updateVignette()}updateVignette(){const e=1-this._radius/2,t=this._strength*e;this.brightness=Math.max(.5,1-t*.5),this.contrast=1+t*.2,(this._colorRgb[0]>0||this._colorRgb[1]>0||this._colorRgb[2]>0)&&(this.saturation=1-t*.3)}get radius(){return this._radius}set radius(e){this._radius=Math.max(.1,Math.min(1.5,e)),this.updateVignette()}get strength(){return this._strength}set strength(e){this._strength=Math.max(0,Math.min(2,e)),this.updateVignette()}get color(){return this._colorValue}set color(e){typeof e=="string"?(this._colorValue=e,this._colorRgb=ee(e)):(this._colorValue="#"+e.toString(16).padStart(6,"0"),this._colorRgb=ee(e)),this.updateVignette()}}m({id:"vignette",name:"Vignette",category:"effects",description:"Add a classic darkened border effect to the image",createFilter:s=>{try{const e=new Ti({radius:s.radius||.8,strength:s.strength||1,color:s.color||"#000000"});return e._customParams={...s},e.updateUIParam=function(t,i){const r=this._customParams||{};switch(this._customParams=r,r[t]=i,t){case"radius":this.radius=Math.max(.1,Math.min(1.5,i));break;case"strength":this.strength=Math.max(0,i);break;case"color":this.color=i,typeof i=="string"&&(r.color=i);break;default:t in this&&(this[t]=i);break}},e}catch{return null}},defaultParams:{radius:.8,strength:1,color:"#000000"},controls:[{id:"radius",type:"slider",label:"Radius",property:"radius",min:.1,max:1.5,step:.01,default:.8,tooltip:"Size of the vignette effect (larger values create a smaller vignette)"},{id:"strength",type:"slider",label:"Strength",property:"strength",min:0,max:2,step:.01,default:1,tooltip:"Intensity of the vignette effect"},{id:"color",type:"color",label:"Color",property:"color",default:"#000000",tooltip:"Color of the vignette (usually black)"}]});function Ei(s){try{let e=[],t=[];try{e=K(),e.length===0&&He()}catch{}const i=s==null?void 0:s.disabled;if(Array.isArray(i)&&i.length>0){let r=0;for(const a of i)Vt(a)&&r++;r>0}try{e=K(),t=We()}catch{e||(e=[]),t||(t=[])}return e.length,e}catch{return[]}}exports.CropControls=Ue;exports.CropManager=re;exports.EDITOR_CATEGORIES=ae;exports.EventEmitter=G;exports.FilterManager=De;exports.PixiRenderer=Be;exports.REGISTRY_TO_UI=Ye;exports.RemoveBgManager=Le;exports.Toolbar=Ve;exports.VanillaImageEditor=Yt;exports.checkmark=ie;exports.chevronLeft=de;exports.chevronRight=ue;exports.close=se;exports.createButton=R;exports.createColorPicker=me;exports.createSelect=be;exports.createSlider=pe;exports.createState=Ie;exports.createTextInput=ge;exports.createToggle=fe;exports.el=f;exports.getAllCategories=We;exports.getAllFilters=K;exports.getFilter=qe;exports.getFiltersByCategory=$e;exports.getPreset=je;exports.getRegisteredFilters=Ze;exports.hasFilter=Lt;exports.initializeFilterRegistry=Ei;exports.isFilterCompatibleWithMedia=Ut;exports.registerCorePixiFilters=He;exports.registerFilter=m;
|
|
2
|
+
//# sourceMappingURL=editor-DaM6IN3r.cjs.map
|