2 lines
16 KiB
JavaScript
2 lines
16 KiB
JavaScript
this.primereact=this.primereact||{},this.primereact.carousel=function(t,e,i,n,s){"use strict";function a(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=a(e),o=a(s);function l(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}function u(t){if(Array.isArray(t))return l(t)}function c(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}function p(t,e){if(t){if("string"==typeof t)return l(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(t):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?l(t,e):void 0}}function h(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function m(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function d(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function f(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function v(t,e,i){return e&&f(t.prototype,e),i&&f(t,i),Object.defineProperty(t,"prototype",{writable:!1}),t}function y(t,e){return y=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},y(t,e)}function g(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&y(t,e)}function b(t){return b="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},b(t)}function S(t,e){if(e&&("object"===b(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return m(t)}function I(t){return I=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},I(t)}function k(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function w(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.push.apply(i,n)}return i}function P(t){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?w(Object(i),!0).forEach((function(e){k(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):w(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}function O(t){var e=C();return function(){var i,n=I(t);if(e){var s=I(this).constructor;i=Reflect.construct(n,arguments,s)}else i=n.apply(this,arguments);return S(this,i)}}function C(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}var V=function(t){g(n,t);var e=O(n);function n(){return d(this,n),e.apply(this,arguments)}return v(n,[{key:"render",value:function(){var t=this.props.template(this.props.item),e=i.classNames(this.props.className,"p-carousel-item",{"p-carousel-item-active":this.props.active,"p-carousel-item-start":this.props.start,"p-carousel-item-end":this.props.end});return r.default.createElement("div",{className:e},t)}}]),n}(e.Component);k(V,"defaultProps",{template:null,item:null,active:!1,start:!1,end:!1,className:null});var N=function(t){g(s,t);var e=O(s);function s(t){var n;return d(this,s),(n=e.call(this,t)).state={numVisible:t.numVisible,numScroll:t.numScroll,totalShiftedItems:t.page*t.numScroll*-1},n.props.onPageChange||(n.state=P(P({},n.state),{},{page:t.page})),n.navBackward=n.navBackward.bind(m(n)),n.navForward=n.navForward.bind(m(n)),n.onTransitionEnd=n.onTransitionEnd.bind(m(n)),n.onTouchStart=n.onTouchStart.bind(m(n)),n.onTouchMove=n.onTouchMove.bind(m(n)),n.onTouchEnd=n.onTouchEnd.bind(m(n)),n.totalIndicators=0,n.remainingItems=0,n.allowAutoplay=!!n.props.autoplayInterval,n.circular=n.props.circular||n.allowAutoplay,n.attributeSelector=i.UniqueComponentId(),n.swipeThreshold=20,n}return v(s,[{key:"step",value:function(t,e){var n=this.state.totalShiftedItems,s=this.isCircular();null!=e?(n=this.state.numScroll*e*-1,s&&(n-=this.state.numVisible),this.isRemainingItemsAdded=!1):(n+=this.state.numScroll*t,this.isRemainingItemsAdded&&(n+=this.remainingItems-this.state.numScroll*t,this.isRemainingItemsAdded=!1),e=Math.abs(Math.floor((s?n+this.state.numVisible:n)/this.state.numScroll)));s&&this.state.page===this.totalIndicators-1&&-1===t?(n=-1*(this.props.value.length+this.state.numVisible),e=0):s&&0===this.state.page&&1===t?(n=0,e=this.totalIndicators-1):e===this.totalIndicators-1&&this.remainingItems>0&&(n+=-1*this.remainingItems-this.state.numScroll*t,this.isRemainingItemsAdded=!0),this.itemsContainer&&(i.DomHandler.removeClass(this.itemsContainer,"p-items-hidden"),this.changePosition(n),this.itemsContainer.style.transition="transform 500ms ease 0s"),this.props.onPageChange?(this.setState({totalShiftedItems:n}),this.props.onPageChange({page:e})):this.setState({page:e,totalShiftedItems:n})}},{key:"calculatePosition",value:function(){if(this.itemsContainer&&this.responsiveOptions){for(var t=window.innerWidth,e={numVisible:this.props.numVisible,numScroll:this.props.numScroll},i=0;i<this.responsiveOptions.length;i++){var n=this.responsiveOptions[i];parseInt(n.breakpoint,10)>=t&&(e=n)}var s={};if(this.state.numScroll!==e.numScroll){var a=this.getPage();a=Math.floor(a*this.state.numScroll/e.numScroll);var r=e.numScroll*a*-1;this.isCircular()&&(r-=e.numVisible),s={totalShiftedItems:r,numScroll:e.numScroll},this.props.onPageChange?this.props.onPageChange({page:a}):s=P(P({},s),{},{page:a})}this.state.numVisible!==e.numVisible&&(s=P(P({},s),{},{numVisible:e.numVisible})),Object.keys(s).length&&this.setState(s)}}},{key:"navBackward",value:function(t,e){(this.circular||0!==this.getPage())&&this.step(1,e),this.allowAutoplay=!1,t.cancelable&&t.preventDefault()}},{key:"navForward",value:function(t,e){(this.circular||this.getPage()<this.totalIndicators-1)&&this.step(-1,e),this.allowAutoplay=!1,t.cancelable&&t.preventDefault()}},{key:"onDotClick",value:function(t,e){var i=this.getPage();e>i?this.navForward(t,e):e<i&&this.navBackward(t,e)}},{key:"onTransitionEnd",value:function(t){this.itemsContainer&&"transform"===t.propertyName&&(i.DomHandler.addClass(this.itemsContainer,"p-items-hidden"),this.itemsContainer.style.transition="",0!==this.state.page&&this.state.page!==this.totalIndicators-1||!this.isCircular()||this.changePosition(this.state.totalShiftedItems))}},{key:"onTouchStart",value:function(t){var e=t.changedTouches[0];this.startPos={x:e.pageX,y:e.pageY}}},{key:"onTouchMove",value:function(t){t.cancelable&&t.preventDefault()}},{key:"onTouchEnd",value:function(t){var e=t.changedTouches[0];this.isVertical()?this.changePageOnTouch(t,e.pageY-this.startPos.y):this.changePageOnTouch(t,e.pageX-this.startPos.x)}},{key:"changePageOnTouch",value:function(t,e){Math.abs(e)>this.swipeThreshold&&(e<0?this.navForward(t):this.navBackward(t))}},{key:"bindDocumentListeners",value:function(){var t=this;this.documentResizeListener||(this.documentResizeListener=function(){t.calculatePosition()},window.addEventListener("resize",this.documentResizeListener))}},{key:"unbindDocumentListeners",value:function(){this.documentResizeListener&&(window.removeEventListener("resize",this.documentResizeListener),this.documentResizeListener=null)}},{key:"isVertical",value:function(){return"vertical"===this.props.orientation}},{key:"isCircular",value:function(){return this.circular&&this.props.value.length>=this.state.numVisible}},{key:"getPage",value:function(){return this.props.onPageChange?this.props.page:this.state.page}},{key:"getTotalIndicators",value:function(){return this.props.value?Math.ceil((this.props.value.length-this.state.numVisible)/this.state.numScroll)+1:0}},{key:"isAutoplay",value:function(){return this.props.autoplayInterval&&this.allowAutoplay}},{key:"startAutoplay",value:function(){var t=this;this.interval=setInterval((function(){t.step(-1,t.state.page===t.totalIndicators-1?0:t.state.page+1)}),this.props.autoplayInterval)}},{key:"stopAutoplay",value:function(){this.interval&&clearInterval(this.interval)}},{key:"createStyle",value:function(){this.carouselStyle||(this.carouselStyle=i.DomHandler.createInlineStyle(o.default.nonce));var t,e="\n .p-carousel[".concat(this.attributeSelector,"] .p-carousel-item {\n flex: 1 0 ").concat(100/this.state.numVisible,"%\n }\n ");if(this.props.responsiveOptions){this.responsiveOptions=u(t=this.props.responsiveOptions)||c(t)||p(t)||h(),this.responsiveOptions.sort((function(t,e){var i=t.breakpoint,n=e.breakpoint;return-1*(null==i&&null!=n?-1:null!=i&&null==n?1:null==i&&null==n?0:"string"==typeof i&&"string"==typeof n?i.localeCompare(n,void 0,{numeric:!0}):i<n?-1:i>n?1:0)}));for(var n=0;n<this.responsiveOptions.length;n++){var s=this.responsiveOptions[n];e+="\n @media screen and (max-width: ".concat(s.breakpoint,") {\n .p-carousel[").concat(this.attributeSelector,"] .p-carousel-item {\n flex: 1 0 ").concat(100/s.numVisible,"%\n }\n }\n ")}}this.carouselStyle.innerHTML=e}},{key:"changePosition",value:function(t){this.itemsContainer&&(this.itemsContainer.style.transform=this.isVertical()?"translate3d(0, ".concat(t*(100/this.state.numVisible),"%, 0)"):"translate3d(".concat(t*(100/this.state.numVisible),"%, 0, 0)"))}},{key:"componentDidMount",value:function(){this.container&&this.container.setAttribute(this.attributeSelector,""),this.createStyle(),this.calculatePosition(),this.changePosition(this.state.totalShiftedItems),this.props.responsiveOptions&&this.bindDocumentListeners()}},{key:"componentDidUpdate",value:function(t,e){var i=this.isCircular(),n=!1,s=this.state.totalShiftedItems;if(this.props.autoplayInterval&&this.stopAutoplay(),e.numScroll!==this.state.numScroll||e.numVisible!==this.state.numVisible||this.props.value&&t.value&&t.value.length!==this.props.value.length){this.remainingItems=(this.props.value.length-this.state.numVisible)%this.state.numScroll;var a=this.getPage();0!==this.totalIndicators&&a>=this.totalIndicators&&(a=this.totalIndicators-1,this.props.onPageChange?this.props.onPageChange({page:a}):this.setState({page:a}),n=!0),s=a*this.state.numScroll*-1,i&&(s-=this.state.numVisible),a===this.totalIndicators-1&&this.remainingItems>0?(s+=-1*this.remainingItems+this.state.numScroll,this.isRemainingItemsAdded=!0):this.isRemainingItemsAdded=!1,s!==this.state.totalShiftedItems&&(this.setState({totalShiftedItems:s}),n=!0),this.changePosition(s)}i&&(0===this.state.page?s=-1*this.state.numVisible:0===s&&(s=-1*this.props.value.length,this.remainingItems>0&&(this.isRemainingItemsAdded=!0)),s!==this.state.totalShiftedItems&&(this.setState({totalShiftedItems:s}),n=!0)),t.page!==this.props.page&&(this.props.page>t.page&&this.props.page<=this.totalIndicators-1?this.step(-1,this.props.page):this.props.page<t.page&&this.step(1,this.props.page)),!n&&this.isAutoplay()&&this.startAutoplay()}},{key:"componentWillUnmount",value:function(){this.props.responsiveOptions&&this.unbindDocumentListeners(),this.props.autoplayInterval&&this.stopAutoplay()}},{key:"renderItems",value:function(){var t=this;if(this.props.value&&this.props.value.length){var e=this.isCircular(),i=null,n=null;if(e){var s=null;i=(s=this.props.value.slice(-1*this.state.numVisible)).map((function(e,i){return r.default.createElement(V,{key:i+"_scloned",className:"p-carousel-item-cloned",template:t.props.itemTemplate,item:e,active:-1*t.state.totalShiftedItems===t.props.value.length+t.state.numVisible,start:0===i,end:i===s.length-1})})),n=(s=this.props.value.slice(0,this.state.numVisible)).map((function(e,i){return r.default.createElement(V,{key:i+"_fcloned",className:"p-carousel-item-cloned",template:t.props.itemTemplate,item:e,active:0===t.state.totalShiftedItems,start:0===i,end:i===s.length-1})}))}var a=this.props.value.map((function(i,n){var s=e?-1*(t.state.totalShiftedItems+t.state.numVisible):-1*t.state.totalShiftedItems,a=s+t.state.numVisible-1;return r.default.createElement(V,{key:n,template:t.props.itemTemplate,item:i,active:s<=n&&a>=n,start:s===n,end:a===n})}));return r.default.createElement(r.default.Fragment,null,i,a,n)}}},{key:"renderHeader",value:function(){return this.props.header?r.default.createElement("div",{className:"p-carousel-header"},this.props.header):null}},{key:"renderFooter",value:function(){return this.props.footer?r.default.createElement("div",{className:"p-carousel-footer"},this.props.footer):null}},{key:"renderContent",value:function(){var t=this,e=this.renderItems(),n=this.isVertical()?this.props.verticalViewPortHeight:"auto",s=this.renderBackwardNavigator(),a=this.renderForwardNavigator(),o=i.classNames("p-carousel-container",this.props.containerClassName);return r.default.createElement("div",{className:o},s,r.default.createElement("div",{className:"p-carousel-items-content",style:{height:n},onTouchStart:this.onTouchStart,onTouchMove:this.onTouchMove,onTouchEnd:this.onTouchEnd},r.default.createElement("div",{ref:function(e){return t.itemsContainer=e},className:"p-carousel-items-container",onTransitionEnd:this.onTransitionEnd},e)),a)}},{key:"renderBackwardNavigator",value:function(){var t=(!this.circular||this.props.value&&this.props.value.length<this.state.numVisible)&&0===this.getPage(),e=i.classNames("p-carousel-prev p-link",{"p-disabled":t}),s=i.classNames("p-carousel-prev-icon pi",{"pi-chevron-left":!this.isVertical(),"pi-chevron-up":this.isVertical()});return r.default.createElement("button",{type:"button",className:e,onClick:this.navBackward,disabled:t},r.default.createElement("span",{className:s}),r.default.createElement(n.Ripple,null))}},{key:"renderForwardNavigator",value:function(){var t=(!this.circular||this.props.value&&this.props.value.length<this.state.numVisible)&&(this.getPage()===this.totalIndicators-1||0===this.totalIndicators),e=i.classNames("p-carousel-next p-link",{"p-disabled":t}),s=i.classNames("p-carousel-next-icon pi",{"pi-chevron-right":!this.isVertical(),"pi-chevron-down":this.isVertical()});return r.default.createElement("button",{type:"button",className:e,onClick:this.navForward,disabled:t},r.default.createElement("span",{className:s}),r.default.createElement(n.Ripple,null))}},{key:"renderIndicator",value:function(t){var e=this,s=this.getPage()===t,a=i.classNames("p-carousel-indicator",{"p-highlight":s});return r.default.createElement("li",{className:a,key:"p-carousel-indicator-"+t},r.default.createElement("button",{type:"button",className:"p-link",onClick:function(i){return e.onDotClick(i,t)}},r.default.createElement(n.Ripple,null)))}},{key:"renderIndicators",value:function(){for(var t=i.classNames("p-carousel-indicators p-reset",this.props.indicatorsContentClassName),e=[],n=0;n<this.totalIndicators;n++)e.push(this.renderIndicator(n));return r.default.createElement("ul",{className:t},e)}},{key:"render",value:function(){var t=this,e=i.classNames("p-carousel p-component",{"p-carousel-vertical":this.isVertical(),"p-carousel-horizontal":!this.isVertical()},this.props.className),n=i.classNames("p-carousel-content",this.props.contentClassName);this.totalIndicators=this.getTotalIndicators();var s=this.renderContent(),a=this.renderIndicators(),o=this.renderHeader(),l=this.renderFooter();return r.default.createElement("div",{ref:function(e){return t.container=e},id:this.props.id,className:e,style:this.props.style},o,r.default.createElement("div",{className:n},s,a),l)}}]),s}(e.Component);return k(N,"defaultProps",{id:null,value:null,page:0,header:null,footer:null,style:null,className:null,itemTemplate:null,circular:!1,autoplayInterval:0,numVisible:1,numScroll:1,responsiveOptions:null,orientation:"horizontal",verticalViewPortHeight:"300px",contentClassName:null,containerClassName:null,indicatorsContentClassName:null,onPageChange:null}),t.Carousel=N,Object.defineProperty(t,"__esModule",{value:!0}),t}({},React,primereact.utils,primereact.ripple,primereact.api);
|