@codingfactory/mediables-vue 2.0.5 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/PixiFrameExporter-CaDjKfAG.cjs +2 -0
  2. package/dist/{PixiFrameExporter-BTXhmL54.cjs.map → PixiFrameExporter-CaDjKfAG.cjs.map} +1 -1
  3. package/dist/{PixiFrameExporter-B5tJ62bD.js → PixiFrameExporter-CvKLKOXx.js} +60 -60
  4. package/dist/{PixiFrameExporter-B5tJ62bD.js.map → PixiFrameExporter-CvKLKOXx.js.map} +1 -1
  5. package/dist/composables/useFloatingPills.d.ts +2 -0
  6. package/dist/composables/useVideoEditor.d.ts +3 -2
  7. package/dist/filters/index.d.ts +3 -3
  8. package/dist/filters/registry.d.ts +15 -0
  9. package/dist/index-CXQ4ykVw.cjs +39 -0
  10. package/dist/index-CXQ4ykVw.cjs.map +1 -0
  11. package/dist/{index-BsOWbGbb.js → index-DBM_ViWA.js} +1629 -1562
  12. package/dist/index-DBM_ViWA.js.map +1 -0
  13. package/dist/{index-CWcyKIOz.js → index-DRQBqLZX.js} +8593 -8668
  14. package/dist/index-DRQBqLZX.js.map +1 -0
  15. package/dist/index-HREFg1jF.cjs +42 -0
  16. package/dist/index-HREFg1jF.cjs.map +1 -0
  17. package/dist/mediables-vanilla.cjs +1 -1
  18. package/dist/mediables-vanilla.mjs +1 -1
  19. package/dist/mediables-vue.cjs +1 -1
  20. package/dist/mediables-vue.mjs +2 -2
  21. package/dist/render-page/assets/{index-hBfvGPpt.js → index-SU1f_egA.js} +45095 -22643
  22. package/dist/render-page/index.html +1 -1
  23. package/dist/style.css +1 -1
  24. package/dist/types/video.d.ts +1 -0
  25. package/dist/video-engine/adapters/MediablesCompositionAdapter.d.ts +2 -1
  26. package/dist/video-engine/index.d.ts +0 -2
  27. package/package.json +17 -18
  28. package/dist/PixiFrameExporter-BTXhmL54.cjs +0 -2
  29. package/dist/index-BsOWbGbb.js.map +0 -1
  30. package/dist/index-CWcyKIOz.js.map +0 -1
  31. package/dist/index-C_X9_ptj.cjs +0 -42
  32. package/dist/index-C_X9_ptj.cjs.map +0 -1
  33. package/dist/index-DVJg3EKN.cjs +0 -76
  34. package/dist/index-DVJg3EKN.cjs.map +0 -1
  35. package/dist/video-engine/adapters/CSSFilterAdapter.d.ts +0 -106
@@ -1,42 +0,0 @@
1
- "use strict";var ne=Object.defineProperty;var ce=(s,e,i)=>e in s?ne(s,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):s[e]=i;var B=(s,e,i)=>ce(s,typeof e!="symbol"?e+"":e,i);const he=require("pixi-filters"),G=require("pixi.js");function K(s){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const i in s)if(i!=="default"){const t=Object.getOwnPropertyDescriptor(s,i);Object.defineProperty(e,i,t.get?t:{enumerable:!0,get:()=>s[i]})}}return e.default=s,Object.freeze(e)}const g=K(he),C=K(G);class X{constructor(){this._events=new Map}on(e,i){return this._events.has(e)||this._events.set(e,new Set),this._events.get(e).add(i),()=>this.off(e,i)}off(e,i){const t=this._events.get(e);t&&t.delete(i)}emit(e,...i){const t=this._events.get(e);t&&t.forEach(r=>{try{r(...i)}catch{}})}once(e,i){const t=(...r)=>{this.off(e,t),i(...r)};return this.on(e,t)}removeAllListeners(e){e?this._events.delete(e):this._events.clear()}}class de extends X{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 i=e.split(".");let t=this._state;for(const r of i){if(t==null)return;t=t[r]}return t}return this._state[e]}set(e,i){const t=this.get(e);if(e.includes(".")){const r=e.split("."),a=r.pop();let o=this._state;for(const l of r)o[l]===void 0&&(o[l]={}),o=o[l];o[a]=i}else this._state[e]=i;this.emit(`change:${e}`,{value:i,old:t}),this.emit("change",{key:e,value:i,old:t})}getAll(){return{...this._state}}toggleFilter(e,i){const t=new Set(this._state.activeFilters);i?t.add(e):(t.delete(e),delete this._state.filterValues[e]),this.set("activeFilters",t)}setFilterValue(e,i,t){this._state.filterValues[e]||(this._state.filterValues[e]={}),this._state.filterValues[e][i]=t,this.emit("change:filterValue",{filterId:e,controlId:i,value:t}),this.emit("change:filterValues",this._state.filterValues)}getFilterValues(e){return this._state.filterValues[e]||{}}initFilterValues(e,i){this._state.filterValues[e]||(this._state.filterValues[e]={}),i.forEach(t=>{t.id in this._state.filterValues[e]||(this._state.filterValues[e][t.id]=t.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 ue(){return new de}class pe extends X{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,l,n,c;const e=(a=(r=this.app)==null?void 0:r.renderer)==null?void 0:a.canvas,i=(e==null?void 0:e.clientWidth)??((l=(o=this.app)==null?void 0:o.screen)==null?void 0:l.width)??0,t=(e==null?void 0:e.clientHeight)??((c=(n=this.app)==null?void 0:n.screen)==null?void 0:c.height)??0;return{w:i,h:t}}render(){var e,i;try{(e=this.app)!=null&&e.renderer&&((i=this.app)!=null&&i.stage)&&this.app.renderer.render(this.app.stage)}catch{}}getFitScaleFor(e){if(!this.app||!e)return 1;const{w:i,h:t}=this._getCssSize();if(i<=1||t<=1)return 1;let r=Math.min(i/e.width,t/e.height)*.9;return(!Number.isFinite(r)||r<=0)&&(r=1),r}applyViewTransform(e={}){if(!this.app||!this.sprite||!this.originalTexture)return;const i=this.fitScale*this.zoom,{w:t,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:t/2,y:r/2};this.sprite.width=this.originalTexture.width*i,this.sprite.height=this.originalTexture.height*i,this.sprite.x=a.x-this.sprite.width/2,this.sprite.y=a.y-this.sprite.height/2,this.render()}setZoom(e,i={}){this.zoom=Math.max(.1,Math.min(8,e)),this.applyViewTransform({keepCenter:i.keepCenter??!0}),this.emit("zoomChange",this.zoom)}fitToScreen(){this.originalTexture&&(this.fitScale=this.getFitScaleFor(this.originalTexture),this.setZoom(1,{keepCenter:!1}))}async mount(e,i=16777215){if(!e)return;this._container=e;const t=async()=>{var n;const r=window.PIXI;if(!r)throw new Error("PIXI.js not found. Please ensure PIXI is loaded globally.");(n=r.Assets)!=null&&n.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:i,antialias:!0,autoDensity:!0,resolution:window.devicePixelRatio||1}),e.appendChild(this.app.canvas);const l=this.app.canvas;l.classList.add("pixi-canvas"),l.style.width="100%",l.style.height="100%",l.style.transform="translateZ(0)",l.style.willChange="transform",l.setAttribute("role","img"),l.setAttribute("aria-label","Image editor canvas — use toolbar controls to edit the image"),this.emit("mounted",{width:a,height:o})};this._mountPromise=t(),await this._mountPromise}async loadTexture(e){var n,c,d;if(this._mountPromise&&await this._mountPromise,!((n=this.app)!=null&&n.renderer))return;const i=window.PIXI,t=await this._loadImageElement(e);if(!t||!((c=this.app)!=null&&c.renderer))return;const r=i.Texture.from(t);if(!r)return;this.originalTexture=r,this.baseTexture=r,this.sprite&&(this.app.stage.removeChild(this.sprite),this.sprite.destroy()),this.sprite=new i.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;const l=this.getFitScaleFor(r);Math.abs(l-this.fitScale)/Math.max(1e-6,l)>.02&&(this.fitScale=l,this.applyViewTransform({center:{x:a/2,y:o/2}})),this.render(),this.emit("textureLoaded",{width:r.width,height:r.height})}exportImage(e="png",i=.92,t=0,r=!0){var m,b,_;if(!((m=this.app)!=null&&m.renderer)||!this.originalTexture)return null;const a=window.PIXI,o=Math.round(this.originalTexture.width),l=Math.round(this.originalTexture.height);if(o<=0||l<=0)return null;let n=o,c=l;if(t>0){const x=Math.max(o,l);let y=t/x;r&&(y=Math.min(1,y)),n=Math.round(o*y),c=Math.round(l*y)}const d=new a.Container,h=new a.Sprite(this.originalTexture);if(h.scale.set(n/o,c/l),(_=(b=this.sprite)==null?void 0:b.filters)!=null&&_.length){const x=this.sprite.filters.map(y=>typeof(y==null?void 0:y.clone)=="function"?y.clone():y);h.filters=x}d.addChild(h);let p=null;try{if(p=a.RenderTexture.create({width:n,height:c}),this.app.renderer.render({container:d,target:p}),!this.app.renderer.extract)return null;const x=this.app.renderer.extract.canvas(p);if(!x)return null;let y=null;if(typeof x.toDataURL=="function")y=x.toDataURL(`image/${e}`,i);else if(typeof x.getContext=="function"){const P=document.createElement("canvas");P.width=x.width,P.height=x.height;const z=P.getContext("2d");z&&(z.drawImage(x,0,0),y=P.toDataURL(`image/${e}`,i))}return y||null}catch{return null}finally{p&&p.destroy(!0),d.destroy({children:!0})}}resizeTo(e){var r;if(!((r=this.app)!=null&&r.renderer)||!e)return;const i=e.clientWidth,t=e.clientHeight;if(!(i===Math.round(this.app.screen.width)&&t===Math.round(this.app.screen.height))&&!(i<=0||t<=0)&&(this.app.renderer.resize(i,t),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 i,t;(t=(i=this.app)==null?void 0:i.renderer)!=null&&t.background&&(this.app.renderer.background.color=e)}_loadImageElement(e){return new Promise(i=>{const t=new Image;typeof e=="string"&&/^https?:\/\//.test(e)&&(t.crossOrigin="anonymous"),t.onload=()=>i(t),t.onerror=()=>{i(null)},t.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 fe={adjust:["adjust","advanced"],blur:["blur"],color:["color"],effects:["effects"],distortion:["distortion"],light:["light"],stylize:["stylize"]};class me extends X{constructor(e,i){super(),this.state=e,this.renderer=i,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 i=fe[e]||[e],t=[],r=new Set;for(const a of i){const o=this._filterRegistry.getFiltersByCategory(a)||[];for(const l of o)r.has(l.id)||(r.add(l.id),t.push(l))}return t}_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,i,t){if(!e||!i)return;if(!i.includes(".")&&!i.includes("[")){e[i]=t;return}const r=i.replace(/\[(\d+)\]/g,".$1").split(".").filter(Boolean);let a=e;for(let l=0;l<r.length-1;l++){const n=r[l];if(!(n in a)||(a=a[n],a==null))return}const o=r[r.length-1];a[o]=t}initializeValues(e){const i=this.getFilterDef(e);i&&i.controls.forEach(t=>{const r=this.state.getFilterValues(e);t.id in r||this.state.setFilterValue(e,t.id,t.default)})}resetValues(e){const i=this.getFilterDef(e);i&&i.controls.forEach(t=>{this.state.setFilterValue(e,t.id,t.default)})}toggle(e,i){this.state.toggleFilter(e,i),i?this.initializeValues(e):delete this.instances[e],this.applyFilters(),this.emit("filterToggled",{filterId:e,enabled:i})}updateValue(e,i,t){const r=this._normalizeValue(t);this.state.setFilterValue(e,i,r);const a=this.instances[e];if(a){const o=this.getFilterDef(e),l=o==null?void 0:o.controls.find(c=>c.id===i),n=(l==null?void 0:l.property)||i;return typeof a.updateUIParam=="function"?(a.updateUIParam(n,r),!0):(this._setDeepProp(a,n,r),a.uniforms&&n in a.uniforms&&(a.uniforms[n]=r),!0)}return!1}applyFilters(){const e=this.renderer.sprite;if(!e)return;for(const a in this.instances)delete this.instances[a];const i=[],t=[];this.state.get("activeFilters").forEach(a=>{try{const o=this.getFilterDef(a);if(!o||!o.createFilter||typeof o.createFilter!="function")return;const l=this.state.getFilterValues(a),n=o.defaultParams?{...o.defaultParams}:{};o.controls&&Array.isArray(o.controls)&&o.controls.forEach(d=>{const h=d.property||d.id;n[h]=l[d.id]??d.default});const c=o.createFilter(n);c&&(i.push(c),this.instances[a]=c)}catch{t.push(a)}});try{e.filters=null,e.filters=i.length?i:null,this.renderer.render(),this.emit("filtersApplied",{count:i.length,failed:t})}catch(a){try{e.filters=null,this.renderer.render()}catch{}this.emit("filtersError",{error:a,failedFilters:t})}t.length>0}resetAll(){for(const e in this.instances)delete this.instances[e];if(this.state.resetFilters(),this.renderer.sprite&&(this.renderer.sprite.filters=null),this.renderer.baseTexture&&this.renderer.originalTexture!==this.renderer.baseTexture&&this.renderer.sprite&&this.renderer.app){const e=window.PIXI;this.renderer.originalTexture=this.renderer.baseTexture,this.renderer.app.stage.removeChild(this.renderer.sprite),this.renderer.sprite.destroy();const i=new e.Sprite(this.renderer.originalTexture);this.renderer.app.stage.addChild(i),this.renderer.sprite=i,this.renderer.fitScale=this.renderer.getFitScaleFor(this.renderer.originalTexture),this.renderer.setZoom(1,{keepCenter:!1}),this.renderer.applyViewTransform()}this.renderer.render(),this.emit("filtersReset")}getInstance(e){return this.instances[e]||null}}const F=class F extends X{constructor(e,i){super(),this.state=e,this.renderer=i,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 i={"1:1":1,"4:3":4/3,"16:9":16/9,"3:2":3/2,"2:3":2/3};if(i[e]!==void 0)return i[e];const t=e.split(":");if(t.length===2){const r=parseFloat(t[0]),a=parseFloat(t[1]);if(Number.isFinite(r)&&Number.isFinite(a)&&a>0)return r/a}return null}applyAspectRatio(){const e=this.state.get("crop.rect"),i=this.state.get("crop.aspect");if(!e||i==="free")return;const t=this._getAspectRatio(i);if(!t)return;const r=e.width/e.height;Math.abs(r-t)<.01||(r>t?e.width=e.height*t:e.height=e.width/t,this.state.set("crop.rect",e))}constrainCropRect(){const e=this.state.get("crop.rect");if(!e)return;const i=this.renderer.sprite,t=this.renderer.app;if(!i||!t)return;const r=this.state.get("crop.shape"),o=r==="circle"||!!this.state.get("autoZoomOnCropOverflow")?{x:0,y:0,w:t.screen.width,h:t.screen.height}:{x:i.x,y:i.y,w:i.width,h:i.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 l=Math.min(e.width,e.height);e.width=l,e.height=l}this.state.set("crop.rect",e)}static calcAutoZoom(e,i,t,r,a,o,l){if(!e||!r||!a||!o)return null;const n=e.width>i,c=e.height>t;if(!n&&!c)return null;const d=F.AUTO_ZOOM_PADDING;let h=l;if(n){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>=l-.01?null:h}_checkAutoZoom(){if(!this.state.get("autoZoomOnCropOverflow"))return;const e=Date.now();if(e-this._lastAutoZoomCheck<F.AUTO_ZOOM_THROTTLE_MS)return;this._lastAutoZoomCheck=e;const i=this.state.get("crop.rect"),t=this.renderer.sprite,r=this.renderer.originalTexture;if(!i||!t||!r)return;const a=F.calcAutoZoom(i,t.width,t.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 i=this.renderer.app;if(!i)return;const t=i.canvas,r=t.clientWidth,a=t.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 l=e.getContext("2d");if(!l)return;l.setTransform(o,0,0,o,0,0),l.clearRect(0,0,r,a),l.fillStyle="rgba(0, 0, 0, 0.5)",l.fillRect(0,0,r,a);const n=this.state.get("crop.rect");if(!n)return;const c=this.state.get("crop.shape");if(l.save(),c==="circle"){const _=n.x+n.width/2,x=n.y+n.height/2,y=Math.min(n.width,n.height)/2;l.beginPath(),l.arc(_,x,y,0,Math.PI*2),l.clip()}else l.beginPath(),l.rect(n.x,n.y,n.width,n.height),l.clip();l.clearRect(n.x,n.y,n.width,n.height),l.restore(),l.strokeStyle="#ffffff",l.lineWidth=2,l.setLineDash([5,5]),c==="circle"?(l.beginPath(),l.arc(n.x+n.width/2,n.y+n.height/2,Math.min(n.width,n.height)/2,0,Math.PI*2),l.stroke()):l.strokeRect(n.x,n.y,n.width,n.height),l.setLineDash([]),l.strokeStyle="rgba(255,255,255,0.3)",l.lineWidth=1;const d=n.width/3,h=n.height/3;for(let _=1;_<=2;_++)l.beginPath(),l.moveTo(n.x+d*_,n.y),l.lineTo(n.x+d*_,n.y+n.height),l.stroke(),l.beginPath(),l.moveTo(n.x,n.y+h*_),l.lineTo(n.x+n.width,n.y+h*_),l.stroke();const p=this.HANDLE_SIZE,m=[{x:n.x,y:n.y,m:"resize-nw"},{x:n.x+n.width,y:n.y,m:"resize-ne"},{x:n.x,y:n.y+n.height,m:"resize-sw"},{x:n.x+n.width,y:n.y+n.height,m:"resize-se"}],S=[{x:n.x+n.width/2,y:n.y,m:"n"},{x:n.x+n.width/2,y:n.y+n.height,m:"s"},{x:n.x,y:n.y+n.height/2,m:"w"},{x:n.x+n.width,y:n.y+n.height/2,m:"e"}],b=[...m,...S];for(const _ of b){const x=this._hoverMode===_.m,y=x?p+4:p;l.beginPath(),l.rect(_.x-y/2,_.y-y/2,y,y),l.fillStyle=x?"#4da3ff":"#ffffff",l.strokeStyle="rgba(0,0,0,0.6)",l.lineWidth=1,l.fill(),l.stroke()}}_hitHandle(e,i){const t=this.state.get("crop.rect");if(!t)return null;const r=(a,o,l,n,c)=>Math.abs(a-l)<=c&&Math.abs(o-n)<=c;return r(e,i,t.x,t.y,this.HANDLE_SIZE)?"resize-nw":r(e,i,t.x+t.width,t.y,this.HANDLE_SIZE)?"resize-ne":r(e,i,t.x,t.y+t.height,this.HANDLE_SIZE)?"resize-sw":r(e,i,t.x+t.width,t.y+t.height,this.HANDLE_SIZE)?"resize-se":Math.abs(i-t.y)<=this.EDGE_HIT_PAD&&e>=t.x&&e<=t.x+t.width?"n":Math.abs(i-(t.y+t.height))<=this.EDGE_HIT_PAD&&e>=t.x&&e<=t.x+t.width?"s":Math.abs(e-t.x)<=this.EDGE_HIT_PAD&&i>=t.y&&i<=t.y+t.height?"w":Math.abs(e-(t.x+t.width))<=this.EDGE_HIT_PAD&&i>=t.y&&i<=t.y+t.height?"e":e>=t.x&&e<=t.x+t.width&&i>=t.y&&i<=t.y+t.height?"move":null}_handlePointerDown(e){const i=this.state.get("crop.rect");if(!i)return;const t=e.global;this._dragMode=this._hitHandle(t.x,t.y),this._dragMode&&(this._isDragging=!0,this._dragStart={x:t.x,y:t.y},this._startRect={...i},this._lastAutoZoomCheck=0)}_handlePointerMove(e){var n,c,d,h;const i=this.renderer.app;if(!i)return;const t=e.global;if(!this._isDragging||!this._dragStart||!this._startRect){this._hoverMode=this._hitHandle(t.x,t.y),i.stage.cursor=this._hoverMode==="move"?"move":this._hoverMode==="n"||this._hoverMode==="s"?"ns-resize":this._hoverMode==="e"||this._hoverMode==="w"?"ew-resize":(n=this._hoverMode)!=null&&n.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=t.x-this._dragStart.x,o=t.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,i=this.renderer.sprite;if(!e||!i)return;let t=this.state.get("crop.rect");if(!t){const a=Math.min(e.screen.width,e.screen.height)*.7,o=i.x+(i.width-a)/2,l=i.y+(i.height-a)/2;t={x:o,y:l,width:a,height:a},this.state.set("crop.rect",t),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 i=e.stage;if(i.off("pointerdown",this._onPointerDown),i.off("pointermove",this._onPointerMove),i.off("pointerup",this._onPointerUp),i.off("pointerupoutside",this._onPointerUp),i.eventMode="auto",i.cursor="default",this.state.set("crop.rect",null),this._overlayCanvas){const t=this._overlayCanvas.getContext("2d");t==null||t.clearRect(0,0,this._overlayCanvas.width,this._overlayCanvas.height)}this.state.set("mode","filters"),this.emit("disabled")}apply(){const e=this.renderer.app,i=this.renderer.sprite,t=this.renderer.originalTexture,r=this.state.get("crop.rect");if(!r||!i||!e||!t)return null;const a=window.PIXI,o=this.renderer.zoom,l=t.width/i.width,n=t.height/i.height,c=(r.x-i.x)*l,d=(r.y-i.y)*n;let h=Math.round(Math.max(1,r.width*l)),p=Math.round(Math.max(1,r.height*n)),m=Math.round(c),S=Math.round(d);if(h<=0||p<=0)return null;const b=new a.Container,_=new a.Sprite(t);if(this.state.get("crop.shape")==="circle"){const z=Math.round(Math.max(h,p)),oe=m+h/2,le=S+p/2;m=Math.round(oe-z/2),S=Math.round(le-z/2),h=p=z;const v=new a.Graphics;typeof v.circle=="function"&&typeof v.fill=="function"?v.circle(h/2,p/2,h/2).fill(16777215):(v.beginFill(16777215,1),v.drawCircle(h/2,p/2,h/2),v.endFill()),_.mask=v,b.addChild(v)}_.x=-m,_.y=-S,b.addChild(_);const y=a.RenderTexture.create({width:h,height:p});e.renderer.render({container:b,target:y,clear:!0}),b.destroy({children:!0}),this.renderer.originalTexture=y,e.stage.removeChild(i),i.destroy();const P=new a.Sprite(y);return e.stage.addChild(P),this.renderer.sprite=P,this.renderer.fitScale=this.renderer.getFitScaleFor(y),this.renderer.setZoom(o,{keepCenter:!1}),this.renderer.applyViewTransform(),this.renderer.render(),this.disable(),this.emit("applied",{width:h,height:p}),{texture:y,preservedZoom:o}}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())}};B(F,"AUTO_ZOOM_PADDING",1.1),B(F,"AUTO_ZOOM_THROTTLE_MS",100);let D=F;class ge{constructor(e={}){this._endpoint=e.endpoint||"/api/v1/media/remove-bg",this._fallbackEndpoint=e.fallbackEndpoint||null}async removeBackground(e,i={}){const t=typeof e=="string"?await this._dataUrlToBlob(e):e,r=new FormData;r.append("file",t,"image.png"),r.append("tier",i.tier||"balanced"),i.model&&r.append("model",i.model),i.alpha_matting&&(r.append("alpha_matting","true"),r.append("alpha_f",String(i.alpha_f??10)),r.append("alpha_fr",String(i.alpha_fr??15)),r.append("alpha_erode_size",String(i.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 l=await a.blob();return{dataUrl:await this._blobToDataUrl(l),model:a.headers.get("X-Model-Used")||"unknown",processMs:a.headers.get("X-Process-Ms")||"0"}}async _dataUrlToBlob(e){if(e.startsWith("data:")){const[t,r]=e.split(","),a=t.match(/:(.*?);/),o=a?a[1]:"image/png",l=atob(r),n=new Uint8Array(l.length);for(let c=0;c<l.length;c++)n[c]=l.charCodeAt(c);return new Blob([n],{type:o})}return(await fetch(e)).blob()}_blobToDataUrl(e){return new Promise((i,t)=>{const r=new FileReader;r.onload=()=>i(r.result),r.onerror=()=>t(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={},...i){const t=document.createElement(s);for(const[r,a]of Object.entries(e))if(a!=null)if(r==="className")t.className=a;else if(r==="style"&&typeof a=="object")Object.assign(t.style,a);else if(r.startsWith("on")&&typeof a=="function"){const o=r.slice(2).toLowerCase();t.addEventListener(o,a)}else r==="dataset"&&typeof a=="object"?Object.assign(t.dataset,a):t.setAttribute(r,a);for(const r of i)typeof r=="string"?t.appendChild(document.createTextNode(r)):r instanceof HTMLElement&&t.appendChild(r);return t}function be({id:s,label:e,min:i=0,max:t=1,step:r=.01,value:a=.5,onChange:o}){const l=s.includes("-")?s.split("-").slice(1).join("-"):s,n=u("div",{className:"slider-control slider-wrapper","data-control":l,"data-testid":`slider-${l}`}),c=u("div",{className:"slider-header"},u("label",{for:s,className:"slider-label"},e),u("span",{className:"slider-value",id:`${s}-value`},O(a))),d=u("input",{type:"range",id:s,className:"slider-input",min:String(i),max:String(t),step:String(r),value:String(a),onInput:h=>{const p=parseFloat(h.target.value),m=n.querySelector(".slider-value");m&&(m.textContent=O(p)),o==null||o(p)}});return n.appendChild(c),n.appendChild(d),n.setValue=h=>{d.value=String(h);const p=n.querySelector(".slider-value");p&&(p.textContent=O(h))},n}function O(s){return Number.isInteger(s)?String(s):s.toFixed(2)}function ye({id:s,label:e,checked:i=!1,onChange:t}){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:i?"checked":void 0,onChange:c=>t==null?void 0:t(c.target.checked)}),l=u("div",{className:"toggle-switch",onClick:c=>{c.target!==o&&(o.checked=!o.checked,t==null||t(o.checked))}}),n=u("span",{className:"toggle-slider"});return l.appendChild(o),l.appendChild(n),r.appendChild(a),r.appendChild(l),r.setChecked=c=>{o.checked=c},r}function _e({id:s,label:e,value:i="#000000",onChange:t}){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:i,onInput:l=>t==null?void 0:t(l.target.value)});return r.appendChild(a),r.appendChild(o),r.setValue=l=>{o.value=l},r}function xe({id:s,label:e,options:i=[],value:t,onChange:r}){const a=u("div",{className:"select-control"}),o=u("label",{className:"select-label",for:s},e),l=u("select",{id:s,className:"select-input",onChange:n=>r==null?void 0:r(n.target.value)});for(const n of i){const c=u("option",{value:n.value},n.label);n.value===t&&(c.selected=!0),l.appendChild(c)}return a.appendChild(o),a.appendChild(l),a.setValue=n=>{l.value=n},a}function T({label:s,className:e="",onClick:i,icon:t=null,disabled:r=!1}){const a=u("button",{type:"button",className:`btn ${e}`.trim(),onClick:i,disabled:r?"disabled":void 0});if(t){const o=u("span",{className:"btn-icon"});o.innerHTML=t;const l=o.querySelector("svg");l&&l.setAttribute("aria-hidden","true"),a.appendChild(o)}return s&&a.appendChild(document.createTextNode(s)),a}function w({icon:s,title:e,className:i="",onClick:t,disabled:r=!1,testId:a=null,ariaLabel:o=null}){const l={type:"button",className:`icon-btn ${i}`.trim(),title:e,"aria-label":o||e,onClick:t,disabled:r?"disabled":void 0};a&&(l.dataset={testid:a});const n=u("button",l);n.innerHTML=s;const c=n.querySelector("svg");return c&&c.setAttribute("aria-hidden","true"),n}function U({label:s,icon:e,active:i=!1,onClick:t}){const r=u("button",{type:"button",className:`chip ${i?"active":""}`.trim(),onClick:t});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 Q='<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>',J='<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>',Ce='<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>',we='<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>',Se='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M432 320v112H320M80 192V80h112M320 80h112v112M192 432H80V320"/></svg>',ke='<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>',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="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>',Pe='<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>',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="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>',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="M176 112l80-80 80 80M255.98 32l.02 448M176 400l80 80 80-80M400 176l80 80-80 80M112 176l-80 80 80 80M32 256h448"/></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="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>',Ae='<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>',Ne='<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>',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="M368 368L144 144M368 144L144 368"/></svg>',te='<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>',Re='<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>',Te='<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>',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="M416 128L192 384l-96-96"/></svg>',Ie='<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>',Xe='<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>',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="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>',H='<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>',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="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 Be{constructor(e,i){this.state=e,this.editor=i,this.element=null,this._unsubscribers=[]}render(){this.element=u("div",{className:"editor-toolbar"});const e=u("div",{className:"toolbar-section toolbar-left"}),i=w({icon:Te,title:"Open Image",className:"toolbar-btn",testId:"btn-open-image",ariaLabel:"Open image file",onClick:()=>this.editor.openFilePicker()});e.appendChild(i);const t=u("div",{className:"toolbar-section toolbar-center"}),r=w({icon:we,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:Ce,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:Se,title:"Fit to Screen",className:"toolbar-btn",testId:"btn-fit-screen",ariaLabel:"Fit to screen",onClick:()=>this.editor.fitToScreen()});t.appendChild(r),t.appendChild(this._zoomLabel),t.appendChild(a),t.appendChild(o);const l=u("div",{className:"toolbar-section toolbar-right"});this._themeBtn=w({icon:this.state.get("isDarkMode")?q:H,title:"Toggle Theme",className:"toolbar-btn",testId:"btn-toggle-theme",ariaLabel:"Toggle theme",onClick:()=>this.editor.toggleTheme()});const n=w({icon:te,title:"Reset All",className:"toolbar-btn",testId:"btn-reset-all",ariaLabel:"Reset all changes",onClick:()=>this.editor.resetAll()}),c=w({icon:Ne,title:"Save Image",className:"toolbar-btn toolbar-btn-primary",testId:"btn-save-edit",ariaLabel:"Save image",onClick:()=>this.editor.save()}),d=w({icon:ee,title:"Close",className:"toolbar-btn",testId:"btn-cancel-edit",ariaLabel:"Close editor",onClick:()=>this.editor.close()});return l.appendChild(this._themeBtn),l.appendChild(n),l.appendChild(c),l.appendChild(d),this.element.appendChild(e),this.element.appendChild(t),this.element.appendChild(l),this._subscribeToState(),this.element}_subscribeToState(){const e=this.state.on("change:zoom",({value:t})=>{this._zoomLabel.textContent=`${Math.round(t*100)}%`});this._unsubscribers.push(e);const i=this.state.on("change:isDarkMode",({value:t})=>{this._themeBtn.innerHTML=t?q:H});this._unsubscribers.push(i)}updateZoom(e){this._zoomLabel&&(this._zoomLabel.textContent=`${Math.round(e*100)}%`)}destroy(){var e;this._unsubscribers.forEach(i=>i()),this._unsubscribers=[],(e=this.element)==null||e.remove(),this.element=null}}const E=[{id:"adjust",name:"Adjust",icon:ke},{id:"blur",name:"Blur",icon:ve},{id:"color",name:"Color",icon:Pe},{id:"effects",name:"Effects",icon:Me},{id:"distortion",name:"Distortion",icon:Fe},{id:"light",name:"Light",icon:ze},{id:"stylize",name:"Stylize",icon:Ye},{id:"crop",name:"Crop",icon:Ae}];class Oe{constructor(e,i){this.state=e,this.editor=i,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:Q,title:"Previous categories",className:"carousel-nav carousel-nav-left",onClick:()=>this._scrollLeft()}),this._carousel=u("div",{className:"category-carousel"}),E.forEach(t=>{const r=U({label:t.name,icon:t.icon,active:this.state.get("selectedCategory")===t.id,onClick:()=>this._selectCategory(t.id)});r.dataset.categoryId=t.id,r.dataset.category=t.id,r.dataset.testid=`category-${t.id}`,this._chips.set(t.id,r),this._carousel.appendChild(r)}),this._rightBtn=w({icon:J,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 i=Math.ceil(E.length/3);for(let t=0;t<i;t++){const r=u("button",{type:"button",className:`pagination-dot ${t===0?"active":""}`,role:"tab","aria-label":`Page ${t+1} of ${i}`,"aria-selected":t===0?"true":"false",onClick:()=>this._scrollToPage(t)});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:i})=>{this._chips.forEach((t,r)=>{t.setActive(r===i)})});this._unsubscribers.push(e)}_selectCategory(e){var i;this.state.set("selectedCategory",e),e==="crop"?this.editor.setMode("crop"):this.editor.setMode("filters"),(i=this._onSelect)==null||i.call(this,e)}_scrollLeft(){this._scrollIndex>0&&(this._scrollIndex--,this._scrollCarousel())}_scrollRight(){this._scrollIndex<E.length-3&&(this._scrollIndex++,this._scrollCarousel())}_scrollToPage(e){this._scrollIndex=e*3,this._scrollCarousel()}_scrollCarousel(){if(this._carousel){const e=this._carousel.querySelector(".chip"),i=(e==null?void 0:e.clientWidth)||100;this._carousel.scrollTo({left:this._scrollIndex*(i+8),behavior:"smooth"})}this._updateNavButtons(),this._updatePagination()}_updateNavButtons(){this._leftBtn&&(this._leftBtn.disabled=this._scrollIndex===0),this._rightBtn&&(this._rightBtn.disabled=this._scrollIndex>=E.length-3)}_updatePagination(){if(this._pagination){const e=this._pagination.querySelectorAll(".pagination-dot"),i=Math.floor(this._scrollIndex/3);e.forEach((t,r)=>{const a=r===i;t.classList.toggle("active",a),t.setAttribute("aria-selected",a?"true":"false")})}}setSelected(e){this._selectCategory(e)}destroy(){var e;this._unsubscribers.forEach(i=>i()),this._unsubscribers=[],this._chips.clear(),(e=this.element)==null||e.remove(),this.element=null}}class Le{constructor(e,i){this.state=e,this.filterManager=i,this.element=null,this._filterCards=new Map,this._scrollIndex=0,this._unsubscribers=[],this._onToggle=null,this._onSelect=null}render({onToggle:e,onSelect:i}){return this._onToggle=e,this._onSelect=i,this.element=u("div",{className:"filter-carousel-container"}),this._leftBtn=w({icon:Q,title:"Previous filters",className:"carousel-nav carousel-nav-left",onClick:()=>this._scrollLeft()}),this._carousel=u("div",{className:"filter-carousel"}),this._rightBtn=w({icon:J,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 i=this.state.on("change:activeFilters",()=>{this._updateActiveStates()});this._unsubscribers.push(i);const t=this.state.on("change:selectedFilter",()=>{this._updateSelectedState()});this._unsubscribers.push(t)}_renderFilters(){this._carousel.innerHTML="",this._filterCards.clear(),this._scrollIndex=0;const e=this.state.get("selectedCategory");if(e==="crop")return;const i=this.filterManager.getFiltersByCategory(e),t=this.state.get("activeFilters"),r=this.state.get("selectedFilter");i.forEach(a=>{const o=this._createFilterCard(a,{isActive:t.has(a.id),isSelected:r===a.id});this._filterCards.set(a.id,o),this._carousel.appendChild(o)}),this._updateNavButtons()}_createFilterCard(e,{isActive:i,isSelected:t}){const r=u("div",{className:`filter-card ${i?"active":""} ${t?"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 l=u("span",{className:"filter-name",title:e.name},e.name),n=u("button",{className:`filter-toggle ${i?"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 n.innerHTML=i?j:"",r.appendChild(a),r.appendChild(l),r.appendChild(n),r._toggle=n,r._isActive=i,r}_handleCardClick(e){var t;this.state.get("activeFilters").has(e)||this._handleToggle(e,!0),this.state.set("selectedFilter",e),(t=this._onSelect)==null||t.call(this,e)}_handleToggle(e,i){var t;(t=this._onToggle)==null||t.call(this,e,i)}_updateActiveStates(){const e=this.state.get("activeFilters");this._filterCards.forEach((i,t)=>{const r=e.has(t);i.classList.toggle("active",r),i._toggle.classList.toggle("active",r),i._toggle.innerHTML=r?j:"",i._isActive=r})}_updateSelectedState(){const e=this.state.get("selectedFilter");this._filterCards.forEach((i,t)=>{i.classList.toggle("selected",t===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"),i=(e==null?void 0:e.clientWidth)||120;this._carousel.scrollTo({left:this._scrollIndex*(i+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(i=>i()),this._unsubscribers=[],this._filterCards.clear(),(e=this.element)==null||e.remove(),this.element=null}}class Ve{constructor(e,i){this.state=e,this.filterManager=i,this.element=null,this._controls=new Map,this._onChange=null,this._onReset=null,this._onAction=null,this._unsubscribers=[]}render({onChange:e,onReset:i,onAction:t}){return this._onChange=e,this._onReset=i,this._onAction=t,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 i=this.state.on("change:filterValues",()=>{this._updateValues()});this._unsubscribers.push(i)}_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 i=this.filterManager.getFilterDef(e);if(!i){this.element.appendChild(u("div",{className:"no-filter-selected"},"Filter not found"));return}const t=u("div",{className:"adjustments-header"});t.appendChild(u("span",{className:"adjustments-title"},i.name)),t.appendChild(T({label:"Reset",className:"btn-text",onClick:()=>this._handleReset(e)})),this.element.appendChild(t);const r=u("div",{className:"adjustments-grid"}),a=this.state.getFilterValues(e);i.controls.forEach(o=>{const l=this._createControl(e,o,a[o.id]??o.default);l&&(this._controls.set(o.id,l),r.appendChild(l))}),this.element.appendChild(r)}_createControl(e,i,t){if(i.hidden)return null;const r=i.label||i.id;switch(this._normalizeControlType(i.type)){case"slider":return be({id:`${e}-${i.id}`,label:r,min:i.min??0,max:i.max??1,step:i.step??.01,value:typeof t=="number"?t:i.default??0,onChange:n=>this._handleChange(e,i.id,n)});case"toggle":return ye({id:`${e}-${i.id}`,label:r,checked:!!t,onChange:n=>this._handleChange(e,i.id,n)});case"color":return _e({id:`${e}-${i.id}`,label:r,value:typeof t=="string"&&t.startsWith("#")?t:i.default||"#000000",onChange:n=>this._handleChange(e,i.id,n)});case"select":const o=this._normalizeOptions(i.options);return xe({id:`${e}-${i.id}`,label:r,options:o,value:t??i.default,onChange:n=>this._handleChange(e,i.id,n)});case"button":const l=u("div",{className:"button-control"});return l.appendChild(T({label:r,className:"btn-secondary",onClick:()=>this._handleAction(e,i.action||i.id)})),l;default:return null}}_normalizeControlType(e){return{slider:"slider",range:"slider",toggle:"toggle",checkbox:"toggle",color:"color",select:"select",dropdown:"select",button:"button",text:"slider"}[e]||e}_normalizeOptions(e){return!e||!Array.isArray(e)?[]:e.map(i=>typeof i=="object"&&i.value!==void 0?{value:i.value,label:i.label||String(i.value)}:typeof i=="string"?{value:i,label:i}:typeof i=="number"?{value:i,label:String(i)}:{value:i,label:String(i)})}_handleChange(e,i,t){var r;(r=this._onChange)==null||r.call(this,e,i,t)}_handleReset(e){var i;(i=this._onReset)==null||i.call(this,e),this._renderControls()}_handleAction(e,i){var t;(t=this._onAction)==null||t.call(this,e,i)}_updateValues(){const e=this.state.get("selectedFilter");if(!e)return;const i=this.state.getFilterValues(e),t=this.filterManager.getFilterDef(e);t&&t.controls.forEach(r=>{const a=this._controls.get(r.id);if(a&&typeof a.setValue=="function"){const o=i[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(i=>i()),this._unsubscribers=[],this._controls.clear(),(e=this.element)==null||e.remove(),this.element=null}}const De=[{id:"free",name:"Free",icon:Ee},{id:"square",name:"Square",icon:Ie},{id:"circle",name:"Circle",icon:Xe}],Ue=[{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 je{constructor(e,i){this.state=e,this.cropManager=i,this.element=null,this._shapeChips=new Map,this._aspectChips=new Map,this._unsubscribers=[]}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 i=u("div",{className:"chip-row"}),t=this.state.get("crop.shape");De.forEach(c=>{const d=U({label:c.name,icon:c.icon,active:t===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),i.appendChild(d)}),e.appendChild(i),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");Ue.forEach(c=>{const d=U({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"}),l=T({label:"Cancel",className:"btn-secondary crop-cancel-btn",icon:ee,onClick:()=>this.cropManager.cancel()});l.dataset.testid="cancel-crop";const n=T({label:"Apply Crop",className:"btn-primary crop-apply-btn",icon:j,onClick:()=>this.cropManager.apply()});return n.dataset.testid="apply-crop",o.appendChild(l),o.appendChild(n),this.element.appendChild(o),this._subscribeToState(),this.element}_subscribeToState(){const e=this.state.on("change:crop.shape",({value:t})=>{this._shapeChips.forEach((r,a)=>{r.setActive(a===t)}),this._updateAspectVisibility()});this._unsubscribers.push(e);const i=this.state.on("change:crop.aspect",({value:t})=>{this._aspectChips.forEach((r,a)=>{r.setActive(a===t)})});this._unsubscribers.push(i)}_selectShape(e){this.cropManager.setShape(e)}_selectAspect(e){this.cropManager.setAspect(e)}_updateAspectVisibility(){const e=this.state.get("crop.shape"),i=this.state.get("lockAspectRatio");this._aspectSection&&(this._aspectSection.style.display=e==="free"&&!i?"":"none")}show(){this.element&&(this.element.style.display="")}hide(){this.element&&(this.element.style.display="none")}destroy(){var e;this._unsubscribers.forEach(i=>i()),this._unsubscribers=[],this._shapeChips.clear(),this._aspectChips.clear(),(e=this.element)==null||e.remove(),this.element=null}}class qe{constructor(e,i){this.state=e,this.filterManager=i,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:i,onClearAll:t,onUpdateValue:r,onSelect:a}){this._onRemove=e,this._onReset=i,this._onClearAll=t,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 l=T({label:"Clear All",className:"btn-text btn-danger",onClick:()=>this._handleClearAll()});return l.dataset.testid="clear-all-filters",o.appendChild(l),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 i=this.state.on("change:filterValues",()=>{this._updateValuesDisplay()});this._unsubscribers.push(i);const t=this.state.on("change:selectedFilter",()=>{this._updateSelectedState()});this._unsubscribers.push(t)}_updateSelectedState(){const e=this.state.get("selectedFilter");this._filterItems.forEach((i,t)=>{i.classList.toggle("selected",t===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(i=>{const t=this.filterManager.getFilterDef(i);if(!t)return;const r=this._createFilterItem(i,t);this._filterItems.set(i,r),this._listContainer.appendChild(r)})}_createFilterItem(e,i){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"}),l=u("span",{className:"filter-item-name"},i.name),n=u("div",{className:"filter-item-actions"}),c=w({icon:te,title:"Reset filter",className:"btn-icon-sm",onClick:()=>this._handleReset(e)}),d=w({icon:Re,title:"Remove filter",className:"btn-icon-sm btn-danger",onClick:()=>this._handleRemove(e)});n.appendChild(c),n.appendChild(d),o.appendChild(l),o.appendChild(n),a.appendChild(o);const h=this.state.getFilterValues(e),p=u("div",{className:"filter-item-summary"});return p.textContent=this._getValuesSummary(i,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,i){if(!e.controls||!Array.isArray(e.controls))return"Default values";const t=[];return e.controls.forEach(r=>{const a=this._normalizeControlType(r.type);if(a==="button")return;const o=r.label||r.id,l=i[r.id]??r.default;l!==r.default&&(a==="slider"?t.push(`${o}: ${this._formatValue(l)}`):a==="toggle"?l&&t.push(o):a==="color"?t.push(`${o}: ${l}`):a==="select"&&t.push(`${o}: ${l}`))}),t.length>0?t.join(", "):"Default values"}_formatValue(e){return typeof e!="number"||Number.isInteger(e)?String(e):e.toFixed(2)}_updateValuesDisplay(){this._filterItems.forEach((e,i)=>{const t=this.filterManager.getFilterDef(i);if(!t||!e._summaryEl)return;const r=this.state.getFilterValues(i);e._summaryEl.textContent=this._getValuesSummary(t,r)})}_handleRemove(e){var i;(i=this._onRemove)==null||i.call(this,e)}_handleReset(e){var i;(i=this._onReset)==null||i.call(this,e)}_handleClearAll(){var e;(e=this._onClearAll)==null||e.call(this)}_handleSelect(e){var i;this.state.set("selectedFilter",e),(i=this._onSelect)==null||i.call(this,e)}show(){this.element&&(this.element.style.display="")}hide(){this.element&&(this.element.style.display="none")}destroy(){var e;this._unsubscribers.forEach(i=>i()),this._unsubscribers=[],this._filterItems.clear(),(e=this.element)==null||e.remove(),this.element=null}}const N={name:"free",initialMode:"filters",cropShape:"free",aspectRatio:"free",autoZoomOnCropOverflow:!1,lockCropShape:!1,lockAspectRatio:!1,showFilters:!0,showCropControls:!0,maxExportWidth:void 0,maxExportHeight:void 0},L={free:{...N},avatar:{...N,name:"avatar",initialMode:"crop",cropShape:"circle",aspectRatio:"1:1",autoZoomOnCropOverflow:!0,lockCropShape:!0,lockAspectRatio:!0},banner:{...N,name:"banner",initialMode:"crop",cropShape:"square",aspectRatio:"16:9",autoZoomOnCropOverflow:!1,lockCropShape:!1,lockAspectRatio:!0},product:{...N,name:"product",initialMode:"filters",cropShape:"square",aspectRatio:"1:1",autoZoomOnCropOverflow:!1,lockCropShape:!1,lockAspectRatio:!1}};function He(s){if(!s)return{...L.free};if(typeof s=="object"&&s!==null)return{...N,...s};const e=L[s];return e?{...e}:{...L.free}}class $e extends X{constructor(e,i={}){var a,o,l;if(super(),!e)throw new Error("VanillaImageEditor: container element is required");this._container=e;const t=i.preset?He(i.preset):null,r=t?{initialMode:t.initialMode==="crop"?"crop":"adjust",cropShape:t.cropShape,initialAspectRatio:t.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,...i},this._preset=t,this._state=ue(),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 pe,this._filterManager=new me(this._state,this._renderer),this._cropManager=new D(this._state,this._renderer),this._removeBgManager=null,((a=this._options.backgroundRemoval)==null?void 0:a.enabled)!==!1&&(this._removeBgManager=new ge({endpoint:(o=this._options.backgroundRemoval)==null?void 0:o.endpoint,fallbackEndpoint:(l=this._options.backgroundRemoval)==null?void 0:l.fallbackEndpoint})),this._loadingOverlay=null,this._toolbar=null,this._categoryCarousel=null,this._filterCarousel=null,this._filterAdjustments=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._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 i=u("div",{className:"editor-content"}),t=u("div",{className:"canvas-section"});this._canvasContainer=u("div",{className:"canvas-container"}),this._cropOverlay=u("canvas",{className:"crop-overlay","aria-hidden":"true"}),t.appendChild(this._canvasContainer),t.appendChild(this._cropOverlay),i.appendChild(t),this._controlsSection=u("div",{className:"controls-section"}),i.appendChild(this._controlsSection),this._editorEl.appendChild(i),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 Be(this._state,this),this._toolbarContainer.appendChild(this._toolbar.render()),this._filterControlsEl=u("div",{className:"filter-controls-container"}),this._categoryCarousel=new Oe(this._state,this),this._filterControlsEl.appendChild(this._categoryCarousel.render(r=>{}));const e=u("div",{className:"filter-layout"}),i=u("div",{className:"filter-left-column"});this._filterCarousel=new Le(this._state,this._filterManager),i.appendChild(this._filterCarousel.render({onToggle:(r,a)=>this._handleFilterToggle(r,a),onSelect:r=>this._handleFilterSelect(r)})),this._filterAdjustments=new Ve(this._state,this._filterManager),i.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(i);const t=u("div",{className:"filter-right-column"});this._activeFiltersPanel=new qe(this._state,this._filterManager),t.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(t),this._filterControlsEl.appendChild(e),this._cropControls=new je(this._state,this._cropManager),this._cropControlsEl=this._cropControls.render(),this._cropControlsEl.style.display="none",this._controlsSection.appendChild(this._filterControlsEl),this._controlsSection.appendChild(this._cropControlsEl)}_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)}_subscribeToState(){this._state.on("change:mode",({value:e})=>{this._updateModeUI(e)}),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){e==="crop"?(this._filterControlsEl.style.display="none",this._cropControlsEl.style.display=""):(this._filterControlsEl.style.display="",this._cropControlsEl.style.display="none")}async _handleFileSelect(e){var t;const i=(t=e.target.files)==null?void 0:t[0];i&&await this.loadImage(i),this._fileInput.value=""}_handleFilterToggle(e,i){this._filterManager.toggle(e,i)}_handleFilterSelect(e){this._state.set("selectedFilter",e)}_handleFilterChange(e,i,t){this._filterManager.updateValue(e,i,t)||this._filterManager.applyFilters(),this._renderer.render()}_handleFilterReset(e){this._filterManager.resetValues(e),this._filterManager.applyFilters()}_handleFilterAction(e,i){const t=this._filterManager.getInstance(e);t&&typeof t.updateUIParam=="function"&&(t.updateUIParam(i,!0),this._filterManager.applyFilters())}setFilterRegistry(e){this._filterManager.setRegistry(e)}async loadImage(e){let i=e;e instanceof File&&(i=await this._fileToDataUrl(e)),await this._renderer.loadTexture(i),this._state.set("hasImage",!0),this._state.set("imageUrl",i),this._options.initialMode==="crop"&&this.setMode("crop"),this.emit("imageLoaded",{url:i})}_fileToDataUrl(e){return new Promise((i,t)=>{const r=new FileReader;r.onload=()=>i(r.result),r.onerror=t,r.readAsDataURL(e)})}openFilePicker(){var e;(e=this._fileInput)==null||e.click()}exportImage(e="png",i=.92){return this._renderer.exportImage(e,i)}save(){var e,i;if(this._state.get("hasImage")){this._state.set("isSaving",!0);try{const t=this.exportImage("png",.92);if(!t)throw new Error("Failed to export image");const r={width:Math.round(((e=this._renderer.sprite)==null?void 0:e.width)||0),height:Math.round(((i=this._renderer.sprite)==null?void 0:i.height)||0)},a=document.createElement("a");a.href=t,a.download=`edited-image-${Date.now()}.png`,document.body.appendChild(a),a.click(),document.body.removeChild(a),this.emit("save",{imageData:t,dimensions:r})}catch(t){this.emit("error",{error:t})}finally{this._state.set("isSaving",!1)}}}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 i=this.exportImage("png");if(!i)throw new Error("Failed to export image for background removal");const t=await this._removeBgManager.removeBackground(i,e);return await this.loadImage(t.dataUrl),this.emit("background-removed",{model:t.model,processMs:t.processMs}),{model:t.model,processMs:t.processMs}}catch(i){throw this.emit("error",{error:i,context:"background-removal"}),i}finally{this._state.set("isProcessing",!1),this._hideLoadingOverlay()}}async isBackgroundRemovalAvailable(){return this._removeBgManager?this._removeBgManager.isAvailable():!1}_showLoadingOverlay(e){var t;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 i=(t=this._canvasContainer)==null?void 0:t.parentElement;i&&!this._loadingOverlay.parentElement&&i.appendChild(this._loadingOverlay)}_hideLoadingOverlay(){var e;(e=this._loadingOverlay)==null||e.remove()}destroy(){var e,i,t,r,a,o,l,n;(e=this._resizeObserver)==null||e.disconnect(),this._renderer.destroy(),this._cropManager.disable(),(i=this._toolbar)==null||i.destroy(),(t=this._categoryCarousel)==null||t.destroy(),(r=this._filterCarousel)==null||r.destroy(),(a=this._filterAdjustments)==null||a.destroy(),(o=this._cropControls)==null||o.destroy(),(l=this._activeFiltersPanel)==null||l.destroy(),(n=this._editorEl)==null||n.remove(),this._container=null,this._state=null,this.emit("destroyed"),this.removeAllListeners()}}const k=new Map,R=new Map;function f(s){var e;return k.has(s.id),k.set(s.id,s),R.has(s.category)||R.set(s.category,[]),(e=R.get(s.category))==null||e.push(s.id),s}function ie(s){return k.get(s)}function I(){return Array.from(k.values())}function Ze(){I().map(i=>i.id),Object.entries(g).filter(i=>/Filter$/.test(i[0])&&typeof i[1]=="function").forEach(([i,t])=>{const r=i.replace(/Filter$/,"").replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();k.has(r)||f({id:r,name:i.replace(/Filter$/,""),category:"unlisted",defaultParams:{},controls:[],createFilter:(a={})=>{try{return new t(a)}catch{return null}}})})}function re(s){return(R.get(s)||[]).map(i=>k.get(i)).filter(Boolean)}function se(){return Array.from(R.keys())}function We(s){return k.has(s)}function ae(){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=I,window.getFilter=ie,window.getFiltersByCategory=re,window.getRegisteredFilters=ae;const s=f;window.registerFilter=e=>{const i=s(e);return window.__DEBUG_FILTERS_LIST=Array.from(k.keys()),i}}typeof window<"u"&&(window.initializeFilterRegistry=window.initializeFilterRegistry||function(){return[]});const{AdjustmentFilter:Ge}=g,{ColorMatrixFilter:Ke}=C;f({id:"adjustment",name:"Adjustment",category:"adjust",description:"Adjust basic image properties like brightness, contrast, and saturation",createFilter:s=>{try{const e={gamma:s.gamma??1,saturation:s.saturation??1,contrast:s.contrast??1,brightness:s.brightness??1,red:s.red??1,green:s.green??1,blue:s.blue??1,alpha:s.alpha??1};try{const i=new Ge(e);return i._customParams={...s},i.updateUIParam=function(t,r){try{const a=this._customParams||{};this._customParams=a,a[t]=r;const o=Number(r);switch(t){case"gamma":this.gamma=o;break;case"saturation":this.saturation=o;break;case"contrast":this.contrast=o;break;case"brightness":this.brightness=o;break;case"red":this.red=o;break;case"green":this.green=o;break;case"blue":this.blue=o;break;case"alpha":this.alpha=o;break;default:t in this&&(this[t]=o);break}}catch{}},i}catch{const t=new Ke;return t._customParams={...s},typeof t.brightness=="function"&&t.brightness(s.brightness,!1),typeof t.contrast=="function"&&t.contrast(s.contrast,!1),typeof t.saturate=="function"&&t.saturate(s.saturation,!1),t.updateUIParam=function(r,a){try{const o=this._customParams||{};switch(this._customParams=o,o[r]=a,r){case"brightness":typeof this.brightness=="function"&&this.brightness(a,!1);break;case"contrast":typeof this.contrast=="function"&&this.contrast(a,!1);break;case"saturation":typeof this.saturate=="function"&&this.saturate(a,!1);break;default:r in this&&(this[r]=a);break}}catch{}},t}}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:Qe}=C;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=new Qe;return e._customParams={...s},e.reset(),s.brightness!==1&&e.brightness(s.brightness,!1),s.contrast!==1&&e.contrast(s.contrast,!1),s.saturation!==1&&e.saturate(s.saturation,!1),s.hue!==0&&e.hue(s.hue,!1),s.sepia>0&&e.sepia(!1),s.negative&&e.negative(!1),e.updateUIParam=function(i,t){try{const r=this._customParams||{};this._customParams=r,r[i]=t,this.reset();const a=r;a.brightness!==1&&this.brightness(a.brightness,!1),a.contrast!==1&&this.contrast(a.contrast,!1),a.saturation!==1&&this.saturate(a.saturation,!1),a.hue!==0&&this.hue(a.hue,!1),a.sepia>0&&this.sepia(!1),a.negative&&this.negative(!1)}catch{}},e}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,i=new C.ColorMatrixFilter;return i.alpha=e,i._customParams={alpha:e},i.updateUIParam=function(t,r){try{const a=this._customParams||{};if(this._customParams=a,t==="alpha"){const o=Number(r);this.alpha=o,a.alpha=o}else t in this&&(this[t]=r)}catch{}},i}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 C.BlurFilter({strength:s.blur||8,quality:s.quality||4});return e._customParams={...s},e.updateUIParam=function(i,t){const r=this._customParams||{};switch(this._customParams=r,r[i]=t,i){case"blur":this.strength=t;break;case"quality":this.quality=t;break;default:i in this&&(this[i]=t);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=C.ColorMatrixFilter;if(!e)return null;const i=new e;try{return typeof i.reset=="function"&&i.reset(),s.brightness!==1&&typeof i.brightness=="function"&&i.brightness(s.brightness,!1),s.contrast!==1&&typeof i.contrast=="function"&&i.contrast(s.contrast,!1),s.saturation!==1&&typeof i.saturate=="function"&&i.saturate(s.saturation,!1),s.hue!==0&&typeof i.hue=="function"&&i.hue(s.hue,!1),s.sepia>0&&typeof i.sepia=="function"&&i.sepia(s.sepia),s.negative&&typeof i.negative=="function"&&i.negative(!1),i}catch{return i}},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:Je}=g;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 i=new Je({color:e,alpha:s.alpha||.5});return i._customParams={...s},i.updateUIParam=function(t,r){const a=this._customParams||{};switch(this._customParams=a,a[t]=r,t){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:t in this&&(this[t]=r);break}return!0},i}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",i=s.distance!==void 0?s.distance:5,t=s.angle!==void 0?s.angle:90,r={x:i*Math.cos(t*Math.PI/180),y:i*Math.sin(t*Math.PI/180)},a=new g.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:i,_angle:t},a.updateUIParam=function(o,l){try{const n=this._customParams||{};switch(this._customParams=n,n[o]=l,o){case"color":if(typeof l=="string"){const d=parseInt(l.replace("#","0x"),16);this.color=d}break;case"alpha":this.alpha=Number(l);break;case"blur":this.blur=Number(l);break;case"quality":this.quality=Number(l);break;case"shadowOnly":this.shadowOnly=!!l;break;case"pixelSizeX":this.pixelSizeX=Number(l),n.pixelSizeX=Number(l);break;case"pixelSizeY":this.pixelSizeY=Number(l),n.pixelSizeY=Number(l);break;case"distance":case"angle":o==="distance"?n._distance=Number(l):n._angle=Number(l);const c={x:n._distance*Math.cos(n._angle*Math.PI/180),y:n._distance*Math.sin(n._angle*Math.PI/180)};n._offset=c,this.offset=c;break;default:o in this&&(this[o]=l);break}return!0}catch{return this._customParams&&(this._customParams[o]=l),!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:et}=C;f({id:"grayscale",name:"Grayscale",category:"color",description:"Convert the image to black and white with adjustable intensity",createFilter:s=>{try{const e=new et;e._customParams={...s};const i=s.intensity!==void 0?s.intensity:1;return $(e,i),e.updateUIParam=function(t,r){const a=this._customParams||{};switch(this._customParams=a,a[t]=r,t){case"intensity":$(this,r);break;default:t in this&&(this[t]=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 $(s,e){s.reset(),s.greyscale(e)}const{HslAdjustmentFilter:tt}=g;f({id:"hsl-adjustment",name:"HSL Adjustment",category:"color",description:"Control hue, saturation, and lightness independently",createFilter:s=>{try{const e=new tt({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(i,t){try{const r=this._customParams||{};switch(this._customParams=r,r[i]=t,i){case"hue":this.hue=Number(t),this.uniforms&&(this.uniforms.uHue=Number(t));break;case"saturation":this.saturation=Number(t),this.uniforms&&(this.uniforms.uSaturation=Number(t));break;case"lightness":this.lightness=Number(t),this.uniforms&&(this.uniforms.uLightness=Number(t));break;case"colorize":this.colorize=!!t,this.uniforms&&(this.uniforms.uColorize=t?1:0);break;case"alpha":this.alpha=Number(t),this.uniforms&&(this.uniforms.uAlpha=Number(t));break;default:i in this&&(this[i]=t);break}return!0}catch{return this._customParams&&(this._customParams[i]=t),!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:it}=g;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 it({strength:s.strength||4,quality:s.quality||3,clamp:s.clamp||!1,pixelSize:s.pixelSize||1});return e._customParams={...s},e.updateUIParam=function(i,t){const r=this._customParams||{};switch(this._customParams=r,r[i]=t,i){case"strength":this.strength=t;break;case"quality":this.quality=t;break;case"clamp":this.clamp=t;break;case"pixelSize":typeof t=="number"?this.pixelSize=t:typeof t=="object"&&t!==null&&"x"in t&&"y"in t&&(this.pixelSize=t);break;case"pixelSizeX":this.pixelSizeX=t;break;case"pixelSizeY":this.pixelSizeY=t;break;default:i in this&&(this[i]=t);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:rt}=g;f({id:"motion-blur",name:"Motion Blur",category:"blur",description:"Creates a directional blur effect simulating motion",createFilter:s=>{try{const e=new rt({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(i,t){const r=this._customParams||{};switch(this._customParams=r,r[i]=t,i){case"velocityX":this.velocityX=t;break;case"velocityY":this.velocityY=t;break;case"kernelSize":this.kernelSize=t;break;case"offset":this.offset=t;break;default:i in this&&(this[i]=t);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:st}=g;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 st({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(i,t){try{switch(i){case"angle":this.angle=Number(t);break;case"centerX":this._customParams.centerX=Number(t),this.center={x:Number(t),y:this._customParams.centerY};break;case"centerY":this._customParams.centerY=Number(t),this.center={x:this._customParams.centerX,y:Number(t)};break;case"kernelSize":this.kernelSize=Number(t);break;case"radius":this.radius=Number(t);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:at}=g;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,i=typeof s.gradientBlur=="number"?s.gradientBlur:600,t=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,l=new at({blur:Number(e),gradientBlur:Number(i),start:{x:Number(t),y:Number(r)},end:{x:Number(a),y:Number(o)}});return l._customParams={blur:e,gradientBlur:i,startX:t,startY:r,endX:a,endY:o},l.updateUIParam=function(n,c){try{const d=Number(c),h=this._customParams||{};switch(this._customParams=h,h[n]=d,n){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:n in this&&(this[n]=d);break}}catch{}},l}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:ot}=g;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 ot({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(i,t){const r=this._customParams||{};switch(this._customParams=r,r[i]=t,i){case"strength":this.strength=t;break;case"centerX":this.centerX=t;break;case"centerY":this.centerY=t;break;case"innerRadius":this.innerRadius=t;break;case"radius":this.radius=t;break;default:i in this&&(this[i]=t);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:Z}=g;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(t=>({offset:t.offset,color:typeof t.color=="string"?parseInt(t.color.replace("#","0x")):t.color,alpha:t.alpha})),e.length<2&&(e=[{offset:0,color:16711680,alpha:1},{offset:1,color:255,alpha:1}]),e.sort((t,r)=>t.offset-r.offset);const i=new Z({type:s.gradientType,stops:e,angle:s.angle,alpha:s.alpha,maxColors:s.maxColors||0,replace:s.replace});return i._customParams={...s},i.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}))},i.getDynamicControls=function(){const t=this.getColorStopsForUI(),r=[];return t.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},i.handleButtonAction=function(t){(t==="addColorStop"||t==="removeColorStop")&&this.updateUIParam(t,!0)},i.updateUIParam=function(t,r){const a=this._customParams||{};switch(this._customParams=a,a[t]=r,t){case"gradientType":this.type=r;break;case"angle":case"alpha":case"maxColors":case"replace":t in this&&(this[t]=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 Z({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(t)){const h=t.match(/colorStops\[(\d+)\]\.(.*)/);if(h){const[p,m,S]=h,b=parseInt(m),_=[...this.stops];if(b>=0&&b<_.length)return S==="color"&&typeof r=="string"?_[b].color=parseInt(r.replace("#","0x")):(S==="offset"||S==="alpha")&&(_[b][S]=r),this.stops=_,this.stops.sort((x,y)=>x.offset-y.offset),a.colorStops=this.getColorStopsForUI(),!0}}else t in this&&(this[t]=r);break}},i}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=g.ColorMapFilter;if(!e)return null;let i=null;s.texturePath?i=C.Texture.from(s.texturePath):i=C.Texture.from("/examples/filters-main/examples/images/colormap.png");const t=new e({colorMap:i,nearest:s.nearest,mix:s.mix});return t._customParams={...s},t.updateUIParam=function(r,a){const o=this._customParams||{};switch(this._customParams=o,o[r]=a,r){case"texturePath":a&&(this.colorMap=C.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},t}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 lt=g.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 i=255;s.targetColor&&(typeof s.targetColor=="string"?i=parseInt(s.targetColor.replace("#","0x"),16):typeof s.targetColor=="number"&&(i=s.targetColor));const t=new lt({originalColor:e,targetColor:i,tolerance:s.tolerance||.4});return t._customParams={...s},t.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},t}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 nt=g.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 t=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([t,r])}if(s.originalColor2&&s.targetColor2){const t=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([t,r])}if(s.enableThirdPair&&s.originalColor3&&s.targetColor3){const t=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([t,r])}const i=new nt(e,s.tolerance||.05,3);return i._customParams={...s},i.updateUIParam=function(t,r){const a=this._customParams||{};if(this._customParams=a,a[t]=r,t==="originalColor1"||t==="targetColor1"||t==="originalColor2"||t==="targetColor2"||t==="originalColor3"||t==="targetColor3"||t==="enableThirdPair"){const o=[];if(a.originalColor1&&a.targetColor1){const l=typeof a.originalColor1=="string"?parseInt(a.originalColor1.replace("#","0x"),16):a.originalColor1,n=typeof a.targetColor1=="string"?parseInt(a.targetColor1.replace("#","0x"),16):a.targetColor1;o.push([l,n])}if(a.originalColor2&&a.targetColor2){const l=typeof a.originalColor2=="string"?parseInt(a.originalColor2.replace("#","0x"),16):a.originalColor2,n=typeof a.targetColor2=="string"?parseInt(a.targetColor2.replace("#","0x"),16):a.targetColor2;o.push([l,n])}if(a.enableThirdPair&&a.originalColor3&&a.targetColor3){const l=typeof a.originalColor3=="string"?parseInt(a.originalColor3.replace("#","0x"),16):a.originalColor3,n=typeof a.targetColor3=="string"?parseInt(a.targetColor3.replace("#","0x"),16):a.targetColor3;o.push([l,n])}this.replacements=o,this.refresh()}else t==="tolerance"?this.tolerance=r:t in this&&(this[t]=r);return!0},i}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:ct}=g;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},i={x:s.greenX!==void 0?s.greenX:0,y:s.greenY!==void 0?s.greenY:10},t={x:s.blueX!==void 0?s.blueX:0,y:s.blueY!==void 0?s.blueY:0},r=new ct({red:e,green:i,blue:t});return r._customParams={...s},r.updateUIParam=function(a,o){try{const l=this._customParams||{};switch(this._customParams=l,l[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:ht}=g;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 ht({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(i,t){try{const r=this._customParams||{};switch(this._customParams=r,r[i]=t,i){case"threshold":this.threshold=Number(t);break;case"bloomScale":this.bloomScale=Number(t);break;case"brightness":this.brightness=Number(t);break;case"blur":this.blur=Number(t);break;case"quality":this.quality=Number(t);break;case"pixelSizeX":r.pixelSizeX=Number(t),this.pixelSize={x:Number(t),y:r.pixelSizeY};break;case"pixelSizeY":r.pixelSizeY=Number(t),this.pixelSize={x:r.pixelSizeX,y:Number(t)};break;default:i in this&&(this[i]=t);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 dt=g.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 i=s.color;typeof i=="string"&&i.startsWith("#")&&(i=parseInt(i.replace("#","0x"),16));const t=s.replaceColor===!0,r=new dt({size:e,color:i,replaceColor:t});return r._customParams={size:e,color:i,replaceColor:t},r.updateUIParam=function(a,o){try{const l=this._customParams||{};switch(this._customParams=l,l[a]=o,a){case"size":this.size=Number(o);break;case"color":typeof o=="string"&&o.startsWith("#")?(l.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 ut=g.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 ut({strength:s.strength||20,quality:s.quality||4,resolution:s.resolution||.5,kernelSize:s.kernelSize||9});return e._customParams={...s},e.updateUIParam=function(i,t){try{const r=this._customParams||{};switch(this._customParams=r,r[i]=t,i){case"strength":this.strength=Number(t),this.blur=Number(t)/4;break;case"quality":this.quality=Number(t);break;case"resolution":this.resolution=Number(t);break;case"kernelSize":const a=Number(t);this.blurXFilter&&this.blurYFilter?(this.blurXFilter.kernelSize=a,this.blurYFilter.kernelSize=a):this.kernelSize=a;break;default:i in this&&(this[i]=t);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:pt}=g;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",i=s.shadowColor?s.shadowColor.replace("#","0x"):"0x000000",t=new pt({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(i,16),shadowAlpha:s.shadowAlpha!==void 0?s.shadowAlpha:.7});return t._customParams={...s},t.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 l=parseInt(a.replace("#","0x"),16);this.lightColor=l}break;case"lightAlpha":this.lightAlpha=Number(a);break;case"shadowColor":if(typeof a=="string"){const l=parseInt(a.replace("#","0x"),16);this.shadowColor=l}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}},t}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:ft}=g;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,i=typeof s.strengthY=="number"?s.strengthY:2,t=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 ft({strength:{x:Number(e),y:Number(i)},quality:Number(t),resolution:Number(r),kernelSize:Number(a)});return o._customParams={strengthX:e,strengthY:i,quality:t,resolution:r,kernelSize:a},o.updateUIParam=function(l,n){var c,d;try{const h=Number(n),p=this._customParams||{};switch(this._customParams=p,p[l]=h,l){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:l in this&&(this[l]=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:mt}=g;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,i=s.centerY??.5,t=s.radius??100,r=s.strength??1,a=new mt({center:{x:e,y:i},radius:t,strength:r});return a._customParams={...s},a.updateUIParam=function(o,l){const n=this._customParams||{};switch(this._customParams=n,n[o]=l,o){case"centerX":this.center||(this.center={x:.5,y:.5}),this.center.x=l;break;case"centerY":this.center||(this.center={x:.5,y:.5}),this.center.y=l;break;case"radius":case"strength":this[o]=l;break;default:o in this&&(this[o]=l);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:gt}=g,A={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 t=s.preset;e=A[t]||A.normal}const i=new gt(e,s.width||200,s.height||200);return i._customParams={...s},i.updateUIParam=function(t,r){const a=this._customParams||{};switch(this._customParams=a,a[t]=r,t){case"preset":if(!a.customMatrix){const o=r;A[o]&&(this.matrix=A[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=A[o]||A.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],n={m00:0,m01:1,m02:2,m10:3,m11:4,m12:5,m20:6,m21:7,m22:8}[t];n!==void 0&&(o[n]=r,this.matrix=o)}break;case"width":this.width=r;break;case"height":this.height=r;break;default:t in this&&(this[t]=r);break}},i}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:bt}=g;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 bt;return e.updateUIParam=function(i,t){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()},i=new g.CRTFilter(e);return i._customParams={...e},i.updateUIParam=function(t,r){try{const a=this._customParams||{};switch(this._customParams=a,a[t]=r,t){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:t in this&&(this[t]=r);break}}catch{}},i}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 yt=C.DisplacementFilter,_t=C.Sprite,V=C.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 i;try{i=V.from(e),i.source.addressMode="repeat"}catch{const o=document.createElement("canvas");o.width=256,o.height=256;const l=o.getContext("2d");if(l){l.fillStyle="#ffffff",l.fillRect(0,0,o.width,o.height),l.fillStyle="#000000";for(let n=0;n<10;n++)for(let c=0;c<10;c++)(n+c)%2===0&&l.fillRect(n*25,c*25,25,25)}i=V.from(o)}const t=new _t(i),r=new yt(t,s.scale||50);return r.scale.x=s.scaleX||50,r.scale.y=s.scaleY||50,r._customParams={...s},r._displacementSprite=t,r.updateUIParam=function(a,o){const l=this._customParams||{};switch(this._customParams=l,l[a]=o,a){case"scaleX":this.scale.x=o;break;case"scaleY":this.scale.y=o;break;case"mapTexture":try{const n=this._displacementSprite;if(n){const c=V.from(o);c.source.addressMode="repeat",n.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},i=new g.DotFilter(e);return i._customParams={...e},i.updateUIParam=function(t,r){try{const a=this._customParams||{};switch(this._customParams=a,a[t]=r,t){case"scale":this.scale=Number(r);break;case"angle":this.angle=Number(r);break;case"grayscale":this.grayscale=!!r;break;default:t in this&&(this[t]=r);break}}catch{}},i}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:xt}=g;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,i=new xt(e);return i._customParams={strength:e},i.updateUIParam=function(t,r){try{const a=this._customParams||{};switch(this._customParams=a,a[t]=r,t){case"strength":const o=Number(r);a.strength=o,this.strength=o;break;default:t in this&&(this[t]=r);break}}catch{}},i}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:Ct}=g,M={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},i={x:s.greenX,y:s.greenY},t={x:s.blueX,y:s.blueY},r=new Ct({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:i,blue:t});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(l,n){const c=this._customParams||{};switch(this._customParams=c,c[l]=n,l){case"animating":this.animating=n,n&&!a&&(a=requestAnimationFrame(o));break;case"slices":this.slices=Math.round(n);break;case"redX":case"redY":const d=this.red;l==="redX"?d.x=n:d.y=n,this.red=d;break;case"greenX":case"greenY":const h=this.green;l==="greenX"?h.x=n:h.y=n,this.green=h;break;case"blueX":case"blueY":const p=this.blue;l==="blueX"?p.x=n:p.y=n,this.blue=p;break;case"seed":this.animating||(this.seed=n);break;case"randomizeSeed":n&&!c.animating&&(this.seed=Math.random());break;case"refresh":if(n)try{this.refresh()}catch{}break;case"offset":case"direction":case"fillMode":case"average":case"minSize":case"sampleSize":l in this&&(this[l]=n);break;default:l in this&&(this[l]=n);break}},r}catch{return null}},defaultParams:{slices:10,offset:100,direction:0,fillMode:M.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:M.TRANSPARENT,label:"Transparent"},{value:M.ORIGINAL,label:"Original"},{value:M.LOOP,label:"Loop"},{value:M.CLAMP,label:"Clamp"},{value:M.MIRROR,label:"Mirror"}],default:M.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:wt}=g;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),i=new wt({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 i._customParams={color:s.color||"#ffffff",...s},i.updateUIParam=function(t,r){try{const a=this._customParams||{};switch(this._customParams=a,a[t]=r,t){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:t in this&&(this[t]=r);break}}catch{}},i}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:St}=g;f({id:"godray",name:"Godray",category:"light",description:"Creates volumetric light-ray effects (crepuscular rays)",createFilter:s=>{try{const e=new St({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(i,t){try{const r=this._customParams||{};switch(this._customParams=r,r[i]=t,i){case"angle":this.angle=Number(t);break;case"parallel":this.parallel=!!t;break;case"centerX":r.centerX=Number(t),this.center={x:Number(t),y:r.centerY};break;case"centerY":r.centerY=Number(t),this.center={x:r.centerX,y:Number(t)};break;case"gain":this.gain=Number(t);break;case"lacunarity":this.lacunarity=Number(t);break;case"time":this.time=Number(t);break;case"alpha":this.alpha=Number(t);break;default:i in this&&(this[i]=t);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 kt=g.SimpleLightmapFilter,W=C.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",i=s.color||"#000000",t=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=W.from(r);let l;try{typeof i=="string"&&i.startsWith("#")?l=parseInt(i.replace("#","0x"),16):l=0}catch{l=0}const n=new kt(o,l,t);return n._customParams={textureType:e,color:i,alpha:t},n.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 b=m.createRadialGradient(128,128,5,128,128,80);b.addColorStop(0,"white"),b.addColorStop(.5,"rgba(255, 255, 255, 0.5)"),b.addColorStop(1,"rgba(0, 0, 0, 0)"),m.fillStyle=b,m.beginPath(),m.arc(128,128,100,0,Math.PI*2),m.fill()}else if(d==="softlight"){const b=m.createLinearGradient(0,0,256,256);b.addColorStop(0,"white"),b.addColorStop(.3,"rgba(220, 220, 220, 1)"),b.addColorStop(.7,"rgba(150, 150, 150, 1)"),b.addColorStop(1,"rgba(80, 80, 80, 1)"),m.fillStyle=b,m.fillRect(0,0,256,256)}else{const b=m.createRadialGradient(128,128,10,128,128,160);b.addColorStop(0,"white"),b.addColorStop(.3,"rgba(220, 220, 220, 1)"),b.addColorStop(.6,"rgba(150, 150, 150, 1)"),b.addColorStop(1,"black"),m.fillStyle=b,m.fillRect(0,0,256,256)}const S=W.from(p);if(this.lightMap=S,this.enabled!==void 0){const b=this.enabled;this.enabled=!1,setTimeout(()=>{this.enabled=b},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{}},n}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:vt}=C;f({id:"noise",name:"Noise",category:"effects",description:"Add random noise to the image",createFilter:s=>{try{const e=new vt({noise:s.noise||.5,seed:s.seed||Math.random()});e.animating=s.animating||!1,e._customParams={...s};let i=null;const t=()=>{e.animating&&(e.seed=Math.random()),i=requestAnimationFrame(t)};return e.animating&&(i=requestAnimationFrame(t)),e._stopAnimation=()=>{i!==null&&(cancelAnimationFrame(i),i=null)},e.updateUIParam=function(r,a){const o=this._customParams||{};switch(this._customParams=o,o[r]=a,r){case"animating":this.animating=a,a&&!i&&(i=requestAnimationFrame(t));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:Pt}=g;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 Pt({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 i=null;const t=()=>{e.animating&&(e.seed=Math.random()),i=requestAnimationFrame(t)};return e.animating&&(i=requestAnimationFrame(t)),e._stopAnimation=()=>{i!==null&&(cancelAnimationFrame(i),i=null)},e.updateUIParam=function(r,a){const o=this._customParams||{};switch(this._customParams=o,o[r]=a,r){case"animating":this.animating=a,a&&!i&&(i=requestAnimationFrame(t));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:Mt}=g;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 i=new Mt({thickness:s.thickness||4,color:e,alpha:s.alpha||1,quality:s.quality||.1,knockout:s.knockout||!1});return i._customParams={...s},i.updateUIParam=function(t,r){const a=this._customParams||{};switch(this._customParams=a,a[t]=r,t){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:t in this&&(this[t]=r);break}},i}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:Ft}=g;f({id:"pixelate",name:"Pixelate",category:"effects",description:"Create a pixelated or mosaic effect",createFilter:s=>{try{const e=new Ft(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(i,t){const r=this._customParams||{};switch(this._customParams=r,r[i]=t,i){case"useUniform":if(r.useUniform=t,t){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,t));break;case"sizeX":r.useUniform||(this.sizeX=Math.max(4,t));break;case"sizeY":r.useUniform||(this.sizeY=Math.max(4,t));break;default:i in this&&(this[i]=t);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:zt}=g;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},i=new zt(e);return i._customParams={...s},i.animating=s.animating??!1,i.updateUIParam=function(t,r){const a=this._customParams||{};switch(this._customParams=a,a[t]=r,t){case"mirror":case"boundary":case"time":this[t]=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:t in this&&(this[t]=r);break}return!0},i}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:At}=g;f({id:"shockwave",name:"Shockwave",category:"distortion",description:"Creates a rippling shockwave or blast wave effect",createFilter:s=>{try{const e=s.centerX??.5,i=s.centerY??.5,t={x:e,y:i},r=s.amplitude??30,a=s.wavelength??160,o=s.speed??500,l=s.brightness??1,n=s.radius??-1,c=s.time??0,d=new At({center:t,amplitude:r,wavelength:a,speed:o,brightness:l,radius:n,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:Nt}=g;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,i=new Nt({strength:s.strength,noiseScale:s.noiseScale,offsetX:s.offsetX,offsetY:s.offsetY,offsetZ:e,step:s.step});i.animating=s.animating||!1,i.animationSpeed=s.animationSpeed||.01,i._customParams={...s};let t=null,r=0;const a=()=>{i.animating&&(r+=i.animationSpeed,i.offsetZ=r),t=requestAnimationFrame(a)};return i.animating&&(t=requestAnimationFrame(a)),i._stopAnimation=()=>{t!==null&&(cancelAnimationFrame(t),t=null)},i.updateUIParam=function(o,l){const n=this._customParams||{};switch(this._customParams=n,n[o]=l,o){case"animating":this.animating=l,l&&!t&&(t=requestAnimationFrame(a));break;case"animationSpeed":this.animationSpeed=l;break;case"offsetZ":this.animating||(this.offsetZ=l);break;case"randomizeSeed":if(l){const c=()=>Math.random()*100-50;this.offsetX=c(),this.offsetY=c(),this.offsetZ=c(),n.offsetX=this.offsetX,n.offsetY=this.offsetY,n.offsetZ=this.offsetZ}break;case"strength":case"noiseScale":case"offsetX":case"offsetY":case"step":o in this&&(this[o]=l);break;default:o in this&&(this[o]=l);break}},i}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 Rt extends C.Filter{constructor(e){const i=G.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:i,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,i){switch(e){case"centerX":this.centerX=i;break;case"centerY":this.centerY=i;break;case"radius":this.radius=i;break;case"angle":this.angle=i;break}}}f({id:"twist",name:"Twist",category:"distortion",description:"Creates a twisting distortion effect around a central point",createFilter:s=>{try{const e=new Rt({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:Tt}=g;function Y(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 It extends Tt{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=Y(e.color)):(this._colorValue="#"+e.color.toString(16).padStart(6,"0"),this._colorRgb=Y(e.color))),this.updateVignette()}updateVignette(){const e=1-this._radius/2,i=this._strength*e;this.brightness=Math.max(.5,1-i*.5),this.contrast=1+i*.2,(this._colorRgb[0]>0||this._colorRgb[1]>0||this._colorRgb[2]>0)&&(this.saturation=1-i*.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=Y(e)):(this._colorValue="#"+e.toString(16).padStart(6,"0"),this._colorRgb=Y(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 It({radius:s.radius||.8,strength:s.strength||1,color:s.color||"#000000"});return e._customParams={...s},e.updateUIParam=function(i,t){const r=this._customParams||{};switch(this._customParams=r,r[i]=t,i){case"radius":this.radius=Math.max(.1,Math.min(1.5,t));break;case"strength":this.strength=Math.max(0,t);break;case"color":this.color=t,typeof t=="string"&&(r.color=t);break;default:i in this&&(this[i]=t);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 Xt(){try{let s=[],e=[];try{s=I(),s.length===0&&Ze()}catch{}try{s=I(),e=se()}catch{s||(s=[]),e||(e=[])}return s.length,s}catch{return[]}}exports.VanillaImageEditor=$e;exports.getAllCategories=se;exports.getAllFilters=I;exports.getFilter=ie;exports.getFiltersByCategory=re;exports.getRegisteredFilters=ae;exports.hasFilter=We;exports.initializeFilterRegistry=Xt;exports.registerFilter=f;
42
- //# sourceMappingURL=index-C_X9_ptj.cjs.map