// All material copyright Esri, All Rights Reserved, unless otherwise specified. // See https://js.arcgis.com/4.30/esri/copyright.txt for details. //>>built define("../../chunks/tslib.es6 ../../core/Evented ../../core/accessorSupport/decorators/property ../../core/accessorSupport/decorators/subclass ./constants ./css ./utils ../support/GoTo".split(" "),function(e,d,f,k,l,m,g,n){d=class extends n.GoToMixin(d.EventedAccessor){constructor(b){super(b);this._widgetCenter=this._movementVector=this._initialAngle=void 0;this._anyAngleMovementEnabled=!1;this._movementTimeout=void 0;this._disabled=!1;this._moveOnceDuration=l.directionalPadMoveOnceDuration;this.angle= void 0;this.speed=1;this.beginFollowingPointer=(a,c)=>{this.disabled||(this._widgetCenter=c,c=this._pointerLocationToVector(a),void 0!==c&&(a=this._resolveClosestAngle(a,c),void 0!==a&&(this._emitMove(g.angleToUnitVector(a)),this._initialAngle=this.angle=a,this._setMovementTimeout(()=>{void 0===this._widgetCenter&&this._stopMovement()}),document.addEventListener("pointermove",this._onPointerMove,{passive:!0}),document.addEventListener("pointerup",this._onPointerUp,{passive:!0,once:!0}))))};this.moveOnce= a=>{a=g.angleToUnitVector(a);this._emitMove(a);this._setMovementTimeout(this._stopMovement)};this._pointerLocationToVector=a=>{if(void 0!==this._widgetCenter){var {x:c,y:h}=g.toUnitVector(this._widgetCenter,a);return{x:c,y:-h}}};this._resolveClosestAngle=(a,c)=>{a=a.target;const h=a?.getAttribute?.("data-angle");if(!a?.classList?.contains(m.css.compassButton))return a=Number.parseInt(h??"",10),Number.isNaN(a)?g.vectorToClosestAngle(c):a};this._onPointerMove=a=>{if(0===a.buttons)this._stopMovement(); else{var c=this._pointerLocationToVector(a);if(void 0!==c)if(this._setMovementTimeout(void 0),a=this._resolveClosestAngle(a,c),void 0===a)this._emitStop();else{var h=g.angleToUnitVector(a),p=null!=this._initialAngle&&this._initialAngle!==a;this._anyAngleMovementEnabled||(this._anyAngleMovementEnabled=p);c=this._anyAngleMovementEnabled?c:h;if(c.x!==this._movementVector?.x||c.y!==this._movementVector?.y)this.angle=a,this._emitMove(c)}}};this._onPointerUp=()=>{void 0===this._movementTimeout?this._stopMovement(): this._widgetCenter=void 0};this._stopMovement=()=>{this._emitStop();this._initialAngle=this._widgetCenter=void 0;this._anyAngleMovementEnabled=!1;document.removeEventListener("pointermove",this._onPointerMove);document.removeEventListener("pointerup",this._stopMovement);this._setMovementTimeout(void 0)};this.on("move-start",()=>this.view?.mapViewNavigation.begin());this.on("move-direction-change",({vector:{x:a,y:c}})=>this.view?.mapViewNavigation.continuousPanVector({x:a*this.speed,y:c*this.speed})); this.on("move-stop",()=>this.view?.mapViewNavigation.stop())}destroy(){this._stopMovement()}get disabled(){const {view:b,_disabled:a,supported:c}=this;return!1===b?.ready||a||!c}set disabled(b){this._disabled=b}get rotation(){return this.view?.rotation??this._get("rotation")??0}set rotation(b){this.view?this.view.constraints.rotationEnabled&&this.callGoTo({target:{rotation:b},options:{animate:0===b?void 0:!1}}):this._set("rotation",b)}get supported(){return null==this.view||"2d"===this.view.type}get state(){const {disabled:b, angle:a}=this;return b?"disabled":null!=a?"moving":"ready"}_setMovementTimeout(b){clearTimeout(this._movementTimeout);this._movementTimeout=void 0===b?void 0:setTimeout(()=>{this._movementTimeout=void 0;b()},this._moveOnceDuration)}_emitMove(b){null==this._movementVector&&this._emitMoveStartEvent({vector:b});const a=this._movementVector;this._movementVector=b;this._emitMoveDirectionChangeEvent({vector:b,oldVector:a})}_emitStop(){this.angle=void 0;void 0!==this._movementVector&&(this._emitMoveStopEvent({oldVector:this._movementVector}), this._movementVector=void 0)}_emitMoveStartEvent(b){this.emit("move-start",{...b,type:"move-start"})}_emitMoveDirectionChangeEvent(b){this.emit("move-direction-change",{...b,type:"move-direction-change"})}_emitMoveStopEvent(b){this.emit("move-stop",{...b,type:"move-stop"})}};e.__decorate([f.property()],d.prototype,"_initialAngle",void 0);e.__decorate([f.property()],d.prototype,"_movementVector",void 0);e.__decorate([f.property()],d.prototype,"_widgetCenter",void 0);e.__decorate([f.property()],d.prototype, "_anyAngleMovementEnabled",void 0);e.__decorate([f.property()],d.prototype,"_movementTimeout",void 0);e.__decorate([f.property()],d.prototype,"_disabled",void 0);e.__decorate([f.property()],d.prototype,"_moveOnceDuration",void 0);e.__decorate([f.property()],d.prototype,"disabled",null);e.__decorate([f.property()],d.prototype,"angle",void 0);e.__decorate([f.property({type:Number,range:{min:0,max:100}})],d.prototype,"speed",void 0);e.__decorate([f.property()],d.prototype,"rotation",null);e.__decorate([f.property()], d.prototype,"supported",null);e.__decorate([f.property({readOnly:!0})],d.prototype,"state",null);e.__decorate([f.property()],d.prototype,"view",void 0);return d=e.__decorate([k.subclass("esri.widgets.DirectionalPad.DirectionalPadViewModel")],d)});