euv-docs 0.48.1

Cross-platform documentation viewer and static site generator powered by euv and euv-ui.
Documentation
/// CLI flag enabling release profile compilation for multi-locale WASM bundles.
pub const DOCS_FLAG_RELEASE: &str = "--release";
/// CLI flag enabling debug profile compilation for multi-locale WASM bundles.
pub const DOCS_FLAG_DEBUG: &str = "--debug";
/// CLI flag selecting a single locale to build (`--locale <dir|prefix|label>`).
pub const DOCS_FLAG_LOCALE: &str = "--locale";
/// CLI flag forcing legacy single-locale static HTML output even when `locales:` is declared.
pub const DOCS_FLAG_STATIC_HTML: &str = "--static-html";

pub(crate) const BUNDLE_PKG_DIR: &str = "pkg";
pub(crate) const BUNDLE_INDEX_HTML: &str = "index.html";
pub(crate) const BUNDLE_NOT_FOUND_HTML: &str = "404.html";
pub(crate) const BUNDLE_PUBLIC_DIR: &str = "public";
pub(crate) const BUNDLE_BUILDER_DIR: &str = "euv-docs-wasm-builder";
pub(crate) const BUNDLE_TARGET_DIR: &str = "euv-docs-wasm-target";
pub(crate) const BUNDLE_CRATE_NAME: &str = "euv_docs_site";
pub(crate) const BUNDLE_SHELL_JSON_FILE: &str = "site_shell.json";
pub(crate) const BUNDLE_BODIES_BIN_FILE: &str = "site_bodies.euvz";
pub(crate) const BUNDLE_CARGO_TOML: &str = "Cargo.toml";
pub(crate) const BUNDLE_SRC_DIR: &str = "src";
pub(crate) const BUNDLE_LIB_RS: &str = "lib.rs";
pub(crate) const BUNDLE_WASM_PACK_BIN: &str = "wasm-pack";
pub(crate) const BUNDLE_ARG_BUILD: &str = "build";
pub(crate) const BUNDLE_ARG_TARGET: &str = "--target";
pub(crate) const BUNDLE_ARG_WEB: &str = "web";
pub(crate) const BUNDLE_ARG_NO_TS: &str = "--no-typescript";
pub(crate) const BUNDLE_ARG_OUT_DIR: &str = "--out-dir";
pub(crate) const BUNDLE_ARG_OUT_NAME: &str = "--out-name";
pub(crate) const BUNDLE_ARG_DEV: &str = "--dev";
pub(crate) const BUNDLE_ENV_TARGET_DIR: &str = "CARGO_TARGET_DIR";
pub(crate) const BUNDLE_ENV_RUSTC_WRAPPER: &str = "RUSTC_WRAPPER";
pub(crate) const BUNDLE_NAME_PREFIX: &str = "euv_docs_";
pub(crate) const BUNDLE_BG_WASM_SUFFIX: &str = "_bg.wasm";
pub(crate) const BUNDLE_JS_EXT: &str = ".js";
pub(crate) const BUNDLE_MJS_EXT: &str = ".mjs";
pub(crate) const BUNDLE_CSS_EXT: &str = ".css";
pub(crate) const BUNDLE_FORBIDDEN_DIRS: [&str; 2] = ["js", "webfonts"];
pub(crate) const BUNDLE_SKIP_FILES: [&str; 1] = [".DS_Store"];
pub(crate) const BUNDLE_EXPORT_PREFIX: &str = "export ";
pub(crate) const BUNDLE_EXPORT_BRACE: &str = "export {";
pub(crate) const BUNDLE_EXPORT_DEFAULT: &str = "export default ";
pub(crate) const BUNDLE_WASM_BINDGEN_VER: &str = "0.2";
pub(crate) const BUNDLE_DIR_CORE: &str = "core";
pub(crate) const BUNDLE_DIR_MACROS: &str = "macros";
pub(crate) const BUNDLE_DIR_UI: &str = "ui";
pub(crate) const BUNDLE_DEFAULT_LOCALE_SUFFIX: &str = "default";
pub(crate) const BUNDLE_ESC_AMP: &str = "&amp;";
pub(crate) const BUNDLE_ESC_LT: &str = "&lt;";
pub(crate) const BUNDLE_ESC_GT: &str = "&gt;";
pub(crate) const BUNDLE_ESC_QUOT: &str = "&quot;";
pub(crate) const BUNDLE_HTML_DOCTYPE_OPEN: &str = "<!DOCTYPE html>\n<html lang=\"";
pub(crate) const BUNDLE_ERR_NO_LOCALES: &str =
    "No locales declared in root README.md frontmatter for multi-locale WASM build";
pub(crate) const BUNDLE_ERR_NO_MATCHING_LOCALE: &str =
    "No locale matched the requested --locale filter";
pub(crate) const BUNDLE_ERR_WASM_PACK: &str = "wasm-pack build failed";
pub(crate) const BUNDLE_WRAPPER_LIB_RS: &str = r#"use wasm_bindgen::prelude::wasm_bindgen;

const SITE_SHELL_JSON: &str = include_str!("site_shell.json");
const SITE_BODIES_BIN: &[u8] = include_bytes!("site_bodies.euvz");

#[wasm_bindgen]
pub fn euv_docs_web_start() -> u64 {
    euv_docs::boot_wasm_docs_compressed_bundle(SITE_SHELL_JSON, SITE_BODIES_BIN)
}

#[wasm_bindgen]
pub fn euv_docs_render_route(route: &str) -> u64 {
    euv_docs::wasm_docs_render_route(route)
}

#[wasm_bindgen]
pub fn euv_docs_pointer_move(x: f32, y: f32) -> u64 {
    euv_docs::wasm_docs_pointer_move(x, y)
}

#[wasm_bindgen]
pub fn euv_docs_pointer_down(x: f32, y: f32) -> u64 {
    euv_docs::wasm_docs_pointer_down(x, y)
}

#[wasm_bindgen]
pub fn euv_docs_pointer_up(x: f32, y: f32) -> u64 {
    euv_docs::wasm_docs_pointer_up(x, y)
}

#[wasm_bindgen]
pub fn euv_docs_pointer_event(
    kind: u8,
    pointer_id: u32,
    is_touch: bool,
    x: f32,
    y: f32,
    pressure: f32,
) -> u64 {
    euv_docs::wasm_docs_pointer_event(kind, pointer_id, is_touch, x, y, pressure)
}

#[wasm_bindgen]
pub fn euv_docs_scroll(dx: f32, dy: f32) -> u64 {
    euv_docs::wasm_docs_scroll(dx, dy)
}

#[wasm_bindgen]
pub fn euv_docs_scroll_at(x: f32, y: f32, dx: f32, dy: f32) -> u64 {
    euv_docs::wasm_docs_scroll_at(x, y, dx, dy)
}

#[wasm_bindgen]
pub fn euv_docs_key_down(key: &str) -> u64 {
    euv_docs::wasm_docs_key_down(key)
}

#[wasm_bindgen]
pub fn euv_docs_key_down_mods(key: &str, ctrl: bool, shift: bool, alt: bool, meta: bool) -> u64 {
    euv_docs::wasm_docs_key_down_mods(key, ctrl, shift, alt, meta)
}

#[wasm_bindgen]
pub fn euv_docs_copy_selected() -> String {
    euv_docs::wasm_docs_copy_selected()
}

#[wasm_bindgen]
pub fn euv_docs_resize(width: u32, height: u32, dpr: f32) -> u64 {
    euv_docs::wasm_docs_resize(width, height, dpr)
}

#[wasm_bindgen]
pub fn euv_docs_resize_physical(phys_w: u32, phys_h: u32, dpr: f32) -> u64 {
    euv_docs::wasm_docs_resize_physical(phys_w, phys_h, dpr)
}

#[wasm_bindgen]
pub fn euv_docs_sync_safe_area() -> u64 {
    euv_docs::wasm_docs_sync_safe_area()
}

#[wasm_bindgen]
pub fn euv_docs_tick(dt_secs: f32) -> u64 {
    euv_docs::wasm_docs_tick(dt_secs)
}
"#;
pub(crate) const BUNDLE_HTML_HEAD_MID: &str = "\">\n<head>\n<meta charset=\"utf-8\"/>\n<meta name=\"viewport\" content=\"width=device-width,initial-scale=1,viewport-fit=cover\"/>\n<meta name=\"description\" content=\"";
pub(crate) const BUNDLE_HTML_DESC_END: &str = "\"/>\n<link rel=\"icon\" type=\"image/png\" href=\"https://devhub.vip/pages/docs/img/euv.png\"/>\n<title>";
pub(crate) const BUNDLE_HTML_STYLE_AND_BODY: &str = "</title>\n<style>:root{--euv-safe-top:env(safe-area-inset-top,0px);--euv-safe-right:env(safe-area-inset-right,0px);--euv-safe-bottom:env(safe-area-inset-bottom,0px);--euv-safe-left:env(safe-area-inset-left,0px);--euv-bg:#09090b;--euv-fg:#fafafa;--euv-muted:#a1a1aa;--euv-track:rgba(255,255,255,0.1);--euv-ring:rgba(255,255,255,0.1);--euv-surface:rgba(24,24,27,0.78);--euv-glow:rgba(99,102,241,0.18);}@media (prefers-color-scheme:light){:root{--euv-bg:#fafafa;--euv-fg:#09090b;--euv-muted:#52525b;--euv-track:rgba(9,9,11,0.09);--euv-ring:rgba(9,9,11,0.09);--euv-surface:rgba(255,255,255,0.88);--euv-glow:rgba(99,102,241,0.12);}}html,body{margin:0;padding:0;width:100vw;height:100vh;height:100dvh;overflow:hidden;background:var(--euv-bg);touch-action:none;-webkit-tap-highlight-color:transparent;-webkit-touch-callout:none;user-select:none;-webkit-user-select:none;outline:none;}canvas{display:block;width:100%;height:100%;touch-action:none;-webkit-tap-highlight-color:transparent;-webkit-touch-callout:none;user-select:none;-webkit-user-select:none;outline:none;}canvas:focus,canvas:focus-visible{outline:none;}#euv-wasm-loader{position:fixed;inset:0;z-index:9999;display:flex;align-items:center;justify-content:center;padding:24px;box-sizing:border-box;background:radial-gradient(620px circle at 50% 42%,var(--euv-glow),transparent 68%),var(--euv-bg);color:var(--euv-fg);font-family:-apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Inter,sans-serif;transition:opacity 220ms cubic-bezier(0.22,1,0.36,1);}.euv-wl-card{width:min(320px,86vw);display:flex;flex-direction:column;align-items:center;gap:14px;}.euv-wl-mark{width:48px;height:48px;border-radius:14px;display:flex;align-items:center;justify-content:center;background:var(--euv-surface);border:1px solid var(--euv-ring);box-shadow:0 8px 28px rgba(0,0,0,0.12);}.euv-wl-title{font-size:16px;font-weight:600;letter-spacing:-0.015em;text-align:center;line-height:1.3;margin:0;}.euv-wl-track{width:100%;height:4px;border-radius:999px;background:var(--euv-track);overflow:hidden;position:relative;}.euv-wl-bar{height:100%;width:0%;border-radius:999px;background:linear-gradient(90deg,#6366f1 0%,#38bdf8 55%,#22d3ee 100%);transition:width 140ms cubic-bezier(0.22,1,0.36,1);position:relative;overflow:hidden;}.euv-wl-bar::after{content:\"\";position:absolute;inset:0;background:linear-gradient(90deg,transparent 0%,rgba(255,255,255,0.45) 50%,transparent 100%);transform:translateX(-100%);animation:euv-wl-shimmer 1.3s ease-in-out infinite;}.euv-wl-meta{width:100%;display:flex;align-items:center;justify-content:space-between;gap:12px;font-size:12px;font-weight:500;color:var(--euv-muted);font-variant-numeric:tabular-nums;}.euv-wl-err{display:none;width:100%;flex-direction:column;align-items:center;gap:10px;text-align:center;}.euv-wl-err-msg{font-size:12px;color:#ef4444;line-height:1.45;}.euv-wl-retry{appearance:none;border:1px solid var(--euv-ring);background:var(--euv-surface);color:var(--euv-fg);font:600 12px/1 -apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,sans-serif;padding:8px 16px;border-radius:999px;cursor:pointer;}@keyframes euv-wl-shimmer{0%{transform:translateX(-100%);}100%{transform:translateX(220%);}}</style>\n</head>\n<body>\n<div id=\"euv-wasm-loader\" role=\"status\" aria-live=\"polite\" aria-label=\"Loading WebAssembly\"><div class=\"euv-wl-card\"><div class=\"euv-wl-mark\" aria-hidden=\"true\"><svg width=\"26\" height=\"26\" viewBox=\"0 0 24 24\" fill=\"none\"><defs><linearGradient id=\"euv-g\" x1=\"2\" y1=\"2\" x2=\"22\" y2=\"22\" gradientUnits=\"userSpaceOnUse\"><stop stop-color=\"#6366f1\"/><stop offset=\"0.55\" stop-color=\"#38bdf8\"/><stop offset=\"1\" stop-color=\"#22d3ee\"/></linearGradient></defs><path d=\"M12 2.5L20.5 7.4V16.6L12 21.5L3.5 16.6V7.4L12 2.5Z\" stroke=\"url(#euv-g)\" stroke-width=\"1.8\" stroke-linejoin=\"round\"/><path d=\"M12 6.8L16.8 9.6V15.2L12 18L7.2 15.2V9.6L12 6.8Z\" fill=\"url(#euv-g)\" fill-opacity=\"0.22\" stroke=\"url(#euv-g)\" stroke-width=\"1.4\" stroke-linejoin=\"round\"/><circle cx=\"12\" cy=\"12.4\" r=\"2.1\" fill=\"url(#euv-g)\"/></svg></div><div class=\"euv-wl-title\" id=\"euv-wasm-title\">";
pub(crate) const BUNDLE_HTML_LOADER_END: &str = "</div><div class=\"euv-wl-track\"><div class=\"euv-wl-bar\" id=\"euv-wasm-bar\"></div></div><div class=\"euv-wl-meta\"><span id=\"euv-wasm-status\">Downloading WebAssembly…</span><span id=\"euv-wasm-pct\">0%</span></div><div class=\"euv-wl-err\" id=\"euv-wasm-err\"><span class=\"euv-wl-err-msg\" id=\"euv-wasm-err-msg\"></span><button type=\"button\" class=\"euv-wl-retry\" id=\"euv-wasm-retry\">Retry</button></div></div></div>\n<script type=\"module\">\n";
pub(crate) const BUNDLE_HTML_BOOT_PREFIX: &str = "\nconst __euvWasmUrl='./pkg/";
pub(crate) const BUNDLE_HTML_BOOT_SUFFIX: &str = r#"';
const __euvLoader=document.getElementById('euv-wasm-loader');
const __euvBar=document.getElementById('euv-wasm-bar');
const __euvStatus=document.getElementById('euv-wasm-status');
const __euvPct=document.getElementById('euv-wasm-pct');
const __euvErr=document.getElementById('euv-wasm-err');
const __euvErrMsg=document.getElementById('euv-wasm-err-msg');
const __euvRetry=document.getElementById('euv-wasm-retry');
const __euvFmtMb=(b)=>(b/1048576).toFixed(1)+' MB';
const __euvSetProg=(p,msg)=>{const c=Math.max(0,Math.min(100,Math.round(p)));if(__euvBar)__euvBar.style.width=c+'%';if(__euvPct)__euvPct.textContent=c+'%';if(__euvStatus&&msg)__euvStatus.textContent=msg;};
async function __euvFetchWasm(url){
const resp=await fetch(url);
if(!resp.ok)throw new Error('HTTP '+resp.status);
const total=Number(resp.headers.get('content-length')||0);
if(!resp.body||typeof resp.body.getReader!=='function'){__euvSetProg(50,'Downloading WebAssembly…');return new Uint8Array(await resp.arrayBuffer());}
const reader=resp.body.getReader();
const chunks=[];let loaded=0;
for(;;){const r=await reader.read();if(r.done)break;chunks.push(r.value);loaded+=r.value.byteLength;if(total>0){__euvSetProg(Math.min(90,(loaded/total)*90),__euvFmtMb(loaded)+' / '+__euvFmtMb(total));}else{__euvSetProg(Math.min(85,85*(1-Math.exp(-loaded/3145728))),__euvFmtMb(loaded));}}
const out=new Uint8Array(loaded);let off=0;
for(const ch of chunks){out.set(ch,off);off+=ch.byteLength;}
return out;
}
async function __euvBoot(){
if(__euvErr)__euvErr.style.display='none';
__euvSetProg(0,'Downloading WebAssembly…');
try{
if(typeof fetch==='function'&&typeof ReadableStream!=='undefined'){
const bytes=await __euvFetchWasm(__euvWasmUrl);
__euvSetProg(92,'Compiling WebAssembly…');
await __wbg_init({ module_or_path: bytes });
}else{
__euvSetProg(50,'Loading WebAssembly…');
await __wbg_init({ module_or_path: __euvWasmUrl });
}
__euvSetProg(97,'Starting…');
euv_docs_web_start();
let obsPhysW=0,obsPhysH=0,lastDpr=0,lastPw=0,lastPh=0;
function syncSize(){const dpr=Math.max(1,Math.min(6,window.devicePixelRatio||1));const el=document.querySelector('canvas');let cssW=0,cssH=0;if(el){const r=el.getBoundingClientRect();if(r.width>=64&&r.height>=64){cssW=r.width;cssH=r.height;}}if(cssW<64||cssH<64){const vv=window.visualViewport;const vvScale=(vv&&typeof vv.scale==='number'&&vv.scale>0)?vv.scale:1;if(vv&&vvScale<=1.01&&vv.width>=64&&vv.height>=64){cssW=vv.width;cssH=vv.height;}else{const de=document.documentElement;cssW=(de&&de.clientWidth)||window.innerWidth||1200;cssH=(de&&de.clientHeight)||window.innerHeight||800;}}const estW=Math.max(64,Math.min(8192,Math.round(cssW*dpr)));const estH=Math.max(64,Math.min(8192,Math.round(cssH*dpr)));const useObs=obsPhysW>=64&&obsPhysH>=64&&Math.abs(obsPhysW-estW)<=2&&Math.abs(obsPhysH-estH)<=2;const pw=useObs?obsPhysW:estW;const ph=useObs?obsPhysH:estH;if(pw!==lastPw||ph!==lastPh||Math.abs(dpr-lastDpr)>0.005){lastPw=pw;lastPh=ph;lastDpr=dpr;euv_docs_resize_physical(pw,ph,dpr);euv_docs_sync_safe_area();requestAnimationFrame(()=>{euv_docs_tick(0);});}}
syncSize();
window.addEventListener('resize',syncSize);
window.addEventListener('orientationchange',()=>{syncSize();setTimeout(syncSize,120);});
document.addEventListener('fullscreenchange',()=>{syncSize();setTimeout(syncSize,60);});
if(window.visualViewport){window.visualViewport.addEventListener('resize',syncSize);}
if(typeof ResizeObserver==='function'){const target=document.querySelector('canvas')||document.documentElement;const ro=new ResizeObserver((entries)=>{if(entries&&entries.length>0){const e=entries[entries.length-1];const d=e.devicePixelContentBoxSize;if(d&&d.length>0){obsPhysW=Math.round(d[0].inlineSize||0);obsPhysH=Math.round(d[0].blockSize||0);}}syncSize();});window.__euvDocsRo=ro;try{ro.observe(target,{box:'device-pixel-content-box'});}catch(_){ro.observe(target);}}
if(typeof matchMedia==='function'){const watchDpr=()=>{const q='(resolution: '+(window.devicePixelRatio||1)+'dppx)';const m=matchMedia(q);window.__euvDocsDprMql=m;const on=()=>{if(window.__euvDocsDprMql===m){window.__euvDocsDprMql=null;}syncSize();watchDpr();};if(m.addEventListener){m.addEventListener('change',on,{once:true});}else if(m.addListener){m.addListener(on);}};watchDpr();}
if(typeof setInterval==='function'){window.__euvDocsDprTimer=setInterval(()=>{const cur=Math.max(1,Math.min(6,window.devicePixelRatio||1));if(Math.abs(cur-lastDpr)>0.005){syncSize();}},250);}
window.addEventListener('hashchange',()=>{const h=(window.location.hash||'').replace(/^#/,'');if(h.startsWith('/'))euv_docs_render_route(h);});
const cvs=document.querySelector('canvas');
if(cvs){
const pt=(ev)=>{const r=cvs.getBoundingClientRect();return [ev.clientX-r.left,ev.clientY-r.top];};
const isTouch=(ev)=>ev.pointerType==='touch';
const press=(ev)=>(typeof ev.pressure==='number'&&ev.pressure>0)?ev.pressure:(ev.buttons>0?1.0:0.0);
cvs.addEventListener('pointerdown',(ev)=>{const [x,y]=pt(ev);if(isTouch(ev)){try{cvs.setPointerCapture(ev.pointerId);}catch(_){}}euv_docs_pointer_event(1,ev.pointerId>>>0,isTouch(ev),x,y,press(ev)||1.0);});
cvs.addEventListener('pointermove',(ev)=>{const [x,y]=pt(ev);euv_docs_pointer_event(0,ev.pointerId>>>0,isTouch(ev),x,y,press(ev));});
cvs.addEventListener('pointerup',(ev)=>{const [x,y]=pt(ev);try{cvs.releasePointerCapture(ev.pointerId);}catch(_){}euv_docs_pointer_event(2,ev.pointerId>>>0,isTouch(ev),x,y,0.0);});
cvs.addEventListener('pointercancel',(ev)=>{const [x,y]=pt(ev);try{cvs.releasePointerCapture(ev.pointerId);}catch(_){}euv_docs_pointer_event(3,ev.pointerId>>>0,isTouch(ev),x,y,0.0);});
cvs.addEventListener('wheel',(ev)=>{ev.preventDefault();const [x,y]=pt(ev);const mult=ev.deltaMode===1?24:(ev.deltaMode===2?(window.innerHeight||800):1);euv_docs_scroll_at(x,y,ev.deltaX*mult,ev.deltaY*mult);},{passive:false});
}
window.addEventListener('keydown',(ev)=>{const cmd=!!(ev.ctrlKey||ev.metaKey);if((cmd&&(ev.key==='k'||ev.key==='K'||ev.key==='a'||ev.key==='A'))||(!cmd&&(ev.key==='PageDown'||ev.key==='PageUp'||ev.key==='Home'||ev.key==='End'||ev.key==='ArrowDown'||ev.key==='ArrowUp'))){ev.preventDefault();}euv_docs_key_down_mods(ev.key,!!ev.ctrlKey,!!ev.shiftKey,!!ev.altKey,!!ev.metaKey);});
document.addEventListener('copy',(ev)=>{const t=ev.target;if(t&&t.getAttribute&&t.getAttribute('data-euv-copy-proxy')==='1'){return;}const s=euv_docs_copy_selected();if(s&&ev.clipboardData){ev.clipboardData.setData('text/plain',s);ev.preventDefault();}});
let prevTs=performance.now();
function frame(ts){const curDpr=Math.max(1,Math.min(6,window.devicePixelRatio||1));if(Math.abs(curDpr-lastDpr)>0.005){syncSize();}const dt=Math.min(0.1,Math.max(0,(ts-prevTs)/1000));prevTs=ts;euv_docs_tick(dt);requestAnimationFrame(frame);}
requestAnimationFrame(frame);
__euvSetProg(100,'Ready');
requestAnimationFrame(()=>{if(__euvLoader){__euvLoader.style.opacity='0';setTimeout(()=>{if(__euvLoader)__euvLoader.remove();},240);}});
}catch(err){
if(__euvStatus)__euvStatus.textContent='Load failed';
if(__euvErrMsg)__euvErrMsg.textContent=(err&&err.message)?String(err.message):'Failed to load WebAssembly module';
if(__euvErr)__euvErr.style.display='flex';
}
}
if(__euvRetry)__euvRetry.addEventListener('click',__euvBoot);
__euvBoot();
</script>
</body>
</html>
"#;