@fieldnotes/core 0.2.3 → 0.3.1

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';
@@ -61,7 +66,15 @@ interface HtmlElement extends BaseElement {
61
66
  type: 'html';
62
67
  size: Size;
63
68
  }
64
- type CanvasElement = StrokeElement | NoteElement | ArrowElement | ImageElement | HtmlElement;
69
+ interface TextElement extends BaseElement {
70
+ type: 'text';
71
+ size: Size;
72
+ text: string;
73
+ fontSize: number;
74
+ color: string;
75
+ textAlign: 'left' | 'center' | 'right';
76
+ }
77
+ type CanvasElement = StrokeElement | NoteElement | ArrowElement | ImageElement | HtmlElement | TextElement;
65
78
  type ElementType = CanvasElement['type'];
66
79
 
67
80
  interface CanvasState {
@@ -196,7 +209,7 @@ interface Tool {
196
209
  onDeactivate?(ctx: ToolContext): void;
197
210
  renderOverlay?(ctx: CanvasRenderingContext2D): void;
198
211
  }
199
- type ToolName = 'hand' | 'select' | 'pencil' | 'eraser' | 'arrow' | 'note' | 'image';
212
+ type ToolName = 'hand' | 'select' | 'pencil' | 'eraser' | 'arrow' | 'note' | 'image' | 'text';
200
213
 
201
214
  declare class ToolManager {
202
215
  private tools;
@@ -360,7 +373,8 @@ declare class Viewport {
360
373
  destroy(): void;
361
374
  private startRenderLoop;
362
375
  private render;
363
- private startEditingNote;
376
+ private startEditingElement;
377
+ private onTextEditStop;
364
378
  private onDblClick;
365
379
  private hitTestWorld;
366
380
  private startInteracting;
@@ -372,6 +386,7 @@ declare class Viewport {
372
386
  private onDrop;
373
387
  private syncDomNode;
374
388
  private renderDomContent;
389
+ private unbindArrowsFrom;
375
390
  private removeDomNode;
376
391
  private clearDomNodes;
377
392
  private createWrapper;
@@ -383,11 +398,14 @@ declare class Viewport {
383
398
  }
384
399
 
385
400
  declare class ElementRenderer {
401
+ private store;
402
+ setStore(store: ElementStore): void;
386
403
  isDomElement(element: CanvasElement): boolean;
387
404
  renderCanvasElement(ctx: CanvasRenderingContext2D, element: CanvasElement): void;
388
405
  private renderStroke;
389
406
  private renderArrow;
390
407
  private renderArrowhead;
408
+ private getVisualEndpoints;
391
409
  }
392
410
 
393
411
  declare class NoteEditor {
@@ -397,8 +415,10 @@ declare class NoteEditor {
397
415
  private keyHandler;
398
416
  private pointerHandler;
399
417
  private pendingEditId;
418
+ private onStopCallback;
400
419
  get isEditing(): boolean;
401
420
  get editingElementId(): string | null;
421
+ setOnStop(callback: (elementId: string) => void): void;
402
422
  startEditing(node: HTMLDivElement, elementId: string, store: ElementStore): void;
403
423
  stopEditing(store: ElementStore): void;
404
424
  destroy(store: ElementStore): void;
@@ -430,6 +450,8 @@ interface ArrowInput extends BaseDefaults {
430
450
  bend?: number;
431
451
  color?: string;
432
452
  width?: number;
453
+ fromBinding?: Binding;
454
+ toBinding?: Binding;
433
455
  }
434
456
  interface ImageInput extends BaseDefaults {
435
457
  position: Point;
@@ -440,11 +462,20 @@ interface HtmlInput extends BaseDefaults {
440
462
  position: Point;
441
463
  size: Size;
442
464
  }
465
+ interface TextInput extends BaseDefaults {
466
+ position: Point;
467
+ size?: Size;
468
+ text?: string;
469
+ fontSize?: number;
470
+ color?: string;
471
+ textAlign?: 'left' | 'center' | 'right';
472
+ }
443
473
  declare function createStroke(input: StrokeInput): StrokeElement;
444
474
  declare function createNote(input: NoteInput): NoteElement;
445
475
  declare function createArrow(input: ArrowInput): ArrowElement;
446
476
  declare function createImage(input: ImageInput): ImageElement;
447
477
  declare function createHtmlElement(input: HtmlInput): HtmlElement;
478
+ declare function createText(input: TextInput): TextElement;
448
479
 
449
480
  interface Rect {
450
481
  x: number;
@@ -459,6 +490,16 @@ declare function getArrowTangentAngle(from: Point, to: Point, bend: number, t: n
459
490
  declare function isNearBezier(point: Point, from: Point, to: Point, bend: number, threshold: number): boolean;
460
491
  declare function getArrowBounds(from: Point, to: Point, bend: number): Rect;
461
492
 
493
+ declare function isBindable(element: CanvasElement): boolean;
494
+ declare function getElementCenter(element: CanvasElement): Point;
495
+ declare function getElementBounds(element: CanvasElement): Rect | null;
496
+ declare function getEdgeIntersection(bounds: Rect, outsidePoint: Point): Point;
497
+ declare function findBindTarget(point: Point, store: ElementStore, threshold: number, excludeId?: string): CanvasElement | null;
498
+ declare function findBoundArrows(elementId: string, store: ElementStore): ArrowElement[];
499
+ declare function updateBoundArrow(arrow: ArrowElement, store: ElementStore): Partial<ArrowElement> | null;
500
+ declare function clearStaleBindings(arrow: ArrowElement, store: ElementStore): Partial<ArrowElement> | null;
501
+ declare function unbindArrow(arrow: ArrowElement, store: ElementStore): Partial<ArrowElement>;
502
+
462
503
  declare class AddElementCommand implements Command {
463
504
  private readonly element;
464
505
  constructor(element: CanvasElement);
@@ -559,6 +600,7 @@ declare class SelectTool implements Tool {
559
600
  private getHandlePositions;
560
601
  private renderMarquee;
561
602
  private renderSelectionBoxes;
603
+ private renderBindingHighlights;
562
604
  private getMarqueeRect;
563
605
  private findElementsInRect;
564
606
  private rectsOverlap;
@@ -578,6 +620,9 @@ declare class ArrowTool implements Tool {
578
620
  private end;
579
621
  private color;
580
622
  private width;
623
+ private fromBinding;
624
+ private fromTarget;
625
+ private toTarget;
581
626
  constructor(options?: ArrowToolOptions);
582
627
  setOptions(options: ArrowToolOptions): void;
583
628
  onPointerDown(state: PointerState, ctx: ToolContext): void;
@@ -601,6 +646,25 @@ declare class NoteTool implements Tool {
601
646
  onPointerUp(state: PointerState, ctx: ToolContext): void;
602
647
  }
603
648
 
649
+ interface TextToolOptions {
650
+ fontSize?: number;
651
+ color?: string;
652
+ textAlign?: 'left' | 'center' | 'right';
653
+ }
654
+ declare class TextTool implements Tool {
655
+ readonly name = "text";
656
+ private fontSize;
657
+ private color;
658
+ private textAlign;
659
+ constructor(options?: TextToolOptions);
660
+ setOptions(options: TextToolOptions): void;
661
+ onActivate(ctx: ToolContext): void;
662
+ onDeactivate(ctx: ToolContext): void;
663
+ onPointerDown(_state: PointerState, _ctx: ToolContext): void;
664
+ onPointerMove(_state: PointerState, _ctx: ToolContext): void;
665
+ onPointerUp(state: PointerState, ctx: ToolContext): void;
666
+ }
667
+
604
668
  interface ImageToolOptions {
605
669
  size?: Size;
606
670
  }
@@ -615,6 +679,6 @@ declare class ImageTool implements Tool {
615
679
  onPointerUp(state: PointerState, ctx: ToolContext): void;
616
680
  }
617
681
 
618
- declare const VERSION = "0.2.3";
682
+ declare const VERSION = "0.3.1";
619
683
 
620
- 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 Tool, type ToolContext, ToolManager, type ToolName, UpdateElementCommand, VERSION, Viewport, type ViewportOptions, createArrow, createHtmlElement, createId, createImage, createNote, createStroke, exportState, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, isNearBezier, parseState };
684
+ 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 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, 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';
@@ -61,7 +66,15 @@ interface HtmlElement extends BaseElement {
61
66
  type: 'html';
62
67
  size: Size;
63
68
  }
64
- type CanvasElement = StrokeElement | NoteElement | ArrowElement | ImageElement | HtmlElement;
69
+ interface TextElement extends BaseElement {
70
+ type: 'text';
71
+ size: Size;
72
+ text: string;
73
+ fontSize: number;
74
+ color: string;
75
+ textAlign: 'left' | 'center' | 'right';
76
+ }
77
+ type CanvasElement = StrokeElement | NoteElement | ArrowElement | ImageElement | HtmlElement | TextElement;
65
78
  type ElementType = CanvasElement['type'];
66
79
 
67
80
  interface CanvasState {
@@ -196,7 +209,7 @@ interface Tool {
196
209
  onDeactivate?(ctx: ToolContext): void;
197
210
  renderOverlay?(ctx: CanvasRenderingContext2D): void;
198
211
  }
199
- type ToolName = 'hand' | 'select' | 'pencil' | 'eraser' | 'arrow' | 'note' | 'image';
212
+ type ToolName = 'hand' | 'select' | 'pencil' | 'eraser' | 'arrow' | 'note' | 'image' | 'text';
200
213
 
201
214
  declare class ToolManager {
202
215
  private tools;
@@ -360,7 +373,8 @@ declare class Viewport {
360
373
  destroy(): void;
361
374
  private startRenderLoop;
362
375
  private render;
363
- private startEditingNote;
376
+ private startEditingElement;
377
+ private onTextEditStop;
364
378
  private onDblClick;
365
379
  private hitTestWorld;
366
380
  private startInteracting;
@@ -372,6 +386,7 @@ declare class Viewport {
372
386
  private onDrop;
373
387
  private syncDomNode;
374
388
  private renderDomContent;
389
+ private unbindArrowsFrom;
375
390
  private removeDomNode;
376
391
  private clearDomNodes;
377
392
  private createWrapper;
@@ -383,11 +398,14 @@ declare class Viewport {
383
398
  }
384
399
 
385
400
  declare class ElementRenderer {
401
+ private store;
402
+ setStore(store: ElementStore): void;
386
403
  isDomElement(element: CanvasElement): boolean;
387
404
  renderCanvasElement(ctx: CanvasRenderingContext2D, element: CanvasElement): void;
388
405
  private renderStroke;
389
406
  private renderArrow;
390
407
  private renderArrowhead;
408
+ private getVisualEndpoints;
391
409
  }
392
410
 
393
411
  declare class NoteEditor {
@@ -397,8 +415,10 @@ declare class NoteEditor {
397
415
  private keyHandler;
398
416
  private pointerHandler;
399
417
  private pendingEditId;
418
+ private onStopCallback;
400
419
  get isEditing(): boolean;
401
420
  get editingElementId(): string | null;
421
+ setOnStop(callback: (elementId: string) => void): void;
402
422
  startEditing(node: HTMLDivElement, elementId: string, store: ElementStore): void;
403
423
  stopEditing(store: ElementStore): void;
404
424
  destroy(store: ElementStore): void;
@@ -430,6 +450,8 @@ interface ArrowInput extends BaseDefaults {
430
450
  bend?: number;
431
451
  color?: string;
432
452
  width?: number;
453
+ fromBinding?: Binding;
454
+ toBinding?: Binding;
433
455
  }
434
456
  interface ImageInput extends BaseDefaults {
435
457
  position: Point;
@@ -440,11 +462,20 @@ interface HtmlInput extends BaseDefaults {
440
462
  position: Point;
441
463
  size: Size;
442
464
  }
465
+ interface TextInput extends BaseDefaults {
466
+ position: Point;
467
+ size?: Size;
468
+ text?: string;
469
+ fontSize?: number;
470
+ color?: string;
471
+ textAlign?: 'left' | 'center' | 'right';
472
+ }
443
473
  declare function createStroke(input: StrokeInput): StrokeElement;
444
474
  declare function createNote(input: NoteInput): NoteElement;
445
475
  declare function createArrow(input: ArrowInput): ArrowElement;
446
476
  declare function createImage(input: ImageInput): ImageElement;
447
477
  declare function createHtmlElement(input: HtmlInput): HtmlElement;
478
+ declare function createText(input: TextInput): TextElement;
448
479
 
449
480
  interface Rect {
450
481
  x: number;
@@ -459,6 +490,16 @@ declare function getArrowTangentAngle(from: Point, to: Point, bend: number, t: n
459
490
  declare function isNearBezier(point: Point, from: Point, to: Point, bend: number, threshold: number): boolean;
460
491
  declare function getArrowBounds(from: Point, to: Point, bend: number): Rect;
461
492
 
493
+ declare function isBindable(element: CanvasElement): boolean;
494
+ declare function getElementCenter(element: CanvasElement): Point;
495
+ declare function getElementBounds(element: CanvasElement): Rect | null;
496
+ declare function getEdgeIntersection(bounds: Rect, outsidePoint: Point): Point;
497
+ declare function findBindTarget(point: Point, store: ElementStore, threshold: number, excludeId?: string): CanvasElement | null;
498
+ declare function findBoundArrows(elementId: string, store: ElementStore): ArrowElement[];
499
+ declare function updateBoundArrow(arrow: ArrowElement, store: ElementStore): Partial<ArrowElement> | null;
500
+ declare function clearStaleBindings(arrow: ArrowElement, store: ElementStore): Partial<ArrowElement> | null;
501
+ declare function unbindArrow(arrow: ArrowElement, store: ElementStore): Partial<ArrowElement>;
502
+
462
503
  declare class AddElementCommand implements Command {
463
504
  private readonly element;
464
505
  constructor(element: CanvasElement);
@@ -559,6 +600,7 @@ declare class SelectTool implements Tool {
559
600
  private getHandlePositions;
560
601
  private renderMarquee;
561
602
  private renderSelectionBoxes;
603
+ private renderBindingHighlights;
562
604
  private getMarqueeRect;
563
605
  private findElementsInRect;
564
606
  private rectsOverlap;
@@ -578,6 +620,9 @@ declare class ArrowTool implements Tool {
578
620
  private end;
579
621
  private color;
580
622
  private width;
623
+ private fromBinding;
624
+ private fromTarget;
625
+ private toTarget;
581
626
  constructor(options?: ArrowToolOptions);
582
627
  setOptions(options: ArrowToolOptions): void;
583
628
  onPointerDown(state: PointerState, ctx: ToolContext): void;
@@ -601,6 +646,25 @@ declare class NoteTool implements Tool {
601
646
  onPointerUp(state: PointerState, ctx: ToolContext): void;
602
647
  }
603
648
 
649
+ interface TextToolOptions {
650
+ fontSize?: number;
651
+ color?: string;
652
+ textAlign?: 'left' | 'center' | 'right';
653
+ }
654
+ declare class TextTool implements Tool {
655
+ readonly name = "text";
656
+ private fontSize;
657
+ private color;
658
+ private textAlign;
659
+ constructor(options?: TextToolOptions);
660
+ setOptions(options: TextToolOptions): void;
661
+ onActivate(ctx: ToolContext): void;
662
+ onDeactivate(ctx: ToolContext): void;
663
+ onPointerDown(_state: PointerState, _ctx: ToolContext): void;
664
+ onPointerMove(_state: PointerState, _ctx: ToolContext): void;
665
+ onPointerUp(state: PointerState, ctx: ToolContext): void;
666
+ }
667
+
604
668
  interface ImageToolOptions {
605
669
  size?: Size;
606
670
  }
@@ -615,6 +679,6 @@ declare class ImageTool implements Tool {
615
679
  onPointerUp(state: PointerState, ctx: ToolContext): void;
616
680
  }
617
681
 
618
- declare const VERSION = "0.2.3";
682
+ declare const VERSION = "0.3.1";
619
683
 
620
- 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 Tool, type ToolContext, ToolManager, type ToolName, UpdateElementCommand, VERSION, Viewport, type ViewportOptions, createArrow, createHtmlElement, createId, createImage, createNote, createStroke, exportState, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, isNearBezier, parseState };
684
+ 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 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, createStroke, createText, exportState, findBindTarget, findBoundArrows, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getEdgeIntersection, getElementBounds, getElementCenter, isBindable, isNearBezier, parseState, unbindArrow, updateBoundArrow };