react-captcha-lite
Version:
CAPTCHA for REACT web apps
2 lines • 5.24 kB
JavaScript
/*! For license information please see index.js.LICENSE.txt */
(()=>{var e={694:(e,r,t)=>{"use strict";var o=t(925);function n(){}function a(){}a.resetWarningCache=n,e.exports=function(){function e(e,r,t,n,a,i){if(i!==o){var l=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw l.name="Invariant Violation",l}}function r(){return e}e.isRequired=e;var t={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:r,element:e,elementType:e,instanceOf:r,node:e,objectOf:r,oneOf:r,oneOfType:r,shape:r,exact:r,checkPropTypes:a,resetWarningCache:n};return t.PropTypes=t,t}},556:(e,r,t)=>{e.exports=t(694)()},925:e=>{"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},35:(e,r,t)=>{"use strict";var o=t(953),n=Symbol.for("react.element"),a=(Symbol.for("react.fragment"),Object.prototype.hasOwnProperty),i=o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};function c(e,r,t){var o,c={},u=null,s=null;for(o in void 0!==t&&(u=""+t),void 0!==r.key&&(u=""+r.key),void 0!==r.ref&&(s=r.ref),r)a.call(r,o)&&!l.hasOwnProperty(o)&&(c[o]=r[o]);if(e&&e.defaultProps)for(o in r=e.defaultProps)void 0===c[o]&&(c[o]=r[o]);return{$$typeof:n,type:e,key:u,ref:s,props:c,_owner:i.current}}r.jsx=c,r.jsxs=c},553:(e,r,t)=>{"use strict";e.exports=t(35)},953:e=>{"use strict";e.exports=require("react")}},r={};function t(o){var n=r[o];if(void 0!==n)return n.exports;var a=r[o]={exports:{}};return e[o](a,a.exports,t),a.exports}t.n=e=>{var r=e&&e.__esModule?()=>e.default:()=>e;return t.d(r,{a:r}),r},t.d=(e,r)=>{for(var o in r)t.o(r,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:r[o]})},t.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};(()=>{"use strict";t.r(o),t.d(o,{CaptchaBox:()=>c,reloadCaptcha:()=>s,validateCaptcha:()=>u});var e=t(953),r=t(556),n=t.n(r),a=t(553);function i(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,o=Array(r);t<r;t++)o[t]=e[t];return o}var l="";function c(r){var t,o,n=r.width,c=void 0===n?200:n,u=r.height,s=void 0===u?60:u,d=r.fontColor,f=void 0===d?"#000":d,p=r.font,y=void 0===p?"bold 20px Arial":p,h=r.boxBorder,v=void 0===h?"2px solid grey":h,_=r.boxBackground,b=void 0===_?"#fff":_,g=r.textType,T=void 0===g?"MIXED":g,m=r.charLength,E=void 0===m?6:m,x=r.reloadStyle,O=void 0===x?{padding:5,cursor:"pointer",border:"1px black solid",userSelect:"none"}:x,S=r.containerStyle,P=void 0===S?{padding:2,display:"flex",gap:5,justifyContent:"center",alignItems:"center"}:S,j=(t=(0,e.useState)(!1),o=2,function(e){if(Array.isArray(e))return e}(t)||function(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var o,n,a,i,l=[],c=!0,u=!1;try{if(a=(t=t.call(e)).next,0===r){if(Object(t)!==t)return;c=!1}else for(;!(c=(o=a.call(t)).done)&&(l.push(o.value),l.length!==r);c=!0);}catch(e){u=!0,n=e}finally{try{if(!c&&null!=t.return&&(i=t.return(),Object(i)!==i))return}finally{if(u)throw n}}return l}}(t,o)||function(e,r){if(e){if("string"==typeof e)return i(e,r);var t={}.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?i(e,r):void 0}}(t,o)||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.")}()),R=j[0],C=j[1],k=(0,e.useRef)(null),w=(0,e.useCallback)((function(e,r){for(var t="",o={UPPER_TEXT:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",LOWER_TEXT:"abcdefghijklmnopqrstuvwxyz",UPPER_TEXT_NUM:"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",LOWER_TEXT_NUM:"abcdefghijklmnopqrstuvwxyz0123456789",NUM_ONLY:"0123456789",MIXED:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"},n=o[e]||o.MIXED,a=0;a<r;a++)t+=n.charAt(Math.floor(Math.random()*n.length));return t}),[]);(0,e.useEffect)((function(){var e=k.current,r=e.getContext("2d");e.width=c,e.height=s,r.fillStyle=f,r.font=y,r.letterSpacing="3px";var t=w(T,E),o=r.measureText(t).width;r.fillText(t,(e.width-o)/2,e.height/2),l=t}),[c,s,f,y,T,E,R,w]);var I=(0,e.useCallback)((function(){C((function(e){return!e}))}),[]);return(0,a.jsxs)("div",{id:"captcha_lite_container",style:P,children:[(0,a.jsx)("canvas",{id:"captcha_lite_canvas",ref:k,style:{border:v,backgroundColor:b},children:"Sorry, your browser does not support canvas."}),(0,a.jsx)("a",{id:"captcha_lite_reload_btn",onClick:I,style:O,children:"↻"})]})}function u(e){var r=e.toString()===l;return s(),r}function s(){document.getElementById("captcha_lite_reload_btn").click()}c.propTypes={width:n().number,height:n().number,fontColor:n().string,boxBorder:n().string,boxBackground:n().string,textType:n().oneOf(["UPPER_TEXT","LOWER_TEXT","UPPER_TEXT_NUM","LOWER_TEXT_NUM","NUM_ONLY","MIXED"]),charLength:n().number,reloadStyle:n().object,containerStyle:n().object}})(),module.exports=o})();