vfsjs-test 1.0.27 → 1.0.29

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 +36 -52
  2. package/package.json +1 -1
  3. package/vfsjs.js +94 -56
package/main.js CHANGED
@@ -1,78 +1,62 @@
1
1
  // main.js - Production Build Core Orchestrator
2
2
 
3
3
  window.vfs = {
4
- add(filename, contentString, customMime = null) {
5
- return window._vfsKernel.write(filename, contentString, customMime);
4
+ add(filename, contentString) {
5
+ window._vfsKernel.write(filename, contentString);
6
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;
17
- }
7
+ importRemote(remoteUrl) {
8
+ window._vfsKernel.pushRemoteScript(remoteUrl);
18
9
  }
19
10
  };
20
11
 
21
- async function runProductionBuild() {
22
- // Seed app.js with single-execution target handlers
12
+ function runProductionBuild() {
13
+ // Stage third-party framework asset links directly
14
+ vfs.importRemote('https://cdn.jsdelivr.net/npm/canvas-confetti@1.9.4/dist/confetti.browser.min.js');
15
+
16
+ // Register application code logic structures
23
17
  vfs.add('app.js', `
24
- console.log("Application loop booted inside clean VFS space!");
18
+ console.log("Application loop booted inside clean isolated VFS Space!");
25
19
 
26
- // Wait for the pristine iframe DOM structure to land safely
27
- document.addEventListener('DOMContentLoaded', () => {
28
- // Find your native body elements or append a single action block card cleanly
29
- let container = document.querySelector('.js-card');
30
-
31
- if (!container) {
32
- container = document.createElement('div');
33
- container.className = 'js-card';
34
- container.innerHTML = '<h3>Automated Clean Shell Live</h3><p>The parent DOM was wiped. This environment is 100% isolated.</p>';
35
- document.body.appendChild(container);
20
+ const container = document.createElement('div');
21
+ container.className = 'js-card';
22
+ container.innerHTML = '<h3>Pure Handshake Isolation Live</h3><p>Zero Service Worker race conditions. 100% stable execution context.</p>';
23
+ document.body.appendChild(container);
24
+
25
+ const button = document.createElement('button');
26
+ button.id = 'action-btn';
27
+ button.innerText = 'Trigger Confetti';
28
+ container.appendChild(button);
29
+
30
+ button.addEventListener('click', () => {
31
+ if (typeof window.confetti === 'function') {
32
+ window.confetti({ particleCount: 100, spread: 70, origin: { y: 0.6 } });
33
+ console.log("[VFS Runtime] Confetti burst executed smoothly.");
34
+ } else {
35
+ console.error("[VFS Runtime Error] Confetti module reference missing on execution thread.");
36
36
  }
37
-
38
- // Append exactly ONE action trigger button cleanly
39
- const button = document.createElement('button');
40
- button.id = 'action-btn';
41
- button.innerText = 'Trigger Confetti';
42
- container.appendChild(button);
43
-
44
- button.addEventListener('click', () => {
45
- if (typeof window.confetti === 'function') {
46
- window.confetti({ particleCount: 100, spread: 70, origin: { y: 0.6 } });
47
- } else {
48
- console.error("Confetti script framework is loading or missing reference mapping.");
49
- }
50
- });
51
37
  });
52
- `, 'text/javascript');
38
+ `);
53
39
 
40
+ // Register explicit application presentation rules
54
41
  vfs.add('style.css', `
55
42
  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; }
56
43
  h1 { color: #38bdf8; font-size: 2.5rem; }
57
- p { color: #94a3b8; max-width: 500px; line-height: 1.6; }
58
-
59
- .js-card { background: #0f172a; border: 1px solid #1e293b; padding: 25px; border-radius: 12px; max-width: 400px; margin-top: 20px; box-shadow: 0 4px 20px rgba(0,0,0,0.4); }
44
+ p { color: #94a3b8; }
45
+ .js-card { background: #0f172a; border: 1px solid #1e293b; padding: 25px; border-radius: 12px; max-width: 400px; margin-top: 20px; box-shadow: 0 4px 20px rgba(0,0,0,0.5); }
60
46
  .js-card h3 { color: #34d399; margin-top: 0; }
61
-
62
- button { background: #38bdf8; color: #020617; border: none; padding: 12px 24px; font-weight: 600; border-radius: 6px; cursor: pointer; margin-top: 15px; font-size: 14px; transition: background 0.15s ease; }
47
+ button { background: #38bdf8; color: #020617; border: none; padding: 12px 24px; font-weight: 600; border-radius: 6px; cursor: pointer; margin-top: 15px; font-size: 14px; }
63
48
  button:hover { background: #7dd3fc; }
64
- `, 'text/css');
65
-
66
- // Fetch the external engine framework dependencies natively
67
- await vfs.importRemote('my-confetti-engine.js', 'https://cdn.jsdelivr.net/npm/canvas-confetti@1.9.4/dist/confetti.browser.min.js', 'text/javascript');
49
+ `);
68
50
 
51
+ // Deploy the viewport framework
69
52
  window._vfsKernel.openViewport();
70
53
  }
71
54
 
55
+ // Verification block loop execution
72
56
  (function verifyKernelAvailability() {
73
- if (window._vfsKernel && navigator.serviceWorker && navigator.serviceWorker.controller) {
57
+ if (window._vfsKernel) {
74
58
  runProductionBuild();
75
59
  } else {
76
- setTimeout(verifyKernelAvailability, 15);
60
+ setTimeout(verifyKernelAvailability, 10);
77
61
  }
78
62
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vfsjs-test",
3
- "version": "1.0.27",
3
+ "version": "1.0.29",
4
4
  "description": "",
5
5
  "main": "index.html",
6
6
  "scripts": {
package/vfsjs.js CHANGED
@@ -1,47 +1,47 @@
1
- // vfsjs.js - Version 11.0.0 (Pristine Shell Extraction Engine)
1
+ // vfsjs.js - Version 14.0.0 (Pure Handshake Messaging Kernel)
2
2
  (function() {
3
+ // If somehow executed inside a frame, self-destruct immediately
3
4
  if (window.self !== window.top) return;
4
5
 
5
- const encoder = new TextEncoder();
6
+ const vfsMemory = {
7
+ 'index.html': '',
8
+ 'app.js': '',
9
+ 'style.css': '',
10
+ 'remote_scripts': []
11
+ };
6
12
 
7
13
  const engineCore = {
8
- async init() {
9
- console.log("%c[VFS Kernel] Cleaning setup artifacts and isolating scope...", "color: #34d399; font-weight: bold;");
10
-
11
- try {
12
- await navigator.serviceWorker.register('./sw.js');
13
- if (!navigator.serviceWorker.controller) {
14
- await new Promise(r => navigator.serviceWorker.addEventListener('controllerchange', r, { once: true }));
15
- }
14
+ init() {
15
+ console.log("%c[VFS Kernel] Initializing Pure Handshake Engine...", "color: #38bdf8; font-weight: bold;");
16
16
 
17
- // 1. Create a live virtual DOM node to sanitize the markup
18
- const parser = new DOMParser();
19
- const doc = parser.parseFromString(`<!DOCTYPE html><html>${document.documentElement.innerHTML}</html>`, 'text/html');
17
+ // 1. Capture the physical HTML content written on the server file
18
+ let rawHtml = document.documentElement.innerHTML;
20
19
 
21
- // 2. CRITICAL CLEANUP: Strip infrastructure scripts out so they NEVER run inside the iframe
22
- const structuralScripts = doc.querySelectorAll('script[src="vfsjs.js"], script[src="main.js"]');
23
- structuralScripts.forEach(script => script.remove());
20
+ // Strip out the host infrastructure scripts so they don't get sent to the iframe
21
+ rawHtml = rawHtml.replace(/<script\s+src="vfsjs\.js"><\/script>/gi, '');
22
+ rawHtml = rawHtml.replace(/<script\s+src="main\.js"><\/script>/gi, '');
23
+ vfsMemory['index.html'] = rawHtml;
24
24
 
25
- const nativeMarkup = `<!DOCTYPE html>\n<html>${doc.documentElement.innerHTML}</html>`;
26
-
27
- // 3. Wipe parent frame clean to keep a blank workspace shell
28
- document.documentElement.innerHTML = '<head><meta charset="UTF-8"><title>VFS Container</title></head><body></body>';
29
-
30
- Object.assign(document.documentElement.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0' });
31
- Object.assign(document.body.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0', background: '#020617' });
32
-
33
- // 4. Send the sanitized native markup down to the worker
34
- this.write('index.html', nativeMarkup, 'text/html');
25
+ // 2. Wipe parent window clean immediately (No lookahead pre-parser network leaks!)
26
+ document.documentElement.innerHTML = '<head><meta charset="UTF-8"><title>VFS Execution Shell</title></head><body></body>';
27
+
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' });
35
30
 
36
- return true;
37
- } catch (err) {
38
- console.error("VFS Separation Fault:", err);
39
- return false;
40
- }
31
+ // 3. Listen for the sandboxed iframe asking for its application bundle
32
+ window.addEventListener('message', (event) => {
33
+ if (event.data && event.data.type === 'VFS_FRAME_READY') {
34
+ const iframeWindow = document.getElementById('canvas-viewport').contentWindow;
35
+ iframeWindow.postMessage({
36
+ type: 'VFS_DELIVER_PAYLOAD',
37
+ payload: vfsMemory
38
+ }, '*');
39
+ }
40
+ });
41
41
  },
42
42
 
43
43
  openViewport() {
44
- console.log("[VFS Kernel] Spawning isolated rendering viewport.");
44
+ console.log("[VFS Kernel] Spawning blank, secure canvas environment.");
45
45
 
46
46
  const iframe = document.createElement('iframe');
47
47
  iframe.id = 'canvas-viewport';
@@ -49,36 +49,74 @@
49
49
  position: 'fixed', top: '0', left: '0', width: '100%', height: '100%',
50
50
  border: 'none', margin: '0', padding: '0', zIndex: '999999', background: '#020617'
51
51
  });
52
+
52
53
  document.body.appendChild(iframe);
53
- iframe.src = './index.html?vfs=true';
54
- },
55
54
 
56
- write(filename, contentString, customMime) {
57
- if (!navigator.serviceWorker.controller) return false;
58
-
59
- let cleanKey = filename.split('?')[0].split('/').pop();
55
+ // Construct an entirely self-contained runtime client inside the iframe
56
+ // It boots up, asks the parent for the virtual files, and executes them cleanly
57
+ const bootloaderScript = `
58
+ <!DOCTYPE html>
59
+ <html>
60
+ <head>
61
+ <meta charset="UTF-8">
62
+ <script>
63
+ window.addEventListener('message', (event) => {
64
+ if (event.data && event.data.type === 'VFS_DELIVER_PAYLOAD') {
65
+ const { payload } = event.data;
66
+
67
+ // 1. Inject Styles
68
+ const style = document.createElement('style');
69
+ style.textContent = payload['style.css'];
70
+ document.head.appendChild(style);
60
71
 
61
- if (!customMime) {
62
- const ext = cleanKey.split('.').pop().toLowerCase();
63
- const mimeMatrix = { 'js': 'text/javascript', 'css': 'text/css', 'html': 'text/html', 'json': 'application/json' };
64
- customMime = mimeMatrix[ext] || 'application/octet-stream';
65
- }
72
+ // 2. Inject External Scripts (Like Confetti Engine) sequentially
73
+ Promise.all(payload.remote_scripts.map(url => {
74
+ return new Promise((resolve, reject) => {
75
+ const script = document.createElement('script');
76
+ script.src = url;
77
+ script.onload = resolve;
78
+ script.onerror = reject;
79
+ document.head.appendChild(script);
80
+ });
81
+ })).then(() => {
82
+ // 3. Inject and run Application loop script only AFTER dependencies load
83
+ const appScript = document.createElement('script');
84
+ appScript.textContent = payload['app.js'];
85
+ document.body.appendChild(appScript);
86
+ }).catch(err => console.error("Dependency Load Failure:", err));
87
+ }
88
+ });
66
89
 
67
- navigator.serviceWorker.controller.postMessage({
68
- type: 'VFS_WRITE',
69
- filename: cleanKey,
70
- content: encoder.encode(contentString),
71
- mime: customMime
72
- });
73
- return true;
90
+ // Tell the parent window we are ready to receive files
91
+ window.parent.postMessage({ type: 'VFS_FRAME_READY' }, '*');
92
+ <\/script>
93
+ </head>
94
+ <body>
95
+ <script>
96
+ window.addEventListener('message', (e) => {
97
+ if (e.data && e.data.type === 'VFS_DELIVER_PAYLOAD') {
98
+ const parser = new DOMParser();
99
+ const doc = parser.parseFromString(e.data.payload['index.html'], 'text/html');
100
+ document.body.innerHTML = doc.body.innerHTML;
101
+ }
102
+ }, { once: true });
103
+ </script>
104
+ </body>
105
+ </html>
106
+ `;
107
+
108
+ iframe.srcdoc = bootloaderScript;
109
+ },
110
+
111
+ write(filename, contentString) {
112
+ vfsMemory[filename] = contentString;
113
+ },
114
+
115
+ pushRemoteScript(url) {
116
+ vfsMemory['remote_scripts'].push(url);
74
117
  }
75
118
  };
76
119
 
77
120
  window._vfsKernel = engineCore;
78
-
79
- if (document.readyState === 'loading') {
80
- document.addEventListener('DOMContentLoaded', () => engineCore.init());
81
- } else {
82
- engineCore.init();
83
- }
121
+ engineCore.init();
84
122
  })();