vfsjs-test 1.0.22 → 1.0.24

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 (5) hide show
  1. package/index.html +2 -0
  2. package/main.js +23 -13
  3. package/package.json +1 -1
  4. package/sw.js +54 -44
  5. package/vfsjs.js +27 -30
package/index.html CHANGED
@@ -3,6 +3,8 @@
3
3
  <head>
4
4
  <script src="vfsjs.js"></script>
5
5
 
6
+ <script src="main.js"></script>
7
+
6
8
  <meta charset="UTF-8">
7
9
  <title>My Completely Normal Project</title>
8
10
 
package/main.js CHANGED
@@ -1,10 +1,9 @@
1
- // main.js - Production Asset Orchestrator
1
+ // main.js - Production Build Core Orchestrator
2
2
 
3
3
  window.vfs = {
4
4
  add(filename, contentString, customMime = null) {
5
5
  return window._vfsKernel.write(filename, contentString, customMime);
6
6
  },
7
-
8
7
  async importRemote(localFilename, remoteUrl, customMime = null) {
9
8
  try {
10
9
  const response = await fetch(remoteUrl);
@@ -13,29 +12,40 @@ window.vfs = {
13
12
  this.add(localFilename, text, customMime);
14
13
  return true;
15
14
  } catch (err) {
16
- console.error(`[VFS Proxy Error] Failed loading remote path:`, err);
15
+ console.error(`[VFS Proxy Error]`, err);
17
16
  return false;
18
17
  }
19
18
  }
20
19
  };
21
20
 
22
- async function buildProductionApplication() {
23
- // 1. Map assets into the active Service Worker cache storage map first
24
- vfs.add('app.js', `console.log("App running cleanly inside VFS!");`, 'text/javascript');
25
- vfs.add('style.css', `body { background: #020617; color: #38bdf8; font-family: monospace; padding: 20px; }`, 'text/css');
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');
31
+
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');
26
36
 
27
- // 2. Fetch remote modules
37
+ // 2. Fetch external dependencies smoothly
28
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');
29
39
 
30
- // 3. CRITICAL: Everything is safely in memory. Signal the kernel to open the iframe viewport!
40
+ // 3. Fire up the layout iframe viewport now that everything is safely registered
31
41
  window._vfsKernel.openViewport();
32
42
  }
33
43
 
34
- // Polling initialization hook to bridge cleanly across asynchronous script loads
44
+ // Verification initialization hook loop
35
45
  (function verifyKernelAvailability() {
36
- if (window._vfsKernel && navigator.serviceWorker.controller) {
37
- buildProductionApplication();
46
+ if (window._vfsKernel && navigator.serviceWorker && navigator.serviceWorker.controller) {
47
+ runProductionBuild();
38
48
  } else {
39
- setTimeout(verifyKernelAvailability, 10);
49
+ setTimeout(verifyKernelAvailability, 15);
40
50
  }
41
51
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vfsjs-test",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "description": "",
5
5
  "main": "index.html",
6
6
  "scripts": {
package/sw.js CHANGED
@@ -1,53 +1,63 @@
1
- // sw.js - Version 1.1.2 (Shadow Router)
2
- const vfsStorage = new Map();
1
+ // sw.js - Version 7.0.0 (Zero-Leak Network Interceptor)
3
2
 
4
- self.addEventListener('install', e => e.waitUntil(self.skipWaiting()));
5
- self.addEventListener('activate', e => e.waitUntil(self.clients.claim()));
3
+ const virtualStorage = new Map();
6
4
 
5
+ self.addEventListener('install', (e) => self.skipWaiting());
6
+ self.addEventListener('activate', (e) => e.waitUntil(self.clients.claim()));
7
+
8
+ // Message handling pipeline for window memory synchronizations
9
+ self.addEventListener('message', (event) => {
10
+ if (event.data && event.data.type === 'VFS_WRITE') {
11
+ virtualStorage.set(event.data.filename, {
12
+ content: event.data.content, // Uint8Array binary format
13
+ mime: event.data.mime
14
+ });
15
+ }
16
+ });
17
+
18
+ // The universal request routing core
7
19
  self.addEventListener('fetch', (event) => {
8
20
  const url = new URL(event.request.url);
9
- let filename = url.pathname.split('/').pop().split('?')[0];
10
21
 
11
- // ROUTING TRICK: If requesting the root domain "/" or "/index.html",
12
- // prioritize our virtual memory database file!
13
- if (filename === '' || url.pathname.endsWith('/')) {
14
- filename = 'index.html';
15
- }
16
-
17
- const isVfsExplicit = url.searchParams.get('vfs') === 'true';
18
-
19
- // Intercept if it's our target index or explicitly tagged
20
- if (vfsStorage.has(filename) || isVfsExplicit) {
21
- event.respondWith(
22
- new Promise((resolve) => {
23
- const checkFile = () => {
24
- if (vfsStorage.has(filename)) {
25
- const fileData = vfsStorage.get(filename);
26
- const ext = filename.split('.').pop().toLowerCase();
27
-
28
- const mimeMatrix = { 'js': 'text/javascript', 'css': 'text/css', 'html': 'text/html' };
29
- const contentType = fileData.mime || mimeMatrix[ext] || 'application/octet-stream';
30
-
31
- resolve(new Response(fileData.content, {
32
- status: 200,
33
- headers: {
34
- 'Content-Type': contentType,
35
- 'Access-Control-Allow-Origin': '*',
36
- 'X-Content-Type-Options': 'nosniff'
37
- }
38
- }));
39
- } else {
40
- setTimeout(checkFile, 5);
22
+ // Check if this request is explicitly targeting our virtual scope ecosystem
23
+ if (url.searchParams.get('vfs') === 'true' || url.href.includes('vfs=true')) {
24
+ const cleanFilename = url.pathname.split('/').pop() || 'index.html';
25
+
26
+ // Match against memory cache database maps
27
+ if (virtualStorage.has(cleanFilename)) {
28
+ const cachedAsset = virtualStorage.get(cleanFilename);
29
+ event.respondWith(
30
+ new Response(cachedAsset.content, {
31
+ status: 200,
32
+ headers: {
33
+ 'Content-Type': cachedAsset.mime,
34
+ 'X-Content-Type-Options': 'nosniff' // Pass strict parsing checks
41
35
  }
42
- };
43
- checkFile();
44
- })
45
- );
46
- }
47
- });
36
+ })
37
+ );
38
+ } else {
39
+ // OPTION B CATCH-ALL: Banish unpkg network fallback crashes!
40
+ // If main.js hasn't populated a script yet, serve a valid empty fallback shell script/style
41
+ let fallbackBody = '';
42
+ let fallbackMime = 'text/plain';
48
43
 
49
- self.addEventListener('message', (event) => {
50
- if (event.data && event.data.type === 'VFS_WRITE') {
51
- vfsStorage.set(event.data.filename, { content: event.data.content, mime: event.data.mime });
44
+ if (cleanFilename.endsWith('.js')) {
45
+ fallbackBody = `console.warn("VFS Interceptor: Dynamic fallback stub active for ${cleanFilename}");`;
46
+ fallbackMime = 'text/javascript';
47
+ } else if (cleanFilename.endsWith('.css')) {
48
+ fallbackBody = `/* VFS Dynamic Style Fallback Stub */`;
49
+ fallbackMime = 'text/css';
50
+ } else if (cleanFilename.endsWith('.json')) {
51
+ fallbackBody = '{}';
52
+ fallbackMime = 'application/json';
53
+ }
54
+
55
+ event.respondWith(
56
+ new Response(fallbackBody, {
57
+ status: 200,
58
+ headers: { 'Content-Type': fallbackMime }
59
+ })
60
+ );
61
+ }
52
62
  }
53
63
  });
package/vfsjs.js CHANGED
@@ -1,57 +1,54 @@
1
- // vfsjs.js - Version 5.0.0 (Production Synchronization Engine)
1
+ // vfsjs.js - Version 7.0.0 (Universal Service Worker Sandbox)
2
2
  (function() {
3
3
  const encoder = new TextEncoder();
4
4
 
5
5
  const engineCore = {
6
6
  async init() {
7
7
  try {
8
- // 1. Boot the Service Worker thread
8
+ // 1. Boot up the background network interception thread
9
9
  await navigator.serviceWorker.register('./sw.js');
10
10
  if (!navigator.serviceWorker.controller) {
11
11
  await new Promise(r => navigator.serviceWorker.addEventListener('controllerchange', r, { once: true }));
12
12
  }
13
13
 
14
- // 2. Capture raw HTML layout
15
- const developerRawHtml = `<!DOCTYPE html>\n<html>${document.documentElement.innerHTML}</html>`;
16
- this.write('index.html', developerRawHtml, 'text/html');
17
-
18
- // 3. Clear window layout & lock sizing boundaries
19
- document.documentElement.innerHTML = '';
20
- Object.assign(document.documentElement.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0' });
21
- Object.assign(document.body.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0', background: '#020617' });
22
-
23
- // 4. Create the iframe canvas, but leave it blank (src="") so it doesn't request files yet!
24
- const iframe = document.createElement('iframe');
25
- iframe.id = 'canvas-viewport';
26
- Object.assign(iframe.style, {
27
- position: 'absolute', top: '0', left: '0', width: '100%', height: '100%',
28
- border: 'none', margin: '0', padding: '0', zIndex: '999999'
29
- });
30
- document.body.appendChild(iframe);
14
+ // 2. Capture layout markup cleanly before UI shift
15
+ const rawHtml = document.documentElement.innerHTML;
16
+ this.write('index.html', `<!DOCTYPE html>\n<html>${rawHtml}</html>`, 'text/html');
31
17
 
18
+ console.log("[VFS Kernel] Core initialized. Communication channel open.");
32
19
  return true;
33
20
  } catch (err) {
34
- console.error("VFS Kernel Initialization Fault:", err);
21
+ console.error("VFS Kernel Boot Fault:", err);
35
22
  return false;
36
23
  }
37
24
  },
38
25
 
39
- // Called exclusively by main.js once all local/remote files are committed to memory
26
+ // Called dynamically by main.js after your cache writes complete
40
27
  openViewport() {
41
- const iframe = document.getElementById('canvas-viewport');
42
- if (iframe) {
43
- console.log("[VFS Kernel] Memory mapping complete. Opening virtual system pipeline.");
44
- iframe.src = './?vfs=true';
45
- }
28
+ console.log("[VFS Kernel] Deploying canvas sandboxed frame wrapper.");
29
+
30
+ // Re-enforce main window shell structures cleanly
31
+ document.body.style.margin = '0';
32
+ document.body.style.padding = '0';
33
+ document.body.style.overflow = 'hidden';
34
+ document.body.style.background = '#020617';
35
+
36
+ const iframe = document.createElement('iframe');
37
+ iframe.id = 'canvas-viewport';
38
+ Object.assign(iframe.style, {
39
+ position: 'fixed', top: '0', left: '0', width: '100%', height: '100%',
40
+ border: 'none', margin: '0', padding: '0', zIndex: '999999'
41
+ });
42
+ document.body.appendChild(iframe);
43
+
44
+ // Force execution routing directly inside our Service Worker scope zone
45
+ iframe.src = './index.html?vfs=true';
46
46
  },
47
47
 
48
48
  write(filename, contentString, customMime) {
49
49
  if (!navigator.serviceWorker.controller) return false;
50
50
 
51
- let cleanKey = filename.split('?')[0];
52
- if (cleanKey.includes('/')) {
53
- cleanKey = cleanKey.split('/').pop();
54
- }
51
+ let cleanKey = filename.split('?')[0].split('/').pop();
55
52
 
56
53
  if (!customMime) {
57
54
  const ext = cleanKey.split('.').pop().toLowerCase();