@fieldnotes/core 0.23.0 → 0.25.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
@@ -1,14 +1,3 @@
1
- type Listener<T> = (data: T) => void;
2
- declare class EventBus<TEvents extends {
3
- [K in keyof TEvents]: TEvents[K];
4
- }> {
5
- private listeners;
6
- on<K extends keyof TEvents>(event: K, listener: Listener<TEvents[K]>): () => void;
7
- off<K extends keyof TEvents>(event: K, listener: Listener<TEvents[K]>): void;
8
- emit<K extends keyof TEvents>(event: K, data: TEvents[K]): void;
9
- clear(): void;
10
- }
11
-
12
1
  interface Point {
13
2
  x: number;
14
3
  y: number;
@@ -24,20 +13,6 @@ interface Size {
24
13
  }
25
14
  type Bounds = Point & Size;
26
15
 
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
-
41
16
  interface BaseElement {
42
17
  id: string;
43
18
  type: string;
@@ -130,31 +105,6 @@ interface TemplateElement extends BaseElement {
130
105
  type CanvasElement = StrokeElement | NoteElement | ArrowElement | ImageElement | HtmlElement | TextElement | ShapeElement | GridElement | TemplateElement;
131
106
  type ElementType = CanvasElement['type'];
132
107
 
133
- interface Layer {
134
- id: string;
135
- name: string;
136
- visible: boolean;
137
- locked: boolean;
138
- order: number;
139
- opacity: number;
140
- }
141
-
142
- interface CanvasState {
143
- version: number;
144
- camera: {
145
- position: Point;
146
- zoom: number;
147
- };
148
- elements: CanvasElement[];
149
- layers?: Layer[];
150
- activeLayerId?: string;
151
- }
152
- declare function exportState(elements: CanvasElement[], camera: {
153
- position: Point;
154
- zoom: number;
155
- }, layers?: Layer[], activeLayerId?: string): CanvasState;
156
- declare function parseState(json: string): CanvasState;
157
-
158
108
  interface CameraOptions {
159
109
  minZoom?: number;
160
110
  maxZoom?: number;
@@ -270,6 +220,26 @@ declare function snapPoint(point: Point, gridSize: number): Point;
270
220
  declare function snapToHexCenter(point: Point, cellSize: number, orientation: HexOrientation): Point;
271
221
  declare function smartSnap(point: Point, ctx: ToolContext): Point;
272
222
 
223
+ interface Layer {
224
+ id: string;
225
+ name: string;
226
+ visible: boolean;
227
+ locked: boolean;
228
+ order: number;
229
+ opacity: number;
230
+ }
231
+
232
+ interface CanvasState {
233
+ version: number;
234
+ camera: {
235
+ position: Point;
236
+ zoom: number;
237
+ };
238
+ elements: CanvasElement[];
239
+ layers?: Layer[];
240
+ activeLayerId?: string;
241
+ }
242
+
273
243
  interface LayerManagerEvents {
274
244
  change: null;
275
245
  create: Layer;
@@ -343,25 +313,22 @@ interface BackgroundOptions {
343
313
  dotRadius?: number;
344
314
  lineWidth?: number;
345
315
  }
346
- declare class Background {
347
- private readonly pattern;
348
- private readonly spacing;
349
- private readonly color;
350
- private readonly dotRadius;
351
- private readonly lineWidth;
352
- private cachedCanvas;
353
- private cachedCtx;
354
- private lastZoom;
355
- private lastOffsetX;
356
- private lastOffsetY;
357
- private lastWidth;
358
- private lastHeight;
359
- constructor(options?: BackgroundOptions);
360
- render(ctx: CanvasRenderingContext2D, camera: Camera): void;
361
- private ensureCachedCanvas;
362
- private adaptSpacing;
363
- private renderDots;
364
- private renderGrid;
316
+
317
+ type ShortcutBindings = Record<string, string | string[] | null>;
318
+ interface ShortcutOptions {
319
+ scope?: 'focus' | 'window';
320
+ bindings?: ShortcutBindings;
321
+ }
322
+ interface ShortcutsApi {
323
+ rebind(action: string, bindings: string | string[] | null): void;
324
+ disable(action: string): void;
325
+ reset(action?: string): void;
326
+ getBindings(): Record<string, string[]>;
327
+ }
328
+
329
+ interface FontSizePreset {
330
+ label: string;
331
+ size: number;
365
332
  }
366
333
 
367
334
  declare class ToolManager {
@@ -405,161 +372,6 @@ declare class HistoryStack {
405
372
  private notifyChange;
406
373
  }
407
374
 
408
- declare class HistoryRecorder {
409
- private readonly store;
410
- private readonly stack;
411
- private readonly layerManager?;
412
- private recording;
413
- private transaction;
414
- private generation;
415
- private updateSnapshots;
416
- private unsubscribers;
417
- constructor(store: ElementStore, stack: HistoryStack, layerManager?: LayerManager | undefined);
418
- pause(): void;
419
- resume(): void;
420
- begin(): void;
421
- get currentTransactionId(): number | null;
422
- commit(): void;
423
- rollback(): void;
424
- destroy(): void;
425
- private record;
426
- private onAdd;
427
- private onRemove;
428
- private onUpdate;
429
- private onLayerCreate;
430
- private onLayerRemove;
431
- private onLayerUpdate;
432
- private flushUpdateSnapshots;
433
- }
434
-
435
- type ShortcutBindings = Record<string, string | string[] | null>;
436
- interface ShortcutOptions {
437
- scope?: 'focus' | 'window';
438
- bindings?: ShortcutBindings;
439
- }
440
- interface ShortcutsApi {
441
- rebind(action: string, bindings: string | string[] | null): void;
442
- disable(action: string): void;
443
- reset(action?: string): void;
444
- getBindings(): Record<string, string[]>;
445
- }
446
-
447
- interface InputHandlerOptions {
448
- toolManager?: ToolManager;
449
- toolContext?: ToolContext;
450
- historyRecorder?: HistoryRecorder;
451
- historyStack?: HistoryStack;
452
- fitToContent?: () => void;
453
- shortcuts?: ShortcutOptions;
454
- }
455
- declare class InputHandler {
456
- private readonly element;
457
- private readonly camera;
458
- private isPanning;
459
- private lastPointer;
460
- private spaceHeld;
461
- private activePointers;
462
- private lastPinchDistance;
463
- private lastPinchCenter;
464
- private toolManager;
465
- private toolContext;
466
- private historyRecorder;
467
- private historyStack;
468
- private isToolActive;
469
- private lastPointerEvent;
470
- private readonly inputFilter;
471
- private deferredDown;
472
- private readonly abortController;
473
- private readonly actions;
474
- private readonly shortcutMap;
475
- private readonly scope;
476
- constructor(element: HTMLElement, camera: Camera, options?: InputHandlerOptions);
477
- setToolManager(toolManager: ToolManager, toolContext: ToolContext): void;
478
- flushPendingHistory(): void;
479
- get shortcuts(): ShortcutsApi;
480
- destroy(): void;
481
- private bind;
482
- private onWheel;
483
- private onPointerDown;
484
- private onPointerMove;
485
- private onPointerUp;
486
- private onKeyDown;
487
- private onKeyUp;
488
- private runAction;
489
- private startPinch;
490
- private handlePinchMove;
491
- private getPinchPoints;
492
- private distance;
493
- private midpoint;
494
- private toPointerState;
495
- private dispatchToolDown;
496
- private dispatchToolMove;
497
- private dispatchToolHover;
498
- private dispatchToolUp;
499
- private isInScope;
500
- private focusSelf;
501
- private cancelToolIfActive;
502
- }
503
-
504
- type FilterAction = 'dispatch' | 'suppress' | 'defer';
505
- interface FilteredEvent {
506
- event: PointerEvent;
507
- action: FilterAction;
508
- }
509
- interface FilteredUpEvent extends FilteredEvent {
510
- pendingTap?: {
511
- x: number;
512
- y: number;
513
- };
514
- }
515
- declare class InputFilter {
516
- private activePenId;
517
- private pendingTap;
518
- static readonly MIN_MOVE_DISTANCE = 3;
519
- filterDown(e: PointerEvent): FilteredEvent;
520
- filterMove(e: PointerEvent): FilteredEvent;
521
- filterUp(e: PointerEvent): FilteredUpEvent;
522
- reset(): void;
523
- }
524
-
525
- interface DoubleTapDetectorOptions {
526
- timeout?: number;
527
- maxDistance?: number;
528
- }
529
- declare class DoubleTapDetector {
530
- private readonly timeout;
531
- private readonly maxDistance;
532
- private lastTapTime;
533
- private lastTapX;
534
- private lastTapY;
535
- private hasPendingTap;
536
- constructor(options?: DoubleTapDetectorOptions);
537
- feed(e: PointerEvent): boolean;
538
- reset(): void;
539
- }
540
-
541
- interface FontSizePreset {
542
- label: string;
543
- size: number;
544
- }
545
- declare const DEFAULT_FONT_SIZE_PRESETS: FontSizePreset[];
546
- declare class NoteToolbar {
547
- private el;
548
- private anchor;
549
- private selectionListener;
550
- private readonly fontSizePresets;
551
- constructor(fontSizePresets?: FontSizePreset[]);
552
- show(anchor: HTMLElement): void;
553
- hide(): void;
554
- getElement(): HTMLDivElement | null;
555
- updatePosition(anchor: HTMLElement): void;
556
- private createToolbarElement;
557
- private createFormatButton;
558
- private createFontSizeSelect;
559
- private positionToolbar;
560
- private updateActiveStates;
561
- }
562
-
563
375
  interface ExportImageOptions {
564
376
  scale?: number;
565
377
  padding?: number;
@@ -602,6 +414,7 @@ interface ViewportOptions {
602
414
  onImageError?: (info: {
603
415
  src: string;
604
416
  elementIds: string[];
417
+ cause?: unknown;
605
418
  }) => void;
606
419
  /** CSS-pixel margin cached beyond the viewport. Default `256`. Set `0` to disable. */
607
420
  panBufferMargin?: number;
@@ -702,87 +515,6 @@ declare class Viewport {
702
515
  private observeResize;
703
516
  }
704
517
 
705
- declare class ElementRenderer {
706
- private store;
707
- private imageCache;
708
- private onImageLoad;
709
- private onImageError;
710
- private camera;
711
- private canvasSize;
712
- private hexTileCache;
713
- private hexTileCacheKey;
714
- private gridBoundsOverride;
715
- setStore(store: ElementStore): void;
716
- setOnImageLoad(callback: () => void): void;
717
- setOnImageError(callback: (src: string) => void): void;
718
- setCamera(camera: Camera): void;
719
- setCanvasSize(w: number, h: number): void;
720
- setGridBoundsOverride(bounds: {
721
- minX: number;
722
- minY: number;
723
- maxX: number;
724
- maxY: number;
725
- } | null): void;
726
- isDomElement(element: CanvasElement): boolean;
727
- renderCanvasElement(ctx: CanvasRenderingContext2D, element: CanvasElement): void;
728
- private renderStroke;
729
- private renderArrow;
730
- private renderArrowhead;
731
- private getVisualEndpoints;
732
- private renderShape;
733
- private fillShapePath;
734
- private strokeShapePath;
735
- private renderGrid;
736
- private renderTemplate;
737
- private renderGeometricTemplate;
738
- private renderHexTemplate;
739
- private renderRadiusMarker;
740
- private renderImage;
741
- private renderImagePlaceholder;
742
- private getHexTile;
743
- private getImage;
744
- }
745
-
746
- interface NoteEditorOptions {
747
- fontSizePresets?: FontSizePreset[];
748
- toolbar?: boolean;
749
- placeholder?: string;
750
- }
751
- declare class NoteEditor {
752
- private editingId;
753
- private editingNode;
754
- private blurHandler;
755
- private keyHandler;
756
- private pointerHandler;
757
- private inputHandler;
758
- private pendingEditId;
759
- private onStopCallback;
760
- private toolbar;
761
- private readonly placeholder;
762
- constructor(options?: NoteEditorOptions);
763
- get isEditing(): boolean;
764
- get editingElementId(): string | null;
765
- setOnStop(callback: (elementId: string) => void): void;
766
- startEditing(node: HTMLDivElement, elementId: string, store: ElementStore): void;
767
- stopEditing(store: ElementStore): void;
768
- destroy(store: ElementStore): void;
769
- updateToolbarPosition(): void;
770
- private activateEditing;
771
- }
772
-
773
- interface RunStyle {
774
- bold: boolean;
775
- italic: boolean;
776
- underline: boolean;
777
- strikethrough: boolean;
778
- fontSize: number;
779
- }
780
- interface StyledRun extends RunStyle {
781
- text: string;
782
- }
783
- declare function sanitizeNoteHtml(html: string): string;
784
- declare function isNoteContentEmpty(html: string): boolean;
785
-
786
518
  interface ActiveFormats {
787
519
  bold: boolean;
788
520
  italic: boolean;
@@ -796,8 +528,6 @@ declare function toggleStrikethrough(): void;
796
528
  declare function setFontSize(size: number): void;
797
529
  declare function getActiveFormats(): ActiveFormats;
798
530
 
799
- declare function createId(prefix: string): string;
800
-
801
531
  declare const DEFAULT_NOTE_FONT_SIZE = 18;
802
532
  interface BaseDefaults {
803
533
  position?: Point;
@@ -892,15 +622,6 @@ declare function getArrowTangentAngle(from: Point, to: Point, bend: number, t: n
892
622
  declare function isNearBezier(point: Point, from: Point, to: Point, bend: number, threshold: number): boolean;
893
623
  declare function getArrowBounds(from: Point, to: Point, bend: number): Bounds;
894
624
 
895
- declare function isBindable(element: CanvasElement): boolean;
896
- declare function getElementCenter(element: CanvasElement): Point;
897
- declare function getEdgeIntersection(bounds: Bounds, outsidePoint: Point): Point;
898
- declare function findBindTarget(point: Point, store: ElementStore, threshold: number, excludeId?: string, filter?: (el: CanvasElement) => boolean): CanvasElement | null;
899
- declare function findBoundArrows(elementId: string, store: ElementStore): ArrowElement[];
900
- declare function updateBoundArrow(arrow: ArrowElement, store: ElementStore): Partial<ArrowElement> | null;
901
- declare function clearStaleBindings(arrow: ArrowElement, store: ElementStore): Partial<ArrowElement> | null;
902
- declare function unbindArrow(arrow: ArrowElement, store: ElementStore): Partial<ArrowElement>;
903
-
904
625
  declare function getElementBounds(element: CanvasElement): Bounds | null;
905
626
  declare function boundsIntersect(a: Bounds, b: Bounds): boolean;
906
627
 
@@ -913,33 +634,6 @@ declare function getHexCellsInLine(center: Point, angle: number, radiusCells: nu
913
634
  declare function getHexCellsInSquare(center: Point, radiusCells: number, cellSize: number, orientation: HexOrientation): Point[];
914
635
  declare function drawHexPath(ctx: CanvasRenderingContext2D, cx: number, cy: number, cellSize: number, orientation: HexOrientation): void;
915
636
 
916
- declare class AddElementCommand implements Command {
917
- private readonly element;
918
- constructor(element: CanvasElement);
919
- execute(store: ElementStore): void;
920
- undo(store: ElementStore): void;
921
- }
922
- declare class RemoveElementCommand implements Command {
923
- private readonly element;
924
- constructor(element: CanvasElement);
925
- execute(store: ElementStore): void;
926
- undo(store: ElementStore): void;
927
- }
928
- declare class UpdateElementCommand implements Command {
929
- private readonly id;
930
- private readonly previous;
931
- private readonly current;
932
- constructor(id: string, previous: CanvasElement, current: CanvasElement);
933
- execute(store: ElementStore): void;
934
- undo(store: ElementStore): void;
935
- }
936
- declare class BatchCommand implements Command {
937
- readonly commands: readonly Command[];
938
- constructor(commands: Command[]);
939
- execute(store: ElementStore): void;
940
- undo(store: ElementStore): void;
941
- }
942
-
943
637
  declare class HandTool implements Tool {
944
638
  readonly name = "hand";
945
639
  private panning;
@@ -1237,30 +931,6 @@ declare class TemplateTool implements Tool {
1237
931
  private notifyOptionsChange;
1238
932
  }
1239
933
 
1240
- declare class CreateLayerCommand implements Command {
1241
- private readonly manager;
1242
- private readonly layer;
1243
- constructor(manager: LayerManager, layer: Layer);
1244
- execute(_store: ElementStore): void;
1245
- undo(_store: ElementStore): void;
1246
- }
1247
- declare class RemoveLayerCommand implements Command {
1248
- private readonly manager;
1249
- private readonly layer;
1250
- constructor(manager: LayerManager, layer: Layer);
1251
- execute(_store: ElementStore): void;
1252
- undo(_store: ElementStore): void;
1253
- }
1254
- declare class UpdateLayerCommand implements Command {
1255
- private readonly manager;
1256
- private readonly layerId;
1257
- private readonly previous;
1258
- private readonly current;
1259
- constructor(manager: LayerManager, layerId: string, previous: Layer, current: Layer);
1260
- execute(_store: ElementStore): void;
1261
- undo(_store: ElementStore): void;
1262
- }
1263
-
1264
- declare const VERSION = "0.23.0";
934
+ declare const VERSION = "0.25.0";
1265
935
 
1266
- 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, DoubleTapDetector, type DoubleTapDetectorOptions, ElementRenderer, ElementStore, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, EventBus, type ExportImageOptions, type FilterAction, type FilteredEvent, type FilteredUpEvent, type FontSizePreset, type GridElement, type GridInfo, HandTool, type HexOrientation, HistoryRecorder, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, InputFilter, InputHandler, type InputHandlerOptions, 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 ShortcutBindings, type ShortcutOptions, type ShortcutsApi, 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, getElementsBoundingBox, getHexCellsInCone, getHexCellsInLine, getHexCellsInRadius, getHexCellsInSquare, getHexDistance, isBindable, isNearBezier, isNoteContentEmpty, parseState, sanitizeNoteHtml, setFontSize, smartSnap, snapPoint, snapToHexCenter, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline, unbindArrow, updateBoundArrow };
936
+ export { type ActiveFormats, type ArrowElement, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, type BackgroundOptions, type BackgroundPattern, type Binding, type Bounds, Camera, type CameraChangeInfo, type CameraOptions, type CanvasElement, type CanvasState, type Command, DEFAULT_NOTE_FONT_SIZE, ElementStore, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, type ExportImageOptions, type FontSizePreset, type GridElement, type GridInfo, HandTool, type HexOrientation, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, type Layer, LayerManager, MeasureTool, type MeasureToolOptions, type Measurement, type NoteElement, NoteTool, type NoteToolOptions, PencilTool, type PencilToolOptions, type Point, type PointerState, type RenderStatsSnapshot, SelectTool, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type ShortcutBindings, type ShortcutOptions, type ShortcutsApi, 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, VERSION, Viewport, type ViewportOptions, boundsIntersect, createArrow, createGrid, createHtmlElement, createImage, createNote, createShape, createStroke, createTemplate, createText, drawHexPath, exportImage, getActiveFormats, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getElementBounds, getElementsBoundingBox, getHexCellsInCone, getHexCellsInLine, getHexCellsInRadius, getHexCellsInSquare, getHexDistance, isNearBezier, setFontSize, smartSnap, snapPoint, snapToHexCenter, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline };