Initial work on html player
This commit is contained in:
parent
b95e585ce5
commit
d02b487649
33
src/main.js
33
src/main.js
|
|
@ -3345,6 +3345,10 @@ async function render() {
|
||||||
name: 'APNG files (.png)',
|
name: 'APNG files (.png)',
|
||||||
extensions: ['png'],
|
extensions: ['png'],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'Packed HTML player (.html)',
|
||||||
|
extensions: ['html'],
|
||||||
|
}
|
||||||
],
|
],
|
||||||
defaultPath: await join(await documentDir(), "untitled.png")
|
defaultPath: await join(await documentDir(), "untitled.png")
|
||||||
});
|
});
|
||||||
|
|
@ -3359,7 +3363,34 @@ async function render() {
|
||||||
// fileExportPath = path
|
// fileExportPath = path
|
||||||
// console.log("wrote SVG")
|
// 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 frames = [];
|
||||||
const canvas = document.createElement('canvas');
|
const canvas = document.createElement('canvas');
|
||||||
canvas.width = config.fileWidth; // Set desired width
|
canvas.width = config.fileWidth; // Set desired width
|
||||||
|
|
@ -3401,6 +3432,8 @@ async function render() {
|
||||||
path, // The destination file path for saving
|
path, // The destination file path for saving
|
||||||
new Uint8Array(await apngBlob.arrayBuffer())
|
new Uint8Array(await apngBlob.arrayBuffer())
|
||||||
);
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
document.querySelector("body").style.cursor = "default"
|
document.querySelector("body").style.cursor = "default"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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>
|
||||||
Loading…
Reference in New Issue