vfsjs-test 1.0.22 → 1.0.24
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.
- package/index.html +2 -0
- package/main.js +23 -13
- package/package.json +1 -1
- package/sw.js +54 -44
- package/vfsjs.js +27 -30
package/index.html
CHANGED
package/main.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
// main.js - Production
|
|
1
|
+
// main.js - Production Build Core Orchestrator
|
|
2
2
|
|
|
3
3
|
window.vfs = {
|
|
4
4
|
add(filename, contentString, customMime = null) {
|
|
5
5
|
return window._vfsKernel.write(filename, contentString, customMime);
|
|
6
6
|
},
|
|
7
|
-
|
|
8
7
|
async importRemote(localFilename, remoteUrl, customMime = null) {
|
|
9
8
|
try {
|
|
10
9
|
const response = await fetch(remoteUrl);
|
|
@@ -13,29 +12,40 @@ window.vfs = {
|
|
|
13
12
|
this.add(localFilename, text, customMime);
|
|
14
13
|
return true;
|
|
15
14
|
} catch (err) {
|
|
16
|
-
console.error(`[VFS Proxy Error]
|
|
15
|
+
console.error(`[VFS Proxy Error]`, err);
|
|
17
16
|
return false;
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
19
|
};
|
|
21
20
|
|
|
22
|
-
async function
|
|
23
|
-
// 1.
|
|
24
|
-
vfs.add('app.js', `
|
|
25
|
-
|
|
21
|
+
async function runProductionBuild() {
|
|
22
|
+
// 1. Seed assets safely into the worker environment
|
|
23
|
+
vfs.add('app.js', `
|
|
24
|
+
console.log("Application loop booted inside clean VFS space!");
|
|
25
|
+
if (typeof window.confetti === 'function') {
|
|
26
|
+
setInterval(() => {
|
|
27
|
+
window.confetti({ particleCount: 50, spread: 60 });
|
|
28
|
+
}, 2500);
|
|
29
|
+
}
|
|
30
|
+
`, 'text/javascript');
|
|
31
|
+
|
|
32
|
+
vfs.add('style.css', `
|
|
33
|
+
body { background: radial-gradient(circle, #1e1b4b, #020617) !important; color: #f8fafc !important; font-family: monospace; text-align: center; padding: 50px; }
|
|
34
|
+
h2 { color: #38bdf8; }
|
|
35
|
+
`, 'text/css');
|
|
26
36
|
|
|
27
|
-
// 2. Fetch
|
|
37
|
+
// 2. Fetch external dependencies smoothly
|
|
28
38
|
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
39
|
|
|
30
|
-
// 3.
|
|
40
|
+
// 3. Fire up the layout iframe viewport now that everything is safely registered
|
|
31
41
|
window._vfsKernel.openViewport();
|
|
32
42
|
}
|
|
33
43
|
|
|
34
|
-
//
|
|
44
|
+
// Verification initialization hook loop
|
|
35
45
|
(function verifyKernelAvailability() {
|
|
36
|
-
if (window._vfsKernel && navigator.serviceWorker.controller) {
|
|
37
|
-
|
|
46
|
+
if (window._vfsKernel && navigator.serviceWorker && navigator.serviceWorker.controller) {
|
|
47
|
+
runProductionBuild();
|
|
38
48
|
} else {
|
|
39
|
-
setTimeout(verifyKernelAvailability,
|
|
49
|
+
setTimeout(verifyKernelAvailability, 15);
|
|
40
50
|
}
|
|
41
51
|
})();
|
package/package.json
CHANGED
package/sw.js
CHANGED
|
@@ -1,53 +1,63 @@
|
|
|
1
|
-
// sw.js - Version
|
|
2
|
-
const vfsStorage = new Map();
|
|
1
|
+
// sw.js - Version 7.0.0 (Zero-Leak Network Interceptor)
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
self.addEventListener('activate', e => e.waitUntil(self.clients.claim()));
|
|
3
|
+
const virtualStorage = new Map();
|
|
6
4
|
|
|
5
|
+
self.addEventListener('install', (e) => self.skipWaiting());
|
|
6
|
+
self.addEventListener('activate', (e) => e.waitUntil(self.clients.claim()));
|
|
7
|
+
|
|
8
|
+
// Message handling pipeline for window memory synchronizations
|
|
9
|
+
self.addEventListener('message', (event) => {
|
|
10
|
+
if (event.data && event.data.type === 'VFS_WRITE') {
|
|
11
|
+
virtualStorage.set(event.data.filename, {
|
|
12
|
+
content: event.data.content, // Uint8Array binary format
|
|
13
|
+
mime: event.data.mime
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// The universal request routing core
|
|
7
19
|
self.addEventListener('fetch', (event) => {
|
|
8
20
|
const url = new URL(event.request.url);
|
|
9
|
-
let filename = url.pathname.split('/').pop().split('?')[0];
|
|
10
21
|
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (vfsStorage.has(filename)) {
|
|
25
|
-
const fileData = vfsStorage.get(filename);
|
|
26
|
-
const ext = filename.split('.').pop().toLowerCase();
|
|
27
|
-
|
|
28
|
-
const mimeMatrix = { 'js': 'text/javascript', 'css': 'text/css', 'html': 'text/html' };
|
|
29
|
-
const contentType = fileData.mime || mimeMatrix[ext] || 'application/octet-stream';
|
|
30
|
-
|
|
31
|
-
resolve(new Response(fileData.content, {
|
|
32
|
-
status: 200,
|
|
33
|
-
headers: {
|
|
34
|
-
'Content-Type': contentType,
|
|
35
|
-
'Access-Control-Allow-Origin': '*',
|
|
36
|
-
'X-Content-Type-Options': 'nosniff'
|
|
37
|
-
}
|
|
38
|
-
}));
|
|
39
|
-
} else {
|
|
40
|
-
setTimeout(checkFile, 5);
|
|
22
|
+
// Check if this request is explicitly targeting our virtual scope ecosystem
|
|
23
|
+
if (url.searchParams.get('vfs') === 'true' || url.href.includes('vfs=true')) {
|
|
24
|
+
const cleanFilename = url.pathname.split('/').pop() || 'index.html';
|
|
25
|
+
|
|
26
|
+
// Match against memory cache database maps
|
|
27
|
+
if (virtualStorage.has(cleanFilename)) {
|
|
28
|
+
const cachedAsset = virtualStorage.get(cleanFilename);
|
|
29
|
+
event.respondWith(
|
|
30
|
+
new Response(cachedAsset.content, {
|
|
31
|
+
status: 200,
|
|
32
|
+
headers: {
|
|
33
|
+
'Content-Type': cachedAsset.mime,
|
|
34
|
+
'X-Content-Type-Options': 'nosniff' // Pass strict parsing checks
|
|
41
35
|
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
36
|
+
})
|
|
37
|
+
);
|
|
38
|
+
} else {
|
|
39
|
+
// OPTION B CATCH-ALL: Banish unpkg network fallback crashes!
|
|
40
|
+
// If main.js hasn't populated a script yet, serve a valid empty fallback shell script/style
|
|
41
|
+
let fallbackBody = '';
|
|
42
|
+
let fallbackMime = 'text/plain';
|
|
48
43
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
44
|
+
if (cleanFilename.endsWith('.js')) {
|
|
45
|
+
fallbackBody = `console.warn("VFS Interceptor: Dynamic fallback stub active for ${cleanFilename}");`;
|
|
46
|
+
fallbackMime = 'text/javascript';
|
|
47
|
+
} else if (cleanFilename.endsWith('.css')) {
|
|
48
|
+
fallbackBody = `/* VFS Dynamic Style Fallback Stub */`;
|
|
49
|
+
fallbackMime = 'text/css';
|
|
50
|
+
} else if (cleanFilename.endsWith('.json')) {
|
|
51
|
+
fallbackBody = '{}';
|
|
52
|
+
fallbackMime = 'application/json';
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
event.respondWith(
|
|
56
|
+
new Response(fallbackBody, {
|
|
57
|
+
status: 200,
|
|
58
|
+
headers: { 'Content-Type': fallbackMime }
|
|
59
|
+
})
|
|
60
|
+
);
|
|
61
|
+
}
|
|
52
62
|
}
|
|
53
63
|
});
|
package/vfsjs.js
CHANGED
|
@@ -1,57 +1,54 @@
|
|
|
1
|
-
// vfsjs.js - Version
|
|
1
|
+
// vfsjs.js - Version 7.0.0 (Universal Service Worker Sandbox)
|
|
2
2
|
(function() {
|
|
3
3
|
const encoder = new TextEncoder();
|
|
4
4
|
|
|
5
5
|
const engineCore = {
|
|
6
6
|
async init() {
|
|
7
7
|
try {
|
|
8
|
-
// 1. Boot the
|
|
8
|
+
// 1. Boot up the background network interception 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
|
|
15
|
-
const
|
|
16
|
-
this.write('index.html',
|
|
17
|
-
|
|
18
|
-
// 3. Clear window layout & lock sizing boundaries
|
|
19
|
-
document.documentElement.innerHTML = '';
|
|
20
|
-
Object.assign(document.documentElement.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0' });
|
|
21
|
-
Object.assign(document.body.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0', background: '#020617' });
|
|
22
|
-
|
|
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);
|
|
14
|
+
// 2. Capture layout markup cleanly before UI shift
|
|
15
|
+
const rawHtml = document.documentElement.innerHTML;
|
|
16
|
+
this.write('index.html', `<!DOCTYPE html>\n<html>${rawHtml}</html>`, 'text/html');
|
|
31
17
|
|
|
18
|
+
console.log("[VFS Kernel] Core initialized. Communication channel open.");
|
|
32
19
|
return true;
|
|
33
20
|
} catch (err) {
|
|
34
|
-
console.error("VFS Kernel
|
|
21
|
+
console.error("VFS Kernel Boot Fault:", err);
|
|
35
22
|
return false;
|
|
36
23
|
}
|
|
37
24
|
},
|
|
38
25
|
|
|
39
|
-
// Called
|
|
26
|
+
// Called dynamically by main.js after your cache writes complete
|
|
40
27
|
openViewport() {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
28
|
+
console.log("[VFS Kernel] Deploying canvas sandboxed frame wrapper.");
|
|
29
|
+
|
|
30
|
+
// Re-enforce main window shell structures cleanly
|
|
31
|
+
document.body.style.margin = '0';
|
|
32
|
+
document.body.style.padding = '0';
|
|
33
|
+
document.body.style.overflow = 'hidden';
|
|
34
|
+
document.body.style.background = '#020617';
|
|
35
|
+
|
|
36
|
+
const iframe = document.createElement('iframe');
|
|
37
|
+
iframe.id = 'canvas-viewport';
|
|
38
|
+
Object.assign(iframe.style, {
|
|
39
|
+
position: 'fixed', 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
|
+
// Force execution routing directly inside our Service Worker scope zone
|
|
45
|
+
iframe.src = './index.html?vfs=true';
|
|
46
46
|
},
|
|
47
47
|
|
|
48
48
|
write(filename, contentString, customMime) {
|
|
49
49
|
if (!navigator.serviceWorker.controller) return false;
|
|
50
50
|
|
|
51
|
-
let cleanKey = filename.split('?')[0];
|
|
52
|
-
if (cleanKey.includes('/')) {
|
|
53
|
-
cleanKey = cleanKey.split('/').pop();
|
|
54
|
-
}
|
|
51
|
+
let cleanKey = filename.split('?')[0].split('/').pop();
|
|
55
52
|
|
|
56
53
|
if (!customMime) {
|
|
57
54
|
const ext = cleanKey.split('.').pop().toLowerCase();
|