Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dragdoll

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dragdoll - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

src/utils/append-element.ts

85

dist/dragdoll.d.ts

@@ -87,10 +87,4 @@ import * as eventti from 'eventti';

};
interface Rect extends Dimensions {
left: number;
top: number;
interface Rect extends Point, Dimensions {
}
interface RectExtended extends Rect {
right: number;
bottom: number;
}
type CSSProperties = Partial<Omit<CSSStyleDeclaration, 'getPropertyPriority' | 'getPropertyValue' | 'item' | 'removeProperty' | 'setProperty' | 'length' | 'parentRule'>>;

@@ -214,9 +208,11 @@

type KeyboardSensorPredicate = (e: KeyboardEvent, sensor: KeyboardSensor, moveDistance: Point) => Point | null | undefined;
interface KeyboardSensorSettings {
type KeyboardSensorPredicate<E extends KeyboardSensorEvents = KeyboardSensorEvents> = (e: KeyboardEvent, sensor: KeyboardSensor<E>) => Point | null | undefined;
interface KeyboardSensorSettings<E extends KeyboardSensorEvents = KeyboardSensorEvents> {
moveDistance: number | Point;
startPredicate: KeyboardSensorPredicate;
movePredicate: KeyboardSensorPredicate;
cancelPredicate: KeyboardSensorPredicate;
endPredicate: KeyboardSensorPredicate;
cancelOnBlur: boolean;
cancelOnVisibilityChange: boolean;
startPredicate: KeyboardSensorPredicate<E>;
movePredicate: KeyboardSensorPredicate<E>;
cancelPredicate: KeyboardSensorPredicate<E>;
endPredicate: KeyboardSensorPredicate<E>;
}

@@ -244,12 +240,18 @@ interface KeyboardSensorStartEvent extends SensorStartEvent {

}
declare const keyboardSensorDefaults: KeyboardSensorSettings<any>;
declare class KeyboardSensor<E extends KeyboardSensorEvents = KeyboardSensorEvents> extends BaseSensor<E> implements Sensor<E> {
events: E;
protected _moveDistance: Point;
protected _startPredicate: KeyboardSensorPredicate;
protected _movePredicate: KeyboardSensorPredicate;
protected _cancelPredicate: KeyboardSensorPredicate;
protected _endPredicate: KeyboardSensorPredicate;
constructor(options?: Partial<KeyboardSensorSettings>);
readonly element: Element | null;
readonly moveDistance: Point;
protected _cancelOnBlur: boolean;
protected _cancelOnVisibilityChange: boolean;
protected _startPredicate: KeyboardSensorPredicate<E>;
protected _movePredicate: KeyboardSensorPredicate<E>;
protected _cancelPredicate: KeyboardSensorPredicate<E>;
protected _endPredicate: KeyboardSensorPredicate<E>;
constructor(element: Element | null, options?: Partial<KeyboardSensorSettings<E>>);
protected _internalCancel(): void;
protected _blurCancelHandler(): void;
protected _onKeyDown(e: KeyboardEvent): void;
updateSettings(options?: Partial<KeyboardSensorSettings>): void;
updateSettings(options?: Partial<KeyboardSensorSettings<E>>): void;
destroy(): void;

@@ -259,4 +261,2 @@ }

interface KeyboardMotionSensorSettings<E extends KeyboardMotionSensorEvents = KeyboardMotionSensorEvents> {
startPredicate: (e: KeyboardEvent, sensor: KeyboardMotionSensor<E>) => Point | null | undefined;
computeSpeed: (sensor: KeyboardMotionSensor<E>) => number;
startKeys: string[];

@@ -269,9 +269,13 @@ moveLeftKeys: string[];

endKeys: string[];
cancelOnBlur: boolean;
cancelOnVisibilityChange: boolean;
computeSpeed: (sensor: KeyboardMotionSensor<E>) => number;
startPredicate: (e: KeyboardEvent, sensor: KeyboardMotionSensor<E>) => Point | null | undefined;
}
interface KeyboardMotionSensorEvents extends BaseMotionSensorEvents {
}
declare const keyboardMotionSensorDefaults: KeyboardMotionSensorSettings<any>;
declare class KeyboardMotionSensor<E extends KeyboardMotionSensorEvents = KeyboardMotionSensorEvents> extends BaseMotionSensor<E> implements Sensor<E> {
events: E;
protected _startPredicate: Exclude<KeyboardMotionSensorSettings<E>['startPredicate'], undefined>;
protected _computeSpeed: Exclude<KeyboardMotionSensorSettings<E>['computeSpeed'], undefined>;
readonly element: Element | null;
protected _moveKeys: Set<string>;

@@ -286,5 +290,11 @@ protected _moveKeyTimestamps: Map<string, number>;

protected _endKeys: Set<string>;
constructor(options?: Partial<KeyboardMotionSensorSettings<E>>);
protected _cancelOnBlur: boolean;
protected _cancelOnVisibilityChange: boolean;
protected _computeSpeed: Exclude<KeyboardMotionSensorSettings<E>['computeSpeed'], undefined>;
protected _startPredicate: Exclude<KeyboardMotionSensorSettings<E>['startPredicate'], undefined>;
constructor(element: Element | null, options?: Partial<KeyboardMotionSensorSettings<E>>);
protected _end(data: E['end']): void;
protected _cancel(data: E['cancel']): void;
protected _internalCancel(): void;
protected _blurCancelHandler(): void;
protected _updateDirection(): void;

@@ -333,2 +343,8 @@ protected _onTick(): void;

declare enum DragStartPhase {
NONE = 0,
INIT = 1,
START_PREPARE = 2,
FINISH_APPLY = 3
}
declare enum DraggableStartPredicateState {

@@ -413,2 +429,3 @@ PENDING = 0,

}>;
protected _startPhase: DragStartPhase;
protected _startId: symbol;

@@ -599,3 +616,2 @@ protected _moveId: symbol;

protected _stopTicking(): void;
protected _getItemClientRect(item: AutoScrollItem, result?: RectExtended): RectExtended;
protected _requestItemScroll(item: AutoScrollItem, axis: AutoScrollAxis, element: Window | Element, direction: AutoScrollDirection, threshold: number, distance: number, maxValue: number): void;

@@ -646,8 +662,3 @@ protected _cancelItemScroll(item: AutoScrollItem, axis: AutoScrollAxis): void;

getPosition: ((draggable: Draggable<S, E>) => Point) | null;
getClientRect: ((draggable: Draggable<S, E>) => {
left: number;
top: number;
width: number;
height: number;
}) | null;
getClientRect: ((draggable: Draggable<S, E>) => Rect) | null;
onStart: AutoScrollItemEventCallback | null;

@@ -684,6 +695,6 @@ onStop: AutoScrollItemEventCallback | null;

declare function createSnapModifier(gridWidth: number, gridHeight: number): ({ startEvent, event, item, }: {
startEvent: SensorStartEvent | SensorMoveEvent;
event: SensorMoveEvent;
item: DraggableDragItem;
declare function createSnapModifier<S extends Sensor[], E extends S[number]['events']>(gridWidth: number, gridHeight: number): ({ item, event, startEvent, }: {
item: DraggableDragItem<S, E>;
event: E['start'] | E['move'];
startEvent: E['start'] | E['move'];
}) => {

@@ -694,2 +705,2 @@ x: number;

export { AUTO_SCROLL_AXIS, AUTO_SCROLL_AXIS_DIRECTION, AUTO_SCROLL_DIRECTION, AutoScroll, type AutoScrollEventCallbacks, type AutoScrollItem, type AutoScrollItemEffectCallback, type AutoScrollItemEventCallback, type AutoScrollItemSpeedCallback, type AutoScrollItemTarget, type AutoScrollOptions, type AutoScrollSettings, BaseMotionSensor, type BaseMotionSensorDragData, type BaseMotionSensorEvents, type BaseMotionSensorTickEvent, BaseSensor, type BaseSensorDragData, Draggable, DraggableAutoScroll, type DraggableAutoScrollOptions, type DraggableAutoScrollSettings, type DraggableEventCallbacks, type DraggablePlugin, type DraggablePluginMap, type DraggableSettings, KeyboardMotionSensor, type KeyboardMotionSensorEvents, type KeyboardMotionSensorSettings, KeyboardSensor, type KeyboardSensorCancelEvent, type KeyboardSensorDestroyEvent, type KeyboardSensorEndEvent, type KeyboardSensorEvents, type KeyboardSensorMoveEvent, type KeyboardSensorPredicate, type KeyboardSensorSettings, type KeyboardSensorStartEvent, PointerSensor, type PointerSensorCancelEvent, type PointerSensorDestroyEvent, type PointerSensorDragData, type PointerSensorEndEvent, type PointerSensorEvents, type PointerSensorMoveEvent, type PointerSensorSettings, type PointerSensorStartEvent, type Sensor, type SensorCancelEvent, type SensorDestroyEvent, type SensorEndEvent, SensorEventType, type SensorEvents, type SensorMoveEvent, type SensorStartEvent, autoScroll, autoScrollPlugin, autoScrollSmoothSpeed, createPointerSensorStartPredicate, createSnapModifier, setTicker, ticker, tickerReadPhase, tickerWritePhase };
export { AUTO_SCROLL_AXIS, AUTO_SCROLL_AXIS_DIRECTION, AUTO_SCROLL_DIRECTION, AutoScroll, type AutoScrollEventCallbacks, type AutoScrollItem, type AutoScrollItemEffectCallback, type AutoScrollItemEventCallback, type AutoScrollItemSpeedCallback, type AutoScrollItemTarget, type AutoScrollOptions, type AutoScrollSettings, BaseMotionSensor, type BaseMotionSensorDragData, type BaseMotionSensorEvents, type BaseMotionSensorTickEvent, BaseSensor, type BaseSensorDragData, Draggable, DraggableAutoScroll, type DraggableAutoScrollOptions, type DraggableAutoScrollSettings, type DraggableEventCallbacks, type DraggablePlugin, type DraggablePluginMap, type DraggableSettings, KeyboardMotionSensor, type KeyboardMotionSensorEvents, type KeyboardMotionSensorSettings, KeyboardSensor, type KeyboardSensorCancelEvent, type KeyboardSensorDestroyEvent, type KeyboardSensorEndEvent, type KeyboardSensorEvents, type KeyboardSensorMoveEvent, type KeyboardSensorPredicate, type KeyboardSensorSettings, type KeyboardSensorStartEvent, PointerSensor, type PointerSensorCancelEvent, type PointerSensorDestroyEvent, type PointerSensorDragData, type PointerSensorEndEvent, type PointerSensorEvents, type PointerSensorMoveEvent, type PointerSensorSettings, type PointerSensorStartEvent, type Sensor, type SensorCancelEvent, type SensorDestroyEvent, type SensorEndEvent, SensorEventType, type SensorEvents, type SensorMoveEvent, type SensorStartEvent, autoScroll, autoScrollPlugin, autoScrollSmoothSpeed, createPointerSensorStartPredicate, createSnapModifier, keyboardMotionSensorDefaults, keyboardSensorDefaults, setTicker, ticker, tickerReadPhase, tickerWritePhase };

@@ -1,1 +0,1 @@

var y={start:"start",move:"move",cancel:"cancel",end:"end",destroy:"destroy"};import{Emitter as tt}from"eventti";var W=class{constructor(){this.drag=null,this.isDestroyed=!1,this._emitter=new tt}_createDragData(e){return{x:e.x,y:e.y}}_updateDragData(e){this.drag&&(this.drag.x=e.x,this.drag.y=e.y)}_resetDragData(){this.drag=null}_start(e){this.isDestroyed||this.drag||(this.drag=this._createDragData(e),this._emitter.emit(y.start,e))}_move(e){this.drag&&(this._updateDragData(e),this._emitter.emit(y.move,e))}_end(e){this.drag&&(this._updateDragData(e),this._emitter.emit(y.end,e),this._resetDragData())}_cancel(e){this.drag&&(this._updateDragData(e),this._emitter.emit(y.cancel,e),this._resetDragData())}on(e,t,n){return this._emitter.on(e,t,n)}off(e,t){this._emitter.off(e,t)}cancel(){this.drag&&(this._emitter.emit(y.cancel,{type:y.cancel,x:this.drag.x,y:this.drag.y}),this._resetDragData())}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.cancel(),this._emitter.emit(y.destroy,{type:y.destroy}),this._emitter.off())}};import{AutoTicker as nt}from"tikki";var E=Symbol(),D=Symbol(),u=new nt({phases:[E,D]});function Ct(r,e,t){E=e,D=t,u=r}var $=class extends W{constructor(){super(),this.drag=null,this._direction={x:0,y:0},this._speed=0,this._tick=this._tick.bind(this)}_createDragData(e){return{...super._createDragData(e),time:0,deltaTime:0}}_start(e){this.isDestroyed||this.drag||(super._start(e),u.on(E,this._tick,this._tick))}_end(e){this.drag&&(u.off(E,this._tick),super._end(e))}_cancel(e){this.drag&&(u.off(E,this._tick),super._cancel(e))}_tick(e){if(this.drag)if(e&&this.drag.time){this.drag.deltaTime=e-this.drag.time,this.drag.time=e;let t={type:"tick",time:this.drag.time,deltaTime:this.drag.deltaTime};if(this._emitter.emit("tick",t),!this.drag)return;let n=this._speed*(this.drag.deltaTime/1e3),i=this._direction.x*n,o=this._direction.y*n;(i||o)&&this._move({type:"move",x:this.drag.x+i,y:this.drag.y+o})}else this.drag.time=e,this.drag.deltaTime=0}};import{Emitter as rt}from"eventti";function he(r,e){if("pointerId"in r)return r.pointerId===e?r:null;if("changedTouches"in r){let t=0;for(;t<r.changedTouches.length;t++)if(r.changedTouches[t].identifier===e)return r.changedTouches[t];return null}return r}function Oe(r){return"pointerType"in r?r.pointerType:"touches"in r?"touch":"mouse"}function Me(r){return"pointerId"in r?r.pointerId:"changedTouches"in r?r.changedTouches[0]?r.changedTouches[0].identifier:null:-1}var me=typeof window<"u"&&typeof window.document<"u",J=(()=>{let r=!1;try{let e=Object.defineProperty({},"passive",{get:function(){r=!0}});window.addEventListener("testPassive",null,e),window.removeEventListener("testPassive",null,e)}catch{}return r})(),Ke=me&&"ontouchstart"in window,We=me&&!!window.PointerEvent,Nt=!!(me&&navigator.vendor&&navigator.vendor.indexOf("Apple")>-1&&navigator.userAgent&&navigator.userAgent.indexOf("CriOS")==-1&&navigator.userAgent.indexOf("FxiOS")==-1);function ue(r={}){let{capture:e=!0,passive:t=!0}=r;return J?{capture:e,passive:t}:{capture:e}}function pe(r){return r==="auto"||r===void 0?We?"pointer":Ke?"touch":"mouse":r}var it={start:"pointerdown",move:"pointermove",cancel:"pointercancel",end:"pointerup"},ot={start:"touchstart",move:"touchmove",cancel:"touchcancel",end:"touchend"},st={start:"mousedown",move:"mousemove",cancel:"",end:"mouseup"},q={pointer:it,touch:ot,mouse:st},X=class{constructor(e,t={}){let{listenerOptions:n={},sourceEvents:i="auto",startPredicate:o=s=>!("button"in s&&s.button>0)}=t;this.element=e,this.drag=null,this.isDestroyed=!1,this._areWindowListenersBound=!1,this._startPredicate=o,this._listenerOptions=ue(n),this._sourceEvents=pe(i),this._emitter=new rt,this._onStart=this._onStart.bind(this),this._onMove=this._onMove.bind(this),this._onCancel=this._onCancel.bind(this),this._onEnd=this._onEnd.bind(this),e.addEventListener(q[this._sourceEvents].start,this._onStart,this._listenerOptions)}_getTrackedPointerEventData(e){return this.drag?he(e,this.drag.pointerId):null}_onStart(e){if(this.isDestroyed||this.drag||!this._startPredicate(e))return;let t=Me(e);if(t===null)return;let n=he(e,t);if(n===null)return;let i={pointerId:t,pointerType:Oe(e),x:n.clientX,y:n.clientY};this.drag=i;let o={...i,type:y.start,srcEvent:e,target:n.target};this._emitter.emit(o.type,o),this.drag&&this._bindWindowListeners()}_onMove(e){if(!this.drag)return;let t=this._getTrackedPointerEventData(e);if(!t)return;this.drag.x=t.clientX,this.drag.y=t.clientY;let n={type:y.move,srcEvent:e,target:t.target,...this.drag};this._emitter.emit(n.type,n)}_onCancel(e){if(!this.drag)return;let t=this._getTrackedPointerEventData(e);if(!t)return;this.drag.x=t.clientX,this.drag.y=t.clientY;let n={type:y.cancel,srcEvent:e,target:t.target,...this.drag};this._emitter.emit(n.type,n),this._resetDrag()}_onEnd(e){if(!this.drag)return;let t=this._getTrackedPointerEventData(e);if(!t)return;this.drag.x=t.clientX,this.drag.y=t.clientY;let n={type:y.end,srcEvent:e,target:t.target,...this.drag};this._emitter.emit(n.type,n),this._resetDrag()}_bindWindowListeners(){if(this._areWindowListenersBound)return;let{move:e,end:t,cancel:n}=q[this._sourceEvents];window.addEventListener(e,this._onMove,this._listenerOptions),window.addEventListener(t,this._onEnd,this._listenerOptions),n&&window.addEventListener(n,this._onCancel,this._listenerOptions),this._areWindowListenersBound=!0}_unbindWindowListeners(){if(this._areWindowListenersBound){let{move:e,end:t,cancel:n}=q[this._sourceEvents];window.removeEventListener(e,this._onMove,this._listenerOptions),window.removeEventListener(t,this._onEnd,this._listenerOptions),n&&window.removeEventListener(n,this._onCancel,this._listenerOptions),this._areWindowListenersBound=!1}}_resetDrag(){this.drag=null,this._unbindWindowListeners()}cancel(){if(!this.drag)return;let e={type:y.cancel,srcEvent:null,target:null,...this.drag};this._emitter.emit(e.type,e),this._resetDrag()}updateSettings(e){if(this.isDestroyed)return;let{listenerOptions:t,sourceEvents:n,startPredicate:i}=e,o=pe(n),s=ue(t);i&&this._startPredicate!==i&&(this._startPredicate=i),(t&&(this._listenerOptions.capture!==s.capture||this._listenerOptions.passive===s.passive)||n&&this._sourceEvents!==o)&&(this.element.removeEventListener(q[this._sourceEvents].start,this._onStart,this._listenerOptions),this._unbindWindowListeners(),this.cancel(),n&&(this._sourceEvents=o),t&&s&&(this._listenerOptions=s),this.element.addEventListener(q[this._sourceEvents].start,this._onStart,this._listenerOptions))}on(e,t,n){return this._emitter.on(e,t,n)}off(e,t){this._emitter.off(e,t)}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.cancel(),this._emitter.emit(y.destroy,{type:y.destroy}),this._emitter.off(),this.element.removeEventListener(q[this._sourceEvents].start,this._onStart,this._listenerOptions))}};var qe=class extends W{constructor(e={}){super();let{moveDistance:t=25,startPredicate:n=l=>{if((l.key==="Enter"||l.key===" ")&&document.activeElement&&document.activeElement!==document.body){let{left:a,top:c}=document.activeElement.getBoundingClientRect();return{x:a,y:c}}return null},movePredicate:i=(l,a,c)=>{if(!a.drag)return null;switch(l.key){case"ArrowLeft":return{x:a.drag.x-c.x,y:a.drag.y};case"ArrowRight":return{x:a.drag.x+c.x,y:a.drag.y};case"ArrowUp":return{x:a.drag.x,y:a.drag.y-c.y};case"ArrowDown":return{x:a.drag.x,y:a.drag.y+c.y};default:return null}},cancelPredicate:o=(l,a)=>a.drag&&l.key==="Escape"?{x:a.drag.x,y:a.drag.y}:null,endPredicate:s=(l,a)=>a.drag&&(l.key==="Enter"||l.key===" ")?{x:a.drag.x,y:a.drag.y}:null}=e;this._moveDistance=typeof t=="number"?{x:t,y:t}:{...t},this._startPredicate=n,this._movePredicate=i,this._cancelPredicate=o,this._endPredicate=s,this.cancel=this.cancel.bind(this),this._onKeyDown=this._onKeyDown.bind(this),document.addEventListener("keydown",this._onKeyDown),window.addEventListener("blur",this.cancel),window.addEventListener("visibilitychange",this.cancel)}_onKeyDown(e){if(!this.drag){let o=this._startPredicate(e,this,this._moveDistance);o&&(e.preventDefault(),this._start({type:"start",x:o.x,y:o.y,srcEvent:e}));return}let t=this._cancelPredicate(e,this,this._moveDistance);if(t){e.preventDefault(),this._cancel({type:"cancel",x:t.x,y:t.y,srcEvent:e});return}let n=this._endPredicate(e,this,this._moveDistance);if(n){e.preventDefault(),this._end({type:"end",x:n.x,y:n.y,srcEvent:e});return}let i=this._movePredicate(e,this,this._moveDistance);if(i){e.preventDefault(),this._move({type:"move",x:i.x,y:i.y,srcEvent:e});return}}updateSettings(e={}){e.moveDistance!==void 0&&(typeof e.moveDistance=="number"?(this._moveDistance.x=e.moveDistance,this._moveDistance.y=e.moveDistance):(this._moveDistance.x=e.moveDistance.x,this._moveDistance.y=e.moveDistance.y)),e.startPredicate!==void 0&&(this._startPredicate=e.startPredicate),e.movePredicate!==void 0&&(this._movePredicate=e.movePredicate),e.cancelPredicate!==void 0&&(this._cancelPredicate=e.cancelPredicate),e.endPredicate!==void 0&&(this._endPredicate=e.endPredicate)}destroy(){this.isDestroyed||(super.destroy(),document.removeEventListener("keydown",this._onKeyDown),window.removeEventListener("blur",this.cancel),window.removeEventListener("visibilitychange",this.cancel))}};var at=["start","cancel","end","moveLeft","moveRight","moveUp","moveDown"];function Q(r,e){if(!r.size||!e.size)return 1/0;let t=1/0;for(let n of r){let i=e.get(n);i!==void 0&&i<t&&(t=i)}return t}var Xe=class extends ${constructor(e={}){super();let{startPredicate:t=()=>{if(document.activeElement){let{left:m,top:b}=document.activeElement.getBoundingClientRect();return{x:m,y:b}}return null},computeSpeed:n=()=>500,startKeys:i=[" ","Enter"],moveLeftKeys:o=["ArrowLeft"],moveRightKeys:s=["ArrowRight"],moveUpKeys:l=["ArrowUp"],moveDownKeys:a=["ArrowDown"],cancelKeys:c=["Escape"],endKeys:d=[" ","Enter"]}=e;this._computeSpeed=n,this._startPredicate=t,this._startKeys=new Set(i),this._cancelKeys=new Set(c),this._endKeys=new Set(d),this._moveLeftKeys=new Set(o),this._moveRightKeys=new Set(s),this._moveUpKeys=new Set(l),this._moveDownKeys=new Set(a),this._moveKeys=new Set([...o,...s,...l,...a]),this._moveKeyTimestamps=new Map,this._onKeyDown=this._onKeyDown.bind(this),this._onKeyUp=this._onKeyUp.bind(this),this._onTick=this._onTick.bind(this),this.on("tick",this._onTick,this._onTick),document.addEventListener("keydown",this._onKeyDown),document.addEventListener("keyup",this._onKeyUp),window.addEventListener("blur",this.cancel),window.addEventListener("visibilitychange",this.cancel)}_end(e){this.drag&&(this._moveKeyTimestamps.clear(),this._direction.x=0,this._direction.y=0,super._end(e))}_cancel(e){this.drag&&(this._moveKeyTimestamps.clear(),this._direction.x=0,this._direction.y=0,super._cancel(e))}_updateDirection(){let e=Q(this._moveLeftKeys,this._moveKeyTimestamps),t=Q(this._moveRightKeys,this._moveKeyTimestamps),n=Q(this._moveUpKeys,this._moveKeyTimestamps),i=Q(this._moveDownKeys,this._moveKeyTimestamps),o=e===t?0:e<t?-1:1,s=n===i?0:n<i?-1:1;if(!(o===0||s===0)){let l=1/(Math.sqrt(o*o+s*s)||1);o*=l,s*=l}this._direction.x=o,this._direction.y=s}_onTick(){this._speed=this._computeSpeed(this)}_onKeyUp(e){this._moveKeyTimestamps.get(e.key)&&(this._moveKeyTimestamps.delete(e.key),this._updateDirection())}_onKeyDown(e){if(!this.drag){if(this._startKeys.has(e.key)){let t=this._startPredicate(e,this);t&&(e.preventDefault(),this._start({type:"start",x:t.x,y:t.y}))}return}if(this._cancelKeys.has(e.key)){e.preventDefault(),this._cancel({type:"cancel",x:this.drag.x,y:this.drag.y});return}if(this._endKeys.has(e.key)){e.preventDefault(),this._end({type:"end",x:this.drag.x,y:this.drag.y});return}if(this._moveKeys.has(e.key)){e.preventDefault(),this._moveKeyTimestamps.get(e.key)||(this._moveKeyTimestamps.set(e.key,Date.now()),this._updateDirection());return}}updateSettings(e={}){let t=!1;if(e.startPredicate!==void 0&&(this._startPredicate=e.startPredicate),e.computeSpeed!==void 0&&(this._computeSpeed=e.computeSpeed),at.forEach((n,i)=>{let o=`${n}Keys`,s=e[o];s!==void 0&&(this[`_${o}`]=new Set(s),i>=3&&(t=!0))}),t){let n=[...this._moveLeftKeys,...this._moveRightKeys,...this._moveUpKeys,...this._moveDownKeys];[...this._moveKeys].every((o,s)=>n[s]===o)||(this._moveKeys=new Set(n),this._moveKeyTimestamps.clear(),this._updateDirection())}}destroy(){this.isDestroyed||(super.destroy(),this.off("tick",this._onTick),document.removeEventListener("keydown",this._onKeyDown),document.removeEventListener("keyup",this._onKeyUp),window.removeEventListener("blur",this.cancel),window.removeEventListener("visibilitychange",this.cancel))}};import{Emitter as ht}from"eventti";var Z=class{constructor(e,t){this.sensor=e,this.isEnded=!1,this.event=t,this.prevEvent=t,this.startEvent=t,this.endEvent=null,this.items=[]}};import{getOffsetContainer as Ve}from"mezr";var Ne=new WeakMap;function ee(r){let e=Ne.get(r)?.deref();return e||(e=window.getComputedStyle(r,null),Ne.set(r,new WeakRef(e))),e}import{getOffset as Ye}from"mezr";function te(r,e,t={left:0,top:0}){if(t.left=0,t.top=0,r===e)return t;let n=Ye([r,"padding"]),i=Ye([e,"padding"]);return t.left=i.left-n.left,t.top=i.top-n.top,t}var lt={left:0,top:0},ct="matrix(1, 0, 0, 1, 0, 0)",dt="matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)",ne=class{constructor(e,t){if(!e.isConnected)throw new Error("Element is not connected");let n=t.drag?.sensor;if(!n)throw new Error("Sensor is not defined");let i=this,o=ee(e),s=e.getBoundingClientRect();this.data={},this.element=e,this.frozenProps=null,this.unfrozenProps=null,this.position={x:0,y:0},this._updateDiff={x:0,y:0},this._moveDiff={x:0,y:0},this._containerDiff={x:0,y:0};let l=e.parentElement;if(!l)throw new Error("Element does not have a parent element.");this.elementContainer=l;let a=Ve(e);if(!a)throw new Error("Offset container could not be computed for the element!");this.elementOffsetContainer=a;let c=t.settings.container||l;this.dragContainer=c;let d=c===l?a:Ve(e,{container:c});if(!d)throw new Error("Drag offset container could not be computed for the element!");this.dragOffsetContainer=d;{let{left:_,top:p,width:g,height:x}=s;this.clientRect={left:_,top:p,width:g,height:x}}if(a!==d){let{left:_,top:p}=te(d,a,lt);this._containerDiff.x=_,this._containerDiff.y=p}let{transform:m}=o;m&&m!=="none"&&m!==ct&&m!==dt?this.initialTransform=m:this.initialTransform="";let{x:b,y:v}=t.settings.getStartPosition({draggable:t,sensor:n,item:i,style:o});this.position.x=b,this.position.y=v;let S=t.settings.getFrozenProps({draggable:t,sensor:n,item:i,style:o});if(Array.isArray(S))if(S.length){let _={};for(let p of S)_[p]=o[p];this.frozenProps=_}else this.frozenProps=null;else this.frozenProps=S;if(this.frozenProps){let _={};for(let p in this.frozenProps)this.frozenProps.hasOwnProperty(p)&&(_[p]=e.style[p]);this.unfrozenProps=_}}updateSize(e){if(e)this.clientRect.width=e.width,this.clientRect.height=e.height;else{let t=this.element.getBoundingClientRect();this.clientRect.width=t.width,this.clientRect.height=t.height}}};var Ue=J?{capture:!0,passive:!0}:!0,mt={left:0,top:0},fe={x:0,y:0};function ut(){return{container:null,startPredicate:()=>!0,getElements:()=>null,releaseElements:()=>null,getFrozenProps:()=>null,getStartPosition:()=>({x:0,y:0}),setPosition:({item:r,x:e,y:t})=>{r.element.style.transform=`translate(${e}px, ${t}px) ${r.initialTransform}`},getPositionChange:({event:r,prevEvent:e})=>(fe.x=r.x-e.x,fe.y=r.y-e.y,fe)}}var ze=class{constructor(e,t={}){this.sensors=e,this.settings=this._parseSettings(t),this.plugins={},this.drag=null,this.isDestroyed=!1,this._sensorData=new Map,this._emitter=new ht,this._startId=Symbol(),this._moveId=Symbol(),this._updateId=Symbol(),this._onMove=this._onMove.bind(this),this._onScroll=this._onScroll.bind(this),this._onEnd=this._onEnd.bind(this),this._prepareStart=this._prepareStart.bind(this),this._applyStart=this._applyStart.bind(this),this._prepareMove=this._prepareMove.bind(this),this._applyMove=this._applyMove.bind(this),this._preparePositionUpdate=this._preparePositionUpdate.bind(this),this._applyPositionUpdate=this._applyPositionUpdate.bind(this),this.sensors.forEach(n=>{this._sensorData.set(n,{predicateState:0,predicateEvent:null,onMove:s=>this._onMove(s,n),onEnd:s=>this._onEnd(s,n)});let{onMove:i,onEnd:o}=this._sensorData.get(n);n.on("start",i,i),n.on("move",i,i),n.on("cancel",o,o),n.on("end",o,o),n.on("destroy",o,o)})}_parseSettings(e,t=ut()){let{container:n=t.container,startPredicate:i=t.startPredicate,getElements:o=t.getElements,releaseElements:s=t.releaseElements,getFrozenProps:l=t.getFrozenProps,getStartPosition:a=t.getStartPosition,setPosition:c=t.setPosition,getPositionChange:d=t.getPositionChange}=e||{};return{container:n,startPredicate:i,getElements:o,releaseElements:s,getFrozenProps:l,getStartPosition:a,setPosition:c,getPositionChange:d}}_emit(e,...t){this._emitter.emit(e,...t)}_onMove(e,t){let n=this._sensorData.get(t);if(n)switch(n.predicateState){case 0:{n.predicateEvent=e;let i=this.settings.startPredicate({draggable:this,sensor:t,event:e});i===!0?this.resolveStartPredicate(t):i===!1&&this.rejectStartPredicate(t);break}case 1:{this.drag&&(this.drag.event=e,u.once(E,this._prepareMove,this._moveId),u.once(D,this._applyMove,this._moveId));break}}}_onScroll(){this.updatePosition()}_onEnd(e,t){let n=this._sensorData.get(t);n&&(this.drag?n.predicateState===1&&(this.drag.endEvent=e,this._sensorData.forEach(i=>{i.predicateState=0,i.predicateEvent=null}),this.stop()):(n.predicateState=0,n.predicateEvent=null))}_prepareStart(){let e=this.drag;if(!e)return;let t=this.settings.getElements({draggable:this,sensor:e.sensor,startEvent:e.startEvent})||[];e.items=t.map(n=>new ne(n,this)),this._emit("preparestart",e.startEvent)}_applyStart(){let e=this.drag;if(!e)return;let{container:t}=this.settings;for(let n of e.items)t&&n.element.parentElement!==t&&(t.appendChild(n.element),n.position.x+=n._containerDiff.x,n.position.y+=n._containerDiff.y),n.frozenProps&&Object.assign(n.element.style,n.frozenProps),this.settings.setPosition({phase:"start",draggable:this,sensor:e.sensor,item:n,x:n.position.x,y:n.position.y});window.addEventListener("scroll",this._onScroll,Ue),this._emit("start",e.startEvent)}_prepareMove(){let e=this.drag;if(!e)return;let{event:t,prevEvent:n,startEvent:i,sensor:o}=e;if(t!==n){for(let s of e.items){let{x:l,y:a}=this.settings.getPositionChange({draggable:this,sensor:o,item:s,event:t,prevEvent:n,startEvent:i});l&&(s.position.x+=l,s.clientRect.left+=l,s._moveDiff.x+=l),a&&(s.position.y+=a,s.clientRect.top+=a,s._moveDiff.y+=a)}e.prevEvent=t,this._emit("preparemove",t)}}_applyMove(){let e=this.drag;if(e){for(let t of e.items)t._moveDiff.x=0,t._moveDiff.y=0,this.settings.setPosition({phase:"move",draggable:this,sensor:e.sensor,item:t,x:t.position.x,y:t.position.y});e.event&&this._emit("move",e.event)}}_preparePositionUpdate(){let{drag:e}=this;if(e)for(let t of e.items){if(t.elementOffsetContainer!==t.dragOffsetContainer){let{left:c,top:d}=te(t.dragOffsetContainer,t.elementOffsetContainer,mt);t._containerDiff.x=c,t._containerDiff.y=d}let{left:n,top:i,width:o,height:s}=t.element.getBoundingClientRect(),l=t.clientRect.left-t._moveDiff.x-n;t.position.x=t.position.x-t._updateDiff.x+l,t._updateDiff.x=l;let a=t.clientRect.top-t._moveDiff.y-i;t.position.y=t.position.y-t._updateDiff.y+a,t._updateDiff.y=a,t.clientRect.width=o,t.clientRect.height=s}}_applyPositionUpdate(){let{drag:e}=this;if(e)for(let t of e.items)t._updateDiff.x=0,t._updateDiff.y=0,this.settings.setPosition({phase:"move",draggable:this,sensor:e.sensor,item:t,x:t.position.x,y:t.position.y})}on(e,t,n){return this._emitter.on(e,t,n)}off(e,t){this._emitter.off(e,t)}resolveStartPredicate(e,t){let n=this._sensorData.get(e);if(!n)return;let i=t||n.predicateEvent;n.predicateState===0&&i&&(n.predicateState=1,n.predicateEvent=null,this.drag=new Z(e,i),this._sensorData.forEach((o,s)=>{s!==e&&(o.predicateState=2,o.predicateEvent=null)}),u.once(E,this._prepareStart,this._startId),u.once(D,this._applyStart,this._startId))}rejectStartPredicate(e){let t=this._sensorData.get(e);t?.predicateState===0&&(t.predicateState=2,t.predicateEvent=null)}stop(){let e=this.drag;if(!e||e.isEnded)return;e.isEnded=!0,u.off(E,this._startId),u.off(D,this._startId),u.off(E,this._moveId),u.off(D,this._moveId),u.off(E,this._updateId),u.off(D,this._updateId),window.removeEventListener("scroll",this._onScroll,Ue);let t=[];for(let n of e.items){if(t.push(n.element),n.elementContainer&&n.element.parentElement!==n.elementContainer&&(n.position.x-=n._containerDiff.x,n.position.y-=n._containerDiff.y,n._containerDiff.x=0,n._containerDiff.y=0,n.elementContainer.appendChild(n.element)),n.unfrozenProps)for(let i in n.unfrozenProps)n.element.style[i]=n.unfrozenProps[i]||"";this.settings.setPosition({phase:"end",draggable:this,sensor:e.sensor,item:n,x:n.position.x,y:n.position.y})}t.length&&this.settings.releaseElements({draggable:this,sensor:e.sensor,elements:t}),this._emit("end",e.endEvent),this.drag=null}updatePosition(e=!1){this.drag&&(e?(this._preparePositionUpdate(),this._applyPositionUpdate()):(u.once(E,this._preparePositionUpdate,this._updateId),u.once(D,this._applyPositionUpdate,this._updateId)))}updateSettings(e={}){this.settings=this._parseSettings(e,this.settings)}use(e){return e(this)}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.stop(),this._sensorData.forEach(({onMove:e,onEnd:t},n)=>{n.off("start",e),n.off("move",e),n.off("cancel",t),n.off("end",t),n.off("destroy",t)}),this._sensorData.clear(),this._emit("destroy"),this._emitter.off())}};import{Emitter as ft}from"eventti";import{getDistance as gt,getRect as He}from"mezr";var B=class{constructor(e,t){this._data=[],this._createObject=e,this._onPut=t}pick(){return this._data.length?this._data.pop():this._createObject()}put(e){this._data.indexOf(e)===-1&&(this._onPut&&this._onPut(e),this._data.push(e))}reset(){this._data.length=0}};import{getIntersection as pt}from"mezr";function Be(r,e){let t=pt(r,e);return t?t.width*t.height:0}function ge(r,e){let t=Be(r,e);if(!t)return 0;let n=Math.min(r.width,e.width)*Math.min(r.height,e.height);return t/n*100}function w(r){return r instanceof Window}function Se(r){return w(r)||r===document.documentElement||r===document.body?window:r}function N(r){return w(r)?r.pageXOffset:r.scrollLeft}function Ee(r){return w(r)&&(r=document.documentElement),r.scrollWidth-r.clientWidth}function Y(r){return w(r)?r.pageYOffset:r.scrollTop}function ve(r){return w(r)&&(r=document.documentElement),r.scrollHeight-r.clientHeight}function _e(r,e){return!(r.right<=e.left||e.right<=r.left||r.bottom<=e.top||e.bottom<=r.top)}var xe={width:0,height:0,left:0,right:0,top:0,bottom:0},Ge={...xe},Fe=50,I={direction:"none",threshold:0,distance:0,value:0,maxValue:0,duration:0,speed:0,deltaTime:0,isEnding:!1},h={x:1,y:2},M={forward:4,reverse:8},re={none:0,left:h.x|M.reverse,right:h.x|M.forward},H={none:0,up:h.y|M.reverse,down:h.y|M.forward},f={...re,...H};function ye(r){switch(r){case re.none:case H.none:return"none";case re.left:return"left";case re.right:return"right";case H.up:return"up";case H.down:return"down";default:throw new Error(`Unknown direction value: ${r}`)}}function je(r,e,t){let{left:n=0,right:i=0,top:o=0,bottom:s=0}=e;return n=Math.max(0,n),i=Math.max(0,i),o=Math.max(0,o),s=Math.max(0,s),t.width=r.width+n+i,t.height=r.height+o+s,t.left=r.left-n,t.top=r.top-o,t.right=r.right+i,t.bottom=r.bottom+s,t}function ie(r,e){return Math.ceil(r)>=Math.floor(e)}function be(r,e){return Math.min(e/2,r)}function De(r,e,t,n){return Math.max(0,t+r*2+n*e-n)/2}var Pe=class{constructor(){this.positionX=0,this.positionY=0,this.directionX=f.none,this.directionY=f.none,this.overlapCheckRequestTime=0}},Te=class{constructor(){this.element=null,this.requestX=null,this.requestY=null,this.scrollLeft=0,this.scrollTop=0}reset(){this.requestX&&(this.requestX.action=null),this.requestY&&(this.requestY.action=null),this.element=null,this.requestX=null,this.requestY=null,this.scrollLeft=0,this.scrollTop=0}addRequest(e){h.x&e.direction?(this.requestX&&this.removeRequest(this.requestX),this.requestX=e):(this.requestY&&this.removeRequest(this.requestY),this.requestY=e),e.action=this}removeRequest(e){this.requestX===e?(this.requestX=null,e.action=null):this.requestY===e&&(this.requestY=null,e.action=null)}computeScrollValues(){this.element&&(this.scrollLeft=this.requestX?this.requestX.value:N(this.element),this.scrollTop=this.requestY?this.requestY.value:Y(this.element))}scroll(){this.element&&(this.element.scrollTo?this.element.scrollTo(this.scrollLeft,this.scrollTop):(this.element.scrollLeft=this.scrollLeft,this.element.scrollTop=this.scrollTop))}},we=class{constructor(){this.item=null,this.element=null,this.isActive=!1,this.isEnding=!1,this.direction=0,this.value=NaN,this.maxValue=0,this.threshold=0,this.distance=0,this.deltaTime=0,this.speed=0,this.duration=0,this.action=null}reset(){this.isActive&&this.onStop(),this.item=null,this.element=null,this.isActive=!1,this.isEnding=!1,this.direction=0,this.value=NaN,this.maxValue=0,this.threshold=0,this.distance=0,this.deltaTime=0,this.speed=0,this.duration=0,this.action=null}hasReachedEnd(){return M.forward&this.direction?ie(this.value,this.maxValue):this.value<=0}computeCurrentScrollValue(){return this.element?this.value!==this.value?h.x&this.direction?N(this.element):Y(this.element):Math.max(0,Math.min(this.value,this.maxValue)):0}computeNextScrollValue(){let e=this.speed*(this.deltaTime/1e3),t=M.forward&this.direction?this.value+e:this.value-e;return Math.max(0,Math.min(t,this.maxValue))}computeSpeed(){if(!this.item||!this.element)return 0;let{speed:e}=this.item;return typeof e=="function"?(I.direction=ye(this.direction),I.threshold=this.threshold,I.distance=this.distance,I.value=this.value,I.maxValue=this.maxValue,I.duration=this.duration,I.speed=this.speed,I.deltaTime=this.deltaTime,I.isEnding=this.isEnding,e(this.element,I)):e}tick(e){return this.isActive||(this.isActive=!0,this.onStart()),this.deltaTime=e,this.value=this.computeCurrentScrollValue(),this.speed=this.computeSpeed(),this.value=this.computeNextScrollValue(),this.duration+=e,this.value}onStart(){if(!this.item||!this.element)return;let{onStart:e}=this.item;typeof e=="function"&&e(this.element,ye(this.direction))}onStop(){if(!this.item||!this.element)return;let{onStop:e}=this.item;typeof e=="function"&&e(this.element,ye(this.direction))}};function $e(r=500,e=.5,t=.25){let n=r*(e>0?1/e:1/0),i=r*(t>0?1/t:1/0);return function(o,s){let l=0;if(!s.isEnding)if(s.threshold>0){let d=s.threshold-Math.max(0,s.distance);l=r/s.threshold*d}else l=r;let a=s.speed;if(a===l)return l;let c=l;return a<l?(c=a+n*(s.deltaTime/1e3),Math.min(l,c)):(c=a-i*(s.deltaTime/1e3),Math.max(l,c))}}var oe=class{constructor(e={}){let{overlapCheckInterval:t=150}=e;this.items=[],this.settings={overlapCheckInterval:t},this._actions=[],this._isDestroyed=!1,this._isTicking=!1,this._tickTime=0,this._tickDeltaTime=0,this._requests={[h.x]:new Map,[h.y]:new Map},this._itemData=new Map,this._requestPool=new B(()=>new we,n=>n.reset()),this._actionPool=new B(()=>new Te,n=>n.reset()),this._emitter=new ft,this._frameRead=this._frameRead.bind(this),this._frameWrite=this._frameWrite.bind(this)}_frameRead(e){this._isDestroyed||(e&&this._tickTime?(this._tickDeltaTime=e-this._tickTime,this._tickTime=e,this._updateItems(),this._updateRequests(),this._updateActions()):(this._tickTime=e,this._tickDeltaTime=0))}_frameWrite(){this._isDestroyed||this._applyActions()}_startTicking(){this._isTicking||(this._isTicking=!0,u.on(E,this._frameRead,this._frameRead),u.on(D,this._frameWrite,this._frameWrite))}_stopTicking(){this._isTicking&&(this._isTicking=!1,this._tickTime=0,this._tickDeltaTime=0,u.off(E,this._frameRead),u.off(D,this._frameWrite))}_getItemClientRect(e,t={width:0,height:0,left:0,right:0,top:0,bottom:0}){let{clientRect:n}=e;return t.left=n.left,t.top=n.top,t.width=n.width,t.height=n.height,t.right=n.left+n.width,t.bottom=n.top+n.height,t}_requestItemScroll(e,t,n,i,o,s,l){let a=this._requests[t],c=a.get(e);c?(c.element!==n||c.direction!==i)&&c.reset():(c=this._requestPool.pick(),a.set(e,c)),c.item=e,c.element=n,c.direction=i,c.threshold=o,c.distance=s,c.maxValue=l}_cancelItemScroll(e,t){let n=this._requests[t],i=n.get(e);i&&(i.action&&i.action.removeRequest(i),this._requestPool.put(i),n.delete(e))}_checkItemOverlap(e,t,n){let{inertAreaSize:i,targets:o}=e;if(!o.length){t&&this._cancelItemScroll(e,h.x),n&&this._cancelItemScroll(e,h.y);return}let s=this._itemData.get(e),l=s?.directionX,a=s?.directionY;if(!l&&!a){t&&this._cancelItemScroll(e,h.x),n&&this._cancelItemScroll(e,h.y);return}let c=this._getItemClientRect(e,xe),d=null,m=-1/0,b=0,v=-1/0,S=f.none,_=0,p=0,g=null,x=-1/0,V=0,U=-1/0,ae=f.none,Ce=0,Re=0,le=0;for(;le<o.length;le++){let A=o[le],Le=typeof A.threshold=="number"?A.threshold:Fe,ce=!!(t&&l&&A.axis!=="y"),de=!!(n&&a&&A.axis!=="x"),O=A.priority||0;if((!ce||O<m)&&(!de||O<x))continue;let k=Se(A.element||A),F=ce?Ee(k):-1,j=de?ve(k):-1;if(F<=0&&j<=0)continue;let P=He([k,"padding"],window),K=ge(c,P)||-1/0;if(K===-1/0)if(A.padding&&_e(c,je(P,A.padding,Ge)))K=-(gt(c,P)||0);else continue;if(ce&&O>=m&&F>0&&(O>m||K>v)){let T=0,C=f.none,R=be(Le,P.width),z=De(R,i,c.width,P.width);l===f.right?(T=P.right+z-c.right,T<=R&&!ie(N(k),F)&&(C=f.right)):l===f.left&&(T=c.left-(P.left-z),T<=R&&N(k)>0&&(C=f.left)),C&&(d=k,m=O,b=R,v=K,S=C,_=T,p=F)}if(de&&O>=x&&j>0&&(O>x||K>U)){let T=0,C=H.none,R=be(Le,P.height),z=De(R,i,c.height,P.height);a===f.down?(T=P.bottom+z-c.bottom,T<=R&&!ie(Y(k),j)&&(C=f.down)):a===f.up&&(T=c.top-(P.top-z),T<=R&&Y(k)>0&&(C=f.up)),C&&(g=k,x=O,V=R,U=K,ae=C,Ce=T,Re=j)}}t&&(d&&S?this._requestItemScroll(e,h.x,d,S,b,_,p):this._cancelItemScroll(e,h.x)),n&&(g&&ae?this._requestItemScroll(e,h.y,g,ae,V,Ce,Re):this._cancelItemScroll(e,h.y))}_updateScrollRequest(e){let t=e.item,{inertAreaSize:n,smoothStop:i,targets:o}=t,s=this._getItemClientRect(t,xe),l=null,a=0;for(;a<o.length;a++){let c=o[a],d=Se(c.element||c);if(d!==e.element)continue;let m=!!(h.x&e.direction);if(m){if(c.axis==="y")continue}else if(c.axis==="x")continue;let b=m?Ee(d):ve(d);if(b<=0)break;let v=He([d,"padding"],window);if((ge(s,v)||-1/0)===-1/0){let U=c.scrollPadding||c.padding;if(!(U&&_e(s,je(v,U,Ge))))break}let _=typeof c.threshold=="number"?c.threshold:Fe,p=be(_,m?v.width:v.height),g=De(p,n,m?s.width:s.height,m?v.width:v.height),x=0;if(e.direction===f.left?x=s.left-(v.left-g):e.direction===f.right?x=v.right+g-s.right:e.direction===f.up?x=s.top-(v.top-g):x=v.bottom+g-s.bottom,x>p)break;let V=m?N(d):Y(d);if(l=M.forward&e.direction?ie(V,b):V<=0,l)break;return e.maxValue=b,e.threshold=p,e.distance=x,e.isEnding=!1,!0}return i===!0&&e.speed>0?(l===null&&(l=e.hasReachedEnd()),e.isEnding=!l):e.isEnding=!1,e.isEnding}_updateItems(){for(let e=0;e<this.items.length;e++){let t=this.items[e],n=this._itemData.get(t),{x:i,y:o}=t.position,s=n.positionX,l=n.positionY;i===s&&o===l||(n.directionX=i>s?f.right:i<s?f.left:n.directionX,n.directionY=o>l?f.down:o<l?f.up:n.directionY,n.positionX=i,n.positionY=o,n.overlapCheckRequestTime===0&&(n.overlapCheckRequestTime=this._tickTime))}}_updateRequests(){let e=this.items,t=this._requests[h.x],n=this._requests[h.y],i=0;for(;i<e.length;i++){let o=e[i],s=this._itemData.get(o),l=s.overlapCheckRequestTime,a=l>0&&this._tickTime-l>this.settings.overlapCheckInterval,c=!0,d=t.get(o);d&&d.isActive&&(c=!this._updateScrollRequest(d),c&&(a=!0,this._cancelItemScroll(o,h.x)));let m=!0,b=n.get(o);b&&b.isActive&&(m=!this._updateScrollRequest(b),m&&(a=!0,this._cancelItemScroll(o,h.y))),a&&(s.overlapCheckRequestTime=0,this._checkItemOverlap(o,c,m))}}_requestAction(e,t){let n=t===h.x,i=null,o=0;for(;o<this._actions.length;o++){if(i=this._actions[o],e.element!==i.element){i=null;continue}if(n?i.requestX:i.requestY){this._cancelItemScroll(e.item,t);return}break}i||(i=this._actionPool.pick()),i.element=e.element,i.addRequest(e),e.tick(this._tickDeltaTime),this._actions.push(i)}_updateActions(){let e=0;for(e=0;e<this.items.length;e++){let t=this.items[e],n=this._requests[h.x].get(t),i=this._requests[h.y].get(t);n&&this._requestAction(n,h.x),i&&this._requestAction(i,h.y)}for(e=0;e<this._actions.length;e++)this._actions[e].computeScrollValues()}_applyActions(){if(!this._actions.length)return;this._emitter.emit("beforescroll");let e=0;for(e=0;e<this._actions.length;e++)this._actions[e].scroll(),this._actionPool.put(this._actions[e]);this._actions.length=0;let t;for(e=0;e<this.items.length;e++)t=this.items[e],t.onPrepareScrollEffect&&t.onPrepareScrollEffect();for(e=0;e<this.items.length;e++)t=this.items[e],t.onApplyScrollEffect&&t.onApplyScrollEffect();this._emitter.emit("afterscroll")}on(e,t,n){return this._emitter.on(e,t,n)}off(e,t){this._emitter.off(e,t)}addItem(e){if(this._isDestroyed||this._itemData.has(e))return;let{x:t,y:n}=e.position,i=new Pe;i.positionX=t,i.positionY=n,i.directionX=f.none,i.directionY=f.none,i.overlapCheckRequestTime=this._tickTime,this._itemData.set(e,i),this.items.push(e),this._isTicking||this._startTicking()}removeItem(e){if(this._isDestroyed)return;let t=this.items.indexOf(e);t!==-1&&(this._requests[h.x].get(e)&&(this._cancelItemScroll(e,h.x),this._requests[h.x].delete(e)),this._requests[h.y].get(e)&&(this._cancelItemScroll(e,h.y),this._requests[h.y].delete(e)),this._itemData.delete(e),this.items.splice(t,1),this._isTicking&&!this.items.length&&this._stopTicking())}isDestroyed(){return this._isDestroyed}isItemScrollingX(e){return!!this._requests[h.x].get(e)?.isActive}isItemScrollingY(e){return!!this._requests[h.y].get(e)?.isActive}isItemScrolling(e){return this.isItemScrollingX(e)||this.isItemScrollingY(e)}updateSettings(e={}){let{overlapCheckInterval:t=this.settings.overlapCheckInterval}=e;this.settings.overlapCheckInterval=t}destroy(){if(this._isDestroyed)return;let e=this.items.slice(0),t=0;for(;t<e.length;t++)this.removeItem(e[t]);this._actions.length=0,this._requestPool.reset(),this._actionPool.reset(),this._emitter.off(),this._isDestroyed=!0}};var Ie=new oe;var G={x:0,y:0},L={left:0,top:0,width:0,height:0};function St(){return{targets:[],inertAreaSize:.2,speed:$e(),smoothStop:!1,getPosition:r=>{let{drag:e}=r,t=e?.items[0];if(t)G.x=t.position.x,G.y=t.position.y;else{let n=e&&(e.event||e.startEvent);G.x=n?n.x:0,G.y=n?n.y:0}return G},getClientRect:r=>{let{drag:e}=r,t=e?.items[0];if(t&&t.element){let{left:n,top:i,width:o,height:s}=t.clientRect;L.left=n,L.top=i,L.width=o,L.height=s}else{let n=e&&(e.event||e.startEvent);L.left=n?n.x-25:0,L.top=n?n.y-25:0,L.width=n?50:0,L.height=n?50:0}return L},onStart:null,onStop:null}}var Ae=class{constructor(e,t){this._draggableAutoScroll=e,this._draggable=t,this._position={x:0,y:0},this._clientRect={left:0,top:0,width:0,height:0}}_getSettings(){return this._draggableAutoScroll.settings}get targets(){let{targets:e}=this._getSettings();return typeof e=="function"&&(e=e(this._draggable)),e}get position(){let{getPosition:e}=this._getSettings();if(typeof e=="function"){let t=e(this._draggable);this._position.x=t.x,this._position.y=t.y}else this._position.x=0,this._position.y=0;return this._position}get clientRect(){let{getClientRect:e}=this._getSettings();if(typeof e=="function"){let{left:t,top:n,width:i,height:o}=e(this._draggable);this._clientRect.left=t,this._clientRect.top=n,this._clientRect.width=i,this._clientRect.height=o}else this._clientRect.left=0,this._clientRect.top=0,this._clientRect.width=0,this._clientRect.height=0;return this._clientRect}get inertAreaSize(){return this._getSettings().inertAreaSize}get smoothStop(){return this._getSettings().smoothStop}get speed(){return this._getSettings().speed}get onStart(){return this._getSettings().onStart}get onStop(){return this._getSettings().onStop}onPrepareScrollEffect(){let e=this._draggable._updateId;u.off(E,e),u.off(D,e),this._draggable._preparePositionUpdate()}onApplyScrollEffect(){this._draggable._applyPositionUpdate()}},ke=class{constructor(e,t={}){this.name="autoscroll",this.version="0.0.2",this.settings=this._parseSettings(t),this._autoScrollProxy=null,e.on("start",()=>{this._autoScrollProxy||(this._autoScrollProxy=new Ae(this,e),Ie.addItem(this._autoScrollProxy))}),e.on("end",()=>{this._autoScrollProxy&&(Ie.removeItem(this._autoScrollProxy),this._autoScrollProxy=null)})}_parseSettings(e,t=St()){let{targets:n=t.targets,inertAreaSize:i=t.inertAreaSize,speed:o=t.speed,smoothStop:s=t.smoothStop,getPosition:l=t.getPosition,getClientRect:a=t.getClientRect,onStart:c=t.onStart,onStop:d=t.onStop}=e||{};return{targets:n,inertAreaSize:i,speed:o,smoothStop:s,getPosition:l,getClientRect:a,onStart:c,onStop:d}}updateSettings(e={}){this.settings=this._parseSettings(e,this.settings)}};function fr(r){return e=>{let t=new ke(e,r),n=e;return n.plugins[t.name]=t,n}}var Je=new Set(["auto","scroll","overlay"]);function se(r){let e=ee(r);return!!(Je.has(e.overflowY)||Je.has(e.overflowX))}function Qe(r){return r instanceof Document}function Ze(r,e=[]){let t=r?.parentNode;for(;t&&!Qe(t);)t instanceof Element?(se(t)&&e.push(t),t=t.parentNode):t instanceof ShadowRoot?t=t.host:t=t.parentNode;return e.push(window),e}function Et(r){let e=[];return se(r)&&e.push(r),Ze(r,e),e}function wr(r={}){let e,t=0,n=null,i,{timeout:o=250,fallback:s=()=>!0}=r,l=d=>d.preventDefault(),a=d=>{if(t){if(e){d.cancelable&&d.preventDefault();return}e===void 0&&(d.cancelable&&d.timeStamp-t>o?(e=!0,d.preventDefault()):e=!1)}};return d=>{if(!(d.sensor instanceof X))return s(d);let{draggable:m,sensor:b,event:v}=d,S=v;if(S.pointerType==="touch"){if(S.type==="start"&&(S.srcEvent.type==="pointerdown"||S.srcEvent.type==="touchstart")){n=S.target;let _=n?Et(n):[];_.forEach(g=>{g.addEventListener("touchmove",a,{passive:!1,capture:!0})});let p=()=>{t&&(m.off("end",p),m.sensors.forEach(g=>{g instanceof X&&g.off("end",p)}),n?.removeEventListener("contextmenu",l),_.forEach(g=>{g.removeEventListener("touchmove",a,{capture:!0})}),t=0,e=void 0,n=null,i=void window.clearTimeout(i))};e=void 0,t=S.srcEvent.timeStamp,n?.addEventListener("contextmenu",l),m.on("end",p),m.sensors.forEach(g=>{g instanceof X&&g.off("end",p)}),o>0&&(i=window.setTimeout(()=>{m.resolveStartPredicate(b),e=!0,i=void 0},o))}return e}return S.type==="start"&&!S.srcEvent.button}}function vt(r,e){return Math.round(r/e)*e}function et(r,e,t){let n=t-e,i=Math.abs(n);if(i>=r){let o=i%r;return vt(n>0?n-o:n+o,r)}return 0}function Ar(r,e){return function({startEvent:n,event:i,item:o}){let{__snapX__:s=n.x,__snapY__:l=n.y}=o.data,a=et(r,s,i.x),c=et(e,l,i.y);return a&&(o.data.__snapX__=s+a),c&&(o.data.__snapY__=l+c),{x:a,y:c}}}export{h as AUTO_SCROLL_AXIS,M as AUTO_SCROLL_AXIS_DIRECTION,f as AUTO_SCROLL_DIRECTION,oe as AutoScroll,$ as BaseMotionSensor,W as BaseSensor,ze as Draggable,ke as DraggableAutoScroll,Xe as KeyboardMotionSensor,qe as KeyboardSensor,X as PointerSensor,y as SensorEventType,Ie as autoScroll,fr as autoScrollPlugin,$e as autoScrollSmoothSpeed,wr as createPointerSensorStartPredicate,Ar as createSnapModifier,Ct as setTicker,u as ticker,E as tickerReadPhase,D as tickerWritePhase};
var b={start:"start",move:"move",cancel:"cancel",end:"end",destroy:"destroy"};import{Emitter as st}from"eventti";var V=class{constructor(){this.drag=null,this.isDestroyed=!1,this._emitter=new st}_createDragData(e){return{x:e.x,y:e.y}}_updateDragData(e){this.drag&&(this.drag.x=e.x,this.drag.y=e.y)}_resetDragData(){this.drag=null}_start(e){this.isDestroyed||this.drag||(this.drag=this._createDragData(e),this._emitter.emit(b.start,e))}_move(e){this.drag&&(this._updateDragData(e),this._emitter.emit(b.move,e))}_end(e){this.drag&&(this._updateDragData(e),this._emitter.emit(b.end,e),this._resetDragData())}_cancel(e){this.drag&&(this._updateDragData(e),this._emitter.emit(b.cancel,e),this._resetDragData())}on(e,t,n){return this._emitter.on(e,t,n)}off(e,t){this._emitter.off(e,t)}cancel(){this.drag&&this._cancel({type:b.cancel,x:this.drag.x,y:this.drag.y})}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.cancel(),this._emitter.emit(b.destroy,{type:b.destroy}),this._emitter.off())}};import{AutoTicker as at}from"tikki";var v=Symbol(),x=Symbol(),m=new at({phases:[v,x]});function Vt(r,e,t){v=e,x=t,m=r}var Q=class extends V{constructor(){super(),this.drag=null,this._direction={x:0,y:0},this._speed=0,this._tick=this._tick.bind(this)}_createDragData(e){return{...super._createDragData(e),time:0,deltaTime:0}}_start(e){this.isDestroyed||this.drag||(super._start(e),m.on(v,this._tick,this._tick))}_end(e){this.drag&&(m.off(v,this._tick),super._end(e))}_cancel(e){this.drag&&(m.off(v,this._tick),super._cancel(e))}_tick(e){if(this.drag)if(e&&this.drag.time){this.drag.deltaTime=e-this.drag.time,this.drag.time=e;let t={type:"tick",time:this.drag.time,deltaTime:this.drag.deltaTime};if(this._emitter.emit("tick",t),!this.drag)return;let n=this._speed*(this.drag.deltaTime/1e3),i=this._direction.x*n,o=this._direction.y*n;(i||o)&&this._move({type:"move",x:this.drag.x+i,y:this.drag.y+o})}else this.drag.time=e,this.drag.deltaTime=0}};import{Emitter as lt}from"eventti";function me(r,e){if("pointerId"in r)return r.pointerId===e?r:null;if("changedTouches"in r){let t=0;for(;t<r.changedTouches.length;t++)if(r.changedTouches[t].identifier===e)return r.changedTouches[t];return null}return r}function Ve(r){return"pointerType"in r?r.pointerType:"touches"in r?"touch":"mouse"}function Ne(r){return"pointerId"in r?r.pointerId:"changedTouches"in r?r.changedTouches[0]?r.changedTouches[0].identifier:null:-1}var pe=typeof window<"u"&&typeof window.document<"u",Z=(()=>{let r=!1;try{let e=Object.defineProperty({},"passive",{get:function(){r=!0}});window.addEventListener("testPassive",null,e),window.removeEventListener("testPassive",null,e)}catch{}return r})(),qe=pe&&"ontouchstart"in window,Xe=pe&&!!window.PointerEvent,Ft=!!(pe&&navigator.vendor&&navigator.vendor.indexOf("Apple")>-1&&navigator.userAgent&&navigator.userAgent.indexOf("CriOS")==-1&&navigator.userAgent.indexOf("FxiOS")==-1);function fe(r={}){let{capture:e=!0,passive:t=!0}=r;return Z?{capture:e,passive:t}:{capture:e}}function ge(r){return r==="auto"||r===void 0?Xe?"pointer":qe?"touch":"mouse":r}var ct={start:"pointerdown",move:"pointermove",cancel:"pointercancel",end:"pointerup"},dt={start:"touchstart",move:"touchmove",cancel:"touchcancel",end:"touchend"},ht={start:"mousedown",move:"mousemove",cancel:"",end:"mouseup"},N={pointer:ct,touch:dt,mouse:ht},q=class{constructor(e,t={}){let{listenerOptions:n={},sourceEvents:i="auto",startPredicate:o=s=>!("button"in s&&s.button>0)}=t;this.element=e,this.drag=null,this.isDestroyed=!1,this._areWindowListenersBound=!1,this._startPredicate=o,this._listenerOptions=fe(n),this._sourceEvents=ge(i),this._emitter=new lt,this._onStart=this._onStart.bind(this),this._onMove=this._onMove.bind(this),this._onCancel=this._onCancel.bind(this),this._onEnd=this._onEnd.bind(this),e.addEventListener(N[this._sourceEvents].start,this._onStart,this._listenerOptions)}_getTrackedPointerEventData(e){return this.drag?me(e,this.drag.pointerId):null}_onStart(e){if(this.isDestroyed||this.drag||!this._startPredicate(e))return;let t=Ne(e);if(t===null)return;let n=me(e,t);if(n===null)return;let i={pointerId:t,pointerType:Ve(e),x:n.clientX,y:n.clientY};this.drag=i;let o={...i,type:b.start,srcEvent:e,target:n.target};this._emitter.emit(o.type,o),this.drag&&this._bindWindowListeners()}_onMove(e){if(!this.drag)return;let t=this._getTrackedPointerEventData(e);if(!t)return;this.drag.x=t.clientX,this.drag.y=t.clientY;let n={type:b.move,srcEvent:e,target:t.target,...this.drag};this._emitter.emit(n.type,n)}_onCancel(e){if(!this.drag)return;let t=this._getTrackedPointerEventData(e);if(!t)return;this.drag.x=t.clientX,this.drag.y=t.clientY;let n={type:b.cancel,srcEvent:e,target:t.target,...this.drag};this._emitter.emit(n.type,n),this._resetDrag()}_onEnd(e){if(!this.drag)return;let t=this._getTrackedPointerEventData(e);if(!t)return;this.drag.x=t.clientX,this.drag.y=t.clientY;let n={type:b.end,srcEvent:e,target:t.target,...this.drag};this._emitter.emit(n.type,n),this._resetDrag()}_bindWindowListeners(){if(this._areWindowListenersBound)return;let{move:e,end:t,cancel:n}=N[this._sourceEvents];window.addEventListener(e,this._onMove,this._listenerOptions),window.addEventListener(t,this._onEnd,this._listenerOptions),n&&window.addEventListener(n,this._onCancel,this._listenerOptions),this._areWindowListenersBound=!0}_unbindWindowListeners(){if(this._areWindowListenersBound){let{move:e,end:t,cancel:n}=N[this._sourceEvents];window.removeEventListener(e,this._onMove,this._listenerOptions),window.removeEventListener(t,this._onEnd,this._listenerOptions),n&&window.removeEventListener(n,this._onCancel,this._listenerOptions),this._areWindowListenersBound=!1}}_resetDrag(){this.drag=null,this._unbindWindowListeners()}cancel(){if(!this.drag)return;let e={type:b.cancel,srcEvent:null,target:null,...this.drag};this._emitter.emit(e.type,e),this._resetDrag()}updateSettings(e){if(this.isDestroyed)return;let{listenerOptions:t,sourceEvents:n,startPredicate:i}=e,o=ge(n),s=fe(t);i&&this._startPredicate!==i&&(this._startPredicate=i),(t&&(this._listenerOptions.capture!==s.capture||this._listenerOptions.passive===s.passive)||n&&this._sourceEvents!==o)&&(this.element.removeEventListener(N[this._sourceEvents].start,this._onStart,this._listenerOptions),this._unbindWindowListeners(),this.cancel(),n&&(this._sourceEvents=o),t&&s&&(this._listenerOptions=s),this.element.addEventListener(N[this._sourceEvents].start,this._onStart,this._listenerOptions))}on(e,t,n){return this._emitter.on(e,t,n)}off(e,t){this._emitter.off(e,t)}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.cancel(),this._emitter.emit(b.destroy,{type:b.destroy}),this._emitter.off(),this.element.removeEventListener(N[this._sourceEvents].start,this._onStart,this._listenerOptions))}};var K={moveDistance:25,cancelOnBlur:!0,cancelOnVisibilityChange:!0,startPredicate:(r,e)=>{if(e.element&&(r.key==="Enter"||r.key===" ")&&document.activeElement===e.element){let{x:t,y:n}=e.element.getBoundingClientRect();return{x:t,y:n}}return null},movePredicate:(r,e)=>{if(!e.drag)return null;switch(r.key){case"ArrowLeft":return{x:e.drag.x-e.moveDistance.x,y:e.drag.y};case"ArrowRight":return{x:e.drag.x+e.moveDistance.x,y:e.drag.y};case"ArrowUp":return{x:e.drag.x,y:e.drag.y-e.moveDistance.y};case"ArrowDown":return{x:e.drag.x,y:e.drag.y+e.moveDistance.y};default:return null}},cancelPredicate:(r,e)=>{if(e.drag&&r.key==="Escape"){let{x:t,y:n}=e.drag;return{x:t,y:n}}return null},endPredicate:(r,e)=>{if(e.drag&&(r.key==="Enter"||r.key===" ")){let{x:t,y:n}=e.drag;return{x:t,y:n}}return null}},Ye=class extends V{constructor(e,t={}){super();let{moveDistance:n=K.moveDistance,cancelOnBlur:i=K.cancelOnBlur,cancelOnVisibilityChange:o=K.cancelOnVisibilityChange,startPredicate:s=K.startPredicate,movePredicate:a=K.movePredicate,cancelPredicate:c=K.cancelPredicate,endPredicate:l=K.endPredicate}=t;this.element=e,this.moveDistance=typeof n=="number"?{x:n,y:n}:{...n},this._cancelOnBlur=i,this._cancelOnVisibilityChange=o,this._startPredicate=s,this._movePredicate=a,this._cancelPredicate=c,this._endPredicate=l,this._onKeyDown=this._onKeyDown.bind(this),this._internalCancel=this._internalCancel.bind(this),this._blurCancelHandler=this._blurCancelHandler.bind(this),document.addEventListener("keydown",this._onKeyDown),i&&e?.addEventListener("blur",this._blurCancelHandler),o&&document.addEventListener("visibilitychange",this._internalCancel)}_internalCancel(){this.cancel()}_blurCancelHandler(){queueMicrotask(()=>{document.activeElement!==this.element&&this.cancel()})}_onKeyDown(e){if(!this.drag){let o=this._startPredicate(e,this);o&&(e.preventDefault(),this._start({type:"start",x:o.x,y:o.y,srcEvent:e}));return}let t=this._cancelPredicate(e,this);if(t){e.preventDefault(),this._cancel({type:"cancel",x:t.x,y:t.y,srcEvent:e});return}let n=this._endPredicate(e,this);if(n){e.preventDefault(),this._end({type:"end",x:n.x,y:n.y,srcEvent:e});return}let i=this._movePredicate(e,this);if(i){e.preventDefault(),this._move({type:"move",x:i.x,y:i.y,srcEvent:e});return}}updateSettings(e={}){let{moveDistance:t,cancelOnBlur:n,cancelOnVisibilityChange:i,startPredicate:o,movePredicate:s,cancelPredicate:a,endPredicate:c}=e;t!==void 0&&(typeof t=="number"?this.moveDistance.x=this.moveDistance.y=t:(this.moveDistance.x=t.x,this.moveDistance.y=t.y)),n!==void 0&&this._cancelOnBlur!==n&&(this._cancelOnBlur=n,n?this.element?.addEventListener("blur",this._blurCancelHandler):this.element?.removeEventListener("blur",this._blurCancelHandler)),i!==void 0&&this._cancelOnVisibilityChange!==i&&(this._cancelOnVisibilityChange=i,i?document.addEventListener("visibilitychange",this._internalCancel):document.removeEventListener("visibilitychange",this._internalCancel)),o&&(this._startPredicate=o),s&&(this._movePredicate=s),a&&(this._cancelPredicate=a),c&&(this._endPredicate=c)}destroy(){this.isDestroyed||(super.destroy(),document.removeEventListener("keydown",this._onKeyDown),this._cancelOnBlur&&this.element?.removeEventListener("blur",this._blurCancelHandler),this._cancelOnVisibilityChange&&document.removeEventListener("visibilitychange",this._internalCancel))}};var ut=["start","cancel","end","moveLeft","moveRight","moveUp","moveDown"];function ee(r,e){if(!r.size||!e.size)return 1/0;let t=1/0;for(let n of r){let i=e.get(n);i!==void 0&&i<t&&(t=i)}return t}var I={startKeys:[" ","Enter"],moveLeftKeys:["ArrowLeft"],moveRightKeys:["ArrowRight"],moveUpKeys:["ArrowUp"],moveDownKeys:["ArrowDown"],cancelKeys:["Escape"],endKeys:[" ","Enter"],cancelOnBlur:!0,cancelOnVisibilityChange:!0,computeSpeed:()=>500,startPredicate:(r,e)=>{if(e.element&&document.activeElement===e.element){let{left:t,top:n}=e.element.getBoundingClientRect();return{x:t,y:n}}return null}},Ue=class extends Q{constructor(e,t={}){super();let{startPredicate:n=I.startPredicate,computeSpeed:i=I.computeSpeed,cancelOnVisibilityChange:o=I.cancelOnVisibilityChange,cancelOnBlur:s=I.cancelOnBlur,startKeys:a=I.startKeys,moveLeftKeys:c=I.moveLeftKeys,moveRightKeys:l=I.moveRightKeys,moveUpKeys:d=I.moveUpKeys,moveDownKeys:u=I.moveDownKeys,cancelKeys:y=I.cancelKeys,endKeys:g=I.endKeys}=t;this.element=e,this._startKeys=new Set(a),this._cancelKeys=new Set(y),this._endKeys=new Set(g),this._moveLeftKeys=new Set(c),this._moveRightKeys=new Set(l),this._moveUpKeys=new Set(d),this._moveDownKeys=new Set(u),this._moveKeys=new Set([...c,...l,...d,...u]),this._moveKeyTimestamps=new Map,this._cancelOnBlur=s,this._cancelOnVisibilityChange=o,this._computeSpeed=i,this._startPredicate=n,this._onKeyDown=this._onKeyDown.bind(this),this._onKeyUp=this._onKeyUp.bind(this),this._onTick=this._onTick.bind(this),this._internalCancel=this._internalCancel.bind(this),this._blurCancelHandler=this._blurCancelHandler.bind(this),this.on("tick",this._onTick,this._onTick),document.addEventListener("keydown",this._onKeyDown),document.addEventListener("keyup",this._onKeyUp),s&&e?.addEventListener("blur",this._blurCancelHandler),o&&document.addEventListener("visibilitychange",this._internalCancel)}_end(e){this.drag&&(this._moveKeyTimestamps.clear(),this._direction.x=0,this._direction.y=0,super._end(e))}_cancel(e){this.drag&&(this._moveKeyTimestamps.clear(),this._direction.x=0,this._direction.y=0,super._cancel(e))}_internalCancel(){this.cancel()}_blurCancelHandler(){queueMicrotask(()=>{document.activeElement!==this.element&&this.cancel()})}_updateDirection(){let e=ee(this._moveLeftKeys,this._moveKeyTimestamps),t=ee(this._moveRightKeys,this._moveKeyTimestamps),n=ee(this._moveUpKeys,this._moveKeyTimestamps),i=ee(this._moveDownKeys,this._moveKeyTimestamps),o=e===t?0:e<t?-1:1,s=n===i?0:n<i?-1:1;if(!(o===0||s===0)){let a=1/(Math.sqrt(o*o+s*s)||1);o*=a,s*=a}this._direction.x=o,this._direction.y=s}_onTick(){this._speed=this._computeSpeed(this)}_onKeyUp(e){this._moveKeyTimestamps.get(e.key)&&(this._moveKeyTimestamps.delete(e.key),this._updateDirection())}_onKeyDown(e){if(!this.drag){if(this._startKeys.has(e.key)){let t=this._startPredicate(e,this);t&&(e.preventDefault(),this._start({type:"start",x:t.x,y:t.y}))}return}if(this._cancelKeys.has(e.key)){e.preventDefault(),this._internalCancel();return}if(this._endKeys.has(e.key)){e.preventDefault(),this._end({type:"end",x:this.drag.x,y:this.drag.y});return}if(this._moveKeys.has(e.key)){e.preventDefault(),this._moveKeyTimestamps.get(e.key)||(this._moveKeyTimestamps.set(e.key,Date.now()),this._updateDirection());return}}updateSettings(e={}){let t=!1,{cancelOnBlur:n,cancelOnVisibilityChange:i,startPredicate:o,computeSpeed:s}=e;if(n!==void 0&&this._cancelOnBlur!==n&&(this._cancelOnBlur=n,n?this.element?.addEventListener("blur",this._blurCancelHandler):this.element?.removeEventListener("blur",this._blurCancelHandler)),i!==void 0&&this._cancelOnVisibilityChange!==i&&(this._cancelOnVisibilityChange=i,i?document.addEventListener("visibilitychange",this._internalCancel):document.removeEventListener("visibilitychange",this._internalCancel)),o!==void 0&&(this._startPredicate=o),s!==void 0&&(this._computeSpeed=s),ut.forEach((a,c)=>{let l=`${a}Keys`,d=e[l];d!==void 0&&(this[`_${l}`]=new Set(d),c>=3&&(t=!0))}),t){let a=[...this._moveLeftKeys,...this._moveRightKeys,...this._moveUpKeys,...this._moveDownKeys];[...this._moveKeys].every((l,d)=>a[d]===l)||(this._moveKeys=new Set(a),this._moveKeyTimestamps.clear(),this._updateDirection())}}destroy(){this.isDestroyed||(super.destroy(),this.off("tick",this._onTick),document.removeEventListener("keydown",this._onKeyDown),document.removeEventListener("keyup",this._onKeyUp),this._cancelOnBlur&&this.element?.removeEventListener("blur",this._blurCancelHandler),this._cancelOnVisibilityChange&&document.removeEventListener("visibilitychange",this._internalCancel))}};import{Emitter as gt}from"eventti";var te=class{constructor(e,t){this.sensor=e,this.isEnded=!1,this.event=t,this.prevEvent=t,this.startEvent=t,this.endEvent=null,this.items=[]}};import{getOffsetContainer as ze}from"mezr";var Be=new WeakMap;function ne(r){let e=Be.get(r)?.deref();return e||(e=window.getComputedStyle(r,null),Be.set(r,new WeakRef(e))),e}import{getOffset as He}from"mezr";function re(r,e,t={left:0,top:0}){if(t.left=0,t.top=0,r===e)return t;let n=He([r,"padding"]),i=He([e,"padding"]);return t.left=i.left-n.left,t.top=i.top-n.top,t}var mt={left:0,top:0},pt="matrix(1, 0, 0, 1, 0, 0)",ft="matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)",ie=class{constructor(e,t){if(!e.isConnected)throw new Error("Element is not connected");let n=t.drag?.sensor;if(!n)throw new Error("Sensor is not defined");let i=this,o=ne(e),s=e.getBoundingClientRect();this.data={},this.element=e,this.frozenProps=null,this.unfrozenProps=null,this.position={x:0,y:0},this._updateDiff={x:0,y:0},this._moveDiff={x:0,y:0},this._containerDiff={x:0,y:0};let a=e.parentElement;if(!a)throw new Error("Element does not have a parent element.");this.elementContainer=a;let c=ze(e);if(!c)throw new Error("Offset container could not be computed for the element!");this.elementOffsetContainer=c;let l=t.settings.container||a;this.dragContainer=l;let d=l===a?c:ze(e,{container:l});if(!d)throw new Error("Drag offset container could not be computed for the element!");this.dragOffsetContainer=d;{let{width:_,height:p,x:S,y:D}=s;this.clientRect={width:_,height:p,x:S,y:D}}if(c!==d){let{left:_,top:p}=re(d,c,mt);this._containerDiff.x=_,this._containerDiff.y=p}let{transform:u}=o;u&&u!=="none"&&u!==pt&&u!==ft?this.initialTransform=u:this.initialTransform="";let{x:y,y:g}=t.settings.getStartPosition({draggable:t,sensor:n,item:i,style:o});this.position.x=y,this.position.y=g;let E=t.settings.getFrozenProps({draggable:t,sensor:n,item:i,style:o});if(Array.isArray(E))if(E.length){let _={};for(let p of E)_[p]=o[p];this.frozenProps=_}else this.frozenProps=null;else this.frozenProps=E;if(this.frozenProps){let _={};for(let p in this.frozenProps)this.frozenProps.hasOwnProperty(p)&&(_[p]=e.style[p]);this.unfrozenProps=_}}updateSize(e){if(e)this.clientRect.width=e.width,this.clientRect.height=e.height;else{let t=this.element.getBoundingClientRect();this.clientRect.width=t.width,this.clientRect.height=t.height}}};function Se(r,e){let t=document.activeElement,n=r.contains(t);e.append(r),n&&document.activeElement!==t&&t.focus({preventScroll:!0})}var Fe=Z?{capture:!0,passive:!0}:!0,St={left:0,top:0},Ee={x:0,y:0};function Et(){return{container:null,startPredicate:()=>!0,getElements:()=>null,releaseElements:()=>null,getFrozenProps:()=>null,getStartPosition:()=>({x:0,y:0}),setPosition:({item:r,x:e,y:t})=>{r.element.style.transform=`translate(${e}px, ${t}px) ${r.initialTransform}`},getPositionChange:({event:r,prevEvent:e})=>(Ee.x=r.x-e.x,Ee.y=r.y-e.y,Ee)}}var Ge=class{constructor(e,t={}){this.sensors=e,this.settings=this._parseSettings(t),this.plugins={},this.drag=null,this.isDestroyed=!1,this._sensorData=new Map,this._emitter=new gt,this._startPhase=0,this._startId=Symbol(),this._moveId=Symbol(),this._updateId=Symbol(),this._onMove=this._onMove.bind(this),this._onScroll=this._onScroll.bind(this),this._onEnd=this._onEnd.bind(this),this._prepareStart=this._prepareStart.bind(this),this._applyStart=this._applyStart.bind(this),this._prepareMove=this._prepareMove.bind(this),this._applyMove=this._applyMove.bind(this),this._preparePositionUpdate=this._preparePositionUpdate.bind(this),this._applyPositionUpdate=this._applyPositionUpdate.bind(this),this.sensors.forEach(n=>{this._sensorData.set(n,{predicateState:0,predicateEvent:null,onMove:s=>this._onMove(s,n),onEnd:s=>this._onEnd(s,n)});let{onMove:i,onEnd:o}=this._sensorData.get(n);n.on("start",i,i),n.on("move",i,i),n.on("cancel",o,o),n.on("end",o,o),n.on("destroy",o,o)})}_parseSettings(e,t=Et()){let{container:n=t.container,startPredicate:i=t.startPredicate,getElements:o=t.getElements,releaseElements:s=t.releaseElements,getFrozenProps:a=t.getFrozenProps,getStartPosition:c=t.getStartPosition,setPosition:l=t.setPosition,getPositionChange:d=t.getPositionChange}=e||{};return{container:n,startPredicate:i,getElements:o,releaseElements:s,getFrozenProps:a,getStartPosition:c,setPosition:l,getPositionChange:d}}_emit(e,...t){this._emitter.emit(e,...t)}_onMove(e,t){let n=this._sensorData.get(t);if(n)switch(n.predicateState){case 0:{n.predicateEvent=e;let i=this.settings.startPredicate({draggable:this,sensor:t,event:e});i===!0?this.resolveStartPredicate(t):i===!1&&this.rejectStartPredicate(t);break}case 1:{this.drag&&(this.drag.event=e,m.once(v,this._prepareMove,this._moveId),m.once(x,this._applyMove,this._moveId));break}}}_onScroll(){this.updatePosition()}_onEnd(e,t){let n=this._sensorData.get(t);n&&(this.drag?n.predicateState===1&&(this.drag.endEvent=e,this._sensorData.forEach(i=>{i.predicateState=0,i.predicateEvent=null}),this.stop()):(n.predicateState=0,n.predicateEvent=null))}_prepareStart(){let e=this.drag;if(!e)return;this._startPhase=2;let t=this.settings.getElements({draggable:this,sensor:e.sensor,startEvent:e.startEvent})||[];e.items=t.map(n=>new ie(n,this)),this._emit("preparestart",e.startEvent)}_applyStart(){let e=this.drag;if(e){for(let t of e.items)t.dragContainer!==t.elementContainer&&(t.position.x+=t._containerDiff.x,t.position.y+=t._containerDiff.y,Se(t.element,t.dragContainer)),t.frozenProps&&Object.assign(t.element.style,t.frozenProps),this.settings.setPosition({phase:"start",draggable:this,sensor:e.sensor,item:t,x:t.position.x,y:t.position.y});window.addEventListener("scroll",this._onScroll,Fe),this._startPhase=3,this._emit("start",e.startEvent)}}_prepareMove(){let e=this.drag;if(!e)return;let{event:t,prevEvent:n,startEvent:i,sensor:o}=e;if(t!==n){for(let s of e.items){let{x:a,y:c}=this.settings.getPositionChange({draggable:this,sensor:o,item:s,event:t,prevEvent:n,startEvent:i});a&&(s.position.x+=a,s.clientRect.x+=a,s._moveDiff.x+=a),c&&(s.position.y+=c,s.clientRect.y+=c,s._moveDiff.y+=c)}e.prevEvent=t,this._emit("preparemove",t)}}_applyMove(){let e=this.drag;if(e){for(let t of e.items)t._moveDiff.x=0,t._moveDiff.y=0,this.settings.setPosition({phase:"move",draggable:this,sensor:e.sensor,item:t,x:t.position.x,y:t.position.y});e.event&&this._emit("move",e.event)}}_preparePositionUpdate(){let{drag:e}=this;if(e)for(let t of e.items){if(t.elementOffsetContainer!==t.dragOffsetContainer){let{left:l,top:d}=re(t.dragOffsetContainer,t.elementOffsetContainer,St);t._containerDiff.x=l,t._containerDiff.y=d}let{left:n,top:i,width:o,height:s}=t.element.getBoundingClientRect(),a=t.clientRect.x-t._moveDiff.x-n;t.position.x=t.position.x-t._updateDiff.x+a,t._updateDiff.x=a;let c=t.clientRect.y-t._moveDiff.y-i;t.position.y=t.position.y-t._updateDiff.y+c,t._updateDiff.y=c,t.clientRect.width=o,t.clientRect.height=s}}_applyPositionUpdate(){let{drag:e}=this;if(e)for(let t of e.items)t._updateDiff.x=0,t._updateDiff.y=0,this.settings.setPosition({phase:"move",draggable:this,sensor:e.sensor,item:t,x:t.position.x,y:t.position.y})}on(e,t,n){return this._emitter.on(e,t,n)}off(e,t){this._emitter.off(e,t)}resolveStartPredicate(e,t){let n=this._sensorData.get(e);if(!n)return;let i=t||n.predicateEvent;n.predicateState===0&&i&&(this._startPhase=1,n.predicateState=1,n.predicateEvent=null,this.drag=new te(e,i),this._sensorData.forEach((o,s)=>{s!==e&&(o.predicateState=2,o.predicateEvent=null)}),m.once(v,this._prepareStart,this._startId),m.once(x,this._applyStart,this._startId))}rejectStartPredicate(e){let t=this._sensorData.get(e);t?.predicateState===0&&(t.predicateState=2,t.predicateEvent=null)}stop(){let e=this.drag;if(!e||e.isEnded)return;if(this._startPhase===2){this.off("start",this._startId),this.on("start",()=>this.stop(),this._startId);return}this._startPhase=0,e.isEnded=!0,m.off(v,this._startId),m.off(x,this._startId),m.off(v,this._moveId),m.off(x,this._moveId),m.off(v,this._updateId),m.off(x,this._updateId),window.removeEventListener("scroll",this._onScroll,Fe);let t=[];for(let n of e.items){if(t.push(n.element),n.elementContainer!==n.dragContainer&&(n.position.x-=n._containerDiff.x,n.position.y-=n._containerDiff.y,n._containerDiff.x=0,n._containerDiff.y=0,Se(n.element,n.elementContainer)),n.unfrozenProps)for(let i in n.unfrozenProps)n.element.style[i]=n.unfrozenProps[i]||"";this.settings.setPosition({phase:"end",draggable:this,sensor:e.sensor,item:n,x:n.position.x,y:n.position.y})}t.length&&this.settings.releaseElements({draggable:this,sensor:e.sensor,elements:t}),this._emit("end",e.endEvent),this.drag=null}updatePosition(e=!1){this.drag&&(e?(this._preparePositionUpdate(),this._applyPositionUpdate()):(m.once(v,this._preparePositionUpdate,this._updateId),m.once(x,this._applyPositionUpdate,this._updateId)))}updateSettings(e={}){this.settings=this._parseSettings(e,this.settings)}use(e){return e(this)}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.stop(),this._sensorData.forEach(({onMove:e,onEnd:t},n)=>{n.off("start",e),n.off("move",e),n.off("cancel",t),n.off("end",t),n.off("destroy",t)}),this._sensorData.clear(),this._emit("destroy"),this._emitter.off())}};import{Emitter as xt}from"eventti";var z=class{constructor(e,t){this._data=[],this._createObject=e,this._onPut=t}pick(){return this._data.length?this._data.pop():this._createObject()}put(e){this._data.indexOf(e)===-1&&(this._onPut&&this._onPut(e),this._data.push(e))}reset(){this._data.length=0}};import{getDistance as vt}from"mezr";function F(r,e={width:0,height:0,x:0,y:0,left:0,top:0,right:0,bottom:0}){return r&&(e.width=r.width,e.height=r.height,e.x=r.x,e.y=r.y,e.left=r.x,e.top=r.y,e.right=r.x+r.width,e.bottom=r.y+r.height),e}var _t=F(),yt=F();function je(r,e){return vt(F(r,_t),F(e,yt))}function $e(r,e,t={width:0,height:0,x:0,y:0}){let n=Math.max(r.x,e.x),i=Math.min(r.x+r.width,e.x+e.width);if(i<=n)return null;let o=Math.max(r.y,e.y),s=Math.min(r.y+r.height,e.y+e.height);return s<=o?null:(t.x=n,t.y=o,t.width=i-n,t.height=s-o,t)}function Je(r,e){let t=$e(r,e);return t?t.width*t.height:0}function ve(r,e){let t=Je(r,e);if(!t)return 0;let n=Math.min(r.width,e.width)*Math.min(r.height,e.height);return t/n*100}import{getRect as bt}from"mezr";function _e(...r){let{width:e,height:t,left:n,top:i}=bt(...r);return{width:e,height:t,x:n,y:i}}function w(r){return r instanceof Window}function ye(r){return w(r)||r===document.documentElement||r===document.body?window:r}function X(r){return w(r)?r.pageXOffset:r.scrollLeft}function be(r){return w(r)&&(r=document.documentElement),r.scrollWidth-r.clientWidth}function Y(r){return w(r)?r.pageYOffset:r.scrollTop}function xe(r){return w(r)&&(r=document.documentElement),r.scrollHeight-r.clientHeight}function De(r,e){return!(r.x+r.width<=e.x||e.x+e.width<=r.x||r.y+r.height<=e.y||e.y+e.height<=r.y)}var Qe={width:0,height:0,x:0,y:0},Ze=50,A={direction:"none",threshold:0,distance:0,value:0,maxValue:0,duration:0,speed:0,deltaTime:0,isEnding:!1},h={x:1,y:2},M={forward:4,reverse:8},oe={none:0,left:h.x|M.reverse,right:h.x|M.forward},G={none:0,up:h.y|M.reverse,down:h.y|M.forward},f={...oe,...G};function Pe(r){switch(r){case oe.none:case G.none:return"none";case oe.left:return"left";case oe.right:return"right";case G.up:return"up";case G.down:return"down";default:throw new Error(`Unknown direction value: ${r}`)}}function et(r,e,t){let{left:n=0,right:i=0,top:o=0,bottom:s=0}=e;return n=Math.max(0,n),i=Math.max(0,i),o=Math.max(0,o),s=Math.max(0,s),t.width=r.width+n+i,t.height=r.height+o+s,t.x=r.x-n,t.y=r.y-o,t}function se(r,e){return Math.ceil(r)>=Math.floor(e)}function Te(r,e){return Math.min(e/2,r)}function Ie(r,e,t,n){return Math.max(0,t+r*2+n*e-n)/2}var we=class{constructor(){this.positionX=0,this.positionY=0,this.directionX=f.none,this.directionY=f.none,this.overlapCheckRequestTime=0}},Ae=class{constructor(){this.element=null,this.requestX=null,this.requestY=null,this.scrollLeft=0,this.scrollTop=0}reset(){this.requestX&&(this.requestX.action=null),this.requestY&&(this.requestY.action=null),this.element=null,this.requestX=null,this.requestY=null,this.scrollLeft=0,this.scrollTop=0}addRequest(e){h.x&e.direction?(this.requestX&&this.removeRequest(this.requestX),this.requestX=e):(this.requestY&&this.removeRequest(this.requestY),this.requestY=e),e.action=this}removeRequest(e){this.requestX===e?(this.requestX=null,e.action=null):this.requestY===e&&(this.requestY=null,e.action=null)}computeScrollValues(){this.element&&(this.scrollLeft=this.requestX?this.requestX.value:X(this.element),this.scrollTop=this.requestY?this.requestY.value:Y(this.element))}scroll(){this.element&&(this.element.scrollTo?this.element.scrollTo(this.scrollLeft,this.scrollTop):(this.element.scrollLeft=this.scrollLeft,this.element.scrollTop=this.scrollTop))}},Ce=class{constructor(){this.item=null,this.element=null,this.isActive=!1,this.isEnding=!1,this.direction=0,this.value=NaN,this.maxValue=0,this.threshold=0,this.distance=0,this.deltaTime=0,this.speed=0,this.duration=0,this.action=null}reset(){this.isActive&&this.onStop(),this.item=null,this.element=null,this.isActive=!1,this.isEnding=!1,this.direction=0,this.value=NaN,this.maxValue=0,this.threshold=0,this.distance=0,this.deltaTime=0,this.speed=0,this.duration=0,this.action=null}hasReachedEnd(){return M.forward&this.direction?se(this.value,this.maxValue):this.value<=0}computeCurrentScrollValue(){return this.element?this.value!==this.value?h.x&this.direction?X(this.element):Y(this.element):Math.max(0,Math.min(this.value,this.maxValue)):0}computeNextScrollValue(){let e=this.speed*(this.deltaTime/1e3),t=M.forward&this.direction?this.value+e:this.value-e;return Math.max(0,Math.min(t,this.maxValue))}computeSpeed(){if(!this.item||!this.element)return 0;let{speed:e}=this.item;return typeof e=="function"?(A.direction=Pe(this.direction),A.threshold=this.threshold,A.distance=this.distance,A.value=this.value,A.maxValue=this.maxValue,A.duration=this.duration,A.speed=this.speed,A.deltaTime=this.deltaTime,A.isEnding=this.isEnding,e(this.element,A)):e}tick(e){return this.isActive||(this.isActive=!0,this.onStart()),this.deltaTime=e,this.value=this.computeCurrentScrollValue(),this.speed=this.computeSpeed(),this.value=this.computeNextScrollValue(),this.duration+=e,this.value}onStart(){if(!this.item||!this.element)return;let{onStart:e}=this.item;typeof e=="function"&&e(this.element,Pe(this.direction))}onStop(){if(!this.item||!this.element)return;let{onStop:e}=this.item;typeof e=="function"&&e(this.element,Pe(this.direction))}};function tt(r=500,e=.5,t=.25){let n=r*(e>0?1/e:1/0),i=r*(t>0?1/t:1/0);return function(o,s){let a=0;if(!s.isEnding)if(s.threshold>0){let d=s.threshold-Math.max(0,s.distance);a=r/s.threshold*d}else a=r;let c=s.speed;if(c===a)return a;let l=a;return c<a?(l=c+n*(s.deltaTime/1e3),Math.min(a,l)):(l=c-i*(s.deltaTime/1e3),Math.max(a,l))}}var ae=class{constructor(e={}){let{overlapCheckInterval:t=150}=e;this.items=[],this.settings={overlapCheckInterval:t},this._actions=[],this._isDestroyed=!1,this._isTicking=!1,this._tickTime=0,this._tickDeltaTime=0,this._requests={[h.x]:new Map,[h.y]:new Map},this._itemData=new Map,this._requestPool=new z(()=>new Ce,n=>n.reset()),this._actionPool=new z(()=>new Ae,n=>n.reset()),this._emitter=new xt,this._frameRead=this._frameRead.bind(this),this._frameWrite=this._frameWrite.bind(this)}_frameRead(e){this._isDestroyed||(e&&this._tickTime?(this._tickDeltaTime=e-this._tickTime,this._tickTime=e,this._updateItems(),this._updateRequests(),this._updateActions()):(this._tickTime=e,this._tickDeltaTime=0))}_frameWrite(){this._isDestroyed||this._applyActions()}_startTicking(){this._isTicking||(this._isTicking=!0,m.on(v,this._frameRead,this._frameRead),m.on(x,this._frameWrite,this._frameWrite))}_stopTicking(){this._isTicking&&(this._isTicking=!1,this._tickTime=0,this._tickDeltaTime=0,m.off(v,this._frameRead),m.off(x,this._frameWrite))}_requestItemScroll(e,t,n,i,o,s,a){let c=this._requests[t],l=c.get(e);l?(l.element!==n||l.direction!==i)&&l.reset():(l=this._requestPool.pick(),c.set(e,l)),l.item=e,l.element=n,l.direction=i,l.threshold=o,l.distance=s,l.maxValue=a}_cancelItemScroll(e,t){let n=this._requests[t],i=n.get(e);i&&(i.action&&i.action.removeRequest(i),this._requestPool.put(i),n.delete(e))}_checkItemOverlap(e,t,n){let{inertAreaSize:i,targets:o,clientRect:s}=e;if(!o.length){t&&this._cancelItemScroll(e,h.x),n&&this._cancelItemScroll(e,h.y);return}let a=this._itemData.get(e),c=a?.directionX,l=a?.directionY;if(!c&&!l){t&&this._cancelItemScroll(e,h.x),n&&this._cancelItemScroll(e,h.y);return}let d=null,u=-1/0,y=0,g=-1/0,E=f.none,_=0,p=0,S=null,D=-1/0,U=0,B=-1/0,ce=f.none,Ke=0,Me=0,de=0;for(;de<o.length;de++){let C=o[de],We=typeof C.threshold=="number"?C.threshold:Ze,he=!!(t&&c&&C.axis!=="y"),ue=!!(n&&l&&C.axis!=="x"),R=C.priority||0;if((!he||R<u)&&(!ue||R<D))continue;let O=ye(C.element||C),$=he?be(O):-1,J=ue?xe(O):-1;if($<=0&&J<=0)continue;let P=_e([O,"padding"],window),W=ve(s,P)||-1/0;if(W===-1/0)if(C.padding&&De(s,et(P,C.padding,Qe)))W=-(je(s,P)||0);else continue;if(he&&R>=u&&$>0&&(R>u||W>g)){let T=0,k=f.none,L=Te(We,P.width),H=Ie(L,i,s.width,P.width);c===f.right?(T=P.x+P.width+H-(s.x+s.width),T<=L&&!se(X(O),$)&&(k=f.right)):c===f.left&&(T=s.x-(P.x-H),T<=L&&X(O)>0&&(k=f.left)),k&&(d=O,u=R,y=L,g=W,E=k,_=T,p=$)}if(ue&&R>=D&&J>0&&(R>D||W>B)){let T=0,k=G.none,L=Te(We,P.height),H=Ie(L,i,s.height,P.height);l===f.down?(T=P.y+P.height+H-(s.y+s.height),T<=L&&!se(Y(O),J)&&(k=f.down)):l===f.up&&(T=s.y-(P.y-H),T<=L&&Y(O)>0&&(k=f.up)),k&&(S=O,D=R,U=L,B=W,ce=k,Ke=T,Me=J)}}t&&(d&&E?this._requestItemScroll(e,h.x,d,E,y,_,p):this._cancelItemScroll(e,h.x)),n&&(S&&ce?this._requestItemScroll(e,h.y,S,ce,U,Ke,Me):this._cancelItemScroll(e,h.y))}_updateScrollRequest(e){let t=e.item,{inertAreaSize:n,smoothStop:i,targets:o,clientRect:s}=t,a=null,c=0;for(;c<o.length;c++){let l=o[c],d=ye(l.element||l);if(d!==e.element)continue;let u=!!(h.x&e.direction);if(u){if(l.axis==="y")continue}else if(l.axis==="x")continue;let y=u?be(d):xe(d);if(y<=0)break;let g=_e([d,"padding"],window);if((ve(s,g)||-1/0)===-1/0){let B=l.scrollPadding||l.padding;if(!(B&&De(s,et(g,B,Qe))))break}let _=typeof l.threshold=="number"?l.threshold:Ze,p=Te(_,u?g.width:g.height),S=Ie(p,n,u?s.width:s.height,u?g.width:g.height),D=0;if(e.direction===f.left?D=s.x-(g.x-S):e.direction===f.right?D=g.x+g.width+S-(s.x+s.width):e.direction===f.up?D=s.y-(g.y-S):D=g.y+g.height+S-(s.y+s.height),D>p)break;let U=u?X(d):Y(d);if(a=M.forward&e.direction?se(U,y):U<=0,a)break;return e.maxValue=y,e.threshold=p,e.distance=D,e.isEnding=!1,!0}return i===!0&&e.speed>0?(a===null&&(a=e.hasReachedEnd()),e.isEnding=!a):e.isEnding=!1,e.isEnding}_updateItems(){for(let e=0;e<this.items.length;e++){let t=this.items[e],n=this._itemData.get(t),{x:i,y:o}=t.position,s=n.positionX,a=n.positionY;i===s&&o===a||(n.directionX=i>s?f.right:i<s?f.left:n.directionX,n.directionY=o>a?f.down:o<a?f.up:n.directionY,n.positionX=i,n.positionY=o,n.overlapCheckRequestTime===0&&(n.overlapCheckRequestTime=this._tickTime))}}_updateRequests(){let e=this.items,t=this._requests[h.x],n=this._requests[h.y],i=0;for(;i<e.length;i++){let o=e[i],s=this._itemData.get(o),a=s.overlapCheckRequestTime,c=a>0&&this._tickTime-a>this.settings.overlapCheckInterval,l=!0,d=t.get(o);d&&d.isActive&&(l=!this._updateScrollRequest(d),l&&(c=!0,this._cancelItemScroll(o,h.x)));let u=!0,y=n.get(o);y&&y.isActive&&(u=!this._updateScrollRequest(y),u&&(c=!0,this._cancelItemScroll(o,h.y))),c&&(s.overlapCheckRequestTime=0,this._checkItemOverlap(o,l,u))}}_requestAction(e,t){let n=t===h.x,i=null,o=0;for(;o<this._actions.length;o++){if(i=this._actions[o],e.element!==i.element){i=null;continue}if(n?i.requestX:i.requestY){this._cancelItemScroll(e.item,t);return}break}i||(i=this._actionPool.pick()),i.element=e.element,i.addRequest(e),e.tick(this._tickDeltaTime),this._actions.push(i)}_updateActions(){let e=0;for(e=0;e<this.items.length;e++){let t=this.items[e],n=this._requests[h.x].get(t),i=this._requests[h.y].get(t);n&&this._requestAction(n,h.x),i&&this._requestAction(i,h.y)}for(e=0;e<this._actions.length;e++)this._actions[e].computeScrollValues()}_applyActions(){if(!this._actions.length)return;this._emitter.emit("beforescroll");let e=0;for(e=0;e<this._actions.length;e++)this._actions[e].scroll(),this._actionPool.put(this._actions[e]);this._actions.length=0;let t;for(e=0;e<this.items.length;e++)t=this.items[e],t.onPrepareScrollEffect&&t.onPrepareScrollEffect();for(e=0;e<this.items.length;e++)t=this.items[e],t.onApplyScrollEffect&&t.onApplyScrollEffect();this._emitter.emit("afterscroll")}on(e,t,n){return this._emitter.on(e,t,n)}off(e,t){this._emitter.off(e,t)}addItem(e){if(this._isDestroyed||this._itemData.has(e))return;let{x:t,y:n}=e.position,i=new we;i.positionX=t,i.positionY=n,i.directionX=f.none,i.directionY=f.none,i.overlapCheckRequestTime=this._tickTime,this._itemData.set(e,i),this.items.push(e),this._isTicking||this._startTicking()}removeItem(e){if(this._isDestroyed)return;let t=this.items.indexOf(e);t!==-1&&(this._requests[h.x].get(e)&&(this._cancelItemScroll(e,h.x),this._requests[h.x].delete(e)),this._requests[h.y].get(e)&&(this._cancelItemScroll(e,h.y),this._requests[h.y].delete(e)),this._itemData.delete(e),this.items.splice(t,1),this._isTicking&&!this.items.length&&this._stopTicking())}isDestroyed(){return this._isDestroyed}isItemScrollingX(e){return!!this._requests[h.x].get(e)?.isActive}isItemScrollingY(e){return!!this._requests[h.y].get(e)?.isActive}isItemScrolling(e){return this.isItemScrollingX(e)||this.isItemScrollingY(e)}updateSettings(e={}){let{overlapCheckInterval:t=this.settings.overlapCheckInterval}=e;this.settings.overlapCheckInterval=t}destroy(){if(this._isDestroyed)return;let e=this.items.slice(0),t=0;for(;t<e.length;t++)this.removeItem(e[t]);this._actions.length=0,this._requestPool.reset(),this._actionPool.reset(),this._emitter.off(),this._isDestroyed=!0}};var Oe=new ae;var ke={x:0,y:0},j={width:0,height:0,x:0,y:0};function Dt(){return{targets:[],inertAreaSize:.2,speed:tt(),smoothStop:!1,getPosition:r=>{let{drag:e}=r,t=e?.items[0];if(t)return t.position;let n=e&&(e.event||e.startEvent);return ke.x=n?n.x:0,ke.y=n?n.y:0,ke},getClientRect:r=>{let{drag:e}=r,t=e?.items[0];if(t&&t.element)return t.clientRect;let n=e&&(e.event||e.startEvent);return j.width=n?50:0,j.height=n?50:0,j.x=n?n.x-25:0,j.y=n?n.y-25:0,j},onStart:null,onStop:null}}var Le=class{constructor(e,t){this._draggableAutoScroll=e,this._draggable=t,this._position={x:0,y:0},this._clientRect={width:0,height:0,x:0,y:0}}_getSettings(){return this._draggableAutoScroll.settings}get targets(){let{targets:e}=this._getSettings();return typeof e=="function"&&(e=e(this._draggable)),e}get position(){let e=this._position,{getPosition:t}=this._getSettings();return typeof t=="function"?Object.assign(e,t(this._draggable)):(e.x=0,e.y=0),e}get clientRect(){let e=this._clientRect,{getClientRect:t}=this._getSettings();return typeof t=="function"?Object.assign(e,t(this._draggable)):(e.width=0,e.height=0,e.x=0,e.y=0),e}get inertAreaSize(){return this._getSettings().inertAreaSize}get smoothStop(){return this._getSettings().smoothStop}get speed(){return this._getSettings().speed}get onStart(){return this._getSettings().onStart}get onStop(){return this._getSettings().onStop}onPrepareScrollEffect(){let e=this._draggable._updateId;m.off(v,e),m.off(x,e),this._draggable._preparePositionUpdate()}onApplyScrollEffect(){this._draggable._applyPositionUpdate()}},Re=class{constructor(e,t={}){this.name="autoscroll",this.version="0.0.3",this.settings=this._parseSettings(t),this._autoScrollProxy=null,e.on("start",()=>{this._autoScrollProxy||(this._autoScrollProxy=new Le(this,e),Oe.addItem(this._autoScrollProxy))}),e.on("end",()=>{this._autoScrollProxy&&(Oe.removeItem(this._autoScrollProxy),this._autoScrollProxy=null)})}_parseSettings(e,t=Dt()){let{targets:n=t.targets,inertAreaSize:i=t.inertAreaSize,speed:o=t.speed,smoothStop:s=t.smoothStop,getPosition:a=t.getPosition,getClientRect:c=t.getClientRect,onStart:l=t.onStart,onStop:d=t.onStop}=e||{};return{targets:n,inertAreaSize:i,speed:o,smoothStop:s,getPosition:a,getClientRect:c,onStart:l,onStop:d}}updateSettings(e={}){this.settings=this._parseSettings(e,this.settings)}};function kr(r){return e=>{let t=new Re(e,r),n=e;return n.plugins[t.name]=t,n}}var nt=new Set(["auto","scroll","overlay"]);function le(r){let e=ne(r);return!!(nt.has(e.overflowY)||nt.has(e.overflowX))}function rt(r){return r instanceof Document}function it(r,e=[]){let t=r?.parentNode;for(;t&&!rt(t);)t instanceof Element?(le(t)&&e.push(t),t=t.parentNode):t instanceof ShadowRoot?t=t.host:t=t.parentNode;return e.push(window),e}function Pt(r){let e=[];return le(r)&&e.push(r),it(r,e),e}function Br(r={}){let e,t=0,n=null,i,{timeout:o=250,fallback:s=()=>!0}=r,a=d=>d.preventDefault(),c=d=>{if(t){if(e){d.cancelable&&d.preventDefault();return}e===void 0&&(d.cancelable&&d.timeStamp-t>o?(e=!0,d.preventDefault()):e=!1)}};return d=>{if(!(d.sensor instanceof q))return s(d);let{draggable:u,sensor:y,event:g}=d,E=g;if(E.pointerType==="touch"){if(E.type==="start"&&(E.srcEvent.type==="pointerdown"||E.srcEvent.type==="touchstart")){n=E.target;let _=n?Pt(n):[];_.forEach(S=>{S.addEventListener("touchmove",c,{passive:!1,capture:!0})});let p=()=>{t&&(u.off("end",p),u.sensors.forEach(S=>{S instanceof q&&S.off("end",p)}),n?.removeEventListener("contextmenu",a),_.forEach(S=>{S.removeEventListener("touchmove",c,{capture:!0})}),t=0,e=void 0,n=null,i=void window.clearTimeout(i))};e=void 0,t=E.srcEvent.timeStamp,n?.addEventListener("contextmenu",a),u.on("end",p),u.sensors.forEach(S=>{S instanceof q&&S.off("end",p)}),o>0&&(i=window.setTimeout(()=>{u.resolveStartPredicate(y),e=!0,i=void 0},o))}return e}return E.type==="start"&&!E.srcEvent.button}}function Tt(r,e){return Math.round(r/e)*e}function ot(r,e,t){let n=t-e,i=Math.abs(n);if(i>=r){let o=i%r;return Tt(n>0?n-o:n+o,r)}return 0}function zr(r,e){return function({item:n,event:i,startEvent:o}){let{__snapX__:s=o.x,__snapY__:a=o.y}=n.data,c=ot(r,s,i.x),l=ot(e,a,i.y);return c&&(n.data.__snapX__=s+c),l&&(n.data.__snapY__=a+l),{x:c,y:l}}}export{h as AUTO_SCROLL_AXIS,M as AUTO_SCROLL_AXIS_DIRECTION,f as AUTO_SCROLL_DIRECTION,ae as AutoScroll,Q as BaseMotionSensor,V as BaseSensor,Ge as Draggable,Re as DraggableAutoScroll,Ue as KeyboardMotionSensor,Ye as KeyboardSensor,q as PointerSensor,b as SensorEventType,Oe as autoScroll,kr as autoScrollPlugin,tt as autoScrollSmoothSpeed,Br as createPointerSensorStartPredicate,zr as createSnapModifier,I as keyboardMotionSensorDefaults,K as keyboardSensorDefaults,Vt as setTicker,m as ticker,v as tickerReadPhase,x as tickerWritePhase};
{
"name": "dragdoll",
"version": "0.3.0",
"version": "0.4.0",
"description": "Modular and extensible drag & drop system.",

@@ -75,3 +75,3 @@ "keywords": [

"mezr": "1.1.0",
"mocha": "10.3.0",
"mocha": "10.4.0",
"parcel": "2.12.0",

@@ -82,5 +82,5 @@ "prettier": "3.2.5",

"tsup": "8.0.2",
"typescript": "5.4.3",
"vitepress": "1.0.1",
"vue": "3.4.21"
"typescript": "5.4.5",
"vitepress": "1.1.3",
"vue": "3.4.25"
},

@@ -87,0 +87,0 @@ "peerDependencies": {

@@ -37,2 +37,2 @@ <h1 align="center">

Copyright © 2022, Niklas Rämö (inramo@gmail.com). Licensed under the MIT license.
Copyright © 2022-2024, Niklas Rämö (inramo@gmail.com). Licensed under the MIT license.
import { Emitter, EventListenerId } from 'eventti';
import { getDistance, getRect } from 'mezr';
import { Point, Rect } from '../types.js';
import { Point, Rect, RectExtended } from '../types.js';
import { Pool } from '../pool.js';

@@ -11,4 +9,8 @@

import { getDistance } from '../utils/get-distance.js';
import { getIntersectionScore } from '../utils/get-intersection-score.js';
import { getRect } from '../utils/get-rect.js';
import { getScrollElement } from '../utils/get-scroll-element.js';

@@ -30,13 +32,9 @@

const R1: RectExtended = {
const TEMP_RECT: Rect = {
width: 0,
height: 0,
left: 0,
right: 0,
top: 0,
bottom: 0,
x: 0,
y: 0,
};
const R2: RectExtended = { ...R1 };
const DEFAULT_THRESHOLD = 50;

@@ -101,3 +99,3 @@

function getPaddedRect(rect: RectExtended, padding: AutoScrollTargetPadding, result: RectExtended) {
function getPaddedRect(rect: Rect, padding: AutoScrollTargetPadding, result: Rect) {
let { left = 0, right = 0, top = 0, bottom = 0 } = padding;

@@ -113,6 +111,4 @@

result.height = rect.height + top + bottom;
result.left = rect.left - left;
result.top = rect.top - top;
result.right = rect.right + right;
result.bottom = rect.bottom + bottom;
result.x = rect.x - left;
result.y = rect.y - top;

@@ -561,16 +557,2 @@ return result;

protected _getItemClientRect(
item: AutoScrollItem,
result: RectExtended = { width: 0, height: 0, left: 0, right: 0, top: 0, bottom: 0 },
) {
const { clientRect } = item;
result.left = clientRect.left;
result.top = clientRect.top;
result.width = clientRect.width;
result.height = clientRect.height;
result.right = clientRect.left + clientRect.width;
result.bottom = clientRect.top + clientRect.height;
return result;
}
protected _requestItemScroll(

@@ -616,3 +598,3 @@ item: AutoScrollItem,

protected _checkItemOverlap(item: AutoScrollItem, checkX: boolean, checkY: boolean) {
const { inertAreaSize, targets } = item;
const { inertAreaSize, targets, clientRect } = item;
if (!targets.length) {

@@ -633,4 +615,2 @@ checkX && this._cancelItemScroll(item, AUTO_SCROLL_AXIS.x);

const itemRect = this._getItemClientRect(item, R1);
let xElement: Window | Element | null = null;

@@ -675,3 +655,3 @@ let xPriority = -Infinity;

const testRect = getRect([testElement, 'padding'], window);
let testScore = getIntersectionScore(itemRect, testRect) || -Infinity;
let testScore = getIntersectionScore(clientRect, testRect) || -Infinity;

@@ -685,5 +665,5 @@ // If the item has no overlap with the target.

target.padding &&
isIntersecting(itemRect, getPaddedRect(testRect, target.padding, R2))
isIntersecting(clientRect, getPaddedRect(testRect, target.padding, TEMP_RECT))
) {
testScore = -(getDistance(itemRect, testRect) || 0);
testScore = -(getDistance(clientRect, testRect) || 0);
}

@@ -709,3 +689,3 @@ // Otherwise let's ignore this target.

inertAreaSize,
itemRect.width,
clientRect.width,
testRect.width,

@@ -715,3 +695,4 @@ );

if (moveDirectionX === AUTO_SCROLL_DIRECTION.right) {
testDistance = testRect.right + testEdgeOffset - itemRect.right;
testDistance =
testRect.x + testRect.width + testEdgeOffset - (clientRect.x + clientRect.width);
if (

@@ -724,3 +705,3 @@ testDistance <= testThreshold &&

} else if (moveDirectionX === AUTO_SCROLL_DIRECTION.left) {
testDistance = itemRect.left - (testRect.left - testEdgeOffset);
testDistance = clientRect.x - (testRect.x - testEdgeOffset);
if (testDistance <= testThreshold && getScrollLeft(testElement) > 0) {

@@ -755,3 +736,3 @@ testDirection = AUTO_SCROLL_DIRECTION.left;

inertAreaSize,
itemRect.height,
clientRect.height,
testRect.height,

@@ -761,3 +742,4 @@ );

if (moveDirectionY === AUTO_SCROLL_DIRECTION.down) {
testDistance = testRect.bottom + testEdgeOffset - itemRect.bottom;
testDistance =
testRect.y + testRect.height + testEdgeOffset - (clientRect.y + clientRect.height);
if (

@@ -770,3 +752,3 @@ testDistance <= testThreshold &&

} else if (moveDirectionY === AUTO_SCROLL_DIRECTION.up) {
testDistance = itemRect.top - (testRect.top - testEdgeOffset);
testDistance = clientRect.y - (testRect.y - testEdgeOffset);
if (testDistance <= testThreshold && getScrollTop(testElement) > 0) {

@@ -826,4 +808,3 @@ testDirection = AUTO_SCROLL_DIRECTION.up;

const item = scrollRequest.item!;
const { inertAreaSize, smoothStop, targets } = item;
const itemRect = this._getItemClientRect(item, R1);
const { inertAreaSize, smoothStop, targets, clientRect } = item;
let hasReachedEnd = null;

@@ -856,3 +837,3 @@

const testRect = getRect([testElement, 'padding'], window);
const testScore = getIntersectionScore(itemRect, testRect) || -Infinity;
const testScore = getIntersectionScore(clientRect, testRect) || -Infinity;

@@ -863,3 +844,3 @@ // If the item has no overlap with the target nor the padded target rect

const padding = target.scrollPadding || target.padding;
if (!(padding && isIntersecting(itemRect, getPaddedRect(testRect, padding, R2)))) {
if (!(padding && isIntersecting(clientRect, getPaddedRect(testRect, padding, TEMP_RECT)))) {
break;

@@ -881,3 +862,3 @@ }

inertAreaSize,
testIsAxisX ? itemRect.width : itemRect.height,
testIsAxisX ? clientRect.width : clientRect.height,
testIsAxisX ? testRect.width : testRect.height,

@@ -889,9 +870,11 @@ );

if (scrollRequest.direction === AUTO_SCROLL_DIRECTION.left) {
testDistance = itemRect.left - (testRect.left - testEdgeOffset);
testDistance = clientRect.x - (testRect.x - testEdgeOffset);
} else if (scrollRequest.direction === AUTO_SCROLL_DIRECTION.right) {
testDistance = testRect.right + testEdgeOffset - itemRect.right;
testDistance =
testRect.x + testRect.width + testEdgeOffset - (clientRect.x + clientRect.width);
} else if (scrollRequest.direction === AUTO_SCROLL_DIRECTION.up) {
testDistance = itemRect.top - (testRect.top - testEdgeOffset);
testDistance = clientRect.y - (testRect.y - testEdgeOffset);
} else {
testDistance = testRect.bottom + testEdgeOffset - itemRect.bottom;
testDistance =
testRect.y + testRect.height + testEdgeOffset - (clientRect.y + clientRect.height);
}

@@ -898,0 +881,0 @@

@@ -94,4 +94,4 @@ import { getOffsetContainer } from 'mezr';

{
const { left, top, width, height } = clientRect;
this.clientRect = { left, top, width, height };
const { width, height, x, y } = clientRect;
this.clientRect = { width, height, x, y };
}

@@ -98,0 +98,0 @@

@@ -13,2 +13,4 @@ import { HAS_PASSIVE_EVENTS } from '../constants.js';

import { appendElement } from 'utils/append-element.js';
import { getOffsetDiff } from '../utils/get-offset-diff.js';

@@ -24,2 +26,9 @@

enum DragStartPhase {
NONE = 0,
INIT = 1,
START_PREPARE = 2,
FINISH_APPLY = 3,
}
enum DraggableStartPredicateState {

@@ -140,2 +149,3 @@ PENDING = 0,

}>;
protected _startPhase: DragStartPhase;
protected _startId: symbol;

@@ -154,2 +164,3 @@ protected _moveId: symbol;

this._emitter = new Emitter();
this._startPhase = DragStartPhase.NONE;
this._startId = Symbol();

@@ -288,2 +299,5 @@ this._moveId = Symbol();

// Update start phase.
this._startPhase = DragStartPhase.START_PREPARE;
// Get elements that we'll need to move with the drag.

@@ -312,9 +326,8 @@ // NB: It is okay if there are no elements and thus no items. The drag

const { container } = this.settings;
for (const item of drag.items as Writeable<DraggableDragItem<S, E>>[]) {
// Append element within the container element if such is provided.
if (container && item.element.parentElement !== container) {
container.appendChild(item.element);
if (item.dragContainer !== item.elementContainer) {
item.position.x += item._containerDiff.x;
item.position.y += item._containerDiff.y;
appendElement(item.element, item.dragContainer);
}

@@ -341,2 +354,5 @@

// Update start phase.
this._startPhase = DragStartPhase.FINISH_APPLY;
// Emit start event.

@@ -369,3 +385,3 @@ this._emit('start', drag.startEvent);

item.position.x += changeX;
item.clientRect.left += changeX;
item.clientRect.x += changeX;
item._moveDiff.x += changeX;

@@ -377,3 +393,3 @@ }

item.position.y += changeY;
item.clientRect.top += changeY;
item.clientRect.y += changeY;
item._moveDiff.y += changeY;

@@ -434,3 +450,3 @@ }

// Update horizontal position data.
const updateDiffX = item.clientRect.left - item._moveDiff.x - left;
const updateDiffX = item.clientRect.x - item._moveDiff.x - left;
item.position.x = item.position.x - item._updateDiff.x + updateDiffX;

@@ -440,3 +456,3 @@ item._updateDiff.x = updateDiffX;

// Update vertical position data.
const updateDiffY = item.clientRect.top - item._moveDiff.y - top;
const updateDiffY = item.clientRect.y - item._moveDiff.y - top;
item.position.y = item.position.y - item._updateDiff.y + updateDiffY;

@@ -492,2 +508,5 @@ item._updateDiff.y = updateDiffY;

if (sensorData.predicateState === DraggableStartPredicateState.PENDING && startEvent) {
// Update start phase.
this._startPhase = DragStartPhase.INIT;
// Resolve the provided sensor's start predicate.

@@ -524,2 +543,16 @@ sensorData.predicateState = DraggableStartPredicateState.RESOLVED;

// If drag start process is still in the prepare and apply phase, let's
// wait for it to finish before stopping the drag process. This is a very
// rare edge case, but it can happen if the drag process is stopped
// forcefully during the start phase.
// NB: We reuse the `_startId` symbol to queue the stop procedure.
if (this._startPhase === DragStartPhase.START_PREPARE) {
this.off('start', this._startId);
this.on('start', () => this.stop(), this._startId);
return;
}
// Reset drag start phase.
this._startPhase = DragStartPhase.NONE;
// Mark drag process as ended.

@@ -544,3 +577,4 @@ drag.isEnded = true;

elements.push(item.element);
if (item.elementContainer && item.element.parentElement !== item.elementContainer) {
if (item.elementContainer !== item.dragContainer) {
item.position.x -= item._containerDiff.x;

@@ -550,3 +584,3 @@ item.position.y -= item._containerDiff.y;

item._containerDiff.y = 0;
item.elementContainer.appendChild(item.element);
appendElement(item.element, item.elementContainer);
}

@@ -553,0 +587,0 @@

@@ -17,7 +17,12 @@ import { ticker, tickerReadPhase, tickerWritePhase } from '../../singletons/ticker.js';

import { Point, Writeable } from '../../types.js';
import { Point, Rect, Writeable } from '../../types.js';
const AUTOSCROLL_POSITION = { x: 0, y: 0 };
const AUTOSCROLL_POSITION: Point = { x: 0, y: 0 };
const AUTOSCROLL_CLIENT_RECT = { left: 0, top: 0, width: 0, height: 0 };
const AUTOSCROLL_CLIENT_RECT: Rect = {
width: 0,
height: 0,
x: 0,
y: 0,
};

@@ -36,12 +41,9 @@ function getDefaultSettings<S extends Sensor[], E extends S[number]['events']>() {

if (primaryItem) {
AUTOSCROLL_POSITION.x = primaryItem.position.x;
AUTOSCROLL_POSITION.y = primaryItem.position.y;
return primaryItem.position;
}
// Fallback to the sensor's clientX/clientY values.
else {
const e = drag && (drag.event || drag.startEvent);
AUTOSCROLL_POSITION.x = e ? e.x : 0;
AUTOSCROLL_POSITION.y = e ? e.y : 0;
}
const e = drag && (drag.event || drag.startEvent);
AUTOSCROLL_POSITION.x = e ? e.x : 0;
AUTOSCROLL_POSITION.y = e ? e.y : 0;
return AUTOSCROLL_POSITION;

@@ -55,18 +57,12 @@ },

if (primaryItem && primaryItem.element) {
const { left, top, width, height } = primaryItem.clientRect;
AUTOSCROLL_CLIENT_RECT.left = left;
AUTOSCROLL_CLIENT_RECT.top = top;
AUTOSCROLL_CLIENT_RECT.width = width;
AUTOSCROLL_CLIENT_RECT.height = height;
return primaryItem.clientRect;
}
// Fallback to the sensor's clientX/clientY values and a static size of
// 50x50px.
else {
const e = drag && (drag.event || drag.startEvent);
AUTOSCROLL_CLIENT_RECT.left = e ? e.x - 25 : 0;
AUTOSCROLL_CLIENT_RECT.top = e ? e.y - 25 : 0;
AUTOSCROLL_CLIENT_RECT.width = e ? 50 : 0;
AUTOSCROLL_CLIENT_RECT.height = e ? 50 : 0;
}
const e = drag && (drag.event || drag.startEvent);
AUTOSCROLL_CLIENT_RECT.width = e ? 50 : 0;
AUTOSCROLL_CLIENT_RECT.height = e ? 50 : 0;
AUTOSCROLL_CLIENT_RECT.x = e ? e.x - 25 : 0;
AUTOSCROLL_CLIENT_RECT.y = e ? e.y - 25 : 0;
return AUTOSCROLL_CLIENT_RECT;

@@ -91,3 +87,3 @@ },

this._position = { x: 0, y: 0 };
this._clientRect = { left: 0, top: 0, width: 0, height: 0 };
this._clientRect = { width: 0, height: 0, x: 0, y: 0 };
}

@@ -108,29 +104,25 @@

get position() {
let { getPosition } = this._getSettings();
const position = this._position;
const { getPosition } = this._getSettings();
if (typeof getPosition === 'function') {
const position = getPosition(this._draggable);
this._position.x = position.x;
this._position.y = position.y;
Object.assign(position, getPosition(this._draggable));
} else {
this._position.x = 0;
this._position.y = 0;
position.x = 0;
position.y = 0;
}
return this._position;
return position;
}
get clientRect() {
let { getClientRect } = this._getSettings();
const rect = this._clientRect;
const { getClientRect } = this._getSettings();
if (typeof getClientRect === 'function') {
const { left, top, width, height } = getClientRect(this._draggable);
this._clientRect.left = left;
this._clientRect.top = top;
this._clientRect.width = width;
this._clientRect.height = height;
Object.assign(rect, getClientRect(this._draggable));
} else {
this._clientRect.left = 0;
this._clientRect.top = 0;
this._clientRect.width = 0;
this._clientRect.height = 0;
rect.width = 0;
rect.height = 0;
rect.x = 0;
rect.y = 0;
}
return this._clientRect;
return rect;
}

@@ -176,10 +168,3 @@

getPosition: ((draggable: Draggable<S, E>) => Point) | null;
getClientRect:
| ((draggable: Draggable<S, E>) => {
left: number;
top: number;
width: number;
height: number;
})
| null;
getClientRect: ((draggable: Draggable<S, E>) => Rect) | null;
onStart: AutoScrollItemEventCallback | null;

@@ -204,3 +189,3 @@ onStop: AutoScrollItemEventCallback | null;

this.name = 'autoscroll';
this.version = '0.0.2';
this.version = '0.0.3';
this.settings = this._parseSettings(options);

@@ -207,0 +192,0 @@ this._autoScrollProxy = null;

@@ -81,8 +81,7 @@ import { Emitter, Events, EventListenerId } from 'eventti';

if (!this.drag) return;
this._emitter.emit(SensorEventType.cancel, {
this._cancel({
type: SensorEventType.cancel,
x: this.drag.x,
y: this.drag.y,
});
this._resetDragData();
} as E['cancel']);
}

@@ -89,0 +88,0 @@

@@ -10,4 +10,2 @@ import { Sensor } from './sensor.js';

> {
startPredicate: (e: KeyboardEvent, sensor: KeyboardMotionSensor<E>) => Point | null | undefined;
computeSpeed: (sensor: KeyboardMotionSensor<E>) => number;
startKeys: string[];

@@ -20,2 +18,6 @@ moveLeftKeys: string[];

endKeys: string[];
cancelOnBlur: boolean;
cancelOnVisibilityChange: boolean;
computeSpeed: (sensor: KeyboardMotionSensor<E>) => number;
startPredicate: (e: KeyboardEvent, sensor: KeyboardMotionSensor<E>) => Point | null | undefined;
}

@@ -47,2 +49,22 @@

export const keyboardMotionSensorDefaults: KeyboardMotionSensorSettings<any> = {
startKeys: [' ', 'Enter'],
moveLeftKeys: ['ArrowLeft'],
moveRightKeys: ['ArrowRight'],
moveUpKeys: ['ArrowUp'],
moveDownKeys: ['ArrowDown'],
cancelKeys: ['Escape'],
endKeys: [' ', 'Enter'],
cancelOnBlur: true,
cancelOnVisibilityChange: true,
computeSpeed: () => 500,
startPredicate: (_e, sensor) => {
if (sensor.element && document.activeElement === sensor.element) {
const { left, top } = sensor.element.getBoundingClientRect();
return { x: left, y: top };
}
return null;
},
} as const;
export class KeyboardMotionSensor<E extends KeyboardMotionSensorEvents = KeyboardMotionSensorEvents>

@@ -53,4 +75,3 @@ extends BaseMotionSensor<E>

declare events: E;
protected _startPredicate: Exclude<KeyboardMotionSensorSettings<E>['startPredicate'], undefined>;
protected _computeSpeed: Exclude<KeyboardMotionSensorSettings<E>['computeSpeed'], undefined>;
readonly element: Element | null;
protected _moveKeys: Set<string>;

@@ -65,26 +86,25 @@ protected _moveKeyTimestamps: Map<string, number>;

protected _endKeys: Set<string>;
protected _cancelOnBlur: boolean;
protected _cancelOnVisibilityChange: boolean;
protected _computeSpeed: Exclude<KeyboardMotionSensorSettings<E>['computeSpeed'], undefined>;
protected _startPredicate: Exclude<KeyboardMotionSensorSettings<E>['startPredicate'], undefined>;
constructor(options: Partial<KeyboardMotionSensorSettings<E>> = {}) {
constructor(element: Element | null, options: Partial<KeyboardMotionSensorSettings<E>> = {}) {
super();
const {
startPredicate = () => {
if (document.activeElement) {
const { left, top } = document.activeElement.getBoundingClientRect();
return { x: left, y: top };
}
return null;
},
computeSpeed = () => 500,
startKeys = [' ', 'Enter'],
moveLeftKeys = ['ArrowLeft'],
moveRightKeys = ['ArrowRight'],
moveUpKeys = ['ArrowUp'],
moveDownKeys = ['ArrowDown'],
cancelKeys = ['Escape'],
endKeys = [' ', 'Enter'],
startPredicate = keyboardMotionSensorDefaults.startPredicate,
computeSpeed = keyboardMotionSensorDefaults.computeSpeed,
cancelOnVisibilityChange = keyboardMotionSensorDefaults.cancelOnVisibilityChange,
cancelOnBlur = keyboardMotionSensorDefaults.cancelOnBlur,
startKeys = keyboardMotionSensorDefaults.startKeys,
moveLeftKeys = keyboardMotionSensorDefaults.moveLeftKeys,
moveRightKeys = keyboardMotionSensorDefaults.moveRightKeys,
moveUpKeys = keyboardMotionSensorDefaults.moveUpKeys,
moveDownKeys = keyboardMotionSensorDefaults.moveDownKeys,
cancelKeys = keyboardMotionSensorDefaults.cancelKeys,
endKeys = keyboardMotionSensorDefaults.endKeys,
} = options;
this._computeSpeed = computeSpeed;
this._startPredicate = startPredicate;
this.element = element;
this._startKeys = new Set(startKeys);

@@ -99,2 +119,6 @@ this._cancelKeys = new Set(cancelKeys);

this._moveKeyTimestamps = new Map();
this._cancelOnBlur = cancelOnBlur;
this._cancelOnVisibilityChange = cancelOnVisibilityChange;
this._computeSpeed = computeSpeed;
this._startPredicate = startPredicate;

@@ -104,2 +128,4 @@ this._onKeyDown = this._onKeyDown.bind(this);

this._onTick = this._onTick.bind(this);
this._internalCancel = this._internalCancel.bind(this);
this._blurCancelHandler = this._blurCancelHandler.bind(this);

@@ -109,4 +135,8 @@ this.on('tick', this._onTick, this._onTick);

document.addEventListener('keyup', this._onKeyUp);
window.addEventListener('blur', this.cancel);
window.addEventListener('visibilitychange', this.cancel);
if (cancelOnBlur) {
element?.addEventListener('blur', this._blurCancelHandler);
}
if (cancelOnVisibilityChange) {
document.addEventListener('visibilitychange', this._internalCancel);
}
}

@@ -130,2 +160,21 @@

protected _internalCancel() {
this.cancel();
}
protected _blurCancelHandler() {
// If the Draggable has a container defined the dragged element will be
// appended to the container, which will cause the element to lose focus
// temporarily in some browsers (e.g. Chrome). Draggable will automatically
// restore the focus immediately after the element is appended, but the blur
// event will be triggered anyway. This is why we need to defer the cancel
// call to the next microtask, where we can check if the element is still
// focused.
queueMicrotask(() => {
if (document.activeElement !== this.element) {
this.cancel();
}
});
}
protected _updateDirection() {

@@ -183,7 +232,3 @@ const leftTime = getEarliestTimestamp(this._moveLeftKeys, this._moveKeyTimestamps);

e.preventDefault();
this._cancel({
type: 'cancel',
x: this.drag.x,
y: this.drag.y,
});
this._internalCancel();
return;

@@ -217,10 +262,33 @@ }

if (options.startPredicate !== undefined) {
this._startPredicate = options.startPredicate;
const { cancelOnBlur, cancelOnVisibilityChange, startPredicate, computeSpeed } = options;
if (cancelOnBlur !== undefined && this._cancelOnBlur !== cancelOnBlur) {
this._cancelOnBlur = cancelOnBlur;
if (cancelOnBlur) {
this.element?.addEventListener('blur', this._blurCancelHandler);
} else {
this.element?.removeEventListener('blur', this._blurCancelHandler);
}
}
if (options.computeSpeed !== undefined) {
this._computeSpeed = options.computeSpeed;
if (
cancelOnVisibilityChange !== undefined &&
this._cancelOnVisibilityChange !== cancelOnVisibilityChange
) {
this._cancelOnVisibilityChange = cancelOnVisibilityChange;
if (cancelOnVisibilityChange) {
document.addEventListener('visibilitychange', this._internalCancel);
} else {
document.removeEventListener('visibilitychange', this._internalCancel);
}
}
if (startPredicate !== undefined) {
this._startPredicate = startPredicate;
}
if (computeSpeed !== undefined) {
this._computeSpeed = computeSpeed;
}
KEY_TYPES.forEach((keyType, index) => {

@@ -264,5 +332,9 @@ const name = `${keyType}Keys` as const;

document.removeEventListener('keyup', this._onKeyUp);
window.removeEventListener('blur', this.cancel);
window.removeEventListener('visibilitychange', this.cancel);
if (this._cancelOnBlur) {
this.element?.removeEventListener('blur', this._blurCancelHandler);
}
if (this._cancelOnVisibilityChange) {
document.removeEventListener('visibilitychange', this._internalCancel);
}
}
}

@@ -14,14 +14,15 @@ import {

export type KeyboardSensorPredicate = (
export type KeyboardSensorPredicate<E extends KeyboardSensorEvents = KeyboardSensorEvents> = (
e: KeyboardEvent,
sensor: KeyboardSensor,
moveDistance: Point,
sensor: KeyboardSensor<E>,
) => Point | null | undefined;
export interface KeyboardSensorSettings {
export interface KeyboardSensorSettings<E extends KeyboardSensorEvents = KeyboardSensorEvents> {
moveDistance: number | Point;
startPredicate: KeyboardSensorPredicate;
movePredicate: KeyboardSensorPredicate;
cancelPredicate: KeyboardSensorPredicate;
endPredicate: KeyboardSensorPredicate;
cancelOnBlur: boolean;
cancelOnVisibilityChange: boolean;
startPredicate: KeyboardSensorPredicate<E>;
movePredicate: KeyboardSensorPredicate<E>;
cancelPredicate: KeyboardSensorPredicate<E>;
endPredicate: KeyboardSensorPredicate<E>;
}

@@ -55,2 +56,64 @@

export const keyboardSensorDefaults: KeyboardSensorSettings<any> = {
moveDistance: 25,
cancelOnBlur: true,
cancelOnVisibilityChange: true,
startPredicate: (e, sensor) => {
if (sensor.element && (e.key === 'Enter' || e.key === ' ')) {
if (document.activeElement === sensor.element) {
const { x, y } = sensor.element.getBoundingClientRect();
return { x, y };
}
}
return null;
},
movePredicate: (e, sensor) => {
if (!sensor.drag) return null;
switch (e.key) {
case 'ArrowLeft': {
return {
x: sensor.drag.x - sensor.moveDistance.x,
y: sensor.drag.y,
};
}
case 'ArrowRight': {
return {
x: sensor.drag.x + sensor.moveDistance.x,
y: sensor.drag.y,
};
}
case 'ArrowUp': {
return {
x: sensor.drag.x,
y: sensor.drag.y - sensor.moveDistance.y,
};
}
case 'ArrowDown': {
return {
x: sensor.drag.x,
y: sensor.drag.y + sensor.moveDistance.y,
};
}
default: {
return null;
}
}
},
cancelPredicate: (e, sensor) => {
if (sensor.drag && e.key === 'Escape') {
const { x, y } = sensor.drag;
return { x, y };
}
return null;
},
endPredicate: (e, sensor) => {
if (sensor.drag && (e.key === 'Enter' || e.key === ' ')) {
const { x, y } = sensor.drag;
return { x, y };
}
return null;
},
} as const;
export class KeyboardSensor<E extends KeyboardSensorEvents = KeyboardSensorEvents>

@@ -61,71 +124,29 @@ extends BaseSensor<E>

declare events: E;
protected _moveDistance: Point;
protected _startPredicate: KeyboardSensorPredicate;
protected _movePredicate: KeyboardSensorPredicate;
protected _cancelPredicate: KeyboardSensorPredicate;
protected _endPredicate: KeyboardSensorPredicate;
readonly element: Element | null;
readonly moveDistance: Point;
protected _cancelOnBlur: boolean;
protected _cancelOnVisibilityChange: boolean;
protected _startPredicate: KeyboardSensorPredicate<E>;
protected _movePredicate: KeyboardSensorPredicate<E>;
protected _cancelPredicate: KeyboardSensorPredicate<E>;
protected _endPredicate: KeyboardSensorPredicate<E>;
constructor(options: Partial<KeyboardSensorSettings> = {}) {
constructor(element: Element | null, options: Partial<KeyboardSensorSettings<E>> = {}) {
super();
const {
moveDistance = 25,
startPredicate = (e) => {
if (e.key === 'Enter' || e.key === ' ') {
if (document.activeElement && document.activeElement !== document.body) {
const { left, top } = document.activeElement.getBoundingClientRect();
return { x: left, y: top };
}
}
return null;
},
movePredicate = (e, sensor, moveDistance) => {
if (!sensor.drag) return null;
switch (e.key) {
case 'ArrowLeft': {
return {
x: sensor.drag.x - moveDistance.x,
y: sensor.drag.y,
};
}
case 'ArrowRight': {
return {
x: sensor.drag.x + moveDistance.x,
y: sensor.drag.y,
};
}
case 'ArrowUp': {
return {
x: sensor.drag.x,
y: sensor.drag.y - moveDistance.y,
};
}
case 'ArrowDown': {
return {
x: sensor.drag.x,
y: sensor.drag.y + moveDistance.y,
};
}
default: {
return null;
}
}
},
cancelPredicate = (e, sensor) => {
if (sensor.drag && e.key === 'Escape') {
return { x: sensor.drag.x, y: sensor.drag.y };
}
return null;
},
endPredicate = (e, sensor) => {
if (sensor.drag && (e.key === 'Enter' || e.key === ' ')) {
return { x: sensor.drag.x, y: sensor.drag.y };
}
return null;
},
moveDistance = keyboardSensorDefaults.moveDistance,
cancelOnBlur = keyboardSensorDefaults.cancelOnBlur,
cancelOnVisibilityChange = keyboardSensorDefaults.cancelOnVisibilityChange,
startPredicate = keyboardSensorDefaults.startPredicate,
movePredicate = keyboardSensorDefaults.movePredicate,
cancelPredicate = keyboardSensorDefaults.cancelPredicate,
endPredicate = keyboardSensorDefaults.endPredicate,
} = options;
this._moveDistance =
this.element = element;
this.moveDistance =
typeof moveDistance === 'number' ? { x: moveDistance, y: moveDistance } : { ...moveDistance };
this._cancelOnBlur = cancelOnBlur;
this._cancelOnVisibilityChange = cancelOnVisibilityChange;
this._startPredicate = startPredicate;

@@ -136,14 +157,38 @@ this._movePredicate = movePredicate;

this.cancel = this.cancel.bind(this);
this._onKeyDown = this._onKeyDown.bind(this);
this._internalCancel = this._internalCancel.bind(this);
this._blurCancelHandler = this._blurCancelHandler.bind(this);
document.addEventListener('keydown', this._onKeyDown);
window.addEventListener('blur', this.cancel);
window.addEventListener('visibilitychange', this.cancel);
if (cancelOnBlur) {
element?.addEventListener('blur', this._blurCancelHandler);
}
if (cancelOnVisibilityChange) {
document.addEventListener('visibilitychange', this._internalCancel);
}
}
protected _internalCancel() {
this.cancel();
}
protected _blurCancelHandler() {
// If the Draggable has a container defined the dragged element will be
// appended to the container, which will cause the element to lose focus
// temporarily in some browsers (e.g. Chrome). Draggable will automatically
// restore the focus immediately after the element is appended, but the blur
// event will be triggered anyway. This is why we need to defer the cancel
// call to the next microtask, where we can check if the element is still
// focused.
queueMicrotask(() => {
if (document.activeElement !== this.element) {
this.cancel();
}
});
}
protected _onKeyDown(e: KeyboardEvent) {
// Handle start.
if (!this.drag) {
const startPosition = this._startPredicate(e, this, this._moveDistance);
const startPosition = this._startPredicate(e, this);
if (startPosition) {

@@ -162,3 +207,3 @@ e.preventDefault();

// Handle cancel.
const cancelPosition = this._cancelPredicate(e, this, this._moveDistance);
const cancelPosition = this._cancelPredicate(e, this);
if (cancelPosition) {

@@ -176,3 +221,3 @@ e.preventDefault();

// Handle end.
const endPosition = this._endPredicate(e, this, this._moveDistance);
const endPosition = this._endPredicate(e, this);
if (endPosition) {

@@ -190,3 +235,3 @@ e.preventDefault();

// Handle move.
const movePosition = this._movePredicate(e, this, this._moveDistance);
const movePosition = this._movePredicate(e, this);
if (movePosition) {

@@ -204,28 +249,58 @@ e.preventDefault();

updateSettings(options: Partial<KeyboardSensorSettings> = {}) {
if (options.moveDistance !== undefined) {
if (typeof options.moveDistance === 'number') {
this._moveDistance.x = options.moveDistance;
this._moveDistance.y = options.moveDistance;
updateSettings(options: Partial<KeyboardSensorSettings<E>> = {}) {
const {
moveDistance,
cancelOnBlur,
cancelOnVisibilityChange,
startPredicate,
movePredicate,
cancelPredicate,
endPredicate,
} = options;
if (moveDistance !== undefined) {
if (typeof moveDistance === 'number') {
this.moveDistance.x = this.moveDistance.y = moveDistance;
} else {
this._moveDistance.x = options.moveDistance.x;
this._moveDistance.y = options.moveDistance.y;
this.moveDistance.x = moveDistance.x;
this.moveDistance.y = moveDistance.y;
}
}
if (options.startPredicate !== undefined) {
this._startPredicate = options.startPredicate;
if (cancelOnBlur !== undefined && this._cancelOnBlur !== cancelOnBlur) {
this._cancelOnBlur = cancelOnBlur;
if (cancelOnBlur) {
this.element?.addEventListener('blur', this._blurCancelHandler);
} else {
this.element?.removeEventListener('blur', this._blurCancelHandler);
}
}
if (options.movePredicate !== undefined) {
this._movePredicate = options.movePredicate;
if (
cancelOnVisibilityChange !== undefined &&
this._cancelOnVisibilityChange !== cancelOnVisibilityChange
) {
this._cancelOnVisibilityChange = cancelOnVisibilityChange;
if (cancelOnVisibilityChange) {
document.addEventListener('visibilitychange', this._internalCancel);
} else {
document.removeEventListener('visibilitychange', this._internalCancel);
}
}
if (options.cancelPredicate !== undefined) {
this._cancelPredicate = options.cancelPredicate;
if (startPredicate) {
this._startPredicate = startPredicate;
}
if (options.endPredicate !== undefined) {
this._endPredicate = options.endPredicate;
if (movePredicate) {
this._movePredicate = movePredicate;
}
if (cancelPredicate) {
this._cancelPredicate = cancelPredicate;
}
if (endPredicate) {
this._endPredicate = endPredicate;
}
}

@@ -237,5 +312,9 @@

document.removeEventListener('keydown', this._onKeyDown);
window.removeEventListener('blur', this.cancel);
window.removeEventListener('visibilitychange', this.cancel);
if (this._cancelOnBlur) {
this.element?.removeEventListener('blur', this._blurCancelHandler);
}
if (this._cancelOnVisibilityChange) {
document.removeEventListener('visibilitychange', this._internalCancel);
}
}
}

@@ -17,9 +17,8 @@ export type Writeable<T> = { -readonly [P in keyof T]: T[P] };

export interface Rect extends Dimensions {
export interface Rect extends Point, Dimensions {}
export interface RectFull extends Rect {
left: number;
right: number;
top: number;
}
export interface RectExtended extends Rect {
right: number;
bottom: number;

@@ -26,0 +25,0 @@ }

@@ -1,2 +0,2 @@

import { SensorStartEvent, SensorMoveEvent } from '../sensors/sensor.js';
import { Sensor } from '../sensors/sensor.js';

@@ -19,11 +19,14 @@ import { DraggableDragItem } from 'draggable/draggable-drag-item.js';

export function createSnapModifier(gridWidth: number, gridHeight: number) {
export function createSnapModifier<S extends Sensor[], E extends S[number]['events']>(
gridWidth: number,
gridHeight: number,
) {
return function snapModifier({
item,
event,
startEvent,
event,
item,
}: {
startEvent: SensorStartEvent | SensorMoveEvent;
event: SensorMoveEvent;
item: DraggableDragItem;
item: DraggableDragItem<S, E>;
event: E['start'] | E['move'];
startEvent: E['start'] | E['move'];
}) {

@@ -30,0 +33,0 @@ let { __snapX__ = startEvent.x, __snapY__ = startEvent.y } = item.data;

@@ -1,4 +0,4 @@

import { getIntersection } from 'mezr';
import { getIntersection } from './get-intersection.js';
import { RectExtended } from '../types.js';
import { Rect } from '../types.js';

@@ -8,5 +8,5 @@ /**

*/
export function getIntersectionArea(a: RectExtended, b: RectExtended) {
export function getIntersectionArea(a: Rect, b: Rect) {
const intersection = getIntersection(a, b);
return intersection ? intersection.width * intersection.height : 0;
}
import { getIntersectionArea } from './get-intersection-area.js';
import { RectExtended } from '../types.js';
import { Rect } from '../types.js';

@@ -9,3 +9,3 @@ /**

*/
export function getIntersectionScore(a: RectExtended, b: RectExtended) {
export function getIntersectionScore(a: Rect, b: Rect) {
const area = getIntersectionArea(a, b);

@@ -12,0 +12,0 @@ if (!area) return 0;

@@ -1,2 +0,2 @@

import { RectExtended } from '../types.js';
import { Rect } from '../types.js';

@@ -6,4 +6,9 @@ /**

*/
export function isIntersecting(a: RectExtended, b: RectExtended) {
return !(a.right <= b.left || b.right <= a.left || a.bottom <= b.top || b.bottom <= a.top);
export function isIntersecting(a: Rect, b: Rect) {
return !(
a.x + a.width <= b.x ||
b.x + b.width <= a.x ||
a.y + a.height <= b.y ||
b.y + b.height <= a.y
);
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc