vfsjs-test 1.0.27 → 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 +36 -52
- package/package.json +1 -1
- package/vfsjs.js +94 -56
package/main.js
CHANGED
|
@@ -1,78 +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
|
-
//
|
|
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');
|
|
15
|
+
|
|
16
|
+
// Register application code logic structures
|
|
23
17
|
vfs.add('app.js', `
|
|
24
|
-
console.log("Application loop booted inside clean VFS
|
|
18
|
+
console.log("Application loop booted inside clean isolated VFS Space!");
|
|
25
19
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
// Append exactly ONE action trigger button cleanly
|
|
39
|
-
const button = document.createElement('button');
|
|
40
|
-
button.id = 'action-btn';
|
|
41
|
-
button.innerText = 'Trigger Confetti';
|
|
42
|
-
container.appendChild(button);
|
|
43
|
-
|
|
44
|
-
button.addEventListener('click', () => {
|
|
45
|
-
if (typeof window.confetti === 'function') {
|
|
46
|
-
window.confetti({ particleCount: 100, spread: 70, origin: { y: 0.6 } });
|
|
47
|
-
} else {
|
|
48
|
-
console.error("Confetti script framework is loading or missing reference mapping.");
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
37
|
});
|
|
52
|
-
|
|
38
|
+
`);
|
|
53
39
|
|
|
40
|
+
// Register explicit application presentation rules
|
|
54
41
|
vfs.add('style.css', `
|
|
55
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; }
|
|
56
43
|
h1 { color: #38bdf8; font-size: 2.5rem; }
|
|
57
|
-
p { color: #94a3b8;
|
|
58
|
-
|
|
59
|
-
.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.4); }
|
|
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); }
|
|
60
46
|
.js-card h3 { color: #34d399; margin-top: 0; }
|
|
61
|
-
|
|
62
|
-
button { background: #38bdf8; color: #020617; border: none; padding: 12px 24px; font-weight: 600; border-radius: 6px; cursor: pointer; margin-top: 15px; font-size: 14px; transition: background 0.15s ease; }
|
|
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; }
|
|
63
48
|
button:hover { background: #7dd3fc; }
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
// Fetch the external engine framework dependencies natively
|
|
67
|
-
await vfs.importRemote('my-confetti-engine.js', 'https://cdn.jsdelivr.net/npm/canvas-confetti@1.9.4/dist/confetti.browser.min.js', 'text/javascript');
|
|
49
|
+
`);
|
|
68
50
|
|
|
51
|
+
// Deploy the viewport framework
|
|
69
52
|
window._vfsKernel.openViewport();
|
|
70
53
|
}
|
|
71
54
|
|
|
55
|
+
// Verification block loop execution
|
|
72
56
|
(function verifyKernelAvailability() {
|
|
73
|
-
if (window._vfsKernel
|
|
57
|
+
if (window._vfsKernel) {
|
|
74
58
|
runProductionBuild();
|
|
75
59
|
} else {
|
|
76
|
-
setTimeout(verifyKernelAvailability,
|
|
60
|
+
setTimeout(verifyKernelAvailability, 10);
|
|
77
61
|
}
|
|
78
62
|
})();
|
package/package.json
CHANGED
package/vfsjs.js
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
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
|
-
console.log("%c[VFS Kernel]
|
|
10
|
-
|
|
11
|
-
try {
|
|
12
|
-
await navigator.serviceWorker.register('./sw.js');
|
|
13
|
-
if (!navigator.serviceWorker.controller) {
|
|
14
|
-
await new Promise(r => navigator.serviceWorker.addEventListener('controllerchange', r, { once: true }));
|
|
15
|
-
}
|
|
14
|
+
init() {
|
|
15
|
+
console.log("%c[VFS Kernel] Initializing Pure Handshake Engine...", "color: #38bdf8; font-weight: bold;");
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const doc = parser.parseFromString(`<!DOCTYPE html><html>${document.documentElement.innerHTML}</html>`, 'text/html');
|
|
17
|
+
// 1. Capture the physical HTML content written on the server file
|
|
18
|
+
let rawHtml = document.documentElement.innerHTML;
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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;
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Object.assign(document.documentElement.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0' });
|
|
31
|
-
Object.assign(document.body.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0', background: '#020617' });
|
|
32
|
-
|
|
33
|
-
// 4. Send the sanitized native markup down to the worker
|
|
34
|
-
this.write('index.html', nativeMarkup, 'text/html');
|
|
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' });
|
|
35
30
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
+
});
|
|
41
41
|
},
|
|
42
42
|
|
|
43
43
|
openViewport() {
|
|
44
|
-
console.log("[VFS Kernel] Spawning
|
|
44
|
+
console.log("[VFS Kernel] Spawning blank, secure canvas environment.");
|
|
45
45
|
|
|
46
46
|
const iframe = document.createElement('iframe');
|
|
47
47
|
iframe.id = 'canvas-viewport';
|
|
@@ -49,36 +49,74 @@
|
|
|
49
49
|
position: 'fixed', top: '0', left: '0', width: '100%', height: '100%',
|
|
50
50
|
border: 'none', margin: '0', padding: '0', zIndex: '999999', background: '#020617'
|
|
51
51
|
});
|
|
52
|
+
|
|
52
53
|
document.body.appendChild(iframe);
|
|
53
|
-
iframe.src = './index.html?vfs=true';
|
|
54
|
-
},
|
|
55
54
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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);
|
|
60
71
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
+
});
|
|
66
89
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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);
|
|
74
117
|
}
|
|
75
118
|
};
|
|
76
119
|
|
|
77
120
|
window._vfsKernel = engineCore;
|
|
78
|
-
|
|
79
|
-
if (document.readyState === 'loading') {
|
|
80
|
-
document.addEventListener('DOMContentLoaded', () => engineCore.init());
|
|
81
|
-
} else {
|
|
82
|
-
engineCore.init();
|
|
83
|
-
}
|
|
121
|
+
engineCore.init();
|
|
84
122
|
})();
|