var gdjs;(function(a){const m={text:"text",email:"email",password:"password",number:"number","telephone number":"tel",url:"url",search:"search"},n=(o,e)=>"rgba("+o[0]+","+o[1]+","+o[2]+","+e/255+")";class s{constructor(e,t){this._input=null;this._object=e,this._instanceContainer=t,this._runtimeGame=this._instanceContainer.getGame(),this._createElement()}_createElement(){if(this._input)throw new Error("Tried to recreate an input while it already exists.");const e=this._object.getInputType()==="text area";this._input=document.createElement(e?"textarea":"input"),this._input.style.border="1px solid black",this._input.autocomplete="off",this._input.style.borderRadius="0px",this._input.style.backgroundColor="white",this._input.style.position="absolute",this._input.style.resize="none",this._input.style.outline="none",this._input.style.pointerEvents="auto",this._input.style.display="none",this._input.addEventListener("input",()=>{!this._input||this._object.onRendererInputValueChanged(this._input.value)}),this._input.addEventListener("touchstart",()=>{!this._input||document.activeElement!==this._input&&this._input.focus()}),this.updateString(),this.updateFont(),this.updatePlaceholder(),this.updateOpacity(),this.updateInputType(),this.updateTextColor(),this.updateFillColorAndOpacity(),this.updateBorderColorAndOpacity(),this.updateBorderWidth(),this.updateDisabled(),this.updateReadOnly(),this._runtimeGame.getRenderer().getDomElementContainer().appendChild(this._input)}_destroyElement(){!this._input||(this._input.remove(),this._input=null)}onScenePaused(){this._destroyElement()}onSceneResumed(){this._createElement()}onDestroy(){this._destroyElement()}updatePreRender(){if(!this._input)return;if(this._object.isHidden()){this._input.style.display="none";return}const e=this._instanceContainer.getLayer(this._object.getLayer());if(!e.isVisible()){this._input.style.display="none";return}const t=a.staticArray(s.prototype.updatePreRender),i=this._instanceContainer.getGame(),r=i.getRenderer(),u=e.convertInverseCoords(this._object.x,this._object.y,0,t),p=u[0],h=u[1],l=e.convertInverseCoords(this._object.x+this._object.getWidth(),this._object.y+this._object.getHeight(),0,t),c=l[0],d=l[1];if(c<0||d<0||p>i.getGameResolutionWidth()||h>i.getGameResolutionHeight()){this._input.style.display="none";return}t[0]=p,t[1]=h,r.convertCanvasToDomElementContainerCoords(t,t);const _=t[0],y=t[1];t[0]=c,t[1]=d,r.convertCanvasToDomElementContainerCoords(t,t);const g=t[0],b=t[1],C=g-_,f=b-y;this._input.style.left=_+"px",this._input.style.top=y+"px",this._input.style.width=C+"px",this._input.style.height=f+"px",this._input.style.transform="rotate3d(0,0,1,"+this._object.getAngle()%360+"deg)",this._input.style.fontSize=this._object.getFontSize()*r.getCanvasToDomElementContainerHeightScale()+"px",this._input.style.display="initial"}updateString(){!this._input||(this._input.value=this._object.getString())}updatePlaceholder(){!this._input||(this._input.placeholder=this._object.getPlaceholder())}updateFont(){!this._input||(this._input.style.fontFamily=this._instanceContainer.getGame().getFontManager().getFontFamily(this._object.getFontResourceName()))}updateOpacity(){!this._input||(this._input.style.opacity=""+this._object.getOpacity()/255)}updateInputType(){if(!this._input)return;const e=this._input instanceof HTMLTextAreaElement,t=this._object.getInputType()==="text area";e!==t&&(this._destroyElement(),this._createElement());const i=m[this._object.getInputType()]||"text";this._input.setAttribute("type",i)}updateTextColor(){!this._input||(this._input.style.color=n(this._object._getRawTextColor(),255))}updateFillColorAndOpacity(){!this._input||(this._input.style.backgroundColor=n(this._object._getRawFillColor(),this._object.getFillOpacity()))}updateBorderColorAndOpacity(){!this._input||(this._input.style.borderColor=n(this._object._getRawBorderColor(),this._object.getBorderOpacity()))}updateBorderWidth(){!this._input||(this._input.style.borderWidth=this._object.getBorderWidth()+"px")}updateDisabled(){!this._input||(this._input.disabled=this._object.isDisabled())}updateReadOnly(){!this._input||(this._input.readOnly=this._object.isReadOnly())}isFocused(){return this._input===document.activeElement}}a.TextInputRuntimeObjectRenderer=s})(gdjs||(gdjs={}));
//# sourceMappingURL=textinputruntimeobject-pixi-renderer.js.map
