@markup-canvas/core 1.0.3 → 1.0.5
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 +2 -1
- package/dist/lib/config/presets/editor-preset.d.ts +2 -0
- package/dist/lib/config/presets/index.d.ts +1 -0
- package/dist/lib/helpers/withRulerCheck.d.ts +4 -4
- package/dist/lib/helpers/withRulerOffset.d.ts +1 -1
- package/dist/lib/rulers/constants.d.ts +0 -1
- package/dist/lib/rulers/createCornerBox.d.ts +2 -2
- package/dist/lib/rulers/createGridOverlay.d.ts +2 -2
- package/dist/lib/rulers/createHorizontalRuler.d.ts +2 -2
- package/dist/lib/rulers/createRulerElements.d.ts +2 -3
- package/dist/lib/rulers/createVerticalRuler.d.ts +2 -2
- package/dist/lib/rulers/index.d.ts +1 -1
- package/dist/lib/rulers/ticks/createHorizontalTick.d.ts +2 -2
- package/dist/lib/rulers/ticks/createVerticalTick.d.ts +2 -2
- package/dist/lib/rulers/updateHorizontalRuler.d.ts +2 -2
- package/dist/lib/rulers/updateRulers.d.ts +2 -2
- package/dist/lib/rulers/updateVerticalRuler.d.ts +2 -2
- package/dist/markup-canvas.cjs.js +136 -94
- package/dist/markup-canvas.esm.js +136 -95
- package/dist/markup-canvas.umd.js +87 -94
- package/dist/markup-canvas.umd.min.js +1 -1
- package/dist/types/config.d.ts +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/rulers.d.ts +6 -12
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/lib/canvas/createCanvas.ts +1 -2
- package/src/lib/canvas/getCanvasBounds.ts +2 -2
- package/src/lib/canvas/getCanvasMethods.ts +1 -3
- package/src/lib/canvas/setupTransformLayer.ts +1 -2
- package/src/lib/config/constants.ts +2 -1
- package/src/lib/config/createMarkupCanvasConfig.ts +5 -0
- package/src/lib/config/presets/editor-preset.ts +57 -0
- package/src/lib/config/presets/index.ts +1 -0
- package/src/lib/events/keyboard/setupKeyboardEvents.ts +1 -1
- package/src/lib/events/keyboard/setupKeyboardNavigation.ts +1 -1
- package/src/lib/events/mouse/handleClickToZoom.ts +1 -1
- package/src/lib/events/touch/handleTouchMove.ts +1 -1
- package/src/lib/events/wheel/handleWheel.ts +1 -1
- package/src/lib/helpers/withRulerCheck.ts +9 -8
- package/src/lib/helpers/withRulerOffset.ts +3 -4
- package/src/lib/matrix/getZoomToMouseTransform.ts +1 -2
- package/src/lib/rulers/constants.ts +0 -2
- package/src/lib/rulers/createCornerBox.ts +12 -12
- package/src/lib/rulers/createGridOverlay.ts +5 -5
- package/src/lib/rulers/createHorizontalRuler.ts +11 -11
- package/src/lib/rulers/createRulerElements.ts +3 -4
- package/src/lib/rulers/createRulers.ts +3 -16
- package/src/lib/rulers/createVerticalRuler.ts +11 -11
- package/src/lib/rulers/index.ts +1 -1
- package/src/lib/rulers/ticks/createHorizontalTick.ts +6 -5
- package/src/lib/rulers/ticks/createVerticalTick.ts +6 -5
- package/src/lib/rulers/updateHorizontalRuler.ts +2 -2
- package/src/lib/rulers/updateRulers.ts +4 -5
- package/src/lib/rulers/updateVerticalRuler.ts +2 -2
- package/src/types/config.ts +1 -0
- package/src/types/index.ts +1 -1
- package/src/types/rulers.ts +6 -13
- package/dist/lib/rulers/RulerElements.d.ts +0 -6
- package/src/lib/rulers/RulerElements.ts +0 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
export { EDITOR_PRESET } from "./lib/config/presets";
|
|
1
2
|
export { MarkupCanvas, MarkupCanvas as default } from "./lib/MarkupCanvas.js";
|
|
2
|
-
export type { BaseCanvas, Canvas, CanvasBounds, CanvasOptions, GestureInfo, MarkupCanvasConfig, MarkupCanvasEvents, MouseDragControls, Point, RulerCanvas,
|
|
3
|
+
export type { BaseCanvas, Canvas, CanvasBounds, CanvasOptions, GestureInfo, MarkupCanvasConfig, MarkupCanvasEvents, MouseDragControls, Point, RulerCanvas, RulerSystem, TouchState, Transform, ZoomBoundaryOptions, ZoomBoundaryResult, } from "./types/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { EDITOR_PRESET } from "./editor-preset.js";
|
|
@@ -3,16 +3,16 @@ export declare function withRulerCheck<T>(canvas: {
|
|
|
3
3
|
}, operation: (hasRulers: boolean) => T): T;
|
|
4
4
|
export declare function withRulerSize<T>(canvas: {
|
|
5
5
|
container: HTMLElement;
|
|
6
|
-
}, operation: (rulerSize: number) => T): T;
|
|
6
|
+
}, rulerSize: number, operation: (rulerSize: number) => T): T;
|
|
7
7
|
export declare function withRulerAdjustment(canvas: {
|
|
8
8
|
container: HTMLElement;
|
|
9
|
-
}, value: number, operation?: (adjustedValue: number) => void): number;
|
|
9
|
+
}, rulerSize: number, value: number, operation?: (adjustedValue: number) => void): number;
|
|
10
10
|
export declare function withRulerOffsets<T>(canvas: {
|
|
11
11
|
container: HTMLElement;
|
|
12
|
-
}, x: number, y: number, operation: (adjustedX: number, adjustedY: number) => T): T;
|
|
12
|
+
}, rulerSize: number, x: number, y: number, operation: (adjustedX: number, adjustedY: number) => T): T;
|
|
13
13
|
export declare function withRulerOffsetObject<T, C extends {
|
|
14
14
|
x: number;
|
|
15
15
|
y: number;
|
|
16
16
|
}>(canvas: {
|
|
17
17
|
container: HTMLElement;
|
|
18
|
-
}, coords: C, operation: (adjusted: C) => T): T;
|
|
18
|
+
}, rulerSize: number, coords: C, operation: (adjusted: C) => T): T;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function createCornerBox(config: Required<
|
|
1
|
+
import type { MarkupCanvasConfig } from "@/types/index.js";
|
|
2
|
+
export declare function createCornerBox(config: Required<MarkupCanvasConfig>): HTMLElement;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function createGridOverlay(config: Required<
|
|
1
|
+
import type { MarkupCanvasConfig } from "@/types/index.js";
|
|
2
|
+
export declare function createGridOverlay(config: Required<MarkupCanvasConfig>): HTMLElement;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function createHorizontalRuler(config: Required<
|
|
1
|
+
import type { MarkupCanvasConfig } from "@/types/index.js";
|
|
2
|
+
export declare function createHorizontalRuler(config: Required<MarkupCanvasConfig>): HTMLElement;
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export declare function createRulerElements(container: HTMLElement, config: Required<RulerOptions>): RulerElements;
|
|
1
|
+
import type { MarkupCanvasConfig, RulerElements } from "@/types/index.js";
|
|
2
|
+
export declare function createRulerElements(container: HTMLElement, config: Required<MarkupCanvasConfig>): RulerElements;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function createVerticalRuler(config: Required<
|
|
1
|
+
import type { MarkupCanvasConfig } from "@/types/index.js";
|
|
2
|
+
export declare function createVerticalRuler(config: Required<MarkupCanvasConfig>): HTMLElement;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type {
|
|
1
|
+
export type { RulerSystem } from "@/types/index.js";
|
|
2
2
|
export { createRulers } from "./createRulers.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function createHorizontalTick(container: HTMLElement | DocumentFragment, position: number, pixelPos: number, tickSpacing: number, config: Required<
|
|
1
|
+
import type { MarkupCanvasConfig } from "@/types/index.js";
|
|
2
|
+
export declare function createHorizontalTick(container: HTMLElement | DocumentFragment, position: number, pixelPos: number, tickSpacing: number, config: Required<MarkupCanvasConfig>): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function createVerticalTick(container: HTMLElement | DocumentFragment, position: number, pixelPos: number, tickSpacing: number, config: Required<
|
|
1
|
+
import type { MarkupCanvasConfig } from "@/types/index.js";
|
|
2
|
+
export declare function createVerticalTick(container: HTMLElement | DocumentFragment, position: number, pixelPos: number, tickSpacing: number, config: Required<MarkupCanvasConfig>): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function updateHorizontalRuler(ruler: HTMLElement, contentLeft: number, contentRight: number, canvasWidth: number, scale: number, config: Required<
|
|
1
|
+
import type { MarkupCanvasConfig } from "@/types/index.js";
|
|
2
|
+
export declare function updateHorizontalRuler(ruler: HTMLElement, contentLeft: number, contentRight: number, canvasWidth: number, scale: number, config: Required<MarkupCanvasConfig>): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { RulerCanvas as Canvas,
|
|
2
|
-
export declare function updateRulers(canvas: Canvas, horizontalRuler: HTMLElement, verticalRuler: HTMLElement, gridOverlay: HTMLElement | undefined, config: Required<
|
|
1
|
+
import type { RulerCanvas as Canvas, MarkupCanvasConfig } from "@/types/index.js";
|
|
2
|
+
export declare function updateRulers(canvas: Canvas, horizontalRuler: HTMLElement, verticalRuler: HTMLElement, gridOverlay: HTMLElement | undefined, config: Required<MarkupCanvasConfig>): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function updateVerticalRuler(ruler: HTMLElement, contentTop: number, contentBottom: number, canvasHeight: number, scale: number, config: Required<
|
|
1
|
+
import type { MarkupCanvasConfig } from "@/types/index.js";
|
|
2
|
+
export declare function updateVerticalRuler(ruler: HTMLElement, contentTop: number, contentBottom: number, canvasHeight: number, scale: number, config: Required<MarkupCanvasConfig>): void;
|
|
@@ -1,12 +1,60 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Markup Canvas
|
|
3
3
|
* High-performance markup canvas with zoom and pan capabilities
|
|
4
|
-
* @version 1.0.
|
|
4
|
+
* @version 1.0.5
|
|
5
5
|
*/
|
|
6
6
|
'use strict';
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
9
9
|
|
|
10
|
+
const EDITOR_PRESET = {
|
|
11
|
+
// Canvas dimensions
|
|
12
|
+
width: 4000,
|
|
13
|
+
height: 4000,
|
|
14
|
+
enableAcceleration: true,
|
|
15
|
+
// Interaction controls
|
|
16
|
+
enableZoom: true,
|
|
17
|
+
enablePan: true,
|
|
18
|
+
enableTouch: true,
|
|
19
|
+
enableKeyboard: false,
|
|
20
|
+
limitKeyboardEventsToCanvas: false,
|
|
21
|
+
// Zoom behavior
|
|
22
|
+
zoomSpeed: 1.5,
|
|
23
|
+
minZoom: 0.05,
|
|
24
|
+
maxZoom: 80,
|
|
25
|
+
enableTransition: false,
|
|
26
|
+
transitionDuration: 0.2,
|
|
27
|
+
enableAdaptiveSpeed: true,
|
|
28
|
+
// Pan behavior
|
|
29
|
+
enableLeftDrag: true,
|
|
30
|
+
enableMiddleDrag: true,
|
|
31
|
+
requireSpaceForMouseDrag: true,
|
|
32
|
+
// Keyboard behavior
|
|
33
|
+
keyboardPanStep: 50,
|
|
34
|
+
keyboardFastMultiplier: 20,
|
|
35
|
+
keyboardZoomStep: 0.2,
|
|
36
|
+
// Click-to-zoom
|
|
37
|
+
enableClickToZoom: true,
|
|
38
|
+
clickZoomLevel: 1.0,
|
|
39
|
+
requireOptionForClickZoom: true,
|
|
40
|
+
// Visual elements
|
|
41
|
+
enableRulers: true,
|
|
42
|
+
enableGrid: false,
|
|
43
|
+
gridColor: "rgba(0, 123, 255, 0.1)",
|
|
44
|
+
// Ruler styling
|
|
45
|
+
rulerBackgroundColor: "rgba(255, 255, 255, 0.4)",
|
|
46
|
+
rulerBorderColor: "#ddd",
|
|
47
|
+
rulerTextColor: "oklch(70.5% 0.015 286.067)",
|
|
48
|
+
rulerMajorTickColor: "oklch(87.1% 0.006 286.286)",
|
|
49
|
+
rulerMinorTickColor: "oklch(92% 0.004 286.32)",
|
|
50
|
+
rulerFontSize: 9,
|
|
51
|
+
rulerFontFamily: "Monaco, Menlo, monospace",
|
|
52
|
+
rulerUnits: "px",
|
|
53
|
+
rulerSize: 20,
|
|
54
|
+
// Callbacks
|
|
55
|
+
onTransformUpdate: () => { },
|
|
56
|
+
};
|
|
57
|
+
|
|
10
58
|
// Default transform values
|
|
11
59
|
const DEFAULT_ZOOM = 1.0;
|
|
12
60
|
// Validation thresholds
|
|
@@ -35,31 +83,10 @@ function setupContentLayer(contentLayer) {
|
|
|
35
83
|
contentLayer.style.pointerEvents = "auto";
|
|
36
84
|
}
|
|
37
85
|
|
|
38
|
-
// Rulers
|
|
39
|
-
const RULER_SIZE = 24;
|
|
40
|
-
const RULER_Z_INDEX = {
|
|
41
|
-
GRID: 100,
|
|
42
|
-
RULERS: 1000,
|
|
43
|
-
CORNER: 1001,
|
|
44
|
-
};
|
|
45
|
-
const TICK_SETTINGS = {
|
|
46
|
-
MAJOR_HEIGHT: 6,
|
|
47
|
-
MINOR_HEIGHT: 4,
|
|
48
|
-
MAJOR_WIDTH: 8,
|
|
49
|
-
MINOR_WIDTH: 4,
|
|
50
|
-
MAJOR_MULTIPLIER: 5,
|
|
51
|
-
LABEL_INTERVAL: 100,
|
|
52
|
-
};
|
|
53
|
-
const GRID_SETTINGS = {
|
|
54
|
-
BASE_SIZE: 100,
|
|
55
|
-
MIN_SIZE: 20,
|
|
56
|
-
MAX_SIZE: 200,
|
|
57
|
-
};
|
|
58
|
-
|
|
59
86
|
// Sets up the transform layer with proper styles and dimensions
|
|
60
87
|
function setupTransformLayer(transformLayer, config) {
|
|
61
88
|
transformLayer.style.position = "absolute";
|
|
62
|
-
const rulerOffset =
|
|
89
|
+
const rulerOffset = config.rulerSize;
|
|
63
90
|
transformLayer.style.top = `${rulerOffset}px`;
|
|
64
91
|
transformLayer.style.left = `${rulerOffset}px`;
|
|
65
92
|
transformLayer.style.width = `${config.width}px`;
|
|
@@ -118,7 +145,7 @@ function createMatrix(scale, translateX, translateY) {
|
|
|
118
145
|
}
|
|
119
146
|
|
|
120
147
|
function getZoomToMouseTransform(mouseX, mouseY, currentTransform, zoomFactor, config) {
|
|
121
|
-
const rulerOffset = config.enableRulers ? -
|
|
148
|
+
const rulerOffset = config.enableRulers ? -config.rulerSize : 0;
|
|
122
149
|
const transform = currentTransform || {
|
|
123
150
|
scale: DEFAULT_ZOOM,
|
|
124
151
|
translateX: rulerOffset,
|
|
@@ -228,20 +255,20 @@ function withRAFThrottle(func) {
|
|
|
228
255
|
return throttled;
|
|
229
256
|
}
|
|
230
257
|
|
|
231
|
-
function withRulerSize(canvas, operation) {
|
|
258
|
+
function withRulerSize(canvas, rulerSize, operation) {
|
|
232
259
|
const hasRulers = canvas.container.querySelector(".canvas-ruler") !== null;
|
|
233
|
-
const
|
|
234
|
-
return operation(
|
|
260
|
+
const finalRulerSize = hasRulers ? rulerSize : 0;
|
|
261
|
+
return operation(finalRulerSize);
|
|
235
262
|
}
|
|
236
|
-
function withRulerOffsets(canvas, x, y, operation) {
|
|
237
|
-
return withRulerSize(canvas, (rulerSize) => {
|
|
263
|
+
function withRulerOffsets(canvas, rulerSize, x, y, operation) {
|
|
264
|
+
return withRulerSize(canvas, rulerSize, (rulerSize) => {
|
|
238
265
|
const adjustedX = x - rulerSize;
|
|
239
266
|
const adjustedY = y - rulerSize;
|
|
240
267
|
return operation(adjustedX, adjustedY);
|
|
241
268
|
});
|
|
242
269
|
}
|
|
243
|
-
function withRulerOffsetObject(canvas, coords, operation) {
|
|
244
|
-
return withRulerSize(canvas, (rulerSize) => {
|
|
270
|
+
function withRulerOffsetObject(canvas, rulerSize, coords, operation) {
|
|
271
|
+
return withRulerSize(canvas, rulerSize, (rulerSize) => {
|
|
245
272
|
const adjusted = {
|
|
246
273
|
...coords,
|
|
247
274
|
x: coords.x - rulerSize,
|
|
@@ -251,10 +278,10 @@ function withRulerOffsetObject(canvas, coords, operation) {
|
|
|
251
278
|
});
|
|
252
279
|
}
|
|
253
280
|
|
|
254
|
-
function withRulerOffset(canvas, x, y, operation) {
|
|
281
|
+
function withRulerOffset(canvas, x, y, rulerSize, operation) {
|
|
255
282
|
const hasRulers = canvas.container.querySelector(".canvas-ruler") !== null;
|
|
256
|
-
const adjustedX = hasRulers ? x -
|
|
257
|
-
const adjustedY = hasRulers ? y -
|
|
283
|
+
const adjustedX = hasRulers ? x - rulerSize : x;
|
|
284
|
+
const adjustedY = hasRulers ? y - rulerSize : y;
|
|
258
285
|
return operation(adjustedX, adjustedY);
|
|
259
286
|
}
|
|
260
287
|
|
|
@@ -298,9 +325,10 @@ const DEFAULT_CONFIG = {
|
|
|
298
325
|
rulerTextColor: "#666",
|
|
299
326
|
rulerMajorTickColor: "#999",
|
|
300
327
|
rulerMinorTickColor: "#ccc",
|
|
301
|
-
rulerFontSize:
|
|
328
|
+
rulerFontSize: 9,
|
|
302
329
|
rulerFontFamily: "Monaco, Menlo, monospace",
|
|
303
330
|
rulerUnits: "px",
|
|
331
|
+
rulerSize: 20,
|
|
304
332
|
// Callbacks
|
|
305
333
|
onTransformUpdate: () => { },
|
|
306
334
|
};
|
|
@@ -319,8 +347,8 @@ function getCanvasBounds(canvas) {
|
|
|
319
347
|
const totalWidth = containerRect.width || container.clientWidth || 0;
|
|
320
348
|
const totalHeight = containerRect.height || container.clientHeight || 0;
|
|
321
349
|
// Calculate canvas dimensions accounting for rulers
|
|
322
|
-
const canvasWidth = withRulerSize({ container }, (rulerSize) => Math.max(0, totalWidth - rulerSize));
|
|
323
|
-
const canvasHeight = withRulerSize({ container }, (rulerSize) => Math.max(0, totalHeight - rulerSize));
|
|
350
|
+
const canvasWidth = withRulerSize({ container }, config.rulerSize, (rulerSize) => Math.max(0, totalWidth - rulerSize));
|
|
351
|
+
const canvasHeight = withRulerSize({ container }, config.rulerSize, (rulerSize) => Math.max(0, totalHeight - rulerSize));
|
|
324
352
|
// Get content dimensions
|
|
325
353
|
const contentWidth = config.width || DEFAULT_CONFIG.width;
|
|
326
354
|
const contentHeight = config.height || DEFAULT_CONFIG.height;
|
|
@@ -467,7 +495,6 @@ function getCanvasMethods() {
|
|
|
467
495
|
},
|
|
468
496
|
// Handle canvas resize
|
|
469
497
|
handleResize: function () {
|
|
470
|
-
this.container.getBoundingClientRect();
|
|
471
498
|
return true;
|
|
472
499
|
},
|
|
473
500
|
// Set zoom level
|
|
@@ -490,7 +517,7 @@ function getCanvasMethods() {
|
|
|
490
517
|
// Reset view with animation
|
|
491
518
|
resetView: function () {
|
|
492
519
|
return withTransition(this.transformLayer, this.config, () => {
|
|
493
|
-
return withRulerSize(this, (rulerSize) => {
|
|
520
|
+
return withRulerSize(this, this.config.rulerSize, (rulerSize) => {
|
|
494
521
|
const resetTransform = {
|
|
495
522
|
scale: 1.0,
|
|
496
523
|
translateX: rulerSize * -1,
|
|
@@ -563,7 +590,7 @@ function createCanvas(container, config) {
|
|
|
563
590
|
if (config.enableAcceleration) {
|
|
564
591
|
enableHardwareAcceleration(transformLayer);
|
|
565
592
|
}
|
|
566
|
-
const rulerOffset = config.enableRulers ? -
|
|
593
|
+
const rulerOffset = config.enableRulers ? -config.rulerSize : 0;
|
|
567
594
|
const initialTransform = {
|
|
568
595
|
scale: DEFAULT_ZOOM,
|
|
569
596
|
translateX: rulerOffset,
|
|
@@ -633,6 +660,10 @@ function createMarkupCanvasConfig(options = {}) {
|
|
|
633
660
|
console.warn("Invalid rulerFontSize, using default");
|
|
634
661
|
config.rulerFontSize = DEFAULT_CONFIG.rulerFontSize;
|
|
635
662
|
}
|
|
663
|
+
if (typeof config.rulerSize !== "number" || config.rulerSize <= 0) {
|
|
664
|
+
console.warn("Invalid rulerSize, using default");
|
|
665
|
+
config.rulerSize = DEFAULT_CONFIG.rulerSize;
|
|
666
|
+
}
|
|
636
667
|
return config;
|
|
637
668
|
}
|
|
638
669
|
|
|
@@ -703,7 +734,7 @@ function setupKeyboardEvents(canvas, config) {
|
|
|
703
734
|
const rect = canvas.container.getBoundingClientRect();
|
|
704
735
|
const rawMouseX = event.clientX - rect.left;
|
|
705
736
|
const rawMouseY = event.clientY - rect.top;
|
|
706
|
-
withRulerOffsets(canvas, rawMouseX, rawMouseY, (adjustedX, adjustedY) => {
|
|
737
|
+
withRulerOffsets(canvas, config.rulerSize, rawMouseX, rawMouseY, (adjustedX, adjustedY) => {
|
|
707
738
|
lastMouseX = adjustedX;
|
|
708
739
|
lastMouseY = adjustedY;
|
|
709
740
|
});
|
|
@@ -903,7 +934,7 @@ function handleClickToZoom(event, canvas, config, mouseDownTime, hasDragged, isD
|
|
|
903
934
|
const rect = canvas.container.getBoundingClientRect();
|
|
904
935
|
const rawClickX = event.clientX - rect.left;
|
|
905
936
|
const rawClickY = event.clientY - rect.top;
|
|
906
|
-
const { clickX, clickY } = withRulerOffset(canvas, rawClickX, rawClickY, (adjustedX, adjustedY) => ({
|
|
937
|
+
const { clickX, clickY } = withRulerOffset(canvas, rawClickX, rawClickY, config.rulerSize, (adjustedX, adjustedY) => ({
|
|
907
938
|
clickX: adjustedX,
|
|
908
939
|
clickY: adjustedY,
|
|
909
940
|
}));
|
|
@@ -1130,7 +1161,7 @@ function handleTouchMove(event, canvas, touchState) {
|
|
|
1130
1161
|
let centerX = currentCenter.x - rect.left;
|
|
1131
1162
|
let centerY = currentCenter.y - rect.top;
|
|
1132
1163
|
// Account for ruler offset if rulers are present
|
|
1133
|
-
const adjustedCenter = withRulerOffsetObject(canvas, { x: centerX, y: centerY }, (adjusted) => adjusted);
|
|
1164
|
+
const adjustedCenter = withRulerOffsetObject(canvas, canvas.config.rulerSize, { x: centerX, y: centerY }, (adjusted) => adjusted);
|
|
1134
1165
|
centerX = adjustedCenter.x;
|
|
1135
1166
|
centerY = adjustedCenter.y;
|
|
1136
1167
|
// Touch zoom uses global transition settings
|
|
@@ -1245,7 +1276,7 @@ function handleWheel(event, canvas, config) {
|
|
|
1245
1276
|
const rawMouseX = event.clientX - rect.left;
|
|
1246
1277
|
const rawMouseY = event.clientY - rect.top;
|
|
1247
1278
|
// Account for ruler offset
|
|
1248
|
-
const { mouseX, mouseY } = withRulerOffset(canvas, rawMouseX, rawMouseY, (adjustedX, adjustedY) => ({
|
|
1279
|
+
const { mouseX, mouseY } = withRulerOffset(canvas, rawMouseX, rawMouseY, config.rulerSize, (adjustedX, adjustedY) => ({
|
|
1249
1280
|
mouseX: adjustedX,
|
|
1250
1281
|
mouseY: adjustedY,
|
|
1251
1282
|
}));
|
|
@@ -1292,6 +1323,26 @@ function setupWheelEvents(canvas, config) {
|
|
|
1292
1323
|
};
|
|
1293
1324
|
}
|
|
1294
1325
|
|
|
1326
|
+
// Rulers
|
|
1327
|
+
const RULER_Z_INDEX = {
|
|
1328
|
+
GRID: 100,
|
|
1329
|
+
RULERS: 1000,
|
|
1330
|
+
CORNER: 1001,
|
|
1331
|
+
};
|
|
1332
|
+
const TICK_SETTINGS = {
|
|
1333
|
+
MAJOR_HEIGHT: 6,
|
|
1334
|
+
MINOR_HEIGHT: 4,
|
|
1335
|
+
MAJOR_WIDTH: 8,
|
|
1336
|
+
MINOR_WIDTH: 4,
|
|
1337
|
+
MAJOR_MULTIPLIER: 5,
|
|
1338
|
+
LABEL_INTERVAL: 100,
|
|
1339
|
+
};
|
|
1340
|
+
const GRID_SETTINGS = {
|
|
1341
|
+
BASE_SIZE: 100,
|
|
1342
|
+
MIN_SIZE: 20,
|
|
1343
|
+
MAX_SIZE: 200,
|
|
1344
|
+
};
|
|
1345
|
+
|
|
1295
1346
|
function createCornerBox(config) {
|
|
1296
1347
|
const corner = document.createElement("div");
|
|
1297
1348
|
corner.className = "canvas-ruler corner-box";
|
|
@@ -1299,21 +1350,21 @@ function createCornerBox(config) {
|
|
|
1299
1350
|
position: absolute;
|
|
1300
1351
|
top: 0;
|
|
1301
1352
|
left: 0;
|
|
1302
|
-
width: ${
|
|
1303
|
-
height: ${
|
|
1304
|
-
background: ${config.
|
|
1305
|
-
border-right: 1px solid ${config.
|
|
1306
|
-
border-bottom: 1px solid ${config.
|
|
1353
|
+
width: ${config.rulerSize}px;
|
|
1354
|
+
height: ${config.rulerSize}px;
|
|
1355
|
+
background: ${config.rulerBackgroundColor};
|
|
1356
|
+
border-right: 1px solid ${config.rulerBorderColor};
|
|
1357
|
+
border-bottom: 1px solid ${config.rulerBorderColor};
|
|
1307
1358
|
z-index: ${RULER_Z_INDEX.CORNER};
|
|
1308
1359
|
display: flex;
|
|
1309
1360
|
align-items: center;
|
|
1310
1361
|
justify-content: center;
|
|
1311
|
-
font-family: ${config.
|
|
1312
|
-
font-size: ${config.
|
|
1313
|
-
color: ${config.
|
|
1362
|
+
font-family: ${config.rulerFontFamily};
|
|
1363
|
+
font-size: ${config.rulerFontSize - 2}px;
|
|
1364
|
+
color: ${config.rulerTextColor};
|
|
1314
1365
|
pointer-events: none;
|
|
1315
1366
|
`;
|
|
1316
|
-
corner.textContent = config.
|
|
1367
|
+
corner.textContent = config.rulerUnits;
|
|
1317
1368
|
return corner;
|
|
1318
1369
|
}
|
|
1319
1370
|
|
|
@@ -1322,8 +1373,8 @@ function createGridOverlay(config) {
|
|
|
1322
1373
|
grid.className = "canvas-ruler grid-overlay";
|
|
1323
1374
|
grid.style.cssText = `
|
|
1324
1375
|
position: absolute;
|
|
1325
|
-
top: ${
|
|
1326
|
-
left: ${
|
|
1376
|
+
top: ${config.rulerSize}px;
|
|
1377
|
+
left: ${config.rulerSize}px;
|
|
1327
1378
|
right: 0;
|
|
1328
1379
|
bottom: 0;
|
|
1329
1380
|
pointer-events: none;
|
|
@@ -1343,17 +1394,17 @@ function createHorizontalRuler(config) {
|
|
|
1343
1394
|
ruler.style.cssText = `
|
|
1344
1395
|
position: absolute;
|
|
1345
1396
|
top: 0;
|
|
1346
|
-
left: ${
|
|
1397
|
+
left: ${config.rulerSize}px;
|
|
1347
1398
|
right: 0;
|
|
1348
|
-
height: ${
|
|
1349
|
-
background: ${config.
|
|
1350
|
-
border-bottom: 1px solid ${config.
|
|
1351
|
-
border-right: 1px solid ${config.
|
|
1399
|
+
height: ${config.rulerSize}px;
|
|
1400
|
+
background: ${config.rulerBackgroundColor};
|
|
1401
|
+
border-bottom: 1px solid ${config.rulerBorderColor};
|
|
1402
|
+
border-right: 1px solid ${config.rulerBorderColor};
|
|
1352
1403
|
z-index: ${RULER_Z_INDEX.RULERS};
|
|
1353
1404
|
pointer-events: none;
|
|
1354
|
-
font-family: ${config.
|
|
1355
|
-
font-size: ${config.
|
|
1356
|
-
color: ${config.
|
|
1405
|
+
font-family: ${config.rulerFontFamily};
|
|
1406
|
+
font-size: ${config.rulerFontSize}px;
|
|
1407
|
+
color: ${config.rulerTextColor};
|
|
1357
1408
|
overflow: hidden;
|
|
1358
1409
|
`;
|
|
1359
1410
|
return ruler;
|
|
@@ -1364,18 +1415,18 @@ function createVerticalRuler(config) {
|
|
|
1364
1415
|
ruler.className = "canvas-ruler vertical-ruler";
|
|
1365
1416
|
ruler.style.cssText = `
|
|
1366
1417
|
position: absolute;
|
|
1367
|
-
top: ${
|
|
1418
|
+
top: ${config.rulerSize}px;
|
|
1368
1419
|
left: 0;
|
|
1369
1420
|
bottom: 0;
|
|
1370
|
-
width: ${
|
|
1371
|
-
background: ${config.
|
|
1372
|
-
border-right: 1px solid ${config.
|
|
1373
|
-
border-bottom: 1px solid ${config.
|
|
1421
|
+
width: ${config.rulerSize}px;
|
|
1422
|
+
background: ${config.rulerBackgroundColor};
|
|
1423
|
+
border-right: 1px solid ${config.rulerBorderColor};
|
|
1424
|
+
border-bottom: 1px solid ${config.rulerBorderColor};
|
|
1374
1425
|
z-index: ${RULER_Z_INDEX.RULERS};
|
|
1375
1426
|
pointer-events: none;
|
|
1376
|
-
font-family: ${config.
|
|
1377
|
-
font-size: ${config.
|
|
1378
|
-
color: ${config.
|
|
1427
|
+
font-family: ${config.rulerFontFamily};
|
|
1428
|
+
font-size: ${config.rulerFontSize}px;
|
|
1429
|
+
color: ${config.rulerTextColor};
|
|
1379
1430
|
overflow: hidden;
|
|
1380
1431
|
`;
|
|
1381
1432
|
return ruler;
|
|
@@ -1385,7 +1436,7 @@ function createRulerElements(container, config) {
|
|
|
1385
1436
|
const horizontalRuler = createHorizontalRuler(config);
|
|
1386
1437
|
const verticalRuler = createVerticalRuler(config);
|
|
1387
1438
|
const cornerBox = createCornerBox(config);
|
|
1388
|
-
const gridOverlay = config.
|
|
1439
|
+
const gridOverlay = config.enableGrid ? createGridOverlay(config) : undefined;
|
|
1389
1440
|
container.appendChild(horizontalRuler);
|
|
1390
1441
|
container.appendChild(verticalRuler);
|
|
1391
1442
|
container.appendChild(cornerBox);
|
|
@@ -1455,7 +1506,7 @@ function createHorizontalTick(container, position, pixelPos, tickSpacing, config
|
|
|
1455
1506
|
bottom: 0;
|
|
1456
1507
|
width: 1px;
|
|
1457
1508
|
height: ${tickHeight}px;
|
|
1458
|
-
background: ${isMajor ? config.
|
|
1509
|
+
background: ${isMajor ? config.rulerMajorTickColor : config.rulerMinorTickColor};
|
|
1459
1510
|
`;
|
|
1460
1511
|
container.appendChild(tick);
|
|
1461
1512
|
const shouldShowLabel = isMajor || position % TICK_SETTINGS.LABEL_INTERVAL === 0;
|
|
@@ -1465,8 +1516,9 @@ function createHorizontalTick(container, position, pixelPos, tickSpacing, config
|
|
|
1465
1516
|
position: absolute;
|
|
1466
1517
|
left: ${pixelPos}px;
|
|
1467
1518
|
bottom: ${tickHeight}px;
|
|
1468
|
-
font-size: ${config.
|
|
1469
|
-
|
|
1519
|
+
font-size: ${config.rulerFontSize}px;
|
|
1520
|
+
line-height: 1;
|
|
1521
|
+
color: ${config.rulerTextColor};
|
|
1470
1522
|
white-space: nowrap;
|
|
1471
1523
|
pointer-events: none;
|
|
1472
1524
|
`;
|
|
@@ -1502,7 +1554,7 @@ function createVerticalTick(container, position, pixelPos, tickSpacing, config)
|
|
|
1502
1554
|
right: 0;
|
|
1503
1555
|
width: ${tickWidth}px;
|
|
1504
1556
|
height: 1px;
|
|
1505
|
-
background: ${isMajor ? config.
|
|
1557
|
+
background: ${isMajor ? config.rulerMajorTickColor : config.rulerMinorTickColor};
|
|
1506
1558
|
`;
|
|
1507
1559
|
container.appendChild(tick);
|
|
1508
1560
|
const shouldShowLabel = isMajor || position % TICK_SETTINGS.LABEL_INTERVAL === 0;
|
|
@@ -1512,8 +1564,9 @@ function createVerticalTick(container, position, pixelPos, tickSpacing, config)
|
|
|
1512
1564
|
position: absolute;
|
|
1513
1565
|
top: ${pixelPos - 6}px;
|
|
1514
1566
|
right: ${tickWidth + 6}px;
|
|
1515
|
-
font-size: ${config.
|
|
1516
|
-
|
|
1567
|
+
font-size: ${config.rulerFontSize}px;
|
|
1568
|
+
line-height: 1;
|
|
1569
|
+
color: ${config.rulerTextColor};
|
|
1517
1570
|
white-space: nowrap;
|
|
1518
1571
|
pointer-events: none;
|
|
1519
1572
|
transform: rotate(-90deg);
|
|
@@ -1546,8 +1599,8 @@ function updateRulers(canvas, horizontalRuler, verticalRuler, gridOverlay, confi
|
|
|
1546
1599
|
const scale = bounds.scale || 1;
|
|
1547
1600
|
const translateX = bounds.translateX || 0;
|
|
1548
1601
|
const translateY = bounds.translateY || 0;
|
|
1549
|
-
const canvasWidth = bounds.width -
|
|
1550
|
-
const canvasHeight = bounds.height -
|
|
1602
|
+
const canvasWidth = bounds.width - config.rulerSize;
|
|
1603
|
+
const canvasHeight = bounds.height - config.rulerSize;
|
|
1551
1604
|
const contentLeft = -translateX / scale;
|
|
1552
1605
|
const contentTop = -translateY / scale;
|
|
1553
1606
|
const contentRight = contentLeft + canvasWidth / scale;
|
|
@@ -1567,25 +1620,13 @@ function createRulers(canvas, config) {
|
|
|
1567
1620
|
let elements;
|
|
1568
1621
|
let cleanupEvents = null;
|
|
1569
1622
|
let isDestroyed = false;
|
|
1570
|
-
const rulerOptions = {
|
|
1571
|
-
backgroundColor: config.rulerBackgroundColor,
|
|
1572
|
-
borderColor: config.rulerBorderColor,
|
|
1573
|
-
textColor: config.rulerTextColor,
|
|
1574
|
-
majorTickColor: config.rulerMajorTickColor,
|
|
1575
|
-
minorTickColor: config.rulerMinorTickColor,
|
|
1576
|
-
fontSize: config.rulerFontSize,
|
|
1577
|
-
fontFamily: config.rulerFontFamily,
|
|
1578
|
-
showGrid: config.enableGrid,
|
|
1579
|
-
gridColor: config.gridColor,
|
|
1580
|
-
units: config.rulerUnits,
|
|
1581
|
-
};
|
|
1582
1623
|
const safeUpdate = () => {
|
|
1583
1624
|
if (isDestroyed || !elements.horizontalRuler || !elements.verticalRuler)
|
|
1584
1625
|
return;
|
|
1585
|
-
updateRulers(canvas, elements.horizontalRuler, elements.verticalRuler, elements.gridOverlay,
|
|
1626
|
+
updateRulers(canvas, elements.horizontalRuler, elements.verticalRuler, elements.gridOverlay, config);
|
|
1586
1627
|
};
|
|
1587
1628
|
try {
|
|
1588
|
-
elements = createRulerElements(canvas.container,
|
|
1629
|
+
elements = createRulerElements(canvas.container, config);
|
|
1589
1630
|
cleanupEvents = setupRulerEvents(canvas, safeUpdate);
|
|
1590
1631
|
safeUpdate();
|
|
1591
1632
|
return {
|
|
@@ -1996,5 +2037,6 @@ class MarkupCanvas {
|
|
|
1996
2037
|
}
|
|
1997
2038
|
}
|
|
1998
2039
|
|
|
2040
|
+
exports.EDITOR_PRESET = EDITOR_PRESET;
|
|
1999
2041
|
exports.MarkupCanvas = MarkupCanvas;
|
|
2000
2042
|
exports.default = MarkupCanvas;
|