| 1 |
- import{c as Q,o as he,h as ge,g as S,t as C,a as X,s as n,i as $,b as re,S as ue,m as Z,e as H,k as ne,l as Be,d as je,u as He,r as Te,D as Ke}from"./web.gEHESIx2.js";var Ve=C('<div style="margin-top:0.5rem;font-size:clamp(0.6rem, 1.5vw + 0.5vh, 1rem);text-align:center;line-height:1.4">'),Je=C('<div style=box-sizing:border-box;flex-direction:column;justify-content:center;align-items:center><div style="font-size:clamp(0.8rem, 3.5vw + 0.5vh, 2.5rem);font-weight:bold;text-align:center;word-break:break-word;line-height:1.2"></div><!$><!/>');function Ze(e){const[t,r]=Q(""),i=()=>{const o=new Date,s=e.settings.format||"24h",a=e.settings.timeFormat||"HH:MM:SS";let c=o.getHours();const l=o.getMinutes().toString().padStart(2,"0"),m=o.getSeconds().toString().padStart(2,"0");let x="",v="";s==="12h"&&(v=c>=12?" PM":" AM",c=c%12||12);const b=s==="24h"?c.toString().padStart(2,"0"):c.toString();switch(a){case"HH:MM:SS":x=`${b}:${l}:${m}${v}`;break;case"HH:MM":x=`${b}:${l}${v}`;break;case"HH only":x=`${b}${v}`;break;default:x=`${b}:${l}:${m}${v}`}e.settings.showDate&&(x=`${o.toLocaleDateString()} ${x}`),r(x)};return he(()=>{i();const o=e.settings.refreshRate||1,s=setInterval(i,o*1e3);ge(()=>clearInterval(s))}),(()=>{var o=S(Je),s=o.firstChild,a=s.nextSibling,[c,l]=X(a.nextSibling);return n(o,"border","1px solid var(--border)"),n(o,"padding","1rem"),n(o,"width","100%"),n(o,"height","100%"),n(o,"display","flex"),n(o,"background","var(--bg, #fff)"),$(s,t),$(o,re(ue,{get when(){return e.settings.showLabel},get children(){var m=S(Ve);return n(m,"color","var(--gray)"),$(m,()=>e.settings.label||"Current Time"),m}}),c,l),o})()}const et={name:"Clock",description:"Display current time and date",settingsSchema:{format:{type:"select",label:"Time Format",default:"24h",options:["12h","24h"],required:!0},timeFormat:{type:"select",label:"Display Format",default:"HH:MM:SS",options:["HH:MM:SS","HH:MM","HH only"]},showDate:{type:"boolean",label:"Show Date",default:!0},showLabel:{type:"boolean",label:"Show Label",default:!0},label:{type:"string",label:"Custom Label",default:"Current Time"},refreshRate:{type:"number",label:"Refresh Rate (seconds)",default:1}}};function tt(e,t){return e*({seconds:1e3,minutes:6e4,hours:36e5,days:864e5}[t]||1e3)}function qe(e,t=60,r="minutes"){const i=e.refreshIntervalValue||t,o=e.refreshIntervalUnit||r;return tt(i,o)}var nt=C('<div style=box-sizing:border-box;flex-direction:column;justify-content:center;align-items:center><div style="margin-bottom:0.5rem;font-weight:bold;font-size:clamp(0.7rem, 2vw + 0.5vh, 1.5rem);text-align:center;line-height:1.3"></div><div style="font-size:clamp(0.8rem, 3.5vw + 0.5vh, 2.5rem);font-weight:bold;text-align:center;word-break:break-word;line-height:1.2"></div><!$><!/>'),it=C('<div style="margin-top:0.5rem;font-size:clamp(0.6rem, 1.5vw + 0.5vh, 1rem);text-align:center;line-height:1.4">');const Oe=new Map,ke=new Map,ve=new Map;function rt(e){const t=`${e.settings.symbol}-${e.settings.currency}`,r=5e3,[i,o]=Q(ke.get(t)||"Loading..."),[s,a]=Q(ve.get(t)||""),c=async()=>{const l=Date.now(),m=Oe.get(t)||0;if(l-m<r){const x=Math.round((r-(l-m))/1e3);console.log(`[CryptoPrice] COOLDOWN: ${x}s remaining`);return}Oe.set(t,l),console.log("[CryptoPrice] Fetching price...");try{const x=e.settings.symbol||"bitcoin",v=e.settings.currency||"USD",b=await fetch(`https://api.coingecko.com/api/v3/simple/price?ids=${x.toLowerCase()}&vs_currencies=${v.toLowerCase()}`);if(!b.ok)throw new Error("Failed to fetch price");const h=(await b.json())[x.toLowerCase()]?.[v.toLowerCase()];if(h){const p=`${v} ${h.toLocaleString()}`;o(p),a(""),ke.set(t,p),ve.delete(t)}else a("Price not found"),ve.set(t,"Price not found")}catch(x){a("Error fetching price"),ve.set(t,"Error fetching price"),console.error("[CryptoPrice] Error:",x)}};return he(()=>{ke.has(t)||c();const l=qe(e.settings,1,"minutes"),m=setInterval(()=>{c()},l);ge(()=>{clearInterval(m)})}),(()=>{var l=S(nt),m=l.firstChild,x=m.nextSibling,v=x.nextSibling,[b,g]=X(v.nextSibling);return n(l,"border","1px solid var(--border)"),n(l,"padding","1rem"),n(l,"width","100%"),n(l,"height","100%"),n(l,"display","flex"),n(l,"background","var(--bg, #fff)"),$(m,()=>e.settings.symbol||"BTC"),$(x,()=>s()||i()),$(l,(()=>{var h=Z(()=>!!e.settings.showLabel);return()=>h()&&(()=>{var p=S(it);return n(p,"color","var(--gray)"),$(p,()=>e.settings.label||"Price"),p})()})(),b,g),l})()}const ot={name:"Crypto Price",description:"Display cryptocurrency price from CoinGecko API",settingsSchema:{symbol:{type:"string",label:"Crypto Symbol (e.g., bitcoin, ethereum)",default:"bitcoin",required:!0},currency:{type:"string",label:"Currency (e.g., USD, EUR)",default:"USD",required:!0},refreshIntervalValue:{type:"number",label:"Refresh Interval",default:1,required:!0},refreshIntervalUnit:{type:"select",label:"Unit",options:["seconds","minutes","hours","days"],default:"minutes",required:!0},showLabel:{type:"boolean",label:"Show Label",default:!0},label:{type:"string",label:"Custom Label",default:"Price"}}};var at=C('<div style="font-size:clamp(0.7rem, 2vw + 0.5vh, 1rem);text-align:center">'),lt=C('<div style="font-size:clamp(0.7rem, 2vw + 0.5vh, 1.2rem);font-weight:bold;margin-bottom:0.5rem;text-align:center">'),st=C('<div style="font-size:clamp(1.5rem, 5vw + 1vh, 3.5rem);font-weight:bold;text-align:center;line-height:1.1"><!$><!/>°<!$><!/>'),dt=C('<div style="font-size:clamp(0.7rem, 1.8vw + 0.5vh, 1.1rem);text-align:center;margin-top:0.3rem;text-transform:capitalize">'),ct=C('<div style="margin-top:0.8rem;font-size:clamp(0.6rem, 1.5vw + 0.5vh, 0.9rem)"><div>💧 <!$><!/>%</div><div>💨 <!$><!/> m/s'),ut=C("<div style=box-sizing:border-box;flex-direction:column;justify-content:center;align-items:center><!$><!/><!$><!/>");function ht(e){const[t,r]=Q(null),[i,o]=Q(""),s=async()=>{try{const a=e.settings.city||"London",c=e.settings.lat||"",l=e.settings.lon||"",m=e.settings.apiKey||"",x=e.settings.units||"metric";if(!m){o("API key required");return}let v=`/api/weather?apiKey=${encodeURIComponent(m)}&units=${x}`;c&&l?v+=`&lat=${encodeURIComponent(c)}&lon=${encodeURIComponent(l)}`:v+=`&city=${encodeURIComponent(a)}`;const b=await fetch(v);if(!b.ok)throw new Error("Failed to fetch weather");const g=await b.json();r({temp:Math.round(g.main.temp),description:g.weather[0].description,humidity:g.main.humidity,windSpeed:g.wind.speed}),o("")}catch(a){o("Error fetching weather"),console.error(a)}};return he(()=>{s();const a=qe(e.settings,10,"minutes"),c=setInterval(s,a);ge(()=>clearInterval(c))}),(()=>{var a=S(ut),c=a.firstChild,[l,m]=X(c.nextSibling),x=l.nextSibling,[v,b]=X(x.nextSibling);return n(a,"border","1px solid var(--border)"),n(a,"padding","1rem"),n(a,"width","100%"),n(a,"height","100%"),n(a,"display","flex"),n(a,"background","var(--bg, #fff)"),$(a,re(ue,{get when(){return i()},get children(){var g=S(at);return n(g,"color","#ff4444"),$(g,i),g}}),l,m),$(a,re(ue,{get when(){return Z(()=>!i())()&&t()},get children(){return[(()=>{var g=S(lt);return $(g,(()=>{var h=Z(()=>!!(e.settings.lat&&e.settings.lon));return()=>h()?`${e.settings.lat}, ${e.settings.lon}`:e.settings.city||"London"})()),g})(),(()=>{var g=S(st),h=g.firstChild,[p,L]=X(h.nextSibling),z=p.nextSibling,P=z.nextSibling,[w,q]=X(P.nextSibling);return $(g,()=>t()?.temp,p,L),$(g,()=>e.settings.units==="metric"?"C":"F",w,q),g})(),(()=>{var g=S(dt);return n(g,"color","var(--gray)"),$(g,()=>t()?.description),g})(),re(ue,{get when(){return e.settings.showDetails},get children(){var g=S(ct),h=g.firstChild,p=h.firstChild,L=p.nextSibling,[z,P]=X(L.nextSibling);z.nextSibling;var w=h.nextSibling,q=w.firstChild,B=q.nextSibling,[f,d]=X(B.nextSibling);return f.nextSibling,n(g,"display","flex"),n(g,"gap","1rem"),n(g,"color","var(--gray)"),$(h,()=>t()?.humidity,z,P),$(w,()=>t()?.windSpeed,f,d),g}})]}}),v,b),a})()}const gt={name:"Weather",description:"Display current weather from OpenWeatherMap API",settingsSchema:{city:{type:"string",label:"City Name",default:"London",required:!1},lat:{type:"string",label:"Latitude (optional, overrides city)",default:"",required:!1},lon:{type:"string",label:"Longitude (optional, overrides city)",default:"",required:!1},apiKey:{type:"string",label:"OpenWeatherMap API Key",default:"",required:!0},units:{type:"select",label:"Temperature Units",default:"metric",options:["metric","imperial"]},showDetails:{type:"boolean",label:"Show Humidity & Wind",default:!0},refreshIntervalValue:{type:"number",label:"Refresh Interval",default:10,required:!0},refreshIntervalUnit:{type:"select",label:"Unit",options:["seconds","minutes","hours","days"],default:"minutes",required:!0}}};var mt=C('<div style=box-sizing:border-box;flex-direction:column;justify-content:center;align-items:center><div style="font-size:1.5rem;line-height:1;font-family:Georgia, serif;font-weight:bold">Σ</div><div style=text-align:center;max-width:95%></div><div style=font-size:0.7rem;text-transform:uppercase;letter-spacing:0.05em>Stoic Wisdom'),ft=C("<div>"),vt=C('<div style=line-height:1.4;font-style:italic>"<!$><!/>"'),bt=C("<div style=margin-top:0.5rem;font-weight:500>— <!$><!/>");const Ue=new Map,De=new Map;function yt(e){const t="stoic-quote",i=De.get(t)||{text:"Loading wisdom...",author:""},[o,s]=Q(i),[a,c]=Q(""),[l,m]=Q(0),x=async(h=!1)=>{const p=Date.now(),L=Ue.get(t)||0;if(!h&&p-L<1e4){console.log("[StoicQuote] Cooldown active, skipping manual refresh");return}Ue.set(t,p),console.log("[StoicQuote] Fetching quote from API...");try{const z=await fetch("https://stoic-quotes.com/api/quote");if(!z.ok)throw new Error("Failed to fetch quote");const P=await z.json(),w={text:P.text,author:P.author};console.log("[StoicQuote] ✨ New quote received:",{author:w.author,preview:w.text.substring(0,50)+"...",timestamp:new Date().toLocaleTimeString()}),s(w),c(""),De.set(t,w),m(q=>q+1),console.log("[StoicQuote] ✅ Quote state updated, render key incremented, forcing re-render")}catch(z){console.error("[StoicQuote] Error:",z),c("Failed to load quote")}};he(()=>{De.has(t)||x(!0);const h=qe(e.settings,1,"hours");console.log(`[StoicQuote] Setting up interval: ${h}ms`);const p=setInterval(()=>{console.log("[StoicQuote] Interval tick - fetching new quote"),x(!0)},h);ge(()=>{console.log("[StoicQuote] Cleaning up interval"),clearInterval(p)})});const v=()=>e.settings.showAuthor!==!1,b=()=>e.settings.fontSize||"medium",g=()=>{const h={small:{quote:"clamp(0.7rem, 1.5vw, 1.2rem)",author:"clamp(0.6rem, 1.2vw, 0.9rem)"},medium:{quote:"clamp(0.9rem, 2vw, 1.5rem)",author:"clamp(0.7rem, 1.5vw, 1.1rem)"},large:{quote:"clamp(1.1rem, 2.5vw, 2rem)",author:"clamp(0.8rem, 1.8vw, 1.3rem)"}};return h[b()]||h.medium};return(()=>{var h=S(mt),p=h.firstChild,L=p.nextSibling,z=L.nextSibling;return n(h,"border","1px solid var(--border)"),n(h,"padding","1rem"),n(h,"width","100%"),n(h,"height","100%"),n(h,"display","flex"),n(h,"background","var(--bg, #fff)"),n(h,"position","relative"),n(p,"position","absolute"),n(p,"top","0.5rem"),n(p,"left","0.5rem"),n(p,"color","var(--border, #ccc)"),n(p,"opacity","0.3"),$(L,(()=>{var P=Z(()=>!!a());return()=>P()?(()=>{var w=S(ft);return n(w,"color","var(--gray, #999)"),$(w,a),w})():[(()=>{var w=S(vt),q=w.firstChild,B=q.nextSibling,[f,d]=X(B.nextSibling);return f.nextSibling,$(w,()=>o().text,f,d),H(k=>n(w,"font-size",g().quote)),w})(),Z(()=>Z(()=>!!(v()&&o().author))()&&(()=>{var w=S(bt),q=w.firstChild,B=q.nextSibling,[f,d]=X(B.nextSibling);return n(w,"color","var(--gray, #666)"),$(w,()=>o().author,f,d),H(k=>n(w,"font-size",g().author)),w})())]})()),n(z,"position","absolute"),n(z,"bottom","8px"),n(z,"left","8px"),n(z,"color","var(--gray, #999)"),n(z,"opacity","0.5"),H(()=>ne(h,"data-render-key",l())),h})()}const xt={name:"Stoic Quote",description:"Display stoic wisdom from Marcus Aurelius, Seneca, and Epictetus",settingsSchema:{fontSize:{type:"select",label:"Font Size",options:["small","medium","large"],default:"medium"},showAuthor:{type:"boolean",label:"Show Author",default:!0},refreshIntervalValue:{type:"number",label:"Refresh Interval",default:1,required:!0},refreshIntervalUnit:{type:"select",label:"Unit",options:["seconds","minutes","hours","days"],default:"hours",required:!0}}},pt={"crypto-price":{schema:ot,Component:rt},clock:{schema:et,Component:Ze},weather:{schema:gt,Component:ht},"stoic-quote":{schema:xt,Component:yt}};function wt(e){return pt[e]}var Me={dragStart:!0},ze={delay:0,distance:3};function $t(e,t={}){let r,i,{bounds:o,axis:s="both",gpuAcceleration:a=!0,legacyTranslate:c=!1,transform:l,applyUserSelectHack:m=!0,disabled:x=!1,ignoreMultitouch:v=!1,recomputeBounds:b=Me,grid:g,threshold:h=ze,position:p,cancel:L,handle:z,defaultClass:P="neodrag",defaultClassDragging:w="neodrag-dragging",defaultClassDragged:q="neodrag-dragged",defaultPosition:B={x:0,y:0},onDragStart:f,onDrag:d,onDragEnd:k}=t,M=!1,I=!1,U=0,A=!1,E=!1,N=0,Y=0,_=0,y=0,K=0,ie=0,{x:ee,y:te}=p?{x:p?.x??0,y:p?.y??0}:B;$e(ee,te);let W,G,oe,xe,pe,Pe="",Qe=!!p;b={...Me,...b},h={...ze,...h??{}};let me=new Set;function Ae(u){M&&!I&&E&&A&&pe&&(I=!0,(function(R){Se("neodrag:start",f,R)})(u),V.add(w),m&&(Pe=we.userSelect,we.userSelect="none"))}const we=document.body.style,V=e.classList;function $e(u=N,R=Y){if(!l){if(c){let O=`${+u}px, ${+R}px`;return be(e,"transform",a?`translate3d(${O}, 0)`:`translate(${O})`)}return be(e,"translate",`${+u}px ${+R}px`)}const T=l({offsetX:u,offsetY:R,rootNode:e});Ie(T)&&be(e,"transform",T)}function Se(u,R,T){const O=(function(F){return{offsetX:N,offsetY:Y,rootNode:e,currentNode:pe,event:F}})(T);e.dispatchEvent(new CustomEvent(u,{detail:O})),R?.(O)}const fe=addEventListener,Ce=new AbortController,_e={signal:Ce.signal,capture:!1};function Fe(){let u=e.offsetWidth/G.width;return isNaN(u)&&(u=1),u}return be(e,"touch-action","none"),fe("pointerdown",(u=>{if(x||u.button===2)return;if(me.add(u.pointerId),v&&me.size>1)return u.preventDefault();if(b.dragStart&&(W=Re(o,e)),Ie(z)&&Ie(L)&&z===L)throw new Error("`handle` selector can't be same as `cancel` selector");if(V.add(P),oe=(function(D,J){if(!D)return[J];if(Le(D))return[D];if(Array.isArray(D))return D;const j=J.querySelectorAll(D);if(j===null)throw new Error("Selector passed for `handle` option should be child of the element on which the action is applied");return Array.from(j.values())})(z,e),xe=(function(D,J){if(!D)return[];if(Le(D))return[D];if(Array.isArray(D))return D;const j=J.querySelectorAll(D);if(j===null)throw new Error("Selector passed for `cancel` option should be child of the element on which the action is applied");return Array.from(j.values())})(L,e),r=/(both|x)/.test(s),i=/(both|y)/.test(s),We(xe,oe))throw new Error("Element being dragged can't be a child of the element on which `cancel` is applied");const R=u.composedPath()[0];if(!oe.some((D=>D.contains(R)||D.shadowRoot?.contains(R)))||We(xe,[R]))return;pe=oe.length===1?e:oe.find((D=>D.contains(R))),M=!0,U=Date.now(),h.delay||(A=!0),G=e.getBoundingClientRect();const{clientX:T,clientY:O}=u,F=Fe();r&&(_=T-ee/F),i&&(y=O-te/F),W&&(K=T-G.left,ie=O-G.top)}),_e),fe("pointermove",(u=>{if(!M||v&&me.size>1)return;if(!I){if(A||Date.now()-U>=h.delay&&(A=!0,Ae(u)),!E){const F=u.clientX-_,D=u.clientY-y;Math.sqrt(F**2+D**2)>=h.distance&&(E=!0,Ae(u))}if(!I)return}b.drag&&(W=Re(o,e)),u.preventDefault(),G=e.getBoundingClientRect();let R=u.clientX,T=u.clientY;const O=Fe();if(W){const F={left:W.left+K,top:W.top+ie,right:W.right+K-G.width,bottom:W.bottom+ie-G.height};R=Ne(R,F.left,F.right),T=Ne(T,F.top,F.bottom)}if(Array.isArray(g)){let[F,D]=g;if(isNaN(+F)||F<0)throw new Error("1st argument of `grid` must be a valid positive number");if(isNaN(+D)||D<0)throw new Error("2nd argument of `grid` must be a valid positive number");let J=R-_,j=T-y;[J,j]=St([F/O,D/O],J,j),R=_+J,T=y+j}r&&(N=Math.round((R-_)*O)),i&&(Y=Math.round((T-y)*O)),ee=N,te=Y,Se("neodrag",d,u),$e()}),_e),fe("pointerup",(u=>{me.delete(u.pointerId),M&&(I&&(fe("click",(R=>R.stopPropagation()),{once:!0,signal:Ce.signal,capture:!0}),b.dragEnd&&(W=Re(o,e)),V.remove(w),V.add(q),m&&(we.userSelect=Pe),Se("neodrag:end",k,u),r&&(_=N),i&&(y=Y)),M=!1,I=!1,A=!1,E=!1)}),_e),{destroy:()=>Ce.abort(),update:u=>{s=u.axis||"both",x=u.disabled??!1,v=u.ignoreMultitouch??!1,z=u.handle,o=u.bounds,b=u.recomputeBounds??Me,L=u.cancel,m=u.applyUserSelectHack??!0,g=u.grid,a=u.gpuAcceleration??!0,c=u.legacyTranslate??!1,l=u.transform,h={...ze,...u.threshold??{}};const R=V.contains(q);V.remove(P,q),P=u.defaultClass??"neodrag",w=u.defaultClassDragging??"neodrag-dragging",q=u.defaultClassDragged??"neodrag-dragged",V.add(P),R&&V.add(q),Qe&&(ee=N=u.position?.x??N,te=Y=u.position?.y??Y,$e())}}}var Ne=(e,t,r)=>Math.min(Math.max(e,t),r),Ie=e=>typeof e=="string",St=([e,t],r,i)=>{const o=(s,a)=>a===0?0:Math.ceil(s/a)*a;return[o(r,e),o(i,t)]},We=(e,t)=>e.some((r=>t.some((i=>r.contains(i)))));function Re(e,t){if(e===void 0)return;if(Le(e))return e.getBoundingClientRect();if(typeof e=="object"){const{top:i=0,left:o=0,right:s=0,bottom:a=0}=e;return{top:i,right:window.innerWidth-s,bottom:window.innerHeight-a,left:o}}if(e==="parent")return t.parentNode.getBoundingClientRect();const r=document.querySelector(e);if(r===null)throw new Error("The selector provided for bound doesn't exists in the document.");return r.getBoundingClientRect()}var be=(e,t,r)=>e.style.setProperty(t,r),Le=e=>e instanceof HTMLElement,Ct=()=>({draggable:(e,t)=>{const{update:r,destroy:i}=$t(e,t());ge(i),Be((()=>r(t())))}}),_t=C("<div style=user-select:none><!$><!/><!$><!/><div>"),kt=C("<button style=z-index:10;font-size:1rem;border-radius:50%;align-items:center;justify-content:center;font-weight:bold>×"),Dt=C("<div class=resize-handle style=z-index:10;border-bottom-right-radius:4px>");const ye={threshold:500,minOverlap:.15};function Ee(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function Xe(e,t){const r=t.x-e.x,i=t.y-e.y;return Math.sqrt(r*r+i*i)}function Mt(e,t){const r=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),i=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y)),o=r*i,s=e.width*e.height;return s>0?o/s:0}function zt(e,t,r){if(t.length===0)return null;const i=Ee(e);let o=null,s=0;console.log("[Snap Debug] Finding target:",{widgetRect:e,widgetCenter:i,cellsCount:t.length,threshold:r,minOverlap:ye.minOverlap});for(const a of t){const c=Ee(a),l=Xe(i,c);if(l>r)continue;const m=Mt(e,a);console.log("[Snap Debug] Checking cell:",{cellId:a.id,cellCenter:c,distance:l.toFixed(1),overlap:m.toFixed(3),withinThreshold:l<=r,meetsMinOverlap:m>=ye.minOverlap}),!(m<ye.minOverlap)&&(m>s||m===s&&o&&l<Xe(i,Ee(o)))&&(s=m,o=a,console.log("[Snap Debug] New best cell:",{cellId:a.id,overlap:m.toFixed(3),distance:l.toFixed(1)}))}return console.log("[Snap Debug] Final best cell:",{cellId:o?.id||"none",overlap:s.toFixed(3)}),o}function Ye(e,t,r,i){if(r.length===0)return{snapped:!1,targetCell:null,position:e};const o={x:e.x,y:e.y,width:t.width,height:t.height},s=zt(o,r,ye.threshold);return s?{snapped:!0,targetCell:s,position:{x:s.x,y:s.y},size:{width:s.width,height:s.height}}:{snapped:!1,targetCell:null,position:e}}function Gt(e){const t=wt(e.config.type),{draggable:r}=Ct(),[i,o]=Q(!1),[s,a]=Q(!1);let c=null,l,m={width:0,height:0},x={x:0,y:0},v=null,b=null;const g=()=>e.config.position||{x:10,y:10},h=()=>e.config.size||{width:200,height:150};he(()=>{c=document.querySelector("[data-grid-container]")});const p=()=>{if(!c)return 1;const f=window.getComputedStyle(c).transform;if(!f||f==="none")return 1;try{const d=f.match(/matrix\(([^)]+)\)/);if(d)return d[1].split(",").map(I=>parseFloat(I.trim()))[0]||1;const k=f.match(/matrix3d\(([^)]+)\)/);if(k)return k[1].split(",").map(I=>parseFloat(I.trim()))[0]||1}catch{return 1}return 1},L=(f,d)=>{if(!c)return null;const k=c.getBoundingClientRect(),M=p();return{x:(f-k.left)/M,y:(d-k.top)/M}},z=()=>{if(!l||!c)return g();const f=l.getBoundingClientRect(),d=c.getBoundingClientRect(),k=p();return{x:(f.left-d.left)/k,y:(f.top-d.top)/k}},P=f=>{if(o(!0),e.onDragStateChange?.(!0),!f||!f.event)return;const d=f.event,k="clientX"in d?d.clientX:d.touches[0].clientX,M="clientY"in d?d.clientY:d.touches[0].clientY;console.log("[Snap Debug] DRAG START",{widgetId:e.config.id,clientX:k,clientY:M,gridCellsCount:e.gridCells?.length||0}),b=L(k,M),v=z(),console.log("[Snap Debug] Drag start positions:",{dragStartPointerPos:b,dragStartWidgetPos:v})},w=f=>{if(!e.gridCells||e.gridCells.length===0){e.onCellHover?.(null);return}if(!f.event)return;const d=f.event,k="clientX"in d?d.clientX:d.touches[0].clientX,M="clientY"in d?d.clientY:d.touches[0].clientY,I=L(k,M);if(!I||!b||!v)return;const U={x:I.x-b.x,y:I.y-b.y},A={x:v.x+U.x,y:v.y+U.y},E=Ye(A,h(),e.gridCells);console.log("[Snap Debug] Drag:",{widgetId:e.config.id,currentPos:A,widgetSize:h(),cellsCount:e.gridCells.length,snapResult:{snapped:E.snapped,targetCellId:E.targetCell?.id}}),e.onCellHover?.(E.targetCell?.id||null)},q=f=>{if(o(!1),e.onDragStateChange?.(!1),e.onCellHover?.(null),!f.event){v=null,b=null;return}const d=f.event,k="clientX"in d?d.clientX:d.touches[0]?.clientX,M="clientY"in d?d.clientY:d.touches[0]?.clientY,I=L(k,M);if(!I||!b||!v){v=null,b=null;return}const U={x:I.x-b.x,y:I.y-b.y},A={x:v.x+U.x,y:v.y+U.y},E=Ye(A,h(),e.gridCells||[]);e.onPositionUpdate?.(e.config.id,{x:Math.round(E.position.x),y:Math.round(E.position.y)}),E.snapped&&E.size&&e.onSizeUpdate?.(e.config.id,{width:Math.round(E.size.width),height:Math.round(E.size.height)}),e.onSnapToCell?.(e.config.id,E.targetCell?.id||null),v=null,b=null},B=f=>{f.preventDefault(),f.stopPropagation(),a(!0),m=h(),x={x:f.clientX,y:f.clientY};const d=M=>{const I=M.clientX-x.x,U=M.clientY-x.y,A=Math.max(150,m.width+I),E=Math.max(100,m.height+U);e.onSizeUpdate?.(e.config.id,{width:Math.round(A),height:Math.round(E)})},k=()=>{a(!1),document.removeEventListener("mousemove",d),document.removeEventListener("mouseup",k)};document.addEventListener("mousemove",d),document.addEventListener("mouseup",k)};return re(ue,{when:t,children:f=>(()=>{var d=S(_t),k=d.firstChild,[M,I]=X(k.nextSibling),U=M.nextSibling,[A,E]=X(U.nextSibling),N=A.nextSibling;He(r,d,()=>({disabled:e.locked||s(),position:g(),bounds:"parent",cancel:"button, input, select, textarea, .resize-handle",onDragStart:P,onDrag:w,onDragEnd:q,gpuAcceleration:!0,applyUserSelectHack:!0}));var Y=l;return typeof Y=="function"?He(Y,d):l=d,n(d,"position","absolute"),$(d,(()=>{var _=Z(()=>!!(!e.locked&&e.onRemove));return()=>_()&&(()=>{var y=S(kt);return y.$$click=K=>{K.stopPropagation(),e.onRemove?.(e.config.id)},n(y,"position","absolute"),n(y,"top","-8px"),n(y,"right","-8px"),n(y,"padding","0"),n(y,"background","#ff4444"),n(y,"color","white"),n(y,"border","none"),n(y,"cursor","pointer"),n(y,"width","24px"),n(y,"height","24px"),n(y,"display","flex"),Te(),y})()})(),M,I),$(d,(()=>{var _=Z(()=>!e.locked&&(!e.gridCells||e.gridCells.length===0));return()=>_()&&(()=>{var y=S(Dt);return y.$$mousedown=B,n(y,"position","absolute"),n(y,"bottom","0"),n(y,"right","0"),n(y,"width","20px"),n(y,"height","20px"),n(y,"cursor","nwse-resize"),n(y,"background","linear-gradient(135deg, transparent 50%, rgba(0,0,0,0.2) 50%)"),Te(),y})()})(),A,E),n(N,"width","100%"),n(N,"height","100%"),n(N,"overflow","auto"),$(N,re(Ke,{get component(){return f().Component},get settings(){return e.config.settings}})),H(_=>{var y=e.config.id,K=`${h().width}px`,ie=`${h().height}px`,ee=e.locked?"default":i()?"grabbing":"grab",te=i()||s()?"none":"box-shadow 0.2s",W=i()||s()?"0 8px 16px rgba(0,0,0,0.2)":"0 2px 4px rgba(0,0,0,0.1)",G=i()||s()?"100":"1";return y!==_.e&&ne(d,"data-widget-id",_.e=y),K!==_.t&&n(d,"width",_.t=K),ie!==_.a&&n(d,"height",_.a=ie),ee!==_.o&&n(d,"cursor",_.o=ee),te!==_.i&&n(d,"transition",_.i=te),W!==_.n&&n(d,"box-shadow",_.n=W),G!==_.s&&n(d,"z-index",_.s=G),_},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0}),d})()})}je(["click","mousedown"]);var It=C("<div style=pointer-events:none>"),Rt=C("<div style=border-radius:12px;box-sizing:border-box>");const ae={id:"simple",name:"Simple 2x2 Grid",description:"Basic 2x2 grid layout",width:800,height:600,background:"#1a1a1a",cells:[{id:"cell-1",x:10,y:10,width:385,height:285},{id:"cell-2",x:405,y:10,width:385,height:285},{id:"cell-3",x:10,y:305,width:385,height:285},{id:"cell-4",x:405,y:305,width:385,height:285}]};function Et(){return(()=>{var e=S(It);return n(e,"position","absolute"),$(e,()=>ae.cells.map(t=>(()=>{var r=S(Rt);return n(r,"position","absolute"),n(r,"border","2px dashed rgba(255, 255, 255, 0.2)"),n(r,"background","rgba(255, 255, 255, 0.03)"),H(i=>{var o=t.id,s=`${t.x}px`,a=`${t.y}px`,c=`${t.width}px`,l=`${t.height}px`;return o!==i.e&&ne(r,"data-grid-cell",i.e=o),s!==i.t&&n(r,"left",i.t=s),a!==i.a&&n(r,"top",i.a=a),c!==i.o&&n(r,"width",i.o=c),l!==i.i&&n(r,"height",i.i=l),i},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),r})())),H(t=>{var r=`${ae.width}px`,i=`${ae.height}px`,o=ae.background;return r!==t.e&&n(e,"width",t.e=r),i!==t.t&&n(e,"height",t.t=i),o!==t.a&&n(e,"background",t.a=o),t},{e:void 0,t:void 0,a:void 0}),e})()}var Lt=C("<div style=pointer-events:none>"),qt=C("<div style=border-radius:12px;box-sizing:border-box>");const le={id:"threeColumn",name:"Three Column Layout",description:"Sidebar, main content, and right panel",width:1200,height:800,background:"#1a1a1a",cells:[{id:"sidebar-left",x:10,y:10,width:200,height:780},{id:"main-top",x:220,y:10,width:760,height:380},{id:"main-bottom-left",x:220,y:400,width:370,height:390},{id:"main-bottom-right",x:600,y:400,width:380,height:390},{id:"panel-top",x:990,y:10,width:200,height:380},{id:"panel-bottom",x:990,y:400,width:200,height:390}]};function Pt(){return(()=>{var e=S(Lt);return n(e,"position","absolute"),$(e,()=>le.cells.map(t=>(()=>{var r=S(qt);return n(r,"position","absolute"),n(r,"border","2px dashed rgba(255, 255, 255, 0.2)"),n(r,"background","rgba(255, 255, 255, 0.03)"),H(i=>{var o=t.id,s=`${t.x}px`,a=`${t.y}px`,c=`${t.width}px`,l=`${t.height}px`;return o!==i.e&&ne(r,"data-grid-cell",i.e=o),s!==i.t&&n(r,"left",i.t=s),a!==i.a&&n(r,"top",i.a=a),c!==i.o&&n(r,"width",i.o=c),l!==i.i&&n(r,"height",i.i=l),i},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),r})())),H(t=>{var r=`${le.width}px`,i=`${le.height}px`,o=le.background;return r!==t.e&&n(e,"width",t.e=r),i!==t.t&&n(e,"height",t.t=i),o!==t.a&&n(e,"background",t.a=o),t},{e:void 0,t:void 0,a:void 0}),e})()}var At=C("<div style=pointer-events:none>"),Ft=C("<div style=border-radius:12px;box-sizing:border-box>");const se={id:"dashboard",name:"Dashboard Layout",description:"Professional dashboard with header and mixed sizes",width:1400,height:900,background:"#1a1a1a",cells:[{id:"header",x:10,y:10,width:1380,height:120},{id:"metric-1",x:10,y:140,width:330,height:200},{id:"metric-2",x:350,y:140,width:330,height:200},{id:"metric-3",x:690,y:140,width:330,height:200},{id:"metric-4",x:1030,y:140,width:360,height:200},{id:"chart-main",x:10,y:350,width:880,height:540},{id:"info-top",x:900,y:350,width:490,height:260},{id:"info-bottom",x:900,y:620,width:490,height:270}]};function Ht(){return(()=>{var e=S(At);return n(e,"position","absolute"),$(e,()=>se.cells.map(t=>(()=>{var r=S(Ft);return n(r,"position","absolute"),n(r,"border","2px dashed rgba(255, 255, 255, 0.2)"),n(r,"background","rgba(255, 255, 255, 0.03)"),H(i=>{var o=t.id,s=`${t.x}px`,a=`${t.y}px`,c=`${t.width}px`,l=`${t.height}px`;return o!==i.e&&ne(r,"data-grid-cell",i.e=o),s!==i.t&&n(r,"left",i.t=s),a!==i.a&&n(r,"top",i.a=a),c!==i.o&&n(r,"width",i.o=c),l!==i.i&&n(r,"height",i.i=l),i},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),r})())),H(t=>{var r=`${se.width}px`,i=`${se.height}px`,o=se.background;return r!==t.e&&n(e,"width",t.e=r),i!==t.t&&n(e,"height",t.t=i),o!==t.a&&n(e,"background",t.a=o),t},{e:void 0,t:void 0,a:void 0}),e})()}var Tt=C("<div style=pointer-events:none>"),Ot=C("<div style=border-radius:12px;box-sizing:border-box>");const de={id:"sidebarContent",name:"Sidebar Content Layout",description:"Two long sidebars with large content in middle",width:1400,height:900,background:"#1a1a1a",cells:[{id:"left-sidebar",x:10,y:10,width:280,height:880},{id:"main-content",x:300,y:10,width:800,height:880},{id:"right-sidebar",x:1110,y:10,width:280,height:880}]};function Ut(){return(()=>{var e=S(Tt);return n(e,"position","absolute"),$(e,()=>de.cells.map(t=>(()=>{var r=S(Ot);return n(r,"position","absolute"),n(r,"border","2px dashed rgba(255, 255, 255, 0.2)"),n(r,"background","rgba(255, 255, 255, 0.03)"),H(i=>{var o=t.id,s=`${t.x}px`,a=`${t.y}px`,c=`${t.width}px`,l=`${t.height}px`;return o!==i.e&&ne(r,"data-grid-cell",i.e=o),s!==i.t&&n(r,"left",i.t=s),a!==i.a&&n(r,"top",i.a=a),c!==i.o&&n(r,"width",i.o=c),l!==i.i&&n(r,"height",i.i=l),i},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),r})())),H(t=>{var r=`${de.width}px`,i=`${de.height}px`,o=de.background;return r!==t.e&&n(e,"width",t.e=r),i!==t.t&&n(e,"height",t.t=i),o!==t.a&&n(e,"background",t.a=o),t},{e:void 0,t:void 0,a:void 0}),e})()}var Nt=C("<div style=pointer-events:none>"),Wt=C("<div style=border-radius:12px;box-sizing:border-box>");const ce={id:"centeredFocus",name:"Centered Focus Layout",description:"2 center items with left sidebar boxes and tall right panel",width:1520,height:760,background:"#1a1a1a",cells:[{id:"left-top",x:10,y:10,width:390,height:340},{id:"left-bottom",x:10,y:360,width:390,height:390},{id:"center-top",x:410,y:10,width:760,height:250},{id:"center-bottom",x:410,y:270,width:760,height:480},{id:"right-tall",x:1180,y:10,width:330,height:740}]};function Xt(){return(()=>{var e=S(Nt);return n(e,"position","absolute"),$(e,()=>ce.cells.map(t=>(()=>{var r=S(Wt);return n(r,"position","absolute"),n(r,"border","2px dashed rgba(255, 255, 255, 0.2)"),n(r,"background","rgba(255, 255, 255, 0.03)"),H(i=>{var o=t.id,s=`${t.x}px`,a=`${t.y}px`,c=`${t.width}px`,l=`${t.height}px`;return o!==i.e&&ne(r,"data-grid-cell",i.e=o),s!==i.t&&n(r,"left",i.t=s),a!==i.a&&n(r,"top",i.a=a),c!==i.o&&n(r,"width",i.o=c),l!==i.i&&n(r,"height",i.i=l),i},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),r})())),H(t=>{var r=`${ce.width}px`,i=`${ce.height}px`,o=ce.background;return r!==t.e&&n(e,"width",t.e=r),i!==t.t&&n(e,"height",t.t=i),o!==t.a&&n(e,"background",t.a=o),t},{e:void 0,t:void 0,a:void 0}),e})()}const Ge={simple:{template:ae,Component:Et},threeColumn:{template:le,Component:Pt},dashboard:{template:se,Component:Ht},sidebarContent:{template:de,Component:Ut},centeredFocus:{template:ce,Component:Xt}};function Qt(e){return Ge[e]}function Bt(){return Object.values(Ge)}export{Gt as W,Qt as a,Bt as g,pt as w};
|