fullstack.web/swa/cross-nav/PIXI.TextInput.min.js

1 line
11 KiB
JavaScript
Raw Permalink Normal View History

2023-08-09 05:57:49 +00:00
!function(t){const e=t.PIXI;t.exportTo[0][t.exportTo[1]]=class extends e.Container{constructor(t){super(),this._input_style=Object.assign({position:"absolute",background:"none",border:"none",outline:"none",transformOrigin:"0 0",lineHeight:"1"},t.input),t.box?this._box_generator="function"==typeof t.box?t.box:new function(t){if((t=t||{fill:13421772}).default)t.focused=t.focused||t.default,t.disabled=t.disabled||t.default;else{let e=t;(t={}).default=t.focused=t.disabled=e}return function(i,s,r){let o=t[r.toLowerCase()],h=new e.Graphics;return o.fill&&h.beginFill(o.fill),o.stroke&&h.lineStyle(o.stroke.width||1,o.stroke.color||0,o.stroke.alpha||1),o.rounded?h.drawRoundedRect(0,0,i,s,o.rounded):h.drawRect(0,0,i,s),h.endFill(),h.closePath(),h}}(t.box):this._box_generator=null,this._input_style.hasOwnProperty("multiline")?(this._multiline=!!this._input_style.multiline,delete this._input_style.multiline):this._multiline=!1,this._box_cache={},this._previous={},this._dom_added=!1,this._dom_visible=!0,this._placeholder="",this._placeholderColor=11119017,this._selection=[0,0],this._restrict_value="",this._createDOMInput(),this.substituteText=!0,this._setState("DEFAULT"),this._addListeners()}get substituteText(){return this._substituted}set substituteText(t){this._substituted!=t&&(this._substituted=t,t?(this._createSurrogate(),this._dom_visible=!1):(this._destroySurrogate(),this._dom_visible=!0),this.placeholder=this._placeholder,this._update())}get placeholder(){return this._placeholder}set placeholder(t){this._placeholder=t,this._substituted?(this._updateSurrogate(),this._dom_input.placeholder=""):this._dom_input.placeholder=t}get disabled(){return this._disabled}set disabled(t){this._disabled=t,this._dom_input.disabled=t,this._setState(t?"DISABLED":"DEFAULT")}get maxLength(){return this._max_length}set maxLength(t){this._max_length=t,this._dom_input.setAttribute("maxlength",t)}get restrict(){return this._restrict_regex}set restrict(t){t instanceof RegExp?("^"!==(t=t.toString().slice(1,-1)).charAt(0)&&(t="^"+t),"$"!==t.charAt(t.length-1)&&(t+="$"),t=new RegExp(t)):t=new RegExp("^["+t+"]*$"),this._restrict_regex=t}get text(){return this._dom_input.value}set text(t){this._dom_input.value=t,this._substituted&&this._updateSurrogate()}get htmlInput(){return this._dom_input}focus(){this._substituted&&!this.dom_visible&&this._setDOMInputVisible(!0),this._dom_input.focus()}blur(){this._dom_input.blur()}select(){this.focus(),this._dom_input.select()}setInputStyle(t,e){this._input_style[t]=e,this._dom_input.style[t]=e,!this._substituted||"fontFamily"!==t&&"fontSize"!==t||this._updateFontMetrics(),this._last_renderer&&this._update()}destroy(t){this._destroyBoxCache(),super.destroy(t)}_createDOMInput(){this._multiline?(this._dom_input=document.createElement("textarea"),this._dom_input.style.resize="none"):(this._dom_input=document.createElement("input"),this._dom_input.type="text");for(let t in this._input_style)this._dom_input.style[t]=this._input_style[t]}_addListeners(){this.on("added",this._onAdded.bind(this)),this.on("removed",this._onRemoved.bind(this)),this._dom_input.addEventListener("keydown",this._onInputKeyDown.bind(this)),this._dom_input.addEventListener("input",this._onInputInput.bind(this)),this._dom_input.addEventListener("keyup",this._onInputKeyUp.bind(this)),this._dom_input.addEventListener("focus",this._onFocused.bind(this)),this._dom_input.addEventListener("blur",this._onBlurred.bind(this))}_onInputKeyDown(t){this._selection=[this._dom_input.selectionStart,this._dom_input.selectionEnd],this.emit("keydown",t.keyCode)}_onInputInput(t){this._restrict_regex&&this._applyRestriction(),this._substituted&&this._updateSubstitution(),this.emit("input",this.text)}_onInputKeyUp(t){this.emit("keyup",t.keyCode)}_onFocused(){this._setState("FOCUSED"),this.emit("focus")}_onBlurred(){this._setState("DEFAULT"),this.emit("blur")}_onAdded(){document.body.appendChild(this._dom_input),this._dom_input.style.display="none",this._dom_added=!0}_onRemoved(){document.body.removeChild(this._dom_input),this._dom_added=!1}_setState(t){this.state=t,this._