jasvir-singh1021 commited on
Commit
af233d1
Β·
verified Β·
1 Parent(s): 3c43538

make a React web app that lets users drag-and-drop both images and text, arrange them freely on a canvas, and design beautiful compositions β€” like posters, mood boards, memos, or social media graphics. 🌟 Suggested React App: Canvas Studio Goal: A simple, intuitive editor where users can upload images and add text blocks, then drag, resize, rotate, and style them freely. βœ… Core Features Drag-and-drop elements (images & text) on a freeform canvas Resizable elements (grab corners to scale) Draggable anywhere on canvas Editable text content, with basic fonts, colors, size sliders Upload images from locally or unsplash Download/export as PNG or JPG Optional templates or grid snapping - Initial Deployment

Browse files
Files changed (2) hide show
  1. README.md +7 -5
  2. index.html +670 -19
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Canvas Studio
3
- emoji: πŸ”₯
4
- colorFrom: gray
5
- colorTo: yellow
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: canvas-studio
3
+ emoji: 🐳
4
+ colorFrom: green
5
+ colorTo: pink
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,670 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Canvas Studio - Design Beautiful Compositions</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <script src="https://unpkg.com/react@18/umd/react.development.js"></script>
9
+ <script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
10
+ <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
11
+ <script src="https://unpkg.com/react-draggable@4.4.4/build/web/react-draggable.min.js"></script>
12
+ <script src="https://unpkg.com/html-to-image@1.11.11/dist/html-to-image.min.js"></script>
13
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
14
+ <style>
15
+ .canvas-container {
16
+ background-image: linear-gradient(45deg, #f5f5f5 25%, transparent 25%),
17
+ linear-gradient(-45deg, #f5f5f5 25%, transparent 25%),
18
+ linear-gradient(45deg, transparent 75%, #f5f5f5 75%),
19
+ linear-gradient(-45deg, transparent 75%, #f5f5f5 75%);
20
+ background-size: 20px 20px;
21
+ background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
22
+ }
23
+ .element-resize-handle {
24
+ position: absolute;
25
+ width: 10px;
26
+ height: 10px;
27
+ background: #3b82f6;
28
+ border-radius: 50%;
29
+ bottom: -5px;
30
+ right: -5px;
31
+ cursor: nwse-resize;
32
+ }
33
+ .element-rotate-handle {
34
+ position: absolute;
35
+ width: 16px;
36
+ height: 16px;
37
+ top: -20px;
38
+ left: 50%;
39
+ transform: translateX(-50%);
40
+ cursor: grab;
41
+ color: #3b82f6;
42
+ }
43
+ .element.selected {
44
+ box-shadow: 0 0 0 2px #3b82f6;
45
+ }
46
+ .font-selector {
47
+ scrollbar-width: thin;
48
+ scrollbar-color: #3b82f6 #e5e7eb;
49
+ }
50
+ .font-selector::-webkit-scrollbar {
51
+ width: 6px;
52
+ }
53
+ .font-selector::-webkit-scrollbar-track {
54
+ background: #e5e7eb;
55
+ }
56
+ .font-selector::-webkit-scrollbar-thumb {
57
+ background-color: #3b82f6;
58
+ border-radius: 3px;
59
+ }
60
+ .unsplash-grid {
61
+ display: grid;
62
+ grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
63
+ gap: 8px;
64
+ }
65
+ @media (max-width: 768px) {
66
+ .toolbar {
67
+ flex-direction: column;
68
+ align-items: flex-start;
69
+ }
70
+ .toolbar-section {
71
+ margin-bottom: 8px;
72
+ }
73
+ .unsplash-grid {
74
+ grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
75
+ }
76
+ }
77
+ </style>
78
+ </head>
79
+ <body class="bg-gray-50">
80
+ <div id="root"></div>
81
+
82
+ <script type="text/babel">
83
+ const { useState, useRef, useEffect, useCallback } = React;
84
+ const Draggable = ReactDraggable;
85
+
86
+ const CanvasStudio = () => {
87
+ const [elements, setElements] = useState([]);
88
+ const [selectedElementId, setSelectedElementId] = useState(null);
89
+ const [activeTool, setActiveTool] = useState(null);
90
+ const [showImageUpload, setShowImageUpload] = useState(false);
91
+ const [showUnsplash, setShowUnsplash] = useState(false);
92
+ const [unsplashImages, setUnsplashImages] = useState([]);
93
+ const [unsplashQuery, setUnsplashQuery] = useState('nature');
94
+ const [canvasSize, setCanvasSize] = useState({ width: 800, height: 600 });
95
+ const [showTemplates, setShowTemplates] = useState(false);
96
+ const [enableGrid, setEnableGrid] = useState(false);
97
+ const [gridSize, setGridSize] = useState(20);
98
+
99
+ const canvasRef = useRef(null);
100
+ const fileInputRef = useRef(null);
101
+
102
+ const templates = [
103
+ {
104
+ name: 'Social Media Post',
105
+ elements: [
106
+ { type: 'text', content: 'Your Title Here', x: 100, y: 100, width: 200, fontSize: 32, color: '#000000', fontFamily: 'Arial' },
107
+ { type: 'text', content: 'Add your message', x: 100, y: 150, width: 300, fontSize: 16, color: '#555555', fontFamily: 'Arial' },
108
+ { type: 'image', src: 'https://images.unsplash.com/photo-1506744038136-46273834b3fb', x: 400, y: 100, width: 300, height: 300 }
109
+ ]
110
+ },
111
+ {
112
+ name: 'Mood Board',
113
+ elements: [
114
+ { type: 'image', src: 'https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05', x: 50, y: 50, width: 200, height: 200 },
115
+ { type: 'image', src: 'https://images.unsplash.com/photo-1447752875215-b2761acb3c5d', x: 300, y: 50, width: 200, height: 200 },
116
+ { type: 'image', src: 'https://images.unsplash.com/photo-1475924156734-496f6cac6ec1', x: 550, y: 50, width: 200, height: 200 },
117
+ { type: 'text', content: 'Inspiration', x: 300, y: 300, width: 200, fontSize: 24, color: '#000000', fontFamily: 'Helvetica' }
118
+ ]
119
+ }
120
+ ];
121
+
122
+ const fonts = [
123
+ 'Arial', 'Helvetica', 'Times New Roman', 'Courier New',
124
+ 'Georgia', 'Verdana', 'Impact', 'Comic Sans MS',
125
+ 'Trebuchet MS', 'Palatino', 'Garamond', 'Bookman'
126
+ ];
127
+
128
+ const selectedElement = elements.find(el => el.id === selectedElementId);
129
+
130
+ const addTextElement = () => {
131
+ const newElement = {
132
+ id: Date.now(),
133
+ type: 'text',
134
+ content: 'Double click to edit',
135
+ x: 100,
136
+ y: 100,
137
+ width: 200,
138
+ fontSize: 24,
139
+ color: '#000000',
140
+ fontFamily: 'Arial',
141
+ rotation: 0
142
+ };
143
+ setElements([...elements, newElement]);
144
+ setSelectedElementId(newElement.id);
145
+ };
146
+
147
+ const addImageElement = (src) => {
148
+ const newElement = {
149
+ id: Date.now(),
150
+ type: 'image',
151
+ src: src,
152
+ x: 200,
153
+ y: 200,
154
+ width: 200,
155
+ height: 200,
156
+ rotation: 0
157
+ };
158
+ setElements([...elements, newElement]);
159
+ setSelectedElementId(newElement.id);
160
+ setShowImageUpload(false);
161
+ setShowUnsplash(false);
162
+ };
163
+
164
+ const handleFileUpload = (e) => {
165
+ const file = e.target.files[0];
166
+ if (file) {
167
+ const reader = new FileReader();
168
+ reader.onload = (event) => {
169
+ addImageElement(event.target.result);
170
+ };
171
+ reader.readAsDataURL(file);
172
+ }
173
+ };
174
+
175
+ const handleElementClick = (id, e) => {
176
+ e.stopPropagation();
177
+ setSelectedElementId(id);
178
+ };
179
+
180
+ const handleCanvasClick = () => {
181
+ setSelectedElementId(null);
182
+ };
183
+
184
+ const handleDragStop = (id, e, data) => {
185
+ setElements(elements.map(el =>
186
+ el.id === id ? { ...el, x: enableGrid ? Math.round(data.x / gridSize) * gridSize : data.x,
187
+ y: enableGrid ? Math.round(data.y / gridSize) * gridSize : data.y } : el
188
+ ));
189
+ };
190
+
191
+ const handleResize = (id, e, direction, ref, delta, position) => {
192
+ setElements(elements.map(el =>
193
+ el.id === id ? {
194
+ ...el,
195
+ width: enableGrid ? Math.round(ref.style.width.replace('px', '') / gridSize) * gridSize : ref.style.width.replace('px', ''),
196
+ height: el.type === 'image' ? (enableGrid ? Math.round(ref.style.height.replace('px', '') / gridSize) * gridSize : ref.style.height.replace('px', '')) : null
197
+ } : el
198
+ ));
199
+ };
200
+
201
+ const handleTextChange = (id, newContent) => {
202
+ setElements(elements.map(el =>
203
+ el.id === id ? { ...el, content: newContent } : el
204
+ ));
205
+ };
206
+
207
+ const handleStyleChange = (property, value) => {
208
+ if (!selectedElementId) return;
209
+ setElements(elements.map(el =>
210
+ el.id === selectedElementId ? { ...el, [property]: value } : el
211
+ ));
212
+ };
213
+
214
+ const deleteSelectedElement = () => {
215
+ if (!selectedElementId) return;
216
+ setElements(elements.filter(el => el.id !== selectedElementId));
217
+ setSelectedElementId(null);
218
+ };
219
+
220
+ const fetchUnsplashImages = useCallback(async () => {
221
+ try {
222
+ const response = await fetch(`https://api.unsplash.com/search/photos?query=${unsplashQuery}&per_page=12&client_id=YOUR_UNSPLASH_ACCESS_KEY`);
223
+ const data = await response.json();
224
+ setUnsplashImages(data.results);
225
+ } catch (error) {
226
+ console.error('Error fetching Unsplash images:', error);
227
+ // Fallback to sample images if API fails
228
+ setUnsplashImages([
229
+ { urls: { regular: 'https://images.unsplash.com/photo-1506744038136-46273834b3fb' } },
230
+ { urls: { regular: 'https://images.unsplash.com/photo-1447752875215-b2761acb3c5d' } },
231
+ { urls: { regular: 'https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05' } },
232
+ { urls: { regular: 'https://images.unsplash.com/photo-1475924156734-496f6cac6ec1' } },
233
+ { urls: { regular: 'https://images.unsplash.com/photo-1501785888041-af3e2856c31f' } },
234
+ { urls: { regular: 'https://images.unsplash.com/photo-1441974231531-c6227db76b6e' } }
235
+ ]);
236
+ }
237
+ }, [unsplashQuery]);
238
+
239
+ useEffect(() => {
240
+ if (showUnsplash) {
241
+ fetchUnsplashImages();
242
+ }
243
+ }, [showUnsplash, unsplashQuery, fetchUnsplashImages]);
244
+
245
+ const downloadCanvas = async () => {
246
+ if (!canvasRef.current) return;
247
+
248
+ try {
249
+ const dataUrl = await htmlToImage.toPng(canvasRef.current);
250
+ const link = document.createElement('a');
251
+ link.download = 'canvas-studio-design.png';
252
+ link.href = dataUrl;
253
+ link.click();
254
+ } catch (error) {
255
+ console.error('Error downloading canvas:', error);
256
+ }
257
+ };
258
+
259
+ const applyTemplate = (template) => {
260
+ const newElements = template.elements.map(el => ({
261
+ ...el,
262
+ id: Date.now() + Math.random()
263
+ }));
264
+ setElements(newElements);
265
+ setShowTemplates(false);
266
+ };
267
+
268
+ const handleRotate = (id, e) => {
269
+ const rotation = parseInt(e.target.value);
270
+ setElements(elements.map(el =>
271
+ el.id === id ? { ...el, rotation } : el
272
+ ));
273
+ };
274
+
275
+ return (
276
+ <div className="min-h-screen flex flex-col">
277
+ {/* Header */}
278
+ <header className="bg-white shadow-sm py-4 px-6">
279
+ <div className="flex justify-between items-center">
280
+ <h1 className="text-2xl font-bold text-blue-600 flex items-center">
281
+ <i className="fas fa-palette mr-2"></i> Canvas Studio
282
+ </h1>
283
+ <div className="flex space-x-4">
284
+ <button
285
+ onClick={() => setShowTemplates(!showTemplates)}
286
+ className="px-4 py-2 bg-gray-100 hover:bg-gray-200 rounded-md flex items-center"
287
+ >
288
+ <i className="fas fa-clone mr-2"></i> Templates
289
+ </button>
290
+ <button
291
+ onClick={downloadCanvas}
292
+ className="px-4 py-2 bg-blue-600 text-white hover:bg-blue-700 rounded-md flex items-center"
293
+ >
294
+ <i className="fas fa-download mr-2"></i> Download
295
+ </button>
296
+ </div>
297
+ </div>
298
+ </header>
299
+
300
+ <div className="flex flex-1 overflow-hidden">
301
+ {/* Sidebar */}
302
+ <div className="w-64 bg-white border-r p-4 overflow-y-auto">
303
+ <h2 className="font-semibold text-lg mb-4">Elements</h2>
304
+
305
+ <div className="space-y-3">
306
+ <button
307
+ onClick={addTextElement}
308
+ className="w-full flex items-center justify-between px-4 py-2 bg-gray-100 hover:bg-gray-200 rounded-md"
309
+ >
310
+ <span>Add Text</span>
311
+ <i className="fas fa-font"></i>
312
+ </button>
313
+
314
+ <button
315
+ onClick={() => {
316
+ setShowImageUpload(true);
317
+ setShowUnsplash(false);
318
+ }}
319
+ className="w-full flex items-center justify-between px-4 py-2 bg-gray-100 hover:bg-gray-200 rounded-md"
320
+ >
321
+ <span>Upload Image</span>
322
+ <i className="fas fa-upload"></i>
323
+ </button>
324
+
325
+ <button
326
+ onClick={() => {
327
+ setShowUnsplash(true);
328
+ setShowImageUpload(false);
329
+ }}
330
+ className="w-full flex items-center justify-between px-4 py-2 bg-gray-100 hover:bg-gray-200 rounded-md"
331
+ >
332
+ <span>Unsplash Images</span>
333
+ <i className="fas fa-camera"></i>
334
+ </button>
335
+ </div>
336
+
337
+ {showImageUpload && (
338
+ <div className="mt-4 p-4 bg-gray-50 rounded-md">
339
+ <input
340
+ type="file"
341
+ ref={fileInputRef}
342
+ onChange={handleFileUpload}
343
+ accept="image/*"
344
+ className="hidden"
345
+ />
346
+ <button
347
+ onClick={() => fileInputRef.current.click()}
348
+ className="w-full px-4 py-2 bg-blue-600 text-white hover:bg-blue-700 rounded-md"
349
+ >
350
+ Select Image
351
+ </button>
352
+ </div>
353
+ )}
354
+
355
+ {showUnsplash && (
356
+ <div className="mt-4">
357
+ <div className="flex mb-2">
358
+ <input
359
+ type="text"
360
+ value={unsplashQuery}
361
+ onChange={(e) => setUnsplashQuery(e.target.value)}
362
+ placeholder="Search Unsplash"
363
+ className="flex-1 px-3 py-2 border rounded-l-md"
364
+ />
365
+ <button
366
+ onClick={fetchUnsplashImages}
367
+ className="px-3 py-2 bg-blue-600 text-white rounded-r-md"
368
+ >
369
+ <i className="fas fa-search"></i>
370
+ </button>
371
+ </div>
372
+ <div className="unsplash-grid max-h-64 overflow-y-auto">
373
+ {unsplashImages.map((img, index) => (
374
+ <img
375
+ key={index}
376
+ src={img.urls?.regular}
377
+ alt="Unsplash"
378
+ className="w-full h-24 object-cover rounded cursor-pointer hover:opacity-80"
379
+ onClick={() => addImageElement(img.urls?.regular)}
380
+ />
381
+ ))}
382
+ </div>
383
+ </div>
384
+ )}
385
+
386
+ {showTemplates && (
387
+ <div className="mt-4">
388
+ <h3 className="font-medium mb-2">Templates</h3>
389
+ <div className="space-y-2">
390
+ {templates.map((template, index) => (
391
+ <div
392
+ key={index}
393
+ className="p-3 border rounded-md cursor-pointer hover:bg-gray-50"
394
+ onClick={() => applyTemplate(template)}
395
+ >
396
+ <div className="font-medium">{template.name}</div>
397
+ <div className="text-sm text-gray-500">{template.elements.length} elements</div>
398
+ </div>
399
+ ))}
400
+ </div>
401
+ </div>
402
+ )}
403
+
404
+ <div className="mt-6">
405
+ <h2 className="font-semibold text-lg mb-2">Canvas Settings</h2>
406
+ <div className="space-y-3">
407
+ <div>
408
+ <label className="block text-sm font-medium mb-1">Width</label>
409
+ <input
410
+ type="number"
411
+ value={canvasSize.width}
412
+ onChange={(e) => setCanvasSize({...canvasSize, width: parseInt(e.target.value)})}
413
+ className="w-full px-3 py-2 border rounded-md"
414
+ />
415
+ </div>
416
+ <div>
417
+ <label className="block text-sm font-medium mb-1">Height</label>
418
+ <input
419
+ type="number"
420
+ value={canvasSize.height}
421
+ onChange={(e) => setCanvasSize({...canvasSize, height: parseInt(e.target.value)})}
422
+ className="w-full px-3 py-2 border rounded-md"
423
+ />
424
+ </div>
425
+ <div className="flex items-center">
426
+ <input
427
+ type="checkbox"
428
+ id="enableGrid"
429
+ checked={enableGrid}
430
+ onChange={(e) => setEnableGrid(e.target.checked)}
431
+ className="mr-2"
432
+ />
433
+ <label htmlFor="enableGrid" className="text-sm">Enable Grid</label>
434
+ </div>
435
+ {enableGrid && (
436
+ <div>
437
+ <label className="block text-sm font-medium mb-1">Grid Size</label>
438
+ <input
439
+ type="range"
440
+ min="10"
441
+ max="50"
442
+ value={gridSize}
443
+ onChange={(e) => setGridSize(parseInt(e.target.value))}
444
+ className="w-full"
445
+ />
446
+ <div className="text-xs text-gray-500">{gridSize}px</div>
447
+ </div>
448
+ )}
449
+ </div>
450
+ </div>
451
+ </div>
452
+
453
+ {/* Main Content */}
454
+ <div className="flex-1 flex flex-col overflow-hidden">
455
+ {/* Toolbar */}
456
+ {selectedElement && (
457
+ <div className="bg-white border-b p-3">
458
+ <div className="flex items-center justify-between">
459
+ <div className="flex items-center space-x-4">
460
+ {selectedElement.type === 'text' && (
461
+ <>
462
+ <div className="relative">
463
+ <select
464
+ value={selectedElement.fontFamily}
465
+ onChange={(e) => handleStyleChange('fontFamily', e.target.value)}
466
+ className="appearance-none bg-gray-100 border border-gray-300 rounded-md px-3 py-1 pr-8 text-sm focus:outline-none"
467
+ >
468
+ {fonts.map(font => (
469
+ <option key={font} value={font} style={{ fontFamily: font }}>
470
+ {font}
471
+ </option>
472
+ ))}
473
+ </select>
474
+ <div className="absolute inset-y-0 right-0 flex items-center pr-2 pointer-events-none">
475
+ <i className="fas fa-chevron-down text-xs"></i>
476
+ </div>
477
+ </div>
478
+
479
+ <input
480
+ type="color"
481
+ value={selectedElement.color}
482
+ onChange={(e) => handleStyleChange('color', e.target.value)}
483
+ className="w-8 h-8 cursor-pointer"
484
+ />
485
+
486
+ <div className="flex items-center space-x-2">
487
+ <button
488
+ onClick={() => handleStyleChange('fontWeight', selectedElement.fontWeight === 'bold' ? 'normal' : 'bold')}
489
+ className={`p-1 rounded ${selectedElement.fontWeight === 'bold' ? 'bg-blue-100 text-blue-600' : 'text-gray-600'}`}
490
+ >
491
+ <i className="fas fa-bold"></i>
492
+ </button>
493
+ <button
494
+ onClick={() => handleStyleChange('fontStyle', selectedElement.fontStyle === 'italic' ? 'normal' : 'italic')}
495
+ className={`p-1 rounded ${selectedElement.fontStyle === 'italic' ? 'bg-blue-100 text-blue-600' : 'text-gray-600'}`}
496
+ >
497
+ <i className="fas fa-italic"></i>
498
+ </button>
499
+ <button
500
+ onClick={() => handleStyleChange('textDecoration', selectedElement.textDecoration === 'underline' ? 'none' : 'underline')}
501
+ className={`p-1 rounded ${selectedElement.textDecoration === 'underline' ? 'bg-blue-100 text-blue-600' : 'text-gray-600'}`}
502
+ >
503
+ <i className="fas fa-underline"></i>
504
+ </button>
505
+ </div>
506
+ </>
507
+ )}
508
+
509
+ <div className="flex items-center space-x-2">
510
+ <label className="text-sm">Size:</label>
511
+ <input
512
+ type="range"
513
+ min="8"
514
+ max="72"
515
+ value={selectedElement.type === 'text' ? selectedElement.fontSize : selectedElement.width}
516
+ onChange={(e) => handleStyleChange(
517
+ selectedElement.type === 'text' ? 'fontSize' : 'width',
518
+ parseInt(e.target.value)
519
+ )}
520
+ className="w-24"
521
+ />
522
+ </div>
523
+
524
+ <div className="flex items-center space-x-2">
525
+ <label className="text-sm">Rotate:</label>
526
+ <input
527
+ type="range"
528
+ min="0"
529
+ max="360"
530
+ value={selectedElement.rotation || 0}
531
+ onChange={(e) => handleRotate(selectedElement.id, e)}
532
+ className="w-24"
533
+ />
534
+ </div>
535
+ </div>
536
+
537
+ <button
538
+ onClick={deleteSelectedElement}
539
+ className="p-2 text-red-500 hover:text-red-700"
540
+ >
541
+ <i className="fas fa-trash"></i>
542
+ </button>
543
+ </div>
544
+ </div>
545
+ )}
546
+
547
+ {/* Canvas */}
548
+ <div className="flex-1 overflow-auto p-8 flex items-center justify-center">
549
+ <div
550
+ ref={canvasRef}
551
+ className="canvas-container bg-white shadow-lg relative"
552
+ style={{
553
+ width: `${canvasSize.width}px`,
554
+ height: `${canvasSize.height}px`,
555
+ position: 'relative'
556
+ }}
557
+ onClick={handleCanvasClick}
558
+ >
559
+ {elements.map(element => (
560
+ <Draggable
561
+ key={element.id}
562
+ position={{ x: element.x, y: element.y }}
563
+ onStop={(e, data) => handleDragStop(element.id, e, data)}
564
+ bounds="parent"
565
+ >
566
+ <div
567
+ className={`absolute ${element.id === selectedElementId ? 'selected' : ''}`}
568
+ style={{
569
+ transform: `rotate(${element.rotation || 0}deg)`,
570
+ cursor: 'move',
571
+ width: `${element.width}px`,
572
+ minWidth: '20px',
573
+ minHeight: '20px'
574
+ }}
575
+ onClick={(e) => handleElementClick(element.id, e)}
576
+ >
577
+ {element.type === 'text' ? (
578
+ <div
579
+ contentEditable
580
+ suppressContentEditableWarning
581
+ onBlur={(e) => handleTextChange(element.id, e.target.textContent)}
582
+ onDoubleClick={(e) => e.stopPropagation()}
583
+ style={{
584
+ fontFamily: element.fontFamily,
585
+ fontSize: `${element.fontSize}px`,
586
+ color: element.color,
587
+ fontWeight: element.fontWeight,
588
+ fontStyle: element.fontStyle,
589
+ textDecoration: element.textDecoration,
590
+ width: '100%',
591
+ outline: 'none'
592
+ }}
593
+ >
594
+ {element.content}
595
+ </div>
596
+ ) : (
597
+ <img
598
+ src={element.src}
599
+ alt=""
600
+ style={{
601
+ width: '100%',
602
+ height: element.height ? `${element.height}px` : 'auto',
603
+ objectFit: 'contain'
604
+ }}
605
+ />
606
+ )}
607
+
608
+ {element.id === selectedElementId && (
609
+ <>
610
+ <div className="element-rotate-handle">
611
+ <i className="fas fa-sync-alt"></i>
612
+ </div>
613
+ <div
614
+ className="element-resize-handle"
615
+ onMouseDown={(e) => {
616
+ e.stopPropagation();
617
+ const startX = e.clientX;
618
+ const startY = e.clientY;
619
+ const startWidth = element.width;
620
+ const startHeight = element.height || element.width;
621
+
622
+ const doResize = (moveEvent) => {
623
+ const newWidth = startWidth + (moveEvent.clientX - startX);
624
+ const newHeight = element.type === 'image' ?
625
+ (startHeight + (moveEvent.clientY - startY)) : null;
626
+
627
+ setElements(elements.map(el =>
628
+ el.id === element.id ? {
629
+ ...el,
630
+ width: newWidth,
631
+ height: newHeight
632
+ } : el
633
+ ));
634
+ };
635
+
636
+ const stopResize = () => {
637
+ document.removeEventListener('mousemove', doResize);
638
+ document.removeEventListener('mouseup', stopResize);
639
+ };
640
+
641
+ document.addEventListener('mousemove', doResize);
642
+ document.addEventListener('mouseup', stopResize);
643
+ }}
644
+ ></div>
645
+ </>
646
+ )}
647
+ </div>
648
+ </Draggable>
649
+ ))}
650
+
651
+ {enableGrid && (
652
+ <div className="absolute inset-0 pointer-events-none" style={{
653
+ backgroundImage: `linear-gradient(to right, rgba(0,0,0,0.1) 1px, transparent 1px),
654
+ linear-gradient(to bottom, rgba(0,0,0,0.1) 1px, transparent 1px)`,
655
+ backgroundSize: `${gridSize}px ${gridSize}px`
656
+ }}></div>
657
+ )}
658
+ </div>
659
+ </div>
660
+ </div>
661
+ </div>
662
+ </div>
663
+ );
664
+ };
665
+
666
+ const root = ReactDOM.createRoot(document.getElementById('root'));
667
+ root.render(<CanvasStudio />);
668
+ </script>
669
+ <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=jasvir-singh1021/canvas-studio" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
670
+ </html>