diff --git a/dist/schemascii-0.3.2-py3-none-any.whl b/dist/schemascii-0.3.2-py3-none-any.whl new file mode 100644 index 0000000..744e369 Binary files /dev/null and b/dist/schemascii-0.3.2-py3-none-any.whl differ diff --git a/dist/schemascii-0.3.2.tar.gz b/dist/schemascii-0.3.2.tar.gz new file mode 100644 index 0000000..be1aab1 Binary files /dev/null and b/dist/schemascii-0.3.2.tar.gz differ diff --git a/index.html b/index.html index da0a519..098f57c 100644 --- a/index.html +++ b/index.html @@ -28,16 +28,21 @@ color: red; } - a, a:visited { + a, + a:visited { color: blue; } @media screen and (prefers-color-scheme: dark) { - body, textarea { + + body, + textarea { color: white; background: black; } - a, a:visited { + + a, + a:visited { color: magenta; } } @@ -47,7 +52,7 @@

Schemascii Playground

-

Loading version...

+

using schemascii version

Schemascii Source

@@ -63,46 +68,25 @@

Messages

Errors


         

More Information

-

https://github.com/dragoncoder047/schemascii/

+

https://github.com/dragoncoder047/schemascii/

- + \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index e14990c..91486a9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "schemascii" -version = "0.3.1" +version = "0.3.2" description = "Render ASCII-art schematics to SVG" readme = "README.md" authors = [{ name = "dragoncoder047", email = "101021094+dragoncoder047@users.noreply.github.com" }] diff --git a/schemascii/__init__.py b/schemascii/__init__.py index ee060e4..96d7308 100644 --- a/schemascii/__init__.py +++ b/schemascii/__init__.py @@ -8,7 +8,7 @@ from .utils import XML from .errors import * -__version__ = "0.3.1" +__version__ = "0.3.2" def render(filename: str, text: str = None, **options) -> str: diff --git a/scripts/web_startup.py b/scripts/web_startup.py new file mode 100644 index 0000000..9e24293 --- /dev/null +++ b/scripts/web_startup.py @@ -0,0 +1,99 @@ +from pyodide.http import pyfetch as fetch, open_url as get +from pyodide.ffi import create_proxy as event_handler +import asyncio +import functools +import sys +import re +import js +import json +from operator import itemgetter +import warnings +import micropip + + +def debounced(fun): + timeout = None + + @functools.wraps(fun) + def inner(): + nonlocal timeout + if timeout: + js.clearTimeout(timeout) + timeout = js.setTimeout(fun, 100) + + return inner + + +def syncify(fun): + @functools.wraps(fun) + def inner(e): + return asyncio.ensure_future(fun(e)) + return inner + + +@event_handler +@debounced +def sync_css(): + style_elem.innerHTML = css_box.value + + +@event_handler +@debounced +def render_catch_warnings(*args, **kwargs): + import schemascii + console.textContent = "" + errors.textContent = "" + with warnings.catch_warnings(record=True) as captured_warnings: + out = schemascii.render(*args, **kwargs) + for warn in captured_warnings: + print("warning:", warn.message) + return out + + +@event_handler +@syncify +async def switch_version(): + if "schemascii" in sys.modules: + del sys.modules["schemascii"] # Invalidate cache + version = ver_switcher.value + await micropip.install(versions_to_wheel_map[version]) + +output = js.document.getElementById("output") +css_box = js.document.getElementById("css") +console = js.document.getElementById("console") +source = js.document.getElementById("schemascii") +style_elem = js.document.getElementById("custom-css") +errors = js.document.getElementById("errors") +ver_switcher = js.document.getElementById("version") + + +print("Loading all versions... ", end="") +versions_all = json.load( + get("https://api.github.com/repos/dragoncoder047/schemascii/contents/dist")) +versions_to_wheel_map = dict( + zip(map(itemgetter("name"), versions_all), map(itemgetter("path"), versions_all))) +all_versions = list(versions_to_wheel_map.keys()) +all_versions.append("DEV") +latest_version = re.search( + r'''version = "([\d.]+)"''', get("pyproject.toml").read()).group(1) +print(all_versions, "latest =", latest_version) + +for ver in all_versions: + opt = js.document.createElement("option") + opt.value = opt.textContent = ver + ver_switcher.append(opt) + +ver_switcher.value = latest_version +await micropip.install(versions_to_wheel_map[latest_version]) + + +css_source = get("schemascii_example.css").read() +style_elem.textContent = css_source +css_box.value = css_source + +css_box.addEventListener("input", sync_css) +source.addEventListener("input", render_catch_warnings) + +source.removeAttribute("disabled") +css_box.removeAttribute("disabled") +console.textContent = "ready\n" diff --git a/test_data/test_charge_pump.txt.svg b/test_data/test_charge_pump.txt.svg index e72f24f..128baf2 100644 --- a/test_data/test_charge_pump.txt.svg +++ b/test_data/test_charge_pump.txt.svg @@ -1 +1 @@ -NE555U176215348BAT1 5 VR1 10 kΩC2 10 µFD2 1N4001J1 -5VR2 100 kΩC1 0.01 µFC3 100 µFC4 10 pFD1 1N4001J2 GND \ No newline at end of file +NE555U176215348BAT1 5 VR1 10 kΩC2 10 µFD2 1N4001J1 -5VR2 100 kΩC1 0.01 µFC3 100 µFC4 10 pFD1 1N4001J2 GND \ No newline at end of file