Rename some files; fix sourceURL pragmas

This commit is contained in:
Adrian Vollmer 2022-10-12 14:41:57 +02:00
parent b563da585e
commit 25fb93219c
5 changed files with 42 additions and 52 deletions

22
zundler/assets/bootstrap.js vendored Normal file
View File

@ -0,0 +1,22 @@
var _base64ToArrayBuffer = function (base64) {
if (!base64) { return []}
var binary_string = window.atob(base64);
var len = binary_string.length;
var bytes = new Uint8Array(len);
for (var i = 0; i < len; i++) {
bytes[i] = binary_string.charCodeAt(i);
}
return bytes.buffer;
};
// Set up the virtual file tree
var GC = window.global_context;
GC = _base64ToArrayBuffer(GC);
GC = pako.inflate(GC);
GC = new TextDecoder("utf-8").decode(GC);
GC = JSON.parse(GC);
window.global_context = GC;
eval(window.global_context.main);
//# sourceURL=bootstrap.js

View File

@ -23,7 +23,7 @@ var embed_js = function() {
var src = newScript.getAttribute('src');
let [path, get_parameters, anchor] = split_url(src);
path = normalize_path(path);
var src = retrieve_file(path) + ' //# ' + path;
var src = retrieve_file(path) + ' //# sourceMap=' + path;
newScript.appendChild(document.createTextNode(src));
newScript.removeAttribute('src');
oldScript.parentNode.replaceChild(newScript, oldScript);
@ -309,6 +309,3 @@ var on_load = function() {
window.addEventListener('load', on_load);
//# inject.js

View File

@ -1,28 +1,5 @@
const iFrameId = 'main';
var _ArrayBufferToBase64 = function (array_buffer) {
var binary = '';
var bytes = new Uint8Array(array_buffer);
var len = bytes.byteLength;
for (var i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i])
}
return window.btoa(binary);
};
var _base64ToArrayBuffer = function (base64) {
if (!base64) { return []}
var binary_string = window.atob(base64);
var len = binary_string.length;
var bytes = new Uint8Array(len);
for (var i = 0; i < len; i++) {
bytes[i] = binary_string.charCodeAt(i);
}
return bytes.buffer;
};
var set_favicon = function(href) {
if (!href) {return;}
var favicon = document.createElement("link");
@ -105,16 +82,7 @@ var normalize_path = function(path) {
};
window.onload = function() {
// Set up the virtual file tree
var FT = window.global_context.file_tree;
FT = _base64ToArrayBuffer(FT);
FT = pako.inflate(FT)
FT = new TextDecoder("utf-8").decode(FT);
FT = JSON.parse(FT);
window.global_context.file_tree = FT;
// Set up message listener
window.addEventListener("message", (evnt) => {
console.log("Received message in parent", evnt);
@ -174,4 +142,5 @@ var hide_loading_indictator = function() {
loading.style.display = 'none';
}
//# init.js
//# sourceURL=main.js

View File

@ -33,11 +33,12 @@ def embed_assets(index_file, output_path=None):
init_files = {}
for filename in [
'init.js',
'inject.js',
'init.css',
'init.html',
'monkeypatch.js',
'bootstrap.js',
'main.js',
'inject_pre.js',
'inject_post.js',
'pako.min.js',
'LICENSE',
]:
@ -56,14 +57,10 @@ def embed_assets(index_file, output_path=None):
file_tree = load_filetree(
base_dir,
before=init_files['monkeypatch.js'],
after=init_files['inject.js'],
before=init_files['inject_pre.js'],
after=init_files['inject_post.js'],
exclude_pattern=new_base_name,
)
file_tree = json.dumps(file_tree)
logger.debug('total asset size: %d' % len(file_tree))
file_tree = deflate(file_tree)
logger.debug('total asset size (compressed): %d' % len(file_tree))
remote_resources = []
@ -71,23 +68,28 @@ def embed_assets(index_file, output_path=None):
'current_path': base_name,
'file_tree': file_tree,
'remote_resources': remote_resources,
'main': init_files['main.js'],
}
global_context = json.dumps(global_context)
logger.debug('total asset size: %d' % len(global_context))
global_context = deflate(global_context)
logger.debug('total asset size (compressed): %d' % len(global_context))
result = """
<!DOCTYPE html>
<html>
<head><style>{style}</style></head>
<body>{body}
<script>window.global_context = {global_context}</script>
<script>window.global_context = "{global_context}"</script>
<script>{pako} //# sourceURL=pako.js</script>
<script>{init_js} //# sourceURL=init.js</script>
<script>{bootstrap} //# sourceURL=boostrap.js</script>
</body><!-- {license} --></html>
""".format(
style=init_files['init.css'],
init_js=init_files['init.js'],
pako=init_files['pako.min.js'],
body=init_files['init.html'],
pako=init_files['pako.min.js'],
bootstrap=init_files['bootstrap.js'],
global_context=global_context,
license=init_files['LICENSE'],
)
@ -171,12 +173,12 @@ def embed_html_resources(html, base_dir, before, after):
if head and before:
script = soup.new_tag("script")
script.string = before
script.string = before + '//# sourceURL=inject_pre.js'
head.insert(0, script)
if body and after:
script = soup.new_tag("script")
script.string = after
script.string = after + '//# sourceURL=inject_post.js'
body.append(script)
# TODO embed remote resources in case we want the entire file to be