Initial work on html player

This commit is contained in:
Skyler Lehmkuhl 2024-12-30 01:54:47 -05:00
parent b95e585ce5
commit d02b487649
2 changed files with 93 additions and 35 deletions

View File

@ -3345,6 +3345,10 @@ async function render() {
name: 'APNG files (.png)',
extensions: ['png'],
},
{
name: 'Packed HTML player (.html)',
extensions: ['html'],
}
],
defaultPath: await join(await documentDir(), "untitled.png")
});
@ -3359,7 +3363,34 @@ async function render() {
// fileExportPath = path
// console.log("wrote SVG")
const ext = path.split('.').pop().toLowerCase();
switch (ext) {
case 'html':
fetch('/player.html')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.text(); // Read the response body as a string
})
.then(data => {
// TODO: strip out the stuff tauri injects
let json = JSON.stringify({
fileWidth: config.fileWidth,
fileHeight: config.fileHeight,
root: root.toJSON()
})
data = data.replace('"${file}"', json)
console.log(data); // The content of the file as a string
})
.catch(error => {
// TODO: alert
console.error('There was a problem with the fetch operation:', error);
});
break;
case 'png':
const frames = [];
const canvas = document.createElement('canvas');
canvas.width = config.fileWidth; // Set desired width
@ -3401,6 +3432,8 @@ async function render() {
path, // The destination file path for saving
new Uint8Array(await apngBlob.arrayBuffer())
);
break;
}
}
document.querySelector("body").style.cursor = "default"
}

25
src/player.html Normal file
View File

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<script>
const _file = "${file}"
function _render() {
requestAnimationFrame(_render)
}
function __setup__() {
const cvs = document.getElementById("cvs")
cvs.width = _file.fileWidth
cvs.height = _file.fileHeight
cvs.style.width = `${_file.fileWidth}px`
cvs.style.height = `${_file.fileHeight}px`
_render()
}
</script>
</head>
<body>
<canvas id="cvs"></canvas>
<script>__setup__()</script>
</body>
</html>