@markup-canvas/core 1.1.7 → 1.2.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/dist/index.d.ts +1 -1
- package/dist/lib/MarkupCanvas.d.ts +9 -12
- package/dist/lib/actions/config/getConfig.d.ts +2 -0
- package/dist/lib/actions/index.d.ts +3 -0
- package/dist/lib/actions/pan/centerContent.d.ts +2 -0
- package/dist/lib/actions/pan/index.d.ts +6 -0
- package/dist/lib/actions/pan/panDown.d.ts +2 -0
- package/dist/lib/actions/pan/panLeft.d.ts +2 -0
- package/dist/lib/actions/pan/panRight.d.ts +2 -0
- package/dist/lib/actions/pan/panUp.d.ts +2 -0
- package/dist/lib/actions/pan/scrollToPoint.d.ts +2 -0
- package/dist/lib/actions/transform/index.d.ts +2 -0
- package/dist/lib/actions/transform/resetTransform.d.ts +2 -0
- package/dist/lib/actions/transform/updateTransform.d.ts +2 -0
- package/dist/lib/actions/ui/grid/hideGrid.d.ts +2 -0
- package/dist/lib/actions/ui/grid/index.d.ts +4 -0
- package/dist/lib/actions/ui/grid/isGridVisible.d.ts +2 -0
- package/dist/lib/actions/ui/grid/showGrid.d.ts +2 -0
- package/dist/lib/actions/ui/grid/toggleGrid.d.ts +2 -0
- package/dist/lib/actions/ui/index.d.ts +4 -0
- package/dist/lib/actions/ui/rulers/areRulersVisible.d.ts +2 -0
- package/dist/lib/actions/ui/rulers/hideRulers.d.ts +2 -0
- package/dist/lib/actions/ui/rulers/index.d.ts +4 -0
- package/dist/lib/actions/ui/rulers/showRulers.d.ts +2 -0
- package/dist/lib/actions/ui/rulers/toggleRulers.d.ts +2 -0
- package/dist/lib/actions/ui/toggleTransition.d.ts +1 -0
- package/dist/lib/actions/ui/updateThemeMode.d.ts +2 -0
- package/dist/lib/actions/zoom/index.d.ts +6 -0
- package/dist/lib/actions/zoom/resetView.d.ts +2 -0
- package/dist/lib/actions/zoom/resetViewToCenter.d.ts +3 -0
- package/dist/lib/actions/zoom/setZoom.d.ts +3 -0
- package/dist/lib/actions/zoom/zoomIn.d.ts +3 -0
- package/dist/lib/actions/zoom/zoomOut.d.ts +3 -0
- package/dist/lib/actions/zoom/zoomToPoint.d.ts +2 -0
- package/dist/lib/canvas/createCanvas.d.ts +2 -2
- package/dist/lib/canvas/fitToScreen.d.ts +2 -0
- package/dist/lib/canvas/getCanvasBounds.d.ts +2 -2
- package/dist/lib/canvas/index.d.ts +1 -1
- package/dist/lib/events/emitTransformEvents.d.ts +3 -0
- package/dist/lib/events/keyboard/handleKeyDown.d.ts +3 -2
- package/dist/lib/events/keyboard/handleKeyUp.d.ts +3 -2
- package/dist/lib/events/keyboard/setupKeyboardEvents.d.ts +3 -2
- package/dist/lib/events/mouse/createMouseDragControls.d.ts +7 -0
- package/dist/lib/events/mouse/handleClickToZoom.d.ts +3 -2
- package/dist/lib/events/mouse/handleMouseDown.d.ts +3 -2
- package/dist/lib/events/mouse/handleMouseLeave.d.ts +3 -2
- package/dist/lib/events/mouse/handleMouseMove.d.ts +3 -2
- package/dist/lib/events/mouse/handleMouseUp.d.ts +3 -2
- package/dist/lib/events/mouse/setupMouseDrag.d.ts +4 -3
- package/dist/lib/events/mouse/setupMouseEvents.d.ts +4 -3
- package/dist/lib/events/touch/handleTouchMove.d.ts +3 -2
- package/dist/lib/events/touch/setupTouchEvents.d.ts +2 -2
- package/dist/lib/events/trackpad/createTrackpadPanHandler.d.ts +2 -2
- package/dist/lib/events/utils/getAdaptiveZoomSpeed.d.ts +2 -2
- package/dist/lib/events/utils/getViewportCenter.d.ts +2 -2
- package/dist/lib/events/utils/resetDragState.d.ts +3 -2
- package/dist/lib/events/utils/updateCursor.d.ts +3 -2
- package/dist/lib/events/wheel/handleWheel.d.ts +3 -2
- package/dist/lib/events/wheel/setupWheelEvents.d.ts +3 -2
- package/dist/lib/events/wheel/setupWheelHandler.d.ts +3 -2
- package/dist/lib/helpers/getVisibleArea.d.ts +7 -0
- package/dist/lib/helpers/index.d.ts +2 -0
- package/dist/lib/helpers/isPointVisible.d.ts +2 -0
- package/dist/lib/transform/applyZoomToCanvas.d.ts +2 -2
- package/dist/lib/window/bindCanvasToWindow.d.ts +3 -0
- package/dist/lib/window/broadcastEvent.d.ts +2 -0
- package/dist/lib/window/cleanupWindowBinding.d.ts +2 -0
- package/dist/lib/window/index.d.ts +3 -0
- package/dist/markup-canvas.cjs.js +686 -530
- package/dist/markup-canvas.esm.js +686 -530
- package/dist/markup-canvas.umd.js +684 -525
- package/dist/markup-canvas.umd.min.js +1 -1
- package/dist/types/canvas.d.ts +1 -48
- package/dist/types/config.d.ts +0 -3
- package/dist/types/events.d.ts +4 -1
- package/dist/types/index.d.ts +3 -2
- package/dist/types/window.d.ts +84 -0
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/lib/MarkupCanvas.ts +136 -316
- package/src/lib/actions/config/getConfig.ts +5 -0
- package/src/lib/actions/index.ts +6 -0
- package/src/lib/actions/pan/centerContent.ts +21 -0
- package/src/lib/actions/pan/index.ts +6 -0
- package/src/lib/actions/pan/panDown.ts +13 -0
- package/src/lib/actions/pan/panLeft.ts +13 -0
- package/src/lib/actions/pan/panRight.ts +13 -0
- package/src/lib/actions/pan/panUp.ts +13 -0
- package/src/lib/actions/pan/scrollToPoint.ts +27 -0
- package/src/lib/actions/transform/index.ts +2 -0
- package/src/lib/actions/transform/resetTransform.ts +11 -0
- package/src/lib/actions/transform/updateTransform.ts +9 -0
- package/src/lib/actions/ui/grid/hideGrid.ts +9 -0
- package/src/lib/actions/ui/grid/index.ts +4 -0
- package/src/lib/actions/ui/grid/isGridVisible.ts +8 -0
- package/src/lib/actions/ui/grid/showGrid.ts +9 -0
- package/src/lib/actions/ui/grid/toggleGrid.ts +9 -0
- package/src/lib/actions/ui/index.ts +4 -0
- package/src/lib/actions/ui/rulers/areRulersVisible.ts +8 -0
- package/src/lib/actions/ui/rulers/hideRulers.ts +9 -0
- package/src/lib/actions/ui/rulers/index.ts +4 -0
- package/src/lib/actions/ui/rulers/showRulers.ts +9 -0
- package/src/lib/actions/ui/rulers/toggleRulers.ts +14 -0
- package/src/lib/actions/ui/toggleTransition.ts +3 -0
- package/src/lib/actions/ui/updateThemeMode.ts +25 -0
- package/src/lib/actions/zoom/index.ts +6 -0
- package/src/lib/actions/zoom/resetView.ts +17 -0
- package/src/lib/actions/zoom/resetViewToCenter.ts +21 -0
- package/src/lib/actions/zoom/setZoom.ts +22 -0
- package/src/lib/actions/zoom/zoomIn.ts +21 -0
- package/src/lib/actions/zoom/zoomOut.ts +21 -0
- package/src/lib/actions/zoom/zoomToPoint.ts +18 -0
- package/src/lib/canvas/createCanvas.ts +6 -14
- package/src/lib/canvas/fitToScreen.ts +27 -0
- package/src/lib/canvas/getCanvasBounds.ts +3 -4
- package/src/lib/canvas/index.ts +1 -1
- package/src/lib/config/constants.ts +2 -6
- package/src/lib/config/presets/editor-preset.ts +2 -6
- package/src/lib/events/emitTransformEvents.ts +9 -0
- package/src/lib/events/keyboard/handleKeyDown.ts +3 -2
- package/src/lib/events/keyboard/handleKeyUp.ts +3 -2
- package/src/lib/events/keyboard/setupKeyboardEvents.ts +3 -2
- package/src/lib/events/mouse/createMouseDragControls.ts +21 -0
- package/src/lib/events/mouse/handleClickToZoom.ts +3 -2
- package/src/lib/events/mouse/handleMouseDown.ts +3 -2
- package/src/lib/events/mouse/handleMouseLeave.ts +3 -2
- package/src/lib/events/mouse/handleMouseMove.ts +3 -2
- package/src/lib/events/mouse/handleMouseUp.ts +3 -2
- package/src/lib/events/mouse/setupMouseDrag.ts +5 -4
- package/src/lib/events/mouse/setupMouseEvents.ts +5 -4
- package/src/lib/events/postMessage/setupPostMessageEvents.ts +10 -0
- package/src/lib/events/touch/handleTouchMove.ts +3 -2
- package/src/lib/events/touch/setupTouchEvents.ts +3 -2
- package/src/lib/events/trackpad/createTrackpadPanHandler.ts +3 -2
- package/src/lib/events/utils/getAdaptiveZoomSpeed.ts +2 -2
- package/src/lib/events/utils/getViewportCenter.ts +2 -2
- package/src/lib/events/utils/resetDragState.ts +3 -2
- package/src/lib/events/utils/updateCursor.ts +3 -2
- package/src/lib/events/wheel/handleWheel.ts +3 -2
- package/src/lib/events/wheel/setupWheelEvents.ts +3 -2
- package/src/lib/events/wheel/setupWheelHandler.ts +3 -2
- package/src/lib/helpers/getVisibleArea.ts +6 -0
- package/src/lib/helpers/index.ts +2 -0
- package/src/lib/helpers/isPointVisible.ts +7 -0
- package/src/lib/rulers/createRulers.ts +0 -1
- package/src/lib/transform/applyZoomToCanvas.ts +2 -2
- package/src/lib/window/bindCanvasToWindow.ts +128 -0
- package/src/lib/window/broadcastEvent.ts +38 -0
- package/src/lib/window/cleanupWindowBinding.ts +15 -0
- package/src/lib/window/index.ts +3 -0
- package/src/types/canvas.ts +1 -48
- package/src/types/config.ts +1 -7
- package/src/types/events.ts +7 -1
- package/src/types/index.ts +4 -2
- package/src/types/window.ts +77 -0
- package/dist/lib/canvas/config.d.ts +0 -2
- package/dist/lib/canvas/getCanvasMethods.d.ts +0 -12
- package/src/lib/canvas/config.ts +0 -29
- package/src/lib/canvas/getCanvasMethods.ts +0 -102
- /package/dist/lib/canvas/{calcVisibleArea.d.ts → calculateVisibleArea.d.ts} +0 -0
- /package/src/lib/canvas/{calcVisibleArea.ts → calculateVisibleArea.ts} +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { MouseDragControls } from "@/types/index.js";
|
|
2
|
+
|
|
3
|
+
export interface MouseDragControlMethods {
|
|
4
|
+
enableMouseDrag: () => boolean;
|
|
5
|
+
disableMouseDrag: () => boolean;
|
|
6
|
+
isMouseDragEnabled: () => boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function createMouseDragControls(dragSetup: MouseDragControls | null): MouseDragControlMethods {
|
|
10
|
+
return {
|
|
11
|
+
enableMouseDrag(): boolean {
|
|
12
|
+
return dragSetup?.enable() ?? false;
|
|
13
|
+
},
|
|
14
|
+
disableMouseDrag(): boolean {
|
|
15
|
+
return dragSetup?.disable() ?? false;
|
|
16
|
+
},
|
|
17
|
+
isMouseDragEnabled(): boolean {
|
|
18
|
+
return dragSetup?.isEnabled() ?? false;
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { CLICK_THRESHOLDS } from "@/lib/events/constants.js";
|
|
2
2
|
import { withRulerOffset } from "@/lib/helpers/index.js";
|
|
3
|
+
import type { MarkupCanvas } from "@/lib/MarkupCanvas.js";
|
|
3
4
|
import { withTransition } from "@/lib/transition/withTransition.js";
|
|
4
|
-
import type {
|
|
5
|
+
import type { MarkupCanvasConfig, Transform } from "@/types/index.js";
|
|
5
6
|
|
|
6
7
|
export function handleClickToZoom(
|
|
7
8
|
event: MouseEvent,
|
|
8
|
-
canvas:
|
|
9
|
+
canvas: MarkupCanvas,
|
|
9
10
|
config: Required<MarkupCanvasConfig>,
|
|
10
11
|
mouseDownTime: number,
|
|
11
12
|
hasDragged: boolean,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { updateCursor } from "@/lib/events/utils/updateCursor.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { MarkupCanvas } from "@/lib/MarkupCanvas.js";
|
|
3
|
+
import type { MarkupCanvasConfig } from "@/types/index.js";
|
|
3
4
|
|
|
4
5
|
export function handleMouseDown(
|
|
5
6
|
event: MouseEvent,
|
|
6
|
-
canvas:
|
|
7
|
+
canvas: MarkupCanvas,
|
|
7
8
|
config: Required<MarkupCanvasConfig>,
|
|
8
9
|
isDragEnabled: boolean,
|
|
9
10
|
isSpacePressed: boolean,
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { resetDragState } from "@/lib/events/utils/resetDragState.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { MarkupCanvas } from "@/lib/MarkupCanvas.js";
|
|
3
|
+
import type { MarkupCanvasConfig } from "@/types/index.js";
|
|
3
4
|
|
|
4
5
|
export function handleMouseLeave(
|
|
5
|
-
canvas:
|
|
6
|
+
canvas: MarkupCanvas,
|
|
6
7
|
config: Required<MarkupCanvasConfig>,
|
|
7
8
|
isDragEnabled: boolean,
|
|
8
9
|
isSpacePressed: boolean,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { CLICK_THRESHOLDS } from "@/lib/events/constants.js";
|
|
2
2
|
import { withRAFThrottle } from "@/lib/helpers/index.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { MarkupCanvas } from "@/lib/MarkupCanvas.js";
|
|
4
|
+
import type { MarkupCanvasConfig, Transform } from "@/types/index.js";
|
|
4
5
|
|
|
5
6
|
export function handleMouseMove(
|
|
6
7
|
event: MouseEvent,
|
|
7
|
-
canvas:
|
|
8
|
+
canvas: MarkupCanvas,
|
|
8
9
|
config: Required<MarkupCanvasConfig>,
|
|
9
10
|
isDragEnabled: boolean,
|
|
10
11
|
isDragging: boolean,
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { handleClickToZoom } from "@/lib/events/mouse/handleClickToZoom.js";
|
|
2
2
|
import { resetClickState } from "@/lib/events/utils/resetClickState.js";
|
|
3
3
|
import { resetDragState } from "@/lib/events/utils/resetDragState.js";
|
|
4
|
-
import type {
|
|
4
|
+
import type { MarkupCanvas } from "@/lib/MarkupCanvas.js";
|
|
5
|
+
import type { MarkupCanvasConfig } from "@/types/index.js";
|
|
5
6
|
|
|
6
7
|
export function handleMouseUp(
|
|
7
8
|
event: MouseEvent,
|
|
8
|
-
canvas:
|
|
9
|
+
canvas: MarkupCanvas,
|
|
9
10
|
config: Required<MarkupCanvasConfig>,
|
|
10
11
|
isDragEnabled: boolean,
|
|
11
12
|
isSpacePressed: boolean,
|
|
@@ -6,13 +6,14 @@ import { handleMouseMove } from "@/lib/events/mouse/handleMouseMove.js";
|
|
|
6
6
|
import { handleMouseUp } from "@/lib/events/mouse/handleMouseUp.js";
|
|
7
7
|
import { resetDragState } from "@/lib/events/utils/resetDragState.js";
|
|
8
8
|
import { updateCursor } from "@/lib/events/utils/updateCursor.js";
|
|
9
|
+
import type { MarkupCanvas } from "@/lib/MarkupCanvas.js";
|
|
9
10
|
import type { MouseDragControls } from "@/types/events.js";
|
|
10
|
-
import type {
|
|
11
|
+
import type { MarkupCanvasConfig } from "@/types/index.js";
|
|
11
12
|
|
|
12
|
-
export function setupMouseEvents(canvas:
|
|
13
|
-
export function setupMouseEvents(canvas:
|
|
13
|
+
export function setupMouseEvents(canvas: MarkupCanvas, config: Required<MarkupCanvasConfig>, withControls: true): MouseDragControls;
|
|
14
|
+
export function setupMouseEvents(canvas: MarkupCanvas, config: Required<MarkupCanvasConfig>, withControls: false): () => void;
|
|
14
15
|
export function setupMouseEvents(
|
|
15
|
-
canvas:
|
|
16
|
+
canvas: MarkupCanvas,
|
|
16
17
|
config: Required<MarkupCanvasConfig>,
|
|
17
18
|
withControls: boolean = true
|
|
18
19
|
): MouseDragControls | (() => void) {
|
|
@@ -6,13 +6,14 @@ import { handleMouseMove } from "@/lib/events/mouse/handleMouseMove.js";
|
|
|
6
6
|
import { handleMouseUp } from "@/lib/events/mouse/handleMouseUp.js";
|
|
7
7
|
import { resetDragState } from "@/lib/events/utils/resetDragState.js";
|
|
8
8
|
import { updateCursor } from "@/lib/events/utils/updateCursor.js";
|
|
9
|
+
import type { MarkupCanvas } from "@/lib/MarkupCanvas.js";
|
|
9
10
|
import type { MouseDragControls } from "@/types/events.js";
|
|
10
|
-
import type {
|
|
11
|
+
import type { MarkupCanvasConfig } from "@/types/index.js";
|
|
11
12
|
|
|
12
|
-
export function setupMouseEvents(canvas:
|
|
13
|
-
export function setupMouseEvents(canvas:
|
|
13
|
+
export function setupMouseEvents(canvas: MarkupCanvas, config: Required<MarkupCanvasConfig>, withControls: true): MouseDragControls;
|
|
14
|
+
export function setupMouseEvents(canvas: MarkupCanvas, config: Required<MarkupCanvasConfig>, withControls: false): () => void;
|
|
14
15
|
export function setupMouseEvents(
|
|
15
|
-
canvas:
|
|
16
|
+
canvas: MarkupCanvas,
|
|
16
17
|
config: Required<MarkupCanvasConfig>,
|
|
17
18
|
withControls: boolean = true
|
|
18
19
|
): MouseDragControls | (() => void) {
|
|
@@ -75,6 +75,16 @@ export function setupPostMessageEvents(canvas: MarkupCanvas): () => void {
|
|
|
75
75
|
const currentConfig = canvas.getConfig();
|
|
76
76
|
const newMode = currentConfig.themeMode === "light" ? "dark" : "light";
|
|
77
77
|
canvas.updateThemeMode(newMode);
|
|
78
|
+
}
|
|
79
|
+
// Transition methods
|
|
80
|
+
else if (action === "updateTransition") {
|
|
81
|
+
const enabled = args[0] as boolean;
|
|
82
|
+
if (typeof enabled !== "boolean") {
|
|
83
|
+
throw new Error(`Invalid transition enabled value: ${enabled}. Must be a boolean.`);
|
|
84
|
+
}
|
|
85
|
+
canvas.updateTransition(enabled);
|
|
86
|
+
} else if (action === "toggleTransitionMode") {
|
|
87
|
+
canvas.toggleTransitionMode();
|
|
78
88
|
} else {
|
|
79
89
|
throw new Error(`Unknown action: ${action}`);
|
|
80
90
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { getTouchCenter } from "@/lib/events/touch/getTouchCenter.js";
|
|
2
2
|
import { getTouchDistance } from "@/lib/events/touch/getTouchDistance.js";
|
|
3
3
|
import { withRAFThrottle, withRulerOffsetObject } from "@/lib/helpers/index.js";
|
|
4
|
+
import type { MarkupCanvas } from "@/lib/MarkupCanvas.js";
|
|
4
5
|
import { applyZoomToCanvas } from "@/lib/transform/applyZoomToCanvas.js";
|
|
5
|
-
import type {
|
|
6
|
+
import type { TouchState, Transform } from "@/types/index.js";
|
|
6
7
|
|
|
7
|
-
export function handleTouchMove(event: TouchEvent, canvas:
|
|
8
|
+
export function handleTouchMove(event: TouchEvent, canvas: MarkupCanvas, touchState: TouchState): void {
|
|
8
9
|
event.preventDefault();
|
|
9
10
|
|
|
10
11
|
const currentTouches = Array.from(event.touches);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { handleTouchEnd } from "@/lib/events/touch/handleTouchEnd.js";
|
|
2
2
|
import { handleTouchMove } from "@/lib/events/touch/handleTouchMove.js";
|
|
3
3
|
import { handleTouchStart } from "@/lib/events/touch/handleTouchStart.js";
|
|
4
|
-
import type {
|
|
4
|
+
import type { MarkupCanvas } from "@/lib/MarkupCanvas.js";
|
|
5
|
+
import type { TouchState } from "@/types/index.js";
|
|
5
6
|
|
|
6
|
-
export function setupTouchEvents(canvas:
|
|
7
|
+
export function setupTouchEvents(canvas: MarkupCanvas): () => void {
|
|
7
8
|
const touchState: TouchState = {
|
|
8
9
|
touches: [],
|
|
9
10
|
lastDistance: 0,
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { withRAFThrottle } from "@/lib/helpers/index.js";
|
|
2
|
+
import type { MarkupCanvas } from "@/lib/MarkupCanvas.js";
|
|
2
3
|
import { disableTransition } from "@/lib/transition";
|
|
3
|
-
import type {
|
|
4
|
+
import type { Transform } from "@/types";
|
|
4
5
|
|
|
5
|
-
export const createTrackpadPanHandler = (canvas:
|
|
6
|
+
export const createTrackpadPanHandler = (canvas: MarkupCanvas) =>
|
|
6
7
|
withRAFThrottle((...args: unknown[]) => {
|
|
7
8
|
const event = args[0] as WheelEvent;
|
|
8
9
|
if (!event || !canvas?.updateTransform) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ADAPTIVE_ZOOM_FACTOR, REFERENCE_DISPLAY_AREA } from "@/lib/events/constants.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { MarkupCanvas } from "@/lib/MarkupCanvas.js";
|
|
3
3
|
|
|
4
|
-
export function getAdaptiveZoomSpeed(canvas:
|
|
4
|
+
export function getAdaptiveZoomSpeed(canvas: MarkupCanvas, baseSpeed: number): number {
|
|
5
5
|
if (!canvas?.getBounds) {
|
|
6
6
|
return baseSpeed;
|
|
7
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MarkupCanvas } from "@/lib/MarkupCanvas.js";
|
|
2
2
|
|
|
3
|
-
export function getViewportCenter(canvas:
|
|
3
|
+
export function getViewportCenter(canvas: MarkupCanvas): { x: number; y: number } {
|
|
4
4
|
try {
|
|
5
5
|
const bounds = canvas.getBounds();
|
|
6
6
|
return {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { updateCursor } from "@/lib/events/utils/updateCursor.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { MarkupCanvas } from "@/lib/MarkupCanvas.js";
|
|
3
|
+
import type { MarkupCanvasConfig } from "@/types/index.js";
|
|
3
4
|
|
|
4
5
|
export function resetDragState(
|
|
5
|
-
canvas:
|
|
6
|
+
canvas: MarkupCanvas,
|
|
6
7
|
config: Required<MarkupCanvasConfig>,
|
|
7
8
|
isDragEnabled: boolean,
|
|
8
9
|
isSpacePressed: boolean,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MarkupCanvas } from "@/lib/MarkupCanvas.js";
|
|
2
|
+
import type { MarkupCanvasConfig } from "@/types/index.js";
|
|
2
3
|
|
|
3
4
|
export function updateCursor(
|
|
4
|
-
canvas:
|
|
5
|
+
canvas: MarkupCanvas,
|
|
5
6
|
config: Required<MarkupCanvasConfig>,
|
|
6
7
|
isDragEnabled: boolean,
|
|
7
8
|
isSpacePressed: boolean,
|
|
@@ -2,10 +2,11 @@ import { TRACKPAD_PINCH_SPEED_FACTOR } from "@/lib/events/constants.js";
|
|
|
2
2
|
import { detectTrackpadGesture } from "@/lib/events/trackpad/detectTrackpadGesture.js";
|
|
3
3
|
import { getAdaptiveZoomSpeed } from "@/lib/events/utils/getAdaptiveZoomSpeed.js";
|
|
4
4
|
import { withRulerOffset } from "@/lib/helpers/index.js";
|
|
5
|
+
import type { MarkupCanvas } from "@/lib/MarkupCanvas.js";
|
|
5
6
|
import { applyZoomToCanvas } from "@/lib/transform/applyZoomToCanvas.js";
|
|
6
|
-
import type {
|
|
7
|
+
import type { MarkupCanvasConfig } from "@/types/index.js";
|
|
7
8
|
|
|
8
|
-
export function handleWheel(event: WheelEvent, canvas:
|
|
9
|
+
export function handleWheel(event: WheelEvent, canvas: MarkupCanvas, config: Required<MarkupCanvasConfig>): boolean {
|
|
9
10
|
if (!event || typeof event.deltaY !== "number") {
|
|
10
11
|
console.warn("Invalid wheel event provided");
|
|
11
12
|
return false;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createTrackpadPanHandler } from "@/lib/events/trackpad/createTrackpadPanHandler";
|
|
2
2
|
import { detectTrackpadGesture } from "@/lib/events/trackpad/detectTrackpadGesture";
|
|
3
3
|
import { handleWheel } from "@/lib/events/wheel/handleWheel";
|
|
4
|
-
import type {
|
|
4
|
+
import type { MarkupCanvas } from "@/lib/MarkupCanvas.js";
|
|
5
|
+
import type { MarkupCanvasConfig } from "@/types";
|
|
5
6
|
|
|
6
|
-
export function setupWheelEvents(canvas:
|
|
7
|
+
export function setupWheelEvents(canvas: MarkupCanvas, config: Required<MarkupCanvasConfig>): () => void {
|
|
7
8
|
const trackpadPanHandler = createTrackpadPanHandler(canvas);
|
|
8
9
|
|
|
9
10
|
const wheelHandler = (event: WheelEvent) => {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createTrackpadPanHandler } from "@/lib/events/trackpad/createTrackpadPanHandler";
|
|
2
2
|
import { detectTrackpadGesture } from "@/lib/events/trackpad/detectTrackpadGesture";
|
|
3
3
|
import { handleWheel } from "@/lib/events/wheel/handleWheel";
|
|
4
|
-
import type {
|
|
4
|
+
import type { MarkupCanvas } from "@/lib/MarkupCanvas.js";
|
|
5
|
+
import type { MarkupCanvasConfig } from "@/types";
|
|
5
6
|
|
|
6
|
-
export function setupWheelEvents(canvas:
|
|
7
|
+
export function setupWheelEvents(canvas: MarkupCanvas, config: Required<MarkupCanvasConfig>): () => void {
|
|
7
8
|
const trackpadPanHandler = createTrackpadPanHandler(canvas);
|
|
8
9
|
|
|
9
10
|
const wheelHandler = (event: WheelEvent) => {
|
package/src/lib/helpers/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { getVisibleArea } from "./getVisibleArea.js";
|
|
2
|
+
export { isPointVisible } from "./isPointVisible.js";
|
|
1
3
|
export { withClampedZoom } from "./withClampedZoom.js";
|
|
2
4
|
export { withDebounce } from "./withDebounce.js";
|
|
3
5
|
export { withFeatureEnabled } from "./withFeatureEnabled.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MarkupCanvas } from "@/lib/MarkupCanvas.js";
|
|
2
|
+
import { getVisibleArea } from "./getVisibleArea.js";
|
|
3
|
+
|
|
4
|
+
export function isPointVisible(canvas: MarkupCanvas, x: number, y: number): boolean {
|
|
5
|
+
const visibleArea = getVisibleArea(canvas);
|
|
6
|
+
return x >= visibleArea.x && x <= visibleArea.x + visibleArea.width && y >= visibleArea.y && y <= visibleArea.y + visibleArea.height;
|
|
7
|
+
}
|
|
@@ -56,7 +56,6 @@ export function createRulers(canvas: Canvas, config: Required<MarkupCanvasConfig
|
|
|
56
56
|
if (elements.horizontalRuler) elements.horizontalRuler.style.display = "block";
|
|
57
57
|
if (elements.verticalRuler) elements.verticalRuler.style.display = "block";
|
|
58
58
|
if (elements.cornerBox) elements.cornerBox.style.display = "flex";
|
|
59
|
-
if (elements.gridOverlay) elements.gridOverlay.style.display = "block";
|
|
60
59
|
},
|
|
61
60
|
|
|
62
61
|
hide: () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import type { MarkupCanvas } from "@/lib/MarkupCanvas.js";
|
|
1
2
|
import { getZoomToMouseTransform } from "@/lib/matrix";
|
|
2
|
-
import type { Canvas } from "@/types";
|
|
3
3
|
|
|
4
|
-
export function applyZoomToCanvas(canvas:
|
|
4
|
+
export function applyZoomToCanvas(canvas: MarkupCanvas, rawZoomFactor: number, centerX: number, centerY: number): boolean {
|
|
5
5
|
const newTransform = getZoomToMouseTransform(centerX, centerY, canvas.transform, rawZoomFactor, canvas.config);
|
|
6
6
|
return canvas.updateTransform(newTransform);
|
|
7
7
|
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { MarkupCanvas } from "@/lib/MarkupCanvas.js";
|
|
2
|
+
import type { MarkupCanvasConfig, WindowAPI } from "@/types/index.js";
|
|
3
|
+
|
|
4
|
+
export function bindCanvasToWindow(canvas: MarkupCanvas, config: Required<MarkupCanvasConfig>): void {
|
|
5
|
+
if (typeof window === "undefined") {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const canvasName = config.name || "markupCanvas";
|
|
10
|
+
const windowObj = window as unknown as Record<string, unknown>;
|
|
11
|
+
|
|
12
|
+
const api: WindowAPI = {
|
|
13
|
+
config: {
|
|
14
|
+
get current() {
|
|
15
|
+
return canvas.config;
|
|
16
|
+
},
|
|
17
|
+
get: canvas.getConfig.bind(canvas),
|
|
18
|
+
update: canvas.updateConfig.bind(canvas),
|
|
19
|
+
},
|
|
20
|
+
// Transform group
|
|
21
|
+
transform: {
|
|
22
|
+
update: canvas.updateTransform.bind(canvas),
|
|
23
|
+
reset: canvas.reset.bind(canvas),
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
// Zoom group
|
|
27
|
+
zoom: {
|
|
28
|
+
set: canvas.setZoom.bind(canvas),
|
|
29
|
+
toPoint: canvas.zoomToPoint.bind(canvas),
|
|
30
|
+
in: canvas.zoomIn.bind(canvas),
|
|
31
|
+
out: canvas.zoomOut.bind(canvas),
|
|
32
|
+
reset: canvas.resetZoom.bind(canvas),
|
|
33
|
+
resetToCenter: canvas.resetViewToCenter.bind(canvas),
|
|
34
|
+
fitToScreen: canvas.fitToScreen.bind(canvas),
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
// Pan group
|
|
38
|
+
pan: {
|
|
39
|
+
left: canvas.panLeft.bind(canvas),
|
|
40
|
+
right: canvas.panRight.bind(canvas),
|
|
41
|
+
up: canvas.panUp.bind(canvas),
|
|
42
|
+
down: canvas.panDown.bind(canvas),
|
|
43
|
+
toPoint: canvas.scrollToPoint.bind(canvas),
|
|
44
|
+
toCenter: canvas.centerContent.bind(canvas),
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
// Mouse drag group
|
|
48
|
+
mouseDrag: {
|
|
49
|
+
enable: canvas.enableMouseDrag.bind(canvas),
|
|
50
|
+
disable: canvas.disableMouseDrag.bind(canvas),
|
|
51
|
+
isEnabled: canvas.isMouseDragEnabled.bind(canvas),
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
// Grid group
|
|
55
|
+
grid: {
|
|
56
|
+
toggle: canvas.toggleGrid.bind(canvas),
|
|
57
|
+
show: canvas.showGrid.bind(canvas),
|
|
58
|
+
hide: canvas.hideGrid.bind(canvas),
|
|
59
|
+
isVisible: canvas.isGridVisible.bind(canvas),
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
// Ruler group
|
|
63
|
+
rulers: {
|
|
64
|
+
toggle: canvas.toggleRulers.bind(canvas),
|
|
65
|
+
show: canvas.showRulers.bind(canvas),
|
|
66
|
+
hide: canvas.hideRulers.bind(canvas),
|
|
67
|
+
isVisible: canvas.areRulersVisible.bind(canvas),
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
// Utility group
|
|
71
|
+
canvas: {
|
|
72
|
+
canvasToContent: canvas.canvasToContent.bind(canvas),
|
|
73
|
+
getVisibleArea: canvas.getVisibleArea.bind(canvas),
|
|
74
|
+
isPointVisible: canvas.isPointVisible.bind(canvas),
|
|
75
|
+
getBounds: canvas.getBounds.bind(canvas),
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
theme: {
|
|
79
|
+
get current() {
|
|
80
|
+
return canvas.config.themeMode;
|
|
81
|
+
},
|
|
82
|
+
update: canvas.updateThemeMode.bind(canvas),
|
|
83
|
+
toggle: canvas.toggleThemeMode.bind(canvas),
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
transition: {
|
|
87
|
+
get current() {
|
|
88
|
+
return canvas.config.enableTransition;
|
|
89
|
+
},
|
|
90
|
+
set: canvas.updateTransition.bind(canvas),
|
|
91
|
+
toggle: canvas.toggleTransitionMode.bind(canvas),
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
// Event group
|
|
95
|
+
event: canvas.event,
|
|
96
|
+
|
|
97
|
+
// Lifecycle group
|
|
98
|
+
lifecycle: {
|
|
99
|
+
cleanup: canvas.cleanup.bind(canvas),
|
|
100
|
+
destroy: canvas.destroy.bind(canvas),
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
// Properties/State group
|
|
104
|
+
state: {
|
|
105
|
+
get isReady() {
|
|
106
|
+
return canvas.isReady;
|
|
107
|
+
},
|
|
108
|
+
get isTransforming() {
|
|
109
|
+
return canvas.isTransforming;
|
|
110
|
+
},
|
|
111
|
+
get visibleBounds() {
|
|
112
|
+
return canvas.visibleBounds;
|
|
113
|
+
},
|
|
114
|
+
get transform() {
|
|
115
|
+
return canvas.transform;
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// Bind public API to window
|
|
121
|
+
windowObj[canvasName] = api;
|
|
122
|
+
|
|
123
|
+
// Track all instances
|
|
124
|
+
if (!windowObj.__markupCanvasInstances) {
|
|
125
|
+
windowObj.__markupCanvasInstances = new Map();
|
|
126
|
+
}
|
|
127
|
+
(windowObj.__markupCanvasInstances as unknown as Map<string, unknown>).set(canvasName, api);
|
|
128
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { MarkupCanvasConfig } from "@/types/index.js";
|
|
2
|
+
|
|
3
|
+
export function broadcastEvent(event: string, data: unknown, config: Required<MarkupCanvasConfig>): void {
|
|
4
|
+
if (typeof window === "undefined") {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// Receivers can get the instance from the window binding
|
|
9
|
+
let broadcastData = data;
|
|
10
|
+
|
|
11
|
+
if (event === "ready") {
|
|
12
|
+
broadcastData = { ready: true };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
window.postMessage(
|
|
16
|
+
{
|
|
17
|
+
source: "markup-canvas",
|
|
18
|
+
event,
|
|
19
|
+
data: broadcastData,
|
|
20
|
+
timestamp: Date.now(),
|
|
21
|
+
canvasName: config.name,
|
|
22
|
+
},
|
|
23
|
+
"*"
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
if (window.parent) {
|
|
27
|
+
window.parent.postMessage(
|
|
28
|
+
{
|
|
29
|
+
source: "markup-canvas",
|
|
30
|
+
event,
|
|
31
|
+
data: broadcastData,
|
|
32
|
+
timestamp: Date.now(),
|
|
33
|
+
canvasName: config.name,
|
|
34
|
+
},
|
|
35
|
+
"*"
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { MarkupCanvasConfig } from "@/types/index.js";
|
|
2
|
+
|
|
3
|
+
export function cleanupWindowBinding(config: Required<MarkupCanvasConfig>): void {
|
|
4
|
+
if (typeof window === "undefined") {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const canvasName = config.name || "markupCanvas";
|
|
9
|
+
const windowObj = window as unknown as Record<string, unknown>;
|
|
10
|
+
|
|
11
|
+
delete windowObj[canvasName];
|
|
12
|
+
if (windowObj.__markupCanvasInstances) {
|
|
13
|
+
(windowObj.__markupCanvasInstances as unknown as Map<string, unknown>).delete(canvasName);
|
|
14
|
+
}
|
|
15
|
+
}
|
package/src/types/canvas.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { MarkupCanvasConfig } from "./config";
|
|
2
|
-
|
|
3
1
|
export interface Transform {
|
|
4
2
|
scale: number;
|
|
5
3
|
translateX: number;
|
|
@@ -11,7 +9,6 @@ export interface CanvasOptions {
|
|
|
11
9
|
height?: number;
|
|
12
10
|
enableAcceleration?: boolean;
|
|
13
11
|
enableEventHandling?: boolean;
|
|
14
|
-
onTransformUpdate?: (transform: Transform) => void;
|
|
15
12
|
}
|
|
16
13
|
|
|
17
14
|
export interface CanvasBounds {
|
|
@@ -38,53 +35,9 @@ export interface CanvasBounds {
|
|
|
38
35
|
canZoomOut: boolean;
|
|
39
36
|
}
|
|
40
37
|
|
|
41
|
-
export interface
|
|
38
|
+
export interface Canvas {
|
|
42
39
|
container: HTMLElement;
|
|
43
40
|
transformLayer: HTMLElement;
|
|
44
41
|
contentLayer: HTMLElement;
|
|
45
|
-
config: Required<MarkupCanvasConfig>;
|
|
46
42
|
transform: Transform;
|
|
47
|
-
getBounds: () => CanvasBounds;
|
|
48
|
-
updateTransform: (newTransform: Partial<Transform>) => boolean;
|
|
49
|
-
reset: () => boolean;
|
|
50
|
-
handleResize: () => boolean;
|
|
51
|
-
setZoom: (zoomLevel: number) => boolean;
|
|
52
|
-
canvasToContent: (x: number, y: number) => { x: number; y: number };
|
|
53
|
-
zoomToPoint: (x: number, y: number, targetScale: number) => boolean;
|
|
54
|
-
resetView: () => boolean;
|
|
55
|
-
zoomToFitContent: () => boolean;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Legacy Canvas interface - kept for backwards compatibility with other parts of the codebase
|
|
59
|
-
export interface Canvas extends BaseCanvas {
|
|
60
|
-
cleanup?: () => void;
|
|
61
|
-
// Exposed control functions for custom keyboard implementation
|
|
62
|
-
panLeft: (distance?: number) => boolean;
|
|
63
|
-
panRight: (distance?: number) => boolean;
|
|
64
|
-
panUp: (distance?: number) => boolean;
|
|
65
|
-
panDown: (distance?: number) => boolean;
|
|
66
|
-
zoomIn: (factor?: number) => boolean;
|
|
67
|
-
zoomOut: (factor?: number) => boolean;
|
|
68
|
-
resetZoom: (duration?: number) => boolean;
|
|
69
|
-
resetViewToCenter: () => boolean;
|
|
70
|
-
// Mouse drag control functions
|
|
71
|
-
enableMouseDrag: () => boolean;
|
|
72
|
-
disableMouseDrag: () => boolean;
|
|
73
|
-
isMouseDragEnabled: () => boolean;
|
|
74
|
-
// Grid control functions
|
|
75
|
-
toggleGrid?: () => boolean;
|
|
76
|
-
showGrid?: () => boolean;
|
|
77
|
-
hideGrid?: () => boolean;
|
|
78
|
-
isGridVisible?: () => boolean;
|
|
79
|
-
// Ruler control functions
|
|
80
|
-
toggleRulers?: () => boolean;
|
|
81
|
-
showRulers?: () => boolean;
|
|
82
|
-
hideRulers?: () => boolean;
|
|
83
|
-
areRulersVisible?: () => boolean;
|
|
84
|
-
// Additional utility functions
|
|
85
|
-
centerContent: () => boolean;
|
|
86
|
-
fitToScreen: () => boolean;
|
|
87
|
-
getVisibleArea: () => { x: number; y: number; width: number; height: number };
|
|
88
|
-
isPointVisible: (x: number, y: number) => boolean;
|
|
89
|
-
scrollToPoint: (x: number, y: number, duration?: number) => boolean;
|
|
90
43
|
}
|
package/src/types/config.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import type { Transform } from "./canvas";
|
|
2
|
-
|
|
3
1
|
export interface MarkupCanvasConfig {
|
|
4
2
|
// Canvas dimensions
|
|
5
3
|
width?: number;
|
|
6
4
|
height?: number;
|
|
7
5
|
enableAcceleration?: boolean;
|
|
8
6
|
|
|
9
|
-
// Global
|
|
10
|
-
bindToWindow?: boolean;
|
|
7
|
+
// Global Instance Access
|
|
11
8
|
name?: string;
|
|
12
9
|
|
|
13
10
|
// Post Message API
|
|
@@ -71,7 +68,4 @@ export interface MarkupCanvasConfig {
|
|
|
71
68
|
|
|
72
69
|
// Theme
|
|
73
70
|
themeMode?: "light" | "dark";
|
|
74
|
-
|
|
75
|
-
// Callbacks
|
|
76
|
-
onTransformUpdate?: (transform: Transform) => void;
|
|
77
71
|
}
|
package/src/types/events.ts
CHANGED
|
@@ -6,6 +6,8 @@ export interface MarkupCanvasEvents {
|
|
|
6
6
|
zoom: number;
|
|
7
7
|
pan: { x: number; y: number };
|
|
8
8
|
ready: MarkupCanvas;
|
|
9
|
+
rulersVisibility: boolean;
|
|
10
|
+
gridVisibility: boolean;
|
|
9
11
|
[key: string]: unknown;
|
|
10
12
|
}
|
|
11
13
|
|
|
@@ -50,7 +52,9 @@ export type PostMessageAction =
|
|
|
50
52
|
| "showGrid"
|
|
51
53
|
| "hideGrid"
|
|
52
54
|
| "updateThemeMode"
|
|
53
|
-
| "toggleThemeMode"
|
|
55
|
+
| "toggleThemeMode"
|
|
56
|
+
| "updateTransition"
|
|
57
|
+
| "toggleTransitionMode";
|
|
54
58
|
|
|
55
59
|
export interface PostMessageRequest {
|
|
56
60
|
source: "markup-canvas";
|
|
@@ -58,3 +62,5 @@ export interface PostMessageRequest {
|
|
|
58
62
|
action: PostMessageAction;
|
|
59
63
|
args?: unknown[];
|
|
60
64
|
}
|
|
65
|
+
|
|
66
|
+
export type CallbackEventName = "transform" | "zoom" | "pan" | "ready" | "rulersVisibility" | "gridVisibility";
|