2 lines
3.7 KiB
JavaScript
2 lines
3.7 KiB
JavaScript
var d=Object.defineProperty;var u=(n,s,e)=>s in n?d(n,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[s]=e;var h=(n,s,e)=>u(n,typeof s!="symbol"?s+"":s,e);import{j as t,ak as p,bs as c}from"./mui-vendor-CkIVaoQP.js";import{r as x}from"./react-vendor-CmFgShSM.js";function o(n,s){return n=Math.ceil(n),s=Math.floor(s),Math.floor(Math.random()*(s-n))+n}class l extends x.Component{constructor(){super(...arguments);h(this,"state",{solution:o(111111,999999),input:""});h(this,"componentDidMount",()=>{this.drawCaptcha()});h(this,"drawCaptcha",()=>{const{solution:e}=this.state,{width:i,height:r}=this.canvas,a=this.canvas.getContext("2d");a.clearRect(0,0,i,r),a.font="40px serif",a.textAlign="center",a.textBaseline="middle",a.fillText(e,i/2,r/2+3),a.strokeStyle="#000000",a.beginPath(),a.moveTo(o(5,20),o(5,20)),a.lineTo(i-o(5,20),r-o(5,20)),a.stroke(),a.moveTo(o(5,20),r-o(5,20)),a.lineTo(i-o(5,20),o(5,20)),a.stroke(),a.closePath(),this.canvas.style.backgroundColor="transparent"});h(this,"refresh",()=>{this.setState({solution:o(111111,999999),input:""},this.drawCaptcha)});h(this,"playAudio",()=>{const{solution:e}=this.state;let i=new SpeechSynthesisUtterance(e.toString().split("").join(" "));i.rate=.25,window.speechSynthesis.speak(i)});h(this,"handleChange",e=>{const{onChange:i}=this.props,{solution:r}=this.state;this.setState({input:e.target.value}),i(e.target.value===r.toString())})}render(){const{input:e}=this.state;return t.jsxs("div",{className:"rnc",children:[t.jsxs("div",{className:"rnc-row",children:[t.jsx("canvas",{ref:i=>this.canvas=i,width:200,height:50,className:"rnc-canvas","data-testid":"captcha-canvas"}),t.jsxs("div",{className:"rnc-column",children:[t.jsx("button",{type:"button","aria-label":"get new captcha",onClick:this.refresh,className:"rnc-button","data-testid":"captcha-refresh",tabIndex:-1,children:t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:t.jsx("g",{"data-name":"Layer 2",children:t.jsxs("g",{"data-name":"refresh",children:[t.jsx("rect",{width:"24",height:"24",opacity:"0"}),t.jsx("path",{d:"M20.3 13.43a1 1 0 0 0-1.25.65A7.14 7.14 0 0 1 12.18 19 7.1 7.1 0 0 1 5 12a7.1 7.1 0 0 1 7.18-7 7.26 7.26 0 0 1 4.65 1.67l-2.17-.36a1 1 0 0 0-1.15.83 1 1 0 0 0 .83 1.15l4.24.7h.17a1 1 0 0 0 .34-.06.33.33 0 0 0 .1-.06.78.78 0 0 0 .2-.11l.09-.11c0-.05.09-.09.13-.15s0-.1.05-.14a1.34 1.34 0 0 0 .07-.18l.75-4a1 1 0 0 0-2-.38l-.27 1.45A9.21 9.21 0 0 0 12.18 3 9.1 9.1 0 0 0 3 12a9.1 9.1 0 0 0 9.18 9A9.12 9.12 0 0 0 21 14.68a1 1 0 0 0-.7-1.25z"})]})})})}),t.jsx("button",{type:"button","aria-label":"play audio",onClick:this.playAudio,className:"rnc-button","data-testid":"captcha-audio",tabIndex:-1,children:t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:t.jsx("g",{"data-name":"Layer 2",children:t.jsxs("g",{"data-name":"volume-up",children:[t.jsx("rect",{width:"24",height:"24",opacity:"0"}),t.jsx("path",{d:"M18.28 8.37a1 1 0 1 0-1.56 1.26 4 4 0 0 1 0 4.74A1 1 0 0 0 17.5 16a1 1 0 0 0 .78-.37 6 6 0 0 0 0-7.26z"}),t.jsx("path",{d:"M19.64 5.23a1 1 0 1 0-1.28 1.54A6.8 6.8 0 0 1 21 12a6.8 6.8 0 0 1-2.64 5.23 1 1 0 0 0-.13 1.41A1 1 0 0 0 19 19a1 1 0 0 0 .64-.23A8.75 8.75 0 0 0 23 12a8.75 8.75 0 0 0-3.36-6.77z"}),t.jsx("path",{d:"M15 3.12a1 1 0 0 0-1 0L7.52 7.57h-5a1 1 0 0 0-1 1v6.86a1 1 0 0 0 1 1h5l6.41 4.4a1.06 1.06 0 0 0 .57.17 1 1 0 0 0 1-1V4a1 1 0 0 0-.5-.88zm-1.47 15L8.4 14.6a1 1 0 0 0-.57-.17H3.5V9.57h4.33a1 1 0 0 0 .57-.17l5.1-3.5z"})]})})})})]})]}),t.jsx(p,{id:"captcha",label:"کد امنیتی",variant:"outlined",value:e,onChange:this.handleChange,sx:{width:"100%"}})]})}}l.defaultProps={placeholder:"کد امنیتی را وارد کنید..."};l.propTypes={onChange:c.func.isRequired,placeholder:c.string};export{l as C};
|