Spaces:
Paused
Paused
File size: 1,460 Bytes
3e6b063 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
// static/js/scribble.js
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
let drawing = false;
canvas.addEventListener("mousedown", () => (drawing = true));
canvas.addEventListener("mouseup", () => (drawing = false));
canvas.addEventListener("mousemove", draw);
function draw(e) {
if (!drawing) return;
ctx.lineWidth = 4;
ctx.lineCap = "round";
ctx.strokeStyle = "#000";
ctx.lineTo(e.offsetX, e.offsetY);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(e.offsetX, e.offsetY);
}
document.getElementById("clear").addEventListener("click", () => {
ctx.clearRect(0, 0, canvas.width, canvas.height);
});
document.getElementById("convert").addEventListener("click", async () => {
const image = canvas.toDataURL("image/png");
const response = await fetch("/scribble/convert", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ image }),
});
const data = await response.json();
if (data.latex) {
document.getElementById("result-box").style.display = "block";
document.getElementById("latex-output").value = data.latex;
} else {
alert("Error generating LaTeX.");
}
});
document.getElementById("copy").addEventListener("click", () => {
const textarea = document.getElementById("latex-output");
textarea.select();
document.execCommand("copy");
alert("✅ LaTeX code copied!");
});
|