@ngenux/ngage-whiteboarding 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.
Files changed (38) hide show
  1. package/README.md +249 -0
  2. package/dist/index.d.ts +11 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.esm.js +42595 -0
  5. package/dist/index.esm.js.map +1 -0
  6. package/dist/index.js +42617 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/src/components/Shapes/Arrow.d.ts +11 -0
  9. package/dist/src/components/Shapes/Arrow.d.ts.map +1 -0
  10. package/dist/src/components/Shapes/Ellipse.d.ts +11 -0
  11. package/dist/src/components/Shapes/Ellipse.d.ts.map +1 -0
  12. package/dist/src/components/Shapes/ErasedShape.d.ts +11 -0
  13. package/dist/src/components/Shapes/ErasedShape.d.ts.map +1 -0
  14. package/dist/src/components/Shapes/FreehandDrawing.d.ts +11 -0
  15. package/dist/src/components/Shapes/FreehandDrawing.d.ts.map +1 -0
  16. package/dist/src/components/Shapes/Line.d.ts +11 -0
  17. package/dist/src/components/Shapes/Line.d.ts.map +1 -0
  18. package/dist/src/components/Shapes/Rectangle.d.ts +11 -0
  19. package/dist/src/components/Shapes/Rectangle.d.ts.map +1 -0
  20. package/dist/src/components/Whiteboard/Board.d.ts +14 -0
  21. package/dist/src/components/Whiteboard/Board.d.ts.map +1 -0
  22. package/dist/src/components/Whiteboard/Toolbar.d.ts +19 -0
  23. package/dist/src/components/Whiteboard/Toolbar.d.ts.map +1 -0
  24. package/dist/src/components/Whiteboard/index.d.ts +9 -0
  25. package/dist/src/components/Whiteboard/index.d.ts.map +1 -0
  26. package/dist/src/context/WhiteboardContext.d.ts +128 -0
  27. package/dist/src/context/WhiteboardContext.d.ts.map +1 -0
  28. package/dist/src/hooks/useCapture.d.ts +4 -0
  29. package/dist/src/hooks/useCapture.d.ts.map +1 -0
  30. package/dist/src/hooks/useCollaborativeWhiteboard.d.ts +27 -0
  31. package/dist/src/hooks/useCollaborativeWhiteboard.d.ts.map +1 -0
  32. package/dist/src/types/index.d.ts +123 -0
  33. package/dist/src/types/index.d.ts.map +1 -0
  34. package/dist/src/utils/compression.d.ts +14 -0
  35. package/dist/src/utils/compression.d.ts.map +1 -0
  36. package/dist/src/utils/socket-utility.d.ts +6 -0
  37. package/dist/src/utils/socket-utility.d.ts.map +1 -0
  38. package/package.json +97 -0
package/README.md ADDED
@@ -0,0 +1,249 @@
1
+ # React Collaborative Whiteboard
2
+
3
+ A React component library for creating collaborative whiteboards with real-time synchronization via WebSockets.
4
+
5
+ ## ✨ Features
6
+
7
+ - 🎨 **Real-time collaborative drawing** - Multiple users can draw simultaneously
8
+ - 🔧 **Multiple drawing tools** - Pencil, shapes (rectangle, ellipse, arrow), eraser, line tools
9
+ - â†Šī¸ **Undo/Redo functionality** - Per-user undo/redo with collaborative support
10
+ - đŸ‘Ĩ **Multi-user support** - Admin controls and user permissions
11
+ - 📱 **Responsive design** - Works on desktop, tablet, and mobile
12
+ - 🔒 **Admin controls** - Lock/unlock canvas, clear canvas, user management
13
+ - 💾 **Export functionality** - PNG, JPEG, PDF export options
14
+ - đŸ—œī¸ **Data compression** - Optimized performance with automatic compression
15
+ - ⚡ **Real-time sync** - Ultra-smooth 60fps collaborative drawing experience
16
+ - đŸŽ¯ **TypeScript support** - Fully typed for better development experience
17
+
18
+ ## đŸ“Ļ Installation
19
+
20
+ ```bash
21
+ npm install @ngenux/ngage-whiteboarding
22
+ ```
23
+
24
+ ## 🚀 Quick Start
25
+
26
+ ### Basic Setup
27
+
28
+ ```tsx
29
+ import React from 'react';
30
+ import { WhiteboardProvider, Whiteboard } from '@ngenux/ngage-whiteboarding';
31
+
32
+ function App() {
33
+ return (
34
+ <WhiteboardProvider webSocketUrl="ws://localhost:3001">
35
+ <Whiteboard
36
+ roomId="room-123"
37
+ userId="user-456"
38
+ isAdmin={true}
39
+ allowedUsers={['user-456', 'user-789']}
40
+ />
41
+ </WhiteboardProvider>
42
+ );
43
+ }
44
+
45
+ export default App;
46
+ ```
47
+
48
+ ### Advanced Usage with Multiple Rooms
49
+
50
+ ```tsx
51
+ import React, { useState } from 'react';
52
+ import { WhiteboardProvider, Whiteboard } from '@ngenux/ngage-whiteboarding';
53
+
54
+ function CollaborativeApp() {
55
+ const [currentRoom, setCurrentRoom] = useState('room-1');
56
+ const [currentUser] = useState('user-' + Math.random().toString(36).substr(2, 9));
57
+
58
+ return (
59
+ <WhiteboardProvider webSocketUrl="wss://your-websocket-server.com">
60
+ <div>
61
+ <select value={currentRoom} onChange={(e) => setCurrentRoom(e.target.value)}>
62
+ <option value="room-1">Room 1</option>
63
+ <option value="room-2">Room 2</option>
64
+ <option value="room-3">Room 3</option>
65
+ </select>
66
+
67
+ <Whiteboard
68
+ roomId={currentRoom}
69
+ userId={currentUser}
70
+ isAdmin={currentUser === 'admin-user'}
71
+ allowedUsers={[currentUser, 'other-user-1', 'other-user-2']}
72
+ />
73
+ </div>
74
+ </WhiteboardProvider>
75
+ );
76
+ }
77
+ ```
78
+
79
+ ## 📝 API Reference
80
+
81
+ ### WhiteboardProvider Props
82
+
83
+ | Prop | Type | Required | Description |
84
+ |------|------|----------|-------------|
85
+ | `webSocketUrl` | `string` | ✅ | WebSocket server URL for real-time collaboration |
86
+ | `children` | `ReactNode` | ✅ | Child components (typically contains `<Whiteboard>`) |
87
+
88
+ ### Whiteboard Props
89
+
90
+ | Prop | Type | Required | Default | Description |
91
+ |------|------|----------|---------|-------------|
92
+ | `roomId` | `string` | ✅ | - | Unique identifier for the collaboration room |
93
+ | `userId` | `string` | ✅ | - | Unique identifier for the current user |
94
+ | `isAdmin` | `boolean` | ❌ | `false` | Whether user has admin privileges (clear, lock/unlock) |
95
+ | `allowedUsers` | `string[]` | ❌ | `[]` | Array of user IDs who have drawing permissions |
96
+
97
+ ### Hooks
98
+
99
+ #### useWhiteboardStream
100
+
101
+ Automatically captures the whiteboard canvas as a video stream (30 FPS). No manual start/stop controls needed.
102
+
103
+ ```tsx
104
+ import { useWhiteboardStream } from '@ngenux/ngage-whiteboarding';
105
+
106
+ function VideoStreamComponent() {
107
+ const { mediaStream } = useWhiteboardStream();
108
+
109
+ return (
110
+ <div>
111
+ {mediaStream && (
112
+ <video
113
+ srcObject={mediaStream}
114
+ autoPlay
115
+ muted
116
+ style={{ width: '300px', height: '200px' }}
117
+ />
118
+ )}
119
+ </div>
120
+ );
121
+ }
122
+ ```
123
+
124
+ **Note:** Stream capture starts automatically when the whiteboard canvas is available and can be controlled via the whiteboard context's `captureEnabled` state.
125
+
126
+ ## 🎨 Features in Detail
127
+
128
+ ### Drawing Tools
129
+ - **Pencil**: Freehand drawing
130
+ - **Shapes**: Rectangle, Ellipse, Arrow, Line
131
+ - **Eraser**: Remove parts of drawings
132
+ - **Select**: Move and transform shapes
133
+ - **Pan**: Navigate around the canvas
134
+
135
+ ### Collaborative Features
136
+ - **Real-time drawing**: See other users draw in real-time
137
+ - **User permissions**: Control who can draw
138
+ - **Admin controls**: Lock/unlock canvas, clear all drawings
139
+ - **Per-user undo/redo**: Each user maintains their own undo stack
140
+
141
+ ### Export Options
142
+ - **PNG**: Transparent or solid background
143
+ - **JPEG**: Solid background (white if transparent is selected)
144
+ - **PDF-format**: High-quality PNG optimized for printing/PDF conversion
145
+
146
+ ## đŸ› ī¸ Development
147
+
148
+ ### Building the Package
149
+
150
+ ```bash
151
+ # Install dependencies
152
+ npm install
153
+
154
+ # Build the package
155
+ npm run build
156
+
157
+ # Watch mode for development
158
+ npm run dev
159
+
160
+ # Preview package contents
161
+ npm run pack-preview
162
+
163
+ # Clean build artifacts
164
+ npm run clean
165
+ ```
166
+
167
+ ### Package Structure
168
+
169
+ ```
170
+ dist/
171
+ ├── index.js # CommonJS build
172
+ ├── index.esm.js # ES modules build
173
+ ├── index.d.ts # TypeScript definitions
174
+ └── *.map # Source maps
175
+ ```
176
+
177
+ ## 🔧 TypeScript Support
178
+
179
+ The package includes full TypeScript definitions:
180
+
181
+ ```tsx
182
+ import type {
183
+ WhiteboardProps,
184
+ WhiteboardProviderProps,
185
+ ToolType,
186
+ StrokeStyle
187
+ } from '@ngenux/ngage-whiteboarding';
188
+
189
+ const MyWhiteboard: React.FC<WhiteboardProps> = (props) => {
190
+ // Your implementation
191
+ };
192
+ ```
193
+
194
+ ## 🌐 Browser Support
195
+
196
+ - Chrome 80+
197
+ - Firefox 75+
198
+ - Safari 13+
199
+ - Edge 80+
200
+
201
+ ## 📱 Responsive Design
202
+
203
+ The whiteboard automatically adapts to different screen sizes and supports touch interactions on mobile devices.
204
+
205
+ ## ⚡ Performance
206
+
207
+ - **Optimized rendering**: Uses Konva.js for high-performance 2D canvas rendering
208
+ - **Data compression**: Automatic compression of collaborative data
209
+ - **Throttled updates**: Optimized for 60fps real-time collaboration
210
+ - **Memory efficient**: Smart cleanup of stale collaborative data
211
+
212
+ ## 🐛 Troubleshooting
213
+
214
+ ### Common Issues
215
+
216
+ 1. **WebSocket connection fails**
217
+ - Ensure your WebSocket server is running and accessible
218
+ - Check CORS configuration on your server
219
+ - Verify the `webSocketUrl` is correct
220
+
221
+ 2. **Drawing doesn't sync between users**
222
+ - Verify all users are in the same `roomId`
223
+ - Check WebSocket server is properly broadcasting messages
224
+ - Ensure `userId` is unique for each user
225
+
226
+ 3. **TypeScript errors**
227
+ - Make sure you're importing types correctly
228
+ - Verify your TypeScript configuration includes the package types
229
+
230
+ ## 📄 License
231
+
232
+ MIT
233
+
234
+ ## 🤝 Contributing
235
+
236
+ Contributions are welcome! Please feel free to submit a Pull Request.
237
+
238
+ ## 📞 Support
239
+
240
+ If you encounter any issues or have questions, please file an issue on the GitHub repository.
241
+
242
+ ---
243
+
244
+ ## 👨‍đŸ’ģ Author
245
+
246
+ **ng-sushil**
247
+ - GitHub: [@ng-sushil](https://github.com/ng-sushil)
248
+
249
+ **Happy collaborating! 🎨✨**
@@ -0,0 +1,11 @@
1
+ import { Whiteboard } from './src/components/Whiteboard';
2
+ import { WhiteboardProvider } from './src/context/WhiteboardContext';
3
+ import { useCapture } from './src/hooks/useCapture';
4
+ export { Whiteboard, WhiteboardProvider, useCapture as useWhiteboardStream };
5
+ export type { WhiteboardProps } from './src/components/Whiteboard';
6
+ export type { ShapeProps, ToolType, StrokeStyle, WhiteboardState, DrawingAction, CompressedData } from './src/types';
7
+ export interface WhiteboardProviderProps {
8
+ children: React.ReactNode;
9
+ webSocketUrl?: string;
10
+ }
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,UAAU,IAAI,mBAAmB,EAAE,CAAC;AAG7E,YAAY,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,YAAY,EACV,UAAU,EACV,QAAQ,EACR,WAAW,EACX,eAAe,EACf,aAAa,EACb,cAAc,EACf,MAAM,aAAa,CAAC;AAGrB,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB"}