Spaces:
Running on Zero
Running on Zero
feat: show png export feedback
Browse filesCo-authored-by: Codex <noreply@openai.com>
- static/app.js +31 -5
static/app.js
CHANGED
|
@@ -25,6 +25,7 @@ const resetButton = document.querySelector("#reset-session");
|
|
| 25 |
const SESSION_STORAGE_KEY = "hackathon-advisor-session-v1";
|
| 26 |
const FIELD_NOTES_FILENAME = "hackathon-advisor-field-notes.md";
|
| 27 |
const CHAPTER_FILENAME = "hackathon-advisor-chapter.md";
|
|
|
|
| 28 |
|
| 29 |
let session = {};
|
| 30 |
let clientPromise = Client.connect(window.location.origin);
|
|
@@ -728,10 +729,39 @@ async function exportMarkdown({ endpoint, filename, button, busyLabel, pendingLa
|
|
| 728 |
}
|
| 729 |
|
| 730 |
function exportArtifact(artifact) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 731 |
const canvas = document.createElement("canvas");
|
| 732 |
canvas.width = 1200;
|
| 733 |
canvas.height = 675;
|
| 734 |
const ctx = canvas.getContext("2d");
|
|
|
|
| 735 |
drawParchment(ctx, canvas.width, canvas.height);
|
| 736 |
const seal = artifact.seal || {};
|
| 737 |
ctx.fillStyle = "#25160e";
|
|
@@ -777,11 +807,7 @@ function exportArtifact(artifact) {
|
|
| 777 |
ctx.fillText(String(value), 582, y);
|
| 778 |
});
|
| 779 |
drawWoodMap(ctx, artifact.wood_map, 742, 396, 330, 184, artifact.verdict);
|
| 780 |
-
|
| 781 |
-
const link = document.createElement("a");
|
| 782 |
-
link.download = `${slugify(artifact.title || "unwritten-page")}.png`;
|
| 783 |
-
link.href = canvas.toDataURL("image/png");
|
| 784 |
-
link.click();
|
| 785 |
}
|
| 786 |
|
| 787 |
function downloadText(filename, text, type = "application/jsonl;charset=utf-8") {
|
|
|
|
| 25 |
const SESSION_STORAGE_KEY = "hackathon-advisor-session-v1";
|
| 26 |
const FIELD_NOTES_FILENAME = "hackathon-advisor-field-notes.md";
|
| 27 |
const CHAPTER_FILENAME = "hackathon-advisor-chapter.md";
|
| 28 |
+
const PNG_EXPORT_LABEL = "PNG";
|
| 29 |
|
| 30 |
let session = {};
|
| 31 |
let clientPromise = Client.connect(window.location.origin);
|
|
|
|
| 729 |
}
|
| 730 |
|
| 731 |
function exportArtifact(artifact) {
|
| 732 |
+
const idleLabel = exportButton.textContent;
|
| 733 |
+
exportButton.disabled = true;
|
| 734 |
+
exportButton.textContent = "PNG...";
|
| 735 |
+
session.ui_status = "Drawing PNG.";
|
| 736 |
+
corrections.textContent = session.ui_status;
|
| 737 |
+
saveSession();
|
| 738 |
+
try {
|
| 739 |
+
const filename = `${slugify(artifact.title || "unwritten-page")}.png`;
|
| 740 |
+
const canvas = renderArtifactCanvas(artifact);
|
| 741 |
+
const dataUrl = canvas.toDataURL("image/png");
|
| 742 |
+
if (!dataUrl.startsWith("data:image/png")) throw new Error("PNG rendering failed");
|
| 743 |
+
const link = document.createElement("a");
|
| 744 |
+
link.download = filename;
|
| 745 |
+
link.href = dataUrl;
|
| 746 |
+
link.click();
|
| 747 |
+
session.ui_status = `PNG saved: ${filename}`;
|
| 748 |
+
corrections.textContent = session.ui_status;
|
| 749 |
+
} catch (error) {
|
| 750 |
+
session.ui_status = `Export failed: ${error.message}`;
|
| 751 |
+
corrections.textContent = session.ui_status;
|
| 752 |
+
} finally {
|
| 753 |
+
saveSession();
|
| 754 |
+
exportButton.textContent = idleLabel || PNG_EXPORT_LABEL;
|
| 755 |
+
setCommandDisabled(false);
|
| 756 |
+
}
|
| 757 |
+
}
|
| 758 |
+
|
| 759 |
+
function renderArtifactCanvas(artifact) {
|
| 760 |
const canvas = document.createElement("canvas");
|
| 761 |
canvas.width = 1200;
|
| 762 |
canvas.height = 675;
|
| 763 |
const ctx = canvas.getContext("2d");
|
| 764 |
+
if (!ctx) throw new Error("canvas is unavailable");
|
| 765 |
drawParchment(ctx, canvas.width, canvas.height);
|
| 766 |
const seal = artifact.seal || {};
|
| 767 |
ctx.fillStyle = "#25160e";
|
|
|
|
| 807 |
ctx.fillText(String(value), 582, y);
|
| 808 |
});
|
| 809 |
drawWoodMap(ctx, artifact.wood_map, 742, 396, 330, 184, artifact.verdict);
|
| 810 |
+
return canvas;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 811 |
}
|
| 812 |
|
| 813 |
function downloadText(filename, text, type = "application/jsonl;charset=utf-8") {
|