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.
Files changed (3) hide show
  1. package/main.js +51 -47
  2. package/package.json +1 -1
  3. package/vfsjs.js +25 -24
package/main.js CHANGED
@@ -1,57 +1,61 @@
1
1
  // main.js - Production Build Core Orchestrator
2
2
 
3
- // SECURITY SHIELD: Do not execute orchestrations inside the iframe viewport container
4
- if (window.self !== window.top) {
5
- // Hide the uncompiled natively authored markup inside the frame until VFS style loads
6
- document.addEventListener('DOMContentLoaded', () => {
7
- document.documentElement.style.visibility = 'hidden';
8
- });
9
- } else {
10
- window.vfs = {
11
- add(filename, contentString, customMime = null) {
12
- return window._vfsKernel.write(filename, contentString, customMime);
13
- },
14
- async importRemote(localFilename, remoteUrl, customMime = null) {
15
- try {
16
- const response = await fetch(remoteUrl);
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
- async function runProductionBuild() {
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
- setInterval(() => {
34
- window.confetti({ particleCount: 50, spread: 60 });
35
- }, 2500);
33
+ window.confetti({ particleCount: 80, spread: 70 });
36
34
  }
37
- `, 'text/javascript');
35
+ });
36
+ `, 'text/javascript');
38
37
 
39
- vfs.add('style.css', `
40
- html, body { background: #020617 !important; color: #f8fafc !important; font-family: monospace !important; visibility: visible !important; }
41
- body { text-align: center; padding: 50px; }
42
- h2 { color: #38bdf8; }
43
- `, 'text/css');
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
- await vfs.importRemote('my-confetti-engine.js', 'https://cdn.jsdelivr.net/npm/canvas-confetti@1.9.4/dist/confetti.browser.min.js', 'text/javascript');
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
- window._vfsKernel.openViewport();
48
- }
50
+ // Signal the kernel to open up the viewport
51
+ window._vfsKernel.openViewport();
52
+ }
49
53
 
50
- (function verifyKernelAvailability() {
51
- if (window._vfsKernel && navigator.serviceWorker && navigator.serviceWorker.controller) {
52
- runProductionBuild();
53
- } else {
54
- setTimeout(verifyKernelAvailability, 15);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vfsjs-test",
3
- "version": "1.0.25",
3
+ "version": "1.0.26",
4
4
  "description": "",
5
5
  "main": "index.html",
6
6
  "scripts": {
package/vfsjs.js CHANGED
@@ -1,56 +1,56 @@
1
- // vfsjs.js - Version 8.0.0 (Anti-Recursion Production Engine)
1
+ // vfsjs.js - Version 10.0.0 (Automated Runtime Clean-Shell Engine)
2
2
  (function() {
3
- // SECURITY SHIELD: If this is running inside the iframe, KILL EXECUTION IMMEDIATELY.
4
- if (window.self !== window.top) {
5
- return;
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
- // Reassuring Console Explanation Message
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
- const rawHtml = document.documentElement.innerHTML;
25
- this.write('index.html', `<!DOCTYPE html>\n<html>${rawHtml}</html>`, 'text/html');
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 Kernel Boot Fault:", err);
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] Deploying canvas sandboxed frame wrapper.");
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 {