vfsjs-test 1.0.19 → 1.0.20

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 (2) hide show
  1. package/package.json +1 -1
  2. package/vfsjs.js +20 -28
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vfsjs-test",
3
- "version": "1.0.19",
3
+ "version": "1.0.20",
4
4
  "description": "",
5
5
  "main": "index.html",
6
6
  "scripts": {
package/vfsjs.js CHANGED
@@ -1,42 +1,28 @@
1
- // vfsjs.js - Version 2.1.0 (Full Production DOM Hijacker Engine)
1
+ // vfsjs.js - Version 3.0.0 (Universal Production Routing 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 Registration Handshake
8
+ // 1. Register the Service Worker
9
9
  await navigator.serviceWorker.register('./sw.js');
10
+
11
+ // Ensure the worker is actively controlling the page before proceeding
10
12
  if (!navigator.serviceWorker.controller) {
11
13
  await new Promise(r => navigator.serviceWorker.addEventListener('controllerchange', r, { once: true }));
12
14
  }
13
15
 
14
- // 2. CRITICAL FIX: Extract sub-resources before wiping the page structure
15
- // We parse scripts and stylesheets to pre-populate empty placeholders or fetch local references
16
- const scripts = Array.from(document.querySelectorAll('script[src*="vfs=true"]'));
17
- const links = Array.from(document.querySelectorAll('link[rel="stylesheet"][href*="vfs=true"]'));
18
-
19
- // Seed baseline virtual assets so the iframe doesn't hit unpkg 404/MIME walls
20
- scripts.forEach(script => {
21
- const cleanUrl = script.getAttribute('src').split('?')[0];
22
- this.write(cleanUrl, `console.log("VFS: Virtual stub active for ${cleanUrl}");`, 'text/javascript');
23
- });
24
-
25
- links.forEach(link => {
26
- const cleanUrl = link.getAttribute('href').split('?')[0];
27
- this.write(cleanUrl, `/* VFS: Virtual stylesheet stub active for ${cleanUrl} */`, 'text/css');
28
- });
29
-
30
- // 3. Capture the developer's raw markup setup
16
+ // 2. Capture the physical file's raw HTML structure exactly as it is
31
17
  const developerRawHtml = `<!DOCTYPE html>\n<html>${document.documentElement.innerHTML}</html>`;
32
18
  this.write('index.html', developerRawHtml, 'text/html');
33
19
 
34
- // 4. Structural Reset: Enforce absolute zero borders and scroll-locks on parent layout
20
+ // 3. Clear out the main window and lock down body dimensions
35
21
  document.documentElement.innerHTML = '';
36
22
  Object.assign(document.documentElement.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0' });
37
23
  Object.assign(document.body.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0', background: '#020617' });
38
24
 
39
- // 5. Mount the Seamless Full-Window Viewport Canvas
25
+ // 4. Mount the clean, scrollable iframe viewport canvas
40
26
  const iframe = document.createElement('iframe');
41
27
  iframe.id = 'canvas-viewport';
42
28
  Object.assign(iframe.style, {
@@ -45,12 +31,12 @@
45
31
  });
46
32
  document.body.appendChild(iframe);
47
33
 
48
- // 6. Direct the iframe context to open the virtual index route natively
34
+ // 5. Point the canvas to the virtual root directory
49
35
  iframe.src = './?vfs=true';
50
36
 
51
37
  return true;
52
38
  } catch (err) {
53
- console.error("VFS Hijacker Core Initialization Failure:", err);
39
+ console.error("VFS Universal Core Initialization Failure:", err);
54
40
  return false;
55
41
  }
56
42
  },
@@ -58,16 +44,22 @@
58
44
  write(filename, contentString, customMime) {
59
45
  if (!navigator.serviceWorker.controller) return false;
60
46
 
61
- // Auto-detect simple extension MIME variants if left blank
47
+ // Extract a clean relative filename path if an absolute or query-string URL slips in
48
+ let cleanKey = filename.split('?')[0];
49
+ if (cleanKey.includes('/')) {
50
+ cleanKey = cleanKey.split('/').pop();
51
+ }
52
+
53
+ // Auto-detect basic mime types if not provided
62
54
  if (!customMime) {
63
- const ext = filename.split('.').pop().toLowerCase();
64
- const mimeMatrix = { 'js': 'text/javascript', 'css': 'text/css', 'html': 'text/html' };
55
+ const ext = cleanKey.split('.').pop().toLowerCase();
56
+ const mimeMatrix = { 'js': 'text/javascript', 'css': 'text/css', 'html': 'text/html', 'json': 'application/json' };
65
57
  customMime = mimeMatrix[ext] || 'application/octet-stream';
66
58
  }
67
59
 
68
60
  navigator.serviceWorker.controller.postMessage({
69
61
  type: 'VFS_WRITE',
70
- filename: filename,
62
+ filename: cleanKey,
71
63
  content: encoder.encode(contentString),
72
64
  mime: customMime
73
65
  });
@@ -77,7 +69,7 @@
77
69
 
78
70
  window._vfsKernel = engineCore;
79
71
 
80
- // Trigger orchestration hook automatically when the structural baseline DOM is parsed
72
+ // Execute immediately or when DOM structural elements are ready
81
73
  if (document.readyState === 'loading') {
82
74
  document.addEventListener('DOMContentLoaded', () => engineCore.init());
83
75
  } else {