/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{remove as e}from"../../core/arrayUtils.js";import{makeHandle as t,handlesGroup as i}from"../../core/handleUtils.js";import{getOrCreateMapValue as o}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},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(i,r){const n=g.fromDefinition(i,r),s=o(this._bindings,n.key,()=>[]);return s.push(n),t(()=>e(s,n))}register(e,t=r.WIDGET){return i([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 i=t.key,o=this._bindings.get(i);if(o)for(const r of o)r.process(e,t)}}class g{constructor(e,t,i,o,r){this.key=e,this.modifiers=t,this.repeats=i,this.continuePropagation=o,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 g(e,[],!1,!1,t);const{key:i,modifier:o,repeats:r,continuePropagation:n}=e;return new g(i,o?Array.isArray(o)?o:[o]:[],!!r,!!n,t)}}export{y as KeyBindings,p as interactiveToolKeys,h as mediaKeys,m as selectionKeys,c as sketchKeys,f as snappingKeys,d as tooltipKeys};
