vfsjs-test 1.0.14 → 1.0.16
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 +59 -22
- package/package.json +1 -1
- package/vfsjs.js +5 -17
package/main.js
CHANGED
|
@@ -1,59 +1,96 @@
|
|
|
1
|
-
// main.js -
|
|
1
|
+
// main.js - Production Developer Environment Layout
|
|
2
2
|
|
|
3
3
|
window.vfs = {
|
|
4
|
+
// Write local strings straight to memory mapping keyspaces
|
|
4
5
|
add(filename, contentString, customMime = null) {
|
|
5
6
|
return window._vfsKernel.write(filename, contentString, customMime);
|
|
7
|
+
},
|
|
8
|
+
|
|
9
|
+
// Remote Proxy Asset Grabber (Requires target destination to support CORS)
|
|
10
|
+
async importRemote(localFilename, remoteUrl, customMime = null) {
|
|
11
|
+
try {
|
|
12
|
+
console.log(`[VFS Proxy] Pulling remote source stream: ${remoteUrl}`);
|
|
13
|
+
const response = await fetch(remoteUrl);
|
|
14
|
+
if (!response.ok) throw new Error(`HTTP network fault code: ${response.status}`);
|
|
15
|
+
|
|
16
|
+
const remoteTextContent = await response.text();
|
|
17
|
+
this.add(localFilename, remoteTextContent, customMime);
|
|
18
|
+
return true;
|
|
19
|
+
} catch (err) {
|
|
20
|
+
console.error(`[VFS Proxy Error] Could not map ${localFilename}:`, err);
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
6
23
|
}
|
|
7
24
|
};
|
|
8
25
|
|
|
9
26
|
async function startDeveloperWorkspace() {
|
|
10
|
-
// 1.
|
|
27
|
+
// 1. Target a real, open-source library on CDNJS (Canvas Confetti)
|
|
28
|
+
const remoteLibraryUrl = 'https://cdnjs.cloudflare.com/ajax/libs/canvas-confetti/1.9.3/confetti.min.js';
|
|
29
|
+
|
|
30
|
+
// 2. Map the remote asset to a virtual file named "my-confetti-engine.js"
|
|
31
|
+
const importSuccess = await vfs.importRemote('my-confetti-engine.js', remoteLibraryUrl, 'text/javascript');
|
|
32
|
+
|
|
33
|
+
if (!importSuccess) {
|
|
34
|
+
console.error("Failed to fetch library from CDNJS.");
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 3. Create the standard HTML layout referencing the newly mapped virtual file
|
|
11
39
|
vfs.add('index.html', `
|
|
12
40
|
<!DOCTYPE html>
|
|
13
41
|
<html>
|
|
14
42
|
<head>
|
|
15
43
|
<meta charset="UTF-8">
|
|
16
|
-
<title>
|
|
44
|
+
<title>CDNJS Virtualization Demo</title>
|
|
17
45
|
<link rel="stylesheet" href="live_theme.css?vfs=true">
|
|
18
46
|
</head>
|
|
19
47
|
<body>
|
|
20
|
-
<
|
|
21
|
-
<p>
|
|
48
|
+
<h2>CDNJS Virtualization Success!</h2>
|
|
49
|
+
<p>The confetti script was loaded out of memory as a local same-origin asset.</p>
|
|
22
50
|
|
|
51
|
+
<script src="my-confetti-engine.js?vfs=true"></script>
|
|
23
52
|
<script src="index.js?vfs=true"></script>
|
|
24
53
|
</body>
|
|
25
54
|
</html>
|
|
26
55
|
`, 'text/html');
|
|
27
56
|
|
|
28
|
-
//
|
|
57
|
+
// 4. Standard Background Theme Layout
|
|
29
58
|
vfs.add('live_theme.css', `
|
|
30
|
-
html, body { margin: 0; padding: 40px; font-family: monospace; }
|
|
31
|
-
body { background: linear-gradient(-45deg, #
|
|
32
|
-
|
|
59
|
+
html, body { margin: 0; padding: 40px; height: 100%; font-family: monospace; background: #020617; color: #f8fafc; text-align: center; }
|
|
60
|
+
body { background: linear-gradient(-45deg, #1e1b4b, #311042, #0f172a) !important; color: #ffffff !important; }
|
|
61
|
+
h2 { color: #38bdf8; text-shadow: 0 0 10px rgba(56, 189, 248, 0.4); }
|
|
33
62
|
`, 'text/css');
|
|
34
63
|
|
|
35
|
-
//
|
|
64
|
+
// 5. Execution Script: Call the global function initialized by the CDNJS script
|
|
36
65
|
vfs.add('index.js', `
|
|
37
|
-
console.log("
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
66
|
+
console.log("Launcher script running. Invoking confetti...");
|
|
67
|
+
|
|
68
|
+
// Ensure the library attached itself to the virtual window context safely
|
|
69
|
+
if (typeof window.confetti === 'function') {
|
|
70
|
+
// Fire an endless burst of celebratory confetti particles!
|
|
71
|
+
setInterval(() => {
|
|
72
|
+
window.confetti({
|
|
73
|
+
particleCount: 50,
|
|
74
|
+
spread: 60,
|
|
75
|
+
origin: { y: 0.6 }
|
|
76
|
+
});
|
|
77
|
+
}, 1500);
|
|
78
|
+
} else {
|
|
79
|
+
console.error("Confetti engine not found in virtual window global scope.");
|
|
45
80
|
}
|
|
46
81
|
`, 'text/javascript');
|
|
47
82
|
|
|
48
|
-
//
|
|
49
|
-
// to step in and serve our VIRTUAL index.html instead of the physical server one.
|
|
83
|
+
// 6. Point the fullscreen viewport to the directory root
|
|
50
84
|
const viewport = document.getElementById('canvas-viewport');
|
|
51
85
|
if (viewport) {
|
|
52
86
|
viewport.src = './?vfs=true';
|
|
53
87
|
}
|
|
54
88
|
}
|
|
55
89
|
|
|
90
|
+
// Global invocation hook listener
|
|
56
91
|
document.addEventListener('DOMContentLoaded', async () => {
|
|
57
|
-
const
|
|
58
|
-
if (
|
|
92
|
+
const isReady = await window._vfsKernel.init();
|
|
93
|
+
if (isReady) {
|
|
94
|
+
startDeveloperWorkspace();
|
|
95
|
+
}
|
|
59
96
|
});
|
package/package.json
CHANGED
package/vfsjs.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
// vfsjs.js - Automated
|
|
1
|
+
// vfsjs.js - Version 1.2.0 Automated Unified Kernel
|
|
2
2
|
(function() {
|
|
3
3
|
const encoder = new TextEncoder();
|
|
4
4
|
|
|
5
5
|
const engineCore = {
|
|
6
6
|
async init() {
|
|
7
7
|
try {
|
|
8
|
-
// 1.
|
|
8
|
+
// 1. Establish background proxy thread interception
|
|
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.
|
|
14
|
+
// 2. Structural Reset: Enforce full-screen boundary constraints on main window
|
|
15
15
|
Object.assign(document.documentElement.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0' });
|
|
16
16
|
Object.assign(document.body.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0', background: '#020617' });
|
|
17
17
|
|
|
18
|
-
// 3.
|
|
18
|
+
// 3. Viewport Ingestion: Spawn the seamless full-window workspace canvas iframe
|
|
19
19
|
const iframe = document.createElement('iframe');
|
|
20
20
|
iframe.id = 'canvas-viewport';
|
|
21
21
|
iframe.setAttribute('scrolling', 'no');
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
document.body.appendChild(iframe);
|
|
35
35
|
return true;
|
|
36
36
|
} catch (err) {
|
|
37
|
-
console.error("VFS
|
|
37
|
+
console.error("VFS Static Initialization Failure:", err);
|
|
38
38
|
return false;
|
|
39
39
|
}
|
|
40
40
|
},
|
|
@@ -48,18 +48,6 @@
|
|
|
48
48
|
mime: customMime
|
|
49
49
|
});
|
|
50
50
|
return true;
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
remove(filename) {
|
|
54
|
-
if (!navigator.serviceWorker.controller) return false;
|
|
55
|
-
navigator.serviceWorker.controller.postMessage({ type: 'VFS_DELETE', filename: filename });
|
|
56
|
-
return true;
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
wipe() {
|
|
60
|
-
if (!navigator.serviceWorker.controller) return false;
|
|
61
|
-
navigator.serviceWorker.controller.postMessage({ type: 'VFS_CLEAR' });
|
|
62
|
-
return true;
|
|
63
51
|
}
|
|
64
52
|
};
|
|
65
53
|
|