snap-dnd 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +318 -0
- package/dist/behaviors/AutoScroll.d.ts +20 -0
- package/dist/behaviors/ConstraintAxis.d.ts +37 -0
- package/dist/behaviors/SnapGrid.d.ts +38 -0
- package/dist/behaviors/index.d.ts +3 -0
- package/dist/core/DragEngine.d.ts +60 -0
- package/dist/core/DragState.d.ts +67 -0
- package/dist/core/DropZone.d.ts +97 -0
- package/dist/core/Snap.d.ts +85 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/index.d.ts +62 -0
- package/dist/plugins/FileDrop.d.ts +33 -0
- package/dist/plugins/Kanban.d.ts +40 -0
- package/dist/plugins/Sortable.d.ts +33 -0
- package/dist/plugins/index.d.ts +3 -0
- package/dist/sensors/FileSensor.d.ts +51 -0
- package/dist/sensors/PointerSensor.d.ts +79 -0
- package/dist/sensors/index.d.ts +2 -0
- package/dist/snap.core.js +13 -0
- package/dist/snap.core.js.map +7 -0
- package/dist/snap.esm.js +49 -0
- package/dist/snap.esm.js.map +7 -0
- package/dist/snap.umd.js +49 -0
- package/dist/snap.umd.js.map +7 -0
- package/dist/types/index.d.ts +161 -0
- package/dist/utils/BoundsCache.d.ts +54 -0
- package/dist/utils/DataTransfer.d.ts +32 -0
- package/dist/utils/EventEmitter.d.ts +37 -0
- package/dist/utils/ObjectPool.d.ts +38 -0
- package/dist/utils/RAFThrottle.d.ts +39 -0
- package/dist/utils/index.d.ts +5 -0
- package/package.json +54 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic object pool for reusing frequently allocated objects
|
|
3
|
+
* Reduces GC pressure during drag operations
|
|
4
|
+
*/
|
|
5
|
+
export declare class ObjectPool<T> {
|
|
6
|
+
private _pool;
|
|
7
|
+
private _factory;
|
|
8
|
+
private _reset;
|
|
9
|
+
private _maxSize;
|
|
10
|
+
constructor(factory: () => T, reset: (obj: T) => void, initialSize?: number, maxSize?: number);
|
|
11
|
+
/**
|
|
12
|
+
* Get an object from the pool or create a new one
|
|
13
|
+
*/
|
|
14
|
+
acquire(): T;
|
|
15
|
+
/**
|
|
16
|
+
* Return an object to the pool for reuse
|
|
17
|
+
*/
|
|
18
|
+
release(obj: T): void;
|
|
19
|
+
/**
|
|
20
|
+
* Clear all pooled objects
|
|
21
|
+
*/
|
|
22
|
+
clear(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Current pool size
|
|
25
|
+
*/
|
|
26
|
+
get size(): number;
|
|
27
|
+
}
|
|
28
|
+
import type { Point, Rect } from '../types/index.js';
|
|
29
|
+
export declare const pointPool: ObjectPool<Point>;
|
|
30
|
+
export declare const rectPool: ObjectPool<Rect>;
|
|
31
|
+
/**
|
|
32
|
+
* Helper to get a point from pool with initial values
|
|
33
|
+
*/
|
|
34
|
+
export declare function acquirePoint(x: number, y: number): Point;
|
|
35
|
+
/**
|
|
36
|
+
* Helper to get a rect from pool with initial values
|
|
37
|
+
*/
|
|
38
|
+
export declare function acquireRect(x: number, y: number, width: number, height: number): Rect;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RAF-based throttling for high-frequency events
|
|
3
|
+
* Ensures only one callback per animation frame
|
|
4
|
+
*/
|
|
5
|
+
export declare class RAFThrottle<T> {
|
|
6
|
+
private _rafId;
|
|
7
|
+
private _pending;
|
|
8
|
+
private _callback;
|
|
9
|
+
constructor(callback: (data: T) => void);
|
|
10
|
+
/**
|
|
11
|
+
* Queue data to be processed on next animation frame
|
|
12
|
+
* Only the most recent data will be processed
|
|
13
|
+
*/
|
|
14
|
+
queue(data: T): void;
|
|
15
|
+
/**
|
|
16
|
+
* Cancel any pending frame
|
|
17
|
+
*/
|
|
18
|
+
cancel(): void;
|
|
19
|
+
/**
|
|
20
|
+
* Process immediately if there's pending data
|
|
21
|
+
*/
|
|
22
|
+
flush(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Check if there's a pending frame
|
|
25
|
+
*/
|
|
26
|
+
get isPending(): boolean;
|
|
27
|
+
private _process;
|
|
28
|
+
/**
|
|
29
|
+
* Cleanup
|
|
30
|
+
*/
|
|
31
|
+
destroy(): void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Create a throttled function using RAF
|
|
35
|
+
*/
|
|
36
|
+
export declare function rafThrottle<T extends (...args: unknown[]) => void>(fn: T): T & {
|
|
37
|
+
cancel: () => void;
|
|
38
|
+
flush: () => void;
|
|
39
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { ObjectPool, pointPool, rectPool, acquirePoint, acquireRect } from './ObjectPool.js';
|
|
2
|
+
export { EventEmitter, type EventCallback } from './EventEmitter.js';
|
|
3
|
+
export { BoundsCache, boundsCache, pointInRect, rectsIntersect, rectCenter, distance } from './BoundsCache.js';
|
|
4
|
+
export { RAFThrottle, rafThrottle } from './RAFThrottle.js';
|
|
5
|
+
export { SnapDataTransfer } from './DataTransfer.js';
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "snap-dnd",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A zero-dependency, memory-optimized drag and drop library for vanilla JS and Web Components",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/snap.umd.js",
|
|
7
|
+
"module": "./dist/snap.esm.js",
|
|
8
|
+
"types": "./dist/snap.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/snap.esm.js",
|
|
12
|
+
"require": "./dist/snap.umd.js"
|
|
13
|
+
},
|
|
14
|
+
"./core": {
|
|
15
|
+
"import": "./dist/snap.core.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "npm run build:full && npm run build:core",
|
|
24
|
+
"build:full": "esbuild src/index.ts --bundle --format=esm --minify --sourcemap --outfile=dist/snap.esm.js && esbuild src/index.ts --bundle --format=iife --global-name=Snap --minify --sourcemap --outfile=dist/snap.umd.js",
|
|
25
|
+
"build:core": "esbuild src/core-only.ts --bundle --format=esm --minify --sourcemap --outfile=dist/snap.core.js",
|
|
26
|
+
"dev": "esbuild src/index.ts --bundle --format=esm --watch --outfile=dist/snap.esm.js",
|
|
27
|
+
"typecheck": "tsc --noEmit",
|
|
28
|
+
"test": "vitest",
|
|
29
|
+
"test:run": "vitest run",
|
|
30
|
+
"prepublishOnly": "npm run build"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=18"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"drag",
|
|
37
|
+
"drop",
|
|
38
|
+
"dnd",
|
|
39
|
+
"draggable",
|
|
40
|
+
"sortable",
|
|
41
|
+
"kanban",
|
|
42
|
+
"vanilla",
|
|
43
|
+
"web-components",
|
|
44
|
+
"lit"
|
|
45
|
+
],
|
|
46
|
+
"author": "",
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/node": "^20.11.0",
|
|
50
|
+
"esbuild": "^0.20.0",
|
|
51
|
+
"typescript": "^5.3.3",
|
|
52
|
+
"vitest": "^1.2.2"
|
|
53
|
+
}
|
|
54
|
+
}
|