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