glitched-text-react
Version:
Glitched/hacker text for react highly customizable
300 lines (299 loc) • 9.55 kB
JavaScript
import re, { useState as te, useRef as $ } from "react";
var k = { exports: {} }, T = {};
/**
* @license React
* react-jsx-runtime.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var D;
function ne() {
if (D) return T;
D = 1;
var u = Symbol.for("react.transitional.element"), f = Symbol.for("react.fragment");
function d(m, a, s) {
var E = null;
if (s !== void 0 && (E = "" + s), a.key !== void 0 && (E = "" + a.key), "key" in a) {
s = {};
for (var c in a)
c !== "key" && (s[c] = a[c]);
} else s = a;
return a = s.ref, {
$$typeof: u,
type: m,
key: E,
ref: a !== void 0 ? a : null,
props: s
};
}
return T.Fragment = f, T.jsx = d, T.jsxs = d, T;
}
var _ = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var L;
function oe() {
return L || (L = 1, process.env.NODE_ENV !== "production" && function() {
function u(e) {
if (e == null) return null;
if (typeof e == "function")
return e.$$typeof === Q ? null : e.displayName || e.name || null;
if (typeof e == "string") return e;
switch (e) {
case S:
return "Fragment";
case q:
return "Profiler";
case J:
return "StrictMode";
case X:
return "Suspense";
case B:
return "SuspenseList";
case Z:
return "Activity";
}
if (typeof e == "object")
switch (typeof e.tag == "number" && console.error(
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
), e.$$typeof) {
case U:
return "Portal";
case V:
return (e.displayName || "Context") + ".Provider";
case G:
return (e._context.displayName || "Context") + ".Consumer";
case z:
var r = e.render;
return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
case H:
return r = e.displayName || null, r !== null ? r : u(e.type) || "Memo";
case y:
r = e._payload, e = e._init;
try {
return u(e(r));
} catch {
}
}
return null;
}
function f(e) {
return "" + e;
}
function d(e) {
try {
f(e);
var r = !1;
} catch {
r = !0;
}
if (r) {
r = console;
var t = r.error, n = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
return t.call(
r,
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
n
), f(e);
}
}
function m(e) {
if (e === S) return "<>";
if (typeof e == "object" && e !== null && e.$$typeof === y)
return "<...>";
try {
var r = u(e);
return r ? "<" + r + ">" : "<...>";
} catch {
return "<...>";
}
}
function a() {
var e = h.A;
return e === null ? null : e.getOwner();
}
function s() {
return Error("react-stack-top-frame");
}
function E(e) {
if (N.call(e, "key")) {
var r = Object.getOwnPropertyDescriptor(e, "key").get;
if (r && r.isReactWarning) return !1;
}
return e.key !== void 0;
}
function c(e, r) {
function t() {
C || (C = !0, console.error(
"%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://react.dev/link/special-props)",
r
));
}
t.isReactWarning = !0, Object.defineProperty(e, "key", {
get: t,
configurable: !0
});
}
function b() {
var e = u(this.type);
return Y[e] || (Y[e] = !0, console.error(
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
)), e = this.props.ref, e !== void 0 ? e : null;
}
function O(e, r, t, n, i, l, j, w) {
return t = l.ref, e = {
$$typeof: g,
type: e,
key: r,
props: l,
_owner: i
}, (t !== void 0 ? t : null) !== null ? Object.defineProperty(e, "ref", {
enumerable: !1,
get: b
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: 0
}), Object.defineProperty(e, "_debugInfo", {
configurable: !1,
enumerable: !1,
writable: !0,
value: null
}), Object.defineProperty(e, "_debugStack", {
configurable: !1,
enumerable: !1,
writable: !0,
value: j
}), Object.defineProperty(e, "_debugTask", {
configurable: !1,
enumerable: !1,
writable: !0,
value: w
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
}
function p(e, r, t, n, i, l, j, w) {
var o = r.children;
if (o !== void 0)
if (n)
if (K(o)) {
for (n = 0; n < o.length; n++)
A(o[n]);
Object.freeze && Object.freeze(o);
} else
console.error(
"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 A(o);
if (N.call(r, "key")) {
o = u(e);
var v = Object.keys(r).filter(function(ee) {
return ee !== "key";
});
n = 0 < v.length ? "{key: someKey, " + v.join(": ..., ") + ": ...}" : "{key: someKey}", F[o + n] || (v = 0 < v.length ? "{" + v.join(": ..., ") + ": ...}" : "{}", console.error(
`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`,
n,
o,
v,
o
), F[o + n] = !0);
}
if (o = null, t !== void 0 && (d(t), o = "" + t), E(r) && (d(r.key), o = "" + r.key), "key" in r) {
t = {};
for (var x in r)
x !== "key" && (t[x] = r[x]);
} else t = r;
return o && c(
t,
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
), O(
e,
o,
l,
i,
a(),
t,
j,
w
);
}
function A(e) {
typeof e == "object" && e !== null && e.$$typeof === g && e._store && (e._store.validated = 1);
}
var R = re, g = Symbol.for("react.transitional.element"), U = Symbol.for("react.portal"), S = Symbol.for("react.fragment"), J = Symbol.for("react.strict_mode"), q = Symbol.for("react.profiler"), G = Symbol.for("react.consumer"), V = Symbol.for("react.context"), z = Symbol.for("react.forward_ref"), X = Symbol.for("react.suspense"), B = Symbol.for("react.suspense_list"), H = Symbol.for("react.memo"), y = Symbol.for("react.lazy"), Z = Symbol.for("react.activity"), Q = Symbol.for("react.client.reference"), h = R.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, N = Object.prototype.hasOwnProperty, K = Array.isArray, P = console.createTask ? console.createTask : function() {
return null;
};
R = {
"react-stack-bottom-frame": function(e) {
return e();
}
};
var C, Y = {}, I = R["react-stack-bottom-frame"].bind(
R,
s
)(), M = P(m(s)), F = {};
_.Fragment = S, _.jsx = function(e, r, t, n, i) {
var l = 1e4 > h.recentlyCreatedOwnerStacks++;
return p(
e,
r,
t,
!1,
n,
i,
l ? Error("react-stack-top-frame") : I,
l ? P(m(e)) : M
);
}, _.jsxs = function(e, r, t, n, i) {
var l = 1e4 > h.recentlyCreatedOwnerStacks++;
return p(
e,
r,
t,
!0,
n,
i,
l ? Error("react-stack-top-frame") : I,
l ? P(m(e)) : M
);
};
}()), _;
}
var W;
function ae() {
return W || (W = 1, process.env.NODE_ENV === "production" ? k.exports = ne() : k.exports = oe()), k.exports;
}
var se = ae();
const ce = ({
text: u,
letters: f = "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
numberOfIterations: d = 4,
msPerIteration: m = 30,
...a
}) => {
const [s, E] = te(u), c = $(0), b = $(void 0), O = () => {
clearInterval(b.current), c.current = 0, b.current = setInterval(() => {
const p = s.split("").map((A, R) => R < c.current ? u[R] : f[Math.floor(Math.random() * f.length)]);
E(p.join("")), c.current += 1 / d, c.current > u.length && clearInterval(b.current);
}, m);
};
return /* @__PURE__ */ se.jsx("h1", { onMouseOver: O, ...a, children: s });
};
export {
ce as GlitchedText
};