vfsjs-test 1.0.4 → 1.0.5
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 -3
- package/main.js +31 -40
- 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,18 @@
|
|
|
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
7
|
<link rel="stylesheet" href="live-theme.css">
|
|
9
8
|
</head>
|
|
10
9
|
<body style="background: #0f172a; color: #38bdf8; font-family: monospace; padding: 20px;">
|
|
11
10
|
|
|
12
|
-
<h2>Infrared VFS
|
|
11
|
+
<h2>Infrared Advanced VFS Core</h2>
|
|
13
12
|
<div id="status" style="background: #020617; border: 1px solid #334155; padding: 15px; height: 180px; color: #f1f5f9; line-height: 1.6; overflow-y: auto;">
|
|
14
|
-
>
|
|
13
|
+
> Initializing isolated modular framework...
|
|
15
14
|
</div>
|
|
16
15
|
|
|
17
16
|
<script src="index.js"></script>
|
|
18
17
|
|
|
18
|
+
<script src="vfsjs.js"></script>
|
|
19
19
|
<script src="main.js"></script>
|
|
20
20
|
</body>
|
|
21
21
|
</html>
|
package/main.js
CHANGED
|
@@ -1,68 +1,59 @@
|
|
|
1
|
-
// main.js -
|
|
1
|
+
// main.js - User API Facade and Browser Orchestration
|
|
2
2
|
const display = document.getElementById('status');
|
|
3
3
|
|
|
4
|
+
// Expose clean interface functions to the developer
|
|
4
5
|
window.vfs = {
|
|
5
|
-
encoder: new TextEncoder(),
|
|
6
|
-
|
|
7
6
|
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}]` : ''}`;
|
|
7
|
+
if (!window._vfsKernel) return console.error("VFS Engine Kernel Offline.");
|
|
8
|
+
return window._vfsKernel.write(filename, contentString, customMime);
|
|
17
9
|
},
|
|
18
10
|
|
|
19
11
|
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>`;
|
|
12
|
+
if (!window._vfsKernel) return console.error("VFS Engine Kernel Offline.");
|
|
13
|
+
return window._vfsKernel.remove(filename);
|
|
26
14
|
},
|
|
27
15
|
|
|
28
16
|
clear() {
|
|
29
|
-
if (!
|
|
30
|
-
|
|
31
|
-
display.innerHTML += `<br>><span style="color: #f59e0b;"> VFS Memory Completely Wiped.</span>`;
|
|
17
|
+
if (!window._vfsKernel) return console.error("VFS Engine Kernel Offline.");
|
|
18
|
+
return window._vfsKernel.wipe();
|
|
32
19
|
}
|
|
33
20
|
};
|
|
34
21
|
|
|
35
22
|
async function bootEngine() {
|
|
36
23
|
try {
|
|
37
|
-
|
|
38
|
-
|
|
24
|
+
// Step 1: Fire up background kernel thread
|
|
25
|
+
const registration = await navigator.serviceWorker.register('./sw.js');
|
|
26
|
+
display.innerHTML += "<br>> Service worker synchronized.";
|
|
39
27
|
|
|
28
|
+
// Step 2: Await activation capture if first mount context
|
|
40
29
|
if (!navigator.serviceWorker.controller) {
|
|
41
|
-
display.innerHTML += "<br>> Activating
|
|
42
|
-
await new Promise(r =>
|
|
30
|
+
display.innerHTML += "<br>> Activating routing links... (Refresh if text stays stuck)";
|
|
31
|
+
await new Promise(r => {
|
|
32
|
+
navigator.serviceWorker.addEventListener('controllerchange', r, { once: true });
|
|
33
|
+
});
|
|
43
34
|
}
|
|
44
|
-
display.innerHTML += "<br>>
|
|
45
|
-
|
|
46
|
-
// Run Verification Loop
|
|
47
|
-
// Inside main.js verification block:
|
|
48
|
-
vfs.add('live-theme.css', `body { background: #070a13 !important; color: #22d3ee !important; }`);
|
|
35
|
+
display.innerHTML += "<br>> Pipeline linked. Running diagnostics...";
|
|
49
36
|
|
|
50
|
-
vfs
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
37
|
+
// Step 3: Diagnostic suite running through your clean user window.vfs API
|
|
38
|
+
vfs.add('live-theme.css', `
|
|
39
|
+
body { background: #030712 !important; color: #38bdf8 !important; }
|
|
40
|
+
#status { border-color: #1f2937 !important; background: #0b0f19 !important; }
|
|
41
|
+
`, 'text/css');
|
|
54
42
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
43
|
+
vfs.add('index.js', `
|
|
44
|
+
console.log("VFS Live: Running via separated vfsjs core engine loop.");
|
|
45
|
+
document.getElementById('status').innerHTML += "<br>> <span style='color: #34d399;'>Virtual routing diagnostics complete. Engine stable.</span>";
|
|
46
|
+
`, 'text/javascript');
|
|
58
47
|
|
|
59
|
-
|
|
60
|
-
|
|
48
|
+
// Test temporary file cycle
|
|
49
|
+
vfs.add('scratchpad.tmp', 'transient text layout storage structural array');
|
|
50
|
+
vfs.delete('scratchpad.tmp');
|
|
61
51
|
|
|
62
52
|
} catch (err) {
|
|
63
|
-
display.innerHTML += `<br>><span style="color: #ef4444;">
|
|
53
|
+
display.innerHTML += `<br>><span style="color: #ef4444;"> Boot Exception: ${err.message}</span>`;
|
|
64
54
|
console.error(err);
|
|
65
55
|
}
|
|
66
56
|
}
|
|
67
57
|
|
|
58
|
+
// Instantiate ecosystem initialization
|
|
68
59
|
bootEngine();
|
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>
|