@fieldnotes/core 0.9.0 → 0.11.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
@@ -59,6 +59,7 @@ interface NoteElement extends BaseElement {
59
59
  text: string;
60
60
  backgroundColor: string;
61
61
  textColor: string;
62
+ fontSize?: number;
62
63
  }
63
64
  interface Binding {
64
65
  elementId: string;
@@ -449,6 +450,28 @@ declare class InputHandler {
449
450
  private cancelToolIfActive;
450
451
  }
451
452
 
453
+ interface FontSizePreset {
454
+ label: string;
455
+ size: number;
456
+ }
457
+ declare const DEFAULT_FONT_SIZE_PRESETS: FontSizePreset[];
458
+ declare class NoteToolbar {
459
+ private el;
460
+ private anchor;
461
+ private selectionListener;
462
+ private readonly fontSizePresets;
463
+ constructor(fontSizePresets?: FontSizePreset[]);
464
+ show(anchor: HTMLElement): void;
465
+ hide(): void;
466
+ getElement(): HTMLDivElement | null;
467
+ updatePosition(anchor: HTMLElement): void;
468
+ private createToolbarElement;
469
+ private createFormatButton;
470
+ private createFontSizeSelect;
471
+ private positionToolbar;
472
+ private updateActiveStates;
473
+ }
474
+
452
475
  interface ExportImageOptions {
453
476
  scale?: number;
454
477
  padding?: number;
@@ -466,9 +489,17 @@ interface RenderStatsSnapshot {
466
489
  frameCount: number;
467
490
  }
468
491
 
492
+ interface GridInfo {
493
+ gridType: 'square' | 'hex';
494
+ hexOrientation: 'pointy' | 'flat';
495
+ cellSize: number;
496
+ cellRadius: number;
497
+ }
469
498
  interface ViewportOptions {
470
499
  camera?: CameraOptions;
471
500
  background?: BackgroundOptions;
501
+ fontSizePresets?: FontSizePreset[];
502
+ toolbar?: boolean;
472
503
  }
473
504
  declare class Viewport {
474
505
  private readonly container;
@@ -494,6 +525,7 @@ declare class Viewport {
494
525
  private readonly renderLoop;
495
526
  private readonly domNodeManager;
496
527
  private readonly interactMode;
528
+ private readonly gridChangeListeners;
497
529
  constructor(container: HTMLElement, options?: ViewportOptions);
498
530
  get ctx(): CanvasRenderingContext2D | null;
499
531
  get snapToGrid(): boolean;
@@ -530,6 +562,8 @@ declare class Viewport {
530
562
  }): string;
531
563
  updateGrid(updates: Partial<Pick<GridElement, 'gridType' | 'hexOrientation' | 'cellSize' | 'strokeColor' | 'strokeWidth' | 'opacity'>>): void;
532
564
  removeGrid(): void;
565
+ getGridInfo(): GridInfo | null;
566
+ onGridChange(listener: (info: GridInfo | null) => void): () => void;
533
567
  getRenderStats(): RenderStatsSnapshot;
534
568
  logPerformance(intervalMs?: number): () => void;
535
569
  destroy(): void;
@@ -547,6 +581,7 @@ declare class Viewport {
547
581
  private applyCameraTransform;
548
582
  private syncCanvasSize;
549
583
  private syncGridContext;
584
+ private notifyGridChangeListeners;
550
585
  private observeResize;
551
586
  }
552
587
 
@@ -581,6 +616,10 @@ declare class ElementRenderer {
581
616
  private getImage;
582
617
  }
583
618
 
619
+ interface NoteEditorOptions {
620
+ fontSizePresets?: FontSizePreset[];
621
+ toolbar?: boolean;
622
+ }
584
623
  declare class NoteEditor {
585
624
  private editingId;
586
625
  private editingNode;
@@ -589,17 +628,46 @@ declare class NoteEditor {
589
628
  private pointerHandler;
590
629
  private pendingEditId;
591
630
  private onStopCallback;
631
+ private toolbar;
632
+ constructor(options?: NoteEditorOptions);
592
633
  get isEditing(): boolean;
593
634
  get editingElementId(): string | null;
594
635
  setOnStop(callback: (elementId: string) => void): void;
595
636
  startEditing(node: HTMLDivElement, elementId: string, store: ElementStore): void;
596
637
  stopEditing(store: ElementStore): void;
597
638
  destroy(store: ElementStore): void;
639
+ updateToolbarPosition(): void;
598
640
  private activateEditing;
599
641
  }
600
642
 
643
+ interface RunStyle {
644
+ bold: boolean;
645
+ italic: boolean;
646
+ underline: boolean;
647
+ strikethrough: boolean;
648
+ fontSize: number;
649
+ }
650
+ interface StyledRun extends RunStyle {
651
+ text: string;
652
+ }
653
+ declare function sanitizeNoteHtml(html: string): string;
654
+
655
+ interface ActiveFormats {
656
+ bold: boolean;
657
+ italic: boolean;
658
+ underline: boolean;
659
+ strikethrough: boolean;
660
+ }
661
+ declare function toggleBold(): void;
662
+ declare function toggleItalic(): void;
663
+ declare function toggleUnderline(): void;
664
+ declare function toggleStrikethrough(): void;
665
+ declare function setFontSize(size: number): void;
666
+ declare function getActiveFormats(): ActiveFormats;
667
+
601
668
  declare function createId(prefix: string): string;
602
669
 
670
+ declare const DEFAULT_NOTE_FONT_SIZE = 18;
603
671
  interface BaseDefaults {
604
672
  position?: Point;
605
673
  zIndex?: number;
@@ -618,6 +686,7 @@ interface NoteInput extends BaseDefaults {
618
686
  text?: string;
619
687
  backgroundColor?: string;
620
688
  textColor?: string;
689
+ fontSize?: number;
621
690
  }
622
691
  interface ArrowInput extends BaseDefaults {
623
692
  from: Point;
@@ -862,12 +931,14 @@ interface NoteToolOptions {
862
931
  backgroundColor?: string;
863
932
  textColor?: string;
864
933
  size?: Size;
934
+ fontSize?: number;
865
935
  }
866
936
  declare class NoteTool implements Tool {
867
937
  readonly name = "note";
868
938
  private backgroundColor;
869
939
  private textColor;
870
940
  private size;
941
+ private fontSize;
871
942
  private optionListeners;
872
943
  constructor(options?: NoteToolOptions);
873
944
  getOptions(): NoteToolOptions;
@@ -1048,6 +1119,6 @@ declare class UpdateLayerCommand implements Command {
1048
1119
  undo(_store: ElementStore): void;
1049
1120
  }
1050
1121
 
1051
- declare const VERSION = "0.9.0";
1122
+ declare const VERSION = "0.11.0";
1052
1123
 
1053
- export { AddElementCommand, type ArrowElement, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, Background, type BackgroundOptions, type BackgroundPattern, BatchCommand, type Binding, type Bounds, Camera, type CameraChangeInfo, type CameraOptions, type CanvasElement, type CanvasState, type Command, CreateLayerCommand, ElementRenderer, ElementStore, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, EventBus, type ExportImageOptions, type GridElement, HandTool, type HexOrientation, HistoryRecorder, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, InputHandler, type Layer, LayerManager, MeasureTool, type MeasureToolOptions, type Measurement, NoteEditor, type NoteElement, NoteTool, type NoteToolOptions, PencilTool, type PencilToolOptions, type Point, type PointerState, Quadtree, RemoveElementCommand, RemoveLayerCommand, type RenderStatsSnapshot, SelectTool, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type Size, type StrokeElement, type StrokePoint, type TemplateElement, type TemplateShape, TemplateTool, type TemplateToolOptions, type TextElement, TextTool, type TextToolOptions, type Tool, type ToolContext, ToolManager, type ToolName, UpdateElementCommand, UpdateLayerCommand, VERSION, Viewport, type ViewportOptions, boundsIntersect, clearStaleBindings, createArrow, createGrid, createHtmlElement, createId, createImage, createNote, createShape, createStroke, createTemplate, createText, drawHexPath, exportImage, exportState, findBindTarget, findBoundArrows, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getEdgeIntersection, getElementBounds, getElementCenter, getHexCellsInCone, getHexCellsInLine, getHexCellsInRadius, getHexCellsInSquare, getHexDistance, isBindable, isNearBezier, parseState, smartSnap, snapPoint, snapToHexCenter, unbindArrow, updateBoundArrow };
1124
+ export { type ActiveFormats, AddElementCommand, type ArrowElement, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, Background, type BackgroundOptions, type BackgroundPattern, BatchCommand, type Binding, type Bounds, Camera, type CameraChangeInfo, type CameraOptions, type CanvasElement, type CanvasState, type Command, CreateLayerCommand, DEFAULT_FONT_SIZE_PRESETS, DEFAULT_NOTE_FONT_SIZE, ElementRenderer, ElementStore, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, EventBus, type ExportImageOptions, type FontSizePreset, type GridElement, type GridInfo, HandTool, type HexOrientation, HistoryRecorder, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, InputHandler, type Layer, LayerManager, MeasureTool, type MeasureToolOptions, type Measurement, NoteEditor, type NoteEditorOptions, type NoteElement, NoteTool, type NoteToolOptions, NoteToolbar, PencilTool, type PencilToolOptions, type Point, type PointerState, Quadtree, RemoveElementCommand, RemoveLayerCommand, type RenderStatsSnapshot, SelectTool, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type Size, type StrokeElement, type StrokePoint, type StyledRun, type TemplateElement, type TemplateShape, TemplateTool, type TemplateToolOptions, type TextElement, TextTool, type TextToolOptions, type Tool, type ToolContext, ToolManager, type ToolName, UpdateElementCommand, UpdateLayerCommand, VERSION, Viewport, type ViewportOptions, boundsIntersect, clearStaleBindings, createArrow, createGrid, createHtmlElement, createId, createImage, createNote, createShape, createStroke, createTemplate, createText, drawHexPath, exportImage, exportState, findBindTarget, findBoundArrows, getActiveFormats, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getEdgeIntersection, getElementBounds, getElementCenter, getHexCellsInCone, getHexCellsInLine, getHexCellsInRadius, getHexCellsInSquare, getHexDistance, isBindable, isNearBezier, parseState, sanitizeNoteHtml, setFontSize, smartSnap, snapPoint, snapToHexCenter, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline, unbindArrow, updateBoundArrow };
package/dist/index.d.ts CHANGED
@@ -59,6 +59,7 @@ interface NoteElement extends BaseElement {
59
59
  text: string;
60
60
  backgroundColor: string;
61
61
  textColor: string;
62
+ fontSize?: number;
62
63
  }
63
64
  interface Binding {
64
65
  elementId: string;
@@ -449,6 +450,28 @@ declare class InputHandler {
449
450
  private cancelToolIfActive;
450
451
  }
451
452
 
453
+ interface FontSizePreset {
454
+ label: string;
455
+ size: number;
456
+ }
457
+ declare const DEFAULT_FONT_SIZE_PRESETS: FontSizePreset[];
458
+ declare class NoteToolbar {
459
+ private el;
460
+ private anchor;
461
+ private selectionListener;
462
+ private readonly fontSizePresets;
463
+ constructor(fontSizePresets?: FontSizePreset[]);
464
+ show(anchor: HTMLElement): void;
465
+ hide(): void;
466
+ getElement(): HTMLDivElement | null;
467
+ updatePosition(anchor: HTMLElement): void;
468
+ private createToolbarElement;
469
+ private createFormatButton;
470
+ private createFontSizeSelect;
471
+ private positionToolbar;
472
+ private updateActiveStates;
473
+ }
474
+
452
475
  interface ExportImageOptions {
453
476
  scale?: number;
454
477
  padding?: number;
@@ -466,9 +489,17 @@ interface RenderStatsSnapshot {
466
489
  frameCount: number;
467
490
  }
468
491
 
492
+ interface GridInfo {
493
+ gridType: 'square' | 'hex';
494
+ hexOrientation: 'pointy' | 'flat';
495
+ cellSize: number;
496
+ cellRadius: number;
497
+ }
469
498
  interface ViewportOptions {
470
499
  camera?: CameraOptions;
471
500
  background?: BackgroundOptions;
501
+ fontSizePresets?: FontSizePreset[];
502
+ toolbar?: boolean;
472
503
  }
473
504
  declare class Viewport {
474
505
  private readonly container;
@@ -494,6 +525,7 @@ declare class Viewport {
494
525
  private readonly renderLoop;
495
526
  private readonly domNodeManager;
496
527
  private readonly interactMode;
528
+ private readonly gridChangeListeners;
497
529
  constructor(container: HTMLElement, options?: ViewportOptions);
498
530
  get ctx(): CanvasRenderingContext2D | null;
499
531
  get snapToGrid(): boolean;
@@ -530,6 +562,8 @@ declare class Viewport {
530
562
  }): string;
531
563
  updateGrid(updates: Partial<Pick<GridElement, 'gridType' | 'hexOrientation' | 'cellSize' | 'strokeColor' | 'strokeWidth' | 'opacity'>>): void;
532
564
  removeGrid(): void;
565
+ getGridInfo(): GridInfo | null;
566
+ onGridChange(listener: (info: GridInfo | null) => void): () => void;
533
567
  getRenderStats(): RenderStatsSnapshot;
534
568
  logPerformance(intervalMs?: number): () => void;
535
569
  destroy(): void;
@@ -547,6 +581,7 @@ declare class Viewport {
547
581
  private applyCameraTransform;
548
582
  private syncCanvasSize;
549
583
  private syncGridContext;
584
+ private notifyGridChangeListeners;
550
585
  private observeResize;
551
586
  }
552
587
 
@@ -581,6 +616,10 @@ declare class ElementRenderer {
581
616
  private getImage;
582
617
  }
583
618
 
619
+ interface NoteEditorOptions {
620
+ fontSizePresets?: FontSizePreset[];
621
+ toolbar?: boolean;
622
+ }
584
623
  declare class NoteEditor {
585
624
  private editingId;
586
625
  private editingNode;
@@ -589,17 +628,46 @@ declare class NoteEditor {
589
628
  private pointerHandler;
590
629
  private pendingEditId;
591
630
  private onStopCallback;
631
+ private toolbar;
632
+ constructor(options?: NoteEditorOptions);
592
633
  get isEditing(): boolean;
593
634
  get editingElementId(): string | null;
594
635
  setOnStop(callback: (elementId: string) => void): void;
595
636
  startEditing(node: HTMLDivElement, elementId: string, store: ElementStore): void;
596
637
  stopEditing(store: ElementStore): void;
597
638
  destroy(store: ElementStore): void;
639
+ updateToolbarPosition(): void;
598
640
  private activateEditing;
599
641
  }
600
642
 
643
+ interface RunStyle {
644
+ bold: boolean;
645
+ italic: boolean;
646
+ underline: boolean;
647
+ strikethrough: boolean;
648
+ fontSize: number;
649
+ }
650
+ interface StyledRun extends RunStyle {
651
+ text: string;
652
+ }
653
+ declare function sanitizeNoteHtml(html: string): string;
654
+
655
+ interface ActiveFormats {
656
+ bold: boolean;
657
+ italic: boolean;
658
+ underline: boolean;
659
+ strikethrough: boolean;
660
+ }
661
+ declare function toggleBold(): void;
662
+ declare function toggleItalic(): void;
663
+ declare function toggleUnderline(): void;
664
+ declare function toggleStrikethrough(): void;
665
+ declare function setFontSize(size: number): void;
666
+ declare function getActiveFormats(): ActiveFormats;
667
+
601
668
  declare function createId(prefix: string): string;
602
669
 
670
+ declare const DEFAULT_NOTE_FONT_SIZE = 18;
603
671
  interface BaseDefaults {
604
672
  position?: Point;
605
673
  zIndex?: number;
@@ -618,6 +686,7 @@ interface NoteInput extends BaseDefaults {
618
686
  text?: string;
619
687
  backgroundColor?: string;
620
688
  textColor?: string;
689
+ fontSize?: number;
621
690
  }
622
691
  interface ArrowInput extends BaseDefaults {
623
692
  from: Point;
@@ -862,12 +931,14 @@ interface NoteToolOptions {
862
931
  backgroundColor?: string;
863
932
  textColor?: string;
864
933
  size?: Size;
934
+ fontSize?: number;
865
935
  }
866
936
  declare class NoteTool implements Tool {
867
937
  readonly name = "note";
868
938
  private backgroundColor;
869
939
  private textColor;
870
940
  private size;
941
+ private fontSize;
871
942
  private optionListeners;
872
943
  constructor(options?: NoteToolOptions);
873
944
  getOptions(): NoteToolOptions;
@@ -1048,6 +1119,6 @@ declare class UpdateLayerCommand implements Command {
1048
1119
  undo(_store: ElementStore): void;
1049
1120
  }
1050
1121
 
1051
- declare const VERSION = "0.9.0";
1122
+ declare const VERSION = "0.11.0";
1052
1123
 
1053
- export { AddElementCommand, type ArrowElement, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, Background, type BackgroundOptions, type BackgroundPattern, BatchCommand, type Binding, type Bounds, Camera, type CameraChangeInfo, type CameraOptions, type CanvasElement, type CanvasState, type Command, CreateLayerCommand, ElementRenderer, ElementStore, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, EventBus, type ExportImageOptions, type GridElement, HandTool, type HexOrientation, HistoryRecorder, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, InputHandler, type Layer, LayerManager, MeasureTool, type MeasureToolOptions, type Measurement, NoteEditor, type NoteElement, NoteTool, type NoteToolOptions, PencilTool, type PencilToolOptions, type Point, type PointerState, Quadtree, RemoveElementCommand, RemoveLayerCommand, type RenderStatsSnapshot, SelectTool, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type Size, type StrokeElement, type StrokePoint, type TemplateElement, type TemplateShape, TemplateTool, type TemplateToolOptions, type TextElement, TextTool, type TextToolOptions, type Tool, type ToolContext, ToolManager, type ToolName, UpdateElementCommand, UpdateLayerCommand, VERSION, Viewport, type ViewportOptions, boundsIntersect, clearStaleBindings, createArrow, createGrid, createHtmlElement, createId, createImage, createNote, createShape, createStroke, createTemplate, createText, drawHexPath, exportImage, exportState, findBindTarget, findBoundArrows, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getEdgeIntersection, getElementBounds, getElementCenter, getHexCellsInCone, getHexCellsInLine, getHexCellsInRadius, getHexCellsInSquare, getHexDistance, isBindable, isNearBezier, parseState, smartSnap, snapPoint, snapToHexCenter, unbindArrow, updateBoundArrow };
1124
+ export { type ActiveFormats, AddElementCommand, type ArrowElement, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, Background, type BackgroundOptions, type BackgroundPattern, BatchCommand, type Binding, type Bounds, Camera, type CameraChangeInfo, type CameraOptions, type CanvasElement, type CanvasState, type Command, CreateLayerCommand, DEFAULT_FONT_SIZE_PRESETS, DEFAULT_NOTE_FONT_SIZE, ElementRenderer, ElementStore, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, EventBus, type ExportImageOptions, type FontSizePreset, type GridElement, type GridInfo, HandTool, type HexOrientation, HistoryRecorder, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, InputHandler, type Layer, LayerManager, MeasureTool, type MeasureToolOptions, type Measurement, NoteEditor, type NoteEditorOptions, type NoteElement, NoteTool, type NoteToolOptions, NoteToolbar, PencilTool, type PencilToolOptions, type Point, type PointerState, Quadtree, RemoveElementCommand, RemoveLayerCommand, type RenderStatsSnapshot, SelectTool, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type Size, type StrokeElement, type StrokePoint, type StyledRun, type TemplateElement, type TemplateShape, TemplateTool, type TemplateToolOptions, type TextElement, TextTool, type TextToolOptions, type Tool, type ToolContext, ToolManager, type ToolName, UpdateElementCommand, UpdateLayerCommand, VERSION, Viewport, type ViewportOptions, boundsIntersect, clearStaleBindings, createArrow, createGrid, createHtmlElement, createId, createImage, createNote, createShape, createStroke, createTemplate, createText, drawHexPath, exportImage, exportState, findBindTarget, findBoundArrows, getActiveFormats, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getEdgeIntersection, getElementBounds, getElementCenter, getHexCellsInCone, getHexCellsInLine, getHexCellsInRadius, getHexCellsInSquare, getHexDistance, isBindable, isNearBezier, parseState, sanitizeNoteHtml, setFontSize, smartSnap, snapPoint, snapToHexCenter, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline, unbindArrow, updateBoundArrow };