import{d as $,_ as G,s as N,r as b,A as F,B as _,cb as T,bT as h,c as Z,o as j,w as U,f as W,aj as S,l as O,u as p,n as V}from"./DnBXlrVC.js";import{c as v,E as L,d as C,a as E,u as f,g as w,b as B}from"./b0zdy1x6.js";var I={position:"bottom-right"},k=v("prosekit/resizable/onResize",null),y=v("prosekit/resizable/onResizeStart",null),x=v("prosekit/resizable/onResizeEnd",null);function R(t){return typeof t=="number"&&Number.isFinite(t)&&t>0}function K(t,e,n,r,i,s){switch(s=s||e/n,s=R(s)?s:1,t){case"bottom-right":return X(e,n,r,i,s);case"bottom-left":return Y(e,n,r,i,s);case"top-right":return q(e,n,r,i,s);case"top-left":return J(e,n,r,i,s);case"top":return Q(e,n,r,i,s);case"right":return ee(e,n,r,i,s);case"bottom":return te(e,n,r,i,s);case"left":return ne(e,n,r,i,s);default:throw new RangeError(`Invalid position: ${t}`)}}var X=(t,e,n,r,i)=>{t+=n,e+=r;let s=t+e;return e=s/(i+1),t=s-e,[t,e]},Y=(t,e,n,r,i)=>{t-=n,e+=r;let s=t+e;return e=s/(i+1),t=s-e,[t,e]},q=(t,e,n,r,i)=>{t+=n,e-=r;let s=t+e;return e=s/(i+1),t=s-e,[t,e]},J=(t,e,n,r,i)=>{t-=n,e-=r;let s=t+e;return e=s/(i+1),t=s-e,[t,e]},Q=(t,e,n,r,i)=>(e-=r,t=e*i,[t,e]),ee=(t,e,n,r,i)=>(t+=n,e=t/i,[t,e]),te=(t,e,n,r,i)=>(e+=r,t=e*i,[t,e]),ne=(t,e,n,r,i)=>(t-=n,e=t/i,[t,e]);function se(t,e){let n=k.consume(t),r=y.consume(t),i=x.consume(t);re(t,e,{onResize:n,onResizeStart:r,onResizeEnd:i})}function re(t,e,n){let r=0,i=0,s=0,a=0,l=1,c=E(!1),d=o=>{var u;o.preventDefault(),c.set(!0),r=o.x,i=o.y;let g=(u=n.onResizeStart.get())==null?void 0:u();g&&([s,a,l]=g)},m=o=>{var u;o.preventDefault();let g=o.x-r,D=o.y-i,[M,P]=K(e.position.peek(),s,a,g,D,l);(u=n.onResize.get())==null||u(M,P)},z=o=>{var u;o.preventDefault(),c.set(!1),(u=n.onResizeEnd.get())==null||u()};f(t,()=>(t.addEventListener("pointerdown",d),()=>{t.removeEventListener("pointerdown",d)})),f(t,()=>{if(!c.get())return;let o=w(t);return o.addEventListener("pointermove",m),o.addEventListener("pointerup",z),()=>{o.removeEventListener("pointermove",m),o.removeEventListener("pointerup",z)}})}var ie=class extends L(se,I){};C("prosekit-resizable-handle",ie);var H={width:null,height:null,aspectRatio:null,onSizeChangeStart:null,onSizeChange:null,onSizeChangeEnd:null};function oe(t,e){let n=()=>{var s,a;let{width:l,height:c}=t.getBoundingClientRect(),d=(s=e.aspectRatio.peek())!=null?s:l/c;return R(d)||(d=0),(a=e.onSizeChangeStart.peek())==null||a({width:l,height:c}),[l,c,d]},r=(s,a)=>{var l;(l=e.onSizeChange.peek())==null||l({width:s,height:a}),e.width.set(s),e.height.set(a)},i=()=>{var s;let{width:a,height:l}=t.getBoundingClientRect();(s=e.onSizeChangeEnd.peek())==null||s({width:a,height:l})};y.provide(t,E(n)),k.provide(t,E(r)),x.provide(t,E(i)),f(t,()=>{ae(t,e.width.get(),e.height.get(),e.aspectRatio.get())})}function ae(t,e,n,r){t.style.width=R(e)?`${e}px`:"",t.style.height=R(n)?`${n}px`:"",R(r)&&(t.style.aspectRatio=`${r}`,e&&e>0&&r>=1?t.style.height="auto":n&&n>0&&r<=1&&(t.style.width="auto"))}var le=class extends L(oe,H){};C("prosekit-resizable-root",le);var A=B("prosekit-resizable-handle","ResizableHandle",I),ue=B("prosekit-resizable-root","ResizableRoot",H);const ce=["src","alt"],ze=$({__name:"ProseImage",props:{contentRef:{type:[String,Object,Function]},view:{},getPos:{type:Function},setAttrs:{type:Function},node:{},selected:{},decorations:{},innerDecorations:{}},async setup(t){let e,n;const r=t,{currentAssetsKeys:i}=F(),{storage:s}=G(),a=N(()=>r.node.value.attrs),l=b(r.node.value.attrs.width);let c="";if(a.value.src?.startsWith("/")){const o=`${i.value}${a.value.src}`;let u=([e,n]=_(()=>s.getItem(o)),e=await e,n(),e);typeof u=="string"&&(u=([e,n]=_(()=>T(u)),e=await e,n(),e)),u?c=URL.createObjectURL(u):c=""}else c=a.value.src;const d=b(),m=h(o=>{r.setAttrs(o)},100);function z(o){o.width=Math.round(o.width),l.value=o.width,m(o)}return(o,u)=>(j(),Z(p(ue),{width:p(l)??void 0,"aspect-ratio":p(d),"on-size-change":z,"on-size-change-end":z,class:V(`IMAGE_RESIZABLE ${(!p(d)||p(d)<=1)&&"min-h-[100px]"} ${(!p(d)||p(d)>=1)&&"min-w-[100px]"}`)},{default:U(()=>[W("img",{src:p(c),alt:p(a).alt,style:O(`width: ${p(l)}px;`),class:"IMAGE_RESIZABLE_IMAGE"},null,12,ce),S(p(A),{class:"IMAGE_RESIZABLE_HANDLE_LEFT IMAGE_RESIZABLE_HANDLE",position:"left"}),S(p(A),{class:"IMAGE_RESIZABLE_HANDLE IMAGE_RESIZABLE_HANDLE_RIGHT",position:"right"})]),_:1},8,["width","aspect-ratio","class"]))}});export{ze as _};
