embla-carousel
Advanced tools
Comparing version 4.3.1 to 4.3.2
@@ -805,6 +805,6 @@ function _extends() { | ||
function ScrollTarget(indexCurrent, loop, scrollSnaps, contentSize, limit, targetVector) { | ||
var reachedMax = limit.reachedMax, | ||
reachedAny = limit.reachedAny, | ||
removeOffset = limit.removeOffset; | ||
function ScrollTarget(loop, scrollSnaps, contentSize, limit, targetVector) { | ||
var reachedAny = limit.reachedAny, | ||
removeOffset = limit.removeOffset, | ||
constrain = limit.constrain; | ||
@@ -816,3 +816,3 @@ function minDistance(d1, d2) { | ||
function findTargetSnap(target) { | ||
var distance = removeOffset(target); | ||
var distance = loop ? removeOffset(target) : constrain(target); | ||
var ascDiffsToSnaps = scrollSnaps.map(function (scrollSnap) { | ||
@@ -847,10 +847,2 @@ return scrollSnap - distance; | ||
function findTargetIndex(target, index) { | ||
var reachedBound = !loop && reachedAny(target); | ||
if (!reachedBound) return index; | ||
var min = indexCurrent.min, | ||
max = indexCurrent.max; | ||
return reachedMax(target) ? min : max; | ||
} | ||
function byIndex(index, direction) { | ||
@@ -867,4 +859,7 @@ var diffToSnap = scrollSnaps[index] - targetVector.get(); | ||
var target = targetVector.get() + distance; | ||
var targetSnap = findTargetSnap(target); | ||
var index = findTargetIndex(target, targetSnap.index); | ||
var _a = findTargetSnap(target), | ||
index = _a.index, | ||
targetSnapDistance = _a.distance; | ||
var reachedBound = !loop && reachedAny(target); | ||
@@ -875,3 +870,3 @@ if (!snap || reachedBound) return { | ||
}; | ||
var diffToSnap = scrollSnaps[index] - targetSnap.distance; | ||
var diffToSnap = scrollSnaps[index] - targetSnapDistance; | ||
var snapDistance = distance + shortcut(diffToSnap, 0); | ||
@@ -1228,3 +1223,3 @@ return { | ||
var scrollBody = ScrollBody(location, speed, 1); | ||
var scrollTarget = ScrollTarget(index, loop, scrollSnaps, contentSize, limit, target); | ||
var scrollTarget = ScrollTarget(loop, scrollSnaps, contentSize, limit, target); | ||
var scrollTo = ScrollTo(animation, index, indexPrevious, scrollTarget, target, events); | ||
@@ -1231,0 +1226,0 @@ var slidesInView = SlidesInView(viewSize, contentSize, slideSizes, snaps, loop, inViewThreshold); // DragHandler |
@@ -807,6 +807,6 @@ 'use strict'; | ||
function ScrollTarget(indexCurrent, loop, scrollSnaps, contentSize, limit, targetVector) { | ||
var reachedMax = limit.reachedMax, | ||
reachedAny = limit.reachedAny, | ||
removeOffset = limit.removeOffset; | ||
function ScrollTarget(loop, scrollSnaps, contentSize, limit, targetVector) { | ||
var reachedAny = limit.reachedAny, | ||
removeOffset = limit.removeOffset, | ||
constrain = limit.constrain; | ||
@@ -818,3 +818,3 @@ function minDistance(d1, d2) { | ||
function findTargetSnap(target) { | ||
var distance = removeOffset(target); | ||
var distance = loop ? removeOffset(target) : constrain(target); | ||
var ascDiffsToSnaps = scrollSnaps.map(function (scrollSnap) { | ||
@@ -849,10 +849,2 @@ return scrollSnap - distance; | ||
function findTargetIndex(target, index) { | ||
var reachedBound = !loop && reachedAny(target); | ||
if (!reachedBound) return index; | ||
var min = indexCurrent.min, | ||
max = indexCurrent.max; | ||
return reachedMax(target) ? min : max; | ||
} | ||
function byIndex(index, direction) { | ||
@@ -869,4 +861,7 @@ var diffToSnap = scrollSnaps[index] - targetVector.get(); | ||
var target = targetVector.get() + distance; | ||
var targetSnap = findTargetSnap(target); | ||
var index = findTargetIndex(target, targetSnap.index); | ||
var _a = findTargetSnap(target), | ||
index = _a.index, | ||
targetSnapDistance = _a.distance; | ||
var reachedBound = !loop && reachedAny(target); | ||
@@ -877,3 +872,3 @@ if (!snap || reachedBound) return { | ||
}; | ||
var diffToSnap = scrollSnaps[index] - targetSnap.distance; | ||
var diffToSnap = scrollSnaps[index] - targetSnapDistance; | ||
var snapDistance = distance + shortcut(diffToSnap, 0); | ||
@@ -1230,3 +1225,3 @@ return { | ||
var scrollBody = ScrollBody(location, speed, 1); | ||
var scrollTarget = ScrollTarget(index, loop, scrollSnaps, contentSize, limit, target); | ||
var scrollTarget = ScrollTarget(loop, scrollSnaps, contentSize, limit, target); | ||
var scrollTo = ScrollTo(animation, index, indexPrevious, scrollTarget, target, events); | ||
@@ -1233,0 +1228,0 @@ var slidesInView = SlidesInView(viewSize, contentSize, slideSizes, snaps, loop, inViewThreshold); // DragHandler |
@@ -1,1 +0,1 @@ | ||
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(n="undefined"!=typeof globalThis?globalThis:n||self).EmblaCarousel=e()}(this,(function(){"use strict";function n(){return(n=Object.assign||function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r])}return n}).apply(this,arguments)}function e(n,e){var t={start:function(){return 0},center:function(n){return r(n)/2},end:r};function r(n){return e-n}return{measure:function(r){return"number"==typeof n?e*Number(n):t[n](r)}}}function t(n){return n?n/Math.abs(n):0}function r(n,e){return Math.abs(n-e)}function o(n,e){for(var t=[],r=0;r<n.length;r+=e)t.push(n.slice(r,r+e));return t}function i(n){return Object.keys(n).map(Number)}function a(n){return n[u(n)]}function u(n){return Math.max(0,n.length-1)}function c(n,e){var t=n.classList;e&&t.contains(e)&&t.remove(e)}function s(n,e){var t=n.classList;e&&!t.contains(e)&&t.add(e)}function d(){var n=[];var e={add:function(t,r,o,i){return void 0===i&&(i=!1),t.addEventListener(r,o,i),n.push((function(){return t.removeEventListener(r,o,i)})),e},removeAll:function(){return n=n.filter((function(n){return n()})),e}};return e}function f(n){var e=n;function t(n){return e/=n,o}function r(n){return"number"==typeof n?n:n.get()}var o={add:function(n){return e+=r(n),o},divide:t,get:function(){return e},multiply:function(n){return e*=n,o},normalize:function(){return 0!==e&&t(e),o},set:function(n){return e=r(n),o},subtract:function(n){return e-=r(n),o}};return o}function l(n,e,o,i,a,u,c,s,l,p,g,m,v,h){var x=n.scroll,y=n.cross,b=["INPUT","SELECT","TEXTAREA"],w=f(0),M=f(0),S=f(0),E=d(),A=d(),T={mouse:2.5,touch:3.5},C={mouse:5,touch:7},D=a?5:12,P=!1,B=!1,I=!1,L=!1;function z(n){if(!(L="mousedown"===n.type)||0===n.button){var e,t,a=r(i.get(),c.get())>=2,s=L||!a,d=(e=n.target,t=e.nodeName||"",!(b.indexOf(t)>-1)),f=a||L&&d;P=!0,u.pointerDown(n),S.set(i),i.set(c),p.useBaseMass().useSpeed(80),function(){var n=L?document:o;A.add(n,"touchmove",O).add(n,"touchend",k).add(n,"mousemove",O).add(n,"mouseup",k)}(),w.set(u.readPoint(n,x)),M.set(u.readPoint(n,y)),h.emit("pointerDown"),s&&(I=!1),f&&n.preventDefault()}}function O(n){if(!B&&!L){if(!n.cancelable)return k();var t=u.readPoint(n,x).get(),o=u.readPoint(n,y).get(),a=r(t,w.get()),c=r(o,M.get());if(!(B=a>c)&&!I)return k()}var d=u.pointerMove(n);!I&&d&&(I=!0),s.start(),i.add(e.applyTo(d)),n.preventDefault()}function k(){var n=u.pointerUp()*(a?C:T)[L?"mouse":"touch"],o=function(n){var e=!(g.byDistance(0,!1).index!==m.get())&&Math.abs(n)>4,r=n+c.get();if(e&&!a&&!v.reachedAny(r)){var o=m.clone().add(-1*t(n));return g.byIndex(o.get(),0).distance}return g.byDistance(n,!a).distance}(e.applyTo(n)),s=function(n,e){if(0===n||0===e)return 0;if(Math.abs(n)<=Math.abs(e))return 0;var t=r(Math.abs(n),Math.abs(e));return Math.abs(t/n)}(n,o);r(i.get(),S.get())>=.5&&!L&&(I=!0),B=!1,P=!1,A.removeAll(),p.useSpeed(D+D*s),l.distance(o,!a),L=!1,h.emit("pointerUp")}function N(n){I&&n.preventDefault()}return{addActivationEvents:function(){var n=o;E.add(n,"touchmove",(function(){})).add(n,"touchend",(function(){})).add(n,"touchstart",z).add(n,"mousedown",z).add(n,"touchcancel",k).add(n,"contextmenu",k).add(n,"click",N)},clickAllowed:function(){return!I},pointerDown:function(){return P},removeAllEvents:function(){E.removeAll(),A.removeAll()}}}function p(n,e){var t=Math.abs(n-e);function r(e){return e<n}function o(n){return n>e}function i(n){return r(n)||o(n)}return{constrain:function(t){return i(t)?r(t)?n:e:t},length:t,loop:function(t){return i(t)?r(t)?e:n:t},max:e,min:n,reachedAny:i,reachedMax:o,reachedMin:r,removeOffset:function(n){return t?n-t*Math.ceil((n-e)/t):n}}}function g(n,e,r){var o,i,a=(o=2,i=Math.pow(10,o),function(n){return Math.round(n*i)/i}),u=f(0),c=f(0),s=f(0),d=0,l=e,p=r;function g(n){return l=n,v}function m(n){return p=n,v}var v={direction:function(){return d},seek:function(e){s.set(e).subtract(n);var r,o,i,a=(r=s.get(),(i=0)+(r-(o=0))/(100-o)*(l-i));return d=t(s.get()),s.normalize().multiply(a).subtract(u),function(n){n.divide(p),c.add(n)}(s),v},settle:function(e){var t=e.get()-n.get(),r=!a(t);return r&&n.set(e),r},update:function(){u.add(c),n.add(u),c.multiply(0)},useBaseMass:function(){return m(r)},useBaseSpeed:function(){return g(e)},useMass:m,useSpeed:g};return v}function m(n,e,t){var r=!1;return{constrain:function(o,i){if(function(t){return!r&&(!!n.reachedAny(t.get())&&!!n.reachedAny(e.get()))}(o)){var a=i?.7:.4,u=o.get()-e.get();o.subtract(u*a),!i&&Math.abs(u)<10&&(o.set(n.constrain(o.get())),t.useSpeed(10).useMass(3))}},toggleActive:function(n){r=!n}}}function v(n,e,t,r,o){var i=p(-e+n,t[0]),u=r.map(i.constrain);return{snapsContained:function(){if(e<=n)return[i.max];if("keepSnaps"===o)return u;var t=function(){var n=u[0],e=a(u),t=u.lastIndexOf(n),r=u.indexOf(e)+1;return p(t,r)}(),r=t.min,c=t.max;return u.slice(r,c)}()}}function h(n,e,t,r){var o=p(t.min+e.measure(.1),t.max+e.measure(.1)),i=o.reachedMin,a=o.reachedMax;return{loop:function(e,t){if(function(n){return 1===n?a(r.get()):-1===n&&i(r.get())}(t)){var o=n*(-1*t);e.forEach((function(n){return n.add(o)}))}}}}function x(n){var e=n.max,t=n.length;return{get:function(n){return(n-e)/-t}}}function y(n,e,t,r,i,u){var c,s,d=n.startEdge,f=n.endEdge,l=i.map((function(n){return r[d]-n[d]})).map(t.measure).map((function(n){return-Math.abs(n)})),p=(c=o(l,u).map((function(n){return n[0]})),s=o(i,u).map((function(n){return a(n)[f]-n[0][d]})).map(t.measure).map(Math.abs).map(e.measure),c.map((function(n,e){return n+s[e]})));return{snaps:l,snapsAligned:p}}function b(n,e,t,r,o,i){var a=o.reachedMax,u=o.reachedAny,c=o.removeOffset;function s(n,e){return Math.abs(n)<Math.abs(e)?n:e}function d(n,t){var o=n,i=n+r,a=n-r;if(!e)return o;if(!t)return s(s(o,i),a);var u=s(o,1===t?i:a);return Math.abs(u)*t}return{byDistance:function(r,o){var s=i.get()+r,f=function(n){var e=c(n);return{index:t.map((function(n){return n-e})).map((function(n){return d(n,0)})).map((function(n,e){return{diff:n,index:e}})).sort((function(n,e){return Math.abs(n.diff)-Math.abs(e.diff)}))[0].index,distance:e}}(s),l=function(t,r){if(!(!e&&u(t)))return r;var o=n.min,i=n.max;return a(t)?o:i}(s,f.index),p=!e&&u(s);return!o||p?{index:l,distance:r}:{index:l,distance:r+d(t[l]-f.distance,0)}},byIndex:function(n,e){return{index:n,distance:d(t[n]-i.get(),e)}},shortcut:d}}function w(n,e,t,r,o,a,u){var c,s=i(r),d=i(r).reverse(),f=(c=o[0]-1,g(p(d,c),"end")).concat(function(){var n=e-o[0]-1;return g(p(s,n),"start")}());function l(n,e){return n.reduce((function(n,e){return n-r[e]}),e)}function p(n,e){return n.reduce((function(n,t){return l(n,e)>0?n.concat([t]):n}),[])}function g(n,e){var r="start"===e,o=r?-t:t,i=a.findSlideBounds(o);return n.map((function(n){var e=r?0:-t,o=r?t:0,a=i.filter((function(e){return e.index===n}))[0][r?"end":"start"];return{point:a,getTarget:function(){return u.get()>a?e:o},index:n,location:-1}}))}return{canLoop:function(){return f.every((function(n){var t=n.index;return l(s.filter((function(n){return n!==t})),e)<=0}))},clear:function(e){f.forEach((function(t){var r=t.index;e[r].style[n.startEdge]=""}))},loop:function(e){f.forEach((function(t){var r=t.getTarget,o=t.location,i=t.index,a=r();a!==o&&(e[i].style[n.startEdge]=a+"%",t.location=a)}))},loopPoints:f}}function M(n,e,t){var r=d(),o=r.removeAll,i=0;function a(n){9===n.keyCode&&(i=(new Date).getTime())}function u(o,a){r.add(o,"focus",(function(){if(!((new Date).getTime()-i>10)){n.scrollLeft=0;var r=Math.floor(a/t);e.index(r,0)}}),!0)}return{addActivationEvents:function(n){r.add(document,"keydown",a,!1),n.forEach(u)},removeAllEvents:o}}function S(n,e,t){var r=t.style,o="x"===n.scroll?function(n){return"translate3d("+n+"%,0px,0px)"}:function(n){return"translate3d(0px,"+n+"%,0px)"},i=!1;return{clear:function(){r.transform=""},to:function(n){i||(r.transform=o(e.applyTo(n.get())))},toggleActive:function(n){i=!n}}}function E(n,r,o,c,s){var d,E=c.align,A=c.axis,T=c.direction,C=c.startIndex,D=c.inViewThreshold,P=c.loop,B=c.speed,I=c.dragFree,L=c.slidesToScroll,z=c.containScroll,O=r.getBoundingClientRect(),k=o.map((function(n){return n.getBoundingClientRect()})),N=function(n){var e="rtl"===n?-1:1;return{applyTo:function(n){return n*e}}}(T),F=function(n,e){var t="y"===n?"y":"x";return{scroll:t,cross:"y"===n?"x":"y",startEdge:"y"===t?"top":"rtl"===e?"right":"left",endEdge:"y"===t?"bottom":"rtl"===e?"left":"right",measureSize:function(n){var e=n.width,r=n.height;return"x"===t?e:r}}}(A,T),U=(d=F.measureSize(O),{measure:function(n){return 0===d?0:n/d*100},totalPercent:100}),V=U.totalPercent,H=e(E,V),R=function(n,e,t,r,o){var i=n.measureSize,c=n.startEdge,s=n.endEdge,d=r.map(i);return{slideSizes:d.map(e.measure),slideSizesWithGaps:r.map((function(n,e,r){var i=e===u(r),f=window.getComputedStyle(a(t)),l=parseFloat(f.getPropertyValue("margin-"+s));return i?d[e]+(o?l:0):r[e+1][c]-n[c]})).map(e.measure).map(Math.abs)}}(F,U,o,k,P),j=R.slideSizes,G=R.slideSizesWithGaps,q=y(F,H,U,O,k,L),W=q.snaps,X=q.snapsAligned,J=-1*a(W)+a(G),Y=v(V,J,W,X,z).snapsContained,K=!P&&""!==z?Y:X,Q=function(n,e,t){var r,o;return{limit:(r=e[0],o=a(e),p(t?r-n:o,r))}}(J,K,P).limit,Z=function n(e,r,o){var i=e.min,a=e.max,u=e[r?"loop":"constrain"],c=u(o);function s(){return c}function d(n){return c=u(n),f}var f={add:function n(e){if(0!==e){var r=t(e);return d(s()+r),n(e+-1*r)}return f},clone:function(){return n(e,r,s())},get:s,max:a,min:i,set:d};return f}(p(0,u(K)),P,C),$=Z.clone(),_=i(o),nn=function(n){var e=0;function t(n,t){return function(){n===!!e&&t()}}function r(){e=window.requestAnimationFrame(n)}return{proceed:t(!0,r),start:t(!1,r),stop:t(!0,(function(){window.cancelAnimationFrame(e),e=0}))}}((function(){P||dn.scrollBounds.constrain(rn,dn.dragHandler.pointerDown()),dn.scrollBody.seek(rn).update();var n=dn.scrollBody.settle(rn);n&&!dn.dragHandler.pointerDown()&&(dn.animation.stop(),s.emit("settle")),n||s.emit("scroll"),P&&(dn.scrollLooper.loop(on,dn.scrollBody.direction()),dn.slideLooper.loop(o)),dn.translate.to(tn),dn.animation.proceed()})),en=K[Z.get()],tn=f(en),rn=f(en),on=[tn,rn],an=g(tn,B,1),un=b(Z,P,K,J,Q,rn),cn=function(n,e,t,r,o,i){function a(r){var a=r.distance,u=r.index!==e.get();a&&(n.start(),o.add(a)),u&&(t.set(e.get()),e.set(r.index),i.emit("select"))}return{distance:function(n,e){a(r.byDistance(n,e))},index:function(n,t){var o=e.clone().set(n);a(r.byIndex(o.get(),t))}}}(nn,Z,$,un,rn,s),sn=function(n,e,t,r,o,i){var a=Math.min(Math.max(i,.01),.99),u=(o?[0,e,-e]:[0]).reduce((function(n,e){return n.concat(c(e,a))}),[]);function c(e,o){var i=t.map((function(n){return n*(o||0)}));return r.map((function(r,o){return{start:r-t[o]+i[o]+e,end:r+n-i[o]+e,index:o}}))}return{check:function(n){return u.reduce((function(e,t){var r=t.index,o=t.start,i=t.end;return!(-1!==e.indexOf(r))&&(o<n&&i>n)?e.concat([r]):e}),[])},findSlideBounds:c}}(V,J,j,W,P,D),dn={animation:nn,axis:F,direction:N,dragHandler:l(F,N,n,rn,I,function(n,e){var t=n.scroll,r={x:"clientX",y:"clientY"},o=f(0),i=f(0),a=f(0),u=f(0),c=[],s=(new Date).getTime(),d=!1;function l(n,e){d=!n.touches;var t=r[e],o=d?n[t]:n.touches[0][t];return u.set(o)}return{pointerDown:function(n){var r=l(n,t);return o.set(r),a.set(r),e.measure(o.get())},pointerMove:function(n){var r=l(n,t),o=(new Date).getTime(),u=o-s;return u>=10&&(u>=100&&(c=[]),c.push(r.get()),s=o),i.set(r).subtract(a),a.set(r),e.measure(i.get())},pointerUp:function(){var n=(new Date).getTime()-s,t=a.get(),r=c.slice(-5).map((function(n){return t-n})).sort((function(n,e){return Math.abs(n)<Math.abs(e)?1:-1}))[0];return a.set(n>100||!r?0:r),c=[],e.measure(a.get())},readPoint:l}}(F,U),tn,nn,cn,an,un,Z,Q,s),pxToPercent:U,index:Z,indexPrevious:$,limit:Q,location:tn,options:c,scrollBody:an,scrollBounds:m(Q,tn,an),scrollLooper:h(J,U,Q,tn),scrollProgress:x(Q),scrollSnaps:K,scrollTarget:un,scrollTo:cn,slideFocus:M(n,cn,L),slideLooper:w(F,V,J,G,K,sn,tn),slidesInView:sn,slideIndexes:_,target:rn,translate:S(F,N,r)};return dn}var A={align:"center",axis:"x",containScroll:"",direction:"ltr",dragFree:!1,draggable:!0,draggableClass:"is-draggable",draggingClass:"is-dragging",inViewThreshold:0,loop:!1,selectedClass:"is-selected",slidesToScroll:1,speed:10,startIndex:0};return function(e,t){var r,o,i,a,u,f,l,p=function(){var n={};function e(e){return n[e]||[]}var t={emit:function(n){return e(n).forEach((function(e){return e(n)})),t},off:function(r,o){return n[r]=e(r).filter((function(n){return n!==o})),t},on:function(r,o){return n[r]=e(r).concat([o]),t}};return t}(),g=d(),m=(r=function(){if(y){var n=a.axis.measureSize(e.getBoundingClientRect());M!==n&&B(),p.emit("resize")}},o=500,i=0,function(){window.clearTimeout(i),i=window.setTimeout(r,o)||0}),v=B,h=p.on,x=p.off,y=!1,b=n({},A),w=n({},b),M=0;function S(){if(!e)throw new Error("Missing root node 😢");var n,t,r=e.querySelector("*");if(!r)throw new Error("Missing container node 😢");f=r,l=Array.prototype.slice.call(f.children),n=e,t=window.getComputedStyle(n,":before").content,u={get:function(){try{return JSON.parse(t.slice(1,-1).replace(/\\/g,""))}catch(n){}return{}}}}function T(t){if(S(),b=n({},b,t),w=n({},b,u.get()),a=E(e,f,l,w,p),g.add(window,"resize",m),a.translate.to(a.location),M=a.axis.measureSize(e.getBoundingClientRect()),w.loop){if(!a.slideLooper.canLoop())return P(),T({loop:!1});a.slideLooper.loop(l)}w.draggable&&f.offsetParent&&l.length&&(a.dragHandler.addActivationEvents(),w.draggableClass&&s(e,w.draggableClass),w.draggingClass&&p.on("pointerDown",C).on("pointerUp",C)),l.length&&a.slideFocus.addActivationEvents(l),w.selectedClass&&(D(),p.on("select",D).on("pointerUp",D)),y||(setTimeout((function(){return p.emit("init")}),0),y=!0)}function C(n){var t=w.draggingClass;"pointerDown"===n?s(e,t):c(e,t)}function D(){var n=w.selectedClass,e=I(!0);L(!0).forEach((function(e){return c(l[e],n)})),e.forEach((function(e){return s(l[e],n)}))}function P(){a.dragHandler.removeAllEvents(),a.slideFocus.removeAllEvents(),a.animation.stop(),g.removeAll(),a.translate.clear(),a.slideLooper.clear(l),c(e,w.draggableClass),l.forEach((function(n){return c(n,w.selectedClass)})),p.off("select",D).off("pointerUp",D).off("pointerDown",C).off("pointerUp",C)}function B(e){if(y){var t=n({startIndex:O()},e);P(),T(t),p.emit("reInit")}}function I(n){var e=a[n?"target":"location"].get(),t=w.loop?"removeOffset":"constrain";return a.slidesInView.check(a.limit[t](e))}function L(n){var e=I(n);return a.slideIndexes.filter((function(n){return-1===e.indexOf(n)}))}function z(n,e){a.scrollBody.useBaseMass().useBaseSpeed(),y&&a.scrollTo.index(n,e||0)}function O(){return a.index.get()}return T(t),{canScrollNext:function(){return a.index.clone().add(1).get()!==O()},canScrollPrev:function(){return a.index.clone().add(-1).get()!==O()},clickAllowed:function(){return a.dragHandler.clickAllowed()},containerNode:function(){return f},dangerouslyGetEngine:function(){return a},destroy:function(){y&&(P(),y=!1,p.emit("destroy"))},off:x,on:h,previousScrollSnap:function(){return a.indexPrevious.get()},reInit:v,rootNode:function(){return e},scrollNext:function(){z(a.index.clone().add(1).get(),-1)},scrollPrev:function(){z(a.index.clone().add(-1).get(),1)},scrollProgress:function(){return a.scrollProgress.get(a.location.get())},scrollSnapList:function(){return a.scrollSnaps.map(a.scrollProgress.get)},scrollTo:z,selectedScrollSnap:O,slideNodes:function(){return l},slidesInView:I,slidesNotInView:L}}})); | ||
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(n="undefined"!=typeof globalThis?globalThis:n||self).EmblaCarousel=e()}(this,(function(){"use strict";function n(){return(n=Object.assign||function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r])}return n}).apply(this,arguments)}function e(n,e){var t={start:function(){return 0},center:function(n){return r(n)/2},end:r};function r(n){return e-n}return{measure:function(r){return"number"==typeof n?e*Number(n):t[n](r)}}}function t(n){return n?n/Math.abs(n):0}function r(n,e){return Math.abs(n-e)}function o(n,e){for(var t=[],r=0;r<n.length;r+=e)t.push(n.slice(r,r+e));return t}function i(n){return Object.keys(n).map(Number)}function a(n){return n[u(n)]}function u(n){return Math.max(0,n.length-1)}function c(n,e){var t=n.classList;e&&t.contains(e)&&t.remove(e)}function s(n,e){var t=n.classList;e&&!t.contains(e)&&t.add(e)}function d(){var n=[];var e={add:function(t,r,o,i){return void 0===i&&(i=!1),t.addEventListener(r,o,i),n.push((function(){return t.removeEventListener(r,o,i)})),e},removeAll:function(){return n=n.filter((function(n){return n()})),e}};return e}function f(n){var e=n;function t(n){return e/=n,o}function r(n){return"number"==typeof n?n:n.get()}var o={add:function(n){return e+=r(n),o},divide:t,get:function(){return e},multiply:function(n){return e*=n,o},normalize:function(){return 0!==e&&t(e),o},set:function(n){return e=r(n),o},subtract:function(n){return e-=r(n),o}};return o}function l(n,e,o,i,a,u,c,s,l,p,g,m,v,h){var x=n.scroll,y=n.cross,b=["INPUT","SELECT","TEXTAREA"],w=f(0),M=f(0),S=f(0),E=d(),A=d(),T={mouse:2.5,touch:3.5},C={mouse:5,touch:7},D=a?5:12,P=!1,B=!1,I=!1,L=!1;function z(n){if(!(L="mousedown"===n.type)||0===n.button){var e,t,a=r(i.get(),c.get())>=2,s=L||!a,d=(e=n.target,t=e.nodeName||"",!(b.indexOf(t)>-1)),f=a||L&&d;P=!0,u.pointerDown(n),S.set(i),i.set(c),p.useBaseMass().useSpeed(80),function(){var n=L?document:o;A.add(n,"touchmove",O).add(n,"touchend",k).add(n,"mousemove",O).add(n,"mouseup",k)}(),w.set(u.readPoint(n,x)),M.set(u.readPoint(n,y)),h.emit("pointerDown"),s&&(I=!1),f&&n.preventDefault()}}function O(n){if(!B&&!L){if(!n.cancelable)return k();var t=u.readPoint(n,x).get(),o=u.readPoint(n,y).get(),a=r(t,w.get()),c=r(o,M.get());if(!(B=a>c)&&!I)return k()}var d=u.pointerMove(n);!I&&d&&(I=!0),s.start(),i.add(e.applyTo(d)),n.preventDefault()}function k(){var n=u.pointerUp()*(a?C:T)[L?"mouse":"touch"],o=function(n){var e=!(g.byDistance(0,!1).index!==m.get())&&Math.abs(n)>4,r=n+c.get();if(e&&!a&&!v.reachedAny(r)){var o=m.clone().add(-1*t(n));return g.byIndex(o.get(),0).distance}return g.byDistance(n,!a).distance}(e.applyTo(n)),s=function(n,e){if(0===n||0===e)return 0;if(Math.abs(n)<=Math.abs(e))return 0;var t=r(Math.abs(n),Math.abs(e));return Math.abs(t/n)}(n,o);r(i.get(),S.get())>=.5&&!L&&(I=!0),B=!1,P=!1,A.removeAll(),p.useSpeed(D+D*s),l.distance(o,!a),L=!1,h.emit("pointerUp")}function N(n){I&&n.preventDefault()}return{addActivationEvents:function(){var n=o;E.add(n,"touchmove",(function(){})).add(n,"touchend",(function(){})).add(n,"touchstart",z).add(n,"mousedown",z).add(n,"touchcancel",k).add(n,"contextmenu",k).add(n,"click",N)},clickAllowed:function(){return!I},pointerDown:function(){return P},removeAllEvents:function(){E.removeAll(),A.removeAll()}}}function p(n,e){var t=Math.abs(n-e);function r(e){return e<n}function o(n){return n>e}function i(n){return r(n)||o(n)}return{constrain:function(t){return i(t)?r(t)?n:e:t},length:t,loop:function(t){return i(t)?r(t)?e:n:t},max:e,min:n,reachedAny:i,reachedMax:o,reachedMin:r,removeOffset:function(n){return t?n-t*Math.ceil((n-e)/t):n}}}function g(n,e,r){var o,i,a=(o=2,i=Math.pow(10,o),function(n){return Math.round(n*i)/i}),u=f(0),c=f(0),s=f(0),d=0,l=e,p=r;function g(n){return l=n,v}function m(n){return p=n,v}var v={direction:function(){return d},seek:function(e){s.set(e).subtract(n);var r,o,i,a=(r=s.get(),(i=0)+(r-(o=0))/(100-o)*(l-i));return d=t(s.get()),s.normalize().multiply(a).subtract(u),function(n){n.divide(p),c.add(n)}(s),v},settle:function(e){var t=e.get()-n.get(),r=!a(t);return r&&n.set(e),r},update:function(){u.add(c),n.add(u),c.multiply(0)},useBaseMass:function(){return m(r)},useBaseSpeed:function(){return g(e)},useMass:m,useSpeed:g};return v}function m(n,e,t){var r=!1;return{constrain:function(o,i){if(function(t){return!r&&(!!n.reachedAny(t.get())&&!!n.reachedAny(e.get()))}(o)){var a=i?.7:.4,u=o.get()-e.get();o.subtract(u*a),!i&&Math.abs(u)<10&&(o.set(n.constrain(o.get())),t.useSpeed(10).useMass(3))}},toggleActive:function(n){r=!n}}}function v(n,e,t,r,o){var i=p(-e+n,t[0]),u=r.map(i.constrain);return{snapsContained:function(){if(e<=n)return[i.max];if("keepSnaps"===o)return u;var t=function(){var n=u[0],e=a(u),t=u.lastIndexOf(n),r=u.indexOf(e)+1;return p(t,r)}(),r=t.min,c=t.max;return u.slice(r,c)}()}}function h(n,e,t,r){var o=p(t.min+e.measure(.1),t.max+e.measure(.1)),i=o.reachedMin,a=o.reachedMax;return{loop:function(e,t){if(function(n){return 1===n?a(r.get()):-1===n&&i(r.get())}(t)){var o=n*(-1*t);e.forEach((function(n){return n.add(o)}))}}}}function x(n){var e=n.max,t=n.length;return{get:function(n){return(n-e)/-t}}}function y(n,e,t,r,i,u){var c,s,d=n.startEdge,f=n.endEdge,l=i.map((function(n){return r[d]-n[d]})).map(t.measure).map((function(n){return-Math.abs(n)})),p=(c=o(l,u).map((function(n){return n[0]})),s=o(i,u).map((function(n){return a(n)[f]-n[0][d]})).map(t.measure).map(Math.abs).map(e.measure),c.map((function(n,e){return n+s[e]})));return{snaps:l,snapsAligned:p}}function b(n,e,t,r,o){var i=r.reachedAny,a=r.removeOffset,u=r.constrain;function c(n,e){return Math.abs(n)<Math.abs(e)?n:e}function s(e,r){var o=e,i=e+t,a=e-t;if(!n)return o;if(!r)return c(c(o,i),a);var u=c(o,1===r?i:a);return Math.abs(u)*r}return{byDistance:function(t,r){var c=o.get()+t,d=function(t){var r=n?a(t):u(t);return{index:e.map((function(n){return n-r})).map((function(n){return s(n,0)})).map((function(n,e){return{diff:n,index:e}})).sort((function(n,e){return Math.abs(n.diff)-Math.abs(e.diff)}))[0].index,distance:r}}(c),f=d.index,l=d.distance,p=!n&&i(c);return!r||p?{index:f,distance:t}:{index:f,distance:t+s(e[f]-l,0)}},byIndex:function(n,t){return{index:n,distance:s(e[n]-o.get(),t)}},shortcut:s}}function w(n,e,t,r,o,a,u){var c,s=i(r),d=i(r).reverse(),f=(c=o[0]-1,g(p(d,c),"end")).concat(function(){var n=e-o[0]-1;return g(p(s,n),"start")}());function l(n,e){return n.reduce((function(n,e){return n-r[e]}),e)}function p(n,e){return n.reduce((function(n,t){return l(n,e)>0?n.concat([t]):n}),[])}function g(n,e){var r="start"===e,o=r?-t:t,i=a.findSlideBounds(o);return n.map((function(n){var e=r?0:-t,o=r?t:0,a=i.filter((function(e){return e.index===n}))[0][r?"end":"start"];return{point:a,getTarget:function(){return u.get()>a?e:o},index:n,location:-1}}))}return{canLoop:function(){return f.every((function(n){var t=n.index;return l(s.filter((function(n){return n!==t})),e)<=0}))},clear:function(e){f.forEach((function(t){var r=t.index;e[r].style[n.startEdge]=""}))},loop:function(e){f.forEach((function(t){var r=t.getTarget,o=t.location,i=t.index,a=r();a!==o&&(e[i].style[n.startEdge]=a+"%",t.location=a)}))},loopPoints:f}}function M(n,e,t){var r=d(),o=r.removeAll,i=0;function a(n){9===n.keyCode&&(i=(new Date).getTime())}function u(o,a){r.add(o,"focus",(function(){if(!((new Date).getTime()-i>10)){n.scrollLeft=0;var r=Math.floor(a/t);e.index(r,0)}}),!0)}return{addActivationEvents:function(n){r.add(document,"keydown",a,!1),n.forEach(u)},removeAllEvents:o}}function S(n,e,t){var r=t.style,o="x"===n.scroll?function(n){return"translate3d("+n+"%,0px,0px)"}:function(n){return"translate3d(0px,"+n+"%,0px)"},i=!1;return{clear:function(){r.transform=""},to:function(n){i||(r.transform=o(e.applyTo(n.get())))},toggleActive:function(n){i=!n}}}function E(n,r,o,c,s){var d,E=c.align,A=c.axis,T=c.direction,C=c.startIndex,D=c.inViewThreshold,P=c.loop,B=c.speed,I=c.dragFree,L=c.slidesToScroll,z=c.containScroll,O=r.getBoundingClientRect(),k=o.map((function(n){return n.getBoundingClientRect()})),N=function(n){var e="rtl"===n?-1:1;return{applyTo:function(n){return n*e}}}(T),F=function(n,e){var t="y"===n?"y":"x";return{scroll:t,cross:"y"===n?"x":"y",startEdge:"y"===t?"top":"rtl"===e?"right":"left",endEdge:"y"===t?"bottom":"rtl"===e?"left":"right",measureSize:function(n){var e=n.width,r=n.height;return"x"===t?e:r}}}(A,T),U=(d=F.measureSize(O),{measure:function(n){return 0===d?0:n/d*100},totalPercent:100}),V=U.totalPercent,H=e(E,V),R=function(n,e,t,r,o){var i=n.measureSize,c=n.startEdge,s=n.endEdge,d=r.map(i);return{slideSizes:d.map(e.measure),slideSizesWithGaps:r.map((function(n,e,r){var i=e===u(r),f=window.getComputedStyle(a(t)),l=parseFloat(f.getPropertyValue("margin-"+s));return i?d[e]+(o?l:0):r[e+1][c]-n[c]})).map(e.measure).map(Math.abs)}}(F,U,o,k,P),j=R.slideSizes,G=R.slideSizesWithGaps,q=y(F,H,U,O,k,L),W=q.snaps,X=q.snapsAligned,J=-1*a(W)+a(G),Y=v(V,J,W,X,z).snapsContained,K=!P&&""!==z?Y:X,Q=function(n,e,t){var r,o;return{limit:(r=e[0],o=a(e),p(t?r-n:o,r))}}(J,K,P).limit,Z=function n(e,r,o){var i=e.min,a=e.max,u=e[r?"loop":"constrain"],c=u(o);function s(){return c}function d(n){return c=u(n),f}var f={add:function n(e){if(0!==e){var r=t(e);return d(s()+r),n(e+-1*r)}return f},clone:function(){return n(e,r,s())},get:s,max:a,min:i,set:d};return f}(p(0,u(K)),P,C),$=Z.clone(),_=i(o),nn=function(n){var e=0;function t(n,t){return function(){n===!!e&&t()}}function r(){e=window.requestAnimationFrame(n)}return{proceed:t(!0,r),start:t(!1,r),stop:t(!0,(function(){window.cancelAnimationFrame(e),e=0}))}}((function(){P||dn.scrollBounds.constrain(rn,dn.dragHandler.pointerDown()),dn.scrollBody.seek(rn).update();var n=dn.scrollBody.settle(rn);n&&!dn.dragHandler.pointerDown()&&(dn.animation.stop(),s.emit("settle")),n||s.emit("scroll"),P&&(dn.scrollLooper.loop(on,dn.scrollBody.direction()),dn.slideLooper.loop(o)),dn.translate.to(tn),dn.animation.proceed()})),en=K[Z.get()],tn=f(en),rn=f(en),on=[tn,rn],an=g(tn,B,1),un=b(P,K,J,Q,rn),cn=function(n,e,t,r,o,i){function a(r){var a=r.distance,u=r.index!==e.get();a&&(n.start(),o.add(a)),u&&(t.set(e.get()),e.set(r.index),i.emit("select"))}return{distance:function(n,e){a(r.byDistance(n,e))},index:function(n,t){var o=e.clone().set(n);a(r.byIndex(o.get(),t))}}}(nn,Z,$,un,rn,s),sn=function(n,e,t,r,o,i){var a=Math.min(Math.max(i,.01),.99),u=(o?[0,e,-e]:[0]).reduce((function(n,e){return n.concat(c(e,a))}),[]);function c(e,o){var i=t.map((function(n){return n*(o||0)}));return r.map((function(r,o){return{start:r-t[o]+i[o]+e,end:r+n-i[o]+e,index:o}}))}return{check:function(n){return u.reduce((function(e,t){var r=t.index,o=t.start,i=t.end;return!(-1!==e.indexOf(r))&&(o<n&&i>n)?e.concat([r]):e}),[])},findSlideBounds:c}}(V,J,j,W,P,D),dn={animation:nn,axis:F,direction:N,dragHandler:l(F,N,n,rn,I,function(n,e){var t=n.scroll,r={x:"clientX",y:"clientY"},o=f(0),i=f(0),a=f(0),u=f(0),c=[],s=(new Date).getTime(),d=!1;function l(n,e){d=!n.touches;var t=r[e],o=d?n[t]:n.touches[0][t];return u.set(o)}return{pointerDown:function(n){var r=l(n,t);return o.set(r),a.set(r),e.measure(o.get())},pointerMove:function(n){var r=l(n,t),o=(new Date).getTime(),u=o-s;return u>=10&&(u>=100&&(c=[]),c.push(r.get()),s=o),i.set(r).subtract(a),a.set(r),e.measure(i.get())},pointerUp:function(){var n=(new Date).getTime()-s,t=a.get(),r=c.slice(-5).map((function(n){return t-n})).sort((function(n,e){return Math.abs(n)<Math.abs(e)?1:-1}))[0];return a.set(n>100||!r?0:r),c=[],e.measure(a.get())},readPoint:l}}(F,U),tn,nn,cn,an,un,Z,Q,s),pxToPercent:U,index:Z,indexPrevious:$,limit:Q,location:tn,options:c,scrollBody:an,scrollBounds:m(Q,tn,an),scrollLooper:h(J,U,Q,tn),scrollProgress:x(Q),scrollSnaps:K,scrollTarget:un,scrollTo:cn,slideFocus:M(n,cn,L),slideLooper:w(F,V,J,G,K,sn,tn),slidesInView:sn,slideIndexes:_,target:rn,translate:S(F,N,r)};return dn}var A={align:"center",axis:"x",containScroll:"",direction:"ltr",dragFree:!1,draggable:!0,draggableClass:"is-draggable",draggingClass:"is-dragging",inViewThreshold:0,loop:!1,selectedClass:"is-selected",slidesToScroll:1,speed:10,startIndex:0};return function(e,t){var r,o,i,a,u,f,l,p=function(){var n={};function e(e){return n[e]||[]}var t={emit:function(n){return e(n).forEach((function(e){return e(n)})),t},off:function(r,o){return n[r]=e(r).filter((function(n){return n!==o})),t},on:function(r,o){return n[r]=e(r).concat([o]),t}};return t}(),g=d(),m=(r=function(){if(y){var n=a.axis.measureSize(e.getBoundingClientRect());M!==n&&B(),p.emit("resize")}},o=500,i=0,function(){window.clearTimeout(i),i=window.setTimeout(r,o)||0}),v=B,h=p.on,x=p.off,y=!1,b=n({},A),w=n({},b),M=0;function S(){if(!e)throw new Error("Missing root node 😢");var n,t,r=e.querySelector("*");if(!r)throw new Error("Missing container node 😢");f=r,l=Array.prototype.slice.call(f.children),n=e,t=window.getComputedStyle(n,":before").content,u={get:function(){try{return JSON.parse(t.slice(1,-1).replace(/\\/g,""))}catch(n){}return{}}}}function T(t){if(S(),b=n({},b,t),w=n({},b,u.get()),a=E(e,f,l,w,p),g.add(window,"resize",m),a.translate.to(a.location),M=a.axis.measureSize(e.getBoundingClientRect()),w.loop){if(!a.slideLooper.canLoop())return P(),T({loop:!1});a.slideLooper.loop(l)}w.draggable&&f.offsetParent&&l.length&&(a.dragHandler.addActivationEvents(),w.draggableClass&&s(e,w.draggableClass),w.draggingClass&&p.on("pointerDown",C).on("pointerUp",C)),l.length&&a.slideFocus.addActivationEvents(l),w.selectedClass&&(D(),p.on("select",D).on("pointerUp",D)),y||(setTimeout((function(){return p.emit("init")}),0),y=!0)}function C(n){var t=w.draggingClass;"pointerDown"===n?s(e,t):c(e,t)}function D(){var n=w.selectedClass,e=I(!0);L(!0).forEach((function(e){return c(l[e],n)})),e.forEach((function(e){return s(l[e],n)}))}function P(){a.dragHandler.removeAllEvents(),a.slideFocus.removeAllEvents(),a.animation.stop(),g.removeAll(),a.translate.clear(),a.slideLooper.clear(l),c(e,w.draggableClass),l.forEach((function(n){return c(n,w.selectedClass)})),p.off("select",D).off("pointerUp",D).off("pointerDown",C).off("pointerUp",C)}function B(e){if(y){var t=n({startIndex:O()},e);P(),T(t),p.emit("reInit")}}function I(n){var e=a[n?"target":"location"].get(),t=w.loop?"removeOffset":"constrain";return a.slidesInView.check(a.limit[t](e))}function L(n){var e=I(n);return a.slideIndexes.filter((function(n){return-1===e.indexOf(n)}))}function z(n,e){a.scrollBody.useBaseMass().useBaseSpeed(),y&&a.scrollTo.index(n,e||0)}function O(){return a.index.get()}return T(t),{canScrollNext:function(){return a.index.clone().add(1).get()!==O()},canScrollPrev:function(){return a.index.clone().add(-1).get()!==O()},clickAllowed:function(){return a.dragHandler.clickAllowed()},containerNode:function(){return f},dangerouslyGetEngine:function(){return a},destroy:function(){y&&(P(),y=!1,p.emit("destroy"))},off:x,on:h,previousScrollSnap:function(){return a.indexPrevious.get()},reInit:v,rootNode:function(){return e},scrollNext:function(){z(a.index.clone().add(1).get(),-1)},scrollPrev:function(){z(a.index.clone().add(-1).get(),1)},scrollProgress:function(){return a.scrollProgress.get(a.location.get())},scrollSnapList:function(){return a.scrollSnaps.map(a.scrollProgress.get)},scrollTo:z,selectedScrollSnap:O,slideNodes:function(){return l},slidesInView:I,slidesNotInView:L}}})); |
{ | ||
"name": "embla-carousel", | ||
"version": "4.3.1", | ||
"version": "4.3.2", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "author": "David Cetinkaya <david.o.cetinkaya@gmail.com>", |
@@ -807,6 +807,6 @@ import { useState, useRef, useMemo, useEffect } from 'react'; | ||
function ScrollTarget(indexCurrent, loop, scrollSnaps, contentSize, limit, targetVector) { | ||
var reachedMax = limit.reachedMax, | ||
reachedAny = limit.reachedAny, | ||
removeOffset = limit.removeOffset; | ||
function ScrollTarget(loop, scrollSnaps, contentSize, limit, targetVector) { | ||
var reachedAny = limit.reachedAny, | ||
removeOffset = limit.removeOffset, | ||
constrain = limit.constrain; | ||
@@ -818,3 +818,3 @@ function minDistance(d1, d2) { | ||
function findTargetSnap(target) { | ||
var distance = removeOffset(target); | ||
var distance = loop ? removeOffset(target) : constrain(target); | ||
var ascDiffsToSnaps = scrollSnaps.map(function (scrollSnap) { | ||
@@ -849,10 +849,2 @@ return scrollSnap - distance; | ||
function findTargetIndex(target, index) { | ||
var reachedBound = !loop && reachedAny(target); | ||
if (!reachedBound) return index; | ||
var min = indexCurrent.min, | ||
max = indexCurrent.max; | ||
return reachedMax(target) ? min : max; | ||
} | ||
function byIndex(index, direction) { | ||
@@ -869,4 +861,7 @@ var diffToSnap = scrollSnaps[index] - targetVector.get(); | ||
var target = targetVector.get() + distance; | ||
var targetSnap = findTargetSnap(target); | ||
var index = findTargetIndex(target, targetSnap.index); | ||
var _a = findTargetSnap(target), | ||
index = _a.index, | ||
targetSnapDistance = _a.distance; | ||
var reachedBound = !loop && reachedAny(target); | ||
@@ -877,3 +872,3 @@ if (!snap || reachedBound) return { | ||
}; | ||
var diffToSnap = scrollSnaps[index] - targetSnap.distance; | ||
var diffToSnap = scrollSnaps[index] - targetSnapDistance; | ||
var snapDistance = distance + shortcut(diffToSnap, 0); | ||
@@ -1230,3 +1225,3 @@ return { | ||
var scrollBody = ScrollBody(location, speed, 1); | ||
var scrollTarget = ScrollTarget(index, loop, scrollSnaps, contentSize, limit, target); | ||
var scrollTarget = ScrollTarget(loop, scrollSnaps, contentSize, limit, target); | ||
var scrollTo = ScrollTo(animation, index, indexPrevious, scrollTarget, target, events); | ||
@@ -1233,0 +1228,0 @@ var slidesInView = SlidesInView(viewSize, contentSize, slideSizes, snaps, loop, inViewThreshold); // DragHandler |
29
react.js
@@ -811,6 +811,6 @@ 'use strict'; | ||
function ScrollTarget(indexCurrent, loop, scrollSnaps, contentSize, limit, targetVector) { | ||
var reachedMax = limit.reachedMax, | ||
reachedAny = limit.reachedAny, | ||
removeOffset = limit.removeOffset; | ||
function ScrollTarget(loop, scrollSnaps, contentSize, limit, targetVector) { | ||
var reachedAny = limit.reachedAny, | ||
removeOffset = limit.removeOffset, | ||
constrain = limit.constrain; | ||
@@ -822,3 +822,3 @@ function minDistance(d1, d2) { | ||
function findTargetSnap(target) { | ||
var distance = removeOffset(target); | ||
var distance = loop ? removeOffset(target) : constrain(target); | ||
var ascDiffsToSnaps = scrollSnaps.map(function (scrollSnap) { | ||
@@ -853,10 +853,2 @@ return scrollSnap - distance; | ||
function findTargetIndex(target, index) { | ||
var reachedBound = !loop && reachedAny(target); | ||
if (!reachedBound) return index; | ||
var min = indexCurrent.min, | ||
max = indexCurrent.max; | ||
return reachedMax(target) ? min : max; | ||
} | ||
function byIndex(index, direction) { | ||
@@ -873,4 +865,7 @@ var diffToSnap = scrollSnaps[index] - targetVector.get(); | ||
var target = targetVector.get() + distance; | ||
var targetSnap = findTargetSnap(target); | ||
var index = findTargetIndex(target, targetSnap.index); | ||
var _a = findTargetSnap(target), | ||
index = _a.index, | ||
targetSnapDistance = _a.distance; | ||
var reachedBound = !loop && reachedAny(target); | ||
@@ -881,3 +876,3 @@ if (!snap || reachedBound) return { | ||
}; | ||
var diffToSnap = scrollSnaps[index] - targetSnap.distance; | ||
var diffToSnap = scrollSnaps[index] - targetSnapDistance; | ||
var snapDistance = distance + shortcut(diffToSnap, 0); | ||
@@ -1234,3 +1229,3 @@ return { | ||
var scrollBody = ScrollBody(location, speed, 1); | ||
var scrollTarget = ScrollTarget(index, loop, scrollSnaps, contentSize, limit, target); | ||
var scrollTarget = ScrollTarget(loop, scrollSnaps, contentSize, limit, target); | ||
var scrollTo = ScrollTo(animation, index, indexPrevious, scrollTarget, target, events); | ||
@@ -1237,0 +1232,0 @@ var slidesInView = SlidesInView(viewSize, contentSize, slideSizes, snaps, loop, inViewThreshold); // DragHandler |
@@ -1,2 +0,1 @@ | ||
import { CounterType } from './counter'; | ||
import { LimitType } from './limit'; | ||
@@ -13,2 +12,2 @@ import { Vector1DType } from './vector1d'; | ||
}; | ||
export declare function ScrollTarget(indexCurrent: CounterType, loop: boolean, scrollSnaps: number[], contentSize: number, limit: LimitType, targetVector: Vector1DType): ScrollTargetType; | ||
export declare function ScrollTarget(loop: boolean, scrollSnaps: number[], contentSize: number, limit: LimitType, targetVector: Vector1DType): ScrollTargetType; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
641536
5787