/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{remove as e}from"../../core/arrayUtils.js";import{makeHandle as t,handlesGroup as o}from"../../core/handleUtils.js";import{getOrCreateMapValue as i}from"../../core/MapUtils.js";import{ViewEventPriorities as r}from"../input/InputManager.js";import{primaryKey as n}from"../input/keys.js";const s="z",a="r",p={cancel:"Escape",complete:"Enter"},c={...p,redo:a,undo:s,center:"Alt",constraint:"Shift",delete:["Backspace","Delete"],vertexAdd:"f",pan:" "},f={toggle:"Control"},d={enterInputMode:"Tab",commit:"Enter",discard:"Escape",next:"Tab"},h={moveUp:{key:"ArrowUp",modifier:"Shift",repeats:!0},moveDown:{key:"ArrowDown",modifier:"Shift",repeats:!0},moveLeft:{key:"ArrowLeft",modifier:"Shift",repeats:!0},moveRight:{key:"ArrowRight",modifier:"Shift",repeats:!0},scaleUp:{key:"+",modifier:"Shift"},scaleDown:{key:"-",modifier:"Shift"},factorModifier:{key:n,continuePropagation:!0},toggleOpacity:"t",preserveAspectRatio:{key:"Shift",continuePropagation:!0},rotateIncrements:{key:"Shift",continuePropagation:!0},editSourcePoints:{key:"Alt",continuePropagation:!0},undo:s,redo:a},g={toggleFollowManipulator:{key:"v",repeats:!1,continuePropagation:!0}},m={invertType:["Control","Meta"]};class y{constructor(){this._bindings=new Map}add(e,t){return this.addToggle(e,e=>{"key-down"===e.type&&t(e)})}addToggle(o,r){const n=l.fromDefinition(o,r),s=i(this._bindings,n.key,()=>[]);return s.push(n),t(()=>e(s,n))}register(e,t=r.WIDGET){return o([e.on("key-down",t=>this.dispatch(e.inputManager,t),t),e.on("key-up",t=>this.dispatch(e.inputManager,t),t)])}dispatch(e,t){const o=t.key,i=this._bindings.get(o);if(i)for(const r of i)r.process(e,t)}}class l{constructor(e,t,o,i,r){this.key=e,this.modifiers=t,this.repeats=o,this.continuePropagation=i,this.callback=r}process(e,t){if(!(t.key!==this.key||"repeat"in t&&t.repeat&&!this.repeats)){for(const t of this.modifiers)if(!e.isModifierKeyDown(t))return;this.continuePropagation||t.stopPropagation(),this.callback(t)}}static fromDefinition(e,t){if("string"==typeof e)return new l(e,[],!1,!1,t);const{key:o,modifier:i,repeats:r,continuePropagation:n}=e;return new l(o,i?Array.isArray(i)?i:[i]:[],!!r,!!n,t)}}export{y as KeyBindings,g as advancedSketchKeys,p as interactiveToolKeys,h as mediaKeys,m as selectionKeys,c as sketchKeys,f as snappingKeys,d as tooltipKeys};
