@bwp-web/canvas 0.4.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.
Files changed (73) hide show
  1. package/dist/Canvas/Canvas.d.ts +11 -0
  2. package/dist/Canvas/Canvas.d.ts.map +1 -0
  3. package/dist/Canvas/index.d.ts +3 -0
  4. package/dist/Canvas/index.d.ts.map +1 -0
  5. package/dist/alignment/cursorSnapping.d.ts +55 -0
  6. package/dist/alignment/cursorSnapping.d.ts.map +1 -0
  7. package/dist/alignment/index.d.ts +9 -0
  8. package/dist/alignment/index.d.ts.map +1 -0
  9. package/dist/alignment/objectAlignment.d.ts +27 -0
  10. package/dist/alignment/objectAlignment.d.ts.map +1 -0
  11. package/dist/alignment/objectAlignmentMath.d.ts +35 -0
  12. package/dist/alignment/objectAlignmentMath.d.ts.map +1 -0
  13. package/dist/alignment/objectAlignmentRendering.d.ts +21 -0
  14. package/dist/alignment/objectAlignmentRendering.d.ts.map +1 -0
  15. package/dist/alignment/objectAlignmentUtils.d.ts +44 -0
  16. package/dist/alignment/objectAlignmentUtils.d.ts.map +1 -0
  17. package/dist/alignment/rotationSnap.d.ts +16 -0
  18. package/dist/alignment/rotationSnap.d.ts.map +1 -0
  19. package/dist/alignment/snapPoints.d.ts +18 -0
  20. package/dist/alignment/snapPoints.d.ts.map +1 -0
  21. package/dist/background.d.ts +79 -0
  22. package/dist/background.d.ts.map +1 -0
  23. package/dist/constants.d.ts +34 -0
  24. package/dist/constants.d.ts.map +1 -0
  25. package/dist/fabricAugmentation.d.ts +15 -0
  26. package/dist/fabricAugmentation.d.ts.map +1 -0
  27. package/dist/hooks/index.d.ts +5 -0
  28. package/dist/hooks/index.d.ts.map +1 -0
  29. package/dist/hooks/shared.d.ts +20 -0
  30. package/dist/hooks/shared.d.ts.map +1 -0
  31. package/dist/hooks/useEditCanvas.d.ts +126 -0
  32. package/dist/hooks/useEditCanvas.d.ts.map +1 -0
  33. package/dist/hooks/useViewCanvas.d.ts +66 -0
  34. package/dist/hooks/useViewCanvas.d.ts.map +1 -0
  35. package/dist/index.cjs +2424 -0
  36. package/dist/index.cjs.map +1 -0
  37. package/dist/index.d.ts +38 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +2365 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/interactions/clickToCreate.d.ts +10 -0
  42. package/dist/interactions/clickToCreate.d.ts.map +1 -0
  43. package/dist/interactions/dragToCreate.d.ts +20 -0
  44. package/dist/interactions/dragToCreate.d.ts.map +1 -0
  45. package/dist/interactions/drawToCreate.d.ts +28 -0
  46. package/dist/interactions/drawToCreate.d.ts.map +1 -0
  47. package/dist/interactions/index.d.ts +9 -0
  48. package/dist/interactions/index.d.ts.map +1 -0
  49. package/dist/interactions/interactionSnapping.d.ts +34 -0
  50. package/dist/interactions/interactionSnapping.d.ts.map +1 -0
  51. package/dist/interactions/shared.d.ts +13 -0
  52. package/dist/interactions/shared.d.ts.map +1 -0
  53. package/dist/interactions/vertexEdit.d.ts +18 -0
  54. package/dist/interactions/vertexEdit.d.ts.map +1 -0
  55. package/dist/keyboard.d.ts +13 -0
  56. package/dist/keyboard.d.ts.map +1 -0
  57. package/dist/serialization.d.ts +52 -0
  58. package/dist/serialization.d.ts.map +1 -0
  59. package/dist/shapes/circle.d.ts +36 -0
  60. package/dist/shapes/circle.d.ts.map +1 -0
  61. package/dist/shapes/index.d.ts +4 -0
  62. package/dist/shapes/index.d.ts.map +1 -0
  63. package/dist/shapes/polygon.d.ts +37 -0
  64. package/dist/shapes/polygon.d.ts.map +1 -0
  65. package/dist/shapes/rectangle.d.ts +31 -0
  66. package/dist/shapes/rectangle.d.ts.map +1 -0
  67. package/dist/styles.d.ts +46 -0
  68. package/dist/styles.d.ts.map +1 -0
  69. package/dist/types.d.ts +48 -0
  70. package/dist/types.d.ts.map +1 -0
  71. package/dist/viewport.d.ts +51 -0
  72. package/dist/viewport.d.ts.map +1 -0
  73. package/package.json +51 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../src/keyboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE9D;;GAEG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,YAAY,EACpB,GAAG,OAAO,EAAE,YAAY,EAAE,GACzB,IAAI,CAGN;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,IAAI,CAgBxE"}
@@ -0,0 +1,52 @@
1
+ import { Canvas as FabricCanvas, type FabricObject } from 'fabric';
2
+ /**
3
+ * Enable zoom-independent stroke widths on a canvas.
4
+ *
5
+ * On every render, each object's `strokeWidth` is set to `base / zoom` so
6
+ * strokes always appear as one visual pixel regardless of zoom level. The
7
+ * original (base) stroke width is stored in an internal WeakMap and is
8
+ * automatically restored before serialization by {@link serializeCanvas}.
9
+ *
10
+ * Returns a cleanup function that removes the listener and restores all
11
+ * stroke widths to their base values.
12
+ */
13
+ export declare function enableScaledStrokes(canvas: FabricCanvas): () => void;
14
+ /**
15
+ * Options for {@link serializeCanvas}.
16
+ */
17
+ export interface SerializeOptions {
18
+ /**
19
+ * Additional Fabric object properties to include in the JSON output.
20
+ * The `'data'` and `'shapeType'` properties are always included.
21
+ * Default: `['data', 'shapeType']`.
22
+ */
23
+ properties?: string[];
24
+ }
25
+ /**
26
+ * Return the base (unscaled) stroke width for an object.
27
+ *
28
+ * When {@link enableScaledStrokes} is active, `obj.strokeWidth` is a
29
+ * zoom-adjusted value. This function returns the original intended width that
30
+ * was recorded before any zoom adjustment was applied. Falls back to the
31
+ * object's current `strokeWidth` if the object has never been seen by
32
+ * `enableScaledStrokes` (e.g. if the feature is disabled).
33
+ */
34
+ export declare function getBaseStrokeWidth(obj: FabricObject): number;
35
+ /**
36
+ * Serialize the canvas to a plain object, ready for `JSON.stringify`.
37
+ *
38
+ * - Always includes the `'data'` and `'shapeType'` custom properties.
39
+ * - If {@link enableScaledStrokes} is active, temporarily restores all stroke
40
+ * widths to their base values before serializing, then reapplies the
41
+ * zoom-scaled values. This ensures the saved JSON always contains the
42
+ * intended visual stroke width, not the zoom-adjusted one.
43
+ */
44
+ export declare function serializeCanvas(canvas: FabricCanvas, options?: SerializeOptions): object;
45
+ /**
46
+ * Load a canvas from a previously serialized JSON object (from {@link serializeCanvas}).
47
+ *
48
+ * Clears the canvas and restores all objects, then requests a re-render.
49
+ * The returned promise resolves once the canvas is fully loaded.
50
+ */
51
+ export declare function loadCanvas(canvas: FabricCanvas, json: object): Promise<void>;
52
+ //# sourceMappingURL=serialization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialization.d.ts","sourceRoot":"","sources":["../src/serialization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,YAAY,EAAQ,KAAK,YAAY,EAAE,MAAM,QAAQ,CAAC;AAWzE;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,IAAI,CA2BpE;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAE5D;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,YAAY,EACpB,OAAO,CAAC,EAAE,gBAAgB,GACzB,MAAM,CAiCR;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,MAAM,EAAE,YAAY,EACpB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,IAAI,CAAC,CAaf"}
@@ -0,0 +1,36 @@
1
+ import { Canvas as FabricCanvas, Rect } from 'fabric';
2
+ import type { Point2D, ShapeStyleOptions } from '../types';
3
+ export interface CircleOptions extends ShapeStyleOptions {
4
+ left: number;
5
+ top: number;
6
+ size: number;
7
+ }
8
+ export interface CircleAtPointOptions extends ShapeStyleOptions {
9
+ size: number;
10
+ }
11
+ /**
12
+ * Re-apply circle control visibility after deserialization.
13
+ *
14
+ * Fabric's `loadFromJSON` does not restore `setControlsVisibility` state, so
15
+ * this must be called on any deserialized object whose `shapeType === 'circle'`
16
+ * to restore the correct handle layout (no mid-edge or rotation handles).
17
+ *
18
+ * Not part of the public package API — imported directly by `serialization.ts`.
19
+ */
20
+ export declare function restoreCircleConstraints(rect: Rect): void;
21
+ /**
22
+ * Create a circle (a square Rect with full border-radius) and add it to the canvas.
23
+ * Returns the fabric Rect instance for further manipulation.
24
+ */
25
+ export declare function createCircle(canvas: FabricCanvas, options: CircleOptions): Rect;
26
+ /**
27
+ * Create a circle at the given scene point and add it to the canvas.
28
+ * Returns the fabric Rect instance.
29
+ */
30
+ export declare function createCircleAtPoint(canvas: FabricCanvas, point: Point2D, options: CircleAtPointOptions): Rect;
31
+ /**
32
+ * Edit an existing circle's properties (position, size, appearance).
33
+ * When size changes, rx and ry are automatically updated to maintain the circular shape.
34
+ */
35
+ export declare function editCircle(canvas: FabricCanvas, rect: Rect, changes: Partial<CircleOptions>): void;
36
+ //# sourceMappingURL=circle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"circle.d.ts","sourceRoot":"","sources":["../../src/shapes/circle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAG3D,MAAM,WAAW,aAAc,SAAQ,iBAAiB;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,oBAAqB,SAAQ,iBAAiB;IAC7D,IAAI,EAAE,MAAM,CAAC;CACd;AAuBD;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAGzD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,aAAa,GACrB,IAAI,CAeN;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,oBAAoB,GAC5B,IAAI,CAiBN;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,YAAY,EACpB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,GAC9B,IAAI,CAeN"}
@@ -0,0 +1,4 @@
1
+ export * from './rectangle';
2
+ export * from './circle';
3
+ export * from './polygon';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shapes/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { Canvas as FabricCanvas, Polygon } from 'fabric';
2
+ import type { Point2D, ShapeStyleOptions } from '../types';
3
+ export interface PolygonOptions extends ShapeStyleOptions {
4
+ points: Point2D[];
5
+ left?: number;
6
+ top?: number;
7
+ }
8
+ /** @deprecated Use `ShapeStyleOptions` directly. This alias will be removed in a future major version. */
9
+ export type PolygonStyleOptions = ShapeStyleOptions;
10
+ /**
11
+ * Create a polygon and add it to the canvas.
12
+ * Returns the fabric Polygon instance for further manipulation.
13
+ */
14
+ export declare function createPolygon(canvas: FabricCanvas, options: PolygonOptions): Polygon;
15
+ /**
16
+ * Create a rectangular polygon at the given scene point and add it to the canvas.
17
+ * Returns the fabric Polygon instance.
18
+ */
19
+ export declare function createPolygonAtPoint(canvas: FabricCanvas, point: Point2D, options: PolygonStyleOptions & {
20
+ width: number;
21
+ height: number;
22
+ }): Polygon;
23
+ /**
24
+ * Create a rectangular polygon from drag bounds (two corner points) and add it to the canvas.
25
+ * Returns the fabric Polygon instance.
26
+ */
27
+ export declare function createPolygonFromDrag(canvas: FabricCanvas, start: Point2D, end: Point2D, style?: PolygonStyleOptions): Polygon;
28
+ /**
29
+ * Create a polygon from an arbitrary array of vertices and add it to the canvas.
30
+ * Returns the fabric Polygon instance.
31
+ */
32
+ export declare function createPolygonFromVertices(canvas: FabricCanvas, points: Point2D[], style?: PolygonStyleOptions): Polygon;
33
+ /**
34
+ * Edit an existing polygon's properties (position, points, appearance, etc.).
35
+ */
36
+ export declare function editPolygon(canvas: FabricCanvas, polygon: Polygon, changes: Partial<PolygonOptions>): void;
37
+ //# sourceMappingURL=polygon.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polygon.d.ts","sourceRoot":"","sources":["../../src/shapes/polygon.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAG3D,MAAM,WAAW,cAAe,SAAQ,iBAAiB;IACvD,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,0GAA0G;AAC1G,MAAM,MAAM,mBAAmB,GAAG,iBAAiB,CAAC;AAEpD;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,cAAc,GACtB,OAAO,CAMT;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,mBAAmB,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC/D,OAAO,CAcT;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,OAAO,EACZ,KAAK,CAAC,EAAE,mBAAmB,GAC1B,OAAO,CAiBT;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,OAAO,EAAE,EACjB,KAAK,CAAC,EAAE,mBAAmB,GAC1B,OAAO,CAQT;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,GAC/B,IAAI,CASN"}
@@ -0,0 +1,31 @@
1
+ import { Canvas as FabricCanvas, Rect } from 'fabric';
2
+ import type { Point2D, ShapeStyleOptions } from '../types';
3
+ export interface RectangleOptions extends ShapeStyleOptions {
4
+ left: number;
5
+ top: number;
6
+ width: number;
7
+ height: number;
8
+ rx?: number;
9
+ ry?: number;
10
+ }
11
+ export interface RectangleAtPointOptions extends ShapeStyleOptions {
12
+ width: number;
13
+ height: number;
14
+ rx?: number;
15
+ ry?: number;
16
+ }
17
+ /**
18
+ * Create a rectangle and add it to the canvas.
19
+ * Returns the fabric Rect instance for further manipulation.
20
+ */
21
+ export declare function createRectangle(canvas: FabricCanvas, options: RectangleOptions): Rect;
22
+ /**
23
+ * Create a rectangle at the given scene point and add it to the canvas.
24
+ * Returns the fabric Rect instance.
25
+ */
26
+ export declare function createRectangleAtPoint(canvas: FabricCanvas, point: Point2D, options: RectangleAtPointOptions): Rect;
27
+ /**
28
+ * Edit an existing rectangle's properties (position, dimensions, appearance, etc.).
29
+ */
30
+ export declare function editRectangle(canvas: FabricCanvas, rect: Rect, changes: Partial<RectangleOptions>): void;
31
+ //# sourceMappingURL=rectangle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rectangle.d.ts","sourceRoot":"","sources":["../../src/shapes/rectangle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAG3D,MAAM,WAAW,gBAAiB,SAAQ,iBAAiB;IACzD,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,uBAAwB,SAAQ,iBAAiB;IAChE,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,gBAAgB,GACxB,IAAI,CAKN;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,uBAAuB,GAC/B,IAAI,CAaN;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,YAAY,EACpB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,CAAC,gBAAgB,CAAC,GACjC,IAAI,CAIN"}
@@ -0,0 +1,46 @@
1
+ export declare const DEFAULT_CONTROL_STYLE: {
2
+ borderColor: string;
3
+ cornerColor: string;
4
+ cornerStrokeColor: string;
5
+ transparentCorners: boolean;
6
+ };
7
+ export declare const DEFAULT_SHAPE_STYLE: {
8
+ borderColor: string;
9
+ cornerColor: string;
10
+ cornerStrokeColor: string;
11
+ transparentCorners: boolean;
12
+ fill: string;
13
+ stroke: string;
14
+ strokeWidth: number;
15
+ strokeUniform: boolean;
16
+ };
17
+ export declare const DEFAULT_CIRCLE_STYLE: {
18
+ borderColor: string;
19
+ cornerColor: string;
20
+ cornerStrokeColor: string;
21
+ transparentCorners: boolean;
22
+ fill: string;
23
+ stroke: string;
24
+ strokeWidth: number;
25
+ strokeUniform: boolean;
26
+ };
27
+ export declare const DEFAULT_DRAG_SHAPE_STYLE: {
28
+ fill: string;
29
+ stroke: string;
30
+ strokeWidth: number;
31
+ strokeUniform: boolean;
32
+ strokeDashArray: number[];
33
+ };
34
+ export declare const DEFAULT_GUIDELINE_SHAPE_STYLE: {
35
+ fill: string;
36
+ stroke: string;
37
+ strokeWidth: number;
38
+ strokeUniform: boolean;
39
+ strokeDashArray: number[];
40
+ };
41
+ export declare const DEFAULT_ALIGNMENT_STYLE: {
42
+ readonly color: "rgba(255, 0, 0, 0.9)";
43
+ readonly width: 1;
44
+ readonly xSize: 2.4;
45
+ };
46
+ //# sourceMappingURL=styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,qBAAqB;;;;;CAKjC,CAAC;AAEF,eAAO,MAAM,mBAAmB;;;;;;;;;CAM/B,CAAC;AAEF,eAAO,MAAM,oBAAoB;;;;;;;;;CAMhC,CAAC;AAEF,eAAO,MAAM,wBAAwB;;;;;;CAMpC,CAAC;AAEF,eAAO,MAAM,6BAA6B;;;;;;CAMzC,CAAC;AAEF,eAAO,MAAM,uBAAuB;;;;CAI1B,CAAC"}
@@ -0,0 +1,48 @@
1
+ import type { Canvas as FabricCanvas, FabricObject } from 'fabric';
2
+ import type { ViewportController } from './viewport';
3
+ import type { GuidelineStyle } from './alignment/cursorSnapping';
4
+ /** A simple 2D point. */
5
+ export type Point2D = {
6
+ x: number;
7
+ y: number;
8
+ };
9
+ /** Common style fields shared across all shape options. */
10
+ export interface ShapeStyleOptions {
11
+ fill?: string;
12
+ stroke?: string;
13
+ strokeWidth?: number;
14
+ }
15
+ /** Snapping configuration used by interaction modes (dragToCreate, drawToCreate). */
16
+ export type SnappingOptions = boolean | {
17
+ /** Snap margin in screen pixels. Default: 6. */
18
+ margin?: number;
19
+ /** Custom guideline style. */
20
+ guidelineStyle?: GuidelineStyle;
21
+ };
22
+ /** Options shared by all interaction modes that create objects. */
23
+ export interface InteractionModeOptions {
24
+ onCreated?: (obj: FabricObject) => void;
25
+ viewport?: ViewportController;
26
+ }
27
+ /** Options shared by interaction modes that support snapping. */
28
+ export interface SnappableInteractionOptions extends InteractionModeOptions {
29
+ /** Enable cursor snapping. Pass `true` for defaults or an options object. Default: enabled. */
30
+ snapping?: SnappingOptions;
31
+ /**
32
+ * Master toggle for alignment/snapping.
33
+ * - `undefined`: uses the `snapping` prop (default: enabled).
34
+ * - `true`: force-enable snapping.
35
+ * - `false`: force-disable snapping.
36
+ */
37
+ enableAlignment?: boolean;
38
+ }
39
+ /** Bounds produced by a drag-to-create interaction. */
40
+ export interface DragBounds {
41
+ startX: number;
42
+ startY: number;
43
+ width: number;
44
+ height: number;
45
+ }
46
+ /** Setup function for interaction modes, used by useEditCanvas.setMode(). */
47
+ export type ModeSetup = (canvas: FabricCanvas, viewport: ViewportController | undefined) => (() => void) | void;
48
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAEjE,yBAAyB;AACzB,MAAM,MAAM,OAAO,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/C,2DAA2D;AAC3D,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,qFAAqF;AACrF,MAAM,MAAM,eAAe,GACvB,OAAO,GACP;IACE,gDAAgD;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8BAA8B;IAC9B,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC,CAAC;AAEN,mEAAmE;AACnE,MAAM,WAAW,sBAAsB;IACrC,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,YAAY,KAAK,IAAI,CAAC;IACxC,QAAQ,CAAC,EAAE,kBAAkB,CAAC;CAC/B;AAED,iEAAiE;AACjE,MAAM,WAAW,2BAA4B,SAAQ,sBAAsB;IACzE,+FAA+F;IAC/F,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B;;;;;OAKG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,uDAAuD;AACvD,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,6EAA6E;AAC7E,MAAM,MAAM,SAAS,GAAG,CACtB,MAAM,EAAE,YAAY,EACpB,QAAQ,EAAE,kBAAkB,GAAG,SAAS,KACrC,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC"}
@@ -0,0 +1,51 @@
1
+ import { Canvas as FabricCanvas } from 'fabric';
2
+ export type ViewportMode = 'select' | 'pan';
3
+ export interface PanAndZoomOptions {
4
+ /** Minimum zoom level (default: 0.2) */
5
+ minZoom?: number;
6
+ /** Maximum zoom level (default: 10) */
7
+ maxZoom?: number;
8
+ /** Zoom sensitivity — larger values zoom faster (default: 1.03) */
9
+ zoomFactor?: number;
10
+ /** Initial viewport mode (default: 'select') */
11
+ initialMode?: ViewportMode;
12
+ }
13
+ export interface ViewportController {
14
+ /** Switch between select and pan modes. */
15
+ setMode: (mode: ViewportMode) => void;
16
+ /** Get the current viewport mode. */
17
+ getMode: () => ViewportMode;
18
+ /** Temporarily disable all pan and zoom input (e.g. during draw modes). */
19
+ setEnabled: (enabled: boolean) => void;
20
+ /**
21
+ * Zoom in toward the canvas center by `step` zoom units.
22
+ * Respects the configured min/max zoom bounds. Default step: 0.2.
23
+ */
24
+ zoomIn: (step?: number) => void;
25
+ /**
26
+ * Zoom out from the canvas center by `step` zoom units.
27
+ * Respects the configured min/max zoom bounds. Default step: 0.2.
28
+ */
29
+ zoomOut: (step?: number) => void;
30
+ /** Remove all event listeners. */
31
+ cleanup: () => void;
32
+ }
33
+ /**
34
+ * Enable pan and zoom on the canvas viewport.
35
+ *
36
+ * - **Zoom**: Scroll the mouse wheel to zoom in/out centred on the cursor
37
+ * (works in both modes). On touch devices, pinch with two fingers to zoom.
38
+ * - **Select mode**: Normal object selection. Hold Cmd (Mac) / Ctrl (Win) and
39
+ * drag to pan. Middle-button drag also pans.
40
+ * - **Pan mode**: Click or single-touch drag to pan freely. Object selection
41
+ * is disabled.
42
+ *
43
+ * Returns a {@link ViewportController} for switching modes, programmatic zoom,
44
+ * and cleanup.
45
+ */
46
+ export declare function enablePanAndZoom(canvas: FabricCanvas, options?: PanAndZoomOptions): ViewportController;
47
+ /**
48
+ * Reset the canvas viewport to the default (no pan, zoom = 1).
49
+ */
50
+ export declare function resetViewport(canvas: FabricCanvas): void;
51
+ //# sourceMappingURL=viewport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viewport.d.ts","sourceRoot":"","sources":["../src/viewport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,YAAY,EAAwB,MAAM,QAAQ,CAAC;AAQtE,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,KAAK,CAAC;AAE5C,MAAM,WAAW,iBAAiB;IAChC,wCAAwC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uCAAuC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mEAAmE;IACnE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gDAAgD;IAChD,WAAW,CAAC,EAAE,YAAY,CAAC;CAC5B;AAED,MAAM,WAAW,kBAAkB;IACjC,2CAA2C;IAC3C,OAAO,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,IAAI,CAAC;IACtC,qCAAqC;IACrC,OAAO,EAAE,MAAM,YAAY,CAAC;IAC5B,2EAA2E;IAC3E,UAAU,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IACvC;;;OAGG;IACH,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC;;;OAGG;IACH,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,kCAAkC;IAClC,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AA0MD;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,YAAY,EACpB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,kBAAkB,CAwEpB;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAExD"}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@bwp-web/canvas",
3
+ "version": "0.4.0",
4
+ "type": "module",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.cjs"
17
+ }
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "sideEffects": false,
24
+ "scripts": {
25
+ "build": "tsup && tsc -p tsconfig.build.json",
26
+ "build:types": "tsc -p tsconfig.build.json",
27
+ "typecheck": "tsc --noEmit",
28
+ "lint": "eslint",
29
+ "format": "prettier --check . --ignore-path ../../.gitignore",
30
+ "clean": "rm -rf dist node_modules .turbo",
31
+ "prepublishOnly": "npm run build"
32
+ },
33
+ "dependencies": {
34
+ "fabric": "^7.2.0"
35
+ },
36
+ "peerDependencies": {
37
+ "@bwp-web/styles": "*",
38
+ "@mui/material": ">=7.0.0",
39
+ "react": ">=18.0.0",
40
+ "react-dom": ">=18.0.0"
41
+ },
42
+ "devDependencies": {
43
+ "@bwp-web/eslint-config": "*",
44
+ "@bwp-web/styles": "*",
45
+ "@types/react": "^19.1.0",
46
+ "eslint": "^9.39.2",
47
+ "prettier": "^3.8.1",
48
+ "tsup": "^8.5.1",
49
+ "typescript": "^5.9.2"
50
+ }
51
+ }