diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..24a8e87 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.png filter=lfs diff=lfs merge=lfs -text diff --git a/logo/logo100.png b/logo/logo100.png index 1a9f92d..e37e60b 100644 Binary files a/logo/logo100.png and b/logo/logo100.png differ diff --git a/logo/logo200.png b/logo/logo200.png index 9a0dd89..5c4ee81 100644 Binary files a/logo/logo200.png and b/logo/logo200.png differ diff --git a/logo/logo50.png b/logo/logo50.png index 6b5effa..4b33d73 100644 Binary files a/logo/logo50.png and b/logo/logo50.png differ diff --git a/logo/logo500.png b/logo/logo500.png index 1d9377c..a96ee0b 100644 Binary files a/logo/logo500.png and b/logo/logo500.png differ diff --git a/pybloqs/static/jsinflate.js b/pybloqs/static/jsinflate.js index 0ea2efe..7a9c777 100644 --- a/pybloqs/static/jsinflate.js +++ b/pybloqs/static/jsinflate.js @@ -1,3 +1,5 @@ -(function(){var zip_inflate=async function(str){const binaryString=atob(str);var bytes=new Uint8Array(binaryString.length);for(var i=0;iacc+chunk.length,0));let offset=0;chunks.forEach(chunk=>{decompressedData.set(chunk,offset);offset+=chunk.length;});return decompressedData;} +chunks.push(value);return reader.read().then(process);});} +var zip_inflate=async function(str){const binaryString=atob(str);var bytes=new Uint8Array(binaryString.length);for(var i=0;i(new TextDecoder().decode(decompressed))).catch(console.error);} if(!window.RawDeflate)RawDeflate={};RawDeflate.inflate=zip_inflate;})(); \ No newline at end of file diff --git a/pybloqs/static/uncompressed/jsinflate.js b/pybloqs/static/uncompressed/jsinflate.js index 273591c..30acec5 100644 --- a/pybloqs/static/uncompressed/jsinflate.js +++ b/pybloqs/static/uncompressed/jsinflate.js @@ -1,15 +1,41 @@ (function(){ + function decompress(bytes) { + const input = new ReadableStream({ + start(c) { + c.enqueue(bytes); + c.close(); + }, + }).pipeThrough(new DecompressionStream("deflate")); + + const reader = input.getReader(); + const chunks = []; + + return reader.read().then(function process({ done, value }) { + if (done) { + const decompressedData = new Uint8Array( + chunks.reduce((acc, chunk) => acc + chunk.length, 0) + ); + let offset = 0; + chunks.forEach(chunk => { + decompressedData.set(chunk, offset); + offset += chunk.length; + }); + return decompressedData; + } + chunks.push(value); + return reader.read().then(process); + }); +} + var zip_inflate=async function(str){ const binaryString = atob(str); var bytes = new Uint8Array(binaryString.length); for (var i = 0; i < binaryString.length; i++) { bytes[i] = binaryString.charCodeAt(i); } - return await new Response( - new Blob([bytes]) - .stream() - .pipeThrough(new DecompressionStream('deflate')) - ).text(); + return decompress(bytes) + .then(decompressed => (new TextDecoder().decode(decompressed))) + .catch(console.error); } if(!window.RawDeflate)RawDeflate={};RawDeflate.inflate=zip_inflate;} )(); diff --git a/pybloqs_in_notebook.png b/pybloqs_in_notebook.png index 8f21ee7..55aaefe 100644 Binary files a/pybloqs_in_notebook.png and b/pybloqs_in_notebook.png differ diff --git a/tests/integration/generate/test_image_file.png b/tests/integration/generate/test_image_file.png index 10a8038..7531829 100755 Binary files a/tests/integration/generate/test_image_file.png and b/tests/integration/generate/test_image_file.png differ diff --git a/tests/regression/html_output/empty.html b/tests/regression/html_output/custom_css.html similarity index 66% rename from tests/regression/html_output/empty.html rename to tests/regression/html_output/custom_css.html index 3230f2d..edcc655 100644 --- a/tests/regression/html_output/empty.html +++ b/tests/regression/html_output/custom_css.html @@ -4,8 +4,10 @@ @@ -39,9 +41,13 @@ } } +
+ Some content
diff --git a/tests/regression/html_output/custom_js_compressed.html b/tests/regression/html_output/custom_js_compressed.html new file mode 100644 index 0000000..c7d5e58 --- /dev/null +++ b/tests/regression/html_output/custom_js_compressed.html @@ -0,0 +1,55 @@ + + + + + + + + + + +
+ Some content +
+ + diff --git a/tests/regression/html_output/custom_js_uncompressed.html b/tests/regression/html_output/custom_js_uncompressed.html new file mode 100644 index 0000000..e875618 --- /dev/null +++ b/tests/regression/html_output/custom_js_uncompressed.html @@ -0,0 +1,55 @@ + + + + + + + + + + +
+ Some content +
+ + diff --git a/tests/regression/html_output/flow.html b/tests/regression/html_output/flow.html index 229cc7d..02751e7 100644 --- a/tests/regression/html_output/flow.html +++ b/tests/regression/html_output/flow.html @@ -4,8 +4,10 @@ diff --git a/tests/regression/html_output/grid.html b/tests/regression/html_output/grid.html index ab7396c..584493e 100644 --- a/tests/regression/html_output/grid.html +++ b/tests/regression/html_output/grid.html @@ -4,8 +4,10 @@ diff --git a/tests/regression/html_output/hrule.html b/tests/regression/html_output/hrule.html index 7efdf0c..c4deb88 100644 --- a/tests/regression/html_output/hrule.html +++ b/tests/regression/html_output/hrule.html @@ -4,8 +4,10 @@ diff --git a/tests/regression/html_output/hstack.html b/tests/regression/html_output/hstack.html index e80bc40..96011fd 100644 --- a/tests/regression/html_output/hstack.html +++ b/tests/regression/html_output/hstack.html @@ -4,8 +4,10 @@ diff --git a/tests/regression/html_output/markdown.html b/tests/regression/html_output/markdown.html index 6e22f96..8672d2f 100644 --- a/tests/regression/html_output/markdown.html +++ b/tests/regression/html_output/markdown.html @@ -4,8 +4,10 @@ diff --git a/tests/regression/html_output/nested.html b/tests/regression/html_output/nested.html index 1057ab8..6f99e83 100644 --- a/tests/regression/html_output/nested.html +++ b/tests/regression/html_output/nested.html @@ -4,8 +4,10 @@ diff --git a/tests/regression/html_output/pre.html b/tests/regression/html_output/pre.html index 76b922c..b66ec85 100644 --- a/tests/regression/html_output/pre.html +++ b/tests/regression/html_output/pre.html @@ -4,8 +4,10 @@ diff --git a/tests/regression/html_output/raw.html b/tests/regression/html_output/raw.html index 9c96b56..5752e5d 100644 --- a/tests/regression/html_output/raw.html +++ b/tests/regression/html_output/raw.html @@ -4,8 +4,10 @@ diff --git a/tests/regression/html_output/span.html b/tests/regression/html_output/span.html index caca18c..e487615 100644 --- a/tests/regression/html_output/span.html +++ b/tests/regression/html_output/span.html @@ -4,8 +4,10 @@ diff --git a/tests/regression/html_output/title.html b/tests/regression/html_output/title.html index 5341eb2..9b45ea6 100644 --- a/tests/regression/html_output/title.html +++ b/tests/regression/html_output/title.html @@ -4,8 +4,10 @@ diff --git a/tests/regression/html_output/title_levels.html b/tests/regression/html_output/title_levels.html index 35d47eb..d8deaab 100644 --- a/tests/regression/html_output/title_levels.html +++ b/tests/regression/html_output/title_levels.html @@ -4,8 +4,10 @@ diff --git a/tests/regression/html_output/vstack.html b/tests/regression/html_output/vstack.html index bf2127c..c368db1 100644 --- a/tests/regression/html_output/vstack.html +++ b/tests/regression/html_output/vstack.html @@ -4,8 +4,10 @@ diff --git a/tests/regression/png_output/custom_css.png b/tests/regression/png_output/custom_css.png new file mode 100644 index 0000000..9c8c079 --- /dev/null +++ b/tests/regression/png_output/custom_css.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2b28e4084e91a5f95799cf9b149b307c23627aeebcd82a7f735f799a74be39ac +size 13131 diff --git a/tests/regression/png_output/custom_js_compressed.png b/tests/regression/png_output/custom_js_compressed.png new file mode 100644 index 0000000..8e9fe97 --- /dev/null +++ b/tests/regression/png_output/custom_js_compressed.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:56fa02d5f8b123c49106070c30bba029aca759b5657ca4384e51856d4ec52d18 +size 13131 diff --git a/tests/regression/png_output/custom_js_uncompressed.png b/tests/regression/png_output/custom_js_uncompressed.png new file mode 100644 index 0000000..8e9fe97 --- /dev/null +++ b/tests/regression/png_output/custom_js_uncompressed.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:56fa02d5f8b123c49106070c30bba029aca759b5657ca4384e51856d4ec52d18 +size 13131 diff --git a/tests/regression/png_output/empty.png b/tests/regression/png_output/empty.png new file mode 100644 index 0000000..e69de29 diff --git a/tests/regression/png_output/flow.png b/tests/regression/png_output/flow.png new file mode 100644 index 0000000..1b1e9fa --- /dev/null +++ b/tests/regression/png_output/flow.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3924128fb039cbc0f110f3fc812e581e880fb544fb482ed24b3fe29adb5afeba +size 40341 diff --git a/tests/regression/png_output/grid.png b/tests/regression/png_output/grid.png new file mode 100644 index 0000000..da34582 --- /dev/null +++ b/tests/regression/png_output/grid.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:668464861aa6284e565c8d1f5f50371c3088dc210cf2877e550ebfc4eae82138 +size 46475 diff --git a/tests/regression/png_output/hrule.png b/tests/regression/png_output/hrule.png new file mode 100644 index 0000000..736d38b --- /dev/null +++ b/tests/regression/png_output/hrule.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cab3adc2f4e1e46062290e7443faf8a4993eeb2ebe29a023724509c00edfb8d0 +size 1563 diff --git a/tests/regression/png_output/hstack.png b/tests/regression/png_output/hstack.png new file mode 100644 index 0000000..9f38802 --- /dev/null +++ b/tests/regression/png_output/hstack.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:de4a51b0b54280b4fb99877df6eded6de487d4a1041059df23a010bd2bf2408f +size 58760 diff --git a/tests/regression/png_output/markdown.png b/tests/regression/png_output/markdown.png new file mode 100644 index 0000000..4f10ec3 --- /dev/null +++ b/tests/regression/png_output/markdown.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:68b9d71fabc5ad15dba05820c128fec3c8a1ba72355ac60c662df6c77d10e230 +size 290671 diff --git a/tests/regression/png_output/nested.png b/tests/regression/png_output/nested.png new file mode 100644 index 0000000..aa16e63 --- /dev/null +++ b/tests/regression/png_output/nested.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f2aa09e2709e1d4964ac8bf9c89f394c224b7070a86bd6fb66ee0345d5463a29 +size 87981 diff --git a/tests/regression/png_output/pre.png b/tests/regression/png_output/pre.png new file mode 100644 index 0000000..e9add6c --- /dev/null +++ b/tests/regression/png_output/pre.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3468ef5d5e43239d979d484eb9241cc3fd6e2a05630bb789ad946a200cb5be7b +size 56676 diff --git a/tests/regression/png_output/raw.png b/tests/regression/png_output/raw.png new file mode 100644 index 0000000..a1580a1 --- /dev/null +++ b/tests/regression/png_output/raw.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c1437709c85a9109c012aed9ae879f4712a18821551d85080b639383ac960af3 +size 14790 diff --git a/tests/regression/png_output/span.png b/tests/regression/png_output/span.png new file mode 100644 index 0000000..e5c8e35 --- /dev/null +++ b/tests/regression/png_output/span.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:32a7ed96e6a7cc476a3c8e2d82a23b9ccebde824369bcd1eaca5f4a64fa9d64e +size 30025 diff --git a/tests/regression/png_output/title.png b/tests/regression/png_output/title.png new file mode 100644 index 0000000..f2fddd5 --- /dev/null +++ b/tests/regression/png_output/title.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6c4c53ded490e43f8af0889b91f69d01cf383e4c1ae80ae56c5ad11477986e43 +size 23788 diff --git a/tests/regression/png_output/title_levels.png b/tests/regression/png_output/title_levels.png new file mode 100644 index 0000000..c5bba3f --- /dev/null +++ b/tests/regression/png_output/title_levels.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1ed40fd09464e1ea02aad9bc049f9345dd277e7b9108011b0e9a4070d7bd1045 +size 54662 diff --git a/tests/regression/png_output/vstack.png b/tests/regression/png_output/vstack.png new file mode 100644 index 0000000..4dc034d --- /dev/null +++ b/tests/regression/png_output/vstack.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:df81ae3bee1edef4e088f5e99e795985ede50b893b0cf314f698d8bd2bc042ab +size 51805 diff --git a/tests/regression/pybloqs_input/custom_css.py b/tests/regression/pybloqs_input/custom_css.py new file mode 100644 index 0000000..92f2fad --- /dev/null +++ b/tests/regression/pybloqs_input/custom_css.py @@ -0,0 +1,14 @@ +# Here we construct a subtype of pybloqs.Raw that includes some +# css resources. Because this is passed to `eval` we need to +# do this within a single expression. + +type( + # Type name... + "CustomCssBlock", + # Inherits from... + (pybloqs.Raw,), + # With attributes + { + "resource_deps": (pybloqs.static.Css(css_string="html{color:red;}", name="TestCss"),), + }, +)("Some content") diff --git a/tests/regression/pybloqs_input/custom_js_compressed.py b/tests/regression/pybloqs_input/custom_js_compressed.py new file mode 100644 index 0000000..b4ff6bc --- /dev/null +++ b/tests/regression/pybloqs_input/custom_js_compressed.py @@ -0,0 +1,14 @@ +# Here we construct a subtype of pybloqs.Raw that includes some +# javascript resources. Because this is passed to `eval` we need to +# do this within a single expression. + +type( + # Type name... + "CustomJSBlock", + # Inherits from... + (pybloqs.Raw,), + # With attributes + { + "resource_deps": (pybloqs.static.JScript(script_string='console.log("Foo ✔");', name="TestJs", encode=True),), + }, +)("Some content") diff --git a/tests/regression/pybloqs_input/custom_js_uncompressed.py b/tests/regression/pybloqs_input/custom_js_uncompressed.py new file mode 100644 index 0000000..95ded31 --- /dev/null +++ b/tests/regression/pybloqs_input/custom_js_uncompressed.py @@ -0,0 +1,14 @@ +# Here we construct a subtype of pybloqs.Raw that includes some +# javascript resources. Because this is passed to `eval` we need to +# do this within a single expression. + +type( + # Type name... + "CustomJSBlock", + # Inherits from... + (pybloqs.Raw,), + # With attributes + { + "resource_deps": (pybloqs.static.JScript(script_string='console.log("Foo");', name="TestJs", encode=False),), + }, +)("Some content") diff --git a/tests/regression/pybloqs_input/empty.py b/tests/regression/pybloqs_input/empty.py deleted file mode 100644 index 91d7fd4..0000000 --- a/tests/regression/pybloqs_input/empty.py +++ /dev/null @@ -1 +0,0 @@ -pybloqs.Block() diff --git a/tests/regression/test_html_output.py b/tests/regression/test_html_output.py index f088059..8b42652 100644 --- a/tests/regression/test_html_output.py +++ b/tests/regression/test_html_output.py @@ -1,6 +1,8 @@ import os import sys from pathlib import Path +import tempfile +from typing import Literal import pytest @@ -15,8 +17,8 @@ def input_file(test_name: str) -> Path: return ROOT_DIR / "pybloqs_input" / f"{test_name}.py" -def output_file(test_name: str) -> Path: - return ROOT_DIR / "html_output" / f"{test_name}.html" +def output_file(test_name: str, type: Literal["html", "png"]) -> Path: + return ROOT_DIR / f"{type}_output" / f"{test_name}.{type}" def read_block_for_test(test: str) -> pybloqs.BaseBlock: @@ -26,18 +28,23 @@ def read_block_for_test(test: str) -> pybloqs.BaseBlock: @pytest.mark.parametrize("test", tests) -def test_html_output(test): +@pytest.mark.parametrize("format", ["html", "png"]) +def test_output(test: str, format: Literal["html", "png"]): input_block = read_block_for_test(test) - with open(output_file(test)) as fp: + with open(output_file(test, format), "rb") as fp: expected = fp.read() - assert input_block.render_html() == expected + with tempfile.NamedTemporaryFile(suffix=f".{format}") as temp: + input_block.save(temp.name) + got = temp.read() + assert got == expected def bless(): for test in tests: + print("Rendering", test) input_block = read_block_for_test(test) - with open(output_file(test), "w") as f: - f.write(input_block.render_html()) + input_block.save(output_file(test, "html")) + input_block.save(output_file(test, "png")) if __name__ == "__main__":