embla-carousel-vue
Advanced tools
Comparing version 8.0.0-rc11 to 8.0.0-rc12
@@ -1,1536 +0,1 @@ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('vue')) : | ||
typeof define === 'function' && define.amd ? define(['vue'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.EmblaCarouselVue = factory(global.Vue)); | ||
})(this, (function (vue) { 'use strict'; | ||
function isObject$1(subject) { | ||
return Object.prototype.toString.call(subject) === '[object Object]'; | ||
} | ||
function isRecord(subject) { | ||
return isObject$1(subject) || Array.isArray(subject); | ||
} | ||
function canUseDOM() { | ||
return !!(typeof window !== 'undefined' && window.document && window.document.createElement); | ||
} | ||
function areOptionsEqual(optionsA, optionsB) { | ||
const optionsAKeys = Object.keys(optionsA); | ||
const optionsBKeys = Object.keys(optionsB); | ||
if (optionsAKeys.length !== optionsBKeys.length) return false; | ||
const breakpointsA = JSON.stringify(Object.keys(optionsA.breakpoints || {})); | ||
const breakpointsB = JSON.stringify(Object.keys(optionsB.breakpoints || {})); | ||
if (breakpointsA !== breakpointsB) return false; | ||
return optionsAKeys.every(key => { | ||
const valueA = optionsA[key]; | ||
const valueB = optionsB[key]; | ||
if (typeof valueA === 'function') return `${valueA}` === `${valueB}`; | ||
if (!isRecord(valueA) || !isRecord(valueB)) return valueA === valueB; | ||
return areOptionsEqual(valueA, valueB); | ||
}); | ||
} | ||
function sortAndMapPluginToOptions(plugins) { | ||
return plugins.concat().sort((a, b) => a.name > b.name ? 1 : -1).map(plugin => plugin.options); | ||
} | ||
function arePluginsEqual(pluginsA, pluginsB) { | ||
if (pluginsA.length !== pluginsB.length) return false; | ||
const optionsA = sortAndMapPluginToOptions(pluginsA); | ||
const optionsB = sortAndMapPluginToOptions(pluginsB); | ||
return optionsA.every((optionA, index) => { | ||
const optionB = optionsB[index]; | ||
return areOptionsEqual(optionA, optionB); | ||
}); | ||
} | ||
function isNumber(subject) { | ||
return typeof subject === 'number'; | ||
} | ||
function isString(subject) { | ||
return typeof subject === 'string'; | ||
} | ||
function isBoolean(subject) { | ||
return typeof subject === 'boolean'; | ||
} | ||
function isObject(subject) { | ||
return Object.prototype.toString.call(subject) === '[object Object]'; | ||
} | ||
function mathAbs(n) { | ||
return Math.abs(n); | ||
} | ||
function mathSign(n) { | ||
return Math.sign(n); | ||
} | ||
function deltaAbs(valueB, valueA) { | ||
return mathAbs(valueB - valueA); | ||
} | ||
function factorAbs(valueB, valueA) { | ||
if (valueB === 0 || valueA === 0) return 0; | ||
if (mathAbs(valueB) <= mathAbs(valueA)) return 0; | ||
const diff = deltaAbs(mathAbs(valueB), mathAbs(valueA)); | ||
return mathAbs(diff / valueB); | ||
} | ||
function arrayKeys(array) { | ||
return objectKeys(array).map(Number); | ||
} | ||
function arrayLast(array) { | ||
return array[arrayLastIndex(array)]; | ||
} | ||
function arrayLastIndex(array) { | ||
return Math.max(0, array.length - 1); | ||
} | ||
function objectKeys(object) { | ||
return Object.keys(object); | ||
} | ||
function objectsMergeDeep(objectA, objectB) { | ||
return [objectA, objectB].reduce((mergedObjects, currentObject) => { | ||
objectKeys(currentObject).forEach(key => { | ||
const valueA = mergedObjects[key]; | ||
const valueB = currentObject[key]; | ||
const areObjects = isObject(valueA) && isObject(valueB); | ||
mergedObjects[key] = areObjects ? objectsMergeDeep(valueA, valueB) : valueB; | ||
}); | ||
return mergedObjects; | ||
}, {}); | ||
} | ||
function isMouseEvent(evt, ownerWindow) { | ||
return typeof ownerWindow.MouseEvent !== 'undefined' && evt instanceof ownerWindow.MouseEvent; | ||
} | ||
function Alignment(align, viewSize) { | ||
const predefined = { | ||
start, | ||
center, | ||
end | ||
}; | ||
function start() { | ||
return 0; | ||
} | ||
function center(n) { | ||
return end(n) / 2; | ||
} | ||
function end(n) { | ||
return viewSize - n; | ||
} | ||
function percent() { | ||
return viewSize * Number(align); | ||
} | ||
function measure(n) { | ||
if (isNumber(align)) return percent(); | ||
return predefined[align](n); | ||
} | ||
const self = { | ||
measure | ||
}; | ||
return self; | ||
} | ||
function Axis(axis, direction) { | ||
const scroll = axis === 'y' ? 'y' : 'x'; | ||
const cross = axis === 'y' ? 'x' : 'y'; | ||
const startEdge = getStartEdge(); | ||
const endEdge = getEndEdge(); | ||
function measureSize(rect) { | ||
const { | ||
width, | ||
height | ||
} = rect; | ||
return scroll === 'x' ? width : height; | ||
} | ||
function getStartEdge() { | ||
if (scroll === 'y') return 'top'; | ||
return direction === 'rtl' ? 'right' : 'left'; | ||
} | ||
function getEndEdge() { | ||
if (scroll === 'y') return 'bottom'; | ||
return direction === 'rtl' ? 'left' : 'right'; | ||
} | ||
const self = { | ||
scroll, | ||
cross, | ||
startEdge, | ||
endEdge, | ||
measureSize | ||
}; | ||
return self; | ||
} | ||
function Limit(min, max) { | ||
const length = mathAbs(min - max); | ||
function reachedMin(n) { | ||
return n < min; | ||
} | ||
function reachedMax(n) { | ||
return n > max; | ||
} | ||
function reachedAny(n) { | ||
return reachedMin(n) || reachedMax(n); | ||
} | ||
function constrain(n) { | ||
if (!reachedAny(n)) return n; | ||
return reachedMin(n) ? min : max; | ||
} | ||
function removeOffset(n) { | ||
if (!length) return n; | ||
return n - length * Math.ceil((n - max) / length); | ||
} | ||
const self = { | ||
length, | ||
max, | ||
min, | ||
constrain, | ||
reachedAny, | ||
reachedMax, | ||
reachedMin, | ||
removeOffset | ||
}; | ||
return self; | ||
} | ||
function Counter(max, start, loop) { | ||
const { | ||
constrain | ||
} = Limit(0, max); | ||
const loopEnd = max + 1; | ||
let counter = withinLimit(start); | ||
function withinLimit(n) { | ||
return !loop ? constrain(n) : mathAbs((loopEnd + n) % loopEnd); | ||
} | ||
function get() { | ||
return counter; | ||
} | ||
function set(n) { | ||
counter = withinLimit(n); | ||
return self; | ||
} | ||
function add(n) { | ||
return clone().set(get() + n); | ||
} | ||
function clone() { | ||
return Counter(max, get(), loop); | ||
} | ||
const self = { | ||
get, | ||
set, | ||
add, | ||
clone | ||
}; | ||
return self; | ||
} | ||
function Direction(direction) { | ||
const sign = direction === 'rtl' ? -1 : 1; | ||
function apply(n) { | ||
return n * sign; | ||
} | ||
const self = { | ||
apply | ||
}; | ||
return self; | ||
} | ||
function EventStore() { | ||
let listeners = []; | ||
function add(node, type, handler, options = { | ||
passive: true | ||
}) { | ||
node.addEventListener(type, handler, options); | ||
listeners.push(() => node.removeEventListener(type, handler, options)); | ||
return self; | ||
} | ||
function clear() { | ||
listeners = listeners.filter(remove => remove()); | ||
} | ||
const self = { | ||
add, | ||
clear | ||
}; | ||
return self; | ||
} | ||
function DragHandler(axis, direction, rootNode, ownerDocument, ownerWindow, target, dragTracker, location, animation, scrollTo, scrollBody, scrollTarget, index, eventHandler, percentOfView, dragFree, dragThreshold, skipSnaps, baseFriction) { | ||
const { | ||
cross: crossAxis | ||
} = axis; | ||
const focusNodes = ['INPUT', 'SELECT', 'TEXTAREA']; | ||
const nonPassiveEvent = { | ||
passive: false | ||
}; | ||
const initEvents = EventStore(); | ||
const dragEvents = EventStore(); | ||
const goToNextThreshold = Limit(50, 225).constrain(percentOfView.measure(20)); | ||
const snapForceBoost = { | ||
mouse: 300, | ||
touch: 400 | ||
}; | ||
const freeForceBoost = { | ||
mouse: 500, | ||
touch: 600 | ||
}; | ||
const baseSpeed = dragFree ? 43 : 25; | ||
let isMoving = false; | ||
let startScroll = 0; | ||
let startCross = 0; | ||
let pointerIsDown = false; | ||
let preventScroll = false; | ||
let preventClick = false; | ||
let isMouse = false; | ||
function init(emblaApi, watchDrag) { | ||
if (!watchDrag) return; | ||
function downIfAllowed(evt) { | ||
if (isBoolean(watchDrag) || watchDrag(emblaApi, evt)) down(evt); | ||
} | ||
const node = rootNode; | ||
initEvents.add(node, 'dragstart', evt => evt.preventDefault(), nonPassiveEvent).add(node, 'touchmove', () => undefined, nonPassiveEvent).add(node, 'touchend', () => undefined).add(node, 'touchstart', downIfAllowed).add(node, 'mousedown', downIfAllowed).add(node, 'touchcancel', up).add(node, 'contextmenu', up).add(node, 'click', click, true); | ||
} | ||
function destroy() { | ||
initEvents.clear(); | ||
dragEvents.clear(); | ||
} | ||
function addDragEvents() { | ||
const node = isMouse ? ownerDocument : rootNode; | ||
dragEvents.add(node, 'touchmove', move, nonPassiveEvent).add(node, 'touchend', up).add(node, 'mousemove', move, nonPassiveEvent).add(node, 'mouseup', up); | ||
} | ||
function isFocusNode(node) { | ||
const nodeName = node.nodeName || ''; | ||
return focusNodes.includes(nodeName); | ||
} | ||
function forceBoost() { | ||
const boost = dragFree ? freeForceBoost : snapForceBoost; | ||
const type = isMouse ? 'mouse' : 'touch'; | ||
return boost[type]; | ||
} | ||
function allowedForce(force, targetChanged) { | ||
const next = index.add(mathSign(force) * -1); | ||
const baseForce = scrollTarget.byDistance(force, !dragFree).distance; | ||
if (dragFree || mathAbs(force) < goToNextThreshold) return baseForce; | ||
if (skipSnaps && targetChanged) return baseForce * 0.5; | ||
return scrollTarget.byIndex(next.get(), 0).distance; | ||
} | ||
function down(evt) { | ||
const isMouseEvt = isMouseEvent(evt, ownerWindow); | ||
isMouse = isMouseEvt; | ||
if (isMouseEvt && evt.button !== 0) return; | ||
if (isFocusNode(evt.target)) return; | ||
preventClick = dragFree && isMouseEvt && !evt.buttons && isMoving; | ||
isMoving = deltaAbs(target.get(), location.get()) >= 2; | ||
pointerIsDown = true; | ||
dragTracker.pointerDown(evt); | ||
scrollBody.useFriction(0).useDuration(0); | ||
target.set(location); | ||
addDragEvents(); | ||
startScroll = dragTracker.readPoint(evt); | ||
startCross = dragTracker.readPoint(evt, crossAxis); | ||
eventHandler.emit('pointerDown'); | ||
} | ||
function move(evt) { | ||
const lastScroll = dragTracker.readPoint(evt); | ||
const lastCross = dragTracker.readPoint(evt, crossAxis); | ||
const diffScroll = deltaAbs(lastScroll, startScroll); | ||
const diffCross = deltaAbs(lastCross, startCross); | ||
if (!preventScroll && !isMouse) { | ||
if (!evt.cancelable) return up(evt); | ||
preventScroll = diffScroll > diffCross; | ||
if (!preventScroll) return up(evt); | ||
} | ||
const diff = dragTracker.pointerMove(evt); | ||
if (diffScroll > dragThreshold) preventClick = true; | ||
scrollBody.useFriction(0.3).useDuration(1); | ||
animation.start(); | ||
target.add(direction.apply(diff)); | ||
evt.preventDefault(); | ||
} | ||
function up(evt) { | ||
const currentLocation = scrollTarget.byDistance(0, false); | ||
const targetChanged = currentLocation.index !== index.get(); | ||
const rawForce = dragTracker.pointerUp(evt) * forceBoost(); | ||
const force = allowedForce(direction.apply(rawForce), targetChanged); | ||
const forceFactor = factorAbs(rawForce, force); | ||
const speed = baseSpeed - 10 * forceFactor; | ||
const friction = baseFriction + forceFactor / 50; | ||
preventScroll = false; | ||
pointerIsDown = false; | ||
dragEvents.clear(); | ||
scrollBody.useDuration(speed).useFriction(friction); | ||
scrollTo.distance(force, !dragFree); | ||
isMouse = false; | ||
eventHandler.emit('pointerUp'); | ||
} | ||
function click(evt) { | ||
if (preventClick) { | ||
evt.stopPropagation(); | ||
evt.preventDefault(); | ||
} | ||
} | ||
function pointerDown() { | ||
return pointerIsDown; | ||
} | ||
const self = { | ||
init, | ||
pointerDown, | ||
destroy | ||
}; | ||
return self; | ||
} | ||
function DragTracker(axis, ownerWindow) { | ||
const logInterval = 170; | ||
let startEvent; | ||
let lastEvent; | ||
function readTime(evt) { | ||
return evt.timeStamp; | ||
} | ||
function readPoint(evt, evtAxis) { | ||
const property = evtAxis || axis.scroll; | ||
const coord = `client${property === 'x' ? 'X' : 'Y'}`; | ||
return (isMouseEvent(evt, ownerWindow) ? evt : evt.touches[0])[coord]; | ||
} | ||
function pointerDown(evt) { | ||
startEvent = evt; | ||
lastEvent = evt; | ||
return readPoint(evt); | ||
} | ||
function pointerMove(evt) { | ||
const diff = readPoint(evt) - readPoint(lastEvent); | ||
const expired = readTime(evt) - readTime(startEvent) > logInterval; | ||
lastEvent = evt; | ||
if (expired) startEvent = evt; | ||
return diff; | ||
} | ||
function pointerUp(evt) { | ||
if (!startEvent || !lastEvent) return 0; | ||
const diffDrag = readPoint(lastEvent) - readPoint(startEvent); | ||
const diffTime = readTime(evt) - readTime(startEvent); | ||
const expired = readTime(evt) - readTime(lastEvent) > logInterval; | ||
const force = diffDrag / diffTime; | ||
const isFlick = diffTime && !expired && mathAbs(force) > 0.1; | ||
return isFlick ? force : 0; | ||
} | ||
const self = { | ||
pointerDown, | ||
pointerMove, | ||
pointerUp, | ||
readPoint | ||
}; | ||
return self; | ||
} | ||
function PercentOfView(viewSize) { | ||
function measure(n) { | ||
return viewSize * (n / 100); | ||
} | ||
const self = { | ||
measure | ||
}; | ||
return self; | ||
} | ||
function ResizeHandler(container, eventHandler, ownerWindow, slides, axis) { | ||
let resizeObserver; | ||
let containerSize; | ||
let slideSizes = []; | ||
let destroyed = false; | ||
function readSize(node) { | ||
return axis.measureSize(node.getBoundingClientRect()); | ||
} | ||
function init(emblaApi, watchResize) { | ||
if (!watchResize) return; | ||
containerSize = readSize(container); | ||
slideSizes = slides.map(readSize); | ||
function defaultCallback(entries) { | ||
for (const entry of entries) { | ||
const isContainer = entry.target === container; | ||
const slideIndex = slides.indexOf(entry.target); | ||
const lastSize = isContainer ? containerSize : slideSizes[slideIndex]; | ||
const newSize = readSize(isContainer ? container : slides[slideIndex]); | ||
if (lastSize !== newSize) { | ||
ownerWindow.requestAnimationFrame(() => { | ||
emblaApi.reInit(); | ||
eventHandler.emit('resize'); | ||
}); | ||
break; | ||
} | ||
} | ||
} | ||
resizeObserver = new ResizeObserver(entries => { | ||
if (destroyed) return; | ||
if (isBoolean(watchResize) || watchResize(emblaApi, entries)) { | ||
defaultCallback(entries); | ||
} | ||
}); | ||
const observeNodes = [container].concat(slides); | ||
observeNodes.forEach(node => resizeObserver.observe(node)); | ||
} | ||
function destroy() { | ||
if (resizeObserver) resizeObserver.disconnect(); | ||
destroyed = true; | ||
} | ||
const self = { | ||
init, | ||
destroy | ||
}; | ||
return self; | ||
} | ||
function ScrollBody(location, target, baseDuration, baseFriction) { | ||
let hasSettled = true; | ||
let bodyVelocity = 0; | ||
let scrollDirection = 0; | ||
let scrollDuration = baseDuration; | ||
let scrollFriction = baseFriction; | ||
let rawLocation = location.get(); | ||
let rawLocationPrevious = 0; | ||
function seek() { | ||
const diff = target.get() - location.get(); | ||
const isInstant = !scrollDuration; | ||
let directionDiff = 0; | ||
if (isInstant) { | ||
bodyVelocity = 0; | ||
location.set(target); | ||
directionDiff = diff; | ||
} else { | ||
bodyVelocity += diff / scrollDuration; | ||
bodyVelocity *= scrollFriction; | ||
rawLocation += bodyVelocity; | ||
location.add(bodyVelocity); | ||
directionDiff = rawLocation - rawLocationPrevious; | ||
} | ||
scrollDirection = mathSign(directionDiff); | ||
rawLocationPrevious = rawLocation; | ||
hasSettled = mathAbs(diff) < 0.001; | ||
return self; | ||
} | ||
function settled() { | ||
return hasSettled; | ||
} | ||
function duration() { | ||
return scrollDuration; | ||
} | ||
function direction() { | ||
return scrollDirection; | ||
} | ||
function velocity() { | ||
return bodyVelocity; | ||
} | ||
function useBaseDuration() { | ||
return useDuration(baseDuration); | ||
} | ||
function useBaseFriction() { | ||
return useFriction(baseFriction); | ||
} | ||
function useDuration(n) { | ||
scrollDuration = n; | ||
return self; | ||
} | ||
function useFriction(n) { | ||
scrollFriction = n; | ||
return self; | ||
} | ||
const self = { | ||
direction, | ||
duration, | ||
velocity, | ||
seek, | ||
settled, | ||
useBaseFriction, | ||
useBaseDuration, | ||
useFriction, | ||
useDuration | ||
}; | ||
return self; | ||
} | ||
function ScrollBounds(limit, location, target, scrollBody, percentOfView) { | ||
const pullBackThreshold = percentOfView.measure(10); | ||
const edgeOffsetTolerance = percentOfView.measure(50); | ||
const frictionLimit = Limit(0.1, 0.99); | ||
let disabled = false; | ||
function shouldConstrain() { | ||
if (disabled) return false; | ||
if (!limit.reachedAny(target.get())) return false; | ||
if (!limit.reachedAny(location.get())) return false; | ||
return true; | ||
} | ||
function constrain(pointerDown) { | ||
if (!shouldConstrain()) return; | ||
const edge = limit.reachedMin(location.get()) ? 'min' : 'max'; | ||
const diffToEdge = mathAbs(limit[edge] - location.get()); | ||
const diffToTarget = target.get() - location.get(); | ||
const friction = frictionLimit.constrain(diffToEdge / edgeOffsetTolerance); | ||
target.subtract(diffToTarget * friction); | ||
if (!pointerDown && mathAbs(diffToTarget) < pullBackThreshold) { | ||
target.set(limit.constrain(target.get())); | ||
scrollBody.useDuration(25).useBaseFriction(); | ||
} | ||
} | ||
function toggleActive(active) { | ||
disabled = !active; | ||
} | ||
const self = { | ||
constrain, | ||
toggleActive | ||
}; | ||
return self; | ||
} | ||
function ScrollContain(viewSize, contentSize, snapsAligned, containScroll) { | ||
const scrollBounds = Limit(-contentSize + viewSize, snapsAligned[0]); | ||
const snapsBounded = measureBounded(); | ||
const snapsContained = measureContained(); | ||
function findDuplicates() { | ||
const startSnap = snapsBounded[0]; | ||
const endSnap = arrayLast(snapsBounded); | ||
const min = snapsBounded.lastIndexOf(startSnap); | ||
const max = snapsBounded.indexOf(endSnap) + 1; | ||
return Limit(min, max); | ||
} | ||
function measureBounded() { | ||
return snapsAligned.map(scrollBounds.constrain).map(scrollBound => parseFloat(scrollBound.toFixed(3))); | ||
} | ||
function measureContained() { | ||
if (contentSize <= viewSize) return [scrollBounds.max]; | ||
if (containScroll === 'keepSnaps') return snapsBounded; | ||
const { | ||
min, | ||
max | ||
} = findDuplicates(); | ||
return snapsBounded.slice(min, max); | ||
} | ||
const self = { | ||
snapsContained | ||
}; | ||
return self; | ||
} | ||
function ScrollLimit(contentSize, scrollSnaps, loop) { | ||
const max = scrollSnaps[0]; | ||
const min = loop ? max - contentSize : arrayLast(scrollSnaps); | ||
const limit = Limit(min, max); | ||
const self = { | ||
limit | ||
}; | ||
return self; | ||
} | ||
function ScrollLooper(contentSize, limit, offsetLocation, vectors) { | ||
const jointSafety = 0.1; | ||
const min = limit.min + jointSafety; | ||
const max = limit.max + jointSafety; | ||
const { | ||
reachedMin, | ||
reachedMax | ||
} = Limit(min, max); | ||
function shouldLoop(direction) { | ||
if (direction === 1) return reachedMax(offsetLocation.get()); | ||
if (direction === -1) return reachedMin(offsetLocation.get()); | ||
return false; | ||
} | ||
function loop(direction) { | ||
if (!shouldLoop(direction)) return; | ||
const loopDistance = contentSize * (direction * -1); | ||
vectors.forEach(v => v.add(loopDistance)); | ||
} | ||
const self = { | ||
loop | ||
}; | ||
return self; | ||
} | ||
function ScrollProgress(limit) { | ||
const { | ||
max, | ||
length: scrollLength | ||
} = limit; | ||
function get(n) { | ||
const currentLocation = n - max; | ||
return currentLocation / -scrollLength; | ||
} | ||
const self = { | ||
get | ||
}; | ||
return self; | ||
} | ||
function ScrollSnaps(axis, alignment, containerRect, slideRects, slideSizesWithGaps, slidesToScroll, containScroll) { | ||
const { | ||
startEdge, | ||
endEdge | ||
} = axis; | ||
const { | ||
groupSlides | ||
} = slidesToScroll; | ||
const alignments = measureSizes().map(alignment.measure); | ||
const snaps = measureUnaligned(); | ||
const snapsAligned = measureAligned(); | ||
function measureSizes() { | ||
return groupSlides(slideRects).map(rects => arrayLast(rects)[endEdge] - rects[0][startEdge]).map(mathAbs); | ||
} | ||
function measureUnaligned() { | ||
return slideRects.map(rect => containerRect[startEdge] - rect[startEdge]).map(snap => -mathAbs(snap)); | ||
} | ||
function measureAligned() { | ||
const containedStartSnap = 0; | ||
const containedEndSnap = arrayLast(snaps) - arrayLast(slideSizesWithGaps); | ||
return groupSlides(snaps).map(g => g[0]).map((snap, index, groupedSnaps) => { | ||
const isFirst = !index; | ||
const isLast = index === arrayLastIndex(groupedSnaps); | ||
if (containScroll && isFirst) return containedStartSnap; | ||
if (containScroll && isLast) return containedEndSnap; | ||
return snap + alignments[index]; | ||
}); | ||
} | ||
const self = { | ||
snaps, | ||
snapsAligned | ||
}; | ||
return self; | ||
} | ||
function ScrollTarget(loop, scrollSnaps, contentSize, limit, targetVector) { | ||
const { | ||
reachedAny, | ||
removeOffset, | ||
constrain | ||
} = limit; | ||
function minDistance(distances) { | ||
return distances.concat().sort((a, b) => mathAbs(a) - mathAbs(b))[0]; | ||
} | ||
function findTargetSnap(target) { | ||
const distance = loop ? removeOffset(target) : constrain(target); | ||
const ascDiffsToSnaps = scrollSnaps.map(scrollSnap => scrollSnap - distance).map(diffToSnap => shortcut(diffToSnap, 0)).map((diff, i) => ({ | ||
diff, | ||
index: i | ||
})).sort((d1, d2) => mathAbs(d1.diff) - mathAbs(d2.diff)); | ||
const { | ||
index | ||
} = ascDiffsToSnaps[0]; | ||
return { | ||
index, | ||
distance | ||
}; | ||
} | ||
function shortcut(target, direction) { | ||
const targets = [target, target + contentSize, target - contentSize]; | ||
if (!loop) return targets[0]; | ||
if (!direction) return minDistance(targets); | ||
const matchingTargets = targets.filter(t => mathSign(t) === direction); | ||
return minDistance(matchingTargets); | ||
} | ||
function byIndex(index, direction) { | ||
const diffToSnap = scrollSnaps[index] - targetVector.get(); | ||
const distance = shortcut(diffToSnap, direction); | ||
return { | ||
index, | ||
distance | ||
}; | ||
} | ||
function byDistance(distance, snap) { | ||
const target = targetVector.get() + distance; | ||
const { | ||
index, | ||
distance: targetSnapDistance | ||
} = findTargetSnap(target); | ||
const reachedBound = !loop && reachedAny(target); | ||
if (!snap || reachedBound) return { | ||
index, | ||
distance | ||
}; | ||
const diffToSnap = scrollSnaps[index] - targetSnapDistance; | ||
const snapDistance = distance + shortcut(diffToSnap, 0); | ||
return { | ||
index, | ||
distance: snapDistance | ||
}; | ||
} | ||
const self = { | ||
byDistance, | ||
byIndex, | ||
shortcut | ||
}; | ||
return self; | ||
} | ||
function ScrollTo(animation, indexCurrent, indexPrevious, scrollTarget, scrollBody, targetVector, eventHandler) { | ||
function scrollTo(target) { | ||
const distanceDiff = target.distance; | ||
const indexDiff = target.index !== indexCurrent.get(); | ||
targetVector.add(distanceDiff); | ||
if (distanceDiff) { | ||
if (scrollBody.duration()) { | ||
animation.start(); | ||
} else { | ||
animation.update(); | ||
animation.render(1); | ||
animation.update(); | ||
} | ||
} | ||
if (indexDiff) { | ||
indexPrevious.set(indexCurrent.get()); | ||
indexCurrent.set(target.index); | ||
eventHandler.emit('select'); | ||
} | ||
} | ||
function distance(n, snap) { | ||
const target = scrollTarget.byDistance(n, snap); | ||
scrollTo(target); | ||
} | ||
function index(n, direction) { | ||
const targetIndex = indexCurrent.clone().set(n); | ||
const target = scrollTarget.byIndex(targetIndex.get(), direction); | ||
scrollTo(target); | ||
} | ||
const self = { | ||
distance, | ||
index | ||
}; | ||
return self; | ||
} | ||
function Vector1D(initialValue) { | ||
let value = initialValue; | ||
function get() { | ||
return value; | ||
} | ||
function set(n) { | ||
value = normalizeInput(n); | ||
} | ||
function add(n) { | ||
value += normalizeInput(n); | ||
} | ||
function subtract(n) { | ||
value -= normalizeInput(n); | ||
} | ||
function normalizeInput(n) { | ||
return isNumber(n) ? n : n.get(); | ||
} | ||
const self = { | ||
get, | ||
set, | ||
add, | ||
subtract | ||
}; | ||
return self; | ||
} | ||
function Translate(axis, direction, container) { | ||
const translate = axis.scroll === 'x' ? x : y; | ||
const containerStyle = container.style; | ||
let disabled = false; | ||
function x(n) { | ||
return `translate3d(${n}px,0px,0px)`; | ||
} | ||
function y(n) { | ||
return `translate3d(0px,${n}px,0px)`; | ||
} | ||
function to(target) { | ||
if (disabled) return; | ||
containerStyle.transform = translate(direction.apply(target)); | ||
} | ||
function toggleActive(active) { | ||
disabled = !active; | ||
} | ||
function clear() { | ||
if (disabled) return; | ||
containerStyle.transform = ''; | ||
if (!container.getAttribute('style')) container.removeAttribute('style'); | ||
} | ||
const self = { | ||
clear, | ||
to, | ||
toggleActive | ||
}; | ||
return self; | ||
} | ||
function SlideLooper(axis, direction, viewSize, contentSize, slideSizesWithGaps, scrollSnaps, slidesInView, offsetLocation, slides) { | ||
const ascItems = arrayKeys(slideSizesWithGaps); | ||
const descItems = arrayKeys(slideSizesWithGaps).reverse(); | ||
const loopPoints = startPoints().concat(endPoints()); | ||
function removeSlideSizes(indexes, from) { | ||
return indexes.reduce((a, i) => { | ||
return a - slideSizesWithGaps[i]; | ||
}, from); | ||
} | ||
function slidesInGap(indexes, gap) { | ||
return indexes.reduce((a, i) => { | ||
const remainingGap = removeSlideSizes(a, gap); | ||
return remainingGap > 0 ? a.concat([i]) : a; | ||
}, []); | ||
} | ||
function findLoopPoints(indexes, edge) { | ||
const isStartEdge = edge === 'start'; | ||
const offset = isStartEdge ? -contentSize : contentSize; | ||
const slideBounds = slidesInView.findSlideBounds([offset]); | ||
return indexes.map(index => { | ||
const initial = isStartEdge ? 0 : -contentSize; | ||
const altered = isStartEdge ? contentSize : 0; | ||
const bounds = slideBounds.filter(b => b.index === index)[0]; | ||
const loopPoint = bounds[isStartEdge ? 'end' : 'start']; | ||
return { | ||
index, | ||
slideLocation: Vector1D(-1), | ||
translate: Translate(axis, direction, slides[index]), | ||
target: () => offsetLocation.get() > loopPoint ? initial : altered | ||
}; | ||
}); | ||
} | ||
function startPoints() { | ||
const gap = scrollSnaps[0] - 1; | ||
const indexes = slidesInGap(descItems, gap); | ||
return findLoopPoints(indexes, 'end'); | ||
} | ||
function endPoints() { | ||
const gap = viewSize - scrollSnaps[0] - 1; | ||
const indexes = slidesInGap(ascItems, gap); | ||
return findLoopPoints(indexes, 'start'); | ||
} | ||
function canLoop() { | ||
return loopPoints.every(({ | ||
index | ||
}) => { | ||
const otherIndexes = ascItems.filter(i => i !== index); | ||
return removeSlideSizes(otherIndexes, viewSize) <= 0.1; | ||
}); | ||
} | ||
function loop() { | ||
loopPoints.forEach(loopPoint => { | ||
const { | ||
target, | ||
translate, | ||
slideLocation | ||
} = loopPoint; | ||
const shiftLocation = target(); | ||
if (shiftLocation === slideLocation.get()) return; | ||
translate.to(shiftLocation); | ||
slideLocation.set(shiftLocation); | ||
}); | ||
} | ||
function clear() { | ||
loopPoints.forEach(loopPoint => loopPoint.translate.clear()); | ||
} | ||
const self = { | ||
canLoop, | ||
clear, | ||
loop, | ||
loopPoints | ||
}; | ||
return self; | ||
} | ||
function SlidesHandler(container, eventHandler) { | ||
let mutationObserver; | ||
let destroyed = false; | ||
function init(emblaApi, watchSlides) { | ||
if (!watchSlides) return; | ||
function defaultCallback(mutations) { | ||
for (const mutation of mutations) { | ||
if (mutation.type === 'childList') { | ||
emblaApi.reInit(); | ||
eventHandler.emit('slidesChanged'); | ||
break; | ||
} | ||
} | ||
} | ||
mutationObserver = new MutationObserver(mutations => { | ||
if (destroyed) return; | ||
if (isBoolean(watchSlides) || watchSlides(emblaApi, mutations)) { | ||
defaultCallback(mutations); | ||
} | ||
}); | ||
mutationObserver.observe(container, { | ||
childList: true | ||
}); | ||
} | ||
function destroy() { | ||
if (mutationObserver) mutationObserver.disconnect(); | ||
destroyed = true; | ||
} | ||
const self = { | ||
init, | ||
destroy | ||
}; | ||
return self; | ||
} | ||
function SlidesInView(viewSize, contentSize, slideSizes, snaps, limit, loop, inViewThreshold) { | ||
const { | ||
removeOffset, | ||
constrain | ||
} = limit; | ||
const roundingSafety = 0.5; | ||
const cachedOffsets = loop ? [0, contentSize, -contentSize] : [0]; | ||
const cachedBounds = findSlideBounds(cachedOffsets, inViewThreshold); | ||
function findSlideThresholds(threshold) { | ||
const slideThreshold = threshold || 0; | ||
return slideSizes.map(slideSize => { | ||
const thresholdLimit = Limit(roundingSafety, slideSize - roundingSafety); | ||
return thresholdLimit.constrain(slideSize * slideThreshold); | ||
}); | ||
} | ||
function findSlideBounds(offsets, threshold) { | ||
const slideOffsets = offsets || cachedOffsets; | ||
const slideThresholds = findSlideThresholds(threshold); | ||
return slideOffsets.reduce((list, offset) => { | ||
const bounds = snaps.map((snap, index) => ({ | ||
start: snap - slideSizes[index] + slideThresholds[index] + offset, | ||
end: snap + viewSize - slideThresholds[index] + offset, | ||
index | ||
})); | ||
return list.concat(bounds); | ||
}, []); | ||
} | ||
function check(location, bounds) { | ||
const limitedLocation = loop ? removeOffset(location) : constrain(location); | ||
const slideBounds = bounds || cachedBounds; | ||
return slideBounds.reduce((list, slideBound) => { | ||
const { | ||
index, | ||
start, | ||
end | ||
} = slideBound; | ||
const inList = list.includes(index); | ||
const inView = start < limitedLocation && end > limitedLocation; | ||
return !inList && inView ? list.concat([index]) : list; | ||
}, []); | ||
} | ||
const self = { | ||
check, | ||
findSlideBounds | ||
}; | ||
return self; | ||
} | ||
function SlideSizes(axis, containerRect, slideRects, slides, readEdgeGap, ownerWindow) { | ||
const { | ||
measureSize, | ||
startEdge, | ||
endEdge | ||
} = axis; | ||
const withEdgeGap = slideRects[0] && readEdgeGap; | ||
const startGap = measureStartGap(); | ||
const endGap = measureEndGap(); | ||
const slideSizes = slideRects.map(measureSize); | ||
const slideSizesWithGaps = measureWithGaps(); | ||
function measureStartGap() { | ||
if (!withEdgeGap) return 0; | ||
const slideRect = slideRects[0]; | ||
return mathAbs(containerRect[startEdge] - slideRect[startEdge]); | ||
} | ||
function measureEndGap() { | ||
if (!withEdgeGap) return 0; | ||
const style = ownerWindow.getComputedStyle(arrayLast(slides)); | ||
return parseFloat(style.getPropertyValue(`margin-${endEdge}`)); | ||
} | ||
function measureWithGaps() { | ||
return slideRects.map((rect, index, rects) => { | ||
const isFirst = !index; | ||
const isLast = index === arrayLastIndex(rects); | ||
if (isFirst) return slideSizes[index] + startGap; | ||
if (isLast) return slideSizes[index] + endGap; | ||
return rects[index + 1][startEdge] - rect[startEdge]; | ||
}).map(mathAbs); | ||
} | ||
const self = { | ||
slideSizes, | ||
slideSizesWithGaps | ||
}; | ||
return self; | ||
} | ||
function SlidesToScroll(viewSize, slideSizesWithGaps, slidesToScroll) { | ||
const groupByNumber = isNumber(slidesToScroll); | ||
function byNumber(array, groupSize) { | ||
return arrayKeys(array).filter(i => i % groupSize === 0).map(i => array.slice(i, i + groupSize)); | ||
} | ||
function bySize(array) { | ||
return arrayKeys(array).reduce((groupSizes, i) => { | ||
const chunk = slideSizesWithGaps.slice(arrayLast(groupSizes), i + 1); | ||
const chunkSize = chunk.reduce((a, s) => a + s, 0); | ||
return !i || chunkSize > viewSize ? groupSizes.concat(i) : groupSizes; | ||
}, []).map((start, i, groupSizes) => array.slice(start, groupSizes[i + 1])); | ||
} | ||
function groupSlides(array) { | ||
return groupByNumber ? byNumber(array, slidesToScroll) : bySize(array); | ||
} | ||
const self = { | ||
groupSlides | ||
}; | ||
return self; | ||
} | ||
function Engine(root, container, slides, ownerDocument, ownerWindow, options, eventHandler, animations) { | ||
// Options | ||
const { | ||
align, | ||
axis: scrollAxis, | ||
direction: contentDirection, | ||
startIndex, | ||
inViewThreshold, | ||
loop, | ||
duration, | ||
dragFree, | ||
dragThreshold, | ||
slidesToScroll: groupSlides, | ||
skipSnaps, | ||
containScroll | ||
} = options; | ||
// Measurements | ||
const containerRect = container.getBoundingClientRect(); | ||
const slideRects = slides.map(slide => slide.getBoundingClientRect()); | ||
const direction = Direction(contentDirection); | ||
const axis = Axis(scrollAxis, contentDirection); | ||
const viewSize = axis.measureSize(containerRect); | ||
const percentOfView = PercentOfView(viewSize); | ||
const alignment = Alignment(align, viewSize); | ||
const containSnaps = !loop && !!containScroll; | ||
const readEdgeGap = loop || !!containScroll; | ||
const { | ||
slideSizes, | ||
slideSizesWithGaps | ||
} = SlideSizes(axis, containerRect, slideRects, slides, readEdgeGap, ownerWindow); | ||
const slidesToScroll = SlidesToScroll(viewSize, slideSizesWithGaps, groupSlides); | ||
const { | ||
snaps, | ||
snapsAligned | ||
} = ScrollSnaps(axis, alignment, containerRect, slideRects, slideSizesWithGaps, slidesToScroll, containSnaps); | ||
const contentSize = -arrayLast(snaps) + arrayLast(slideSizesWithGaps); | ||
const { | ||
snapsContained | ||
} = ScrollContain(viewSize, contentSize, snapsAligned, containScroll); | ||
const scrollSnaps = containSnaps ? snapsContained : snapsAligned; | ||
const { | ||
limit | ||
} = ScrollLimit(contentSize, scrollSnaps, loop); | ||
// Indexes | ||
const index = Counter(arrayLastIndex(scrollSnaps), startIndex, loop); | ||
const indexPrevious = index.clone(); | ||
const slideIndexes = arrayKeys(slides); | ||
// Animation | ||
const update = ({ | ||
dragHandler, | ||
scrollBody, | ||
scrollBounds, | ||
eventHandler, | ||
animation, | ||
options: { | ||
loop | ||
} | ||
}) => { | ||
const pointerDown = dragHandler.pointerDown(); | ||
if (!loop) scrollBounds.constrain(pointerDown); | ||
const hasSettled = scrollBody.seek().settled(); | ||
if (hasSettled && !pointerDown) { | ||
animation.stop(); | ||
eventHandler.emit('settle'); | ||
} | ||
if (!hasSettled) eventHandler.emit('scroll'); | ||
}; | ||
const render = ({ | ||
scrollBody, | ||
translate, | ||
location, | ||
offsetLocation, | ||
scrollLooper, | ||
slideLooper, | ||
options: { | ||
loop | ||
} | ||
}, lagOffset) => { | ||
const velocity = scrollBody.velocity(); | ||
offsetLocation.set(location.get() - velocity + velocity * lagOffset); | ||
if (loop) { | ||
scrollLooper.loop(scrollBody.direction()); | ||
slideLooper.loop(); | ||
} | ||
translate.to(offsetLocation.get()); | ||
}; | ||
const animation = { | ||
start: () => animations.start(engine), | ||
stop: () => animations.stop(engine), | ||
update: () => update(engine), | ||
render: lagOffset => render(engine, lagOffset) | ||
}; | ||
// Shared | ||
const friction = 0.68; | ||
const startLocation = scrollSnaps[index.get()]; | ||
const location = Vector1D(startLocation); | ||
const offsetLocation = Vector1D(startLocation); | ||
const target = Vector1D(startLocation); | ||
const scrollBody = ScrollBody(location, target, duration, friction); | ||
const scrollTarget = ScrollTarget(loop, scrollSnaps, contentSize, limit, target); | ||
const scrollTo = ScrollTo(animation, index, indexPrevious, scrollTarget, scrollBody, target, eventHandler); | ||
const slidesInView = SlidesInView(viewSize, contentSize, slideSizes, snaps, limit, loop, inViewThreshold); | ||
// Engine | ||
const engine = { | ||
ownerDocument, | ||
ownerWindow, | ||
eventHandler, | ||
containerRect, | ||
slideRects, | ||
animation, | ||
axis, | ||
direction, | ||
dragHandler: DragHandler(axis, direction, root, ownerDocument, ownerWindow, target, DragTracker(axis, ownerWindow), location, animation, scrollTo, scrollBody, scrollTarget, index, eventHandler, percentOfView, dragFree, dragThreshold, skipSnaps, friction), | ||
eventStore: EventStore(), | ||
percentOfView, | ||
index, | ||
indexPrevious, | ||
limit, | ||
location, | ||
offsetLocation, | ||
options, | ||
resizeHandler: ResizeHandler(container, eventHandler, ownerWindow, slides, axis), | ||
scrollBody, | ||
scrollBounds: ScrollBounds(limit, location, target, scrollBody, percentOfView), | ||
scrollLooper: ScrollLooper(contentSize, limit, offsetLocation, [location, offsetLocation, target]), | ||
scrollProgress: ScrollProgress(limit), | ||
scrollSnaps, | ||
scrollTarget, | ||
scrollTo, | ||
slideLooper: SlideLooper(axis, direction, viewSize, contentSize, slideSizesWithGaps, scrollSnaps, slidesInView, offsetLocation, slides), | ||
slidesHandler: SlidesHandler(container, eventHandler), | ||
slidesInView, | ||
slideIndexes, | ||
slidesToScroll, | ||
target, | ||
translate: Translate(axis, direction, container) | ||
}; | ||
return engine; | ||
} | ||
function Animations(ownerWindow) { | ||
const timeStep = 1000 / 60; | ||
let engines = []; | ||
let lastTimeStamp = null; | ||
let lag = 0; | ||
let animationFrame = 0; | ||
function animate(timeStamp) { | ||
if (!lastTimeStamp) lastTimeStamp = timeStamp; | ||
const elapsed = timeStamp - lastTimeStamp; | ||
lastTimeStamp = timeStamp; | ||
lag += elapsed; | ||
while (lag >= timeStep) { | ||
engines.forEach(({ | ||
animation | ||
}) => animation.update()); | ||
lag -= timeStep; | ||
} | ||
const lagOffset = mathAbs(lag / timeStep); | ||
engines.forEach(({ | ||
animation | ||
}) => animation.render(lagOffset)); | ||
if (animationFrame) ownerWindow.requestAnimationFrame(animate); | ||
} | ||
function start(engine) { | ||
if (!engines.includes(engine)) engines.push(engine); | ||
if (animationFrame) return; | ||
animationFrame = ownerWindow.requestAnimationFrame(animate); | ||
} | ||
function stop(engine) { | ||
engines = engines.filter(e => e !== engine); | ||
if (engines.length) return; | ||
ownerWindow.cancelAnimationFrame(animationFrame); | ||
lastTimeStamp = null; | ||
lag = 0; | ||
animationFrame = 0; | ||
} | ||
function reset() { | ||
lastTimeStamp = null; | ||
lag = 0; | ||
} | ||
const self = { | ||
start, | ||
stop, | ||
reset, | ||
window: ownerWindow | ||
}; | ||
return self; | ||
} | ||
function EventHandler() { | ||
const listeners = {}; | ||
let api; | ||
function init(emblaApi) { | ||
api = emblaApi; | ||
} | ||
function getListeners(evt) { | ||
return listeners[evt] || []; | ||
} | ||
function emit(evt) { | ||
getListeners(evt).forEach(e => e(api, evt)); | ||
return self; | ||
} | ||
function on(evt, cb) { | ||
listeners[evt] = getListeners(evt).concat([cb]); | ||
return self; | ||
} | ||
function off(evt, cb) { | ||
listeners[evt] = getListeners(evt).filter(e => e !== cb); | ||
return self; | ||
} | ||
const self = { | ||
init, | ||
emit, | ||
off, | ||
on | ||
}; | ||
return self; | ||
} | ||
const defaultOptions = { | ||
align: 'center', | ||
axis: 'x', | ||
container: null, | ||
slides: null, | ||
containScroll: 'trimSnaps', | ||
direction: 'ltr', | ||
slidesToScroll: 1, | ||
breakpoints: {}, | ||
dragFree: false, | ||
dragThreshold: 10, | ||
inViewThreshold: 0, | ||
loop: false, | ||
skipSnaps: false, | ||
duration: 25, | ||
startIndex: 0, | ||
active: true, | ||
watchDrag: true, | ||
watchResize: true, | ||
watchSlides: true | ||
}; | ||
function OptionsHandler(ownerWindow) { | ||
function mergeOptions(optionsA, optionsB) { | ||
return objectsMergeDeep(optionsA, optionsB || {}); | ||
} | ||
function optionsAtMedia(options) { | ||
const optionsAtMedia = options.breakpoints || {}; | ||
const matchedMediaOptions = objectKeys(optionsAtMedia).filter(media => ownerWindow.matchMedia(media).matches).map(media => optionsAtMedia[media]).reduce((a, mediaOption) => mergeOptions(a, mediaOption), {}); | ||
return mergeOptions(options, matchedMediaOptions); | ||
} | ||
function optionsMediaQueries(optionsList) { | ||
return optionsList.map(options => objectKeys(options.breakpoints || {})).reduce((acc, mediaQueries) => acc.concat(mediaQueries), []).map(ownerWindow.matchMedia); | ||
} | ||
const self = { | ||
mergeOptions, | ||
optionsAtMedia, | ||
optionsMediaQueries | ||
}; | ||
return self; | ||
} | ||
function PluginsHandler(optionsHandler) { | ||
let activePlugins = []; | ||
function init(plugins, emblaApi) { | ||
activePlugins = plugins.filter(({ | ||
options | ||
}) => optionsHandler.optionsAtMedia(options).active !== false); | ||
activePlugins.forEach(plugin => plugin.init(emblaApi, optionsHandler)); | ||
return plugins.reduce((map, plugin) => Object.assign(map, { | ||
[plugin.name]: plugin | ||
}), {}); | ||
} | ||
function destroy() { | ||
activePlugins = activePlugins.filter(plugin => plugin.destroy()); | ||
} | ||
const self = { | ||
init, | ||
destroy | ||
}; | ||
return self; | ||
} | ||
function EmblaCarousel(root, userOptions, userPlugins) { | ||
const ownerDocument = root.ownerDocument; | ||
const ownerWindow = ownerDocument.defaultView; | ||
const optionsHandler = OptionsHandler(ownerWindow); | ||
const pluginsHandler = PluginsHandler(optionsHandler); | ||
const mediaHandlers = EventStore(); | ||
const documentVisibleHandler = EventStore(); | ||
const eventHandler = EventHandler(); | ||
const { | ||
animationRealms | ||
} = EmblaCarousel; | ||
const { | ||
mergeOptions, | ||
optionsAtMedia, | ||
optionsMediaQueries | ||
} = optionsHandler; | ||
const { | ||
on, | ||
off, | ||
emit | ||
} = eventHandler; | ||
const reInit = reActivate; | ||
let destroyed = false; | ||
let engine; | ||
let optionsBase = mergeOptions(defaultOptions, EmblaCarousel.globalOptions); | ||
let options = mergeOptions(optionsBase); | ||
let pluginList = []; | ||
let pluginApis; | ||
let container; | ||
let slides; | ||
function storeElements() { | ||
const { | ||
container: userContainer, | ||
slides: userSlides | ||
} = options; | ||
const customContainer = isString(userContainer) ? root.querySelector(userContainer) : userContainer; | ||
container = customContainer || root.children[0]; | ||
const customSlides = isString(userSlides) ? container.querySelectorAll(userSlides) : userSlides; | ||
slides = [].slice.call(customSlides || container.children); | ||
} | ||
function createEngine(options, animations) { | ||
const engine = Engine(root, container, slides, ownerDocument, ownerWindow, options, eventHandler, animations); | ||
if (options.loop && !engine.slideLooper.canLoop()) { | ||
const optionsWithoutLoop = Object.assign({}, options, { | ||
loop: false | ||
}); | ||
return createEngine(optionsWithoutLoop, animations); | ||
} | ||
return engine; | ||
} | ||
function activate(withOptions, withPlugins) { | ||
if (destroyed) return; | ||
const animationRealm = animationRealms.find(a => a.window === ownerWindow); | ||
const animations = animationRealm || Animations(ownerWindow); | ||
if (!animationRealm) animationRealms.push(animations); | ||
optionsBase = mergeOptions(optionsBase, withOptions); | ||
options = optionsAtMedia(optionsBase); | ||
pluginList = withPlugins || pluginList; | ||
storeElements(); | ||
engine = createEngine(options, animations); | ||
optionsMediaQueries([optionsBase, ...pluginList.map(({ | ||
options | ||
}) => options)]).forEach(query => mediaHandlers.add(query, 'change', reActivate)); | ||
if (!options.active) return; | ||
engine.translate.to(engine.location.get()); | ||
engine.eventHandler.init(self); | ||
engine.resizeHandler.init(self, options.watchResize); | ||
engine.slidesHandler.init(self, options.watchSlides); | ||
documentVisibleHandler.add(ownerDocument, 'visibilitychange', () => { | ||
if (ownerDocument.hidden) animations.reset(); | ||
}); | ||
if (engine.options.loop) engine.slideLooper.loop(); | ||
if (container.offsetParent && slides.length) { | ||
engine.dragHandler.init(self, options.watchDrag); | ||
} | ||
pluginApis = pluginsHandler.init(pluginList, self); | ||
} | ||
function reActivate(withOptions, withPlugins) { | ||
const startIndex = selectedScrollSnap(); | ||
deActivate(); | ||
activate(mergeOptions({ | ||
startIndex | ||
}, withOptions), withPlugins); | ||
eventHandler.emit('reInit'); | ||
} | ||
function deActivate() { | ||
engine.dragHandler.destroy(); | ||
engine.animation.stop(); | ||
engine.eventStore.clear(); | ||
engine.translate.clear(); | ||
engine.slideLooper.clear(); | ||
engine.resizeHandler.destroy(); | ||
engine.slidesHandler.destroy(); | ||
pluginsHandler.destroy(); | ||
mediaHandlers.clear(); | ||
documentVisibleHandler.clear(); | ||
} | ||
function destroy() { | ||
if (destroyed) return; | ||
destroyed = true; | ||
mediaHandlers.clear(); | ||
deActivate(); | ||
eventHandler.emit('destroy'); | ||
} | ||
function slidesInView(target) { | ||
const location = engine[target ? 'target' : 'location'].get(); | ||
const type = options.loop ? 'removeOffset' : 'constrain'; | ||
return engine.slidesInView.check(engine.limit[type](location)); | ||
} | ||
function slidesNotInView(target) { | ||
const inView = slidesInView(target); | ||
return engine.slideIndexes.filter(index => !inView.includes(index)); | ||
} | ||
function scrollTo(index, jump, direction) { | ||
if (!options.active || destroyed) return; | ||
engine.scrollBody.useBaseFriction().useDuration(jump ? 0 : options.duration); | ||
engine.scrollTo.index(index, direction || 0); | ||
} | ||
function scrollNext(jump) { | ||
const next = engine.index.add(1).get(); | ||
scrollTo(next, jump === true, -1); | ||
} | ||
function scrollPrev(jump) { | ||
const prev = engine.index.add(-1).get(); | ||
scrollTo(prev, jump === true, 1); | ||
} | ||
function canScrollNext() { | ||
const next = engine.index.add(1).get(); | ||
return next !== selectedScrollSnap(); | ||
} | ||
function canScrollPrev() { | ||
const prev = engine.index.add(-1).get(); | ||
return prev !== selectedScrollSnap(); | ||
} | ||
function scrollSnapList() { | ||
return engine.scrollSnaps.map(engine.scrollProgress.get); | ||
} | ||
function scrollProgress() { | ||
return engine.scrollProgress.get(engine.location.get()); | ||
} | ||
function selectedScrollSnap() { | ||
return engine.index.get(); | ||
} | ||
function previousScrollSnap() { | ||
return engine.indexPrevious.get(); | ||
} | ||
function plugins() { | ||
return pluginApis; | ||
} | ||
function internalEngine() { | ||
return engine; | ||
} | ||
function rootNode() { | ||
return root; | ||
} | ||
function containerNode() { | ||
return container; | ||
} | ||
function slideNodes() { | ||
return slides; | ||
} | ||
const self = { | ||
canScrollNext, | ||
canScrollPrev, | ||
containerNode, | ||
internalEngine, | ||
destroy, | ||
off, | ||
on, | ||
emit, | ||
plugins, | ||
previousScrollSnap, | ||
reInit, | ||
rootNode, | ||
scrollNext, | ||
scrollPrev, | ||
scrollProgress, | ||
scrollSnapList, | ||
scrollTo, | ||
selectedScrollSnap, | ||
slideNodes, | ||
slidesInView, | ||
slidesNotInView | ||
}; | ||
activate(userOptions, userPlugins); | ||
setTimeout(() => eventHandler.emit('init'), 0); | ||
return self; | ||
} | ||
EmblaCarousel.animationRealms = []; | ||
EmblaCarousel.globalOptions = undefined; | ||
function emblaCarouselVue(options = {}, plugins = []) { | ||
const storedOptions = vue.ref(vue.isRef(options) ? options.value : options); | ||
const storedPlugins = vue.ref(vue.isRef(plugins) ? plugins.value : plugins); | ||
const emblaNode = vue.ref(); | ||
const emblaApi = vue.ref(); | ||
function reInit() { | ||
if (!emblaApi.value) return; | ||
emblaApi.value.reInit(storedOptions.value, storedPlugins.value); | ||
} | ||
vue.onMounted(() => { | ||
if (!canUseDOM() || !emblaNode.value) return; | ||
EmblaCarousel.globalOptions = emblaCarouselVue.globalOptions; | ||
emblaApi.value = EmblaCarousel(emblaNode.value, storedOptions.value, storedPlugins.value); | ||
}); | ||
vue.onUnmounted(() => { | ||
if (emblaApi.value) emblaApi.value.destroy(); | ||
}); | ||
if (vue.isRef(options)) { | ||
vue.watch(options, newOptions => { | ||
if (areOptionsEqual(storedOptions.value, newOptions)) return; | ||
storedOptions.value = newOptions; | ||
reInit(); | ||
}); | ||
} | ||
if (vue.isRef(plugins)) { | ||
vue.watch(plugins, newPlugins => { | ||
if (arePluginsEqual(storedPlugins.value, newPlugins)) return; | ||
storedPlugins.value = newPlugins; | ||
reInit(); | ||
}); | ||
} | ||
return [emblaNode, emblaApi]; | ||
} | ||
emblaCarouselVue.globalOptions = undefined; | ||
return emblaCarouselVue; | ||
})); | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("vue")):"function"==typeof define&&define.amd?define(["vue"],t):(n="undefined"!=typeof globalThis?globalThis:n||self).EmblaCarouselVue=t(n.Vue)}(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 g(n).map(Number)}function f(n){return n[p(n)]}function p(n){return Math.max(0,n.length-1)}function m(n,t=0){return Array.from(Array(n),((n,e)=>t+e))}function g(n){return Object.keys(n)}function h(n,t){return[n,t].reduce(((n,t)=>(g(t).forEach((e=>{const r=n[e],o=t[e],i=u(r)&&u(o);n[e]=i?h(r,o):o})),n)),{})}function y(n,t){return void 0!==t.MouseEvent&&n instanceof t.MouseEvent}function v(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 w(){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,h,v,b,S,E,O,D,I){const{cross:A}=n,L=["INPUT","SELECT","TEXTAREA"],M={passive:!1},T=w(),k=w(),F=x(50,225).constrain(b.measure(20)),R={mouse:300,touch:400},P={mouse:500,touch:600},z=S?43:25;let j=!1,V=0,B=0,H=!1,N=!1,C=!1,q=!1;function G(n){const e=u.readPoint(n),r=u.readPoint(n,A),o=l(e,V),c=l(r,B);if(!N&&!q){if(!n.cancelable)return U(n);if(N=o>c,!N)return U(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 U(n){const e=g.byDistance(0,!1).index!==h.get(),r=u.pointerUp(n)*(S?P:R)[q?"mouse":"touch"],o=function(n,t){const e=h.add(-1*a(n)),r=g.byDistance(n,!S).distance;return S||s(n)<F?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=z-10*i,d=D+i/50;N=!1,H=!1,k.clear(),m.useDuration(c).useFriction(d),p.distance(o,!S),q=!1,v.emit("pointerUp")}function $(n){C&&(n.stopPropagation(),n.preventDefault())}return{init:function(n){if(!I)return;function t(t){(c(I)||I(n,t))&&function(n){const t=y(n,o);if(q=t,t&&0!==n.button)return;if(function(n){const t=n.nodeName||"";return L.includes(t)}(n.target))return;C=S&&t&&!n.buttons&&j,j=l(i.get(),d.get())>=2,H=!0,u.pointerDown(n),m.useFriction(0).useDuration(0),i.set(d),function(){const n=q?r:e;k.add(n,"touchmove",G,M).add(n,"touchend",U).add(n,"mousemove",G,M).add(n,"mouseup",U)}(),V=u.readPoint(n),B=u.readPoint(n,A),v.emit("pointerDown")}(t)}const s=e;T.add(s,"dragstart",(n=>n.preventDefault()),M).add(s,"touchmove",(()=>{}),M).add(s,"touchend",(()=>{})).add(s,"touchstart",t).add(s,"mousedown",t).add(s,"touchcancel",U).add(s,"contextmenu",U).add(s,"click",$,!0)},pointerDown:function(){return H},destroy:function(){T.clear(),k.clear()}}}function E(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(y(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 O(n,t,e,r,o,i){let u,s,a=[],l=!1;function d(n){return o.measureSize(n.getBoundingClientRect())}return{init:function(o){if(!i)return;s=d(n),a=r.map(d),u=new ResizeObserver((u=>{l||(c(i)||i(o,u))&&function(i){for(const c of i){const i=c.target===n,u=r.indexOf(c.target);if((i?s:a[u])!==d(i?n:r[u])){e.requestAnimationFrame((()=>{o.reInit(),t.emit("resize")}));break}}}(u)})),[n].concat(r).forEach((n=>u.observe(n)))},destroy:function(){u&&u.disconnect(),l=!0}}}function D(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 I(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,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);const i=o.filter((n=>a(n)===r));return i.length?l(i):f(o)-e}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 L(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 M(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,a){const l=d(i),f=d(i).reverse(),p=function(){const n=u[0]-1;return h(g(f,n),r,!1)}().concat(function(){const n=e-u[0]-1;return h(g(l,n),-r,!0)}());function m(n,t){return n.reduce(((n,t)=>n-i[t]),t)}function g(n,t){return n.reduce(((n,e)=>m(n,t)>0?n.concat([e]):n),[])}function h(i,u,l){const d=function(n){return c.map(((t,r)=>({start:t-o[r]+.5+n,end:t+e-.5+n})))}(u);return i.map((e=>{const o=l?0:-r,i=l?r:0,c=l?"end":"start",u=d[e][c];return{index:e,slideLocation:L(-1),translate:M(n,t,a[e]),target:()=>s.get()>u?o:i}}))}return{canLoop:function(){return p.every((({index:n})=>m(l.filter((t=>t!==n)),e)<=.1))},clear:function(){p.forEach((n=>n.translate.clear()))},loop:function(){p.forEach((n=>{const{target:t,translate:e,slideLocation:r}=n,o=t();o!==r.get()&&(e.to(o),r.set(o))}))},loopPoints:p}}function k(n,t,e){let r,o=!1;return{init:function(i){e&&(r=new MutationObserver((n=>{o||(c(e)||e(i,n))&&function(n){for(const e of n)if("childList"===e.type){i.reInit(),t.emit("slidesChanged");break}}(n)})),r.observe(n,{childList:!0}))},destroy:function(){r&&r.disconnect(),o=!0}}}function F(n,t,e,r){const o={};let i,c=null,u=null,s=!1;return{init:function(){i=new IntersectionObserver((n=>{s||(n.forEach((n=>{const e=t.indexOf(n.target);o[e]=n})),c=null,u=null,e.emit("slidesInView"))}),{root:n.parentElement,threshold:r}),t.forEach((n=>i.observe(n)))},destroy:function(){i&&i.disconnect(),s=!0},get:function(n=!0){if(n&&c)return c;if(!n&&u)return u;const t=function(n){return g(o).reduce(((t,e)=>{const r=parseInt(e),{isIntersecting:i}=o[r];return(n&&i||!n&&!i)&&t.push(r),t}),[])}(n);return n&&(c=t),n||(u=t),t}}}function R(n,t,e,r,i,c,u,a,l){const{startEdge:m,endEdge:g}=n,h=o(r);return{groupSlides:function(n){return h?function(n,t){return d(n).filter((n=>n%t==0)).map((e=>n.slice(e,e+t)))}(n,r):function(n){return n.length?d(n).reduce(((r,o)=>{const d=f(r)||0,h=0===d,y=o===p(n),v=c[m]-u[d][m],x=c[m]-u[o][g],b=!i&&h?t.apply(a):0;return s(x-(!i&&y?t.apply(l):0)-(v+b))>e&&r.push(o),y&&r.push(n.length),r}),[]).map(((t,e,r)=>{const o=Math.max(r[e-1]||0);return n.slice(o,t)})):[]}(n)}}}function P(n,t,e,r,i,c,u,l){const{align:g,axis:h,direction:y,startIndex:P,loop:z,duration:j,dragFree:V,dragThreshold:B,inViewThreshold:H,slidesToScroll:N,skipSnaps:C,containScroll:q,watchResize:G,watchSlides:U,watchDrag:$}=c,W=t.getBoundingClientRect(),J=e.map((n=>n.getBoundingClientRect())),Q=function(n){const t="rtl"===n?-1:1;return{apply:function(n){return n*t}}}(y),X=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}}}(h,y),Y=X.measureSize(W),K=function(n){return{measure:function(t){return n*(t/100)}}}(Y),Z=v(g,Y),_=!z&&!!q,nn=z||!!q,{slideSizes:tn,slideSizesWithGaps:en,startGap:rn,endGap:on}=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,startGap:d,endGap:m}}(X,W,J,e,nn,i),cn=R(X,Q,Y,N,z,W,J,rn,on),{snaps:un,snapsAligned:sn}=function(n,t,e,r,o){const{startEdge:i,endEdge:c}=n,{groupSlides:u}=o,a=u(r).map((n=>f(n)[c]-n[0][i])).map(s).map(t.measure),l=r.map((n=>e[i]-n[i])).map((n=>-s(n))),d=u(l).map((n=>n[0])).map(((n,t)=>n+a[t]));return{snaps:l,snapsAligned:d}}(X,Z,W,J,cn),an=-f(un)+f(en),{snapsContained:ln,scrollContainLimit:dn}=function(n,t,e,r){const o=x(-t+n,0),i=e.map(o.constrain).map((n=>parseFloat(n.toFixed(3)))),c=function(){const n=i[0],t=f(i);return x(i.lastIndexOf(n),i.indexOf(t)+1)}();return{snapsContained:function(){if(t<=n)return[o.max];if("keepSnaps"===r)return i;const{min:e,max:u}=c;return i.slice(e,u)}(),scrollContainLimit:c}}(Y,an,sn,q),fn=_?ln:sn,{limit:pn}=function(n,t,e){const r=t[0];return{limit:x(e?r-n:f(t),r)}}(an,fn,z),mn=b(p(fn),P,z),gn=mn.clone(),hn=d(e),yn={start:()=>l.start(Tn),stop:()=>l.stop(Tn),update:()=>(({dragHandler:n,scrollBody:t,scrollBounds:e,eventHandler:r,animation:o,options:{loop:i}})=>{const c=n.pointerDown();i||e.constrain(c);const u=t.seek().settled();u&&!c&&(o.stop(),r.emit("settle")),u||r.emit("scroll")})(Tn),render:n=>(({scrollBody:n,translate:t,location:e,offsetLocation:r,scrollLooper:o,slideLooper:i,options:{loop:c}},u)=>{const s=n.velocity();r.set(e.get()-s+s*u),c&&(o.loop(n.direction()),i.loop()),t.to(r.get())})(Tn,n)},vn=fn[mn.get()],xn=L(vn),bn=L(vn),wn=L(vn),Sn=function(n,t,e,r){let o=!0,i=0,c=0,u=e,l=r,d=n.get(),f=0;function p(n){return u=n,g}function m(n){return l=n,g}const g={direction:function(){return c},duration:function(){return u},velocity:function(){return i},seek:function(){const e=t.get()-n.get();let r=0;return u?(i+=e/u,i*=l,d+=i,n.add(i),r=d-f):(i=0,n.set(t),r=e),c=a(r),f=d,o=s(e)<.001,g},settled:function(){return o},useBaseFriction:function(){return m(r)},useBaseDuration:function(){return p(e)},useFriction:m,useDuration:p};return g}(xn,wn,j,.68),En=A(z,fn,an,pn,wn),On=function(n,t,e,r,o,i,c){function u(r){const u=r.distance,s=r.index!==t.get();i.add(u),u&&(o.duration()?n.start():(n.update(),n.render(1),n.update())),s&&(e.set(t.get()),t.set(r.index),c.emit("select"))}return{distance:function(n,t){u(r.byDistance(n,t))},index:function(n,e){const o=t.clone().set(n);u(r.byIndex(o.get(),e))}}}(yn,mn,gn,En,Sn,wn,u),Dn=function(n){const{max:t,length:e}=n;return{get:function(n){return e?(n-t)/-e:0}}}(pn),In=w(),An=F(t,e,u,H),{slideRegistry:Ln}=function(n,t,e,r,o,i){const{groupSlides:c}=o,{min:u,max:s}=r;return{slideRegistry:function(){const r=c(i);return!e||t<=n?r:r.slice(u,s).map(((n,t,e)=>{const r=!t,o=!r&&t===p(e);return r?m(f(e[0])+1):o?m(p(i)-f(e)[0]+1,f(e)[0]):n}))}()}}(Y,an,_,dn,cn,hn),Mn=function(n,t,e,r,i,c){let u=0;function s(n){"Tab"===n.code&&(u=(new Date).getTime())}function a(s){c.add(s,"focus",(()=>{if((new Date).getTime()-u>10)return;n.scrollLeft=0;const c=t.indexOf(s),a=e.findIndex((n=>n.includes(c)));o(a)&&(i.useDuration(0),r.index(a,0))}),{passive:!0,capture:!0})}return{init:function(){c.add(document,"keydown",s,!1),t.forEach(a)}}}(n,e,Ln,On,Sn,In),Tn={ownerDocument:r,ownerWindow:i,eventHandler:u,containerRect:W,slideRects:J,animation:yn,axis:X,direction:Q,dragHandler:S(X,Q,n,r,i,wn,E(X,i),xn,yn,On,Sn,En,mn,u,K,V,B,C,.68,$),eventStore:In,percentOfView:K,index:mn,indexPrevious:gn,limit:pn,location:xn,offsetLocation:bn,options:c,resizeHandler:O(t,u,i,e,X,G),scrollBody:Sn,scrollBounds:D(pn,xn,wn,Sn,K),scrollLooper:I(an,pn,bn,[xn,bn,wn]),scrollProgress:Dn,scrollSnapList:fn.map(Dn.get),scrollSnaps:fn,scrollTarget:En,scrollTo:On,slideLooper:T(X,Q,Y,an,tn,en,un,fn,bn,e),slideFocus:Mn,slidesHandler:k(t,u,U),slidesInView:An,slideIndexes:hn,slideRegistry:Ln,slidesToScroll:cn,target:wn,translate:M(X,Q,t)};return Tn}const z={align:"center",axis:"x",container:null,slides:null,containScroll:"trimSnaps",direction:"ltr",slidesToScroll:1,inViewThreshold:0,breakpoints:{},dragFree:!1,dragThreshold:10,loop:!1,skipSnaps:!1,duration:25,startIndex:0,active:!0,watchDrag:!0,watchResize:!0,watchSlides:!0};function j(n){function t(n,t){return h(n,t||{})}const e={mergeOptions:t,optionsAtMedia:function(e){const r=e.breakpoints||{},o=g(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=>g(n.breakpoints||{}))).reduce(((n,t)=>n.concat(t)),[]).map(n.matchMedia)}};return e}function V(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=r.filter((({options:t})=>!1!==n.optionsAtMedia(t).active)),t.forEach((t=>t.init(e,n))),r.reduce(((n,t)=>Object.assign(n,{[t.name]:t})),{})},destroy:function(){t=t.filter((n=>n.destroy()))}}}(c),a=w(),l=w(),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}=V,{mergeOptions:p,optionsAtMedia:m,optionsMediaQueries:g}=c,{on:h,off:y,emit:v}=d,x=k;let b,S,E,O,D=!1,I=p(z,V.globalOptions),A=p(I),L=[];function M(t,e){const i=P(n,E,O,r,o,t,d,e);if(t.loop&&!i.slideLooper.canLoop()){return M(Object.assign({},t,{loop:!1}),e)}return i}function T(t,e){if(D)return;const c=f.find((n=>n.window===o)),d=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);c||f.push(d),I=p(I,t),A=m(I),L=e||L,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)}(),b=M(A,d),g([I,...L.map((({options:n})=>n))]).forEach((n=>a.add(n,"change",k))),A.active&&(b.translate.to(b.location.get()),b.slidesInView.init(),b.slideFocus.init(),b.eventHandler.init(H),b.resizeHandler.init(H),b.slidesHandler.init(H),l.add(r,"visibilitychange",(()=>{r.hidden&&d.reset()})),b.options.loop&&b.slideLooper.loop(),E.offsetParent&&O.length&&b.dragHandler.init(H),S=u.init(H,L))}function k(n,t){const e=B();F(),T(p({startIndex:e},n),t),d.emit("reInit")}function F(){b.dragHandler.destroy(),b.animation.stop(),b.eventStore.clear(),b.translate.clear(),b.slideLooper.clear(),b.resizeHandler.destroy(),b.slidesHandler.destroy(),u.destroy(),a.clear(),l.clear()}function R(n,t,e){A.active&&!D&&(b.scrollBody.useBaseFriction().useDuration(t?0:A.duration),b.scrollTo.index(n,e||0))}function B(){return b.index.get()}const H={canScrollNext:function(){return b.index.add(1).get()!==B()},canScrollPrev:function(){return b.index.add(-1).get()!==B()},containerNode:function(){return E},internalEngine:function(){return b},destroy:function(){D||(D=!0,a.clear(),F(),d.emit("destroy"))},off:y,on:h,emit:v,plugins:function(){return S},previousScrollSnap:function(){return b.indexPrevious.get()},reInit:x,rootNode:function(){return n},scrollNext:function(n){R(b.index.add(1).get(),!0===n,-1)},scrollPrev:function(n){R(b.index.add(-1).get(),!0===n,1)},scrollProgress:function(){return b.scrollProgress.get(b.location.get())},scrollSnapList:function(){return b.scrollSnapList},scrollTo:R,selectedScrollSnap:B,slideNodes:function(){return O},slidesInView:function(){return b.slidesInView.get()},slidesNotInView:function(){return b.slidesInView.get(!1)}};return T(t,e),setTimeout((()=>d.emit("init")),0),H}function B(t={},o=[]){const i=n.ref(n.isRef(t)?t.value:t),c=n.ref(n.isRef(o)?o.value:o),u=n.ref(),s=n.ref();function a(){s.value&&s.value.reInit(i.value,c.value)}return n.onMounted((()=>{"undefined"!=typeof window&&window.document&&window.document.createElement&&u.value&&(V.globalOptions=B.globalOptions,s.value=V(u.value,i.value,c.value))})),n.onUnmounted((()=>{s.value&&s.value.destroy()})),n.isRef(t)&&n.watch(t,(n=>{e(i.value,n)||(i.value=n,a())})),n.isRef(o)&&n.watch(o,(n=>{(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.value,n)||(c.value=n,a())})),[u,s]}return V.animationRealms=[],V.globalOptions=void 0,B.globalOptions=void 0,B})); |
{ | ||
"name": "embla-carousel-vue", | ||
"version": "8.0.0-rc11", | ||
"version": "8.0.0-rc12", | ||
"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-rc11", | ||
"embla-carousel-reactive-utils": "8.0.0-rc11" | ||
"embla-carousel": "8.0.0-rc12", | ||
"embla-carousel-reactive-utils": "8.0.0-rc12" | ||
}, | ||
@@ -63,0 +63,0 @@ "peerDependencies": { |
@@ -9,7 +9,7 @@ <br /> | ||
<p align="center"> | ||
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/npm/l/embla-carousel?color=%238ab4f8"></a> | ||
<a href="https://www.npmjs.com/package/embla-carousel-vue"><img src="https://img.shields.io/npm/v/embla-carousel-vue.svg?color=%23c1a8e2"></a> | ||
<a href="https://github.com/davidjerleke/embla-carousel/actions?query=workflow%3A%22Continuous+Integration%22"><img src="https://img.shields.io/github/actions/workflow/status/davidjerleke/embla-carousel/cd.yml?color=%238ab4f8"></a> | ||
<a href="https://prettier.io"><img src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat&color=%23c1a8e2"></a> | ||
<a href="https://bundlephobia.com/result?p=embla-carousel-vue@latest"><img src="https://img.shields.io/bundlephobia/minzip/embla-carousel-vue?color=%238ab4f8&label=gzip%20size"> | ||
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/npm/l/embla-carousel?color=%238ab4f8&style=flat-square"></a> | ||
<a href="https://www.npmjs.com/package/embla-carousel-vue"><img src="https://img.shields.io/npm/v/embla-carousel-vue.svg?color=%23c1a8e2&style=flat-square"></a> | ||
<a href="https://github.com/davidjerleke/embla-carousel/actions?query=workflow%3A%22Continuous+Integration%22"><img src="https://img.shields.io/github/actions/workflow/status/davidjerleke/embla-carousel/cd.yml?color=%238ab4f8&style=flat-square"></a> | ||
<a href="https://prettier.io"><img src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg?color=%23c1a8e2&style=flat-square"></a> | ||
<a href="https://bundlephobia.com/result?p=embla-carousel-vue@latest"><img src="https://img.shields.io/bundlephobia/minzip/embla-carousel-vue?color=%238ab4f8&style=flat-square&label=gzip%20size"> | ||
</a> | ||
@@ -23,3 +23,3 @@ </p> | ||
<p align="center"> | ||
The <strong>Vue version</strong> of <a href="https://www.embla-carousel.com/">Embla Carousel</a>. | ||
<strong>Embla Carousel</strong> is a bare bones carousel library with great fluid motion and awesome swipe precision. It's library agnostic, dependency free and 100% open source. | ||
</p> | ||
@@ -31,3 +31,3 @@ | ||
<strong> | ||
<code> <a href="https://www.embla-carousel.com/get-started/#choose-installation-type">Installation</a> </code> | ||
<code> <a href="https://www.embla-carousel.com/examples/predefined/">Examples</a> </code> | ||
</strong> | ||
@@ -38,3 +38,3 @@ </p> | ||
<strong> | ||
<code> <a href="https://www.embla-carousel.com/api/">API Reference</a> </code> | ||
<code> <a href="https://www.embla-carousel.com/examples/generator/">Generator</a> </code> | ||
</strong> | ||
@@ -45,3 +45,3 @@ </p> | ||
<strong> | ||
<code> <a href="https://www.embla-carousel.com/examples/static/">Examples</a> </code> | ||
<code> <a href="https://www.embla-carousel.com/get-started/#choose-installation-type">Installation</a> </code> | ||
</strong> | ||
@@ -53,2 +53,82 @@ </p> | ||
<div align="center"> | ||
<strong> | ||
<h2 align="center">Ready for</h2> | ||
</strong> | ||
<p align="center"> | ||
<a href="https://www.embla-carousel.com/get-started/module/"> | ||
<img src="https://www.embla-carousel.com/javascript-logo.svg" width="40" height="40" /> | ||
</a> | ||
| ||
<a href="https://www.embla-carousel.com/get-started/module/"> | ||
<img src="https://www.embla-carousel.com/typescript-logo.svg" width="40" height="40" /> | ||
</a> | ||
| ||
<a href="https://www.embla-carousel.com/get-started/react/"> | ||
<img src="https://www.embla-carousel.com/react-logo.svg" width="40" height="40" /> | ||
</a> | ||
| ||
<a href="https://www.embla-carousel.com/get-started/vue/"> | ||
<img src="https://www.embla-carousel.com/vue-logo.svg" width="40" height="40" /> | ||
| ||
<a href="https://www.embla-carousel.com/get-started/svelte/"> | ||
<img src="https://www.embla-carousel.com/svelte-logo.svg" width="40" height="40" /> | ||
</a> | ||
</p> | ||
</div> | ||
<br> | ||
<div align="center"> | ||
<strong> | ||
<h2 align="center">Contributors</h2> | ||
</strong> | ||
<p align="center"> | ||
Thank you to all contributors for making <a href="https://www.embla-carousel.com/">Embla Carousel</a> awesome! <a href="https://github.com/davidjerleke/embla-carousel/blob/master/.github/CONTRIBUTING.md">Contributions</a> are welcome. | ||
</p> | ||
<p align="center"> | ||
<a href="https://github.com/nikrowell"><img src="https://avatars2.githubusercontent.com/u/260039?s=120&v=4" title="nikrowell" width="50" height="50" style="max-width:100%;"></a> | ||
<a href="https://github.com/michaelrambeau"><img src="https://avatars0.githubusercontent.com/u/5546996?s=120&v=4" title="michaelrambeau" width="50" height="50" style="max-width:100%;"></a> | ||
<a href="https://github.com/ehellman"><img src="https://avatars3.githubusercontent.com/u/586152?s=120&v=4" title="ehellman" width="50" height="50" style="max-width:100%;"></a> | ||
<a href="https://github.com/afilp"><img src="https://avatars0.githubusercontent.com/u/7850073?s=120&v=4" title="afilp" width="50" height="50" style="max-width:100%;"></a> | ||
<a href="https://github.com/mrksmts"><img src="https://avatars1.githubusercontent.com/u/437794?s=120&v=4" title="mrksmts" width="50" height="50" style="max-width:100%;"></a> | ||
<a href="https://github.com/SLMNBJ"><img src="https://avatars2.githubusercontent.com/u/30017004?s=120&v=4" title="SLMNBJ" width="50" height="50" style="max-width:100%;"></a> | ||
<a href="https://github.com/readeral"><img src="https://avatars0.githubusercontent.com/u/15904136?s=120&v=4" title="readeral" width="50" height="50" style="max-width:100%;"></a> | ||
<a href="https://github.com/romellem"><img src="https://avatars2.githubusercontent.com/u/8504000?s=120&v=4" title="romellem" width="50" height="50" style="max-width:100%;"></a> | ||
<a href="https://github.com/niubsta"><img src="https://avatars0.githubusercontent.com/u/270320?s=120&v=4" title="niubsta" width="50" height="50" style="max-width:100%;"></a> | ||
<a href="https://github.com/allen-garvey"><img src="https://avatars1.githubusercontent.com/u/9314727?s=120s&v=4" title="allen-garvey" width="50" height="50" style="max-width:100%;"></a> | ||
<a href="https://github.com/sedlukha"><img src="https://avatars3.githubusercontent.com/u/14075940?s=120&v=4" title="sedlukha" width="50" height="50" style="max-width:100%;"></a> | ||
<a href="https://github.com/wopian"><img src="https://avatars3.githubusercontent.com/u/3440094?s=120&v=4" title="wopian" width="50" height="50" style="max-width:100%;"></a> | ||
<a href="https://github.com/msallent"><img src="https://avatars3.githubusercontent.com/u/8879212?s=120&v=4" title="msallent" width="50" height="50" style="max-width:100%;"></a> | ||
<a href="https://github.com/omarkhatibco"><img src="https://avatars1.githubusercontent.com/u/9054278?s=120&v=4" title="omarkhatibco" width="50" height="50" style="max-width:100%;"></a> | ||
<a href="https://github.com/ppromerojr"><img src="https://avatars1.githubusercontent.com/u/15343254?s=120&v=4" title="ppromerojr" width="50" height="50" style="max-width:100%;"></a> | ||
<a href="https://github.com/openscript"><img src="https://avatars3.githubusercontent.com/u/1105080?s=120&v=4" title="openscript" width="50" height="50" style="max-width:100%;"></a> | ||
<a href="https://github.com/pipisasa"><img src="https://avatars.githubusercontent.com/u/54534600?s=120&v=4" title="pipisasa" width="50" height="50" style="max-width:100%;"></a> | ||
<a href="https://github.com/silllli"><img src="https://avatars.githubusercontent.com/u/9334305?s=120&v=4" title="silllli" width="50" height="50" style="max-width:100%;"></a> | ||
<a href="https://github.com/JoshuaCrewe"><img src="https://avatars.githubusercontent.com/u/12238901?s=120&v=4" title="JoshuaCrewe" width="50" height="50" style="max-width:100%;"></a> | ||
<a href="https://github.com/th-km"><img src="https://avatars.githubusercontent.com/u/35410212?s=120&v=4" title="th-km" width="50" height="50" style="max-width:100%;"></a> | ||
<a href="https://github.com/rojadesign"><img src="https://avatars.githubusercontent.com/u/35687281?s=120&v=4" title="th-km"" width="50" height="50" style="max-width:100%;"></a> | ||
<a href="https://github.com/SaizFerri"><img src="https://avatars.githubusercontent.com/u/19834971?s=120&v=4" title="SaizFerri" width="50" height="50" style="max-width:100%;"></a> | ||
<a href="https://github.com/horseeyephil"><img src="https://avatars.githubusercontent.com/u/32337092?s=120&v=4" title="horseeyephil" width="50" height="50" style="max-width:100%;"></a> | ||
</p> | ||
</div> | ||
<br> | ||
<div align="center"> | ||
<strong> | ||
<h2 align="center">Special Thanks</h2> | ||
</strong> | ||
<p align="center"> | ||
Massive thanks to <a href="https://github.com/gunnarx2">gunnarx2</a> for creating the <a href="https://www.embla-carousel.com/get-started/react/">useEmblaCarousel </a> hook and to <a href="https://github.com/xiel">xiel</a> for creating the <a href="https://github.com/xiel/embla-carousel-wheel-gestures">Embla Carousel Wheel Gestures</a> package. | ||
</p> | ||
<p align="center"> | ||
<a href="https://github.com/gunnarx2"><img src="https://avatars2.githubusercontent.com/u/10469652?s=120&v=4" title="gunnarx2" width="50" height="50" style="max-width:100%;"></a> | ||
<a href="https://github.com/xiel"><img src="https://avatars0.githubusercontent.com/u/615522?s=120&v=4" title="xiel" width="50" height="50" style="max-width:100%;"></a> | ||
</p> | ||
</div> | ||
<br> | ||
<h2 align="center">Open Source</h2> | ||
@@ -55,0 +135,0 @@ |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
148
33670
170
3
1
+ Addedembla-carousel@8.0.0-rc12(transitive)
+ Addedembla-carousel-reactive-utils@8.0.0-rc12(transitive)
- Removedembla-carousel@8.0.0-rc11(transitive)
- Removedembla-carousel-reactive-utils@8.0.0-rc11(transitive)
Updatedembla-carousel@8.0.0-rc12