@fieldnotes/core 0.3.0 → 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.
package/dist/index.d.cts CHANGED
@@ -44,6 +44,9 @@ interface NoteElement extends BaseElement {
44
44
  text: string;
45
45
  backgroundColor: string;
46
46
  }
47
+ interface Binding {
48
+ elementId: string;
49
+ }
47
50
  interface ArrowElement extends BaseElement {
48
51
  type: 'arrow';
49
52
  from: Point;
@@ -51,6 +54,8 @@ interface ArrowElement extends BaseElement {
51
54
  bend: number;
52
55
  color: string;
53
56
  width: number;
57
+ fromBinding?: Binding;
58
+ toBinding?: Binding;
54
59
  }
55
60
  interface ImageElement extends BaseElement {
56
61
  type: 'image';
@@ -69,7 +74,16 @@ interface TextElement extends BaseElement {
69
74
  color: string;
70
75
  textAlign: 'left' | 'center' | 'right';
71
76
  }
72
- type CanvasElement = StrokeElement | NoteElement | ArrowElement | ImageElement | HtmlElement | TextElement;
77
+ type ShapeKind = 'rectangle' | 'ellipse';
78
+ interface ShapeElement extends BaseElement {
79
+ type: 'shape';
80
+ shape: ShapeKind;
81
+ size: Size;
82
+ strokeColor: string;
83
+ strokeWidth: number;
84
+ fillColor: string;
85
+ }
86
+ type CanvasElement = StrokeElement | NoteElement | ArrowElement | ImageElement | HtmlElement | TextElement | ShapeElement;
73
87
  type ElementType = CanvasElement['type'];
74
88
 
75
89
  interface CanvasState {
@@ -204,7 +218,7 @@ interface Tool {
204
218
  onDeactivate?(ctx: ToolContext): void;
205
219
  renderOverlay?(ctx: CanvasRenderingContext2D): void;
206
220
  }
207
- type ToolName = 'hand' | 'select' | 'pencil' | 'eraser' | 'arrow' | 'note' | 'image' | 'text';
221
+ type ToolName = 'hand' | 'select' | 'pencil' | 'eraser' | 'arrow' | 'note' | 'image' | 'text' | 'shape';
208
222
 
209
223
  declare class ToolManager {
210
224
  private tools;
@@ -381,6 +395,7 @@ declare class Viewport {
381
395
  private onDrop;
382
396
  private syncDomNode;
383
397
  private renderDomContent;
398
+ private unbindArrowsFrom;
384
399
  private removeDomNode;
385
400
  private clearDomNodes;
386
401
  private createWrapper;
@@ -392,11 +407,17 @@ declare class Viewport {
392
407
  }
393
408
 
394
409
  declare class ElementRenderer {
410
+ private store;
411
+ setStore(store: ElementStore): void;
395
412
  isDomElement(element: CanvasElement): boolean;
396
413
  renderCanvasElement(ctx: CanvasRenderingContext2D, element: CanvasElement): void;
397
414
  private renderStroke;
398
415
  private renderArrow;
399
416
  private renderArrowhead;
417
+ private getVisualEndpoints;
418
+ private renderShape;
419
+ private fillShapePath;
420
+ private strokeShapePath;
400
421
  }
401
422
 
402
423
  declare class NoteEditor {
@@ -441,6 +462,8 @@ interface ArrowInput extends BaseDefaults {
441
462
  bend?: number;
442
463
  color?: string;
443
464
  width?: number;
465
+ fromBinding?: Binding;
466
+ toBinding?: Binding;
444
467
  }
445
468
  interface ImageInput extends BaseDefaults {
446
469
  position: Point;
@@ -464,6 +487,15 @@ declare function createNote(input: NoteInput): NoteElement;
464
487
  declare function createArrow(input: ArrowInput): ArrowElement;
465
488
  declare function createImage(input: ImageInput): ImageElement;
466
489
  declare function createHtmlElement(input: HtmlInput): HtmlElement;
490
+ interface ShapeInput extends BaseDefaults {
491
+ position: Point;
492
+ size: Size;
493
+ shape?: ShapeKind;
494
+ strokeColor?: string;
495
+ strokeWidth?: number;
496
+ fillColor?: string;
497
+ }
498
+ declare function createShape(input: ShapeInput): ShapeElement;
467
499
  declare function createText(input: TextInput): TextElement;
468
500
 
469
501
  interface Rect {
@@ -479,6 +511,16 @@ declare function getArrowTangentAngle(from: Point, to: Point, bend: number, t: n
479
511
  declare function isNearBezier(point: Point, from: Point, to: Point, bend: number, threshold: number): boolean;
480
512
  declare function getArrowBounds(from: Point, to: Point, bend: number): Rect;
481
513
 
514
+ declare function isBindable(element: CanvasElement): boolean;
515
+ declare function getElementCenter(element: CanvasElement): Point;
516
+ declare function getElementBounds(element: CanvasElement): Rect | null;
517
+ declare function getEdgeIntersection(bounds: Rect, outsidePoint: Point): Point;
518
+ declare function findBindTarget(point: Point, store: ElementStore, threshold: number, excludeId?: string): CanvasElement | null;
519
+ declare function findBoundArrows(elementId: string, store: ElementStore): ArrowElement[];
520
+ declare function updateBoundArrow(arrow: ArrowElement, store: ElementStore): Partial<ArrowElement> | null;
521
+ declare function clearStaleBindings(arrow: ArrowElement, store: ElementStore): Partial<ArrowElement> | null;
522
+ declare function unbindArrow(arrow: ArrowElement, store: ElementStore): Partial<ArrowElement>;
523
+
482
524
  declare class AddElementCommand implements Command {
483
525
  private readonly element;
484
526
  constructor(element: CanvasElement);
@@ -579,6 +621,7 @@ declare class SelectTool implements Tool {
579
621
  private getHandlePositions;
580
622
  private renderMarquee;
581
623
  private renderSelectionBoxes;
624
+ private renderBindingHighlights;
582
625
  private getMarqueeRect;
583
626
  private findElementsInRect;
584
627
  private rectsOverlap;
@@ -598,6 +641,9 @@ declare class ArrowTool implements Tool {
598
641
  private end;
599
642
  private color;
600
643
  private width;
644
+ private fromBinding;
645
+ private fromTarget;
646
+ private toTarget;
601
647
  constructor(options?: ArrowToolOptions);
602
648
  setOptions(options: ArrowToolOptions): void;
603
649
  onPointerDown(state: PointerState, ctx: ToolContext): void;
@@ -654,6 +700,35 @@ declare class ImageTool implements Tool {
654
700
  onPointerUp(state: PointerState, ctx: ToolContext): void;
655
701
  }
656
702
 
657
- declare const VERSION = "0.3.0";
703
+ interface ShapeToolOptions {
704
+ shape?: ShapeKind;
705
+ strokeColor?: string;
706
+ strokeWidth?: number;
707
+ fillColor?: string;
708
+ }
709
+ declare class ShapeTool implements Tool {
710
+ readonly name = "shape";
711
+ private drawing;
712
+ private start;
713
+ private end;
714
+ private shiftHeld;
715
+ private shape;
716
+ private strokeColor;
717
+ private strokeWidth;
718
+ private fillColor;
719
+ constructor(options?: ShapeToolOptions);
720
+ setOptions(options: ShapeToolOptions): void;
721
+ onActivate(_ctx: ToolContext): void;
722
+ onDeactivate(_ctx: ToolContext): void;
723
+ onPointerDown(state: PointerState, ctx: ToolContext): void;
724
+ onPointerMove(state: PointerState, ctx: ToolContext): void;
725
+ onPointerUp(_state: PointerState, ctx: ToolContext): void;
726
+ renderOverlay(ctx: CanvasRenderingContext2D): void;
727
+ private computeRect;
728
+ private onKeyDown;
729
+ private onKeyUp;
730
+ }
731
+
732
+ declare const VERSION = "0.4.0";
658
733
 
659
- export { AddElementCommand, type ArrowElement, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, Background, type BackgroundOptions, type BackgroundPattern, BatchCommand, type Bounds, Camera, type CameraOptions, type CanvasElement, type CanvasState, type Command, ElementRenderer, ElementStore, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, EventBus, HandTool, HistoryRecorder, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, InputHandler, NoteEditor, type NoteElement, NoteTool, type NoteToolOptions, PencilTool, type PencilToolOptions, type Point, type PointerState, RemoveElementCommand, SelectTool, type Size, type StrokeElement, type StrokePoint, type TextElement, TextTool, type TextToolOptions, type Tool, type ToolContext, ToolManager, type ToolName, UpdateElementCommand, VERSION, Viewport, type ViewportOptions, createArrow, createHtmlElement, createId, createImage, createNote, createStroke, createText, exportState, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, isNearBezier, parseState };
734
+ export { AddElementCommand, type ArrowElement, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, Background, type BackgroundOptions, type BackgroundPattern, BatchCommand, type Binding, type Bounds, Camera, type CameraOptions, type CanvasElement, type CanvasState, type Command, ElementRenderer, ElementStore, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, EventBus, HandTool, HistoryRecorder, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, InputHandler, NoteEditor, type NoteElement, NoteTool, type NoteToolOptions, PencilTool, type PencilToolOptions, type Point, type PointerState, RemoveElementCommand, SelectTool, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type Size, type StrokeElement, type StrokePoint, type TextElement, TextTool, type TextToolOptions, type Tool, type ToolContext, ToolManager, type ToolName, UpdateElementCommand, VERSION, Viewport, type ViewportOptions, clearStaleBindings, createArrow, createHtmlElement, createId, createImage, createNote, createShape, createStroke, createText, exportState, findBindTarget, findBoundArrows, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getEdgeIntersection, getElementBounds, getElementCenter, isBindable, isNearBezier, parseState, unbindArrow, updateBoundArrow };
package/dist/index.d.ts CHANGED
@@ -44,6 +44,9 @@ interface NoteElement extends BaseElement {
44
44
  text: string;
45
45
  backgroundColor: string;
46
46
  }
47
+ interface Binding {
48
+ elementId: string;
49
+ }
47
50
  interface ArrowElement extends BaseElement {
48
51
  type: 'arrow';
49
52
  from: Point;
@@ -51,6 +54,8 @@ interface ArrowElement extends BaseElement {
51
54
  bend: number;
52
55
  color: string;
53
56
  width: number;
57
+ fromBinding?: Binding;
58
+ toBinding?: Binding;
54
59
  }
55
60
  interface ImageElement extends BaseElement {
56
61
  type: 'image';
@@ -69,7 +74,16 @@ interface TextElement extends BaseElement {
69
74
  color: string;
70
75
  textAlign: 'left' | 'center' | 'right';
71
76
  }
72
- type CanvasElement = StrokeElement | NoteElement | ArrowElement | ImageElement | HtmlElement | TextElement;
77
+ type ShapeKind = 'rectangle' | 'ellipse';
78
+ interface ShapeElement extends BaseElement {
79
+ type: 'shape';
80
+ shape: ShapeKind;
81
+ size: Size;
82
+ strokeColor: string;
83
+ strokeWidth: number;
84
+ fillColor: string;
85
+ }
86
+ type CanvasElement = StrokeElement | NoteElement | ArrowElement | ImageElement | HtmlElement | TextElement | ShapeElement;
73
87
  type ElementType = CanvasElement['type'];
74
88
 
75
89
  interface CanvasState {
@@ -204,7 +218,7 @@ interface Tool {
204
218
  onDeactivate?(ctx: ToolContext): void;
205
219
  renderOverlay?(ctx: CanvasRenderingContext2D): void;
206
220
  }
207
- type ToolName = 'hand' | 'select' | 'pencil' | 'eraser' | 'arrow' | 'note' | 'image' | 'text';
221
+ type ToolName = 'hand' | 'select' | 'pencil' | 'eraser' | 'arrow' | 'note' | 'image' | 'text' | 'shape';
208
222
 
209
223
  declare class ToolManager {
210
224
  private tools;
@@ -381,6 +395,7 @@ declare class Viewport {
381
395
  private onDrop;
382
396
  private syncDomNode;
383
397
  private renderDomContent;
398
+ private unbindArrowsFrom;
384
399
  private removeDomNode;
385
400
  private clearDomNodes;
386
401
  private createWrapper;
@@ -392,11 +407,17 @@ declare class Viewport {
392
407
  }
393
408
 
394
409
  declare class ElementRenderer {
410
+ private store;
411
+ setStore(store: ElementStore): void;
395
412
  isDomElement(element: CanvasElement): boolean;
396
413
  renderCanvasElement(ctx: CanvasRenderingContext2D, element: CanvasElement): void;
397
414
  private renderStroke;
398
415
  private renderArrow;
399
416
  private renderArrowhead;
417
+ private getVisualEndpoints;
418
+ private renderShape;
419
+ private fillShapePath;
420
+ private strokeShapePath;
400
421
  }
401
422
 
402
423
  declare class NoteEditor {
@@ -441,6 +462,8 @@ interface ArrowInput extends BaseDefaults {
441
462
  bend?: number;
442
463
  color?: string;
443
464
  width?: number;
465
+ fromBinding?: Binding;
466
+ toBinding?: Binding;
444
467
  }
445
468
  interface ImageInput extends BaseDefaults {
446
469
  position: Point;
@@ -464,6 +487,15 @@ declare function createNote(input: NoteInput): NoteElement;
464
487
  declare function createArrow(input: ArrowInput): ArrowElement;
465
488
  declare function createImage(input: ImageInput): ImageElement;
466
489
  declare function createHtmlElement(input: HtmlInput): HtmlElement;
490
+ interface ShapeInput extends BaseDefaults {
491
+ position: Point;
492
+ size: Size;
493
+ shape?: ShapeKind;
494
+ strokeColor?: string;
495
+ strokeWidth?: number;
496
+ fillColor?: string;
497
+ }
498
+ declare function createShape(input: ShapeInput): ShapeElement;
467
499
  declare function createText(input: TextInput): TextElement;
468
500
 
469
501
  interface Rect {
@@ -479,6 +511,16 @@ declare function getArrowTangentAngle(from: Point, to: Point, bend: number, t: n
479
511
  declare function isNearBezier(point: Point, from: Point, to: Point, bend: number, threshold: number): boolean;
480
512
  declare function getArrowBounds(from: Point, to: Point, bend: number): Rect;
481
513
 
514
+ declare function isBindable(element: CanvasElement): boolean;
515
+ declare function getElementCenter(element: CanvasElement): Point;
516
+ declare function getElementBounds(element: CanvasElement): Rect | null;
517
+ declare function getEdgeIntersection(bounds: Rect, outsidePoint: Point): Point;
518
+ declare function findBindTarget(point: Point, store: ElementStore, threshold: number, excludeId?: string): CanvasElement | null;
519
+ declare function findBoundArrows(elementId: string, store: ElementStore): ArrowElement[];
520
+ declare function updateBoundArrow(arrow: ArrowElement, store: ElementStore): Partial<ArrowElement> | null;
521
+ declare function clearStaleBindings(arrow: ArrowElement, store: ElementStore): Partial<ArrowElement> | null;
522
+ declare function unbindArrow(arrow: ArrowElement, store: ElementStore): Partial<ArrowElement>;
523
+
482
524
  declare class AddElementCommand implements Command {
483
525
  private readonly element;
484
526
  constructor(element: CanvasElement);
@@ -579,6 +621,7 @@ declare class SelectTool implements Tool {
579
621
  private getHandlePositions;
580
622
  private renderMarquee;
581
623
  private renderSelectionBoxes;
624
+ private renderBindingHighlights;
582
625
  private getMarqueeRect;
583
626
  private findElementsInRect;
584
627
  private rectsOverlap;
@@ -598,6 +641,9 @@ declare class ArrowTool implements Tool {
598
641
  private end;
599
642
  private color;
600
643
  private width;
644
+ private fromBinding;
645
+ private fromTarget;
646
+ private toTarget;
601
647
  constructor(options?: ArrowToolOptions);
602
648
  setOptions(options: ArrowToolOptions): void;
603
649
  onPointerDown(state: PointerState, ctx: ToolContext): void;
@@ -654,6 +700,35 @@ declare class ImageTool implements Tool {
654
700
  onPointerUp(state: PointerState, ctx: ToolContext): void;
655
701
  }
656
702
 
657
- declare const VERSION = "0.3.0";
703
+ interface ShapeToolOptions {
704
+ shape?: ShapeKind;
705
+ strokeColor?: string;
706
+ strokeWidth?: number;
707
+ fillColor?: string;
708
+ }
709
+ declare class ShapeTool implements Tool {
710
+ readonly name = "shape";
711
+ private drawing;
712
+ private start;
713
+ private end;
714
+ private shiftHeld;
715
+ private shape;
716
+ private strokeColor;
717
+ private strokeWidth;
718
+ private fillColor;
719
+ constructor(options?: ShapeToolOptions);
720
+ setOptions(options: ShapeToolOptions): void;
721
+ onActivate(_ctx: ToolContext): void;
722
+ onDeactivate(_ctx: ToolContext): void;
723
+ onPointerDown(state: PointerState, ctx: ToolContext): void;
724
+ onPointerMove(state: PointerState, ctx: ToolContext): void;
725
+ onPointerUp(_state: PointerState, ctx: ToolContext): void;
726
+ renderOverlay(ctx: CanvasRenderingContext2D): void;
727
+ private computeRect;
728
+ private onKeyDown;
729
+ private onKeyUp;
730
+ }
731
+
732
+ declare const VERSION = "0.4.0";
658
733
 
659
- export { AddElementCommand, type ArrowElement, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, Background, type BackgroundOptions, type BackgroundPattern, BatchCommand, type Bounds, Camera, type CameraOptions, type CanvasElement, type CanvasState, type Command, ElementRenderer, ElementStore, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, EventBus, HandTool, HistoryRecorder, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, InputHandler, NoteEditor, type NoteElement, NoteTool, type NoteToolOptions, PencilTool, type PencilToolOptions, type Point, type PointerState, RemoveElementCommand, SelectTool, type Size, type StrokeElement, type StrokePoint, type TextElement, TextTool, type TextToolOptions, type Tool, type ToolContext, ToolManager, type ToolName, UpdateElementCommand, VERSION, Viewport, type ViewportOptions, createArrow, createHtmlElement, createId, createImage, createNote, createStroke, createText, exportState, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, isNearBezier, parseState };
734
+ export { AddElementCommand, type ArrowElement, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, Background, type BackgroundOptions, type BackgroundPattern, BatchCommand, type Binding, type Bounds, Camera, type CameraOptions, type CanvasElement, type CanvasState, type Command, ElementRenderer, ElementStore, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, EventBus, HandTool, HistoryRecorder, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, InputHandler, NoteEditor, type NoteElement, NoteTool, type NoteToolOptions, PencilTool, type PencilToolOptions, type Point, type PointerState, RemoveElementCommand, SelectTool, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type Size, type StrokeElement, type StrokePoint, type TextElement, TextTool, type TextToolOptions, type Tool, type ToolContext, ToolManager, type ToolName, UpdateElementCommand, VERSION, Viewport, type ViewportOptions, clearStaleBindings, createArrow, createHtmlElement, createId, createImage, createNote, createShape, createStroke, createText, exportState, findBindTarget, findBoundArrows, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getEdgeIntersection, getElementBounds, getElementCenter, isBindable, isNearBezier, parseState, unbindArrow, updateBoundArrow };