vfsjs-test 1.0.21 → 1.0.22
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.
- package/main.js +36 -24
- package/package.json +1 -1
- package/vfsjs.js +21 -21
package/main.js
CHANGED
|
@@ -1,29 +1,41 @@
|
|
|
1
|
-
//
|
|
1
|
+
// main.js - Production Asset Orchestrator
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
window.vfs = {
|
|
4
|
+
add(filename, contentString, customMime = null) {
|
|
5
|
+
return window._vfsKernel.write(filename, contentString, customMime);
|
|
6
|
+
},
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
async importRemote(localFilename, remoteUrl, customMime = null) {
|
|
9
|
+
try {
|
|
10
|
+
const response = await fetch(remoteUrl);
|
|
11
|
+
if (!response.ok) throw new Error(`HTTP network error: ${response.status}`);
|
|
12
|
+
const text = await response.text();
|
|
13
|
+
this.add(localFilename, text, customMime);
|
|
14
|
+
return true;
|
|
15
|
+
} catch (err) {
|
|
16
|
+
console.error(`[VFS Proxy Error] Failed loading remote path:`, err);
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
async function buildProductionApplication() {
|
|
23
|
+
// 1. Map assets into the active Service Worker cache storage map first
|
|
24
|
+
vfs.add('app.js', `console.log("App running cleanly inside VFS!");`, 'text/javascript');
|
|
25
|
+
vfs.add('style.css', `body { background: #020617; color: #38bdf8; font-family: monospace; padding: 20px; }`, 'text/css');
|
|
11
26
|
|
|
12
|
-
//
|
|
13
|
-
|
|
27
|
+
// 2. Fetch remote modules
|
|
28
|
+
await vfs.importRemote('my-confetti-engine.js', 'https://cdn.jsdelivr.net/npm/canvas-confetti@1.9.4/dist/confetti.browser.min.js', 'text/javascript');
|
|
29
|
+
|
|
30
|
+
// 3. CRITICAL: Everything is safely in memory. Signal the kernel to open the iframe viewport!
|
|
31
|
+
window._vfsKernel.openViewport();
|
|
14
32
|
}
|
|
15
33
|
|
|
16
|
-
//
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (isReady) {
|
|
25
|
-
startDeveloperWorkspace();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}, 10);
|
|
29
|
-
});
|
|
34
|
+
// Polling initialization hook to bridge cleanly across asynchronous script loads
|
|
35
|
+
(function verifyKernelAvailability() {
|
|
36
|
+
if (window._vfsKernel && navigator.serviceWorker.controller) {
|
|
37
|
+
buildProductionApplication();
|
|
38
|
+
} else {
|
|
39
|
+
setTimeout(verifyKernelAvailability, 10);
|
|
40
|
+
}
|
|
41
|
+
})();
|
package/package.json
CHANGED
package/vfsjs.js
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
// vfsjs.js - Version
|
|
1
|
+
// vfsjs.js - Version 5.0.0 (Production Synchronization Engine)
|
|
2
2
|
(function() {
|
|
3
3
|
const encoder = new TextEncoder();
|
|
4
4
|
|
|
5
5
|
const engineCore = {
|
|
6
6
|
async init() {
|
|
7
7
|
try {
|
|
8
|
-
// 1.
|
|
8
|
+
// 1. Boot the Service Worker thread
|
|
9
9
|
await navigator.serviceWorker.register('./sw.js');
|
|
10
10
|
if (!navigator.serviceWorker.controller) {
|
|
11
11
|
await new Promise(r => navigator.serviceWorker.addEventListener('controllerchange', r, { once: true }));
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
// 2. Capture
|
|
14
|
+
// 2. Capture raw HTML layout
|
|
15
15
|
const developerRawHtml = `<!DOCTYPE html>\n<html>${document.documentElement.innerHTML}</html>`;
|
|
16
16
|
this.write('index.html', developerRawHtml, 'text/html');
|
|
17
17
|
|
|
18
|
-
// 3.
|
|
18
|
+
// 3. Clear window layout & lock sizing boundaries
|
|
19
19
|
document.documentElement.innerHTML = '';
|
|
20
20
|
Object.assign(document.documentElement.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0' });
|
|
21
21
|
Object.assign(document.body.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0', background: '#020617' });
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
// 4. Create the iframe canvas, but leave it blank (src="") so it doesn't request files yet!
|
|
24
|
+
const iframe = document.createElement('iframe');
|
|
25
|
+
iframe.id = 'canvas-viewport';
|
|
26
|
+
Object.assign(iframe.style, {
|
|
27
|
+
position: 'absolute', top: '0', left: '0', width: '100%', height: '100%',
|
|
28
|
+
border: 'none', margin: '0', padding: '0', zIndex: '999999'
|
|
29
|
+
});
|
|
30
|
+
document.body.appendChild(iframe);
|
|
31
|
+
|
|
24
32
|
return true;
|
|
25
33
|
} catch (err) {
|
|
26
|
-
console.error("VFS
|
|
34
|
+
console.error("VFS Kernel Initialization Fault:", err);
|
|
27
35
|
return false;
|
|
28
36
|
}
|
|
29
37
|
},
|
|
30
38
|
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
Object.assign(iframe.style, {
|
|
39
|
-
position: 'absolute', top: '0', left: '0', width: '100%', height: '100%',
|
|
40
|
-
border: 'none', margin: '0', padding: '0', zIndex: '999999'
|
|
41
|
-
});
|
|
42
|
-
document.body.appendChild(iframe);
|
|
43
|
-
|
|
44
|
-
// Point to the virtual root route safely now that assets are loaded
|
|
45
|
-
iframe.src = './?vfs=true';
|
|
39
|
+
// Called exclusively by main.js once all local/remote files are committed to memory
|
|
40
|
+
openViewport() {
|
|
41
|
+
const iframe = document.getElementById('canvas-viewport');
|
|
42
|
+
if (iframe) {
|
|
43
|
+
console.log("[VFS Kernel] Memory mapping complete. Opening virtual system pipeline.");
|
|
44
|
+
iframe.src = './?vfs=true';
|
|
45
|
+
}
|
|
46
46
|
},
|
|
47
47
|
|
|
48
48
|
write(filename, contentString, customMime) {
|