vfsjs-test 1.0.21 → 1.0.23
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 +52 -24
- package/package.json +1 -1
- package/vfsjs.js +54 -43
package/main.js
CHANGED
|
@@ -1,29 +1,57 @@
|
|
|
1
|
-
//
|
|
1
|
+
// main.js - Production Build Wrapper
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
window.vfs = {
|
|
4
|
+
add(filename, contentString, customMime = null) {
|
|
5
|
+
// Strip out query paths down to base keys
|
|
6
|
+
let cleanKey = filename.split('?')[0].split('/').pop();
|
|
7
|
+
window._vfsVirtualCache[cleanKey] = { content: contentString, mime: customMime };
|
|
8
|
+
console.log(`[VFS Cache] Staging file asset: ${cleanKey}`);
|
|
9
|
+
return true;
|
|
10
|
+
},
|
|
7
11
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
async importRemote(localFilename, remoteUrl, customMime = null) {
|
|
13
|
+
try {
|
|
14
|
+
const response = await fetch(remoteUrl);
|
|
15
|
+
if (!response.ok) throw new Error(`HTTP Fault: ${response.status}`);
|
|
16
|
+
const text = await response.text();
|
|
17
|
+
this.add(localFilename, text, customMime);
|
|
18
|
+
return true;
|
|
19
|
+
} catch (err) {
|
|
20
|
+
console.error(`[VFS Proxy Error]`, err);
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
async function buildProductionApplication() {
|
|
27
|
+
// 1. Stage compilation data targets
|
|
28
|
+
vfs.add('app.js', `
|
|
29
|
+
console.log("Launcher script running. Invoking confetti...");
|
|
30
|
+
if (typeof window.confetti === 'function') {
|
|
31
|
+
setInterval(() => {
|
|
32
|
+
window.confetti({ particleCount: 40, spread: 50, origin: { y: 0.6 } });
|
|
33
|
+
}, 2000);
|
|
34
|
+
} else {
|
|
35
|
+
console.error("Confetti script missing from global iframe execution scope.");
|
|
36
|
+
}
|
|
37
|
+
`, 'text/javascript');
|
|
11
38
|
|
|
12
|
-
|
|
13
|
-
|
|
39
|
+
vfs.add('style.css', `
|
|
40
|
+
body { background: #020617 !important; color: #38bdf8 !important; font-family: monospace; padding: 40px; text-align: center; }
|
|
41
|
+
h2 { text-shadow: 0 0 8px rgba(56,189,248,0.5); }
|
|
42
|
+
`, 'text/css');
|
|
43
|
+
|
|
44
|
+
// 2. Fetch CDNJS/jsDelivr packages that bypass scope paths safely
|
|
45
|
+
await vfs.importRemote('my-confetti-engine.js', 'https://cdn.jsdelivr.net/npm/canvas-confetti@1.9.4/dist/confetti.browser.min.js', 'text/javascript');
|
|
46
|
+
|
|
47
|
+
// 3. Compile and open viewport
|
|
48
|
+
window._vfsKernel.openViewport();
|
|
14
49
|
}
|
|
15
50
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const isReady = await navigator.serviceWorker.ready;
|
|
24
|
-
if (isReady) {
|
|
25
|
-
startDeveloperWorkspace();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}, 10);
|
|
29
|
-
});
|
|
51
|
+
(function verifyKernelAvailability() {
|
|
52
|
+
if (window._vfsKernel) {
|
|
53
|
+
buildProductionApplication();
|
|
54
|
+
} else {
|
|
55
|
+
setTimeout(verifyKernelAvailability, 10);
|
|
56
|
+
}
|
|
57
|
+
})();
|
package/package.json
CHANGED
package/vfsjs.js
CHANGED
|
@@ -1,74 +1,85 @@
|
|
|
1
|
-
// vfsjs.js - Version
|
|
1
|
+
// vfsjs.js - Version 6.0.0 (Zero-Network Tag Inline Engine)
|
|
2
2
|
(function() {
|
|
3
|
-
const encoder = new TextEncoder();
|
|
4
|
-
|
|
5
3
|
const engineCore = {
|
|
6
4
|
async init() {
|
|
7
5
|
try {
|
|
8
|
-
// 1.
|
|
6
|
+
// 1. Boot Service Worker for the root frame route interception if needed
|
|
9
7
|
await navigator.serviceWorker.register('./sw.js');
|
|
10
8
|
if (!navigator.serviceWorker.controller) {
|
|
11
9
|
await new Promise(r => navigator.serviceWorker.addEventListener('controllerchange', r, { once: true }));
|
|
12
10
|
}
|
|
13
11
|
|
|
14
|
-
// 2. Capture the
|
|
15
|
-
const
|
|
16
|
-
|
|
12
|
+
// 2. Capture the developer's original raw HTML string structure
|
|
13
|
+
const rawHtml = document.documentElement.innerHTML;
|
|
14
|
+
window._vfsRawTemplate = `<!DOCTYPE html>\n<html>${rawHtml}</html>`;
|
|
17
15
|
|
|
18
|
-
// 3.
|
|
16
|
+
// 3. Clear parent UI layout instantly
|
|
19
17
|
document.documentElement.innerHTML = '';
|
|
20
18
|
Object.assign(document.documentElement.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0' });
|
|
21
19
|
Object.assign(document.body.style, { width: '100%', height: '100%', overflow: 'hidden', margin: '0', padding: '0', background: '#020617' });
|
|
22
20
|
|
|
23
|
-
|
|
21
|
+
// 4. Create the pristine layout iframe container
|
|
22
|
+
const iframe = document.createElement('iframe');
|
|
23
|
+
iframe.id = 'canvas-viewport';
|
|
24
|
+
Object.assign(iframe.style, {
|
|
25
|
+
position: 'absolute', top: '0', left: '0', width: '100%', height: '100%',
|
|
26
|
+
border: 'none', margin: '0', padding: '0', zIndex: '999999'
|
|
27
|
+
});
|
|
28
|
+
document.body.appendChild(iframe);
|
|
29
|
+
|
|
24
30
|
return true;
|
|
25
31
|
} catch (err) {
|
|
26
|
-
console.error("VFS
|
|
32
|
+
console.error("VFS Critical Bootstrap Failure:", err);
|
|
27
33
|
return false;
|
|
28
34
|
}
|
|
29
35
|
},
|
|
30
36
|
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
// Called by main.js after vfs.add loops complete
|
|
38
|
+
openViewport() {
|
|
39
|
+
const iframe = document.getElementById('canvas-viewport');
|
|
40
|
+
if (!iframe) return;
|
|
34
41
|
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
Object.assign(iframe.style, {
|
|
39
|
-
position: 'absolute', top: '0', left: '0', width: '100%', height: '100%',
|
|
40
|
-
border: 'none', margin: '0', padding: '0', zIndex: '999999'
|
|
41
|
-
});
|
|
42
|
-
document.body.appendChild(iframe);
|
|
42
|
+
// Create a virtual document parser out of our captured template
|
|
43
|
+
const parser = new DOMParser();
|
|
44
|
+
const doc = parser.parseFromString(window._vfsRawTemplate, 'text/html');
|
|
43
45
|
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
// 1. Process and inline all marked script tags out of VFS memory maps
|
|
47
|
+
const scripts = Array.from(doc.querySelectorAll('script[src*="vfs=true"]'));
|
|
48
|
+
scripts.forEach(script => {
|
|
49
|
+
const srcAttr = script.getAttribute('src').split('?')[0].split('/').pop();
|
|
50
|
+
const virtualCode = window._vfsVirtualCache[srcAttr];
|
|
51
|
+
|
|
52
|
+
if (virtualCode) {
|
|
53
|
+
const inlineScript = doc.createElement('script');
|
|
54
|
+
inlineScript.textContent = virtualCode.content;
|
|
55
|
+
script.parentNode.replaceChild(inlineScript, script);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
47
58
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
59
|
+
// 2. Process and inline all marked style sheets out of VFS memory maps
|
|
60
|
+
const links = Array.from(doc.querySelectorAll('link[rel="stylesheet"][href*="vfs=true"]'));
|
|
61
|
+
links.forEach(link => {
|
|
62
|
+
const hrefAttr = link.getAttribute('href').split('?')[0].split('/').pop();
|
|
63
|
+
const virtualCSS = window._vfsVirtualCache[hrefAttr];
|
|
64
|
+
|
|
65
|
+
if (virtualCSS) {
|
|
66
|
+
const inlineStyle = doc.createElement('style');
|
|
67
|
+
inlineStyle.textContent = virtualCSS.content;
|
|
68
|
+
link.parentNode.replaceChild(inlineStyle, link);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
55
71
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const mimeMatrix = { 'js': 'text/javascript', 'css': 'text/css', 'html': 'text/html', 'json': 'application/json' };
|
|
59
|
-
customMime = mimeMatrix[ext] || 'application/octet-stream';
|
|
60
|
-
}
|
|
72
|
+
// 3. Convert modified dynamic DOM tree back to a string bundle
|
|
73
|
+
const compilationOutput = `<!DOCTYPE html>\n<html>${doc.documentElement.innerHTML}</html>`;
|
|
61
74
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
content: encoder.encode(contentString),
|
|
66
|
-
mime: customMime
|
|
67
|
-
});
|
|
68
|
-
return true;
|
|
75
|
+
// 4. Inject compilation cleanly via srcdoc to bypass unpkg scope boundaries completely!
|
|
76
|
+
iframe.srcdoc = compilationOutput;
|
|
77
|
+
console.log("[VFS Kernel] Execution compilation injected successfully via srcdoc channel.");
|
|
69
78
|
}
|
|
70
79
|
};
|
|
71
80
|
|
|
81
|
+
// Shared internal key store memory map allocation
|
|
82
|
+
window._vfsVirtualCache = {};
|
|
72
83
|
window._vfsKernel = engineCore;
|
|
73
84
|
|
|
74
85
|
if (document.readyState === 'loading') {
|