vfsjs-test 1.0.18 → 1.0.20
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/package.json +1 -1
- package/vfsjs.js +32 -14
package/package.json
CHANGED
package/vfsjs.js
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
1
|
-
// vfsjs.js - Version
|
|
1
|
+
// vfsjs.js - Version 3.0.0 (Universal Production Routing Engine)
|
|
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. Register the Service Worker
|
|
9
9
|
await navigator.serviceWorker.register('./sw.js');
|
|
10
|
+
|
|
11
|
+
// Ensure the worker is actively controlling the page before proceeding
|
|
10
12
|
if (!navigator.serviceWorker.controller) {
|
|
11
13
|
await new Promise(r => navigator.serviceWorker.addEventListener('controllerchange', r, { once: true }));
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
// 2.
|
|
15
|
-
// We wrap it back into a standard root <html> tag structure
|
|
16
|
+
// 2. Capture the physical file's raw HTML structure exactly as it is
|
|
16
17
|
const developerRawHtml = `<!DOCTYPE html>\n<html>${document.documentElement.innerHTML}</html>`;
|
|
17
|
-
|
|
18
|
-
// 3. Commit their real file markup into the Virtual File System instantly
|
|
19
18
|
this.write('index.html', developerRawHtml, 'text/html');
|
|
20
19
|
|
|
21
|
-
//
|
|
20
|
+
// 3. Clear out the main window and lock down body dimensions
|
|
22
21
|
document.documentElement.innerHTML = '';
|
|
23
22
|
Object.assign(document.documentElement.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0' });
|
|
24
23
|
Object.assign(document.body.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0', background: '#020617' });
|
|
25
24
|
|
|
26
|
-
//
|
|
25
|
+
// 4. Mount the clean, scrollable iframe viewport canvas
|
|
27
26
|
const iframe = document.createElement('iframe');
|
|
28
27
|
iframe.id = 'canvas-viewport';
|
|
29
28
|
Object.assign(iframe.style, {
|
|
@@ -32,20 +31,37 @@
|
|
|
32
31
|
});
|
|
33
32
|
document.body.appendChild(iframe);
|
|
34
33
|
|
|
35
|
-
//
|
|
34
|
+
// 5. Point the canvas to the virtual root directory
|
|
36
35
|
iframe.src = './?vfs=true';
|
|
37
36
|
|
|
38
37
|
return true;
|
|
39
38
|
} catch (err) {
|
|
40
|
-
console.error("VFS
|
|
39
|
+
console.error("VFS Universal Core Initialization Failure:", err);
|
|
41
40
|
return false;
|
|
42
41
|
}
|
|
43
42
|
},
|
|
44
43
|
|
|
45
44
|
write(filename, contentString, customMime) {
|
|
46
45
|
if (!navigator.serviceWorker.controller) return false;
|
|
46
|
+
|
|
47
|
+
// Extract a clean relative filename path if an absolute or query-string URL slips in
|
|
48
|
+
let cleanKey = filename.split('?')[0];
|
|
49
|
+
if (cleanKey.includes('/')) {
|
|
50
|
+
cleanKey = cleanKey.split('/').pop();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Auto-detect basic mime types if not provided
|
|
54
|
+
if (!customMime) {
|
|
55
|
+
const ext = cleanKey.split('.').pop().toLowerCase();
|
|
56
|
+
const mimeMatrix = { 'js': 'text/javascript', 'css': 'text/css', 'html': 'text/html', 'json': 'application/json' };
|
|
57
|
+
customMime = mimeMatrix[ext] || 'application/octet-stream';
|
|
58
|
+
}
|
|
59
|
+
|
|
47
60
|
navigator.serviceWorker.controller.postMessage({
|
|
48
|
-
type: 'VFS_WRITE',
|
|
61
|
+
type: 'VFS_WRITE',
|
|
62
|
+
filename: cleanKey,
|
|
63
|
+
content: encoder.encode(contentString),
|
|
64
|
+
mime: customMime
|
|
49
65
|
});
|
|
50
66
|
return true;
|
|
51
67
|
}
|
|
@@ -53,8 +69,10 @@
|
|
|
53
69
|
|
|
54
70
|
window._vfsKernel = engineCore;
|
|
55
71
|
|
|
56
|
-
//
|
|
57
|
-
document.
|
|
72
|
+
// Execute immediately or when DOM structural elements are ready
|
|
73
|
+
if (document.readyState === 'loading') {
|
|
74
|
+
document.addEventListener('DOMContentLoaded', () => engineCore.init());
|
|
75
|
+
} else {
|
|
58
76
|
engineCore.init();
|
|
59
|
-
}
|
|
77
|
+
}
|
|
60
78
|
})();
|