vfsjs-test 1.0.21 → 1.0.22

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 +36 -24
  2. package/package.json +1 -1
  3. package/vfsjs.js +21 -21
package/main.js CHANGED
@@ -1,29 +1,41 @@
1
- // Inside main.js
1
+ // main.js - Production Asset Orchestrator
2
2
 
3
- async function startDeveloperWorkspace() {
4
- // 1. Fetch remote libraries, populate virtual files, etc.
5
- const remoteLibraryUrl = 'https://cdn.jsdelivr.net/npm/canvas-confetti@1.9.4/dist/confetti.browser.min.js';
6
- await vfs.importRemote('my-confetti-engine.js', remoteLibraryUrl, 'text/javascript');
3
+ window.vfs = {
4
+ add(filename, contentString, customMime = null) {
5
+ return window._vfsKernel.write(filename, contentString, customMime);
6
+ },
7
7
 
8
- // 2. Populate your script and style data maps into the active worker cache state
9
- vfs.add('app.js', `console.log("App script running natively inside virtualized layout context!");`, 'text/javascript');
10
- vfs.add('style.css', `body { background: #020617; color: #38bdf8; font-family: monospace; }`, 'text/css');
8
+ async importRemote(localFilename, remoteUrl, customMime = null) {
9
+ try {
10
+ const response = await fetch(remoteUrl);
11
+ if (!response.ok) throw new Error(`HTTP network error: ${response.status}`);
12
+ const text = await response.text();
13
+ this.add(localFilename, text, customMime);
14
+ return true;
15
+ } catch (err) {
16
+ console.error(`[VFS Proxy Error] Failed loading remote path:`, err);
17
+ return false;
18
+ }
19
+ }
20
+ };
21
+
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');
11
26
 
12
- // 3. CRITICAL: The VFS is loaded, call launch() to spawn the iframe safely!
13
- window._vfsKernel.launch();
27
+ // 2. Fetch remote modules
28
+ 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
+
30
+ // 3. CRITICAL: Everything is safely in memory. Signal the kernel to open the iframe viewport!
31
+ window._vfsKernel.openViewport();
14
32
  }
15
33
 
16
- // Global invocation hook listener
17
- document.addEventListener('DOMContentLoaded', async () => {
18
- // Loop interval ensures window._vfsKernel is instantiated and done setting up step 1
19
- const checker = setInterval(async () => {
20
- if (window._vfsKernel) {
21
- clearInterval(checker);
22
- // Wait for the service worker confirmation to pass back up
23
- const isReady = await navigator.serviceWorker.ready;
24
- if (isReady) {
25
- startDeveloperWorkspace();
26
- }
27
- }
28
- }, 10);
29
- });
34
+ // Polling initialization hook to bridge cleanly across asynchronous script loads
35
+ (function verifyKernelAvailability() {
36
+ if (window._vfsKernel && navigator.serviceWorker.controller) {
37
+ buildProductionApplication();
38
+ } else {
39
+ setTimeout(verifyKernelAvailability, 10);
40
+ }
41
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vfsjs-test",
3
- "version": "1.0.21",
3
+ "version": "1.0.22",
4
4
  "description": "",
5
5
  "main": "index.html",
6
6
  "scripts": {
package/vfsjs.js CHANGED
@@ -1,48 +1,48 @@
1
- // vfsjs.js - Version 4.0.0 (Race-Condition Proof Production Engine)
1
+ // vfsjs.js - Version 5.0.0 (Production Synchronization Engine)
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 Handshake
8
+ // 1. Boot the Service Worker 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 the physical file's raw HTML structure exactly as it is written
14
+ // 2. Capture raw HTML layout
15
15
  const developerRawHtml = `<!DOCTYPE html>\n<html>${document.documentElement.innerHTML}</html>`;
16
16
  this.write('index.html', developerRawHtml, 'text/html');
17
17
 
18
- // 3. Structural Reset: Wipe page visual nodes and lock outer body down solid
18
+ // 3. Clear window layout & lock sizing boundaries
19
19
  document.documentElement.innerHTML = '';
20
20
  Object.assign(document.documentElement.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0' });
21
21
  Object.assign(document.body.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0', background: '#020617' });
22
22
 
23
- console.log("[VFS Kernel] Stage 1 Ready: Core cached. Awaiting developer vfs.add() execution...");
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);
31
+
24
32
  return true;
25
33
  } catch (err) {
26
- console.error("VFS Core Initialization Failure:", err);
34
+ console.error("VFS Kernel Initialization Fault:", err);
27
35
  return false;
28
36
  }
29
37
  },
30
38
 
31
- // PHASE 2: Call this ONLY when files are completely mapped to safely spawn the iframe!
32
- launch() {
33
- if (document.getElementById('canvas-viewport')) return;
34
-
35
- console.log("[VFS Kernel] Stage 2 Triggered: All assets populated. Mounting secure viewport sandbox.");
36
- const iframe = document.createElement('iframe');
37
- iframe.id = 'canvas-viewport';
38
- Object.assign(iframe.style, {
39
- position: 'absolute', 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
- // Point to the virtual root route safely now that assets are loaded
45
- iframe.src = './?vfs=true';
39
+ // Called exclusively by main.js once all local/remote files are committed to memory
40
+ 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
+ }
46
46
  },
47
47
 
48
48
  write(filename, contentString, customMime) {