"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("three"),r=require("@react-three/fiber"),n=require("../../core/Line.cjs.js"),o=require("../Html.cjs.js"),a=require("./context.cjs.js");function i(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}require("@babel/runtime/helpers/extends"),require("three-stdlib"),require("react-dom/client");var s=i(e),c=i(t);const l=new c.Ray,u=new c.Vector3,d=new c.Matrix4;exports.PlaneSlider=({dir1:e,dir2:t,axis:i})=>{const{translation:p,translationLimits:m,annotations:x,annotationsClass:b,depthTest:g,scale:f,lineWidth:h,fixed:M,axisColors:y,hoveredColor:C,opacity:P,renderOrder:v,onDragStart:w,onDrag:O,onDragEnd:j,userData:k}=s.useContext(a.context),F=r.useThree((e=>e.controls)),z=s.useRef(null),E=s.useRef(null),V=s.useRef(null),q=s.useRef(0),D=s.useRef(0),[R,T]=s.useState(!1),S=s.useCallback((e=>{x&&(z.current.innerText=`${p.current[(i+1)%3].toFixed(2)}, ${p.current[(i+2)%3].toFixed(2)}`,z.current.style.display="block"),e.stopPropagation();const t=e.point.clone(),r=(new c.Vector3).setFromMatrixPosition(E.current.matrixWorld),n=(new c.Vector3).setFromMatrixColumn(E.current.matrixWorld,0).normalize(),o=(new c.Vector3).setFromMatrixColumn(E.current.matrixWorld,1).normalize(),a=(new c.Vector3).setFromMatrixColumn(E.current.matrixWorld,2).normalize(),s=(new c.Plane).setFromNormalAndCoplanarPoint(a,r);V.current={clickPoint:t,e1:n,e2:o,plane:s},q.current=p.current[(i+1)%3],D.current=p.current[(i+2)%3],w({component:"Slider",axis:i,origin:r,directions:[n,o,a]}),F&&(F.enabled=!1),e.target.setPointerCapture(e.pointerId)}),[x,F,w,i]),W=s.useCallback((e=>{if(e.stopPropagation(),R||T(!0),V.current){const{clickPoint:t,e1:r,e2:n,plane:o}=V.current,[a,s]=(null==m?void 0:m[(i+1)%3])||[void 0,void 0],[c,b]=(null==m?void 0:m[(i+2)%3])||[void 0,void 0];l.copy(e.ray),l.intersectPlane(o,u),l.direction.negate(),l.intersectPlane(o,u),u.sub(t);let[g,f]=((e,t,r)=>{const n=Math.abs(e.x)>=Math.abs(e.y)&&Math.abs(e.x)>=Math.abs(e.z)?0:Math.abs(e.y)>=Math.abs(e.x)&&Math.abs(e.y)>=Math.abs(e.z)?1:2,o=[0,1,2].sort(((e,r)=>Math.abs(t.getComponent(r))-Math.abs(t.getComponent(e)))),a=n===o[0]?o[1]:o[0],i=e.getComponent(n),s=e.getComponent(a),c=t.getComponent(n),l=t.getComponent(a),u=r.getComponent(n),d=(r.getComponent(a)-u*(s/i))/(l-c*(s/i));return[(u-d*c)/i,d]})(r,n,u);void 0!==a&&(g=Math.max(g,a-q.current)),void 0!==s&&(g=Math.min(g,s-q.current)),void 0!==c&&(f=Math.max(f,c-D.current)),void 0!==b&&(f=Math.min(f,b-D.current)),p.current[(i+1)%3]=q.current+g,p.current[(i+2)%3]=D.current+f,x&&(z.current.innerText=`${p.current[(i+1)%3].toFixed(2)}, ${p.current[(i+2)%3].toFixed(2)}`),d.makeTranslation(g*r.x+f*n.x,g*r.y+f*n.y,g*r.z+f*n.z),O(d)}}),[x,O,R,p,m,i]),$=s.useCallback((e=>{x&&(z.current.style.display="none"),e.stopPropagation(),V.current=null,j(),F&&(F.enabled=!0),e.target.releasePointerCapture(e.pointerId)}),[x,F,j]),_=s.useCallback((e=>{e.stopPropagation(),T(!1)}),[]),L=s.useMemo((()=>{const r=e.clone().normalize(),n=t.clone().normalize();return(new c.Matrix4).makeBasis(r,n,r.clone().cross(n))}),[e,t]),A=M?1/7:f/7,B=M?.225:.225*f,H=R?C:y[i],I=s.useMemo((()=>[new c.Vector3(0,0,0),new c.Vector3(0,B,0),new c.Vector3(B,B,0),new c.Vector3(B,0,0),new c.Vector3(0,0,0)]),[B]);return s.createElement("group",{ref:E,matrix:L,matrixAutoUpdate:!1},x&&s.createElement(o.Html,{position:[0,0,0]},s.createElement("div",{style:{display:"none",background:"#151520",color:"white",padding:"6px 8px",borderRadius:7,whiteSpace:"nowrap"},className:b,ref:z})),s.createElement("group",{position:[1.7*A,1.7*A,0]},s.createElement("mesh",{visible:!0,onPointerDown:S,onPointerMove:W,onPointerUp:$,onPointerOut:_,scale:B,userData:k,renderOrder:v},s.createElement("planeGeometry",null),s.createElement("meshBasicMaterial",{transparent:!0,depthTest:g,color:H,polygonOffset:!0,polygonOffsetFactor:-10,side:c.DoubleSide,fog:!1})),s.createElement(n.Line,{position:[-B/2,-B/2,0],transparent:!0,depthTest:g,points:I,lineWidth:h,color:H,opacity:P,polygonOffset:!0,polygonOffsetFactor:-10,userData:k,fog:!1,renderOrder:v})))};
