/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../chunks/_rollupPluginBabelHelpers","../../../core/clock","../InputHandler","./support"],(function(t,e,i,n,o){"use strict";const r={maximumClickDelay:300,movementUntilMouseDrag:1.5,movementUntilPenDrag:6,movementUntilTouchDrag:6,holdDelay:500};let a=function(t){function n(n=r.maximumClickDelay,o=r.movementUntilMouseDrag,a=r.movementUntilPenDrag,s=r.movementUntilTouchDrag,l=r.holdDelay,m=i.clock){var u;return(u=t.call(this,!1)||this).maximumClickDelay=n,u.movementUntilMouseDrag=o,u.movementUntilPenDrag=a,u.movementUntilTouchDrag=s,u.holdDelay=l,u._clock=m,u._pointerState=new Map,u._pointerDrag=u.registerOutgoing("pointer-drag"),u._immediateClick=u.registerOutgoing("immediate-click"),u._pointerHold=u.registerOutgoing("hold"),u.registerIncoming("pointer-down",u._handlePointerDown.bind(e._assertThisInitialized(u))),u.registerIncoming("pointer-up",(t=>{u._handlePointerLoss(t,"pointer-up")})),u.registerIncoming("pointer-capture-lost",(t=>{u._handlePointerLoss(t,"pointer-capture-lost")})),u.registerIncoming("pointer-cancel",(t=>{u._handlePointerLoss(t,"pointer-cancel")})),u._moveHandle=u.registerIncoming("pointer-move",u._handlePointerMove.bind(e._assertThisInitialized(u))),u._moveHandle.pause(),u}e._inheritsLoose(n,t);var a=n.prototype;return a.onUninstall=function(){this._pointerState.forEach((t=>{null!=t.holdTimeout&&(t.holdTimeout.remove(),t.holdTimeout=null)})),t.prototype.onUninstall.call(this)},a._handlePointerDown=function(t){const e=t.data,i=e.native.pointerId;let n=null;0===this._pointerState.size&&(n=this._clock.setTimeout((()=>{const e=this._pointerState.get(i);if(e){if(!e.isDragging){const i=e.previousEvent;this._pointerHold.emit(i,void 0,t.modifiers),e.holdEmitted=!0}e.holdTimeout=null}}),this.holdDelay));const o={startEvent:e,previousEvent:e,startTimestamp:t.timestamp,isDragging:!1,downButton:e.native.button,holdTimeout:n,modifiers:new Set};this._pointerState.set(i,o),this.startCapturingPointer(e.native),this._moveHandle.resume(),this._pointerState.size>1&&this._startDragging(t)},a._createPointerDragData=function(t,e,i){return{action:t,startEvent:e.startEvent,previousEvent:e.previousEvent,currentEvent:i}},a._handlePointerMove=function(t){const e=t.data,i=e.native.pointerId,n=this._pointerState.get(i);if(n){if(n.isDragging)this._pointerDrag.emit(this._createPointerDragData("update",n,e),void 0,n.modifiers);else{o.euclideanDistance(e,n.startEvent)>this._getDragThreshold(e.native.pointerType)&&this._startDragging(t)}n.previousEvent=e}},a._getDragThreshold=function(t){switch(t){case"touch":return this.movementUntilTouchDrag;case"pen":return this.movementUntilPenDrag;default:return this.movementUntilMouseDrag}},a._startDragging=function(t){const e=t.data,i=e.native.pointerId;this._pointerState.forEach((n=>{null!=n.holdTimeout&&(n.holdTimeout.remove(),n.holdTimeout=null),n.isDragging||(n.modifiers=t.modifiers,n.isDragging=!0,i===n.startEvent.native.pointerId?this._pointerDrag.emit(this._createPointerDragData("start",n,e)):this._pointerDrag.emit(this._createPointerDragData("start",n,n.previousEvent),t.timestamp))}))},a._handlePointerLoss=function(t,e){const i=t.data,n=i.native.pointerId,o=this._pointerState.get(n);if(o){if(null!=o.holdTimeout&&(o.holdTimeout.remove(),o.holdTimeout=null),o.isDragging)this._pointerDrag.emit(this._createPointerDragData("end",o,"pointer-up"===e?i:o.previousEvent),void 0,o.modifiers);else if("pointer-up"===e&&o.downButton===i.native.button){t.timestamp-o.startTimestamp<=this.maximumClickDelay&&!o.holdEmitted&&this._immediateClick.emit(i)}this._pointerState.delete(n),this.stopCapturingPointer(i.native),0===this._pointerState.size&&this._moveHandle.pause()}},n}(n.InputHandler);t.DefaultParameters=r,t.PointerClickHoldAndDrag=a,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
