-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
50 lines (46 loc) · 1.67 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Canvas Drag & Drop Interface</title>
<link rel="stylesheet" href="src/styles/canvas.css">
</head>
<body>
<div id="menuBar" class="menu-bar"></div>
<div class="canvas-container">
<canvas id="canvas"></canvas>
</div>
<script type="module">
import { CanvasManager } from './src/js/canvas-manager.js';
import { MenuManager } from './src/js/menu.js';
const canvas = document.getElementById('canvas');
const menuBar = document.getElementById('menuBar');
const canvasManager = new CanvasManager(canvas);
const menuManager = new MenuManager(menuBar);
canvas.addEventListener('dragover', (e) => {
e.preventDefault();
});
canvas.addEventListener('drop', (e) => {
e.preventDefault();
const rect = canvas.getBoundingClientRect();
const x = (e.clientX - rect.left - canvasManager.pan.x) / canvasManager.zoom;
const y = (e.clientY - rect.top - canvasManager.pan.y) / canvasManager.zoom;
try {
const item = JSON.parse(e.dataTransfer.getData('text/plain'));
canvasManager.addShape(
'rectangle',
x - 40,
y - 20,
80,
40,
item.color,
item.label
);
} catch (error) {
console.error('Error dropping shape:', error);
}
});
</script>
</body>
</html>