@flowscape-ui/core-sdk 1.0.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 +300 -0
- package/dist/index.cjs +7347 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1430 -0
- package/dist/index.d.ts +1430 -0
- package/dist/index.js +7314 -0
- package/dist/index.js.map +1 -0
- package/package.json +87 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Flowscape UI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# 🎨 @flowscape-ui/core-sdk
|
|
4
|
+
|
|
5
|
+
**Powerful 2D canvas engine built on Konva**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@flowscape-ui/core-sdk)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
[](https://www.typescriptlang.org/)
|
|
10
|
+
[](https://bundlephobia.com/package/@flowscape-ui/core-sdk)
|
|
11
|
+
|
|
12
|
+
[Documentation](https://github.com/Flowscape-UI/core-sdk#readme) • [Examples](https://github.com/Flowscape-UI/core-sdk/tree/main/playground) • [Changelog](./CHANGELOG.md)
|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## ✨ Features
|
|
19
|
+
|
|
20
|
+
- 🎯 **Framework-agnostic** — works with React, Vue, Svelte, Angular or vanilla JS
|
|
21
|
+
- 🧩 **Plugin system** — extensible architecture with ready-to-use plugins
|
|
22
|
+
- 📐 **Complete toolset** — grid, rulers, guides, area selection
|
|
23
|
+
- ⌨️ **Hotkeys** — Ctrl+C/V/X, Delete, Ctrl+G for grouping
|
|
24
|
+
- 🎨 **Rich shapes** — rectangles, circles, text, images, arrows, stars
|
|
25
|
+
- 🔄 **Transformations** — rotation, scaling, movement with aspect ratio lock
|
|
26
|
+
- 📦 **TypeScript-first** — full typing out of the box
|
|
27
|
+
- 🚀 **Optimized** — tree-shaking, ESM + CJS, source maps
|
|
28
|
+
|
|
29
|
+
## 📦 Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install @flowscape-ui/core-sdk
|
|
33
|
+
# or
|
|
34
|
+
yarn add @flowscape-ui/core-sdk
|
|
35
|
+
# or
|
|
36
|
+
bun add @flowscape-ui/core-sdk
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 🚀 Quick Start
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { CoreEngine, GridPlugin, SelectionPlugin, NodeHotkeysPlugin } from '@flowscape-ui/core-sdk';
|
|
43
|
+
|
|
44
|
+
// Create engine with plugins
|
|
45
|
+
const core = new CoreEngine({
|
|
46
|
+
container: document.getElementById('canvas-container')!,
|
|
47
|
+
width: 1200,
|
|
48
|
+
height: 800,
|
|
49
|
+
plugins: [
|
|
50
|
+
new GridPlugin({ enabled: true }),
|
|
51
|
+
new SelectionPlugin({ dragEnabled: true }),
|
|
52
|
+
new NodeHotkeysPlugin(), // Ctrl+C/V/X, Delete
|
|
53
|
+
],
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Add shapes
|
|
57
|
+
const rect = core.nodes.addShape({
|
|
58
|
+
x: 100,
|
|
59
|
+
y: 100,
|
|
60
|
+
width: 200,
|
|
61
|
+
height: 150,
|
|
62
|
+
fill: '#3b82f6',
|
|
63
|
+
cornerRadius: 8,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const text = core.nodes.addText({
|
|
67
|
+
x: 120,
|
|
68
|
+
y: 140,
|
|
69
|
+
text: 'Hello Flowscape!',
|
|
70
|
+
fontSize: 24,
|
|
71
|
+
fill: 'white',
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// Grouping
|
|
75
|
+
const group = core.nodes.addGroup({
|
|
76
|
+
x: 400,
|
|
77
|
+
y: 200,
|
|
78
|
+
});
|
|
79
|
+
rect.getNode().moveTo(group.getNode());
|
|
80
|
+
text.getNode().moveTo(group.getNode());
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## 🏗️ Architecture
|
|
84
|
+
|
|
85
|
+
### Core Components
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
┌─────────────────────────────────────┐
|
|
89
|
+
│ CoreEngine │
|
|
90
|
+
│ ┌──────────────────────────────┐ │
|
|
91
|
+
│ │ Plugin System │ │
|
|
92
|
+
│ │ - GridPlugin │ │
|
|
93
|
+
│ │ - SelectionPlugin │ │
|
|
94
|
+
│ │ - RulerPlugin │ │
|
|
95
|
+
│ │ - NodeHotkeysPlugin │ │
|
|
96
|
+
│ └──────────────────────────────┘ │
|
|
97
|
+
│ ┌──────────────────────────────┐ │
|
|
98
|
+
│ │ Node Manager │ │
|
|
99
|
+
│ │ - ShapeNode │ │
|
|
100
|
+
│ │ - TextNode │ │
|
|
101
|
+
│ │ - ImageNode │ │
|
|
102
|
+
│ │ - GroupNode │ │
|
|
103
|
+
│ └──────────────────────────────┘ │
|
|
104
|
+
│ ┌──────────────────────────────┐ │
|
|
105
|
+
│ │ Camera Manager │ │
|
|
106
|
+
│ │ - Zoom (Ctrl+Wheel) │ │
|
|
107
|
+
│ │ - Pan (Space+Drag) │ │
|
|
108
|
+
│ └──────────────────────────────┘ │
|
|
109
|
+
└─────────────────────────────────────┘
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Plugin System
|
|
113
|
+
|
|
114
|
+
Plugins extend engine functionality without modifying the core:
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
import { Plugin } from '@flowscape-ui/core-sdk';
|
|
118
|
+
|
|
119
|
+
class CustomPlugin extends Plugin {
|
|
120
|
+
protected onAttach(core: CoreEngine): void {
|
|
121
|
+
// Initialize on attach
|
|
122
|
+
core.eventBus.on('node:created', (node) => {
|
|
123
|
+
console.log('Node created:', node);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
protected onDetach(core: CoreEngine): void {
|
|
128
|
+
// Cleanup on detach
|
|
129
|
+
core.eventBus.off('node:created');
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Usage
|
|
134
|
+
const core = new CoreEngine({
|
|
135
|
+
container: element,
|
|
136
|
+
plugins: [new CustomPlugin()],
|
|
137
|
+
});
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Built-in Plugins
|
|
141
|
+
|
|
142
|
+
| Plugin | Description |
|
|
143
|
+
| --------------------- | ---------------------------------------- |
|
|
144
|
+
| `GridPlugin` | Adaptive grid with automatic scaling |
|
|
145
|
+
| `SelectionPlugin` | Selection, transformation, drag & drop |
|
|
146
|
+
| `NodeHotkeysPlugin` | Ctrl+C/V/X, Delete, Ctrl+[/] for z-index |
|
|
147
|
+
| `CameraHotkeysPlugin` | Ctrl+wheel for zoom, arrows for pan |
|
|
148
|
+
| `RulerPlugin` | Rulers with measurement units |
|
|
149
|
+
| `RulerGuidesPlugin` | Guide lines (drag from rulers) |
|
|
150
|
+
| `AreaSelectionPlugin` | Area selection with frame (Shift+Drag) |
|
|
151
|
+
| `LogoPlugin` | Watermark/logo on canvas |
|
|
152
|
+
|
|
153
|
+
## 📚 Usage Examples
|
|
154
|
+
|
|
155
|
+
### Creating Shapes
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
// Rectangle with rounded corners
|
|
159
|
+
const rect = core.nodes.addShape({
|
|
160
|
+
x: 50,
|
|
161
|
+
y: 50,
|
|
162
|
+
width: 200,
|
|
163
|
+
height: 100,
|
|
164
|
+
fill: '#10b981',
|
|
165
|
+
cornerRadius: 12,
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// Circle
|
|
169
|
+
const circle = core.nodes.addCircle({
|
|
170
|
+
x: 300,
|
|
171
|
+
y: 100,
|
|
172
|
+
radius: 50,
|
|
173
|
+
fill: '#f59e0b',
|
|
174
|
+
stroke: '#d97706',
|
|
175
|
+
strokeWidth: 3,
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// Text
|
|
179
|
+
const text = core.nodes.addText({
|
|
180
|
+
x: 400,
|
|
181
|
+
y: 50,
|
|
182
|
+
text: 'Flowscape UI',
|
|
183
|
+
fontSize: 32,
|
|
184
|
+
fontFamily: 'Inter',
|
|
185
|
+
fill: '#1f2937',
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// Image
|
|
189
|
+
const image = core.nodes.addImage({
|
|
190
|
+
x: 100,
|
|
191
|
+
y: 200,
|
|
192
|
+
width: 200,
|
|
193
|
+
height: 150,
|
|
194
|
+
src: '/path/to/image.jpg',
|
|
195
|
+
});
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Working with Events
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
// Subscribe to events
|
|
202
|
+
core.eventBus.on('node:created', (node) => {
|
|
203
|
+
console.log('Node created:', node);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
core.eventBus.on('node:selected', (node) => {
|
|
207
|
+
console.log('Node selected:', node);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
core.eventBus.on('camera:zoom', ({ scale }) => {
|
|
211
|
+
console.log('Zoom changed:', scale);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// Unsubscribe
|
|
215
|
+
const handler = (node) => console.log(node);
|
|
216
|
+
core.eventBus.on('node:created', handler);
|
|
217
|
+
core.eventBus.off('node:created', handler);
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Grouping and Management
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
// Create group
|
|
224
|
+
const group = core.nodes.addGroup({ x: 0, y: 0 });
|
|
225
|
+
|
|
226
|
+
// Add nodes to group
|
|
227
|
+
const rect1 = core.nodes.addShape({ x: 10, y: 10, width: 50, height: 50 });
|
|
228
|
+
const rect2 = core.nodes.addShape({ x: 70, y: 10, width: 50, height: 50 });
|
|
229
|
+
|
|
230
|
+
rect1.getNode().moveTo(group.getNode());
|
|
231
|
+
rect2.getNode().moveTo(group.getNode());
|
|
232
|
+
|
|
233
|
+
// Manage z-index
|
|
234
|
+
rect1.getNode().moveUp(); // Move up one level
|
|
235
|
+
rect2.getNode().moveDown(); // Move down one level
|
|
236
|
+
rect1.getNode().moveToTop(); // Move to top
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Camera and Navigation
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
// Programmatic zoom
|
|
243
|
+
core.camera.zoomIn(); // Zoom in
|
|
244
|
+
core.camera.zoomOut(); // Zoom out
|
|
245
|
+
core.camera.setZoom(1.5); // Set specific scale
|
|
246
|
+
|
|
247
|
+
// Panning
|
|
248
|
+
core.camera.pan(100, 50); // Pan by dx, dy
|
|
249
|
+
|
|
250
|
+
// Center on node
|
|
251
|
+
const node = core.nodes.addShape({ x: 500, y: 500, width: 100, height: 100 });
|
|
252
|
+
core.camera.centerOn(node);
|
|
253
|
+
|
|
254
|
+
// Reset camera
|
|
255
|
+
core.camera.reset();
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## 🔧 Development
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
# Install dependencies
|
|
262
|
+
bun install
|
|
263
|
+
|
|
264
|
+
# Run playground
|
|
265
|
+
bun run dev
|
|
266
|
+
|
|
267
|
+
# Build library
|
|
268
|
+
bun run build
|
|
269
|
+
|
|
270
|
+
# Tests
|
|
271
|
+
bun run test # Watch mode
|
|
272
|
+
bun run test:run # Single run
|
|
273
|
+
bun run test:coverage # With coverage
|
|
274
|
+
|
|
275
|
+
# Linting
|
|
276
|
+
bun run lint # ESLint
|
|
277
|
+
bun run lint:ts # TypeScript check
|
|
278
|
+
bun run lint:fix # Auto-fix
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
## 📖 Documentation
|
|
282
|
+
|
|
283
|
+
Coming soon
|
|
284
|
+
|
|
285
|
+
### Branching Strategy
|
|
286
|
+
|
|
287
|
+
- `dev` — active development
|
|
288
|
+
- `main` — stable version, auto-publish to npm
|
|
289
|
+
|
|
290
|
+
## 📄 License
|
|
291
|
+
|
|
292
|
+
MIT © [Flowscape UI Team](https://github.com/Flowscape-UI)
|
|
293
|
+
|
|
294
|
+
---
|
|
295
|
+
|
|
296
|
+
<div align="center">
|
|
297
|
+
|
|
298
|
+
**[⭐ Star on GitHub](https://github.com/Flowscape-UI/core-sdk)** • **[🐛 Report Bug](https://github.com/Flowscape-UI/core-sdk/issues)** • **[💡 Request Feature](https://github.com/Flowscape-UI/core-sdk/issues/new)**
|
|
299
|
+
|
|
300
|
+
</div>
|