-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
376 lines (339 loc) · 12.2 KB
/
index.html
File metadata and controls
376 lines (339 loc) · 12.2 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML Package Bundle</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
line-height: 1.6;
color: #333;
}
h1 {
color: #2c3e50;
border-bottom: 2px solid #eee;
padding-bottom: 10px;
}
h2 {
color: #2c3e50;
margin-top: 0;
}
.app {
margin-bottom: 40px;
padding: 20px;
border: 1px solid #eee;
border-radius: 8px;
background: #f9f9f9;
}
.counter {
display: flex;
align-items: center;
gap: 10px;
margin-top: 20px;
}
.count {
font-size: 24px;
font-weight: bold;
min-width: 50px;
text-align: center;
}
.button {
background-color: #4285f4;
color: white;
border: none;
padding: 8px 16px;
border-radius: 4px;
font-size: 14px;
cursor: pointer;
margin-right: 8px;
}
.button:hover {
background-color: #3b78e7;
}
.file-list {
list-style-type: none;
padding: 0;
margin: 0;
}
.file-list li {
padding: 8px 0;
border-bottom: 1px solid #f0f0f0;
cursor: pointer;
}
.file-name {
font-weight: bold;
color: #2c3e50;
}
.file-info {
color: #666;
font-size: 0.9em;
}
/* Utility Classes */
.hidden {
display: none;
}
/* DevTools panel (hidden by default) */
#devtools-panel {
position: fixed;
bottom: 0;
right: 0;
width: 40px;
height: 40px;
background-color: rgba(0, 0, 0, 0.7);
color: white;
border-radius: 8px 0 0 0;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
z-index: 1000;
transition: all 0.3s ease;
}
#devtools-panel.expanded {
width: 100%;
height: 60%;
border-radius: 0;
background-color: #2c3e50;
padding: 20px;
box-sizing: border-box;
overflow: auto;
}
#devtools-content {
display: none;
width: 100%;
height: 100%;
}
#devtools-panel.expanded #devtools-content {
display: block;
}
#devtools-panel.expanded #devtools-toggle {
position: absolute;
top: 10px;
right: 10px;
}
</style>
</head>
<body>
<!-- Core application that works in all environments -->
<div class="app" id="app">
<h1>HTML Package Bundle</h1>
<p>A self-contained application with bundled source files</p>
<div id="app-content">
<!-- Application content will be rendered here -->
<div class="counter">
<button id="counter-decrement" class="button">-</button>
<div class="count" id="counter-value">0</div>
<button id="counter-increment" class="button">+</button>
</div>
</div>
<div id="environment-status"></div>
</div>
<!-- DevTools Panel (initially hidden/collapsed) -->
<div id="devtools-panel">
<div id="devtools-toggle">⚙️</div>
<div id="devtools-content" class="hidden">
<h2>Development Tools</h2>
<p>These tools are for editing and modifying the application.</p>
<div id="devtools-tabs">
<button id="tab-files" class="button">Files</button>
<button id="tab-edit" class="button">Editor</button>
<button id="tab-environment" class="button">Environment</button>
<button id="tab-webcontainer" class="button">WebContainer</button>
</div>
<div id="devtools-panels">
<!-- Files Panel -->
<div id="panel-files" class="devtools-panel">
<h3>Source Files</h3>
<div id="source-bundle">
<p>Source files will be listed here.</p>
</div>
<button id="save-to-disk" class="button">Save to Disk</button>
<button id="add-file" class="button">Add File</button>
<button id="export-bundle" class="button">Export Bundle</button>
<div id="save-status"></div>
</div>
<!-- Editor Panel -->
<div id="panel-edit" class="devtools-panel hidden">
<h3>File Editor</h3>
<div id="editor-container">
<p>Select a file to edit</p>
</div>
</div>
<!-- Environment Panel -->
<div id="panel-environment" class="devtools-panel hidden">
<h3>Environment Details</h3>
<div id="environment-info">
<p>Environment information will be displayed here.</p>
</div>
<div id="file-operations">
<p>File operation status will appear here.</p>
</div>
</div>
<!-- WebContainer Panel -->
<div id="panel-webcontainer" class="devtools-panel hidden">
<h3>WebContainer Dev Environment</h3>
<p>Run a full development environment in your browser.</p>
<div id="webcontainer-controls">
<button id="startWebContainerBtn" class="button">Start Dev Environment</button>
<button id="installDepsBtn" class="button" disabled>Install Dependencies</button>
<button id="startServerBtn" class="button" disabled>Start Server</button>
<button id="runCommandBtn" class="button" disabled>Run Command</button>
<button id="buildProjectBtn" class="button" disabled>Build & Update Runtime</button>
</div>
<div id="webcontainer-status">
<p>WebContainer not started.</p>
</div>
<div id="terminal-container" class="hidden">
<h4>Terminal</h4>
<pre id="terminal"></pre>
</div>
<div id="preview-container" class="hidden">
<h4>Preview</h4>
<div class="preview-controls">
<span id="preview-url"></span>
<button id="refreshPreviewBtn" class="button">Refresh</button>
<button id="openPreviewBtn" class="button">Open in New Tab</button>
</div>
<iframe id="preview-frame"></iframe>
</div>
</div>
</div>
</div>
</div>
<!-- This element will contain the bundled source files as JSON -->
<script id="source-bundle-data" type="application/json" style="display:none"></script>
<!-- Core Application Script (minimal functionality, works in all environments) -->
<script>
// Core application functionality - minimal functionality that works everywhere
document.addEventListener('DOMContentLoaded', function() {
// Detect environment
const protocol = window.location.protocol;
const isFileProtocol = protocol === 'file:';
const isLocalhost = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';
const isHTTPS = protocol === 'https:';
const isSecureContext = isHTTPS || isLocalhost;
// Display environment status
const envStatus = document.getElementById('environment-status');
if (envStatus) {
envStatus.innerHTML = `
<p><strong>Running in:</strong> ${isFileProtocol ? 'File Protocol' : isLocalhost ? 'Localhost' : 'Web Server'}</p>
<p><small>Click the gear icon ⚙️ in the bottom-right corner to access developer tools.</small></p>
`;
}
// Initialize counter
let count = 0;
const countElement = document.getElementById('counter-value');
document.getElementById('counter-decrement').addEventListener('click', function() {
count--;
countElement.textContent = count;
});
document.getElementById('counter-increment').addEventListener('click', function() {
count++;
countElement.textContent = count;
});
// Setup DevTools toggle
const devtoolsPanel = document.getElementById('devtools-panel');
const devtoolsToggle = document.getElementById('devtools-toggle');
const devtoolsContent = document.getElementById('devtools-content');
if (devtoolsToggle && devtoolsPanel) {
devtoolsToggle.addEventListener('click', function() {
if (devtoolsPanel.classList.contains('expanded')) {
devtoolsPanel.classList.remove('expanded');
devtoolsContent.classList.add('hidden');
} else {
devtoolsPanel.classList.add('expanded');
devtoolsContent.classList.remove('hidden');
}
});
}
// Handle basic file save/download functionality
const saveToDiskBtn = document.getElementById('save-to-disk');
const saveStatus = document.getElementById('save-status');
if (saveToDiskBtn && saveStatus) {
saveToDiskBtn.addEventListener('click', function() {
try {
// Create a complete HTML file
const htmlContent = document.documentElement.outerHTML;
// Create a blob with the HTML content
const blob = new Blob([htmlContent], { type: 'text/html' });
const url = URL.createObjectURL(blob);
// Create a temporary link element to trigger the download
const a = document.createElement('a');
a.href = url;
a.download = 'html-package-bundle.html';
document.body.appendChild(a);
a.click();
// Clean up
setTimeout(() => {
document.body.removeChild(a);
URL.revokeObjectURL(url);
saveStatus.textContent = 'Saved successfully!';
saveStatus.style.color = '#0d652d';
setTimeout(() => {
saveStatus.textContent = '';
}, 3000);
}, 100);
} catch (error) {
console.error('Error saving file:', error);
saveStatus.textContent = 'Error saving file';
saveStatus.style.color = '#5f2120';
}
});
}
// Setup DevTools tabs
const tabs = document.querySelectorAll('#devtools-tabs button');
const panels = document.querySelectorAll('.devtools-panel');
tabs.forEach(tab => {
tab.addEventListener('click', function() {
// Get the target panel ID
const targetId = this.id.replace('tab-', 'panel-');
// Hide all panels
panels.forEach(panel => {
panel.classList.add('hidden');
});
// Show the target panel
document.getElementById(targetId).classList.remove('hidden');
// Update active tab
tabs.forEach(t => t.classList.remove('active'));
this.classList.add('active');
});
});
// Initialize the source bundle display
const bundleData = document.getElementById('source-bundle-data');
if (bundleData && bundleData.textContent) {
try {
const bundle = JSON.parse(bundleData.textContent);
// Update source bundle section
const sourceBundleElement = document.getElementById('source-bundle');
if (sourceBundleElement && bundle.files) {
let html = `
<p><strong>${bundle.files.length} files</strong> in bundle.</p>
<ul class="file-list">
`;
// Sort files by path
const sortedFiles = [...bundle.files].sort((a, b) => a.path.localeCompare(b.path));
for (const file of sortedFiles) {
html += `
<li data-path="${file.path}">
<span class="file-name">${file.path}</span>
<span class="file-info">(${new Date(file.lastModified).toLocaleString()})</span>
</li>
`;
}
html += '</ul>';
sourceBundleElement.innerHTML = html;
}
} catch (error) {
console.error('Failed to parse bundle data:', error);
}
}
});
</script>
<!-- Module script for server environments (loads development tools) -->
<script type="module" src="/src/main.ts"></script>
</body>
</html>