Comparing version 0.6.3 to 0.7.0
/** | ||
* Muuri v0.6.3 | ||
* Muuri v0.7.0 | ||
* https://github.com/haltu/muuri | ||
@@ -17,2 +17,2 @@ * Copyright (c) 2015-present, Haltu Oy | ||
*/ | ||
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i(require("hammerjs")):"function"==typeof define&&define.amd?define(["hammerjs"],i):t.Muuri=i(t.Hammer)}(this,function(t){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t;var i="Muuri",e={},s="layoutEnd";function n(){this._events={},this._queue=[],this._processCount=0,this._isDestroyed=!1}n.prototype.on=function(t,i){if(this._isDestroyed)return this;var e=this._events[t];return e||(e=this._events[t]=[]),e.push(i),this},n.prototype.once=function(t,i){if(this._isDestroyed)return this;var e=function(){this.off(t,e),i.apply(null,arguments)}.bind(this);return this.on(t,e)},n.prototype.off=function(t,i){if(this._isDestroyed)return this;var e=this._events[t];if(!e||!e.length)return this;if(!i)return e.length=0,this;for(var s=e.length;s--;)i===e[s]&&e.splice(s,1);return this},n.prototype.emit=function(t,i,e,s){if(this._isDestroyed)return this;var n=this._events[t];if(!n||!n.length)return this;var r,o,h=this._queue,a=h.length,_=arguments.length-1;for(o=0;o<n.length;o++)h.push(n[o]);for(r=h.length,++this._processCount,o=a;o<r;o++)if(0===_?h[o]():1===_?h[o](i):2===_?h[o](i,e):h[o](i,e,s),this._isDestroyed)return this;return--this._processCount,this._processCount||r!==h.length||(h.length=0),this},n.prototype.destroy=function(){if(this._isDestroyed)return this;var t,i=this._events;for(t in this._isDestroyed=!0,this._queue.length=this._processCount=0,i)i[t]&&(i[t].length=0,i[t]=void 0);return this};var r=!1,o="transform",h="transform";["","Webkit","Moz","O","ms"].forEach(function(t){if(!r){var i=t?t+"Transform":"transform";void 0!==document.documentElement.style[i]&&(t=t.toLowerCase(),o=t?"-"+t+"-transform":"transform",h=i,r=!0)}});var a="function"==typeof WeakMap?new WeakMap:null;function _(t,i){var e=a&&a.get(t);return e||(e=window.getComputedStyle(t,null),a&&a.set(t,e)),e.getPropertyValue("transform"===i?o:i)}function l(t,i){var e={};for(var s in i)e[s]=_(t,s.replace(/([A-Z])/g,"-$1").toLowerCase());return e}function d(t,i){for(var e in i)t.style["transform"===e?h:e]=i[e]}function f(t,i){this._item=t,this._element=i,this._animation=null,this._propsTo=null,this._callback=null,this._keyframes=[],this._options={},this._isDestroyed=!1,this._onFinish=this._onFinish.bind(this)}f.prototype.start=function(t,i,e){if(!this._isDestroyed){var s,n=e||0,r="function"==typeof n.onFinish?n.onFinish:null,o=!1;if(this._animation){for(s in i)if(i[s]!==this._propsTo[s]){o=!0;break}if(!o)return void(this._callback=r);this._animation.cancel()}for(s in this._callback=r,this._propsTo={},i)this._propsTo[s]=i[s];this._keyframes[0]=t,this._keyframes[1]=i,this._options.duration=n.duration||300,this._options.easing=n.easing||"ease",this._animation=this._element.animate(this._keyframes,this._options),this._animation.onfinish=this._onFinish,d(this._element,i)}},f.prototype.stop=function(t){!this._isDestroyed&&this._animation&&(d(this._element,t||l(this._element,this._propsTo)),this._animation.cancel(),this._animation=this._propsTo=this._callback=null)},f.prototype.isAnimating=function(){return!!this._animation},f.prototype.destroy=function(){this._isDestroyed||(this.stop(),this._item=this._element=this._options=this._keyframes=null,this._isDestroyed=!0)},f.prototype._onFinish=function(){var t=this._callback;this._animation=this._propsTo=this._callback=null,t&&t()};var u=(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame||function(t){return window.setTimeout(t,16)}).bind(window);function c(){this._nextTick=null,this._queue=[],this._reads={},this._writes={},this._batch=[],this._batchReads={},this._batchWrites={},this._flush=this._flush.bind(this)}c.prototype.add=function(t,i,e,s){var n=this._queue.indexOf(t);n>-1&&(this._queue[n]=void 0),s?this._queue.unshift(t):this._queue.push(t),this._reads[t]=i,this._writes[t]=e,this._nextTick||(this._nextTick=u(this._flush))},c.prototype.cancel=function(t){var i=this._queue.indexOf(t);i>-1&&(this._queue[i]=void 0,this._reads[t]=void 0,this._writes[t]=void 0)},c.prototype._flush=function(){var t,i,e=this._queue,s=this._reads,n=this._writes,r=this._batch,o=this._batchReads,h=this._batchWrites,a=e.length;for(this._nextTick=null,i=0;i<a;i++)(t=e[i])&&(r.push(t),o[t]=s[t],s[t]=void 0,h[t]=n[t],n[t]=void 0);for(e.length=0,i=0;i<a;i++)o[t=r[i]]&&(o[t](),o[t]=void 0);for(i=0;i<a;i++)h[t=r[i]]&&(h[t](),h[t]=void 0);r.length=0,!this._nextTick&&e.length&&(this._nextTick=u(this._flush))};var p=new c,m=Element.prototype,g=m.matches||m.matchesSelector||m.webkitMatchesSelector||m.mozMatchesSelector||m.msMatchesSelector||m.oMatchesSelector;function y(t,i){return g.call(t,i)}var v="classList"in Element.prototype?function(t,i){t.classList.add(i)}:function(t,i){y(t,"."+i)||(t.className+=" "+i)};function w(t,i,e){var s=t.length,n=Math.max(0,e?s:s-1);return i>n?n:i<0?Math.max(n+i+1,0):i}function D(t,i,e){if(!(t.length<2)){var s=w(t,i),n=w(t,e);s!==n&&t.splice(n,0,t.splice(s,1)[0])}}function b(t,i,e){if(!(t.length<2)){var s,n=w(t,i),r=w(t,e);n!==r&&(s=t[n],t[n]=t[r],t[r]=s)}}var S="cancel",A="finish";function C(t,i){var e;return i>0?function(s){void 0!==e&&(e=window.clearTimeout(e),s===A&&t()),s!==S&&s!==A&&(e=window.setTimeout(function(){e=void 0,t()},i))}:function(i){i!==S&&t()}}function x(t){var i=_(t,"transform");if(!i||"none"===i)return!1;var e=_(t,"display");return"inline"!==e&&"none"!==e}function R(t,i){for(var e=(i?t:t.parentElement)||document;e&&e!==document&&"static"===_(e,"position")&&!x(e);)e=e.parentElement||document;return e}function I(t,i){return parseFloat(_(t,i))||0}var L={},E={},M={};function H(t,i){var e,s=i||{};return s.left=0,s.top=0,t===document?s:(s.left=window.pageXOffset||0,s.top=window.pageYOffset||0,t.self===window.self?s:(e=t.getBoundingClientRect(),s.left+=e.left,s.top+=e.top,s.left+=I(t,"border-left-width"),s.top+=I(t,"border-top-width"),s))}function G(t,i,e){return M.left=0,M.top=0,t===i?M:e&&(t=R(t,!0))===(i=R(i,!0))?M:(H(t,L),H(i,E),M.left=E.left-L.left,M.top=E.top-L.top,M)}var T={};function P(t){T.x=0,T.y=0;var i=_(t,"transform");if(!i)return T;var e=i.replace("matrix(","").split(",");return T.x=parseFloat(e[4])||0,T.y=parseFloat(e[5])||0,T}function k(t,i){return"translateX("+t+"px) translateY("+i+"px)"}var O=[];function X(t,i,e){var s="number"==typeof e?e:-1;s<0&&(s=t.length-s+1),t.splice.apply(t,O.concat(s,0,i)),O.length=0}var Y="[object Object]",q=Object.prototype.toString;function B(t){return"object"==typeof t&&q.call(t)===Y}var N="classList"in Element.prototype?function(t,i){t.classList.remove(i)}:function(t,i){y(t,"."+i)&&(t.className=(" "+t.className+" ").replace(" "+i+" "," ").trim())},F=Q(),z=0,V=1,W=2,j=3;function U(e){if(!t)throw new Error("["+i+"] required dependency Hammer is not defined.");null===F&&(F=Q());var s,n,r=this,o=e._element,h=e.getGrid(),a=h._settings,_="function"==typeof a.dragStartPredicate?a.dragStartPredicate:U.defaultStartPredicate,l=z;this._item=e,this._gridId=h._id,this._hammer=s=new t.Manager(o),this._isDestroyed=!1,this._isMigrating=!1,this._reset(),this._onScroll=this._onScroll.bind(this),this._prepareMove=this._prepareMove.bind(this),this._applyMove=this._applyMove.bind(this),this._prepareScroll=this._prepareScroll.bind(this),this._applyScroll=this._applyScroll.bind(this),this._checkOverlap=this._checkOverlap.bind(this),this._forceResolveStartPredicate=function(t){this._isDestroyed||l!==V||(l=W,this._onStart(t))},this._checkOverlapDebounce=C(this._checkOverlap,a.dragSortInterval),s.add(new t.Pan({event:"drag",pointers:1,threshold:0,direction:t.DIRECTION_ALL})),s.add(new t.Press({event:"draginit",pointers:1,threshold:1e3,time:0})),B(a.dragHammerSettings)&&s.set(a.dragHammerSettings),s.on("draginit dragstart dragmove",function(t){l===z&&(l=V),l===V?!0===(n=_(r._item,t))?(l=W,r._onStart(t)):!1===n&&(l=j):l===W&&r._isActive&&r._onMove(t)}).on("dragend dragcancel draginitup",function(t){var i=l===W;_(r._item,t),l=z,i&&r._isActive&&r._onEnd(t)}),o.addEventListener("dragstart",Z,!1)}function Z(t){t.preventDefault&&t.preventDefault()}function $(t,i){return t.left+t.width<=i.left||i.left+i.width<=t.left||t.top+t.height<=i.top||i.top+i.height<=t.top?0:(Math.min(t.left+t.width,i.left+i.width)-Math.max(t.left,i.left))*(Math.min(t.top+t.height,i.top+i.height)-Math.max(t.top,i.top))/(Math.min(t.width,i.width)*Math.min(t.height,i.height))*100}function J(t,i){var e=i||[],s=t.parentNode;if(F){if("fixed"===_(t,"position"))return e;for(;s&&s!==document&&s!==document.documentElement;)K(s)&&e.push(s),s="fixed"===_(s,"position")?null:s.parentNode;return null!==s&&e.push(window),e}for(;s&&s!==document;)"fixed"!==_(t,"position")||x(s)?(K(s)&&e.push(s),t=s,s=s.parentNode):s=s.parentNode;return e[e.length-1]===document.documentElement?e[e.length-1]=window:e.push(window),e}function K(t){var i=_(t,"overflow");return"auto"===i||"scroll"===i||("auto"===(i=_(t,"overflow-x"))||"scroll"===i||("auto"===(i=_(t,"overflow-y"))||"scroll"===i))}function Q(){if(!r)return!0;if(!document.body)return null;var t=[0,1].map(function(t,i){return(t=document.createElement("div")).style.position=i?"fixed":"absolute",t.style.display="block",t.style.visibility="hidden",t.style.left=i?"0px":"1px",t.style[h]="none",t}),i=document.body.appendChild(t[0]),e=i.appendChild(t[1]),s=e.getBoundingClientRect().left;i.style[h]="scale(1)";var n=s===e.getBoundingClientRect().left;return document.body.removeChild(i),n}function tt(){this._queue=[],this._isDestroyed=!1}function it(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._isInterrupted=!1,this._currentStyles={},this._targetStyles={},this._currentLeft=0,this._currentTop=0,this._offsetLeft=0,this._offsetTop=0,this._skipNextAnimation=!1,this._animateOptions={onFinish:this._finish.bind(this)},this._queue=new tt,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this)}U.defaultStartPredicate=function(t,i,e){var s=t._drag,n=s._startPredicateData||s._setupStartPredicate(e);if(!i.isFinal)return!(!n.handleElement&&(n.handleElement=s._getStartPredicateHandle(i),!n.handleElement))&&(n.delay&&(n.event=i,n.delayTimer||(n.delayTimer=window.setTimeout(function(){n.delay=0,s._resolveStartPredicate(n.event)&&(s._forceResolveStartPredicate(n.event),s._resetStartPredicate())},n.delay))),s._resolveStartPredicate(i));s._finishStartPredicate(i)},U.defaultSortPredicate=function(){var t={},i={},e={},s=[];return function(n,r){var o=n._drag,h=o._getGrid(),a=r&&"number"==typeof r.threshold?r.threshold:50,_=r&&"swap"===r.action?"swap":"move";t.width=n._width,t.height=n._height,t.left=o._elementClientX,t.top=o._elementClientY;var l=function(e,n,r){var o,h,a,_,l=null,d=n._settings.dragSort,f=-1;if(!0===d?(s[0]=n,h=s):h=d.call(n,e),!Array.isArray(h))return l;for(_=0;_<h.length;_++)(a=h[_])._isDestroyed||(a._updateBoundingRect(),i.width=a._width,i.height=a._height,i.left=a._left,i.top=a._top,(o=$(t,i))>r&&o>f&&(f=o,l=a));return s.length=0,l}(n,h,a);if(!l)return!1;var d,f,u,c,p,m=0,g=0,y=-1;for(l===h?(t.left=o._gridX+n._marginLeft,t.top=o._gridY+n._marginTop):(l._updateBorders(1,0,1,0),m=l._left+l._borderLeft,g=l._top+l._borderTop),p=0;p<l._items.length;p++)(u=l._items[p])._isActive&&u!==n&&(f=!0,i.width=u._width,i.height=u._height,i.left=u._left+u._marginLeft+m,i.top=u._top+u._marginTop+g,(c=$(t,i))>y&&(d=p,y=c));return y<a&&n.getGrid()!==l&&(d=f?-1:0,y=1/0),y>=a&&(e.grid=l,e.index=d,e.action=_,e)}}(),U.prototype.stop=function(){var t=this._item._element,i=this._getGrid();return this._isActive?this._isMigrating?(this._finishMigration(),this):(this._cancelAsyncUpdates(),this._unbindScrollListeners(),this._checkOverlapDebounce("cancel"),t.parentNode!==i._element&&(i._element.appendChild(t),t.style[h]=k(this._gridX,this._gridY)),N(t,i._settings.itemDraggingClass),this._reset(),this):this},U.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(),this._hammer.destroy(),this._item._element.removeEventListener("dragstart",Z,!1),this._isDestroyed=!0,this)},U.prototype._getGrid=function(){return e[this._gridId]||null},U.prototype._reset=function(){this._isActive=!1,this._container=null,this._containingBlock=null,this._lastEvent=null,this._lastScrollEvent=null,this._scrollers=[],this._left=0,this._top=0,this._gridX=0,this._gridY=0,this._elementClientX=0,this._elementClientY=0,this._containerDiffX=0,this._containerDiffY=0},U.prototype._bindScrollListeners=function(){var t,i,e=this._getGrid()._element,s=this._container,n=this._scrollers;if(n.length=0,J(this._item._element,n),s!==e)for(J(e,t=[]),t.push(e),i=0;i<t.length;i++)n.indexOf(t[i])<0&&n.push(t[i]);for(i=0;i<n.length;i++)n[i].addEventListener("scroll",this._onScroll)},U.prototype._unbindScrollListeners=function(){var t,i=this._scrollers;for(t=0;t<i.length;t++)i[t].removeEventListener("scroll",this._onScroll);i.length=0},U.prototype._setupStartPredicate=function(t){var i=t||this._getGrid()._settings.dragStartPredicate||0;return this._startPredicateData={distance:Math.abs(i.distance)||0,delay:Math.max(i.delay,0)||0,handle:"string"==typeof i.handle&&i.handle}},U.prototype._getStartPredicateHandle=function(t){var i=this._startPredicateData,e=this._item._element,s=e;if(!i.handle)return s;for(s=(t.changedPointers[0]||0).target;s&&!y(s,i.handle);)s=s!==e?s.parentElement:null;return s||null},U.prototype._resolveStartPredicate=function(t){var i,e,s,n,r,o=this._startPredicateData,h=t.changedPointers[0],a=h&&h.pageX||0,_=h&&h.pageY||0;if(!(t.distance<o.distance||o.delay))return e=(i=o.handleElement.getBoundingClientRect()).left+(window.pageXOffset||0),s=i.top+(window.pageYOffset||0),n=i.width,r=i.height,this._resetStartPredicate(),n&&r&&a>=e&&a<e+n&&_>=s&&_<s+r},U.prototype._finishStartPredicate=function(t){var i=this._item._element;this._resetStartPredicate(),function(t){return Math.abs(t.deltaX)<2&&Math.abs(t.deltaY)<2&&t.deltaTime<200}(t)&&function(t){if("a"!==t.tagName.toLowerCase())return;var i=t.getAttribute("href");if(!i)return;var e=t.getAttribute("target");e&&"_self"!==e?window.open(i,e):window.location.href=i}(i)},U.prototype._resetStartPredicate=function(){var t=this._startPredicateData;t&&(t.delayTimer&&(t.delayTimer=window.clearTimeout(t.delayTimer)),this._startPredicateData=null)},U.prototype._checkOverlap=function(){if(this._isActive){var t,i,e,s,n,r,o,h=this._item,a=this._getGrid()._settings;(t="function"==typeof a.dragSortPredicate?a.dragSortPredicate(h,this._lastEvent):U.defaultSortPredicate(h,a.dragSortPredicate))&&"number"==typeof t.index&&(o=(i=h.getGrid())!==(s=t.grid||i),e=i._items.indexOf(h),n=w(s._items,t.index,o),r="swap"===t.action?"swap":"move",o?(i._hasListeners("beforeSend")&&i._emit("beforeSend",{item:h,fromGrid:i,fromIndex:e,toGrid:s,toIndex:n}),s._hasListeners("beforeReceive")&&s._emit("beforeReceive",{item:h,fromGrid:i,fromIndex:e,toGrid:s,toIndex:n}),h._gridId=s._id,this._isMigrating=h._gridId!==this._gridId,i._items.splice(e,1),X(s._items,h,n),h._sortData=null,i._hasListeners("send")&&i._emit("send",{item:h,fromGrid:i,fromIndex:e,toGrid:s,toIndex:n}),s._hasListeners("receive")&&s._emit("receive",{item:h,fromGrid:i,fromIndex:e,toGrid:s,toIndex:n}),i.layout(),s.layout()):e!==n&&(("swap"===r?b:D)(i._items,e,n),i._hasListeners("move")&&i._emit("move",{item:h,fromIndex:e,toIndex:n,action:r}),i.layout()))}},U.prototype._finishMigration=function(){var t,i,e=this._item,s=e._release,n=e._element,r=e._isActive,o=e.getGrid(),a=o._element,_=o._settings,l=_.dragContainer||a,f=this._getGrid()._settings,u=n.parentNode;this._isMigrating=!1,this.destroy(),N(n,f.itemClass),N(n,f.itemVisibleClass),N(n,f.itemHiddenClass),v(n,_.itemClass),v(n,r?_.itemVisibleClass:_.itemHiddenClass),l!==u&&(l.appendChild(n),i=G(u,l,!0),(t=P(n)).x-=i.left,t.y-=i.top),e._refreshDimensions(),e._refreshSortData(),i=G(l,a,!0),s._containerDiffX=i.left,s._containerDiffY=i.top,e._drag=_.dragEnabled?new U(e):null,l!==u&&(n.style[h]=k(t.x,t.y)),e._child.removeAttribute("style"),d(e._child,r?_.visibleStyles:_.hiddenStyles),s.start()},U.prototype._cancelAsyncUpdates=function(){var t=this._item._id;p.cancel(t+"move"),p.cancel(t+"scroll")},U.prototype._onStart=function(t){var i=this._item;if(i._isActive){var e,s=i._element,n=this._getGrid(),r=n._settings,o=i._release,a=i._migrate,_=n._element,l=r.dragContainer||_,d=R(l,!0),f=P(s),u=f.x,c=f.y,p=s.getBoundingClientRect(),m=l!==_;m&&(e=G(d,_)),i.isPositioning()&&i._layout.stop(!0,{transform:k(u,c)}),a._isActive&&(u-=a._containerDiffX,c-=a._containerDiffY,a.stop(!0,{transform:k(u,c)})),i.isReleasing()&&o._reset(),this._isActive=!0,this._lastEvent=t,this._container=l,this._containingBlock=d,this._elementClientX=p.left,this._elementClientY=p.top,this._left=this._gridX=u,this._top=this._gridY=c,n._emit("dragInit",i,t),m&&(this._containerDiffX=e.left,this._containerDiffY=e.top,s.parentNode===l?(this._gridX=u-this._containerDiffX,this._gridY=c-this._containerDiffY):(this._left=u+this._containerDiffX,this._top=c+this._containerDiffY,l.appendChild(s),s.style[h]=k(this._left,this._top))),v(s,r.itemDraggingClass),this._bindScrollListeners(),n._emit("dragStart",i,t)}},U.prototype._onMove=function(t){var i=this._item;if(i._isActive){var e=this._getGrid()._settings.dragAxis,s=t.deltaX-this._lastEvent.deltaX,n=t.deltaY-this._lastEvent.deltaY;this._lastEvent=t,"y"!==e&&(this._left+=s,this._gridX+=s,this._elementClientX+=s),"x"!==e&&(this._top+=n,this._gridY+=n,this._elementClientY+=n),p.add(i._id+"move",this._prepareMove,this._applyMove,!0)}else this.stop()},U.prototype._prepareMove=function(){this._item._isActive&&this._getGrid()._settings.dragSort&&this._checkOverlapDebounce()},U.prototype._applyMove=function(){var t=this._item;t._isActive&&(t._element.style[h]=k(this._left,this._top),this._getGrid()._emit("dragMove",t,this._lastEvent))},U.prototype._onScroll=function(t){var i=this._item;i._isActive?(this._lastScrollEvent=t,p.add(i._id+"scroll",this._prepareScroll,this._applyScroll,!0)):this.stop()},U.prototype._prepareScroll=function(){var t=this._item;if(t._isActive){var i,e=t._element,s=this._getGrid(),n=s._settings,r=n.dragAxis,o=s._element,h=e.getBoundingClientRect(),a=this._elementClientX-h.left,_=this._elementClientY-h.top;this._container!==o&&(i=G(this._containingBlock,o),this._containerDiffX=i.left,this._containerDiffY=i.top),"y"!==r&&(this._left+=a,this._gridX=this._left-this._containerDiffX),"x"!==r&&(this._top+=_,this._gridY=this._top-this._containerDiffY),n.dragSort&&this._checkOverlapDebounce()}},U.prototype._applyScroll=function(){var t=this._item;t._isActive&&(t._element.style[h]=k(this._left,this._top),this._getGrid()._emit("dragScroll",t,this._lastScrollEvent))},U.prototype._onEnd=function(t){var i=this._item,e=i._element,s=this._getGrid(),n=s._settings,r=i._release;i._isActive?(this._cancelAsyncUpdates(),n.dragSort&&this._checkOverlapDebounce("finish"),this._unbindScrollListeners(),r._containerDiffX=this._containerDiffX,r._containerDiffY=this._containerDiffY,this._reset(),N(e,n.itemDraggingClass),s._emit("dragEnd",i,t),this._isMigrating?this._finishMigration():r.start()):this.stop()},tt.prototype.add=function(t){return this._isDestroyed?this:(this._queue.push(t),this)},tt.prototype.flush=function(t,i){if(this._isDestroyed)return this;var e,s=this._queue,n=s.length;if(!n)return this;var r=1===n,o=r?s[0]:s.slice(0);if(s.length=0,r)return o(t,i),this;for(e=0;e<n&&(o[e](t,i),!this._isDestroyed);e++);return this},tt.prototype.destroy=function(){return this._isDestroyed?this:(this._isDestroyed=!0,this._queue.length=0,this)},it.prototype.start=function(t,i){if(!this._isDestroyed){var e,s,n,r=this._item,o=r._element,h=r._migrate,a=r._release,_=r.getGrid()._settings,l=this._isActive,f=a._isActive&&!1===a._isPositioningStarted,u=f?_.dragReleaseDuration:_.layoutDuration,c=f?_.dragReleaseEasing:_.layoutEasing,m=!t&&!this._skipNextAnimation&&u>0;return l&&this._queue.flush(!0,r),f&&(a._isPositioningStarted=!0),"function"==typeof i&&this._queue.add(i),e=a._isActive?a._containerDiffX:h._isActive?h._containerDiffX:0,s=a._isActive?a._containerDiffY:h._isActive?h._containerDiffY:0,this._targetStyles.transform=k(r._left+e,r._top+s),m?(this._isActive=!0,this._animateOptions.easing=c,this._animateOptions.duration=u,this._isInterrupted=l,this._offsetLeft=e,this._offsetTop=s,p.add(r._id,this._setupAnimation,this._startAnimation),this):(l&&p.cancel(r._id),n=r._animate.isAnimating(),this.stop(!1,this._targetStyles),!n&&d(o,this._targetStyles),this._skipNextAnimation=!1,this._finish())}},it.prototype.stop=function(t,i){if(this._isDestroyed||!this._isActive)return this;var e=this._item;return p.cancel(e._id),e._animate.stop(i),N(e._element,e.getGrid()._settings.itemPositioningClass),this._isActive=!1,t&&this._queue.flush(!0,e),this},it.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0,{}),this._queue.destroy(),this._item=this._currentStyles=this._targetStyles=this._animateOptions=null,this._isDestroyed=!0,this)},it.prototype._finish=function(){if(!this._isDestroyed){var t=this._item,i=t._migrate,e=t._release;this._isActive&&(this._isActive=!1,N(t._element,t.getGrid()._settings.itemPositioningClass)),e._isActive&&e.stop(),i._isActive&&i.stop(),this._queue.flush(!1,t)}},it.prototype._setupAnimation=function(){var t=P(this._item._element);this._currentLeft=t.x-this._offsetLeft,this._currentTop=t.y-this._offsetTop},it.prototype._startAnimation=function(){var t=this._item,i=t._element,e=t.getGrid()._settings;if(t._left===this._currentLeft&&t._top===this._currentTop)return this._isInterrupted&&this.stop(!1,this._targetStyles),this._isActive=!1,void this._finish();!this._isInterrupted&&v(i,e.itemPositioningClass),this._currentStyles.transform=k(this._currentLeft+this._offsetLeft,this._currentTop+this._offsetTop),t._animate.start(this._currentStyles,this._targetStyles,this._animateOptions)};var et={};function st(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._container=!1,this._containerDiffX=0,this._containerDiffY=0}st.prototype.start=function(t,i,e){if(this._isDestroyed)return this;var s,n,r,o,a,_,l,f,u=this._item,c=u._element,p=u.isVisible(),m=u.getGrid(),g=m._settings,y=t._settings,D=t._element,b=t._items,S=m._items.indexOf(u),A=e||document.body;if("number"==typeof i)s=w(b,i,!0);else{if(!(n=t._getItem(i)))return this;s=b.indexOf(n)}return(u.isPositioning()||this._isActive||u.isReleasing())&&(l=(_=P(c)).x,f=_.y),u.isPositioning()&&u._layout.stop(!0,{transform:k(l,f)}),this._isActive&&(l-=this._containerDiffX,f-=this._containerDiffY,this.stop(!0,{transform:k(l,f)})),u.isReleasing()&&(l-=u._release._containerDiffX,f-=u._release._containerDiffY,u._release.stop(!0,{transform:k(l,f)})),u._visibility._stopAnimation(),u._drag&&u._drag.destroy(),u._visibility._queue.flush(!0,u),m._hasListeners("beforeSend")&&m._emit("beforeSend",{item:u,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("beforeReceive")&&t._emit("beforeReceive",{item:u,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),N(c,g.itemClass),N(c,g.itemVisibleClass),N(c,g.itemHiddenClass),v(c,y.itemClass),v(c,p?y.itemVisibleClass:y.itemHiddenClass),m._items.splice(S,1),X(b,u,s),u._gridId=t._id,A!==(r=c.parentNode)&&(A.appendChild(c),o=G(A,r,!0),_||(l=(_=P(c)).x,f=_.y),c.style[h]=k(l+o.left,f+o.top)),u._child.removeAttribute("style"),d(u._child,p?y.visibleStyles:y.hiddenStyles),c.style.display=p?"block":"hidden",a=G(A,D,!0),u._refreshDimensions(),u._refreshSortData(),u._drag=y.dragEnabled?new U(u):null,this._isActive=!0,this._container=A,this._containerDiffX=a.left,this._containerDiffY=a.top,m._hasListeners("send")&&m._emit("send",{item:u,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("receive")&&t._emit("receive",{item:u,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),this},st.prototype.stop=function(t,i){if(this._isDestroyed||!this._isActive)return this;var e,s=this._item,n=s._element,r=s.getGrid()._element;return this._container!==r&&(i||(t?(e=P(n),et.transform=k(e.x-this._containerDiffX,e.y-this._containerDiffY)):et.transform=k(s._left,s._top),i=et),r.appendChild(n),d(n,i)),this._isActive=!1,this._container=null,this._containerDiffX=0,this._containerDiffY=0,this},st.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)};var nt={};function rt(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0}function ot(t){var i=t._isActive,e=t._element,s=t.getGrid()._settings;this._item=t,this._isDestroyed=!1,this._isHidden=!i,this._isHiding=!1,this._isShowing=!1,this._queue=new tt,this._finishShow=this._finishShow.bind(this),this._finishHide=this._finishHide.bind(this),e.style.display=i?"block":"none",v(e,i?s.itemVisibleClass:s.itemHiddenClass),d(t._child,i?s.visibleStyles:s.hiddenStyles)}rt.prototype.start=function(){if(this._isDestroyed||this._isActive)return this;var t=this._item,i=t.getGrid();return this._isActive=!0,v(t._element,i._settings.itemReleasingClass),i._emit("dragReleaseStart",t),t._layout.start(!1),this},rt.prototype.stop=function(t,i){if(this._isDestroyed||!this._isActive)return this;var e,s=this._item,n=s._element,r=s.getGrid(),o=r._element;return this._reset(),n.parentNode!==o&&(i||(t?(e=P(n),nt.transform=k(e.x-this._containerDiffX,e.y-this._containerDiffY)):nt.transform=k(s._left,s._top),i=nt),o.appendChild(n),d(n,i)),t||r._emit("dragReleaseEnd",s),this},rt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)},rt.prototype._reset=function(){if(!this._isDestroyed){var t=this._item;this._isActive=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0,N(t._element,t.getGrid()._settings.itemReleasingClass)}},ot.prototype.show=function(t,i){if(this._isDestroyed)return this;var e=this._item,s=e._element,n=this._queue,r="function"==typeof i?i:null,o=e.getGrid()._settings;return this._isShowing||this._isHidden?this._isShowing&&!t?(r&&n.add(r),this):(this._isShowing||(n.flush(!0,e),N(s,o.itemHiddenClass),v(s,o.itemVisibleClass),this._isHiding||(s.style.display="block")),r&&n.add(r),e._isActive=this._isShowing=!0,this._isHiding=this._isHidden=!1,this._startAnimation(!0,t,this._finishShow),this):(r&&r(!1,e),this)},ot.prototype.hide=function(t,i){if(this._isDestroyed)return this;var e=this._item,s=e._element,n=this._queue,r="function"==typeof i?i:null,o=e.getGrid()._settings;return!this._isHiding&&this._isHidden?(r&&r(!1,e),this):this._isHiding&&!t?(r&&n.add(r),this):(this._isHiding||(n.flush(!0,e),v(s,o.itemHiddenClass),N(s,o.itemVisibleClass)),r&&n.add(r),this._isHidden=this._isHiding=!0,e._isActive=this._isShowing=!1,this._startAnimation(!1,t,this._finishHide),this)},ot.prototype.destroy=function(){if(this._isDestroyed)return this;var t=this._item,i=t._element,e=t.getGrid(),s=this._queue,n=e._settings;return this._stopAnimation({}),s.flush(!0,t).destroy(),N(i,n.itemVisibleClass),N(i,n.itemHiddenClass),this._item=null,this._isHiding=this._isShowing=!1,this._isDestroyed=this._isHidden=!0,this},ot.prototype._startAnimation=function(t,i,e){if(!this._isDestroyed){var s,n=this._item,r=n.getGrid()._settings,o=t?r.visibleStyles:r.hiddenStyles,h=parseInt(t?r.showDuration:r.hideDuration)||0,a=(t?r.showEasing:r.hideEasing)||"ease",_=i||h<=0;if(o){if(p.cancel(n._id+"visibility"),_)return n._animateChild.isAnimating()?n._animateChild.stop(o):d(n._child,o),void(e&&e());p.add(n._id+"visibility",function(){s=l(n._child,o)},function(){n._animateChild.start(s,o,{duration:h,easing:a,onFinish:e})})}else e&&e()}},ot.prototype._stopAnimation=function(t){if(!this._isDestroyed){var i=this._item;p.cancel(i._id),i._animateChild.stop(t)}},ot.prototype._finishShow=function(){this._isHidden||(this._isShowing=!1,this._queue.flush(!1,this._item))};var ht={};ot.prototype._finishHide=function(){if(this._isHidden){var t=this._item;this._isHiding=!1,ht.transform=k(0,0),t._layout.stop(!0,ht),t._element.style.display="none",this._queue.flush(!1,t)}};var at,_t,lt,dt,ft=0;function ut(){return++ft}function ct(t,i,e){var s=t._settings;this._id=ut(),this._gridId=t._id,this._isDestroyed=!1,this._left=0,this._top=0,this._element=i,this._child=i.children[0],i.parentNode!==t._element&&t._element.appendChild(i),v(i,s.itemClass),"boolean"!=typeof e&&(e="none"!==_(i,"display")),this._isActive=e,i.style.left="0",i.style.top="0",i.style[h]=k(0,0),this._animate=new f(this,i),this._animateChild=new f(this,this._child),this._visibility=new ot(this),this._layout=new it(this),this._migrate=new st(this),this._release=new rt(this),this._drag=s.dragEnabled?new U(this):null,this._refreshDimensions(),this._refreshSortData()}function pt(){this._layout={slots:[],slotSizes:[],setWidth:!1,setHeight:!1,width:!1,height:!1},this._freeSlots=[],this._newSlots=[],this._rectItem={},this._rectStore=[],this._rectId=0,this._sortRectsLeftTop=this._sortRectsLeftTop.bind(this),this._sortRectsTopLeft=this._sortRectsTopLeft.bind(this)}ct.prototype.getGrid=function(){return e[this._gridId]},ct.prototype.getElement=function(){return this._element},ct.prototype.getWidth=function(){return this._width},ct.prototype.getHeight=function(){return this._height},ct.prototype.getMargin=function(){return{left:this._marginLeft,right:this._marginRight,top:this._marginTop,bottom:this._marginBottom}},ct.prototype.getPosition=function(){return{left:this._left,top:this._top}},ct.prototype.isActive=function(){return this._isActive},ct.prototype.isVisible=function(){return!!this._visibility&&!this._visibility._isHidden},ct.prototype.isShowing=function(){return!(!this._visibility||!this._visibility._isShowing)},ct.prototype.isHiding=function(){return!(!this._visibility||!this._visibility._isHiding)},ct.prototype.isPositioning=function(){return!(!this._layout||!this._layout._isActive)},ct.prototype.isDragging=function(){return!(!this._drag||!this._drag._isActive)},ct.prototype.isReleasing=function(){return!(!this._release||!this._release._isActive)},ct.prototype.isDestroyed=function(){return this._isDestroyed},ct.prototype._refreshDimensions=function(){if(!this._isDestroyed&&!this._visibility._isHidden){var t=this._element,i=t.getBoundingClientRect();this._width=i.width,this._height=i.height,this._marginLeft=Math.max(0,I(t,"margin-left")),this._marginRight=Math.max(0,I(t,"margin-right")),this._marginTop=Math.max(0,I(t,"margin-top")),this._marginBottom=Math.max(0,I(t,"margin-bottom"))}},ct.prototype._refreshSortData=function(){if(!this._isDestroyed){var t,i=this._sortData={},e=this.getGrid()._settings.sortData;for(t in e)i[t]=e[t](this,this._element)}},ct.prototype._destroy=function(t){if(!this._isDestroyed){var i=this._element,e=this.getGrid(),s=e._settings,n=e._items.indexOf(this);this._release.destroy(),this._migrate.destroy(),this._layout.destroy(),this._visibility.destroy(),this._animate.destroy(),this._animateChild.destroy(),this._drag&&this._drag.destroy(),i.removeAttribute("style"),this._child.removeAttribute("style"),N(i,s.itemClass),n>-1&&e._items.splice(n,1),t&&i.parentNode.removeChild(i),this._isActive=!1,this._isDestroyed=!0}},pt.prototype.getLayout=function(t,i,e,s){var n,r=this._layout,o=!(!s||!s.fillGaps),h=!(!s||!s.horizontal),a=!(!s||!s.alignRight),_=!(!s||!s.alignBottom),l=!(!s||!s.rounding);if(r.slots.length=r.slotSizes.length=0,r.width=h?0:l?Math.round(i):i,r.height=h?l?Math.round(e):e:0,r.setWidth=h,r.setHeight=!h,!t.length)return r;for(n=0;n<t.length;n++)this._addSlot(t[n],h,o,l);if(a)for(n=0;n<r.slots.length;n+=2)r.slots[n]=r.width-(r.slots[n]+r.slotSizes[n]);if(_)for(n=1;n<r.slots.length;n+=2)r.slots[n]=r.height-(r.slots[n]+r.slotSizes[n]);return this._freeSlots.length=0,this._newSlots.length=0,this._rectId=0,r},pt.prototype._addSlot=(at={},function(t,i,e,s){var n,r,o,h,a,_,l=this._layout,d=this._freeSlots,f=this._newSlots;for(f.length=0,at.left=null,at.top=null,at.width=t._width+t._marginLeft+t._marginRight,at.height=t._height+t._marginTop+t._marginBottom,s&&(at.width=Math.round(at.width),at.height=Math.round(at.height)),a=0;a<d.length;a++)if((r=d[a])&&(n=this._getRect(r),at.width<=n.width+.001&&at.height<=n.height+.001)){at.left=n.left,at.top=n.top;break}for(null===at.left&&(at.left=i?l.width:0,at.top=i?0:l.height,e||(h=!0)),!i&&at.top+at.height>l.height&&(at.left>0&&f.push(this._addRect(0,l.height,at.left,1/0)),at.left+at.width<l.width&&f.push(this._addRect(at.left+at.width,l.height,l.width-at.left-at.width,1/0)),l.height=at.top+at.height),i&&at.left+at.width>l.width&&(at.top>0&&f.push(this._addRect(l.width,0,1/0,at.top)),at.top+at.height<l.height&&f.push(this._addRect(l.width,at.top+at.height,1/0,l.height-at.top-at.height)),l.width=at.left+at.width),a=e?0:h?d.length:a;a<d.length;a++)if(r=d[a])for(n=this._getRect(r),o=this._splitRect(n,at),_=0;_<o.length;_++)r=o[_],(n=this._getRect(r)).width>.49&&n.height>.49&&(!i&&n.top<l.height||i&&n.left<l.width)&&f.push(r);f.length&&this._purgeRects(f).sort(i?this._sortRectsLeftTop:this._sortRectsTopLeft),i?l.width=Math.max(l.width,at.left+at.width):l.height=Math.max(l.height,at.top+at.height),l.slots.push(at.left,at.top),l.slotSizes.push(at.width,at.height),this._freeSlots=f,this._newSlots=d}),pt.prototype._addRect=function(t,i,e,s){var n=++this._rectId,r=this._rectStore;return r[n]=t||0,r[++this._rectId]=i||0,r[++this._rectId]=e||0,r[++this._rectId]=s||0,n},pt.prototype._getRect=function(t,i){var e=i||this._rectItem,s=this._rectStore;return e.left=s[t]||0,e.top=s[++t]||0,e.width=s[++t]||0,e.height=s[++t]||0,e},pt.prototype._splitRect=(_t=[],function(t,i){return _t.length=0,this._doRectsOverlap(t,i)?(t.left<i.left&&_t.push(this._addRect(t.left,t.top,i.left-t.left,t.height)),t.left+t.width>i.left+i.width&&_t.push(this._addRect(i.left+i.width,t.top,t.left+t.width-(i.left+i.width),t.height)),t.top<i.top&&_t.push(this._addRect(t.left,t.top,t.width,i.top-t.top)),t.top+t.height>i.top+i.height&&_t.push(this._addRect(t.left,i.top+i.height,t.width,t.top+t.height-(i.top+i.height))),_t):(_t.push(this._addRect(t.left,t.top,t.width,t.height)),_t)}),pt.prototype._doRectsOverlap=function(t,i){return!(t.left+t.width<=i.left||i.left+i.width<=t.left||t.top+t.height<=i.top||i.top+i.height<=t.top)},pt.prototype._isRectWithinRect=function(t,i){return t.left>=i.left&&t.top>=i.top&&t.left+t.width<=i.left+i.width&&t.top+t.height<=i.top+i.height},pt.prototype._purgeRects=(lt={},dt={},function(t){for(var i,e=t.length;e--;)if(i=t.length,t[e])for(this._getRect(t[e],lt);i--;)if(t[i]&&e!==i&&this._isRectWithinRect(lt,this._getRect(t[i],dt))){t[e]=0;break}return t}),pt.prototype._sortRectsTopLeft=function(){var t={},i={};return function(e,s){return this._getRect(e,t),this._getRect(s,i),t.top<i.top?-1:t.top>i.top?1:t.left<i.left?-1:t.left>i.left?1:0}}(),pt.prototype._sortRectsLeftTop=function(){var t={},i={};return function(e,s){return this._getRect(e,t),this._getRect(s,i),t.left<i.left?-1:t.left>i.left?1:t.top<i.top?-1:t.top>i.top?1:0}}();var mt="[object HTMLCollection]",gt="[object NodeList]";function yt(t){var i=Object.prototype.toString.call(t);return i===mt||i===gt}function vt(t){return yt(t)?Array.prototype.slice.call(t):Array.prototype.concat(t)}var wt=new pt,Dt=function(){};function bt(t,i){var s,r,o,h=this;if(t=this._element="string"==typeof t?document.querySelector(t):t,!document.body.contains(t))throw new Error("Container element must be an existing DOM element");"function"!=typeof(s=this._settings=function(t,i){var e=St({},t);i&&(e=St(e,i));return e.visibleStyles=(i||0).visibleStyles||(t||0).visibleStyles,e.hiddenStyles=(i||0).hiddenStyles||(t||0).hiddenStyles,e}(bt.defaultOptions,i)).dragSort&&(s.dragSort=!!s.dragSort),this._id=ut(),e[this._id]=h,this._isDestroyed=!1,this._layout={id:0,items:[],slots:[],setWidth:!1,setHeight:!1,width:0,height:0},this._emitter=new n,v(t,s.containerClass),this._items=[],"string"==typeof(r=s.items)?vt(t.children).forEach(function(t){("*"===r||y(t,r))&&h._items.push(new ct(h,t))}):(Array.isArray(r)||yt(r))&&(this._items=vt(r).map(function(t){return new ct(h,t)})),"number"!=typeof(o=s.layoutOnResize)&&(o=!0===o?0:-1),o>=0&&window.addEventListener("resize",h._resizeHandler=C(function(){h.refreshItems().layout()},o)),s.layoutOnInit&&this.layout(!0)}function St(t,i){var e,s,n,r=Object.keys(i),o=r.length;for(n=0;n<o;n++)e=B(i[s=r[n]]),B(t[s])&&e?t[s]=St(St({},t[s]),i[s]):e?t[s]=St({},i[s]):Array.isArray(i[s])?t[s]=i[s].slice(0):t[s]=i[s];return t}return bt.Item=ct,bt.ItemLayout=it,bt.ItemVisibility=ot,bt.ItemRelease=rt,bt.ItemMigrate=st,bt.ItemAnimate=f,bt.ItemDrag=U,bt.Emitter=n,bt.defaultOptions={items:"*",showDuration:300,showEasing:"ease",hideDuration:300,hideEasing:"ease",visibleStyles:{opacity:"1",transform:"scale(1)"},hiddenStyles:{opacity:"0",transform:"scale(0.5)"},layout:{fillGaps:!1,horizontal:!1,alignRight:!1,alignBottom:!1,rounding:!0},layoutOnResize:100,layoutOnInit:!0,layoutDuration:300,layoutEasing:"ease",sortData:null,dragEnabled:!1,dragContainer:null,dragStartPredicate:{distance:0,delay:0,handle:!1},dragAxis:null,dragSort:!0,dragSortInterval:100,dragSortPredicate:{threshold:50,action:"move"},dragReleaseDuration:300,dragReleaseEasing:"ease",dragHammerSettings:{touchAction:"none"},containerClass:"muuri",itemClass:"muuri-item",itemVisibleClass:"muuri-item-shown",itemHiddenClass:"muuri-item-hidden",itemPositioningClass:"muuri-item-positioning",itemDraggingClass:"muuri-item-dragging",itemReleasingClass:"muuri-item-releasing"},bt.prototype.on=function(t,i){return this._emitter.on(t,i),this},bt.prototype.once=function(t,i){return this._emitter.once(t,i),this},bt.prototype.off=function(t,i){return this._emitter.off(t,i),this},bt.prototype.getElement=function(){return this._element},bt.prototype.getItems=function(t){if(this._isDestroyed||!t&&0!==t)return this._items.slice(0);var i,e,s=[],n=vt(t);for(e=0;e<n.length;e++)(i=this._getItem(n[e]))&&s.push(i);return s},bt.prototype.refreshItems=function(t){if(this._isDestroyed)return this;var i,e=this.getItems(t);for(i=0;i<e.length;i++)e[i]._refreshDimensions();return this},bt.prototype.refreshSortData=function(t){if(this._isDestroyed)return this;var i,e=this.getItems(t);for(i=0;i<e.length;i++)e[i]._refreshSortData();return this},bt.prototype.synchronize=function(){if(this._isDestroyed)return this;var t,i,e,s=this._element,n=this._items;if(n.length){for(e=0;e<n.length;e++)(i=n[e]._element).parentNode===s&&(t=t||document.createDocumentFragment()).appendChild(i);t&&s.appendChild(t)}return this._emit("synchronize"),this},bt.prototype.layout=function(t,i){if(this._isDestroyed)return this;var e,n,r,o=this,h=this._element,a=this._updateLayout(),l=a.id,d=a.items.length,f=d,u="function"==typeof t?t:i,c="function"==typeof u,p=c?a.items.slice(0):null;function m(){if(!(--f>0)){var t=o._layout.id!==l;c&&u(t,p),!t&&o._hasListeners(s)&&o._emit(s,a.items.slice(0))}}if((a.setHeight&&"number"==typeof a.height||a.setWidth&&"number"==typeof a.width)&&(e="border-box"===_(h,"box-sizing")),a.setHeight&&("number"==typeof a.height?h.style.height=(e?a.height+this._borderTop+this._borderBottom:a.height)+"px":h.style.height=a.height),a.setWidth&&("number"==typeof a.width?h.style.width=(e?a.width+this._borderLeft+this._borderRight:a.width)+"px":h.style.width=a.width),this._hasListeners("layoutStart")&&this._emit("layoutStart",a.items.slice(0)),!d)return m(),this;for(r=0;r<d;r++)(n=a.items[r])&&(n._left=a.slots[2*r],n._top=a.slots[2*r+1],n.isDragging()?m():n._layout.start(!0===t,m));return this},bt.prototype.add=function(t,i){if(this._isDestroyed||!t)return[];var e=vt(t);if(!e.length)return e;var s,n,r=i||0,o=r.layout?r.layout:void 0===r.layout,h=this._items,a=!1;for(n=0;n<e.length;n++)s=new ct(this,e[n],r.isActive),e[n]=s,s._isActive&&(a=!0,s._layout._skipNextAnimation=!0);return X(h,e,r.index),this._hasListeners("add")&&this._emit("add",e.slice(0)),a&&o&&this.layout("instant"===o,"function"==typeof o?o:void 0),e},bt.prototype.remove=function(t,i){if(this._isDestroyed)return this;var e,s,n=i||0,r=n.layout?n.layout:void 0===n.layout,o=!1,h=this.getItems(),a=this.getItems(t),_=[];for(s=0;s<a.length;s++)e=a[s],_.push(h.indexOf(e)),e._isActive&&(o=!0),e._destroy(n.removeElements);return this._hasListeners("remove")&&this._emit("remove",a.slice(0),_),o&&r&&this.layout("instant"===r,"function"==typeof r?r:void 0),a},bt.prototype.show=function(t,i){return this._isDestroyed?this:(this._setItemsVisibility(t,!0,i),this)},bt.prototype.hide=function(t,i){return this._isDestroyed?this:(this._setItemsVisibility(t,!1,i),this)},bt.prototype.filter=function(t,i){if(this._isDestroyed||!this._items.length)return this;var e,s,n=[],r=[],o="string"==typeof t,h="function"==typeof t,a=i||0,_=!0===a.instant,l=a.layout?a.layout:void 0===a.layout,d="function"==typeof a.onFinish?a.onFinish:null,f=-1,u=Dt;if(d&&(u=function(){++f&&d(n.slice(0),r.slice(0))}),h||o)for(s=0;s<this._items.length;s++)e=this._items[s],(h?t(e):y(e._element,t))?n.push(e):r.push(e);return n.length?this.show(n,{instant:_,onFinish:u,layout:!1}):u(),r.length?this.hide(r,{instant:_,onFinish:u,layout:!1}):u(),(n.length||r.length)&&(this._hasListeners("filter")&&this._emit("filter",n.slice(0),r.slice(0)),l&&this.layout("instant"===l,"function"==typeof l?l:void 0)),this},bt.prototype.sort=function(){var t,e,s,n;function r(t){for(var i={},e=0;e<t.length;e++)i[t[e]._id]=e;return i}function o(t,i){var s=n[t._id],r=n[i._id];return e?r-s:s-r}function h(i,h){for(var a,_,l,d,f=0,u=0;u<t.length;u++)if(a=t[u][0],_=t[u][1],l=(i._sortData?i:i._refreshSortData())._sortData[a],d=(h._sortData?h:h._refreshSortData())._sortData[a],f="desc"===_||!_&&e?d<l?-1:d>l?1:0:l<d?-1:l>d?1:0)return f;return f||(n||(n=r(s)),f=o(i,h)),f}function a(i,h){var a=t(i,h);return e&&a&&(a=-a),a||(n||(n=r(s)),a=o(i,h)),a}return function(r,o){if(this._isDestroyed||this._items.length<2)return this;var _,l=this._items,d=o||0,f=d.layout?d.layout:void 0===d.layout;if(t=r,e=!!d.descending,s=l.slice(0),n=null,"function"==typeof t)l.sort(a);else if("string"==typeof t)t=r.trim().split(" ").map(function(t){return t.split(":")}),l.sort(h);else{if(!Array.isArray(t))return this;if(t.length!==l.length)throw new Error("["+i+"] sort reference items do not match with grid items.");for(_=0;_<l.length;_++){if(t.indexOf(l[_])<0)throw new Error("["+i+"] sort reference items do not match with grid items.");l[_]=t[_]}e&&l.reverse()}return this._hasListeners("sort")&&this._emit("sort",l.slice(0),s),f&&this.layout("instant"===f,"function"==typeof f?f:void 0),this}}(),bt.prototype.move=function(t,i,e){if(this._isDestroyed||this._items.length<2)return this;var s,n,r=this._items,o=e||0,h=o.layout?o.layout:void 0===o.layout,a="swap"===o.action,_=a?"swap":"move",l=this._getItem(t),d=this._getItem(i);return l&&d&&l!==d&&(s=r.indexOf(l),n=r.indexOf(d),a?b(r,s,n):D(r,s,n),this._hasListeners("move")&&this._emit("move",{item:l,fromIndex:s,toIndex:n,action:_}),h&&this.layout("instant"===h,"function"==typeof h?h:void 0)),this},bt.prototype.send=function(t,i,e,s){if(this._isDestroyed||i._isDestroyed||this===i)return this;if(!(t=this._getItem(t)))return this;var n=s||0,r=n.appendTo||document.body,o=n.layoutSender?n.layoutSender:void 0===n.layoutSender,h=n.layoutReceiver?n.layoutReceiver:void 0===n.layoutReceiver;return t._migrate.start(i,e,r),t._migrate._isActive&&t._isActive&&(o&&this.layout("instant"===o,"function"==typeof o?o:void 0),h&&i.layout("instant"===h,"function"==typeof h?h:void 0)),this},bt.prototype.destroy=function(t){if(this._isDestroyed)return this;var i,s=this._element,n=this._items.slice(0);for(this._resizeHandler&&window.removeEventListener("resize",this._resizeHandler),i=0;i<n.length;i++)n[i]._destroy(t);return N(s,this._settings.containerClass),s.style.height="",s.style.width="",this._emit("destroy"),this._emitter.destroy(),e[this._id]=void 0,this._isDestroyed=!0,this},bt.prototype._getItem=function(t){if(this._isDestroyed||!t&&0!==t)return null;if("number"==typeof t)return this._items[t>-1?t:this._items.length+t]||null;if(t instanceof ct)return t._gridId===this._id?t:null;for(var i=0;i<this._items.length;i++)if(this._items[i]._element===t)return this._items[i];return null},bt.prototype._updateLayout=function(){var t,i=this._layout,e=this._settings.layout;for(++i.id,i.items.length=0,t=0;t<this._items.length;t++)this._items[t]._isActive&&i.items.push(this._items[t]);this._refreshDimensions();var s=this._width-this._borderLeft-this._borderRight,n=this._height-this._borderTop-this._borderBottom,r="function"==typeof e?e(i.items.slice(0),s,n):wt.getLayout(i.items,s,n,e);return i.slots=r.slots.slice(0),i.setWidth=Boolean(r.setWidth),i.setHeight=Boolean(r.setHeight),i.width=r.width,i.height=r.height,i},bt.prototype._emit=function(){this._isDestroyed||this._emitter.emit.apply(this._emitter,arguments)},bt.prototype._hasListeners=function(t){var i=this._emitter._events[t];return!(!i||!i.length)},bt.prototype._updateBoundingRect=function(){var t=this._element.getBoundingClientRect();this._width=t.width,this._height=t.height,this._left=t.left,this._top=t.top},bt.prototype._updateBorders=function(t,i,e,s){var n=this._element;t&&(this._borderLeft=I(n,"border-left-width")),i&&(this._borderRight=I(n,"border-right-width")),e&&(this._borderTop=I(n,"border-top-width")),s&&(this._borderBottom=I(n,"border-bottom-width"))},bt.prototype._refreshDimensions=function(){this._updateBoundingRect(),this._updateBorders(1,1,1,1)},bt.prototype._setItemsVisibility=function(t,i,e){var s,n,r=this,o=this.getItems(t),h=e||0,a=!0===h.instant,_=h.onFinish,l=h.layout?h.layout:void 0===h.layout,d=o.length,f=i?"showStart":"hideStart",u=i?"showEnd":"hideEnd",c=i?"show":"hide",p=!1,m=[],g=[];if(d){for(this._hasListeners(f)&&this._emit(f,o.slice(0)),n=0;n<o.length;n++)s=o[n],(i&&!s._isActive||!i&&s._isActive)&&(p=!0),i&&!s._isActive&&(s._layout._skipNextAnimation=!0),i&&s._visibility._isHidden&&g.push(s),s._visibility[c](a,function(t,i){t||m.push(i),--d<1&&("function"==typeof _&&_(m.slice(0)),r._hasListeners(u)&&r._emit(u,m.slice(0)))});g.length&&this.refreshItems(g),p&&l&&this.layout("instant"===l,"function"==typeof l?l:void 0)}else"function"==typeof _&&_(o)},bt}); | ||
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i(require("hammerjs")):"function"==typeof define&&define.amd?define(["hammerjs"],i):t.Muuri=i(t.Hammer)}(this,function(t){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t;var i="Muuri",e={},s="layoutEnd";function n(){this._events={},this._queue=[],this._counter=0,this._isDestroyed=!1}n.prototype.on=function(t,i){if(this._isDestroyed)return this;var e=this._events[t];return e||(e=this._events[t]=[]),e.push(i),this},n.prototype.once=function(t,i){if(this._isDestroyed)return this;var e=function(){this.off(t,e),i.apply(null,arguments)}.bind(this);return this.on(t,e)},n.prototype.off=function(t,i){if(this._isDestroyed)return this;var e=this._events[t];if(!e||!e.length)return this;if(!i)return e.length=0,this;for(var s=e.length;s--;)i===e[s]&&e.splice(s,1);return this},n.prototype.emit=function(t,i,e,s){if(this._isDestroyed)return this;var n=this._events[t];if(!n||!n.length)return this;var r,o=this._queue,h=o.length,a=arguments.length-1;for(r=0;r<n.length;r++)o.push(n[r]);for(++this._counter,r=h,h=o.length;r<h;r++)if(0===a?o[r]():1===a?o[r](i):2===a?o[r](i,e):o[r](i,e,s),this._isDestroyed)return this;return--this._counter,this._counter||(o.length=0),this},n.prototype.destroy=function(){if(this._isDestroyed)return this;var t,i=this._events;for(t in this._isDestroyed=!0,this._queue.length=this._counter=0,i)i[t]&&(i[t].length=0,i[t]=void 0);return this};var r=!1,o="transform",h="transform";["","Webkit","Moz","O","ms"].forEach(function(t){if(!r){var i=t?t+"Transform":"transform";void 0!==document.documentElement.style[i]&&(t=t.toLowerCase(),o=t?"-"+t+"-transform":"transform",h=i,r=!0)}});var a="function"==typeof WeakMap?new WeakMap:null;function _(t,i){var e=a&&a.get(t);return e||(e=window.getComputedStyle(t,null),a&&a.set(t,e)),e.getPropertyValue("transform"===i?o:i)}var l=/([A-Z])/g;function d(t){return t.replace(l,"-$1").toLowerCase()}function f(t,i){for(var e in i)t.style["transform"===e?h:e]=i[e]}function u(t){this._element=t,this._animation=null,this._callback=null,this._props=[],this._values=[],this._keyframes=[],this._options={},this._isDestroyed=!1,this._onFinish=this._onFinish.bind(this)}u.prototype.start=function(t,i,e){if(!this._isDestroyed){var s=this._animation,n=this._props,r=this._values,o=e||0,h=!1;if(s){var a,_=0;for(var l in i)if(++_,-1===(a=n.indexOf(l))||i[l]!==r[a]){h=!0;break}h||_===n.length||(h=!0)}if(h&&s.cancel(),this._callback="function"==typeof o.onFinish?o.onFinish:null,!s||h){for(l in n.length=r.length=0,i)n.push(l),r.push(i[l]);var d=this._keyframes;d[0]=t,d[1]=i;var u=this._options;u.duration=o.duration||300,u.easing=o.easing||"ease";var c=this._element;(s=c.animate(d,u)).onfinish=this._onFinish,this._animation=s,f(c,i)}}},u.prototype.stop=function(t){if(!this._isDestroyed&&this._animation){var i,e,s,n=this._element,r=this._props,o=this._values;if(t)f(n,t);else for(s=0;s<r.length;s++)e=_(n,d(i=r[s])),n.style["transform"===i?h:i]=e;this._animation.cancel(),this._animation=this._callback=null,r.length=o.length=0}},u.prototype.isAnimating=function(){return!!this._animation},u.prototype.destroy=function(){this._isDestroyed||(this.stop(),this._element=this._options=this._keyframes=null,this._isDestroyed=!0)},u.prototype._onFinish=function(){var t=this._callback;this._animation=this._callback=null,this._props.length=this._values.length=0,t&&t()};var c=(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame||function(t){return window.setTimeout(t,16)}).bind(window);function p(){this._nextTick=null,this._queue=[],this._reads={},this._writes={},this._batch=[],this._batchReads={},this._batchWrites={},this._flush=this._flush.bind(this)}p.prototype.add=function(t,i,e,s){var n=this._queue.indexOf(t);n>-1&&(this._queue[n]=void 0),s?this._queue.unshift(t):this._queue.push(t),this._reads[t]=i,this._writes[t]=e,this._nextTick||(this._nextTick=c(this._flush))},p.prototype.cancel=function(t){var i=this._queue.indexOf(t);i>-1&&(this._queue[i]=void 0,this._reads[t]=void 0,this._writes[t]=void 0)},p.prototype._flush=function(){var t,i,e=this._queue,s=this._reads,n=this._writes,r=this._batch,o=this._batchReads,h=this._batchWrites,a=e.length;for(this._nextTick=null,i=0;i<a;i++)(t=e[i])&&(r.push(t),o[t]=s[t],s[t]=void 0,h[t]=n[t],n[t]=void 0);for(e.length=0,i=0;i<a;i++)o[t=r[i]]&&(o[t](),o[t]=void 0);for(i=0;i<a;i++)h[t=r[i]]&&(h[t](),h[t]=void 0);r.length=0,!this._nextTick&&e.length&&(this._nextTick=c(this._flush))};var m=new p,g="layout",y="visibility",v="move",w="scroll";function D(t){return m.cancel(t+g)}function b(t){return m.cancel(t+y)}function S(t){return m.cancel(t+v)}function A(t){return m.cancel(t+w)}var x=Element.prototype,R=x.matches||x.matchesSelector||x.webkitMatchesSelector||x.mozMatchesSelector||x.msMatchesSelector||x.oMatchesSelector;function C(t,i){return R.call(t,i)}var I="classList"in Element.prototype?function(t,i){t.classList.add(i)}:function(t,i){C(t,"."+i)||(t.className+=" "+i)};function L(t,i,e){var s=t.length,n=Math.max(0,e?s:s-1);return i>n?n:i<0?Math.max(n+i+1,0):i}function E(t,i,e){if(!(t.length<2)){var s=L(t,i),n=L(t,e);s!==n&&t.splice(n,0,t.splice(s,1)[0])}}function M(t,i,e){if(!(t.length<2)){var s,n=L(t,i),r=L(t,e);n!==r&&(s=t[n],t[n]=t[r],t[r]=s)}}var H="cancel",G="finish";function P(t,i){var e;return i>0?function(s){void 0!==e&&(e=window.clearTimeout(e),s===G&&t()),s!==H&&s!==G&&(e=window.setTimeout(function(){e=void 0,t()},i))}:function(i){i!==H&&t()}}function O(t){var i=_(t,"transform");if(!i||"none"===i)return!1;var e=_(t,"display");return"inline"!==e&&"none"!==e}function T(t,i){for(var e=(i?t:t.parentElement)||document;e&&e!==document&&"static"===_(e,"position")&&!O(e);)e=e.parentElement||document;return e}function k(t,i){return parseFloat(_(t,i))||0}var X={},Y={},q={};function B(t,i){var e,s=i||{};return s.left=0,s.top=0,t===document?s:(s.left=window.pageXOffset||0,s.top=window.pageYOffset||0,t.self===window.self?s:(e=t.getBoundingClientRect(),s.left+=e.left,s.top+=e.top,s.left+=k(t,"border-left-width"),s.top+=k(t,"border-top-width"),s))}function N(t,i,e){return q.left=0,q.top=0,t===i?q:e&&(t=T(t,!0))===(i=T(i,!0))?q:(B(t,X),B(i,Y),q.left=Y.left-X.left,q.top=Y.top-X.top,q)}var F={};function z(t){F.x=0,F.y=0;var i=_(t,"transform");if(!i)return F;var e=i.replace("matrix(","").split(",");return F.x=parseFloat(e[4])||0,F.y=parseFloat(e[5])||0,F}function V(t,i){return"translateX("+t+"px) translateY("+i+"px)"}var W=[];function j(t,i,e){var s="number"==typeof e?e:-1;s<0&&(s=t.length-s+1),t.splice.apply(t,W.concat(s,0,i)),W.length=0}var Z="[object Object]",$=Object.prototype.toString;function J(t){return"object"==typeof t&&$.call(t)===Z}var K="classList"in Element.prototype?function(t,i){t.classList.remove(i)}:function(t,i){C(t,"."+i)&&(t.className=(" "+t.className+" ").replace(" "+i+" "," ").trim())},Q=at(),U=0,tt=1,it=2,et=3;function st(e){if(!t)throw new Error("["+i+"] required dependency Hammer is not defined.");null===Q&&(Q=at());var s,n,r=this,o=e._element,h=e.getGrid(),a=h._settings,_="function"==typeof a.dragStartPredicate?a.dragStartPredicate:st.defaultStartPredicate,l=U;this._item=e,this._gridId=h._id,this._hammer=s=new t.Manager(o),this._isDestroyed=!1,this._isMigrating=!1,this._reset(),this._onScroll=this._onScroll.bind(this),this._prepareMove=this._prepareMove.bind(this),this._applyMove=this._applyMove.bind(this),this._prepareScroll=this._prepareScroll.bind(this),this._applyScroll=this._applyScroll.bind(this),this._checkOverlap=this._checkOverlap.bind(this),this._forceResolveStartPredicate=function(t){this._isDestroyed||l!==tt||(l=it,this._onStart(t))},this._checkOverlapDebounce=P(this._checkOverlap,a.dragSortInterval),s.add(new t.Pan({event:"drag",pointers:1,threshold:0,direction:t.DIRECTION_ALL})),s.add(new t.Press({event:"draginit",pointers:1,threshold:1e3,time:0})),J(a.dragHammerSettings)&&s.set(a.dragHammerSettings),s.on("draginit dragstart dragmove",function(t){l===U&&(l=tt),l===tt?!0===(n=_(r._item,t))?(l=it,r._onStart(t)):!1===n&&(l=et):l===it&&r._isActive&&r._onMove(t)}).on("dragend dragcancel draginitup",function(t){var i=l===it;_(r._item,t),l=U,i&&r._isActive&&r._onEnd(t)}),o.addEventListener("dragstart",nt,!1)}function nt(t){t.preventDefault&&t.preventDefault()}function rt(t,i){return t.left+t.width<=i.left||i.left+i.width<=t.left||t.top+t.height<=i.top||i.top+i.height<=t.top?0:(Math.min(t.left+t.width,i.left+i.width)-Math.max(t.left,i.left))*(Math.min(t.top+t.height,i.top+i.height)-Math.max(t.top,i.top))/(Math.min(t.width,i.width)*Math.min(t.height,i.height))*100}function ot(t,i){var e=i||[],s=t.parentNode;if(Q){if("fixed"===_(t,"position"))return e;for(;s&&s!==document&&s!==document.documentElement;)ht(s)&&e.push(s),s="fixed"===_(s,"position")?null:s.parentNode;return null!==s&&e.push(window),e}for(;s&&s!==document;)"fixed"!==_(t,"position")||O(s)?(ht(s)&&e.push(s),t=s,s=s.parentNode):s=s.parentNode;return e[e.length-1]===document.documentElement?e[e.length-1]=window:e.push(window),e}function ht(t){var i=_(t,"overflow");return"auto"===i||"scroll"===i||("auto"===(i=_(t,"overflow-x"))||"scroll"===i||("auto"===(i=_(t,"overflow-y"))||"scroll"===i))}function at(){if(!r)return!0;if(!document.body)return null;var t=[0,1].map(function(t,i){return(t=document.createElement("div")).style.position=i?"fixed":"absolute",t.style.display="block",t.style.visibility="hidden",t.style.left=i?"0px":"1px",t.style[h]="none",t}),i=document.body.appendChild(t[0]),e=i.appendChild(t[1]),s=e.getBoundingClientRect().left;i.style[h]="scale(1)";var n=s===e.getBoundingClientRect().left;return document.body.removeChild(i),n}function _t(){this._queue=[],this._isDestroyed=!1}function lt(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._isInterrupted=!1,this._currentStyles={},this._targetStyles={},this._currentLeft=0,this._currentTop=0,this._offsetLeft=0,this._offsetTop=0,this._skipNextAnimation=!1,this._animateOptions={onFinish:this._finish.bind(this)},this._queue=new _t,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this)}st.defaultStartPredicate=function(t,i,e){var s=t._drag,n=s._startPredicateData||s._setupStartPredicate(e);if(!i.isFinal)return!(!n.handleElement&&(n.handleElement=s._getStartPredicateHandle(i),!n.handleElement))&&(n.delay&&(n.event=i,n.delayTimer||(n.delayTimer=window.setTimeout(function(){n.delay=0,s._resolveStartPredicate(n.event)&&(s._forceResolveStartPredicate(n.event),s._resetStartPredicate())},n.delay))),s._resolveStartPredicate(i));s._finishStartPredicate(i)},st.defaultSortPredicate=function(){var t={},i={},e={},s=[];return function(n,r){var o=n._drag,h=o._getGrid(),a=r&&"number"==typeof r.threshold?r.threshold:50,_=r&&"swap"===r.action?"swap":"move";t.width=n._width,t.height=n._height,t.left=o._elementClientX,t.top=o._elementClientY;var l=function(e,n,r){var o,h,a,_,l=null,d=n._settings.dragSort,f=-1;if(!0===d?(s[0]=n,h=s):h=d.call(n,e),!Array.isArray(h))return l;for(_=0;_<h.length;_++)(a=h[_])._isDestroyed||(a._updateBoundingRect(),i.width=a._width,i.height=a._height,i.left=a._left,i.top=a._top,(o=rt(t,i))>r&&o>f&&(f=o,l=a));return s.length=0,l}(n,h,a);if(!l)return!1;var d,f,u,c,p,m=0,g=0,y=-1;for(l===h?(t.left=o._gridX+n._marginLeft,t.top=o._gridY+n._marginTop):(l._updateBorders(1,0,1,0),m=l._left+l._borderLeft,g=l._top+l._borderTop),p=0;p<l._items.length;p++)(u=l._items[p])._isActive&&u!==n&&(f=!0,i.width=u._width,i.height=u._height,i.left=u._left+u._marginLeft+m,i.top=u._top+u._marginTop+g,(c=rt(t,i))>y&&(d=p,y=c));return y<a&&n.getGrid()!==l&&(d=f?-1:0,y=1/0),y>=a&&(e.grid=l,e.index=d,e.action=_,e)}}(),st.prototype.stop=function(){var t=this._item,i=t._element,e=this._getGrid();return this._isActive?this._isMigrating?(this._finishMigration(),this):(S(t._id),A(t._id),this._unbindScrollListeners(),this._checkOverlapDebounce("cancel"),i.parentNode!==e._element&&(e._element.appendChild(i),i.style[h]=V(this._gridX,this._gridY)),K(i,e._settings.itemDraggingClass),this._reset(),this):this},st.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(),this._hammer.destroy(),this._item._element.removeEventListener("dragstart",nt,!1),this._isDestroyed=!0,this)},st.prototype._getGrid=function(){return e[this._gridId]||null},st.prototype._reset=function(){this._isActive=!1,this._container=null,this._containingBlock=null,this._lastEvent=null,this._lastScrollEvent=null,this._scrollers=[],this._left=0,this._top=0,this._gridX=0,this._gridY=0,this._elementClientX=0,this._elementClientY=0,this._containerDiffX=0,this._containerDiffY=0},st.prototype._bindScrollListeners=function(){var t,i,e=this._getGrid()._element,s=this._container,n=this._scrollers;if(n.length=0,ot(this._item._element,n),s!==e)for(ot(e,t=[]),t.push(e),i=0;i<t.length;i++)n.indexOf(t[i])<0&&n.push(t[i]);for(i=0;i<n.length;i++)n[i].addEventListener("scroll",this._onScroll)},st.prototype._unbindScrollListeners=function(){var t,i=this._scrollers;for(t=0;t<i.length;t++)i[t].removeEventListener("scroll",this._onScroll);i.length=0},st.prototype._setupStartPredicate=function(t){var i=t||this._getGrid()._settings.dragStartPredicate||0;return this._startPredicateData={distance:Math.abs(i.distance)||0,delay:Math.max(i.delay,0)||0,handle:"string"==typeof i.handle&&i.handle}},st.prototype._getStartPredicateHandle=function(t){var i=this._startPredicateData,e=this._item._element,s=e;if(!i.handle)return s;for(s=(t.changedPointers[0]||0).target;s&&!C(s,i.handle);)s=s!==e?s.parentElement:null;return s||null},st.prototype._resolveStartPredicate=function(t){var i,e,s,n,r,o=this._startPredicateData,h=t.changedPointers[0],a=h&&h.pageX||0,_=h&&h.pageY||0;if(!(t.distance<o.distance||o.delay))return e=(i=o.handleElement.getBoundingClientRect()).left+(window.pageXOffset||0),s=i.top+(window.pageYOffset||0),n=i.width,r=i.height,this._resetStartPredicate(),n&&r&&a>=e&&a<e+n&&_>=s&&_<s+r},st.prototype._finishStartPredicate=function(t){var i=this._item._element;this._resetStartPredicate(),function(t){return Math.abs(t.deltaX)<2&&Math.abs(t.deltaY)<2&&t.deltaTime<200}(t)&&function(t){if("a"!==t.tagName.toLowerCase())return;var i=t.getAttribute("href");if(!i)return;var e=t.getAttribute("target");e&&"_self"!==e?window.open(i,e):window.location.href=i}(i)},st.prototype._resetStartPredicate=function(){var t=this._startPredicateData;t&&(t.delayTimer&&(t.delayTimer=window.clearTimeout(t.delayTimer)),this._startPredicateData=null)},st.prototype._checkOverlap=function(){if(this._isActive){var t,i,e,s,n,r,o,h=this._item,a=this._getGrid()._settings;(t="function"==typeof a.dragSortPredicate?a.dragSortPredicate(h,this._lastEvent):st.defaultSortPredicate(h,a.dragSortPredicate))&&"number"==typeof t.index&&(o=(i=h.getGrid())!==(s=t.grid||i),e=i._items.indexOf(h),n=L(s._items,t.index,o),r="swap"===t.action?"swap":"move",o?(i._hasListeners("beforeSend")&&i._emit("beforeSend",{item:h,fromGrid:i,fromIndex:e,toGrid:s,toIndex:n}),s._hasListeners("beforeReceive")&&s._emit("beforeReceive",{item:h,fromGrid:i,fromIndex:e,toGrid:s,toIndex:n}),h._gridId=s._id,this._isMigrating=h._gridId!==this._gridId,i._items.splice(e,1),j(s._items,h,n),h._sortData=null,i._hasListeners("send")&&i._emit("send",{item:h,fromGrid:i,fromIndex:e,toGrid:s,toIndex:n}),s._hasListeners("receive")&&s._emit("receive",{item:h,fromGrid:i,fromIndex:e,toGrid:s,toIndex:n}),i.layout(),s.layout()):e!==n&&(("swap"===r?M:E)(i._items,e,n),i._hasListeners("move")&&i._emit("move",{item:h,fromIndex:e,toIndex:n,action:r}),i.layout()))}},st.prototype._finishMigration=function(){var t,i,e=this._item,s=e._release,n=e._element,r=e._isActive,o=e.getGrid(),a=o._element,_=o._settings,l=_.dragContainer||a,d=this._getGrid()._settings,u=n.parentNode;this._isMigrating=!1,this.destroy(),K(n,d.itemClass),K(n,d.itemVisibleClass),K(n,d.itemHiddenClass),I(n,_.itemClass),I(n,r?_.itemVisibleClass:_.itemHiddenClass),l!==u&&(l.appendChild(n),i=N(u,l,!0),(t=z(n)).x-=i.left,t.y-=i.top),e._refreshDimensions(),e._refreshSortData(),i=N(l,a,!0),s._containerDiffX=i.left,s._containerDiffY=i.top,e._drag=_.dragEnabled?new st(e):null,l!==u&&(n.style[h]=V(t.x,t.y)),e._child.removeAttribute("style"),f(e._child,r?_.visibleStyles:_.hiddenStyles),s.start()},st.prototype._onStart=function(t){var i=this._item;if(i._isActive){var e,s=i._element,n=this._getGrid(),r=n._settings,o=i._release,a=i._migrate,_=n._element,l=r.dragContainer||_,d=T(l,!0),f=z(s),u=f.x,c=f.y,p=s.getBoundingClientRect(),m=l!==_;m&&(e=N(d,_)),i.isPositioning()&&i._layout.stop(!0,{transform:V(u,c)}),a._isActive&&(u-=a._containerDiffX,c-=a._containerDiffY,a.stop(!0,{transform:V(u,c)})),i.isReleasing()&&o._reset(),this._isActive=!0,this._lastEvent=t,this._container=l,this._containingBlock=d,this._elementClientX=p.left,this._elementClientY=p.top,this._left=this._gridX=u,this._top=this._gridY=c,n._emit("dragInit",i,t),m&&(this._containerDiffX=e.left,this._containerDiffY=e.top,s.parentNode===l?(this._gridX=u-this._containerDiffX,this._gridY=c-this._containerDiffY):(this._left=u+this._containerDiffX,this._top=c+this._containerDiffY,l.appendChild(s),s.style[h]=V(this._left,this._top))),I(s,r.itemDraggingClass),this._bindScrollListeners(),n._emit("dragStart",i,t)}},st.prototype._onMove=function(t){var i=this._item;if(i._isActive){var e,s,n,r=this._getGrid()._settings.dragAxis,o=t.deltaX-this._lastEvent.deltaX,h=t.deltaY-this._lastEvent.deltaY;this._lastEvent=t,"y"!==r&&(this._left+=o,this._gridX+=o,this._elementClientX+=o),"x"!==r&&(this._top+=h,this._gridY+=h,this._elementClientY+=h),e=i._id,s=this._prepareMove,n=this._applyMove,m.add(e+v,s,n,!0)}else this.stop()},st.prototype._prepareMove=function(){this._item._isActive&&this._getGrid()._settings.dragSort&&this._checkOverlapDebounce()},st.prototype._applyMove=function(){var t=this._item;t._isActive&&(t._element.style[h]=V(this._left,this._top),this._getGrid()._emit("dragMove",t,this._lastEvent))},st.prototype._onScroll=function(t){var i,e,s,n=this._item;n._isActive?(this._lastScrollEvent=t,i=n._id,e=this._prepareScroll,s=this._applyScroll,m.add(i+w,e,s,!0)):this.stop()},st.prototype._prepareScroll=function(){var t=this._item;if(t._isActive){var i,e=t._element,s=this._getGrid(),n=s._settings,r=n.dragAxis,o=s._element,h=e.getBoundingClientRect(),a=this._elementClientX-h.left,_=this._elementClientY-h.top;this._container!==o&&(i=N(this._containingBlock,o),this._containerDiffX=i.left,this._containerDiffY=i.top),"y"!==r&&(this._left+=a,this._gridX=this._left-this._containerDiffX),"x"!==r&&(this._top+=_,this._gridY=this._top-this._containerDiffY),n.dragSort&&this._checkOverlapDebounce()}},st.prototype._applyScroll=function(){var t=this._item;t._isActive&&(t._element.style[h]=V(this._left,this._top),this._getGrid()._emit("dragScroll",t,this._lastScrollEvent))},st.prototype._onEnd=function(t){var i=this._item,e=i._element,s=this._getGrid(),n=s._settings,r=i._release;i._isActive?(S(i._id),A(i._id),n.dragSort&&this._checkOverlapDebounce("finish"),this._unbindScrollListeners(),r._containerDiffX=this._containerDiffX,r._containerDiffY=this._containerDiffY,this._reset(),K(e,n.itemDraggingClass),s._emit("dragEnd",i,t),this._isMigrating?this._finishMigration():r.start()):this.stop()},_t.prototype.add=function(t){return this._isDestroyed?this:(this._queue.push(t),this)},_t.prototype.flush=function(t,i){if(this._isDestroyed)return this;var e,s=this._queue,n=s.length;if(!n)return this;var r=1===n,o=r?s[0]:s.slice(0);if(s.length=0,r)return o(t,i),this;for(e=0;e<n&&(o[e](t,i),!this._isDestroyed);e++);return this},_t.prototype.destroy=function(){return this._isDestroyed?this:(this._isDestroyed=!0,this._queue.length=0,this)},lt.prototype.start=function(t,i){if(!this._isDestroyed){var e,s,n,r,o=this._item,h=o._element,a=o._release,_=o.getGrid()._settings,l=this._isActive,d=a._isActive&&!1===a._isPositioningStarted,u=d?_.dragReleaseDuration:_.layoutDuration,c=d?_.dragReleaseEasing:_.layoutEasing,p=!t&&!this._skipNextAnimation&&u>0;return l&&this._queue.flush(!0,o),d&&(a._isPositioningStarted=!0),"function"==typeof i&&this._queue.add(i),p?(this._isActive=!0,this._animateOptions.easing=c,this._animateOptions.duration=u,this._isInterrupted=l,s=o._id,n=this._setupAnimation,r=this._startAnimation,m.add(s+g,n,r),this):(this._updateOffsets(),this._updateTargetStyles(),l&&D(o._id),e=o._animate.isAnimating(),this.stop(!1,this._targetStyles),!e&&f(h,this._targetStyles),this._skipNextAnimation=!1,this._finish())}},lt.prototype.stop=function(t,i){if(this._isDestroyed||!this._isActive)return this;var e=this._item;return D(e._id),e._animate.stop(i),K(e._element,e.getGrid()._settings.itemPositioningClass),this._isActive=!1,t&&this._queue.flush(!0,e),this},lt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0,{}),this._queue.destroy(),this._item=this._currentStyles=this._targetStyles=this._animateOptions=null,this._isDestroyed=!0,this)},lt.prototype._updateOffsets=function(){if(!this._isDestroyed){var t=this._item,i=t._migrate,e=t._release;this._offsetLeft=e._isActive?e._containerDiffX:i._isActive?i._containerDiffX:0,this._offsetTop=e._isActive?e._containerDiffY:i._isActive?i._containerDiffY:0}},lt.prototype._updateTargetStyles=function(){if(!this._isDestroyed){var t=this._item;this._targetStyles.transform=V(t._left+this._offsetLeft,t._top+this._offsetTop)}},lt.prototype._finish=function(){if(!this._isDestroyed){var t=this._item,i=t._migrate,e=t._release;this._isActive&&(this._isActive=!1,K(t._element,t.getGrid()._settings.itemPositioningClass)),e._isActive&&e.stop(),i._isActive&&i.stop(),this._queue.flush(!1,t)}},lt.prototype._setupAnimation=function(){var t=z(this._item._element);this._currentLeft=t.x,this._currentTop=t.y},lt.prototype._startAnimation=function(){var t=this._item,i=t._element,e=t.getGrid()._settings;if(this._updateOffsets(),this._updateTargetStyles(),t._left===this._currentLeft-this._offsetLeft&&t._top===this._currentTop-this._offsetTop)return this._isInterrupted&&this.stop(!1,this._targetStyles),this._isActive=!1,void this._finish();!this._isInterrupted&&I(i,e.itemPositioningClass),this._currentStyles.transform=V(this._currentLeft,this._currentTop),t._animate.start(this._currentStyles,this._targetStyles,this._animateOptions)};var dt={};function ft(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._container=!1,this._containerDiffX=0,this._containerDiffY=0}ft.prototype.start=function(t,i,e){if(this._isDestroyed)return this;var s,n,r,o,a,_,l,d,u=this._item,c=u._element,p=u.isVisible(),m=u.getGrid(),g=m._settings,y=t._settings,v=t._element,w=t._items,D=m._items.indexOf(u),b=e||document.body;if("number"==typeof i)s=L(w,i,!0);else{if(!(n=t._getItem(i)))return this;s=w.indexOf(n)}return(u.isPositioning()||this._isActive||u.isReleasing())&&(l=(_=z(c)).x,d=_.y),u.isPositioning()&&u._layout.stop(!0,{transform:V(l,d)}),this._isActive&&(l-=this._containerDiffX,d-=this._containerDiffY,this.stop(!0,{transform:V(l,d)})),u.isReleasing()&&(l-=u._release._containerDiffX,d-=u._release._containerDiffY,u._release.stop(!0,{transform:V(l,d)})),u._visibility._stopAnimation(),u._drag&&u._drag.destroy(),u._visibility._queue.flush(!0,u),m._hasListeners("beforeSend")&&m._emit("beforeSend",{item:u,fromGrid:m,fromIndex:D,toGrid:t,toIndex:s}),t._hasListeners("beforeReceive")&&t._emit("beforeReceive",{item:u,fromGrid:m,fromIndex:D,toGrid:t,toIndex:s}),K(c,g.itemClass),K(c,g.itemVisibleClass),K(c,g.itemHiddenClass),I(c,y.itemClass),I(c,p?y.itemVisibleClass:y.itemHiddenClass),m._items.splice(D,1),j(w,u,s),u._gridId=t._id,b!==(r=c.parentNode)&&(b.appendChild(c),o=N(b,r,!0),_||(l=(_=z(c)).x,d=_.y),c.style[h]=V(l+o.left,d+o.top)),u._child.removeAttribute("style"),f(u._child,p?y.visibleStyles:y.hiddenStyles),c.style.display=p?"block":"hidden",a=N(b,v,!0),u._refreshDimensions(),u._refreshSortData(),u._drag=y.dragEnabled?new st(u):null,this._isActive=!0,this._container=b,this._containerDiffX=a.left,this._containerDiffY=a.top,m._hasListeners("send")&&m._emit("send",{item:u,fromGrid:m,fromIndex:D,toGrid:t,toIndex:s}),t._hasListeners("receive")&&t._emit("receive",{item:u,fromGrid:m,fromIndex:D,toGrid:t,toIndex:s}),this},ft.prototype.stop=function(t,i){if(this._isDestroyed||!this._isActive)return this;var e,s=this._item,n=s._element,r=s.getGrid()._element;return this._container!==r&&(i||(t?(e=z(n),dt.transform=V(e.x-this._containerDiffX,e.y-this._containerDiffY)):dt.transform=V(s._left,s._top),i=dt),r.appendChild(n),f(n,i)),this._isActive=!1,this._container=null,this._containerDiffX=0,this._containerDiffY=0,this},ft.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)};var ut={};function ct(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0}function pt(t){var i=t._isActive,e=t._element,s=t.getGrid()._settings;this._item=t,this._isDestroyed=!1,this._isHidden=!i,this._isHiding=!1,this._isShowing=!1,this._queue=new _t,this._finishShow=this._finishShow.bind(this),this._finishHide=this._finishHide.bind(this),e.style.display=i?"block":"none",I(e,i?s.itemVisibleClass:s.itemHiddenClass),f(t._child,i?s.visibleStyles:s.hiddenStyles)}ct.prototype.start=function(){if(this._isDestroyed||this._isActive)return this;var t=this._item,i=t.getGrid();return this._isActive=!0,I(t._element,i._settings.itemReleasingClass),i._emit("dragReleaseStart",t),t._layout.start(!1),this},ct.prototype.stop=function(t,i){if(this._isDestroyed||!this._isActive)return this;var e,s=this._item,n=s._element,r=s.getGrid(),o=r._element;return this._reset(),n.parentNode!==o&&(i||(t?(e=z(n),ut.transform=V(e.x-this._containerDiffX,e.y-this._containerDiffY)):ut.transform=V(s._left,s._top),i=ut),o.appendChild(n),f(n,i)),t||r._emit("dragReleaseEnd",s),this},ct.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)},ct.prototype._reset=function(){if(!this._isDestroyed){var t=this._item;this._isActive=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0,K(t._element,t.getGrid()._settings.itemReleasingClass)}},pt.prototype.show=function(t,i){if(this._isDestroyed)return this;var e=this._item,s=e._element,n=this._queue,r="function"==typeof i?i:null,o=e.getGrid()._settings;return this._isShowing||this._isHidden?this._isShowing&&!t?(r&&n.add(r),this):(this._isShowing||(n.flush(!0,e),K(s,o.itemHiddenClass),I(s,o.itemVisibleClass),this._isHiding||(s.style.display="block")),r&&n.add(r),e._isActive=this._isShowing=!0,this._isHiding=this._isHidden=!1,this._startAnimation(!0,t,this._finishShow),this):(r&&r(!1,e),this)},pt.prototype.hide=function(t,i){if(this._isDestroyed)return this;var e=this._item,s=e._element,n=this._queue,r="function"==typeof i?i:null,o=e.getGrid()._settings;return!this._isHiding&&this._isHidden?(r&&r(!1,e),this):this._isHiding&&!t?(r&&n.add(r),this):(this._isHiding||(n.flush(!0,e),I(s,o.itemHiddenClass),K(s,o.itemVisibleClass)),r&&n.add(r),this._isHidden=this._isHiding=!0,e._isActive=this._isShowing=!1,this._startAnimation(!1,t,this._finishHide),this)},pt.prototype.destroy=function(){if(this._isDestroyed)return this;var t=this._item,i=t._element,e=t.getGrid(),s=this._queue,n=e._settings;return this._stopAnimation({}),s.flush(!0,t).destroy(),K(i,n.itemVisibleClass),K(i,n.itemHiddenClass),this._item=null,this._isHiding=this._isShowing=!1,this._isDestroyed=this._isHidden=!0,this},pt.prototype._startAnimation=function(t,i,e){if(!this._isDestroyed){var s,n=this._item,r=n.getGrid()._settings,o=t?r.visibleStyles:r.hiddenStyles,h=parseInt(t?r.showDuration:r.hideDuration)||0,a=(t?r.showEasing:r.hideEasing)||"ease",l=i||h<=0;if(o){if(b(n._id),l)return n._animateChild.isAnimating()?n._animateChild.stop(o):f(n._child,o),void(e&&e());var u,c,p;u=n._id,c=function(){s=function(t,i){var e={};for(var s in i)e[s]=_(t,d(s));return e}(n._child,o)},p=function(){n._animateChild.start(s,o,{duration:h,easing:a,onFinish:e})},m.add(u+y,c,p)}else e&&e()}},pt.prototype._stopAnimation=function(t){if(!this._isDestroyed){var i=this._item;b(i._id),i._animateChild.stop(t)}},pt.prototype._finishShow=function(){this._isHidden||(this._isShowing=!1,this._queue.flush(!1,this._item))};var mt={};pt.prototype._finishHide=function(){if(this._isHidden){var t=this._item;this._isHiding=!1,mt.transform=V(0,0),t._layout.stop(!0,mt),t._element.style.display="none",this._queue.flush(!1,t)}};var gt,yt,vt,wt,Dt=0;function bt(){return++Dt}function St(t,i,e){var s=t._settings;this._id=bt(),this._gridId=t._id,this._isDestroyed=!1,this._left=0,this._top=0,this._element=i,this._child=i.children[0],i.parentNode!==t._element&&t._element.appendChild(i),I(i,s.itemClass),"boolean"!=typeof e&&(e="none"!==_(i,"display")),this._isActive=e,i.style.left="0",i.style.top="0",i.style[h]=V(0,0),this._animate=new u(i),this._animateChild=new u(this._child),this._visibility=new pt(this),this._layout=new lt(this),this._migrate=new ft(this),this._release=new ct(this),this._drag=s.dragEnabled?new st(this):null,this._refreshDimensions(),this._refreshSortData()}function At(){this._slots=[],this._slotSizes=[],this._freeSlots=[],this._newSlots=[],this._rectItem={},this._rectStore=[],this._rectId=0,this._layout={slots:null,setWidth:!1,setHeight:!1,width:!1,height:!1},this._sortRectsLeftTop=this._sortRectsLeftTop.bind(this),this._sortRectsTopLeft=this._sortRectsTopLeft.bind(this)}St.prototype.getGrid=function(){return e[this._gridId]},St.prototype.getElement=function(){return this._element},St.prototype.getWidth=function(){return this._width},St.prototype.getHeight=function(){return this._height},St.prototype.getMargin=function(){return{left:this._marginLeft,right:this._marginRight,top:this._marginTop,bottom:this._marginBottom}},St.prototype.getPosition=function(){return{left:this._left,top:this._top}},St.prototype.isActive=function(){return this._isActive},St.prototype.isVisible=function(){return!!this._visibility&&!this._visibility._isHidden},St.prototype.isShowing=function(){return!(!this._visibility||!this._visibility._isShowing)},St.prototype.isHiding=function(){return!(!this._visibility||!this._visibility._isHiding)},St.prototype.isPositioning=function(){return!(!this._layout||!this._layout._isActive)},St.prototype.isDragging=function(){return!(!this._drag||!this._drag._isActive)},St.prototype.isReleasing=function(){return!(!this._release||!this._release._isActive)},St.prototype.isDestroyed=function(){return this._isDestroyed},St.prototype._refreshDimensions=function(){if(!this._isDestroyed&&!this._visibility._isHidden){var t=this._element,i=t.getBoundingClientRect();this._width=i.width,this._height=i.height,this._marginLeft=Math.max(0,k(t,"margin-left")),this._marginRight=Math.max(0,k(t,"margin-right")),this._marginTop=Math.max(0,k(t,"margin-top")),this._marginBottom=Math.max(0,k(t,"margin-bottom"))}},St.prototype._refreshSortData=function(){if(!this._isDestroyed){var t,i=this._sortData={},e=this.getGrid()._settings.sortData;for(t in e)i[t]=e[t](this,this._element)}},St.prototype._destroy=function(t){if(!this._isDestroyed){var i=this._element,e=this.getGrid(),s=e._settings,n=e._items.indexOf(this);this._release.destroy(),this._migrate.destroy(),this._layout.destroy(),this._visibility.destroy(),this._animate.destroy(),this._animateChild.destroy(),this._drag&&this._drag.destroy(),i.removeAttribute("style"),this._child.removeAttribute("style"),K(i,s.itemClass),n>-1&&e._items.splice(n,1),t&&i.parentNode.removeChild(i),this._isActive=!1,this._isDestroyed=!0}},At.prototype.getLayout=function(t,i,e,s,n){var r,o=this._layout,h=!(!n||!n.fillGaps),a=!(!n||!n.horizontal),_=!(!n||!n.alignRight),l=!(!n||!n.alignBottom),d=!(!n||!n.rounding),f=this._slotSizes;if(o.slots=s||this._slots,o.width=a?0:d?Math.round(i):i,o.height=a?d?Math.round(e):e:0,o.setWidth=a,o.setHeight=!a,o.slots.length=0,f.length=0,!t.length)return o;for(r=0;r<t.length;r++)this._addSlot(t[r],a,h,d,_||l);if(_)for(r=0;r<o.slots.length;r+=2)o.slots[r]=o.width-(o.slots[r]+f[r]);if(l)for(r=1;r<o.slots.length;r+=2)o.slots[r]=o.height-(o.slots[r]+f[r]);return f.length=0,this._freeSlots.length=0,this._newSlots.length=0,this._rectId=0,o},At.prototype._addSlot=(gt={},function(t,i,e,s,n){var r,o,h,a,_,l,d=this._layout,f=this._freeSlots,u=this._newSlots;for(u.length=0,gt.left=null,gt.top=null,gt.width=t._width+t._marginLeft+t._marginRight,gt.height=t._height+t._marginTop+t._marginBottom,s&&(gt.width=Math.round(gt.width),gt.height=Math.round(gt.height)),_=0;_<f.length;_++)if((o=f[_])&&(r=this._getRect(o),gt.width<=r.width+.001&>.height<=r.height+.001)){gt.left=r.left,gt.top=r.top;break}for(null===gt.left&&(gt.left=i?d.width:0,gt.top=i?0:d.height,e||(a=!0)),!i&>.top+gt.height>d.height&&(gt.left>0&&u.push(this._addRect(0,d.height,gt.left,1/0)),gt.left+gt.width<d.width&&u.push(this._addRect(gt.left+gt.width,d.height,d.width-gt.left-gt.width,1/0)),d.height=gt.top+gt.height),i&>.left+gt.width>d.width&&(gt.top>0&&u.push(this._addRect(d.width,0,1/0,gt.top)),gt.top+gt.height<d.height&&u.push(this._addRect(d.width,gt.top+gt.height,1/0,d.height-gt.top-gt.height)),d.width=gt.left+gt.width),_=e?0:a?f.length:_;_<f.length;_++)if(o=f[_])for(r=this._getRect(o),h=this._splitRect(r,gt),l=0;l<h.length;l++)o=h[l],(r=this._getRect(o)).width>.49&&r.height>.49&&(!i&&r.top<d.height||i&&r.left<d.width)&&u.push(o);u.length&&this._purgeRects(u).sort(i?this._sortRectsLeftTop:this._sortRectsTopLeft),i?d.width=Math.max(d.width,gt.left+gt.width):d.height=Math.max(d.height,gt.top+gt.height),d.slots.push(gt.left,gt.top),n&&this._slotSizes.push(gt.width,gt.height),this._freeSlots=u,this._newSlots=f}),At.prototype._addRect=function(t,i,e,s){var n=++this._rectId,r=this._rectStore;return r[n]=t||0,r[++this._rectId]=i||0,r[++this._rectId]=e||0,r[++this._rectId]=s||0,n},At.prototype._getRect=function(t,i){var e=i||this._rectItem,s=this._rectStore;return e.left=s[t]||0,e.top=s[++t]||0,e.width=s[++t]||0,e.height=s[++t]||0,e},At.prototype._splitRect=(yt=[],function(t,i){return yt.length=0,this._doRectsOverlap(t,i)?(t.left<i.left&&yt.push(this._addRect(t.left,t.top,i.left-t.left,t.height)),t.left+t.width>i.left+i.width&&yt.push(this._addRect(i.left+i.width,t.top,t.left+t.width-(i.left+i.width),t.height)),t.top<i.top&&yt.push(this._addRect(t.left,t.top,t.width,i.top-t.top)),t.top+t.height>i.top+i.height&&yt.push(this._addRect(t.left,i.top+i.height,t.width,t.top+t.height-(i.top+i.height))),yt):(yt.push(this._addRect(t.left,t.top,t.width,t.height)),yt)}),At.prototype._doRectsOverlap=function(t,i){return!(t.left+t.width<=i.left||i.left+i.width<=t.left||t.top+t.height<=i.top||i.top+i.height<=t.top)},At.prototype._isRectWithinRect=function(t,i){return t.left>=i.left&&t.top>=i.top&&t.left+t.width<=i.left+i.width&&t.top+t.height<=i.top+i.height},At.prototype._purgeRects=(vt={},wt={},function(t){for(var i,e=t.length;e--;)if(i=t.length,t[e])for(this._getRect(t[e],vt);i--;)if(t[i]&&e!==i&&this._isRectWithinRect(vt,this._getRect(t[i],wt))){t[e]=0;break}return t}),At.prototype._sortRectsTopLeft=function(){var t={},i={};return function(e,s){return this._getRect(e,t),this._getRect(s,i),t.top<i.top?-1:t.top>i.top?1:t.left<i.left?-1:t.left>i.left?1:0}}(),At.prototype._sortRectsLeftTop=function(){var t={},i={};return function(e,s){return this._getRect(e,t),this._getRect(s,i),t.left<i.left?-1:t.left>i.left?1:t.top<i.top?-1:t.top>i.top?1:0}}();var xt="[object HTMLCollection]",Rt="[object NodeList]";function Ct(t){var i=Object.prototype.toString.call(t);return i===xt||i===Rt}function It(t){return Ct(t)?Array.prototype.slice.call(t):Array.prototype.concat(t)}var Lt=new At,Et=function(){};function Mt(t,i){var s,r,o,h=this;if(t=this._element="string"==typeof t?document.querySelector(t):t,!document.body.contains(t))throw new Error("Container element must be an existing DOM element");"function"!=typeof(s=this._settings=function(t,i){var e=Ht({},t);i&&(e=Ht(e,i));return e.visibleStyles=(i||0).visibleStyles||(t||0).visibleStyles,e.hiddenStyles=(i||0).hiddenStyles||(t||0).hiddenStyles,e}(Mt.defaultOptions,i)).dragSort&&(s.dragSort=!!s.dragSort),this._id=bt(),e[this._id]=h,this._isDestroyed=!1,this._layout={id:0,items:[],slots:[],setWidth:!1,setHeight:!1,width:0,height:0},this._emitter=new n,I(t,s.containerClass),this._items=[],"string"==typeof(r=s.items)?It(t.children).forEach(function(t){("*"===r||C(t,r))&&h._items.push(new St(h,t))}):(Array.isArray(r)||Ct(r))&&(this._items=It(r).map(function(t){return new St(h,t)})),"number"!=typeof(o=s.layoutOnResize)&&(o=!0===o?0:-1),o>=0&&window.addEventListener("resize",h._resizeHandler=P(function(){h.refreshItems().layout()},o)),s.layoutOnInit&&this.layout(!0)}function Ht(t,i){var e,s,n,r=Object.keys(i),o=r.length;for(n=0;n<o;n++)e=J(i[s=r[n]]),J(t[s])&&e?t[s]=Ht(Ht({},t[s]),i[s]):e?t[s]=Ht({},i[s]):Array.isArray(i[s])?t[s]=i[s].slice(0):t[s]=i[s];return t}return Mt.Item=St,Mt.ItemLayout=lt,Mt.ItemVisibility=pt,Mt.ItemRelease=ct,Mt.ItemMigrate=ft,Mt.ItemAnimate=u,Mt.ItemDrag=st,Mt.Emitter=n,Mt.defaultOptions={items:"*",showDuration:300,showEasing:"ease",hideDuration:300,hideEasing:"ease",visibleStyles:{opacity:"1",transform:"scale(1)"},hiddenStyles:{opacity:"0",transform:"scale(0.5)"},layout:{fillGaps:!1,horizontal:!1,alignRight:!1,alignBottom:!1,rounding:!0},layoutOnResize:100,layoutOnInit:!0,layoutDuration:300,layoutEasing:"ease",sortData:null,dragEnabled:!1,dragContainer:null,dragStartPredicate:{distance:0,delay:0,handle:!1},dragAxis:null,dragSort:!0,dragSortInterval:100,dragSortPredicate:{threshold:50,action:"move"},dragReleaseDuration:300,dragReleaseEasing:"ease",dragHammerSettings:{touchAction:"none"},containerClass:"muuri",itemClass:"muuri-item",itemVisibleClass:"muuri-item-shown",itemHiddenClass:"muuri-item-hidden",itemPositioningClass:"muuri-item-positioning",itemDraggingClass:"muuri-item-dragging",itemReleasingClass:"muuri-item-releasing"},Mt.prototype.on=function(t,i){return this._emitter.on(t,i),this},Mt.prototype.once=function(t,i){return this._emitter.once(t,i),this},Mt.prototype.off=function(t,i){return this._emitter.off(t,i),this},Mt.prototype.getElement=function(){return this._element},Mt.prototype.getItems=function(t){if(this._isDestroyed||!t&&0!==t)return this._items.slice(0);var i,e,s=[],n=It(t);for(e=0;e<n.length;e++)(i=this._getItem(n[e]))&&s.push(i);return s},Mt.prototype.refreshItems=function(t){if(this._isDestroyed)return this;var i,e=this.getItems(t);for(i=0;i<e.length;i++)e[i]._refreshDimensions();return this},Mt.prototype.refreshSortData=function(t){if(this._isDestroyed)return this;var i,e=this.getItems(t);for(i=0;i<e.length;i++)e[i]._refreshSortData();return this},Mt.prototype.synchronize=function(){if(this._isDestroyed)return this;var t,i,e,s=this._element,n=this._items;if(n.length){for(e=0;e<n.length;e++)(i=n[e]._element).parentNode===s&&(t=t||document.createDocumentFragment()).appendChild(i);t&&s.appendChild(t)}return this._emit("synchronize"),this},Mt.prototype.layout=function(t,i){if(this._isDestroyed)return this;var e,n,r,o=this,h=this._element,a=this._updateLayout(),l=a.id,d=a.items.length,f=d,u="function"==typeof t?t:i,c="function"==typeof u,p=c?a.items.slice(0):null;function m(){if(!(--f>0)){var t=o._layout.id!==l;c&&u(t,p),!t&&o._hasListeners(s)&&o._emit(s,a.items.slice(0))}}if((a.setHeight&&"number"==typeof a.height||a.setWidth&&"number"==typeof a.width)&&(e="border-box"===_(h,"box-sizing")),a.setHeight&&("number"==typeof a.height?h.style.height=(e?a.height+this._borderTop+this._borderBottom:a.height)+"px":h.style.height=a.height),a.setWidth&&("number"==typeof a.width?h.style.width=(e?a.width+this._borderLeft+this._borderRight:a.width)+"px":h.style.width=a.width),this._hasListeners("layoutStart")&&this._emit("layoutStart",a.items.slice(0)),!d)return m(),this;for(r=0;r<d;r++)(n=a.items[r])&&(n._left=a.slots[2*r],n._top=a.slots[2*r+1],n.isDragging()?m():n._layout.start(!0===t,m));return this},Mt.prototype.add=function(t,i){if(this._isDestroyed||!t)return[];var e=It(t);if(!e.length)return e;var s,n,r=i||0,o=r.layout?r.layout:void 0===r.layout,h=this._items,a=!1;for(n=0;n<e.length;n++)s=new St(this,e[n],r.isActive),e[n]=s,s._isActive&&(a=!0,s._layout._skipNextAnimation=!0);return j(h,e,r.index),this._hasListeners("add")&&this._emit("add",e.slice(0)),a&&o&&this.layout("instant"===o,"function"==typeof o?o:void 0),e},Mt.prototype.remove=function(t,i){if(this._isDestroyed)return this;var e,s,n=i||0,r=n.layout?n.layout:void 0===n.layout,o=!1,h=this.getItems(),a=this.getItems(t),_=[];for(s=0;s<a.length;s++)e=a[s],_.push(h.indexOf(e)),e._isActive&&(o=!0),e._destroy(n.removeElements);return this._hasListeners("remove")&&this._emit("remove",a.slice(0),_),o&&r&&this.layout("instant"===r,"function"==typeof r?r:void 0),a},Mt.prototype.show=function(t,i){return this._isDestroyed?this:(this._setItemsVisibility(t,!0,i),this)},Mt.prototype.hide=function(t,i){return this._isDestroyed?this:(this._setItemsVisibility(t,!1,i),this)},Mt.prototype.filter=function(t,i){if(this._isDestroyed||!this._items.length)return this;var e,s,n=[],r=[],o="string"==typeof t,h="function"==typeof t,a=i||0,_=!0===a.instant,l=a.layout?a.layout:void 0===a.layout,d="function"==typeof a.onFinish?a.onFinish:null,f=-1,u=Et;if(d&&(u=function(){++f&&d(n.slice(0),r.slice(0))}),h||o)for(s=0;s<this._items.length;s++)e=this._items[s],(h?t(e):C(e._element,t))?n.push(e):r.push(e);return n.length?this.show(n,{instant:_,onFinish:u,layout:!1}):u(),r.length?this.hide(r,{instant:_,onFinish:u,layout:!1}):u(),(n.length||r.length)&&(this._hasListeners("filter")&&this._emit("filter",n.slice(0),r.slice(0)),l&&this.layout("instant"===l,"function"==typeof l?l:void 0)),this},Mt.prototype.sort=function(){var t,e,s,n;function r(t){for(var i={},e=0;e<t.length;e++)i[t[e]._id]=e;return i}function o(t,i){var s=n[t._id],r=n[i._id];return e?r-s:s-r}function h(i,h){for(var a,_,l,d,f=0,u=0;u<t.length;u++)if(a=t[u][0],_=t[u][1],l=(i._sortData?i:i._refreshSortData())._sortData[a],d=(h._sortData?h:h._refreshSortData())._sortData[a],f="desc"===_||!_&&e?d<l?-1:d>l?1:0:l<d?-1:l>d?1:0)return f;return f||(n||(n=r(s)),f=o(i,h)),f}function a(i,h){var a=t(i,h);return e&&a&&(a=-a),a||(n||(n=r(s)),o(i,h))}return function(r,o){if(this._isDestroyed||this._items.length<2)return this;var _,l=this._items,d=o||0,f=d.layout?d.layout:void 0===d.layout;if(t=r,e=!!d.descending,s=l.slice(0),n=null,"function"==typeof t)l.sort(a);else if("string"==typeof t)t=r.trim().split(" ").map(function(t){return t.split(":")}),l.sort(h);else{if(!Array.isArray(t))return this;if(t.length!==l.length)throw new Error("["+i+"] sort reference items do not match with grid items.");for(_=0;_<l.length;_++){if(t.indexOf(l[_])<0)throw new Error("["+i+"] sort reference items do not match with grid items.");l[_]=t[_]}e&&l.reverse()}return this._hasListeners("sort")&&this._emit("sort",l.slice(0),s),f&&this.layout("instant"===f,"function"==typeof f?f:void 0),this}}(),Mt.prototype.move=function(t,i,e){if(this._isDestroyed||this._items.length<2)return this;var s,n,r=this._items,o=e||0,h=o.layout?o.layout:void 0===o.layout,a="swap"===o.action,_=a?"swap":"move",l=this._getItem(t),d=this._getItem(i);return l&&d&&l!==d&&(s=r.indexOf(l),n=r.indexOf(d),a?M(r,s,n):E(r,s,n),this._hasListeners("move")&&this._emit("move",{item:l,fromIndex:s,toIndex:n,action:_}),h&&this.layout("instant"===h,"function"==typeof h?h:void 0)),this},Mt.prototype.send=function(t,i,e,s){if(this._isDestroyed||i._isDestroyed||this===i)return this;if(!(t=this._getItem(t)))return this;var n=s||0,r=n.appendTo||document.body,o=n.layoutSender?n.layoutSender:void 0===n.layoutSender,h=n.layoutReceiver?n.layoutReceiver:void 0===n.layoutReceiver;return t._migrate.start(i,e,r),t._migrate._isActive&&t._isActive&&(o&&this.layout("instant"===o,"function"==typeof o?o:void 0),h&&i.layout("instant"===h,"function"==typeof h?h:void 0)),this},Mt.prototype.destroy=function(t){if(this._isDestroyed)return this;var i,s=this._element,n=this._items.slice(0);for(this._resizeHandler&&window.removeEventListener("resize",this._resizeHandler),i=0;i<n.length;i++)n[i]._destroy(t);return K(s,this._settings.containerClass),s.style.height="",s.style.width="",this._emit("destroy"),this._emitter.destroy(),e[this._id]=void 0,this._isDestroyed=!0,this},Mt.prototype._getItem=function(t){if(this._isDestroyed||!t&&0!==t)return null;if("number"==typeof t)return this._items[t>-1?t:this._items.length+t]||null;if(t instanceof St)return t._gridId===this._id?t:null;for(var i=0;i<this._items.length;i++)if(this._items[i]._element===t)return this._items[i];return null},Mt.prototype._updateLayout=function(){var t,i,e,s,n=this._layout,r=this._settings.layout;for(++n.id,n.items.length=0,s=0;s<this._items.length;s++)this._items[s]._isActive&&n.items.push(this._items[s]);return this._refreshDimensions(),t=this._width-this._borderLeft-this._borderRight,i=this._height-this._borderTop-this._borderBottom,e="function"==typeof r?r(n.items,t,i):Lt.getLayout(n.items,t,i,n.slots,r),n.slots=e.slots,n.setWidth=Boolean(e.setWidth),n.setHeight=Boolean(e.setHeight),n.width=e.width,n.height=e.height,n},Mt.prototype._emit=function(){this._isDestroyed||this._emitter.emit.apply(this._emitter,arguments)},Mt.prototype._hasListeners=function(t){var i=this._emitter._events[t];return!(!i||!i.length)},Mt.prototype._updateBoundingRect=function(){var t=this._element.getBoundingClientRect();this._width=t.width,this._height=t.height,this._left=t.left,this._top=t.top},Mt.prototype._updateBorders=function(t,i,e,s){var n=this._element;t&&(this._borderLeft=k(n,"border-left-width")),i&&(this._borderRight=k(n,"border-right-width")),e&&(this._borderTop=k(n,"border-top-width")),s&&(this._borderBottom=k(n,"border-bottom-width"))},Mt.prototype._refreshDimensions=function(){this._updateBoundingRect(),this._updateBorders(1,1,1,1)},Mt.prototype._setItemsVisibility=function(t,i,e){var s,n,r=this,o=this.getItems(t),h=e||0,a=!0===h.instant,_=h.onFinish,l=h.layout?h.layout:void 0===h.layout,d=o.length,f=i?"showStart":"hideStart",u=i?"showEnd":"hideEnd",c=i?"show":"hide",p=!1,m=[],g=[];if(d){for(this._hasListeners(f)&&this._emit(f,o.slice(0)),n=0;n<o.length;n++)s=o[n],(i&&!s._isActive||!i&&s._isActive)&&(p=!0),i&&!s._isActive&&(s._layout._skipNextAnimation=!0),i&&s._visibility._isHidden&&g.push(s),s._visibility[c](a,function(t,i){t||m.push(i),--d<1&&("function"==typeof _&&_(m.slice(0)),r._hasListeners(u)&&r._emit(u,m.slice(0)))});g.length&&this.refreshItems(g),p&&l&&this.layout("instant"===l,"function"==typeof l?l:void 0)}else"function"==typeof _&&_(o)},Mt}); |
{ | ||
"name": "muuri", | ||
"version": "0.6.3", | ||
"version": "0.7.0", | ||
"description": "Responsive, sortable, filterable and draggable grid layouts.", | ||
@@ -33,12 +33,13 @@ "keywords": [ | ||
"lint": "./node_modules/.bin/gulp lint", | ||
"format": "find ./src/**/*.js | xargs -I{} ./node_modules/.bin/prettier --write {}", | ||
"format-test": "find ./src/**/*.js | xargs -I{} ./node_modules/.bin/prettier --list-different {}", | ||
"size": "./node_modules/.bin/gulp size" | ||
"format": "./node_modules/.bin/prettier --write ./src/**/*.js", | ||
"format-test": "./node_modules/.bin/prettier --list-different ./src/**/*.js", | ||
"size": "./node_modules/.bin/gulp size", | ||
"pre-commit-hook": "./node_modules/.bin/gulp pre-commit" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "./node_modules/.bin/gulp pre-commit" | ||
"pre-commit": "npm run pre-commit-hook" | ||
} | ||
}, | ||
"dependencies": { | ||
"peerDependencies": { | ||
"hammerjs": "^2.0.0" | ||
@@ -49,6 +50,7 @@ }, | ||
"gulp": "^4.0.0", | ||
"gulp-eslint": "^4.0.2", | ||
"gulp-eslint": "^5.0.0", | ||
"gulp-size": "^3.0.0", | ||
"husky": "^1.0.0-rc.12", | ||
"karma": "^2.0.4", | ||
"hammerjs": "^2.0.8", | ||
"husky": "^1.0.0-rc.13", | ||
"karma": "^3.0.0", | ||
"karma-chrome-launcher": "^2.2.0", | ||
@@ -62,14 +64,14 @@ "karma-edge-launcher": "^0.4.2", | ||
"mezr": "^0.6.2", | ||
"prettier": "^1.13.7", | ||
"prettier": "^1.14.3", | ||
"prosthetic-hand": "^1.3.1", | ||
"qunit": "^2.6.1", | ||
"qunit": "^2.6.2", | ||
"rimraf": "^2.6.2", | ||
"rollup": "^0.62.0", | ||
"rollup-plugin-commonjs": "^9.1.3", | ||
"rollup-plugin-node-resolve": "^3.3.0", | ||
"rollup": "^0.66.1", | ||
"rollup-plugin-commonjs": "^9.1.8", | ||
"rollup-plugin-node-resolve": "^3.4.0", | ||
"rollup-plugin-strip-banner": "^0.2.0", | ||
"rollup-plugin-terser": "^1.0.1", | ||
"rollup-plugin-terser": "^3.0.0", | ||
"web-animations-js": "^2.3.1", | ||
"yargs": "^12.0.1" | ||
"yargs": "^12.0.2" | ||
} | ||
} |
@@ -54,5 +54,3 @@ import resolve from 'rollup-plugin-node-resolve'; | ||
output: { | ||
comments(node, comment) { | ||
return /@license/i.test(comment.value); | ||
} | ||
comments: 'some' | ||
} | ||
@@ -59,0 +57,0 @@ }) |
@@ -16,3 +16,3 @@ /** | ||
this._queue = []; | ||
this._processCount = 0; | ||
this._counter = 0; | ||
this._isDestroyed = false; | ||
@@ -113,3 +113,3 @@ } | ||
// Get event listeners and quite early if there's none. | ||
// Get event listeners and quit early if there's no listeners. | ||
var listeners = this._events[event]; | ||
@@ -119,5 +119,4 @@ if (!listeners || !listeners.length) return this; | ||
var queue = this._queue; | ||
var queueLength = queue.length; | ||
var argsLength = arguments.length - 1; | ||
var queueNewLength; | ||
var qLength = queue.length; | ||
var aLength = arguments.length - 1; | ||
var i; | ||
@@ -133,5 +132,2 @@ | ||
// Get queue's new length. | ||
queueNewLength = queue.length; | ||
// Increment queue counter. This is needed for the scenarios where emit is | ||
@@ -141,24 +137,21 @@ // triggered while the queue is already processing. We need to keep track of | ||
// the queue in the end when the last queue processor is finished. | ||
++this._processCount; | ||
++this._counter; | ||
// Process the queue (the specific part of it for this emit). | ||
for (i = queueLength; i < queueNewLength; i++) { | ||
for (i = qLength, qLength = queue.length; i < qLength; i++) { | ||
// prettier-ignore | ||
argsLength === 0 ? queue[i]() : | ||
argsLength === 1 ? queue[i](arg1) : | ||
argsLength === 2 ? queue[i](arg1, arg2) : | ||
queue[i](arg1, arg2, arg3); | ||
aLength === 0 ? queue[i]() : | ||
aLength === 1 ? queue[i](arg1) : | ||
aLength === 2 ? queue[i](arg1, arg2) : | ||
queue[i](arg1, arg2, arg3); | ||
// Let's always make sure after the callback that the emitter is still | ||
// alive (not destroyed). We want to stop processing asap when the emitter | ||
// is destroyed. | ||
// Stop processing if the emitter is destroyed. | ||
if (this._isDestroyed) return this; | ||
} | ||
// Decrement queue counter. | ||
--this._processCount; | ||
// Decrement queue process counter. | ||
--this._counter; | ||
// If there are no more queues processing and there were no new items were | ||
// added to the queue during processing let's reset the queue. | ||
if (!this._processCount && queueNewLength === queue.length) queue.length = 0; | ||
// Reset the queue if there are no more queue processes running. | ||
if (!this._counter) queue.length = 0; | ||
@@ -185,3 +178,3 @@ return this; | ||
// Reset queue (if queue is currently processing this will also stop that). | ||
this._queue.length = this._processCount = 0; | ||
this._queue.length = this._counter = 0; | ||
@@ -188,0 +181,0 @@ // Remove all listeners. |
@@ -897,9 +897,8 @@ /** | ||
if (isDescending && result) result = -result; | ||
// If values are equal let's compare the item indices to make sure we | ||
// have a stable sort. | ||
if (!result) { | ||
if (!indexMap) indexMap = getIndexMap(origItems); | ||
result = compareIndices(a, b); | ||
} | ||
return result; | ||
// If we have a valid result (not zero) let's return it right away. | ||
if (result) return result; | ||
// If result is zero let's compare the item indices to make sure we have a | ||
// stable sort. | ||
if (!indexMap) indexMap = getIndexMap(origItems); | ||
return compareIndices(a, b); | ||
} | ||
@@ -1177,2 +1176,5 @@ | ||
var settings = this._settings.layout; | ||
var width; | ||
var height; | ||
var newLayout; | ||
var i; | ||
@@ -1193,17 +1195,14 @@ | ||
// Calculate container width and height (without borders). | ||
var width = this._width - this._borderLeft - this._borderRight; | ||
var height = this._height - this._borderTop - this._borderBottom; | ||
width = this._width - this._borderLeft - this._borderRight; | ||
height = this._height - this._borderTop - this._borderBottom; | ||
// Calculate new layout. | ||
var newLayout = | ||
typeof settings === 'function' | ||
? settings(layout.items.slice(0), width, height) | ||
: packer.getLayout(layout.items, width, height, settings); | ||
if (typeof settings === 'function') { | ||
newLayout = settings(layout.items, width, height); | ||
} else { | ||
newLayout = packer.getLayout(layout.items, width, height, layout.slots, settings); | ||
} | ||
// Let's update the grid's layout. | ||
/** | ||
* @todo Instead of slicing create a slots array for each grid and provide | ||
* that to the `packer.getLayout` method, which in turn can populate it. | ||
*/ | ||
layout.slots = newLayout.slots.slice(0); | ||
layout.slots = newLayout.slots; | ||
layout.setWidth = Boolean(newLayout.setWidth); | ||
@@ -1210,0 +1209,0 @@ layout.setHeight = Boolean(newLayout.setHeight); |
@@ -76,4 +76,4 @@ /** | ||
// Initiate item's animation controllers. | ||
this._animate = new ItemAnimate(this, element); | ||
this._animateChild = new ItemAnimate(this, this._child); | ||
this._animate = new ItemAnimate(element); | ||
this._animateChild = new ItemAnimate(this._child); | ||
@@ -80,0 +80,0 @@ // Setup visibility handler. |
@@ -7,4 +7,6 @@ /** | ||
import getCurrentStyles from '../utils/getCurrentStyles.js'; | ||
import getStyle from '../utils/getStyle.js'; | ||
import getStyleName from '../utils/getStyleName.js'; | ||
import setStyles from '../utils/setStyles.js'; | ||
import { transformProp } from '../utils/supportedTransform.js'; | ||
@@ -15,11 +17,10 @@ /** | ||
* @class | ||
* @param {Item} item | ||
* @param {HTMLElement} element | ||
*/ | ||
function ItemAnimate(item, element) { | ||
this._item = item; | ||
function ItemAnimate(element) { | ||
this._element = element; | ||
this._animation = null; | ||
this._propsTo = null; | ||
this._callback = null; | ||
this._props = []; | ||
this._values = []; | ||
this._keyframes = []; | ||
@@ -52,17 +53,21 @@ this._options = {}; | ||
var animation = this._animation; | ||
var currentProps = this._props; | ||
var currentValues = this._values; | ||
var opts = options || 0; | ||
var callback = typeof opts.onFinish === 'function' ? opts.onFinish : null; | ||
var shouldStop = false; | ||
var propName; | ||
var cancelAnimation = false; | ||
// If we have an ongoing animation. | ||
if (this._animation) { | ||
// Check if we should stop the current animation. Here basically just test | ||
// that is the new animation animating to the same props with same values | ||
// as the current animation. Note that this is not currently checking the | ||
// scenario where the current animation has matching props and values to | ||
// the new animation and also has some extra props. | ||
for (propName in propsTo) { | ||
if (propsTo[propName] !== this._propsTo[propName]) { | ||
shouldStop = true; | ||
// If we have an existing animation running, let's check if it needs to be | ||
// cancelled or if it can continue running. | ||
if (animation) { | ||
var propCount = 0; | ||
var propIndex; | ||
// Check if the requested animation target props and values match with the | ||
// current props and values. | ||
for (var propName in propsTo) { | ||
++propCount; | ||
propIndex = currentProps.indexOf(propName); | ||
if (propIndex === -1 || propsTo[propName] !== currentValues[propIndex]) { | ||
cancelAnimation = true; | ||
break; | ||
@@ -72,34 +77,47 @@ } | ||
// Let's cancel the ongoing animation if needed. | ||
if (shouldStop) { | ||
this._animation.cancel(); | ||
// Check if the target props count matches current props count. This is | ||
// needed for the edge case scenario where target props contain the same | ||
// styles as current props, but the current props have some additional | ||
// props. | ||
if (!cancelAnimation && propCount !== currentProps.length) { | ||
cancelAnimation = true; | ||
} | ||
// Otherwise let's just change the callback and quit early. | ||
else { | ||
this._callback = callback; | ||
return; | ||
} | ||
} | ||
// Store callback. | ||
this._callback = callback; | ||
// Cancel animation (if required). | ||
if (cancelAnimation) animation.cancel(); | ||
// Store target props (copy to guard against mutation). | ||
this._propsTo = {}; | ||
// Store animation callback. | ||
this._callback = typeof opts.onFinish === 'function' ? opts.onFinish : null; | ||
// If we have a running animation that does not need to be cancelled, let's | ||
// call it a day here and let it run. | ||
if (animation && !cancelAnimation) return; | ||
// Store target props and values to instance. | ||
currentProps.length = currentValues.length = 0; | ||
for (propName in propsTo) { | ||
this._propsTo[propName] = propsTo[propName]; | ||
currentProps.push(propName); | ||
currentValues.push(propsTo[propName]); | ||
} | ||
// Start the animation. | ||
this._keyframes[0] = propsFrom; | ||
this._keyframes[1] = propsTo; | ||
this._options.duration = opts.duration || 300; | ||
this._options.easing = opts.easing || 'ease'; | ||
this._animation = this._element.animate(this._keyframes, this._options); | ||
// Set up keyframes. | ||
var animKeyframes = this._keyframes; | ||
animKeyframes[0] = propsFrom; | ||
animKeyframes[1] = propsTo; | ||
// Bind animation finish callback. | ||
this._animation.onfinish = this._onFinish; | ||
// Set up options. | ||
var animOptions = this._options; | ||
animOptions.duration = opts.duration || 300; | ||
animOptions.easing = opts.easing || 'ease'; | ||
// Set the end styles. | ||
setStyles(this._element, propsTo); | ||
// Start the animation | ||
var element = this._element; | ||
animation = element.animate(animKeyframes, animOptions); | ||
animation.onfinish = this._onFinish; | ||
this._animation = animation; | ||
// Set the end styles. This makes sure that the element stays at the end | ||
// values after animation is finished. | ||
setStyles(element, propsTo); | ||
}; | ||
@@ -112,9 +130,31 @@ | ||
* @memberof ItemAnimate.prototype | ||
* @param {Object} [currentStyles] | ||
* @param {Object} [styles] | ||
*/ | ||
ItemAnimate.prototype.stop = function(currentStyles) { | ||
ItemAnimate.prototype.stop = function(styles) { | ||
if (this._isDestroyed || !this._animation) return; | ||
setStyles(this._element, currentStyles || getCurrentStyles(this._element, this._propsTo)); | ||
var element = this._element; | ||
var currentProps = this._props; | ||
var currentValues = this._values; | ||
var propName; | ||
var propValue; | ||
var i; | ||
// Calculate (if not provided) and set styles. | ||
if (!styles) { | ||
for (i = 0; i < currentProps.length; i++) { | ||
propName = currentProps[i]; | ||
propValue = getStyle(element, getStyleName(propName)); | ||
element.style[propName === 'transform' ? transformProp : propName] = propValue; | ||
} | ||
} else { | ||
setStyles(element, styles); | ||
} | ||
// Cancel animation. | ||
this._animation.cancel(); | ||
this._animation = this._propsTo = this._callback = null; | ||
this._animation = this._callback = null; | ||
// Reset current props and values. | ||
currentProps.length = currentValues.length = 0; | ||
}; | ||
@@ -142,3 +182,3 @@ | ||
this.stop(); | ||
this._item = this._element = this._options = this._keyframes = null; | ||
this._element = this._options = this._keyframes = null; | ||
this._isDestroyed = true; | ||
@@ -160,3 +200,4 @@ }; | ||
var callback = this._callback; | ||
this._animation = this._propsTo = this._callback = null; | ||
this._animation = this._callback = null; | ||
this._props.length = this._values.length = 0; | ||
callback && callback(); | ||
@@ -163,0 +204,0 @@ }; |
@@ -23,4 +23,5 @@ /** | ||
} from '../shared.js'; | ||
import ticker from '../ticker.js'; | ||
import { addMoveTick, cancelMoveTick, addScrollTick, cancelScrollTick } from '../ticker.js'; | ||
import addClass from '../utils/addClass.js'; | ||
@@ -432,4 +433,5 @@ import arrayMove from '../utils/arrayMove.js'; | ||
// Cancel raf loop actions. | ||
this._cancelAsyncUpdates(); | ||
// Cancel queued move and scroll ticks. | ||
cancelMoveTick(item._id); | ||
cancelScrollTick(item._id); | ||
@@ -914,14 +916,2 @@ // Remove scroll listeners. | ||
/** | ||
* Cancel move/scroll event ticker action. | ||
* | ||
* @private | ||
* @memberof ItemDrag.prototype | ||
*/ | ||
ItemDrag.prototype._cancelAsyncUpdates = function() { | ||
var id = this._item._id; | ||
ticker.cancel(id + 'move'); | ||
ticker.cancel(id + 'scroll'); | ||
}; | ||
/** | ||
* Drag start handler. | ||
@@ -1061,3 +1051,3 @@ * | ||
// Do move prepare/apply handling in the next tick. | ||
ticker.add(item._id + 'move', this._prepareMove, this._applyMove, true); | ||
addMoveTick(item._id, this._prepareMove, this._applyMove); | ||
}; | ||
@@ -1118,3 +1108,3 @@ | ||
// Do scroll prepare/apply handling in the next tick. | ||
ticker.add(item._id + 'scroll', this._prepareScroll, this._applyScroll, true); | ||
addScrollTick(item._id, this._prepareScroll, this._applyScroll); | ||
}; | ||
@@ -1208,4 +1198,5 @@ | ||
// Cancel ticker actions. | ||
this._cancelAsyncUpdates(); | ||
// Cancel queued move and scroll ticks. | ||
cancelMoveTick(item._id); | ||
cancelScrollTick(item._id); | ||
@@ -1212,0 +1203,0 @@ // Finish currently queued overlap check. |
@@ -7,3 +7,3 @@ /** | ||
import ticker from '../ticker.js'; | ||
import { addLayoutTick, cancelLayoutTick } from '../ticker.js'; | ||
@@ -65,3 +65,2 @@ import Queue from '../Queue/Queue.js'; | ||
var element = item._element; | ||
var migrate = item._migrate; | ||
var release = item._release; | ||
@@ -76,4 +75,2 @@ var gridSettings = item.getGrid()._settings; | ||
var animEnabled = !instant && !this._skipNextAnimation && animDuration > 0; | ||
var offsetLeft; | ||
var offsetTop; | ||
var isAnimating; | ||
@@ -91,22 +88,7 @@ | ||
// Get item container's left offset. | ||
offsetLeft = release._isActive | ||
? release._containerDiffX | ||
: migrate._isActive | ||
? migrate._containerDiffX | ||
: 0; | ||
// Get item container's top offset. | ||
offsetTop = release._isActive | ||
? release._containerDiffY | ||
: migrate._isActive | ||
? migrate._containerDiffY | ||
: 0; | ||
// Get target styles. | ||
this._targetStyles.transform = getTranslateString(item._left + offsetLeft, item._top + offsetTop); | ||
// If no animations are needed, easy peasy! | ||
if (!animEnabled) { | ||
isPositioning && ticker.cancel(item._id); | ||
this._updateOffsets(); | ||
this._updateTargetStyles(); | ||
isPositioning && cancelLayoutTick(item._id); | ||
isAnimating = item._animate.isAnimating(); | ||
@@ -125,7 +107,5 @@ this.stop(false, this._targetStyles); | ||
this._isInterrupted = isPositioning; | ||
this._offsetLeft = offsetLeft; | ||
this._offsetTop = offsetTop; | ||
// Start the item's layout animation in the next tick. | ||
ticker.add(item._id, this._setupAnimation, this._startAnimation); | ||
addLayoutTick(item._id, this._setupAnimation, this._startAnimation); | ||
@@ -150,3 +130,3 @@ return this; | ||
// Cancel animation init. | ||
ticker.cancel(item._id); | ||
cancelLayoutTick(item._id); | ||
@@ -190,2 +170,45 @@ // Stop animation. | ||
/** | ||
* Calculate and update item's current layout offset data. | ||
* | ||
* @private | ||
* @memberof ItemLayout.prototype | ||
*/ | ||
ItemLayout.prototype._updateOffsets = function() { | ||
if (this._isDestroyed) return; | ||
var item = this._item; | ||
var migrate = item._migrate; | ||
var release = item._release; | ||
this._offsetLeft = release._isActive | ||
? release._containerDiffX | ||
: migrate._isActive | ||
? migrate._containerDiffX | ||
: 0; | ||
this._offsetTop = release._isActive | ||
? release._containerDiffY | ||
: migrate._isActive | ||
? migrate._containerDiffY | ||
: 0; | ||
}; | ||
/** | ||
* Calculate and update item's layout target styles. | ||
* | ||
* @private | ||
* @memberof ItemLayout.prototype | ||
*/ | ||
ItemLayout.prototype._updateTargetStyles = function() { | ||
if (this._isDestroyed) return; | ||
var item = this._item; | ||
this._targetStyles.transform = getTranslateString( | ||
item._left + this._offsetLeft, | ||
item._top + this._offsetTop | ||
); | ||
}; | ||
/** | ||
* Finish item layout procedure. | ||
@@ -226,4 +249,4 @@ * | ||
var translate = getTranslate(element); | ||
this._currentLeft = translate.x - this._offsetLeft; | ||
this._currentTop = translate.y - this._offsetTop; | ||
this._currentLeft = translate.x; | ||
this._currentTop = translate.y; | ||
}; | ||
@@ -243,5 +266,12 @@ | ||
// Let's update the offset data and target styles. | ||
this._updateOffsets(); | ||
this._updateTargetStyles(); | ||
// If the item is already in correct position let's quit early. | ||
if (item._left === this._currentLeft && item._top === this._currentTop) { | ||
this._isInterrupted && this.stop(false, this._targetStyles); | ||
if ( | ||
item._left === this._currentLeft - this._offsetLeft && | ||
item._top === this._currentTop - this._offsetTop | ||
) { | ||
if (this._isInterrupted) this.stop(false, this._targetStyles); | ||
this._isActive = false; | ||
@@ -256,6 +286,3 @@ this._finish(); | ||
// Get current styles for animation. | ||
this._currentStyles.transform = getTranslateString( | ||
this._currentLeft + this._offsetLeft, | ||
this._currentTop + this._offsetTop | ||
); | ||
this._currentStyles.transform = getTranslateString(this._currentLeft, this._currentTop); | ||
@@ -262,0 +289,0 @@ // Animate. |
@@ -7,3 +7,3 @@ /** | ||
import ticker from '../ticker.js'; | ||
import { addVisibilityTick, cancelVisibilityTick } from '../ticker.js'; | ||
@@ -233,4 +233,4 @@ import Queue from '../Queue/Queue.js'; | ||
// Let's reset item's visibility ticker. | ||
ticker.cancel(item._id + 'visibility'); | ||
// Cancel queued visibility tick. | ||
cancelVisibilityTick(item._id); | ||
@@ -248,5 +248,5 @@ // If we need to apply the styles instantly without animation. | ||
// Animate. | ||
ticker.add( | ||
item._id + 'visibility', | ||
// Start the animation in the next tick (to avoid layout thrashing). | ||
addVisibilityTick( | ||
item._id, | ||
function() { | ||
@@ -275,3 +275,3 @@ currentStyles = getCurrentStyles(item._child, targetStyles); | ||
var item = this._item; | ||
ticker.cancel(item._id); | ||
cancelVisibilityTick(item._id); | ||
item._animateChild.stop(targetStyles); | ||
@@ -278,0 +278,0 @@ }; |
@@ -16,5 +16,13 @@ /** | ||
function Packer() { | ||
this._slots = []; | ||
this._slotSizes = []; | ||
this._freeSlots = []; | ||
this._newSlots = []; | ||
this._rectItem = {}; | ||
this._rectStore = []; | ||
this._rectId = 0; | ||
// The layout return data, which will be populated in getLayout. | ||
this._layout = { | ||
slots: [], | ||
slotSizes: [], | ||
slots: null, | ||
setWidth: false, | ||
@@ -25,7 +33,2 @@ setHeight: false, | ||
}; | ||
this._freeSlots = []; | ||
this._newSlots = []; | ||
this._rectItem = {}; | ||
this._rectStore = []; | ||
this._rectId = 0; | ||
@@ -43,2 +46,3 @@ // Bind sort handlers. | ||
* @param {Number} height | ||
* @param {Number[]} [slots] | ||
* @param {Object} [options] | ||
@@ -51,3 +55,3 @@ * @param {Boolean} [options.fillGaps=false] | ||
*/ | ||
Packer.prototype.getLayout = function(items, width, height, options) { | ||
Packer.prototype.getLayout = function(items, width, height, slots, options) { | ||
var layout = this._layout; | ||
@@ -59,6 +63,7 @@ var fillGaps = !!(options && options.fillGaps); | ||
var rounding = !!(options && options.rounding); | ||
var slotSizes = this._slotSizes; | ||
var i; | ||
// Reset layout data. | ||
layout.slots.length = layout.slotSizes.length = 0; | ||
layout.slots = slots ? slots : this._slots; | ||
layout.width = isHorizontal ? 0 : rounding ? Math.round(width) : width; | ||
@@ -69,2 +74,6 @@ layout.height = !isHorizontal ? 0 : rounding ? Math.round(height) : height; | ||
// Make sure slots and slot size arrays are reset. | ||
layout.slots.length = 0; | ||
slotSizes.length = 0; | ||
// No need to go further if items do not exist. | ||
@@ -75,3 +84,3 @@ if (!items.length) return layout; | ||
for (i = 0; i < items.length; i++) { | ||
this._addSlot(items[i], isHorizontal, fillGaps, rounding); | ||
this._addSlot(items[i], isHorizontal, fillGaps, rounding, alignRight || alignBottom); | ||
} | ||
@@ -82,3 +91,3 @@ | ||
for (i = 0; i < layout.slots.length; i = i + 2) { | ||
layout.slots[i] = layout.width - (layout.slots[i] + layout.slotSizes[i]); | ||
layout.slots[i] = layout.width - (layout.slots[i] + slotSizes[i]); | ||
} | ||
@@ -90,3 +99,3 @@ } | ||
for (i = 1; i < layout.slots.length; i = i + 2) { | ||
layout.slots[i] = layout.height - (layout.slots[i] + layout.slotSizes[i]); | ||
layout.slots[i] = layout.height - (layout.slots[i] + slotSizes[i]); | ||
} | ||
@@ -96,2 +105,3 @@ } | ||
// Reset slots arrays and rect id. | ||
slotSizes.length = 0; | ||
this._freeSlots.length = 0; | ||
@@ -119,3 +129,3 @@ this._newSlots.length = 0; | ||
var itemSlot = {}; | ||
return function(item, isHorizontal, fillGaps, rounding) { | ||
return function(item, isHorizontal, fillGaps, rounding, trackSize) { | ||
var layout = this._layout; | ||
@@ -258,5 +268,5 @@ var freeSlots = this._freeSlots; | ||
// Add item slot data to layout slots (and store the slot size for later | ||
// usage too). | ||
// usage too if necessary). | ||
layout.slots.push(itemSlot.left, itemSlot.top); | ||
layout.slotSizes.push(itemSlot.width, itemSlot.height); | ||
if (trackSize) this._slotSizes.push(itemSlot.width, itemSlot.height); | ||
@@ -263,0 +273,0 @@ // Free/new slots switcheroo! |
@@ -9,2 +9,41 @@ /** | ||
export default new Ticker(); | ||
var ticker = new Ticker(); | ||
var layoutTick = 'layout'; | ||
var visibilityTick = 'visibility'; | ||
var moveTick = 'move'; | ||
var scrollTick = 'scroll'; | ||
export default ticker; | ||
export function addLayoutTick(itemId, readCallback, writeCallback) { | ||
return ticker.add(itemId + layoutTick, readCallback, writeCallback); | ||
} | ||
export function cancelLayoutTick(itemId) { | ||
return ticker.cancel(itemId + layoutTick); | ||
} | ||
export function addVisibilityTick(itemId, readCallback, writeCallback) { | ||
return ticker.add(itemId + visibilityTick, readCallback, writeCallback); | ||
} | ||
export function cancelVisibilityTick(itemId) { | ||
return ticker.cancel(itemId + visibilityTick); | ||
} | ||
export function addMoveTick(itemId, readCallback, writeCallback) { | ||
return ticker.add(itemId + moveTick, readCallback, writeCallback, true); | ||
} | ||
export function cancelMoveTick(itemId) { | ||
return ticker.cancel(itemId + moveTick); | ||
} | ||
export function addScrollTick(itemId, readCallback, writeCallback) { | ||
return ticker.add(itemId + scrollTick, readCallback, writeCallback, true); | ||
} | ||
export function cancelScrollTick(itemId) { | ||
return ticker.cancel(itemId + scrollTick); | ||
} |
@@ -7,2 +7,4 @@ /** | ||
var styleNameRegEx = /([A-Z])/g; | ||
/** | ||
@@ -15,3 +17,3 @@ * Transforms a camel case style property to kebab case style property. | ||
export default function getStyleName(string) { | ||
return string.replace(/([A-Z])/g, '-$1').toLowerCase(); | ||
return string.replace(styleNameRegEx, '-$1').toLowerCase(); | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
641334
14976
2108
26
- Removedhammerjs@^2.0.0