vfsjs-test 1.0.18 → 1.0.19

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 +40 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vfsjs-test",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "description": "",
5
5
  "main": "index.html",
6
6
  "scripts": {
package/vfsjs.js CHANGED
@@ -1,29 +1,42 @@
1
- // vfsjs.js - Version 2.0.0 (DOM Hijacker Core)
1
+ // vfsjs.js - Version 2.1.0 (Full Production DOM Hijacker 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. Establish background proxy thread interception
8
+ // 1. Core Service Worker Registration Handshake
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. HIJACK STEP: Capture the exact raw HTML code the developer wrote on the page
15
- // We wrap it back into a standard root <html> tag structure
16
- const developerRawHtml = `<!DOCTYPE html>\n<html>${document.documentElement.innerHTML}</html>`;
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
+ });
17
29
 
18
- // 3. Commit their real file markup into the Virtual File System instantly
30
+ // 3. Capture the developer's raw markup setup
31
+ const developerRawHtml = `<!DOCTYPE html>\n<html>${document.documentElement.innerHTML}</html>`;
19
32
  this.write('index.html', developerRawHtml, 'text/html');
20
33
 
21
- // 4. Structural Reset: Wipe the main window clear and lock it down
34
+ // 4. Structural Reset: Enforce absolute zero borders and scroll-locks on parent layout
22
35
  document.documentElement.innerHTML = '';
23
36
  Object.assign(document.documentElement.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0' });
24
37
  Object.assign(document.body.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0', background: '#020617' });
25
38
 
26
- // 5. Spawn the seamless canvas iframe over the blank screen
39
+ // 5. Mount the Seamless Full-Window Viewport Canvas
27
40
  const iframe = document.createElement('iframe');
28
41
  iframe.id = 'canvas-viewport';
29
42
  Object.assign(iframe.style, {
@@ -32,20 +45,31 @@
32
45
  });
33
46
  document.body.appendChild(iframe);
34
47
 
35
- // 6. Point the canvas to our newly virtualized file route!
48
+ // 6. Direct the iframe context to open the virtual index route natively
36
49
  iframe.src = './?vfs=true';
37
50
 
38
51
  return true;
39
52
  } catch (err) {
40
- console.error("VFS Hijacker Core Failure:", err);
53
+ console.error("VFS Hijacker Core Initialization Failure:", err);
41
54
  return false;
42
55
  }
43
56
  },
44
57
 
45
58
  write(filename, contentString, customMime) {
46
59
  if (!navigator.serviceWorker.controller) return false;
60
+
61
+ // Auto-detect simple extension MIME variants if left blank
62
+ if (!customMime) {
63
+ const ext = filename.split('.').pop().toLowerCase();
64
+ const mimeMatrix = { 'js': 'text/javascript', 'css': 'text/css', 'html': 'text/html' };
65
+ customMime = mimeMatrix[ext] || 'application/octet-stream';
66
+ }
67
+
47
68
  navigator.serviceWorker.controller.postMessage({
48
- type: 'VFS_WRITE', filename: filename, content: encoder.encode(contentString), mime: customMime
69
+ type: 'VFS_WRITE',
70
+ filename: filename,
71
+ content: encoder.encode(contentString),
72
+ mime: customMime
49
73
  });
50
74
  return true;
51
75
  }
@@ -53,8 +77,10 @@
53
77
 
54
78
  window._vfsKernel = engineCore;
55
79
 
56
- // AUTOMATION: Run the hijack sequence as soon as the DOM tree is structured
57
- document.addEventListener('DOMContentLoaded', () => {
80
+ // Trigger orchestration hook automatically when the structural baseline DOM is parsed
81
+ if (document.readyState === 'loading') {
82
+ document.addEventListener('DOMContentLoaded', () => engineCore.init());
83
+ } else {
58
84
  engineCore.init();
59
- });
85
+ }
60
86
  })();