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

698 lines (689 loc) 22.6 kB
import re, { useState as ur, useEffect as sr } from "react"; var ee = { exports: {} }, W = {}; /** * @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 Se; function fr() { if (Se) return W; Se = 1; var c = re, y = Symbol.for("react.element"), E = Symbol.for("react.fragment"), b = Object.prototype.hasOwnProperty, R = c.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, S = { key: !0, ref: !0, __self: !0, __source: !0 }; function C(_, l, O) { var d, h = {}, T = null, j = null; O !== void 0 && (T = "" + O), l.key !== void 0 && (T = "" + l.key), l.ref !== void 0 && (j = l.ref); for (d in l) b.call(l, d) && !S.hasOwnProperty(d) && (h[d] = l[d]); if (_ && _.defaultProps) for (d in l = _.defaultProps, l) h[d] === void 0 && (h[d] = l[d]); return { $$typeof: y, type: _, key: T, ref: j, props: h, _owner: R.current }; } return W.Fragment = E, W.jsx = C, W.jsxs = C, W; } var Y = {}; /** * @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 Ce; function lr() { return Ce || (Ce = 1, process.env.NODE_ENV !== "production" && function() { var c = re, y = Symbol.for("react.element"), E = Symbol.for("react.portal"), b = Symbol.for("react.fragment"), R = Symbol.for("react.strict_mode"), S = Symbol.for("react.profiler"), C = Symbol.for("react.provider"), _ = Symbol.for("react.context"), l = Symbol.for("react.forward_ref"), O = Symbol.for("react.suspense"), d = Symbol.for("react.suspense_list"), h = Symbol.for("react.memo"), T = Symbol.for("react.lazy"), j = Symbol.for("react.offscreen"), L = Symbol.iterator, k = "@@iterator"; function A(e) { if (e === null || typeof e != "object") return null; var r = L && e[L] || e[k]; 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]; Oe("error", e, t); } } function Oe(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 Pe = !1, je = !1, ke = !1, Fe = !1, De = !1, te; te = Symbol.for("react.module.reference"); function Ae(e) { return !!(typeof e == "string" || typeof e == "function" || e === b || e === S || De || e === R || e === O || e === d || Fe || e === j || Pe || je || ke || typeof e == "object" && e !== null && (e.$$typeof === T || e.$$typeof === h || e.$$typeof === C || e.$$typeof === _ || e.$$typeof === l || // This needs to include all possible module reference object // types supported by any Flight configuration anywhere since // we don't know which Flight build this will end up being used // with. e.$$typeof === te || e.getModuleId !== void 0)); } function $e(e, r, t) { var n = e.displayName; if (n) return n; var i = r.displayName || r.name || ""; return i !== "" ? t + "(" + i + ")" : t; } function ne(e) { return e.displayName || "Context"; } function x(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 E: return "Portal"; case S: return "Profiler"; case R: return "StrictMode"; case O: return "Suspense"; case d: return "SuspenseList"; } if (typeof e == "object") switch (e.$$typeof) { case _: var r = e; return ne(r) + ".Consumer"; case C: var t = e; return ne(t._context) + ".Provider"; case l: return $e(e, e.render, "ForwardRef"); case h: var n = e.displayName || null; return n !== null ? n : x(e.type) || "Memo"; case T: { var i = e, u = i._payload, o = i._init; try { return x(o(u)); } catch { return null; } } } return null; } var P = Object.assign, $ = 0, ae, oe, ie, ue, se, fe, le; function ce() { } ce.__reactDisabledLog = !0; function Ie() { { if ($ === 0) { ae = console.log, oe = console.info, ie = console.warn, ue = console.error, se = console.group, fe = console.groupCollapsed, le = console.groupEnd; var e = { configurable: !0, enumerable: !0, value: ce, writable: !0 }; Object.defineProperties(console, { info: e, log: e, warn: e, error: e, group: e, groupCollapsed: e, groupEnd: e }); } $++; } } function We() { { if ($--, $ === 0) { var e = { configurable: !0, enumerable: !0, writable: !0 }; Object.defineProperties(console, { log: P({}, e, { value: ae }), info: P({}, e, { value: oe }), warn: P({}, e, { value: ie }), error: P({}, e, { value: ue }), group: P({}, e, { value: se }), groupCollapsed: P({}, e, { value: fe }), groupEnd: P({}, e, { value: le }) }); } $ < 0 && v("disabledDepth fell below zero. This is a bug in React. Please file an issue."); } } var z = g.ReactCurrentDispatcher, B; function M(e, r, t) { { if (B === void 0) try { throw Error(); } catch (i) { var n = i.stack.trim().match(/\n( *(at )?)/); B = n && n[1] || ""; } return ` ` + B + e; } } var q = !1, N; { var Ye = typeof WeakMap == "function" ? WeakMap : Map; N = new Ye(); } function de(e, r) { if (!e || q) return ""; { var t = N.get(e); if (t !== void 0) return t; } var n; q = !0; var i = Error.prepareStackTrace; Error.prepareStackTrace = void 0; var u; u = z.current, z.current = null, Ie(); 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" && N.set(e, m), m; } while (s >= 1 && f >= 0); break; } } } finally { q = !1, z.current = u, We(), Error.prepareStackTrace = i; } var D = e ? e.displayName || e.name : "", we = D ? M(D) : ""; return typeof e == "function" && N.set(e, we), we; } function Le(e, r, t) { return de(e, !1); } function Me(e) { var r = e.prototype; return !!(r && r.isReactComponent); } function V(e, r, t) { if (e == null) return ""; if (typeof e == "function") return de(e, Me(e)); if (typeof e == "string") return M(e); switch (e) { case O: return M("Suspense"); case d: return M("SuspenseList"); } if (typeof e == "object") switch (e.$$typeof) { case l: return Le(e.render); case h: return V(e.type, r, t); case T: { var n = e, i = n._payload, u = n._init; try { return V(u(i), r, t); } catch { } } } return ""; } var U = Object.prototype.hasOwnProperty, ve = {}, pe = g.ReactDebugCurrentFrame; function G(e) { if (e) { var r = e._owner, t = V(e.type, e._source, r ? r.type : null); pe.setExtraStackFrame(t); } else pe.setExtraStackFrame(null); } function Ne(e, r, t, n, i) { { var u = Function.call.bind(U); 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) && (G(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), G(null)), a instanceof Error && !(a.message in ve) && (ve[a.message] = !0, G(i), v("Failed %s type: %s", t, a.message), G(null)); } } } var Ve = Array.isArray; function J(e) { return Ve(e); } function Ue(e) { { var r = typeof Symbol == "function" && Symbol.toStringTag, t = r && e[Symbol.toStringTag] || e.constructor.name || "Object"; return t; } } function Ge(e) { try { return ge(e), !1; } catch { return !0; } } function ge(e) { return "" + e; } function he(e) { if (Ge(e)) return v("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", Ue(e)), ge(e); } var I = g.ReactCurrentOwner, ze = { key: !0, ref: !0, __self: !0, __source: !0 }, me, be, K; K = {}; function Be(e) { if (U.call(e, "ref")) { var r = Object.getOwnPropertyDescriptor(e, "ref").get; if (r && r.isReactWarning) return !1; } return e.ref !== void 0; } function qe(e) { if (U.call(e, "key")) { var r = Object.getOwnPropertyDescriptor(e, "key").get; if (r && r.isReactWarning) return !1; } return e.key !== void 0; } function Je(e, r) { if (typeof e.ref == "string" && I.current && r && I.current.stateNode !== r) { var t = x(I.current.type); K[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', x(I.current.type), e.ref), K[t] = !0); } } function Ke(e, r) { { var t = function() { me || (me = !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 He(e, r) { { var t = function() { be || (be = !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 Xe = function(e, r, t, n, i, u, o) { var a = { // This tag allows us to uniquely identify this as a React Element $$typeof: y, // Built-in properties that belong on the element type: e, key: r, ref: t, props: o, // Record the component responsible for creating this element. _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 Ze(e, r, t, n, i) { { var u, o = {}, a = null, p = null; t !== void 0 && (he(t), a = "" + t), qe(r) && (he(r.key), a = "" + r.key), Be(r) && (p = r.ref, Je(r, i)); for (u in r) U.call(r, u) && !ze.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 && Ke(o, f), p && He(o, f); } return Xe(e, a, p, i, n, I.current, o); } } var H = g.ReactCurrentOwner, ye = g.ReactDebugCurrentFrame; function F(e) { if (e) { var r = e._owner, t = V(e.type, e._source, r ? r.type : null); ye.setExtraStackFrame(t); } else ye.setExtraStackFrame(null); } var X; X = !1; function Z(e) { return typeof e == "object" && e !== null && e.$$typeof === y; } function Ee() { { if (H.current) { var e = x(H.current.type); if (e) return ` Check the render method of \`` + e + "`."; } return ""; } } function Qe(e) { { if (e !== void 0) { var r = e.fileName.replace(/^.*[\\\/]/, ""), t = e.lineNumber; return ` Check your code at ` + r + ":" + t + "."; } return ""; } } var Re = {}; function er(e) { { var r = Ee(); 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 _e(e, r) { { if (!e._store || e._store.validated || e.key != null) return; e._store.validated = !0; var t = er(r); if (Re[t]) return; Re[t] = !0; var n = ""; e && e._owner && e._owner !== H.current && (n = " It was passed a child from " + x(e._owner.type) + "."), F(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), F(null); } } function Te(e, r) { { if (typeof e != "object") return; if (J(e)) for (var t = 0; t < e.length; t++) { var n = e[t]; Z(n) && _e(n, r); } else if (Z(e)) e._store && (e._store.validated = !0); else if (e) { var i = A(e); if (typeof i == "function" && i !== e.entries) for (var u = i.call(e), o; !(o = u.next()).done; ) Z(o.value) && _e(o.value, r); } } } function rr(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 || // Note: Memo only checks outer props here. // Inner props are checked in the reconciler. r.$$typeof === h)) t = r.propTypes; else return; if (t) { var n = x(r); Ne(t, e.props, "prop", n, e); } else if (r.PropTypes !== void 0 && !X) { X = !0; var i = x(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 tr(e) { { for (var r = Object.keys(e.props), t = 0; t < r.length; t++) { var n = r[t]; if (n !== "children" && n !== "key") { F(e), v("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", n), F(null); break; } } e.ref !== null && (F(e), v("Invalid attribute `ref` supplied to `React.Fragment`."), F(null)); } } function xe(e, r, t, n, i, u) { { var o = Ae(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 = Qe(i); p ? a += p : a += Ee(); var s; e === null ? s = "null" : J(e) ? s = "array" : e !== void 0 && e.$$typeof === y ? (s = "<" + (x(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 = Ze(e, r, t, i, u); if (f == null) return f; if (o) { var m = r.children; if (m !== void 0) if (n) if (J(m)) { for (var D = 0; D < m.length; D++) Te(m[D], 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 Te(m, e); } return e === b ? tr(f) : rr(f), f; } } function nr(e, r, t) { return xe(e, r, t, !0); } function ar(e, r, t) { return xe(e, r, t, !1); } var or = ar, ir = nr; Y.Fragment = b, Y.jsx = or, Y.jsxs = ir; }()), Y; } process.env.NODE_ENV === "production" ? ee.exports = fr() : ee.exports = lr(); var Q = ee.exports; function cr(c, y) { let E = ""; const b = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for (let R = 0; R < c; R++) { const S = b.charAt( Math.floor(Math.random() * b.length) ); E += S; } return y(E), E; } function dr(c) { const y = c.height, E = c.width, b = c.textColor, R = c.fontFamily, S = c.fontSize, C = c.paddingLeft, _ = c.paddingTop, l = c.length, O = c.background, d = c.onGenerated, [h, T] = ur(""); sr(() => { T(cr(l, d)); }, [l, d]); const j = () => { const k = []; if (h) { const A = h.split(""); for (let g = 0; g < A.length; g++) k.push( `<text font-family="${R}" font-size="${S}" x="${C * g}" y="${_}" fill="${b}" >${A[g]}</text>` ); } return k; }, L = () => { const k = j(), g = `data:image/svg+xml;base64,${btoa( `<svg xmlns='http://www.w3.org/2000/svg' height="${y}" width="${E}"> ${k.join()} </svg>` )}`; return re.createElement("img", { style: { background: O, paddingLeft: `${C}px`, borderRadius: "4px" }, src: g, alt: "" }); }; return /* @__PURE__ */ Q.jsx(Q.Fragment, { children: /* @__PURE__ */ Q.jsx(L, {}) }); } dr.defaultProps = { height: 100, width: 200, textColor: "#e50446", fontFamily: "Arial", fontSize: "30", paddingTop: "60", paddingLeft: 40, lenght: 5, background: "#000000", onGenerated: () => { } }; export { dr as CaptchaText };