vfsjs-test 1.0.23 → 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 (5) hide show
  1. package/index.html +2 -0
  2. package/main.js +50 -50
  3. package/package.json +1 -1
  4. package/sw.js +54 -44
  5. package/vfsjs.js +51 -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,57 +1,57 @@
1
- // main.js - Production Build Wrapper
1
+ // main.js - Production Build Core Orchestrator
2
2
 
3
- window.vfs = {
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;
10
- },
11
-
12
- async importRemote(localFilename, remoteUrl, customMime = null) {
13
- try {
14
- const response = await fetch(remoteUrl);
15
- if (!response.ok) throw new Error(`HTTP Fault: ${response.status}`);
16
- const text = await response.text();
17
- this.add(localFilename, text, customMime);
18
- return true;
19
- } catch (err) {
20
- console.error(`[VFS Proxy Error]`, err);
21
- return false;
22
- }
23
- }
24
- };
25
-
26
- async function buildProductionApplication() {
27
- // 1. Stage compilation data targets
28
- vfs.add('app.js', `
29
- console.log("Launcher script running. Invoking confetti...");
30
- if (typeof window.confetti === 'function') {
31
- 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.");
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
+ }
36
25
  }
37
- `, 'text/javascript');
26
+ };
38
27
 
39
- 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); }
42
- `, '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');
43
38
 
44
- // 2. Fetch CDNJS/jsDelivr packages that bypass scope paths safely
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');
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');
46
44
 
47
- // 3. Compile and open viewport
48
- window._vfsKernel.openViewport();
49
- }
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');
50
46
 
51
- (function verifyKernelAvailability() {
52
- if (window._vfsKernel) {
53
- buildProductionApplication();
54
- } else {
55
- setTimeout(verifyKernelAvailability, 10);
47
+ window._vfsKernel.openViewport();
56
48
  }
57
- })();
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.23",
3
+ "version": "1.0.25",
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,80 @@
1
- // vfsjs.js - Version 6.0.0 (Zero-Network Tag Inline Engine)
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
+
8
+ const encoder = new TextEncoder();
9
+
3
10
  const engineCore = {
4
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
+
5
18
  try {
6
- // 1. Boot Service Worker for the root frame route interception if needed
7
19
  await navigator.serviceWorker.register('./sw.js');
8
20
  if (!navigator.serviceWorker.controller) {
9
21
  await new Promise(r => navigator.serviceWorker.addEventListener('controllerchange', r, { once: true }));
10
22
  }
11
23
 
12
- // 2. Capture the developer's original raw HTML string structure
13
24
  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);
25
+ this.write('index.html', `<!DOCTYPE html>\n<html>${rawHtml}</html>`, 'text/html');
29
26
 
27
+ console.log("[VFS Kernel] Core initialized. Communication channel open.");
30
28
  return true;
31
29
  } catch (err) {
32
- console.error("VFS Critical Bootstrap Failure:", err);
30
+ console.error("VFS Kernel Boot Fault:", err);
33
31
  return false;
34
32
  }
35
33
  },
36
34
 
37
- // Called by main.js after vfs.add loops complete
38
35
  openViewport() {
39
- const iframe = document.getElementById('canvas-viewport');
40
- if (!iframe) return;
41
-
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');
36
+ console.log("[VFS Kernel] Deploying canvas sandboxed frame wrapper.");
37
+
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';
41
+ document.body.style.margin = '0';
42
+ document.body.style.padding = '0';
43
+ document.body.style.overflow = 'hidden';
45
44
 
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
- }
45
+ const iframe = document.createElement('iframe');
46
+ iframe.id = 'canvas-viewport';
47
+ Object.assign(iframe.style, {
48
+ position: 'fixed', top: '0', left: '0', width: '100%', height: '100%',
49
+ border: 'none', margin: '0', padding: '0', zIndex: '999999',
50
+ background: '#020617' // Force iframe background dark before content arrives
57
51
  });
52
+ document.body.appendChild(iframe);
58
53
 
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
- });
54
+ iframe.src = './index.html?vfs=true';
55
+ },
71
56
 
72
- // 3. Convert modified dynamic DOM tree back to a string bundle
73
- const compilationOutput = `<!DOCTYPE html>\n<html>${doc.documentElement.innerHTML}</html>`;
57
+ write(filename, contentString, customMime) {
58
+ if (!navigator.serviceWorker.controller) return false;
59
+
60
+ let cleanKey = filename.split('?')[0].split('/').pop();
74
61
 
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.");
62
+ if (!customMime) {
63
+ const ext = cleanKey.split('.').pop().toLowerCase();
64
+ const mimeMatrix = { 'js': 'text/javascript', 'css': 'text/css', 'html': 'text/html', 'json': 'application/json' };
65
+ customMime = mimeMatrix[ext] || 'application/octet-stream';
66
+ }
67
+
68
+ navigator.serviceWorker.controller.postMessage({
69
+ type: 'VFS_WRITE',
70
+ filename: cleanKey,
71
+ content: encoder.encode(contentString),
72
+ mime: customMime
73
+ });
74
+ return true;
78
75
  }
79
76
  };
80
77
 
81
- // Shared internal key store memory map allocation
82
- window._vfsVirtualCache = {};
83
78
  window._vfsKernel = engineCore;
84
79
 
85
80
  if (document.readyState === 'loading') {