vfsjs-test 1.0.28 → 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 +35 -50
  2. package/package.json +1 -1
  3. package/vfsjs.js +95 -54
package/main.js CHANGED
@@ -1,77 +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
- // 1. Fetch remote script engine and write it into local cache immediately
23
- await vfs.importRemote('my-confetti-engine.js', 'https://cdn.jsdelivr.net/npm/canvas-confetti@1.9.4/dist/confetti.browser.min.js', 'text/javascript');
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');
24
15
 
25
- // 2. Inject app.js with a small pool verification to bind the action button cleanly
16
+ // Register application code logic structures
26
17
  vfs.add('app.js', `
27
- console.log("Application loop booted inside clean VFS space!");
18
+ console.log("Application loop booted inside clean isolated VFS Space!");
28
19
 
29
- document.addEventListener('DOMContentLoaded', () => {
30
- let container = document.querySelector('.js-card');
31
- if (!container) {
32
- container = document.createElement('div');
33
- container.className = 'js-card';
34
- container.innerHTML = '<h3>Automated Clean Shell Live</h3><p>The environment is isolated cleanly.</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
- const button = document.createElement('button');
39
- button.id = 'action-btn';
40
- button.innerText = 'Trigger Confetti';
41
- container.appendChild(button);
42
-
43
- // Robust polling wrapper to guarantee framework availability on click
44
- button.addEventListener('click', () => {
45
- const targetWindow = window.parent.vfs ? window.parent : window;
46
- if (typeof targetWindow.confetti === 'function') {
47
- targetWindow.confetti({ particleCount: 100, spread: 70, origin: { y: 0.6 } });
48
- } else if (typeof window.confetti === 'function') {
49
- window.confetti({ particleCount: 100, spread: 70, origin: { y: 0.6 } });
50
- } else {
51
- console.error("Confetti fallback execution error: Reference missing.");
52
- }
53
- });
54
37
  });
55
- `, 'text/javascript');
38
+ `);
56
39
 
40
+ // Register explicit application presentation rules
57
41
  vfs.add('style.css', `
58
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; }
59
43
  h1 { color: #38bdf8; font-size: 2.5rem; }
60
- p { color: #94a3b8; max-width: 500px; }
61
- .js-card { background: #0f172a; border: 1px solid #1e293b; padding: 25px; border-radius: 12px; max-width: 400px; margin-top: 20px; }
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); }
62
46
  .js-card h3 { color: #34d399; margin-top: 0; }
63
- button { background: #38bdf8; color: #020617; border: none; padding: 12px 24px; font-weight: 600; border-radius: 6px; cursor: pointer; margin-top: 15px; }
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; }
64
48
  button:hover { background: #7dd3fc; }
65
- `, 'text/css');
49
+ `);
66
50
 
67
- // 3. Open viewport canvas wrapper framework
51
+ // Deploy the viewport framework
68
52
  window._vfsKernel.openViewport();
69
53
  }
70
54
 
55
+ // Verification block loop execution
71
56
  (function verifyKernelAvailability() {
72
- if (window._vfsKernel && navigator.serviceWorker && navigator.serviceWorker.controller) {
57
+ if (window._vfsKernel) {
73
58
  runProductionBuild();
74
59
  } else {
75
- setTimeout(verifyKernelAvailability, 15);
60
+ setTimeout(verifyKernelAvailability, 10);
76
61
  }
77
62
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vfsjs-test",
3
- "version": "1.0.28",
3
+ "version": "1.0.29",
4
4
  "description": "",
5
5
  "main": "index.html",
6
6
  "scripts": {
package/vfsjs.js CHANGED
@@ -1,81 +1,122 @@
1
- // vfsjs.js - Version 12.0.0 (Zero-Leak Pure 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
- // Reassuring, bold console warning statement
10
- console.warn(
11
- "%c[VFS Kernel] NOTICE: Any 'MIME type text/plain' or 'NS_ERROR_CORRUPTED_CONTENT' logs above are expected Phase-1 browser artifacts. The engine gracefully isolates them.",
12
- "font-weight: bold; font-size: 11px;"
13
- );
14
-
15
- try {
16
- await navigator.serviceWorker.register('./sw.js');
17
- if (!navigator.serviceWorker.controller) {
18
- await new Promise(r => navigator.serviceWorker.addEventListener('controllerchange', r, { once: true }));
19
- }
14
+ init() {
15
+ console.log("%c[VFS Kernel] Initializing Pure Handshake Engine...", "color: #38bdf8; font-weight: bold;");
20
16
 
21
- // Get raw HTML code strings cleanly
22
- let htmlString = `<!DOCTYPE html>\n<html>${document.documentElement.innerHTML}</html>`;
17
+ // 1. Capture the physical HTML content written on the server file
18
+ let rawHtml = document.documentElement.innerHTML;
23
19
 
24
- // Wipe infrastructure script tags via string manipulation to block DOMParser leaks
25
- htmlString = htmlString.replace(/<script\s+src="vfsjs\.js"><\/script>/gi, '');
26
- htmlString = htmlString.replace(/<script\s+src="main\.js"><\/script>/gi, '');
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;
27
24
 
28
- // Clean the parent view area completely
29
- document.documentElement.innerHTML = '<head><meta charset="UTF-8"><title>VFS Container Shell</title></head><body></body>';
30
-
31
- Object.assign(document.documentElement.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0' });
32
- Object.assign(document.body.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0', background: '#020617' });
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' });
33
30
 
34
- this.write('index.html', htmlString, 'text/html');
35
- return true;
36
- } catch (err) {
37
- console.error("VFS Extraction Fault:", err);
38
- return false;
39
- }
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
+ });
40
41
  },
41
42
 
42
43
  openViewport() {
43
- console.log("[VFS Kernel] Spawning isolated rendering viewport.");
44
+ console.log("[VFS Kernel] Spawning blank, secure canvas environment.");
45
+
44
46
  const iframe = document.createElement('iframe');
45
47
  iframe.id = 'canvas-viewport';
46
48
  Object.assign(iframe.style, {
47
49
  position: 'fixed', top: '0', left: '0', width: '100%', height: '100%',
48
50
  border: 'none', margin: '0', padding: '0', zIndex: '999999', background: '#020617'
49
51
  });
52
+
50
53
  document.body.appendChild(iframe);
51
- iframe.src = './index.html?vfs=true';
52
- },
53
54
 
54
- write(filename, contentString, customMime) {
55
- if (!navigator.serviceWorker.controller) return false;
56
- 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);
57
71
 
58
- if (!customMime) {
59
- const ext = cleanKey.split('.').pop().toLowerCase();
60
- const mimeMatrix = { 'js': 'text/javascript', 'css': 'text/css', 'html': 'text/html', 'json': 'application/json' };
61
- customMime = mimeMatrix[ext] || 'application/octet-stream';
62
- }
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
+ });
63
89
 
64
- navigator.serviceWorker.controller.postMessage({
65
- type: 'VFS_WRITE',
66
- filename: cleanKey,
67
- content: encoder.encode(contentString),
68
- mime: customMime
69
- });
70
- 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);
71
117
  }
72
118
  };
73
119
 
74
120
  window._vfsKernel = engineCore;
75
-
76
- if (document.readyState === 'loading') {
77
- document.addEventListener('DOMContentLoaded', () => engineCore.init());
78
- } else {
79
- engineCore.init();
80
- }
121
+ engineCore.init();
81
122
  })();