import e from"../../_util/raf.mjs";import t from"../../_util/supportsPassive.mjs";import n from"../../vc-util/Dom/addEventListener.mjs";import r from"../../vc-util/devWarning.mjs";import{useInjectTableContext as i}from"../../table/context.mjs";import{computed as a,createVNode as o,defineComponent as s,getCurrentInstance as c,onUnmounted as l,shallowRef as u,watchEffect as d}from"vue";var f={mouse:{start:`mousedown`,move:`mousemove`,stop:`mouseup`},touch:{start:`touchstart`,move:`touchmove`,stop:`touchend`}},p=50,m=s({compatConfig:{MODE:3},name:`DragHandle`,props:{prefixCls:String,width:{type:Number,required:!0},minWidth:{type:Number,default:p},maxWidth:{type:Number,default:1/0},column:{type:Object,default:void 0}},setup(s){let m=0,h={remove:()=>{}},g={remove:()=>{}},_=()=>{h.remove(),g.remove()};l(()=>{_()}),d(()=>{r(!isNaN(s.width),`Table`,`width must be a number when use resizable`)});let{onResizeColumn:v}=i(),y=a(()=>typeof s.minWidth==`number`&&!isNaN(s.minWidth)?s.minWidth:p),b=a(()=>typeof s.maxWidth==`number`&&!isNaN(s.maxWidth)?s.maxWidth:1/0),x=c(),S=0,C=u(!1),w,T=t=>{let n=0;n=t.touches?t.touches.length?t.touches[0].pageX:t.changedTouches[0].pageX:t.pageX;let r=m-n,i=Math.max(S-r,y.value);i=Math.min(i,b.value),e.cancel(w),w=e(()=>{v(i,s.column.__originColumn__)})},E=e=>{T(e)},D=e=>{C.value=!1,T(e),_()},O=(e,t)=>{C.value=!0,_(),S=x.vnode.el.parentNode.getBoundingClientRect().width,!(e instanceof MouseEvent&&e.which!==1)&&(e.stopPropagation&&e.stopPropagation(),m=e.touches?e.touches[0].pageX:e.pageX,h=n(document.documentElement,t.move,E),g=n(document.documentElement,t.stop,D))},k=e=>{e.stopPropagation(),e.preventDefault(),O(e,f.mouse)},A=e=>{e.stopPropagation(),e.preventDefault(),O(e,f.touch)},j=e=>{e.stopPropagation(),e.preventDefault()};return()=>{let{prefixCls:e}=s,n={[t?`onTouchstartPassive`:`onTouchstart`]:e=>A(e)};return o(`div`,{class:`${e}-resize-handle ${C.value?`dragging`:``}`,onMousedown:k,...n,onClick:j},[o(`div`,{class:`${e}-resize-handle-line`},null)])}}});export{m as default};