|
1 |
| -from pyodide.http import pyfetch as fetch, open_url as get |
2 |
| -from pyodide.ffi import create_proxy as event_handler |
3 | 1 | import asyncio
|
4 | 2 | import functools
|
5 | 3 | import sys
|
6 | 4 | import re
|
7 | 5 | import js
|
8 | 6 | import json
|
9 | 7 | import warnings
|
| 8 | +from pyodide.http import pyfetch as fetch, open_url as get |
| 9 | +from pyodide.ffi import create_proxy as event_handler |
10 | 10 | import micropip
|
11 | 11 |
|
12 | 12 |
|
@@ -57,13 +57,21 @@ async def switch_version():
|
57 | 57 | version = ver_switcher.value
|
58 | 58 | await micropip.install(versions_to_wheel_map[version])
|
59 | 59 |
|
| 60 | +@event_handler |
| 61 | +def download_svg(): |
| 62 | + a = js.document.createElement("a") |
| 63 | + a.setAttribute("href", js.URL.createObjectURL(js.Blob.new([output.innerHTML], {"type": "application/svg+xml"}))) |
| 64 | + a.setAttribute("download", f"schemascii_playground_{js.Date.new.toISOString()}_no_css.svg") |
| 65 | + a.click() |
| 66 | + |
60 | 67 | output = js.document.getElementById("output")
|
61 | 68 | css_box = js.document.getElementById("css")
|
62 | 69 | console = js.document.getElementById("console")
|
63 | 70 | source = js.document.getElementById("schemascii")
|
64 | 71 | style_elem = js.document.getElementById("custom-css")
|
65 | 72 | errors = js.document.getElementById("errors")
|
66 | 73 | ver_switcher = js.document.getElementById("version")
|
| 74 | +download_button = js.document.getElementById("download") |
67 | 75 |
|
68 | 76 |
|
69 | 77 | print("Loading all versions... ", end="")
|
@@ -93,6 +101,7 @@ async def switch_version():
|
93 | 101 |
|
94 | 102 | css_box.addEventListener("input", sync_css)
|
95 | 103 | source.addEventListener("input", render_catch_warnings)
|
| 104 | +download_button.addEventListener("click", download_svg) |
96 | 105 |
|
97 | 106 | source.removeAttribute("disabled")
|
98 | 107 | css_box.removeAttribute("disabled")
|
|
0 commit comments