epic-modals 0.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.
Files changed (46) hide show
  1. package/LICENSE +93 -0
  2. package/README.md +287 -0
  3. package/dist/core/config.svelte.d.ts +85 -0
  4. package/dist/core/index.d.ts +6 -0
  5. package/dist/core/stacking.svelte.d.ts +19 -0
  6. package/dist/core/state.svelte.d.ts +321 -0
  7. package/dist/core/types.d.ts +98 -0
  8. package/dist/core/viewport.d.ts +92 -0
  9. package/dist/core/viewport.test.d.ts +2 -0
  10. package/dist/epic-modals.css +9 -0
  11. package/dist/index.d.ts +2 -0
  12. package/dist/index.js +1 -0
  13. package/dist/react/Dock.d.ts +13 -0
  14. package/dist/react/Modal.d.ts +11 -0
  15. package/dist/react/ModalProvider.d.ts +11 -0
  16. package/dist/react/context.d.ts +4 -0
  17. package/dist/react/index.d.ts +15 -0
  18. package/dist/react/svelte-bridge.d.ts +18 -0
  19. package/dist/react/useModal.d.ts +27 -0
  20. package/dist/react/useModalZIndex.d.ts +35 -0
  21. package/dist/react.d.ts +11 -0
  22. package/dist/react.js +1 -0
  23. package/dist/styles/animations.css +1 -0
  24. package/dist/styles/dock.css +1 -0
  25. package/dist/styles/index.css +1 -0
  26. package/dist/styles/modal.css +1 -0
  27. package/dist/styles/themes/dark.css +1 -0
  28. package/dist/styles/themes/light.css +1 -0
  29. package/dist/styles/variables.css +1 -0
  30. package/dist/svelte/context.d.ts +8 -0
  31. package/dist/svelte/hooks/index.d.ts +13 -0
  32. package/dist/svelte/hooks/useFocusTrap.svelte.d.ts +20 -0
  33. package/dist/svelte/hooks/useModal.svelte.d.ts +41 -0
  34. package/dist/svelte/hooks/useModalAnimation.svelte.d.ts +16 -0
  35. package/dist/svelte/hooks/useModalDrag.svelte.d.ts +16 -0
  36. package/dist/svelte/hooks/useModalResize.svelte.d.ts +18 -0
  37. package/dist/svelte/hooks/useModalZIndex.svelte.d.ts +30 -0
  38. package/dist/svelte/hooks/usePortal.svelte.d.ts +13 -0
  39. package/dist/svelte/hooks/useWindowEvent.svelte.d.ts +12 -0
  40. package/dist/svelte/index.d.ts +14 -0
  41. package/dist/svelte.d.ts +10 -0
  42. package/dist/svelte.js +1 -0
  43. package/dist/vanilla/index.d.ts +51 -0
  44. package/dist/vanilla.d.ts +10 -0
  45. package/dist/vanilla.js +1 -0
  46. package/package.json +89 -0
package/dist/svelte.js ADDED
@@ -0,0 +1 @@
1
+ import*as e from"svelte/internal/client";import"svelte/internal/disclose-version";import{getContext as t,onMount as n,setContext as i,tick as o,onDestroy as r,untrack as s}from"svelte";import{scale as d,fly as a,fade as l}from"svelte/transition";import{cubicOut as c,backOut as g}from"svelte/easing";const u={BASE:0,DROPDOWN:100,STICKY:200,OVERLAY:300,MODAL:400,DOCK:8e3,TOAST:9e3};let h=e.state(e.proxy(u.MODAL));function p(){e.set(h,ft().zIndex.base,!0)}function f(){const t=e.get(h);return e.set(h,e.get(h)+2),t}function m(e){const t=ft();return"MODAL"===e?t.zIndex.base:"DOCK"===e?t.zIndex.dock:"TOAST"===e?t.zIndex.toast:u[e]}function v(){e.set(h,ft().zIndex.base,!0)}const w=8;function y(e,t,n,i,o={}){const{margin:r=w,allowPartialVisibility:s=!1}=o,d="undefined"!=typeof window?window.innerWidth:1920,a="undefined"!=typeof window?window.innerHeight:1080;let l,c,g,u;return s&&n>d-2*r?(l=40-n,c=d-40):(l=r,c=Math.max(r,d-n-r)),s&&i>a-2*r?(g=40-i,u=a-40):(g=r,u=Math.max(r,a-i-r)),{x:Math.max(l,Math.min(c,e)),y:Math.max(g,Math.min(u,t))}}function x(e,t,n,i,o={}){const{margin:r=w}=o,s=("undefined"!=typeof window?window.innerWidth:1920)-2*r,d=("undefined"!=typeof window?window.innerHeight:1080)-2*r,a=Math.min(n,s),l=Math.min(i,d),c=y(e,t,a,l,o);return{x:c.x,y:c.y,width:a,height:l}}function z(e,t){return Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x))*Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y))}function I(e,t,n,i,o,r){const s={x:e-r,y:t-r,width:n+2*r,height:i+2*r};let d=0;for(const e of o)d+=z(s,e);return d}function b(e){if("undefined"==typeof document)return[];const t=[];for(const n of e)try{const e=document.querySelectorAll(n);for(const n of e){const e=n.getBoundingClientRect();e.width>0&&e.height>0&&t.push({x:e.left,y:e.top,width:e.width,height:e.height})}}catch{}return t}function _(e,t,n,i,o,r,s){const d=(o-n)/2,a=(r-i)/2,l=d-s,c=a-s,g=Math.abs(e-d)/(l||1),u=Math.abs(t-a)/(c||1),h=Math.sqrt(g*g+u*u)/Math.SQRT2,p=50,f=e-s,m=o-n-s-e,v=t-s,w=r-i-s-t;let y=0;return f<p&&(y+=.3*(1-f/p)),m<p&&(y+=.3*(1-m/p)),v<p&&(y+=.2*(1-v/p)),w<p&&(y+=.2*(1-w/p)),Math.min(1,h+y)}function M(e,t,n,i={}){const{modalGap:o=16,gridResolution:r=10,avoidBounds:s=[],avoidMargin:d=16}=i,a=i.margin??o,l="undefined"!=typeof window?window.innerWidth:1920,c="undefined"!=typeof window?window.innerHeight:1080,g=s.map(e=>({x:e.x-d,y:e.y-d,width:e.width+2*d,height:e.height+2*d})),u={x:(l-e)/2,y:(c-t)/2};if(0===n.length&&0===g.length)return u;const h=a,p=Math.max(a,l-e-a),f=a,m=Math.max(a,c-t-a);if(p<=h||m<=f)return u;const v=I(u.x,u.y,e,t,n,o),w=I(u.x,u.y,e,t,g,0);if(0===v&&0===w)return u;const y=[],x=(p-h)/r,z=(m-f)/r;for(let i=0;i<=r;i++)for(let s=0;s<=r;s++){const r=h+i*x,d=f+s*z,u=I(r,d,e,t,n,o),p=I(r,d,e,t,g,0),m=_(r,d,e,t,l,c,a);y.push({pos:{x:r,y:d},modalOverlap:u,avoidOverlap:p,centerDist:m})}const b=y.filter(e=>0===e.avoidOverlap),M=b.length>0?b:y,k=e*t,D=Math.min(...M.map(e=>e.modalOverlap))/k;return M.sort((e,t)=>{if(0===b.length&&e.avoidOverlap!==t.avoidOverlap)return e.avoidOverlap-t.avoidOverlap;const n=e.modalOverlap/k,i=t.modalOverlap/k;if(D<.3){const o=.3,r=n<=o,s=i<=o;if(r&&s)return e.centerDist+.3*n-(t.centerDist+.3*i);if(r)return-1;if(s)return 1}return.6*n+.4*e.centerDist-(.6*i+.4*t.centerDist)}),M[0].pos}function k(e,t,n,i={}){const{modalGap:o=16}=i,r=i.margin??o,s="undefined"!=typeof window?window.innerWidth:1920,d="undefined"!=typeof window?window.innerHeight:1080,a=n.reduce((e,t)=>e+t.width,0)+e,l=n.length*o,c=s-2*r;if(a+l>c)return null;const g=c-a-l;n.length;const u=g/2,h=s/2,p=[...n.map(e=>({id:e.id,width:e.width,height:e.height,currentX:e.x+e.width/2,currentY:e.y,isNew:!1})),{id:"__new__",width:e,height:t,currentX:h,currentY:(d-t)/2,isNew:!0}];p.sort((e,t)=>e.currentX-t.currentX);let f=r+u;const m=new Map;let v=null;for(const e of p){const t=f;if(e.isNew)v={x:Math.round(t),y:Math.round(e.currentY)};else{const i=n.find(t=>t.id===e.id);Math.abs(t-i.x)>5&&m.set(e.id,{x:Math.round(t),y:Math.round(i.y)})}f+=e.width+o}return v?{newModalPosition:v,existingModalMoves:m}:null}let D=e.proxy(new Map),P=e.state(0);const C=new Set;function B(){e.update(P),queueMicrotask(()=>{C.forEach(e=>e())})}function O(e){return C.add(e),()=>C.delete(e)}let T=e.state(e.proxy([])),R=e.state(e.proxy([])),E=e.state(e.proxy([])),S=e.state(e.proxy([])),H=e.state(e.proxy([])),F=e.state(e.proxy([])),L=e.state(e.proxy([])),W=e.state(e.proxy([])),A=e.state(null),$=e.proxy(new Map),X=e.state(null),Y=e.proxy(new Map),q=e.proxy(new Set),N=e.proxy(new Set),j=e.state(e.proxy([])),G=null,K=null;function V(t){const n=D.get(t.id),i=(null==n?void 0:n.zIndex)??f();n?D.set(t.id,{...n,title:t.title,icon:t.icon,glow:t.glow,zIndex:i}):D.set(t.id,{...t,zIndex:i,isAnimating:!1}),B(),t.isMinimized&&!e.get(j).includes(t.id)&&e.get(j).push(t.id)}function U(t){const n=D.get(t);if(n){if(e.set(j,e.get(j).filter(e=>e!==t),!0),n.childId){const e=D.get(n.childId);e&&D.set(n.childId,{...e,parentId:void 0})}if(n.parentId){const e=D.get(n.parentId);e&&D.set(n.parentId,{...e,childId:void 0,lastChildId:n.id})}D.delete(t),B(),N.delete(t),q.delete(t)}}function Q(t){const n=D.get(t);if(!n||n.isMinimized)return;if(it(t),n.parentId){const e=D.get(n.parentId);if(e&&!e.isMinimized)return void Q(n.parentId)}if(e.set(T,[...e.get(T),t],!0),n.position&&n.size&&K){const i=K(),o=e.get(j).indexOf(t),r=i.x+o*(i.height+8),s=i.y;e.set(A,{x:r,y:s,originX:n.position.x+n.size.width/2,originY:n.position.y+n.size.height/2},!0)}const i=n.childId;D.set(t,{...n,isMinimized:!0,lastChildId:i}),B(),e.get(j).includes(t)||e.get(j).push(t),n.childId&&fe(t)}function Z(t){const n=D.get(t);if(!n||!n.isMinimized)return;D.set(t,{...n,isMinimized:!1,isOpen:!0}),B(),e.set(H,[...e.get(H),t],!0),oe(t);const i=n.lastChildId||n.childId;i&&ee(i)}function J(){Array.from(D.values()).filter(e=>e.isMinimized).map(e=>e.id).forEach(t=>{const n=D.get(t);if(n){D.set(t,{...n,isMinimized:!1,isOpen:!0}),e.set(H,[...e.get(H),t],!0),oe(t);const i=n.lastChildId||n.childId;i&&ee(i)}}),e.set(j,[],!0),B()}function ee(t){const n=D.get(t);n&&n.isHiddenWithParent&&(D.set(t,{...n,isHiddenWithParent:!1}),B(),e.set(F,[...e.get(F),t],!0))}function te(e,t,n){const i=D.get(e);if(!i)return;let o=t;if((null==n?void 0:n.constrain)&&i.size&&(o=y(t.x,t.y,i.size.width,i.size.height)),D.set(e,{...i,position:o,size:(null==n?void 0:n.size)??i.size,hasBeenDragged:i.hasBeenDragged||(null==n?void 0:n.drag)||!1}),i.childId){let t=e,n=o;for(;;){const e=D.get(t);if(!(null==e?void 0:e.childId))break;const i=D.get(e.childId);if(!(null==i?void 0:i.offsetFromParent))break;const o={x:n.x+i.offsetFromParent.x,y:n.y+i.offsetFromParent.y};D.set(e.childId,{...i,position:o,hasBeenDragged:!0}),t=e.childId,n=o}}if(i.parentId&&i.offsetFromParent){const t=ft();let n=e,r=i;for(;r.parentId&&r.offsetFromParent;){const i=D.get(r.parentId);if(!i)break;const s=n===e?o:D.get(n).position,d={x:s.x-r.offsetFromParent.x,y:s.y-r.offsetFromParent.y};"animated"===t.parentChild.movementMode?Y.set(r.parentId,d):D.set(r.parentId,{...i,position:d,hasBeenDragged:!0}),n=r.parentId,r=i}}B()}function ne(e,t){const n=D.get(e);n&&(D.set(e,{...n,size:t}),B())}function ie(e,t){const n=D.get(e);n&&(D.set(e,{...n,...t}),B())}function oe(e){var t;const n=D.get(e);if(!n)return;const i=Math.max(...Array.from(D.values()).map(e=>e.zIndex),0);if(n.parentId){const o=D.get(n.parentId);o&&o.zIndex<i&&D.set(n.parentId,{...o,zIndex:i+2});const r=(null==(t=D.get(n.parentId))?void 0:t.zIndex)??i+2;return n.zIndex<=r&&D.set(e,{...n,zIndex:r+2}),void B()}if(n.zIndex<i&&(D.set(e,{...n,zIndex:i+2}),B()),n.childId){const t=D.get(n.childId),i=D.get(e);t&&i&&t.zIndex<=i.zIndex&&(D.set(n.childId,{...t,zIndex:i.zIndex+2}),B())}}function re(e){const t=D.get(e);if(!t)return!1;const n=Math.max(...Array.from(D.values()).map(e=>e.zIndex),0);return t.zIndex===n&&!t.isMinimized&&!t.isHiddenWithParent}function se(t){e.set(j,t,!0)}function de(t,n,i){const o=n.getBoundingClientRect();$.set(t,{x:o.left+o.width/2,y:o.top+o.height/2});const r=ft();(null==i?void 0:i.parentId)&&r.features.parentChild&&e.set(X,{parentId:i.parentId,childId:t},!0),e.get(R).includes(t)||e.set(R,[...e.get(R),t],!0),B();const s=D.get(t);if(s){if(s.isOpen&&!s.isMinimized&&!s.isHiddenWithParent)return e.set(R,e.get(R).filter(e=>e!==t),!0),We(t),void oe(t);if(s.isMinimized)return e.set(R,e.get(R).filter(e=>e!==t),!0),void Z(t);D.set(t,{...s,isOpen:!0}),oe(t),null==G||G.push(t)}}function ae(t){V(t);const n=D.get(t.id);n&&(D.set(t.id,{...n,isOpen:!0}),B()),e.set(R,[...e.get(R),t.id],!0),B(),oe(t.id),null==G||G.push(t.id)}function le(t,n=!1){const i=D.get(t);i&&(it(t),n?e.set(S,[...e.get(S),t],!0):e.set(E,[...e.get(E),t],!0),B(),i.childId&&le(i.childId,n),null==G||G.pop())}function ce(){Array.from(D.keys()).forEach(e=>le(e,!0))}function ge(e){const t=D.get(e);if(t){if(t.parentId){const n=D.get(t.parentId);n&&n.childId===e&&D.set(t.parentId,{...n,childId:void 0,lastChildId:e})}D.set(e,{...t,isOpen:!1,isMinimized:!1,isHiddenWithParent:!1,isTransparent:!1,position:null,size:null,hasBeenDragged:!1,parentId:void 0,childId:void 0,offsetFromParent:void 0}),B()}}function ue(e){const t=D.get(e);if(!t)return[e];const n=[e];return t.childId&&n.push(...ue(t.childId)),n}function he(t,n,i){const o=ft();if(i&&!$.has(t.id)){const e=i.getBoundingClientRect();$.set(t.id,{x:e.left+e.width/2,y:e.top+e.height/2})}const r={id:t.id,title:t.title??"",icon:t.icon??"",isOpen:!0,isMinimized:!1,isHiddenWithParent:!1,isTransparent:t.isTransparent??!1,isRejected:!1,position:t.position??null,size:t.size??null,hasBeenDragged:t.hasBeenDragged??!1,dockPosition:t.dockPosition??-1,glow:t.glow??null};if(!o.features.parentChild){V(r);const n=D.get(t.id);return n&&D.set(t.id,{...n,isOpen:!0}),e.set(R,[...e.get(R),t.id],!0),B(),void oe(t.id)}const s=D.get(n);if(!s)return;s.childId&&le(s.childId,!0),V({...r,parentId:n});const d=D.get(t.id);d&&D.set(t.id,{...d,isOpen:!0,parentId:n}),e.set(R,[...e.get(R),t.id],!0),B(),oe(t.id),e.set(X,{parentId:n,childId:t.id},!0)}function pe(e,t){if(!ft().features.parentChild)return;const n=D.get(e),i=D.get(t);if(!n||!i)return;let o={x:40,y:40};n.position&&i.position&&(o={x:i.position.x-n.position.x,y:i.position.y-n.position.y});const r=Math.max(i.zIndex,n.zIndex+1);D.set(e,{...n,childId:t,lastChildId:t}),D.set(t,{...i,parentId:e,offsetFromParent:o,zIndex:r}),B()}function fe(e){const t=D.get(e);if(!(null==t?void 0:t.childId))return;const n=D.get(t.childId);n&&(D.set(t.childId,{...n,isHiddenWithParent:!0}),B())}function me(e,t){const n=D.get(e);if(!(null==n?void 0:n.childId))return;const i=D.get(n.childId);if(!i||!i.offsetFromParent)return;const o={x:t.x+i.offsetFromParent.x,y:t.y+i.offsetFromParent.y};D.set(n.childId,{...i,position:o}),B()}function ve(e,t){const n=D.get(e),i=D.get(t);if(!(null==n?void 0:n.position)||!(null==i?void 0:i.position))return;const o={x:n.position.x-i.position.x,y:n.position.y-i.position.y};D.set(e,{...n,offsetFromParent:o}),B()}function we(t){return e.get(T).includes(t)}function ye(t){return!!e.get(T).includes(t)&&(e.set(T,e.get(T).filter(e=>e!==t),!0),!0)}function xe(){return e.get(T).length>0}function ze(){return Array.from(D.keys())}function Ie(e){return D.get(e)}function be(e){const t=[];for(const[n,i]of D.entries())if(n!==e&&i.isOpen&&!i.isMinimized&&!i.isHiddenWithParent&&!i.parentId)if(i.position&&i.size)t.push({id:String(n),x:i.position.x,y:i.position.y,width:i.size.width,height:i.size.height});else{const e=document.querySelector(`[data-modal-id="${String(n)}"]`);if(e){const i=e.getBoundingClientRect();t.push({id:String(n),x:i.left,y:i.top,width:i.width,height:i.height})}}return t}function _e(e){const t=[];for(const[n,i]of D.entries())if(n!==e&&i.isOpen&&!i.isMinimized&&!i.isHiddenWithParent)if(i.position&&i.size)t.push({x:i.position.x,y:i.position.y,width:i.size.width,height:i.size.height});else{const e=document.querySelector(`[data-modal-id="${String(n)}"]`);if(e){const n=e.getBoundingClientRect();t.push({x:n.left,y:n.top,width:n.width,height:n.height})}}return t}function Me(){return e.get(P)}function ke(){const t=e.get(A);return e.set(A,null),t}function De(t){return e.get(R).includes(t)}function Pe(t){return!!e.get(R).includes(t)&&(e.set(R,e.get(R).filter(e=>e!==t),!0),!0)}function Ce(t){return e.get(E).includes(t)}function Be(t){return!!e.get(E).includes(t)&&(e.set(E,e.get(E).filter(e=>e!==t),!0),!0)}function Oe(t){return e.get(S).includes(t)}function Te(t){return!!e.get(S).includes(t)&&(e.set(S,e.get(S).filter(e=>e!==t),!0),!0)}function Re(t){return e.get(H).includes(t)}function Ee(t){return!!e.get(H).includes(t)&&(e.set(H,e.get(H).filter(e=>e!==t),!0),!0)}function Se(t){return e.get(F).includes(t)}function He(t){return!!e.get(F).includes(t)&&(e.set(F,e.get(F).filter(e=>e!==t),!0),!0)}function Fe(t){return e.get(L).includes(t)}function Le(t){return!!e.get(L).includes(t)&&(e.set(L,e.get(L).filter(e=>e!==t),!0),!0)}function We(t){D.get(t)&&(e.get(L).includes(t)||e.get(W).includes(t)||(e.set(L,[...e.get(L),t],!0),B()))}function Ae(t){e.get(W).includes(t)||e.set(W,[...e.get(W),t],!0)}function $e(t){e.set(W,e.get(W).filter(e=>e!==t),!0)}function Xe(){return e.get(X)}function Ye(t){if(!e.get(X)||e.get(X).childId!==t)return null;const n=e.get(X);return e.set(X,null),n}function qe(e,t){$.set(e,t)}function Ne(e){const t=$.get(e);return t&&$.delete(e),t??null}function je(e,t){t?q.add(e):q.delete(e)}function Ge(e){return q.has(e)}function Ke(e){const t=D.get(e);return void 0!==t&&t.isOpen&&!t.isMinimized&&!t.isHiddenWithParent}function Ve(e){return D.has(e)}function Ue(){return{get modals(){return D},get pendingMinimize(){return e.get(T)},get pendingOpen(){return e.get(R)},get pendingClose(){return e.get(E)},get pendingRestore(){return e.get(H)},get dockOrder(){return e.get(j)}}}function Qe(e){N.has(e)?N.delete(e):N.add(e);const t=D.get(e);t&&(D.set(e,{...t,isTransparent:N.has(e)}),B())}function Ze(e){N.delete(e);const t=D.get(e);t&&(D.set(e,{...t,isTransparent:!1}),B())}function Je(e){e.animate([{transform:"translateX(0)"},{transform:"translateX(-6px)"},{transform:"translateX(6px)"},{transform:"translateX(-6px)"},{transform:"translateX(6px)"},{transform:"translateX(0)"}],{duration:300,easing:"ease-in-out"})}function et(e){const t=Y.get(e);if(!t)return;const n=D.get(e);n&&(D.set(e,{...n,isAnimatingPosition:!0,position:t}),Y.delete(e),B())}function tt(e){const t=D.get(e);t&&(D.set(e,{...t,isAnimatingPosition:!1}),B())}function nt(e){return Y.has(e)}function it(e){Y.delete(e)}function ot(e){const t=ft().parentChild.animationDuration;for(const[t,n]of e){const e=D.get(t);e&&D.set(t,{...e,position:n,isAnimatingPosition:!0,hasBeenDragged:!0})}B(),setTimeout(()=>{for(const t of e.keys()){const e=D.get(t);e&&D.set(t,{...e,isAnimatingPosition:!1})}B()},t)}function rt(e){const t=ft();if("animated"!==t.parentChild.movementMode)return;const n=t.parentChild.animationDuration,i=[];let o=e;for(;;){const e=D.get(o);if(!(null==e?void 0:e.parentId))break;i.push({parentId:e.parentId,childId:o}),o=e.parentId}i.forEach(({parentId:e,childId:t},i)=>{setTimeout(()=>{const i=D.get(t),o=D.get(e);if(!(null==i?void 0:i.position)||!i.offsetFromParent||!o)return;const r={x:i.position.x-i.offsetFromParent.x,y:i.position.y-i.offsetFromParent.y};Y.set(e,r),et(e),setTimeout(()=>tt(e),n)},i*n)})}function st(e){}function dt(e){G=e}function at(e){K=e}function lt(){return{modals:D,pendingMinimize:e.get(T),pendingOpen:e.get(R),pendingClose:e.get(E),pendingRestore:e.get(H),dockOrder:e.get(j),animatingModals:q,transparentModals:N}}function ct(){D.clear(),e.get(T).length=0,e.get(R).length=0,e.get(E).length=0,e.get(S).length=0,e.get(H).length=0,e.get(F).length=0,e.set(A,null),$.clear(),e.set(X,null),Y.clear(),q.clear(),N.clear(),e.get(j).length=0,G=null,K=null}const gt={features:{dock:!0,minimize:!0,transparency:!0,resize:!0,drag:!0,focusTrap:!0,animations:!0,backdrop:!0,parentChild:!0},dock:{position:"bottom",labelMode:"beside",enableReorder:!0,enableFreeDrag:!0},animations:{open:400,close:250,minimize:500,restore:400},appearance:{headerLayout:"macos",defaultWidth:"480px",defaultHeight:"auto",minWidth:280,minHeight:200},zIndex:{base:400,dock:8e3,toast:9e3},parentChild:{movementMode:"animated",animationDuration:300},positioning:{strategy:"smart",modalGap:16,avoidElements:[]},portalTarget:"#modal-portal"};let ut={...gt},ht=e.state(0);function pt(){return e.get(ht)}function ft(){return ut}function mt(t){const n=ut;ut=wt(gt,t),e.update(ht),n.features.dock&&!ut.features.dock&&J()}function vt(){ut={...gt},e.update(ht)}function wt(e,t){return{features:{...e.features,...t.features},dock:{...e.dock,...t.dock},animations:{...e.animations,...t.animations},appearance:{...e.appearance,...t.appearance},zIndex:{...e.zIndex,...t.zIndex},parentChild:{...e.parentChild,...t.parentChild},positioning:{...e.positioning,...t.positioning},portalTarget:t.portalTarget??e.portalTarget}}function yt(e){return ut.features[e]}const xt=Symbol("modal-render-icon"),zt=Symbol("modal-id");function It(e,t){if(!Ve(e))throw new Error(`Cannot call ${t}() on unregistered modal "${String(e)}". Ensure the Modal component is rendered.`)}function bt(e){return{shake:()=>{It(e,"shake"),We(e)},bringToFront:()=>{It(e,"bringToFront"),oe(e)},isOpen:()=>Ke(e),isRegistered:()=>Ve(e),open:t=>{It(e,"open"),de(e,t)},close:()=>{It(e,"close"),le(e)},minimize:()=>{It(e,"minimize"),Q(e)},restore:()=>{It(e,"restore"),Z(e)},openChild:(t,n)=>{It(e,"openChild"),he({id:t},e,n)}}}function _t(t={x:0,y:0}){const n=e.proxy({...t}),i=e.proxy({isDragging:!1,startX:0,startY:0,initialX:0,initialY:0,hasBeenDragged:!1});return{get position(){return n},get hasBeenDragged(){return i.hasBeenDragged},get isDragging(){return i.isDragging},onPointerDown:function(e,t){if(0===e.button){if(!i.hasBeenDragged){const e=t.getBoundingClientRect();n.x=e.left,n.y=e.top}i.isDragging=!0,i.startX=e.clientX,i.startY=e.clientY,i.initialX=n.x,i.initialY=n.y,t.setPointerCapture(e.pointerId)}},onPointerMove:function(e,t,o){if(!i.isDragging)return;const r=e.clientX-i.startX,s=e.clientY-i.startY,d=y(i.initialX+r,i.initialY+s,o.width,o.height);n.x=d.x,n.y=d.y,i.hasBeenDragged=!0},onPointerUp:function(e,t){i.isDragging&&(i.isDragging=!1,t.releasePointerCapture(e.pointerId))},setPosition:function(e){n.x=e.x,n.y=e.y},setHasBeenDragged:function(e){i.hasBeenDragged=e},reset:function(){n.x=t.x,n.y=t.y,i.hasBeenDragged=!1}}}function Mt(t,n,i,o,r,s,d){let a=e.state(!1),l=e.state(""),c=e.state(e.proxy({width:0,height:0})),g=e.state(!1),u=e.state(!1),h={x:0,y:0,width:0,height:0,posX:0,posY:0,centerX:0,centerY:0},p=null;function f(s,d){s.preventDefault(),s.stopPropagation();const u=t();if(!u)return;const f=u.getBoundingClientRect();o()||(i({x:f.left,y:f.top}),r(!0)),e.get(g)||(e.set(c,{width:f.width,height:f.height},!0),e.set(g,!0));const w=n();e.set(a,!0),e.set(l,d,!0),p=s.pointerId,h={x:s.clientX,y:s.clientY,width:e.get(c).width,height:e.get(c).height,posX:w.x,posY:w.y,centerX:w.x+e.get(c).width/2,centerY:w.y+e.get(c).height/2},window.addEventListener("pointermove",m),window.addEventListener("pointerup",v),window.addEventListener("pointercancel",v)}function m(t){if(t.pointerId!==p)return;const n=t.clientX-h.x,o=t.clientY-h.y,r=window.innerWidth,s=window.innerHeight,a=(null==d?void 0:d())??!1;let g=h.width,u=h.height,f=h.posX,m=h.posY;if(a){if(e.get(l).includes("e")||e.get(l).includes("w")){const t=e.get(l).includes("e")?n:-n;g=Math.max(280,h.width+2*t),f=h.centerX-g/2}if(e.get(l).includes("s")||e.get(l).includes("n")){const t=e.get(l).includes("s")?o:-o;u=Math.max(200,h.height+2*t),m=h.centerY-u/2}}else{if(e.get(l).includes("e")){const e=r-f;g=Math.max(280,Math.min(h.width+n,e))}if(e.get(l).includes("w")){const e=h.width-280,t=Math.min(n,e);g=h.width-t,f=h.posX+t}if(e.get(l).includes("s")){const e=s-m;u=Math.max(200,Math.min(h.height+o,e))}if(e.get(l).includes("n")){const e=h.height-200,t=Math.min(o,e);u=h.height-t,m=h.posY+t}}const v=x(f,m,g,u);e.set(c,{width:v.width,height:v.height},!0),i({x:v.x,y:v.y})}function v(t){t.pointerId===p&&(e.set(a,!1),p=null,window.removeEventListener("pointermove",m),window.removeEventListener("pointerup",v),window.removeEventListener("pointercancel",v),e.set(u,!0),s(n(),e.get(c)),setTimeout(()=>{e.set(u,!1)},0))}const w={startResize:f};return{get isResizing(){return e.get(a)},get resizeDirection(){return e.get(l)},get size(){return e.get(c)},get hasBeenResized(){return e.get(g)},get isActive(){return e.get(a)},get justFinishedResizing(){return e.get(u)},start:f,setHasBeenResized:()=>{},setSize:function(t){e.set(c,t,!0),e.set(g,!0)},reset:function(){e.set(g,!1),e.set(c,{width:0,height:0},!0)},constrainToViewport:function(){const o=n(),r=t();if(!r)return;const s=x(o.x,o.y,e.get(c).width||r.offsetWidth,e.get(c).height||r.offsetHeight);e.set(c,{width:s.width,height:s.height},!0),i({x:s.x,y:s.y})},handlers:w}}function kt(){return ft().features.animations}function Dt(t,n,i,o,r,s,d,a,l){let c=e.state(!1),g=e.state(!1),u=e.state(!1),h=e.state(!1),p=e.state(null),f=e.state(null),m=null,v=null;function w(){v&&(clearTimeout(v),v=null)}function y(){const e=t(),n=document.querySelector(`.modal-dock-item[data-modal-id="${e}"]`),i=document.querySelector('[data-dock-container="true"]'),o=n||i;if(o){const e=o.getBoundingClientRect();return{x:e.left+e.width/2,y:e.top+e.height/2}}return{x:window.innerWidth/2,y:window.innerHeight-40}}return e.user_effect(()=>()=>{w(),e.set(c,!1),e.set(g,!1),e.set(u,!1),e.set(h,!1),e.set(p,null),e.set(f,null),m=null}),{get isMinimizing(){return e.get(c)},get isRestoring(){return e.get(g)},get isOpening(){return e.get(u)},get isClosing(){return e.get(h)},get animationTransform(){return e.get(p)},get pendingOpenSource(){return e.get(f)},startMinimize:function(t,h){const f=n();if(e.get(c)||!f)return;if(e.set(g,!1),e.set(u,!1),w(),!kt()){const e=f.getBoundingClientRect();let t=r()?i():{x:e.left,y:e.top},n=d()?a():{width:e.width,height:e.height};return r()||(o(t),s(!0)),void(h?h():l(t,!0,n))}const m=f.getBoundingClientRect(),x=m.left+m.width/2,z=m.top+m.height/2;let I=r()?i():{x:m.left,y:m.top},b=d()?a():{width:m.width,height:m.height};r()||(o(I),s(!0));const _=t??y(),M=_.x-m.left,k=_.y-m.top,D={x:_.x-x,y:_.y-z,originX:M,originY:k};e.set(p,D,!0),requestAnimationFrame(()=>{requestAnimationFrame(()=>{e.set(c,!0)})}),v=setTimeout(()=>{h?h():l(I,!0,b)},500)},startRestore:function(t,n){if(!kt()){const e=t||{x:window.innerWidth/2,y:window.innerHeight/2};return o(e),void s(!0)}const i=y(),r=t||{x:window.innerWidth/2,y:window.innerHeight/2},d=n||{width:480,height:400};o(r),s(!0);const a=r.x+d.width/2,l=r.y+d.height/2,c=i.x-r.x,u=i.y-r.y;e.set(p,{x:i.x-a,y:i.y-l,originX:c,originY:u},!0),e.set(g,!0),setTimeout(()=>{e.set(g,!1),e.set(p,null)},400)},startClose:function(t){e.get(h)||e.get(c)||(kt()?(m=t,e.set(h,!0),setTimeout(()=>{e.set(h,!1),m&&(m(),m=null)},250)):t())},setPendingOpenSource:function(t){e.set(f,t,!0)},tryStartOpenAnimation:function(){const t=n();if(!e.get(f)||!t||e.get(u))return!1;if(!kt())return e.set(f,null),!1;const d=e.get(f);e.set(f,null);const a=t.getBoundingClientRect(),l=r()?i():{x:a.left,y:a.top},c=a.width,g=a.height,h=l.x+c/2,m=l.y+g/2;r()||(o(l),s(!0));const v=d.x-l.x,w=d.y-l.y;return e.set(p,{x:d.x-h,y:d.y-m,originX:v,originY:w},!0),e.set(u,!0),setTimeout(()=>{e.set(u,!1),e.set(p,null)},400),!0},forceClearMinimize:function(){w(),e.set(c,!1),e.set(p,null)}}}const Pt=["button:not([disabled])","[href]","input:not([disabled])","select:not([disabled])","textarea:not([disabled])",'[tabindex]:not([tabindex="-1"])'].join(", ");function Ct(e){return Array.from(e.querySelectorAll(Pt)).filter(e=>null!==e.offsetParent||"A"===e.tagName)}function Bt(e,t){if("Tab"!==e.key)return;const n=Ct(t);if(0===n.length)return void e.preventDefault();const i=n[0],o=n[n.length-1],r=document.activeElement;e.shiftKey?r===i&&(o.focus(),e.preventDefault()):r===o&&(i.focus(),e.preventDefault())}function Ot(e){const t=Ct(e);return t.length>0&&(t[0].focus(),!0)}function Tt(){return{trapFocus:Bt,focusFirstElement:Ot}}const Rt="modal-portal";function Et(){return{mount:function(e,t=null){const n=function(e){if("undefined"==typeof window)return null;if(e instanceof HTMLElement)return e;if("string"==typeof e){const t=document.querySelector(e);if(t)return t;if(e.startsWith("#")){const t=e.slice(1),n=document.createElement("div");return n.id=t,document.body.appendChild(n),n}}let t=document.getElementById(Rt);return t||(t=document.createElement("div"),t.id=Rt,document.body.appendChild(t)),t}(t);return n?(n.appendChild(e),()=>{e.parentNode===n&&n.removeChild(e),n.id!==Rt&&0===n.children.length&&n.parentNode&&n.parentNode.removeChild(n)}):()=>{}}}}function St(e){const n=t(zt),i=e??n;if(!i)throw new Error("useModalZIndex: No modal ID provided and no modal context found. Either pass a modal ID or use this hook inside a Modal component.");return{get zIndex(){const e=Ie(i);return((null==e?void 0:e.zIndex)??ft().zIndex.base)+1},get portalTarget(){return ft().portalTarget}}}function Ht(){function t(e,t,n){return"undefined"==typeof window?()=>{}:(window.addEventListener(e,t,n),()=>{window.removeEventListener(e,t,n)})}return{addListener:t,addListenerEffect:function(n,i,o){e.user_effect(()=>{if("undefined"!=typeof window)return t(n,i,o)})}}}var Ft=e.from_html('<div style="display: contents;"><!></div>');function Lt(t,i){e.push(i,!0);let o=e.prop(i,"target",3,"body"),r=null,s=null;const{mount:d}=Et();n(()=>(r&&(s=d(r,o())),()=>{null==s||s()}));var a=Ft(),l=e.child(a);e.snippet(l,()=>i.children),e.reset(a),e.bind_this(a,e=>r=e,()=>r),e.append(t,a),e.pop()}var Wt=e.from_html('<button type="button" aria-label="Minimize"></button>'),At=e.from_html('<button type="button" class="modal-header-light modal-header-light-style" aria-label="Toggle style"></button>'),$t=e.from_html('<div class="modal-header-icon"><!></div>'),Xt=e.from_html('<div class="modal-header-icon"><!></div>'),Yt=e.from_html('<h2 class="modal-header-title"> </h2>'),qt=e.from_html('<h2 class="modal-header-title"> </h2>'),Nt=e.from_html('<div class="modal-header-traffic-lights"><button type="button" class="modal-header-light modal-header-light-close" aria-label="Close"></button> <!> <!></div> <div class="modal-header-mac-center"><!> <div class="modal-header-title-group"><!></div></div> <div class="modal-header-mac-spacer"></div>',1),jt=e.from_html('<div class="modal-header-icon"><!></div>'),Gt=e.from_html('<div class="modal-header-icon"><!></div>'),Kt=e.from_html('<h2 class="modal-header-title"> </h2>'),Vt=e.from_html('<h2 class="modal-header-title"> </h2>'),Ut=e.from_html('<button type="button" class="modal-header-btn-windows modal-header-btn-windows-style" aria-label="Toggle style">&#9671;</button>'),Qt=e.from_html('<button type="button" aria-label="Minimize">&#8211;</button>'),Zt=e.from_html('<div class="modal-header-title-group"><!> <!></div> <div class="modal-header-actions"><!> <!> <button type="button" class="modal-header-btn-windows modal-header-btn-windows-close" aria-label="Close">&times;</button></div>',1),Jt=e.from_html("<header><!></header>");function en(n,i){e.push(i,!0);let o=e.prop(i,"isTransparent",3,!1),r=e.prop(i,"headerLayout",3,"macos"),s=e.prop(i,"minimizable",3,!0),d=e.prop(i,"minimizeDisabled",3,!1),a=e.prop(i,"transparencyEnabled",3,!0);const l=t(xt),c=e.derived(()=>null==l?void 0:l()),g=e.derived(()=>"macos"===r());var u=Jt();let h;u.__pointerdown=function(e){var t;e.target.closest("button")||null==(t=i.onStartDrag)||t.call(i,e)};var p=e.child(u),f=t=>{var n=Nt(),o=e.first_child(n),r=e.child(o);r.__click=function(...e){var t;null==(t=i.onClose)||t.apply(this,e)};var l=e.sibling(r,2),g=t=>{var n=Wt();let o;n.__click=function(...e){var t;null==(t=d()?void 0:i.onMinimize)||t.apply(this,e)},e.template_effect(()=>{o=e.set_class(n,1,"modal-header-light modal-header-light-minimize",null,o,{"modal-header-light-disabled":d()}),n.disabled=d(),e.set_attribute(n,"title",d()?"Enable dock to minimize":void 0)}),e.append(t,n)};e.if(l,e=>{s()&&e(g)});var u=e.sibling(l,2),h=t=>{var n=At();n.__click=function(...e){var t;null==(t=i.onToggleStyle)||t.apply(this,e)},e.append(t,n)};e.if(u,e=>{a()&&e(h)}),e.reset(o);var p=e.sibling(o,2),f=e.child(p),m=t=>{var n=$t(),o=e.child(n);e.snippet(o,()=>i.customIcon),e.reset(n),e.append(t,n)},v=t=>{var n=e.comment(),o=e.first_child(n),r=t=>{var n=Xt(),o=e.child(n);e.snippet(o,()=>e.get(c),()=>i.icon),e.reset(n),e.append(t,n)};e.if(o,t=>{i.icon&&e.get(c)&&t(r)},!0),e.append(t,n)};e.if(f,e=>{i.customIcon?e(m):e(v,!1)});var w=e.sibling(f,2),y=e.child(w),x=t=>{var n=Yt(),o=e.child(n,!0);e.reset(n),e.template_effect(()=>{e.set_attribute(n,"id",i.titleId),e.set_text(o,i.title)}),e.append(t,n)},z=t=>{var n=qt(),o=e.child(n,!0);e.reset(n),e.template_effect(()=>e.set_text(o,i.title)),e.append(t,n)};e.if(y,e=>{i.titleId?e(x):e(z,!1)}),e.reset(w),e.reset(p),e.next(2),e.append(t,n)},m=t=>{var n=Zt(),o=e.first_child(n),r=e.child(o),l=t=>{var n=jt(),o=e.child(n);e.snippet(o,()=>i.customIcon),e.reset(n),e.append(t,n)},g=t=>{var n=e.comment(),o=e.first_child(n),r=t=>{var n=Gt(),o=e.child(n);e.snippet(o,()=>e.get(c),()=>i.icon),e.reset(n),e.append(t,n)};e.if(o,t=>{i.icon&&e.get(c)&&t(r)},!0),e.append(t,n)};e.if(r,e=>{i.customIcon?e(l):e(g,!1)});var u=e.sibling(r,2),h=t=>{var n=Kt(),o=e.child(n,!0);e.reset(n),e.template_effect(()=>{e.set_attribute(n,"id",i.titleId),e.set_text(o,i.title)}),e.append(t,n)},p=t=>{var n=Vt(),o=e.child(n,!0);e.reset(n),e.template_effect(()=>e.set_text(o,i.title)),e.append(t,n)};e.if(u,e=>{i.titleId?e(h):e(p,!1)}),e.reset(o);var f=e.sibling(o,2),m=e.child(f),v=t=>{var n=Ut();n.__click=function(...e){var t;null==(t=i.onToggleStyle)||t.apply(this,e)},e.append(t,n)};e.if(m,e=>{a()&&e(v)});var w=e.sibling(m,2),y=t=>{var n=Qt();let o;n.__click=function(...e){var t;null==(t=d()?void 0:i.onMinimize)||t.apply(this,e)},e.template_effect(()=>{o=e.set_class(n,1,"modal-header-btn-windows",null,o,{"modal-header-btn-windows-disabled":d()}),n.disabled=d(),e.set_attribute(n,"title",d()?"Enable dock to minimize":void 0)}),e.append(t,n)};e.if(w,e=>{s()&&e(y)}),e.sibling(w,2).__click=function(...e){var t;null==(t=i.onClose)||t.apply(this,e)},e.reset(f),e.append(t,n)};e.if(p,t=>{e.get(g)?t(f):t(m,!1)}),e.reset(u),e.template_effect(()=>h=e.set_class(u,1,"modal-header",null,h,{"modal-header-draggable":!!i.onStartDrag,transparent:o()})),e.append(n,u),e.pop()}e.delegate(["pointerdown","click"]);var tn=e.from_html("<div></div>"),nn=e.from_html('<div class="modal-resize-handles"></div>');function on(t,n){e.push(n,!0);const i=["n","s","e","w","ne","nw","se","sw"];var o=e.comment(),r=e.first_child(o),s=t=>{var o=nn();e.each(o,21,()=>i,e.index,(t,i)=>{var o=tn();o.__pointerdown=t=>function(e,t){var i;null==(i=n.onStartResize)||i.call(n,e,t)}(t,e.get(i)),e.template_effect(()=>e.set_class(o,1,`modal-resize-handle modal-resize-${e.get(i)??""}`)),e.append(t,o)}),e.reset(o),e.append(t,o)};e.if(r,e=>{n.onStartResize&&e(s)}),e.append(t,o),e.pop()}e.delegate(["pointerdown"]);var rn=e.from_html('<div class="modal-footer"><!></div>'),sn=e.from_html("<div></div>"),dn=e.from_html('<div role="dialog" aria-modal="true" tabindex="-1"><!> <div class="modal-body"><!></div> <!> <!> <!></div>');function an(t,s){e.push(s,!0);let d=e.prop(s,"maxWidth",3,"600px"),a=e.prop(s,"autoOpen",3,!1),l=e.prop(s,"closeOnEscape",3,!0),c=e.state(!1);n(()=>{V({id:s.id,title:s.title,icon:s.icon??"",isOpen:a(),isMinimized:!1,isHiddenWithParent:!1,isTransparent:!1,isRejected:!1,position:null,size:null,hasBeenDragged:!1,dockPosition:0,glow:s.glow??null,parentId:void 0,childId:void 0,offsetFromParent:void 0}),e.set(c,!0)}),r(()=>{U(s.id)});const g=e.derived(()=>{if(!e.get(c))return!1;Me();const t=Ie(s.id);return!!t&&(t.isOpen||t.isMinimized||De(s.id)||Ce(s.id)||we(s.id))});var u=e.comment(),h=e.first_child(u),p=t=>{!function(t,s){e.push(s,!0);let d=e.prop(s,"maxWidth",3,"600px"),a=e.prop(s,"autoOpen",3,!1),l=e.prop(s,"closeOnEscape",3,!0),c=e.prop(s,"skipRegistration",3,!1);i(zt,s.id);const g=ft().portalTarget;function u(e){var t,n;return(null==(n=null==(t=s.config)?void 0:t.features)?void 0:n[e])??yt(e)}const h=e.derived(()=>(pt(),u("drag"))),p=e.derived(()=>(pt(),u("minimize"))),f=e.derived(()=>(pt(),!u("dock"))),m=e.derived(()=>(pt(),u("transparency"))),v=e.derived(()=>(pt(),u("resize"))),w=e.derived(()=>{var e,t;return pt(),(null==(t=null==(e=s.config)?void 0:e.appearance)?void 0:t.headerLayout)??ft().appearance.headerLayout});let x=e.state(null),z=e.state(!1),_=e.state(!1),D=e.state(!1),P=e.state(!1),C=e.state(!1);const B=e.derived(()=>(Me(),Ie(s.id))),O=e.derived(()=>e.get(B)&&(e.get(B).isOpen||Ce(s.id))&&(!e.get(B).isMinimized||we(s.id))&&!e.get(B).isHiddenWithParent),T=e.derived(()=>{var t;return!!(null==(t=e.get(B))?void 0:t.childId)}),R=e.derived(()=>{var t;return!!(null==(t=e.get(B))?void 0:t.parentId)}),E=e.derived(()=>e.get(T)||e.get(_)),S=e.derived(()=>!!s.glow),H=e.derived(()=>`modal-title-${s.id}`),F=e.derived(()=>{var t;return(null==(t=e.get(B))?void 0:t.zIndex)??1e3}),L=_t({x:0,y:0});let W=e.state(!1);const A=Mt(()=>e.get(x),()=>L.position,e=>L.setPosition(e),()=>L.hasBeenDragged,e=>L.setHasBeenDragged(e),(t,n)=>{const i=Ie(s.id);if(null==i?void 0:i.parentId){const t=Ie(i.parentId),o=document.querySelector(`[data-modal-id="${i.parentId}"]`);if(t&&o){const i=t.position??{x:o.getBoundingClientRect().left,y:o.getBoundingClientRect().top},r=t.size??{width:o.offsetWidth,height:o.offsetHeight},d={x:i.x+(r.width-n.width)/2,y:i.y+(r.height-n.height)/2};e.set(W,!0),L.setPosition(d);const a={x:d.x-i.x,y:d.y-i.y};return ie(s.id,{position:d,size:n,hasBeenDragged:!0,offsetFromParent:a}),void setTimeout(()=>{e.set(W,!1)},200)}}ie(s.id,{position:t,size:n,hasBeenDragged:!0})}),$=Dt(()=>s.id,()=>e.get(x),()=>L.position,e=>L.setPosition(e),()=>L.hasBeenDragged,e=>L.setHasBeenDragged(e),()=>A.hasBeenResized,()=>A.size,(e,t,n)=>{ie(s.id,{position:e,size:n,hasBeenDragged:t}),Q(s.id)}),{trapFocus:X,focusFirstElement:Y}=Tt(),q=e.derived(()=>$.isMinimizing||$.isRestoring||$.isOpening||$.isClosing),N=e.derived(()=>(Se(s.id)||Re(s.id))&&!$.isRestoring);let j=e.state(!1);const G=e.derived(()=>$.isRestoring||$.isOpening||e.get(j)),K=e.derived(()=>e.get(O)&&!L.hasBeenDragged&&!e.get(q)&&!$.pendingOpenSource&&!e.get(N)),Z=e.derived(()=>{const t=[];return t.push(`z-index: ${e.get(F)};`),$.animationTransform?(t.push(`left: ${L.position.x}px; top: ${L.position.y}px;`),t.push(`--genie-origin-x: ${$.animationTransform.originX}px;`),t.push(`--genie-origin-y: ${$.animationTransform.originY}px;`),t.push(`--genie-translate-x: ${$.animationTransform.x}px;`),t.push(`--genie-translate-y: ${$.animationTransform.y}px;`)):L.hasBeenDragged&&t.push(`left: ${L.position.x}px; top: ${L.position.y}px; transform: none;`),A.hasBeenResized?t.push(`width: ${A.size.width}px; height: ${A.size.height}px; max-width: none; max-height: none;`):(s.preferredHeight&&t.push(`min-height: ${s.preferredHeight};`),d()&&t.push(`max-width: ${d()};`)),e.get(S)&&s.glow&&(t.push(`--modal-glow-color: ${s.glow.color};`),t.push(`--modal-glow-intensity: ${s.glow.intensity};`)),t.join(" ")});function J(){e.get(p)&&Q(s.id)}function ee(){var e;Oe(s.id)&&Te(s.id),le(s.id),null==(e=s.onClose)||e.call(s)}function ne(){Qe(s.id)}function se(t){e.get(h)&&e.get(x)&&L.onPointerDown(t,e.get(x))}function de(e){l()&&"Escape"===e.key&&re(s.id)&&(e.stopPropagation(),ee())}function ae(t){if(!e.get(x))return;const n=L.isDragging,i=A.hasBeenResized?A.size:{width:e.get(x).offsetWidth,height:e.get(x).offsetHeight};L.onPointerMove(t,e.get(x),i),L.isDragging&&n&&te(s.id,L.position,{drag:!0})}function ce(t){if(!e.get(x))return;const n=L.isDragging;L.onPointerUp(t,e.get(x)),n&&!A.justFinishedResizing&&(te(s.id,L.position,{drag:!0}),rt(s.id))}function ue(){var t;const n=ft();if("smart"!==(null==(t=n.positioning)?void 0:t.strategy))return!1;const i=Ie(s.id);if(null==i?void 0:i.parentId)return!1;if((null==i?void 0:i.hasBeenDragged)||(null==i?void 0:i.position))return!1;const o=e.get(x)||document.querySelector(`[data-modal-id="${s.id}"]`);if(!o)return!1;const r=o.offsetWidth,d=o.offsetHeight;if(r<=0||d<=0)return!1;const a=n.positioning.modalGap??16,l=_e(s.id),c=M(r,d,l,{modalGap:a,avoidBounds:b(n.positioning.avoidElements??[])});if(I(c.x,c.y,r,d,l,a)/(r*d)>.1&&l.length>0){const e=k(r,d,be(s.id),{modalGap:a});if(e&&e.existingModalMoves.size>0)return ot(e.existingModalMoves),L.setPosition(e.newModalPosition),L.setHasBeenDragged(!0),te(s.id,e.newModalPosition,{size:{width:r,height:d}}),!0}return L.setPosition(c),L.setHasBeenDragged(!0),te(s.id,c,{size:{width:r,height:d}}),!0}function he(){o().then(()=>o()).then(()=>{let t=0;const n=()=>{t+=1,ue()||t>5||requestAnimationFrame(n)};e.get(x)?n():requestAnimationFrame(n)})}n(()=>{var t;function n(){const t=Ie(s.id);if(!(null==t?void 0:t.position)||!e.get(x))return;if(t.parentId)return;const n=A.hasBeenResized?A.size.width:e.get(x).offsetWidth,i=A.hasBeenResized?A.size.height:e.get(x).offsetHeight;if(n<=0||i<=0)return;const o=y(t.position.x,t.position.y,n,i);(Math.abs(o.x-t.position.x)>1||Math.abs(o.y-t.position.y)>1)&&(L.setPosition(o),te(s.id,o))}return c()||(t=a(),V({id:s.id,title:s.title,icon:s.icon??"",isOpen:t,isMinimized:!1,isHiddenWithParent:!1,isTransparent:!1,isRejected:!1,position:null,size:null,hasBeenDragged:!1,dockPosition:0,glow:s.glow??null,parentId:void 0,childId:void 0,offsetFromParent:void 0}),t&&oe(s.id)),a()&&(o().then(()=>{e.get(x)&&Y(e.get(x))}),he()),window.addEventListener("pointermove",ae),window.addEventListener("pointerup",ce),window.addEventListener("resize",n),()=>{window.removeEventListener("pointermove",ae),window.removeEventListener("pointerup",ce),window.removeEventListener("resize",n)}}),r(()=>{Ze(s.id),c()||U(s.id)}),e.user_effect(()=>{Me();const t=Ie(s.id);if(t){if(e.set(z,t.isTransparent,!0),!L.isDragging&&!A.isResizing&&t.position){const e=L.position,n=t.position;(Math.abs(e.x-n.x)>.5||Math.abs(e.y-n.y)>.5)&&(L.setPosition(n),t.hasBeenDragged&&L.setHasBeenDragged(!0))}o().then(()=>function(){var t;if(!Ie(s.id))return;if(Oe(s.id))return Te(s.id),void(null==(t=s.onClose)||t.call(s));if(we(s.id)&&!e.get(P)){if(e.set(P,!0),ke(),e.get(x)){const t=e.get(x).getBoundingClientRect(),n=L.hasBeenDragged?L.position:{x:t.left,y:t.top},i=A.hasBeenResized?A.size:{width:t.width,height:t.height};ie(s.id,{position:n,size:i,hasBeenDragged:!0})}$.startMinimize(void 0,()=>{ye(s.id),e.set(P,!1)})}if(Re(s.id)){Ee(s.id);const t=Ie(s.id);$.startRestore((null==t?void 0:t.position)??void 0,(null==t?void 0:t.size)??void 0),o().then(()=>{e.get(x)&&Y(e.get(x))})}if(Se(s.id)){He(s.id);const e=Ie(s.id);$.startRestore((null==e?void 0:e.position)??void 0,(null==e?void 0:e.size)??void 0)}if(Ce(s.id)&&(Be(s.id),$.startClose(()=>{var e;Ze(s.id),ge(s.id),null==(e=s.onClose)||e.call(s)})),De(s.id)){Pe(s.id);const t=Ne(s.id)||s.openSourcePosition||null;t?($.setPendingOpenSource(t),o().then(()=>o()).then(()=>{ue(),$.tryStartOpenAnimation()})):he(),o().then(()=>{e.get(x)&&Y(e.get(x))})}Fe(s.id)&&(Le(s.id),Ae(s.id),e.set(C,!0),setTimeout(()=>{e.set(C,!1),$e(s.id)},600));const n=Ye(s.id);var i;n&&e.get(x)&&(i=n.parentId,o().then(()=>o()).then(()=>{let t=0;const n=()=>{t+=1;const o=function(t){var n,i;const o=Ie(t);if(!o)return!1;const r=e.get(x)||document.querySelector(`[data-modal-id="${s.id}"]`),d=document.querySelector(`[data-modal-id="${t}"]`),a=null==d?void 0:d.getBoundingClientRect(),l=o.position??(a?{x:a.left,y:a.top}:null);if(!l||!r)return!1;const c=(null==(n=o.size)?void 0:n.width)??(null==d?void 0:d.offsetWidth)??(null==a?void 0:a.width)??480,g=(null==(i=o.size)?void 0:i.height)??(null==d?void 0:d.offsetHeight)??(null==a?void 0:a.height)??400,u=r.offsetWidth,h=r.offsetHeight;if(c<=0||g<=0||u<=0||h<=0)return!1;const p={x:l.x+(c-u)/2,y:l.y+(g-h)/2};return L.setPosition(p),L.setHasBeenDragged(!0),te(s.id,p,{size:{width:u,height:h}}),o.position&&o.size||!a||te(t,{x:a.left,y:a.top},{size:{width:c,height:g}}),pe(t,s.id),!0}(i);o||t>5||requestAnimationFrame(n)};e.get(x)?n():requestAnimationFrame(n)}))}())}}),e.user_effect(()=>{const t=Ie(s.id);t&&t.isTransparent!==e.get(z)&&e.set(z,t.isTransparent,!0)}),e.user_effect(()=>{if(e.get(O)&&e.get(x)){const t=t=>function(t){e.get(x)&&X(t,e.get(x))}(t);return e.get(x).addEventListener("keydown",t),()=>{var n;return null==(n=e.get(x))?void 0:n.removeEventListener("keydown",t)}}}),e.user_effect(()=>{!e.get(O)&&$.isMinimizing&&$.forceClearMinimize()}),e.user_effect(()=>{$.isRestoring||$.isOpening?e.set(j,!0):e.get(j)&&requestAnimationFrame(()=>{e.set(j,!1)})}),e.user_effect(()=>{e.get(D)&&!e.get(T)&&(e.set(_,!0),setTimeout(()=>{e.set(_,!1)},200)),e.set(D,e.get(T),!0)});var fe=e.comment(),me=e.first_child(fe),ve=t=>{Lt(t,{get target(){return g},children:(t,n)=>{var i=dn();let o;i.__keydown=de;var r=e.child(i);{let t=e.derived(()=>e.get(h)?se:void 0);en(r,{get title(){return s.title},get customIcon(){return s.customIcon},get icon(){return s.icon},get isTransparent(){return e.get(z)},get titleId(){return e.get(H)},get headerLayout(){return e.get(w)},get onStartDrag(){return e.get(t)},onToggleStyle:ne,onMinimize:J,onClose:ee,get minimizable(){return e.get(p)},get minimizeDisabled(){return e.get(f)},get transparencyEnabled(){return e.get(m)}})}var d=e.sibling(r,2),a=e.child(d);e.snippet(a,()=>s.children??e.noop),e.reset(d);var l=e.sibling(d,2),c=t=>{var n=rn(),i=e.child(n);e.snippet(i,()=>s.footer),e.reset(n),e.append(t,n)};e.if(l,e=>{s.footer&&e(c)});var g=e.sibling(l,2);{let t=e.derived(()=>e.get(v)&&!e.get(T)?A.handlers.startResize:void 0);on(g,{get onStartResize(){return e.get(t)}})}var u=e.sibling(g,2),y=t=>{var n=sn();let i;e.template_effect(()=>i=e.set_class(n,1,"modal-child-overlay",null,i,{"modal-overlay-closing":e.get(_)})),e.append(t,n)};e.if(u,t=>{e.get(E)&&t(y)}),e.reset(i),e.bind_this(i,t=>e.set(x,t),()=>e.get(x)),e.template_effect(()=>{var t;o=e.set_class(i,1,"modal-dialog",null,o,{"modal-dragging":L.isDragging,"modal-resizing":A.isResizing,"modal-positioned":L.hasBeenDragged,"modal-minimizing":$.isMinimizing,"modal-restoring":$.isRestoring,"modal-opening":$.isOpening,"modal-closing":$.isClosing,"modal-centered":e.get(K),"modal-solid":!e.get(z),"modal-transparent":e.get(z),"modal-glow":e.get(S),"modal-has-child":e.get(T),"modal-is-child":e.get(R),"modal-visible-by-animation":e.get(G),"modal-animating-to-center":e.get(W),"modal-animating-position":null==(t=e.get(B))?void 0:t.isAnimatingPosition,"modal-attention":e.get(C)}),e.set_attribute(i,"data-modal-id",s.id),e.set_style(i,e.get(Z)),e.set_attribute(i,"aria-labelledby",e.get(H))}),e.event("pointerdown",i,()=>oe(s.id),!0),e.append(t,i)},$$slots:{default:!0}})};e.if(me,t=>{e.get(O)&&t(ve)}),e.append(t,fe),e.pop()}(t,{get id(){return s.id},get title(){return s.title},get icon(){return s.icon},get customIcon(){return s.customIcon},get maxWidth(){return d()},get preferredHeight(){return s.preferredHeight},get autoOpen(){return a()},get openSourcePosition(){return s.openSourcePosition},get glow(){return s.glow},get config(){return s.config},get closeOnEscape(){return l()},get onClose(){return s.onClose},get children(){return s.children},get footer(){return s.footer},skipRegistration:!0})};e.if(h,t=>{e.get(g)&&t(p)}),e.append(t,u),e.pop()}e.delegate(["keydown"]);var ln=e.from_html('<button type="button" aria-label="Drag dock"></button>'),cn=e.from_html('<span class="modal-dock-item-icon-placeholder"> </span>'),gn=e.from_html('<span class="modal-dock-item-label"> </span>'),un=e.from_html("<span>+</span>"),hn=e.from_html('<span class="modal-dock-child-indicator"><!></span>'),pn=e.from_html('<button><span class="modal-dock-item-icon"><!></span> <!> <span class="modal-dock-item-glow"></span> <!></button>'),fn=e.from_html('<div data-dock-container="true"><div><!> <!></div></div>');function mn(n,i){e.push(i,!0);const o=t(xt),r=e.derived(()=>i.renderIcon??(null==o?void 0:o())),s=Ue(),l=e.derived(()=>(pt(),ft())),u=e.derived(()=>m("DOCK")),h=e.derived(()=>e.get(l).dock.position),p=e.derived(()=>e.get(l).dock.labelMode);let f=e.state("horizontal"),v=e.state(e.proxy({x:100,y:100})),w=e.state(null),x=e.state(!1),z={x:0,y:0},I=null;const b=e.derived(()=>(Me(),Array.from(s.modals.values()).filter(e=>e.isMinimized).sort((e,t)=>e.dockPosition-t.dockPosition))),_=e.derived(()=>{switch(e.get(h)){case"left":return{x:-20,duration:250,easing:c};case"right":return{x:20,duration:250,easing:c};default:return{y:20,duration:250,easing:c}}});function M(t){var n;"free"===e.get(h)&&(e.set(x,!0),I=t.pointerId,z={x:t.clientX-e.get(v).x,y:t.clientY-e.get(v).y},null==(n=t.currentTarget)||n.setPointerCapture(t.pointerId),window.addEventListener("pointermove",k),window.addEventListener("pointerup",D),window.addEventListener("pointercancel",D))}function k(t){if(t.pointerId!==I||!e.get(w))return;const n=e.get(w).getBoundingClientRect(),i=window.innerWidth-n.width-8,o=window.innerHeight-n.height-8,r=Math.min(Math.max(t.clientX-z.x,8),Math.max(8,i)),s=Math.min(Math.max(t.clientY-z.y,8),Math.max(8,o));e.set(v,{x:Math.round(r),y:Math.round(s)},!0)}function D(t){t.pointerId===I&&(e.set(x,!1),I=null,window.removeEventListener("pointermove",k),window.removeEventListener("pointerup",D),window.removeEventListener("pointercancel",D))}const{addListener:P}=Ht();function C(){if("free"!==e.get(h)||!e.get(w))return;const t=e.get(w).getBoundingClientRect(),n=y(e.get(v).x,e.get(v).y,t.width,t.height);n.x===e.get(v).x&&n.y===e.get(v).y||e.set(v,{x:Math.round(n.x),y:Math.round(n.y)},!0)}e.user_effect(()=>{"undefined"!=typeof window&&P("resize",C)});var B={setDockOrientation:function(t){e.set(f,t,!0)},setDockFreePosition:function(t){e.set(v,t,!0)},getDockState:function(){return{dockPosition:e.get(h),dockOrientation:e.get(f),dockFreePosition:e.get(v),dockLabelMode:e.get(p)}}};return Lt(n,{get target(){return e.get(l).portalTarget},children:(t,n)=>{var i=fn();let o,l;var c=e.child(i);let m;var y=e.child(c),z=t=>{var n=ln();let i;n.__pointerdown=M,e.template_effect(()=>i=e.set_class(n,1,"modal-dock-handle",null,i,{"modal-dock-handle-dragging":e.get(x)})),e.append(t,n)};e.if(y,t=>{"free"===e.get(h)&&t(z)});var I=e.sibling(y,2);e.each(I,19,()=>e.get(b),e=>e.id,(t,n,i)=>{const o=e.derived(()=>e.get(n).lastChildId?s.modals.get(e.get(n).lastChildId):null);var a=pn();let l;a.__click=t=>{Ge(e.get(n).id)?Je(t.currentTarget):Z(e.get(n).id)};var c=e.child(a),u=e.child(c),h=t=>{var i=e.comment(),o=e.first_child(i);e.snippet(o,()=>e.get(r),()=>e.get(n).icon),e.append(t,i)},f=t=>{var i=cn(),o=e.child(i,!0);e.reset(i),e.template_effect(t=>e.set_text(o,t),[()=>e.get(n).title.charAt(0)]),e.append(t,i)};e.if(u,t=>{e.get(n).icon&&e.get(r)?t(h):t(f,!1)}),e.reset(c);var m=e.sibling(c,2),v=t=>{var i=gn(),o=e.child(i,!0);e.reset(i),e.template_effect(()=>e.set_text(o,e.get(n).title)),e.append(t,i)};e.if(m,t=>{"hidden"!==e.get(p)&&t(v)});var w=e.sibling(m,4),y=t=>{var n=hn(),i=e.child(n),s=t=>{var n=e.comment(),i=e.first_child(n);e.snippet(i,()=>e.get(r),()=>e.get(o).icon),e.append(t,n)},d=t=>{var n=un();e.append(t,n)};e.if(i,t=>{e.get(o).icon&&e.get(r)?t(s):t(d,!1)}),e.reset(n),e.append(t,n)};e.if(w,t=>{e.get(n).lastChildId&&e.get(o)&&t(y)}),e.reset(a),e.template_effect(()=>{l=e.set_class(a,1,"modal-dock-item",null,l,{"modal-dock-item-has-glow":!!e.get(n).glow,"modal-dock-item-has-child":!!e.get(n).lastChildId,"modal-dock-item-label-beside":"beside"===e.get(p),"modal-dock-item-label-below":"below"===e.get(p)}),e.set_attribute(a,"data-modal-id",e.get(n).id),e.set_style(a,e.get(n).glow?`--modal-dock-glow-color: ${e.get(n).glow.color};`:"")}),e.transition(3,a,()=>d,()=>({duration:300,delay:50*e.get(i),easing:g,start:.5})),e.append(t,a)}),e.reset(c),e.reset(i),e.bind_this(i,t=>e.set(w,t),()=>e.get(w)),e.template_effect(()=>{o=e.set_class(i,1,"modal-dock-container",null,o,{"modal-dock-left":"left"===e.get(h),"modal-dock-right":"right"===e.get(h),"modal-dock-bottom":"bottom"===e.get(h),"modal-dock-free":"free"===e.get(h),"modal-dock-empty":0===e.get(b).length}),l=e.set_style(i,"free"===e.get(h)?`left: ${e.get(v).x}px; top: ${e.get(v).y}px;`:"",l,{"z-index":e.get(u)}),m=e.set_class(c,1,"modal-dock",null,m,{"modal-dock-free-horizontal":"free"===e.get(h)&&"horizontal"===e.get(f),"modal-dock-free-vertical":"free"===e.get(h)&&"vertical"===e.get(f)})}),e.transition(3,i,()=>a,()=>e.get(b).length>0?e.get(_):{duration:0}),e.append(t,i)},$$slots:{default:!0}}),e.pop(B)}e.delegate(["pointerdown","click"]);var vn=e.from_html('<div class="modal-backdrop svelte-1d3nq4t" aria-hidden="true"></div>');function wn(t,n){e.push(n,!0);const i=Ue(),o=e.derived(()=>(pt(),ft())),r=e.derived(()=>e.get(o).features.backdrop),s=e.derived(()=>(Me(),Array.from(i.modals.values()).some(e=>e.isOpen&&!e.isMinimized&&!e.isHiddenWithParent))),d=e.derived(()=>e.get(r)&&e.get(s)),a=e.derived(()=>m("MODAL")-1);Lt(t,{get target(){return e.get(o).portalTarget},children:(t,n)=>{var i=e.comment(),o=e.first_child(i),r=t=>{var n=vn();let i;e.template_effect(()=>i=e.set_style(n,"",i,{"z-index":e.get(a)})),e.transition(3,n,()=>l,()=>({duration:200})),e.append(t,n)};e.if(o,t=>{e.get(d)&&t(r)}),e.append(t,i)},$$slots:{default:!0}}),e.pop()}var yn=e.from_html("<!> <!>",1);function xn(t,n){e.push(n,!0),i(xt,()=>n.renderIcon),e.user_effect(()=>(s(()=>{n.config&&mt(n.config),p()}),()=>{vt(),v()})),e.user_effect(()=>{if("undefined"==typeof document)return;const e=s(()=>ft().portalTarget);if("string"==typeof e&&!document.querySelector(e)){const t=document.createElement("div");return t.id=e.replace("#",""),document.body.appendChild(t),()=>{t.remove()}}});var o=yn(),r=e.first_child(o);wn(r,{});var d=e.sibling(r,2);e.snippet(d,()=>n.children??e.noop),e.append(t,o),e.pop()}export{wn as Backdrop,mn as Dock,an as Modal,en as ModalHeader,xn as ModalProvider,Lt as Portal,on as ResizeHandles,lt as _getInternalState,ct as _resetInternalState,f as acquireModalZIndex,ot as animateModalsToPositions,et as animateParentToPosition,oe as bringToFront,z as calculateOverlap,_ as calculatePositionScore,k as calculateRearrangement,I as calculateTotalOverlap,tt as clearParentAnimationFlag,it as clearPendingParentAnimation,ce as closeAllModals,le as closeModal,x as constrainSizeToViewport,y as constrainToViewport,Ne as consumeOpenSourcePosition,Le as consumePendingAttention,He as consumePendingChildRestore,Be as consumePendingClose,Te as consumePendingForceClose,ye as consumePendingMinimize,ke as consumePendingMinimizeTarget,Pe as consumePendingOpen,Ye as consumePendingParentLink,Ee as consumePendingRestore,ae as createModal,gt as defaultConfig,$e as endAttentionAnimation,ge as finalizeModalClose,M as findSmartPosition,Ot as focusFirstElement,ft as getConfig,pt as getConfigVersion,b as getElementBounds,m as getLayerZIndex,Ie as getModalState,Ue as getModalsStore,ue as getModalsToClose,_e as getOpenModalBounds,be as getOpenModalBoundsWithIds,Xe as getPendingParentLink,ze as getRegisteredModalIds,Me as getStateVersion,xe as hasAnyPendingMinimize,Fe as hasPendingAttention,Se as hasPendingChildRestore,Ce as hasPendingClose,Oe as hasPendingForceClose,we as hasPendingMinimize,De as hasPendingOpen,nt as hasPendingParentAnimation,Re as hasPendingRestore,fe as hideChildWithParent,p as initializeStacking,yt as isFeatureEnabled,Ge as isModalAnimating,Ke as isModalOpen,Ve as isModalRegistered,re as isTopModal,pe as linkModals,wt as mergeConfig,Q as minimizeModal,he as openChildModal,de as openModal,V as registerModal,se as reorderDock,vt as resetConfig,Ze as resetModalTransparency,v as resetStacking,J as restoreAllMinimizedModals,ee as restoreChildModal,Z as restoreModal,ve as setChildOffsetFromParent,mt as setConfig,at as setDockPositionGetter,je as setModalAnimating,st as setRegistryFunctions,dt as setURLStateCallbacks,Je as shakeElement,Ae as startAttentionAnimation,qe as storeOpenSourcePosition,O as subscribe,Qe as toggleModalTransparency,Bt as trapFocus,We as triggerAttention,rt as triggerCascadingParentAnimations,U as unregisterModal,me as updateChildPosition,ie as updateModal,te as updateModalPosition,ne as updateModalSize,Tt as useFocusTrap,bt as useModal,Dt as useModalAnimation,_t as useModalDrag,Mt as useModalResize,St as useModalZIndex,Et as usePortal,Ht as useWindowEvent};
@@ -0,0 +1,51 @@
1
+ import { BaseModalProps } from '../core/types';
2
+ import { ModalLibraryConfig } from '../core/config.svelte.js';
3
+ export { openModal, closeModal, minimizeModal, restoreModal, bringToFront, isModalOpen, isModalRegistered, openChildModal, closeAllModals, toggleModalTransparency, } from '../core/state.svelte.js';
4
+ export { setConfig, getConfig } from '../core/config.svelte.js';
5
+ export interface ModalOptions extends Omit<BaseModalProps, 'icon'> {
6
+ content?: string | HTMLElement;
7
+ footer?: string | HTMLElement;
8
+ /** Icon identifier string (used by renderIcon in modal header and dock) */
9
+ icon?: string;
10
+ /** Custom icon element (overrides icon string if provided) */
11
+ customIcon?: string | HTMLElement;
12
+ }
13
+ export interface ModalControl {
14
+ destroy: () => void;
15
+ }
16
+ export interface DockControl {
17
+ destroy: () => void;
18
+ }
19
+ /**
20
+ * Create a modal
21
+ */
22
+ export declare function createModal(options: ModalOptions): ModalControl;
23
+ /**
24
+ * Create a dock for minimized modals
25
+ */
26
+ export declare function createDock(): DockControl;
27
+ export interface BackdropControl {
28
+ destroy: () => void;
29
+ }
30
+ /**
31
+ * Create a backdrop overlay (shown when modals are open)
32
+ */
33
+ export declare function createBackdrop(): BackdropControl;
34
+ export interface InitOptions {
35
+ config?: Partial<ModalLibraryConfig>;
36
+ /** Whether to create the backdrop automatically (default: true if features.backdrop is enabled) */
37
+ backdrop?: boolean;
38
+ /** Whether to create the dock automatically (default: true if features.dock is enabled) */
39
+ dock?: boolean;
40
+ }
41
+ export interface InitControl {
42
+ destroy: () => void;
43
+ backdrop: BackdropControl | null;
44
+ dock: DockControl | null;
45
+ }
46
+ /**
47
+ * Initialize the modals library (similar to ModalProvider in Svelte)
48
+ * Call this once before creating any modals
49
+ */
50
+ export declare function init(options?: InitOptions): InitControl;
51
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Vanilla JavaScript API for the Modals Library
3
+ *
4
+ * This entry point exports the vanilla API for creating and managing modals
5
+ * without requiring a framework like Svelte or React.
6
+ *
7
+ * @module vanilla
8
+ */
9
+ export * from './vanilla/index';
10
+ //# sourceMappingURL=vanilla.d.ts.map
@@ -0,0 +1 @@
1
+ import{onMount as e,getContext as t,setContext as i,tick as n,onDestroy as o,mount as r,unmount as d}from"svelte";import"svelte/internal/disclose-version";import*as s from"svelte/internal/client";import{scale as a,fly as l,fade as c}from"svelte/transition";import{cubicOut as g,backOut as u}from"svelte/easing";const h={features:{dock:!0,minimize:!0,transparency:!0,resize:!0,drag:!0,focusTrap:!0,animations:!0,backdrop:!0,parentChild:!0},dock:{position:"bottom",labelMode:"beside",enableReorder:!0,enableFreeDrag:!0},animations:{open:400,close:250,minimize:500,restore:400},appearance:{headerLayout:"macos",defaultWidth:"480px",defaultHeight:"auto",minWidth:280,minHeight:200},zIndex:{base:400,dock:8e3,toast:9e3},parentChild:{movementMode:"animated",animationDuration:300},positioning:{strategy:"smart",modalGap:16,avoidElements:[]},portalTarget:"#modal-portal"};let p={...h},f=s.state(0);function m(){return s.get(f)}function v(){return p}function w(e){const t=p;var i,n;p={features:{...(i=h).features,...(n=e).features},dock:{...i.dock,...n.dock},animations:{...i.animations,...n.animations},appearance:{...i.appearance,...n.appearance},zIndex:{...i.zIndex,...n.zIndex},parentChild:{...i.parentChild,...n.parentChild},positioning:{...i.positioning,...n.positioning},portalTarget:n.portalTarget??i.portalTarget},s.update(f),t.features.dock&&!p.features.dock&&(Array.from(P.values()).filter(e=>e.isMinimized).map(e=>e.id).forEach(e=>{const t=P.get(e);if(t){P.set(e,{...t,isMinimized:!1,isOpen:!0}),s.set(S,[...s.get(S),e],!0),ee(e);const i=t.lastChildId||t.childId;i&&Q(i)}}),s.set(j,[],!0),O())}const y={BASE:0,DROPDOWN:100,STICKY:200,OVERLAY:300,MODAL:400,DOCK:8e3,TOAST:9e3};let x=s.state(s.proxy(y.MODAL));function z(e){const t=v();return"MODAL"===e?t.zIndex.base:"DOCK"===e?t.zIndex.dock:"TOAST"===e?t.zIndex.toast:y[e]}const I=8;function b(e,t,i,n,o={}){const{margin:r=I,allowPartialVisibility:d=!1}=o,s="undefined"!=typeof window?window.innerWidth:1920,a="undefined"!=typeof window?window.innerHeight:1080;let l,c,g,u;return d&&i>s-2*r?(l=40-i,c=s-40):(l=r,c=Math.max(r,s-i-r)),d&&n>a-2*r?(g=40-n,u=a-40):(g=r,u=Math.max(r,a-n-r)),{x:Math.max(l,Math.min(c,e)),y:Math.max(g,Math.min(u,t))}}function _(e,t,i,n,o={}){const{margin:r=I}=o,d=("undefined"!=typeof window?window.innerWidth:1920)-2*r,s=("undefined"!=typeof window?window.innerHeight:1080)-2*r,a=Math.min(i,d),l=Math.min(n,s),c=b(e,t,a,l,o);return{x:c.x,y:c.y,width:a,height:l}}function M(e,t){return Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x))*Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y))}function k(e,t,i,n,o,r){const d={x:e-r,y:t-r,width:i+2*r,height:n+2*r};let s=0;for(const e of o)s+=M(d,e);return s}function D(e,t,i,n,o,r,d){const s=(o-i)/2,a=(r-n)/2,l=s-d,c=a-d,g=Math.abs(e-s)/(l||1),u=Math.abs(t-a)/(c||1),h=Math.sqrt(g*g+u*u)/Math.SQRT2,p=50,f=e-d,m=o-i-d-e,v=t-d,w=r-n-d-t;let y=0;return f<p&&(y+=.3*(1-f/p)),m<p&&(y+=.3*(1-m/p)),v<p&&(y+=.2*(1-v/p)),w<p&&(y+=.2*(1-w/p)),Math.min(1,h+y)}let P=s.proxy(new Map),C=s.state(0);const B=new Set;function O(){s.update(C),queueMicrotask(()=>{B.forEach(e=>e())})}let R=s.state(s.proxy([])),T=s.state(s.proxy([])),E=s.state(s.proxy([])),H=s.state(s.proxy([])),S=s.state(s.proxy([])),L=s.state(s.proxy([])),W=s.state(s.proxy([])),A=s.state(s.proxy([])),$=s.state(null),F=s.proxy(new Map),X=s.state(null),Y=s.proxy(new Map),q=s.proxy(new Set),N=s.proxy(new Set),j=s.state(s.proxy([]));function G(e){const t=P.get(e.id),i=(null==t?void 0:t.zIndex)??function(){const e=s.get(x);return s.set(x,s.get(x)+2),e}();t?P.set(e.id,{...t,title:e.title,icon:e.icon,glow:e.glow,zIndex:i}):P.set(e.id,{...e,zIndex:i,isAnimating:!1}),O(),e.isMinimized&&!s.get(j).includes(e.id)&&s.get(j).push(e.id)}function K(e){const t=P.get(e);if(t){if(s.set(j,s.get(j).filter(t=>t!==e),!0),t.childId){const e=P.get(t.childId);e&&P.set(t.childId,{...e,parentId:void 0})}if(t.parentId){const e=P.get(t.parentId);e&&P.set(t.parentId,{...e,childId:void 0,lastChildId:t.id})}P.delete(e),O(),N.delete(e),q.delete(e)}}function V(e){const t=P.get(e);if(!t||t.isMinimized)return;if(ye(e),t.parentId){const e=P.get(t.parentId);if(e&&!e.isMinimized)return void V(t.parentId)}s.set(R,[...s.get(R),e],!0),t.position&&t.size;const i=t.childId;P.set(e,{...t,isMinimized:!0,lastChildId:i}),O(),s.get(j).includes(e)||s.get(j).push(e),t.childId&&function(e){const t=P.get(e);if(!(null==t?void 0:t.childId))return;const i=P.get(t.childId);i&&(P.set(t.childId,{...i,isHiddenWithParent:!0}),O())}(e)}function U(e){const t=P.get(e);if(!t||!t.isMinimized)return;P.set(e,{...t,isMinimized:!1,isOpen:!0}),O(),s.set(S,[...s.get(S),e],!0),ee(e);const i=t.lastChildId||t.childId;i&&Q(i)}function Q(e){const t=P.get(e);t&&t.isHiddenWithParent&&(P.set(e,{...t,isHiddenWithParent:!1}),O(),s.set(L,[...s.get(L),e],!0))}function J(e,t,i){const n=P.get(e);if(!n)return;let o=t;if((null==i?void 0:i.constrain)&&n.size&&(o=b(t.x,t.y,n.size.width,n.size.height)),P.set(e,{...n,position:o,size:(null==i?void 0:i.size)??n.size,hasBeenDragged:n.hasBeenDragged||(null==i?void 0:i.drag)||!1}),n.childId){let t=e,i=o;for(;;){const e=P.get(t);if(!(null==e?void 0:e.childId))break;const n=P.get(e.childId);if(!(null==n?void 0:n.offsetFromParent))break;const o={x:i.x+n.offsetFromParent.x,y:i.y+n.offsetFromParent.y};P.set(e.childId,{...n,position:o,hasBeenDragged:!0}),t=e.childId,i=o}}if(n.parentId&&n.offsetFromParent){const t=v();let i=e,r=n;for(;r.parentId&&r.offsetFromParent;){const n=P.get(r.parentId);if(!n)break;const d=i===e?o:P.get(i).position,s={x:d.x-r.offsetFromParent.x,y:d.y-r.offsetFromParent.y};"animated"===t.parentChild.movementMode?Y.set(r.parentId,s):P.set(r.parentId,{...n,position:s,hasBeenDragged:!0}),i=r.parentId,r=n}}O()}function Z(e,t){const i=P.get(e);i&&(P.set(e,{...i,...t}),O())}function ee(e){var t;const i=P.get(e);if(!i)return;const n=Math.max(...Array.from(P.values()).map(e=>e.zIndex),0);if(i.parentId){const o=P.get(i.parentId);o&&o.zIndex<n&&P.set(i.parentId,{...o,zIndex:n+2});const r=(null==(t=P.get(i.parentId))?void 0:t.zIndex)??n+2;return i.zIndex<=r&&P.set(e,{...i,zIndex:r+2}),void O()}if(i.zIndex<n&&(P.set(e,{...i,zIndex:n+2}),O()),i.childId){const t=P.get(i.childId),n=P.get(e);t&&n&&t.zIndex<=n.zIndex&&(P.set(i.childId,{...t,zIndex:n.zIndex+2}),O())}}function te(e,t,i){const n=t.getBoundingClientRect();F.set(e,{x:n.left+n.width/2,y:n.top+n.height/2});const o=v();(null==i?void 0:i.parentId)&&o.features.parentChild&&s.set(X,{parentId:i.parentId,childId:e},!0),s.get(T).includes(e)||s.set(T,[...s.get(T),e],!0),O();const r=P.get(e);if(r){if(r.isOpen&&!r.isMinimized&&!r.isHiddenWithParent)return s.set(T,s.get(T).filter(t=>t!==e),!0),function(e){P.get(e)&&(s.get(W).includes(e)||s.get(A).includes(e)||(s.set(W,[...s.get(W),e],!0),O()))}(e),void ee(e);if(r.isMinimized)return s.set(T,s.get(T).filter(t=>t!==e),!0),void U(e);P.set(e,{...r,isOpen:!0}),ee(e)}}function ie(e,t=!1){const i=P.get(e);i&&(ye(e),t?s.set(H,[...s.get(H),e],!0):s.set(E,[...s.get(E),e],!0),O(),i.childId&&ie(i.childId,t))}function ne(){Array.from(P.keys()).forEach(e=>ie(e,!0))}function oe(e,t,i){const n=v();if(i&&!F.has(e.id)){const t=i.getBoundingClientRect();F.set(e.id,{x:t.left+t.width/2,y:t.top+t.height/2})}const o={id:e.id,title:e.title??"",icon:e.icon??"",isOpen:!0,isMinimized:!1,isHiddenWithParent:!1,isTransparent:e.isTransparent??!1,isRejected:!1,position:e.position??null,size:e.size??null,hasBeenDragged:e.hasBeenDragged??!1,dockPosition:e.dockPosition??-1,glow:e.glow??null};if(!n.features.parentChild){G(o);const t=P.get(e.id);return t&&P.set(e.id,{...t,isOpen:!0}),s.set(T,[...s.get(T),e.id],!0),O(),void ee(e.id)}const r=P.get(t);if(!r)return;r.childId&&ie(r.childId,!0),G({...o,parentId:t});const d=P.get(e.id);d&&P.set(e.id,{...d,isOpen:!0,parentId:t}),s.set(T,[...s.get(T),e.id],!0),O(),ee(e.id),s.set(X,{parentId:t,childId:e.id},!0)}function re(e){return s.get(R).includes(e)}function de(e){return P.get(e)}function se(){return s.get(C)}function ae(e){return s.get(T).includes(e)}function le(e){return s.get(E).includes(e)}function ce(e){return s.get(H).includes(e)}function ge(e){return!!s.get(H).includes(e)&&(s.set(H,s.get(H).filter(t=>t!==e),!0),!0)}function ue(e){return s.get(S).includes(e)}function he(e){return s.get(L).includes(e)}function pe(e){const t=P.get(e);return void 0!==t&&t.isOpen&&!t.isMinimized&&!t.isHiddenWithParent}function fe(e){return P.has(e)}function me(){return{get modals(){return P},get pendingMinimize(){return s.get(R)},get pendingOpen(){return s.get(T)},get pendingClose(){return s.get(E)},get pendingRestore(){return s.get(S)},get dockOrder(){return s.get(j)}}}function ve(e){N.has(e)?N.delete(e):N.add(e);const t=P.get(e);t&&(P.set(e,{...t,isTransparent:N.has(e)}),O())}function we(e){N.delete(e);const t=P.get(e);t&&(P.set(e,{...t,isTransparent:!1}),O())}function ye(e){Y.delete(e)}const xe=Symbol("modal-render-icon"),ze=Symbol("modal-id");function Ie(){return v().features.animations}const be=["button:not([disabled])","[href]","input:not([disabled])","select:not([disabled])","textarea:not([disabled])",'[tabindex]:not([tabindex="-1"])'].join(", ");function _e(e){return Array.from(e.querySelectorAll(be)).filter(e=>null!==e.offsetParent||"A"===e.tagName)}function Me(e,t){if("Tab"!==e.key)return;const i=_e(t);if(0===i.length)return void e.preventDefault();const n=i[0],o=i[i.length-1],r=document.activeElement;e.shiftKey?r===n&&(o.focus(),e.preventDefault()):r===o&&(n.focus(),e.preventDefault())}function ke(e){const t=_e(e);return t.length>0&&(t[0].focus(),!0)}const De="modal-portal";var Pe=s.from_html('<div style="display: contents;"><!></div>');function Ce(t,i){s.push(i,!0);let n=s.prop(i,"target",3,"body"),o=null,r=null;const{mount:d}={mount:function(e,t=null){const i=function(e){if("undefined"==typeof window)return null;if(e instanceof HTMLElement)return e;if("string"==typeof e){const t=document.querySelector(e);if(t)return t;if(e.startsWith("#")){const t=e.slice(1),i=document.createElement("div");return i.id=t,document.body.appendChild(i),i}}let t=document.getElementById(De);return t||(t=document.createElement("div"),t.id=De,document.body.appendChild(t)),t}(t);return i?(i.appendChild(e),()=>{e.parentNode===i&&i.removeChild(e),i.id!==De&&0===i.children.length&&i.parentNode&&i.parentNode.removeChild(i)}):()=>{}}};e(()=>(o&&(r=d(o,n())),()=>{null==r||r()}));var a=Pe(),l=s.child(a);s.snippet(l,()=>i.children),s.reset(a),s.bind_this(a,e=>o=e,()=>o),s.append(t,a),s.pop()}var Be=s.from_html('<button type="button" aria-label="Minimize"></button>'),Oe=s.from_html('<button type="button" class="modal-header-light modal-header-light-style" aria-label="Toggle style"></button>'),Re=s.from_html('<div class="modal-header-icon"><!></div>'),Te=s.from_html('<div class="modal-header-icon"><!></div>'),Ee=s.from_html('<h2 class="modal-header-title"> </h2>'),He=s.from_html('<h2 class="modal-header-title"> </h2>'),Se=s.from_html('<div class="modal-header-traffic-lights"><button type="button" class="modal-header-light modal-header-light-close" aria-label="Close"></button> <!> <!></div> <div class="modal-header-mac-center"><!> <div class="modal-header-title-group"><!></div></div> <div class="modal-header-mac-spacer"></div>',1),Le=s.from_html('<div class="modal-header-icon"><!></div>'),We=s.from_html('<div class="modal-header-icon"><!></div>'),Ae=s.from_html('<h2 class="modal-header-title"> </h2>'),$e=s.from_html('<h2 class="modal-header-title"> </h2>'),Fe=s.from_html('<button type="button" class="modal-header-btn-windows modal-header-btn-windows-style" aria-label="Toggle style">&#9671;</button>'),Xe=s.from_html('<button type="button" aria-label="Minimize">&#8211;</button>'),Ye=s.from_html('<div class="modal-header-title-group"><!> <!></div> <div class="modal-header-actions"><!> <!> <button type="button" class="modal-header-btn-windows modal-header-btn-windows-close" aria-label="Close">&times;</button></div>',1),qe=s.from_html("<header><!></header>");s.delegate(["pointerdown","click"]);var Ne=s.from_html("<div></div>"),je=s.from_html('<div class="modal-resize-handles"></div>');s.delegate(["pointerdown"]);var Ge=s.from_html('<div class="modal-footer"><!></div>'),Ke=s.from_html("<div></div>"),Ve=s.from_html('<div role="dialog" aria-modal="true" tabindex="-1"><!> <div class="modal-body"><!></div> <!> <!> <!></div>');function Ue(r,d){s.push(d,!0);let a=s.prop(d,"maxWidth",3,"600px"),l=s.prop(d,"autoOpen",3,!1),c=s.prop(d,"closeOnEscape",3,!0),g=s.state(!1);e(()=>{G({id:d.id,title:d.title,icon:d.icon??"",isOpen:l(),isMinimized:!1,isHiddenWithParent:!1,isTransparent:!1,isRejected:!1,position:null,size:null,hasBeenDragged:!1,dockPosition:0,glow:d.glow??null,parentId:void 0,childId:void 0,offsetFromParent:void 0}),s.set(g,!0)}),o(()=>{K(d.id)});const u=s.derived(()=>{if(!s.get(g))return!1;se();const e=de(d.id);return!!e&&(e.isOpen||e.isMinimized||ae(d.id)||le(d.id)||re(d.id))});var h=s.comment(),f=s.first_child(h),w=r=>{!function(r,d){s.push(d,!0);let a=s.prop(d,"maxWidth",3,"600px"),l=s.prop(d,"autoOpen",3,!1),c=s.prop(d,"closeOnEscape",3,!0),g=s.prop(d,"skipRegistration",3,!1);i(ze,d.id);const u=v().portalTarget;function h(e){var t,i;return(null==(i=null==(t=d.config)?void 0:t.features)?void 0:i[e])??function(e){return p.features[e]}(e)}const f=s.derived(()=>(m(),h("drag"))),w=s.derived(()=>(m(),h("minimize"))),y=s.derived(()=>(m(),!h("dock"))),x=s.derived(()=>(m(),h("transparency"))),z=s.derived(()=>(m(),h("resize"))),I=s.derived(()=>{var e,t;return m(),(null==(t=null==(e=d.config)?void 0:e.appearance)?void 0:t.headerLayout)??v().appearance.headerLayout});let M=s.state(null),C=s.state(!1),B=s.state(!1),H=s.state(!1),q=s.state(!1),N=s.state(!1);const j=s.derived(()=>(se(),de(d.id))),U=s.derived(()=>s.get(j)&&(s.get(j).isOpen||le(d.id))&&(!s.get(j).isMinimized||re(d.id))&&!s.get(j).isHiddenWithParent),Q=s.derived(()=>{var e;return!!(null==(e=s.get(j))?void 0:e.childId)}),te=s.derived(()=>{var e;return!!(null==(e=s.get(j))?void 0:e.parentId)}),ne=s.derived(()=>s.get(Q)||s.get(B)),oe=s.derived(()=>!!d.glow),pe=s.derived(()=>`modal-title-${d.id}`),fe=s.derived(()=>{var e;return(null==(e=s.get(j))?void 0:e.zIndex)??1e3}),me=function(e={x:0,y:0}){const t=s.proxy({...e}),i=s.proxy({isDragging:!1,startX:0,startY:0,initialX:0,initialY:0,hasBeenDragged:!1});return{get position(){return t},get hasBeenDragged(){return i.hasBeenDragged},get isDragging(){return i.isDragging},onPointerDown:function(e,n){if(0===e.button){if(!i.hasBeenDragged){const e=n.getBoundingClientRect();t.x=e.left,t.y=e.top}i.isDragging=!0,i.startX=e.clientX,i.startY=e.clientY,i.initialX=t.x,i.initialY=t.y,n.setPointerCapture(e.pointerId)}},onPointerMove:function(e,n,o){if(!i.isDragging)return;const r=e.clientX-i.startX,d=e.clientY-i.startY,s=b(i.initialX+r,i.initialY+d,o.width,o.height);t.x=s.x,t.y=s.y,i.hasBeenDragged=!0},onPointerUp:function(e,t){i.isDragging&&(i.isDragging=!1,t.releasePointerCapture(e.pointerId))},setPosition:function(e){t.x=e.x,t.y=e.y},setHasBeenDragged:function(e){i.hasBeenDragged=e},reset:function(){t.x=e.x,t.y=e.y,i.hasBeenDragged=!1}}}({x:0,y:0});let ye=s.state(!1);const be=function(e,t,i){let n=s.state(!1),o=s.state(""),r=s.state(s.proxy({width:0,height:0})),a=s.state(!1),l=s.state(!1),c={x:0,y:0,width:0,height:0,posX:0,posY:0},g=null;function u(d,l){d.preventDefault(),d.stopPropagation();const u=e();if(!u)return;const f=u.getBoundingClientRect();me.hasBeenDragged||(i({x:f.left,y:f.top}),me.setHasBeenDragged(!0)),s.get(a)||(s.set(r,{width:f.width,height:f.height},!0),s.set(a,!0));const m=t();s.set(n,!0),s.set(o,l,!0),g=d.pointerId,c={x:d.clientX,y:d.clientY,width:s.get(r).width,height:s.get(r).height,posX:m.x,posY:m.y,centerX:m.x+s.get(r).width/2,centerY:m.y+s.get(r).height/2},window.addEventListener("pointermove",h),window.addEventListener("pointerup",p),window.addEventListener("pointercancel",p)}function h(e){if(e.pointerId!==g)return;const t=e.clientX-c.x,n=e.clientY-c.y,d=window.innerWidth,a=window.innerHeight;let l=c.width,u=c.height,h=c.posX,p=c.posY;if(s.get(o).includes("e")){const e=d-h;l=Math.max(280,Math.min(c.width+t,e))}if(s.get(o).includes("w")){const e=c.width-280,i=Math.min(t,e);l=c.width-i,h=c.posX+i}if(s.get(o).includes("s")){const e=a-p;u=Math.max(200,Math.min(c.height+n,e))}if(s.get(o).includes("n")){const e=c.height-200,t=Math.min(n,e);u=c.height-t,p=c.posY+t}const f=_(h,p,l,u);s.set(r,{width:f.width,height:f.height},!0),i({x:f.x,y:f.y})}function p(e){e.pointerId===g&&(s.set(n,!1),g=null,window.removeEventListener("pointermove",h),window.removeEventListener("pointerup",p),window.removeEventListener("pointercancel",p),s.set(l,!0),((e,t)=>{const i=de(d.id);if(null==i?void 0:i.parentId){const e=de(i.parentId),n=document.querySelector(`[data-modal-id="${i.parentId}"]`);if(e&&n){const i=e.position??{x:n.getBoundingClientRect().left,y:n.getBoundingClientRect().top},o=e.size??{width:n.offsetWidth,height:n.offsetHeight},r={x:i.x+(o.width-t.width)/2,y:i.y+(o.height-t.height)/2};s.set(ye,!0),me.setPosition(r);const a={x:r.x-i.x,y:r.y-i.y};return Z(d.id,{position:r,size:t,hasBeenDragged:!0,offsetFromParent:a}),void setTimeout(()=>{s.set(ye,!1)},200)}}Z(d.id,{position:e,size:t,hasBeenDragged:!0})})(t(),s.get(r)),setTimeout(()=>{s.set(l,!1)},0))}const f={startResize:u};return{get isResizing(){return s.get(n)},get resizeDirection(){return s.get(o)},get size(){return s.get(r)},get hasBeenResized(){return s.get(a)},get isActive(){return s.get(n)},get justFinishedResizing(){return s.get(l)},start:u,setHasBeenResized:()=>{},setSize:function(e){s.set(r,e,!0),s.set(a,!0)},reset:function(){s.set(a,!1),s.set(r,{width:0,height:0},!0)},constrainToViewport:function(){const n=t(),o=e();if(!o)return;const d=_(n.x,n.y,s.get(r).width||o.offsetWidth,s.get(r).height||o.offsetHeight);s.set(r,{width:d.width,height:d.height},!0),i({x:d.x,y:d.y})},handlers:f}}(()=>s.get(M),()=>me.position,e=>me.setPosition(e)),_e=function(e,t,i,n,o,r,a,l,c){let g=s.state(!1),u=s.state(!1),h=s.state(!1),p=s.state(!1),f=s.state(null),m=s.state(null),v=null,w=null;function y(){w&&(clearTimeout(w),w=null)}function x(){const e=d.id,t=document.querySelector(`.modal-dock-item[data-modal-id="${e}"]`),i=document.querySelector('[data-dock-container="true"]'),n=t||i;if(n){const e=n.getBoundingClientRect();return{x:e.left+e.width/2,y:e.top+e.height/2}}return{x:window.innerWidth/2,y:window.innerHeight-40}}return s.user_effect(()=>()=>{y(),s.set(g,!1),s.set(u,!1),s.set(h,!1),s.set(p,!1),s.set(f,null),s.set(m,null),v=null}),{get isMinimizing(){return s.get(g)},get isRestoring(){return s.get(u)},get isOpening(){return s.get(h)},get isClosing(){return s.get(p)},get animationTransform(){return s.get(f)},get pendingOpenSource(){return s.get(m)},startMinimize:function(e,d){const p=t();if(s.get(g)||!p)return;if(s.set(u,!1),s.set(h,!1),y(),!Ie()){const e=p.getBoundingClientRect();let t=o()?i():{x:e.left,y:e.top},s=a()?l():{width:e.width,height:e.height};return o()||(n(t),r(!0)),void(d?d():c(t,!0,s))}const m=p.getBoundingClientRect(),v=m.left+m.width/2,z=m.top+m.height/2;let I=o()?i():{x:m.left,y:m.top},b=a()?l():{width:m.width,height:m.height};o()||(n(I),r(!0));const _=e??x(),M=_.x-m.left,k=_.y-m.top,D={x:_.x-v,y:_.y-z,originX:M,originY:k};s.set(f,D,!0),requestAnimationFrame(()=>{requestAnimationFrame(()=>{s.set(g,!0)})}),w=setTimeout(()=>{d?d():c(I,!0,b)},500)},startRestore:function(e,t){if(!Ie()){const t=e||{x:window.innerWidth/2,y:window.innerHeight/2};return n(t),void r(!0)}const i=x(),o=e||{x:window.innerWidth/2,y:window.innerHeight/2},d=t||{width:480,height:400};n(o),r(!0);const a=o.x+d.width/2,l=o.y+d.height/2,c=i.x-o.x,g=i.y-o.y;s.set(f,{x:i.x-a,y:i.y-l,originX:c,originY:g},!0),s.set(u,!0),setTimeout(()=>{s.set(u,!1),s.set(f,null)},400)},startClose:function(e){s.get(p)||s.get(g)||(Ie()?(v=e,s.set(p,!0),setTimeout(()=>{s.set(p,!1),v&&(v(),v=null)},250)):e())},setPendingOpenSource:function(e){s.set(m,e,!0)},tryStartOpenAnimation:function(){const e=t();if(!s.get(m)||!e||s.get(h))return!1;if(!Ie())return s.set(m,null),!1;const d=s.get(m);s.set(m,null);const a=e.getBoundingClientRect(),l=o()?i():{x:a.left,y:a.top},c=a.width,g=a.height,u=l.x+c/2,p=l.y+g/2;o()||(n(l),r(!0));const v=d.x-l.x,w=d.y-l.y;return s.set(f,{x:d.x-u,y:d.y-p,originX:v,originY:w},!0),s.set(h,!0),setTimeout(()=>{s.set(h,!1),s.set(f,null)},400),!0},forceClearMinimize:function(){y(),s.set(g,!1),s.set(f,null)}}}(0,()=>s.get(M),()=>me.position,e=>me.setPosition(e),()=>me.hasBeenDragged,e=>me.setHasBeenDragged(e),()=>be.hasBeenResized,()=>be.size,(e,t,i)=>{Z(d.id,{position:e,size:i,hasBeenDragged:t}),V(d.id)}),{trapFocus:De,focusFirstElement:Pe}={trapFocus:Me,focusFirstElement:ke},Ue=s.derived(()=>_e.isMinimizing||_e.isRestoring||_e.isOpening||_e.isClosing),Qe=s.derived(()=>(he(d.id)||ue(d.id))&&!_e.isRestoring);let Je=s.state(!1);const Ze=s.derived(()=>_e.isRestoring||_e.isOpening||s.get(Je)),et=s.derived(()=>s.get(U)&&!me.hasBeenDragged&&!s.get(Ue)&&!_e.pendingOpenSource&&!s.get(Qe)),tt=s.derived(()=>{const e=[];return e.push(`z-index: ${s.get(fe)};`),_e.animationTransform?(e.push(`left: ${me.position.x}px; top: ${me.position.y}px;`),e.push(`--genie-origin-x: ${_e.animationTransform.originX}px;`),e.push(`--genie-origin-y: ${_e.animationTransform.originY}px;`),e.push(`--genie-translate-x: ${_e.animationTransform.x}px;`),e.push(`--genie-translate-y: ${_e.animationTransform.y}px;`)):me.hasBeenDragged&&e.push(`left: ${me.position.x}px; top: ${me.position.y}px; transform: none;`),be.hasBeenResized?e.push(`width: ${be.size.width}px; height: ${be.size.height}px; max-width: none; max-height: none;`):(d.preferredHeight&&e.push(`min-height: ${d.preferredHeight};`),a()&&e.push(`max-width: ${a()};`)),s.get(oe)&&d.glow&&(e.push(`--modal-glow-color: ${d.glow.color};`),e.push(`--modal-glow-intensity: ${d.glow.intensity};`)),e.join(" ")});function it(){s.get(w)&&V(d.id)}function nt(){var e;ce(d.id)&&ge(d.id),ie(d.id),null==(e=d.onClose)||e.call(d)}function ot(){ve(d.id)}function rt(e){s.get(f)&&s.get(M)&&me.onPointerDown(e,s.get(M))}function dt(e){c()&&"Escape"===e.key&&function(e){const t=P.get(e);if(!t)return!1;const i=Math.max(...Array.from(P.values()).map(e=>e.zIndex),0);return t.zIndex===i&&!t.isMinimized&&!t.isHiddenWithParent}(d.id)&&(e.stopPropagation(),nt())}function st(e){if(!s.get(M))return;const t=me.isDragging,i=be.hasBeenResized?be.size:{width:s.get(M).offsetWidth,height:s.get(M).offsetHeight};me.onPointerMove(e,s.get(M),i),me.isDragging&&t&&J(d.id,me.position,{drag:!0})}function at(e){if(!s.get(M))return;const t=me.isDragging;me.onPointerUp(e,s.get(M)),t&&!be.justFinishedResizing&&(J(d.id,me.position,{drag:!0}),function(e){const t=v();if("animated"!==t.parentChild.movementMode)return;const i=t.parentChild.animationDuration,n=[];let o=e;for(;;){const e=P.get(o);if(!(null==e?void 0:e.parentId))break;n.push({parentId:e.parentId,childId:o}),o=e.parentId}n.forEach(({parentId:e,childId:t},n)=>{setTimeout(()=>{const n=P.get(t),o=P.get(e);if(!(null==n?void 0:n.position)||!n.offsetFromParent||!o)return;const r={x:n.position.x-n.offsetFromParent.x,y:n.position.y-n.offsetFromParent.y};Y.set(e,r),function(e){const t=Y.get(e);if(!t)return;const i=P.get(e);i&&(P.set(e,{...i,isAnimatingPosition:!0,position:t}),Y.delete(e),O())}(e),setTimeout(()=>function(e){const t=P.get(e);t&&(P.set(e,{...t,isAnimatingPosition:!1}),O())}(e),i)},n*i)})}(d.id))}function lt(){var e;const t=v();if("smart"!==(null==(e=t.positioning)?void 0:e.strategy))return!1;const i=de(d.id);if(null==i?void 0:i.parentId)return!1;if((null==i?void 0:i.hasBeenDragged)||(null==i?void 0:i.position))return!1;const n=s.get(M)||document.querySelector(`[data-modal-id="${d.id}"]`);if(!n)return!1;const o=n.offsetWidth,r=n.offsetHeight;if(o<=0||r<=0)return!1;const a=t.positioning.modalGap??16,l=function(e){const t=[];for(const[i,n]of P.entries())if(i!==e&&n.isOpen&&!n.isMinimized&&!n.isHiddenWithParent)if(n.position&&n.size)t.push({x:n.position.x,y:n.position.y,width:n.size.width,height:n.size.height});else{const e=document.querySelector(`[data-modal-id="${String(i)}"]`);if(e){const i=e.getBoundingClientRect();t.push({x:i.left,y:i.top,width:i.width,height:i.height})}}return t}(d.id),c=function(e){if("undefined"==typeof document)return[];const t=[];for(const i of e)try{const e=document.querySelectorAll(i);for(const i of e){const e=i.getBoundingClientRect();e.width>0&&e.height>0&&t.push({x:e.left,y:e.top,width:e.width,height:e.height})}}catch{}return t}(t.positioning.avoidElements??[]),g=function(e,t,i,n={}){const{modalGap:o=16,gridResolution:r=10,avoidBounds:d=[],avoidMargin:s=16}=n,a=n.margin??o,l="undefined"!=typeof window?window.innerWidth:1920,c="undefined"!=typeof window?window.innerHeight:1080,g=d.map(e=>({x:e.x-s,y:e.y-s,width:e.width+2*s,height:e.height+2*s})),u={x:(l-e)/2,y:(c-t)/2};if(0===i.length&&0===g.length)return u;const h=a,p=Math.max(a,l-e-a),f=a,m=Math.max(a,c-t-a);if(p<=h||m<=f)return u;const v=k(u.x,u.y,e,t,i,o),w=k(u.x,u.y,e,t,g,0);if(0===v&&0===w)return u;const y=[],x=(p-h)/r,z=(m-f)/r;for(let n=0;n<=r;n++)for(let d=0;d<=r;d++){const r=h+n*x,s=f+d*z,u=k(r,s,e,t,i,o),p=k(r,s,e,t,g,0),m=D(r,s,e,t,l,c,a);y.push({pos:{x:r,y:s},modalOverlap:u,avoidOverlap:p,centerDist:m})}const I=y.filter(e=>0===e.avoidOverlap),b=I.length>0?I:y,_=e*t,M=Math.min(...b.map(e=>e.modalOverlap))/_;return b.sort((e,t)=>{if(0===I.length&&e.avoidOverlap!==t.avoidOverlap)return e.avoidOverlap-t.avoidOverlap;const i=e.modalOverlap/_,n=t.modalOverlap/_;if(M<.3){const o=.3,r=i<=o,d=n<=o;if(r&&d)return e.centerDist+.3*i-(t.centerDist+.3*n);if(r)return-1;if(d)return 1}return.6*i+.4*e.centerDist-(.6*n+.4*t.centerDist)}),b[0].pos}(o,r,l,{modalGap:a,avoidBounds:c});if(k(g.x,g.y,o,r,l,a)/(o*r)>.1&&l.length>0){const e=function(e){const t=[];for(const[i,n]of P.entries())if(i!==e&&n.isOpen&&!n.isMinimized&&!n.isHiddenWithParent&&!n.parentId)if(n.position&&n.size)t.push({id:String(i),x:n.position.x,y:n.position.y,width:n.size.width,height:n.size.height});else{const e=document.querySelector(`[data-modal-id="${String(i)}"]`);if(e){const n=e.getBoundingClientRect();t.push({id:String(i),x:n.left,y:n.top,width:n.width,height:n.height})}}return t}(d.id),t=function(e,t,i,n={}){const{modalGap:o=16}=n,r=n.margin??o,d="undefined"!=typeof window?window.innerWidth:1920,s="undefined"!=typeof window?window.innerHeight:1080,a=i.reduce((e,t)=>e+t.width,0)+e,l=i.length*o,c=d-2*r;if(a+l>c)return null;const g=c-a-l;i.length;const u=g/2,h=d/2,p=[...i.map(e=>({id:e.id,width:e.width,height:e.height,currentX:e.x+e.width/2,currentY:e.y,isNew:!1})),{id:"__new__",width:e,height:t,currentX:h,currentY:(s-t)/2,isNew:!0}];p.sort((e,t)=>e.currentX-t.currentX);let f=r+u;const m=new Map;let v=null;for(const e of p){const t=f;if(e.isNew)v={x:Math.round(t),y:Math.round(e.currentY)};else{const n=i.find(t=>t.id===e.id);Math.abs(t-n.x)>5&&m.set(e.id,{x:Math.round(t),y:Math.round(n.y)})}f+=e.width+o}return v?{newModalPosition:v,existingModalMoves:m}:null}(o,r,e,{modalGap:a});if(t&&t.existingModalMoves.size>0)return function(e){const t=v().parentChild.animationDuration;for(const[t,i]of e){const e=P.get(t);e&&P.set(t,{...e,position:i,isAnimatingPosition:!0,hasBeenDragged:!0})}O(),setTimeout(()=>{for(const t of e.keys()){const e=P.get(t);e&&P.set(t,{...e,isAnimatingPosition:!1})}O()},t)}(t.existingModalMoves),me.setPosition(t.newModalPosition),me.setHasBeenDragged(!0),J(d.id,t.newModalPosition,{size:{width:o,height:r}}),!0}return me.setPosition(g),me.setHasBeenDragged(!0),J(d.id,g,{size:{width:o,height:r}}),!0}function ct(){n().then(()=>n()).then(()=>{let e=0;const t=()=>{e+=1,lt()||e>5||requestAnimationFrame(t)};s.get(M)?t():requestAnimationFrame(t)})}e(()=>{var e;function t(){const e=de(d.id);if(!(null==e?void 0:e.position)||!s.get(M))return;if(e.parentId)return;const t=be.hasBeenResized?be.size.width:s.get(M).offsetWidth,i=be.hasBeenResized?be.size.height:s.get(M).offsetHeight;if(t<=0||i<=0)return;const n=b(e.position.x,e.position.y,t,i);(Math.abs(n.x-e.position.x)>1||Math.abs(n.y-e.position.y)>1)&&(me.setPosition(n),J(d.id,n))}return g()||(e=l(),G({id:d.id,title:d.title,icon:d.icon??"",isOpen:e,isMinimized:!1,isHiddenWithParent:!1,isTransparent:!1,isRejected:!1,position:null,size:null,hasBeenDragged:!1,dockPosition:0,glow:d.glow??null,parentId:void 0,childId:void 0,offsetFromParent:void 0}),e&&ee(d.id)),l()&&(n().then(()=>{s.get(M)&&Pe(s.get(M))}),ct()),window.addEventListener("pointermove",st),window.addEventListener("pointerup",at),window.addEventListener("resize",t),()=>{window.removeEventListener("pointermove",st),window.removeEventListener("pointerup",at),window.removeEventListener("resize",t)}}),o(()=>{we(d.id),g()||K(d.id)}),s.user_effect(()=>{se();const e=de(d.id);if(e){if(s.set(C,e.isTransparent,!0),!me.isDragging&&!be.isResizing&&e.position){const t=me.position,i=e.position;(Math.abs(t.x-i.x)>.5||Math.abs(t.y-i.y)>.5)&&(me.setPosition(i),e.hasBeenDragged&&me.setHasBeenDragged(!0))}n().then(()=>function(){var e,t;if(!de(d.id))return;if(ce(d.id))return ge(d.id),void(null==(e=d.onClose)||e.call(d));if(re(d.id)&&!s.get(q)){if(s.set(q,!0),s.get($),s.set($,null),s.get(M)){const e=s.get(M).getBoundingClientRect(),t=me.hasBeenDragged?me.position:{x:e.left,y:e.top},i=be.hasBeenResized?be.size:{width:e.width,height:e.height};Z(d.id,{position:t,size:i,hasBeenDragged:!0})}_e.startMinimize(void 0,()=>{var e;e=d.id,s.get(R).includes(e)&&s.set(R,s.get(R).filter(t=>t!==e),!0),s.set(q,!1)})}if(ue(d.id)){t=d.id,s.get(S).includes(t)&&s.set(S,s.get(S).filter(e=>e!==t),!0);const e=de(d.id);_e.startRestore((null==e?void 0:e.position)??void 0,(null==e?void 0:e.size)??void 0),n().then(()=>{s.get(M)&&Pe(s.get(M))})}if(he(d.id)){!function(e){s.get(L).includes(e)&&s.set(L,s.get(L).filter(t=>t!==e),!0)}(d.id);const e=de(d.id);_e.startRestore((null==e?void 0:e.position)??void 0,(null==e?void 0:e.size)??void 0)}if(le(d.id)&&(function(e){s.get(E).includes(e)&&s.set(E,s.get(E).filter(t=>t!==e),!0)}(d.id),_e.startClose(()=>{var e;we(d.id),function(e){const t=P.get(e);if(t){if(t.parentId){const i=P.get(t.parentId);i&&i.childId===e&&P.set(t.parentId,{...i,childId:void 0,lastChildId:e})}P.set(e,{...t,isOpen:!1,isMinimized:!1,isHiddenWithParent:!1,isTransparent:!1,position:null,size:null,hasBeenDragged:!1,parentId:void 0,childId:void 0,offsetFromParent:void 0}),O()}}(d.id),null==(e=d.onClose)||e.call(d)})),ae(d.id)){!function(e){s.get(T).includes(e)&&s.set(T,s.get(T).filter(t=>t!==e),!0)}(d.id);const e=function(e){const t=F.get(e);return t&&F.delete(e),t??null}(d.id)||d.openSourcePosition||null;e?(_e.setPendingOpenSource(e),n().then(()=>n()).then(()=>{lt(),_e.tryStartOpenAnimation()})):ct(),n().then(()=>{s.get(M)&&Pe(s.get(M))})}(function(e){return s.get(W).includes(e)})(d.id)&&(function(e){s.get(W).includes(e)&&s.set(W,s.get(W).filter(t=>t!==e),!0)}(d.id),function(e){s.get(A).includes(e)||s.set(A,[...s.get(A),e],!0)}(d.id),s.set(N,!0),setTimeout(()=>{s.set(N,!1),function(e){s.set(A,s.get(A).filter(t=>t!==e),!0)}(d.id)},600));const i=function(e){if(!s.get(X)||s.get(X).childId!==e)return null;const t=s.get(X);return s.set(X,null),t}(d.id);var o;i&&s.get(M)&&(o=i.parentId,n().then(()=>n()).then(()=>{let e=0;const t=()=>{e+=1;const i=function(e){var t,i;const n=de(e);if(!n)return!1;const o=s.get(M)||document.querySelector(`[data-modal-id="${d.id}"]`),r=document.querySelector(`[data-modal-id="${e}"]`),a=null==r?void 0:r.getBoundingClientRect(),l=n.position??(a?{x:a.left,y:a.top}:null);if(!l||!o)return!1;const c=(null==(t=n.size)?void 0:t.width)??(null==r?void 0:r.offsetWidth)??(null==a?void 0:a.width)??480,g=(null==(i=n.size)?void 0:i.height)??(null==r?void 0:r.offsetHeight)??(null==a?void 0:a.height)??400,u=o.offsetWidth,h=o.offsetHeight;if(c<=0||g<=0||u<=0||h<=0)return!1;const p={x:l.x+(c-u)/2,y:l.y+(g-h)/2};return me.setPosition(p),me.setHasBeenDragged(!0),J(d.id,p,{size:{width:u,height:h}}),n.position&&n.size||!a||J(e,{x:a.left,y:a.top},{size:{width:c,height:g}}),function(e,t){if(!v().features.parentChild)return;const i=P.get(e),n=P.get(t);if(!i||!n)return;let o={x:40,y:40};i.position&&n.position&&(o={x:n.position.x-i.position.x,y:n.position.y-i.position.y});const r=Math.max(n.zIndex,i.zIndex+1);P.set(e,{...i,childId:t,lastChildId:t}),P.set(t,{...n,parentId:e,offsetFromParent:o,zIndex:r}),O()}(e,d.id),!0}(o);i||e>5||requestAnimationFrame(t)};s.get(M)?t():requestAnimationFrame(t)}))}())}}),s.user_effect(()=>{const e=de(d.id);e&&e.isTransparent!==s.get(C)&&s.set(C,e.isTransparent,!0)}),s.user_effect(()=>{if(s.get(U)&&s.get(M)){const e=e=>function(e){s.get(M)&&De(e,s.get(M))}(e);return s.get(M).addEventListener("keydown",e),()=>{var t;return null==(t=s.get(M))?void 0:t.removeEventListener("keydown",e)}}}),s.user_effect(()=>{!s.get(U)&&_e.isMinimizing&&_e.forceClearMinimize()}),s.user_effect(()=>{_e.isRestoring||_e.isOpening?s.set(Je,!0):s.get(Je)&&requestAnimationFrame(()=>{s.set(Je,!1)})}),s.user_effect(()=>{s.get(H)&&!s.get(Q)&&(s.set(B,!0),setTimeout(()=>{s.set(B,!1)},200)),s.set(H,s.get(Q),!0)});var gt=s.comment(),ut=s.first_child(gt),ht=e=>{Ce(e,{get target(){return u},children:(e,i)=>{var n=Ve();let o;n.__keydown=dt;var r=s.child(n);{let e=s.derived(()=>s.get(f)?rt:void 0);!function(e,i){s.push(i,!0);let n=s.prop(i,"isTransparent",3,!1),o=s.prop(i,"headerLayout",3,"macos"),r=s.prop(i,"minimizable",3,!0),d=s.prop(i,"minimizeDisabled",3,!1),a=s.prop(i,"transparencyEnabled",3,!0);const l=t(xe),c=s.derived(()=>null==l?void 0:l()),g=s.derived(()=>"macos"===o());var u=qe();let h;u.__pointerdown=function(e){var t;e.target.closest("button")||null==(t=i.onStartDrag)||t.call(i,e)};var p=s.child(u),f=e=>{var t=Se(),n=s.first_child(t),o=s.child(n);o.__click=function(...e){var t;null==(t=i.onClose)||t.apply(this,e)};var l=s.sibling(o,2),g=e=>{var t=Be();let n;t.__click=function(...e){var t;null==(t=d()?void 0:i.onMinimize)||t.apply(this,e)},s.template_effect(()=>{n=s.set_class(t,1,"modal-header-light modal-header-light-minimize",null,n,{"modal-header-light-disabled":d()}),t.disabled=d(),s.set_attribute(t,"title",d()?"Enable dock to minimize":void 0)}),s.append(e,t)};s.if(l,e=>{r()&&e(g)});var u=s.sibling(l,2),h=e=>{var t=Oe();t.__click=function(...e){var t;null==(t=i.onToggleStyle)||t.apply(this,e)},s.append(e,t)};s.if(u,e=>{a()&&e(h)}),s.reset(n);var p=s.sibling(n,2),f=s.child(p),m=e=>{var t=Re(),n=s.child(t);s.snippet(n,()=>i.customIcon),s.reset(t),s.append(e,t)},v=e=>{var t=s.comment(),n=s.first_child(t),o=e=>{var t=Te(),n=s.child(t);s.snippet(n,()=>s.get(c),()=>i.icon),s.reset(t),s.append(e,t)};s.if(n,e=>{i.icon&&s.get(c)&&e(o)},!0),s.append(e,t)};s.if(f,e=>{i.customIcon?e(m):e(v,!1)});var w=s.sibling(f,2),y=s.child(w),x=e=>{var t=Ee(),n=s.child(t,!0);s.reset(t),s.template_effect(()=>{s.set_attribute(t,"id",i.titleId),s.set_text(n,i.title)}),s.append(e,t)},z=e=>{var t=He(),n=s.child(t,!0);s.reset(t),s.template_effect(()=>s.set_text(n,i.title)),s.append(e,t)};s.if(y,e=>{i.titleId?e(x):e(z,!1)}),s.reset(w),s.reset(p),s.next(2),s.append(e,t)},m=e=>{var t=Ye(),n=s.first_child(t),o=s.child(n),l=e=>{var t=Le(),n=s.child(t);s.snippet(n,()=>i.customIcon),s.reset(t),s.append(e,t)},g=e=>{var t=s.comment(),n=s.first_child(t),o=e=>{var t=We(),n=s.child(t);s.snippet(n,()=>s.get(c),()=>i.icon),s.reset(t),s.append(e,t)};s.if(n,e=>{i.icon&&s.get(c)&&e(o)},!0),s.append(e,t)};s.if(o,e=>{i.customIcon?e(l):e(g,!1)});var u=s.sibling(o,2),h=e=>{var t=Ae(),n=s.child(t,!0);s.reset(t),s.template_effect(()=>{s.set_attribute(t,"id",i.titleId),s.set_text(n,i.title)}),s.append(e,t)},p=e=>{var t=$e(),n=s.child(t,!0);s.reset(t),s.template_effect(()=>s.set_text(n,i.title)),s.append(e,t)};s.if(u,e=>{i.titleId?e(h):e(p,!1)}),s.reset(n);var f=s.sibling(n,2),m=s.child(f),v=e=>{var t=Fe();t.__click=function(...e){var t;null==(t=i.onToggleStyle)||t.apply(this,e)},s.append(e,t)};s.if(m,e=>{a()&&e(v)});var w=s.sibling(m,2),y=e=>{var t=Xe();let n;t.__click=function(...e){var t;null==(t=d()?void 0:i.onMinimize)||t.apply(this,e)},s.template_effect(()=>{n=s.set_class(t,1,"modal-header-btn-windows",null,n,{"modal-header-btn-windows-disabled":d()}),t.disabled=d(),s.set_attribute(t,"title",d()?"Enable dock to minimize":void 0)}),s.append(e,t)};s.if(w,e=>{r()&&e(y)}),s.sibling(w,2).__click=function(...e){var t;null==(t=i.onClose)||t.apply(this,e)},s.reset(f),s.append(e,t)};s.if(p,e=>{s.get(g)?e(f):e(m,!1)}),s.reset(u),s.template_effect(()=>h=s.set_class(u,1,"modal-header",null,h,{"modal-header-draggable":!!i.onStartDrag,transparent:n()})),s.append(e,u),s.pop()}(r,{get title(){return d.title},get customIcon(){return d.customIcon},get icon(){return d.icon},get isTransparent(){return s.get(C)},get titleId(){return s.get(pe)},get headerLayout(){return s.get(I)},get onStartDrag(){return s.get(e)},onToggleStyle:ot,onMinimize:it,onClose:nt,get minimizable(){return s.get(w)},get minimizeDisabled(){return s.get(y)},get transparencyEnabled(){return s.get(x)}})}var a=s.sibling(r,2),l=s.child(a);s.snippet(l,()=>d.children??s.noop),s.reset(a);var c=s.sibling(a,2),g=e=>{var t=Ge(),i=s.child(t);s.snippet(i,()=>d.footer),s.reset(t),s.append(e,t)};s.if(c,e=>{d.footer&&e(g)});var u=s.sibling(c,2);{let e=s.derived(()=>s.get(z)&&!s.get(Q)?be.handlers.startResize:void 0);!function(e,t){s.push(t,!0);const i=["n","s","e","w","ne","nw","se","sw"];var n=s.comment(),o=s.first_child(n),r=e=>{var n=je();s.each(n,21,()=>i,s.index,(e,i)=>{var n=Ne();n.__pointerdown=e=>function(e,i){var n;null==(n=t.onStartResize)||n.call(t,e,i)}(e,s.get(i)),s.template_effect(()=>s.set_class(n,1,`modal-resize-handle modal-resize-${s.get(i)??""}`)),s.append(e,n)}),s.reset(n),s.append(e,n)};s.if(o,e=>{t.onStartResize&&e(r)}),s.append(e,n),s.pop()}(u,{get onStartResize(){return s.get(e)}})}var h=s.sibling(u,2),p=e=>{var t=Ke();let i;s.template_effect(()=>i=s.set_class(t,1,"modal-child-overlay",null,i,{"modal-overlay-closing":s.get(B)})),s.append(e,t)};s.if(h,e=>{s.get(ne)&&e(p)}),s.reset(n),s.bind_this(n,e=>s.set(M,e),()=>s.get(M)),s.template_effect(()=>{var e;o=s.set_class(n,1,"modal-dialog",null,o,{"modal-dragging":me.isDragging,"modal-resizing":be.isResizing,"modal-positioned":me.hasBeenDragged,"modal-minimizing":_e.isMinimizing,"modal-restoring":_e.isRestoring,"modal-opening":_e.isOpening,"modal-closing":_e.isClosing,"modal-centered":s.get(et),"modal-solid":!s.get(C),"modal-transparent":s.get(C),"modal-glow":s.get(oe),"modal-has-child":s.get(Q),"modal-is-child":s.get(te),"modal-visible-by-animation":s.get(Ze),"modal-animating-to-center":s.get(ye),"modal-animating-position":null==(e=s.get(j))?void 0:e.isAnimatingPosition,"modal-attention":s.get(N)}),s.set_attribute(n,"data-modal-id",d.id),s.set_style(n,s.get(tt)),s.set_attribute(n,"aria-labelledby",s.get(pe))}),s.event("pointerdown",n,()=>ee(d.id),!0),s.append(e,n)},$$slots:{default:!0}})};s.if(ut,e=>{s.get(U)&&e(ht)}),s.append(r,gt),s.pop()}(r,{get id(){return d.id},get title(){return d.title},get icon(){return d.icon},get customIcon(){return d.customIcon},get maxWidth(){return a()},get preferredHeight(){return d.preferredHeight},get autoOpen(){return l()},get openSourcePosition(){return d.openSourcePosition},get glow(){return d.glow},get config(){return d.config},get closeOnEscape(){return c()},get onClose(){return d.onClose},get children(){return d.children},get footer(){return d.footer},skipRegistration:!0})};s.if(f,e=>{s.get(u)&&e(w)}),s.append(r,h),s.pop()}s.delegate(["keydown"]);var Qe=s.from_html('<button type="button" aria-label="Drag dock"></button>'),Je=s.from_html('<span class="modal-dock-item-icon-placeholder"> </span>'),Ze=s.from_html('<span class="modal-dock-item-label"> </span>'),et=s.from_html("<span>+</span>"),tt=s.from_html('<span class="modal-dock-child-indicator"><!></span>'),it=s.from_html('<button><span class="modal-dock-item-icon"><!></span> <!> <span class="modal-dock-item-glow"></span> <!></button>'),nt=s.from_html('<div data-dock-container="true"><div><!> <!></div></div>');function ot(e,i){s.push(i,!0);const n=t(xe),o=s.derived(()=>i.renderIcon??(null==n?void 0:n())),r=me(),d=s.derived(()=>(m(),v())),c=s.derived(()=>z("DOCK")),h=s.derived(()=>s.get(d).dock.position),p=s.derived(()=>s.get(d).dock.labelMode);let f=s.state("horizontal"),w=s.state(s.proxy({x:100,y:100})),y=s.state(null),x=s.state(!1),I={x:0,y:0},_=null;const M=s.derived(()=>(se(),Array.from(r.modals.values()).filter(e=>e.isMinimized).sort((e,t)=>e.dockPosition-t.dockPosition))),k=s.derived(()=>{switch(s.get(h)){case"left":return{x:-20,duration:250,easing:g};case"right":return{x:20,duration:250,easing:g};default:return{y:20,duration:250,easing:g}}});function D(e){var t;"free"===s.get(h)&&(s.set(x,!0),_=e.pointerId,I={x:e.clientX-s.get(w).x,y:e.clientY-s.get(w).y},null==(t=e.currentTarget)||t.setPointerCapture(e.pointerId),window.addEventListener("pointermove",P),window.addEventListener("pointerup",C),window.addEventListener("pointercancel",C))}function P(e){if(e.pointerId!==_||!s.get(y))return;const t=s.get(y).getBoundingClientRect(),i=window.innerWidth-t.width-8,n=window.innerHeight-t.height-8,o=Math.min(Math.max(e.clientX-I.x,8),Math.max(8,i)),r=Math.min(Math.max(e.clientY-I.y,8),Math.max(8,n));s.set(w,{x:Math.round(o),y:Math.round(r)},!0)}function C(e){e.pointerId===_&&(s.set(x,!1),_=null,window.removeEventListener("pointermove",P),window.removeEventListener("pointerup",C),window.removeEventListener("pointercancel",C))}const{addListener:B}=function(){function e(e,t,i){return"undefined"==typeof window?()=>{}:(window.addEventListener(e,t,i),()=>{window.removeEventListener(e,t,i)})}return{addListener:e,addListenerEffect:function(t,i,n){s.user_effect(()=>{if("undefined"!=typeof window)return e(t,i,n)})}}}();function O(){if("free"!==s.get(h)||!s.get(y))return;const e=s.get(y).getBoundingClientRect(),t=b(s.get(w).x,s.get(w).y,e.width,e.height);t.x===s.get(w).x&&t.y===s.get(w).y||s.set(w,{x:Math.round(t.x),y:Math.round(t.y)},!0)}s.user_effect(()=>{"undefined"!=typeof window&&B("resize",O)});var R={setDockOrientation:function(e){s.set(f,e,!0)},setDockFreePosition:function(e){s.set(w,e,!0)},getDockState:function(){return{dockPosition:s.get(h),dockOrientation:s.get(f),dockFreePosition:s.get(w),dockLabelMode:s.get(p)}}};return Ce(e,{get target(){return s.get(d).portalTarget},children:(e,t)=>{var i=nt();let n,d;var g=s.child(i);let m;var v=s.child(g),z=e=>{var t=Qe();let i;t.__pointerdown=D,s.template_effect(()=>i=s.set_class(t,1,"modal-dock-handle",null,i,{"modal-dock-handle-dragging":s.get(x)})),s.append(e,t)};s.if(v,e=>{"free"===s.get(h)&&e(z)});var I=s.sibling(v,2);s.each(I,19,()=>s.get(M),e=>e.id,(e,t,i)=>{const n=s.derived(()=>s.get(t).lastChildId?r.modals.get(s.get(t).lastChildId):null);var d=it();let l;d.__click=e=>{var i;i=s.get(t).id,q.has(i)?e.currentTarget.animate([{transform:"translateX(0)"},{transform:"translateX(-6px)"},{transform:"translateX(6px)"},{transform:"translateX(-6px)"},{transform:"translateX(6px)"},{transform:"translateX(0)"}],{duration:300,easing:"ease-in-out"}):U(s.get(t).id)};var c=s.child(d),g=s.child(c),h=e=>{var i=s.comment(),n=s.first_child(i);s.snippet(n,()=>s.get(o),()=>s.get(t).icon),s.append(e,i)},f=e=>{var i=Je(),n=s.child(i,!0);s.reset(i),s.template_effect(e=>s.set_text(n,e),[()=>s.get(t).title.charAt(0)]),s.append(e,i)};s.if(g,e=>{s.get(t).icon&&s.get(o)?e(h):e(f,!1)}),s.reset(c);var m=s.sibling(c,2),v=e=>{var i=Ze(),n=s.child(i,!0);s.reset(i),s.template_effect(()=>s.set_text(n,s.get(t).title)),s.append(e,i)};s.if(m,e=>{"hidden"!==s.get(p)&&e(v)});var w=s.sibling(m,4),y=e=>{var t=tt(),i=s.child(t),r=e=>{var t=s.comment(),i=s.first_child(t);s.snippet(i,()=>s.get(o),()=>s.get(n).icon),s.append(e,t)},d=e=>{var t=et();s.append(e,t)};s.if(i,e=>{s.get(n).icon&&s.get(o)?e(r):e(d,!1)}),s.reset(t),s.append(e,t)};s.if(w,e=>{s.get(t).lastChildId&&s.get(n)&&e(y)}),s.reset(d),s.template_effect(()=>{l=s.set_class(d,1,"modal-dock-item",null,l,{"modal-dock-item-has-glow":!!s.get(t).glow,"modal-dock-item-has-child":!!s.get(t).lastChildId,"modal-dock-item-label-beside":"beside"===s.get(p),"modal-dock-item-label-below":"below"===s.get(p)}),s.set_attribute(d,"data-modal-id",s.get(t).id),s.set_style(d,s.get(t).glow?`--modal-dock-glow-color: ${s.get(t).glow.color};`:"")}),s.transition(3,d,()=>a,()=>({duration:300,delay:50*s.get(i),easing:u,start:.5})),s.append(e,d)}),s.reset(g),s.reset(i),s.bind_this(i,e=>s.set(y,e),()=>s.get(y)),s.template_effect(()=>{n=s.set_class(i,1,"modal-dock-container",null,n,{"modal-dock-left":"left"===s.get(h),"modal-dock-right":"right"===s.get(h),"modal-dock-bottom":"bottom"===s.get(h),"modal-dock-free":"free"===s.get(h),"modal-dock-empty":0===s.get(M).length}),d=s.set_style(i,"free"===s.get(h)?`left: ${s.get(w).x}px; top: ${s.get(w).y}px;`:"",d,{"z-index":s.get(c)}),m=s.set_class(g,1,"modal-dock",null,m,{"modal-dock-free-horizontal":"free"===s.get(h)&&"horizontal"===s.get(f),"modal-dock-free-vertical":"free"===s.get(h)&&"vertical"===s.get(f)})}),s.transition(3,i,()=>l,()=>s.get(M).length>0?s.get(k):{duration:0}),s.append(e,i)},$$slots:{default:!0}}),s.pop(R)}s.delegate(["pointerdown","click"]);var rt=s.from_html('<div class="modal-backdrop svelte-1d3nq4t" aria-hidden="true"></div>');function dt(e,t){s.push(t,!0);const i=me(),n=s.derived(()=>(m(),v())),o=s.derived(()=>s.get(n).features.backdrop),r=s.derived(()=>(se(),Array.from(i.modals.values()).some(e=>e.isOpen&&!e.isMinimized&&!e.isHiddenWithParent))),d=s.derived(()=>s.get(o)&&s.get(r)),a=s.derived(()=>z("MODAL")-1);Ce(e,{get target(){return s.get(n).portalTarget},children:(e,t)=>{var i=s.comment(),n=s.first_child(i),o=e=>{var t=rt();let i;s.template_effect(()=>i=s.set_style(t,"",i,{"z-index":s.get(a)})),s.transition(3,t,()=>c,()=>({duration:200})),s.append(e,t)};s.if(n,e=>{s.get(d)&&e(o)}),s.append(e,i)},$$slots:{default:!0}}),s.pop()}function st(e){const{content:t,footer:i,icon:n,...o}=e,s=r(Ue,{target:document.body,props:{...o,children:t?()=>lt(t):void 0,footer:i?()=>lt(i):void 0,icon:n?()=>lt(n):void 0}});return{destroy:()=>d(s)}}function at(){const e=r(ot,{target:document.body,props:{}});return{destroy:()=>d(e)}}function lt(e){if("string"==typeof e){const t=document.createElement("div");return t.innerHTML=e,t}return e}function ct(){const e=r(dt,{target:document.body,props:{}});return{destroy:()=>d(e)}}function gt(e={}){const{config:t}=e;t&&w(t),s.set(x,v().zIndex.base,!0);const i=v(),n=e.backdrop??i.features.backdrop?ct():null,o=e.dock??i.features.dock?at():null;return{backdrop:n,dock:o,destroy:()=>{null==n||n.destroy(),null==o||o.destroy()}}}export{ee as bringToFront,ne as closeAllModals,ie as closeModal,ct as createBackdrop,at as createDock,st as createModal,v as getConfig,gt as init,pe as isModalOpen,fe as isModalRegistered,V as minimizeModal,oe as openChildModal,te as openModal,U as restoreModal,w as setConfig,ve as toggleModalTransparency};
package/package.json ADDED
@@ -0,0 +1,89 @@
1
+ {
2
+ "name": "epic-modals",
3
+ "version": "0.0.4",
4
+ "description": "A stunning modal library with macOS-style animations, drag, resize, and dock. Supports Svelte 5, React, and vanilla JS.",
5
+ "keywords": [
6
+ "modal",
7
+ "dialog",
8
+ "svelte",
9
+ "react",
10
+ "vanilla",
11
+ "draggable",
12
+ "resizable",
13
+ "dock",
14
+ "macos",
15
+ "animations"
16
+ ],
17
+ "author": "Damian Lesiuk",
18
+ "license": "Elastic-2.0",
19
+ "homepage": "https://epicmodals.eu",
20
+ "type": "module",
21
+ "main": "./dist/index.js",
22
+ "module": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "default": "./dist/index.js"
28
+ },
29
+ "./svelte": {
30
+ "types": "./dist/svelte.d.ts",
31
+ "svelte": "./dist/svelte.js",
32
+ "default": "./dist/svelte.js"
33
+ },
34
+ "./react": {
35
+ "types": "./dist/react.d.ts",
36
+ "default": "./dist/react.js"
37
+ },
38
+ "./vanilla": {
39
+ "types": "./dist/vanilla.d.ts",
40
+ "default": "./dist/vanilla.js"
41
+ },
42
+ "./styles": "./dist/styles/index.css",
43
+ "./styles/themes/light": "./dist/styles/themes/light.css",
44
+ "./styles/themes/dark": "./dist/styles/themes/dark.css"
45
+ },
46
+ "files": [
47
+ "dist",
48
+ "!dist/**/*.map",
49
+ "LICENSE"
50
+ ],
51
+ "scripts": {
52
+ "dev": "vite dev",
53
+ "build": "ENTRY=index vite build --mode development && ENTRY=svelte vite build --mode development && ENTRY=react vite build --mode development && ENTRY=vanilla vite build --mode development",
54
+ "build:prod": "ENTRY=index vite build && ENTRY=svelte vite build && ENTRY=react vite build && ENTRY=vanilla vite build && node scripts/build-css.js",
55
+ "check": "svelte-check --tsconfig ./tsconfig.json",
56
+ "test": "vitest run",
57
+ "test:watch": "vitest",
58
+ "test:e2e": "playwright test",
59
+ "test:e2e:ui": "playwright test --ui",
60
+ "test:e2e:headed": "playwright test --headed"
61
+ },
62
+ "peerDependencies": {
63
+ "react": "^18.0.0 || ^19.0.0",
64
+ "react-dom": "^18.0.0 || ^19.0.0",
65
+ "svelte": "^5.0.0"
66
+ },
67
+ "peerDependenciesMeta": {
68
+ "react": {
69
+ "optional": true
70
+ },
71
+ "react-dom": {
72
+ "optional": true
73
+ }
74
+ },
75
+ "devDependencies": {
76
+ "@rollup/plugin-terser": "^0.4.4",
77
+ "lightningcss": "^1.30.0",
78
+ "@sveltejs/vite-plugin-svelte": "^5.0.0",
79
+ "@types/react": "^19.2.8",
80
+ "@types/react-dom": "^19.2.3",
81
+ "svelte": "^5.0.0",
82
+ "svelte-check": "^4.0.0",
83
+ "terser": "^5.46.0",
84
+ "typescript": "^5.6.0",
85
+ "vite": "^6.0.0",
86
+ "vite-plugin-dts": "^4.5.4",
87
+ "vitest": "^4.0.17"
88
+ }
89
+ }