@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.
Files changed (60) hide show
  1. package/dist/index.d.ts +2 -1
  2. package/dist/lib/config/presets/editor-preset.d.ts +2 -0
  3. package/dist/lib/config/presets/index.d.ts +1 -0
  4. package/dist/lib/helpers/withRulerCheck.d.ts +4 -4
  5. package/dist/lib/helpers/withRulerOffset.d.ts +1 -1
  6. package/dist/lib/rulers/constants.d.ts +0 -1
  7. package/dist/lib/rulers/createCornerBox.d.ts +2 -2
  8. package/dist/lib/rulers/createGridOverlay.d.ts +2 -2
  9. package/dist/lib/rulers/createHorizontalRuler.d.ts +2 -2
  10. package/dist/lib/rulers/createRulerElements.d.ts +2 -3
  11. package/dist/lib/rulers/createVerticalRuler.d.ts +2 -2
  12. package/dist/lib/rulers/index.d.ts +1 -1
  13. package/dist/lib/rulers/ticks/createHorizontalTick.d.ts +2 -2
  14. package/dist/lib/rulers/ticks/createVerticalTick.d.ts +2 -2
  15. package/dist/lib/rulers/updateHorizontalRuler.d.ts +2 -2
  16. package/dist/lib/rulers/updateRulers.d.ts +2 -2
  17. package/dist/lib/rulers/updateVerticalRuler.d.ts +2 -2
  18. package/dist/markup-canvas.cjs.js +136 -94
  19. package/dist/markup-canvas.esm.js +136 -95
  20. package/dist/markup-canvas.umd.js +87 -94
  21. package/dist/markup-canvas.umd.min.js +1 -1
  22. package/dist/types/config.d.ts +1 -0
  23. package/dist/types/index.d.ts +1 -1
  24. package/dist/types/rulers.d.ts +6 -12
  25. package/package.json +1 -1
  26. package/src/index.ts +1 -1
  27. package/src/lib/canvas/createCanvas.ts +1 -2
  28. package/src/lib/canvas/getCanvasBounds.ts +2 -2
  29. package/src/lib/canvas/getCanvasMethods.ts +1 -3
  30. package/src/lib/canvas/setupTransformLayer.ts +1 -2
  31. package/src/lib/config/constants.ts +2 -1
  32. package/src/lib/config/createMarkupCanvasConfig.ts +5 -0
  33. package/src/lib/config/presets/editor-preset.ts +57 -0
  34. package/src/lib/config/presets/index.ts +1 -0
  35. package/src/lib/events/keyboard/setupKeyboardEvents.ts +1 -1
  36. package/src/lib/events/keyboard/setupKeyboardNavigation.ts +1 -1
  37. package/src/lib/events/mouse/handleClickToZoom.ts +1 -1
  38. package/src/lib/events/touch/handleTouchMove.ts +1 -1
  39. package/src/lib/events/wheel/handleWheel.ts +1 -1
  40. package/src/lib/helpers/withRulerCheck.ts +9 -8
  41. package/src/lib/helpers/withRulerOffset.ts +3 -4
  42. package/src/lib/matrix/getZoomToMouseTransform.ts +1 -2
  43. package/src/lib/rulers/constants.ts +0 -2
  44. package/src/lib/rulers/createCornerBox.ts +12 -12
  45. package/src/lib/rulers/createGridOverlay.ts +5 -5
  46. package/src/lib/rulers/createHorizontalRuler.ts +11 -11
  47. package/src/lib/rulers/createRulerElements.ts +3 -4
  48. package/src/lib/rulers/createRulers.ts +3 -16
  49. package/src/lib/rulers/createVerticalRuler.ts +11 -11
  50. package/src/lib/rulers/index.ts +1 -1
  51. package/src/lib/rulers/ticks/createHorizontalTick.ts +6 -5
  52. package/src/lib/rulers/ticks/createVerticalTick.ts +6 -5
  53. package/src/lib/rulers/updateHorizontalRuler.ts +2 -2
  54. package/src/lib/rulers/updateRulers.ts +4 -5
  55. package/src/lib/rulers/updateVerticalRuler.ts +2 -2
  56. package/src/types/config.ts +1 -0
  57. package/src/types/index.ts +1 -1
  58. package/src/types/rulers.ts +6 -13
  59. package/dist/lib/rulers/RulerElements.d.ts +0 -6
  60. 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, RulerOptions, RulerSystem, TouchState, Transform, ZoomBoundaryOptions, ZoomBoundaryResult, } from "./types/index.js";
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,2 @@
1
+ import type { MarkupCanvasConfig } from "@/types";
2
+ export declare const EDITOR_PRESET: Required<MarkupCanvasConfig>;
@@ -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,3 +1,3 @@
1
1
  export declare function withRulerOffset<T>(canvas: {
2
2
  container: HTMLElement;
3
- }, x: number, y: number, operation: (adjustedX: number, adjustedY: number) => T): T;
3
+ }, x: number, y: number, rulerSize: number, operation: (adjustedX: number, adjustedY: number) => T): T;
@@ -1,4 +1,3 @@
1
- export declare const RULER_SIZE = 24;
2
1
  export declare const RULER_Z_INDEX: {
3
2
  readonly GRID: 100;
4
3
  readonly RULERS: 1000;
@@ -1,2 +1,2 @@
1
- import type { RulerOptions } from "@/types/index.js";
2
- export declare function createCornerBox(config: Required<RulerOptions>): HTMLElement;
1
+ import type { MarkupCanvasConfig } from "@/types/index.js";
2
+ export declare function createCornerBox(config: Required<MarkupCanvasConfig>): HTMLElement;
@@ -1,2 +1,2 @@
1
- import type { RulerOptions } from "@/types/index.js";
2
- export declare function createGridOverlay(config: Required<RulerOptions>): HTMLElement;
1
+ import type { MarkupCanvasConfig } from "@/types/index.js";
2
+ export declare function createGridOverlay(config: Required<MarkupCanvasConfig>): HTMLElement;
@@ -1,2 +1,2 @@
1
- import type { RulerOptions } from "@/types/index.js";
2
- export declare function createHorizontalRuler(config: Required<RulerOptions>): HTMLElement;
1
+ import type { MarkupCanvasConfig } from "@/types/index.js";
2
+ export declare function createHorizontalRuler(config: Required<MarkupCanvasConfig>): HTMLElement;
@@ -1,3 +1,2 @@
1
- import type { RulerOptions } from "@/types/index.js";
2
- import type { RulerElements } from "./RulerElements.js";
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 { RulerOptions } from "@/types/index.js";
2
- export declare function createVerticalRuler(config: Required<RulerOptions>): HTMLElement;
1
+ import type { MarkupCanvasConfig } from "@/types/index.js";
2
+ export declare function createVerticalRuler(config: Required<MarkupCanvasConfig>): HTMLElement;
@@ -1,2 +1,2 @@
1
- export type { RulerOptions, RulerSystem } from "@/types/index.js";
1
+ export type { RulerSystem } from "@/types/index.js";
2
2
  export { createRulers } from "./createRulers.js";
@@ -1,2 +1,2 @@
1
- import type { RulerOptions } from "@/types/index.js";
2
- export declare function createHorizontalTick(container: HTMLElement | DocumentFragment, position: number, pixelPos: number, tickSpacing: number, config: Required<RulerOptions>): void;
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 { RulerOptions } from "@/types/index.js";
2
- export declare function createVerticalTick(container: HTMLElement | DocumentFragment, position: number, pixelPos: number, tickSpacing: number, config: Required<RulerOptions>): void;
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 { RulerOptions } from "@/types/index.js";
2
- export declare function updateHorizontalRuler(ruler: HTMLElement, contentLeft: number, contentRight: number, canvasWidth: number, scale: number, config: Required<RulerOptions>): void;
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, RulerOptions } from "@/types/index.js";
2
- export declare function updateRulers(canvas: Canvas, horizontalRuler: HTMLElement, verticalRuler: HTMLElement, gridOverlay: HTMLElement | undefined, config: Required<RulerOptions>): void;
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 { RulerOptions } from "@/types/index.js";
2
- export declare function updateVerticalRuler(ruler: HTMLElement, contentTop: number, contentBottom: number, canvasHeight: number, scale: number, config: Required<RulerOptions>): void;
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.3
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 = RULER_SIZE;
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 ? -RULER_SIZE : 0;
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 rulerSize = hasRulers ? RULER_SIZE : 0;
234
- return operation(rulerSize);
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 - RULER_SIZE : x;
257
- const adjustedY = hasRulers ? y - RULER_SIZE : 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: 10,
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 ? -RULER_SIZE : 0;
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: ${RULER_SIZE}px;
1303
- height: ${RULER_SIZE}px;
1304
- background: ${config.backgroundColor};
1305
- border-right: 1px solid ${config.borderColor};
1306
- border-bottom: 1px solid ${config.borderColor};
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.fontFamily};
1312
- font-size: ${config.fontSize - 2}px;
1313
- color: ${config.textColor};
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.units;
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: ${RULER_SIZE}px;
1326
- left: ${RULER_SIZE}px;
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: ${RULER_SIZE}px;
1397
+ left: ${config.rulerSize}px;
1347
1398
  right: 0;
1348
- height: ${RULER_SIZE}px;
1349
- background: ${config.backgroundColor};
1350
- border-bottom: 1px solid ${config.borderColor};
1351
- border-right: 1px solid ${config.borderColor};
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.fontFamily};
1355
- font-size: ${config.fontSize}px;
1356
- color: ${config.textColor};
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: ${RULER_SIZE}px;
1418
+ top: ${config.rulerSize}px;
1368
1419
  left: 0;
1369
1420
  bottom: 0;
1370
- width: ${RULER_SIZE}px;
1371
- background: ${config.backgroundColor};
1372
- border-right: 1px solid ${config.borderColor};
1373
- border-bottom: 1px solid ${config.borderColor};
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.fontFamily};
1377
- font-size: ${config.fontSize}px;
1378
- color: ${config.textColor};
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.showGrid ? createGridOverlay(config) : undefined;
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.majorTickColor : config.minorTickColor};
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.fontSize}px;
1469
- color: ${config.textColor};
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.majorTickColor : config.minorTickColor};
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.fontSize}px;
1516
- color: ${config.textColor};
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 - RULER_SIZE;
1550
- const canvasHeight = bounds.height - RULER_SIZE;
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, rulerOptions);
1626
+ updateRulers(canvas, elements.horizontalRuler, elements.verticalRuler, elements.gridOverlay, config);
1586
1627
  };
1587
1628
  try {
1588
- elements = createRulerElements(canvas.container, rulerOptions);
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;