@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
package/src/types/index.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// Canvas types
|
|
2
2
|
export type {
|
|
3
|
-
BaseCanvas,
|
|
4
3
|
Canvas,
|
|
5
4
|
CanvasBounds,
|
|
6
5
|
CanvasOptions,
|
|
@@ -11,7 +10,7 @@ export type {
|
|
|
11
10
|
export type { MarkupCanvasConfig } from "./config.js";
|
|
12
11
|
|
|
13
12
|
// Event types
|
|
14
|
-
export type { GestureInfo, MarkupCanvasEvents, MouseDragControls, TouchState } from "./events.js";
|
|
13
|
+
export type { CallbackEventName, GestureInfo, MarkupCanvasEvents, MouseDragControls, TouchState } from "./events.js";
|
|
15
14
|
|
|
16
15
|
// Matrix types
|
|
17
16
|
export type {
|
|
@@ -26,3 +25,6 @@ export type {
|
|
|
26
25
|
RulerElements,
|
|
27
26
|
RulerSystem,
|
|
28
27
|
} from "./rulers.js";
|
|
28
|
+
|
|
29
|
+
// Window API types
|
|
30
|
+
export type { WindowAPI } from "./window.js";
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { EventEmitter } from "@/lib/events/EventEmitter.js";
|
|
2
|
+
import type { CanvasBounds, Transform } from "./canvas.js";
|
|
3
|
+
import type { MarkupCanvasConfig } from "./config.js";
|
|
4
|
+
import type { MarkupCanvasEvents } from "./events.js";
|
|
5
|
+
|
|
6
|
+
export interface WindowAPI {
|
|
7
|
+
config: {
|
|
8
|
+
readonly current: MarkupCanvasConfig;
|
|
9
|
+
readonly get: () => MarkupCanvasConfig;
|
|
10
|
+
readonly update: (config: Partial<MarkupCanvasConfig>) => void;
|
|
11
|
+
};
|
|
12
|
+
transform: {
|
|
13
|
+
readonly update: (transform: Transform) => void;
|
|
14
|
+
readonly reset: () => void;
|
|
15
|
+
};
|
|
16
|
+
zoom: {
|
|
17
|
+
readonly set: (zoomLevel: number) => void;
|
|
18
|
+
readonly toPoint: (x: number, y: number, zoomLevel: number) => void;
|
|
19
|
+
readonly in: (factor?: number) => void;
|
|
20
|
+
readonly out: (factor?: number) => void;
|
|
21
|
+
readonly reset: () => void;
|
|
22
|
+
readonly resetToCenter: () => void;
|
|
23
|
+
readonly fitToScreen: () => void;
|
|
24
|
+
};
|
|
25
|
+
pan: {
|
|
26
|
+
readonly left: (distance?: number) => void;
|
|
27
|
+
readonly right: (distance?: number) => void;
|
|
28
|
+
readonly up: (distance?: number) => void;
|
|
29
|
+
readonly down: (distance?: number) => void;
|
|
30
|
+
readonly toPoint: (x: number, y: number) => void;
|
|
31
|
+
readonly toCenter: () => void;
|
|
32
|
+
};
|
|
33
|
+
mouseDrag: {
|
|
34
|
+
readonly enable: () => void;
|
|
35
|
+
readonly disable: () => void;
|
|
36
|
+
isEnabled: () => boolean;
|
|
37
|
+
};
|
|
38
|
+
grid: {
|
|
39
|
+
readonly toggle: () => void;
|
|
40
|
+
readonly show: () => void;
|
|
41
|
+
readonly hide: () => void;
|
|
42
|
+
readonly isVisible: () => boolean;
|
|
43
|
+
};
|
|
44
|
+
rulers: {
|
|
45
|
+
readonly toggle: () => void;
|
|
46
|
+
readonly show: () => void;
|
|
47
|
+
readonly hide: () => void;
|
|
48
|
+
readonly isVisible: () => boolean;
|
|
49
|
+
};
|
|
50
|
+
canvas: {
|
|
51
|
+
readonly canvasToContent: (x: number, y: number) => { x: number; y: number };
|
|
52
|
+
readonly getVisibleArea: () => { x: number; y: number; width: number; height: number };
|
|
53
|
+
readonly isPointVisible: (x: number, y: number) => boolean;
|
|
54
|
+
readonly getBounds: () => CanvasBounds;
|
|
55
|
+
};
|
|
56
|
+
theme: {
|
|
57
|
+
readonly current: "light" | "dark";
|
|
58
|
+
readonly update: (mode: "light" | "dark") => void;
|
|
59
|
+
readonly toggle: () => "light" | "dark";
|
|
60
|
+
};
|
|
61
|
+
transition: {
|
|
62
|
+
readonly current: boolean;
|
|
63
|
+
readonly set: (enabled: boolean) => void;
|
|
64
|
+
readonly toggle: () => boolean;
|
|
65
|
+
};
|
|
66
|
+
event: EventEmitter<MarkupCanvasEvents>;
|
|
67
|
+
lifecycle: {
|
|
68
|
+
readonly cleanup: () => void;
|
|
69
|
+
readonly destroy: () => void;
|
|
70
|
+
};
|
|
71
|
+
state: {
|
|
72
|
+
readonly isReady: boolean;
|
|
73
|
+
readonly isTransforming: boolean;
|
|
74
|
+
readonly visibleBounds: Record<string, unknown>;
|
|
75
|
+
readonly transform: Transform;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { BaseCanvas, Transform } from "@/types/index.js";
|
|
2
|
-
export declare function getCanvasMethods(): {
|
|
3
|
-
getBounds: (this: BaseCanvas) => import("@/types/index.js").CanvasBounds;
|
|
4
|
-
updateTransform: (this: BaseCanvas, newTransform: Partial<Transform>) => boolean;
|
|
5
|
-
reset: (this: BaseCanvas) => boolean;
|
|
6
|
-
handleResize: (this: BaseCanvas) => boolean;
|
|
7
|
-
setZoom: (this: BaseCanvas, zoomLevel: number) => boolean;
|
|
8
|
-
canvasToContent: (this: BaseCanvas, x: number, y: number) => import("@/types/index.js").Point;
|
|
9
|
-
zoomToPoint: (this: BaseCanvas, x: number, y: number, targetScale: number) => boolean;
|
|
10
|
-
resetView: (this: BaseCanvas) => boolean;
|
|
11
|
-
zoomToFitContent: (this: BaseCanvas) => boolean;
|
|
12
|
-
};
|
package/src/lib/canvas/config.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { CanvasOptions } from "@/types/index.js";
|
|
2
|
-
|
|
3
|
-
const DEFAULT_CANVAS_WIDTH = 8000;
|
|
4
|
-
const DEFAULT_CANVAS_HEIGHT = 8000;
|
|
5
|
-
|
|
6
|
-
// Creates a validated configuration object with defaults
|
|
7
|
-
export function createCanvasConfig(options: CanvasOptions = {}): Required<CanvasOptions> {
|
|
8
|
-
const config: Required<CanvasOptions> = {
|
|
9
|
-
width: DEFAULT_CANVAS_WIDTH,
|
|
10
|
-
height: DEFAULT_CANVAS_HEIGHT,
|
|
11
|
-
enableAcceleration: true,
|
|
12
|
-
enableEventHandling: true,
|
|
13
|
-
onTransformUpdate: () => {},
|
|
14
|
-
...options,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// Validate and fix configuration values
|
|
18
|
-
if (typeof config.width !== "number" || config.width <= 0) {
|
|
19
|
-
console.warn("Invalid width, using default 8000px");
|
|
20
|
-
config.width = DEFAULT_CANVAS_WIDTH;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (typeof config.height !== "number" || config.height <= 0) {
|
|
24
|
-
console.warn("Invalid height, using default 8000px");
|
|
25
|
-
config.height = DEFAULT_CANVAS_HEIGHT;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return config;
|
|
29
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { getCanvasBounds } from "@/lib/canvas/getCanvasBounds.js";
|
|
2
|
-
import { ZOOM_FIT_PADDING } from "@/lib/constants.js";
|
|
3
|
-
import { withClampedZoom, withFeatureEnabled, withRulerSize } from "@/lib/helpers/index.js";
|
|
4
|
-
import { canvasToContent } from "@/lib/matrix/canvasToContent.js";
|
|
5
|
-
import { createMatrix } from "@/lib/matrix/createMatrix.js";
|
|
6
|
-
import { getZoomToMouseTransform } from "@/lib/matrix/getZoomToMouseTransform.js";
|
|
7
|
-
import { applyTransform } from "@/lib/transform/index.js";
|
|
8
|
-
import { withTransition } from "@/lib/transition/index.js";
|
|
9
|
-
import type { BaseCanvas, Transform } from "@/types/index.js";
|
|
10
|
-
|
|
11
|
-
export function getCanvasMethods() {
|
|
12
|
-
return {
|
|
13
|
-
// Utility methods
|
|
14
|
-
getBounds: function (this: BaseCanvas) {
|
|
15
|
-
return getCanvasBounds(this);
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
// Transform methods
|
|
19
|
-
updateTransform: function (this: BaseCanvas, newTransform: Partial<Transform>) {
|
|
20
|
-
this.transform = { ...this.transform, ...newTransform };
|
|
21
|
-
const matrix = createMatrix(this.transform.scale, this.transform.translateX, this.transform.translateY);
|
|
22
|
-
const result = applyTransform(this.transformLayer, matrix);
|
|
23
|
-
|
|
24
|
-
withFeatureEnabled(this.config, "onTransformUpdate", () => {
|
|
25
|
-
this.config.onTransformUpdate!(this.transform);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
return result;
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
// Reset method
|
|
32
|
-
reset: function (this: BaseCanvas) {
|
|
33
|
-
const resetTransform: Transform = {
|
|
34
|
-
scale: 1.0,
|
|
35
|
-
translateX: 0,
|
|
36
|
-
translateY: 0,
|
|
37
|
-
};
|
|
38
|
-
return this.updateTransform(resetTransform);
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
// Handle canvas resize
|
|
42
|
-
handleResize: function (this: BaseCanvas) {
|
|
43
|
-
return true;
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
// Set zoom level
|
|
47
|
-
setZoom: function (this: BaseCanvas, zoomLevel: number) {
|
|
48
|
-
const newScale = withClampedZoom(this.config, (clamp) => clamp(zoomLevel));
|
|
49
|
-
return this.updateTransform({ scale: newScale });
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
// Convert canvas coordinates to content coordinates
|
|
53
|
-
canvasToContent: function (this: BaseCanvas, x: number, y: number) {
|
|
54
|
-
const matrix = createMatrix(this.transform.scale, this.transform.translateX, this.transform.translateY);
|
|
55
|
-
return canvasToContent(x, y, matrix);
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
// Zoom to a specific point with animation
|
|
59
|
-
zoomToPoint: function (this: BaseCanvas, x: number, y: number, targetScale: number) {
|
|
60
|
-
return withTransition(this.transformLayer, this.config, () => {
|
|
61
|
-
const newTransform = getZoomToMouseTransform(x, y, this.transform, targetScale / this.transform.scale, this.config);
|
|
62
|
-
return this.updateTransform(newTransform);
|
|
63
|
-
});
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
// Reset view with animation
|
|
67
|
-
resetView: function (this: BaseCanvas) {
|
|
68
|
-
return withTransition(this.transformLayer, this.config, () => {
|
|
69
|
-
return withRulerSize(this, this.config.rulerSize, (rulerSize) => {
|
|
70
|
-
const resetTransform: Transform = {
|
|
71
|
-
scale: 1.0,
|
|
72
|
-
translateX: rulerSize * -1,
|
|
73
|
-
translateY: rulerSize * -1,
|
|
74
|
-
};
|
|
75
|
-
return this.updateTransform(resetTransform);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
},
|
|
79
|
-
|
|
80
|
-
// Zoom to fit content in canvas
|
|
81
|
-
zoomToFitContent: function (this: BaseCanvas) {
|
|
82
|
-
return withTransition(this.transformLayer, this.config, () => {
|
|
83
|
-
const bounds = this.getBounds();
|
|
84
|
-
const scaleX = bounds.width / this.config.width;
|
|
85
|
-
const scaleY = bounds.height / this.config.height;
|
|
86
|
-
const fitScale = withClampedZoom(this.config, (clamp) => clamp(Math.min(scaleX, scaleY) * ZOOM_FIT_PADDING));
|
|
87
|
-
|
|
88
|
-
// Center the content
|
|
89
|
-
const scaledWidth = this.config.width * fitScale;
|
|
90
|
-
const scaledHeight = this.config.height * fitScale;
|
|
91
|
-
const centerX = (bounds.width - scaledWidth) / 2;
|
|
92
|
-
const centerY = (bounds.height - scaledHeight) / 2;
|
|
93
|
-
|
|
94
|
-
return this.updateTransform({
|
|
95
|
-
scale: fitScale,
|
|
96
|
-
translateX: centerX,
|
|
97
|
-
translateY: centerY,
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
}
|
|
File without changes
|
|
File without changes
|