import{i as e}from"./rolldown-runtime-B1FJdls4.js";import{m as t}from"./vendor-dnd-C1cICjTT.js";import{s as n}from"./vendor-markdown-Db1-9wH7.js";var r=e(t(),1),i=n();function a(e){return Math.max(.35,Math.min(4,e))}function o({children:e,className:t=``,contentClassName:n=``,title:o=`Pinch/drag to zoom and pan`,transformOrigin:s=`0 0`,captureGesturesWithOverlay:c=!1}){let[l,u]=(0,r.useState)(1),[d,f]=(0,r.useState)({x:0,y:0}),p=(0,r.useRef)(new Map),m=(0,r.useRef)(null),h=(0,r.useCallback)(()=>{u(1),f({x:0,y:0}),p.current.clear(),m.current=null},[]),g=(0,r.useCallback)((e,t,n)=>{u(r=>{let i=a(e),o=i/r;return f(e=>({x:t-(t-e.x)*o,y:n-(n-e.y)*o})),i})},[]),_=(0,r.useCallback)(e=>{if(!e.ctrlKey&&!e.metaKey)return;e.preventDefault();let t=e.currentTarget.getBoundingClientRect();g(l*Math.exp(-e.deltaY*.0025),e.clientX-t.left,e.clientY-t.top)},[l,g]),v=(0,r.useCallback)(e=>{p.current.set(e.pointerId,{x:e.clientX,y:e.clientY});let t=Array.from(p.current.values());if(t.length>=2){e.preventDefault(),e.stopPropagation();try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}let[n,r]=t,i=e.currentTarget.getBoundingClientRect();m.current={mode:`pinch`,startScale:l,startPan:d,startDistance:Math.hypot(n.x-r.x,n.y-r.y),startCenter:{x:(n.x+r.x)/2-i.left,y:(n.y+r.y)/2-i.top}};return}if(l>1.01||e.altKey||e.button===1){e.preventDefault(),e.stopPropagation();try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}m.current={mode:`pan`,startScale:l,startPan:d,startPointer:{x:e.clientX,y:e.clientY}}}},[d,l]),y=(0,r.useCallback)(e=>{if(!p.current.has(e.pointerId))return;p.current.set(e.pointerId,{x:e.clientX,y:e.clientY});let t=m.current;if(t){if(e.preventDefault(),e.stopPropagation(),t.mode===`pinch`){let n=Array.from(p.current.values());if(n.length<2||!t.startDistance||!t.startCenter)return;let[r,i]=n,o=Math.hypot(r.x-i.x,r.y-i.y),s=e.currentTarget.getBoundingClientRect(),c={x:(r.x+i.x)/2-s.left,y:(r.y+i.y)/2-s.top},l=a(t.startScale*(o/t.startDistance)),d=l/t.startScale;u(l),f({x:c.x-t.startCenter.x+c.x-(c.x-t.startPan.x)*d,y:c.y-t.startCenter.y+c.y-(c.y-t.startPan.y)*d});return}t.startPointer&&f({x:t.startPan.x+e.clientX-t.startPointer.x,y:t.startPan.y+e.clientY-t.startPointer.y})}},[]),b=(0,r.useCallback)(e=>{p.current.delete(e.pointerId),p.current.size===0&&(m.current=null)},[]),x=Math.abs(l-1)>.01,S={onPointerDownCapture:v,onPointerMoveCapture:y,onPointerUpCapture:b,onPointerCancelCapture:b};return(0,i.jsxs)(`div`,{className:`relative overflow-hidden ${t}`,onWheel:_,...c?{}:S,style:{touchAction:x?`none`:`pan-x pan-y pinch-zoom`},title:o,children:[(0,i.jsx)(`div`,{className:`absolute inset-0 ${n}`,style:{transform:`translate3d(${d.x}px, ${d.y}px, 0) scale(${l})`,transformOrigin:s,willChange:x?`transform`:void 0},children:e}),c&&(0,i.jsx)(`div`,{className:`mc-artifact-gesture-layer absolute inset-0 z-10`,...S,style:{touchAction:`none`,pointerEvents:`auto`},"aria-hidden":`true`}),c&&(0,i.jsx)(`style`,{children:`@media (pointer: fine) { .mc-artifact-gesture-layer { pointer-events: none !important; } }`}),x&&(0,i.jsxs)(`button`,{type:`button`,onClick:h,className:`absolute bottom-2 right-2 z-20 rounded-md border border-terminal-border/70 bg-terminal-bg/85 px-2 py-1 text-[10px] font-mono text-terminal-cyan shadow-lg backdrop-blur hover:bg-terminal-surface`,title:`Reset zoom`,children:[Math.round(l*100),`% · Reset`]})]})}var s=r.memo(o);export{s as t};