From a2ffdaf15863fb6920a20da4a0c68a097cadd973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20R=C3=A4m=C3=B6?= Date: Fri, 19 Jul 2019 21:25:07 +0300 Subject: [PATCH 001/120] Update comment. --- src/Dragger/Dragger.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Dragger/Dragger.js b/src/Dragger/Dragger.js index 4ecf5791..14942fa1 100644 --- a/src/Dragger/Dragger.js +++ b/src/Dragger/Dragger.js @@ -80,7 +80,7 @@ function Dragger(element, cssProps) { this.setTouchAction(taDefaultValue); } - // Prevent native link/image dragging for the item and it's ancestors. + // Prevent native link/image dragging for the item and it's children. element.addEventListener('dragstart', Dragger._preventDefault, false); // Listen to start event. From dc4b8e6ba692eb55755862475412d25a9a835eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20R=C3=A4m=C3=B6?= Date: Fri, 19 Jul 2019 23:18:31 +0300 Subject: [PATCH 002/120] Smarter dragSortPredicate. --- dist/muuri.js | 30 +++++++++++++++++++++--------- dist/muuri.min.js | 4 ++-- package.json | 2 +- src/Grid/Grid.js | 3 ++- src/Item/ItemDrag.js | 23 +++++++++++++++++------ 5 files changed, 43 insertions(+), 19 deletions(-) diff --git a/dist/muuri.js b/dist/muuri.js index f5d3066f..30d1b1b6 100644 --- a/dist/muuri.js +++ b/dist/muuri.js @@ -1,5 +1,5 @@ /** -* Muuri v0.8.0 +* Muuri v0.9.0 * https://github.com/haltu/muuri * Copyright (c) 2015-present, Haltu Oy * Released under the MIT license @@ -581,7 +581,7 @@ this.setTouchAction(taDefaultValue); } - // Prevent native link/image dragging for the item and it's ancestors. + // Prevent native link/image dragging for the item and it's children. element.addEventListener('dragstart', Dragger._preventDefault, false); // Listen to start event. @@ -1955,6 +1955,8 @@ // Get drag sort predicate settings. var sortThreshold = options && typeof options.threshold === 'number' ? options.threshold : 50; var sortAction = options && options.action === actionSwap ? actionSwap : actionMove; + var sortMigrateAction = + options && options.migrateAction === actionSwap ? actionSwap : actionMove; // Populate item rect data. itemRect.width = item._width; @@ -1969,6 +1971,7 @@ // dragged item enough. if (!grid) return false; + var isMigration = item.getGrid() !== grid; var gridOffsetLeft = 0; var gridOffsetTop = 0; var matchScore = -1; @@ -2018,18 +2021,25 @@ } } - // If there is no valid match and the item is being moved into another - // grid. - if (matchScore < sortThreshold && item.getGrid() !== grid) { - matchIndex = hasValidTargets ? -1 : 0; - matchScore = Infinity; + // If there is no valid match and the dragged item is being moved into + // another grid we need to do some guess work here. If there simply are no + // valid targets (which means that the dragged item will be the only active + // item in the new grid) we can just add it as the first item. If we have + // valid items in the new grid and the dragged item is overlapping one or + // more of the items in the new grid let's make an exception with the + // threshold and just pick the item which the dragged item is overlapping + // most. However, if the dragged item is not overlapping any of the valid + // items in the new grid let's position it as the last item in the grid. + if (matchScore < sortThreshold && isMigration) { + matchIndex = hasValidTargets ? (matchScore > 0 ? matchIndex : -1) : 0; + matchScore = sortThreshold; } // Check if the best match overlaps enough to justify a placement switch. if (matchScore >= sortThreshold) { returnData.grid = grid; returnData.index = matchIndex; - returnData.action = sortAction; + returnData.action = isMigration ? sortMigrateAction : sortAction; return returnData; } @@ -2486,6 +2496,7 @@ } // If the item was moved to another grid. + // TODO: Support "swap" action! else { this._hBlockedIndex = null; @@ -5629,7 +5640,8 @@ }, dragSortPredicate: { threshold: 50, - action: actionMove + action: actionMove, + migrateAction: actionMove }, dragReleaseDuration: 300, dragReleaseEasing: 'ease', diff --git a/dist/muuri.min.js b/dist/muuri.min.js index 4bd2fc7d..58ce5149 100644 --- a/dist/muuri.min.js +++ b/dist/muuri.min.js @@ -1,5 +1,5 @@ /** -* Muuri v0.8.0 +* Muuri v0.9.0 * https://github.com/haltu/muuri * Copyright (c) 2015-present, Haltu Oy * Released under the MIT license @@ -14,4 +14,4 @@ * Copyright (c) 2018-present, Niklas Rämö * @license MIT */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Muuri=e()}(this,function(){"use strict";var t={},e="layoutEnd";function i(){this._events={},this._queue=[],this._counter=0,this._isDestroyed=!1}i.prototype.on=function(t,e){if(this._isDestroyed)return this;var i=this._events[t];return i||(i=this._events[t]=[]),i.push(e),this},i.prototype.off=function(t,e){if(this._isDestroyed)return this;var i=this._events[t];if(!i||!i.length)return this;if(!e)return i.length=0,this;for(var s=i.length;s--;)e===i[s]&&i.splice(s,1);return this},i.prototype.emit=function(t,e,i,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-1||(M._activeInstances.push(t),M._emitter.on(D,t._onMove),M._emitter.on(A,t._onCancel),M._emitter.on(b,t._onEnd),1===M._activeInstances.length&&M._bindListeners())},M._deactivateInstance=function(t){var e=M._activeInstances.indexOf(t);-1!==e&&(M._activeInstances.splice(e,1),M._emitter.off(D,t._onMove),M._emitter.off(A,t._onCancel),M._emitter.off(b,t._onEnd),M._activeInstances.length||M._unbindListeners())},M._bindListeners=function(){var t=M._events;window.addEventListener(t.move,M._onMove,R),window.addEventListener(t.end,M._onEnd,R),t.cancel&&window.addEventListener(t.cancel,M._onCancel,R)},M._unbindListeners=function(){var t=M._events;window.removeEventListener(t.move,M._onMove,R),window.removeEventListener(t.end,M._onEnd,R),t.cancel&&window.removeEventListener(t.cancel,M._onCancel,R)},M._getEventPointerId=function(t){return"number"==typeof t.pointerId?t.pointerId:t.changedTouches?t.changedTouches[0]?t.changedTouches[0].identifier:null:1},M._getTouchById=function(t,e){if("number"==typeof t.pointerId)return t.pointerId===e?t:null;if(t.changedTouches){for(var i=0;i-1&&(this._queue[n]=void 0),s?this._queue.unshift(t):this._queue.push(t),this._reads[t]=e,this._writes[t]=i,this._nextStep||(this._nextStep=y(this._step))},T.prototype.cancel=function(t){var e=this._queue.indexOf(t);e>-1&&(this._queue[e]=void 0,delete this._reads[t],delete this._writes[t])},T.prototype._step=function(){var t,e,i=this._queue,s=this._reads,n=this._writes,r=this._batch,o=this._batchReads,h=this._batchWrites,a=i.length;for(this._nextStep=null,e=0;en?n:e<0?Math.max(n+e+1,0):e}function K(t,e,i){if(!(t.length<2)){var s=J(t,e),n=J(t,i);s!==n&&t.splice(n,0,t.splice(s,1)[0])}}function Q(t,e,i){if(!(t.length<2)){var s,n=J(t,e),r=J(t,i);n!==r&&(s=t[n],t[n]=t[r],t[r]=s)}}var tt="cancel",et="finish",it="debounce",st=0;function nt(t,e){var i,s=++st+it;return e>0?function(n){void 0!==i&&(i=window.clearTimeout(i),k.cancel(s),n===et&&t()),n!==tt&&n!==et&&(i=window.setTimeout(function(){i=void 0,k.add(s,t,null,!0)},e))}:function(e){e!==tt&&t()}}function rt(t){var e=a(t,"transform");if(!e||"none"===e)return!1;var i=a(t,"display");return"inline"!==i&&"none"!==i}function ot(t,e){for(var i=window.document,s=(e?t:t.parentElement)||i;s&&s!==i&&"static"===a(s,"position")&&!rt(s);)s=s.parentElement||i;return s}function ht(t,e){return parseFloat(a(t,e))||0}var at={},_t={},lt={};function dt(t,e){var i,s=e||{};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:(i=t.getBoundingClientRect(),s.left+=i.left,s.top+=i.top,s.left+=ht(t,"border-left-width"),s.top+=ht(t,"border-top-width"),s))}function ct(t,e,i){return lt.left=0,lt.top=0,t===e?lt:i&&(t=ot(t,!0))===(e=ot(e,!0))?lt:(dt(t,at),dt(e,_t),lt.left=_t.left-at.left,lt.top=_t.top-at.top,lt)}var ut="overflow",ft="overflow-x",pt="overflow-y",mt="auto",gt="scroll";function yt(t){var e=a(t,ut);return e===mt||e===gt||((e=a(t,ft))===mt||e===gt||((e=a(t,pt))===mt||e===gt))}function vt(t,e,i){for(var s=i||[],n=e?t:t.parentNode;n&&n!==document;)n.getRootNode&&n instanceof DocumentFragment?n=n.getRootNode().host:(yt(n)&&s.push(n),n=n.parentNode);return s.push(window),s}var wt={},St="transform",Dt="none",bt=/^matrix3d/,At=/([^,]*,){4}/,Et=/([^,]*,){12}/,Ct=/[^,]*,/;function Lt(t){wt.x=0,wt.y=0;var e=a(t,St);if(!e||e===Dt)return wt;var i=bt.test(e),s=e.replace(i?Et:At,""),n=s.replace(Ct,"");return wt.x=parseFloat(s)||0,wt.y=parseFloat(n)||0,wt}function It(t,e){return"translateX("+t+"px) translateY("+e+"px)"}function Rt(t,e){t.classList?t.classList.remove(e):W(t,"."+e)&&(t.className=(" "+t.className+" ").replace(" "+e+" "," ").trim())}var xt,Pt,Mt,Tt,kt=0;function Xt(t){var e=t._element,i=t.getGrid(),s=i._settings;this._item=t,this._gridId=i._id,this._isDestroyed=!1,this._isMigrating=!1,this._startPredicate=c(s.dragStartPredicate)?s.dragStartPredicate:Xt.defaultStartPredicate,this._startPredicateState=kt,this._startPredicateResult=void 0,this._hBlockedIndex=null,this._hX1=0,this._hX2=0,this._hY1=0,this._hY2=0,this._reset(),this._preStartCheck=this._preStartCheck.bind(this),this._preEndCheck=this._preEndCheck.bind(this),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);var n=s.dragSortHeuristics.sortInterval;this._checkOverlapDebounce=nt(this._checkOverlap,n),this._dragger=new M(e,s.dragCssProps),this._dragger.on("start",this._preStartCheck),this._dragger.on("move",this._preStartCheck),this._dragger.on("cancel",this._preEndCheck),this._dragger.on("end",this._preEndCheck)}function Yt(t,e){return t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top?0:(Math.min(t.left+t.width,e.left+e.width)-Math.max(t.left,e.left))*(Math.min(t.top+t.height,e.top+e.height)-Math.max(t.top,e.top))/(Math.min(t.width,e.width)*Math.min(t.height,e.height))*100}function Gt(t){this._item=t,this._animate=new p,this._element=null,this._className="",this._didMigrate=!1,this._resetAfterLayout=!1,this._currentLeft=0,this._currentTop=0,this._nextLeft=0,this._nextTop=0,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this),this._onLayoutStart=this._onLayoutStart.bind(this),this._onLayoutEnd=this._onLayoutEnd.bind(this),this._onReleaseEnd=this._onReleaseEnd.bind(this),this._onMigrate=this._onMigrate.bind(this)}function Ht(){this._queue=[],this._isDestroyed=!1}function Ot(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 Ht,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this)}Xt.defaultStartPredicate=function(t,e,i){var s=t._drag,n=s._startPredicateData||s._setupStartPredicate(i);if(!e.isFinal)return!(!n.handleElement&&(n.handleElement=s._getStartPredicateHandle(e),!n.handleElement))&&(n.delay&&(n.event=e,n.delayTimer||(n.delayTimer=window.setTimeout(function(){n.delay=0,s._resolveStartPredicate(n.event)&&(s._forceResolveStartPredicate(n.event),s._resetStartPredicate())},n.delay))),s._resolveStartPredicate(e));s._finishStartPredicate(e)},Xt.defaultSortPredicate=(xt={},Pt={},Mt={},Tt=[],function(t,e){var i=t._drag,s=i._getGrid(),n=e&&"number"==typeof e.threshold?e.threshold:50,r=e&&"swap"===e.action?"swap":"move";xt.width=t._width,xt.height=t._height,xt.left=i._elementClientX,xt.top=i._elementClientY;var o=function(t,e,i){var s,n,r,o,h=null,a=e._settings.dragSort,_=-1;if(!0===a?(Tt[0]=e,n=Tt):n=a.call(e,t),!Array.isArray(n))return h;for(o=0;oi&&s>_&&(_=s,h=r));return Tt.length=0,h}(t,s,n);if(!o)return!1;var h,a,_,l,d,c=0,u=0,f=-1;for(o===s?(xt.left=i._gridX+t._marginLeft,xt.top=i._gridY+t._marginTop):(o._updateBorders(1,0,1,0),c=o._left+o._borderLeft,u=o._top+o._borderTop),d=0;df&&(h=d,f=l));return f=n&&(Mt.grid=o,Mt.index=h,Mt.action=r,Mt)}),Xt.prototype.stop=function(){var t=this._item,e=t._element,i=this._getGrid();return this._isActive?this._isMigrating?(this._finishMigration(),this):(N(t._id),q(t._id),this._unbindScrollListeners(),this._checkOverlapDebounce("cancel"),e.parentNode!==i._element&&(i._element.appendChild(e),e.style[n]=It(this._gridX,this._gridY)),Rt(e,i._settings.itemDraggingClass),this._reset(),this):this},Xt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(),this._dragger.destroy(),this._isDestroyed=!0,this)},Xt.prototype._getGrid=function(){return t[this._gridId]||null},Xt.prototype._reset=function(){this._isActive=!1,this._container=null,this._containingBlock=null,this._dragEvent=null,this._scrollEvent=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},Xt.prototype._bindScrollListeners=function(){var t,e,i=this._getGrid()._element,s=this._container,n=this._scrollers;if(n.length=0,vt(this._item._element,!1,n),s!==i)for(vt(i,!0,t=[]),e=0;e=s&&t.pageX=n&&t.pageY3&&e.minBounceBackAngle>0;if(h||(this._hBlockedIndex=null),Math.abs(r)>i||Math.abs(o)>i){if(h){var a=Math.atan2(r,o),_=Math.atan2(this._hX2-this._hX1,this._hY2-this._hY1),l=Math.atan2(Math.sin(a-_),Math.cos(a-_));Math.abs(l)>e.minBounceBackAngle&&(this._hBlockedIndex=null)}return this._hX1=this._hX2,this._hY1=this._hY2,this._hX2=s,this._hY2=n,!0}return!1},Xt.prototype._resetStartPredicate=function(){var t=this._startPredicateData;t&&(t.delayTimer&&(t.delayTimer=window.clearTimeout(t.delayTimer)),this._startPredicateData=null)},Xt.prototype._checkOverlap=function(){if(this._isActive){var t,e,i,s,n,r,o,h=this._item,a=this._getGrid()._settings;(t=c(a.dragSortPredicate)?a.dragSortPredicate(h,this._dragEvent):Xt.defaultSortPredicate(h,a.dragSortPredicate))&&"number"==typeof t.index&&(o=(e=h.getGrid())!==(s=t.grid||e),i=e._items.indexOf(h),n=J(s._items,t.index,o),r="swap"===t.action?"swap":"move",(o||n!==this._hBlockedIndex)&&(o?(this._hBlockedIndex=null,e._hasListeners("beforeSend")&&e._emit("beforeSend",{item:h,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("beforeReceive")&&s._emit("beforeReceive",{item:h,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),h._gridId=s._id,this._isMigrating=h._gridId!==this._gridId,e._items.splice(i,1),$(s._items,h,n),h._sortData=null,e._hasListeners("send")&&e._emit("send",{item:h,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("receive")&&s._emit("receive",{item:h,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),e.layout(),s.layout()):i!==n&&(this._hBlockedIndex=i,("swap"===r?Q:K)(e._items,i,n),e._hasListeners("move")&&e._emit("move",{item:h,fromIndex:i,toIndex:n,action:r}),e.layout())))}},Xt.prototype._finishMigration=function(){var t,e,i=this._item,s=i._release,r=i._element,o=i._isActive,h=i.getGrid(),a=h._element,_=h._settings,l=_.dragContainer||a,d=this._getGrid()._settings,c=r.parentNode;this._isMigrating=!1,this.destroy(),Rt(r,d.itemClass),Rt(r,d.itemVisibleClass),Rt(r,d.itemHiddenClass),j(r,_.itemClass),j(r,o?_.itemVisibleClass:_.itemHiddenClass),l!==c&&(l.appendChild(r),e=ct(c,l,!0),(t=Lt(r)).x-=e.left,t.y-=e.top),i._refreshDimensions(),i._refreshSortData(),e=ct(l,a,!0),s._containerDiffX=e.left,s._containerDiffY=e.top,i._drag=_.dragEnabled?new Xt(i):null,l!==c&&(r.style[n]=It(t.x,t.y)),i._child.removeAttribute("style"),f(i._child,o?_.visibleStyles:_.hiddenStyles),s.start()},Xt.prototype._preStartCheck=function(t){this._startPredicateState===kt&&(this._startPredicateState=1),1===this._startPredicateState?(this._startPredicateResult=this._startPredicate(this._item,t),!0===this._startPredicateResult?(this._startPredicateState=2,this._onStart(t)):!1===this._startPredicateResult&&(this._startPredicateState=3)):2===this._startPredicateState&&this._isActive&&this._onMove(t)},Xt.prototype._preEndCheck=function(t){var e=2===this._startPredicateState;this._startPredicate(this._item,t),this._startPredicateState=kt,e&&this._isActive&&this._onEnd(t)},Xt.prototype._onStart=function(t){var e=this._item;if(e._isActive){var i,s=e._element,r=this._getGrid(),o=r._settings,h=e._release,a=e._migrate,_=r._element,l=o.dragContainer||_,d=ot(l,!0),c=Lt(s),u=c.x,f=c.y,p=s.getBoundingClientRect(),m=l!==_;this._resetHeuristics(t),m&&(i=ct(d,_)),e.isPositioning()&&e._layout.stop(!0,{transform:It(u,f)}),a._isActive&&(u-=a._containerDiffX,f-=a._containerDiffY,a.stop(!0,{transform:It(u,f)})),e.isReleasing()&&h._reset(),this._isActive=!0,this._dragEvent=t,this._container=l,this._containingBlock=d,this._elementClientX=p.left,this._elementClientY=p.top,this._left=this._gridX=u,this._top=this._gridY=f,o.dragPlaceholder.enabled&&e._dragPlaceholder.create(),r._emit("dragInit",e,t),m&&(this._containerDiffX=i.left,this._containerDiffY=i.top,s.parentNode===l?(this._gridX=u-this._containerDiffX,this._gridY=f-this._containerDiffY):(this._left=u+this._containerDiffX,this._top=f+this._containerDiffY,l.appendChild(s),s.style[n]=It(this._left,this._top))),j(s,o.itemDraggingClass),this._bindScrollListeners(),r._emit("dragStart",e,t)}},Xt.prototype._onMove=function(t){var e=this._item;if(e._isActive){var i,s,n,r=this._getGrid()._settings.dragAxis;if("y"!==r){var o=t.clientX-this._dragEvent.clientX;this._left+=o,this._gridX+=o,this._elementClientX+=o}if("x"!==r){var h=t.clientY-this._dragEvent.clientY;this._top+=h,this._gridY+=h,this._elementClientY+=h}this._dragEvent=t,i=e._id,s=this._prepareMove,n=this._applyMove,k.add(i+G,s,n,!0)}else this.stop()},Xt.prototype._prepareMove=function(){this._item._isActive&&this._getGrid()._settings.dragSort&&this._checkHeuristics(this._dragEvent)&&this._checkOverlapDebounce()},Xt.prototype._applyMove=function(){var t=this._item;t._isActive&&(t._element.style[n]=It(this._left,this._top),this._getGrid()._emit("dragMove",t,this._dragEvent))},Xt.prototype._onScroll=function(t){var e,i,s,n=this._item;n._isActive?(this._scrollEvent=t,e=n._id,i=this._prepareScroll,s=this._applyScroll,k.add(e+H,i,s,!0)):this.stop()},Xt.prototype._prepareScroll=function(){var t=this._item;if(t._isActive){var e,i=t._element,s=this._getGrid(),n=s._settings,r=n.dragAxis,o=s._element,h=i.getBoundingClientRect(),a=this._elementClientX-h.left,_=this._elementClientY-h.top;this._container!==o&&(e=ct(this._containingBlock,o),this._containerDiffX=e.left,this._containerDiffY=e.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()}},Xt.prototype._applyScroll=function(){var t=this._item;t._isActive&&(t._element.style[n]=It(this._left,this._top),this._getGrid()._emit("dragScroll",t,this._scrollEvent))},Xt.prototype._onEnd=function(t){var e=this._item,i=e._element,s=this._getGrid(),n=s._settings,r=e._release;e._isActive?(N(e._id),q(e._id),n.dragSort&&this._checkOverlapDebounce("finish"),this._unbindScrollListeners(),r._containerDiffX=this._containerDiffX,r._containerDiffY=this._containerDiffY,this._reset(),Rt(i,n.itemDraggingClass),s._emit("dragEnd",e,t),this._isMigrating?this._finishMigration():r.start()):this.stop()},Gt.prototype._onLayoutStart=function(){var t=this._item,e=t.getGrid(),i=e._items.indexOf(t),s=e._layout.slots[2*i],n=e._layout.slots[2*i+1];if(this._didMigrate||t._left!==s||t._top!==n){var r,o,h;if(s+=t._marginLeft,n+=t._marginTop,!(e._settings.dragPlaceholder.duration>0)||this._didMigrate){F(t._id);var a={transform:It(s,n)};return this._animate.isAnimating()?this._animate.stop(a):f(this._element,a),void(this._didMigrate&&(e.getElement().appendChild(this._element),this._didMigrate=!1))}this._nextLeft=s,this._nextTop=n,r=t._id,o=this._setupAnimation,h=this._startAnimation,k.add(r+O,o,h)}},Gt.prototype._setupAnimation=function(){if(this.isActive()){var t=Lt(this._element);this._currentLeft=t.x,this._currentTop=t.y}},Gt.prototype._startAnimation=function(){if(this.isActive()){var t=this._animate,e=this._currentLeft,i=this._currentTop,s=this._nextLeft,n=this._nextTop,r={transform:It(s,n)};if(e!==s||i!==n){var o=this._item.getGrid()._settings.dragPlaceholder,h={transform:It(e,i)};t.start(h,r,{duration:o.duration,easing:o.easing,onFinish:this._onLayoutEnd})}else t.isAnimating()&&t.stop(r)}},Gt.prototype._onLayoutEnd=function(){this._resetAfterLayout&&this.reset()},Gt.prototype._onReleaseEnd=function(t){if(t._id===this._item._id){if(!this._animate.isAnimating())return void this.reset();this._resetAfterLayout=!0}},Gt.prototype._onMigrate=function(t){if(t.item===this._item){var e=this._item.getGrid(),i=t.toGrid;e.off("dragReleaseEnd",this._onReleaseEnd),e.off("layoutStart",this._onLayoutStart),e.off("beforeSend",this._onMigrate),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("layoutStart",this._onLayoutStart),i.on("beforeSend",this._onMigrate),this._didMigrate=!0}},Gt.prototype.create=function(){if(this.isActive())this._resetAfterLayout=!1;else{var t,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;t=c(s.dragPlaceholder.createElement)?s.dragPlaceholder.createElement(e):window.document.createElement("div"),this._element=t,n._element=t,this._className=s.itemPlaceholderClass||"",this._className&&j(t,this._className);var r=e._left+e._marginLeft,o=e._top+e._marginTop;f(t,{display:"block",position:"absolute",left:"0",top:"0",width:e._width+"px",height:e._height+"px",transform:It(r,o)}),i.on("layoutStart",this._onLayoutStart),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("beforeSend",this._onMigrate),c(s.dragPlaceholder.onCreate)&&s.dragPlaceholder.onCreate(e,t),i.getElement().appendChild(t)}},Gt.prototype.reset=function(){if(this.isActive()){var t=this._element,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;this._resetAfterLayout=!1,F(e._id),n.stop(),n._element=null,i.off("dragReleaseEnd",this._onReleaseEnd),i.off("layoutStart",this._onLayoutStart),i.off("beforeSend",this._onMigrate),this._className&&(Rt(t,this._className),this._className=""),t.parentNode.removeChild(t),this._element=null,c(s.dragPlaceholder.onRemove)&&s.dragPlaceholder.onRemove(e,t)}},Gt.prototype.updateDimensions=function(t,e){this.isActive()&&f(this._element,{width:t+"px",height:e+"px"})},Gt.prototype.isActive=function(){return!!this._element},Gt.prototype.destroy=function(){this.reset(),this._animate.destroy(),this._item=this._animate=null},Ht.prototype.add=function(t){return this._isDestroyed?this:(this._queue.push(t),this)},Ht.prototype.flush=function(t,e){if(this._isDestroyed)return this;var i,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,e),this;for(i=0;i0;return l&&this._queue.flush(!0,o),d&&(a._isPositioningStarted=!0),c(e)&&this._queue.add(e),m?(this._isActive=!0,this._animateOptions.easing=p,this._animateOptions.duration=u,this._isInterrupted=l,s=o._id,n=this._setupAnimation,r=this._startAnimation,k.add(s+X,n,r),this):(this._updateOffsets(),this._updateTargetStyles(),i=o._animate.isAnimating(),this.stop(!1,this._targetStyles),!i&&f(h,this._targetStyles),this._skipNextAnimation=!1,this._finish())}},Ot.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item;return i=s._id,k.cancel(i+X),s._animate.stop(e),Rt(s._element,s.getGrid()._settings.itemPositioningClass),this._isActive=!1,t&&this._queue.flush(!0,s),this},Ot.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)},Ot.prototype._updateOffsets=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._offsetLeft=i._isActive?i._containerDiffX:e._isActive?e._containerDiffX:0,this._offsetTop=i._isActive?i._containerDiffY:e._isActive?e._containerDiffY:0}},Ot.prototype._updateTargetStyles=function(){this._isDestroyed||(this._targetStyles.transform=It(this._item._left+this._offsetLeft,this._item._top+this._offsetTop))},Ot.prototype._finish=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._isActive&&(this._isActive=!1,Rt(t._element,t.getGrid()._settings.itemPositioningClass)),i._isActive&&i.stop(),e._isActive&&e.stop(),this._queue.flush(!1,t)}},Ot.prototype._setupAnimation=function(){var t=Lt(this._item._element);this._currentLeft=t.x,this._currentTop=t.y},Ot.prototype._startAnimation=function(){var t=this._item,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||j(t._element,e.itemPositioningClass),this._currentStyles.transform=It(this._currentLeft,this._currentTop),t._animate.start(this._currentStyles,this._targetStyles,this._animateOptions)};var Bt={};function Nt(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._container=!1,this._containerDiffX=0,this._containerDiffY=0}Nt.prototype.start=function(t,e,i){if(this._isDestroyed)return this;var s,r,o,h,a,_,l,d,c=this._item,u=c._element,p=c.isVisible(),m=c.getGrid(),g=m._settings,y=t._settings,v=t._element,w=t._items,S=m._items.indexOf(c),D=i||window.document.body;if("number"==typeof e)s=J(w,e,!0);else{if(!(r=t._getItem(e)))return this;s=w.indexOf(r)}return(c.isPositioning()||this._isActive||c.isReleasing())&&(l=(_=Lt(u)).x,d=_.y),c.isPositioning()&&c._layout.stop(!0,{transform:It(l,d)}),this._isActive&&(l-=this._containerDiffX,d-=this._containerDiffY,this.stop(!0,{transform:It(l,d)})),c.isReleasing()&&(l-=c._release._containerDiffX,d-=c._release._containerDiffY,c._release.stop(!0,{transform:It(l,d)})),c._visibility._stopAnimation(),c._drag&&c._drag.destroy(),c._visibility._queue.flush(!0,c),m._hasListeners("beforeSend")&&m._emit("beforeSend",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("beforeReceive")&&t._emit("beforeReceive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),Rt(u,g.itemClass),Rt(u,g.itemVisibleClass),Rt(u,g.itemHiddenClass),j(u,y.itemClass),j(u,p?y.itemVisibleClass:y.itemHiddenClass),m._items.splice(S,1),$(w,c,s),c._gridId=t._id,D!==(o=u.parentNode)&&(D.appendChild(u),h=ct(D,o,!0),_||(l=(_=Lt(u)).x,d=_.y),u.style[n]=It(l+h.left,d+h.top)),c._child.removeAttribute("style"),f(c._child,p?y.visibleStyles:y.hiddenStyles),u.style.display=p?"block":"hidden",a=ct(D,v,!0),c._refreshDimensions(),c._refreshSortData(),c._drag=y.dragEnabled?new Xt(c):null,this._isActive=!0,this._container=D,this._containerDiffX=a.left,this._containerDiffY=a.top,m._hasListeners("send")&&m._emit("send",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("receive")&&t._emit("receive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),this},Nt.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid()._element;return this._container!==r&&(e||(t?(i=Lt(n),Bt.transform=It(i.x-this._containerDiffX,i.y-this._containerDiffY)):Bt.transform=It(s._left,s._top),e=Bt),r.appendChild(n),f(n,e)),this._isActive=!1,this._container=null,this._containerDiffX=0,this._containerDiffY=0,this},Nt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)};var qt={};function Ft(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0}function zt(t){var e=t._isActive,i=t._element,s=t.getGrid()._settings;this._item=t,this._isDestroyed=!1,this._isHidden=!e,this._isHiding=!1,this._isShowing=!1,this._queue=new Ht,this._finishShow=this._finishShow.bind(this),this._finishHide=this._finishHide.bind(this),i.style.display=e?"block":"none",j(i,e?s.itemVisibleClass:s.itemHiddenClass),f(t._child,e?s.visibleStyles:s.hiddenStyles)}Ft.prototype.start=function(){if(this._isDestroyed||this._isActive)return this;var t=this._item,e=t.getGrid();return this._isActive=!0,j(t._element,e._settings.itemReleasingClass),e._emit("dragReleaseStart",t),t._layout.start(!1),this},Ft.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid(),o=r._element;return this._reset(),n.parentNode!==o&&(e||(t?(i=Lt(n),qt.transform=It(i.x-this._containerDiffX,i.y-this._containerDiffY)):qt.transform=It(s._left,s._top),e=qt),o.appendChild(n),f(n,e)),t||r._emit("dragReleaseEnd",s),this},Ft.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)},Ft.prototype._reset=function(){if(!this._isDestroyed){var t=this._item;this._isActive=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0,Rt(t._element,t.getGrid()._settings.itemReleasingClass)}},zt.prototype.show=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return this._isShowing||this._isHidden?this._isShowing&&!t?(r&&n.add(r),this):(this._isShowing||(n.flush(!0,i),Rt(s,o.itemHiddenClass),j(s,o.itemVisibleClass),this._isHiding||(s.style.display="block")),r&&n.add(r),i._isActive=this._isShowing=!0,this._isHiding=this._isHidden=!1,this._startAnimation(!0,t,this._finishShow),this):(r&&r(!1,i),this)},zt.prototype.hide=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return!this._isHiding&&this._isHidden?(r&&r(!1,i),this):this._isHiding&&!t?(r&&n.add(r),this):(this._isHiding||(n.flush(!0,i),j(s,o.itemHiddenClass),Rt(s,o.itemVisibleClass)),r&&n.add(r),this._isHidden=this._isHiding=!0,i._isActive=this._isShowing=!1,this._startAnimation(!1,t,this._finishHide),this)},zt.prototype.destroy=function(){if(this._isDestroyed)return this;var t=this._item,e=t._element,i=t.getGrid(),s=this._queue,n=i._settings;return this._stopAnimation({}),s.flush(!0,t).destroy(),Rt(e,n.itemVisibleClass),Rt(e,n.itemHiddenClass),this._item=null,this._isHiding=this._isShowing=!1,this._isDestroyed=this._isHidden=!0,this},zt.prototype._startAnimation=function(t,e,i){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,_=(t?r.showEasing:r.hideEasing)||"ease",d=e||h<=0;if(o){if(B(n._id),d)return n._animateChild.isAnimating()?n._animateChild.stop(o):f(n._child,o),void(i&&i());var c,u,p;c=n._id,u=function(){s=function(t,e){var i={};for(var s in e)i[s]=a(t,l(s));return i}(n._child,o)},p=function(){n._animateChild.start(s,o,{duration:h,easing:_,onFinish:i})},k.add(c+Y,u,p)}else i&&i()}},zt.prototype._stopAnimation=function(t){if(!this._isDestroyed){var e=this._item;B(e._id),e._animateChild.stop(t)}},zt.prototype._finishShow=function(){this._isHidden||(this._isShowing=!1,this._queue.flush(!1,this._item))};var Vt={};zt.prototype._finishHide=function(){if(this._isHidden){var t=this._item;this._isHiding=!1,Vt.transform=It(0,0),t._layout.stop(!0,Vt),t._element.style.display="none",this._queue.flush(!1,t)}};var Wt,jt,Ut,Zt,$t=0;function Jt(){return++$t}function Kt(t,e,i){var s=t._settings;this._id=Jt(),this._gridId=t._id,this._isDestroyed=!1,this._left=0,this._top=0,this._element=e,this._child=e.children[0],e.parentNode!==t._element&&t._element.appendChild(e),j(e,s.itemClass),"boolean"!=typeof i&&(i="none"!==a(e,"display")),this._isActive=i,e.style.left="0",e.style.top="0",e.style[n]=It(0,0),this._animate=new p(e),this._animateChild=new p(this._child),this._visibility=new zt(this),this._layout=new Ot(this),this._migrate=new Nt(this),this._release=new Ft(this),this._dragPlaceholder=new Gt(this),this._drag=s.dragEnabled?new Xt(this):null,this._refreshDimensions(),this._refreshSortData()}function Qt(){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)}Kt.prototype.getGrid=function(){return t[this._gridId]},Kt.prototype.getElement=function(){return this._element},Kt.prototype.getWidth=function(){return this._width},Kt.prototype.getHeight=function(){return this._height},Kt.prototype.getMargin=function(){return{left:this._marginLeft,right:this._marginRight,top:this._marginTop,bottom:this._marginBottom}},Kt.prototype.getPosition=function(){return{left:this._left,top:this._top}},Kt.prototype.isActive=function(){return this._isActive},Kt.prototype.isVisible=function(){return!!this._visibility&&!this._visibility._isHidden},Kt.prototype.isShowing=function(){return!(!this._visibility||!this._visibility._isShowing)},Kt.prototype.isHiding=function(){return!(!this._visibility||!this._visibility._isHiding)},Kt.prototype.isPositioning=function(){return!(!this._layout||!this._layout._isActive)},Kt.prototype.isDragging=function(){return!(!this._drag||!this._drag._isActive)},Kt.prototype.isReleasing=function(){return!(!this._release||!this._release._isActive)},Kt.prototype.isDestroyed=function(){return this._isDestroyed},Kt.prototype._refreshDimensions=function(){if(!this._isDestroyed&&!this._visibility._isHidden){var t=this._element,e=this._dragPlaceholder,i=t.getBoundingClientRect();this._width=i.width,this._height=i.height,this._marginLeft=Math.max(0,ht(t,"margin-left")),this._marginRight=Math.max(0,ht(t,"margin-right")),this._marginTop=Math.max(0,ht(t,"margin-top")),this._marginBottom=Math.max(0,ht(t,"margin-bottom")),e&&e.updateDimensions(this._width,this._height)}},Kt.prototype._refreshSortData=function(){if(!this._isDestroyed){var t,e=this._sortData={},i=this.getGrid()._settings.sortData;for(t in i)e[t]=i[t](this,this._element)}},Kt.prototype._destroy=function(t){if(!this._isDestroyed){var e=this._element,i=this.getGrid(),s=i._settings,n=i._items.indexOf(this);this._release.destroy(),this._migrate.destroy(),this._layout.destroy(),this._visibility.destroy(),this._animate.destroy(),this._animateChild.destroy(),this._dragPlaceholder.destroy(),this._drag&&this._drag.destroy(),e.removeAttribute("style"),this._child.removeAttribute("style"),Rt(e,s.itemClass),n>-1&&i._items.splice(n,1),t&&e.parentNode.removeChild(e),this._isActive=!1,this._isDestroyed=!0}},Qt.prototype.getLayout=function(t,e,i,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),c=this._slotSizes;if(o.slots=s||this._slots,o.width=a?0:d?Math.round(e):e,o.height=a?d?Math.round(i):i:0,o.setWidth=a,o.setHeight=!a,o.slots.length=0,c.length=0,!t.length)return o;for(r=0;rd.height&&(Wt.left>0&&u.push(this._addRect(0,d.height,Wt.left,1/0)),Wt.left+Wt.widthd.width&&(Wt.top>0&&u.push(this._addRect(d.width,0,1/0,Wt.top)),Wt.top+Wt.height.49&&r.height>.49&&(!e&&r.tope.left+e.width&&jt.push(this._addRect(e.left+e.width,t.top,t.left+t.width-(e.left+e.width),t.height)),t.tope.top+e.height&&jt.push(this._addRect(t.left,e.top+e.height,t.width,t.top+t.height-(e.top+e.height))),jt):(jt.push(this._addRect(t.left,t.top,t.width,t.height)),jt)}),Qt.prototype._doRectsOverlap=function(t,e){return!(t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top)},Qt.prototype._isRectWithinRect=function(t,e){return t.left>=e.left&&t.top>=e.top&&t.left+t.width<=e.left+e.width&&t.top+t.height<=e.top+e.height},Qt.prototype._purgeRects=(Ut={},Zt={},function(t){for(var e,i=t.length;i--;)if(e=t.length,t[i])for(this._getRect(t[i],Ut);e--;)if(t[e]&&i!==e&&this._isRectWithinRect(Ut,this._getRect(t[e],Zt))){t[i]=0;break}return t}),Qt.prototype._sortRectsTopLeft=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.tope.top?1:t.lefte.left?1:0}}(),Qt.prototype._sortRectsLeftTop=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.lefte.left?1:t.tope.top?1:0}}();var te="[object HTMLCollection]",ee="[object NodeList]";function ie(t){var e=Object.prototype.toString.call(t);return e===te||e===ee}var se="object",ne="[object Object]",re=Object.prototype.toString;function oe(t){return typeof t===se&&re.call(t)===ne}function he(t){return ie(t)?Array.prototype.slice.call(t):Array.prototype.concat(t)}var ae=new Qt,_e=function(){},le="number",de="string";function ce(e,s){var n,r,o,h=this;if(!((e=this._element=typeof e===de?window.document.querySelector(e):e).getRootNode?e.getRootNode({composed:!0})===document:window.document.body.contains(e))||e===window.document.documentElement)throw new Error("Container element must be an existing DOM element");c((n=this._settings=function(t,e){var i=ue({},t);e&&(i=ue(i,e));return i.visibleStyles=(e||0).visibleStyles||(t||0).visibleStyles,i.hiddenStyles=(e||0).hiddenStyles||(t||0).hiddenStyles,i}(ce.defaultOptions,s)).dragSort)||(n.dragSort=!!n.dragSort),this._id=Jt(),t[this._id]=h,this._isDestroyed=!1,this._layout={id:0,items:[],slots:[],setWidth:!1,setHeight:!1,width:0,height:0},this._emitter=new i,j(e,n.containerClass),this._items=[],typeof(r=n.items)===de?he(e.children).forEach(function(t){("*"===r||W(t,r))&&h._items.push(new Kt(h,t))}):(Array.isArray(r)||ie(r))&&(this._items=he(r).map(function(t){return new Kt(h,t)})),typeof(o=n.layoutOnResize)!==le&&(o=!0===o?0:-1),o>=0&&window.addEventListener("resize",h._resizeHandler=nt(function(){h.refreshItems().layout()},o)),n.layoutOnInit&&this.layout(!0)}function ue(t,e){var i,s,n,r=Object.keys(e),o=r.length;for(n=0;n0)){var s=o._layout.id!==l,n=c(t)?t:i;c(n)&&n(s,_.items.slice(0)),!s&&o._hasListeners(e)&&o._emit(e,_.items.slice(0))}}if((_.setHeight&&typeof _.height===le||_.setWidth&&typeof _.width===le)&&(s="border-box"===a(h,"box-sizing")),_.setHeight&&(typeof _.height===le?h.style.height=(s?_.height+this._borderTop+this._borderBottom:_.height)+"px":h.style.height=_.height),_.setWidth&&(typeof _.width===le?h.style.width=(s?_.width+this._borderLeft+this._borderRight:_.width)+"px":h.style.width=_.width),this._hasListeners("layoutStart")&&this._emit("layoutStart",_.items.slice(0)),!d)return f(),this;for(r=0;rl?1:0:ld?1:0)return c;return c||(s||(s=n(i)),c=r(o,h)),c}function h(o,h){var a=t(o,h);return e&&a&&(a=-a),a||(s||(s=n(i)),r(o,h))}return function(n,r){if(this._isDestroyed||this._items.length<2)return this;var a,_=this._items,l=r||0,d=l.layout?l.layout:void 0===l.layout;if(t=n,e=!!l.descending,i=_.slice(0),s=null,c(t))_.sort(h);else if(typeof t===de)t=n.trim().split(" ").map(function(t){return t.split(":")}),_.sort(o);else{if(!Array.isArray(t))return this;if(t.length!==_.length)throw new Error("[Muuri] sort reference items do not match with grid items.");for(a=0;a<_.length;a++){if(t.indexOf(_[a])<0)throw new Error("[Muuri] sort reference items do not match with grid items.");_[a]=t[a]}e&&_.reverse()}return this._hasListeners("sort")&&this._emit("sort",_.slice(0),i),d&&this.layout("instant"===d,c(d)?d:void 0),this}}(),ce.prototype.move=function(t,e,i){if(this._isDestroyed||this._items.length<2)return this;var s,n,r=this._items,o=i||0,h=o.layout?o.layout:void 0===o.layout,a="swap"===o.action,_=a?"swap":"move",l=this._getItem(t),d=this._getItem(e);return l&&d&&l!==d&&(s=r.indexOf(l),n=r.indexOf(d),a?Q(r,s,n):K(r,s,n),this._hasListeners("move")&&this._emit("move",{item:l,fromIndex:s,toIndex:n,action:_}),h&&this.layout("instant"===h,c(h)?h:void 0)),this},ce.prototype.send=function(t,e,i,s){if(this._isDestroyed||e._isDestroyed||this===e)return this;if(!(t=this._getItem(t)))return this;var n=s||0,r=n.appendTo||window.document.body,o=n.layoutSender?n.layoutSender:void 0===n.layoutSender,h=n.layoutReceiver?n.layoutReceiver:void 0===n.layoutReceiver;return t._migrate.start(e,i,r),t._migrate._isActive&&t._isActive&&(o&&this.layout("instant"===o,c(o)?o:void 0),h&&e.layout("instant"===h,c(h)?h:void 0)),this},ce.prototype.destroy=function(e){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-1?t:this._items.length+t]||null;if(t instanceof Kt)return t._gridId===this._id?t:null;for(var e=0;e-1||(M._activeInstances.push(t),M._emitter.on(D,t._onMove),M._emitter.on(A,t._onCancel),M._emitter.on(b,t._onEnd),1===M._activeInstances.length&&M._bindListeners())},M._deactivateInstance=function(t){var e=M._activeInstances.indexOf(t);-1!==e&&(M._activeInstances.splice(e,1),M._emitter.off(D,t._onMove),M._emitter.off(A,t._onCancel),M._emitter.off(b,t._onEnd),M._activeInstances.length||M._unbindListeners())},M._bindListeners=function(){var t=M._events;window.addEventListener(t.move,M._onMove,R),window.addEventListener(t.end,M._onEnd,R),t.cancel&&window.addEventListener(t.cancel,M._onCancel,R)},M._unbindListeners=function(){var t=M._events;window.removeEventListener(t.move,M._onMove,R),window.removeEventListener(t.end,M._onEnd,R),t.cancel&&window.removeEventListener(t.cancel,M._onCancel,R)},M._getEventPointerId=function(t){return"number"==typeof t.pointerId?t.pointerId:t.changedTouches?t.changedTouches[0]?t.changedTouches[0].identifier:null:1},M._getTouchById=function(t,e){if("number"==typeof t.pointerId)return t.pointerId===e?t:null;if(t.changedTouches){for(var i=0;i-1&&(this._queue[n]=void 0),s?this._queue.unshift(t):this._queue.push(t),this._reads[t]=e,this._writes[t]=i,this._nextStep||(this._nextStep=y(this._step))},T.prototype.cancel=function(t){var e=this._queue.indexOf(t);e>-1&&(this._queue[e]=void 0,delete this._reads[t],delete this._writes[t])},T.prototype._step=function(){var t,e,i=this._queue,s=this._reads,n=this._writes,r=this._batch,o=this._batchReads,h=this._batchWrites,a=i.length;for(this._nextStep=null,e=0;en?n:e<0?Math.max(n+e+1,0):e}function K(t,e,i){if(!(t.length<2)){var s=J(t,e),n=J(t,i);s!==n&&t.splice(n,0,t.splice(s,1)[0])}}function Q(t,e,i){if(!(t.length<2)){var s,n=J(t,e),r=J(t,i);n!==r&&(s=t[n],t[n]=t[r],t[r]=s)}}var tt="cancel",et="finish",it="debounce",st=0;function nt(t,e){var i,s=++st+it;return e>0?function(n){void 0!==i&&(i=window.clearTimeout(i),k.cancel(s),n===et&&t()),n!==tt&&n!==et&&(i=window.setTimeout(function(){i=void 0,k.add(s,t,null,!0)},e))}:function(e){e!==tt&&t()}}function rt(t){var e=a(t,"transform");if(!e||"none"===e)return!1;var i=a(t,"display");return"inline"!==i&&"none"!==i}function ot(t,e){for(var i=window.document,s=(e?t:t.parentElement)||i;s&&s!==i&&"static"===a(s,"position")&&!rt(s);)s=s.parentElement||i;return s}function ht(t,e){return parseFloat(a(t,e))||0}var at={},_t={},lt={};function dt(t,e){var i,s=e||{};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:(i=t.getBoundingClientRect(),s.left+=i.left,s.top+=i.top,s.left+=ht(t,"border-left-width"),s.top+=ht(t,"border-top-width"),s))}function ct(t,e,i){return lt.left=0,lt.top=0,t===e?lt:i&&(t=ot(t,!0))===(e=ot(e,!0))?lt:(dt(t,at),dt(e,_t),lt.left=_t.left-at.left,lt.top=_t.top-at.top,lt)}var ut="overflow",ft="overflow-x",pt="overflow-y",mt="auto",gt="scroll";function yt(t){var e=a(t,ut);return e===mt||e===gt||((e=a(t,ft))===mt||e===gt||((e=a(t,pt))===mt||e===gt))}function vt(t,e,i){for(var s=i||[],n=e?t:t.parentNode;n&&n!==document;)n.getRootNode&&n instanceof DocumentFragment?n=n.getRootNode().host:(yt(n)&&s.push(n),n=n.parentNode);return s.push(window),s}var wt={},St="transform",Dt="none",bt=/^matrix3d/,At=/([^,]*,){4}/,Et=/([^,]*,){12}/,Ct=/[^,]*,/;function Lt(t){wt.x=0,wt.y=0;var e=a(t,St);if(!e||e===Dt)return wt;var i=bt.test(e),s=e.replace(i?Et:At,""),n=s.replace(Ct,"");return wt.x=parseFloat(s)||0,wt.y=parseFloat(n)||0,wt}function It(t,e){return"translateX("+t+"px) translateY("+e+"px)"}function Rt(t,e){t.classList?t.classList.remove(e):W(t,"."+e)&&(t.className=(" "+t.className+" ").replace(" "+e+" "," ").trim())}var xt,Pt,Mt,Tt,kt=0;function Xt(t){var e=t._element,i=t.getGrid(),s=i._settings;this._item=t,this._gridId=i._id,this._isDestroyed=!1,this._isMigrating=!1,this._startPredicate=c(s.dragStartPredicate)?s.dragStartPredicate:Xt.defaultStartPredicate,this._startPredicateState=kt,this._startPredicateResult=void 0,this._hBlockedIndex=null,this._hX1=0,this._hX2=0,this._hY1=0,this._hY2=0,this._reset(),this._preStartCheck=this._preStartCheck.bind(this),this._preEndCheck=this._preEndCheck.bind(this),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);var n=s.dragSortHeuristics.sortInterval;this._checkOverlapDebounce=nt(this._checkOverlap,n),this._dragger=new M(e,s.dragCssProps),this._dragger.on("start",this._preStartCheck),this._dragger.on("move",this._preStartCheck),this._dragger.on("cancel",this._preEndCheck),this._dragger.on("end",this._preEndCheck)}function Yt(t,e){return t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top?0:(Math.min(t.left+t.width,e.left+e.width)-Math.max(t.left,e.left))*(Math.min(t.top+t.height,e.top+e.height)-Math.max(t.top,e.top))/(Math.min(t.width,e.width)*Math.min(t.height,e.height))*100}function Gt(t){this._item=t,this._animate=new p,this._element=null,this._className="",this._didMigrate=!1,this._resetAfterLayout=!1,this._currentLeft=0,this._currentTop=0,this._nextLeft=0,this._nextTop=0,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this),this._onLayoutStart=this._onLayoutStart.bind(this),this._onLayoutEnd=this._onLayoutEnd.bind(this),this._onReleaseEnd=this._onReleaseEnd.bind(this),this._onMigrate=this._onMigrate.bind(this)}function Ht(){this._queue=[],this._isDestroyed=!1}function Ot(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 Ht,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this)}Xt.defaultStartPredicate=function(t,e,i){var s=t._drag,n=s._startPredicateData||s._setupStartPredicate(i);if(!e.isFinal)return!(!n.handleElement&&(n.handleElement=s._getStartPredicateHandle(e),!n.handleElement))&&(n.delay&&(n.event=e,n.delayTimer||(n.delayTimer=window.setTimeout(function(){n.delay=0,s._resolveStartPredicate(n.event)&&(s._forceResolveStartPredicate(n.event),s._resetStartPredicate())},n.delay))),s._resolveStartPredicate(e));s._finishStartPredicate(e)},Xt.defaultSortPredicate=(xt={},Pt={},Mt={},Tt=[],function(t,e){var i=t._drag,s=i._getGrid(),n=e&&"number"==typeof e.threshold?e.threshold:50,r=e&&"swap"===e.action?"swap":"move",o=e&&"swap"===e.migrateAction?"swap":"move";xt.width=t._width,xt.height=t._height,xt.left=i._elementClientX,xt.top=i._elementClientY;var h=function(t,e,i){var s,n,r,o,h=null,a=e._settings.dragSort,_=-1;if(!0===a?(Tt[0]=e,n=Tt):n=a.call(e,t),!Array.isArray(n))return h;for(o=0;oi&&s>_&&(_=s,h=r));return Tt.length=0,h}(t,s,n);if(!h)return!1;var a,_,l,d,c,u=t.getGrid()!==h,f=0,p=0,m=-1;for(h===s?(xt.left=i._gridX+t._marginLeft,xt.top=i._gridY+t._marginTop):(h._updateBorders(1,0,1,0),f=h._left+h._borderLeft,p=h._top+h._borderTop),c=0;cm&&(a=c,m=d));return m0?a:-1:0,m=n),m>=n&&(Mt.grid=h,Mt.index=a,Mt.action=u?o:r,Mt)}),Xt.prototype.stop=function(){var t=this._item,e=t._element,i=this._getGrid();return this._isActive?this._isMigrating?(this._finishMigration(),this):(N(t._id),q(t._id),this._unbindScrollListeners(),this._checkOverlapDebounce("cancel"),e.parentNode!==i._element&&(i._element.appendChild(e),e.style[n]=It(this._gridX,this._gridY)),Rt(e,i._settings.itemDraggingClass),this._reset(),this):this},Xt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(),this._dragger.destroy(),this._isDestroyed=!0,this)},Xt.prototype._getGrid=function(){return t[this._gridId]||null},Xt.prototype._reset=function(){this._isActive=!1,this._container=null,this._containingBlock=null,this._dragEvent=null,this._scrollEvent=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},Xt.prototype._bindScrollListeners=function(){var t,e,i=this._getGrid()._element,s=this._container,n=this._scrollers;if(n.length=0,vt(this._item._element,!1,n),s!==i)for(vt(i,!0,t=[]),e=0;e=s&&t.pageX=n&&t.pageY3&&e.minBounceBackAngle>0;if(h||(this._hBlockedIndex=null),Math.abs(r)>i||Math.abs(o)>i){if(h){var a=Math.atan2(r,o),_=Math.atan2(this._hX2-this._hX1,this._hY2-this._hY1),l=Math.atan2(Math.sin(a-_),Math.cos(a-_));Math.abs(l)>e.minBounceBackAngle&&(this._hBlockedIndex=null)}return this._hX1=this._hX2,this._hY1=this._hY2,this._hX2=s,this._hY2=n,!0}return!1},Xt.prototype._resetStartPredicate=function(){var t=this._startPredicateData;t&&(t.delayTimer&&(t.delayTimer=window.clearTimeout(t.delayTimer)),this._startPredicateData=null)},Xt.prototype._checkOverlap=function(){if(this._isActive){var t,e,i,s,n,r,o,h=this._item,a=this._getGrid()._settings;(t=c(a.dragSortPredicate)?a.dragSortPredicate(h,this._dragEvent):Xt.defaultSortPredicate(h,a.dragSortPredicate))&&"number"==typeof t.index&&(o=(e=h.getGrid())!==(s=t.grid||e),i=e._items.indexOf(h),n=J(s._items,t.index,o),r="swap"===t.action?"swap":"move",(o||n!==this._hBlockedIndex)&&(o?(this._hBlockedIndex=null,e._hasListeners("beforeSend")&&e._emit("beforeSend",{item:h,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("beforeReceive")&&s._emit("beforeReceive",{item:h,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),h._gridId=s._id,this._isMigrating=h._gridId!==this._gridId,e._items.splice(i,1),$(s._items,h,n),h._sortData=null,e._hasListeners("send")&&e._emit("send",{item:h,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("receive")&&s._emit("receive",{item:h,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),e.layout(),s.layout()):i!==n&&(this._hBlockedIndex=i,("swap"===r?Q:K)(e._items,i,n),e._hasListeners("move")&&e._emit("move",{item:h,fromIndex:i,toIndex:n,action:r}),e.layout())))}},Xt.prototype._finishMigration=function(){var t,e,i=this._item,s=i._release,r=i._element,o=i._isActive,h=i.getGrid(),a=h._element,_=h._settings,l=_.dragContainer||a,d=this._getGrid()._settings,c=r.parentNode;this._isMigrating=!1,this.destroy(),Rt(r,d.itemClass),Rt(r,d.itemVisibleClass),Rt(r,d.itemHiddenClass),j(r,_.itemClass),j(r,o?_.itemVisibleClass:_.itemHiddenClass),l!==c&&(l.appendChild(r),e=ct(c,l,!0),(t=Lt(r)).x-=e.left,t.y-=e.top),i._refreshDimensions(),i._refreshSortData(),e=ct(l,a,!0),s._containerDiffX=e.left,s._containerDiffY=e.top,i._drag=_.dragEnabled?new Xt(i):null,l!==c&&(r.style[n]=It(t.x,t.y)),i._child.removeAttribute("style"),f(i._child,o?_.visibleStyles:_.hiddenStyles),s.start()},Xt.prototype._preStartCheck=function(t){this._startPredicateState===kt&&(this._startPredicateState=1),1===this._startPredicateState?(this._startPredicateResult=this._startPredicate(this._item,t),!0===this._startPredicateResult?(this._startPredicateState=2,this._onStart(t)):!1===this._startPredicateResult&&(this._startPredicateState=3)):2===this._startPredicateState&&this._isActive&&this._onMove(t)},Xt.prototype._preEndCheck=function(t){var e=2===this._startPredicateState;this._startPredicate(this._item,t),this._startPredicateState=kt,e&&this._isActive&&this._onEnd(t)},Xt.prototype._onStart=function(t){var e=this._item;if(e._isActive){var i,s=e._element,r=this._getGrid(),o=r._settings,h=e._release,a=e._migrate,_=r._element,l=o.dragContainer||_,d=ot(l,!0),c=Lt(s),u=c.x,f=c.y,p=s.getBoundingClientRect(),m=l!==_;this._resetHeuristics(t),m&&(i=ct(d,_)),e.isPositioning()&&e._layout.stop(!0,{transform:It(u,f)}),a._isActive&&(u-=a._containerDiffX,f-=a._containerDiffY,a.stop(!0,{transform:It(u,f)})),e.isReleasing()&&h._reset(),this._isActive=!0,this._dragEvent=t,this._container=l,this._containingBlock=d,this._elementClientX=p.left,this._elementClientY=p.top,this._left=this._gridX=u,this._top=this._gridY=f,o.dragPlaceholder.enabled&&e._dragPlaceholder.create(),r._emit("dragInit",e,t),m&&(this._containerDiffX=i.left,this._containerDiffY=i.top,s.parentNode===l?(this._gridX=u-this._containerDiffX,this._gridY=f-this._containerDiffY):(this._left=u+this._containerDiffX,this._top=f+this._containerDiffY,l.appendChild(s),s.style[n]=It(this._left,this._top))),j(s,o.itemDraggingClass),this._bindScrollListeners(),r._emit("dragStart",e,t)}},Xt.prototype._onMove=function(t){var e=this._item;if(e._isActive){var i,s,n,r=this._getGrid()._settings.dragAxis;if("y"!==r){var o=t.clientX-this._dragEvent.clientX;this._left+=o,this._gridX+=o,this._elementClientX+=o}if("x"!==r){var h=t.clientY-this._dragEvent.clientY;this._top+=h,this._gridY+=h,this._elementClientY+=h}this._dragEvent=t,i=e._id,s=this._prepareMove,n=this._applyMove,k.add(i+G,s,n,!0)}else this.stop()},Xt.prototype._prepareMove=function(){this._item._isActive&&this._getGrid()._settings.dragSort&&this._checkHeuristics(this._dragEvent)&&this._checkOverlapDebounce()},Xt.prototype._applyMove=function(){var t=this._item;t._isActive&&(t._element.style[n]=It(this._left,this._top),this._getGrid()._emit("dragMove",t,this._dragEvent))},Xt.prototype._onScroll=function(t){var e,i,s,n=this._item;n._isActive?(this._scrollEvent=t,e=n._id,i=this._prepareScroll,s=this._applyScroll,k.add(e+H,i,s,!0)):this.stop()},Xt.prototype._prepareScroll=function(){var t=this._item;if(t._isActive){var e,i=t._element,s=this._getGrid(),n=s._settings,r=n.dragAxis,o=s._element,h=i.getBoundingClientRect(),a=this._elementClientX-h.left,_=this._elementClientY-h.top;this._container!==o&&(e=ct(this._containingBlock,o),this._containerDiffX=e.left,this._containerDiffY=e.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()}},Xt.prototype._applyScroll=function(){var t=this._item;t._isActive&&(t._element.style[n]=It(this._left,this._top),this._getGrid()._emit("dragScroll",t,this._scrollEvent))},Xt.prototype._onEnd=function(t){var e=this._item,i=e._element,s=this._getGrid(),n=s._settings,r=e._release;e._isActive?(N(e._id),q(e._id),n.dragSort&&this._checkOverlapDebounce("finish"),this._unbindScrollListeners(),r._containerDiffX=this._containerDiffX,r._containerDiffY=this._containerDiffY,this._reset(),Rt(i,n.itemDraggingClass),s._emit("dragEnd",e,t),this._isMigrating?this._finishMigration():r.start()):this.stop()},Gt.prototype._onLayoutStart=function(){var t=this._item,e=t.getGrid(),i=e._items.indexOf(t),s=e._layout.slots[2*i],n=e._layout.slots[2*i+1];if(this._didMigrate||t._left!==s||t._top!==n){var r,o,h;if(s+=t._marginLeft,n+=t._marginTop,!(e._settings.dragPlaceholder.duration>0)||this._didMigrate){F(t._id);var a={transform:It(s,n)};return this._animate.isAnimating()?this._animate.stop(a):f(this._element,a),void(this._didMigrate&&(e.getElement().appendChild(this._element),this._didMigrate=!1))}this._nextLeft=s,this._nextTop=n,r=t._id,o=this._setupAnimation,h=this._startAnimation,k.add(r+O,o,h)}},Gt.prototype._setupAnimation=function(){if(this.isActive()){var t=Lt(this._element);this._currentLeft=t.x,this._currentTop=t.y}},Gt.prototype._startAnimation=function(){if(this.isActive()){var t=this._animate,e=this._currentLeft,i=this._currentTop,s=this._nextLeft,n=this._nextTop,r={transform:It(s,n)};if(e!==s||i!==n){var o=this._item.getGrid()._settings.dragPlaceholder,h={transform:It(e,i)};t.start(h,r,{duration:o.duration,easing:o.easing,onFinish:this._onLayoutEnd})}else t.isAnimating()&&t.stop(r)}},Gt.prototype._onLayoutEnd=function(){this._resetAfterLayout&&this.reset()},Gt.prototype._onReleaseEnd=function(t){if(t._id===this._item._id){if(!this._animate.isAnimating())return void this.reset();this._resetAfterLayout=!0}},Gt.prototype._onMigrate=function(t){if(t.item===this._item){var e=this._item.getGrid(),i=t.toGrid;e.off("dragReleaseEnd",this._onReleaseEnd),e.off("layoutStart",this._onLayoutStart),e.off("beforeSend",this._onMigrate),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("layoutStart",this._onLayoutStart),i.on("beforeSend",this._onMigrate),this._didMigrate=!0}},Gt.prototype.create=function(){if(this.isActive())this._resetAfterLayout=!1;else{var t,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;t=c(s.dragPlaceholder.createElement)?s.dragPlaceholder.createElement(e):window.document.createElement("div"),this._element=t,n._element=t,this._className=s.itemPlaceholderClass||"",this._className&&j(t,this._className);var r=e._left+e._marginLeft,o=e._top+e._marginTop;f(t,{display:"block",position:"absolute",left:"0",top:"0",width:e._width+"px",height:e._height+"px",transform:It(r,o)}),i.on("layoutStart",this._onLayoutStart),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("beforeSend",this._onMigrate),c(s.dragPlaceholder.onCreate)&&s.dragPlaceholder.onCreate(e,t),i.getElement().appendChild(t)}},Gt.prototype.reset=function(){if(this.isActive()){var t=this._element,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;this._resetAfterLayout=!1,F(e._id),n.stop(),n._element=null,i.off("dragReleaseEnd",this._onReleaseEnd),i.off("layoutStart",this._onLayoutStart),i.off("beforeSend",this._onMigrate),this._className&&(Rt(t,this._className),this._className=""),t.parentNode.removeChild(t),this._element=null,c(s.dragPlaceholder.onRemove)&&s.dragPlaceholder.onRemove(e,t)}},Gt.prototype.updateDimensions=function(t,e){this.isActive()&&f(this._element,{width:t+"px",height:e+"px"})},Gt.prototype.isActive=function(){return!!this._element},Gt.prototype.destroy=function(){this.reset(),this._animate.destroy(),this._item=this._animate=null},Ht.prototype.add=function(t){return this._isDestroyed?this:(this._queue.push(t),this)},Ht.prototype.flush=function(t,e){if(this._isDestroyed)return this;var i,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,e),this;for(i=0;i0;return l&&this._queue.flush(!0,o),d&&(a._isPositioningStarted=!0),c(e)&&this._queue.add(e),m?(this._isActive=!0,this._animateOptions.easing=p,this._animateOptions.duration=u,this._isInterrupted=l,s=o._id,n=this._setupAnimation,r=this._startAnimation,k.add(s+X,n,r),this):(this._updateOffsets(),this._updateTargetStyles(),i=o._animate.isAnimating(),this.stop(!1,this._targetStyles),!i&&f(h,this._targetStyles),this._skipNextAnimation=!1,this._finish())}},Ot.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item;return i=s._id,k.cancel(i+X),s._animate.stop(e),Rt(s._element,s.getGrid()._settings.itemPositioningClass),this._isActive=!1,t&&this._queue.flush(!0,s),this},Ot.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)},Ot.prototype._updateOffsets=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._offsetLeft=i._isActive?i._containerDiffX:e._isActive?e._containerDiffX:0,this._offsetTop=i._isActive?i._containerDiffY:e._isActive?e._containerDiffY:0}},Ot.prototype._updateTargetStyles=function(){this._isDestroyed||(this._targetStyles.transform=It(this._item._left+this._offsetLeft,this._item._top+this._offsetTop))},Ot.prototype._finish=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._isActive&&(this._isActive=!1,Rt(t._element,t.getGrid()._settings.itemPositioningClass)),i._isActive&&i.stop(),e._isActive&&e.stop(),this._queue.flush(!1,t)}},Ot.prototype._setupAnimation=function(){var t=Lt(this._item._element);this._currentLeft=t.x,this._currentTop=t.y},Ot.prototype._startAnimation=function(){var t=this._item,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||j(t._element,e.itemPositioningClass),this._currentStyles.transform=It(this._currentLeft,this._currentTop),t._animate.start(this._currentStyles,this._targetStyles,this._animateOptions)};var Bt={};function Nt(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._container=!1,this._containerDiffX=0,this._containerDiffY=0}Nt.prototype.start=function(t,e,i){if(this._isDestroyed)return this;var s,r,o,h,a,_,l,d,c=this._item,u=c._element,p=c.isVisible(),m=c.getGrid(),g=m._settings,y=t._settings,v=t._element,w=t._items,S=m._items.indexOf(c),D=i||window.document.body;if("number"==typeof e)s=J(w,e,!0);else{if(!(r=t._getItem(e)))return this;s=w.indexOf(r)}return(c.isPositioning()||this._isActive||c.isReleasing())&&(l=(_=Lt(u)).x,d=_.y),c.isPositioning()&&c._layout.stop(!0,{transform:It(l,d)}),this._isActive&&(l-=this._containerDiffX,d-=this._containerDiffY,this.stop(!0,{transform:It(l,d)})),c.isReleasing()&&(l-=c._release._containerDiffX,d-=c._release._containerDiffY,c._release.stop(!0,{transform:It(l,d)})),c._visibility._stopAnimation(),c._drag&&c._drag.destroy(),c._visibility._queue.flush(!0,c),m._hasListeners("beforeSend")&&m._emit("beforeSend",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("beforeReceive")&&t._emit("beforeReceive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),Rt(u,g.itemClass),Rt(u,g.itemVisibleClass),Rt(u,g.itemHiddenClass),j(u,y.itemClass),j(u,p?y.itemVisibleClass:y.itemHiddenClass),m._items.splice(S,1),$(w,c,s),c._gridId=t._id,D!==(o=u.parentNode)&&(D.appendChild(u),h=ct(D,o,!0),_||(l=(_=Lt(u)).x,d=_.y),u.style[n]=It(l+h.left,d+h.top)),c._child.removeAttribute("style"),f(c._child,p?y.visibleStyles:y.hiddenStyles),u.style.display=p?"block":"hidden",a=ct(D,v,!0),c._refreshDimensions(),c._refreshSortData(),c._drag=y.dragEnabled?new Xt(c):null,this._isActive=!0,this._container=D,this._containerDiffX=a.left,this._containerDiffY=a.top,m._hasListeners("send")&&m._emit("send",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("receive")&&t._emit("receive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),this},Nt.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid()._element;return this._container!==r&&(e||(t?(i=Lt(n),Bt.transform=It(i.x-this._containerDiffX,i.y-this._containerDiffY)):Bt.transform=It(s._left,s._top),e=Bt),r.appendChild(n),f(n,e)),this._isActive=!1,this._container=null,this._containerDiffX=0,this._containerDiffY=0,this},Nt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)};var qt={};function Ft(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0}function zt(t){var e=t._isActive,i=t._element,s=t.getGrid()._settings;this._item=t,this._isDestroyed=!1,this._isHidden=!e,this._isHiding=!1,this._isShowing=!1,this._queue=new Ht,this._finishShow=this._finishShow.bind(this),this._finishHide=this._finishHide.bind(this),i.style.display=e?"block":"none",j(i,e?s.itemVisibleClass:s.itemHiddenClass),f(t._child,e?s.visibleStyles:s.hiddenStyles)}Ft.prototype.start=function(){if(this._isDestroyed||this._isActive)return this;var t=this._item,e=t.getGrid();return this._isActive=!0,j(t._element,e._settings.itemReleasingClass),e._emit("dragReleaseStart",t),t._layout.start(!1),this},Ft.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid(),o=r._element;return this._reset(),n.parentNode!==o&&(e||(t?(i=Lt(n),qt.transform=It(i.x-this._containerDiffX,i.y-this._containerDiffY)):qt.transform=It(s._left,s._top),e=qt),o.appendChild(n),f(n,e)),t||r._emit("dragReleaseEnd",s),this},Ft.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)},Ft.prototype._reset=function(){if(!this._isDestroyed){var t=this._item;this._isActive=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0,Rt(t._element,t.getGrid()._settings.itemReleasingClass)}},zt.prototype.show=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return this._isShowing||this._isHidden?this._isShowing&&!t?(r&&n.add(r),this):(this._isShowing||(n.flush(!0,i),Rt(s,o.itemHiddenClass),j(s,o.itemVisibleClass),this._isHiding||(s.style.display="block")),r&&n.add(r),i._isActive=this._isShowing=!0,this._isHiding=this._isHidden=!1,this._startAnimation(!0,t,this._finishShow),this):(r&&r(!1,i),this)},zt.prototype.hide=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return!this._isHiding&&this._isHidden?(r&&r(!1,i),this):this._isHiding&&!t?(r&&n.add(r),this):(this._isHiding||(n.flush(!0,i),j(s,o.itemHiddenClass),Rt(s,o.itemVisibleClass)),r&&n.add(r),this._isHidden=this._isHiding=!0,i._isActive=this._isShowing=!1,this._startAnimation(!1,t,this._finishHide),this)},zt.prototype.destroy=function(){if(this._isDestroyed)return this;var t=this._item,e=t._element,i=t.getGrid(),s=this._queue,n=i._settings;return this._stopAnimation({}),s.flush(!0,t).destroy(),Rt(e,n.itemVisibleClass),Rt(e,n.itemHiddenClass),this._item=null,this._isHiding=this._isShowing=!1,this._isDestroyed=this._isHidden=!0,this},zt.prototype._startAnimation=function(t,e,i){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,_=(t?r.showEasing:r.hideEasing)||"ease",d=e||h<=0;if(o){if(B(n._id),d)return n._animateChild.isAnimating()?n._animateChild.stop(o):f(n._child,o),void(i&&i());var c,u,p;c=n._id,u=function(){s=function(t,e){var i={};for(var s in e)i[s]=a(t,l(s));return i}(n._child,o)},p=function(){n._animateChild.start(s,o,{duration:h,easing:_,onFinish:i})},k.add(c+Y,u,p)}else i&&i()}},zt.prototype._stopAnimation=function(t){if(!this._isDestroyed){var e=this._item;B(e._id),e._animateChild.stop(t)}},zt.prototype._finishShow=function(){this._isHidden||(this._isShowing=!1,this._queue.flush(!1,this._item))};var Vt={};zt.prototype._finishHide=function(){if(this._isHidden){var t=this._item;this._isHiding=!1,Vt.transform=It(0,0),t._layout.stop(!0,Vt),t._element.style.display="none",this._queue.flush(!1,t)}};var Wt,jt,Ut,Zt,$t=0;function Jt(){return++$t}function Kt(t,e,i){var s=t._settings;this._id=Jt(),this._gridId=t._id,this._isDestroyed=!1,this._left=0,this._top=0,this._element=e,this._child=e.children[0],e.parentNode!==t._element&&t._element.appendChild(e),j(e,s.itemClass),"boolean"!=typeof i&&(i="none"!==a(e,"display")),this._isActive=i,e.style.left="0",e.style.top="0",e.style[n]=It(0,0),this._animate=new p(e),this._animateChild=new p(this._child),this._visibility=new zt(this),this._layout=new Ot(this),this._migrate=new Nt(this),this._release=new Ft(this),this._dragPlaceholder=new Gt(this),this._drag=s.dragEnabled?new Xt(this):null,this._refreshDimensions(),this._refreshSortData()}function Qt(){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)}Kt.prototype.getGrid=function(){return t[this._gridId]},Kt.prototype.getElement=function(){return this._element},Kt.prototype.getWidth=function(){return this._width},Kt.prototype.getHeight=function(){return this._height},Kt.prototype.getMargin=function(){return{left:this._marginLeft,right:this._marginRight,top:this._marginTop,bottom:this._marginBottom}},Kt.prototype.getPosition=function(){return{left:this._left,top:this._top}},Kt.prototype.isActive=function(){return this._isActive},Kt.prototype.isVisible=function(){return!!this._visibility&&!this._visibility._isHidden},Kt.prototype.isShowing=function(){return!(!this._visibility||!this._visibility._isShowing)},Kt.prototype.isHiding=function(){return!(!this._visibility||!this._visibility._isHiding)},Kt.prototype.isPositioning=function(){return!(!this._layout||!this._layout._isActive)},Kt.prototype.isDragging=function(){return!(!this._drag||!this._drag._isActive)},Kt.prototype.isReleasing=function(){return!(!this._release||!this._release._isActive)},Kt.prototype.isDestroyed=function(){return this._isDestroyed},Kt.prototype._refreshDimensions=function(){if(!this._isDestroyed&&!this._visibility._isHidden){var t=this._element,e=this._dragPlaceholder,i=t.getBoundingClientRect();this._width=i.width,this._height=i.height,this._marginLeft=Math.max(0,ht(t,"margin-left")),this._marginRight=Math.max(0,ht(t,"margin-right")),this._marginTop=Math.max(0,ht(t,"margin-top")),this._marginBottom=Math.max(0,ht(t,"margin-bottom")),e&&e.updateDimensions(this._width,this._height)}},Kt.prototype._refreshSortData=function(){if(!this._isDestroyed){var t,e=this._sortData={},i=this.getGrid()._settings.sortData;for(t in i)e[t]=i[t](this,this._element)}},Kt.prototype._destroy=function(t){if(!this._isDestroyed){var e=this._element,i=this.getGrid(),s=i._settings,n=i._items.indexOf(this);this._release.destroy(),this._migrate.destroy(),this._layout.destroy(),this._visibility.destroy(),this._animate.destroy(),this._animateChild.destroy(),this._dragPlaceholder.destroy(),this._drag&&this._drag.destroy(),e.removeAttribute("style"),this._child.removeAttribute("style"),Rt(e,s.itemClass),n>-1&&i._items.splice(n,1),t&&e.parentNode.removeChild(e),this._isActive=!1,this._isDestroyed=!0}},Qt.prototype.getLayout=function(t,e,i,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),c=this._slotSizes;if(o.slots=s||this._slots,o.width=a?0:d?Math.round(e):e,o.height=a?d?Math.round(i):i:0,o.setWidth=a,o.setHeight=!a,o.slots.length=0,c.length=0,!t.length)return o;for(r=0;rd.height&&(Wt.left>0&&u.push(this._addRect(0,d.height,Wt.left,1/0)),Wt.left+Wt.widthd.width&&(Wt.top>0&&u.push(this._addRect(d.width,0,1/0,Wt.top)),Wt.top+Wt.height.49&&r.height>.49&&(!e&&r.tope.left+e.width&&jt.push(this._addRect(e.left+e.width,t.top,t.left+t.width-(e.left+e.width),t.height)),t.tope.top+e.height&&jt.push(this._addRect(t.left,e.top+e.height,t.width,t.top+t.height-(e.top+e.height))),jt):(jt.push(this._addRect(t.left,t.top,t.width,t.height)),jt)}),Qt.prototype._doRectsOverlap=function(t,e){return!(t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top)},Qt.prototype._isRectWithinRect=function(t,e){return t.left>=e.left&&t.top>=e.top&&t.left+t.width<=e.left+e.width&&t.top+t.height<=e.top+e.height},Qt.prototype._purgeRects=(Ut={},Zt={},function(t){for(var e,i=t.length;i--;)if(e=t.length,t[i])for(this._getRect(t[i],Ut);e--;)if(t[e]&&i!==e&&this._isRectWithinRect(Ut,this._getRect(t[e],Zt))){t[i]=0;break}return t}),Qt.prototype._sortRectsTopLeft=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.tope.top?1:t.lefte.left?1:0}}(),Qt.prototype._sortRectsLeftTop=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.lefte.left?1:t.tope.top?1:0}}();var te="[object HTMLCollection]",ee="[object NodeList]";function ie(t){var e=Object.prototype.toString.call(t);return e===te||e===ee}var se="object",ne="[object Object]",re=Object.prototype.toString;function oe(t){return typeof t===se&&re.call(t)===ne}function he(t){return ie(t)?Array.prototype.slice.call(t):Array.prototype.concat(t)}var ae=new Qt,_e=function(){},le="number",de="string";function ce(e,s){var n,r,o,h=this;if(!((e=this._element=typeof e===de?window.document.querySelector(e):e).getRootNode?e.getRootNode({composed:!0})===document:window.document.body.contains(e))||e===window.document.documentElement)throw new Error("Container element must be an existing DOM element");c((n=this._settings=function(t,e){var i=ue({},t);e&&(i=ue(i,e));return i.visibleStyles=(e||0).visibleStyles||(t||0).visibleStyles,i.hiddenStyles=(e||0).hiddenStyles||(t||0).hiddenStyles,i}(ce.defaultOptions,s)).dragSort)||(n.dragSort=!!n.dragSort),this._id=Jt(),t[this._id]=h,this._isDestroyed=!1,this._layout={id:0,items:[],slots:[],setWidth:!1,setHeight:!1,width:0,height:0},this._emitter=new i,j(e,n.containerClass),this._items=[],typeof(r=n.items)===de?he(e.children).forEach(function(t){("*"===r||W(t,r))&&h._items.push(new Kt(h,t))}):(Array.isArray(r)||ie(r))&&(this._items=he(r).map(function(t){return new Kt(h,t)})),typeof(o=n.layoutOnResize)!==le&&(o=!0===o?0:-1),o>=0&&window.addEventListener("resize",h._resizeHandler=nt(function(){h.refreshItems().layout()},o)),n.layoutOnInit&&this.layout(!0)}function ue(t,e){var i,s,n,r=Object.keys(e),o=r.length;for(n=0;n0)){var s=o._layout.id!==l,n=c(t)?t:i;c(n)&&n(s,_.items.slice(0)),!s&&o._hasListeners(e)&&o._emit(e,_.items.slice(0))}}if((_.setHeight&&typeof _.height===le||_.setWidth&&typeof _.width===le)&&(s="border-box"===a(h,"box-sizing")),_.setHeight&&(typeof _.height===le?h.style.height=(s?_.height+this._borderTop+this._borderBottom:_.height)+"px":h.style.height=_.height),_.setWidth&&(typeof _.width===le?h.style.width=(s?_.width+this._borderLeft+this._borderRight:_.width)+"px":h.style.width=_.width),this._hasListeners("layoutStart")&&this._emit("layoutStart",_.items.slice(0)),!d)return f(),this;for(r=0;rl?1:0:ld?1:0)return c;return c||(s||(s=n(i)),c=r(o,h)),c}function h(o,h){var a=t(o,h);return e&&a&&(a=-a),a||(s||(s=n(i)),r(o,h))}return function(n,r){if(this._isDestroyed||this._items.length<2)return this;var a,_=this._items,l=r||0,d=l.layout?l.layout:void 0===l.layout;if(t=n,e=!!l.descending,i=_.slice(0),s=null,c(t))_.sort(h);else if(typeof t===de)t=n.trim().split(" ").map(function(t){return t.split(":")}),_.sort(o);else{if(!Array.isArray(t))return this;if(t.length!==_.length)throw new Error("[Muuri] sort reference items do not match with grid items.");for(a=0;a<_.length;a++){if(t.indexOf(_[a])<0)throw new Error("[Muuri] sort reference items do not match with grid items.");_[a]=t[a]}e&&_.reverse()}return this._hasListeners("sort")&&this._emit("sort",_.slice(0),i),d&&this.layout("instant"===d,c(d)?d:void 0),this}}(),ce.prototype.move=function(t,e,i){if(this._isDestroyed||this._items.length<2)return this;var s,n,r=this._items,o=i||0,h=o.layout?o.layout:void 0===o.layout,a="swap"===o.action,_=a?"swap":"move",l=this._getItem(t),d=this._getItem(e);return l&&d&&l!==d&&(s=r.indexOf(l),n=r.indexOf(d),a?Q(r,s,n):K(r,s,n),this._hasListeners("move")&&this._emit("move",{item:l,fromIndex:s,toIndex:n,action:_}),h&&this.layout("instant"===h,c(h)?h:void 0)),this},ce.prototype.send=function(t,e,i,s){if(this._isDestroyed||e._isDestroyed||this===e)return this;if(!(t=this._getItem(t)))return this;var n=s||0,r=n.appendTo||window.document.body,o=n.layoutSender?n.layoutSender:void 0===n.layoutSender,h=n.layoutReceiver?n.layoutReceiver:void 0===n.layoutReceiver;return t._migrate.start(e,i,r),t._migrate._isActive&&t._isActive&&(o&&this.layout("instant"===o,c(o)?o:void 0),h&&e.layout("instant"===h,c(h)?h:void 0)),this},ce.prototype.destroy=function(e){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-1?t:this._items.length+t]||null;if(t instanceof Kt)return t._gridId===this._id?t:null;for(var e=0;e 0 ? matchIndex : -1) : 0; + matchScore = sortThreshold; } // Check if the best match overlaps enough to justify a placement switch. if (matchScore >= sortThreshold) { returnData.grid = grid; returnData.index = matchIndex; - returnData.action = sortAction; + returnData.action = isMigration ? sortMigrateAction : sortAction; return returnData; } @@ -772,6 +782,7 @@ ItemDrag.prototype._checkOverlap = function() { } // If the item was moved to another grid. + // TODO: Support "swap" action! else { this._hBlockedIndex = null; From 7604c85092f76a82d8db79c44afb0337837ee317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20R=C3=A4m=C3=B6?= Date: Sat, 20 Jul 2019 10:07:52 +0300 Subject: [PATCH 003/120] Add an example to README how to drag sort only on release. --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index f10b7b51..0b582a0d 100644 --- a/README.md +++ b/README.md @@ -805,6 +805,17 @@ var grid = new Muuri(elem, { }); ``` +```javascript +// Pro tip: If you want drag sorting happening only on release set a really +// long sortInterval. A bit of a hack, but works. +var grid = new Muuri(elem, { + dragEnabled: true, + dragSortHeuristics: { + sortInterval: 3600000 // 1 hour + } +}); +``` + ### dragSortPredicate   Defines the logic for the sort procedure during dragging an item. From 1def259b00a379b35fad5b969ef05abd240a548e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20R=C3=A4m=C3=B6?= Date: Sat, 20 Jul 2019 12:23:51 +0300 Subject: [PATCH 004/120] Support swap action when dragging item between grids. --- README.md | 11 ++++++++--- dist/muuri.js | 23 ++++++++++++++++++++++- dist/muuri.min.js | 2 +- src/Grid/Grid.js | 1 + src/Item/ItemDrag.js | 22 +++++++++++++++++++++- 5 files changed, 53 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0b582a0d..bde5c2fa 100644 --- a/README.md +++ b/README.md @@ -220,7 +220,8 @@ The default options are stored in `Muuri.defaultOptions` object, which in it's d }, dragSortPredicate: { threshold: 50, - action: actionMove + action: 'move', + migrateAction: 'move' }, dragReleaseDuration: 300, dragReleaseEasing: 'ease', @@ -820,14 +821,18 @@ var grid = new Muuri(elem, { Defines the logic for the sort procedure during dragging an item. -* Default value: `{action: 'move', threshold: 50}`. +* Default value: `{action: 'move', migrateAction: 'move', threshold: 50}`. * Accepted types: function, object. If an object is provided the default sort predicate handler will be used. You can define the following properties: * **action**  —  *string* * Default value: `'move'`. * Allowed values: `'move'`, `'swap'`. - * Should the dragged item be *moved* to the new position or should it *swap* places with the item it overlaps? + * Should the dragged item be *moved* to the new position or should it *swap* places with the item it overlaps when the drag occurs within the same grid? +* **migrateAction**  —  *string* + * Default value: `'move'`. + * Allowed values: `'move'`, `'swap'`. + * Should the dragged item be *moved* to the new position or should it *swap* places with the item it overlaps when the dragged item is moved to another grid? * **threshold**  —  *number* * Default value: `50`. * Allowed values: `1` - `100`. diff --git a/dist/muuri.js b/dist/muuri.js index 30d1b1b6..03915d56 100644 --- a/dist/muuri.js +++ b/dist/muuri.js @@ -2442,6 +2442,7 @@ var currentIndex; var targetGrid; var targetIndex; + var targetItem; var sortAction; var isMigration; @@ -2496,10 +2497,12 @@ } // If the item was moved to another grid. - // TODO: Support "swap" action! else { this._hBlockedIndex = null; + // Let's fetch the target item when it's still in it's original index. + targetItem = targetGrid._items[targetIndex]; + // Emit beforeSend event. if (currentGrid._hasListeners(eventBeforeSend)) { currentGrid._emit(eventBeforeSend, { @@ -2559,6 +2562,23 @@ }); } + // If the sort action is "swap" let's respect it and send the target item + // (if it exists) from the target grid to the originating grid. This process + // is done on purpose after the dragged item placed within the target grid + // so that we can keep this implementation as simple as possible utilizing + // the existing API. + if (sortAction === actionSwap && targetItem && targetItem.isActive()) { + // Sanity check to make sure that the target item is still part of the + // target grid. It could have been manipulated in the event handlers. + if (targetGrid._items.indexOf(targetItem) > -1) { + targetGrid.send(targetItem, currentGrid, currentIndex, { + appendTo: this._container || window.document.body, + layoutSender: false, + layoutReceiver: false + }); + } + } + // Layout both grids. currentGrid.layout(); targetGrid.layout(); @@ -5412,6 +5432,7 @@ * @param {(Function|Object)} [options.dragSortPredicate] * @param {Number} [options.dragSortPredicate.threshold=50] * @param {String} [options.dragSortPredicate.action="move"] + * @param {String} [options.dragSortPredicate.migrateAction="move"] * @param {Number} [options.dragReleaseDuration=300] * @param {String} [options.dragReleaseEasing="ease"] * @param {Object} [options.dragCssProps] diff --git a/dist/muuri.min.js b/dist/muuri.min.js index 58ce5149..4809c37e 100644 --- a/dist/muuri.min.js +++ b/dist/muuri.min.js @@ -14,4 +14,4 @@ * Copyright (c) 2018-present, Niklas Rämö * @license MIT */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Muuri=e()}(this,function(){"use strict";var t={},e="layoutEnd";function i(){this._events={},this._queue=[],this._counter=0,this._isDestroyed=!1}i.prototype.on=function(t,e){if(this._isDestroyed)return this;var i=this._events[t];return i||(i=this._events[t]=[]),i.push(e),this},i.prototype.off=function(t,e){if(this._isDestroyed)return this;var i=this._events[t];if(!i||!i.length)return this;if(!e)return i.length=0,this;for(var s=i.length;s--;)e===i[s]&&i.splice(s,1);return this},i.prototype.emit=function(t,e,i,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-1||(M._activeInstances.push(t),M._emitter.on(D,t._onMove),M._emitter.on(A,t._onCancel),M._emitter.on(b,t._onEnd),1===M._activeInstances.length&&M._bindListeners())},M._deactivateInstance=function(t){var e=M._activeInstances.indexOf(t);-1!==e&&(M._activeInstances.splice(e,1),M._emitter.off(D,t._onMove),M._emitter.off(A,t._onCancel),M._emitter.off(b,t._onEnd),M._activeInstances.length||M._unbindListeners())},M._bindListeners=function(){var t=M._events;window.addEventListener(t.move,M._onMove,R),window.addEventListener(t.end,M._onEnd,R),t.cancel&&window.addEventListener(t.cancel,M._onCancel,R)},M._unbindListeners=function(){var t=M._events;window.removeEventListener(t.move,M._onMove,R),window.removeEventListener(t.end,M._onEnd,R),t.cancel&&window.removeEventListener(t.cancel,M._onCancel,R)},M._getEventPointerId=function(t){return"number"==typeof t.pointerId?t.pointerId:t.changedTouches?t.changedTouches[0]?t.changedTouches[0].identifier:null:1},M._getTouchById=function(t,e){if("number"==typeof t.pointerId)return t.pointerId===e?t:null;if(t.changedTouches){for(var i=0;i-1&&(this._queue[n]=void 0),s?this._queue.unshift(t):this._queue.push(t),this._reads[t]=e,this._writes[t]=i,this._nextStep||(this._nextStep=y(this._step))},T.prototype.cancel=function(t){var e=this._queue.indexOf(t);e>-1&&(this._queue[e]=void 0,delete this._reads[t],delete this._writes[t])},T.prototype._step=function(){var t,e,i=this._queue,s=this._reads,n=this._writes,r=this._batch,o=this._batchReads,h=this._batchWrites,a=i.length;for(this._nextStep=null,e=0;en?n:e<0?Math.max(n+e+1,0):e}function K(t,e,i){if(!(t.length<2)){var s=J(t,e),n=J(t,i);s!==n&&t.splice(n,0,t.splice(s,1)[0])}}function Q(t,e,i){if(!(t.length<2)){var s,n=J(t,e),r=J(t,i);n!==r&&(s=t[n],t[n]=t[r],t[r]=s)}}var tt="cancel",et="finish",it="debounce",st=0;function nt(t,e){var i,s=++st+it;return e>0?function(n){void 0!==i&&(i=window.clearTimeout(i),k.cancel(s),n===et&&t()),n!==tt&&n!==et&&(i=window.setTimeout(function(){i=void 0,k.add(s,t,null,!0)},e))}:function(e){e!==tt&&t()}}function rt(t){var e=a(t,"transform");if(!e||"none"===e)return!1;var i=a(t,"display");return"inline"!==i&&"none"!==i}function ot(t,e){for(var i=window.document,s=(e?t:t.parentElement)||i;s&&s!==i&&"static"===a(s,"position")&&!rt(s);)s=s.parentElement||i;return s}function ht(t,e){return parseFloat(a(t,e))||0}var at={},_t={},lt={};function dt(t,e){var i,s=e||{};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:(i=t.getBoundingClientRect(),s.left+=i.left,s.top+=i.top,s.left+=ht(t,"border-left-width"),s.top+=ht(t,"border-top-width"),s))}function ct(t,e,i){return lt.left=0,lt.top=0,t===e?lt:i&&(t=ot(t,!0))===(e=ot(e,!0))?lt:(dt(t,at),dt(e,_t),lt.left=_t.left-at.left,lt.top=_t.top-at.top,lt)}var ut="overflow",ft="overflow-x",pt="overflow-y",mt="auto",gt="scroll";function yt(t){var e=a(t,ut);return e===mt||e===gt||((e=a(t,ft))===mt||e===gt||((e=a(t,pt))===mt||e===gt))}function vt(t,e,i){for(var s=i||[],n=e?t:t.parentNode;n&&n!==document;)n.getRootNode&&n instanceof DocumentFragment?n=n.getRootNode().host:(yt(n)&&s.push(n),n=n.parentNode);return s.push(window),s}var wt={},St="transform",Dt="none",bt=/^matrix3d/,At=/([^,]*,){4}/,Et=/([^,]*,){12}/,Ct=/[^,]*,/;function Lt(t){wt.x=0,wt.y=0;var e=a(t,St);if(!e||e===Dt)return wt;var i=bt.test(e),s=e.replace(i?Et:At,""),n=s.replace(Ct,"");return wt.x=parseFloat(s)||0,wt.y=parseFloat(n)||0,wt}function It(t,e){return"translateX("+t+"px) translateY("+e+"px)"}function Rt(t,e){t.classList?t.classList.remove(e):W(t,"."+e)&&(t.className=(" "+t.className+" ").replace(" "+e+" "," ").trim())}var xt,Pt,Mt,Tt,kt=0;function Xt(t){var e=t._element,i=t.getGrid(),s=i._settings;this._item=t,this._gridId=i._id,this._isDestroyed=!1,this._isMigrating=!1,this._startPredicate=c(s.dragStartPredicate)?s.dragStartPredicate:Xt.defaultStartPredicate,this._startPredicateState=kt,this._startPredicateResult=void 0,this._hBlockedIndex=null,this._hX1=0,this._hX2=0,this._hY1=0,this._hY2=0,this._reset(),this._preStartCheck=this._preStartCheck.bind(this),this._preEndCheck=this._preEndCheck.bind(this),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);var n=s.dragSortHeuristics.sortInterval;this._checkOverlapDebounce=nt(this._checkOverlap,n),this._dragger=new M(e,s.dragCssProps),this._dragger.on("start",this._preStartCheck),this._dragger.on("move",this._preStartCheck),this._dragger.on("cancel",this._preEndCheck),this._dragger.on("end",this._preEndCheck)}function Yt(t,e){return t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top?0:(Math.min(t.left+t.width,e.left+e.width)-Math.max(t.left,e.left))*(Math.min(t.top+t.height,e.top+e.height)-Math.max(t.top,e.top))/(Math.min(t.width,e.width)*Math.min(t.height,e.height))*100}function Gt(t){this._item=t,this._animate=new p,this._element=null,this._className="",this._didMigrate=!1,this._resetAfterLayout=!1,this._currentLeft=0,this._currentTop=0,this._nextLeft=0,this._nextTop=0,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this),this._onLayoutStart=this._onLayoutStart.bind(this),this._onLayoutEnd=this._onLayoutEnd.bind(this),this._onReleaseEnd=this._onReleaseEnd.bind(this),this._onMigrate=this._onMigrate.bind(this)}function Ht(){this._queue=[],this._isDestroyed=!1}function Ot(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 Ht,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this)}Xt.defaultStartPredicate=function(t,e,i){var s=t._drag,n=s._startPredicateData||s._setupStartPredicate(i);if(!e.isFinal)return!(!n.handleElement&&(n.handleElement=s._getStartPredicateHandle(e),!n.handleElement))&&(n.delay&&(n.event=e,n.delayTimer||(n.delayTimer=window.setTimeout(function(){n.delay=0,s._resolveStartPredicate(n.event)&&(s._forceResolveStartPredicate(n.event),s._resetStartPredicate())},n.delay))),s._resolveStartPredicate(e));s._finishStartPredicate(e)},Xt.defaultSortPredicate=(xt={},Pt={},Mt={},Tt=[],function(t,e){var i=t._drag,s=i._getGrid(),n=e&&"number"==typeof e.threshold?e.threshold:50,r=e&&"swap"===e.action?"swap":"move",o=e&&"swap"===e.migrateAction?"swap":"move";xt.width=t._width,xt.height=t._height,xt.left=i._elementClientX,xt.top=i._elementClientY;var h=function(t,e,i){var s,n,r,o,h=null,a=e._settings.dragSort,_=-1;if(!0===a?(Tt[0]=e,n=Tt):n=a.call(e,t),!Array.isArray(n))return h;for(o=0;oi&&s>_&&(_=s,h=r));return Tt.length=0,h}(t,s,n);if(!h)return!1;var a,_,l,d,c,u=t.getGrid()!==h,f=0,p=0,m=-1;for(h===s?(xt.left=i._gridX+t._marginLeft,xt.top=i._gridY+t._marginTop):(h._updateBorders(1,0,1,0),f=h._left+h._borderLeft,p=h._top+h._borderTop),c=0;cm&&(a=c,m=d));return m0?a:-1:0,m=n),m>=n&&(Mt.grid=h,Mt.index=a,Mt.action=u?o:r,Mt)}),Xt.prototype.stop=function(){var t=this._item,e=t._element,i=this._getGrid();return this._isActive?this._isMigrating?(this._finishMigration(),this):(N(t._id),q(t._id),this._unbindScrollListeners(),this._checkOverlapDebounce("cancel"),e.parentNode!==i._element&&(i._element.appendChild(e),e.style[n]=It(this._gridX,this._gridY)),Rt(e,i._settings.itemDraggingClass),this._reset(),this):this},Xt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(),this._dragger.destroy(),this._isDestroyed=!0,this)},Xt.prototype._getGrid=function(){return t[this._gridId]||null},Xt.prototype._reset=function(){this._isActive=!1,this._container=null,this._containingBlock=null,this._dragEvent=null,this._scrollEvent=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},Xt.prototype._bindScrollListeners=function(){var t,e,i=this._getGrid()._element,s=this._container,n=this._scrollers;if(n.length=0,vt(this._item._element,!1,n),s!==i)for(vt(i,!0,t=[]),e=0;e=s&&t.pageX=n&&t.pageY3&&e.minBounceBackAngle>0;if(h||(this._hBlockedIndex=null),Math.abs(r)>i||Math.abs(o)>i){if(h){var a=Math.atan2(r,o),_=Math.atan2(this._hX2-this._hX1,this._hY2-this._hY1),l=Math.atan2(Math.sin(a-_),Math.cos(a-_));Math.abs(l)>e.minBounceBackAngle&&(this._hBlockedIndex=null)}return this._hX1=this._hX2,this._hY1=this._hY2,this._hX2=s,this._hY2=n,!0}return!1},Xt.prototype._resetStartPredicate=function(){var t=this._startPredicateData;t&&(t.delayTimer&&(t.delayTimer=window.clearTimeout(t.delayTimer)),this._startPredicateData=null)},Xt.prototype._checkOverlap=function(){if(this._isActive){var t,e,i,s,n,r,o,h=this._item,a=this._getGrid()._settings;(t=c(a.dragSortPredicate)?a.dragSortPredicate(h,this._dragEvent):Xt.defaultSortPredicate(h,a.dragSortPredicate))&&"number"==typeof t.index&&(o=(e=h.getGrid())!==(s=t.grid||e),i=e._items.indexOf(h),n=J(s._items,t.index,o),r="swap"===t.action?"swap":"move",(o||n!==this._hBlockedIndex)&&(o?(this._hBlockedIndex=null,e._hasListeners("beforeSend")&&e._emit("beforeSend",{item:h,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("beforeReceive")&&s._emit("beforeReceive",{item:h,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),h._gridId=s._id,this._isMigrating=h._gridId!==this._gridId,e._items.splice(i,1),$(s._items,h,n),h._sortData=null,e._hasListeners("send")&&e._emit("send",{item:h,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("receive")&&s._emit("receive",{item:h,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),e.layout(),s.layout()):i!==n&&(this._hBlockedIndex=i,("swap"===r?Q:K)(e._items,i,n),e._hasListeners("move")&&e._emit("move",{item:h,fromIndex:i,toIndex:n,action:r}),e.layout())))}},Xt.prototype._finishMigration=function(){var t,e,i=this._item,s=i._release,r=i._element,o=i._isActive,h=i.getGrid(),a=h._element,_=h._settings,l=_.dragContainer||a,d=this._getGrid()._settings,c=r.parentNode;this._isMigrating=!1,this.destroy(),Rt(r,d.itemClass),Rt(r,d.itemVisibleClass),Rt(r,d.itemHiddenClass),j(r,_.itemClass),j(r,o?_.itemVisibleClass:_.itemHiddenClass),l!==c&&(l.appendChild(r),e=ct(c,l,!0),(t=Lt(r)).x-=e.left,t.y-=e.top),i._refreshDimensions(),i._refreshSortData(),e=ct(l,a,!0),s._containerDiffX=e.left,s._containerDiffY=e.top,i._drag=_.dragEnabled?new Xt(i):null,l!==c&&(r.style[n]=It(t.x,t.y)),i._child.removeAttribute("style"),f(i._child,o?_.visibleStyles:_.hiddenStyles),s.start()},Xt.prototype._preStartCheck=function(t){this._startPredicateState===kt&&(this._startPredicateState=1),1===this._startPredicateState?(this._startPredicateResult=this._startPredicate(this._item,t),!0===this._startPredicateResult?(this._startPredicateState=2,this._onStart(t)):!1===this._startPredicateResult&&(this._startPredicateState=3)):2===this._startPredicateState&&this._isActive&&this._onMove(t)},Xt.prototype._preEndCheck=function(t){var e=2===this._startPredicateState;this._startPredicate(this._item,t),this._startPredicateState=kt,e&&this._isActive&&this._onEnd(t)},Xt.prototype._onStart=function(t){var e=this._item;if(e._isActive){var i,s=e._element,r=this._getGrid(),o=r._settings,h=e._release,a=e._migrate,_=r._element,l=o.dragContainer||_,d=ot(l,!0),c=Lt(s),u=c.x,f=c.y,p=s.getBoundingClientRect(),m=l!==_;this._resetHeuristics(t),m&&(i=ct(d,_)),e.isPositioning()&&e._layout.stop(!0,{transform:It(u,f)}),a._isActive&&(u-=a._containerDiffX,f-=a._containerDiffY,a.stop(!0,{transform:It(u,f)})),e.isReleasing()&&h._reset(),this._isActive=!0,this._dragEvent=t,this._container=l,this._containingBlock=d,this._elementClientX=p.left,this._elementClientY=p.top,this._left=this._gridX=u,this._top=this._gridY=f,o.dragPlaceholder.enabled&&e._dragPlaceholder.create(),r._emit("dragInit",e,t),m&&(this._containerDiffX=i.left,this._containerDiffY=i.top,s.parentNode===l?(this._gridX=u-this._containerDiffX,this._gridY=f-this._containerDiffY):(this._left=u+this._containerDiffX,this._top=f+this._containerDiffY,l.appendChild(s),s.style[n]=It(this._left,this._top))),j(s,o.itemDraggingClass),this._bindScrollListeners(),r._emit("dragStart",e,t)}},Xt.prototype._onMove=function(t){var e=this._item;if(e._isActive){var i,s,n,r=this._getGrid()._settings.dragAxis;if("y"!==r){var o=t.clientX-this._dragEvent.clientX;this._left+=o,this._gridX+=o,this._elementClientX+=o}if("x"!==r){var h=t.clientY-this._dragEvent.clientY;this._top+=h,this._gridY+=h,this._elementClientY+=h}this._dragEvent=t,i=e._id,s=this._prepareMove,n=this._applyMove,k.add(i+G,s,n,!0)}else this.stop()},Xt.prototype._prepareMove=function(){this._item._isActive&&this._getGrid()._settings.dragSort&&this._checkHeuristics(this._dragEvent)&&this._checkOverlapDebounce()},Xt.prototype._applyMove=function(){var t=this._item;t._isActive&&(t._element.style[n]=It(this._left,this._top),this._getGrid()._emit("dragMove",t,this._dragEvent))},Xt.prototype._onScroll=function(t){var e,i,s,n=this._item;n._isActive?(this._scrollEvent=t,e=n._id,i=this._prepareScroll,s=this._applyScroll,k.add(e+H,i,s,!0)):this.stop()},Xt.prototype._prepareScroll=function(){var t=this._item;if(t._isActive){var e,i=t._element,s=this._getGrid(),n=s._settings,r=n.dragAxis,o=s._element,h=i.getBoundingClientRect(),a=this._elementClientX-h.left,_=this._elementClientY-h.top;this._container!==o&&(e=ct(this._containingBlock,o),this._containerDiffX=e.left,this._containerDiffY=e.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()}},Xt.prototype._applyScroll=function(){var t=this._item;t._isActive&&(t._element.style[n]=It(this._left,this._top),this._getGrid()._emit("dragScroll",t,this._scrollEvent))},Xt.prototype._onEnd=function(t){var e=this._item,i=e._element,s=this._getGrid(),n=s._settings,r=e._release;e._isActive?(N(e._id),q(e._id),n.dragSort&&this._checkOverlapDebounce("finish"),this._unbindScrollListeners(),r._containerDiffX=this._containerDiffX,r._containerDiffY=this._containerDiffY,this._reset(),Rt(i,n.itemDraggingClass),s._emit("dragEnd",e,t),this._isMigrating?this._finishMigration():r.start()):this.stop()},Gt.prototype._onLayoutStart=function(){var t=this._item,e=t.getGrid(),i=e._items.indexOf(t),s=e._layout.slots[2*i],n=e._layout.slots[2*i+1];if(this._didMigrate||t._left!==s||t._top!==n){var r,o,h;if(s+=t._marginLeft,n+=t._marginTop,!(e._settings.dragPlaceholder.duration>0)||this._didMigrate){F(t._id);var a={transform:It(s,n)};return this._animate.isAnimating()?this._animate.stop(a):f(this._element,a),void(this._didMigrate&&(e.getElement().appendChild(this._element),this._didMigrate=!1))}this._nextLeft=s,this._nextTop=n,r=t._id,o=this._setupAnimation,h=this._startAnimation,k.add(r+O,o,h)}},Gt.prototype._setupAnimation=function(){if(this.isActive()){var t=Lt(this._element);this._currentLeft=t.x,this._currentTop=t.y}},Gt.prototype._startAnimation=function(){if(this.isActive()){var t=this._animate,e=this._currentLeft,i=this._currentTop,s=this._nextLeft,n=this._nextTop,r={transform:It(s,n)};if(e!==s||i!==n){var o=this._item.getGrid()._settings.dragPlaceholder,h={transform:It(e,i)};t.start(h,r,{duration:o.duration,easing:o.easing,onFinish:this._onLayoutEnd})}else t.isAnimating()&&t.stop(r)}},Gt.prototype._onLayoutEnd=function(){this._resetAfterLayout&&this.reset()},Gt.prototype._onReleaseEnd=function(t){if(t._id===this._item._id){if(!this._animate.isAnimating())return void this.reset();this._resetAfterLayout=!0}},Gt.prototype._onMigrate=function(t){if(t.item===this._item){var e=this._item.getGrid(),i=t.toGrid;e.off("dragReleaseEnd",this._onReleaseEnd),e.off("layoutStart",this._onLayoutStart),e.off("beforeSend",this._onMigrate),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("layoutStart",this._onLayoutStart),i.on("beforeSend",this._onMigrate),this._didMigrate=!0}},Gt.prototype.create=function(){if(this.isActive())this._resetAfterLayout=!1;else{var t,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;t=c(s.dragPlaceholder.createElement)?s.dragPlaceholder.createElement(e):window.document.createElement("div"),this._element=t,n._element=t,this._className=s.itemPlaceholderClass||"",this._className&&j(t,this._className);var r=e._left+e._marginLeft,o=e._top+e._marginTop;f(t,{display:"block",position:"absolute",left:"0",top:"0",width:e._width+"px",height:e._height+"px",transform:It(r,o)}),i.on("layoutStart",this._onLayoutStart),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("beforeSend",this._onMigrate),c(s.dragPlaceholder.onCreate)&&s.dragPlaceholder.onCreate(e,t),i.getElement().appendChild(t)}},Gt.prototype.reset=function(){if(this.isActive()){var t=this._element,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;this._resetAfterLayout=!1,F(e._id),n.stop(),n._element=null,i.off("dragReleaseEnd",this._onReleaseEnd),i.off("layoutStart",this._onLayoutStart),i.off("beforeSend",this._onMigrate),this._className&&(Rt(t,this._className),this._className=""),t.parentNode.removeChild(t),this._element=null,c(s.dragPlaceholder.onRemove)&&s.dragPlaceholder.onRemove(e,t)}},Gt.prototype.updateDimensions=function(t,e){this.isActive()&&f(this._element,{width:t+"px",height:e+"px"})},Gt.prototype.isActive=function(){return!!this._element},Gt.prototype.destroy=function(){this.reset(),this._animate.destroy(),this._item=this._animate=null},Ht.prototype.add=function(t){return this._isDestroyed?this:(this._queue.push(t),this)},Ht.prototype.flush=function(t,e){if(this._isDestroyed)return this;var i,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,e),this;for(i=0;i0;return l&&this._queue.flush(!0,o),d&&(a._isPositioningStarted=!0),c(e)&&this._queue.add(e),m?(this._isActive=!0,this._animateOptions.easing=p,this._animateOptions.duration=u,this._isInterrupted=l,s=o._id,n=this._setupAnimation,r=this._startAnimation,k.add(s+X,n,r),this):(this._updateOffsets(),this._updateTargetStyles(),i=o._animate.isAnimating(),this.stop(!1,this._targetStyles),!i&&f(h,this._targetStyles),this._skipNextAnimation=!1,this._finish())}},Ot.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item;return i=s._id,k.cancel(i+X),s._animate.stop(e),Rt(s._element,s.getGrid()._settings.itemPositioningClass),this._isActive=!1,t&&this._queue.flush(!0,s),this},Ot.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)},Ot.prototype._updateOffsets=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._offsetLeft=i._isActive?i._containerDiffX:e._isActive?e._containerDiffX:0,this._offsetTop=i._isActive?i._containerDiffY:e._isActive?e._containerDiffY:0}},Ot.prototype._updateTargetStyles=function(){this._isDestroyed||(this._targetStyles.transform=It(this._item._left+this._offsetLeft,this._item._top+this._offsetTop))},Ot.prototype._finish=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._isActive&&(this._isActive=!1,Rt(t._element,t.getGrid()._settings.itemPositioningClass)),i._isActive&&i.stop(),e._isActive&&e.stop(),this._queue.flush(!1,t)}},Ot.prototype._setupAnimation=function(){var t=Lt(this._item._element);this._currentLeft=t.x,this._currentTop=t.y},Ot.prototype._startAnimation=function(){var t=this._item,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||j(t._element,e.itemPositioningClass),this._currentStyles.transform=It(this._currentLeft,this._currentTop),t._animate.start(this._currentStyles,this._targetStyles,this._animateOptions)};var Bt={};function Nt(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._container=!1,this._containerDiffX=0,this._containerDiffY=0}Nt.prototype.start=function(t,e,i){if(this._isDestroyed)return this;var s,r,o,h,a,_,l,d,c=this._item,u=c._element,p=c.isVisible(),m=c.getGrid(),g=m._settings,y=t._settings,v=t._element,w=t._items,S=m._items.indexOf(c),D=i||window.document.body;if("number"==typeof e)s=J(w,e,!0);else{if(!(r=t._getItem(e)))return this;s=w.indexOf(r)}return(c.isPositioning()||this._isActive||c.isReleasing())&&(l=(_=Lt(u)).x,d=_.y),c.isPositioning()&&c._layout.stop(!0,{transform:It(l,d)}),this._isActive&&(l-=this._containerDiffX,d-=this._containerDiffY,this.stop(!0,{transform:It(l,d)})),c.isReleasing()&&(l-=c._release._containerDiffX,d-=c._release._containerDiffY,c._release.stop(!0,{transform:It(l,d)})),c._visibility._stopAnimation(),c._drag&&c._drag.destroy(),c._visibility._queue.flush(!0,c),m._hasListeners("beforeSend")&&m._emit("beforeSend",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("beforeReceive")&&t._emit("beforeReceive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),Rt(u,g.itemClass),Rt(u,g.itemVisibleClass),Rt(u,g.itemHiddenClass),j(u,y.itemClass),j(u,p?y.itemVisibleClass:y.itemHiddenClass),m._items.splice(S,1),$(w,c,s),c._gridId=t._id,D!==(o=u.parentNode)&&(D.appendChild(u),h=ct(D,o,!0),_||(l=(_=Lt(u)).x,d=_.y),u.style[n]=It(l+h.left,d+h.top)),c._child.removeAttribute("style"),f(c._child,p?y.visibleStyles:y.hiddenStyles),u.style.display=p?"block":"hidden",a=ct(D,v,!0),c._refreshDimensions(),c._refreshSortData(),c._drag=y.dragEnabled?new Xt(c):null,this._isActive=!0,this._container=D,this._containerDiffX=a.left,this._containerDiffY=a.top,m._hasListeners("send")&&m._emit("send",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("receive")&&t._emit("receive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),this},Nt.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid()._element;return this._container!==r&&(e||(t?(i=Lt(n),Bt.transform=It(i.x-this._containerDiffX,i.y-this._containerDiffY)):Bt.transform=It(s._left,s._top),e=Bt),r.appendChild(n),f(n,e)),this._isActive=!1,this._container=null,this._containerDiffX=0,this._containerDiffY=0,this},Nt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)};var qt={};function Ft(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0}function zt(t){var e=t._isActive,i=t._element,s=t.getGrid()._settings;this._item=t,this._isDestroyed=!1,this._isHidden=!e,this._isHiding=!1,this._isShowing=!1,this._queue=new Ht,this._finishShow=this._finishShow.bind(this),this._finishHide=this._finishHide.bind(this),i.style.display=e?"block":"none",j(i,e?s.itemVisibleClass:s.itemHiddenClass),f(t._child,e?s.visibleStyles:s.hiddenStyles)}Ft.prototype.start=function(){if(this._isDestroyed||this._isActive)return this;var t=this._item,e=t.getGrid();return this._isActive=!0,j(t._element,e._settings.itemReleasingClass),e._emit("dragReleaseStart",t),t._layout.start(!1),this},Ft.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid(),o=r._element;return this._reset(),n.parentNode!==o&&(e||(t?(i=Lt(n),qt.transform=It(i.x-this._containerDiffX,i.y-this._containerDiffY)):qt.transform=It(s._left,s._top),e=qt),o.appendChild(n),f(n,e)),t||r._emit("dragReleaseEnd",s),this},Ft.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)},Ft.prototype._reset=function(){if(!this._isDestroyed){var t=this._item;this._isActive=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0,Rt(t._element,t.getGrid()._settings.itemReleasingClass)}},zt.prototype.show=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return this._isShowing||this._isHidden?this._isShowing&&!t?(r&&n.add(r),this):(this._isShowing||(n.flush(!0,i),Rt(s,o.itemHiddenClass),j(s,o.itemVisibleClass),this._isHiding||(s.style.display="block")),r&&n.add(r),i._isActive=this._isShowing=!0,this._isHiding=this._isHidden=!1,this._startAnimation(!0,t,this._finishShow),this):(r&&r(!1,i),this)},zt.prototype.hide=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return!this._isHiding&&this._isHidden?(r&&r(!1,i),this):this._isHiding&&!t?(r&&n.add(r),this):(this._isHiding||(n.flush(!0,i),j(s,o.itemHiddenClass),Rt(s,o.itemVisibleClass)),r&&n.add(r),this._isHidden=this._isHiding=!0,i._isActive=this._isShowing=!1,this._startAnimation(!1,t,this._finishHide),this)},zt.prototype.destroy=function(){if(this._isDestroyed)return this;var t=this._item,e=t._element,i=t.getGrid(),s=this._queue,n=i._settings;return this._stopAnimation({}),s.flush(!0,t).destroy(),Rt(e,n.itemVisibleClass),Rt(e,n.itemHiddenClass),this._item=null,this._isHiding=this._isShowing=!1,this._isDestroyed=this._isHidden=!0,this},zt.prototype._startAnimation=function(t,e,i){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,_=(t?r.showEasing:r.hideEasing)||"ease",d=e||h<=0;if(o){if(B(n._id),d)return n._animateChild.isAnimating()?n._animateChild.stop(o):f(n._child,o),void(i&&i());var c,u,p;c=n._id,u=function(){s=function(t,e){var i={};for(var s in e)i[s]=a(t,l(s));return i}(n._child,o)},p=function(){n._animateChild.start(s,o,{duration:h,easing:_,onFinish:i})},k.add(c+Y,u,p)}else i&&i()}},zt.prototype._stopAnimation=function(t){if(!this._isDestroyed){var e=this._item;B(e._id),e._animateChild.stop(t)}},zt.prototype._finishShow=function(){this._isHidden||(this._isShowing=!1,this._queue.flush(!1,this._item))};var Vt={};zt.prototype._finishHide=function(){if(this._isHidden){var t=this._item;this._isHiding=!1,Vt.transform=It(0,0),t._layout.stop(!0,Vt),t._element.style.display="none",this._queue.flush(!1,t)}};var Wt,jt,Ut,Zt,$t=0;function Jt(){return++$t}function Kt(t,e,i){var s=t._settings;this._id=Jt(),this._gridId=t._id,this._isDestroyed=!1,this._left=0,this._top=0,this._element=e,this._child=e.children[0],e.parentNode!==t._element&&t._element.appendChild(e),j(e,s.itemClass),"boolean"!=typeof i&&(i="none"!==a(e,"display")),this._isActive=i,e.style.left="0",e.style.top="0",e.style[n]=It(0,0),this._animate=new p(e),this._animateChild=new p(this._child),this._visibility=new zt(this),this._layout=new Ot(this),this._migrate=new Nt(this),this._release=new Ft(this),this._dragPlaceholder=new Gt(this),this._drag=s.dragEnabled?new Xt(this):null,this._refreshDimensions(),this._refreshSortData()}function Qt(){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)}Kt.prototype.getGrid=function(){return t[this._gridId]},Kt.prototype.getElement=function(){return this._element},Kt.prototype.getWidth=function(){return this._width},Kt.prototype.getHeight=function(){return this._height},Kt.prototype.getMargin=function(){return{left:this._marginLeft,right:this._marginRight,top:this._marginTop,bottom:this._marginBottom}},Kt.prototype.getPosition=function(){return{left:this._left,top:this._top}},Kt.prototype.isActive=function(){return this._isActive},Kt.prototype.isVisible=function(){return!!this._visibility&&!this._visibility._isHidden},Kt.prototype.isShowing=function(){return!(!this._visibility||!this._visibility._isShowing)},Kt.prototype.isHiding=function(){return!(!this._visibility||!this._visibility._isHiding)},Kt.prototype.isPositioning=function(){return!(!this._layout||!this._layout._isActive)},Kt.prototype.isDragging=function(){return!(!this._drag||!this._drag._isActive)},Kt.prototype.isReleasing=function(){return!(!this._release||!this._release._isActive)},Kt.prototype.isDestroyed=function(){return this._isDestroyed},Kt.prototype._refreshDimensions=function(){if(!this._isDestroyed&&!this._visibility._isHidden){var t=this._element,e=this._dragPlaceholder,i=t.getBoundingClientRect();this._width=i.width,this._height=i.height,this._marginLeft=Math.max(0,ht(t,"margin-left")),this._marginRight=Math.max(0,ht(t,"margin-right")),this._marginTop=Math.max(0,ht(t,"margin-top")),this._marginBottom=Math.max(0,ht(t,"margin-bottom")),e&&e.updateDimensions(this._width,this._height)}},Kt.prototype._refreshSortData=function(){if(!this._isDestroyed){var t,e=this._sortData={},i=this.getGrid()._settings.sortData;for(t in i)e[t]=i[t](this,this._element)}},Kt.prototype._destroy=function(t){if(!this._isDestroyed){var e=this._element,i=this.getGrid(),s=i._settings,n=i._items.indexOf(this);this._release.destroy(),this._migrate.destroy(),this._layout.destroy(),this._visibility.destroy(),this._animate.destroy(),this._animateChild.destroy(),this._dragPlaceholder.destroy(),this._drag&&this._drag.destroy(),e.removeAttribute("style"),this._child.removeAttribute("style"),Rt(e,s.itemClass),n>-1&&i._items.splice(n,1),t&&e.parentNode.removeChild(e),this._isActive=!1,this._isDestroyed=!0}},Qt.prototype.getLayout=function(t,e,i,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),c=this._slotSizes;if(o.slots=s||this._slots,o.width=a?0:d?Math.round(e):e,o.height=a?d?Math.round(i):i:0,o.setWidth=a,o.setHeight=!a,o.slots.length=0,c.length=0,!t.length)return o;for(r=0;rd.height&&(Wt.left>0&&u.push(this._addRect(0,d.height,Wt.left,1/0)),Wt.left+Wt.widthd.width&&(Wt.top>0&&u.push(this._addRect(d.width,0,1/0,Wt.top)),Wt.top+Wt.height.49&&r.height>.49&&(!e&&r.tope.left+e.width&&jt.push(this._addRect(e.left+e.width,t.top,t.left+t.width-(e.left+e.width),t.height)),t.tope.top+e.height&&jt.push(this._addRect(t.left,e.top+e.height,t.width,t.top+t.height-(e.top+e.height))),jt):(jt.push(this._addRect(t.left,t.top,t.width,t.height)),jt)}),Qt.prototype._doRectsOverlap=function(t,e){return!(t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top)},Qt.prototype._isRectWithinRect=function(t,e){return t.left>=e.left&&t.top>=e.top&&t.left+t.width<=e.left+e.width&&t.top+t.height<=e.top+e.height},Qt.prototype._purgeRects=(Ut={},Zt={},function(t){for(var e,i=t.length;i--;)if(e=t.length,t[i])for(this._getRect(t[i],Ut);e--;)if(t[e]&&i!==e&&this._isRectWithinRect(Ut,this._getRect(t[e],Zt))){t[i]=0;break}return t}),Qt.prototype._sortRectsTopLeft=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.tope.top?1:t.lefte.left?1:0}}(),Qt.prototype._sortRectsLeftTop=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.lefte.left?1:t.tope.top?1:0}}();var te="[object HTMLCollection]",ee="[object NodeList]";function ie(t){var e=Object.prototype.toString.call(t);return e===te||e===ee}var se="object",ne="[object Object]",re=Object.prototype.toString;function oe(t){return typeof t===se&&re.call(t)===ne}function he(t){return ie(t)?Array.prototype.slice.call(t):Array.prototype.concat(t)}var ae=new Qt,_e=function(){},le="number",de="string";function ce(e,s){var n,r,o,h=this;if(!((e=this._element=typeof e===de?window.document.querySelector(e):e).getRootNode?e.getRootNode({composed:!0})===document:window.document.body.contains(e))||e===window.document.documentElement)throw new Error("Container element must be an existing DOM element");c((n=this._settings=function(t,e){var i=ue({},t);e&&(i=ue(i,e));return i.visibleStyles=(e||0).visibleStyles||(t||0).visibleStyles,i.hiddenStyles=(e||0).hiddenStyles||(t||0).hiddenStyles,i}(ce.defaultOptions,s)).dragSort)||(n.dragSort=!!n.dragSort),this._id=Jt(),t[this._id]=h,this._isDestroyed=!1,this._layout={id:0,items:[],slots:[],setWidth:!1,setHeight:!1,width:0,height:0},this._emitter=new i,j(e,n.containerClass),this._items=[],typeof(r=n.items)===de?he(e.children).forEach(function(t){("*"===r||W(t,r))&&h._items.push(new Kt(h,t))}):(Array.isArray(r)||ie(r))&&(this._items=he(r).map(function(t){return new Kt(h,t)})),typeof(o=n.layoutOnResize)!==le&&(o=!0===o?0:-1),o>=0&&window.addEventListener("resize",h._resizeHandler=nt(function(){h.refreshItems().layout()},o)),n.layoutOnInit&&this.layout(!0)}function ue(t,e){var i,s,n,r=Object.keys(e),o=r.length;for(n=0;n0)){var s=o._layout.id!==l,n=c(t)?t:i;c(n)&&n(s,_.items.slice(0)),!s&&o._hasListeners(e)&&o._emit(e,_.items.slice(0))}}if((_.setHeight&&typeof _.height===le||_.setWidth&&typeof _.width===le)&&(s="border-box"===a(h,"box-sizing")),_.setHeight&&(typeof _.height===le?h.style.height=(s?_.height+this._borderTop+this._borderBottom:_.height)+"px":h.style.height=_.height),_.setWidth&&(typeof _.width===le?h.style.width=(s?_.width+this._borderLeft+this._borderRight:_.width)+"px":h.style.width=_.width),this._hasListeners("layoutStart")&&this._emit("layoutStart",_.items.slice(0)),!d)return f(),this;for(r=0;rl?1:0:ld?1:0)return c;return c||(s||(s=n(i)),c=r(o,h)),c}function h(o,h){var a=t(o,h);return e&&a&&(a=-a),a||(s||(s=n(i)),r(o,h))}return function(n,r){if(this._isDestroyed||this._items.length<2)return this;var a,_=this._items,l=r||0,d=l.layout?l.layout:void 0===l.layout;if(t=n,e=!!l.descending,i=_.slice(0),s=null,c(t))_.sort(h);else if(typeof t===de)t=n.trim().split(" ").map(function(t){return t.split(":")}),_.sort(o);else{if(!Array.isArray(t))return this;if(t.length!==_.length)throw new Error("[Muuri] sort reference items do not match with grid items.");for(a=0;a<_.length;a++){if(t.indexOf(_[a])<0)throw new Error("[Muuri] sort reference items do not match with grid items.");_[a]=t[a]}e&&_.reverse()}return this._hasListeners("sort")&&this._emit("sort",_.slice(0),i),d&&this.layout("instant"===d,c(d)?d:void 0),this}}(),ce.prototype.move=function(t,e,i){if(this._isDestroyed||this._items.length<2)return this;var s,n,r=this._items,o=i||0,h=o.layout?o.layout:void 0===o.layout,a="swap"===o.action,_=a?"swap":"move",l=this._getItem(t),d=this._getItem(e);return l&&d&&l!==d&&(s=r.indexOf(l),n=r.indexOf(d),a?Q(r,s,n):K(r,s,n),this._hasListeners("move")&&this._emit("move",{item:l,fromIndex:s,toIndex:n,action:_}),h&&this.layout("instant"===h,c(h)?h:void 0)),this},ce.prototype.send=function(t,e,i,s){if(this._isDestroyed||e._isDestroyed||this===e)return this;if(!(t=this._getItem(t)))return this;var n=s||0,r=n.appendTo||window.document.body,o=n.layoutSender?n.layoutSender:void 0===n.layoutSender,h=n.layoutReceiver?n.layoutReceiver:void 0===n.layoutReceiver;return t._migrate.start(e,i,r),t._migrate._isActive&&t._isActive&&(o&&this.layout("instant"===o,c(o)?o:void 0),h&&e.layout("instant"===h,c(h)?h:void 0)),this},ce.prototype.destroy=function(e){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-1?t:this._items.length+t]||null;if(t instanceof Kt)return t._gridId===this._id?t:null;for(var e=0;e-1||(M._activeInstances.push(t),M._emitter.on(D,t._onMove),M._emitter.on(A,t._onCancel),M._emitter.on(b,t._onEnd),1===M._activeInstances.length&&M._bindListeners())},M._deactivateInstance=function(t){var e=M._activeInstances.indexOf(t);-1!==e&&(M._activeInstances.splice(e,1),M._emitter.off(D,t._onMove),M._emitter.off(A,t._onCancel),M._emitter.off(b,t._onEnd),M._activeInstances.length||M._unbindListeners())},M._bindListeners=function(){var t=M._events;window.addEventListener(t.move,M._onMove,R),window.addEventListener(t.end,M._onEnd,R),t.cancel&&window.addEventListener(t.cancel,M._onCancel,R)},M._unbindListeners=function(){var t=M._events;window.removeEventListener(t.move,M._onMove,R),window.removeEventListener(t.end,M._onEnd,R),t.cancel&&window.removeEventListener(t.cancel,M._onCancel,R)},M._getEventPointerId=function(t){return"number"==typeof t.pointerId?t.pointerId:t.changedTouches?t.changedTouches[0]?t.changedTouches[0].identifier:null:1},M._getTouchById=function(t,e){if("number"==typeof t.pointerId)return t.pointerId===e?t:null;if(t.changedTouches){for(var i=0;i-1&&(this._queue[n]=void 0),s?this._queue.unshift(t):this._queue.push(t),this._reads[t]=e,this._writes[t]=i,this._nextStep||(this._nextStep=y(this._step))},T.prototype.cancel=function(t){var e=this._queue.indexOf(t);e>-1&&(this._queue[e]=void 0,delete this._reads[t],delete this._writes[t])},T.prototype._step=function(){var t,e,i=this._queue,s=this._reads,n=this._writes,r=this._batch,o=this._batchReads,h=this._batchWrites,a=i.length;for(this._nextStep=null,e=0;en?n:e<0?Math.max(n+e+1,0):e}function K(t,e,i){if(!(t.length<2)){var s=J(t,e),n=J(t,i);s!==n&&t.splice(n,0,t.splice(s,1)[0])}}function Q(t,e,i){if(!(t.length<2)){var s,n=J(t,e),r=J(t,i);n!==r&&(s=t[n],t[n]=t[r],t[r]=s)}}var tt="cancel",et="finish",it="debounce",st=0;function nt(t,e){var i,s=++st+it;return e>0?function(n){void 0!==i&&(i=window.clearTimeout(i),k.cancel(s),n===et&&t()),n!==tt&&n!==et&&(i=window.setTimeout(function(){i=void 0,k.add(s,t,null,!0)},e))}:function(e){e!==tt&&t()}}function rt(t){var e=a(t,"transform");if(!e||"none"===e)return!1;var i=a(t,"display");return"inline"!==i&&"none"!==i}function ot(t,e){for(var i=window.document,s=(e?t:t.parentElement)||i;s&&s!==i&&"static"===a(s,"position")&&!rt(s);)s=s.parentElement||i;return s}function ht(t,e){return parseFloat(a(t,e))||0}var at={},_t={},lt={};function dt(t,e){var i,s=e||{};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:(i=t.getBoundingClientRect(),s.left+=i.left,s.top+=i.top,s.left+=ht(t,"border-left-width"),s.top+=ht(t,"border-top-width"),s))}function ct(t,e,i){return lt.left=0,lt.top=0,t===e?lt:i&&(t=ot(t,!0))===(e=ot(e,!0))?lt:(dt(t,at),dt(e,_t),lt.left=_t.left-at.left,lt.top=_t.top-at.top,lt)}var ut="overflow",ft="overflow-x",pt="overflow-y",mt="auto",gt="scroll";function yt(t){var e=a(t,ut);return e===mt||e===gt||((e=a(t,ft))===mt||e===gt||((e=a(t,pt))===mt||e===gt))}function vt(t,e,i){for(var s=i||[],n=e?t:t.parentNode;n&&n!==document;)n.getRootNode&&n instanceof DocumentFragment?n=n.getRootNode().host:(yt(n)&&s.push(n),n=n.parentNode);return s.push(window),s}var wt={},St="transform",Dt="none",bt=/^matrix3d/,At=/([^,]*,){4}/,Et=/([^,]*,){12}/,Ct=/[^,]*,/;function Lt(t){wt.x=0,wt.y=0;var e=a(t,St);if(!e||e===Dt)return wt;var i=bt.test(e),s=e.replace(i?Et:At,""),n=s.replace(Ct,"");return wt.x=parseFloat(s)||0,wt.y=parseFloat(n)||0,wt}function It(t,e){return"translateX("+t+"px) translateY("+e+"px)"}function Rt(t,e){t.classList?t.classList.remove(e):W(t,"."+e)&&(t.className=(" "+t.className+" ").replace(" "+e+" "," ").trim())}var xt,Pt,Mt,Tt,kt=0;function Xt(t){var e=t._element,i=t.getGrid(),s=i._settings;this._item=t,this._gridId=i._id,this._isDestroyed=!1,this._isMigrating=!1,this._startPredicate=c(s.dragStartPredicate)?s.dragStartPredicate:Xt.defaultStartPredicate,this._startPredicateState=kt,this._startPredicateResult=void 0,this._hBlockedIndex=null,this._hX1=0,this._hX2=0,this._hY1=0,this._hY2=0,this._reset(),this._preStartCheck=this._preStartCheck.bind(this),this._preEndCheck=this._preEndCheck.bind(this),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);var n=s.dragSortHeuristics.sortInterval;this._checkOverlapDebounce=nt(this._checkOverlap,n),this._dragger=new M(e,s.dragCssProps),this._dragger.on("start",this._preStartCheck),this._dragger.on("move",this._preStartCheck),this._dragger.on("cancel",this._preEndCheck),this._dragger.on("end",this._preEndCheck)}function Yt(t,e){return t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top?0:(Math.min(t.left+t.width,e.left+e.width)-Math.max(t.left,e.left))*(Math.min(t.top+t.height,e.top+e.height)-Math.max(t.top,e.top))/(Math.min(t.width,e.width)*Math.min(t.height,e.height))*100}function Gt(t){this._item=t,this._animate=new p,this._element=null,this._className="",this._didMigrate=!1,this._resetAfterLayout=!1,this._currentLeft=0,this._currentTop=0,this._nextLeft=0,this._nextTop=0,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this),this._onLayoutStart=this._onLayoutStart.bind(this),this._onLayoutEnd=this._onLayoutEnd.bind(this),this._onReleaseEnd=this._onReleaseEnd.bind(this),this._onMigrate=this._onMigrate.bind(this)}function Ht(){this._queue=[],this._isDestroyed=!1}function Ot(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 Ht,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this)}Xt.defaultStartPredicate=function(t,e,i){var s=t._drag,n=s._startPredicateData||s._setupStartPredicate(i);if(!e.isFinal)return!(!n.handleElement&&(n.handleElement=s._getStartPredicateHandle(e),!n.handleElement))&&(n.delay&&(n.event=e,n.delayTimer||(n.delayTimer=window.setTimeout(function(){n.delay=0,s._resolveStartPredicate(n.event)&&(s._forceResolveStartPredicate(n.event),s._resetStartPredicate())},n.delay))),s._resolveStartPredicate(e));s._finishStartPredicate(e)},Xt.defaultSortPredicate=(xt={},Pt={},Mt={},Tt=[],function(t,e){var i=t._drag,s=i._getGrid(),n=e&&"number"==typeof e.threshold?e.threshold:50,r=e&&"swap"===e.action?"swap":"move",o=e&&"swap"===e.migrateAction?"swap":"move";xt.width=t._width,xt.height=t._height,xt.left=i._elementClientX,xt.top=i._elementClientY;var h=function(t,e,i){var s,n,r,o,h=null,a=e._settings.dragSort,_=-1;if(!0===a?(Tt[0]=e,n=Tt):n=a.call(e,t),!Array.isArray(n))return h;for(o=0;oi&&s>_&&(_=s,h=r));return Tt.length=0,h}(t,s,n);if(!h)return!1;var a,_,l,d,c,u=t.getGrid()!==h,f=0,p=0,m=-1;for(h===s?(xt.left=i._gridX+t._marginLeft,xt.top=i._gridY+t._marginTop):(h._updateBorders(1,0,1,0),f=h._left+h._borderLeft,p=h._top+h._borderTop),c=0;cm&&(a=c,m=d));return m0?a:-1:0,m=n),m>=n&&(Mt.grid=h,Mt.index=a,Mt.action=u?o:r,Mt)}),Xt.prototype.stop=function(){var t=this._item,e=t._element,i=this._getGrid();return this._isActive?this._isMigrating?(this._finishMigration(),this):(N(t._id),q(t._id),this._unbindScrollListeners(),this._checkOverlapDebounce("cancel"),e.parentNode!==i._element&&(i._element.appendChild(e),e.style[n]=It(this._gridX,this._gridY)),Rt(e,i._settings.itemDraggingClass),this._reset(),this):this},Xt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(),this._dragger.destroy(),this._isDestroyed=!0,this)},Xt.prototype._getGrid=function(){return t[this._gridId]||null},Xt.prototype._reset=function(){this._isActive=!1,this._container=null,this._containingBlock=null,this._dragEvent=null,this._scrollEvent=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},Xt.prototype._bindScrollListeners=function(){var t,e,i=this._getGrid()._element,s=this._container,n=this._scrollers;if(n.length=0,vt(this._item._element,!1,n),s!==i)for(vt(i,!0,t=[]),e=0;e=s&&t.pageX=n&&t.pageY3&&e.minBounceBackAngle>0;if(h||(this._hBlockedIndex=null),Math.abs(r)>i||Math.abs(o)>i){if(h){var a=Math.atan2(r,o),_=Math.atan2(this._hX2-this._hX1,this._hY2-this._hY1),l=Math.atan2(Math.sin(a-_),Math.cos(a-_));Math.abs(l)>e.minBounceBackAngle&&(this._hBlockedIndex=null)}return this._hX1=this._hX2,this._hY1=this._hY2,this._hX2=s,this._hY2=n,!0}return!1},Xt.prototype._resetStartPredicate=function(){var t=this._startPredicateData;t&&(t.delayTimer&&(t.delayTimer=window.clearTimeout(t.delayTimer)),this._startPredicateData=null)},Xt.prototype._checkOverlap=function(){if(this._isActive){var t,e,i,s,n,r,o,h,a=this._item,_=this._getGrid()._settings;(t=c(_.dragSortPredicate)?_.dragSortPredicate(a,this._dragEvent):Xt.defaultSortPredicate(a,_.dragSortPredicate))&&"number"==typeof t.index&&(h=(e=a.getGrid())!==(s=t.grid||e),i=e._items.indexOf(a),n=J(s._items,t.index,h),o="swap"===t.action?"swap":"move",(h||n!==this._hBlockedIndex)&&(h?(this._hBlockedIndex=null,r=s._items[n],e._hasListeners("beforeSend")&&e._emit("beforeSend",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("beforeReceive")&&s._emit("beforeReceive",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),a._gridId=s._id,this._isMigrating=a._gridId!==this._gridId,e._items.splice(i,1),$(s._items,a,n),a._sortData=null,e._hasListeners("send")&&e._emit("send",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("receive")&&s._emit("receive",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),"swap"===o&&r&&r.isActive()&&s._items.indexOf(r)>-1&&s.send(r,e,i,{appendTo:this._container||window.document.body,layoutSender:!1,layoutReceiver:!1}),e.layout(),s.layout()):i!==n&&(this._hBlockedIndex=i,("swap"===o?Q:K)(e._items,i,n),e._hasListeners("move")&&e._emit("move",{item:a,fromIndex:i,toIndex:n,action:o}),e.layout())))}},Xt.prototype._finishMigration=function(){var t,e,i=this._item,s=i._release,r=i._element,o=i._isActive,h=i.getGrid(),a=h._element,_=h._settings,l=_.dragContainer||a,d=this._getGrid()._settings,c=r.parentNode;this._isMigrating=!1,this.destroy(),Rt(r,d.itemClass),Rt(r,d.itemVisibleClass),Rt(r,d.itemHiddenClass),j(r,_.itemClass),j(r,o?_.itemVisibleClass:_.itemHiddenClass),l!==c&&(l.appendChild(r),e=ct(c,l,!0),(t=Lt(r)).x-=e.left,t.y-=e.top),i._refreshDimensions(),i._refreshSortData(),e=ct(l,a,!0),s._containerDiffX=e.left,s._containerDiffY=e.top,i._drag=_.dragEnabled?new Xt(i):null,l!==c&&(r.style[n]=It(t.x,t.y)),i._child.removeAttribute("style"),f(i._child,o?_.visibleStyles:_.hiddenStyles),s.start()},Xt.prototype._preStartCheck=function(t){this._startPredicateState===kt&&(this._startPredicateState=1),1===this._startPredicateState?(this._startPredicateResult=this._startPredicate(this._item,t),!0===this._startPredicateResult?(this._startPredicateState=2,this._onStart(t)):!1===this._startPredicateResult&&(this._startPredicateState=3)):2===this._startPredicateState&&this._isActive&&this._onMove(t)},Xt.prototype._preEndCheck=function(t){var e=2===this._startPredicateState;this._startPredicate(this._item,t),this._startPredicateState=kt,e&&this._isActive&&this._onEnd(t)},Xt.prototype._onStart=function(t){var e=this._item;if(e._isActive){var i,s=e._element,r=this._getGrid(),o=r._settings,h=e._release,a=e._migrate,_=r._element,l=o.dragContainer||_,d=ot(l,!0),c=Lt(s),u=c.x,f=c.y,p=s.getBoundingClientRect(),m=l!==_;this._resetHeuristics(t),m&&(i=ct(d,_)),e.isPositioning()&&e._layout.stop(!0,{transform:It(u,f)}),a._isActive&&(u-=a._containerDiffX,f-=a._containerDiffY,a.stop(!0,{transform:It(u,f)})),e.isReleasing()&&h._reset(),this._isActive=!0,this._dragEvent=t,this._container=l,this._containingBlock=d,this._elementClientX=p.left,this._elementClientY=p.top,this._left=this._gridX=u,this._top=this._gridY=f,o.dragPlaceholder.enabled&&e._dragPlaceholder.create(),r._emit("dragInit",e,t),m&&(this._containerDiffX=i.left,this._containerDiffY=i.top,s.parentNode===l?(this._gridX=u-this._containerDiffX,this._gridY=f-this._containerDiffY):(this._left=u+this._containerDiffX,this._top=f+this._containerDiffY,l.appendChild(s),s.style[n]=It(this._left,this._top))),j(s,o.itemDraggingClass),this._bindScrollListeners(),r._emit("dragStart",e,t)}},Xt.prototype._onMove=function(t){var e=this._item;if(e._isActive){var i,s,n,r=this._getGrid()._settings.dragAxis;if("y"!==r){var o=t.clientX-this._dragEvent.clientX;this._left+=o,this._gridX+=o,this._elementClientX+=o}if("x"!==r){var h=t.clientY-this._dragEvent.clientY;this._top+=h,this._gridY+=h,this._elementClientY+=h}this._dragEvent=t,i=e._id,s=this._prepareMove,n=this._applyMove,k.add(i+G,s,n,!0)}else this.stop()},Xt.prototype._prepareMove=function(){this._item._isActive&&this._getGrid()._settings.dragSort&&this._checkHeuristics(this._dragEvent)&&this._checkOverlapDebounce()},Xt.prototype._applyMove=function(){var t=this._item;t._isActive&&(t._element.style[n]=It(this._left,this._top),this._getGrid()._emit("dragMove",t,this._dragEvent))},Xt.prototype._onScroll=function(t){var e,i,s,n=this._item;n._isActive?(this._scrollEvent=t,e=n._id,i=this._prepareScroll,s=this._applyScroll,k.add(e+H,i,s,!0)):this.stop()},Xt.prototype._prepareScroll=function(){var t=this._item;if(t._isActive){var e,i=t._element,s=this._getGrid(),n=s._settings,r=n.dragAxis,o=s._element,h=i.getBoundingClientRect(),a=this._elementClientX-h.left,_=this._elementClientY-h.top;this._container!==o&&(e=ct(this._containingBlock,o),this._containerDiffX=e.left,this._containerDiffY=e.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()}},Xt.prototype._applyScroll=function(){var t=this._item;t._isActive&&(t._element.style[n]=It(this._left,this._top),this._getGrid()._emit("dragScroll",t,this._scrollEvent))},Xt.prototype._onEnd=function(t){var e=this._item,i=e._element,s=this._getGrid(),n=s._settings,r=e._release;e._isActive?(N(e._id),q(e._id),n.dragSort&&this._checkOverlapDebounce("finish"),this._unbindScrollListeners(),r._containerDiffX=this._containerDiffX,r._containerDiffY=this._containerDiffY,this._reset(),Rt(i,n.itemDraggingClass),s._emit("dragEnd",e,t),this._isMigrating?this._finishMigration():r.start()):this.stop()},Gt.prototype._onLayoutStart=function(){var t=this._item,e=t.getGrid(),i=e._items.indexOf(t),s=e._layout.slots[2*i],n=e._layout.slots[2*i+1];if(this._didMigrate||t._left!==s||t._top!==n){var r,o,h;if(s+=t._marginLeft,n+=t._marginTop,!(e._settings.dragPlaceholder.duration>0)||this._didMigrate){F(t._id);var a={transform:It(s,n)};return this._animate.isAnimating()?this._animate.stop(a):f(this._element,a),void(this._didMigrate&&(e.getElement().appendChild(this._element),this._didMigrate=!1))}this._nextLeft=s,this._nextTop=n,r=t._id,o=this._setupAnimation,h=this._startAnimation,k.add(r+O,o,h)}},Gt.prototype._setupAnimation=function(){if(this.isActive()){var t=Lt(this._element);this._currentLeft=t.x,this._currentTop=t.y}},Gt.prototype._startAnimation=function(){if(this.isActive()){var t=this._animate,e=this._currentLeft,i=this._currentTop,s=this._nextLeft,n=this._nextTop,r={transform:It(s,n)};if(e!==s||i!==n){var o=this._item.getGrid()._settings.dragPlaceholder,h={transform:It(e,i)};t.start(h,r,{duration:o.duration,easing:o.easing,onFinish:this._onLayoutEnd})}else t.isAnimating()&&t.stop(r)}},Gt.prototype._onLayoutEnd=function(){this._resetAfterLayout&&this.reset()},Gt.prototype._onReleaseEnd=function(t){if(t._id===this._item._id){if(!this._animate.isAnimating())return void this.reset();this._resetAfterLayout=!0}},Gt.prototype._onMigrate=function(t){if(t.item===this._item){var e=this._item.getGrid(),i=t.toGrid;e.off("dragReleaseEnd",this._onReleaseEnd),e.off("layoutStart",this._onLayoutStart),e.off("beforeSend",this._onMigrate),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("layoutStart",this._onLayoutStart),i.on("beforeSend",this._onMigrate),this._didMigrate=!0}},Gt.prototype.create=function(){if(this.isActive())this._resetAfterLayout=!1;else{var t,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;t=c(s.dragPlaceholder.createElement)?s.dragPlaceholder.createElement(e):window.document.createElement("div"),this._element=t,n._element=t,this._className=s.itemPlaceholderClass||"",this._className&&j(t,this._className);var r=e._left+e._marginLeft,o=e._top+e._marginTop;f(t,{display:"block",position:"absolute",left:"0",top:"0",width:e._width+"px",height:e._height+"px",transform:It(r,o)}),i.on("layoutStart",this._onLayoutStart),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("beforeSend",this._onMigrate),c(s.dragPlaceholder.onCreate)&&s.dragPlaceholder.onCreate(e,t),i.getElement().appendChild(t)}},Gt.prototype.reset=function(){if(this.isActive()){var t=this._element,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;this._resetAfterLayout=!1,F(e._id),n.stop(),n._element=null,i.off("dragReleaseEnd",this._onReleaseEnd),i.off("layoutStart",this._onLayoutStart),i.off("beforeSend",this._onMigrate),this._className&&(Rt(t,this._className),this._className=""),t.parentNode.removeChild(t),this._element=null,c(s.dragPlaceholder.onRemove)&&s.dragPlaceholder.onRemove(e,t)}},Gt.prototype.updateDimensions=function(t,e){this.isActive()&&f(this._element,{width:t+"px",height:e+"px"})},Gt.prototype.isActive=function(){return!!this._element},Gt.prototype.destroy=function(){this.reset(),this._animate.destroy(),this._item=this._animate=null},Ht.prototype.add=function(t){return this._isDestroyed?this:(this._queue.push(t),this)},Ht.prototype.flush=function(t,e){if(this._isDestroyed)return this;var i,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,e),this;for(i=0;i0;return l&&this._queue.flush(!0,o),d&&(a._isPositioningStarted=!0),c(e)&&this._queue.add(e),m?(this._isActive=!0,this._animateOptions.easing=p,this._animateOptions.duration=u,this._isInterrupted=l,s=o._id,n=this._setupAnimation,r=this._startAnimation,k.add(s+X,n,r),this):(this._updateOffsets(),this._updateTargetStyles(),i=o._animate.isAnimating(),this.stop(!1,this._targetStyles),!i&&f(h,this._targetStyles),this._skipNextAnimation=!1,this._finish())}},Ot.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item;return i=s._id,k.cancel(i+X),s._animate.stop(e),Rt(s._element,s.getGrid()._settings.itemPositioningClass),this._isActive=!1,t&&this._queue.flush(!0,s),this},Ot.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)},Ot.prototype._updateOffsets=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._offsetLeft=i._isActive?i._containerDiffX:e._isActive?e._containerDiffX:0,this._offsetTop=i._isActive?i._containerDiffY:e._isActive?e._containerDiffY:0}},Ot.prototype._updateTargetStyles=function(){this._isDestroyed||(this._targetStyles.transform=It(this._item._left+this._offsetLeft,this._item._top+this._offsetTop))},Ot.prototype._finish=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._isActive&&(this._isActive=!1,Rt(t._element,t.getGrid()._settings.itemPositioningClass)),i._isActive&&i.stop(),e._isActive&&e.stop(),this._queue.flush(!1,t)}},Ot.prototype._setupAnimation=function(){var t=Lt(this._item._element);this._currentLeft=t.x,this._currentTop=t.y},Ot.prototype._startAnimation=function(){var t=this._item,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||j(t._element,e.itemPositioningClass),this._currentStyles.transform=It(this._currentLeft,this._currentTop),t._animate.start(this._currentStyles,this._targetStyles,this._animateOptions)};var Bt={};function Nt(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._container=!1,this._containerDiffX=0,this._containerDiffY=0}Nt.prototype.start=function(t,e,i){if(this._isDestroyed)return this;var s,r,o,h,a,_,l,d,c=this._item,u=c._element,p=c.isVisible(),m=c.getGrid(),g=m._settings,y=t._settings,v=t._element,w=t._items,S=m._items.indexOf(c),D=i||window.document.body;if("number"==typeof e)s=J(w,e,!0);else{if(!(r=t._getItem(e)))return this;s=w.indexOf(r)}return(c.isPositioning()||this._isActive||c.isReleasing())&&(l=(_=Lt(u)).x,d=_.y),c.isPositioning()&&c._layout.stop(!0,{transform:It(l,d)}),this._isActive&&(l-=this._containerDiffX,d-=this._containerDiffY,this.stop(!0,{transform:It(l,d)})),c.isReleasing()&&(l-=c._release._containerDiffX,d-=c._release._containerDiffY,c._release.stop(!0,{transform:It(l,d)})),c._visibility._stopAnimation(),c._drag&&c._drag.destroy(),c._visibility._queue.flush(!0,c),m._hasListeners("beforeSend")&&m._emit("beforeSend",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("beforeReceive")&&t._emit("beforeReceive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),Rt(u,g.itemClass),Rt(u,g.itemVisibleClass),Rt(u,g.itemHiddenClass),j(u,y.itemClass),j(u,p?y.itemVisibleClass:y.itemHiddenClass),m._items.splice(S,1),$(w,c,s),c._gridId=t._id,D!==(o=u.parentNode)&&(D.appendChild(u),h=ct(D,o,!0),_||(l=(_=Lt(u)).x,d=_.y),u.style[n]=It(l+h.left,d+h.top)),c._child.removeAttribute("style"),f(c._child,p?y.visibleStyles:y.hiddenStyles),u.style.display=p?"block":"hidden",a=ct(D,v,!0),c._refreshDimensions(),c._refreshSortData(),c._drag=y.dragEnabled?new Xt(c):null,this._isActive=!0,this._container=D,this._containerDiffX=a.left,this._containerDiffY=a.top,m._hasListeners("send")&&m._emit("send",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("receive")&&t._emit("receive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),this},Nt.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid()._element;return this._container!==r&&(e||(t?(i=Lt(n),Bt.transform=It(i.x-this._containerDiffX,i.y-this._containerDiffY)):Bt.transform=It(s._left,s._top),e=Bt),r.appendChild(n),f(n,e)),this._isActive=!1,this._container=null,this._containerDiffX=0,this._containerDiffY=0,this},Nt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)};var qt={};function Ft(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0}function zt(t){var e=t._isActive,i=t._element,s=t.getGrid()._settings;this._item=t,this._isDestroyed=!1,this._isHidden=!e,this._isHiding=!1,this._isShowing=!1,this._queue=new Ht,this._finishShow=this._finishShow.bind(this),this._finishHide=this._finishHide.bind(this),i.style.display=e?"block":"none",j(i,e?s.itemVisibleClass:s.itemHiddenClass),f(t._child,e?s.visibleStyles:s.hiddenStyles)}Ft.prototype.start=function(){if(this._isDestroyed||this._isActive)return this;var t=this._item,e=t.getGrid();return this._isActive=!0,j(t._element,e._settings.itemReleasingClass),e._emit("dragReleaseStart",t),t._layout.start(!1),this},Ft.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid(),o=r._element;return this._reset(),n.parentNode!==o&&(e||(t?(i=Lt(n),qt.transform=It(i.x-this._containerDiffX,i.y-this._containerDiffY)):qt.transform=It(s._left,s._top),e=qt),o.appendChild(n),f(n,e)),t||r._emit("dragReleaseEnd",s),this},Ft.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)},Ft.prototype._reset=function(){if(!this._isDestroyed){var t=this._item;this._isActive=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0,Rt(t._element,t.getGrid()._settings.itemReleasingClass)}},zt.prototype.show=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return this._isShowing||this._isHidden?this._isShowing&&!t?(r&&n.add(r),this):(this._isShowing||(n.flush(!0,i),Rt(s,o.itemHiddenClass),j(s,o.itemVisibleClass),this._isHiding||(s.style.display="block")),r&&n.add(r),i._isActive=this._isShowing=!0,this._isHiding=this._isHidden=!1,this._startAnimation(!0,t,this._finishShow),this):(r&&r(!1,i),this)},zt.prototype.hide=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return!this._isHiding&&this._isHidden?(r&&r(!1,i),this):this._isHiding&&!t?(r&&n.add(r),this):(this._isHiding||(n.flush(!0,i),j(s,o.itemHiddenClass),Rt(s,o.itemVisibleClass)),r&&n.add(r),this._isHidden=this._isHiding=!0,i._isActive=this._isShowing=!1,this._startAnimation(!1,t,this._finishHide),this)},zt.prototype.destroy=function(){if(this._isDestroyed)return this;var t=this._item,e=t._element,i=t.getGrid(),s=this._queue,n=i._settings;return this._stopAnimation({}),s.flush(!0,t).destroy(),Rt(e,n.itemVisibleClass),Rt(e,n.itemHiddenClass),this._item=null,this._isHiding=this._isShowing=!1,this._isDestroyed=this._isHidden=!0,this},zt.prototype._startAnimation=function(t,e,i){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,_=(t?r.showEasing:r.hideEasing)||"ease",d=e||h<=0;if(o){if(B(n._id),d)return n._animateChild.isAnimating()?n._animateChild.stop(o):f(n._child,o),void(i&&i());var c,u,p;c=n._id,u=function(){s=function(t,e){var i={};for(var s in e)i[s]=a(t,l(s));return i}(n._child,o)},p=function(){n._animateChild.start(s,o,{duration:h,easing:_,onFinish:i})},k.add(c+Y,u,p)}else i&&i()}},zt.prototype._stopAnimation=function(t){if(!this._isDestroyed){var e=this._item;B(e._id),e._animateChild.stop(t)}},zt.prototype._finishShow=function(){this._isHidden||(this._isShowing=!1,this._queue.flush(!1,this._item))};var Vt={};zt.prototype._finishHide=function(){if(this._isHidden){var t=this._item;this._isHiding=!1,Vt.transform=It(0,0),t._layout.stop(!0,Vt),t._element.style.display="none",this._queue.flush(!1,t)}};var Wt,jt,Ut,Zt,$t=0;function Jt(){return++$t}function Kt(t,e,i){var s=t._settings;this._id=Jt(),this._gridId=t._id,this._isDestroyed=!1,this._left=0,this._top=0,this._element=e,this._child=e.children[0],e.parentNode!==t._element&&t._element.appendChild(e),j(e,s.itemClass),"boolean"!=typeof i&&(i="none"!==a(e,"display")),this._isActive=i,e.style.left="0",e.style.top="0",e.style[n]=It(0,0),this._animate=new p(e),this._animateChild=new p(this._child),this._visibility=new zt(this),this._layout=new Ot(this),this._migrate=new Nt(this),this._release=new Ft(this),this._dragPlaceholder=new Gt(this),this._drag=s.dragEnabled?new Xt(this):null,this._refreshDimensions(),this._refreshSortData()}function Qt(){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)}Kt.prototype.getGrid=function(){return t[this._gridId]},Kt.prototype.getElement=function(){return this._element},Kt.prototype.getWidth=function(){return this._width},Kt.prototype.getHeight=function(){return this._height},Kt.prototype.getMargin=function(){return{left:this._marginLeft,right:this._marginRight,top:this._marginTop,bottom:this._marginBottom}},Kt.prototype.getPosition=function(){return{left:this._left,top:this._top}},Kt.prototype.isActive=function(){return this._isActive},Kt.prototype.isVisible=function(){return!!this._visibility&&!this._visibility._isHidden},Kt.prototype.isShowing=function(){return!(!this._visibility||!this._visibility._isShowing)},Kt.prototype.isHiding=function(){return!(!this._visibility||!this._visibility._isHiding)},Kt.prototype.isPositioning=function(){return!(!this._layout||!this._layout._isActive)},Kt.prototype.isDragging=function(){return!(!this._drag||!this._drag._isActive)},Kt.prototype.isReleasing=function(){return!(!this._release||!this._release._isActive)},Kt.prototype.isDestroyed=function(){return this._isDestroyed},Kt.prototype._refreshDimensions=function(){if(!this._isDestroyed&&!this._visibility._isHidden){var t=this._element,e=this._dragPlaceholder,i=t.getBoundingClientRect();this._width=i.width,this._height=i.height,this._marginLeft=Math.max(0,ht(t,"margin-left")),this._marginRight=Math.max(0,ht(t,"margin-right")),this._marginTop=Math.max(0,ht(t,"margin-top")),this._marginBottom=Math.max(0,ht(t,"margin-bottom")),e&&e.updateDimensions(this._width,this._height)}},Kt.prototype._refreshSortData=function(){if(!this._isDestroyed){var t,e=this._sortData={},i=this.getGrid()._settings.sortData;for(t in i)e[t]=i[t](this,this._element)}},Kt.prototype._destroy=function(t){if(!this._isDestroyed){var e=this._element,i=this.getGrid(),s=i._settings,n=i._items.indexOf(this);this._release.destroy(),this._migrate.destroy(),this._layout.destroy(),this._visibility.destroy(),this._animate.destroy(),this._animateChild.destroy(),this._dragPlaceholder.destroy(),this._drag&&this._drag.destroy(),e.removeAttribute("style"),this._child.removeAttribute("style"),Rt(e,s.itemClass),n>-1&&i._items.splice(n,1),t&&e.parentNode.removeChild(e),this._isActive=!1,this._isDestroyed=!0}},Qt.prototype.getLayout=function(t,e,i,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),c=this._slotSizes;if(o.slots=s||this._slots,o.width=a?0:d?Math.round(e):e,o.height=a?d?Math.round(i):i:0,o.setWidth=a,o.setHeight=!a,o.slots.length=0,c.length=0,!t.length)return o;for(r=0;rd.height&&(Wt.left>0&&u.push(this._addRect(0,d.height,Wt.left,1/0)),Wt.left+Wt.widthd.width&&(Wt.top>0&&u.push(this._addRect(d.width,0,1/0,Wt.top)),Wt.top+Wt.height.49&&r.height>.49&&(!e&&r.tope.left+e.width&&jt.push(this._addRect(e.left+e.width,t.top,t.left+t.width-(e.left+e.width),t.height)),t.tope.top+e.height&&jt.push(this._addRect(t.left,e.top+e.height,t.width,t.top+t.height-(e.top+e.height))),jt):(jt.push(this._addRect(t.left,t.top,t.width,t.height)),jt)}),Qt.prototype._doRectsOverlap=function(t,e){return!(t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top)},Qt.prototype._isRectWithinRect=function(t,e){return t.left>=e.left&&t.top>=e.top&&t.left+t.width<=e.left+e.width&&t.top+t.height<=e.top+e.height},Qt.prototype._purgeRects=(Ut={},Zt={},function(t){for(var e,i=t.length;i--;)if(e=t.length,t[i])for(this._getRect(t[i],Ut);e--;)if(t[e]&&i!==e&&this._isRectWithinRect(Ut,this._getRect(t[e],Zt))){t[i]=0;break}return t}),Qt.prototype._sortRectsTopLeft=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.tope.top?1:t.lefte.left?1:0}}(),Qt.prototype._sortRectsLeftTop=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.lefte.left?1:t.tope.top?1:0}}();var te="[object HTMLCollection]",ee="[object NodeList]";function ie(t){var e=Object.prototype.toString.call(t);return e===te||e===ee}var se="object",ne="[object Object]",re=Object.prototype.toString;function oe(t){return typeof t===se&&re.call(t)===ne}function he(t){return ie(t)?Array.prototype.slice.call(t):Array.prototype.concat(t)}var ae=new Qt,_e=function(){},le="number",de="string";function ce(e,s){var n,r,o,h=this;if(!((e=this._element=typeof e===de?window.document.querySelector(e):e).getRootNode?e.getRootNode({composed:!0})===document:window.document.body.contains(e))||e===window.document.documentElement)throw new Error("Container element must be an existing DOM element");c((n=this._settings=function(t,e){var i=ue({},t);e&&(i=ue(i,e));return i.visibleStyles=(e||0).visibleStyles||(t||0).visibleStyles,i.hiddenStyles=(e||0).hiddenStyles||(t||0).hiddenStyles,i}(ce.defaultOptions,s)).dragSort)||(n.dragSort=!!n.dragSort),this._id=Jt(),t[this._id]=h,this._isDestroyed=!1,this._layout={id:0,items:[],slots:[],setWidth:!1,setHeight:!1,width:0,height:0},this._emitter=new i,j(e,n.containerClass),this._items=[],typeof(r=n.items)===de?he(e.children).forEach(function(t){("*"===r||W(t,r))&&h._items.push(new Kt(h,t))}):(Array.isArray(r)||ie(r))&&(this._items=he(r).map(function(t){return new Kt(h,t)})),typeof(o=n.layoutOnResize)!==le&&(o=!0===o?0:-1),o>=0&&window.addEventListener("resize",h._resizeHandler=nt(function(){h.refreshItems().layout()},o)),n.layoutOnInit&&this.layout(!0)}function ue(t,e){var i,s,n,r=Object.keys(e),o=r.length;for(n=0;n0)){var s=o._layout.id!==l,n=c(t)?t:i;c(n)&&n(s,_.items.slice(0)),!s&&o._hasListeners(e)&&o._emit(e,_.items.slice(0))}}if((_.setHeight&&typeof _.height===le||_.setWidth&&typeof _.width===le)&&(s="border-box"===a(h,"box-sizing")),_.setHeight&&(typeof _.height===le?h.style.height=(s?_.height+this._borderTop+this._borderBottom:_.height)+"px":h.style.height=_.height),_.setWidth&&(typeof _.width===le?h.style.width=(s?_.width+this._borderLeft+this._borderRight:_.width)+"px":h.style.width=_.width),this._hasListeners("layoutStart")&&this._emit("layoutStart",_.items.slice(0)),!d)return f(),this;for(r=0;rl?1:0:ld?1:0)return c;return c||(s||(s=n(i)),c=r(o,h)),c}function h(o,h){var a=t(o,h);return e&&a&&(a=-a),a||(s||(s=n(i)),r(o,h))}return function(n,r){if(this._isDestroyed||this._items.length<2)return this;var a,_=this._items,l=r||0,d=l.layout?l.layout:void 0===l.layout;if(t=n,e=!!l.descending,i=_.slice(0),s=null,c(t))_.sort(h);else if(typeof t===de)t=n.trim().split(" ").map(function(t){return t.split(":")}),_.sort(o);else{if(!Array.isArray(t))return this;if(t.length!==_.length)throw new Error("[Muuri] sort reference items do not match with grid items.");for(a=0;a<_.length;a++){if(t.indexOf(_[a])<0)throw new Error("[Muuri] sort reference items do not match with grid items.");_[a]=t[a]}e&&_.reverse()}return this._hasListeners("sort")&&this._emit("sort",_.slice(0),i),d&&this.layout("instant"===d,c(d)?d:void 0),this}}(),ce.prototype.move=function(t,e,i){if(this._isDestroyed||this._items.length<2)return this;var s,n,r=this._items,o=i||0,h=o.layout?o.layout:void 0===o.layout,a="swap"===o.action,_=a?"swap":"move",l=this._getItem(t),d=this._getItem(e);return l&&d&&l!==d&&(s=r.indexOf(l),n=r.indexOf(d),a?Q(r,s,n):K(r,s,n),this._hasListeners("move")&&this._emit("move",{item:l,fromIndex:s,toIndex:n,action:_}),h&&this.layout("instant"===h,c(h)?h:void 0)),this},ce.prototype.send=function(t,e,i,s){if(this._isDestroyed||e._isDestroyed||this===e)return this;if(!(t=this._getItem(t)))return this;var n=s||0,r=n.appendTo||window.document.body,o=n.layoutSender?n.layoutSender:void 0===n.layoutSender,h=n.layoutReceiver?n.layoutReceiver:void 0===n.layoutReceiver;return t._migrate.start(e,i,r),t._migrate._isActive&&t._isActive&&(o&&this.layout("instant"===o,c(o)?o:void 0),h&&e.layout("instant"===h,c(h)?h:void 0)),this},ce.prototype.destroy=function(e){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-1?t:this._items.length+t]||null;if(t instanceof Kt)return t._gridId===this._id?t:null;for(var e=0;e -1) { + targetGrid.send(targetItem, currentGrid, currentIndex, { + appendTo: this._container || window.document.body, + layoutSender: false, + layoutReceiver: false + }); + } + } + // Layout both grids. currentGrid.layout(); targetGrid.layout(); From 80d55afd59ce25a9032301aedef639d74e79c89e Mon Sep 17 00:00:00 2001 From: Niklas Ramo Date: Sat, 20 Jul 2019 15:47:17 +0300 Subject: [PATCH 005/120] Update demo. --- demos/basic.html | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/demos/basic.html b/demos/basic.html index 04c37614..0d39b7c4 100644 --- a/demos/basic.html +++ b/demos/basic.html @@ -41,6 +41,10 @@ margin: 5px; z-index: 1; } + .item.muuri-item-placeholder { + opacity: 0.5; + margin: 0; + } .item.h1 { height: 50px; line-height: 50px; @@ -112,6 +116,15 @@ dragContainer: document.body, dragSort: function() { return [grid1, grid2]; + }, + dragSortPredicate: { + migrateAction: 'move', + }, + dragPlaceholder: { + enabled: true, + createElement: function (item) { + return item.getElement().cloneNode(true); + } } }); @@ -121,6 +134,15 @@ dragContainer: document.body, dragSort: function() { return [grid1, grid2]; + }, + dragSortPredicate: { + migrateAction: 'swap', + }, + dragPlaceholder: { + enabled: true, + createElement: function (item) { + return item.getElement().cloneNode(true); + } } }); From 718c1b276c47734691235a9784f1c89b14b7f922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20R=C3=A4m=C3=B6?= Date: Sat, 20 Jul 2019 23:28:29 +0300 Subject: [PATCH 006/120] Added Muuri Dragger to the copyright notice banner. --- dist/muuri.js | 2 +- dist/muuri.min.js | 2 +- rollup.banner.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/muuri.js b/dist/muuri.js index 03915d56..d582f357 100644 --- a/dist/muuri.js +++ b/dist/muuri.js @@ -10,7 +10,7 @@ * Copyright (c) 2016-present, Niklas Rämö * @license MIT * -* Muuri Ticker / Muuri Emitter / Muuri Queue +* Muuri Ticker / Muuri Emitter / Muuri Queue / Muuri Dragger * Copyright (c) 2018-present, Niklas Rämö * @license MIT */ diff --git a/dist/muuri.min.js b/dist/muuri.min.js index 4809c37e..03780445 100644 --- a/dist/muuri.min.js +++ b/dist/muuri.min.js @@ -10,7 +10,7 @@ * Copyright (c) 2016-present, Niklas Rämö * @license MIT * -* Muuri Ticker / Muuri Emitter / Muuri Queue +* Muuri Ticker / Muuri Emitter / Muuri Queue / Muuri Dragger * Copyright (c) 2018-present, Niklas Rämö * @license MIT */ diff --git a/rollup.banner.js b/rollup.banner.js index 8d38f8fd..3eabf123 100644 --- a/rollup.banner.js +++ b/rollup.banner.js @@ -12,7 +12,7 @@ module.exports = `/** * Copyright (c) 2016-present, Niklas Rämö * @license MIT * -* Muuri Ticker / Muuri Emitter / Muuri Queue +* Muuri Ticker / Muuri Emitter / Muuri Queue / Muuri Dragger * Copyright (c) 2018-present, Niklas Rämö * @license MIT */ From 4cfe163092a33e9ad820d927df6498b0383b4c46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20R=C3=A4m=C3=B6?= Date: Mon, 22 Jul 2019 13:27:59 +0300 Subject: [PATCH 007/120] Refactor default drag sort predicate. --- dist/muuri.js | 23 +++++++++++++---------- dist/muuri.min.js | 2 +- src/Item/ItemDrag.js | 23 +++++++++++++---------- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/dist/muuri.js b/dist/muuri.js index d582f357..7f21734f 100644 --- a/dist/muuri.js +++ b/dist/muuri.js @@ -1881,6 +1881,8 @@ /** * Default drag sort predicate. * + * @todo Check if we layout thrashing is a problem here and if we can alleviate + * it's potential effects. * @public * @memberof ItemDrag * @param {Item} item @@ -1895,7 +1897,7 @@ var itemRect = {}; var targetRect = {}; var returnData = {}; - var rootGridArray = []; + var gridsArray = []; function getTargetGrid(item, rootGrid, threshold) { var target = null; @@ -1908,14 +1910,16 @@ // Get potential target grids. if (dragSort === true) { - rootGridArray[0] = rootGrid; - grids = rootGridArray; - } else { + gridsArray[0] = rootGrid; + grids = gridsArray; + } else if (isFunction(dragSort)) { grids = dragSort.call(rootGrid, item); } // Return immediately if there are no grids. - if (!Array.isArray(grids)) return target; + if (!grids || !Array.isArray(grids) || !grids.length) { + return target; + } // Loop through the grids and get the best match. for (i = 0; i < grids.length; i++) { @@ -1942,8 +1946,8 @@ } } - // Always reset root grid array. - rootGridArray.length = 0; + // Always reset grids array. + gridsArray.length = 0; return target; } @@ -1955,8 +1959,7 @@ // Get drag sort predicate settings. var sortThreshold = options && typeof options.threshold === 'number' ? options.threshold : 50; var sortAction = options && options.action === actionSwap ? actionSwap : actionMove; - var sortMigrateAction = - options && options.migrateAction === actionSwap ? actionSwap : actionMove; + var migrateAction = options && options.migrateAction === actionSwap ? actionSwap : actionMove; // Populate item rect data. itemRect.width = item._width; @@ -2039,7 +2042,7 @@ if (matchScore >= sortThreshold) { returnData.grid = grid; returnData.index = matchIndex; - returnData.action = isMigration ? sortMigrateAction : sortAction; + returnData.action = isMigration ? migrateAction : sortAction; return returnData; } diff --git a/dist/muuri.min.js b/dist/muuri.min.js index 03780445..cc3045c9 100644 --- a/dist/muuri.min.js +++ b/dist/muuri.min.js @@ -14,4 +14,4 @@ * Copyright (c) 2018-present, Niklas Rämö * @license MIT */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Muuri=e()}(this,function(){"use strict";var t={},e="layoutEnd";function i(){this._events={},this._queue=[],this._counter=0,this._isDestroyed=!1}i.prototype.on=function(t,e){if(this._isDestroyed)return this;var i=this._events[t];return i||(i=this._events[t]=[]),i.push(e),this},i.prototype.off=function(t,e){if(this._isDestroyed)return this;var i=this._events[t];if(!i||!i.length)return this;if(!e)return i.length=0,this;for(var s=i.length;s--;)e===i[s]&&i.splice(s,1);return this},i.prototype.emit=function(t,e,i,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-1||(M._activeInstances.push(t),M._emitter.on(D,t._onMove),M._emitter.on(A,t._onCancel),M._emitter.on(b,t._onEnd),1===M._activeInstances.length&&M._bindListeners())},M._deactivateInstance=function(t){var e=M._activeInstances.indexOf(t);-1!==e&&(M._activeInstances.splice(e,1),M._emitter.off(D,t._onMove),M._emitter.off(A,t._onCancel),M._emitter.off(b,t._onEnd),M._activeInstances.length||M._unbindListeners())},M._bindListeners=function(){var t=M._events;window.addEventListener(t.move,M._onMove,R),window.addEventListener(t.end,M._onEnd,R),t.cancel&&window.addEventListener(t.cancel,M._onCancel,R)},M._unbindListeners=function(){var t=M._events;window.removeEventListener(t.move,M._onMove,R),window.removeEventListener(t.end,M._onEnd,R),t.cancel&&window.removeEventListener(t.cancel,M._onCancel,R)},M._getEventPointerId=function(t){return"number"==typeof t.pointerId?t.pointerId:t.changedTouches?t.changedTouches[0]?t.changedTouches[0].identifier:null:1},M._getTouchById=function(t,e){if("number"==typeof t.pointerId)return t.pointerId===e?t:null;if(t.changedTouches){for(var i=0;i-1&&(this._queue[n]=void 0),s?this._queue.unshift(t):this._queue.push(t),this._reads[t]=e,this._writes[t]=i,this._nextStep||(this._nextStep=y(this._step))},T.prototype.cancel=function(t){var e=this._queue.indexOf(t);e>-1&&(this._queue[e]=void 0,delete this._reads[t],delete this._writes[t])},T.prototype._step=function(){var t,e,i=this._queue,s=this._reads,n=this._writes,r=this._batch,o=this._batchReads,h=this._batchWrites,a=i.length;for(this._nextStep=null,e=0;en?n:e<0?Math.max(n+e+1,0):e}function K(t,e,i){if(!(t.length<2)){var s=J(t,e),n=J(t,i);s!==n&&t.splice(n,0,t.splice(s,1)[0])}}function Q(t,e,i){if(!(t.length<2)){var s,n=J(t,e),r=J(t,i);n!==r&&(s=t[n],t[n]=t[r],t[r]=s)}}var tt="cancel",et="finish",it="debounce",st=0;function nt(t,e){var i,s=++st+it;return e>0?function(n){void 0!==i&&(i=window.clearTimeout(i),k.cancel(s),n===et&&t()),n!==tt&&n!==et&&(i=window.setTimeout(function(){i=void 0,k.add(s,t,null,!0)},e))}:function(e){e!==tt&&t()}}function rt(t){var e=a(t,"transform");if(!e||"none"===e)return!1;var i=a(t,"display");return"inline"!==i&&"none"!==i}function ot(t,e){for(var i=window.document,s=(e?t:t.parentElement)||i;s&&s!==i&&"static"===a(s,"position")&&!rt(s);)s=s.parentElement||i;return s}function ht(t,e){return parseFloat(a(t,e))||0}var at={},_t={},lt={};function dt(t,e){var i,s=e||{};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:(i=t.getBoundingClientRect(),s.left+=i.left,s.top+=i.top,s.left+=ht(t,"border-left-width"),s.top+=ht(t,"border-top-width"),s))}function ct(t,e,i){return lt.left=0,lt.top=0,t===e?lt:i&&(t=ot(t,!0))===(e=ot(e,!0))?lt:(dt(t,at),dt(e,_t),lt.left=_t.left-at.left,lt.top=_t.top-at.top,lt)}var ut="overflow",ft="overflow-x",pt="overflow-y",mt="auto",gt="scroll";function yt(t){var e=a(t,ut);return e===mt||e===gt||((e=a(t,ft))===mt||e===gt||((e=a(t,pt))===mt||e===gt))}function vt(t,e,i){for(var s=i||[],n=e?t:t.parentNode;n&&n!==document;)n.getRootNode&&n instanceof DocumentFragment?n=n.getRootNode().host:(yt(n)&&s.push(n),n=n.parentNode);return s.push(window),s}var wt={},St="transform",Dt="none",bt=/^matrix3d/,At=/([^,]*,){4}/,Et=/([^,]*,){12}/,Ct=/[^,]*,/;function Lt(t){wt.x=0,wt.y=0;var e=a(t,St);if(!e||e===Dt)return wt;var i=bt.test(e),s=e.replace(i?Et:At,""),n=s.replace(Ct,"");return wt.x=parseFloat(s)||0,wt.y=parseFloat(n)||0,wt}function It(t,e){return"translateX("+t+"px) translateY("+e+"px)"}function Rt(t,e){t.classList?t.classList.remove(e):W(t,"."+e)&&(t.className=(" "+t.className+" ").replace(" "+e+" "," ").trim())}var xt,Pt,Mt,Tt,kt=0;function Xt(t){var e=t._element,i=t.getGrid(),s=i._settings;this._item=t,this._gridId=i._id,this._isDestroyed=!1,this._isMigrating=!1,this._startPredicate=c(s.dragStartPredicate)?s.dragStartPredicate:Xt.defaultStartPredicate,this._startPredicateState=kt,this._startPredicateResult=void 0,this._hBlockedIndex=null,this._hX1=0,this._hX2=0,this._hY1=0,this._hY2=0,this._reset(),this._preStartCheck=this._preStartCheck.bind(this),this._preEndCheck=this._preEndCheck.bind(this),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);var n=s.dragSortHeuristics.sortInterval;this._checkOverlapDebounce=nt(this._checkOverlap,n),this._dragger=new M(e,s.dragCssProps),this._dragger.on("start",this._preStartCheck),this._dragger.on("move",this._preStartCheck),this._dragger.on("cancel",this._preEndCheck),this._dragger.on("end",this._preEndCheck)}function Yt(t,e){return t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top?0:(Math.min(t.left+t.width,e.left+e.width)-Math.max(t.left,e.left))*(Math.min(t.top+t.height,e.top+e.height)-Math.max(t.top,e.top))/(Math.min(t.width,e.width)*Math.min(t.height,e.height))*100}function Gt(t){this._item=t,this._animate=new p,this._element=null,this._className="",this._didMigrate=!1,this._resetAfterLayout=!1,this._currentLeft=0,this._currentTop=0,this._nextLeft=0,this._nextTop=0,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this),this._onLayoutStart=this._onLayoutStart.bind(this),this._onLayoutEnd=this._onLayoutEnd.bind(this),this._onReleaseEnd=this._onReleaseEnd.bind(this),this._onMigrate=this._onMigrate.bind(this)}function Ht(){this._queue=[],this._isDestroyed=!1}function Ot(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 Ht,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this)}Xt.defaultStartPredicate=function(t,e,i){var s=t._drag,n=s._startPredicateData||s._setupStartPredicate(i);if(!e.isFinal)return!(!n.handleElement&&(n.handleElement=s._getStartPredicateHandle(e),!n.handleElement))&&(n.delay&&(n.event=e,n.delayTimer||(n.delayTimer=window.setTimeout(function(){n.delay=0,s._resolveStartPredicate(n.event)&&(s._forceResolveStartPredicate(n.event),s._resetStartPredicate())},n.delay))),s._resolveStartPredicate(e));s._finishStartPredicate(e)},Xt.defaultSortPredicate=(xt={},Pt={},Mt={},Tt=[],function(t,e){var i=t._drag,s=i._getGrid(),n=e&&"number"==typeof e.threshold?e.threshold:50,r=e&&"swap"===e.action?"swap":"move",o=e&&"swap"===e.migrateAction?"swap":"move";xt.width=t._width,xt.height=t._height,xt.left=i._elementClientX,xt.top=i._elementClientY;var h=function(t,e,i){var s,n,r,o,h=null,a=e._settings.dragSort,_=-1;if(!0===a?(Tt[0]=e,n=Tt):n=a.call(e,t),!Array.isArray(n))return h;for(o=0;oi&&s>_&&(_=s,h=r));return Tt.length=0,h}(t,s,n);if(!h)return!1;var a,_,l,d,c,u=t.getGrid()!==h,f=0,p=0,m=-1;for(h===s?(xt.left=i._gridX+t._marginLeft,xt.top=i._gridY+t._marginTop):(h._updateBorders(1,0,1,0),f=h._left+h._borderLeft,p=h._top+h._borderTop),c=0;cm&&(a=c,m=d));return m0?a:-1:0,m=n),m>=n&&(Mt.grid=h,Mt.index=a,Mt.action=u?o:r,Mt)}),Xt.prototype.stop=function(){var t=this._item,e=t._element,i=this._getGrid();return this._isActive?this._isMigrating?(this._finishMigration(),this):(N(t._id),q(t._id),this._unbindScrollListeners(),this._checkOverlapDebounce("cancel"),e.parentNode!==i._element&&(i._element.appendChild(e),e.style[n]=It(this._gridX,this._gridY)),Rt(e,i._settings.itemDraggingClass),this._reset(),this):this},Xt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(),this._dragger.destroy(),this._isDestroyed=!0,this)},Xt.prototype._getGrid=function(){return t[this._gridId]||null},Xt.prototype._reset=function(){this._isActive=!1,this._container=null,this._containingBlock=null,this._dragEvent=null,this._scrollEvent=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},Xt.prototype._bindScrollListeners=function(){var t,e,i=this._getGrid()._element,s=this._container,n=this._scrollers;if(n.length=0,vt(this._item._element,!1,n),s!==i)for(vt(i,!0,t=[]),e=0;e=s&&t.pageX=n&&t.pageY3&&e.minBounceBackAngle>0;if(h||(this._hBlockedIndex=null),Math.abs(r)>i||Math.abs(o)>i){if(h){var a=Math.atan2(r,o),_=Math.atan2(this._hX2-this._hX1,this._hY2-this._hY1),l=Math.atan2(Math.sin(a-_),Math.cos(a-_));Math.abs(l)>e.minBounceBackAngle&&(this._hBlockedIndex=null)}return this._hX1=this._hX2,this._hY1=this._hY2,this._hX2=s,this._hY2=n,!0}return!1},Xt.prototype._resetStartPredicate=function(){var t=this._startPredicateData;t&&(t.delayTimer&&(t.delayTimer=window.clearTimeout(t.delayTimer)),this._startPredicateData=null)},Xt.prototype._checkOverlap=function(){if(this._isActive){var t,e,i,s,n,r,o,h,a=this._item,_=this._getGrid()._settings;(t=c(_.dragSortPredicate)?_.dragSortPredicate(a,this._dragEvent):Xt.defaultSortPredicate(a,_.dragSortPredicate))&&"number"==typeof t.index&&(h=(e=a.getGrid())!==(s=t.grid||e),i=e._items.indexOf(a),n=J(s._items,t.index,h),o="swap"===t.action?"swap":"move",(h||n!==this._hBlockedIndex)&&(h?(this._hBlockedIndex=null,r=s._items[n],e._hasListeners("beforeSend")&&e._emit("beforeSend",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("beforeReceive")&&s._emit("beforeReceive",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),a._gridId=s._id,this._isMigrating=a._gridId!==this._gridId,e._items.splice(i,1),$(s._items,a,n),a._sortData=null,e._hasListeners("send")&&e._emit("send",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("receive")&&s._emit("receive",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),"swap"===o&&r&&r.isActive()&&s._items.indexOf(r)>-1&&s.send(r,e,i,{appendTo:this._container||window.document.body,layoutSender:!1,layoutReceiver:!1}),e.layout(),s.layout()):i!==n&&(this._hBlockedIndex=i,("swap"===o?Q:K)(e._items,i,n),e._hasListeners("move")&&e._emit("move",{item:a,fromIndex:i,toIndex:n,action:o}),e.layout())))}},Xt.prototype._finishMigration=function(){var t,e,i=this._item,s=i._release,r=i._element,o=i._isActive,h=i.getGrid(),a=h._element,_=h._settings,l=_.dragContainer||a,d=this._getGrid()._settings,c=r.parentNode;this._isMigrating=!1,this.destroy(),Rt(r,d.itemClass),Rt(r,d.itemVisibleClass),Rt(r,d.itemHiddenClass),j(r,_.itemClass),j(r,o?_.itemVisibleClass:_.itemHiddenClass),l!==c&&(l.appendChild(r),e=ct(c,l,!0),(t=Lt(r)).x-=e.left,t.y-=e.top),i._refreshDimensions(),i._refreshSortData(),e=ct(l,a,!0),s._containerDiffX=e.left,s._containerDiffY=e.top,i._drag=_.dragEnabled?new Xt(i):null,l!==c&&(r.style[n]=It(t.x,t.y)),i._child.removeAttribute("style"),f(i._child,o?_.visibleStyles:_.hiddenStyles),s.start()},Xt.prototype._preStartCheck=function(t){this._startPredicateState===kt&&(this._startPredicateState=1),1===this._startPredicateState?(this._startPredicateResult=this._startPredicate(this._item,t),!0===this._startPredicateResult?(this._startPredicateState=2,this._onStart(t)):!1===this._startPredicateResult&&(this._startPredicateState=3)):2===this._startPredicateState&&this._isActive&&this._onMove(t)},Xt.prototype._preEndCheck=function(t){var e=2===this._startPredicateState;this._startPredicate(this._item,t),this._startPredicateState=kt,e&&this._isActive&&this._onEnd(t)},Xt.prototype._onStart=function(t){var e=this._item;if(e._isActive){var i,s=e._element,r=this._getGrid(),o=r._settings,h=e._release,a=e._migrate,_=r._element,l=o.dragContainer||_,d=ot(l,!0),c=Lt(s),u=c.x,f=c.y,p=s.getBoundingClientRect(),m=l!==_;this._resetHeuristics(t),m&&(i=ct(d,_)),e.isPositioning()&&e._layout.stop(!0,{transform:It(u,f)}),a._isActive&&(u-=a._containerDiffX,f-=a._containerDiffY,a.stop(!0,{transform:It(u,f)})),e.isReleasing()&&h._reset(),this._isActive=!0,this._dragEvent=t,this._container=l,this._containingBlock=d,this._elementClientX=p.left,this._elementClientY=p.top,this._left=this._gridX=u,this._top=this._gridY=f,o.dragPlaceholder.enabled&&e._dragPlaceholder.create(),r._emit("dragInit",e,t),m&&(this._containerDiffX=i.left,this._containerDiffY=i.top,s.parentNode===l?(this._gridX=u-this._containerDiffX,this._gridY=f-this._containerDiffY):(this._left=u+this._containerDiffX,this._top=f+this._containerDiffY,l.appendChild(s),s.style[n]=It(this._left,this._top))),j(s,o.itemDraggingClass),this._bindScrollListeners(),r._emit("dragStart",e,t)}},Xt.prototype._onMove=function(t){var e=this._item;if(e._isActive){var i,s,n,r=this._getGrid()._settings.dragAxis;if("y"!==r){var o=t.clientX-this._dragEvent.clientX;this._left+=o,this._gridX+=o,this._elementClientX+=o}if("x"!==r){var h=t.clientY-this._dragEvent.clientY;this._top+=h,this._gridY+=h,this._elementClientY+=h}this._dragEvent=t,i=e._id,s=this._prepareMove,n=this._applyMove,k.add(i+G,s,n,!0)}else this.stop()},Xt.prototype._prepareMove=function(){this._item._isActive&&this._getGrid()._settings.dragSort&&this._checkHeuristics(this._dragEvent)&&this._checkOverlapDebounce()},Xt.prototype._applyMove=function(){var t=this._item;t._isActive&&(t._element.style[n]=It(this._left,this._top),this._getGrid()._emit("dragMove",t,this._dragEvent))},Xt.prototype._onScroll=function(t){var e,i,s,n=this._item;n._isActive?(this._scrollEvent=t,e=n._id,i=this._prepareScroll,s=this._applyScroll,k.add(e+H,i,s,!0)):this.stop()},Xt.prototype._prepareScroll=function(){var t=this._item;if(t._isActive){var e,i=t._element,s=this._getGrid(),n=s._settings,r=n.dragAxis,o=s._element,h=i.getBoundingClientRect(),a=this._elementClientX-h.left,_=this._elementClientY-h.top;this._container!==o&&(e=ct(this._containingBlock,o),this._containerDiffX=e.left,this._containerDiffY=e.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()}},Xt.prototype._applyScroll=function(){var t=this._item;t._isActive&&(t._element.style[n]=It(this._left,this._top),this._getGrid()._emit("dragScroll",t,this._scrollEvent))},Xt.prototype._onEnd=function(t){var e=this._item,i=e._element,s=this._getGrid(),n=s._settings,r=e._release;e._isActive?(N(e._id),q(e._id),n.dragSort&&this._checkOverlapDebounce("finish"),this._unbindScrollListeners(),r._containerDiffX=this._containerDiffX,r._containerDiffY=this._containerDiffY,this._reset(),Rt(i,n.itemDraggingClass),s._emit("dragEnd",e,t),this._isMigrating?this._finishMigration():r.start()):this.stop()},Gt.prototype._onLayoutStart=function(){var t=this._item,e=t.getGrid(),i=e._items.indexOf(t),s=e._layout.slots[2*i],n=e._layout.slots[2*i+1];if(this._didMigrate||t._left!==s||t._top!==n){var r,o,h;if(s+=t._marginLeft,n+=t._marginTop,!(e._settings.dragPlaceholder.duration>0)||this._didMigrate){F(t._id);var a={transform:It(s,n)};return this._animate.isAnimating()?this._animate.stop(a):f(this._element,a),void(this._didMigrate&&(e.getElement().appendChild(this._element),this._didMigrate=!1))}this._nextLeft=s,this._nextTop=n,r=t._id,o=this._setupAnimation,h=this._startAnimation,k.add(r+O,o,h)}},Gt.prototype._setupAnimation=function(){if(this.isActive()){var t=Lt(this._element);this._currentLeft=t.x,this._currentTop=t.y}},Gt.prototype._startAnimation=function(){if(this.isActive()){var t=this._animate,e=this._currentLeft,i=this._currentTop,s=this._nextLeft,n=this._nextTop,r={transform:It(s,n)};if(e!==s||i!==n){var o=this._item.getGrid()._settings.dragPlaceholder,h={transform:It(e,i)};t.start(h,r,{duration:o.duration,easing:o.easing,onFinish:this._onLayoutEnd})}else t.isAnimating()&&t.stop(r)}},Gt.prototype._onLayoutEnd=function(){this._resetAfterLayout&&this.reset()},Gt.prototype._onReleaseEnd=function(t){if(t._id===this._item._id){if(!this._animate.isAnimating())return void this.reset();this._resetAfterLayout=!0}},Gt.prototype._onMigrate=function(t){if(t.item===this._item){var e=this._item.getGrid(),i=t.toGrid;e.off("dragReleaseEnd",this._onReleaseEnd),e.off("layoutStart",this._onLayoutStart),e.off("beforeSend",this._onMigrate),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("layoutStart",this._onLayoutStart),i.on("beforeSend",this._onMigrate),this._didMigrate=!0}},Gt.prototype.create=function(){if(this.isActive())this._resetAfterLayout=!1;else{var t,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;t=c(s.dragPlaceholder.createElement)?s.dragPlaceholder.createElement(e):window.document.createElement("div"),this._element=t,n._element=t,this._className=s.itemPlaceholderClass||"",this._className&&j(t,this._className);var r=e._left+e._marginLeft,o=e._top+e._marginTop;f(t,{display:"block",position:"absolute",left:"0",top:"0",width:e._width+"px",height:e._height+"px",transform:It(r,o)}),i.on("layoutStart",this._onLayoutStart),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("beforeSend",this._onMigrate),c(s.dragPlaceholder.onCreate)&&s.dragPlaceholder.onCreate(e,t),i.getElement().appendChild(t)}},Gt.prototype.reset=function(){if(this.isActive()){var t=this._element,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;this._resetAfterLayout=!1,F(e._id),n.stop(),n._element=null,i.off("dragReleaseEnd",this._onReleaseEnd),i.off("layoutStart",this._onLayoutStart),i.off("beforeSend",this._onMigrate),this._className&&(Rt(t,this._className),this._className=""),t.parentNode.removeChild(t),this._element=null,c(s.dragPlaceholder.onRemove)&&s.dragPlaceholder.onRemove(e,t)}},Gt.prototype.updateDimensions=function(t,e){this.isActive()&&f(this._element,{width:t+"px",height:e+"px"})},Gt.prototype.isActive=function(){return!!this._element},Gt.prototype.destroy=function(){this.reset(),this._animate.destroy(),this._item=this._animate=null},Ht.prototype.add=function(t){return this._isDestroyed?this:(this._queue.push(t),this)},Ht.prototype.flush=function(t,e){if(this._isDestroyed)return this;var i,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,e),this;for(i=0;i0;return l&&this._queue.flush(!0,o),d&&(a._isPositioningStarted=!0),c(e)&&this._queue.add(e),m?(this._isActive=!0,this._animateOptions.easing=p,this._animateOptions.duration=u,this._isInterrupted=l,s=o._id,n=this._setupAnimation,r=this._startAnimation,k.add(s+X,n,r),this):(this._updateOffsets(),this._updateTargetStyles(),i=o._animate.isAnimating(),this.stop(!1,this._targetStyles),!i&&f(h,this._targetStyles),this._skipNextAnimation=!1,this._finish())}},Ot.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item;return i=s._id,k.cancel(i+X),s._animate.stop(e),Rt(s._element,s.getGrid()._settings.itemPositioningClass),this._isActive=!1,t&&this._queue.flush(!0,s),this},Ot.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)},Ot.prototype._updateOffsets=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._offsetLeft=i._isActive?i._containerDiffX:e._isActive?e._containerDiffX:0,this._offsetTop=i._isActive?i._containerDiffY:e._isActive?e._containerDiffY:0}},Ot.prototype._updateTargetStyles=function(){this._isDestroyed||(this._targetStyles.transform=It(this._item._left+this._offsetLeft,this._item._top+this._offsetTop))},Ot.prototype._finish=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._isActive&&(this._isActive=!1,Rt(t._element,t.getGrid()._settings.itemPositioningClass)),i._isActive&&i.stop(),e._isActive&&e.stop(),this._queue.flush(!1,t)}},Ot.prototype._setupAnimation=function(){var t=Lt(this._item._element);this._currentLeft=t.x,this._currentTop=t.y},Ot.prototype._startAnimation=function(){var t=this._item,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||j(t._element,e.itemPositioningClass),this._currentStyles.transform=It(this._currentLeft,this._currentTop),t._animate.start(this._currentStyles,this._targetStyles,this._animateOptions)};var Bt={};function Nt(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._container=!1,this._containerDiffX=0,this._containerDiffY=0}Nt.prototype.start=function(t,e,i){if(this._isDestroyed)return this;var s,r,o,h,a,_,l,d,c=this._item,u=c._element,p=c.isVisible(),m=c.getGrid(),g=m._settings,y=t._settings,v=t._element,w=t._items,S=m._items.indexOf(c),D=i||window.document.body;if("number"==typeof e)s=J(w,e,!0);else{if(!(r=t._getItem(e)))return this;s=w.indexOf(r)}return(c.isPositioning()||this._isActive||c.isReleasing())&&(l=(_=Lt(u)).x,d=_.y),c.isPositioning()&&c._layout.stop(!0,{transform:It(l,d)}),this._isActive&&(l-=this._containerDiffX,d-=this._containerDiffY,this.stop(!0,{transform:It(l,d)})),c.isReleasing()&&(l-=c._release._containerDiffX,d-=c._release._containerDiffY,c._release.stop(!0,{transform:It(l,d)})),c._visibility._stopAnimation(),c._drag&&c._drag.destroy(),c._visibility._queue.flush(!0,c),m._hasListeners("beforeSend")&&m._emit("beforeSend",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("beforeReceive")&&t._emit("beforeReceive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),Rt(u,g.itemClass),Rt(u,g.itemVisibleClass),Rt(u,g.itemHiddenClass),j(u,y.itemClass),j(u,p?y.itemVisibleClass:y.itemHiddenClass),m._items.splice(S,1),$(w,c,s),c._gridId=t._id,D!==(o=u.parentNode)&&(D.appendChild(u),h=ct(D,o,!0),_||(l=(_=Lt(u)).x,d=_.y),u.style[n]=It(l+h.left,d+h.top)),c._child.removeAttribute("style"),f(c._child,p?y.visibleStyles:y.hiddenStyles),u.style.display=p?"block":"hidden",a=ct(D,v,!0),c._refreshDimensions(),c._refreshSortData(),c._drag=y.dragEnabled?new Xt(c):null,this._isActive=!0,this._container=D,this._containerDiffX=a.left,this._containerDiffY=a.top,m._hasListeners("send")&&m._emit("send",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("receive")&&t._emit("receive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),this},Nt.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid()._element;return this._container!==r&&(e||(t?(i=Lt(n),Bt.transform=It(i.x-this._containerDiffX,i.y-this._containerDiffY)):Bt.transform=It(s._left,s._top),e=Bt),r.appendChild(n),f(n,e)),this._isActive=!1,this._container=null,this._containerDiffX=0,this._containerDiffY=0,this},Nt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)};var qt={};function Ft(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0}function zt(t){var e=t._isActive,i=t._element,s=t.getGrid()._settings;this._item=t,this._isDestroyed=!1,this._isHidden=!e,this._isHiding=!1,this._isShowing=!1,this._queue=new Ht,this._finishShow=this._finishShow.bind(this),this._finishHide=this._finishHide.bind(this),i.style.display=e?"block":"none",j(i,e?s.itemVisibleClass:s.itemHiddenClass),f(t._child,e?s.visibleStyles:s.hiddenStyles)}Ft.prototype.start=function(){if(this._isDestroyed||this._isActive)return this;var t=this._item,e=t.getGrid();return this._isActive=!0,j(t._element,e._settings.itemReleasingClass),e._emit("dragReleaseStart",t),t._layout.start(!1),this},Ft.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid(),o=r._element;return this._reset(),n.parentNode!==o&&(e||(t?(i=Lt(n),qt.transform=It(i.x-this._containerDiffX,i.y-this._containerDiffY)):qt.transform=It(s._left,s._top),e=qt),o.appendChild(n),f(n,e)),t||r._emit("dragReleaseEnd",s),this},Ft.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)},Ft.prototype._reset=function(){if(!this._isDestroyed){var t=this._item;this._isActive=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0,Rt(t._element,t.getGrid()._settings.itemReleasingClass)}},zt.prototype.show=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return this._isShowing||this._isHidden?this._isShowing&&!t?(r&&n.add(r),this):(this._isShowing||(n.flush(!0,i),Rt(s,o.itemHiddenClass),j(s,o.itemVisibleClass),this._isHiding||(s.style.display="block")),r&&n.add(r),i._isActive=this._isShowing=!0,this._isHiding=this._isHidden=!1,this._startAnimation(!0,t,this._finishShow),this):(r&&r(!1,i),this)},zt.prototype.hide=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return!this._isHiding&&this._isHidden?(r&&r(!1,i),this):this._isHiding&&!t?(r&&n.add(r),this):(this._isHiding||(n.flush(!0,i),j(s,o.itemHiddenClass),Rt(s,o.itemVisibleClass)),r&&n.add(r),this._isHidden=this._isHiding=!0,i._isActive=this._isShowing=!1,this._startAnimation(!1,t,this._finishHide),this)},zt.prototype.destroy=function(){if(this._isDestroyed)return this;var t=this._item,e=t._element,i=t.getGrid(),s=this._queue,n=i._settings;return this._stopAnimation({}),s.flush(!0,t).destroy(),Rt(e,n.itemVisibleClass),Rt(e,n.itemHiddenClass),this._item=null,this._isHiding=this._isShowing=!1,this._isDestroyed=this._isHidden=!0,this},zt.prototype._startAnimation=function(t,e,i){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,_=(t?r.showEasing:r.hideEasing)||"ease",d=e||h<=0;if(o){if(B(n._id),d)return n._animateChild.isAnimating()?n._animateChild.stop(o):f(n._child,o),void(i&&i());var c,u,p;c=n._id,u=function(){s=function(t,e){var i={};for(var s in e)i[s]=a(t,l(s));return i}(n._child,o)},p=function(){n._animateChild.start(s,o,{duration:h,easing:_,onFinish:i})},k.add(c+Y,u,p)}else i&&i()}},zt.prototype._stopAnimation=function(t){if(!this._isDestroyed){var e=this._item;B(e._id),e._animateChild.stop(t)}},zt.prototype._finishShow=function(){this._isHidden||(this._isShowing=!1,this._queue.flush(!1,this._item))};var Vt={};zt.prototype._finishHide=function(){if(this._isHidden){var t=this._item;this._isHiding=!1,Vt.transform=It(0,0),t._layout.stop(!0,Vt),t._element.style.display="none",this._queue.flush(!1,t)}};var Wt,jt,Ut,Zt,$t=0;function Jt(){return++$t}function Kt(t,e,i){var s=t._settings;this._id=Jt(),this._gridId=t._id,this._isDestroyed=!1,this._left=0,this._top=0,this._element=e,this._child=e.children[0],e.parentNode!==t._element&&t._element.appendChild(e),j(e,s.itemClass),"boolean"!=typeof i&&(i="none"!==a(e,"display")),this._isActive=i,e.style.left="0",e.style.top="0",e.style[n]=It(0,0),this._animate=new p(e),this._animateChild=new p(this._child),this._visibility=new zt(this),this._layout=new Ot(this),this._migrate=new Nt(this),this._release=new Ft(this),this._dragPlaceholder=new Gt(this),this._drag=s.dragEnabled?new Xt(this):null,this._refreshDimensions(),this._refreshSortData()}function Qt(){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)}Kt.prototype.getGrid=function(){return t[this._gridId]},Kt.prototype.getElement=function(){return this._element},Kt.prototype.getWidth=function(){return this._width},Kt.prototype.getHeight=function(){return this._height},Kt.prototype.getMargin=function(){return{left:this._marginLeft,right:this._marginRight,top:this._marginTop,bottom:this._marginBottom}},Kt.prototype.getPosition=function(){return{left:this._left,top:this._top}},Kt.prototype.isActive=function(){return this._isActive},Kt.prototype.isVisible=function(){return!!this._visibility&&!this._visibility._isHidden},Kt.prototype.isShowing=function(){return!(!this._visibility||!this._visibility._isShowing)},Kt.prototype.isHiding=function(){return!(!this._visibility||!this._visibility._isHiding)},Kt.prototype.isPositioning=function(){return!(!this._layout||!this._layout._isActive)},Kt.prototype.isDragging=function(){return!(!this._drag||!this._drag._isActive)},Kt.prototype.isReleasing=function(){return!(!this._release||!this._release._isActive)},Kt.prototype.isDestroyed=function(){return this._isDestroyed},Kt.prototype._refreshDimensions=function(){if(!this._isDestroyed&&!this._visibility._isHidden){var t=this._element,e=this._dragPlaceholder,i=t.getBoundingClientRect();this._width=i.width,this._height=i.height,this._marginLeft=Math.max(0,ht(t,"margin-left")),this._marginRight=Math.max(0,ht(t,"margin-right")),this._marginTop=Math.max(0,ht(t,"margin-top")),this._marginBottom=Math.max(0,ht(t,"margin-bottom")),e&&e.updateDimensions(this._width,this._height)}},Kt.prototype._refreshSortData=function(){if(!this._isDestroyed){var t,e=this._sortData={},i=this.getGrid()._settings.sortData;for(t in i)e[t]=i[t](this,this._element)}},Kt.prototype._destroy=function(t){if(!this._isDestroyed){var e=this._element,i=this.getGrid(),s=i._settings,n=i._items.indexOf(this);this._release.destroy(),this._migrate.destroy(),this._layout.destroy(),this._visibility.destroy(),this._animate.destroy(),this._animateChild.destroy(),this._dragPlaceholder.destroy(),this._drag&&this._drag.destroy(),e.removeAttribute("style"),this._child.removeAttribute("style"),Rt(e,s.itemClass),n>-1&&i._items.splice(n,1),t&&e.parentNode.removeChild(e),this._isActive=!1,this._isDestroyed=!0}},Qt.prototype.getLayout=function(t,e,i,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),c=this._slotSizes;if(o.slots=s||this._slots,o.width=a?0:d?Math.round(e):e,o.height=a?d?Math.round(i):i:0,o.setWidth=a,o.setHeight=!a,o.slots.length=0,c.length=0,!t.length)return o;for(r=0;rd.height&&(Wt.left>0&&u.push(this._addRect(0,d.height,Wt.left,1/0)),Wt.left+Wt.widthd.width&&(Wt.top>0&&u.push(this._addRect(d.width,0,1/0,Wt.top)),Wt.top+Wt.height.49&&r.height>.49&&(!e&&r.tope.left+e.width&&jt.push(this._addRect(e.left+e.width,t.top,t.left+t.width-(e.left+e.width),t.height)),t.tope.top+e.height&&jt.push(this._addRect(t.left,e.top+e.height,t.width,t.top+t.height-(e.top+e.height))),jt):(jt.push(this._addRect(t.left,t.top,t.width,t.height)),jt)}),Qt.prototype._doRectsOverlap=function(t,e){return!(t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top)},Qt.prototype._isRectWithinRect=function(t,e){return t.left>=e.left&&t.top>=e.top&&t.left+t.width<=e.left+e.width&&t.top+t.height<=e.top+e.height},Qt.prototype._purgeRects=(Ut={},Zt={},function(t){for(var e,i=t.length;i--;)if(e=t.length,t[i])for(this._getRect(t[i],Ut);e--;)if(t[e]&&i!==e&&this._isRectWithinRect(Ut,this._getRect(t[e],Zt))){t[i]=0;break}return t}),Qt.prototype._sortRectsTopLeft=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.tope.top?1:t.lefte.left?1:0}}(),Qt.prototype._sortRectsLeftTop=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.lefte.left?1:t.tope.top?1:0}}();var te="[object HTMLCollection]",ee="[object NodeList]";function ie(t){var e=Object.prototype.toString.call(t);return e===te||e===ee}var se="object",ne="[object Object]",re=Object.prototype.toString;function oe(t){return typeof t===se&&re.call(t)===ne}function he(t){return ie(t)?Array.prototype.slice.call(t):Array.prototype.concat(t)}var ae=new Qt,_e=function(){},le="number",de="string";function ce(e,s){var n,r,o,h=this;if(!((e=this._element=typeof e===de?window.document.querySelector(e):e).getRootNode?e.getRootNode({composed:!0})===document:window.document.body.contains(e))||e===window.document.documentElement)throw new Error("Container element must be an existing DOM element");c((n=this._settings=function(t,e){var i=ue({},t);e&&(i=ue(i,e));return i.visibleStyles=(e||0).visibleStyles||(t||0).visibleStyles,i.hiddenStyles=(e||0).hiddenStyles||(t||0).hiddenStyles,i}(ce.defaultOptions,s)).dragSort)||(n.dragSort=!!n.dragSort),this._id=Jt(),t[this._id]=h,this._isDestroyed=!1,this._layout={id:0,items:[],slots:[],setWidth:!1,setHeight:!1,width:0,height:0},this._emitter=new i,j(e,n.containerClass),this._items=[],typeof(r=n.items)===de?he(e.children).forEach(function(t){("*"===r||W(t,r))&&h._items.push(new Kt(h,t))}):(Array.isArray(r)||ie(r))&&(this._items=he(r).map(function(t){return new Kt(h,t)})),typeof(o=n.layoutOnResize)!==le&&(o=!0===o?0:-1),o>=0&&window.addEventListener("resize",h._resizeHandler=nt(function(){h.refreshItems().layout()},o)),n.layoutOnInit&&this.layout(!0)}function ue(t,e){var i,s,n,r=Object.keys(e),o=r.length;for(n=0;n0)){var s=o._layout.id!==l,n=c(t)?t:i;c(n)&&n(s,_.items.slice(0)),!s&&o._hasListeners(e)&&o._emit(e,_.items.slice(0))}}if((_.setHeight&&typeof _.height===le||_.setWidth&&typeof _.width===le)&&(s="border-box"===a(h,"box-sizing")),_.setHeight&&(typeof _.height===le?h.style.height=(s?_.height+this._borderTop+this._borderBottom:_.height)+"px":h.style.height=_.height),_.setWidth&&(typeof _.width===le?h.style.width=(s?_.width+this._borderLeft+this._borderRight:_.width)+"px":h.style.width=_.width),this._hasListeners("layoutStart")&&this._emit("layoutStart",_.items.slice(0)),!d)return f(),this;for(r=0;rl?1:0:ld?1:0)return c;return c||(s||(s=n(i)),c=r(o,h)),c}function h(o,h){var a=t(o,h);return e&&a&&(a=-a),a||(s||(s=n(i)),r(o,h))}return function(n,r){if(this._isDestroyed||this._items.length<2)return this;var a,_=this._items,l=r||0,d=l.layout?l.layout:void 0===l.layout;if(t=n,e=!!l.descending,i=_.slice(0),s=null,c(t))_.sort(h);else if(typeof t===de)t=n.trim().split(" ").map(function(t){return t.split(":")}),_.sort(o);else{if(!Array.isArray(t))return this;if(t.length!==_.length)throw new Error("[Muuri] sort reference items do not match with grid items.");for(a=0;a<_.length;a++){if(t.indexOf(_[a])<0)throw new Error("[Muuri] sort reference items do not match with grid items.");_[a]=t[a]}e&&_.reverse()}return this._hasListeners("sort")&&this._emit("sort",_.slice(0),i),d&&this.layout("instant"===d,c(d)?d:void 0),this}}(),ce.prototype.move=function(t,e,i){if(this._isDestroyed||this._items.length<2)return this;var s,n,r=this._items,o=i||0,h=o.layout?o.layout:void 0===o.layout,a="swap"===o.action,_=a?"swap":"move",l=this._getItem(t),d=this._getItem(e);return l&&d&&l!==d&&(s=r.indexOf(l),n=r.indexOf(d),a?Q(r,s,n):K(r,s,n),this._hasListeners("move")&&this._emit("move",{item:l,fromIndex:s,toIndex:n,action:_}),h&&this.layout("instant"===h,c(h)?h:void 0)),this},ce.prototype.send=function(t,e,i,s){if(this._isDestroyed||e._isDestroyed||this===e)return this;if(!(t=this._getItem(t)))return this;var n=s||0,r=n.appendTo||window.document.body,o=n.layoutSender?n.layoutSender:void 0===n.layoutSender,h=n.layoutReceiver?n.layoutReceiver:void 0===n.layoutReceiver;return t._migrate.start(e,i,r),t._migrate._isActive&&t._isActive&&(o&&this.layout("instant"===o,c(o)?o:void 0),h&&e.layout("instant"===h,c(h)?h:void 0)),this},ce.prototype.destroy=function(e){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-1?t:this._items.length+t]||null;if(t instanceof Kt)return t._gridId===this._id?t:null;for(var e=0;e-1||(M._activeInstances.push(t),M._emitter.on(D,t._onMove),M._emitter.on(A,t._onCancel),M._emitter.on(b,t._onEnd),1===M._activeInstances.length&&M._bindListeners())},M._deactivateInstance=function(t){var e=M._activeInstances.indexOf(t);-1!==e&&(M._activeInstances.splice(e,1),M._emitter.off(D,t._onMove),M._emitter.off(A,t._onCancel),M._emitter.off(b,t._onEnd),M._activeInstances.length||M._unbindListeners())},M._bindListeners=function(){var t=M._events;window.addEventListener(t.move,M._onMove,R),window.addEventListener(t.end,M._onEnd,R),t.cancel&&window.addEventListener(t.cancel,M._onCancel,R)},M._unbindListeners=function(){var t=M._events;window.removeEventListener(t.move,M._onMove,R),window.removeEventListener(t.end,M._onEnd,R),t.cancel&&window.removeEventListener(t.cancel,M._onCancel,R)},M._getEventPointerId=function(t){return"number"==typeof t.pointerId?t.pointerId:t.changedTouches?t.changedTouches[0]?t.changedTouches[0].identifier:null:1},M._getTouchById=function(t,e){if("number"==typeof t.pointerId)return t.pointerId===e?t:null;if(t.changedTouches){for(var i=0;i-1&&(this._queue[n]=void 0),s?this._queue.unshift(t):this._queue.push(t),this._reads[t]=e,this._writes[t]=i,this._nextStep||(this._nextStep=y(this._step))},T.prototype.cancel=function(t){var e=this._queue.indexOf(t);e>-1&&(this._queue[e]=void 0,delete this._reads[t],delete this._writes[t])},T.prototype._step=function(){var t,e,i=this._queue,s=this._reads,n=this._writes,r=this._batch,o=this._batchReads,h=this._batchWrites,a=i.length;for(this._nextStep=null,e=0;en?n:e<0?Math.max(n+e+1,0):e}function K(t,e,i){if(!(t.length<2)){var s=J(t,e),n=J(t,i);s!==n&&t.splice(n,0,t.splice(s,1)[0])}}function Q(t,e,i){if(!(t.length<2)){var s,n=J(t,e),r=J(t,i);n!==r&&(s=t[n],t[n]=t[r],t[r]=s)}}var tt="cancel",et="finish",it="debounce",st=0;function nt(t,e){var i,s=++st+it;return e>0?function(n){void 0!==i&&(i=window.clearTimeout(i),k.cancel(s),n===et&&t()),n!==tt&&n!==et&&(i=window.setTimeout(function(){i=void 0,k.add(s,t,null,!0)},e))}:function(e){e!==tt&&t()}}function rt(t){var e=a(t,"transform");if(!e||"none"===e)return!1;var i=a(t,"display");return"inline"!==i&&"none"!==i}function ot(t,e){for(var i=window.document,s=(e?t:t.parentElement)||i;s&&s!==i&&"static"===a(s,"position")&&!rt(s);)s=s.parentElement||i;return s}function ht(t,e){return parseFloat(a(t,e))||0}var at={},_t={},lt={};function dt(t,e){var i,s=e||{};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:(i=t.getBoundingClientRect(),s.left+=i.left,s.top+=i.top,s.left+=ht(t,"border-left-width"),s.top+=ht(t,"border-top-width"),s))}function ct(t,e,i){return lt.left=0,lt.top=0,t===e?lt:i&&(t=ot(t,!0))===(e=ot(e,!0))?lt:(dt(t,at),dt(e,_t),lt.left=_t.left-at.left,lt.top=_t.top-at.top,lt)}var ut="overflow",ft="overflow-x",pt="overflow-y",mt="auto",gt="scroll";function yt(t){var e=a(t,ut);return e===mt||e===gt||((e=a(t,ft))===mt||e===gt||((e=a(t,pt))===mt||e===gt))}function vt(t,e,i){for(var s=i||[],n=e?t:t.parentNode;n&&n!==document;)n.getRootNode&&n instanceof DocumentFragment?n=n.getRootNode().host:(yt(n)&&s.push(n),n=n.parentNode);return s.push(window),s}var wt={},St="transform",Dt="none",bt=/^matrix3d/,At=/([^,]*,){4}/,Et=/([^,]*,){12}/,Ct=/[^,]*,/;function Lt(t){wt.x=0,wt.y=0;var e=a(t,St);if(!e||e===Dt)return wt;var i=bt.test(e),s=e.replace(i?Et:At,""),n=s.replace(Ct,"");return wt.x=parseFloat(s)||0,wt.y=parseFloat(n)||0,wt}function It(t,e){return"translateX("+t+"px) translateY("+e+"px)"}function Rt(t,e){t.classList?t.classList.remove(e):W(t,"."+e)&&(t.className=(" "+t.className+" ").replace(" "+e+" "," ").trim())}var xt,Pt,Mt,Tt,kt=0;function Xt(t){var e=t._element,i=t.getGrid(),s=i._settings;this._item=t,this._gridId=i._id,this._isDestroyed=!1,this._isMigrating=!1,this._startPredicate=c(s.dragStartPredicate)?s.dragStartPredicate:Xt.defaultStartPredicate,this._startPredicateState=kt,this._startPredicateResult=void 0,this._hBlockedIndex=null,this._hX1=0,this._hX2=0,this._hY1=0,this._hY2=0,this._reset(),this._preStartCheck=this._preStartCheck.bind(this),this._preEndCheck=this._preEndCheck.bind(this),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);var n=s.dragSortHeuristics.sortInterval;this._checkOverlapDebounce=nt(this._checkOverlap,n),this._dragger=new M(e,s.dragCssProps),this._dragger.on("start",this._preStartCheck),this._dragger.on("move",this._preStartCheck),this._dragger.on("cancel",this._preEndCheck),this._dragger.on("end",this._preEndCheck)}function Yt(t,e){return t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top?0:(Math.min(t.left+t.width,e.left+e.width)-Math.max(t.left,e.left))*(Math.min(t.top+t.height,e.top+e.height)-Math.max(t.top,e.top))/(Math.min(t.width,e.width)*Math.min(t.height,e.height))*100}function Gt(t){this._item=t,this._animate=new p,this._element=null,this._className="",this._didMigrate=!1,this._resetAfterLayout=!1,this._currentLeft=0,this._currentTop=0,this._nextLeft=0,this._nextTop=0,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this),this._onLayoutStart=this._onLayoutStart.bind(this),this._onLayoutEnd=this._onLayoutEnd.bind(this),this._onReleaseEnd=this._onReleaseEnd.bind(this),this._onMigrate=this._onMigrate.bind(this)}function Ht(){this._queue=[],this._isDestroyed=!1}function Ot(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 Ht,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this)}Xt.defaultStartPredicate=function(t,e,i){var s=t._drag,n=s._startPredicateData||s._setupStartPredicate(i);if(!e.isFinal)return!(!n.handleElement&&(n.handleElement=s._getStartPredicateHandle(e),!n.handleElement))&&(n.delay&&(n.event=e,n.delayTimer||(n.delayTimer=window.setTimeout(function(){n.delay=0,s._resolveStartPredicate(n.event)&&(s._forceResolveStartPredicate(n.event),s._resetStartPredicate())},n.delay))),s._resolveStartPredicate(e));s._finishStartPredicate(e)},Xt.defaultSortPredicate=(xt={},Pt={},Mt={},Tt=[],function(t,e){var i=t._drag,s=i._getGrid(),n=e&&"number"==typeof e.threshold?e.threshold:50,r=e&&"swap"===e.action?"swap":"move",o=e&&"swap"===e.migrateAction?"swap":"move";xt.width=t._width,xt.height=t._height,xt.left=i._elementClientX,xt.top=i._elementClientY;var h=function(t,e,i){var s,n,r,o,h=null,a=e._settings.dragSort,_=-1;if(!0===a?(Tt[0]=e,n=Tt):c(a)&&(n=a.call(e,t)),!n||!Array.isArray(n)||!n.length)return h;for(o=0;oi&&s>_&&(_=s,h=r));return Tt.length=0,h}(t,s,n);if(!h)return!1;var a,_,l,d,u,f=t.getGrid()!==h,p=0,m=0,g=-1;for(h===s?(xt.left=i._gridX+t._marginLeft,xt.top=i._gridY+t._marginTop):(h._updateBorders(1,0,1,0),p=h._left+h._borderLeft,m=h._top+h._borderTop),u=0;ug&&(a=u,g=d));return g0?a:-1:0,g=n),g>=n&&(Mt.grid=h,Mt.index=a,Mt.action=f?o:r,Mt)}),Xt.prototype.stop=function(){var t=this._item,e=t._element,i=this._getGrid();return this._isActive?this._isMigrating?(this._finishMigration(),this):(N(t._id),q(t._id),this._unbindScrollListeners(),this._checkOverlapDebounce("cancel"),e.parentNode!==i._element&&(i._element.appendChild(e),e.style[n]=It(this._gridX,this._gridY)),Rt(e,i._settings.itemDraggingClass),this._reset(),this):this},Xt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(),this._dragger.destroy(),this._isDestroyed=!0,this)},Xt.prototype._getGrid=function(){return t[this._gridId]||null},Xt.prototype._reset=function(){this._isActive=!1,this._container=null,this._containingBlock=null,this._dragEvent=null,this._scrollEvent=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},Xt.prototype._bindScrollListeners=function(){var t,e,i=this._getGrid()._element,s=this._container,n=this._scrollers;if(n.length=0,vt(this._item._element,!1,n),s!==i)for(vt(i,!0,t=[]),e=0;e=s&&t.pageX=n&&t.pageY3&&e.minBounceBackAngle>0;if(h||(this._hBlockedIndex=null),Math.abs(r)>i||Math.abs(o)>i){if(h){var a=Math.atan2(r,o),_=Math.atan2(this._hX2-this._hX1,this._hY2-this._hY1),l=Math.atan2(Math.sin(a-_),Math.cos(a-_));Math.abs(l)>e.minBounceBackAngle&&(this._hBlockedIndex=null)}return this._hX1=this._hX2,this._hY1=this._hY2,this._hX2=s,this._hY2=n,!0}return!1},Xt.prototype._resetStartPredicate=function(){var t=this._startPredicateData;t&&(t.delayTimer&&(t.delayTimer=window.clearTimeout(t.delayTimer)),this._startPredicateData=null)},Xt.prototype._checkOverlap=function(){if(this._isActive){var t,e,i,s,n,r,o,h,a=this._item,_=this._getGrid()._settings;(t=c(_.dragSortPredicate)?_.dragSortPredicate(a,this._dragEvent):Xt.defaultSortPredicate(a,_.dragSortPredicate))&&"number"==typeof t.index&&(h=(e=a.getGrid())!==(s=t.grid||e),i=e._items.indexOf(a),n=J(s._items,t.index,h),o="swap"===t.action?"swap":"move",(h||n!==this._hBlockedIndex)&&(h?(this._hBlockedIndex=null,r=s._items[n],e._hasListeners("beforeSend")&&e._emit("beforeSend",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("beforeReceive")&&s._emit("beforeReceive",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),a._gridId=s._id,this._isMigrating=a._gridId!==this._gridId,e._items.splice(i,1),$(s._items,a,n),a._sortData=null,e._hasListeners("send")&&e._emit("send",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("receive")&&s._emit("receive",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),"swap"===o&&r&&r.isActive()&&s._items.indexOf(r)>-1&&s.send(r,e,i,{appendTo:this._container||window.document.body,layoutSender:!1,layoutReceiver:!1}),e.layout(),s.layout()):i!==n&&(this._hBlockedIndex=i,("swap"===o?Q:K)(e._items,i,n),e._hasListeners("move")&&e._emit("move",{item:a,fromIndex:i,toIndex:n,action:o}),e.layout())))}},Xt.prototype._finishMigration=function(){var t,e,i=this._item,s=i._release,r=i._element,o=i._isActive,h=i.getGrid(),a=h._element,_=h._settings,l=_.dragContainer||a,d=this._getGrid()._settings,c=r.parentNode;this._isMigrating=!1,this.destroy(),Rt(r,d.itemClass),Rt(r,d.itemVisibleClass),Rt(r,d.itemHiddenClass),j(r,_.itemClass),j(r,o?_.itemVisibleClass:_.itemHiddenClass),l!==c&&(l.appendChild(r),e=ct(c,l,!0),(t=Lt(r)).x-=e.left,t.y-=e.top),i._refreshDimensions(),i._refreshSortData(),e=ct(l,a,!0),s._containerDiffX=e.left,s._containerDiffY=e.top,i._drag=_.dragEnabled?new Xt(i):null,l!==c&&(r.style[n]=It(t.x,t.y)),i._child.removeAttribute("style"),f(i._child,o?_.visibleStyles:_.hiddenStyles),s.start()},Xt.prototype._preStartCheck=function(t){this._startPredicateState===kt&&(this._startPredicateState=1),1===this._startPredicateState?(this._startPredicateResult=this._startPredicate(this._item,t),!0===this._startPredicateResult?(this._startPredicateState=2,this._onStart(t)):!1===this._startPredicateResult&&(this._startPredicateState=3)):2===this._startPredicateState&&this._isActive&&this._onMove(t)},Xt.prototype._preEndCheck=function(t){var e=2===this._startPredicateState;this._startPredicate(this._item,t),this._startPredicateState=kt,e&&this._isActive&&this._onEnd(t)},Xt.prototype._onStart=function(t){var e=this._item;if(e._isActive){var i,s=e._element,r=this._getGrid(),o=r._settings,h=e._release,a=e._migrate,_=r._element,l=o.dragContainer||_,d=ot(l,!0),c=Lt(s),u=c.x,f=c.y,p=s.getBoundingClientRect(),m=l!==_;this._resetHeuristics(t),m&&(i=ct(d,_)),e.isPositioning()&&e._layout.stop(!0,{transform:It(u,f)}),a._isActive&&(u-=a._containerDiffX,f-=a._containerDiffY,a.stop(!0,{transform:It(u,f)})),e.isReleasing()&&h._reset(),this._isActive=!0,this._dragEvent=t,this._container=l,this._containingBlock=d,this._elementClientX=p.left,this._elementClientY=p.top,this._left=this._gridX=u,this._top=this._gridY=f,o.dragPlaceholder.enabled&&e._dragPlaceholder.create(),r._emit("dragInit",e,t),m&&(this._containerDiffX=i.left,this._containerDiffY=i.top,s.parentNode===l?(this._gridX=u-this._containerDiffX,this._gridY=f-this._containerDiffY):(this._left=u+this._containerDiffX,this._top=f+this._containerDiffY,l.appendChild(s),s.style[n]=It(this._left,this._top))),j(s,o.itemDraggingClass),this._bindScrollListeners(),r._emit("dragStart",e,t)}},Xt.prototype._onMove=function(t){var e=this._item;if(e._isActive){var i,s,n,r=this._getGrid()._settings.dragAxis;if("y"!==r){var o=t.clientX-this._dragEvent.clientX;this._left+=o,this._gridX+=o,this._elementClientX+=o}if("x"!==r){var h=t.clientY-this._dragEvent.clientY;this._top+=h,this._gridY+=h,this._elementClientY+=h}this._dragEvent=t,i=e._id,s=this._prepareMove,n=this._applyMove,k.add(i+G,s,n,!0)}else this.stop()},Xt.prototype._prepareMove=function(){this._item._isActive&&this._getGrid()._settings.dragSort&&this._checkHeuristics(this._dragEvent)&&this._checkOverlapDebounce()},Xt.prototype._applyMove=function(){var t=this._item;t._isActive&&(t._element.style[n]=It(this._left,this._top),this._getGrid()._emit("dragMove",t,this._dragEvent))},Xt.prototype._onScroll=function(t){var e,i,s,n=this._item;n._isActive?(this._scrollEvent=t,e=n._id,i=this._prepareScroll,s=this._applyScroll,k.add(e+H,i,s,!0)):this.stop()},Xt.prototype._prepareScroll=function(){var t=this._item;if(t._isActive){var e,i=t._element,s=this._getGrid(),n=s._settings,r=n.dragAxis,o=s._element,h=i.getBoundingClientRect(),a=this._elementClientX-h.left,_=this._elementClientY-h.top;this._container!==o&&(e=ct(this._containingBlock,o),this._containerDiffX=e.left,this._containerDiffY=e.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()}},Xt.prototype._applyScroll=function(){var t=this._item;t._isActive&&(t._element.style[n]=It(this._left,this._top),this._getGrid()._emit("dragScroll",t,this._scrollEvent))},Xt.prototype._onEnd=function(t){var e=this._item,i=e._element,s=this._getGrid(),n=s._settings,r=e._release;e._isActive?(N(e._id),q(e._id),n.dragSort&&this._checkOverlapDebounce("finish"),this._unbindScrollListeners(),r._containerDiffX=this._containerDiffX,r._containerDiffY=this._containerDiffY,this._reset(),Rt(i,n.itemDraggingClass),s._emit("dragEnd",e,t),this._isMigrating?this._finishMigration():r.start()):this.stop()},Gt.prototype._onLayoutStart=function(){var t=this._item,e=t.getGrid(),i=e._items.indexOf(t),s=e._layout.slots[2*i],n=e._layout.slots[2*i+1];if(this._didMigrate||t._left!==s||t._top!==n){var r,o,h;if(s+=t._marginLeft,n+=t._marginTop,!(e._settings.dragPlaceholder.duration>0)||this._didMigrate){F(t._id);var a={transform:It(s,n)};return this._animate.isAnimating()?this._animate.stop(a):f(this._element,a),void(this._didMigrate&&(e.getElement().appendChild(this._element),this._didMigrate=!1))}this._nextLeft=s,this._nextTop=n,r=t._id,o=this._setupAnimation,h=this._startAnimation,k.add(r+O,o,h)}},Gt.prototype._setupAnimation=function(){if(this.isActive()){var t=Lt(this._element);this._currentLeft=t.x,this._currentTop=t.y}},Gt.prototype._startAnimation=function(){if(this.isActive()){var t=this._animate,e=this._currentLeft,i=this._currentTop,s=this._nextLeft,n=this._nextTop,r={transform:It(s,n)};if(e!==s||i!==n){var o=this._item.getGrid()._settings.dragPlaceholder,h={transform:It(e,i)};t.start(h,r,{duration:o.duration,easing:o.easing,onFinish:this._onLayoutEnd})}else t.isAnimating()&&t.stop(r)}},Gt.prototype._onLayoutEnd=function(){this._resetAfterLayout&&this.reset()},Gt.prototype._onReleaseEnd=function(t){if(t._id===this._item._id){if(!this._animate.isAnimating())return void this.reset();this._resetAfterLayout=!0}},Gt.prototype._onMigrate=function(t){if(t.item===this._item){var e=this._item.getGrid(),i=t.toGrid;e.off("dragReleaseEnd",this._onReleaseEnd),e.off("layoutStart",this._onLayoutStart),e.off("beforeSend",this._onMigrate),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("layoutStart",this._onLayoutStart),i.on("beforeSend",this._onMigrate),this._didMigrate=!0}},Gt.prototype.create=function(){if(this.isActive())this._resetAfterLayout=!1;else{var t,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;t=c(s.dragPlaceholder.createElement)?s.dragPlaceholder.createElement(e):window.document.createElement("div"),this._element=t,n._element=t,this._className=s.itemPlaceholderClass||"",this._className&&j(t,this._className);var r=e._left+e._marginLeft,o=e._top+e._marginTop;f(t,{display:"block",position:"absolute",left:"0",top:"0",width:e._width+"px",height:e._height+"px",transform:It(r,o)}),i.on("layoutStart",this._onLayoutStart),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("beforeSend",this._onMigrate),c(s.dragPlaceholder.onCreate)&&s.dragPlaceholder.onCreate(e,t),i.getElement().appendChild(t)}},Gt.prototype.reset=function(){if(this.isActive()){var t=this._element,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;this._resetAfterLayout=!1,F(e._id),n.stop(),n._element=null,i.off("dragReleaseEnd",this._onReleaseEnd),i.off("layoutStart",this._onLayoutStart),i.off("beforeSend",this._onMigrate),this._className&&(Rt(t,this._className),this._className=""),t.parentNode.removeChild(t),this._element=null,c(s.dragPlaceholder.onRemove)&&s.dragPlaceholder.onRemove(e,t)}},Gt.prototype.updateDimensions=function(t,e){this.isActive()&&f(this._element,{width:t+"px",height:e+"px"})},Gt.prototype.isActive=function(){return!!this._element},Gt.prototype.destroy=function(){this.reset(),this._animate.destroy(),this._item=this._animate=null},Ht.prototype.add=function(t){return this._isDestroyed?this:(this._queue.push(t),this)},Ht.prototype.flush=function(t,e){if(this._isDestroyed)return this;var i,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,e),this;for(i=0;i0;return l&&this._queue.flush(!0,o),d&&(a._isPositioningStarted=!0),c(e)&&this._queue.add(e),m?(this._isActive=!0,this._animateOptions.easing=p,this._animateOptions.duration=u,this._isInterrupted=l,s=o._id,n=this._setupAnimation,r=this._startAnimation,k.add(s+X,n,r),this):(this._updateOffsets(),this._updateTargetStyles(),i=o._animate.isAnimating(),this.stop(!1,this._targetStyles),!i&&f(h,this._targetStyles),this._skipNextAnimation=!1,this._finish())}},Ot.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item;return i=s._id,k.cancel(i+X),s._animate.stop(e),Rt(s._element,s.getGrid()._settings.itemPositioningClass),this._isActive=!1,t&&this._queue.flush(!0,s),this},Ot.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)},Ot.prototype._updateOffsets=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._offsetLeft=i._isActive?i._containerDiffX:e._isActive?e._containerDiffX:0,this._offsetTop=i._isActive?i._containerDiffY:e._isActive?e._containerDiffY:0}},Ot.prototype._updateTargetStyles=function(){this._isDestroyed||(this._targetStyles.transform=It(this._item._left+this._offsetLeft,this._item._top+this._offsetTop))},Ot.prototype._finish=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._isActive&&(this._isActive=!1,Rt(t._element,t.getGrid()._settings.itemPositioningClass)),i._isActive&&i.stop(),e._isActive&&e.stop(),this._queue.flush(!1,t)}},Ot.prototype._setupAnimation=function(){var t=Lt(this._item._element);this._currentLeft=t.x,this._currentTop=t.y},Ot.prototype._startAnimation=function(){var t=this._item,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||j(t._element,e.itemPositioningClass),this._currentStyles.transform=It(this._currentLeft,this._currentTop),t._animate.start(this._currentStyles,this._targetStyles,this._animateOptions)};var Bt={};function Nt(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._container=!1,this._containerDiffX=0,this._containerDiffY=0}Nt.prototype.start=function(t,e,i){if(this._isDestroyed)return this;var s,r,o,h,a,_,l,d,c=this._item,u=c._element,p=c.isVisible(),m=c.getGrid(),g=m._settings,y=t._settings,v=t._element,w=t._items,S=m._items.indexOf(c),D=i||window.document.body;if("number"==typeof e)s=J(w,e,!0);else{if(!(r=t._getItem(e)))return this;s=w.indexOf(r)}return(c.isPositioning()||this._isActive||c.isReleasing())&&(l=(_=Lt(u)).x,d=_.y),c.isPositioning()&&c._layout.stop(!0,{transform:It(l,d)}),this._isActive&&(l-=this._containerDiffX,d-=this._containerDiffY,this.stop(!0,{transform:It(l,d)})),c.isReleasing()&&(l-=c._release._containerDiffX,d-=c._release._containerDiffY,c._release.stop(!0,{transform:It(l,d)})),c._visibility._stopAnimation(),c._drag&&c._drag.destroy(),c._visibility._queue.flush(!0,c),m._hasListeners("beforeSend")&&m._emit("beforeSend",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("beforeReceive")&&t._emit("beforeReceive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),Rt(u,g.itemClass),Rt(u,g.itemVisibleClass),Rt(u,g.itemHiddenClass),j(u,y.itemClass),j(u,p?y.itemVisibleClass:y.itemHiddenClass),m._items.splice(S,1),$(w,c,s),c._gridId=t._id,D!==(o=u.parentNode)&&(D.appendChild(u),h=ct(D,o,!0),_||(l=(_=Lt(u)).x,d=_.y),u.style[n]=It(l+h.left,d+h.top)),c._child.removeAttribute("style"),f(c._child,p?y.visibleStyles:y.hiddenStyles),u.style.display=p?"block":"hidden",a=ct(D,v,!0),c._refreshDimensions(),c._refreshSortData(),c._drag=y.dragEnabled?new Xt(c):null,this._isActive=!0,this._container=D,this._containerDiffX=a.left,this._containerDiffY=a.top,m._hasListeners("send")&&m._emit("send",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("receive")&&t._emit("receive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),this},Nt.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid()._element;return this._container!==r&&(e||(t?(i=Lt(n),Bt.transform=It(i.x-this._containerDiffX,i.y-this._containerDiffY)):Bt.transform=It(s._left,s._top),e=Bt),r.appendChild(n),f(n,e)),this._isActive=!1,this._container=null,this._containerDiffX=0,this._containerDiffY=0,this},Nt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)};var qt={};function Ft(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0}function zt(t){var e=t._isActive,i=t._element,s=t.getGrid()._settings;this._item=t,this._isDestroyed=!1,this._isHidden=!e,this._isHiding=!1,this._isShowing=!1,this._queue=new Ht,this._finishShow=this._finishShow.bind(this),this._finishHide=this._finishHide.bind(this),i.style.display=e?"block":"none",j(i,e?s.itemVisibleClass:s.itemHiddenClass),f(t._child,e?s.visibleStyles:s.hiddenStyles)}Ft.prototype.start=function(){if(this._isDestroyed||this._isActive)return this;var t=this._item,e=t.getGrid();return this._isActive=!0,j(t._element,e._settings.itemReleasingClass),e._emit("dragReleaseStart",t),t._layout.start(!1),this},Ft.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid(),o=r._element;return this._reset(),n.parentNode!==o&&(e||(t?(i=Lt(n),qt.transform=It(i.x-this._containerDiffX,i.y-this._containerDiffY)):qt.transform=It(s._left,s._top),e=qt),o.appendChild(n),f(n,e)),t||r._emit("dragReleaseEnd",s),this},Ft.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)},Ft.prototype._reset=function(){if(!this._isDestroyed){var t=this._item;this._isActive=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0,Rt(t._element,t.getGrid()._settings.itemReleasingClass)}},zt.prototype.show=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return this._isShowing||this._isHidden?this._isShowing&&!t?(r&&n.add(r),this):(this._isShowing||(n.flush(!0,i),Rt(s,o.itemHiddenClass),j(s,o.itemVisibleClass),this._isHiding||(s.style.display="block")),r&&n.add(r),i._isActive=this._isShowing=!0,this._isHiding=this._isHidden=!1,this._startAnimation(!0,t,this._finishShow),this):(r&&r(!1,i),this)},zt.prototype.hide=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return!this._isHiding&&this._isHidden?(r&&r(!1,i),this):this._isHiding&&!t?(r&&n.add(r),this):(this._isHiding||(n.flush(!0,i),j(s,o.itemHiddenClass),Rt(s,o.itemVisibleClass)),r&&n.add(r),this._isHidden=this._isHiding=!0,i._isActive=this._isShowing=!1,this._startAnimation(!1,t,this._finishHide),this)},zt.prototype.destroy=function(){if(this._isDestroyed)return this;var t=this._item,e=t._element,i=t.getGrid(),s=this._queue,n=i._settings;return this._stopAnimation({}),s.flush(!0,t).destroy(),Rt(e,n.itemVisibleClass),Rt(e,n.itemHiddenClass),this._item=null,this._isHiding=this._isShowing=!1,this._isDestroyed=this._isHidden=!0,this},zt.prototype._startAnimation=function(t,e,i){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,_=(t?r.showEasing:r.hideEasing)||"ease",d=e||h<=0;if(o){if(B(n._id),d)return n._animateChild.isAnimating()?n._animateChild.stop(o):f(n._child,o),void(i&&i());var c,u,p;c=n._id,u=function(){s=function(t,e){var i={};for(var s in e)i[s]=a(t,l(s));return i}(n._child,o)},p=function(){n._animateChild.start(s,o,{duration:h,easing:_,onFinish:i})},k.add(c+Y,u,p)}else i&&i()}},zt.prototype._stopAnimation=function(t){if(!this._isDestroyed){var e=this._item;B(e._id),e._animateChild.stop(t)}},zt.prototype._finishShow=function(){this._isHidden||(this._isShowing=!1,this._queue.flush(!1,this._item))};var Vt={};zt.prototype._finishHide=function(){if(this._isHidden){var t=this._item;this._isHiding=!1,Vt.transform=It(0,0),t._layout.stop(!0,Vt),t._element.style.display="none",this._queue.flush(!1,t)}};var Wt,jt,Ut,Zt,$t=0;function Jt(){return++$t}function Kt(t,e,i){var s=t._settings;this._id=Jt(),this._gridId=t._id,this._isDestroyed=!1,this._left=0,this._top=0,this._element=e,this._child=e.children[0],e.parentNode!==t._element&&t._element.appendChild(e),j(e,s.itemClass),"boolean"!=typeof i&&(i="none"!==a(e,"display")),this._isActive=i,e.style.left="0",e.style.top="0",e.style[n]=It(0,0),this._animate=new p(e),this._animateChild=new p(this._child),this._visibility=new zt(this),this._layout=new Ot(this),this._migrate=new Nt(this),this._release=new Ft(this),this._dragPlaceholder=new Gt(this),this._drag=s.dragEnabled?new Xt(this):null,this._refreshDimensions(),this._refreshSortData()}function Qt(){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)}Kt.prototype.getGrid=function(){return t[this._gridId]},Kt.prototype.getElement=function(){return this._element},Kt.prototype.getWidth=function(){return this._width},Kt.prototype.getHeight=function(){return this._height},Kt.prototype.getMargin=function(){return{left:this._marginLeft,right:this._marginRight,top:this._marginTop,bottom:this._marginBottom}},Kt.prototype.getPosition=function(){return{left:this._left,top:this._top}},Kt.prototype.isActive=function(){return this._isActive},Kt.prototype.isVisible=function(){return!!this._visibility&&!this._visibility._isHidden},Kt.prototype.isShowing=function(){return!(!this._visibility||!this._visibility._isShowing)},Kt.prototype.isHiding=function(){return!(!this._visibility||!this._visibility._isHiding)},Kt.prototype.isPositioning=function(){return!(!this._layout||!this._layout._isActive)},Kt.prototype.isDragging=function(){return!(!this._drag||!this._drag._isActive)},Kt.prototype.isReleasing=function(){return!(!this._release||!this._release._isActive)},Kt.prototype.isDestroyed=function(){return this._isDestroyed},Kt.prototype._refreshDimensions=function(){if(!this._isDestroyed&&!this._visibility._isHidden){var t=this._element,e=this._dragPlaceholder,i=t.getBoundingClientRect();this._width=i.width,this._height=i.height,this._marginLeft=Math.max(0,ht(t,"margin-left")),this._marginRight=Math.max(0,ht(t,"margin-right")),this._marginTop=Math.max(0,ht(t,"margin-top")),this._marginBottom=Math.max(0,ht(t,"margin-bottom")),e&&e.updateDimensions(this._width,this._height)}},Kt.prototype._refreshSortData=function(){if(!this._isDestroyed){var t,e=this._sortData={},i=this.getGrid()._settings.sortData;for(t in i)e[t]=i[t](this,this._element)}},Kt.prototype._destroy=function(t){if(!this._isDestroyed){var e=this._element,i=this.getGrid(),s=i._settings,n=i._items.indexOf(this);this._release.destroy(),this._migrate.destroy(),this._layout.destroy(),this._visibility.destroy(),this._animate.destroy(),this._animateChild.destroy(),this._dragPlaceholder.destroy(),this._drag&&this._drag.destroy(),e.removeAttribute("style"),this._child.removeAttribute("style"),Rt(e,s.itemClass),n>-1&&i._items.splice(n,1),t&&e.parentNode.removeChild(e),this._isActive=!1,this._isDestroyed=!0}},Qt.prototype.getLayout=function(t,e,i,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),c=this._slotSizes;if(o.slots=s||this._slots,o.width=a?0:d?Math.round(e):e,o.height=a?d?Math.round(i):i:0,o.setWidth=a,o.setHeight=!a,o.slots.length=0,c.length=0,!t.length)return o;for(r=0;rd.height&&(Wt.left>0&&u.push(this._addRect(0,d.height,Wt.left,1/0)),Wt.left+Wt.widthd.width&&(Wt.top>0&&u.push(this._addRect(d.width,0,1/0,Wt.top)),Wt.top+Wt.height.49&&r.height>.49&&(!e&&r.tope.left+e.width&&jt.push(this._addRect(e.left+e.width,t.top,t.left+t.width-(e.left+e.width),t.height)),t.tope.top+e.height&&jt.push(this._addRect(t.left,e.top+e.height,t.width,t.top+t.height-(e.top+e.height))),jt):(jt.push(this._addRect(t.left,t.top,t.width,t.height)),jt)}),Qt.prototype._doRectsOverlap=function(t,e){return!(t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top)},Qt.prototype._isRectWithinRect=function(t,e){return t.left>=e.left&&t.top>=e.top&&t.left+t.width<=e.left+e.width&&t.top+t.height<=e.top+e.height},Qt.prototype._purgeRects=(Ut={},Zt={},function(t){for(var e,i=t.length;i--;)if(e=t.length,t[i])for(this._getRect(t[i],Ut);e--;)if(t[e]&&i!==e&&this._isRectWithinRect(Ut,this._getRect(t[e],Zt))){t[i]=0;break}return t}),Qt.prototype._sortRectsTopLeft=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.tope.top?1:t.lefte.left?1:0}}(),Qt.prototype._sortRectsLeftTop=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.lefte.left?1:t.tope.top?1:0}}();var te="[object HTMLCollection]",ee="[object NodeList]";function ie(t){var e=Object.prototype.toString.call(t);return e===te||e===ee}var se="object",ne="[object Object]",re=Object.prototype.toString;function oe(t){return typeof t===se&&re.call(t)===ne}function he(t){return ie(t)?Array.prototype.slice.call(t):Array.prototype.concat(t)}var ae=new Qt,_e=function(){},le="number",de="string";function ce(e,s){var n,r,o,h=this;if(!((e=this._element=typeof e===de?window.document.querySelector(e):e).getRootNode?e.getRootNode({composed:!0})===document:window.document.body.contains(e))||e===window.document.documentElement)throw new Error("Container element must be an existing DOM element");c((n=this._settings=function(t,e){var i=ue({},t);e&&(i=ue(i,e));return i.visibleStyles=(e||0).visibleStyles||(t||0).visibleStyles,i.hiddenStyles=(e||0).hiddenStyles||(t||0).hiddenStyles,i}(ce.defaultOptions,s)).dragSort)||(n.dragSort=!!n.dragSort),this._id=Jt(),t[this._id]=h,this._isDestroyed=!1,this._layout={id:0,items:[],slots:[],setWidth:!1,setHeight:!1,width:0,height:0},this._emitter=new i,j(e,n.containerClass),this._items=[],typeof(r=n.items)===de?he(e.children).forEach(function(t){("*"===r||W(t,r))&&h._items.push(new Kt(h,t))}):(Array.isArray(r)||ie(r))&&(this._items=he(r).map(function(t){return new Kt(h,t)})),typeof(o=n.layoutOnResize)!==le&&(o=!0===o?0:-1),o>=0&&window.addEventListener("resize",h._resizeHandler=nt(function(){h.refreshItems().layout()},o)),n.layoutOnInit&&this.layout(!0)}function ue(t,e){var i,s,n,r=Object.keys(e),o=r.length;for(n=0;n0)){var s=o._layout.id!==l,n=c(t)?t:i;c(n)&&n(s,_.items.slice(0)),!s&&o._hasListeners(e)&&o._emit(e,_.items.slice(0))}}if((_.setHeight&&typeof _.height===le||_.setWidth&&typeof _.width===le)&&(s="border-box"===a(h,"box-sizing")),_.setHeight&&(typeof _.height===le?h.style.height=(s?_.height+this._borderTop+this._borderBottom:_.height)+"px":h.style.height=_.height),_.setWidth&&(typeof _.width===le?h.style.width=(s?_.width+this._borderLeft+this._borderRight:_.width)+"px":h.style.width=_.width),this._hasListeners("layoutStart")&&this._emit("layoutStart",_.items.slice(0)),!d)return f(),this;for(r=0;rl?1:0:ld?1:0)return c;return c||(s||(s=n(i)),c=r(o,h)),c}function h(o,h){var a=t(o,h);return e&&a&&(a=-a),a||(s||(s=n(i)),r(o,h))}return function(n,r){if(this._isDestroyed||this._items.length<2)return this;var a,_=this._items,l=r||0,d=l.layout?l.layout:void 0===l.layout;if(t=n,e=!!l.descending,i=_.slice(0),s=null,c(t))_.sort(h);else if(typeof t===de)t=n.trim().split(" ").map(function(t){return t.split(":")}),_.sort(o);else{if(!Array.isArray(t))return this;if(t.length!==_.length)throw new Error("[Muuri] sort reference items do not match with grid items.");for(a=0;a<_.length;a++){if(t.indexOf(_[a])<0)throw new Error("[Muuri] sort reference items do not match with grid items.");_[a]=t[a]}e&&_.reverse()}return this._hasListeners("sort")&&this._emit("sort",_.slice(0),i),d&&this.layout("instant"===d,c(d)?d:void 0),this}}(),ce.prototype.move=function(t,e,i){if(this._isDestroyed||this._items.length<2)return this;var s,n,r=this._items,o=i||0,h=o.layout?o.layout:void 0===o.layout,a="swap"===o.action,_=a?"swap":"move",l=this._getItem(t),d=this._getItem(e);return l&&d&&l!==d&&(s=r.indexOf(l),n=r.indexOf(d),a?Q(r,s,n):K(r,s,n),this._hasListeners("move")&&this._emit("move",{item:l,fromIndex:s,toIndex:n,action:_}),h&&this.layout("instant"===h,c(h)?h:void 0)),this},ce.prototype.send=function(t,e,i,s){if(this._isDestroyed||e._isDestroyed||this===e)return this;if(!(t=this._getItem(t)))return this;var n=s||0,r=n.appendTo||window.document.body,o=n.layoutSender?n.layoutSender:void 0===n.layoutSender,h=n.layoutReceiver?n.layoutReceiver:void 0===n.layoutReceiver;return t._migrate.start(e,i,r),t._migrate._isActive&&t._isActive&&(o&&this.layout("instant"===o,c(o)?o:void 0),h&&e.layout("instant"===h,c(h)?h:void 0)),this},ce.prototype.destroy=function(e){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-1?t:this._items.length+t]||null;if(t instanceof Kt)return t._gridId===this._id?t:null;for(var e=0;e= sortThreshold) { returnData.grid = grid; returnData.index = matchIndex; - returnData.action = isMigration ? sortMigrateAction : sortAction; + returnData.action = isMigration ? migrateAction : sortAction; return returnData; } From a3bbe80b7de2d8b51df14ff1961474be51215bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20R=C3=A4m=C3=B6?= Date: Tue, 23 Jul 2019 11:04:50 +0300 Subject: [PATCH 008/120] Refactor drag sort predicate. --- dist/muuri.js | 22 ++++++++++++---------- dist/muuri.min.js | 2 +- src/Grid/Grid.js | 2 -- src/Item/ItemDrag.js | 19 ++++++++++++------- src/Item/ItemMigrate.js | 1 - 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/dist/muuri.js b/dist/muuri.js index 7f21734f..5b39730c 100644 --- a/dist/muuri.js +++ b/dist/muuri.js @@ -1881,8 +1881,6 @@ /** * Default drag sort predicate. * - * @todo Check if we layout thrashing is a problem here and if we can alleviate - * it's potential effects. * @public * @memberof ItemDrag * @param {Item} item @@ -1898,6 +1896,8 @@ var targetRect = {}; var returnData = {}; var gridsArray = []; + var minThreshold = 1; + var maxThreshold = 100; function getTargetGrid(item, rootGrid, threshold) { var target = null; @@ -1961,6 +1961,11 @@ var sortAction = options && options.action === actionSwap ? actionSwap : actionMove; var migrateAction = options && options.migrateAction === actionSwap ? actionSwap : actionMove; + // Sort threshold must be a positive number capped to a max value of 100. If + // that's not the case this function will not work correctly. So let's clamp + // the threshold just in case. + sortThreshold = Math.min(Math.max(sortThreshold, minThreshold), maxThreshold); + // Populate item rect data. itemRect.width = item._width; itemRect.height = item._height; @@ -1977,9 +1982,9 @@ var isMigration = item.getGrid() !== grid; var gridOffsetLeft = 0; var gridOffsetTop = 0; - var matchScore = -1; - var matchIndex; - var hasValidTargets; + var matchScore = 0; + var matchIndex = -1; + var hasValidTargets = false; var target; var score; var i; @@ -2033,8 +2038,8 @@ // threshold and just pick the item which the dragged item is overlapping // most. However, if the dragged item is not overlapping any of the valid // items in the new grid let's position it as the last item in the grid. - if (matchScore < sortThreshold && isMigration) { - matchIndex = hasValidTargets ? (matchScore > 0 ? matchIndex : -1) : 0; + if (isMigration && matchScore < sortThreshold) { + matchIndex = hasValidTargets ? matchIndex : 0; matchScore = sortThreshold; } @@ -3861,7 +3866,6 @@ targetIndex = normalizeArrayIndex(targetItems, position, true); } else { targetItem = targetGrid._getItem(position); - /** @todo Consider throwing an error here instead of silently failing. */ if (!targetItem) return this; targetIndex = targetItems.indexOf(targetItem); } @@ -6331,7 +6335,6 @@ } // Otherwise let's just skip it, nothing we can do here. else { - /** @todo Maybe throw an error here? */ return this; } @@ -6541,7 +6544,6 @@ // In other cases let's assume that the target is an element, so let's try // to find an item that matches the element and return it. If item is not // found return null. - /** @todo This could be made a lot faster by using Map/WeakMap of elements. */ for (var i = 0; i < this._items.length; i++) { if (this._items[i]._element === target) { return this._items[i]; diff --git a/dist/muuri.min.js b/dist/muuri.min.js index cc3045c9..c7a0735b 100644 --- a/dist/muuri.min.js +++ b/dist/muuri.min.js @@ -14,4 +14,4 @@ * Copyright (c) 2018-present, Niklas Rämö * @license MIT */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Muuri=e()}(this,function(){"use strict";var t={},e="layoutEnd";function i(){this._events={},this._queue=[],this._counter=0,this._isDestroyed=!1}i.prototype.on=function(t,e){if(this._isDestroyed)return this;var i=this._events[t];return i||(i=this._events[t]=[]),i.push(e),this},i.prototype.off=function(t,e){if(this._isDestroyed)return this;var i=this._events[t];if(!i||!i.length)return this;if(!e)return i.length=0,this;for(var s=i.length;s--;)e===i[s]&&i.splice(s,1);return this},i.prototype.emit=function(t,e,i,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-1||(M._activeInstances.push(t),M._emitter.on(D,t._onMove),M._emitter.on(A,t._onCancel),M._emitter.on(b,t._onEnd),1===M._activeInstances.length&&M._bindListeners())},M._deactivateInstance=function(t){var e=M._activeInstances.indexOf(t);-1!==e&&(M._activeInstances.splice(e,1),M._emitter.off(D,t._onMove),M._emitter.off(A,t._onCancel),M._emitter.off(b,t._onEnd),M._activeInstances.length||M._unbindListeners())},M._bindListeners=function(){var t=M._events;window.addEventListener(t.move,M._onMove,R),window.addEventListener(t.end,M._onEnd,R),t.cancel&&window.addEventListener(t.cancel,M._onCancel,R)},M._unbindListeners=function(){var t=M._events;window.removeEventListener(t.move,M._onMove,R),window.removeEventListener(t.end,M._onEnd,R),t.cancel&&window.removeEventListener(t.cancel,M._onCancel,R)},M._getEventPointerId=function(t){return"number"==typeof t.pointerId?t.pointerId:t.changedTouches?t.changedTouches[0]?t.changedTouches[0].identifier:null:1},M._getTouchById=function(t,e){if("number"==typeof t.pointerId)return t.pointerId===e?t:null;if(t.changedTouches){for(var i=0;i-1&&(this._queue[n]=void 0),s?this._queue.unshift(t):this._queue.push(t),this._reads[t]=e,this._writes[t]=i,this._nextStep||(this._nextStep=y(this._step))},T.prototype.cancel=function(t){var e=this._queue.indexOf(t);e>-1&&(this._queue[e]=void 0,delete this._reads[t],delete this._writes[t])},T.prototype._step=function(){var t,e,i=this._queue,s=this._reads,n=this._writes,r=this._batch,o=this._batchReads,h=this._batchWrites,a=i.length;for(this._nextStep=null,e=0;en?n:e<0?Math.max(n+e+1,0):e}function K(t,e,i){if(!(t.length<2)){var s=J(t,e),n=J(t,i);s!==n&&t.splice(n,0,t.splice(s,1)[0])}}function Q(t,e,i){if(!(t.length<2)){var s,n=J(t,e),r=J(t,i);n!==r&&(s=t[n],t[n]=t[r],t[r]=s)}}var tt="cancel",et="finish",it="debounce",st=0;function nt(t,e){var i,s=++st+it;return e>0?function(n){void 0!==i&&(i=window.clearTimeout(i),k.cancel(s),n===et&&t()),n!==tt&&n!==et&&(i=window.setTimeout(function(){i=void 0,k.add(s,t,null,!0)},e))}:function(e){e!==tt&&t()}}function rt(t){var e=a(t,"transform");if(!e||"none"===e)return!1;var i=a(t,"display");return"inline"!==i&&"none"!==i}function ot(t,e){for(var i=window.document,s=(e?t:t.parentElement)||i;s&&s!==i&&"static"===a(s,"position")&&!rt(s);)s=s.parentElement||i;return s}function ht(t,e){return parseFloat(a(t,e))||0}var at={},_t={},lt={};function dt(t,e){var i,s=e||{};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:(i=t.getBoundingClientRect(),s.left+=i.left,s.top+=i.top,s.left+=ht(t,"border-left-width"),s.top+=ht(t,"border-top-width"),s))}function ct(t,e,i){return lt.left=0,lt.top=0,t===e?lt:i&&(t=ot(t,!0))===(e=ot(e,!0))?lt:(dt(t,at),dt(e,_t),lt.left=_t.left-at.left,lt.top=_t.top-at.top,lt)}var ut="overflow",ft="overflow-x",pt="overflow-y",mt="auto",gt="scroll";function yt(t){var e=a(t,ut);return e===mt||e===gt||((e=a(t,ft))===mt||e===gt||((e=a(t,pt))===mt||e===gt))}function vt(t,e,i){for(var s=i||[],n=e?t:t.parentNode;n&&n!==document;)n.getRootNode&&n instanceof DocumentFragment?n=n.getRootNode().host:(yt(n)&&s.push(n),n=n.parentNode);return s.push(window),s}var wt={},St="transform",Dt="none",bt=/^matrix3d/,At=/([^,]*,){4}/,Et=/([^,]*,){12}/,Ct=/[^,]*,/;function Lt(t){wt.x=0,wt.y=0;var e=a(t,St);if(!e||e===Dt)return wt;var i=bt.test(e),s=e.replace(i?Et:At,""),n=s.replace(Ct,"");return wt.x=parseFloat(s)||0,wt.y=parseFloat(n)||0,wt}function It(t,e){return"translateX("+t+"px) translateY("+e+"px)"}function Rt(t,e){t.classList?t.classList.remove(e):W(t,"."+e)&&(t.className=(" "+t.className+" ").replace(" "+e+" "," ").trim())}var xt,Pt,Mt,Tt,kt=0;function Xt(t){var e=t._element,i=t.getGrid(),s=i._settings;this._item=t,this._gridId=i._id,this._isDestroyed=!1,this._isMigrating=!1,this._startPredicate=c(s.dragStartPredicate)?s.dragStartPredicate:Xt.defaultStartPredicate,this._startPredicateState=kt,this._startPredicateResult=void 0,this._hBlockedIndex=null,this._hX1=0,this._hX2=0,this._hY1=0,this._hY2=0,this._reset(),this._preStartCheck=this._preStartCheck.bind(this),this._preEndCheck=this._preEndCheck.bind(this),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);var n=s.dragSortHeuristics.sortInterval;this._checkOverlapDebounce=nt(this._checkOverlap,n),this._dragger=new M(e,s.dragCssProps),this._dragger.on("start",this._preStartCheck),this._dragger.on("move",this._preStartCheck),this._dragger.on("cancel",this._preEndCheck),this._dragger.on("end",this._preEndCheck)}function Yt(t,e){return t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top?0:(Math.min(t.left+t.width,e.left+e.width)-Math.max(t.left,e.left))*(Math.min(t.top+t.height,e.top+e.height)-Math.max(t.top,e.top))/(Math.min(t.width,e.width)*Math.min(t.height,e.height))*100}function Gt(t){this._item=t,this._animate=new p,this._element=null,this._className="",this._didMigrate=!1,this._resetAfterLayout=!1,this._currentLeft=0,this._currentTop=0,this._nextLeft=0,this._nextTop=0,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this),this._onLayoutStart=this._onLayoutStart.bind(this),this._onLayoutEnd=this._onLayoutEnd.bind(this),this._onReleaseEnd=this._onReleaseEnd.bind(this),this._onMigrate=this._onMigrate.bind(this)}function Ht(){this._queue=[],this._isDestroyed=!1}function Ot(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 Ht,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this)}Xt.defaultStartPredicate=function(t,e,i){var s=t._drag,n=s._startPredicateData||s._setupStartPredicate(i);if(!e.isFinal)return!(!n.handleElement&&(n.handleElement=s._getStartPredicateHandle(e),!n.handleElement))&&(n.delay&&(n.event=e,n.delayTimer||(n.delayTimer=window.setTimeout(function(){n.delay=0,s._resolveStartPredicate(n.event)&&(s._forceResolveStartPredicate(n.event),s._resetStartPredicate())},n.delay))),s._resolveStartPredicate(e));s._finishStartPredicate(e)},Xt.defaultSortPredicate=(xt={},Pt={},Mt={},Tt=[],function(t,e){var i=t._drag,s=i._getGrid(),n=e&&"number"==typeof e.threshold?e.threshold:50,r=e&&"swap"===e.action?"swap":"move",o=e&&"swap"===e.migrateAction?"swap":"move";xt.width=t._width,xt.height=t._height,xt.left=i._elementClientX,xt.top=i._elementClientY;var h=function(t,e,i){var s,n,r,o,h=null,a=e._settings.dragSort,_=-1;if(!0===a?(Tt[0]=e,n=Tt):c(a)&&(n=a.call(e,t)),!n||!Array.isArray(n)||!n.length)return h;for(o=0;oi&&s>_&&(_=s,h=r));return Tt.length=0,h}(t,s,n);if(!h)return!1;var a,_,l,d,u,f=t.getGrid()!==h,p=0,m=0,g=-1;for(h===s?(xt.left=i._gridX+t._marginLeft,xt.top=i._gridY+t._marginTop):(h._updateBorders(1,0,1,0),p=h._left+h._borderLeft,m=h._top+h._borderTop),u=0;ug&&(a=u,g=d));return g0?a:-1:0,g=n),g>=n&&(Mt.grid=h,Mt.index=a,Mt.action=f?o:r,Mt)}),Xt.prototype.stop=function(){var t=this._item,e=t._element,i=this._getGrid();return this._isActive?this._isMigrating?(this._finishMigration(),this):(N(t._id),q(t._id),this._unbindScrollListeners(),this._checkOverlapDebounce("cancel"),e.parentNode!==i._element&&(i._element.appendChild(e),e.style[n]=It(this._gridX,this._gridY)),Rt(e,i._settings.itemDraggingClass),this._reset(),this):this},Xt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(),this._dragger.destroy(),this._isDestroyed=!0,this)},Xt.prototype._getGrid=function(){return t[this._gridId]||null},Xt.prototype._reset=function(){this._isActive=!1,this._container=null,this._containingBlock=null,this._dragEvent=null,this._scrollEvent=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},Xt.prototype._bindScrollListeners=function(){var t,e,i=this._getGrid()._element,s=this._container,n=this._scrollers;if(n.length=0,vt(this._item._element,!1,n),s!==i)for(vt(i,!0,t=[]),e=0;e=s&&t.pageX=n&&t.pageY3&&e.minBounceBackAngle>0;if(h||(this._hBlockedIndex=null),Math.abs(r)>i||Math.abs(o)>i){if(h){var a=Math.atan2(r,o),_=Math.atan2(this._hX2-this._hX1,this._hY2-this._hY1),l=Math.atan2(Math.sin(a-_),Math.cos(a-_));Math.abs(l)>e.minBounceBackAngle&&(this._hBlockedIndex=null)}return this._hX1=this._hX2,this._hY1=this._hY2,this._hX2=s,this._hY2=n,!0}return!1},Xt.prototype._resetStartPredicate=function(){var t=this._startPredicateData;t&&(t.delayTimer&&(t.delayTimer=window.clearTimeout(t.delayTimer)),this._startPredicateData=null)},Xt.prototype._checkOverlap=function(){if(this._isActive){var t,e,i,s,n,r,o,h,a=this._item,_=this._getGrid()._settings;(t=c(_.dragSortPredicate)?_.dragSortPredicate(a,this._dragEvent):Xt.defaultSortPredicate(a,_.dragSortPredicate))&&"number"==typeof t.index&&(h=(e=a.getGrid())!==(s=t.grid||e),i=e._items.indexOf(a),n=J(s._items,t.index,h),o="swap"===t.action?"swap":"move",(h||n!==this._hBlockedIndex)&&(h?(this._hBlockedIndex=null,r=s._items[n],e._hasListeners("beforeSend")&&e._emit("beforeSend",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("beforeReceive")&&s._emit("beforeReceive",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),a._gridId=s._id,this._isMigrating=a._gridId!==this._gridId,e._items.splice(i,1),$(s._items,a,n),a._sortData=null,e._hasListeners("send")&&e._emit("send",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("receive")&&s._emit("receive",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),"swap"===o&&r&&r.isActive()&&s._items.indexOf(r)>-1&&s.send(r,e,i,{appendTo:this._container||window.document.body,layoutSender:!1,layoutReceiver:!1}),e.layout(),s.layout()):i!==n&&(this._hBlockedIndex=i,("swap"===o?Q:K)(e._items,i,n),e._hasListeners("move")&&e._emit("move",{item:a,fromIndex:i,toIndex:n,action:o}),e.layout())))}},Xt.prototype._finishMigration=function(){var t,e,i=this._item,s=i._release,r=i._element,o=i._isActive,h=i.getGrid(),a=h._element,_=h._settings,l=_.dragContainer||a,d=this._getGrid()._settings,c=r.parentNode;this._isMigrating=!1,this.destroy(),Rt(r,d.itemClass),Rt(r,d.itemVisibleClass),Rt(r,d.itemHiddenClass),j(r,_.itemClass),j(r,o?_.itemVisibleClass:_.itemHiddenClass),l!==c&&(l.appendChild(r),e=ct(c,l,!0),(t=Lt(r)).x-=e.left,t.y-=e.top),i._refreshDimensions(),i._refreshSortData(),e=ct(l,a,!0),s._containerDiffX=e.left,s._containerDiffY=e.top,i._drag=_.dragEnabled?new Xt(i):null,l!==c&&(r.style[n]=It(t.x,t.y)),i._child.removeAttribute("style"),f(i._child,o?_.visibleStyles:_.hiddenStyles),s.start()},Xt.prototype._preStartCheck=function(t){this._startPredicateState===kt&&(this._startPredicateState=1),1===this._startPredicateState?(this._startPredicateResult=this._startPredicate(this._item,t),!0===this._startPredicateResult?(this._startPredicateState=2,this._onStart(t)):!1===this._startPredicateResult&&(this._startPredicateState=3)):2===this._startPredicateState&&this._isActive&&this._onMove(t)},Xt.prototype._preEndCheck=function(t){var e=2===this._startPredicateState;this._startPredicate(this._item,t),this._startPredicateState=kt,e&&this._isActive&&this._onEnd(t)},Xt.prototype._onStart=function(t){var e=this._item;if(e._isActive){var i,s=e._element,r=this._getGrid(),o=r._settings,h=e._release,a=e._migrate,_=r._element,l=o.dragContainer||_,d=ot(l,!0),c=Lt(s),u=c.x,f=c.y,p=s.getBoundingClientRect(),m=l!==_;this._resetHeuristics(t),m&&(i=ct(d,_)),e.isPositioning()&&e._layout.stop(!0,{transform:It(u,f)}),a._isActive&&(u-=a._containerDiffX,f-=a._containerDiffY,a.stop(!0,{transform:It(u,f)})),e.isReleasing()&&h._reset(),this._isActive=!0,this._dragEvent=t,this._container=l,this._containingBlock=d,this._elementClientX=p.left,this._elementClientY=p.top,this._left=this._gridX=u,this._top=this._gridY=f,o.dragPlaceholder.enabled&&e._dragPlaceholder.create(),r._emit("dragInit",e,t),m&&(this._containerDiffX=i.left,this._containerDiffY=i.top,s.parentNode===l?(this._gridX=u-this._containerDiffX,this._gridY=f-this._containerDiffY):(this._left=u+this._containerDiffX,this._top=f+this._containerDiffY,l.appendChild(s),s.style[n]=It(this._left,this._top))),j(s,o.itemDraggingClass),this._bindScrollListeners(),r._emit("dragStart",e,t)}},Xt.prototype._onMove=function(t){var e=this._item;if(e._isActive){var i,s,n,r=this._getGrid()._settings.dragAxis;if("y"!==r){var o=t.clientX-this._dragEvent.clientX;this._left+=o,this._gridX+=o,this._elementClientX+=o}if("x"!==r){var h=t.clientY-this._dragEvent.clientY;this._top+=h,this._gridY+=h,this._elementClientY+=h}this._dragEvent=t,i=e._id,s=this._prepareMove,n=this._applyMove,k.add(i+G,s,n,!0)}else this.stop()},Xt.prototype._prepareMove=function(){this._item._isActive&&this._getGrid()._settings.dragSort&&this._checkHeuristics(this._dragEvent)&&this._checkOverlapDebounce()},Xt.prototype._applyMove=function(){var t=this._item;t._isActive&&(t._element.style[n]=It(this._left,this._top),this._getGrid()._emit("dragMove",t,this._dragEvent))},Xt.prototype._onScroll=function(t){var e,i,s,n=this._item;n._isActive?(this._scrollEvent=t,e=n._id,i=this._prepareScroll,s=this._applyScroll,k.add(e+H,i,s,!0)):this.stop()},Xt.prototype._prepareScroll=function(){var t=this._item;if(t._isActive){var e,i=t._element,s=this._getGrid(),n=s._settings,r=n.dragAxis,o=s._element,h=i.getBoundingClientRect(),a=this._elementClientX-h.left,_=this._elementClientY-h.top;this._container!==o&&(e=ct(this._containingBlock,o),this._containerDiffX=e.left,this._containerDiffY=e.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()}},Xt.prototype._applyScroll=function(){var t=this._item;t._isActive&&(t._element.style[n]=It(this._left,this._top),this._getGrid()._emit("dragScroll",t,this._scrollEvent))},Xt.prototype._onEnd=function(t){var e=this._item,i=e._element,s=this._getGrid(),n=s._settings,r=e._release;e._isActive?(N(e._id),q(e._id),n.dragSort&&this._checkOverlapDebounce("finish"),this._unbindScrollListeners(),r._containerDiffX=this._containerDiffX,r._containerDiffY=this._containerDiffY,this._reset(),Rt(i,n.itemDraggingClass),s._emit("dragEnd",e,t),this._isMigrating?this._finishMigration():r.start()):this.stop()},Gt.prototype._onLayoutStart=function(){var t=this._item,e=t.getGrid(),i=e._items.indexOf(t),s=e._layout.slots[2*i],n=e._layout.slots[2*i+1];if(this._didMigrate||t._left!==s||t._top!==n){var r,o,h;if(s+=t._marginLeft,n+=t._marginTop,!(e._settings.dragPlaceholder.duration>0)||this._didMigrate){F(t._id);var a={transform:It(s,n)};return this._animate.isAnimating()?this._animate.stop(a):f(this._element,a),void(this._didMigrate&&(e.getElement().appendChild(this._element),this._didMigrate=!1))}this._nextLeft=s,this._nextTop=n,r=t._id,o=this._setupAnimation,h=this._startAnimation,k.add(r+O,o,h)}},Gt.prototype._setupAnimation=function(){if(this.isActive()){var t=Lt(this._element);this._currentLeft=t.x,this._currentTop=t.y}},Gt.prototype._startAnimation=function(){if(this.isActive()){var t=this._animate,e=this._currentLeft,i=this._currentTop,s=this._nextLeft,n=this._nextTop,r={transform:It(s,n)};if(e!==s||i!==n){var o=this._item.getGrid()._settings.dragPlaceholder,h={transform:It(e,i)};t.start(h,r,{duration:o.duration,easing:o.easing,onFinish:this._onLayoutEnd})}else t.isAnimating()&&t.stop(r)}},Gt.prototype._onLayoutEnd=function(){this._resetAfterLayout&&this.reset()},Gt.prototype._onReleaseEnd=function(t){if(t._id===this._item._id){if(!this._animate.isAnimating())return void this.reset();this._resetAfterLayout=!0}},Gt.prototype._onMigrate=function(t){if(t.item===this._item){var e=this._item.getGrid(),i=t.toGrid;e.off("dragReleaseEnd",this._onReleaseEnd),e.off("layoutStart",this._onLayoutStart),e.off("beforeSend",this._onMigrate),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("layoutStart",this._onLayoutStart),i.on("beforeSend",this._onMigrate),this._didMigrate=!0}},Gt.prototype.create=function(){if(this.isActive())this._resetAfterLayout=!1;else{var t,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;t=c(s.dragPlaceholder.createElement)?s.dragPlaceholder.createElement(e):window.document.createElement("div"),this._element=t,n._element=t,this._className=s.itemPlaceholderClass||"",this._className&&j(t,this._className);var r=e._left+e._marginLeft,o=e._top+e._marginTop;f(t,{display:"block",position:"absolute",left:"0",top:"0",width:e._width+"px",height:e._height+"px",transform:It(r,o)}),i.on("layoutStart",this._onLayoutStart),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("beforeSend",this._onMigrate),c(s.dragPlaceholder.onCreate)&&s.dragPlaceholder.onCreate(e,t),i.getElement().appendChild(t)}},Gt.prototype.reset=function(){if(this.isActive()){var t=this._element,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;this._resetAfterLayout=!1,F(e._id),n.stop(),n._element=null,i.off("dragReleaseEnd",this._onReleaseEnd),i.off("layoutStart",this._onLayoutStart),i.off("beforeSend",this._onMigrate),this._className&&(Rt(t,this._className),this._className=""),t.parentNode.removeChild(t),this._element=null,c(s.dragPlaceholder.onRemove)&&s.dragPlaceholder.onRemove(e,t)}},Gt.prototype.updateDimensions=function(t,e){this.isActive()&&f(this._element,{width:t+"px",height:e+"px"})},Gt.prototype.isActive=function(){return!!this._element},Gt.prototype.destroy=function(){this.reset(),this._animate.destroy(),this._item=this._animate=null},Ht.prototype.add=function(t){return this._isDestroyed?this:(this._queue.push(t),this)},Ht.prototype.flush=function(t,e){if(this._isDestroyed)return this;var i,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,e),this;for(i=0;i0;return l&&this._queue.flush(!0,o),d&&(a._isPositioningStarted=!0),c(e)&&this._queue.add(e),m?(this._isActive=!0,this._animateOptions.easing=p,this._animateOptions.duration=u,this._isInterrupted=l,s=o._id,n=this._setupAnimation,r=this._startAnimation,k.add(s+X,n,r),this):(this._updateOffsets(),this._updateTargetStyles(),i=o._animate.isAnimating(),this.stop(!1,this._targetStyles),!i&&f(h,this._targetStyles),this._skipNextAnimation=!1,this._finish())}},Ot.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item;return i=s._id,k.cancel(i+X),s._animate.stop(e),Rt(s._element,s.getGrid()._settings.itemPositioningClass),this._isActive=!1,t&&this._queue.flush(!0,s),this},Ot.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)},Ot.prototype._updateOffsets=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._offsetLeft=i._isActive?i._containerDiffX:e._isActive?e._containerDiffX:0,this._offsetTop=i._isActive?i._containerDiffY:e._isActive?e._containerDiffY:0}},Ot.prototype._updateTargetStyles=function(){this._isDestroyed||(this._targetStyles.transform=It(this._item._left+this._offsetLeft,this._item._top+this._offsetTop))},Ot.prototype._finish=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._isActive&&(this._isActive=!1,Rt(t._element,t.getGrid()._settings.itemPositioningClass)),i._isActive&&i.stop(),e._isActive&&e.stop(),this._queue.flush(!1,t)}},Ot.prototype._setupAnimation=function(){var t=Lt(this._item._element);this._currentLeft=t.x,this._currentTop=t.y},Ot.prototype._startAnimation=function(){var t=this._item,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||j(t._element,e.itemPositioningClass),this._currentStyles.transform=It(this._currentLeft,this._currentTop),t._animate.start(this._currentStyles,this._targetStyles,this._animateOptions)};var Bt={};function Nt(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._container=!1,this._containerDiffX=0,this._containerDiffY=0}Nt.prototype.start=function(t,e,i){if(this._isDestroyed)return this;var s,r,o,h,a,_,l,d,c=this._item,u=c._element,p=c.isVisible(),m=c.getGrid(),g=m._settings,y=t._settings,v=t._element,w=t._items,S=m._items.indexOf(c),D=i||window.document.body;if("number"==typeof e)s=J(w,e,!0);else{if(!(r=t._getItem(e)))return this;s=w.indexOf(r)}return(c.isPositioning()||this._isActive||c.isReleasing())&&(l=(_=Lt(u)).x,d=_.y),c.isPositioning()&&c._layout.stop(!0,{transform:It(l,d)}),this._isActive&&(l-=this._containerDiffX,d-=this._containerDiffY,this.stop(!0,{transform:It(l,d)})),c.isReleasing()&&(l-=c._release._containerDiffX,d-=c._release._containerDiffY,c._release.stop(!0,{transform:It(l,d)})),c._visibility._stopAnimation(),c._drag&&c._drag.destroy(),c._visibility._queue.flush(!0,c),m._hasListeners("beforeSend")&&m._emit("beforeSend",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("beforeReceive")&&t._emit("beforeReceive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),Rt(u,g.itemClass),Rt(u,g.itemVisibleClass),Rt(u,g.itemHiddenClass),j(u,y.itemClass),j(u,p?y.itemVisibleClass:y.itemHiddenClass),m._items.splice(S,1),$(w,c,s),c._gridId=t._id,D!==(o=u.parentNode)&&(D.appendChild(u),h=ct(D,o,!0),_||(l=(_=Lt(u)).x,d=_.y),u.style[n]=It(l+h.left,d+h.top)),c._child.removeAttribute("style"),f(c._child,p?y.visibleStyles:y.hiddenStyles),u.style.display=p?"block":"hidden",a=ct(D,v,!0),c._refreshDimensions(),c._refreshSortData(),c._drag=y.dragEnabled?new Xt(c):null,this._isActive=!0,this._container=D,this._containerDiffX=a.left,this._containerDiffY=a.top,m._hasListeners("send")&&m._emit("send",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("receive")&&t._emit("receive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),this},Nt.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid()._element;return this._container!==r&&(e||(t?(i=Lt(n),Bt.transform=It(i.x-this._containerDiffX,i.y-this._containerDiffY)):Bt.transform=It(s._left,s._top),e=Bt),r.appendChild(n),f(n,e)),this._isActive=!1,this._container=null,this._containerDiffX=0,this._containerDiffY=0,this},Nt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)};var qt={};function Ft(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0}function zt(t){var e=t._isActive,i=t._element,s=t.getGrid()._settings;this._item=t,this._isDestroyed=!1,this._isHidden=!e,this._isHiding=!1,this._isShowing=!1,this._queue=new Ht,this._finishShow=this._finishShow.bind(this),this._finishHide=this._finishHide.bind(this),i.style.display=e?"block":"none",j(i,e?s.itemVisibleClass:s.itemHiddenClass),f(t._child,e?s.visibleStyles:s.hiddenStyles)}Ft.prototype.start=function(){if(this._isDestroyed||this._isActive)return this;var t=this._item,e=t.getGrid();return this._isActive=!0,j(t._element,e._settings.itemReleasingClass),e._emit("dragReleaseStart",t),t._layout.start(!1),this},Ft.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid(),o=r._element;return this._reset(),n.parentNode!==o&&(e||(t?(i=Lt(n),qt.transform=It(i.x-this._containerDiffX,i.y-this._containerDiffY)):qt.transform=It(s._left,s._top),e=qt),o.appendChild(n),f(n,e)),t||r._emit("dragReleaseEnd",s),this},Ft.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)},Ft.prototype._reset=function(){if(!this._isDestroyed){var t=this._item;this._isActive=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0,Rt(t._element,t.getGrid()._settings.itemReleasingClass)}},zt.prototype.show=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return this._isShowing||this._isHidden?this._isShowing&&!t?(r&&n.add(r),this):(this._isShowing||(n.flush(!0,i),Rt(s,o.itemHiddenClass),j(s,o.itemVisibleClass),this._isHiding||(s.style.display="block")),r&&n.add(r),i._isActive=this._isShowing=!0,this._isHiding=this._isHidden=!1,this._startAnimation(!0,t,this._finishShow),this):(r&&r(!1,i),this)},zt.prototype.hide=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return!this._isHiding&&this._isHidden?(r&&r(!1,i),this):this._isHiding&&!t?(r&&n.add(r),this):(this._isHiding||(n.flush(!0,i),j(s,o.itemHiddenClass),Rt(s,o.itemVisibleClass)),r&&n.add(r),this._isHidden=this._isHiding=!0,i._isActive=this._isShowing=!1,this._startAnimation(!1,t,this._finishHide),this)},zt.prototype.destroy=function(){if(this._isDestroyed)return this;var t=this._item,e=t._element,i=t.getGrid(),s=this._queue,n=i._settings;return this._stopAnimation({}),s.flush(!0,t).destroy(),Rt(e,n.itemVisibleClass),Rt(e,n.itemHiddenClass),this._item=null,this._isHiding=this._isShowing=!1,this._isDestroyed=this._isHidden=!0,this},zt.prototype._startAnimation=function(t,e,i){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,_=(t?r.showEasing:r.hideEasing)||"ease",d=e||h<=0;if(o){if(B(n._id),d)return n._animateChild.isAnimating()?n._animateChild.stop(o):f(n._child,o),void(i&&i());var c,u,p;c=n._id,u=function(){s=function(t,e){var i={};for(var s in e)i[s]=a(t,l(s));return i}(n._child,o)},p=function(){n._animateChild.start(s,o,{duration:h,easing:_,onFinish:i})},k.add(c+Y,u,p)}else i&&i()}},zt.prototype._stopAnimation=function(t){if(!this._isDestroyed){var e=this._item;B(e._id),e._animateChild.stop(t)}},zt.prototype._finishShow=function(){this._isHidden||(this._isShowing=!1,this._queue.flush(!1,this._item))};var Vt={};zt.prototype._finishHide=function(){if(this._isHidden){var t=this._item;this._isHiding=!1,Vt.transform=It(0,0),t._layout.stop(!0,Vt),t._element.style.display="none",this._queue.flush(!1,t)}};var Wt,jt,Ut,Zt,$t=0;function Jt(){return++$t}function Kt(t,e,i){var s=t._settings;this._id=Jt(),this._gridId=t._id,this._isDestroyed=!1,this._left=0,this._top=0,this._element=e,this._child=e.children[0],e.parentNode!==t._element&&t._element.appendChild(e),j(e,s.itemClass),"boolean"!=typeof i&&(i="none"!==a(e,"display")),this._isActive=i,e.style.left="0",e.style.top="0",e.style[n]=It(0,0),this._animate=new p(e),this._animateChild=new p(this._child),this._visibility=new zt(this),this._layout=new Ot(this),this._migrate=new Nt(this),this._release=new Ft(this),this._dragPlaceholder=new Gt(this),this._drag=s.dragEnabled?new Xt(this):null,this._refreshDimensions(),this._refreshSortData()}function Qt(){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)}Kt.prototype.getGrid=function(){return t[this._gridId]},Kt.prototype.getElement=function(){return this._element},Kt.prototype.getWidth=function(){return this._width},Kt.prototype.getHeight=function(){return this._height},Kt.prototype.getMargin=function(){return{left:this._marginLeft,right:this._marginRight,top:this._marginTop,bottom:this._marginBottom}},Kt.prototype.getPosition=function(){return{left:this._left,top:this._top}},Kt.prototype.isActive=function(){return this._isActive},Kt.prototype.isVisible=function(){return!!this._visibility&&!this._visibility._isHidden},Kt.prototype.isShowing=function(){return!(!this._visibility||!this._visibility._isShowing)},Kt.prototype.isHiding=function(){return!(!this._visibility||!this._visibility._isHiding)},Kt.prototype.isPositioning=function(){return!(!this._layout||!this._layout._isActive)},Kt.prototype.isDragging=function(){return!(!this._drag||!this._drag._isActive)},Kt.prototype.isReleasing=function(){return!(!this._release||!this._release._isActive)},Kt.prototype.isDestroyed=function(){return this._isDestroyed},Kt.prototype._refreshDimensions=function(){if(!this._isDestroyed&&!this._visibility._isHidden){var t=this._element,e=this._dragPlaceholder,i=t.getBoundingClientRect();this._width=i.width,this._height=i.height,this._marginLeft=Math.max(0,ht(t,"margin-left")),this._marginRight=Math.max(0,ht(t,"margin-right")),this._marginTop=Math.max(0,ht(t,"margin-top")),this._marginBottom=Math.max(0,ht(t,"margin-bottom")),e&&e.updateDimensions(this._width,this._height)}},Kt.prototype._refreshSortData=function(){if(!this._isDestroyed){var t,e=this._sortData={},i=this.getGrid()._settings.sortData;for(t in i)e[t]=i[t](this,this._element)}},Kt.prototype._destroy=function(t){if(!this._isDestroyed){var e=this._element,i=this.getGrid(),s=i._settings,n=i._items.indexOf(this);this._release.destroy(),this._migrate.destroy(),this._layout.destroy(),this._visibility.destroy(),this._animate.destroy(),this._animateChild.destroy(),this._dragPlaceholder.destroy(),this._drag&&this._drag.destroy(),e.removeAttribute("style"),this._child.removeAttribute("style"),Rt(e,s.itemClass),n>-1&&i._items.splice(n,1),t&&e.parentNode.removeChild(e),this._isActive=!1,this._isDestroyed=!0}},Qt.prototype.getLayout=function(t,e,i,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),c=this._slotSizes;if(o.slots=s||this._slots,o.width=a?0:d?Math.round(e):e,o.height=a?d?Math.round(i):i:0,o.setWidth=a,o.setHeight=!a,o.slots.length=0,c.length=0,!t.length)return o;for(r=0;rd.height&&(Wt.left>0&&u.push(this._addRect(0,d.height,Wt.left,1/0)),Wt.left+Wt.widthd.width&&(Wt.top>0&&u.push(this._addRect(d.width,0,1/0,Wt.top)),Wt.top+Wt.height.49&&r.height>.49&&(!e&&r.tope.left+e.width&&jt.push(this._addRect(e.left+e.width,t.top,t.left+t.width-(e.left+e.width),t.height)),t.tope.top+e.height&&jt.push(this._addRect(t.left,e.top+e.height,t.width,t.top+t.height-(e.top+e.height))),jt):(jt.push(this._addRect(t.left,t.top,t.width,t.height)),jt)}),Qt.prototype._doRectsOverlap=function(t,e){return!(t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top)},Qt.prototype._isRectWithinRect=function(t,e){return t.left>=e.left&&t.top>=e.top&&t.left+t.width<=e.left+e.width&&t.top+t.height<=e.top+e.height},Qt.prototype._purgeRects=(Ut={},Zt={},function(t){for(var e,i=t.length;i--;)if(e=t.length,t[i])for(this._getRect(t[i],Ut);e--;)if(t[e]&&i!==e&&this._isRectWithinRect(Ut,this._getRect(t[e],Zt))){t[i]=0;break}return t}),Qt.prototype._sortRectsTopLeft=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.tope.top?1:t.lefte.left?1:0}}(),Qt.prototype._sortRectsLeftTop=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.lefte.left?1:t.tope.top?1:0}}();var te="[object HTMLCollection]",ee="[object NodeList]";function ie(t){var e=Object.prototype.toString.call(t);return e===te||e===ee}var se="object",ne="[object Object]",re=Object.prototype.toString;function oe(t){return typeof t===se&&re.call(t)===ne}function he(t){return ie(t)?Array.prototype.slice.call(t):Array.prototype.concat(t)}var ae=new Qt,_e=function(){},le="number",de="string";function ce(e,s){var n,r,o,h=this;if(!((e=this._element=typeof e===de?window.document.querySelector(e):e).getRootNode?e.getRootNode({composed:!0})===document:window.document.body.contains(e))||e===window.document.documentElement)throw new Error("Container element must be an existing DOM element");c((n=this._settings=function(t,e){var i=ue({},t);e&&(i=ue(i,e));return i.visibleStyles=(e||0).visibleStyles||(t||0).visibleStyles,i.hiddenStyles=(e||0).hiddenStyles||(t||0).hiddenStyles,i}(ce.defaultOptions,s)).dragSort)||(n.dragSort=!!n.dragSort),this._id=Jt(),t[this._id]=h,this._isDestroyed=!1,this._layout={id:0,items:[],slots:[],setWidth:!1,setHeight:!1,width:0,height:0},this._emitter=new i,j(e,n.containerClass),this._items=[],typeof(r=n.items)===de?he(e.children).forEach(function(t){("*"===r||W(t,r))&&h._items.push(new Kt(h,t))}):(Array.isArray(r)||ie(r))&&(this._items=he(r).map(function(t){return new Kt(h,t)})),typeof(o=n.layoutOnResize)!==le&&(o=!0===o?0:-1),o>=0&&window.addEventListener("resize",h._resizeHandler=nt(function(){h.refreshItems().layout()},o)),n.layoutOnInit&&this.layout(!0)}function ue(t,e){var i,s,n,r=Object.keys(e),o=r.length;for(n=0;n0)){var s=o._layout.id!==l,n=c(t)?t:i;c(n)&&n(s,_.items.slice(0)),!s&&o._hasListeners(e)&&o._emit(e,_.items.slice(0))}}if((_.setHeight&&typeof _.height===le||_.setWidth&&typeof _.width===le)&&(s="border-box"===a(h,"box-sizing")),_.setHeight&&(typeof _.height===le?h.style.height=(s?_.height+this._borderTop+this._borderBottom:_.height)+"px":h.style.height=_.height),_.setWidth&&(typeof _.width===le?h.style.width=(s?_.width+this._borderLeft+this._borderRight:_.width)+"px":h.style.width=_.width),this._hasListeners("layoutStart")&&this._emit("layoutStart",_.items.slice(0)),!d)return f(),this;for(r=0;rl?1:0:ld?1:0)return c;return c||(s||(s=n(i)),c=r(o,h)),c}function h(o,h){var a=t(o,h);return e&&a&&(a=-a),a||(s||(s=n(i)),r(o,h))}return function(n,r){if(this._isDestroyed||this._items.length<2)return this;var a,_=this._items,l=r||0,d=l.layout?l.layout:void 0===l.layout;if(t=n,e=!!l.descending,i=_.slice(0),s=null,c(t))_.sort(h);else if(typeof t===de)t=n.trim().split(" ").map(function(t){return t.split(":")}),_.sort(o);else{if(!Array.isArray(t))return this;if(t.length!==_.length)throw new Error("[Muuri] sort reference items do not match with grid items.");for(a=0;a<_.length;a++){if(t.indexOf(_[a])<0)throw new Error("[Muuri] sort reference items do not match with grid items.");_[a]=t[a]}e&&_.reverse()}return this._hasListeners("sort")&&this._emit("sort",_.slice(0),i),d&&this.layout("instant"===d,c(d)?d:void 0),this}}(),ce.prototype.move=function(t,e,i){if(this._isDestroyed||this._items.length<2)return this;var s,n,r=this._items,o=i||0,h=o.layout?o.layout:void 0===o.layout,a="swap"===o.action,_=a?"swap":"move",l=this._getItem(t),d=this._getItem(e);return l&&d&&l!==d&&(s=r.indexOf(l),n=r.indexOf(d),a?Q(r,s,n):K(r,s,n),this._hasListeners("move")&&this._emit("move",{item:l,fromIndex:s,toIndex:n,action:_}),h&&this.layout("instant"===h,c(h)?h:void 0)),this},ce.prototype.send=function(t,e,i,s){if(this._isDestroyed||e._isDestroyed||this===e)return this;if(!(t=this._getItem(t)))return this;var n=s||0,r=n.appendTo||window.document.body,o=n.layoutSender?n.layoutSender:void 0===n.layoutSender,h=n.layoutReceiver?n.layoutReceiver:void 0===n.layoutReceiver;return t._migrate.start(e,i,r),t._migrate._isActive&&t._isActive&&(o&&this.layout("instant"===o,c(o)?o:void 0),h&&e.layout("instant"===h,c(h)?h:void 0)),this},ce.prototype.destroy=function(e){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-1?t:this._items.length+t]||null;if(t instanceof Kt)return t._gridId===this._id?t:null;for(var e=0;e-1||(M._activeInstances.push(t),M._emitter.on(D,t._onMove),M._emitter.on(A,t._onCancel),M._emitter.on(b,t._onEnd),1===M._activeInstances.length&&M._bindListeners())},M._deactivateInstance=function(t){var e=M._activeInstances.indexOf(t);-1!==e&&(M._activeInstances.splice(e,1),M._emitter.off(D,t._onMove),M._emitter.off(A,t._onCancel),M._emitter.off(b,t._onEnd),M._activeInstances.length||M._unbindListeners())},M._bindListeners=function(){var t=M._events;window.addEventListener(t.move,M._onMove,x),window.addEventListener(t.end,M._onEnd,x),t.cancel&&window.addEventListener(t.cancel,M._onCancel,x)},M._unbindListeners=function(){var t=M._events;window.removeEventListener(t.move,M._onMove,x),window.removeEventListener(t.end,M._onEnd,x),t.cancel&&window.removeEventListener(t.cancel,M._onCancel,x)},M._getEventPointerId=function(t){return"number"==typeof t.pointerId?t.pointerId:t.changedTouches?t.changedTouches[0]?t.changedTouches[0].identifier:null:1},M._getTouchById=function(t,e){if("number"==typeof t.pointerId)return t.pointerId===e?t:null;if(t.changedTouches){for(var i=0;i-1&&(this._queue[n]=void 0),s?this._queue.unshift(t):this._queue.push(t),this._reads[t]=e,this._writes[t]=i,this._nextStep||(this._nextStep=y(this._step))},T.prototype.cancel=function(t){var e=this._queue.indexOf(t);e>-1&&(this._queue[e]=void 0,delete this._reads[t],delete this._writes[t])},T.prototype._step=function(){var t,e,i=this._queue,s=this._reads,n=this._writes,r=this._batch,o=this._batchReads,h=this._batchWrites,a=i.length;for(this._nextStep=null,e=0;en?n:e<0?Math.max(n+e+1,0):e}function K(t,e,i){if(!(t.length<2)){var s=J(t,e),n=J(t,i);s!==n&&t.splice(n,0,t.splice(s,1)[0])}}function Q(t,e,i){if(!(t.length<2)){var s,n=J(t,e),r=J(t,i);n!==r&&(s=t[n],t[n]=t[r],t[r]=s)}}var tt="cancel",et="finish",it="debounce",st=0;function nt(t,e){var i,s=++st+it;return e>0?function(n){void 0!==i&&(i=window.clearTimeout(i),k.cancel(s),n===et&&t()),n!==tt&&n!==et&&(i=window.setTimeout(function(){i=void 0,k.add(s,t,null,!0)},e))}:function(e){e!==tt&&t()}}function rt(t){var e=a(t,"transform");if(!e||"none"===e)return!1;var i=a(t,"display");return"inline"!==i&&"none"!==i}function ot(t,e){for(var i=window.document,s=(e?t:t.parentElement)||i;s&&s!==i&&"static"===a(s,"position")&&!rt(s);)s=s.parentElement||i;return s}function ht(t,e){return parseFloat(a(t,e))||0}var at={},_t={},lt={};function dt(t,e){var i,s=e||{};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:(i=t.getBoundingClientRect(),s.left+=i.left,s.top+=i.top,s.left+=ht(t,"border-left-width"),s.top+=ht(t,"border-top-width"),s))}function ct(t,e,i){return lt.left=0,lt.top=0,t===e?lt:i&&(t=ot(t,!0))===(e=ot(e,!0))?lt:(dt(t,at),dt(e,_t),lt.left=_t.left-at.left,lt.top=_t.top-at.top,lt)}var ut="overflow",ft="overflow-x",pt="overflow-y",mt="auto",gt="scroll";function yt(t){var e=a(t,ut);return e===mt||e===gt||((e=a(t,ft))===mt||e===gt||((e=a(t,pt))===mt||e===gt))}function vt(t,e,i){for(var s=i||[],n=e?t:t.parentNode;n&&n!==document;)n.getRootNode&&n instanceof DocumentFragment?n=n.getRootNode().host:(yt(n)&&s.push(n),n=n.parentNode);return s.push(window),s}var wt={},St="transform",Dt="none",bt=/^matrix3d/,At=/([^,]*,){4}/,Et=/([^,]*,){12}/,Ct=/[^,]*,/;function Lt(t){wt.x=0,wt.y=0;var e=a(t,St);if(!e||e===Dt)return wt;var i=bt.test(e),s=e.replace(i?Et:At,""),n=s.replace(Ct,"");return wt.x=parseFloat(s)||0,wt.y=parseFloat(n)||0,wt}function It(t,e){return"translateX("+t+"px) translateY("+e+"px)"}function xt(t,e){t.classList?t.classList.remove(e):W(t,"."+e)&&(t.className=(" "+t.className+" ").replace(" "+e+" "," ").trim())}var Rt,Pt,Mt,Tt,kt=0;function Xt(t){var e=t._element,i=t.getGrid(),s=i._settings;this._item=t,this._gridId=i._id,this._isDestroyed=!1,this._isMigrating=!1,this._startPredicate=c(s.dragStartPredicate)?s.dragStartPredicate:Xt.defaultStartPredicate,this._startPredicateState=kt,this._startPredicateResult=void 0,this._hBlockedIndex=null,this._hX1=0,this._hX2=0,this._hY1=0,this._hY2=0,this._reset(),this._preStartCheck=this._preStartCheck.bind(this),this._preEndCheck=this._preEndCheck.bind(this),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);var n=s.dragSortHeuristics.sortInterval;this._checkOverlapDebounce=nt(this._checkOverlap,n),this._dragger=new M(e,s.dragCssProps),this._dragger.on("start",this._preStartCheck),this._dragger.on("move",this._preStartCheck),this._dragger.on("cancel",this._preEndCheck),this._dragger.on("end",this._preEndCheck)}function Yt(t,e){return t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top?0:(Math.min(t.left+t.width,e.left+e.width)-Math.max(t.left,e.left))*(Math.min(t.top+t.height,e.top+e.height)-Math.max(t.top,e.top))/(Math.min(t.width,e.width)*Math.min(t.height,e.height))*100}function Gt(t){this._item=t,this._animate=new p,this._element=null,this._className="",this._didMigrate=!1,this._resetAfterLayout=!1,this._currentLeft=0,this._currentTop=0,this._nextLeft=0,this._nextTop=0,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this),this._onLayoutStart=this._onLayoutStart.bind(this),this._onLayoutEnd=this._onLayoutEnd.bind(this),this._onReleaseEnd=this._onReleaseEnd.bind(this),this._onMigrate=this._onMigrate.bind(this)}function Ht(){this._queue=[],this._isDestroyed=!1}function Ot(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 Ht,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this)}Xt.defaultStartPredicate=function(t,e,i){var s=t._drag,n=s._startPredicateData||s._setupStartPredicate(i);if(!e.isFinal)return!(!n.handleElement&&(n.handleElement=s._getStartPredicateHandle(e),!n.handleElement))&&(n.delay&&(n.event=e,n.delayTimer||(n.delayTimer=window.setTimeout(function(){n.delay=0,s._resolveStartPredicate(n.event)&&(s._forceResolveStartPredicate(n.event),s._resetStartPredicate())},n.delay))),s._resolveStartPredicate(e));s._finishStartPredicate(e)},Xt.defaultSortPredicate=(Rt={},Pt={},Mt={},Tt=[],function(t,e){var i=t._drag,s=i._getGrid(),n=e&&"number"==typeof e.threshold?e.threshold:50,r=e&&"swap"===e.action?"swap":"move",o=e&&"swap"===e.migrateAction?"swap":"move";n=Math.min(Math.max(n,1),100),Rt.width=t._width,Rt.height=t._height,Rt.left=i._elementClientX,Rt.top=i._elementClientY;var h=function(t,e,i){var s,n,r,o,h=null,a=e._settings.dragSort,_=-1;if(!0===a?(Tt[0]=e,n=Tt):c(a)&&(n=a.call(e,t)),!n||!Array.isArray(n)||!n.length)return h;for(o=0;oi&&s>_&&(_=s,h=r));return Tt.length=0,h}(t,s,n);if(!h)return!1;var a,_,l,d=t.getGrid()!==h,u=0,f=0,p=0,m=-1,g=!1;for(h===s?(Rt.left=i._gridX+t._marginLeft,Rt.top=i._gridY+t._marginTop):(h._updateBorders(1,0,1,0),u=h._left+h._borderLeft,f=h._top+h._borderTop),l=0;lp&&(m=l,p=_));return d&&p=n&&(Mt.grid=h,Mt.index=m,Mt.action=d?o:r,Mt)}),Xt.prototype.stop=function(){var t=this._item,e=t._element,i=this._getGrid();return this._isActive?this._isMigrating?(this._finishMigration(),this):(N(t._id),q(t._id),this._unbindScrollListeners(),this._checkOverlapDebounce("cancel"),e.parentNode!==i._element&&(i._element.appendChild(e),e.style[n]=It(this._gridX,this._gridY)),xt(e,i._settings.itemDraggingClass),this._reset(),this):this},Xt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(),this._dragger.destroy(),this._isDestroyed=!0,this)},Xt.prototype._getGrid=function(){return t[this._gridId]||null},Xt.prototype._reset=function(){this._isActive=!1,this._container=null,this._containingBlock=null,this._dragEvent=null,this._scrollEvent=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},Xt.prototype._bindScrollListeners=function(){var t,e,i=this._getGrid()._element,s=this._container,n=this._scrollers;if(n.length=0,vt(this._item._element,!1,n),s!==i)for(vt(i,!0,t=[]),e=0;e=s&&t.pageX=n&&t.pageY3&&e.minBounceBackAngle>0;if(h||(this._hBlockedIndex=null),Math.abs(r)>i||Math.abs(o)>i){if(h){var a=Math.atan2(r,o),_=Math.atan2(this._hX2-this._hX1,this._hY2-this._hY1),l=Math.atan2(Math.sin(a-_),Math.cos(a-_));Math.abs(l)>e.minBounceBackAngle&&(this._hBlockedIndex=null)}return this._hX1=this._hX2,this._hY1=this._hY2,this._hX2=s,this._hY2=n,!0}return!1},Xt.prototype._resetStartPredicate=function(){var t=this._startPredicateData;t&&(t.delayTimer&&(t.delayTimer=window.clearTimeout(t.delayTimer)),this._startPredicateData=null)},Xt.prototype._checkOverlap=function(){if(this._isActive){var t,e,i,s,n,r,o,h,a=this._item,_=this._getGrid()._settings;(t=c(_.dragSortPredicate)?_.dragSortPredicate(a,this._dragEvent):Xt.defaultSortPredicate(a,_.dragSortPredicate))&&"number"==typeof t.index&&(h=(e=a.getGrid())!==(s=t.grid||e),i=e._items.indexOf(a),n=J(s._items,t.index,h),o="swap"===t.action?"swap":"move",(h||n!==this._hBlockedIndex)&&(h?(this._hBlockedIndex=null,r=s._items[n],e._hasListeners("beforeSend")&&e._emit("beforeSend",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("beforeReceive")&&s._emit("beforeReceive",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),a._gridId=s._id,this._isMigrating=a._gridId!==this._gridId,e._items.splice(i,1),$(s._items,a,n),a._sortData=null,e._hasListeners("send")&&e._emit("send",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("receive")&&s._emit("receive",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),"swap"===o&&r&&r.isActive()&&s._items.indexOf(r)>-1&&s.send(r,e,i,{appendTo:this._container||window.document.body,layoutSender:!1,layoutReceiver:!1}),e.layout(),s.layout()):i!==n&&(this._hBlockedIndex=i,("swap"===o?Q:K)(e._items,i,n),e._hasListeners("move")&&e._emit("move",{item:a,fromIndex:i,toIndex:n,action:o}),e.layout())))}},Xt.prototype._finishMigration=function(){var t,e,i=this._item,s=i._release,r=i._element,o=i._isActive,h=i.getGrid(),a=h._element,_=h._settings,l=_.dragContainer||a,d=this._getGrid()._settings,c=r.parentNode;this._isMigrating=!1,this.destroy(),xt(r,d.itemClass),xt(r,d.itemVisibleClass),xt(r,d.itemHiddenClass),j(r,_.itemClass),j(r,o?_.itemVisibleClass:_.itemHiddenClass),l!==c&&(l.appendChild(r),e=ct(c,l,!0),(t=Lt(r)).x-=e.left,t.y-=e.top),i._refreshDimensions(),i._refreshSortData(),e=ct(l,a,!0),s._containerDiffX=e.left,s._containerDiffY=e.top,i._drag=_.dragEnabled?new Xt(i):null,l!==c&&(r.style[n]=It(t.x,t.y)),i._child.removeAttribute("style"),f(i._child,o?_.visibleStyles:_.hiddenStyles),s.start()},Xt.prototype._preStartCheck=function(t){this._startPredicateState===kt&&(this._startPredicateState=1),1===this._startPredicateState?(this._startPredicateResult=this._startPredicate(this._item,t),!0===this._startPredicateResult?(this._startPredicateState=2,this._onStart(t)):!1===this._startPredicateResult&&(this._startPredicateState=3)):2===this._startPredicateState&&this._isActive&&this._onMove(t)},Xt.prototype._preEndCheck=function(t){var e=2===this._startPredicateState;this._startPredicate(this._item,t),this._startPredicateState=kt,e&&this._isActive&&this._onEnd(t)},Xt.prototype._onStart=function(t){var e=this._item;if(e._isActive){var i,s=e._element,r=this._getGrid(),o=r._settings,h=e._release,a=e._migrate,_=r._element,l=o.dragContainer||_,d=ot(l,!0),c=Lt(s),u=c.x,f=c.y,p=s.getBoundingClientRect(),m=l!==_;this._resetHeuristics(t),m&&(i=ct(d,_)),e.isPositioning()&&e._layout.stop(!0,{transform:It(u,f)}),a._isActive&&(u-=a._containerDiffX,f-=a._containerDiffY,a.stop(!0,{transform:It(u,f)})),e.isReleasing()&&h._reset(),this._isActive=!0,this._dragEvent=t,this._container=l,this._containingBlock=d,this._elementClientX=p.left,this._elementClientY=p.top,this._left=this._gridX=u,this._top=this._gridY=f,o.dragPlaceholder.enabled&&e._dragPlaceholder.create(),r._emit("dragInit",e,t),m&&(this._containerDiffX=i.left,this._containerDiffY=i.top,s.parentNode===l?(this._gridX=u-this._containerDiffX,this._gridY=f-this._containerDiffY):(this._left=u+this._containerDiffX,this._top=f+this._containerDiffY,l.appendChild(s),s.style[n]=It(this._left,this._top))),j(s,o.itemDraggingClass),this._bindScrollListeners(),r._emit("dragStart",e,t)}},Xt.prototype._onMove=function(t){var e=this._item;if(e._isActive){var i,s,n,r=this._getGrid()._settings.dragAxis;if("y"!==r){var o=t.clientX-this._dragEvent.clientX;this._left+=o,this._gridX+=o,this._elementClientX+=o}if("x"!==r){var h=t.clientY-this._dragEvent.clientY;this._top+=h,this._gridY+=h,this._elementClientY+=h}this._dragEvent=t,i=e._id,s=this._prepareMove,n=this._applyMove,k.add(i+G,s,n,!0)}else this.stop()},Xt.prototype._prepareMove=function(){this._item._isActive&&this._getGrid()._settings.dragSort&&this._checkHeuristics(this._dragEvent)&&this._checkOverlapDebounce()},Xt.prototype._applyMove=function(){var t=this._item;t._isActive&&(t._element.style[n]=It(this._left,this._top),this._getGrid()._emit("dragMove",t,this._dragEvent))},Xt.prototype._onScroll=function(t){var e,i,s,n=this._item;n._isActive?(this._scrollEvent=t,e=n._id,i=this._prepareScroll,s=this._applyScroll,k.add(e+H,i,s,!0)):this.stop()},Xt.prototype._prepareScroll=function(){var t=this._item;if(t._isActive){var e,i=t._element,s=this._getGrid(),n=s._settings,r=n.dragAxis,o=s._element,h=i.getBoundingClientRect(),a=this._elementClientX-h.left,_=this._elementClientY-h.top;this._container!==o&&(e=ct(this._containingBlock,o),this._containerDiffX=e.left,this._containerDiffY=e.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()}},Xt.prototype._applyScroll=function(){var t=this._item;t._isActive&&(t._element.style[n]=It(this._left,this._top),this._getGrid()._emit("dragScroll",t,this._scrollEvent))},Xt.prototype._onEnd=function(t){var e=this._item,i=e._element,s=this._getGrid(),n=s._settings,r=e._release;e._isActive?(N(e._id),q(e._id),n.dragSort&&this._checkOverlapDebounce("finish"),this._unbindScrollListeners(),r._containerDiffX=this._containerDiffX,r._containerDiffY=this._containerDiffY,this._reset(),xt(i,n.itemDraggingClass),s._emit("dragEnd",e,t),this._isMigrating?this._finishMigration():r.start()):this.stop()},Gt.prototype._onLayoutStart=function(){var t=this._item,e=t.getGrid(),i=e._items.indexOf(t),s=e._layout.slots[2*i],n=e._layout.slots[2*i+1];if(this._didMigrate||t._left!==s||t._top!==n){var r,o,h;if(s+=t._marginLeft,n+=t._marginTop,!(e._settings.dragPlaceholder.duration>0)||this._didMigrate){F(t._id);var a={transform:It(s,n)};return this._animate.isAnimating()?this._animate.stop(a):f(this._element,a),void(this._didMigrate&&(e.getElement().appendChild(this._element),this._didMigrate=!1))}this._nextLeft=s,this._nextTop=n,r=t._id,o=this._setupAnimation,h=this._startAnimation,k.add(r+O,o,h)}},Gt.prototype._setupAnimation=function(){if(this.isActive()){var t=Lt(this._element);this._currentLeft=t.x,this._currentTop=t.y}},Gt.prototype._startAnimation=function(){if(this.isActive()){var t=this._animate,e=this._currentLeft,i=this._currentTop,s=this._nextLeft,n=this._nextTop,r={transform:It(s,n)};if(e!==s||i!==n){var o=this._item.getGrid()._settings.dragPlaceholder,h={transform:It(e,i)};t.start(h,r,{duration:o.duration,easing:o.easing,onFinish:this._onLayoutEnd})}else t.isAnimating()&&t.stop(r)}},Gt.prototype._onLayoutEnd=function(){this._resetAfterLayout&&this.reset()},Gt.prototype._onReleaseEnd=function(t){if(t._id===this._item._id){if(!this._animate.isAnimating())return void this.reset();this._resetAfterLayout=!0}},Gt.prototype._onMigrate=function(t){if(t.item===this._item){var e=this._item.getGrid(),i=t.toGrid;e.off("dragReleaseEnd",this._onReleaseEnd),e.off("layoutStart",this._onLayoutStart),e.off("beforeSend",this._onMigrate),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("layoutStart",this._onLayoutStart),i.on("beforeSend",this._onMigrate),this._didMigrate=!0}},Gt.prototype.create=function(){if(this.isActive())this._resetAfterLayout=!1;else{var t,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;t=c(s.dragPlaceholder.createElement)?s.dragPlaceholder.createElement(e):window.document.createElement("div"),this._element=t,n._element=t,this._className=s.itemPlaceholderClass||"",this._className&&j(t,this._className);var r=e._left+e._marginLeft,o=e._top+e._marginTop;f(t,{display:"block",position:"absolute",left:"0",top:"0",width:e._width+"px",height:e._height+"px",transform:It(r,o)}),i.on("layoutStart",this._onLayoutStart),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("beforeSend",this._onMigrate),c(s.dragPlaceholder.onCreate)&&s.dragPlaceholder.onCreate(e,t),i.getElement().appendChild(t)}},Gt.prototype.reset=function(){if(this.isActive()){var t=this._element,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;this._resetAfterLayout=!1,F(e._id),n.stop(),n._element=null,i.off("dragReleaseEnd",this._onReleaseEnd),i.off("layoutStart",this._onLayoutStart),i.off("beforeSend",this._onMigrate),this._className&&(xt(t,this._className),this._className=""),t.parentNode.removeChild(t),this._element=null,c(s.dragPlaceholder.onRemove)&&s.dragPlaceholder.onRemove(e,t)}},Gt.prototype.updateDimensions=function(t,e){this.isActive()&&f(this._element,{width:t+"px",height:e+"px"})},Gt.prototype.isActive=function(){return!!this._element},Gt.prototype.destroy=function(){this.reset(),this._animate.destroy(),this._item=this._animate=null},Ht.prototype.add=function(t){return this._isDestroyed?this:(this._queue.push(t),this)},Ht.prototype.flush=function(t,e){if(this._isDestroyed)return this;var i,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,e),this;for(i=0;i0;return l&&this._queue.flush(!0,o),d&&(a._isPositioningStarted=!0),c(e)&&this._queue.add(e),m?(this._isActive=!0,this._animateOptions.easing=p,this._animateOptions.duration=u,this._isInterrupted=l,s=o._id,n=this._setupAnimation,r=this._startAnimation,k.add(s+X,n,r),this):(this._updateOffsets(),this._updateTargetStyles(),i=o._animate.isAnimating(),this.stop(!1,this._targetStyles),!i&&f(h,this._targetStyles),this._skipNextAnimation=!1,this._finish())}},Ot.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item;return i=s._id,k.cancel(i+X),s._animate.stop(e),xt(s._element,s.getGrid()._settings.itemPositioningClass),this._isActive=!1,t&&this._queue.flush(!0,s),this},Ot.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)},Ot.prototype._updateOffsets=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._offsetLeft=i._isActive?i._containerDiffX:e._isActive?e._containerDiffX:0,this._offsetTop=i._isActive?i._containerDiffY:e._isActive?e._containerDiffY:0}},Ot.prototype._updateTargetStyles=function(){this._isDestroyed||(this._targetStyles.transform=It(this._item._left+this._offsetLeft,this._item._top+this._offsetTop))},Ot.prototype._finish=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._isActive&&(this._isActive=!1,xt(t._element,t.getGrid()._settings.itemPositioningClass)),i._isActive&&i.stop(),e._isActive&&e.stop(),this._queue.flush(!1,t)}},Ot.prototype._setupAnimation=function(){var t=Lt(this._item._element);this._currentLeft=t.x,this._currentTop=t.y},Ot.prototype._startAnimation=function(){var t=this._item,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||j(t._element,e.itemPositioningClass),this._currentStyles.transform=It(this._currentLeft,this._currentTop),t._animate.start(this._currentStyles,this._targetStyles,this._animateOptions)};var Bt={};function Nt(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._container=!1,this._containerDiffX=0,this._containerDiffY=0}Nt.prototype.start=function(t,e,i){if(this._isDestroyed)return this;var s,r,o,h,a,_,l,d,c=this._item,u=c._element,p=c.isVisible(),m=c.getGrid(),g=m._settings,y=t._settings,v=t._element,w=t._items,S=m._items.indexOf(c),D=i||window.document.body;if("number"==typeof e)s=J(w,e,!0);else{if(!(r=t._getItem(e)))return this;s=w.indexOf(r)}return(c.isPositioning()||this._isActive||c.isReleasing())&&(l=(_=Lt(u)).x,d=_.y),c.isPositioning()&&c._layout.stop(!0,{transform:It(l,d)}),this._isActive&&(l-=this._containerDiffX,d-=this._containerDiffY,this.stop(!0,{transform:It(l,d)})),c.isReleasing()&&(l-=c._release._containerDiffX,d-=c._release._containerDiffY,c._release.stop(!0,{transform:It(l,d)})),c._visibility._stopAnimation(),c._drag&&c._drag.destroy(),c._visibility._queue.flush(!0,c),m._hasListeners("beforeSend")&&m._emit("beforeSend",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("beforeReceive")&&t._emit("beforeReceive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),xt(u,g.itemClass),xt(u,g.itemVisibleClass),xt(u,g.itemHiddenClass),j(u,y.itemClass),j(u,p?y.itemVisibleClass:y.itemHiddenClass),m._items.splice(S,1),$(w,c,s),c._gridId=t._id,D!==(o=u.parentNode)&&(D.appendChild(u),h=ct(D,o,!0),_||(l=(_=Lt(u)).x,d=_.y),u.style[n]=It(l+h.left,d+h.top)),c._child.removeAttribute("style"),f(c._child,p?y.visibleStyles:y.hiddenStyles),u.style.display=p?"block":"hidden",a=ct(D,v,!0),c._refreshDimensions(),c._refreshSortData(),c._drag=y.dragEnabled?new Xt(c):null,this._isActive=!0,this._container=D,this._containerDiffX=a.left,this._containerDiffY=a.top,m._hasListeners("send")&&m._emit("send",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("receive")&&t._emit("receive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),this},Nt.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid()._element;return this._container!==r&&(e||(t?(i=Lt(n),Bt.transform=It(i.x-this._containerDiffX,i.y-this._containerDiffY)):Bt.transform=It(s._left,s._top),e=Bt),r.appendChild(n),f(n,e)),this._isActive=!1,this._container=null,this._containerDiffX=0,this._containerDiffY=0,this},Nt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)};var qt={};function Ft(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0}function zt(t){var e=t._isActive,i=t._element,s=t.getGrid()._settings;this._item=t,this._isDestroyed=!1,this._isHidden=!e,this._isHiding=!1,this._isShowing=!1,this._queue=new Ht,this._finishShow=this._finishShow.bind(this),this._finishHide=this._finishHide.bind(this),i.style.display=e?"block":"none",j(i,e?s.itemVisibleClass:s.itemHiddenClass),f(t._child,e?s.visibleStyles:s.hiddenStyles)}Ft.prototype.start=function(){if(this._isDestroyed||this._isActive)return this;var t=this._item,e=t.getGrid();return this._isActive=!0,j(t._element,e._settings.itemReleasingClass),e._emit("dragReleaseStart",t),t._layout.start(!1),this},Ft.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid(),o=r._element;return this._reset(),n.parentNode!==o&&(e||(t?(i=Lt(n),qt.transform=It(i.x-this._containerDiffX,i.y-this._containerDiffY)):qt.transform=It(s._left,s._top),e=qt),o.appendChild(n),f(n,e)),t||r._emit("dragReleaseEnd",s),this},Ft.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)},Ft.prototype._reset=function(){if(!this._isDestroyed){var t=this._item;this._isActive=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0,xt(t._element,t.getGrid()._settings.itemReleasingClass)}},zt.prototype.show=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return this._isShowing||this._isHidden?this._isShowing&&!t?(r&&n.add(r),this):(this._isShowing||(n.flush(!0,i),xt(s,o.itemHiddenClass),j(s,o.itemVisibleClass),this._isHiding||(s.style.display="block")),r&&n.add(r),i._isActive=this._isShowing=!0,this._isHiding=this._isHidden=!1,this._startAnimation(!0,t,this._finishShow),this):(r&&r(!1,i),this)},zt.prototype.hide=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return!this._isHiding&&this._isHidden?(r&&r(!1,i),this):this._isHiding&&!t?(r&&n.add(r),this):(this._isHiding||(n.flush(!0,i),j(s,o.itemHiddenClass),xt(s,o.itemVisibleClass)),r&&n.add(r),this._isHidden=this._isHiding=!0,i._isActive=this._isShowing=!1,this._startAnimation(!1,t,this._finishHide),this)},zt.prototype.destroy=function(){if(this._isDestroyed)return this;var t=this._item,e=t._element,i=t.getGrid(),s=this._queue,n=i._settings;return this._stopAnimation({}),s.flush(!0,t).destroy(),xt(e,n.itemVisibleClass),xt(e,n.itemHiddenClass),this._item=null,this._isHiding=this._isShowing=!1,this._isDestroyed=this._isHidden=!0,this},zt.prototype._startAnimation=function(t,e,i){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,_=(t?r.showEasing:r.hideEasing)||"ease",d=e||h<=0;if(o){if(B(n._id),d)return n._animateChild.isAnimating()?n._animateChild.stop(o):f(n._child,o),void(i&&i());var c,u,p;c=n._id,u=function(){s=function(t,e){var i={};for(var s in e)i[s]=a(t,l(s));return i}(n._child,o)},p=function(){n._animateChild.start(s,o,{duration:h,easing:_,onFinish:i})},k.add(c+Y,u,p)}else i&&i()}},zt.prototype._stopAnimation=function(t){if(!this._isDestroyed){var e=this._item;B(e._id),e._animateChild.stop(t)}},zt.prototype._finishShow=function(){this._isHidden||(this._isShowing=!1,this._queue.flush(!1,this._item))};var Vt={};zt.prototype._finishHide=function(){if(this._isHidden){var t=this._item;this._isHiding=!1,Vt.transform=It(0,0),t._layout.stop(!0,Vt),t._element.style.display="none",this._queue.flush(!1,t)}};var Wt,jt,Ut,Zt,$t=0;function Jt(){return++$t}function Kt(t,e,i){var s=t._settings;this._id=Jt(),this._gridId=t._id,this._isDestroyed=!1,this._left=0,this._top=0,this._element=e,this._child=e.children[0],e.parentNode!==t._element&&t._element.appendChild(e),j(e,s.itemClass),"boolean"!=typeof i&&(i="none"!==a(e,"display")),this._isActive=i,e.style.left="0",e.style.top="0",e.style[n]=It(0,0),this._animate=new p(e),this._animateChild=new p(this._child),this._visibility=new zt(this),this._layout=new Ot(this),this._migrate=new Nt(this),this._release=new Ft(this),this._dragPlaceholder=new Gt(this),this._drag=s.dragEnabled?new Xt(this):null,this._refreshDimensions(),this._refreshSortData()}function Qt(){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)}Kt.prototype.getGrid=function(){return t[this._gridId]},Kt.prototype.getElement=function(){return this._element},Kt.prototype.getWidth=function(){return this._width},Kt.prototype.getHeight=function(){return this._height},Kt.prototype.getMargin=function(){return{left:this._marginLeft,right:this._marginRight,top:this._marginTop,bottom:this._marginBottom}},Kt.prototype.getPosition=function(){return{left:this._left,top:this._top}},Kt.prototype.isActive=function(){return this._isActive},Kt.prototype.isVisible=function(){return!!this._visibility&&!this._visibility._isHidden},Kt.prototype.isShowing=function(){return!(!this._visibility||!this._visibility._isShowing)},Kt.prototype.isHiding=function(){return!(!this._visibility||!this._visibility._isHiding)},Kt.prototype.isPositioning=function(){return!(!this._layout||!this._layout._isActive)},Kt.prototype.isDragging=function(){return!(!this._drag||!this._drag._isActive)},Kt.prototype.isReleasing=function(){return!(!this._release||!this._release._isActive)},Kt.prototype.isDestroyed=function(){return this._isDestroyed},Kt.prototype._refreshDimensions=function(){if(!this._isDestroyed&&!this._visibility._isHidden){var t=this._element,e=this._dragPlaceholder,i=t.getBoundingClientRect();this._width=i.width,this._height=i.height,this._marginLeft=Math.max(0,ht(t,"margin-left")),this._marginRight=Math.max(0,ht(t,"margin-right")),this._marginTop=Math.max(0,ht(t,"margin-top")),this._marginBottom=Math.max(0,ht(t,"margin-bottom")),e&&e.updateDimensions(this._width,this._height)}},Kt.prototype._refreshSortData=function(){if(!this._isDestroyed){var t,e=this._sortData={},i=this.getGrid()._settings.sortData;for(t in i)e[t]=i[t](this,this._element)}},Kt.prototype._destroy=function(t){if(!this._isDestroyed){var e=this._element,i=this.getGrid(),s=i._settings,n=i._items.indexOf(this);this._release.destroy(),this._migrate.destroy(),this._layout.destroy(),this._visibility.destroy(),this._animate.destroy(),this._animateChild.destroy(),this._dragPlaceholder.destroy(),this._drag&&this._drag.destroy(),e.removeAttribute("style"),this._child.removeAttribute("style"),xt(e,s.itemClass),n>-1&&i._items.splice(n,1),t&&e.parentNode.removeChild(e),this._isActive=!1,this._isDestroyed=!0}},Qt.prototype.getLayout=function(t,e,i,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),c=this._slotSizes;if(o.slots=s||this._slots,o.width=a?0:d?Math.round(e):e,o.height=a?d?Math.round(i):i:0,o.setWidth=a,o.setHeight=!a,o.slots.length=0,c.length=0,!t.length)return o;for(r=0;rd.height&&(Wt.left>0&&u.push(this._addRect(0,d.height,Wt.left,1/0)),Wt.left+Wt.widthd.width&&(Wt.top>0&&u.push(this._addRect(d.width,0,1/0,Wt.top)),Wt.top+Wt.height.49&&r.height>.49&&(!e&&r.tope.left+e.width&&jt.push(this._addRect(e.left+e.width,t.top,t.left+t.width-(e.left+e.width),t.height)),t.tope.top+e.height&&jt.push(this._addRect(t.left,e.top+e.height,t.width,t.top+t.height-(e.top+e.height))),jt):(jt.push(this._addRect(t.left,t.top,t.width,t.height)),jt)}),Qt.prototype._doRectsOverlap=function(t,e){return!(t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top)},Qt.prototype._isRectWithinRect=function(t,e){return t.left>=e.left&&t.top>=e.top&&t.left+t.width<=e.left+e.width&&t.top+t.height<=e.top+e.height},Qt.prototype._purgeRects=(Ut={},Zt={},function(t){for(var e,i=t.length;i--;)if(e=t.length,t[i])for(this._getRect(t[i],Ut);e--;)if(t[e]&&i!==e&&this._isRectWithinRect(Ut,this._getRect(t[e],Zt))){t[i]=0;break}return t}),Qt.prototype._sortRectsTopLeft=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.tope.top?1:t.lefte.left?1:0}}(),Qt.prototype._sortRectsLeftTop=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.lefte.left?1:t.tope.top?1:0}}();var te="[object HTMLCollection]",ee="[object NodeList]";function ie(t){var e=Object.prototype.toString.call(t);return e===te||e===ee}var se="object",ne="[object Object]",re=Object.prototype.toString;function oe(t){return typeof t===se&&re.call(t)===ne}function he(t){return ie(t)?Array.prototype.slice.call(t):Array.prototype.concat(t)}var ae=new Qt,_e=function(){},le="number",de="string";function ce(e,s){var n,r,o,h=this;if(!((e=this._element=typeof e===de?window.document.querySelector(e):e).getRootNode?e.getRootNode({composed:!0})===document:window.document.body.contains(e))||e===window.document.documentElement)throw new Error("Container element must be an existing DOM element");c((n=this._settings=function(t,e){var i=ue({},t);e&&(i=ue(i,e));return i.visibleStyles=(e||0).visibleStyles||(t||0).visibleStyles,i.hiddenStyles=(e||0).hiddenStyles||(t||0).hiddenStyles,i}(ce.defaultOptions,s)).dragSort)||(n.dragSort=!!n.dragSort),this._id=Jt(),t[this._id]=h,this._isDestroyed=!1,this._layout={id:0,items:[],slots:[],setWidth:!1,setHeight:!1,width:0,height:0},this._emitter=new i,j(e,n.containerClass),this._items=[],typeof(r=n.items)===de?he(e.children).forEach(function(t){("*"===r||W(t,r))&&h._items.push(new Kt(h,t))}):(Array.isArray(r)||ie(r))&&(this._items=he(r).map(function(t){return new Kt(h,t)})),typeof(o=n.layoutOnResize)!==le&&(o=!0===o?0:-1),o>=0&&window.addEventListener("resize",h._resizeHandler=nt(function(){h.refreshItems().layout()},o)),n.layoutOnInit&&this.layout(!0)}function ue(t,e){var i,s,n,r=Object.keys(e),o=r.length;for(n=0;n0)){var s=o._layout.id!==l,n=c(t)?t:i;c(n)&&n(s,_.items.slice(0)),!s&&o._hasListeners(e)&&o._emit(e,_.items.slice(0))}}if((_.setHeight&&typeof _.height===le||_.setWidth&&typeof _.width===le)&&(s="border-box"===a(h,"box-sizing")),_.setHeight&&(typeof _.height===le?h.style.height=(s?_.height+this._borderTop+this._borderBottom:_.height)+"px":h.style.height=_.height),_.setWidth&&(typeof _.width===le?h.style.width=(s?_.width+this._borderLeft+this._borderRight:_.width)+"px":h.style.width=_.width),this._hasListeners("layoutStart")&&this._emit("layoutStart",_.items.slice(0)),!d)return f(),this;for(r=0;rl?1:0:ld?1:0)return c;return c||(s||(s=n(i)),c=r(o,h)),c}function h(o,h){var a=t(o,h);return e&&a&&(a=-a),a||(s||(s=n(i)),r(o,h))}return function(n,r){if(this._isDestroyed||this._items.length<2)return this;var a,_=this._items,l=r||0,d=l.layout?l.layout:void 0===l.layout;if(t=n,e=!!l.descending,i=_.slice(0),s=null,c(t))_.sort(h);else if(typeof t===de)t=n.trim().split(" ").map(function(t){return t.split(":")}),_.sort(o);else{if(!Array.isArray(t))return this;if(t.length!==_.length)throw new Error("[Muuri] sort reference items do not match with grid items.");for(a=0;a<_.length;a++){if(t.indexOf(_[a])<0)throw new Error("[Muuri] sort reference items do not match with grid items.");_[a]=t[a]}e&&_.reverse()}return this._hasListeners("sort")&&this._emit("sort",_.slice(0),i),d&&this.layout("instant"===d,c(d)?d:void 0),this}}(),ce.prototype.move=function(t,e,i){if(this._isDestroyed||this._items.length<2)return this;var s,n,r=this._items,o=i||0,h=o.layout?o.layout:void 0===o.layout,a="swap"===o.action,_=a?"swap":"move",l=this._getItem(t),d=this._getItem(e);return l&&d&&l!==d&&(s=r.indexOf(l),n=r.indexOf(d),a?Q(r,s,n):K(r,s,n),this._hasListeners("move")&&this._emit("move",{item:l,fromIndex:s,toIndex:n,action:_}),h&&this.layout("instant"===h,c(h)?h:void 0)),this},ce.prototype.send=function(t,e,i,s){if(this._isDestroyed||e._isDestroyed||this===e)return this;if(!(t=this._getItem(t)))return this;var n=s||0,r=n.appendTo||window.document.body,o=n.layoutSender?n.layoutSender:void 0===n.layoutSender,h=n.layoutReceiver?n.layoutReceiver:void 0===n.layoutReceiver;return t._migrate.start(e,i,r),t._migrate._isActive&&t._isActive&&(o&&this.layout("instant"===o,c(o)?o:void 0),h&&e.layout("instant"===h,c(h)?h:void 0)),this},ce.prototype.destroy=function(e){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-1?t:this._items.length+t]||null;if(t instanceof Kt)return t._gridId===this._id?t:null;for(var e=0;e 0 ? matchIndex : -1) : 0; + if (isMigration && matchScore < sortThreshold) { + matchIndex = hasValidTargets ? matchIndex : 0; matchScore = sortThreshold; } diff --git a/src/Item/ItemMigrate.js b/src/Item/ItemMigrate.js index 4584502f..7c31ef79 100644 --- a/src/Item/ItemMigrate.js +++ b/src/Item/ItemMigrate.js @@ -78,7 +78,6 @@ ItemMigrate.prototype.start = function(targetGrid, position, container) { targetIndex = normalizeArrayIndex(targetItems, position, true); } else { targetItem = targetGrid._getItem(position); - /** @todo Consider throwing an error here instead of silently failing. */ if (!targetItem) return this; targetIndex = targetItems.indexOf(targetItem); } From 794828e14369f9ba0845d5324ba63a1752716515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20R=C3=A4m=C3=B6?= Date: Tue, 23 Jul 2019 11:07:14 +0300 Subject: [PATCH 009/120] Update package-lock.json --- package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 5693c1d1..096a22e2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "muuri", - "version": "0.8.0", + "version": "0.9.0", "lockfileVersion": 1, "requires": true, "dependencies": { From 11330563cac0a862a85f6622e10d326fc2e522a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20R=C3=A4m=C3=B6?= Date: Tue, 23 Jul 2019 11:09:12 +0300 Subject: [PATCH 010/120] Update Muuri version number in README. --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index bde5c2fa..15c599cd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Muuri -[![gzip size](https://img.badgesize.io/https://unpkg.com/muuri@0.8.0/dist/muuri.min.js?compression=gzip)](https://unpkg.com/muuri@0.8.0/dist/muuri.min.js) +[![gzip size](https://img.badgesize.io/https://unpkg.com/muuri@0.9.0/dist/muuri.min.js?compression=gzip)](https://unpkg.com/muuri@0.9.0/dist/muuri.min.js) [![npm](https://img.shields.io/npm/v/muuri.svg)](http://npm.im/muuri) Muuri is a JavaScript layout engine that allows you to build all kinds of layouts and make them responsive, sortable, filterable, draggable and/or animated. Comparing to what's out there Muuri is a combination of [Packery](http://packery.metafizzy.co/), [Masonry](http://masonry.desandro.com/), [Isotope](http://isotope.metafizzy.co/) and [Sortable](https://github.com/RubaXa/Sortable). Wanna see it in action? Check out the [demo](http://haltu.github.io/muuri/) on the website. @@ -40,12 +40,12 @@ npm install muuri ``` Or download: -* [muuri.js](https://unpkg.com/muuri@0.8.0/dist/muuri.js) - for development (not minified, with comments). -* [muuri.min.js](https://unpkg.com/muuri@0.8.0/dist/muuri.min.js) - for production (minified, no comments). +* [muuri.js](https://unpkg.com/muuri@0.9.0/dist/muuri.js) - for development (not minified, with comments). +* [muuri.min.js](https://unpkg.com/muuri@0.9.0/dist/muuri.min.js) - for production (minified, no comments). Or link directly: ```html - + ``` ### 2. Get Web Animations Polyfill (if needed) @@ -62,7 +62,7 @@ Add Muuri on your site and make sure to include the Web Animations Polyfill befo ```html - + ``` ### 4. Add the markup From ee866c718d97eca55c6bd80792f6d48e06a831b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20R=C3=A4m=C3=B6?= Date: Fri, 26 Jul 2019 12:24:43 +0300 Subject: [PATCH 011/120] Fix dependency vulnerabilities. --- package-lock.json | 65 +++++++++++++++-------------------------------- 1 file changed, 21 insertions(+), 44 deletions(-) diff --git a/package-lock.json b/package-lock.json index 096a22e2..dd0f5455 100644 --- a/package-lock.json +++ b/package-lock.json @@ -324,9 +324,9 @@ }, "dependencies": { "lodash": { - "version": "4.17.11", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", + "version": "4.17.15", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", "dev": true } } @@ -3556,9 +3556,9 @@ }, "dependencies": { "lodash": { - "version": "4.17.11", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", + "version": "4.17.15", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", "dev": true }, "source-map": { @@ -3744,9 +3744,9 @@ } }, "lodash": { - "version": "4.17.11", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", + "version": "4.17.15", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", "dev": true }, "lodash.debounce": { @@ -3994,9 +3994,9 @@ } }, "mixin-deep": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.1.tgz", - "integrity": "sha512-8ZItLHeEgaqEvd5lYBXfm4EZSFCX29Jb9K+lAHhDKzReKBQKj3R+7NOF6tjqYi9t4oI8VUfaWITJQm86wnXGNQ==", + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.2.tgz", + "integrity": "sha512-WRoDn//mXBiJ1H40rqa3vH0toePwSsGb45iInWlTySa+Uu4k3tYUSxa2v1KqAiLtvlrSzaExqS1gtk96A9zvEA==", "dev": true, "requires": { "for-in": "^1.0.2", @@ -4323,7 +4323,7 @@ }, "os-locale": { "version": "1.4.0", - "resolved": "http://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz", + "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz", "integrity": "sha1-IPnxeuKe00XoveWDsT0gCYA8FNk=", "dev": true, "requires": { @@ -5083,9 +5083,9 @@ "dev": true }, "set-value": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/set-value/-/set-value-2.0.0.tgz", - "integrity": "sha512-hw0yxk9GT/Hr5yJEYnHNKYXkIA8mVJgd9ditYZCe16ZczcaELYYcfvaXesNACk2O8O0nTiPQcQhGUQj8JLzeeg==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/set-value/-/set-value-2.0.1.tgz", + "integrity": "sha512-JxHc1weCN68wRY0fhCoXpyK55m/XPHafOmK4UWD7m2CI14GMcFypt4w/0+NV5f/ZMby2F6S2wwA7fgynh9gWSw==", "dev": true, "requires": { "extend-shallow": "^2.0.1", @@ -5885,38 +5885,15 @@ "dev": true }, "union-value": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.0.tgz", - "integrity": "sha1-XHHDTLW61dzr4+oM0IIHulqhrqQ=", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz", + "integrity": "sha512-tJfXmxMeWYnczCVs7XAEvIV7ieppALdyepWMkHkwciRpZraG/xwT+s2JN8+pr1+8jCRf80FFzvr+MpQeeoF4Xg==", "dev": true, "requires": { "arr-union": "^3.1.0", "get-value": "^2.0.6", "is-extendable": "^0.1.1", - "set-value": "^0.4.3" - }, - "dependencies": { - "extend-shallow": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz", - "integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=", - "dev": true, - "requires": { - "is-extendable": "^0.1.0" - } - }, - "set-value": { - "version": "0.4.3", - "resolved": "https://registry.npmjs.org/set-value/-/set-value-0.4.3.tgz", - "integrity": "sha1-fbCPnT0i3H945Trzw79GZuzfzPE=", - "dev": true, - "requires": { - "extend-shallow": "^2.0.1", - "is-extendable": "^0.1.1", - "is-plain-object": "^2.0.1", - "to-object-path": "^0.3.0" - } - } + "set-value": "^2.0.1" } }, "unique-stream": { @@ -6144,7 +6121,7 @@ }, "wrap-ansi": { "version": "2.1.0", - "resolved": "http://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", "integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=", "dev": true, "requires": { From abfd9bc9f1b7c69fe9d3c7a194800c6ad43d54d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20R=C3=A4m=C3=B6?= Date: Fri, 26 Jul 2019 13:06:53 +0300 Subject: [PATCH 012/120] wip --- src/Grid/Grid.js | 121 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 88 insertions(+), 33 deletions(-) diff --git a/src/Grid/Grid.js b/src/Grid/Grid.js index 4732c19f..63c6a34f 100644 --- a/src/Grid/Grid.js +++ b/src/Grid/Grid.js @@ -52,7 +52,7 @@ import removeClass from '../utils/removeClass'; import toArray from '../utils/toArray'; var packer = new Packer(); -var noop = function() {}; +var noop = function () { }; var numberType = 'number'; var stringType = 'string'; @@ -173,13 +173,13 @@ function Grid(element, options) { this._items = []; items = settings.items; if (typeof items === stringType) { - toArray(element.children).forEach(function(itemElement) { + toArray(element.children).forEach(function (itemElement) { if (items === '*' || elementMatches(itemElement, items)) { inst._items.push(new Item(inst, itemElement)); } }); } else if (Array.isArray(items) || isNodeList(items)) { - this._items = toArray(items).map(function(itemElement) { + this._items = toArray(items).map(function (itemElement) { return new Item(inst, itemElement); }); } @@ -193,7 +193,7 @@ function Grid(element, options) { if (layoutOnResize >= 0) { window.addEventListener( 'resize', - (inst._resizeHandler = debounce(function() { + (inst._resizeHandler = debounce(function () { inst.refreshItems().layout(); }, layoutOnResize)) ); @@ -373,7 +373,7 @@ Grid.defaultOptions = { * @param {Function} listener * @returns {Grid} */ -Grid.prototype.on = function(event, listener) { +Grid.prototype.on = function (event, listener) { this._emitter.on(event, listener); return this; }; @@ -387,7 +387,7 @@ Grid.prototype.on = function(event, listener) { * @param {Function} listener * @returns {Grid} */ -Grid.prototype.off = function(event, listener) { +Grid.prototype.off = function (event, listener) { this._emitter.off(event, listener); return this; }; @@ -399,7 +399,7 @@ Grid.prototype.off = function(event, listener) { * @memberof Grid.prototype * @returns {HTMLElement} */ -Grid.prototype.getElement = function() { +Grid.prototype.getElement = function () { return this._element; }; @@ -414,7 +414,7 @@ Grid.prototype.getElement = function() { * @param {GridMultiItemQuery} [targets] * @returns {Item[]} */ -Grid.prototype.getItems = function(targets) { +Grid.prototype.getItems = function (targets) { // Return all items immediately if no targets were provided or if the // instance is destroyed. if (this._isDestroyed || (!targets && targets !== 0)) { @@ -435,6 +435,61 @@ Grid.prototype.getItems = function(targets) { return ret; }; +/** + * Update grid options. + * + * @public + * @memberof Grid.prototype + * @param {Object} options + * @returns {Object} + */ +Grid.prototype.updateOptions = function (options) { + var changedProps = Object.keys(options); + var current = this._settings; + var merged = mergeSettings(current, options); + var items = this._items; + var i, item; + + // Step 1: Teardown existing functionality with existing settings (if needed). + + // Disable dragging for items. + if (changedProps.indexOf('dragEnabled') > -1) { + if (current.dragEnabled && !options.dragEnabled) { + for (i = 0; i < items.length; i++) { + item = items[i]; + if (item._drag) { + item._drag.destroy(); + item._drag = null; + } + } + } + } + + // Step 2: Update settings. + this._settings = merged; + + // Step 3: Instantiate new functionality (if needed). + + // Enable dragging for items. + if (changedProps.indexOf('dragEnabled') > -1) { + if (!current.dragEnabled && options.dragEnabled) { + for (i = 0; i < items.length; i++) { + item = items[i]; + if (!item._drag) { + item._drag = new ItemDrag(item); + } + } + } + } + + // Refresh sort data if it potentially changed. + if (changedProps.indexOf('sortData') > -1) { + this.refreshSortData(); + } + + return merged; +}; + /** * Update the cached dimensions of the instance's items. * @@ -443,7 +498,7 @@ Grid.prototype.getItems = function(targets) { * @param {GridMultiItemQuery} [items] * @returns {Grid} */ -Grid.prototype.refreshItems = function(items) { +Grid.prototype.refreshItems = function (items) { if (this._isDestroyed) return this; var targets = this.getItems(items); @@ -464,7 +519,7 @@ Grid.prototype.refreshItems = function(items) { * @param {GridMultiItemQuery} [items] * @returns {Grid} */ -Grid.prototype.refreshSortData = function(items) { +Grid.prototype.refreshSortData = function (items) { if (this._isDestroyed) return this; var targetItems = this.getItems(items); @@ -488,7 +543,7 @@ Grid.prototype.refreshSortData = function(items) { * @memberof Grid.prototype * @returns {Grid} */ -Grid.prototype.synchronize = function() { +Grid.prototype.synchronize = function () { if (this._isDestroyed) return this; var container = this._element; @@ -525,7 +580,7 @@ Grid.prototype.synchronize = function() { * @param {LayoutCallback} [onFinish] * @returns {Grid} */ -Grid.prototype.layout = function(instant, onFinish) { +Grid.prototype.layout = function (instant, onFinish) { if (this._isDestroyed) return this; var inst = this; @@ -638,7 +693,7 @@ Grid.prototype.layout = function(instant, onFinish) { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Item[]} */ -Grid.prototype.add = function(elements, options) { +Grid.prototype.add = function (elements, options) { if (this._isDestroyed || !elements) return []; var newItems = toArray(elements); @@ -694,7 +749,7 @@ Grid.prototype.add = function(elements, options) { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Item[]} */ -Grid.prototype.remove = function(items, options) { +Grid.prototype.remove = function (items, options) { if (this._isDestroyed) return this; var opts = options || 0; @@ -739,7 +794,7 @@ Grid.prototype.remove = function(items, options) { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Grid} */ -Grid.prototype.show = function(items, options) { +Grid.prototype.show = function (items, options) { if (this._isDestroyed) return this; this._setItemsVisibility(items, true, options); return this; @@ -757,7 +812,7 @@ Grid.prototype.show = function(items, options) { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Grid} */ -Grid.prototype.hide = function(items, options) { +Grid.prototype.hide = function (items, options) { if (this._isDestroyed) return this; this._setItemsVisibility(items, false, options); return this; @@ -782,7 +837,7 @@ Grid.prototype.hide = function(items, options) { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Grid} */ -Grid.prototype.filter = function(predicate, options) { +Grid.prototype.filter = function (predicate, options) { if (this._isDestroyed || !this._items.length) return this; var itemsToShow = []; @@ -800,7 +855,7 @@ Grid.prototype.filter = function(predicate, options) { // If we have onFinish callback, let's create proper tryFinish callback. if (onFinish) { - tryFinish = function() { + tryFinish = function () { ++tryFinishCounter && onFinish(itemsToShow.slice(0), itemsToHide.slice(0)); }; } @@ -873,7 +928,7 @@ Grid.prototype.filter = function(predicate, options) { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Grid} */ -Grid.prototype.sort = (function() { +Grid.prototype.sort = (function () { var sortComparer; var isDescending; var origItems; @@ -883,7 +938,7 @@ Grid.prototype.sort = (function() { return data .trim() .split(' ') - .map(function(val) { + .map(function (val) { return val.split(':'); }); } @@ -953,7 +1008,7 @@ Grid.prototype.sort = (function() { return compareIndices(a, b); } - return function(comparer, options) { + return function (comparer, options) { if (this._isDestroyed || this._items.length < 2) return this; var items = this._items; @@ -1025,7 +1080,7 @@ Grid.prototype.sort = (function() { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Grid} */ -Grid.prototype.move = function(item, position, options) { +Grid.prototype.move = function (item, position, options) { if (this._isDestroyed || this._items.length < 2) return this; var items = this._items; @@ -1084,7 +1139,7 @@ Grid.prototype.move = function(item, position, options) { * @param {(Boolean|LayoutCallback|String)} [options.layoutReceiver=true] * @returns {Grid} */ -Grid.prototype.send = function(item, grid, position, options) { +Grid.prototype.send = function (item, grid, position, options) { if (this._isDestroyed || grid._isDestroyed || this === grid) return this; // Make sure we have a valid target item. @@ -1129,7 +1184,7 @@ Grid.prototype.send = function(item, grid, position, options) { * @param {Boolean} [removeElements=false] * @returns {Grid} */ -Grid.prototype.destroy = function(removeElements) { +Grid.prototype.destroy = function (removeElements) { if (this._isDestroyed) return this; var container = this._element; @@ -1180,7 +1235,7 @@ Grid.prototype.destroy = function(removeElements) { * @param {GridSingleItemQuery} [target] * @returns {?Item} */ -Grid.prototype._getItem = function(target) { +Grid.prototype._getItem = function (target) { // If no target is specified or the instance is destroyed, return null. if (this._isDestroyed || (!target && target !== 0)) { return null; @@ -1218,7 +1273,7 @@ Grid.prototype._getItem = function(target) { * @memberof Grid.prototype * @returns {LayoutData} */ -Grid.prototype._updateLayout = function() { +Grid.prototype._updateLayout = function () { var layout = this._layout; var settings = this._settings.layout; var width; @@ -1267,7 +1322,7 @@ Grid.prototype._updateLayout = function() { * @param {String} event * @param {...*} [arg] */ -Grid.prototype._emit = function() { +Grid.prototype._emit = function () { if (this._isDestroyed) return; this._emitter.emit.apply(this._emitter, arguments); }; @@ -1280,7 +1335,7 @@ Grid.prototype._emit = function() { * @param {String} event * @returns {Boolean} */ -Grid.prototype._hasListeners = function(event) { +Grid.prototype._hasListeners = function (event) { var listeners = this._emitter._events[event]; return !!(listeners && listeners.length); }; @@ -1291,7 +1346,7 @@ Grid.prototype._hasListeners = function(event) { * @private * @memberof Grid.prototype */ -Grid.prototype._updateBoundingRect = function() { +Grid.prototype._updateBoundingRect = function () { var element = this._element; var rect = element.getBoundingClientRect(); this._width = rect.width; @@ -1310,7 +1365,7 @@ Grid.prototype._updateBoundingRect = function() { * @param {Boolean} top * @param {Boolean} bottom */ -Grid.prototype._updateBorders = function(left, right, top, bottom) { +Grid.prototype._updateBorders = function (left, right, top, bottom) { var element = this._element; if (left) this._borderLeft = getStyleAsFloat(element, 'border-left-width'); if (right) this._borderRight = getStyleAsFloat(element, 'border-right-width'); @@ -1324,7 +1379,7 @@ Grid.prototype._updateBorders = function(left, right, top, bottom) { * @private * @memberof Grid.prototype */ -Grid.prototype._refreshDimensions = function() { +Grid.prototype._refreshDimensions = function () { this._updateBoundingRect(); this._updateBorders(1, 1, 1, 1); }; @@ -1341,7 +1396,7 @@ Grid.prototype._refreshDimensions = function() { * @param {(ShowCallback|HideCallback)} [options.onFinish] * @param {(Boolean|LayoutCallback|String)} [options.layout=true] */ -Grid.prototype._setItemsVisibility = function(items, toVisible, options) { +Grid.prototype._setItemsVisibility = function (items, toVisible, options) { var grid = this; var targetItems = this.getItems(items); var opts = options || 0; @@ -1392,7 +1447,7 @@ Grid.prototype._setItemsVisibility = function(items, toVisible, options) { } // Show/hide the item. - item._visibility[method](isInstant, function(interrupted, item) { + item._visibility[method](isInstant, function (interrupted, item) { // If the current item's animation was not interrupted add it to the // completedItems array. if (!interrupted) completedItems.push(item); From c9f79cc2eab0f9ec5f3b973e6d26f32162f3d546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20R=C3=A4m=C3=B6?= Date: Fri, 26 Jul 2019 13:07:10 +0300 Subject: [PATCH 013/120] wip --- src/Grid/Grid.js | 68 ++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/Grid/Grid.js b/src/Grid/Grid.js index 63c6a34f..f2d414f8 100644 --- a/src/Grid/Grid.js +++ b/src/Grid/Grid.js @@ -52,7 +52,7 @@ import removeClass from '../utils/removeClass'; import toArray from '../utils/toArray'; var packer = new Packer(); -var noop = function () { }; +var noop = function() {}; var numberType = 'number'; var stringType = 'string'; @@ -173,13 +173,13 @@ function Grid(element, options) { this._items = []; items = settings.items; if (typeof items === stringType) { - toArray(element.children).forEach(function (itemElement) { + toArray(element.children).forEach(function(itemElement) { if (items === '*' || elementMatches(itemElement, items)) { inst._items.push(new Item(inst, itemElement)); } }); } else if (Array.isArray(items) || isNodeList(items)) { - this._items = toArray(items).map(function (itemElement) { + this._items = toArray(items).map(function(itemElement) { return new Item(inst, itemElement); }); } @@ -193,7 +193,7 @@ function Grid(element, options) { if (layoutOnResize >= 0) { window.addEventListener( 'resize', - (inst._resizeHandler = debounce(function () { + (inst._resizeHandler = debounce(function() { inst.refreshItems().layout(); }, layoutOnResize)) ); @@ -373,7 +373,7 @@ Grid.defaultOptions = { * @param {Function} listener * @returns {Grid} */ -Grid.prototype.on = function (event, listener) { +Grid.prototype.on = function(event, listener) { this._emitter.on(event, listener); return this; }; @@ -387,7 +387,7 @@ Grid.prototype.on = function (event, listener) { * @param {Function} listener * @returns {Grid} */ -Grid.prototype.off = function (event, listener) { +Grid.prototype.off = function(event, listener) { this._emitter.off(event, listener); return this; }; @@ -399,7 +399,7 @@ Grid.prototype.off = function (event, listener) { * @memberof Grid.prototype * @returns {HTMLElement} */ -Grid.prototype.getElement = function () { +Grid.prototype.getElement = function() { return this._element; }; @@ -414,7 +414,7 @@ Grid.prototype.getElement = function () { * @param {GridMultiItemQuery} [targets] * @returns {Item[]} */ -Grid.prototype.getItems = function (targets) { +Grid.prototype.getItems = function(targets) { // Return all items immediately if no targets were provided or if the // instance is destroyed. if (this._isDestroyed || (!targets && targets !== 0)) { @@ -443,7 +443,7 @@ Grid.prototype.getItems = function (targets) { * @param {Object} options * @returns {Object} */ -Grid.prototype.updateOptions = function (options) { +Grid.prototype.updateOptions = function(options) { var changedProps = Object.keys(options); var current = this._settings; var merged = mergeSettings(current, options); @@ -498,7 +498,7 @@ Grid.prototype.updateOptions = function (options) { * @param {GridMultiItemQuery} [items] * @returns {Grid} */ -Grid.prototype.refreshItems = function (items) { +Grid.prototype.refreshItems = function(items) { if (this._isDestroyed) return this; var targets = this.getItems(items); @@ -519,7 +519,7 @@ Grid.prototype.refreshItems = function (items) { * @param {GridMultiItemQuery} [items] * @returns {Grid} */ -Grid.prototype.refreshSortData = function (items) { +Grid.prototype.refreshSortData = function(items) { if (this._isDestroyed) return this; var targetItems = this.getItems(items); @@ -543,7 +543,7 @@ Grid.prototype.refreshSortData = function (items) { * @memberof Grid.prototype * @returns {Grid} */ -Grid.prototype.synchronize = function () { +Grid.prototype.synchronize = function() { if (this._isDestroyed) return this; var container = this._element; @@ -580,7 +580,7 @@ Grid.prototype.synchronize = function () { * @param {LayoutCallback} [onFinish] * @returns {Grid} */ -Grid.prototype.layout = function (instant, onFinish) { +Grid.prototype.layout = function(instant, onFinish) { if (this._isDestroyed) return this; var inst = this; @@ -693,7 +693,7 @@ Grid.prototype.layout = function (instant, onFinish) { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Item[]} */ -Grid.prototype.add = function (elements, options) { +Grid.prototype.add = function(elements, options) { if (this._isDestroyed || !elements) return []; var newItems = toArray(elements); @@ -749,7 +749,7 @@ Grid.prototype.add = function (elements, options) { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Item[]} */ -Grid.prototype.remove = function (items, options) { +Grid.prototype.remove = function(items, options) { if (this._isDestroyed) return this; var opts = options || 0; @@ -794,7 +794,7 @@ Grid.prototype.remove = function (items, options) { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Grid} */ -Grid.prototype.show = function (items, options) { +Grid.prototype.show = function(items, options) { if (this._isDestroyed) return this; this._setItemsVisibility(items, true, options); return this; @@ -812,7 +812,7 @@ Grid.prototype.show = function (items, options) { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Grid} */ -Grid.prototype.hide = function (items, options) { +Grid.prototype.hide = function(items, options) { if (this._isDestroyed) return this; this._setItemsVisibility(items, false, options); return this; @@ -837,7 +837,7 @@ Grid.prototype.hide = function (items, options) { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Grid} */ -Grid.prototype.filter = function (predicate, options) { +Grid.prototype.filter = function(predicate, options) { if (this._isDestroyed || !this._items.length) return this; var itemsToShow = []; @@ -855,7 +855,7 @@ Grid.prototype.filter = function (predicate, options) { // If we have onFinish callback, let's create proper tryFinish callback. if (onFinish) { - tryFinish = function () { + tryFinish = function() { ++tryFinishCounter && onFinish(itemsToShow.slice(0), itemsToHide.slice(0)); }; } @@ -928,7 +928,7 @@ Grid.prototype.filter = function (predicate, options) { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Grid} */ -Grid.prototype.sort = (function () { +Grid.prototype.sort = (function() { var sortComparer; var isDescending; var origItems; @@ -938,7 +938,7 @@ Grid.prototype.sort = (function () { return data .trim() .split(' ') - .map(function (val) { + .map(function(val) { return val.split(':'); }); } @@ -1008,7 +1008,7 @@ Grid.prototype.sort = (function () { return compareIndices(a, b); } - return function (comparer, options) { + return function(comparer, options) { if (this._isDestroyed || this._items.length < 2) return this; var items = this._items; @@ -1080,7 +1080,7 @@ Grid.prototype.sort = (function () { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Grid} */ -Grid.prototype.move = function (item, position, options) { +Grid.prototype.move = function(item, position, options) { if (this._isDestroyed || this._items.length < 2) return this; var items = this._items; @@ -1139,7 +1139,7 @@ Grid.prototype.move = function (item, position, options) { * @param {(Boolean|LayoutCallback|String)} [options.layoutReceiver=true] * @returns {Grid} */ -Grid.prototype.send = function (item, grid, position, options) { +Grid.prototype.send = function(item, grid, position, options) { if (this._isDestroyed || grid._isDestroyed || this === grid) return this; // Make sure we have a valid target item. @@ -1184,7 +1184,7 @@ Grid.prototype.send = function (item, grid, position, options) { * @param {Boolean} [removeElements=false] * @returns {Grid} */ -Grid.prototype.destroy = function (removeElements) { +Grid.prototype.destroy = function(removeElements) { if (this._isDestroyed) return this; var container = this._element; @@ -1235,7 +1235,7 @@ Grid.prototype.destroy = function (removeElements) { * @param {GridSingleItemQuery} [target] * @returns {?Item} */ -Grid.prototype._getItem = function (target) { +Grid.prototype._getItem = function(target) { // If no target is specified or the instance is destroyed, return null. if (this._isDestroyed || (!target && target !== 0)) { return null; @@ -1273,7 +1273,7 @@ Grid.prototype._getItem = function (target) { * @memberof Grid.prototype * @returns {LayoutData} */ -Grid.prototype._updateLayout = function () { +Grid.prototype._updateLayout = function() { var layout = this._layout; var settings = this._settings.layout; var width; @@ -1322,7 +1322,7 @@ Grid.prototype._updateLayout = function () { * @param {String} event * @param {...*} [arg] */ -Grid.prototype._emit = function () { +Grid.prototype._emit = function() { if (this._isDestroyed) return; this._emitter.emit.apply(this._emitter, arguments); }; @@ -1335,7 +1335,7 @@ Grid.prototype._emit = function () { * @param {String} event * @returns {Boolean} */ -Grid.prototype._hasListeners = function (event) { +Grid.prototype._hasListeners = function(event) { var listeners = this._emitter._events[event]; return !!(listeners && listeners.length); }; @@ -1346,7 +1346,7 @@ Grid.prototype._hasListeners = function (event) { * @private * @memberof Grid.prototype */ -Grid.prototype._updateBoundingRect = function () { +Grid.prototype._updateBoundingRect = function() { var element = this._element; var rect = element.getBoundingClientRect(); this._width = rect.width; @@ -1365,7 +1365,7 @@ Grid.prototype._updateBoundingRect = function () { * @param {Boolean} top * @param {Boolean} bottom */ -Grid.prototype._updateBorders = function (left, right, top, bottom) { +Grid.prototype._updateBorders = function(left, right, top, bottom) { var element = this._element; if (left) this._borderLeft = getStyleAsFloat(element, 'border-left-width'); if (right) this._borderRight = getStyleAsFloat(element, 'border-right-width'); @@ -1379,7 +1379,7 @@ Grid.prototype._updateBorders = function (left, right, top, bottom) { * @private * @memberof Grid.prototype */ -Grid.prototype._refreshDimensions = function () { +Grid.prototype._refreshDimensions = function() { this._updateBoundingRect(); this._updateBorders(1, 1, 1, 1); }; @@ -1396,7 +1396,7 @@ Grid.prototype._refreshDimensions = function () { * @param {(ShowCallback|HideCallback)} [options.onFinish] * @param {(Boolean|LayoutCallback|String)} [options.layout=true] */ -Grid.prototype._setItemsVisibility = function (items, toVisible, options) { +Grid.prototype._setItemsVisibility = function(items, toVisible, options) { var grid = this; var targetItems = this.getItems(items); var opts = options || 0; @@ -1447,7 +1447,7 @@ Grid.prototype._setItemsVisibility = function (items, toVisible, options) { } // Show/hide the item. - item._visibility[method](isInstant, function (interrupted, item) { + item._visibility[method](isInstant, function(interrupted, item) { // If the current item's animation was not interrupted add it to the // completedItems array. if (!interrupted) completedItems.push(item); From b9246b4d3ea55f176e2aa1dfdc886006048fd470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20R=C3=A4m=C3=B6?= Date: Wed, 31 Jul 2019 08:43:01 +0300 Subject: [PATCH 014/120] wip --- src/Grid/Grid.js | 102 ++++++++++++++++++++++++++++++----------------- 1 file changed, 66 insertions(+), 36 deletions(-) diff --git a/src/Grid/Grid.js b/src/Grid/Grid.js index f2d414f8..e67dc917 100644 --- a/src/Grid/Grid.js +++ b/src/Grid/Grid.js @@ -52,12 +52,30 @@ import removeClass from '../utils/removeClass'; import toArray from '../utils/toArray'; var packer = new Packer(); -var noop = function() {}; +var noop = function () { }; var numberType = 'number'; var stringType = 'string'; var instantLayout = 'instant'; + +function bindLayoutOnResize(grid, value) { + if (typeof value !== numberType) { + value = value === true ? 0 : -1; + } + + if (value >= 0) { + grid._resizeHandler = debounce(function () { + grid.refreshItems().layout(); + }, value); + + window.addEventListener( + 'resize', + grid._resizeHandler + ); + } +} + /** * Creates a new Grid instance. * @@ -173,13 +191,13 @@ function Grid(element, options) { this._items = []; items = settings.items; if (typeof items === stringType) { - toArray(element.children).forEach(function(itemElement) { + toArray(element.children).forEach(function (itemElement) { if (items === '*' || elementMatches(itemElement, items)) { inst._items.push(new Item(inst, itemElement)); } }); } else if (Array.isArray(items) || isNodeList(items)) { - this._items = toArray(items).map(function(itemElement) { + this._items = toArray(items).map(function (itemElement) { return new Item(inst, itemElement); }); } @@ -193,7 +211,7 @@ function Grid(element, options) { if (layoutOnResize >= 0) { window.addEventListener( 'resize', - (inst._resizeHandler = debounce(function() { + (inst._resizeHandler = debounce(function () { inst.refreshItems().layout(); }, layoutOnResize)) ); @@ -373,7 +391,7 @@ Grid.defaultOptions = { * @param {Function} listener * @returns {Grid} */ -Grid.prototype.on = function(event, listener) { +Grid.prototype.on = function (event, listener) { this._emitter.on(event, listener); return this; }; @@ -387,7 +405,7 @@ Grid.prototype.on = function(event, listener) { * @param {Function} listener * @returns {Grid} */ -Grid.prototype.off = function(event, listener) { +Grid.prototype.off = function (event, listener) { this._emitter.off(event, listener); return this; }; @@ -399,7 +417,7 @@ Grid.prototype.off = function(event, listener) { * @memberof Grid.prototype * @returns {HTMLElement} */ -Grid.prototype.getElement = function() { +Grid.prototype.getElement = function () { return this._element; }; @@ -414,7 +432,7 @@ Grid.prototype.getElement = function() { * @param {GridMultiItemQuery} [targets] * @returns {Item[]} */ -Grid.prototype.getItems = function(targets) { +Grid.prototype.getItems = function (targets) { // Return all items immediately if no targets were provided or if the // instance is destroyed. if (this._isDestroyed || (!targets && targets !== 0)) { @@ -443,7 +461,7 @@ Grid.prototype.getItems = function(targets) { * @param {Object} options * @returns {Object} */ -Grid.prototype.updateOptions = function(options) { +Grid.prototype.updateOptions = function (options) { var changedProps = Object.keys(options); var current = this._settings; var merged = mergeSettings(current, options); @@ -482,11 +500,23 @@ Grid.prototype.updateOptions = function(options) { } } - // Refresh sort data if it potentially changed. + // Reset sort data if it potentially changed. if (changedProps.indexOf('sortData') > -1) { - this.refreshSortData(); + for (i = 0; i < items.length; i++) { + items[i]._sortData = null; + } } + // TODO: layoutOnResize + if (changedProps.indexOf('layoutOnResize')) { + // Unbind window resize event listener. + if (this._resizeHandler) { + window.removeEventListener('resize', this._resizeHandler); + } + } + + // TODO: Should we call layout if it potentially changed? + return merged; }; @@ -498,7 +528,7 @@ Grid.prototype.updateOptions = function(options) { * @param {GridMultiItemQuery} [items] * @returns {Grid} */ -Grid.prototype.refreshItems = function(items) { +Grid.prototype.refreshItems = function (items) { if (this._isDestroyed) return this; var targets = this.getItems(items); @@ -519,7 +549,7 @@ Grid.prototype.refreshItems = function(items) { * @param {GridMultiItemQuery} [items] * @returns {Grid} */ -Grid.prototype.refreshSortData = function(items) { +Grid.prototype.refreshSortData = function (items) { if (this._isDestroyed) return this; var targetItems = this.getItems(items); @@ -543,7 +573,7 @@ Grid.prototype.refreshSortData = function(items) { * @memberof Grid.prototype * @returns {Grid} */ -Grid.prototype.synchronize = function() { +Grid.prototype.synchronize = function () { if (this._isDestroyed) return this; var container = this._element; @@ -580,7 +610,7 @@ Grid.prototype.synchronize = function() { * @param {LayoutCallback} [onFinish] * @returns {Grid} */ -Grid.prototype.layout = function(instant, onFinish) { +Grid.prototype.layout = function (instant, onFinish) { if (this._isDestroyed) return this; var inst = this; @@ -693,7 +723,7 @@ Grid.prototype.layout = function(instant, onFinish) { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Item[]} */ -Grid.prototype.add = function(elements, options) { +Grid.prototype.add = function (elements, options) { if (this._isDestroyed || !elements) return []; var newItems = toArray(elements); @@ -749,7 +779,7 @@ Grid.prototype.add = function(elements, options) { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Item[]} */ -Grid.prototype.remove = function(items, options) { +Grid.prototype.remove = function (items, options) { if (this._isDestroyed) return this; var opts = options || 0; @@ -794,7 +824,7 @@ Grid.prototype.remove = function(items, options) { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Grid} */ -Grid.prototype.show = function(items, options) { +Grid.prototype.show = function (items, options) { if (this._isDestroyed) return this; this._setItemsVisibility(items, true, options); return this; @@ -812,7 +842,7 @@ Grid.prototype.show = function(items, options) { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Grid} */ -Grid.prototype.hide = function(items, options) { +Grid.prototype.hide = function (items, options) { if (this._isDestroyed) return this; this._setItemsVisibility(items, false, options); return this; @@ -837,7 +867,7 @@ Grid.prototype.hide = function(items, options) { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Grid} */ -Grid.prototype.filter = function(predicate, options) { +Grid.prototype.filter = function (predicate, options) { if (this._isDestroyed || !this._items.length) return this; var itemsToShow = []; @@ -855,7 +885,7 @@ Grid.prototype.filter = function(predicate, options) { // If we have onFinish callback, let's create proper tryFinish callback. if (onFinish) { - tryFinish = function() { + tryFinish = function () { ++tryFinishCounter && onFinish(itemsToShow.slice(0), itemsToHide.slice(0)); }; } @@ -928,7 +958,7 @@ Grid.prototype.filter = function(predicate, options) { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Grid} */ -Grid.prototype.sort = (function() { +Grid.prototype.sort = (function () { var sortComparer; var isDescending; var origItems; @@ -938,7 +968,7 @@ Grid.prototype.sort = (function() { return data .trim() .split(' ') - .map(function(val) { + .map(function (val) { return val.split(':'); }); } @@ -1008,7 +1038,7 @@ Grid.prototype.sort = (function() { return compareIndices(a, b); } - return function(comparer, options) { + return function (comparer, options) { if (this._isDestroyed || this._items.length < 2) return this; var items = this._items; @@ -1080,7 +1110,7 @@ Grid.prototype.sort = (function() { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Grid} */ -Grid.prototype.move = function(item, position, options) { +Grid.prototype.move = function (item, position, options) { if (this._isDestroyed || this._items.length < 2) return this; var items = this._items; @@ -1139,7 +1169,7 @@ Grid.prototype.move = function(item, position, options) { * @param {(Boolean|LayoutCallback|String)} [options.layoutReceiver=true] * @returns {Grid} */ -Grid.prototype.send = function(item, grid, position, options) { +Grid.prototype.send = function (item, grid, position, options) { if (this._isDestroyed || grid._isDestroyed || this === grid) return this; // Make sure we have a valid target item. @@ -1184,7 +1214,7 @@ Grid.prototype.send = function(item, grid, position, options) { * @param {Boolean} [removeElements=false] * @returns {Grid} */ -Grid.prototype.destroy = function(removeElements) { +Grid.prototype.destroy = function (removeElements) { if (this._isDestroyed) return this; var container = this._element; @@ -1235,7 +1265,7 @@ Grid.prototype.destroy = function(removeElements) { * @param {GridSingleItemQuery} [target] * @returns {?Item} */ -Grid.prototype._getItem = function(target) { +Grid.prototype._getItem = function (target) { // If no target is specified or the instance is destroyed, return null. if (this._isDestroyed || (!target && target !== 0)) { return null; @@ -1273,7 +1303,7 @@ Grid.prototype._getItem = function(target) { * @memberof Grid.prototype * @returns {LayoutData} */ -Grid.prototype._updateLayout = function() { +Grid.prototype._updateLayout = function () { var layout = this._layout; var settings = this._settings.layout; var width; @@ -1322,7 +1352,7 @@ Grid.prototype._updateLayout = function() { * @param {String} event * @param {...*} [arg] */ -Grid.prototype._emit = function() { +Grid.prototype._emit = function () { if (this._isDestroyed) return; this._emitter.emit.apply(this._emitter, arguments); }; @@ -1335,7 +1365,7 @@ Grid.prototype._emit = function() { * @param {String} event * @returns {Boolean} */ -Grid.prototype._hasListeners = function(event) { +Grid.prototype._hasListeners = function (event) { var listeners = this._emitter._events[event]; return !!(listeners && listeners.length); }; @@ -1346,7 +1376,7 @@ Grid.prototype._hasListeners = function(event) { * @private * @memberof Grid.prototype */ -Grid.prototype._updateBoundingRect = function() { +Grid.prototype._updateBoundingRect = function () { var element = this._element; var rect = element.getBoundingClientRect(); this._width = rect.width; @@ -1365,7 +1395,7 @@ Grid.prototype._updateBoundingRect = function() { * @param {Boolean} top * @param {Boolean} bottom */ -Grid.prototype._updateBorders = function(left, right, top, bottom) { +Grid.prototype._updateBorders = function (left, right, top, bottom) { var element = this._element; if (left) this._borderLeft = getStyleAsFloat(element, 'border-left-width'); if (right) this._borderRight = getStyleAsFloat(element, 'border-right-width'); @@ -1379,7 +1409,7 @@ Grid.prototype._updateBorders = function(left, right, top, bottom) { * @private * @memberof Grid.prototype */ -Grid.prototype._refreshDimensions = function() { +Grid.prototype._refreshDimensions = function () { this._updateBoundingRect(); this._updateBorders(1, 1, 1, 1); }; @@ -1396,7 +1426,7 @@ Grid.prototype._refreshDimensions = function() { * @param {(ShowCallback|HideCallback)} [options.onFinish] * @param {(Boolean|LayoutCallback|String)} [options.layout=true] */ -Grid.prototype._setItemsVisibility = function(items, toVisible, options) { +Grid.prototype._setItemsVisibility = function (items, toVisible, options) { var grid = this; var targetItems = this.getItems(items); var opts = options || 0; @@ -1447,7 +1477,7 @@ Grid.prototype._setItemsVisibility = function(items, toVisible, options) { } // Show/hide the item. - item._visibility[method](isInstant, function(interrupted, item) { + item._visibility[method](isInstant, function (interrupted, item) { // If the current item's animation was not interrupted add it to the // completedItems array. if (!interrupted) completedItems.push(item); From 05250a734f8a328f3da551174e433880240afb2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20R=C3=A4m=C3=B6?= Date: Wed, 31 Jul 2019 14:11:21 +0300 Subject: [PATCH 015/120] wip --- src/Grid/Grid.js | 214 +++++++++++++++++++++++++------------------ src/Item/ItemDrag.js | 30 +++--- 2 files changed, 135 insertions(+), 109 deletions(-) diff --git a/src/Grid/Grid.js b/src/Grid/Grid.js index e67dc917..6912c7b9 100644 --- a/src/Grid/Grid.js +++ b/src/Grid/Grid.js @@ -52,30 +52,12 @@ import removeClass from '../utils/removeClass'; import toArray from '../utils/toArray'; var packer = new Packer(); -var noop = function () { }; +var noop = function() {}; var numberType = 'number'; var stringType = 'string'; var instantLayout = 'instant'; - -function bindLayoutOnResize(grid, value) { - if (typeof value !== numberType) { - value = value === true ? 0 : -1; - } - - if (value >= 0) { - grid._resizeHandler = debounce(function () { - grid.refreshItems().layout(); - }, value); - - window.addEventListener( - 'resize', - grid._resizeHandler - ); - } -} - /** * Creates a new Grid instance. * @@ -140,11 +122,14 @@ function Grid(element, options) { var inst = this; var settings; var items; - var layoutOnResize; - // Allow passing element as selector string. Store element for instance. - element = this._element = - typeof element === stringType ? window.document.querySelector(element) : element; + // Allow passing element as selector string + if (typeof element === stringType) { + element = window.document.querySelector(element); + } + + // Store element for instance. + this._element = element; // Throw an error if the container element is not body element or does not // exist within the body element. @@ -191,31 +176,20 @@ function Grid(element, options) { this._items = []; items = settings.items; if (typeof items === stringType) { - toArray(element.children).forEach(function (itemElement) { + toArray(element.children).forEach(function(itemElement) { if (items === '*' || elementMatches(itemElement, items)) { inst._items.push(new Item(inst, itemElement)); } }); } else if (Array.isArray(items) || isNodeList(items)) { - this._items = toArray(items).map(function (itemElement) { + this._items = toArray(items).map(function(itemElement) { return new Item(inst, itemElement); }); } // If layoutOnResize option is a valid number sanitize it and bind the resize // handler. - layoutOnResize = settings.layoutOnResize; - if (typeof layoutOnResize !== numberType) { - layoutOnResize = layoutOnResize === true ? 0 : -1; - } - if (layoutOnResize >= 0) { - window.addEventListener( - 'resize', - (inst._resizeHandler = debounce(function () { - inst.refreshItems().layout(); - }, layoutOnResize)) - ); - } + bindLayoutOnResize(this, settings.layoutOnResize); // Layout on init if necessary. if (settings.layoutOnInit) { @@ -391,7 +365,7 @@ Grid.defaultOptions = { * @param {Function} listener * @returns {Grid} */ -Grid.prototype.on = function (event, listener) { +Grid.prototype.on = function(event, listener) { this._emitter.on(event, listener); return this; }; @@ -405,7 +379,7 @@ Grid.prototype.on = function (event, listener) { * @param {Function} listener * @returns {Grid} */ -Grid.prototype.off = function (event, listener) { +Grid.prototype.off = function(event, listener) { this._emitter.off(event, listener); return this; }; @@ -417,7 +391,7 @@ Grid.prototype.off = function (event, listener) { * @memberof Grid.prototype * @returns {HTMLElement} */ -Grid.prototype.getElement = function () { +Grid.prototype.getElement = function() { return this._element; }; @@ -432,7 +406,7 @@ Grid.prototype.getElement = function () { * @param {GridMultiItemQuery} [targets] * @returns {Item[]} */ -Grid.prototype.getItems = function (targets) { +Grid.prototype.getItems = function(targets) { // Return all items immediately if no targets were provided or if the // instance is destroyed. if (this._isDestroyed || (!targets && targets !== 0)) { @@ -461,18 +435,27 @@ Grid.prototype.getItems = function (targets) { * @param {Object} options * @returns {Object} */ -Grid.prototype.updateOptions = function (options) { +Grid.prototype.updateOptions = function(options) { + var element = this._element; var changedProps = Object.keys(options); - var current = this._settings; - var merged = mergeSettings(current, options); + var oldSettings = this._settings; + var newSettings = mergeSettings(oldSettings, options); var items = this._items; var i, item; - // Step 1: Teardown existing functionality with existing settings (if needed). + // Sanitize `dragSort` setting. + if (!isFunction(newSettings.dragSort)) { + newSettings.dragSort = !!newSettings.dragSort; + } + + // Update settings to the instance. + this._settings = newSettings; - // Disable dragging for items. + // Disable/enable dragging for items. if (changedProps.indexOf('dragEnabled') > -1) { - if (current.dragEnabled && !options.dragEnabled) { + // Disable dragging. + if (oldSettings.dragEnabled && !newSettings.dragEnabled) { + this._settings = oldSettings; for (i = 0; i < items.length; i++) { item = items[i]; if (item._drag) { @@ -480,17 +463,11 @@ Grid.prototype.updateOptions = function (options) { item._drag = null; } } + this._settings = newSettings; } - } - // Step 2: Update settings. - this._settings = merged; - - // Step 3: Instantiate new functionality (if needed). - - // Enable dragging for items. - if (changedProps.indexOf('dragEnabled') > -1) { - if (!current.dragEnabled && options.dragEnabled) { + // Enable dragging. + if (!oldSettings.dragEnabled && newSettings.dragEnabled) { for (i = 0; i < items.length; i++) { item = items[i]; if (!item._drag) { @@ -500,6 +477,26 @@ Grid.prototype.updateOptions = function (options) { } } + // Update drag CSS properties. + if (changedProps.indexOf('dragCssProps') > -1) { + if (oldSettings.dragEnabled && newSettings.dragEnabled) { + for (i = 0; i < items.length; i++) { + item = items[i]; + if (item._drag) { + item._drag._dragger.setCssProps(newSettings.dragCssProps); + } + } + } + } + + // Update container element's class name. + if (changedProps.indexOf('containerClass') > -1) { + if (oldSettings.containerClass !== newSettings.containerClass) { + removeClass(element, oldSettings.containerClass); + addClass(element, newSettings.containerClass); + } + } + // Reset sort data if it potentially changed. if (changedProps.indexOf('sortData') > -1) { for (i = 0; i < items.length; i++) { @@ -507,17 +504,21 @@ Grid.prototype.updateOptions = function (options) { } } - // TODO: layoutOnResize - if (changedProps.indexOf('layoutOnResize')) { - // Unbind window resize event listener. - if (this._resizeHandler) { - window.removeEventListener('resize', this._resizeHandler); - } + // Rebind `layoutOnResize`. + if (changedProps.indexOf('layoutOnResize') > -1) { + unbindLayoutOnResize(this); + bindLayoutOnResize(this, newSettings.layoutOnResize); } + // TODO: How to handle `dragStartPredicate` change? + // TODO: How to handle `dragSortPredicate` change? + // TODO: How to handle `dragSortHeuristics` change? + // TODO: How to handle `dragPlaceholder` change? + // TODO: How to handle item class changes (performantly)? + // TODO: How to handle visible/hidden style changes? // TODO: Should we call layout if it potentially changed? - return merged; + return newSettings; }; /** @@ -528,7 +529,7 @@ Grid.prototype.updateOptions = function (options) { * @param {GridMultiItemQuery} [items] * @returns {Grid} */ -Grid.prototype.refreshItems = function (items) { +Grid.prototype.refreshItems = function(items) { if (this._isDestroyed) return this; var targets = this.getItems(items); @@ -549,7 +550,7 @@ Grid.prototype.refreshItems = function (items) { * @param {GridMultiItemQuery} [items] * @returns {Grid} */ -Grid.prototype.refreshSortData = function (items) { +Grid.prototype.refreshSortData = function(items) { if (this._isDestroyed) return this; var targetItems = this.getItems(items); @@ -573,7 +574,7 @@ Grid.prototype.refreshSortData = function (items) { * @memberof Grid.prototype * @returns {Grid} */ -Grid.prototype.synchronize = function () { +Grid.prototype.synchronize = function() { if (this._isDestroyed) return this; var container = this._element; @@ -610,7 +611,7 @@ Grid.prototype.synchronize = function () { * @param {LayoutCallback} [onFinish] * @returns {Grid} */ -Grid.prototype.layout = function (instant, onFinish) { +Grid.prototype.layout = function(instant, onFinish) { if (this._isDestroyed) return this; var inst = this; @@ -723,7 +724,7 @@ Grid.prototype.layout = function (instant, onFinish) { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Item[]} */ -Grid.prototype.add = function (elements, options) { +Grid.prototype.add = function(elements, options) { if (this._isDestroyed || !elements) return []; var newItems = toArray(elements); @@ -779,7 +780,7 @@ Grid.prototype.add = function (elements, options) { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Item[]} */ -Grid.prototype.remove = function (items, options) { +Grid.prototype.remove = function(items, options) { if (this._isDestroyed) return this; var opts = options || 0; @@ -824,7 +825,7 @@ Grid.prototype.remove = function (items, options) { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Grid} */ -Grid.prototype.show = function (items, options) { +Grid.prototype.show = function(items, options) { if (this._isDestroyed) return this; this._setItemsVisibility(items, true, options); return this; @@ -842,7 +843,7 @@ Grid.prototype.show = function (items, options) { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Grid} */ -Grid.prototype.hide = function (items, options) { +Grid.prototype.hide = function(items, options) { if (this._isDestroyed) return this; this._setItemsVisibility(items, false, options); return this; @@ -867,7 +868,7 @@ Grid.prototype.hide = function (items, options) { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Grid} */ -Grid.prototype.filter = function (predicate, options) { +Grid.prototype.filter = function(predicate, options) { if (this._isDestroyed || !this._items.length) return this; var itemsToShow = []; @@ -885,7 +886,7 @@ Grid.prototype.filter = function (predicate, options) { // If we have onFinish callback, let's create proper tryFinish callback. if (onFinish) { - tryFinish = function () { + tryFinish = function() { ++tryFinishCounter && onFinish(itemsToShow.slice(0), itemsToHide.slice(0)); }; } @@ -958,7 +959,7 @@ Grid.prototype.filter = function (predicate, options) { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Grid} */ -Grid.prototype.sort = (function () { +Grid.prototype.sort = (function() { var sortComparer; var isDescending; var origItems; @@ -968,7 +969,7 @@ Grid.prototype.sort = (function () { return data .trim() .split(' ') - .map(function (val) { + .map(function(val) { return val.split(':'); }); } @@ -1038,7 +1039,7 @@ Grid.prototype.sort = (function () { return compareIndices(a, b); } - return function (comparer, options) { + return function(comparer, options) { if (this._isDestroyed || this._items.length < 2) return this; var items = this._items; @@ -1110,7 +1111,7 @@ Grid.prototype.sort = (function () { * @param {(Boolean|LayoutCallback|String)} [options.layout=true] * @returns {Grid} */ -Grid.prototype.move = function (item, position, options) { +Grid.prototype.move = function(item, position, options) { if (this._isDestroyed || this._items.length < 2) return this; var items = this._items; @@ -1169,7 +1170,7 @@ Grid.prototype.move = function (item, position, options) { * @param {(Boolean|LayoutCallback|String)} [options.layoutReceiver=true] * @returns {Grid} */ -Grid.prototype.send = function (item, grid, position, options) { +Grid.prototype.send = function(item, grid, position, options) { if (this._isDestroyed || grid._isDestroyed || this === grid) return this; // Make sure we have a valid target item. @@ -1214,7 +1215,7 @@ Grid.prototype.send = function (item, grid, position, options) { * @param {Boolean} [removeElements=false] * @returns {Grid} */ -Grid.prototype.destroy = function (removeElements) { +Grid.prototype.destroy = function(removeElements) { if (this._isDestroyed) return this; var container = this._element; @@ -1222,9 +1223,7 @@ Grid.prototype.destroy = function (removeElements) { var i; // Unbind window resize event listener. - if (this._resizeHandler) { - window.removeEventListener('resize', this._resizeHandler); - } + unbindLayoutOnResize(this); // Destroy items. for (i = 0; i < items.length; i++) { @@ -1265,7 +1264,7 @@ Grid.prototype.destroy = function (removeElements) { * @param {GridSingleItemQuery} [target] * @returns {?Item} */ -Grid.prototype._getItem = function (target) { +Grid.prototype._getItem = function(target) { // If no target is specified or the instance is destroyed, return null. if (this._isDestroyed || (!target && target !== 0)) { return null; @@ -1303,7 +1302,7 @@ Grid.prototype._getItem = function (target) { * @memberof Grid.prototype * @returns {LayoutData} */ -Grid.prototype._updateLayout = function () { +Grid.prototype._updateLayout = function() { var layout = this._layout; var settings = this._settings.layout; var width; @@ -1352,7 +1351,7 @@ Grid.prototype._updateLayout = function () { * @param {String} event * @param {...*} [arg] */ -Grid.prototype._emit = function () { +Grid.prototype._emit = function() { if (this._isDestroyed) return; this._emitter.emit.apply(this._emitter, arguments); }; @@ -1365,7 +1364,7 @@ Grid.prototype._emit = function () { * @param {String} event * @returns {Boolean} */ -Grid.prototype._hasListeners = function (event) { +Grid.prototype._hasListeners = function(event) { var listeners = this._emitter._events[event]; return !!(listeners && listeners.length); }; @@ -1376,7 +1375,7 @@ Grid.prototype._hasListeners = function (event) { * @private * @memberof Grid.prototype */ -Grid.prototype._updateBoundingRect = function () { +Grid.prototype._updateBoundingRect = function() { var element = this._element; var rect = element.getBoundingClientRect(); this._width = rect.width; @@ -1395,7 +1394,7 @@ Grid.prototype._updateBoundingRect = function () { * @param {Boolean} top * @param {Boolean} bottom */ -Grid.prototype._updateBorders = function (left, right, top, bottom) { +Grid.prototype._updateBorders = function(left, right, top, bottom) { var element = this._element; if (left) this._borderLeft = getStyleAsFloat(element, 'border-left-width'); if (right) this._borderRight = getStyleAsFloat(element, 'border-right-width'); @@ -1409,7 +1408,7 @@ Grid.prototype._updateBorders = function (left, right, top, bottom) { * @private * @memberof Grid.prototype */ -Grid.prototype._refreshDimensions = function () { +Grid.prototype._refreshDimensions = function() { this._updateBoundingRect(); this._updateBorders(1, 1, 1, 1); }; @@ -1426,7 +1425,7 @@ Grid.prototype._refreshDimensions = function () { * @param {(ShowCallback|HideCallback)} [options.onFinish] * @param {(Boolean|LayoutCallback|String)} [options.layout=true] */ -Grid.prototype._setItemsVisibility = function (items, toVisible, options) { +Grid.prototype._setItemsVisibility = function(items, toVisible, options) { var grid = this; var targetItems = this.getItems(items); var opts = options || 0; @@ -1477,7 +1476,7 @@ Grid.prototype._setItemsVisibility = function (items, toVisible, options) { } // Show/hide the item. - item._visibility[method](isInstant, function (interrupted, item) { + item._visibility[method](isInstant, function(interrupted, item) { // If the current item's animation was not interrupted add it to the // completedItems array. if (!interrupted) completedItems.push(item); @@ -1583,4 +1582,37 @@ function mergeObjects(target, source) { return target; } +/** + * Bind grid's resize handler to window. + * + * @param {Grid} grid + * @param {(Number|Boolean)} delay + */ +function bindLayoutOnResize(grid, delay) { + if (typeof delay !== numberType) { + delay = delay === true ? 0 : -1; + } + + if (delay >= 0) { + grid._resizeHandler = debounce(function() { + grid.refreshItems().layout(); + }, delay); + + window.addEventListener('resize', grid._resizeHandler); + } +} + +/** + * Unbind grid's resize handler from window. + * + * @param {Grid} grid + */ +function unbindLayoutOnResize(grid) { + if (grid._resizeHandler) { + grid._resizeHandler('cancel'); + window.removeEventListener('resize', grid._resizeHandler); + grid._resizeHandler = null; + } +} + export default Grid; diff --git a/src/Item/ItemDrag.js b/src/Item/ItemDrag.js index fcd9f392..13263162 100644 --- a/src/Item/ItemDrag.js +++ b/src/Item/ItemDrag.js @@ -126,7 +126,18 @@ function ItemDrag(item) { */ ItemDrag.defaultStartPredicate = function(item, event, options) { var drag = item._drag; - var predicate = drag._startPredicateData || drag._setupStartPredicate(options); + + // Setup predicate data from options if not already set. + if (!drag._startPredicateData) { + var config = options || drag._getGrid()._settings.dragStartPredicate || {}; + drag._startPredicateData = { + distance: Math.max(config.distance, 0) || 0, + delay: Math.max(config.delay, 0) || 0, + handle: typeof config.handle === 'string' ? config.handle : false + }; + } + + var predicate = drag._startPredicateData; // Final event logic. At this stage return value does not matter anymore, // the predicate is either resolved or it's not and there's nothing to do @@ -522,23 +533,6 @@ ItemDrag.prototype._unbindScrollListeners = function() { scrollers.length = 0; }; -/** - * Setup default start predicate. - * - * @private - * @memberof ItemDrag.prototype - * @param {Object} [options] - * @returns {Object} - */ -ItemDrag.prototype._setupStartPredicate = function(options) { - var config = options || this._getGrid()._settings.dragStartPredicate || 0; - return (this._startPredicateData = { - distance: Math.abs(config.distance) || 0, - delay: Math.max(config.delay, 0) || 0, - handle: typeof config.handle === 'string' ? config.handle : false - }); -}; - /** * Setup default start predicate handle. * From b4e8c3686402bcbc522cd0ab9a8efb8879cb7bec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20R=C3=A4m=C3=B6?= Date: Sat, 3 Aug 2019 12:45:09 +0300 Subject: [PATCH 016/120] Simplify getContainingBlock util. --- dist/muuri.js | 207 ++++++++++++++++++++++++-------- dist/muuri.min.js | 2 +- src/Item/ItemDrag.js | 2 +- src/utils/getContainingBlock.js | 16 +-- src/utils/getOffsetDiff.js | 4 +- 5 files changed, 167 insertions(+), 64 deletions(-) diff --git a/dist/muuri.js b/dist/muuri.js index 5b39730c..bba928c6 100644 --- a/dist/muuri.js +++ b/dist/muuri.js @@ -1517,22 +1517,18 @@ * absolute positioned elements. * * @param {HTMLElement} element - * @param {Boolean} [includeSelf=false] - * - When this is set to true the containing block checking is started from - * the provided element. Otherwise the checking is started from the - * provided element's parent element. * @returns {(Document|Element)} */ - function getContainingBlock(element, includeSelf) { + function getContainingBlock(element) { // As long as the containing block is an element, static and not // transformed, try to get the element's parent element and fallback to // document. https://github.com/niklasramo/mezr/blob/0.6.1/mezr.js#L339 - var document = window.document; - var ret = (includeSelf ? element : element.parentElement) || document; - while (ret && ret !== document && getStyle(ret, 'position') === 'static' && !isTransformed(ret)) { - ret = ret.parentElement || document; + var doc = window.document; + var res = element || doc; + while (res && res !== doc && getStyle(res, 'position') === 'static' && !isTransformed(res)) { + res = res.parentElement || doc; } - return ret; + return res; } /** @@ -1613,8 +1609,8 @@ // Compare containing blocks if necessary. if (compareContainingBlocks) { - elemA = getContainingBlock(elemA, true); - elemB = getContainingBlock(elemB, true); + elemA = getContainingBlock(elemA); + elemB = getContainingBlock(elemB); // If containing blocks are identical, let's return early. if (elemA === elemB) return offsetDiff; @@ -1840,7 +1836,18 @@ */ ItemDrag.defaultStartPredicate = function(item, event, options) { var drag = item._drag; - var predicate = drag._startPredicateData || drag._setupStartPredicate(options); + + // Setup predicate data from options if not already set. + if (!drag._startPredicateData) { + var config = options || drag._getGrid()._settings.dragStartPredicate || {}; + drag._startPredicateData = { + distance: Math.max(config.distance, 0) || 0, + delay: Math.max(config.delay, 0) || 0, + handle: typeof config.handle === 'string' ? config.handle : false + }; + } + + var predicate = drag._startPredicateData; // Final event logic. At this stage return value does not matter anymore, // the predicate is either resolved or it's not and there's nothing to do @@ -2236,23 +2243,6 @@ scrollers.length = 0; }; - /** - * Setup default start predicate. - * - * @private - * @memberof ItemDrag.prototype - * @param {Object} [options] - * @returns {Object} - */ - ItemDrag.prototype._setupStartPredicate = function(options) { - var config = options || this._getGrid()._settings.dragStartPredicate || 0; - return (this._startPredicateData = { - distance: Math.abs(config.distance) || 0, - delay: Math.max(config.delay, 0) || 0, - handle: typeof config.handle === 'string' ? config.handle : false - }); - }; - /** * Setup default start predicate handle. * @@ -2740,7 +2730,7 @@ var migrate = item._migrate; var gridContainer = grid._element; var dragContainer = settings.dragContainer || gridContainer; - var containingBlock = getContainingBlock(dragContainer, true); + var containingBlock = getContainingBlock(dragContainer); var translate = getTranslate(element); var currentLeft = translate.x; var currentTop = translate.y; @@ -5464,11 +5454,14 @@ var inst = this; var settings; var items; - var layoutOnResize; - // Allow passing element as selector string. Store element for instance. - element = this._element = - typeof element === stringType ? window.document.querySelector(element) : element; + // Allow passing element as selector string + if (typeof element === stringType) { + element = window.document.querySelector(element); + } + + // Store element for instance. + this._element = element; // Throw an error if the container element is not body element or does not // exist within the body element. @@ -5528,18 +5521,7 @@ // If layoutOnResize option is a valid number sanitize it and bind the resize // handler. - layoutOnResize = settings.layoutOnResize; - if (typeof layoutOnResize !== numberType$1) { - layoutOnResize = layoutOnResize === true ? 0 : -1; - } - if (layoutOnResize >= 0) { - window.addEventListener( - 'resize', - (inst._resizeHandler = debounce(function() { - inst.refreshItems().layout(); - }, layoutOnResize)) - ); - } + bindLayoutOnResize(this, settings.layoutOnResize); // Layout on init if necessary. if (settings.layoutOnInit) { @@ -5777,6 +5759,100 @@ return ret; }; + /** + * Update grid options. + * + * @public + * @memberof Grid.prototype + * @param {Object} options + * @returns {Object} + */ + Grid.prototype.updateOptions = function(options) { + var element = this._element; + var changedProps = Object.keys(options); + var oldSettings = this._settings; + var newSettings = mergeSettings(oldSettings, options); + var items = this._items; + var i, item; + + // Sanitize `dragSort` setting. + if (!isFunction(newSettings.dragSort)) { + newSettings.dragSort = !!newSettings.dragSort; + } + + // Update settings to the instance. + this._settings = newSettings; + + // Disable/enable dragging for items. + if (changedProps.indexOf('dragEnabled') > -1) { + // Disable dragging. + if (oldSettings.dragEnabled && !newSettings.dragEnabled) { + this._settings = oldSettings; + for (i = 0; i < items.length; i++) { + item = items[i]; + if (item._drag) { + item._drag.destroy(); + item._drag = null; + } + } + this._settings = newSettings; + } + + // Enable dragging. + if (!oldSettings.dragEnabled && newSettings.dragEnabled) { + for (i = 0; i < items.length; i++) { + item = items[i]; + if (!item._drag) { + item._drag = new ItemDrag(item); + } + } + } + } + + // Update drag CSS properties. + if (changedProps.indexOf('dragCssProps') > -1) { + if (oldSettings.dragEnabled && newSettings.dragEnabled) { + for (i = 0; i < items.length; i++) { + item = items[i]; + if (item._drag) { + item._drag._dragger.setCssProps(newSettings.dragCssProps); + } + } + } + } + + // Update container element's class name. + if (changedProps.indexOf('containerClass') > -1) { + if (oldSettings.containerClass !== newSettings.containerClass) { + removeClass(element, oldSettings.containerClass); + addClass(element, newSettings.containerClass); + } + } + + // Reset sort data if it potentially changed. + if (changedProps.indexOf('sortData') > -1) { + for (i = 0; i < items.length; i++) { + items[i]._sortData = null; + } + } + + // Rebind `layoutOnResize`. + if (changedProps.indexOf('layoutOnResize') > -1) { + unbindLayoutOnResize(this); + bindLayoutOnResize(this, newSettings.layoutOnResize); + } + + // TODO: How to handle `dragStartPredicate` change? + // TODO: How to handle `dragSortPredicate` change? + // TODO: How to handle `dragSortHeuristics` change? + // TODO: How to handle `dragPlaceholder` change? + // TODO: How to handle item class changes (performantly)? + // TODO: How to handle visible/hidden style changes? + // TODO: Should we call layout if it potentially changed? + + return newSettings; + }; + /** * Update the cached dimensions of the instance's items. * @@ -6479,9 +6555,7 @@ var i; // Unbind window resize event listener. - if (this._resizeHandler) { - window.removeEventListener('resize', this._resizeHandler); - } + unbindLayoutOnResize(this); // Destroy items. for (i = 0; i < items.length; i++) { @@ -6840,6 +6914,39 @@ return target; } + /** + * Bind grid's resize handler to window. + * + * @param {Grid} grid + * @param {(Number|Boolean)} delay + */ + function bindLayoutOnResize(grid, delay) { + if (typeof delay !== numberType$1) { + delay = delay === true ? 0 : -1; + } + + if (delay >= 0) { + grid._resizeHandler = debounce(function() { + grid.refreshItems().layout(); + }, delay); + + window.addEventListener('resize', grid._resizeHandler); + } + } + + /** + * Unbind grid's resize handler from window. + * + * @param {Grid} grid + */ + function unbindLayoutOnResize(grid) { + if (grid._resizeHandler) { + grid._resizeHandler('cancel'); + window.removeEventListener('resize', grid._resizeHandler); + grid._resizeHandler = null; + } + } + return Grid; })); diff --git a/dist/muuri.min.js b/dist/muuri.min.js index c7a0735b..bb653b66 100644 --- a/dist/muuri.min.js +++ b/dist/muuri.min.js @@ -14,4 +14,4 @@ * Copyright (c) 2018-present, Niklas Rämö * @license MIT */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Muuri=e()}(this,function(){"use strict";var t={},e="layoutEnd";function i(){this._events={},this._queue=[],this._counter=0,this._isDestroyed=!1}i.prototype.on=function(t,e){if(this._isDestroyed)return this;var i=this._events[t];return i||(i=this._events[t]=[]),i.push(e),this},i.prototype.off=function(t,e){if(this._isDestroyed)return this;var i=this._events[t];if(!i||!i.length)return this;if(!e)return i.length=0,this;for(var s=i.length;s--;)e===i[s]&&i.splice(s,1);return this},i.prototype.emit=function(t,e,i,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-1||(M._activeInstances.push(t),M._emitter.on(D,t._onMove),M._emitter.on(A,t._onCancel),M._emitter.on(b,t._onEnd),1===M._activeInstances.length&&M._bindListeners())},M._deactivateInstance=function(t){var e=M._activeInstances.indexOf(t);-1!==e&&(M._activeInstances.splice(e,1),M._emitter.off(D,t._onMove),M._emitter.off(A,t._onCancel),M._emitter.off(b,t._onEnd),M._activeInstances.length||M._unbindListeners())},M._bindListeners=function(){var t=M._events;window.addEventListener(t.move,M._onMove,x),window.addEventListener(t.end,M._onEnd,x),t.cancel&&window.addEventListener(t.cancel,M._onCancel,x)},M._unbindListeners=function(){var t=M._events;window.removeEventListener(t.move,M._onMove,x),window.removeEventListener(t.end,M._onEnd,x),t.cancel&&window.removeEventListener(t.cancel,M._onCancel,x)},M._getEventPointerId=function(t){return"number"==typeof t.pointerId?t.pointerId:t.changedTouches?t.changedTouches[0]?t.changedTouches[0].identifier:null:1},M._getTouchById=function(t,e){if("number"==typeof t.pointerId)return t.pointerId===e?t:null;if(t.changedTouches){for(var i=0;i-1&&(this._queue[n]=void 0),s?this._queue.unshift(t):this._queue.push(t),this._reads[t]=e,this._writes[t]=i,this._nextStep||(this._nextStep=y(this._step))},T.prototype.cancel=function(t){var e=this._queue.indexOf(t);e>-1&&(this._queue[e]=void 0,delete this._reads[t],delete this._writes[t])},T.prototype._step=function(){var t,e,i=this._queue,s=this._reads,n=this._writes,r=this._batch,o=this._batchReads,h=this._batchWrites,a=i.length;for(this._nextStep=null,e=0;en?n:e<0?Math.max(n+e+1,0):e}function K(t,e,i){if(!(t.length<2)){var s=J(t,e),n=J(t,i);s!==n&&t.splice(n,0,t.splice(s,1)[0])}}function Q(t,e,i){if(!(t.length<2)){var s,n=J(t,e),r=J(t,i);n!==r&&(s=t[n],t[n]=t[r],t[r]=s)}}var tt="cancel",et="finish",it="debounce",st=0;function nt(t,e){var i,s=++st+it;return e>0?function(n){void 0!==i&&(i=window.clearTimeout(i),k.cancel(s),n===et&&t()),n!==tt&&n!==et&&(i=window.setTimeout(function(){i=void 0,k.add(s,t,null,!0)},e))}:function(e){e!==tt&&t()}}function rt(t){var e=a(t,"transform");if(!e||"none"===e)return!1;var i=a(t,"display");return"inline"!==i&&"none"!==i}function ot(t,e){for(var i=window.document,s=(e?t:t.parentElement)||i;s&&s!==i&&"static"===a(s,"position")&&!rt(s);)s=s.parentElement||i;return s}function ht(t,e){return parseFloat(a(t,e))||0}var at={},_t={},lt={};function dt(t,e){var i,s=e||{};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:(i=t.getBoundingClientRect(),s.left+=i.left,s.top+=i.top,s.left+=ht(t,"border-left-width"),s.top+=ht(t,"border-top-width"),s))}function ct(t,e,i){return lt.left=0,lt.top=0,t===e?lt:i&&(t=ot(t,!0))===(e=ot(e,!0))?lt:(dt(t,at),dt(e,_t),lt.left=_t.left-at.left,lt.top=_t.top-at.top,lt)}var ut="overflow",ft="overflow-x",pt="overflow-y",mt="auto",gt="scroll";function yt(t){var e=a(t,ut);return e===mt||e===gt||((e=a(t,ft))===mt||e===gt||((e=a(t,pt))===mt||e===gt))}function vt(t,e,i){for(var s=i||[],n=e?t:t.parentNode;n&&n!==document;)n.getRootNode&&n instanceof DocumentFragment?n=n.getRootNode().host:(yt(n)&&s.push(n),n=n.parentNode);return s.push(window),s}var wt={},St="transform",Dt="none",bt=/^matrix3d/,At=/([^,]*,){4}/,Et=/([^,]*,){12}/,Ct=/[^,]*,/;function Lt(t){wt.x=0,wt.y=0;var e=a(t,St);if(!e||e===Dt)return wt;var i=bt.test(e),s=e.replace(i?Et:At,""),n=s.replace(Ct,"");return wt.x=parseFloat(s)||0,wt.y=parseFloat(n)||0,wt}function It(t,e){return"translateX("+t+"px) translateY("+e+"px)"}function xt(t,e){t.classList?t.classList.remove(e):W(t,"."+e)&&(t.className=(" "+t.className+" ").replace(" "+e+" "," ").trim())}var Rt,Pt,Mt,Tt,kt=0;function Xt(t){var e=t._element,i=t.getGrid(),s=i._settings;this._item=t,this._gridId=i._id,this._isDestroyed=!1,this._isMigrating=!1,this._startPredicate=c(s.dragStartPredicate)?s.dragStartPredicate:Xt.defaultStartPredicate,this._startPredicateState=kt,this._startPredicateResult=void 0,this._hBlockedIndex=null,this._hX1=0,this._hX2=0,this._hY1=0,this._hY2=0,this._reset(),this._preStartCheck=this._preStartCheck.bind(this),this._preEndCheck=this._preEndCheck.bind(this),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);var n=s.dragSortHeuristics.sortInterval;this._checkOverlapDebounce=nt(this._checkOverlap,n),this._dragger=new M(e,s.dragCssProps),this._dragger.on("start",this._preStartCheck),this._dragger.on("move",this._preStartCheck),this._dragger.on("cancel",this._preEndCheck),this._dragger.on("end",this._preEndCheck)}function Yt(t,e){return t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top?0:(Math.min(t.left+t.width,e.left+e.width)-Math.max(t.left,e.left))*(Math.min(t.top+t.height,e.top+e.height)-Math.max(t.top,e.top))/(Math.min(t.width,e.width)*Math.min(t.height,e.height))*100}function Gt(t){this._item=t,this._animate=new p,this._element=null,this._className="",this._didMigrate=!1,this._resetAfterLayout=!1,this._currentLeft=0,this._currentTop=0,this._nextLeft=0,this._nextTop=0,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this),this._onLayoutStart=this._onLayoutStart.bind(this),this._onLayoutEnd=this._onLayoutEnd.bind(this),this._onReleaseEnd=this._onReleaseEnd.bind(this),this._onMigrate=this._onMigrate.bind(this)}function Ht(){this._queue=[],this._isDestroyed=!1}function Ot(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 Ht,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this)}Xt.defaultStartPredicate=function(t,e,i){var s=t._drag,n=s._startPredicateData||s._setupStartPredicate(i);if(!e.isFinal)return!(!n.handleElement&&(n.handleElement=s._getStartPredicateHandle(e),!n.handleElement))&&(n.delay&&(n.event=e,n.delayTimer||(n.delayTimer=window.setTimeout(function(){n.delay=0,s._resolveStartPredicate(n.event)&&(s._forceResolveStartPredicate(n.event),s._resetStartPredicate())},n.delay))),s._resolveStartPredicate(e));s._finishStartPredicate(e)},Xt.defaultSortPredicate=(Rt={},Pt={},Mt={},Tt=[],function(t,e){var i=t._drag,s=i._getGrid(),n=e&&"number"==typeof e.threshold?e.threshold:50,r=e&&"swap"===e.action?"swap":"move",o=e&&"swap"===e.migrateAction?"swap":"move";n=Math.min(Math.max(n,1),100),Rt.width=t._width,Rt.height=t._height,Rt.left=i._elementClientX,Rt.top=i._elementClientY;var h=function(t,e,i){var s,n,r,o,h=null,a=e._settings.dragSort,_=-1;if(!0===a?(Tt[0]=e,n=Tt):c(a)&&(n=a.call(e,t)),!n||!Array.isArray(n)||!n.length)return h;for(o=0;oi&&s>_&&(_=s,h=r));return Tt.length=0,h}(t,s,n);if(!h)return!1;var a,_,l,d=t.getGrid()!==h,u=0,f=0,p=0,m=-1,g=!1;for(h===s?(Rt.left=i._gridX+t._marginLeft,Rt.top=i._gridY+t._marginTop):(h._updateBorders(1,0,1,0),u=h._left+h._borderLeft,f=h._top+h._borderTop),l=0;lp&&(m=l,p=_));return d&&p=n&&(Mt.grid=h,Mt.index=m,Mt.action=d?o:r,Mt)}),Xt.prototype.stop=function(){var t=this._item,e=t._element,i=this._getGrid();return this._isActive?this._isMigrating?(this._finishMigration(),this):(N(t._id),q(t._id),this._unbindScrollListeners(),this._checkOverlapDebounce("cancel"),e.parentNode!==i._element&&(i._element.appendChild(e),e.style[n]=It(this._gridX,this._gridY)),xt(e,i._settings.itemDraggingClass),this._reset(),this):this},Xt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(),this._dragger.destroy(),this._isDestroyed=!0,this)},Xt.prototype._getGrid=function(){return t[this._gridId]||null},Xt.prototype._reset=function(){this._isActive=!1,this._container=null,this._containingBlock=null,this._dragEvent=null,this._scrollEvent=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},Xt.prototype._bindScrollListeners=function(){var t,e,i=this._getGrid()._element,s=this._container,n=this._scrollers;if(n.length=0,vt(this._item._element,!1,n),s!==i)for(vt(i,!0,t=[]),e=0;e=s&&t.pageX=n&&t.pageY3&&e.minBounceBackAngle>0;if(h||(this._hBlockedIndex=null),Math.abs(r)>i||Math.abs(o)>i){if(h){var a=Math.atan2(r,o),_=Math.atan2(this._hX2-this._hX1,this._hY2-this._hY1),l=Math.atan2(Math.sin(a-_),Math.cos(a-_));Math.abs(l)>e.minBounceBackAngle&&(this._hBlockedIndex=null)}return this._hX1=this._hX2,this._hY1=this._hY2,this._hX2=s,this._hY2=n,!0}return!1},Xt.prototype._resetStartPredicate=function(){var t=this._startPredicateData;t&&(t.delayTimer&&(t.delayTimer=window.clearTimeout(t.delayTimer)),this._startPredicateData=null)},Xt.prototype._checkOverlap=function(){if(this._isActive){var t,e,i,s,n,r,o,h,a=this._item,_=this._getGrid()._settings;(t=c(_.dragSortPredicate)?_.dragSortPredicate(a,this._dragEvent):Xt.defaultSortPredicate(a,_.dragSortPredicate))&&"number"==typeof t.index&&(h=(e=a.getGrid())!==(s=t.grid||e),i=e._items.indexOf(a),n=J(s._items,t.index,h),o="swap"===t.action?"swap":"move",(h||n!==this._hBlockedIndex)&&(h?(this._hBlockedIndex=null,r=s._items[n],e._hasListeners("beforeSend")&&e._emit("beforeSend",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("beforeReceive")&&s._emit("beforeReceive",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),a._gridId=s._id,this._isMigrating=a._gridId!==this._gridId,e._items.splice(i,1),$(s._items,a,n),a._sortData=null,e._hasListeners("send")&&e._emit("send",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("receive")&&s._emit("receive",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),"swap"===o&&r&&r.isActive()&&s._items.indexOf(r)>-1&&s.send(r,e,i,{appendTo:this._container||window.document.body,layoutSender:!1,layoutReceiver:!1}),e.layout(),s.layout()):i!==n&&(this._hBlockedIndex=i,("swap"===o?Q:K)(e._items,i,n),e._hasListeners("move")&&e._emit("move",{item:a,fromIndex:i,toIndex:n,action:o}),e.layout())))}},Xt.prototype._finishMigration=function(){var t,e,i=this._item,s=i._release,r=i._element,o=i._isActive,h=i.getGrid(),a=h._element,_=h._settings,l=_.dragContainer||a,d=this._getGrid()._settings,c=r.parentNode;this._isMigrating=!1,this.destroy(),xt(r,d.itemClass),xt(r,d.itemVisibleClass),xt(r,d.itemHiddenClass),j(r,_.itemClass),j(r,o?_.itemVisibleClass:_.itemHiddenClass),l!==c&&(l.appendChild(r),e=ct(c,l,!0),(t=Lt(r)).x-=e.left,t.y-=e.top),i._refreshDimensions(),i._refreshSortData(),e=ct(l,a,!0),s._containerDiffX=e.left,s._containerDiffY=e.top,i._drag=_.dragEnabled?new Xt(i):null,l!==c&&(r.style[n]=It(t.x,t.y)),i._child.removeAttribute("style"),f(i._child,o?_.visibleStyles:_.hiddenStyles),s.start()},Xt.prototype._preStartCheck=function(t){this._startPredicateState===kt&&(this._startPredicateState=1),1===this._startPredicateState?(this._startPredicateResult=this._startPredicate(this._item,t),!0===this._startPredicateResult?(this._startPredicateState=2,this._onStart(t)):!1===this._startPredicateResult&&(this._startPredicateState=3)):2===this._startPredicateState&&this._isActive&&this._onMove(t)},Xt.prototype._preEndCheck=function(t){var e=2===this._startPredicateState;this._startPredicate(this._item,t),this._startPredicateState=kt,e&&this._isActive&&this._onEnd(t)},Xt.prototype._onStart=function(t){var e=this._item;if(e._isActive){var i,s=e._element,r=this._getGrid(),o=r._settings,h=e._release,a=e._migrate,_=r._element,l=o.dragContainer||_,d=ot(l,!0),c=Lt(s),u=c.x,f=c.y,p=s.getBoundingClientRect(),m=l!==_;this._resetHeuristics(t),m&&(i=ct(d,_)),e.isPositioning()&&e._layout.stop(!0,{transform:It(u,f)}),a._isActive&&(u-=a._containerDiffX,f-=a._containerDiffY,a.stop(!0,{transform:It(u,f)})),e.isReleasing()&&h._reset(),this._isActive=!0,this._dragEvent=t,this._container=l,this._containingBlock=d,this._elementClientX=p.left,this._elementClientY=p.top,this._left=this._gridX=u,this._top=this._gridY=f,o.dragPlaceholder.enabled&&e._dragPlaceholder.create(),r._emit("dragInit",e,t),m&&(this._containerDiffX=i.left,this._containerDiffY=i.top,s.parentNode===l?(this._gridX=u-this._containerDiffX,this._gridY=f-this._containerDiffY):(this._left=u+this._containerDiffX,this._top=f+this._containerDiffY,l.appendChild(s),s.style[n]=It(this._left,this._top))),j(s,o.itemDraggingClass),this._bindScrollListeners(),r._emit("dragStart",e,t)}},Xt.prototype._onMove=function(t){var e=this._item;if(e._isActive){var i,s,n,r=this._getGrid()._settings.dragAxis;if("y"!==r){var o=t.clientX-this._dragEvent.clientX;this._left+=o,this._gridX+=o,this._elementClientX+=o}if("x"!==r){var h=t.clientY-this._dragEvent.clientY;this._top+=h,this._gridY+=h,this._elementClientY+=h}this._dragEvent=t,i=e._id,s=this._prepareMove,n=this._applyMove,k.add(i+G,s,n,!0)}else this.stop()},Xt.prototype._prepareMove=function(){this._item._isActive&&this._getGrid()._settings.dragSort&&this._checkHeuristics(this._dragEvent)&&this._checkOverlapDebounce()},Xt.prototype._applyMove=function(){var t=this._item;t._isActive&&(t._element.style[n]=It(this._left,this._top),this._getGrid()._emit("dragMove",t,this._dragEvent))},Xt.prototype._onScroll=function(t){var e,i,s,n=this._item;n._isActive?(this._scrollEvent=t,e=n._id,i=this._prepareScroll,s=this._applyScroll,k.add(e+H,i,s,!0)):this.stop()},Xt.prototype._prepareScroll=function(){var t=this._item;if(t._isActive){var e,i=t._element,s=this._getGrid(),n=s._settings,r=n.dragAxis,o=s._element,h=i.getBoundingClientRect(),a=this._elementClientX-h.left,_=this._elementClientY-h.top;this._container!==o&&(e=ct(this._containingBlock,o),this._containerDiffX=e.left,this._containerDiffY=e.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()}},Xt.prototype._applyScroll=function(){var t=this._item;t._isActive&&(t._element.style[n]=It(this._left,this._top),this._getGrid()._emit("dragScroll",t,this._scrollEvent))},Xt.prototype._onEnd=function(t){var e=this._item,i=e._element,s=this._getGrid(),n=s._settings,r=e._release;e._isActive?(N(e._id),q(e._id),n.dragSort&&this._checkOverlapDebounce("finish"),this._unbindScrollListeners(),r._containerDiffX=this._containerDiffX,r._containerDiffY=this._containerDiffY,this._reset(),xt(i,n.itemDraggingClass),s._emit("dragEnd",e,t),this._isMigrating?this._finishMigration():r.start()):this.stop()},Gt.prototype._onLayoutStart=function(){var t=this._item,e=t.getGrid(),i=e._items.indexOf(t),s=e._layout.slots[2*i],n=e._layout.slots[2*i+1];if(this._didMigrate||t._left!==s||t._top!==n){var r,o,h;if(s+=t._marginLeft,n+=t._marginTop,!(e._settings.dragPlaceholder.duration>0)||this._didMigrate){F(t._id);var a={transform:It(s,n)};return this._animate.isAnimating()?this._animate.stop(a):f(this._element,a),void(this._didMigrate&&(e.getElement().appendChild(this._element),this._didMigrate=!1))}this._nextLeft=s,this._nextTop=n,r=t._id,o=this._setupAnimation,h=this._startAnimation,k.add(r+O,o,h)}},Gt.prototype._setupAnimation=function(){if(this.isActive()){var t=Lt(this._element);this._currentLeft=t.x,this._currentTop=t.y}},Gt.prototype._startAnimation=function(){if(this.isActive()){var t=this._animate,e=this._currentLeft,i=this._currentTop,s=this._nextLeft,n=this._nextTop,r={transform:It(s,n)};if(e!==s||i!==n){var o=this._item.getGrid()._settings.dragPlaceholder,h={transform:It(e,i)};t.start(h,r,{duration:o.duration,easing:o.easing,onFinish:this._onLayoutEnd})}else t.isAnimating()&&t.stop(r)}},Gt.prototype._onLayoutEnd=function(){this._resetAfterLayout&&this.reset()},Gt.prototype._onReleaseEnd=function(t){if(t._id===this._item._id){if(!this._animate.isAnimating())return void this.reset();this._resetAfterLayout=!0}},Gt.prototype._onMigrate=function(t){if(t.item===this._item){var e=this._item.getGrid(),i=t.toGrid;e.off("dragReleaseEnd",this._onReleaseEnd),e.off("layoutStart",this._onLayoutStart),e.off("beforeSend",this._onMigrate),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("layoutStart",this._onLayoutStart),i.on("beforeSend",this._onMigrate),this._didMigrate=!0}},Gt.prototype.create=function(){if(this.isActive())this._resetAfterLayout=!1;else{var t,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;t=c(s.dragPlaceholder.createElement)?s.dragPlaceholder.createElement(e):window.document.createElement("div"),this._element=t,n._element=t,this._className=s.itemPlaceholderClass||"",this._className&&j(t,this._className);var r=e._left+e._marginLeft,o=e._top+e._marginTop;f(t,{display:"block",position:"absolute",left:"0",top:"0",width:e._width+"px",height:e._height+"px",transform:It(r,o)}),i.on("layoutStart",this._onLayoutStart),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("beforeSend",this._onMigrate),c(s.dragPlaceholder.onCreate)&&s.dragPlaceholder.onCreate(e,t),i.getElement().appendChild(t)}},Gt.prototype.reset=function(){if(this.isActive()){var t=this._element,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;this._resetAfterLayout=!1,F(e._id),n.stop(),n._element=null,i.off("dragReleaseEnd",this._onReleaseEnd),i.off("layoutStart",this._onLayoutStart),i.off("beforeSend",this._onMigrate),this._className&&(xt(t,this._className),this._className=""),t.parentNode.removeChild(t),this._element=null,c(s.dragPlaceholder.onRemove)&&s.dragPlaceholder.onRemove(e,t)}},Gt.prototype.updateDimensions=function(t,e){this.isActive()&&f(this._element,{width:t+"px",height:e+"px"})},Gt.prototype.isActive=function(){return!!this._element},Gt.prototype.destroy=function(){this.reset(),this._animate.destroy(),this._item=this._animate=null},Ht.prototype.add=function(t){return this._isDestroyed?this:(this._queue.push(t),this)},Ht.prototype.flush=function(t,e){if(this._isDestroyed)return this;var i,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,e),this;for(i=0;i0;return l&&this._queue.flush(!0,o),d&&(a._isPositioningStarted=!0),c(e)&&this._queue.add(e),m?(this._isActive=!0,this._animateOptions.easing=p,this._animateOptions.duration=u,this._isInterrupted=l,s=o._id,n=this._setupAnimation,r=this._startAnimation,k.add(s+X,n,r),this):(this._updateOffsets(),this._updateTargetStyles(),i=o._animate.isAnimating(),this.stop(!1,this._targetStyles),!i&&f(h,this._targetStyles),this._skipNextAnimation=!1,this._finish())}},Ot.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item;return i=s._id,k.cancel(i+X),s._animate.stop(e),xt(s._element,s.getGrid()._settings.itemPositioningClass),this._isActive=!1,t&&this._queue.flush(!0,s),this},Ot.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)},Ot.prototype._updateOffsets=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._offsetLeft=i._isActive?i._containerDiffX:e._isActive?e._containerDiffX:0,this._offsetTop=i._isActive?i._containerDiffY:e._isActive?e._containerDiffY:0}},Ot.prototype._updateTargetStyles=function(){this._isDestroyed||(this._targetStyles.transform=It(this._item._left+this._offsetLeft,this._item._top+this._offsetTop))},Ot.prototype._finish=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._isActive&&(this._isActive=!1,xt(t._element,t.getGrid()._settings.itemPositioningClass)),i._isActive&&i.stop(),e._isActive&&e.stop(),this._queue.flush(!1,t)}},Ot.prototype._setupAnimation=function(){var t=Lt(this._item._element);this._currentLeft=t.x,this._currentTop=t.y},Ot.prototype._startAnimation=function(){var t=this._item,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||j(t._element,e.itemPositioningClass),this._currentStyles.transform=It(this._currentLeft,this._currentTop),t._animate.start(this._currentStyles,this._targetStyles,this._animateOptions)};var Bt={};function Nt(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._container=!1,this._containerDiffX=0,this._containerDiffY=0}Nt.prototype.start=function(t,e,i){if(this._isDestroyed)return this;var s,r,o,h,a,_,l,d,c=this._item,u=c._element,p=c.isVisible(),m=c.getGrid(),g=m._settings,y=t._settings,v=t._element,w=t._items,S=m._items.indexOf(c),D=i||window.document.body;if("number"==typeof e)s=J(w,e,!0);else{if(!(r=t._getItem(e)))return this;s=w.indexOf(r)}return(c.isPositioning()||this._isActive||c.isReleasing())&&(l=(_=Lt(u)).x,d=_.y),c.isPositioning()&&c._layout.stop(!0,{transform:It(l,d)}),this._isActive&&(l-=this._containerDiffX,d-=this._containerDiffY,this.stop(!0,{transform:It(l,d)})),c.isReleasing()&&(l-=c._release._containerDiffX,d-=c._release._containerDiffY,c._release.stop(!0,{transform:It(l,d)})),c._visibility._stopAnimation(),c._drag&&c._drag.destroy(),c._visibility._queue.flush(!0,c),m._hasListeners("beforeSend")&&m._emit("beforeSend",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("beforeReceive")&&t._emit("beforeReceive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),xt(u,g.itemClass),xt(u,g.itemVisibleClass),xt(u,g.itemHiddenClass),j(u,y.itemClass),j(u,p?y.itemVisibleClass:y.itemHiddenClass),m._items.splice(S,1),$(w,c,s),c._gridId=t._id,D!==(o=u.parentNode)&&(D.appendChild(u),h=ct(D,o,!0),_||(l=(_=Lt(u)).x,d=_.y),u.style[n]=It(l+h.left,d+h.top)),c._child.removeAttribute("style"),f(c._child,p?y.visibleStyles:y.hiddenStyles),u.style.display=p?"block":"hidden",a=ct(D,v,!0),c._refreshDimensions(),c._refreshSortData(),c._drag=y.dragEnabled?new Xt(c):null,this._isActive=!0,this._container=D,this._containerDiffX=a.left,this._containerDiffY=a.top,m._hasListeners("send")&&m._emit("send",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("receive")&&t._emit("receive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),this},Nt.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid()._element;return this._container!==r&&(e||(t?(i=Lt(n),Bt.transform=It(i.x-this._containerDiffX,i.y-this._containerDiffY)):Bt.transform=It(s._left,s._top),e=Bt),r.appendChild(n),f(n,e)),this._isActive=!1,this._container=null,this._containerDiffX=0,this._containerDiffY=0,this},Nt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)};var qt={};function Ft(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0}function zt(t){var e=t._isActive,i=t._element,s=t.getGrid()._settings;this._item=t,this._isDestroyed=!1,this._isHidden=!e,this._isHiding=!1,this._isShowing=!1,this._queue=new Ht,this._finishShow=this._finishShow.bind(this),this._finishHide=this._finishHide.bind(this),i.style.display=e?"block":"none",j(i,e?s.itemVisibleClass:s.itemHiddenClass),f(t._child,e?s.visibleStyles:s.hiddenStyles)}Ft.prototype.start=function(){if(this._isDestroyed||this._isActive)return this;var t=this._item,e=t.getGrid();return this._isActive=!0,j(t._element,e._settings.itemReleasingClass),e._emit("dragReleaseStart",t),t._layout.start(!1),this},Ft.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid(),o=r._element;return this._reset(),n.parentNode!==o&&(e||(t?(i=Lt(n),qt.transform=It(i.x-this._containerDiffX,i.y-this._containerDiffY)):qt.transform=It(s._left,s._top),e=qt),o.appendChild(n),f(n,e)),t||r._emit("dragReleaseEnd",s),this},Ft.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)},Ft.prototype._reset=function(){if(!this._isDestroyed){var t=this._item;this._isActive=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0,xt(t._element,t.getGrid()._settings.itemReleasingClass)}},zt.prototype.show=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return this._isShowing||this._isHidden?this._isShowing&&!t?(r&&n.add(r),this):(this._isShowing||(n.flush(!0,i),xt(s,o.itemHiddenClass),j(s,o.itemVisibleClass),this._isHiding||(s.style.display="block")),r&&n.add(r),i._isActive=this._isShowing=!0,this._isHiding=this._isHidden=!1,this._startAnimation(!0,t,this._finishShow),this):(r&&r(!1,i),this)},zt.prototype.hide=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return!this._isHiding&&this._isHidden?(r&&r(!1,i),this):this._isHiding&&!t?(r&&n.add(r),this):(this._isHiding||(n.flush(!0,i),j(s,o.itemHiddenClass),xt(s,o.itemVisibleClass)),r&&n.add(r),this._isHidden=this._isHiding=!0,i._isActive=this._isShowing=!1,this._startAnimation(!1,t,this._finishHide),this)},zt.prototype.destroy=function(){if(this._isDestroyed)return this;var t=this._item,e=t._element,i=t.getGrid(),s=this._queue,n=i._settings;return this._stopAnimation({}),s.flush(!0,t).destroy(),xt(e,n.itemVisibleClass),xt(e,n.itemHiddenClass),this._item=null,this._isHiding=this._isShowing=!1,this._isDestroyed=this._isHidden=!0,this},zt.prototype._startAnimation=function(t,e,i){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,_=(t?r.showEasing:r.hideEasing)||"ease",d=e||h<=0;if(o){if(B(n._id),d)return n._animateChild.isAnimating()?n._animateChild.stop(o):f(n._child,o),void(i&&i());var c,u,p;c=n._id,u=function(){s=function(t,e){var i={};for(var s in e)i[s]=a(t,l(s));return i}(n._child,o)},p=function(){n._animateChild.start(s,o,{duration:h,easing:_,onFinish:i})},k.add(c+Y,u,p)}else i&&i()}},zt.prototype._stopAnimation=function(t){if(!this._isDestroyed){var e=this._item;B(e._id),e._animateChild.stop(t)}},zt.prototype._finishShow=function(){this._isHidden||(this._isShowing=!1,this._queue.flush(!1,this._item))};var Vt={};zt.prototype._finishHide=function(){if(this._isHidden){var t=this._item;this._isHiding=!1,Vt.transform=It(0,0),t._layout.stop(!0,Vt),t._element.style.display="none",this._queue.flush(!1,t)}};var Wt,jt,Ut,Zt,$t=0;function Jt(){return++$t}function Kt(t,e,i){var s=t._settings;this._id=Jt(),this._gridId=t._id,this._isDestroyed=!1,this._left=0,this._top=0,this._element=e,this._child=e.children[0],e.parentNode!==t._element&&t._element.appendChild(e),j(e,s.itemClass),"boolean"!=typeof i&&(i="none"!==a(e,"display")),this._isActive=i,e.style.left="0",e.style.top="0",e.style[n]=It(0,0),this._animate=new p(e),this._animateChild=new p(this._child),this._visibility=new zt(this),this._layout=new Ot(this),this._migrate=new Nt(this),this._release=new Ft(this),this._dragPlaceholder=new Gt(this),this._drag=s.dragEnabled?new Xt(this):null,this._refreshDimensions(),this._refreshSortData()}function Qt(){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)}Kt.prototype.getGrid=function(){return t[this._gridId]},Kt.prototype.getElement=function(){return this._element},Kt.prototype.getWidth=function(){return this._width},Kt.prototype.getHeight=function(){return this._height},Kt.prototype.getMargin=function(){return{left:this._marginLeft,right:this._marginRight,top:this._marginTop,bottom:this._marginBottom}},Kt.prototype.getPosition=function(){return{left:this._left,top:this._top}},Kt.prototype.isActive=function(){return this._isActive},Kt.prototype.isVisible=function(){return!!this._visibility&&!this._visibility._isHidden},Kt.prototype.isShowing=function(){return!(!this._visibility||!this._visibility._isShowing)},Kt.prototype.isHiding=function(){return!(!this._visibility||!this._visibility._isHiding)},Kt.prototype.isPositioning=function(){return!(!this._layout||!this._layout._isActive)},Kt.prototype.isDragging=function(){return!(!this._drag||!this._drag._isActive)},Kt.prototype.isReleasing=function(){return!(!this._release||!this._release._isActive)},Kt.prototype.isDestroyed=function(){return this._isDestroyed},Kt.prototype._refreshDimensions=function(){if(!this._isDestroyed&&!this._visibility._isHidden){var t=this._element,e=this._dragPlaceholder,i=t.getBoundingClientRect();this._width=i.width,this._height=i.height,this._marginLeft=Math.max(0,ht(t,"margin-left")),this._marginRight=Math.max(0,ht(t,"margin-right")),this._marginTop=Math.max(0,ht(t,"margin-top")),this._marginBottom=Math.max(0,ht(t,"margin-bottom")),e&&e.updateDimensions(this._width,this._height)}},Kt.prototype._refreshSortData=function(){if(!this._isDestroyed){var t,e=this._sortData={},i=this.getGrid()._settings.sortData;for(t in i)e[t]=i[t](this,this._element)}},Kt.prototype._destroy=function(t){if(!this._isDestroyed){var e=this._element,i=this.getGrid(),s=i._settings,n=i._items.indexOf(this);this._release.destroy(),this._migrate.destroy(),this._layout.destroy(),this._visibility.destroy(),this._animate.destroy(),this._animateChild.destroy(),this._dragPlaceholder.destroy(),this._drag&&this._drag.destroy(),e.removeAttribute("style"),this._child.removeAttribute("style"),xt(e,s.itemClass),n>-1&&i._items.splice(n,1),t&&e.parentNode.removeChild(e),this._isActive=!1,this._isDestroyed=!0}},Qt.prototype.getLayout=function(t,e,i,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),c=this._slotSizes;if(o.slots=s||this._slots,o.width=a?0:d?Math.round(e):e,o.height=a?d?Math.round(i):i:0,o.setWidth=a,o.setHeight=!a,o.slots.length=0,c.length=0,!t.length)return o;for(r=0;rd.height&&(Wt.left>0&&u.push(this._addRect(0,d.height,Wt.left,1/0)),Wt.left+Wt.widthd.width&&(Wt.top>0&&u.push(this._addRect(d.width,0,1/0,Wt.top)),Wt.top+Wt.height.49&&r.height>.49&&(!e&&r.tope.left+e.width&&jt.push(this._addRect(e.left+e.width,t.top,t.left+t.width-(e.left+e.width),t.height)),t.tope.top+e.height&&jt.push(this._addRect(t.left,e.top+e.height,t.width,t.top+t.height-(e.top+e.height))),jt):(jt.push(this._addRect(t.left,t.top,t.width,t.height)),jt)}),Qt.prototype._doRectsOverlap=function(t,e){return!(t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top)},Qt.prototype._isRectWithinRect=function(t,e){return t.left>=e.left&&t.top>=e.top&&t.left+t.width<=e.left+e.width&&t.top+t.height<=e.top+e.height},Qt.prototype._purgeRects=(Ut={},Zt={},function(t){for(var e,i=t.length;i--;)if(e=t.length,t[i])for(this._getRect(t[i],Ut);e--;)if(t[e]&&i!==e&&this._isRectWithinRect(Ut,this._getRect(t[e],Zt))){t[i]=0;break}return t}),Qt.prototype._sortRectsTopLeft=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.tope.top?1:t.lefte.left?1:0}}(),Qt.prototype._sortRectsLeftTop=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.lefte.left?1:t.tope.top?1:0}}();var te="[object HTMLCollection]",ee="[object NodeList]";function ie(t){var e=Object.prototype.toString.call(t);return e===te||e===ee}var se="object",ne="[object Object]",re=Object.prototype.toString;function oe(t){return typeof t===se&&re.call(t)===ne}function he(t){return ie(t)?Array.prototype.slice.call(t):Array.prototype.concat(t)}var ae=new Qt,_e=function(){},le="number",de="string";function ce(e,s){var n,r,o,h=this;if(!((e=this._element=typeof e===de?window.document.querySelector(e):e).getRootNode?e.getRootNode({composed:!0})===document:window.document.body.contains(e))||e===window.document.documentElement)throw new Error("Container element must be an existing DOM element");c((n=this._settings=function(t,e){var i=ue({},t);e&&(i=ue(i,e));return i.visibleStyles=(e||0).visibleStyles||(t||0).visibleStyles,i.hiddenStyles=(e||0).hiddenStyles||(t||0).hiddenStyles,i}(ce.defaultOptions,s)).dragSort)||(n.dragSort=!!n.dragSort),this._id=Jt(),t[this._id]=h,this._isDestroyed=!1,this._layout={id:0,items:[],slots:[],setWidth:!1,setHeight:!1,width:0,height:0},this._emitter=new i,j(e,n.containerClass),this._items=[],typeof(r=n.items)===de?he(e.children).forEach(function(t){("*"===r||W(t,r))&&h._items.push(new Kt(h,t))}):(Array.isArray(r)||ie(r))&&(this._items=he(r).map(function(t){return new Kt(h,t)})),typeof(o=n.layoutOnResize)!==le&&(o=!0===o?0:-1),o>=0&&window.addEventListener("resize",h._resizeHandler=nt(function(){h.refreshItems().layout()},o)),n.layoutOnInit&&this.layout(!0)}function ue(t,e){var i,s,n,r=Object.keys(e),o=r.length;for(n=0;n0)){var s=o._layout.id!==l,n=c(t)?t:i;c(n)&&n(s,_.items.slice(0)),!s&&o._hasListeners(e)&&o._emit(e,_.items.slice(0))}}if((_.setHeight&&typeof _.height===le||_.setWidth&&typeof _.width===le)&&(s="border-box"===a(h,"box-sizing")),_.setHeight&&(typeof _.height===le?h.style.height=(s?_.height+this._borderTop+this._borderBottom:_.height)+"px":h.style.height=_.height),_.setWidth&&(typeof _.width===le?h.style.width=(s?_.width+this._borderLeft+this._borderRight:_.width)+"px":h.style.width=_.width),this._hasListeners("layoutStart")&&this._emit("layoutStart",_.items.slice(0)),!d)return f(),this;for(r=0;rl?1:0:ld?1:0)return c;return c||(s||(s=n(i)),c=r(o,h)),c}function h(o,h){var a=t(o,h);return e&&a&&(a=-a),a||(s||(s=n(i)),r(o,h))}return function(n,r){if(this._isDestroyed||this._items.length<2)return this;var a,_=this._items,l=r||0,d=l.layout?l.layout:void 0===l.layout;if(t=n,e=!!l.descending,i=_.slice(0),s=null,c(t))_.sort(h);else if(typeof t===de)t=n.trim().split(" ").map(function(t){return t.split(":")}),_.sort(o);else{if(!Array.isArray(t))return this;if(t.length!==_.length)throw new Error("[Muuri] sort reference items do not match with grid items.");for(a=0;a<_.length;a++){if(t.indexOf(_[a])<0)throw new Error("[Muuri] sort reference items do not match with grid items.");_[a]=t[a]}e&&_.reverse()}return this._hasListeners("sort")&&this._emit("sort",_.slice(0),i),d&&this.layout("instant"===d,c(d)?d:void 0),this}}(),ce.prototype.move=function(t,e,i){if(this._isDestroyed||this._items.length<2)return this;var s,n,r=this._items,o=i||0,h=o.layout?o.layout:void 0===o.layout,a="swap"===o.action,_=a?"swap":"move",l=this._getItem(t),d=this._getItem(e);return l&&d&&l!==d&&(s=r.indexOf(l),n=r.indexOf(d),a?Q(r,s,n):K(r,s,n),this._hasListeners("move")&&this._emit("move",{item:l,fromIndex:s,toIndex:n,action:_}),h&&this.layout("instant"===h,c(h)?h:void 0)),this},ce.prototype.send=function(t,e,i,s){if(this._isDestroyed||e._isDestroyed||this===e)return this;if(!(t=this._getItem(t)))return this;var n=s||0,r=n.appendTo||window.document.body,o=n.layoutSender?n.layoutSender:void 0===n.layoutSender,h=n.layoutReceiver?n.layoutReceiver:void 0===n.layoutReceiver;return t._migrate.start(e,i,r),t._migrate._isActive&&t._isActive&&(o&&this.layout("instant"===o,c(o)?o:void 0),h&&e.layout("instant"===h,c(h)?h:void 0)),this},ce.prototype.destroy=function(e){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-1?t:this._items.length+t]||null;if(t instanceof Kt)return t._gridId===this._id?t:null;for(var e=0;e-1||(M._activeInstances.push(t),M._emitter.on(b,t._onMove),M._emitter.on(A,t._onCancel),M._emitter.on(D,t._onEnd),1===M._activeInstances.length&&M._bindListeners())},M._deactivateInstance=function(t){var e=M._activeInstances.indexOf(t);-1!==e&&(M._activeInstances.splice(e,1),M._emitter.off(b,t._onMove),M._emitter.off(A,t._onCancel),M._emitter.off(D,t._onEnd),M._activeInstances.length||M._unbindListeners())},M._bindListeners=function(){var t=M._events;window.addEventListener(t.move,M._onMove,R),window.addEventListener(t.end,M._onEnd,R),t.cancel&&window.addEventListener(t.cancel,M._onCancel,R)},M._unbindListeners=function(){var t=M._events;window.removeEventListener(t.move,M._onMove,R),window.removeEventListener(t.end,M._onEnd,R),t.cancel&&window.removeEventListener(t.cancel,M._onCancel,R)},M._getEventPointerId=function(t){return"number"==typeof t.pointerId?t.pointerId:t.changedTouches?t.changedTouches[0]?t.changedTouches[0].identifier:null:1},M._getTouchById=function(t,e){if("number"==typeof t.pointerId)return t.pointerId===e?t:null;if(t.changedTouches){for(var i=0;i-1&&(this._queue[n]=void 0),s?this._queue.unshift(t):this._queue.push(t),this._reads[t]=e,this._writes[t]=i,this._nextStep||(this._nextStep=y(this._step))},T.prototype.cancel=function(t){var e=this._queue.indexOf(t);e>-1&&(this._queue[e]=void 0,delete this._reads[t],delete this._writes[t])},T.prototype._step=function(){var t,e,i=this._queue,s=this._reads,n=this._writes,r=this._batch,o=this._batchReads,h=this._batchWrites,a=i.length;for(this._nextStep=null,e=0;en?n:e<0?Math.max(n+e+1,0):e}function K(t,e,i){if(!(t.length<2)){var s=J(t,e),n=J(t,i);s!==n&&t.splice(n,0,t.splice(s,1)[0])}}function Q(t,e,i){if(!(t.length<2)){var s,n=J(t,e),r=J(t,i);n!==r&&(s=t[n],t[n]=t[r],t[r]=s)}}var tt="cancel",et="finish",it="debounce",st=0;function nt(t,e){var i,s=++st+it;return e>0?function(n){void 0!==i&&(i=window.clearTimeout(i),k.cancel(s),n===et&&t()),n!==tt&&n!==et&&(i=window.setTimeout(function(){i=void 0,k.add(s,t,null,!0)},e))}:function(e){e!==tt&&t()}}function rt(t){var e=a(t,"transform");if(!e||"none"===e)return!1;var i=a(t,"display");return"inline"!==i&&"none"!==i}function ot(t){for(var e=window.document,i=t||e;i&&i!==e&&"static"===a(i,"position")&&!rt(i);)i=i.parentElement||e;return i}function ht(t,e){return parseFloat(a(t,e))||0}var at={},_t={},lt={};function dt(t,e){var i,s=e||{};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:(i=t.getBoundingClientRect(),s.left+=i.left,s.top+=i.top,s.left+=ht(t,"border-left-width"),s.top+=ht(t,"border-top-width"),s))}function ct(t,e,i){return lt.left=0,lt.top=0,t===e?lt:i&&(t=ot(t))===(e=ot(e))?lt:(dt(t,at),dt(e,_t),lt.left=_t.left-at.left,lt.top=_t.top-at.top,lt)}var ut="overflow",ft="overflow-x",pt="overflow-y",mt="auto",gt="scroll";function yt(t){var e=a(t,ut);return e===mt||e===gt||((e=a(t,ft))===mt||e===gt||((e=a(t,pt))===mt||e===gt))}function vt(t,e,i){for(var s=i||[],n=e?t:t.parentNode;n&&n!==document;)n.getRootNode&&n instanceof DocumentFragment?n=n.getRootNode().host:(yt(n)&&s.push(n),n=n.parentNode);return s.push(window),s}var wt={},St="transform",bt="none",Dt=/^matrix3d/,At=/([^,]*,){4}/,Et=/([^,]*,){12}/,Ct=/[^,]*,/;function Lt(t){wt.x=0,wt.y=0;var e=a(t,St);if(!e||e===bt)return wt;var i=Dt.test(e),s=e.replace(i?Et:At,""),n=s.replace(Ct,"");return wt.x=parseFloat(s)||0,wt.y=parseFloat(n)||0,wt}function xt(t,e){return"translateX("+t+"px) translateY("+e+"px)"}function Rt(t,e){t.classList?t.classList.remove(e):W(t,"."+e)&&(t.className=(" "+t.className+" ").replace(" "+e+" "," ").trim())}var It,Pt,Mt,Tt,kt=0;function Xt(t){var e=t._element,i=t.getGrid(),s=i._settings;this._item=t,this._gridId=i._id,this._isDestroyed=!1,this._isMigrating=!1,this._startPredicate=c(s.dragStartPredicate)?s.dragStartPredicate:Xt.defaultStartPredicate,this._startPredicateState=kt,this._startPredicateResult=void 0,this._hBlockedIndex=null,this._hX1=0,this._hX2=0,this._hY1=0,this._hY2=0,this._reset(),this._preStartCheck=this._preStartCheck.bind(this),this._preEndCheck=this._preEndCheck.bind(this),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);var n=s.dragSortHeuristics.sortInterval;this._checkOverlapDebounce=nt(this._checkOverlap,n),this._dragger=new M(e,s.dragCssProps),this._dragger.on("start",this._preStartCheck),this._dragger.on("move",this._preStartCheck),this._dragger.on("cancel",this._preEndCheck),this._dragger.on("end",this._preEndCheck)}function Yt(t,e){return t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top?0:(Math.min(t.left+t.width,e.left+e.width)-Math.max(t.left,e.left))*(Math.min(t.top+t.height,e.top+e.height)-Math.max(t.top,e.top))/(Math.min(t.width,e.width)*Math.min(t.height,e.height))*100}function Ot(t){this._item=t,this._animate=new p,this._element=null,this._className="",this._didMigrate=!1,this._resetAfterLayout=!1,this._currentLeft=0,this._currentTop=0,this._nextLeft=0,this._nextTop=0,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this),this._onLayoutStart=this._onLayoutStart.bind(this),this._onLayoutEnd=this._onLayoutEnd.bind(this),this._onReleaseEnd=this._onReleaseEnd.bind(this),this._onMigrate=this._onMigrate.bind(this)}function Gt(){this._queue=[],this._isDestroyed=!1}function Ht(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 Gt,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this)}Xt.defaultStartPredicate=function(t,e,i){var s=t._drag;if(!s._startPredicateData){var n=i||s._getGrid()._settings.dragStartPredicate||{};s._startPredicateData={distance:Math.max(n.distance,0)||0,delay:Math.max(n.delay,0)||0,handle:"string"==typeof n.handle&&n.handle}}var r=s._startPredicateData;if(!e.isFinal)return!(!r.handleElement&&(r.handleElement=s._getStartPredicateHandle(e),!r.handleElement))&&(r.delay&&(r.event=e,r.delayTimer||(r.delayTimer=window.setTimeout(function(){r.delay=0,s._resolveStartPredicate(r.event)&&(s._forceResolveStartPredicate(r.event),s._resetStartPredicate())},r.delay))),s._resolveStartPredicate(e));s._finishStartPredicate(e)},Xt.defaultSortPredicate=(It={},Pt={},Mt={},Tt=[],function(t,e){var i=t._drag,s=i._getGrid(),n=e&&"number"==typeof e.threshold?e.threshold:50,r=e&&"swap"===e.action?"swap":"move",o=e&&"swap"===e.migrateAction?"swap":"move";n=Math.min(Math.max(n,1),100),It.width=t._width,It.height=t._height,It.left=i._elementClientX,It.top=i._elementClientY;var h=function(t,e,i){var s,n,r,o,h=null,a=e._settings.dragSort,_=-1;if(!0===a?(Tt[0]=e,n=Tt):c(a)&&(n=a.call(e,t)),!n||!Array.isArray(n)||!n.length)return h;for(o=0;oi&&s>_&&(_=s,h=r));return Tt.length=0,h}(t,s,n);if(!h)return!1;var a,_,l,d=t.getGrid()!==h,u=0,f=0,p=0,m=-1,g=!1;for(h===s?(It.left=i._gridX+t._marginLeft,It.top=i._gridY+t._marginTop):(h._updateBorders(1,0,1,0),u=h._left+h._borderLeft,f=h._top+h._borderTop),l=0;lp&&(m=l,p=_));return d&&p=n&&(Mt.grid=h,Mt.index=m,Mt.action=d?o:r,Mt)}),Xt.prototype.stop=function(){var t=this._item,e=t._element,i=this._getGrid();return this._isActive?this._isMigrating?(this._finishMigration(),this):(N(t._id),q(t._id),this._unbindScrollListeners(),this._checkOverlapDebounce("cancel"),e.parentNode!==i._element&&(i._element.appendChild(e),e.style[n]=xt(this._gridX,this._gridY)),Rt(e,i._settings.itemDraggingClass),this._reset(),this):this},Xt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(),this._dragger.destroy(),this._isDestroyed=!0,this)},Xt.prototype._getGrid=function(){return t[this._gridId]||null},Xt.prototype._reset=function(){this._isActive=!1,this._container=null,this._containingBlock=null,this._dragEvent=null,this._scrollEvent=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},Xt.prototype._bindScrollListeners=function(){var t,e,i=this._getGrid()._element,s=this._container,n=this._scrollers;if(n.length=0,vt(this._item._element,!1,n),s!==i)for(vt(i,!0,t=[]),e=0;e=s&&t.pageX=n&&t.pageY3&&e.minBounceBackAngle>0;if(h||(this._hBlockedIndex=null),Math.abs(r)>i||Math.abs(o)>i){if(h){var a=Math.atan2(r,o),_=Math.atan2(this._hX2-this._hX1,this._hY2-this._hY1),l=Math.atan2(Math.sin(a-_),Math.cos(a-_));Math.abs(l)>e.minBounceBackAngle&&(this._hBlockedIndex=null)}return this._hX1=this._hX2,this._hY1=this._hY2,this._hX2=s,this._hY2=n,!0}return!1},Xt.prototype._resetStartPredicate=function(){var t=this._startPredicateData;t&&(t.delayTimer&&(t.delayTimer=window.clearTimeout(t.delayTimer)),this._startPredicateData=null)},Xt.prototype._checkOverlap=function(){if(this._isActive){var t,e,i,s,n,r,o,h,a=this._item,_=this._getGrid()._settings;(t=c(_.dragSortPredicate)?_.dragSortPredicate(a,this._dragEvent):Xt.defaultSortPredicate(a,_.dragSortPredicate))&&"number"==typeof t.index&&(h=(e=a.getGrid())!==(s=t.grid||e),i=e._items.indexOf(a),n=J(s._items,t.index,h),o="swap"===t.action?"swap":"move",(h||n!==this._hBlockedIndex)&&(h?(this._hBlockedIndex=null,r=s._items[n],e._hasListeners("beforeSend")&&e._emit("beforeSend",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("beforeReceive")&&s._emit("beforeReceive",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),a._gridId=s._id,this._isMigrating=a._gridId!==this._gridId,e._items.splice(i,1),$(s._items,a,n),a._sortData=null,e._hasListeners("send")&&e._emit("send",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("receive")&&s._emit("receive",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),"swap"===o&&r&&r.isActive()&&s._items.indexOf(r)>-1&&s.send(r,e,i,{appendTo:this._container||window.document.body,layoutSender:!1,layoutReceiver:!1}),e.layout(),s.layout()):i!==n&&(this._hBlockedIndex=i,("swap"===o?Q:K)(e._items,i,n),e._hasListeners("move")&&e._emit("move",{item:a,fromIndex:i,toIndex:n,action:o}),e.layout())))}},Xt.prototype._finishMigration=function(){var t,e,i=this._item,s=i._release,r=i._element,o=i._isActive,h=i.getGrid(),a=h._element,_=h._settings,l=_.dragContainer||a,d=this._getGrid()._settings,c=r.parentNode;this._isMigrating=!1,this.destroy(),Rt(r,d.itemClass),Rt(r,d.itemVisibleClass),Rt(r,d.itemHiddenClass),j(r,_.itemClass),j(r,o?_.itemVisibleClass:_.itemHiddenClass),l!==c&&(l.appendChild(r),e=ct(c,l,!0),(t=Lt(r)).x-=e.left,t.y-=e.top),i._refreshDimensions(),i._refreshSortData(),e=ct(l,a,!0),s._containerDiffX=e.left,s._containerDiffY=e.top,i._drag=_.dragEnabled?new Xt(i):null,l!==c&&(r.style[n]=xt(t.x,t.y)),i._child.removeAttribute("style"),f(i._child,o?_.visibleStyles:_.hiddenStyles),s.start()},Xt.prototype._preStartCheck=function(t){this._startPredicateState===kt&&(this._startPredicateState=1),1===this._startPredicateState?(this._startPredicateResult=this._startPredicate(this._item,t),!0===this._startPredicateResult?(this._startPredicateState=2,this._onStart(t)):!1===this._startPredicateResult&&(this._startPredicateState=3)):2===this._startPredicateState&&this._isActive&&this._onMove(t)},Xt.prototype._preEndCheck=function(t){var e=2===this._startPredicateState;this._startPredicate(this._item,t),this._startPredicateState=kt,e&&this._isActive&&this._onEnd(t)},Xt.prototype._onStart=function(t){var e=this._item;if(e._isActive){var i,s=e._element,r=this._getGrid(),o=r._settings,h=e._release,a=e._migrate,_=r._element,l=o.dragContainer||_,d=ot(l),c=Lt(s),u=c.x,f=c.y,p=s.getBoundingClientRect(),m=l!==_;this._resetHeuristics(t),m&&(i=ct(d,_)),e.isPositioning()&&e._layout.stop(!0,{transform:xt(u,f)}),a._isActive&&(u-=a._containerDiffX,f-=a._containerDiffY,a.stop(!0,{transform:xt(u,f)})),e.isReleasing()&&h._reset(),this._isActive=!0,this._dragEvent=t,this._container=l,this._containingBlock=d,this._elementClientX=p.left,this._elementClientY=p.top,this._left=this._gridX=u,this._top=this._gridY=f,o.dragPlaceholder.enabled&&e._dragPlaceholder.create(),r._emit("dragInit",e,t),m&&(this._containerDiffX=i.left,this._containerDiffY=i.top,s.parentNode===l?(this._gridX=u-this._containerDiffX,this._gridY=f-this._containerDiffY):(this._left=u+this._containerDiffX,this._top=f+this._containerDiffY,l.appendChild(s),s.style[n]=xt(this._left,this._top))),j(s,o.itemDraggingClass),this._bindScrollListeners(),r._emit("dragStart",e,t)}},Xt.prototype._onMove=function(t){var e=this._item;if(e._isActive){var i,s,n,r=this._getGrid()._settings.dragAxis;if("y"!==r){var o=t.clientX-this._dragEvent.clientX;this._left+=o,this._gridX+=o,this._elementClientX+=o}if("x"!==r){var h=t.clientY-this._dragEvent.clientY;this._top+=h,this._gridY+=h,this._elementClientY+=h}this._dragEvent=t,i=e._id,s=this._prepareMove,n=this._applyMove,k.add(i+O,s,n,!0)}else this.stop()},Xt.prototype._prepareMove=function(){this._item._isActive&&this._getGrid()._settings.dragSort&&this._checkHeuristics(this._dragEvent)&&this._checkOverlapDebounce()},Xt.prototype._applyMove=function(){var t=this._item;t._isActive&&(t._element.style[n]=xt(this._left,this._top),this._getGrid()._emit("dragMove",t,this._dragEvent))},Xt.prototype._onScroll=function(t){var e,i,s,n=this._item;n._isActive?(this._scrollEvent=t,e=n._id,i=this._prepareScroll,s=this._applyScroll,k.add(e+G,i,s,!0)):this.stop()},Xt.prototype._prepareScroll=function(){var t=this._item;if(t._isActive){var e,i=t._element,s=this._getGrid(),n=s._settings,r=n.dragAxis,o=s._element,h=i.getBoundingClientRect(),a=this._elementClientX-h.left,_=this._elementClientY-h.top;this._container!==o&&(e=ct(this._containingBlock,o),this._containerDiffX=e.left,this._containerDiffY=e.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()}},Xt.prototype._applyScroll=function(){var t=this._item;t._isActive&&(t._element.style[n]=xt(this._left,this._top),this._getGrid()._emit("dragScroll",t,this._scrollEvent))},Xt.prototype._onEnd=function(t){var e=this._item,i=e._element,s=this._getGrid(),n=s._settings,r=e._release;e._isActive?(N(e._id),q(e._id),n.dragSort&&this._checkOverlapDebounce("finish"),this._unbindScrollListeners(),r._containerDiffX=this._containerDiffX,r._containerDiffY=this._containerDiffY,this._reset(),Rt(i,n.itemDraggingClass),s._emit("dragEnd",e,t),this._isMigrating?this._finishMigration():r.start()):this.stop()},Ot.prototype._onLayoutStart=function(){var t=this._item,e=t.getGrid(),i=e._items.indexOf(t),s=e._layout.slots[2*i],n=e._layout.slots[2*i+1];if(this._didMigrate||t._left!==s||t._top!==n){var r,o,h;if(s+=t._marginLeft,n+=t._marginTop,!(e._settings.dragPlaceholder.duration>0)||this._didMigrate){F(t._id);var a={transform:xt(s,n)};return this._animate.isAnimating()?this._animate.stop(a):f(this._element,a),void(this._didMigrate&&(e.getElement().appendChild(this._element),this._didMigrate=!1))}this._nextLeft=s,this._nextTop=n,r=t._id,o=this._setupAnimation,h=this._startAnimation,k.add(r+H,o,h)}},Ot.prototype._setupAnimation=function(){if(this.isActive()){var t=Lt(this._element);this._currentLeft=t.x,this._currentTop=t.y}},Ot.prototype._startAnimation=function(){if(this.isActive()){var t=this._animate,e=this._currentLeft,i=this._currentTop,s=this._nextLeft,n=this._nextTop,r={transform:xt(s,n)};if(e!==s||i!==n){var o=this._item.getGrid()._settings.dragPlaceholder,h={transform:xt(e,i)};t.start(h,r,{duration:o.duration,easing:o.easing,onFinish:this._onLayoutEnd})}else t.isAnimating()&&t.stop(r)}},Ot.prototype._onLayoutEnd=function(){this._resetAfterLayout&&this.reset()},Ot.prototype._onReleaseEnd=function(t){if(t._id===this._item._id){if(!this._animate.isAnimating())return void this.reset();this._resetAfterLayout=!0}},Ot.prototype._onMigrate=function(t){if(t.item===this._item){var e=this._item.getGrid(),i=t.toGrid;e.off("dragReleaseEnd",this._onReleaseEnd),e.off("layoutStart",this._onLayoutStart),e.off("beforeSend",this._onMigrate),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("layoutStart",this._onLayoutStart),i.on("beforeSend",this._onMigrate),this._didMigrate=!0}},Ot.prototype.create=function(){if(this.isActive())this._resetAfterLayout=!1;else{var t,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;t=c(s.dragPlaceholder.createElement)?s.dragPlaceholder.createElement(e):window.document.createElement("div"),this._element=t,n._element=t,this._className=s.itemPlaceholderClass||"",this._className&&j(t,this._className);var r=e._left+e._marginLeft,o=e._top+e._marginTop;f(t,{display:"block",position:"absolute",left:"0",top:"0",width:e._width+"px",height:e._height+"px",transform:xt(r,o)}),i.on("layoutStart",this._onLayoutStart),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("beforeSend",this._onMigrate),c(s.dragPlaceholder.onCreate)&&s.dragPlaceholder.onCreate(e,t),i.getElement().appendChild(t)}},Ot.prototype.reset=function(){if(this.isActive()){var t=this._element,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;this._resetAfterLayout=!1,F(e._id),n.stop(),n._element=null,i.off("dragReleaseEnd",this._onReleaseEnd),i.off("layoutStart",this._onLayoutStart),i.off("beforeSend",this._onMigrate),this._className&&(Rt(t,this._className),this._className=""),t.parentNode.removeChild(t),this._element=null,c(s.dragPlaceholder.onRemove)&&s.dragPlaceholder.onRemove(e,t)}},Ot.prototype.updateDimensions=function(t,e){this.isActive()&&f(this._element,{width:t+"px",height:e+"px"})},Ot.prototype.isActive=function(){return!!this._element},Ot.prototype.destroy=function(){this.reset(),this._animate.destroy(),this._item=this._animate=null},Gt.prototype.add=function(t){return this._isDestroyed?this:(this._queue.push(t),this)},Gt.prototype.flush=function(t,e){if(this._isDestroyed)return this;var i,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,e),this;for(i=0;i0;return l&&this._queue.flush(!0,o),d&&(a._isPositioningStarted=!0),c(e)&&this._queue.add(e),m?(this._isActive=!0,this._animateOptions.easing=p,this._animateOptions.duration=u,this._isInterrupted=l,s=o._id,n=this._setupAnimation,r=this._startAnimation,k.add(s+X,n,r),this):(this._updateOffsets(),this._updateTargetStyles(),i=o._animate.isAnimating(),this.stop(!1,this._targetStyles),!i&&f(h,this._targetStyles),this._skipNextAnimation=!1,this._finish())}},Ht.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item;return i=s._id,k.cancel(i+X),s._animate.stop(e),Rt(s._element,s.getGrid()._settings.itemPositioningClass),this._isActive=!1,t&&this._queue.flush(!0,s),this},Ht.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)},Ht.prototype._updateOffsets=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._offsetLeft=i._isActive?i._containerDiffX:e._isActive?e._containerDiffX:0,this._offsetTop=i._isActive?i._containerDiffY:e._isActive?e._containerDiffY:0}},Ht.prototype._updateTargetStyles=function(){this._isDestroyed||(this._targetStyles.transform=xt(this._item._left+this._offsetLeft,this._item._top+this._offsetTop))},Ht.prototype._finish=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._isActive&&(this._isActive=!1,Rt(t._element,t.getGrid()._settings.itemPositioningClass)),i._isActive&&i.stop(),e._isActive&&e.stop(),this._queue.flush(!1,t)}},Ht.prototype._setupAnimation=function(){var t=Lt(this._item._element);this._currentLeft=t.x,this._currentTop=t.y},Ht.prototype._startAnimation=function(){var t=this._item,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||j(t._element,e.itemPositioningClass),this._currentStyles.transform=xt(this._currentLeft,this._currentTop),t._animate.start(this._currentStyles,this._targetStyles,this._animateOptions)};var Bt={};function Nt(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._container=!1,this._containerDiffX=0,this._containerDiffY=0}Nt.prototype.start=function(t,e,i){if(this._isDestroyed)return this;var s,r,o,h,a,_,l,d,c=this._item,u=c._element,p=c.isVisible(),m=c.getGrid(),g=m._settings,y=t._settings,v=t._element,w=t._items,S=m._items.indexOf(c),b=i||window.document.body;if("number"==typeof e)s=J(w,e,!0);else{if(!(r=t._getItem(e)))return this;s=w.indexOf(r)}return(c.isPositioning()||this._isActive||c.isReleasing())&&(l=(_=Lt(u)).x,d=_.y),c.isPositioning()&&c._layout.stop(!0,{transform:xt(l,d)}),this._isActive&&(l-=this._containerDiffX,d-=this._containerDiffY,this.stop(!0,{transform:xt(l,d)})),c.isReleasing()&&(l-=c._release._containerDiffX,d-=c._release._containerDiffY,c._release.stop(!0,{transform:xt(l,d)})),c._visibility._stopAnimation(),c._drag&&c._drag.destroy(),c._visibility._queue.flush(!0,c),m._hasListeners("beforeSend")&&m._emit("beforeSend",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("beforeReceive")&&t._emit("beforeReceive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),Rt(u,g.itemClass),Rt(u,g.itemVisibleClass),Rt(u,g.itemHiddenClass),j(u,y.itemClass),j(u,p?y.itemVisibleClass:y.itemHiddenClass),m._items.splice(S,1),$(w,c,s),c._gridId=t._id,b!==(o=u.parentNode)&&(b.appendChild(u),h=ct(b,o,!0),_||(l=(_=Lt(u)).x,d=_.y),u.style[n]=xt(l+h.left,d+h.top)),c._child.removeAttribute("style"),f(c._child,p?y.visibleStyles:y.hiddenStyles),u.style.display=p?"block":"hidden",a=ct(b,v,!0),c._refreshDimensions(),c._refreshSortData(),c._drag=y.dragEnabled?new Xt(c):null,this._isActive=!0,this._container=b,this._containerDiffX=a.left,this._containerDiffY=a.top,m._hasListeners("send")&&m._emit("send",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("receive")&&t._emit("receive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),this},Nt.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid()._element;return this._container!==r&&(e||(t?(i=Lt(n),Bt.transform=xt(i.x-this._containerDiffX,i.y-this._containerDiffY)):Bt.transform=xt(s._left,s._top),e=Bt),r.appendChild(n),f(n,e)),this._isActive=!1,this._container=null,this._containerDiffX=0,this._containerDiffY=0,this},Nt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)};var qt={};function Ft(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0}function zt(t){var e=t._isActive,i=t._element,s=t.getGrid()._settings;this._item=t,this._isDestroyed=!1,this._isHidden=!e,this._isHiding=!1,this._isShowing=!1,this._queue=new Gt,this._finishShow=this._finishShow.bind(this),this._finishHide=this._finishHide.bind(this),i.style.display=e?"block":"none",j(i,e?s.itemVisibleClass:s.itemHiddenClass),f(t._child,e?s.visibleStyles:s.hiddenStyles)}Ft.prototype.start=function(){if(this._isDestroyed||this._isActive)return this;var t=this._item,e=t.getGrid();return this._isActive=!0,j(t._element,e._settings.itemReleasingClass),e._emit("dragReleaseStart",t),t._layout.start(!1),this},Ft.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid(),o=r._element;return this._reset(),n.parentNode!==o&&(e||(t?(i=Lt(n),qt.transform=xt(i.x-this._containerDiffX,i.y-this._containerDiffY)):qt.transform=xt(s._left,s._top),e=qt),o.appendChild(n),f(n,e)),t||r._emit("dragReleaseEnd",s),this},Ft.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)},Ft.prototype._reset=function(){if(!this._isDestroyed){var t=this._item;this._isActive=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0,Rt(t._element,t.getGrid()._settings.itemReleasingClass)}},zt.prototype.show=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return this._isShowing||this._isHidden?this._isShowing&&!t?(r&&n.add(r),this):(this._isShowing||(n.flush(!0,i),Rt(s,o.itemHiddenClass),j(s,o.itemVisibleClass),this._isHiding||(s.style.display="block")),r&&n.add(r),i._isActive=this._isShowing=!0,this._isHiding=this._isHidden=!1,this._startAnimation(!0,t,this._finishShow),this):(r&&r(!1,i),this)},zt.prototype.hide=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return!this._isHiding&&this._isHidden?(r&&r(!1,i),this):this._isHiding&&!t?(r&&n.add(r),this):(this._isHiding||(n.flush(!0,i),j(s,o.itemHiddenClass),Rt(s,o.itemVisibleClass)),r&&n.add(r),this._isHidden=this._isHiding=!0,i._isActive=this._isShowing=!1,this._startAnimation(!1,t,this._finishHide),this)},zt.prototype.destroy=function(){if(this._isDestroyed)return this;var t=this._item,e=t._element,i=t.getGrid(),s=this._queue,n=i._settings;return this._stopAnimation({}),s.flush(!0,t).destroy(),Rt(e,n.itemVisibleClass),Rt(e,n.itemHiddenClass),this._item=null,this._isHiding=this._isShowing=!1,this._isDestroyed=this._isHidden=!0,this},zt.prototype._startAnimation=function(t,e,i){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,_=(t?r.showEasing:r.hideEasing)||"ease",d=e||h<=0;if(o){if(B(n._id),d)return n._animateChild.isAnimating()?n._animateChild.stop(o):f(n._child,o),void(i&&i());var c,u,p;c=n._id,u=function(){s=function(t,e){var i={};for(var s in e)i[s]=a(t,l(s));return i}(n._child,o)},p=function(){n._animateChild.start(s,o,{duration:h,easing:_,onFinish:i})},k.add(c+Y,u,p)}else i&&i()}},zt.prototype._stopAnimation=function(t){if(!this._isDestroyed){var e=this._item;B(e._id),e._animateChild.stop(t)}},zt.prototype._finishShow=function(){this._isHidden||(this._isShowing=!1,this._queue.flush(!1,this._item))};var Vt={};zt.prototype._finishHide=function(){if(this._isHidden){var t=this._item;this._isHiding=!1,Vt.transform=xt(0,0),t._layout.stop(!0,Vt),t._element.style.display="none",this._queue.flush(!1,t)}};var Wt,jt,Ut,Zt,$t=0;function Jt(){return++$t}function Kt(t,e,i){var s=t._settings;this._id=Jt(),this._gridId=t._id,this._isDestroyed=!1,this._left=0,this._top=0,this._element=e,this._child=e.children[0],e.parentNode!==t._element&&t._element.appendChild(e),j(e,s.itemClass),"boolean"!=typeof i&&(i="none"!==a(e,"display")),this._isActive=i,e.style.left="0",e.style.top="0",e.style[n]=xt(0,0),this._animate=new p(e),this._animateChild=new p(this._child),this._visibility=new zt(this),this._layout=new Ht(this),this._migrate=new Nt(this),this._release=new Ft(this),this._dragPlaceholder=new Ot(this),this._drag=s.dragEnabled?new Xt(this):null,this._refreshDimensions(),this._refreshSortData()}function Qt(){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)}Kt.prototype.getGrid=function(){return t[this._gridId]},Kt.prototype.getElement=function(){return this._element},Kt.prototype.getWidth=function(){return this._width},Kt.prototype.getHeight=function(){return this._height},Kt.prototype.getMargin=function(){return{left:this._marginLeft,right:this._marginRight,top:this._marginTop,bottom:this._marginBottom}},Kt.prototype.getPosition=function(){return{left:this._left,top:this._top}},Kt.prototype.isActive=function(){return this._isActive},Kt.prototype.isVisible=function(){return!!this._visibility&&!this._visibility._isHidden},Kt.prototype.isShowing=function(){return!(!this._visibility||!this._visibility._isShowing)},Kt.prototype.isHiding=function(){return!(!this._visibility||!this._visibility._isHiding)},Kt.prototype.isPositioning=function(){return!(!this._layout||!this._layout._isActive)},Kt.prototype.isDragging=function(){return!(!this._drag||!this._drag._isActive)},Kt.prototype.isReleasing=function(){return!(!this._release||!this._release._isActive)},Kt.prototype.isDestroyed=function(){return this._isDestroyed},Kt.prototype._refreshDimensions=function(){if(!this._isDestroyed&&!this._visibility._isHidden){var t=this._element,e=this._dragPlaceholder,i=t.getBoundingClientRect();this._width=i.width,this._height=i.height,this._marginLeft=Math.max(0,ht(t,"margin-left")),this._marginRight=Math.max(0,ht(t,"margin-right")),this._marginTop=Math.max(0,ht(t,"margin-top")),this._marginBottom=Math.max(0,ht(t,"margin-bottom")),e&&e.updateDimensions(this._width,this._height)}},Kt.prototype._refreshSortData=function(){if(!this._isDestroyed){var t,e=this._sortData={},i=this.getGrid()._settings.sortData;for(t in i)e[t]=i[t](this,this._element)}},Kt.prototype._destroy=function(t){if(!this._isDestroyed){var e=this._element,i=this.getGrid(),s=i._settings,n=i._items.indexOf(this);this._release.destroy(),this._migrate.destroy(),this._layout.destroy(),this._visibility.destroy(),this._animate.destroy(),this._animateChild.destroy(),this._dragPlaceholder.destroy(),this._drag&&this._drag.destroy(),e.removeAttribute("style"),this._child.removeAttribute("style"),Rt(e,s.itemClass),n>-1&&i._items.splice(n,1),t&&e.parentNode.removeChild(e),this._isActive=!1,this._isDestroyed=!0}},Qt.prototype.getLayout=function(t,e,i,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),c=this._slotSizes;if(o.slots=s||this._slots,o.width=a?0:d?Math.round(e):e,o.height=a?d?Math.round(i):i:0,o.setWidth=a,o.setHeight=!a,o.slots.length=0,c.length=0,!t.length)return o;for(r=0;rd.height&&(Wt.left>0&&u.push(this._addRect(0,d.height,Wt.left,1/0)),Wt.left+Wt.widthd.width&&(Wt.top>0&&u.push(this._addRect(d.width,0,1/0,Wt.top)),Wt.top+Wt.height.49&&r.height>.49&&(!e&&r.tope.left+e.width&&jt.push(this._addRect(e.left+e.width,t.top,t.left+t.width-(e.left+e.width),t.height)),t.tope.top+e.height&&jt.push(this._addRect(t.left,e.top+e.height,t.width,t.top+t.height-(e.top+e.height))),jt):(jt.push(this._addRect(t.left,t.top,t.width,t.height)),jt)}),Qt.prototype._doRectsOverlap=function(t,e){return!(t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top)},Qt.prototype._isRectWithinRect=function(t,e){return t.left>=e.left&&t.top>=e.top&&t.left+t.width<=e.left+e.width&&t.top+t.height<=e.top+e.height},Qt.prototype._purgeRects=(Ut={},Zt={},function(t){for(var e,i=t.length;i--;)if(e=t.length,t[i])for(this._getRect(t[i],Ut);e--;)if(t[e]&&i!==e&&this._isRectWithinRect(Ut,this._getRect(t[e],Zt))){t[i]=0;break}return t}),Qt.prototype._sortRectsTopLeft=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.tope.top?1:t.lefte.left?1:0}}(),Qt.prototype._sortRectsLeftTop=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.lefte.left?1:t.tope.top?1:0}}();var te="[object HTMLCollection]",ee="[object NodeList]";function ie(t){var e=Object.prototype.toString.call(t);return e===te||e===ee}var se="object",ne="[object Object]",re=Object.prototype.toString;function oe(t){return typeof t===se&&re.call(t)===ne}function he(t){return ie(t)?Array.prototype.slice.call(t):Array.prototype.concat(t)}var ae=new Qt,_e=function(){},le="number",de="string";function ce(e,s){var n,r,o=this;if(typeof e===de&&(e=window.document.querySelector(e)),this._element=e,!(e.getRootNode?e.getRootNode({composed:!0})===document:window.document.body.contains(e))||e===window.document.documentElement)throw new Error("Container element must be an existing DOM element");c((n=this._settings=ue(ce.defaultOptions,s)).dragSort)||(n.dragSort=!!n.dragSort),this._id=Jt(),t[this._id]=o,this._isDestroyed=!1,this._layout={id:0,items:[],slots:[],setWidth:!1,setHeight:!1,width:0,height:0},this._emitter=new i,j(e,n.containerClass),this._items=[],typeof(r=n.items)===de?he(e.children).forEach(function(t){("*"===r||W(t,r))&&o._items.push(new Kt(o,t))}):(Array.isArray(r)||ie(r))&&(this._items=he(r).map(function(t){return new Kt(o,t)})),pe(this,n.layoutOnResize),n.layoutOnInit&&this.layout(!0)}function ue(t,e){var i=fe({},t);return e&&(i=fe(i,e)),i.visibleStyles=(e||0).visibleStyles||(t||0).visibleStyles,i.hiddenStyles=(e||0).hiddenStyles||(t||0).hiddenStyles,i}function fe(t,e){var i,s,n,r=Object.keys(e),o=r.length;for(n=0;n=0&&(t._resizeHandler=nt(function(){t.refreshItems().layout()},e),window.addEventListener("resize",t._resizeHandler))}function me(t){t._resizeHandler&&(t._resizeHandler("cancel"),window.removeEventListener("resize",t._resizeHandler),t._resizeHandler=null)}return ce.Item=Kt,ce.ItemLayout=Ht,ce.ItemVisibility=zt,ce.ItemMigrate=Nt,ce.ItemAnimate=p,ce.ItemDrag=Xt,ce.ItemRelease=Ft,ce.ItemDragPlaceholder=Ot,ce.Emitter=i,ce.Dragger=M,ce.Packer=Qt,ce.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,dragSortHeuristics:{sortInterval:100,minDragDistance:10,minBounceBackAngle:1},dragSortPredicate:{threshold:50,action:"move",migrateAction:"move"},dragReleaseDuration:300,dragReleaseEasing:"ease",dragCssProps:{touchAction:"none",userSelect:"none",userDrag:"none",tapHighlightColor:"rgba(0, 0, 0, 0)",touchCallout:"none",contentZooming:"none"},dragPlaceholder:{enabled:!1,duration:300,easing:"ease",createElement:null,onCreate:null,onRemove:null},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",itemPlaceholderClass:"muuri-item-placeholder"},ce.prototype.on=function(t,e){return this._emitter.on(t,e),this},ce.prototype.off=function(t,e){return this._emitter.off(t,e),this},ce.prototype.getElement=function(){return this._element},ce.prototype.getItems=function(t){if(this._isDestroyed||!t&&0!==t)return this._items.slice(0);var e,i,s=[],n=he(t);for(i=0;i-1){if(r.dragEnabled&&!o.dragEnabled){for(this._settings=r,e=0;e-1&&r.dragEnabled&&o.dragEnabled)for(e=0;e-1&&r.containerClass!==o.containerClass&&(Rt(s,r.containerClass),j(s,o.containerClass)),n.indexOf("sortData")>-1)for(e=0;e-1&&(me(this),pe(this,o.layoutOnResize)),o},ce.prototype.refreshItems=function(t){if(this._isDestroyed)return this;var e,i=this.getItems(t);for(e=0;e0)){var s=o._layout.id!==l,n=c(t)?t:i;c(n)&&n(s,_.items.slice(0)),!s&&o._hasListeners(e)&&o._emit(e,_.items.slice(0))}}if((_.setHeight&&typeof _.height===le||_.setWidth&&typeof _.width===le)&&(s="border-box"===a(h,"box-sizing")),_.setHeight&&(typeof _.height===le?h.style.height=(s?_.height+this._borderTop+this._borderBottom:_.height)+"px":h.style.height=_.height),_.setWidth&&(typeof _.width===le?h.style.width=(s?_.width+this._borderLeft+this._borderRight:_.width)+"px":h.style.width=_.width),this._hasListeners("layoutStart")&&this._emit("layoutStart",_.items.slice(0)),!d)return f(),this;for(r=0;rl?1:0:ld?1:0)return c;return c||(s||(s=n(i)),c=r(o,h)),c}function h(o,h){var a=t(o,h);return e&&a&&(a=-a),a||(s||(s=n(i)),r(o,h))}return function(n,r){if(this._isDestroyed||this._items.length<2)return this;var a,_=this._items,l=r||0,d=l.layout?l.layout:void 0===l.layout;if(t=n,e=!!l.descending,i=_.slice(0),s=null,c(t))_.sort(h);else if(typeof t===de)t=n.trim().split(" ").map(function(t){return t.split(":")}),_.sort(o);else{if(!Array.isArray(t))return this;if(t.length!==_.length)throw new Error("[Muuri] sort reference items do not match with grid items.");for(a=0;a<_.length;a++){if(t.indexOf(_[a])<0)throw new Error("[Muuri] sort reference items do not match with grid items.");_[a]=t[a]}e&&_.reverse()}return this._hasListeners("sort")&&this._emit("sort",_.slice(0),i),d&&this.layout("instant"===d,c(d)?d:void 0),this}}(),ce.prototype.move=function(t,e,i){if(this._isDestroyed||this._items.length<2)return this;var s,n,r=this._items,o=i||0,h=o.layout?o.layout:void 0===o.layout,a="swap"===o.action,_=a?"swap":"move",l=this._getItem(t),d=this._getItem(e);return l&&d&&l!==d&&(s=r.indexOf(l),n=r.indexOf(d),a?Q(r,s,n):K(r,s,n),this._hasListeners("move")&&this._emit("move",{item:l,fromIndex:s,toIndex:n,action:_}),h&&this.layout("instant"===h,c(h)?h:void 0)),this},ce.prototype.send=function(t,e,i,s){if(this._isDestroyed||e._isDestroyed||this===e)return this;if(!(t=this._getItem(t)))return this;var n=s||0,r=n.appendTo||window.document.body,o=n.layoutSender?n.layoutSender:void 0===n.layoutSender,h=n.layoutReceiver?n.layoutReceiver:void 0===n.layoutReceiver;return t._migrate.start(e,i,r),t._migrate._isActive&&t._isActive&&(o&&this.layout("instant"===o,c(o)?o:void 0),h&&e.layout("instant"===h,c(h)?h:void 0)),this},ce.prototype.destroy=function(e){if(this._isDestroyed)return this;var i,s=this._element,n=this._items.slice(0);for(me(this),i=0;i-1?t:this._items.length+t]||null;if(t instanceof Kt)return t._gridId===this._id?t:null;for(var e=0;e Date: Sat, 3 Aug 2019 13:16:55 +0300 Subject: [PATCH 017/120] Simplify ItemVisibility.prototype._finishHide method. --- dist/muuri.js | 21 +++++++++++---------- dist/muuri.min.js | 2 +- src/Item/ItemVisibility.js | 21 +++++++++++---------- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/dist/muuri.js b/dist/muuri.js index bba928c6..7bb69ae8 100644 --- a/dist/muuri.js +++ b/dist/muuri.js @@ -4493,16 +4493,17 @@ * @private * @memberof ItemVisibility.prototype */ - var finishStyles = {}; - ItemVisibility.prototype._finishHide = function() { - if (!this._isHidden) return; - var item = this._item; - this._isHiding = false; - finishStyles.transform = getTranslateString(0, 0); - item._layout.stop(true, finishStyles); - item._element.style.display = 'none'; - this._queue.flush(false, item); - }; + ItemVisibility.prototype._finishHide = (function() { + var finishStyles = { transform: getTranslateString(0, 0) }; + return function() { + if (!this._isHidden) return; + var item = this._item; + this._isHiding = false; + item._layout.stop(true, finishStyles); + item._element.style.display = 'none'; + this._queue.flush(false, item); + }; + })(); var id = 0; diff --git a/dist/muuri.min.js b/dist/muuri.min.js index bb653b66..30703d7d 100644 --- a/dist/muuri.min.js +++ b/dist/muuri.min.js @@ -14,4 +14,4 @@ * Copyright (c) 2018-present, Niklas Rämö * @license MIT */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Muuri=e()}(this,function(){"use strict";var t={},e="layoutEnd";function i(){this._events={},this._queue=[],this._counter=0,this._isDestroyed=!1}i.prototype.on=function(t,e){if(this._isDestroyed)return this;var i=this._events[t];return i||(i=this._events[t]=[]),i.push(e),this},i.prototype.off=function(t,e){if(this._isDestroyed)return this;var i=this._events[t];if(!i||!i.length)return this;if(!e)return i.length=0,this;for(var s=i.length;s--;)e===i[s]&&i.splice(s,1);return this},i.prototype.emit=function(t,e,i,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-1||(M._activeInstances.push(t),M._emitter.on(b,t._onMove),M._emitter.on(A,t._onCancel),M._emitter.on(D,t._onEnd),1===M._activeInstances.length&&M._bindListeners())},M._deactivateInstance=function(t){var e=M._activeInstances.indexOf(t);-1!==e&&(M._activeInstances.splice(e,1),M._emitter.off(b,t._onMove),M._emitter.off(A,t._onCancel),M._emitter.off(D,t._onEnd),M._activeInstances.length||M._unbindListeners())},M._bindListeners=function(){var t=M._events;window.addEventListener(t.move,M._onMove,R),window.addEventListener(t.end,M._onEnd,R),t.cancel&&window.addEventListener(t.cancel,M._onCancel,R)},M._unbindListeners=function(){var t=M._events;window.removeEventListener(t.move,M._onMove,R),window.removeEventListener(t.end,M._onEnd,R),t.cancel&&window.removeEventListener(t.cancel,M._onCancel,R)},M._getEventPointerId=function(t){return"number"==typeof t.pointerId?t.pointerId:t.changedTouches?t.changedTouches[0]?t.changedTouches[0].identifier:null:1},M._getTouchById=function(t,e){if("number"==typeof t.pointerId)return t.pointerId===e?t:null;if(t.changedTouches){for(var i=0;i-1&&(this._queue[n]=void 0),s?this._queue.unshift(t):this._queue.push(t),this._reads[t]=e,this._writes[t]=i,this._nextStep||(this._nextStep=y(this._step))},T.prototype.cancel=function(t){var e=this._queue.indexOf(t);e>-1&&(this._queue[e]=void 0,delete this._reads[t],delete this._writes[t])},T.prototype._step=function(){var t,e,i=this._queue,s=this._reads,n=this._writes,r=this._batch,o=this._batchReads,h=this._batchWrites,a=i.length;for(this._nextStep=null,e=0;en?n:e<0?Math.max(n+e+1,0):e}function K(t,e,i){if(!(t.length<2)){var s=J(t,e),n=J(t,i);s!==n&&t.splice(n,0,t.splice(s,1)[0])}}function Q(t,e,i){if(!(t.length<2)){var s,n=J(t,e),r=J(t,i);n!==r&&(s=t[n],t[n]=t[r],t[r]=s)}}var tt="cancel",et="finish",it="debounce",st=0;function nt(t,e){var i,s=++st+it;return e>0?function(n){void 0!==i&&(i=window.clearTimeout(i),k.cancel(s),n===et&&t()),n!==tt&&n!==et&&(i=window.setTimeout(function(){i=void 0,k.add(s,t,null,!0)},e))}:function(e){e!==tt&&t()}}function rt(t){var e=a(t,"transform");if(!e||"none"===e)return!1;var i=a(t,"display");return"inline"!==i&&"none"!==i}function ot(t){for(var e=window.document,i=t||e;i&&i!==e&&"static"===a(i,"position")&&!rt(i);)i=i.parentElement||e;return i}function ht(t,e){return parseFloat(a(t,e))||0}var at={},_t={},lt={};function dt(t,e){var i,s=e||{};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:(i=t.getBoundingClientRect(),s.left+=i.left,s.top+=i.top,s.left+=ht(t,"border-left-width"),s.top+=ht(t,"border-top-width"),s))}function ct(t,e,i){return lt.left=0,lt.top=0,t===e?lt:i&&(t=ot(t))===(e=ot(e))?lt:(dt(t,at),dt(e,_t),lt.left=_t.left-at.left,lt.top=_t.top-at.top,lt)}var ut="overflow",ft="overflow-x",pt="overflow-y",mt="auto",gt="scroll";function yt(t){var e=a(t,ut);return e===mt||e===gt||((e=a(t,ft))===mt||e===gt||((e=a(t,pt))===mt||e===gt))}function vt(t,e,i){for(var s=i||[],n=e?t:t.parentNode;n&&n!==document;)n.getRootNode&&n instanceof DocumentFragment?n=n.getRootNode().host:(yt(n)&&s.push(n),n=n.parentNode);return s.push(window),s}var wt={},St="transform",bt="none",Dt=/^matrix3d/,At=/([^,]*,){4}/,Et=/([^,]*,){12}/,Ct=/[^,]*,/;function Lt(t){wt.x=0,wt.y=0;var e=a(t,St);if(!e||e===bt)return wt;var i=Dt.test(e),s=e.replace(i?Et:At,""),n=s.replace(Ct,"");return wt.x=parseFloat(s)||0,wt.y=parseFloat(n)||0,wt}function xt(t,e){return"translateX("+t+"px) translateY("+e+"px)"}function Rt(t,e){t.classList?t.classList.remove(e):W(t,"."+e)&&(t.className=(" "+t.className+" ").replace(" "+e+" "," ").trim())}var It,Pt,Mt,Tt,kt=0;function Xt(t){var e=t._element,i=t.getGrid(),s=i._settings;this._item=t,this._gridId=i._id,this._isDestroyed=!1,this._isMigrating=!1,this._startPredicate=c(s.dragStartPredicate)?s.dragStartPredicate:Xt.defaultStartPredicate,this._startPredicateState=kt,this._startPredicateResult=void 0,this._hBlockedIndex=null,this._hX1=0,this._hX2=0,this._hY1=0,this._hY2=0,this._reset(),this._preStartCheck=this._preStartCheck.bind(this),this._preEndCheck=this._preEndCheck.bind(this),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);var n=s.dragSortHeuristics.sortInterval;this._checkOverlapDebounce=nt(this._checkOverlap,n),this._dragger=new M(e,s.dragCssProps),this._dragger.on("start",this._preStartCheck),this._dragger.on("move",this._preStartCheck),this._dragger.on("cancel",this._preEndCheck),this._dragger.on("end",this._preEndCheck)}function Yt(t,e){return t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top?0:(Math.min(t.left+t.width,e.left+e.width)-Math.max(t.left,e.left))*(Math.min(t.top+t.height,e.top+e.height)-Math.max(t.top,e.top))/(Math.min(t.width,e.width)*Math.min(t.height,e.height))*100}function Ot(t){this._item=t,this._animate=new p,this._element=null,this._className="",this._didMigrate=!1,this._resetAfterLayout=!1,this._currentLeft=0,this._currentTop=0,this._nextLeft=0,this._nextTop=0,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this),this._onLayoutStart=this._onLayoutStart.bind(this),this._onLayoutEnd=this._onLayoutEnd.bind(this),this._onReleaseEnd=this._onReleaseEnd.bind(this),this._onMigrate=this._onMigrate.bind(this)}function Gt(){this._queue=[],this._isDestroyed=!1}function Ht(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 Gt,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this)}Xt.defaultStartPredicate=function(t,e,i){var s=t._drag;if(!s._startPredicateData){var n=i||s._getGrid()._settings.dragStartPredicate||{};s._startPredicateData={distance:Math.max(n.distance,0)||0,delay:Math.max(n.delay,0)||0,handle:"string"==typeof n.handle&&n.handle}}var r=s._startPredicateData;if(!e.isFinal)return!(!r.handleElement&&(r.handleElement=s._getStartPredicateHandle(e),!r.handleElement))&&(r.delay&&(r.event=e,r.delayTimer||(r.delayTimer=window.setTimeout(function(){r.delay=0,s._resolveStartPredicate(r.event)&&(s._forceResolveStartPredicate(r.event),s._resetStartPredicate())},r.delay))),s._resolveStartPredicate(e));s._finishStartPredicate(e)},Xt.defaultSortPredicate=(It={},Pt={},Mt={},Tt=[],function(t,e){var i=t._drag,s=i._getGrid(),n=e&&"number"==typeof e.threshold?e.threshold:50,r=e&&"swap"===e.action?"swap":"move",o=e&&"swap"===e.migrateAction?"swap":"move";n=Math.min(Math.max(n,1),100),It.width=t._width,It.height=t._height,It.left=i._elementClientX,It.top=i._elementClientY;var h=function(t,e,i){var s,n,r,o,h=null,a=e._settings.dragSort,_=-1;if(!0===a?(Tt[0]=e,n=Tt):c(a)&&(n=a.call(e,t)),!n||!Array.isArray(n)||!n.length)return h;for(o=0;oi&&s>_&&(_=s,h=r));return Tt.length=0,h}(t,s,n);if(!h)return!1;var a,_,l,d=t.getGrid()!==h,u=0,f=0,p=0,m=-1,g=!1;for(h===s?(It.left=i._gridX+t._marginLeft,It.top=i._gridY+t._marginTop):(h._updateBorders(1,0,1,0),u=h._left+h._borderLeft,f=h._top+h._borderTop),l=0;lp&&(m=l,p=_));return d&&p=n&&(Mt.grid=h,Mt.index=m,Mt.action=d?o:r,Mt)}),Xt.prototype.stop=function(){var t=this._item,e=t._element,i=this._getGrid();return this._isActive?this._isMigrating?(this._finishMigration(),this):(N(t._id),q(t._id),this._unbindScrollListeners(),this._checkOverlapDebounce("cancel"),e.parentNode!==i._element&&(i._element.appendChild(e),e.style[n]=xt(this._gridX,this._gridY)),Rt(e,i._settings.itemDraggingClass),this._reset(),this):this},Xt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(),this._dragger.destroy(),this._isDestroyed=!0,this)},Xt.prototype._getGrid=function(){return t[this._gridId]||null},Xt.prototype._reset=function(){this._isActive=!1,this._container=null,this._containingBlock=null,this._dragEvent=null,this._scrollEvent=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},Xt.prototype._bindScrollListeners=function(){var t,e,i=this._getGrid()._element,s=this._container,n=this._scrollers;if(n.length=0,vt(this._item._element,!1,n),s!==i)for(vt(i,!0,t=[]),e=0;e=s&&t.pageX=n&&t.pageY3&&e.minBounceBackAngle>0;if(h||(this._hBlockedIndex=null),Math.abs(r)>i||Math.abs(o)>i){if(h){var a=Math.atan2(r,o),_=Math.atan2(this._hX2-this._hX1,this._hY2-this._hY1),l=Math.atan2(Math.sin(a-_),Math.cos(a-_));Math.abs(l)>e.minBounceBackAngle&&(this._hBlockedIndex=null)}return this._hX1=this._hX2,this._hY1=this._hY2,this._hX2=s,this._hY2=n,!0}return!1},Xt.prototype._resetStartPredicate=function(){var t=this._startPredicateData;t&&(t.delayTimer&&(t.delayTimer=window.clearTimeout(t.delayTimer)),this._startPredicateData=null)},Xt.prototype._checkOverlap=function(){if(this._isActive){var t,e,i,s,n,r,o,h,a=this._item,_=this._getGrid()._settings;(t=c(_.dragSortPredicate)?_.dragSortPredicate(a,this._dragEvent):Xt.defaultSortPredicate(a,_.dragSortPredicate))&&"number"==typeof t.index&&(h=(e=a.getGrid())!==(s=t.grid||e),i=e._items.indexOf(a),n=J(s._items,t.index,h),o="swap"===t.action?"swap":"move",(h||n!==this._hBlockedIndex)&&(h?(this._hBlockedIndex=null,r=s._items[n],e._hasListeners("beforeSend")&&e._emit("beforeSend",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("beforeReceive")&&s._emit("beforeReceive",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),a._gridId=s._id,this._isMigrating=a._gridId!==this._gridId,e._items.splice(i,1),$(s._items,a,n),a._sortData=null,e._hasListeners("send")&&e._emit("send",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("receive")&&s._emit("receive",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),"swap"===o&&r&&r.isActive()&&s._items.indexOf(r)>-1&&s.send(r,e,i,{appendTo:this._container||window.document.body,layoutSender:!1,layoutReceiver:!1}),e.layout(),s.layout()):i!==n&&(this._hBlockedIndex=i,("swap"===o?Q:K)(e._items,i,n),e._hasListeners("move")&&e._emit("move",{item:a,fromIndex:i,toIndex:n,action:o}),e.layout())))}},Xt.prototype._finishMigration=function(){var t,e,i=this._item,s=i._release,r=i._element,o=i._isActive,h=i.getGrid(),a=h._element,_=h._settings,l=_.dragContainer||a,d=this._getGrid()._settings,c=r.parentNode;this._isMigrating=!1,this.destroy(),Rt(r,d.itemClass),Rt(r,d.itemVisibleClass),Rt(r,d.itemHiddenClass),j(r,_.itemClass),j(r,o?_.itemVisibleClass:_.itemHiddenClass),l!==c&&(l.appendChild(r),e=ct(c,l,!0),(t=Lt(r)).x-=e.left,t.y-=e.top),i._refreshDimensions(),i._refreshSortData(),e=ct(l,a,!0),s._containerDiffX=e.left,s._containerDiffY=e.top,i._drag=_.dragEnabled?new Xt(i):null,l!==c&&(r.style[n]=xt(t.x,t.y)),i._child.removeAttribute("style"),f(i._child,o?_.visibleStyles:_.hiddenStyles),s.start()},Xt.prototype._preStartCheck=function(t){this._startPredicateState===kt&&(this._startPredicateState=1),1===this._startPredicateState?(this._startPredicateResult=this._startPredicate(this._item,t),!0===this._startPredicateResult?(this._startPredicateState=2,this._onStart(t)):!1===this._startPredicateResult&&(this._startPredicateState=3)):2===this._startPredicateState&&this._isActive&&this._onMove(t)},Xt.prototype._preEndCheck=function(t){var e=2===this._startPredicateState;this._startPredicate(this._item,t),this._startPredicateState=kt,e&&this._isActive&&this._onEnd(t)},Xt.prototype._onStart=function(t){var e=this._item;if(e._isActive){var i,s=e._element,r=this._getGrid(),o=r._settings,h=e._release,a=e._migrate,_=r._element,l=o.dragContainer||_,d=ot(l),c=Lt(s),u=c.x,f=c.y,p=s.getBoundingClientRect(),m=l!==_;this._resetHeuristics(t),m&&(i=ct(d,_)),e.isPositioning()&&e._layout.stop(!0,{transform:xt(u,f)}),a._isActive&&(u-=a._containerDiffX,f-=a._containerDiffY,a.stop(!0,{transform:xt(u,f)})),e.isReleasing()&&h._reset(),this._isActive=!0,this._dragEvent=t,this._container=l,this._containingBlock=d,this._elementClientX=p.left,this._elementClientY=p.top,this._left=this._gridX=u,this._top=this._gridY=f,o.dragPlaceholder.enabled&&e._dragPlaceholder.create(),r._emit("dragInit",e,t),m&&(this._containerDiffX=i.left,this._containerDiffY=i.top,s.parentNode===l?(this._gridX=u-this._containerDiffX,this._gridY=f-this._containerDiffY):(this._left=u+this._containerDiffX,this._top=f+this._containerDiffY,l.appendChild(s),s.style[n]=xt(this._left,this._top))),j(s,o.itemDraggingClass),this._bindScrollListeners(),r._emit("dragStart",e,t)}},Xt.prototype._onMove=function(t){var e=this._item;if(e._isActive){var i,s,n,r=this._getGrid()._settings.dragAxis;if("y"!==r){var o=t.clientX-this._dragEvent.clientX;this._left+=o,this._gridX+=o,this._elementClientX+=o}if("x"!==r){var h=t.clientY-this._dragEvent.clientY;this._top+=h,this._gridY+=h,this._elementClientY+=h}this._dragEvent=t,i=e._id,s=this._prepareMove,n=this._applyMove,k.add(i+O,s,n,!0)}else this.stop()},Xt.prototype._prepareMove=function(){this._item._isActive&&this._getGrid()._settings.dragSort&&this._checkHeuristics(this._dragEvent)&&this._checkOverlapDebounce()},Xt.prototype._applyMove=function(){var t=this._item;t._isActive&&(t._element.style[n]=xt(this._left,this._top),this._getGrid()._emit("dragMove",t,this._dragEvent))},Xt.prototype._onScroll=function(t){var e,i,s,n=this._item;n._isActive?(this._scrollEvent=t,e=n._id,i=this._prepareScroll,s=this._applyScroll,k.add(e+G,i,s,!0)):this.stop()},Xt.prototype._prepareScroll=function(){var t=this._item;if(t._isActive){var e,i=t._element,s=this._getGrid(),n=s._settings,r=n.dragAxis,o=s._element,h=i.getBoundingClientRect(),a=this._elementClientX-h.left,_=this._elementClientY-h.top;this._container!==o&&(e=ct(this._containingBlock,o),this._containerDiffX=e.left,this._containerDiffY=e.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()}},Xt.prototype._applyScroll=function(){var t=this._item;t._isActive&&(t._element.style[n]=xt(this._left,this._top),this._getGrid()._emit("dragScroll",t,this._scrollEvent))},Xt.prototype._onEnd=function(t){var e=this._item,i=e._element,s=this._getGrid(),n=s._settings,r=e._release;e._isActive?(N(e._id),q(e._id),n.dragSort&&this._checkOverlapDebounce("finish"),this._unbindScrollListeners(),r._containerDiffX=this._containerDiffX,r._containerDiffY=this._containerDiffY,this._reset(),Rt(i,n.itemDraggingClass),s._emit("dragEnd",e,t),this._isMigrating?this._finishMigration():r.start()):this.stop()},Ot.prototype._onLayoutStart=function(){var t=this._item,e=t.getGrid(),i=e._items.indexOf(t),s=e._layout.slots[2*i],n=e._layout.slots[2*i+1];if(this._didMigrate||t._left!==s||t._top!==n){var r,o,h;if(s+=t._marginLeft,n+=t._marginTop,!(e._settings.dragPlaceholder.duration>0)||this._didMigrate){F(t._id);var a={transform:xt(s,n)};return this._animate.isAnimating()?this._animate.stop(a):f(this._element,a),void(this._didMigrate&&(e.getElement().appendChild(this._element),this._didMigrate=!1))}this._nextLeft=s,this._nextTop=n,r=t._id,o=this._setupAnimation,h=this._startAnimation,k.add(r+H,o,h)}},Ot.prototype._setupAnimation=function(){if(this.isActive()){var t=Lt(this._element);this._currentLeft=t.x,this._currentTop=t.y}},Ot.prototype._startAnimation=function(){if(this.isActive()){var t=this._animate,e=this._currentLeft,i=this._currentTop,s=this._nextLeft,n=this._nextTop,r={transform:xt(s,n)};if(e!==s||i!==n){var o=this._item.getGrid()._settings.dragPlaceholder,h={transform:xt(e,i)};t.start(h,r,{duration:o.duration,easing:o.easing,onFinish:this._onLayoutEnd})}else t.isAnimating()&&t.stop(r)}},Ot.prototype._onLayoutEnd=function(){this._resetAfterLayout&&this.reset()},Ot.prototype._onReleaseEnd=function(t){if(t._id===this._item._id){if(!this._animate.isAnimating())return void this.reset();this._resetAfterLayout=!0}},Ot.prototype._onMigrate=function(t){if(t.item===this._item){var e=this._item.getGrid(),i=t.toGrid;e.off("dragReleaseEnd",this._onReleaseEnd),e.off("layoutStart",this._onLayoutStart),e.off("beforeSend",this._onMigrate),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("layoutStart",this._onLayoutStart),i.on("beforeSend",this._onMigrate),this._didMigrate=!0}},Ot.prototype.create=function(){if(this.isActive())this._resetAfterLayout=!1;else{var t,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;t=c(s.dragPlaceholder.createElement)?s.dragPlaceholder.createElement(e):window.document.createElement("div"),this._element=t,n._element=t,this._className=s.itemPlaceholderClass||"",this._className&&j(t,this._className);var r=e._left+e._marginLeft,o=e._top+e._marginTop;f(t,{display:"block",position:"absolute",left:"0",top:"0",width:e._width+"px",height:e._height+"px",transform:xt(r,o)}),i.on("layoutStart",this._onLayoutStart),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("beforeSend",this._onMigrate),c(s.dragPlaceholder.onCreate)&&s.dragPlaceholder.onCreate(e,t),i.getElement().appendChild(t)}},Ot.prototype.reset=function(){if(this.isActive()){var t=this._element,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;this._resetAfterLayout=!1,F(e._id),n.stop(),n._element=null,i.off("dragReleaseEnd",this._onReleaseEnd),i.off("layoutStart",this._onLayoutStart),i.off("beforeSend",this._onMigrate),this._className&&(Rt(t,this._className),this._className=""),t.parentNode.removeChild(t),this._element=null,c(s.dragPlaceholder.onRemove)&&s.dragPlaceholder.onRemove(e,t)}},Ot.prototype.updateDimensions=function(t,e){this.isActive()&&f(this._element,{width:t+"px",height:e+"px"})},Ot.prototype.isActive=function(){return!!this._element},Ot.prototype.destroy=function(){this.reset(),this._animate.destroy(),this._item=this._animate=null},Gt.prototype.add=function(t){return this._isDestroyed?this:(this._queue.push(t),this)},Gt.prototype.flush=function(t,e){if(this._isDestroyed)return this;var i,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,e),this;for(i=0;i0;return l&&this._queue.flush(!0,o),d&&(a._isPositioningStarted=!0),c(e)&&this._queue.add(e),m?(this._isActive=!0,this._animateOptions.easing=p,this._animateOptions.duration=u,this._isInterrupted=l,s=o._id,n=this._setupAnimation,r=this._startAnimation,k.add(s+X,n,r),this):(this._updateOffsets(),this._updateTargetStyles(),i=o._animate.isAnimating(),this.stop(!1,this._targetStyles),!i&&f(h,this._targetStyles),this._skipNextAnimation=!1,this._finish())}},Ht.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item;return i=s._id,k.cancel(i+X),s._animate.stop(e),Rt(s._element,s.getGrid()._settings.itemPositioningClass),this._isActive=!1,t&&this._queue.flush(!0,s),this},Ht.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)},Ht.prototype._updateOffsets=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._offsetLeft=i._isActive?i._containerDiffX:e._isActive?e._containerDiffX:0,this._offsetTop=i._isActive?i._containerDiffY:e._isActive?e._containerDiffY:0}},Ht.prototype._updateTargetStyles=function(){this._isDestroyed||(this._targetStyles.transform=xt(this._item._left+this._offsetLeft,this._item._top+this._offsetTop))},Ht.prototype._finish=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._isActive&&(this._isActive=!1,Rt(t._element,t.getGrid()._settings.itemPositioningClass)),i._isActive&&i.stop(),e._isActive&&e.stop(),this._queue.flush(!1,t)}},Ht.prototype._setupAnimation=function(){var t=Lt(this._item._element);this._currentLeft=t.x,this._currentTop=t.y},Ht.prototype._startAnimation=function(){var t=this._item,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||j(t._element,e.itemPositioningClass),this._currentStyles.transform=xt(this._currentLeft,this._currentTop),t._animate.start(this._currentStyles,this._targetStyles,this._animateOptions)};var Bt={};function Nt(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._container=!1,this._containerDiffX=0,this._containerDiffY=0}Nt.prototype.start=function(t,e,i){if(this._isDestroyed)return this;var s,r,o,h,a,_,l,d,c=this._item,u=c._element,p=c.isVisible(),m=c.getGrid(),g=m._settings,y=t._settings,v=t._element,w=t._items,S=m._items.indexOf(c),b=i||window.document.body;if("number"==typeof e)s=J(w,e,!0);else{if(!(r=t._getItem(e)))return this;s=w.indexOf(r)}return(c.isPositioning()||this._isActive||c.isReleasing())&&(l=(_=Lt(u)).x,d=_.y),c.isPositioning()&&c._layout.stop(!0,{transform:xt(l,d)}),this._isActive&&(l-=this._containerDiffX,d-=this._containerDiffY,this.stop(!0,{transform:xt(l,d)})),c.isReleasing()&&(l-=c._release._containerDiffX,d-=c._release._containerDiffY,c._release.stop(!0,{transform:xt(l,d)})),c._visibility._stopAnimation(),c._drag&&c._drag.destroy(),c._visibility._queue.flush(!0,c),m._hasListeners("beforeSend")&&m._emit("beforeSend",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("beforeReceive")&&t._emit("beforeReceive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),Rt(u,g.itemClass),Rt(u,g.itemVisibleClass),Rt(u,g.itemHiddenClass),j(u,y.itemClass),j(u,p?y.itemVisibleClass:y.itemHiddenClass),m._items.splice(S,1),$(w,c,s),c._gridId=t._id,b!==(o=u.parentNode)&&(b.appendChild(u),h=ct(b,o,!0),_||(l=(_=Lt(u)).x,d=_.y),u.style[n]=xt(l+h.left,d+h.top)),c._child.removeAttribute("style"),f(c._child,p?y.visibleStyles:y.hiddenStyles),u.style.display=p?"block":"hidden",a=ct(b,v,!0),c._refreshDimensions(),c._refreshSortData(),c._drag=y.dragEnabled?new Xt(c):null,this._isActive=!0,this._container=b,this._containerDiffX=a.left,this._containerDiffY=a.top,m._hasListeners("send")&&m._emit("send",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("receive")&&t._emit("receive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),this},Nt.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid()._element;return this._container!==r&&(e||(t?(i=Lt(n),Bt.transform=xt(i.x-this._containerDiffX,i.y-this._containerDiffY)):Bt.transform=xt(s._left,s._top),e=Bt),r.appendChild(n),f(n,e)),this._isActive=!1,this._container=null,this._containerDiffX=0,this._containerDiffY=0,this},Nt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)};var qt={};function Ft(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0}function zt(t){var e=t._isActive,i=t._element,s=t.getGrid()._settings;this._item=t,this._isDestroyed=!1,this._isHidden=!e,this._isHiding=!1,this._isShowing=!1,this._queue=new Gt,this._finishShow=this._finishShow.bind(this),this._finishHide=this._finishHide.bind(this),i.style.display=e?"block":"none",j(i,e?s.itemVisibleClass:s.itemHiddenClass),f(t._child,e?s.visibleStyles:s.hiddenStyles)}Ft.prototype.start=function(){if(this._isDestroyed||this._isActive)return this;var t=this._item,e=t.getGrid();return this._isActive=!0,j(t._element,e._settings.itemReleasingClass),e._emit("dragReleaseStart",t),t._layout.start(!1),this},Ft.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid(),o=r._element;return this._reset(),n.parentNode!==o&&(e||(t?(i=Lt(n),qt.transform=xt(i.x-this._containerDiffX,i.y-this._containerDiffY)):qt.transform=xt(s._left,s._top),e=qt),o.appendChild(n),f(n,e)),t||r._emit("dragReleaseEnd",s),this},Ft.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)},Ft.prototype._reset=function(){if(!this._isDestroyed){var t=this._item;this._isActive=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0,Rt(t._element,t.getGrid()._settings.itemReleasingClass)}},zt.prototype.show=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return this._isShowing||this._isHidden?this._isShowing&&!t?(r&&n.add(r),this):(this._isShowing||(n.flush(!0,i),Rt(s,o.itemHiddenClass),j(s,o.itemVisibleClass),this._isHiding||(s.style.display="block")),r&&n.add(r),i._isActive=this._isShowing=!0,this._isHiding=this._isHidden=!1,this._startAnimation(!0,t,this._finishShow),this):(r&&r(!1,i),this)},zt.prototype.hide=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return!this._isHiding&&this._isHidden?(r&&r(!1,i),this):this._isHiding&&!t?(r&&n.add(r),this):(this._isHiding||(n.flush(!0,i),j(s,o.itemHiddenClass),Rt(s,o.itemVisibleClass)),r&&n.add(r),this._isHidden=this._isHiding=!0,i._isActive=this._isShowing=!1,this._startAnimation(!1,t,this._finishHide),this)},zt.prototype.destroy=function(){if(this._isDestroyed)return this;var t=this._item,e=t._element,i=t.getGrid(),s=this._queue,n=i._settings;return this._stopAnimation({}),s.flush(!0,t).destroy(),Rt(e,n.itemVisibleClass),Rt(e,n.itemHiddenClass),this._item=null,this._isHiding=this._isShowing=!1,this._isDestroyed=this._isHidden=!0,this},zt.prototype._startAnimation=function(t,e,i){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,_=(t?r.showEasing:r.hideEasing)||"ease",d=e||h<=0;if(o){if(B(n._id),d)return n._animateChild.isAnimating()?n._animateChild.stop(o):f(n._child,o),void(i&&i());var c,u,p;c=n._id,u=function(){s=function(t,e){var i={};for(var s in e)i[s]=a(t,l(s));return i}(n._child,o)},p=function(){n._animateChild.start(s,o,{duration:h,easing:_,onFinish:i})},k.add(c+Y,u,p)}else i&&i()}},zt.prototype._stopAnimation=function(t){if(!this._isDestroyed){var e=this._item;B(e._id),e._animateChild.stop(t)}},zt.prototype._finishShow=function(){this._isHidden||(this._isShowing=!1,this._queue.flush(!1,this._item))};var Vt={};zt.prototype._finishHide=function(){if(this._isHidden){var t=this._item;this._isHiding=!1,Vt.transform=xt(0,0),t._layout.stop(!0,Vt),t._element.style.display="none",this._queue.flush(!1,t)}};var Wt,jt,Ut,Zt,$t=0;function Jt(){return++$t}function Kt(t,e,i){var s=t._settings;this._id=Jt(),this._gridId=t._id,this._isDestroyed=!1,this._left=0,this._top=0,this._element=e,this._child=e.children[0],e.parentNode!==t._element&&t._element.appendChild(e),j(e,s.itemClass),"boolean"!=typeof i&&(i="none"!==a(e,"display")),this._isActive=i,e.style.left="0",e.style.top="0",e.style[n]=xt(0,0),this._animate=new p(e),this._animateChild=new p(this._child),this._visibility=new zt(this),this._layout=new Ht(this),this._migrate=new Nt(this),this._release=new Ft(this),this._dragPlaceholder=new Ot(this),this._drag=s.dragEnabled?new Xt(this):null,this._refreshDimensions(),this._refreshSortData()}function Qt(){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)}Kt.prototype.getGrid=function(){return t[this._gridId]},Kt.prototype.getElement=function(){return this._element},Kt.prototype.getWidth=function(){return this._width},Kt.prototype.getHeight=function(){return this._height},Kt.prototype.getMargin=function(){return{left:this._marginLeft,right:this._marginRight,top:this._marginTop,bottom:this._marginBottom}},Kt.prototype.getPosition=function(){return{left:this._left,top:this._top}},Kt.prototype.isActive=function(){return this._isActive},Kt.prototype.isVisible=function(){return!!this._visibility&&!this._visibility._isHidden},Kt.prototype.isShowing=function(){return!(!this._visibility||!this._visibility._isShowing)},Kt.prototype.isHiding=function(){return!(!this._visibility||!this._visibility._isHiding)},Kt.prototype.isPositioning=function(){return!(!this._layout||!this._layout._isActive)},Kt.prototype.isDragging=function(){return!(!this._drag||!this._drag._isActive)},Kt.prototype.isReleasing=function(){return!(!this._release||!this._release._isActive)},Kt.prototype.isDestroyed=function(){return this._isDestroyed},Kt.prototype._refreshDimensions=function(){if(!this._isDestroyed&&!this._visibility._isHidden){var t=this._element,e=this._dragPlaceholder,i=t.getBoundingClientRect();this._width=i.width,this._height=i.height,this._marginLeft=Math.max(0,ht(t,"margin-left")),this._marginRight=Math.max(0,ht(t,"margin-right")),this._marginTop=Math.max(0,ht(t,"margin-top")),this._marginBottom=Math.max(0,ht(t,"margin-bottom")),e&&e.updateDimensions(this._width,this._height)}},Kt.prototype._refreshSortData=function(){if(!this._isDestroyed){var t,e=this._sortData={},i=this.getGrid()._settings.sortData;for(t in i)e[t]=i[t](this,this._element)}},Kt.prototype._destroy=function(t){if(!this._isDestroyed){var e=this._element,i=this.getGrid(),s=i._settings,n=i._items.indexOf(this);this._release.destroy(),this._migrate.destroy(),this._layout.destroy(),this._visibility.destroy(),this._animate.destroy(),this._animateChild.destroy(),this._dragPlaceholder.destroy(),this._drag&&this._drag.destroy(),e.removeAttribute("style"),this._child.removeAttribute("style"),Rt(e,s.itemClass),n>-1&&i._items.splice(n,1),t&&e.parentNode.removeChild(e),this._isActive=!1,this._isDestroyed=!0}},Qt.prototype.getLayout=function(t,e,i,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),c=this._slotSizes;if(o.slots=s||this._slots,o.width=a?0:d?Math.round(e):e,o.height=a?d?Math.round(i):i:0,o.setWidth=a,o.setHeight=!a,o.slots.length=0,c.length=0,!t.length)return o;for(r=0;rd.height&&(Wt.left>0&&u.push(this._addRect(0,d.height,Wt.left,1/0)),Wt.left+Wt.widthd.width&&(Wt.top>0&&u.push(this._addRect(d.width,0,1/0,Wt.top)),Wt.top+Wt.height.49&&r.height>.49&&(!e&&r.tope.left+e.width&&jt.push(this._addRect(e.left+e.width,t.top,t.left+t.width-(e.left+e.width),t.height)),t.tope.top+e.height&&jt.push(this._addRect(t.left,e.top+e.height,t.width,t.top+t.height-(e.top+e.height))),jt):(jt.push(this._addRect(t.left,t.top,t.width,t.height)),jt)}),Qt.prototype._doRectsOverlap=function(t,e){return!(t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top)},Qt.prototype._isRectWithinRect=function(t,e){return t.left>=e.left&&t.top>=e.top&&t.left+t.width<=e.left+e.width&&t.top+t.height<=e.top+e.height},Qt.prototype._purgeRects=(Ut={},Zt={},function(t){for(var e,i=t.length;i--;)if(e=t.length,t[i])for(this._getRect(t[i],Ut);e--;)if(t[e]&&i!==e&&this._isRectWithinRect(Ut,this._getRect(t[e],Zt))){t[i]=0;break}return t}),Qt.prototype._sortRectsTopLeft=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.tope.top?1:t.lefte.left?1:0}}(),Qt.prototype._sortRectsLeftTop=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.lefte.left?1:t.tope.top?1:0}}();var te="[object HTMLCollection]",ee="[object NodeList]";function ie(t){var e=Object.prototype.toString.call(t);return e===te||e===ee}var se="object",ne="[object Object]",re=Object.prototype.toString;function oe(t){return typeof t===se&&re.call(t)===ne}function he(t){return ie(t)?Array.prototype.slice.call(t):Array.prototype.concat(t)}var ae=new Qt,_e=function(){},le="number",de="string";function ce(e,s){var n,r,o=this;if(typeof e===de&&(e=window.document.querySelector(e)),this._element=e,!(e.getRootNode?e.getRootNode({composed:!0})===document:window.document.body.contains(e))||e===window.document.documentElement)throw new Error("Container element must be an existing DOM element");c((n=this._settings=ue(ce.defaultOptions,s)).dragSort)||(n.dragSort=!!n.dragSort),this._id=Jt(),t[this._id]=o,this._isDestroyed=!1,this._layout={id:0,items:[],slots:[],setWidth:!1,setHeight:!1,width:0,height:0},this._emitter=new i,j(e,n.containerClass),this._items=[],typeof(r=n.items)===de?he(e.children).forEach(function(t){("*"===r||W(t,r))&&o._items.push(new Kt(o,t))}):(Array.isArray(r)||ie(r))&&(this._items=he(r).map(function(t){return new Kt(o,t)})),pe(this,n.layoutOnResize),n.layoutOnInit&&this.layout(!0)}function ue(t,e){var i=fe({},t);return e&&(i=fe(i,e)),i.visibleStyles=(e||0).visibleStyles||(t||0).visibleStyles,i.hiddenStyles=(e||0).hiddenStyles||(t||0).hiddenStyles,i}function fe(t,e){var i,s,n,r=Object.keys(e),o=r.length;for(n=0;n=0&&(t._resizeHandler=nt(function(){t.refreshItems().layout()},e),window.addEventListener("resize",t._resizeHandler))}function me(t){t._resizeHandler&&(t._resizeHandler("cancel"),window.removeEventListener("resize",t._resizeHandler),t._resizeHandler=null)}return ce.Item=Kt,ce.ItemLayout=Ht,ce.ItemVisibility=zt,ce.ItemMigrate=Nt,ce.ItemAnimate=p,ce.ItemDrag=Xt,ce.ItemRelease=Ft,ce.ItemDragPlaceholder=Ot,ce.Emitter=i,ce.Dragger=M,ce.Packer=Qt,ce.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,dragSortHeuristics:{sortInterval:100,minDragDistance:10,minBounceBackAngle:1},dragSortPredicate:{threshold:50,action:"move",migrateAction:"move"},dragReleaseDuration:300,dragReleaseEasing:"ease",dragCssProps:{touchAction:"none",userSelect:"none",userDrag:"none",tapHighlightColor:"rgba(0, 0, 0, 0)",touchCallout:"none",contentZooming:"none"},dragPlaceholder:{enabled:!1,duration:300,easing:"ease",createElement:null,onCreate:null,onRemove:null},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",itemPlaceholderClass:"muuri-item-placeholder"},ce.prototype.on=function(t,e){return this._emitter.on(t,e),this},ce.prototype.off=function(t,e){return this._emitter.off(t,e),this},ce.prototype.getElement=function(){return this._element},ce.prototype.getItems=function(t){if(this._isDestroyed||!t&&0!==t)return this._items.slice(0);var e,i,s=[],n=he(t);for(i=0;i-1){if(r.dragEnabled&&!o.dragEnabled){for(this._settings=r,e=0;e-1&&r.dragEnabled&&o.dragEnabled)for(e=0;e-1&&r.containerClass!==o.containerClass&&(Rt(s,r.containerClass),j(s,o.containerClass)),n.indexOf("sortData")>-1)for(e=0;e-1&&(me(this),pe(this,o.layoutOnResize)),o},ce.prototype.refreshItems=function(t){if(this._isDestroyed)return this;var e,i=this.getItems(t);for(e=0;e0)){var s=o._layout.id!==l,n=c(t)?t:i;c(n)&&n(s,_.items.slice(0)),!s&&o._hasListeners(e)&&o._emit(e,_.items.slice(0))}}if((_.setHeight&&typeof _.height===le||_.setWidth&&typeof _.width===le)&&(s="border-box"===a(h,"box-sizing")),_.setHeight&&(typeof _.height===le?h.style.height=(s?_.height+this._borderTop+this._borderBottom:_.height)+"px":h.style.height=_.height),_.setWidth&&(typeof _.width===le?h.style.width=(s?_.width+this._borderLeft+this._borderRight:_.width)+"px":h.style.width=_.width),this._hasListeners("layoutStart")&&this._emit("layoutStart",_.items.slice(0)),!d)return f(),this;for(r=0;rl?1:0:ld?1:0)return c;return c||(s||(s=n(i)),c=r(o,h)),c}function h(o,h){var a=t(o,h);return e&&a&&(a=-a),a||(s||(s=n(i)),r(o,h))}return function(n,r){if(this._isDestroyed||this._items.length<2)return this;var a,_=this._items,l=r||0,d=l.layout?l.layout:void 0===l.layout;if(t=n,e=!!l.descending,i=_.slice(0),s=null,c(t))_.sort(h);else if(typeof t===de)t=n.trim().split(" ").map(function(t){return t.split(":")}),_.sort(o);else{if(!Array.isArray(t))return this;if(t.length!==_.length)throw new Error("[Muuri] sort reference items do not match with grid items.");for(a=0;a<_.length;a++){if(t.indexOf(_[a])<0)throw new Error("[Muuri] sort reference items do not match with grid items.");_[a]=t[a]}e&&_.reverse()}return this._hasListeners("sort")&&this._emit("sort",_.slice(0),i),d&&this.layout("instant"===d,c(d)?d:void 0),this}}(),ce.prototype.move=function(t,e,i){if(this._isDestroyed||this._items.length<2)return this;var s,n,r=this._items,o=i||0,h=o.layout?o.layout:void 0===o.layout,a="swap"===o.action,_=a?"swap":"move",l=this._getItem(t),d=this._getItem(e);return l&&d&&l!==d&&(s=r.indexOf(l),n=r.indexOf(d),a?Q(r,s,n):K(r,s,n),this._hasListeners("move")&&this._emit("move",{item:l,fromIndex:s,toIndex:n,action:_}),h&&this.layout("instant"===h,c(h)?h:void 0)),this},ce.prototype.send=function(t,e,i,s){if(this._isDestroyed||e._isDestroyed||this===e)return this;if(!(t=this._getItem(t)))return this;var n=s||0,r=n.appendTo||window.document.body,o=n.layoutSender?n.layoutSender:void 0===n.layoutSender,h=n.layoutReceiver?n.layoutReceiver:void 0===n.layoutReceiver;return t._migrate.start(e,i,r),t._migrate._isActive&&t._isActive&&(o&&this.layout("instant"===o,c(o)?o:void 0),h&&e.layout("instant"===h,c(h)?h:void 0)),this},ce.prototype.destroy=function(e){if(this._isDestroyed)return this;var i,s=this._element,n=this._items.slice(0);for(me(this),i=0;i-1?t:this._items.length+t]||null;if(t instanceof Kt)return t._gridId===this._id?t:null;for(var e=0;e-1||(M._activeInstances.push(t),M._emitter.on(b,t._onMove),M._emitter.on(A,t._onCancel),M._emitter.on(D,t._onEnd),1===M._activeInstances.length&&M._bindListeners())},M._deactivateInstance=function(t){var e=M._activeInstances.indexOf(t);-1!==e&&(M._activeInstances.splice(e,1),M._emitter.off(b,t._onMove),M._emitter.off(A,t._onCancel),M._emitter.off(D,t._onEnd),M._activeInstances.length||M._unbindListeners())},M._bindListeners=function(){var t=M._events;window.addEventListener(t.move,M._onMove,R),window.addEventListener(t.end,M._onEnd,R),t.cancel&&window.addEventListener(t.cancel,M._onCancel,R)},M._unbindListeners=function(){var t=M._events;window.removeEventListener(t.move,M._onMove,R),window.removeEventListener(t.end,M._onEnd,R),t.cancel&&window.removeEventListener(t.cancel,M._onCancel,R)},M._getEventPointerId=function(t){return"number"==typeof t.pointerId?t.pointerId:t.changedTouches?t.changedTouches[0]?t.changedTouches[0].identifier:null:1},M._getTouchById=function(t,e){if("number"==typeof t.pointerId)return t.pointerId===e?t:null;if(t.changedTouches){for(var i=0;i-1&&(this._queue[n]=void 0),s?this._queue.unshift(t):this._queue.push(t),this._reads[t]=e,this._writes[t]=i,this._nextStep||(this._nextStep=y(this._step))},T.prototype.cancel=function(t){var e=this._queue.indexOf(t);e>-1&&(this._queue[e]=void 0,delete this._reads[t],delete this._writes[t])},T.prototype._step=function(){var t,e,i=this._queue,s=this._reads,n=this._writes,r=this._batch,o=this._batchReads,h=this._batchWrites,a=i.length;for(this._nextStep=null,e=0;en?n:e<0?Math.max(n+e+1,0):e}function K(t,e,i){if(!(t.length<2)){var s=J(t,e),n=J(t,i);s!==n&&t.splice(n,0,t.splice(s,1)[0])}}function Q(t,e,i){if(!(t.length<2)){var s,n=J(t,e),r=J(t,i);n!==r&&(s=t[n],t[n]=t[r],t[r]=s)}}var tt="cancel",et="finish",it="debounce",st=0;function nt(t,e){var i,s=++st+it;return e>0?function(n){void 0!==i&&(i=window.clearTimeout(i),k.cancel(s),n===et&&t()),n!==tt&&n!==et&&(i=window.setTimeout(function(){i=void 0,k.add(s,t,null,!0)},e))}:function(e){e!==tt&&t()}}function rt(t){var e=a(t,"transform");if(!e||"none"===e)return!1;var i=a(t,"display");return"inline"!==i&&"none"!==i}function ot(t){for(var e=window.document,i=t||e;i&&i!==e&&"static"===a(i,"position")&&!rt(i);)i=i.parentElement||e;return i}function ht(t,e){return parseFloat(a(t,e))||0}var at={},_t={},lt={};function dt(t,e){var i,s=e||{};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:(i=t.getBoundingClientRect(),s.left+=i.left,s.top+=i.top,s.left+=ht(t,"border-left-width"),s.top+=ht(t,"border-top-width"),s))}function ct(t,e,i){return lt.left=0,lt.top=0,t===e?lt:i&&(t=ot(t))===(e=ot(e))?lt:(dt(t,at),dt(e,_t),lt.left=_t.left-at.left,lt.top=_t.top-at.top,lt)}var ut="overflow",ft="overflow-x",pt="overflow-y",mt="auto",gt="scroll";function yt(t){var e=a(t,ut);return e===mt||e===gt||((e=a(t,ft))===mt||e===gt||((e=a(t,pt))===mt||e===gt))}function vt(t,e,i){for(var s=i||[],n=e?t:t.parentNode;n&&n!==document;)n.getRootNode&&n instanceof DocumentFragment?n=n.getRootNode().host:(yt(n)&&s.push(n),n=n.parentNode);return s.push(window),s}var wt={},St="transform",bt="none",Dt=/^matrix3d/,At=/([^,]*,){4}/,Et=/([^,]*,){12}/,Ct=/[^,]*,/;function Lt(t){wt.x=0,wt.y=0;var e=a(t,St);if(!e||e===bt)return wt;var i=Dt.test(e),s=e.replace(i?Et:At,""),n=s.replace(Ct,"");return wt.x=parseFloat(s)||0,wt.y=parseFloat(n)||0,wt}function xt(t,e){return"translateX("+t+"px) translateY("+e+"px)"}function Rt(t,e){t.classList?t.classList.remove(e):W(t,"."+e)&&(t.className=(" "+t.className+" ").replace(" "+e+" "," ").trim())}var It,Pt,Mt,Tt,kt=0;function Xt(t){var e=t._element,i=t.getGrid(),s=i._settings;this._item=t,this._gridId=i._id,this._isDestroyed=!1,this._isMigrating=!1,this._startPredicate=c(s.dragStartPredicate)?s.dragStartPredicate:Xt.defaultStartPredicate,this._startPredicateState=kt,this._startPredicateResult=void 0,this._hBlockedIndex=null,this._hX1=0,this._hX2=0,this._hY1=0,this._hY2=0,this._reset(),this._preStartCheck=this._preStartCheck.bind(this),this._preEndCheck=this._preEndCheck.bind(this),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);var n=s.dragSortHeuristics.sortInterval;this._checkOverlapDebounce=nt(this._checkOverlap,n),this._dragger=new M(e,s.dragCssProps),this._dragger.on("start",this._preStartCheck),this._dragger.on("move",this._preStartCheck),this._dragger.on("cancel",this._preEndCheck),this._dragger.on("end",this._preEndCheck)}function Yt(t,e){return t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top?0:(Math.min(t.left+t.width,e.left+e.width)-Math.max(t.left,e.left))*(Math.min(t.top+t.height,e.top+e.height)-Math.max(t.top,e.top))/(Math.min(t.width,e.width)*Math.min(t.height,e.height))*100}function Ot(t){this._item=t,this._animate=new p,this._element=null,this._className="",this._didMigrate=!1,this._resetAfterLayout=!1,this._currentLeft=0,this._currentTop=0,this._nextLeft=0,this._nextTop=0,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this),this._onLayoutStart=this._onLayoutStart.bind(this),this._onLayoutEnd=this._onLayoutEnd.bind(this),this._onReleaseEnd=this._onReleaseEnd.bind(this),this._onMigrate=this._onMigrate.bind(this)}function Gt(){this._queue=[],this._isDestroyed=!1}function Ht(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 Gt,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this)}Xt.defaultStartPredicate=function(t,e,i){var s=t._drag;if(!s._startPredicateData){var n=i||s._getGrid()._settings.dragStartPredicate||{};s._startPredicateData={distance:Math.max(n.distance,0)||0,delay:Math.max(n.delay,0)||0,handle:"string"==typeof n.handle&&n.handle}}var r=s._startPredicateData;if(!e.isFinal)return!(!r.handleElement&&(r.handleElement=s._getStartPredicateHandle(e),!r.handleElement))&&(r.delay&&(r.event=e,r.delayTimer||(r.delayTimer=window.setTimeout(function(){r.delay=0,s._resolveStartPredicate(r.event)&&(s._forceResolveStartPredicate(r.event),s._resetStartPredicate())},r.delay))),s._resolveStartPredicate(e));s._finishStartPredicate(e)},Xt.defaultSortPredicate=(It={},Pt={},Mt={},Tt=[],function(t,e){var i=t._drag,s=i._getGrid(),n=e&&"number"==typeof e.threshold?e.threshold:50,r=e&&"swap"===e.action?"swap":"move",o=e&&"swap"===e.migrateAction?"swap":"move";n=Math.min(Math.max(n,1),100),It.width=t._width,It.height=t._height,It.left=i._elementClientX,It.top=i._elementClientY;var h=function(t,e,i){var s,n,r,o,h=null,a=e._settings.dragSort,_=-1;if(!0===a?(Tt[0]=e,n=Tt):c(a)&&(n=a.call(e,t)),!n||!Array.isArray(n)||!n.length)return h;for(o=0;oi&&s>_&&(_=s,h=r));return Tt.length=0,h}(t,s,n);if(!h)return!1;var a,_,l,d=t.getGrid()!==h,u=0,f=0,p=0,m=-1,g=!1;for(h===s?(It.left=i._gridX+t._marginLeft,It.top=i._gridY+t._marginTop):(h._updateBorders(1,0,1,0),u=h._left+h._borderLeft,f=h._top+h._borderTop),l=0;lp&&(m=l,p=_));return d&&p=n&&(Mt.grid=h,Mt.index=m,Mt.action=d?o:r,Mt)}),Xt.prototype.stop=function(){var t=this._item,e=t._element,i=this._getGrid();return this._isActive?this._isMigrating?(this._finishMigration(),this):(N(t._id),q(t._id),this._unbindScrollListeners(),this._checkOverlapDebounce("cancel"),e.parentNode!==i._element&&(i._element.appendChild(e),e.style[n]=xt(this._gridX,this._gridY)),Rt(e,i._settings.itemDraggingClass),this._reset(),this):this},Xt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(),this._dragger.destroy(),this._isDestroyed=!0,this)},Xt.prototype._getGrid=function(){return t[this._gridId]||null},Xt.prototype._reset=function(){this._isActive=!1,this._container=null,this._containingBlock=null,this._dragEvent=null,this._scrollEvent=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},Xt.prototype._bindScrollListeners=function(){var t,e,i=this._getGrid()._element,s=this._container,n=this._scrollers;if(n.length=0,vt(this._item._element,!1,n),s!==i)for(vt(i,!0,t=[]),e=0;e=s&&t.pageX=n&&t.pageY3&&e.minBounceBackAngle>0;if(h||(this._hBlockedIndex=null),Math.abs(r)>i||Math.abs(o)>i){if(h){var a=Math.atan2(r,o),_=Math.atan2(this._hX2-this._hX1,this._hY2-this._hY1),l=Math.atan2(Math.sin(a-_),Math.cos(a-_));Math.abs(l)>e.minBounceBackAngle&&(this._hBlockedIndex=null)}return this._hX1=this._hX2,this._hY1=this._hY2,this._hX2=s,this._hY2=n,!0}return!1},Xt.prototype._resetStartPredicate=function(){var t=this._startPredicateData;t&&(t.delayTimer&&(t.delayTimer=window.clearTimeout(t.delayTimer)),this._startPredicateData=null)},Xt.prototype._checkOverlap=function(){if(this._isActive){var t,e,i,s,n,r,o,h,a=this._item,_=this._getGrid()._settings;(t=c(_.dragSortPredicate)?_.dragSortPredicate(a,this._dragEvent):Xt.defaultSortPredicate(a,_.dragSortPredicate))&&"number"==typeof t.index&&(h=(e=a.getGrid())!==(s=t.grid||e),i=e._items.indexOf(a),n=J(s._items,t.index,h),o="swap"===t.action?"swap":"move",(h||n!==this._hBlockedIndex)&&(h?(this._hBlockedIndex=null,r=s._items[n],e._hasListeners("beforeSend")&&e._emit("beforeSend",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("beforeReceive")&&s._emit("beforeReceive",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),a._gridId=s._id,this._isMigrating=a._gridId!==this._gridId,e._items.splice(i,1),$(s._items,a,n),a._sortData=null,e._hasListeners("send")&&e._emit("send",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("receive")&&s._emit("receive",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),"swap"===o&&r&&r.isActive()&&s._items.indexOf(r)>-1&&s.send(r,e,i,{appendTo:this._container||window.document.body,layoutSender:!1,layoutReceiver:!1}),e.layout(),s.layout()):i!==n&&(this._hBlockedIndex=i,("swap"===o?Q:K)(e._items,i,n),e._hasListeners("move")&&e._emit("move",{item:a,fromIndex:i,toIndex:n,action:o}),e.layout())))}},Xt.prototype._finishMigration=function(){var t,e,i=this._item,s=i._release,r=i._element,o=i._isActive,h=i.getGrid(),a=h._element,_=h._settings,l=_.dragContainer||a,d=this._getGrid()._settings,c=r.parentNode;this._isMigrating=!1,this.destroy(),Rt(r,d.itemClass),Rt(r,d.itemVisibleClass),Rt(r,d.itemHiddenClass),j(r,_.itemClass),j(r,o?_.itemVisibleClass:_.itemHiddenClass),l!==c&&(l.appendChild(r),e=ct(c,l,!0),(t=Lt(r)).x-=e.left,t.y-=e.top),i._refreshDimensions(),i._refreshSortData(),e=ct(l,a,!0),s._containerDiffX=e.left,s._containerDiffY=e.top,i._drag=_.dragEnabled?new Xt(i):null,l!==c&&(r.style[n]=xt(t.x,t.y)),i._child.removeAttribute("style"),f(i._child,o?_.visibleStyles:_.hiddenStyles),s.start()},Xt.prototype._preStartCheck=function(t){this._startPredicateState===kt&&(this._startPredicateState=1),1===this._startPredicateState?(this._startPredicateResult=this._startPredicate(this._item,t),!0===this._startPredicateResult?(this._startPredicateState=2,this._onStart(t)):!1===this._startPredicateResult&&(this._startPredicateState=3)):2===this._startPredicateState&&this._isActive&&this._onMove(t)},Xt.prototype._preEndCheck=function(t){var e=2===this._startPredicateState;this._startPredicate(this._item,t),this._startPredicateState=kt,e&&this._isActive&&this._onEnd(t)},Xt.prototype._onStart=function(t){var e=this._item;if(e._isActive){var i,s=e._element,r=this._getGrid(),o=r._settings,h=e._release,a=e._migrate,_=r._element,l=o.dragContainer||_,d=ot(l),c=Lt(s),u=c.x,f=c.y,p=s.getBoundingClientRect(),m=l!==_;this._resetHeuristics(t),m&&(i=ct(d,_)),e.isPositioning()&&e._layout.stop(!0,{transform:xt(u,f)}),a._isActive&&(u-=a._containerDiffX,f-=a._containerDiffY,a.stop(!0,{transform:xt(u,f)})),e.isReleasing()&&h._reset(),this._isActive=!0,this._dragEvent=t,this._container=l,this._containingBlock=d,this._elementClientX=p.left,this._elementClientY=p.top,this._left=this._gridX=u,this._top=this._gridY=f,o.dragPlaceholder.enabled&&e._dragPlaceholder.create(),r._emit("dragInit",e,t),m&&(this._containerDiffX=i.left,this._containerDiffY=i.top,s.parentNode===l?(this._gridX=u-this._containerDiffX,this._gridY=f-this._containerDiffY):(this._left=u+this._containerDiffX,this._top=f+this._containerDiffY,l.appendChild(s),s.style[n]=xt(this._left,this._top))),j(s,o.itemDraggingClass),this._bindScrollListeners(),r._emit("dragStart",e,t)}},Xt.prototype._onMove=function(t){var e=this._item;if(e._isActive){var i,s,n,r=this._getGrid()._settings.dragAxis;if("y"!==r){var o=t.clientX-this._dragEvent.clientX;this._left+=o,this._gridX+=o,this._elementClientX+=o}if("x"!==r){var h=t.clientY-this._dragEvent.clientY;this._top+=h,this._gridY+=h,this._elementClientY+=h}this._dragEvent=t,i=e._id,s=this._prepareMove,n=this._applyMove,k.add(i+O,s,n,!0)}else this.stop()},Xt.prototype._prepareMove=function(){this._item._isActive&&this._getGrid()._settings.dragSort&&this._checkHeuristics(this._dragEvent)&&this._checkOverlapDebounce()},Xt.prototype._applyMove=function(){var t=this._item;t._isActive&&(t._element.style[n]=xt(this._left,this._top),this._getGrid()._emit("dragMove",t,this._dragEvent))},Xt.prototype._onScroll=function(t){var e,i,s,n=this._item;n._isActive?(this._scrollEvent=t,e=n._id,i=this._prepareScroll,s=this._applyScroll,k.add(e+G,i,s,!0)):this.stop()},Xt.prototype._prepareScroll=function(){var t=this._item;if(t._isActive){var e,i=t._element,s=this._getGrid(),n=s._settings,r=n.dragAxis,o=s._element,h=i.getBoundingClientRect(),a=this._elementClientX-h.left,_=this._elementClientY-h.top;this._container!==o&&(e=ct(this._containingBlock,o),this._containerDiffX=e.left,this._containerDiffY=e.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()}},Xt.prototype._applyScroll=function(){var t=this._item;t._isActive&&(t._element.style[n]=xt(this._left,this._top),this._getGrid()._emit("dragScroll",t,this._scrollEvent))},Xt.prototype._onEnd=function(t){var e=this._item,i=e._element,s=this._getGrid(),n=s._settings,r=e._release;e._isActive?(N(e._id),q(e._id),n.dragSort&&this._checkOverlapDebounce("finish"),this._unbindScrollListeners(),r._containerDiffX=this._containerDiffX,r._containerDiffY=this._containerDiffY,this._reset(),Rt(i,n.itemDraggingClass),s._emit("dragEnd",e,t),this._isMigrating?this._finishMigration():r.start()):this.stop()},Ot.prototype._onLayoutStart=function(){var t=this._item,e=t.getGrid(),i=e._items.indexOf(t),s=e._layout.slots[2*i],n=e._layout.slots[2*i+1];if(this._didMigrate||t._left!==s||t._top!==n){var r,o,h;if(s+=t._marginLeft,n+=t._marginTop,!(e._settings.dragPlaceholder.duration>0)||this._didMigrate){F(t._id);var a={transform:xt(s,n)};return this._animate.isAnimating()?this._animate.stop(a):f(this._element,a),void(this._didMigrate&&(e.getElement().appendChild(this._element),this._didMigrate=!1))}this._nextLeft=s,this._nextTop=n,r=t._id,o=this._setupAnimation,h=this._startAnimation,k.add(r+H,o,h)}},Ot.prototype._setupAnimation=function(){if(this.isActive()){var t=Lt(this._element);this._currentLeft=t.x,this._currentTop=t.y}},Ot.prototype._startAnimation=function(){if(this.isActive()){var t=this._animate,e=this._currentLeft,i=this._currentTop,s=this._nextLeft,n=this._nextTop,r={transform:xt(s,n)};if(e!==s||i!==n){var o=this._item.getGrid()._settings.dragPlaceholder,h={transform:xt(e,i)};t.start(h,r,{duration:o.duration,easing:o.easing,onFinish:this._onLayoutEnd})}else t.isAnimating()&&t.stop(r)}},Ot.prototype._onLayoutEnd=function(){this._resetAfterLayout&&this.reset()},Ot.prototype._onReleaseEnd=function(t){if(t._id===this._item._id){if(!this._animate.isAnimating())return void this.reset();this._resetAfterLayout=!0}},Ot.prototype._onMigrate=function(t){if(t.item===this._item){var e=this._item.getGrid(),i=t.toGrid;e.off("dragReleaseEnd",this._onReleaseEnd),e.off("layoutStart",this._onLayoutStart),e.off("beforeSend",this._onMigrate),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("layoutStart",this._onLayoutStart),i.on("beforeSend",this._onMigrate),this._didMigrate=!0}},Ot.prototype.create=function(){if(this.isActive())this._resetAfterLayout=!1;else{var t,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;t=c(s.dragPlaceholder.createElement)?s.dragPlaceholder.createElement(e):window.document.createElement("div"),this._element=t,n._element=t,this._className=s.itemPlaceholderClass||"",this._className&&j(t,this._className);var r=e._left+e._marginLeft,o=e._top+e._marginTop;f(t,{display:"block",position:"absolute",left:"0",top:"0",width:e._width+"px",height:e._height+"px",transform:xt(r,o)}),i.on("layoutStart",this._onLayoutStart),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("beforeSend",this._onMigrate),c(s.dragPlaceholder.onCreate)&&s.dragPlaceholder.onCreate(e,t),i.getElement().appendChild(t)}},Ot.prototype.reset=function(){if(this.isActive()){var t=this._element,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;this._resetAfterLayout=!1,F(e._id),n.stop(),n._element=null,i.off("dragReleaseEnd",this._onReleaseEnd),i.off("layoutStart",this._onLayoutStart),i.off("beforeSend",this._onMigrate),this._className&&(Rt(t,this._className),this._className=""),t.parentNode.removeChild(t),this._element=null,c(s.dragPlaceholder.onRemove)&&s.dragPlaceholder.onRemove(e,t)}},Ot.prototype.updateDimensions=function(t,e){this.isActive()&&f(this._element,{width:t+"px",height:e+"px"})},Ot.prototype.isActive=function(){return!!this._element},Ot.prototype.destroy=function(){this.reset(),this._animate.destroy(),this._item=this._animate=null},Gt.prototype.add=function(t){return this._isDestroyed?this:(this._queue.push(t),this)},Gt.prototype.flush=function(t,e){if(this._isDestroyed)return this;var i,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,e),this;for(i=0;i0;return l&&this._queue.flush(!0,o),d&&(a._isPositioningStarted=!0),c(e)&&this._queue.add(e),m?(this._isActive=!0,this._animateOptions.easing=p,this._animateOptions.duration=u,this._isInterrupted=l,s=o._id,n=this._setupAnimation,r=this._startAnimation,k.add(s+X,n,r),this):(this._updateOffsets(),this._updateTargetStyles(),i=o._animate.isAnimating(),this.stop(!1,this._targetStyles),!i&&f(h,this._targetStyles),this._skipNextAnimation=!1,this._finish())}},Ht.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item;return i=s._id,k.cancel(i+X),s._animate.stop(e),Rt(s._element,s.getGrid()._settings.itemPositioningClass),this._isActive=!1,t&&this._queue.flush(!0,s),this},Ht.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)},Ht.prototype._updateOffsets=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._offsetLeft=i._isActive?i._containerDiffX:e._isActive?e._containerDiffX:0,this._offsetTop=i._isActive?i._containerDiffY:e._isActive?e._containerDiffY:0}},Ht.prototype._updateTargetStyles=function(){this._isDestroyed||(this._targetStyles.transform=xt(this._item._left+this._offsetLeft,this._item._top+this._offsetTop))},Ht.prototype._finish=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._isActive&&(this._isActive=!1,Rt(t._element,t.getGrid()._settings.itemPositioningClass)),i._isActive&&i.stop(),e._isActive&&e.stop(),this._queue.flush(!1,t)}},Ht.prototype._setupAnimation=function(){var t=Lt(this._item._element);this._currentLeft=t.x,this._currentTop=t.y},Ht.prototype._startAnimation=function(){var t=this._item,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||j(t._element,e.itemPositioningClass),this._currentStyles.transform=xt(this._currentLeft,this._currentTop),t._animate.start(this._currentStyles,this._targetStyles,this._animateOptions)};var Bt={};function Nt(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._container=!1,this._containerDiffX=0,this._containerDiffY=0}Nt.prototype.start=function(t,e,i){if(this._isDestroyed)return this;var s,r,o,h,a,_,l,d,c=this._item,u=c._element,p=c.isVisible(),m=c.getGrid(),g=m._settings,y=t._settings,v=t._element,w=t._items,S=m._items.indexOf(c),b=i||window.document.body;if("number"==typeof e)s=J(w,e,!0);else{if(!(r=t._getItem(e)))return this;s=w.indexOf(r)}return(c.isPositioning()||this._isActive||c.isReleasing())&&(l=(_=Lt(u)).x,d=_.y),c.isPositioning()&&c._layout.stop(!0,{transform:xt(l,d)}),this._isActive&&(l-=this._containerDiffX,d-=this._containerDiffY,this.stop(!0,{transform:xt(l,d)})),c.isReleasing()&&(l-=c._release._containerDiffX,d-=c._release._containerDiffY,c._release.stop(!0,{transform:xt(l,d)})),c._visibility._stopAnimation(),c._drag&&c._drag.destroy(),c._visibility._queue.flush(!0,c),m._hasListeners("beforeSend")&&m._emit("beforeSend",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("beforeReceive")&&t._emit("beforeReceive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),Rt(u,g.itemClass),Rt(u,g.itemVisibleClass),Rt(u,g.itemHiddenClass),j(u,y.itemClass),j(u,p?y.itemVisibleClass:y.itemHiddenClass),m._items.splice(S,1),$(w,c,s),c._gridId=t._id,b!==(o=u.parentNode)&&(b.appendChild(u),h=ct(b,o,!0),_||(l=(_=Lt(u)).x,d=_.y),u.style[n]=xt(l+h.left,d+h.top)),c._child.removeAttribute("style"),f(c._child,p?y.visibleStyles:y.hiddenStyles),u.style.display=p?"block":"hidden",a=ct(b,v,!0),c._refreshDimensions(),c._refreshSortData(),c._drag=y.dragEnabled?new Xt(c):null,this._isActive=!0,this._container=b,this._containerDiffX=a.left,this._containerDiffY=a.top,m._hasListeners("send")&&m._emit("send",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("receive")&&t._emit("receive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),this},Nt.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid()._element;return this._container!==r&&(e||(t?(i=Lt(n),Bt.transform=xt(i.x-this._containerDiffX,i.y-this._containerDiffY)):Bt.transform=xt(s._left,s._top),e=Bt),r.appendChild(n),f(n,e)),this._isActive=!1,this._container=null,this._containerDiffX=0,this._containerDiffY=0,this},Nt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)};var qt,Ft={};function zt(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0}function Vt(t){var e=t._isActive,i=t._element,s=t.getGrid()._settings;this._item=t,this._isDestroyed=!1,this._isHidden=!e,this._isHiding=!1,this._isShowing=!1,this._queue=new Gt,this._finishShow=this._finishShow.bind(this),this._finishHide=this._finishHide.bind(this),i.style.display=e?"block":"none",j(i,e?s.itemVisibleClass:s.itemHiddenClass),f(t._child,e?s.visibleStyles:s.hiddenStyles)}zt.prototype.start=function(){if(this._isDestroyed||this._isActive)return this;var t=this._item,e=t.getGrid();return this._isActive=!0,j(t._element,e._settings.itemReleasingClass),e._emit("dragReleaseStart",t),t._layout.start(!1),this},zt.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid(),o=r._element;return this._reset(),n.parentNode!==o&&(e||(t?(i=Lt(n),Ft.transform=xt(i.x-this._containerDiffX,i.y-this._containerDiffY)):Ft.transform=xt(s._left,s._top),e=Ft),o.appendChild(n),f(n,e)),t||r._emit("dragReleaseEnd",s),this},zt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)},zt.prototype._reset=function(){if(!this._isDestroyed){var t=this._item;this._isActive=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0,Rt(t._element,t.getGrid()._settings.itemReleasingClass)}},Vt.prototype.show=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return this._isShowing||this._isHidden?this._isShowing&&!t?(r&&n.add(r),this):(this._isShowing||(n.flush(!0,i),Rt(s,o.itemHiddenClass),j(s,o.itemVisibleClass),this._isHiding||(s.style.display="block")),r&&n.add(r),i._isActive=this._isShowing=!0,this._isHiding=this._isHidden=!1,this._startAnimation(!0,t,this._finishShow),this):(r&&r(!1,i),this)},Vt.prototype.hide=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return!this._isHiding&&this._isHidden?(r&&r(!1,i),this):this._isHiding&&!t?(r&&n.add(r),this):(this._isHiding||(n.flush(!0,i),j(s,o.itemHiddenClass),Rt(s,o.itemVisibleClass)),r&&n.add(r),this._isHidden=this._isHiding=!0,i._isActive=this._isShowing=!1,this._startAnimation(!1,t,this._finishHide),this)},Vt.prototype.destroy=function(){if(this._isDestroyed)return this;var t=this._item,e=t._element,i=t.getGrid(),s=this._queue,n=i._settings;return this._stopAnimation({}),s.flush(!0,t).destroy(),Rt(e,n.itemVisibleClass),Rt(e,n.itemHiddenClass),this._item=null,this._isHiding=this._isShowing=!1,this._isDestroyed=this._isHidden=!0,this},Vt.prototype._startAnimation=function(t,e,i){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,_=(t?r.showEasing:r.hideEasing)||"ease",d=e||h<=0;if(o){if(B(n._id),d)return n._animateChild.isAnimating()?n._animateChild.stop(o):f(n._child,o),void(i&&i());var c,u,p;c=n._id,u=function(){s=function(t,e){var i={};for(var s in e)i[s]=a(t,l(s));return i}(n._child,o)},p=function(){n._animateChild.start(s,o,{duration:h,easing:_,onFinish:i})},k.add(c+Y,u,p)}else i&&i()}},Vt.prototype._stopAnimation=function(t){if(!this._isDestroyed){var e=this._item;B(e._id),e._animateChild.stop(t)}},Vt.prototype._finishShow=function(){this._isHidden||(this._isShowing=!1,this._queue.flush(!1,this._item))},Vt.prototype._finishHide=(qt={transform:xt(0,0)},function(){if(this._isHidden){var t=this._item;this._isHiding=!1,t._layout.stop(!0,qt),t._element.style.display="none",this._queue.flush(!1,t)}});var Wt,jt,Ut,Zt,$t=0;function Jt(){return++$t}function Kt(t,e,i){var s=t._settings;this._id=Jt(),this._gridId=t._id,this._isDestroyed=!1,this._left=0,this._top=0,this._element=e,this._child=e.children[0],e.parentNode!==t._element&&t._element.appendChild(e),j(e,s.itemClass),"boolean"!=typeof i&&(i="none"!==a(e,"display")),this._isActive=i,e.style.left="0",e.style.top="0",e.style[n]=xt(0,0),this._animate=new p(e),this._animateChild=new p(this._child),this._visibility=new Vt(this),this._layout=new Ht(this),this._migrate=new Nt(this),this._release=new zt(this),this._dragPlaceholder=new Ot(this),this._drag=s.dragEnabled?new Xt(this):null,this._refreshDimensions(),this._refreshSortData()}function Qt(){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)}Kt.prototype.getGrid=function(){return t[this._gridId]},Kt.prototype.getElement=function(){return this._element},Kt.prototype.getWidth=function(){return this._width},Kt.prototype.getHeight=function(){return this._height},Kt.prototype.getMargin=function(){return{left:this._marginLeft,right:this._marginRight,top:this._marginTop,bottom:this._marginBottom}},Kt.prototype.getPosition=function(){return{left:this._left,top:this._top}},Kt.prototype.isActive=function(){return this._isActive},Kt.prototype.isVisible=function(){return!!this._visibility&&!this._visibility._isHidden},Kt.prototype.isShowing=function(){return!(!this._visibility||!this._visibility._isShowing)},Kt.prototype.isHiding=function(){return!(!this._visibility||!this._visibility._isHiding)},Kt.prototype.isPositioning=function(){return!(!this._layout||!this._layout._isActive)},Kt.prototype.isDragging=function(){return!(!this._drag||!this._drag._isActive)},Kt.prototype.isReleasing=function(){return!(!this._release||!this._release._isActive)},Kt.prototype.isDestroyed=function(){return this._isDestroyed},Kt.prototype._refreshDimensions=function(){if(!this._isDestroyed&&!this._visibility._isHidden){var t=this._element,e=this._dragPlaceholder,i=t.getBoundingClientRect();this._width=i.width,this._height=i.height,this._marginLeft=Math.max(0,ht(t,"margin-left")),this._marginRight=Math.max(0,ht(t,"margin-right")),this._marginTop=Math.max(0,ht(t,"margin-top")),this._marginBottom=Math.max(0,ht(t,"margin-bottom")),e&&e.updateDimensions(this._width,this._height)}},Kt.prototype._refreshSortData=function(){if(!this._isDestroyed){var t,e=this._sortData={},i=this.getGrid()._settings.sortData;for(t in i)e[t]=i[t](this,this._element)}},Kt.prototype._destroy=function(t){if(!this._isDestroyed){var e=this._element,i=this.getGrid(),s=i._settings,n=i._items.indexOf(this);this._release.destroy(),this._migrate.destroy(),this._layout.destroy(),this._visibility.destroy(),this._animate.destroy(),this._animateChild.destroy(),this._dragPlaceholder.destroy(),this._drag&&this._drag.destroy(),e.removeAttribute("style"),this._child.removeAttribute("style"),Rt(e,s.itemClass),n>-1&&i._items.splice(n,1),t&&e.parentNode.removeChild(e),this._isActive=!1,this._isDestroyed=!0}},Qt.prototype.getLayout=function(t,e,i,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),c=this._slotSizes;if(o.slots=s||this._slots,o.width=a?0:d?Math.round(e):e,o.height=a?d?Math.round(i):i:0,o.setWidth=a,o.setHeight=!a,o.slots.length=0,c.length=0,!t.length)return o;for(r=0;rd.height&&(Wt.left>0&&u.push(this._addRect(0,d.height,Wt.left,1/0)),Wt.left+Wt.widthd.width&&(Wt.top>0&&u.push(this._addRect(d.width,0,1/0,Wt.top)),Wt.top+Wt.height.49&&r.height>.49&&(!e&&r.tope.left+e.width&&jt.push(this._addRect(e.left+e.width,t.top,t.left+t.width-(e.left+e.width),t.height)),t.tope.top+e.height&&jt.push(this._addRect(t.left,e.top+e.height,t.width,t.top+t.height-(e.top+e.height))),jt):(jt.push(this._addRect(t.left,t.top,t.width,t.height)),jt)}),Qt.prototype._doRectsOverlap=function(t,e){return!(t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top)},Qt.prototype._isRectWithinRect=function(t,e){return t.left>=e.left&&t.top>=e.top&&t.left+t.width<=e.left+e.width&&t.top+t.height<=e.top+e.height},Qt.prototype._purgeRects=(Ut={},Zt={},function(t){for(var e,i=t.length;i--;)if(e=t.length,t[i])for(this._getRect(t[i],Ut);e--;)if(t[e]&&i!==e&&this._isRectWithinRect(Ut,this._getRect(t[e],Zt))){t[i]=0;break}return t}),Qt.prototype._sortRectsTopLeft=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.tope.top?1:t.lefte.left?1:0}}(),Qt.prototype._sortRectsLeftTop=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.lefte.left?1:t.tope.top?1:0}}();var te="[object HTMLCollection]",ee="[object NodeList]";function ie(t){var e=Object.prototype.toString.call(t);return e===te||e===ee}var se="object",ne="[object Object]",re=Object.prototype.toString;function oe(t){return typeof t===se&&re.call(t)===ne}function he(t){return ie(t)?Array.prototype.slice.call(t):Array.prototype.concat(t)}var ae=new Qt,_e=function(){},le="number",de="string";function ce(e,s){var n,r,o=this;if(typeof e===de&&(e=window.document.querySelector(e)),this._element=e,!(e.getRootNode?e.getRootNode({composed:!0})===document:window.document.body.contains(e))||e===window.document.documentElement)throw new Error("Container element must be an existing DOM element");c((n=this._settings=ue(ce.defaultOptions,s)).dragSort)||(n.dragSort=!!n.dragSort),this._id=Jt(),t[this._id]=o,this._isDestroyed=!1,this._layout={id:0,items:[],slots:[],setWidth:!1,setHeight:!1,width:0,height:0},this._emitter=new i,j(e,n.containerClass),this._items=[],typeof(r=n.items)===de?he(e.children).forEach(function(t){("*"===r||W(t,r))&&o._items.push(new Kt(o,t))}):(Array.isArray(r)||ie(r))&&(this._items=he(r).map(function(t){return new Kt(o,t)})),pe(this,n.layoutOnResize),n.layoutOnInit&&this.layout(!0)}function ue(t,e){var i=fe({},t);return e&&(i=fe(i,e)),i.visibleStyles=(e||0).visibleStyles||(t||0).visibleStyles,i.hiddenStyles=(e||0).hiddenStyles||(t||0).hiddenStyles,i}function fe(t,e){var i,s,n,r=Object.keys(e),o=r.length;for(n=0;n=0&&(t._resizeHandler=nt(function(){t.refreshItems().layout()},e),window.addEventListener("resize",t._resizeHandler))}function me(t){t._resizeHandler&&(t._resizeHandler("cancel"),window.removeEventListener("resize",t._resizeHandler),t._resizeHandler=null)}return ce.Item=Kt,ce.ItemLayout=Ht,ce.ItemVisibility=Vt,ce.ItemMigrate=Nt,ce.ItemAnimate=p,ce.ItemDrag=Xt,ce.ItemRelease=zt,ce.ItemDragPlaceholder=Ot,ce.Emitter=i,ce.Dragger=M,ce.Packer=Qt,ce.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,dragSortHeuristics:{sortInterval:100,minDragDistance:10,minBounceBackAngle:1},dragSortPredicate:{threshold:50,action:"move",migrateAction:"move"},dragReleaseDuration:300,dragReleaseEasing:"ease",dragCssProps:{touchAction:"none",userSelect:"none",userDrag:"none",tapHighlightColor:"rgba(0, 0, 0, 0)",touchCallout:"none",contentZooming:"none"},dragPlaceholder:{enabled:!1,duration:300,easing:"ease",createElement:null,onCreate:null,onRemove:null},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",itemPlaceholderClass:"muuri-item-placeholder"},ce.prototype.on=function(t,e){return this._emitter.on(t,e),this},ce.prototype.off=function(t,e){return this._emitter.off(t,e),this},ce.prototype.getElement=function(){return this._element},ce.prototype.getItems=function(t){if(this._isDestroyed||!t&&0!==t)return this._items.slice(0);var e,i,s=[],n=he(t);for(i=0;i-1){if(r.dragEnabled&&!o.dragEnabled){for(this._settings=r,e=0;e-1&&r.dragEnabled&&o.dragEnabled)for(e=0;e-1&&r.containerClass!==o.containerClass&&(Rt(s,r.containerClass),j(s,o.containerClass)),n.indexOf("sortData")>-1)for(e=0;e-1&&(me(this),pe(this,o.layoutOnResize)),o},ce.prototype.refreshItems=function(t){if(this._isDestroyed)return this;var e,i=this.getItems(t);for(e=0;e0)){var s=o._layout.id!==l,n=c(t)?t:i;c(n)&&n(s,_.items.slice(0)),!s&&o._hasListeners(e)&&o._emit(e,_.items.slice(0))}}if((_.setHeight&&typeof _.height===le||_.setWidth&&typeof _.width===le)&&(s="border-box"===a(h,"box-sizing")),_.setHeight&&(typeof _.height===le?h.style.height=(s?_.height+this._borderTop+this._borderBottom:_.height)+"px":h.style.height=_.height),_.setWidth&&(typeof _.width===le?h.style.width=(s?_.width+this._borderLeft+this._borderRight:_.width)+"px":h.style.width=_.width),this._hasListeners("layoutStart")&&this._emit("layoutStart",_.items.slice(0)),!d)return f(),this;for(r=0;rl?1:0:ld?1:0)return c;return c||(s||(s=n(i)),c=r(o,h)),c}function h(o,h){var a=t(o,h);return e&&a&&(a=-a),a||(s||(s=n(i)),r(o,h))}return function(n,r){if(this._isDestroyed||this._items.length<2)return this;var a,_=this._items,l=r||0,d=l.layout?l.layout:void 0===l.layout;if(t=n,e=!!l.descending,i=_.slice(0),s=null,c(t))_.sort(h);else if(typeof t===de)t=n.trim().split(" ").map(function(t){return t.split(":")}),_.sort(o);else{if(!Array.isArray(t))return this;if(t.length!==_.length)throw new Error("[Muuri] sort reference items do not match with grid items.");for(a=0;a<_.length;a++){if(t.indexOf(_[a])<0)throw new Error("[Muuri] sort reference items do not match with grid items.");_[a]=t[a]}e&&_.reverse()}return this._hasListeners("sort")&&this._emit("sort",_.slice(0),i),d&&this.layout("instant"===d,c(d)?d:void 0),this}}(),ce.prototype.move=function(t,e,i){if(this._isDestroyed||this._items.length<2)return this;var s,n,r=this._items,o=i||0,h=o.layout?o.layout:void 0===o.layout,a="swap"===o.action,_=a?"swap":"move",l=this._getItem(t),d=this._getItem(e);return l&&d&&l!==d&&(s=r.indexOf(l),n=r.indexOf(d),a?Q(r,s,n):K(r,s,n),this._hasListeners("move")&&this._emit("move",{item:l,fromIndex:s,toIndex:n,action:_}),h&&this.layout("instant"===h,c(h)?h:void 0)),this},ce.prototype.send=function(t,e,i,s){if(this._isDestroyed||e._isDestroyed||this===e)return this;if(!(t=this._getItem(t)))return this;var n=s||0,r=n.appendTo||window.document.body,o=n.layoutSender?n.layoutSender:void 0===n.layoutSender,h=n.layoutReceiver?n.layoutReceiver:void 0===n.layoutReceiver;return t._migrate.start(e,i,r),t._migrate._isActive&&t._isActive&&(o&&this.layout("instant"===o,c(o)?o:void 0),h&&e.layout("instant"===h,c(h)?h:void 0)),this},ce.prototype.destroy=function(e){if(this._isDestroyed)return this;var i,s=this._element,n=this._items.slice(0);for(me(this),i=0;i-1?t:this._items.length+t]||null;if(t instanceof Kt)return t._gridId===this._id?t:null;for(var e=0;e Date: Sat, 3 Aug 2019 13:41:19 +0300 Subject: [PATCH 018/120] Wrap tempStyles inside IIFE. --- dist/muuri.js | 129 ++++++++++++++++++++-------------------- dist/muuri.min.js | 2 +- src/Item/ItemMigrate.js | 64 ++++++++++---------- src/Item/ItemRelease.js | 69 ++++++++++----------- 4 files changed, 133 insertions(+), 131 deletions(-) diff --git a/dist/muuri.js b/dist/muuri.js index 7bb69ae8..df479e3f 100644 --- a/dist/muuri.js +++ b/dist/muuri.js @@ -3796,8 +3796,6 @@ item._animate.start(this._currentStyles, this._targetStyles, this._animateOptions); }; - var tempStyles = {}; - /** * The migrate process handler constructor. * @@ -4012,40 +4010,42 @@ * - Optional current translateX and translateY styles. * @returns {ItemMigrate} */ - ItemMigrate.prototype.stop = function(abort, currentStyles) { - if (this._isDestroyed || !this._isActive) return this; + ItemMigrate.prototype.stop = (function() { + var tempStyles = {}; + return function(abort, currentStyles) { + if (this._isDestroyed || !this._isActive) return this; - var item = this._item; - var element = item._element; - var grid = item.getGrid(); - var gridElement = grid._element; - var translate; - - if (this._container !== gridElement) { - if (!currentStyles) { - if (abort) { - translate = getTranslate(element); - tempStyles.transform = getTranslateString( - translate.x - this._containerDiffX, - translate.y - this._containerDiffY - ); - } else { - tempStyles.transform = getTranslateString(item._left, item._top); + var item = this._item; + var element = item._element; + var grid = item.getGrid(); + var gridElement = grid._element; + var translate; + + if (this._container !== gridElement) { + if (!currentStyles) { + if (abort) { + translate = getTranslate(element); + tempStyles.transform = getTranslateString( + translate.x - this._containerDiffX, + translate.y - this._containerDiffY + ); + } else { + tempStyles.transform = getTranslateString(item._left, item._top); + } + currentStyles = tempStyles; } - currentStyles = tempStyles; + gridElement.appendChild(element); + setStyles(element, currentStyles); } - gridElement.appendChild(element); - setStyles(element, currentStyles); - } - - this._isActive = false; - this._container = null; - this._containerDiffX = 0; - this._containerDiffY = 0; - return this; - }; + this._isActive = false; + this._container = null; + this._containerDiffX = 0; + this._containerDiffY = 0; + return this; + }; + })(); /** * Destroy instance. * @@ -4061,8 +4061,6 @@ return this; }; - var tempStyles$1 = {}; - /** * The release process handler constructor. Although this might seem as proper * fit for the drag process this needs to be separated into it's own logic @@ -4128,42 +4126,45 @@ * - Optional current translateX and translateY styles. * @returns {ItemRelease} */ - ItemRelease.prototype.stop = function(abort, currentStyles) { - if (this._isDestroyed || !this._isActive) return this; - - var item = this._item; - var element = item._element; - var grid = item.getGrid(); - var container = grid._element; - var translate; - - // Reset data and remove releasing class name from the element. - this._reset(); + ItemRelease.prototype.stop = (function() { + var tempStyles = { transform: '' }; + return function(abort, currentStyles) { + if (this._isDestroyed || !this._isActive) return this; - // If the released element is outside the grid's container element put it - // back there and adjust position accordingly. - if (element.parentNode !== container) { - if (!currentStyles) { - if (abort) { - translate = getTranslate(element); - tempStyles$1.transform = getTranslateString( - translate.x - this._containerDiffX, - translate.y - this._containerDiffY - ); - } else { - tempStyles$1.transform = getTranslateString(item._left, item._top); + var item = this._item; + var element = item._element; + var grid = item.getGrid(); + var container = grid._element; + var translate; + + // Reset data and remove releasing class name from the element. + this._reset(); + + // If the released element is outside the grid's container element put it + // back there and adjust position accordingly. + if (element.parentNode !== container) { + if (!currentStyles) { + if (abort) { + translate = getTranslate(element); + tempStyles.transform = getTranslateString( + translate.x - this._containerDiffX, + translate.y - this._containerDiffY + ); + } else { + tempStyles.transform = getTranslateString(item._left, item._top); + } + currentStyles = tempStyles; } - currentStyles = tempStyles$1; + container.appendChild(element); + setStyles(element, currentStyles); } - container.appendChild(element); - setStyles(element, currentStyles); - } - // Emit dragReleaseEnd event. - if (!abort) grid._emit(eventDragReleaseEnd, item); + // Emit dragReleaseEnd event. + if (!abort) grid._emit(eventDragReleaseEnd, item); - return this; - }; + return this; + }; + })(); /** * Destroy instance. diff --git a/dist/muuri.min.js b/dist/muuri.min.js index 30703d7d..f8750d3c 100644 --- a/dist/muuri.min.js +++ b/dist/muuri.min.js @@ -14,4 +14,4 @@ * Copyright (c) 2018-present, Niklas Rämö * @license MIT */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Muuri=e()}(this,function(){"use strict";var t={},e="layoutEnd";function i(){this._events={},this._queue=[],this._counter=0,this._isDestroyed=!1}i.prototype.on=function(t,e){if(this._isDestroyed)return this;var i=this._events[t];return i||(i=this._events[t]=[]),i.push(e),this},i.prototype.off=function(t,e){if(this._isDestroyed)return this;var i=this._events[t];if(!i||!i.length)return this;if(!e)return i.length=0,this;for(var s=i.length;s--;)e===i[s]&&i.splice(s,1);return this},i.prototype.emit=function(t,e,i,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-1||(M._activeInstances.push(t),M._emitter.on(b,t._onMove),M._emitter.on(A,t._onCancel),M._emitter.on(D,t._onEnd),1===M._activeInstances.length&&M._bindListeners())},M._deactivateInstance=function(t){var e=M._activeInstances.indexOf(t);-1!==e&&(M._activeInstances.splice(e,1),M._emitter.off(b,t._onMove),M._emitter.off(A,t._onCancel),M._emitter.off(D,t._onEnd),M._activeInstances.length||M._unbindListeners())},M._bindListeners=function(){var t=M._events;window.addEventListener(t.move,M._onMove,R),window.addEventListener(t.end,M._onEnd,R),t.cancel&&window.addEventListener(t.cancel,M._onCancel,R)},M._unbindListeners=function(){var t=M._events;window.removeEventListener(t.move,M._onMove,R),window.removeEventListener(t.end,M._onEnd,R),t.cancel&&window.removeEventListener(t.cancel,M._onCancel,R)},M._getEventPointerId=function(t){return"number"==typeof t.pointerId?t.pointerId:t.changedTouches?t.changedTouches[0]?t.changedTouches[0].identifier:null:1},M._getTouchById=function(t,e){if("number"==typeof t.pointerId)return t.pointerId===e?t:null;if(t.changedTouches){for(var i=0;i-1&&(this._queue[n]=void 0),s?this._queue.unshift(t):this._queue.push(t),this._reads[t]=e,this._writes[t]=i,this._nextStep||(this._nextStep=y(this._step))},T.prototype.cancel=function(t){var e=this._queue.indexOf(t);e>-1&&(this._queue[e]=void 0,delete this._reads[t],delete this._writes[t])},T.prototype._step=function(){var t,e,i=this._queue,s=this._reads,n=this._writes,r=this._batch,o=this._batchReads,h=this._batchWrites,a=i.length;for(this._nextStep=null,e=0;en?n:e<0?Math.max(n+e+1,0):e}function K(t,e,i){if(!(t.length<2)){var s=J(t,e),n=J(t,i);s!==n&&t.splice(n,0,t.splice(s,1)[0])}}function Q(t,e,i){if(!(t.length<2)){var s,n=J(t,e),r=J(t,i);n!==r&&(s=t[n],t[n]=t[r],t[r]=s)}}var tt="cancel",et="finish",it="debounce",st=0;function nt(t,e){var i,s=++st+it;return e>0?function(n){void 0!==i&&(i=window.clearTimeout(i),k.cancel(s),n===et&&t()),n!==tt&&n!==et&&(i=window.setTimeout(function(){i=void 0,k.add(s,t,null,!0)},e))}:function(e){e!==tt&&t()}}function rt(t){var e=a(t,"transform");if(!e||"none"===e)return!1;var i=a(t,"display");return"inline"!==i&&"none"!==i}function ot(t){for(var e=window.document,i=t||e;i&&i!==e&&"static"===a(i,"position")&&!rt(i);)i=i.parentElement||e;return i}function ht(t,e){return parseFloat(a(t,e))||0}var at={},_t={},lt={};function dt(t,e){var i,s=e||{};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:(i=t.getBoundingClientRect(),s.left+=i.left,s.top+=i.top,s.left+=ht(t,"border-left-width"),s.top+=ht(t,"border-top-width"),s))}function ct(t,e,i){return lt.left=0,lt.top=0,t===e?lt:i&&(t=ot(t))===(e=ot(e))?lt:(dt(t,at),dt(e,_t),lt.left=_t.left-at.left,lt.top=_t.top-at.top,lt)}var ut="overflow",ft="overflow-x",pt="overflow-y",mt="auto",gt="scroll";function yt(t){var e=a(t,ut);return e===mt||e===gt||((e=a(t,ft))===mt||e===gt||((e=a(t,pt))===mt||e===gt))}function vt(t,e,i){for(var s=i||[],n=e?t:t.parentNode;n&&n!==document;)n.getRootNode&&n instanceof DocumentFragment?n=n.getRootNode().host:(yt(n)&&s.push(n),n=n.parentNode);return s.push(window),s}var wt={},St="transform",bt="none",Dt=/^matrix3d/,At=/([^,]*,){4}/,Et=/([^,]*,){12}/,Ct=/[^,]*,/;function Lt(t){wt.x=0,wt.y=0;var e=a(t,St);if(!e||e===bt)return wt;var i=Dt.test(e),s=e.replace(i?Et:At,""),n=s.replace(Ct,"");return wt.x=parseFloat(s)||0,wt.y=parseFloat(n)||0,wt}function xt(t,e){return"translateX("+t+"px) translateY("+e+"px)"}function Rt(t,e){t.classList?t.classList.remove(e):W(t,"."+e)&&(t.className=(" "+t.className+" ").replace(" "+e+" "," ").trim())}var It,Pt,Mt,Tt,kt=0;function Xt(t){var e=t._element,i=t.getGrid(),s=i._settings;this._item=t,this._gridId=i._id,this._isDestroyed=!1,this._isMigrating=!1,this._startPredicate=c(s.dragStartPredicate)?s.dragStartPredicate:Xt.defaultStartPredicate,this._startPredicateState=kt,this._startPredicateResult=void 0,this._hBlockedIndex=null,this._hX1=0,this._hX2=0,this._hY1=0,this._hY2=0,this._reset(),this._preStartCheck=this._preStartCheck.bind(this),this._preEndCheck=this._preEndCheck.bind(this),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);var n=s.dragSortHeuristics.sortInterval;this._checkOverlapDebounce=nt(this._checkOverlap,n),this._dragger=new M(e,s.dragCssProps),this._dragger.on("start",this._preStartCheck),this._dragger.on("move",this._preStartCheck),this._dragger.on("cancel",this._preEndCheck),this._dragger.on("end",this._preEndCheck)}function Yt(t,e){return t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top?0:(Math.min(t.left+t.width,e.left+e.width)-Math.max(t.left,e.left))*(Math.min(t.top+t.height,e.top+e.height)-Math.max(t.top,e.top))/(Math.min(t.width,e.width)*Math.min(t.height,e.height))*100}function Ot(t){this._item=t,this._animate=new p,this._element=null,this._className="",this._didMigrate=!1,this._resetAfterLayout=!1,this._currentLeft=0,this._currentTop=0,this._nextLeft=0,this._nextTop=0,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this),this._onLayoutStart=this._onLayoutStart.bind(this),this._onLayoutEnd=this._onLayoutEnd.bind(this),this._onReleaseEnd=this._onReleaseEnd.bind(this),this._onMigrate=this._onMigrate.bind(this)}function Gt(){this._queue=[],this._isDestroyed=!1}function Ht(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 Gt,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this)}Xt.defaultStartPredicate=function(t,e,i){var s=t._drag;if(!s._startPredicateData){var n=i||s._getGrid()._settings.dragStartPredicate||{};s._startPredicateData={distance:Math.max(n.distance,0)||0,delay:Math.max(n.delay,0)||0,handle:"string"==typeof n.handle&&n.handle}}var r=s._startPredicateData;if(!e.isFinal)return!(!r.handleElement&&(r.handleElement=s._getStartPredicateHandle(e),!r.handleElement))&&(r.delay&&(r.event=e,r.delayTimer||(r.delayTimer=window.setTimeout(function(){r.delay=0,s._resolveStartPredicate(r.event)&&(s._forceResolveStartPredicate(r.event),s._resetStartPredicate())},r.delay))),s._resolveStartPredicate(e));s._finishStartPredicate(e)},Xt.defaultSortPredicate=(It={},Pt={},Mt={},Tt=[],function(t,e){var i=t._drag,s=i._getGrid(),n=e&&"number"==typeof e.threshold?e.threshold:50,r=e&&"swap"===e.action?"swap":"move",o=e&&"swap"===e.migrateAction?"swap":"move";n=Math.min(Math.max(n,1),100),It.width=t._width,It.height=t._height,It.left=i._elementClientX,It.top=i._elementClientY;var h=function(t,e,i){var s,n,r,o,h=null,a=e._settings.dragSort,_=-1;if(!0===a?(Tt[0]=e,n=Tt):c(a)&&(n=a.call(e,t)),!n||!Array.isArray(n)||!n.length)return h;for(o=0;oi&&s>_&&(_=s,h=r));return Tt.length=0,h}(t,s,n);if(!h)return!1;var a,_,l,d=t.getGrid()!==h,u=0,f=0,p=0,m=-1,g=!1;for(h===s?(It.left=i._gridX+t._marginLeft,It.top=i._gridY+t._marginTop):(h._updateBorders(1,0,1,0),u=h._left+h._borderLeft,f=h._top+h._borderTop),l=0;lp&&(m=l,p=_));return d&&p=n&&(Mt.grid=h,Mt.index=m,Mt.action=d?o:r,Mt)}),Xt.prototype.stop=function(){var t=this._item,e=t._element,i=this._getGrid();return this._isActive?this._isMigrating?(this._finishMigration(),this):(N(t._id),q(t._id),this._unbindScrollListeners(),this._checkOverlapDebounce("cancel"),e.parentNode!==i._element&&(i._element.appendChild(e),e.style[n]=xt(this._gridX,this._gridY)),Rt(e,i._settings.itemDraggingClass),this._reset(),this):this},Xt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(),this._dragger.destroy(),this._isDestroyed=!0,this)},Xt.prototype._getGrid=function(){return t[this._gridId]||null},Xt.prototype._reset=function(){this._isActive=!1,this._container=null,this._containingBlock=null,this._dragEvent=null,this._scrollEvent=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},Xt.prototype._bindScrollListeners=function(){var t,e,i=this._getGrid()._element,s=this._container,n=this._scrollers;if(n.length=0,vt(this._item._element,!1,n),s!==i)for(vt(i,!0,t=[]),e=0;e=s&&t.pageX=n&&t.pageY3&&e.minBounceBackAngle>0;if(h||(this._hBlockedIndex=null),Math.abs(r)>i||Math.abs(o)>i){if(h){var a=Math.atan2(r,o),_=Math.atan2(this._hX2-this._hX1,this._hY2-this._hY1),l=Math.atan2(Math.sin(a-_),Math.cos(a-_));Math.abs(l)>e.minBounceBackAngle&&(this._hBlockedIndex=null)}return this._hX1=this._hX2,this._hY1=this._hY2,this._hX2=s,this._hY2=n,!0}return!1},Xt.prototype._resetStartPredicate=function(){var t=this._startPredicateData;t&&(t.delayTimer&&(t.delayTimer=window.clearTimeout(t.delayTimer)),this._startPredicateData=null)},Xt.prototype._checkOverlap=function(){if(this._isActive){var t,e,i,s,n,r,o,h,a=this._item,_=this._getGrid()._settings;(t=c(_.dragSortPredicate)?_.dragSortPredicate(a,this._dragEvent):Xt.defaultSortPredicate(a,_.dragSortPredicate))&&"number"==typeof t.index&&(h=(e=a.getGrid())!==(s=t.grid||e),i=e._items.indexOf(a),n=J(s._items,t.index,h),o="swap"===t.action?"swap":"move",(h||n!==this._hBlockedIndex)&&(h?(this._hBlockedIndex=null,r=s._items[n],e._hasListeners("beforeSend")&&e._emit("beforeSend",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("beforeReceive")&&s._emit("beforeReceive",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),a._gridId=s._id,this._isMigrating=a._gridId!==this._gridId,e._items.splice(i,1),$(s._items,a,n),a._sortData=null,e._hasListeners("send")&&e._emit("send",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("receive")&&s._emit("receive",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),"swap"===o&&r&&r.isActive()&&s._items.indexOf(r)>-1&&s.send(r,e,i,{appendTo:this._container||window.document.body,layoutSender:!1,layoutReceiver:!1}),e.layout(),s.layout()):i!==n&&(this._hBlockedIndex=i,("swap"===o?Q:K)(e._items,i,n),e._hasListeners("move")&&e._emit("move",{item:a,fromIndex:i,toIndex:n,action:o}),e.layout())))}},Xt.prototype._finishMigration=function(){var t,e,i=this._item,s=i._release,r=i._element,o=i._isActive,h=i.getGrid(),a=h._element,_=h._settings,l=_.dragContainer||a,d=this._getGrid()._settings,c=r.parentNode;this._isMigrating=!1,this.destroy(),Rt(r,d.itemClass),Rt(r,d.itemVisibleClass),Rt(r,d.itemHiddenClass),j(r,_.itemClass),j(r,o?_.itemVisibleClass:_.itemHiddenClass),l!==c&&(l.appendChild(r),e=ct(c,l,!0),(t=Lt(r)).x-=e.left,t.y-=e.top),i._refreshDimensions(),i._refreshSortData(),e=ct(l,a,!0),s._containerDiffX=e.left,s._containerDiffY=e.top,i._drag=_.dragEnabled?new Xt(i):null,l!==c&&(r.style[n]=xt(t.x,t.y)),i._child.removeAttribute("style"),f(i._child,o?_.visibleStyles:_.hiddenStyles),s.start()},Xt.prototype._preStartCheck=function(t){this._startPredicateState===kt&&(this._startPredicateState=1),1===this._startPredicateState?(this._startPredicateResult=this._startPredicate(this._item,t),!0===this._startPredicateResult?(this._startPredicateState=2,this._onStart(t)):!1===this._startPredicateResult&&(this._startPredicateState=3)):2===this._startPredicateState&&this._isActive&&this._onMove(t)},Xt.prototype._preEndCheck=function(t){var e=2===this._startPredicateState;this._startPredicate(this._item,t),this._startPredicateState=kt,e&&this._isActive&&this._onEnd(t)},Xt.prototype._onStart=function(t){var e=this._item;if(e._isActive){var i,s=e._element,r=this._getGrid(),o=r._settings,h=e._release,a=e._migrate,_=r._element,l=o.dragContainer||_,d=ot(l),c=Lt(s),u=c.x,f=c.y,p=s.getBoundingClientRect(),m=l!==_;this._resetHeuristics(t),m&&(i=ct(d,_)),e.isPositioning()&&e._layout.stop(!0,{transform:xt(u,f)}),a._isActive&&(u-=a._containerDiffX,f-=a._containerDiffY,a.stop(!0,{transform:xt(u,f)})),e.isReleasing()&&h._reset(),this._isActive=!0,this._dragEvent=t,this._container=l,this._containingBlock=d,this._elementClientX=p.left,this._elementClientY=p.top,this._left=this._gridX=u,this._top=this._gridY=f,o.dragPlaceholder.enabled&&e._dragPlaceholder.create(),r._emit("dragInit",e,t),m&&(this._containerDiffX=i.left,this._containerDiffY=i.top,s.parentNode===l?(this._gridX=u-this._containerDiffX,this._gridY=f-this._containerDiffY):(this._left=u+this._containerDiffX,this._top=f+this._containerDiffY,l.appendChild(s),s.style[n]=xt(this._left,this._top))),j(s,o.itemDraggingClass),this._bindScrollListeners(),r._emit("dragStart",e,t)}},Xt.prototype._onMove=function(t){var e=this._item;if(e._isActive){var i,s,n,r=this._getGrid()._settings.dragAxis;if("y"!==r){var o=t.clientX-this._dragEvent.clientX;this._left+=o,this._gridX+=o,this._elementClientX+=o}if("x"!==r){var h=t.clientY-this._dragEvent.clientY;this._top+=h,this._gridY+=h,this._elementClientY+=h}this._dragEvent=t,i=e._id,s=this._prepareMove,n=this._applyMove,k.add(i+O,s,n,!0)}else this.stop()},Xt.prototype._prepareMove=function(){this._item._isActive&&this._getGrid()._settings.dragSort&&this._checkHeuristics(this._dragEvent)&&this._checkOverlapDebounce()},Xt.prototype._applyMove=function(){var t=this._item;t._isActive&&(t._element.style[n]=xt(this._left,this._top),this._getGrid()._emit("dragMove",t,this._dragEvent))},Xt.prototype._onScroll=function(t){var e,i,s,n=this._item;n._isActive?(this._scrollEvent=t,e=n._id,i=this._prepareScroll,s=this._applyScroll,k.add(e+G,i,s,!0)):this.stop()},Xt.prototype._prepareScroll=function(){var t=this._item;if(t._isActive){var e,i=t._element,s=this._getGrid(),n=s._settings,r=n.dragAxis,o=s._element,h=i.getBoundingClientRect(),a=this._elementClientX-h.left,_=this._elementClientY-h.top;this._container!==o&&(e=ct(this._containingBlock,o),this._containerDiffX=e.left,this._containerDiffY=e.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()}},Xt.prototype._applyScroll=function(){var t=this._item;t._isActive&&(t._element.style[n]=xt(this._left,this._top),this._getGrid()._emit("dragScroll",t,this._scrollEvent))},Xt.prototype._onEnd=function(t){var e=this._item,i=e._element,s=this._getGrid(),n=s._settings,r=e._release;e._isActive?(N(e._id),q(e._id),n.dragSort&&this._checkOverlapDebounce("finish"),this._unbindScrollListeners(),r._containerDiffX=this._containerDiffX,r._containerDiffY=this._containerDiffY,this._reset(),Rt(i,n.itemDraggingClass),s._emit("dragEnd",e,t),this._isMigrating?this._finishMigration():r.start()):this.stop()},Ot.prototype._onLayoutStart=function(){var t=this._item,e=t.getGrid(),i=e._items.indexOf(t),s=e._layout.slots[2*i],n=e._layout.slots[2*i+1];if(this._didMigrate||t._left!==s||t._top!==n){var r,o,h;if(s+=t._marginLeft,n+=t._marginTop,!(e._settings.dragPlaceholder.duration>0)||this._didMigrate){F(t._id);var a={transform:xt(s,n)};return this._animate.isAnimating()?this._animate.stop(a):f(this._element,a),void(this._didMigrate&&(e.getElement().appendChild(this._element),this._didMigrate=!1))}this._nextLeft=s,this._nextTop=n,r=t._id,o=this._setupAnimation,h=this._startAnimation,k.add(r+H,o,h)}},Ot.prototype._setupAnimation=function(){if(this.isActive()){var t=Lt(this._element);this._currentLeft=t.x,this._currentTop=t.y}},Ot.prototype._startAnimation=function(){if(this.isActive()){var t=this._animate,e=this._currentLeft,i=this._currentTop,s=this._nextLeft,n=this._nextTop,r={transform:xt(s,n)};if(e!==s||i!==n){var o=this._item.getGrid()._settings.dragPlaceholder,h={transform:xt(e,i)};t.start(h,r,{duration:o.duration,easing:o.easing,onFinish:this._onLayoutEnd})}else t.isAnimating()&&t.stop(r)}},Ot.prototype._onLayoutEnd=function(){this._resetAfterLayout&&this.reset()},Ot.prototype._onReleaseEnd=function(t){if(t._id===this._item._id){if(!this._animate.isAnimating())return void this.reset();this._resetAfterLayout=!0}},Ot.prototype._onMigrate=function(t){if(t.item===this._item){var e=this._item.getGrid(),i=t.toGrid;e.off("dragReleaseEnd",this._onReleaseEnd),e.off("layoutStart",this._onLayoutStart),e.off("beforeSend",this._onMigrate),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("layoutStart",this._onLayoutStart),i.on("beforeSend",this._onMigrate),this._didMigrate=!0}},Ot.prototype.create=function(){if(this.isActive())this._resetAfterLayout=!1;else{var t,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;t=c(s.dragPlaceholder.createElement)?s.dragPlaceholder.createElement(e):window.document.createElement("div"),this._element=t,n._element=t,this._className=s.itemPlaceholderClass||"",this._className&&j(t,this._className);var r=e._left+e._marginLeft,o=e._top+e._marginTop;f(t,{display:"block",position:"absolute",left:"0",top:"0",width:e._width+"px",height:e._height+"px",transform:xt(r,o)}),i.on("layoutStart",this._onLayoutStart),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("beforeSend",this._onMigrate),c(s.dragPlaceholder.onCreate)&&s.dragPlaceholder.onCreate(e,t),i.getElement().appendChild(t)}},Ot.prototype.reset=function(){if(this.isActive()){var t=this._element,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;this._resetAfterLayout=!1,F(e._id),n.stop(),n._element=null,i.off("dragReleaseEnd",this._onReleaseEnd),i.off("layoutStart",this._onLayoutStart),i.off("beforeSend",this._onMigrate),this._className&&(Rt(t,this._className),this._className=""),t.parentNode.removeChild(t),this._element=null,c(s.dragPlaceholder.onRemove)&&s.dragPlaceholder.onRemove(e,t)}},Ot.prototype.updateDimensions=function(t,e){this.isActive()&&f(this._element,{width:t+"px",height:e+"px"})},Ot.prototype.isActive=function(){return!!this._element},Ot.prototype.destroy=function(){this.reset(),this._animate.destroy(),this._item=this._animate=null},Gt.prototype.add=function(t){return this._isDestroyed?this:(this._queue.push(t),this)},Gt.prototype.flush=function(t,e){if(this._isDestroyed)return this;var i,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,e),this;for(i=0;i0;return l&&this._queue.flush(!0,o),d&&(a._isPositioningStarted=!0),c(e)&&this._queue.add(e),m?(this._isActive=!0,this._animateOptions.easing=p,this._animateOptions.duration=u,this._isInterrupted=l,s=o._id,n=this._setupAnimation,r=this._startAnimation,k.add(s+X,n,r),this):(this._updateOffsets(),this._updateTargetStyles(),i=o._animate.isAnimating(),this.stop(!1,this._targetStyles),!i&&f(h,this._targetStyles),this._skipNextAnimation=!1,this._finish())}},Ht.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item;return i=s._id,k.cancel(i+X),s._animate.stop(e),Rt(s._element,s.getGrid()._settings.itemPositioningClass),this._isActive=!1,t&&this._queue.flush(!0,s),this},Ht.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)},Ht.prototype._updateOffsets=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._offsetLeft=i._isActive?i._containerDiffX:e._isActive?e._containerDiffX:0,this._offsetTop=i._isActive?i._containerDiffY:e._isActive?e._containerDiffY:0}},Ht.prototype._updateTargetStyles=function(){this._isDestroyed||(this._targetStyles.transform=xt(this._item._left+this._offsetLeft,this._item._top+this._offsetTop))},Ht.prototype._finish=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._isActive&&(this._isActive=!1,Rt(t._element,t.getGrid()._settings.itemPositioningClass)),i._isActive&&i.stop(),e._isActive&&e.stop(),this._queue.flush(!1,t)}},Ht.prototype._setupAnimation=function(){var t=Lt(this._item._element);this._currentLeft=t.x,this._currentTop=t.y},Ht.prototype._startAnimation=function(){var t=this._item,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||j(t._element,e.itemPositioningClass),this._currentStyles.transform=xt(this._currentLeft,this._currentTop),t._animate.start(this._currentStyles,this._targetStyles,this._animateOptions)};var Bt={};function Nt(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._container=!1,this._containerDiffX=0,this._containerDiffY=0}Nt.prototype.start=function(t,e,i){if(this._isDestroyed)return this;var s,r,o,h,a,_,l,d,c=this._item,u=c._element,p=c.isVisible(),m=c.getGrid(),g=m._settings,y=t._settings,v=t._element,w=t._items,S=m._items.indexOf(c),b=i||window.document.body;if("number"==typeof e)s=J(w,e,!0);else{if(!(r=t._getItem(e)))return this;s=w.indexOf(r)}return(c.isPositioning()||this._isActive||c.isReleasing())&&(l=(_=Lt(u)).x,d=_.y),c.isPositioning()&&c._layout.stop(!0,{transform:xt(l,d)}),this._isActive&&(l-=this._containerDiffX,d-=this._containerDiffY,this.stop(!0,{transform:xt(l,d)})),c.isReleasing()&&(l-=c._release._containerDiffX,d-=c._release._containerDiffY,c._release.stop(!0,{transform:xt(l,d)})),c._visibility._stopAnimation(),c._drag&&c._drag.destroy(),c._visibility._queue.flush(!0,c),m._hasListeners("beforeSend")&&m._emit("beforeSend",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("beforeReceive")&&t._emit("beforeReceive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),Rt(u,g.itemClass),Rt(u,g.itemVisibleClass),Rt(u,g.itemHiddenClass),j(u,y.itemClass),j(u,p?y.itemVisibleClass:y.itemHiddenClass),m._items.splice(S,1),$(w,c,s),c._gridId=t._id,b!==(o=u.parentNode)&&(b.appendChild(u),h=ct(b,o,!0),_||(l=(_=Lt(u)).x,d=_.y),u.style[n]=xt(l+h.left,d+h.top)),c._child.removeAttribute("style"),f(c._child,p?y.visibleStyles:y.hiddenStyles),u.style.display=p?"block":"hidden",a=ct(b,v,!0),c._refreshDimensions(),c._refreshSortData(),c._drag=y.dragEnabled?new Xt(c):null,this._isActive=!0,this._container=b,this._containerDiffX=a.left,this._containerDiffY=a.top,m._hasListeners("send")&&m._emit("send",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("receive")&&t._emit("receive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),this},Nt.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid()._element;return this._container!==r&&(e||(t?(i=Lt(n),Bt.transform=xt(i.x-this._containerDiffX,i.y-this._containerDiffY)):Bt.transform=xt(s._left,s._top),e=Bt),r.appendChild(n),f(n,e)),this._isActive=!1,this._container=null,this._containerDiffX=0,this._containerDiffY=0,this},Nt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)};var qt,Ft={};function zt(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0}function Vt(t){var e=t._isActive,i=t._element,s=t.getGrid()._settings;this._item=t,this._isDestroyed=!1,this._isHidden=!e,this._isHiding=!1,this._isShowing=!1,this._queue=new Gt,this._finishShow=this._finishShow.bind(this),this._finishHide=this._finishHide.bind(this),i.style.display=e?"block":"none",j(i,e?s.itemVisibleClass:s.itemHiddenClass),f(t._child,e?s.visibleStyles:s.hiddenStyles)}zt.prototype.start=function(){if(this._isDestroyed||this._isActive)return this;var t=this._item,e=t.getGrid();return this._isActive=!0,j(t._element,e._settings.itemReleasingClass),e._emit("dragReleaseStart",t),t._layout.start(!1),this},zt.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid(),o=r._element;return this._reset(),n.parentNode!==o&&(e||(t?(i=Lt(n),Ft.transform=xt(i.x-this._containerDiffX,i.y-this._containerDiffY)):Ft.transform=xt(s._left,s._top),e=Ft),o.appendChild(n),f(n,e)),t||r._emit("dragReleaseEnd",s),this},zt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)},zt.prototype._reset=function(){if(!this._isDestroyed){var t=this._item;this._isActive=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0,Rt(t._element,t.getGrid()._settings.itemReleasingClass)}},Vt.prototype.show=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return this._isShowing||this._isHidden?this._isShowing&&!t?(r&&n.add(r),this):(this._isShowing||(n.flush(!0,i),Rt(s,o.itemHiddenClass),j(s,o.itemVisibleClass),this._isHiding||(s.style.display="block")),r&&n.add(r),i._isActive=this._isShowing=!0,this._isHiding=this._isHidden=!1,this._startAnimation(!0,t,this._finishShow),this):(r&&r(!1,i),this)},Vt.prototype.hide=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return!this._isHiding&&this._isHidden?(r&&r(!1,i),this):this._isHiding&&!t?(r&&n.add(r),this):(this._isHiding||(n.flush(!0,i),j(s,o.itemHiddenClass),Rt(s,o.itemVisibleClass)),r&&n.add(r),this._isHidden=this._isHiding=!0,i._isActive=this._isShowing=!1,this._startAnimation(!1,t,this._finishHide),this)},Vt.prototype.destroy=function(){if(this._isDestroyed)return this;var t=this._item,e=t._element,i=t.getGrid(),s=this._queue,n=i._settings;return this._stopAnimation({}),s.flush(!0,t).destroy(),Rt(e,n.itemVisibleClass),Rt(e,n.itemHiddenClass),this._item=null,this._isHiding=this._isShowing=!1,this._isDestroyed=this._isHidden=!0,this},Vt.prototype._startAnimation=function(t,e,i){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,_=(t?r.showEasing:r.hideEasing)||"ease",d=e||h<=0;if(o){if(B(n._id),d)return n._animateChild.isAnimating()?n._animateChild.stop(o):f(n._child,o),void(i&&i());var c,u,p;c=n._id,u=function(){s=function(t,e){var i={};for(var s in e)i[s]=a(t,l(s));return i}(n._child,o)},p=function(){n._animateChild.start(s,o,{duration:h,easing:_,onFinish:i})},k.add(c+Y,u,p)}else i&&i()}},Vt.prototype._stopAnimation=function(t){if(!this._isDestroyed){var e=this._item;B(e._id),e._animateChild.stop(t)}},Vt.prototype._finishShow=function(){this._isHidden||(this._isShowing=!1,this._queue.flush(!1,this._item))},Vt.prototype._finishHide=(qt={transform:xt(0,0)},function(){if(this._isHidden){var t=this._item;this._isHiding=!1,t._layout.stop(!0,qt),t._element.style.display="none",this._queue.flush(!1,t)}});var Wt,jt,Ut,Zt,$t=0;function Jt(){return++$t}function Kt(t,e,i){var s=t._settings;this._id=Jt(),this._gridId=t._id,this._isDestroyed=!1,this._left=0,this._top=0,this._element=e,this._child=e.children[0],e.parentNode!==t._element&&t._element.appendChild(e),j(e,s.itemClass),"boolean"!=typeof i&&(i="none"!==a(e,"display")),this._isActive=i,e.style.left="0",e.style.top="0",e.style[n]=xt(0,0),this._animate=new p(e),this._animateChild=new p(this._child),this._visibility=new Vt(this),this._layout=new Ht(this),this._migrate=new Nt(this),this._release=new zt(this),this._dragPlaceholder=new Ot(this),this._drag=s.dragEnabled?new Xt(this):null,this._refreshDimensions(),this._refreshSortData()}function Qt(){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)}Kt.prototype.getGrid=function(){return t[this._gridId]},Kt.prototype.getElement=function(){return this._element},Kt.prototype.getWidth=function(){return this._width},Kt.prototype.getHeight=function(){return this._height},Kt.prototype.getMargin=function(){return{left:this._marginLeft,right:this._marginRight,top:this._marginTop,bottom:this._marginBottom}},Kt.prototype.getPosition=function(){return{left:this._left,top:this._top}},Kt.prototype.isActive=function(){return this._isActive},Kt.prototype.isVisible=function(){return!!this._visibility&&!this._visibility._isHidden},Kt.prototype.isShowing=function(){return!(!this._visibility||!this._visibility._isShowing)},Kt.prototype.isHiding=function(){return!(!this._visibility||!this._visibility._isHiding)},Kt.prototype.isPositioning=function(){return!(!this._layout||!this._layout._isActive)},Kt.prototype.isDragging=function(){return!(!this._drag||!this._drag._isActive)},Kt.prototype.isReleasing=function(){return!(!this._release||!this._release._isActive)},Kt.prototype.isDestroyed=function(){return this._isDestroyed},Kt.prototype._refreshDimensions=function(){if(!this._isDestroyed&&!this._visibility._isHidden){var t=this._element,e=this._dragPlaceholder,i=t.getBoundingClientRect();this._width=i.width,this._height=i.height,this._marginLeft=Math.max(0,ht(t,"margin-left")),this._marginRight=Math.max(0,ht(t,"margin-right")),this._marginTop=Math.max(0,ht(t,"margin-top")),this._marginBottom=Math.max(0,ht(t,"margin-bottom")),e&&e.updateDimensions(this._width,this._height)}},Kt.prototype._refreshSortData=function(){if(!this._isDestroyed){var t,e=this._sortData={},i=this.getGrid()._settings.sortData;for(t in i)e[t]=i[t](this,this._element)}},Kt.prototype._destroy=function(t){if(!this._isDestroyed){var e=this._element,i=this.getGrid(),s=i._settings,n=i._items.indexOf(this);this._release.destroy(),this._migrate.destroy(),this._layout.destroy(),this._visibility.destroy(),this._animate.destroy(),this._animateChild.destroy(),this._dragPlaceholder.destroy(),this._drag&&this._drag.destroy(),e.removeAttribute("style"),this._child.removeAttribute("style"),Rt(e,s.itemClass),n>-1&&i._items.splice(n,1),t&&e.parentNode.removeChild(e),this._isActive=!1,this._isDestroyed=!0}},Qt.prototype.getLayout=function(t,e,i,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),c=this._slotSizes;if(o.slots=s||this._slots,o.width=a?0:d?Math.round(e):e,o.height=a?d?Math.round(i):i:0,o.setWidth=a,o.setHeight=!a,o.slots.length=0,c.length=0,!t.length)return o;for(r=0;rd.height&&(Wt.left>0&&u.push(this._addRect(0,d.height,Wt.left,1/0)),Wt.left+Wt.widthd.width&&(Wt.top>0&&u.push(this._addRect(d.width,0,1/0,Wt.top)),Wt.top+Wt.height.49&&r.height>.49&&(!e&&r.tope.left+e.width&&jt.push(this._addRect(e.left+e.width,t.top,t.left+t.width-(e.left+e.width),t.height)),t.tope.top+e.height&&jt.push(this._addRect(t.left,e.top+e.height,t.width,t.top+t.height-(e.top+e.height))),jt):(jt.push(this._addRect(t.left,t.top,t.width,t.height)),jt)}),Qt.prototype._doRectsOverlap=function(t,e){return!(t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top)},Qt.prototype._isRectWithinRect=function(t,e){return t.left>=e.left&&t.top>=e.top&&t.left+t.width<=e.left+e.width&&t.top+t.height<=e.top+e.height},Qt.prototype._purgeRects=(Ut={},Zt={},function(t){for(var e,i=t.length;i--;)if(e=t.length,t[i])for(this._getRect(t[i],Ut);e--;)if(t[e]&&i!==e&&this._isRectWithinRect(Ut,this._getRect(t[e],Zt))){t[i]=0;break}return t}),Qt.prototype._sortRectsTopLeft=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.tope.top?1:t.lefte.left?1:0}}(),Qt.prototype._sortRectsLeftTop=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.lefte.left?1:t.tope.top?1:0}}();var te="[object HTMLCollection]",ee="[object NodeList]";function ie(t){var e=Object.prototype.toString.call(t);return e===te||e===ee}var se="object",ne="[object Object]",re=Object.prototype.toString;function oe(t){return typeof t===se&&re.call(t)===ne}function he(t){return ie(t)?Array.prototype.slice.call(t):Array.prototype.concat(t)}var ae=new Qt,_e=function(){},le="number",de="string";function ce(e,s){var n,r,o=this;if(typeof e===de&&(e=window.document.querySelector(e)),this._element=e,!(e.getRootNode?e.getRootNode({composed:!0})===document:window.document.body.contains(e))||e===window.document.documentElement)throw new Error("Container element must be an existing DOM element");c((n=this._settings=ue(ce.defaultOptions,s)).dragSort)||(n.dragSort=!!n.dragSort),this._id=Jt(),t[this._id]=o,this._isDestroyed=!1,this._layout={id:0,items:[],slots:[],setWidth:!1,setHeight:!1,width:0,height:0},this._emitter=new i,j(e,n.containerClass),this._items=[],typeof(r=n.items)===de?he(e.children).forEach(function(t){("*"===r||W(t,r))&&o._items.push(new Kt(o,t))}):(Array.isArray(r)||ie(r))&&(this._items=he(r).map(function(t){return new Kt(o,t)})),pe(this,n.layoutOnResize),n.layoutOnInit&&this.layout(!0)}function ue(t,e){var i=fe({},t);return e&&(i=fe(i,e)),i.visibleStyles=(e||0).visibleStyles||(t||0).visibleStyles,i.hiddenStyles=(e||0).hiddenStyles||(t||0).hiddenStyles,i}function fe(t,e){var i,s,n,r=Object.keys(e),o=r.length;for(n=0;n=0&&(t._resizeHandler=nt(function(){t.refreshItems().layout()},e),window.addEventListener("resize",t._resizeHandler))}function me(t){t._resizeHandler&&(t._resizeHandler("cancel"),window.removeEventListener("resize",t._resizeHandler),t._resizeHandler=null)}return ce.Item=Kt,ce.ItemLayout=Ht,ce.ItemVisibility=Vt,ce.ItemMigrate=Nt,ce.ItemAnimate=p,ce.ItemDrag=Xt,ce.ItemRelease=zt,ce.ItemDragPlaceholder=Ot,ce.Emitter=i,ce.Dragger=M,ce.Packer=Qt,ce.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,dragSortHeuristics:{sortInterval:100,minDragDistance:10,minBounceBackAngle:1},dragSortPredicate:{threshold:50,action:"move",migrateAction:"move"},dragReleaseDuration:300,dragReleaseEasing:"ease",dragCssProps:{touchAction:"none",userSelect:"none",userDrag:"none",tapHighlightColor:"rgba(0, 0, 0, 0)",touchCallout:"none",contentZooming:"none"},dragPlaceholder:{enabled:!1,duration:300,easing:"ease",createElement:null,onCreate:null,onRemove:null},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",itemPlaceholderClass:"muuri-item-placeholder"},ce.prototype.on=function(t,e){return this._emitter.on(t,e),this},ce.prototype.off=function(t,e){return this._emitter.off(t,e),this},ce.prototype.getElement=function(){return this._element},ce.prototype.getItems=function(t){if(this._isDestroyed||!t&&0!==t)return this._items.slice(0);var e,i,s=[],n=he(t);for(i=0;i-1){if(r.dragEnabled&&!o.dragEnabled){for(this._settings=r,e=0;e-1&&r.dragEnabled&&o.dragEnabled)for(e=0;e-1&&r.containerClass!==o.containerClass&&(Rt(s,r.containerClass),j(s,o.containerClass)),n.indexOf("sortData")>-1)for(e=0;e-1&&(me(this),pe(this,o.layoutOnResize)),o},ce.prototype.refreshItems=function(t){if(this._isDestroyed)return this;var e,i=this.getItems(t);for(e=0;e0)){var s=o._layout.id!==l,n=c(t)?t:i;c(n)&&n(s,_.items.slice(0)),!s&&o._hasListeners(e)&&o._emit(e,_.items.slice(0))}}if((_.setHeight&&typeof _.height===le||_.setWidth&&typeof _.width===le)&&(s="border-box"===a(h,"box-sizing")),_.setHeight&&(typeof _.height===le?h.style.height=(s?_.height+this._borderTop+this._borderBottom:_.height)+"px":h.style.height=_.height),_.setWidth&&(typeof _.width===le?h.style.width=(s?_.width+this._borderLeft+this._borderRight:_.width)+"px":h.style.width=_.width),this._hasListeners("layoutStart")&&this._emit("layoutStart",_.items.slice(0)),!d)return f(),this;for(r=0;rl?1:0:ld?1:0)return c;return c||(s||(s=n(i)),c=r(o,h)),c}function h(o,h){var a=t(o,h);return e&&a&&(a=-a),a||(s||(s=n(i)),r(o,h))}return function(n,r){if(this._isDestroyed||this._items.length<2)return this;var a,_=this._items,l=r||0,d=l.layout?l.layout:void 0===l.layout;if(t=n,e=!!l.descending,i=_.slice(0),s=null,c(t))_.sort(h);else if(typeof t===de)t=n.trim().split(" ").map(function(t){return t.split(":")}),_.sort(o);else{if(!Array.isArray(t))return this;if(t.length!==_.length)throw new Error("[Muuri] sort reference items do not match with grid items.");for(a=0;a<_.length;a++){if(t.indexOf(_[a])<0)throw new Error("[Muuri] sort reference items do not match with grid items.");_[a]=t[a]}e&&_.reverse()}return this._hasListeners("sort")&&this._emit("sort",_.slice(0),i),d&&this.layout("instant"===d,c(d)?d:void 0),this}}(),ce.prototype.move=function(t,e,i){if(this._isDestroyed||this._items.length<2)return this;var s,n,r=this._items,o=i||0,h=o.layout?o.layout:void 0===o.layout,a="swap"===o.action,_=a?"swap":"move",l=this._getItem(t),d=this._getItem(e);return l&&d&&l!==d&&(s=r.indexOf(l),n=r.indexOf(d),a?Q(r,s,n):K(r,s,n),this._hasListeners("move")&&this._emit("move",{item:l,fromIndex:s,toIndex:n,action:_}),h&&this.layout("instant"===h,c(h)?h:void 0)),this},ce.prototype.send=function(t,e,i,s){if(this._isDestroyed||e._isDestroyed||this===e)return this;if(!(t=this._getItem(t)))return this;var n=s||0,r=n.appendTo||window.document.body,o=n.layoutSender?n.layoutSender:void 0===n.layoutSender,h=n.layoutReceiver?n.layoutReceiver:void 0===n.layoutReceiver;return t._migrate.start(e,i,r),t._migrate._isActive&&t._isActive&&(o&&this.layout("instant"===o,c(o)?o:void 0),h&&e.layout("instant"===h,c(h)?h:void 0)),this},ce.prototype.destroy=function(e){if(this._isDestroyed)return this;var i,s=this._element,n=this._items.slice(0);for(me(this),i=0;i-1?t:this._items.length+t]||null;if(t instanceof Kt)return t._gridId===this._id?t:null;for(var e=0;e-1||(M._activeInstances.push(t),M._emitter.on(b,t._onMove),M._emitter.on(A,t._onCancel),M._emitter.on(D,t._onEnd),1===M._activeInstances.length&&M._bindListeners())},M._deactivateInstance=function(t){var e=M._activeInstances.indexOf(t);-1!==e&&(M._activeInstances.splice(e,1),M._emitter.off(b,t._onMove),M._emitter.off(A,t._onCancel),M._emitter.off(D,t._onEnd),M._activeInstances.length||M._unbindListeners())},M._bindListeners=function(){var t=M._events;window.addEventListener(t.move,M._onMove,R),window.addEventListener(t.end,M._onEnd,R),t.cancel&&window.addEventListener(t.cancel,M._onCancel,R)},M._unbindListeners=function(){var t=M._events;window.removeEventListener(t.move,M._onMove,R),window.removeEventListener(t.end,M._onEnd,R),t.cancel&&window.removeEventListener(t.cancel,M._onCancel,R)},M._getEventPointerId=function(t){return"number"==typeof t.pointerId?t.pointerId:t.changedTouches?t.changedTouches[0]?t.changedTouches[0].identifier:null:1},M._getTouchById=function(t,e){if("number"==typeof t.pointerId)return t.pointerId===e?t:null;if(t.changedTouches){for(var i=0;i-1&&(this._queue[n]=void 0),s?this._queue.unshift(t):this._queue.push(t),this._reads[t]=e,this._writes[t]=i,this._nextStep||(this._nextStep=y(this._step))},T.prototype.cancel=function(t){var e=this._queue.indexOf(t);e>-1&&(this._queue[e]=void 0,delete this._reads[t],delete this._writes[t])},T.prototype._step=function(){var t,e,i=this._queue,s=this._reads,n=this._writes,r=this._batch,o=this._batchReads,h=this._batchWrites,a=i.length;for(this._nextStep=null,e=0;en?n:e<0?Math.max(n+e+1,0):e}function K(t,e,i){if(!(t.length<2)){var s=J(t,e),n=J(t,i);s!==n&&t.splice(n,0,t.splice(s,1)[0])}}function Q(t,e,i){if(!(t.length<2)){var s,n=J(t,e),r=J(t,i);n!==r&&(s=t[n],t[n]=t[r],t[r]=s)}}var tt="cancel",et="finish",it="debounce",st=0;function nt(t,e){var i,s=++st+it;return e>0?function(n){void 0!==i&&(i=window.clearTimeout(i),k.cancel(s),n===et&&t()),n!==tt&&n!==et&&(i=window.setTimeout(function(){i=void 0,k.add(s,t,null,!0)},e))}:function(e){e!==tt&&t()}}function rt(t){var e=a(t,"transform");if(!e||"none"===e)return!1;var i=a(t,"display");return"inline"!==i&&"none"!==i}function ot(t){for(var e=window.document,i=t||e;i&&i!==e&&"static"===a(i,"position")&&!rt(i);)i=i.parentElement||e;return i}function ht(t,e){return parseFloat(a(t,e))||0}var at={},_t={},lt={};function dt(t,e){var i,s=e||{};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:(i=t.getBoundingClientRect(),s.left+=i.left,s.top+=i.top,s.left+=ht(t,"border-left-width"),s.top+=ht(t,"border-top-width"),s))}function ct(t,e,i){return lt.left=0,lt.top=0,t===e?lt:i&&(t=ot(t))===(e=ot(e))?lt:(dt(t,at),dt(e,_t),lt.left=_t.left-at.left,lt.top=_t.top-at.top,lt)}var ut="overflow",ft="overflow-x",pt="overflow-y",mt="auto",gt="scroll";function yt(t){var e=a(t,ut);return e===mt||e===gt||((e=a(t,ft))===mt||e===gt||((e=a(t,pt))===mt||e===gt))}function vt(t,e,i){for(var s=i||[],n=e?t:t.parentNode;n&&n!==document;)n.getRootNode&&n instanceof DocumentFragment?n=n.getRootNode().host:(yt(n)&&s.push(n),n=n.parentNode);return s.push(window),s}var wt={},St="transform",bt="none",Dt=/^matrix3d/,At=/([^,]*,){4}/,Et=/([^,]*,){12}/,Ct=/[^,]*,/;function Lt(t){wt.x=0,wt.y=0;var e=a(t,St);if(!e||e===bt)return wt;var i=Dt.test(e),s=e.replace(i?Et:At,""),n=s.replace(Ct,"");return wt.x=parseFloat(s)||0,wt.y=parseFloat(n)||0,wt}function xt(t,e){return"translateX("+t+"px) translateY("+e+"px)"}function Rt(t,e){t.classList?t.classList.remove(e):W(t,"."+e)&&(t.className=(" "+t.className+" ").replace(" "+e+" "," ").trim())}var It,Pt,Mt,Tt,kt,Xt,Yt=0;function Ot(t){var e=t._element,i=t.getGrid(),s=i._settings;this._item=t,this._gridId=i._id,this._isDestroyed=!1,this._isMigrating=!1,this._startPredicate=c(s.dragStartPredicate)?s.dragStartPredicate:Ot.defaultStartPredicate,this._startPredicateState=Yt,this._startPredicateResult=void 0,this._hBlockedIndex=null,this._hX1=0,this._hX2=0,this._hY1=0,this._hY2=0,this._reset(),this._preStartCheck=this._preStartCheck.bind(this),this._preEndCheck=this._preEndCheck.bind(this),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);var n=s.dragSortHeuristics.sortInterval;this._checkOverlapDebounce=nt(this._checkOverlap,n),this._dragger=new M(e,s.dragCssProps),this._dragger.on("start",this._preStartCheck),this._dragger.on("move",this._preStartCheck),this._dragger.on("cancel",this._preEndCheck),this._dragger.on("end",this._preEndCheck)}function Gt(t,e){return t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top?0:(Math.min(t.left+t.width,e.left+e.width)-Math.max(t.left,e.left))*(Math.min(t.top+t.height,e.top+e.height)-Math.max(t.top,e.top))/(Math.min(t.width,e.width)*Math.min(t.height,e.height))*100}function Ht(t){this._item=t,this._animate=new p,this._element=null,this._className="",this._didMigrate=!1,this._resetAfterLayout=!1,this._currentLeft=0,this._currentTop=0,this._nextLeft=0,this._nextTop=0,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this),this._onLayoutStart=this._onLayoutStart.bind(this),this._onLayoutEnd=this._onLayoutEnd.bind(this),this._onReleaseEnd=this._onReleaseEnd.bind(this),this._onMigrate=this._onMigrate.bind(this)}function Bt(){this._queue=[],this._isDestroyed=!1}function Nt(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 Bt,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this)}function qt(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._container=!1,this._containerDiffX=0,this._containerDiffY=0}function Ft(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0}function zt(t){var e=t._isActive,i=t._element,s=t.getGrid()._settings;this._item=t,this._isDestroyed=!1,this._isHidden=!e,this._isHiding=!1,this._isShowing=!1,this._queue=new Bt,this._finishShow=this._finishShow.bind(this),this._finishHide=this._finishHide.bind(this),i.style.display=e?"block":"none",j(i,e?s.itemVisibleClass:s.itemHiddenClass),f(t._child,e?s.visibleStyles:s.hiddenStyles)}Ot.defaultStartPredicate=function(t,e,i){var s=t._drag;if(!s._startPredicateData){var n=i||s._getGrid()._settings.dragStartPredicate||{};s._startPredicateData={distance:Math.max(n.distance,0)||0,delay:Math.max(n.delay,0)||0,handle:"string"==typeof n.handle&&n.handle}}var r=s._startPredicateData;if(!e.isFinal)return!(!r.handleElement&&(r.handleElement=s._getStartPredicateHandle(e),!r.handleElement))&&(r.delay&&(r.event=e,r.delayTimer||(r.delayTimer=window.setTimeout(function(){r.delay=0,s._resolveStartPredicate(r.event)&&(s._forceResolveStartPredicate(r.event),s._resetStartPredicate())},r.delay))),s._resolveStartPredicate(e));s._finishStartPredicate(e)},Ot.defaultSortPredicate=(It={},Pt={},Mt={},Tt=[],function(t,e){var i=t._drag,s=i._getGrid(),n=e&&"number"==typeof e.threshold?e.threshold:50,r=e&&"swap"===e.action?"swap":"move",o=e&&"swap"===e.migrateAction?"swap":"move";n=Math.min(Math.max(n,1),100),It.width=t._width,It.height=t._height,It.left=i._elementClientX,It.top=i._elementClientY;var h=function(t,e,i){var s,n,r,o,h=null,a=e._settings.dragSort,_=-1;if(!0===a?(Tt[0]=e,n=Tt):c(a)&&(n=a.call(e,t)),!n||!Array.isArray(n)||!n.length)return h;for(o=0;oi&&s>_&&(_=s,h=r));return Tt.length=0,h}(t,s,n);if(!h)return!1;var a,_,l,d=t.getGrid()!==h,u=0,f=0,p=0,m=-1,g=!1;for(h===s?(It.left=i._gridX+t._marginLeft,It.top=i._gridY+t._marginTop):(h._updateBorders(1,0,1,0),u=h._left+h._borderLeft,f=h._top+h._borderTop),l=0;lp&&(m=l,p=_));return d&&p=n&&(Mt.grid=h,Mt.index=m,Mt.action=d?o:r,Mt)}),Ot.prototype.stop=function(){var t=this._item,e=t._element,i=this._getGrid();return this._isActive?this._isMigrating?(this._finishMigration(),this):(N(t._id),q(t._id),this._unbindScrollListeners(),this._checkOverlapDebounce("cancel"),e.parentNode!==i._element&&(i._element.appendChild(e),e.style[n]=xt(this._gridX,this._gridY)),Rt(e,i._settings.itemDraggingClass),this._reset(),this):this},Ot.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(),this._dragger.destroy(),this._isDestroyed=!0,this)},Ot.prototype._getGrid=function(){return t[this._gridId]||null},Ot.prototype._reset=function(){this._isActive=!1,this._container=null,this._containingBlock=null,this._dragEvent=null,this._scrollEvent=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},Ot.prototype._bindScrollListeners=function(){var t,e,i=this._getGrid()._element,s=this._container,n=this._scrollers;if(n.length=0,vt(this._item._element,!1,n),s!==i)for(vt(i,!0,t=[]),e=0;e=s&&t.pageX=n&&t.pageY3&&e.minBounceBackAngle>0;if(h||(this._hBlockedIndex=null),Math.abs(r)>i||Math.abs(o)>i){if(h){var a=Math.atan2(r,o),_=Math.atan2(this._hX2-this._hX1,this._hY2-this._hY1),l=Math.atan2(Math.sin(a-_),Math.cos(a-_));Math.abs(l)>e.minBounceBackAngle&&(this._hBlockedIndex=null)}return this._hX1=this._hX2,this._hY1=this._hY2,this._hX2=s,this._hY2=n,!0}return!1},Ot.prototype._resetStartPredicate=function(){var t=this._startPredicateData;t&&(t.delayTimer&&(t.delayTimer=window.clearTimeout(t.delayTimer)),this._startPredicateData=null)},Ot.prototype._checkOverlap=function(){if(this._isActive){var t,e,i,s,n,r,o,h,a=this._item,_=this._getGrid()._settings;(t=c(_.dragSortPredicate)?_.dragSortPredicate(a,this._dragEvent):Ot.defaultSortPredicate(a,_.dragSortPredicate))&&"number"==typeof t.index&&(h=(e=a.getGrid())!==(s=t.grid||e),i=e._items.indexOf(a),n=J(s._items,t.index,h),o="swap"===t.action?"swap":"move",(h||n!==this._hBlockedIndex)&&(h?(this._hBlockedIndex=null,r=s._items[n],e._hasListeners("beforeSend")&&e._emit("beforeSend",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("beforeReceive")&&s._emit("beforeReceive",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),a._gridId=s._id,this._isMigrating=a._gridId!==this._gridId,e._items.splice(i,1),$(s._items,a,n),a._sortData=null,e._hasListeners("send")&&e._emit("send",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("receive")&&s._emit("receive",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),"swap"===o&&r&&r.isActive()&&s._items.indexOf(r)>-1&&s.send(r,e,i,{appendTo:this._container||window.document.body,layoutSender:!1,layoutReceiver:!1}),e.layout(),s.layout()):i!==n&&(this._hBlockedIndex=i,("swap"===o?Q:K)(e._items,i,n),e._hasListeners("move")&&e._emit("move",{item:a,fromIndex:i,toIndex:n,action:o}),e.layout())))}},Ot.prototype._finishMigration=function(){var t,e,i=this._item,s=i._release,r=i._element,o=i._isActive,h=i.getGrid(),a=h._element,_=h._settings,l=_.dragContainer||a,d=this._getGrid()._settings,c=r.parentNode;this._isMigrating=!1,this.destroy(),Rt(r,d.itemClass),Rt(r,d.itemVisibleClass),Rt(r,d.itemHiddenClass),j(r,_.itemClass),j(r,o?_.itemVisibleClass:_.itemHiddenClass),l!==c&&(l.appendChild(r),e=ct(c,l,!0),(t=Lt(r)).x-=e.left,t.y-=e.top),i._refreshDimensions(),i._refreshSortData(),e=ct(l,a,!0),s._containerDiffX=e.left,s._containerDiffY=e.top,i._drag=_.dragEnabled?new Ot(i):null,l!==c&&(r.style[n]=xt(t.x,t.y)),i._child.removeAttribute("style"),f(i._child,o?_.visibleStyles:_.hiddenStyles),s.start()},Ot.prototype._preStartCheck=function(t){this._startPredicateState===Yt&&(this._startPredicateState=1),1===this._startPredicateState?(this._startPredicateResult=this._startPredicate(this._item,t),!0===this._startPredicateResult?(this._startPredicateState=2,this._onStart(t)):!1===this._startPredicateResult&&(this._startPredicateState=3)):2===this._startPredicateState&&this._isActive&&this._onMove(t)},Ot.prototype._preEndCheck=function(t){var e=2===this._startPredicateState;this._startPredicate(this._item,t),this._startPredicateState=Yt,e&&this._isActive&&this._onEnd(t)},Ot.prototype._onStart=function(t){var e=this._item;if(e._isActive){var i,s=e._element,r=this._getGrid(),o=r._settings,h=e._release,a=e._migrate,_=r._element,l=o.dragContainer||_,d=ot(l),c=Lt(s),u=c.x,f=c.y,p=s.getBoundingClientRect(),m=l!==_;this._resetHeuristics(t),m&&(i=ct(d,_)),e.isPositioning()&&e._layout.stop(!0,{transform:xt(u,f)}),a._isActive&&(u-=a._containerDiffX,f-=a._containerDiffY,a.stop(!0,{transform:xt(u,f)})),e.isReleasing()&&h._reset(),this._isActive=!0,this._dragEvent=t,this._container=l,this._containingBlock=d,this._elementClientX=p.left,this._elementClientY=p.top,this._left=this._gridX=u,this._top=this._gridY=f,o.dragPlaceholder.enabled&&e._dragPlaceholder.create(),r._emit("dragInit",e,t),m&&(this._containerDiffX=i.left,this._containerDiffY=i.top,s.parentNode===l?(this._gridX=u-this._containerDiffX,this._gridY=f-this._containerDiffY):(this._left=u+this._containerDiffX,this._top=f+this._containerDiffY,l.appendChild(s),s.style[n]=xt(this._left,this._top))),j(s,o.itemDraggingClass),this._bindScrollListeners(),r._emit("dragStart",e,t)}},Ot.prototype._onMove=function(t){var e=this._item;if(e._isActive){var i,s,n,r=this._getGrid()._settings.dragAxis;if("y"!==r){var o=t.clientX-this._dragEvent.clientX;this._left+=o,this._gridX+=o,this._elementClientX+=o}if("x"!==r){var h=t.clientY-this._dragEvent.clientY;this._top+=h,this._gridY+=h,this._elementClientY+=h}this._dragEvent=t,i=e._id,s=this._prepareMove,n=this._applyMove,k.add(i+O,s,n,!0)}else this.stop()},Ot.prototype._prepareMove=function(){this._item._isActive&&this._getGrid()._settings.dragSort&&this._checkHeuristics(this._dragEvent)&&this._checkOverlapDebounce()},Ot.prototype._applyMove=function(){var t=this._item;t._isActive&&(t._element.style[n]=xt(this._left,this._top),this._getGrid()._emit("dragMove",t,this._dragEvent))},Ot.prototype._onScroll=function(t){var e,i,s,n=this._item;n._isActive?(this._scrollEvent=t,e=n._id,i=this._prepareScroll,s=this._applyScroll,k.add(e+G,i,s,!0)):this.stop()},Ot.prototype._prepareScroll=function(){var t=this._item;if(t._isActive){var e,i=t._element,s=this._getGrid(),n=s._settings,r=n.dragAxis,o=s._element,h=i.getBoundingClientRect(),a=this._elementClientX-h.left,_=this._elementClientY-h.top;this._container!==o&&(e=ct(this._containingBlock,o),this._containerDiffX=e.left,this._containerDiffY=e.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()}},Ot.prototype._applyScroll=function(){var t=this._item;t._isActive&&(t._element.style[n]=xt(this._left,this._top),this._getGrid()._emit("dragScroll",t,this._scrollEvent))},Ot.prototype._onEnd=function(t){var e=this._item,i=e._element,s=this._getGrid(),n=s._settings,r=e._release;e._isActive?(N(e._id),q(e._id),n.dragSort&&this._checkOverlapDebounce("finish"),this._unbindScrollListeners(),r._containerDiffX=this._containerDiffX,r._containerDiffY=this._containerDiffY,this._reset(),Rt(i,n.itemDraggingClass),s._emit("dragEnd",e,t),this._isMigrating?this._finishMigration():r.start()):this.stop()},Ht.prototype._onLayoutStart=function(){var t=this._item,e=t.getGrid(),i=e._items.indexOf(t),s=e._layout.slots[2*i],n=e._layout.slots[2*i+1];if(this._didMigrate||t._left!==s||t._top!==n){var r,o,h;if(s+=t._marginLeft,n+=t._marginTop,!(e._settings.dragPlaceholder.duration>0)||this._didMigrate){F(t._id);var a={transform:xt(s,n)};return this._animate.isAnimating()?this._animate.stop(a):f(this._element,a),void(this._didMigrate&&(e.getElement().appendChild(this._element),this._didMigrate=!1))}this._nextLeft=s,this._nextTop=n,r=t._id,o=this._setupAnimation,h=this._startAnimation,k.add(r+H,o,h)}},Ht.prototype._setupAnimation=function(){if(this.isActive()){var t=Lt(this._element);this._currentLeft=t.x,this._currentTop=t.y}},Ht.prototype._startAnimation=function(){if(this.isActive()){var t=this._animate,e=this._currentLeft,i=this._currentTop,s=this._nextLeft,n=this._nextTop,r={transform:xt(s,n)};if(e!==s||i!==n){var o=this._item.getGrid()._settings.dragPlaceholder,h={transform:xt(e,i)};t.start(h,r,{duration:o.duration,easing:o.easing,onFinish:this._onLayoutEnd})}else t.isAnimating()&&t.stop(r)}},Ht.prototype._onLayoutEnd=function(){this._resetAfterLayout&&this.reset()},Ht.prototype._onReleaseEnd=function(t){if(t._id===this._item._id){if(!this._animate.isAnimating())return void this.reset();this._resetAfterLayout=!0}},Ht.prototype._onMigrate=function(t){if(t.item===this._item){var e=this._item.getGrid(),i=t.toGrid;e.off("dragReleaseEnd",this._onReleaseEnd),e.off("layoutStart",this._onLayoutStart),e.off("beforeSend",this._onMigrate),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("layoutStart",this._onLayoutStart),i.on("beforeSend",this._onMigrate),this._didMigrate=!0}},Ht.prototype.create=function(){if(this.isActive())this._resetAfterLayout=!1;else{var t,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;t=c(s.dragPlaceholder.createElement)?s.dragPlaceholder.createElement(e):window.document.createElement("div"),this._element=t,n._element=t,this._className=s.itemPlaceholderClass||"",this._className&&j(t,this._className);var r=e._left+e._marginLeft,o=e._top+e._marginTop;f(t,{display:"block",position:"absolute",left:"0",top:"0",width:e._width+"px",height:e._height+"px",transform:xt(r,o)}),i.on("layoutStart",this._onLayoutStart),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("beforeSend",this._onMigrate),c(s.dragPlaceholder.onCreate)&&s.dragPlaceholder.onCreate(e,t),i.getElement().appendChild(t)}},Ht.prototype.reset=function(){if(this.isActive()){var t=this._element,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;this._resetAfterLayout=!1,F(e._id),n.stop(),n._element=null,i.off("dragReleaseEnd",this._onReleaseEnd),i.off("layoutStart",this._onLayoutStart),i.off("beforeSend",this._onMigrate),this._className&&(Rt(t,this._className),this._className=""),t.parentNode.removeChild(t),this._element=null,c(s.dragPlaceholder.onRemove)&&s.dragPlaceholder.onRemove(e,t)}},Ht.prototype.updateDimensions=function(t,e){this.isActive()&&f(this._element,{width:t+"px",height:e+"px"})},Ht.prototype.isActive=function(){return!!this._element},Ht.prototype.destroy=function(){this.reset(),this._animate.destroy(),this._item=this._animate=null},Bt.prototype.add=function(t){return this._isDestroyed?this:(this._queue.push(t),this)},Bt.prototype.flush=function(t,e){if(this._isDestroyed)return this;var i,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,e),this;for(i=0;i0;return l&&this._queue.flush(!0,o),d&&(a._isPositioningStarted=!0),c(e)&&this._queue.add(e),m?(this._isActive=!0,this._animateOptions.easing=p,this._animateOptions.duration=u,this._isInterrupted=l,s=o._id,n=this._setupAnimation,r=this._startAnimation,k.add(s+X,n,r),this):(this._updateOffsets(),this._updateTargetStyles(),i=o._animate.isAnimating(),this.stop(!1,this._targetStyles),!i&&f(h,this._targetStyles),this._skipNextAnimation=!1,this._finish())}},Nt.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item;return i=s._id,k.cancel(i+X),s._animate.stop(e),Rt(s._element,s.getGrid()._settings.itemPositioningClass),this._isActive=!1,t&&this._queue.flush(!0,s),this},Nt.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)},Nt.prototype._updateOffsets=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._offsetLeft=i._isActive?i._containerDiffX:e._isActive?e._containerDiffX:0,this._offsetTop=i._isActive?i._containerDiffY:e._isActive?e._containerDiffY:0}},Nt.prototype._updateTargetStyles=function(){this._isDestroyed||(this._targetStyles.transform=xt(this._item._left+this._offsetLeft,this._item._top+this._offsetTop))},Nt.prototype._finish=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._isActive&&(this._isActive=!1,Rt(t._element,t.getGrid()._settings.itemPositioningClass)),i._isActive&&i.stop(),e._isActive&&e.stop(),this._queue.flush(!1,t)}},Nt.prototype._setupAnimation=function(){var t=Lt(this._item._element);this._currentLeft=t.x,this._currentTop=t.y},Nt.prototype._startAnimation=function(){var t=this._item,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||j(t._element,e.itemPositioningClass),this._currentStyles.transform=xt(this._currentLeft,this._currentTop),t._animate.start(this._currentStyles,this._targetStyles,this._animateOptions)},qt.prototype.start=function(t,e,i){if(this._isDestroyed)return this;var s,r,o,h,a,_,l,d,c=this._item,u=c._element,p=c.isVisible(),m=c.getGrid(),g=m._settings,y=t._settings,v=t._element,w=t._items,S=m._items.indexOf(c),b=i||window.document.body;if("number"==typeof e)s=J(w,e,!0);else{if(!(r=t._getItem(e)))return this;s=w.indexOf(r)}return(c.isPositioning()||this._isActive||c.isReleasing())&&(l=(_=Lt(u)).x,d=_.y),c.isPositioning()&&c._layout.stop(!0,{transform:xt(l,d)}),this._isActive&&(l-=this._containerDiffX,d-=this._containerDiffY,this.stop(!0,{transform:xt(l,d)})),c.isReleasing()&&(l-=c._release._containerDiffX,d-=c._release._containerDiffY,c._release.stop(!0,{transform:xt(l,d)})),c._visibility._stopAnimation(),c._drag&&c._drag.destroy(),c._visibility._queue.flush(!0,c),m._hasListeners("beforeSend")&&m._emit("beforeSend",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("beforeReceive")&&t._emit("beforeReceive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),Rt(u,g.itemClass),Rt(u,g.itemVisibleClass),Rt(u,g.itemHiddenClass),j(u,y.itemClass),j(u,p?y.itemVisibleClass:y.itemHiddenClass),m._items.splice(S,1),$(w,c,s),c._gridId=t._id,b!==(o=u.parentNode)&&(b.appendChild(u),h=ct(b,o,!0),_||(l=(_=Lt(u)).x,d=_.y),u.style[n]=xt(l+h.left,d+h.top)),c._child.removeAttribute("style"),f(c._child,p?y.visibleStyles:y.hiddenStyles),u.style.display=p?"block":"hidden",a=ct(b,v,!0),c._refreshDimensions(),c._refreshSortData(),c._drag=y.dragEnabled?new Ot(c):null,this._isActive=!0,this._container=b,this._containerDiffX=a.left,this._containerDiffY=a.top,m._hasListeners("send")&&m._emit("send",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("receive")&&t._emit("receive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),this},qt.prototype.stop=(kt={},function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid()._element;return this._container!==r&&(e||(t?(i=Lt(n),kt.transform=xt(i.x-this._containerDiffX,i.y-this._containerDiffY)):kt.transform=xt(s._left,s._top),e=kt),r.appendChild(n),f(n,e)),this._isActive=!1,this._container=null,this._containerDiffX=0,this._containerDiffY=0,this}),qt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)},Ft.prototype.start=function(){if(this._isDestroyed||this._isActive)return this;var t=this._item,e=t.getGrid();return this._isActive=!0,j(t._element,e._settings.itemReleasingClass),e._emit("dragReleaseStart",t),t._layout.start(!1),this},Ft.prototype.stop=function(){var t={transform:""};return function(e,i){if(this._isDestroyed||!this._isActive)return this;var s,n=this._item,r=n._element,o=n.getGrid(),h=o._element;return this._reset(),r.parentNode!==h&&(i||(e?(s=Lt(r),t.transform=xt(s.x-this._containerDiffX,s.y-this._containerDiffY)):t.transform=xt(n._left,n._top),i=t),h.appendChild(r),f(r,i)),e||o._emit("dragReleaseEnd",n),this}}(),Ft.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)},Ft.prototype._reset=function(){if(!this._isDestroyed){var t=this._item;this._isActive=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0,Rt(t._element,t.getGrid()._settings.itemReleasingClass)}},zt.prototype.show=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return this._isShowing||this._isHidden?this._isShowing&&!t?(r&&n.add(r),this):(this._isShowing||(n.flush(!0,i),Rt(s,o.itemHiddenClass),j(s,o.itemVisibleClass),this._isHiding||(s.style.display="block")),r&&n.add(r),i._isActive=this._isShowing=!0,this._isHiding=this._isHidden=!1,this._startAnimation(!0,t,this._finishShow),this):(r&&r(!1,i),this)},zt.prototype.hide=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return!this._isHiding&&this._isHidden?(r&&r(!1,i),this):this._isHiding&&!t?(r&&n.add(r),this):(this._isHiding||(n.flush(!0,i),j(s,o.itemHiddenClass),Rt(s,o.itemVisibleClass)),r&&n.add(r),this._isHidden=this._isHiding=!0,i._isActive=this._isShowing=!1,this._startAnimation(!1,t,this._finishHide),this)},zt.prototype.destroy=function(){if(this._isDestroyed)return this;var t=this._item,e=t._element,i=t.getGrid(),s=this._queue,n=i._settings;return this._stopAnimation({}),s.flush(!0,t).destroy(),Rt(e,n.itemVisibleClass),Rt(e,n.itemHiddenClass),this._item=null,this._isHiding=this._isShowing=!1,this._isDestroyed=this._isHidden=!0,this},zt.prototype._startAnimation=function(t,e,i){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,_=(t?r.showEasing:r.hideEasing)||"ease",d=e||h<=0;if(o){if(B(n._id),d)return n._animateChild.isAnimating()?n._animateChild.stop(o):f(n._child,o),void(i&&i());var c,u,p;c=n._id,u=function(){s=function(t,e){var i={};for(var s in e)i[s]=a(t,l(s));return i}(n._child,o)},p=function(){n._animateChild.start(s,o,{duration:h,easing:_,onFinish:i})},k.add(c+Y,u,p)}else i&&i()}},zt.prototype._stopAnimation=function(t){if(!this._isDestroyed){var e=this._item;B(e._id),e._animateChild.stop(t)}},zt.prototype._finishShow=function(){this._isHidden||(this._isShowing=!1,this._queue.flush(!1,this._item))},zt.prototype._finishHide=(Xt={transform:xt(0,0)},function(){if(this._isHidden){var t=this._item;this._isHiding=!1,t._layout.stop(!0,Xt),t._element.style.display="none",this._queue.flush(!1,t)}});var Vt,Wt,jt,Ut,Zt=0;function $t(){return++Zt}function Jt(t,e,i){var s=t._settings;this._id=$t(),this._gridId=t._id,this._isDestroyed=!1,this._left=0,this._top=0,this._element=e,this._child=e.children[0],e.parentNode!==t._element&&t._element.appendChild(e),j(e,s.itemClass),"boolean"!=typeof i&&(i="none"!==a(e,"display")),this._isActive=i,e.style.left="0",e.style.top="0",e.style[n]=xt(0,0),this._animate=new p(e),this._animateChild=new p(this._child),this._visibility=new zt(this),this._layout=new Nt(this),this._migrate=new qt(this),this._release=new Ft(this),this._dragPlaceholder=new Ht(this),this._drag=s.dragEnabled?new Ot(this):null,this._refreshDimensions(),this._refreshSortData()}function Kt(){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)}Jt.prototype.getGrid=function(){return t[this._gridId]},Jt.prototype.getElement=function(){return this._element},Jt.prototype.getWidth=function(){return this._width},Jt.prototype.getHeight=function(){return this._height},Jt.prototype.getMargin=function(){return{left:this._marginLeft,right:this._marginRight,top:this._marginTop,bottom:this._marginBottom}},Jt.prototype.getPosition=function(){return{left:this._left,top:this._top}},Jt.prototype.isActive=function(){return this._isActive},Jt.prototype.isVisible=function(){return!!this._visibility&&!this._visibility._isHidden},Jt.prototype.isShowing=function(){return!(!this._visibility||!this._visibility._isShowing)},Jt.prototype.isHiding=function(){return!(!this._visibility||!this._visibility._isHiding)},Jt.prototype.isPositioning=function(){return!(!this._layout||!this._layout._isActive)},Jt.prototype.isDragging=function(){return!(!this._drag||!this._drag._isActive)},Jt.prototype.isReleasing=function(){return!(!this._release||!this._release._isActive)},Jt.prototype.isDestroyed=function(){return this._isDestroyed},Jt.prototype._refreshDimensions=function(){if(!this._isDestroyed&&!this._visibility._isHidden){var t=this._element,e=this._dragPlaceholder,i=t.getBoundingClientRect();this._width=i.width,this._height=i.height,this._marginLeft=Math.max(0,ht(t,"margin-left")),this._marginRight=Math.max(0,ht(t,"margin-right")),this._marginTop=Math.max(0,ht(t,"margin-top")),this._marginBottom=Math.max(0,ht(t,"margin-bottom")),e&&e.updateDimensions(this._width,this._height)}},Jt.prototype._refreshSortData=function(){if(!this._isDestroyed){var t,e=this._sortData={},i=this.getGrid()._settings.sortData;for(t in i)e[t]=i[t](this,this._element)}},Jt.prototype._destroy=function(t){if(!this._isDestroyed){var e=this._element,i=this.getGrid(),s=i._settings,n=i._items.indexOf(this);this._release.destroy(),this._migrate.destroy(),this._layout.destroy(),this._visibility.destroy(),this._animate.destroy(),this._animateChild.destroy(),this._dragPlaceholder.destroy(),this._drag&&this._drag.destroy(),e.removeAttribute("style"),this._child.removeAttribute("style"),Rt(e,s.itemClass),n>-1&&i._items.splice(n,1),t&&e.parentNode.removeChild(e),this._isActive=!1,this._isDestroyed=!0}},Kt.prototype.getLayout=function(t,e,i,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),c=this._slotSizes;if(o.slots=s||this._slots,o.width=a?0:d?Math.round(e):e,o.height=a?d?Math.round(i):i:0,o.setWidth=a,o.setHeight=!a,o.slots.length=0,c.length=0,!t.length)return o;for(r=0;rd.height&&(Vt.left>0&&u.push(this._addRect(0,d.height,Vt.left,1/0)),Vt.left+Vt.widthd.width&&(Vt.top>0&&u.push(this._addRect(d.width,0,1/0,Vt.top)),Vt.top+Vt.height.49&&r.height>.49&&(!e&&r.tope.left+e.width&&Wt.push(this._addRect(e.left+e.width,t.top,t.left+t.width-(e.left+e.width),t.height)),t.tope.top+e.height&&Wt.push(this._addRect(t.left,e.top+e.height,t.width,t.top+t.height-(e.top+e.height))),Wt):(Wt.push(this._addRect(t.left,t.top,t.width,t.height)),Wt)}),Kt.prototype._doRectsOverlap=function(t,e){return!(t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top)},Kt.prototype._isRectWithinRect=function(t,e){return t.left>=e.left&&t.top>=e.top&&t.left+t.width<=e.left+e.width&&t.top+t.height<=e.top+e.height},Kt.prototype._purgeRects=(jt={},Ut={},function(t){for(var e,i=t.length;i--;)if(e=t.length,t[i])for(this._getRect(t[i],jt);e--;)if(t[e]&&i!==e&&this._isRectWithinRect(jt,this._getRect(t[e],Ut))){t[i]=0;break}return t}),Kt.prototype._sortRectsTopLeft=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.tope.top?1:t.lefte.left?1:0}}(),Kt.prototype._sortRectsLeftTop=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.lefte.left?1:t.tope.top?1:0}}();var Qt="[object HTMLCollection]",te="[object NodeList]";function ee(t){var e=Object.prototype.toString.call(t);return e===Qt||e===te}var ie="object",se="[object Object]",ne=Object.prototype.toString;function re(t){return typeof t===ie&&ne.call(t)===se}function oe(t){return ee(t)?Array.prototype.slice.call(t):Array.prototype.concat(t)}var he=new Kt,ae=function(){},_e="number",le="string";function de(e,s){var n,r,o=this;if(typeof e===le&&(e=window.document.querySelector(e)),this._element=e,!(e.getRootNode?e.getRootNode({composed:!0})===document:window.document.body.contains(e))||e===window.document.documentElement)throw new Error("Container element must be an existing DOM element");c((n=this._settings=ce(de.defaultOptions,s)).dragSort)||(n.dragSort=!!n.dragSort),this._id=$t(),t[this._id]=o,this._isDestroyed=!1,this._layout={id:0,items:[],slots:[],setWidth:!1,setHeight:!1,width:0,height:0},this._emitter=new i,j(e,n.containerClass),this._items=[],typeof(r=n.items)===le?oe(e.children).forEach(function(t){("*"===r||W(t,r))&&o._items.push(new Jt(o,t))}):(Array.isArray(r)||ee(r))&&(this._items=oe(r).map(function(t){return new Jt(o,t)})),fe(this,n.layoutOnResize),n.layoutOnInit&&this.layout(!0)}function ce(t,e){var i=ue({},t);return e&&(i=ue(i,e)),i.visibleStyles=(e||0).visibleStyles||(t||0).visibleStyles,i.hiddenStyles=(e||0).hiddenStyles||(t||0).hiddenStyles,i}function ue(t,e){var i,s,n,r=Object.keys(e),o=r.length;for(n=0;n=0&&(t._resizeHandler=nt(function(){t.refreshItems().layout()},e),window.addEventListener("resize",t._resizeHandler))}function pe(t){t._resizeHandler&&(t._resizeHandler("cancel"),window.removeEventListener("resize",t._resizeHandler),t._resizeHandler=null)}return de.Item=Jt,de.ItemLayout=Nt,de.ItemVisibility=zt,de.ItemMigrate=qt,de.ItemAnimate=p,de.ItemDrag=Ot,de.ItemRelease=Ft,de.ItemDragPlaceholder=Ht,de.Emitter=i,de.Dragger=M,de.Packer=Kt,de.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,dragSortHeuristics:{sortInterval:100,minDragDistance:10,minBounceBackAngle:1},dragSortPredicate:{threshold:50,action:"move",migrateAction:"move"},dragReleaseDuration:300,dragReleaseEasing:"ease",dragCssProps:{touchAction:"none",userSelect:"none",userDrag:"none",tapHighlightColor:"rgba(0, 0, 0, 0)",touchCallout:"none",contentZooming:"none"},dragPlaceholder:{enabled:!1,duration:300,easing:"ease",createElement:null,onCreate:null,onRemove:null},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",itemPlaceholderClass:"muuri-item-placeholder"},de.prototype.on=function(t,e){return this._emitter.on(t,e),this},de.prototype.off=function(t,e){return this._emitter.off(t,e),this},de.prototype.getElement=function(){return this._element},de.prototype.getItems=function(t){if(this._isDestroyed||!t&&0!==t)return this._items.slice(0);var e,i,s=[],n=oe(t);for(i=0;i-1){if(r.dragEnabled&&!o.dragEnabled){for(this._settings=r,e=0;e-1&&r.dragEnabled&&o.dragEnabled)for(e=0;e-1&&r.containerClass!==o.containerClass&&(Rt(s,r.containerClass),j(s,o.containerClass)),n.indexOf("sortData")>-1)for(e=0;e-1&&(pe(this),fe(this,o.layoutOnResize)),o},de.prototype.refreshItems=function(t){if(this._isDestroyed)return this;var e,i=this.getItems(t);for(e=0;e0)){var s=o._layout.id!==l,n=c(t)?t:i;c(n)&&n(s,_.items.slice(0)),!s&&o._hasListeners(e)&&o._emit(e,_.items.slice(0))}}if((_.setHeight&&typeof _.height===_e||_.setWidth&&typeof _.width===_e)&&(s="border-box"===a(h,"box-sizing")),_.setHeight&&(typeof _.height===_e?h.style.height=(s?_.height+this._borderTop+this._borderBottom:_.height)+"px":h.style.height=_.height),_.setWidth&&(typeof _.width===_e?h.style.width=(s?_.width+this._borderLeft+this._borderRight:_.width)+"px":h.style.width=_.width),this._hasListeners("layoutStart")&&this._emit("layoutStart",_.items.slice(0)),!d)return f(),this;for(r=0;rl?1:0:ld?1:0)return c;return c||(s||(s=n(i)),c=r(o,h)),c}function h(o,h){var a=t(o,h);return e&&a&&(a=-a),a||(s||(s=n(i)),r(o,h))}return function(n,r){if(this._isDestroyed||this._items.length<2)return this;var a,_=this._items,l=r||0,d=l.layout?l.layout:void 0===l.layout;if(t=n,e=!!l.descending,i=_.slice(0),s=null,c(t))_.sort(h);else if(typeof t===le)t=n.trim().split(" ").map(function(t){return t.split(":")}),_.sort(o);else{if(!Array.isArray(t))return this;if(t.length!==_.length)throw new Error("[Muuri] sort reference items do not match with grid items.");for(a=0;a<_.length;a++){if(t.indexOf(_[a])<0)throw new Error("[Muuri] sort reference items do not match with grid items.");_[a]=t[a]}e&&_.reverse()}return this._hasListeners("sort")&&this._emit("sort",_.slice(0),i),d&&this.layout("instant"===d,c(d)?d:void 0),this}}(),de.prototype.move=function(t,e,i){if(this._isDestroyed||this._items.length<2)return this;var s,n,r=this._items,o=i||0,h=o.layout?o.layout:void 0===o.layout,a="swap"===o.action,_=a?"swap":"move",l=this._getItem(t),d=this._getItem(e);return l&&d&&l!==d&&(s=r.indexOf(l),n=r.indexOf(d),a?Q(r,s,n):K(r,s,n),this._hasListeners("move")&&this._emit("move",{item:l,fromIndex:s,toIndex:n,action:_}),h&&this.layout("instant"===h,c(h)?h:void 0)),this},de.prototype.send=function(t,e,i,s){if(this._isDestroyed||e._isDestroyed||this===e)return this;if(!(t=this._getItem(t)))return this;var n=s||0,r=n.appendTo||window.document.body,o=n.layoutSender?n.layoutSender:void 0===n.layoutSender,h=n.layoutReceiver?n.layoutReceiver:void 0===n.layoutReceiver;return t._migrate.start(e,i,r),t._migrate._isActive&&t._isActive&&(o&&this.layout("instant"===o,c(o)?o:void 0),h&&e.layout("instant"===h,c(h)?h:void 0)),this},de.prototype.destroy=function(e){if(this._isDestroyed)return this;var i,s=this._element,n=this._items.slice(0);for(pe(this),i=0;i-1?t:this._items.length+t]||null;if(t instanceof Jt)return t._gridId===this._id?t:null;for(var e=0;e Date: Wed, 7 Aug 2019 23:00:31 +0300 Subject: [PATCH 019/120] Refactoring. --- dist/muuri.js | 225 ++++++++++++++++------------ dist/muuri.min.js | 2 +- src/Grid/Grid.js | 85 +++++++---- src/Item/ItemAnimate.js | 2 +- src/Item/ItemDrag.js | 4 +- src/Item/ItemLayout.js | 4 +- src/Item/ItemMigrate.js | 2 +- src/Item/ItemVisibility.js | 14 +- src/Queue/Queue.js | 50 ++++--- src/utils/getOffsetDiff.js | 24 +-- src/utils/getScrollableAncestors.js | 28 ++-- src/utils/isFunction.js | 4 +- src/utils/isNodeList.js | 2 +- src/utils/toArray.js | 6 +- 14 files changed, 263 insertions(+), 189 deletions(-) diff --git a/dist/muuri.js b/dist/muuri.js index df479e3f..44bf03a4 100644 --- a/dist/muuri.js +++ b/dist/muuri.js @@ -260,7 +260,7 @@ return string.replace(styleNameRegEx, '-$1').toLowerCase(); } - var strFunction = 'function'; + var functionType = 'function'; /** * Check if a value is a function. @@ -269,7 +269,7 @@ * @returns {Boolean} */ function isFunction(val) { - return typeof val === strFunction; + return typeof val === functionType; } var transformStyle$1 = 'transform'; @@ -384,7 +384,7 @@ animOptions.duration = opts.duration || 300; animOptions.easing = opts.easing || 'ease'; - // Start the animation + // Start the animation. var element = this._element; animation = element.animate(animKeyframes, animOptions); animation.onfinish = this._onFinish; @@ -1560,33 +1560,33 @@ * @returns {Object} */ function getOffset(element, offsetData) { - var ret = offsetData || {}; + var offset = offsetData || {}; var rect; // Set up return data. - ret.left = 0; - ret.top = 0; + offset.left = 0; + offset.top = 0; // Document's offsets are always 0. - if (element === document) return ret; + if (element === document) return offset; // Add viewport scroll left/top to the respective offsets. - ret.left = window.pageXOffset || 0; - ret.top = window.pageYOffset || 0; + offset.left = window.pageXOffset || 0; + offset.top = window.pageYOffset || 0; // Window's offsets are the viewport scroll left/top values. - if (element.self === window.self) return ret; + if (element.self === window.self) return offset; // Add element's client rects to the offsets. rect = element.getBoundingClientRect(); - ret.left += rect.left; - ret.top += rect.top; + offset.left += rect.left; + offset.top += rect.top; // Exclude element's borders from the offset. - ret.left += getStyleAsFloat(element, 'border-left-width'); - ret.top += getStyleAsFloat(element, 'border-top-width'); + offset.left += getStyleAsFloat(element, 'border-left-width'); + offset.top += getStyleAsFloat(element, 'border-top-width'); - return ret; + return offset; } /** @@ -1651,38 +1651,38 @@ } /** - * Collect element's ancestors that are potentially scrollable elements. + * Collect element's ancestors that are potentially scrollable elements. The + * provided element is also also included in the check, meaning that if it is + * scrollable it is added to the result array. * * @param {HTMLElement} element - * @param {Boolean} [includeSelf=false] - * @param {Array} [data] + * @param {Array} [result] * @returns {Array} */ - function getScrollableAncestors(element, includeSelf, data) { - var ret = data || []; - var parent = includeSelf ? element : element.parentNode; + function getScrollableAncestors(element, result) { + result = result || []; // Find scroll parents. - while (parent && parent !== document) { + while (element && element !== window.document) { // If element is inside ShadowDOM let's get it's host node from the real // DOM and continue looping. - if (parent.getRootNode && parent instanceof DocumentFragment) { - parent = parent.getRootNode().host; + if (element.getRootNode && element instanceof DocumentFragment) { + element = element.getRootNode().host; continue; } // If element is scrollable let's add it to the scrollable list. - if (isScrollable(parent)) { - ret.push(parent); + if (isScrollable(element)) { + result.push(element); } - parent = parent.parentNode; + element = element.parentNode; } // Always add window to the results. - ret.push(window); + result.push(window); - return ret; + return result; } var translateValue = {}; @@ -2204,14 +2204,14 @@ // Get dragged element's scrolling parents. scrollers.length = 0; - getScrollableAncestors(this._item._element, false, scrollers); + getScrollableAncestors(this._item._element.parentNode, scrollers); // If drag container is defined and it's not the same element as grid // container then we need to add the grid container and it's scroll parents // to the elements which are going to be listener for scroll events. if (dragContainer !== gridContainer) { gridScrollers = []; - getScrollableAncestors(gridContainer, true, gridScrollers); + getScrollableAncestors(gridContainer, gridScrollers); for (i = 0; i < gridScrollers.length; i++) { if (scrollers.indexOf(gridScrollers[i]) < 0) { scrollers.push(gridScrollers[i]); @@ -3457,6 +3457,8 @@ */ function Queue() { this._queue = []; + this._processQueue = []; + this._processCounter = 0; this._isDestroyed = false; } @@ -3480,40 +3482,52 @@ }; /** - * Process queue callbacks and reset the queue. + * Process queue callbacks in the order they were insterted and reset the queue. + * The provided arguments are passed on to the callbacks. * * @public * @memberof Queue.prototype - * @param {*} arg1 - * @param {*} arg2 + * @param {...*} args * @returns {Queue} */ - Queue.prototype.flush = function(arg1, arg2) { + Queue.prototype.process = function() { if (this._isDestroyed) return this; var queue = this._queue; - var length = queue.length; - var i; + var queueLength = queue.length; // Quit early if the queue is empty. - if (!length) return this; + if (!queueLength) return this; - var singleCallback = length === 1; - var snapshot = singleCallback ? queue[0] : queue.slice(0); + var pQueue = this._processQueue; + var pQueueLength = pQueue.length; + var i; + + // Append the current queue callbacks to the process queue. + for (i = 0; i < queueLength; i++) { + pQueue.push(queue[i]); + } // Reset queue. queue.length = 0; - // If we only have a single callback let's just call it. - if (singleCallback) { - snapshot(arg1, arg2); - return this; + // Increment process counter. + ++this._processCounter; + + // Call the new process queue callbacks. + var indexFrom = pQueueLength; + var indexTo = pQueue.length; + for (i = indexFrom; i < indexTo; i++) { + if (this._isDestroyed) return this; + pQueue[i].apply(null, arguments); } - // If we have multiple callbacks, let's process them. - for (i = 0; i < length; i++) { - snapshot[i](arg1, arg2); - if (this._isDestroyed) break; + // Decrement process counter. + --this._processCounter; + + // Reset process queue once it has stop processing. + if (!this._processCounter) { + pQueue.length = 0; } return this; @@ -3531,6 +3545,8 @@ this._isDestroyed = true; this._queue.length = 0; + this._processQueue.length = 0; + this._processCounter = 0; return this; }; @@ -3654,7 +3670,7 @@ this._isActive = false; // Process callback queue if needed. - if (processCallbackQueue) this._queue.flush(true, item); + if (processCallbackQueue) this._queue.process(true, item); return this; }; @@ -3744,7 +3760,7 @@ if (migrate._isActive) migrate.stop(); // Process the callback queue. - this._queue.flush(false, item); + this._queue.process(false, item); }; /** @@ -3891,7 +3907,7 @@ if (item._drag) item._drag.destroy(); // Process current visibility animation queue. - item._visibility._queue.flush(true, item); + item._visibility._queue.process(true, item); // Emit beforeSend event. if (grid._hasListeners(eventBeforeSend)) { @@ -4294,7 +4310,7 @@ // queue with the interrupted flag active, update classes and set display // to block if necessary. if (!this._isShowing) { - queue.flush(true, item); + queue.process(true, item); removeClass(element, settings.itemHiddenClass); addClass(element, settings.itemVisibleClass); if (!this._isHiding) element.style.display = 'block'; @@ -4349,7 +4365,7 @@ // queue with the interrupted flag active, update classes and set display // to block if necessary. if (!this._isHiding) { - queue.flush(true, item); + queue.process(true, item); addClass(element, settings.itemHiddenClass); removeClass(element, settings.itemVisibleClass); } @@ -4387,7 +4403,7 @@ this._stopAnimation({}); // Fire all uncompleted callbacks with interrupted flag and destroy the queue. - queue.flush(true, item).destroy(); + queue.process(true, item).destroy(); // Remove visible/hidden classes. removeClass(element, settings.itemVisibleClass); @@ -4421,8 +4437,8 @@ var item = this._item; var settings = item.getGrid()._settings; var targetStyles = toVisible ? settings.visibleStyles : settings.hiddenStyles; - var duration = parseInt(toVisible ? settings.showDuration : settings.hideDuration) || 0; - var easing = (toVisible ? settings.showEasing : settings.hideEasing) || 'ease'; + var duration = toVisible ? settings.showDuration : settings.hideDuration; + var easing = toVisible ? settings.showEasing : settings.hideEasing; var isInstant = instant || duration <= 0; var currentStyles; @@ -4485,7 +4501,7 @@ ItemVisibility.prototype._finishShow = function() { if (this._isHidden) return; this._isShowing = false; - this._queue.flush(false, this._item); + this._queue.process(false, this._item); }; /** @@ -4502,7 +4518,7 @@ this._isHiding = false; item._layout.stop(true, finishStyles); item._element.style.display = 'none'; - this._queue.flush(false, item); + this._queue.process(false, item); }; })(); @@ -5351,7 +5367,7 @@ var nodeListType = '[object NodeList]'; /** - * Check if a value is a node list + * Check if a value is a node list or a html collection. * * @param {*} val * @returns {Boolean} @@ -5378,11 +5394,11 @@ /** * Converts a value to an array or clones an array. * - * @param {*} target + * @param {*} val * @returns {Array} */ - function toArray(target) { - return isNodeList(target) ? Array.prototype.slice.call(target) : Array.prototype.concat(target); + function toArray(val) { + return isNodeList(val) ? Array.prototype.slice.call(val) : Array.prototype.concat(val); } var packer = new Packer(); @@ -5455,7 +5471,6 @@ function Grid(element, options) { var inst = this; var settings; - var items; // Allow passing element as selector string if (typeof element === stringType) { @@ -5507,19 +5522,7 @@ addClass(element, settings.containerClass); // Create initial items. - this._items = []; - items = settings.items; - if (typeof items === stringType) { - toArray(element.children).forEach(function(itemElement) { - if (items === '*' || elementMatches(itemElement, items)) { - inst._items.push(new Item(inst, itemElement)); - } - }); - } else if (Array.isArray(items) || isNodeList(items)) { - this._items = toArray(items).map(function(itemElement) { - return new Item(inst, itemElement); - }); - } + this._items = getInitialGridItems(this, settings.items); // If layoutOnResize option is a valid number sanitize it and bind the resize // handler. @@ -5743,22 +5746,24 @@ Grid.prototype.getItems = function(targets) { // Return all items immediately if no targets were provided or if the // instance is destroyed. - if (this._isDestroyed || (!targets && targets !== 0)) { + if (this._isDestroyed || targets === undefined) { return this._items.slice(0); } - var ret = []; - var targetItems = toArray(targets); - var item; - var i; + var items = []; + var i, item; - // If target items are defined return filtered results. - for (i = 0; i < targetItems.length; i++) { - item = this._getItem(targetItems[i]); - item && ret.push(item); + if (Array.isArray(targets) || isNodeList(targets)) { + for (i = 0; i < targets.length; i++) { + item = this._getItem(targets[i]); + if (item) items.push(item); + } + } else { + item = this._getItem(targets); + if (item) items.push(item); } - return ret; + return items; }; /** @@ -6309,11 +6314,11 @@ } function getIndexMap(items) { - var ret = {}; + var result = {}; for (var i = 0; i < items.length; i++) { - ret[items[i]._id] = i; + result[items[i]._id] = i; } - return ret; + return result; } function compareIndices(itemA, itemB) { @@ -6851,19 +6856,20 @@ */ function mergeSettings(defaultSettings, userSettings) { // Create a fresh copy of default settings. - var ret = mergeObjects({}, defaultSettings); + var settings = mergeObjects({}, defaultSettings); // Merge user settings to default settings. if (userSettings) { - ret = mergeObjects(ret, userSettings); + settings = mergeObjects(settings, userSettings); } // Handle visible/hidden styles manually so that the whole object is // overridden instead of the props. - ret.visibleStyles = (userSettings || 0).visibleStyles || (defaultSettings || 0).visibleStyles; - ret.hiddenStyles = (userSettings || 0).hiddenStyles || (defaultSettings || 0).hiddenStyles; + settings.visibleStyles = + (userSettings || {}).visibleStyles || (defaultSettings || {}).visibleStyles; + settings.hiddenStyles = (userSettings || {}).hiddenStyles || (defaultSettings || {}).hiddenStyles; - return ret; + return settings; } /** @@ -6916,6 +6922,37 @@ return target; } + /** + * Collect and return initial items for grid. + * + * @param {Grid} grid + * @param {?(HTMLElement[]|NodeList|String)} items + * @returns {HTMLElement[]} + */ + function getInitialGridItems(grid, items) { + var result = []; + var wildCardSelector = '*'; + var i, elem; + + // If we have a selector. + if (typeof items === stringType) { + for (i = 0; i < grid._element.children.length; i++) { + elem = grid._element.children[i]; + if (items === wildCardSelector || elementMatches(elem, items)) { + result.push(new Item(grid, elem)); + } + } + } + // If we have an array of elements or a node list. + else if (Array.isArray(items) || isNodeList(items)) { + for (i = 0; i < items.length; i++) { + result.push(new Item(grid, items[i])); + } + } + + return result; + } + /** * Bind grid's resize handler to window. * diff --git a/dist/muuri.min.js b/dist/muuri.min.js index f8750d3c..61f934c0 100644 --- a/dist/muuri.min.js +++ b/dist/muuri.min.js @@ -14,4 +14,4 @@ * Copyright (c) 2018-present, Niklas Rämö * @license MIT */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Muuri=e()}(this,function(){"use strict";var t={},e="layoutEnd";function i(){this._events={},this._queue=[],this._counter=0,this._isDestroyed=!1}i.prototype.on=function(t,e){if(this._isDestroyed)return this;var i=this._events[t];return i||(i=this._events[t]=[]),i.push(e),this},i.prototype.off=function(t,e){if(this._isDestroyed)return this;var i=this._events[t];if(!i||!i.length)return this;if(!e)return i.length=0,this;for(var s=i.length;s--;)e===i[s]&&i.splice(s,1);return this},i.prototype.emit=function(t,e,i,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-1||(M._activeInstances.push(t),M._emitter.on(b,t._onMove),M._emitter.on(A,t._onCancel),M._emitter.on(D,t._onEnd),1===M._activeInstances.length&&M._bindListeners())},M._deactivateInstance=function(t){var e=M._activeInstances.indexOf(t);-1!==e&&(M._activeInstances.splice(e,1),M._emitter.off(b,t._onMove),M._emitter.off(A,t._onCancel),M._emitter.off(D,t._onEnd),M._activeInstances.length||M._unbindListeners())},M._bindListeners=function(){var t=M._events;window.addEventListener(t.move,M._onMove,R),window.addEventListener(t.end,M._onEnd,R),t.cancel&&window.addEventListener(t.cancel,M._onCancel,R)},M._unbindListeners=function(){var t=M._events;window.removeEventListener(t.move,M._onMove,R),window.removeEventListener(t.end,M._onEnd,R),t.cancel&&window.removeEventListener(t.cancel,M._onCancel,R)},M._getEventPointerId=function(t){return"number"==typeof t.pointerId?t.pointerId:t.changedTouches?t.changedTouches[0]?t.changedTouches[0].identifier:null:1},M._getTouchById=function(t,e){if("number"==typeof t.pointerId)return t.pointerId===e?t:null;if(t.changedTouches){for(var i=0;i-1&&(this._queue[n]=void 0),s?this._queue.unshift(t):this._queue.push(t),this._reads[t]=e,this._writes[t]=i,this._nextStep||(this._nextStep=y(this._step))},T.prototype.cancel=function(t){var e=this._queue.indexOf(t);e>-1&&(this._queue[e]=void 0,delete this._reads[t],delete this._writes[t])},T.prototype._step=function(){var t,e,i=this._queue,s=this._reads,n=this._writes,r=this._batch,o=this._batchReads,h=this._batchWrites,a=i.length;for(this._nextStep=null,e=0;en?n:e<0?Math.max(n+e+1,0):e}function K(t,e,i){if(!(t.length<2)){var s=J(t,e),n=J(t,i);s!==n&&t.splice(n,0,t.splice(s,1)[0])}}function Q(t,e,i){if(!(t.length<2)){var s,n=J(t,e),r=J(t,i);n!==r&&(s=t[n],t[n]=t[r],t[r]=s)}}var tt="cancel",et="finish",it="debounce",st=0;function nt(t,e){var i,s=++st+it;return e>0?function(n){void 0!==i&&(i=window.clearTimeout(i),k.cancel(s),n===et&&t()),n!==tt&&n!==et&&(i=window.setTimeout(function(){i=void 0,k.add(s,t,null,!0)},e))}:function(e){e!==tt&&t()}}function rt(t){var e=a(t,"transform");if(!e||"none"===e)return!1;var i=a(t,"display");return"inline"!==i&&"none"!==i}function ot(t){for(var e=window.document,i=t||e;i&&i!==e&&"static"===a(i,"position")&&!rt(i);)i=i.parentElement||e;return i}function ht(t,e){return parseFloat(a(t,e))||0}var at={},_t={},lt={};function dt(t,e){var i,s=e||{};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:(i=t.getBoundingClientRect(),s.left+=i.left,s.top+=i.top,s.left+=ht(t,"border-left-width"),s.top+=ht(t,"border-top-width"),s))}function ct(t,e,i){return lt.left=0,lt.top=0,t===e?lt:i&&(t=ot(t))===(e=ot(e))?lt:(dt(t,at),dt(e,_t),lt.left=_t.left-at.left,lt.top=_t.top-at.top,lt)}var ut="overflow",ft="overflow-x",pt="overflow-y",mt="auto",gt="scroll";function yt(t){var e=a(t,ut);return e===mt||e===gt||((e=a(t,ft))===mt||e===gt||((e=a(t,pt))===mt||e===gt))}function vt(t,e,i){for(var s=i||[],n=e?t:t.parentNode;n&&n!==document;)n.getRootNode&&n instanceof DocumentFragment?n=n.getRootNode().host:(yt(n)&&s.push(n),n=n.parentNode);return s.push(window),s}var wt={},St="transform",bt="none",Dt=/^matrix3d/,At=/([^,]*,){4}/,Et=/([^,]*,){12}/,Ct=/[^,]*,/;function Lt(t){wt.x=0,wt.y=0;var e=a(t,St);if(!e||e===bt)return wt;var i=Dt.test(e),s=e.replace(i?Et:At,""),n=s.replace(Ct,"");return wt.x=parseFloat(s)||0,wt.y=parseFloat(n)||0,wt}function xt(t,e){return"translateX("+t+"px) translateY("+e+"px)"}function Rt(t,e){t.classList?t.classList.remove(e):W(t,"."+e)&&(t.className=(" "+t.className+" ").replace(" "+e+" "," ").trim())}var It,Pt,Mt,Tt,kt,Xt,Yt=0;function Ot(t){var e=t._element,i=t.getGrid(),s=i._settings;this._item=t,this._gridId=i._id,this._isDestroyed=!1,this._isMigrating=!1,this._startPredicate=c(s.dragStartPredicate)?s.dragStartPredicate:Ot.defaultStartPredicate,this._startPredicateState=Yt,this._startPredicateResult=void 0,this._hBlockedIndex=null,this._hX1=0,this._hX2=0,this._hY1=0,this._hY2=0,this._reset(),this._preStartCheck=this._preStartCheck.bind(this),this._preEndCheck=this._preEndCheck.bind(this),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);var n=s.dragSortHeuristics.sortInterval;this._checkOverlapDebounce=nt(this._checkOverlap,n),this._dragger=new M(e,s.dragCssProps),this._dragger.on("start",this._preStartCheck),this._dragger.on("move",this._preStartCheck),this._dragger.on("cancel",this._preEndCheck),this._dragger.on("end",this._preEndCheck)}function Gt(t,e){return t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top?0:(Math.min(t.left+t.width,e.left+e.width)-Math.max(t.left,e.left))*(Math.min(t.top+t.height,e.top+e.height)-Math.max(t.top,e.top))/(Math.min(t.width,e.width)*Math.min(t.height,e.height))*100}function Ht(t){this._item=t,this._animate=new p,this._element=null,this._className="",this._didMigrate=!1,this._resetAfterLayout=!1,this._currentLeft=0,this._currentTop=0,this._nextLeft=0,this._nextTop=0,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this),this._onLayoutStart=this._onLayoutStart.bind(this),this._onLayoutEnd=this._onLayoutEnd.bind(this),this._onReleaseEnd=this._onReleaseEnd.bind(this),this._onMigrate=this._onMigrate.bind(this)}function Bt(){this._queue=[],this._isDestroyed=!1}function Nt(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 Bt,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this)}function qt(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._container=!1,this._containerDiffX=0,this._containerDiffY=0}function Ft(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0}function zt(t){var e=t._isActive,i=t._element,s=t.getGrid()._settings;this._item=t,this._isDestroyed=!1,this._isHidden=!e,this._isHiding=!1,this._isShowing=!1,this._queue=new Bt,this._finishShow=this._finishShow.bind(this),this._finishHide=this._finishHide.bind(this),i.style.display=e?"block":"none",j(i,e?s.itemVisibleClass:s.itemHiddenClass),f(t._child,e?s.visibleStyles:s.hiddenStyles)}Ot.defaultStartPredicate=function(t,e,i){var s=t._drag;if(!s._startPredicateData){var n=i||s._getGrid()._settings.dragStartPredicate||{};s._startPredicateData={distance:Math.max(n.distance,0)||0,delay:Math.max(n.delay,0)||0,handle:"string"==typeof n.handle&&n.handle}}var r=s._startPredicateData;if(!e.isFinal)return!(!r.handleElement&&(r.handleElement=s._getStartPredicateHandle(e),!r.handleElement))&&(r.delay&&(r.event=e,r.delayTimer||(r.delayTimer=window.setTimeout(function(){r.delay=0,s._resolveStartPredicate(r.event)&&(s._forceResolveStartPredicate(r.event),s._resetStartPredicate())},r.delay))),s._resolveStartPredicate(e));s._finishStartPredicate(e)},Ot.defaultSortPredicate=(It={},Pt={},Mt={},Tt=[],function(t,e){var i=t._drag,s=i._getGrid(),n=e&&"number"==typeof e.threshold?e.threshold:50,r=e&&"swap"===e.action?"swap":"move",o=e&&"swap"===e.migrateAction?"swap":"move";n=Math.min(Math.max(n,1),100),It.width=t._width,It.height=t._height,It.left=i._elementClientX,It.top=i._elementClientY;var h=function(t,e,i){var s,n,r,o,h=null,a=e._settings.dragSort,_=-1;if(!0===a?(Tt[0]=e,n=Tt):c(a)&&(n=a.call(e,t)),!n||!Array.isArray(n)||!n.length)return h;for(o=0;oi&&s>_&&(_=s,h=r));return Tt.length=0,h}(t,s,n);if(!h)return!1;var a,_,l,d=t.getGrid()!==h,u=0,f=0,p=0,m=-1,g=!1;for(h===s?(It.left=i._gridX+t._marginLeft,It.top=i._gridY+t._marginTop):(h._updateBorders(1,0,1,0),u=h._left+h._borderLeft,f=h._top+h._borderTop),l=0;lp&&(m=l,p=_));return d&&p=n&&(Mt.grid=h,Mt.index=m,Mt.action=d?o:r,Mt)}),Ot.prototype.stop=function(){var t=this._item,e=t._element,i=this._getGrid();return this._isActive?this._isMigrating?(this._finishMigration(),this):(N(t._id),q(t._id),this._unbindScrollListeners(),this._checkOverlapDebounce("cancel"),e.parentNode!==i._element&&(i._element.appendChild(e),e.style[n]=xt(this._gridX,this._gridY)),Rt(e,i._settings.itemDraggingClass),this._reset(),this):this},Ot.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(),this._dragger.destroy(),this._isDestroyed=!0,this)},Ot.prototype._getGrid=function(){return t[this._gridId]||null},Ot.prototype._reset=function(){this._isActive=!1,this._container=null,this._containingBlock=null,this._dragEvent=null,this._scrollEvent=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},Ot.prototype._bindScrollListeners=function(){var t,e,i=this._getGrid()._element,s=this._container,n=this._scrollers;if(n.length=0,vt(this._item._element,!1,n),s!==i)for(vt(i,!0,t=[]),e=0;e=s&&t.pageX=n&&t.pageY3&&e.minBounceBackAngle>0;if(h||(this._hBlockedIndex=null),Math.abs(r)>i||Math.abs(o)>i){if(h){var a=Math.atan2(r,o),_=Math.atan2(this._hX2-this._hX1,this._hY2-this._hY1),l=Math.atan2(Math.sin(a-_),Math.cos(a-_));Math.abs(l)>e.minBounceBackAngle&&(this._hBlockedIndex=null)}return this._hX1=this._hX2,this._hY1=this._hY2,this._hX2=s,this._hY2=n,!0}return!1},Ot.prototype._resetStartPredicate=function(){var t=this._startPredicateData;t&&(t.delayTimer&&(t.delayTimer=window.clearTimeout(t.delayTimer)),this._startPredicateData=null)},Ot.prototype._checkOverlap=function(){if(this._isActive){var t,e,i,s,n,r,o,h,a=this._item,_=this._getGrid()._settings;(t=c(_.dragSortPredicate)?_.dragSortPredicate(a,this._dragEvent):Ot.defaultSortPredicate(a,_.dragSortPredicate))&&"number"==typeof t.index&&(h=(e=a.getGrid())!==(s=t.grid||e),i=e._items.indexOf(a),n=J(s._items,t.index,h),o="swap"===t.action?"swap":"move",(h||n!==this._hBlockedIndex)&&(h?(this._hBlockedIndex=null,r=s._items[n],e._hasListeners("beforeSend")&&e._emit("beforeSend",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("beforeReceive")&&s._emit("beforeReceive",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),a._gridId=s._id,this._isMigrating=a._gridId!==this._gridId,e._items.splice(i,1),$(s._items,a,n),a._sortData=null,e._hasListeners("send")&&e._emit("send",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("receive")&&s._emit("receive",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),"swap"===o&&r&&r.isActive()&&s._items.indexOf(r)>-1&&s.send(r,e,i,{appendTo:this._container||window.document.body,layoutSender:!1,layoutReceiver:!1}),e.layout(),s.layout()):i!==n&&(this._hBlockedIndex=i,("swap"===o?Q:K)(e._items,i,n),e._hasListeners("move")&&e._emit("move",{item:a,fromIndex:i,toIndex:n,action:o}),e.layout())))}},Ot.prototype._finishMigration=function(){var t,e,i=this._item,s=i._release,r=i._element,o=i._isActive,h=i.getGrid(),a=h._element,_=h._settings,l=_.dragContainer||a,d=this._getGrid()._settings,c=r.parentNode;this._isMigrating=!1,this.destroy(),Rt(r,d.itemClass),Rt(r,d.itemVisibleClass),Rt(r,d.itemHiddenClass),j(r,_.itemClass),j(r,o?_.itemVisibleClass:_.itemHiddenClass),l!==c&&(l.appendChild(r),e=ct(c,l,!0),(t=Lt(r)).x-=e.left,t.y-=e.top),i._refreshDimensions(),i._refreshSortData(),e=ct(l,a,!0),s._containerDiffX=e.left,s._containerDiffY=e.top,i._drag=_.dragEnabled?new Ot(i):null,l!==c&&(r.style[n]=xt(t.x,t.y)),i._child.removeAttribute("style"),f(i._child,o?_.visibleStyles:_.hiddenStyles),s.start()},Ot.prototype._preStartCheck=function(t){this._startPredicateState===Yt&&(this._startPredicateState=1),1===this._startPredicateState?(this._startPredicateResult=this._startPredicate(this._item,t),!0===this._startPredicateResult?(this._startPredicateState=2,this._onStart(t)):!1===this._startPredicateResult&&(this._startPredicateState=3)):2===this._startPredicateState&&this._isActive&&this._onMove(t)},Ot.prototype._preEndCheck=function(t){var e=2===this._startPredicateState;this._startPredicate(this._item,t),this._startPredicateState=Yt,e&&this._isActive&&this._onEnd(t)},Ot.prototype._onStart=function(t){var e=this._item;if(e._isActive){var i,s=e._element,r=this._getGrid(),o=r._settings,h=e._release,a=e._migrate,_=r._element,l=o.dragContainer||_,d=ot(l),c=Lt(s),u=c.x,f=c.y,p=s.getBoundingClientRect(),m=l!==_;this._resetHeuristics(t),m&&(i=ct(d,_)),e.isPositioning()&&e._layout.stop(!0,{transform:xt(u,f)}),a._isActive&&(u-=a._containerDiffX,f-=a._containerDiffY,a.stop(!0,{transform:xt(u,f)})),e.isReleasing()&&h._reset(),this._isActive=!0,this._dragEvent=t,this._container=l,this._containingBlock=d,this._elementClientX=p.left,this._elementClientY=p.top,this._left=this._gridX=u,this._top=this._gridY=f,o.dragPlaceholder.enabled&&e._dragPlaceholder.create(),r._emit("dragInit",e,t),m&&(this._containerDiffX=i.left,this._containerDiffY=i.top,s.parentNode===l?(this._gridX=u-this._containerDiffX,this._gridY=f-this._containerDiffY):(this._left=u+this._containerDiffX,this._top=f+this._containerDiffY,l.appendChild(s),s.style[n]=xt(this._left,this._top))),j(s,o.itemDraggingClass),this._bindScrollListeners(),r._emit("dragStart",e,t)}},Ot.prototype._onMove=function(t){var e=this._item;if(e._isActive){var i,s,n,r=this._getGrid()._settings.dragAxis;if("y"!==r){var o=t.clientX-this._dragEvent.clientX;this._left+=o,this._gridX+=o,this._elementClientX+=o}if("x"!==r){var h=t.clientY-this._dragEvent.clientY;this._top+=h,this._gridY+=h,this._elementClientY+=h}this._dragEvent=t,i=e._id,s=this._prepareMove,n=this._applyMove,k.add(i+O,s,n,!0)}else this.stop()},Ot.prototype._prepareMove=function(){this._item._isActive&&this._getGrid()._settings.dragSort&&this._checkHeuristics(this._dragEvent)&&this._checkOverlapDebounce()},Ot.prototype._applyMove=function(){var t=this._item;t._isActive&&(t._element.style[n]=xt(this._left,this._top),this._getGrid()._emit("dragMove",t,this._dragEvent))},Ot.prototype._onScroll=function(t){var e,i,s,n=this._item;n._isActive?(this._scrollEvent=t,e=n._id,i=this._prepareScroll,s=this._applyScroll,k.add(e+G,i,s,!0)):this.stop()},Ot.prototype._prepareScroll=function(){var t=this._item;if(t._isActive){var e,i=t._element,s=this._getGrid(),n=s._settings,r=n.dragAxis,o=s._element,h=i.getBoundingClientRect(),a=this._elementClientX-h.left,_=this._elementClientY-h.top;this._container!==o&&(e=ct(this._containingBlock,o),this._containerDiffX=e.left,this._containerDiffY=e.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()}},Ot.prototype._applyScroll=function(){var t=this._item;t._isActive&&(t._element.style[n]=xt(this._left,this._top),this._getGrid()._emit("dragScroll",t,this._scrollEvent))},Ot.prototype._onEnd=function(t){var e=this._item,i=e._element,s=this._getGrid(),n=s._settings,r=e._release;e._isActive?(N(e._id),q(e._id),n.dragSort&&this._checkOverlapDebounce("finish"),this._unbindScrollListeners(),r._containerDiffX=this._containerDiffX,r._containerDiffY=this._containerDiffY,this._reset(),Rt(i,n.itemDraggingClass),s._emit("dragEnd",e,t),this._isMigrating?this._finishMigration():r.start()):this.stop()},Ht.prototype._onLayoutStart=function(){var t=this._item,e=t.getGrid(),i=e._items.indexOf(t),s=e._layout.slots[2*i],n=e._layout.slots[2*i+1];if(this._didMigrate||t._left!==s||t._top!==n){var r,o,h;if(s+=t._marginLeft,n+=t._marginTop,!(e._settings.dragPlaceholder.duration>0)||this._didMigrate){F(t._id);var a={transform:xt(s,n)};return this._animate.isAnimating()?this._animate.stop(a):f(this._element,a),void(this._didMigrate&&(e.getElement().appendChild(this._element),this._didMigrate=!1))}this._nextLeft=s,this._nextTop=n,r=t._id,o=this._setupAnimation,h=this._startAnimation,k.add(r+H,o,h)}},Ht.prototype._setupAnimation=function(){if(this.isActive()){var t=Lt(this._element);this._currentLeft=t.x,this._currentTop=t.y}},Ht.prototype._startAnimation=function(){if(this.isActive()){var t=this._animate,e=this._currentLeft,i=this._currentTop,s=this._nextLeft,n=this._nextTop,r={transform:xt(s,n)};if(e!==s||i!==n){var o=this._item.getGrid()._settings.dragPlaceholder,h={transform:xt(e,i)};t.start(h,r,{duration:o.duration,easing:o.easing,onFinish:this._onLayoutEnd})}else t.isAnimating()&&t.stop(r)}},Ht.prototype._onLayoutEnd=function(){this._resetAfterLayout&&this.reset()},Ht.prototype._onReleaseEnd=function(t){if(t._id===this._item._id){if(!this._animate.isAnimating())return void this.reset();this._resetAfterLayout=!0}},Ht.prototype._onMigrate=function(t){if(t.item===this._item){var e=this._item.getGrid(),i=t.toGrid;e.off("dragReleaseEnd",this._onReleaseEnd),e.off("layoutStart",this._onLayoutStart),e.off("beforeSend",this._onMigrate),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("layoutStart",this._onLayoutStart),i.on("beforeSend",this._onMigrate),this._didMigrate=!0}},Ht.prototype.create=function(){if(this.isActive())this._resetAfterLayout=!1;else{var t,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;t=c(s.dragPlaceholder.createElement)?s.dragPlaceholder.createElement(e):window.document.createElement("div"),this._element=t,n._element=t,this._className=s.itemPlaceholderClass||"",this._className&&j(t,this._className);var r=e._left+e._marginLeft,o=e._top+e._marginTop;f(t,{display:"block",position:"absolute",left:"0",top:"0",width:e._width+"px",height:e._height+"px",transform:xt(r,o)}),i.on("layoutStart",this._onLayoutStart),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("beforeSend",this._onMigrate),c(s.dragPlaceholder.onCreate)&&s.dragPlaceholder.onCreate(e,t),i.getElement().appendChild(t)}},Ht.prototype.reset=function(){if(this.isActive()){var t=this._element,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;this._resetAfterLayout=!1,F(e._id),n.stop(),n._element=null,i.off("dragReleaseEnd",this._onReleaseEnd),i.off("layoutStart",this._onLayoutStart),i.off("beforeSend",this._onMigrate),this._className&&(Rt(t,this._className),this._className=""),t.parentNode.removeChild(t),this._element=null,c(s.dragPlaceholder.onRemove)&&s.dragPlaceholder.onRemove(e,t)}},Ht.prototype.updateDimensions=function(t,e){this.isActive()&&f(this._element,{width:t+"px",height:e+"px"})},Ht.prototype.isActive=function(){return!!this._element},Ht.prototype.destroy=function(){this.reset(),this._animate.destroy(),this._item=this._animate=null},Bt.prototype.add=function(t){return this._isDestroyed?this:(this._queue.push(t),this)},Bt.prototype.flush=function(t,e){if(this._isDestroyed)return this;var i,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,e),this;for(i=0;i0;return l&&this._queue.flush(!0,o),d&&(a._isPositioningStarted=!0),c(e)&&this._queue.add(e),m?(this._isActive=!0,this._animateOptions.easing=p,this._animateOptions.duration=u,this._isInterrupted=l,s=o._id,n=this._setupAnimation,r=this._startAnimation,k.add(s+X,n,r),this):(this._updateOffsets(),this._updateTargetStyles(),i=o._animate.isAnimating(),this.stop(!1,this._targetStyles),!i&&f(h,this._targetStyles),this._skipNextAnimation=!1,this._finish())}},Nt.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item;return i=s._id,k.cancel(i+X),s._animate.stop(e),Rt(s._element,s.getGrid()._settings.itemPositioningClass),this._isActive=!1,t&&this._queue.flush(!0,s),this},Nt.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)},Nt.prototype._updateOffsets=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._offsetLeft=i._isActive?i._containerDiffX:e._isActive?e._containerDiffX:0,this._offsetTop=i._isActive?i._containerDiffY:e._isActive?e._containerDiffY:0}},Nt.prototype._updateTargetStyles=function(){this._isDestroyed||(this._targetStyles.transform=xt(this._item._left+this._offsetLeft,this._item._top+this._offsetTop))},Nt.prototype._finish=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._isActive&&(this._isActive=!1,Rt(t._element,t.getGrid()._settings.itemPositioningClass)),i._isActive&&i.stop(),e._isActive&&e.stop(),this._queue.flush(!1,t)}},Nt.prototype._setupAnimation=function(){var t=Lt(this._item._element);this._currentLeft=t.x,this._currentTop=t.y},Nt.prototype._startAnimation=function(){var t=this._item,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||j(t._element,e.itemPositioningClass),this._currentStyles.transform=xt(this._currentLeft,this._currentTop),t._animate.start(this._currentStyles,this._targetStyles,this._animateOptions)},qt.prototype.start=function(t,e,i){if(this._isDestroyed)return this;var s,r,o,h,a,_,l,d,c=this._item,u=c._element,p=c.isVisible(),m=c.getGrid(),g=m._settings,y=t._settings,v=t._element,w=t._items,S=m._items.indexOf(c),b=i||window.document.body;if("number"==typeof e)s=J(w,e,!0);else{if(!(r=t._getItem(e)))return this;s=w.indexOf(r)}return(c.isPositioning()||this._isActive||c.isReleasing())&&(l=(_=Lt(u)).x,d=_.y),c.isPositioning()&&c._layout.stop(!0,{transform:xt(l,d)}),this._isActive&&(l-=this._containerDiffX,d-=this._containerDiffY,this.stop(!0,{transform:xt(l,d)})),c.isReleasing()&&(l-=c._release._containerDiffX,d-=c._release._containerDiffY,c._release.stop(!0,{transform:xt(l,d)})),c._visibility._stopAnimation(),c._drag&&c._drag.destroy(),c._visibility._queue.flush(!0,c),m._hasListeners("beforeSend")&&m._emit("beforeSend",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("beforeReceive")&&t._emit("beforeReceive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),Rt(u,g.itemClass),Rt(u,g.itemVisibleClass),Rt(u,g.itemHiddenClass),j(u,y.itemClass),j(u,p?y.itemVisibleClass:y.itemHiddenClass),m._items.splice(S,1),$(w,c,s),c._gridId=t._id,b!==(o=u.parentNode)&&(b.appendChild(u),h=ct(b,o,!0),_||(l=(_=Lt(u)).x,d=_.y),u.style[n]=xt(l+h.left,d+h.top)),c._child.removeAttribute("style"),f(c._child,p?y.visibleStyles:y.hiddenStyles),u.style.display=p?"block":"hidden",a=ct(b,v,!0),c._refreshDimensions(),c._refreshSortData(),c._drag=y.dragEnabled?new Ot(c):null,this._isActive=!0,this._container=b,this._containerDiffX=a.left,this._containerDiffY=a.top,m._hasListeners("send")&&m._emit("send",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("receive")&&t._emit("receive",{item:c,fromGrid:m,fromIndex:S,toGrid:t,toIndex:s}),this},qt.prototype.stop=(kt={},function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid()._element;return this._container!==r&&(e||(t?(i=Lt(n),kt.transform=xt(i.x-this._containerDiffX,i.y-this._containerDiffY)):kt.transform=xt(s._left,s._top),e=kt),r.appendChild(n),f(n,e)),this._isActive=!1,this._container=null,this._containerDiffX=0,this._containerDiffY=0,this}),qt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)},Ft.prototype.start=function(){if(this._isDestroyed||this._isActive)return this;var t=this._item,e=t.getGrid();return this._isActive=!0,j(t._element,e._settings.itemReleasingClass),e._emit("dragReleaseStart",t),t._layout.start(!1),this},Ft.prototype.stop=function(){var t={transform:""};return function(e,i){if(this._isDestroyed||!this._isActive)return this;var s,n=this._item,r=n._element,o=n.getGrid(),h=o._element;return this._reset(),r.parentNode!==h&&(i||(e?(s=Lt(r),t.transform=xt(s.x-this._containerDiffX,s.y-this._containerDiffY)):t.transform=xt(n._left,n._top),i=t),h.appendChild(r),f(r,i)),e||o._emit("dragReleaseEnd",n),this}}(),Ft.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)},Ft.prototype._reset=function(){if(!this._isDestroyed){var t=this._item;this._isActive=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0,Rt(t._element,t.getGrid()._settings.itemReleasingClass)}},zt.prototype.show=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return this._isShowing||this._isHidden?this._isShowing&&!t?(r&&n.add(r),this):(this._isShowing||(n.flush(!0,i),Rt(s,o.itemHiddenClass),j(s,o.itemVisibleClass),this._isHiding||(s.style.display="block")),r&&n.add(r),i._isActive=this._isShowing=!0,this._isHiding=this._isHidden=!1,this._startAnimation(!0,t,this._finishShow),this):(r&&r(!1,i),this)},zt.prototype.hide=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return!this._isHiding&&this._isHidden?(r&&r(!1,i),this):this._isHiding&&!t?(r&&n.add(r),this):(this._isHiding||(n.flush(!0,i),j(s,o.itemHiddenClass),Rt(s,o.itemVisibleClass)),r&&n.add(r),this._isHidden=this._isHiding=!0,i._isActive=this._isShowing=!1,this._startAnimation(!1,t,this._finishHide),this)},zt.prototype.destroy=function(){if(this._isDestroyed)return this;var t=this._item,e=t._element,i=t.getGrid(),s=this._queue,n=i._settings;return this._stopAnimation({}),s.flush(!0,t).destroy(),Rt(e,n.itemVisibleClass),Rt(e,n.itemHiddenClass),this._item=null,this._isHiding=this._isShowing=!1,this._isDestroyed=this._isHidden=!0,this},zt.prototype._startAnimation=function(t,e,i){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,_=(t?r.showEasing:r.hideEasing)||"ease",d=e||h<=0;if(o){if(B(n._id),d)return n._animateChild.isAnimating()?n._animateChild.stop(o):f(n._child,o),void(i&&i());var c,u,p;c=n._id,u=function(){s=function(t,e){var i={};for(var s in e)i[s]=a(t,l(s));return i}(n._child,o)},p=function(){n._animateChild.start(s,o,{duration:h,easing:_,onFinish:i})},k.add(c+Y,u,p)}else i&&i()}},zt.prototype._stopAnimation=function(t){if(!this._isDestroyed){var e=this._item;B(e._id),e._animateChild.stop(t)}},zt.prototype._finishShow=function(){this._isHidden||(this._isShowing=!1,this._queue.flush(!1,this._item))},zt.prototype._finishHide=(Xt={transform:xt(0,0)},function(){if(this._isHidden){var t=this._item;this._isHiding=!1,t._layout.stop(!0,Xt),t._element.style.display="none",this._queue.flush(!1,t)}});var Vt,Wt,jt,Ut,Zt=0;function $t(){return++Zt}function Jt(t,e,i){var s=t._settings;this._id=$t(),this._gridId=t._id,this._isDestroyed=!1,this._left=0,this._top=0,this._element=e,this._child=e.children[0],e.parentNode!==t._element&&t._element.appendChild(e),j(e,s.itemClass),"boolean"!=typeof i&&(i="none"!==a(e,"display")),this._isActive=i,e.style.left="0",e.style.top="0",e.style[n]=xt(0,0),this._animate=new p(e),this._animateChild=new p(this._child),this._visibility=new zt(this),this._layout=new Nt(this),this._migrate=new qt(this),this._release=new Ft(this),this._dragPlaceholder=new Ht(this),this._drag=s.dragEnabled?new Ot(this):null,this._refreshDimensions(),this._refreshSortData()}function Kt(){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)}Jt.prototype.getGrid=function(){return t[this._gridId]},Jt.prototype.getElement=function(){return this._element},Jt.prototype.getWidth=function(){return this._width},Jt.prototype.getHeight=function(){return this._height},Jt.prototype.getMargin=function(){return{left:this._marginLeft,right:this._marginRight,top:this._marginTop,bottom:this._marginBottom}},Jt.prototype.getPosition=function(){return{left:this._left,top:this._top}},Jt.prototype.isActive=function(){return this._isActive},Jt.prototype.isVisible=function(){return!!this._visibility&&!this._visibility._isHidden},Jt.prototype.isShowing=function(){return!(!this._visibility||!this._visibility._isShowing)},Jt.prototype.isHiding=function(){return!(!this._visibility||!this._visibility._isHiding)},Jt.prototype.isPositioning=function(){return!(!this._layout||!this._layout._isActive)},Jt.prototype.isDragging=function(){return!(!this._drag||!this._drag._isActive)},Jt.prototype.isReleasing=function(){return!(!this._release||!this._release._isActive)},Jt.prototype.isDestroyed=function(){return this._isDestroyed},Jt.prototype._refreshDimensions=function(){if(!this._isDestroyed&&!this._visibility._isHidden){var t=this._element,e=this._dragPlaceholder,i=t.getBoundingClientRect();this._width=i.width,this._height=i.height,this._marginLeft=Math.max(0,ht(t,"margin-left")),this._marginRight=Math.max(0,ht(t,"margin-right")),this._marginTop=Math.max(0,ht(t,"margin-top")),this._marginBottom=Math.max(0,ht(t,"margin-bottom")),e&&e.updateDimensions(this._width,this._height)}},Jt.prototype._refreshSortData=function(){if(!this._isDestroyed){var t,e=this._sortData={},i=this.getGrid()._settings.sortData;for(t in i)e[t]=i[t](this,this._element)}},Jt.prototype._destroy=function(t){if(!this._isDestroyed){var e=this._element,i=this.getGrid(),s=i._settings,n=i._items.indexOf(this);this._release.destroy(),this._migrate.destroy(),this._layout.destroy(),this._visibility.destroy(),this._animate.destroy(),this._animateChild.destroy(),this._dragPlaceholder.destroy(),this._drag&&this._drag.destroy(),e.removeAttribute("style"),this._child.removeAttribute("style"),Rt(e,s.itemClass),n>-1&&i._items.splice(n,1),t&&e.parentNode.removeChild(e),this._isActive=!1,this._isDestroyed=!0}},Kt.prototype.getLayout=function(t,e,i,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),c=this._slotSizes;if(o.slots=s||this._slots,o.width=a?0:d?Math.round(e):e,o.height=a?d?Math.round(i):i:0,o.setWidth=a,o.setHeight=!a,o.slots.length=0,c.length=0,!t.length)return o;for(r=0;rd.height&&(Vt.left>0&&u.push(this._addRect(0,d.height,Vt.left,1/0)),Vt.left+Vt.widthd.width&&(Vt.top>0&&u.push(this._addRect(d.width,0,1/0,Vt.top)),Vt.top+Vt.height.49&&r.height>.49&&(!e&&r.tope.left+e.width&&Wt.push(this._addRect(e.left+e.width,t.top,t.left+t.width-(e.left+e.width),t.height)),t.tope.top+e.height&&Wt.push(this._addRect(t.left,e.top+e.height,t.width,t.top+t.height-(e.top+e.height))),Wt):(Wt.push(this._addRect(t.left,t.top,t.width,t.height)),Wt)}),Kt.prototype._doRectsOverlap=function(t,e){return!(t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top)},Kt.prototype._isRectWithinRect=function(t,e){return t.left>=e.left&&t.top>=e.top&&t.left+t.width<=e.left+e.width&&t.top+t.height<=e.top+e.height},Kt.prototype._purgeRects=(jt={},Ut={},function(t){for(var e,i=t.length;i--;)if(e=t.length,t[i])for(this._getRect(t[i],jt);e--;)if(t[e]&&i!==e&&this._isRectWithinRect(jt,this._getRect(t[e],Ut))){t[i]=0;break}return t}),Kt.prototype._sortRectsTopLeft=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.tope.top?1:t.lefte.left?1:0}}(),Kt.prototype._sortRectsLeftTop=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.lefte.left?1:t.tope.top?1:0}}();var Qt="[object HTMLCollection]",te="[object NodeList]";function ee(t){var e=Object.prototype.toString.call(t);return e===Qt||e===te}var ie="object",se="[object Object]",ne=Object.prototype.toString;function re(t){return typeof t===ie&&ne.call(t)===se}function oe(t){return ee(t)?Array.prototype.slice.call(t):Array.prototype.concat(t)}var he=new Kt,ae=function(){},_e="number",le="string";function de(e,s){var n,r,o=this;if(typeof e===le&&(e=window.document.querySelector(e)),this._element=e,!(e.getRootNode?e.getRootNode({composed:!0})===document:window.document.body.contains(e))||e===window.document.documentElement)throw new Error("Container element must be an existing DOM element");c((n=this._settings=ce(de.defaultOptions,s)).dragSort)||(n.dragSort=!!n.dragSort),this._id=$t(),t[this._id]=o,this._isDestroyed=!1,this._layout={id:0,items:[],slots:[],setWidth:!1,setHeight:!1,width:0,height:0},this._emitter=new i,j(e,n.containerClass),this._items=[],typeof(r=n.items)===le?oe(e.children).forEach(function(t){("*"===r||W(t,r))&&o._items.push(new Jt(o,t))}):(Array.isArray(r)||ee(r))&&(this._items=oe(r).map(function(t){return new Jt(o,t)})),fe(this,n.layoutOnResize),n.layoutOnInit&&this.layout(!0)}function ce(t,e){var i=ue({},t);return e&&(i=ue(i,e)),i.visibleStyles=(e||0).visibleStyles||(t||0).visibleStyles,i.hiddenStyles=(e||0).hiddenStyles||(t||0).hiddenStyles,i}function ue(t,e){var i,s,n,r=Object.keys(e),o=r.length;for(n=0;n=0&&(t._resizeHandler=nt(function(){t.refreshItems().layout()},e),window.addEventListener("resize",t._resizeHandler))}function pe(t){t._resizeHandler&&(t._resizeHandler("cancel"),window.removeEventListener("resize",t._resizeHandler),t._resizeHandler=null)}return de.Item=Jt,de.ItemLayout=Nt,de.ItemVisibility=zt,de.ItemMigrate=qt,de.ItemAnimate=p,de.ItemDrag=Ot,de.ItemRelease=Ft,de.ItemDragPlaceholder=Ht,de.Emitter=i,de.Dragger=M,de.Packer=Kt,de.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,dragSortHeuristics:{sortInterval:100,minDragDistance:10,minBounceBackAngle:1},dragSortPredicate:{threshold:50,action:"move",migrateAction:"move"},dragReleaseDuration:300,dragReleaseEasing:"ease",dragCssProps:{touchAction:"none",userSelect:"none",userDrag:"none",tapHighlightColor:"rgba(0, 0, 0, 0)",touchCallout:"none",contentZooming:"none"},dragPlaceholder:{enabled:!1,duration:300,easing:"ease",createElement:null,onCreate:null,onRemove:null},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",itemPlaceholderClass:"muuri-item-placeholder"},de.prototype.on=function(t,e){return this._emitter.on(t,e),this},de.prototype.off=function(t,e){return this._emitter.off(t,e),this},de.prototype.getElement=function(){return this._element},de.prototype.getItems=function(t){if(this._isDestroyed||!t&&0!==t)return this._items.slice(0);var e,i,s=[],n=oe(t);for(i=0;i-1){if(r.dragEnabled&&!o.dragEnabled){for(this._settings=r,e=0;e-1&&r.dragEnabled&&o.dragEnabled)for(e=0;e-1&&r.containerClass!==o.containerClass&&(Rt(s,r.containerClass),j(s,o.containerClass)),n.indexOf("sortData")>-1)for(e=0;e-1&&(pe(this),fe(this,o.layoutOnResize)),o},de.prototype.refreshItems=function(t){if(this._isDestroyed)return this;var e,i=this.getItems(t);for(e=0;e0)){var s=o._layout.id!==l,n=c(t)?t:i;c(n)&&n(s,_.items.slice(0)),!s&&o._hasListeners(e)&&o._emit(e,_.items.slice(0))}}if((_.setHeight&&typeof _.height===_e||_.setWidth&&typeof _.width===_e)&&(s="border-box"===a(h,"box-sizing")),_.setHeight&&(typeof _.height===_e?h.style.height=(s?_.height+this._borderTop+this._borderBottom:_.height)+"px":h.style.height=_.height),_.setWidth&&(typeof _.width===_e?h.style.width=(s?_.width+this._borderLeft+this._borderRight:_.width)+"px":h.style.width=_.width),this._hasListeners("layoutStart")&&this._emit("layoutStart",_.items.slice(0)),!d)return f(),this;for(r=0;rl?1:0:ld?1:0)return c;return c||(s||(s=n(i)),c=r(o,h)),c}function h(o,h){var a=t(o,h);return e&&a&&(a=-a),a||(s||(s=n(i)),r(o,h))}return function(n,r){if(this._isDestroyed||this._items.length<2)return this;var a,_=this._items,l=r||0,d=l.layout?l.layout:void 0===l.layout;if(t=n,e=!!l.descending,i=_.slice(0),s=null,c(t))_.sort(h);else if(typeof t===le)t=n.trim().split(" ").map(function(t){return t.split(":")}),_.sort(o);else{if(!Array.isArray(t))return this;if(t.length!==_.length)throw new Error("[Muuri] sort reference items do not match with grid items.");for(a=0;a<_.length;a++){if(t.indexOf(_[a])<0)throw new Error("[Muuri] sort reference items do not match with grid items.");_[a]=t[a]}e&&_.reverse()}return this._hasListeners("sort")&&this._emit("sort",_.slice(0),i),d&&this.layout("instant"===d,c(d)?d:void 0),this}}(),de.prototype.move=function(t,e,i){if(this._isDestroyed||this._items.length<2)return this;var s,n,r=this._items,o=i||0,h=o.layout?o.layout:void 0===o.layout,a="swap"===o.action,_=a?"swap":"move",l=this._getItem(t),d=this._getItem(e);return l&&d&&l!==d&&(s=r.indexOf(l),n=r.indexOf(d),a?Q(r,s,n):K(r,s,n),this._hasListeners("move")&&this._emit("move",{item:l,fromIndex:s,toIndex:n,action:_}),h&&this.layout("instant"===h,c(h)?h:void 0)),this},de.prototype.send=function(t,e,i,s){if(this._isDestroyed||e._isDestroyed||this===e)return this;if(!(t=this._getItem(t)))return this;var n=s||0,r=n.appendTo||window.document.body,o=n.layoutSender?n.layoutSender:void 0===n.layoutSender,h=n.layoutReceiver?n.layoutReceiver:void 0===n.layoutReceiver;return t._migrate.start(e,i,r),t._migrate._isActive&&t._isActive&&(o&&this.layout("instant"===o,c(o)?o:void 0),h&&e.layout("instant"===h,c(h)?h:void 0)),this},de.prototype.destroy=function(e){if(this._isDestroyed)return this;var i,s=this._element,n=this._items.slice(0);for(pe(this),i=0;i-1?t:this._items.length+t]||null;if(t instanceof Jt)return t._gridId===this._id?t:null;for(var e=0;e-1||(M._activeInstances.push(t),M._emitter.on(b,t._onMove),M._emitter.on(A,t._onCancel),M._emitter.on(D,t._onEnd),1===M._activeInstances.length&&M._bindListeners())},M._deactivateInstance=function(t){var e=M._activeInstances.indexOf(t);-1!==e&&(M._activeInstances.splice(e,1),M._emitter.off(b,t._onMove),M._emitter.off(A,t._onCancel),M._emitter.off(D,t._onEnd),M._activeInstances.length||M._unbindListeners())},M._bindListeners=function(){var t=M._events;window.addEventListener(t.move,M._onMove,R),window.addEventListener(t.end,M._onEnd,R),t.cancel&&window.addEventListener(t.cancel,M._onCancel,R)},M._unbindListeners=function(){var t=M._events;window.removeEventListener(t.move,M._onMove,R),window.removeEventListener(t.end,M._onEnd,R),t.cancel&&window.removeEventListener(t.cancel,M._onCancel,R)},M._getEventPointerId=function(t){return"number"==typeof t.pointerId?t.pointerId:t.changedTouches?t.changedTouches[0]?t.changedTouches[0].identifier:null:1},M._getTouchById=function(t,e){if("number"==typeof t.pointerId)return t.pointerId===e?t:null;if(t.changedTouches){for(var i=0;i-1&&(this._queue[n]=void 0),s?this._queue.unshift(t):this._queue.push(t),this._reads[t]=e,this._writes[t]=i,this._nextStep||(this._nextStep=y(this._step))},T.prototype.cancel=function(t){var e=this._queue.indexOf(t);e>-1&&(this._queue[e]=void 0,delete this._reads[t],delete this._writes[t])},T.prototype._step=function(){var t,e,i=this._queue,s=this._reads,n=this._writes,r=this._batch,o=this._batchReads,h=this._batchWrites,a=i.length;for(this._nextStep=null,e=0;en?n:e<0?Math.max(n+e+1,0):e}function J(t,e,i){if(!(t.length<2)){var s=$(t,e),n=$(t,i);s!==n&&t.splice(n,0,t.splice(s,1)[0])}}function K(t,e,i){if(!(t.length<2)){var s,n=$(t,e),r=$(t,i);n!==r&&(s=t[n],t[n]=t[r],t[r]=s)}}var tt="cancel",et="finish",it="debounce",st=0;function nt(t,e){var i,s=++st+it;return e>0?function(n){void 0!==i&&(i=window.clearTimeout(i),k.cancel(s),n===et&&t()),n!==tt&&n!==et&&(i=window.setTimeout(function(){i=void 0,k.add(s,t,null,!0)},e))}:function(e){e!==tt&&t()}}function rt(t){var e=a(t,"transform");if(!e||"none"===e)return!1;var i=a(t,"display");return"inline"!==i&&"none"!==i}function ot(t){for(var e=window.document,i=t||e;i&&i!==e&&"static"===a(i,"position")&&!rt(i);)i=i.parentElement||e;return i}function ht(t,e){return parseFloat(a(t,e))||0}var at={},_t={},lt={};function dt(t,e){var i,s=e||{};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:(i=t.getBoundingClientRect(),s.left+=i.left,s.top+=i.top,s.left+=ht(t,"border-left-width"),s.top+=ht(t,"border-top-width"),s))}function ct(t,e,i){return lt.left=0,lt.top=0,t===e?lt:i&&(t=ot(t))===(e=ot(e))?lt:(dt(t,at),dt(e,_t),lt.left=_t.left-at.left,lt.top=_t.top-at.top,lt)}var ut="overflow",ft="overflow-x",pt="overflow-y",gt="auto",mt="scroll";function yt(t){var e=a(t,ut);return e===gt||e===mt||((e=a(t,ft))===gt||e===mt||((e=a(t,pt))===gt||e===mt))}function vt(t,e){for(e=e||[];t&&t!==window.document;)t.getRootNode&&t instanceof DocumentFragment?t=t.getRootNode().host:(yt(t)&&e.push(t),t=t.parentNode);return e.push(window),e}var wt={},St="transform",bt="none",Dt=/^matrix3d/,At=/([^,]*,){4}/,Et=/([^,]*,){12}/,Ct=/[^,]*,/;function Lt(t){wt.x=0,wt.y=0;var e=a(t,St);if(!e||e===bt)return wt;var i=Dt.test(e),s=e.replace(i?Et:At,""),n=s.replace(Ct,"");return wt.x=parseFloat(s)||0,wt.y=parseFloat(n)||0,wt}function xt(t,e){return"translateX("+t+"px) translateY("+e+"px)"}function Rt(t,e){t.classList?t.classList.remove(e):W(t,"."+e)&&(t.className=(" "+t.className+" ").replace(" "+e+" "," ").trim())}var It,Pt,Mt,Tt,kt,Xt,Yt=0;function Ot(t){var e=t._element,i=t.getGrid(),s=i._settings;this._item=t,this._gridId=i._id,this._isDestroyed=!1,this._isMigrating=!1,this._startPredicate=c(s.dragStartPredicate)?s.dragStartPredicate:Ot.defaultStartPredicate,this._startPredicateState=Yt,this._startPredicateResult=void 0,this._hBlockedIndex=null,this._hX1=0,this._hX2=0,this._hY1=0,this._hY2=0,this._reset(),this._preStartCheck=this._preStartCheck.bind(this),this._preEndCheck=this._preEndCheck.bind(this),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);var n=s.dragSortHeuristics.sortInterval;this._checkOverlapDebounce=nt(this._checkOverlap,n),this._dragger=new M(e,s.dragCssProps),this._dragger.on("start",this._preStartCheck),this._dragger.on("move",this._preStartCheck),this._dragger.on("cancel",this._preEndCheck),this._dragger.on("end",this._preEndCheck)}function Gt(t,e){return t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top?0:(Math.min(t.left+t.width,e.left+e.width)-Math.max(t.left,e.left))*(Math.min(t.top+t.height,e.top+e.height)-Math.max(t.top,e.top))/(Math.min(t.width,e.width)*Math.min(t.height,e.height))*100}function Ht(t){this._item=t,this._animate=new p,this._element=null,this._className="",this._didMigrate=!1,this._resetAfterLayout=!1,this._currentLeft=0,this._currentTop=0,this._nextLeft=0,this._nextTop=0,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this),this._onLayoutStart=this._onLayoutStart.bind(this),this._onLayoutEnd=this._onLayoutEnd.bind(this),this._onReleaseEnd=this._onReleaseEnd.bind(this),this._onMigrate=this._onMigrate.bind(this)}function Bt(){this._queue=[],this._processQueue=[],this._processCounter=0,this._isDestroyed=!1}function Nt(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 Bt,this._setupAnimation=this._setupAnimation.bind(this),this._startAnimation=this._startAnimation.bind(this)}function qt(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._container=!1,this._containerDiffX=0,this._containerDiffY=0}function Ft(t){this._item=t,this._isActive=!1,this._isDestroyed=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0}function zt(t){var e=t._isActive,i=t._element,s=t.getGrid()._settings;this._item=t,this._isDestroyed=!1,this._isHidden=!e,this._isHiding=!1,this._isShowing=!1,this._queue=new Bt,this._finishShow=this._finishShow.bind(this),this._finishHide=this._finishHide.bind(this),i.style.display=e?"block":"none",j(i,e?s.itemVisibleClass:s.itemHiddenClass),f(t._child,e?s.visibleStyles:s.hiddenStyles)}Ot.defaultStartPredicate=function(t,e,i){var s=t._drag;if(!s._startPredicateData){var n=i||s._getGrid()._settings.dragStartPredicate||{};s._startPredicateData={distance:Math.max(n.distance,0)||0,delay:Math.max(n.delay,0)||0,handle:"string"==typeof n.handle&&n.handle}}var r=s._startPredicateData;if(!e.isFinal)return!(!r.handleElement&&(r.handleElement=s._getStartPredicateHandle(e),!r.handleElement))&&(r.delay&&(r.event=e,r.delayTimer||(r.delayTimer=window.setTimeout(function(){r.delay=0,s._resolveStartPredicate(r.event)&&(s._forceResolveStartPredicate(r.event),s._resetStartPredicate())},r.delay))),s._resolveStartPredicate(e));s._finishStartPredicate(e)},Ot.defaultSortPredicate=(It={},Pt={},Mt={},Tt=[],function(t,e){var i=t._drag,s=i._getGrid(),n=e&&"number"==typeof e.threshold?e.threshold:50,r=e&&"swap"===e.action?"swap":"move",o=e&&"swap"===e.migrateAction?"swap":"move";n=Math.min(Math.max(n,1),100),It.width=t._width,It.height=t._height,It.left=i._elementClientX,It.top=i._elementClientY;var h=function(t,e,i){var s,n,r,o,h=null,a=e._settings.dragSort,_=-1;if(!0===a?(Tt[0]=e,n=Tt):c(a)&&(n=a.call(e,t)),!n||!Array.isArray(n)||!n.length)return h;for(o=0;oi&&s>_&&(_=s,h=r));return Tt.length=0,h}(t,s,n);if(!h)return!1;var a,_,l,d=t.getGrid()!==h,u=0,f=0,p=0,g=-1,m=!1;for(h===s?(It.left=i._gridX+t._marginLeft,It.top=i._gridY+t._marginTop):(h._updateBorders(1,0,1,0),u=h._left+h._borderLeft,f=h._top+h._borderTop),l=0;lp&&(g=l,p=_));return d&&p=n&&(Mt.grid=h,Mt.index=g,Mt.action=d?o:r,Mt)}),Ot.prototype.stop=function(){var t=this._item,e=t._element,i=this._getGrid();return this._isActive?this._isMigrating?(this._finishMigration(),this):(N(t._id),q(t._id),this._unbindScrollListeners(),this._checkOverlapDebounce("cancel"),e.parentNode!==i._element&&(i._element.appendChild(e),e.style[n]=xt(this._gridX,this._gridY)),Rt(e,i._settings.itemDraggingClass),this._reset(),this):this},Ot.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(),this._dragger.destroy(),this._isDestroyed=!0,this)},Ot.prototype._getGrid=function(){return t[this._gridId]||null},Ot.prototype._reset=function(){this._isActive=!1,this._container=null,this._containingBlock=null,this._dragEvent=null,this._scrollEvent=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},Ot.prototype._bindScrollListeners=function(){var t,e,i=this._getGrid()._element,s=this._container,n=this._scrollers;if(n.length=0,vt(this._item._element.parentNode,n),s!==i)for(vt(i,t=[]),e=0;e=s&&t.pageX=n&&t.pageY3&&e.minBounceBackAngle>0;if(h||(this._hBlockedIndex=null),Math.abs(r)>i||Math.abs(o)>i){if(h){var a=Math.atan2(r,o),_=Math.atan2(this._hX2-this._hX1,this._hY2-this._hY1),l=Math.atan2(Math.sin(a-_),Math.cos(a-_));Math.abs(l)>e.minBounceBackAngle&&(this._hBlockedIndex=null)}return this._hX1=this._hX2,this._hY1=this._hY2,this._hX2=s,this._hY2=n,!0}return!1},Ot.prototype._resetStartPredicate=function(){var t=this._startPredicateData;t&&(t.delayTimer&&(t.delayTimer=window.clearTimeout(t.delayTimer)),this._startPredicateData=null)},Ot.prototype._checkOverlap=function(){if(this._isActive){var t,e,i,s,n,r,o,h,a=this._item,_=this._getGrid()._settings;(t=c(_.dragSortPredicate)?_.dragSortPredicate(a,this._dragEvent):Ot.defaultSortPredicate(a,_.dragSortPredicate))&&"number"==typeof t.index&&(h=(e=a.getGrid())!==(s=t.grid||e),i=e._items.indexOf(a),n=$(s._items,t.index,h),o="swap"===t.action?"swap":"move",(h||n!==this._hBlockedIndex)&&(h?(this._hBlockedIndex=null,r=s._items[n],e._hasListeners("beforeSend")&&e._emit("beforeSend",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("beforeReceive")&&s._emit("beforeReceive",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),a._gridId=s._id,this._isMigrating=a._gridId!==this._gridId,e._items.splice(i,1),Z(s._items,a,n),a._sortData=null,e._hasListeners("send")&&e._emit("send",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),s._hasListeners("receive")&&s._emit("receive",{item:a,fromGrid:e,fromIndex:i,toGrid:s,toIndex:n}),"swap"===o&&r&&r.isActive()&&s._items.indexOf(r)>-1&&s.send(r,e,i,{appendTo:this._container||window.document.body,layoutSender:!1,layoutReceiver:!1}),e.layout(),s.layout()):i!==n&&(this._hBlockedIndex=i,("swap"===o?K:J)(e._items,i,n),e._hasListeners("move")&&e._emit("move",{item:a,fromIndex:i,toIndex:n,action:o}),e.layout())))}},Ot.prototype._finishMigration=function(){var t,e,i=this._item,s=i._release,r=i._element,o=i._isActive,h=i.getGrid(),a=h._element,_=h._settings,l=_.dragContainer||a,d=this._getGrid()._settings,c=r.parentNode;this._isMigrating=!1,this.destroy(),Rt(r,d.itemClass),Rt(r,d.itemVisibleClass),Rt(r,d.itemHiddenClass),j(r,_.itemClass),j(r,o?_.itemVisibleClass:_.itemHiddenClass),l!==c&&(l.appendChild(r),e=ct(c,l,!0),(t=Lt(r)).x-=e.left,t.y-=e.top),i._refreshDimensions(),i._refreshSortData(),e=ct(l,a,!0),s._containerDiffX=e.left,s._containerDiffY=e.top,i._drag=_.dragEnabled?new Ot(i):null,l!==c&&(r.style[n]=xt(t.x,t.y)),i._child.removeAttribute("style"),f(i._child,o?_.visibleStyles:_.hiddenStyles),s.start()},Ot.prototype._preStartCheck=function(t){this._startPredicateState===Yt&&(this._startPredicateState=1),1===this._startPredicateState?(this._startPredicateResult=this._startPredicate(this._item,t),!0===this._startPredicateResult?(this._startPredicateState=2,this._onStart(t)):!1===this._startPredicateResult&&(this._startPredicateState=3)):2===this._startPredicateState&&this._isActive&&this._onMove(t)},Ot.prototype._preEndCheck=function(t){var e=2===this._startPredicateState;this._startPredicate(this._item,t),this._startPredicateState=Yt,e&&this._isActive&&this._onEnd(t)},Ot.prototype._onStart=function(t){var e=this._item;if(e._isActive){var i,s=e._element,r=this._getGrid(),o=r._settings,h=e._release,a=e._migrate,_=r._element,l=o.dragContainer||_,d=ot(l),c=Lt(s),u=c.x,f=c.y,p=s.getBoundingClientRect(),g=l!==_;this._resetHeuristics(t),g&&(i=ct(d,_)),e.isPositioning()&&e._layout.stop(!0,{transform:xt(u,f)}),a._isActive&&(u-=a._containerDiffX,f-=a._containerDiffY,a.stop(!0,{transform:xt(u,f)})),e.isReleasing()&&h._reset(),this._isActive=!0,this._dragEvent=t,this._container=l,this._containingBlock=d,this._elementClientX=p.left,this._elementClientY=p.top,this._left=this._gridX=u,this._top=this._gridY=f,o.dragPlaceholder.enabled&&e._dragPlaceholder.create(),r._emit("dragInit",e,t),g&&(this._containerDiffX=i.left,this._containerDiffY=i.top,s.parentNode===l?(this._gridX=u-this._containerDiffX,this._gridY=f-this._containerDiffY):(this._left=u+this._containerDiffX,this._top=f+this._containerDiffY,l.appendChild(s),s.style[n]=xt(this._left,this._top))),j(s,o.itemDraggingClass),this._bindScrollListeners(),r._emit("dragStart",e,t)}},Ot.prototype._onMove=function(t){var e=this._item;if(e._isActive){var i,s,n,r=this._getGrid()._settings.dragAxis;if("y"!==r){var o=t.clientX-this._dragEvent.clientX;this._left+=o,this._gridX+=o,this._elementClientX+=o}if("x"!==r){var h=t.clientY-this._dragEvent.clientY;this._top+=h,this._gridY+=h,this._elementClientY+=h}this._dragEvent=t,i=e._id,s=this._prepareMove,n=this._applyMove,k.add(i+O,s,n,!0)}else this.stop()},Ot.prototype._prepareMove=function(){this._item._isActive&&this._getGrid()._settings.dragSort&&this._checkHeuristics(this._dragEvent)&&this._checkOverlapDebounce()},Ot.prototype._applyMove=function(){var t=this._item;t._isActive&&(t._element.style[n]=xt(this._left,this._top),this._getGrid()._emit("dragMove",t,this._dragEvent))},Ot.prototype._onScroll=function(t){var e,i,s,n=this._item;n._isActive?(this._scrollEvent=t,e=n._id,i=this._prepareScroll,s=this._applyScroll,k.add(e+G,i,s,!0)):this.stop()},Ot.prototype._prepareScroll=function(){var t=this._item;if(t._isActive){var e,i=t._element,s=this._getGrid(),n=s._settings,r=n.dragAxis,o=s._element,h=i.getBoundingClientRect(),a=this._elementClientX-h.left,_=this._elementClientY-h.top;this._container!==o&&(e=ct(this._containingBlock,o),this._containerDiffX=e.left,this._containerDiffY=e.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()}},Ot.prototype._applyScroll=function(){var t=this._item;t._isActive&&(t._element.style[n]=xt(this._left,this._top),this._getGrid()._emit("dragScroll",t,this._scrollEvent))},Ot.prototype._onEnd=function(t){var e=this._item,i=e._element,s=this._getGrid(),n=s._settings,r=e._release;e._isActive?(N(e._id),q(e._id),n.dragSort&&this._checkOverlapDebounce("finish"),this._unbindScrollListeners(),r._containerDiffX=this._containerDiffX,r._containerDiffY=this._containerDiffY,this._reset(),Rt(i,n.itemDraggingClass),s._emit("dragEnd",e,t),this._isMigrating?this._finishMigration():r.start()):this.stop()},Ht.prototype._onLayoutStart=function(){var t=this._item,e=t.getGrid(),i=e._items.indexOf(t),s=e._layout.slots[2*i],n=e._layout.slots[2*i+1];if(this._didMigrate||t._left!==s||t._top!==n){var r,o,h;if(s+=t._marginLeft,n+=t._marginTop,!(e._settings.dragPlaceholder.duration>0)||this._didMigrate){F(t._id);var a={transform:xt(s,n)};return this._animate.isAnimating()?this._animate.stop(a):f(this._element,a),void(this._didMigrate&&(e.getElement().appendChild(this._element),this._didMigrate=!1))}this._nextLeft=s,this._nextTop=n,r=t._id,o=this._setupAnimation,h=this._startAnimation,k.add(r+H,o,h)}},Ht.prototype._setupAnimation=function(){if(this.isActive()){var t=Lt(this._element);this._currentLeft=t.x,this._currentTop=t.y}},Ht.prototype._startAnimation=function(){if(this.isActive()){var t=this._animate,e=this._currentLeft,i=this._currentTop,s=this._nextLeft,n=this._nextTop,r={transform:xt(s,n)};if(e!==s||i!==n){var o=this._item.getGrid()._settings.dragPlaceholder,h={transform:xt(e,i)};t.start(h,r,{duration:o.duration,easing:o.easing,onFinish:this._onLayoutEnd})}else t.isAnimating()&&t.stop(r)}},Ht.prototype._onLayoutEnd=function(){this._resetAfterLayout&&this.reset()},Ht.prototype._onReleaseEnd=function(t){if(t._id===this._item._id){if(!this._animate.isAnimating())return void this.reset();this._resetAfterLayout=!0}},Ht.prototype._onMigrate=function(t){if(t.item===this._item){var e=this._item.getGrid(),i=t.toGrid;e.off("dragReleaseEnd",this._onReleaseEnd),e.off("layoutStart",this._onLayoutStart),e.off("beforeSend",this._onMigrate),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("layoutStart",this._onLayoutStart),i.on("beforeSend",this._onMigrate),this._didMigrate=!0}},Ht.prototype.create=function(){if(this.isActive())this._resetAfterLayout=!1;else{var t,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;t=c(s.dragPlaceholder.createElement)?s.dragPlaceholder.createElement(e):window.document.createElement("div"),this._element=t,n._element=t,this._className=s.itemPlaceholderClass||"",this._className&&j(t,this._className);var r=e._left+e._marginLeft,o=e._top+e._marginTop;f(t,{display:"block",position:"absolute",left:"0",top:"0",width:e._width+"px",height:e._height+"px",transform:xt(r,o)}),i.on("layoutStart",this._onLayoutStart),i.on("dragReleaseEnd",this._onReleaseEnd),i.on("beforeSend",this._onMigrate),c(s.dragPlaceholder.onCreate)&&s.dragPlaceholder.onCreate(e,t),i.getElement().appendChild(t)}},Ht.prototype.reset=function(){if(this.isActive()){var t=this._element,e=this._item,i=e.getGrid(),s=i._settings,n=this._animate;this._resetAfterLayout=!1,F(e._id),n.stop(),n._element=null,i.off("dragReleaseEnd",this._onReleaseEnd),i.off("layoutStart",this._onLayoutStart),i.off("beforeSend",this._onMigrate),this._className&&(Rt(t,this._className),this._className=""),t.parentNode.removeChild(t),this._element=null,c(s.dragPlaceholder.onRemove)&&s.dragPlaceholder.onRemove(e,t)}},Ht.prototype.updateDimensions=function(t,e){this.isActive()&&f(this._element,{width:t+"px",height:e+"px"})},Ht.prototype.isActive=function(){return!!this._element},Ht.prototype.destroy=function(){this.reset(),this._animate.destroy(),this._item=this._animate=null},Bt.prototype.add=function(t){return this._isDestroyed?this:(this._queue.push(t),this)},Bt.prototype.process=function(){if(this._isDestroyed)return this;var t=this._queue,e=t.length;if(!e)return this;var i,s=this._processQueue,n=s.length;for(i=0;i0;return l&&this._queue.flush(!0,o),d&&(a._isPositioningStarted=!0),c(e)&&this._queue.add(e),g?(this._isActive=!0,this._animateOptions.easing=p,this._animateOptions.duration=u,this._isInterrupted=l,s=o._id,n=this._setupAnimation,r=this._startAnimation,k.add(s+X,n,r),this):(this._updateOffsets(),this._updateTargetStyles(),i=o._animate.isAnimating(),this.stop(!1,this._targetStyles),!i&&f(h,this._targetStyles),this._skipNextAnimation=!1,this._finish())}},Nt.prototype.stop=function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item;return i=s._id,k.cancel(i+X),s._animate.stop(e),Rt(s._element,s.getGrid()._settings.itemPositioningClass),this._isActive=!1,t&&this._queue.process(!0,s),this},Nt.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)},Nt.prototype._updateOffsets=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._offsetLeft=i._isActive?i._containerDiffX:e._isActive?e._containerDiffX:0,this._offsetTop=i._isActive?i._containerDiffY:e._isActive?e._containerDiffY:0}},Nt.prototype._updateTargetStyles=function(){this._isDestroyed||(this._targetStyles.transform=xt(this._item._left+this._offsetLeft,this._item._top+this._offsetTop))},Nt.prototype._finish=function(){if(!this._isDestroyed){var t=this._item,e=t._migrate,i=t._release;this._isActive&&(this._isActive=!1,Rt(t._element,t.getGrid()._settings.itemPositioningClass)),i._isActive&&i.stop(),e._isActive&&e.stop(),this._queue.process(!1,t)}},Nt.prototype._setupAnimation=function(){var t=Lt(this._item._element);this._currentLeft=t.x,this._currentTop=t.y},Nt.prototype._startAnimation=function(){var t=this._item,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||j(t._element,e.itemPositioningClass),this._currentStyles.transform=xt(this._currentLeft,this._currentTop),t._animate.start(this._currentStyles,this._targetStyles,this._animateOptions)},qt.prototype.start=function(t,e,i){if(this._isDestroyed)return this;var s,r,o,h,a,_,l,d,c=this._item,u=c._element,p=c.isVisible(),g=c.getGrid(),m=g._settings,y=t._settings,v=t._element,w=t._items,S=g._items.indexOf(c),b=i||window.document.body;if("number"==typeof e)s=$(w,e,!0);else{if(!(r=t._getItem(e)))return this;s=w.indexOf(r)}return(c.isPositioning()||this._isActive||c.isReleasing())&&(l=(_=Lt(u)).x,d=_.y),c.isPositioning()&&c._layout.stop(!0,{transform:xt(l,d)}),this._isActive&&(l-=this._containerDiffX,d-=this._containerDiffY,this.stop(!0,{transform:xt(l,d)})),c.isReleasing()&&(l-=c._release._containerDiffX,d-=c._release._containerDiffY,c._release.stop(!0,{transform:xt(l,d)})),c._visibility._stopAnimation(),c._drag&&c._drag.destroy(),c._visibility._queue.process(!0,c),g._hasListeners("beforeSend")&&g._emit("beforeSend",{item:c,fromGrid:g,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("beforeReceive")&&t._emit("beforeReceive",{item:c,fromGrid:g,fromIndex:S,toGrid:t,toIndex:s}),Rt(u,m.itemClass),Rt(u,m.itemVisibleClass),Rt(u,m.itemHiddenClass),j(u,y.itemClass),j(u,p?y.itemVisibleClass:y.itemHiddenClass),g._items.splice(S,1),Z(w,c,s),c._gridId=t._id,b!==(o=u.parentNode)&&(b.appendChild(u),h=ct(b,o,!0),_||(l=(_=Lt(u)).x,d=_.y),u.style[n]=xt(l+h.left,d+h.top)),c._child.removeAttribute("style"),f(c._child,p?y.visibleStyles:y.hiddenStyles),u.style.display=p?"block":"hidden",a=ct(b,v,!0),c._refreshDimensions(),c._refreshSortData(),c._drag=y.dragEnabled?new Ot(c):null,this._isActive=!0,this._container=b,this._containerDiffX=a.left,this._containerDiffY=a.top,g._hasListeners("send")&&g._emit("send",{item:c,fromGrid:g,fromIndex:S,toGrid:t,toIndex:s}),t._hasListeners("receive")&&t._emit("receive",{item:c,fromGrid:g,fromIndex:S,toGrid:t,toIndex:s}),this},qt.prototype.stop=(kt={},function(t,e){if(this._isDestroyed||!this._isActive)return this;var i,s=this._item,n=s._element,r=s.getGrid()._element;return this._container!==r&&(e||(t?(i=Lt(n),kt.transform=xt(i.x-this._containerDiffX,i.y-this._containerDiffY)):kt.transform=xt(s._left,s._top),e=kt),r.appendChild(n),f(n,e)),this._isActive=!1,this._container=null,this._containerDiffX=0,this._containerDiffY=0,this}),qt.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)},Ft.prototype.start=function(){if(this._isDestroyed||this._isActive)return this;var t=this._item,e=t.getGrid();return this._isActive=!0,j(t._element,e._settings.itemReleasingClass),e._emit("dragReleaseStart",t),t._layout.start(!1),this},Ft.prototype.stop=function(){var t={transform:""};return function(e,i){if(this._isDestroyed||!this._isActive)return this;var s,n=this._item,r=n._element,o=n.getGrid(),h=o._element;return this._reset(),r.parentNode!==h&&(i||(e?(s=Lt(r),t.transform=xt(s.x-this._containerDiffX,s.y-this._containerDiffY)):t.transform=xt(n._left,n._top),i=t),h.appendChild(r),f(r,i)),e||o._emit("dragReleaseEnd",n),this}}(),Ft.prototype.destroy=function(){return this._isDestroyed?this:(this.stop(!0),this._item=null,this._isDestroyed=!0,this)},Ft.prototype._reset=function(){if(!this._isDestroyed){var t=this._item;this._isActive=!1,this._isPositioningStarted=!1,this._containerDiffX=0,this._containerDiffY=0,Rt(t._element,t.getGrid()._settings.itemReleasingClass)}},zt.prototype.show=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return this._isShowing||this._isHidden?this._isShowing&&!t?(r&&n.add(r),this):(this._isShowing||(n.process(!0,i),Rt(s,o.itemHiddenClass),j(s,o.itemVisibleClass),this._isHiding||(s.style.display="block")),r&&n.add(r),i._isActive=this._isShowing=!0,this._isHiding=this._isHidden=!1,this._startAnimation(!0,t,this._finishShow),this):(r&&r(!1,i),this)},zt.prototype.hide=function(t,e){if(this._isDestroyed)return this;var i=this._item,s=i._element,n=this._queue,r=c(e)?e:null,o=i.getGrid()._settings;return!this._isHiding&&this._isHidden?(r&&r(!1,i),this):this._isHiding&&!t?(r&&n.add(r),this):(this._isHiding||(n.process(!0,i),j(s,o.itemHiddenClass),Rt(s,o.itemVisibleClass)),r&&n.add(r),this._isHidden=this._isHiding=!0,i._isActive=this._isShowing=!1,this._startAnimation(!1,t,this._finishHide),this)},zt.prototype.destroy=function(){if(this._isDestroyed)return this;var t=this._item,e=t._element,i=t.getGrid(),s=this._queue,n=i._settings;return this._stopAnimation({}),s.process(!0,t).destroy(),Rt(e,n.itemVisibleClass),Rt(e,n.itemHiddenClass),this._item=null,this._isHiding=this._isShowing=!1,this._isDestroyed=this._isHidden=!0,this},zt.prototype._startAnimation=function(t,e,i){if(!this._isDestroyed){var s,n=this._item,r=n.getGrid()._settings,o=t?r.visibleStyles:r.hiddenStyles,h=t?r.showDuration:r.hideDuration,_=t?r.showEasing:r.hideEasing,d=e||h<=0;if(o){if(B(n._id),d)return n._animateChild.isAnimating()?n._animateChild.stop(o):f(n._child,o),void(i&&i());var c,u,p;c=n._id,u=function(){s=function(t,e){var i={};for(var s in e)i[s]=a(t,l(s));return i}(n._child,o)},p=function(){n._animateChild.start(s,o,{duration:h,easing:_,onFinish:i})},k.add(c+Y,u,p)}else i&&i()}},zt.prototype._stopAnimation=function(t){if(!this._isDestroyed){var e=this._item;B(e._id),e._animateChild.stop(t)}},zt.prototype._finishShow=function(){this._isHidden||(this._isShowing=!1,this._queue.process(!1,this._item))},zt.prototype._finishHide=(Xt={transform:xt(0,0)},function(){if(this._isHidden){var t=this._item;this._isHiding=!1,t._layout.stop(!0,Xt),t._element.style.display="none",this._queue.process(!1,t)}});var Vt,Wt,jt,Qt,Ut=0;function Zt(){return++Ut}function $t(t,e,i){var s=t._settings;this._id=Zt(),this._gridId=t._id,this._isDestroyed=!1,this._left=0,this._top=0,this._element=e,this._child=e.children[0],e.parentNode!==t._element&&t._element.appendChild(e),j(e,s.itemClass),"boolean"!=typeof i&&(i="none"!==a(e,"display")),this._isActive=i,e.style.left="0",e.style.top="0",e.style[n]=xt(0,0),this._animate=new p(e),this._animateChild=new p(this._child),this._visibility=new zt(this),this._layout=new Nt(this),this._migrate=new qt(this),this._release=new Ft(this),this._dragPlaceholder=new Ht(this),this._drag=s.dragEnabled?new Ot(this):null,this._refreshDimensions(),this._refreshSortData()}function Jt(){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)}$t.prototype.getGrid=function(){return t[this._gridId]},$t.prototype.getElement=function(){return this._element},$t.prototype.getWidth=function(){return this._width},$t.prototype.getHeight=function(){return this._height},$t.prototype.getMargin=function(){return{left:this._marginLeft,right:this._marginRight,top:this._marginTop,bottom:this._marginBottom}},$t.prototype.getPosition=function(){return{left:this._left,top:this._top}},$t.prototype.isActive=function(){return this._isActive},$t.prototype.isVisible=function(){return!!this._visibility&&!this._visibility._isHidden},$t.prototype.isShowing=function(){return!(!this._visibility||!this._visibility._isShowing)},$t.prototype.isHiding=function(){return!(!this._visibility||!this._visibility._isHiding)},$t.prototype.isPositioning=function(){return!(!this._layout||!this._layout._isActive)},$t.prototype.isDragging=function(){return!(!this._drag||!this._drag._isActive)},$t.prototype.isReleasing=function(){return!(!this._release||!this._release._isActive)},$t.prototype.isDestroyed=function(){return this._isDestroyed},$t.prototype._refreshDimensions=function(){if(!this._isDestroyed&&!this._visibility._isHidden){var t=this._element,e=this._dragPlaceholder,i=t.getBoundingClientRect();this._width=i.width,this._height=i.height,this._marginLeft=Math.max(0,ht(t,"margin-left")),this._marginRight=Math.max(0,ht(t,"margin-right")),this._marginTop=Math.max(0,ht(t,"margin-top")),this._marginBottom=Math.max(0,ht(t,"margin-bottom")),e&&e.updateDimensions(this._width,this._height)}},$t.prototype._refreshSortData=function(){if(!this._isDestroyed){var t,e=this._sortData={},i=this.getGrid()._settings.sortData;for(t in i)e[t]=i[t](this,this._element)}},$t.prototype._destroy=function(t){if(!this._isDestroyed){var e=this._element,i=this.getGrid(),s=i._settings,n=i._items.indexOf(this);this._release.destroy(),this._migrate.destroy(),this._layout.destroy(),this._visibility.destroy(),this._animate.destroy(),this._animateChild.destroy(),this._dragPlaceholder.destroy(),this._drag&&this._drag.destroy(),e.removeAttribute("style"),this._child.removeAttribute("style"),Rt(e,s.itemClass),n>-1&&i._items.splice(n,1),t&&e.parentNode.removeChild(e),this._isActive=!1,this._isDestroyed=!0}},Jt.prototype.getLayout=function(t,e,i,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),c=this._slotSizes;if(o.slots=s||this._slots,o.width=a?0:d?Math.round(e):e,o.height=a?d?Math.round(i):i:0,o.setWidth=a,o.setHeight=!a,o.slots.length=0,c.length=0,!t.length)return o;for(r=0;rd.height&&(Vt.left>0&&u.push(this._addRect(0,d.height,Vt.left,1/0)),Vt.left+Vt.widthd.width&&(Vt.top>0&&u.push(this._addRect(d.width,0,1/0,Vt.top)),Vt.top+Vt.height.49&&r.height>.49&&(!e&&r.tope.left+e.width&&Wt.push(this._addRect(e.left+e.width,t.top,t.left+t.width-(e.left+e.width),t.height)),t.tope.top+e.height&&Wt.push(this._addRect(t.left,e.top+e.height,t.width,t.top+t.height-(e.top+e.height))),Wt):(Wt.push(this._addRect(t.left,t.top,t.width,t.height)),Wt)}),Jt.prototype._doRectsOverlap=function(t,e){return!(t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top)},Jt.prototype._isRectWithinRect=function(t,e){return t.left>=e.left&&t.top>=e.top&&t.left+t.width<=e.left+e.width&&t.top+t.height<=e.top+e.height},Jt.prototype._purgeRects=(jt={},Qt={},function(t){for(var e,i=t.length;i--;)if(e=t.length,t[i])for(this._getRect(t[i],jt);e--;)if(t[e]&&i!==e&&this._isRectWithinRect(jt,this._getRect(t[e],Qt))){t[i]=0;break}return t}),Jt.prototype._sortRectsTopLeft=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.tope.top?1:t.lefte.left?1:0}}(),Jt.prototype._sortRectsLeftTop=function(){var t={},e={};return function(i,s){return this._getRect(i,t),this._getRect(s,e),t.lefte.left?1:t.tope.top?1:0}}();var Kt="[object HTMLCollection]",te="[object NodeList]";function ee(t){var e=Object.prototype.toString.call(t);return e===Kt||e===te}var ie="object",se="[object Object]",ne=Object.prototype.toString;function re(t){return typeof t===ie&&ne.call(t)===se}var oe=new Jt,he=function(){},ae="number",_e="string";function le(e,s){var n;if(typeof e===_e&&(e=window.document.querySelector(e)),this._element=e,!(e.getRootNode?e.getRootNode({composed:!0})===document:window.document.body.contains(e))||e===window.document.documentElement)throw new Error("Container element must be an existing DOM element");c((n=this._settings=de(le.defaultOptions,s)).dragSort)||(n.dragSort=!!n.dragSort),this._id=Zt(),t[this._id]=this,this._isDestroyed=!1,this._layout={id:0,items:[],slots:[],setWidth:!1,setHeight:!1,width:0,height:0},this._emitter=new i,j(e,n.containerClass),this._items=function(t,e){var i,s,n=[];if(typeof e===_e)for(i=0;i=0&&(t._resizeHandler=nt(function(){t.refreshItems().layout()},e),window.addEventListener("resize",t._resizeHandler))}function fe(t){t._resizeHandler&&(t._resizeHandler("cancel"),window.removeEventListener("resize",t._resizeHandler),t._resizeHandler=null)}return le.Item=$t,le.ItemLayout=Nt,le.ItemVisibility=zt,le.ItemMigrate=qt,le.ItemAnimate=p,le.ItemDrag=Ot,le.ItemRelease=Ft,le.ItemDragPlaceholder=Ht,le.Emitter=i,le.Dragger=M,le.Packer=Jt,le.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,dragSortHeuristics:{sortInterval:100,minDragDistance:10,minBounceBackAngle:1},dragSortPredicate:{threshold:50,action:"move",migrateAction:"move"},dragReleaseDuration:300,dragReleaseEasing:"ease",dragCssProps:{touchAction:"none",userSelect:"none",userDrag:"none",tapHighlightColor:"rgba(0, 0, 0, 0)",touchCallout:"none",contentZooming:"none"},dragPlaceholder:{enabled:!1,duration:300,easing:"ease",createElement:null,onCreate:null,onRemove:null},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",itemPlaceholderClass:"muuri-item-placeholder"},le.prototype.on=function(t,e){return this._emitter.on(t,e),this},le.prototype.off=function(t,e){return this._emitter.off(t,e),this},le.prototype.getElement=function(){return this._element},le.prototype.getItems=function(t){if(this._isDestroyed||void 0===t)return this._items.slice(0);var e,i,s=[];if(Array.isArray(t)||ee(t))for(e=0;e-1){if(r.dragEnabled&&!o.dragEnabled){for(this._settings=r,e=0;e-1&&r.dragEnabled&&o.dragEnabled)for(e=0;e-1&&r.containerClass!==o.containerClass&&(Rt(s,r.containerClass),j(s,o.containerClass)),n.indexOf("sortData")>-1)for(e=0;e-1&&(fe(this),ue(this,o.layoutOnResize)),o},le.prototype.refreshItems=function(t){if(this._isDestroyed)return this;var e,i=this.getItems(t);for(e=0;e0)){var s=o._layout.id!==l,n=c(t)?t:i;c(n)&&n(s,_.items.slice(0)),!s&&o._hasListeners(e)&&o._emit(e,_.items.slice(0))}}if((_.setHeight&&typeof _.height===ae||_.setWidth&&typeof _.width===ae)&&(s="border-box"===a(h,"box-sizing")),_.setHeight&&(typeof _.height===ae?h.style.height=(s?_.height+this._borderTop+this._borderBottom:_.height)+"px":h.style.height=_.height),_.setWidth&&(typeof _.width===ae?h.style.width=(s?_.width+this._borderLeft+this._borderRight:_.width)+"px":h.style.width=_.width),this._hasListeners("layoutStart")&&this._emit("layoutStart",_.items.slice(0)),!d)return f(),this;for(r=0;rl?1:0:ld?1:0)return c;return c||(s||(s=n(i)),c=r(o,h)),c}function h(o,h){var a=t(o,h);return e&&a&&(a=-a),a||(s||(s=n(i)),r(o,h))}return function(n,r){if(this._isDestroyed||this._items.length<2)return this;var a,_=this._items,l=r||0,d=l.layout?l.layout:void 0===l.layout;if(t=n,e=!!l.descending,i=_.slice(0),s=null,c(t))_.sort(h);else if(typeof t===_e)t=n.trim().split(" ").map(function(t){return t.split(":")}),_.sort(o);else{if(!Array.isArray(t))return this;if(t.length!==_.length)throw new Error("[Muuri] sort reference items do not match with grid items.");for(a=0;a<_.length;a++){if(t.indexOf(_[a])<0)throw new Error("[Muuri] sort reference items do not match with grid items.");_[a]=t[a]}e&&_.reverse()}return this._hasListeners("sort")&&this._emit("sort",_.slice(0),i),d&&this.layout("instant"===d,c(d)?d:void 0),this}}(),le.prototype.move=function(t,e,i){if(this._isDestroyed||this._items.length<2)return this;var s,n,r=this._items,o=i||0,h=o.layout?o.layout:void 0===o.layout,a="swap"===o.action,_=a?"swap":"move",l=this._getItem(t),d=this._getItem(e);return l&&d&&l!==d&&(s=r.indexOf(l),n=r.indexOf(d),a?K(r,s,n):J(r,s,n),this._hasListeners("move")&&this._emit("move",{item:l,fromIndex:s,toIndex:n,action:_}),h&&this.layout("instant"===h,c(h)?h:void 0)),this},le.prototype.send=function(t,e,i,s){if(this._isDestroyed||e._isDestroyed||this===e)return this;if(!(t=this._getItem(t)))return this;var n=s||0,r=n.appendTo||window.document.body,o=n.layoutSender?n.layoutSender:void 0===n.layoutSender,h=n.layoutReceiver?n.layoutReceiver:void 0===n.layoutReceiver;return t._migrate.start(e,i,r),t._migrate._isActive&&t._isActive&&(o&&this.layout("instant"===o,c(o)?o:void 0),h&&e.layout("instant"===h,c(h)?h:void 0)),this},le.prototype.destroy=function(e){if(this._isDestroyed)return this;var i,s=this._element,n=this._items.slice(0);for(fe(this),i=0;i-1?t:this._items.length+t]||null;if(t instanceof $t)return t._gridId===this._id?t:null;for(var e=0;e