@fieldnotes/core 0.8.6 → 0.8.8

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
@@ -24,6 +24,20 @@ interface Size {
24
24
  }
25
25
  type Bounds = Point & Size;
26
26
 
27
+ declare class Quadtree {
28
+ private root;
29
+ private _size;
30
+ private readonly worldBounds;
31
+ constructor(worldBounds: Bounds);
32
+ get size(): number;
33
+ insert(id: string, bounds: Bounds): void;
34
+ remove(id: string): void;
35
+ update(id: string, newBounds: Bounds): void;
36
+ query(rect: Bounds): string[];
37
+ queryPoint(point: Point): string[];
38
+ clear(): void;
39
+ }
40
+
27
41
  interface BaseElement {
28
42
  id: string;
29
43
  type: string;
@@ -58,6 +72,8 @@ interface ArrowElement extends BaseElement {
58
72
  width: number;
59
73
  fromBinding?: Binding;
60
74
  toBinding?: Binding;
75
+ /** Derived from from/to/bend. Redundant in serialized state — safe to omit. */
76
+ cachedControlPoint?: Point;
61
77
  }
62
78
  interface ImageElement extends BaseElement {
63
79
  type: 'image';
@@ -139,6 +155,7 @@ declare class ElementStore {
139
155
  private elements;
140
156
  private bus;
141
157
  private layerOrderMap;
158
+ private spatialIndex;
142
159
  get count(): number;
143
160
  setLayerOrder(order: Map<string, number>): void;
144
161
  getAll(): CanvasElement[];
@@ -152,6 +169,8 @@ declare class ElementStore {
152
169
  clear(): void;
153
170
  snapshot(): CanvasElement[];
154
171
  loadSnapshot(elements: CanvasElement[]): void;
172
+ queryRect(rect: Bounds): CanvasElement[];
173
+ queryPoint(point: Point): CanvasElement[];
155
174
  on<K extends keyof ElementStoreEvents>(event: K, listener: (data: ElementStoreEvents[K]) => void): () => void;
156
175
  onChange(listener: () => void): () => void;
157
176
  }
@@ -160,6 +179,10 @@ interface CameraOptions {
160
179
  minZoom?: number;
161
180
  maxZoom?: number;
162
181
  }
182
+ interface CameraChangeInfo {
183
+ panned: boolean;
184
+ zoomed: boolean;
185
+ }
163
186
  declare class Camera {
164
187
  private x;
165
188
  private y;
@@ -176,9 +199,12 @@ declare class Camera {
176
199
  zoomAt(level: number, screenPoint: Point): void;
177
200
  screenToWorld(screen: Point): Point;
178
201
  worldToScreen(world: Point): Point;
202
+ getVisibleRect(canvasWidth: number, canvasHeight: number): Bounds;
179
203
  toCSSTransform(): string;
180
- onChange(listener: () => void): () => void;
181
- private notifyChange;
204
+ onChange(listener: (info: CameraChangeInfo) => void): () => void;
205
+ private notifyPan;
206
+ private notifyZoom;
207
+ private notifyPanAndZoom;
182
208
  }
183
209
 
184
210
  declare class LayerManager {
@@ -249,8 +275,16 @@ declare class Background {
249
275
  private readonly color;
250
276
  private readonly dotRadius;
251
277
  private readonly lineWidth;
278
+ private cachedCanvas;
279
+ private cachedCtx;
280
+ private lastZoom;
281
+ private lastOffsetX;
282
+ private lastOffsetY;
283
+ private lastWidth;
284
+ private lastHeight;
252
285
  constructor(options?: BackgroundOptions);
253
286
  render(ctx: CanvasRenderingContext2D, camera: Camera): void;
287
+ private ensureCachedCanvas;
254
288
  private adaptSpacing;
255
289
  private renderDots;
256
290
  private renderGrid;
@@ -487,6 +521,14 @@ declare class Viewport {
487
521
  private observeResize;
488
522
  }
489
523
 
524
+ interface RenderStatsSnapshot {
525
+ fps: number;
526
+ avgFrameMs: number;
527
+ p95FrameMs: number;
528
+ lastFrameMs: number;
529
+ frameCount: number;
530
+ }
531
+
490
532
  declare class ElementRenderer {
491
533
  private store;
492
534
  private imageCache;
@@ -601,29 +643,25 @@ interface GridInput extends BaseDefaults {
601
643
  declare function createGrid(input: GridInput): GridElement;
602
644
  declare function createText(input: TextInput): TextElement;
603
645
 
604
- interface Rect {
605
- x: number;
606
- y: number;
607
- w: number;
608
- h: number;
609
- }
610
646
  declare function getArrowControlPoint(from: Point, to: Point, bend: number): Point;
611
647
  declare function getArrowMidpoint(from: Point, to: Point, bend: number): Point;
612
648
  declare function getBendFromPoint(from: Point, to: Point, dragPoint: Point): number;
613
649
  declare function getArrowTangentAngle(from: Point, to: Point, bend: number, t: number): number;
614
650
  declare function isNearBezier(point: Point, from: Point, to: Point, bend: number, threshold: number): boolean;
615
- declare function getArrowBounds(from: Point, to: Point, bend: number): Rect;
651
+ declare function getArrowBounds(from: Point, to: Point, bend: number): Bounds;
616
652
 
617
653
  declare function isBindable(element: CanvasElement): boolean;
618
654
  declare function getElementCenter(element: CanvasElement): Point;
619
- declare function getElementBounds(element: CanvasElement): Rect | null;
620
- declare function getEdgeIntersection(bounds: Rect, outsidePoint: Point): Point;
655
+ declare function getEdgeIntersection(bounds: Bounds, outsidePoint: Point): Point;
621
656
  declare function findBindTarget(point: Point, store: ElementStore, threshold: number, excludeId?: string, filter?: (el: CanvasElement) => boolean): CanvasElement | null;
622
657
  declare function findBoundArrows(elementId: string, store: ElementStore): ArrowElement[];
623
658
  declare function updateBoundArrow(arrow: ArrowElement, store: ElementStore): Partial<ArrowElement> | null;
624
659
  declare function clearStaleBindings(arrow: ArrowElement, store: ElementStore): Partial<ArrowElement> | null;
625
660
  declare function unbindArrow(arrow: ArrowElement, store: ElementStore): Partial<ArrowElement>;
626
661
 
662
+ declare function getElementBounds(element: CanvasElement): Bounds | null;
663
+ declare function boundsIntersect(a: Bounds, b: Bounds): boolean;
664
+
627
665
  declare class AddElementCommand implements Command {
628
666
  private readonly element;
629
667
  constructor(element: CanvasElement);
@@ -666,6 +704,8 @@ interface PencilToolOptions {
666
704
  color?: string;
667
705
  width?: number;
668
706
  smoothing?: number;
707
+ minPointDistance?: number;
708
+ progressiveSimplifyThreshold?: number;
669
709
  }
670
710
  declare class PencilTool implements Tool {
671
711
  readonly name = "pencil";
@@ -674,6 +714,9 @@ declare class PencilTool implements Tool {
674
714
  private color;
675
715
  private width;
676
716
  private smoothing;
717
+ private minPointDistance;
718
+ private progressiveThreshold;
719
+ private nextSimplifyAt;
677
720
  private optionListeners;
678
721
  constructor(options?: PencilToolOptions);
679
722
  onActivate(ctx: ToolContext): void;
@@ -734,7 +777,6 @@ declare class SelectTool implements Tool {
734
777
  private getMarqueeRect;
735
778
  private findElementsInRect;
736
779
  private rectsOverlap;
737
- private getElementBounds;
738
780
  private hitTest;
739
781
  private isInsideBounds;
740
782
  }
@@ -882,6 +924,6 @@ declare class UpdateLayerCommand implements Command {
882
924
  undo(_store: ElementStore): void;
883
925
  }
884
926
 
885
- declare const VERSION = "0.8.6";
927
+ declare const VERSION = "0.8.8";
886
928
 
887
- 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, 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, NoteEditor, type NoteElement, NoteTool, type NoteToolOptions, PencilTool, type PencilToolOptions, type Point, type PointerState, RemoveElementCommand, RemoveLayerCommand, 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, UpdateLayerCommand, VERSION, Viewport, type ViewportOptions, clearStaleBindings, createArrow, createGrid, createHtmlElement, createId, createImage, createNote, createShape, createStroke, createText, exportImage, exportState, findBindTarget, findBoundArrows, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getEdgeIntersection, getElementBounds, getElementCenter, isBindable, isNearBezier, parseState, snapPoint, unbindArrow, updateBoundArrow };
929
+ 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, 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 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, createText, exportImage, exportState, findBindTarget, findBoundArrows, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getEdgeIntersection, getElementBounds, getElementCenter, isBindable, isNearBezier, parseState, snapPoint, unbindArrow, updateBoundArrow };
package/dist/index.d.ts CHANGED
@@ -24,6 +24,20 @@ interface Size {
24
24
  }
25
25
  type Bounds = Point & Size;
26
26
 
27
+ declare class Quadtree {
28
+ private root;
29
+ private _size;
30
+ private readonly worldBounds;
31
+ constructor(worldBounds: Bounds);
32
+ get size(): number;
33
+ insert(id: string, bounds: Bounds): void;
34
+ remove(id: string): void;
35
+ update(id: string, newBounds: Bounds): void;
36
+ query(rect: Bounds): string[];
37
+ queryPoint(point: Point): string[];
38
+ clear(): void;
39
+ }
40
+
27
41
  interface BaseElement {
28
42
  id: string;
29
43
  type: string;
@@ -58,6 +72,8 @@ interface ArrowElement extends BaseElement {
58
72
  width: number;
59
73
  fromBinding?: Binding;
60
74
  toBinding?: Binding;
75
+ /** Derived from from/to/bend. Redundant in serialized state — safe to omit. */
76
+ cachedControlPoint?: Point;
61
77
  }
62
78
  interface ImageElement extends BaseElement {
63
79
  type: 'image';
@@ -139,6 +155,7 @@ declare class ElementStore {
139
155
  private elements;
140
156
  private bus;
141
157
  private layerOrderMap;
158
+ private spatialIndex;
142
159
  get count(): number;
143
160
  setLayerOrder(order: Map<string, number>): void;
144
161
  getAll(): CanvasElement[];
@@ -152,6 +169,8 @@ declare class ElementStore {
152
169
  clear(): void;
153
170
  snapshot(): CanvasElement[];
154
171
  loadSnapshot(elements: CanvasElement[]): void;
172
+ queryRect(rect: Bounds): CanvasElement[];
173
+ queryPoint(point: Point): CanvasElement[];
155
174
  on<K extends keyof ElementStoreEvents>(event: K, listener: (data: ElementStoreEvents[K]) => void): () => void;
156
175
  onChange(listener: () => void): () => void;
157
176
  }
@@ -160,6 +179,10 @@ interface CameraOptions {
160
179
  minZoom?: number;
161
180
  maxZoom?: number;
162
181
  }
182
+ interface CameraChangeInfo {
183
+ panned: boolean;
184
+ zoomed: boolean;
185
+ }
163
186
  declare class Camera {
164
187
  private x;
165
188
  private y;
@@ -176,9 +199,12 @@ declare class Camera {
176
199
  zoomAt(level: number, screenPoint: Point): void;
177
200
  screenToWorld(screen: Point): Point;
178
201
  worldToScreen(world: Point): Point;
202
+ getVisibleRect(canvasWidth: number, canvasHeight: number): Bounds;
179
203
  toCSSTransform(): string;
180
- onChange(listener: () => void): () => void;
181
- private notifyChange;
204
+ onChange(listener: (info: CameraChangeInfo) => void): () => void;
205
+ private notifyPan;
206
+ private notifyZoom;
207
+ private notifyPanAndZoom;
182
208
  }
183
209
 
184
210
  declare class LayerManager {
@@ -249,8 +275,16 @@ declare class Background {
249
275
  private readonly color;
250
276
  private readonly dotRadius;
251
277
  private readonly lineWidth;
278
+ private cachedCanvas;
279
+ private cachedCtx;
280
+ private lastZoom;
281
+ private lastOffsetX;
282
+ private lastOffsetY;
283
+ private lastWidth;
284
+ private lastHeight;
252
285
  constructor(options?: BackgroundOptions);
253
286
  render(ctx: CanvasRenderingContext2D, camera: Camera): void;
287
+ private ensureCachedCanvas;
254
288
  private adaptSpacing;
255
289
  private renderDots;
256
290
  private renderGrid;
@@ -487,6 +521,14 @@ declare class Viewport {
487
521
  private observeResize;
488
522
  }
489
523
 
524
+ interface RenderStatsSnapshot {
525
+ fps: number;
526
+ avgFrameMs: number;
527
+ p95FrameMs: number;
528
+ lastFrameMs: number;
529
+ frameCount: number;
530
+ }
531
+
490
532
  declare class ElementRenderer {
491
533
  private store;
492
534
  private imageCache;
@@ -601,29 +643,25 @@ interface GridInput extends BaseDefaults {
601
643
  declare function createGrid(input: GridInput): GridElement;
602
644
  declare function createText(input: TextInput): TextElement;
603
645
 
604
- interface Rect {
605
- x: number;
606
- y: number;
607
- w: number;
608
- h: number;
609
- }
610
646
  declare function getArrowControlPoint(from: Point, to: Point, bend: number): Point;
611
647
  declare function getArrowMidpoint(from: Point, to: Point, bend: number): Point;
612
648
  declare function getBendFromPoint(from: Point, to: Point, dragPoint: Point): number;
613
649
  declare function getArrowTangentAngle(from: Point, to: Point, bend: number, t: number): number;
614
650
  declare function isNearBezier(point: Point, from: Point, to: Point, bend: number, threshold: number): boolean;
615
- declare function getArrowBounds(from: Point, to: Point, bend: number): Rect;
651
+ declare function getArrowBounds(from: Point, to: Point, bend: number): Bounds;
616
652
 
617
653
  declare function isBindable(element: CanvasElement): boolean;
618
654
  declare function getElementCenter(element: CanvasElement): Point;
619
- declare function getElementBounds(element: CanvasElement): Rect | null;
620
- declare function getEdgeIntersection(bounds: Rect, outsidePoint: Point): Point;
655
+ declare function getEdgeIntersection(bounds: Bounds, outsidePoint: Point): Point;
621
656
  declare function findBindTarget(point: Point, store: ElementStore, threshold: number, excludeId?: string, filter?: (el: CanvasElement) => boolean): CanvasElement | null;
622
657
  declare function findBoundArrows(elementId: string, store: ElementStore): ArrowElement[];
623
658
  declare function updateBoundArrow(arrow: ArrowElement, store: ElementStore): Partial<ArrowElement> | null;
624
659
  declare function clearStaleBindings(arrow: ArrowElement, store: ElementStore): Partial<ArrowElement> | null;
625
660
  declare function unbindArrow(arrow: ArrowElement, store: ElementStore): Partial<ArrowElement>;
626
661
 
662
+ declare function getElementBounds(element: CanvasElement): Bounds | null;
663
+ declare function boundsIntersect(a: Bounds, b: Bounds): boolean;
664
+
627
665
  declare class AddElementCommand implements Command {
628
666
  private readonly element;
629
667
  constructor(element: CanvasElement);
@@ -666,6 +704,8 @@ interface PencilToolOptions {
666
704
  color?: string;
667
705
  width?: number;
668
706
  smoothing?: number;
707
+ minPointDistance?: number;
708
+ progressiveSimplifyThreshold?: number;
669
709
  }
670
710
  declare class PencilTool implements Tool {
671
711
  readonly name = "pencil";
@@ -674,6 +714,9 @@ declare class PencilTool implements Tool {
674
714
  private color;
675
715
  private width;
676
716
  private smoothing;
717
+ private minPointDistance;
718
+ private progressiveThreshold;
719
+ private nextSimplifyAt;
677
720
  private optionListeners;
678
721
  constructor(options?: PencilToolOptions);
679
722
  onActivate(ctx: ToolContext): void;
@@ -734,7 +777,6 @@ declare class SelectTool implements Tool {
734
777
  private getMarqueeRect;
735
778
  private findElementsInRect;
736
779
  private rectsOverlap;
737
- private getElementBounds;
738
780
  private hitTest;
739
781
  private isInsideBounds;
740
782
  }
@@ -882,6 +924,6 @@ declare class UpdateLayerCommand implements Command {
882
924
  undo(_store: ElementStore): void;
883
925
  }
884
926
 
885
- declare const VERSION = "0.8.6";
927
+ declare const VERSION = "0.8.8";
886
928
 
887
- 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, 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, NoteEditor, type NoteElement, NoteTool, type NoteToolOptions, PencilTool, type PencilToolOptions, type Point, type PointerState, RemoveElementCommand, RemoveLayerCommand, 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, UpdateLayerCommand, VERSION, Viewport, type ViewportOptions, clearStaleBindings, createArrow, createGrid, createHtmlElement, createId, createImage, createNote, createShape, createStroke, createText, exportImage, exportState, findBindTarget, findBoundArrows, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getEdgeIntersection, getElementBounds, getElementCenter, isBindable, isNearBezier, parseState, snapPoint, unbindArrow, updateBoundArrow };
929
+ 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, 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 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, createText, exportImage, exportState, findBindTarget, findBoundArrows, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getEdgeIntersection, getElementBounds, getElementCenter, isBindable, isNearBezier, parseState, snapPoint, unbindArrow, updateBoundArrow };