UNPKG

captcha-text-generator

Version:

Captcha Text Generator === This is a reactjs component for generating captcha text. - automatically generate random text - easy to validate - easy to customize the style

39 lines (30 loc) 15 kB
(function(j,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],y):(j=typeof globalThis<"u"?globalThis:j||self,y(j["captcha-text-generator"]={},j.require$$0))})(this,function(j,y){"use strict";var J={exports:{}},$={};/** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var ne;function je(){if(ne)return $;ne=1;var c=y,E=Symbol.for("react.element"),R=Symbol.for("react.fragment"),b=Object.prototype.hasOwnProperty,_=c.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,C={key:!0,ref:!0,__self:!0,__source:!0};function O(T,l,P){var d,h={},x=null,F=null;P!==void 0&&(x=""+P),l.key!==void 0&&(x=""+l.key),l.ref!==void 0&&(F=l.ref);for(d in l)b.call(l,d)&&!C.hasOwnProperty(d)&&(h[d]=l[d]);if(T&&T.defaultProps)for(d in l=T.defaultProps,l)h[d]===void 0&&(h[d]=l[d]);return{$$typeof:E,type:T,key:x,ref:F,props:h,_owner:_.current}}return $.Fragment=R,$.jsx=O,$.jsxs=O,$}var W={};/** * @license React * react-jsx-runtime.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var ae;function ke(){return ae||(ae=1,process.env.NODE_ENV!=="production"&&function(){var c=y,E=Symbol.for("react.element"),R=Symbol.for("react.portal"),b=Symbol.for("react.fragment"),_=Symbol.for("react.strict_mode"),C=Symbol.for("react.profiler"),O=Symbol.for("react.provider"),T=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),P=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),h=Symbol.for("react.memo"),x=Symbol.for("react.lazy"),F=Symbol.for("react.offscreen"),N=Symbol.iterator,D="@@iterator";function Y(e){if(e===null||typeof e!="object")return null;var r=N&&e[N]||e[D];return typeof r=="function"?r:null}var g=c.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function v(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];De("error",e,t)}}function De(e,r,t){{var n=g.ReactDebugCurrentFrame,i=n.getStackAddendum();i!==""&&(r+="%s",t=t.concat([i]));var u=t.map(function(o){return String(o)});u.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,u)}}var Ae=!1,Ie=!1,$e=!1,We=!1,Ye=!1,ie;ie=Symbol.for("react.module.reference");function Le(e){return!!(typeof e=="string"||typeof e=="function"||e===b||e===C||Ye||e===_||e===P||e===d||We||e===F||Ae||Ie||$e||typeof e=="object"&&e!==null&&(e.$$typeof===x||e.$$typeof===h||e.$$typeof===O||e.$$typeof===T||e.$$typeof===l||e.$$typeof===ie||e.getModuleId!==void 0))}function Me(e,r,t){var n=e.displayName;if(n)return n;var i=r.displayName||r.name||"";return i!==""?t+"("+i+")":t}function ue(e){return e.displayName||"Context"}function S(e){if(e==null)return null;if(typeof e.tag=="number"&&v("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case b:return"Fragment";case R:return"Portal";case C:return"Profiler";case _:return"StrictMode";case P:return"Suspense";case d:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case T:var r=e;return ue(r)+".Consumer";case O:var t=e;return ue(t._context)+".Provider";case l:return Me(e,e.render,"ForwardRef");case h:var n=e.displayName||null;return n!==null?n:S(e.type)||"Memo";case x:{var i=e,u=i._payload,o=i._init;try{return S(o(u))}catch{return null}}}return null}var k=Object.assign,L=0,se,fe,le,ce,de,ve,pe;function ge(){}ge.__reactDisabledLog=!0;function Ne(){{if(L===0){se=console.log,fe=console.info,le=console.warn,ce=console.error,de=console.group,ve=console.groupCollapsed,pe=console.groupEnd;var e={configurable:!0,enumerable:!0,value:ge,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}L++}}function Ve(){{if(L--,L===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:k({},e,{value:se}),info:k({},e,{value:fe}),warn:k({},e,{value:le}),error:k({},e,{value:ce}),group:k({},e,{value:de}),groupCollapsed:k({},e,{value:ve}),groupEnd:k({},e,{value:pe})})}L<0&&v("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var K=g.ReactCurrentDispatcher,H;function V(e,r,t){{if(H===void 0)try{throw Error()}catch(i){var n=i.stack.trim().match(/\n( *(at )?)/);H=n&&n[1]||""}return` `+H+e}}var X=!1,U;{var Ue=typeof WeakMap=="function"?WeakMap:Map;U=new Ue}function he(e,r){if(!e||X)return"";{var t=U.get(e);if(t!==void 0)return t}var n;X=!0;var i=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var u;u=K.current,K.current=null,Ne();try{if(r){var o=function(){throw Error()};if(Object.defineProperty(o.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(o,[])}catch(w){n=w}Reflect.construct(e,[],o)}else{try{o.call()}catch(w){n=w}e.call(o.prototype)}}else{try{throw Error()}catch(w){n=w}e()}}catch(w){if(w&&n&&typeof w.stack=="string"){for(var a=w.stack.split(` `),p=n.stack.split(` `),s=a.length-1,f=p.length-1;s>=1&&f>=0&&a[s]!==p[f];)f--;for(;s>=1&&f>=0;s--,f--)if(a[s]!==p[f]){if(s!==1||f!==1)do if(s--,f--,f<0||a[s]!==p[f]){var m=` `+a[s].replace(" at new "," at ");return e.displayName&&m.includes("<anonymous>")&&(m=m.replace("<anonymous>",e.displayName)),typeof e=="function"&&U.set(e,m),m}while(s>=1&&f>=0);break}}}finally{X=!1,K.current=u,Ve(),Error.prepareStackTrace=i}var I=e?e.displayName||e.name:"",Pe=I?V(I):"";return typeof e=="function"&&U.set(e,Pe),Pe}function Ge(e,r,t){return he(e,!1)}function ze(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function G(e,r,t){if(e==null)return"";if(typeof e=="function")return he(e,ze(e));if(typeof e=="string")return V(e);switch(e){case P:return V("Suspense");case d:return V("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case l:return Ge(e.render);case h:return G(e.type,r,t);case x:{var n=e,i=n._payload,u=n._init;try{return G(u(i),r,t)}catch{}}}return""}var z=Object.prototype.hasOwnProperty,me={},be=g.ReactDebugCurrentFrame;function B(e){if(e){var r=e._owner,t=G(e.type,e._source,r?r.type:null);be.setExtraStackFrame(t)}else be.setExtraStackFrame(null)}function Be(e,r,t,n,i){{var u=Function.call.bind(z);for(var o in e)if(u(e,o)){var a=void 0;try{if(typeof e[o]!="function"){var p=Error((n||"React class")+": "+t+" type `"+o+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[o]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw p.name="Invariant Violation",p}a=e[o](r,o,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(s){a=s}a&&!(a instanceof Error)&&(B(i),v("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,o,typeof a),B(null)),a instanceof Error&&!(a.message in me)&&(me[a.message]=!0,B(i),v("Failed %s type: %s",t,a.message),B(null))}}}var Je=Array.isArray;function Z(e){return Je(e)}function qe(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function Ke(e){try{return ye(e),!1}catch{return!0}}function ye(e){return""+e}function Ee(e){if(Ke(e))return v("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",qe(e)),ye(e)}var M=g.ReactCurrentOwner,He={key:!0,ref:!0,__self:!0,__source:!0},Re,_e,Q;Q={};function Xe(e){if(z.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function Ze(e){if(z.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function Qe(e,r){if(typeof e.ref=="string"&&M.current&&r&&M.current.stateNode!==r){var t=S(M.current.type);Q[t]||(v('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',S(M.current.type),e.ref),Q[t]=!0)}}function er(e,r){{var t=function(){Re||(Re=!0,v("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}}function rr(e,r){{var t=function(){_e||(_e=!0,v("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}}var tr=function(e,r,t,n,i,u,o){var a={$$typeof:E,type:e,key:r,ref:t,props:o,_owner:u};return a._store={},Object.defineProperty(a._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(a,"_self",{configurable:!1,enumerable:!1,writable:!1,value:n}),Object.defineProperty(a,"_source",{configurable:!1,enumerable:!1,writable:!1,value:i}),Object.freeze&&(Object.freeze(a.props),Object.freeze(a)),a};function nr(e,r,t,n,i){{var u,o={},a=null,p=null;t!==void 0&&(Ee(t),a=""+t),Ze(r)&&(Ee(r.key),a=""+r.key),Xe(r)&&(p=r.ref,Qe(r,i));for(u in r)z.call(r,u)&&!He.hasOwnProperty(u)&&(o[u]=r[u]);if(e&&e.defaultProps){var s=e.defaultProps;for(u in s)o[u]===void 0&&(o[u]=s[u])}if(a||p){var f=typeof e=="function"?e.displayName||e.name||"Unknown":e;a&&er(o,f),p&&rr(o,f)}return tr(e,a,p,i,n,M.current,o)}}var ee=g.ReactCurrentOwner,Te=g.ReactDebugCurrentFrame;function A(e){if(e){var r=e._owner,t=G(e.type,e._source,r?r.type:null);Te.setExtraStackFrame(t)}else Te.setExtraStackFrame(null)}var re;re=!1;function te(e){return typeof e=="object"&&e!==null&&e.$$typeof===E}function xe(){{if(ee.current){var e=S(ee.current.type);if(e)return` Check the render method of \``+e+"`."}return""}}function ar(e){{if(e!==void 0){var r=e.fileName.replace(/^.*[\\\/]/,""),t=e.lineNumber;return` Check your code at `+r+":"+t+"."}return""}}var Se={};function or(e){{var r=xe();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=` Check the top-level render call using <`+t+">.")}return r}}function we(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=or(r);if(Se[t])return;Se[t]=!0;var n="";e&&e._owner&&e._owner!==ee.current&&(n=" It was passed a child from "+S(e._owner.type)+"."),A(e),v('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),A(null)}}function Ce(e,r){{if(typeof e!="object")return;if(Z(e))for(var t=0;t<e.length;t++){var n=e[t];te(n)&&we(n,r)}else if(te(e))e._store&&(e._store.validated=!0);else if(e){var i=Y(e);if(typeof i=="function"&&i!==e.entries)for(var u=i.call(e),o;!(o=u.next()).done;)te(o.value)&&we(o.value,r)}}}function ir(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===l||r.$$typeof===h))t=r.propTypes;else return;if(t){var n=S(r);Be(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!re){re=!0;var i=S(r);v("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",i||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&v("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function ur(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){A(e),v("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),A(null);break}}e.ref!==null&&(A(e),v("Invalid attribute `ref` supplied to `React.Fragment`."),A(null))}}function Oe(e,r,t,n,i,u){{var o=Le(e);if(!o){var a="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(a+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var p=ar(i);p?a+=p:a+=xe();var s;e===null?s="null":Z(e)?s="array":e!==void 0&&e.$$typeof===E?(s="<"+(S(e.type)||"Unknown")+" />",a=" Did you accidentally export a JSX literal instead of a component?"):s=typeof e,v("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",s,a)}var f=nr(e,r,t,i,u);if(f==null)return f;if(o){var m=r.children;if(m!==void 0)if(n)if(Z(m)){for(var I=0;I<m.length;I++)Ce(m[I],e);Object.freeze&&Object.freeze(m)}else v("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Ce(m,e)}return e===b?ur(f):ir(f),f}}function sr(e,r,t){return Oe(e,r,t,!0)}function fr(e,r,t){return Oe(e,r,t,!1)}var lr=fr,cr=sr;W.Fragment=b,W.jsx=lr,W.jsxs=cr}()),W}process.env.NODE_ENV==="production"?J.exports=je():J.exports=ke();var q=J.exports;function Fe(c,E){let R="";const b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";for(let _=0;_<c;_++){const C=b.charAt(Math.floor(Math.random()*b.length));R+=C}return E(R),R}function oe(c){const E=c.height,R=c.width,b=c.textColor,_=c.fontFamily,C=c.fontSize,O=c.paddingLeft,T=c.paddingTop,l=c.length,P=c.background,d=c.onGenerated,[h,x]=y.useState("");y.useEffect(()=>{x(Fe(l,d))},[l,d]);const F=()=>{const D=[];if(h){const Y=h.split("");for(let g=0;g<Y.length;g++)D.push(`<text font-family="${_}" font-size="${C}" x="${O*g}" y="${T}" fill="${b}" >${Y[g]}</text>`)}return D},N=()=>{const D=F(),g=`data:image/svg+xml;base64,${btoa(`<svg xmlns='http://www.w3.org/2000/svg' height="${E}" width="${R}"> ${D.join()} </svg>`)}`;return y.createElement("img",{style:{background:P,paddingLeft:`${O}px`,borderRadius:"4px"},src:g,alt:""})};return q.jsx(q.Fragment,{children:q.jsx(N,{})})}oe.defaultProps={height:100,width:200,textColor:"#e50446",fontFamily:"Arial",fontSize:"30",paddingTop:"60",paddingLeft:40,lenght:5,background:"#000000",onGenerated:()=>{}},j.CaptchaText=oe,Object.defineProperty(j,Symbol.toStringTag,{value:"Module"})});