Repository navigation
Expand file tree
/
Copy pathamp-carousel-0.1.js
More file actions
62 lines (62 loc) · 31.8 KB
/
Copy pathamp-carousel-0.1.js
File metadata and controls
62 lines (62 loc) · 31.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
(window.AMP = window.AMP || []).push({n:"amp-carousel", f:(function(AMP) {var process={env:{NODE_ENV:"production"}};var e;function l(a,b){function c(){}c.prototype=b.prototype;a.prototype=new c;a.prototype.constructor=a;for(var d in b)if(Object.defineProperties){var f=Object.getOwnPropertyDescriptor(b,d);f&&Object.defineProperty(a,d,f)}else a[d]=b[d]};(new Date).getTime();var m=self.log=self.log||{user:null,dev:null};function n(){if(m.dev)return m.dev;throw Error("failed to call initLogConstructor");};function p(a,b){a=a.__AMP_TOP||a;var c=a.services&&a.services[b]&&a.services[b].obj;return c};function q(a){return p(a,"timer")};var r;
function aa(a,b){var c=r||(r=Object.create(null));if(b in c)a=c[b];else{var d=b,f;if(a._experimentCookie)f=a._experimentCookie;else{c:{d:{try{f=a.document.cookie;break d}catch(L){}f=void 0}if(f){f=f.split(";");for(var g=0;g<f.length;g++){var h=f[g].trim(),k=h.indexOf("=");if(-1!=k&&"AMP_EXP"==decodeURIComponent(h.substring(0,k).trim())){f=decodeURIComponent(h.substring(k+1).trim());break c}}}f=null}f=a._experimentCookie=f?f.split(/\s*,\s*/g):[]}a=-1!=f.indexOf(d)?!0:a.AMP_CONFIG&&a.AMP_CONFIG.hasOwnProperty(d)?Math.random()<
a.AMP_CONFIG[d]:!1;a=c[b]=a}return a};function t(){this.S=[]}e=t.prototype;e.add=function(a){var b=this;this.S.push(a);return function(){b.remove(a)}};e.remove=function(a){a=this.S.indexOf(a);-1<a&&this.S.splice(a,1)};e.removeAll=function(){this.S.length=0};e.fire=function(a){for(var b=this.S,c=0;c<b.length;c++)(0,b[c])(a)};e.getHandlerCount=function(){return this.S.length};var u,ba="Webkit webkit Moz moz ms O o".split(" ");function ca(a,b){var c=void 0;u||(u=Object.create(null));var d=u[b];if(!d||c){d=b;if(void 0===a[b]){var f=b.charAt(0).toUpperCase()+b.slice(1);a:{for(var g=0;g<ba.length;g++){var h=ba[g]+f;if(void 0!==a[h]){f=h;break a}}f=""}var k=f;void 0!==a[k]&&(d=k)}c||(u[b]=d)}return d}function v(a,b,c){var d;(b=ca(a.style,b))&&(a.style[b]=d?c+d:c)}function da(a){var b=ca(a.style,"scrollSnapType");return b?a.style[b]:void 0}
function w(a,b){for(var c in b)v(a,c,b[c])}function x(a){return"string"==typeof a?"translateX("+a+")":"translateX("+(a+"px")+")"};function ea(a){return"fixed"==a||"fixed-height"==a||"responsive"==a||"fill"==a||"flex-item"==a};function y(a,b,c){var d=this;this.ab=q(a);this.fb=b;this.cb=c||0;this.Z=-1;this.wa=0;this.K=!1;this.bb=function(){return d.la()}}y.prototype.isPending=function(){return-1!=this.Z};y.prototype.schedule=function(a){var b=a||this.cb;this.K&&10>b&&(b=10);var c=Date.now()+b;return!this.isPending()||-10>c-this.wa?(this.cancel(),this.wa=c,this.Z=this.ab.delay(this.bb,b),!0):!1};y.prototype.la=function(){this.Z=-1;this.wa=0;this.K=!0;this.fb();this.K=!1};
y.prototype.cancel=function(){this.isPending()&&(this.ab.cancel(this.Z),this.Z=-1)};function z(a,b,c,d){var f=new fa(0,0,a,b,c,d,1,1);return f.solveYValueFromXValue.bind(f)}function fa(a,b,c,d,f,g,h,k){this.x0=a;this.y0=b;this.x1=c;this.y1=d;this.x2=f;this.y2=g;this.x3=h;this.y3=k}e=fa.prototype;e.solveYValueFromXValue=function(a){return this.getPointY(this.solvePositionFromXValue(a))};
e.solvePositionFromXValue=function(a){var b=1E-6,c=(a-this.x0)/(this.x3-this.x0);if(0>=c)return 0;if(1<=c)return 1;for(var d=0,f=1,g=0,h=0;8>h;h++){var g=this.getPointX(c),k=(this.getPointX(c+b)-g)/b;if(Math.abs(g-a)<b)return c;if(Math.abs(k)<b)break;else g<a?d=c:f=c,c-=(g-a)/k}for(h=0;Math.abs(g-a)>b&&8>h;h++)g<a?(d=c,c=(c+f)/2):(f=c,c=(c+d)/2),g=this.getPointX(c);return c};
e.getPointX=function(a){if(0==a)return this.x0;if(1==a)return this.x3;var b=this.lerp(this.x0,this.x1,a),c=this.lerp(this.x1,this.x2,a),d=this.lerp(this.x2,this.x3,a),b=this.lerp(b,c,a),c=this.lerp(c,d,a);return this.lerp(b,c,a)};e.getPointY=function(a){if(0==a)return this.y0;if(1==a)return this.y3;var b=this.lerp(this.y0,this.y1,a),c=this.lerp(this.y1,this.y2,a),d=this.lerp(this.y2,this.y3,a),b=this.lerp(b,c,a),c=this.lerp(c,d,a);return this.lerp(b,c,a)};e.lerp=function(a,b,c){return a+c*(b-a)};
var ga=z(.25,.1,.25,1),ha=z(.42,0,1,1),ia=z(0,0,.58,1),ja=z(.42,0,.58,1),ka={linear:function(a){return a},ease:ga,"ease-in":ha,"ease-out":ia,"ease-in-out":ja};function la(a){if(!a)return null;if("string"==typeof a){if(-1!=a.indexOf("cubic-bezier")){var b=a.match(/cubic-bezier\((.+)\)/);if(b){var c=b[1].split(",").map(parseFloat);if(4==c.length){for(var d=0;4>d;d++)if(isNaN(c[d]))return null;return z(c[0],c[1],c[2],c[3])}}return null}return ka[a]}return a};function ma(){}function A(a,b){this.M=a;this.D=b||p(self,"vsync");this.Sa=null;this.l=[]}function B(a,b,c,d){return(new A(a)).setCurve(d).add(0,b,1).start(c)}A.prototype.setCurve=function(a){a&&(this.Sa=la(a));return this};A.prototype.add=function(a,b,c,d){this.l.push({delay:a,func:b,duration:c,curve:la(d)});return this};A.prototype.start=function(a){var b=new oa(this.D,this.M,this.l,this.Sa,a);b.Ma();return b};
function oa(a,b,c,d,f){var g=this;this.D=a;this.M=b;this.l=[];for(b=0;b<c.length;b++){var h=c[b];this.l.push({delay:h.delay,func:h.func,duration:h.duration,curve:h.curve||d,started:!1,completed:!1})}this.eb=f;this.rb=this.qb=this.R=0;this.K=!1;this.Za={};this.Y=new Promise(function(a,b){g.Ha=a;g.Ga=b});this.$a=this.D.createAnimTask(this.M,{mutate:this.mb.bind(this)})}e=oa.prototype;e.then=function(a,b){return a||b?this.Y.then(a,b):this.Y};e.thenAlways=function(a){a=a||ma;return this.then(a,a)};
e.halt=function(a){C(this,!1,a||0)};e.Ma=function(){this.R=Date.now();this.K=!0;this.D.canAnimate(this.M)?this.$a(this.Za):(n().warn("Animation","cannot animate"),C(this,!1,0))};function C(a,b,c){if(a.K){a.K=!1;if(0!=c){1<a.l.length&&a.l.sort(function(a,b){return a.delay+a.duration-(b.delay+b.duration)});try{if(0<c)for(var d=0;d<a.l.length;d++)a.l[d].func(1,!0);else for(d=a.l.length-1;0<=d;d--)a.l[d].func(0,!1)}catch(f){n().error("Animation","completion failed: "+f,f),b=!1}}b?a.Ha():a.Ga()}}
e.mb=function(){if(this.K){for(var a=Date.now(),b=Math.min((a-this.R)/this.eb,1),c=0;c<this.l.length;c++){var d=this.l[c];!d.started&&b>=d.delay&&(d.started=!0)}for(c=0;c<this.l.length;c++)if(d=this.l[c],d.started&&!d.completed)a:{var f,g;if(0<d.duration){if(g=f=Math.min((b-d.delay)/d.duration,1),d.curve&&1!=g)try{g=d.curve(f)}catch(h){n().error("Animation","step curve failed: "+h,h);C(this,!1,0);break a}}else g=f=1;1==f&&(d.completed=!0);try{d.func(g,d.completed)}catch(h){n().error("Animation","step mutate failed: "+
h,h),C(this,!1,0)}}1==b?C(this,!0,0):this.D.canAnimate(this.M)?this.$a(this.Za):(n().warn("Animation","cancel animation"),C(this,!1,0))}};function pa(){return null}function qa(a){return function(b,c){for(var d=0;d<a.length;d++){var f=a[d];f(b,c)}}}function D(a,b){return function(c,d){for(var f in b)v(a,f,b[f](c,d))}}function E(a,b){return function(c){return a+(b-a)*c}}function ra(a){return function(b){b=a(b);return"string"==typeof b?"translateX("+b+")":"translateX("+b+"px)"}}function sa(){var a=E(1,.98);return function(b){return"scale("+a(b)+")"}};function ta(a,b,c,d){this.type=a;this.data=b;this.time=c;this.event=d}
function ua(a,b){this.I=a;this.i=[];this.fa=[];this.A=[];this.h=[];this.o=null;this.kb=b;this.pa=!1;this.la=new y(a.ownerDocument.defaultView,this.Ta.bind(this));this.Ya=new t;this.Ba=Object.create(null);this.Ra=this.jb.bind(this);this.Pa=this.hb.bind(this);this.Qa=this.ib.bind(this);this.Oa=this.gb.bind(this);this.I.addEventListener("touchstart",this.Ra);this.I.addEventListener("touchend",this.Pa);this.I.addEventListener("touchmove",this.Qa);this.I.addEventListener("touchcancel",this.Oa);this.Ca=
!1}function va(a){var b=a.__AMP_Gestures;b||(b=new ua(a,!1),a.__AMP_Gestures=b);return b}e=ua.prototype;e.cleanup=function(){this.I.removeEventListener("touchstart",this.Ra);this.I.removeEventListener("touchend",this.Pa);this.I.removeEventListener("touchmove",this.Qa);this.I.removeEventListener("touchcancel",this.Oa);this.la.cancel()};e.onGesture=function(a,b){var c=new a(this),d=c.getType(),f=this.Ba[d];f||(this.i.push(c),f=new t,this.Ba[d]=f);return f.add(b)};e.onPointerDown=function(a){return this.Ya.add(a)};
e.jb=function(a){var b=Date.now();this.pa=!1;this.Ya.fire(a);for(var c=0;c<this.i.length;c++)if(!this.A[c]&&(this.h[c]&&this.h[c]<b&&F(this,c),this.i[c].onTouchStart(a))){var d=c;this.fa[d]=!0;this.h[d]=0}G(this,a)};e.ib=function(a){for(var b=Date.now(),c=0;c<this.i.length;c++)this.fa[c]&&(this.h[c]&&this.h[c]<b?F(this,c):this.i[c].onTouchMove(a)||F(this,c));G(this,a)};
e.hb=function(a){for(var b=Date.now(),c=0;c<this.i.length;c++)this.fa[c]&&(this.h[c]&&this.h[c]<b?F(this,c):(this.i[c].onTouchEnd(a),(!this.h[c]||this.h[c]<b)&&F(this,c)));G(this,a)};e.gb=function(a){for(var b=0;b<this.i.length;b++){var c=b;this.A[c]=0;F(this,c)}G(this,a)};function G(a,b){var c=!!a.o||a.pa;a.pa=!1;if(!c)for(var d=Date.now(),f=0;f<a.i.length;f++)if(a.A[f]||a.h[f]&&a.h[f]>=d){c=!0;break}c&&(b.stopPropagation(),a.kb||b.preventDefault());a.Ca&&(a.Ca=!1,a.Ta())}
e.Ta=function(){for(var a=Date.now(),b=-1,c=0;c<this.i.length;c++)if(!this.A[c])this.h[c]&&this.h[c]<a&&F(this,c);else if(-1==b||this.A[c]>this.A[b])b=c;if(-1!=b){for(var d=0,c=0;c<this.i.length;c++)!this.A[c]&&this.fa[c]&&(d=Math.max(d,this.h[c]-a));if(2>d){for(var a=b,c=this.i[a],f=0;f<this.i.length;f++)if(f!=a){var g=f;this.A[g]=0;F(this,g)}this.A[a]=0;this.h[a]=0;this.o=c;c.acceptStart()}else this.la.schedule(d)}};function F(a,b){a.fa[b]=!1;a.h[b]=0;a.A[b]||a.i[b].acceptCancel()}
function H(a,b){this.pb=a;this.ka=b}e=H.prototype;e.getType=function(){return this.pb};e.signalReady=function(a){var b=this.ka;if(b.o)this.acceptCancel();else{for(var c=Date.now(),d=0;d<b.i.length;d++)b.i[d]==this&&(b.A[d]=c+a,b.h[d]=0);b.Ca=!0}};e.signalPending=function(a){var b=this.ka;if(b.o)this.acceptCancel();else for(var c=Date.now(),d=0;d<b.i.length;d++)b.i[d]==this&&(b.h[d]=c+a)};e.signalEnd=function(){var a=this.ka;a.o==this&&(a.o=null,a.pa=!0)};
e.signalEmit=function(a,b){var c=this.ka.Ba[this.getType()];c&&c.fire(new ta(this.getType(),a,Date.now(),b))};e.acceptStart=function(){};e.acceptCancel=function(){};e.onTouchStart=function(){return!1};e.onTouchMove=function(){return!1};e.onTouchEnd=function(){};function wa(){}var xa=Math.round(-16.67/Math.log(.95));function ya(a,b,c){1>b&&(b=1);var d=a/b,f=.5+Math.min(b/33.34,.5);return d*f+c*(1-f)}function za(a,b,c,d){var f=0,g=0;return(new Aa(a,b,f,c,g,d,void 0)).Ma()}function Aa(a,b,c,d,f,g,h){var k=this;this.D=h||p(self,"vsync");this.M=a;this.qa=g;this.v=b;this.w=c;this.ua=d;this.va=f;this.C=this.B=0;this.O=this.R=Date.now();this.Y=new Promise(function(a,b){k.Ha=a;k.Ga=b});this.U=!1}e=Aa.prototype;
e.Ma=function(){this.U=!0;if(.02>=Math.abs(this.ua)&&.02>=Math.abs(this.va))this.qa(this.v,this.w),this.sa(!0);else{this.B=this.ua;this.C=this.va;var a=this.lb.bind(this),b=this.sa.bind(this,!0);this.D.runAnimMutateSeries(this.M,a,5E3).then(b,b)}return this};e.halt=function(){this.U&&this.sa(!1)};e.then=function(a,b){return a||b?this.Y.then(a,b):this.Y};e.thenAlways=function(a){a=a||wa;return this.then(a,a)};
e.lb=function(a,b){if(!this.U)return!1;this.O=Date.now();this.v+=b*this.B;this.w+=b*this.C;if(!this.qa(this.v,this.w))return!1;var c=Math.exp(-a/xa);this.B=this.ua*c;this.C=this.va*c;return.02<Math.abs(this.B)||.02<Math.abs(this.C)};e.sa=function(a){this.U&&(this.U=!1,this.O=Date.now(),this.qa(this.v,this.w),a?this.Ha():this.Ga())};function I(a,b,c,d){H.call(this,a,b);this.ja=c;this.oa=d;this.o=!1;this.C=this.B=this.Da=this.O=this.R=this.Fa=this.Ea=this.w=this.v=this.da=this.ca=0}l(I,H);e=I.prototype;e.onTouchStart=function(a){a=a.touches;if(!a||1!=a.length)return!1;this.R=Date.now();this.ca=a[0].clientX;this.da=a[0].clientY;return!0};
e.onTouchMove=function(a){var b=a.changedTouches||a.touches;if(b&&1==b.length){var c=b[0].clientX,b=b[0].clientY;this.v=c;this.w=b;if(this.o)J(this,!1,!1,a);else if(a=Math.abs(c-this.ca),c=Math.abs(b-this.da),this.ja&&this.oa)(8<=a||8<=c)&&this.signalReady(-10);else if(this.ja)if(8<=a&&a>c)this.signalReady(-10);else{if(8<=c)return!1}else if(this.oa)if(8<=c&&c>a)this.signalReady(-10);else{if(8<=a)return!1}else return!1}return!0};e.onTouchEnd=function(a){this.o&&(this.o=!1,J(this,!1,!0,a),this.signalEnd())};
e.acceptStart=function(){this.o=!0;this.Ea=this.ca;this.Fa=this.da;this.Da=this.R;this.ca=this.v;this.da=this.w;J(this,!0,!1,null)};e.acceptCancel=function(){this.o=!1};function J(a,b,c,d){a.O=Date.now();var f=a.O-a.Da;if(!c&&4<f||c&&16<f)a.B=ya(a.v-a.Ea,f,a.B),a.C=ya(a.w-a.Fa,f,a.C),a.B=1E-4<Math.abs(a.B)?a.B:0,a.C=1E-4<Math.abs(a.C)?a.C:0,a.Ea=a.v,a.Fa=a.w,a.Da=a.O;a.signalEmit({first:b,last:c,time:a.O,deltaX:a.ja?a.v-a.ca:0,deltaY:a.oa?a.w-a.da:0,velocityX:a.ja?a.B:0,velocityY:a.oa?a.C:0},d)}
function K(a){I.call(this,"swipe-x",a,!0,!1)}l(K,I);function M(a){AMP.BaseElement.call(this,a);this.F=this.G=null;this.La=!1}l(M,AMP.BaseElement);e=M.prototype;e.buildCallback=function(){(this.La=this.element.hasAttribute("controls"))&&this.element.classList.add("-amp-carousel-has-controls");this.buildCarousel();this.buildButtons();this.setupGestures();this.setControlsState()};e.viewportCallback=function(a){this.onViewportCallback(a);a&&this.hintControls()};e.onViewportCallback=function(){};
e.buildButtons=function(){var a=this;this.G=this.element.ownerDocument.createElement("div");this.G.classList.add("amp-carousel-button");this.G.classList.add("amp-carousel-button-prev");this.G.setAttribute("role","button");this.G.setAttribute("aria-label","previous");this.G.onclick=function(){a.interactionPrev()};this.element.appendChild(this.G);this.F=this.element.ownerDocument.createElement("div");this.F.classList.add("amp-carousel-button");this.F.classList.add("amp-carousel-button-next");this.F.setAttribute("role",
"button");this.F.setAttribute("aria-label","next");this.F.onclick=function(){a.interactionNext()};this.element.appendChild(this.F)};e.prerenderAllowed=function(){return!0};e.isRelayoutNeeded=function(){return!0};e.buildCarousel=function(){};e.setupGestures=function(){};e.go=function(a,b,c){c=void 0===c?!1:c;this.goCallback(a,b,c)};e.goCallback=function(){};
e.setControlsState=function(){this.G.classList.toggle("amp-disabled",!this.hasPrev());this.G.setAttribute("aria-disabled",!this.hasPrev());this.F.classList.toggle("amp-disabled",!this.hasNext());this.F.setAttribute("aria-disabled",!this.hasNext())};
e.hintControls=function(){var a=this;!this.La&&this.isInViewport()&&this.getVsync().mutate(function(){a.element.classList.add("-amp-carousel-button-start-hint");q(a.win).delay(function(){a.deferMutate(function(){return a.element.classList.remove("-amp-carousel-button-start-hint")})},1E3)})};e.unlayoutCallback=function(){return!0};e.hasPrev=function(){};e.hasNext=function(){};e.interactionNext=function(){this.F.classList.contains("amp-disabled")||this.go(1,!0,!1)};
e.interactionPrev=function(){this.G.classList.contains("amp-disabled")||this.go(-1,!0,!1)};function N(a){M.call(this,a);this.ha=null;this.Va=this.ia=!1;this.Na=5E3;this.Ka=this.shouldLoop=!1}l(N,M);e=N.prototype;
e.buildCarousel=function(){this.ia=this.element.hasAttribute("loop");this.Va=this.element.hasAttribute("autoplay");this.buildSlides();this.shouldLoop=this.ia&&this.isLoopingEligible();if(this.Ka=this.Va&&this.isLoopingEligible()){var a=Number(this.element.getAttribute("delay"));0<a&&(this.Na=Math.max(1E3,a));this.ia||(this.element.setAttribute("loop",""),this.shouldLoop=this.ia=!0)}};e.buildSlides=function(){};e.onViewportCallback=function(a){this.updateViewportState(a);a?Ba(this):this.clearAutoplay()};
e.goCallback=function(a,b,c){this.moveSlide(a,b);c?Ba(this):this.clearAutoplay()};e.moveSlide=function(){};e.updateViewportState=function(){};e.isLoopingEligible=function(){return!1};function Ba(a){a.Ka&&(a.clearAutoplay(),a.ha=q(a.win).delay(a.go.bind(a,1,!0,!0),a.Na))}e.clearAutoplay=function(){null!==this.ha&&(q(this.win).cancel(this.ha),this.ha=null)};function O(a){N.call(this,a);this.b=null;this.f=0;this.na=null}l(O,N);e=O.prototype;e.isLayoutSupported=function(a){return ea(a)};e.buildSlides=function(){var a=this;this.b=this.getRealChildren();this.b.forEach(function(b,d){a.setAsOwner(b);b.style.visibility=0<d?"hidden":"visible";a.applyFillContent(b)});var b;if(m.user)b=m.user;else throw Error("failed to call initLogConstructor");b.assert(1<=this.b.length,"amp-carousel with type=slides should have at least 1 slide.")};
e.isLoopingEligible=function(){return 2<this.b.length};e.layoutCallback=function(){var a=P(this);a&&(this.scheduleLayout(a),this.J(1));return Promise.resolve()};e.updateViewportState=function(a){var b=P(this);b&&this.updateInViewport(b,a)};e.moveSlide=function(a,b){var c=this,d=Ca(this,a);if(0<=d&&d!=this.f){var f=this.b[d],g=P(this);this.f=d;Q(this,f,a);b?(g.style.zIndex=0,B(this.element,R(this,g,f,a),200,"ease-out").thenAlways(function(){c.m(g,f);c.J(a)})):this.m(g,f)}};
function Q(a,b,c){var d=a.element.offsetWidth;w(b,{transform:x(c*d),zIndex:1,visibility:"visible"});a.scheduleLayout(b)}function S(a,b){var c=a.b[b];b==a.f?w(c,{zIndex:0,transform:"",opacity:1}):w(c,{visibility:"hidden",zIndex:0,transform:"",opacity:1})}function R(a,b,c,d){return qa([D(c,{transform:ra(E(d*a.element.offsetWidth,0)),opacity:E(.8,1)}),D(b,{transform:sa(),opacity:E(1,.4)})])}
e.m=function(a,b){w(a,{visibility:"hidden",zIndex:0,transform:"",opacity:1});w(b,{visibility:"visible",zIndex:0,transform:"",opacity:1});this.updateInViewport(a,!1);this.updateInViewport(b,!0);this.scheduleLayout(b);this.scheduleResume(b);this.setControlsState();this.schedulePause(a)};function P(a){return a.b[a.f]}function Ca(a,b){b=a.f+b;0>b?b=a.b.length+b:b>=a.b.length&&(b%=a.b.length);return b}e.J=function(a){var b=Ca(this,a);b!=this.f&&this.schedulePreload(this.b[b])};
e.setupGestures=function(){var a=this,b=va(this.element);b.onGesture(K,function(b){b.data.first&&a.za(b.data);a.Aa(b.data);b.data.last&&a.ya(b.data)})};
e.za=function(){this.clearAutoplay();var a=P(this),b=this.element.offsetWidth,c=0,d=0,f=pa,g=pa,h=this.b.length,k=(this.f+-1+h)%h,h=this.b.length,h=(this.f+1+h)%h;if(this.shouldLoop||0<=this.f-1){var L=this.b[k];Q(this,L,-1);f=R(this,a,L,-1);c=-1}if(this.shouldLoop||this.f+1<this.b.length){var na=this.b[h];Q(this,na,1);g=R(this,a,na,1);d=1}this.na={containerWidth:b,prevTr:f,nextTr:g,prevIndex:k,nextIndex:h,min:c,max:d,pos:0,currentIndex:this.f}};
e.Aa=function(a){var b=this.na;if(b&&b.currentIndex==this.f){var c=Math.min(b.max,Math.max(b.min,-a.deltaX/b.containerWidth));b.nextTr(0<c?c:0);b.prevTr(0>c?-c:0);b.pos=c}};
e.ya=function(a){var b=this,c=this.na;if(c&&c.currentIndex==this.f){this.na=null;var d=c.pos;0<=c.pos*-a.velocityX&&(d=c.pos-Math.sign(a.velocityX)*(.2<Math.abs(a.velocityX)?1:0));var d=Math.min(c.max,Math.max(c.min,d)),f=.55<=Math.abs(d)?Math.sign(d):0,g;if(f!=c.pos){var h=E(c.pos,f);g=B(this.element,function(a){a=h(a);c.nextTr(0<a?a:0);c.prevTr(0>a?-a:0);c.pos=a},150,z(.19,.49,.2,1)).thenAlways()}else g=Promise.resolve();return g.then(function(){if(c.currentIndex==b.f){var a=P(b);.5<f?(c.nextTr(1),
b.f=c.nextIndex,b.m(a,P(b)),-1!=c.prevIndex&&c.prevIndex!=b.f&&S(b,c.prevIndex)):(-.5>f?(c.prevTr(1),b.f=c.prevIndex,b.m(a,P(b))):(c.nextTr(0),c.prevTr(0),S(b,b.f),-1!=c.prevIndex&&c.prevIndex!=b.f&&S(b,c.prevIndex)),-1!=c.nextIndex&&c.nextIndex!=b.f&&S(b,c.nextIndex))}})}};e.hasPrev=function(){return this.shouldLoop?!0:0!=this.f};e.hasNext=function(){return this.shouldLoop?!0:this.f<this.b.length-1};function T(a){M.call(this,a);this.a=0;this.c=this.u=null;this.Ua=this.Wa=this.Xa=this.ba=0;this.P=null}l(T,M);e=T.prototype;e.isLayoutSupported=function(a){return"fixed"==a||"fixed-height"==a};
e.buildCarousel=function(){var a=this;this.u=this.getRealChildren();this.c=this.element.ownerDocument.createElement("div");w(this.c,{whiteSpace:"nowrap",position:"absolute",zIndex:1,top:0,left:0,bottom:0});this.element.appendChild(this.c);this.u.forEach(function(b){a.setAsOwner(b);b.style.display="inline-block";b!=a.u[0]&&(b.style.marginLeft="8px");a.c.appendChild(b)})};e.layoutCallback=function(){this.V(this.a);this.J(this.a,1);this.setControlsState();return Promise.resolve()};
e.onViewportCallback=function(){this.ga(this.a,this.a)};e.goCallback=function(a,b){var c=this,d=this.X(this.a,a),f=this.c;if(d!=this.a){var g=this.a;this.a=d;b?B(this.element,D(f,{transform:ra(E(-g,-d))}),200,"ease-out").thenAlways(function(){c.m(g,d)}):this.m(g,d)}};e.m=function(a,b){w(this.c,{transform:x(-b)});this.ga(b,a);this.V(b);this.J(b,Math.sign(b-a));this.setControlsState()};e.X=function(a,b){var c=this.element.offsetWidth,d=this.c.scrollWidth;a+=b*c;return 0>a?0:d>=c&&a>d-c?d-c:a};
e.H=function(a,b){for(var c=this.getLayoutWidth(),d=0;d<this.u.length;d++){var f=this.u[d];f.offsetLeft+f.offsetWidth>=a&&f.offsetLeft<=a+c&&b(f)}};e.V=function(a){var b=this;this.H(a,function(a){b.scheduleLayout(a);b.scheduleResume(a)})};e.J=function(a,b){var c=this,d=this.X(a,b);d!=a&&this.H(d,function(a){c.schedulePreload(a)})};e.ga=function(a,b){var c=this,d=[];this.H(a,function(a){d.push(a);c.updateInViewport(a,!0)});b!=a&&this.H(b,function(a){-1==d.indexOf(a)&&(c.updateInViewport(a,!1),c.schedulePause(a))})};
e.setupGestures=function(){var a=this,b=va(this.element);b.onGesture(K,function(b){b.data.first&&a.za(b.data);a.Aa(b.data);b.data.last&&a.ya(b.data)});b.onPointerDown(function(){a.P&&(a.P.halt(),a.P=null)})};e.za=function(){var a=this.element.offsetWidth,b=this.c.scrollWidth;this.Xa=0;this.Wa=Math.max(b-a,0);this.Ua=Math.min(.4*a,200);this.ba=this.a;this.P=null};e.Aa=function(a){var b=this.c;this.a=U(this,this.ba-a.deltaX,!0);w(b,{transform:x(-this.a)});.05>Math.abs(a.velocityX)&&this.m(this.ba,this.a)};
e.ya=function(a){var b=this,c=this.c;.1<Math.abs(a.velocityX)?(this.P=za(this.element,this.a,-a.velocityX,function(a){a=.5*(U(b,a,!0)+U(b,a,!1));if(1>=Math.abs(a-b.a))return!1;b.a=a;w(c,{transform:x(-b.a)});return!0}),a=this.P.thenAlways()):a=Promise.resolve();return a.then(function(){var a=U(b,b.a,!1);if(!(1>Math.abs(a-b.a))){var f=E(b.a,a);return B(b.element,function(a){b.a=f(a);w(c,{transform:x(-b.a)})},250,z(.4,0,.2,1.4)).thenAlways()}}).then(function(){b.m(b.ba,b.a);b.ba=b.a;b.P=null})};
function U(a,b,c){var d=c?a.Ua:0;return Math.min(a.Wa+d,Math.max(a.Xa-d,b))}e.hasPrev=function(){return 0!=this.a};e.hasNext=function(){var a=this.getLayoutWidth(),b=Math.max(this.c.scrollWidth-a,0);return this.a!=b};function V(a){N.call(this,a);this.D=null;this.N=!1;this.b=[];this.s=0;this.g=null;this.T=[];this.aa=!1;this.ea=this.$=null;this.ta=!1;this.W=0;this.j=null;this.ma=this.L=0}l(V,N);e=V.prototype;e.isLayoutSupported=function(a){return ea(a)};
e.buildSlides=function(){var a=this;this.D=this.getVsync();this.N=void 0!=da(this.element);this.element.classList.add("-amp-slidescroll");this.b=this.getRealChildren();this.s=this.b.length;this.g=this.win.document.createElement("div");this.g.classList.add("-amp-slides-container");if(this.N){var b=this.win.document.createElement("div");b.classList.add("-amp-carousel-start-marker");this.g.appendChild(b);b=this.win.document.createElement("div");b.classList.add("-amp-carousel-end-marker");this.g.appendChild(b)}this.b.forEach(function(b){a.setAsOwner(b);
var d=a.win.document.createElement("div");b.classList.add("amp-carousel-slide");d.appendChild(b);d.classList.add("-amp-slide-item");a.g.appendChild(d);a.T.push(d)});this.element.appendChild(this.g);this.ra();this.g.addEventListener("scroll",this.Ia.bind(this));this.g.addEventListener("touchmove",this.ob.bind(this));this.N&&this.g.addEventListener("touchend",this.nb.bind(this))};e.isLoopingEligible=function(){return 2<this.s};e.ob=function(){this.clearAutoplay();this.N&&(this.ta=!0,this.ea&&q(this.win).cancel(this.ea))};
e.nb=function(){var a=this;this.ta&&(this.$&&q(this.win).cancel(this.$),this.ea=q(this.win).delay(function(){var b=a.g.scrollLeft;a.aa||(W(a,b),a.ea=null)},120));this.ta=!1};e.onLayoutMeasure=function(){this.L=this.getLayoutWidth();null!==this.j&&(this.g.scrollLeft=Da(this,this.j));this.ma=this.g.scrollLeft};e.layoutCallback=function(){null===this.j&&X(this,0);return Promise.resolve()};e.updateViewportState=function(a){null!==this.j&&this.updateInViewport(this.b[this.j],a)};
e.hasPrev=function(){return this.shouldLoop||0<this.j};e.hasNext=function(){return this.shouldLoop||this.j<this.b.length-1};e.moveSlide=function(a,b){if(null!==this.j){var c=this.hasNext(),d=this.hasPrev();if(1==a&&c||-1==a&&d){var f=this.j+a;-1==f?f=this.s-1:f>=this.s&&(f=0);b?Y(this,1!=a||d?this.L:0,a):X(this,f)}}};
e.Ia=function(){var a=this;this.$&&q(this.win).cancel(this.$);var b=this.g.scrollLeft;this.N||Ea(this,b);if(!this.ea){var c=this.N?35:100;this.$=q(this.win).delay(function(){a.aa||(a.N?W(a,b):Y(a,b))},c)}this.ma=b};function Ea(a,b){var c=a.g.scrollWidth;-1==a.W&&b>=a.ma?Y(a,b).then(function(){a.W=0}):1==a.W&&b<=a.ma?Y(a,b).then(function(){a.W=0}):a.W=0>b?-1:b+a.L>c?1:0}
function Y(a,b,c){a.aa=!0;var d,f=Fa(a,b)-a.j,g=a.hasPrev();0!=f||1!=c&&-1!=c||(f=c);if(0==f)d=g?a.L:0;else if(1==f||-1!=f&&f==-1*(a.s-1))d=g?2*a.L:a.L;else if(-1==f||f==a.s-1)d=0;return Ga(a,b,d).then(function(){W(a,d)})}function Fa(a,b){var c=Math.round(b/a.L),d=0;b=a.hasPrev();var f=a.hasNext();b&&f?d=c-1:f?d=c:b&&(d=c-1);b=a.j+d;return b=a.shouldLoop?0>b?a.s-1:b>=a.s?0:b:0>b?0:b>=a.s?a.s-1:b}
function W(a,b){a.aa=!0;var c=Fa(a,b);a.D.mutate(function(){a.g.classList.add("-amp-no-scroll");X(a,c);a.D.mutate(function(){a.g.classList.remove("-amp-no-scroll");a.aa=!1})})}
function X(a,b){var c=a.s;if(!(0>b||b>=c||a.j==b)){var d=0<=b-1?b-1:a.shouldLoop?c-1:null,c=b+1<c?b+1:a.shouldLoop?0:null,f=[];null!=d&&f.push(d);f.push(b);null!=c&&f.push(c);null!==a.j&&a.updateInViewport(a.b[a.j],!1);a.updateInViewport(a.b[b],!0);f.forEach(function(c,d){a.shouldLoop&&v(a.T[c],"order",d+1);a.T[c].classList.add("-amp-slide-item-show");c==b?(a.scheduleLayout(a.b[c]),a.scheduleResume(a.b[c])):a.schedulePreload(a.b[c])});a.g.scrollLeft=Da(a,b);a.j=b;Ha(a,f);a.setControlsState()}}
function Da(a,b){var c=a.L;a.shouldLoop||0!=b||(c=0);return c}function Ha(a,b){for(var c=a.s,d=0;d<c;d++)a.T[d].classList.contains("-amp-slide-item-show")&&(-1==b.indexOf(d)&&(a.shouldLoop&&v(a.T[d],"order",""),a.T[d].classList.remove("-amp-slide-item-show")),a.j!=d&&a.schedulePause(a.b[d]))}function Ga(a,b,c){if(b==c)return Promise.resolve();var d=E(b,c);c=z(.4,0,.2,1);var f=a.g;return B(f,function(b){a.g.scrollLeft=d(b)},80,c).thenAlways()}
e.ra=function(){this.element.addEventListener("touchmove",function(a){a.stopPropagation()})};function Z(a){M.call(this,a);this.xa=this.a=0;this.Ja=this.c=this.u=null}l(Z,M);e=Z.prototype;e.isLayoutSupported=function(a){return"fixed"==a||"fixed-height"==a};
e.buildCarousel=function(){var a=this;this.u=this.getRealChildren();this.c=this.element.ownerDocument.createElement("div");w(this.c,{"white-space":"nowrap","overflow-x":"auto","overflow-y":"hidden","-webkit-overflow-scrolling":"touch"});this.element.appendChild(this.c);this.u.forEach(function(b){a.setAsOwner(b);b.classList.add("amp-carousel-slide");b.style.display="inline-block";b!=a.u[0]&&(b.style.marginLeft="8px");a.c.appendChild(b)});this.ra();this.c.addEventListener("scroll",this.Ia.bind(this))};
e.layoutCallback=function(){this.V(this.a);this.J(this.a,1);this.setControlsState();return Promise.resolve()};e.onViewportCallback=function(){this.ga(this.a,this.a)};e.goCallback=function(a,b){var c=this,d=this.X(this.a,a);a=this.a;if(d!=a)if(b){var f=E(a,d);B(this.element,function(a){c.c.scrollLeft=f(a)},200,"ease-in-out").thenAlways(function(){c.m(d)})}else this.m(d),this.c.scrollLeft=d};e.Ia=function(){var a=this.c.scrollLeft;this.a=a;null===this.Ja&&Ia(this,a)};
function Ia(a,b){a.Ja=q(a.win).delay(function(){30>Math.abs(b-a.a)?(a.Ja=null,a.m(a.a)):Ia(a,a.a)},100)}e.m=function(a){this.ga(a,this.xa);this.V(a);this.J(a,Math.sign(a-this.xa));this.setControlsState();this.a=this.xa=a};e.X=function(a,b){var c=this.element.offsetWidth,d=this.c.scrollWidth;a+=b*c;return 0>a?0:d>=c&&a>d-c?d-c:a};e.H=function(a,b){for(var c=this.getLayoutWidth(),d=0;d<this.u.length;d++){var f=this.u[d];f.offsetLeft+f.offsetWidth>=a&&f.offsetLeft<=a+c&&b(f)}};
e.V=function(a){var b=this;this.H(a,function(a){b.scheduleLayout(a)})};e.J=function(a,b){var c=this;b=this.X(a,b);b!=a&&this.H(b,function(a){c.schedulePreload(a)})};e.ga=function(a,b){var c=this,d=[];this.H(a,function(a){d.push(a);c.updateInViewport(a,!0)});b!=a&&this.H(b,function(a){-1==d.indexOf(a)&&(c.updateInViewport(a,!1),c.schedulePause(a))})};e.hasPrev=function(){return 0!=this.a};e.hasNext=function(){var a=this.getLayoutWidth();return this.a!=Math.max(this.c.scrollWidth-a,0)};
e.ra=function(){this.element.addEventListener("touchmove",function(a){a.stopPropagation()})};AMP.registerElement("amp-carousel",function(a){if(a.hasAttribute("type")&&"slides"==a.getAttribute("type")){var b=aa(a.ownerDocument.defaultView,"amp-slidescroll");return b?new V(a):new O(a)}var c=aa(a.ownerDocument.defaultView,"amp-scrollable-carousel");return c?new Z(a):new T(a)},'.amp-carousel-slide>.-amp-replaced-content{-o-object-fit:contain;object-fit:contain}.amp-carousel-button{position:absolute;box-sizing:border-box;top:50%;height:34px;width:34px;border-radius:2px;opacity:0;pointer-events:all;background-color:rgba(0,0,0,.5);background-position:50% 50%;background-repeat:no-repeat;-webkit-transform:translateY(-50%);transform:translateY(-50%);visibility:hidden;z-index:10}.amp-mode-mouse .amp-carousel-button,amp-carousel[controls] .amp-carousel-button{opacity:1;visibility:visible}.amp-carousel-button-prev{left:16px;background-image:url(\'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="%23fff" viewBox="0 0 18 18"><path d="M15 8.25H5.87l4.19-4.19L9 3 3 9l6 6 1.06-1.06-4.19-4.19H15v-1.5z" /></svg>\');background-size:18px 18px}.amp-carousel-button-next{right:16px;background-image:url(\'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="%23fff" viewBox="0 0 18 18"><path d="M9 3L7.94 4.06l4.19 4.19H3v1.5h9.13l-4.19 4.19L9 15l6-6z" /></svg>\');background-size:18px 18px}:not(.amp-mode-mouse) .-amp-carousel-button-start-hint .amp-carousel-button:not(.amp-disabled){-webkit-animation:a 1s ease-in 0s 1 normal both;animation:a 1s ease-in 0s 1 normal both}@-webkit-keyframes a{0%{opacity:1;visibility:visible}to{opacity:0;visibility:hidden}}@keyframes a{0%{opacity:1;visibility:visible}to{opacity:0;visibility:hidden}}amp-carousel .amp-carousel-button.amp-disabled{-webkit-animation:none;animation:none;opacity:0;visibility:hidden}.-amp-slides-container{display:-webkit-box!important;display:-webkit-flex!important;display:-ms-flexbox!important;display:flex!important;-webkit-flex-wrap:nowrap;-ms-flex-wrap:nowrap;flex-wrap:nowrap;height:100%!important;left:0;overflow-x:auto!important;overflow-y:hidden!important;position:absolute!important;top:0;width:100%!important;-webkit-scroll-snap-type:mandatory!important;scroll-snap-type:mandatory!important;padding-bottom:20px!important;box-sizing:content-box!important;-webkit-overflow-scrolling:touch!important}.-amp-slides-container.-amp-no-scroll{overflow-x:hidden!important}.-amp-slide-item{-webkit-box-align:center!important;-webkit-align-items:center!important;-ms-flex-align:center!important;align-items:center!important;display:none!important;-webkit-box-flex:0!important;-webkit-flex:0 0 100%!important;-ms-flex:0 0 100%!important;flex:0 0 100%!important;height:100%!important;-webkit-box-pack:center!important;-webkit-justify-content:center!important;-ms-flex-pack:center!important;justify-content:center!important;position:relative!important;-webkit-scroll-snap-coordinate:0 0!important;scroll-snap-coordinate:0 0!important;width:100%!important}.-amp-slide-item>*{height:100%;width:100%}.-amp-slide-item-show{display:-webkit-box!important;display:-webkit-flex!important;display:-ms-flexbox!important;display:flex!important}.-amp-carousel-end-marker,.-amp-carousel-start-marker{background-color:transparent!important;display:block!important;-webkit-box-flex:0!important;-webkit-flex:0 0 1px!important;-ms-flex:0 0 1px!important;flex:0 0 1px!important;height:100%!important;position:relative!important;-webkit-scroll-snap-coordinate:0 0!important;scroll-snap-coordinate:0 0!important;width:1px!important}.-amp-carousel-start-marker{-webkit-box-ordinal-group:0!important;-webkit-order:-1!important;-ms-flex-order:-1!important;order:-1!important;margin-left:-1px!important}.-amp-carousel-end-marker{-webkit-box-ordinal-group:100000001!important;-webkit-order:100000000!important;-ms-flex-order:100000000!important;order:100000000!important;margin-right:-1px!important}\n/*# sourceURL=/extensions/amp-carousel/0.1/amp-carousel.css*/');
})});
//# sourceMappingURL=amp-carousel-0.1.js.map