embla-carousel
Advanced tools
Comparing version 4.0.6 to 4.1.0
@@ -101,2 +101,51 @@ function _extends() { | ||
function map(value, iStart, iStop, oStart, oStop) { | ||
return oStart + (oStop - oStart) * ((value - iStart) / (iStop - iStart)); | ||
} | ||
function mathSign(n) { | ||
return !n ? 0 : n / Math.abs(n); | ||
} | ||
function deltaAbs(valueB, valueA) { | ||
return Math.abs(valueB - valueA); | ||
} | ||
function factorAbs(valueB, valueA) { | ||
if (valueB === 0 || valueA === 0) return 0; | ||
if (Math.abs(valueB) <= Math.abs(valueA)) return 0; | ||
var diff = deltaAbs(Math.abs(valueB), Math.abs(valueA)); | ||
return Math.abs(diff / valueB); | ||
} | ||
function roundToDecimals(decimalPoints) { | ||
var pow = Math.pow(10, decimalPoints); | ||
return function (n) { | ||
return Math.round(n * pow) / pow; | ||
}; | ||
} | ||
function debounce(callback, time) { | ||
var timeout = 0; | ||
return function () { | ||
window.clearTimeout(timeout); | ||
timeout = window.setTimeout(callback, time) || 0; | ||
}; | ||
} | ||
function groupArray(array, size) { | ||
var groups = []; | ||
for (var i = 0; i < array.length; i += size) { | ||
groups.push(array.slice(i, i + size)); | ||
} | ||
return groups; | ||
} | ||
function arrayKeys(array) { | ||
return Object.keys(array).map(Number); | ||
} | ||
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); | ||
} | ||
function Counter(params) { | ||
@@ -123,3 +172,3 @@ var start = params.start, | ||
if (n !== 0) { | ||
var sign = n / Math.abs(n); | ||
var sign = mathSign(n); | ||
set(get() + sign); | ||
@@ -151,51 +200,11 @@ return add(n + sign * -1); | ||
function Vector1D(value) { | ||
var vector = value; | ||
function Direction(direction) { | ||
var sign = direction === 'rtl' ? -1 : 1; | ||
function get() { | ||
return vector; | ||
function applyTo(n) { | ||
return n * sign; | ||
} | ||
function set(n) { | ||
vector = readNumber(n); | ||
return self; | ||
} | ||
function add(n) { | ||
vector += readNumber(n); | ||
return self; | ||
} | ||
function subtract(n) { | ||
vector -= readNumber(n); | ||
return self; | ||
} | ||
function multiply(n) { | ||
vector *= n; | ||
return self; | ||
} | ||
function divide(n) { | ||
vector /= n; | ||
return self; | ||
} | ||
function normalize() { | ||
if (vector !== 0) divide(vector); | ||
return self; | ||
} | ||
function readNumber(n) { | ||
return typeof n === 'number' ? n : n.get(); | ||
} | ||
var self = { | ||
add: add, | ||
divide: divide, | ||
get: get, | ||
multiply: multiply, | ||
normalize: normalize, | ||
set: set, | ||
subtract: subtract | ||
applyTo: applyTo | ||
}; | ||
@@ -205,23 +214,2 @@ return self; | ||
function Direction(value) { | ||
var direction = Vector1D(normalize(value)); | ||
var get = direction.get; | ||
function normalize(n) { | ||
return n === 0 ? 0 : n / Math.abs(n); | ||
} | ||
function set(v) { | ||
var d = normalize(v.get()); | ||
if (d !== 0) direction.set(d); | ||
return self; | ||
} | ||
var self = { | ||
get: get, | ||
set: set | ||
}; | ||
return self; | ||
} | ||
function EventStore() { | ||
@@ -256,53 +244,51 @@ var listeners = []; | ||
function Limit(params) { | ||
var min = params.min, | ||
max = params.max; | ||
var length = Math.abs(min - max); | ||
function Vector1D(value) { | ||
var vector = value; | ||
function reachedMin(n) { | ||
return n < min; | ||
function get() { | ||
return vector; | ||
} | ||
function reachedMax(n) { | ||
return n > max; | ||
function set(n) { | ||
vector = readNumber(n); | ||
return self; | ||
} | ||
function reachedAny(n) { | ||
return reachedMin(n) || reachedMax(n); | ||
function add(n) { | ||
vector += readNumber(n); | ||
return self; | ||
} | ||
function removeOffset(n) { | ||
if (min === max) return n; | ||
function subtract(n) { | ||
vector -= readNumber(n); | ||
return self; | ||
} | ||
while (reachedMin(n)) { | ||
n += length; | ||
} | ||
function multiply(n) { | ||
vector *= n; | ||
return self; | ||
} | ||
while (reachedMax(n)) { | ||
n -= length; | ||
} | ||
return n; | ||
function divide(n) { | ||
vector /= n; | ||
return self; | ||
} | ||
function loop(n) { | ||
if (!reachedAny(n)) return n; | ||
return reachedMin(n) ? max : min; | ||
function normalize() { | ||
if (vector !== 0) divide(vector); | ||
return self; | ||
} | ||
function constrain(n) { | ||
if (!reachedAny(n)) return n; | ||
return reachedMin(n) ? min : max; | ||
function readNumber(n) { | ||
return typeof n === 'number' ? n : n.get(); | ||
} | ||
var self = { | ||
constrain: constrain, | ||
length: length, | ||
loop: loop, | ||
max: max, | ||
min: min, | ||
reachedAny: reachedAny, | ||
reachedMax: reachedMax, | ||
reachedMin: reachedMin, | ||
removeOffset: removeOffset | ||
add: add, | ||
divide: divide, | ||
get: get, | ||
multiply: multiply, | ||
normalize: normalize, | ||
set: set, | ||
subtract: subtract | ||
}; | ||
@@ -317,8 +303,10 @@ return self; | ||
animation = params.animation, | ||
axis = params.axis; | ||
var element = params.element, | ||
axis = params.axis, | ||
scrollTo = params.scrollTo; | ||
var root = params.root, | ||
dragTracker = params.dragTracker, | ||
location = params.location, | ||
events = params.events, | ||
limit = params.limit; | ||
limit = params.limit, | ||
direction = params.direction; | ||
var scrollAxis = axis.scroll, | ||
@@ -342,6 +330,2 @@ crossAxis = axis.cross; | ||
var dragThreshold = 4; | ||
var edgeLimit = Limit({ | ||
min: limit.min - 70, | ||
max: limit.max + 70 | ||
}); | ||
var pointerIsDown = false; | ||
@@ -353,3 +337,3 @@ var preventScroll = false; | ||
function addActivationEvents() { | ||
var node = element; | ||
var node = root; | ||
activationEvents.add(node, 'touchmove', function () { | ||
@@ -363,3 +347,3 @@ return undefined; | ||
function addInteractionEvents() { | ||
var node = !isMouse ? element : document; | ||
var node = !isMouse ? root : document; | ||
interactionEvents.add(node, 'touchmove', move).add(node, 'touchend', up).add(node, 'mousemove', move).add(node, 'mouseup', up); | ||
@@ -384,9 +368,2 @@ } | ||
function speedFactor(forceB, forceA) { | ||
var diff = delta(Math.abs(forceB), Math.abs(forceA)); | ||
if (Math.abs(forceB) <= Math.abs(forceA)) return 0; | ||
if (forceB === 0 || forceA === 0) return 0; | ||
return Math.abs(diff / forceB); | ||
} | ||
function allowedForce(force) { | ||
@@ -401,11 +378,6 @@ var scrollTarget = params.scrollTarget, | ||
if (seekNext && !dragFree && !limit.reachedAny(destination)) { | ||
var next = index.clone().add(Direction(force).get() * -1); | ||
var next = index.clone().add(mathSign(force) * -1); | ||
return scrollTarget.byIndex(next.get(), 0).distance; | ||
} | ||
if (!params.loop && edgeLimit.reachedAny(destination)) { | ||
var edge = edgeLimit.reachedMax(destination) ? 'max' : 'min'; | ||
return edgeLimit[edge] - target.get(); | ||
} | ||
return scrollTarget.byDistance(force, !dragFree).distance; | ||
@@ -417,3 +389,3 @@ } | ||
if (isMouse && evt.button !== 0) return; | ||
var isMoving = delta(target.get(), location.get()) >= 2; | ||
var isMoving = deltaAbs(target.get(), location.get()) >= 2; | ||
var clearPreventClick = isMouse || !isMoving; | ||
@@ -440,4 +412,4 @@ var isNotFocusNode = !isFocusNode(evt.target); | ||
var moveCross = dragTracker.readPoint(evt, crossAxis).get(); | ||
var diffScroll = delta(moveScroll, startScroll.get()); | ||
var diffCross = delta(moveCross, startCross.get()); | ||
var diffScroll = deltaAbs(moveScroll, startScroll.get()); | ||
var diffCross = deltaAbs(moveCross, startCross.get()); | ||
preventScroll = diffScroll > diffCross; | ||
@@ -449,6 +421,6 @@ if (!preventScroll && !preventClick) return up(); | ||
var reachedLimit = limit.reachedAny(location.get()); | ||
var resist = !params.loop && reachedLimit ? 2 : 1; | ||
var resist = !params.loop && reachedLimit ? 4 : 1; | ||
if (!preventClick && diff) preventClick = true; | ||
animation.start(); | ||
target.add(diff / resist); | ||
target.add(direction.applyTo(diff / resist)); | ||
evt.preventDefault(); | ||
@@ -458,7 +430,6 @@ } | ||
function up() { | ||
var scrollTo = params.scrollTo; | ||
var rawForce = dragTracker.pointerUp() * forceBoost(); | ||
var force = allowedForce(rawForce); | ||
var factor = speedFactor(rawForce, force); | ||
var isMoving = delta(target.get(), dragStartPoint.get()) >= 0.5; | ||
var force = allowedForce(direction.applyTo(rawForce)); | ||
var speedFactor = factorAbs(rawForce, force); | ||
var isMoving = deltaAbs(target.get(), dragStartPoint.get()) >= 0.5; | ||
if (isMoving && !isMouse) preventClick = true; | ||
@@ -468,3 +439,3 @@ preventScroll = false; | ||
interactionEvents.removeAll(); | ||
scrollBody.useSpeed(baseSpeed + baseSpeed * factor); | ||
scrollBody.useSpeed(baseSpeed + baseSpeed * speedFactor); | ||
scrollTo.distance(force, !dragFree); | ||
@@ -475,6 +446,2 @@ isMouse = false; | ||
function delta(pointB, pointA) { | ||
return Math.abs(pointB - pointA); | ||
} | ||
function click(evt) { | ||
@@ -573,2 +540,57 @@ if (preventClick) evt.preventDefault(); | ||
function Limit(params) { | ||
var min = params.min, | ||
max = params.max; | ||
var length = Math.abs(min - max); | ||
function reachedMin(n) { | ||
return n < min; | ||
} | ||
function reachedMax(n) { | ||
return n > max; | ||
} | ||
function reachedAny(n) { | ||
return reachedMin(n) || reachedMax(n); | ||
} | ||
function removeOffset(n) { | ||
if (min === max) return n; | ||
while (reachedMin(n)) { | ||
n += length; | ||
} | ||
while (reachedMax(n)) { | ||
n -= length; | ||
} | ||
return n; | ||
} | ||
function loop(n) { | ||
if (!reachedAny(n)) return n; | ||
return reachedMin(n) ? max : min; | ||
} | ||
function constrain(n) { | ||
if (!reachedAny(n)) return n; | ||
return reachedMin(n) ? min : max; | ||
} | ||
var self = { | ||
constrain: constrain, | ||
length: length, | ||
loop: loop, | ||
max: max, | ||
min: min, | ||
reachedAny: reachedAny, | ||
reachedMax: reachedMax, | ||
reachedMin: reachedMin, | ||
removeOffset: removeOffset | ||
}; | ||
return self; | ||
} | ||
function PxToPercent(viewInPx) { | ||
@@ -588,44 +610,2 @@ var totalPercent = 100; | ||
function map(value, iStart, iStop, oStart, oStop) { | ||
return oStart + (oStop - oStart) * ((value - iStart) / (iStop - iStart)); | ||
} | ||
function arrayFromCollection(nodeList) { | ||
return Array.prototype.slice.call(nodeList); | ||
} | ||
function debounce(callback, time) { | ||
var timeout = { | ||
id: 0 | ||
}; | ||
return function () { | ||
window.clearTimeout(timeout.id); | ||
timeout.id = window.setTimeout(callback, time) || 0; | ||
}; | ||
} | ||
function roundToDecimals(decimalPoints) { | ||
var pow = Math.pow(10, decimalPoints); | ||
return function (n) { | ||
return Math.round(n * pow) / pow; | ||
}; | ||
} | ||
function groupArray(array, size) { | ||
var groups = []; | ||
for (var i = 0; i < array.length; i += size) { | ||
groups.push(array.slice(i, i + size)); | ||
} | ||
return groups; | ||
} | ||
function arrayKeys(array) { | ||
return Object.keys(array).map(Number); | ||
} | ||
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); | ||
} | ||
function ScrollBody(params) { | ||
@@ -639,3 +619,3 @@ var location = params.location, | ||
var attraction = Vector1D(0); | ||
var direction = Direction(0); | ||
var attractionDirection = 0; | ||
var speed = baseSpeed; | ||
@@ -659,3 +639,3 @@ var mass = baseMass; | ||
var m = map(magnitude, 0, 100, 0, speed); | ||
direction.set(attraction); | ||
attractionDirection = mathSign(attraction.get()); | ||
attraction.normalize().multiply(m).subtract(velocity); | ||
@@ -674,2 +654,6 @@ applyForce(attraction); | ||
function direction() { | ||
return attractionDirection; | ||
} | ||
function useSpeed(n) { | ||
@@ -712,25 +696,30 @@ speed = n; | ||
var min = limit.min, | ||
max = limit.max, | ||
reachedMin = limit.reachedMin, | ||
reachedMax = limit.reachedMax; | ||
var tolerance = 50; | ||
max = limit.max; | ||
var tolerance = 70; | ||
var edgeLimit = Limit({ | ||
min: min - tolerance, | ||
max: max + tolerance | ||
}); | ||
var disabled = false; | ||
var timeout = 0; | ||
function shouldConstrain(v) { | ||
if (disabled || timeout) return false; | ||
if (reachedMin(location.get())) return v.get() !== min; | ||
if (reachedMax(location.get())) return v.get() !== max; | ||
return false; | ||
function shouldConstrain(target) { | ||
if (disabled) return false; | ||
if (!limit.reachedAny(location.get())) return false; | ||
if (target.get() === min || target.get() === max) return false; | ||
return true; | ||
} | ||
function constrain(v) { | ||
if (!shouldConstrain(v)) return; | ||
timeout = window.setTimeout(function () { | ||
var constraint = limit.constrain(v.get()); | ||
v.set(constraint); | ||
scrollBody.useSpeed(10).useMass(3); | ||
animation.start(); | ||
timeout = 0; | ||
}, tolerance); | ||
function constrain(target) { | ||
if (!shouldConstrain(target)) return; | ||
target.set(edgeLimit.constrain(target.get())); | ||
if (!timeout) { | ||
timeout = window.setTimeout(function () { | ||
target.set(limit.constrain(target.get())); | ||
scrollBody.useSpeed(10).useMass(3); | ||
animation.start(); | ||
timeout = 0; | ||
}, tolerance); | ||
} | ||
} | ||
@@ -1029,3 +1018,4 @@ | ||
scrollLocation = params.location, | ||
slidesInView = params.slidesInView; | ||
slidesInView = params.slidesInView, | ||
direction = params.direction; | ||
var contentSize = params.contentSize, | ||
@@ -1108,3 +1098,3 @@ viewSize = params.viewSize, | ||
if (target !== location) { | ||
slides[index].style[loopStyle] = target + "%"; | ||
slides[index].style[loopStyle] = direction.applyTo(target) + "%"; | ||
loopPoint.location = target; | ||
@@ -1222,10 +1212,7 @@ } | ||
var axis = params.axis, | ||
container = params.container; | ||
var translates = { | ||
x: x, | ||
y: y | ||
}; | ||
var translateAxis = translates[axis.scroll]; | ||
container = params.container, | ||
direction = params.direction; | ||
var containerStyle = container.style; | ||
var translate = axis.scroll === 'x' ? x : y; | ||
var roundToTwoDecimals = roundToDecimals(2); | ||
var containerStyle = container.style; | ||
var disabled = false; | ||
@@ -1243,10 +1230,7 @@ var location = 0; | ||
function to(v) { | ||
if (disabled) return; | ||
var target = roundToTwoDecimals(v.get()); | ||
if (location !== target) { | ||
getComputedStyle(container).transform; | ||
containerStyle.transform = translateAxis(target); | ||
location = target; | ||
} | ||
if (disabled || location === target) return; | ||
getComputedStyle(container).transform; | ||
containerStyle.transform = translate(direction.applyTo(target)); | ||
location = target; | ||
} | ||
@@ -1275,2 +1259,3 @@ | ||
scrollAxis = options.axis, | ||
contentDirection = options.direction, | ||
startIndex = options.startIndex, | ||
@@ -1316,3 +1301,9 @@ inViewThreshold = options.inViewThreshold, | ||
var containedSnaps = contain.measure(defaultSnaps, trimSnaps); | ||
var scrollSnaps = shouldContain ? containedSnaps : defaultSnaps; // Index | ||
var scrollSnaps = shouldContain ? containedSnaps : defaultSnaps; | ||
var scrollLimit = ScrollLimit({ | ||
loop: loop, | ||
contentSize: contentSize | ||
}); | ||
var limit = scrollLimit.measure(scrollSnaps); | ||
var direction = Direction(contentDirection); // Index | ||
@@ -1329,10 +1320,4 @@ var indexMax = Math.max(0, scrollSnaps.length - 1); | ||
}); | ||
var indexPrevious = index.clone(); // ScrollLimit | ||
var indexPrevious = index.clone(); // Draw | ||
var scrollLimit = ScrollLimit({ | ||
loop: loop, | ||
contentSize: contentSize | ||
}); | ||
var limit = scrollLimit.measure(scrollSnaps); // Draw | ||
var update = function update() { | ||
@@ -1342,3 +1327,3 @@ engine.scrollBody.seek(target).update(); | ||
if (!dragHandler.pointerDown()) { | ||
if (!engine.dragHandler.pointerDown()) { | ||
if (!loop) engine.scrollBounds.constrain(target); | ||
@@ -1353,4 +1338,3 @@ | ||
if (loop) { | ||
var direction = engine.scrollBody.direction.get(); | ||
engine.scrollLooper.loop(loopVectors, direction); | ||
engine.scrollLooper.loop(loopVectors, engine.scrollBody.direction()); | ||
engine.slideLooper.loop(slides); | ||
@@ -1402,2 +1386,3 @@ } | ||
axis: axis, | ||
direction: direction, | ||
dragFree: dragFree, | ||
@@ -1408,3 +1393,3 @@ dragTracker: DragTracker({ | ||
}), | ||
element: root, | ||
root: root, | ||
events: events, | ||
@@ -1424,2 +1409,3 @@ index: index, | ||
axis: axis, | ||
direction: direction, | ||
dragHandler: dragHandler, | ||
@@ -1459,2 +1445,3 @@ pxToPercent: pxToPercent, | ||
contentSize: contentSize, | ||
direction: direction, | ||
location: location, | ||
@@ -1471,3 +1458,4 @@ scrollSnaps: scrollSnaps, | ||
axis: axis, | ||
container: container | ||
container: container, | ||
direction: direction | ||
}) | ||
@@ -1523,2 +1511,3 @@ }; | ||
containerSelector: '*', | ||
direction: 'ltr', | ||
dragFree: false, | ||
@@ -1559,3 +1548,3 @@ draggable: true, | ||
container = sliderContainer; | ||
slides = arrayFromCollection(container.children); | ||
slides = Array.prototype.slice.call(container.children); | ||
} | ||
@@ -1562,0 +1551,0 @@ |
@@ -103,2 +103,51 @@ 'use strict'; | ||
function map(value, iStart, iStop, oStart, oStop) { | ||
return oStart + (oStop - oStart) * ((value - iStart) / (iStop - iStart)); | ||
} | ||
function mathSign(n) { | ||
return !n ? 0 : n / Math.abs(n); | ||
} | ||
function deltaAbs(valueB, valueA) { | ||
return Math.abs(valueB - valueA); | ||
} | ||
function factorAbs(valueB, valueA) { | ||
if (valueB === 0 || valueA === 0) return 0; | ||
if (Math.abs(valueB) <= Math.abs(valueA)) return 0; | ||
var diff = deltaAbs(Math.abs(valueB), Math.abs(valueA)); | ||
return Math.abs(diff / valueB); | ||
} | ||
function roundToDecimals(decimalPoints) { | ||
var pow = Math.pow(10, decimalPoints); | ||
return function (n) { | ||
return Math.round(n * pow) / pow; | ||
}; | ||
} | ||
function debounce(callback, time) { | ||
var timeout = 0; | ||
return function () { | ||
window.clearTimeout(timeout); | ||
timeout = window.setTimeout(callback, time) || 0; | ||
}; | ||
} | ||
function groupArray(array, size) { | ||
var groups = []; | ||
for (var i = 0; i < array.length; i += size) { | ||
groups.push(array.slice(i, i + size)); | ||
} | ||
return groups; | ||
} | ||
function arrayKeys(array) { | ||
return Object.keys(array).map(Number); | ||
} | ||
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); | ||
} | ||
function Counter(params) { | ||
@@ -125,3 +174,3 @@ var start = params.start, | ||
if (n !== 0) { | ||
var sign = n / Math.abs(n); | ||
var sign = mathSign(n); | ||
set(get() + sign); | ||
@@ -153,51 +202,11 @@ return add(n + sign * -1); | ||
function Vector1D(value) { | ||
var vector = value; | ||
function Direction(direction) { | ||
var sign = direction === 'rtl' ? -1 : 1; | ||
function get() { | ||
return vector; | ||
function applyTo(n) { | ||
return n * sign; | ||
} | ||
function set(n) { | ||
vector = readNumber(n); | ||
return self; | ||
} | ||
function add(n) { | ||
vector += readNumber(n); | ||
return self; | ||
} | ||
function subtract(n) { | ||
vector -= readNumber(n); | ||
return self; | ||
} | ||
function multiply(n) { | ||
vector *= n; | ||
return self; | ||
} | ||
function divide(n) { | ||
vector /= n; | ||
return self; | ||
} | ||
function normalize() { | ||
if (vector !== 0) divide(vector); | ||
return self; | ||
} | ||
function readNumber(n) { | ||
return typeof n === 'number' ? n : n.get(); | ||
} | ||
var self = { | ||
add: add, | ||
divide: divide, | ||
get: get, | ||
multiply: multiply, | ||
normalize: normalize, | ||
set: set, | ||
subtract: subtract | ||
applyTo: applyTo | ||
}; | ||
@@ -207,23 +216,2 @@ return self; | ||
function Direction(value) { | ||
var direction = Vector1D(normalize(value)); | ||
var get = direction.get; | ||
function normalize(n) { | ||
return n === 0 ? 0 : n / Math.abs(n); | ||
} | ||
function set(v) { | ||
var d = normalize(v.get()); | ||
if (d !== 0) direction.set(d); | ||
return self; | ||
} | ||
var self = { | ||
get: get, | ||
set: set | ||
}; | ||
return self; | ||
} | ||
function EventStore() { | ||
@@ -258,53 +246,51 @@ var listeners = []; | ||
function Limit(params) { | ||
var min = params.min, | ||
max = params.max; | ||
var length = Math.abs(min - max); | ||
function Vector1D(value) { | ||
var vector = value; | ||
function reachedMin(n) { | ||
return n < min; | ||
function get() { | ||
return vector; | ||
} | ||
function reachedMax(n) { | ||
return n > max; | ||
function set(n) { | ||
vector = readNumber(n); | ||
return self; | ||
} | ||
function reachedAny(n) { | ||
return reachedMin(n) || reachedMax(n); | ||
function add(n) { | ||
vector += readNumber(n); | ||
return self; | ||
} | ||
function removeOffset(n) { | ||
if (min === max) return n; | ||
function subtract(n) { | ||
vector -= readNumber(n); | ||
return self; | ||
} | ||
while (reachedMin(n)) { | ||
n += length; | ||
} | ||
function multiply(n) { | ||
vector *= n; | ||
return self; | ||
} | ||
while (reachedMax(n)) { | ||
n -= length; | ||
} | ||
return n; | ||
function divide(n) { | ||
vector /= n; | ||
return self; | ||
} | ||
function loop(n) { | ||
if (!reachedAny(n)) return n; | ||
return reachedMin(n) ? max : min; | ||
function normalize() { | ||
if (vector !== 0) divide(vector); | ||
return self; | ||
} | ||
function constrain(n) { | ||
if (!reachedAny(n)) return n; | ||
return reachedMin(n) ? min : max; | ||
function readNumber(n) { | ||
return typeof n === 'number' ? n : n.get(); | ||
} | ||
var self = { | ||
constrain: constrain, | ||
length: length, | ||
loop: loop, | ||
max: max, | ||
min: min, | ||
reachedAny: reachedAny, | ||
reachedMax: reachedMax, | ||
reachedMin: reachedMin, | ||
removeOffset: removeOffset | ||
add: add, | ||
divide: divide, | ||
get: get, | ||
multiply: multiply, | ||
normalize: normalize, | ||
set: set, | ||
subtract: subtract | ||
}; | ||
@@ -319,8 +305,10 @@ return self; | ||
animation = params.animation, | ||
axis = params.axis; | ||
var element = params.element, | ||
axis = params.axis, | ||
scrollTo = params.scrollTo; | ||
var root = params.root, | ||
dragTracker = params.dragTracker, | ||
location = params.location, | ||
events = params.events, | ||
limit = params.limit; | ||
limit = params.limit, | ||
direction = params.direction; | ||
var scrollAxis = axis.scroll, | ||
@@ -344,6 +332,2 @@ crossAxis = axis.cross; | ||
var dragThreshold = 4; | ||
var edgeLimit = Limit({ | ||
min: limit.min - 70, | ||
max: limit.max + 70 | ||
}); | ||
var pointerIsDown = false; | ||
@@ -355,3 +339,3 @@ var preventScroll = false; | ||
function addActivationEvents() { | ||
var node = element; | ||
var node = root; | ||
activationEvents.add(node, 'touchmove', function () { | ||
@@ -365,3 +349,3 @@ return undefined; | ||
function addInteractionEvents() { | ||
var node = !isMouse ? element : document; | ||
var node = !isMouse ? root : document; | ||
interactionEvents.add(node, 'touchmove', move).add(node, 'touchend', up).add(node, 'mousemove', move).add(node, 'mouseup', up); | ||
@@ -386,9 +370,2 @@ } | ||
function speedFactor(forceB, forceA) { | ||
var diff = delta(Math.abs(forceB), Math.abs(forceA)); | ||
if (Math.abs(forceB) <= Math.abs(forceA)) return 0; | ||
if (forceB === 0 || forceA === 0) return 0; | ||
return Math.abs(diff / forceB); | ||
} | ||
function allowedForce(force) { | ||
@@ -403,11 +380,6 @@ var scrollTarget = params.scrollTarget, | ||
if (seekNext && !dragFree && !limit.reachedAny(destination)) { | ||
var next = index.clone().add(Direction(force).get() * -1); | ||
var next = index.clone().add(mathSign(force) * -1); | ||
return scrollTarget.byIndex(next.get(), 0).distance; | ||
} | ||
if (!params.loop && edgeLimit.reachedAny(destination)) { | ||
var edge = edgeLimit.reachedMax(destination) ? 'max' : 'min'; | ||
return edgeLimit[edge] - target.get(); | ||
} | ||
return scrollTarget.byDistance(force, !dragFree).distance; | ||
@@ -419,3 +391,3 @@ } | ||
if (isMouse && evt.button !== 0) return; | ||
var isMoving = delta(target.get(), location.get()) >= 2; | ||
var isMoving = deltaAbs(target.get(), location.get()) >= 2; | ||
var clearPreventClick = isMouse || !isMoving; | ||
@@ -442,4 +414,4 @@ var isNotFocusNode = !isFocusNode(evt.target); | ||
var moveCross = dragTracker.readPoint(evt, crossAxis).get(); | ||
var diffScroll = delta(moveScroll, startScroll.get()); | ||
var diffCross = delta(moveCross, startCross.get()); | ||
var diffScroll = deltaAbs(moveScroll, startScroll.get()); | ||
var diffCross = deltaAbs(moveCross, startCross.get()); | ||
preventScroll = diffScroll > diffCross; | ||
@@ -451,6 +423,6 @@ if (!preventScroll && !preventClick) return up(); | ||
var reachedLimit = limit.reachedAny(location.get()); | ||
var resist = !params.loop && reachedLimit ? 2 : 1; | ||
var resist = !params.loop && reachedLimit ? 4 : 1; | ||
if (!preventClick && diff) preventClick = true; | ||
animation.start(); | ||
target.add(diff / resist); | ||
target.add(direction.applyTo(diff / resist)); | ||
evt.preventDefault(); | ||
@@ -460,7 +432,6 @@ } | ||
function up() { | ||
var scrollTo = params.scrollTo; | ||
var rawForce = dragTracker.pointerUp() * forceBoost(); | ||
var force = allowedForce(rawForce); | ||
var factor = speedFactor(rawForce, force); | ||
var isMoving = delta(target.get(), dragStartPoint.get()) >= 0.5; | ||
var force = allowedForce(direction.applyTo(rawForce)); | ||
var speedFactor = factorAbs(rawForce, force); | ||
var isMoving = deltaAbs(target.get(), dragStartPoint.get()) >= 0.5; | ||
if (isMoving && !isMouse) preventClick = true; | ||
@@ -470,3 +441,3 @@ preventScroll = false; | ||
interactionEvents.removeAll(); | ||
scrollBody.useSpeed(baseSpeed + baseSpeed * factor); | ||
scrollBody.useSpeed(baseSpeed + baseSpeed * speedFactor); | ||
scrollTo.distance(force, !dragFree); | ||
@@ -477,6 +448,2 @@ isMouse = false; | ||
function delta(pointB, pointA) { | ||
return Math.abs(pointB - pointA); | ||
} | ||
function click(evt) { | ||
@@ -575,2 +542,57 @@ if (preventClick) evt.preventDefault(); | ||
function Limit(params) { | ||
var min = params.min, | ||
max = params.max; | ||
var length = Math.abs(min - max); | ||
function reachedMin(n) { | ||
return n < min; | ||
} | ||
function reachedMax(n) { | ||
return n > max; | ||
} | ||
function reachedAny(n) { | ||
return reachedMin(n) || reachedMax(n); | ||
} | ||
function removeOffset(n) { | ||
if (min === max) return n; | ||
while (reachedMin(n)) { | ||
n += length; | ||
} | ||
while (reachedMax(n)) { | ||
n -= length; | ||
} | ||
return n; | ||
} | ||
function loop(n) { | ||
if (!reachedAny(n)) return n; | ||
return reachedMin(n) ? max : min; | ||
} | ||
function constrain(n) { | ||
if (!reachedAny(n)) return n; | ||
return reachedMin(n) ? min : max; | ||
} | ||
var self = { | ||
constrain: constrain, | ||
length: length, | ||
loop: loop, | ||
max: max, | ||
min: min, | ||
reachedAny: reachedAny, | ||
reachedMax: reachedMax, | ||
reachedMin: reachedMin, | ||
removeOffset: removeOffset | ||
}; | ||
return self; | ||
} | ||
function PxToPercent(viewInPx) { | ||
@@ -590,44 +612,2 @@ var totalPercent = 100; | ||
function map(value, iStart, iStop, oStart, oStop) { | ||
return oStart + (oStop - oStart) * ((value - iStart) / (iStop - iStart)); | ||
} | ||
function arrayFromCollection(nodeList) { | ||
return Array.prototype.slice.call(nodeList); | ||
} | ||
function debounce(callback, time) { | ||
var timeout = { | ||
id: 0 | ||
}; | ||
return function () { | ||
window.clearTimeout(timeout.id); | ||
timeout.id = window.setTimeout(callback, time) || 0; | ||
}; | ||
} | ||
function roundToDecimals(decimalPoints) { | ||
var pow = Math.pow(10, decimalPoints); | ||
return function (n) { | ||
return Math.round(n * pow) / pow; | ||
}; | ||
} | ||
function groupArray(array, size) { | ||
var groups = []; | ||
for (var i = 0; i < array.length; i += size) { | ||
groups.push(array.slice(i, i + size)); | ||
} | ||
return groups; | ||
} | ||
function arrayKeys(array) { | ||
return Object.keys(array).map(Number); | ||
} | ||
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); | ||
} | ||
function ScrollBody(params) { | ||
@@ -641,3 +621,3 @@ var location = params.location, | ||
var attraction = Vector1D(0); | ||
var direction = Direction(0); | ||
var attractionDirection = 0; | ||
var speed = baseSpeed; | ||
@@ -661,3 +641,3 @@ var mass = baseMass; | ||
var m = map(magnitude, 0, 100, 0, speed); | ||
direction.set(attraction); | ||
attractionDirection = mathSign(attraction.get()); | ||
attraction.normalize().multiply(m).subtract(velocity); | ||
@@ -676,2 +656,6 @@ applyForce(attraction); | ||
function direction() { | ||
return attractionDirection; | ||
} | ||
function useSpeed(n) { | ||
@@ -714,25 +698,30 @@ speed = n; | ||
var min = limit.min, | ||
max = limit.max, | ||
reachedMin = limit.reachedMin, | ||
reachedMax = limit.reachedMax; | ||
var tolerance = 50; | ||
max = limit.max; | ||
var tolerance = 70; | ||
var edgeLimit = Limit({ | ||
min: min - tolerance, | ||
max: max + tolerance | ||
}); | ||
var disabled = false; | ||
var timeout = 0; | ||
function shouldConstrain(v) { | ||
if (disabled || timeout) return false; | ||
if (reachedMin(location.get())) return v.get() !== min; | ||
if (reachedMax(location.get())) return v.get() !== max; | ||
return false; | ||
function shouldConstrain(target) { | ||
if (disabled) return false; | ||
if (!limit.reachedAny(location.get())) return false; | ||
if (target.get() === min || target.get() === max) return false; | ||
return true; | ||
} | ||
function constrain(v) { | ||
if (!shouldConstrain(v)) return; | ||
timeout = window.setTimeout(function () { | ||
var constraint = limit.constrain(v.get()); | ||
v.set(constraint); | ||
scrollBody.useSpeed(10).useMass(3); | ||
animation.start(); | ||
timeout = 0; | ||
}, tolerance); | ||
function constrain(target) { | ||
if (!shouldConstrain(target)) return; | ||
target.set(edgeLimit.constrain(target.get())); | ||
if (!timeout) { | ||
timeout = window.setTimeout(function () { | ||
target.set(limit.constrain(target.get())); | ||
scrollBody.useSpeed(10).useMass(3); | ||
animation.start(); | ||
timeout = 0; | ||
}, tolerance); | ||
} | ||
} | ||
@@ -1031,3 +1020,4 @@ | ||
scrollLocation = params.location, | ||
slidesInView = params.slidesInView; | ||
slidesInView = params.slidesInView, | ||
direction = params.direction; | ||
var contentSize = params.contentSize, | ||
@@ -1110,3 +1100,3 @@ viewSize = params.viewSize, | ||
if (target !== location) { | ||
slides[index].style[loopStyle] = target + "%"; | ||
slides[index].style[loopStyle] = direction.applyTo(target) + "%"; | ||
loopPoint.location = target; | ||
@@ -1224,10 +1214,7 @@ } | ||
var axis = params.axis, | ||
container = params.container; | ||
var translates = { | ||
x: x, | ||
y: y | ||
}; | ||
var translateAxis = translates[axis.scroll]; | ||
container = params.container, | ||
direction = params.direction; | ||
var containerStyle = container.style; | ||
var translate = axis.scroll === 'x' ? x : y; | ||
var roundToTwoDecimals = roundToDecimals(2); | ||
var containerStyle = container.style; | ||
var disabled = false; | ||
@@ -1245,10 +1232,7 @@ var location = 0; | ||
function to(v) { | ||
if (disabled) return; | ||
var target = roundToTwoDecimals(v.get()); | ||
if (location !== target) { | ||
getComputedStyle(container).transform; | ||
containerStyle.transform = translateAxis(target); | ||
location = target; | ||
} | ||
if (disabled || location === target) return; | ||
getComputedStyle(container).transform; | ||
containerStyle.transform = translate(direction.applyTo(target)); | ||
location = target; | ||
} | ||
@@ -1277,2 +1261,3 @@ | ||
scrollAxis = options.axis, | ||
contentDirection = options.direction, | ||
startIndex = options.startIndex, | ||
@@ -1318,3 +1303,9 @@ inViewThreshold = options.inViewThreshold, | ||
var containedSnaps = contain.measure(defaultSnaps, trimSnaps); | ||
var scrollSnaps = shouldContain ? containedSnaps : defaultSnaps; // Index | ||
var scrollSnaps = shouldContain ? containedSnaps : defaultSnaps; | ||
var scrollLimit = ScrollLimit({ | ||
loop: loop, | ||
contentSize: contentSize | ||
}); | ||
var limit = scrollLimit.measure(scrollSnaps); | ||
var direction = Direction(contentDirection); // Index | ||
@@ -1331,10 +1322,4 @@ var indexMax = Math.max(0, scrollSnaps.length - 1); | ||
}); | ||
var indexPrevious = index.clone(); // ScrollLimit | ||
var indexPrevious = index.clone(); // Draw | ||
var scrollLimit = ScrollLimit({ | ||
loop: loop, | ||
contentSize: contentSize | ||
}); | ||
var limit = scrollLimit.measure(scrollSnaps); // Draw | ||
var update = function update() { | ||
@@ -1344,3 +1329,3 @@ engine.scrollBody.seek(target).update(); | ||
if (!dragHandler.pointerDown()) { | ||
if (!engine.dragHandler.pointerDown()) { | ||
if (!loop) engine.scrollBounds.constrain(target); | ||
@@ -1355,4 +1340,3 @@ | ||
if (loop) { | ||
var direction = engine.scrollBody.direction.get(); | ||
engine.scrollLooper.loop(loopVectors, direction); | ||
engine.scrollLooper.loop(loopVectors, engine.scrollBody.direction()); | ||
engine.slideLooper.loop(slides); | ||
@@ -1404,2 +1388,3 @@ } | ||
axis: axis, | ||
direction: direction, | ||
dragFree: dragFree, | ||
@@ -1410,3 +1395,3 @@ dragTracker: DragTracker({ | ||
}), | ||
element: root, | ||
root: root, | ||
events: events, | ||
@@ -1426,2 +1411,3 @@ index: index, | ||
axis: axis, | ||
direction: direction, | ||
dragHandler: dragHandler, | ||
@@ -1461,2 +1447,3 @@ pxToPercent: pxToPercent, | ||
contentSize: contentSize, | ||
direction: direction, | ||
location: location, | ||
@@ -1473,3 +1460,4 @@ scrollSnaps: scrollSnaps, | ||
axis: axis, | ||
container: container | ||
container: container, | ||
direction: direction | ||
}) | ||
@@ -1525,2 +1513,3 @@ }; | ||
containerSelector: '*', | ||
direction: 'ltr', | ||
dragFree: false, | ||
@@ -1561,3 +1550,3 @@ draggable: true, | ||
container = sliderContainer; | ||
slides = arrayFromCollection(container.children); | ||
slides = Array.prototype.slice.call(container.children); | ||
} | ||
@@ -1564,0 +1553,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=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){var e=n.viewSize,t=n.align,r={start:function(){return 0},center:function(n){return o(n)/2},end:o};function o(n){return e-n}return{measure:function(n){return"number"==typeof t?e*Number(t):r[t](n)}}}function t(n){var e=n.start,r=n.limit,o=n.loop,i=r.min,a=r.max,c=r[o?"loop":"constrain"],u=c(e);function s(){return u}function l(n){return u=c(n),d}var d={add:function n(e){if(0!==e){var t=e/Math.abs(e);return l(s()+t),n(e+-1*t)}return d},clone:function(){return t({start:s(),limit:r,loop:o})},get:s,max:a,min:i,set:l};return d}function r(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 o(n){var e=r(t(n));function t(n){return 0===n?0:n/Math.abs(n)}var o={get:e.get,set:function(n){var r=t(n.get());return 0!==r&&e.set(r),o}};return o}function i(){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 a(n){var e=n.min,t=n.max,r=Math.abs(e-t);function o(n){return n<e}function i(n){return n>t}function a(n){return o(n)||i(n)}return{constrain:function(n){return a(n)?o(n)?e:t:n},length:r,loop:function(n){return a(n)?o(n)?t:e:n},max:t,min:e,reachedAny:a,reachedMax:i,reachedMin:o,removeOffset:function(n){if(e===t)return n;for(;o(n);)n+=r;for(;i(n);)n-=r;return n}}}function c(n){var e=n.target,t=n.scrollBody,c=n.dragFree,u=n.animation,s=n.axis,l=n.element,d=n.dragTracker,f=n.location,m=n.events,g=n.limit,v=s.scroll,p=s.cross,x=["INPUT","SELECT","TEXTAREA"],h=r(0),S=r(0),w=r(0),y=i(),b=i(),T={mouse:2.5,touch:3.5},M={mouse:5,touch:7},z=c?5:12,A=a({min:g.min-70,max:g.max+70}),E=!1,P=!1,D=!1,B=!1;function I(n){if(!(B="mousedown"===n.type)||0===n.button){var r,o,i=k(e.get(),f.get())>=2,a=B||!i,c=(r=n.target,o=r.nodeName||"",!(x.indexOf(o)>-1)),u=i||B&&c;E=!0,d.pointerDown(n),w.set(e),e.set(f),t.useBaseMass().useSpeed(80),function(){var n=B?document:l;b.add(n,"touchmove",C).add(n,"touchend",L).add(n,"mousemove",C).add(n,"mouseup",L)}(),h.set(d.readPoint(n,v)),S.set(d.readPoint(n,p)),m.emit("pointerDown"),a&&(D=!1),u&&n.preventDefault()}}function C(t){if(!P&&!B){if(!t.cancelable)return L();var r=d.readPoint(t,v).get(),o=d.readPoint(t,p).get(),i=k(r,h.get()),a=k(o,S.get());if(!(P=i>a)&&!D)return L()}var c=d.pointerMove(t),s=g.reachedAny(f.get()),l=!n.loop&&s?2:1;!D&&c&&(D=!0),u.start(),e.add(c/l),t.preventDefault()}function L(){var r,i,a,u=n.scrollTo,s=d.pointerUp()*(c?M:T)[B?"mouse":"touch"],l=function(t){var r=n.scrollTarget,i=n.index,a=!(r.byDistance(0,!1).index!==i.get())&&Math.abs(t)>4,u=t+f.get();if(a&&!c&&!g.reachedAny(u)){var s=i.clone().add(-1*o(t).get());return r.byIndex(s.get(),0).distance}if(!n.loop&&A.reachedAny(u)){var l=A.reachedMax(u)?"max":"min";return A[l]-e.get()}return r.byDistance(t,!c).distance}(s),v=(r=s,i=l,a=k(Math.abs(r),Math.abs(i)),Math.abs(r)<=Math.abs(i)||0===r||0===i?0:Math.abs(a/r));k(e.get(),w.get())>=.5&&!B&&(D=!0),P=!1,E=!1,b.removeAll(),t.useSpeed(z+z*v),u.distance(l,!c),B=!1,m.emit("pointerUp")}function k(n,e){return Math.abs(n-e)}function O(n){D&&n.preventDefault()}return{addActivationEvents:function(){var n=l;y.add(n,"touchmove",(function(){})).add(n,"touchend",(function(){})).add(n,"touchstart",I).add(n,"mousedown",I).add(n,"touchcancel",L).add(n,"contextmenu",L).add(n,"click",O)},clickAllowed:function(){return!D},pointerDown:function(){return E},removeAllEvents:function(){y.removeAll(),b.removeAll()}}}function u(n){var e=n.axis,t=n.pxToPercent,o=e.scroll,i={x:"clientX",y:"clientY"},a=r(0),c=r(0),u=r(0),s=r(0),l=[],d=(new Date).getTime(),f=!1;function m(n,e){f=!n.touches;var t=i[e],r=f?n[t]:n.touches[0][t];return s.set(r)}return{pointerDown:function(n){var e=m(n,o);return a.set(e),u.set(e),t.measure(a.get())},pointerMove:function(n){var e=m(n,o),r=(new Date).getTime(),i=r-d;return i>=10&&(i>=100&&(l=[]),l.push(e.get()),d=r),c.set(e).subtract(u),u.set(e),t.measure(c.get())},pointerUp:function(){var n=(new Date).getTime()-d,e=u.get(),r=l.slice(-5).map((function(n){return e-n})).sort((function(n,e){return Math.abs(n)<Math.abs(e)?1:-1}))[0];return u.set(n>100||!r?0:r),l=[],t.measure(u.get())},readPoint:m}}function s(n){var e=Math.pow(10,n);return function(n){return Math.round(n*e)/e}}function l(n){return Object.keys(n).map(Number)}function d(n,e){var t=n.classList;e&&t.contains(e)&&t.remove(e)}function f(n,e){var t=n.classList;e&&!t.contains(e)&&t.add(e)}function m(n){var e=n.location,t=n.speed,i=n.mass,a=s(2),c=r(0),u=r(0),l=r(0),d=o(0),f=t,m=i;function g(n){return f=n,p}function v(n){return m=n,p}var p={direction:d,seek:function(n){l.set(n).subtract(e);var t,r,o=l.get(),i=(r=0)+(o-(t=0))/(100-t)*(f-r);return d.set(l),l.normalize().multiply(i).subtract(c),function(n){n.divide(m),u.add(n)}(l),p},settle:function(n){var t=n.get()-e.get(),r=!a(t);return r&&e.set(n),r},update:function(){c.add(u),e.add(c),u.multiply(0)},useBaseMass:function(){return v(i)},useBaseSpeed:function(){return g(t)},useMass:v,useSpeed:g};return p}function g(n){var e=n.limit,t=n.location,r=n.scrollBody,o=n.animation,i=e.min,a=e.max,c=e.reachedMin,u=e.reachedMax,s=!1,l=0;return{constrain:function(n){(function(n){return!s&&!l&&(c(t.get())?n.get()!==i:!!u(t.get())&&n.get()!==a)})(n)&&(l=window.setTimeout((function(){var t=e.constrain(n.get());n.set(t),r.useSpeed(10).useMass(3),o.start(),l=0}),50))},toggleActive:function(n){s=!n}}}function v(n){var e=n.alignment,t=n.contentSize,r=n.viewSize,o=a({min:-t+r,max:0}),i=[e.measure(t)],c=t>r;return{measure:function(n,e){var t=n.map(o.constrain),r=function(n){var e=n[0],t=n[n.length-1];return a({min:n.lastIndexOf(e)+1,max:n.indexOf(t)})}(t),u=r.min,s=r.max;return c?e?t.slice(u-1,s+1):t:i}}}function p(n){var e=n.contentSize,t=n.location,r=n.limit,o=n.pxToPercent,i=a({min:r.min+o.measure(.1),max:r.max+o.measure(.1)}),c=i.reachedMin,u=i.reachedMax;return{loop:function(n,r){if(function(n){return 1===n?u(t.get()):-1===n&&c(t.get())}(r)){var o=e*(-1*r);n.forEach((function(n){return n.add(o)}))}}}}function x(n){var e=n.loop,t=n.limit,r=n.scrollSnaps,o=n.contentSize,i=t.reachedMax,a=t.reachedAny,c=t.removeOffset;function u(n,e){return Math.abs(n)<Math.abs(e)?n:e}function s(n,t){var r=n,i=n+o,a=n-o;if(!e)return r;if(!t)return u(u(r,i),a);var c=u(r,1===t?i:a);return Math.abs(c)*t}return{byDistance:function(t,o){var u=n.target.get()+t,l=function(n){var e=c(n);return{index:r.map((function(n){return n-e})).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:e}}(u),d=function(t,r){if(!(!e&&a(t)))return r;var o=n.index,c=o.min,u=o.max;return i(t)?c:u}(u,l.index),f=!e&&a(u);return!o||f?{index:d,distance:t}:{index:d,distance:t+s(r[d]-l.distance,0)}},byIndex:function(e,t){return{index:e,distance:s(r[e]-n.target.get(),t)}},shortcut:s}}function h(n){var e,t=n.axis,r=n.location,o=n.slidesInView,i=n.contentSize,a=n.viewSize,c=n.slideSizes,u=n.scrollSnaps,s=l(c),d=l(c).reverse(),f=(e=u[0]-1,p(v(d,e),"end")).concat(function(){var n=a-u[0]-1;return p(v(s,n),"start")}()),m="x"===t.scroll?"left":"top";function g(n,e){return n.reduce((function(n,e){return n-c[e]}),e)}function v(n,e){return n.reduce((function(n,t){return g(n,e)>0?n.concat([t]):n}),[])}function p(n,e){var t="start"===e,a=t?-i:i,c=o.findSlideBounds(a);return n.map((function(n){var e=t?0:-i,o=t?i:0,a=c.filter((function(e){return e.index===n}))[0][t?"end":"start"];return{point:a,getTarget:function(){return r.get()>a?e:o},index:n,location:-1}}))}return{canLoop:function(){return f.every((function(n){var e=n.index;return g(s.filter((function(n){return n!==e})),a)<=0}))},clear:function(n){f.forEach((function(e){var t=e.index;n[t].style[m]=""}))},loop:function(n){f.forEach((function(e){var t=e.getTarget,r=e.location,o=e.index,i=t();i!==r&&(n[o].style[m]=i+"%",e.location=i)}))},loopPoints:f}}function S(n){var e=n.scrollTo,t=n.slidesToScroll,r=n.root,o=i(),a=o.removeAll,c=0;function u(n){9===n.keyCode&&(c=(new Date).getTime())}function s(n,i){o.add(n,"focus",(function(){if(!((new Date).getTime()-c>10)){r.scrollLeft=0;var n=Math.floor(i/t);e.index(n,0)}}),!0)}return{addActivationEvents:function(n){o.add(document,"keydown",u,!1),n.forEach(s)},removeAllEvents:a}}function w(n){var e=n.axis,t=n.container,r={x:function(n){return"translate3d("+n+"%,0px,0px)"},y:function(n){return"translate3d(0px,"+n+"%,0px)"}}[e.scroll],o=s(2),i=t.style,a=!1,c=0;return{clear:function(){i.transform="",c=0},to:function(n){if(!a){var e=o(n.get());c!==e&&(getComputedStyle(t).transform,i.transform=r(e),c=e)}},toggleActive:function(n){a=!n}}}function y(n,o,i,s,d){var f,y,b,T,M,z=s.align,A=s.axis,E=s.startIndex,P=s.inViewThreshold,D=s.loop,B=s.speed,I=s.dragFree,C=s.slidesToScroll,L=s.containScroll,k=function(n){var e="y"===n?"y":"x";return{cross:"y"===n?"x":"y",measure:function(n){var t=n.getBoundingClientRect(),r=t.width,o=t.height;return"x"===e?r:o},scroll:e}}(A),O=(f=k.measure(o),{measure:function(n){return n/f*100},totalPercent:100}),V=O.totalPercent,F=i.map(k.measure).map(O.measure),N=l(F),U=function(n,e){for(var t=[],r=0;r<n.length;r+=e)t.push(n.slice(r,r+e));return t}(F,C).map((function(n){return n.reduce((function(n,e){return n+e}))})),j=F.reduce((function(n,e){return n+e}),0),H=e({align:z,viewSize:V}),q=function(n){var e,r=n.snapSizes,o=n.alignment,i=n.loop,c=r.map(o.measure),u=(e=t({limit:a({min:0,max:r.length-1}),start:0,loop:i}),r.map((function(n,t){var r=e.set(t+1).get();return n+c[t]-c[r]})));return{measure:function(n){return u.slice(0,n).reduce((function(n,e){return n-e}),c[0])}}}({snapSizes:U,alignment:H,loop:D}),R=l(U).map(q.measure),X=v({alignment:H,contentSize:j,viewSize:V}),G=!D&&""!==L,Y="trimSnaps"===L,J=X.measure(R,Y),K=G?J:R,Q=t({limit:a({min:0,max:Math.max(0,K.length-1)}),start:E,loop:D}),W=Q.clone(),Z=function(n){var e=n.contentSize,t=n.loop;return{measure:function(n){var r=n[0],o=n[n.length-1];return a({min:t?r-e:o,max:r})}}}({loop:D,contentSize:j}).measure(K),$=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(){sn.scrollBody.seek(en).update();var n=sn.scrollBody.settle(en);if(un.pointerDown()||(D||sn.scrollBounds.constrain(en),n&&(sn.animation.stop(),d.emit("settle"))),D){var e=sn.scrollBody.direction.get();sn.scrollLooper.loop(tn,e),sn.slideLooper.loop(i)}n||d.emit("scroll"),sn.translate.to(nn),sn.animation.proceed()})),_=K[Q.get()],nn=r(_),en=r(_),tn=[nn,en],rn=m({location:nn,speed:B,mass:1}),on=x({contentSize:j,index:Q,limit:Z,loop:D,scrollSnaps:K,target:en}),an=function(n){var e=n.index,t=n.scrollTarget,r=n.animation,o=n.indexPrevious,i=n.events,a=n.target;function c(n){var t=n.distance,c=n.index!==e.get();t&&(r.start(),a.add(t)),c&&(o.set(e.get()),e.set(n.index),i.emit("select"))}return{distance:function(n,e){c(t.byDistance(n,e))},index:function(n,r){var o=e.clone().set(n);c(t.byIndex(o.get(),r))}}}({animation:$,events:d,index:Q,indexPrevious:W,scrollTarget:on,target:en}),cn=function(n){var e=n.contentSize,t=n.slideSizes,r=n.viewSize,o=n.inViewThreshold,i=n.loop,a=Math.min(Math.max(o,.01),.99),c=l(t).map((function(n){return t.slice(0,n).reduce((function(n,e){return n-e}),0)})),u=(i?[0,e,-e]:[0]).reduce((function(n,e){return n.concat(s(e,a))}),[]);function s(n,e){var o=t.map((function(n){return n*(e||0)}));return c.map((function(e,i){return{start:e-t[i]+o[i]+n,end:e+r-o[i]+n,index:i}}))}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:s}}({contentSize:j,inViewThreshold:P,loop:D,slideSizes:F,viewSize:V}),un=c({animation:$,axis:k,dragFree:I,dragTracker:u({axis:k,pxToPercent:O}),element:n,events:d,index:Q,limit:Z,location:nn,loop:D,scrollBody:rn,scrollTo:an,scrollTarget:on,target:en}),sn={animation:$,axis:k,dragHandler:un,pxToPercent:O,index:Q,indexPrevious:W,limit:Z,location:nn,options:s,scrollBody:rn,scrollBounds:g({animation:$,limit:Z,location:nn,scrollBody:rn}),scrollLooper:p({contentSize:j,limit:Z,location:nn,pxToPercent:O}),scrollProgress:(y={limit:Z},b=y.limit,T=b.max,M=b.length,{get:function(n){return(n-T)/-M}}),scrollSnaps:K,scrollTarget:on,scrollTo:an,slideFocus:S({root:n,scrollTo:an,slidesToScroll:C}),slideLooper:h({axis:k,contentSize:j,location:nn,scrollSnaps:K,slideSizes:F,slidesInView:cn,viewSize:V}),slidesInView:cn,slideIndexes:N,target:en,translate:w({axis:k,container:o})};return sn}var b={align:"center",axis:"x",containScroll:"",containerSelector:"*",dragFree:!1,draggable:!0,draggableClass:"is-draggable",draggingClass:"is-dragging",inViewThreshold:0,loop:!1,selectedClass:"is-selected",slidesToScroll:1,speed:10,startIndex:0};return function(e,t){var r,o,a,c,u,s,l=function(){var n={destroy:[],pointerDown:[],pointerUp:[],init:[],reInit:[],resize:[],scroll:[],select:[],settle:[]},e={emit:function(t){return n[t].forEach((function(n){return n(t)})),e},off:function(t,r){return n[t]=n[t].filter((function(n){return n!==r})),e},on:function(t,r){return n[t]=n[t].concat([r]),e}};return e}(),m=i(),g=(r=function(){if(h){var n=c.axis.measure(e);w!==n&&P(),l.emit("resize")}},o=500,a={id:0},function(){window.clearTimeout(a.id),a.id=window.setTimeout(r,o)||0}),v=P,p=l.on,x=l.off,h=!1,S=n({},b),w=0;function T(){if(!e)throw new Error("Missing root node 😢");var n,t=S.containerSelector,r=e.querySelector(t);if(!r)throw new Error("Missing container node 😢");n=(u=r).children,s=Array.prototype.slice.call(n)}function M(t){if(T(),S=n(S,t),c=y(e,u,s,S,l),w=c.axis.measure(e),m.add(window,"resize",g),c.translate.to(c.location),S.loop){if(!c.slideLooper.canLoop())return E(),M({loop:!1});c.slideLooper.loop(s)}S.draggable&&s.length&&(c.dragHandler.addActivationEvents(),S.draggableClass&&f(e,S.draggableClass),S.draggingClass&&l.on("pointerDown",z).on("pointerUp",z)),s.length&&c.slideFocus.addActivationEvents(s),S.selectedClass&&(A(),l.on("select",A).on("pointerUp",A)),h||(setTimeout((function(){return l.emit("init")}),0),h=!0)}function z(n){var t=S.draggingClass;"pointerDown"===n?f(e,t):d(e,t)}function A(){var n=S.selectedClass,e=D(!0);B(!0).forEach((function(e){return d(s[e],n)})),e.forEach((function(e){return f(s[e],n)}))}function E(){c.dragHandler.removeAllEvents(),c.slideFocus.removeAllEvents(),c.animation.stop(),m.removeAll(),c.translate.clear(),c.slideLooper.clear(s),d(e,S.draggableClass),s.forEach((function(n){return d(n,S.selectedClass)})),l.off("select",A),l.off("pointerUp",A),l.off("pointerDown",z),l.off("pointerUp",z)}function P(e){if(h){var t=n({startIndex:C()},e);E(),M(t),l.emit("reInit")}}function D(n){var e=c[n?"target":"location"].get(),t=S.loop?"removeOffset":"constrain";return c.slidesInView.check(c.limit[t](e))}function B(n){var e=D(n);return c.slideIndexes.filter((function(n){return-1===e.indexOf(n)}))}function I(n,e){c.scrollBody.useBaseMass().useBaseSpeed(),h&&c.scrollTo.index(n,e||0)}function C(){return c.index.get()}return M(t),{canScrollNext:function(){return c.index.clone().add(1).get()!==C()},canScrollPrev:function(){return c.index.clone().add(-1).get()!==C()},clickAllowed:function(){return c.dragHandler.clickAllowed()},containerNode:function(){return u},dangerouslyGetEngine:function(){return c},destroy:function(){h&&(E(),h=!1,l.emit("destroy"))},off:x,on:p,previousScrollSnap:function(){return c.indexPrevious.get()},reInit:v,scrollNext:function(){I(c.index.clone().add(1).get(),-1)},scrollPrev:function(){I(c.index.clone().add(-1).get(),1)},scrollProgress:function(){return c.scrollProgress.get(c.location.get())},scrollSnapList:function(){return c.scrollSnaps.map(c.scrollProgress.get)},scrollTo:I,selectedScrollSnap:C,slideNodes:function(){return s},slidesInView:D,slidesNotInView:B}}})); | ||
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(n=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){var e=n.viewSize,t=n.align,r={start:function(){return 0},center:function(n){return o(n)/2},end:o};function o(n){return e-n}return{measure:function(n){return"number"==typeof t?e*Number(t):r[t](n)}}}function t(n){return n?n/Math.abs(n):0}function r(n,e){return Math.abs(n-e)}function o(n){var e=Math.pow(10,n);return function(n){return Math.round(n*e)/e}}function i(n){return Object.keys(n).map(Number)}function a(n,e){var t=n.classList;e&&t.contains(e)&&t.remove(e)}function c(n,e){var t=n.classList;e&&!t.contains(e)&&t.add(e)}function u(n){var e=n.start,r=n.limit,o=n.loop,i=r.min,a=r.max,c=r[o?"loop":"constrain"],s=c(e);function l(){return s}function d(n){return s=c(n),f}var f={add:function n(e){if(0!==e){var r=t(e);return d(l()+r),n(e+-1*r)}return f},clone:function(){return u({start:l(),limit:r,loop:o})},get:l,max:a,min:i,set:d};return f}function s(){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 l(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 d(n){var e=n.target,o=n.scrollBody,i=n.dragFree,a=n.animation,c=n.axis,u=n.scrollTo,d=n.root,f=n.dragTracker,m=n.location,p=n.events,g=n.limit,v=n.direction,x=c.scroll,h=c.cross,S=["INPUT","SELECT","TEXTAREA"],y=l(0),w=l(0),T=l(0),b=s(),M=s(),z={mouse:2.5,touch:3.5},A={mouse:5,touch:7},E=i?5:12,P=!1,D=!1,B=!1,I=!1;function C(n){if(!(I="mousedown"===n.type)||0===n.button){var t,i,a=r(e.get(),m.get())>=2,c=I||!a,u=(t=n.target,i=t.nodeName||"",!(S.indexOf(i)>-1)),s=a||I&&u;P=!0,f.pointerDown(n),T.set(e),e.set(m),o.useBaseMass().useSpeed(80),function(){var n=I?document:d;M.add(n,"touchmove",L).add(n,"touchend",k).add(n,"mousemove",L).add(n,"mouseup",k)}(),y.set(f.readPoint(n,x)),w.set(f.readPoint(n,h)),p.emit("pointerDown"),c&&(B=!1),s&&n.preventDefault()}}function L(t){if(!D&&!I){if(!t.cancelable)return k();var o=f.readPoint(t,x).get(),i=f.readPoint(t,h).get(),c=r(o,y.get()),u=r(i,w.get());if(!(D=c>u)&&!B)return k()}var s=f.pointerMove(t),l=g.reachedAny(m.get()),d=!n.loop&&l?4:1;!B&&s&&(B=!0),a.start(),e.add(v.applyTo(s/d)),t.preventDefault()}function k(){var a=f.pointerUp()*(i?A:z)[I?"mouse":"touch"],c=function(e){var r=n.scrollTarget,o=n.index,a=!(r.byDistance(0,!1).index!==o.get())&&Math.abs(e)>4,c=e+m.get();if(a&&!i&&!g.reachedAny(c)){var u=o.clone().add(-1*t(e));return r.byIndex(u.get(),0).distance}return r.byDistance(e,!i).distance}(v.applyTo(a)),s=function(n,e){if(0===n||0===e)return 0;if(Math.abs(n)<=Math.abs(e))return 0;var t=r(Math.abs(n),Math.abs(e));return Math.abs(t/n)}(a,c);r(e.get(),T.get())>=.5&&!I&&(B=!0),D=!1,P=!1,M.removeAll(),o.useSpeed(E+E*s),u.distance(c,!i),I=!1,p.emit("pointerUp")}function O(n){B&&n.preventDefault()}return{addActivationEvents:function(){var n=d;b.add(n,"touchmove",(function(){})).add(n,"touchend",(function(){})).add(n,"touchstart",C).add(n,"mousedown",C).add(n,"touchcancel",k).add(n,"contextmenu",k).add(n,"click",O)},clickAllowed:function(){return!B},pointerDown:function(){return P},removeAllEvents:function(){b.removeAll(),M.removeAll()}}}function f(n){var e=n.axis,t=n.pxToPercent,r=e.scroll,o={x:"clientX",y:"clientY"},i=l(0),a=l(0),c=l(0),u=l(0),s=[],d=(new Date).getTime(),f=!1;function m(n,e){f=!n.touches;var t=o[e],r=f?n[t]:n.touches[0][t];return u.set(r)}return{pointerDown:function(n){var e=m(n,r);return i.set(e),c.set(e),t.measure(i.get())},pointerMove:function(n){var e=m(n,r),o=(new Date).getTime(),i=o-d;return i>=10&&(i>=100&&(s=[]),s.push(e.get()),d=o),a.set(e).subtract(c),c.set(e),t.measure(a.get())},pointerUp:function(){var n=(new Date).getTime()-d,e=c.get(),r=s.slice(-5).map((function(n){return e-n})).sort((function(n,e){return Math.abs(n)<Math.abs(e)?1:-1}))[0];return c.set(n>100||!r?0:r),s=[],t.measure(c.get())},readPoint:m}}function m(n){var e=n.min,t=n.max,r=Math.abs(e-t);function o(n){return n<e}function i(n){return n>t}function a(n){return o(n)||i(n)}return{constrain:function(n){return a(n)?o(n)?e:t:n},length:r,loop:function(n){return a(n)?o(n)?t:e:n},max:t,min:e,reachedAny:a,reachedMax:i,reachedMin:o,removeOffset:function(n){if(e===t)return n;for(;o(n);)n+=r;for(;i(n);)n-=r;return n}}}function p(n){var e=n.location,r=n.speed,i=n.mass,a=o(2),c=l(0),u=l(0),s=l(0),d=0,f=r,m=i;function p(n){return f=n,v}function g(n){return m=n,v}var v={direction:function(){return d},seek:function(n){s.set(n).subtract(e);var r,o,i=s.get(),a=(o=0)+(i-(r=0))/(100-r)*(f-o);return d=t(s.get()),s.normalize().multiply(a).subtract(c),function(n){n.divide(m),u.add(n)}(s),v},settle:function(n){var t=n.get()-e.get(),r=!a(t);return r&&e.set(n),r},update:function(){c.add(u),e.add(c),u.multiply(0)},useBaseMass:function(){return g(i)},useBaseSpeed:function(){return p(r)},useMass:g,useSpeed:p};return v}function g(n){var e=n.limit,t=n.location,r=n.scrollBody,o=n.animation,i=e.min,a=e.max,c=m({min:i-70,max:a+70}),u=!1,s=0;return{constrain:function(n){(function(n){return!u&&(!!e.reachedAny(t.get())&&(n.get()!==i&&n.get()!==a))})(n)&&(n.set(c.constrain(n.get())),s||(s=window.setTimeout((function(){n.set(e.constrain(n.get())),r.useSpeed(10).useMass(3),o.start(),s=0}),70)))},toggleActive:function(n){u=!n}}}function v(n){var e=n.alignment,t=n.contentSize,r=n.viewSize,o=m({min:-t+r,max:0}),i=[e.measure(t)],a=t>r;return{measure:function(n,e){var t=n.map(o.constrain),r=function(n){var e=n[0],t=n[n.length-1];return m({min:n.lastIndexOf(e)+1,max:n.indexOf(t)})}(t),c=r.min,u=r.max;return a?e?t.slice(c-1,u+1):t:i}}}function x(n){var e=n.contentSize,t=n.location,r=n.limit,o=n.pxToPercent,i=m({min:r.min+o.measure(.1),max:r.max+o.measure(.1)}),a=i.reachedMin,c=i.reachedMax;return{loop:function(n,r){if(function(n){return 1===n?c(t.get()):-1===n&&a(t.get())}(r)){var o=e*(-1*r);n.forEach((function(n){return n.add(o)}))}}}}function h(n){var e=n.loop,t=n.limit,r=n.scrollSnaps,o=n.contentSize,i=t.reachedMax,a=t.reachedAny,c=t.removeOffset;function u(n,e){return Math.abs(n)<Math.abs(e)?n:e}function s(n,t){var r=n,i=n+o,a=n-o;if(!e)return r;if(!t)return u(u(r,i),a);var c=u(r,1===t?i:a);return Math.abs(c)*t}return{byDistance:function(t,o){var u=n.target.get()+t,l=function(n){var e=c(n);return{index:r.map((function(n){return n-e})).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:e}}(u),d=function(t,r){if(!(!e&&a(t)))return r;var o=n.index,c=o.min,u=o.max;return i(t)?c:u}(u,l.index),f=!e&&a(u);return!o||f?{index:d,distance:t}:{index:d,distance:t+s(r[d]-l.distance,0)}},byIndex:function(e,t){return{index:e,distance:s(r[e]-n.target.get(),t)}},shortcut:s}}function S(n){var e,t=n.axis,r=n.location,o=n.slidesInView,a=n.direction,c=n.contentSize,u=n.viewSize,s=n.slideSizes,l=n.scrollSnaps,d=i(s),f=i(s).reverse(),m=(e=l[0]-1,x(v(f,e),"end")).concat(function(){var n=u-l[0]-1;return x(v(d,n),"start")}()),p="x"===t.scroll?"left":"top";function g(n,e){return n.reduce((function(n,e){return n-s[e]}),e)}function v(n,e){return n.reduce((function(n,t){return g(n,e)>0?n.concat([t]):n}),[])}function x(n,e){var t="start"===e,i=t?-c:c,a=o.findSlideBounds(i);return n.map((function(n){var e=t?0:-c,o=t?c:0,i=a.filter((function(e){return e.index===n}))[0][t?"end":"start"];return{point:i,getTarget:function(){return r.get()>i?e:o},index:n,location:-1}}))}return{canLoop:function(){return m.every((function(n){var e=n.index;return g(d.filter((function(n){return n!==e})),u)<=0}))},clear:function(n){m.forEach((function(e){var t=e.index;n[t].style[p]=""}))},loop:function(n){m.forEach((function(e){var t=e.getTarget,r=e.location,o=e.index,i=t();i!==r&&(n[o].style[p]=a.applyTo(i)+"%",e.location=i)}))},loopPoints:m}}function y(n){var e=n.scrollTo,t=n.slidesToScroll,r=n.root,o=s(),i=o.removeAll,a=0;function c(n){9===n.keyCode&&(a=(new Date).getTime())}function u(n,i){o.add(n,"focus",(function(){if(!((new Date).getTime()-a>10)){r.scrollLeft=0;var n=Math.floor(i/t);e.index(n,0)}}),!0)}return{addActivationEvents:function(n){o.add(document,"keydown",c,!1),n.forEach(u)},removeAllEvents:i}}function w(n){var e=n.axis,t=n.container,r=n.direction,i=t.style,a="x"===e.scroll?function(n){return"translate3d("+n+"%,0px,0px)"}:function(n){return"translate3d(0px,"+n+"%,0px)"},c=o(2),u=!1,s=0;return{clear:function(){i.transform="",s=0},to:function(n){var e=c(n.get());u||s===e||(getComputedStyle(t).transform,i.transform=a(r.applyTo(e)),s=e)},toggleActive:function(n){u=!n}}}function T(n,t,r,o,a){var c,s,T,b,M,z=o.align,A=o.axis,E=o.direction,P=o.startIndex,D=o.inViewThreshold,B=o.loop,I=o.speed,C=o.dragFree,L=o.slidesToScroll,k=o.containScroll,O=function(n){var e="y"===n?"y":"x";return{cross:"y"===n?"x":"y",measure:function(n){var t=n.getBoundingClientRect(),r=t.width,o=t.height;return"x"===e?r:o},scroll:e}}(A),V=(c=O.measure(t),{measure:function(n){return n/c*100},totalPercent:100}),F=V.totalPercent,N=r.map(O.measure).map(V.measure),U=i(N),H=function(n,e){for(var t=[],r=0;r<n.length;r+=e)t.push(n.slice(r,r+e));return t}(N,L).map((function(n){return n.reduce((function(n,e){return n+e}))})),j=N.reduce((function(n,e){return n+e}),0),q=e({align:z,viewSize:F}),R=function(n){var e,t=n.snapSizes,r=n.alignment,o=n.loop,i=t.map(r.measure),a=(e=u({limit:m({min:0,max:t.length-1}),start:0,loop:o}),t.map((function(n,t){var r=e.set(t+1).get();return n+i[t]-i[r]})));return{measure:function(n){return a.slice(0,n).reduce((function(n,e){return n-e}),i[0])}}}({snapSizes:H,alignment:q,loop:B}),X=i(H).map(R.measure),G=v({alignment:q,contentSize:j,viewSize:F}),Y=!B&&""!==k,J="trimSnaps"===k,K=G.measure(X,J),Q=Y?K:X,W=function(n){var e=n.contentSize,t=n.loop;return{measure:function(n){var r=n[0],o=n[n.length-1];return m({min:t?r-e:o,max:r})}}}({loop:B,contentSize:j}).measure(Q),Z=function(n){var e="rtl"===n?-1:1;return{applyTo:function(n){return n*e}}}(E),$=u({limit:m({min:0,max:Math.max(0,Q.length-1)}),start:P,loop:B}),_=$.clone(),nn=function(n){var e=0;function t(n,t){return function(){n===!!e&&t()}}function r(){e=window.requestAnimationFrame(n)}return{proceed:t(!0,r),start:t(!1,r),stop:t(!0,(function(){window.cancelAnimationFrame(e),e=0}))}}((function(){ln.scrollBody.seek(rn).update();var n=ln.scrollBody.settle(rn);ln.dragHandler.pointerDown()||(B||ln.scrollBounds.constrain(rn),n&&(ln.animation.stop(),a.emit("settle"))),B&&(ln.scrollLooper.loop(on,ln.scrollBody.direction()),ln.slideLooper.loop(r)),n||a.emit("scroll"),ln.translate.to(tn),ln.animation.proceed()})),en=Q[$.get()],tn=l(en),rn=l(en),on=[tn,rn],an=p({location:tn,speed:I,mass:1}),cn=h({contentSize:j,index:$,limit:W,loop:B,scrollSnaps:Q,target:rn}),un=function(n){var e=n.index,t=n.scrollTarget,r=n.animation,o=n.indexPrevious,i=n.events,a=n.target;function c(n){var t=n.distance,c=n.index!==e.get();t&&(r.start(),a.add(t)),c&&(o.set(e.get()),e.set(n.index),i.emit("select"))}return{distance:function(n,e){c(t.byDistance(n,e))},index:function(n,r){var o=e.clone().set(n);c(t.byIndex(o.get(),r))}}}({animation:nn,events:a,index:$,indexPrevious:_,scrollTarget:cn,target:rn}),sn=function(n){var e=n.contentSize,t=n.slideSizes,r=n.viewSize,o=n.inViewThreshold,a=n.loop,c=Math.min(Math.max(o,.01),.99),u=i(t).map((function(n){return t.slice(0,n).reduce((function(n,e){return n-e}),0)})),s=(a?[0,e,-e]:[0]).reduce((function(n,e){return n.concat(l(e,c))}),[]);function l(n,e){var o=t.map((function(n){return n*(e||0)}));return u.map((function(e,i){return{start:e-t[i]+o[i]+n,end:e+r-o[i]+n,index:i}}))}return{check:function(n){return s.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:l}}({contentSize:j,inViewThreshold:D,loop:B,slideSizes:N,viewSize:F}),ln={animation:nn,axis:O,direction:Z,dragHandler:d({animation:nn,axis:O,direction:Z,dragFree:C,dragTracker:f({axis:O,pxToPercent:V}),root:n,events:a,index:$,limit:W,location:tn,loop:B,scrollBody:an,scrollTo:un,scrollTarget:cn,target:rn}),pxToPercent:V,index:$,indexPrevious:_,limit:W,location:tn,options:o,scrollBody:an,scrollBounds:g({animation:nn,limit:W,location:tn,scrollBody:an}),scrollLooper:x({contentSize:j,limit:W,location:tn,pxToPercent:V}),scrollProgress:(s={limit:W},T=s.limit,b=T.max,M=T.length,{get:function(n){return(n-b)/-M}}),scrollSnaps:Q,scrollTarget:cn,scrollTo:un,slideFocus:y({root:n,scrollTo:un,slidesToScroll:L}),slideLooper:S({axis:O,contentSize:j,direction:Z,location:tn,scrollSnaps:Q,slideSizes:N,slidesInView:sn,viewSize:F}),slidesInView:sn,slideIndexes:U,target:rn,translate:w({axis:O,container:t,direction:Z})};return ln}var b={align:"center",axis:"x",containScroll:"",containerSelector:"*",direction:"ltr",dragFree:!1,draggable:!0,draggableClass:"is-draggable",draggingClass:"is-dragging",inViewThreshold:0,loop:!1,selectedClass:"is-selected",slidesToScroll:1,speed:10,startIndex:0};return function(e,t){var r,o,i,u,l,d,f=function(){var n={destroy:[],pointerDown:[],pointerUp:[],init:[],reInit:[],resize:[],scroll:[],select:[],settle:[]},e={emit:function(t){return n[t].forEach((function(n){return n(t)})),e},off:function(t,r){return n[t]=n[t].filter((function(n){return n!==r})),e},on:function(t,r){return n[t]=n[t].concat([r]),e}};return e}(),m=s(),p=(r=function(){if(h){var n=u.axis.measure(e);y!==n&&E(),f.emit("resize")}},o=500,i=0,function(){window.clearTimeout(i),i=window.setTimeout(r,o)||0}),g=E,v=f.on,x=f.off,h=!1,S=n({},b),y=0;function w(t){if(function(){if(!e)throw new Error("Missing root node 😢");var n=S.containerSelector,t=e.querySelector(n);if(!t)throw new Error("Missing container node 😢");l=t,d=Array.prototype.slice.call(l.children)}(),S=n(S,t),u=T(e,l,d,S,f),y=u.axis.measure(e),m.add(window,"resize",p),u.translate.to(u.location),S.loop){if(!u.slideLooper.canLoop())return A(),w({loop:!1});u.slideLooper.loop(d)}S.draggable&&d.length&&(u.dragHandler.addActivationEvents(),S.draggableClass&&c(e,S.draggableClass),S.draggingClass&&f.on("pointerDown",M).on("pointerUp",M)),d.length&&u.slideFocus.addActivationEvents(d),S.selectedClass&&(z(),f.on("select",z).on("pointerUp",z)),h||(setTimeout((function(){return f.emit("init")}),0),h=!0)}function M(n){var t=S.draggingClass;"pointerDown"===n?c(e,t):a(e,t)}function z(){var n=S.selectedClass,e=P(!0);D(!0).forEach((function(e){return a(d[e],n)})),e.forEach((function(e){return c(d[e],n)}))}function A(){u.dragHandler.removeAllEvents(),u.slideFocus.removeAllEvents(),u.animation.stop(),m.removeAll(),u.translate.clear(),u.slideLooper.clear(d),a(e,S.draggableClass),d.forEach((function(n){return a(n,S.selectedClass)})),f.off("select",z),f.off("pointerUp",z),f.off("pointerDown",M),f.off("pointerUp",M)}function E(e){if(h){var t=n({startIndex:I()},e);A(),w(t),f.emit("reInit")}}function P(n){var e=u[n?"target":"location"].get(),t=S.loop?"removeOffset":"constrain";return u.slidesInView.check(u.limit[t](e))}function D(n){var e=P(n);return u.slideIndexes.filter((function(n){return-1===e.indexOf(n)}))}function B(n,e){u.scrollBody.useBaseMass().useBaseSpeed(),h&&u.scrollTo.index(n,e||0)}function I(){return u.index.get()}return w(t),{canScrollNext:function(){return u.index.clone().add(1).get()!==I()},canScrollPrev:function(){return u.index.clone().add(-1).get()!==I()},clickAllowed:function(){return u.dragHandler.clickAllowed()},containerNode:function(){return l},dangerouslyGetEngine:function(){return u},destroy:function(){h&&(A(),h=!1,f.emit("destroy"))},off:x,on:v,previousScrollSnap:function(){return u.indexPrevious.get()},reInit:g,scrollNext:function(){B(u.index.clone().add(1).get(),-1)},scrollPrev:function(){B(u.index.clone().add(-1).get(),1)},scrollProgress:function(){return u.scrollProgress.get(u.location.get())},scrollSnapList:function(){return u.scrollSnaps.map(u.scrollProgress.get)},scrollTo:B,selectedScrollSnap:I,slideNodes:function(){return d},slidesInView:P,slidesNotInView:D}}})); |
{ | ||
"name": "embla-carousel", | ||
"version": "4.0.6", | ||
"version": "4.1.0", | ||
"private": false, | ||
@@ -42,7 +42,7 @@ "author": "David Cetinkaya <david.o.cetinkaya@gmail.com>", | ||
"test": "jest --config jestconfig.json", | ||
"lint": "eslint src --ext .ts", | ||
"lint": "eslint src/** --ext .js,.jsx,.ts,.tsx", | ||
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"", | ||
"prepare": "npm run build", | ||
"prepublishOnly": "npm-run-all test lint", | ||
"preversion": "npm run lint", | ||
"preversion": "npm-run-all test lint", | ||
"version": "npm run format && git add -A src", | ||
@@ -49,0 +49,0 @@ "postversion": "git push && git push --tags" |
449
react.esm.js
@@ -103,2 +103,51 @@ import { useState, useRef, useMemo, useEffect } from 'react'; | ||
function map(value, iStart, iStop, oStart, oStop) { | ||
return oStart + (oStop - oStart) * ((value - iStart) / (iStop - iStart)); | ||
} | ||
function mathSign(n) { | ||
return !n ? 0 : n / Math.abs(n); | ||
} | ||
function deltaAbs(valueB, valueA) { | ||
return Math.abs(valueB - valueA); | ||
} | ||
function factorAbs(valueB, valueA) { | ||
if (valueB === 0 || valueA === 0) return 0; | ||
if (Math.abs(valueB) <= Math.abs(valueA)) return 0; | ||
var diff = deltaAbs(Math.abs(valueB), Math.abs(valueA)); | ||
return Math.abs(diff / valueB); | ||
} | ||
function roundToDecimals(decimalPoints) { | ||
var pow = Math.pow(10, decimalPoints); | ||
return function (n) { | ||
return Math.round(n * pow) / pow; | ||
}; | ||
} | ||
function debounce(callback, time) { | ||
var timeout = 0; | ||
return function () { | ||
window.clearTimeout(timeout); | ||
timeout = window.setTimeout(callback, time) || 0; | ||
}; | ||
} | ||
function groupArray(array, size) { | ||
var groups = []; | ||
for (var i = 0; i < array.length; i += size) { | ||
groups.push(array.slice(i, i + size)); | ||
} | ||
return groups; | ||
} | ||
function arrayKeys(array) { | ||
return Object.keys(array).map(Number); | ||
} | ||
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); | ||
} | ||
function Counter(params) { | ||
@@ -125,3 +174,3 @@ var start = params.start, | ||
if (n !== 0) { | ||
var sign = n / Math.abs(n); | ||
var sign = mathSign(n); | ||
set(get() + sign); | ||
@@ -153,51 +202,11 @@ return add(n + sign * -1); | ||
function Vector1D(value) { | ||
var vector = value; | ||
function Direction(direction) { | ||
var sign = direction === 'rtl' ? -1 : 1; | ||
function get() { | ||
return vector; | ||
function applyTo(n) { | ||
return n * sign; | ||
} | ||
function set(n) { | ||
vector = readNumber(n); | ||
return self; | ||
} | ||
function add(n) { | ||
vector += readNumber(n); | ||
return self; | ||
} | ||
function subtract(n) { | ||
vector -= readNumber(n); | ||
return self; | ||
} | ||
function multiply(n) { | ||
vector *= n; | ||
return self; | ||
} | ||
function divide(n) { | ||
vector /= n; | ||
return self; | ||
} | ||
function normalize() { | ||
if (vector !== 0) divide(vector); | ||
return self; | ||
} | ||
function readNumber(n) { | ||
return typeof n === 'number' ? n : n.get(); | ||
} | ||
var self = { | ||
add: add, | ||
divide: divide, | ||
get: get, | ||
multiply: multiply, | ||
normalize: normalize, | ||
set: set, | ||
subtract: subtract | ||
applyTo: applyTo | ||
}; | ||
@@ -207,23 +216,2 @@ return self; | ||
function Direction(value) { | ||
var direction = Vector1D(normalize(value)); | ||
var get = direction.get; | ||
function normalize(n) { | ||
return n === 0 ? 0 : n / Math.abs(n); | ||
} | ||
function set(v) { | ||
var d = normalize(v.get()); | ||
if (d !== 0) direction.set(d); | ||
return self; | ||
} | ||
var self = { | ||
get: get, | ||
set: set | ||
}; | ||
return self; | ||
} | ||
function EventStore() { | ||
@@ -258,53 +246,51 @@ var listeners = []; | ||
function Limit(params) { | ||
var min = params.min, | ||
max = params.max; | ||
var length = Math.abs(min - max); | ||
function Vector1D(value) { | ||
var vector = value; | ||
function reachedMin(n) { | ||
return n < min; | ||
function get() { | ||
return vector; | ||
} | ||
function reachedMax(n) { | ||
return n > max; | ||
function set(n) { | ||
vector = readNumber(n); | ||
return self; | ||
} | ||
function reachedAny(n) { | ||
return reachedMin(n) || reachedMax(n); | ||
function add(n) { | ||
vector += readNumber(n); | ||
return self; | ||
} | ||
function removeOffset(n) { | ||
if (min === max) return n; | ||
function subtract(n) { | ||
vector -= readNumber(n); | ||
return self; | ||
} | ||
while (reachedMin(n)) { | ||
n += length; | ||
} | ||
function multiply(n) { | ||
vector *= n; | ||
return self; | ||
} | ||
while (reachedMax(n)) { | ||
n -= length; | ||
} | ||
return n; | ||
function divide(n) { | ||
vector /= n; | ||
return self; | ||
} | ||
function loop(n) { | ||
if (!reachedAny(n)) return n; | ||
return reachedMin(n) ? max : min; | ||
function normalize() { | ||
if (vector !== 0) divide(vector); | ||
return self; | ||
} | ||
function constrain(n) { | ||
if (!reachedAny(n)) return n; | ||
return reachedMin(n) ? min : max; | ||
function readNumber(n) { | ||
return typeof n === 'number' ? n : n.get(); | ||
} | ||
var self = { | ||
constrain: constrain, | ||
length: length, | ||
loop: loop, | ||
max: max, | ||
min: min, | ||
reachedAny: reachedAny, | ||
reachedMax: reachedMax, | ||
reachedMin: reachedMin, | ||
removeOffset: removeOffset | ||
add: add, | ||
divide: divide, | ||
get: get, | ||
multiply: multiply, | ||
normalize: normalize, | ||
set: set, | ||
subtract: subtract | ||
}; | ||
@@ -319,8 +305,10 @@ return self; | ||
animation = params.animation, | ||
axis = params.axis; | ||
var element = params.element, | ||
axis = params.axis, | ||
scrollTo = params.scrollTo; | ||
var root = params.root, | ||
dragTracker = params.dragTracker, | ||
location = params.location, | ||
events = params.events, | ||
limit = params.limit; | ||
limit = params.limit, | ||
direction = params.direction; | ||
var scrollAxis = axis.scroll, | ||
@@ -344,6 +332,2 @@ crossAxis = axis.cross; | ||
var dragThreshold = 4; | ||
var edgeLimit = Limit({ | ||
min: limit.min - 70, | ||
max: limit.max + 70 | ||
}); | ||
var pointerIsDown = false; | ||
@@ -355,3 +339,3 @@ var preventScroll = false; | ||
function addActivationEvents() { | ||
var node = element; | ||
var node = root; | ||
activationEvents.add(node, 'touchmove', function () { | ||
@@ -365,3 +349,3 @@ return undefined; | ||
function addInteractionEvents() { | ||
var node = !isMouse ? element : document; | ||
var node = !isMouse ? root : document; | ||
interactionEvents.add(node, 'touchmove', move).add(node, 'touchend', up).add(node, 'mousemove', move).add(node, 'mouseup', up); | ||
@@ -386,9 +370,2 @@ } | ||
function speedFactor(forceB, forceA) { | ||
var diff = delta(Math.abs(forceB), Math.abs(forceA)); | ||
if (Math.abs(forceB) <= Math.abs(forceA)) return 0; | ||
if (forceB === 0 || forceA === 0) return 0; | ||
return Math.abs(diff / forceB); | ||
} | ||
function allowedForce(force) { | ||
@@ -403,11 +380,6 @@ var scrollTarget = params.scrollTarget, | ||
if (seekNext && !dragFree && !limit.reachedAny(destination)) { | ||
var next = index.clone().add(Direction(force).get() * -1); | ||
var next = index.clone().add(mathSign(force) * -1); | ||
return scrollTarget.byIndex(next.get(), 0).distance; | ||
} | ||
if (!params.loop && edgeLimit.reachedAny(destination)) { | ||
var edge = edgeLimit.reachedMax(destination) ? 'max' : 'min'; | ||
return edgeLimit[edge] - target.get(); | ||
} | ||
return scrollTarget.byDistance(force, !dragFree).distance; | ||
@@ -419,3 +391,3 @@ } | ||
if (isMouse && evt.button !== 0) return; | ||
var isMoving = delta(target.get(), location.get()) >= 2; | ||
var isMoving = deltaAbs(target.get(), location.get()) >= 2; | ||
var clearPreventClick = isMouse || !isMoving; | ||
@@ -442,4 +414,4 @@ var isNotFocusNode = !isFocusNode(evt.target); | ||
var moveCross = dragTracker.readPoint(evt, crossAxis).get(); | ||
var diffScroll = delta(moveScroll, startScroll.get()); | ||
var diffCross = delta(moveCross, startCross.get()); | ||
var diffScroll = deltaAbs(moveScroll, startScroll.get()); | ||
var diffCross = deltaAbs(moveCross, startCross.get()); | ||
preventScroll = diffScroll > diffCross; | ||
@@ -451,6 +423,6 @@ if (!preventScroll && !preventClick) return up(); | ||
var reachedLimit = limit.reachedAny(location.get()); | ||
var resist = !params.loop && reachedLimit ? 2 : 1; | ||
var resist = !params.loop && reachedLimit ? 4 : 1; | ||
if (!preventClick && diff) preventClick = true; | ||
animation.start(); | ||
target.add(diff / resist); | ||
target.add(direction.applyTo(diff / resist)); | ||
evt.preventDefault(); | ||
@@ -460,7 +432,6 @@ } | ||
function up() { | ||
var scrollTo = params.scrollTo; | ||
var rawForce = dragTracker.pointerUp() * forceBoost(); | ||
var force = allowedForce(rawForce); | ||
var factor = speedFactor(rawForce, force); | ||
var isMoving = delta(target.get(), dragStartPoint.get()) >= 0.5; | ||
var force = allowedForce(direction.applyTo(rawForce)); | ||
var speedFactor = factorAbs(rawForce, force); | ||
var isMoving = deltaAbs(target.get(), dragStartPoint.get()) >= 0.5; | ||
if (isMoving && !isMouse) preventClick = true; | ||
@@ -470,3 +441,3 @@ preventScroll = false; | ||
interactionEvents.removeAll(); | ||
scrollBody.useSpeed(baseSpeed + baseSpeed * factor); | ||
scrollBody.useSpeed(baseSpeed + baseSpeed * speedFactor); | ||
scrollTo.distance(force, !dragFree); | ||
@@ -477,6 +448,2 @@ isMouse = false; | ||
function delta(pointB, pointA) { | ||
return Math.abs(pointB - pointA); | ||
} | ||
function click(evt) { | ||
@@ -575,2 +542,57 @@ if (preventClick) evt.preventDefault(); | ||
function Limit(params) { | ||
var min = params.min, | ||
max = params.max; | ||
var length = Math.abs(min - max); | ||
function reachedMin(n) { | ||
return n < min; | ||
} | ||
function reachedMax(n) { | ||
return n > max; | ||
} | ||
function reachedAny(n) { | ||
return reachedMin(n) || reachedMax(n); | ||
} | ||
function removeOffset(n) { | ||
if (min === max) return n; | ||
while (reachedMin(n)) { | ||
n += length; | ||
} | ||
while (reachedMax(n)) { | ||
n -= length; | ||
} | ||
return n; | ||
} | ||
function loop(n) { | ||
if (!reachedAny(n)) return n; | ||
return reachedMin(n) ? max : min; | ||
} | ||
function constrain(n) { | ||
if (!reachedAny(n)) return n; | ||
return reachedMin(n) ? min : max; | ||
} | ||
var self = { | ||
constrain: constrain, | ||
length: length, | ||
loop: loop, | ||
max: max, | ||
min: min, | ||
reachedAny: reachedAny, | ||
reachedMax: reachedMax, | ||
reachedMin: reachedMin, | ||
removeOffset: removeOffset | ||
}; | ||
return self; | ||
} | ||
function PxToPercent(viewInPx) { | ||
@@ -590,44 +612,2 @@ var totalPercent = 100; | ||
function map(value, iStart, iStop, oStart, oStop) { | ||
return oStart + (oStop - oStart) * ((value - iStart) / (iStop - iStart)); | ||
} | ||
function arrayFromCollection(nodeList) { | ||
return Array.prototype.slice.call(nodeList); | ||
} | ||
function debounce(callback, time) { | ||
var timeout = { | ||
id: 0 | ||
}; | ||
return function () { | ||
window.clearTimeout(timeout.id); | ||
timeout.id = window.setTimeout(callback, time) || 0; | ||
}; | ||
} | ||
function roundToDecimals(decimalPoints) { | ||
var pow = Math.pow(10, decimalPoints); | ||
return function (n) { | ||
return Math.round(n * pow) / pow; | ||
}; | ||
} | ||
function groupArray(array, size) { | ||
var groups = []; | ||
for (var i = 0; i < array.length; i += size) { | ||
groups.push(array.slice(i, i + size)); | ||
} | ||
return groups; | ||
} | ||
function arrayKeys(array) { | ||
return Object.keys(array).map(Number); | ||
} | ||
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); | ||
} | ||
function ScrollBody(params) { | ||
@@ -641,3 +621,3 @@ var location = params.location, | ||
var attraction = Vector1D(0); | ||
var direction = Direction(0); | ||
var attractionDirection = 0; | ||
var speed = baseSpeed; | ||
@@ -661,3 +641,3 @@ var mass = baseMass; | ||
var m = map(magnitude, 0, 100, 0, speed); | ||
direction.set(attraction); | ||
attractionDirection = mathSign(attraction.get()); | ||
attraction.normalize().multiply(m).subtract(velocity); | ||
@@ -676,2 +656,6 @@ applyForce(attraction); | ||
function direction() { | ||
return attractionDirection; | ||
} | ||
function useSpeed(n) { | ||
@@ -714,25 +698,30 @@ speed = n; | ||
var min = limit.min, | ||
max = limit.max, | ||
reachedMin = limit.reachedMin, | ||
reachedMax = limit.reachedMax; | ||
var tolerance = 50; | ||
max = limit.max; | ||
var tolerance = 70; | ||
var edgeLimit = Limit({ | ||
min: min - tolerance, | ||
max: max + tolerance | ||
}); | ||
var disabled = false; | ||
var timeout = 0; | ||
function shouldConstrain(v) { | ||
if (disabled || timeout) return false; | ||
if (reachedMin(location.get())) return v.get() !== min; | ||
if (reachedMax(location.get())) return v.get() !== max; | ||
return false; | ||
function shouldConstrain(target) { | ||
if (disabled) return false; | ||
if (!limit.reachedAny(location.get())) return false; | ||
if (target.get() === min || target.get() === max) return false; | ||
return true; | ||
} | ||
function constrain(v) { | ||
if (!shouldConstrain(v)) return; | ||
timeout = window.setTimeout(function () { | ||
var constraint = limit.constrain(v.get()); | ||
v.set(constraint); | ||
scrollBody.useSpeed(10).useMass(3); | ||
animation.start(); | ||
timeout = 0; | ||
}, tolerance); | ||
function constrain(target) { | ||
if (!shouldConstrain(target)) return; | ||
target.set(edgeLimit.constrain(target.get())); | ||
if (!timeout) { | ||
timeout = window.setTimeout(function () { | ||
target.set(limit.constrain(target.get())); | ||
scrollBody.useSpeed(10).useMass(3); | ||
animation.start(); | ||
timeout = 0; | ||
}, tolerance); | ||
} | ||
} | ||
@@ -1031,3 +1020,4 @@ | ||
scrollLocation = params.location, | ||
slidesInView = params.slidesInView; | ||
slidesInView = params.slidesInView, | ||
direction = params.direction; | ||
var contentSize = params.contentSize, | ||
@@ -1110,3 +1100,3 @@ viewSize = params.viewSize, | ||
if (target !== location) { | ||
slides[index].style[loopStyle] = target + "%"; | ||
slides[index].style[loopStyle] = direction.applyTo(target) + "%"; | ||
loopPoint.location = target; | ||
@@ -1224,10 +1214,7 @@ } | ||
var axis = params.axis, | ||
container = params.container; | ||
var translates = { | ||
x: x, | ||
y: y | ||
}; | ||
var translateAxis = translates[axis.scroll]; | ||
container = params.container, | ||
direction = params.direction; | ||
var containerStyle = container.style; | ||
var translate = axis.scroll === 'x' ? x : y; | ||
var roundToTwoDecimals = roundToDecimals(2); | ||
var containerStyle = container.style; | ||
var disabled = false; | ||
@@ -1245,10 +1232,7 @@ var location = 0; | ||
function to(v) { | ||
if (disabled) return; | ||
var target = roundToTwoDecimals(v.get()); | ||
if (location !== target) { | ||
getComputedStyle(container).transform; | ||
containerStyle.transform = translateAxis(target); | ||
location = target; | ||
} | ||
if (disabled || location === target) return; | ||
getComputedStyle(container).transform; | ||
containerStyle.transform = translate(direction.applyTo(target)); | ||
location = target; | ||
} | ||
@@ -1277,2 +1261,3 @@ | ||
scrollAxis = options.axis, | ||
contentDirection = options.direction, | ||
startIndex = options.startIndex, | ||
@@ -1318,3 +1303,9 @@ inViewThreshold = options.inViewThreshold, | ||
var containedSnaps = contain.measure(defaultSnaps, trimSnaps); | ||
var scrollSnaps = shouldContain ? containedSnaps : defaultSnaps; // Index | ||
var scrollSnaps = shouldContain ? containedSnaps : defaultSnaps; | ||
var scrollLimit = ScrollLimit({ | ||
loop: loop, | ||
contentSize: contentSize | ||
}); | ||
var limit = scrollLimit.measure(scrollSnaps); | ||
var direction = Direction(contentDirection); // Index | ||
@@ -1331,10 +1322,4 @@ var indexMax = Math.max(0, scrollSnaps.length - 1); | ||
}); | ||
var indexPrevious = index.clone(); // ScrollLimit | ||
var indexPrevious = index.clone(); // Draw | ||
var scrollLimit = ScrollLimit({ | ||
loop: loop, | ||
contentSize: contentSize | ||
}); | ||
var limit = scrollLimit.measure(scrollSnaps); // Draw | ||
var update = function update() { | ||
@@ -1344,3 +1329,3 @@ engine.scrollBody.seek(target).update(); | ||
if (!dragHandler.pointerDown()) { | ||
if (!engine.dragHandler.pointerDown()) { | ||
if (!loop) engine.scrollBounds.constrain(target); | ||
@@ -1355,4 +1340,3 @@ | ||
if (loop) { | ||
var direction = engine.scrollBody.direction.get(); | ||
engine.scrollLooper.loop(loopVectors, direction); | ||
engine.scrollLooper.loop(loopVectors, engine.scrollBody.direction()); | ||
engine.slideLooper.loop(slides); | ||
@@ -1404,2 +1388,3 @@ } | ||
axis: axis, | ||
direction: direction, | ||
dragFree: dragFree, | ||
@@ -1410,3 +1395,3 @@ dragTracker: DragTracker({ | ||
}), | ||
element: root, | ||
root: root, | ||
events: events, | ||
@@ -1426,2 +1411,3 @@ index: index, | ||
axis: axis, | ||
direction: direction, | ||
dragHandler: dragHandler, | ||
@@ -1461,2 +1447,3 @@ pxToPercent: pxToPercent, | ||
contentSize: contentSize, | ||
direction: direction, | ||
location: location, | ||
@@ -1473,3 +1460,4 @@ scrollSnaps: scrollSnaps, | ||
axis: axis, | ||
container: container | ||
container: container, | ||
direction: direction | ||
}) | ||
@@ -1525,2 +1513,3 @@ }; | ||
containerSelector: '*', | ||
direction: 'ltr', | ||
dragFree: false, | ||
@@ -1561,3 +1550,3 @@ draggable: true, | ||
container = sliderContainer; | ||
slides = arrayFromCollection(container.children); | ||
slides = Array.prototype.slice.call(container.children); | ||
} | ||
@@ -1564,0 +1553,0 @@ |
449
react.js
@@ -107,2 +107,51 @@ 'use strict'; | ||
function map(value, iStart, iStop, oStart, oStop) { | ||
return oStart + (oStop - oStart) * ((value - iStart) / (iStop - iStart)); | ||
} | ||
function mathSign(n) { | ||
return !n ? 0 : n / Math.abs(n); | ||
} | ||
function deltaAbs(valueB, valueA) { | ||
return Math.abs(valueB - valueA); | ||
} | ||
function factorAbs(valueB, valueA) { | ||
if (valueB === 0 || valueA === 0) return 0; | ||
if (Math.abs(valueB) <= Math.abs(valueA)) return 0; | ||
var diff = deltaAbs(Math.abs(valueB), Math.abs(valueA)); | ||
return Math.abs(diff / valueB); | ||
} | ||
function roundToDecimals(decimalPoints) { | ||
var pow = Math.pow(10, decimalPoints); | ||
return function (n) { | ||
return Math.round(n * pow) / pow; | ||
}; | ||
} | ||
function debounce(callback, time) { | ||
var timeout = 0; | ||
return function () { | ||
window.clearTimeout(timeout); | ||
timeout = window.setTimeout(callback, time) || 0; | ||
}; | ||
} | ||
function groupArray(array, size) { | ||
var groups = []; | ||
for (var i = 0; i < array.length; i += size) { | ||
groups.push(array.slice(i, i + size)); | ||
} | ||
return groups; | ||
} | ||
function arrayKeys(array) { | ||
return Object.keys(array).map(Number); | ||
} | ||
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); | ||
} | ||
function Counter(params) { | ||
@@ -129,3 +178,3 @@ var start = params.start, | ||
if (n !== 0) { | ||
var sign = n / Math.abs(n); | ||
var sign = mathSign(n); | ||
set(get() + sign); | ||
@@ -157,51 +206,11 @@ return add(n + sign * -1); | ||
function Vector1D(value) { | ||
var vector = value; | ||
function Direction(direction) { | ||
var sign = direction === 'rtl' ? -1 : 1; | ||
function get() { | ||
return vector; | ||
function applyTo(n) { | ||
return n * sign; | ||
} | ||
function set(n) { | ||
vector = readNumber(n); | ||
return self; | ||
} | ||
function add(n) { | ||
vector += readNumber(n); | ||
return self; | ||
} | ||
function subtract(n) { | ||
vector -= readNumber(n); | ||
return self; | ||
} | ||
function multiply(n) { | ||
vector *= n; | ||
return self; | ||
} | ||
function divide(n) { | ||
vector /= n; | ||
return self; | ||
} | ||
function normalize() { | ||
if (vector !== 0) divide(vector); | ||
return self; | ||
} | ||
function readNumber(n) { | ||
return typeof n === 'number' ? n : n.get(); | ||
} | ||
var self = { | ||
add: add, | ||
divide: divide, | ||
get: get, | ||
multiply: multiply, | ||
normalize: normalize, | ||
set: set, | ||
subtract: subtract | ||
applyTo: applyTo | ||
}; | ||
@@ -211,23 +220,2 @@ return self; | ||
function Direction(value) { | ||
var direction = Vector1D(normalize(value)); | ||
var get = direction.get; | ||
function normalize(n) { | ||
return n === 0 ? 0 : n / Math.abs(n); | ||
} | ||
function set(v) { | ||
var d = normalize(v.get()); | ||
if (d !== 0) direction.set(d); | ||
return self; | ||
} | ||
var self = { | ||
get: get, | ||
set: set | ||
}; | ||
return self; | ||
} | ||
function EventStore() { | ||
@@ -262,53 +250,51 @@ var listeners = []; | ||
function Limit(params) { | ||
var min = params.min, | ||
max = params.max; | ||
var length = Math.abs(min - max); | ||
function Vector1D(value) { | ||
var vector = value; | ||
function reachedMin(n) { | ||
return n < min; | ||
function get() { | ||
return vector; | ||
} | ||
function reachedMax(n) { | ||
return n > max; | ||
function set(n) { | ||
vector = readNumber(n); | ||
return self; | ||
} | ||
function reachedAny(n) { | ||
return reachedMin(n) || reachedMax(n); | ||
function add(n) { | ||
vector += readNumber(n); | ||
return self; | ||
} | ||
function removeOffset(n) { | ||
if (min === max) return n; | ||
function subtract(n) { | ||
vector -= readNumber(n); | ||
return self; | ||
} | ||
while (reachedMin(n)) { | ||
n += length; | ||
} | ||
function multiply(n) { | ||
vector *= n; | ||
return self; | ||
} | ||
while (reachedMax(n)) { | ||
n -= length; | ||
} | ||
return n; | ||
function divide(n) { | ||
vector /= n; | ||
return self; | ||
} | ||
function loop(n) { | ||
if (!reachedAny(n)) return n; | ||
return reachedMin(n) ? max : min; | ||
function normalize() { | ||
if (vector !== 0) divide(vector); | ||
return self; | ||
} | ||
function constrain(n) { | ||
if (!reachedAny(n)) return n; | ||
return reachedMin(n) ? min : max; | ||
function readNumber(n) { | ||
return typeof n === 'number' ? n : n.get(); | ||
} | ||
var self = { | ||
constrain: constrain, | ||
length: length, | ||
loop: loop, | ||
max: max, | ||
min: min, | ||
reachedAny: reachedAny, | ||
reachedMax: reachedMax, | ||
reachedMin: reachedMin, | ||
removeOffset: removeOffset | ||
add: add, | ||
divide: divide, | ||
get: get, | ||
multiply: multiply, | ||
normalize: normalize, | ||
set: set, | ||
subtract: subtract | ||
}; | ||
@@ -323,8 +309,10 @@ return self; | ||
animation = params.animation, | ||
axis = params.axis; | ||
var element = params.element, | ||
axis = params.axis, | ||
scrollTo = params.scrollTo; | ||
var root = params.root, | ||
dragTracker = params.dragTracker, | ||
location = params.location, | ||
events = params.events, | ||
limit = params.limit; | ||
limit = params.limit, | ||
direction = params.direction; | ||
var scrollAxis = axis.scroll, | ||
@@ -348,6 +336,2 @@ crossAxis = axis.cross; | ||
var dragThreshold = 4; | ||
var edgeLimit = Limit({ | ||
min: limit.min - 70, | ||
max: limit.max + 70 | ||
}); | ||
var pointerIsDown = false; | ||
@@ -359,3 +343,3 @@ var preventScroll = false; | ||
function addActivationEvents() { | ||
var node = element; | ||
var node = root; | ||
activationEvents.add(node, 'touchmove', function () { | ||
@@ -369,3 +353,3 @@ return undefined; | ||
function addInteractionEvents() { | ||
var node = !isMouse ? element : document; | ||
var node = !isMouse ? root : document; | ||
interactionEvents.add(node, 'touchmove', move).add(node, 'touchend', up).add(node, 'mousemove', move).add(node, 'mouseup', up); | ||
@@ -390,9 +374,2 @@ } | ||
function speedFactor(forceB, forceA) { | ||
var diff = delta(Math.abs(forceB), Math.abs(forceA)); | ||
if (Math.abs(forceB) <= Math.abs(forceA)) return 0; | ||
if (forceB === 0 || forceA === 0) return 0; | ||
return Math.abs(diff / forceB); | ||
} | ||
function allowedForce(force) { | ||
@@ -407,11 +384,6 @@ var scrollTarget = params.scrollTarget, | ||
if (seekNext && !dragFree && !limit.reachedAny(destination)) { | ||
var next = index.clone().add(Direction(force).get() * -1); | ||
var next = index.clone().add(mathSign(force) * -1); | ||
return scrollTarget.byIndex(next.get(), 0).distance; | ||
} | ||
if (!params.loop && edgeLimit.reachedAny(destination)) { | ||
var edge = edgeLimit.reachedMax(destination) ? 'max' : 'min'; | ||
return edgeLimit[edge] - target.get(); | ||
} | ||
return scrollTarget.byDistance(force, !dragFree).distance; | ||
@@ -423,3 +395,3 @@ } | ||
if (isMouse && evt.button !== 0) return; | ||
var isMoving = delta(target.get(), location.get()) >= 2; | ||
var isMoving = deltaAbs(target.get(), location.get()) >= 2; | ||
var clearPreventClick = isMouse || !isMoving; | ||
@@ -446,4 +418,4 @@ var isNotFocusNode = !isFocusNode(evt.target); | ||
var moveCross = dragTracker.readPoint(evt, crossAxis).get(); | ||
var diffScroll = delta(moveScroll, startScroll.get()); | ||
var diffCross = delta(moveCross, startCross.get()); | ||
var diffScroll = deltaAbs(moveScroll, startScroll.get()); | ||
var diffCross = deltaAbs(moveCross, startCross.get()); | ||
preventScroll = diffScroll > diffCross; | ||
@@ -455,6 +427,6 @@ if (!preventScroll && !preventClick) return up(); | ||
var reachedLimit = limit.reachedAny(location.get()); | ||
var resist = !params.loop && reachedLimit ? 2 : 1; | ||
var resist = !params.loop && reachedLimit ? 4 : 1; | ||
if (!preventClick && diff) preventClick = true; | ||
animation.start(); | ||
target.add(diff / resist); | ||
target.add(direction.applyTo(diff / resist)); | ||
evt.preventDefault(); | ||
@@ -464,7 +436,6 @@ } | ||
function up() { | ||
var scrollTo = params.scrollTo; | ||
var rawForce = dragTracker.pointerUp() * forceBoost(); | ||
var force = allowedForce(rawForce); | ||
var factor = speedFactor(rawForce, force); | ||
var isMoving = delta(target.get(), dragStartPoint.get()) >= 0.5; | ||
var force = allowedForce(direction.applyTo(rawForce)); | ||
var speedFactor = factorAbs(rawForce, force); | ||
var isMoving = deltaAbs(target.get(), dragStartPoint.get()) >= 0.5; | ||
if (isMoving && !isMouse) preventClick = true; | ||
@@ -474,3 +445,3 @@ preventScroll = false; | ||
interactionEvents.removeAll(); | ||
scrollBody.useSpeed(baseSpeed + baseSpeed * factor); | ||
scrollBody.useSpeed(baseSpeed + baseSpeed * speedFactor); | ||
scrollTo.distance(force, !dragFree); | ||
@@ -481,6 +452,2 @@ isMouse = false; | ||
function delta(pointB, pointA) { | ||
return Math.abs(pointB - pointA); | ||
} | ||
function click(evt) { | ||
@@ -579,2 +546,57 @@ if (preventClick) evt.preventDefault(); | ||
function Limit(params) { | ||
var min = params.min, | ||
max = params.max; | ||
var length = Math.abs(min - max); | ||
function reachedMin(n) { | ||
return n < min; | ||
} | ||
function reachedMax(n) { | ||
return n > max; | ||
} | ||
function reachedAny(n) { | ||
return reachedMin(n) || reachedMax(n); | ||
} | ||
function removeOffset(n) { | ||
if (min === max) return n; | ||
while (reachedMin(n)) { | ||
n += length; | ||
} | ||
while (reachedMax(n)) { | ||
n -= length; | ||
} | ||
return n; | ||
} | ||
function loop(n) { | ||
if (!reachedAny(n)) return n; | ||
return reachedMin(n) ? max : min; | ||
} | ||
function constrain(n) { | ||
if (!reachedAny(n)) return n; | ||
return reachedMin(n) ? min : max; | ||
} | ||
var self = { | ||
constrain: constrain, | ||
length: length, | ||
loop: loop, | ||
max: max, | ||
min: min, | ||
reachedAny: reachedAny, | ||
reachedMax: reachedMax, | ||
reachedMin: reachedMin, | ||
removeOffset: removeOffset | ||
}; | ||
return self; | ||
} | ||
function PxToPercent(viewInPx) { | ||
@@ -594,44 +616,2 @@ var totalPercent = 100; | ||
function map(value, iStart, iStop, oStart, oStop) { | ||
return oStart + (oStop - oStart) * ((value - iStart) / (iStop - iStart)); | ||
} | ||
function arrayFromCollection(nodeList) { | ||
return Array.prototype.slice.call(nodeList); | ||
} | ||
function debounce(callback, time) { | ||
var timeout = { | ||
id: 0 | ||
}; | ||
return function () { | ||
window.clearTimeout(timeout.id); | ||
timeout.id = window.setTimeout(callback, time) || 0; | ||
}; | ||
} | ||
function roundToDecimals(decimalPoints) { | ||
var pow = Math.pow(10, decimalPoints); | ||
return function (n) { | ||
return Math.round(n * pow) / pow; | ||
}; | ||
} | ||
function groupArray(array, size) { | ||
var groups = []; | ||
for (var i = 0; i < array.length; i += size) { | ||
groups.push(array.slice(i, i + size)); | ||
} | ||
return groups; | ||
} | ||
function arrayKeys(array) { | ||
return Object.keys(array).map(Number); | ||
} | ||
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); | ||
} | ||
function ScrollBody(params) { | ||
@@ -645,3 +625,3 @@ var location = params.location, | ||
var attraction = Vector1D(0); | ||
var direction = Direction(0); | ||
var attractionDirection = 0; | ||
var speed = baseSpeed; | ||
@@ -665,3 +645,3 @@ var mass = baseMass; | ||
var m = map(magnitude, 0, 100, 0, speed); | ||
direction.set(attraction); | ||
attractionDirection = mathSign(attraction.get()); | ||
attraction.normalize().multiply(m).subtract(velocity); | ||
@@ -680,2 +660,6 @@ applyForce(attraction); | ||
function direction() { | ||
return attractionDirection; | ||
} | ||
function useSpeed(n) { | ||
@@ -718,25 +702,30 @@ speed = n; | ||
var min = limit.min, | ||
max = limit.max, | ||
reachedMin = limit.reachedMin, | ||
reachedMax = limit.reachedMax; | ||
var tolerance = 50; | ||
max = limit.max; | ||
var tolerance = 70; | ||
var edgeLimit = Limit({ | ||
min: min - tolerance, | ||
max: max + tolerance | ||
}); | ||
var disabled = false; | ||
var timeout = 0; | ||
function shouldConstrain(v) { | ||
if (disabled || timeout) return false; | ||
if (reachedMin(location.get())) return v.get() !== min; | ||
if (reachedMax(location.get())) return v.get() !== max; | ||
return false; | ||
function shouldConstrain(target) { | ||
if (disabled) return false; | ||
if (!limit.reachedAny(location.get())) return false; | ||
if (target.get() === min || target.get() === max) return false; | ||
return true; | ||
} | ||
function constrain(v) { | ||
if (!shouldConstrain(v)) return; | ||
timeout = window.setTimeout(function () { | ||
var constraint = limit.constrain(v.get()); | ||
v.set(constraint); | ||
scrollBody.useSpeed(10).useMass(3); | ||
animation.start(); | ||
timeout = 0; | ||
}, tolerance); | ||
function constrain(target) { | ||
if (!shouldConstrain(target)) return; | ||
target.set(edgeLimit.constrain(target.get())); | ||
if (!timeout) { | ||
timeout = window.setTimeout(function () { | ||
target.set(limit.constrain(target.get())); | ||
scrollBody.useSpeed(10).useMass(3); | ||
animation.start(); | ||
timeout = 0; | ||
}, tolerance); | ||
} | ||
} | ||
@@ -1035,3 +1024,4 @@ | ||
scrollLocation = params.location, | ||
slidesInView = params.slidesInView; | ||
slidesInView = params.slidesInView, | ||
direction = params.direction; | ||
var contentSize = params.contentSize, | ||
@@ -1114,3 +1104,3 @@ viewSize = params.viewSize, | ||
if (target !== location) { | ||
slides[index].style[loopStyle] = target + "%"; | ||
slides[index].style[loopStyle] = direction.applyTo(target) + "%"; | ||
loopPoint.location = target; | ||
@@ -1228,10 +1218,7 @@ } | ||
var axis = params.axis, | ||
container = params.container; | ||
var translates = { | ||
x: x, | ||
y: y | ||
}; | ||
var translateAxis = translates[axis.scroll]; | ||
container = params.container, | ||
direction = params.direction; | ||
var containerStyle = container.style; | ||
var translate = axis.scroll === 'x' ? x : y; | ||
var roundToTwoDecimals = roundToDecimals(2); | ||
var containerStyle = container.style; | ||
var disabled = false; | ||
@@ -1249,10 +1236,7 @@ var location = 0; | ||
function to(v) { | ||
if (disabled) return; | ||
var target = roundToTwoDecimals(v.get()); | ||
if (location !== target) { | ||
getComputedStyle(container).transform; | ||
containerStyle.transform = translateAxis(target); | ||
location = target; | ||
} | ||
if (disabled || location === target) return; | ||
getComputedStyle(container).transform; | ||
containerStyle.transform = translate(direction.applyTo(target)); | ||
location = target; | ||
} | ||
@@ -1281,2 +1265,3 @@ | ||
scrollAxis = options.axis, | ||
contentDirection = options.direction, | ||
startIndex = options.startIndex, | ||
@@ -1322,3 +1307,9 @@ inViewThreshold = options.inViewThreshold, | ||
var containedSnaps = contain.measure(defaultSnaps, trimSnaps); | ||
var scrollSnaps = shouldContain ? containedSnaps : defaultSnaps; // Index | ||
var scrollSnaps = shouldContain ? containedSnaps : defaultSnaps; | ||
var scrollLimit = ScrollLimit({ | ||
loop: loop, | ||
contentSize: contentSize | ||
}); | ||
var limit = scrollLimit.measure(scrollSnaps); | ||
var direction = Direction(contentDirection); // Index | ||
@@ -1335,10 +1326,4 @@ var indexMax = Math.max(0, scrollSnaps.length - 1); | ||
}); | ||
var indexPrevious = index.clone(); // ScrollLimit | ||
var indexPrevious = index.clone(); // Draw | ||
var scrollLimit = ScrollLimit({ | ||
loop: loop, | ||
contentSize: contentSize | ||
}); | ||
var limit = scrollLimit.measure(scrollSnaps); // Draw | ||
var update = function update() { | ||
@@ -1348,3 +1333,3 @@ engine.scrollBody.seek(target).update(); | ||
if (!dragHandler.pointerDown()) { | ||
if (!engine.dragHandler.pointerDown()) { | ||
if (!loop) engine.scrollBounds.constrain(target); | ||
@@ -1359,4 +1344,3 @@ | ||
if (loop) { | ||
var direction = engine.scrollBody.direction.get(); | ||
engine.scrollLooper.loop(loopVectors, direction); | ||
engine.scrollLooper.loop(loopVectors, engine.scrollBody.direction()); | ||
engine.slideLooper.loop(slides); | ||
@@ -1408,2 +1392,3 @@ } | ||
axis: axis, | ||
direction: direction, | ||
dragFree: dragFree, | ||
@@ -1414,3 +1399,3 @@ dragTracker: DragTracker({ | ||
}), | ||
element: root, | ||
root: root, | ||
events: events, | ||
@@ -1430,2 +1415,3 @@ index: index, | ||
axis: axis, | ||
direction: direction, | ||
dragHandler: dragHandler, | ||
@@ -1465,2 +1451,3 @@ pxToPercent: pxToPercent, | ||
contentSize: contentSize, | ||
direction: direction, | ||
location: location, | ||
@@ -1477,3 +1464,4 @@ scrollSnaps: scrollSnaps, | ||
axis: axis, | ||
container: container | ||
container: container, | ||
direction: direction | ||
}) | ||
@@ -1529,2 +1517,3 @@ }; | ||
containerSelector: '*', | ||
direction: 'ltr', | ||
dragFree: false, | ||
@@ -1565,3 +1554,3 @@ draggable: true, | ||
container = sliderContainer; | ||
slides = arrayFromCollection(container.children); | ||
slides = Array.prototype.slice.call(container.children); | ||
} | ||
@@ -1568,0 +1557,0 @@ |
@@ -93,2 +93,5 @@ <br /> | ||
<a href="https://github.com/msallent"><img src="https://avatars3.githubusercontent.com/u/8879212?s=122&v=4" title="msallent" width="66" height="66" style="max-width:100%;"></a> | ||
<a href="https://github.com/omarkhatibco"><img src="https://avatars1.githubusercontent.com/u/9054278?s=122&v=4" title="msallent" width="66" height="66" style="max-width:100%;"></a> | ||
<a href="https://github.com/ppromerojr"><img src="https://avatars1.githubusercontent.com/u/15343254?s=122&v=4" title="wopian" width="66" height="66" style="max-width:100%;"></a> | ||
</p> | ||
@@ -95,0 +98,0 @@ </div> |
@@ -1,6 +0,5 @@ | ||
import { Vector1D } from './vector1d'; | ||
export declare type DirectionOption = 'ltr' | 'rtl'; | ||
export declare type Direction = { | ||
get: () => number; | ||
set: (v: Vector1D) => Direction; | ||
applyTo: (n: number) => number; | ||
}; | ||
export declare function Direction(value: number): Direction; | ||
export declare function Direction(direction: DirectionOption): Direction; |
import { Animation } from './animation'; | ||
import { Counter } from './counter'; | ||
import { Direction } from './direction'; | ||
import { DragTracker } from './dragTracker'; | ||
@@ -13,3 +14,4 @@ import { EventEmitter } from './eventEmitter'; | ||
axis: Axis; | ||
element: HTMLElement; | ||
direction: Direction; | ||
root: HTMLElement; | ||
target: Vector1D; | ||
@@ -16,0 +18,0 @@ dragFree: boolean; |
import { Animation } from './animation'; | ||
import { Axis } from './axis'; | ||
import { Counter } from './counter'; | ||
import { Direction } from './direction'; | ||
import { DragHandler } from './dragHandler'; | ||
@@ -22,2 +23,3 @@ import { EventEmitter } from './eventEmitter'; | ||
axis: Axis; | ||
direction: Direction; | ||
animation: Animation; | ||
@@ -24,0 +26,0 @@ scrollBounds: ScrollBounds; |
import { AlignmentOption } from './alignment'; | ||
import { AxisOption } from './axis'; | ||
import { DirectionOption } from './direction'; | ||
import { ScrollContainOption } from './scrollContain'; | ||
@@ -9,2 +10,3 @@ export declare type Options = { | ||
containerSelector: string; | ||
direction: DirectionOption; | ||
dragFree: boolean; | ||
@@ -11,0 +13,0 @@ draggable: boolean; |
@@ -1,2 +0,1 @@ | ||
import { Direction } from './direction'; | ||
import { Vector1D } from './vector1d'; | ||
@@ -9,3 +8,3 @@ declare type Params = { | ||
export declare type ScrollBody = { | ||
direction: Direction; | ||
direction: () => number; | ||
seek: (v: Vector1D) => ScrollBody; | ||
@@ -12,0 +11,0 @@ settle: (v: Vector1D) => boolean; |
import { Axis } from './axis'; | ||
import { Direction } from './direction'; | ||
import { SlidesInView } from './slidesInView'; | ||
@@ -6,2 +7,3 @@ import { Vector1D } from './vector1d'; | ||
axis: Axis; | ||
direction: Direction; | ||
scrollSnaps: number[]; | ||
@@ -8,0 +10,0 @@ viewSize: number; |
import { Axis } from './axis'; | ||
import { Direction } from './direction'; | ||
import { Vector1D } from './vector1d'; | ||
@@ -6,2 +7,3 @@ declare type Params = { | ||
container: HTMLElement; | ||
direction: Direction; | ||
}; | ||
@@ -8,0 +10,0 @@ export declare type Translate = { |
export declare function map(value: number, iStart: number, iStop: number, oStart: number, oStop: number): number; | ||
export declare function arrayFromCollection(nodeList: HTMLCollection): HTMLElement[]; | ||
export declare function mathSign(n: number): number; | ||
export declare function deltaAbs(valueB: number, valueA: number): number; | ||
export declare function factorAbs(valueB: number, valueA: number): number; | ||
export declare function roundToDecimals(decimalPoints: number): (n: number) => number; | ||
export declare function debounce(callback: () => void, time: number): () => void; | ||
export declare function roundToDecimals(decimalPoints: number): (n: number) => number; | ||
export declare function groupArray<GenericType>(array: GenericType[], size: number): GenericType[][]; | ||
@@ -6,0 +8,0 @@ export declare function arrayKeys<GenericType>(array: GenericType): number[]; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
654149
132
6583