vfsjs-test 1.0.23 → 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 +16 -22
  3. package/package.json +1 -1
  4. package/sw.js +54 -44
  5. package/vfsjs.js +42 -56
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,18 +1,13 @@
1
- // main.js - Production Build Wrapper
1
+ // main.js - Production Build Core Orchestrator
2
2
 
3
3
  window.vfs = {
4
4
  add(filename, contentString, customMime = null) {
5
- // Strip out query paths down to base keys
6
- let cleanKey = filename.split('?')[0].split('/').pop();
7
- window._vfsVirtualCache[cleanKey] = { content: contentString, mime: customMime };
8
- console.log(`[VFS Cache] Staging file asset: ${cleanKey}`);
9
- return true;
5
+ return window._vfsKernel.write(filename, contentString, customMime);
10
6
  },
11
-
12
7
  async importRemote(localFilename, remoteUrl, customMime = null) {
13
8
  try {
14
9
  const response = await fetch(remoteUrl);
15
- if (!response.ok) throw new Error(`HTTP Fault: ${response.status}`);
10
+ if (!response.ok) throw new Error(`HTTP network error: ${response.status}`);
16
11
  const text = await response.text();
17
12
  this.add(localFilename, text, customMime);
18
13
  return true;
@@ -23,35 +18,34 @@ window.vfs = {
23
18
  }
24
19
  };
25
20
 
26
- async function buildProductionApplication() {
27
- // 1. Stage compilation data targets
21
+ async function runProductionBuild() {
22
+ // 1. Seed assets safely into the worker environment
28
23
  vfs.add('app.js', `
29
- console.log("Launcher script running. Invoking confetti...");
24
+ console.log("Application loop booted inside clean VFS space!");
30
25
  if (typeof window.confetti === 'function') {
31
26
  setInterval(() => {
32
- window.confetti({ particleCount: 40, spread: 50, origin: { y: 0.6 } });
33
- }, 2000);
34
- } else {
35
- console.error("Confetti script missing from global iframe execution scope.");
27
+ window.confetti({ particleCount: 50, spread: 60 });
28
+ }, 2500);
36
29
  }
37
30
  `, 'text/javascript');
38
31
 
39
32
  vfs.add('style.css', `
40
- body { background: #020617 !important; color: #38bdf8 !important; font-family: monospace; padding: 40px; text-align: center; }
41
- h2 { text-shadow: 0 0 8px rgba(56,189,248,0.5); }
33
+ body { background: radial-gradient(circle, #1e1b4b, #020617) !important; color: #f8fafc !important; font-family: monospace; text-align: center; padding: 50px; }
34
+ h2 { color: #38bdf8; }
42
35
  `, 'text/css');
43
36
 
44
- // 2. Fetch CDNJS/jsDelivr packages that bypass scope paths safely
37
+ // 2. Fetch external dependencies smoothly
45
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');
46
39
 
47
- // 3. Compile and open viewport
40
+ // 3. Fire up the layout iframe viewport now that everything is safely registered
48
41
  window._vfsKernel.openViewport();
49
42
  }
50
43
 
44
+ // Verification initialization hook loop
51
45
  (function verifyKernelAvailability() {
52
- if (window._vfsKernel) {
53
- buildProductionApplication();
46
+ if (window._vfsKernel && navigator.serviceWorker && navigator.serviceWorker.controller) {
47
+ runProductionBuild();
54
48
  } else {
55
- setTimeout(verifyKernelAvailability, 10);
49
+ setTimeout(verifyKernelAvailability, 15);
56
50
  }
57
51
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vfsjs-test",
3
- "version": "1.0.23",
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,85 +1,71 @@
1
- // vfsjs.js - Version 6.0.0 (Zero-Network Tag Inline Engine)
1
+ // vfsjs.js - Version 7.0.0 (Universal Service Worker Sandbox)
2
2
  (function() {
3
+ const encoder = new TextEncoder();
4
+
3
5
  const engineCore = {
4
6
  async init() {
5
7
  try {
6
- // 1. Boot Service Worker for the root frame route interception if needed
8
+ // 1. Boot up the background network interception thread
7
9
  await navigator.serviceWorker.register('./sw.js');
8
10
  if (!navigator.serviceWorker.controller) {
9
11
  await new Promise(r => navigator.serviceWorker.addEventListener('controllerchange', r, { once: true }));
10
12
  }
11
13
 
12
- // 2. Capture the developer's original raw HTML string structure
14
+ // 2. Capture layout markup cleanly before UI shift
13
15
  const rawHtml = document.documentElement.innerHTML;
14
- window._vfsRawTemplate = `<!DOCTYPE html>\n<html>${rawHtml}</html>`;
15
-
16
- // 3. Clear parent UI layout instantly
17
- document.documentElement.innerHTML = '';
18
- Object.assign(document.documentElement.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0' });
19
- Object.assign(document.body.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0', background: '#020617' });
20
-
21
- // 4. Create the pristine layout iframe container
22
- const iframe = document.createElement('iframe');
23
- iframe.id = 'canvas-viewport';
24
- Object.assign(iframe.style, {
25
- position: 'absolute', top: '0', left: '0', width: '100%', height: '100%',
26
- border: 'none', margin: '0', padding: '0', zIndex: '999999'
27
- });
28
- document.body.appendChild(iframe);
16
+ this.write('index.html', `<!DOCTYPE html>\n<html>${rawHtml}</html>`, 'text/html');
29
17
 
18
+ console.log("[VFS Kernel] Core initialized. Communication channel open.");
30
19
  return true;
31
20
  } catch (err) {
32
- console.error("VFS Critical Bootstrap Failure:", err);
21
+ console.error("VFS Kernel Boot Fault:", err);
33
22
  return false;
34
23
  }
35
24
  },
36
25
 
37
- // Called by main.js after vfs.add loops complete
26
+ // Called dynamically by main.js after your cache writes complete
38
27
  openViewport() {
39
- const iframe = document.getElementById('canvas-viewport');
40
- if (!iframe) return;
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';
41
35
 
42
- // Create a virtual document parser out of our captured template
43
- const parser = new DOMParser();
44
- const doc = parser.parseFromString(window._vfsRawTemplate, 'text/html');
45
-
46
- // 1. Process and inline all marked script tags out of VFS memory maps
47
- const scripts = Array.from(doc.querySelectorAll('script[src*="vfs=true"]'));
48
- scripts.forEach(script => {
49
- const srcAttr = script.getAttribute('src').split('?')[0].split('/').pop();
50
- const virtualCode = window._vfsVirtualCache[srcAttr];
51
-
52
- if (virtualCode) {
53
- const inlineScript = doc.createElement('script');
54
- inlineScript.textContent = virtualCode.content;
55
- script.parentNode.replaceChild(inlineScript, script);
56
- }
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'
57
41
  });
42
+ document.body.appendChild(iframe);
58
43
 
59
- // 2. Process and inline all marked style sheets out of VFS memory maps
60
- const links = Array.from(doc.querySelectorAll('link[rel="stylesheet"][href*="vfs=true"]'));
61
- links.forEach(link => {
62
- const hrefAttr = link.getAttribute('href').split('?')[0].split('/').pop();
63
- const virtualCSS = window._vfsVirtualCache[hrefAttr];
64
-
65
- if (virtualCSS) {
66
- const inlineStyle = doc.createElement('style');
67
- inlineStyle.textContent = virtualCSS.content;
68
- link.parentNode.replaceChild(inlineStyle, link);
69
- }
70
- });
44
+ // Force execution routing directly inside our Service Worker scope zone
45
+ iframe.src = './index.html?vfs=true';
46
+ },
71
47
 
72
- // 3. Convert modified dynamic DOM tree back to a string bundle
73
- const compilationOutput = `<!DOCTYPE html>\n<html>${doc.documentElement.innerHTML}</html>`;
48
+ write(filename, contentString, customMime) {
49
+ if (!navigator.serviceWorker.controller) return false;
50
+
51
+ let cleanKey = filename.split('?')[0].split('/').pop();
74
52
 
75
- // 4. Inject compilation cleanly via srcdoc to bypass unpkg scope boundaries completely!
76
- iframe.srcdoc = compilationOutput;
77
- console.log("[VFS Kernel] Execution compilation injected successfully via srcdoc channel.");
53
+ if (!customMime) {
54
+ const ext = cleanKey.split('.').pop().toLowerCase();
55
+ const mimeMatrix = { 'js': 'text/javascript', 'css': 'text/css', 'html': 'text/html', 'json': 'application/json' };
56
+ customMime = mimeMatrix[ext] || 'application/octet-stream';
57
+ }
58
+
59
+ navigator.serviceWorker.controller.postMessage({
60
+ type: 'VFS_WRITE',
61
+ filename: cleanKey,
62
+ content: encoder.encode(contentString),
63
+ mime: customMime
64
+ });
65
+ return true;
78
66
  }
79
67
  };
80
68
 
81
- // Shared internal key store memory map allocation
82
- window._vfsVirtualCache = {};
83
69
  window._vfsKernel = engineCore;
84
70
 
85
71
  if (document.readyState === 'loading') {