vfsjs-test 1.0.13 → 1.0.15

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 (4) hide show
  1. package/main.js +64 -58
  2. package/package.json +1 -1
  3. package/sw.js +15 -30
  4. package/vfsjs.js +5 -17
package/main.js CHANGED
@@ -1,90 +1,96 @@
1
- // main.js - Developer Workspace API
1
+ // main.js - Production Developer Environment Layout
2
2
 
3
3
  window.vfs = {
4
+ // Write local strings straight to memory mapping keyspaces
4
5
  add(filename, contentString, customMime = null) {
5
6
  return window._vfsKernel.write(filename, contentString, customMime);
6
7
  },
7
- delete(filename) { return window._vfsKernel.remove(filename); },
8
- clear() { return window._vfsKernel.wipe(); }
9
- };
10
-
11
- async function startDeveloperWorkspace() {
12
- // 1. Add standard CSS rules directly
13
- vfs.add('live_theme.css', `
14
- html, body { margin: 0; padding: 40px; height: 100%; overflow: hidden; font-family: monospace; background: #020617; color: #38bdf8; }
15
- body { background: linear-gradient(-45deg, #ff007f, #7f00ff, #00bfff, #00ff7f, #ffea00, #ff007f) !important; background-size: 400% 400% !important; animation: rainbowShift 12s ease infinite !important; color: #ffffff !important; }
16
- @keyframes rainbowShift { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } }
17
- `, 'text/css');
18
8
 
19
- // 2. Add traditional JavaScript code
20
- vfs.add('index.js', `
21
- console.log("VFS Engine: Spin test activated inside the seamless frame!");
22
-
23
- // 1. Inject a global CSS animation rule directly into the frame's head
24
- const styleNode = document.createElement('style');
25
- styleNode.innerHTML = \`
26
- @keyframes customSpinMatrix {
27
- 0% { transform: rotate(0deg); }
28
- 100% { transform: rotate(360deg); }
29
- }
30
- .vfs-spinning-target {
31
- display: inline-block !important;
32
- animation: customSpinMatrix 4s linear infinite !important;
9
+ // Remote Proxy Asset Grabber (Requires target destination to support CORS)
10
+ async importRemote(localFilename, remoteUrl, customMime = null) {
11
+ try {
12
+ console.log(`[VFS Proxy] Pulling remote source stream: ${remoteUrl}`);
13
+ const response = await fetch(remoteUrl);
14
+ if (!response.ok) throw new Error(`HTTP network fault code: ${response.status}`);
15
+
16
+ const remoteTextContent = await response.text();
17
+ this.add(localFilename, remoteTextContent, customMime);
18
+ return true;
19
+ } catch (err) {
20
+ console.error(`[VFS Proxy Error] Could not map ${localFilename}:`, err);
21
+ return false;
33
22
  }
34
- \`;
35
- document.head.appendChild(styleNode);
36
-
37
- // 2. Locate all text elements and wrap their text in spinning tags
38
- function applySpinToText() {
39
- // Target headers, paragraphs, lists, and span layers
40
- const textElements = document.querySelectorAll('h1, h2, h3, p, span, li, div');
41
-
42
- textElements.forEach(element => {
43
- // Ignore containers that have children to avoid breaking structure layouts
44
- if (element.children.length === 0 && element.innerText.trim() !== '') {
45
- const words = element.innerText.split(' ');
46
- element.innerHTML = words.map(word =>
47
- \`<span class="vfs-spinning-target">\${word}</span>\`
48
- ).join(' ');
49
- }
50
- });
51
23
  }
24
+ };
25
+
26
+ async function startDeveloperWorkspace() {
27
+ // 1. Target a real, open-source library on CDNJS (Canvas Confetti)
28
+ const remoteLibraryUrl = 'https://cdnjs.cloudflare.com/ajax/libs/canvas-confetti/1.9.3/confetti.browser.min.js';
29
+
30
+ // 2. Map the remote asset to a virtual file named "my-confetti-engine.js"
31
+ const importSuccess = await vfs.importRemote('my-confetti-engine.js', remoteLibraryUrl, 'text/javascript');
52
32
 
53
- // Run the spin cycle as soon as the virtual document structure loads
54
- if (document.readyState === 'loading') {
55
- document.addEventListener('DOMContentLoaded', applySpinToText);
56
- } else {
57
- applySpinToText();
33
+ if (!importSuccess) {
34
+ console.error("Failed to fetch library from CDNJS.");
35
+ return;
58
36
  }
59
- `, 'text/javascript');
60
37
 
61
- // 3. Add the main index entry file using native, normal markup tags!
62
- vfs.add('workspace.html', `
38
+ // 3. Create the standard HTML layout referencing the newly mapped virtual file
39
+ vfs.add('index.html', `
63
40
  <!DOCTYPE html>
64
41
  <html>
65
42
  <head>
66
43
  <meta charset="UTF-8">
44
+ <title>CDNJS Virtualization Demo</title>
67
45
  <link rel="stylesheet" href="live_theme.css?vfs=true">
68
46
  </head>
69
47
  <body>
70
- <h2>Infrared Seamless Virtual Environment</h2>
71
- <p>This layout runs seamlessly inside an entirely virtual context.</p>
48
+ <h2>CDNJS Virtualization Success!</h2>
49
+ <p>The confetti script was loaded out of memory as a local same-origin asset.</p>
50
+
51
+ <script src="my-confetti-engine.js?vfs=true"></script>
72
52
  <script src="index.js?vfs=true"></script>
73
53
  </body>
74
54
  </html>
75
55
  `, 'text/html');
76
56
 
77
- // 4. Point the auto-generated viewport to the entry path!
57
+ // 4. Standard Background Theme Layout
58
+ vfs.add('live_theme.css', `
59
+ html, body { margin: 0; padding: 40px; height: 100%; font-family: monospace; background: #020617; color: #f8fafc; text-align: center; }
60
+ body { background: linear-gradient(-45deg, #1e1b4b, #311042, #0f172a) !important; color: #ffffff !important; }
61
+ h2 { color: #38bdf8; text-shadow: 0 0 10px rgba(56, 189, 248, 0.4); }
62
+ `, 'text/css');
63
+
64
+ // 5. Execution Script: Call the global function initialized by the CDNJS script
65
+ vfs.add('index.js', `
66
+ console.log("Launcher script running. Invoking confetti...");
67
+
68
+ // Ensure the library attached itself to the virtual window context safely
69
+ if (typeof window.confetti === 'function') {
70
+ // Fire an endless burst of celebratory confetti particles!
71
+ setInterval(() => {
72
+ window.confetti({
73
+ particleCount: 50,
74
+ spread: 60,
75
+ origin: { y: 0.6 }
76
+ });
77
+ }, 1500);
78
+ } else {
79
+ console.error("Confetti engine not found in virtual window global scope.");
80
+ }
81
+ `, 'text/javascript');
82
+
83
+ // 6. Point the fullscreen viewport to the directory root
78
84
  const viewport = document.getElementById('canvas-viewport');
79
85
  if (viewport) {
80
- viewport.src = 'workspace.html?vfs=true';
86
+ viewport.src = './?vfs=true';
81
87
  }
82
88
  }
83
89
 
84
- // Automatically bootstrap when document structure is verified
90
+ // Global invocation hook listener
85
91
  document.addEventListener('DOMContentLoaded', async () => {
86
- const ready = await window._vfsKernel.init();
87
- if (ready) {
92
+ const isReady = await window._vfsKernel.init();
93
+ if (isReady) {
88
94
  startDeveloperWorkspace();
89
95
  }
90
96
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vfsjs-test",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "",
5
5
  "main": "index.html",
6
6
  "scripts": {
package/sw.js CHANGED
@@ -1,33 +1,32 @@
1
- // sw.js - Version 1.0.8
1
+ // sw.js - Version 1.1.2 (Shadow Router)
2
2
  const vfsStorage = new Map();
3
3
 
4
- const defaultMimes = {
5
- 'js': 'text/javascript',
6
- 'css': 'text/css',
7
- 'html': 'text/html',
8
- 'json': 'application/json'
9
- };
10
-
11
4
  self.addEventListener('install', e => e.waitUntil(self.skipWaiting()));
12
5
  self.addEventListener('activate', e => e.waitUntil(self.clients.claim()));
13
6
 
14
7
  self.addEventListener('fetch', (event) => {
15
8
  const url = new URL(event.request.url);
9
+ let filename = url.pathname.split('/').pop().split('?')[0];
16
10
 
17
- // Strip paths and query parameters to get raw file names
18
- const filename = url.pathname.split('/').pop().split('?')[0];
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
+
19
17
  const isVfsExplicit = url.searchParams.get('vfs') === 'true';
20
18
 
21
- // Intercept if we have the file in memory OR if the developer explicitly tagged it
19
+ // Intercept if it's our target index or explicitly tagged
22
20
  if (vfsStorage.has(filename) || isVfsExplicit) {
23
21
  event.respondWith(
24
- // Use a short promise loop to wait if the asset hasn't finished writing to memory yet
25
22
  new Promise((resolve) => {
26
23
  const checkFile = () => {
27
24
  if (vfsStorage.has(filename)) {
28
25
  const fileData = vfsStorage.get(filename);
29
26
  const ext = filename.split('.').pop().toLowerCase();
30
- const contentType = fileData.mime || defaultMimes[ext] || 'application/octet-stream';
27
+
28
+ const mimeMatrix = { 'js': 'text/javascript', 'css': 'text/css', 'html': 'text/html' };
29
+ const contentType = fileData.mime || mimeMatrix[ext] || 'application/octet-stream';
31
30
 
32
31
  resolve(new Response(fileData.content, {
33
32
  status: 200,
@@ -38,8 +37,7 @@ self.addEventListener('fetch', (event) => {
38
37
  }
39
38
  }));
40
39
  } else {
41
- // Retry shortly if the network thread beat the main thread execution
42
- setTimeout(checkFile, 10);
40
+ setTimeout(checkFile, 5);
43
41
  }
44
42
  };
45
43
  checkFile();
@@ -49,20 +47,7 @@ self.addEventListener('fetch', (event) => {
49
47
  });
50
48
 
51
49
  self.addEventListener('message', (event) => {
52
- if (!event.data || !event.data.type) return;
53
-
54
- switch (event.data.type) {
55
- case 'VFS_WRITE':
56
- vfsStorage.set(event.data.filename, {
57
- content: event.data.content,
58
- mime: event.data.mime || null
59
- });
60
- break;
61
- case 'VFS_DELETE':
62
- vfsStorage.delete(event.data.filename);
63
- break;
64
- case 'VFS_CLEAR':
65
- vfsStorage.clear();
66
- break;
50
+ if (event.data && event.data.type === 'VFS_WRITE') {
51
+ vfsStorage.set(event.data.filename, { content: event.data.content, mime: event.data.mime });
67
52
  }
68
53
  });
package/vfsjs.js CHANGED
@@ -1,21 +1,21 @@
1
- // vfsjs.js - Automated Infrastructure Engine Core
1
+ // vfsjs.js - Version 1.2.0 Automated Unified Kernel
2
2
  (function() {
3
3
  const encoder = new TextEncoder();
4
4
 
5
5
  const engineCore = {
6
6
  async init() {
7
7
  try {
8
- // 1. Core Service Worker Registration
8
+ // 1. Establish background proxy thread interception
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. AUTOMATION UPGRADE: Enforce full-screen layout constraints on the main window
14
+ // 2. Structural Reset: Enforce full-screen boundary constraints on main window
15
15
  Object.assign(document.documentElement.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0' });
16
16
  Object.assign(document.body.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0', background: '#020617' });
17
17
 
18
- // 3. AUTOMATION UPGRADE: Create and mount the seamless borderless canvas iframe
18
+ // 3. Viewport Ingestion: Spawn the seamless full-window workspace canvas iframe
19
19
  const iframe = document.createElement('iframe');
20
20
  iframe.id = 'canvas-viewport';
21
21
  iframe.setAttribute('scrolling', 'no');
@@ -34,7 +34,7 @@
34
34
  document.body.appendChild(iframe);
35
35
  return true;
36
36
  } catch (err) {
37
- console.error("VFS Kernel Boot Failure:", err);
37
+ console.error("VFS Static Initialization Failure:", err);
38
38
  return false;
39
39
  }
40
40
  },
@@ -48,18 +48,6 @@
48
48
  mime: customMime
49
49
  });
50
50
  return true;
51
- },
52
-
53
- remove(filename) {
54
- if (!navigator.serviceWorker.controller) return false;
55
- navigator.serviceWorker.controller.postMessage({ type: 'VFS_DELETE', filename: filename });
56
- return true;
57
- },
58
-
59
- wipe() {
60
- if (!navigator.serviceWorker.controller) return false;
61
- navigator.serviceWorker.controller.postMessage({ type: 'VFS_CLEAR' });
62
- return true;
63
51
  }
64
52
  };
65
53