@acrool/react-hooks
Version:
Common javascript utils methods for project development
306 lines (305 loc) • 9.77 kB
JavaScript
import te, { createContext as ne, useState as oe, useRef as ae, useCallback as $, useEffect as se, useContext as ue } from "react";
var T = { exports: {} }, R = {};
/**
* @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 F;
function ce() {
if (F) return R;
F = 1;
var u = Symbol.for("react.transitional.element"), m = Symbol.for("react.fragment");
function i(f, a, s) {
var c = null;
if (s !== void 0 && (c = "" + s), a.key !== void 0 && (c = "" + a.key), "key" in a) {
s = {};
for (var E in a)
E !== "key" && (s[E] = a[E]);
} else s = a;
return a = s.ref, {
$$typeof: u,
type: f,
key: c,
ref: a !== void 0 ? a : null,
props: s
};
}
return R.Fragment = m, R.jsx = i, R.jsxs = i, R;
}
var b = {};
/**
* @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 D;
function le() {
return D || (D = 1, process.env.NODE_ENV !== "production" && function() {
function u(e) {
if (e == null) return null;
if (typeof e == "function")
return e.$$typeof === K ? null : e.displayName || e.name || null;
if (typeof e == "string") return e;
switch (e) {
case p:
return "Fragment";
case J:
return "Profiler";
case q:
return "StrictMode";
case X:
return "Suspense";
case B:
return "SuspenseList";
case Q:
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 z:
return (e._context.displayName || "Context") + ".Consumer";
case G:
var r = e.render;
return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
case Z:
return r = e.displayName || null, r !== null ? r : u(e.type) || "Memo";
case h:
r = e._payload, e = e._init;
try {
return u(e(r));
} catch {
}
}
return null;
}
function m(e) {
return "" + e;
}
function i(e) {
try {
m(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
), m(e);
}
}
function f(e) {
if (e === p) return "<>";
if (typeof e == "object" && e !== null && e.$$typeof === h)
return "<...>";
try {
var r = u(e);
return r ? "<" + r + ">" : "<...>";
} catch {
return "<...>";
}
}
function a() {
var e = k.A;
return e === null ? null : e.getOwner();
}
function s() {
return Error("react-stack-top-frame");
}
function c(e) {
if (y.call(e, "key")) {
var r = Object.getOwnPropertyDescriptor(e, "key").get;
if (r && r.isReactWarning) return !1;
}
return e.key !== void 0;
}
function E(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 H() {
var e = u(this.type);
return N[e] || (N[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 W(e, r, t, n, d, l, x, P) {
return t = l.ref, e = {
$$typeof: j,
type: e,
key: r,
props: l,
_owner: d
}, (t !== void 0 ? t : null) !== null ? Object.defineProperty(e, "ref", {
enumerable: !1,
get: H
}) : 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: x
}), Object.defineProperty(e, "_debugTask", {
configurable: !1,
enumerable: !1,
writable: !0,
value: P
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
}
function w(e, r, t, n, d, l, x, P) {
var o = r.children;
if (o !== void 0)
if (n)
if (ee(o)) {
for (n = 0; n < o.length; n++)
g(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 g(o);
if (y.call(r, "key")) {
o = u(e);
var v = Object.keys(r).filter(function(re) {
return re !== "key";
});
n = 0 < v.length ? "{key: someKey, " + v.join(": ..., ") + ": ...}" : "{key: someKey}", I[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
), I[o + n] = !0);
}
if (o = null, t !== void 0 && (i(t), o = "" + t), c(r) && (i(r.key), o = "" + r.key), "key" in r) {
t = {};
for (var A in r)
A !== "key" && (t[A] = r[A]);
} else t = r;
return o && E(
t,
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
), W(
e,
o,
l,
d,
a(),
t,
x,
P
);
}
function g(e) {
typeof e == "object" && e !== null && e.$$typeof === j && e._store && (e._store.validated = 1);
}
var _ = te, j = Symbol.for("react.transitional.element"), U = Symbol.for("react.portal"), p = Symbol.for("react.fragment"), q = Symbol.for("react.strict_mode"), J = Symbol.for("react.profiler"), z = Symbol.for("react.consumer"), V = Symbol.for("react.context"), G = Symbol.for("react.forward_ref"), X = Symbol.for("react.suspense"), B = Symbol.for("react.suspense_list"), Z = Symbol.for("react.memo"), h = Symbol.for("react.lazy"), Q = Symbol.for("react.activity"), K = Symbol.for("react.client.reference"), k = _.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, y = Object.prototype.hasOwnProperty, ee = Array.isArray, O = console.createTask ? console.createTask : function() {
return null;
};
_ = {
"react-stack-bottom-frame": function(e) {
return e();
}
};
var C, N = {}, Y = _["react-stack-bottom-frame"].bind(
_,
s
)(), L = O(f(s)), I = {};
b.Fragment = p, b.jsx = function(e, r, t, n, d) {
var l = 1e4 > k.recentlyCreatedOwnerStacks++;
return w(
e,
r,
t,
!1,
n,
d,
l ? Error("react-stack-top-frame") : Y,
l ? O(f(e)) : L
);
}, b.jsxs = function(e, r, t, n, d) {
var l = 1e4 > k.recentlyCreatedOwnerStacks++;
return w(
e,
r,
t,
!0,
n,
d,
l ? Error("react-stack-top-frame") : Y,
l ? O(f(e)) : L
);
};
}()), b;
}
var M;
function ie() {
return M || (M = 1, process.env.NODE_ENV === "production" ? T.exports = ce() : T.exports = le()), T.exports;
}
var fe = ie();
const S = ne({
isHovering: !1
}), me = ({
children: u
}) => {
const [m, i] = oe(!1), f = ae(null), a = $(() => i(!0), []), s = $(() => i(!1), []);
return se(() => {
const c = f.current;
if (c)
return c.addEventListener("mouseenter", a), c.addEventListener("mouseleave", s), () => {
c.removeEventListener("mouseenter", a), c.removeEventListener("mouseleave", s);
};
}, [a, s]), /* @__PURE__ */ fe.jsx(S.Provider, { value: { isHovering: m, ref: f }, children: u });
}, ve = S.Consumer, Ee = () => {
const u = ue(S);
if (!u)
throw new Error("useHoverContext 必須在 HoverProvider 內使用");
return u.isHovering;
};
export {
ve as HoverConsumer,
me as HoverProvider,
Ee as useHover
};