use-canvas-drag 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 ADDED
@@ -0,0 +1,37 @@
1
+ # use-canvas-drag
2
+
3
+ Vue3 画布拖拽组合式函数,支持多种鼠标触发方式。
4
+
5
+ ## 安装
6
+
7
+ \`\`\`bash
8
+ npm install use-canvas-drag
9
+ \`\`\`
10
+
11
+ ## 使用
12
+
13
+ \`\`\`typescript
14
+ import { useCanvasDrag } from 'use-canvas-drag'
15
+
16
+ const { isPanning, handlers, stopPan } = useCanvasDrag({
17
+ container: '#canvas',
18
+ mode: 'right', // 可选: 'left' | 'right' | 'middle' | 'shift-left' | 'ctrl-left' | 'alt-left'
19
+ })
20
+ \`\`\`
21
+
22
+ ## API
23
+
24
+ ### useCanvasDrag(options)
25
+
26
+ | 参数 | 类型 | 说明 |
27
+ | ----------- | ----------------------------------------- | ---------------------- |
28
+ | container | string\| HTMLElement \| () => HTMLElement | 画布容器 |
29
+ | mode | DragTrigger\| DragTrigger[] | 触发方式,默认 'right' |
30
+ | enabled | boolean | 是否启用,默认 true |
31
+ | onStartDrag | (e: MouseEvent) => void | 开始拖拽回调 |
32
+ | onDrag | ({x, y}) => void | 拖拽中回调 |
33
+ | onEndDrag | () => void | 结束拖拽回调 |
34
+
35
+ ## License
36
+
37
+ MIT
@@ -0,0 +1 @@
1
+ export {}
File without changes
@@ -0,0 +1 @@
1
+ (function(e){typeof define==`function`&&define.amd?define([],e):e()})(function(){});
@@ -0,0 +1 @@
1
+ export type { DragButtonConfig, CanvasDragOptions, DragTrigger } from './useCanvasDrag';
@@ -0,0 +1,37 @@
1
+ export interface DragButtonConfig {
2
+ button?: number;
3
+ modifiers?: {
4
+ shift?: boolean;
5
+ ctrl?: boolean;
6
+ alt?: boolean;
7
+ meta?: boolean;
8
+ };
9
+ }
10
+ type ModeValue = 'right' | 'middle' | 'left' | 'shift-left' | 'ctrl-left' | 'alt-left';
11
+ export type DragTrigger = ModeValue | DragButtonConfig;
12
+ export interface CanvasDragOptions {
13
+ /**拖拽触发键列表 */
14
+ mode?: DragTrigger | DragTrigger[];
15
+ /** 画布容器 */
16
+ container: string | HTMLElement | (() => HTMLElement | null);
17
+ /** 是否启用拖拽 */
18
+ enabled?: boolean;
19
+ /** 拖拽开始时触发 */
20
+ onStartDrag?: (e: MouseEvent) => void;
21
+ /** 拖拽中触发 */
22
+ onDrag?: (detail: {
23
+ x: number;
24
+ y: number;
25
+ }) => void;
26
+ /** 拖拽结束时触发 */
27
+ onEndDrag?: () => void;
28
+ }
29
+ export declare function useCanvasDrag(options: CanvasDragOptions): {
30
+ isPanning: import('vue').Ref<boolean, boolean>;
31
+ handlers: {
32
+ onMouseDown: (e: MouseEvent) => void;
33
+ onContextMenu: (e: MouseEvent) => void;
34
+ };
35
+ stopPan: () => void;
36
+ };
37
+ export {};
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "use-canvas-drag",
3
+ "version": "0.1.0",
4
+ "description": "Vue3 画布拖拽组合式函数,支持多种触发方式",
5
+ "main": "./dist/index.umd.js",
6
+ "module": "./dist/index.esm.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.esm.js",
11
+ "require": "./dist/index.umd.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "vite build",
20
+ "test": "echo \"Error: no test specified\" && exit 1"
21
+ },
22
+ "keywords": [
23
+ "vue3",
24
+ "canvas",
25
+ "drag",
26
+ "pan",
27
+ "use-canvas-drag"
28
+ ],
29
+ "author": "lrb",
30
+ "license": "MIT",
31
+ "peerDependencies": {
32
+ "vue": "^3.0.0"
33
+ },
34
+ "devDependencies": {
35
+ "@vitejs/plugin-vue": "^6.0.6",
36
+ "typescript": "^6.0.3",
37
+ "vite": "^8.0.12",
38
+ "vite-plugin-dts": "^4.5.0",
39
+ "vue": "^3.5.34",
40
+ "vue-tsc": "^3.2.8"
41
+ }
42
+ }