vfsjs-test 1.0.4 → 1.0.6
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 +3 -6
- package/main.js +44 -41
- package/package.json +1 -1
- package/sw.js +3 -4
- package/vfsjs.js +43 -0
- package/logo.svg +0 -45
package/index.html
CHANGED
|
@@ -4,18 +4,15 @@
|
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>Infrared Engine Workspace</title>
|
|
7
|
-
|
|
8
|
-
<link rel="stylesheet" href="live-theme.css">
|
|
9
7
|
</head>
|
|
10
8
|
<body style="background: #0f172a; color: #38bdf8; font-family: monospace; padding: 20px;">
|
|
11
9
|
|
|
12
|
-
<h2>Infrared VFS
|
|
10
|
+
<h2>Infrared Advanced VFS Core</h2>
|
|
13
11
|
<div id="status" style="background: #020617; border: 1px solid #334155; padding: 15px; height: 180px; color: #f1f5f9; line-height: 1.6; overflow-y: auto;">
|
|
14
|
-
>
|
|
12
|
+
> Initializing isolated modular framework...
|
|
15
13
|
</div>
|
|
16
14
|
|
|
17
|
-
<script src="
|
|
18
|
-
|
|
15
|
+
<script src="vfsjs.js"></script>
|
|
19
16
|
<script src="main.js"></script>
|
|
20
17
|
</body>
|
|
21
18
|
</html>
|
package/main.js
CHANGED
|
@@ -1,66 +1,69 @@
|
|
|
1
|
-
// main.js -
|
|
1
|
+
// main.js - User API Facade and Browser Orchestration
|
|
2
2
|
const display = document.getElementById('status');
|
|
3
3
|
|
|
4
4
|
window.vfs = {
|
|
5
|
-
encoder: new TextEncoder(),
|
|
6
|
-
|
|
7
5
|
add(filename, contentString, customMime = null) {
|
|
8
|
-
if (!
|
|
9
|
-
|
|
10
|
-
navigator.serviceWorker.controller.postMessage({
|
|
11
|
-
type: 'VFS_WRITE',
|
|
12
|
-
filename: filename,
|
|
13
|
-
content: this.encoder.encode(contentString),
|
|
14
|
-
mime: customMime
|
|
15
|
-
});
|
|
16
|
-
display.innerHTML += `<br>> VFS Added: <b>${filename}</b> ${customMime ? `[${customMime}]` : ''}`;
|
|
6
|
+
if (!window._vfsKernel) return console.error("VFS Engine Kernel Offline.");
|
|
7
|
+
return window._vfsKernel.write(filename, contentString, customMime);
|
|
17
8
|
},
|
|
18
|
-
|
|
19
9
|
delete(filename) {
|
|
20
|
-
if (!
|
|
21
|
-
|
|
22
|
-
type: 'VFS_DELETE',
|
|
23
|
-
filename: filename
|
|
24
|
-
});
|
|
25
|
-
display.innerHTML += `<br>> VFS Deleted: <span style="color: #ef4444;">${filename}</span>`;
|
|
10
|
+
if (!window._vfsKernel) return console.error("VFS Engine Kernel Offline.");
|
|
11
|
+
return window._vfsKernel.remove(filename);
|
|
26
12
|
},
|
|
27
|
-
|
|
28
13
|
clear() {
|
|
29
|
-
if (!
|
|
30
|
-
|
|
31
|
-
display.innerHTML += `<br>><span style="color: #f59e0b;"> VFS Memory Completely Wiped.</span>`;
|
|
14
|
+
if (!window._vfsKernel) return console.error("VFS Engine Kernel Offline.");
|
|
15
|
+
return window._vfsKernel.wipe();
|
|
32
16
|
}
|
|
33
17
|
};
|
|
34
18
|
|
|
19
|
+
// Helper function to mount our virtual files safely into the DOM runtime
|
|
20
|
+
function executeVirtualEnvironment() {
|
|
21
|
+
display.innerHTML += "<br>> Mounting virtual assets into DOM tree...";
|
|
22
|
+
|
|
23
|
+
// 1. Inject the Style Layer
|
|
24
|
+
const styleLink = document.createElement('link');
|
|
25
|
+
styleLink.rel = 'stylesheet';
|
|
26
|
+
styleLink.href = 'live-theme.css';
|
|
27
|
+
document.head.appendChild(styleLink);
|
|
28
|
+
|
|
29
|
+
// 2. Inject the Logic Layer
|
|
30
|
+
const scriptTag = document.createElement('script');
|
|
31
|
+
scriptTag.src = 'index.js';
|
|
32
|
+
document.body.appendChild(scriptTag);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
35
|
async function bootEngine() {
|
|
36
36
|
try {
|
|
37
|
-
const registration = await navigator.serviceWorker.register('./sw.js'
|
|
38
|
-
display.innerHTML += "<br>> Service worker
|
|
37
|
+
const registration = await navigator.serviceWorker.register('./sw.js');
|
|
38
|
+
display.innerHTML += "<br>> Service worker synchronized.";
|
|
39
39
|
|
|
40
40
|
if (!navigator.serviceWorker.controller) {
|
|
41
|
-
display.innerHTML += "<br>> Activating
|
|
42
|
-
await new Promise(r =>
|
|
41
|
+
display.innerHTML += "<br>> Activating routing links... (Please refresh if stuck)";
|
|
42
|
+
await new Promise(r => {
|
|
43
|
+
navigator.serviceWorker.addEventListener('controllerchange', r, { once: true });
|
|
44
|
+
});
|
|
43
45
|
}
|
|
44
|
-
display.innerHTML += "<br>>
|
|
46
|
+
display.innerHTML += "<br>> Pipeline linked. Writing data layers...";
|
|
45
47
|
|
|
46
|
-
//
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
// Write targets directly into memory first
|
|
49
|
+
vfs.add('live-theme.css', `
|
|
50
|
+
body { background: #030712 !important; color: #22d3ee !important; }
|
|
51
|
+
#status { border-color: #1f2937 !important; background: #0b0f19 !important; }
|
|
52
|
+
`, 'text/css');
|
|
49
53
|
|
|
50
|
-
vfs.add('index.js', `
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
`, 'text/javascript');
|
|
54
|
+
vfs.add('index.js', `
|
|
55
|
+
console.log("VFS Live: Running perfectly under dynamic injection!");
|
|
56
|
+
document.getElementById('status').innerHTML += "<br>> <span style='color: #34d399;'>Virtual routing complete. Engine stable.</span>";
|
|
57
|
+
`, 'text/javascript');
|
|
54
58
|
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
vfs.delete('trash.js');
|
|
59
|
+
// Give the background worker thread a brief split-second to cache the blobs
|
|
60
|
+
await new Promise(r => setTimeout(r, 50));
|
|
58
61
|
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
// Now run them safely!
|
|
63
|
+
executeVirtualEnvironment();
|
|
61
64
|
|
|
62
65
|
} catch (err) {
|
|
63
|
-
display.innerHTML += `<br>><span style="color: #ef4444;">
|
|
66
|
+
display.innerHTML += `<br>><span style="color: #ef4444;"> Boot Exception: ${err.message}</span>`;
|
|
64
67
|
console.error(err);
|
|
65
68
|
}
|
|
66
69
|
}
|
package/package.json
CHANGED
package/sw.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// sw.js -
|
|
1
|
+
// sw.js - Isolated Network Intercept Core
|
|
2
2
|
const vfsStorage = new Map();
|
|
3
3
|
|
|
4
4
|
const defaultMimes = {
|
|
@@ -24,7 +24,8 @@ self.addEventListener('fetch', (event) => {
|
|
|
24
24
|
status: 200,
|
|
25
25
|
headers: {
|
|
26
26
|
'Content-Type': contentType,
|
|
27
|
-
'Access-Control-Allow-Origin': '*'
|
|
27
|
+
'Access-Control-Allow-Origin': '*',
|
|
28
|
+
'X-Content-Type-Options': 'nosniff'
|
|
28
29
|
}
|
|
29
30
|
}));
|
|
30
31
|
}
|
|
@@ -40,11 +41,9 @@ self.addEventListener('message', (event) => {
|
|
|
40
41
|
mime: event.data.mime || null
|
|
41
42
|
});
|
|
42
43
|
break;
|
|
43
|
-
|
|
44
44
|
case 'VFS_DELETE':
|
|
45
45
|
vfsStorage.delete(event.data.filename);
|
|
46
46
|
break;
|
|
47
|
-
|
|
48
47
|
case 'VFS_CLEAR':
|
|
49
48
|
vfsStorage.clear();
|
|
50
49
|
break;
|
package/vfsjs.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// vfsjs.js - Internal Core Logic Engine
|
|
2
|
+
(function() {
|
|
3
|
+
const encoder = new TextEncoder();
|
|
4
|
+
const display = document.getElementById('status');
|
|
5
|
+
|
|
6
|
+
// Internal core operations dictionary
|
|
7
|
+
const engineCore = {
|
|
8
|
+
write(filename, contentString, customMime) {
|
|
9
|
+
if (!navigator.serviceWorker.controller) return false;
|
|
10
|
+
|
|
11
|
+
navigator.serviceWorker.controller.postMessage({
|
|
12
|
+
type: 'VFS_WRITE',
|
|
13
|
+
filename: filename,
|
|
14
|
+
content: encoder.encode(contentString),
|
|
15
|
+
mime: customMime
|
|
16
|
+
});
|
|
17
|
+
if (display) display.innerHTML += `<br>> Core Write: <b>${filename}</b>`;
|
|
18
|
+
return true;
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
remove(filename) {
|
|
22
|
+
if (!navigator.serviceWorker.controller) return false;
|
|
23
|
+
|
|
24
|
+
navigator.serviceWorker.controller.postMessage({
|
|
25
|
+
type: 'VFS_DELETE',
|
|
26
|
+
filename: filename
|
|
27
|
+
});
|
|
28
|
+
if (display) display.innerHTML += `<br>> Core Remove: <span style="color: #ef4444;">${filename}</span>`;
|
|
29
|
+
return true;
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
wipe() {
|
|
33
|
+
if (!navigator.serviceWorker.controller) return false;
|
|
34
|
+
|
|
35
|
+
navigator.serviceWorker.controller.postMessage({ type: 'VFS_CLEAR' });
|
|
36
|
+
if (display) display.innerHTML += `<br>><span style="color: #f59e0b;"> Core Clear: Matrix registers flushed.</span>`;
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// Expose internal engine safely to global scope window context
|
|
42
|
+
window._vfsKernel = engineCore;
|
|
43
|
+
})();
|
package/logo.svg
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg">
|
|
2
|
-
<foreignObject width="100%" height="100%">
|
|
3
|
-
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" style="width:100%;height:100%">
|
|
4
|
-
<head>
|
|
5
|
-
<style>
|
|
6
|
-
body,html,iframe{width:100%;height:100%}body,html{margin:0;padding:0;background:#000;overflow:hidden}iframe{border:0}
|
|
7
|
-
</style>
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
<script>
|
|
11
|
-
//
|
|
12
|
-
<![CDATA[
|
|
13
|
-
(function() {
|
|
14
|
-
const src = "https://cdn.jsdelivr.net/npm/vfsjs-test@1.0.4/";
|
|
15
|
-
|
|
16
|
-
// In SVG, document.body is null. We must find the XHTML body manually:
|
|
17
|
-
const targetBody = document.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "body")[0];
|
|
18
|
-
|
|
19
|
-
fetch(src + "index.html")
|
|
20
|
-
.then(res => res.text())
|
|
21
|
-
.then(html => {
|
|
22
|
-
const frame = document.createElementNS("http://www.w3.org/1999/xhtml", "iframe");
|
|
23
|
-
targetBody.appendChild(frame);
|
|
24
|
-
|
|
25
|
-
const patchedHtml = html.replace("<head>", `<head><base href="${src}" />`);
|
|
26
|
-
|
|
27
|
-
const doc = frame.contentWindow.document;
|
|
28
|
-
doc.open();
|
|
29
|
-
doc.write(patchedHtml);
|
|
30
|
-
doc.close();
|
|
31
|
-
})
|
|
32
|
-
.catch(err => {
|
|
33
|
-
console.error("Loader Error:", err);
|
|
34
|
-
if (targetBody) {
|
|
35
|
-
targetBody.style.color = "white";
|
|
36
|
-
targetBody.innerHTML = "Failed to load content: " + err.message;
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
})();
|
|
40
|
-
// ]]>
|
|
41
|
-
</script>
|
|
42
|
-
</body>
|
|
43
|
-
</html>
|
|
44
|
-
</foreignObject>
|
|
45
|
-
</svg>
|