import*as SDK from"../sdk/sdk.js";export class InputModel extends SDK.SDKModel.SDKModel{constructor(e){super(e),this._inputAgent=e.inputAgent(),this._activeTouchOffsetTop=null,this._activeTouchParams=null}emitKeyEvent(e){let t;switch(e.type){case"keydown":t=Protocol.Input.DispatchKeyEventRequestType.KeyDown;break;case"keyup":t=Protocol.Input.DispatchKeyEventRequestType.KeyUp;break;case"keypress":t=Protocol.Input.DispatchKeyEventRequestType.Char;break;default:return}const o=e,s="keypress"===e.type?String.fromCharCode(o.charCode):void 0;this._inputAgent.invoke_dispatchKeyEvent({type:t,modifiers:this._modifiersForEvent(o),text:s,unmodifiedText:s?s.toLowerCase():void 0,keyIdentifier:o.keyIdentifier,code:o.code,key:o.key,windowsVirtualKeyCode:o.keyCode,nativeVirtualKeyCode:o.keyCode,autoRepeat:!1,isKeypad:!1,isSystemKey:!1})}emitTouchFromMouseEvent(e,t,o){const s=["none","left","middle","right"],u={mousedown:Protocol.Input.EmulateTouchFromMouseEventRequestType.MousePressed,mouseup:Protocol.Input.EmulateTouchFromMouseEventRequestType.MouseReleased,mousemove:Protocol.Input.EmulateTouchFromMouseEventRequestType.MouseMoved,mousewheel:Protocol.Input.EmulateTouchFromMouseEventRequestType.MouseWheel},i=e.type;if(!(i in u))return;const n=e;if(!(n.which in s))return;if("mousewheel"!==i&&"none"===s[n.which])return;"mousedown"!==i&&null!==this._activeTouchOffsetTop||(this._activeTouchOffsetTop=t);const c=Math.round(n.offsetX/o);let r=Math.round(n.offsetY/o);r=Math.round(r-this._activeTouchOffsetTop);const a={type:u[i],x:c,y:r,modifiers:0,button:s[n.which],clickCount:0};if("mousewheel"===e.type){const e=n;a.deltaX=e.deltaX/o,a.deltaY=-e.deltaY/o}else this._activeTouchParams=a;"mouseup"===e.type&&(this._activeTouchOffsetTop=null),this._inputAgent.invoke_emulateTouchFromMouseEvent(a)}cancelTouch(){if(null!==this._activeTouchParams){const e=this._activeTouchParams;this._activeTouchParams=null,e.type="mouseReleased",this._inputAgent.invoke_emulateTouchFromMouseEvent(e)}}_modifiersForEvent(e){return(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0)}}SDK.SDKModel.SDKModel.register(InputModel,SDK.SDKModel.Capability.Input,!1);