@alekstar79/draggable-resizable-container 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -1,11 +1,45 @@
1
- (function(l,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("@alekstar79/reactive-event-system"),require("@alekstar79/utility")):typeof define=="function"&&define.amd?define(["exports","@alekstar79/reactive-event-system","@alekstar79/utility"],d):(l=typeof globalThis<"u"?globalThis:l||self,d(l.ContainerManager={},l.ReactiveEventSystem,l.utility))})(this,function(l,d,u){"use strict";var ue=Object.defineProperty;var me=(l,d,u)=>d in l?ue(l,d,{enumerable:!0,configurable:!0,writable:!0,value:u}):l[d]=u;var r=(l,d,u)=>me(l,typeof d!="symbol"?d+"":d,u);var B=document.createElement("style");B.textContent=`.container{position:absolute;background:#fff;border:2px solid #e2e8f0;border-radius:8px;box-shadow:0 4px 6px #0000001a;overflow:hidden;resize:none}.drag-handle{position:absolute;top:0;left:0;right:0;height:24px;background:#f7fafc;border-bottom:1px solid #e2e8f0;cursor:move;display:flex;align-items:center;justify-content:center;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-webkit-touch-callout:none;-webkit-tap-highlight-color:transparent}.container-title{font-weight:600;font-size:.9rem;flex:1;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0}.container-content{position:absolute;top:40px;left:0;right:0;bottom:0;padding:16px;overflow:auto;box-sizing:border-box}.container[data-mode=pinned]{border-color:#e53e3e}.container[data-mode=snap]{border-color:#38a169}.container[data-mode=smooth]{border-color:#3182ce}.resize-n,.resize-s{height:12px;cursor:ns-resize;left:0;right:0}.resize-e,.resize-w{width:12px;cursor:ew-resize;top:0;bottom:0}.resize-ne,.resize-nw,.resize-se,.resize-sw{width:16px;height:16px;background:transparent;border-radius:2px}.resize-n{top:0}.resize-s{bottom:0}.resize-e{right:0}.resize-w{left:0}.resize-ne{top:0;right:0;cursor:nesw-resize}.resize-nw{top:0;left:0;cursor:nwse-resize}.resize-se{bottom:0;right:0;cursor:nwse-resize}.resize-sw{bottom:0;left:0;cursor:nesw-resize}.resize-handle:hover{background:#4299e14d}.resize-ne:hover,.resize-nw:hover,.resize-se:hover,.resize-sw:hover{background:#4299e14d;transform:scale(1.1)}.resize-handle{position:absolute;background:transparent;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;transition:background-color .2s ease}.handle-content{display:flex;justify-content:space-between;align-items:center;width:100%;padding:0 8px;box-sizing:border-box}.mode-controls-container{display:flex;gap:6px;align-items:center;flex-shrink:0}.mode-btn{width:32px;height:32px;border:none;border-radius:8px;cursor:pointer;font-size:14px;transition:all .3s cubic-bezier(.4,0,.2,1);display:flex;align-items:center;justify-content:center;background:transparent;color:#6b7280;position:relative;overflow:hidden}.mode-btn:hover{transform:scale(1.2);background:#0000000d}.mode-btn:active{transform:scale(1.1)}.mode-btn:focus-visible{outline:2px solid #3b82f6;outline-offset:2px}.container-content::-webkit-scrollbar{width:6px}.container-content::-webkit-scrollbar-track{background:#f3f4f6;border-radius:3px}.container-content::-webkit-scrollbar-thumb{background:#9ca3af;border-radius:3px}.container-content::-webkit-scrollbar-thumb:hover{background:#6b7280}
2
- /*$vite$:1*/`,document.head.appendChild(B);class F{constructor(e){r(this,"container");this.container=e||this.createContainer()}createContainer(){const e=document.querySelector(".notifications");if(e)return e;const t=document.createElement("div");return t.className="notifications",document.body.appendChild(t),t}show(e,t="info"){const i=document.createElement("li"),s=this.removeToast.bind(this,i);i.innerHTML=this.getToastHTML(e,t),i.className=`toast ${t}`,i.timeoutId=window.setTimeout(s,4e3);const a=i.querySelector(".icon");a&&a.addEventListener("click",s),this.container.appendChild(i)}getToastHTML(e,t){return`
1
+ (function(d,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("@alekstar79/reactive-event-system"),require("@alekstar79/utility")):typeof define=="function"&&define.amd?define(["exports","@alekstar79/reactive-event-system","@alekstar79/utility"],l):(d=typeof globalThis<"u"?globalThis:d||self,l(d.ContainerManager={},d.ReactiveEventSystem,d.utility))})(this,function(d,l,u){"use strict";var mt=Object.defineProperty;var pt=(d,l,u)=>l in d?mt(d,l,{enumerable:!0,configurable:!0,writable:!0,value:u}):d[l]=u;var a=(d,l,u)=>pt(d,typeof l!="symbol"?l+"":l,u);var B=document.createElement("style");B.textContent=`.container{position:absolute;background:#fff;border:2px solid #e2e8f0;border-radius:8px;box-shadow:0 4px 6px #0000001a;overflow:hidden;resize:none}.drag-handle{position:absolute;top:0;left:0;right:0;height:24px;background:#f7fafc;border-bottom:1px solid #e2e8f0;cursor:move;display:flex;align-items:center;justify-content:center;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-webkit-touch-callout:none;-webkit-tap-highlight-color:transparent}.container-title{font-weight:600;font-size:.9rem;flex:1;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0}.container-content{position:absolute;top:40px;left:0;right:0;bottom:0;padding:16px;overflow:auto;box-sizing:border-box}.container[data-mode=pinned]{border-color:#e53e3e}.container[data-mode=snap]{border-color:#38a169}.container[data-mode=smooth]{border-color:#3182ce}.resize-n,.resize-s{height:12px;cursor:ns-resize;left:0;right:0}.resize-e,.resize-w{width:12px;cursor:ew-resize;top:0;bottom:0}.resize-ne,.resize-nw,.resize-se,.resize-sw{width:16px;height:16px;background:transparent;border-radius:2px}.resize-n{top:0}.resize-s{bottom:0}.resize-e{right:0}.resize-w{left:0}.resize-ne{top:0;right:0;cursor:nesw-resize}.resize-nw{top:0;left:0;cursor:nwse-resize}.resize-se{bottom:0;right:0;cursor:nwse-resize}.resize-sw{bottom:0;left:0;cursor:nesw-resize}.resize-handle:hover{background:#4299e14d}.resize-ne:hover,.resize-nw:hover,.resize-se:hover,.resize-sw:hover{background:#4299e14d;transform:scale(1.1)}.resize-handle{position:absolute;background:transparent;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;transition:background-color .2s ease}.handle-content{display:flex;justify-content:space-between;align-items:center;width:100%;padding:0 8px;box-sizing:border-box}.mode-controls-container{display:flex;gap:6px;align-items:center;flex-shrink:0}.mode-btn{width:32px;height:32px;border:none;border-radius:8px;cursor:pointer;font-size:14px;transition:all .3s cubic-bezier(.4,0,.2,1);display:flex;align-items:center;justify-content:center;background:transparent;color:#6b7280;position:relative;overflow:hidden}.mode-btn:hover{transform:scale(1.2);background:#0000000d}.mode-btn:active{transform:scale(1.1)}.mode-btn:focus-visible{outline:2px solid #3b82f6;outline-offset:2px}.container-content::-webkit-scrollbar{width:6px}.container-content::-webkit-scrollbar-track{background:#f3f4f6;border-radius:3px}.container-content::-webkit-scrollbar-thumb{background:#9ca3af;border-radius:3px}.container-content::-webkit-scrollbar-thumb:hover{background:#6b7280}
2
+ /*$vite$:1*/`,document.head.appendChild(B);class F{constructor(t){a(this,"container");this.container=t||this.createContainer()}createContainer(){const t=document.querySelector(".notifications");if(t)return t;const e=document.createElement("div");return e.className="notifications",document.body.appendChild(e),e}show(t,e="info"){const i=document.createElement("li"),s=this.removeToast.bind(this,i);i.innerHTML=this.getToastHTML(t,e),i.className=`toast ${e}`,i.timeoutId=window.setTimeout(s,4e3);const r=i.querySelector(".icon");r&&r.addEventListener("click",s),this.container.appendChild(i)}getToastHTML(t,e){return`
3
3
  <div class="column">
4
- <i class="fa-solid ${{success:"fa-circle-check",error:"fa-circle-xmark",warning:"fa-triangle-exclamation",info:"fa-circle-info"}[t]}"></i>
5
- <span>${e}</span>
4
+ <i class="fa-solid ${{success:"fa-circle-check",error:"fa-circle-xmark",warning:"fa-triangle-exclamation",info:"fa-circle-info"}[e]}"></i>
5
+ <span>${t}</span>
6
6
  </div>
7
7
  <i class="icon fa-solid fa-xmark"></i>
8
- `}removeToast(e){e.classList.add("hide"),e.timeoutId&&clearTimeout(e.timeoutId),setTimeout(()=>{e.parentNode&&e.parentNode.removeChild(e)},300)}clear(){for(;this.container.firstChild;)this.container.removeChild(this.container.firstChild)}}new F;class q{static createContainerElement(e,t,i,s,a){const o=document.createElement("div");return o.className="container advanced-container new",o.style.position="absolute",o.style.width=`${e}px`,o.style.height=`${t}px`,i!==void 0&&(o.style.left=`${i}px`),s!==void 0&&(o.style.top=`${s}px`),a&&(o.style.borderColor=a),o}}class J{constructor(e){r(this,"templateLoader");this.templateLoader=e}async createContent(e,t){try{const i=t.classList.contains("container-content");let s;if(i?s=t:(s=t.querySelector(".container-content"),s||(s=document.createElement("div"),s.className="container-content",t.appendChild(s))),s.innerHTML="",typeof e=="string")s.innerHTML=e;else if(e instanceof HTMLElement)s.appendChild(e);else if(e.template)try{s.innerHTML=await this.templateLoader.loadTemplate(e.template)}catch(a){console.error(`[ContentCreator] Failed to load template: ${e.template}`,a),s.innerHTML=`<div class="template-error">Failed to load template: ${e.template}</div>`}return s}catch(i){throw console.error("[ContentCreator] Error creating content:",i),i}}setTemplateLoader(e){this.templateLoader=e}}var Z=Object.defineProperty,_=(h,e,t)=>e in h?Z(h,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):h[e]=t,f=(h,e,t)=>_(h,typeof e!="symbol"?e+"":e,t);class P{constructor(){f(this,"templates",new Map),f(this,"lastUpdated",new Map)}register(e){if(!e.name.trim())throw new Error("Template name cannot be empty");this.templates.set(e.name,e),this.lastUpdated.set(e.name,Date.now())}async registerBulk(e){for(const[t,i]of Object.entries(e))this.register({name:t,source:i})}get(e){return this.templates.get(e)}has(e){return this.templates.has(e)}remove(e){this.templates.delete(e),this.lastUpdated.delete(e)}list(){return Array.from(this.templates.keys())}clear(){this.templates.clear(),this.lastUpdated.clear()}getMetadata(e){var t;return(t=this.templates.get(e))==null?void 0:t.metadata}}class ee{constructor(e=36e5){f(this,"cache",new Map),f(this,"ttl"),this.ttl=e}set(e,t){this.cache.set(e,{content:t,timestamp:Date.now()})}get(e){const t=this.cache.get(e);return t?this.ttl<=0||Date.now()-t.timestamp>this.ttl?(this.cache.delete(e),null):t.content:null}has(e){return this.get(e)!==null}clear(){this.cache.clear()}size(){return this.cache.size}}class O{constructor(e,t={}){f(this,"cache"),f(this,"config"),f(this,"metrics"),f(this,"retryQueue",new Map),f(this,"registry"),this.registry=e??new P,this.cache=new ee(t==null?void 0:t.cacheTTL),this.config=this.normalizeConfig(t),this.metrics={totalLoads:0,totalHits:0,totalMisses:0,totalErrors:0,averageLoadTime:0,cacheHitRate:0}}normalizeConfig(e={}){var i;const t=e||{};return{environment:t.environment==="auto"?typeof process<"u"&&((i=process.env)==null?void 0:i.NODE_ENV)==="production"?"production":"development":t.environment??"development",cache:t.cache??!0,cacheTTL:t.cacheTTL??36e5,enableMetrics:t.enableMetrics??!0,onError:t.onError??(()=>{}),onWarn:t.onWarn??(()=>{}),fallbackTemplate:t.fallbackTemplate??'<div class="template-error">Template load failed</div>'}}async loadTemplate(e,t=2){const i=performance.now(),s=this.retryQueue.get(e)??0;if(this.metrics.totalLoads++,this.config.cache){const o=this.cache.get(e);if(o)return this.metrics.totalHits++,this.updateCacheHitRate(),o}this.metrics.totalMisses++;const a=this.registry.get(e);if(!a){const o=this.createError(`Template "${e}" not found. Available: ${this.registry.list().join(", ")}`,e,s);return this.metrics.totalErrors++,this.config.onError(o),this.config.fallbackTemplate}try{let o=typeof a.source=="function"?await a.source():a.source;if(typeof o!="string"){const c=this.createError("Template source must return a string, got "+typeof o,e,s);return this.metrics.totalErrors++,this.config.onError(c),this.config.fallbackTemplate}return this.config.cache&&this.cache.set(e,o),this.retryQueue.delete(e),this.recordLoadTime(i),o}catch(o){const c=o instanceof Error?o:new Error(String(o));if(s<t)return this.retryQueue.set(e,s+1),this.config.onWarn(`Retrying template "${e}" (attempt ${s+1}/${t})`),await new Promise(m=>setTimeout(m,100*Math.pow(2,s))),this.loadTemplate(e,t);const g=this.createError(`Failed to load template "${e}": ${c.message}`,e,s);return this.metrics.totalErrors++,this.config.onError(g),this.retryQueue.delete(e),this.config.fallbackTemplate}}async loadTemplates(e){const t={};return await Promise.all(e.map(async i=>{t[i]=await this.loadTemplate(i)})),t}getMetrics(){return{...this.metrics}}clearCache(){this.cache.clear()}resetMetrics(){this.metrics={totalLoads:0,totalHits:0,totalMisses:0,totalErrors:0,averageLoadTime:0,cacheHitRate:0}}has(e){return this.registry.has(e)}list(){return this.registry.list()}info(e){return this.registry.get(e)}createError(e,t,i){return Object.assign(new Error(e),{name:"TemplateLoadError",templateName:t,timestamp:new Date,retryCount:i})}recordLoadTime(e){if(this.config.enableMetrics){const t=performance.now()-e,i=this.metrics.averageLoadTime*(this.metrics.totalLoads-1)+t;this.metrics.averageLoadTime=i/this.metrics.totalLoads}}updateCacheHitRate(){this.config.enableMetrics&&(this.metrics.cacheHitRate=this.metrics.totalHits/this.metrics.totalLoads)}}let v;async function te(h=[]){const e=new P;let t={};try{t=Object.assign({"../demo/templates/media.html":()=>Promise.resolve().then(()=>he).then(s=>s.default),"../demo/templates/stats.html":()=>Promise.resolve().then(()=>de).then(s=>s.default),"../demo/templates/tasks.html":()=>Promise.resolve().then(()=>le).then(s=>s.default)});const i={};Object.entries(t).forEach(([s,a])=>{var c;const o=(c=s.split("/").pop())==null?void 0:c.replace(/\.html$/,"");o&&(i[o]=async()=>typeof a=="function"?await a():String(a))}),await e.registerBulk(i)}catch(i){console.error("[TemplateLoader] Failed to load templates:",i),h.forEach(({name:s,source:a})=>{e.register({name:s,source:a})})}return new O(e,{environment:"development",cache:!0,cacheTTL:36e5,enableMetrics:!0,fallbackTemplate:'<div class="template-error">Template not found</div>',onError:i=>console.error(`[TemplateLoader Error] ${i.templateName}:`,i.message),onWarn:i=>console.warn(`[TemplateLoader] ${i}`)})}function ie(){const h=new P;return new O(h,{environment:"production",cache:!0,cacheTTL:36e5,enableMetrics:!1,onWarn:e=>console.warn(`[TemplateLoader] ${e}`),onError:e=>{console.warn(`Template load failed: ${e.templateName}`)}})}async function se(){return v||(typeof process<"u"&&process.env&&process.env.NODE_ENV==="development"?v=await te():(v=ie(),v.registry.register({name:"media",source:async()=>(await fetch("./templates/media.html")).text(),metadata:{version:"1.0",description:"Media card",cached:!0}}),v.registry.register({name:"userProfile",source:'<div class="user-profile"><h2>Profile</h2></div>',metadata:{version:"1.0",description:"User profile card",cached:!0}})),v)}function ne(){if(!v)throw new Error("Template system not initialized. Call initializeTemplateSystem() first.");return v}function re(h,[e,t]){return t?{...h,[e]:t}:h}class Q{constructor(e){r(this,"source","cursor");r(this,"element",null);r(this,"top",!1);r(this,"right",!1);r(this,"bottom",!1);r(this,"left",!1);r(this,"edge",null);Object.assign(this,e)}}class j{constructor(){r(this,"listeners",{})}on(e,t){return this.listeners[e]||(this.listeners[e]=new Set),this.listeners[e].add(t),()=>{var i;(i=this.off)==null||i.call(this,e,t)}}emit(e,t){var i;(i=this.listeners[e])==null||i.forEach(s=>{try{s(t)}catch(a){console.error(`Error in event listener for ${String(e)}:`,a)}})}off(e,t){var i;(i=this.listeners[e])==null||i.delete(t)}destroy(){this.listeners={}}}class ae{constructor(e=50,t,i=null){r(this,"root");r(this,"edgeThreshold");r(this,"targets",new Set);r(this,"currentEdges",new Map);r(this,"rafId",null);r(this,"isActive",!1);r(this,"callbacks",new Set);r(this,"currentMousePos",{x:0,y:0});r(this,"currentCursorEdge",{top:!1,right:!1,bottom:!1,left:!1,edge:null});this.edgeThreshold=e,this.targets=t instanceof Set?t:new Set(t),this.root=i,t&&t.forEach(s=>this.targets.add(s)),this.checkBoundaries=this.checkBoundaries.bind(this)}start(){this.isActive||(this.isActive=!0,this.setupMouseTracking(),this.checkBoundaries())}stop(){this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.isActive=!1}addTarget(e){this.targets.add(e)}removeTarget(e){this.targets.delete(e),this.currentEdges.delete(e)}onChange(e){return this.callbacks.add(e),()=>{this.callbacks.delete(e)}}getCursorEdgeInfo(){return{...this.currentCursorEdge}}setEdgeThreshold(e){if(e<0)throw new Error("Edge threshold must be non-negative");this.edgeThreshold=e}setupMouseTracking(){document.addEventListener("mousemove",e=>{this.currentMousePos={x:e.clientX,y:e.clientY}})}getViewportSize(){return this.root?{width:this.root.clientWidth,height:this.root.clientHeight}:{width:window.innerWidth,height:window.innerHeight}}getRelativeRect(e){const t=e.getBoundingClientRect();if(!this.root)return t;const i=this.root.getBoundingClientRect();return{x:t.left-i.left,y:t.top-i.top,top:t.top-i.top,bottom:t.bottom-i.top,left:t.left-i.left,right:t.right-i.left,height:t.height,width:t.width,toJSON:()=>{}}}getCursorPosition(){if(!this.root)return this.currentMousePos;const e=this.root.getBoundingClientRect();return{x:this.currentMousePos.x-e.left,y:this.currentMousePos.y-e.top}}checkBoundaries(){this.targets.forEach(t=>{const i=this.checkElementBoundaries(t),s=this.currentEdges.get(t);(!s||this.hasEdgeChanged(s,i))&&(this.currentEdges.set(t,i),this.notifyCallbacks(new Q({...i,source:"element",element:t})))});const e=this.checkCursorBoundaries();this.hasEdgeChanged(this.currentCursorEdge,e)&&(this.currentCursorEdge=e,this.notifyCallbacks(new Q({...e,source:"cursor",element:null}))),this.isActive&&(this.rafId=requestAnimationFrame(this.checkBoundaries))}getCursorBoundingClientRect(){const{x:e,y:t}=this.getCursorPosition();return{x:e,y:t,top:t,bottom:t,left:e,right:e,width:0,height:0,toJSON:()=>{}}}checkElementBoundaries(e){const{width:t,height:i}=this.getViewportSize(),s=this.getRelativeRect(e),a={top:s.top<this.edgeThreshold,right:s.right>t-this.edgeThreshold,bottom:s.bottom>i-this.edgeThreshold,left:s.left<this.edgeThreshold,edge:null};return this.determineEdge(a,s,t,i),a}checkCursorBoundaries(){const e=this.getCursorBoundingClientRect(),t=window.innerWidth,i=window.innerHeight,s={top:e.top<this.edgeThreshold,right:e.right>t-this.edgeThreshold,bottom:e.bottom>i-this.edgeThreshold,left:e.left<this.edgeThreshold,edge:null};return this.determineEdge(s,e,t,i),s}hasEdgeChanged(e,t){return e.top!==t.top||e.right!==t.right||e.bottom!==t.bottom||e.left!==t.left}determineEdge(e,t,i,s){const a=[];if(e.top&&a.push("top"),e.right&&a.push("right"),e.bottom&&a.push("bottom"),e.left&&a.push("left"),a.length===0)e.edge=null;else if(a.length===1)e.edge=a[0];else{const o={top:t.top,right:i-t.right,bottom:s-t.bottom,left:t.left};e.edge=a.reduce((c,g)=>o[g]<o[c]?g:c)}}notifyCallbacks(e){this.callbacks.forEach(t=>{try{t(e)}catch(i){console.error("Error in boundary change callback:",i)}})}destroy(){this.stop(),this.callbacks.clear()}}const b=class b extends ae{constructor(t,i){super(t,i);r(this,"lastEdge",{});r(this,"emitter",null);this.onChange(this.onBoundaryChange.bind(this)),this.start()}static init(t,i){return b.instance??(b.instance=new b(t,i))}changed({edge:t,source:i,element:s}){return t!==this.lastEdge.edge||i!==this.lastEdge.source||s!==this.lastEdge.element}onBoundaryChange({edge:t,source:i,element:s}){this.changed({edge:t,source:i,element:s})&&(this.lastEdge=Object.entries({edge:t,source:i,element:s}).reduce(re,{}),s?t?this.onEdgeEnter({edge:t,source:i,element:s}):this.onEdgeLeave(this.lastEdge):t?this.onCursorEnter({edge:t,source:i}):this.onCursorLeave(this.lastEdge))}onEdgeEnter(t){var i;(i=this.emitter)==null||i.emit("edge:enter",t)}onEdgeLeave(t){var i;(i=this.emitter)==null||i.emit("edge:leave",t)}onCursorEnter(t){var i;(i=this.emitter)==null||i.emit("cursor:enter",t)}onCursorLeave(t){var i;(i=this.emitter)==null||i.emit("cursor:leave",t)}setEmitter(t){this.emitter=t}on(t,i){var s;(s=this.emitter)==null||s.on(t,i)}getCurrentEdge(){return this.lastEdge}};r(b,"instance");let H=b;function oe(h={},e=[]){const t=H.init(h.edgeThreshold,e);return h.emitter&&t.setEmitter(h.emitter instanceof j?h.emitter:new j),t}const p=class p{constructor(){r(this,"draggable",[])}zIndex(e){return`${p.highestZIndex+this.draggable.findIndex(t=>t===e)}`}push(e){return this.draggable=[...new Set([...this.draggable,e])],this}remove(e){return this.draggable=this.draggable.filter(t=>t!==e),this}sort(e){return this.draggable.sort((t,i)=>t===e?1:i===e?-1:0),this}};r(p,"inatance"),r(p,"highestZIndex",1e3),r(p,"init",()=>p.inatance??(p.inatance=new p));let I=p;function W(){return{width:window.innerWidth||document.documentElement.clientWidth,height:window.innerHeight||document.documentElement.clientHeight}}function ce(){return I.init()}const S=class S{constructor(e,t={}){r(this,"dragStream");r(this,"resizeStream");r(this,"stateChangeStream");r(this,"eventEmitter");r(this,"pluginEventEmitter");r(this,"config");r(this,"container");r(this,"dragHandle");r(this,"resizeHandles",new Map);r(this,"installedPlugins",new Set);r(this,"reactiveEffects",[]);r(this,"isDragging",!1);r(this,"isResizing",!1);r(this,"resizeDirection",null);r(this,"startX",0);r(this,"startY",0);r(this,"startState");r(this,"resizeObserver",null);r(this,"parentResizeObserver",null);r(this,"zIndexState");r(this,"reactiveState",d.reactive({x:0,y:0,width:0,height:0,mode:"smooth",draggingDirection:"all"}));r(this,"constrainedState",d.computed(()=>{var s;const e=this.reactiveState;if(!this.config)return{...e};let t={...e};const{boundaries:i}=this.config;if(t.width=u.clamp(e.width,i.minWidth||S.MINWIDTH,i.maxWidth||1/0),t.height=u.clamp(e.height,i.minHeight||S.MINHEIGHT,i.maxHeight||1/0),this.shouldConstrainToViewport()){const a=W();t.x=u.clamp(e.x,0,a.width-t.width),t.y=u.clamp(e.y,0,a.height-t.height)}return(s=this.config)!=null&&s.constrainToParent&&(t=this.constrainToParent(t)),t}));r(this,"domUpdateEffect",d.effect(()=>{var t;const e=this.constrainedState.value;this.container&&(this.container.style.left=`${e.x}px`,this.container.style.top=`${e.y}px`,this.container.style.width=`${e.width}px`,this.container.style.height=`${e.height}px`,(t=this.eventEmitter)==null||t.emit("stateChange",{type:"stateChange",state:{...e},mode:this.reactiveState.mode,element:this.container}))}));this.config=u.deepMerge({_uid:"",mode:"smooth",constrainToViewport:!1,draggingDirection:"all",constrainToParent:!1,boundaries:{minWidth:S.MINWIDTH,minHeight:S.MINHEIGHT},autoAdjust:{enabled:!1,width:!1,height:!1},resize:{enabled:!0,directions:["se"]}},t),this.container=e,this.zIndexState=ce();const i=this.getCurrentState();this.reactiveState.x=i.x,this.reactiveState.y=i.y,this.reactiveState.width=i.width,this.reactiveState.height=i.height,this.reactiveState.mode=this.config.mode,this.reactiveState.draggingDirection=this.config.draggingDirection,this.eventEmitter=new d({enableMetrics:!0}),this.pluginEventEmitter=new d({enableMetrics:!0}),this.stateChangeStream=this.eventEmitter.stream("stateChange"),this.dragStream=this.eventEmitter.stream("drag"),this.resizeStream=this.eventEmitter.stream("resize"),this.startState=this.getState(),this.setupEventMiddleware(),this.initializeHandles(),this.bindEvents(),this.setupResizeObservers(),this.setupReactiveMonitoring()}setupResizeObservers(){var e;this.shouldConstrainToViewport()&&this.setupViewportResizeObserver(),(e=this.config.autoAdjust)!=null&&e.enabled&&this.setupParentResizeObserver()}shouldConstrainToViewport(){return!this.config.constrainToParent||this.config.constrainToViewport}setupViewportResizeObserver(){let e=null;this.resizeObserver=new ResizeObserver(()=>{e&&cancelAnimationFrame(e),e=requestAnimationFrame(()=>{this.handleViewportResize()})}),this.resizeObserver.observe(document.body)}handleViewportResize(){if(!this.shouldConstrainToViewport())return;const e=W(),i={...this.getState()};let s=!1;i.x+i.width>e.width&&(i.x=Math.max(0,e.width-i.width),s=!0),i.y+i.height>e.height&&(i.y=Math.max(0,e.height-i.height),s=!0),i.x<0&&(i.x=0,s=!0),i.y<0&&(i.y=0,s=!0),s&&(this.setState(i),this.eventEmitter.emit("viewportResize",{type:"viewportResize",state:this.getState(),mode:this.reactiveState.mode,element:this.container}))}setupParentResizeObserver(){const e=this.container.parentElement;e&&(this.parentResizeObserver=new ResizeObserver(t=>{for(const i of t)this.handleParentResize(i)}),this.parentResizeObserver.observe(e))}handleParentResize(e){const{autoAdjust:t}=this.config;if(!(t!=null&&t.enabled))return;const i=e.contentRect,a={...this.getState()};let o=!1;if(t.width){const c=this.getMaxWidthConstraint(),g=Math.min(i.width,c);Math.abs(a.width-g)>1&&(a.width=g,o=!0)}if(t.height){const c=this.getMaxHeightConstraint(),g=Math.min(i.height,c);Math.abs(a.height-g)>1&&(a.height=g,o=!0)}o&&(this.setState(a),this.eventEmitter.emit("autoAdjust",{type:"autoAdjust",state:this.getState(),mode:this.reactiveState.mode,element:this.container}))}initializeHandles(){var e;this.initializeDragHandle(),(e=this.config.resize)!=null&&e.enabled&&this.initializeResizeHandles()}initializeDragHandle(){this.dragHandle=this.container.querySelector("[data-drag-handle]"),this.dragHandle?this.dragHandle.setAttribute("oncontextmenu","return false"):(this.dragHandle=document.createElement("div"),this.dragHandle.className="drag-handle",this.dragHandle.setAttribute("data-drag-handle","true"),this.dragHandle.setAttribute("oncontextmenu","return false"),this.container.prepend(this.dragHandle))}initializeResizeHandles(){var t;(((t=this.config.resize)==null?void 0:t.directions)||["se"]).forEach(i=>{const s=this.createResizeHandle(i);this.resizeHandles.set(i,s),this.container.appendChild(s)})}createResizeHandle(e){const t=document.createElement("div");return t.className=`resize-handle resize-${e}`,t.setAttribute("data-resize-handle",e),t.setAttribute("data-resize-direction",e),t.addEventListener("contextmenu",this.onContextMenu),this.applyResizeHandleStyles(t,e),t}applyResizeHandleStyles(e,t){const i={n:"ns-resize",s:"ns-resize",e:"ew-resize",w:"ew-resize",ne:"nesw-resize",nw:"nwse-resize",se:"nwse-resize",sw:"nesw-resize"};e.style.position="absolute",e.style.cursor=i[t],this.positionResizeHandle(e,t)}positionResizeHandle(e,t){switch(t){case"n":e.style.top="0",e.style.left="0",e.style.right="0",e.style.height="12px";break;case"s":e.style.bottom="0",e.style.left="0",e.style.right="0",e.style.height="12px";break;case"e":e.style.right="0",e.style.top="0",e.style.bottom="0",e.style.width="12px";break;case"w":e.style.left="0",e.style.top="0",e.style.bottom="0",e.style.width="12px";break;case"ne":e.style.top="0",e.style.right="0",e.style.width="12px",e.style.height="12px";break;case"nw":e.style.top="0",e.style.left="0",e.style.width="12px",e.style.height="12px";break;case"se":e.style.bottom="0",e.style.right="0",e.style.width="12px",e.style.height="12px";break;case"sw":e.style.bottom="0",e.style.left="0",e.style.width="12px",e.style.height="12px";break}}bindEvents(){var e;this.onDragStart=this.onDragStart.bind(this),this.onDragMove=this.onDragMove.bind(this),this.onDragEnd=this.onDragEnd.bind(this),this.onResizeStart=this.onResizeStart.bind(this),this.onResizeMove=this.onResizeMove.bind(this),this.onResizeEnd=this.onResizeEnd.bind(this),this.onContextMenu=this.onContextMenu.bind(this),this.hasPluginByName("SnappingPlugin")||(this.dragHandle.addEventListener("mousedown",this.onDragStart),this.dragHandle.addEventListener("touchstart",this.onDragStart)),(e=this.config.resize)!=null&&e.enabled&&this.resizeHandles.forEach((t,i)=>{t.addEventListener("mousedown",s=>this.onResizeStart(s,i)),t.addEventListener("touchstart",s=>this.onResizeStart(s,i))}),this.dragHandle.addEventListener("contextmenu",this.onContextMenu)}applyMovementMode(e,t){const i={...this.startState};return this.reactiveState.mode==="smooth"&&(i.x=this.startState.x+e,i.y=this.startState.y+t),i}calculateResizeState(e,t,i){const s={...this.startState};switch(i){case"e":s.width=this.startState.width+e;break;case"w":s.width=this.startState.width-e,s.x=this.startState.x+e;break;case"n":s.height=this.startState.height-t,s.y=this.startState.y+t;break;case"s":s.height=this.startState.height+t;break;case"ne":s.width=this.startState.width+e,s.height=this.startState.height-t,s.y=this.startState.y+t;break;case"nw":s.width=this.startState.width-e,s.height=this.startState.height-t,s.x=this.startState.x+e,s.y=this.startState.y+t;break;case"se":s.width=this.startState.width+e,s.height=this.startState.height+t;break;case"sw":s.width=this.startState.width-e,s.height=this.startState.height+t,s.x=this.startState.x+e;break}return s}constrainToParent(e){const t=this.container.parentElement;if(!t)return e;const i=t.getBoundingClientRect();if(i.width===0||i.height===0)return e;const s=Math.max(0,i.width-e.width),a=Math.max(0,i.height-e.height),o=i.width-e.x,c=i.height-e.y;return{x:u.clamp(e.x,0,s),y:u.clamp(e.y,0,a),width:u.clamp(e.width,0,o),height:u.clamp(e.height,0,c)}}getMaxWidthConstraint(){const{boundaries:e}=this.config;let t=e.maxWidth||1/0;if(this.config.constrainToParent&&this.container.parentElement){const i=this.container.parentElement.getBoundingClientRect().width;t=Math.min(t,i)}return t}getMaxHeightConstraint(){const{boundaries:e}=this.config;let t=e.maxHeight||1/0;if(this.config.constrainToParent&&this.container.parentElement){const i=this.container.parentElement.getBoundingClientRect().height;t=Math.min(t,i)}return t}onContextMenu(e){e.preventDefault(),e.stopPropagation()}hasPluginByName(e){return Array.from(this.installedPlugins).some(t=>t.constructor.name===e)}getCurrentState(){const e=this.container.getBoundingClientRect(),t=window.getComputedStyle(this.container),i=parseFloat(t.width)||e.width,s=parseFloat(t.height)||e.height;return{x:e.left,y:e.top,width:i,height:s}}setupEventMiddleware(){this.eventEmitter.use("*",(e,t)=>(typeof window<"u"&&window.DEBUG_CONTAINER_MANAGER&&console.log(`[ContainerManager] ${t}:`,e),e)),this.eventEmitter.use("dragStart",(e,t)=>{if(this.reactiveState.mode==="pinned")throw new Error("Cannot drag in pinned mode");return e}),this.eventEmitter.use("drag",(e,t)=>e)}setupReactiveMonitoring(){const e=d.effect(()=>{const{state:i}=this.stateChangeStream});this.reactiveEffects.push(e);const t=d.effect(()=>{const i=this.eventEmitter.getMetrics();i.state.errorCount>10&&console.warn("[ContainerManager] High error count in event system:",i.state.errorCount)});this.reactiveEffects.push(t)}on(e,t){this.eventEmitter.on(e,t)}off(e,t){this.eventEmitter.off(e,t)}waitFor(e,t){return this.eventEmitter.waitFor(e,t)}getStream(e){return this.eventEmitter.stream(e)}pipe(e,t,i){return this.eventEmitter.pipe(e,t,i)}getEventMetrics(){return this.eventEmitter.getMetrics()}emitPluginEvent(e,t){this.pluginEventEmitter.emit(e,t)}onPluginEvent(e,t){this.pluginEventEmitter.on(e,t)}offPluginEvent(e,t){this.pluginEventEmitter.off(e,t)}usePluginMiddleware(e,t){return this.pluginEventEmitter.use(e,t)}onDragStart(e){if(this.reactiveState.mode==="pinned")return;e.preventDefault(),this.bringToFront(),this.isDragging=!0;const t=e instanceof MouseEvent?e.clientX:e.touches[0].clientX,i=e instanceof MouseEvent?e.clientY:e.touches[0].clientY;this.startX=t,this.startY=i,this.startState=this.getState(),this.eventEmitter.emit("dragStart",{type:"drag",state:this.getState(),mode:this.reactiveState.mode,element:this.container}),document.addEventListener("mousemove",this.onDragMove),document.addEventListener("mouseup",this.onDragEnd),document.addEventListener("touchmove",this.onDragMove),document.addEventListener("touchend",this.onDragEnd)}onDragMove(e){if(!this.isDragging)return;const{clientX:t,clientY:i}=this.directionResolver(e instanceof MouseEvent?e.clientX:e.touches[0].clientX,e instanceof MouseEvent?e.clientY:e.touches[0].clientY),s=t-this.startX,a=i-this.startY,o=this.applyMovementMode(s,a);this.setState(o),this.eventEmitter.emit("drag",{type:"drag",state:this.getState(),mode:this.reactiveState.mode,element:this.container})}onDragEnd(){this.isDragging=!1,document.removeEventListener("mousemove",this.onDragMove),document.removeEventListener("mouseup",this.onDragEnd),document.removeEventListener("touchmove",this.onDragMove),document.removeEventListener("touchend",this.onDragEnd),this.eventEmitter.emit("dragEnd",{type:"drag",state:this.getState(),mode:this.reactiveState.mode,element:this.container})}onResizeStart(e,t){e.preventDefault(),e.stopPropagation(),this.bringToFront(),this.isResizing=!0,this.resizeDirection=t;const i=e instanceof MouseEvent?e.clientX:e.touches[0].clientX,s=e instanceof MouseEvent?e.clientY:e.touches[0].clientY;this.startX=i,this.startY=s,this.startState=this.getState(),document.addEventListener("mousemove",this.onResizeMove),document.addEventListener("mouseup",this.onResizeEnd),document.addEventListener("touchmove",this.onResizeMove),document.addEventListener("touchend",this.onResizeEnd),this.eventEmitter.emit("resizeStart",{type:"resize",state:this.getState(),mode:this.reactiveState.mode,element:this.container,direction:t})}onResizeMove(e){if(!this.isResizing||!this.resizeDirection)return;const t=e instanceof MouseEvent?e.clientX:e.touches[0].clientX,i=e instanceof MouseEvent?e.clientY:e.touches[0].clientY,s=t-this.startX,a=i-this.startY,o=this.calculateResizeState(s,a,this.resizeDirection);this.setState(o),this.eventEmitter.emit("resize",{type:"resize",state:this.getState(),mode:this.reactiveState.mode,direction:this.resizeDirection,element:this.container})}onResizeEnd(){this.isResizing=!1,this.resizeDirection=null,document.removeEventListener("mousemove",this.onResizeMove),document.removeEventListener("mouseup",this.onResizeEnd),document.removeEventListener("touchmove",this.onResizeMove),document.removeEventListener("touchend",this.onResizeEnd),this.eventEmitter.emit("resizeEnd",{type:"resize",state:this.getState(),mode:this.reactiveState.mode,element:this.container})}setDirection(e){this.reactiveState.draggingDirection=e,this.emitPluginEvent("directionChanged",{direction:e})}getDirection(){return this.reactiveState.draggingDirection}directionResolver(e,t){const i=this.reactiveState.draggingDirection,s=i==="vertical",a=i==="horizontal";return{clientX:s?this.startX:e,clientY:a?this.startY:t}}getMode(){return this.reactiveState.mode}setMode(e){this.reactiveState.mode=e,this.eventEmitter.emit("modeChange",{type:"modeChange",state:this.getState(),mode:this.reactiveState.mode,element:this.container})}setBoundaries(e){this.config.boundaries={...this.config.boundaries,...e}}getState(){return{x:this.reactiveState.x,y:this.reactiveState.y,width:this.reactiveState.width,height:this.reactiveState.height}}setState(e){e.height!==void 0&&(this.reactiveState.height=e.height),e.width!==void 0&&(this.reactiveState.width=e.width),e.x!==void 0&&(this.reactiveState.x=e.x),e.y!==void 0&&(this.reactiveState.y=e.y),this.applyStateToDOM()}applyStateToDOM(){const e=this.getState();this.container.style.left=`${e.x}px`,this.container.style.top=`${e.y}px`,this.container.style.width=`${e.width}px`,this.container.style.height=`${e.height}px`}bringToFront(){const{_uid:e}=this.config;this.container.style.zIndex=this.zIndexState.sort(e).zIndex(e)}getContainer(){return this.container}setAutoAdjust(e){var t;this.config.autoAdjust={...this.config.autoAdjust,...e},this.parentResizeObserver&&(this.parentResizeObserver.disconnect(),this.parentResizeObserver=null),(t=this.config.autoAdjust)!=null&&t.enabled&&this.setupParentResizeObserver()}setResizeConfig(e){var t;this.config.resize={...this.config.resize,...e},this.resizeHandles.forEach(i=>i.remove()),this.resizeHandles.clear(),(t=this.config.resize)!=null&&t.enabled&&(this.initializeResizeHandles(),this.bindEvents())}setConstrainToParent(e){this.config.constrainToParent=e,this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.shouldConstrainToViewport()&&this.setupViewportResizeObserver()}setConstrainToViewport(e){this.config.constrainToViewport=e,this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.shouldConstrainToViewport()&&this.setupViewportResizeObserver()}recalculateForParent(){if(!this.config.constrainToParent||!this.container.parentElement)return;const e=this.container.parentElement.getBoundingClientRect(),t=this.getState();if(e.width===0||e.height===0)return;const i=t.width,s=t.height,a=Math.min(i,e.width),o=Math.min(s,e.height),c=t.x,g=t.y,m=Math.min(c,e.width-a),w=Math.min(g,e.height-o);this.setState({x:m,y:w,width:a,height:o}),this.eventEmitter.emit("parentRecalculated",{type:"parentRecalculated",state:this.getState(),mode:this.reactiveState.mode,element:this.container})}use(e,t){if(this.installedPlugins.has(e))return this;try{e.install(this,t),this.installedPlugins.add(e)}catch(i){console.error("[ContainerManager] Failed to install plugin:",i)}return this}hasPlugin(e){return this.installedPlugins.has(e)}getInstalledPlugins(){return Array.from(this.installedPlugins)}destroy(){this.reactiveEffects.forEach(e=>e()),this.reactiveEffects=[],this.stateChangeStream.destroy(),this.dragStream.destroy(),this.resizeStream.destroy(),this.eventEmitter.destroy(),this.pluginEventEmitter.destroy(),this.domUpdateEffect(),this.dragHandle.removeEventListener("mousedown",this.onDragStart),this.dragHandle.removeEventListener("touchstart",this.onDragStart),this.dragHandle.removeEventListener("contextmenu",this.onContextMenu),this.resizeHandles.forEach((e,t)=>{e.removeEventListener("mousedown",i=>this.onResizeStart(i,t)),e.removeEventListener("touchstart",i=>this.onResizeStart(i,t))}),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.parentResizeObserver&&(this.parentResizeObserver.disconnect(),this.parentResizeObserver=null),this.installedPlugins.clear(),this.zIndexState.remove(this.config._uid)}};r(S,"MINWIDTH",200),r(S,"MINHEIGHT",45);let $=S;const D=class D{constructor(e={}){r(this,"reactiveState",d.reactive({snapStep:10,enabled:!0,isActive:!1,lastPosition:null}));r(this,"manager");r(this,"startState",null);r(this,"startX",0);r(this,"startY",0);this.reactiveState.snapStep=e.snapStep??10,this.reactiveState.enabled=e.enabled??!0,this.onDragMove=this.onDragMove.bind(this),this.onDragEnd=this.onDragEnd.bind(this)}get pluginId(){return D._pluginId}install(e,t){this.manager=e,t&&(this.reactiveState.snapStep=t.snapStep??this.reactiveState.snapStep,this.reactiveState.enabled=t.enabled??this.reactiveState.enabled),this.overrideDragMethods(),this.addPluginMethods()}overrideDragMethods(){if(!this.manager)return;const e=this.manager.getContainer().querySelector(".drag-handle");e&&(e.onmousedown=t=>{this.onDragStart(t)},e.ontouchstart=t=>{this.onDragStart(t)})}onDragStart(e){var s,a;if(!this.manager||this.manager.getMode()==="pinned")return;e.preventDefault(),(a=(s=this.manager).bringToFront)==null||a.call(s),this.reactiveState.isActive=!0;const t=e instanceof MouseEvent?e.clientX:e.touches[0].clientX,i=e instanceof MouseEvent?e.clientY:e.touches[0].clientY;this.startX=t,this.startY=i,this.startState=this.manager.getState(),this.reactiveState.lastPosition={x:this.startState.x,y:this.startState.y},document.addEventListener("mousemove",this.onDragMove),document.addEventListener("mouseup",this.onDragEnd),document.addEventListener("touchmove",this.onDragMove),document.addEventListener("touchend",this.onDragEnd),this.manager.emitPluginEvent("dragStart",{type:"drag",state:this.startState,mode:this.manager.getMode()})}onDragMove(e){if(!this.reactiveState.isActive||!this.manager||!this.startState)return;const{clientX:t,clientY:i}=this.manager.directionResolver(e instanceof MouseEvent?e.clientX:e.touches[0].clientX,e instanceof MouseEvent?e.clientY:e.touches[0].clientY);let s=t-this.startX,a=i-this.startY;if(this.reactiveState.enabled){const g=this.applySnapping(s,a);s=g.deltaX,a=g.deltaY}const o={x:this.startState.x+s,y:this.startState.y+a,width:this.startState.width,height:this.startState.height},c=this.manager.config;c!=null&&c.constrainToViewport&&this.constrainToViewport(o),this.manager.setState(o),this.reactiveState.lastPosition={x:o.x,y:o.y},this.manager.emitPluginEvent("drag",{type:"drag",state:o,mode:this.manager.getMode()})}onDragEnd(){this.manager&&(this.reactiveState.isActive=!1,this.reactiveState.lastPosition=null,this.startState=null,document.removeEventListener("mousemove",this.onDragMove),document.removeEventListener("mouseup",this.onDragEnd),document.removeEventListener("touchmove",this.onDragMove),document.removeEventListener("touchend",this.onDragEnd),this.manager.emitPluginEvent("dragEnd",{type:"drag",state:this.manager.getState(),mode:this.manager.getMode()}))}applySnapping(e,t){return{deltaX:this.snapToGrid(e,this.reactiveState.snapStep),deltaY:this.snapToGrid(t,this.reactiveState.snapStep)}}snapToGrid(e,t){return Math.round(e/t)*t}constrainToViewport(e){const t=window.innerWidth||document.documentElement.clientWidth,i=window.innerHeight||document.documentElement.clientHeight;e.x=Math.max(0,Math.min(e.x,t-e.width)),e.y=Math.max(0,Math.min(e.y,i-e.height))}addPluginMethods(){this.manager.setSnapStep=e=>{this.reactiveState.snapStep=e,this.manager.emitPluginEvent("snapStepChanged",{snapStep:e})},this.manager.setSnappingEnabled=e=>{this.reactiveState.enabled=e,this.manager.emitPluginEvent("snappingEnabledChanged",{enabled:e})},this.manager.getSnappingConfig=()=>({snapStep:this.reactiveState.snapStep,enabled:this.reactiveState.enabled})}destroy(){this.reactiveState.isActive=!1,this.reactiveState.lastPosition=null}};r(D,"_pluginId",Symbol("SnappingPlugin"));let A=D;const R=class R{constructor(e={}){r(this,"dockedContainers",new Map);r(this,"occupiedEdges",new Map);r(this,"tracker",oe({emitter:!0,edgeThreshold:20}));r(this,"manager");r(this,"edgeThreshold");this.edgeThreshold=e.edgeThreshold??30,this.occupiedEdges.set("top",null),this.occupiedEdges.set("bottom",null),this.occupiedEdges.set("left",null),this.occupiedEdges.set("right",null)}get pluginId(){return R._pluginId}install(e){this.manager=e,this.tracker.addTarget(this.manager.getContainer()),this.tracker.on("edge:enter",t=>{t.source==="element"&&t.element===this.manager.getContainer()&&this.handleEdgeEnter(t.edge)}),this.tracker.on("edge:leave",t=>{t.source==="element"&&t.element===this.manager.getContainer()&&this.handleEdgeLeave(t.edge)}),this.attachEventHandlers()}handleEdgeEnter(e){const t=this.manager.getContainer();this.isEdgeOccupied(e)?t.classList.add("edge-dock-hint",`edge-dock-hint-${e}`,"edge-dock-blocked"):t.classList.add("edge-dock-hint",`edge-dock-hint-${e}`)}handleEdgeLeave(e){this.manager.getContainer().classList.remove("edge-dock-hint",`edge-dock-hint-${e}`,"edge-dock-blocked")}isEdgeOccupied(e){return this.occupiedEdges.get(e)!==null}attachEventHandlers(){const e=this.manager.getContainer();e.addEventListener("mouseenter",this.onMouseEnter.bind(this)),e.addEventListener("mouseleave",this.onMouseLeave.bind(this)),this.manager.on("dragStart",t=>{this.onDragStart(t.element)}),this.manager.on("drag",t=>{this.onDrag(t.element)}),this.manager.on("dragEnd",t=>{this.onDragEnd(t.element)})}onMouseEnter(){const e=this.manager.getContainer();this.isContainerDocked(e)&&e.classList.add("edge-docked-visible")}onMouseLeave(){const e=this.manager.getContainer();this.isContainerDocked(e)&&e.classList.remove("edge-docked-visible")}onDragStart(e){e.classList.remove("edge-dock-hint","edge-dock-blocked","edge-docked-visible","edge-dock-hint-top","edge-dock-hint-bottom","edge-dock-hint-left","edge-dock-hint-right");const t=this.dockedContainers.get(e);t&&this.undockContainer(e,t)}onDrag(e){const t=e.getBoundingClientRect(),i=this.getClosestEdge(t);this.updateEdgeHints(e,i)}onDragEnd(e){const t=e.getBoundingClientRect(),i=this.getClosestEdge(t);e.classList.remove("edge-dock-hint","edge-dock-blocked","edge-dock-hint-top","edge-dock-hint-bottom","edge-dock-hint-left","edge-dock-hint-right"),i&&!this.isEdgeOccupied(i)&&this.dockContainer(e,i)}updateEdgeHints(e,t){e.classList.remove("edge-dock-hint","edge-dock-blocked","edge-dock-hint-top","edge-dock-hint-bottom","edge-dock-hint-left","edge-dock-hint-right"),t&&(this.isEdgeOccupied(t)?e.classList.add("edge-dock-hint",`edge-dock-hint-${t}`,"edge-dock-blocked"):e.classList.add("edge-dock-hint",`edge-dock-hint-${t}`))}getClosestEdge(e){const t=e.top,i=e.left,s=window.innerHeight-e.bottom,a=window.innerWidth-e.right,c=Object.entries({top:t,bottom:s,left:i,right:a}).filter(([g,m])=>m>=-this.edgeThreshold&&m<=this.edgeThreshold).sort((g,m)=>g[1]-m[1]);return c.length>0?c[0][0]:null}dockContainer(e,t){const i=window.getComputedStyle(e),s=e.getBoundingClientRect(),a={x:s.left,y:s.top};this.dockedContainers.set(e,{element:e,edge:t,screenPosition:a,originalPosition:{top:parseFloat(i.top)||s.top,left:parseFloat(i.left)||s.left,width:s.width,height:s.height,transform:i.transform,position:i.position}}),this.occupiedEdges.set(t,e),e.style.top="",e.style.bottom="",e.style.left="",e.style.right="",e.style.width="",e.style.height="",e.style.transform="",e.classList.add("edge-docked",`edge-docked-${t}`),this.applyEdgePositioning(e,t,a),e.setAttribute("data-docked","true"),e.setAttribute("data-docked-edge",t)}applyEdgePositioning(e,t,i){const s=e.getBoundingClientRect();switch(t){case"top":e.style.left=`${i.x}px`,e.style.width=`${s.width}px`;break;case"bottom":e.style.left=`${i.x}px`,e.style.width=`${s.width}px`;break;case"left":e.style.top=`${i.y}px`,e.style.height=`${s.height}px`;break;case"right":e.style.top=`${i.y}px`,e.style.height=`${s.height}px`;break}}undockContainer(e,t){this.dockedContainers.delete(e),this.occupiedEdges.set(t.edge,null),e.classList.remove("edge-docked","edge-docked-visible","edge-docked-top","edge-docked-bottom","edge-docked-left","edge-docked-right"),e.removeAttribute("data-docked"),e.removeAttribute("data-docked-edge"),e.style.top="",e.style.bottom="",e.style.left="",e.style.right="",e.style.width="",e.style.height="",e.style.transform="",e.style.position="",this.restoreOriginalPosition(e,t)}restoreOriginalPosition(e,t){this.manager.setState({x:t.screenPosition.x,y:t.screenPosition.y,width:t.originalPosition.width,height:t.originalPosition.height})}getDockedContainer(e){const t=this.occupiedEdges.get(e);return t&&this.dockedContainers.get(t)||null}isContainerDocked(e){return this.dockedContainers.has(e)}getContainerDockEdge(e){const t=this.dockedContainers.get(e);return t?t.edge:null}destroy(){const e=this.manager.getContainer();e.removeEventListener("mouseenter",this.onMouseEnter.bind(this)),e.removeEventListener("mouseleave",this.onMouseLeave.bind(this)),this.dockedContainers.forEach((t,i)=>{this.undockContainer(i,t)}),this.dockedContainers.clear(),this.occupiedEdges.forEach((t,i)=>{this.occupiedEdges.set(i,null)})}};r(R,"_pluginId",Symbol("EdgeDockingPlugin"));let N=R;const n=class n{constructor(){r(this,"manager");r(this,"containerId");r(this,"isDemoContainer",!1);r(this,"autoSaveEffect")}get pluginId(){return n._pluginId}static get containerStates(){return n.reactiveState.containerStates}static get closedQueue(){return n.reactiveState.closedQueue}static get demoContainers(){return n.reactiveState.demoContainers}install(e,t){if(this.manager=e,this.containerId=t==null?void 0:t.containerId,this.isDemoContainer=(t==null?void 0:t.isDemo)||!1,!this.containerId){console.warn("[StatePersistencePlugin] containerId is required for state persistence");return}n.containers.push({manager:e,containerId:this.containerId,isDemo:this.isDemoContainer}),this.isDemoContainer&&n.registerDemoContainer(this.containerId),n.isGlobalEventsInitialized||(n.initializeGlobalEvents(),n.isGlobalEventsInitialized=!0),this.isDemoContainer&&this.setupAutoSaveEffect(),this.bindContainerEvents()}setupAutoSaveEffect(){if(!this.manager||!this.containerId)return;const e=u.debounce(()=>{this.isDemoContainer&&this.saveState()},300);this.autoSaveEffect=d.effect(()=>{this.manager.getState(),this.manager.getMode(),e()})}bindContainerEvents(){this.manager&&(this.manager.on("dragStart",()=>{}),this.manager.on("dragEnd",()=>{this.isDemoContainer&&this.saveState()}),this.manager.on("resizeEnd",()=>{this.isDemoContainer&&this.saveState()}),this.manager.onPluginEvent("maximizeChanged",()=>{this.isDemoContainer&&this.saveState()}),this.manager.onPluginEvent("directionChanged",()=>{this.isDemoContainer&&this.saveState()}))}static initializeGlobalEvents(){window.addEventListener("beforeunload",()=>{n.saveAllContainers()}),document.addEventListener("visibilitychange",()=>{document.hidden&&n.saveAllContainers()}),window.addEventListener("resize",u.debounce(()=>{n.saveAllContainers()},500))}static registerDemoContainer(e){try{n.demoContainers.includes(e)||(n.demoContainers.push(e),n.saveDemoContainersToStorage())}catch(t){console.error("[StatePersistencePlugin] Failed to register demo container:",t)}}static saveDemoContainersToStorage(){try{localStorage.setItem(n.DEMO_CONTAINERS_KEY,JSON.stringify(n.demoContainers))}catch(e){console.error("[StatePersistencePlugin] Failed to save demo containers:",e)}}static getDemoContainers(){try{const e=localStorage.getItem(n.DEMO_CONTAINERS_KEY);return e?JSON.parse(e):[]}catch(e){return console.error("[StatePersistencePlugin] Failed to parse demo containers:",e),[]}}static isDemoContainer(e){return n.getDemoContainers().includes(e)}static getAllStates(){try{const e=localStorage.getItem(n.STORAGE_KEY);return e?JSON.parse(e):{}}catch(e){return console.error("[StatePersistencePlugin] Failed to parse stored states:",e),{}}}static addToClosedQueue(e){if(!n.isDemoContainer(e)){console.log(`[StatePersistencePlugin] Skipping closed queue for non-demo container: ${e}`);return}if(!n.getContainerState(e)){console.error(`[StatePersistencePlugin] Cannot add ${e} to closed queue: state not found`);return}const i=n.closedQueue,s=i.indexOf(e);s>-1&&i.splice(s,1),i.push(e),n.saveClosedQueueToStorage()}static saveClosedQueueToStorage(){try{localStorage.setItem(n.CLOSED_QUEUE_KEY,JSON.stringify(n.closedQueue))}catch(e){console.error("[StatePersistencePlugin] Failed to save closed queue:",e)}}static getClosedQueue(){try{const e=localStorage.getItem(n.CLOSED_QUEUE_KEY);return e?JSON.parse(e):[]}catch(e){return console.error("[StatePersistencePlugin] Failed to parse closed queue:",e),[]}}saveState(){!this.manager||!this.containerId||!this.isDemoContainer||d.batch(()=>{var z;n.reactiveState.isSaving=!0,n.reactiveState.pendingChanges=!0;const e=this.manager.getContainer(),t=e.dataset.maximized==="true",i=this.manager.getState(),s=this.manager.getMode(),a=this.manager.getDirection(),o=e.dataset.containerType||"unknown",c=e.dataset.title,g=e.dataset.color,m=e.dataset.useSnapping==="true",w=(z=this.manager.config)==null?void 0:z.resize,y=e.parentElement,x=y&&y!==document.body?y.id||`parent-${this.containerId}`:void 0,C={...i,mode:s,draggingDirection:a,isMaximized:t,containerType:o,title:c,color:g,useSnapping:m,isClosed:!1,parentElementId:x,closedTimestamp:0,resize:w,isDemoContainer:!0};n.reactiveState.containerStates[this.containerId]=C;const E=n.getAllStates();E[this.containerId]=C,localStorage.setItem(n.STORAGE_KEY,JSON.stringify(E)),n.reactiveState.lastSaved=Date.now(),n.reactiveState.isSaving=!1})}static saveContainerStateBeforeClose(e,t){var G,U,K;const i=e.getState(),s=e.getMode();if(!n.isDemoContainer(t)){n.containers=n.containers.filter(M=>M.containerId!==t);return}const o=e.getContainer(),c=e.getDirection(),g=o.dataset.maximized==="true",m=o.dataset.containerType||"unknown",w=o.dataset.title,y=o.dataset.color,x=o.dataset.useSnapping==="true",C=(G=e.config)==null?void 0:G.resize,E=((U=e.isEdgeDocked)==null?void 0:U.call(e))||!1,z=((K=e.getDockEdge)==null?void 0:K.call(e))||null,k=o.parentElement,ge=k&&k!==document.body?k.id||`parent-${t}`:void 0,X={...i,mode:s,draggingDirection:c,isMaximized:g,isEdgeDocked:E,dockEdge:z||void 0,containerType:m,title:w,color:y,useSnapping:x,isClosed:!0,parentElementId:ge,closedTimestamp:Date.now(),resize:C,isDemoContainer:!0},V=n.getAllStates();V[t]=X;try{localStorage.setItem(n.STORAGE_KEY,JSON.stringify(V))}catch(M){console.error("[StatePersistencePlugin] Failed to save to localStorage:",M)}n.reactiveState.containerStates[t]=X,n.containers=n.containers.filter(M=>M.containerId!==t),n.addToClosedQueue(t)}static saveAllContainers(){d.batch(()=>{const e=n.getAllStates();n.containers.filter(({isDemo:t})=>t).forEach(({manager:t,containerId:i})=>{var k;const s=t.getState(),a=t.getMode(),o=t.getContainer(),c=t.getDirection(),g=o.dataset.maximized==="true",m=o.dataset.containerType||"unknown",w=o.dataset.title,y=o.dataset.color,x=o.dataset.useSnapping==="true",C=(k=t.config)==null?void 0:k.resize,E=o.parentElement,z=E&&E!==document.body?E.id||`parent-${i}`:void 0;e[i]={...s,mode:a,draggingDirection:c,isMaximized:g,containerType:m,title:w,color:y,useSnapping:x,isClosed:!1,parentElementId:z,closedTimestamp:0,resize:C,isDemoContainer:!0}}),n.reactiveState.containerStates=e,localStorage.setItem(n.STORAGE_KEY,JSON.stringify(e)),n.reactiveState.lastSaved=Date.now()})}static popLastClosedContainer(){try{const e=n.closedQueue;if(e.length===0)return null;const t=e.pop();return n.saveClosedQueueToStorage(),t}catch(e){return console.error("[StatePersistencePlugin] Failed to pop last closed container:",e),null}}static hasClosedContainers(){return n.closedQueue.length>0}static getContainerState(e){try{const t=n.containerStates[e];if(t)return t;const s=n.getAllStates()[e];return s?(n.reactiveState.containerStates[e]=s,s):null}catch(t){return console.error("[StatePersistencePlugin] Failed to get container state:",t),null}}static getAllContainerStates(){return n.getAllStates()}static hasContainerState(e){return n.getContainerState(e)!==null}static updateContainerState(e,t){try{const i=n.getAllStates(),s=i[e];if(s){const a={...s,...t};i[e]=a,localStorage.setItem(n.STORAGE_KEY,JSON.stringify(i)),n.reactiveState.containerStates[e]=a}else{console.warn(`[StatePersistencePlugin] No state found for container ${e}, creating new state`);const a={x:0,y:0,width:300,height:200,mode:"smooth",draggingDirection:"all",isMaximized:!1,containerType:"unknown",isClosed:!1,isDemoContainer:n.isDemoContainer(e),...t};i[e]=a,localStorage.setItem(n.STORAGE_KEY,JSON.stringify(i)),n.reactiveState.containerStates[e]=a}}catch(i){console.error("[StatePersistencePlugin] Failed to update container state:",i)}}static clearStorage(){d.batch(()=>{n.reactiveState.containerStates={},n.closedQueue.length=0,n.demoContainers.length=0,n.reactiveState.isSaving=!1,n.reactiveState.lastSaved=null,n.reactiveState.pendingChanges=!1}),localStorage.removeItem(n.STORAGE_KEY),localStorage.removeItem(n.CLOSED_QUEUE_KEY),localStorage.removeItem(n.DEMO_CONTAINERS_KEY),n.containers=[]}static initializeReactiveState(){try{const e=n.getAllStates(),t=n.getClosedQueue(),i=n.getDemoContainers();d.batch(()=>{n.reactiveState.containerStates=e,n.closedQueue.length=0,n.closedQueue.push(...t),n.demoContainers.length=0,n.demoContainers.push(...i)})}catch(e){console.error("[StatePersistencePlugin] Failed to initialize reactive state:",e)}}static getMetrics(){return{totalContainers:Object.keys(n.containerStates).length,demoContainers:n.demoContainers.length,closedContainers:n.closedQueue.length,lastSaved:n.reactiveState.lastSaved,isSaving:n.reactiveState.isSaving}}static debugStorage(){console.log("[StatePersistencePlugin] === START DEBUG INFO ===");try{const e=localStorage.getItem(n.STORAGE_KEY);if(e){const s=JSON.parse(e);console.log(`[StatePersistencePlugin] Number of states: ${Object.keys(s).length}`),console.log("[StatePersistencePlugin] State keys:",Object.keys(s));for(const[a,o]of Object.entries(s))console.log(`[StatePersistencePlugin] State ${a}:`,{isDemoContainer:o.isDemoContainer,isClosed:o.isClosed,title:o.title})}const t=localStorage.getItem(n.CLOSED_QUEUE_KEY);console.log("[StatePersistencePlugin] Closed queue:",t?JSON.parse(t):[]);const i=localStorage.getItem(n.DEMO_CONTAINERS_KEY);console.log("[StatePersistencePlugin] Demo containers:",i?JSON.parse(i):[])}catch(e){console.error("[StatePersistencePlugin] Debug error:",e)}console.log("[StatePersistencePlugin] === END DEBUG INFO ===")}destroy(){this.autoSaveEffect&&(this.autoSaveEffect(),this.autoSaveEffect=void 0),this.containerId&&(n.containers=n.containers.filter(e=>e.containerId!==this.containerId))}};r(n,"_pluginId",Symbol("StatePersistencePlugin")),r(n,"STORAGE_KEY","containerManagerState"),r(n,"CLOSED_QUEUE_KEY","containerManagerClosedQueue"),r(n,"DEMO_CONTAINERS_KEY","containerManagerDemoContainers"),r(n,"reactiveState",d.reactive({isSaving:!1,lastSaved:null,pendingChanges:!1,containerStates:{},closedQueue:[],demoContainers:[]})),r(n,"isGlobalEventsInitialized",!1),r(n,"containers",[]);let T=n;T.initializeReactiveState();const L=class L{constructor(){r(this,"manager");r(this,"containerName","");r(this,"notificationSystem",null)}get pluginId(){return L._pluginId}install(e,t){this.manager=e,this.containerName=(t==null?void 0:t.containerName)||`Container-${Math.random().toString(36).substring(2,11)}`,this.notificationSystem=t==null?void 0:t.notificationSystem,this.bindEvents()}bindEvents(){this.manager&&(this.logResize=u.debounce(this.logResize.bind(this),250),this.logDrag=u.debounce(this.logDrag.bind(this),250),this.logViewportResize=u.debounce(this.logViewportResize.bind(this),250),this.logSnapStep=u.debounce(this.logSnapStep.bind(this),250),this.manager.on("modeChange",e=>{this.logModeChange(e.mode)}),this.manager.on("resize",e=>{this.logResize(e.state)}),this.manager.on("resizeEnd",e=>{this.logResize(e.state)}),this.manager.on("drag",e=>{this.logDrag(e.state)}),this.manager.on("dragEnd",e=>{this.logDrag(e.state)}),this.manager.on("viewportResize",e=>{this.logViewportResize(e.state)}),this.manager.onPluginEvent("snappingEnabledChanged",e=>{this.logSnappingEnabled(e.enabled)}),this.manager.onPluginEvent("snapStepChanged",e=>{this.logSnapStep(e.snapStep)}),this.manager.onPluginEvent("directionChanged",e=>{this.logDirectionChange(e.direction)}))}logResize(e){const t=`Resized to ${Math.round(e.width)}×${Math.round(e.height)}`;this.showNotification(t,"info")}logDrag(e){const t=`Moved to (${Math.round(e.x)}, ${Math.round(e.y)})`;this.showNotification(t,"info")}logModeChange(e){const t=`Mode changed to ${e}`;this.showNotification(t,"warning")}logViewportResize(e){const t=`Adjusted position to (${Math.round(e.x)}, ${Math.round(e.y)}) due to window resize`;this.showNotification(t,"info")}logSnappingEnabled(e){const t=`Snapping ${e?"enabled":"disabled"}`;this.showNotification(t,e?"success":"warning")}logSnapStep(e){const t=`Snap step changed to ${e}px`;this.showNotification(t,"info")}logDirectionChange(e){const t=`Drag direction: ${e}`;this.showNotification(t,"info")}showNotification(e,t){if(this.notificationSystem){const i=`${this.containerName}: ${e}`;this.notificationSystem.show(i,t)}}};r(L,"_pluginId",Symbol("LoggingPlugin"));let Y=L;const he=Object.freeze(Object.defineProperty({__proto__:null,default:`<div class="media-content">
8
+ `}removeToast(t){t.classList.add("hide"),t.timeoutId&&clearTimeout(t.timeoutId),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t)},300)}clear(){for(;this.container.firstChild;)this.container.removeChild(this.container.firstChild)}}new F;class J{static createContainerElement(t,e,i,s,r){const o=document.createElement("div");return o.className="container advanced-container new",o.style.position="absolute",o.style.width=`${t}px`,o.style.height=`${e}px`,i!==void 0&&(o.style.left=`${i}px`),s!==void 0&&(o.style.top=`${s}px`),r&&(o.style.borderColor=r),o}}class Z{constructor(t){a(this,"templateLoader");this.templateLoader=t}async createContent(t,e){try{const i=e.classList.contains("container-content");let s;if(i?s=e:(s=e.querySelector(".container-content"),s||(s=document.createElement("div"),s.className="container-content",e.appendChild(s))),s.innerHTML="",typeof t=="string")s.innerHTML=t;else if(t instanceof HTMLElement)s.appendChild(t);else if(t.template)try{s.innerHTML=await this.templateLoader.loadTemplate(t.template)}catch(r){console.error(`[ContentCreator] Failed to load template: ${t.template}`,r),s.innerHTML=`<div class="template-error">Failed to load template: ${t.template}</div>`}return s}catch(i){throw console.error("[ContentCreator] Error creating content:",i),i}}setTemplateLoader(t){this.templateLoader=t}}class _{constructor(){a(this,"globalStatsElement",null)}initialize(t){this.globalStatsElement=t}showContainerStats(t){this.globalStatsElement&&this.updateStatsPanel(this.generateContainerStatsHTML(t))}showGlobalStats(t){this.globalStatsElement&&this.updateStatsPanel(this.generateGlobalStatsHTML(t))}generateContainerStatsHTML(t){const e=t.hasSnapping&&t.step!==void 0?`<div class="stat-item">
9
+ <span class="stat-label">Step:</span>
10
+ <span class="stat-value">${t.step}</span>
11
+ </div>`:"";return`
12
+ <h4>Block Stats</h4>
13
+ <div class="stat-item">
14
+ <span class="stat-label">Active Block:</span>
15
+ <span class="stat-value">${t.activeBlock}</span>
16
+ </div>
17
+ <div class="stat-item">
18
+ <span class="stat-label">Lock:</span>
19
+ <span class="stat-value">${t.lock}</span>
20
+ </div>
21
+ <div class="stat-item">
22
+ <span class="stat-label">Direction:</span>
23
+ <span class="stat-value">${t.direction}</span>
24
+ </div>
25
+ ${e}`}generateGlobalStatsHTML(t){return`
26
+ <h4>Global Stats</h4>
27
+ <div class="stat-item">
28
+ <span class="stat-label">Containers:</span>
29
+ <span class="stat-value">${t.containerCount}</span>
30
+ </div>
31
+ <div class="stat-item">
32
+ <span class="stat-label">Content Types:</span>
33
+ <span class="stat-value">${t.contentTypes}</span>
34
+ </div>
35
+ <div class="stat-item">
36
+ <span class="stat-label">Pinned Mode:</span>
37
+ <span class="stat-value">${t.pinnedMode}</span>
38
+ </div>
39
+ <div class="stat-item">
40
+ <span class="stat-label">With Snapping:</span>
41
+ <span class="stat-value">${t.snappingCount}</span>
42
+ </div>`}updateStatsPanel(t){this.globalStatsElement&&(this.globalStatsElement.innerHTML=t)}}var tt=Object.defineProperty,et=(h,t,e)=>t in h?tt(h,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[t]=e,f=(h,t,e)=>et(h,typeof t!="symbol"?t+"":t,e);class P{constructor(){f(this,"templates",new Map),f(this,"lastUpdated",new Map)}register(t){if(!t.name.trim())throw new Error("Template name cannot be empty");this.templates.set(t.name,t),this.lastUpdated.set(t.name,Date.now())}async registerBulk(t){for(const[e,i]of Object.entries(t))this.register({name:e,source:i})}get(t){return this.templates.get(t)}has(t){return this.templates.has(t)}remove(t){this.templates.delete(t),this.lastUpdated.delete(t)}list(){return Array.from(this.templates.keys())}clear(){this.templates.clear(),this.lastUpdated.clear()}getMetadata(t){var e;return(e=this.templates.get(t))==null?void 0:e.metadata}}class it{constructor(t=36e5){f(this,"cache",new Map),f(this,"ttl"),this.ttl=t}set(t,e){this.cache.set(t,{content:e,timestamp:Date.now()})}get(t){const e=this.cache.get(t);return e?this.ttl<=0||Date.now()-e.timestamp>this.ttl?(this.cache.delete(t),null):e.content:null}has(t){return this.get(t)!==null}clear(){this.cache.clear()}size(){return this.cache.size}}class O{constructor(t,e={}){f(this,"cache"),f(this,"config"),f(this,"metrics"),f(this,"retryQueue",new Map),f(this,"registry"),this.registry=t??new P,this.cache=new it(e==null?void 0:e.cacheTTL),this.config=this.normalizeConfig(e),this.metrics={totalLoads:0,totalHits:0,totalMisses:0,totalErrors:0,averageLoadTime:0,cacheHitRate:0}}normalizeConfig(t={}){var i;const e=t||{};return{environment:e.environment==="auto"?typeof process<"u"&&((i=process.env)==null?void 0:i.NODE_ENV)==="production"?"production":"development":e.environment??"development",cache:e.cache??!0,cacheTTL:e.cacheTTL??36e5,enableMetrics:e.enableMetrics??!0,onError:e.onError??(()=>{}),onWarn:e.onWarn??(()=>{}),fallbackTemplate:e.fallbackTemplate??'<div class="template-error">Template load failed</div>'}}async loadTemplate(t,e=2){const i=performance.now(),s=this.retryQueue.get(t)??0;if(this.metrics.totalLoads++,this.config.cache){const o=this.cache.get(t);if(o)return this.metrics.totalHits++,this.updateCacheHitRate(),o}this.metrics.totalMisses++;const r=this.registry.get(t);if(!r){const o=this.createError(`Template "${t}" not found. Available: ${this.registry.list().join(", ")}`,t,s);return this.metrics.totalErrors++,this.config.onError(o),this.config.fallbackTemplate}try{let o=typeof r.source=="function"?await r.source():r.source;if(typeof o!="string"){const c=this.createError("Template source must return a string, got "+typeof o,t,s);return this.metrics.totalErrors++,this.config.onError(c),this.config.fallbackTemplate}return this.config.cache&&this.cache.set(t,o),this.retryQueue.delete(t),this.recordLoadTime(i),o}catch(o){const c=o instanceof Error?o:new Error(String(o));if(s<e)return this.retryQueue.set(t,s+1),this.config.onWarn(`Retrying template "${t}" (attempt ${s+1}/${e})`),await new Promise(m=>setTimeout(m,100*Math.pow(2,s))),this.loadTemplate(t,e);const g=this.createError(`Failed to load template "${t}": ${c.message}`,t,s);return this.metrics.totalErrors++,this.config.onError(g),this.retryQueue.delete(t),this.config.fallbackTemplate}}async loadTemplates(t){const e={};return await Promise.all(t.map(async i=>{e[i]=await this.loadTemplate(i)})),e}getMetrics(){return{...this.metrics}}clearCache(){this.cache.clear()}resetMetrics(){this.metrics={totalLoads:0,totalHits:0,totalMisses:0,totalErrors:0,averageLoadTime:0,cacheHitRate:0}}has(t){return this.registry.has(t)}list(){return this.registry.list()}info(t){return this.registry.get(t)}createError(t,e,i){return Object.assign(new Error(t),{name:"TemplateLoadError",templateName:e,timestamp:new Date,retryCount:i})}recordLoadTime(t){if(this.config.enableMetrics){const e=performance.now()-t,i=this.metrics.averageLoadTime*(this.metrics.totalLoads-1)+e;this.metrics.averageLoadTime=i/this.metrics.totalLoads}}updateCacheHitRate(){this.config.enableMetrics&&(this.metrics.cacheHitRate=this.metrics.totalHits/this.metrics.totalLoads)}}let v;async function st(h=[]){const t=new P;let e={};try{e=Object.assign({"../demo/templates/media.html":()=>Promise.resolve().then(()=>dt).then(s=>s.default),"../demo/templates/stats.html":()=>Promise.resolve().then(()=>lt).then(s=>s.default),"../demo/templates/tasks.html":()=>Promise.resolve().then(()=>gt).then(s=>s.default)});const i={};Object.entries(e).forEach(([s,r])=>{var c;const o=(c=s.split("/").pop())==null?void 0:c.replace(/\.html$/,"");o&&(i[o]=async()=>typeof r=="function"?await r():String(r))}),await t.registerBulk(i)}catch(i){console.error("[TemplateLoader] Failed to load templates:",i),h.forEach(({name:s,source:r})=>{t.register({name:s,source:r})})}return new O(t,{environment:"development",cache:!0,cacheTTL:36e5,enableMetrics:!0,fallbackTemplate:'<div class="template-error">Template not found</div>',onError:i=>console.error(`[TemplateLoader Error] ${i.templateName}:`,i.message),onWarn:i=>console.warn(`[TemplateLoader] ${i}`)})}function nt(){const h=new P;return new O(h,{environment:"production",cache:!0,cacheTTL:36e5,enableMetrics:!1,onWarn:t=>console.warn(`[TemplateLoader] ${t}`),onError:t=>{console.warn(`Template load failed: ${t.templateName}`)}})}async function at(){return v||(typeof process<"u"&&process.env&&process.env.NODE_ENV==="development"?v=await st():(v=nt(),v.registry.register({name:"media",source:async()=>(await fetch("./templates/media.html")).text(),metadata:{version:"1.0",description:"Media card",cached:!0}}),v.registry.register({name:"userProfile",source:'<div class="user-profile"><h2>Profile</h2></div>',metadata:{version:"1.0",description:"User profile card",cached:!0}})),v)}function rt(){if(!v)throw new Error("Template system not initialized. Call initializeTemplateSystem() first.");return v}function ot(h,[t,e]){return e?{...h,[t]:e}:h}class Q{constructor(t){a(this,"source","cursor");a(this,"element",null);a(this,"top",!1);a(this,"right",!1);a(this,"bottom",!1);a(this,"left",!1);a(this,"edge",null);Object.assign(this,t)}}class W{constructor(){a(this,"listeners",{})}on(t,e){return this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),()=>{var i;(i=this.off)==null||i.call(this,t,e)}}emit(t,e){var i;(i=this.listeners[t])==null||i.forEach(s=>{try{s(e)}catch(r){console.error(`Error in event listener for ${String(t)}:`,r)}})}off(t,e){var i;(i=this.listeners[t])==null||i.delete(e)}destroy(){this.listeners={}}}class ct{constructor(t=50,e,i=null){a(this,"root");a(this,"edgeThreshold");a(this,"targets",new Set);a(this,"currentEdges",new Map);a(this,"rafId",null);a(this,"isActive",!1);a(this,"callbacks",new Set);a(this,"currentMousePos",{x:0,y:0});a(this,"currentCursorEdge",{top:!1,right:!1,bottom:!1,left:!1,edge:null});this.edgeThreshold=t,this.targets=e instanceof Set?e:new Set(e),this.root=i,e&&e.forEach(s=>this.targets.add(s)),this.checkBoundaries=this.checkBoundaries.bind(this)}start(){this.isActive||(this.isActive=!0,this.setupMouseTracking(),this.checkBoundaries())}stop(){this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.isActive=!1}addTarget(t){this.targets.add(t)}removeTarget(t){this.targets.delete(t),this.currentEdges.delete(t)}onChange(t){return this.callbacks.add(t),()=>{this.callbacks.delete(t)}}getCursorEdgeInfo(){return{...this.currentCursorEdge}}setEdgeThreshold(t){if(t<0)throw new Error("Edge threshold must be non-negative");this.edgeThreshold=t}setupMouseTracking(){document.addEventListener("mousemove",t=>{this.currentMousePos={x:t.clientX,y:t.clientY}})}getViewportSize(){return this.root?{width:this.root.clientWidth,height:this.root.clientHeight}:{width:window.innerWidth,height:window.innerHeight}}getRelativeRect(t){const e=t.getBoundingClientRect();if(!this.root)return e;const i=this.root.getBoundingClientRect();return{x:e.left-i.left,y:e.top-i.top,top:e.top-i.top,bottom:e.bottom-i.top,left:e.left-i.left,right:e.right-i.left,height:e.height,width:e.width,toJSON:()=>{}}}getCursorPosition(){if(!this.root)return this.currentMousePos;const t=this.root.getBoundingClientRect();return{x:this.currentMousePos.x-t.left,y:this.currentMousePos.y-t.top}}checkBoundaries(){this.targets.forEach(e=>{const i=this.checkElementBoundaries(e),s=this.currentEdges.get(e);(!s||this.hasEdgeChanged(s,i))&&(this.currentEdges.set(e,i),this.notifyCallbacks(new Q({...i,source:"element",element:e})))});const t=this.checkCursorBoundaries();this.hasEdgeChanged(this.currentCursorEdge,t)&&(this.currentCursorEdge=t,this.notifyCallbacks(new Q({...t,source:"cursor",element:null}))),this.isActive&&(this.rafId=requestAnimationFrame(this.checkBoundaries))}getCursorBoundingClientRect(){const{x:t,y:e}=this.getCursorPosition();return{x:t,y:e,top:e,bottom:e,left:t,right:t,width:0,height:0,toJSON:()=>{}}}checkElementBoundaries(t){const{width:e,height:i}=this.getViewportSize(),s=this.getRelativeRect(t),r={top:s.top<this.edgeThreshold,right:s.right>e-this.edgeThreshold,bottom:s.bottom>i-this.edgeThreshold,left:s.left<this.edgeThreshold,edge:null};return this.determineEdge(r,s,e,i),r}checkCursorBoundaries(){const t=this.getCursorBoundingClientRect(),e=window.innerWidth,i=window.innerHeight,s={top:t.top<this.edgeThreshold,right:t.right>e-this.edgeThreshold,bottom:t.bottom>i-this.edgeThreshold,left:t.left<this.edgeThreshold,edge:null};return this.determineEdge(s,t,e,i),s}hasEdgeChanged(t,e){return t.top!==e.top||t.right!==e.right||t.bottom!==e.bottom||t.left!==e.left}determineEdge(t,e,i,s){const r=[];if(t.top&&r.push("top"),t.right&&r.push("right"),t.bottom&&r.push("bottom"),t.left&&r.push("left"),r.length===0)t.edge=null;else if(r.length===1)t.edge=r[0];else{const o={top:e.top,right:i-e.right,bottom:s-e.bottom,left:e.left};t.edge=r.reduce((c,g)=>o[g]<o[c]?g:c)}}notifyCallbacks(t){this.callbacks.forEach(e=>{try{e(t)}catch(i){console.error("Error in boundary change callback:",i)}})}destroy(){this.stop(),this.callbacks.clear()}}const b=class b extends ct{constructor(e,i){super(e,i);a(this,"lastEdge",{});a(this,"emitter",null);this.onChange(this.onBoundaryChange.bind(this)),this.start()}static init(e,i){return b.instance??(b.instance=new b(e,i))}changed({edge:e,source:i,element:s}){return e!==this.lastEdge.edge||i!==this.lastEdge.source||s!==this.lastEdge.element}onBoundaryChange({edge:e,source:i,element:s}){this.changed({edge:e,source:i,element:s})&&(this.lastEdge=Object.entries({edge:e,source:i,element:s}).reduce(ot,{}),s?e?this.onEdgeEnter({edge:e,source:i,element:s}):this.onEdgeLeave(this.lastEdge):e?this.onCursorEnter({edge:e,source:i}):this.onCursorLeave(this.lastEdge))}onEdgeEnter(e){var i;(i=this.emitter)==null||i.emit("edge:enter",e)}onEdgeLeave(e){var i;(i=this.emitter)==null||i.emit("edge:leave",e)}onCursorEnter(e){var i;(i=this.emitter)==null||i.emit("cursor:enter",e)}onCursorLeave(e){var i;(i=this.emitter)==null||i.emit("cursor:leave",e)}setEmitter(e){this.emitter=e}on(e,i){var s;(s=this.emitter)==null||s.on(e,i)}getCurrentEdge(){return this.lastEdge}};a(b,"instance");let H=b;function ht(h={},t=[]){const e=H.init(h.edgeThreshold,t);return h.emitter&&e.setEmitter(h.emitter instanceof W?h.emitter:new W),e}const p=class p{constructor(){a(this,"draggable",[])}zIndex(t){return`${p.highestZIndex+this.draggable.findIndex(e=>e===t)}`}push(t){return this.draggable=[...new Set([...this.draggable,t])],this}remove(t){return this.draggable=this.draggable.filter(e=>e!==t),this}sort(t){return this.draggable.sort((e,i)=>e===t?1:i===t?-1:0),this}};a(p,"inatance"),a(p,"highestZIndex",1e3),a(p,"init",()=>p.inatance??(p.inatance=new p));let $=p;function j(){return{width:window.innerWidth||document.documentElement.clientWidth,height:window.innerHeight||document.documentElement.clientHeight}}function X(){return $.init()}const S=class S{constructor(t,e={}){a(this,"dragStream");a(this,"resizeStream");a(this,"stateChangeStream");a(this,"eventEmitter");a(this,"pluginEventEmitter");a(this,"config");a(this,"container");a(this,"dragHandle");a(this,"resizeHandles",new Map);a(this,"installedPlugins",new Set);a(this,"reactiveEffects",[]);a(this,"isDragging",!1);a(this,"isResizing",!1);a(this,"resizeDirection",null);a(this,"startX",0);a(this,"startY",0);a(this,"startState");a(this,"resizeObserver",null);a(this,"parentResizeObserver",null);a(this,"zIndexState");a(this,"reactiveState",l.reactive({x:0,y:0,width:0,height:0,mode:"smooth",draggingDirection:"all"}));a(this,"constrainedState",l.computed(()=>{var s;const t=this.reactiveState;if(!this.config)return{...t};let e={...t};const{boundaries:i}=this.config;if(e.width=u.clamp(t.width,i.minWidth||S.MINWIDTH,i.maxWidth||1/0),e.height=u.clamp(t.height,i.minHeight||S.MINHEIGHT,i.maxHeight||1/0),this.shouldConstrainToViewport()){const r=j();e.x=u.clamp(t.x,0,r.width-e.width),e.y=u.clamp(t.y,0,r.height-e.height)}return(s=this.config)!=null&&s.constrainToParent&&(e=this.constrainToParent(e)),e}));a(this,"domUpdateEffect",l.effect(()=>{var e;const t=this.constrainedState.value;this.container&&(this.container.style.left=`${t.x}px`,this.container.style.top=`${t.y}px`,this.container.style.width=`${t.width}px`,this.container.style.height=`${t.height}px`,(e=this.eventEmitter)==null||e.emit("stateChange",{type:"stateChange",state:{...t},mode:this.reactiveState.mode,element:this.container}))}));this.config=u.deepMerge({_uid:"",mode:"smooth",constrainToViewport:!1,draggingDirection:"all",constrainToParent:!1,boundaries:{minWidth:S.MINWIDTH,minHeight:S.MINHEIGHT},autoAdjust:{enabled:!1,width:!1,height:!1},resize:{enabled:!0,directions:["se"]}},e),this.container=t,this.zIndexState=X();const i=this.getCurrentState();this.reactiveState.x=i.x,this.reactiveState.y=i.y,this.reactiveState.width=i.width,this.reactiveState.height=i.height,this.reactiveState.mode=this.config.mode,this.reactiveState.draggingDirection=this.config.draggingDirection,this.eventEmitter=new l({enableMetrics:!0}),this.pluginEventEmitter=new l({enableMetrics:!0}),this.stateChangeStream=this.eventEmitter.stream("stateChange"),this.dragStream=this.eventEmitter.stream("drag"),this.resizeStream=this.eventEmitter.stream("resize"),this.startState=this.getState(),this.setupEventMiddleware(),this.initializeHandles(),this.bindEvents(),this.setupResizeObservers(),this.setupReactiveMonitoring()}setupResizeObservers(){var t;this.shouldConstrainToViewport()&&this.setupViewportResizeObserver(),(t=this.config.autoAdjust)!=null&&t.enabled&&this.setupParentResizeObserver()}shouldConstrainToViewport(){return!this.config.constrainToParent||this.config.constrainToViewport}setupViewportResizeObserver(){let t=null;this.resizeObserver=new ResizeObserver(()=>{t&&cancelAnimationFrame(t),t=requestAnimationFrame(()=>{this.handleViewportResize()})}),this.resizeObserver.observe(document.body)}handleViewportResize(){if(!this.shouldConstrainToViewport())return;const t=j(),i={...this.getState()};let s=!1;i.x+i.width>t.width&&(i.x=Math.max(0,t.width-i.width),s=!0),i.y+i.height>t.height&&(i.y=Math.max(0,t.height-i.height),s=!0),i.x<0&&(i.x=0,s=!0),i.y<0&&(i.y=0,s=!0),s&&(this.setState(i),this.eventEmitter.emit("viewportResize",{type:"viewportResize",state:this.getState(),mode:this.reactiveState.mode,element:this.container}))}setupParentResizeObserver(){const t=this.container.parentElement;t&&(this.parentResizeObserver=new ResizeObserver(e=>{for(const i of e)this.handleParentResize(i)}),this.parentResizeObserver.observe(t))}handleParentResize(t){const{autoAdjust:e}=this.config;if(!(e!=null&&e.enabled))return;const i=t.contentRect,r={...this.getState()};let o=!1;if(e.width){const c=this.getMaxWidthConstraint(),g=Math.min(i.width,c);Math.abs(r.width-g)>1&&(r.width=g,o=!0)}if(e.height){const c=this.getMaxHeightConstraint(),g=Math.min(i.height,c);Math.abs(r.height-g)>1&&(r.height=g,o=!0)}o&&(this.setState(r),this.eventEmitter.emit("autoAdjust",{type:"autoAdjust",state:this.getState(),mode:this.reactiveState.mode,element:this.container}))}initializeHandles(){var t;this.initializeDragHandle(),(t=this.config.resize)!=null&&t.enabled&&this.initializeResizeHandles()}initializeDragHandle(){this.dragHandle=this.container.querySelector("[data-drag-handle]"),this.dragHandle?this.dragHandle.setAttribute("oncontextmenu","return false"):(this.dragHandle=document.createElement("div"),this.dragHandle.className="drag-handle",this.dragHandle.setAttribute("data-drag-handle","true"),this.dragHandle.setAttribute("oncontextmenu","return false"),this.container.prepend(this.dragHandle))}initializeResizeHandles(){var e;(((e=this.config.resize)==null?void 0:e.directions)||["se"]).forEach(i=>{const s=this.createResizeHandle(i);this.resizeHandles.set(i,s),this.container.appendChild(s)})}createResizeHandle(t){const e=document.createElement("div");return e.className=`resize-handle resize-${t}`,e.setAttribute("data-resize-handle",t),e.setAttribute("data-resize-direction",t),e.addEventListener("contextmenu",this.onContextMenu),this.applyResizeHandleStyles(e,t),e}applyResizeHandleStyles(t,e){const i={n:"ns-resize",s:"ns-resize",e:"ew-resize",w:"ew-resize",ne:"nesw-resize",nw:"nwse-resize",se:"nwse-resize",sw:"nesw-resize"};t.style.position="absolute",t.style.cursor=i[e],this.positionResizeHandle(t,e)}positionResizeHandle(t,e){switch(e){case"n":t.style.top="0",t.style.left="0",t.style.right="0",t.style.height="12px";break;case"s":t.style.bottom="0",t.style.left="0",t.style.right="0",t.style.height="12px";break;case"e":t.style.right="0",t.style.top="0",t.style.bottom="0",t.style.width="12px";break;case"w":t.style.left="0",t.style.top="0",t.style.bottom="0",t.style.width="12px";break;case"ne":t.style.top="0",t.style.right="0",t.style.width="12px",t.style.height="12px";break;case"nw":t.style.top="0",t.style.left="0",t.style.width="12px",t.style.height="12px";break;case"se":t.style.bottom="0",t.style.right="0",t.style.width="12px",t.style.height="12px";break;case"sw":t.style.bottom="0",t.style.left="0",t.style.width="12px",t.style.height="12px";break}}bindEvents(){var t;this.onDragStart=this.onDragStart.bind(this),this.onDragMove=this.onDragMove.bind(this),this.onDragEnd=this.onDragEnd.bind(this),this.onResizeStart=this.onResizeStart.bind(this),this.onResizeMove=this.onResizeMove.bind(this),this.onResizeEnd=this.onResizeEnd.bind(this),this.onContextMenu=this.onContextMenu.bind(this),this.hasPluginByName("SnappingPlugin")||(this.dragHandle.addEventListener("mousedown",this.onDragStart),this.dragHandle.addEventListener("touchstart",this.onDragStart)),(t=this.config.resize)!=null&&t.enabled&&this.resizeHandles.forEach((e,i)=>{e.addEventListener("mousedown",s=>this.onResizeStart(s,i)),e.addEventListener("touchstart",s=>this.onResizeStart(s,i))}),this.dragHandle.addEventListener("contextmenu",this.onContextMenu)}applyMovementMode(t,e){const i={...this.startState};return this.reactiveState.mode==="smooth"&&(i.x=this.startState.x+t,i.y=this.startState.y+e),i}calculateResizeState(t,e,i){const s={...this.startState};switch(i){case"e":s.width=this.startState.width+t;break;case"w":s.width=this.startState.width-t,s.x=this.startState.x+t;break;case"n":s.height=this.startState.height-e,s.y=this.startState.y+e;break;case"s":s.height=this.startState.height+e;break;case"ne":s.width=this.startState.width+t,s.height=this.startState.height-e,s.y=this.startState.y+e;break;case"nw":s.width=this.startState.width-t,s.height=this.startState.height-e,s.x=this.startState.x+t,s.y=this.startState.y+e;break;case"se":s.width=this.startState.width+t,s.height=this.startState.height+e;break;case"sw":s.width=this.startState.width-t,s.height=this.startState.height+e,s.x=this.startState.x+t;break}return s}constrainToParent(t){const e=this.container.parentElement;if(!e)return t;const i=e.getBoundingClientRect();if(i.width===0||i.height===0)return t;const s=Math.max(0,i.width-t.width),r=Math.max(0,i.height-t.height),o=i.width-t.x,c=i.height-t.y;return{x:u.clamp(t.x,0,s),y:u.clamp(t.y,0,r),width:u.clamp(t.width,0,o),height:u.clamp(t.height,0,c)}}getMaxWidthConstraint(){const{boundaries:t}=this.config;let e=t.maxWidth||1/0;if(this.config.constrainToParent&&this.container.parentElement){const i=this.container.parentElement.getBoundingClientRect().width;e=Math.min(e,i)}return e}getMaxHeightConstraint(){const{boundaries:t}=this.config;let e=t.maxHeight||1/0;if(this.config.constrainToParent&&this.container.parentElement){const i=this.container.parentElement.getBoundingClientRect().height;e=Math.min(e,i)}return e}onContextMenu(t){t.preventDefault(),t.stopPropagation()}hasPluginByName(t){return Array.from(this.installedPlugins).some(e=>e.constructor.name===t)}getCurrentState(){const t=this.container.getBoundingClientRect(),e=window.getComputedStyle(this.container),i=parseFloat(e.width)||t.width,s=parseFloat(e.height)||t.height;return{x:t.left,y:t.top,width:i,height:s}}setupEventMiddleware(){this.eventEmitter.use("*",(t,e)=>(typeof window<"u"&&window.DEBUG_CONTAINER_MANAGER&&console.log(`[ContainerManager] ${e}:`,t),t)),this.eventEmitter.use("dragStart",(t,e)=>{if(this.reactiveState.mode==="pinned")throw new Error("Cannot drag in pinned mode");return t}),this.eventEmitter.use("drag",(t,e)=>t)}setupReactiveMonitoring(){const t=l.effect(()=>{const{state:i}=this.stateChangeStream});this.reactiveEffects.push(t);const e=l.effect(()=>{const i=this.eventEmitter.getMetrics();i.state.errorCount>10&&console.warn("[ContainerManager] High error count in event system:",i.state.errorCount)});this.reactiveEffects.push(e)}on(t,e){this.eventEmitter.on(t,e)}off(t,e){this.eventEmitter.off(t,e)}waitFor(t,e){return this.eventEmitter.waitFor(t,e)}getStream(t){return this.eventEmitter.stream(t)}pipe(t,e,i){return this.eventEmitter.pipe(t,e,i)}getEventMetrics(){return this.eventEmitter.getMetrics()}emitPluginEvent(t,e){this.pluginEventEmitter.emit(t,e)}onPluginEvent(t,e){this.pluginEventEmitter.on(t,e)}offPluginEvent(t,e){this.pluginEventEmitter.off(t,e)}usePluginMiddleware(t,e){return this.pluginEventEmitter.use(t,e)}onDragStart(t){if(this.reactiveState.mode==="pinned")return;t.preventDefault(),this.bringToFront(),this.isDragging=!0;const e=t instanceof MouseEvent?t.clientX:t.touches[0].clientX,i=t instanceof MouseEvent?t.clientY:t.touches[0].clientY;this.startX=e,this.startY=i,this.startState=this.getState(),this.eventEmitter.emit("dragStart",{type:"drag",state:this.getState(),mode:this.reactiveState.mode,element:this.container}),document.addEventListener("mousemove",this.onDragMove),document.addEventListener("mouseup",this.onDragEnd),document.addEventListener("touchmove",this.onDragMove),document.addEventListener("touchend",this.onDragEnd)}onDragMove(t){if(!this.isDragging)return;const{clientX:e,clientY:i}=this.directionResolver(t instanceof MouseEvent?t.clientX:t.touches[0].clientX,t instanceof MouseEvent?t.clientY:t.touches[0].clientY),s=e-this.startX,r=i-this.startY,o=this.applyMovementMode(s,r);this.setState(o),this.eventEmitter.emit("drag",{type:"drag",state:this.getState(),mode:this.reactiveState.mode,element:this.container})}onDragEnd(){this.isDragging=!1,document.removeEventListener("mousemove",this.onDragMove),document.removeEventListener("mouseup",this.onDragEnd),document.removeEventListener("touchmove",this.onDragMove),document.removeEventListener("touchend",this.onDragEnd),this.eventEmitter.emit("dragEnd",{type:"drag",state:this.getState(),mode:this.reactiveState.mode,element:this.container})}onResizeStart(t,e){t.preventDefault(),t.stopPropagation(),this.bringToFront(),this.isResizing=!0,this.resizeDirection=e;const i=t instanceof MouseEvent?t.clientX:t.touches[0].clientX,s=t instanceof MouseEvent?t.clientY:t.touches[0].clientY;this.startX=i,this.startY=s,this.startState=this.getState(),document.addEventListener("mousemove",this.onResizeMove),document.addEventListener("mouseup",this.onResizeEnd),document.addEventListener("touchmove",this.onResizeMove),document.addEventListener("touchend",this.onResizeEnd),this.eventEmitter.emit("resizeStart",{type:"resize",state:this.getState(),mode:this.reactiveState.mode,element:this.container,direction:e})}onResizeMove(t){if(!this.isResizing||!this.resizeDirection)return;const e=t instanceof MouseEvent?t.clientX:t.touches[0].clientX,i=t instanceof MouseEvent?t.clientY:t.touches[0].clientY,s=e-this.startX,r=i-this.startY,o=this.calculateResizeState(s,r,this.resizeDirection);this.setState(o),this.eventEmitter.emit("resize",{type:"resize",state:this.getState(),mode:this.reactiveState.mode,direction:this.resizeDirection,element:this.container})}onResizeEnd(){this.isResizing=!1,this.resizeDirection=null,document.removeEventListener("mousemove",this.onResizeMove),document.removeEventListener("mouseup",this.onResizeEnd),document.removeEventListener("touchmove",this.onResizeMove),document.removeEventListener("touchend",this.onResizeEnd),this.eventEmitter.emit("resizeEnd",{type:"resize",state:this.getState(),mode:this.reactiveState.mode,element:this.container})}setDirection(t){this.reactiveState.draggingDirection=t,this.emitPluginEvent("directionChanged",{direction:t})}getDirection(){return this.reactiveState.draggingDirection}directionResolver(t,e){const i=this.reactiveState.draggingDirection,s=i==="vertical",r=i==="horizontal";return{clientX:s?this.startX:t,clientY:r?this.startY:e}}getMode(){return this.reactiveState.mode}setMode(t){this.reactiveState.mode=t,this.eventEmitter.emit("modeChange",{type:"modeChange",state:this.getState(),mode:this.reactiveState.mode,element:this.container})}setBoundaries(t){this.config.boundaries={...this.config.boundaries,...t}}getState(){return{x:this.reactiveState.x,y:this.reactiveState.y,width:this.reactiveState.width,height:this.reactiveState.height}}setState(t){t.height!==void 0&&(this.reactiveState.height=t.height),t.width!==void 0&&(this.reactiveState.width=t.width),t.x!==void 0&&(this.reactiveState.x=t.x),t.y!==void 0&&(this.reactiveState.y=t.y),this.applyStateToDOM()}applyStateToDOM(){const t=this.getState();this.container.style.left=`${t.x}px`,this.container.style.top=`${t.y}px`,this.container.style.width=`${t.width}px`,this.container.style.height=`${t.height}px`}bringToFront(){const{_uid:t}=this.config;this.container.style.zIndex=this.zIndexState.sort(t).zIndex(t)}getContainer(){return this.container}setAutoAdjust(t){var e;this.config.autoAdjust={...this.config.autoAdjust,...t},this.parentResizeObserver&&(this.parentResizeObserver.disconnect(),this.parentResizeObserver=null),(e=this.config.autoAdjust)!=null&&e.enabled&&this.setupParentResizeObserver()}setResizeConfig(t){var e;this.config.resize={...this.config.resize,...t},this.resizeHandles.forEach(i=>i.remove()),this.resizeHandles.clear(),(e=this.config.resize)!=null&&e.enabled&&(this.initializeResizeHandles(),this.bindEvents())}setConstrainToParent(t){this.config.constrainToParent=t,this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.shouldConstrainToViewport()&&this.setupViewportResizeObserver()}setConstrainToViewport(t){this.config.constrainToViewport=t,this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.shouldConstrainToViewport()&&this.setupViewportResizeObserver()}recalculateForParent(){if(!this.config.constrainToParent||!this.container.parentElement)return;const t=this.container.parentElement.getBoundingClientRect(),e=this.getState();if(t.width===0||t.height===0)return;const i=e.width,s=e.height,r=Math.min(i,t.width),o=Math.min(s,t.height),c=e.x,g=e.y,m=Math.min(c,t.width-r),w=Math.min(g,t.height-o);this.setState({x:m,y:w,width:r,height:o}),this.eventEmitter.emit("parentRecalculated",{type:"parentRecalculated",state:this.getState(),mode:this.reactiveState.mode,element:this.container})}use(t,e){if(this.installedPlugins.has(t))return this;try{t.install(this,e),this.installedPlugins.add(t)}catch(i){console.error("[ContainerManager] Failed to install plugin:",i)}return this}hasPlugin(t){return this.installedPlugins.has(t)}getInstalledPlugins(){return Array.from(this.installedPlugins)}destroy(){this.reactiveEffects.forEach(t=>t()),this.reactiveEffects=[],this.stateChangeStream.destroy(),this.dragStream.destroy(),this.resizeStream.destroy(),this.eventEmitter.destroy(),this.pluginEventEmitter.destroy(),this.domUpdateEffect(),this.dragHandle.removeEventListener("mousedown",this.onDragStart),this.dragHandle.removeEventListener("touchstart",this.onDragStart),this.dragHandle.removeEventListener("contextmenu",this.onContextMenu),this.resizeHandles.forEach((t,e)=>{t.removeEventListener("mousedown",i=>this.onResizeStart(i,e)),t.removeEventListener("touchstart",i=>this.onResizeStart(i,e))}),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.parentResizeObserver&&(this.parentResizeObserver.disconnect(),this.parentResizeObserver=null),this.installedPlugins.clear(),this.zIndexState.remove(this.config._uid)}};a(S,"MINWIDTH",200),a(S,"MINHEIGHT",45);let I=S;const D=class D{constructor(t={}){a(this,"reactiveState",l.reactive({snapStep:10,enabled:!0,isActive:!1,lastPosition:null}));a(this,"manager");a(this,"startState",null);a(this,"startX",0);a(this,"startY",0);this.reactiveState.snapStep=t.snapStep??10,this.reactiveState.enabled=t.enabled??!0,this.onDragMove=this.onDragMove.bind(this),this.onDragEnd=this.onDragEnd.bind(this)}get pluginId(){return D._pluginId}install(t,e){this.manager=t,e&&(this.reactiveState.snapStep=e.snapStep??this.reactiveState.snapStep,this.reactiveState.enabled=e.enabled??this.reactiveState.enabled),this.overrideDragMethods(),this.addPluginMethods()}overrideDragMethods(){if(!this.manager)return;const t=this.manager.getContainer().querySelector(".drag-handle");t&&(t.onmousedown=e=>{this.onDragStart(e)},t.ontouchstart=e=>{this.onDragStart(e)})}onDragStart(t){var s,r;if(!this.manager||this.manager.getMode()==="pinned")return;t.preventDefault(),(r=(s=this.manager).bringToFront)==null||r.call(s),this.reactiveState.isActive=!0;const e=t instanceof MouseEvent?t.clientX:t.touches[0].clientX,i=t instanceof MouseEvent?t.clientY:t.touches[0].clientY;this.startX=e,this.startY=i,this.startState=this.manager.getState(),this.reactiveState.lastPosition={x:this.startState.x,y:this.startState.y},document.addEventListener("mousemove",this.onDragMove),document.addEventListener("mouseup",this.onDragEnd),document.addEventListener("touchmove",this.onDragMove),document.addEventListener("touchend",this.onDragEnd),this.manager.emitPluginEvent("dragStart",{type:"drag",state:this.startState,mode:this.manager.getMode()})}onDragMove(t){if(!this.reactiveState.isActive||!this.manager||!this.startState)return;const{clientX:e,clientY:i}=this.manager.directionResolver(t instanceof MouseEvent?t.clientX:t.touches[0].clientX,t instanceof MouseEvent?t.clientY:t.touches[0].clientY);let s=e-this.startX,r=i-this.startY;if(this.reactiveState.enabled){const g=this.applySnapping(s,r);s=g.deltaX,r=g.deltaY}const o={x:this.startState.x+s,y:this.startState.y+r,width:this.startState.width,height:this.startState.height},c=this.manager.config;c!=null&&c.constrainToViewport&&this.constrainToViewport(o),this.manager.setState(o),this.reactiveState.lastPosition={x:o.x,y:o.y},this.manager.emitPluginEvent("drag",{type:"drag",state:o,mode:this.manager.getMode()})}onDragEnd(){this.manager&&(this.reactiveState.isActive=!1,this.reactiveState.lastPosition=null,this.startState=null,document.removeEventListener("mousemove",this.onDragMove),document.removeEventListener("mouseup",this.onDragEnd),document.removeEventListener("touchmove",this.onDragMove),document.removeEventListener("touchend",this.onDragEnd),this.manager.emitPluginEvent("dragEnd",{type:"drag",state:this.manager.getState(),mode:this.manager.getMode()}))}applySnapping(t,e){return{deltaX:this.snapToGrid(t,this.reactiveState.snapStep),deltaY:this.snapToGrid(e,this.reactiveState.snapStep)}}snapToGrid(t,e){return Math.round(t/e)*e}constrainToViewport(t){const e=window.innerWidth||document.documentElement.clientWidth,i=window.innerHeight||document.documentElement.clientHeight;t.x=Math.max(0,Math.min(t.x,e-t.width)),t.y=Math.max(0,Math.min(t.y,i-t.height))}addPluginMethods(){this.manager.setSnapStep=t=>{this.reactiveState.snapStep=t,this.manager.emitPluginEvent("snapStepChanged",{snapStep:t})},this.manager.setSnappingEnabled=t=>{this.reactiveState.enabled=t,this.manager.emitPluginEvent("snappingEnabledChanged",{enabled:t})},this.manager.getSnappingConfig=()=>({snapStep:this.reactiveState.snapStep,enabled:this.reactiveState.enabled})}destroy(){this.reactiveState.isActive=!1,this.reactiveState.lastPosition=null}};a(D,"_pluginId",Symbol("SnappingPlugin"));let A=D;const L=class L{constructor(t={}){a(this,"dockedContainers",new Map);a(this,"occupiedEdges",new Map);a(this,"tracker",ht({emitter:!0,edgeThreshold:20}));a(this,"manager");a(this,"edgeThreshold");this.edgeThreshold=t.edgeThreshold??30,this.occupiedEdges.set("top",null),this.occupiedEdges.set("bottom",null),this.occupiedEdges.set("left",null),this.occupiedEdges.set("right",null)}get pluginId(){return L._pluginId}install(t){this.manager=t,this.tracker.addTarget(this.manager.getContainer()),this.tracker.on("edge:enter",e=>{e.source==="element"&&e.element===this.manager.getContainer()&&this.handleEdgeEnter(e.edge)}),this.tracker.on("edge:leave",e=>{e.source==="element"&&e.element===this.manager.getContainer()&&this.handleEdgeLeave(e.edge)}),this.attachEventHandlers()}handleEdgeEnter(t){const e=this.manager.getContainer();this.isEdgeOccupied(t)?e.classList.add("edge-dock-hint",`edge-dock-hint-${t}`,"edge-dock-blocked"):e.classList.add("edge-dock-hint",`edge-dock-hint-${t}`)}handleEdgeLeave(t){this.manager.getContainer().classList.remove("edge-dock-hint",`edge-dock-hint-${t}`,"edge-dock-blocked")}isEdgeOccupied(t){return this.occupiedEdges.get(t)!==null}attachEventHandlers(){const t=this.manager.getContainer();t.addEventListener("mouseenter",this.onMouseEnter.bind(this)),t.addEventListener("mouseleave",this.onMouseLeave.bind(this)),this.manager.on("dragStart",e=>{this.onDragStart(e.element)}),this.manager.on("drag",e=>{this.onDrag(e.element)}),this.manager.on("dragEnd",e=>{this.onDragEnd(e.element)})}onMouseEnter(){const t=this.manager.getContainer();this.isContainerDocked(t)&&t.classList.add("edge-docked-visible")}onMouseLeave(){const t=this.manager.getContainer();this.isContainerDocked(t)&&t.classList.remove("edge-docked-visible")}onDragStart(t){t.classList.remove("edge-dock-hint","edge-dock-blocked","edge-docked-visible","edge-dock-hint-top","edge-dock-hint-bottom","edge-dock-hint-left","edge-dock-hint-right");const e=this.dockedContainers.get(t);e&&this.undockContainer(t,e)}onDrag(t){const e=t.getBoundingClientRect(),i=this.getClosestEdge(e);this.updateEdgeHints(t,i)}onDragEnd(t){const e=t.getBoundingClientRect(),i=this.getClosestEdge(e);t.classList.remove("edge-dock-hint","edge-dock-blocked","edge-dock-hint-top","edge-dock-hint-bottom","edge-dock-hint-left","edge-dock-hint-right"),i&&!this.isEdgeOccupied(i)&&this.dockContainer(t,i)}updateEdgeHints(t,e){t.classList.remove("edge-dock-hint","edge-dock-blocked","edge-dock-hint-top","edge-dock-hint-bottom","edge-dock-hint-left","edge-dock-hint-right"),e&&(this.isEdgeOccupied(e)?t.classList.add("edge-dock-hint",`edge-dock-hint-${e}`,"edge-dock-blocked"):t.classList.add("edge-dock-hint",`edge-dock-hint-${e}`))}getClosestEdge(t){const e=t.top,i=t.left,s=window.innerHeight-t.bottom,r=window.innerWidth-t.right,c=Object.entries({top:e,bottom:s,left:i,right:r}).filter(([g,m])=>m>=-this.edgeThreshold&&m<=this.edgeThreshold).sort((g,m)=>g[1]-m[1]);return c.length>0?c[0][0]:null}dockContainer(t,e){const i=window.getComputedStyle(t),s=t.getBoundingClientRect(),r={x:s.left,y:s.top};this.dockedContainers.set(t,{element:t,edge:e,screenPosition:r,originalPosition:{top:parseFloat(i.top)||s.top,left:parseFloat(i.left)||s.left,width:s.width,height:s.height,transform:i.transform,position:i.position}}),this.occupiedEdges.set(e,t),t.style.top="",t.style.bottom="",t.style.left="",t.style.right="",t.style.width="",t.style.height="",t.style.transform="",t.classList.add("edge-docked",`edge-docked-${e}`),this.applyEdgePositioning(t,e,r),t.setAttribute("data-docked","true"),t.setAttribute("data-docked-edge",e)}applyEdgePositioning(t,e,i){const s=t.getBoundingClientRect();switch(e){case"top":t.style.left=`${i.x}px`,t.style.width=`${s.width}px`;break;case"bottom":t.style.left=`${i.x}px`,t.style.width=`${s.width}px`;break;case"left":t.style.top=`${i.y}px`,t.style.height=`${s.height}px`;break;case"right":t.style.top=`${i.y}px`,t.style.height=`${s.height}px`;break}}undockContainer(t,e){this.dockedContainers.delete(t),this.occupiedEdges.set(e.edge,null),t.classList.remove("edge-docked","edge-docked-visible","edge-docked-top","edge-docked-bottom","edge-docked-left","edge-docked-right"),t.removeAttribute("data-docked"),t.removeAttribute("data-docked-edge"),t.style.top="",t.style.bottom="",t.style.left="",t.style.right="",t.style.width="",t.style.height="",t.style.transform="",t.style.position="",this.restoreOriginalPosition(t,e)}restoreOriginalPosition(t,e){this.manager.setState({x:e.screenPosition.x,y:e.screenPosition.y,width:e.originalPosition.width,height:e.originalPosition.height})}getDockedContainer(t){const e=this.occupiedEdges.get(t);return e&&this.dockedContainers.get(e)||null}isContainerDocked(t){return this.dockedContainers.has(t)}getContainerDockEdge(t){const e=this.dockedContainers.get(t);return e?e.edge:null}destroy(){const t=this.manager.getContainer();t.removeEventListener("mouseenter",this.onMouseEnter.bind(this)),t.removeEventListener("mouseleave",this.onMouseLeave.bind(this)),this.dockedContainers.forEach((e,i)=>{this.undockContainer(i,e)}),this.dockedContainers.clear(),this.occupiedEdges.forEach((e,i)=>{this.occupiedEdges.set(i,null)})}};a(L,"_pluginId",Symbol("EdgeDockingPlugin"));let N=L;const n=class n{constructor(){a(this,"manager");a(this,"containerId");a(this,"isDemoContainer",!1);a(this,"autoSaveEffect")}get pluginId(){return n._pluginId}static get containerStates(){return n.reactiveState.containerStates}static get closedQueue(){return n.reactiveState.closedQueue}static get demoContainers(){return n.reactiveState.demoContainers}install(t,e){if(this.manager=t,this.containerId=e==null?void 0:e.containerId,this.isDemoContainer=(e==null?void 0:e.isDemo)||!1,!this.containerId){console.warn("[StatePersistencePlugin] containerId is required for state persistence");return}n.containers.push({manager:t,containerId:this.containerId,isDemo:this.isDemoContainer}),this.isDemoContainer&&n.registerDemoContainer(this.containerId),n.isGlobalEventsInitialized||(n.initializeGlobalEvents(),n.isGlobalEventsInitialized=!0),this.isDemoContainer&&this.setupAutoSaveEffect(),this.bindContainerEvents()}setupAutoSaveEffect(){if(!this.manager||!this.containerId)return;const t=u.debounce(()=>{this.isDemoContainer&&this.saveState()},300);this.autoSaveEffect=l.effect(()=>{this.manager.getState(),this.manager.getMode(),t()})}bindContainerEvents(){this.manager&&(this.manager.on("dragStart",()=>{}),this.manager.on("dragEnd",()=>{this.isDemoContainer&&this.saveState()}),this.manager.on("resizeEnd",()=>{this.isDemoContainer&&this.saveState()}),this.manager.onPluginEvent("maximizeChanged",()=>{this.isDemoContainer&&this.saveState()}),this.manager.onPluginEvent("directionChanged",()=>{this.isDemoContainer&&this.saveState()}))}static initializeGlobalEvents(){window.addEventListener("beforeunload",()=>{n.saveAllContainers()}),document.addEventListener("visibilitychange",()=>{document.hidden&&n.saveAllContainers()}),window.addEventListener("resize",u.debounce(()=>{n.saveAllContainers()},500))}static registerDemoContainer(t){try{n.demoContainers.includes(t)||(n.demoContainers.push(t),n.saveDemoContainersToStorage())}catch(e){console.error("[StatePersistencePlugin] Failed to register demo container:",e)}}static saveDemoContainersToStorage(){try{localStorage.setItem(n.DEMO_CONTAINERS_KEY,JSON.stringify(n.demoContainers))}catch(t){console.error("[StatePersistencePlugin] Failed to save demo containers:",t)}}static getDemoContainers(){try{const t=localStorage.getItem(n.DEMO_CONTAINERS_KEY);return t?JSON.parse(t):[]}catch(t){return console.error("[StatePersistencePlugin] Failed to parse demo containers:",t),[]}}static isDemoContainer(t){return n.getDemoContainers().includes(t)}static getAllStates(){try{const t=localStorage.getItem(n.STORAGE_KEY);return t?JSON.parse(t):{}}catch(t){return console.error("[StatePersistencePlugin] Failed to parse stored states:",t),{}}}static addToClosedQueue(t){if(!n.isDemoContainer(t)){console.log(`[StatePersistencePlugin] Skipping closed queue for non-demo container: ${t}`);return}if(!n.getContainerState(t)){console.error(`[StatePersistencePlugin] Cannot add ${t} to closed queue: state not found`);return}const i=n.closedQueue,s=i.indexOf(t);s>-1&&i.splice(s,1),i.push(t),n.saveClosedQueueToStorage()}static saveClosedQueueToStorage(){try{localStorage.setItem(n.CLOSED_QUEUE_KEY,JSON.stringify(n.closedQueue))}catch(t){console.error("[StatePersistencePlugin] Failed to save closed queue:",t)}}static getClosedQueue(){try{const t=localStorage.getItem(n.CLOSED_QUEUE_KEY);return t?JSON.parse(t):[]}catch(t){return console.error("[StatePersistencePlugin] Failed to parse closed queue:",t),[]}}saveState(){!this.manager||!this.containerId||!this.isDemoContainer||l.batch(()=>{var z;n.reactiveState.isSaving=!0,n.reactiveState.pendingChanges=!0;const t=this.manager.getContainer(),e=t.dataset.maximized==="true",i=this.manager.getState(),s=this.manager.getMode(),r=this.manager.getDirection(),o=t.dataset.containerType||"unknown",c=t.dataset.title,g=t.dataset.color,m=t.dataset.useSnapping==="true",w=(z=this.manager.config)==null?void 0:z.resize,y=t.parentElement,M=y&&y!==document.body?y.id||`parent-${this.containerId}`:void 0,C={...i,mode:s,draggingDirection:r,isMaximized:e,containerType:o,title:c,color:g,useSnapping:m,isClosed:!1,parentElementId:M,closedTimestamp:0,resize:w,isDemoContainer:!0};n.reactiveState.containerStates[this.containerId]=C;const E=n.getAllStates();E[this.containerId]=C,localStorage.setItem(n.STORAGE_KEY,JSON.stringify(E)),n.reactiveState.lastSaved=Date.now(),n.reactiveState.isSaving=!1})}static saveContainerStateBeforeClose(t,e){var U,K,q;const i=t.getState(),s=t.getMode();if(!n.isDemoContainer(e)){n.containers=n.containers.filter(T=>T.containerId!==e);return}const o=t.getContainer(),c=t.getDirection(),g=o.dataset.maximized==="true",m=o.dataset.containerType||"unknown",w=o.dataset.title,y=o.dataset.color,M=o.dataset.useSnapping==="true",C=(U=t.config)==null?void 0:U.resize,E=((K=t.isEdgeDocked)==null?void 0:K.call(t))||!1,z=((q=t.getDockEdge)==null?void 0:q.call(t))||null,k=o.parentElement,ut=k&&k!==document.body?k.id||`parent-${e}`:void 0,G={...i,mode:s,draggingDirection:c,isMaximized:g,isEdgeDocked:E,dockEdge:z||void 0,containerType:m,title:w,color:y,useSnapping:M,isClosed:!0,parentElementId:ut,closedTimestamp:Date.now(),resize:C,isDemoContainer:!0},V=n.getAllStates();V[e]=G;try{localStorage.setItem(n.STORAGE_KEY,JSON.stringify(V))}catch(T){console.error("[StatePersistencePlugin] Failed to save to localStorage:",T)}n.reactiveState.containerStates[e]=G,n.containers=n.containers.filter(T=>T.containerId!==e),n.addToClosedQueue(e)}static saveAllContainers(){l.batch(()=>{const t=n.getAllStates();n.containers.filter(({isDemo:e})=>e).forEach(({manager:e,containerId:i})=>{var k;const s=e.getState(),r=e.getMode(),o=e.getContainer(),c=e.getDirection(),g=o.dataset.maximized==="true",m=o.dataset.containerType||"unknown",w=o.dataset.title,y=o.dataset.color,M=o.dataset.useSnapping==="true",C=(k=e.config)==null?void 0:k.resize,E=o.parentElement,z=E&&E!==document.body?E.id||`parent-${i}`:void 0;t[i]={...s,mode:r,draggingDirection:c,isMaximized:g,containerType:m,title:w,color:y,useSnapping:M,isClosed:!1,parentElementId:z,closedTimestamp:0,resize:C,isDemoContainer:!0}}),n.reactiveState.containerStates=t,localStorage.setItem(n.STORAGE_KEY,JSON.stringify(t)),n.reactiveState.lastSaved=Date.now()})}static popLastClosedContainer(){try{const t=n.closedQueue;if(t.length===0)return null;const e=t.pop();return n.saveClosedQueueToStorage(),e}catch(t){return console.error("[StatePersistencePlugin] Failed to pop last closed container:",t),null}}static hasClosedContainers(){return n.closedQueue.length>0}static getContainerState(t){try{const e=n.containerStates[t];if(e)return e;const s=n.getAllStates()[t];return s?(n.reactiveState.containerStates[t]=s,s):null}catch(e){return console.error("[StatePersistencePlugin] Failed to get container state:",e),null}}static getAllContainerStates(){return n.getAllStates()}static hasContainerState(t){return n.getContainerState(t)!==null}static updateContainerState(t,e){try{const i=n.getAllStates(),s=i[t];if(s){const r={...s,...e};i[t]=r,localStorage.setItem(n.STORAGE_KEY,JSON.stringify(i)),n.reactiveState.containerStates[t]=r}else{console.warn(`[StatePersistencePlugin] No state found for container ${t}, creating new state`);const r={x:0,y:0,width:300,height:200,mode:"smooth",draggingDirection:"all",isMaximized:!1,containerType:"unknown",isClosed:!1,isDemoContainer:n.isDemoContainer(t),...e};i[t]=r,localStorage.setItem(n.STORAGE_KEY,JSON.stringify(i)),n.reactiveState.containerStates[t]=r}}catch(i){console.error("[StatePersistencePlugin] Failed to update container state:",i)}}static clearStorage(){l.batch(()=>{n.reactiveState.containerStates={},n.closedQueue.length=0,n.demoContainers.length=0,n.reactiveState.isSaving=!1,n.reactiveState.lastSaved=null,n.reactiveState.pendingChanges=!1}),localStorage.removeItem(n.STORAGE_KEY),localStorage.removeItem(n.CLOSED_QUEUE_KEY),localStorage.removeItem(n.DEMO_CONTAINERS_KEY),n.containers=[]}static initializeReactiveState(){try{const t=n.getAllStates(),e=n.getClosedQueue(),i=n.getDemoContainers();l.batch(()=>{n.reactiveState.containerStates=t,n.closedQueue.length=0,n.closedQueue.push(...e),n.demoContainers.length=0,n.demoContainers.push(...i)})}catch(t){console.error("[StatePersistencePlugin] Failed to initialize reactive state:",t)}}static getMetrics(){return{totalContainers:Object.keys(n.containerStates).length,demoContainers:n.demoContainers.length,closedContainers:n.closedQueue.length,lastSaved:n.reactiveState.lastSaved,isSaving:n.reactiveState.isSaving}}static debugStorage(){console.log("[StatePersistencePlugin] === START DEBUG INFO ===");try{const t=localStorage.getItem(n.STORAGE_KEY);if(t){const s=JSON.parse(t);console.log(`[StatePersistencePlugin] Number of states: ${Object.keys(s).length}`),console.log("[StatePersistencePlugin] State keys:",Object.keys(s));for(const[r,o]of Object.entries(s))console.log(`[StatePersistencePlugin] State ${r}:`,{isDemoContainer:o.isDemoContainer,isClosed:o.isClosed,title:o.title})}const e=localStorage.getItem(n.CLOSED_QUEUE_KEY);console.log("[StatePersistencePlugin] Closed queue:",e?JSON.parse(e):[]);const i=localStorage.getItem(n.DEMO_CONTAINERS_KEY);console.log("[StatePersistencePlugin] Demo containers:",i?JSON.parse(i):[])}catch(t){console.error("[StatePersistencePlugin] Debug error:",t)}console.log("[StatePersistencePlugin] === END DEBUG INFO ===")}destroy(){this.autoSaveEffect&&(this.autoSaveEffect(),this.autoSaveEffect=void 0),this.containerId&&(n.containers=n.containers.filter(t=>t.containerId!==this.containerId))}};a(n,"_pluginId",Symbol("StatePersistencePlugin")),a(n,"STORAGE_KEY","containerManagerState"),a(n,"CLOSED_QUEUE_KEY","containerManagerClosedQueue"),a(n,"DEMO_CONTAINERS_KEY","containerManagerDemoContainers"),a(n,"reactiveState",l.reactive({isSaving:!1,lastSaved:null,pendingChanges:!1,containerStates:{},closedQueue:[],demoContainers:[]})),a(n,"isGlobalEventsInitialized",!1),a(n,"containers",[]);let x=n;x.initializeReactiveState();const R=class R{constructor(){a(this,"manager");a(this,"containerName","");a(this,"notificationSystem",null)}get pluginId(){return R._pluginId}install(t,e){this.manager=t,this.containerName=(e==null?void 0:e.containerName)||`Container-${Math.random().toString(36).substring(2,11)}`,this.notificationSystem=e==null?void 0:e.notificationSystem,this.bindEvents()}bindEvents(){this.manager&&(this.logResize=u.debounce(this.logResize.bind(this),250),this.logDrag=u.debounce(this.logDrag.bind(this),250),this.logViewportResize=u.debounce(this.logViewportResize.bind(this),250),this.logSnapStep=u.debounce(this.logSnapStep.bind(this),250),this.manager.on("modeChange",t=>{this.logModeChange(t.mode)}),this.manager.on("resize",t=>{this.logResize(t.state)}),this.manager.on("resizeEnd",t=>{this.logResize(t.state)}),this.manager.on("drag",t=>{this.logDrag(t.state)}),this.manager.on("dragEnd",t=>{this.logDrag(t.state)}),this.manager.on("viewportResize",t=>{this.logViewportResize(t.state)}),this.manager.onPluginEvent("snappingEnabledChanged",t=>{this.logSnappingEnabled(t.enabled)}),this.manager.onPluginEvent("snapStepChanged",t=>{this.logSnapStep(t.snapStep)}),this.manager.onPluginEvent("directionChanged",t=>{this.logDirectionChange(t.direction)}))}logResize(t){const e=`Resized to ${Math.round(t.width)}×${Math.round(t.height)}`;this.showNotification(e,"info")}logDrag(t){const e=`Moved to (${Math.round(t.x)}, ${Math.round(t.y)})`;this.showNotification(e,"info")}logModeChange(t){const e=`Mode changed to ${t}`;this.showNotification(e,"warning")}logViewportResize(t){const e=`Adjusted position to (${Math.round(t.x)}, ${Math.round(t.y)}) due to window resize`;this.showNotification(e,"info")}logSnappingEnabled(t){const e=`Snapping ${t?"enabled":"disabled"}`;this.showNotification(e,t?"success":"warning")}logSnapStep(t){const e=`Snap step changed to ${t}px`;this.showNotification(e,"info")}logDirectionChange(t){const e=`Drag direction: ${t}`;this.showNotification(e,"info")}showNotification(t,e){if(this.notificationSystem){const i=`${this.containerName}: ${t}`;this.notificationSystem.show(i,e)}}};a(R,"_pluginId",Symbol("LoggingPlugin"));let Y=R;const dt=Object.freeze(Object.defineProperty({__proto__:null,default:`<div class="media-content">
9
43
  <h4>🎬 Media Gallery</h4>
10
44
  <div class="media-grid">
11
45
  <div class="media-item" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);">
@@ -25,7 +59,7 @@
25
59
  <small>📁 Template: media.html</small>
26
60
  </div>
27
61
  </div>
28
- `},Symbol.toStringTag,{value:"Module"})),de=Object.freeze(Object.defineProperty({__proto__:null,default:`<div class="stats-content">
62
+ `},Symbol.toStringTag,{value:"Module"})),lt=Object.freeze(Object.defineProperty({__proto__:null,default:`<div class="stats-content">
29
63
  <h4>📊 Statistics Panel</h4>
30
64
  <div class="stats-grid">
31
65
  <div class="stat-card">
@@ -56,7 +90,7 @@
56
90
  </div>
57
91
  </div>
58
92
  <p>This template demonstrates dynamic content structure with CSS styling.</p>
59
- </div>`},Symbol.toStringTag,{value:"Module"})),le=Object.freeze(Object.defineProperty({__proto__:null,default:`<div class="tasks-content">
93
+ </div>`},Symbol.toStringTag,{value:"Module"})),gt=Object.freeze(Object.defineProperty({__proto__:null,default:`<div class="tasks-content">
60
94
  <h4>✅ Task Manager</h4>
61
95
  <div class="task-list">
62
96
  <div class="task-item completed">
@@ -85,5 +119,5 @@
85
119
  </div>
86
120
  </div>
87
121
  <p>Template content can include interactive elements and dynamic data.</p>
88
- </div>`},Symbol.toStringTag,{value:"Module"}));l.ContainerInitializer=q,l.ContainerManager=$,l.ContentCreator=J,l.EdgeDockingPlugin=N,l.LoggingPlugin=Y,l.NotificationSystem=F,l.SnappingPlugin=A,l.StatePersistencePlugin=T,l.TemplateLoader=O,l.getTemplateLoader=ne,l.initializeTemplateSystem=se,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
122
+ </div>`},Symbol.toStringTag,{value:"Module"}));d.ContainerInitializer=J,d.ContainerManager=I,d.ContentCreator=Z,d.EdgeDockingPlugin=N,d.LoggingPlugin=Y,d.NotificationSystem=F,d.SnappingPlugin=A,d.StatePersistencePlugin=x,d.StatsManager=_,d.TemplateLoader=O,d.getState=X,d.getTemplateLoader=rt,d.initializeTemplateSystem=at,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
89
123
  //# sourceMappingURL=index.umd.js.map