@lancercomet/zoom-pan 0.1.1 → 0.1.3
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/dist/core/view-manager.d.ts +212 -0
- package/dist/index.d.ts +9 -831
- package/dist/index.js +1 -0
- package/dist/index.module.js +1 -0
- package/dist/layer/layer-manager.base.d.ts +34 -0
- package/dist/layer/layer-manager.content.d.ts +52 -0
- package/dist/layer/layer-manager.top-screen.d.ts +13 -0
- package/dist/layer/layer.base.d.ts +16 -0
- package/dist/layer/layer.bitmap.d.ts +37 -0
- package/dist/layer/layer.canvas.d.ts +116 -0
- package/dist/plugins/document/index.d.ts +148 -0
- package/dist/plugins/history/history-manager.d.ts +68 -0
- package/dist/plugins/history/index.d.ts +3 -0
- package/dist/plugins/history/snapshot-command.d.ts +68 -0
- package/dist/plugins/history/types.d.ts +9 -0
- package/dist/plugins/index.d.ts +4 -0
- package/dist/plugins/interaction/index.d.ts +76 -0
- package/dist/plugins/types.d.ts +29 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/utils/index.d.ts +3 -0
- package/package.json +8 -4
- package/dist/index.mjs +0 -812
- package/dist/index.umd.js +0 -795
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { ICommand } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for objects that can capture and restore snapshots.
|
|
4
|
+
* CanvasLayer implements this interface.
|
|
5
|
+
*/
|
|
6
|
+
interface ISnapshotable {
|
|
7
|
+
captureSnapshot(region?: ISnapshotRegion): ImageData | null;
|
|
8
|
+
restoreSnapshot(data: ImageData, position?: {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
}): void;
|
|
12
|
+
}
|
|
13
|
+
interface ISnapshotRegion {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
}
|
|
19
|
+
interface SnapshotCommandOptions {
|
|
20
|
+
/**
|
|
21
|
+
* The region of the snapshot. If not provided, uses full canvas.
|
|
22
|
+
*/
|
|
23
|
+
region?: ISnapshotRegion;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A generic command that stores before/after snapshots for undo/redo.
|
|
27
|
+
* This command is decoupled from any specific layer implementation.
|
|
28
|
+
*/
|
|
29
|
+
declare class SnapshotCommand implements ICommand {
|
|
30
|
+
readonly type = "snapshot";
|
|
31
|
+
private readonly _target;
|
|
32
|
+
private readonly _beforeData;
|
|
33
|
+
private readonly _afterData;
|
|
34
|
+
private readonly _region?;
|
|
35
|
+
private _isExecuted;
|
|
36
|
+
/**
|
|
37
|
+
* Create a snapshot command.
|
|
38
|
+
*
|
|
39
|
+
* @param target - The object to restore snapshots to (must implement ISnapshotable)
|
|
40
|
+
* @param beforeData - The snapshot before the change
|
|
41
|
+
* @param afterData - The snapshot after the change
|
|
42
|
+
* @param options - Optional configuration
|
|
43
|
+
*/
|
|
44
|
+
constructor(target: ISnapshotable, beforeData: ImageData, afterData: ImageData, options?: SnapshotCommandOptions);
|
|
45
|
+
execute(): void;
|
|
46
|
+
undo(): void;
|
|
47
|
+
canMerge(): boolean;
|
|
48
|
+
merge(): ICommand;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Helper function to create a snapshot command.
|
|
52
|
+
*
|
|
53
|
+
* Usage:
|
|
54
|
+
* ```typescript
|
|
55
|
+
* // Before starting the action
|
|
56
|
+
* const before = layer.captureSnapshot()
|
|
57
|
+
*
|
|
58
|
+
* // ... perform some drawing ...
|
|
59
|
+
*
|
|
60
|
+
* // After the action is complete
|
|
61
|
+
* const after = layer.captureSnapshot()
|
|
62
|
+
* const command = createSnapshotCommand(layer, before, after)
|
|
63
|
+
* historyManager.addCommand(command)
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare function createSnapshotCommand(target: ISnapshotable, beforeData: ImageData | null, afterData: ImageData | null, options?: SnapshotCommandOptions): SnapshotCommand | null;
|
|
67
|
+
export { SnapshotCommand, createSnapshotCommand };
|
|
68
|
+
export type { ISnapshotable, ISnapshotRegion, SnapshotCommandOptions };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { ViewManager } from '../../core/view-manager';
|
|
2
|
+
import type { Plugin } from '../types';
|
|
3
|
+
interface InteractionPluginOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Enable pan (drag to move). Default true.
|
|
6
|
+
*/
|
|
7
|
+
panEnabled?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Enable zoom (wheel to scale). Default true.
|
|
10
|
+
*/
|
|
11
|
+
zoomEnabled?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Friction for inertia (per frame). Default 0.92.
|
|
14
|
+
*/
|
|
15
|
+
friction?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Stop speed threshold (px/ms). Default 20/1000.
|
|
18
|
+
*/
|
|
19
|
+
stopSpeed?: number;
|
|
20
|
+
/**
|
|
21
|
+
* EMA alpha for velocity smoothing. Default 0.25.
|
|
22
|
+
*/
|
|
23
|
+
emaAlpha?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Idle time (ms) before clearing inertia on pointer up. Default 120.
|
|
26
|
+
*/
|
|
27
|
+
idleNoInertiaMs?: number;
|
|
28
|
+
/**
|
|
29
|
+
* Wheel sensitivity (pixel -> log step multiplier). Default 0.0015.
|
|
30
|
+
*/
|
|
31
|
+
wheelSensitivity?: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Interaction Plugin
|
|
35
|
+
*
|
|
36
|
+
* Handles pan (drag), zoom (wheel), and inertia.
|
|
37
|
+
* Can be enabled/disabled at runtime.
|
|
38
|
+
*/
|
|
39
|
+
declare class InteractionPlugin implements Plugin {
|
|
40
|
+
readonly name = "interaction";
|
|
41
|
+
private _view;
|
|
42
|
+
private _options;
|
|
43
|
+
private _panEnabled;
|
|
44
|
+
private _zoomEnabled;
|
|
45
|
+
private _dragging;
|
|
46
|
+
private _vx;
|
|
47
|
+
private _vy;
|
|
48
|
+
private _lastMoveTs;
|
|
49
|
+
private _activePointerId;
|
|
50
|
+
private _onDownBound;
|
|
51
|
+
private _onMoveBound;
|
|
52
|
+
private _onUpBound;
|
|
53
|
+
private _onWheelBound;
|
|
54
|
+
constructor(options?: InteractionPluginOptions);
|
|
55
|
+
install(view: ViewManager): void;
|
|
56
|
+
destroy(): void;
|
|
57
|
+
isPanEnabled(): boolean;
|
|
58
|
+
isZoomEnabled(): boolean;
|
|
59
|
+
setPanEnabled(enabled: boolean): void;
|
|
60
|
+
setZoomEnabled(enabled: boolean): void;
|
|
61
|
+
setWheelSensitivity(s: number): void;
|
|
62
|
+
isDragging(): boolean;
|
|
63
|
+
private _onUpdate;
|
|
64
|
+
private _onPointerDown;
|
|
65
|
+
private _onPointerMove;
|
|
66
|
+
private _onPointerUp;
|
|
67
|
+
private _getLineHeightPx;
|
|
68
|
+
private _normalizeWheelDelta;
|
|
69
|
+
private _onWheel;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Create an interaction plugin instance.
|
|
73
|
+
*/
|
|
74
|
+
declare function createInteractionPlugin(options?: InteractionPluginOptions): InteractionPlugin;
|
|
75
|
+
export { InteractionPlugin, createInteractionPlugin };
|
|
76
|
+
export type { InteractionPluginOptions };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ViewManager } from '../core/view-manager';
|
|
2
|
+
/**
|
|
3
|
+
* Plugin interface for ViewManager.
|
|
4
|
+
* Plugins can extend the core functionality with additional features.
|
|
5
|
+
*/
|
|
6
|
+
interface Plugin {
|
|
7
|
+
/**
|
|
8
|
+
* Unique name of the plugin.
|
|
9
|
+
*/
|
|
10
|
+
readonly name: string;
|
|
11
|
+
/**
|
|
12
|
+
* Called when the plugin is installed on a ViewManager instance.
|
|
13
|
+
* @param view The ViewManager instance
|
|
14
|
+
*/
|
|
15
|
+
install(view: ViewManager): void;
|
|
16
|
+
/**
|
|
17
|
+
* Called when the plugin is uninstalled or the ViewManager is destroyed.
|
|
18
|
+
*/
|
|
19
|
+
destroy(): void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Plugin constructor type for creating plugin instances.
|
|
23
|
+
*/
|
|
24
|
+
type PluginConstructor<T extends Plugin = Plugin, O = unknown> = new (options?: O) => T;
|
|
25
|
+
/**
|
|
26
|
+
* Plugin factory function type.
|
|
27
|
+
*/
|
|
28
|
+
type PluginFactory<T extends Plugin = Plugin, O = unknown> = (options?: O) => T;
|
|
29
|
+
export type { Plugin, PluginConstructor, PluginFactory };
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lancercomet/zoom-pan",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Yet another web 2D rendering lib.",
|
|
5
|
-
"main": "./dist/index.
|
|
6
|
-
"module": "./dist/index.
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.module.js",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist/**/*",
|
|
9
9
|
"README.md"
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"scripts": {
|
|
12
12
|
"dev": "vite",
|
|
13
13
|
"build:example": "vite build --mode example",
|
|
14
|
-
"build:lib": "
|
|
14
|
+
"build:lib": "rollup -c"
|
|
15
15
|
},
|
|
16
16
|
"keywords": [],
|
|
17
17
|
"author": "",
|
|
@@ -20,6 +20,10 @@
|
|
|
20
20
|
"@lancercomet/eslint-config-eslint-rules": "^0.2.0",
|
|
21
21
|
"@rollup/plugin-terser": "^0.4.4",
|
|
22
22
|
"@vitejs/plugin-vue-jsx": "^5.1.1",
|
|
23
|
+
"rollup": "^4.53.3",
|
|
24
|
+
"rollup-plugin-commonjs": "^10.1.0",
|
|
25
|
+
"rollup-plugin-delete": "^2.0.0",
|
|
26
|
+
"rollup-plugin-typescript2": "^0.31.2",
|
|
23
27
|
"stylus": "^0.64.0",
|
|
24
28
|
"terser": "^5.44.1",
|
|
25
29
|
"typescript": "^5.9.2",
|