secure-react-captcha
Version:
React Secure Captcha is a powerful and customizable npm package designed to seamlessly integrate secure and user-friendly CAPTCHA functionality into your React application.
1 lines • 5.76 kB
JavaScript
(()=>{"use strict";var t={n:e=>{var r=e&&e.__esModule?()=>e.default:()=>e;return t.d(r,{a:r}),r},d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{default:()=>h});const r=require("react");var n=t.n(r);function a(){for(var t="#",e=0;e<6;e++)t+="0123456789ABCDEF"[Math.floor(16*Math.random())];return t}function o(t,e){return Math.random()*(e-t)+t}function i(t){return function(t){if(Array.isArray(t))return c(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||u(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function l(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,a,o,i,l=[],u=!0,c=!1;try{if(o=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=o.call(r)).done)&&(l.push(n.value),l.length!==e);u=!0);}catch(t){c=!0,a=t}finally{try{if(!u&&null!=r.return&&(i=r.return(),Object(i)!==i))return}finally{if(c)throw a}}return l}}(t,e)||u(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(t,e){if(t){if("string"==typeof t)return c(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?c(t,e):void 0}}function c(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}const h=function(t){var e=t.setValidated,u=t.needDots,c=void 0===u||u,h=t.needLines,f=void 0===h||h,d=t.minDots,s=void 0===d?400:d,m=t.maxDots,v=void 0===m?500:m,y=t.minLines,g=void 0===y?10:y,b=t.maxLines,M=void 0===b?100:b,p=t.characters,w=void 0===p?"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz":p,S=l((0,r.useState)("a"),2),E=S[0],x=S[1],A=l((0,r.useState)("a"),2),j=A[0],k=A[1],O=l((0,r.useState)(""),2),_=O[0],T=O[1],C=l((0,r.useState)(Array(5).fill("")),2),I=C[0],N=C[1],P=function(){k(function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:64,e="",r=0;r<t;r++)e+="qwertyuiopasdfghjklzxcvbn0987654321mQWERTYUIOSDFGHJKLZXCVBNM"[Math.floor(60*Math.random())];return e}());var t=function(t,e,r,n,i,l,u,c){var h=t.getContext("2d");if(t.width=250,t.height=50,h.fillStyle="#FFF",h.fillRect(0,0,t.width,t.height),e)for(var f=0;f<o(Math.min(l,u),Math.max(l,u));f++)h.fillStyle=a(),h.beginPath(),h.arc(Math.random()*t.width,Math.random()*t.height,2*Math.random(),0,2*Math.PI),h.fill();if(r)for(var d=0;d<o(Math.min(n,i),Math.max(n,i));d++){h.strokeStyle=a(),h.lineWidth=o(1,2),h.beginPath();var s=Math.random()*o(t.width,t.width+o(10,50)),m=Math.random()*o(t.height,t.height+o(10,50)),v=Math.random()*o(t.width,t.width+o(10,50)),y=Math.random()*o(t.height,t.height+o(10,50)),g=Math.random()*o(t.width,t.width+o(10,50)),b=Math.random()*o(t.height,t.height+o(10,50)),M=Math.random()*o(t.width,t.width+o(10,50)),p=Math.random()*o(t.height,t.height+o(10,50));h.moveTo(s,m),h.bezierCurveTo(v,y,g,b,M,p),h.stroke()}for(var w="",S=0;S<5;S++){h.fillStyle=function(t,e,r){var n,a,o,i,l,u,c,h;switch(u=r*(1-e),c=r*(1-(l=6*t-(i=Math.floor(6*t)))*e),h=r*(1-(1-l)*e),i%6){case 0:n=r,a=h,o=u;break;case 1:n=c,a=r,o=u;break;case 2:n=u,a=r,o=h;break;case 3:n=u,a=c,o=r;break;case 4:n=h,a=u,o=r;break;case 5:n=r,a=u,o=c}return"#"+((1<<24)+(Math.round(255*n)<<16)+(Math.round(255*a)<<8)+Math.round(255*o)).toString(16).slice(1)}(Math.random(),.8+.2*Math.random(),.1+.3*Math.random()),h.strokeStyle="#000",h.lineWidth=1,h.save();var E=15*Math.random()+20;h.font="".concat(E,"px Arial"),h.translate(25+45*S,35),h.transform(1,.75*Math.random()-.25,.75*Math.random()-.25,1,0,0);var x=c.charAt(Math.floor(Math.random()*c.length));w+=x,h.fillText(x,0,0),h.strokeText(x,0,0),h.restore()}return w}(document.getElementById(j),c,f,g,M,s,v,w);x(t),T(""),N(Array(5).fill("")),e(!1)},D=function(t){return function(e){var r=e.target.value;""===r?N((function(r){var n=i(r);if(n[t]="",t>0){var a=e.target.previousElementSibling;a&&a.focus()}return n})):w.includes(r)&&N((function(n){var a=i(n);if(a[t]=r,t<4){var o=e.target.nextElementSibling;o&&o.focus()}return a}))}},F=function(t){return function(e){if(8===e.keyCode&&""===I[t]){var r=e.target.previousElementSibling;r&&r.focus()}}};return(0,r.useEffect)((function(){P()}),[]),(0,r.useEffect)((function(){T(I.join(""))}),[I]),(0,r.useEffect)((function(){console.log(_),5===_.length?e(_===E):e(!1)}),[_]),n().createElement("div",{className:"src_container"},n().createElement("div",{className:"src_canvas_container"},n().createElement("canvas",{id:j,className:"src_canvas"}),n().createElement("button",{className:"src_reset_button",type:"button",onClick:function(){return P()}},n().createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24"},n().createElement("path",{d:"M12 3a8.959 8.959 0 0 0-7 3.339V4H3v6h6V8H6.274a6.982 6.982 0 1 1-1.054 5.751l-1.936.5A9 9 0 1 0 12 3z",fill:"white"})))),n().createElement("div",{className:"d-flex justify-content-between"},I.map((function(t,e){return n().createElement("input",{type:"text",className:"src_input",key:e,placeholder:"X",maxLength:"1",value:t,onChange:D(e),onKeyUp:F(e)})}))))};module.exports=e})();