@flowscape-ui/core-sdk 1.0.6 → 1.0.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
@@ -346,6 +346,7 @@ interface BaseNodeOptions {
346
346
  y?: number;
347
347
  width?: number;
348
348
  height?: number;
349
+ rotation?: number;
349
350
  }
350
351
  declare abstract class BaseNode<T extends Konva.Node = Konva.Node> implements NodeHandle<T> {
351
352
  protected konvaNode: T;
@@ -432,6 +433,10 @@ interface CoreEvents {
432
433
  'camera:panStep': [{
433
434
  panStep: number;
434
435
  }];
436
+ /** Camera pan gesture started (mouse down) */
437
+ 'camera:panStart': [{
438
+ button: number;
439
+ }];
435
440
  /** Camera was moved (panning) */
436
441
  'camera:pan': [{
437
442
  dx: number;
@@ -441,10 +446,18 @@ interface CoreEvents {
441
446
  y: number;
442
447
  };
443
448
  }];
449
+ /** Camera pan gesture ended (mouse up / leave) */
450
+ 'camera:panEnd': [];
444
451
  /** Plugin was added */
445
452
  'plugin:added': [pluginName: string];
446
453
  /** Plugin was removed */
447
454
  'plugin:removed': [pluginName: string];
455
+ /** Persistence restore failed */
456
+ 'persistence:restore:error': [{
457
+ error: string;
458
+ }];
459
+ /** Persistence restore completed */
460
+ 'persistence:restore:done': [];
448
461
  /** Stage was resized */
449
462
  'stage:resized': [{
450
463
  width: number;
@@ -1307,6 +1320,10 @@ declare class CoreEngine {
1307
1320
  * Enable or disable auto-resize
1308
1321
  */
1309
1322
  setAutoResize(enabled: boolean): void;
1323
+ /**
1324
+ * Show the canvas container after persistence restore completes
1325
+ */
1326
+ showContainer(): void;
1310
1327
  }
1311
1328
 
1312
1329
  /**
@@ -1472,15 +1489,21 @@ declare class CameraHotkeysPlugin extends Plugin {
1472
1489
  private _last;
1473
1490
  private _prevCursor;
1474
1491
  private _prevStageDraggable?;
1492
+ private _onMouseDownDOM;
1493
+ private _onMouseMoveDOM;
1494
+ private _onMouseUpDOM;
1495
+ private _onMouseLeaveDOM;
1496
+ private _panningCursorRafId;
1497
+ private _onCameraPanEvent;
1475
1498
  constructor(options?: CameraHotkeysOptions);
1476
1499
  setOptions(patch: Partial<CameraHotkeysOptions>): void;
1477
1500
  protected onAttach(core: CoreEngine): void;
1478
1501
  protected onDetach(core: CoreEngine): void;
1479
1502
  private _onWheelDOM;
1480
- private _onMouseDownKonva;
1481
- private _onMouseMoveKonva;
1482
- private _onMouseUpKonva;
1483
- private _onMouseLeaveKonva;
1503
+ private _applyPanningCursor;
1504
+ private _startPanningCursorLoop;
1505
+ private _stopPanningCursorLoop;
1506
+ private _restoreCursor;
1484
1507
  private _onContextMenuDOM;
1485
1508
  private _handleKeyDown;
1486
1509
  private _isEditableTarget;
@@ -1498,12 +1521,17 @@ declare class ContentFromClipboardPlugin extends Plugin {
1498
1521
  private _core?;
1499
1522
  private _options;
1500
1523
  private _dragDropAddon;
1524
+ private _middlePressed;
1525
+ private _onContainerMouseDown;
1526
+ private _onContainerMouseUp;
1501
1527
  constructor(options?: ContentFromClipboardPluginOptions);
1502
1528
  protected onAttach(core: CoreEngine): void;
1503
1529
  protected onDetach(_core: CoreEngine): void;
1504
1530
  private _onPaste;
1531
+ private _onPasteAsync;
1505
1532
  private _handlePaste;
1506
1533
  handleDrop(e: DragEvent): Promise<void>;
1534
+ private _resetAltKeyStuck;
1507
1535
  private _handleDataTransfer;
1508
1536
  private _pasteSvgText;
1509
1537
  private _pasteSvgFile;
@@ -1744,15 +1772,45 @@ declare class NodeHotkeysPlugin extends Plugin {
1744
1772
  private _options;
1745
1773
  private _clipboard;
1746
1774
  private _selectionPlugin?;
1775
+ private _isAltPressed;
1776
+ private _isMouseDown;
1777
+ private _isCameraPanning;
1778
+ private _cloneStartPos;
1779
+ private _clonedNodes;
1780
+ private _cloneOriginals;
1781
+ private _cloneDragEventsStarted;
1782
+ private _clonePrevDraggable;
1783
+ private _prevCursor;
1784
+ private _isCloneCursorActive;
1785
+ private _doubleCursorCss;
1786
+ private _cloneOriginalsHidden;
1787
+ private _cloneAutoPanRafId;
1788
+ private _cloneAutoPanActive;
1789
+ private _cloneAutoPanEdgePx;
1790
+ private _cloneAutoPanMaxSpeedPx;
1747
1791
  constructor(options?: NodeHotkeysOptions);
1792
+ private _startCloneAutoPanLoop;
1793
+ private _stopCloneAutoPanLoop;
1794
+ private _getHoveredNodeUnderPointer;
1748
1795
  protected onAttach(core: CoreEngine): void;
1749
1796
  protected onDetach(_core: CoreEngine): void;
1797
+ private _onCameraPanStart;
1798
+ private _onCameraPanEnd;
1750
1799
  private _onPaste;
1751
1800
  private _onKeyDown;
1801
+ private _onKeyUp;
1802
+ private _onMouseDown;
1803
+ private _onMouseUp;
1804
+ private _onMouseMove;
1805
+ private _updateCloneCursor;
1806
+ private _isOverCornerRadiusHandle;
1807
+ private _getDoubleCursorCss;
1808
+ private _restoreCursor;
1752
1809
  private _isEditableTarget;
1753
1810
  private _handleCopy;
1754
1811
  private _handleCut;
1755
1812
  private _handlePaste;
1813
+ private _detachClonesFromFrame;
1756
1814
  private _handleDelete;
1757
1815
  private _getSelectedNodes;
1758
1816
  private _deleteNodes;
@@ -1765,6 +1823,7 @@ declare class NodeHotkeysPlugin extends Plugin {
1765
1823
  private _getScreenCenter;
1766
1824
  private _getClipboardCenter;
1767
1825
  private _computeSelectionWorldCenter;
1826
+ private _centerOnSelection;
1768
1827
  private _handleMoveUp;
1769
1828
  private _handleMoveDown;
1770
1829
  private _handleMoveToTop;
@@ -1779,6 +1838,201 @@ declare class NodeHotkeysPlugin extends Plugin {
1779
1838
  * - For node inside group — FORBIDDEN to change z-index
1780
1839
  */
1781
1840
  private _syncGroupZIndex;
1841
+ private _handleCloneStart;
1842
+ private _handleCloneMove;
1843
+ private _handleCloneEnd;
1844
+ }
1845
+
1846
+ /**
1847
+ * IndexedDB storage service for canvas persistence.
1848
+ * Handles storage of canvas state and blob files (images, videos, etc.)
1849
+ */
1850
+ interface StoredCanvasState {
1851
+ id: string;
1852
+ state: string;
1853
+ updatedAt: number;
1854
+ }
1855
+ interface StoredBlob {
1856
+ id: string;
1857
+ blob: Blob;
1858
+ mimeType: string;
1859
+ originalUrl?: string | undefined;
1860
+ }
1861
+ declare class PersistenceStorage {
1862
+ private _dbName;
1863
+ private _db;
1864
+ private _dbPromise;
1865
+ constructor(_dbName?: string);
1866
+ /**
1867
+ * Initialize IndexedDB connection
1868
+ */
1869
+ init(): Promise<void>;
1870
+ private _openDatabase;
1871
+ private _getDb;
1872
+ /**
1873
+ * Save canvas state to IndexedDB
1874
+ */
1875
+ saveCanvasState(id: string, state: string): Promise<void>;
1876
+ /**
1877
+ * Load canvas state from IndexedDB
1878
+ */
1879
+ loadCanvasState(id: string): Promise<StoredCanvasState | null>;
1880
+ /**
1881
+ * Delete canvas state from IndexedDB
1882
+ */
1883
+ deleteCanvasState(id: string): Promise<void>;
1884
+ /**
1885
+ * List all canvas states
1886
+ */
1887
+ listCanvasStates(): Promise<StoredCanvasState[]>;
1888
+ /**
1889
+ * Save blob to IndexedDB
1890
+ */
1891
+ saveBlob(id: string, blob: Blob, originalUrl?: string): Promise<void>;
1892
+ /**
1893
+ * Load blob from IndexedDB
1894
+ */
1895
+ loadBlob(id: string): Promise<StoredBlob | null>;
1896
+ /**
1897
+ * Delete blob from IndexedDB
1898
+ */
1899
+ deleteBlob(id: string): Promise<void>;
1900
+ /**
1901
+ * Load multiple blobs by IDs
1902
+ */
1903
+ loadBlobs(ids: string[]): Promise<Map<string, StoredBlob>>;
1904
+ /**
1905
+ * Save multiple blobs
1906
+ */
1907
+ saveBlobs(blobs: Map<string, {
1908
+ blob: Blob;
1909
+ originalUrl?: string;
1910
+ }>): Promise<void>;
1911
+ /**
1912
+ * List all blob IDs
1913
+ */
1914
+ listBlobIds(): Promise<string[]>;
1915
+ /**
1916
+ * Clear all blobs not referenced in the given set
1917
+ */
1918
+ cleanupUnusedBlobs(usedBlobIds: Set<string>): Promise<number>;
1919
+ /**
1920
+ * Clear all data (canvas states and blobs)
1921
+ */
1922
+ clearAll(): Promise<void>;
1923
+ /**
1924
+ * Close database connection
1925
+ */
1926
+ close(): void;
1927
+ /**
1928
+ * Delete the entire database
1929
+ */
1930
+ deleteDatabase(): Promise<void>;
1931
+ }
1932
+
1933
+ /**
1934
+ * PersistencePlugin - Auto-saves canvas state to IndexedDB on any change.
1935
+ * Restores state on page reload. Supports export/import to JSON with embedded blobs.
1936
+ */
1937
+
1938
+ interface PersistencePluginOptions {
1939
+ /** Unique ID for this canvas (default: 'default') */
1940
+ canvasId?: string;
1941
+ /** Debounce delay in ms before saving (default: 300) */
1942
+ debounceMs?: number;
1943
+ /** Auto-restore on attach (default: true) */
1944
+ autoRestore?: boolean;
1945
+ /** Custom IndexedDB database name */
1946
+ dbName?: string;
1947
+ /** Enable debug logging */
1948
+ debug?: boolean;
1949
+ }
1950
+ declare class PersistencePlugin extends Plugin {
1951
+ private _core;
1952
+ private _storage;
1953
+ private _canvasId;
1954
+ private _debounceMs;
1955
+ private _autoRestore;
1956
+ private _debug;
1957
+ private _saveTimer;
1958
+ private _isRestoring;
1959
+ private _blobUrls;
1960
+ private _initialized;
1961
+ /** Maps original blob URLs to stored blob IDs */
1962
+ private _blobUrlToId;
1963
+ constructor(options?: PersistencePluginOptions);
1964
+ protected onAttach(core: CoreEngine): void;
1965
+ protected onDetach(core: CoreEngine): void;
1966
+ private _initialize;
1967
+ private _subscribeToEvents;
1968
+ private _unsubscribeFromEvents;
1969
+ private _onNodeCreated;
1970
+ private _onNodeChange;
1971
+ private _onClipboardPaste;
1972
+ /**
1973
+ * Capture blob data from a media node if it has a blob URL
1974
+ */
1975
+ private _captureBlobFromNode;
1976
+ private _onNodeTransformed;
1977
+ private _onCameraChange;
1978
+ private _onKonvaDragEnd;
1979
+ private _onKonvaTransformEnd;
1980
+ private _onTextChange;
1981
+ /**
1982
+ * Subscribe to textChange events for all existing TextNodes
1983
+ */
1984
+ private _subscribeToTextNodes;
1985
+ private _scheduleSave;
1986
+ private _cancelPendingSave;
1987
+ /**
1988
+ * Save current canvas state to IndexedDB
1989
+ */
1990
+ save(): Promise<void>;
1991
+ /**
1992
+ * Restore canvas state from IndexedDB
1993
+ */
1994
+ restore(): Promise<boolean>;
1995
+ /**
1996
+ * Clear saved state from IndexedDB
1997
+ */
1998
+ clear(): Promise<void>;
1999
+ /**
2000
+ * Export canvas to JSON string with embedded blobs
2001
+ */
2002
+ exportToJSON(): Promise<string>;
2003
+ /**
2004
+ * Import canvas from JSON string with embedded blobs
2005
+ */
2006
+ importFromJSON(json: string): void;
2007
+ /**
2008
+ * Download canvas as JSON file
2009
+ */
2010
+ downloadJSON(filename?: string): Promise<void>;
2011
+ /**
2012
+ * Upload and import canvas from JSON file
2013
+ */
2014
+ uploadJSON(): Promise<void>;
2015
+ /**
2016
+ * Check if there is saved state
2017
+ */
2018
+ hasSavedState(): Promise<boolean>;
2019
+ /**
2020
+ * Get storage instance for advanced usage
2021
+ */
2022
+ getStorage(): PersistenceStorage;
2023
+ /**
2024
+ * Get canvas ID
2025
+ */
2026
+ getCanvasId(): string;
2027
+ /**
2028
+ * Set canvas ID (will trigger restore if autoRestore is enabled)
2029
+ */
2030
+ setCanvasId(id: string): Promise<void>;
2031
+ private _log;
2032
+ /**
2033
+ * Capture blob URLs from all nodes that haven't been captured yet
2034
+ */
2035
+ private _captureAllBlobUrls;
1782
2036
  }
1783
2037
 
1784
2038
  interface RulerGuidesPluginOptions {
@@ -2465,6 +2719,53 @@ declare class TextAutoTrimAddon extends NodeAddon<TextNode> {
2465
2719
  private normalize;
2466
2720
  }
2467
2721
 
2722
+ /**
2723
+ * Canvas serialization/deserialization utility.
2724
+ * Handles conversion of canvas state to/from JSON format with blob extraction.
2725
+ */
2726
+
2727
+ interface SerializedNode {
2728
+ id: string;
2729
+ type: string;
2730
+ attrs: Record<string, unknown>;
2731
+ zIndex: number;
2732
+ blobId?: string;
2733
+ children?: SerializedNode[];
2734
+ parentFrameId?: string;
2735
+ }
2736
+ interface SerializedCamera {
2737
+ x: number;
2738
+ y: number;
2739
+ scale: number;
2740
+ }
2741
+ interface SerializedCanvas {
2742
+ version: number;
2743
+ timestamp: number;
2744
+ nodes: SerializedNode[];
2745
+ camera: SerializedCamera;
2746
+ blobIds: string[];
2747
+ }
2748
+ interface ExtractedBlob {
2749
+ id: string;
2750
+ blob: Blob;
2751
+ originalUrl: string;
2752
+ }
2753
+ interface DeserializeOptions {
2754
+ blobUrls?: Map<string, string>;
2755
+ clearExisting?: boolean;
2756
+ }
2757
+ interface SerializeOptions {
2758
+ /** Pre-existing mapping of blob URLs to blob IDs (from captured blobs) */
2759
+ blobUrlToId?: Map<string, string>;
2760
+ }
2761
+ declare function serializeCanvas(core: CoreEngine, options?: SerializeOptions): SerializedCanvas;
2762
+ declare function extractBlobs(core: CoreEngine): Promise<Map<string, ExtractedBlob>>;
2763
+ declare function deserializeCanvas(core: CoreEngine, state: SerializedCanvas, options?: DeserializeOptions): void;
2764
+ declare function exportCanvasToJSON(core: CoreEngine): Promise<string>;
2765
+ declare function importCanvasFromJSON(core: CoreEngine, json: string, options?: Omit<DeserializeOptions, 'blobUrls'>): void;
2766
+ declare function createBlobUrlMap(state: SerializedCanvas, storedBlobs: Map<string, Blob>): Map<string, string>;
2767
+ declare function revokeBlobUrls(blobUrls: Map<string, string>): void;
2768
+
2468
2769
  /**
2469
2770
  * DebounceHelper - utility for debouncing (delayed execution)
2470
2771
  *
@@ -2555,4 +2856,4 @@ declare const frameTemplates: {
2555
2856
  };
2556
2857
  };
2557
2858
 
2558
- export { type ArcNodeHandle, type ArcNodeOptions, AreaSelectionPlugin, type AreaSelectionPluginOptions, type ArrowNodeHandle, type ArrowNodeOptions, type BaseNodeOptions, type CameraHotkeysOptions, CameraHotkeysPlugin, CameraManager, type CircleNodeHandle, type CircleNodeOptions, ContentFromClipboardPlugin, type ContentFromClipboardPluginOptions, CoreEngine, type CoreEngineOptions, type CoreEvents, DebounceHelper, type EllipseNodeHandle, type EllipseNodeOptions, EventBus, FrameNode, type FrameNodeOptions, type FrameOptions, type GifNodeHandle, type GifNodeOptions, GridPlugin, type GridPluginOptions, type GroupNodeHandle, type GroupNodeOptions, type HistoryAction, HistoryManager, HistoryPlugin, type HistoryPluginOptions, ImageHoverFilterAddon, type ImageNodeHandle, type ImageNodeOptions, type ImageSource, type KonvaArc, type KonvaArrow, type KonvaCircle, type KonvaEllipse, type KonvaGroup, type KonvaGroupConfig, type KonvaImage, type KonvaLayer, type KonvaNode, type KonvaNodeConfig, type KonvaRegularPolygon, type KonvaRing, type KonvaShape, type KonvaStage, type KonvaStar, type KonvaText, type LogoOptions, LogoPlugin, MediaPlaceholder, type MediaPlaceholderOptions, NodeAddon, NodeAddons, type NodeAddonsHandle, type NodeHandle, type NodeHotkeysOptions, NodeHotkeysPlugin, NodeManager, PluginAddon, Plugins, type RegularPolygonNodeHandle, type RegularPolygonNodeOptions, type RingNodeHandle, type RingNodeOptions, RulerGuidesAddon, RulerGuidesPlugin, type RulerGuidesPluginOptions, RulerHighlightAddon, RulerHighlightPlugin, type RulerHighlightPluginOptions, RulerManagerAddon, RulerManagerPlugin, type RulerManagerPluginOptions, RulerPlugin, type RulerPluginOptions, SelectionPlugin, type SelectionPluginOptions, ShapeHoverHighlightAddon, type ShapeNodeHandle, type ShapeNodeOptions, type StarNodeHandle, type StarNodeOptions, type SvgNodeHandle, type SvgNodeOptions, TextAutoTrimAddon, type TextNodeHandle, type TextNodeOptions, ThrottleHelper, type VideoNodeHandle, type VideoNodeOptions, VideoOverlayAddon, type VideoOverlayAddonOptions, VisualGuidesPlugin, type VisualGuidesPluginOptions, frameTemplates };
2859
+ export { type ArcNodeHandle, type ArcNodeOptions, AreaSelectionPlugin, type AreaSelectionPluginOptions, type ArrowNodeHandle, type ArrowNodeOptions, type BaseNodeOptions, type CameraHotkeysOptions, CameraHotkeysPlugin, CameraManager, type CircleNodeHandle, type CircleNodeOptions, ContentFromClipboardPlugin, type ContentFromClipboardPluginOptions, CoreEngine, type CoreEngineOptions, type CoreEvents, DebounceHelper, type DeserializeOptions, type EllipseNodeHandle, type EllipseNodeOptions, EventBus, type ExtractedBlob, FrameNode, type FrameNodeOptions, type FrameOptions, type GifNodeHandle, type GifNodeOptions, GridPlugin, type GridPluginOptions, type GroupNodeHandle, type GroupNodeOptions, type HistoryAction, HistoryManager, HistoryPlugin, type HistoryPluginOptions, ImageHoverFilterAddon, type ImageNodeHandle, type ImageNodeOptions, type ImageSource, type KonvaArc, type KonvaArrow, type KonvaCircle, type KonvaEllipse, type KonvaGroup, type KonvaGroupConfig, type KonvaImage, type KonvaLayer, type KonvaNode, type KonvaNodeConfig, type KonvaRegularPolygon, type KonvaRing, type KonvaShape, type KonvaStage, type KonvaStar, type KonvaText, type LogoOptions, LogoPlugin, MediaPlaceholder, type MediaPlaceholderOptions, NodeAddon, NodeAddons, type NodeAddonsHandle, type NodeHandle, type NodeHotkeysOptions, NodeHotkeysPlugin, NodeManager, PersistencePlugin, type PersistencePluginOptions, PersistenceStorage, PluginAddon, Plugins, type RegularPolygonNodeHandle, type RegularPolygonNodeOptions, type RingNodeHandle, type RingNodeOptions, RulerGuidesAddon, RulerGuidesPlugin, type RulerGuidesPluginOptions, RulerHighlightAddon, RulerHighlightPlugin, type RulerHighlightPluginOptions, RulerManagerAddon, RulerManagerPlugin, type RulerManagerPluginOptions, RulerPlugin, type RulerPluginOptions, SelectionPlugin, type SelectionPluginOptions, type SerializeOptions, type SerializedCamera, type SerializedCanvas, type SerializedNode, ShapeHoverHighlightAddon, type ShapeNodeHandle, type ShapeNodeOptions, type StarNodeHandle, type StarNodeOptions, type StoredBlob, type StoredCanvasState, type SvgNodeHandle, type SvgNodeOptions, TextAutoTrimAddon, type TextNodeHandle, type TextNodeOptions, ThrottleHelper, type VideoNodeHandle, type VideoNodeOptions, VideoOverlayAddon, type VideoOverlayAddonOptions, VisualGuidesPlugin, type VisualGuidesPluginOptions, createBlobUrlMap, deserializeCanvas, exportCanvasToJSON, extractBlobs, frameTemplates, importCanvasFromJSON, revokeBlobUrls, serializeCanvas };