vfsjs-test 1.0.28 → 1.0.29
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/main.js +35 -50
- package/package.json +1 -1
- package/vfsjs.js +95 -54
package/main.js
CHANGED
|
@@ -1,77 +1,62 @@
|
|
|
1
1
|
// main.js - Production Build Core Orchestrator
|
|
2
2
|
|
|
3
3
|
window.vfs = {
|
|
4
|
-
add(filename, contentString
|
|
5
|
-
|
|
4
|
+
add(filename, contentString) {
|
|
5
|
+
window._vfsKernel.write(filename, contentString);
|
|
6
6
|
},
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const response = await fetch(remoteUrl);
|
|
10
|
-
if (!response.ok) throw new Error(`HTTP network error: ${response.status}`);
|
|
11
|
-
const text = await response.text();
|
|
12
|
-
this.add(localFilename, text, customMime);
|
|
13
|
-
return true;
|
|
14
|
-
} catch (err) {
|
|
15
|
-
console.error(`[VFS Proxy Error]`, err);
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
7
|
+
importRemote(remoteUrl) {
|
|
8
|
+
window._vfsKernel.pushRemoteScript(remoteUrl);
|
|
18
9
|
}
|
|
19
10
|
};
|
|
20
11
|
|
|
21
|
-
|
|
22
|
-
//
|
|
23
|
-
|
|
12
|
+
function runProductionBuild() {
|
|
13
|
+
// Stage third-party framework asset links directly
|
|
14
|
+
vfs.importRemote('https://cdn.jsdelivr.net/npm/canvas-confetti@1.9.4/dist/confetti.browser.min.js');
|
|
24
15
|
|
|
25
|
-
//
|
|
16
|
+
// Register application code logic structures
|
|
26
17
|
vfs.add('app.js', `
|
|
27
|
-
console.log("Application loop booted inside clean VFS
|
|
18
|
+
console.log("Application loop booted inside clean isolated VFS Space!");
|
|
28
19
|
|
|
29
|
-
document.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
20
|
+
const container = document.createElement('div');
|
|
21
|
+
container.className = 'js-card';
|
|
22
|
+
container.innerHTML = '<h3>Pure Handshake Isolation Live</h3><p>Zero Service Worker race conditions. 100% stable execution context.</p>';
|
|
23
|
+
document.body.appendChild(container);
|
|
24
|
+
|
|
25
|
+
const button = document.createElement('button');
|
|
26
|
+
button.id = 'action-btn';
|
|
27
|
+
button.innerText = 'Trigger Confetti';
|
|
28
|
+
container.appendChild(button);
|
|
29
|
+
|
|
30
|
+
button.addEventListener('click', () => {
|
|
31
|
+
if (typeof window.confetti === 'function') {
|
|
32
|
+
window.confetti({ particleCount: 100, spread: 70, origin: { y: 0.6 } });
|
|
33
|
+
console.log("[VFS Runtime] Confetti burst executed smoothly.");
|
|
34
|
+
} else {
|
|
35
|
+
console.error("[VFS Runtime Error] Confetti module reference missing on execution thread.");
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
const button = document.createElement('button');
|
|
39
|
-
button.id = 'action-btn';
|
|
40
|
-
button.innerText = 'Trigger Confetti';
|
|
41
|
-
container.appendChild(button);
|
|
42
|
-
|
|
43
|
-
// Robust polling wrapper to guarantee framework availability on click
|
|
44
|
-
button.addEventListener('click', () => {
|
|
45
|
-
const targetWindow = window.parent.vfs ? window.parent : window;
|
|
46
|
-
if (typeof targetWindow.confetti === 'function') {
|
|
47
|
-
targetWindow.confetti({ particleCount: 100, spread: 70, origin: { y: 0.6 } });
|
|
48
|
-
} else if (typeof window.confetti === 'function') {
|
|
49
|
-
window.confetti({ particleCount: 100, spread: 70, origin: { y: 0.6 } });
|
|
50
|
-
} else {
|
|
51
|
-
console.error("Confetti fallback execution error: Reference missing.");
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
37
|
});
|
|
55
|
-
|
|
38
|
+
`);
|
|
56
39
|
|
|
40
|
+
// Register explicit application presentation rules
|
|
57
41
|
vfs.add('style.css', `
|
|
58
42
|
body { background: #020617; color: #f8fafc; font-family: system-ui, sans-serif; text-align: center; padding: 50px; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 80vh; margin: 0; }
|
|
59
43
|
h1 { color: #38bdf8; font-size: 2.5rem; }
|
|
60
|
-
p { color: #94a3b8;
|
|
61
|
-
.js-card { background: #0f172a; border: 1px solid #1e293b; padding: 25px; border-radius: 12px; max-width: 400px; margin-top: 20px; }
|
|
44
|
+
p { color: #94a3b8; }
|
|
45
|
+
.js-card { background: #0f172a; border: 1px solid #1e293b; padding: 25px; border-radius: 12px; max-width: 400px; margin-top: 20px; box-shadow: 0 4px 20px rgba(0,0,0,0.5); }
|
|
62
46
|
.js-card h3 { color: #34d399; margin-top: 0; }
|
|
63
|
-
button { background: #38bdf8; color: #020617; border: none; padding: 12px 24px; font-weight: 600; border-radius: 6px; cursor: pointer; margin-top: 15px; }
|
|
47
|
+
button { background: #38bdf8; color: #020617; border: none; padding: 12px 24px; font-weight: 600; border-radius: 6px; cursor: pointer; margin-top: 15px; font-size: 14px; }
|
|
64
48
|
button:hover { background: #7dd3fc; }
|
|
65
|
-
|
|
49
|
+
`);
|
|
66
50
|
|
|
67
|
-
//
|
|
51
|
+
// Deploy the viewport framework
|
|
68
52
|
window._vfsKernel.openViewport();
|
|
69
53
|
}
|
|
70
54
|
|
|
55
|
+
// Verification block loop execution
|
|
71
56
|
(function verifyKernelAvailability() {
|
|
72
|
-
if (window._vfsKernel
|
|
57
|
+
if (window._vfsKernel) {
|
|
73
58
|
runProductionBuild();
|
|
74
59
|
} else {
|
|
75
|
-
setTimeout(verifyKernelAvailability,
|
|
60
|
+
setTimeout(verifyKernelAvailability, 10);
|
|
76
61
|
}
|
|
77
62
|
})();
|
package/package.json
CHANGED
package/vfsjs.js
CHANGED
|
@@ -1,81 +1,122 @@
|
|
|
1
|
-
// vfsjs.js - Version
|
|
1
|
+
// vfsjs.js - Version 14.0.0 (Pure Handshake Messaging Kernel)
|
|
2
2
|
(function() {
|
|
3
|
+
// If somehow executed inside a frame, self-destruct immediately
|
|
3
4
|
if (window.self !== window.top) return;
|
|
4
5
|
|
|
5
|
-
const
|
|
6
|
+
const vfsMemory = {
|
|
7
|
+
'index.html': '',
|
|
8
|
+
'app.js': '',
|
|
9
|
+
'style.css': '',
|
|
10
|
+
'remote_scripts': []
|
|
11
|
+
};
|
|
6
12
|
|
|
7
13
|
const engineCore = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
console.warn(
|
|
11
|
-
"%c[VFS Kernel] NOTICE: Any 'MIME type text/plain' or 'NS_ERROR_CORRUPTED_CONTENT' logs above are expected Phase-1 browser artifacts. The engine gracefully isolates them.",
|
|
12
|
-
"font-weight: bold; font-size: 11px;"
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
await navigator.serviceWorker.register('./sw.js');
|
|
17
|
-
if (!navigator.serviceWorker.controller) {
|
|
18
|
-
await new Promise(r => navigator.serviceWorker.addEventListener('controllerchange', r, { once: true }));
|
|
19
|
-
}
|
|
14
|
+
init() {
|
|
15
|
+
console.log("%c[VFS Kernel] Initializing Pure Handshake Engine...", "color: #38bdf8; font-weight: bold;");
|
|
20
16
|
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
// 1. Capture the physical HTML content written on the server file
|
|
18
|
+
let rawHtml = document.documentElement.innerHTML;
|
|
23
19
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
// Strip out the host infrastructure scripts so they don't get sent to the iframe
|
|
21
|
+
rawHtml = rawHtml.replace(/<script\s+src="vfsjs\.js"><\/script>/gi, '');
|
|
22
|
+
rawHtml = rawHtml.replace(/<script\s+src="main\.js"><\/script>/gi, '');
|
|
23
|
+
vfsMemory['index.html'] = rawHtml;
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
// 2. Wipe parent window clean immediately (No lookahead pre-parser network leaks!)
|
|
26
|
+
document.documentElement.innerHTML = '<head><meta charset="UTF-8"><title>VFS Execution Shell</title></head><body></body>';
|
|
27
|
+
|
|
28
|
+
Object.assign(document.documentElement.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0' });
|
|
29
|
+
Object.assign(document.body.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0', background: '#020617' });
|
|
33
30
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
// 3. Listen for the sandboxed iframe asking for its application bundle
|
|
32
|
+
window.addEventListener('message', (event) => {
|
|
33
|
+
if (event.data && event.data.type === 'VFS_FRAME_READY') {
|
|
34
|
+
const iframeWindow = document.getElementById('canvas-viewport').contentWindow;
|
|
35
|
+
iframeWindow.postMessage({
|
|
36
|
+
type: 'VFS_DELIVER_PAYLOAD',
|
|
37
|
+
payload: vfsMemory
|
|
38
|
+
}, '*');
|
|
39
|
+
}
|
|
40
|
+
});
|
|
40
41
|
},
|
|
41
42
|
|
|
42
43
|
openViewport() {
|
|
43
|
-
console.log("[VFS Kernel] Spawning
|
|
44
|
+
console.log("[VFS Kernel] Spawning blank, secure canvas environment.");
|
|
45
|
+
|
|
44
46
|
const iframe = document.createElement('iframe');
|
|
45
47
|
iframe.id = 'canvas-viewport';
|
|
46
48
|
Object.assign(iframe.style, {
|
|
47
49
|
position: 'fixed', top: '0', left: '0', width: '100%', height: '100%',
|
|
48
50
|
border: 'none', margin: '0', padding: '0', zIndex: '999999', background: '#020617'
|
|
49
51
|
});
|
|
52
|
+
|
|
50
53
|
document.body.appendChild(iframe);
|
|
51
|
-
iframe.src = './index.html?vfs=true';
|
|
52
|
-
},
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
// Construct an entirely self-contained runtime client inside the iframe
|
|
56
|
+
// It boots up, asks the parent for the virtual files, and executes them cleanly
|
|
57
|
+
const bootloaderScript = `
|
|
58
|
+
<!DOCTYPE html>
|
|
59
|
+
<html>
|
|
60
|
+
<head>
|
|
61
|
+
<meta charset="UTF-8">
|
|
62
|
+
<script>
|
|
63
|
+
window.addEventListener('message', (event) => {
|
|
64
|
+
if (event.data && event.data.type === 'VFS_DELIVER_PAYLOAD') {
|
|
65
|
+
const { payload } = event.data;
|
|
66
|
+
|
|
67
|
+
// 1. Inject Styles
|
|
68
|
+
const style = document.createElement('style');
|
|
69
|
+
style.textContent = payload['style.css'];
|
|
70
|
+
document.head.appendChild(style);
|
|
57
71
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
72
|
+
// 2. Inject External Scripts (Like Confetti Engine) sequentially
|
|
73
|
+
Promise.all(payload.remote_scripts.map(url => {
|
|
74
|
+
return new Promise((resolve, reject) => {
|
|
75
|
+
const script = document.createElement('script');
|
|
76
|
+
script.src = url;
|
|
77
|
+
script.onload = resolve;
|
|
78
|
+
script.onerror = reject;
|
|
79
|
+
document.head.appendChild(script);
|
|
80
|
+
});
|
|
81
|
+
})).then(() => {
|
|
82
|
+
// 3. Inject and run Application loop script only AFTER dependencies load
|
|
83
|
+
const appScript = document.createElement('script');
|
|
84
|
+
appScript.textContent = payload['app.js'];
|
|
85
|
+
document.body.appendChild(appScript);
|
|
86
|
+
}).catch(err => console.error("Dependency Load Failure:", err));
|
|
87
|
+
}
|
|
88
|
+
});
|
|
63
89
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
90
|
+
// Tell the parent window we are ready to receive files
|
|
91
|
+
window.parent.postMessage({ type: 'VFS_FRAME_READY' }, '*');
|
|
92
|
+
<\/script>
|
|
93
|
+
</head>
|
|
94
|
+
<body>
|
|
95
|
+
<script>
|
|
96
|
+
window.addEventListener('message', (e) => {
|
|
97
|
+
if (e.data && e.data.type === 'VFS_DELIVER_PAYLOAD') {
|
|
98
|
+
const parser = new DOMParser();
|
|
99
|
+
const doc = parser.parseFromString(e.data.payload['index.html'], 'text/html');
|
|
100
|
+
document.body.innerHTML = doc.body.innerHTML;
|
|
101
|
+
}
|
|
102
|
+
}, { once: true });
|
|
103
|
+
</script>
|
|
104
|
+
</body>
|
|
105
|
+
</html>
|
|
106
|
+
`;
|
|
107
|
+
|
|
108
|
+
iframe.srcdoc = bootloaderScript;
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
write(filename, contentString) {
|
|
112
|
+
vfsMemory[filename] = contentString;
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
pushRemoteScript(url) {
|
|
116
|
+
vfsMemory['remote_scripts'].push(url);
|
|
71
117
|
}
|
|
72
118
|
};
|
|
73
119
|
|
|
74
120
|
window._vfsKernel = engineCore;
|
|
75
|
-
|
|
76
|
-
if (document.readyState === 'loading') {
|
|
77
|
-
document.addEventListener('DOMContentLoaded', () => engineCore.init());
|
|
78
|
-
} else {
|
|
79
|
-
engineCore.init();
|
|
80
|
-
}
|
|
121
|
+
engineCore.init();
|
|
81
122
|
})();
|