embla-carousel-react
Advanced tools
Comparing version 8.0.0-rc05 to 8.0.0-rc06
@@ -1,1 +0,1 @@ | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):(n="undefined"!=typeof globalThis?globalThis:n||self).EmblaCarouselReact=t(n.React)}(this,(function(n){"use strict";function t(n){return function(n){return"[object Object]"===Object.prototype.toString.call(n)}(n)||Array.isArray(n)}function e(n,r){const o=Object.keys(n),i=Object.keys(r);if(o.length!==i.length)return!1;return JSON.stringify(Object.keys(n.breakpoints||{}))===JSON.stringify(Object.keys(r.breakpoints||{}))&&o.every((o=>{const i=n[o],c=r[o];return"function"==typeof i?`${i}`==`${c}`:t(i)&&t(c)?e(i,c):i===c}))}function r(n){return n.concat().sort(((n,t)=>n.name>t.name?1:-1)).map((n=>n.options))}function o(n){return"number"==typeof n}function i(n){return"string"==typeof n}function c(n){return"boolean"==typeof n}function u(n){return"[object Object]"===Object.prototype.toString.call(n)}function s(n){return Math.abs(n)}function a(n){return Math.sign(n)}function l(n,t){return s(n-t)}function d(n){return m(n).map(Number)}function f(n){return n[p(n)]}function p(n){return Math.max(0,n.length-1)}function m(n){return Object.keys(n)}function g(n,t){return[n,t].reduce(((n,t)=>(m(t).forEach((e=>{const r=n[e],o=t[e],i=u(r)&&u(o);n[e]=i?g(r,o):o})),n)),{})}function h(n,t){return void 0!==t.MouseEvent&&n instanceof t.MouseEvent}function y(n,t){const e={start:function(){return 0},center:function(n){return r(n)/2},end:r};function r(n){return t-n}return{measure:function(r){return o(n)?t*Number(n):e[n](r)}}}function x(n,t){const e=s(n-t);function r(t){return t<n}function o(n){return n>t}function i(n){return r(n)||o(n)}return{length:e,max:t,min:n,constrain:function(e){return i(e)?r(e)?n:t:e},reachedAny:i,reachedMax:o,reachedMin:r,removeOffset:function(n){return e?n-e*Math.ceil((n-t)/e):n}}}function b(n,t,e){const{constrain:r}=x(0,n),o=n+1;let i=c(t);function c(n){return e?s((o+n)%o):r(n)}function u(){return i}function a(){return b(n,u(),e)}const l={get:u,set:function(n){return i=c(n),l},add:function(n){return a().set(u()+n)},clone:a};return l}function v(){let n=[];const t={add:function(e,r,o,i={passive:!0}){return e.addEventListener(r,o,i),n.push((()=>e.removeEventListener(r,o,i))),t},clear:function(){n=n.filter((n=>n()))}};return t}function S(n,t,e,r,o,i,u,d,f,p,m,g,y,b,S,w,E,O,D){const{cross:k}=n,A=["INPUT","SELECT","TEXTAREA"],M={passive:!1},I=v(),P=v(),T=x(50,225).constrain(S.measure(20)),z={mouse:300,touch:400},B={mouse:500,touch:600},F=w?43:25;let L=!1,R=0,j=0,H=!1,N=!1,C=!1,V=!1;function q(n){const e=u.readPoint(n),r=u.readPoint(n,k),o=l(e,R),c=l(r,j);if(!N&&!V){if(!n.cancelable)return $(n);if(N=o>c,!N)return $(n)}const s=u.pointerMove(n);o>E&&(C=!0),m.useFriction(.3).useDuration(1),f.start(),i.add(t.apply(s)),n.preventDefault()}function $(n){const e=g.byDistance(0,!1).index!==y.get(),r=u.pointerUp(n)*(w?B:z)[V?"mouse":"touch"],o=function(n,t){const e=y.add(-1*a(n)),r=g.byDistance(n,!w).distance;return w||s(n)<T?r:O&&t?.5*r:g.byIndex(e.get(),0).distance}(t.apply(r),e),i=function(n,t){if(0===n||0===t)return 0;if(s(n)<=s(t))return 0;const e=l(s(n),s(t));return s(e/n)}(r,o),c=F-10*i,d=D+i/50;N=!1,H=!1,P.clear(),m.useDuration(c).useFriction(d),p.distance(o,!w),V=!1,b.emit("pointerUp")}function U(n){C&&(n.stopPropagation(),n.preventDefault())}return{init:function(n,t){if(!t)return;function s(s){(c(t)||t(n,s))&&function(n){const t=h(n,o);if(V=t,t&&0!==n.button)return;if(function(n){const t=n.nodeName||"";return A.includes(t)}(n.target))return;C=w&&t&&!n.buttons&&L,L=l(i.get(),d.get())>=2,H=!0,u.pointerDown(n),m.useFriction(0).useDuration(0),i.set(d),function(){const n=V?r:e;P.add(n,"touchmove",q,M).add(n,"touchend",$).add(n,"mousemove",q,M).add(n,"mouseup",$)}(),R=u.readPoint(n),j=u.readPoint(n,k),b.emit("pointerDown")}(s)}const a=e;I.add(a,"dragstart",(n=>n.preventDefault()),M).add(a,"touchmove",(()=>{}),M).add(a,"touchend",(()=>{})).add(a,"touchstart",s).add(a,"mousedown",s).add(a,"touchcancel",$).add(a,"contextmenu",$).add(a,"click",U,!0)},pointerDown:function(){return H},destroy:function(){I.clear(),P.clear()}}}function w(n,t){let e,r;function o(n){return n.timeStamp}function i(e,r){const o="client"+("x"===(r||n.scroll)?"X":"Y");return(h(e,t)?e:e.touches[0])[o]}return{pointerDown:function(n){return e=n,r=n,i(n)},pointerMove:function(n){const t=i(n)-i(r),c=o(n)-o(e)>170;return r=n,c&&(e=n),t},pointerUp:function(n){if(!e||!r)return 0;const t=i(r)-i(e),c=o(n)-o(e),u=o(n)-o(r)>170,a=t/c;return c&&!u&&s(a)>.1?a:0},readPoint:i}}function E(n,t,e,r){let o,i,u=[],s=!1;function a(n){return e.measureSize(n.getBoundingClientRect())}return{init:function(e,l){if(!l)return;i=a(n),u=t.map(a),o=new ResizeObserver((o=>{s||(c(l)||l(e,o))&&function(o){for(const c of o){const o=c.target===n,s=t.indexOf(c.target);if((o?i:u[s])!==a(o?n:t[s])){e.reInit(),r.emit("resize");break}}}(o)})),[n].concat(t).forEach((n=>o.observe(n)))},destroy:function(){o&&o.disconnect(),s=!0}}}function O(n,t,e,r,o){const i=o.measure(10),c=o.measure(50),u=x(.1,.99);let a=!1;return{constrain:function(o){if(a||!n.reachedAny(e.get())||!n.reachedAny(t.get()))return;const l=n.reachedMin(t.get())?"min":"max",d=s(n[l]-t.get()),f=e.get()-t.get(),p=u.constrain(d/c);e.subtract(f*p),!o&&s(f)<i&&(e.set(n.constrain(e.get())),r.useDuration(25).useBaseFriction())},toggleActive:function(n){a=!n}}}function D(n,t,e,r){const o=x(-t+n,e[0]),i=e.map(o.constrain).map((n=>parseFloat(n.toFixed(3))));return{snapsContained:function(){if(t<=n)return[o.max];if("keepSnaps"===r)return i;const{min:e,max:c}=function(){const n=i[0],t=f(i),e=i.lastIndexOf(n),r=i.indexOf(t)+1;return x(e,r)}();return i.slice(e,c)}()}}function k(n,t,e,r){const o=t.min+.1,i=t.max+.1,{reachedMin:c,reachedMax:u}=x(o,i);return{loop:function(t){if(!function(n){return 1===n?u(e.get()):-1===n&&c(e.get())}(t))return;const o=n*(-1*t);r.forEach((n=>n.add(o)))}}}function A(n){const{max:t,length:e}=n;return{get:function(n){return(n-t)/-e}}}function M(n,t,e,r,o){const{reachedAny:i,removeOffset:c,constrain:u}=r;function l(n){return n.concat().sort(((n,t)=>s(n)-s(t)))[0]}function d(t,r){const o=[t,t+e,t-e];if(!n)return o[0];if(!r)return l(o);return l(o.filter((n=>a(n)===r)))}return{byDistance:function(e,r){const a=o.get()+e,{index:l,distance:f}=function(e){const r=n?c(e):u(e),o=t.map((n=>n-r)).map((n=>d(n,0))).map(((n,t)=>({diff:n,index:t}))).sort(((n,t)=>s(n.diff)-s(t.diff))),{index:i}=o[0];return{index:i,distance:r}}(a),p=!n&&i(a);return!r||p?{index:l,distance:e}:{index:l,distance:e+d(t[l]-f,0)}},byIndex:function(n,e){return{index:n,distance:d(t[n]-o.get(),e)}},shortcut:d}}function I(n){let t=n;function e(n){return o(n)?n:n.get()}return{get:function(){return t},set:function(n){t=e(n)},add:function(n){t+=e(n)},subtract:function(n){t-=e(n)}}}function P(n,t,e){const r="x"===n.scroll?function(n){return`translate3d(${n}px,0px,0px)`}:function(n){return`translate3d(0px,${n}px,0px)`},o=e.style;let i=!1;return{clear:function(){i||(o.transform="",e.getAttribute("style")||e.removeAttribute("style"))},to:function(n){i||(o.transform=r(t.apply(n)))},toggleActive:function(n){i=!n}}}function T(n,t,e,r,o,i,c,u,s){const a=d(o),l=d(o).reverse(),f=function(){const n=i[0]-1;return g(m(l,n),"end")}().concat(function(){const n=e-i[0]-1;return g(m(a,n),"start")}());function p(n,t){return n.reduce(((n,t)=>n-o[t]),t)}function m(n,t){return n.reduce(((n,e)=>p(n,t)>0?n.concat([e]):n),[])}function g(e,o){const i="start"===o,a=i?-r:r,l=c.findSlideBounds([a]);return e.map((e=>{const o=i?0:-r,c=i?r:0,a=l.filter((n=>n.index===e))[0][i?"end":"start"],d=I(-1),f=P(n,t,s[e]);return{index:e,location:d,translate:f,target:()=>u.get()>a?o:c}}))}return{canLoop:function(){return f.every((({index:n})=>p(a.filter((t=>t!==n)),e)<=.1))},clear:function(){f.forEach((n=>n.translate.clear()))},loop:function(){f.forEach((n=>{const{target:t,translate:e,location:r}=n,o=t();o!==r.get()&&(e.to(o),r.set(o))}))},loopPoints:f}}function z(n,t){let e,r=!1;return{init:function(o,i){i&&(e=new MutationObserver((n=>{r||(c(i)||i(o,n))&&function(n){for(const e of n)if("childList"===e.type){o.reInit(),t.emit("slidesChanged");break}}(n)})),e.observe(n,{childList:!0}))},destroy:function(){e&&e.disconnect(),r=!0}}}function B(n,t,e,r,o,i,c){const{removeOffset:u,constrain:s}=o,a=i?[0,t,-t]:[0],l=d(a,c);function d(t,o){const i=t||a,c=function(n){const t=n||0;return e.map((n=>x(.5,n-.5).constrain(n*t)))}(o);return i.reduce(((t,o)=>{const i=r.map(((t,r)=>({start:t-e[r]+c[r]+o,end:t+n-c[r]+o,index:r})));return t.concat(i)}),[])}return{check:function(n,t){const e=i?u(n):s(n);return(t||l).reduce(((n,t)=>{const{index:r,start:o,end:i}=t;return!n.includes(r)&&(o<e&&i>e)?n.concat([r]):n}),[])},findSlideBounds:d}}function F(n,t,e){const r=o(e);return{groupSlides:function(o){return r?function(n,t){return d(n).filter((n=>n%t==0)).map((e=>n.slice(e,e+t)))}(o,e):function(e){return d(e).reduce(((e,r)=>{const o=t.slice(f(e),r+1).reduce(((n,t)=>n+t),0);return!r||o>n?e.concat(r):e}),[]).map(((n,t,r)=>e.slice(n,r[t+1])))}(o)}}}function L(n,t,e,r,o,i,c,u){const{align:l,axis:m,direction:g,startIndex:h,inViewThreshold:L,loop:R,duration:j,dragFree:H,dragThreshold:N,slidesToScroll:C,skipSnaps:V,containScroll:q}=i,$=t.getBoundingClientRect(),U=e.map((n=>n.getBoundingClientRect())),W=function(n){const t="rtl"===n?-1:1;return{apply:function(n){return n*t}}}(g),G=function(n,t){const e="y"===n?"y":"x";return{scroll:e,cross:"y"===n?"x":"y",startEdge:"y"===e?"top":"rtl"===t?"right":"left",endEdge:"y"===e?"bottom":"rtl"===t?"left":"right",measureSize:function(n){const{width:t,height:r}=n;return"x"===e?t:r}}}(m,g),J=G.measureSize($),Q=function(n){return{measure:function(t){return n*(t/100)}}}(J),X=y(l,J),Y=!R&&!!q,K=R||!!q,{slideSizes:Z,slideSizesWithGaps:_}=function(n,t,e,r,o,i){const{measureSize:c,startEdge:u,endEdge:a}=n,l=e[0]&&o,d=function(){if(!l)return 0;const n=e[0];return s(t[u]-n[u])}(),m=function(){if(!l)return 0;const n=i.getComputedStyle(f(r));return parseFloat(n.getPropertyValue(`margin-${a}`))}(),g=e.map(c),h=e.map(((n,t,e)=>{const r=!t,o=t===p(e);return r?g[t]+d:o?g[t]+m:e[t+1][u]-n[u]})).map(s);return{slideSizes:g,slideSizesWithGaps:h}}(G,$,U,e,K,o),nn=F(J,_,C),{snaps:tn,snapsAligned:en}=function(n,t,e,r,o,i,c){const{startEdge:u,endEdge:a}=n,{groupSlides:l}=i,d=l(r).map((n=>f(n)[a]-n[0][u])).map(s).map(t.measure),m=r.map((n=>e[u]-n[u])).map((n=>-s(n))),g=function(){const n=f(m)-f(o);return l(m).map((n=>n[0])).map(((t,e,r)=>{const o=!e,i=e===p(r);return c&&o?0:c&&i?n:t+d[e]}))}();return{snaps:m,snapsAligned:g}}(G,X,$,U,_,nn,Y),rn=-f(tn)+f(_),{snapsContained:on}=D(J,rn,en,q),cn=Y?on:en,{limit:un}=function(n,t,e){const r=t[0];return{limit:x(e?r-n:f(t),r)}}(rn,cn,R),sn=b(p(cn),h,R),an=sn.clone(),ln=d(e),dn={update:()=>(({dragHandler:n,scrollBody:t,scrollBounds:e,scrollLooper:r,slideLooper:o,eventHandler:i,animation:c,options:{loop:u}})=>{const s=n.pointerDown();u||e.constrain(s);const a=t.seek().settled();a&&!s&&(c.stop(),i.emit("settle")),a||i.emit("scroll"),u&&(r.loop(t.direction()),o.loop())})(bn),render:n=>(({scrollBody:n,translate:t,location:e},r)=>{const o=n.velocity(),i=e.get()-o+o*r;t.to(i)})(bn,n),start:()=>u.start(bn),stop:()=>u.stop(bn)},fn=cn[sn.get()],pn=I(fn),mn=I(fn),gn=function(n,t,e,r){let o=!0,i=0,c=0,u=e,l=r;function d(n){return u=n,p}function f(n){return l=n,p}const p={direction:function(){return c},seek:function(){const e=t.get()-n.get();return l&&u?(i+=e/u,i*=l,n.add(i)):(i=0,n.set(t)),c=a(i||e),o=s(e)<.001,p},settled:function(){return o&&n.set(t),o},useBaseFriction:function(){return f(r)},useBaseDuration:function(){return d(e)},useFriction:f,useDuration:d,velocity:function(){return i}};return p}(pn,mn,j,.68),hn=M(R,cn,rn,un,mn),yn=function(n,t,e,r,o,i){function c(r){const c=r.distance,u=r.index!==t.get();c&&(n.start(),o.add(c)),u&&(e.set(t.get()),t.set(r.index),i.emit("select"))}return{distance:function(n,t){c(r.byDistance(n,t))},index:function(n,e){const o=t.clone().set(n);c(r.byIndex(o.get(),e))}}}(dn,sn,an,hn,mn,c),xn=B(J,rn,Z,tn,un,R,L),bn={ownerDocument:r,ownerWindow:o,eventHandler:c,containerRect:$,slideRects:U,animation:dn,axis:G,direction:W,dragHandler:S(G,W,n,r,o,mn,w(G,o),pn,dn,yn,gn,hn,sn,c,Q,H,N,V,.68),eventStore:v(),percentOfView:Q,index:sn,indexPrevious:an,limit:un,location:pn,options:i,resizeHandler:E(t,e,G,c),scrollBody:gn,scrollBounds:O(un,pn,mn,gn,Q),scrollLooper:k(rn,un,pn,[pn,mn]),scrollProgress:A(un),scrollSnaps:cn,scrollTarget:hn,scrollTo:yn,slideLooper:T(G,W,J,rn,_,cn,xn,pn,e),slidesHandler:z(t,c),slidesInView:xn,slideIndexes:ln,slidesToScroll:nn,target:mn,translate:P(G,W,t)};return bn}const R={align:"center",axis:"x",container:null,slides:null,containScroll:null,direction:"ltr",slidesToScroll:1,breakpoints:{},dragFree:!1,dragThreshold:10,inViewThreshold:0,loop:!1,skipSnaps:!1,duration:25,startIndex:0,active:!0,watchDrag:!0,watchResize:!0,watchSlides:!0};function j(n){function t(n,t){return g(n,t||{})}const e={mergeOptions:t,optionsAtMedia:function(e){const r=e.breakpoints||{},o=m(r).filter((t=>n.matchMedia(t).matches)).map((n=>r[n])).reduce(((n,e)=>t(n,e)),{});return t(e,o)},optionsMediaQueries:function(t){return t.map((n=>m(n.breakpoints||{}))).reduce(((n,t)=>n.concat(t)),[]).map(n.matchMedia)}};return e}function H(n,t,e){const r=n.ownerDocument,o=r.defaultView,c=j(o),u=function(n){let t=[];return{init:function(e,r){return t=e.filter((({options:t})=>!1!==n.optionsAtMedia(t).active)),t.forEach((t=>t.init(r,n))),e.reduce(((n,t)=>Object.assign(n,{[t.name]:t})),{})},destroy:function(){t=t.filter((n=>n.destroy()))}}}(c),a=v(),l=v(),d=function(){const n={};let t;function e(t){return n[t]||[]}const r={init:function(n){t=n},emit:function(n){return e(n).forEach((e=>e(t,n))),r},off:function(t,o){return n[t]=e(t).filter((n=>n!==o)),r},on:function(t,o){return n[t]=e(t).concat([o]),r}};return r}(),{animationRealms:f}=H,{mergeOptions:p,optionsAtMedia:m,optionsMediaQueries:g}=c,{on:h,off:y,emit:x}=d,b=P;let S,w,E,O,D=!1,k=p(R,H.globalOptions),A=p(k),M=[];function I(t,e){if(D)return;const c=f.find((n=>n.window===o)),h=c||function(n){const t=1e3/60;let e=[],r=null,o=0,i=0;function c(u){r||(r=u);const a=u-r;for(r=u,o+=a;o>=t;)e.forEach((({animation:n})=>n.update())),o-=t;const l=s(o/t);e.forEach((({animation:n})=>n.render(l))),i&&n.requestAnimationFrame(c)}return{start:function(t){e.includes(t)||e.push(t),i||(i=n.requestAnimationFrame(c))},stop:function(t){e=e.filter((n=>n!==t)),e.length||(n.cancelAnimationFrame(i),r=null,o=0,i=0)},reset:function(){r=null,o=0},window:n}}(o);if(c||f.push(h),k=p(k,t),A=m(k),function(){const{container:t,slides:e}=A,r=i(t)?n.querySelector(t):t;E=r||n.children[0];const o=i(e)?E.querySelectorAll(e):e;O=[].slice.call(o||E.children)}(),S=L(n,E,O,r,o,A,d,h),!A.active)return T();if(S.translate.to(S.location.get()),M=e||M,w=u.init(M,N),g([k,...M.map((({options:n})=>n))]).forEach((n=>a.add(n,"change",P))),S.eventHandler.init(N),S.resizeHandler.init(N,A.watchResize),S.slidesHandler.init(N,A.watchSlides),l.add(r,"visibilitychange",(()=>{r.hidden&&h.reset()})),A.loop){if(!S.slideLooper.canLoop())return T(),I({loop:!1},e),void(k=p(k,{loop:!0}));S.slideLooper.loop()}E.offsetParent&&O.length&&S.dragHandler.init(N,A.watchDrag)}function P(n,t){const e=F();T(),I(p({startIndex:e},n),t),d.emit("reInit")}function T(){S.dragHandler.destroy(),S.animation.stop(),S.eventStore.clear(),S.translate.clear(),S.slideLooper.clear(),S.resizeHandler.destroy(),S.slidesHandler.destroy(),u.destroy(),a.clear(),l.clear()}function z(n){const t=S[n?"target":"location"].get(),e=A.loop?"removeOffset":"constrain";return S.slidesInView.check(S.limit[e](t))}function B(n,t,e){A.active&&!D&&(S.scrollBody.useBaseFriction().useDuration(t?0:A.duration),S.scrollTo.index(n,e||0))}function F(){return S.index.get()}const N={canScrollNext:function(){return S.index.add(1).get()!==F()},canScrollPrev:function(){return S.index.add(-1).get()!==F()},containerNode:function(){return E},internalEngine:function(){return S},destroy:function(){D||(D=!0,a.clear(),T(),d.emit("destroy"))},off:y,on:h,emit:x,plugins:function(){return w},previousScrollSnap:function(){return S.indexPrevious.get()},reInit:b,rootNode:function(){return n},scrollNext:function(n){B(S.index.add(1).get(),!0===n,-1)},scrollPrev:function(n){B(S.index.add(-1).get(),!0===n,1)},scrollProgress:function(){return S.scrollProgress.get(S.location.get())},scrollSnapList:function(){return S.scrollSnaps.map(S.scrollProgress.get)},scrollTo:B,selectedScrollSnap:F,slideNodes:function(){return O},slidesInView:z,slidesNotInView:function(n){const t=z(n);return S.slideIndexes.filter((n=>!t.includes(n)))}};return I(t,e),setTimeout((()=>d.emit("init")),0),N}function N(t={},o=[]){const i=n.useRef(t),c=n.useRef(o),[u,s]=n.useState(),[a,l]=n.useState(),d=n.useCallback((()=>{u&&u.reInit(i.current,c.current)}),[u]);return n.useEffect((()=>{if("undefined"!=typeof window&&window.document&&window.document.createElement&&a){H.globalOptions=N.globalOptions;const n=H(a,i.current,c.current);return s(n),()=>n.destroy()}s(void 0)}),[a,s]),n.useEffect((()=>{e(i.current,t)||(i.current=t,d())}),[t,d]),n.useEffect((()=>{(function(n,t){if(n.length!==t.length)return!1;const o=r(n),i=r(t);return o.every(((n,t)=>e(n,i[t])))})(c.current,o)||(c.current=o,d())}),[o,d]),[l,u]}return H.animationRealms=[],H.globalOptions=void 0,N.globalOptions=void 0,N})); | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):(n="undefined"!=typeof globalThis?globalThis:n||self).EmblaCarouselReact=t(n.React)}(this,(function(n){"use strict";function t(n){return function(n){return"[object Object]"===Object.prototype.toString.call(n)}(n)||Array.isArray(n)}function e(n,r){const o=Object.keys(n),i=Object.keys(r);if(o.length!==i.length)return!1;return JSON.stringify(Object.keys(n.breakpoints||{}))===JSON.stringify(Object.keys(r.breakpoints||{}))&&o.every((o=>{const i=n[o],c=r[o];return"function"==typeof i?`${i}`==`${c}`:t(i)&&t(c)?e(i,c):i===c}))}function r(n){return n.concat().sort(((n,t)=>n.name>t.name?1:-1)).map((n=>n.options))}function o(n){return"number"==typeof n}function i(n){return"string"==typeof n}function c(n){return"boolean"==typeof n}function u(n){return"[object Object]"===Object.prototype.toString.call(n)}function s(n){return Math.abs(n)}function a(n){return Math.sign(n)}function l(n,t){return s(n-t)}function d(n){return m(n).map(Number)}function f(n){return n[p(n)]}function p(n){return Math.max(0,n.length-1)}function m(n){return Object.keys(n)}function g(n,t){return[n,t].reduce(((n,t)=>(m(t).forEach((e=>{const r=n[e],o=t[e],i=u(r)&&u(o);n[e]=i?g(r,o):o})),n)),{})}function h(n,t){return void 0!==t.MouseEvent&&n instanceof t.MouseEvent}function y(n,t){const e={start:function(){return 0},center:function(n){return r(n)/2},end:r};function r(n){return t-n}return{measure:function(r){return o(n)?t*Number(n):e[n](r)}}}function x(n,t){const e=s(n-t);function r(t){return t<n}function o(n){return n>t}function i(n){return r(n)||o(n)}return{length:e,max:t,min:n,constrain:function(e){return i(e)?r(e)?n:t:e},reachedAny:i,reachedMax:o,reachedMin:r,removeOffset:function(n){return e?n-e*Math.ceil((n-t)/e):n}}}function b(n,t,e){const{constrain:r}=x(0,n),o=n+1;let i=c(t);function c(n){return e?s((o+n)%o):r(n)}function u(){return i}function a(){return b(n,u(),e)}const l={get:u,set:function(n){return i=c(n),l},add:function(n){return a().set(u()+n)},clone:a};return l}function v(){let n=[];const t={add:function(e,r,o,i={passive:!0}){return e.addEventListener(r,o,i),n.push((()=>e.removeEventListener(r,o,i))),t},clear:function(){n=n.filter((n=>n()))}};return t}function S(n,t,e,r,o,i,u,d,f,p,m,g,y,b,S,w,E,O,D){const{cross:k}=n,A=["INPUT","SELECT","TEXTAREA"],M={passive:!1},I=v(),P=v(),T=x(50,225).constrain(S.measure(20)),z={mouse:300,touch:400},B={mouse:500,touch:600},F=w?43:25;let L=!1,R=0,j=0,H=!1,N=!1,C=!1,V=!1;function q(n){const e=u.readPoint(n),r=u.readPoint(n,k),o=l(e,R),c=l(r,j);if(!N&&!V){if(!n.cancelable)return $(n);if(N=o>c,!N)return $(n)}const s=u.pointerMove(n);o>E&&(C=!0),m.useFriction(.3).useDuration(1),f.start(),i.add(t.apply(s)),n.preventDefault()}function $(n){const e=g.byDistance(0,!1).index!==y.get(),r=u.pointerUp(n)*(w?B:z)[V?"mouse":"touch"],o=function(n,t){const e=y.add(-1*a(n)),r=g.byDistance(n,!w).distance;return w||s(n)<T?r:O&&t?.5*r:g.byIndex(e.get(),0).distance}(t.apply(r),e),i=function(n,t){if(0===n||0===t)return 0;if(s(n)<=s(t))return 0;const e=l(s(n),s(t));return s(e/n)}(r,o),c=F-10*i,d=D+i/50;N=!1,H=!1,P.clear(),m.useDuration(c).useFriction(d),p.distance(o,!w),V=!1,b.emit("pointerUp")}function U(n){C&&(n.stopPropagation(),n.preventDefault())}return{init:function(n,t){if(!t)return;function s(s){(c(t)||t(n,s))&&function(n){const t=h(n,o);if(V=t,t&&0!==n.button)return;if(function(n){const t=n.nodeName||"";return A.includes(t)}(n.target))return;C=w&&t&&!n.buttons&&L,L=l(i.get(),d.get())>=2,H=!0,u.pointerDown(n),m.useFriction(0).useDuration(0),i.set(d),function(){const n=V?r:e;P.add(n,"touchmove",q,M).add(n,"touchend",$).add(n,"mousemove",q,M).add(n,"mouseup",$)}(),R=u.readPoint(n),j=u.readPoint(n,k),b.emit("pointerDown")}(s)}const a=e;I.add(a,"dragstart",(n=>n.preventDefault()),M).add(a,"touchmove",(()=>{}),M).add(a,"touchend",(()=>{})).add(a,"touchstart",s).add(a,"mousedown",s).add(a,"touchcancel",$).add(a,"contextmenu",$).add(a,"click",U,!0)},pointerDown:function(){return H},destroy:function(){I.clear(),P.clear()}}}function w(n,t){let e,r;function o(n){return n.timeStamp}function i(e,r){const o="client"+("x"===(r||n.scroll)?"X":"Y");return(h(e,t)?e:e.touches[0])[o]}return{pointerDown:function(n){return e=n,r=n,i(n)},pointerMove:function(n){const t=i(n)-i(r),c=o(n)-o(e)>170;return r=n,c&&(e=n),t},pointerUp:function(n){if(!e||!r)return 0;const t=i(r)-i(e),c=o(n)-o(e),u=o(n)-o(r)>170,a=t/c;return c&&!u&&s(a)>.1?a:0},readPoint:i}}function E(n,t,e,r){let o,i,u=[],s=!1;function a(n){return e.measureSize(n.getBoundingClientRect())}return{init:function(e,l){if(!l)return;i=a(n),u=t.map(a),o=new ResizeObserver((o=>{s||(c(l)||l(e,o))&&function(o){for(const c of o){const o=c.target===n,s=t.indexOf(c.target);if((o?i:u[s])!==a(o?n:t[s])){e.reInit(),r.emit("resize");break}}}(o)})),[n].concat(t).forEach((n=>o.observe(n)))},destroy:function(){o&&o.disconnect(),s=!0}}}function O(n,t,e,r,o){const i=o.measure(10),c=o.measure(50),u=x(.1,.99);let a=!1;return{constrain:function(o){if(a||!n.reachedAny(e.get())||!n.reachedAny(t.get()))return;const l=n.reachedMin(t.get())?"min":"max",d=s(n[l]-t.get()),f=e.get()-t.get(),p=u.constrain(d/c);e.subtract(f*p),!o&&s(f)<i&&(e.set(n.constrain(e.get())),r.useDuration(25).useBaseFriction())},toggleActive:function(n){a=!n}}}function D(n,t,e,r){const o=x(-t+n,e[0]),i=e.map(o.constrain).map((n=>parseFloat(n.toFixed(3))));return{snapsContained:function(){if(t<=n)return[o.max];if("keepSnaps"===r)return i;const{min:e,max:c}=function(){const n=i[0],t=f(i),e=i.lastIndexOf(n),r=i.indexOf(t)+1;return x(e,r)}();return i.slice(e,c)}()}}function k(n,t,e,r){const o=t.min+.1,i=t.max+.1,{reachedMin:c,reachedMax:u}=x(o,i);return{loop:function(t){if(!function(n){return 1===n?u(e.get()):-1===n&&c(e.get())}(t))return;const o=n*(-1*t);r.forEach((n=>n.add(o)))}}}function A(n){const{max:t,length:e}=n;return{get:function(n){return(n-t)/-e}}}function M(n,t,e,r,o){const{reachedAny:i,removeOffset:c,constrain:u}=r;function l(n){return n.concat().sort(((n,t)=>s(n)-s(t)))[0]}function d(t,r){const o=[t,t+e,t-e];if(!n)return o[0];if(!r)return l(o);return l(o.filter((n=>a(n)===r)))}return{byDistance:function(e,r){const a=o.get()+e,{index:l,distance:f}=function(e){const r=n?c(e):u(e),o=t.map((n=>n-r)).map((n=>d(n,0))).map(((n,t)=>({diff:n,index:t}))).sort(((n,t)=>s(n.diff)-s(t.diff))),{index:i}=o[0];return{index:i,distance:r}}(a),p=!n&&i(a);return!r||p?{index:l,distance:e}:{index:l,distance:e+d(t[l]-f,0)}},byIndex:function(n,e){return{index:n,distance:d(t[n]-o.get(),e)}},shortcut:d}}function I(n){let t=n;function e(n){return o(n)?n:n.get()}return{get:function(){return t},set:function(n){t=e(n)},add:function(n){t+=e(n)},subtract:function(n){t-=e(n)}}}function P(n,t,e){const r="x"===n.scroll?function(n){return`translate3d(${n}px,0px,0px)`}:function(n){return`translate3d(0px,${n}px,0px)`},o=e.style;let i=!1;return{clear:function(){i||(o.transform="",e.getAttribute("style")||e.removeAttribute("style"))},to:function(n){i||(o.transform=r(t.apply(n)))},toggleActive:function(n){i=!n}}}function T(n,t,e,r,o,i,c,u,s){const a=d(o),l=d(o).reverse(),f=function(){const n=i[0]-1;return g(m(l,n),"end")}().concat(function(){const n=e-i[0]-1;return g(m(a,n),"start")}());function p(n,t){return n.reduce(((n,t)=>n-o[t]),t)}function m(n,t){return n.reduce(((n,e)=>p(n,t)>0?n.concat([e]):n),[])}function g(e,o){const i="start"===o,a=i?-r:r,l=c.findSlideBounds([a]);return e.map((e=>{const o=i?0:-r,c=i?r:0,a=l.filter((n=>n.index===e))[0][i?"end":"start"],d=I(-1),f=P(n,t,s[e]);return{index:e,location:d,translate:f,target:()=>u.get()>a?o:c}}))}return{canLoop:function(){return f.every((({index:n})=>p(a.filter((t=>t!==n)),e)<=.1))},clear:function(){f.forEach((n=>n.translate.clear()))},loop:function(){f.forEach((n=>{const{target:t,translate:e,location:r}=n,o=t();o!==r.get()&&(e.to(o),r.set(o))}))},loopPoints:f}}function z(n,t){let e,r=!1;return{init:function(o,i){i&&(e=new MutationObserver((n=>{r||(c(i)||i(o,n))&&function(n){for(const e of n)if("childList"===e.type){o.reInit(),t.emit("slidesChanged");break}}(n)})),e.observe(n,{childList:!0}))},destroy:function(){e&&e.disconnect(),r=!0}}}function B(n,t,e,r,o,i,c){const{removeOffset:u,constrain:s}=o,a=i?[0,t,-t]:[0],l=d(a,c);function d(t,o){const i=t||a,c=function(n){const t=n||0;return e.map((n=>x(.5,n-.5).constrain(n*t)))}(o);return i.reduce(((t,o)=>{const i=r.map(((t,r)=>({start:t-e[r]+c[r]+o,end:t+n-c[r]+o,index:r})));return t.concat(i)}),[])}return{check:function(n,t){const e=i?u(n):s(n);return(t||l).reduce(((n,t)=>{const{index:r,start:o,end:i}=t;return!n.includes(r)&&(o<e&&i>e)?n.concat([r]):n}),[])},findSlideBounds:d}}function F(n,t,e){const r=o(e);return{groupSlides:function(o){return r?function(n,t){return d(n).filter((n=>n%t==0)).map((e=>n.slice(e,e+t)))}(o,e):function(e){return d(e).reduce(((e,r)=>{const o=t.slice(f(e),r+1).reduce(((n,t)=>n+t),0);return!r||o>n?e.concat(r):e}),[]).map(((n,t,r)=>e.slice(n,r[t+1])))}(o)}}}function L(n,t,e,r,o,i,c,u){const{align:l,axis:m,direction:g,startIndex:h,inViewThreshold:L,loop:R,duration:j,dragFree:H,dragThreshold:N,slidesToScroll:C,skipSnaps:V,containScroll:q}=i,$=t.getBoundingClientRect(),U=e.map((n=>n.getBoundingClientRect())),W=function(n){const t="rtl"===n?-1:1;return{apply:function(n){return n*t}}}(g),G=function(n,t){const e="y"===n?"y":"x";return{scroll:e,cross:"y"===n?"x":"y",startEdge:"y"===e?"top":"rtl"===t?"right":"left",endEdge:"y"===e?"bottom":"rtl"===t?"left":"right",measureSize:function(n){const{width:t,height:r}=n;return"x"===e?t:r}}}(m,g),J=G.measureSize($),Q=function(n){return{measure:function(t){return n*(t/100)}}}(J),X=y(l,J),Y=!R&&!!q,K=R||!!q,{slideSizes:Z,slideSizesWithGaps:_}=function(n,t,e,r,o,i){const{measureSize:c,startEdge:u,endEdge:a}=n,l=e[0]&&o,d=function(){if(!l)return 0;const n=e[0];return s(t[u]-n[u])}(),m=function(){if(!l)return 0;const n=i.getComputedStyle(f(r));return parseFloat(n.getPropertyValue(`margin-${a}`))}(),g=e.map(c),h=e.map(((n,t,e)=>{const r=!t,o=t===p(e);return r?g[t]+d:o?g[t]+m:e[t+1][u]-n[u]})).map(s);return{slideSizes:g,slideSizesWithGaps:h}}(G,$,U,e,K,o),nn=F(J,_,C),{snaps:tn,snapsAligned:en}=function(n,t,e,r,o,i,c){const{startEdge:u,endEdge:a}=n,{groupSlides:l}=i,d=l(r).map((n=>f(n)[a]-n[0][u])).map(s).map(t.measure),m=r.map((n=>e[u]-n[u])).map((n=>-s(n))),g=function(){const n=f(m)-f(o);return l(m).map((n=>n[0])).map(((t,e,r)=>{const o=!e,i=e===p(r);return c&&o?0:c&&i?n:t+d[e]}))}();return{snaps:m,snapsAligned:g}}(G,X,$,U,_,nn,Y),rn=-f(tn)+f(_),{snapsContained:on}=D(J,rn,en,q),cn=Y?on:en,{limit:un}=function(n,t,e){const r=t[0];return{limit:x(e?r-n:f(t),r)}}(rn,cn,R),sn=b(p(cn),h,R),an=sn.clone(),ln=d(e),dn={update:()=>(({dragHandler:n,scrollBody:t,scrollBounds:e,scrollLooper:r,slideLooper:o,eventHandler:i,animation:c,options:{loop:u}})=>{const s=n.pointerDown();u||e.constrain(s);const a=t.seek().settled();a&&!s&&(c.stop(),i.emit("settle")),a||i.emit("scroll"),u&&(r.loop(t.direction()),o.loop())})(bn),render:n=>(({scrollBody:n,translate:t,location:e},r)=>{const o=n.velocity(),i=e.get()-o+o*r;t.to(i)})(bn,n),start:()=>u.start(bn),stop:()=>u.stop(bn)},fn=cn[sn.get()],pn=I(fn),mn=I(fn),gn=function(n,t,e,r){let o=!0,i=0,c=0,u=e,l=r;function d(n){return u=n,p}function f(n){return l=n,p}const p={direction:function(){return c},seek:function(){const e=t.get()-n.get();return l&&u?(i+=e/u,i*=l,n.add(i)):(i=0,n.set(t)),c=a(i||e),o=s(e)<.001,p},settled:function(){return o&&n.set(t),o},useBaseFriction:function(){return f(r)},useBaseDuration:function(){return d(e)},useFriction:f,useDuration:d,velocity:function(){return i}};return p}(pn,mn,j,.68),hn=M(R,cn,rn,un,mn),yn=function(n,t,e,r,o,i){function c(r){const c=r.distance,u=r.index!==t.get();c&&(n.start(),o.add(c)),u&&(e.set(t.get()),t.set(r.index),i.emit("select"))}return{distance:function(n,t){c(r.byDistance(n,t))},index:function(n,e){const o=t.clone().set(n);c(r.byIndex(o.get(),e))}}}(dn,sn,an,hn,mn,c),xn=B(J,rn,Z,tn,un,R,L),bn={ownerDocument:r,ownerWindow:o,eventHandler:c,containerRect:$,slideRects:U,animation:dn,axis:G,direction:W,dragHandler:S(G,W,n,r,o,mn,w(G,o),pn,dn,yn,gn,hn,sn,c,Q,H,N,V,.68),eventStore:v(),percentOfView:Q,index:sn,indexPrevious:an,limit:un,location:pn,options:i,resizeHandler:E(t,e,G,c),scrollBody:gn,scrollBounds:O(un,pn,mn,gn,Q),scrollLooper:k(rn,un,pn,[pn,mn]),scrollProgress:A(un),scrollSnaps:cn,scrollTarget:hn,scrollTo:yn,slideLooper:T(G,W,J,rn,_,cn,xn,pn,e),slidesHandler:z(t,c),slidesInView:xn,slideIndexes:ln,slidesToScroll:nn,target:mn,translate:P(G,W,t)};return bn}const R={align:"center",axis:"x",container:null,slides:null,containScroll:null,direction:"ltr",slidesToScroll:1,breakpoints:{},dragFree:!1,dragThreshold:10,inViewThreshold:0,loop:!1,skipSnaps:!1,duration:25,startIndex:0,active:!0,watchDrag:!0,watchResize:!0,watchSlides:!0};function j(n){function t(n,t){return g(n,t||{})}const e={mergeOptions:t,optionsAtMedia:function(e){const r=e.breakpoints||{},o=m(r).filter((t=>n.matchMedia(t).matches)).map((n=>r[n])).reduce(((n,e)=>t(n,e)),{});return t(e,o)},optionsMediaQueries:function(t){return t.map((n=>m(n.breakpoints||{}))).reduce(((n,t)=>n.concat(t)),[]).map(n.matchMedia)}};return e}function H(n,t,e){const r=n.ownerDocument,o=r.defaultView,c=j(o),u=function(n){let t=[];return{init:function(e,r){return t=e.filter((({options:t})=>!1!==n.optionsAtMedia(t).active)),t.forEach((t=>t.init(r,n))),e.reduce(((n,t)=>Object.assign(n,{[t.name]:t})),{})},destroy:function(){t=t.filter((n=>n.destroy()))}}}(c),a=v(),l=v(),d=function(){const n={};let t;function e(t){return n[t]||[]}const r={init:function(n){t=n},emit:function(n){return e(n).forEach((e=>e(t,n))),r},off:function(t,o){return n[t]=e(t).filter((n=>n!==o)),r},on:function(t,o){return n[t]=e(t).concat([o]),r}};return r}(),{animationRealms:f}=H,{mergeOptions:p,optionsAtMedia:m,optionsMediaQueries:g}=c,{on:h,off:y,emit:x}=d,b=P;let S,w,E,O,D=!1,k=p(R,H.globalOptions),A=p(k),M=[];function I(t,e){if(D)return;const c=f.find((n=>n.window===o)),h=c||function(n){const t=1e3/60;let e=[],r=null,o=0,i=0;function c(u){r||(r=u);const a=u-r;for(r=u,o+=a;o>=t;)e.forEach((({animation:n})=>n.update())),o-=t;const l=s(o/t);e.forEach((({animation:n})=>n.render(l))),i&&n.requestAnimationFrame(c)}return{start:function(t){e.includes(t)||e.push(t),i||(i=n.requestAnimationFrame(c))},stop:function(t){e=e.filter((n=>n!==t)),e.length||(n.cancelAnimationFrame(i),r=null,o=0,i=0)},reset:function(){r=null,o=0},window:n}}(o);if(c||f.push(h),k=p(k,t),A=m(k),M=e||M,function(){const{container:t,slides:e}=A,r=i(t)?n.querySelector(t):t;E=r||n.children[0];const o=i(e)?E.querySelectorAll(e):e;O=[].slice.call(o||E.children)}(),S=L(n,E,O,r,o,A,d,h),g([k,...M.map((({options:n})=>n))]).forEach((n=>a.add(n,"change",P))),A.active){if(S.translate.to(S.location.get()),S.eventHandler.init(N),S.resizeHandler.init(N,A.watchResize),S.slidesHandler.init(N,A.watchSlides),l.add(r,"visibilitychange",(()=>{r.hidden&&h.reset()})),A.loop){if(!S.slideLooper.canLoop())return T(),I({loop:!1},e),void(k=p(k,{loop:!0}));S.slideLooper.loop()}E.offsetParent&&O.length&&S.dragHandler.init(N,A.watchDrag),w=u.init(M,N)}}function P(n,t){const e=F();T(),I(p({startIndex:e},n),t),d.emit("reInit")}function T(){S.dragHandler.destroy(),S.animation.stop(),S.eventStore.clear(),S.translate.clear(),S.slideLooper.clear(),S.resizeHandler.destroy(),S.slidesHandler.destroy(),u.destroy(),a.clear(),l.clear()}function z(n){const t=S[n?"target":"location"].get(),e=A.loop?"removeOffset":"constrain";return S.slidesInView.check(S.limit[e](t))}function B(n,t,e){A.active&&!D&&(S.scrollBody.useBaseFriction().useDuration(t?0:A.duration),S.scrollTo.index(n,e||0))}function F(){return S.index.get()}const N={canScrollNext:function(){return S.index.add(1).get()!==F()},canScrollPrev:function(){return S.index.add(-1).get()!==F()},containerNode:function(){return E},internalEngine:function(){return S},destroy:function(){D||(D=!0,a.clear(),T(),d.emit("destroy"))},off:y,on:h,emit:x,plugins:function(){return w},previousScrollSnap:function(){return S.indexPrevious.get()},reInit:b,rootNode:function(){return n},scrollNext:function(n){B(S.index.add(1).get(),!0===n,-1)},scrollPrev:function(n){B(S.index.add(-1).get(),!0===n,1)},scrollProgress:function(){return S.scrollProgress.get(S.location.get())},scrollSnapList:function(){return S.scrollSnaps.map(S.scrollProgress.get)},scrollTo:B,selectedScrollSnap:F,slideNodes:function(){return O},slidesInView:z,slidesNotInView:function(n){const t=z(n);return S.slideIndexes.filter((n=>!t.includes(n)))}};return I(t,e),setTimeout((()=>d.emit("init")),0),N}function N(t={},o=[]){const i=n.useRef(t),c=n.useRef(o),[u,s]=n.useState(),[a,l]=n.useState(),d=n.useCallback((()=>{u&&u.reInit(i.current,c.current)}),[u]);return n.useEffect((()=>{if("undefined"!=typeof window&&window.document&&window.document.createElement&&a){H.globalOptions=N.globalOptions;const n=H(a,i.current,c.current);return s(n),()=>n.destroy()}s(void 0)}),[a,s]),n.useEffect((()=>{e(i.current,t)||(i.current=t,d())}),[t,d]),n.useEffect((()=>{(function(n,t){if(n.length!==t.length)return!1;const o=r(n),i=r(t);return o.every(((n,t)=>e(n,i[t])))})(c.current,o)||(c.current=o,d())}),[o,d]),[l,u]}return H.animationRealms=[],H.globalOptions=void 0,N.globalOptions=void 0,N})); |
{ | ||
"name": "embla-carousel-react", | ||
"version": "8.0.0-rc05", | ||
"version": "8.0.0-rc06", | ||
"author": "David Jerleke", | ||
@@ -59,4 +59,4 @@ "description": "A lightweight carousel library with fluid motion and great swipe precision", | ||
"dependencies": { | ||
"embla-carousel": "8.0.0-rc05", | ||
"embla-carousel-reactive-utils": "8.0.0-rc05" | ||
"embla-carousel": "8.0.0-rc06", | ||
"embla-carousel-reactive-utils": "8.0.0-rc06" | ||
}, | ||
@@ -63,0 +63,0 @@ "peerDependencies": { |
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
25902
+ Addedembla-carousel@8.0.0-rc06(transitive)
+ Addedembla-carousel-reactive-utils@8.0.0-rc06(transitive)
- Removedembla-carousel@8.0.0-rc05(transitive)
- Removedembla-carousel-reactive-utils@8.0.0-rc05(transitive)
Updatedembla-carousel@8.0.0-rc06