@codingfactory/mediables-vue 2.4.0 → 2.4.2
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-D8dt-5Oj.js → PixiFrameExporter-C_1YAQeT.js} +2 -2
- package/dist/{PixiFrameExporter-D8dt-5Oj.js.map → PixiFrameExporter-C_1YAQeT.js.map} +1 -1
- package/dist/{PixiFrameExporter-rWh-JQub.cjs → PixiFrameExporter-Suw6Dxf2.cjs} +2 -2
- package/dist/{PixiFrameExporter-rWh-JQub.cjs.map → PixiFrameExporter-Suw6Dxf2.cjs.map} +1 -1
- package/dist/editor-BUpGsg4D.cjs +42 -0
- package/dist/editor-BUpGsg4D.cjs.map +1 -0
- package/dist/{editor-624YYYUE.js → editor-Cw08D0SQ.js} +323 -281
- package/dist/editor-Cw08D0SQ.js.map +1 -0
- package/dist/{index-Bwmk8LYJ.js → index-mZS1mNLQ.js} +3 -3
- package/dist/{index-Bwmk8LYJ.js.map → index-mZS1mNLQ.js.map} +1 -1
- package/dist/{index-PyOrcGKi.cjs → index-wOQ7eP9R.cjs} +3 -3
- package/dist/{index-PyOrcGKi.cjs.map → index-wOQ7eP9R.cjs.map} +1 -1
- 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/package.json +1 -1
- package/dist/editor-624YYYUE.js.map +0 -1
- package/dist/editor-BU3jmGLs.cjs +0 -42
- package/dist/editor-BU3jmGLs.cjs.map +0 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";var Pe=Object.defineProperty;var Me=(s,e,t)=>e in s?Pe(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var j=(s,e,t)=>Me(s,typeof e!="symbol"?e+"":e,t);const Fe=require("pixi-filters"),oe=require("pixi.js");function ne(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 b=ne(Fe),S=ne(oe);class O{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 Ae extends O{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},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(){const e=[];if(this._state.activeFilters)for(const i of this._state.activeFilters){const r=this._state.filterValues[i];e.push({id:i,enabled:!0,values:r?{...r}:{}})}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"},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 ze(){return new Ae}class Re extends O{constructor(){super(),this.app=null,this.sprite=null,this.originalTexture=null,this.baseTexture=null,this.fitScale=1,this.zoom=1,this._container=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{}}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){if(!e)return;this._container=e;const i=async()=>{var l;const r=window.PIXI;if(!r)throw new Error("PIXI.js not found. Please ensure PIXI is loaded globally.");(l=r.Assets)!=null&&l.setPreferences&&r.Assets.setPreferences({crossOrigin:"anonymous"});const a=e.clientWidth||600,o=e.clientHeight||400;this.app=new r.Application,await this.app.init({width:a,height:o,backgroundColor:t,antialias:!0,autoDensity:!0,resolution:window.devicePixelRatio||1}),e.appendChild(this.app.canvas);const n=this.app.canvas;n.classList.add("pixi-canvas"),n.style.width="100%",n.style.height="100%",n.style.transform="translateZ(0)",n.style.willChange="transform",n.setAttribute("role","img"),n.setAttribute("aria-label","Image editor canvas — use toolbar controls to edit the image"),this.emit("mounted",{width:a,height:o})};this._mountPromise=i(),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 new Promise(requestAnimationFrame),!((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}exportImage(e="png",t=.92,i=0,r=!0){var y;if(!((y=this.app)!=null&&y.renderer)||!this.originalTexture||!this.sprite)return null;const a=window.PIXI,o=Math.round(this.originalTexture.width),n=Math.round(this.originalTexture.height);if(o<=0||n<=0)return null;let l=o;if(i>0){const _=Math.max(o,n);let v=i/_;r&&(v=Math.min(1,v)),l=Math.round(o*v)}const c=this.sprite,d=c.x,h=c.y,p=c.width,m=c.height;if(p<=0||m<=0)return null;const x=l/p;let g=null;try{if(c.x=0,c.y=0,g=a.RenderTexture.create({width:Math.ceil(p),height:Math.ceil(m),resolution:x}),this.app.renderer.render({container:this.app.stage,target:g}),!this.app.renderer.extract)return null;const _=this.app.renderer.extract.canvas(g);if(!_)return null;let v=null;if(typeof _.toDataURL=="function")v=_.toDataURL(`image/${e}`,t);else if(typeof _.getContext=="function"){const C=document.createElement("canvas");C.width=_.width,C.height=_.height;const L=C.getContext("2d");L&&(L.drawImage(_,0,0),v=C.toDataURL(`image/${e}`,t))}return v||null}catch{return null}finally{c.x=d,c.y=h,g&&g.destroy(!0)}}getExportDimensions(){const e=this.originalTexture;return{width:Math.round((e==null?void 0:e.width)||0),height:Math.round((e==null?void 0:e.height)||0)}}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 Ne={adjust:["adjust","advanced"],blur:["blur"],color:["color"],effects:["effects"],distortion:["distortion"],light:["light"],stylize:["stylize"]};class Te extends O{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=Ne[e]||[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}_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);t&&t.controls.forEach(i=>{const r=this.state.getFilterValues(e);i.id in r||this.state.setFilterValue(e,i.id,i.default)})}resetValues(e){const t=this.getFilterDef(e);t&&t.controls.forEach(i=>{this.state.setFilterValue(e,i.id,i.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);this.state.setFilterValue(e,t,r);const a=this.instances[e];if(a){const o=this.getFilterDef(e),n=o==null?void 0:o.controls.find(c=>c.id===t),l=(n==null?void 0:n.property)||t;return typeof a.updateUIParam=="function"?(a.updateUIParam(l,r),!0):(this._setDeepProp(a,l,r),a.uniforms&&l in a.uniforms&&(a.uniforms[l]=r),!0)}return!1}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(d=>{const h=d.property||d.id;l[h]=n[d.id]??d.default});const c=o.createFilter(l);c&&(t.push(c),this.instances[a]=c)}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 T=class T extends O{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"),o=r==="circle"||!!this.state.get("autoZoomOnCropOverflow")?{x:0,y:0,w:i.screen.width,h:i.screen.height}:{x:t.x,y:t.y,w:t.width,h:t.height};if(e.x=Math.max(o.x,Math.min(e.x,o.x+o.w-e.width)),e.y=Math.max(o.y,Math.min(e.y,o.y+o.h-e.height)),e.width=Math.min(e.width,o.w),e.height=Math.min(e.height,o.h),r!=="free"||this.state.get("crop.aspect")==="1:1"){const n=Math.min(e.width,e.height);e.width=n,e.height=n}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=T.AUTO_ZOOM_PADDING;let h=n;if(l){const p=e.width/(d*r*o);h=Math.min(h,p)}if(c){const p=e.height/(d*a*o);h=Math.min(h,p)}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<T.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=T.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 y=l.x+l.width/2,P=l.y+l.height/2,_=Math.min(l.width,l.height)/2;n.beginPath(),n.arc(y,P,_,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 y=1;y<=2;y++)n.beginPath(),n.moveTo(l.x+d*y,l.y),n.lineTo(l.x+d*y,l.y+l.height),n.stroke(),n.beginPath(),n.moveTo(l.x,l.y+h*y),n.lineTo(l.x+l.width,l.y+h*y),n.stroke();const p=this.HANDLE_SIZE,m=[{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"}],x=[{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=[...m,...x];for(const y of g){const P=this._hoverMode===y.m,_=P?p+4:p;n.beginPath(),n.rect(y.x-_/2,y.y-_/2,_,_),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.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){const a=Math.min(e.screen.width,e.screen.height)*.7,o=t.x+(t.width-a)/2,n=t.y+(t.height-a)/2;i={x:o,y:n,width:a,height:a},this.state.set("crop.rect",i),this.state.get("crop.shape")==="circle"&&this.state.set("crop.aspect","1:1"),this.state.get("crop.aspect")!=="free"&&(this.applyAspectRatio(),this.constrainCropRect())}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._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)),p=Math.round(Math.max(1,r.height*l)),m=Math.round(c),x=Math.round(d);if(h<=0||p<=0)return null;const g=new a.Container,y=new a.Sprite(i);if(this.state.get("crop.shape")==="circle"){const V=Math.round(Math.max(h,p)),ve=m+h/2,ke=x+p/2;m=Math.round(ve-V/2),x=Math.round(ke-V/2),h=p=V;const A=new a.Graphics;typeof A.circle=="function"&&typeof A.fill=="function"?A.circle(h/2,p/2,h/2).fill(16777215):(A.beginFill(16777215,1),A.drawCircle(h/2,p/2,h/2),A.endFill()),y.mask=A,g.addChild(A)}y.x=-m,y.y=-x,g.addChild(y);const _=a.RenderTexture.create({width:h,height:p});e.renderer.render({container:g,target:_,clear:!0}),g.destroy({children:!0});const v=this.renderer.originalTexture;v&&v!==this.renderer.baseTexture&&v.destroy(!0),this.renderer.originalTexture=_,e.stage.removeChild(t),t.destroy();const C=new a.Sprite(_);e.stage.addChild(C),this.renderer.sprite=C,this.renderer.fitScale=this.renderer.getFitScaleFor(_),this.renderer.setZoom(o,{keepCenter:!1}),this.renderer.applyViewTransform(),this.renderer.render();const L={x:m,y:x,width:h,height:p},we=this.state.get("crop.shape")||"free",Se=this.state.get("crop.aspect")||"free";return this.disable(),this.state.set("crop.appliedRect",L),this.state.set("crop.appliedShape",we),this.state.set("crop.appliedAspect",Se),this.emit("applied",{width:h,height:p}),{texture:_,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 p=new o.Container,m=new o.Sprite(a);if(t==="circle"){const P=Math.round(Math.max(l,c)),_=d+l/2,v=h+c/2;d=Math.round(_-P/2),h=Math.round(v-P/2),l=c=P;const C=new o.Graphics;typeof C.circle=="function"&&typeof C.fill=="function"?C.circle(l/2,c/2,l/2).fill(16777215):(C.beginFill(16777215,1),C.drawCircle(l/2,c/2,l/2),C.endFill()),m.mask=C,p.addChild(C)}m.x=-d,m.y=-h,p.addChild(m);const x=o.RenderTexture.create({width:l,height:c});i.renderer.render({container:p,target:x,clear:!0}),p.destroy({children:!0});const g=this.renderer.originalTexture;g&&g!==this.renderer.baseTexture&&g.destroy(!0),this.renderer.originalTexture=x,i.stage.removeChild(r),r.destroy();const y=new o.Sprite(x);return i.stage.addChild(y),this.renderer.sprite=y,this.renderer.fitScale=this.renderer.getFitScaleFor(x),this.renderer.setZoom(n,{keepCenter:!1}),this.renderer.applyViewTransform(),this.renderer.render(),{texture:x,preservedZoom:n}}cancel(){this.disable(),this.emit("cancelled")}setShape(e){this.state.get("lockCropShape")||(this.state.set("crop.shape",e),(e==="circle"||e==="square")&&this.state.set("crop.aspect","1:1"),this.applyAspectRatio(),this.constrainCropRect(),this.drawOverlay())}setAspect(e){this.state.get("lockAspectRatio")||(this.state.set("crop.aspect",e),this.applyAspectRatio(),this.constrainCropRect(),this.drawOverlay())}};j(T,"AUTO_ZOOM_PADDING",1.1),j(T,"AUTO_ZOOM_THROTTLE_MS",100);let W=T;class Ie{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 u(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 le({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=u("div",{className:"slider-control slider-wrapper","data-control":n,"data-testid":`slider-${n}`}),c=u("div",{className:"slider-header"},u("label",{for:s,className:"slider-label"},e),u("span",{className:"slider-value",id:`${s}-value`},q(a))),d=u("input",{type:"range",id:s,className:"slider-input",min:String(t),max:String(i),step:String(r),value:String(a),onInput:h=>{const p=parseFloat(h.target.value),m=l.querySelector(".slider-value");m&&(m.textContent=q(p)),o==null||o(p)}});return l.appendChild(c),l.appendChild(d),l.setValue=h=>{d.value=String(h);const p=l.querySelector(".slider-value");p&&(p.textContent=q(h))},l}function q(s){return Number.isInteger(s)?String(s):s.toFixed(2)}function ce({id:s,label:e,checked:t=!1,onChange:i}){const r=u("div",{className:"toggle-control"}),a=u("label",{className:"toggle-label",for:s},e),o=u("input",{type:"checkbox",id:s,className:"toggle-input",checked:t?"checked":void 0,onChange:c=>i==null?void 0:i(c.target.checked)}),n=u("div",{className:"toggle-switch",onClick:c=>{c.target!==o&&(o.checked=!o.checked,i==null||i(o.checked))}}),l=u("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 he({id:s,label:e,value:t="#000000",onChange:i}){const r=u("div",{className:"color-control"}),a=u("label",{className:"color-label",for:s},e),o=u("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 de({id:s,label:e,options:t=[],value:i,onChange:r}){const a=u("div",{className:"select-control"}),o=u("label",{className:"select-label",for:s},e),n=u("select",{id:s,className:"select-input",onChange:l=>r==null?void 0:r(l.target.value)});for(const l of t){const c=u("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 z({label:s,className:e="",onClick:t,icon:i=null,disabled:r=!1}){const a=u("button",{type:"button",className:`btn ${e}`.trim(),onClick:t,disabled:r?"disabled":void 0});if(i){const o=u("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 w({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=u("button",n);l.innerHTML=s;const c=l.querySelector("svg");return c&&c.setAttribute("aria-hidden","true"),l}function Z({label:s,icon:e,active:t=!1,onClick:i}){const r=u("button",{type:"button",className:`chip ${t?"active":""}`.trim(),onClick:i});if(e){const a=u("span",{className:"chip-icon"});a.innerHTML=e;const o=a.querySelector("svg");o&&o.setAttribute("aria-hidden","true"),r.appendChild(a)}return r.appendChild(u("span",{className:"chip-label"},s)),r.setActive=a=>{r.classList.toggle("active",a)},r}const 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="M328 112L184 256l144 144"/></svg>',pe='<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>',Ee='<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>',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="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>',Ye='<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>',Be='<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>',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="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>',Le='<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>',De='<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>',Ue='<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>',Ve='<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>',fe='<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>',je='<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>',K='<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>',me='<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>',qe='<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>',He='<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>',G='<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>',$e='<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>',We='<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>',Ze='<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>',Q='<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>',J='<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>',Ge='<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>';class Ke{constructor(e,t){this.state=e,this.editor=t,this.element=null,this._unsubscribers=[]}render(){this.element=u("div",{className:"editor-toolbar"});const e=u("div",{className:"toolbar-section toolbar-left"}),t=w({icon:He,title:"Open Image",className:"toolbar-btn",testId:"btn-open-image",ariaLabel:"Open image file",onClick:()=>this.editor.openFilePicker()});e.appendChild(t);const i=u("div",{className:"toolbar-section toolbar-center"}),r=w({icon:Xe,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=u("span",{className:"zoom-label","aria-live":"polite","aria-atomic":"true",role:"status"},"100%");const a=w({icon:Ee,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=w({icon:Ye,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=u("div",{className:"toolbar-section toolbar-right"});this._themeBtn=w({icon:this.state.get("isDarkMode")?Q:J,title:"Toggle Theme",className:"toolbar-btn toolbar-btn-theme",testId:"btn-toggle-theme",ariaLabel:"Toggle theme",onClick:()=>this.editor.toggleTheme()}),this._cropBtn=w({icon:fe,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=w({icon:me,title:"Reset All",className:"toolbar-btn",testId:"btn-reset-all",ariaLabel:"Reset all changes",onClick:()=>this.editor.resetAll()}),c=w({icon:je,title:"Save Image",className:"toolbar-btn toolbar-btn-primary",testId:"btn-save-edit",ariaLabel:"Save image",onClick:()=>this.editor.save()}),d=w({icon:K,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?Q:J});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 D=[{id:"adjust",name:"Adjust",icon:Be},{id:"blur",name:"Blur",icon:Oe},{id:"color",name:"Color",icon:Le},{id:"effects",name:"Effects",icon:De},{id:"distortion",name:"Distortion",icon:Ue},{id:"light",name:"Light",icon:Ve},{id:"stylize",name:"Stylize",icon:Ge},{id:"crop",name:"Crop",icon:fe}];class Qe{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=u("div",{className:"category-carousel-container","data-testid":"category-carousel"}),this._leftBtn=w({icon:ue,title:"Previous categories",className:"carousel-nav carousel-nav-left",onClick:()=>this._scrollLeft()}),this._carousel=u("div",{className:"category-carousel"}),D.forEach(i=>{const r=Z({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=w({icon:pe,title:"Next categories",className:"carousel-nav carousel-nav-right",onClick:()=>this._scrollRight()}),this._pagination=u("div",{className:"carousel-pagination",role:"tablist","aria-label":"Category pages"});const t=Math.ceil(D.length/3);for(let i=0;i<t;i++){const r=u("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 t;this.state.set("selectedCategory",e),e==="crop"?this.editor.setMode("crop"):this.editor.setMode("filters"),(t=this._onSelect)==null||t.call(this,e)}_scrollLeft(){this._scrollIndex>0&&(this._scrollIndex--,this._scrollCarousel())}_scrollRight(){this._scrollIndex<D.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>=D.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 Je{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=u("div",{className:"filter-carousel-container"}),this._leftBtn=w({icon:ue,title:"Previous filters",className:"carousel-nav carousel-nav-left",onClick:()=>this._scrollLeft()}),this._carousel=u("div",{className:"filter-carousel"}),this._rightBtn=w({icon:pe,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=u("div",{className:`filter-card ${t?"active":""} ${i?"selected":""}`,"data-filter":e.id,"data-testid":`filter-${e.id}`,onClick:()=>this._handleCardClick(e.id)}),a=u("div",{className:"filter-preview"}),o=u("span",{className:"filter-preview-text"},e.name.charAt(0));a.appendChild(o);const n=u("span",{className:"filter-name",title:e.name},e.name),l=u("button",{className:`filter-toggle ${t?"active":""}`,onClick:c=>{var p;c.stopPropagation();const h=!this.state.get("activeFilters").has(e.id);this._handleToggle(e.id,h),h&&(this.state.set("selectedFilter",e.id),(p=this._onSelect)==null||p.call(this,e.id))}});return l.innerHTML=t?G:"",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?G:"",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 et{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=u("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(u("div",{className:"no-filter-selected"},"Select a filter to adjust"));return}const t=this.filterManager.getFilterDef(e);if(!t){this.element.appendChild(u("div",{className:"no-filter-selected"},"Filter not found"));return}const i=u("div",{className:"adjustments-header"});i.appendChild(u("span",{className:"adjustments-title"},t.name)),i.appendChild(z({label:"Reset",className:"btn-text",onClick:()=>this._handleReset(e)})),this.element.appendChild(i);const r=u("div",{className:"adjustments-grid"}),a=this.state.getFilterValues(e);t.controls.forEach(o=>{const n=this._createControl(e,o,a[o.id]??o.default);n&&(this._controls.set(o.id,n),r.appendChild(n))}),this.element.appendChild(r)}_createControl(e,t,i){if(t.hidden)return null;const r=t.label||t.id;switch(this._normalizeControlType(t.type)){case"slider":return le({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:l=>this._handleChange(e,t.id,l)});case"toggle":return ce({id:`${e}-${t.id}`,label:r,checked:!!i,onChange:l=>this._handleChange(e,t.id,l)});case"color":return he({id:`${e}-${t.id}`,label:r,value:typeof i=="string"&&i.startsWith("#")?i:t.default||"#000000",onChange:l=>this._handleChange(e,t.id,l)});case"select":const o=this._normalizeOptions(t.options);return de({id:`${e}-${t.id}`,label:r,options:o,value:i??t.default,onChange:l=>this._handleChange(e,t.id,l)});case"button":const n=u("div",{className:"button-control"});return n.appendChild(z({label:r,className:"btn-secondary",onClick:()=>this._handleAction(e,t.action||t.id)})),n;default:return null}}_normalizeControlType(e){return{slider:"slider",range:"slider",toggle:"toggle",checkbox:"toggle",color:"color",select:"select",dropdown:"select",button:"button",text:"slider"}[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)}_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 tt{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=u("div",{className:"mobile-filter-drawer"});const o=u("div",{className:"drawer-header"});this._titleEl=u("span",{className:"drawer-title"},"Filter");const n=u("div",{className:"drawer-header-actions"}),l=z({label:"Reset",className:"btn-text",onClick:()=>{var h;this._currentFilterId&&((h=this._onReset)==null||h.call(this,this._currentFilterId),this._renderControls())}}),c=z({label:"Remove",className:"btn-text btn-danger",onClick:()=>{var h;this._currentFilterId&&((h=this._onRemove)==null||h.call(this,this._currentFilterId),this.close())}}),d=w({icon:K,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=u("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=u("div",{className:"adjustments-grid"}),i=this.state.getFilterValues(this._currentFilterId);e.controls.forEach(r=>{if(r.hidden)return;const a=this._createControl(this._currentFilterId,r,i[r.id]??r.default);a&&(this._controls.set(r.id,a),t.appendChild(a))}),this._body.appendChild(t)}_createControl(e,t,i){const r=t.label||t.id;switch(this._normalizeControlType(t.type)){case"slider":return le({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:o=>{var n;return(n=this._onChange)==null?void 0:n.call(this,e,t.id,o)}});case"toggle":return ce({id:`drawer-${e}-${t.id}`,label:r,checked:!!i,onChange:o=>{var n;return(n=this._onChange)==null?void 0:n.call(this,e,t.id,o)}});case"color":return he({id:`drawer-${e}-${t.id}`,label:r,value:typeof i=="string"&&i.startsWith("#")?i:t.default||"#000000",onChange:o=>{var n;return(n=this._onChange)==null?void 0:n.call(this,e,t.id,o)}});case"select":{const o=this._normalizeOptions(t.options);return de({id:`drawer-${e}-${t.id}`,label:r,options:o,value:i??t.default,onChange:n=>{var l;return(l=this._onChange)==null?void 0:l.call(this,e,t.id,n)}})}case"button":{const o=u("div",{className:"button-control"});return o.appendChild(z({label:r,className:"btn-secondary",onClick:()=>{var n;return(n=this._onAction)==null?void 0:n.call(this,e,t.action||t.id)}})),o}default:return null}}_normalizeControlType(e){return{slider:"slider",range:"slider",toggle:"toggle",checkbox:"toggle",color:"color",select:"select",dropdown:"select",button:"button",text:"slider"}[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 it{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=u("div",{className:"mobile-active-filters","data-testid":"mobile-active-filters"}),this._scrollContainer=u("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=u("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=u("div",{className:"active-filter-chip","data-filter-id":e,"data-testid":`active-chip-${e}`}),r=u("span",{className:"active-filter-chip-label",onClick:o=>{var n;o.stopPropagation(),(n=this._onSelect)==null||n.call(this,e)}},t.name),a=u("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 rt=[{id:"free",name:"Free",icon:Ze},{id:"square",name:"Square",icon:$e},{id:"circle",name:"Circle",icon:We}],st=[{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"}];class at{constructor(e,t){this.state=e,this.cropManager=t,this.element=null,this._shapeChips=new Map,this._aspectChips=new Map,this._unsubscribers=[]}_applyCropAndReturnToFilters(){this.cropManager.apply()===null&&typeof this.cropManager.disable=="function"&&this.cropManager.disable(),this.state.set("selectedCategory","adjust")}render(){this.element=u("div",{className:"crop-controls","data-testid":"crop-controls"});const e=u("div",{className:"crop-section"});e.appendChild(u("label",{className:"section-label"},"Shape"));const t=u("div",{className:"chip-row"}),i=this.state.get("crop.shape");rt.forEach(c=>{const d=Z({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=u("div",{className:"crop-section"}),this._aspectSection.appendChild(u("label",{className:"section-label"},"Aspect Ratio"));const r=u("div",{className:"chip-row aspect-row"}),a=this.state.get("crop.aspect");st.forEach(c=>{const d=Z({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=u("div",{className:"crop-actions"}),n=z({label:"Cancel",className:"btn-secondary crop-cancel-btn",icon:K,onClick:()=>this.cropManager.cancel()});n.dataset.testid="cancel-crop";const l=z({label:"Apply Crop",className:"btn-primary crop-apply-btn",icon:G,onClick:()=>this._applyCropAndReturnToFilters()});return l.dataset.testid="apply-crop",o.appendChild(n),o.appendChild(l),this.element.appendChild(o),this._subscribeToState(),this.element}_subscribeToState(){const e=this.state.on("change:crop.shape",({value:i})=>{this._shapeChips.forEach((r,a)=>{r.setActive(a===i)}),this._updateAspectVisibility()});this._unsubscribers.push(e);const t=this.state.on("change:crop.aspect",({value:i})=>{this._aspectChips.forEach((r,a)=>{r.setActive(a===i)})});this._unsubscribers.push(t)}_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(),(e=this.element)==null||e.remove(),this.element=null}}class ot{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=u("div",{className:"active-filters-panel","data-testid":"active-filters-panel"});const o=u("div",{className:"panel-header"});o.appendChild(u("h3",{className:"panel-title"},"Active Filters"));const n=z({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=u("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(u("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=u("div",{className:`active-filter-item ${r?"selected":""}`,"data-active-filter":e,"data-testid":`active-filter-${e}`,onClick:m=>{m.target.closest(".filter-item-actions")||this._handleSelect(e)}}),o=u("div",{className:"filter-item-header"}),n=u("span",{className:"filter-item-name"},t.name),l=u("div",{className:"filter-item-actions"}),c=w({icon:me,title:"Reset filter",className:"btn-icon-sm",onClick:()=>this._handleReset(e)}),d=w({icon:qe,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),p=u("div",{className:"filter-item-summary"});return p.textContent=this._getValuesSummary(t,h),a.appendChild(p),a._summaryEl=p,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 Y={name:"free",initialMode:"filters",cropShape:"free",aspectRatio:"free",autoZoomOnCropOverflow:!1,lockCropShape:!1,lockAspectRatio:!1,showFilters:!0,showCropControls:!0,maxExportWidth:void 0,maxExportHeight:void 0},H={free:{...Y},avatar:{...Y,name:"avatar",initialMode:"crop",cropShape:"circle",aspectRatio:"1:1",autoZoomOnCropOverflow:!0,lockCropShape:!0,lockAspectRatio:!0},banner:{...Y,name:"banner",initialMode:"crop",cropShape:"square",aspectRatio:"16:9",autoZoomOnCropOverflow:!1,lockCropShape:!1,lockAspectRatio:!0},product:{...Y,name:"product",initialMode:"filters",cropShape:"square",aspectRatio:"1:1",autoZoomOnCropOverflow:!1,lockCropShape:!1,lockAspectRatio:!1}};function nt(s){if(!s)return{...H.free};if(typeof s=="object"&&s!==null)return{...Y,...s};const e=H[s];return e?{...e}:{...H.free}}class lt extends O{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?nt(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=ze(),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 Re,this._filterManager=new Te(this._state,this._renderer),this._cropManager=new W(this._state,this._renderer),this._removeBgManager=null,((a=this._options.backgroundRemoval)==null?void 0:a.enabled)!==!1&&(this._removeBgManager=new Ie({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=u("div",{className:`vanilla-image-editor ${this._state.get("isDarkMode")?"dark":"light"}`});const e=u("div",{className:"editor-toolbar-container"});this._editorEl.appendChild(e),this._toolbarContainer=e;const t=u("div",{className:"editor-content"}),i=u("div",{className:"canvas-section"});this._canvasContainer=u("div",{className:"canvas-container"}),this._cropOverlay=u("canvas",{className:"crop-overlay","aria-hidden":"true"}),i.appendChild(this._canvasContainer),i.appendChild(this._cropOverlay),t.appendChild(i),this._controlsSection=u("div",{className:"controls-section"}),t.appendChild(this._controlsSection),this._editorEl.appendChild(t),this._fileInput=u("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 Ke(this._state,this),this._toolbarContainer.appendChild(this._toolbar.render()),this._filterControlsEl=u("div",{className:"filter-controls-container"}),this._categoryCarousel=new Qe(this._state,this),this._filterControlsEl.appendChild(this._categoryCarousel.render(r=>{}));const e=u("div",{className:"filter-layout"}),t=u("div",{className:"filter-left-column"});this._filterCarousel=new Je(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 et(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=u("div",{className:"filter-right-column"});this._activeFiltersPanel=new ot(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 it(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 at(this._state,this._cropManager),this._cropControlsEl=this._cropControls.render(),this._cropControlsEl.style.display="none",this._controlsSection.appendChild(this._filterControlsEl),this._controlsSection.appendChild(this._cropControlsEl),this._mobileFilterDrawer=new tt(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){const i=this._filterManager.getInstance(e);i&&typeof i.updateUIParam=="function"&&(i.updateUIParam(t,!0),this._filterManager.applyFilters())}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.shape",this._options.cropShape||"free"),this._state.set("crop.aspect",this._options.initialAspectRatio||"free"),this._state.get("mode")==="crop"&&(this._cropManager.disable(),this._state.set("mode","filters"))}_hydrateState(e){if(!(!e||e.version!==1)){if(e.crop){const t=e.crop.shape||"free",i=e.crop.aspectRatio||"free";e.crop.rect&&(this._cropManager.applyFromPixelRect(e.crop.rect,t),this._state.set("crop.appliedRect",{...e.crop.rect}),this._state.set("crop.appliedShape",t),this._state.set("crop.appliedAspect",i)),this._state.set("crop.shape",t),this._state.set("crop.aspect",i)}if(Array.isArray(e.filters)){for(const t of e.filters)if(t.enabled&&(this._state.toggleFilter(t.id,!0),this._filterManager.initializeValues(t.id),t.values))for(const[i,r]of Object.entries(t.values))this._state.setFilterValue(t.id,i,r);this._filterManager.applyFilters()}}}openFilePicker(){var e;(e=this._fileInput)==null||e.click()}exportImage(e="png",t=.92){return this._renderer.exportImage(e,t)}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"},filters:t}}close(){this.emit("cancel")}setZoom(e){this._renderer.setZoom(e)}fitToScreen(){this._renderer.fitToScreen()}resetAll(){this._filterManager.resetAll()}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=u("div",{className:"editor-loading-overlay"},[u("div",{className:"editor-loading-spinner"}),u("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 k=new Map,I=new Map;function ct(s,e){return!Array.isArray(s.mediaTargets)||s.mediaTargets.length===0?!0:s.mediaTargets.includes(e)}function f(s){var e;return k.has(s.id),k.set(s.id,s),I.has(s.category)||I.set(s.category,[]),(e=I.get(s.category))==null||e.push(s.id),s}function ge(s){return k.get(s)}function B(){return Array.from(k.values())}function be(){B().map(t=>t.id),Object.entries(b).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();k.has(r)||f({id:r,name:t.replace(/Filter$/,""),category:"unlisted",mediaTargets:["image"],defaultParams:{},controls:[],createFilter:(a={})=>{try{return new i(a)}catch{return null}}})})}function ye(s){return(I.get(s)||[]).map(t=>k.get(t)).filter(Boolean)}function _e(){return Array.from(I.keys())}function ht(s){return k.has(s)}function dt(s){const e=k.get(s);if(!e)return!1;k.delete(s);const t=I.get(e.category);if(t){const i=t.indexOf(s);i!==-1&&t.splice(i,1),t.length===0&&I.delete(e.category)}return!0}function ut(s,e){const t=k.get(s);return t?ct(t,e):!1}function xe(){return Array.from(k.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(k.keys()),window.getAllFilters=B,window.getFilter=ge,window.getFiltersByCategory=ye,window.getRegisteredFilters=xe;const s=f;window.registerFilter=e=>{const t=s(e);return window.__DEBUG_FILTERS_LIST=Array.from(k.keys()),t}}typeof window<"u"&&(window.initializeFilterRegistry=window.initializeFilterRegistry||function(){return[]});const{AdjustmentFilter:pt}=b,{ColorMatrixFilter:ft}=S,M={gamma:1,saturation:1,contrast:1,brightness:1,red:1,green:1,blue:1,alpha:1},mt=new Set(["gamma","saturation","contrast","brightness","red","green","blue","alpha"]);function F(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 ee(s){return mt.has(s)}function gt(s){return{gamma:F(s.gamma,M.gamma),saturation:F(s.saturation,M.saturation),contrast:F(s.contrast,M.contrast),brightness:F(s.brightness,M.brightness),red:F(s.red,M.red),green:F(s.green,M.green),blue:F(s.blue,M.blue),alpha:F(s.alpha,M.alpha)}}function te(s,e){s.reset(),s.brightness(e.brightness,!0),s.contrast(e.contrast,!0),s.saturate(e.saturation,!0)}f({id:"adjustment",name:"Adjustment",category:"adjust",description:"Adjust basic image properties like brightness, contrast, and saturation",createFilter:s=>{try{const e=gt(s??{}),t={...e};try{const i=new pt(t),r=i;return r._customParams={...e},r.updateUIParam=function(o,n){try{if(!ee(o))return;const l=this._customParams??{...M},c=F(n,l[o]);l[o]=c,this._customParams=l;const d=this;o in d&&(d[o]=c)}catch{}},i}catch{const r=new ft,a=r;return a._customParams={...e},te(r,e),a.updateUIParam=function(n,l){try{if(!ee(n))return;const c=this._customParams??{...M},d=F(l,c[n]);c[n]=d,this._customParams=c,te(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:bt}=S,N={brightness:1,contrast:1,saturation:1,hue:0,sepia:0,negative:!1},yt=new Set(["brightness","contrast","saturation","hue","sepia","negative"]);function _t(s){return yt.has(s)}function X(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,e){if(typeof s=="boolean")return s;if(typeof s=="string"){if(s==="true")return!0;if(s==="false")return!1}return e}function xt(s){return{brightness:X(s.brightness,N.brightness),contrast:X(s.contrast,N.contrast),saturation:X(s.saturation,N.saturation),hue:X(s.hue,N.hue),sepia:X(s.sepia,N.sepia),negative:Ce(s.negative,N.negative)}}function ie(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)}f({id:"adjustment-advanced",name:"Advanced Adjustment",category:"adjust",description:"Comprehensive image adjustments including brightness, contrast, saturation, hue, and more",createFilter:s=>{try{const e=xt(s??{}),t=new bt,i=t;return i._customParams={...e},ie(t,e),i.updateUIParam=function(a,o){try{if(!_t(a))return;const n=this._customParams??{...N};if(a==="negative")n.negative=Ce(o,n.negative);else{const l=a;n[l]=X(o,n[l])}this._customParams=n,ie(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}]});f({id:"alpha",name:"Alpha",category:"adjust",description:"Adjust the transparency of the image",createFilter:s=>{try{const e=s.alpha!==void 0?s.alpha:1,t=new S.ColorMatrixFilter;return t.alpha=e,t._customParams={alpha:e},t.updateUIParam=function(i,r){try{const a=this._customParams||{};if(this._customParams=a,i==="alpha"){const o=Number(r);this.alpha=o,a.alpha=o}else i in this&&(this[i]=r)}catch{}},t}catch{return null}},defaultParams:{alpha:1},controls:[{id:"alpha",type:"slider",label:"Transparency",property:"alpha",min:0,max:1,step:.01,default:1}]});f({id:"blur",name:"Blur",category:"blur",description:"Apply a smooth blur effect to the entire image",createFilter:s=>{try{const e=new S.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}]});f({id:"color-matrix",name:"Color Matrix",category:"advanced",description:"Advanced color adjustments including sepia, hue rotation, and more",createFilter:s=>{const e=S.ColorMatrixFilter;if(!e)return null;const t=new e;try{return typeof t.reset=="function"&&t.reset(),s.brightness!==1&&typeof t.brightness=="function"&&t.brightness(s.brightness,!1),s.contrast!==1&&typeof t.contrast=="function"&&t.contrast(s.contrast,!1),s.saturation!==1&&typeof t.saturate=="function"&&t.saturate(s.saturation,!1),s.hue!==0&&typeof t.hue=="function"&&t.hue(s.hue,!1),s.sepia>0&&typeof t.sepia=="function"&&t.sepia(s.sepia),s.negative&&typeof t.negative=="function"&&t.negative(!1),t}catch{return t}},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: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:"slider",label:"Sepia",property:"sepia",min:0,max:1,step:.01,default:0},{id:"negative",type:"toggle",label:"Negative",property:"negative",default:!1}]});const{ColorOverlayFilter:Ct}=b;f({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 Ct({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}]});f({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={x:t*Math.cos(i*Math.PI/180),y:t*Math.sin(i*Math.PI/180)},a=new b.DropShadowFilter({offset:r,color:parseInt(e,16),alpha:s.alpha!==void 0?s.alpha:.5,blur:s.blur!==void 0?s.blur:2,quality:s.quality!==void 0?s.quality:3,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}});return a._customParams={...s,_offset:r,_distance:t,_angle:i},a.updateUIParam=function(o,n){try{const l=this._customParams||{};switch(this._customParams=l,l[o]=n,o){case"color":if(typeof n=="string"){const d=parseInt(n.replace("#","0x"),16);this.color=d}break;case"alpha":this.alpha=Number(n);break;case"blur":this.blur=Number(n);break;case"quality":this.quality=Number(n);break;case"shadowOnly":this.shadowOnly=!!n;break;case"pixelSizeX":this.pixelSizeX=Number(n),l.pixelSizeX=Number(n);break;case"pixelSizeY":this.pixelSizeY=Number(n),l.pixelSizeY=Number(n);break;case"distance":case"angle":o==="distance"?l._distance=Number(n):l._angle=Number(n);const c={x:l._distance*Math.cos(l._angle*Math.PI/180),y:l._distance*Math.sin(l._angle*Math.PI/180)};l._offset=c,this.offset=c;break;default:o in this&&(this[o]=n);break}return!0}catch{return this._customParams&&(this._customParams[o]=n),!1}},a}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:wt}=S;f({id:"grayscale",name:"Grayscale",category:"color",description:"Convert the image to black and white with adjustable intensity",createFilter:s=>{try{const e=new wt;e._customParams={...s};const t=s.intensity!==void 0?s.intensity:1;return re(e,t),e.updateUIParam=function(i,r){const a=this._customParams||{};switch(this._customParams=a,a[i]=r,i){case"intensity":re(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 re(s,e){s.reset(),s.greyscale(e)}const{HslAdjustmentFilter:St}=b;f({id:"hsl-adjustment",name:"HSL Adjustment",category:"color",description:"Control hue, saturation, and lightness independently",createFilter:s=>{try{const e=new St({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:vt}=b;f({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 vt({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:kt}=b;f({id:"motion-blur",name:"Motion Blur",category:"blur",description:"Creates a directional blur effect simulating motion",createFilter:s=>{try{const e=new kt({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:Pt}=b;f({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 Pt({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:Mt}=b;f({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 Mt({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:Ft}=b;f({id:"zoom-blur",name:"Zoom Blur",category:"blur",description:"Creates a zoom blur effect from a center point",createFilter:s=>{try{const e=new Ft({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:se}=b;f({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=>{try{let e=[];e=(s.colorStops||[{offset:0,color:"#ff0000",alpha:1},{offset:1,color:"#0000ff",alpha:1}]).map(i=>({offset:i.offset,color:typeof i.color=="string"?parseInt(i.color.replace("#","0x")):i.color,alpha:i.alpha})),e.length<2&&(e=[{offset:0,color:16711680,alpha:1},{offset:1,color:255,alpha:1}]),e.sort((i,r)=>i.offset-r.offset);const t=new se({type:s.gradientType,stops:e,angle:s.angle,alpha:s.alpha,maxColors:s.maxColors||0,replace:s.replace});return t._customParams={...s},t.getColorStopsForUI=function(){return!this.stops||!Array.isArray(this.stops)?[]:this.stops.map(r=>({offset:r.offset,color:typeof r.color=="number"?"#"+r.color.toString(16).padStart(6,"0"):r.color,alpha:r.alpha}))},t.getDynamicControls=function(){const i=this.getColorStopsForUI(),r=[];return i.forEach((a,o)=>{r.push({id:`colorStop-${o}-color`,type:"color",label:`Stop ${o+1} Color`,property:`colorStops[${o}].color`,default:a.color}),r.push({id:`colorStop-${o}-offset`,type:"slider",label:`Stop ${o+1} Position`,property:`colorStops[${o}].offset`,min:0,max:1,step:.01,default:a.offset}),r.push({id:`colorStop-${o}-alpha`,type:"slider",label:`Stop ${o+1} Alpha`,property:`colorStops[${o}].alpha`,min:0,max:1,step:.01,default:a.alpha})}),r},t.handleButtonAction=function(i){(i==="addColorStop"||i==="removeColorStop")&&this.updateUIParam(i,!0)},t.updateUIParam=function(i,r){const a=this._customParams||{};switch(this._customParams=a,a[i]=r,i){case"gradientType":this.type=r;break;case"angle":case"alpha":case"maxColors":case"replace":i in this&&(this[i]=r);break;case"addColorStop":const o=[...this.stops],c={offset:1,alpha:1,color:(()=>{const h=Math.floor(Math.random()*255),p=Math.floor(Math.random()*255),m=Math.floor(Math.random()*255);return h<<16|p<<8|m})()};if(o.length>0){for(let p=0;p<o.length;p++)o[p].offset*=.8;c.offset=1}o.push(c),this.stops=o,a.colorStops=this.stops.map(h=>({offset:h.offset,color:typeof h.color=="number"?"#"+h.color.toString(16).padStart(6,"0"):h.color,alpha:h.alpha}));break;case"removeColorStop":const d=[...this.stops];d.length>2&&(d.pop(),this.stops=d,a.colorStops=this.stops.map(h=>({offset:h.offset,color:typeof h.color=="number"?"#"+h.color.toString(16).padStart(6,"0"):h.color,alpha:h.alpha})));break;case"cssGradient":if(r&&typeof r=="string"&&r.trim()!=="")try{const h=new se({css:r});this.type=h.type,this.angle=h.angle,this.stops=[...h.stops],a.colorStops=this.stops.map(p=>({offset:p.offset,color:typeof p.color=="number"?"#"+p.color.toString(16).padStart(6,"0"):p.color,alpha:p.alpha}))}catch{}break;case"colorStops":if(Array.isArray(r)){const h=r.map(p=>({offset:p.offset,color:typeof p.color=="string"?parseInt(p.color.replace("#","0x")):p.color,alpha:p.alpha}));h.sort((p,m)=>p.offset-m.offset),this.stops=h}break;default:if(/colorStops\[\d+\]\..*/.test(i)){const h=i.match(/colorStops\[(\d+)\]\.(.*)/);if(h){const[p,m,x]=h,g=parseInt(m),y=[...this.stops];if(g>=0&&g<y.length)return x==="color"&&typeof r=="string"?y[g].color=parseInt(r.replace("#","0x")):(x==="offset"||x==="alpha")&&(y[g][x]=r),this.stops=y,this.stops.sort((P,_)=>P.offset-_.offset),a.colorStops=this.getColorStopsForUI(),!0}}else i in this&&(this[i]=r);break}},t}catch{return null}},defaultParams:{gradientType:0,colorStops:[{offset:0,color:"#ff0000",alpha:1},{offset:1,color:"#0000ff",alpha:1}],addColorStop:!1,removeColorStop:!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:"",tooltip:'Enter a CSS gradient like "linear-gradient(to right, red, blue)"'}]});f({id:"color-map",name:"Color Map",category:"color",description:"Maps colors using a reference texture as a lookup table",createFilter:s=>{try{const e=b.ColorMapFilter;if(!e)return null;let t=null;s.texturePath?t=S.Texture.from(s.texturePath):t=S.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=S.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 At=b.ColorReplaceFilter;f({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 At({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 zt=b.MultiColorReplaceFilter;f({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 zt(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:Rt}=b;f({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 Rt({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:Nt}=b;f({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 Nt({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 Tt=b.AsciiFilter;f({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 Tt({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 It=b.BackdropBlurFilter;f({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 It({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:Et}=b;f({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 Et({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:Xt}=b;f({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 Xt({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),p=this._customParams||{};switch(this._customParams=p,p[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:Yt}=b;f({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 Yt({center:{x:e,y:t},radius:i,strength:r});return a._customParams={...s},a.updateUIParam=function(o,n){const l=this._customParams||{};switch(this._customParams=l,l[o]=n,o){case"centerX":this.center||(this.center={x:.5,y:.5}),this.center.x=n;break;case"centerY":this.center||(this.center={x:.5,y:.5}),this.center.y=n;break;case"radius":case"strength":this[o]=n;break;default:o in this&&(this[o]=n);break}return!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:Bt}=b,E={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]};f({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=E[i]||E.normal}const t=new Bt(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;E[o]&&(this.matrix=E[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=E[o]||E.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:Ot}=b;f({id:"cross-hatch",name:"Cross Hatch",category:"stylize",description:"Creates a crosshatching effect like in a pencil drawing",createFilter:s=>{try{const e=new Ot;return e.updateUIParam=function(t,i){return!0},e}catch{return null}},defaultParams:{},controls:[]});f({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 b.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 Lt=S.DisplacementFilter,Dt=S.Sprite,$=S.Texture;f({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=$.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=$.from(o)}const i=new Dt(t),r=new Lt(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=$.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}]});f({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 b.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:Ut}=b;f({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 Ut(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:Vt}=b,R={TRANSPARENT:0,ORIGINAL:1,LOOP:2,CLAMP:3,MIRROR:4};f({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 Vt({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 p=this.blue;n==="blueX"?p.x=l:p.y=l,this.blue=p;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:R.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:R.TRANSPARENT,label:"Transparent"},{value:R.ORIGINAL,label:"Original"},{value:R.LOOP,label:"Loop"},{value:R.CLAMP,label:"Clamp"},{value:R.MIRROR,label:"Mirror"}],default:R.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:jt}=b;f({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 jt({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:qt}=b;f({id:"godray",name:"Godray",category:"light",description:"Creates volumetric light-ray effects (crepuscular rays)",createFilter:s=>{try{const e=new qt({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 Ht=b.SimpleLightmapFilter,ae=S.Texture;f({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=ae.from(r);let n;try{typeof t=="string"&&t.startsWith("#")?n=parseInt(t.replace("#","0x"),16):n=0}catch{n=0}const l=new Ht(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 p=document.createElement("canvas");p.width=256,p.height=256;const m=p.getContext("2d");if(m){if(d==="spotlight"){m.fillStyle="black",m.fillRect(0,0,256,256);const g=m.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)"),m.fillStyle=g,m.beginPath(),m.arc(128,128,100,0,Math.PI*2),m.fill()}else if(d==="softlight"){const g=m.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)"),m.fillStyle=g,m.fillRect(0,0,256,256)}else{const g=m.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"),m.fillStyle=g,m.fillRect(0,0,256,256)}const x=ae.from(p);if(this.lightMap=x,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:$t}=S;f({id:"noise",name:"Noise",category:"effects",description:"Add random noise to the image",createFilter:s=>{try{const e=new $t({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:Wt}=b;f({id:"old-film",name:"Old Film",category:"effects",description:"Apply a vintage film effect with scratches and grain",createFilter:s=>{try{const e=new Wt({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:Zt}=b;f({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 Zt({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:Gt}=b;f({id:"pixelate",name:"Pixelate",category:"effects",description:"Create a pixelated or mosaic effect",createFilter:s=>{try{const e=new Gt(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:Kt}=b;f({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 Kt(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:Qt}=b;f({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 Qt({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,p){const m=this._customParams||{};switch(this._customParams=m,m[h]=p,h){case"centerX":this.center||(this.center={x:.5,y:.5}),this.center.x=p;break;case"centerY":this.center||(this.center={x:.5,y:.5}),this.center.y=p;break;case"amplitude":case"wavelength":case"speed":case"brightness":case"radius":case"time":this[h]=p;break;case"animating":this.animating=p;break;default:h in this&&(this[h]=p);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:Jt}=b;f({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 Jt({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"}]});class ei extends S.Filter{constructor(e){const t=oe.GlProgram.from({vertex:`
|
|
2
|
+
attribute vec2 aPosition;
|
|
3
|
+
varying vec2 vTextureCoord;
|
|
4
|
+
uniform mat3 projectionMatrix;
|
|
5
|
+
|
|
6
|
+
void main() {
|
|
7
|
+
vTextureCoord = aPosition;
|
|
8
|
+
gl_Position = vec4((projectionMatrix * vec3(aPosition, 1.0)).xy, 0.0, 1.0);
|
|
9
|
+
}
|
|
10
|
+
`,fragment:`
|
|
11
|
+
precision mediump float;
|
|
12
|
+
|
|
13
|
+
varying vec2 vTextureCoord;
|
|
14
|
+
uniform sampler2D uSampler;
|
|
15
|
+
|
|
16
|
+
uniform vec2 uCenter;
|
|
17
|
+
uniform float uRadius;
|
|
18
|
+
uniform float uAngle;
|
|
19
|
+
|
|
20
|
+
void main() {
|
|
21
|
+
vec2 coord = vTextureCoord;
|
|
22
|
+
vec2 dir = coord - uCenter;
|
|
23
|
+
float dist = length(dir);
|
|
24
|
+
|
|
25
|
+
if (dist < uRadius) {
|
|
26
|
+
float percent = (uRadius - dist) / uRadius;
|
|
27
|
+
float theta = percent * percent * uAngle;
|
|
28
|
+
float s = sin(theta);
|
|
29
|
+
float c = cos(theta);
|
|
30
|
+
|
|
31
|
+
dir = vec2(
|
|
32
|
+
dir.x * c - dir.y * s,
|
|
33
|
+
dir.x * s + dir.y * c
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
coord = dir + uCenter;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
gl_FragColor = texture2D(uSampler, coord);
|
|
40
|
+
}
|
|
41
|
+
`});super({glProgram:t,resources:{twistUniforms:{uCenter:{type:"vec2<f32>",value:[.5,.5]},uRadius:{type:"f32",value:.25},uAngle:{type:"f32",value:4}}}}),this._centerX=.5,this._centerY=.5,this._radius=.25,this._angle=4,e&&(e.centerX!==void 0&&(this._centerX=e.centerX),e.centerY!==void 0&&(this._centerY=e.centerY),e.radius!==void 0&&(this._radius=e.radius),e.angle!==void 0&&(this._angle=e.angle)),this._updateUniforms()}_updateUniforms(){this.uniforms&&(this.uniforms.uCenter=[this._centerX,this._centerY],this.uniforms.uRadius=this._radius,this.uniforms.uAngle=this._angle)}get centerX(){return this._centerX}set centerX(e){this._centerX=e,this._updateUniforms()}get centerY(){return this._centerY}set centerY(e){this._centerY=e,this._updateUniforms()}get radius(){return this._radius}set radius(e){this._radius=e,this._updateUniforms()}get angle(){return this._angle}set angle(e){this._angle=e,this._updateUniforms()}updateUIParam(e,t){switch(e){case"centerX":this.centerX=t;break;case"centerY":this.centerY=t;break;case"radius":this.radius=t;break;case"angle":this.angle=t;break}}}f({id:"twist",name:"Twist",category:"distortion",description:"Creates a twisting distortion effect around a central point",createFilter:s=>{try{const e=new ei({centerX:s.centerX??.5,centerY:s.centerY??.5,radius:s.radius??.25,angle:s.angle??4});return e._customParams={...s},e}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 (0-1, 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:ti}=b;function U(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 ii extends ti{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=U(e.color)):(this._colorValue="#"+e.color.toString(16).padStart(6,"0"),this._colorRgb=U(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=U(e)):(this._colorValue="#"+e.toString(16).padStart(6,"0"),this._colorRgb=U(e)),this.updateVignette()}}f({id:"vignette",name:"Vignette",category:"effects",description:"Add a classic darkened border effect to the image",createFilter:s=>{try{const e=new ii({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 ri(s){try{let e=[],t=[];try{e=B(),e.length===0&&be()}catch{}const i=s==null?void 0:s.disabled;if(Array.isArray(i)&&i.length>0){let r=0;for(const a of i)dt(a)&&r++;r>0}try{e=B(),t=_e()}catch{e||(e=[]),t||(t=[])}return e.length,e}catch{return[]}}exports.VanillaImageEditor=lt;exports.getAllCategories=_e;exports.getAllFilters=B;exports.getFilter=ge;exports.getFiltersByCategory=ye;exports.getRegisteredFilters=xe;exports.hasFilter=ht;exports.initializeFilterRegistry=ri;exports.isFilterCompatibleWithMedia=ut;exports.registerCorePixiFilters=be;exports.registerFilter=f;
|
|
42
|
+
//# sourceMappingURL=editor-BUpGsg4D.cjs.map
|