embla-carousel
Advanced tools
Comparing version 5.0.1 to 6.0.0
@@ -7,2 +7,3 @@ import { AnimationType } from './Animation'; | ||
import { EventEmitterType } from './EventEmitter'; | ||
import { EventStoreType } from './EventStore'; | ||
import { LimitType } from './Limit'; | ||
@@ -18,3 +19,2 @@ import { OptionsType } from './Options'; | ||
import { SlideLooperType } from './SlideLooper'; | ||
import { SlideFocusType } from './SlideFocus'; | ||
import { SlidesInViewType } from './SlidesInView'; | ||
@@ -38,3 +38,3 @@ import { TranslateType } from './Translate'; | ||
dragHandler: DragHandlerType; | ||
slideFocus: SlideFocusType; | ||
eventStore: EventStoreType; | ||
slideLooper: SlideLooperType; | ||
@@ -41,0 +41,0 @@ slidesInView: SlidesInViewType; |
import { Engine } from './Engine'; | ||
import { EventEmitterType } from './EventEmitter'; | ||
import { EmblaOptionsType } from './Options'; | ||
export declare type EmblaNodesType = { | ||
root: HTMLElement; | ||
container?: HTMLElement; | ||
slides?: HTMLElement[]; | ||
}; | ||
declare type EmblaPluginOptionsType = { | ||
[key: string]: unknown; | ||
}; | ||
export declare type EmblaPluginType<OptionsType extends EmblaPluginOptionsType = EmblaPluginOptionsType> = { | ||
name: string; | ||
options: OptionsType; | ||
init: (embla: EmblaCarouselType) => void; | ||
destroy: () => void; | ||
}; | ||
export declare type EmblaCarouselType = { | ||
@@ -9,3 +23,3 @@ canScrollNext: () => boolean; | ||
containerNode: () => HTMLElement; | ||
dangerouslyGetEngine: () => Engine; | ||
internalEngine: () => Engine; | ||
destroy: () => void; | ||
@@ -27,3 +41,3 @@ off: EventEmitterType['off']; | ||
}; | ||
declare function EmblaCarousel(sliderRoot: HTMLElement, userOptions?: EmblaOptionsType): EmblaCarouselType; | ||
declare function EmblaCarousel<EmblaPluginsType extends EmblaPluginType>(nodes: HTMLElement | EmblaNodesType, userOptions?: EmblaOptionsType, userPlugins?: EmblaPluginsType[]): EmblaCarouselType; | ||
export default EmblaCarousel; |
@@ -12,8 +12,5 @@ import { AlignmentOptionType } from './Alignment'; | ||
draggable: boolean; | ||
draggableClass: string; | ||
draggingClass: string; | ||
inViewThreshold: number; | ||
loop: boolean; | ||
skipSnaps: boolean; | ||
selectedClass: string; | ||
slidesToScroll: number; | ||
@@ -20,0 +17,0 @@ speed: number; |
import { Vector1DType } from './Vector1d'; | ||
export declare type ScrollBodyType = { | ||
direction: () => number; | ||
seek: (v: Vector1DType) => ScrollBodyType; | ||
settle: (v: Vector1DType) => boolean; | ||
seek: (target: Vector1DType) => ScrollBodyType; | ||
settle: (target: Vector1DType) => boolean; | ||
update: () => void; | ||
@@ -7,0 +7,0 @@ useBaseMass: () => ScrollBodyType; |
@@ -11,3 +11,1 @@ export declare function map(value: number, iStart: number, iStop: number, oStart: number, oStop: number): number; | ||
export declare function lastIndex<GenericType>(array: GenericType[]): number; | ||
export declare function removeClass(node: HTMLElement, className: string): void; | ||
export declare function addClass(node: HTMLElement, className: string): void; |
@@ -1,19 +0,1 @@ | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function Alignment(align, viewSize) { | ||
@@ -330,10 +312,2 @@ var predefined = { | ||
} | ||
function removeClass(node, className) { | ||
var cl = node.classList; | ||
if (className && cl.contains(className)) cl.remove(className); | ||
} | ||
function addClass(node, className) { | ||
var cl = node.classList; | ||
if (className && !cl.contains(className)) cl.add(className); | ||
} | ||
@@ -585,9 +559,9 @@ function DragHandler(axis, direction, rootNode, target, dragFree, dragTracker, location, animation, scrollTo, scrollBody, scrollTarget, index, events, loop, skipSnaps) { | ||
function applyForce(v) { | ||
v.divide(mass); | ||
acceleration.add(v); | ||
function applyForce(force) { | ||
force.divide(mass); | ||
acceleration.add(force); | ||
} | ||
function seek(v) { | ||
attraction.set(v).subtract(location); | ||
function seek(target) { | ||
attraction.set(target).subtract(location); | ||
var magnitude = map(attraction.get(), 0, 100, 0, speed); | ||
@@ -600,6 +574,6 @@ attractionDirection = mathSign(attraction.get()); | ||
function settle(v) { | ||
var diff = v.get() - location.get(); | ||
function settle(target) { | ||
var diff = target.get() - location.get(); | ||
var hasSettled = !roundToTwoDecimals(diff); | ||
if (hasSettled) location.set(v); | ||
if (hasSettled) location.set(target); | ||
return hasSettled; | ||
@@ -1011,37 +985,2 @@ } | ||
function SlideFocus(rootNode, scrollTo, slidesToScroll) { | ||
var eventStore = EventStore(); | ||
var removeAllEvents = eventStore.removeAll; | ||
var lastTabPressTime = 0; | ||
function registerTabPress(event) { | ||
if (event.keyCode !== 9) return; | ||
lastTabPressTime = new Date().getTime(); | ||
} | ||
function addFocusEvent(slide, index) { | ||
var focus = function focus() { | ||
var nowTime = new Date().getTime(); | ||
var diffTime = nowTime - lastTabPressTime; | ||
if (diffTime > 10) return; | ||
rootNode.scrollLeft = 0; | ||
var selectedIndex = Math.floor(index / slidesToScroll); | ||
scrollTo.index(selectedIndex, 0); | ||
}; | ||
eventStore.add(slide, 'focus', focus, true); | ||
} | ||
function addActivationEvents(slides) { | ||
eventStore.add(document, 'keydown', registerTabPress, false); | ||
slides.forEach(addFocusEvent); | ||
} | ||
var self = { | ||
addActivationEvents: addActivationEvents, | ||
removeAllEvents: removeAllEvents | ||
}; | ||
return self; | ||
} | ||
function SlidesInView(viewSize, contentSize, slideSizes, snaps, loop, inViewThreshold) { | ||
@@ -1226,2 +1165,3 @@ var threshold = Math.min(Math.max(inViewThreshold, 0.01), 0.99); | ||
dragHandler: dragHandler, | ||
eventStore: EventStore(), | ||
pxToPercent: pxToPercent, | ||
@@ -1240,3 +1180,2 @@ index: index, | ||
scrollTo: scrollTo, | ||
slideFocus: SlideFocus(root, scrollTo, slidesToScroll), | ||
slideLooper: SlideLooper(axis, viewSize, contentSize, slideSizesWithGaps, scrollSnaps, slidesInView, location, slides), | ||
@@ -1255,4 +1194,3 @@ slidesInView: slidesInView, | ||
function getListeners(evt) { | ||
var eventListeners = listeners[evt]; | ||
return eventListeners || []; | ||
return listeners[evt] || []; | ||
} | ||
@@ -1294,8 +1232,5 @@ | ||
draggable: true, | ||
draggableClass: 'is-draggable', | ||
draggingClass: 'is-dragging', | ||
inViewThreshold: 0, | ||
loop: false, | ||
skipSnaps: true, | ||
selectedClass: 'is-selected', | ||
skipSnaps: false, | ||
slidesToScroll: 1, | ||
@@ -1324,5 +1259,4 @@ speed: 10, | ||
function EmblaCarousel(sliderRoot, userOptions) { | ||
function EmblaCarousel(nodes, userOptions, userPlugins) { | ||
var events = EventEmitter(); | ||
var eventStore = EventStore(); | ||
var debouncedResize = debounce(resize, 500); | ||
@@ -1334,30 +1268,32 @@ var reInit = reActivate; | ||
var activated = false; | ||
var optionsBase = _extends({}, defaultOptions); | ||
var options = _extends({}, optionsBase); | ||
var optionsBase = Object.assign({}, defaultOptions); | ||
var options = Object.assign({}, optionsBase); | ||
var optionsPseudo; | ||
var rootNodeSize = 0; | ||
var plugins; | ||
var rootSize = 0; | ||
var root; | ||
var container; | ||
var slides; | ||
activate(userOptions); | ||
function setupElements() { | ||
if (!sliderRoot) throw new Error('Missing root node 😢'); | ||
var sliderContainer = sliderRoot.querySelector('*'); | ||
if (!sliderContainer) throw new Error('Missing container node 😢'); | ||
container = sliderContainer; | ||
slides = Array.prototype.slice.call(container.children); | ||
optionsPseudo = OptionsPseudo(sliderRoot); | ||
var providedContainer = 'container' in nodes && nodes.container; | ||
var providedSlides = 'slides' in nodes && nodes.slides; | ||
root = 'root' in nodes ? nodes.root : nodes; | ||
container = providedContainer || root.children[0]; | ||
slides = providedSlides || [].slice.call(container.children); | ||
optionsPseudo = OptionsPseudo(root); | ||
} | ||
function activate(partialOptions) { | ||
function activate(withOptions, withPlugins) { | ||
setupElements(); | ||
optionsBase = _extends({}, optionsBase, partialOptions); | ||
options = _extends({}, optionsBase, optionsPseudo.get()); | ||
engine = Engine(sliderRoot, container, slides, options, events); | ||
eventStore.add(window, 'resize', debouncedResize); | ||
optionsBase = Object.assign({}, optionsBase, withOptions); | ||
options = Object.assign({}, optionsBase, optionsPseudo.get()); | ||
plugins = Object.assign([], withPlugins); | ||
engine = Engine(root, container, slides, options, events); | ||
engine.eventStore.add(window, 'resize', debouncedResize); | ||
engine.translate.to(engine.location); | ||
rootNodeSize = engine.axis.measureSize(sliderRoot.getBoundingClientRect()); | ||
rootSize = engine.axis.measureSize(root.getBoundingClientRect()); | ||
plugins.forEach(function (plugin) { | ||
return plugin.init(self); | ||
}); | ||
@@ -1369,3 +1305,3 @@ if (options.loop) { | ||
loop: false | ||
}); | ||
}, withPlugins); | ||
} | ||
@@ -1378,21 +1314,4 @@ | ||
engine.dragHandler.addActivationEvents(); | ||
if (options.draggableClass) { | ||
addClass(sliderRoot, options.draggableClass); | ||
} | ||
if (options.draggingClass) { | ||
events.on('pointerDown', toggleDraggingClass).on('pointerUp', toggleDraggingClass); | ||
} | ||
} | ||
if (slides.length) { | ||
engine.slideFocus.addActivationEvents(slides); | ||
} | ||
if (options.selectedClass) { | ||
toggleSelectedClass(); | ||
events.on('select', toggleSelectedClass).on('pointerUp', toggleSelectedClass); | ||
} | ||
if (!activated) { | ||
@@ -1406,46 +1325,24 @@ setTimeout(function () { | ||
function toggleDraggingClass(evt) { | ||
var draggingClass = options.draggingClass; | ||
if (evt === 'pointerDown') addClass(sliderRoot, draggingClass);else removeClass(sliderRoot, draggingClass); | ||
function reActivate(withOptions, withPlugins) { | ||
if (!activated) return; | ||
var startIndex = selectedScrollSnap(); | ||
var newOptions = Object.assign({ | ||
startIndex: startIndex | ||
}, withOptions); | ||
deActivate(); | ||
activate(newOptions, withPlugins || plugins); | ||
events.emit('reInit'); | ||
} | ||
function toggleSelectedClass() { | ||
var selectedClass = options.selectedClass; | ||
var inView = slidesInView(true); | ||
var notInView = slidesNotInView(true); | ||
notInView.forEach(function (index) { | ||
return removeClass(slides[index], selectedClass); | ||
}); | ||
inView.forEach(function (index) { | ||
return addClass(slides[index], selectedClass); | ||
}); | ||
} | ||
function deActivate() { | ||
engine.dragHandler.removeAllEvents(); | ||
engine.slideFocus.removeAllEvents(); | ||
engine.animation.stop(); | ||
eventStore.removeAll(); | ||
engine.eventStore.removeAll(); | ||
engine.translate.clear(); | ||
engine.slideLooper.clear(); | ||
removeClass(sliderRoot, options.draggableClass); | ||
slides.forEach(function (slide) { | ||
return removeClass(slide, options.selectedClass); | ||
plugins.forEach(function (plugin) { | ||
return plugin.destroy(); | ||
}); | ||
events.off('select', toggleSelectedClass).off('pointerUp', toggleSelectedClass).off('pointerDown', toggleDraggingClass).off('pointerUp', toggleDraggingClass); | ||
} | ||
function reActivate(partialOptions) { | ||
if (!activated) return; | ||
var startIndex = selectedScrollSnap(); | ||
var newOptions = _extends({ | ||
startIndex: startIndex | ||
}, partialOptions); | ||
deActivate(); | ||
activate(newOptions); | ||
events.emit('reInit'); | ||
} | ||
function destroy() { | ||
@@ -1460,4 +1357,4 @@ if (!activated) return; | ||
if (!activated) return; | ||
var size = engine.axis.measureSize(sliderRoot.getBoundingClientRect()); | ||
if (rootNodeSize !== size) reActivate(); | ||
var size = engine.axis.measureSize(root.getBoundingClientRect()); | ||
if (rootSize !== size) reActivate(); | ||
events.emit('resize'); | ||
@@ -1524,3 +1421,3 @@ } | ||
function dangerouslyGetEngine() { | ||
function internalEngine() { | ||
return engine; | ||
@@ -1530,3 +1427,3 @@ } | ||
function rootNode() { | ||
return sliderRoot; | ||
return root; | ||
} | ||
@@ -1547,3 +1444,3 @@ | ||
containerNode: containerNode, | ||
dangerouslyGetEngine: dangerouslyGetEngine, | ||
internalEngine: internalEngine, | ||
destroy: destroy, | ||
@@ -1565,2 +1462,3 @@ off: off, | ||
}; | ||
activate(userOptions, userPlugins); | ||
return self; | ||
@@ -1567,0 +1465,0 @@ } |
'use strict'; | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function Alignment(align, viewSize) { | ||
@@ -332,10 +314,2 @@ var predefined = { | ||
} | ||
function removeClass(node, className) { | ||
var cl = node.classList; | ||
if (className && cl.contains(className)) cl.remove(className); | ||
} | ||
function addClass(node, className) { | ||
var cl = node.classList; | ||
if (className && !cl.contains(className)) cl.add(className); | ||
} | ||
@@ -587,9 +561,9 @@ function DragHandler(axis, direction, rootNode, target, dragFree, dragTracker, location, animation, scrollTo, scrollBody, scrollTarget, index, events, loop, skipSnaps) { | ||
function applyForce(v) { | ||
v.divide(mass); | ||
acceleration.add(v); | ||
function applyForce(force) { | ||
force.divide(mass); | ||
acceleration.add(force); | ||
} | ||
function seek(v) { | ||
attraction.set(v).subtract(location); | ||
function seek(target) { | ||
attraction.set(target).subtract(location); | ||
var magnitude = map(attraction.get(), 0, 100, 0, speed); | ||
@@ -602,6 +576,6 @@ attractionDirection = mathSign(attraction.get()); | ||
function settle(v) { | ||
var diff = v.get() - location.get(); | ||
function settle(target) { | ||
var diff = target.get() - location.get(); | ||
var hasSettled = !roundToTwoDecimals(diff); | ||
if (hasSettled) location.set(v); | ||
if (hasSettled) location.set(target); | ||
return hasSettled; | ||
@@ -1013,37 +987,2 @@ } | ||
function SlideFocus(rootNode, scrollTo, slidesToScroll) { | ||
var eventStore = EventStore(); | ||
var removeAllEvents = eventStore.removeAll; | ||
var lastTabPressTime = 0; | ||
function registerTabPress(event) { | ||
if (event.keyCode !== 9) return; | ||
lastTabPressTime = new Date().getTime(); | ||
} | ||
function addFocusEvent(slide, index) { | ||
var focus = function focus() { | ||
var nowTime = new Date().getTime(); | ||
var diffTime = nowTime - lastTabPressTime; | ||
if (diffTime > 10) return; | ||
rootNode.scrollLeft = 0; | ||
var selectedIndex = Math.floor(index / slidesToScroll); | ||
scrollTo.index(selectedIndex, 0); | ||
}; | ||
eventStore.add(slide, 'focus', focus, true); | ||
} | ||
function addActivationEvents(slides) { | ||
eventStore.add(document, 'keydown', registerTabPress, false); | ||
slides.forEach(addFocusEvent); | ||
} | ||
var self = { | ||
addActivationEvents: addActivationEvents, | ||
removeAllEvents: removeAllEvents | ||
}; | ||
return self; | ||
} | ||
function SlidesInView(viewSize, contentSize, slideSizes, snaps, loop, inViewThreshold) { | ||
@@ -1228,2 +1167,3 @@ var threshold = Math.min(Math.max(inViewThreshold, 0.01), 0.99); | ||
dragHandler: dragHandler, | ||
eventStore: EventStore(), | ||
pxToPercent: pxToPercent, | ||
@@ -1242,3 +1182,2 @@ index: index, | ||
scrollTo: scrollTo, | ||
slideFocus: SlideFocus(root, scrollTo, slidesToScroll), | ||
slideLooper: SlideLooper(axis, viewSize, contentSize, slideSizesWithGaps, scrollSnaps, slidesInView, location, slides), | ||
@@ -1257,4 +1196,3 @@ slidesInView: slidesInView, | ||
function getListeners(evt) { | ||
var eventListeners = listeners[evt]; | ||
return eventListeners || []; | ||
return listeners[evt] || []; | ||
} | ||
@@ -1296,8 +1234,5 @@ | ||
draggable: true, | ||
draggableClass: 'is-draggable', | ||
draggingClass: 'is-dragging', | ||
inViewThreshold: 0, | ||
loop: false, | ||
skipSnaps: true, | ||
selectedClass: 'is-selected', | ||
skipSnaps: false, | ||
slidesToScroll: 1, | ||
@@ -1326,5 +1261,4 @@ speed: 10, | ||
function EmblaCarousel(sliderRoot, userOptions) { | ||
function EmblaCarousel(nodes, userOptions, userPlugins) { | ||
var events = EventEmitter(); | ||
var eventStore = EventStore(); | ||
var debouncedResize = debounce(resize, 500); | ||
@@ -1336,30 +1270,32 @@ var reInit = reActivate; | ||
var activated = false; | ||
var optionsBase = _extends({}, defaultOptions); | ||
var options = _extends({}, optionsBase); | ||
var optionsBase = Object.assign({}, defaultOptions); | ||
var options = Object.assign({}, optionsBase); | ||
var optionsPseudo; | ||
var rootNodeSize = 0; | ||
var plugins; | ||
var rootSize = 0; | ||
var root; | ||
var container; | ||
var slides; | ||
activate(userOptions); | ||
function setupElements() { | ||
if (!sliderRoot) throw new Error('Missing root node 😢'); | ||
var sliderContainer = sliderRoot.querySelector('*'); | ||
if (!sliderContainer) throw new Error('Missing container node 😢'); | ||
container = sliderContainer; | ||
slides = Array.prototype.slice.call(container.children); | ||
optionsPseudo = OptionsPseudo(sliderRoot); | ||
var providedContainer = 'container' in nodes && nodes.container; | ||
var providedSlides = 'slides' in nodes && nodes.slides; | ||
root = 'root' in nodes ? nodes.root : nodes; | ||
container = providedContainer || root.children[0]; | ||
slides = providedSlides || [].slice.call(container.children); | ||
optionsPseudo = OptionsPseudo(root); | ||
} | ||
function activate(partialOptions) { | ||
function activate(withOptions, withPlugins) { | ||
setupElements(); | ||
optionsBase = _extends({}, optionsBase, partialOptions); | ||
options = _extends({}, optionsBase, optionsPseudo.get()); | ||
engine = Engine(sliderRoot, container, slides, options, events); | ||
eventStore.add(window, 'resize', debouncedResize); | ||
optionsBase = Object.assign({}, optionsBase, withOptions); | ||
options = Object.assign({}, optionsBase, optionsPseudo.get()); | ||
plugins = Object.assign([], withPlugins); | ||
engine = Engine(root, container, slides, options, events); | ||
engine.eventStore.add(window, 'resize', debouncedResize); | ||
engine.translate.to(engine.location); | ||
rootNodeSize = engine.axis.measureSize(sliderRoot.getBoundingClientRect()); | ||
rootSize = engine.axis.measureSize(root.getBoundingClientRect()); | ||
plugins.forEach(function (plugin) { | ||
return plugin.init(self); | ||
}); | ||
@@ -1371,3 +1307,3 @@ if (options.loop) { | ||
loop: false | ||
}); | ||
}, withPlugins); | ||
} | ||
@@ -1380,21 +1316,4 @@ | ||
engine.dragHandler.addActivationEvents(); | ||
if (options.draggableClass) { | ||
addClass(sliderRoot, options.draggableClass); | ||
} | ||
if (options.draggingClass) { | ||
events.on('pointerDown', toggleDraggingClass).on('pointerUp', toggleDraggingClass); | ||
} | ||
} | ||
if (slides.length) { | ||
engine.slideFocus.addActivationEvents(slides); | ||
} | ||
if (options.selectedClass) { | ||
toggleSelectedClass(); | ||
events.on('select', toggleSelectedClass).on('pointerUp', toggleSelectedClass); | ||
} | ||
if (!activated) { | ||
@@ -1408,46 +1327,24 @@ setTimeout(function () { | ||
function toggleDraggingClass(evt) { | ||
var draggingClass = options.draggingClass; | ||
if (evt === 'pointerDown') addClass(sliderRoot, draggingClass);else removeClass(sliderRoot, draggingClass); | ||
function reActivate(withOptions, withPlugins) { | ||
if (!activated) return; | ||
var startIndex = selectedScrollSnap(); | ||
var newOptions = Object.assign({ | ||
startIndex: startIndex | ||
}, withOptions); | ||
deActivate(); | ||
activate(newOptions, withPlugins || plugins); | ||
events.emit('reInit'); | ||
} | ||
function toggleSelectedClass() { | ||
var selectedClass = options.selectedClass; | ||
var inView = slidesInView(true); | ||
var notInView = slidesNotInView(true); | ||
notInView.forEach(function (index) { | ||
return removeClass(slides[index], selectedClass); | ||
}); | ||
inView.forEach(function (index) { | ||
return addClass(slides[index], selectedClass); | ||
}); | ||
} | ||
function deActivate() { | ||
engine.dragHandler.removeAllEvents(); | ||
engine.slideFocus.removeAllEvents(); | ||
engine.animation.stop(); | ||
eventStore.removeAll(); | ||
engine.eventStore.removeAll(); | ||
engine.translate.clear(); | ||
engine.slideLooper.clear(); | ||
removeClass(sliderRoot, options.draggableClass); | ||
slides.forEach(function (slide) { | ||
return removeClass(slide, options.selectedClass); | ||
plugins.forEach(function (plugin) { | ||
return plugin.destroy(); | ||
}); | ||
events.off('select', toggleSelectedClass).off('pointerUp', toggleSelectedClass).off('pointerDown', toggleDraggingClass).off('pointerUp', toggleDraggingClass); | ||
} | ||
function reActivate(partialOptions) { | ||
if (!activated) return; | ||
var startIndex = selectedScrollSnap(); | ||
var newOptions = _extends({ | ||
startIndex: startIndex | ||
}, partialOptions); | ||
deActivate(); | ||
activate(newOptions); | ||
events.emit('reInit'); | ||
} | ||
function destroy() { | ||
@@ -1462,4 +1359,4 @@ if (!activated) return; | ||
if (!activated) return; | ||
var size = engine.axis.measureSize(sliderRoot.getBoundingClientRect()); | ||
if (rootNodeSize !== size) reActivate(); | ||
var size = engine.axis.measureSize(root.getBoundingClientRect()); | ||
if (rootSize !== size) reActivate(); | ||
events.emit('resize'); | ||
@@ -1526,3 +1423,3 @@ } | ||
function dangerouslyGetEngine() { | ||
function internalEngine() { | ||
return engine; | ||
@@ -1532,3 +1429,3 @@ } | ||
function rootNode() { | ||
return sliderRoot; | ||
return root; | ||
} | ||
@@ -1549,3 +1446,3 @@ | ||
containerNode: containerNode, | ||
dangerouslyGetEngine: dangerouslyGetEngine, | ||
internalEngine: internalEngine, | ||
destroy: destroy, | ||
@@ -1567,2 +1464,3 @@ off: off, | ||
}; | ||
activate(userOptions, userPlugins); | ||
return self; | ||
@@ -1569,0 +1467,0 @@ } |
@@ -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,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,max:e,min:n,reachedAny:i,reachedMax:o,reachedMin:r,removeOffset:function(n){return t?n-t*Math.ceil((n-e)/t):n}}}function r(n,e,o){var i=t(0,n),a=i.min,u=i.constrain,c=n+1,s=d(e);function d(n){return o?Math.abs((c+n)%c):u(n)}function f(){return s}function l(n){return s=d(n),p}var p={add:function(n){return l(f()+n)},clone:function(){return r(n,f(),o)},get:f,set:l,min:a,max:n};return p}function o(){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 i(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 a(n){return n?n/Math.abs(n):0}function u(n,e){return Math.abs(n-e)}function c(n,e){for(var t=[],r=0;r<n.length;r+=e)t.push(n.slice(r,r+e));return t}function s(n){return Object.keys(n).map(Number)}function d(n){return n[f(n)]}function f(n){return Math.max(0,n.length-1)}function l(n,e){var t=n.classList;e&&t.contains(e)&&t.remove(e)}function p(n,e){var t=n.classList;e&&!t.contains(e)&&t.add(e)}function g(n,e,t,r,c,s,d,f,l,p,g,m,v,h,x){var y=n.scroll,b=n.cross,w=["INPUT","SELECT","TEXTAREA"],M=i(0),S=i(0),E=i(0),A=o(),T=o(),C={mouse:2.5,touch:3.5},D={mouse:5,touch:7},P=c?5:16,B=!1,I=!1,L=!1,k=!1;function z(n){if(!(k="mousedown"===n.type)||0===n.button){var e,o,i=u(r.get(),d.get())>=2,a=k||!i,c=(e=n.target,o=e.nodeName||"",!(w.indexOf(o)>-1)),f=i||k&&c;B=!0,s.pointerDown(n),E.set(r),r.set(d),p.useBaseMass().useSpeed(80),function(){var n=k?document:t;T.add(n,"touchmove",O).add(n,"touchend",N).add(n,"mousemove",O).add(n,"mouseup",N)}(),M.set(s.readPoint(n,y)),S.set(s.readPoint(n,b)),v.emit("pointerDown"),a&&(L=!1),f&&n.preventDefault()}}function O(n){if(!I&&!k){if(!n.cancelable)return N();var t=s.readPoint(n,y).get(),o=s.readPoint(n,b).get(),i=u(t,M.get()),a=u(o,S.get());if(!(I=i>a)&&!L)return N()}var c=s.pointerMove(n);!L&&c&&(L=!0),f.start(),r.add(e.applyTo(c)),n.preventDefault()}function N(){var n=g.byDistance(0,!1).index!==m.get(),t=s.pointerUp()*(c?D:C)[k?"mouse":"touch"],o=function(n,e){var t=m.clone().add(-1*a(n)),r=t.get()===m.min||t.get()===m.max,o=g.byDistance(n,!c).distance;return c||Math.abs(n)<20?o:!h&&r?.6*o:x&&e?.5*o:g.byIndex(t.get(),0).distance}(e.applyTo(t),n),i=function(n,e){if(0===n||0===e)return 0;if(Math.abs(n)<=Math.abs(e))return 0;var t=u(Math.abs(n),Math.abs(e));return Math.abs(t/n)}(t,o),d=u(r.get(),E.get())>=.5,f=n&&i>.75,y=Math.abs(t)<20,b=f?10:P,w=f?1+2.5*i:1;d&&!k&&(L=!0),I=!1,B=!1,T.removeAll(),p.useSpeed(y?9:b).useMass(w),l.distance(o,!c),k=!1,v.emit("pointerUp")}function F(n){L&&n.preventDefault()}return{addActivationEvents:function(){var n=t;A.add(n,"touchmove",(function(){})).add(n,"touchend",(function(){})).add(n,"touchstart",z).add(n,"mousedown",z).add(n,"touchcancel",N).add(n,"contextmenu",N).add(n,"click",F)},clickAllowed:function(){return!L},pointerDown:function(){return B},removeAllEvents:function(){A.removeAll(),T.removeAll()}}}function m(n,e,t){var r,o,u=(r=2,o=Math.pow(10,r),function(n){return Math.round(n*o)/o}),c=i(0),s=i(0),d=i(0),f=0,l=e,p=t;function g(n){return l=n,v}function m(n){return p=n,v}var v={direction:function(){return f},seek:function(e){d.set(e).subtract(n);var t,r,o,i=(t=d.get(),(o=0)+(t-(r=0))/(100-r)*(l-o));return f=a(d.get()),d.normalize().multiply(i).subtract(c),function(n){n.divide(p),s.add(n)}(d),v},settle:function(e){var t=e.get()-n.get(),r=!u(t);return r&&n.set(e),r},update:function(){c.add(s),n.add(c),s.multiply(0)},useBaseMass:function(){return m(t)},useBaseSpeed:function(){return g(e)},useMass:m,useSpeed:g};return v}function v(n,e,t,r){var o=!1;return{constrain:function(i){if(!o&&n.reachedAny(t.get())&&n.reachedAny(e.get())){var a=i?.7:.45,u=t.get()-e.get();t.subtract(u*a),!i&&Math.abs(u)<10&&(t.set(n.constrain(t.get())),r.useSpeed(10).useMass(3))}},toggleActive:function(n){o=!n}}}function h(n,e,r,o,i){var a=t(-e+n,r[0]),u=o.map(a.constrain);return{snapsContained:function(){if(e<=n)return[a.max];if("keepSnaps"===i)return u;var r=function(){var n=u[0],e=d(u),r=u.lastIndexOf(n),o=u.indexOf(e)+1;return t(r,o)}(),o=r.min,c=r.max;return u.slice(o,c)}()}}function x(n,e,r,o,i){var a=t(r.min+e.measure(.1),r.max+e.measure(.1)),u=a.reachedMin,c=a.reachedMax;return{loop:function(e){if(function(n){return 1===n?c(o.get()):-1===n&&u(o.get())}(e)){var t=n*(-1*e);i.forEach((function(n){return n.add(t)}))}}}}function y(n){var e=n.max,t=n.length;return{get:function(n){return(n-e)/-t}}}function b(n,e,t,r,o,i){var a,u,s=n.startEdge,f=n.endEdge,l=o.map((function(n){return r[s]-n[s]})).map(t.measure).map((function(n){return-Math.abs(n)})),p=(a=c(l,i).map((function(n){return n[0]})),u=c(o,i).map((function(n){return d(n)[f]-n[0][s]})).map(t.measure).map(Math.abs).map(e.measure),a.map((function(n,e){return n+u[e]})));return{snaps:l,snapsAligned:p}}function w(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 M(n,e,t,r,o,i,a,u){var c,d=s(r),f=s(r).reverse(),l=(c=o[0]-1,m(g(f,c),"end")).concat(function(){var n=e-o[0]-1;return m(g(d,n),"start")}());function p(n,e){return n.reduce((function(n,e){return n-r[e]}),e)}function g(n,e){return n.reduce((function(n,t){return p(n,e)>0?n.concat([t]):n}),[])}function m(n,e){var r="start"===e,o=r?-t:t,u=i.findSlideBounds(o);return n.map((function(n){var e=r?0:-t,o=r?t:0,i=u.filter((function(e){return e.index===n}))[0][r?"end":"start"];return{point:i,getTarget:function(){return a.get()>i?e:o},index:n,location:-1}}))}return{canLoop:function(){return l.every((function(n){var t=n.index;return p(d.filter((function(n){return n!==t})),e)<=0}))},clear:function(){l.forEach((function(e){var t=e.index;u[t].style[n.startEdge]=""}))},loop:function(){l.forEach((function(e){var t=e.getTarget,r=e.location,o=e.index,i=t();i!==r&&(u[o].style[n.startEdge]=i+"%",e.location=i)}))},loopPoints:l}}function S(n,e,t){var r=o(),i=r.removeAll,a=0;function u(n){9===n.keyCode&&(a=(new Date).getTime())}function c(o,i){r.add(o,"focus",(function(){if(!((new Date).getTime()-a>10)){n.scrollLeft=0;var r=Math.floor(i/t);e.index(r,0)}}),!0)}return{addActivationEvents:function(n){r.add(document,"keydown",u,!1),n.forEach(c)},removeAllEvents:i}}function E(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 A(n,o,a,u,c){var l,p=u.align,A=u.axis,T=u.direction,C=u.startIndex,D=u.inViewThreshold,P=u.loop,B=u.speed,I=u.dragFree,L=u.slidesToScroll,k=u.skipSnaps,z=u.containScroll,O=o.getBoundingClientRect(),N=a.map((function(n){return n.getBoundingClientRect()})),F=function(n){var e="rtl"===n?-1:1;return{applyTo:function(n){return n*e}}}(T),U=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),V=(l=U.measureSize(O),{measure:function(n){return 0===l?0:n/l*100},totalPercent:100}),H=V.totalPercent,R=e(p,H),j=function(n,e,t,r,o){var i=n.measureSize,a=n.startEdge,u=n.endEdge,c=r.map(i);return{slideSizes:c.map(e.measure),slideSizesWithGaps:r.map((function(n,e,r){var i=e===f(r),s=window.getComputedStyle(d(t)),l=parseFloat(s.getPropertyValue("margin-"+u));return i?c[e]+(o?l:0):r[e+1][a]-n[a]})).map(e.measure).map(Math.abs)}}(U,V,a,N,P),G=j.slideSizes,q=j.slideSizesWithGaps,W=b(U,R,V,O,N,L),X=W.snaps,J=W.snapsAligned,Y=-d(X)+d(q),K=h(H,Y,X,J,z).snapsContained,Q=!P&&""!==z?K:J,Z=function(n,e,r){var o,i;return{limit:(o=e[0],i=d(e),t(r?o-n:i,o))}}(Y,Q,P).limit,$=r(f(Q),C,P),_=$.clone(),nn=s(a),en=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(dn.dragHandler.pointerDown()),dn.scrollBody.seek(on).update();var n=dn.scrollBody.settle(on);n&&!dn.dragHandler.pointerDown()&&(dn.animation.stop(),c.emit("settle")),n||c.emit("scroll"),P&&(dn.scrollLooper.loop(dn.scrollBody.direction()),dn.slideLooper.loop()),dn.translate.to(rn),dn.animation.proceed()})),tn=Q[$.get()],rn=i(tn),on=i(tn),an=m(rn,B,1),un=w(P,Q,Y,Z,on),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))}}}(en,$,_,un,on,c),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}}(H,Y,G,X,P,D),dn={animation:en,axis:U,direction:F,dragHandler:g(U,F,n,on,I,function(n,e){var t=n.scroll,r={x:"clientX",y:"clientY"},o=i(0),a=i(0),u=i(0),c=i(0),s=[],d=(new Date).getTime(),f=!1;function l(n,e){f=!n.touches;var t=r[e],o=f?n[t]:n.touches[0][t];return c.set(o)}return{pointerDown:function(n){var r=l(n,t);return o.set(r),u.set(r),e.measure(o.get())},pointerMove:function(n){var r=l(n,t),o=(new Date).getTime(),i=o-d;return i>=10&&(i>=100&&(s=[]),s.push(r.get()),d=o),a.set(r).subtract(u),u.set(r),e.measure(a.get())},pointerUp:function(){var n=(new Date).getTime()-d,t=u.get(),r=s.slice(-5).map((function(n){return t-n})).sort((function(n,e){return Math.abs(n)<Math.abs(e)?1:-1}))[0];return u.set(n>100||!r?0:r),s=[],e.measure(u.get())},readPoint:l}}(U,V),rn,en,cn,an,un,$,c,P,k),pxToPercent:V,index:$,indexPrevious:_,limit:Z,location:rn,options:u,scrollBody:an,scrollBounds:v(Z,rn,on,an),scrollLooper:x(Y,V,Z,rn,[rn,on]),scrollProgress:y(Z),scrollSnaps:Q,scrollTarget:un,scrollTo:cn,slideFocus:S(n,cn,L),slideLooper:M(U,H,Y,q,Q,sn,rn,a),slidesInView:sn,slideIndexes:nn,target:on,translate:E(U,F,o)};return dn}var T={align:"center",axis:"x",containScroll:"",direction:"ltr",dragFree:!1,draggable:!0,draggableClass:"is-draggable",draggingClass:"is-dragging",inViewThreshold:0,loop:!1,skipSnaps:!0,selectedClass:"is-selected",slidesToScroll:1,speed:10,startIndex:0};return function(e,t){var r,i,a,u,c,s,d,f=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=o(),m=(r=function(){if(y){var n=u.axis.measureSize(e.getBoundingClientRect());M!==n&&B(),f.emit("resize")}},i=500,a=0,function(){window.clearTimeout(a),a=window.setTimeout(r,i)||0}),v=B,h=f.on,x=f.off,y=!1,b=n({},T),w=n({},b),M=0;function S(){if(!e)throw new Error("Missing root node 😢");var n,t=e.querySelector("*");if(!t)throw new Error("Missing container node 😢");s=t,d=Array.prototype.slice.call(s.children),n=getComputedStyle(e,":before").content,c={get:function(){try{return JSON.parse(n.slice(1,-1).replace(/\\/g,""))}catch(n){}return{}}}}function E(t){if(S(),b=n({},b,t),w=n({},b,c.get()),u=A(e,s,d,w,f),g.add(window,"resize",m),u.translate.to(u.location),M=u.axis.measureSize(e.getBoundingClientRect()),w.loop){if(!u.slideLooper.canLoop())return P(),E({loop:!1});u.slideLooper.loop()}w.draggable&&s.offsetParent&&d.length&&(u.dragHandler.addActivationEvents(),w.draggableClass&&p(e,w.draggableClass),w.draggingClass&&f.on("pointerDown",C).on("pointerUp",C)),d.length&&u.slideFocus.addActivationEvents(d),w.selectedClass&&(D(),f.on("select",D).on("pointerUp",D)),y||(setTimeout((function(){return f.emit("init")}),0),y=!0)}function C(n){var t=w.draggingClass;"pointerDown"===n?p(e,t):l(e,t)}function D(){var n=w.selectedClass,e=I(!0);L(!0).forEach((function(e){return l(d[e],n)})),e.forEach((function(e){return p(d[e],n)}))}function P(){u.dragHandler.removeAllEvents(),u.slideFocus.removeAllEvents(),u.animation.stop(),g.removeAll(),u.translate.clear(),u.slideLooper.clear(),l(e,w.draggableClass),d.forEach((function(n){return l(n,w.selectedClass)})),f.off("select",D).off("pointerUp",D).off("pointerDown",C).off("pointerUp",C)}function B(e){if(y){var t=n({startIndex:z()},e);P(),E(t),f.emit("reInit")}}function I(n){var e=u[n?"target":"location"].get(),t=w.loop?"removeOffset":"constrain";return u.slidesInView.check(u.limit[t](e))}function L(n){var e=I(n);return u.slideIndexes.filter((function(n){return-1===e.indexOf(n)}))}function k(n,e,t){u.scrollBody.useBaseMass().useSpeed(e?100:w.speed),y&&u.scrollTo.index(n,t||0)}function z(){return u.index.get()}return E(t),{canScrollNext:function(){return u.index.clone().add(1).get()!==z()},canScrollPrev:function(){return u.index.clone().add(-1).get()!==z()},clickAllowed:function(){return u.dragHandler.clickAllowed()},containerNode:function(){return s},dangerouslyGetEngine:function(){return u},destroy:function(){y&&(P(),y=!1,f.emit("destroy"))},off:x,on:h,previousScrollSnap:function(){return u.indexPrevious.get()},reInit:v,rootNode:function(){return e},scrollNext:function(n){k(u.index.clone().add(1).get(),!0===n,-1)},scrollPrev:function(n){k(u.index.clone().add(-1).get(),!0===n,1)},scrollProgress:function(){return u.scrollProgress.get(u.location.get())},scrollSnapList:function(){return u.scrollSnaps.map(u.scrollProgress.get)},scrollTo:k,selectedScrollSnap:z,slideNodes:function(){return d},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(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 e(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,max:e,min:n,reachedAny:i,reachedMax:o,reachedMin:r,removeOffset:function(n){return t?n-t*Math.ceil((n-e)/t):n}}}function t(n,r,o){var i=e(0,n),u=i.min,a=i.constrain,c=n+1,s=d(r);function d(n){return o?Math.abs((c+n)%c):a(n)}function f(){return s}function l(n){return s=d(n),p}var p={add:function(n){return l(f()+n)},clone:function(){return t(n,f(),o)},get:f,set:l,min:u,max:n};return p}function r(){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 o(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 i(n){return n?n/Math.abs(n):0}function u(n,e){return Math.abs(n-e)}function a(n,e){for(var t=[],r=0;r<n.length;r+=e)t.push(n.slice(r,r+e));return t}function c(n){return Object.keys(n).map(Number)}function s(n){return n[d(n)]}function d(n){return Math.max(0,n.length-1)}function f(n,e,t,a,c,s,d,f,l,p,m,g,v,h,x){var b=n.scroll,y=n.cross,M=["INPUT","SELECT","TEXTAREA"],S=o(0),w=o(0),T=o(0),E=r(),A=r(),P={mouse:2.5,touch:3.5},B={mouse:5,touch:7},D=c?5:16,I=!1,O=!1,z=!1,L=!1;function k(n){if(!(L="mousedown"===n.type)||0===n.button){var e,r,o=u(a.get(),d.get())>=2,i=L||!o,c=(e=n.target,r=e.nodeName||"",!(M.indexOf(r)>-1)),f=o||L&&c;I=!0,s.pointerDown(n),T.set(a),a.set(d),p.useBaseMass().useSpeed(80),function(){var n=L?document:t;A.add(n,"touchmove",N).add(n,"touchend",C).add(n,"mousemove",N).add(n,"mouseup",C)}(),S.set(s.readPoint(n,b)),w.set(s.readPoint(n,y)),v.emit("pointerDown"),i&&(z=!1),f&&n.preventDefault()}}function N(n){if(!O&&!L){if(!n.cancelable)return C();var t=s.readPoint(n,b).get(),r=s.readPoint(n,y).get(),o=u(t,S.get()),i=u(r,w.get());if(!(O=o>i)&&!z)return C()}var c=s.pointerMove(n);!z&&c&&(z=!0),f.start(),a.add(e.applyTo(c)),n.preventDefault()}function C(){var n=m.byDistance(0,!1).index!==g.get(),t=s.pointerUp()*(c?B:P)[L?"mouse":"touch"],r=function(n,e){var t=g.clone().add(-1*i(n)),r=t.get()===g.min||t.get()===g.max,o=m.byDistance(n,!c).distance;return c||Math.abs(n)<20?o:!h&&r?.6*o:x&&e?.5*o:m.byIndex(t.get(),0).distance}(e.applyTo(t),n),o=function(n,e){if(0===n||0===e)return 0;if(Math.abs(n)<=Math.abs(e))return 0;var t=u(Math.abs(n),Math.abs(e));return Math.abs(t/n)}(t,r),d=u(a.get(),T.get())>=.5,f=n&&o>.75,b=Math.abs(t)<20,y=f?10:D,M=f?1+2.5*o:1;d&&!L&&(z=!0),O=!1,I=!1,A.removeAll(),p.useSpeed(b?9:y).useMass(M),l.distance(r,!c),L=!1,v.emit("pointerUp")}function j(n){z&&n.preventDefault()}return{addActivationEvents:function(){var n=t;E.add(n,"touchmove",(function(){})).add(n,"touchend",(function(){})).add(n,"touchstart",k).add(n,"mousedown",k).add(n,"touchcancel",C).add(n,"contextmenu",C).add(n,"click",j)},clickAllowed:function(){return!z},pointerDown:function(){return I},removeAllEvents:function(){E.removeAll(),A.removeAll()}}}function l(n,e,t){var r,u,a=(r=2,u=Math.pow(10,r),function(n){return Math.round(n*u)/u}),c=o(0),s=o(0),d=o(0),f=0,l=e,p=t;function m(n){return l=n,v}function g(n){return p=n,v}var v={direction:function(){return f},seek:function(e){d.set(e).subtract(n);var t,r,o,u,a=(t=d.get(),(o=0)+(t-(r=0))/(100-r)*(l-o));return f=i(d.get()),d.normalize().multiply(a).subtract(c),(u=d).divide(p),s.add(u),v},settle:function(e){var t=e.get()-n.get(),r=!a(t);return r&&n.set(e),r},update:function(){c.add(s),n.add(c),s.multiply(0)},useBaseMass:function(){return g(t)},useBaseSpeed:function(){return m(e)},useMass:g,useSpeed:m};return v}function p(n,e,t,r){var o=!1;return{constrain:function(i){if(!o&&n.reachedAny(t.get())&&n.reachedAny(e.get())){var u=i?.7:.45,a=t.get()-e.get();t.subtract(a*u),!i&&Math.abs(a)<10&&(t.set(n.constrain(t.get())),r.useSpeed(10).useMass(3))}},toggleActive:function(n){o=!n}}}function m(n,t,r,o,i){var u=e(-t+n,r[0]),a=o.map(u.constrain);return{snapsContained:function(){if(t<=n)return[u.max];if("keepSnaps"===i)return a;var r=function(){var n=a[0],t=s(a),r=a.lastIndexOf(n),o=a.indexOf(t)+1;return e(r,o)}(),o=r.min,c=r.max;return a.slice(o,c)}()}}function g(n,t,r,o,i){var u=e(r.min+t.measure(.1),r.max+t.measure(.1)),a=u.reachedMin,c=u.reachedMax;return{loop:function(e){if(function(n){return 1===n?c(o.get()):-1===n&&a(o.get())}(e)){var t=n*(-1*e);i.forEach((function(n){return n.add(t)}))}}}}function v(n){var e=n.max,t=n.length;return{get:function(n){return(n-e)/-t}}}function h(n,e,t,r,o,i){var u,c,d=n.startEdge,f=n.endEdge,l=o.map((function(n){return r[d]-n[d]})).map(t.measure).map((function(n){return-Math.abs(n)})),p=(u=a(l,i).map((function(n){return n[0]})),c=a(o,i).map((function(n){return s(n)[f]-n[0][d]})).map(t.measure).map(Math.abs).map(e.measure),u.map((function(n,e){return n+c[e]})));return{snaps:l,snapsAligned:p}}function x(n,e,t,r,o){var i=r.reachedAny,u=r.removeOffset,a=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,u=e-t;if(!n)return o;if(!r)return c(c(o,i),u);var a=c(o,1===r?i:u);return Math.abs(a)*r}return{byDistance:function(t,r){var c=o.get()+t,d=function(t){var r=n?u(t):a(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 b(n,e,t,r,o,i,u,a){var s,d=c(r),f=c(r).reverse(),l=(s=o[0]-1,g(m(f,s),"end")).concat(function(){var n=e-o[0]-1;return g(m(d,n),"start")}());function p(n,e){return n.reduce((function(n,e){return n-r[e]}),e)}function m(n,e){return n.reduce((function(n,t){return p(n,e)>0?n.concat([t]):n}),[])}function g(n,e){var r="start"===e,o=r?-t:t,a=i.findSlideBounds(o);return n.map((function(n){var e=r?0:-t,o=r?t:0,i=a.filter((function(e){return e.index===n}))[0][r?"end":"start"];return{point:i,getTarget:function(){return u.get()>i?e:o},index:n,location:-1}}))}return{canLoop:function(){return l.every((function(n){var t=n.index;return p(d.filter((function(n){return n!==t})),e)<=0}))},clear:function(){l.forEach((function(e){var t=e.index;a[t].style[n.startEdge]=""}))},loop:function(){l.forEach((function(e){var t=e.getTarget,r=e.location,o=e.index,i=t();i!==r&&(a[o].style[n.startEdge]=i+"%",e.location=i)}))},loopPoints:l}}function y(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 M(i,u,a,M,S){var w,T=M.align,E=M.axis,A=M.direction,P=M.startIndex,B=M.inViewThreshold,D=M.loop,I=M.speed,O=M.dragFree,z=M.slidesToScroll,L=M.skipSnaps,k=M.containScroll,N=u.getBoundingClientRect(),C=a.map((function(n){return n.getBoundingClientRect()})),j=function(n){var e="rtl"===n?-1:1;return{applyTo:function(n){return n*e}}}(A),V=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}}}(E,A),H=(w=V.measureSize(N),{measure:function(n){return 0===w?0:n/w*100},totalPercent:100}),F=H.totalPercent,R=n(T,F),U=function(n,e,t,r,o){var i=n.measureSize,u=n.startEdge,a=n.endEdge,c=r.map(i);return{slideSizes:c.map(e.measure),slideSizesWithGaps:r.map((function(n,e,r){var i=e===d(r),f=window.getComputedStyle(s(t)),l=parseFloat(f.getPropertyValue("margin-"+a));return i?c[e]+(o?l:0):r[e+1][u]-n[u]})).map(e.measure).map(Math.abs)}}(V,H,a,C,D),G=U.slideSizes,W=U.slideSizesWithGaps,X=h(V,R,H,N,C,z),q=X.snaps,J=X.snapsAligned,Y=-s(q)+s(W),K=m(F,Y,q,J,k).snapsContained,Q=!D&&""!==k?K:J,Z=function(n,t,r){var o,i;return{limit:(o=t[0],i=s(t),e(r?o-n:i,o))}}(Y,Q,D).limit,$=t(d(Q),P,D),_=$.clone(),nn=c(a),en=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(){D||dn.scrollBounds.constrain(dn.dragHandler.pointerDown()),dn.scrollBody.seek(on).update();var n=dn.scrollBody.settle(on);n&&!dn.dragHandler.pointerDown()&&(dn.animation.stop(),S.emit("settle")),n||S.emit("scroll"),D&&(dn.scrollLooper.loop(dn.scrollBody.direction()),dn.slideLooper.loop()),dn.translate.to(rn),dn.animation.proceed()})),tn=Q[$.get()],rn=o(tn),on=o(tn),un=l(rn,I,1),an=x(D,Q,Y,Z,on),cn=function(n,e,t,r,o,i){function u(r){var u=r.distance,a=r.index!==e.get();u&&(n.start(),o.add(u)),a&&(t.set(e.get()),e.set(r.index),i.emit("select"))}return{distance:function(n,e){u(r.byDistance(n,e))},index:function(n,t){var o=e.clone().set(n);u(r.byIndex(o.get(),t))}}}(en,$,_,an,on,S),sn=function(n,e,t,r,o,i){var u=Math.min(Math.max(i,.01),.99),a=(o?[0,e,-e]:[0]).reduce((function(n,e){return n.concat(c(e,u))}),[]);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 a.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}}(F,Y,G,q,D,B),dn={animation:en,axis:V,direction:j,dragHandler:f(V,j,i,on,O,function(n,e){var t=n.scroll,r={x:"clientX",y:"clientY"},i=o(0),u=o(0),a=o(0),c=o(0),s=[],d=(new Date).getTime(),f=!1;function l(n,e){f=!n.touches;var t=r[e],o=f?n[t]:n.touches[0][t];return c.set(o)}return{pointerDown:function(n){var r=l(n,t);return i.set(r),a.set(r),e.measure(i.get())},pointerMove:function(n){var r=l(n,t),o=(new Date).getTime(),i=o-d;return i>=10&&(i>=100&&(s=[]),s.push(r.get()),d=o),u.set(r).subtract(a),a.set(r),e.measure(u.get())},pointerUp:function(){var n=(new Date).getTime()-d,t=a.get(),r=s.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),s=[],e.measure(a.get())},readPoint:l}}(V,H),rn,en,cn,un,an,$,S,D,L),eventStore:r(),pxToPercent:H,index:$,indexPrevious:_,limit:Z,location:rn,options:M,scrollBody:un,scrollBounds:p(Z,rn,on,un),scrollLooper:g(Y,H,Z,rn,[rn,on]),scrollProgress:v(Z),scrollSnaps:Q,scrollTarget:an,scrollTo:cn,slideLooper:b(V,F,Y,W,Q,sn,rn,a),slidesInView:sn,slideIndexes:nn,target:on,translate:y(V,j,u)};return dn}var S={align:"center",axis:"x",containScroll:"",direction:"ltr",dragFree:!1,draggable:!0,inViewThreshold:0,loop:!1,skipSnaps:!1,slidesToScroll:1,speed:10,startIndex:0};return function(n,e,t){var r,o,i,u,a,c,s,d,f,l=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}(),p=(r=function(){if(h){var n=u.axis.measureSize(s.getBoundingClientRect());y!==n&&E(),l.emit("resize")}},o=500,i=0,function(){window.clearTimeout(i),i=window.setTimeout(r,o)||0}),m=E,g=l.on,v=l.off,h=!1,x=Object.assign({},S),b=Object.assign({},x),y=0;function w(){var e,t="container"in n&&n.container,r="slides"in n&&n.slides;s="root"in n?n.root:n,d=t||s.children[0],f=r||[].slice.call(d.children),e=getComputedStyle(s,":before").content,a={get:function(){try{return JSON.parse(e.slice(1,-1).replace(/\\/g,""))}catch(n){}return{}}}}function T(n,e){if(w(),x=Object.assign({},x,n),b=Object.assign({},x,a.get()),c=Object.assign([],e),(u=M(s,d,f,b,l)).eventStore.add(window,"resize",p),u.translate.to(u.location),y=u.axis.measureSize(s.getBoundingClientRect()),c.forEach((function(n){return n.init(I)})),b.loop){if(!u.slideLooper.canLoop())return A(),T({loop:!1},e);u.slideLooper.loop()}b.draggable&&d.offsetParent&&f.length&&u.dragHandler.addActivationEvents(),h||(setTimeout((function(){return l.emit("init")}),0),h=!0)}function E(n,e){if(h){var t=D(),r=Object.assign({startIndex:t},n);A(),T(r,e||c),l.emit("reInit")}}function A(){u.dragHandler.removeAllEvents(),u.animation.stop(),u.eventStore.removeAll(),u.translate.clear(),u.slideLooper.clear(),c.forEach((function(n){return n.destroy()}))}function P(n){var e=u[n?"target":"location"].get(),t=b.loop?"removeOffset":"constrain";return u.slidesInView.check(u.limit[t](e))}function B(n,e,t){u.scrollBody.useBaseMass().useSpeed(e?100:b.speed),h&&u.scrollTo.index(n,t||0)}function D(){return u.index.get()}var I={canScrollNext:function(){return u.index.clone().add(1).get()!==D()},canScrollPrev:function(){return u.index.clone().add(-1).get()!==D()},clickAllowed:function(){return u.dragHandler.clickAllowed()},containerNode:function(){return d},internalEngine:function(){return u},destroy:function(){h&&(A(),h=!1,l.emit("destroy"))},off:v,on:g,previousScrollSnap:function(){return u.indexPrevious.get()},reInit:m,rootNode:function(){return s},scrollNext:function(n){B(u.index.clone().add(1).get(),!0===n,-1)},scrollPrev:function(n){B(u.index.clone().add(-1).get(),!0===n,1)},scrollProgress:function(){return u.scrollProgress.get(u.location.get())},scrollSnapList:function(){return u.scrollSnaps.map(u.scrollProgress.get)},scrollTo:B,selectedScrollSnap:D,slideNodes:function(){return f},slidesInView:P,slidesNotInView:function(n){var e=P(n);return u.slideIndexes.filter((function(n){return-1===e.indexOf(n)}))}};return T(e,t),I}})); |
export { EmblaOptionsType } from './components/Options'; | ||
export { EmblaEventType } from './components/EventEmitter'; | ||
export { EmblaCarouselType } from './components'; | ||
export { EmblaCarouselType, EmblaPluginType } from './components'; | ||
export { default } from './components'; |
{ | ||
"name": "embla-carousel", | ||
"version": "5.0.1", | ||
"version": "6.0.0", | ||
"author": "David Cetinkaya", | ||
@@ -45,3 +45,2 @@ "description": "A lightweight carousel library with fluid motion and great swipe precision", | ||
"@babel/core": "^7.13.15", | ||
"@babel/plugin-transform-object-assign": "^7.12.13", | ||
"@babel/preset-env": "^7.13.15", | ||
@@ -48,0 +47,0 @@ "@babel/preset-typescript": "^7.13.0", |
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
18
317738
38
2876