define(['exports', 'preact/jsx-runtime', 'preact/hooks', './clientUtils-8c0e90ff', './useVisDragModeControls-f187d8b2', './hooks/PRIVATE_useChartMarquee/themes/useChartMarquee.css'], (function(t,e,n,r,o,i){"use strict";function a(t,e){return"zoom"===t||"select"===t?"crosshair":"pan"===t?e?"grabbing":"grab":void 0}function s(t,e,n){return t>=n.x&&t<=n.x+n.width&&e>=n.y&&e<=n.y+n.height}function u(t,e,n,r,o){return!(s(t,e,n)||s(t,e,r)||s(t,e,o))}function c({x1:t,y1:n,width:r,height:o}){return e.jsxs(e.Fragment,{children:[e.jsx("rect",{x:t,y:n,width:r,height:o,class:i.styles.visMarquee,"data-oj-private-object":"marquee"}),e.jsx("rect",{x:t+1,y:n+1,width:Math.max(0,r-2),height:Math.max(0,o-2),class:i.styles.visMarqueeInnerArea})]})}t.useChartMarquee=function({plotAreaSpace:t,xSpace:i,ySpace:h,dragMode:x,chartWidth:f,isMultiSelection:l,onViewportChange:m,isZoomScroll:d,xAxisExtent:M,xScale:g,selectedIds:y,getDataById:p,onSelectionChange:v,viewportMax:w,viewportMin:S,isRtl:C,xAxisMinExtent:P}){const z=r.isTouch(),b=n.useRef(!1),q=n.useRef(0),R=n.useRef(),j=function(t,e,n){return!(!n||!t||"user"!==e&&"pan"!==e)}(d,x,z),A=function(t,e,n){return!!t&&(e&&"zoom"===n||!e&&"user"===n)}(d,z,x),B=function(t,e,n,r){return!!t&&(e||"user"!==r&&"select"!==r?"user"===r||n&&"select"===r:n)}(l,d,z,x),{dragButtonDivRef:D,toggleButtonContent:I,userDragMode:E}=o.useVisDragModeControls({componentWidth:f,plotAreaSpace:t,isRtl:C,showPanButton:j,showZoomButton:A,showSelectButton:B,dragMode:x}),[T,V]=n.useState(!1),U=n.useRef(!1),[k,K]=n.useState(),W=n.useRef(new Set),X=function(t,e,n,r,o,i){return null!=o&&t?o:"user"!==r||n?n?"off":r:e?"pan":i?"select":"off"}(j&&"pan"===E||B&&"select"===E||A&&"zoom"===E,d,z,x,E,l),Y=function(t,e,n,r,o,i){if(t&&e){const a=n.x+n.width,u=n.y+n.height;let c=Math.max(Math.min(t.x,e.x),n.x),h=Math.min(Math.max(t.x,e.x),a),x=Math.max(Math.min(t.y,e.y),n.y);const f=Math.min(Math.max(t.y,e.y),u);let l=Math.abs(h-c),m=Math.abs(f-x);return s(t.x,t.y,r)||i?(x=n.y,m=n.height):s(t.x,t.y,o)&&(c=n.x,h=a,l=n.width),{x1:c,y1:x,width:l,height:m,x2:h,y2:f}}}(R.current,k,t,i,h,"zoom"===X);let Z;const F="select"===X&&Y?(t,e)=>{if(R.current?.isMeta&&y?.has(t))return!0;const{x1:n,x2:r,y1:o,y2:i}=Y,{x:a,y:u}=e;return s(a,u,{x:n,width:r-n,y:o,height:i-o})?(W.current?.add(t),!0):(W.current?.delete(t),!1)}:void 0;return!Y||"zoom"!==X&&"select"!==X||(Z=e.jsx(c,{...Y})),{ignoreSelectPointerUp:("pan"===X||"zoom"===X)&&U.current,cursor:a(X,T),yAxisCursor:"zoom"!==X?a(X,T):"initial",marqueeContent:Z,toggleButtonContent:!T&&(!z&&b.current||z)&&I,isPointInsideMarquee:F,dragMode:X,marqueeProps:"off"!=x?{onPointerDown:e=>{if(D?.current?.contains(e.target))return;const n=e.offsetX,r=e.offsetY;V(!0),u(n,r,t,i,h)||"zoom"===X&&s(n,r,h)||(R.current={x:n,y:r})},onPointerMove:e=>{if(!T)return;U.current=!0,e.metaKey&&R.current&&(R.current.isMeta=!0);const n=e.offsetX,r=e.offsetY;if(!(u(n,r,t,i,h)||"zoom"===X&&s(n,r,h))){if("pan"===X&&m&&(!z||z&&1===q.current)){const t=g.invert(n)-g.invert(k?.x||R.current?.x),e=w-S;let r=S-t,o=w-t;r<M.min&&(r=M.min,o=r+e),o>M.max&&(o=M.max,r=o-e),r!=S&&o!=w&&Math.abs(o-r)>P&&m({xMin:r,xMax:o})}K({x:n,y:r})}},onPointerUp:t=>{if(V(!1),K(void 0),R.current=void 0,U.current=!1,!D.current?.contains(t.target)&&Y){if("zoom"===X){const{x1:t,x2:e}=Y;let n=Math.min(g.invert(t),g.invert(e)),r=Math.max(g.invert(t),g.invert(e));if(Math.abs(r-n)<P){const t=(n+r)/2;n=Math.max(M.min,t-P/2),r=Math.min(M.max,n+P)}m?.({xMin:n,xMax:r})}if("select"===X){const e=[...new Set([...W.current,...t.metaKey&&y||new Set])],n=e.map((t=>p(t)));v?.({ids:e,data:n}),W.current=new Set}}},onPointerLeave:t=>{b.current=!1,Y&&z&&"off"!=X&&t.currentTarget.setPointerCapture(t.pointerId)},onPointerEnter:()=>{b.current=!0},onTouchEnd:t=>{V(!1),K(void 0),R.current=void 0,q.current=t.touches.length},onTouchStart:t=>{q.current=t.touches.length}}:{}}}}));
//# sourceMappingURL=useChartMarquee-2f7d51c4.js.map
