UNPKG

@zhou96/marquee-text

Version:
31 lines (28 loc) 14.8 kB
(function(T,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],d):(T=typeof globalThis<"u"?globalThis:T||self,d(T.MarqueeText={},T.React))})(this,function(T,d){"use strict";var X={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 oe;function Ie(){if(oe)return W;oe=1;var k=d,O=Symbol.for("react.element"),M=Symbol.for("react.fragment"),y=Object.prototype.hasOwnProperty,w=k.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,P={key:!0,ref:!0,__self:!0,__source:!0};function R(m,f,E){var v,g={},b=null,D=null;E!==void 0&&(b=""+E),f.key!==void 0&&(b=""+f.key),f.ref!==void 0&&(D=f.ref);for(v in f)y.call(f,v)&&!P.hasOwnProperty(v)&&(g[v]=f[v]);if(m&&m.defaultProps)for(v in f=m.defaultProps,f)g[v]===void 0&&(g[v]=f[v]);return{$$typeof:O,type:m,key:b,ref:D,props:g,_owner:w.current}}return W.Fragment=M,W.jsx=R,W.jsxs=R,W}var I={};/** * @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 ue;function Me(){return ue||(ue=1,process.env.NODE_ENV!=="production"&&function(){var k=d,O=Symbol.for("react.element"),M=Symbol.for("react.portal"),y=Symbol.for("react.fragment"),w=Symbol.for("react.strict_mode"),P=Symbol.for("react.profiler"),R=Symbol.for("react.provider"),m=Symbol.for("react.context"),f=Symbol.for("react.forward_ref"),E=Symbol.for("react.suspense"),v=Symbol.for("react.suspense_list"),g=Symbol.for("react.memo"),b=Symbol.for("react.lazy"),D=Symbol.for("react.offscreen"),Y=Symbol.iterator,B="@@iterator";function H(e){if(e===null||typeof e!="object")return null;var r=Y&&e[Y]||e[B];return typeof r=="function"?r:null}var S=k.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function c(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];L("error",e,t)}}function L(e,r,t){{var n=S.ReactDebugCurrentFrame,o=n.getStackAddendum();o!==""&&(r+="%s",t=t.concat([o]));var u=t.map(function(i){return String(i)});u.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,u)}}var J=!1,fe=!1,q=!1,Ye=!1,Le=!1,ce;ce=Symbol.for("react.module.reference");function Ve(e){return!!(typeof e=="string"||typeof e=="function"||e===y||e===P||Le||e===w||e===E||e===v||Ye||e===D||J||fe||q||typeof e=="object"&&e!==null&&(e.$$typeof===b||e.$$typeof===g||e.$$typeof===R||e.$$typeof===m||e.$$typeof===f||e.$$typeof===ce||e.getModuleId!==void 0))}function Ue(e,r,t){var n=e.displayName;if(n)return n;var o=r.displayName||r.name||"";return o!==""?t+"("+o+")":t}function de(e){return e.displayName||"Context"}function C(e){if(e==null)return null;if(typeof e.tag=="number"&&c("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 y:return"Fragment";case M:return"Portal";case P:return"Profiler";case w:return"StrictMode";case E:return"Suspense";case v:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case m:var r=e;return de(r)+".Consumer";case R:var t=e;return de(t._context)+".Provider";case f:return Ue(e,e.render,"ForwardRef");case g:var n=e.displayName||null;return n!==null?n:C(e.type)||"Memo";case b:{var o=e,u=o._payload,i=o._init;try{return C(i(u))}catch{return null}}}return null}var x=Object.assign,V=0,ve,pe,he,_e,me,ge,ye;function Re(){}Re.__reactDisabledLog=!0;function Ne(){{if(V===0){ve=console.log,pe=console.info,he=console.warn,_e=console.error,me=console.group,ge=console.groupCollapsed,ye=console.groupEnd;var e={configurable:!0,enumerable:!0,value:Re,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}V++}}function Be(){{if(V--,V===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:x({},e,{value:ve}),info:x({},e,{value:pe}),warn:x({},e,{value:he}),error:x({},e,{value:_e}),group:x({},e,{value:me}),groupCollapsed:x({},e,{value:ge}),groupEnd:x({},e,{value:ye})})}V<0&&c("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Z=S.ReactCurrentDispatcher,Q;function K(e,r,t){{if(Q===void 0)try{throw Error()}catch(o){var n=o.stack.trim().match(/\n( *(at )?)/);Q=n&&n[1]||""}return` `+Q+e}}var ee=!1,$;{var Je=typeof WeakMap=="function"?WeakMap:Map;$=new Je}function Ee(e,r){if(!e||ee)return"";{var t=$.get(e);if(t!==void 0)return t}var n;ee=!0;var o=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var u;u=Z.current,Z.current=null,Ne();try{if(r){var i=function(){throw Error()};if(Object.defineProperty(i.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(i,[])}catch(h){n=h}Reflect.construct(e,[],i)}else{try{i.call()}catch(h){n=h}e.call(i.prototype)}}else{try{throw Error()}catch(h){n=h}e()}}catch(h){if(h&&n&&typeof h.stack=="string"){for(var a=h.stack.split(` `),p=n.stack.split(` `),s=a.length-1,l=p.length-1;s>=1&&l>=0&&a[s]!==p[l];)l--;for(;s>=1&&l>=0;s--,l--)if(a[s]!==p[l]){if(s!==1||l!==1)do if(s--,l--,l<0||a[s]!==p[l]){var _=` `+a[s].replace(" at new "," at ");return e.displayName&&_.includes("<anonymous>")&&(_=_.replace("<anonymous>",e.displayName)),typeof e=="function"&&$.set(e,_),_}while(s>=1&&l>=0);break}}}finally{ee=!1,Z.current=u,Be(),Error.prepareStackTrace=o}var F=e?e.displayName||e.name:"",j=F?K(F):"";return typeof e=="function"&&$.set(e,j),j}function Ke(e,r,t){return Ee(e,!1)}function $e(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function z(e,r,t){if(e==null)return"";if(typeof e=="function")return Ee(e,$e(e));if(typeof e=="string")return K(e);switch(e){case E:return K("Suspense");case v:return K("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case f:return Ke(e.render);case g:return z(e.type,r,t);case b:{var n=e,o=n._payload,u=n._init;try{return z(u(o),r,t)}catch{}}}return""}var U=Object.prototype.hasOwnProperty,be={},Te=S.ReactDebugCurrentFrame;function G(e){if(e){var r=e._owner,t=z(e.type,e._source,r?r.type:null);Te.setExtraStackFrame(t)}else Te.setExtraStackFrame(null)}function ze(e,r,t,n,o){{var u=Function.call.bind(U);for(var i in e)if(u(e,i)){var a=void 0;try{if(typeof e[i]!="function"){var p=Error((n||"React class")+": "+t+" type `"+i+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[i]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw p.name="Invariant Violation",p}a=e[i](r,i,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(s){a=s}a&&!(a instanceof Error)&&(G(o),c("%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,i,typeof a),G(null)),a instanceof Error&&!(a.message in be)&&(be[a.message]=!0,G(o),c("Failed %s type: %s",t,a.message),G(null))}}}var Ge=Array.isArray;function re(e){return Ge(e)}function Xe(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function He(e){try{return Se(e),!1}catch{return!0}}function Se(e){return""+e}function Ce(e){if(He(e))return c("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Xe(e)),Se(e)}var Oe=S.ReactCurrentOwner,qe={key:!0,ref:!0,__self:!0,__source:!0},we,Pe;function Ze(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 er(e,r){typeof e.ref=="string"&&Oe.current}function rr(e,r){{var t=function(){we||(we=!0,c("%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 tr(e,r){{var t=function(){Pe||(Pe=!0,c("%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 nr=function(e,r,t,n,o,u,i){var a={$$typeof:O,type:e,key:r,ref:t,props:i,_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:o}),Object.freeze&&(Object.freeze(a.props),Object.freeze(a)),a};function ar(e,r,t,n,o){{var u,i={},a=null,p=null;t!==void 0&&(Ce(t),a=""+t),Qe(r)&&(Ce(r.key),a=""+r.key),Ze(r)&&(p=r.ref,er(r,o));for(u in r)U.call(r,u)&&!qe.hasOwnProperty(u)&&(i[u]=r[u]);if(e&&e.defaultProps){var s=e.defaultProps;for(u in s)i[u]===void 0&&(i[u]=s[u])}if(a||p){var l=typeof e=="function"?e.displayName||e.name||"Unknown":e;a&&rr(i,l),p&&tr(i,l)}return nr(e,a,p,o,n,Oe.current,i)}}var te=S.ReactCurrentOwner,xe=S.ReactDebugCurrentFrame;function A(e){if(e){var r=e._owner,t=z(e.type,e._source,r?r.type:null);xe.setExtraStackFrame(t)}else xe.setExtraStackFrame(null)}var ne;ne=!1;function ae(e){return typeof e=="object"&&e!==null&&e.$$typeof===O}function je(){{if(te.current){var e=C(te.current.type);if(e)return` Check the render method of \``+e+"`."}return""}}function ir(e){return""}var ke={};function or(e){{var r=je();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 De(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=or(r);if(ke[t])return;ke[t]=!0;var n="";e&&e._owner&&e._owner!==te.current&&(n=" It was passed a child from "+C(e._owner.type)+"."),A(e),c('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 Ae(e,r){{if(typeof e!="object")return;if(re(e))for(var t=0;t<e.length;t++){var n=e[t];ae(n)&&De(n,r)}else if(ae(e))e._store&&(e._store.validated=!0);else if(e){var o=H(e);if(typeof o=="function"&&o!==e.entries)for(var u=o.call(e),i;!(i=u.next()).done;)ae(i.value)&&De(i.value,r)}}}function ur(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===f||r.$$typeof===g))t=r.propTypes;else return;if(t){var n=C(r);ze(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!ne){ne=!0;var o=C(r);c("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",o||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&c("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function sr(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),c("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),c("Invalid attribute `ref` supplied to `React.Fragment`."),A(null))}}var Fe={};function We(e,r,t,n,o,u){{var i=Ve(e);if(!i){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=ir();p?a+=p:a+=je();var s;e===null?s="null":re(e)?s="array":e!==void 0&&e.$$typeof===O?(s="<"+(C(e.type)||"Unknown")+" />",a=" Did you accidentally export a JSX literal instead of a component?"):s=typeof e,c("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 l=ar(e,r,t,o,u);if(l==null)return l;if(i){var _=r.children;if(_!==void 0)if(n)if(re(_)){for(var F=0;F<_.length;F++)Ae(_[F],e);Object.freeze&&Object.freeze(_)}else c("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 Ae(_,e)}if(U.call(r,"key")){var j=C(e),h=Object.keys(r).filter(function(pr){return pr!=="key"}),ie=h.length>0?"{key: someKey, "+h.join(": ..., ")+": ...}":"{key: someKey}";if(!Fe[j+ie]){var vr=h.length>0?"{"+h.join(": ..., ")+": ...}":"{}";c(`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} />`,ie,j,vr,j),Fe[j+ie]=!0}}return e===y?sr(l):ur(l),l}}function lr(e,r,t){return We(e,r,t,!0)}function fr(e,r,t){return We(e,r,t,!1)}var cr=fr,dr=lr;I.Fragment=y,I.jsx=cr,I.jsxs=dr}()),I}process.env.NODE_ENV==="production"?X.exports=Ie():X.exports=Me();var se=X.exports;const N={container:"_container_3y29l_1",textContent:"_textContent_3y29l_8",animate:"_animate_3y29l_13",animateRight:"_animateRight_3y29l_17"},le=({text:k,className:O="",style:M={},speed:y=20,pauseOnHover:w=!0,direction:P="left"})=>{const R=d.useRef(null),m=d.useRef(null),[f,E]=d.useState(!1),[v,g]=d.useState(0),[b,D]=d.useState(0),[Y,B]=d.useState(!1),H=d.useMemo(()=>Y&&w,[Y,w]);d.useEffect(()=>{const c=()=>{if(R.current&&m.current){const L=R.current.offsetWidth,J=m.current.offsetWidth;if(J>L){const q=(L+J)/y;D(L),g(q),E(!0)}else E(!1)}};return c(),window.addEventListener("resize",c),()=>window.removeEventListener("resize",c)},[k,y]);const S=d.useMemo(()=>f?P==="right"?N.animateRight:N.animate:"",[f,P]);return se.jsx("div",{ref:R,className:`${N.container} ${O}`,style:M,onMouseEnter:()=>B(!0),onMouseLeave:()=>B(!1),children:se.jsx("div",{ref:m,className:`${N.textContent} ${S}`,style:{...f&&{"--animation-duration":`${v}s`,"--container-width":b+"px",animationPlayState:H?"paused":"running"}},children:k})})};T.MarqueeText=le,T.default=le,Object.defineProperties(T,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});