@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
|
@@ -40,8 +40,6 @@ export function getCanvasMethods() {
|
|
|
40
40
|
|
|
41
41
|
// Handle canvas resize
|
|
42
42
|
handleResize: function (this: BaseCanvas) {
|
|
43
|
-
const newRect = this.container.getBoundingClientRect();
|
|
44
|
-
|
|
45
43
|
return true;
|
|
46
44
|
},
|
|
47
45
|
|
|
@@ -68,7 +66,7 @@ export function getCanvasMethods() {
|
|
|
68
66
|
// Reset view with animation
|
|
69
67
|
resetView: function (this: BaseCanvas) {
|
|
70
68
|
return withTransition(this.transformLayer, this.config, () => {
|
|
71
|
-
return withRulerSize(this, (rulerSize) => {
|
|
69
|
+
return withRulerSize(this, this.config.rulerSize, (rulerSize) => {
|
|
72
70
|
const resetTransform: Transform = {
|
|
73
71
|
scale: 1.0,
|
|
74
72
|
translateX: rulerSize * -1,
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { RULER_SIZE } from "@/lib/rulers/constants";
|
|
2
1
|
import type { MarkupCanvasConfig } from "@/types";
|
|
3
2
|
|
|
4
3
|
// Sets up the transform layer with proper styles and dimensions
|
|
5
4
|
export function setupTransformLayer(transformLayer: HTMLElement, config: Required<MarkupCanvasConfig>): void {
|
|
6
5
|
transformLayer.style.position = "absolute";
|
|
7
6
|
|
|
8
|
-
const rulerOffset =
|
|
7
|
+
const rulerOffset = config.rulerSize;
|
|
9
8
|
|
|
10
9
|
transformLayer.style.top = `${rulerOffset}px`;
|
|
11
10
|
transformLayer.style.left = `${rulerOffset}px`;
|
|
@@ -47,9 +47,10 @@ export const DEFAULT_CONFIG: Required<MarkupCanvasConfig> = {
|
|
|
47
47
|
rulerTextColor: "#666",
|
|
48
48
|
rulerMajorTickColor: "#999",
|
|
49
49
|
rulerMinorTickColor: "#ccc",
|
|
50
|
-
rulerFontSize:
|
|
50
|
+
rulerFontSize: 9,
|
|
51
51
|
rulerFontFamily: "Monaco, Menlo, monospace",
|
|
52
52
|
rulerUnits: "px",
|
|
53
|
+
rulerSize: 20,
|
|
53
54
|
|
|
54
55
|
// Callbacks
|
|
55
56
|
onTransformUpdate: () => {},
|
|
@@ -52,5 +52,10 @@ export function createMarkupCanvasConfig(options: MarkupCanvasConfig = {}): Requ
|
|
|
52
52
|
config.rulerFontSize = DEFAULT_CONFIG.rulerFontSize;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
if (typeof config.rulerSize !== "number" || config.rulerSize <= 0) {
|
|
56
|
+
console.warn("Invalid rulerSize, using default");
|
|
57
|
+
config.rulerSize = DEFAULT_CONFIG.rulerSize;
|
|
58
|
+
}
|
|
59
|
+
|
|
55
60
|
return config;
|
|
56
61
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { MarkupCanvasConfig } from "@/types";
|
|
2
|
+
|
|
3
|
+
export const EDITOR_PRESET: Required<MarkupCanvasConfig> = {
|
|
4
|
+
// Canvas dimensions
|
|
5
|
+
width: 4000,
|
|
6
|
+
height: 4000,
|
|
7
|
+
enableAcceleration: true,
|
|
8
|
+
|
|
9
|
+
// Interaction controls
|
|
10
|
+
enableZoom: true,
|
|
11
|
+
enablePan: true,
|
|
12
|
+
enableTouch: true,
|
|
13
|
+
enableKeyboard: false,
|
|
14
|
+
limitKeyboardEventsToCanvas: false,
|
|
15
|
+
|
|
16
|
+
// Zoom behavior
|
|
17
|
+
zoomSpeed: 1.5,
|
|
18
|
+
minZoom: 0.05,
|
|
19
|
+
maxZoom: 80,
|
|
20
|
+
enableTransition: false,
|
|
21
|
+
transitionDuration: 0.2,
|
|
22
|
+
enableAdaptiveSpeed: true,
|
|
23
|
+
|
|
24
|
+
// Pan behavior
|
|
25
|
+
enableLeftDrag: true,
|
|
26
|
+
enableMiddleDrag: true,
|
|
27
|
+
requireSpaceForMouseDrag: true,
|
|
28
|
+
|
|
29
|
+
// Keyboard behavior
|
|
30
|
+
keyboardPanStep: 50,
|
|
31
|
+
keyboardFastMultiplier: 20,
|
|
32
|
+
keyboardZoomStep: 0.2,
|
|
33
|
+
|
|
34
|
+
// Click-to-zoom
|
|
35
|
+
enableClickToZoom: true,
|
|
36
|
+
clickZoomLevel: 1.0,
|
|
37
|
+
requireOptionForClickZoom: true,
|
|
38
|
+
|
|
39
|
+
// Visual elements
|
|
40
|
+
enableRulers: true,
|
|
41
|
+
enableGrid: false,
|
|
42
|
+
gridColor: "rgba(0, 123, 255, 0.1)",
|
|
43
|
+
|
|
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
|
+
|
|
55
|
+
// Callbacks
|
|
56
|
+
onTransformUpdate: () => {},
|
|
57
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { EDITOR_PRESET } from "./editor-preset.js";
|
|
@@ -14,7 +14,7 @@ export function setupKeyboardEvents(canvas: Canvas, config: Required<MarkupCanva
|
|
|
14
14
|
const rawMouseX = event.clientX - rect.left;
|
|
15
15
|
const rawMouseY = event.clientY - rect.top;
|
|
16
16
|
|
|
17
|
-
withRulerOffsets(canvas, rawMouseX, rawMouseY, (adjustedX, adjustedY) => {
|
|
17
|
+
withRulerOffsets(canvas, config.rulerSize, rawMouseX, rawMouseY, (adjustedX, adjustedY) => {
|
|
18
18
|
lastMouseX = adjustedX;
|
|
19
19
|
lastMouseY = adjustedY;
|
|
20
20
|
});
|
|
@@ -15,7 +15,7 @@ export function setupKeyboardEvents(canvas: Canvas, config: Required<MarkupCanva
|
|
|
15
15
|
const rawMouseY = event.clientY - rect.top;
|
|
16
16
|
|
|
17
17
|
// Use the new helper to adjust for ruler offset
|
|
18
|
-
withRulerOffsets(canvas, rawMouseX, rawMouseY, (adjustedX, adjustedY) => {
|
|
18
|
+
withRulerOffsets(canvas, config.rulerSize, rawMouseX, rawMouseY, (adjustedX, adjustedY) => {
|
|
19
19
|
lastMouseX = adjustedX;
|
|
20
20
|
lastMouseY = adjustedY;
|
|
21
21
|
});
|
|
@@ -24,7 +24,7 @@ export function handleClickToZoom(
|
|
|
24
24
|
const rawClickX = event.clientX - rect.left;
|
|
25
25
|
const rawClickY = event.clientY - rect.top;
|
|
26
26
|
|
|
27
|
-
const { clickX, clickY } = withRulerOffset(canvas, rawClickX, rawClickY, (adjustedX, adjustedY) => ({
|
|
27
|
+
const { clickX, clickY } = withRulerOffset(canvas, rawClickX, rawClickY, config.rulerSize, (adjustedX, adjustedY) => ({
|
|
28
28
|
clickX: adjustedX,
|
|
29
29
|
clickY: adjustedY,
|
|
30
30
|
}));
|
|
@@ -39,7 +39,7 @@ export function handleTouchMove(event: TouchEvent, canvas: Canvas, touchState: T
|
|
|
39
39
|
let centerY = currentCenter.y - rect.top;
|
|
40
40
|
|
|
41
41
|
// Account for ruler offset if rulers are present
|
|
42
|
-
const adjustedCenter = withRulerOffsetObject(canvas, { x: centerX, y: centerY }, (adjusted) => adjusted);
|
|
42
|
+
const adjustedCenter = withRulerOffsetObject(canvas, canvas.config.rulerSize, { x: centerX, y: centerY }, (adjusted) => adjusted);
|
|
43
43
|
centerX = adjustedCenter.x;
|
|
44
44
|
centerY = adjustedCenter.y;
|
|
45
45
|
|
|
@@ -25,7 +25,7 @@ export function handleWheel(event: WheelEvent, canvas: Canvas, config: Required<
|
|
|
25
25
|
const rawMouseY = event.clientY - rect.top;
|
|
26
26
|
|
|
27
27
|
// Account for ruler offset
|
|
28
|
-
const { mouseX, mouseY } = withRulerOffset(canvas, rawMouseX, rawMouseY, (adjustedX, adjustedY) => ({
|
|
28
|
+
const { mouseX, mouseY } = withRulerOffset(canvas, rawMouseX, rawMouseY, config.rulerSize, (adjustedX, adjustedY) => ({
|
|
29
29
|
mouseX: adjustedX,
|
|
30
30
|
mouseY: adjustedY,
|
|
31
31
|
}));
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
import { RULER_SIZE } from "../rulers/constants";
|
|
2
|
-
|
|
3
1
|
export function withRulerCheck<T>(canvas: { container: HTMLElement }, operation: (hasRulers: boolean) => T): T {
|
|
4
2
|
const hasRulers = canvas.container.querySelector(".canvas-ruler") !== null;
|
|
5
3
|
return operation(hasRulers);
|
|
6
4
|
}
|
|
7
5
|
|
|
8
|
-
export function withRulerSize<T>(canvas: { container: HTMLElement }, operation: (rulerSize: number) => T): T {
|
|
6
|
+
export function withRulerSize<T>(canvas: { container: HTMLElement }, rulerSize: number, operation: (rulerSize: number) => T): T {
|
|
9
7
|
const hasRulers = canvas.container.querySelector(".canvas-ruler") !== null;
|
|
10
|
-
const
|
|
11
|
-
return operation(
|
|
8
|
+
const finalRulerSize = hasRulers ? rulerSize : 0;
|
|
9
|
+
return operation(finalRulerSize);
|
|
12
10
|
}
|
|
13
11
|
|
|
14
12
|
export function withRulerAdjustment(
|
|
15
13
|
canvas: { container: HTMLElement },
|
|
14
|
+
rulerSize: number,
|
|
16
15
|
value: number,
|
|
17
16
|
operation?: (adjustedValue: number) => void
|
|
18
17
|
): number {
|
|
19
|
-
return withRulerSize(canvas, (rulerSize) => {
|
|
18
|
+
return withRulerSize(canvas, rulerSize, (rulerSize) => {
|
|
20
19
|
const adjusted = value - rulerSize;
|
|
21
20
|
operation?.(adjusted);
|
|
22
21
|
return adjusted;
|
|
@@ -25,11 +24,12 @@ export function withRulerAdjustment(
|
|
|
25
24
|
|
|
26
25
|
export function withRulerOffsets<T>(
|
|
27
26
|
canvas: { container: HTMLElement },
|
|
27
|
+
rulerSize: number,
|
|
28
28
|
x: number,
|
|
29
29
|
y: number,
|
|
30
30
|
operation: (adjustedX: number, adjustedY: number) => T
|
|
31
31
|
): T {
|
|
32
|
-
return withRulerSize(canvas, (rulerSize) => {
|
|
32
|
+
return withRulerSize(canvas, rulerSize, (rulerSize) => {
|
|
33
33
|
const adjustedX = x - rulerSize;
|
|
34
34
|
const adjustedY = y - rulerSize;
|
|
35
35
|
return operation(adjustedX, adjustedY);
|
|
@@ -38,10 +38,11 @@ export function withRulerOffsets<T>(
|
|
|
38
38
|
|
|
39
39
|
export function withRulerOffsetObject<T, C extends { x: number; y: number }>(
|
|
40
40
|
canvas: { container: HTMLElement },
|
|
41
|
+
rulerSize: number,
|
|
41
42
|
coords: C,
|
|
42
43
|
operation: (adjusted: C) => T
|
|
43
44
|
): T {
|
|
44
|
-
return withRulerSize(canvas, (rulerSize) => {
|
|
45
|
+
return withRulerSize(canvas, rulerSize, (rulerSize) => {
|
|
45
46
|
const adjusted = {
|
|
46
47
|
...coords,
|
|
47
48
|
x: coords.x - rulerSize,
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { RULER_SIZE } from "../rulers/constants";
|
|
2
|
-
|
|
3
1
|
export function withRulerOffset<T>(
|
|
4
2
|
canvas: { container: HTMLElement },
|
|
5
3
|
x: number,
|
|
6
4
|
y: number,
|
|
5
|
+
rulerSize: number,
|
|
7
6
|
operation: (adjustedX: number, adjustedY: number) => T
|
|
8
7
|
): T {
|
|
9
8
|
const hasRulers = canvas.container.querySelector(".canvas-ruler") !== null;
|
|
10
|
-
const adjustedX = hasRulers ? x -
|
|
11
|
-
const adjustedY = hasRulers ? y -
|
|
9
|
+
const adjustedX = hasRulers ? x - rulerSize : x;
|
|
10
|
+
const adjustedY = hasRulers ? y - rulerSize : y;
|
|
12
11
|
|
|
13
12
|
return operation(adjustedX, adjustedY);
|
|
14
13
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { DEFAULT_ZOOM, ZOOM_CHANGE_THRESHOLD } from "@/lib/constants.js";
|
|
2
2
|
import { clampZoom } from "@/lib/matrix/clampZoom.js";
|
|
3
3
|
import type { MarkupCanvasConfig, Transform } from "@/types/index.js";
|
|
4
|
-
import { RULER_SIZE } from "../rulers/constants";
|
|
5
4
|
|
|
6
5
|
export function getZoomToMouseTransform(
|
|
7
6
|
mouseX: number,
|
|
@@ -10,7 +9,7 @@ export function getZoomToMouseTransform(
|
|
|
10
9
|
zoomFactor: number,
|
|
11
10
|
config: Required<MarkupCanvasConfig>
|
|
12
11
|
): Transform {
|
|
13
|
-
const rulerOffset = config.enableRulers ? -
|
|
12
|
+
const rulerOffset = config.enableRulers ? -config.rulerSize : 0;
|
|
14
13
|
|
|
15
14
|
const transform = currentTransform || {
|
|
16
15
|
scale: DEFAULT_ZOOM,
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
1
|
+
import type { MarkupCanvasConfig } from "@/types/index.js";
|
|
2
|
+
import { RULER_Z_INDEX } from "./constants";
|
|
3
3
|
|
|
4
|
-
export function createCornerBox(config: Required<
|
|
4
|
+
export function createCornerBox(config: Required<MarkupCanvasConfig>): HTMLElement {
|
|
5
5
|
const corner = document.createElement("div");
|
|
6
6
|
corner.className = "canvas-ruler corner-box";
|
|
7
7
|
corner.style.cssText = `
|
|
8
8
|
position: absolute;
|
|
9
9
|
top: 0;
|
|
10
10
|
left: 0;
|
|
11
|
-
width: ${
|
|
12
|
-
height: ${
|
|
13
|
-
background: ${config.
|
|
14
|
-
border-right: 1px solid ${config.
|
|
15
|
-
border-bottom: 1px solid ${config.
|
|
11
|
+
width: ${config.rulerSize}px;
|
|
12
|
+
height: ${config.rulerSize}px;
|
|
13
|
+
background: ${config.rulerBackgroundColor};
|
|
14
|
+
border-right: 1px solid ${config.rulerBorderColor};
|
|
15
|
+
border-bottom: 1px solid ${config.rulerBorderColor};
|
|
16
16
|
z-index: ${RULER_Z_INDEX.CORNER};
|
|
17
17
|
display: flex;
|
|
18
18
|
align-items: center;
|
|
19
19
|
justify-content: center;
|
|
20
|
-
font-family: ${config.
|
|
21
|
-
font-size: ${config.
|
|
22
|
-
color: ${config.
|
|
20
|
+
font-family: ${config.rulerFontFamily};
|
|
21
|
+
font-size: ${config.rulerFontSize - 2}px;
|
|
22
|
+
color: ${config.rulerTextColor};
|
|
23
23
|
pointer-events: none;
|
|
24
24
|
`;
|
|
25
|
-
corner.textContent = config.
|
|
25
|
+
corner.textContent = config.rulerUnits;
|
|
26
26
|
return corner;
|
|
27
27
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
1
|
+
import type { MarkupCanvasConfig } from "@/types/index.js";
|
|
2
|
+
import { RULER_Z_INDEX } from "./constants";
|
|
3
3
|
|
|
4
|
-
export function createGridOverlay(config: Required<
|
|
4
|
+
export function createGridOverlay(config: Required<MarkupCanvasConfig>): HTMLElement {
|
|
5
5
|
const grid = document.createElement("div");
|
|
6
6
|
grid.className = "canvas-ruler grid-overlay";
|
|
7
7
|
grid.style.cssText = `
|
|
8
8
|
position: absolute;
|
|
9
|
-
top: ${
|
|
10
|
-
left: ${
|
|
9
|
+
top: ${config.rulerSize}px;
|
|
10
|
+
left: ${config.rulerSize}px;
|
|
11
11
|
right: 0;
|
|
12
12
|
bottom: 0;
|
|
13
13
|
pointer-events: none;
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
1
|
+
import type { MarkupCanvasConfig } from "@/types/index.js";
|
|
2
|
+
import { RULER_Z_INDEX } from "./constants";
|
|
3
3
|
|
|
4
|
-
export function createHorizontalRuler(config: Required<
|
|
4
|
+
export function createHorizontalRuler(config: Required<MarkupCanvasConfig>): HTMLElement {
|
|
5
5
|
const ruler = document.createElement("div");
|
|
6
6
|
ruler.className = "canvas-ruler horizontal-ruler";
|
|
7
7
|
ruler.style.cssText = `
|
|
8
8
|
position: absolute;
|
|
9
9
|
top: 0;
|
|
10
|
-
left: ${
|
|
10
|
+
left: ${config.rulerSize}px;
|
|
11
11
|
right: 0;
|
|
12
|
-
height: ${
|
|
13
|
-
background: ${config.
|
|
14
|
-
border-bottom: 1px solid ${config.
|
|
15
|
-
border-right: 1px solid ${config.
|
|
12
|
+
height: ${config.rulerSize}px;
|
|
13
|
+
background: ${config.rulerBackgroundColor};
|
|
14
|
+
border-bottom: 1px solid ${config.rulerBorderColor};
|
|
15
|
+
border-right: 1px solid ${config.rulerBorderColor};
|
|
16
16
|
z-index: ${RULER_Z_INDEX.RULERS};
|
|
17
17
|
pointer-events: none;
|
|
18
|
-
font-family: ${config.
|
|
19
|
-
font-size: ${config.
|
|
20
|
-
color: ${config.
|
|
18
|
+
font-family: ${config.rulerFontFamily};
|
|
19
|
+
font-size: ${config.rulerFontSize}px;
|
|
20
|
+
color: ${config.rulerTextColor};
|
|
21
21
|
overflow: hidden;
|
|
22
22
|
`;
|
|
23
23
|
return ruler;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MarkupCanvasConfig, RulerElements } from "@/types/index.js";
|
|
2
2
|
import { createCornerBox } from "./createCornerBox.js";
|
|
3
3
|
import { createGridOverlay } from "./createGridOverlay.js";
|
|
4
4
|
import { createHorizontalRuler } from "./createHorizontalRuler.js";
|
|
5
5
|
import { createVerticalRuler } from "./createVerticalRuler.js";
|
|
6
|
-
import type { RulerElements } from "./RulerElements.js";
|
|
7
6
|
|
|
8
|
-
export function createRulerElements(container: HTMLElement, config: Required<
|
|
7
|
+
export function createRulerElements(container: HTMLElement, config: Required<MarkupCanvasConfig>): RulerElements {
|
|
9
8
|
const horizontalRuler = createHorizontalRuler(config);
|
|
10
9
|
const verticalRuler = createVerticalRuler(config);
|
|
11
10
|
const cornerBox = createCornerBox(config);
|
|
12
|
-
const gridOverlay = config.
|
|
11
|
+
const gridOverlay = config.enableGrid ? createGridOverlay(config) : undefined;
|
|
13
12
|
|
|
14
13
|
container.appendChild(horizontalRuler);
|
|
15
14
|
container.appendChild(verticalRuler);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RulerCanvas as Canvas, MarkupCanvasConfig, RulerSystem } from "@/types/index.js";
|
|
2
|
+
import type { RulerElements } from "@/types/rulers.js";
|
|
2
3
|
import { createRulerElements } from "./createRulerElements.js";
|
|
3
|
-
import type { RulerElements } from "./RulerElements.js";
|
|
4
4
|
import { setupRulerEvents } from "./setupRulerEvents.js";
|
|
5
5
|
import { updateRulers } from "./updateRulers.js";
|
|
6
6
|
|
|
@@ -14,26 +14,13 @@ export function createRulers(canvas: Canvas, config: Required<MarkupCanvasConfig
|
|
|
14
14
|
let cleanupEvents: (() => void) | null = null;
|
|
15
15
|
let isDestroyed = false;
|
|
16
16
|
|
|
17
|
-
const rulerOptions = {
|
|
18
|
-
backgroundColor: config.rulerBackgroundColor,
|
|
19
|
-
borderColor: config.rulerBorderColor,
|
|
20
|
-
textColor: config.rulerTextColor,
|
|
21
|
-
majorTickColor: config.rulerMajorTickColor,
|
|
22
|
-
minorTickColor: config.rulerMinorTickColor,
|
|
23
|
-
fontSize: config.rulerFontSize,
|
|
24
|
-
fontFamily: config.rulerFontFamily,
|
|
25
|
-
showGrid: config.enableGrid,
|
|
26
|
-
gridColor: config.gridColor,
|
|
27
|
-
units: config.rulerUnits,
|
|
28
|
-
};
|
|
29
|
-
|
|
30
17
|
const safeUpdate = (): void => {
|
|
31
18
|
if (isDestroyed || !elements.horizontalRuler || !elements.verticalRuler) return;
|
|
32
|
-
updateRulers(canvas, elements.horizontalRuler, elements.verticalRuler, elements.gridOverlay,
|
|
19
|
+
updateRulers(canvas, elements.horizontalRuler, elements.verticalRuler, elements.gridOverlay, config);
|
|
33
20
|
};
|
|
34
21
|
|
|
35
22
|
try {
|
|
36
|
-
elements = createRulerElements(canvas.container,
|
|
23
|
+
elements = createRulerElements(canvas.container, config);
|
|
37
24
|
cleanupEvents = setupRulerEvents(canvas, safeUpdate);
|
|
38
25
|
|
|
39
26
|
safeUpdate();
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
1
|
+
import type { MarkupCanvasConfig } from "@/types/index.js";
|
|
2
|
+
import { RULER_Z_INDEX } from "./constants";
|
|
3
3
|
|
|
4
|
-
export function createVerticalRuler(config: Required<
|
|
4
|
+
export function createVerticalRuler(config: Required<MarkupCanvasConfig>): HTMLElement {
|
|
5
5
|
const ruler = document.createElement("div");
|
|
6
6
|
ruler.className = "canvas-ruler vertical-ruler";
|
|
7
7
|
ruler.style.cssText = `
|
|
8
8
|
position: absolute;
|
|
9
|
-
top: ${
|
|
9
|
+
top: ${config.rulerSize}px;
|
|
10
10
|
left: 0;
|
|
11
11
|
bottom: 0;
|
|
12
|
-
width: ${
|
|
13
|
-
background: ${config.
|
|
14
|
-
border-right: 1px solid ${config.
|
|
15
|
-
border-bottom: 1px solid ${config.
|
|
12
|
+
width: ${config.rulerSize}px;
|
|
13
|
+
background: ${config.rulerBackgroundColor};
|
|
14
|
+
border-right: 1px solid ${config.rulerBorderColor};
|
|
15
|
+
border-bottom: 1px solid ${config.rulerBorderColor};
|
|
16
16
|
z-index: ${RULER_Z_INDEX.RULERS};
|
|
17
17
|
pointer-events: none;
|
|
18
|
-
font-family: ${config.
|
|
19
|
-
font-size: ${config.
|
|
20
|
-
color: ${config.
|
|
18
|
+
font-family: ${config.rulerFontFamily};
|
|
19
|
+
font-size: ${config.rulerFontSize}px;
|
|
20
|
+
color: ${config.rulerTextColor};
|
|
21
21
|
overflow: hidden;
|
|
22
22
|
`;
|
|
23
23
|
return ruler;
|
package/src/lib/rulers/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type {
|
|
1
|
+
export type { RulerSystem } from "@/types/index.js";
|
|
2
2
|
export { createRulers } from "./createRulers.js";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { TICK_SETTINGS } from "@/lib/rulers/constants.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { MarkupCanvasConfig } from "@/types/index.js";
|
|
3
3
|
|
|
4
4
|
export function createHorizontalTick(
|
|
5
5
|
container: HTMLElement | DocumentFragment,
|
|
6
6
|
position: number,
|
|
7
7
|
pixelPos: number,
|
|
8
8
|
tickSpacing: number,
|
|
9
|
-
config: Required<
|
|
9
|
+
config: Required<MarkupCanvasConfig>
|
|
10
10
|
): void {
|
|
11
11
|
const tick = document.createElement("div");
|
|
12
12
|
const isMajor = position % (tickSpacing * TICK_SETTINGS.MAJOR_MULTIPLIER) === 0;
|
|
@@ -18,7 +18,7 @@ export function createHorizontalTick(
|
|
|
18
18
|
bottom: 0;
|
|
19
19
|
width: 1px;
|
|
20
20
|
height: ${tickHeight}px;
|
|
21
|
-
background: ${isMajor ? config.
|
|
21
|
+
background: ${isMajor ? config.rulerMajorTickColor : config.rulerMinorTickColor};
|
|
22
22
|
`;
|
|
23
23
|
|
|
24
24
|
container.appendChild(tick);
|
|
@@ -30,8 +30,9 @@ export function createHorizontalTick(
|
|
|
30
30
|
position: absolute;
|
|
31
31
|
left: ${pixelPos}px;
|
|
32
32
|
bottom: ${tickHeight}px;
|
|
33
|
-
font-size: ${config.
|
|
34
|
-
|
|
33
|
+
font-size: ${config.rulerFontSize}px;
|
|
34
|
+
line-height: 1;
|
|
35
|
+
color: ${config.rulerTextColor};
|
|
35
36
|
white-space: nowrap;
|
|
36
37
|
pointer-events: none;
|
|
37
38
|
`;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { TICK_SETTINGS } from "@/lib/rulers/constants.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { MarkupCanvasConfig } from "@/types/index.js";
|
|
3
3
|
|
|
4
4
|
export function createVerticalTick(
|
|
5
5
|
container: HTMLElement | DocumentFragment,
|
|
6
6
|
position: number,
|
|
7
7
|
pixelPos: number,
|
|
8
8
|
tickSpacing: number,
|
|
9
|
-
config: Required<
|
|
9
|
+
config: Required<MarkupCanvasConfig>
|
|
10
10
|
): void {
|
|
11
11
|
const tick = document.createElement("div");
|
|
12
12
|
const isMajor = position % (tickSpacing * TICK_SETTINGS.MAJOR_MULTIPLIER) === 0;
|
|
@@ -18,7 +18,7 @@ export function createVerticalTick(
|
|
|
18
18
|
right: 0;
|
|
19
19
|
width: ${tickWidth}px;
|
|
20
20
|
height: 1px;
|
|
21
|
-
background: ${isMajor ? config.
|
|
21
|
+
background: ${isMajor ? config.rulerMajorTickColor : config.rulerMinorTickColor};
|
|
22
22
|
`;
|
|
23
23
|
|
|
24
24
|
container.appendChild(tick);
|
|
@@ -30,8 +30,9 @@ export function createVerticalTick(
|
|
|
30
30
|
position: absolute;
|
|
31
31
|
top: ${pixelPos - 6}px;
|
|
32
32
|
right: ${tickWidth + 6}px;
|
|
33
|
-
font-size: ${config.
|
|
34
|
-
|
|
33
|
+
font-size: ${config.rulerFontSize}px;
|
|
34
|
+
line-height: 1;
|
|
35
|
+
color: ${config.rulerTextColor};
|
|
35
36
|
white-space: nowrap;
|
|
36
37
|
pointer-events: none;
|
|
37
38
|
transform: rotate(-90deg);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MarkupCanvasConfig } from "@/types/index.js";
|
|
2
2
|
import { calculateTickSpacing } from "./ticks/calculateTickSpacing.js";
|
|
3
3
|
import { createHorizontalTick } from "./ticks/createHorizontalTick.js";
|
|
4
4
|
|
|
@@ -8,7 +8,7 @@ export function updateHorizontalRuler(
|
|
|
8
8
|
contentRight: number,
|
|
9
9
|
canvasWidth: number,
|
|
10
10
|
scale: number,
|
|
11
|
-
config: Required<
|
|
11
|
+
config: Required<MarkupCanvasConfig>
|
|
12
12
|
): void {
|
|
13
13
|
const rulerWidth = canvasWidth;
|
|
14
14
|
const contentWidth = contentRight - contentLeft;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { updateGrid } from "@/lib/rulers/updateGrid.js";
|
|
2
|
-
import type { RulerCanvas as Canvas,
|
|
3
|
-
import { RULER_SIZE } from "./constants";
|
|
2
|
+
import type { RulerCanvas as Canvas, MarkupCanvasConfig } from "@/types/index.js";
|
|
4
3
|
import { updateHorizontalRuler } from "./updateHorizontalRuler.js";
|
|
5
4
|
import { updateVerticalRuler } from "./updateVerticalRuler.js";
|
|
6
5
|
|
|
@@ -9,15 +8,15 @@ export function updateRulers(
|
|
|
9
8
|
horizontalRuler: HTMLElement,
|
|
10
9
|
verticalRuler: HTMLElement,
|
|
11
10
|
gridOverlay: HTMLElement | undefined,
|
|
12
|
-
config: Required<
|
|
11
|
+
config: Required<MarkupCanvasConfig>
|
|
13
12
|
): void {
|
|
14
13
|
const bounds = canvas.getBounds();
|
|
15
14
|
const scale = bounds.scale || 1;
|
|
16
15
|
const translateX = bounds.translateX || 0;
|
|
17
16
|
const translateY = bounds.translateY || 0;
|
|
18
17
|
|
|
19
|
-
const canvasWidth = bounds.width -
|
|
20
|
-
const canvasHeight = bounds.height -
|
|
18
|
+
const canvasWidth = bounds.width - config.rulerSize;
|
|
19
|
+
const canvasHeight = bounds.height - config.rulerSize;
|
|
21
20
|
|
|
22
21
|
const contentLeft = -translateX / scale;
|
|
23
22
|
const contentTop = -translateY / scale;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { calculateTickSpacing, createVerticalTick } from "@/lib/rulers/ticks";
|
|
2
|
-
import type {
|
|
2
|
+
import type { MarkupCanvasConfig } from "@/types/index.js";
|
|
3
3
|
|
|
4
4
|
export function updateVerticalRuler(
|
|
5
5
|
ruler: HTMLElement,
|
|
@@ -7,7 +7,7 @@ export function updateVerticalRuler(
|
|
|
7
7
|
contentBottom: number,
|
|
8
8
|
canvasHeight: number,
|
|
9
9
|
scale: number,
|
|
10
|
-
config: Required<
|
|
10
|
+
config: Required<MarkupCanvasConfig>
|
|
11
11
|
): void {
|
|
12
12
|
const rulerHeight = canvasHeight;
|
|
13
13
|
const contentHeight = contentBottom - contentTop;
|
package/src/types/config.ts
CHANGED
package/src/types/index.ts
CHANGED
package/src/types/rulers.ts
CHANGED
|
@@ -1,18 +1,5 @@
|
|
|
1
1
|
import type { CanvasBounds, Transform } from "./canvas.js";
|
|
2
2
|
|
|
3
|
-
export interface RulerOptions {
|
|
4
|
-
backgroundColor?: string;
|
|
5
|
-
borderColor?: string;
|
|
6
|
-
textColor?: string;
|
|
7
|
-
majorTickColor?: string;
|
|
8
|
-
minorTickColor?: string;
|
|
9
|
-
fontSize?: number;
|
|
10
|
-
fontFamily?: string;
|
|
11
|
-
showGrid?: boolean;
|
|
12
|
-
gridColor?: string;
|
|
13
|
-
units?: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
3
|
export interface RulerSystem {
|
|
17
4
|
horizontalRuler: HTMLElement;
|
|
18
5
|
verticalRuler: HTMLElement;
|
|
@@ -33,3 +20,9 @@ export interface RulerCanvas {
|
|
|
33
20
|
updateTransform: (newTransform: Partial<Transform>) => boolean;
|
|
34
21
|
getBounds: () => CanvasBounds;
|
|
35
22
|
}
|
|
23
|
+
export interface RulerElements {
|
|
24
|
+
horizontalRuler: HTMLElement;
|
|
25
|
+
verticalRuler: HTMLElement;
|
|
26
|
+
cornerBox: HTMLElement;
|
|
27
|
+
gridOverlay?: HTMLElement;
|
|
28
|
+
}
|