2 lines
13 KiB
JavaScript
2 lines
13 KiB
JavaScript
import{d9 as O,da as H,db as W,t as Z,l as s,aq as U,aY as he,x as me,G as J,H as K,M as _,z as g,aK as ve,dc as Q,d8 as fe,ad as I,ae as ge,D as p,Q as v,T as i,U as ye,E as we,a4 as P,v as Ee,aw as Se,d7 as Me,J as xe}from"./index-CEmnTf-r.js";var R,Te=(R={},R[O]="in",R[H]="in",R[W]="out",R),Ne={component:function(h){var a,e,n=h.data||{},t=h.thumbMode,r=h.classnames;return s.createElement(s.Fragment,null,n.hasOwnProperty("image")?s.createElement(Me,{src:n.image,title:n.title,href:n.href,blank:n.blank,htmlTarget:n.htmlTarget,caption:n.description,thumbMode:(e=(a=n.thumbMode)!==null&&a!==void 0?a:t)!==null&&e!==void 0?e:"contain",imageMode:"original",className:r("Carousel-image")}):n.hasOwnProperty("html")?s.createElement(xe,{html:n.html,filterHtml:h.env.filterHtml}):n.hasOwnProperty("item")?s.createElement("span",null,n.item):s.createElement("p",null))}},$=20,Ce=function(h){Z(a,h);function a(){var e=h!==null&&h.apply(this,arguments)||this;return e.wrapperRef=s.createRef(),e.state={current:0,options:e.props.options||U(e.props)||[],nextAnimation:"",mouseStartLocation:null,isPaused:!1},e.loading=!1,e.marqueeRef=s.createRef(),e.contentRef=s.createRef(),e}return a.prototype.componentDidMount=function(){this.prepareAutoSlide(),this.props.animation==="marquee"&&this.marquee()},a.prototype.componentDidUpdate=function(e){var n=this.props,t=n.options||U(n)||[],r=e.options||U(e)||[];he(r,t)&&this.setState({options:t}),this.props.animation==="marquee"&&e.animation!=="marquee"&&this.marquee()},a.prototype.componentWillUnmount=function(){this.clearAutoTimeout(),cancelAnimationFrame(this.marqueeRequestId)},a.prototype.marquee=function(){var e=this;if(!(!this.marqueeRef.current||!this.contentRef.current)){var n=0,t=performance.now(),r=this.contentRef.current,o=function(u){var c,l,m=u-t;t=u;var M=(l=(c=e.marqueeRef.current)===null||c===void 0?void 0:c.offsetWidth)!==null&&l!==void 0?l:0;if(!e.state.isPaused){var N=M*(m/e.props.duration);n+=-N;var x=r.scrollWidth/2;Math.abs(n)>=x&&(n=0),r.style.transform="translateX(".concat(n,"px)")}e.marqueeRequestId=requestAnimationFrame(o)};this.marqueeRequestId=requestAnimationFrame(o)}},a.prototype.doAction=function(e,n,t,r){var o=e==null?void 0:e.actionType;~["next","prev"].indexOf(o)?this.autoSlide(o):o==="goto-image"&&this.changeSlide((r==null?void 0:r.activeIndex)-1)},a.prototype.prepareAutoSlide=function(){if(!(this.state.options.length<2)&&(this.clearAutoTimeout(),this.props.auto)){var e=this.props.interval;this.intervalTimeout=setTimeout(this.autoSlide,typeof e=="string"?me(e,this.props.data)||5e3:e)}},a.prototype.autoSlide=function(e){this.clearAutoTimeout();var n=this.props.animation,t=this.state.nextAnimation;switch(e){case"prev":n==="slide"?t="slideRight":t="",this.transitFramesTowards("right",t);break;case"next":default:t="",this.transitFramesTowards("left",t);break}this.durationTimeout=setTimeout(this.prepareAutoSlide,this.props.duration)},a.prototype.transitFramesTowards=function(e,n){return J(this,void 0,void 0,function(){var t,r,o,u,c,l;return K(this,function(m){switch(m.label){case 0:if(t=this.state.current,r=t,this.props.loop===!1&&(t===0&&e==="right"||t===this.state.options.length-1&&e==="left"))return[2];switch(e){case"left":t=this.getFrameId("next");break;case"right":t=this.getFrameId("prev");break}return o=this.props,u=o.dispatchEvent,c=o.data,[4,u("change",P(c,{activeIndex:t+1,prevIndex:r}))];case 1:return l=m.sent(),l!=null&&l.prevented?[2]:(this.setState({current:t,nextAnimation:n}),[2])}})})},a.prototype.getFrameId=function(e){var n=this.state,t=n.options,r=n.current,o=t.length;switch(e){case"prev":return(r-1+o)%o;case"next":return(r+1)%o;default:return r}},a.prototype.next=function(){var e=this.props.multiple;this.loading&&e&&e.count>1||this.autoSlide("next")},a.prototype.prev=function(){var e=this.props.multiple;this.loading&&e&&e.count>1||this.autoSlide("prev")},a.prototype.clearAutoTimeout=function(){clearTimeout(this.intervalTimeout),clearTimeout(this.durationTimeout)},a.prototype.changeSlide=function(e){return J(this,void 0,void 0,function(){var n,t,r,o,u,c;return K(this,function(l){switch(l.label){case 0:return n=this.state.current,t=this.props,r=t.dispatchEvent,o=t.data,u=t.multiple,this.loading&&u&&u.count>1?[2]:[4,r("change",P(o,{activeIndex:e,prevIndex:n}))];case 1:return c=l.sent(),c!=null&&c.prevented?[2]:(this.setState({current:e}),[2])}})})},a.prototype.renderDots=function(){var e=this,n=this.props.classnames,t=this.state,r=t.current,o=t.options;return s.createElement("div",{className:n("Carousel-dotsControl"),onMouseEnter:this.handleMouseEnter,onMouseLeave:this.handleMouseLeave},Array.from({length:o.length}).map(function(u,c){return s.createElement("span",{key:c,onClick:function(){return e.changeSlide(c)},className:n("Carousel-dot",r===c?"is-active":"")})}))},a.prototype.renderArrows=function(){var e=this.props.classnames;return s.createElement("div",{className:e("Carousel-arrowsControl"),onMouseEnter:this.handleMouseEnter,onMouseLeave:this.handleMouseLeave},s.createElement("div",{className:e("Carousel-leftArrow"),onClick:this.prev},s.createElement(_,{icon:"left-arrow",className:"icon"})),s.createElement("div",{className:e("Carousel-rightArrow"),onClick:this.next},s.createElement(_,{icon:"right-arrow",className:"icon"})))},a.prototype.handleMouseEnter=function(){var e=this.props.multiple;e&&e.count>1||this.clearAutoTimeout()},a.prototype.handleMouseLeave=function(){var e=this.props.multiple;e&&e.count>1||this.prepareAutoSlide()},a.prototype.getNewOptions=function(e,n){n===void 0&&(n=1);var t=e;if(Array.isArray(e)&&e.length){t=new Array(e.length);for(var r=0;r<e.length;r++){t[r]=new Array(n);for(var o=0;o<n;o++)t[r][o]=e[(r+o)%e.length]}}return t},a.prototype.getEventScreenXY=function(e){var n,t,r,o,u,c,l,m;return e.screenX!==void 0?(l=e.screenX,m=e.screenY):!((n=e.touches)===null||n===void 0)&&n.length?(l=(t=e.touches[0])===null||t===void 0?void 0:t.screenX,m=(r=e.touches[0])===null||r===void 0?void 0:r.screenY):!((o=e.changedTouches)===null||o===void 0)&&o.length&&(l=(u=e.changedTouches[0])===null||u===void 0?void 0:u.screenX,m=(c=e.changedTouches[0])===null||c===void 0?void 0:c.screenY),{screenX:l,screenY:m}},a.prototype.addMouseDownListener=function(e){var n=this.props.direction,t=this.getEventScreenXY(e),r=t.screenX,o=t.screenY,u=n==="vertical"?o:r;u!==void 0&&this.setState({mouseStartLocation:u})},a.prototype.addMouseUpListener=function(e){var n=this.getEventScreenXY(e),t=n.screenX,r=n.screenY,o=this.props.direction,u=o==="vertical"?r:t;this.state.mouseStartLocation!==null&&u!==void 0&&(u-this.state.mouseStartLocation>$?this.autoSlide("prev"):this.state.mouseStartLocation-u>$&&this.autoSlide(),this.setState({mouseStartLocation:null}))},a.prototype.render=function(){var e,n,t=this,r=this.props,o=r.render,u=r.className,c=r.style,l=r.classnames,m=r.itemSchema,M=r.animation,N=r.width,x=r.height,G=r.controls,ee=r.controlsTheme,te=r.placeholder,re=r.data,ne=r.name,C=r.duration,A=r.multiple,ae=r.alwaysShowArrow,y=r.icons,b=r.id,V=r.wrapperCustomStyle,ie=r.env,F=r.themeCss,X=this.state,S=X.options,j=X.current,oe=X.nextAnimation,k=null,L=c?g({},c):{};N&&(isNaN(Number(N))?L.width=N:L.width=N+"px"),x&&(isNaN(Number(x))?L.height=x:L.height=x+"px");var B=ve([G.indexOf("dots")>-1&&M!=="marquee",G.indexOf("arrows")>-1&&M!=="marquee"],2),se=B[0],z=B[1],D=oe||M;if(Array.isArray(S)&&S.length){var d=1;A&&typeof A.count=="number"&&A.count>=2&&(d=Math.floor(A.count)<S.length?Math.floor(A.count):S.length);var Y=this.getNewOptions(S,d),le=d>1&&typeof C=="number"?"".concat(C,"ms"):C||"500ms",ue=d>1&&typeof C=="number"?C:500,ce=(e={},e[O]=0,e[H]=0,e[W]=D==="slideRight"?100/d:-100/d,e[Q]=D==="slideRight"?-100/d:100/d,e),de=d>1?g({transitionTimingFunction:"linear",transitionDuration:le},M==="slide"?{transform:"translateX(".concat(ce[status],"%)")}:{}):{},q=function(E){var w,f=E.itemSchema,T=Ee(E,["itemSchema"]);return o("".concat(j,"/body"),f||m?f||m:Ne,{thumbMode:t.props.thumbMode,data:P(re,Se(E)?T:(w={item:E},w[ne]=E,w))})};k=M==="marquee"?s.createElement("div",{ref:this.marqueeRef,className:l("Marquee-container"),onMouseEnter:function(){return t.setState({isPaused:!0})},onMouseLeave:function(){return t.setState({isPaused:!1})},style:{width:"100%",height:x}},s.createElement("div",{className:l("Marquee-content"),ref:this.contentRef},S.concat(S).map(function(E,w){return s.createElement("div",{key:w,className:l("Marquee-item")},d===1?q(E):null,d>1?Y.concat(Y)[w].map(function(f,T){return s.createElement("div",{key:T,style:{width:100/d+"%",height:"100%",float:"left"}},q(f))}):null)}))):s.createElement("div",{ref:this.wrapperRef,className:l("Carousel-container"),onMouseEnter:this.handleMouseEnter,onMouseLeave:this.handleMouseLeave},S.map(function(E,w){return s.createElement(fe,{mountOnEnter:!0,unmountOnExit:!0,in:w===j,timeout:ue,key:w},function(f){return f===O&&t.wrapperRef.current&&t.wrapperRef.current.childNodes.forEach(function(T){return T.offsetHeight}),d>1&&((f===O||f===W)&&!t.loading?t.loading=!0:(f===H||f===Q)&&t.loading&&(t.loading=!1)),s.createElement("div",{className:l("Carousel-item",D,Te[f]),style:de},d===1?q(E):null,d>1?Y[w].map(function(T,pe){return s.createElement("div",{key:pe,style:{width:100/d+"%",height:"100%",float:"left"}},q(T))}):null)})}))}return s.createElement("div",{className:l("Carousel Carousel--".concat(ee),(n={},n["Carousel-arrow--always"]=!!ae,n),u,I(g(g({},this.props),{name:"baseControlClassName",id:b,themeCss:F})),I(g(g({},this.props),{name:"wrapperCustomStyle",id:b,themeCss:V})),{"Carousel-vertical":this.props.direction==="vertical"}),onMouseDown:this.props.mouseEvent?this.addMouseDownListener:void 0,onMouseUp:this.props.mouseEvent?this.addMouseUpListener:void 0,onMouseLeave:this.props.mouseEvent?this.addMouseUpListener:void 0,onTouchStart:this.props.mouseEvent?this.addMouseDownListener:void 0,onTouchEnd:this.props.mouseEvent?this.addMouseUpListener:void 0,style:L},k||te,se?this.renderDots():null,z?s.createElement("div",{className:l("Carousel-leftArrow",I(g(g({},this.props),{name:"galleryControlClassName",id:b,themeCss:F}))),onClick:this.prev},y&&y.prev?s.isValidElement(y.prev)?y.prev:o("arrow-prev",y.prev):s.createElement(_,{icon:"left-arrow",className:"icon",iconContent:"ImageGallery-prevBtn"})):null,z?s.createElement("div",{className:l("Carousel-rightArrow",I(g(g({},this.props),{name:"galleryControlClassName",id:b,themeCss:F}))),onClick:this.next},y&&y.next?s.isValidElement(y.next)?y.next:o("arrow-next",y.next):s.createElement(_,{icon:"right-arrow",className:"icon",iconContent:"ImageGallery-nextBtn"})):null,s.createElement(ge,g({},this.props,{config:{wrapperCustomStyle:V,id:b,themeCss:F,classNames:[{key:"baseControlClassName"},{key:"galleryControlClassName",weights:{default:{suf:" svg",important:!0}}}]},env:ie})))},a.defaultProps={auto:!0,interval:5e3,duration:500,controlsTheme:"light",animation:"fade",controls:["dots","arrows"],placeholder:"-",multiple:{count:1},alwaysShowArrow:!1},p([v,i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",void 0)],a.prototype,"prepareAutoSlide",null),p([v,i("design:type",Function),i("design:paramtypes",[String]),i("design:returntype",void 0)],a.prototype,"autoSlide",null),p([v,i("design:type",Function),i("design:paramtypes",[String,String]),i("design:returntype",Promise)],a.prototype,"transitFramesTowards",null),p([v,i("design:type",Function),i("design:paramtypes",[String]),i("design:returntype",void 0)],a.prototype,"getFrameId",null),p([v,i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",void 0)],a.prototype,"next",null),p([v,i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",void 0)],a.prototype,"prev",null),p([v,i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",void 0)],a.prototype,"clearAutoTimeout",null),p([v,i("design:type",Function),i("design:paramtypes",[Number]),i("design:returntype",Promise)],a.prototype,"changeSlide",null),p([v,i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",void 0)],a.prototype,"handleMouseEnter",null),p([v,i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",void 0)],a.prototype,"handleMouseLeave",null),p([v,i("design:type",Function),i("design:paramtypes",[Object]),i("design:returntype",void 0)],a.prototype,"addMouseDownListener",null),p([v,i("design:type",Function),i("design:paramtypes",[Object]),i("design:returntype",void 0)],a.prototype,"addMouseUpListener",null),a}(s.Component),be=function(h){Z(a,h);function a(e,n){var t=h.call(this,e)||this,r=n;return r.registerComponent(t),t}return a.prototype.componentWillUnmount=function(){var e;(e=h.prototype.componentWillUnmount)===null||e===void 0||e.call(this);var n=this.context;n.unRegisterComponent(this)},a.contextType=ye,a=p([we({type:"carousel"}),i("design:paramtypes",[Object,Object])],a),a}(Ce);export{Ce as Carousel,be as CarouselRenderer};
|