vfsjs-test 1.0.24 → 1.0.25

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 +49 -43
  2. package/package.json +1 -1
  3. package/vfsjs.js +17 -8
package/main.js CHANGED
@@ -1,51 +1,57 @@
1
1
  // main.js - Production Build Core Orchestrator
2
2
 
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;
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
+ }
17
25
  }
18
- }
19
- };
20
-
21
- async function runProductionBuild() {
22
- // 1. Seed assets safely into the worker environment
23
- vfs.add('app.js', `
24
- console.log("Application loop booted inside clean VFS space!");
25
- if (typeof window.confetti === 'function') {
26
- setInterval(() => {
27
- window.confetti({ particleCount: 50, spread: 60 });
28
- }, 2500);
29
- }
30
- `, 'text/javascript');
26
+ };
31
27
 
32
- vfs.add('style.css', `
33
- body { background: radial-gradient(circle, #1e1b4b, #020617) !important; color: #f8fafc !important; font-family: monospace; text-align: center; padding: 50px; }
34
- h2 { color: #38bdf8; }
35
- `, 'text/css');
28
+ async function runProductionBuild() {
29
+ // Seed files exactly ONCE
30
+ vfs.add('app.js', `
31
+ console.log("Application loop booted inside clean VFS space!");
32
+ if (typeof window.confetti === 'function') {
33
+ setInterval(() => {
34
+ window.confetti({ particleCount: 50, spread: 60 });
35
+ }, 2500);
36
+ }
37
+ `, 'text/javascript');
36
38
 
37
- // 2. Fetch external dependencies smoothly
38
- await vfs.importRemote('my-confetti-engine.js', 'https://cdn.jsdelivr.net/npm/canvas-confetti@1.9.4/dist/confetti.browser.min.js', 'text/javascript');
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');
39
44
 
40
- // 3. Fire up the layout iframe viewport now that everything is safely registered
41
- window._vfsKernel.openViewport();
42
- }
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');
43
46
 
44
- // Verification initialization hook loop
45
- (function verifyKernelAvailability() {
46
- if (window._vfsKernel && navigator.serviceWorker && navigator.serviceWorker.controller) {
47
- runProductionBuild();
48
- } else {
49
- setTimeout(verifyKernelAvailability, 15);
47
+ window._vfsKernel.openViewport();
50
48
  }
51
- })();
49
+
50
+ (function verifyKernelAvailability() {
51
+ if (window._vfsKernel && navigator.serviceWorker && navigator.serviceWorker.controller) {
52
+ runProductionBuild();
53
+ } else {
54
+ setTimeout(verifyKernelAvailability, 15);
55
+ }
56
+ })();
57
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vfsjs-test",
3
- "version": "1.0.24",
3
+ "version": "1.0.25",
4
4
  "description": "",
5
5
  "main": "index.html",
6
6
  "scripts": {
package/vfsjs.js CHANGED
@@ -1,17 +1,26 @@
1
- // vfsjs.js - Version 7.0.0 (Universal Service Worker Sandbox)
1
+ // vfsjs.js - Version 8.0.0 (Anti-Recursion Production 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
+ }
7
+
3
8
  const encoder = new TextEncoder();
4
9
 
5
10
  const engineCore = {
6
11
  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
+ );
17
+
7
18
  try {
8
- // 1. Boot up the background network interception thread
9
19
  await navigator.serviceWorker.register('./sw.js');
10
20
  if (!navigator.serviceWorker.controller) {
11
21
  await new Promise(r => navigator.serviceWorker.addEventListener('controllerchange', r, { once: true }));
12
22
  }
13
23
 
14
- // 2. Capture layout markup cleanly before UI shift
15
24
  const rawHtml = document.documentElement.innerHTML;
16
25
  this.write('index.html', `<!DOCTYPE html>\n<html>${rawHtml}</html>`, 'text/html');
17
26
 
@@ -23,25 +32,25 @@
23
32
  }
24
33
  },
25
34
 
26
- // Called dynamically by main.js after your cache writes complete
27
35
  openViewport() {
28
36
  console.log("[VFS Kernel] Deploying canvas sandboxed frame wrapper.");
29
37
 
30
- // Re-enforce main window shell structures cleanly
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';
31
41
  document.body.style.margin = '0';
32
42
  document.body.style.padding = '0';
33
43
  document.body.style.overflow = 'hidden';
34
- document.body.style.background = '#020617';
35
44
 
36
45
  const iframe = document.createElement('iframe');
37
46
  iframe.id = 'canvas-viewport';
38
47
  Object.assign(iframe.style, {
39
48
  position: 'fixed', top: '0', left: '0', width: '100%', height: '100%',
40
- border: 'none', margin: '0', padding: '0', zIndex: '999999'
49
+ border: 'none', margin: '0', padding: '0', zIndex: '999999',
50
+ background: '#020617' // Force iframe background dark before content arrives
41
51
  });
42
52
  document.body.appendChild(iframe);
43
53
 
44
- // Force execution routing directly inside our Service Worker scope zone
45
54
  iframe.src = './index.html?vfs=true';
46
55
  },
47
56