vfsjs-test 1.0.5 → 1.0.7
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 +0 -3
- package/main.js +37 -43
- package/package.json +1 -1
- package/vfsjs.js +46 -11
package/index.html
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
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
|
-
<link rel="stylesheet" href="live-theme.css">
|
|
8
7
|
</head>
|
|
9
8
|
<body style="background: #0f172a; color: #38bdf8; font-family: monospace; padding: 20px;">
|
|
10
9
|
|
|
@@ -13,8 +12,6 @@
|
|
|
13
12
|
> Initializing isolated modular framework...
|
|
14
13
|
</div>
|
|
15
14
|
|
|
16
|
-
<script src="index.js"></script>
|
|
17
|
-
|
|
18
15
|
<script src="vfsjs.js"></script>
|
|
19
16
|
<script src="main.js"></script>
|
|
20
17
|
</body>
|
package/main.js
CHANGED
|
@@ -1,59 +1,53 @@
|
|
|
1
|
-
// main.js -
|
|
1
|
+
// main.js - Simple Developer Interface Facade
|
|
2
2
|
const display = document.getElementById('status');
|
|
3
3
|
|
|
4
|
-
//
|
|
4
|
+
// Clean user-facing API surface area
|
|
5
5
|
window.vfs = {
|
|
6
6
|
add(filename, contentString, customMime = null) {
|
|
7
|
-
if (!window._vfsKernel) return console.error("VFS Engine Kernel Offline.");
|
|
8
7
|
return window._vfsKernel.write(filename, contentString, customMime);
|
|
9
8
|
},
|
|
10
|
-
|
|
11
9
|
delete(filename) {
|
|
12
|
-
if (!window._vfsKernel) return console.error("VFS Engine Kernel Offline.");
|
|
13
10
|
return window._vfsKernel.remove(filename);
|
|
14
11
|
},
|
|
15
|
-
|
|
16
12
|
clear() {
|
|
17
|
-
if (!window._vfsKernel) return console.error("VFS Engine Kernel Offline.");
|
|
18
13
|
return window._vfsKernel.wipe();
|
|
14
|
+
},
|
|
15
|
+
hook(filename, type) {
|
|
16
|
+
// type should be 'js' or 'css'
|
|
17
|
+
return window._vfsKernel.mount(filename, type);
|
|
18
|
+
},
|
|
19
|
+
unhook() {
|
|
20
|
+
return window._vfsKernel.unmount();
|
|
19
21
|
}
|
|
20
22
|
};
|
|
21
23
|
|
|
22
|
-
async function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
vfs.add('scratchpad.tmp', 'transient text layout storage structural array');
|
|
50
|
-
vfs.delete('scratchpad.tmp');
|
|
51
|
-
|
|
52
|
-
} catch (err) {
|
|
53
|
-
display.innerHTML += `<br>><span style="color: #ef4444;"> Boot Exception: ${err.message}</span>`;
|
|
54
|
-
console.error(err);
|
|
55
|
-
}
|
|
24
|
+
async function startDeveloperWorkspace() {
|
|
25
|
+
// 1. Fire up the kernel underneath automatically
|
|
26
|
+
const ready = await window._vfsKernel.init();
|
|
27
|
+
if (!ready) return;
|
|
28
|
+
|
|
29
|
+
display.innerHTML += "<br>> Running developer asset deployment...";
|
|
30
|
+
|
|
31
|
+
// 2. Add your scripts and styles to memory
|
|
32
|
+
vfs.add('live-theme.css', `
|
|
33
|
+
body { background: #020617 !important; color: #a5f3fc !important; }
|
|
34
|
+
#status { border-color: #334155 !important; background: #0f172a !important; }
|
|
35
|
+
`, 'text/css');
|
|
36
|
+
|
|
37
|
+
vfs.add('index.js', `
|
|
38
|
+
console.log("VFS Engine: Hooked successfully!");
|
|
39
|
+
document.getElementById('status').innerHTML += "<br>> <span style='color: #22c55e;'>Virtual asset code running live!</span>";
|
|
40
|
+
`, 'text/javascript');
|
|
41
|
+
|
|
42
|
+
// Give the worker split-second thread cache timing
|
|
43
|
+
await new Promise(r => setTimeout(r, 50));
|
|
44
|
+
|
|
45
|
+
// 3. Mount them into the page environment using your new API!
|
|
46
|
+
vfs.hook('live-theme.css', 'css');
|
|
47
|
+
vfs.hook('index.js', 'js');
|
|
48
|
+
|
|
49
|
+
// Example Test: You can run vfs.unhook() anytime later to completely pull them out!
|
|
50
|
+
// setTimeout(() => { vfs.unhook(); }, 5000);
|
|
56
51
|
}
|
|
57
52
|
|
|
58
|
-
|
|
59
|
-
bootEngine();
|
|
53
|
+
startDeveloperWorkspace();
|
package/package.json
CHANGED
package/vfsjs.js
CHANGED
|
@@ -1,13 +1,30 @@
|
|
|
1
|
-
// vfsjs.js -
|
|
1
|
+
// vfsjs.js - Upgraded Core Logic Engine
|
|
2
2
|
(function() {
|
|
3
3
|
const encoder = new TextEncoder();
|
|
4
4
|
const display = document.getElementById('status');
|
|
5
|
+
let injectedNodes = []; // Tracks dynamically mounted elements
|
|
5
6
|
|
|
6
|
-
// Internal core operations dictionary
|
|
7
7
|
const engineCore = {
|
|
8
|
+
// Automatically registers and activates the Service Worker thread
|
|
9
|
+
async init() {
|
|
10
|
+
try {
|
|
11
|
+
await navigator.serviceWorker.register('./sw.js');
|
|
12
|
+
if (display) display.innerHTML += "<br>> Service worker synchronized.";
|
|
13
|
+
|
|
14
|
+
if (!navigator.serviceWorker.controller) {
|
|
15
|
+
if (display) display.innerHTML += "<br>> Securing worker routing links...";
|
|
16
|
+
await new Promise(r => navigator.serviceWorker.addEventListener('controllerchange', r, { once: true }));
|
|
17
|
+
}
|
|
18
|
+
if (display) display.innerHTML += "<br>> Matrix pipeline fully established.";
|
|
19
|
+
return true;
|
|
20
|
+
} catch (err) {
|
|
21
|
+
if (display) display.innerHTML += `<br>><span style="color: #ef4444;"> Core Init Failure: ${err.message}</span>`;
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
|
|
8
26
|
write(filename, contentString, customMime) {
|
|
9
27
|
if (!navigator.serviceWorker.controller) return false;
|
|
10
|
-
|
|
11
28
|
navigator.serviceWorker.controller.postMessage({
|
|
12
29
|
type: 'VFS_WRITE',
|
|
13
30
|
filename: filename,
|
|
@@ -20,24 +37,42 @@
|
|
|
20
37
|
|
|
21
38
|
remove(filename) {
|
|
22
39
|
if (!navigator.serviceWorker.controller) return false;
|
|
23
|
-
|
|
24
|
-
navigator.serviceWorker.controller.postMessage({
|
|
25
|
-
type: 'VFS_DELETE',
|
|
26
|
-
filename: filename
|
|
27
|
-
});
|
|
40
|
+
navigator.serviceWorker.controller.postMessage({ type: 'VFS_DELETE', filename: filename });
|
|
28
41
|
if (display) display.innerHTML += `<br>> Core Remove: <span style="color: #ef4444;">${filename}</span>`;
|
|
29
42
|
return true;
|
|
30
43
|
},
|
|
31
44
|
|
|
32
45
|
wipe() {
|
|
33
46
|
if (!navigator.serviceWorker.controller) return false;
|
|
34
|
-
|
|
35
47
|
navigator.serviceWorker.controller.postMessage({ type: 'VFS_CLEAR' });
|
|
36
|
-
if (display) display.innerHTML += `<br>><span style="color: #f59e0b;"> Core Clear: Matrix
|
|
48
|
+
if (display) display.innerHTML += `<br>><span style="color: #f59e0b;"> Core Clear: Matrix flushed.</span>`;
|
|
37
49
|
return true;
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
// Dynamically injects virtual assets into the browser frame safely
|
|
53
|
+
mount(filename, type) {
|
|
54
|
+
if (type === 'css') {
|
|
55
|
+
const el = document.createElement('link');
|
|
56
|
+
el.rel = 'stylesheet';
|
|
57
|
+
el.href = filename;
|
|
58
|
+
document.head.appendChild(el);
|
|
59
|
+
injectedNodes.push(el);
|
|
60
|
+
} else if (type === 'js') {
|
|
61
|
+
const el = document.createElement('script');
|
|
62
|
+
el.src = filename;
|
|
63
|
+
document.body.appendChild(el);
|
|
64
|
+
injectedNodes.push(el);
|
|
65
|
+
}
|
|
66
|
+
if (display) display.innerHTML += `<br>> Frame Hooked: Loaded [${filename}]`;
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
// Pulls all injected elements back out of the DOM frame
|
|
70
|
+
unmount() {
|
|
71
|
+
injectedNodes.forEach(node => node.remove());
|
|
72
|
+
injectedNodes = [];
|
|
73
|
+
if (display) display.innerHTML += `<br>><span style="color: #f43f5e;"> Frame Unhooked: Virtual nodes detached.</span>`;
|
|
38
74
|
}
|
|
39
75
|
};
|
|
40
76
|
|
|
41
|
-
// Expose internal engine safely to global scope window context
|
|
42
77
|
window._vfsKernel = engineCore;
|
|
43
78
|
})();
|