# SPDX-License-Identifier: Apache-2.0
"""Bundle out/*.stl + out/parts.json into ../viewer.html (opens from disk, no server)."""
import base64
import json
from pathlib import Path

HERE = Path(__file__).parent
OUT = HERE / "out"
meshes = {n: base64.b64encode((OUT / f"{n}.stl").read_bytes()).decode()
          for n in ("top_shell", "bottom_shell", "eye_cup", "eye_lens", "read_button")}
parts = json.loads((OUT / "parts.json").read_text())
tpl = (HERE / "viewer_template.html").read_text()
html = tpl.replace("/*MESHES*/{}", json.dumps(meshes)).replace("/*PARTS*/{}", json.dumps(parts))
(HERE.parent / "viewer.html").write_text(html)
print("viewer.html", round(len(html) / 1e6, 2), "MB")
