-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
105 lines (88 loc) · 3.08 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./UI/style.css"></link>
<style>
canvas {
display: block;
}
.ui-overlay {
position: absolute;
z-index: 999;
user-select: none;
}
.selectable {
user-select: all;
}
</style>
</head>
<body>
<div class="ui-overlay">
</div>
<script>
async function appendUIContent() {
try {
// Fetch the ui.html file
const response = await fetch('./UI/ui.html');
if (!response.ok) {
throw new Error('Failed to fetch UI content');
}
// Get the HTML content from the response
const htmlContent = await response.text();
// Append the HTML content to the .ui-overlay div
const uiOverlay = document.querySelector('.ui-overlay');
uiOverlay.innerHTML = htmlContent;
} catch (error) {
console.error(error);
}
}
appendUIContent();
function fetchImportMap(url) {
return fetch(url)
.then(response => {
if (!response.ok) {
throw new Error('Failed to fetch import map');
}
return response.json();
});
}
// Function to append import map to the document
function appendImportMap(importMap) {
const script = document.createElement('script');
script.type = 'importmap';
script.textContent = JSON.stringify(importMap);
document.head.appendChild(script);
// Now that the import map is applied, start loading modules
loadModules();
}
// Function to load modules
async function loadModules() {
try {
const { Engine } = await import('./engine.js');
const { Program } = await import('./program.js');
// Once modules are imported, continue with program initialization
const program = new Program();
document.title = program.applicationName;
program.engine = new Engine();
program.engine.program = program;
program.engine.start();
program.start();
} catch (error) {
console.error('Failed to import modules:', error);
}
}
// URL of the JSON file containing the import map
const importMapUrl = './imports.json'; // Replace with the actual URL
// Fetch and append the import map
fetchImportMap(importMapUrl)
.then(importMap => {
appendImportMap(importMap);
})
.catch(error => {
console.error('Failed to fetch or append import map:', error);
});
</script>
</body>
</html>