UNPKG

react-lite-scrollbar

Version:
316 lines (315 loc) 9.91 kB
import ee, { useState as re, useCallback as te, useEffect as ne } from "react"; var v = { exports: {} }, _ = {}; /** * @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 oe() { if (F) return _; F = 1; var c = Symbol.for("react.transitional.element"), d = Symbol.for("react.fragment"); function i(f, a, s) { var l = null; if (s !== void 0 && (l = "" + s), a.key !== void 0 && (l = "" + a.key), "key" in a) { s = {}; for (var m in a) m !== "key" && (s[m] = a[m]); } else s = a; return a = s.ref, { $$typeof: c, type: f, key: l, ref: a !== void 0 ? a : null, props: s }; } return _.Fragment = d, _.jsx = i, _.jsxs = i, _; } 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 L; function ae() { return L || (L = 1, process.env.NODE_ENV !== "production" && function() { function c(e) { if (e == null) return null; if (typeof e == "function") return e.$$typeof === Z ? null : e.displayName || e.name || null; if (typeof e == "string") return e; switch (e) { case k: return "Fragment"; case q: return "Profiler"; case M: return "StrictMode"; case H: return "Suspense"; case V: return "SuspenseList"; case B: 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 W: return "Portal"; case G: return (e.displayName || "Context") + ".Provider"; case z: return (e._context.displayName || "Context") + ".Consumer"; case J: var r = e.render; return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e; case X: return r = e.displayName || null, r !== null ? r : c(e.type) || "Memo"; case j: r = e._payload, e = e._init; try { return c(e(r)); } catch { } } return null; } function d(e) { return "" + e; } function i(e) { try { d(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 ), d(e); } } function f(e) { if (e === k) return "<>"; if (typeof e == "object" && e !== null && e.$$typeof === j) return "<...>"; try { var r = c(e); return r ? "<" + r + ">" : "<...>"; } catch { return "<...>"; } } function a() { var e = A.A; return e === null ? null : e.getOwner(); } function s() { return Error("react-stack-top-frame"); } function l(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 m(e, r) { function t() { N || (N = !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 p() { var e = c(this.type); return C[e] || (C[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 U(e, r, t, n, E, u, S, h) { return t = u.ref, e = { $$typeof: P, type: e, key: r, props: u, _owner: E }, (t !== void 0 ? t : null) !== null ? Object.defineProperty(e, "ref", { enumerable: !1, get: p }) : 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: S }), Object.defineProperty(e, "_debugTask", { configurable: !1, enumerable: !1, writable: !0, value: h }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e; } function g(e, r, t, n, E, u, S, h) { var o = r.children; if (o !== void 0) if (n) if (Q(o)) { for (n = 0; n < o.length; n++) x(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 x(o); if (y.call(r, "key")) { o = c(e); var R = Object.keys(r).filter(function(K) { return K !== "key"; }); n = 0 < R.length ? "{key: someKey, " + R.join(": ..., ") + ": ...}" : "{key: someKey}", I[o + n] || (R = 0 < R.length ? "{" + R.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, R, o ), I[o + n] = !0); } if (o = null, t !== void 0 && (i(t), o = "" + t), l(r) && (i(r.key), o = "" + r.key), "key" in r) { t = {}; for (var w in r) w !== "key" && (t[w] = r[w]); } else t = r; return o && m( t, typeof e == "function" ? e.displayName || e.name || "Unknown" : e ), U( e, o, u, E, a(), t, S, h ); } function x(e) { typeof e == "object" && e !== null && e.$$typeof === P && e._store && (e._store.validated = 1); } var T = ee, P = Symbol.for("react.transitional.element"), W = Symbol.for("react.portal"), k = Symbol.for("react.fragment"), M = Symbol.for("react.strict_mode"), q = Symbol.for("react.profiler"), z = Symbol.for("react.consumer"), G = Symbol.for("react.context"), J = Symbol.for("react.forward_ref"), H = Symbol.for("react.suspense"), V = Symbol.for("react.suspense_list"), X = Symbol.for("react.memo"), j = Symbol.for("react.lazy"), B = Symbol.for("react.activity"), Z = Symbol.for("react.client.reference"), A = T.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, y = Object.prototype.hasOwnProperty, Q = Array.isArray, O = console.createTask ? console.createTask : function() { return null; }; T = { "react-stack-bottom-frame": function(e) { return e(); } }; var N, C = {}, D = T["react-stack-bottom-frame"].bind( T, s )(), Y = O(f(s)), I = {}; b.Fragment = k, b.jsx = function(e, r, t, n, E) { var u = 1e4 > A.recentlyCreatedOwnerStacks++; return g( e, r, t, !1, n, E, u ? Error("react-stack-top-frame") : D, u ? O(f(e)) : Y ); }, b.jsxs = function(e, r, t, n, E) { var u = 1e4 > A.recentlyCreatedOwnerStacks++; return g( e, r, t, !0, n, E, u ? Error("react-stack-top-frame") : D, u ? O(f(e)) : Y ); }; }()), b; } var $; function se() { return $ || ($ = 1, process.env.NODE_ENV === "production" ? v.exports = oe() : v.exports = ae()), v.exports; } var ce = se(); const le = "4", ue = "#000", ie = "0.1", fe = 999, de = (c, d = le, i = ue, f = ie) => ({ margin: 0, padding: 0, top: 0, position: "fixed", zIndex: fe, backgroundColor: i, height: `${d}px`, width: c ?? void 0, transitionDuration: `${f}s` }); function Ee({ height: c, bgColor: d, duration: i }) { const [f, a] = re(null), s = te(() => { const l = document.body.scrollTop || document.documentElement.scrollTop, m = document.documentElement.scrollHeight - document.documentElement.clientHeight, p = l / m * 100; m > 0 ? a(`${p}%`) : a(null); }, []); return ne(() => { try { window.addEventListener("scroll", s); } catch (l) { console.error(l); } return () => { try { window.removeEventListener("scroll", s); } catch (l) { console.error(l); } }; }, [s]), /* @__PURE__ */ ce.jsx("div", { style: de(f, c, d, i) }); } export { Ee as ScrollBar };