f1ow 0.1.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/LICENSE +21 -0
- package/README.md +210 -0
- package/dist/assets/elbowWorker-CUBh1uET.js +1 -0
- package/dist/assets/exportWorker-hU9uNZXJ.js +8 -0
- package/dist/assets/syncWorker.worker-CnlpNZ3k.js +6 -0
- package/dist/components/Canvas/CanvasElement.d.ts +42 -0
- package/dist/components/Canvas/ConnectionPoints.d.ts +13 -0
- package/dist/components/Canvas/GridLayer.d.ts +13 -0
- package/dist/components/Canvas/LinearElementHandles.d.ts +17 -0
- package/dist/components/Canvas/SelectionBox.d.ts +12 -0
- package/dist/components/Canvas/SelectionTransformer.d.ts +7 -0
- package/dist/components/ContextMenu/ContextMenu.d.ts +23 -0
- package/dist/components/StylePanel/StylePanel.d.ts +7 -0
- package/dist/components/Toolbar/Toolbar.d.ts +9 -0
- package/dist/components/shapes/ArrowShape.d.ts +18 -0
- package/dist/components/shapes/DiamondShape.d.ts +24 -0
- package/dist/components/shapes/EllipseShape.d.ts +24 -0
- package/dist/components/shapes/FreeDrawShape.d.ts +24 -0
- package/dist/components/shapes/ImageShape.d.ts +24 -0
- package/dist/components/shapes/LineShape.d.ts +18 -0
- package/dist/components/shapes/RectangleShape.d.ts +24 -0
- package/dist/components/shapes/TextShape.d.ts +23 -0
- package/dist/constants/index.d.ts +44 -0
- package/dist/f1ow-canvas.js +37725 -0
- package/dist/f1ow-canvas.umd.cjs +371 -0
- package/dist/hooks/useEfficientZoom.d.ts +14 -0
- package/dist/hooks/useElbowShapeFingerprint.d.ts +21 -0
- package/dist/hooks/useElbowWorker.d.ts +23 -0
- package/dist/hooks/useKeyboardShortcuts.d.ts +7 -0
- package/dist/hooks/useProgressiveRender.d.ts +52 -0
- package/dist/hooks/useSpatialIndex.d.ts +9 -0
- package/dist/hooks/useViewportCulling.d.ts +13 -0
- package/dist/lib/FlowCanvas.d.ts +4 -0
- package/dist/lib/FlowCanvasProps.d.ts +154 -0
- package/dist/lib/index.d.ts +57 -0
- package/dist/store/useCanvasStore.d.ts +127 -0
- package/dist/store/useLinearEditStore.d.ts +25 -0
- package/dist/types/index.d.ts +257 -0
- package/dist/utils/alignment.d.ts +34 -0
- package/dist/utils/arrowheads.d.ts +20 -0
- package/dist/utils/camera.d.ts +63 -0
- package/dist/utils/clipboard.d.ts +4 -0
- package/dist/utils/clone.d.ts +29 -0
- package/dist/utils/connection.d.ts +122 -0
- package/dist/utils/crdtPrep.d.ts +97 -0
- package/dist/utils/curve.d.ts +51 -0
- package/dist/utils/elbow.d.ts +110 -0
- package/dist/utils/elbowWorkerManager.d.ts +53 -0
- package/dist/utils/export.d.ts +17 -0
- package/dist/utils/exportWorkerManager.d.ts +25 -0
- package/dist/utils/fractionalIndex.d.ts +51 -0
- package/dist/utils/geometry.d.ts +49 -0
- package/dist/utils/id.d.ts +1 -0
- package/dist/utils/image.d.ts +52 -0
- package/dist/utils/performance.d.ts +65 -0
- package/dist/utils/roughness.d.ts +104 -0
- package/dist/utils/spatialIndex.d.ts +109 -0
- package/dist/utils/spatialSoA.d.ts +82 -0
- package/dist/workers/elbowWorker.d.ts +18 -0
- package/dist/workers/exportWorker.d.ts +18 -0
- package/package.json +80 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { CanvasElement, ViewportState } from '../types';
|
|
2
|
+
/** Numeric encoding for element types (used in SoA type array) */
|
|
3
|
+
export declare const ELEMENT_TYPE_MAP: Record<string, number>;
|
|
4
|
+
/**
|
|
5
|
+
* Structure-of-Arrays view for spatial queries.
|
|
6
|
+
* All arrays are indexed in parallel — index `i` in each array
|
|
7
|
+
* corresponds to the same element.
|
|
8
|
+
*/
|
|
9
|
+
export interface SpatialSoAData {
|
|
10
|
+
/** Element IDs, indexed in parallel */
|
|
11
|
+
ids: string[];
|
|
12
|
+
/** X position (world-space) */
|
|
13
|
+
x: Float64Array;
|
|
14
|
+
/** Y position (world-space) */
|
|
15
|
+
y: Float64Array;
|
|
16
|
+
/** Width (world-space) */
|
|
17
|
+
w: Float64Array;
|
|
18
|
+
/** Height (world-space) */
|
|
19
|
+
h: Float64Array;
|
|
20
|
+
/** Element type as numeric code */
|
|
21
|
+
types: Uint8Array;
|
|
22
|
+
/** Active element count (may be less than array capacity) */
|
|
23
|
+
length: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Maintains SoA parallel views synchronized with the element array.
|
|
27
|
+
*
|
|
28
|
+
* Usage:
|
|
29
|
+
* ```ts
|
|
30
|
+
* const soa = new SpatialSoA();
|
|
31
|
+
* soa.rebuild(elements);
|
|
32
|
+
* const visibleIds = soa.cullViewport(viewport, stageW, stageH);
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare class SpatialSoA {
|
|
36
|
+
private _data;
|
|
37
|
+
/** Pre-allocated capacity (grows on demand) */
|
|
38
|
+
private _capacity;
|
|
39
|
+
/** ID → SoA index for O(1) single-element updates */
|
|
40
|
+
private _indexMap;
|
|
41
|
+
constructor(initialCapacity?: number);
|
|
42
|
+
/** Current element count */
|
|
43
|
+
get length(): number;
|
|
44
|
+
/** Read-only access to the SoA data */
|
|
45
|
+
get data(): Readonly<SpatialSoAData>;
|
|
46
|
+
private _allocate;
|
|
47
|
+
private _ensureCapacity;
|
|
48
|
+
/**
|
|
49
|
+
* Full rebuild from the canonical element array.
|
|
50
|
+
* Call when elements reference changes (add/remove/reorder).
|
|
51
|
+
* ~1.2ms for 10K elements.
|
|
52
|
+
*/
|
|
53
|
+
rebuild(elements: CanvasElement[]): void;
|
|
54
|
+
/**
|
|
55
|
+
* Update a single element's spatial data in-place.
|
|
56
|
+
* O(1) — no array copying.
|
|
57
|
+
* Returns false if the element is not in the SoA.
|
|
58
|
+
*/
|
|
59
|
+
updateElement(el: CanvasElement): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Viewport culling using SoA iteration.
|
|
62
|
+
* Returns IDs of elements whose AABB overlaps the viewport.
|
|
63
|
+
*
|
|
64
|
+
* 2-3× faster than AoS iteration for large sets because:
|
|
65
|
+
* - Sequential memory access (cache-line friendly)
|
|
66
|
+
* - No object pointer dereferencing per element
|
|
67
|
+
* - TypedArray iteration compiles to tight machine code in V8
|
|
68
|
+
*/
|
|
69
|
+
cullViewport(viewport: ViewportState, stageWidth: number, stageHeight: number, padding?: number): string[];
|
|
70
|
+
/**
|
|
71
|
+
* Rectangle query — return IDs of elements overlapping a world-space rect.
|
|
72
|
+
*/
|
|
73
|
+
queryRect(minX: number, minY: number, maxX: number, maxY: number): string[];
|
|
74
|
+
/**
|
|
75
|
+
* Point query — return IDs of elements containing a world-space point.
|
|
76
|
+
*/
|
|
77
|
+
queryPoint(wx: number, wy: number): string[];
|
|
78
|
+
/** Clear all data (does not release typed array memory) */
|
|
79
|
+
clear(): void;
|
|
80
|
+
}
|
|
81
|
+
/** Get or create a shared SpatialSoA singleton */
|
|
82
|
+
export declare function getSharedSpatialSoA(): SpatialSoA;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* elbowWorker.ts — Web Worker for off-main-thread elbow connector routing.
|
|
3
|
+
*
|
|
4
|
+
* Runs the expensive A* grid-search algorithm in a background thread so
|
|
5
|
+
* the main thread stays at 60fps during intensive drag operations that
|
|
6
|
+
* trigger many simultaneous route recomputations.
|
|
7
|
+
*
|
|
8
|
+
* Communication protocol:
|
|
9
|
+
* Main → Worker:
|
|
10
|
+
* { type: 'updateElements', elements: SerializedElement[] }
|
|
11
|
+
* { type: 'computeRoute', requestId, params: RouteParams }
|
|
12
|
+
* Worker → Main:
|
|
13
|
+
* { type: 'routeResult', requestId, points: number[] }
|
|
14
|
+
*
|
|
15
|
+
* Uses Vite's native Worker module support — imported with:
|
|
16
|
+
* new Worker(new URL('./elbowWorker.ts', import.meta.url), { type: 'module' })
|
|
17
|
+
*/
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* exportWorker.ts — Web Worker for off-main-thread SVG export.
|
|
3
|
+
*
|
|
4
|
+
* Generates SVG strings from serialized element data in a background
|
|
5
|
+
* thread, keeping the main thread responsive during export of large
|
|
6
|
+
* canvases (10K+ elements).
|
|
7
|
+
*
|
|
8
|
+
* Communication protocol:
|
|
9
|
+
* Main → Worker:
|
|
10
|
+
* { type: 'exportSVG', requestId: string, elements: CanvasElement[] }
|
|
11
|
+
* Worker → Main:
|
|
12
|
+
* { type: 'svgResult', requestId: string, svg: string }
|
|
13
|
+
* { type: 'error', requestId: string, message: string }
|
|
14
|
+
*
|
|
15
|
+
* Uses Vite's native Worker module support — imported with:
|
|
16
|
+
* new Worker(new URL('./exportWorker.ts', import.meta.url), { type: 'module' })
|
|
17
|
+
*/
|
|
18
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "f1ow",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Interactive canvas drawing toolkit built on KonvaJS — drop-in React component for diagrams, sketches & whiteboards",
|
|
6
|
+
"author": "Nuumz <info@nuumz.com>",
|
|
7
|
+
"homepage": "https://github.com/nuumz/f1ow-canvas#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/nuumz/f1ow-canvas.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/nuumz/f1ow-canvas/issues"
|
|
14
|
+
},
|
|
15
|
+
"main": "./dist/f1ow.umd.cjs",
|
|
16
|
+
"module": "./dist/f1ow.js",
|
|
17
|
+
"types": "./dist/lib/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/lib/index.d.ts",
|
|
21
|
+
"import": "./dist/f1ow.js",
|
|
22
|
+
"require": "./dist/f1ow.umd.cjs"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"LICENSE",
|
|
28
|
+
"README.md"
|
|
29
|
+
],
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"scripts": {
|
|
32
|
+
"dev": "vite",
|
|
33
|
+
"build": "vite build",
|
|
34
|
+
"build:lib": "vite build --mode lib",
|
|
35
|
+
"preview": "vite preview",
|
|
36
|
+
"typecheck": "tsc --noEmit",
|
|
37
|
+
"prepublishOnly": "npm run typecheck && npm run build:lib"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"react": ">=17.0.0",
|
|
41
|
+
"react-dom": ">=17.0.0"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"konva": "^9.3.18",
|
|
45
|
+
"lucide-react": "^0.468.0",
|
|
46
|
+
"nanoid": "^5.0.9",
|
|
47
|
+
"rbush": "^4.0.1",
|
|
48
|
+
"react-konva": "^18.2.10",
|
|
49
|
+
"y-websocket": "^3.0.0",
|
|
50
|
+
"yjs": "^13.6.29",
|
|
51
|
+
"zustand": "^5.0.3"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@types/node": "^25.2.1",
|
|
55
|
+
"@types/rbush": "^4.0.0",
|
|
56
|
+
"@types/react": "^18.3.18",
|
|
57
|
+
"@types/react-dom": "^18.3.5",
|
|
58
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
59
|
+
"react": "^18.3.1",
|
|
60
|
+
"react-dom": "^18.3.1",
|
|
61
|
+
"typescript": "^5.7.3",
|
|
62
|
+
"vite": "^6.0.7",
|
|
63
|
+
"vite-plugin-dts": "^4.3.0"
|
|
64
|
+
},
|
|
65
|
+
"keywords": [
|
|
66
|
+
"canvas",
|
|
67
|
+
"drawing",
|
|
68
|
+
"konvajs",
|
|
69
|
+
"react",
|
|
70
|
+
"whiteboard",
|
|
71
|
+
"diagram",
|
|
72
|
+
"flowchart",
|
|
73
|
+
"react-component",
|
|
74
|
+
"konva",
|
|
75
|
+
"collaborative",
|
|
76
|
+
"vector",
|
|
77
|
+
"sketch"
|
|
78
|
+
],
|
|
79
|
+
"license": "MIT"
|
|
80
|
+
}
|