vfsjs-test 1.0.25 → 1.0.26
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 +51 -47
- package/package.json +1 -1
- package/vfsjs.js +25 -24
package/main.js
CHANGED
|
@@ -1,57 +1,61 @@
|
|
|
1
1
|
// main.js - Production Build Core Orchestrator
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (!response.ok) throw new Error(`HTTP network error: ${response.status}`);
|
|
18
|
-
const text = await response.text();
|
|
19
|
-
this.add(localFilename, text, customMime);
|
|
20
|
-
return true;
|
|
21
|
-
} catch (err) {
|
|
22
|
-
console.error(`[VFS Proxy Error]`, err);
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
3
|
+
window.vfs = {
|
|
4
|
+
add(filename, contentString, customMime = null) {
|
|
5
|
+
return window._vfsKernel.write(filename, contentString, customMime);
|
|
6
|
+
},
|
|
7
|
+
async importRemote(localFilename, remoteUrl, customMime = null) {
|
|
8
|
+
try {
|
|
9
|
+
const response = await fetch(remoteUrl);
|
|
10
|
+
if (!response.ok) throw new Error(`HTTP network error: ${response.status}`);
|
|
11
|
+
const text = await response.text();
|
|
12
|
+
this.add(localFilename, text, customMime);
|
|
13
|
+
return true;
|
|
14
|
+
} catch (err) {
|
|
15
|
+
console.error(`[VFS Proxy Error]`, err);
|
|
16
|
+
return false;
|
|
25
17
|
}
|
|
26
|
-
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
async function runProductionBuild() {
|
|
22
|
+
// Seed your custom app.js code string directly into memory
|
|
23
|
+
vfs.add('app.js', `
|
|
24
|
+
console.log("Application loop booted inside clean VFS space!");
|
|
25
|
+
|
|
26
|
+
const container = document.createElement('div');
|
|
27
|
+
container.className = 'js-card';
|
|
28
|
+
container.innerHTML = '<h3>Automated Clean Shell Live</h3><p>The parent DOM was wiped. This environment is 100% isolated.</p><button id="action-btn">Trigger Confetti</button>';
|
|
29
|
+
document.body.appendChild(container);
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
// Seed files exactly ONCE
|
|
30
|
-
vfs.add('app.js', `
|
|
31
|
-
console.log("Application loop booted inside clean VFS space!");
|
|
31
|
+
document.getElementById('action-btn').addEventListener('click', () => {
|
|
32
32
|
if (typeof window.confetti === 'function') {
|
|
33
|
-
|
|
34
|
-
window.confetti({ particleCount: 50, spread: 60 });
|
|
35
|
-
}, 2500);
|
|
33
|
+
window.confetti({ particleCount: 80, spread: 70 });
|
|
36
34
|
}
|
|
37
|
-
|
|
35
|
+
});
|
|
36
|
+
`, 'text/javascript');
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
// Seed your custom style.css string directly into memory
|
|
39
|
+
vfs.add('style.css', `
|
|
40
|
+
body { background: #020617; color: #f8fafc; font-family: system-ui, sans-serif; text-align: center; padding: 50px; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 80vh; margin: 0; }
|
|
41
|
+
h1 { color: #38bdf8; }
|
|
42
|
+
.js-card { background: #0f172a; border: 1px solid #1e293b; padding: 25px; border-radius: 12px; max-width: 400px; margin-top: 30px; }
|
|
43
|
+
.js-card h3 { color: #34d399; margin-top: 0; }
|
|
44
|
+
button { background: #38bdf8; color: #020617; border: none; padding: 10px 20px; font-weight: 600; border-radius: 6px; cursor: pointer; margin-top: 10px; }
|
|
45
|
+
`, 'text/css');
|
|
44
46
|
|
|
45
|
-
|
|
47
|
+
// Load any third-party script assets natively
|
|
48
|
+
await vfs.importRemote('my-confetti-engine.js', 'https://cdn.jsdelivr.net/npm/canvas-confetti@1.9.4/dist/confetti.browser.min.js', 'text/javascript');
|
|
46
49
|
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
// Signal the kernel to open up the viewport
|
|
51
|
+
window._vfsKernel.openViewport();
|
|
52
|
+
}
|
|
49
53
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
}
|
|
54
|
+
// Verification pooling check
|
|
55
|
+
(function verifyKernelAvailability() {
|
|
56
|
+
if (window._vfsKernel && navigator.serviceWorker && navigator.serviceWorker.controller) {
|
|
57
|
+
runProductionBuild();
|
|
58
|
+
} else {
|
|
59
|
+
setTimeout(verifyKernelAvailability, 15);
|
|
60
|
+
}
|
|
61
|
+
})();
|
package/package.json
CHANGED
package/vfsjs.js
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
// vfsjs.js - Version
|
|
1
|
+
// vfsjs.js - Version 10.0.0 (Automated Runtime Clean-Shell Engine)
|
|
2
2
|
(function() {
|
|
3
|
-
// SECURITY SHIELD: If
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
3
|
+
// SECURITY SHIELD: If we are inside the iframe, do absolutely nothing.
|
|
4
|
+
// The iframe will read the pristine virtual files from the Service Worker.
|
|
5
|
+
if (window.self !== window.top) return;
|
|
7
6
|
|
|
8
7
|
const encoder = new TextEncoder();
|
|
9
8
|
|
|
10
9
|
const engineCore = {
|
|
11
10
|
async init() {
|
|
12
|
-
|
|
13
|
-
console.log(
|
|
14
|
-
"%c[VFS Kernel] NOTICE: Any 'MIME type text/plain' or 'NS_ERROR_CORRUPTED_CONTENT' errors appearing above this line are completely normal Phase-1 browser artifacts. The VFS engine gracefully abandons those uninstalled network requests and handles them safely in memory.",
|
|
15
|
-
"color: #38bdf8; font-weight: bold; background: #0f172a; padding: 4px 8px; border-radius: 4px;"
|
|
16
|
-
);
|
|
11
|
+
console.log("%c[VFS Kernel] Automated Clean-Shell Engine Initializing...", "color: #38bdf8; font-weight: bold;");
|
|
17
12
|
|
|
18
13
|
try {
|
|
14
|
+
// 1. Boot up the Service Worker interceptor
|
|
19
15
|
await navigator.serviceWorker.register('./sw.js');
|
|
20
16
|
if (!navigator.serviceWorker.controller) {
|
|
21
17
|
await new Promise(r => navigator.serviceWorker.addEventListener('controllerchange', r, { once: true }));
|
|
22
18
|
}
|
|
23
19
|
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
// 2. Capture the pristine physical HTML right now
|
|
21
|
+
const nativeMarkup = `<!DOCTYPE html>\n<html>${document.documentElement.innerHTML}</html>`;
|
|
22
|
+
|
|
23
|
+
// 3. AUTOMATED CLEAN SHELL: Wipe the parent DOM instantly!
|
|
24
|
+
// This kills all pending network requests for style.css or app.js in the parent.
|
|
25
|
+
document.documentElement.innerHTML = '<head><meta charset="UTF-8"><title>VFS Runtime Canvas</title></head><body></body>';
|
|
26
|
+
|
|
27
|
+
// 4. Set up pristine parent layout styling
|
|
28
|
+
Object.assign(document.documentElement.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0' });
|
|
29
|
+
Object.assign(document.body.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0', background: '#020617' });
|
|
30
|
+
|
|
31
|
+
// 5. Commit the native code markup safely to the virtual memory file system
|
|
32
|
+
this.write('index.html', nativeMarkup, 'text/html');
|
|
26
33
|
|
|
27
|
-
console.log("[VFS Kernel] Core initialized. Communication channel open.");
|
|
28
34
|
return true;
|
|
29
35
|
} catch (err) {
|
|
30
|
-
console.error("VFS
|
|
36
|
+
console.error("VFS Critical Runtime Separation Fault:", err);
|
|
31
37
|
return false;
|
|
32
38
|
}
|
|
33
39
|
},
|
|
34
40
|
|
|
41
|
+
// Triggered by main.js once custom script/style overrides are committed
|
|
35
42
|
openViewport() {
|
|
36
|
-
console.log("[VFS Kernel]
|
|
43
|
+
console.log("[VFS Kernel] Opening sandboxed runtime viewport frame.");
|
|
37
44
|
|
|
38
|
-
// FLASH FIX: Give the main body a dark background instantly so there is no bright/unstyled flash
|
|
39
|
-
document.documentElement.style.background = '#020617';
|
|
40
|
-
document.body.style.background = '#020617';
|
|
41
|
-
document.body.style.margin = '0';
|
|
42
|
-
document.body.style.padding = '0';
|
|
43
|
-
document.body.style.overflow = 'hidden';
|
|
44
|
-
|
|
45
45
|
const iframe = document.createElement('iframe');
|
|
46
46
|
iframe.id = 'canvas-viewport';
|
|
47
47
|
Object.assign(iframe.style, {
|
|
48
48
|
position: 'fixed', top: '0', left: '0', width: '100%', height: '100%',
|
|
49
|
-
border: 'none', margin: '0', padding: '0', zIndex: '999999',
|
|
50
|
-
background: '#020617' // Force iframe background dark before content arrives
|
|
49
|
+
border: 'none', margin: '0', padding: '0', zIndex: '999999', background: '#020617'
|
|
51
50
|
});
|
|
52
51
|
document.body.appendChild(iframe);
|
|
53
52
|
|
|
53
|
+
// Launch the iframe into the virtual file system space
|
|
54
54
|
iframe.src = './index.html?vfs=true';
|
|
55
55
|
},
|
|
56
56
|
|
|
@@ -77,6 +77,7 @@
|
|
|
77
77
|
|
|
78
78
|
window._vfsKernel = engineCore;
|
|
79
79
|
|
|
80
|
+
// Run instantly to capture the DOM structure before the browser can parse the body tags
|
|
80
81
|
if (document.readyState === 'loading') {
|
|
81
82
|
document.addEventListener('DOMContentLoaded', () => engineCore.init());
|
|
82
83
|
} else {
|