import{r as t,c as i,h as s,g as e}from"./p-78e3ebb9.js";const h="taro-input-core{display:block}input{display:block;overflow:hidden;height:1.4rem;text-overflow:clip;text-align:inherit;white-space:nowrap}";function o(t,i,s){if(i==="search")t="search";if(s)t="password";if(typeof t==="undefined"){return"text"}if(!t){throw new Error("unexpected type")}if(t==="digit")t="number";return t}function n(t){return t!==null&&t!==void 0?t:""}const u=class{constructor(s){t(this,s);this.onInput=i(this,"input",7);this.onPaste=i(this,"paste",7);this.onFocus=i(this,"focus",7);this.onBlur=i(this,"blur",7);this.onConfirm=i(this,"confirm",7);this.onChange=i(this,"change",7);this.onKeyDown=i(this,"keydown",7);this.isOnComposition=false;this.isOnPaste=false;this.onInputExcuted=false;this.handleInput=t=>{t.stopPropagation();const{type:i,maxlength:s,confirmType:e,password:h}=this;if(!this.isOnComposition&&!this.onInputExcuted){let n=t.target.value;const u=o(i,e,h);this.onInputExcuted=true;if(u==="number"&&n&&s>-1&&s<=n.length){n=n.substring(0,s);t.target.value=n}this.value=n;this.onInput.emit({value:n,cursor:n.length});this.onInputExcuted=false}};this.handlePaste=t=>{t.stopPropagation();this.isOnPaste=true;this.onPaste.emit({value:t.target.value})};this.handleFocus=t=>{t.stopPropagation();this.onInputExcuted=false;this.onFocus.emit({value:t.target.value})};this.handleBlur=t=>{t.stopPropagation();this.onBlur.emit({value:t.target.value})};this.handleChange=t=>{t.stopPropagation();this.onChange.emit({value:t.target.value});if(this.isOnPaste){this.isOnPaste=false;this.value=t.target.value;this.onInput.emit({value:t.target.value,cursor:t.target.value.length})}};this.handleKeyDown=t=>{t.stopPropagation();const{value:i}=t.target;const s=t.keyCode||t.code;this.onInputExcuted=false;this.onKeyDown.emit({value:i,cursor:i.length,keyCode:s});s===13&&this.onConfirm.emit({value:i})};this.handleComposition=t=>{t.stopPropagation();if(!(t.target instanceof HTMLInputElement))return;if(t.type==="compositionend"){this.isOnComposition=false;this.value=t.target.value;this.onInput.emit({value:t.target.value,cursor:t.target.value.length})}else{this.isOnComposition=true}};this.handleBeforeinput=t=>{if(!t.data)return;const i=t.data&&/[0-9]/.test(t.data);if(this.type==="number"&&!i){t.preventDefault()}if(this.type==="digit"&&!i){if(t.data!=="."||t.data==="."&&t.target.value.indexOf(".")>-1){t.preventDefault()}}};this.value=undefined;this.type=undefined;this.password=false;this.placeholder=undefined;this.disabled=false;this.maxlength=140;this.autoFocus=false;this.confirmType="done";this.name=undefined;this.nativeProps={}}async focus(){this.inputRef.focus()}watchAutoFocus(t,i){var s;if(!i&&t){(s=this.inputRef)===null||s===void 0?void 0:s.focus()}}watchValue(t){const i=n(t);if(this.inputRef.value!==i){this.inputRef.value=i}}componentDidLoad(){var t,i,s,e,h;if(this.type==="file"){this.fileListener=()=>{this.onInput.emit()};(t=this.inputRef)===null||t===void 0?void 0:t.addEventListener("change",this.fileListener)}else{(i=this.inputRef)===null||i===void 0?void 0:i.addEventListener("compositionstart",this.handleComposition);(s=this.inputRef)===null||s===void 0?void 0:s.addEventListener("compositionend",this.handleComposition);(e=this.inputRef)===null||e===void 0?void 0:e.addEventListener("beforeinput",this.handleBeforeinput);(h=this.inputRef)===null||h===void 0?void 0:h.addEventListener("textInput",this.handleBeforeinput)}Object.defineProperty(this.el,"value",{get:()=>this.inputRef.value,set:t=>this.value=t,configurable:true})}disconnectedCallback(){var t,i,s,e,h;if(this.type==="file"){(t=this.inputRef)===null||t===void 0?void 0:t.removeEventListener("change",this.fileListener)}else{(i=this.inputRef)===null||i===void 0?void 0:i.removeEventListener("compositionstart",this.handleComposition);(s=this.inputRef)===null||s===void 0?void 0:s.removeEventListener("compositionend",this.handleComposition);(e=this.inputRef)===null||e===void 0?void 0:e.removeEventListener("beforeinput",this.handleBeforeinput);(h=this.inputRef)===null||h===void 0?void 0:h.removeEventListener("textInput",this.handleBeforeinput)}}render(){const{value:t,type:i,password:e,placeholder:h,autoFocus:u,disabled:l,maxlength:a,confirmType:r,name:c,nativeProps:d}=this;return s("input",Object.assign({ref:t=>{this.inputRef=t;if(u&&t)t.focus()},class:"weui-input",type:o(i,r,e),placeholder:h,autoFocus:u,disabled:l,maxlength:a,name:c,onInput:this.handleInput,onFocus:this.handleFocus,onBlur:this.handleBlur,onChange:this.handleChange,onKeyDown:this.handleKeyDown,onPaste:this.handlePaste,onCompositionStart:this.handleComposition,onCompositionEnd:this.handleComposition},d,{value:n(t)}))}get el(){return e(this)}static get watchers(){return{autoFocus:["watchAutoFocus"],value:["watchValue"]}}};u.style=h;export{u as taro_input_core};
//# sourceMappingURL=p-fe58b450.entry.js.map