vfsjs-test 1.0.22 → 1.0.23

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 +27 -11
  2. package/package.json +1 -1
  3. package/vfsjs.js +45 -34
package/main.js CHANGED
@@ -1,39 +1,55 @@
1
- // main.js - Production Asset Orchestrator
1
+ // main.js - Production Build Wrapper
2
2
 
3
3
  window.vfs = {
4
4
  add(filename, contentString, customMime = null) {
5
- return window._vfsKernel.write(filename, contentString, customMime);
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;
6
10
  },
7
11
 
8
12
  async importRemote(localFilename, remoteUrl, customMime = null) {
9
13
  try {
10
14
  const response = await fetch(remoteUrl);
11
- if (!response.ok) throw new Error(`HTTP network error: ${response.status}`);
15
+ if (!response.ok) throw new Error(`HTTP Fault: ${response.status}`);
12
16
  const text = await response.text();
13
17
  this.add(localFilename, text, customMime);
14
18
  return true;
15
19
  } catch (err) {
16
- console.error(`[VFS Proxy Error] Failed loading remote path:`, err);
20
+ console.error(`[VFS Proxy Error]`, err);
17
21
  return false;
18
22
  }
19
23
  }
20
24
  };
21
25
 
22
26
  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');
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.");
36
+ }
37
+ `, 'text/javascript');
38
+
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');
26
43
 
27
- // 2. Fetch remote modules
44
+ // 2. Fetch CDNJS/jsDelivr packages that bypass scope paths safely
28
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');
29
46
 
30
- // 3. CRITICAL: Everything is safely in memory. Signal the kernel to open the iframe viewport!
47
+ // 3. Compile and open viewport
31
48
  window._vfsKernel.openViewport();
32
49
  }
33
50
 
34
- // Polling initialization hook to bridge cleanly across asynchronous script loads
35
51
  (function verifyKernelAvailability() {
36
- if (window._vfsKernel && navigator.serviceWorker.controller) {
52
+ if (window._vfsKernel) {
37
53
  buildProductionApplication();
38
54
  } else {
39
55
  setTimeout(verifyKernelAvailability, 10);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vfsjs-test",
3
- "version": "1.0.22",
3
+ "version": "1.0.23",
4
4
  "description": "",
5
5
  "main": "index.html",
6
6
  "scripts": {
package/vfsjs.js CHANGED
@@ -1,26 +1,24 @@
1
- // vfsjs.js - Version 5.0.0 (Production Synchronization Engine)
1
+ // vfsjs.js - Version 6.0.0 (Zero-Network Tag Inline Engine)
2
2
  (function() {
3
- const encoder = new TextEncoder();
4
-
5
3
  const engineCore = {
6
4
  async init() {
7
5
  try {
8
- // 1. Boot the Service Worker thread
6
+ // 1. Boot Service Worker for the root frame route interception if needed
9
7
  await navigator.serviceWorker.register('./sw.js');
10
8
  if (!navigator.serviceWorker.controller) {
11
9
  await new Promise(r => navigator.serviceWorker.addEventListener('controllerchange', r, { once: true }));
12
10
  }
13
11
 
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');
12
+ // 2. Capture the developer's original raw HTML string structure
13
+ const rawHtml = document.documentElement.innerHTML;
14
+ window._vfsRawTemplate = `<!DOCTYPE html>\n<html>${rawHtml}</html>`;
17
15
 
18
- // 3. Clear window layout & lock sizing boundaries
16
+ // 3. Clear parent UI layout instantly
19
17
  document.documentElement.innerHTML = '';
20
18
  Object.assign(document.documentElement.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0' });
21
19
  Object.assign(document.body.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0', background: '#020617' });
22
20
 
23
- // 4. Create the iframe canvas, but leave it blank (src="") so it doesn't request files yet!
21
+ // 4. Create the pristine layout iframe container
24
22
  const iframe = document.createElement('iframe');
25
23
  iframe.id = 'canvas-viewport';
26
24
  Object.assign(iframe.style, {
@@ -31,44 +29,57 @@
31
29
 
32
30
  return true;
33
31
  } catch (err) {
34
- console.error("VFS Kernel Initialization Fault:", err);
32
+ console.error("VFS Critical Bootstrap Failure:", err);
35
33
  return false;
36
34
  }
37
35
  },
38
36
 
39
- // Called exclusively by main.js once all local/remote files are committed to memory
37
+ // Called by main.js after vfs.add loops complete
40
38
  openViewport() {
41
39
  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
- }
46
- },
40
+ if (!iframe) return;
47
41
 
48
- write(filename, contentString, customMime) {
49
- if (!navigator.serviceWorker.controller) return false;
50
-
51
- let cleanKey = filename.split('?')[0];
52
- if (cleanKey.includes('/')) {
53
- cleanKey = cleanKey.split('/').pop();
54
- }
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');
55
45
 
56
- if (!customMime) {
57
- const ext = cleanKey.split('.').pop().toLowerCase();
58
- const mimeMatrix = { 'js': 'text/javascript', 'css': 'text/css', 'html': 'text/html', 'json': 'application/json' };
59
- customMime = mimeMatrix[ext] || 'application/octet-stream';
60
- }
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
+ }
57
+ });
61
58
 
62
- navigator.serviceWorker.controller.postMessage({
63
- type: 'VFS_WRITE',
64
- filename: cleanKey,
65
- content: encoder.encode(contentString),
66
- mime: customMime
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
+ }
67
70
  });
68
- return true;
71
+
72
+ // 3. Convert modified dynamic DOM tree back to a string bundle
73
+ const compilationOutput = `<!DOCTYPE html>\n<html>${doc.documentElement.innerHTML}</html>`;
74
+
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.");
69
78
  }
70
79
  };
71
80
 
81
+ // Shared internal key store memory map allocation
82
+ window._vfsVirtualCache = {};
72
83
  window._vfsKernel = engineCore;
73
84
 
74
85
  if (document.readyState === 'loading') {