vfsjs-test 1.0.23 → 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 +16 -22
- package/package.json +1 -1
- package/sw.js +54 -44
- package/vfsjs.js +42 -56
package/index.html
CHANGED
package/main.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
// main.js - Production Build
|
|
1
|
+
// main.js - Production Build Core Orchestrator
|
|
2
2
|
|
|
3
3
|
window.vfs = {
|
|
4
4
|
add(filename, contentString, customMime = null) {
|
|
5
|
-
|
|
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;
|
|
5
|
+
return window._vfsKernel.write(filename, contentString, customMime);
|
|
10
6
|
},
|
|
11
|
-
|
|
12
7
|
async importRemote(localFilename, remoteUrl, customMime = null) {
|
|
13
8
|
try {
|
|
14
9
|
const response = await fetch(remoteUrl);
|
|
15
|
-
if (!response.ok) throw new Error(`HTTP
|
|
10
|
+
if (!response.ok) throw new Error(`HTTP network error: ${response.status}`);
|
|
16
11
|
const text = await response.text();
|
|
17
12
|
this.add(localFilename, text, customMime);
|
|
18
13
|
return true;
|
|
@@ -23,35 +18,34 @@ window.vfs = {
|
|
|
23
18
|
}
|
|
24
19
|
};
|
|
25
20
|
|
|
26
|
-
async function
|
|
27
|
-
// 1.
|
|
21
|
+
async function runProductionBuild() {
|
|
22
|
+
// 1. Seed assets safely into the worker environment
|
|
28
23
|
vfs.add('app.js', `
|
|
29
|
-
console.log("
|
|
24
|
+
console.log("Application loop booted inside clean VFS space!");
|
|
30
25
|
if (typeof window.confetti === 'function') {
|
|
31
26
|
setInterval(() => {
|
|
32
|
-
window.confetti({ particleCount:
|
|
33
|
-
},
|
|
34
|
-
} else {
|
|
35
|
-
console.error("Confetti script missing from global iframe execution scope.");
|
|
27
|
+
window.confetti({ particleCount: 50, spread: 60 });
|
|
28
|
+
}, 2500);
|
|
36
29
|
}
|
|
37
30
|
`, 'text/javascript');
|
|
38
31
|
|
|
39
32
|
vfs.add('style.css', `
|
|
40
|
-
body { background: #020617 !important; color: #
|
|
41
|
-
h2 {
|
|
33
|
+
body { background: radial-gradient(circle, #1e1b4b, #020617) !important; color: #f8fafc !important; font-family: monospace; text-align: center; padding: 50px; }
|
|
34
|
+
h2 { color: #38bdf8; }
|
|
42
35
|
`, 'text/css');
|
|
43
36
|
|
|
44
|
-
// 2. Fetch
|
|
37
|
+
// 2. Fetch external dependencies smoothly
|
|
45
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');
|
|
46
39
|
|
|
47
|
-
// 3.
|
|
40
|
+
// 3. Fire up the layout iframe viewport now that everything is safely registered
|
|
48
41
|
window._vfsKernel.openViewport();
|
|
49
42
|
}
|
|
50
43
|
|
|
44
|
+
// Verification initialization hook loop
|
|
51
45
|
(function verifyKernelAvailability() {
|
|
52
|
-
if (window._vfsKernel) {
|
|
53
|
-
|
|
46
|
+
if (window._vfsKernel && navigator.serviceWorker && navigator.serviceWorker.controller) {
|
|
47
|
+
runProductionBuild();
|
|
54
48
|
} else {
|
|
55
|
-
setTimeout(verifyKernelAvailability,
|
|
49
|
+
setTimeout(verifyKernelAvailability, 15);
|
|
56
50
|
}
|
|
57
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,85 +1,71 @@
|
|
|
1
|
-
// vfsjs.js - Version
|
|
1
|
+
// vfsjs.js - Version 7.0.0 (Universal Service Worker Sandbox)
|
|
2
2
|
(function() {
|
|
3
|
+
const encoder = new TextEncoder();
|
|
4
|
+
|
|
3
5
|
const engineCore = {
|
|
4
6
|
async init() {
|
|
5
7
|
try {
|
|
6
|
-
// 1. Boot
|
|
8
|
+
// 1. Boot up the background network interception thread
|
|
7
9
|
await navigator.serviceWorker.register('./sw.js');
|
|
8
10
|
if (!navigator.serviceWorker.controller) {
|
|
9
11
|
await new Promise(r => navigator.serviceWorker.addEventListener('controllerchange', r, { once: true }));
|
|
10
12
|
}
|
|
11
13
|
|
|
12
|
-
// 2. Capture
|
|
14
|
+
// 2. Capture layout markup cleanly before UI shift
|
|
13
15
|
const rawHtml = document.documentElement.innerHTML;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
// 3. Clear parent UI layout instantly
|
|
17
|
-
document.documentElement.innerHTML = '';
|
|
18
|
-
Object.assign(document.documentElement.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0' });
|
|
19
|
-
Object.assign(document.body.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0', background: '#020617' });
|
|
20
|
-
|
|
21
|
-
// 4. Create the pristine layout iframe container
|
|
22
|
-
const iframe = document.createElement('iframe');
|
|
23
|
-
iframe.id = 'canvas-viewport';
|
|
24
|
-
Object.assign(iframe.style, {
|
|
25
|
-
position: 'absolute', top: '0', left: '0', width: '100%', height: '100%',
|
|
26
|
-
border: 'none', margin: '0', padding: '0', zIndex: '999999'
|
|
27
|
-
});
|
|
28
|
-
document.body.appendChild(iframe);
|
|
16
|
+
this.write('index.html', `<!DOCTYPE html>\n<html>${rawHtml}</html>`, 'text/html');
|
|
29
17
|
|
|
18
|
+
console.log("[VFS Kernel] Core initialized. Communication channel open.");
|
|
30
19
|
return true;
|
|
31
20
|
} catch (err) {
|
|
32
|
-
console.error("VFS
|
|
21
|
+
console.error("VFS Kernel Boot Fault:", err);
|
|
33
22
|
return false;
|
|
34
23
|
}
|
|
35
24
|
},
|
|
36
25
|
|
|
37
|
-
// Called by main.js after
|
|
26
|
+
// Called dynamically by main.js after your cache writes complete
|
|
38
27
|
openViewport() {
|
|
39
|
-
|
|
40
|
-
|
|
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';
|
|
41
35
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
}
|
|
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'
|
|
57
41
|
});
|
|
42
|
+
document.body.appendChild(iframe);
|
|
58
43
|
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
}
|
|
70
|
-
});
|
|
44
|
+
// Force execution routing directly inside our Service Worker scope zone
|
|
45
|
+
iframe.src = './index.html?vfs=true';
|
|
46
|
+
},
|
|
71
47
|
|
|
72
|
-
|
|
73
|
-
|
|
48
|
+
write(filename, contentString, customMime) {
|
|
49
|
+
if (!navigator.serviceWorker.controller) return false;
|
|
50
|
+
|
|
51
|
+
let cleanKey = filename.split('?')[0].split('/').pop();
|
|
74
52
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
53
|
+
if (!customMime) {
|
|
54
|
+
const ext = cleanKey.split('.').pop().toLowerCase();
|
|
55
|
+
const mimeMatrix = { 'js': 'text/javascript', 'css': 'text/css', 'html': 'text/html', 'json': 'application/json' };
|
|
56
|
+
customMime = mimeMatrix[ext] || 'application/octet-stream';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
navigator.serviceWorker.controller.postMessage({
|
|
60
|
+
type: 'VFS_WRITE',
|
|
61
|
+
filename: cleanKey,
|
|
62
|
+
content: encoder.encode(contentString),
|
|
63
|
+
mime: customMime
|
|
64
|
+
});
|
|
65
|
+
return true;
|
|
78
66
|
}
|
|
79
67
|
};
|
|
80
68
|
|
|
81
|
-
// Shared internal key store memory map allocation
|
|
82
|
-
window._vfsVirtualCache = {};
|
|
83
69
|
window._vfsKernel = engineCore;
|
|
84
70
|
|
|
85
71
|
if (document.readyState === 'loading') {
|