@codingfactory/mediables-vue 2.4.23 → 2.6.1

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 (58) hide show
  1. package/README.md +7 -1
  2. package/dist/{PixiFrameExporter-DmyELJBR.cjs → PixiFrameExporter-CetwQ3WI.cjs} +2 -2
  3. package/dist/{PixiFrameExporter-DmyELJBR.cjs.map → PixiFrameExporter-CetwQ3WI.cjs.map} +1 -1
  4. package/dist/{PixiFrameExporter-UPjs5JGK.js → PixiFrameExporter-DFchWLl5.js} +2 -2
  5. package/dist/{PixiFrameExporter-UPjs5JGK.js.map → PixiFrameExporter-DFchWLl5.js.map} +1 -1
  6. package/dist/components/ExistingMediaSelector.vue.d.ts +13 -1
  7. package/dist/components/ImageEditor/ImageEditor.vue.d.ts +1 -0
  8. package/dist/components/ImageEditorModal.vue.d.ts +2 -0
  9. package/dist/components/MediaAlbumInlineCreate.vue.d.ts +2 -0
  10. package/dist/components/MediaAlbumUnavailableState.vue.d.ts +2 -0
  11. package/dist/components/MediaLibraryPicker.vue.d.ts +2 -0
  12. package/dist/components/MediaLibraryPickerModal.vue.d.ts +2 -0
  13. package/dist/components/MediaManagementView.vue.d.ts +2 -0
  14. package/dist/components/MediaPreviewSheet.vue.d.ts +2 -0
  15. package/dist/components/MediaSelectionTray.vue.d.ts +2 -0
  16. package/dist/components/MediaSourceSheet.vue.d.ts +2 -0
  17. package/dist/components/MediaThumbnailCell.vue.d.ts +2 -0
  18. package/dist/components/MediaUploadSheet.vue.d.ts +2 -0
  19. package/dist/components/VirtualMediaGrid.vue.d.ts +2 -0
  20. package/dist/composables/useFloatingPills.d.ts +4 -0
  21. package/dist/composables/useMediaDeletion.d.ts +66 -0
  22. package/dist/composables/useMediaLibraryPickerController.d.ts +60 -0
  23. package/dist/composables/useMediaLibraryQuery.d.ts +25 -0
  24. package/dist/composables/useMediaLibrarySession.d.ts +12 -0
  25. package/dist/composables/useMediaLibraryStateMachine.d.ts +6 -0
  26. package/dist/composables/useMediaLibraryTelemetry.d.ts +4 -0
  27. package/dist/composables/useMediaTrash.d.ts +64 -0
  28. package/dist/composables/useMediaUploadQueue.d.ts +2 -0
  29. package/dist/editor-BTwIhrcA.cjs +2 -0
  30. package/dist/editor-BTwIhrcA.cjs.map +1 -0
  31. package/dist/{editor-2Q72CZjK.js → editor-CYj5y5bp.js} +1417 -1167
  32. package/dist/editor-CYj5y5bp.js.map +1 -0
  33. package/dist/filters/registry.d.ts +4 -0
  34. package/dist/index-DNgtg1bF.js +28402 -0
  35. package/dist/index-DNgtg1bF.js.map +1 -0
  36. package/dist/index-nQskCfGV.cjs +342 -0
  37. package/dist/index-nQskCfGV.cjs.map +1 -0
  38. package/dist/index.d.ts +24 -0
  39. package/dist/mediables-vanilla.cjs +1 -1
  40. package/dist/mediables-vanilla.mjs +1 -1
  41. package/dist/mediables-vue.cjs +1 -1
  42. package/dist/mediables-vue.mjs +92 -74
  43. package/dist/render-page/assets/{index-ZZVWF3LA.js → index-y90zwXpc.js} +713 -531
  44. package/dist/render-page/index.html +1 -1
  45. package/dist/style.css +1 -1
  46. package/dist/types/collection.d.ts +1 -1
  47. package/dist/types/media.d.ts +26 -0
  48. package/dist/types/mediaLibraryPicker.d.ts +183 -0
  49. package/dist/types/mediaLibraryState.d.ts +29 -0
  50. package/docs/media-library-api.md +76 -0
  51. package/package.json +6 -3
  52. package/dist/editor-2Q72CZjK.js.map +0 -1
  53. package/dist/editor-DjvxEsss.cjs +0 -42
  54. package/dist/editor-DjvxEsss.cjs.map +0 -1
  55. package/dist/index-DMnweeFo.cjs +0 -342
  56. package/dist/index-DMnweeFo.cjs.map +0 -1
  57. package/dist/index-Dj_Ppp4_.js +0 -25226
  58. package/dist/index-Dj_Ppp4_.js.map +0 -1
@@ -0,0 +1,64 @@
1
+ import { type Ref } from 'vue';
2
+ import type { Media, RestoreStatus } from '../types/media';
3
+ import type { MediaLibraryHttpClient } from '../types/mediaLibraryPicker';
4
+ /**
5
+ * Phase 4 trash composable. Wraps the trash list + restore endpoints
6
+ * exposed by MediaTrashController (Phase 1B).
7
+ *
8
+ * Backend contract:
9
+ * GET /v1/user/media/trash — paginated list of trashed items
10
+ * POST /v1/user/media/{uuid}/restore — restore single item
11
+ *
12
+ * Restore handles the Round 3 collision case: if the user reuploaded the
13
+ * same file while the trashed copy was sitting in trash, the server
14
+ * returns `409 duplicate_conflict` with the duplicate UUID. The host page
15
+ * should catch that and offer the user a merge/cancel choice.
16
+ *
17
+ * SECURITY: scoping is server-side. The trash endpoint enforces
18
+ * `user_id = auth()->id()` in the package, and any host app extending this
19
+ * to admin/shared scope (e.g., cart_legacy) supplies its own httpClient
20
+ * and endpoint paths. Frontend never decides whose trash to show.
21
+ */
22
+ export interface TrashListItem extends Media {
23
+ deletion_status: 'trashed';
24
+ }
25
+ export interface TrashListResponse {
26
+ data: TrashListItem[];
27
+ meta: {
28
+ current_page: number;
29
+ per_page: number;
30
+ total: number;
31
+ };
32
+ }
33
+ export interface RestoreResult {
34
+ status: RestoreStatus;
35
+ data?: Media | null;
36
+ duplicate_uuid?: string | null;
37
+ message?: string;
38
+ }
39
+ export interface UseMediaTrashOptions {
40
+ httpClient: MediaLibraryHttpClient;
41
+ /** Endpoint paths — overridable for apps with non-default routes (e.g., admin namespace). */
42
+ listEndpoint?: string;
43
+ /** Function building the restore endpoint URL. Default: `/v1/user/media/{uuid}/restore`. */
44
+ buildRestoreEndpoint?: (uuid: string) => string;
45
+ perPage?: number;
46
+ }
47
+ export interface UseMediaTrashReturn {
48
+ items: Ref<TrashListItem[]>;
49
+ total: Ref<number>;
50
+ currentPage: Ref<number>;
51
+ isLoading: Ref<boolean>;
52
+ isRestoring: Ref<boolean>;
53
+ error: Ref<Error | null>;
54
+ fetch: (page?: number) => Promise<void>;
55
+ restore: (uuid: string) => Promise<RestoreResult>;
56
+ reset: () => void;
57
+ }
58
+ declare function buildDefaultRestoreEndpoint(uuid: string): string;
59
+ export declare function useMediaTrash(options: UseMediaTrashOptions): UseMediaTrashReturn;
60
+ export declare const __testing__: {
61
+ buildDefaultRestoreEndpoint: typeof buildDefaultRestoreEndpoint;
62
+ DEFAULT_LIST_ENDPOINT: string;
63
+ };
64
+ export {};
@@ -24,6 +24,8 @@ export interface UseMediaUploadQueueOptions {
24
24
  onUploadComplete?: (upload: UploadProgress, media: Media) => void;
25
25
  onUploadError?: (upload: UploadProgress, error: Error) => void;
26
26
  onQueueComplete?: () => void;
27
+ /** Runs after upload succeeds but before the queue marks an item completed. */
28
+ postUpload?: (upload: UploadProgress, media: Media, adapter: StorageAdapter) => Promise<void>;
27
29
  }
28
30
  /**
29
31
  * Return type for useMediaUploadQueue
@@ -0,0 +1,2 @@
1
+ "use strict";var it=Object.defineProperty;var rt=(r,e,t)=>e in r?it(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var re=(r,e,t)=>rt(r,typeof e!="symbol"?e+"":e,t);const st=require("pixi-filters"),at=require("pixi.js");function Re(r){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const i=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,i.get?i:{enumerable:!0,get:()=>r[t]})}}return e.default=r,Object.freeze(e)}const b=Re(st),R=Re(at);class W{constructor(){this._events=new Map}on(e,t){return this._events.has(e)||this._events.set(e,new Set),this._events.get(e).add(t),()=>this.off(e,t)}off(e,t){const i=this._events.get(e);i&&i.delete(t)}emit(e,...t){const i=this._events.get(e);i&&i.forEach(s=>{try{s(...t)}catch{}})}once(e,t){const i=(...s)=>{this.off(e,i),t(...s)};return this.on(e,i)}removeAllListeners(e){e?this._events.delete(e):this._events.clear()}}class nt extends W{constructor(){super(),this._state={hasImage:!1,imageUrl:null,mode:"filters",zoom:1,fitScale:1,activeFilters:new Set,filterValues:{},selectedFilter:null,selectedCategory:"adjust",crop:{shape:"free",aspect:"free",rect:null},theme:"auto",isDarkMode:!1,isSaving:!1}}get(e){if(e.includes(".")){const t=e.split(".");let i=this._state;for(const s of t){if(i==null)return;i=i[s]}return i}return this._state[e]}set(e,t){const i=this.get(e);if(e.includes(".")){const s=e.split("."),a=s.pop();let n=this._state;for(const o of s)n[o]===void 0&&(n[o]={}),n=n[o];n[a]=t}else this._state[e]=t;this.emit(`change:${e}`,{value:t,old:i}),this.emit("change",{key:e,value:t,old:i})}getAll(){return{...this._state}}getSerializableState(){const e=[];if(this._state.activeFilters)for(const i of this._state.activeFilters){const s=this._state.filterValues[i];e.push({id:i,enabled:!0,values:s?{...s}:{}})}const t=this._state.crop;return{version:1,crop:{rect:t!=null&&t.rect?{...t.rect}:null,aspectRatio:(t==null?void 0:t.aspect)||"free",shape:(t==null?void 0:t.shape)||"free"},filters:e}}toggleFilter(e,t){const i=new Set(this._state.activeFilters);t?i.add(e):(i.delete(e),delete this._state.filterValues[e]),this.set("activeFilters",i)}setFilterValue(e,t,i){this._state.filterValues[e]||(this._state.filterValues[e]={}),this._state.filterValues[e][t]=i,this.emit("change:filterValue",{filterId:e,controlId:t,value:i}),this.emit("change:filterValues",this._state.filterValues)}getFilterValues(e){return this._state.filterValues[e]||{}}initFilterValues(e,t){this._state.filterValues[e]||(this._state.filterValues[e]={}),t.forEach(i=>{i.id in this._state.filterValues[e]||(this._state.filterValues[e][i.id]=i.default)}),this.emit("change:filterValues",this._state.filterValues)}resetFilters(){this._state.activeFilters=new Set,this._state.filterValues={},this._state.selectedFilter=null,this.emit("change:activeFilters",{value:this._state.activeFilters}),this.emit("change:filterValues",this._state.filterValues),this.emit("change:selectedFilter",{value:null}),this.emit("filtersReset")}detectTheme(){if(this._state.theme==="auto"){const e=window.matchMedia("(prefers-color-scheme: dark)").matches;this.set("isDarkMode",e)}else this.set("isDarkMode",this._state.theme==="dark")}}function Te(){return new nt}class Ee extends W{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 s,a,n,o,l,c;const e=(a=(s=this.app)==null?void 0:s.renderer)==null?void 0:a.canvas,t=(e==null?void 0:e.clientWidth)??((o=(n=this.app)==null?void 0:n.screen)==null?void 0:o.width)??0,i=(e==null?void 0:e.clientHeight)??((c=(l=this.app)==null?void 0:l.screen)==null?void 0:c.height)??0;return{w:t,h:i}}render(){var e,t;try{(e=this.app)!=null&&e.renderer&&((t=this.app)!=null&&t.stage)&&this.app.renderer.render(this.app.stage)}catch{}}_waitForNextFrame(e=32){return new Promise(t=>{if(typeof window>"u"){t();return}let i=!1,s=0;const a=()=>{i||(i=!0,window.clearTimeout(s),t())};if(s=window.setTimeout(a,e),typeof window.requestAnimationFrame=="function"){window.requestAnimationFrame(()=>a());return}a()})}getFitScaleFor(e){if(!this.app||!e)return 1;const{w:t,h:i}=this._getCssSize();if(t<=1||i<=1)return 1;let s=Math.min(t/e.width,i/e.height)*.9;return(!Number.isFinite(s)||s<=0)&&(s=1),s}applyViewTransform(e={}){if(!this.app||!this.sprite||!this.originalTexture)return;const t=this.fitScale*this.zoom,{w:i,h:s}=this._getCssSize(),a=e.keepCenter?{x:this.sprite.x+this.sprite.width/2,y:this.sprite.y+this.sprite.height/2}:e.center??{x:i/2,y:s/2};this.sprite.width=this.originalTexture.width*t,this.sprite.height=this.originalTexture.height*t,this.sprite.x=a.x-this.sprite.width/2,this.sprite.y=a.y-this.sprite.height/2,this.render()}setZoom(e,t={}){this.zoom=Math.max(.1,Math.min(8,e)),this.applyViewTransform({keepCenter:t.keepCenter??!0}),this.emit("zoomChange",this.zoom)}fitToScreen(){this.originalTexture&&(this.fitScale=this.getFitScaleFor(this.originalTexture),this.setZoom(1,{keepCenter:!1}))}async mount(e,t=16777215,i={}){if(!e)return;this._container=e;const s=async()=>{var d;const a=window.PIXI;if(!a)throw new Error("PIXI.js not found. Please ensure PIXI is loaded globally.");(d=a.Assets)!=null&&d.setPreferences&&a.Assets.setPreferences({crossOrigin:"anonymous"});const n=e.clientWidth||600,o=e.clientHeight||400,l=typeof i.backgroundAlpha=="number"?i.backgroundAlpha:1;this.app=new a.Application,await this.app.init({width:n,height:o,backgroundColor:t,backgroundAlpha:l,antialias:!0,autoDensity:!0,resolution:window.devicePixelRatio||1}),e.appendChild(this.app.canvas);const c=this.app.canvas;c.classList.add("pixi-canvas"),c.style.width="100%",c.style.height="100%",c.style.transform="translateZ(0)",c.style.willChange="transform",c.setAttribute("role","img"),c.setAttribute("aria-label","Image editor canvas — use toolbar controls to edit the image"),this.emit("mounted",{width:n,height:o})};this._mountPromise=s(),await this._mountPromise}async loadTexture(e){var l,c,d;if(this._mountPromise&&await this._mountPromise,!((l=this.app)!=null&&l.renderer))return!1;const t=window.PIXI,i=await this._loadImageElement(e);if(!i||!((c=this.app)!=null&&c.renderer))return!1;const s=t.Texture.from(i);if(!s)return!1;this.originalTexture=s,this.baseTexture=s,this.sprite&&(this.app.stage.removeChild(this.sprite),this.sprite.destroy()),this.sprite=new t.Sprite(s),this.app.stage.addChild(this.sprite),this.fitScale=this.getFitScaleFor(s),this.zoom=1;const{w:a,h:n}=this._getCssSize();if(this.applyViewTransform({center:{x:a/2,y:n/2}}),await this._waitForNextFrame(),!((d=this.app)!=null&&d.renderer))return!1;const o=this.getFitScaleFor(s);return Math.abs(o-this.fitScale)/Math.max(1e-6,o)>.02&&(this.fitScale=o,this.applyViewTransform({center:{x:a/2,y:n/2}})),this.render(),this.emit("textureLoaded",{width:s.width,height:s.height}),!0}exportImage(e="png",t=.92,i=0,s=!0,a=0){var T;if(!((T=this.app)!=null&&T.renderer)||!this.originalTexture||!this.sprite)return null;const n=window.PIXI,o=Math.round(this.originalTexture.width),l=Math.round(this.originalTexture.height);if(o<=0||l<=0)return null;const c=this.sprite.width,d=this.sprite.height;if(c<=0||d<=0)return null;const h=c/o,u=h>0?1/h:1,f=[];if(Array.isArray(this.sprite.filters)){for(const y of this.sprite.filters)if(y)if(typeof y.createExportFilter=="function"){const C=y.createExportFilter({previewToNativeScale:u});C&&f.push(C)}else f.push(y)}let _=0;for(const y of f){const C=typeof y.getExportPadding=="function"?Number(y.getExportPadding())||0:typeof y._exportPadding=="number"?y._exportPadding:typeof y.padding=="number"?y.padding:0;C>0&&(_+=C)}const g=Math.max(Math.ceil(_),64),x=y=>{var k,w;const C=Math.ceil(o+2*y),v=Math.ceil(l+2*y),M=new n.Container,F=new n.Sprite(this.originalTexture);F.x=y,F.y=y,F.scale.set(1,1),f.length>0&&(F.filters=f,F.filterArea=new n.Rectangle(0,0,o,l)),M.addChild(F);const I=n.RenderTexture.create({width:C,height:v,resolution:1});try{this.app.renderer.render({container:M,target:I,clear:!0,clearColor:[0,0,0,0]});const S=(w=(k=this.app.renderer.extract)==null?void 0:k.canvas)==null?void 0:w.call(k,I);return S?{canvas:S,width:C,height:v,margin:y}:null}finally{F.filters=null,M.removeChildren(),F.destroy({children:!1,texture:!1,textureSource:!1}),M.destroy({children:!1}),I.destroy(!0)}},A=(y,C,v)=>{const M=typeof y.getContext=="function"?y.getContext("2d"):null;if(!M)return null;let F;try{F=M.getImageData(0,0,C,v).data}catch{return null}const I=1;let k=C,w=v,S=-1,G=-1;const ge=4,Ke=C*ge;for(let Y=0;Y<v;Y++){const tt=Y*Ke;for(let D=0;D<C;D++)F[tt+D*ge+3]>=I&&(D<k&&(k=D),D>S&&(S=D),Y<w&&(w=Y),Y>G&&(G=Y))}if(S<0)return null;const Qe=S-k+1,Je=G-w+1,et=k===0||w===0||S===C-1||G===v-1;return{x:k,y:w,width:Qe,height:Je,touchesEdge:et}};let P=null;try{let y=x(g);if(!y)return null;let C=A(y.canvas,y.width,y.height);if(!C)return null;if(C.touchesEdge&&g<o&&g<l){const k=Math.max(g*4,256),w=x(k);if(w){const S=A(w.canvas,w.width,w.height);S&&!S.touchesEdge?(y=w,C=S):(y=w,C=S??C)}}let v=C.width,M=C.height;if(i>0){const k=Math.max(v,M);let w=i/k;s&&(w=Math.min(1,w)),v=Math.max(1,Math.round(v*w)),M=Math.max(1,Math.round(M*w))}if(a>0&&v*M>a){const k=Math.sqrt(a/(v*M));v=Math.max(1,Math.floor(v*k)),M=Math.max(1,Math.floor(M*k))}const F=document.createElement("canvas");F.width=v,F.height=M;const I=F.getContext("2d");return I?(I.drawImage(y.canvas,C.x,C.y,C.width,C.height,0,0,v,M),P=F.toDataURL(`image/${e}`,t),this._lastExportDimensions={width:v,height:M},P||null):null}catch{return null}}getExportDimensions(){var n;if(this._lastExportDimensions)return{...this._lastExportDimensions};const e=this.originalTexture,t=Math.round((e==null?void 0:e.width)||0),i=Math.round((e==null?void 0:e.height)||0);let s=0;const a=(n=this.sprite)==null?void 0:n.filters;if(Array.isArray(a))for(const o of a){if(!o)continue;const l=typeof o._exportPadding=="number"?o._exportPadding:typeof o.padding=="number"?o.padding:0;l>s&&(s=l)}return{width:t+2*s,height:i+2*s}}async exportBlob(e="png",t=.92){const i=this.exportImage(e,t);if(!i)return null;const a=await(await fetch(i)).blob(),n=this.getExportDimensions();return{blob:a,width:n.width,height:n.height}}resizeTo(e){var s;if(!((s=this.app)!=null&&s.renderer)||!e)return;const t=e.clientWidth,i=e.clientHeight;if(!(t===Math.round(this.app.screen.width)&&i===Math.round(this.app.screen.height))&&!(t<=0||i<=0)&&(this.app.renderer.resize(t,i),this.originalTexture&&this.sprite)){const a={x:this.sprite.x+this.sprite.width/2,y:this.sprite.y+this.sprite.height/2};this.fitScale=this.getFitScaleFor(this.originalTexture),this.applyViewTransform({center:a})}}setBackgroundColor(e){var t,i;(i=(t=this.app)==null?void 0:t.renderer)!=null&&i.background&&(this.app.renderer.background.color=e)}_loadImageElement(e){return new Promise(t=>{const i=new Image;typeof e=="string"&&/^https?:\/\//.test(e)&&(i.crossOrigin="anonymous"),i.onload=()=>t(i),i.onerror=()=>{t(null)},i.src=e})}destroy(){if(this._mountPromise=null,this.app){try{this.app.destroy(!0,{children:!0,texture:!0})}catch{}this.app=null}this.sprite=null,this.originalTexture=null,this.baseTexture=null,this._container=null,this.removeAllListeners()}}const ce='<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>',he='<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>',ot='<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>',lt='<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>',ct='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M432 320v112H320M80 192V80h112M320 80h112v112M192 432H80V320"/></svg>',ht='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="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>',dt='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="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>',ut='<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>',pt='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="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>',ft='<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>',mt='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="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>',Ie='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="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>',gt='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="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>',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="M368 368L144 144M368 144L144 368"/></svg>',Xe='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="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>',bt='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="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>',yt='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="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>',_t='<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>',xt='<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>',Ct='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M80 96h64l64 320h64l64-160h96"/></svg>',be='<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>',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="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>',wt='<svg viewBox="0 0 512 512" width="20" height="20"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="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>',ie=[{id:"adjust",name:"Adjust",icon:ht,registryCategories:["adjust","advanced"]},{id:"blur",name:"Blur",icon:dt,registryCategories:["blur"]},{id:"color",name:"Color",icon:ut,registryCategories:["color"]},{id:"effects",name:"Effects",icon:pt,registryCategories:["effects"]},{id:"distortion",name:"Distortion",icon:ft,registryCategories:["distortion"]},{id:"light",name:"Light",icon:mt,registryCategories:["light"]},{id:"stylize",name:"Stylize",icon:wt,registryCategories:["stylize"]},{id:"crop",name:"Crop",icon:Ie}],St=Object.fromEntries(ie.filter(r=>Array.isArray(r.registryCategories)&&r.registryCategories.length>0).map(r=>[r.id,r.registryCategories])),Be=Object.fromEntries(ie.filter(r=>Array.isArray(r.registryCategories)).flatMap(r=>r.registryCategories.map(e=>[e,r.id])));function vt(r){return St[r]||[r]}class Oe extends W{constructor(e,t){super(),this.state=e,this.renderer=t,this.instances={},this._filterRegistry=null}setRegistry(e){this._filterRegistry=e}getFilterDef(e){return this._filterRegistry?this._filterRegistry.getFilter(e):null}getAllFilters(){var e;return((e=this._filterRegistry)==null?void 0:e.getAllFilters())||[]}getFiltersByCategory(e){if(!this._filterRegistry)return[];const t=vt(e),i=[],s=new Set;for(const a of t){const n=this._filterRegistry.getFiltersByCategory(a)||[];for(const o of n)s.has(o.id)||(s.add(o.id),i.push(o))}return i}_normalizeValue(e){return Array.isArray(e)?e.length>0&&typeof e[0]=="object"?e:Number(e[0]??0):typeof e=="string"?e.startsWith("#")?e:e.trim()===""?0:Number(e):e}_getDeepProp(e,t){if(!e||!t)return;if(!t.includes(".")&&!t.includes("["))return e[t];const i=t.replace(/\[(\d+)\]/g,".$1").split(".").filter(Boolean);let s=e;for(const a of i){if(s==null)return;s=s[a]}return s}_setDeepProp(e,t,i){if(!e||!t)return;if(!t.includes(".")&&!t.includes("[")){e[t]=i;return}const s=t.replace(/\[(\d+)\]/g,".$1").split(".").filter(Boolean);let a=e;for(let o=0;o<s.length-1;o++){const l=s[o];if(!(l in a)||(a=a[l],a==null))return}const n=s[s.length-1];a[n]=i}initializeValues(e){const t=this.getFilterDef(e);if(!t)return;const i=this.state.getFilterValues(e),s=new Set((t.controls||[]).map(a=>a.id));if(t.defaultParams)for(const[a,n]of Object.entries(t.defaultParams))!s.has(a)&&!(a in i)&&this.state.setFilterValue(e,a,n);t.controls&&t.controls.forEach(a=>{a.id in i||this.state.setFilterValue(e,a.id,a.default)})}resetValues(e){const t=this.getFilterDef(e);if(!t)return;const i=new Set((t.controls||[]).map(s=>s.id));if(t.defaultParams)for(const[s,a]of Object.entries(t.defaultParams))i.has(s)||this.state.setFilterValue(e,s,a);t.controls&&t.controls.forEach(s=>{this.state.setFilterValue(e,s.id,s.default)})}toggle(e,t){this.state.toggleFilter(e,t),t?this.initializeValues(e):delete this.instances[e],this.applyFilters(),this.emit("filterToggled",{filterId:e,enabled:t})}updateValue(e,t,i){const s=this._normalizeValue(i),a=this.getFilterDef(e),n=a==null?void 0:a.controls.find(h=>h.id===t),o=!n&&(t.includes("[")||t.includes("."));o||this.state.setFilterValue(e,t,s);const l=this.instances[e];if(!l)return!1;const c=(n==null?void 0:n.property)||t;if(typeof l.updateUIParam=="function"){if(l.updateUIParam(c,s),o&&typeof l.getSerializableParams=="function"){const h=l.getSerializableParams();for(const[u,f]of Object.entries(h))this.state.setFilterValue(e,u,f)}return!0}const d=this._getDeepProp(l,c);return typeof d=="function"?!1:l.uniforms&&c in l.uniforms?(l.uniforms[c]=s,!0):d!==void 0?(this._setDeepProp(l,c,s),!0):!1}performFilterAction(e,t){const i=this.instances[e];if(!(!i||typeof i.updateUIParam!="function")){if(i.updateUIParam(t,!0),typeof i.getSerializableParams=="function"){const s=i.getSerializableParams();for(const[a,n]of Object.entries(s))this.state.setFilterValue(e,a,n)}this.applyFilters(),this.emit("filterActionPerformed",{filterId:e,action:t})}}applyFilters(){const e=this.renderer.sprite;if(!e)return;for(const a in this.instances)delete this.instances[a];const t=[],i=[];this.state.get("activeFilters").forEach(a=>{try{const n=this.getFilterDef(a);if(!n||!n.createFilter||typeof n.createFilter!="function")return;const o=this.state.getFilterValues(a),l=n.defaultParams?{...n.defaultParams}:{};n.controls&&Array.isArray(n.controls)&&n.controls.forEach(f=>{const _=f.property||f.id;l[_]=o[f.id]??f.default});const c=new Set((n.controls||[]).map(f=>f.id));for(const[f,_]of Object.entries(o))c.has(f)||(l[f]=_);const d=this.renderer.sprite,h=this.renderer.originalTexture;l._sourceWidth=Math.round((h==null?void 0:h.width)||(d==null?void 0:d.width)||0),l._sourceHeight=Math.round((h==null?void 0:h.height)||(d==null?void 0:d.height)||0);const u=n.createFilter(l);u&&(t.push(u),this.instances[a]=u)}catch{i.push(a)}});try{e.filters=null,e.filters=t.length?t:null,this.renderer.render(),this.emit("filtersApplied",{count:t.length,failed:i})}catch(a){try{e.filters=null,this.renderer.render()}catch{}this.emit("filtersError",{error:a,failedFilters:i})}i.length>0}resetAll(){for(const e in this.instances)delete this.instances[e];this.state.resetFilters(),this.renderer.sprite&&(this.renderer.sprite.filters=null),this.renderer.render(),this.emit("filtersReset")}getInstance(e){return this.instances[e]||null}}const U=class U extends W{constructor(e,t){super(),this.state=e,this.renderer=t,this._overlayCanvas=null,this._isDragging=!1,this._dragStart=null,this._dragMode=null,this._startRect=null,this._hoverMode=null,this._lastAutoZoomCheck=0,this.HANDLE_SIZE=14,this.EDGE_HIT_PAD=10,this._onPointerDown=this._handlePointerDown.bind(this),this._onPointerMove=this._handlePointerMove.bind(this),this._onPointerUp=this._handlePointerUp.bind(this)}setOverlayCanvas(e){this._overlayCanvas=e}_getAspectRatio(e){if(!e||e==="free")return null;const t={"1:1":1,"4:3":4/3,"16:9":16/9,"3:2":3/2,"2:3":2/3};if(t[e]!==void 0)return t[e];const i=e.split(":");if(i.length===2){const s=parseFloat(i[0]),a=parseFloat(i[1]);if(Number.isFinite(s)&&Number.isFinite(a)&&a>0)return s/a}return null}applyAspectRatio(){const e=this.state.get("crop.rect"),t=this.state.get("crop.aspect");if(!e||t==="free")return;const i=this._getAspectRatio(t);if(!i)return;const s=e.width/e.height;Math.abs(s-i)<.01||(s>i?e.width=e.height*i:e.height=e.width/i,this.state.set("crop.rect",e))}constrainCropRect(){const e=this.state.get("crop.rect");if(!e)return;const t=this.renderer.sprite,i=this.renderer.app;if(!t||!i)return;const s=this.state.get("crop.shape"),a={x:0,y:0,w:i.screen.width,h:i.screen.height};if(e.x=Math.max(a.x,Math.min(e.x,a.x+a.w-e.width)),e.y=Math.max(a.y,Math.min(e.y,a.y+a.h-e.height)),e.width=Math.min(e.width,a.w),e.height=Math.min(e.height,a.h),s!=="free"||this.state.get("crop.aspect")==="1:1"){const n=Math.min(e.width,e.height);e.width=n,e.height=n}this.state.set("crop.rect",e)}static calcAutoZoom(e,t,i,s,a,n,o){if(!e||!s||!a||!n)return null;const l=e.width>t,c=e.height>i;if(!l&&!c)return null;const d=U.AUTO_ZOOM_PADDING;let h=o;if(l){const u=e.width/(d*s*n);h=Math.min(h,u)}if(c){const u=e.height/(d*a*n);h=Math.min(h,u)}return h=Math.max(.1,h),h>=o-.01?null:h}_checkAutoZoom(){if(!this.state.get("autoZoomOnCropOverflow"))return;const e=Date.now();if(e-this._lastAutoZoomCheck<U.AUTO_ZOOM_THROTTLE_MS)return;this._lastAutoZoomCheck=e;const t=this.state.get("crop.rect"),i=this.renderer.sprite,s=this.renderer.originalTexture;if(!t||!i||!s)return;const a=U.calcAutoZoom(t,i.width,i.height,s.width,s.height,this.renderer.fitScale,this.renderer.zoom);a!==null&&this.renderer.setZoom(a,{keepCenter:!0})}drawOverlay(){const e=this._overlayCanvas;if(!e)return;const t=this.renderer.app;if(!t)return;const i=t.canvas,s=i.clientWidth,a=i.clientHeight,n=window.devicePixelRatio||1;(e.width!==Math.max(1,Math.floor(s*n))||e.height!==Math.max(1,Math.floor(a*n)))&&(e.width=Math.max(1,Math.floor(s*n)),e.height=Math.max(1,Math.floor(a*n)),e.style.width=s+"px",e.style.height=a+"px");const o=e.getContext("2d");if(!o)return;o.setTransform(n,0,0,n,0,0),o.clearRect(0,0,s,a),o.fillStyle="rgba(0, 0, 0, 0.5)",o.fillRect(0,0,s,a);const l=this.state.get("crop.rect");if(!l)return;const c=this.state.get("crop.shape");if(o.save(),c==="circle"){const x=l.x+l.width/2,A=l.y+l.height/2,P=Math.min(l.width,l.height)/2;o.beginPath(),o.arc(x,A,P,0,Math.PI*2),o.clip()}else o.beginPath(),o.rect(l.x,l.y,l.width,l.height),o.clip();o.clearRect(l.x,l.y,l.width,l.height),o.restore(),o.strokeStyle="#ffffff",o.lineWidth=2,o.setLineDash([5,5]),c==="circle"?(o.beginPath(),o.arc(l.x+l.width/2,l.y+l.height/2,Math.min(l.width,l.height)/2,0,Math.PI*2),o.stroke()):o.strokeRect(l.x,l.y,l.width,l.height),o.setLineDash([]),o.strokeStyle="rgba(255,255,255,0.3)",o.lineWidth=1;const d=l.width/3,h=l.height/3;for(let x=1;x<=2;x++)o.beginPath(),o.moveTo(l.x+d*x,l.y),o.lineTo(l.x+d*x,l.y+l.height),o.stroke(),o.beginPath(),o.moveTo(l.x,l.y+h*x),o.lineTo(l.x+l.width,l.y+h*x),o.stroke();const u=this.HANDLE_SIZE,f=[{x:l.x,y:l.y,m:"resize-nw"},{x:l.x+l.width,y:l.y,m:"resize-ne"},{x:l.x,y:l.y+l.height,m:"resize-sw"},{x:l.x+l.width,y:l.y+l.height,m:"resize-se"}],_=[{x:l.x+l.width/2,y:l.y,m:"n"},{x:l.x+l.width/2,y:l.y+l.height,m:"s"},{x:l.x,y:l.y+l.height/2,m:"w"},{x:l.x+l.width,y:l.y+l.height/2,m:"e"}],g=[...f,..._];for(const x of g){const A=this._hoverMode===x.m,P=A?u+4:u;o.beginPath(),o.rect(x.x-P/2,x.y-P/2,P,P),o.fillStyle=A?"#4da3ff":"#ffffff",o.strokeStyle="rgba(0,0,0,0.6)",o.lineWidth=1,o.fill(),o.stroke()}}_hitHandle(e,t){const i=this.state.get("crop.rect");if(!i)return null;const s=(a,n,o,l,c)=>Math.abs(a-o)<=c&&Math.abs(n-l)<=c;return s(e,t,i.x,i.y,this.HANDLE_SIZE)?"resize-nw":s(e,t,i.x+i.width,i.y,this.HANDLE_SIZE)?"resize-ne":s(e,t,i.x,i.y+i.height,this.HANDLE_SIZE)?"resize-sw":s(e,t,i.x+i.width,i.y+i.height,this.HANDLE_SIZE)?"resize-se":Math.abs(t-i.y)<=this.EDGE_HIT_PAD&&e>=i.x&&e<=i.x+i.width?"n":Math.abs(t-(i.y+i.height))<=this.EDGE_HIT_PAD&&e>=i.x&&e<=i.x+i.width?"s":Math.abs(e-i.x)<=this.EDGE_HIT_PAD&&t>=i.y&&t<=i.y+i.height?"w":Math.abs(e-(i.x+i.width))<=this.EDGE_HIT_PAD&&t>=i.y&&t<=i.y+i.height?"e":e>=i.x&&e<=i.x+i.width&&t>=i.y&&t<=i.y+i.height?"move":null}_handlePointerDown(e){const t=this.state.get("crop.rect");if(!t)return;const i=e.global;this._dragMode=this._hitHandle(i.x,i.y),this._dragMode&&(this._isDragging=!0,this._dragStart={x:i.x,y:i.y},this._startRect={...t},this._lastAutoZoomCheck=0)}_handlePointerMove(e){var l,c,d,h;const t=this.renderer.app;if(!t)return;const i=e.global;if(!this._isDragging||!this._dragStart||!this._startRect){this._hoverMode=this._hitHandle(i.x,i.y),t.stage.cursor=this._hoverMode==="move"?"move":this._hoverMode==="n"||this._hoverMode==="s"?"ns-resize":this._hoverMode==="e"||this._hoverMode==="w"?"ew-resize":(l=this._hoverMode)!=null&&l.endsWith("nw")||(c=this._hoverMode)!=null&&c.endsWith("se")?"nwse-resize":(d=this._hoverMode)!=null&&d.endsWith("ne")||(h=this._hoverMode)!=null&&h.endsWith("sw")?"nesw-resize":"crosshair",this.drawOverlay();return}const s=this.state.get("crop.rect");if(!s)return;const a=i.x-this._dragStart.x,n=i.y-this._dragStart.y;switch(this._dragMode){case"move":s.x=this._startRect.x+a,s.y=this._startRect.y+n;break;case"n":s.y=this._startRect.y+n,s.height=this._startRect.height-n;break;case"s":s.height=this._startRect.height+n;break;case"w":s.x=this._startRect.x+a,s.width=this._startRect.width-a;break;case"e":s.width=this._startRect.width+a;break;case"resize-nw":s.x=this._startRect.x+a,s.y=this._startRect.y+n,s.width=this._startRect.width-a,s.height=this._startRect.height-n;break;case"resize-ne":s.y=this._startRect.y+n,s.width=this._startRect.width+a,s.height=this._startRect.height-n;break;case"resize-sw":s.x=this._startRect.x+a,s.width=this._startRect.width-a,s.height=this._startRect.height+n;break;case"resize-se":s.width=this._startRect.width+a,s.height=this._startRect.height+n;break}s.width=Math.max(50,s.width),s.height=Math.max(50,s.height),this.state.set("crop.rect",s),this.state.get("crop.shape")==="circle"&&this.state.get("crop.aspect")!=="1:1"&&this.state.set("crop.aspect","1:1"),this.applyAspectRatio(),this._dragMode!=="move"&&this._checkAutoZoom(),this.constrainCropRect(),this.drawOverlay()}_handlePointerUp(){this._isDragging=!1,this._dragMode=null,this._dragStart=null,this._startRect=null}enable(){const e=this.renderer.app,t=this.renderer.sprite;if(!e||!t)return;let i=this.state.get("crop.rect");if(!i){this.state.get("crop.shape")==="circle"&&this.state.set("crop.aspect","1:1");const n=this.state.get("crop.aspect"),o=this._getAspectRatio(n);let l,c;if(o){const u=t.width*.9,f=t.height*.9;u/f>o?(c=f,l=c*o):(l=u,c=l/o)}else{const u=Math.min(e.screen.width,e.screen.height)*.7;l=u,c=u}const d=t.x+(t.width-l)/2,h=t.y+(t.height-c)/2;i={x:d,y:h,width:l,height:c},this.state.set("crop.rect",i),n!=="free"&&this.constrainCropRect()}const s=e.stage;s.eventMode="static",s.hitArea=e.screen,s.cursor="crosshair",s.on("pointerdown",this._onPointerDown),s.on("pointermove",this._onPointerMove),s.on("pointerup",this._onPointerUp),s.on("pointerupoutside",this._onPointerUp),this.state.set("mode","crop"),this.drawOverlay(),this.emit("enabled")}disable(){const e=this.renderer.app;if(!e)return;const t=e.stage;if(t.off("pointerdown",this._onPointerDown),t.off("pointermove",this._onPointerMove),t.off("pointerup",this._onPointerUp),t.off("pointerupoutside",this._onPointerUp),t.eventMode="auto",t.cursor="default",this.state.set("crop.rect",null),this._overlayCanvas){const i=this._overlayCanvas.getContext("2d");i==null||i.clearRect(0,0,this._overlayCanvas.width,this._overlayCanvas.height)}this.state.set("mode","filters"),this.emit("disabled")}apply(){const e=this.renderer.app,t=this.renderer.sprite,i=this.renderer.originalTexture,s=this.state.get("crop.rect");if(!s||!t||!e||!i)return null;const a=window.PIXI,n=this.renderer.zoom,o=i.width/t.width,l=i.height/t.height,c=(s.x-t.x)*o,d=(s.y-t.y)*l;let h=Math.round(Math.max(1,s.width*o)),u=Math.round(Math.max(1,s.height*l)),f=Math.round(c),_=Math.round(d);if(h<=0||u<=0)return null;const g=new a.Container,x=new a.Sprite(i);if(this.state.get("crop.shape")==="circle"){const I=Math.round(Math.max(h,u)),k=f+h/2,w=_+u/2;f=Math.round(k-I/2),_=Math.round(w-I/2),h=u=I;const S=new a.Graphics;typeof S.circle=="function"&&typeof S.fill=="function"?S.circle(h/2,u/2,h/2).fill(16777215):(S.beginFill(16777215,1),S.drawCircle(h/2,u/2,h/2),S.endFill()),x.mask=S,g.addChild(S)}x.x=-f,x.y=-_,g.addChild(x);const P=a.RenderTexture.create({width:h,height:u});e.renderer.render({container:g,target:P,clear:!0}),g.destroy({children:!0});const T=this.renderer.originalTexture;T&&T!==this.renderer.baseTexture&&T.destroy(!0),this.renderer.originalTexture=P,e.stage.removeChild(t),t.destroy();const N=new a.Sprite(P);e.stage.addChild(N),this.renderer.sprite=N,this.renderer.fitScale=this.renderer.getFitScaleFor(P),this.renderer.setZoom(n,{keepCenter:!1}),this.renderer.applyViewTransform(),this.renderer.render();const y=this.state.get("crop.appliedRect"),v=y&&Number.isFinite(y.x)&&Number.isFinite(y.y)&&Number.isFinite(y.width)&&Number.isFinite(y.height)?{x:Math.round(y.x+f),y:Math.round(y.y+_),width:h,height:u}:{x:f,y:_,width:h,height:u},M=this.state.get("crop.shape")||"free",F=this.state.get("crop.aspect")||"free";return this.disable(),this.state.set("crop.appliedRect",v),this.state.set("crop.appliedShape",M),this.state.set("crop.appliedAspect",F),this.emit("applied",{width:h,height:u}),{texture:P,preservedZoom:n}}applyFromPixelRect(e,t="free"){const i=this.renderer.app,s=this.renderer.sprite,a=this.renderer.originalTexture;if(!e||!s||!i||!a)return null;const n=window.PIXI,o=this.renderer.zoom;let l=Math.round(Math.max(1,e.width)),c=Math.round(Math.max(1,e.height)),d=Math.round(e.x),h=Math.round(e.y);if(l<=0||c<=0)return null;const u=new n.Container,f=new n.Sprite(a);if(t==="circle"){const A=Math.round(Math.max(l,c)),P=d+l/2,T=h+c/2;d=Math.round(P-A/2),h=Math.round(T-A/2),l=c=A;const N=new n.Graphics;typeof N.circle=="function"&&typeof N.fill=="function"?N.circle(l/2,c/2,l/2).fill(16777215):(N.beginFill(16777215,1),N.drawCircle(l/2,c/2,l/2),N.endFill()),f.mask=N,u.addChild(N)}f.x=-d,f.y=-h,u.addChild(f);const _=n.RenderTexture.create({width:l,height:c});i.renderer.render({container:u,target:_,clear:!0}),u.destroy({children:!0});const g=this.renderer.originalTexture;g&&g!==this.renderer.baseTexture&&g.destroy(!0),this.renderer.originalTexture=_,i.stage.removeChild(s),s.destroy();const x=new n.Sprite(_);return i.stage.addChild(x),this.renderer.sprite=x,this.renderer.fitScale=this.renderer.getFitScaleFor(_),this.renderer.setZoom(o,{keepCenter:!1}),this.renderer.applyViewTransform(),this.renderer.render(),{texture:_,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){if(this.state.get("lockAspectRatio"))return;if(this.state.get("crop.shape")!=="free"){if(this.state.get("lockCropShape"))return;this.state.set("crop.shape","free")}this.state.set("crop.aspect",e),this.applyAspectRatio(),this.constrainCropRect(),this.drawOverlay()}};re(U,"AUTO_ZOOM_PADDING",1.1),re(U,"AUTO_ZOOM_THROTTLE_MS",100);let ee=U;class Ye{constructor(e={}){this._endpoint=e.endpoint||"/api/v1/media/remove-bg",this._fallbackEndpoint=e.fallbackEndpoint||null}async removeBackground(e,t={}){const i=typeof e=="string"?await this._dataUrlToBlob(e):e,s=new FormData;s.append("file",i,"image.png"),s.append("tier",t.tier||"balanced"),t.model&&s.append("model",t.model),t.alpha_matting&&(s.append("alpha_matting","true"),s.append("alpha_f",String(t.alpha_f??10)),s.append("alpha_fr",String(t.alpha_fr??15)),s.append("alpha_erode_size",String(t.alpha_erode_size??10)));let a,n;try{a=await fetch(this._endpoint,{method:"POST",body:s,credentials:"include"})}catch(c){n=c}if((!a||!a.ok)&&this._fallbackEndpoint)try{a=await fetch(this._fallbackEndpoint,{method:"POST",body:s})}catch(c){n||(n=c)}if(!a)throw n||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 o=await a.blob();return{dataUrl:await this._blobToDataUrl(o),model:a.headers.get("X-Model-Used")||"unknown",processMs:a.headers.get("X-Process-Ms")||"0"}}async _dataUrlToBlob(e){if(e.startsWith("data:")){const[i,s]=e.split(","),a=i.match(/:(.*?);/),n=a?a[1]:"image/png",o=atob(s),l=new Uint8Array(o.length);for(let c=0;c<o.length;c++)l[c]=o.charCodeAt(c);return new Blob([l],{type:n})}return(await fetch(e)).blob()}_blobToDataUrl(e){return new Promise((t,i)=>{const s=new FileReader;s.onload=()=>t(s.result),s.onerror=()=>i(new Error("Failed to read blob as data URL")),s.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 p(r,e={},...t){const i=document.createElement(r);for(const[s,a]of Object.entries(e))if(a!=null)if(s==="className")i.className=a;else if(s==="style"&&typeof a=="object")Object.assign(i.style,a);else if(s.startsWith("on")&&typeof a=="function"){const n=s.slice(2).toLowerCase();i.addEventListener(n,a)}else s==="dataset"&&typeof a=="object"?Object.assign(i.dataset,a):i.setAttribute(s,a);for(const s of t)typeof s=="string"?i.appendChild(document.createTextNode(s)):s instanceof HTMLElement&&i.appendChild(s);return i}function de({id:r,label:e,min:t=0,max:i=1,step:s=.01,value:a=.5,onChange:n}){const o=r.includes("-")?r.split("-").slice(1).join("-"):r,l=p("div",{className:"slider-control slider-wrapper","data-control":o,"data-testid":`slider-${o}`}),c=p("div",{className:"slider-header"},p("label",{for:r,className:"slider-label"},e),p("span",{className:"slider-value",id:`${r}-value`},se(a))),d=p("input",{type:"range",id:r,className:"slider-input",min:String(t),max:String(i),step:String(s),value:String(a),onInput:h=>{const u=parseFloat(h.target.value),f=l.querySelector(".slider-value");f&&(f.textContent=se(u)),n==null||n(u)}});return l.appendChild(c),l.appendChild(d),l.setValue=h=>{d.value=String(h);const u=l.querySelector(".slider-value");u&&(u.textContent=se(h))},l}function se(r){return Number.isInteger(r)?String(r):r.toFixed(2)}function ue({id:r,label:e,checked:t=!1,onChange:i}){const s=p("div",{className:"toggle-control"}),a=p("label",{className:"toggle-label",for:r},e),n=p("input",{type:"checkbox",id:r,className:"toggle-input",checked:t?"checked":void 0,onChange:c=>i==null?void 0:i(c.target.checked)}),o=p("div",{className:"toggle-switch",onClick:c=>{c.target!==n&&(n.checked=!n.checked,i==null||i(n.checked))}}),l=p("span",{className:"toggle-slider"});return o.appendChild(n),o.appendChild(l),s.appendChild(a),s.appendChild(o),s.setChecked=c=>{n.checked=c},s}function pe({id:r,label:e,value:t="#000000",onChange:i}){const s=p("div",{className:"color-control"}),a=p("label",{className:"color-label",for:r},e),n=p("input",{type:"color",id:r,className:"color-input",value:t,onInput:o=>i==null?void 0:i(o.target.value)});return s.appendChild(a),s.appendChild(n),s.setValue=o=>{n.value=o},s}function fe({id:r,label:e,value:t="",placeholder:i="",onCommit:s}){const a=p("div",{className:"text-control","data-control":r,"data-testid":`text-${r}`}),n=p("label",{className:"text-label",for:r},e);let o=t;const l=p("input",{type:"text",id:r,className:"text-input",value:t,placeholder:i,onKeyDown:d=>{d.key==="Enter"&&(d.preventDefault(),c(),l.blur())},onBlur:()=>c()});function c(){const d=l.value;d!==o&&(o=d,s==null||s(d))}return a.appendChild(n),a.appendChild(l),a.setValue=d=>{const h=d==null?"":String(d);l.value=h,o=h},a}function me({id:r,label:e,options:t=[],value:i,onChange:s}){const a=p("div",{className:"select-control"}),n=p("label",{className:"select-label",for:r},e),o=p("select",{id:r,className:"select-input",onChange:l=>s==null?void 0:s(l.target.value)});for(const l of t){const c=p("option",{value:l.value},l.label);l.value===i&&(c.selected=!0),o.appendChild(c)}return a.appendChild(n),a.appendChild(o),a.setValue=l=>{o.value=l},a}function O({label:r,className:e="",onClick:t,icon:i=null,disabled:s=!1}){const a=p("button",{type:"button",className:`btn ${e}`.trim(),onClick:t,disabled:s?"disabled":void 0});if(i){const n=p("span",{className:"btn-icon"});n.innerHTML=i;const o=n.querySelector("svg");o&&o.setAttribute("aria-hidden","true"),a.appendChild(n)}return r&&a.appendChild(document.createTextNode(r)),a}function z({icon:r,title:e,className:t="",onClick:i,disabled:s=!1,testId:a=null,ariaLabel:n=null}){const o={type:"button",className:`icon-btn ${t}`.trim(),title:e,"aria-label":n||e,onClick:i,disabled:s?"disabled":void 0};a&&(o.dataset={testid:a});const l=p("button",o);l.innerHTML=r;const c=l.querySelector("svg");return c&&c.setAttribute("aria-hidden","true"),l}function le({label:r,icon:e,active:t=!1,onClick:i}){const s=p("button",{type:"button",className:`chip ${t?"active":""}`.trim(),onClick:i});if(e){const a=p("span",{className:"chip-icon"});a.innerHTML=e;const n=a.querySelector("svg");n&&n.setAttribute("aria-hidden","true"),s.appendChild(a)}return s.appendChild(p("span",{className:"chip-label"},r)),s.setActive=a=>{s.classList.toggle("active",a)},s}class De{constructor(e,t){this.state=e,this.editor=t,this.element=null,this._unsubscribers=[]}render(){this.element=p("div",{className:"editor-toolbar"});const e=p("div",{className:"toolbar-section toolbar-left"}),t=z({icon:yt,title:"Open Image",className:"toolbar-btn",testId:"btn-open-image",ariaLabel:"Open image file",onClick:()=>this.editor.openFilePicker()});e.appendChild(t);const i=p("div",{className:"toolbar-section toolbar-center"}),s=z({icon:lt,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=p("span",{className:"zoom-label","aria-live":"polite","aria-atomic":"true",role:"status"},"100%");const a=z({icon:ot,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)}}),n=z({icon:ct,title:"Fit to Screen",className:"toolbar-btn",testId:"btn-fit-screen",ariaLabel:"Fit to screen",onClick:()=>this.editor.fitToScreen()});i.appendChild(s),i.appendChild(this._zoomLabel),i.appendChild(a),i.appendChild(n);const o=p("div",{className:"toolbar-section toolbar-right"});this._themeBtn=z({icon:this.state.get("isDarkMode")?be:ye,title:"Toggle Theme",className:"toolbar-btn toolbar-btn-theme",testId:"btn-toggle-theme",ariaLabel:"Toggle theme",onClick:()=>this.editor.toggleTheme()}),this._cropBtn=z({icon:Ie,title:"Crop",className:"toolbar-btn toolbar-btn-crop",testId:"btn-crop",ariaLabel:"Crop image",onClick:()=>{this.state.get("mode")==="crop"?this.editor.setMode("filters"):this.editor.setMode("crop")}});const l=z({icon:Xe,title:"Reset All",className:"toolbar-btn",testId:"btn-reset-all",ariaLabel:"Reset all changes",onClick:()=>this.editor.resetAll()}),c=z({icon:gt,title:"Save Image",className:"toolbar-btn toolbar-btn-primary",testId:"btn-save-edit",ariaLabel:"Save image",onClick:()=>this.editor.save()}),d=z({icon:te,title:"Close",className:"toolbar-btn",testId:"btn-cancel-edit",ariaLabel:"Close editor",onClick:()=>this.editor.close()});return o.appendChild(this._themeBtn),o.appendChild(this._cropBtn),o.appendChild(l),o.appendChild(c),o.appendChild(d),this.element.appendChild(e),this.element.appendChild(i),this.element.appendChild(o),this._subscribeToState(),this.element}_subscribeToState(){const e=this.state.on("change:zoom",({value:s})=>{this._zoomLabel.textContent=`${Math.round(s*100)}%`});this._unsubscribers.push(e);const t=this.state.on("change:isDarkMode",({value:s})=>{this._themeBtn.innerHTML=s?be:ye});this._unsubscribers.push(t);const i=this.state.on("change:mode",({value:s})=>{this._cropBtn&&this._cropBtn.classList.toggle("toolbar-btn-primary",s==="crop")});this._unsubscribers.push(i)}updateZoom(e){this._zoomLabel&&(this._zoomLabel.textContent=`${Math.round(e*100)}%`)}destroy(){var e;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],(e=this.element)==null||e.remove(),this.element=null}}const K=ie;class Mt{constructor(e,t){this.state=e,this.editor=t,this.element=null,this._chips=new Map,this._scrollIndex=0,this._unsubscribers=[]}render(e){this._onSelect=e,this.element=p("div",{className:"category-carousel-container","data-testid":"category-carousel"}),this._leftBtn=z({icon:ce,title:"Previous categories",className:"carousel-nav carousel-nav-left",onClick:()=>this._scrollLeft()}),this._carousel=p("div",{className:"category-carousel"}),K.forEach(i=>{const s=le({label:i.name,icon:i.icon,active:this.state.get("selectedCategory")===i.id,onClick:()=>this._selectCategory(i.id)});s.dataset.categoryId=i.id,s.dataset.category=i.id,s.dataset.testid=`category-${i.id}`,this._chips.set(i.id,s),this._carousel.appendChild(s)}),this._rightBtn=z({icon:he,title:"Next categories",className:"carousel-nav carousel-nav-right",onClick:()=>this._scrollRight()}),this._pagination=p("div",{className:"carousel-pagination",role:"tablist","aria-label":"Category pages"});const t=Math.ceil(K.length/3);for(let i=0;i<t;i++){const s=p("button",{type:"button",className:`pagination-dot ${i===0?"active":""}`,role:"tab","aria-label":`Page ${i+1} of ${t}`,"aria-selected":i===0?"true":"false",onClick:()=>this._scrollToPage(i)});this._pagination.appendChild(s)}return this.element.appendChild(this._leftBtn),this.element.appendChild(this._carousel),this.element.appendChild(this._rightBtn),this.element.appendChild(this._pagination),this._subscribeToState(),this._updateNavButtons(),this.element}_subscribeToState(){const e=this.state.on("change:selectedCategory",({value:t})=>{this._chips.forEach((i,s)=>{i.setActive(s===t)})});this._unsubscribers.push(e)}_selectCategory(e){var s;this.state.set("selectedCategory",e);const t=this.state.get("mode");e==="crop"?t!=="crop"&&this.editor.setMode("crop"):t!=="filters"&&this.editor.setMode("filters");const i=this._chips.get(e);i&&this._carousel&&i.scrollIntoView({behavior:"smooth",inline:"center",block:"nearest"}),(s=this._onSelect)==null||s.call(this,e)}_scrollLeft(){this._scrollIndex>0&&(this._scrollIndex--,this._scrollCarousel())}_scrollRight(){this._scrollIndex<K.length-3&&(this._scrollIndex++,this._scrollCarousel())}_scrollToPage(e){this._scrollIndex=e*3,this._scrollCarousel()}_scrollCarousel(){if(this._carousel){const e=this._carousel.querySelector(".chip"),t=(e==null?void 0:e.clientWidth)||100;this._carousel.scrollTo({left:this._scrollIndex*(t+8),behavior:"smooth"})}this._updateNavButtons(),this._updatePagination()}_updateNavButtons(){this._leftBtn&&(this._leftBtn.disabled=this._scrollIndex===0),this._rightBtn&&(this._rightBtn.disabled=this._scrollIndex>=K.length-3)}_updatePagination(){if(this._pagination){const e=this._pagination.querySelectorAll(".pagination-dot"),t=Math.floor(this._scrollIndex/3);e.forEach((i,s)=>{const a=s===t;i.classList.toggle("active",a),i.setAttribute("aria-selected",a?"true":"false")})}}setSelected(e){this._selectCategory(e)}destroy(){var e;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],this._chips.clear(),(e=this.element)==null||e.remove(),this.element=null}}class Pt{constructor(e,t){this.state=e,this.filterManager=t,this.element=null,this._filterCards=new Map,this._scrollIndex=0,this._unsubscribers=[],this._onToggle=null,this._onSelect=null}render({onToggle:e,onSelect:t}){return this._onToggle=e,this._onSelect=t,this.element=p("div",{className:"filter-carousel-container"}),this._leftBtn=z({icon:ce,title:"Previous filters",className:"carousel-nav carousel-nav-left",onClick:()=>this._scrollLeft()}),this._carousel=p("div",{className:"filter-carousel"}),this._rightBtn=z({icon:he,title:"Next filters",className:"carousel-nav carousel-nav-right",onClick:()=>this._scrollRight()}),this.element.appendChild(this._leftBtn),this.element.appendChild(this._carousel),this.element.appendChild(this._rightBtn),this._subscribeToState(),this._renderFilters(),this.element}_subscribeToState(){const e=this.state.on("change:selectedCategory",()=>{this._renderFilters()});this._unsubscribers.push(e);const t=this.state.on("change:activeFilters",()=>{this._updateActiveStates()});this._unsubscribers.push(t);const i=this.state.on("change:selectedFilter",()=>{this._updateSelectedState()});this._unsubscribers.push(i)}_renderFilters(){this._carousel.innerHTML="",this._filterCards.clear(),this._scrollIndex=0;const e=this.state.get("selectedCategory");if(e==="crop")return;const t=this.filterManager.getFiltersByCategory(e),i=this.state.get("activeFilters"),s=this.state.get("selectedFilter");t.forEach(a=>{const n=this._createFilterCard(a,{isActive:i.has(a.id),isSelected:s===a.id});this._filterCards.set(a.id,n),this._carousel.appendChild(n)}),this._updateNavButtons()}_createFilterCard(e,{isActive:t,isSelected:i}){const s=p("div",{className:`filter-card ${t?"active":""} ${i?"selected":""}`,"data-filter":e.id,"data-testid":`filter-${e.id}`,onClick:()=>this._handleCardClick(e.id)}),a=p("div",{className:"filter-preview"}),n=p("span",{className:"filter-preview-text"},e.name.charAt(0));a.appendChild(n);const o=p("span",{className:"filter-name",title:e.name},e.name),l=p("button",{className:`filter-toggle ${t?"active":""}`,onClick:c=>{var u;c.stopPropagation();const h=!this.state.get("activeFilters").has(e.id);this._handleToggle(e.id,h),h&&(this.state.set("selectedFilter",e.id),(u=this._onSelect)==null||u.call(this,e.id))}});return l.innerHTML=t?J:"",s.appendChild(a),s.appendChild(o),s.appendChild(l),s._toggle=l,s._isActive=t,s}_handleCardClick(e){var i;this.state.get("activeFilters").has(e)||this._handleToggle(e,!0),this.state.set("selectedFilter",e),(i=this._onSelect)==null||i.call(this,e)}_handleToggle(e,t){var i;(i=this._onToggle)==null||i.call(this,e,t)}_updateActiveStates(){const e=this.state.get("activeFilters");this._filterCards.forEach((t,i)=>{const s=e.has(i);t.classList.toggle("active",s),t._toggle.classList.toggle("active",s),t._toggle.innerHTML=s?J:"",t._isActive=s})}_updateSelectedState(){const e=this.state.get("selectedFilter");this._filterCards.forEach((t,i)=>{t.classList.toggle("selected",i===e)})}_scrollLeft(){this._scrollIndex>0&&(this._scrollIndex--,this._scrollCarousel())}_scrollRight(){const e=Math.max(0,this._filterCards.size-3);this._scrollIndex<e&&(this._scrollIndex++,this._scrollCarousel())}_scrollCarousel(){if(this._carousel){const e=this._carousel.querySelector(".filter-card"),t=(e==null?void 0:e.clientWidth)||120;this._carousel.scrollTo({left:this._scrollIndex*(t+8),behavior:"smooth"})}this._updateNavButtons()}_updateNavButtons(){const e=Math.max(0,this._filterCards.size-3);this._leftBtn&&(this._leftBtn.disabled=this._scrollIndex===0),this._rightBtn&&(this._rightBtn.disabled=this._scrollIndex>=e)}destroy(){var e;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],this._filterCards.clear(),(e=this.element)==null||e.remove(),this.element=null}}class kt{constructor(e,t){this.state=e,this.filterManager=t,this.element=null,this._controls=new Map,this._onChange=null,this._onReset=null,this._onAction=null,this._unsubscribers=[]}render({onChange:e,onReset:t,onAction:i}){return this._onChange=e,this._onReset=t,this._onAction=i,this.element=p("div",{className:"filter-adjustments"}),this._subscribeToState(),this._renderControls(),this.element}_subscribeToState(){const e=this.state.on("change:selectedFilter",()=>{this._renderControls()});this._unsubscribers.push(e);const t=this.state.on("change:filterValues",()=>{this._updateValues()});this._unsubscribers.push(t)}_renderControls(){this.element.innerHTML="",this._controls.clear();const e=this.state.get("selectedFilter");if(!e){this.element.appendChild(p("div",{className:"no-filter-selected"},"Select a filter to adjust"));return}const t=this.filterManager.getFilterDef(e);if(!t){this.element.appendChild(p("div",{className:"no-filter-selected"},"Filter not found"));return}const i=p("div",{className:"adjustments-header"});i.appendChild(p("span",{className:"adjustments-title"},t.name)),i.appendChild(O({label:"Reset",className:"btn-text",onClick:()=>this._handleReset(e)})),this.element.appendChild(i);const s=p("div",{className:"adjustments-grid"}),a=this.state.getFilterValues(e);(t.controls||[]).forEach(o=>{const l=a[o.id]??o.default,c=this._createControl(e,o,l);c&&(this._controls.set(o.id,c),s.appendChild(c))});const n=this.filterManager.getInstance(e);if(n&&typeof n.getDynamicControls=="function"){let o=[];try{o=n.getDynamicControls()||[]}catch{}o.forEach(l=>{const c=l.property||l.id,d=a[c]??l.default,h=this._createControl(e,l,d);h&&(this._controls.set(l.id,h),s.appendChild(h))})}this.element.appendChild(s)}_createControl(e,t,i){if(t.hidden)return null;const s=t.label||t.id,a=this._normalizeControlType(t.type),n=t.property||t.id;switch(a){case"slider":return de({id:`${e}-${t.id}`,label:s,min:t.min??0,max:t.max??1,step:t.step??.01,value:typeof i=="number"?i:t.default??0,onChange:c=>this._handleChange(e,n,c)});case"toggle":return ue({id:`${e}-${t.id}`,label:s,checked:!!i,onChange:c=>this._handleChange(e,n,c)});case"color":return pe({id:`${e}-${t.id}`,label:s,value:typeof i=="string"&&i.startsWith("#")?i:t.default||"#000000",onChange:c=>this._handleChange(e,n,c)});case"select":const o=this._normalizeOptions(t.options);return me({id:`${e}-${t.id}`,label:s,options:o,value:i??t.default,onChange:c=>this._handleChange(e,n,c)});case"text":return fe({id:`${e}-${t.id}`,label:s,value:typeof i=="string"?i:t.default??"",placeholder:t.placeholder||"",onCommit:c=>this._handleChange(e,n,c)});case"button":const l=p("div",{className:"button-control"});return l.appendChild(O({label:s,className:"btn-secondary",onClick:()=>this._handleAction(e,t.action||t.id)})),l;default:return null}}_normalizeControlType(e){return{slider:"slider",range:"slider",toggle:"toggle",checkbox:"toggle",color:"color",select:"select",dropdown:"select",button:"button",text:"text"}[e]||e}_normalizeOptions(e){return!e||!Array.isArray(e)?[]:e.map(t=>typeof t=="object"&&t.value!==void 0?{value:t.value,label:t.label||String(t.value)}:typeof t=="string"?{value:t,label:t}:typeof t=="number"?{value:t,label:String(t)}:{value:t,label:String(t)})}_handleChange(e,t,i){var s;(s=this._onChange)==null||s.call(this,e,t,i)}_handleReset(e){var t;(t=this._onReset)==null||t.call(this,e),this._renderControls()}_handleAction(e,t){var i;(i=this._onAction)==null||i.call(this,e,t),this._renderControls()}_updateValues(){const e=this.state.get("selectedFilter");if(!e)return;const t=this.state.getFilterValues(e),i=this.filterManager.getFilterDef(e);i&&i.controls.forEach(s=>{const a=this._controls.get(s.id);if(a&&typeof a.setValue=="function"){const n=t[s.id]??s.default;a.setValue(n)}})}show(){this.element&&(this.element.style.display="")}hide(){this.element&&(this.element.style.display="none")}destroy(){var e;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],this._controls.clear(),(e=this.element)==null||e.remove(),this.element=null}}class Ft{constructor(e,t){this.state=e,this.filterManager=t,this._drawer=null,this._body=null,this._titleEl=null,this._isOpen=!1,this._currentFilterId=null,this._controls=new Map,this._onChange=null,this._onReset=null,this._onRemove=null,this._onAction=null,this._container=null}build(e,{onChange:t,onReset:i,onRemove:s,onAction:a}){this._onChange=t,this._onReset=i,this._onRemove=s,this._onAction=a,this._container=e,this._drawer=p("div",{className:"mobile-filter-drawer"});const n=p("div",{className:"drawer-header"});this._titleEl=p("span",{className:"drawer-title"},"Filter");const o=p("div",{className:"drawer-header-actions"}),l=O({label:"Reset",className:"btn-text",onClick:()=>{var h;this._currentFilterId&&((h=this._onReset)==null||h.call(this,this._currentFilterId),this._renderControls())}}),c=O({label:"Remove",className:"btn-text btn-danger",onClick:()=>{var h;this._currentFilterId&&((h=this._onRemove)==null||h.call(this,this._currentFilterId),this.close())}}),d=z({icon:te,title:"Close",className:"btn-icon-sm",ariaLabel:"Close drawer",onClick:()=>this.close()});o.appendChild(l),o.appendChild(c),o.appendChild(d),n.appendChild(this._titleEl),n.appendChild(o),this._drawer.appendChild(n),this._body=p("div",{className:"drawer-body"}),this._drawer.appendChild(this._body),e.appendChild(this._drawer)}open(e){this._isOpen&&this._currentFilterId===e||(this._currentFilterId=e,this._renderControls(),this._isOpen||(this._isOpen=!0,this._sizeToContainer(),this._animateOpen()))}close(){this._isOpen&&(this._isOpen=!1,this._animateClose(),this._currentFilterId=null)}get isOpen(){return this._isOpen}_sizeToContainer(){if(!this._container||!this._drawer)return;const e=this._container.offsetHeight;e>0&&(this._drawer.style.height=e+"px")}_animateOpen(){this._drawer.style.transition="none",this._drawer.style.transform="translateY(100%)",this._drawer.offsetHeight,this._drawer.style.transition="transform 0.25s cubic-bezier(0.33, 1, 0.68, 1)",this._drawer.style.transform="translateY(0)"}_animateClose(){this._drawer.style.transition="transform 0.2s cubic-bezier(0.32, 0, 0.67, 0)",this._drawer.style.transform="translateY(100%)"}_renderControls(){if(this._body.innerHTML="",this._controls.clear(),!this._currentFilterId)return;const e=this.filterManager.getFilterDef(this._currentFilterId);if(!e)return;this._titleEl.textContent=e.name;const t=p("div",{className:"adjustments-grid"}),i=this.state.getFilterValues(this._currentFilterId);(e.controls||[]).forEach(a=>{if(a.hidden)return;const n=this._createControl(this._currentFilterId,a,i[a.id]??a.default);n&&(this._controls.set(a.id,n),t.appendChild(n))});const s=this.filterManager.getInstance(this._currentFilterId);if(s&&typeof s.getDynamicControls=="function"){let a=[];try{a=s.getDynamicControls()||[]}catch{}a.forEach(n=>{const o=n.property||n.id,l=i[o]??n.default,c=this._createControl(this._currentFilterId,n,l);c&&(this._controls.set(n.id,c),t.appendChild(c))})}this._body.appendChild(t)}_createControl(e,t,i){if(t.hidden)return null;const s=t.label||t.id,a=this._normalizeControlType(t.type),n=t.property||t.id;switch(a){case"slider":return de({id:`drawer-${e}-${t.id}`,label:s,min:t.min??0,max:t.max??1,step:t.step??.01,value:typeof i=="number"?i:t.default??0,onChange:o=>{var l;return(l=this._onChange)==null?void 0:l.call(this,e,n,o)}});case"toggle":return ue({id:`drawer-${e}-${t.id}`,label:s,checked:!!i,onChange:o=>{var l;return(l=this._onChange)==null?void 0:l.call(this,e,n,o)}});case"color":return pe({id:`drawer-${e}-${t.id}`,label:s,value:typeof i=="string"&&i.startsWith("#")?i:t.default||"#000000",onChange:o=>{var l;return(l=this._onChange)==null?void 0:l.call(this,e,n,o)}});case"select":{const o=this._normalizeOptions(t.options);return me({id:`drawer-${e}-${t.id}`,label:s,options:o,value:i??t.default,onChange:l=>{var c;return(c=this._onChange)==null?void 0:c.call(this,e,n,l)}})}case"text":return fe({id:`drawer-${e}-${t.id}`,label:s,value:typeof i=="string"?i:t.default??"",placeholder:t.placeholder||"",onCommit:o=>{var l;return(l=this._onChange)==null?void 0:l.call(this,e,n,o)}});case"button":{const o=p("div",{className:"button-control"});return o.appendChild(O({label:s,className:"btn-secondary",onClick:()=>{var l;(l=this._onAction)==null||l.call(this,e,t.action||t.id),this._renderControls()}})),o}default:return null}}_normalizeControlType(e){return{slider:"slider",range:"slider",toggle:"toggle",checkbox:"toggle",color:"color",select:"select",dropdown:"select",button:"button",text:"text"}[e]||e}_normalizeOptions(e){return!e||!Array.isArray(e)?[]:e.map(t=>typeof t=="object"&&t.value!==void 0?{value:t.value,label:t.label||String(t.value)}:typeof t=="string"?{value:t,label:t}:typeof t=="number"?{value:t,label:String(t)}:{value:t,label:String(t)})}destroy(){var e;this._controls.clear(),(e=this._drawer)==null||e.remove(),this._drawer=null,this._isOpen=!1,this._currentFilterId=null,this._container=null}}class At{constructor(e,t){this.state=e,this.filterManager=t,this.element=null,this._scrollContainer=null,this._chips=new Map,this._unsubscribers=[],this._onToggle=null,this._onSelect=null}render({onToggle:e,onSelect:t}){return this._onToggle=e,this._onSelect=t,this.element=p("div",{className:"mobile-active-filters","data-testid":"mobile-active-filters"}),this._scrollContainer=p("div",{className:"mobile-active-filters-scroll"}),this.element.appendChild(this._scrollContainer),this._subscribeToState(),this._renderChips(),this.element}_subscribeToState(){const e=this.state.on("change:activeFilters",()=>{this._renderChips()});this._unsubscribers.push(e);const t=this.state.on("change:selectedFilter",()=>{this._updateSelectedState()});this._unsubscribers.push(t)}_renderChips(){this._scrollContainer.innerHTML="",this._chips.clear();const e=this.state.get("activeFilters");if(!e||e.size===0){const t=p("div",{className:"active-filter-placeholder"},"No active filters");this._scrollContainer.appendChild(t);return}e.forEach(t=>{const i=this.filterManager.getFilterDef(t);if(!i)return;const s=this._createChip(t,i);this._chips.set(t,s),this._scrollContainer.appendChild(s)}),this._updateSelectedState()}_createChip(e,t){const i=p("div",{className:"active-filter-chip","data-filter-id":e,"data-testid":`active-chip-${e}`}),s=p("span",{className:"active-filter-chip-label",onClick:n=>{var o;n.stopPropagation(),(o=this._onSelect)==null||o.call(this,e)}},t.name),a=p("button",{className:"active-filter-chip-check","aria-label":`Remove ${t.name} filter`,onClick:n=>{var o;n.stopPropagation(),(o=this._onToggle)==null||o.call(this,e,!1)}});return a.innerHTML='<svg width="10" height="10" viewBox="0 0 12 12"><path d="M2 6l3 3 5-5" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/></svg>',i.appendChild(s),i.appendChild(a),i}_updateSelectedState(){const e=this.state.get("selectedFilter");this._chips.forEach((t,i)=>{t.classList.toggle("selected",i===e)})}destroy(){var e;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],this._chips.clear(),(e=this.element)==null||e.remove(),this.element=null}}const zt=[{id:"free",name:"Free",icon:Ct},{id:"square",name:"Square",icon:_t},{id:"circle",name:"Circle",icon:xt}],Nt=[{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 Le{constructor(e,t){this.state=e,this.cropManager=t,this.element=null,this._shapeChips=new Map,this._aspectChips=new Map,this._unsubscribers=[]}_applyCropAndReturnToFilters(){this.cropManager.apply()===null&&typeof this.cropManager.disable=="function"&&this.cropManager.disable(),this.state.set("selectedCategory","adjust")}render(){this.element=p("div",{className:"crop-controls","data-testid":"crop-controls"});const e=p("div",{className:"crop-section"});e.appendChild(p("label",{className:"section-label"},"Shape"));const t=p("div",{className:"chip-row"}),i=this.state.get("crop.shape");zt.forEach(c=>{const d=le({label:c.name,icon:c.icon,active:i===c.id,onClick:()=>this._selectShape(c.id)});d.dataset.shape=c.id,d.dataset.testid=`crop-shape-${c.id}`,this._shapeChips.set(c.id,d),t.appendChild(d)}),e.appendChild(t),this.element.appendChild(e),this.state.get("lockCropShape")&&(e.style.display="none"),this._shapeSection=e,this._aspectSection=p("div",{className:"crop-section"}),this._aspectSection.appendChild(p("label",{className:"section-label"},"Aspect Ratio"));const s=p("div",{className:"chip-row aspect-row"}),a=this.state.get("crop.aspect");Nt.forEach(c=>{const d=le({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),s.appendChild(d)}),this._aspectSection.appendChild(s),this.element.appendChild(this._aspectSection),this._updateAspectVisibility();const n=p("div",{className:"crop-actions"}),o=O({label:"Cancel",className:"btn-secondary crop-cancel-btn",icon:te,onClick:()=>this.cropManager.cancel()});o.dataset.testid="cancel-crop";const l=O({label:"Apply Crop",className:"btn-primary crop-apply-btn",icon:J,onClick:()=>this._applyCropAndReturnToFilters()});return l.dataset.testid="apply-crop",n.appendChild(o),n.appendChild(l),this.element.appendChild(n),this._subscribeToState(),this.element}_subscribeToState(){const e=this.state.on("change:crop.shape",({value:i})=>{this._shapeChips.forEach((s,a)=>{s.setActive(a===i)}),this._updateAspectVisibility()});this._unsubscribers.push(e);const t=this.state.on("change:crop.aspect",({value:i})=>{this._aspectChips.forEach((s,a)=>{s.setActive(a===i)})});this._unsubscribers.push(t)}_selectShape(e){this.cropManager.setShape(e)}_selectAspect(e){this.cropManager.setAspect(e)}_updateAspectVisibility(){const e=this.state.get("crop.shape"),t=this.state.get("lockAspectRatio");this._aspectSection&&(this._aspectSection.style.display=e==="free"&&!t?"":"none")}show(){this.element&&(this.element.style.display="")}hide(){this.element&&(this.element.style.display="none")}destroy(){var e;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],this._shapeChips.clear(),this._aspectChips.clear(),(e=this.element)==null||e.remove(),this.element=null}}class Rt{constructor(e,t){this.state=e,this.filterManager=t,this.element=null,this._filterItems=new Map,this._unsubscribers=[],this._onRemove=null,this._onReset=null,this._onClearAll=null,this._onUpdateValue=null,this._onSelect=null}render({onRemove:e,onReset:t,onClearAll:i,onUpdateValue:s,onSelect:a}){this._onRemove=e,this._onReset=t,this._onClearAll=i,this._onUpdateValue=s,this._onSelect=a,this.element=p("div",{className:"active-filters-panel","data-testid":"active-filters-panel"});const n=p("div",{className:"panel-header"});n.appendChild(p("h3",{className:"panel-title"},"Active Filters"));const o=O({label:"Clear All",className:"btn-text btn-danger",onClick:()=>this._handleClearAll()});return o.dataset.testid="clear-all-filters",n.appendChild(o),this.element.appendChild(n),this._listContainer=p("div",{className:"active-filters-list"}),this.element.appendChild(this._listContainer),this._subscribeToState(),this._renderFilterList(),this.element}_subscribeToState(){const e=this.state.on("change:activeFilters",()=>{this._renderFilterList()});this._unsubscribers.push(e);const t=this.state.on("change:filterValues",()=>{this._updateValuesDisplay()});this._unsubscribers.push(t);const i=this.state.on("change:selectedFilter",()=>{this._updateSelectedState()});this._unsubscribers.push(i)}_updateSelectedState(){const e=this.state.get("selectedFilter");this._filterItems.forEach((t,i)=>{t.classList.toggle("selected",i===e)})}_renderFilterList(){this._listContainer.innerHTML="",this._filterItems.clear();const e=this.state.get("activeFilters");if(e.size===0){this._listContainer.appendChild(p("div",{className:"no-filters-message"},"No filters active"));return}e.forEach(t=>{const i=this.filterManager.getFilterDef(t);if(!i)return;const s=this._createFilterItem(t,i);this._filterItems.set(t,s),this._listContainer.appendChild(s)})}_createFilterItem(e,t){const s=this.state.get("selectedFilter")===e,a=p("div",{className:`active-filter-item ${s?"selected":""}`,"data-active-filter":e,"data-testid":`active-filter-${e}`,onClick:f=>{f.target.closest(".filter-item-actions")||this._handleSelect(e)}}),n=p("div",{className:"filter-item-header"}),o=p("span",{className:"filter-item-name"},t.name),l=p("div",{className:"filter-item-actions"}),c=z({icon:Xe,title:"Reset filter",className:"btn-icon-sm",onClick:()=>this._handleReset(e)}),d=z({icon:bt,title:"Remove filter",className:"btn-icon-sm btn-danger",onClick:()=>this._handleRemove(e)});l.appendChild(c),l.appendChild(d),n.appendChild(o),n.appendChild(l),a.appendChild(n);const h=this.state.getFilterValues(e),u=p("div",{className:"filter-item-summary"});return u.textContent=this._getValuesSummary(t,h),a.appendChild(u),a._summaryEl=u,a}_normalizeControlType(e){return{slider:"slider",range:"slider",toggle:"toggle",checkbox:"toggle",color:"color",select:"select",dropdown:"select",button:"button"}[e]||e}_getValuesSummary(e,t){if(!e.controls||!Array.isArray(e.controls))return"Default values";const i=[];return e.controls.forEach(s=>{const a=this._normalizeControlType(s.type);if(a==="button")return;const n=s.label||s.id,o=t[s.id]??s.default;o!==s.default&&(a==="slider"?i.push(`${n}: ${this._formatValue(o)}`):a==="toggle"?o&&i.push(n):a==="color"?i.push(`${n}: ${o}`):a==="select"&&i.push(`${n}: ${o}`))}),i.length>0?i.join(", "):"Default values"}_formatValue(e){return typeof e!="number"||Number.isInteger(e)?String(e):e.toFixed(2)}_updateValuesDisplay(){this._filterItems.forEach((e,t)=>{const i=this.filterManager.getFilterDef(t);if(!i||!e._summaryEl)return;const s=this.state.getFilterValues(t);e._summaryEl.textContent=this._getValuesSummary(i,s)})}_handleRemove(e){var t;(t=this._onRemove)==null||t.call(this,e)}_handleReset(e){var t;(t=this._onReset)==null||t.call(this,e)}_handleClearAll(){var e;(e=this._onClearAll)==null||e.call(this)}_handleSelect(e){var t;this.state.set("selectedFilter",e),(t=this._onSelect)==null||t.call(this,e)}show(){this.element&&(this.element.style.display="")}hide(){this.element&&(this.element.style.display="none")}destroy(){var e;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],this._filterItems.clear(),(e=this.element)==null||e.remove(),this.element=null}}const H={name:"free",initialMode:"filters",cropShape:"free",aspectRatio:"free",autoZoomOnCropOverflow:!1,lockCropShape:!1,lockAspectRatio:!1,showFilters:!0,showCropControls:!0,maxExportWidth:void 0,maxExportHeight:void 0},ae={free:{...H},avatar:{...H,name:"avatar",initialMode:"crop",cropShape:"circle",aspectRatio:"1:1",autoZoomOnCropOverflow:!0,lockCropShape:!0,lockAspectRatio:!0},banner:{...H,name:"banner",initialMode:"crop",cropShape:"square",aspectRatio:"16:9",autoZoomOnCropOverflow:!1,lockCropShape:!1,lockAspectRatio:!0},cover:{...H,name:"cover",initialMode:"crop",cropShape:"free",aspectRatio:"24:5",autoZoomOnCropOverflow:!0,lockCropShape:!0,lockAspectRatio:!0},product:{...H,name:"product",initialMode:"filters",cropShape:"square",aspectRatio:"1:1",autoZoomOnCropOverflow:!1,lockCropShape:!1,lockAspectRatio:!1}};function Ve(r){if(!r)return{...ae.free};if(typeof r=="object"&&r!==null)return{...H,...r};const e=ae[r];return e?{...e}:{...ae.free}}class Tt extends W{constructor(e,t={}){var a,n,o;if(super(),!e)throw new Error("VanillaImageEditor: container element is required");this._container=e,this._destroyed=!1,this._loadVersion=0,this._objectUrls=new Set;const i=t.preset?Ve(t.preset):null,s=i?{initialMode:i.initialMode==="crop"?"crop":"adjust",cropShape:i.cropShape,initialAspectRatio:i.aspectRatio}:{};this._options={theme:"auto",initialImage:null,initialMode:"adjust",cropShape:"free",initialAspectRatio:"free",backgroundRemoval:{enabled:!0,endpoint:"/api/v1/media/remove-bg",fallbackEndpoint:null},...s,...t},this._preset=i,this._state=Te(),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 Ee,this._filterManager=new Oe(this._state,this._renderer),this._cropManager=new ee(this._state,this._renderer),this._removeBgManager=null,((a=this._options.backgroundRemoval)==null?void 0:a.enabled)!==!1&&(this._removeBgManager=new Ye({endpoint:(n=this._options.backgroundRemoval)==null?void 0:n.endpoint,fallbackEndpoint:(o=this._options.backgroundRemoval)==null?void 0:o.fallbackEndpoint})),this._loadingOverlay=null,this._isMobile=typeof window<"u"?window.innerWidth<=768:!1,this._toolbar=null,this._categoryCarousel=null,this._filterCarousel=null,this._filterAdjustments=null,this._mobileFilterDrawer=null,this._mobileActiveFilters=null,this._cropControls=null,this._activeFiltersPanel=null,this._editorEl=null,this._canvasContainer=null,this._cropOverlay=null,this._controlsSection=null,this._filterControlsEl=null,this._fileInput=null,this._resizeObserver=null,this._init()}async _init(){this._state.detectTheme(),this._buildDOM(),await this._renderer.mount(this._canvasContainer,this._state.get("isDarkMode")?657930:16777215),this._cropManager.setOverlayCanvas(this._cropOverlay),this._initUI(),this._setupResizeObserver(),this._setupWindowResize(),this._subscribeToState(),this._options.initialImage&&await this.loadImage(this._options.initialImage),this.emit("ready")}_buildDOM(){this._container.innerHTML="",this._editorEl=p("div",{className:`vanilla-image-editor ${this._state.get("isDarkMode")?"dark":"light"}`});const e=p("div",{className:"editor-toolbar-container"});this._editorEl.appendChild(e),this._toolbarContainer=e;const t=p("div",{className:"editor-content"}),i=p("div",{className:"canvas-section"});this._canvasContainer=p("div",{className:"canvas-container"}),this._cropOverlay=p("canvas",{className:"crop-overlay","aria-hidden":"true"}),i.appendChild(this._canvasContainer),i.appendChild(this._cropOverlay),t.appendChild(i),this._controlsSection=p("div",{className:"controls-section"}),t.appendChild(this._controlsSection),this._editorEl.appendChild(t),this._fileInput=p("input",{type:"file",accept:"image/*",className:"hidden-file-input","aria-label":"Choose image file to edit",onChange:s=>this._handleFileSelect(s)}),this._editorEl.appendChild(this._fileInput),this._container.appendChild(this._editorEl)}_initUI(){this._toolbar=new De(this._state,this),this._toolbarContainer.appendChild(this._toolbar.render()),this._filterControlsEl=p("div",{className:"filter-controls-container"}),this._categoryCarousel=new Mt(this._state,this),this._filterControlsEl.appendChild(this._categoryCarousel.render(s=>{}));const e=p("div",{className:"filter-layout"}),t=p("div",{className:"filter-left-column"});this._filterCarousel=new Pt(this._state,this._filterManager),t.appendChild(this._filterCarousel.render({onToggle:(s,a)=>this._handleFilterToggle(s,a),onSelect:s=>{this._handleFilterSelect(s),this._isMobile&&this._mobileFilterDrawer&&this._mobileFilterDrawer.open(s)}})),this._filterAdjustments=new kt(this._state,this._filterManager),t.appendChild(this._filterAdjustments.render({onChange:(s,a,n)=>this._handleFilterChange(s,a,n),onReset:s=>this._handleFilterReset(s),onAction:(s,a)=>this._handleFilterAction(s,a)})),e.appendChild(t);const i=p("div",{className:"filter-right-column"});this._activeFiltersPanel=new Rt(this._state,this._filterManager),i.appendChild(this._activeFiltersPanel.render({onRemove:s=>this._handleFilterToggle(s,!1),onReset:s=>this._handleFilterReset(s),onClearAll:()=>this.resetAll(),onSelect:s=>this._handleFilterSelect(s)})),e.appendChild(i),this._filterControlsEl.appendChild(e),this._mobileActiveFilters=new At(this._state,this._filterManager),this._filterControlsEl.appendChild(this._mobileActiveFilters.render({onToggle:(s,a)=>this._handleFilterToggle(s,a),onSelect:s=>{this._handleFilterSelect(s),this._isMobile&&this._mobileFilterDrawer&&this._mobileFilterDrawer.open(s)}})),this._cropControls=new Le(this._state,this._cropManager),this._cropControlsEl=this._cropControls.render(),this._cropControlsEl.style.display="none",this._controlsSection.appendChild(this._filterControlsEl),this._controlsSection.appendChild(this._cropControlsEl),this._mobileFilterDrawer=new Ft(this._state,this._filterManager),this._mobileFilterDrawer.build(this._controlsSection,{onChange:(s,a,n)=>this._handleFilterChange(s,a,n),onReset:s=>this._handleFilterReset(s),onRemove:s=>{this._handleFilterToggle(s,!1),this._state.set("selectedFilter",null)},onAction:(s,a)=>this._handleFilterAction(s,a)})}_setupResizeObserver(){let e=null;this._resizeObserver=new ResizeObserver(()=>{clearTimeout(e),e=setTimeout(()=>{this._canvasContainer&&(this._renderer.resizeTo(this._canvasContainer),this._state.get("mode")==="crop"&&this._cropManager.drawOverlay())},50)}),this._resizeObserver.observe(this._canvasContainer)}_setupWindowResize(){this._handleWindowResize=()=>{var e;this._isMobile=window.innerWidth<=768,!this._isMobile&&((e=this._mobileFilterDrawer)!=null&&e.isOpen)&&this._mobileFilterDrawer.close()},window.addEventListener("resize",this._handleWindowResize)}_subscribeToState(){this._state.on("change:mode",({value:e})=>{this._updateModeUI(e),e==="filters"&&this._filterManager.applyFilters()}),this._state.on("change:isDarkMode",({value:e})=>{this._editorEl.classList.toggle("dark",e),this._editorEl.classList.toggle("light",!e),this._renderer.setBackgroundColor(e?657930:16777215)}),this._state.on("change:hasImage",({value:e})=>{this._editorEl.classList.toggle("has-image",e)}),this._renderer.on("zoomChange",e=>{this._state.set("zoom",e)})}_updateModeUI(e){var t;e==="crop"?(this._filterControlsEl.style.display="none",this._cropControlsEl.style.display="",(t=this._mobileFilterDrawer)!=null&&t.isOpen&&this._mobileFilterDrawer.close()):(this._filterControlsEl.style.display="",this._cropControlsEl.style.display="none")}async _handleFileSelect(e){var i;const t=(i=e.target.files)==null?void 0:i[0];t&&await this.loadImage(t),this._fileInput.value=""}_handleFilterToggle(e,t){this._filterManager.toggle(e,t)}_handleFilterSelect(e){this._state.set("selectedFilter",e)}_handleFilterChange(e,t,i){this._filterManager.updateValue(e,t,i)||this._filterManager.applyFilters(),this._renderer.render()}_handleFilterReset(e){this._filterManager.resetValues(e),this._filterManager.applyFilters()}_handleFilterAction(e,t){this._filterManager.performFilterAction(e,t)}setFilterRegistry(e){this._filterManager.setRegistry(e)}async loadImage(e,t={}){if(this._destroyed)return;const i=++this._loadVersion;let s=e;this._resetEditorState(),e instanceof Blob&&(s=URL.createObjectURL(e),this._objectUrls.add(s));const a=await this._renderer.loadTexture(s);if(!(this._destroyed||this._loadVersion!==i)){if(!a){this.emit("error",new Error("Failed to load image"));return}this._state.set("hasImage",!0),this._state.set("imageUrl",s),t.state&&this._hydrateState(t.state),this._options.initialMode==="crop"&&this.setMode("crop"),this.emit("imageLoaded",{url:s})}}_resetEditorState(){this._filterManager.resetAll(),this._state.set("crop.rect",null),this._state.set("crop.appliedRect",null),this._state.set("crop.appliedShape",null),this._state.set("crop.appliedAspect",null),this._state.set("crop.shape",this._options.cropShape||"free"),this._state.set("crop.aspect",this._options.initialAspectRatio||"free"),this._state.get("mode")==="crop"&&(this._cropManager.disable(),this._state.set("mode","filters"))}_hydrateState(e){if(!(!e||e.version!==1)){if(e.crop){const t=e.crop.shape||"free",i=e.crop.aspectRatio||"free";e.crop.rect&&(this._cropManager.applyFromPixelRect(e.crop.rect,t),this._state.set("crop.appliedRect",{...e.crop.rect}),this._state.set("crop.appliedShape",t),this._state.set("crop.appliedAspect",i)),this._state.set("crop.shape",t),this._state.set("crop.aspect",i)}if(Array.isArray(e.filters)){let t=null;for(const i of e.filters)if(i.enabled&&(t===null&&(t=i.id),this._state.toggleFilter(i.id,!0),this._filterManager.initializeValues(i.id),i.values))for(const[s,a]of Object.entries(i.values))this._state.setFilterValue(i.id,s,a);if(t!==null){this._state.set("selectedFilter",t);const i=this._filterManager.getFilterDef(t);if(typeof(i==null?void 0:i.category)=="string"){const s=Be[i.category]??i.category;this._state.set("selectedCategory",s)}}this._filterManager.applyFilters()}}}openFilePicker(){var e;(e=this._fileInput)==null||e.click()}exportImage(e="png",t=.92,i={}){return this._state.get("crop.rect")&&!this._cropManager.apply()?null:this._renderer.exportImage(e,t,i.maxEdge??0,i.dontUpscale!==!1,i.maxPixels??0)}save(){if(this._state.get("hasImage")){this._state.set("isSaving",!0);try{const e=this.exportImage("png",.92);if(!e)throw new Error("Failed to export image");const t=this._renderer.originalTexture,i={width:Math.round((t==null?void 0:t.width)||0),height:Math.round((t==null?void 0:t.height)||0)},s=document.createElement("a");s.href=e,s.download=`edited-image-${Date.now()}.png`,document.body.appendChild(s),s.click(),document.body.removeChild(s),this.emit("save",{imageData:e,dimensions:i,state:this.getSerializableState()})}catch(e){this.emit("error",{error:e})}finally{this._state.set("isSaving",!1)}}}getSerializableState(){const e=this._state.get("activeFilters"),t=[];if(e)for(const n of e){const o=this._state.getFilterValues(n);t.push({id:n,enabled:!0,values:{...o}})}const i=this._state.get("crop.appliedRect"),s=this._state.get("crop.rect"),a=i||s;return{version:1,crop:{rect:a?{...a}:null,aspectRatio:this._state.get("crop.appliedAspect")||this._state.get("crop.aspect")||"free",shape:this._state.get("crop.appliedShape")||this._state.get("crop.shape")||"free"},filters:t}}close(){this.emit("cancel")}setZoom(e){this._renderer.setZoom(e)}fitToScreen(){this._renderer.fitToScreen()}resetAll(){this._filterManager.resetAll()}toggleTheme(){const e=this._state.get("isDarkMode");this._state.set("isDarkMode",!e)}setTheme(e){this._state.set("theme",e),this._state.detectTheme()}setMode(e){e==="crop"?this._cropManager.enable():this._cropManager.disable(),this._state.set("mode",e)}getState(){return this._state.getAll()}async removeBackground(e={}){if(!this._removeBgManager)throw new Error("Background removal is not enabled");if(!this._state.get("hasImage"))throw new Error("No image loaded");this._state.set("isProcessing",!0),this._showLoadingOverlay("Removing background...");try{const t=this.exportImage("png");if(!t)throw new Error("Failed to export image for background removal");const i=await this._removeBgManager.removeBackground(t,e);return await this.loadImage(i.dataUrl),this.emit("background-removed",{model:i.model,processMs:i.processMs}),{model:i.model,processMs:i.processMs}}catch(t){throw this.emit("error",{error:t,context:"background-removal"}),t}finally{this._state.set("isProcessing",!1),this._hideLoadingOverlay()}}async isBackgroundRemovalAvailable(){return this._removeBgManager?this._removeBgManager.isAvailable():!1}_showLoadingOverlay(e){var i;if(!this._loadingOverlay)this._loadingOverlay=p("div",{className:"editor-loading-overlay"},[p("div",{className:"editor-loading-spinner"}),p("div",{className:"editor-loading-text"},e)]);else{const s=this._loadingOverlay.querySelector(".editor-loading-text");s&&(s.textContent=e)}const t=(i=this._canvasContainer)==null?void 0:i.parentElement;t&&!this._loadingOverlay.parentElement&&t.appendChild(this._loadingOverlay)}_hideLoadingOverlay(){var e;(e=this._loadingOverlay)==null||e.remove()}destroy(){var e,t,i,s,a,n,o,l,c,d;this._destroyed=!0;for(const h of this._objectUrls)try{URL.revokeObjectURL(h)}catch{}this._objectUrls.clear(),(e=this._resizeObserver)==null||e.disconnect(),this._renderer.destroy(),this._cropManager.disable(),this._handleWindowResize&&window.removeEventListener("resize",this._handleWindowResize),(t=this._toolbar)==null||t.destroy(),(i=this._categoryCarousel)==null||i.destroy(),(s=this._filterCarousel)==null||s.destroy(),(a=this._filterAdjustments)==null||a.destroy(),(n=this._mobileFilterDrawer)==null||n.destroy(),(o=this._mobileActiveFilters)==null||o.destroy(),(l=this._cropControls)==null||l.destroy(),(c=this._activeFiltersPanel)==null||c.destroy(),(d=this._editorEl)==null||d.remove(),this._container=null,this._state=null,this.emit("destroyed"),this.removeAllListeners()}}const E=new Map,j=new Map;function Et(r,e){return!Array.isArray(r.mediaTargets)||r.mediaTargets.length===0?!0:r.mediaTargets.includes(e)}function m(r){var e;return E.has(r.id),E.set(r.id,r),j.has(r.category)||j.set(r.category,[]),(e=j.get(r.category))==null||e.push(r.id),r}function Ue(r){return E.get(r)}function Z(){return Array.from(E.values())}function je(){Z().map(t=>t.id),Object.entries(b).filter(t=>/Filter$/.test(t[0])&&typeof t[1]=="function").forEach(([t,i])=>{const s=t.replace(/Filter$/,"").replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();E.has(s)||m({id:s,name:t.replace(/Filter$/,""),category:"unlisted",mediaTargets:["image"],defaultParams:{},controls:[],createFilter:(a={})=>{try{return new i(a)}catch{return null}}})})}function qe(r){return(j.get(r)||[]).map(t=>E.get(t)).filter(Boolean)}function He(){return Array.from(j.keys())}function It(r){return E.has(r)}function Xt(r){const e=E.get(r);if(!e)return!1;E.delete(r);const t=j.get(e.category);if(t){const i=t.indexOf(r);i!==-1&&t.splice(i,1),t.length===0&&j.delete(e.category)}return!0}function Bt(r,e){const t=E.get(r);return t?Et(t,e):!1}function $e(){return Array.from(E.values()).map(r=>({id:r.id,name:r.name,category:r.category,controls:r.controls}))}if(typeof window<"u"){window.__DEBUG_FILTERS_LIST=Array.from(E.keys()),window.getAllFilters=Z,window.getFilter=Ue,window.getFiltersByCategory=qe,window.getRegisteredFilters=$e;const r=m;window.registerFilter=e=>{const t=r(e);return window.__DEBUG_FILTERS_LIST=Array.from(E.keys()),t}}typeof window<"u"&&(window.initializeFilterRegistry=window.initializeFilterRegistry||function(){return[]});const{AdjustmentFilter:Ot}=b,{ColorMatrixFilter:Yt}=R,X={gamma:1,saturation:1,contrast:1,brightness:1,red:1,green:1,blue:1,alpha:1},Dt=new Set(["gamma","saturation","contrast","brightness","red","green","blue","alpha"]);function B(r,e){if(typeof r=="number"&&Number.isFinite(r))return r;if(typeof r=="string"){const t=Number(r);if(Number.isFinite(t))return t}return e}function _e(r){return Dt.has(r)}function Lt(r){return{gamma:B(r.gamma,X.gamma),saturation:B(r.saturation,X.saturation),contrast:B(r.contrast,X.contrast),brightness:B(r.brightness,X.brightness),red:B(r.red,X.red),green:B(r.green,X.green),blue:B(r.blue,X.blue),alpha:B(r.alpha,X.alpha)}}function xe(r,e){r.reset(),r.brightness(e.brightness,!0),r.contrast(e.contrast,!0),r.saturate(e.saturation,!0)}m({id:"adjustment",name:"Adjustment",category:"adjust",description:"Adjust basic image properties like brightness, contrast, and saturation",createFilter:r=>{try{const e=Lt(r??{}),t={...e};try{const i=new Ot(t),s=i;return s._customParams={...e},s.updateUIParam=function(n,o){try{if(!_e(n))return;const l=this._customParams??{...X},c=B(o,l[n]);l[n]=c,this._customParams=l;const d=this;n in d&&(d[n]=c)}catch{}},i}catch{const s=new Yt,a=s;return a._customParams={...e},xe(s,e),a.updateUIParam=function(o,l){try{if(!_e(o))return;const c=this._customParams??{...X},d=B(l,c[o]);c[o]=d,this._customParams=c,xe(this,c)}catch{}},s}}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:Vt}=R,V={brightness:1,contrast:1,saturation:1,hue:0,sepia:0,negative:!1},Ut=new Set(["brightness","contrast","saturation","hue","sepia","negative"]);function jt(r){return Ut.has(r)}function $(r,e){if(typeof r=="number"&&Number.isFinite(r))return r;if(typeof r=="string"){const t=Number(r);if(Number.isFinite(t))return t}return e}function We(r,e){if(typeof r=="boolean")return r;if(typeof r=="string"){if(r==="true")return!0;if(r==="false")return!1}return e}function qt(r){return{brightness:$(r.brightness,V.brightness),contrast:$(r.contrast,V.contrast),saturation:$(r.saturation,V.saturation),hue:$(r.hue,V.hue),sepia:$(r.sepia,V.sepia),negative:We(r.negative,V.negative)}}function Ce(r,e){r.reset(),e.brightness!==1&&r.brightness(e.brightness,!0),e.contrast!==1&&r.contrast(e.contrast,!0),e.saturation!==1&&r.saturate(e.saturation,!0),e.hue!==0&&r.hue(e.hue,!0),e.sepia>0&&r.sepia(!0),e.negative&&r.negative(!0)}m({id:"adjustment-advanced",name:"Advanced Adjustment",category:"adjust",description:"Comprehensive image adjustments including brightness, contrast, saturation, hue, and more",createFilter:r=>{try{const e=qt(r??{}),t=new Vt,i=t;return i._customParams={...e},Ce(t,e),i.updateUIParam=function(a,n){try{if(!jt(a))return;const o=this._customParams??{...V};if(a==="negative")o.negative=We(n,o.negative);else{const l=a;o[l]=$(n,o[l])}this._customParams=o,Ce(this,o)}catch{}},t}catch{return null}},defaultParams:{brightness:1,contrast:1,saturation:1,hue:0,sepia:0,negative:!1},controls:[{id:"brightness",type:"slider",label:"Brightness",property:"brightness",min:0,max:2,step:.01,default:1},{id:"contrast",type:"slider",label:"Contrast",property:"contrast",min:0,max:2,step:.01,default:1},{id:"saturation",type:"slider",label:"Saturation",property:"saturation",min:0,max:2,step:.01,default:1},{id:"hue",type:"slider",label:"Hue Rotation",property:"hue",min:0,max:360,step:1,default:0},{id:"sepia",type:"slider",label:"Sepia",property:"sepia",min:0,max:1,step:.01,default:0},{id:"negative",type:"toggle",label:"Negative",property:"negative",default:!1}]});const we=r=>Math.max(0,Math.min(1,r));m({id:"alpha",name:"Alpha",category:"adjust",description:"Adjust the opacity of the image",createFilter:r=>{const e=we(r.alpha!==void 0?Number(r.alpha):1),t=new R.AlphaFilter(e);return t.updateUIParam=function(i,s){i==="alpha"&&(this.alpha=we(Number(s)))},t},defaultParams:{alpha:1},controls:[{id:"alpha",type:"slider",label:"Opacity",property:"alpha",min:0,max:1,step:.01,default:1}]});m({id:"blur",name:"Blur",category:"blur",description:"Apply a smooth blur effect to the entire image",createFilter:r=>{try{const e=new R.BlurFilter({strength:r.blur||8,quality:r.quality||4});return e._customParams={...r},e.updateUIParam=function(t,i){const s=this._customParams||{};switch(this._customParams=s,s[t]=i,t){case"blur":this.strength=i;break;case"quality":this.quality=i;break;default:t in this&&(this[t]=i);break}return!0},e}catch{return null}},defaultParams:{blur:8,quality:4},controls:[{id:"blur",type:"slider",label:"Blur",property:"blur",min:0,max:100,step:.1,default:8},{id:"quality",type:"slider",label:"Quality",property:"quality",min:1,max:10,step:1,default:4}]});function Se(r,e){typeof r.reset=="function"&&r.reset(),e.brightness!==1&&r.brightness(e.brightness,!1),e.contrast!==1&&r.contrast(e.contrast,!1),e.saturation!==1&&r.saturate(e.saturation,!1),e.hue!==0&&r.hue(e.hue,!1),e.sepia&&r.sepia(!1),e.negative&&r.negative(!1)}function ve(r){return{brightness:Number(r.brightness??1),contrast:Number(r.contrast??1),saturation:Number(r.saturation??1),hue:Number(r.hue??0),sepia:!!r.sepia,negative:!!r.negative}}m({id:"color-matrix",name:"Color Matrix",category:"advanced",description:"Advanced color adjustments including sepia, hue rotation, and negative",createFilter:r=>{const e=R.ColorMatrixFilter;if(!e)return null;const t=new e,i=ve(r);return t._customParams={...i},Se(t,i),t.updateUIParam=function(s,a){const n=this._customParams??ve({});switch(s){case"brightness":case"contrast":case"saturation":case"hue":n[s]=Number(a);break;case"sepia":case"negative":n[s]=!!a;break;default:return}this._customParams=n,Se(this,n)},t},defaultParams:{brightness:1,contrast:1,saturation:1,hue:0,sepia:!1,negative:!1},controls:[{id:"brightness",type:"slider",label:"Brightness",property:"brightness",min:0,max:5,step:.1,default:1},{id:"contrast",type:"slider",label:"Contrast",property:"contrast",min:0,max:5,step:.1,default:1},{id:"saturation",type:"slider",label:"Saturation",property:"saturation",min:0,max:5,step:.1,default:1},{id:"hue",type:"slider",label:"Hue Rotation",property:"hue",min:-180,max:180,step:1,default:0},{id:"sepia",type:"toggle",label:"Sepia",property:"sepia",default:!1},{id:"negative",type:"toggle",label:"Negative",property:"negative",default:!1}]});const{ColorOverlayFilter:Ht}=b;m({id:"colorOverlay",name:"Color Overlay",category:"color",description:"Apply a colored tint or overlay to the entire image",createFilter:r=>{try{let e=16711680;r.color&&(typeof r.color=="string"?e=parseInt(r.color.replace("#","0x"),16):typeof r.color=="number"&&(e=r.color));const t=new Ht({color:e,alpha:r.alpha||.5});return t._customParams={...r},t.updateUIParam=function(i,s){const a=this._customParams||{};switch(this._customParams=a,a[i]=s,i){case"color":let n;typeof s=="string"?n=parseInt(s.replace("#","0x"),16):n=Number(s),this.color=n,this.uniforms&&(this.uniforms.uColor=n);break;case"alpha":this.alpha=Number(s),this.uniforms&&(this.uniforms.uAlpha=Number(s));break;default:i in this&&(this[i]=s);break}return!0},t}catch{return null}},defaultParams:{color:"#ff0000",alpha:.5},controls:[{id:"color",type:"color",label:"Color",property:"color",default:"#ff0000"},{id:"alpha",type:"slider",label:"Opacity",property:"alpha",min:0,max:1,step:.01,default:.5}]});m({id:"drop-shadow",name:"Drop Shadow",category:"effects",description:"Add a soft drop shadow to the image",createFilter:r=>{try{const e=r.color?r.color.replace("#","0x"):"0x000000",t=r.distance!==void 0?r.distance:5,i=r.angle!==void 0?r.angle:90,s=r.blur!==void 0?r.blur:2,a=r.quality!==void 0?r.quality:3,n={x:t*Math.cos(i*Math.PI/180),y:t*Math.sin(i*Math.PI/180)},o=new b.DropShadowFilter({offset:n,color:parseInt(e,16),alpha:r.alpha!==void 0?r.alpha:.5,blur:s,quality:a,shadowOnly:r.shadowOnly!==void 0?r.shadowOnly:!1,pixelSize:{x:r.pixelSizeX!==void 0?r.pixelSizeX:1,y:r.pixelSizeY!==void 0?r.pixelSizeY:1}}),l=(h,u,f,_)=>{const g=h*u*2,x=Math.sqrt(f*f+_*_);return Math.ceil(g+x+2)};o._exportPadding=l(s,a,n.x,n.y),o.padding=Math.max(o.padding??0,o._exportPadding),o._customParams={...r,_offset:n,_distance:t,_angle:i};const c=(h,u)=>{const f=Number(h._distance??h.distance??5)*u,_=Number(h._angle??h.angle??90),g=Number(h.blur??2)*u,x=Number(h.quality??3),A={x:f*Math.cos(_*Math.PI/180),y:f*Math.sin(_*Math.PI/180)},P=h.color?String(h.color).replace("#","0x"):"0x000000",T=new b.DropShadowFilter({offset:A,color:parseInt(P,16),alpha:h.alpha!==void 0?Number(h.alpha):.5,blur:g,quality:x,shadowOnly:h.shadowOnly!==void 0?!!h.shadowOnly:!1,pixelSize:{x:h.pixelSizeX!==void 0?Number(h.pixelSizeX):1,y:h.pixelSizeY!==void 0?Number(h.pixelSizeY):1}}),N=l(g,x,A.x,A.y);return T._exportPadding=N,T.padding=Math.max(T.padding??0,N),T};o.createExportFilter=function(h={}){const u=Number.isFinite(h.previewToNativeScale)?Math.max(1,Number(h.previewToNativeScale)):1,f=this._customParams||r;return c(f,u)},o.getExportPadding=function(){return Number(this._exportPadding||this.padding||0)};const d=h=>{var x;const u=((x=h._customParams)==null?void 0:x._offset)??{x:0,y:0},f=Number(h.blur??0),_=Number(h.quality??1),g=l(f,_,u.x,u.y);h._exportPadding=g,h.padding=Math.max(h.padding??0,g)};return o.updateUIParam=function(h,u){try{const f=this._customParams||{};switch(this._customParams=f,f[h]=u,h){case"color":typeof u=="string"&&(this.color=parseInt(u.replace("#","0x"),16));break;case"alpha":this.alpha=Number(u);break;case"blur":this.blur=Number(u),d(this);break;case"quality":this.quality=Number(u),d(this);break;case"shadowOnly":this.shadowOnly=!!u;break;case"pixelSizeX":this.pixelSizeX=Number(u),f.pixelSizeX=Number(u);break;case"pixelSizeY":this.pixelSizeY=Number(u),f.pixelSizeY=Number(u);break;case"distance":case"angle":{h==="distance"?(f._distance=Number(u),f.distance=Number(u)):(f._angle=Number(u),f.angle=Number(u));const _={x:f._distance*Math.cos(f._angle*Math.PI/180),y:f._distance*Math.sin(f._angle*Math.PI/180)};f._offset=_,this.offset=_,d(this);break}default:h in this&&(this[h]=u);break}return!0}catch{return this._customParams&&(this._customParams[h]=u),!1}},o}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:$t}=R;m({id:"grayscale",name:"Grayscale",category:"color",description:"Convert the image to black and white with adjustable intensity",createFilter:r=>{try{const e=new $t;e._customParams={...r};const t=r.intensity!==void 0?r.intensity:1;return Me(e,t),e.updateUIParam=function(i,s){const a=this._customParams||{};switch(this._customParams=a,a[i]=s,i){case"intensity":Me(this,s);break;default:i in this&&(this[i]=s);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 Me(r,e){r.reset(),r.greyscale(e)}const{HslAdjustmentFilter:Wt}=b;m({id:"hsl-adjustment",name:"HSL Adjustment",category:"color",description:"Control hue, saturation, and lightness independently",createFilter:r=>{try{const e=new Wt({hue:r.hue!==void 0?r.hue:0,saturation:r.saturation!==void 0?r.saturation:0,lightness:r.lightness!==void 0?r.lightness:0,colorize:r.colorize!==void 0?r.colorize:!1,alpha:r.alpha!==void 0?r.alpha:1});return e._customParams={...r},e.updateUIParam=function(t,i){try{const s=this._customParams||{};switch(this._customParams=s,s[t]=i,t){case"hue":this.hue=Number(i),this.uniforms&&(this.uniforms.uHue=Number(i));break;case"saturation":this.saturation=Number(i),this.uniforms&&(this.uniforms.uSaturation=Number(i));break;case"lightness":this.lightness=Number(i),this.uniforms&&(this.uniforms.uLightness=Number(i));break;case"colorize":this.colorize=!!i,this.uniforms&&(this.uniforms.uColorize=i?1:0);break;case"alpha":this.alpha=Number(i),this.uniforms&&(this.uniforms.uAlpha=Number(i));break;default:t in this&&(this[t]=i);break}return!0}catch{return this._customParams&&(this._customParams[t]=i),!1}},e}catch{return null}},defaultParams:{hue:0,saturation:0,lightness:0,colorize:!1,alpha:1},controls:[{id:"hue",type:"slider",label:"Hue",property:"hue",min:-180,max:180,step:1,default:0},{id:"saturation",type:"slider",label:"Saturation",property:"saturation",min:-1,max:1,step:.01,default:0},{id:"lightness",type:"slider",label:"Lightness",property:"lightness",min:-1,max:1,step:.01,default:0},{id:"colorize",type:"toggle",label:"Colorize",property:"colorize",default:!1},{id:"alpha",type:"slider",label:"Alpha",property:"alpha",min:0,max:1,step:.01,default:1}]});const{KawaseBlurFilter:Zt}=b;m({id:"kawase-blur",name:"Kawase Blur",category:"blur",description:"A more optimized blur algorithm that is faster than standard blur",createFilter:r=>{try{const e=new Zt({strength:r.strength||4,quality:r.quality||3,clamp:r.clamp||!1,pixelSize:r.pixelSize||1});return e._customParams={...r},e.updateUIParam=function(t,i){const s=this._customParams||{};switch(this._customParams=s,s[t]=i,t){case"strength":this.strength=i;break;case"quality":this.quality=i;break;case"clamp":this.clamp=i;break;case"pixelSize":typeof i=="number"?this.pixelSize=i:typeof i=="object"&&i!==null&&"x"in i&&"y"in i&&(this.pixelSize=i);break;case"pixelSizeX":this.pixelSizeX=i;break;case"pixelSizeY":this.pixelSizeY=i;break;default:t in this&&(this[t]=i);break}return!0},e}catch{return null}},defaultParams:{strength:4,quality:3,clamp:!1,pixelSize:1},controls:[{id:"strength",type:"slider",label:"Strength",property:"strength",min:0,max:20,step:.1,default:4},{id:"quality",type:"slider",label:"Quality",property:"quality",min:1,max:20,step:1,default:3},{id:"clamp",type:"toggle",label:"Clamp Edges",property:"clamp",default:!1},{id:"pixelSize",type:"slider",label:"Pixel Size",property:"pixelSize",min:.5,max:10,step:.5,default:1},{id:"pixelSizeX",type:"slider",label:"Pixel Size X",property:"pixelSizeX",min:0,max:10,step:.1,default:1},{id:"pixelSizeY",type:"slider",label:"Pixel Size Y",property:"pixelSizeY",min:0,max:10,step:.1,default:1}]});const{MotionBlurFilter:Gt}=b;m({id:"motion-blur",name:"Motion Blur",category:"blur",description:"Creates a directional blur effect simulating motion",createFilter:r=>{try{const e=new Gt({velocity:{x:r.velocityX!==void 0?r.velocityX:0,y:r.velocityY!==void 0?r.velocityY:0},kernelSize:r.kernelSize||5,offset:r.offset!==void 0?r.offset:0});return e._customParams={...r},e.updateUIParam=function(t,i){const s=this._customParams||{};switch(this._customParams=s,s[t]=i,t){case"velocityX":this.velocityX=i;break;case"velocityY":this.velocityY=i;break;case"kernelSize":this.kernelSize=i;break;case"offset":this.offset=i;break;default:t in this&&(this[t]=i);break}return!0},e}catch{return null}},defaultParams:{velocityX:0,velocityY:0,kernelSize:5,offset:0},controls:[{id:"velocityX",type:"slider",label:"Velocity X",property:"velocityX",min:-90,max:90,step:1,default:0},{id:"velocityY",type:"slider",label:"Velocity Y",property:"velocityY",min:-90,max:90,step:1,default:0},{id:"kernelSize",type:"select",label:"Kernel Size",property:"kernelSize",options:[{label:"3",value:3},{label:"5",value:5},{label:"7",value:7},{label:"9",value:9},{label:"11",value:11},{label:"13",value:13},{label:"15",value:15},{label:"17",value:17},{label:"19",value:19},{label:"21",value:21},{label:"23",value:23},{label:"25",value:25}],default:5},{id:"offset",type:"slider",label:"Offset",property:"offset",min:-150,max:150,step:1,default:0}]});const{RadialBlurFilter:Kt}=b;m({id:"radial-blur",name:"Radial Blur",category:"blur",description:"Creates a circular blur effect emanating from a center point",createFilter:r=>{try{const e=new Kt({angle:r.angle??20,center:{x:r.centerX??0,y:r.centerY??0},kernelSize:r.kernelSize??15,radius:r.radius??300});return e._customParams={centerX:r.centerX??0,centerY:r.centerY??0},e.updateUIParam=function(t,i){try{switch(t){case"angle":this.angle=Number(i);break;case"centerX":this._customParams.centerX=Number(i),this.center={x:Number(i),y:this._customParams.centerY};break;case"centerY":this._customParams.centerY=Number(i),this.center={x:this._customParams.centerX,y:Number(i)};break;case"kernelSize":this.kernelSize=Number(i);break;case"radius":this.radius=Number(i);break;default:}}catch{}},e}catch{return null}},defaultParams:{angle:20,centerX:0,centerY:0,kernelSize:15,radius:300},controls:[{id:"angle",type:"slider",label:"Angle",property:"angle",min:-180,max:180,step:1,default:20},{id:"centerX",type:"slider",label:"Center X",property:"centerX",min:-1,max:1,step:.01,default:0},{id:"centerY",type:"slider",label:"Center Y",property:"centerY",min:-1,max:1,step:.01,default:0},{id:"kernelSize",type:"select",label:"Kernel Size",property:"kernelSize",options:[{label:"3",value:3},{label:"5",value:5},{label:"7",value:7},{label:"9",value:9},{label:"11",value:11},{label:"13",value:13},{label:"15",value:15},{label:"17",value:17},{label:"19",value:19},{label:"21",value:21},{label:"23",value:23},{label:"25",value:25}],default:15},{id:"radius",type:"slider",label:"Radius",property:"radius",min:-1,max:1e3,step:10,default:300}]});const{TiltShiftFilter:Qt}=b;m({id:"tilt-shift",name:"Tilt Shift",category:"blur",description:"Creates a depth-of-field effect simulating miniature photography",createFilter:r=>{try{const e=typeof r.blur=="number"?r.blur:100,t=typeof r.gradientBlur=="number"?r.gradientBlur:600,i=typeof r.startX=="number"?r.startX:0,s=typeof r.startY=="number"?r.startY:.5,a=typeof r.endX=="number"?r.endX:1,n=typeof r.endY=="number"?r.endY:.5,o=new Qt({blur:Number(e),gradientBlur:Number(t),start:{x:Number(i),y:Number(s)},end:{x:Number(a),y:Number(n)}});return o._customParams={blur:e,gradientBlur:t,startX:i,startY:s,endX:a,endY:n},o.updateUIParam=function(l,c){try{const d=Number(c),h=this._customParams||{};switch(this._customParams=h,h[l]=d,l){case"blur":this.blur=d;break;case"gradientBlur":this.gradientBlur=d;break;case"startX":this.start&&typeof this.start=="object"&&(this.start.x=d);break;case"startY":this.start&&typeof this.start=="object"&&(this.start.y=d);break;case"endX":this.end&&typeof this.end=="object"&&(this.end.x=d);break;case"endY":this.end&&typeof this.end=="object"&&(this.end.y=d);break;default:l in this&&(this[l]=d);break}}catch{}},o}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:Jt}=b;m({id:"zoom-blur",name:"Zoom Blur",category:"blur",description:"Creates a zoom blur effect from a center point",createFilter:r=>{try{const e=new Jt({strength:r.strength||.1,center:{x:r.centerX!==void 0?r.centerX:.5,y:r.centerY!==void 0?r.centerY:.5},innerRadius:r.innerRadius||80,radius:r.radius!==void 0?r.radius:-1,maxKernelSize:r.maxKernelSize||32});return e._customParams={...r},e.updateUIParam=function(t,i){const s=this._customParams||{};switch(this._customParams=s,s[t]=i,t){case"strength":this.strength=i;break;case"centerX":this.centerX=i;break;case"centerY":this.centerY=i;break;case"innerRadius":this.innerRadius=i;break;case"radius":this.radius=i;break;default:t in this&&(this[t]=i);break}return!0},e}catch{return null}},defaultParams:{strength:.1,centerX:.5,centerY:.5,innerRadius:80,radius:-1,maxKernelSize:32},controls:[{id:"strength",type:"slider",label:"Strength",property:"strength",min:0,max:.5,step:.01,default:.1},{id:"centerX",type:"slider",label:"Center X",property:"centerX",min:0,max:1,step:.01,default:.5},{id:"centerY",type:"slider",label:"Center Y",property:"centerY",min:0,max:1,step:.01,default:.5},{id:"innerRadius",type:"slider",label:"Inner Radius",property:"innerRadius",min:0,max:1e3,step:1,default:80},{id:"radius",type:"slider",label:"Outer Radius",property:"radius",min:-1,max:1e3,step:10,default:-1},{id:"maxKernelSize",type:"select",label:"Quality",property:"maxKernelSize",options:[{label:"Low",value:16},{label:"Medium",value:32},{label:"High",value:48},{label:"Very High",value:64}],default:32}]});const{ColorGradientFilter:Pe}=b;function Ze(r){return parseInt(r.replace("#","0x"),16)}function ei(r){return"#"+r.toString(16).padStart(6,"0")}function ke(r){return{offset:Number(r.offset),color:typeof r.color=="string"?Ze(r.color):Number(r.color),alpha:Number(r.alpha)}}function Fe(r){return{offset:r.offset,color:typeof r.color=="number"?ei(r.color):r.color,alpha:r.alpha}}m({id:"color-gradient",name:"Color Gradient",category:"color",description:"Applies a linear, radial or conic color gradient over the image with multiple color stops",createFilter:r=>{let t=(r.colorStops||[{offset:0,color:"#ff0000",alpha:1},{offset:1,color:"#0000ff",alpha:1}]).map(ke);t.length<2&&(t=[{offset:0,color:16711680,alpha:1},{offset:1,color:255,alpha:1}]),t.sort((s,a)=>s.offset-a.offset);const i=new Pe({type:r.gradientType,stops:t,angle:r.angle,alpha:r.alpha,maxColors:r.maxColors||0,replace:r.replace});return i._customParams={cssGradient:r.cssGradient||""},i.getSerializableParams=function(){var a;const s=Array.isArray(this.stops)?this.stops.map(Fe):[];return{gradientType:this.type,colorStops:s,angle:this.angle,alpha:this.alpha,maxColors:this.maxColors,replace:this.replace,cssGradient:((a=this._customParams)==null?void 0:a.cssGradient)??""}},i.getColorStopsForUI=function(){return Array.isArray(this.stops)?this.stops.map(Fe):[]},i.getDynamicControls=function(){const s=this.getColorStopsForUI(),a=[];return s.forEach((n,o)=>{a.push({id:`colorStop-${o}-color`,type:"color",label:`Stop ${o+1} Color`,property:`colorStops[${o}].color`,default:n.color}),a.push({id:`colorStop-${o}-offset`,type:"slider",label:`Stop ${o+1} Position`,property:`colorStops[${o}].offset`,min:0,max:1,step:.01,default:n.offset}),a.push({id:`colorStop-${o}-alpha`,type:"slider",label:`Stop ${o+1} Alpha`,property:`colorStops[${o}].alpha`,min:0,max:1,step:.01,default:n.alpha})}),a},i.handleButtonAction=function(s){(s==="addColorStop"||s==="removeColorStop")&&this.updateUIParam(s,!0)},i.updateUIParam=function(s,a){const n=this._customParams??{};switch(this._customParams=n,s){case"gradientType":this.type=Number(a);return;case"angle":case"alpha":case"maxColors":this[s]=Number(a);return;case"replace":this.replace=!!a;return;case"addColorStop":{const o=Array.isArray(this.stops)?[...this.stops]:[],l=Math.floor(Math.random()*255)<<16|Math.floor(Math.random()*255)<<8|Math.floor(Math.random()*255);if(o.length>0)for(const d of o)d.offset*=.8;o.push({offset:1,color:l,alpha:1}),o.sort((c,d)=>c.offset-d.offset),this.stops=o;return}case"removeColorStop":{const o=Array.isArray(this.stops)?[...this.stops]:[];o.length>2&&(o.pop(),this.stops=o);return}case"cssGradient":{const o=typeof a=="string"?a.trim():"";if(n.cssGradient=o,!o)return;try{const l=new Pe({css:o});this.type=l.type,this.angle=l.angle,this.stops=[...l.stops]}catch{}return}case"colorStops":{if(!Array.isArray(a))return;const o=a.map(ke);o.sort((l,c)=>l.offset-c.offset),this.stops=o;return}default:{const o=/^colorStops\[(\d+)\]\.(offset|color|alpha)$/.exec(s);if(o){const[,l,c]=o,d=Number(l),h=Array.isArray(this.stops)?[...this.stops]:[];if(d<0||d>=h.length)return;c==="color"?h[d].color=typeof a=="string"?Ze(a):Number(a):(c==="offset"||c==="alpha")&&(h[d][c]=Number(a)),this.stops=h}}}},i},defaultParams:{gradientType:0,colorStops:[{offset:0,color:"#ff0000",alpha:1},{offset:1,color:"#0000ff",alpha:1}],cssGradient:"",angle:90,alpha:.75,maxColors:0,replace:!1},controls:[{id:"gradientType",type:"select",label:"Gradient Type",property:"gradientType",options:[{label:"Linear",value:0},{label:"Radial",value:1},{label:"Conic",value:2}],default:0},{id:"angle",type:"slider",label:"Angle",property:"angle",min:0,max:360,step:1,default:90},{id:"alpha",type:"slider",label:"Overall Alpha",property:"alpha",min:0,max:1,step:.01,default:.75},{id:"maxColors",type:"slider",label:"Max Colors",property:"maxColors",min:0,max:24,step:1,default:0},{id:"replace",type:"toggle",label:"Replace Original Colors",property:"replace",default:!1},{id:"addColorStop",type:"button",label:"Add New Color Stop",action:"addColorStop"},{id:"removeColorStop",type:"button",label:"Remove Last Color Stop",action:"removeColorStop"},{id:"cssGradient",type:"text",label:"CSS Gradient",property:"cssGradient",default:"",placeholder:"e.g. linear-gradient(to right, red, blue)"}]});m({id:"color-map",name:"Color Map",category:"color",description:"Maps colors using a reference texture as a lookup table",createFilter:r=>{try{const e=b.ColorMapFilter;if(!e)return null;let t=null;r.texturePath?t=R.Texture.from(r.texturePath):t=R.Texture.from("/examples/filters-main/examples/images/colormap.png");const i=new e({colorMap:t,nearest:r.nearest,mix:r.mix});return i._customParams={...r},i.updateUIParam=function(s,a){const n=this._customParams||{};switch(this._customParams=n,n[s]=a,s){case"texturePath":a&&(this.colorMap=R.Texture.from(a));break;case"mix":this.mix=a;break;case"nearest":this.nearest=a;break;default:s in this&&(this[s]=a);break}return!0},i}catch{return null}},defaultParams:{texturePath:"",mix:1,nearest:!1},controls:[{id:"texturePath",type:"select",label:"Color Map",property:"texturePath",options:[{label:"Default",value:"/examples/filters-main/examples/images/colormap.png"},{label:"Grayscale",value:"/examples/filters-main/examples/images/colormap-grayscale.png"},{label:"Sepia",value:"/examples/filters-main/examples/images/colormap-sepia.png"}],default:"/examples/filters-main/examples/images/colormap.png"},{id:"mix",type:"slider",label:"Mix",property:"mix",min:0,max:1,step:.01,default:1},{id:"nearest",type:"toggle",label:"Nearest Neighbor Sampling",property:"nearest",default:!1}]});const ti=b.ColorReplaceFilter;m({id:"color-replace",name:"Color Replace",category:"color",description:"Replaces a specific color in the image with another color",createFilter:r=>{try{let e=16711680;r.originalColor&&(typeof r.originalColor=="string"?e=parseInt(r.originalColor.replace("#","0x"),16):typeof r.originalColor=="number"&&(e=r.originalColor));let t=255;r.targetColor&&(typeof r.targetColor=="string"?t=parseInt(r.targetColor.replace("#","0x"),16):typeof r.targetColor=="number"&&(t=r.targetColor));const i=new ti({originalColor:e,targetColor:t,tolerance:r.tolerance||.4});return i._customParams={...r},i.updateUIParam=function(s,a){const n=this._customParams||{};switch(this._customParams=n,n[s]=a,s){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:s in this&&(this[s]=a);break}return!0},i}catch{return null}},defaultParams:{originalColor:"#ff0000",targetColor:"#0000ff",tolerance:.4},controls:[{id:"originalColor",type:"color",label:"Original Color",property:"originalColor",default:"#ff0000"},{id:"targetColor",type:"color",label:"Target Color",property:"targetColor",default:"#0000ff"},{id:"tolerance",type:"slider",label:"Tolerance",property:"tolerance",min:0,max:1,step:.01,default:.4}]});const ii=b.MultiColorReplaceFilter;m({id:"multi-color-replace",name:"Multi-Color Replace",category:"color",description:"Replaces multiple colors in the image with different target colors",createFilter:r=>{try{const e=[];if(r.originalColor1&&r.targetColor1){const i=typeof r.originalColor1=="string"?parseInt(r.originalColor1.replace("#","0x"),16):r.originalColor1,s=typeof r.targetColor1=="string"?parseInt(r.targetColor1.replace("#","0x"),16):r.targetColor1;e.push([i,s])}if(r.originalColor2&&r.targetColor2){const i=typeof r.originalColor2=="string"?parseInt(r.originalColor2.replace("#","0x"),16):r.originalColor2,s=typeof r.targetColor2=="string"?parseInt(r.targetColor2.replace("#","0x"),16):r.targetColor2;e.push([i,s])}if(r.enableThirdPair&&r.originalColor3&&r.targetColor3){const i=typeof r.originalColor3=="string"?parseInt(r.originalColor3.replace("#","0x"),16):r.originalColor3,s=typeof r.targetColor3=="string"?parseInt(r.targetColor3.replace("#","0x"),16):r.targetColor3;e.push([i,s])}const t=new ii(e,r.tolerance||.05,3);return t._customParams={...r},t.updateUIParam=function(i,s){const a=this._customParams||{};if(this._customParams=a,a[i]=s,i==="originalColor1"||i==="targetColor1"||i==="originalColor2"||i==="targetColor2"||i==="originalColor3"||i==="targetColor3"||i==="enableThirdPair"){const n=[];if(a.originalColor1&&a.targetColor1){const o=typeof a.originalColor1=="string"?parseInt(a.originalColor1.replace("#","0x"),16):a.originalColor1,l=typeof a.targetColor1=="string"?parseInt(a.targetColor1.replace("#","0x"),16):a.targetColor1;n.push([o,l])}if(a.originalColor2&&a.targetColor2){const o=typeof a.originalColor2=="string"?parseInt(a.originalColor2.replace("#","0x"),16):a.originalColor2,l=typeof a.targetColor2=="string"?parseInt(a.targetColor2.replace("#","0x"),16):a.targetColor2;n.push([o,l])}if(a.enableThirdPair&&a.originalColor3&&a.targetColor3){const o=typeof a.originalColor3=="string"?parseInt(a.originalColor3.replace("#","0x"),16):a.originalColor3,l=typeof a.targetColor3=="string"?parseInt(a.targetColor3.replace("#","0x"),16):a.targetColor3;n.push([o,l])}this.replacements=n,this.refresh()}else i==="tolerance"?this.tolerance=s:i in this&&(this[i]=s);return!0},t}catch{return null}},defaultParams:{originalColor1:"#ff0000",targetColor1:"#0000ff",originalColor2:"#00ff00",targetColor2:"#ffff00",enableThirdPair:!1,originalColor3:"#ff00ff",targetColor3:"#00ffff",tolerance:.05},controls:[{id:"originalColor1",type:"color",label:"Original Color 1",property:"originalColor1",default:"#ff0000"},{id:"targetColor1",type:"color",label:"Target Color 1",property:"targetColor1",default:"#0000ff"},{id:"originalColor2",type:"color",label:"Original Color 2",property:"originalColor2",default:"#00ff00"},{id:"targetColor2",type:"color",label:"Target Color 2",property:"targetColor2",default:"#ffff00"},{id:"enableThirdPair",type:"toggle",label:"Enable Third Color Pair",property:"enableThirdPair",default:!1},{id:"originalColor3",type:"color",label:"Original Color 3",property:"originalColor3",default:"#ff00ff"},{id:"targetColor3",type:"color",label:"Target Color 3",property:"targetColor3",default:"#00ffff"},{id:"tolerance",type:"slider",label:"Tolerance",property:"tolerance",min:0,max:.5,step:.01,default:.05}]});const{RGBSplitFilter:ri}=b;m({id:"rgb-split",name:"RGB Split",category:"color",description:"Shifts the red, green, and blue channels to create a retro 3D or glitch effect",createFilter:r=>{try{const e={x:r.redX!==void 0?r.redX:-10,y:r.redY!==void 0?r.redY:0},t={x:r.greenX!==void 0?r.greenX:0,y:r.greenY!==void 0?r.greenY:10},i={x:r.blueX!==void 0?r.blueX:0,y:r.blueY!==void 0?r.blueY:0},s=new ri({red:e,green:t,blue:i});return s._customParams={...r},s.updateUIParam=function(a,n){try{const o=this._customParams||{};switch(this._customParams=o,o[a]=n,a){case"redX":this.redX=Number(n);break;case"redY":this.redY=Number(n);break;case"greenX":this.greenX=Number(n);break;case"greenY":this.greenY=Number(n);break;case"blueX":this.blueX=Number(n);break;case"blueY":this.blueY=Number(n);break;default:a in this&&(this[a]=n);break}return!0}catch{return this._customParams&&(this._customParams[a]=n),!1}},s}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:si}=b;m({id:"advanced-bloom",name:"Advanced Bloom",category:"light",description:"Adds a sophisticated bloom/glow effect with fine-grained control",createFilter:r=>{try{const e=new si({threshold:r.threshold||.5,bloomScale:r.bloomScale||1,brightness:r.brightness||1,blur:r.blur||8,quality:r.quality||4,pixelSize:{x:r.pixelSizeX||1,y:r.pixelSizeY||1}});return e._customParams={pixelSizeX:r.pixelSizeX||1,pixelSizeY:r.pixelSizeY||1},e.updateUIParam=function(t,i){try{const s=this._customParams||{};switch(this._customParams=s,s[t]=i,t){case"threshold":this.threshold=Number(i);break;case"bloomScale":this.bloomScale=Number(i);break;case"brightness":this.brightness=Number(i);break;case"blur":this.blur=Number(i);break;case"quality":this.quality=Number(i);break;case"pixelSizeX":s.pixelSizeX=Number(i),this.pixelSize={x:Number(i),y:s.pixelSizeY};break;case"pixelSizeY":s.pixelSizeY=Number(i),this.pixelSize={x:s.pixelSizeX,y:Number(i)};break;default:t in this&&(this[t]=i);break}}catch{}},e}catch{return null}},defaultParams:{threshold:.5,bloomScale:1,brightness:1,blur:8,quality:4,pixelSizeX:1,pixelSizeY:1},controls:[{id:"threshold",type:"slider",label:"Threshold",property:"threshold",min:0,max:1,step:.01,default:.5},{id:"bloomScale",type:"slider",label:"Bloom Intensity",property:"bloomScale",min:0,max:3,step:.1,default:1},{id:"brightness",type:"slider",label:"Brightness",property:"brightness",min:0,max:3,step:.1,default:1},{id:"blur",type:"slider",label:"Blur Strength",property:"blur",min:0,max:20,step:1,default:8},{id:"quality",type:"slider",label:"Quality",property:"quality",min:1,max:10,step:1,default:4},{id:"pixelSizeX",type:"slider",label:"Pixel Size X",property:"pixelSizeX",min:.5,max:10,step:.5,default:1},{id:"pixelSizeY",type:"slider",label:"Pixel Size Y",property:"pixelSizeY",min:.5,max:10,step:.5,default:1}]});const ai=b.AsciiFilter;m({id:"ascii",name:"ASCII",category:"stylize",description:"Convert image to ASCII text characters",createFilter:r=>{try{const e=typeof r.size=="number"?r.size:8;let t=r.color;typeof t=="string"&&t.startsWith("#")&&(t=parseInt(t.replace("#","0x"),16));const i=r.replaceColor===!0,s=new ai({size:e,color:t,replaceColor:i});return s._customParams={size:e,color:t,replaceColor:i},s.updateUIParam=function(a,n){try{const o=this._customParams||{};switch(this._customParams=o,o[a]=n,a){case"size":this.size=Number(n);break;case"color":typeof n=="string"&&n.startsWith("#")?(o.color=n,this.color=parseInt(n.replace("#","0x"),16)):this.color=n;break;case"replaceColor":this.replaceColor=!!n;break;default:a in this&&(this[a]=n);break}}catch{}},s}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 ni=b.BackdropBlurFilter;m({id:"backdrop-blur",name:"Backdrop Blur",category:"blur",description:"Blurs what is behind the object, creating a glass-like effect",createFilter:r=>{try{const e=new ni({strength:r.strength||20,quality:r.quality||4,resolution:r.resolution||.5,kernelSize:r.kernelSize||9});return e._customParams={...r},e.updateUIParam=function(t,i){try{const s=this._customParams||{};switch(this._customParams=s,s[t]=i,t){case"strength":this.strength=Number(i),this.blur=Number(i)/4;break;case"quality":this.quality=Number(i);break;case"resolution":this.resolution=Number(i);break;case"kernelSize":const a=Number(i);this.blurXFilter&&this.blurYFilter?(this.blurXFilter.kernelSize=a,this.blurYFilter.kernelSize=a):this.kernelSize=a;break;default:t in this&&(this[t]=i);break}}catch{}},e}catch{return null}},defaultParams:{strength:20,quality:4,resolution:.5,kernelSize:9},controls:[{id:"strength",type:"slider",label:"Strength",property:"strength",min:0,max:50,step:1,default:20},{id:"quality",type:"slider",label:"Quality",property:"quality",min:1,max:10,step:1,default:4},{id:"resolution",type:"slider",label:"Resolution",property:"resolution",min:.1,max:1,step:.1,default:.5},{id:"kernelSize",type:"select",label:"Kernel Size",property:"kernelSize",options:[{label:"5",value:5},{label:"7",value:7},{label:"9",value:9},{label:"11",value:11},{label:"13",value:13},{label:"15",value:15}],default:9}]});const{BevelFilter:oi}=b;m({id:"bevel",name:"Bevel",category:"effects",description:"Add a 3D-like beveled edge effect to the image",createFilter:r=>{try{const e=r.lightColor?r.lightColor.replace("#","0x"):"0xffffff",t=r.shadowColor?r.shadowColor.replace("#","0x"):"0x000000",i=new oi({rotation:r.rotation!==void 0?r.rotation:45,thickness:r.thickness!==void 0?r.thickness:2,lightColor:parseInt(e,16),lightAlpha:r.lightAlpha!==void 0?r.lightAlpha:.7,shadowColor:parseInt(t,16),shadowAlpha:r.shadowAlpha!==void 0?r.shadowAlpha:.7});return i._customParams={...r},i.updateUIParam=function(s,a){try{const n=this._customParams||{};switch(this._customParams=n,n[s]=a,s){case"rotation":this.rotation=Number(a);break;case"thickness":this.thickness=Number(a);break;case"lightColor":if(typeof a=="string"){const o=parseInt(a.replace("#","0x"),16);this.lightColor=o}break;case"lightAlpha":this.lightAlpha=Number(a);break;case"shadowColor":if(typeof a=="string"){const o=parseInt(a.replace("#","0x"),16);this.shadowColor=o}break;case"shadowAlpha":this.shadowAlpha=Number(a);break;default:s in this&&(this[s]=a);break}return!0}catch{return this._customParams&&(this._customParams[s]=a),!1}},i}catch{return null}},defaultParams:{rotation:45,thickness:2,lightColor:"#ffffff",lightAlpha:.7,shadowColor:"#000000",shadowAlpha:.7},controls:[{id:"rotation",type:"slider",label:"Angle",property:"rotation",min:0,max:360,step:1,default:45},{id:"thickness",type:"slider",label:"Thickness",property:"thickness",min:0,max:10,step:.1,default:2},{id:"lightColor",type:"color",label:"Light Color",property:"lightColor",default:"#ffffff"},{id:"lightAlpha",type:"slider",label:"Light Opacity",property:"lightAlpha",min:0,max:1,step:.01,default:.7},{id:"shadowColor",type:"color",label:"Shadow Color",property:"shadowColor",default:"#000000"},{id:"shadowAlpha",type:"slider",label:"Shadow Opacity",property:"shadowAlpha",min:0,max:1,step:.01,default:.7}]});const{BloomFilter:li}=b;m({id:"bloom",name:"Bloom/Glow",category:"light",description:"Add a subtle glow effect to bright areas of the image",createFilter:r=>{try{const e=typeof r.strengthX=="number"?r.strengthX:2,t=typeof r.strengthY=="number"?r.strengthY:2,i=typeof r.quality=="number"?r.quality:4,s=typeof r.resolution=="number"?r.resolution:1,a=typeof r.kernelSize=="number"?r.kernelSize:5,n=new li({strength:{x:Number(e),y:Number(t)},quality:Number(i),resolution:Number(s),kernelSize:Number(a)});return n._customParams={strengthX:e,strengthY:t,quality:i,resolution:s,kernelSize:a},n.updateUIParam=function(o,l){var c,d;try{const h=Number(l),u=this._customParams||{};switch(this._customParams=u,u[o]=h,o){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:o in this&&(this[o]=h);break}}catch{}},n}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:Ae}=b,ne=r=>{const e=Math.max(0,Number(r)||0);return Math.ceil(e+2)};m({id:"bulge-pinch",name:"Bulge/Pinch",category:"distortion",description:"Creates a bulge or pinch effect in a circular area",createFilter:r=>{try{const e=r.centerX??.5,t=r.centerY??.5,i=r.radius??100,s=r.strength??1,a=new Ae({center:{x:e,y:t},radius:i,strength:s}),n=ne(i);a.padding=Math.max(a.padding??0,n),a._exportPadding=n,a._customParams={...r};const o=l=>{var h;const c=Number(((h=l._customParams)==null?void 0:h.radius)??l.radius??0),d=ne(c);l._exportPadding=d,l.padding=Math.max(l.padding??0,d)};return a.updateUIParam=function(l,c){const d=this._customParams||{};switch(this._customParams=d,d[l]=c,l){case"centerX":this.center||(this.center={x:.5,y:.5}),this.center.x=c;break;case"centerY":this.center||(this.center={x:.5,y:.5}),this.center.y=c;break;case"radius":this.radius=Number(c),o(this);break;case"strength":this.strength=Number(c);break;default:l in this&&(this[l]=c);break}return!0},a.createExportFilter=function(l={}){const c=Number.isFinite(l.previewToNativeScale)?Math.max(1,Number(l.previewToNativeScale)):1,d=this._customParams||r,h=Number(d.radius??100)*c,u=new Ae({center:{x:Number(d.centerX??.5),y:Number(d.centerY??.5)},radius:h,strength:Number(d.strength??1)}),f=ne(h);return u._exportPadding=f,u.padding=Math.max(u.padding??0,f),u},a.getExportPadding=function(){return Number(this._exportPadding||this.padding||0)},a}catch{return null}},defaultParams:{centerX:.5,centerY:.5,radius:100,strength:1},controls:[{id:"centerX",type:"slider",label:"Center X",property:"centerX",min:0,max:1,step:.01,default:.5},{id:"centerY",type:"slider",label:"Center Y",property:"centerY",min:0,max:1,step:.01,default:.5},{id:"radius",type:"slider",label:"Radius",property:"radius",min:0,max:1e3,step:1,default:100},{id:"strength",type:"slider",label:"Strength",property:"strength",min:-1,max:1,step:.01,default:1}]});const{ConvolutionFilter:ci}=b,q={normal:[0,0,0,0,1,0,0,0,0],gaussianBlur:[.045,.122,.045,.122,.332,.122,.045,.122,.045],boxBlur:[1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9],edgeDetection:[-1,-1,-1,-1,8,-1,-1,-1,-1],edgeEnhance:[0,0,0,-1,1,0,0,0,0],emboss:[-2,-1,0,-1,1,1,0,1,2],sharpen:[0,-1,0,-1,5,-1,0,-1,0],sobelHorizontal:[1,2,1,0,0,0,-1,-2,-1],sobelVertical:[1,0,-1,2,0,-2,1,0,-1]};m({id:"convolution",name:"Convolution Matrix",category:"effects",description:"Apply custom image effects using matrix convolution",createFilter:r=>{try{let e;if(r.customMatrix)e=[r.m00,r.m01,r.m02,r.m10,r.m11,r.m12,r.m20,r.m21,r.m22];else{const i=r.preset;e=q[i]||q.normal}const t=new ci(e,r.width||200,r.height||200);return t._customParams={...r},t.updateUIParam=function(i,s){const a=this._customParams||{};switch(this._customParams=a,a[i]=s,i){case"preset":if(!a.customMatrix){const n=s;q[n]&&(this.matrix=q[n])}break;case"customMatrix":if(s){const n=this.matrix;a.m00=n[0],a.m01=n[1],a.m02=n[2],a.m10=n[3],a.m11=n[4],a.m12=n[5],a.m20=n[6],a.m21=n[7],a.m22=n[8]}else{const n=a.preset;this.matrix=q[n]||q.normal}break;case"m00":case"m01":case"m02":case"m10":case"m11":case"m12":case"m20":case"m21":case"m22":if(a.customMatrix){const n=[...this.matrix],l={m00:0,m01:1,m02:2,m10:3,m11:4,m12:5,m20:6,m21:7,m22:8}[i];l!==void 0&&(n[l]=s,this.matrix=n)}break;case"width":this.width=s;break;case"height":this.height=s;break;default:i in this&&(this[i]=s);break}},t}catch{return null}},defaultParams:{preset:"normal",customMatrix:!1,m00:0,m01:0,m02:0,m10:0,m11:1,m12:0,m20:0,m21:0,m22:0,width:200,height:200},controls:[{id:"preset",type:"select",label:"Effect Preset",property:"preset",options:[{value:"normal",label:"Normal"},{value:"gaussianBlur",label:"Gaussian Blur"},{value:"boxBlur",label:"Box Blur"},{value:"edgeDetection",label:"Edge Detection"},{value:"edgeEnhance",label:"Edge Enhance"},{value:"emboss",label:"Emboss"},{value:"sharpen",label:"Sharpen"},{value:"sobelHorizontal",label:"Sobel Horizontal"},{value:"sobelVertical",label:"Sobel Vertical"}],default:"normal"},{id:"customMatrix",type:"toggle",label:"Use Custom Matrix",property:"customMatrix",default:!1},{id:"width",type:"slider",label:"Width",property:"width",min:50,max:500,step:10,default:200},{id:"height",type:"slider",label:"Height",property:"height",min:50,max:500,step:10,default:200},{id:"m00",type:"slider",label:"Matrix [0,0]",property:"m00",min:-5,max:5,step:.1,default:0},{id:"m01",type:"slider",label:"Matrix [0,1]",property:"m01",min:-5,max:5,step:.1,default:0},{id:"m02",type:"slider",label:"Matrix [0,2]",property:"m02",min:-5,max:5,step:.1,default:0},{id:"m10",type:"slider",label:"Matrix [1,0]",property:"m10",min:-5,max:5,step:.1,default:0},{id:"m11",type:"slider",label:"Matrix [1,1]",property:"m11",min:-5,max:5,step:.1,default:1},{id:"m12",type:"slider",label:"Matrix [1,2]",property:"m12",min:-5,max:5,step:.1,default:0},{id:"m20",type:"slider",label:"Matrix [2,0]",property:"m20",min:-5,max:5,step:.1,default:0},{id:"m21",type:"slider",label:"Matrix [2,1]",property:"m21",min:-5,max:5,step:.1,default:0},{id:"m22",type:"slider",label:"Matrix [2,2]",property:"m22",min:-5,max:5,step:.1,default:0}]});const{CrossHatchFilter:hi}=b;m({id:"cross-hatch",name:"Cross Hatch",category:"stylize",description:"Creates a crosshatching effect like in a pencil drawing",createFilter:r=>{try{const e=new hi;return e.updateUIParam=function(t,i){return!0},e}catch{return null}},defaultParams:{},controls:[]});m({id:"crt",name:"CRT Screen",category:"stylize",description:"Simulates an old CRT screen with scan lines and noise",createFilter:r=>{try{const e={lineWidth:typeof r.lineWidth=="number"?r.lineWidth:1,noise:typeof r.noise=="number"?r.noise:.3,curvature:typeof r.curvature=="number"?r.curvature:1,lineContrast:typeof r.lineContrast=="number"?r.lineContrast:.25,verticalLine:r.verticalLine===!0,noiseSize:typeof r.noiseSize=="number"?r.noiseSize:1,vignetting:typeof r.vignetting=="number"?r.vignetting:.3,vignettingAlpha:typeof r.vignettingAlpha=="number"?r.vignettingAlpha:1,vignettingBlur:typeof r.vignettingBlur=="number"?r.vignettingBlur:.3,time:typeof r.time=="number"?r.time:0,seed:typeof r.seed=="number"?r.seed:Math.random()},t=new b.CRTFilter(e);return t._customParams={...e},t.updateUIParam=function(i,s){try{const a=this._customParams||{};switch(this._customParams=a,a[i]=s,i){case"lineWidth":this.lineWidth=Number(s);break;case"noise":this.noise=Number(s);break;case"curvature":this.curvature=Number(s);break;case"lineContrast":this.lineContrast=Number(s);break;case"verticalLine":this.verticalLine=!!s;break;case"noiseSize":this.noiseSize=Number(s);break;case"vignetting":this.vignetting=Number(s);break;case"vignettingAlpha":this.vignettingAlpha=Number(s);break;case"vignettingBlur":this.vignettingBlur=Number(s);break;case"time":this.time=Number(s);break;case"seed":this.seed=Number(s);break;default:i in this&&(this[i]=s);break}}catch{}},t}catch{return null}},defaultParams:{lineWidth:1,noise:.3,curvature:1,lineContrast:.25,verticalLine:!1,noiseSize:1,vignetting:.3,vignettingAlpha:1,vignettingBlur:.3,time:0,seed:1},controls:[{id:"lineWidth",type:"slider",label:"Scan Line Width",property:"lineWidth",min:0,max:5,step:.1,default:1},{id:"noise",type:"slider",label:"Noise Amount",property:"noise",min:0,max:1,step:.01,default:.3},{id:"curvature",type:"slider",label:"Screen Curvature",property:"curvature",min:0,max:10,step:.1,default:1},{id:"lineContrast",type:"slider",label:"Line Contrast",property:"lineContrast",min:0,max:1,step:.01,default:.25},{id:"verticalLine",type:"toggle",label:"Vertical Lines",property:"verticalLine",default:!1},{id:"noiseSize",type:"slider",label:"Noise Size",property:"noiseSize",min:.5,max:5,step:.1,default:1},{id:"vignetting",type:"slider",label:"Vignette Size",property:"vignetting",min:0,max:1,step:.01,default:.3},{id:"vignettingAlpha",type:"slider",label:"Vignette Opacity",property:"vignettingAlpha",min:0,max:1,step:.01,default:1},{id:"vignettingBlur",type:"slider",label:"Vignette Blur",property:"vignettingBlur",min:0,max:1,step:.01,default:.3},{id:"time",type:"slider",label:"Animation Time",property:"time",min:0,max:10,step:.1,default:0}]});const di=R.DisplacementFilter,ui=R.Sprite,oe=R.Texture;m({id:"displacement",name:"Displacement Map",category:"distortion",description:"Distorts the image using a displacement map texture",createFilter:r=>{try{const e=r.mapTexture||"/assets/images/displacement_map.png";let t;try{t=oe.from(e),t.source.addressMode="repeat"}catch{const n=document.createElement("canvas");n.width=256,n.height=256;const o=n.getContext("2d");if(o){o.fillStyle="#ffffff",o.fillRect(0,0,n.width,n.height),o.fillStyle="#000000";for(let l=0;l<10;l++)for(let c=0;c<10;c++)(l+c)%2===0&&o.fillRect(l*25,c*25,25,25)}t=oe.from(n)}const i=new ui(t),s=new di(i,r.scale||50);return s.scale.x=r.scaleX||50,s.scale.y=r.scaleY||50,s._customParams={...r},s._displacementSprite=i,s.updateUIParam=function(a,n){const o=this._customParams||{};switch(this._customParams=o,o[a]=n,a){case"scaleX":this.scale.x=n;break;case"scaleY":this.scale.y=n;break;case"mapTexture":try{const l=this._displacementSprite;if(l){const c=oe.from(n);c.source.addressMode="repeat",l.texture=c}}catch{}break;default:a in this?this[a]=n:a in this.scale&&(this.scale[a]=n);break}return!0},s}catch{return null}},defaultParams:{mapTexture:"/assets/images/displacement_map.png",scale:50,scaleX:50,scaleY:50},controls:[{id:"mapTexture",type:"select",label:"Displacement Map",property:"mapTexture",options:[{label:"Default",value:"/assets/images/displacement_map.png"},{label:"Clouds",value:"/assets/images/clouds.png"},{label:"Ripple",value:"/assets/images/ripple.png"}],default:"/assets/images/displacement_map.png"},{id:"scaleX",type:"slider",label:"Scale X",property:"scaleX",min:1,max:200,step:1,default:50},{id:"scaleY",type:"slider",label:"Scale Y",property:"scaleY",min:1,max:200,step:1,default:50}]});m({id:"dot",name:"Dot Screen",category:"stylize",description:"Simulates a halftone printing pattern with dots",createFilter:r=>{try{const e={scale:typeof r.scale=="number"?r.scale:1,angle:typeof r.angle=="number"?r.angle:5,grayscale:r.grayscale===!0},t=new b.DotFilter(e);return t._customParams={...e},t.updateUIParam=function(i,s){try{const a=this._customParams||{};switch(this._customParams=a,a[i]=s,i){case"scale":this.scale=Number(s);break;case"angle":this.angle=Number(s);break;case"grayscale":this.grayscale=!!s;break;default:i in this&&(this[i]=s);break}}catch{}},t}catch{return null}},defaultParams:{scale:1,angle:5,grayscale:!0},controls:[{id:"scale",type:"slider",label:"Dot Scale",property:"scale",min:.5,max:10,step:.1,default:1},{id:"angle",type:"slider",label:"Dot Angle",property:"angle",min:0,max:10,step:.1,default:5},{id:"grayscale",type:"toggle",label:"Grayscale",property:"grayscale",default:!0}]});const{EmbossFilter:pi}=b;m({id:"emboss",name:"Emboss",category:"stylize",description:"Creates an embossed relief effect",createFilter:r=>{try{const e=typeof r.strength=="number"?r.strength:5,t=new pi(e);return t._customParams={strength:e},t.updateUIParam=function(i,s){try{const a=this._customParams||{};switch(this._customParams=a,a[i]=s,i){case"strength":const n=Number(s);a.strength=n,this.strength=n;break;default:i in this&&(this[i]=s);break}}catch{}},t}catch{return null}},defaultParams:{strength:5},controls:[{id:"strength",type:"slider",label:"Strength",property:"strength",min:0,max:20,step:.5,default:5}]});const{GlitchFilter:fi}=b,L={TRANSPARENT:0,ORIGINAL:1,LOOP:2,CLAMP:3,MIRROR:4};m({id:"glitch",name:"Glitch",category:"effects",description:"Apply digital distortion and glitch effects",createFilter:r=>{try{const e={x:r.redX,y:r.redY},t={x:r.greenX,y:r.greenY},i={x:r.blueX,y:r.blueY},s=new fi({slices:r.slices,offset:r.offset,direction:r.direction,fillMode:r.fillMode,seed:r.seed,average:r.average,minSize:r.minSize,sampleSize:r.sampleSize,red:e,green:t,blue:i});s.animating=r.animating||!1,s._customParams={...r},typeof s.refresh=="function"&&s.refresh();let a=null;const n=()=>{s.animating&&(s.seed=Math.random()),a=requestAnimationFrame(n)};return s.animating&&(a=requestAnimationFrame(n)),s._stopAnimation=()=>{a!==null&&(cancelAnimationFrame(a),a=null)},s.updateUIParam=function(o,l){const c=this._customParams||{};switch(this._customParams=c,c[o]=l,o){case"animating":this.animating=l,l&&!a&&(a=requestAnimationFrame(n));break;case"slices":this.slices=Math.round(l);break;case"redX":case"redY":const d=this.red;o==="redX"?d.x=l:d.y=l,this.red=d;break;case"greenX":case"greenY":const h=this.green;o==="greenX"?h.x=l:h.y=l,this.green=h;break;case"blueX":case"blueY":const u=this.blue;o==="blueX"?u.x=l:u.y=l,this.blue=u;break;case"seed":this.animating||(this.seed=l);break;case"randomizeSeed":l&&!c.animating&&(this.seed=Math.random());break;case"refresh":if(l)try{this.refresh()}catch{}break;case"offset":case"direction":case"fillMode":case"average":case"minSize":case"sampleSize":o in this&&(this[o]=l);break;default:o in this&&(this[o]=l);break}},s}catch{return null}},defaultParams:{slices:10,offset:100,direction:0,fillMode:L.LOOP,seed:.5,average:!1,minSize:8,sampleSize:512,redX:2,redY:2,greenX:-10,greenY:4,blueX:10,blueY:-4,animating:!1,randomizeSeed:!1,refresh:!1},controls:[{id:"animating",type:"toggle",label:"Animate Automatically",property:"animating",default:!1},{id:"slices",type:"slider",label:"Slices",property:"slices",min:2,max:20,step:1,default:10},{id:"offset",type:"slider",label:"Offset Amount",property:"offset",min:-400,max:400,step:1,default:100},{id:"direction",type:"slider",label:"Direction",property:"direction",min:-180,max:180,step:1,default:0},{id:"fillMode",type:"select",label:"Fill Mode",property:"fillMode",options:[{value:L.TRANSPARENT,label:"Transparent"},{value:L.ORIGINAL,label:"Original"},{value:L.LOOP,label:"Loop"},{value:L.CLAMP,label:"Clamp"},{value:L.MIRROR,label:"Mirror"}],default:L.LOOP},{id:"seed",type:"slider",label:"Seed",property:"seed",min:0,max:1,step:.01,default:.5},{id:"randomizeSeed",type:"button",label:"Randomize Seed",action:"randomizeSeed"},{id:"refresh",type:"button",label:"Refresh Filter",action:"refresh"},{id:"average",type:"toggle",label:"Average Slices",property:"average",default:!1},{id:"redX",type:"slider",label:"Red X Offset",property:"redX",min:-50,max:50,step:.5,default:2},{id:"redY",type:"slider",label:"Red Y Offset",property:"redY",min:-50,max:50,step:.5,default:2},{id:"greenX",type:"slider",label:"Green X Offset",property:"greenX",min:-50,max:50,step:.5,default:-10},{id:"greenY",type:"slider",label:"Green Y Offset",property:"greenY",min:-50,max:50,step:.5,default:4},{id:"blueX",type:"slider",label:"Blue X Offset",property:"blueX",min:-50,max:50,step:.5,default:10},{id:"blueY",type:"slider",label:"Blue Y Offset",property:"blueY",min:-50,max:50,step:.5,default:-4}]});const{GlowFilter:mi}=b;m({id:"glow",name:"Glow",category:"light",description:"Adds a customizable glow effect around the image",createFilter:r=>{try{const e=parseInt(r.color.replace("#","0x"),16),t=new mi({distance:r.distance||10,outerStrength:r.outerStrength||4,innerStrength:r.innerStrength||0,color:e,alpha:r.alpha??1,quality:r.quality||.1,knockout:r.knockout||!1});return t._customParams={color:r.color||"#ffffff",...r},t.updateUIParam=function(i,s){try{const a=this._customParams||{};switch(this._customParams=a,a[i]=s,i){case"distance":this.distance=Number(s);break;case"outerStrength":this.outerStrength=Number(s);break;case"innerStrength":this.innerStrength=Number(s);break;case"color":a.color=s,this.color=parseInt(s.replace("#","0x"),16);break;case"alpha":this.alpha=Number(s);break;case"quality":this.quality=Number(s);break;case"knockout":this.knockout=!!s;break;default:i in this&&(this[i]=s);break}}catch{}},t}catch{return null}},defaultParams:{distance:10,outerStrength:4,innerStrength:0,color:"#ffffff",alpha:1,quality:.1,knockout:!1},controls:[{id:"distance",type:"slider",label:"Distance",property:"distance",min:0,max:20,step:1,default:10},{id:"outerStrength",type:"slider",label:"Outer Strength",property:"outerStrength",min:0,max:20,step:.1,default:4},{id:"innerStrength",type:"slider",label:"Inner Strength",property:"innerStrength",min:0,max:20,step:.1,default:0},{id:"color",type:"color",label:"Color",property:"color",default:"#ffffff"},{id:"alpha",type:"slider",label:"Alpha",property:"alpha",min:0,max:1,step:.01,default:1},{id:"quality",type:"slider",label:"Quality",property:"quality",min:.01,max:1,step:.01,default:.1},{id:"knockout",type:"toggle",label:"Show Glow Only",property:"knockout",default:!1}]});const{GodrayFilter:gi}=b;m({id:"godray",name:"Godray",category:"light",description:"Creates volumetric light-ray effects (crepuscular rays)",createFilter:r=>{try{const e=new gi({angle:r.angle||30,parallel:r.parallel??!0,center:{x:r.centerX||0,y:r.centerY||0},gain:r.gain||.5,lacunarity:r.lacunarity||2.5,time:r.time||0,alpha:r.alpha||1});return e._customParams={centerX:r.centerX||0,centerY:r.centerY||0,...r},e.updateUIParam=function(t,i){try{const s=this._customParams||{};switch(this._customParams=s,s[t]=i,t){case"angle":this.angle=Number(i);break;case"parallel":this.parallel=!!i;break;case"centerX":s.centerX=Number(i),this.center={x:Number(i),y:s.centerY};break;case"centerY":s.centerY=Number(i),this.center={x:s.centerX,y:Number(i)};break;case"gain":this.gain=Number(i);break;case"lacunarity":this.lacunarity=Number(i);break;case"time":this.time=Number(i);break;case"alpha":this.alpha=Number(i);break;default:t in this&&(this[t]=i);break}}catch{}},e}catch{return null}},defaultParams:{angle:30,parallel:!0,centerX:0,centerY:0,gain:.5,lacunarity:2.5,time:0,alpha:1},controls:[{id:"angle",type:"slider",label:"Angle",property:"angle",min:0,max:360,step:1,default:30},{id:"parallel",type:"toggle",label:"Parallel Rays",property:"parallel",default:!0},{id:"centerX",type:"slider",label:"Light Source X",property:"centerX",min:-1,max:1,step:.01,default:0},{id:"centerY",type:"slider",label:"Light Source Y",property:"centerY",min:-1,max:1,step:.01,default:0},{id:"gain",type:"slider",label:"Gain/Intensity",property:"gain",min:0,max:1,step:.01,default:.5},{id:"lacunarity",type:"slider",label:"Density",property:"lacunarity",min:.1,max:10,step:.1,default:2.5},{id:"time",type:"slider",label:"Time",property:"time",min:0,max:10,step:.1,default:0},{id:"alpha",type:"slider",label:"Alpha",property:"alpha",min:0,max:1,step:.01,default:1}]});const bi=b.SimpleLightmapFilter,ze=R.Texture;m({id:"lightmap",name:"Lightmap",category:"light",description:"Applies lighting effects using a reference texture as a light map",createFilter:r=>{try{const e=r.textureType||"default",t=r.color||"#000000",i=typeof r.alpha=="number"?r.alpha:1,s=document.createElement("canvas");s.width=256,s.height=256;const a=s.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 n=ze.from(s);let o;try{typeof t=="string"&&t.startsWith("#")?o=parseInt(t.replace("#","0x"),16):o=0}catch{o=0}const l=new bi(n,o,i);return l._customParams={textureType:e,color:t,alpha:i},l.updateUIParam=function(c,d){try{const h=this._customParams||{};switch(this._customParams=h,h[c]=d,c){case"textureType":h.textureType=d;const u=document.createElement("canvas");u.width=256,u.height=256;const f=u.getContext("2d");if(f){if(d==="spotlight"){f.fillStyle="black",f.fillRect(0,0,256,256);const g=f.createRadialGradient(128,128,5,128,128,80);g.addColorStop(0,"white"),g.addColorStop(.5,"rgba(255, 255, 255, 0.5)"),g.addColorStop(1,"rgba(0, 0, 0, 0)"),f.fillStyle=g,f.beginPath(),f.arc(128,128,100,0,Math.PI*2),f.fill()}else if(d==="softlight"){const g=f.createLinearGradient(0,0,256,256);g.addColorStop(0,"white"),g.addColorStop(.3,"rgba(220, 220, 220, 1)"),g.addColorStop(.7,"rgba(150, 150, 150, 1)"),g.addColorStop(1,"rgba(80, 80, 80, 1)"),f.fillStyle=g,f.fillRect(0,0,256,256)}else{const g=f.createRadialGradient(128,128,10,128,128,160);g.addColorStop(0,"white"),g.addColorStop(.3,"rgba(220, 220, 220, 1)"),g.addColorStop(.6,"rgba(150, 150, 150, 1)"),g.addColorStop(1,"black"),f.fillStyle=g,f.fillRect(0,0,256,256)}const _=ze.from(u);if(this.lightMap=_,this.enabled!==void 0){const g=this.enabled;this.enabled=!1,setTimeout(()=>{this.enabled=g},0)}}break;case"color":h.color=d;try{typeof d=="string"&&d.startsWith("#")?this.color=parseInt(d.replace("#","0x"),16):this.color=0}catch{this.color=0}break;case"alpha":this.alpha=Number(d);break;default:c in this&&(this[c]=d);break}}catch{}},l}catch{return null}},defaultParams:{textureType:"default",color:"#000000",alpha:1},controls:[{id:"textureType",type:"select",label:"Light Map Type",property:"textureType",options:[{label:"Default",value:"default"},{label:"Spotlight",value:"spotlight"},{label:"Soft Light",value:"softlight"}],default:"default"},{id:"color",type:"color",label:"Ambient Color",property:"color",default:"#000000"},{id:"alpha",type:"slider",label:"Intensity",property:"alpha",min:0,max:1,step:.01,default:1}]});const{NoiseFilter:yi}=R;m({id:"noise",name:"Noise",category:"effects",description:"Add random noise to the image",createFilter:r=>{try{const e=new yi({noise:r.noise||.5,seed:r.seed||Math.random()});e.animating=r.animating||!1,e._customParams={...r};let t=null;const i=()=>{e.animating&&(e.seed=Math.random()),t=requestAnimationFrame(i)};return e.animating&&(t=requestAnimationFrame(i)),e._stopAnimation=()=>{t!==null&&(cancelAnimationFrame(t),t=null)},e.updateUIParam=function(s,a){const n=this._customParams||{};switch(this._customParams=n,n[s]=a,s){case"animating":this.animating=a,a&&!t&&(t=requestAnimationFrame(i));break;case"noise":this.noise=Math.max(0,Math.min(1,a));break;case"seed":this.animating||(this.seed=a);break;case"randomizeSeed":a&&(this.seed=Math.random());break;default:s in this&&(this[s]=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:_i}=b;m({id:"old-film",name:"Old Film",category:"effects",description:"Apply a vintage film effect with scratches and grain",createFilter:r=>{try{const e=new _i({sepia:r.sepia,noise:r.noise,noiseSize:r.noiseSize,scratch:r.scratch,scratchDensity:r.scratchDensity,scratchWidth:r.scratchWidth,vignetting:r.vignetting,vignettingAlpha:r.vignettingAlpha,vignettingBlur:r.vignettingBlur,seed:r.seed||Math.random()});e.animating=r.animating||!1,e._customParams={...r};let t=null;const i=()=>{e.animating&&(e.seed=Math.random()),t=requestAnimationFrame(i)};return e.animating&&(t=requestAnimationFrame(i)),e._stopAnimation=()=>{t!==null&&(cancelAnimationFrame(t),t=null)},e.updateUIParam=function(s,a){const n=this._customParams||{};switch(this._customParams=n,n[s]=a,s){case"animating":this.animating=a,a&&!t&&(t=requestAnimationFrame(i));break;case"seed":this.animating||(this.seed=a);break;case"randomizeSeed":a&&(this.seed=Math.random());break;case"sepia":case"noise":case"noiseSize":case"scratch":case"scratchDensity":case"scratchWidth":case"vignetting":case"vignettingAlpha":case"vignettingBlur":s in this&&(this[s]=a);break;default:s in this&&(this[s]=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:xi}=b;m({id:"outline",name:"Outline",category:"effects",description:"Add an outline or stroke around the image",createFilter:r=>{try{let e=r.color;typeof e=="string"&&(e=parseInt(e.replace("#","0x"),16));const t=new xi({thickness:r.thickness||4,color:e,alpha:r.alpha||1,quality:r.quality||.1,knockout:r.knockout||!1});return t._customParams={...r},t.updateUIParam=function(i,s){const a=this._customParams||{};switch(this._customParams=a,a[i]=s,i){case"thickness":this.thickness=Math.max(0,s);break;case"color":typeof s=="string"?(this.color=parseInt(s.replace("#","0x"),16),a.color=s):this.color=s;break;case"alpha":this.alpha=Math.max(0,Math.min(1,s));break;case"quality":this.quality=Math.max(.01,Math.min(1,s));break;case"knockout":this.knockout=!!s;break;default:i in this&&(this[i]=s);break}},t}catch{return null}},defaultParams:{thickness:4,color:"#000000",alpha:1,quality:.1,knockout:!1},controls:[{id:"thickness",type:"slider",label:"Thickness",property:"thickness",min:0,max:20,step:.1,default:4},{id:"color",type:"color",label:"Color",property:"color",default:"#000000"},{id:"alpha",type:"slider",label:"Alpha",property:"alpha",min:0,max:1,step:.01,default:1},{id:"quality",type:"slider",label:"Quality",property:"quality",min:.01,max:1,step:.01,default:.1,tooltip:"Higher values give better quality but slower performance"},{id:"knockout",type:"toggle",label:"Outline Only",property:"knockout",default:!1,tooltip:"Only show the outline, not the image content"}]});const{PixelateFilter:Ci}=b;m({id:"pixelate",name:"Pixelate",category:"effects",description:"Create a pixelated or mosaic effect",createFilter:r=>{try{const e=new Ci(r.useUniform?Math.max(4,r.size||10):[Math.max(4,r.sizeX||10),Math.max(4,r.sizeY||10)]);return e._customParams={...r},e.updateUIParam=function(t,i){const s=this._customParams||{};switch(this._customParams=s,s[t]=i,t){case"useUniform":if(s.useUniform=i,i){const a=Math.round((this.sizeX+this.sizeY)/2);this.size=Math.max(4,a),s.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),s.sizeX=this.sizeX,s.sizeY=this.sizeY}break;case"size":s.useUniform&&(this.size=Math.max(4,i));break;case"sizeX":s.useUniform||(this.sizeX=Math.max(4,i));break;case"sizeY":s.useUniform||(this.sizeY=Math.max(4,i));break;default:t in this&&(this[t]=i);break}},e}catch{return null}},defaultParams:{useUniform:!0,size:10,sizeX:10,sizeY:10},controls:[{id:"useUniform",type:"toggle",label:"Uniform Pixels",property:"useUniform",default:!0,tooltip:"Use the same size for both X and Y dimensions"},{id:"size",type:"slider",label:"Pixel Size",property:"size",min:4,max:40,step:1,default:10,tooltip:"Size of the pixels in both dimensions"},{id:"sizeX",type:"slider",label:"Horizontal Size",property:"sizeX",min:4,max:40,step:1,default:10,tooltip:"Size of the pixels in the horizontal direction"},{id:"sizeY",type:"slider",label:"Vertical Size",property:"sizeY",min:4,max:40,step:1,default:10,tooltip:"Size of the pixels in the vertical direction"}]});const{ReflectionFilter:wi}=b;m({id:"reflection",name:"Reflection",category:"distortion",description:"Creates a water reflection effect with configurable waves",createFilter:r=>{try{const e={mirror:r.mirror??!0,boundary:r.boundary??.5,amplitude:new Float32Array([r.amplitudeStart??0,r.amplitudeEnd??20]),waveLength:new Float32Array([r.wavelengthStart??30,r.wavelengthEnd??100]),alpha:new Float32Array([r.alphaStart??1,r.alphaEnd??1]),time:r.time??0},t=new wi(e);return t._customParams={...r},t.animating=r.animating??!1,t.updateUIParam=function(i,s){const a=this._customParams||{};switch(this._customParams=a,a[i]=s,i){case"mirror":case"boundary":case"time":this[i]=s;break;case"amplitudeStart":Array.isArray(this.amplitude)||(this.amplitude=[0,this._customParams.amplitudeEnd||20]),this.amplitude[0]=s;break;case"amplitudeEnd":Array.isArray(this.amplitude)||(this.amplitude=[this._customParams.amplitudeStart||0,20]),this.amplitude[1]=s;break;case"wavelengthStart":Array.isArray(this.waveLength)||(this.waveLength=[30,this._customParams.wavelengthEnd||100]),this.waveLength[0]=s;break;case"wavelengthEnd":Array.isArray(this.waveLength)||(this.waveLength=[this._customParams.wavelengthStart||30,100]),this.waveLength[1]=s;break;case"alphaStart":Array.isArray(this.alpha)||(this.alpha=[1,this._customParams.alphaEnd||1]),this.alpha[0]=s;break;case"alphaEnd":Array.isArray(this.alpha)||(this.alpha=[this._customParams.alphaStart||1,1]),this.alpha[1]=s;break;case"animating":this.animating=s;break;default:i in this&&(this[i]=s);break}return!0},t}catch{return null}},defaultParams:{mirror:!0,boundary:.5,amplitudeStart:0,amplitudeEnd:20,wavelengthStart:30,wavelengthEnd:100,alphaStart:1,alphaEnd:1,time:0,animating:!1},controls:[{id:"mirror",type:"toggle",label:"Mirror Image",property:"mirror",default:!0},{id:"boundary",type:"slider",label:"Boundary Line",property:"boundary",min:0,max:1,step:.01,default:.5},{id:"amplitudeStart",type:"slider",label:"Wave Height (Start)",property:"amplitudeStart",min:0,max:50,step:1,default:0},{id:"amplitudeEnd",type:"slider",label:"Wave Height (End)",property:"amplitudeEnd",min:0,max:50,step:1,default:20},{id:"wavelengthStart",type:"slider",label:"Wave Length (Start)",property:"wavelengthStart",min:10,max:200,step:1,default:30},{id:"wavelengthEnd",type:"slider",label:"Wave Length (End)",property:"wavelengthEnd",min:10,max:200,step:1,default:100},{id:"alphaStart",type:"slider",label:"Opacity (Start)",property:"alphaStart",min:0,max:1,step:.01,default:1},{id:"alphaEnd",type:"slider",label:"Opacity (End)",property:"alphaEnd",min:0,max:1,step:.01,default:1},{id:"time",type:"slider",label:"Animation Time",property:"time",min:0,max:10,step:.1,default:0},{id:"animating",type:"toggle",label:"Auto Animate",property:"animating",default:!1}]});const{ShockwaveFilter:Si}=b;m({id:"shockwave",name:"Shockwave",category:"distortion",description:"Creates a rippling shockwave or blast wave effect",createFilter:r=>{try{const e=r.centerX??.5,t=r.centerY??.5,i={x:e,y:t},s=r.amplitude??30,a=r.wavelength??160,n=r.speed??500,o=r.brightness??1,l=r.radius??-1,c=r.time??0,d=new Si({center:i,amplitude:s,wavelength:a,speed:n,brightness:o,radius:l,time:c});return d._customParams={...r},d.animating=r.animating??!1,d.updateUIParam=function(h,u){const f=this._customParams||{};switch(this._customParams=f,f[h]=u,h){case"centerX":this.center||(this.center={x:.5,y:.5}),this.center.x=u;break;case"centerY":this.center||(this.center={x:.5,y:.5}),this.center.y=u;break;case"amplitude":case"wavelength":case"speed":case"brightness":case"radius":case"time":this[h]=u;break;case"animating":this.animating=u;break;default:h in this&&(this[h]=u);break}return!0},d}catch{return null}},defaultParams:{centerX:.5,centerY:.5,amplitude:30,wavelength:160,speed:500,brightness:1,radius:-1,time:0,animating:!1},controls:[{id:"centerX",type:"slider",label:"Center X",property:"centerX",min:0,max:1,step:.01,default:.5},{id:"centerY",type:"slider",label:"Center Y",property:"centerY",min:0,max:1,step:.01,default:.5},{id:"amplitude",type:"slider",label:"Amplitude",property:"amplitude",min:0,max:100,step:1,default:30},{id:"wavelength",type:"slider",label:"Wavelength",property:"wavelength",min:10,max:500,step:1,default:160},{id:"speed",type:"slider",label:"Speed",property:"speed",min:1,max:1e3,step:10,default:500},{id:"brightness",type:"slider",label:"Brightness",property:"brightness",min:0,max:5,step:.1,default:1},{id:"radius",type:"slider",label:"Max Radius",property:"radius",min:-1,max:1e3,step:10,default:-1},{id:"time",type:"slider",label:"Time",property:"time",min:0,max:5,step:.1,default:0},{id:"animating",type:"toggle",label:"Auto Animate",property:"animating",default:!1}]});const{SimplexNoiseFilter:vi}=b;m({id:"simplex-noise",name:"Simplex Noise",category:"effects",description:"Apply procedural noise to create texture effects",createFilter:r=>{try{const e=r.animating?0:r.offsetZ||0,t=new vi({strength:r.strength,noiseScale:r.noiseScale,offsetX:r.offsetX,offsetY:r.offsetY,offsetZ:e,step:r.step});t.animating=r.animating||!1,t.animationSpeed=r.animationSpeed||.01,t._customParams={...r};let i=null,s=0;const a=()=>{t.animating&&(s+=t.animationSpeed,t.offsetZ=s),i=requestAnimationFrame(a)};return t.animating&&(i=requestAnimationFrame(a)),t._stopAnimation=()=>{i!==null&&(cancelAnimationFrame(i),i=null)},t.updateUIParam=function(n,o){const l=this._customParams||{};switch(this._customParams=l,l[n]=o,n){case"animating":this.animating=o,o&&!i&&(i=requestAnimationFrame(a));break;case"animationSpeed":this.animationSpeed=o;break;case"offsetZ":this.animating||(this.offsetZ=o);break;case"randomizeSeed":if(o){const c=()=>Math.random()*100-50;this.offsetX=c(),this.offsetY=c(),this.offsetZ=c(),l.offsetX=this.offsetX,l.offsetY=this.offsetY,l.offsetZ=this.offsetZ}break;case"strength":case"noiseScale":case"offsetX":case"offsetY":case"step":n in this&&(this[n]=o);break;default:n in this&&(this[n]=o);break}},t}catch{return null}},defaultParams:{strength:.5,noiseScale:10,offsetX:0,offsetY:0,offsetZ:0,step:-1,animating:!1,animationSpeed:.01,randomizeSeed:!1},controls:[{id:"strength",type:"slider",label:"Noise Strength",property:"strength",min:0,max:1,step:.01,default:.5},{id:"noiseScale",type:"slider",label:"Noise Scale",property:"noiseScale",min:1,max:50,step:.5,default:10},{id:"offsetX",type:"slider",label:"X Offset",property:"offsetX",min:-50,max:50,step:.5,default:0},{id:"offsetY",type:"slider",label:"Y Offset",property:"offsetY",min:-50,max:50,step:.5,default:0},{id:"offsetZ",type:"slider",label:"Z Offset",property:"offsetZ",min:-50,max:50,step:.5,default:0},{id:"step",type:"slider",label:"Step Threshold",property:"step",min:-1,max:1,step:.01,default:-1,tooltip:"Values above 0 create a blocky effect"},{id:"animating",type:"toggle",label:"Animate Noise",property:"animating",default:!1},{id:"animationSpeed",type:"slider",label:"Animation Speed",property:"animationSpeed",min:.001,max:.05,step:.001,default:.01},{id:"randomizeSeed",type:"button",label:"Randomize Pattern",action:"randomizeSeed"}]});const{TwistFilter:Mi}=b,Ge=r=>Math.ceil(Math.max(0,Number(r)||0)+2),Ne=(r,e=1)=>{const t=Math.max(1,Number(r._sourceWidth??0)),i=Math.max(1,Number(r._sourceHeight??0)),s=Math.min(t,i),a=Number(r.centerX??.5),n=Number(r.centerY??.5),o=Number(r.radius??.25),l=Number(r.angle??4),c=a*t*e,d=n*i*e,h=o*s*e,u=new Mi({offset:{x:c,y:d},radius:h,angle:l}),f=Ge(h);return u.padding=Math.max(u.padding??0,f),u._exportPadding=f,u};m({id:"twist",name:"Twist",category:"distortion",description:"Creates a twisting distortion effect around a central point",createFilter:r=>{try{const e={centerX:r.centerX??.5,centerY:r.centerY??.5,radius:r.radius??.25,angle:r.angle??4,_sourceWidth:r._sourceWidth,_sourceHeight:r._sourceHeight},t=Ne(e,1);return t._customParams={...e},t.updateUIParam=function(i,s){const a=this._customParams||{};this._customParams=a,a[i]=s;const n=Math.max(1,Number(a._sourceWidth??0)),o=Math.max(1,Number(a._sourceHeight??0)),l=Math.min(n,o),c=Number(a.centerX??.5),d=Number(a.centerY??.5),h=Number(a.radius??.25),u=Number(a.angle??4);this.offset&&(this.offset.x=c*n,this.offset.y=d*o),this.radius=h*l,this.angle=u;const f=Ge(this.radius);return this._exportPadding=f,this.padding=Math.max(this.padding??0,f),!0},t.createExportFilter=function(i={}){const s=Number.isFinite(i.previewToNativeScale)?Math.max(1,Number(i.previewToNativeScale)):1,a=this._customParams||e;return Ne(a,s)},t.getExportPadding=function(){return Number(this._exportPadding||this.padding||0)},t}catch{return null}},defaultParams:{centerX:.5,centerY:.5,radius:.25,angle:4},controls:[{id:"angle",type:"slider",label:"Angle",property:"angle",min:-10,max:10,step:.1,default:4,tooltip:"Amount of twisting (positive is clockwise)"},{id:"radius",type:"slider",label:"Radius",property:"radius",min:.05,max:.75,step:.01,default:.25,tooltip:"Size of the twist effect (relative to image)"},{id:"centerX",type:"slider",label:"Center X",property:"centerX",min:0,max:1,step:.01,default:.5,tooltip:"Horizontal position of twist center"},{id:"centerY",type:"slider",label:"Center Y",property:"centerY",min:0,max:1,step:.01,default:.5,tooltip:"Vertical position of twist center"}]});const{AdjustmentFilter:Pi}=b;function Q(r){const e=typeof r=="string"?parseInt(r.replace("#","0x"),16):r;return[(e>>16&255)/255,(e>>8&255)/255,(e&255)/255]}class ki extends Pi{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=Q(e.color)):(this._colorValue="#"+e.color.toString(16).padStart(6,"0"),this._colorRgb=Q(e.color))),this.updateVignette()}updateVignette(){const e=1-this._radius/2,t=this._strength*e;this.brightness=Math.max(.5,1-t*.5),this.contrast=1+t*.2,(this._colorRgb[0]>0||this._colorRgb[1]>0||this._colorRgb[2]>0)&&(this.saturation=1-t*.3)}get radius(){return this._radius}set radius(e){this._radius=Math.max(.1,Math.min(1.5,e)),this.updateVignette()}get strength(){return this._strength}set strength(e){this._strength=Math.max(0,Math.min(2,e)),this.updateVignette()}get color(){return this._colorValue}set color(e){typeof e=="string"?(this._colorValue=e,this._colorRgb=Q(e)):(this._colorValue="#"+e.toString(16).padStart(6,"0"),this._colorRgb=Q(e)),this.updateVignette()}}m({id:"vignette",name:"Vignette",category:"effects",description:"Add a classic darkened border effect to the image",createFilter:r=>{try{const e=new ki({radius:r.radius||.8,strength:r.strength||1,color:r.color||"#000000"});return e._customParams={...r},e.updateUIParam=function(t,i){const s=this._customParams||{};switch(this._customParams=s,s[t]=i,t){case"radius":this.radius=Math.max(.1,Math.min(1.5,i));break;case"strength":this.strength=Math.max(0,i);break;case"color":this.color=i,typeof i=="string"&&(s.color=i);break;default:t in this&&(this[t]=i);break}},e}catch{return null}},defaultParams:{radius:.8,strength:1,color:"#000000"},controls:[{id:"radius",type:"slider",label:"Radius",property:"radius",min:.1,max:1.5,step:.01,default:.8,tooltip:"Size of the vignette effect (larger values create a smaller vignette)"},{id:"strength",type:"slider",label:"Strength",property:"strength",min:0,max:2,step:.01,default:1,tooltip:"Intensity of the vignette effect"},{id:"color",type:"color",label:"Color",property:"color",default:"#000000",tooltip:"Color of the vignette (usually black)"}]});function Fi(r){try{let e=[],t=[];try{e=Z(),e.length===0&&je()}catch{}const i=r==null?void 0:r.disabled;if(Array.isArray(i)&&i.length>0){let s=0;for(const a of i)Xt(a)&&s++;s>0}try{e=Z(),t=He()}catch{e||(e=[]),t||(t=[])}return e.length,e}catch{return[]}}exports.CropControls=Le;exports.CropManager=ee;exports.EDITOR_CATEGORIES=ie;exports.EventEmitter=W;exports.FilterManager=Oe;exports.PixiRenderer=Ee;exports.REGISTRY_TO_UI=Be;exports.RemoveBgManager=Ye;exports.Toolbar=De;exports.VanillaImageEditor=Tt;exports.checkmark=J;exports.chevronLeft=ce;exports.chevronRight=he;exports.close=te;exports.createButton=O;exports.createColorPicker=pe;exports.createSelect=me;exports.createSlider=de;exports.createState=Te;exports.createTextInput=fe;exports.createToggle=ue;exports.el=p;exports.getAllCategories=He;exports.getAllFilters=Z;exports.getFilter=Ue;exports.getFiltersByCategory=qe;exports.getPreset=Ve;exports.getRegisteredFilters=$e;exports.hasFilter=It;exports.initializeFilterRegistry=Fi;exports.isFilterCompatibleWithMedia=Bt;exports.registerCorePixiFilters=je;exports.registerFilter=m;
2
+ //# sourceMappingURL=editor-BTwIhrcA.cjs.map