Pluto.jl · Snapshot.jl · WasmTarget.jl · Native Therapy Components
Interactive Notebooks as Components
Many Julia workflows begin in a Pluto.jl notebook. With Snapshot.jl, you can compile those reactive notebooks to WasmGC and embed them directly inside any Therapy.jl route alongside @island controls and WasmMakie plots. No iframes, no running Julia server.
Interactive 2x2 matrix transformation and exact singular value decomposition rendered as live theme-reactive SVG in WebAssembly.
Matrix Geometry & Singular Values
Every $2 \times 2$ real matrix $A$ maps the unit circle onto an ellipse. Its singular value decomposition $A = U \Sigma V^\top$ breaks that action into three simple geometric steps: rotate by $V^\top$, stretch along orthogonal axes by $\sigma_1$ and $\sigma_2$, and rotate by $U$.
Everything below the sliders runs in your browser as WebAssembly via WasmTarget.jl. Drag the sliders to shear, stretch, or rotate $A$, and switch the site theme in the top bar to see the SVG diagram reskin with the page.
using PlutoUIRotation angle (degrees) =
Horizontal scale $s_x$ =
Vertical scale $s_y$ =
Horizontal shear $k$ =
struct SVD2x2
a11::Float64
a12::Float64
a21::Float64
a22::Float64
s1::Float64
s2::Float64
det_a::Float64
tr_a::Float64
cond_a::Float64
v1x::Float64
v1y::Float64
v2x::Float64
v2y::Float64
av1x::Float64
av1y::Float64
av2x::Float64
av2y::Float64
endBuild A = R(theta) * Shear(k) * Diag(sx, sy) and compute its exact 2x2 SVD.
"Build A = R(theta) * Shear(k) * Diag(sx, sy) and compute its exact 2x2 SVD."
function svd_2x2(theta_deg::Int, sx::Float64, sy::Float64, shear::Float64)::SVD2x2
th = Float64(theta_deg) * (3.141592653589793 / 180.0)
ct = cos(th)
st = sin(th)
m11 = sx
m12 = shear * sy
m22 = sy
a11 = ct * m11
a12 = ct * m12 - st * m22
a21 = st * m11
a22 = st * m12 + ct * m22
g11 = a11 * a11 + a21 * a21
g12 = a11 * a12 + a21 * a22
g22 = a12 * a12 + a22 * a22
tr_g = g11 + g22
diff_g = g11 - g22
disc = sqrt(diff_g * diff_g + 4.0 * g12 * g12)
lam1 = max(0.0, 0.5 * (tr_g + disc))
lam2 = max(0.0, 0.5 * (tr_g - disc))
s1 = sqrt(lam1)
s2 = sqrt(lam2)
phi = 0.5 * atan(2.0 * g12, diff_g)
v1x = cos(phi)
v1y = sin(phi)
v2x = -v1y
v2y = v1x
av1x = a11 * v1x + a12 * v1y
av1y = a21 * v1x + a22 * v1y
av2x = a11 * v2x + a12 * v2y
av2y = a21 * v2x + a22 * v2y
det_a = a11 * a22 - a12 * a21
tr_a = a11 + a22
cond_a = s2 > 1e-9 ? s1 / s2 : 999.9
return SVD2x2(
a11, a12, a21, a22,
s1, s2, det_a, tr_a, cond_a,
v1x, v1y, v2x, v2y,
av1x, av1y, av2x, av2y,
)
endFormat a Float64 to two decimal places.
"Format a Float64 to two decimal places."
function fmt2(x::Float64)::String
neg = x < 0.0
scaled = round(Int, abs(x) * 100.0)
whole = div(scaled, 100)
frac = mod(scaled, 100)
frac_str = frac < 10 ? string("0", frac) : string(frac)
return neg ? string("-", whole, ".", frac_str) : string(whole, ".", frac_str)
endRender the side-by-side unit circle and transformed ellipse as theme-reactive SVG.
"Render the side-by-side unit circle and transformed ellipse as theme-reactive SVG."
function render_svd_scene(theta_deg::Int, sx::Float64, sy::Float64, shear::Float64)
r = svd_2x2(theta_deg, sx, sy, shear)
scale = 48.0
cx1 = 150.0
cy1 = 142.0
cx2 = 470.0
cy2 = 142.0
parts = String[]
push!(parts, "<div style=\"width:100%;max-width:660px;margin:0 auto;\">")
push!(parts, "<svg viewBox=\"0 0 640 288\" width=\"100%\" style=\"display:block;border-radius:12px;border:1px solid color-mix(in oklab,var(--color-base-content) 14%,transparent);background:var(--color-base-200);\">")
push!(parts, "<rect x=\"14\" y=\"14\" width=\"272\" height=\"260\" rx=\"10\" fill=\"var(--color-base-100)\" stroke=\"color-mix(in oklab,var(--color-base-content) 10%,transparent)\" stroke-width=\"1\"/>")
push!(parts, "<rect x=\"334\" y=\"14\" width=\"292\" height=\"260\" rx=\"10\" fill=\"var(--color-base-100)\" stroke=\"color-mix(in oklab,var(--color-base-content) 10%,transparent)\" stroke-width=\"1\"/>")
push!(parts, "<text x=\"28\" y=\"36\" font-size=\"12\" font-weight=\"600\" fill=\"var(--color-base-content)\" opacity=\"0.75\">Input space: unit circle & v1, v2</text>")
push!(parts, "<text x=\"348\" y=\"36\" font-size=\"12\" font-weight=\"600\" fill=\"var(--color-base-content)\" opacity=\"0.75\">Output space: A(S1) & s1*u1, s2*u2</text>")
push!(parts, "<line x1=\"34\" y1=\"142\" x2=\"266\" y2=\"142\" stroke=\"var(--color-base-content)\" stroke-opacity=\"0.14\" stroke-width=\"1\"/>")
push!(parts, "<line x1=\"150\" y1=\"48\" x2=\"150\" y2=\"256\" stroke=\"var(--color-base-content)\" stroke-opacity=\"0.14\" stroke-width=\"1\"/>")
push!(parts, "<line x1=\"350\" y1=\"142\" x2=\"610\" y2=\"142\" stroke=\"var(--color-base-content)\" stroke-opacity=\"0.14\" stroke-width=\"1\"/>")
push!(parts, "<line x1=\"470\" y1=\"48\" x2=\"470\" y2=\"256\" stroke=\"var(--color-base-content)\" stroke-opacity=\"0.14\" stroke-width=\"1\"/>")
for g in -2:2
gf = Float64(g) * 0.5
x0 = cx2 + scale * (r.a11 * (-1.5) + r.a12 * gf)
y0 = cy2 - scale * (r.a21 * (-1.5) + r.a22 * gf)
x1 = cx2 + scale * (r.a11 * 1.5 + r.a12 * gf)
y1 = cy2 - scale * (r.a21 * 1.5 + r.a22 * gf)
push!(parts, string("<line x1=\"", fmt2(x0), "\" y1=\"", fmt2(y0), "\" x2=\"", fmt2(x1), "\" y2=\"", fmt2(y1), "\" stroke=\"var(--color-primary)\" stroke-opacity=\"0.12\" stroke-width=\"1\"/>"))
vx0 = cx2 + scale * (r.a11 * gf + r.a12 * (-1.5))
vy0 = cy2 - scale * (r.a21 * gf + r.a22 * (-1.5))
vx1 = cx2 + scale * (r.a11 * gf + r.a12 * 1.5)
vy1 = cy2 - scale * (r.a21 * gf + r.a22 * 1.5)
push!(parts, string("<line x1=\"", fmt2(vx0), "\" y1=\"", fmt2(vy0), "\" x2=\"", fmt2(vx1), "\" y2=\"", fmt2(vy1), "\" stroke=\"var(--color-primary)\" stroke-opacity=\"0.12\" stroke-width=\"1\"/>"))
end
push!(parts, "<circle cx=\"150\" cy=\"142\" r=\"48\" fill=\"color-mix(in oklab,var(--color-primary) 10%,transparent)\" stroke=\"var(--color-primary)\" stroke-width=\"2\"/>")
push!(parts, "<polygon points=\"")
nseg = 64
for i in 0:(nseg - 1)
ang = (6.283185307179586 * Float64(i)) / Float64(nseg)
ux = cos(ang)
uy = sin(ang)
ex = cx2 + scale * (r.a11 * ux + r.a12 * uy)
ey = cy2 - scale * (r.a21 * ux + r.a22 * uy)
if i > 0
push!(parts, " ")
end
push!(parts, string(fmt2(ex), ",", fmt2(ey)))
end
push!(parts, "\" fill=\"color-mix(in oklab,var(--color-primary) 14%,transparent)\" stroke=\"var(--color-primary)\" stroke-width=\"2.2\"/>")
v1px = fmt2(cx1 + scale * r.v1x)
v1py = fmt2(cy1 - scale * r.v1y)
v2px = fmt2(cx1 + scale * r.v2x)
v2py = fmt2(cy1 - scale * r.v2y)
push!(parts, string("<line x1=\"150\" y1=\"142\" x2=\"", v1px, "\" y2=\"", v1py, "\" stroke=\"var(--color-primary)\" stroke-width=\"3\" stroke-linecap=\"round\"/>"))
push!(parts, string("<circle cx=\"", v1px, "\" cy=\"", v1py, "\" r=\"4\" fill=\"var(--color-primary)\"/>"))
push!(parts, string("<line x1=\"150\" y1=\"142\" x2=\"", v2px, "\" y2=\"", v2py, "\" stroke=\"var(--color-secondary)\" stroke-width=\"3\" stroke-linecap=\"round\"/>"))
push!(parts, string("<circle cx=\"", v2px, "\" cy=\"", v2py, "\" r=\"4\" fill=\"var(--color-secondary)\"/>"))
av1px = fmt2(cx2 + scale * r.av1x)
av1py = fmt2(cy2 - scale * r.av1y)
av2px = fmt2(cx2 + scale * r.av2x)
av2py = fmt2(cy2 - scale * r.av2y)
push!(parts, string("<line x1=\"470\" y1=\"142\" x2=\"", av1px, "\" y2=\"", av1py, "\" stroke=\"var(--color-primary)\" stroke-width=\"3\" stroke-linecap=\"round\"/>"))
push!(parts, string("<circle cx=\"", av1px, "\" cy=\"", av1py, "\" r=\"4.5\" fill=\"var(--color-primary)\"/>"))
push!(parts, string("<line x1=\"470\" y1=\"142\" x2=\"", av2px, "\" y2=\"", av2py, "\" stroke=\"var(--color-secondary)\" stroke-width=\"3\" stroke-linecap=\"round\"/>"))
push!(parts, string("<circle cx=\"", av2px, "\" cy=\"", av2py, "\" r=\"4.5\" fill=\"var(--color-secondary)\"/>"))
push!(parts, "<text x=\"310\" y=\"147\" text-anchor=\"middle\" font-size=\"16\" font-weight=\"700\" fill=\"var(--color-primary)\">A</text>")
push!(parts, "<line x1=\"292\" y1=\"156\" x2=\"326\" y2=\"156\" stroke=\"var(--color-primary)\" stroke-width=\"1.8\"/>")
push!(parts, "</svg>")
push!(parts, "<div style=\"display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:10px;margin-top:12px;\">")
push!(parts, string("<div style=\"padding:10px 12px;border-radius:10px;border:1px solid color-mix(in oklab,var(--color-base-content) 12%,transparent);background:var(--color-base-100);\"><div style=\"font-size:11px;opacity:0.65;\">Singular value s1</div><div style=\"font-family:monospace;font-size:16px;font-weight:700;color:var(--color-primary);\">", fmt2(r.s1), "</div></div>"))
push!(parts, string("<div style=\"padding:10px 12px;border-radius:10px;border:1px solid color-mix(in oklab,var(--color-base-content) 12%,transparent);background:var(--color-base-100);\"><div style=\"font-size:11px;opacity:0.65;\">Singular value s2</div><div style=\"font-family:monospace;font-size:16px;font-weight:700;color:var(--color-secondary);\">", fmt2(r.s2), "</div></div>"))
push!(parts, string("<div style=\"padding:10px 12px;border-radius:10px;border:1px solid color-mix(in oklab,var(--color-base-content) 12%,transparent);background:var(--color-base-100);\"><div style=\"font-size:11px;opacity:0.65;\">Condition k(A)</div><div style=\"font-family:monospace;font-size:16px;font-weight:700;\">", fmt2(r.cond_a), "</div></div>"))
push!(parts, string("<div style=\"padding:10px 12px;border-radius:10px;border:1px solid color-mix(in oklab,var(--color-base-content) 12%,transparent);background:var(--color-base-100);\"><div style=\"font-size:11px;opacity:0.65;\">Area scale |det(A)|</div><div style=\"font-family:monospace;font-size:16px;font-weight:700;\">", fmt2(abs(r.det_a)), "</div></div>"))
push!(parts, "</div></div>")
return HTML(join(parts))
endfunction render_svd_summary(theta_deg::Int, sx::Float64, sy::Float64, shear::Float64)
r = svd_2x2(theta_deg, sx, sy, shear)
return HTML(string(
"<div style=\"font-family:monospace;font-size:13px;padding:10px 14px;border-radius:10px;border:1px solid color-mix(in oklab,var(--color-base-content) 12%,transparent);background:var(--color-base-100);\">",
"A = [", fmt2(r.a11), " ", fmt2(r.a12), "; ", fmt2(r.a21), " ", fmt2(r.a22), "] | ",
"tr(A) = ", fmt2(r.tr_a), " | ",
"det(A) = ", fmt2(r.det_a),
"</div>",
))
endTip: toggle light and dark mode in the top bar. Because the notebook mounts natively into Therapy's DOM instead of an iframe, its CSS tokens and SVG diagrams reskin with the page, and switching notebook tabs above runs through Therapy's View Transitions router.
Built for Scientific Julia Workflows
Explore data and models in Pluto, then publish them directly inside a real web application or documentation portal without rewriting your analysis in JavaScript.
One Component Tree
Compose SnapshotNotebook right next to Therapy navigation, authentication, @island forms, and Markdown prose. Shared CSS tokens keep typography and dark mode aligned automatically.
Zero-Server Interactivity
Pluto @bind sliders and inputs drive compiled Julia WasmGC modules directly in the reader's browser. Host on GitHub Pages, Cloudflare, or any static CDN with instant cold starts.
SPA View Transitions
Therapy's client router disposes the previous notebook's WasmGC runtime on therapy:router:before-swap and boots the next notebook cleanly during soft page transitions.
Embed in 3 Steps
Export your Pluto notebook with fragment = true, mount the output directory via staticfiles, and render SnapshotNotebook in any route.
using Snapshot
using Therapy
# 1. Export a reactive Pluto notebook as an embeddable HTML fragment + WasmGC islands
Snapshot.export_notebook(
"notebooks/svd_geometry.jl";
output_dir = "notebooks-static",
theme_picker = false,
fragment = true,
fragment_dependencies = :host,
assets_base = "__PI_ASSETS_BASE__",
)
# 2. Mount the exported assets in app.jl
app = App(
routes_dir = "src/routes",
components_dir = "src/components",
title = "Scientific Dashboard",
)
staticfiles(app, joinpath(@__DIR__, "notebooks-static"), "notebooks-static")
# 3. Render the notebook inside any route (src/routes/notebooks/index.jl)
() -> Div(
H1("Matrix Geometry Lab"),
SnapshotNotebook(
joinpath(@__DIR__, "..", "..", "notebooks-static", "svd_geometry.fragment.html");
assets_base = "/notebooks-static",
),
)Ready for Evolving WasmTarget & Julia WebAssembly
Both Therapy.jl and Snapshot.jl isolate compilation behind a thin Wasm backend adapter (WasmPlatformSpec, compile_island_wasm, and content-addressed on-disk caching). As WasmTarget.jl expands Julia language coverage and as Julia's native WebAssembly BinaryPlatforms support (Julia PR #64675) brings wasm32 JLL binaries and bridge modules, existing Therapy routes and embedded Snapshot notebooks gain broader Julia package support without rewriting your app.