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