diff --git a/deploy.sh b/deploy.sh index 11bf1cb..4f1f1ca 100755 --- a/deploy.sh +++ b/deploy.sh @@ -37,7 +37,8 @@ fi echo "[3/4] 上传 ${SRC} -> ${REMOTE_HOST}:${SITE_DIR}/" ssh -o RemoteCommand=none -o RequestTTY=no "$REMOTE_HOST" "mkdir -p ${SITE_DIR}" -rsync -az --delete -e "ssh -o RemoteCommand=none -o RequestTTY=no" "$SRC" "${REMOTE_HOST}:${SITE_DIR}/" +# --delete 但保护 /pyodide/(自托管运行时,仅手动管理,见 docs/实现方案.md 附录 B) +rsync -az --delete --exclude 'pyodide' -e "ssh -o RemoteCommand=none -o RequestTTY=no" "$SRC" "${REMOTE_HOST}:${SITE_DIR}/" echo "[4/4] 验证" sleep 1 diff --git a/docs/实现方案.md b/docs/实现方案.md index 8ef3e61..0578fc3 100644 --- a/docs/实现方案.md +++ b/docs/实现方案.md @@ -402,9 +402,11 @@ runs/YYYYMMDD-HHMMSS-<实验名>-/ | 公网链路 | `chenxy.biboer.cn`(Cloudflare DNS CNAME)→ mac-tunnel(`cloudflared`)→ `http://127.0.0.1:5050` | | 服务器 | m4(Homebrew nginx,监听 5050 仅 HTTP;站点目录 `/Users/gavin/www/chenxy`) | | 域名脚本 | m4 上 `./yuming.sh chenxy.biboer.cn 5050` 管理隧道与 nginx 占位配置 | -| 发布方式 | `./deploy.sh`(同步 core 到 web/py + rsync 到 m4 + 本地 HTTP 验证);`./deploy.sh local` 仅同步 core 供本地预览 | -| 已上线 | M0–M4 五个交互页(v8:修复 Pyodide 初始化时序竞态与 M3 表格渲染) | -| 注意 | m4 nginx master 由 root/launchd 管理,改配置后需 `sudo /opt/homebrew/bin/nginx -s reload`;静态资源经 Cloudflare 边缘缓存,改 JS/CSS 后需在 `index.html` 中递增 `?v=` 版本号强制刷新 | +| 发布方式 | `./deploy.sh`(构建 figma GUI → rsync 到 m4 → HTTP 验证);`./deploy.sh legacy` 部署旧版 web/;`./deploy.sh local` 仅同步 core | +| 已上线 | React 版六页面 GUI(Figma 重构):P1 正/反向设计、P2–P4、P5 扫描+蒙特卡洛(参数各自可调)、P6 导出;参数与计算结果 localStorage 持久化(刷新保持) | +| Pyodide 自托管 | `/pyodide/` 目录(v0.26.4 + numpy/scipy/openblas wheel ≈ 70MB,一次性下载至 m4,**rsync --delete 排除保护**);nginx `Cache-Control: immutable` 一年缓存 | +| 加载提速 | Service Worker 缓存 Pyodide 运行时与构建产物——二次访问引擎 ~0.5s 就绪(首次仍需网络下载);Pyodide `packageCacheDir:"idb"` 双保险;sw.js 响应 no-store 防钉死,注册 URL 带版本参数 | +| 注意 | m4 nginx master 由 root/launchd 管理,改配置需 `sudo /opt/homebrew/bin/nginx -s reload`;构建产物文件名带内容 hash 无需手动版本号;index.html 为 no-store | ### B.4 内容纪律(诚信红线在网站的落实) diff --git a/figma/dist/assets/index-PBaEiqxk.js b/figma/dist/assets/index-CbLgLCQA.js similarity index 96% rename from figma/dist/assets/index-PBaEiqxk.js rename to figma/dist/assets/index-CbLgLCQA.js index e9cbb8a..2e769eb 100644 --- a/figma/dist/assets/index-PBaEiqxk.js +++ b/figma/dist/assets/index-CbLgLCQA.js @@ -207,6 +207,6 @@ def p5_montecarlo(snr, repeats, seed, window, n_bins=26): "single": stats(st_s), "fiber": stats(st_f), "tau_true": 52.80, "xrange": [lo, hi], "snr": float(snr), "window": float(window), "repeats": int(repeats)}) -`,zQ=null,BQ=null;async function VQ(){window.loadPyodide||await new Promise((e,t)=>{let n=document.createElement(`script`);n.src=`https://cdn.jsdelivr.net/pyodide/v0.26.4/full/pyodide.js`,n.onload=()=>e(),n.onerror=()=>t(Error(`Pyodide 脚本加载失败(需访问 cdn.jsdelivr.net)`)),document.head.appendChild(n)}),zQ=await window.loadPyodide({indexURL:`https://cdn.jsdelivr.net/pyodide/v0.26.4/full/`}),await zQ.loadPackage([`numpy`,`scipy`]),zQ.runPython(`import sys; sys.path.insert(0, '/')`);for(let e of LQ){let t=await fetch(`py/${e}`);if(!t.ok)throw Error(`加载 ${e} 失败:HTTP ${t.status}`);let n=await t.text(),r=e.split(`/`).slice(0,-1).join(`/`);zQ.runPython(`import os; os.makedirs("/${r}", exist_ok=True)`),zQ.FS.writeFile(`/`+e,n)}zQ.runPython(`import importlib; importlib.invalidate_caches()`),zQ.runPython(RQ)}function HQ(){return BQ||=VQ().catch(e=>{throw BQ=null,e}),BQ}function UQ(){return BQ?zQ?`ready`:`loading`:`idle`}async function WQ(e,...t){await HQ();let n=zQ.globals.get(e);if(n===void 0)throw Error(`Python 函数 ${e} 未注册`);let r=await n(...t);return JSON.parse(r)}function GQ({name:e,size:t=18}){return(0,$.jsx)(`svg`,{width:t,height:t,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:{sliders:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M4 6h10M18 6h2M4 18h2M10 18h10M8 3v6M8 15v6M16 3v6M16 15v6`}),(0,$.jsx)(`path`,{d:`M14 6h4M6 18h4`})]}),pulse:(0,$.jsx)($.Fragment,{children:(0,$.jsx)(`path`,{d:`M3 12h4l2.2-6 4 12 2.2-6H21`})}),calibrate:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`}),(0,$.jsx)(`path`,{d:`M12 2v4M12 18v4M2 12h4M18 12h4M4.9 4.9l2.8 2.8M16.3 16.3l2.8 2.8M19.1 4.9l-2.8 2.8M7.7 16.3l-2.8 2.8`})]}),compare:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M4 19V5M4 19h16`}),(0,$.jsx)(`path`,{d:`m7 15 4-5 3 2 5-7`})]}),scan:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M4 4v5M4 15v5M20 4v5M20 15v5M4 4h5M15 4h5M4 20h5M15 20h5`}),(0,$.jsx)(`path`,{d:`M8 12h8`})]}),export:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M12 3v12M7 8l5-5 5 5`}),(0,$.jsx)(`path`,{d:`M5 14v6h14v-6`})]}),play:(0,$.jsx)(`path`,{d:`m9 7 8 5-8 5Z`}),copy:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`rect`,{x:`8`,y:`8`,width:`11`,height:`11`,rx:`2`}),(0,$.jsx)(`path`,{d:`M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3`})]}),refresh:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M20 7v5h-5M4 17v-5h5`}),(0,$.jsx)(`path`,{d:`M18.5 9A7 7 0 0 0 6.2 6.2L4 8M5.5 15A7 7 0 0 0 17.8 17.8L20 16`})]}),check:(0,$.jsx)(`path`,{d:`m5 12 4 4L19 6`}),info:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,$.jsx)(`path`,{d:`M12 11v6M12 7h.01`})]}),chevron:(0,$.jsx)(`path`,{d:`m9 18 6-6-6-6`}),loader:(0,$.jsx)($.Fragment,{children:(0,$.jsx)(`path`,{d:`M12 3a9 9 0 1 0 9 9`,className:`spin`})})}[e]})}var KQ=[`#6d5efc`,`#16a6a1`,`#ee8758`,`#db5ca7`],qQ=[{name:`参数与方案`,sub:`采样网格设计`,icon:`sliders`},{name:`原始采样`,sub:`波形生成与采样`,icon:`pulse`},{name:`校准与重建`,sub:`通道误差对比`,icon:`calibrate`},{name:`拟合与比较`,sub:`算法性能分析`,icon:`compare`},{name:`参数扫描`,sub:`稳定性趋势`,icon:`scan`},{name:`结果导出`,sub:`可复现记录包`,icon:`export`}];function JQ({title:e,note:t,children:n,className:r=``}){return(0,$.jsxs)(`section`,{className:`card ${r}`,children:[e&&(0,$.jsx)(`div`,{className:`card-head`,children:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{children:e}),t&&(0,$.jsx)(`p`,{children:t})]})}),n]})}function YQ({label:e,value:t,min:n,max:r,step:i=1,unit:a,onChange:o}){let s=(t-n)/(r-n)*100;return(0,$.jsxs)(`div`,{className:`control-row`,children:[(0,$.jsxs)(`div`,{className:`control-label`,children:[(0,$.jsx)(`span`,{children:e}),(0,$.jsxs)(`div`,{className:`number-box`,children:[(0,$.jsx)(`input`,{type:`number`,min:n,max:r,step:i,value:t,onChange:e=>o(Number(e.target.value))}),(0,$.jsx)(`em`,{children:a})]})]}),(0,$.jsx)(`input`,{className:`range`,style:{"--value":`${s}%`},type:`range`,min:n,max:r,step:i,value:t,onChange:e=>o(Number(e.target.value))}),(0,$.jsxs)(`div`,{className:`range-labels`,children:[(0,$.jsx)(`span`,{children:n}),(0,$.jsx)(`span`,{children:r})]})]})}function XQ({children:e,secondary:t=!1,icon:n,onClick:r,disabled:i=!1}){return(0,$.jsxs)(`button`,{className:t?`button secondary`:`button`,onClick:r,disabled:i,children:[n&&(0,$.jsx)(GQ,{name:n,size:16}),e]})}function ZQ({items:e}){return(0,$.jsx)(`div`,{className:`legend`,children:e.map(e=>(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`i`,{style:{background:e.dotted?`transparent`:e.color,borderColor:e.color},className:e.dotted?`dot`:``}),(0,$.jsx)(`span`,{children:e.label})]},e.label))})}function QQ({title:e,text:t,action:n}){return(0,$.jsxs)(`div`,{className:`hero-row`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{children:e}),(0,$.jsx)(`p`,{children:t})]}),n&&(0,$.jsx)(`div`,{className:`action-row`,children:n})]})}function $Q({value:e,label:t,note:n,highlight:r=!1}){return(0,$.jsxs)(`div`,{className:`metric ${r?`highlight`:``}`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{children:t}),(0,$.jsx)(`strong`,{children:e})]}),n&&(0,$.jsx)(`em`,{children:n})]})}function e$({label:e,options:t,value:n,onChange:r}){return(0,$.jsxs)(`label`,{className:`select-row`,children:[(0,$.jsx)(`span`,{children:e}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`select`,{value:n,onChange:e=>r(e.target.value),children:t.map(e=>(0,$.jsx)(`option`,{value:e.v,children:e.label},e.v))}),(0,$.jsx)(GQ,{name:`chevron`,size:14})]})]})}function t$({onClick:e,running:t,label:n=`运行计算`}){return(0,$.jsx)(XQ,{icon:t?`loader`:`play`,onClick:e,disabled:t,children:t?`计算中…`:n})}function n$(){let[e,t]=(0,v.useState)(`loading`),[n,r]=(0,v.useState)(``);return(0,v.useEffect)(()=>{HQ().then(()=>t(`ready`)).catch(e=>{r(String(e)),t(`error`)})},[]),e===`ready`?null:(0,$.jsx)(`div`,{className:`engine-overlay`,children:(0,$.jsxs)(`div`,{className:`engine-box`,children:[(0,$.jsx)(`div`,{className:`engine-mark`,children:(0,$.jsx)(GQ,{name:`pulse`,size:20})}),e===`loading`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`b`,{children:`正在启动科学计算引擎`}),(0,$.jsx)(`span`,{children:`Pyodide + numpy / scipy(约 40 MB,首次加载较慢,之后有缓存)`}),(0,$.jsx)(`div`,{className:`engine-bar`,children:(0,$.jsx)(`i`,{})})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`b`,{children:`计算引擎加载失败`}),(0,$.jsx)(`span`,{children:n}),(0,$.jsx)(XQ,{onClick:()=>location.reload(),icon:`refresh`,children:`刷新重试`})]})]})})}var r$={params:{}},i$=`fdets.v2.`;function a$(e,t){try{let n=localStorage.getItem(i$+e);if(n==null)return t;let r=JSON.parse(n);return Array.isArray(t)!==Array.isArray(r)||typeof r!=typeof t?t:r}catch{return t}}function o$(e,t){try{localStorage.setItem(i$+e,JSON.stringify(t))}catch{}}function s$(e,t){let[n,r]=(0,v.useState)(()=>a$(e,t));return(0,v.useEffect)(()=>{o$(e,n)},[e,n]),[n,r]}function c$(){let[e,t]=s$(`p1.tau`,52.8),[n,r]=s$(`p1.dt`,10),[i,a]=s$(`p1.ng`,1.468),[o,s]=s$(`p1.mode`,`forward`),[c,l]=s$(`p1.lengths`,[0,9.7,19.4,29.1]),[u,d]=s$(`p1.targets`,[0,2.5,5,7.5]),[f,p]=(0,v.useState)(!1),[m,h]=(0,v.useState)(!1),[g,_]=(0,v.useState)(null),[y,b]=(0,v.useState)(``),x=(0,v.useMemo)(()=>c.map(e=>e*i/.2998%n),[c,i,n]),S=async()=>{p(!0),b(``);try{let e=await WQ(`p1_forward`,c,i,n,u);_(e)}catch(e){b(String(e))}p(!1)},C=()=>{navigator.clipboard?.writeText(JSON.stringify(o===`forward`?{tau:e,dt:n,ng:i,lengths:c}:{tau:e,dt:n,ng:i,targets:u},null,2)),h(!0),window.setTimeout(()=>h(!1),1400)},w=(0,v.useRef)(!1);(0,v.useEffect)(()=>{w.current||(w.current=!0,S())},[]),g&&(r$.p1=g),r$.params={...r$.params,tau:e,dt:n,ng:i,lengths:c,targets:u,mode:o};let T=[...new Set(u.map(e=>Number((e%n+n)%n)))].sort((e,t)=>e-t),E=T.slice(1).map((e,t)=>e-T[t]),D=n/Math.max(1,T.length),O=E.length?Math.max(...E.map(e=>Math.abs(e-D))):0;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`hero-row`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{children:`参数与方案`}),(0,$.jsx)(`p`,{children:`建立光纤长度、传播延时与等效采样相位之间的映射关系。`})]}),(0,$.jsxs)(`div`,{className:`action-row`,children:[(0,$.jsx)(XQ,{secondary:!0,icon:m?`check`:`copy`,onClick:C,children:m?`已复制`:`复制参数`}),(0,$.jsx)(t$,{onClick:S,running:f})]})]}),(0,$.jsxs)(`div`,{className:`mode-switch`,children:[(0,$.jsxs)(`button`,{className:o===`forward`?`active`:``,onClick:()=>s(`forward`),children:[`正向计算 `,(0,$.jsx)(`span`,{children:`长度 → 延时 / 相位`})]}),(0,$.jsxs)(`button`,{className:o===`reverse`?`active`:``,onClick:()=>s(`reverse`),children:[`反向设计 `,(0,$.jsx)(`span`,{children:`目标相位 → 候选长度`})]})]}),(0,$.jsxs)(`div`,{className:`principle-strip`,children:[(0,$.jsxs)(`div`,{className:`principle-title`,children:[(0,$.jsx)(`span`,{children:`测量链路`}),(0,$.jsx)(`b`,{children:`光学游标卡尺`})]}),(0,$.jsx)(`div`,{className:`principle-flow`,children:[[`01`,`荧光衰减`,`I(t)`],[`02`,`四路光纤`,`时间编码`],[`03`,`光电探测`,`PD + TIA`],[`04`,`低速采样`,`ADC · 10 ns`],[`05`,`校准重建`,`归位 + 交织`],[`06`,`寿命拟合`,`τ₂ 估计`]].map(([e,t,n],r)=>(0,$.jsxs)(`div`,{className:`principle-step`,children:[(0,$.jsx)(`small`,{children:e}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`b`,{children:t}),(0,$.jsx)(`em`,{children:n})]}),r<5&&(0,$.jsx)(GQ,{name:`chevron`,size:13})]},e))}),(0,$.jsxs)(`div`,{className:`model-formula`,children:[(0,$.jsx)(`span`,{children:`信号模型`}),(0,$.jsxs)(`b`,{children:[`I`,(0,$.jsx)(`sub`,{children:`true`}),`(t) = 0.16e`,(0,$.jsx)(`sup`,{children:`−t/0.6`}),` + 0.84e`,(0,$.jsx)(`sup`,{children:`−t/52.8`})]})]})]}),y&&(0,$.jsxs)(`div`,{className:`insight`,style:{marginBottom:12},children:[(0,$.jsx)(GQ,{name:`info`}),(0,$.jsx)(`span`,{children:y})]}),(0,$.jsxs)(`div`,{className:`workspace-grid`,children:[(0,$.jsxs)(`div`,{className:`stack`,children:[(0,$.jsx)(JQ,{title:`基础参数`,note:`荧光衰减与 ADC 采样条件`,children:(0,$.jsxs)(`div`,{className:`basic-grid`,children:[(0,$.jsx)(YQ,{label:`荧光寿命 τ₂`,value:e,min:10,max:100,step:.5,unit:`ns`,onChange:t}),(0,$.jsx)(YQ,{label:`采样间隔 Δt`,value:n,min:2,max:50,step:.5,unit:`ns`,onChange:r}),(0,$.jsx)(YQ,{label:`群折射率 nᵍ`,value:i,min:1.44,max:1.5,step:.001,unit:``,onChange:a})]})}),o===`forward`?(0,$.jsxs)(JQ,{title:`光纤通道`,note:`当前使用 4 路延时光纤`,children:[(0,$.jsx)(`div`,{className:`channel-inputs`,children:c.map((e,t)=>(0,$.jsxs)(`label`,{children:[(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`i`,{style:{background:KQ[t]}}),`CH`,t+1]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`input`,{type:`number`,value:e,step:.1,onChange:e=>l(c.map((n,r)=>r===t?Number(e.target.value):n))}),(0,$.jsx)(`em`,{children:`m`})]})]},t))}),(0,$.jsxs)(`div`,{className:`tip`,children:[(0,$.jsx)(GQ,{name:`info`,size:16}),(0,$.jsxs)(`span`,{children:[`建议相邻通道保持约 `,(29.1/3).toFixed(1),` m 长度差,以获得均匀的 `,(n/4).toFixed(2),` ns 相位步长。`]})]})]}):(0,$.jsxs)(JQ,{title:`目标相位`,note:`期望各通道在单个 ADC 周期内的等效位置`,children:[(0,$.jsx)(`div`,{className:`channel-inputs`,children:u.map((e,t)=>(0,$.jsxs)(`label`,{children:[(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`i`,{style:{background:KQ[t]}}),`φ`,t+1]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`input`,{type:`number`,value:e,step:.5,onChange:e=>d(u.map((n,r)=>r===t?Number(e.target.value):n))}),(0,$.jsx)(`em`,{children:`ns`})]})]},t))}),(0,$.jsxs)(`div`,{className:`tip`,children:[(0,$.jsx)(GQ,{name:`info`,size:16}),(0,$.jsxs)(`span`,{children:[`默认均匀网格 j·Δt/4(当前 Δt = `,n,` ns → 步长 `,(n/4).toFixed(2),` ns);输入非均匀相位时,软件给出逐相位最短候选并提示网格不均匀——这本身是教学点。`]})]})]})]}),(0,$.jsxs)(`div`,{className:`stack`,children:[(0,$.jsxs)(`div`,{className:`summary-card`,children:[(0,$.jsx)(`div`,{className:`summary-icon`,children:(0,$.jsx)(GQ,{name:`check`})}),o===`forward`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{children:`等效采样网格(正向)`}),(0,$.jsxs)(`strong`,{children:[(g?.sorted??x).map(e=>e.toFixed(2)).join(` / `),` ns`]}),(0,$.jsxs)(`p`,{children:[`理想步长 `,(n/4).toFixed(2),` ns · 最大间隔偏差 `,g?g.uniformity.max_gap_dev_ns.toExponential(1):`—`]})]}),(0,$.jsxs)(`div`,{className:`uniform`,children:[`均匀性 `,(0,$.jsxs)(`b`,{children:[g?Math.max(0,100-g.uniformity.max_gap_dev_ns/(n/4)*100).toFixed(2):`—`,`%`]})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{children:`目标相位(反向)`}),(0,$.jsxs)(`strong`,{children:[T.map(e=>e.toFixed(2)).join(` / `),` ns`]}),(0,$.jsxs)(`p`,{children:[g?.is_uniform_grid?`均匀网格 · 构造式推荐解`:`非均匀网格 · 逐相位最短候选`,` · 与理想步长最大偏差 `,O.toFixed(2),` ns`]})]}),(0,$.jsxs)(`div`,{className:`uniform`,children:[`网格判定 `,(0,$.jsx)(`b`,{children:g?.is_uniform_grid??O<1e-6?`均匀`:`非均匀`})]})]})]}),(0,$.jsx)(JQ,{title:`延时–相位映射`,note:`各通道在单个 ADC 周期内的等效位置`,children:(0,$.jsxs)(`div`,{className:`phase-chart`,children:[(0,$.jsxs)(`div`,{className:`phase-axis`,children:[[0,n/4,n/2,3*n/4,n].map(e=>(0,$.jsx)(`span`,{style:{left:`${e/n*100}%`},children:e.toFixed(1)},e)),(o===`forward`?g?g.channels.map(e=>e.phase_ns):x:T).map((e,t)=>(0,$.jsxs)(`div`,{className:`phase-dot`,style:{left:`${6+e/n*88}%`,bottom:`${30+t*14}%`,background:KQ[t]},children:[(0,$.jsx)(`b`,{children:o===`forward`?`CH${t+1}`:`φ${t+1}`}),(0,$.jsxs)(`small`,{children:[e.toFixed(2),` ns`]})]},t))]}),(0,$.jsx)(`div`,{className:`phase-label`,children:o===`forward`?`采样相位 (ns) —— 由光纤长度算出`:`目标相位 (ns) —— 待反推光纤长度`})]})}),(0,$.jsx)(JQ,{title:o===`forward`?`正向:通道计算结果`:g?.recommended?`反向:构造式推荐解`:`反向:逐相位最短候选`,note:o===`forward`?void 0:g?.recommended?g.construction??void 0:`目标非均匀网格——无构造式统一解,下表为每相位的最短光纤`,children:(0,$.jsx)(`div`,{className:`table-scroll`,children:(0,$.jsxs)(`table`,{children:[(0,$.jsx)(`thead`,{children:(0,$.jsx)(`tr`,{children:o===`forward`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`th`,{children:`通道`}),(0,$.jsx)(`th`,{children:`光纤长度`}),(0,$.jsx)(`th`,{children:`传播延时`}),(0,$.jsx)(`th`,{children:`采样相位`})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`th`,{children:`目标相位`}),(0,$.jsx)(`th`,{children:g?.recommended?`通道序 k`:`周期数 m`}),(0,$.jsx)(`th`,{children:`传播延时`}),(0,$.jsx)(`th`,{children:`候选长度`})]})})}),(0,$.jsxs)(`tbody`,{children:[o===`forward`?(g?.channels??[]).map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:(0,$.jsxs)(`b`,{children:[`CH`,e.index+1]})}),(0,$.jsxs)(`td`,{children:[e.length_m.toFixed(1),` m`]}),(0,$.jsxs)(`td`,{children:[e.delay_ns.toFixed(2),` ns`]}),(0,$.jsxs)(`td`,{className:`accent`,children:[e.phase_ns.toFixed(2),` ns`]})]},e.index)):(g?.recommended??[]).map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:(0,$.jsxs)(`b`,{children:[e.phase_ns.toFixed(2),` ns`]})}),(0,$.jsx)(`td`,{children:e.k}),(0,$.jsxs)(`td`,{children:[e.delay_ns.toFixed(2),` ns`]}),(0,$.jsxs)(`td`,{className:`accent`,children:[e.length_m.toFixed(2),` m`]})]},e.k)),o===`reverse`&&!g?.recommended&&(g?.candidates_short??[]).map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:(0,$.jsxs)(`b`,{children:[e.phase_ns.toFixed(2),` ns`]})}),(0,$.jsx)(`td`,{children:e.m}),(0,$.jsxs)(`td`,{children:[e.delay_ns.toFixed(2),` ns`]}),(0,$.jsxs)(`td`,{className:`accent`,children:[e.length_m.toFixed(2),` m`]})]},e.phase_ns))]})]})})})]})]})]})}function l$(){let[e,t]=s$(`p2.snr`,50),[n,r]=s$(`p2.bits`,`12`),[i,a]=s$(`p2.window`,`400`),[o,s]=s$(`p2.ideal`,!1),[c,l]=s$(`p2.seed`,42),[u,d]=(0,v.useState)(null),[f,p]=(0,v.useState)(!1),[m,h]=(0,v.useState)(``),g=async(t=c)=>{p(!0),h(``);try{let r=await WQ(`p2_sample`,52.8,Number(i),e,Number(n),o,t);d(r)}catch(e){h(String(e))}p(!1)},_=(0,v.useRef)(!1);(0,v.useEffect)(()=>{_.current||(_.current=!0,g())},[]),u&&(r$.p2=u),r$.params={...r$.params,p2_snr:e,p2_bits:n,p2_window:i,p2_ideal:o,p2_seed:c};let y=(0,v.useMemo)(()=>u?{grid:{left:52,right:20,top:34,bottom:40},tooltip:FQ(),legend:PQ,xAxis:AQ(),yAxis:jQ(),series:[MQ(u.t_cont,u.y_cont,`理想连续信号`,OQ.truth),NQ(u.t_single,u.y_single,`10 ns 直接采样`,OQ.orange,6),NQ(u.t_multi,u.y_multi,`四通道等效采样`,OQ.blue,3.5)]}:null,[u]),b=(Number(i)/52.8).toFixed(2);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(QQ,{title:`原始采样`,text:`对比低速 ADC 直接采样与四通道等效补点后的波形细节。`,action:(0,$.jsx)(XQ,{icon:`refresh`,onClick:()=>{let e=Math.floor(Math.random()*9e4)+1e3;l(e),g(e)},disabled:f,children:f?`采样中…`:`重新采样`})}),m&&(0,$.jsxs)(`div`,{className:`insight`,style:{marginBottom:12},children:[(0,$.jsx)(GQ,{name:`info`}),(0,$.jsx)(`span`,{children:m})]}),(0,$.jsxs)(`div`,{className:`metric-grid`,children:[(0,$.jsx)($Q,{value:u?String(u.n_single):`—`,label:`单通道采样点`,note:`${i} ns 窗口`}),(0,$.jsx)($Q,{value:u?String(u.n_multi):`—`,label:`四通道总点数`,note:`${(Number(i)/4).toFixed(0)}× 密度`,highlight:!0}),(0,$.jsx)($Q,{value:String(c),label:`当前随机种子`,note:`可复现`})]}),(0,$.jsxs)(`div`,{className:`workspace-grid wide-left`,children:[(0,$.jsxs)(JQ,{title:`时间–强度采样对比`,note:u?`NLS 拟合寿命 τ̂ = ${u.tau_hat.toFixed(3)} ns · 相对偏差 ${(u.rel_error*100).toFixed(2)}%`:`四相位补点显著提升了衰减曲线的时间分辨率`,children:[(0,$.jsx)(ZQ,{items:[{color:OQ.truth,label:`理想连续信号`},{color:OQ.orange,label:`10 ns 直接采样`,dotted:!0},{color:OQ.blue,label:`四通道等效采样`,dotted:!0}]}),y?(0,$.jsx)(IQ,{option:y,height:280}):(0,$.jsx)(`div`,{className:`chart-placeholder`}),(0,$.jsxs)(`div`,{className:`insight`,children:[(0,$.jsx)(GQ,{name:`info`}),(0,$.jsxs)(`span`,{children:[`当前 `,i,` ns 窗口覆盖约 `,(0,$.jsxs)(`b`,{children:[b,` τ₂`]}),`,信号已充分衰减;四通道有效采样密度提升 4 倍。注意:`,(Number(i)/4).toFixed(1),` ns 等效采样网格不等同于整机时间分辨率。`]})]})]}),(0,$.jsxs)(JQ,{title:`采样条件`,note:`修改后点击「重新采样」应用`,children:[(0,$.jsxs)(`div`,{className:`sampling-grid`,children:[(0,$.jsx)(YQ,{label:`信噪比 SNR`,value:e,min:20,max:80,unit:`dB`,onChange:t}),(0,$.jsx)(e$,{label:`ADC 位数`,options:[{v:`8`,label:`8 bit`},{v:`10`,label:`10 bit`},{v:`12`,label:`12 bit`},{v:`14`,label:`14 bit`}],value:n,onChange:r}),(0,$.jsx)(e$,{label:`记录窗口`,options:[{v:`40`,label:`40 ns`},{v:`100`,label:`100 ns`},{v:`200`,label:`200 ns`},{v:`400`,label:`400 ns`}],value:i,onChange:a}),(0,$.jsxs)(`label`,{className:`toggle-row`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`b`,{children:`理想无噪`}),(0,$.jsx)(`span`,{children:`关闭噪声与量化模拟`})]}),(0,$.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked)}),(0,$.jsx)(`i`,{})]})]}),(0,$.jsxs)(`div`,{className:`tip`,style:{marginTop:12},children:[(0,$.jsx)(GQ,{name:`info`,size:16}),(0,$.jsx)(`span`,{children:`窗口 40 ns(≈0.76τ)时仅 4 个采样点,信号才衰减到初值 47%——这正是四相位方案要解决的困境。`})]})]})]})]})}function u$(){let[e,t]=s$(`p3.gain`,1),[n,r]=s$(`p3.delay`,1),[i,a]=s$(`p3.baseline`,1),[o,s]=s$(`p3.snr`,50),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(``),m=async()=>{d(!0),p(``);try{let t=await WQ(`p3_calibrate`,e,n,i,o,42);l(t)}catch(e){p(String(e))}d(!1)},h=(0,v.useRef)(!1);(0,v.useEffect)(()=>{h.current||(h.current=!0,m())},[]),c&&(r$.p3=c),r$.params={...r$.params,p3_gain:e,p3_delay:n,p3_baseline:i,p3_snr:o};let g=(0,v.useMemo)(()=>{if(!c)return null;let e=c.calibrated.t.map(e=>[e,Math.exp(-e/c.tau_true)]);return{grid:{left:52,right:20,top:34,bottom:40},tooltip:FQ(),legend:PQ,xAxis:AQ(),yAxis:jQ(),series:[{...MQ([],[],`理论真值`,OQ.truth),data:e},NQ(c.raw.t,c.raw.y,`不校准`,OQ.orange,3),NQ(c.nominal.t,c.nominal.y,`基线 + 增益`,OQ.teal,3),NQ(c.calibrated.t,c.calibrated.y,`完整校准`,OQ.blue,3)]}},[c]),_=e=>e==null?null:Math.abs(e-(c?.tau_true??52.8))/(c?.tau_true??52.8)*100;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(QQ,{title:`校准与重建`,text:`注入通道硬件误差,观察不同校准层级对曲线连续度与寿命估计的影响。`,action:(0,$.jsx)(t$,{onClick:m,running:u,label:`运行校准对比`})}),f&&(0,$.jsxs)(`div`,{className:`insight`,style:{marginBottom:12},children:[(0,$.jsx)(GQ,{name:`info`}),(0,$.jsx)(`span`,{children:f})]}),(0,$.jsxs)(`div`,{className:`workspace-grid wide-left`,children:[(0,$.jsxs)(`div`,{className:`stack`,children:[(0,$.jsxs)(JQ,{title:`重建曲线对比`,note:`完整校准后数据点重新贴近理论真值`,children:[(0,$.jsx)(ZQ,{items:[{color:OQ.truth,label:`理论真值`},{color:OQ.orange,label:`不校准`},{color:OQ.teal,label:`基线 + 增益`},{color:OQ.blue,label:`完整校准`}]}),g?(0,$.jsx)(IQ,{option:g,height:280}):(0,$.jsx)(`div`,{className:`chart-placeholder`})]}),(0,$.jsx)(JQ,{title:`方案对比`,children:(0,$.jsx)(`div`,{className:`table-scroll`,children:(0,$.jsxs)(`table`,{children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{children:`方案`}),(0,$.jsx)(`th`,{children:`τ̂ (ns)`}),(0,$.jsx)(`th`,{children:`相对偏差`}),(0,$.jsx)(`th`,{children:`有效点数`}),(0,$.jsx)(`th`,{children:`mean_jump`})]})}),(0,$.jsx)(`tbody`,{children:c?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:(0,$.jsx)(`b`,{children:`不校准重建`})}),(0,$.jsx)(`td`,{children:c.raw.tau?.toFixed(3)??`—`}),(0,$.jsx)(`td`,{className:_(c.raw.tau)>2?`bad`:``,children:_(c.raw.tau)==null?`—`:`+${_(c.raw.tau).toFixed(2)}%`}),(0,$.jsx)(`td`,{children:c.raw.n}),(0,$.jsx)(`td`,{children:c.raw.jump.toFixed(4)})]}),(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:(0,$.jsx)(`b`,{children:`基线 + 增益`})}),(0,$.jsx)(`td`,{children:c.nominal.tau?.toFixed(3)??`—`}),(0,$.jsx)(`td`,{className:_(c.nominal.tau)>2?`bad`:``,children:_(c.nominal.tau)==null?`—`:`+${_(c.nominal.tau).toFixed(2)}%`}),(0,$.jsx)(`td`,{children:c.nominal.n}),(0,$.jsx)(`td`,{children:c.nominal.jump.toFixed(4)})]}),(0,$.jsxs)(`tr`,{className:`best`,children:[(0,$.jsx)(`td`,{children:(0,$.jsx)(`b`,{children:`完整校准`})}),(0,$.jsx)(`td`,{children:c.calibrated.tau?.toFixed(3)??`—`}),(0,$.jsx)(`td`,{className:`good`,children:_(c.calibrated.tau)==null?`—`:`+${_(c.calibrated.tau).toFixed(2)}%`}),(0,$.jsx)(`td`,{children:c.calibrated.n}),(0,$.jsx)(`td`,{children:c.calibrated.jump.toFixed(4)})]})]}):(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:5,style:{textAlign:`center`,padding:`20px`},children:`点击「运行校准对比」开始`})})})]})})})]}),(0,$.jsxs)(JQ,{title:`误差注入`,note:`CH1 作为无误差参考通道`,children:[(0,$.jsxs)(`div`,{className:`error-grid`,children:[(0,$.jsx)(YQ,{label:`通道增益失配`,value:e,min:0,max:1.5,step:.05,unit:`×`,onChange:t}),(0,$.jsx)(YQ,{label:`延时误差`,value:n,min:0,max:2,step:.1,unit:`ns`,onChange:r}),(0,$.jsx)(YQ,{label:`基线偏置`,value:i,min:0,max:2,step:.1,unit:`×`,onChange:a}),(0,$.jsx)(YQ,{label:`信噪比 SNR`,value:o,min:20,max:70,unit:`dB`,onChange:s})]}),(0,$.jsxs)(`div`,{className:`teaching-note`,children:[(0,$.jsx)(`span`,{children:`教学点`}),(0,$.jsx)(`p`,{children:`校准显著降低通道断层;延时常数错位不改变单指数 τ,它会被幅度自由度吸收。`})]})]})]})]})}function d$(){let[e,t]=s$(`p4.snr`,50),[n,r]=s$(`p4.seed`,42),[i,a]=s$(`p4.algos`,[`NLS`,`对数线性`,`稳健拟合`]),[o,s]=(0,v.useState)(null),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(``),f=e=>a(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),p=async(t=n)=>{l(!0),d(``);try{let n=await WQ(`p4_fit`,e,t);s(n)}catch(e){d(String(e))}l(!1)},m=(0,v.useRef)(!1);(0,v.useEffect)(()=>{m.current||(m.current=!0,p())},[]),o&&(r$.p4=o),r$.params={...r$.params,p4_snr:e,p4_seed:n,p4_algos:i};let h=(0,v.useMemo)(()=>{if(!o)return null;let e=[NQ(o.t,o.y,`采样数据`,OQ.gray,4)];return e.push(MQ(o.t,o.t.map(e=>Math.exp(-e/o.true)),`真值曲线`,OQ.truth)),i.includes(`NLS`)&&o.nls.curve&&e.push(MQ(o.t,o.nls.curve,`NLS`,OQ.blue,{lineStyle:{color:OQ.blue,width:2}})),i.includes(`对数线性`)&&o.ll.curve&&e.push(MQ(o.t,o.ll.curve,`对数线性`,OQ.orange,{lineStyle:{color:OQ.orange,width:2,type:`dashed`}})),i.includes(`稳健拟合`)&&o.rob.curve&&e.push(MQ(o.t,o.rob.curve,`稳健拟合`,OQ.teal,{lineStyle:{color:OQ.teal,width:2,type:`dotted`}})),{grid:{left:52,right:20,top:34,bottom:40},tooltip:FQ(),legend:PQ,xAxis:AQ(),yAxis:jQ(),series:e}},[o,i]),g=e=>e==null?null:Math.abs(e-52.8)/52.8*100;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(QQ,{title:`拟合与比较`,text:`使用完全相同的采样数据,比较三种寿命拟合算法的系统偏差。`,action:(0,$.jsx)(XQ,{secondary:!0,icon:`refresh`,onClick:()=>{let e=Math.floor(Math.random()*9e4)+1e3;r(e),p(e)},disabled:c,children:c?`采样中…`:`重新采样`})}),u&&(0,$.jsxs)(`div`,{className:`insight`,style:{marginBottom:12},children:[(0,$.jsx)(GQ,{name:`info`}),(0,$.jsx)(`span`,{children:u})]}),(0,$.jsxs)(`div`,{className:`top-controls`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{children:`算法选择`}),(0,$.jsx)(`div`,{className:`chips`,children:[`NLS`,`对数线性`,`稳健拟合`].map(e=>(0,$.jsxs)(`button`,{className:i.includes(e)?`selected`:``,onClick:()=>f(e),children:[(0,$.jsx)(GQ,{name:`check`,size:14}),e]},e))})]}),(0,$.jsx)(`div`,{className:`compact-range`,children:(0,$.jsx)(YQ,{label:`信噪比 SNR`,value:e,min:20,max:70,unit:`dB`,onChange:t})})]}),(0,$.jsxs)(JQ,{title:`拟合曲线`,note:`低幅值尾部揭示了不同损失函数的差异`,children:[(0,$.jsx)(ZQ,{items:[{color:OQ.gray,label:`采样数据`,dotted:!0},{color:OQ.truth,label:`真值曲线`},{color:OQ.blue,label:`NLS`},{color:OQ.orange,label:`对数线性`},{color:OQ.teal,label:`稳健拟合`}]}),h?(0,$.jsx)(IQ,{option:h,height:280}):(0,$.jsx)(`div`,{className:`chart-placeholder`})]}),(0,$.jsxs)(JQ,{title:`算法结果`,children:[(0,$.jsx)(`div`,{className:`table-scroll`,children:(0,$.jsxs)(`table`,{children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{children:`算法`}),(0,$.jsx)(`th`,{children:`τ̂ (ns)`}),(0,$.jsx)(`th`,{children:`相对偏差`}),(0,$.jsx)(`th`,{children:`估计基线 B`}),(0,$.jsx)(`th`,{children:`剔点数`})]})}),(0,$.jsx)(`tbody`,{children:o?(0,$.jsxs)($.Fragment,{children:[i.includes(`NLS`)&&(0,$.jsxs)(`tr`,{className:`best`,children:[(0,$.jsxs)(`td`,{children:[(0,$.jsx)(`b`,{children:`NLS`}),(0,$.jsx)(`small`,{className:`tag`,children:`推荐`})]}),(0,$.jsx)(`td`,{children:o.nls.tau?.toFixed(3)}),(0,$.jsxs)(`td`,{className:`good`,children:[g(o.nls.tau)?.toFixed(2),`%`]}),(0,$.jsx)(`td`,{children:o.nls.B.toFixed(4)}),(0,$.jsx)(`td`,{children:`0`})]}),i.includes(`对数线性`)&&(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:(0,$.jsx)(`b`,{children:`对数线性`})}),(0,$.jsx)(`td`,{children:o.ll.tau?.toFixed(3)??`—`}),(0,$.jsxs)(`td`,{className:g(o.ll.tau)>2?`bad`:``,children:[g(o.ll.tau)?.toFixed(2)??`—`,`%`]}),(0,$.jsx)(`td`,{children:o.ll.B.toFixed(4)}),(0,$.jsx)(`td`,{children:o.ll.dropped})]}),i.includes(`稳健拟合`)&&(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:(0,$.jsx)(`b`,{children:`稳健拟合`})}),(0,$.jsx)(`td`,{children:o.rob.tau?.toFixed(3)}),(0,$.jsxs)(`td`,{className:`good`,children:[g(o.rob.tau)?.toFixed(2),`%`]}),(0,$.jsx)(`td`,{children:o.rob.B.toFixed(4)}),(0,$.jsx)(`td`,{children:`—`})]})]}):(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:5,style:{textAlign:`center`,padding:`20px`},children:`正在计算…`})})})]})}),(0,$.jsxs)(`div`,{className:`insight`,children:[(0,$.jsx)(GQ,{name:`info`}),(0,$.jsx)(`span`,{children:`对数线性在估计基线时存在系统偏差;低幅值尾部经对数变换后,噪声权重被显著放大。NLS 在同一数据上提供无偏基准。`})]})]})]})}function f$(){let[e,t]=(0,v.useState)(0),[n,r]=(0,v.useState)(!1),[i,a]=s$(`p5.snr`,50),[o,s]=s$(`p5.repeats`,16),[c]=s$(`p5.seed`,42),[l,u]=s$(`p5.wins`,[100,150,200,300,400]),[d,f]=(0,v.useState)([]),[p,m]=(0,v.useState)(null),[h,g]=(0,v.useState)(!1),[_,y]=(0,v.useState)(``),[b,x]=s$(`p5.mcSnr`,50),[S,C]=s$(`p5.mcWindow`,400),[w,T]=s$(`p5.mcRepeats`,30),[E,D]=s$(`p5.mcSeed`,42),O=e=>u(t=>t.includes(e)?t.length>1?t.filter(t=>t!==e):t:[...t,e].sort((e,t)=>e-t)),k=async()=>{r(!0),t(0),f([]);let e=[];for(let n=0;n{g(!0),y(``);try{let e=await WQ(`p5_montecarlo`,b,w,E,S);m(e)}catch(e){y(String(e))}g(!1)};d.length&&(r$.p5=d),p&&!p.error&&(r$.p5mc=p),r$.params={...r$.params,p5_snr:i,p5_repeats:o,p5_wins:l,p5_seed:c,mc:{snr:b,window:S,repeats:w,seed:E}};let j=(0,v.useMemo)(()=>d.length?{grid:{left:52,right:20,top:34,bottom:40},tooltip:FQ(),legend:PQ,xAxis:AQ(`记录窗口 (ns)`),yAxis:jQ({name:`相对标准差 (%)`,logBase:10,axisLabel:{...kQ,formatter:e=>String(e)}}),series:[{name:`单通道`,type:`line`,data:d.map(e=>[e.window,e.single]),symbolSize:6,itemStyle:{color:OQ.orange},lineStyle:{color:OQ.orange,width:2}},{name:`四相位等效`,type:`line`,data:d.map(e=>[e.window,e.fiber]),symbolSize:6,itemStyle:{color:OQ.blue,borderColor:`#fff`,borderWidth:1},lineStyle:{color:OQ.blue,width:2}}]}:null,[d]),ee=(0,v.useMemo)(()=>{if(!d.length)return null;let e=d.filter(e=>e.ratio&&isFinite(e.ratio));return e.length?e.reduce((e,t)=>(e.ratio??0)>(t.ratio??0)?e:t):null},[d]),te=(0,v.useMemo)(()=>{if(!p||p.error)return null;let e=(e,t,n)=>({type:`bar`,barWidth:`100%`,barGap:n?`-100%`:void 0,data:p.bins.map((t,n)=>[Number(t.toFixed(2)),e[n]]),itemStyle:{color:t,borderRadius:[2,2,0,0]},z:n?3:2});return{grid:{left:44,right:20,top:34,bottom:42},tooltip:{trigger:`axis`,textStyle:{fontSize:10,fontFamily:`DM Mono, monospace`}},legend:{...PQ,data:[`单通道`,`四相位等效`,`真值 ${p.tau_true} ns`]},xAxis:{type:`value`,name:`拟合寿命 τ̂₂ (ns)`,nameLocation:`middle`,nameGap:27,nameTextStyle:{...kQ,color:`#8e97a9`},min:p.xrange[0],max:p.xrange[1],axisLine:{show:!0,lineStyle:{color:`#c3c9d3`}},axisTick:{show:!1},axisLabel:kQ,splitLine:{lineStyle:{color:`#edf0f4`}}},yAxis:{type:`value`,name:`次数`,nameGap:14,nameTextStyle:{...kQ,color:`#8e97a9`},axisLine:{show:!1},axisTick:{show:!1},axisLabel:kQ,splitLine:{lineStyle:{color:`#edf0f4`}}},series:[{name:`单通道`,...e(p.single_counts,`rgba(238,135,88,.72)`,!1)},{name:`四相位等效`,...e(p.fiber_counts,`rgba(8,125,175,.65)`,!0)},{name:`真值 ${p.tau_true} ns`,type:`line`,markLine:{symbol:`none`,animation:!1,data:[{xAxis:p.tau_true}],lineStyle:{color:`#1c2f46`,type:`dashed`,width:1.5},label:{formatter:`真值 ${p.tau_true}`,fontSize:9,color:`#1c2f46`,position:`insideEndTop`}},data:[]}]}},[p]);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(QQ,{title:`参数扫描`,text:`批量扫描记录窗口与噪声水平,量化等效采样带来的稳定性收益。`}),(0,$.jsxs)(JQ,{title:`寿命估计稳定性`,note:`纵轴:τ₂ 相对标准差 (%) · 对数尺度 —— 扫描多个记录窗口,对比两种采样方案的拟合稳定性`,className:`scan-card`,children:[(0,$.jsxs)(`div`,{className:`mc-controls`,children:[(0,$.jsxs)(`div`,{className:`mc-ctrl`,children:[(0,$.jsxs)(`div`,{className:`control-label`,children:[(0,$.jsx)(`span`,{children:`固定 SNR`}),(0,$.jsxs)(`div`,{className:`number-box`,children:[(0,$.jsx)(`input`,{type:`number`,min:25,max:80,value:i,onChange:e=>a(Number(e.target.value))}),(0,$.jsx)(`em`,{children:`dB`})]})]}),(0,$.jsx)(`input`,{className:`range`,style:{"--value":`${(i-25)/55*100}%`},type:`range`,min:25,max:80,value:i,onChange:e=>a(Number(e.target.value))})]}),(0,$.jsxs)(`div`,{className:`mc-ctrl`,children:[(0,$.jsx)(`span`,{className:`mc-lbl`,children:`重复次数`}),(0,$.jsxs)(`b`,{children:[(0,$.jsx)(`input`,{className:`inline-num`,type:`number`,min:8,max:60,value:o,onChange:e=>s(Number(e.target.value))}),` 次 / 窗口`]})]}),(0,$.jsxs)(`div`,{className:`mc-ctrl`,children:[(0,$.jsx)(`span`,{className:`mc-lbl`,children:`随机种子`}),(0,$.jsx)(`b`,{children:c})]}),(0,$.jsxs)(`div`,{className:`mc-ctrl`,children:[(0,$.jsx)(`span`,{className:`mc-lbl`,children:`窗口扫描范围`}),(0,$.jsx)(`div`,{className:`window-chips`,children:[100,150,200,300,400].map(e=>(0,$.jsxs)(`button`,{className:l.includes(e)?`active`:``,onClick:()=>O(e),children:[e,` ns`]},e))})]}),(0,$.jsx)(XQ,{icon:n?`loader`:`play`,onClick:k,disabled:n,children:n?`扫描中 ${e}%`:`运行扫描`})]}),n&&(0,$.jsxs)(`div`,{className:`progress`,style:{marginBottom:12},children:[(0,$.jsx)(`i`,{style:{width:`${e}%`}}),(0,$.jsxs)(`span`,{children:[`扫描进行中 · `,e,`%(`,l.length,` 个窗口 × `,o,` 次)`]})]}),(0,$.jsx)(ZQ,{items:[{color:OQ.orange,label:`单通道`},{color:OQ.blue,label:`四相位等效`}]}),j?(0,$.jsx)(IQ,{option:j,height:280}):(0,$.jsx)(`div`,{className:`chart-placeholder`,children:n?`扫描进行中…`:`点击「运行扫描」开始`}),d.length>0&&(0,$.jsx)(`div`,{className:`table-scroll`,style:{marginTop:12},children:(0,$.jsxs)(`table`,{children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{children:`窗口 (ns)`}),(0,$.jsx)(`th`,{children:`单通道`}),(0,$.jsx)(`th`,{children:`四相位`}),(0,$.jsx)(`th`,{children:`提升比`}),(0,$.jsx)(`th`,{children:`失败率`})]})}),(0,$.jsx)(`tbody`,{children:d.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:(0,$.jsx)(`b`,{children:e.window})}),(0,$.jsxs)(`td`,{children:[e.single?.toFixed(2)??`—`,`%`]}),(0,$.jsxs)(`td`,{children:[e.fiber?.toFixed(2)??`—`,`%`]}),(0,$.jsxs)(`td`,{className:e.ratio&&e.ratio>=3?`good`:``,children:[e.ratio?.toFixed(1),`×`]}),(0,$.jsxs)(`td`,{children:[e.single_fail.toFixed(0),`% / `,e.fiber_fail.toFixed(0),`%`]})]},e.window))})]})})]}),(0,$.jsx)(JQ,{title:`关键结论`,note:`窗口扫描的结论摘要`,children:ee?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`conclusion-row`,children:[(0,$.jsxs)(`div`,{className:`big-result`,children:[(0,$.jsx)(`span`,{children:`最大稳定性提升`}),(0,$.jsxs)(`strong`,{children:[(ee.ratio??0).toFixed(1),(0,$.jsx)(`small`,{children:`×`})]}),(0,$.jsxs)(`p`,{children:[`SNR `,i,` dB · `,ee.window,` ns`]})]}),(0,$.jsxs)(`div`,{className:`before-after`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{children:`单通道 σ/τ`}),(0,$.jsxs)(`b`,{children:[ee.single?.toFixed(2),`%`]})]}),(0,$.jsx)(GQ,{name:`chevron`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{children:`四相位 σ/τ`}),(0,$.jsxs)(`b`,{children:[ee.fiber?.toFixed(2),`%`]})]})]}),(0,$.jsxs)(`div`,{className:`reference-benchmark`,children:[(0,$.jsx)(`span`,{children:`研究报告仿真基准`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`b`,{children:`7.65%`}),(0,$.jsx)(GQ,{name:`chevron`,size:13}),(0,$.jsx)(`b`,{children:`0.60%`})]}),(0,$.jsx)(`small`,{children:`200 次蒙特卡洛 · 仅作辅助对照`})]})]}),(0,$.jsxs)(`div`,{className:`success-note`,children:[(0,$.jsx)(GQ,{name:`check`}),(0,$.jsx)(`span`,{children:`浏览器计算完成,与本地 CLI 结果一致`})]})]}):(0,$.jsx)(`div`,{className:`empty-status`,children:`运行扫描后,结论卡片将在此显示`})}),(0,$.jsxs)(JQ,{title:`蒙特卡洛 τ̂₂ 分布`,note:p&&!p.error?`窗口 ${p.window} ns · SNR ${p.snr} dB · 重复 ${p.repeats} 次 · 种子 ${E} —— 分布越窄,寿命估计越稳定`:`在同一条件下重复拟合 N 次 —— τ̂₂ 分布越窄,寿命估计越稳定(含置信区间与失败率)`,className:`mc-card`,children:[(0,$.jsxs)(`div`,{className:`mc-controls`,children:[(0,$.jsxs)(`div`,{className:`mc-ctrl`,children:[(0,$.jsxs)(`div`,{className:`control-label`,children:[(0,$.jsx)(`span`,{children:`SNR`}),(0,$.jsxs)(`div`,{className:`number-box`,children:[(0,$.jsx)(`input`,{type:`number`,min:20,max:80,value:b,onChange:e=>x(Number(e.target.value))}),(0,$.jsx)(`em`,{children:`dB`})]})]}),(0,$.jsx)(`input`,{className:`range`,style:{"--value":`${(b-20)/60*100}%`},type:`range`,min:20,max:80,value:b,onChange:e=>x(Number(e.target.value))})]}),(0,$.jsxs)(`div`,{className:`mc-ctrl`,children:[(0,$.jsx)(`span`,{className:`mc-lbl`,children:`记录窗口`}),(0,$.jsx)(`div`,{className:`window-chips`,children:[100,150,200,300,400].map(e=>(0,$.jsxs)(`button`,{className:S===e?`active`:``,onClick:()=>C(e),children:[e,` ns`]},e))})]}),(0,$.jsxs)(`div`,{className:`mc-ctrl`,children:[(0,$.jsx)(`span`,{className:`mc-lbl`,children:`重复次数`}),(0,$.jsxs)(`b`,{children:[(0,$.jsx)(`input`,{className:`inline-num`,type:`number`,min:10,max:200,value:w,onChange:e=>T(Number(e.target.value))}),` 次`]})]}),(0,$.jsxs)(`div`,{className:`mc-ctrl`,children:[(0,$.jsx)(`span`,{className:`mc-lbl`,children:`随机种子`}),(0,$.jsx)(`b`,{children:(0,$.jsx)(`input`,{className:`inline-num`,type:`number`,min:0,max:999999,value:E,onChange:e=>D(Number(e.target.value))})})]}),(0,$.jsx)(XQ,{icon:h?`loader`:`play`,onClick:A,disabled:h,children:h?`计算中…`:`运行蒙特卡洛`})]}),(0,$.jsx)(ZQ,{items:[{color:OQ.orange,label:`单通道 10 ns`},{color:OQ.blue,label:`四相位 2.5 ns`},{color:OQ.truth,label:`真值 52.8 ns`,dotted:!0}]}),_&&(0,$.jsxs)(`div`,{className:`insight`,style:{marginBottom:10},children:[(0,$.jsx)(GQ,{name:`info`}),(0,$.jsx)(`span`,{children:_})]}),p?.error===`no-fits`&&(0,$.jsxs)(`div`,{className:`insight`,style:{marginBottom:10},children:[(0,$.jsx)(GQ,{name:`info`}),(0,$.jsx)(`span`,{children:`拟合全部失败(当前条件过差),请提高 SNR 或窗口。`})]}),p&&!p.error&&(0,$.jsxs)($.Fragment,{children:[te&&(0,$.jsx)(IQ,{option:te,height:250}),(0,$.jsx)(`div`,{className:`table-scroll`,style:{marginTop:12},children:(0,$.jsxs)(`table`,{children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{children:`方案`}),(0,$.jsx)(`th`,{children:`均值 (ns)`}),(0,$.jsx)(`th`,{children:`σ/τ`}),(0,$.jsx)(`th`,{children:`bias`}),(0,$.jsx)(`th`,{children:`拟合失败`})]})}),(0,$.jsxs)(`tbody`,{children:[(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:(0,$.jsx)(`b`,{children:`单通道 10 ns`})}),(0,$.jsx)(`td`,{children:p.single.mean?.toFixed(3)??`—`}),(0,$.jsx)(`td`,{className:`bad`,children:p.single.rel_std==null?`—`:(p.single.rel_std*100).toFixed(2)+`%`}),(0,$.jsx)(`td`,{children:p.single.bias==null?`—`:(p.single.bias*100).toFixed(2)+`%`}),(0,$.jsxs)(`td`,{children:[p.single.n_failed,`/`,p.single.n]})]}),(0,$.jsxs)(`tr`,{className:`best`,children:[(0,$.jsx)(`td`,{children:(0,$.jsx)(`b`,{children:`四相位 2.5 ns`})}),(0,$.jsx)(`td`,{children:p.fiber.mean?.toFixed(3)??`—`}),(0,$.jsx)(`td`,{className:`good`,children:p.fiber.rel_std==null?`—`:(p.fiber.rel_std*100).toFixed(2)+`%`}),(0,$.jsx)(`td`,{children:p.fiber.bias==null?`—`:(p.fiber.bias*100).toFixed(2)+`%`}),(0,$.jsxs)(`td`,{children:[p.fiber.n_failed,`/`,p.fiber.n]})]})]})]})}),(0,$.jsxs)(`div`,{className:`insight`,children:[(0,$.jsx)(GQ,{name:`info`}),(0,$.jsx)(`span`,{children:`四相位等效采样的 τ̂ 分布明显比单通道窄——同参数下与上方窗口扫描结论一致;低 SNR(≤35 dB)时差距会进一步拉大,可调高 SNR 后重跑对比。`})]})]}),!p&&(0,$.jsxs)(`div`,{className:`chart-placeholder`,children:[`点击「运行蒙特卡洛」——在 SNR `,b,` dB / 窗口 `,S,` ns 条件下重复拟合 `,w,` 次,观察两种方案的 τ̂₂ 散布`]})]})]})}function p$(){let[e,t]=(0,v.useState)(!1),[n,r]=s$(`p6.name`,``),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(!1),c=[`p1`,`p2`,`p3`,`p4`,`p5`].filter(e=>r$[e]).length,l=()=>{let e=new Date,r=e=>String(e).padStart(2,`0`),i=`${`${e.getFullYear()}${r(e.getMonth()+1)}${r(e.getDate())}-${r(e.getHours())}${r(e.getMinutes())}`}-m5_gui_session${n?`-`+n:``}`,o=new Blob([JSON.stringify({exported_at:e.toISOString(),data_origin:`software-simulated`,seed:42,params:r$.params,results:{p1:r$.p1,p2:r$.p2,p3:r$.p3,p4:r$.p4,p5:r$.p5,p5mc:r$.p5mc},note:`光纤延时等效采样教学实验 · GUI 会话记录包(软件仿真,非实测)`},null,2)],{type:`application/json`}),s=(e,t)=>{let n=document.createElement(`a`);n.href=URL.createObjectURL(e),n.download=t,n.click(),URL.revokeObjectURL(n.href)};if(s(o,`${i}/session.json`),r$.p5?.length){let e=r$.p5.map(e=>[e.window,e.single,e.fiber,e.ratio?.toFixed(2)??``,e.single_fail,e.fiber_fail].join(`,`)).join(` +`,zQ=null,BQ=null;async function VQ(){let e=await fetch(`/pyodide/pyodide-lock.json`,{method:`HEAD`}).catch(()=>null),t=e&&e.ok?location.origin+`/pyodide/`:`https://cdn.jsdelivr.net/pyodide/v0.26.4/full/`;window.loadPyodide||await new Promise((e,n)=>{let r=document.createElement(`script`);r.src=t+`pyodide.js`,r.onload=()=>e(),r.onerror=()=>n(Error(`Pyodide 脚本加载失败`)),document.head.appendChild(r)}),zQ=await window.loadPyodide({indexURL:t,packageCacheDir:`idb`,lockFileURL:t+`pyodide-lock.json`}),await zQ.loadPackage([`numpy`,`scipy`]),zQ.runPython(`import sys; sys.path.insert(0, '/')`);for(let e of LQ){let t=await fetch(`py/${e}`);if(!t.ok)throw Error(`加载 ${e} 失败:HTTP ${t.status}`);let n=await t.text(),r=e.split(`/`).slice(0,-1).join(`/`);zQ.runPython(`import os; os.makedirs("/${r}", exist_ok=True)`),zQ.FS.writeFile(`/`+e,n)}zQ.runPython(`import importlib; importlib.invalidate_caches()`),zQ.runPython(RQ)}function HQ(){return BQ||=VQ().catch(e=>{throw BQ=null,e}),BQ}function UQ(){return BQ?zQ?`ready`:`loading`:`idle`}async function WQ(e,...t){await HQ();let n=zQ.globals.get(e);if(n===void 0)throw Error(`Python 函数 ${e} 未注册`);let r=await n(...t);return JSON.parse(r)}function GQ({name:e,size:t=18}){return(0,$.jsx)(`svg`,{width:t,height:t,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:{sliders:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M4 6h10M18 6h2M4 18h2M10 18h10M8 3v6M8 15v6M16 3v6M16 15v6`}),(0,$.jsx)(`path`,{d:`M14 6h4M6 18h4`})]}),pulse:(0,$.jsx)($.Fragment,{children:(0,$.jsx)(`path`,{d:`M3 12h4l2.2-6 4 12 2.2-6H21`})}),calibrate:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`}),(0,$.jsx)(`path`,{d:`M12 2v4M12 18v4M2 12h4M18 12h4M4.9 4.9l2.8 2.8M16.3 16.3l2.8 2.8M19.1 4.9l-2.8 2.8M7.7 16.3l-2.8 2.8`})]}),compare:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M4 19V5M4 19h16`}),(0,$.jsx)(`path`,{d:`m7 15 4-5 3 2 5-7`})]}),scan:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M4 4v5M4 15v5M20 4v5M20 15v5M4 4h5M15 4h5M4 20h5M15 20h5`}),(0,$.jsx)(`path`,{d:`M8 12h8`})]}),export:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M12 3v12M7 8l5-5 5 5`}),(0,$.jsx)(`path`,{d:`M5 14v6h14v-6`})]}),play:(0,$.jsx)(`path`,{d:`m9 7 8 5-8 5Z`}),copy:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`rect`,{x:`8`,y:`8`,width:`11`,height:`11`,rx:`2`}),(0,$.jsx)(`path`,{d:`M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3`})]}),refresh:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`path`,{d:`M20 7v5h-5M4 17v-5h5`}),(0,$.jsx)(`path`,{d:`M18.5 9A7 7 0 0 0 6.2 6.2L4 8M5.5 15A7 7 0 0 0 17.8 17.8L20 16`})]}),check:(0,$.jsx)(`path`,{d:`m5 12 4 4L19 6`}),info:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,$.jsx)(`path`,{d:`M12 11v6M12 7h.01`})]}),chevron:(0,$.jsx)(`path`,{d:`m9 18 6-6-6-6`}),loader:(0,$.jsx)($.Fragment,{children:(0,$.jsx)(`path`,{d:`M12 3a9 9 0 1 0 9 9`,className:`spin`})})}[e]})}var KQ=[`#6d5efc`,`#16a6a1`,`#ee8758`,`#db5ca7`],qQ=[{name:`参数与方案`,sub:`采样网格设计`,icon:`sliders`},{name:`原始采样`,sub:`波形生成与采样`,icon:`pulse`},{name:`校准与重建`,sub:`通道误差对比`,icon:`calibrate`},{name:`拟合与比较`,sub:`算法性能分析`,icon:`compare`},{name:`参数扫描`,sub:`稳定性趋势`,icon:`scan`},{name:`结果导出`,sub:`可复现记录包`,icon:`export`}];function JQ({title:e,note:t,children:n,className:r=``}){return(0,$.jsxs)(`section`,{className:`card ${r}`,children:[e&&(0,$.jsx)(`div`,{className:`card-head`,children:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{children:e}),t&&(0,$.jsx)(`p`,{children:t})]})}),n]})}function YQ({label:e,value:t,min:n,max:r,step:i=1,unit:a,onChange:o}){let s=(t-n)/(r-n)*100;return(0,$.jsxs)(`div`,{className:`control-row`,children:[(0,$.jsxs)(`div`,{className:`control-label`,children:[(0,$.jsx)(`span`,{children:e}),(0,$.jsxs)(`div`,{className:`number-box`,children:[(0,$.jsx)(`input`,{type:`number`,min:n,max:r,step:i,value:t,onChange:e=>o(Number(e.target.value))}),(0,$.jsx)(`em`,{children:a})]})]}),(0,$.jsx)(`input`,{className:`range`,style:{"--value":`${s}%`},type:`range`,min:n,max:r,step:i,value:t,onChange:e=>o(Number(e.target.value))}),(0,$.jsxs)(`div`,{className:`range-labels`,children:[(0,$.jsx)(`span`,{children:n}),(0,$.jsx)(`span`,{children:r})]})]})}function XQ({children:e,secondary:t=!1,icon:n,onClick:r,disabled:i=!1}){return(0,$.jsxs)(`button`,{className:t?`button secondary`:`button`,onClick:r,disabled:i,children:[n&&(0,$.jsx)(GQ,{name:n,size:16}),e]})}function ZQ({items:e}){return(0,$.jsx)(`div`,{className:`legend`,children:e.map(e=>(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`i`,{style:{background:e.dotted?`transparent`:e.color,borderColor:e.color},className:e.dotted?`dot`:``}),(0,$.jsx)(`span`,{children:e.label})]},e.label))})}function QQ({title:e,text:t,action:n}){return(0,$.jsxs)(`div`,{className:`hero-row`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{children:e}),(0,$.jsx)(`p`,{children:t})]}),n&&(0,$.jsx)(`div`,{className:`action-row`,children:n})]})}function $Q({value:e,label:t,note:n,highlight:r=!1}){return(0,$.jsxs)(`div`,{className:`metric ${r?`highlight`:``}`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{children:t}),(0,$.jsx)(`strong`,{children:e})]}),n&&(0,$.jsx)(`em`,{children:n})]})}function e$({label:e,options:t,value:n,onChange:r}){return(0,$.jsxs)(`label`,{className:`select-row`,children:[(0,$.jsx)(`span`,{children:e}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`select`,{value:n,onChange:e=>r(e.target.value),children:t.map(e=>(0,$.jsx)(`option`,{value:e.v,children:e.label},e.v))}),(0,$.jsx)(GQ,{name:`chevron`,size:14})]})]})}function t$({onClick:e,running:t,label:n=`运行计算`}){return(0,$.jsx)(XQ,{icon:t?`loader`:`play`,onClick:e,disabled:t,children:t?`计算中…`:n})}function n$(){let[e,t]=(0,v.useState)(`loading`),[n,r]=(0,v.useState)(``);return(0,v.useEffect)(()=>{HQ().then(()=>t(`ready`)).catch(e=>{r(String(e)),t(`error`)})},[]),e===`ready`?null:(0,$.jsx)(`div`,{className:`engine-overlay`,children:(0,$.jsxs)(`div`,{className:`engine-box`,children:[(0,$.jsx)(`div`,{className:`engine-mark`,children:(0,$.jsx)(GQ,{name:`pulse`,size:20})}),e===`loading`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`b`,{children:`正在启动科学计算引擎`}),(0,$.jsx)(`span`,{children:`Pyodide + numpy / scipy(约 40 MB,首次加载较慢,之后有缓存)`}),(0,$.jsx)(`div`,{className:`engine-bar`,children:(0,$.jsx)(`i`,{})})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`b`,{children:`计算引擎加载失败`}),(0,$.jsx)(`span`,{children:n}),(0,$.jsx)(XQ,{onClick:()=>location.reload(),icon:`refresh`,children:`刷新重试`})]})]})})}var r$={params:{}},i$=`fdets.v2.`;function a$(e,t){try{let n=localStorage.getItem(i$+e);if(n==null)return t;let r=JSON.parse(n);return r===null?t===null?null:t:Array.isArray(t)!==Array.isArray(r)||typeof r!=typeof t?t:r}catch{return t}}function o$(e,t){try{localStorage.setItem(i$+e,JSON.stringify(t))}catch{}}function s$(e,t){let[n,r]=(0,v.useState)(()=>a$(e,t));return(0,v.useEffect)(()=>{o$(e,n)},[e,n]),[n,r]}function c$(e,t){let n=e+`.fp`,[r,i]=(0,v.useState)(()=>{let r=localStorage.getItem(i$+n),i=null;try{i=r==null?null:JSON.parse(r)}catch{i=null}return i===t?l$(e,null):null});return(0,v.useEffect)(()=>{r!=null&&(o$(e,r),o$(n,t))},[r]),[r,i]}function l$(e,t){try{let n=localStorage.getItem(i$+e);return n==null?t:JSON.parse(n)}catch{return t}}function u$(){let[e,t]=s$(`p1.tau`,52.8),[n,r]=s$(`p1.dt`,10),[i,a]=s$(`p1.ng`,1.468),[o,s]=s$(`p1.mode`,`forward`),[c,l]=s$(`p1.lengths`,[0,9.7,19.4,29.1]),[u,d]=s$(`p1.targets`,[0,2.5,5,7.5]),[f,p]=(0,v.useState)(!1),[m,h]=(0,v.useState)(!1),[g,_]=c$(`p1.res`,JSON.stringify([c,i,n,u])),[y,b]=(0,v.useState)(``),x=(0,v.useMemo)(()=>c.map(e=>e*i/.2998%n),[c,i,n]),S=async()=>{p(!0),b(``);try{let e=await WQ(`p1_forward`,c,i,n,u);_(e)}catch(e){b(String(e))}p(!1)},C=()=>{navigator.clipboard?.writeText(JSON.stringify(o===`forward`?{tau:e,dt:n,ng:i,lengths:c}:{tau:e,dt:n,ng:i,targets:u},null,2)),h(!0),window.setTimeout(()=>h(!1),1400)},w=(0,v.useRef)(!1);(0,v.useEffect)(()=>{w.current||(w.current=!0,S())},[]),g&&(r$.p1=g),r$.params={...r$.params,tau:e,dt:n,ng:i,lengths:c,targets:u,mode:o};let T=[...new Set(u.map(e=>Number((e%n+n)%n)))].sort((e,t)=>e-t),E=T.slice(1).map((e,t)=>e-T[t]),D=n/Math.max(1,T.length),O=E.length?Math.max(...E.map(e=>Math.abs(e-D))):0;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`hero-row`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{children:`参数与方案`}),(0,$.jsx)(`p`,{children:`建立光纤长度、传播延时与等效采样相位之间的映射关系。`})]}),(0,$.jsxs)(`div`,{className:`action-row`,children:[(0,$.jsx)(XQ,{secondary:!0,icon:m?`check`:`copy`,onClick:C,children:m?`已复制`:`复制参数`}),(0,$.jsx)(t$,{onClick:S,running:f})]})]}),(0,$.jsxs)(`div`,{className:`mode-switch`,children:[(0,$.jsxs)(`button`,{className:o===`forward`?`active`:``,onClick:()=>s(`forward`),children:[`正向计算 `,(0,$.jsx)(`span`,{children:`长度 → 延时 / 相位`})]}),(0,$.jsxs)(`button`,{className:o===`reverse`?`active`:``,onClick:()=>s(`reverse`),children:[`反向设计 `,(0,$.jsx)(`span`,{children:`目标相位 → 候选长度`})]})]}),(0,$.jsxs)(`div`,{className:`principle-strip`,children:[(0,$.jsxs)(`div`,{className:`principle-title`,children:[(0,$.jsx)(`span`,{children:`测量链路`}),(0,$.jsx)(`b`,{children:`光学游标卡尺`})]}),(0,$.jsx)(`div`,{className:`principle-flow`,children:[[`01`,`荧光衰减`,`I(t)`],[`02`,`四路光纤`,`时间编码`],[`03`,`光电探测`,`PD + TIA`],[`04`,`低速采样`,`ADC · 10 ns`],[`05`,`校准重建`,`归位 + 交织`],[`06`,`寿命拟合`,`τ₂ 估计`]].map(([e,t,n],r)=>(0,$.jsxs)(`div`,{className:`principle-step`,children:[(0,$.jsx)(`small`,{children:e}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`b`,{children:t}),(0,$.jsx)(`em`,{children:n})]}),r<5&&(0,$.jsx)(GQ,{name:`chevron`,size:13})]},e))}),(0,$.jsxs)(`div`,{className:`model-formula`,children:[(0,$.jsx)(`span`,{children:`信号模型`}),(0,$.jsxs)(`b`,{children:[`I`,(0,$.jsx)(`sub`,{children:`true`}),`(t) = 0.16e`,(0,$.jsx)(`sup`,{children:`−t/0.6`}),` + 0.84e`,(0,$.jsx)(`sup`,{children:`−t/52.8`})]})]})]}),y&&(0,$.jsxs)(`div`,{className:`insight`,style:{marginBottom:12},children:[(0,$.jsx)(GQ,{name:`info`}),(0,$.jsx)(`span`,{children:y})]}),(0,$.jsxs)(`div`,{className:`workspace-grid`,children:[(0,$.jsxs)(`div`,{className:`stack`,children:[(0,$.jsx)(JQ,{title:`基础参数`,note:`荧光衰减与 ADC 采样条件`,children:(0,$.jsxs)(`div`,{className:`basic-grid`,children:[(0,$.jsx)(YQ,{label:`荧光寿命 τ₂`,value:e,min:10,max:100,step:.5,unit:`ns`,onChange:t}),(0,$.jsx)(YQ,{label:`采样间隔 Δt`,value:n,min:2,max:50,step:.5,unit:`ns`,onChange:r}),(0,$.jsx)(YQ,{label:`群折射率 nᵍ`,value:i,min:1.44,max:1.5,step:.001,unit:``,onChange:a})]})}),o===`forward`?(0,$.jsxs)(JQ,{title:`光纤通道`,note:`当前使用 4 路延时光纤`,children:[(0,$.jsx)(`div`,{className:`channel-inputs`,children:c.map((e,t)=>(0,$.jsxs)(`label`,{children:[(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`i`,{style:{background:KQ[t]}}),`CH`,t+1]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`input`,{type:`number`,value:e,step:.1,onChange:e=>l(c.map((n,r)=>r===t?Number(e.target.value):n))}),(0,$.jsx)(`em`,{children:`m`})]})]},t))}),(0,$.jsxs)(`div`,{className:`tip`,children:[(0,$.jsx)(GQ,{name:`info`,size:16}),(0,$.jsxs)(`span`,{children:[`建议相邻通道保持约 `,(29.1/3).toFixed(1),` m 长度差,以获得均匀的 `,(n/4).toFixed(2),` ns 相位步长。`]})]})]}):(0,$.jsxs)(JQ,{title:`目标相位`,note:`期望各通道在单个 ADC 周期内的等效位置`,children:[(0,$.jsx)(`div`,{className:`channel-inputs`,children:u.map((e,t)=>(0,$.jsxs)(`label`,{children:[(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`i`,{style:{background:KQ[t]}}),`φ`,t+1]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`input`,{type:`number`,value:e,step:.5,onChange:e=>d(u.map((n,r)=>r===t?Number(e.target.value):n))}),(0,$.jsx)(`em`,{children:`ns`})]})]},t))}),(0,$.jsxs)(`div`,{className:`tip`,children:[(0,$.jsx)(GQ,{name:`info`,size:16}),(0,$.jsxs)(`span`,{children:[`默认均匀网格 j·Δt/4(当前 Δt = `,n,` ns → 步长 `,(n/4).toFixed(2),` ns);输入非均匀相位时,软件给出逐相位最短候选并提示网格不均匀——这本身是教学点。`]})]})]})]}),(0,$.jsxs)(`div`,{className:`stack`,children:[(0,$.jsxs)(`div`,{className:`summary-card`,children:[(0,$.jsx)(`div`,{className:`summary-icon`,children:(0,$.jsx)(GQ,{name:`check`})}),o===`forward`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{children:`等效采样网格(正向)`}),(0,$.jsxs)(`strong`,{children:[(g?.sorted??x).map(e=>e.toFixed(2)).join(` / `),` ns`]}),(0,$.jsxs)(`p`,{children:[`理想步长 `,(n/4).toFixed(2),` ns · 最大间隔偏差 `,g?g.uniformity.max_gap_dev_ns.toExponential(1):`—`]})]}),(0,$.jsxs)(`div`,{className:`uniform`,children:[`均匀性 `,(0,$.jsxs)(`b`,{children:[g?Math.max(0,100-g.uniformity.max_gap_dev_ns/(n/4)*100).toFixed(2):`—`,`%`]})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{children:`目标相位(反向)`}),(0,$.jsxs)(`strong`,{children:[T.map(e=>e.toFixed(2)).join(` / `),` ns`]}),(0,$.jsxs)(`p`,{children:[g?.is_uniform_grid?`均匀网格 · 构造式推荐解`:`非均匀网格 · 逐相位最短候选`,` · 与理想步长最大偏差 `,O.toFixed(2),` ns`]})]}),(0,$.jsxs)(`div`,{className:`uniform`,children:[`网格判定 `,(0,$.jsx)(`b`,{children:g?.is_uniform_grid??O<1e-6?`均匀`:`非均匀`})]})]})]}),(0,$.jsx)(JQ,{title:`延时–相位映射`,note:`各通道在单个 ADC 周期内的等效位置`,children:(0,$.jsxs)(`div`,{className:`phase-chart`,children:[(0,$.jsxs)(`div`,{className:`phase-axis`,children:[[0,n/4,n/2,3*n/4,n].map(e=>(0,$.jsx)(`span`,{style:{left:`${e/n*100}%`},children:e.toFixed(1)},e)),(o===`forward`?g?g.channels.map(e=>e.phase_ns):x:T).map((e,t)=>(0,$.jsxs)(`div`,{className:`phase-dot`,style:{left:`${6+e/n*88}%`,bottom:`${30+t*14}%`,background:KQ[t]},children:[(0,$.jsx)(`b`,{children:o===`forward`?`CH${t+1}`:`φ${t+1}`}),(0,$.jsxs)(`small`,{children:[e.toFixed(2),` ns`]})]},t))]}),(0,$.jsx)(`div`,{className:`phase-label`,children:o===`forward`?`采样相位 (ns) —— 由光纤长度算出`:`目标相位 (ns) —— 待反推光纤长度`})]})}),(0,$.jsx)(JQ,{title:o===`forward`?`正向:通道计算结果`:g?.recommended?`反向:构造式推荐解`:`反向:逐相位最短候选`,note:o===`forward`?void 0:g?.recommended?g.construction??void 0:`目标非均匀网格——无构造式统一解,下表为每相位的最短光纤`,children:(0,$.jsx)(`div`,{className:`table-scroll`,children:(0,$.jsxs)(`table`,{children:[(0,$.jsx)(`thead`,{children:(0,$.jsx)(`tr`,{children:o===`forward`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`th`,{children:`通道`}),(0,$.jsx)(`th`,{children:`光纤长度`}),(0,$.jsx)(`th`,{children:`传播延时`}),(0,$.jsx)(`th`,{children:`采样相位`})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`th`,{children:`目标相位`}),(0,$.jsx)(`th`,{children:g?.recommended?`通道序 k`:`周期数 m`}),(0,$.jsx)(`th`,{children:`传播延时`}),(0,$.jsx)(`th`,{children:`候选长度`})]})})}),(0,$.jsxs)(`tbody`,{children:[o===`forward`?(g?.channels??[]).map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:(0,$.jsxs)(`b`,{children:[`CH`,e.index+1]})}),(0,$.jsxs)(`td`,{children:[e.length_m.toFixed(1),` m`]}),(0,$.jsxs)(`td`,{children:[e.delay_ns.toFixed(2),` ns`]}),(0,$.jsxs)(`td`,{className:`accent`,children:[e.phase_ns.toFixed(2),` ns`]})]},e.index)):(g?.recommended??[]).map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:(0,$.jsxs)(`b`,{children:[e.phase_ns.toFixed(2),` ns`]})}),(0,$.jsx)(`td`,{children:e.k}),(0,$.jsxs)(`td`,{children:[e.delay_ns.toFixed(2),` ns`]}),(0,$.jsxs)(`td`,{className:`accent`,children:[e.length_m.toFixed(2),` m`]})]},e.k)),o===`reverse`&&!g?.recommended&&(g?.candidates_short??[]).map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:(0,$.jsxs)(`b`,{children:[e.phase_ns.toFixed(2),` ns`]})}),(0,$.jsx)(`td`,{children:e.m}),(0,$.jsxs)(`td`,{children:[e.delay_ns.toFixed(2),` ns`]}),(0,$.jsxs)(`td`,{className:`accent`,children:[e.length_m.toFixed(2),` m`]})]},e.phase_ns))]})]})})})]})]})]})}function d$(){let[e,t]=s$(`p2.snr`,50),[n,r]=s$(`p2.bits`,`12`),[i,a]=s$(`p2.window`,`400`),[o,s]=s$(`p2.ideal`,!1),[c,l]=s$(`p2.seed`,42),[u,d]=c$(`p2.res`,JSON.stringify([i,e,n,o,c])),[f,p]=(0,v.useState)(!1),[m,h]=(0,v.useState)(``),g=async(t=c)=>{p(!0),h(``);try{let r=await WQ(`p2_sample`,52.8,Number(i),e,Number(n),o,t);d(r)}catch(e){h(String(e))}p(!1)},_=(0,v.useRef)(!1);(0,v.useEffect)(()=>{_.current||(_.current=!0,g())},[]),u&&(r$.p2=u),r$.params={...r$.params,p2_snr:e,p2_bits:n,p2_window:i,p2_ideal:o,p2_seed:c};let y=(0,v.useMemo)(()=>u?{grid:{left:52,right:20,top:34,bottom:40},tooltip:FQ(),legend:PQ,xAxis:AQ(),yAxis:jQ(),series:[MQ(u.t_cont,u.y_cont,`理想连续信号`,OQ.truth),NQ(u.t_single,u.y_single,`10 ns 直接采样`,OQ.orange,6),NQ(u.t_multi,u.y_multi,`四通道等效采样`,OQ.blue,3.5)]}:null,[u]),b=(Number(i)/52.8).toFixed(2);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(QQ,{title:`原始采样`,text:`对比低速 ADC 直接采样与四通道等效补点后的波形细节。`,action:(0,$.jsx)(XQ,{icon:`refresh`,onClick:()=>{let e=Math.floor(Math.random()*9e4)+1e3;l(e),g(e)},disabled:f,children:f?`采样中…`:`重新采样`})}),m&&(0,$.jsxs)(`div`,{className:`insight`,style:{marginBottom:12},children:[(0,$.jsx)(GQ,{name:`info`}),(0,$.jsx)(`span`,{children:m})]}),(0,$.jsxs)(`div`,{className:`metric-grid`,children:[(0,$.jsx)($Q,{value:u?String(u.n_single):`—`,label:`单通道采样点`,note:`${i} ns 窗口`}),(0,$.jsx)($Q,{value:u?String(u.n_multi):`—`,label:`四通道总点数`,note:`${(Number(i)/4).toFixed(0)}× 密度`,highlight:!0}),(0,$.jsx)($Q,{value:String(c),label:`当前随机种子`,note:`可复现`})]}),(0,$.jsxs)(`div`,{className:`workspace-grid wide-left`,children:[(0,$.jsxs)(JQ,{title:`时间–强度采样对比`,note:u?`NLS 拟合寿命 τ̂ = ${u.tau_hat.toFixed(3)} ns · 相对偏差 ${(u.rel_error*100).toFixed(2)}%`:`四相位补点显著提升了衰减曲线的时间分辨率`,children:[(0,$.jsx)(ZQ,{items:[{color:OQ.truth,label:`理想连续信号`},{color:OQ.orange,label:`10 ns 直接采样`,dotted:!0},{color:OQ.blue,label:`四通道等效采样`,dotted:!0}]}),y?(0,$.jsx)(IQ,{option:y,height:280}):(0,$.jsx)(`div`,{className:`chart-placeholder`}),(0,$.jsxs)(`div`,{className:`insight`,children:[(0,$.jsx)(GQ,{name:`info`}),(0,$.jsxs)(`span`,{children:[`当前 `,i,` ns 窗口覆盖约 `,(0,$.jsxs)(`b`,{children:[b,` τ₂`]}),`,信号已充分衰减;四通道有效采样密度提升 4 倍。注意:`,(Number(i)/4).toFixed(1),` ns 等效采样网格不等同于整机时间分辨率。`]})]})]}),(0,$.jsxs)(JQ,{title:`采样条件`,note:`修改后点击「重新采样」应用`,children:[(0,$.jsxs)(`div`,{className:`sampling-grid`,children:[(0,$.jsx)(YQ,{label:`信噪比 SNR`,value:e,min:20,max:80,unit:`dB`,onChange:t}),(0,$.jsx)(e$,{label:`ADC 位数`,options:[{v:`8`,label:`8 bit`},{v:`10`,label:`10 bit`},{v:`12`,label:`12 bit`},{v:`14`,label:`14 bit`}],value:n,onChange:r}),(0,$.jsx)(e$,{label:`记录窗口`,options:[{v:`40`,label:`40 ns`},{v:`100`,label:`100 ns`},{v:`200`,label:`200 ns`},{v:`400`,label:`400 ns`}],value:i,onChange:a}),(0,$.jsxs)(`label`,{className:`toggle-row`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`b`,{children:`理想无噪`}),(0,$.jsx)(`span`,{children:`关闭噪声与量化模拟`})]}),(0,$.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked)}),(0,$.jsx)(`i`,{})]})]}),(0,$.jsxs)(`div`,{className:`tip`,style:{marginTop:12},children:[(0,$.jsx)(GQ,{name:`info`,size:16}),(0,$.jsx)(`span`,{children:`窗口 40 ns(≈0.76τ)时仅 4 个采样点,信号才衰减到初值 47%——这正是四相位方案要解决的困境。`})]})]})]})]})}function f$(){let[e,t]=s$(`p3.gain`,1),[n,r]=s$(`p3.delay`,1),[i,a]=s$(`p3.baseline`,1),[o,s]=s$(`p3.snr`,50),[c,l]=c$(`p3.res`,JSON.stringify([e,n,i,o])),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(``),m=async()=>{d(!0),p(``);try{let t=await WQ(`p3_calibrate`,e,n,i,o,42);l(t)}catch(e){p(String(e))}d(!1)},h=(0,v.useRef)(!1);(0,v.useEffect)(()=>{h.current||(h.current=!0,m())},[]),c&&(r$.p3=c),r$.params={...r$.params,p3_gain:e,p3_delay:n,p3_baseline:i,p3_snr:o};let g=(0,v.useMemo)(()=>{if(!c)return null;let e=c.calibrated.t.map(e=>[e,Math.exp(-e/c.tau_true)]);return{grid:{left:52,right:20,top:34,bottom:40},tooltip:FQ(),legend:PQ,xAxis:AQ(),yAxis:jQ(),series:[{...MQ([],[],`理论真值`,OQ.truth),data:e},NQ(c.raw.t,c.raw.y,`不校准`,OQ.orange,3),NQ(c.nominal.t,c.nominal.y,`基线 + 增益`,OQ.teal,3),NQ(c.calibrated.t,c.calibrated.y,`完整校准`,OQ.blue,3)]}},[c]),_=e=>e==null?null:Math.abs(e-(c?.tau_true??52.8))/(c?.tau_true??52.8)*100;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(QQ,{title:`校准与重建`,text:`注入通道硬件误差,观察不同校准层级对曲线连续度与寿命估计的影响。`,action:(0,$.jsx)(t$,{onClick:m,running:u,label:`运行校准对比`})}),f&&(0,$.jsxs)(`div`,{className:`insight`,style:{marginBottom:12},children:[(0,$.jsx)(GQ,{name:`info`}),(0,$.jsx)(`span`,{children:f})]}),(0,$.jsxs)(`div`,{className:`workspace-grid wide-left`,children:[(0,$.jsxs)(`div`,{className:`stack`,children:[(0,$.jsxs)(JQ,{title:`重建曲线对比`,note:`完整校准后数据点重新贴近理论真值`,children:[(0,$.jsx)(ZQ,{items:[{color:OQ.truth,label:`理论真值`},{color:OQ.orange,label:`不校准`},{color:OQ.teal,label:`基线 + 增益`},{color:OQ.blue,label:`完整校准`}]}),g?(0,$.jsx)(IQ,{option:g,height:280}):(0,$.jsx)(`div`,{className:`chart-placeholder`})]}),(0,$.jsx)(JQ,{title:`方案对比`,children:(0,$.jsx)(`div`,{className:`table-scroll`,children:(0,$.jsxs)(`table`,{children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{children:`方案`}),(0,$.jsx)(`th`,{children:`τ̂ (ns)`}),(0,$.jsx)(`th`,{children:`相对偏差`}),(0,$.jsx)(`th`,{children:`有效点数`}),(0,$.jsx)(`th`,{children:`mean_jump`})]})}),(0,$.jsx)(`tbody`,{children:c?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:(0,$.jsx)(`b`,{children:`不校准重建`})}),(0,$.jsx)(`td`,{children:c.raw.tau?.toFixed(3)??`—`}),(0,$.jsx)(`td`,{className:_(c.raw.tau)>2?`bad`:``,children:_(c.raw.tau)==null?`—`:`+${_(c.raw.tau).toFixed(2)}%`}),(0,$.jsx)(`td`,{children:c.raw.n}),(0,$.jsx)(`td`,{children:c.raw.jump.toFixed(4)})]}),(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:(0,$.jsx)(`b`,{children:`基线 + 增益`})}),(0,$.jsx)(`td`,{children:c.nominal.tau?.toFixed(3)??`—`}),(0,$.jsx)(`td`,{className:_(c.nominal.tau)>2?`bad`:``,children:_(c.nominal.tau)==null?`—`:`+${_(c.nominal.tau).toFixed(2)}%`}),(0,$.jsx)(`td`,{children:c.nominal.n}),(0,$.jsx)(`td`,{children:c.nominal.jump.toFixed(4)})]}),(0,$.jsxs)(`tr`,{className:`best`,children:[(0,$.jsx)(`td`,{children:(0,$.jsx)(`b`,{children:`完整校准`})}),(0,$.jsx)(`td`,{children:c.calibrated.tau?.toFixed(3)??`—`}),(0,$.jsx)(`td`,{className:`good`,children:_(c.calibrated.tau)==null?`—`:`+${_(c.calibrated.tau).toFixed(2)}%`}),(0,$.jsx)(`td`,{children:c.calibrated.n}),(0,$.jsx)(`td`,{children:c.calibrated.jump.toFixed(4)})]})]}):(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:5,style:{textAlign:`center`,padding:`20px`},children:`点击「运行校准对比」开始`})})})]})})})]}),(0,$.jsxs)(JQ,{title:`误差注入`,note:`CH1 作为无误差参考通道`,children:[(0,$.jsxs)(`div`,{className:`error-grid`,children:[(0,$.jsx)(YQ,{label:`通道增益失配`,value:e,min:0,max:1.5,step:.05,unit:`×`,onChange:t}),(0,$.jsx)(YQ,{label:`延时误差`,value:n,min:0,max:2,step:.1,unit:`ns`,onChange:r}),(0,$.jsx)(YQ,{label:`基线偏置`,value:i,min:0,max:2,step:.1,unit:`×`,onChange:a}),(0,$.jsx)(YQ,{label:`信噪比 SNR`,value:o,min:20,max:70,unit:`dB`,onChange:s})]}),(0,$.jsxs)(`div`,{className:`teaching-note`,children:[(0,$.jsx)(`span`,{children:`教学点`}),(0,$.jsx)(`p`,{children:`校准显著降低通道断层;延时常数错位不改变单指数 τ,它会被幅度自由度吸收。`})]})]})]})]})}function p$(){let[e,t]=s$(`p4.snr`,50),[n,r]=s$(`p4.seed`,42),[i,a]=s$(`p4.algos`,[`NLS`,`对数线性`,`稳健拟合`]),[o,s]=c$(`p4.res`,JSON.stringify([e,n])),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(``),f=e=>a(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),p=async(t=n)=>{l(!0),d(``);try{let n=await WQ(`p4_fit`,e,t);s(n)}catch(e){d(String(e))}l(!1)},m=(0,v.useRef)(!1);(0,v.useEffect)(()=>{m.current||(m.current=!0,p())},[]),o&&(r$.p4=o),r$.params={...r$.params,p4_snr:e,p4_seed:n,p4_algos:i};let h=(0,v.useMemo)(()=>{if(!o)return null;let e=[NQ(o.t,o.y,`采样数据`,OQ.gray,4)];return e.push(MQ(o.t,o.t.map(e=>Math.exp(-e/o.true)),`真值曲线`,OQ.truth)),i.includes(`NLS`)&&o.nls.curve&&e.push(MQ(o.t,o.nls.curve,`NLS`,OQ.blue,{lineStyle:{color:OQ.blue,width:2}})),i.includes(`对数线性`)&&o.ll.curve&&e.push(MQ(o.t,o.ll.curve,`对数线性`,OQ.orange,{lineStyle:{color:OQ.orange,width:2,type:`dashed`}})),i.includes(`稳健拟合`)&&o.rob.curve&&e.push(MQ(o.t,o.rob.curve,`稳健拟合`,OQ.teal,{lineStyle:{color:OQ.teal,width:2,type:`dotted`}})),{grid:{left:52,right:20,top:34,bottom:40},tooltip:FQ(),legend:PQ,xAxis:AQ(),yAxis:jQ(),series:e}},[o,i]),g=e=>e==null?null:Math.abs(e-52.8)/52.8*100;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(QQ,{title:`拟合与比较`,text:`使用完全相同的采样数据,比较三种寿命拟合算法的系统偏差。`,action:(0,$.jsx)(XQ,{secondary:!0,icon:`refresh`,onClick:()=>{let e=Math.floor(Math.random()*9e4)+1e3;r(e),p(e)},disabled:c,children:c?`采样中…`:`重新采样`})}),u&&(0,$.jsxs)(`div`,{className:`insight`,style:{marginBottom:12},children:[(0,$.jsx)(GQ,{name:`info`}),(0,$.jsx)(`span`,{children:u})]}),(0,$.jsxs)(`div`,{className:`top-controls`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{children:`算法选择`}),(0,$.jsx)(`div`,{className:`chips`,children:[`NLS`,`对数线性`,`稳健拟合`].map(e=>(0,$.jsxs)(`button`,{className:i.includes(e)?`selected`:``,onClick:()=>f(e),children:[(0,$.jsx)(GQ,{name:`check`,size:14}),e]},e))})]}),(0,$.jsx)(`div`,{className:`compact-range`,children:(0,$.jsx)(YQ,{label:`信噪比 SNR`,value:e,min:20,max:70,unit:`dB`,onChange:t})})]}),(0,$.jsxs)(JQ,{title:`拟合曲线`,note:`低幅值尾部揭示了不同损失函数的差异`,children:[(0,$.jsx)(ZQ,{items:[{color:OQ.gray,label:`采样数据`,dotted:!0},{color:OQ.truth,label:`真值曲线`},{color:OQ.blue,label:`NLS`},{color:OQ.orange,label:`对数线性`},{color:OQ.teal,label:`稳健拟合`}]}),h?(0,$.jsx)(IQ,{option:h,height:280}):(0,$.jsx)(`div`,{className:`chart-placeholder`})]}),(0,$.jsxs)(JQ,{title:`算法结果`,children:[(0,$.jsx)(`div`,{className:`table-scroll`,children:(0,$.jsxs)(`table`,{children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{children:`算法`}),(0,$.jsx)(`th`,{children:`τ̂ (ns)`}),(0,$.jsx)(`th`,{children:`相对偏差`}),(0,$.jsx)(`th`,{children:`估计基线 B`}),(0,$.jsx)(`th`,{children:`剔点数`})]})}),(0,$.jsx)(`tbody`,{children:o?(0,$.jsxs)($.Fragment,{children:[i.includes(`NLS`)&&(0,$.jsxs)(`tr`,{className:`best`,children:[(0,$.jsxs)(`td`,{children:[(0,$.jsx)(`b`,{children:`NLS`}),(0,$.jsx)(`small`,{className:`tag`,children:`推荐`})]}),(0,$.jsx)(`td`,{children:o.nls.tau?.toFixed(3)}),(0,$.jsxs)(`td`,{className:`good`,children:[g(o.nls.tau)?.toFixed(2),`%`]}),(0,$.jsx)(`td`,{children:o.nls.B.toFixed(4)}),(0,$.jsx)(`td`,{children:`0`})]}),i.includes(`对数线性`)&&(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:(0,$.jsx)(`b`,{children:`对数线性`})}),(0,$.jsx)(`td`,{children:o.ll.tau?.toFixed(3)??`—`}),(0,$.jsxs)(`td`,{className:g(o.ll.tau)>2?`bad`:``,children:[g(o.ll.tau)?.toFixed(2)??`—`,`%`]}),(0,$.jsx)(`td`,{children:o.ll.B.toFixed(4)}),(0,$.jsx)(`td`,{children:o.ll.dropped})]}),i.includes(`稳健拟合`)&&(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:(0,$.jsx)(`b`,{children:`稳健拟合`})}),(0,$.jsx)(`td`,{children:o.rob.tau?.toFixed(3)}),(0,$.jsxs)(`td`,{className:`good`,children:[g(o.rob.tau)?.toFixed(2),`%`]}),(0,$.jsx)(`td`,{children:o.rob.B.toFixed(4)}),(0,$.jsx)(`td`,{children:`—`})]})]}):(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:5,style:{textAlign:`center`,padding:`20px`},children:`正在计算…`})})})]})}),(0,$.jsxs)(`div`,{className:`insight`,children:[(0,$.jsx)(GQ,{name:`info`}),(0,$.jsx)(`span`,{children:`对数线性在估计基线时存在系统偏差;低幅值尾部经对数变换后,噪声权重被显著放大。NLS 在同一数据上提供无偏基准。`})]})]})]})}function m$(){let[e,t]=(0,v.useState)(0),[n,r]=(0,v.useState)(!1),[i,a]=s$(`p5.snr`,50),[o,s]=s$(`p5.repeats`,16),[c]=s$(`p5.seed`,42),[l,u]=s$(`p5.wins`,[100,150,200,300,400]),[d,f]=(0,v.useState)(!1),[p,m]=(0,v.useState)(``),[h,g]=s$(`p5.mcSnr`,50),[_,y]=s$(`p5.mcWindow`,400),[b,x]=s$(`p5.mcRepeats`,30),[S,C]=s$(`p5.mcSeed`,42),[w,T]=c$(`p5.rows`,JSON.stringify([i,o,c,l])),[E,D]=c$(`p5.mc`,JSON.stringify([h,b,S,_])),O=e=>u(t=>t.includes(e)?t.length>1?t.filter(t=>t!==e):t:[...t,e].sort((e,t)=>e-t)),k=async()=>{r(!0),t(0),T([]);let e=[];for(let n=0;n{f(!0),m(``);try{let e=await WQ(`p5_montecarlo`,h,b,S,_);D(e)}catch(e){m(String(e))}f(!1)};w?.length&&(r$.p5=w),E&&!E.error&&(r$.p5mc=E),r$.params={...r$.params,p5_snr:i,p5_repeats:o,p5_wins:l,p5_seed:c,mc:{snr:h,window:_,repeats:b,seed:S}};let j=(0,v.useMemo)(()=>w?.length?{grid:{left:52,right:20,top:34,bottom:40},tooltip:FQ(),legend:PQ,xAxis:AQ(`记录窗口 (ns)`),yAxis:jQ({name:`相对标准差 (%)`,logBase:10,axisLabel:{...kQ,formatter:e=>String(e)}}),series:[{name:`单通道`,type:`line`,data:w.map(e=>[e.window,e.single]),symbolSize:6,itemStyle:{color:OQ.orange},lineStyle:{color:OQ.orange,width:2}},{name:`四相位等效`,type:`line`,data:w.map(e=>[e.window,e.fiber]),symbolSize:6,itemStyle:{color:OQ.blue,borderColor:`#fff`,borderWidth:1},lineStyle:{color:OQ.blue,width:2}}]}:null,[w]),ee=(0,v.useMemo)(()=>{if(!w?.length)return null;let e=w.filter(e=>e.ratio&&isFinite(e.ratio));return e.length?e.reduce((e,t)=>(e.ratio??0)>(t.ratio??0)?e:t):null},[w]),te=(0,v.useMemo)(()=>{if(!E||E.error)return null;let e=(e,t,n)=>({type:`bar`,barWidth:`100%`,barGap:n?`-100%`:void 0,data:E.bins.map((t,n)=>[Number(t.toFixed(2)),e[n]]),itemStyle:{color:t,borderRadius:[2,2,0,0]},z:n?3:2});return{grid:{left:44,right:20,top:34,bottom:42},tooltip:{trigger:`axis`,textStyle:{fontSize:10,fontFamily:`DM Mono, monospace`}},legend:{...PQ,data:[`单通道`,`四相位等效`,`真值 ${E.tau_true} ns`]},xAxis:{type:`value`,name:`拟合寿命 τ̂₂ (ns)`,nameLocation:`middle`,nameGap:27,nameTextStyle:{...kQ,color:`#8e97a9`},min:E.xrange[0],max:E.xrange[1],axisLine:{show:!0,lineStyle:{color:`#c3c9d3`}},axisTick:{show:!1},axisLabel:kQ,splitLine:{lineStyle:{color:`#edf0f4`}}},yAxis:{type:`value`,name:`次数`,nameGap:14,nameTextStyle:{...kQ,color:`#8e97a9`},axisLine:{show:!1},axisTick:{show:!1},axisLabel:kQ,splitLine:{lineStyle:{color:`#edf0f4`}}},series:[{name:`单通道`,...e(E.single_counts,`rgba(238,135,88,.72)`,!1)},{name:`四相位等效`,...e(E.fiber_counts,`rgba(8,125,175,.65)`,!0)},{name:`真值 ${E.tau_true} ns`,type:`line`,markLine:{symbol:`none`,animation:!1,data:[{xAxis:E.tau_true}],lineStyle:{color:`#1c2f46`,type:`dashed`,width:1.5},label:{formatter:`真值 ${E.tau_true}`,fontSize:9,color:`#1c2f46`,position:`insideEndTop`}},data:[]}]}},[E]);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(QQ,{title:`参数扫描`,text:`批量扫描记录窗口与噪声水平,量化等效采样带来的稳定性收益。`}),(0,$.jsxs)(JQ,{title:`寿命估计稳定性`,note:`纵轴:τ₂ 相对标准差 (%) · 对数尺度 —— 扫描多个记录窗口,对比两种采样方案的拟合稳定性`,className:`scan-card`,children:[(0,$.jsxs)(`div`,{className:`mc-controls`,children:[(0,$.jsxs)(`div`,{className:`mc-ctrl`,children:[(0,$.jsxs)(`div`,{className:`control-label`,children:[(0,$.jsx)(`span`,{children:`固定 SNR`}),(0,$.jsxs)(`div`,{className:`number-box`,children:[(0,$.jsx)(`input`,{type:`number`,min:25,max:80,value:i,onChange:e=>a(Number(e.target.value))}),(0,$.jsx)(`em`,{children:`dB`})]})]}),(0,$.jsx)(`input`,{className:`range`,style:{"--value":`${(i-25)/55*100}%`},type:`range`,min:25,max:80,value:i,onChange:e=>a(Number(e.target.value))})]}),(0,$.jsxs)(`div`,{className:`mc-ctrl`,children:[(0,$.jsx)(`span`,{className:`mc-lbl`,children:`重复次数`}),(0,$.jsxs)(`b`,{children:[(0,$.jsx)(`input`,{className:`inline-num`,type:`number`,min:8,max:60,value:o,onChange:e=>s(Number(e.target.value))}),` 次 / 窗口`]})]}),(0,$.jsxs)(`div`,{className:`mc-ctrl`,children:[(0,$.jsx)(`span`,{className:`mc-lbl`,children:`随机种子`}),(0,$.jsx)(`b`,{children:c})]}),(0,$.jsxs)(`div`,{className:`mc-ctrl`,children:[(0,$.jsx)(`span`,{className:`mc-lbl`,children:`窗口扫描范围`}),(0,$.jsx)(`div`,{className:`window-chips`,children:[100,150,200,300,400].map(e=>(0,$.jsxs)(`button`,{className:l.includes(e)?`active`:``,onClick:()=>O(e),children:[e,` ns`]},e))})]}),(0,$.jsx)(XQ,{icon:n?`loader`:`play`,onClick:k,disabled:n,children:n?`扫描中 ${e}%`:`运行扫描`})]}),n&&(0,$.jsxs)(`div`,{className:`progress`,style:{marginBottom:12},children:[(0,$.jsx)(`i`,{style:{width:`${e}%`}}),(0,$.jsxs)(`span`,{children:[`扫描进行中 · `,e,`%(`,l.length,` 个窗口 × `,o,` 次)`]})]}),(0,$.jsx)(ZQ,{items:[{color:OQ.orange,label:`单通道`},{color:OQ.blue,label:`四相位等效`}]}),j?(0,$.jsx)(IQ,{option:j,height:280}):(0,$.jsx)(`div`,{className:`chart-placeholder`,children:n?`扫描进行中…`:`点击「运行扫描」开始`}),w&&w.length>0&&(0,$.jsx)(`div`,{className:`table-scroll`,style:{marginTop:12},children:(0,$.jsxs)(`table`,{children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{children:`窗口 (ns)`}),(0,$.jsx)(`th`,{children:`单通道`}),(0,$.jsx)(`th`,{children:`四相位`}),(0,$.jsx)(`th`,{children:`提升比`}),(0,$.jsx)(`th`,{children:`失败率`})]})}),(0,$.jsx)(`tbody`,{children:w.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:(0,$.jsx)(`b`,{children:e.window})}),(0,$.jsxs)(`td`,{children:[e.single?.toFixed(2)??`—`,`%`]}),(0,$.jsxs)(`td`,{children:[e.fiber?.toFixed(2)??`—`,`%`]}),(0,$.jsxs)(`td`,{className:e.ratio&&e.ratio>=3?`good`:``,children:[e.ratio?.toFixed(1),`×`]}),(0,$.jsxs)(`td`,{children:[e.single_fail.toFixed(0),`% / `,e.fiber_fail.toFixed(0),`%`]})]},e.window))})]})})]}),(0,$.jsx)(JQ,{title:`关键结论`,note:`窗口扫描的结论摘要`,children:ee?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`conclusion-row`,children:[(0,$.jsxs)(`div`,{className:`big-result`,children:[(0,$.jsx)(`span`,{children:`最大稳定性提升`}),(0,$.jsxs)(`strong`,{children:[(ee.ratio??0).toFixed(1),(0,$.jsx)(`small`,{children:`×`})]}),(0,$.jsxs)(`p`,{children:[`SNR `,i,` dB · `,ee.window,` ns`]})]}),(0,$.jsxs)(`div`,{className:`before-after`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{children:`单通道 σ/τ`}),(0,$.jsxs)(`b`,{children:[ee.single?.toFixed(2),`%`]})]}),(0,$.jsx)(GQ,{name:`chevron`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{children:`四相位 σ/τ`}),(0,$.jsxs)(`b`,{children:[ee.fiber?.toFixed(2),`%`]})]})]}),(0,$.jsxs)(`div`,{className:`reference-benchmark`,children:[(0,$.jsx)(`span`,{children:`研究报告仿真基准`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`b`,{children:`7.65%`}),(0,$.jsx)(GQ,{name:`chevron`,size:13}),(0,$.jsx)(`b`,{children:`0.60%`})]}),(0,$.jsx)(`small`,{children:`200 次蒙特卡洛 · 仅作辅助对照`})]})]}),(0,$.jsxs)(`div`,{className:`success-note`,children:[(0,$.jsx)(GQ,{name:`check`}),(0,$.jsx)(`span`,{children:`浏览器计算完成,与本地 CLI 结果一致`})]})]}):(0,$.jsx)(`div`,{className:`empty-status`,children:`运行扫描后,结论卡片将在此显示`})}),(0,$.jsxs)(JQ,{title:`蒙特卡洛 τ̂₂ 分布`,note:E&&!E.error?`窗口 ${E.window} ns · SNR ${E.snr} dB · 重复 ${E.repeats} 次 · 种子 ${S} —— 分布越窄,寿命估计越稳定`:`在同一条件下重复拟合 N 次 —— τ̂₂ 分布越窄,寿命估计越稳定(含置信区间与失败率)`,className:`mc-card`,children:[(0,$.jsxs)(`div`,{className:`mc-controls`,children:[(0,$.jsxs)(`div`,{className:`mc-ctrl`,children:[(0,$.jsxs)(`div`,{className:`control-label`,children:[(0,$.jsx)(`span`,{children:`SNR`}),(0,$.jsxs)(`div`,{className:`number-box`,children:[(0,$.jsx)(`input`,{type:`number`,min:20,max:80,value:h,onChange:e=>g(Number(e.target.value))}),(0,$.jsx)(`em`,{children:`dB`})]})]}),(0,$.jsx)(`input`,{className:`range`,style:{"--value":`${(h-20)/60*100}%`},type:`range`,min:20,max:80,value:h,onChange:e=>g(Number(e.target.value))})]}),(0,$.jsxs)(`div`,{className:`mc-ctrl`,children:[(0,$.jsx)(`span`,{className:`mc-lbl`,children:`记录窗口`}),(0,$.jsx)(`div`,{className:`window-chips`,children:[100,150,200,300,400].map(e=>(0,$.jsxs)(`button`,{className:_===e?`active`:``,onClick:()=>y(e),children:[e,` ns`]},e))})]}),(0,$.jsxs)(`div`,{className:`mc-ctrl`,children:[(0,$.jsx)(`span`,{className:`mc-lbl`,children:`重复次数`}),(0,$.jsxs)(`b`,{children:[(0,$.jsx)(`input`,{className:`inline-num`,type:`number`,min:10,max:200,value:b,onChange:e=>x(Number(e.target.value))}),` 次`]})]}),(0,$.jsxs)(`div`,{className:`mc-ctrl`,children:[(0,$.jsx)(`span`,{className:`mc-lbl`,children:`随机种子`}),(0,$.jsx)(`b`,{children:(0,$.jsx)(`input`,{className:`inline-num`,type:`number`,min:0,max:999999,value:S,onChange:e=>C(Number(e.target.value))})})]}),(0,$.jsx)(XQ,{icon:d?`loader`:`play`,onClick:A,disabled:d,children:d?`计算中…`:`运行蒙特卡洛`})]}),(0,$.jsx)(ZQ,{items:[{color:OQ.orange,label:`单通道 10 ns`},{color:OQ.blue,label:`四相位 2.5 ns`},{color:OQ.truth,label:`真值 52.8 ns`,dotted:!0}]}),p&&(0,$.jsxs)(`div`,{className:`insight`,style:{marginBottom:10},children:[(0,$.jsx)(GQ,{name:`info`}),(0,$.jsx)(`span`,{children:p})]}),E?.error===`no-fits`&&(0,$.jsxs)(`div`,{className:`insight`,style:{marginBottom:10},children:[(0,$.jsx)(GQ,{name:`info`}),(0,$.jsx)(`span`,{children:`拟合全部失败(当前条件过差),请提高 SNR 或窗口。`})]}),E&&!E.error&&(0,$.jsxs)($.Fragment,{children:[te&&(0,$.jsx)(IQ,{option:te,height:250}),(0,$.jsx)(`div`,{className:`table-scroll`,style:{marginTop:12},children:(0,$.jsxs)(`table`,{children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{children:`方案`}),(0,$.jsx)(`th`,{children:`均值 (ns)`}),(0,$.jsx)(`th`,{children:`σ/τ`}),(0,$.jsx)(`th`,{children:`bias`}),(0,$.jsx)(`th`,{children:`拟合失败`})]})}),(0,$.jsxs)(`tbody`,{children:[(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:(0,$.jsx)(`b`,{children:`单通道 10 ns`})}),(0,$.jsx)(`td`,{children:E.single.mean?.toFixed(3)??`—`}),(0,$.jsx)(`td`,{className:`bad`,children:E.single.rel_std==null?`—`:(E.single.rel_std*100).toFixed(2)+`%`}),(0,$.jsx)(`td`,{children:E.single.bias==null?`—`:(E.single.bias*100).toFixed(2)+`%`}),(0,$.jsxs)(`td`,{children:[E.single.n_failed,`/`,E.single.n]})]}),(0,$.jsxs)(`tr`,{className:`best`,children:[(0,$.jsx)(`td`,{children:(0,$.jsx)(`b`,{children:`四相位 2.5 ns`})}),(0,$.jsx)(`td`,{children:E.fiber.mean?.toFixed(3)??`—`}),(0,$.jsx)(`td`,{className:`good`,children:E.fiber.rel_std==null?`—`:(E.fiber.rel_std*100).toFixed(2)+`%`}),(0,$.jsx)(`td`,{children:E.fiber.bias==null?`—`:(E.fiber.bias*100).toFixed(2)+`%`}),(0,$.jsxs)(`td`,{children:[E.fiber.n_failed,`/`,E.fiber.n]})]})]})]})}),(0,$.jsxs)(`div`,{className:`insight`,children:[(0,$.jsx)(GQ,{name:`info`}),(0,$.jsx)(`span`,{children:`四相位等效采样的 τ̂ 分布明显比单通道窄——同参数下与上方窗口扫描结论一致;低 SNR(≤35 dB)时差距会进一步拉大,可调高 SNR 后重跑对比。`})]})]}),!E&&(0,$.jsxs)(`div`,{className:`chart-placeholder`,children:[`点击「运行蒙特卡洛」——在 SNR `,h,` dB / 窗口 `,_,` ns 条件下重复拟合 `,b,` 次,观察两种方案的 τ̂₂ 散布`]})]})]})}function h$(){let[e,t]=(0,v.useState)(!1),[n,r]=s$(`p6.name`,``),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(!1),c=[`p1`,`p2`,`p3`,`p4`,`p5`].filter(e=>r$[e]).length,l=()=>{let e=new Date,r=e=>String(e).padStart(2,`0`),i=`${`${e.getFullYear()}${r(e.getMonth()+1)}${r(e.getDate())}-${r(e.getHours())}${r(e.getMinutes())}`}-m5_gui_session${n?`-`+n:``}`,o=new Blob([JSON.stringify({exported_at:e.toISOString(),data_origin:`software-simulated`,seed:42,params:r$.params,results:{p1:r$.p1,p2:r$.p2,p3:r$.p3,p4:r$.p4,p5:r$.p5,p5mc:r$.p5mc},note:`光纤延时等效采样教学实验 · GUI 会话记录包(软件仿真,非实测)`},null,2)],{type:`application/json`}),s=(e,t)=>{let n=document.createElement(`a`);n.href=URL.createObjectURL(e),n.download=t,n.click(),URL.revokeObjectURL(n.href)};if(s(o,`${i}/session.json`),r$.p5?.length){let e=r$.p5.map(e=>[e.window,e.single,e.fiber,e.ratio?.toFixed(2)??``,e.single_fail,e.fiber_fail].join(`,`)).join(` `);s(new Blob([`window_ns,single_rel_std_pct,fiber_rel_std_pct,ratio,single_fail_pct,fiber_fail_pct -`+e],{type:`text/csv`}),`${i}/page5_scan.csv`)}a(`${i}/`),t(!0)};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(QQ,{title:`结果导出`,text:`将当前会话的参数、数据与图表打包,生成可复现的实验记录。`}),(0,$.jsxs)(`div`,{className:`export-layout`,children:[(0,$.jsxs)(JQ,{title:`创建记录包`,note:`导出包含当前会话中已计算的全部结果`,children:[(0,$.jsxs)(`label`,{className:`field`,children:[(0,$.jsx)(`span`,{children:`记录名(备注)`}),(0,$.jsx)(`input`,{placeholder:`例如:四相位采样基准实验`,value:n,onChange:e=>r(e.target.value)})]}),(0,$.jsxs)(`label`,{className:`field`,children:[(0,$.jsx)(`span`,{children:`导出方式`}),(0,$.jsxs)(`div`,{className:`path-input`,children:[(0,$.jsx)(`input`,{value:`浏览器下载(session.json + CSV)`,readOnly:!0}),(0,$.jsx)(`button`,{type:`button`,onClick:l,children:`开始导出`})]})]}),(0,$.jsxs)(`div`,{className:`export-meta`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{children:`数据来源`}),(0,$.jsx)(`b`,{children:`software-simulated`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{children:`随机种子`}),(0,$.jsx)(`b`,{children:`42`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{children:`包含页面`}),(0,$.jsxs)(`b`,{children:[c,` / 5`]})]})]}),(0,$.jsxs)(`div`,{className:`provenance-note`,children:[(0,$.jsx)(GQ,{name:`info`,size:15}),(0,$.jsx)(`span`,{children:`记录包将明确区分理论计算、软件仿真、逻辑仿真与硬件实测数据;本会话全部为软件仿真。`})]}),(0,$.jsx)(XQ,{icon:`export`,onClick:l,children:`一键导出记录包`})]}),(0,$.jsxs)(JQ,{title:`记录包内容`,note:`标准化目录结构便于复现与归档`,children:[(0,$.jsxs)(`div`,{className:`file-tree`,children:[(0,$.jsxs)(`div`,{className:`folder`,children:[`▾ `,(0,$.jsxs)(`b`,{children:[e?i:`YYYYMMDD-HHmm`,`-m5_gui_session/`]})]}),[{f:`session.json`,icon:`{}`,d:c>0?`全部参数与结果`:`(尚未运行任何实验)`,on:!0},{f:`meta.json`,icon:`{}`,d:`来源、时间与种子(内嵌 session.json)`,on:!0},{f:`page5_scan.csv`,icon:`▱`,d:r$.p5?.length?`扫描原始数据`:`执行参数扫描后生成`,on:!!r$.p5?.length}].map(e=>(0,$.jsxs)(`div`,{className:`file`,style:{opacity:e.on?1:.45},children:[(0,$.jsx)(`span`,{children:e.icon}),e.f,(0,$.jsx)(`em`,{children:e.d})]},e.f))]}),e?(0,$.jsxs)(`div`,{className:`export-success`,children:[(0,$.jsx)(GQ,{name:`check`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`b`,{children:`记录包导出成功(浏览器下载)`}),(0,$.jsx)(`span`,{children:i})]}),(0,$.jsx)(`button`,{onClick:()=>{navigator.clipboard?.writeText(i),s(!0),window.setTimeout(()=>s(!1),1400)},children:o?`已复制`:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(GQ,{name:`copy`,size:16}),`复制路径`]})})]}):(0,$.jsx)(`div`,{className:`empty-status`,children:`完成导出后,文件路径将显示在这里`}),(0,$.jsxs)(`div`,{className:`tip`,style:{marginTop:14},children:[(0,$.jsx)(GQ,{name:`info`,size:15}),(0,$.jsx)(`span`,{children:`论文图表可由对应记录包重新生成;本地 CLI(python -m fiber_delay_sim.cli all)产出完整记录包(含 SVG/PNG 图表)。`})]})]})]})]})}function m$(){let[e,t]=s$(`app.page`,0),[n,r]=(0,v.useState)(UQ()===`ready`);(0,v.useEffect)(()=>{HQ().then(()=>r(!0)).catch(()=>{})},[]),(0,v.useEffect)(()=>{(e<0||e>=qQ.length)&&t(0)},[e]);let i=[(0,$.jsx)(c$,{}),(0,$.jsx)(l$,{}),(0,$.jsx)(u$,{}),(0,$.jsx)(d$,{}),(0,$.jsx)(f$,{}),(0,$.jsx)(p$,{})][e];return(0,$.jsxs)(`div`,{className:`app-shell`,children:[(0,$.jsx)(n$,{}),(0,$.jsxs)(`aside`,{className:`sidebar`,children:[(0,$.jsxs)(`div`,{className:`brand`,children:[(0,$.jsx)(`div`,{className:`brand-mark`,children:(0,$.jsx)(GQ,{name:`pulse`,size:21})}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`b`,{children:`光纤延时`}),(0,$.jsx)(`span`,{children:`等效采样实验仿真`})]})]}),(0,$.jsxs)(`div`,{className:`integrity`,children:[(0,$.jsx)(`i`,{}),`仿真演示 · 非实测数据`]}),(0,$.jsx)(`nav`,{children:qQ.map((n,r)=>(0,$.jsxs)(`button`,{className:e===r?`active`:``,onClick:()=>t(r),children:[(0,$.jsx)(GQ,{name:n.icon}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`b`,{children:n.name}),(0,$.jsx)(`small`,{children:n.sub})]}),e===r&&(0,$.jsx)(GQ,{name:`chevron`,size:14})]},n.name))}),(0,$.jsxs)(`div`,{className:`sidebar-foot`,children:[(0,$.jsx)(`span`,{children:`PHOTONIC INSTRUMENTATION LAB`}),(0,$.jsxs)(`b`,{children:[`FDETS `,(0,$.jsx)(`em`,{children:`v2.0`})]}),(0,$.jsx)(`small`,{children:`Fiber-Delay Equivalent-Time Sampling`})]})]}),(0,$.jsxs)(`main`,{children:[(0,$.jsxs)(`header`,{className:`mobile-header`,children:[(0,$.jsxs)(`div`,{className:`brand`,children:[(0,$.jsx)(`div`,{className:`brand-mark`,children:(0,$.jsx)(GQ,{name:`pulse`,size:18})}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`b`,{children:`FiberScope`}),(0,$.jsx)(`span`,{children:`光纤延时实验仿真`})]})]}),(0,$.jsxs)(`div`,{className:`integrity`,children:[(0,$.jsx)(`i`,{}),`仿真数据`]})]}),(0,$.jsxs)(`header`,{className:`system-header`,children:[(0,$.jsxs)(`div`,{className:`system-breadcrumb`,children:[(0,$.jsx)(`span`,{children:`FDETS LAB`}),(0,$.jsx)(`i`,{children:`/`}),(0,$.jsx)(`b`,{children:qQ[e].name})]}),(0,$.jsxs)(`div`,{className:`system-meta`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{children:`数据域`}),(0,$.jsx)(`b`,{children:`SOFTWARE SIMULATION`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{children:`信号模型`}),(0,$.jsx)(`b`,{children:`BI-EXPONENTIAL`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{children:`计算引擎`}),(0,$.jsx)(`b`,{children:n?`PYODIDE`:`LOADING…`})]}),(0,$.jsxs)(`div`,{className:`system-online`,children:[(0,$.jsx)(`i`,{}),(0,$.jsx)(`span`,{children:`运行状态`}),(0,$.jsx)(`b`,{children:n?`READY`:`INIT`})]})]})]}),(0,$.jsx)(`div`,{className:`mobile-nav`,children:qQ.map((n,r)=>(0,$.jsxs)(`button`,{className:e===r?`active`:``,onClick:()=>t(r),children:[(0,$.jsx)(GQ,{name:n.icon}),(0,$.jsx)(`span`,{children:n.name})]},n.name))}),(0,$.jsx)(`div`,{className:`content`,children:i})]})]})}y.createRoot(document.getElementById(`root`)).render((0,$.jsx)(v.StrictMode,{children:(0,$.jsx)(m$,{})})); \ No newline at end of file +`+e],{type:`text/csv`}),`${i}/page5_scan.csv`)}a(`${i}/`),t(!0)};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(QQ,{title:`结果导出`,text:`将当前会话的参数、数据与图表打包,生成可复现的实验记录。`}),(0,$.jsxs)(`div`,{className:`export-layout`,children:[(0,$.jsxs)(JQ,{title:`创建记录包`,note:`导出包含当前会话中已计算的全部结果`,children:[(0,$.jsxs)(`label`,{className:`field`,children:[(0,$.jsx)(`span`,{children:`记录名(备注)`}),(0,$.jsx)(`input`,{placeholder:`例如:四相位采样基准实验`,value:n,onChange:e=>r(e.target.value)})]}),(0,$.jsxs)(`label`,{className:`field`,children:[(0,$.jsx)(`span`,{children:`导出方式`}),(0,$.jsxs)(`div`,{className:`path-input`,children:[(0,$.jsx)(`input`,{value:`浏览器下载(session.json + CSV)`,readOnly:!0}),(0,$.jsx)(`button`,{type:`button`,onClick:l,children:`开始导出`})]})]}),(0,$.jsxs)(`div`,{className:`export-meta`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{children:`数据来源`}),(0,$.jsx)(`b`,{children:`software-simulated`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{children:`随机种子`}),(0,$.jsx)(`b`,{children:`42`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{children:`包含页面`}),(0,$.jsxs)(`b`,{children:[c,` / 5`]})]})]}),(0,$.jsxs)(`div`,{className:`provenance-note`,children:[(0,$.jsx)(GQ,{name:`info`,size:15}),(0,$.jsx)(`span`,{children:`记录包将明确区分理论计算、软件仿真、逻辑仿真与硬件实测数据;本会话全部为软件仿真。`})]}),(0,$.jsx)(XQ,{icon:`export`,onClick:l,children:`一键导出记录包`})]}),(0,$.jsxs)(JQ,{title:`记录包内容`,note:`标准化目录结构便于复现与归档`,children:[(0,$.jsxs)(`div`,{className:`file-tree`,children:[(0,$.jsxs)(`div`,{className:`folder`,children:[`▾ `,(0,$.jsxs)(`b`,{children:[e?i:`YYYYMMDD-HHmm`,`-m5_gui_session/`]})]}),[{f:`session.json`,icon:`{}`,d:c>0?`全部参数与结果`:`(尚未运行任何实验)`,on:!0},{f:`meta.json`,icon:`{}`,d:`来源、时间与种子(内嵌 session.json)`,on:!0},{f:`page5_scan.csv`,icon:`▱`,d:r$.p5?.length?`扫描原始数据`:`执行参数扫描后生成`,on:!!r$.p5?.length}].map(e=>(0,$.jsxs)(`div`,{className:`file`,style:{opacity:e.on?1:.45},children:[(0,$.jsx)(`span`,{children:e.icon}),e.f,(0,$.jsx)(`em`,{children:e.d})]},e.f))]}),e?(0,$.jsxs)(`div`,{className:`export-success`,children:[(0,$.jsx)(GQ,{name:`check`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`b`,{children:`记录包导出成功(浏览器下载)`}),(0,$.jsx)(`span`,{children:i})]}),(0,$.jsx)(`button`,{onClick:()=>{navigator.clipboard?.writeText(i),s(!0),window.setTimeout(()=>s(!1),1400)},children:o?`已复制`:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(GQ,{name:`copy`,size:16}),`复制路径`]})})]}):(0,$.jsx)(`div`,{className:`empty-status`,children:`完成导出后,文件路径将显示在这里`}),(0,$.jsxs)(`div`,{className:`tip`,style:{marginTop:14},children:[(0,$.jsx)(GQ,{name:`info`,size:15}),(0,$.jsx)(`span`,{children:`论文图表可由对应记录包重新生成;本地 CLI(python -m fiber_delay_sim.cli all)产出完整记录包(含 SVG/PNG 图表)。`})]})]})]})]})}function g$(){let[e,t]=s$(`app.page`,0),[n,r]=(0,v.useState)(UQ()===`ready`);(0,v.useEffect)(()=>{HQ().then(()=>r(!0)).catch(()=>{})},[]),(0,v.useEffect)(()=>{(e<0||e>=qQ.length)&&t(0)},[e]);let i=[(0,$.jsx)(u$,{}),(0,$.jsx)(d$,{}),(0,$.jsx)(f$,{}),(0,$.jsx)(p$,{}),(0,$.jsx)(m$,{}),(0,$.jsx)(h$,{})][e];return(0,$.jsxs)(`div`,{className:`app-shell`,children:[(0,$.jsx)(n$,{}),(0,$.jsxs)(`aside`,{className:`sidebar`,children:[(0,$.jsxs)(`div`,{className:`brand`,children:[(0,$.jsx)(`div`,{className:`brand-mark`,children:(0,$.jsx)(GQ,{name:`pulse`,size:21})}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`b`,{children:`光纤延时`}),(0,$.jsx)(`span`,{children:`等效采样实验仿真`})]})]}),(0,$.jsxs)(`div`,{className:`integrity`,children:[(0,$.jsx)(`i`,{}),`仿真演示 · 非实测数据`]}),(0,$.jsx)(`nav`,{children:qQ.map((n,r)=>(0,$.jsxs)(`button`,{className:e===r?`active`:``,onClick:()=>t(r),children:[(0,$.jsx)(GQ,{name:n.icon}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`b`,{children:n.name}),(0,$.jsx)(`small`,{children:n.sub})]}),e===r&&(0,$.jsx)(GQ,{name:`chevron`,size:14})]},n.name))}),(0,$.jsxs)(`div`,{className:`sidebar-foot`,children:[(0,$.jsx)(`span`,{children:`PHOTONIC INSTRUMENTATION LAB`}),(0,$.jsxs)(`b`,{children:[`FDETS `,(0,$.jsx)(`em`,{children:`v2.0`})]}),(0,$.jsx)(`small`,{children:`Fiber-Delay Equivalent-Time Sampling`})]})]}),(0,$.jsxs)(`main`,{children:[(0,$.jsxs)(`header`,{className:`mobile-header`,children:[(0,$.jsxs)(`div`,{className:`brand`,children:[(0,$.jsx)(`div`,{className:`brand-mark`,children:(0,$.jsx)(GQ,{name:`pulse`,size:18})}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`b`,{children:`FiberScope`}),(0,$.jsx)(`span`,{children:`光纤延时实验仿真`})]})]}),(0,$.jsxs)(`div`,{className:`integrity`,children:[(0,$.jsx)(`i`,{}),`仿真数据`]})]}),(0,$.jsxs)(`header`,{className:`system-header`,children:[(0,$.jsxs)(`div`,{className:`system-breadcrumb`,children:[(0,$.jsx)(`span`,{children:`FDETS LAB`}),(0,$.jsx)(`i`,{children:`/`}),(0,$.jsx)(`b`,{children:qQ[e].name})]}),(0,$.jsxs)(`div`,{className:`system-meta`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{children:`数据域`}),(0,$.jsx)(`b`,{children:`SOFTWARE SIMULATION`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{children:`信号模型`}),(0,$.jsx)(`b`,{children:`BI-EXPONENTIAL`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{children:`计算引擎`}),(0,$.jsx)(`b`,{children:n?`PYODIDE`:`LOADING…`})]}),(0,$.jsxs)(`div`,{className:`system-online`,children:[(0,$.jsx)(`i`,{}),(0,$.jsx)(`span`,{children:`运行状态`}),(0,$.jsx)(`b`,{children:n?`READY`:`INIT`})]})]})]}),(0,$.jsx)(`div`,{className:`mobile-nav`,children:qQ.map((n,r)=>(0,$.jsxs)(`button`,{className:e===r?`active`:``,onClick:()=>t(r),children:[(0,$.jsx)(GQ,{name:n.icon}),(0,$.jsx)(`span`,{children:n.name})]},n.name))}),(0,$.jsx)(`div`,{className:`content`,children:i})]})]})}if(y.createRoot(document.getElementById(`root`)).render((0,$.jsx)(v.StrictMode,{children:(0,$.jsx)(g$,{})})),`serviceWorker`in navigator&&location.protocol===`https:`){let e=()=>navigator.serviceWorker.register(`/sw.js?v=2`).catch(()=>{});document.readyState===`complete`?e():window.addEventListener(`load`,e,{once:!0})} \ No newline at end of file diff --git a/figma/dist/index.html b/figma/dist/index.html index 6a103dc..7fd2e70 100644 --- a/figma/dist/index.html +++ b/figma/dist/index.html @@ -4,7 +4,7 @@ 光纤延时等效采样 · 教学实验仿真 - + diff --git a/figma/dist/sw.js b/figma/dist/sw.js new file mode 100644 index 0000000..08676dd --- /dev/null +++ b/figma/dist/sw.js @@ -0,0 +1,65 @@ +/* Service Worker:静态资源持久缓存(Pyodide 运行时 + 构建产物) + * 首次访问从网络拉取并写入 Cache API;此后(包括刷新/离线)全部本地命中, + * Pyodide 引擎启动从 ~60s 降到 ~2-3s。 + * 缓存策略: + * - "/pyodide/...":带版本(v0.26.4),内容不可变 → cache-first,永不淘汰 + * - "/assets/...":文件名带内容 hash → cache-first + * - "/py/..."(算法核心 py 文件):no-store 语义 → network-only(SW 不缓存) + * - 根路径与 index.html:network-first(SW 更新后立即生效) + */ + +const CACHE = "fdets-static-v1"; +const IMMUTABLE = [ + /\/pyodide\//, // 自托管 Pyodide 运行时(版本化,immutable) + /\/assets\/.+-[A-Za-z0-9_]{8}\.[a-z]+$/, // vite 内容 hash 产物 +]; + +self.addEventListener("install", (e) => { + self.skipWaiting(); + e.waitUntil(caches.open(CACHE)); +}); + +self.addEventListener("activate", (e) => { + e.waitUntil((async () => { + // 清理旧版本缓存 + const keys = await caches.keys(); + await Promise.all(keys.filter(k => k.startsWith("fdets-static-") && k !== CACHE).map(k => caches.delete(k))); + await self.clients.claim(); + })()); +}); + +self.addEventListener("fetch", (e) => { + const url = new URL(e.request.url); + if (url.origin !== location.origin) return; // 只管同源 + if (e.request.method !== "GET") return; + + // 不可变静态资源:cache-first + if (IMMUTABLE.some((re) => re.test(url.pathname))) { + e.respondWith((async () => { + const cached = await caches.match(e.request); + if (cached) return cached; + const resp = await fetch(e.request); + if (resp.ok) { + const cache = await caches.open(CACHE); + cache.put(e.request, resp.clone()); + } + return resp; + })()); + return; + } + + // HTML 入口:network-first(保证新版本部署后立即生效) + if (url.pathname === "/" || url.pathname.endsWith(".html")) { + e.respondWith((async () => { + try { + const resp = await fetch(e.request, { cache: "no-store" }); + return resp; + } catch { + const cached = await caches.match(e.request); + if (cached) return cached; + throw new Error("offline"); + } + })()); + } + // 其余(py 算法核心等):默认行为,不拦截 +}); \ No newline at end of file diff --git a/figma/public/sw.js b/figma/public/sw.js new file mode 100644 index 0000000..08676dd --- /dev/null +++ b/figma/public/sw.js @@ -0,0 +1,65 @@ +/* Service Worker:静态资源持久缓存(Pyodide 运行时 + 构建产物) + * 首次访问从网络拉取并写入 Cache API;此后(包括刷新/离线)全部本地命中, + * Pyodide 引擎启动从 ~60s 降到 ~2-3s。 + * 缓存策略: + * - "/pyodide/...":带版本(v0.26.4),内容不可变 → cache-first,永不淘汰 + * - "/assets/...":文件名带内容 hash → cache-first + * - "/py/..."(算法核心 py 文件):no-store 语义 → network-only(SW 不缓存) + * - 根路径与 index.html:network-first(SW 更新后立即生效) + */ + +const CACHE = "fdets-static-v1"; +const IMMUTABLE = [ + /\/pyodide\//, // 自托管 Pyodide 运行时(版本化,immutable) + /\/assets\/.+-[A-Za-z0-9_]{8}\.[a-z]+$/, // vite 内容 hash 产物 +]; + +self.addEventListener("install", (e) => { + self.skipWaiting(); + e.waitUntil(caches.open(CACHE)); +}); + +self.addEventListener("activate", (e) => { + e.waitUntil((async () => { + // 清理旧版本缓存 + const keys = await caches.keys(); + await Promise.all(keys.filter(k => k.startsWith("fdets-static-") && k !== CACHE).map(k => caches.delete(k))); + await self.clients.claim(); + })()); +}); + +self.addEventListener("fetch", (e) => { + const url = new URL(e.request.url); + if (url.origin !== location.origin) return; // 只管同源 + if (e.request.method !== "GET") return; + + // 不可变静态资源:cache-first + if (IMMUTABLE.some((re) => re.test(url.pathname))) { + e.respondWith((async () => { + const cached = await caches.match(e.request); + if (cached) return cached; + const resp = await fetch(e.request); + if (resp.ok) { + const cache = await caches.open(CACHE); + cache.put(e.request, resp.clone()); + } + return resp; + })()); + return; + } + + // HTML 入口:network-first(保证新版本部署后立即生效) + if (url.pathname === "/" || url.pathname.endsWith(".html")) { + e.respondWith((async () => { + try { + const resp = await fetch(e.request, { cache: "no-store" }); + return resp; + } catch { + const cached = await caches.match(e.request); + if (cached) return cached; + throw new Error("offline"); + } + })()); + } + // 其余(py 算法核心等):默认行为,不拦截 +}); \ No newline at end of file diff --git a/figma/src/App.tsx b/figma/src/App.tsx index 97957d6..263c04b 100644 --- a/figma/src/App.tsx +++ b/figma/src/App.tsx @@ -127,6 +127,10 @@ function pload(key: string, fallback: T): T { const raw = localStorage.getItem(LS_NS + key); if (raw == null) return fallback; const v = JSON.parse(raw); + if (v === null) { + // 显式区分 "存过 null"(允许,如结果清空)与 "无记录" + return fallback === null ? null as T : fallback; + } // 类型不匹配(旧版残留/手改损坏)时回退默认值 if (Array.isArray(fallback) !== Array.isArray(v)) return fallback; if (typeof v !== typeof fallback) return fallback; @@ -147,6 +151,46 @@ function useSticky(key: string, initial: T) { return [v, setV] as const; } +/** + * 持久化计算结果:附带参数指纹。 + * - 保存:{ fp: 指纹, data: 结果 },参数变化 → 新指纹 → 旧结果恢复时校验失败自动作废; + * - 这样保证“刷新后图表保留”,同时“改参数后旧图不会被误显示”。 + */ +function useStickyResult(key: string, fingerprint: string) { + const fpKey = key + ".fp"; + const [v, setV] = useState(() => { + const savedFpRaw = localStorage.getItem(LS_NS + fpKey); + let savedFp: string | null = null; + try { savedFp = savedFpRaw == null ? null : JSON.parse(savedFpRaw); } catch { savedFp = null; } + if (savedFp !== fingerprint) return null; // 参数已变:旧结果作废 + return ploadStrict(key, null); + }); + // 保存:新数据到达即写入并同步指纹。 + // 注意不用 v==null 判断去删除存档——刷新恢复的初始 null 会误删(React 18/19 + // StrictMode 下 effect 双跑加剧);显式置 null 的场景(run 前 setRows([])) + // 紧接着就会写入新结果,旧档被覆盖即可。 + useEffect(() => { + if (v != null) { + psave(key, v); + psave(fpKey, fingerprint); + } + // fingerprint 变化(参数编辑中)不触发清档——加载时校验已兜底 + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [v]); + return [v, setV] as const; +} + +/** useStickyResult 专用加载:不做类型校验直接 JSON.parse(数据形状由消费端 JSX 防护) */ +function ploadStrict(key: string, fallback: T): T { + try { + const raw = localStorage.getItem(LS_NS + key); + if (raw == null) return fallback; + return JSON.parse(raw) as T; + } catch { + return fallback; + } +} + function clearPersisted() { try { Object.keys(localStorage) @@ -166,7 +210,7 @@ function ParameterPage() { const [targets, setTargets] = useSticky("p1.targets", [0, 2.5, 5, 7.5]); const [running, setRunning] = useState(false); const [copied, setCopied] = useState(false); - const [res, setRes] = useState(null); + const [res, setRes] = useStickyResult("p1.res", JSON.stringify([lengths, ng, dt, targets])); const [err, setErr] = useState(""); const phases = useMemo(() => lengths.map((l) => (l * ng / 0.2998) % dt), [lengths, ng, dt]); @@ -299,7 +343,7 @@ function SamplingPage() { const [window_, setWindow] = useSticky("p2.window", "400"); const [ideal, setIdeal] = useSticky("p2.ideal", false); const [seed, setSeed] = useSticky("p2.seed", 42); - const [res, setRes] = useState(null); + const [res, setRes] = useStickyResult("p2.res", JSON.stringify([window_, snr, bits, ideal, seed])); const [running, setRunning] = useState(false); const [err, setErr] = useState(""); @@ -370,7 +414,7 @@ function CalibrationPage() { const [delay, setDelay] = useSticky("p3.delay", 1); const [baseline, setBaseline] = useSticky("p3.baseline", 1); const [snr, setSnr] = useSticky("p3.snr", 50); - const [res, setRes] = useState(null); + const [res, setRes] = useStickyResult("p3.res", JSON.stringify([gain, delay, baseline, snr])); const [running, setRunning] = useState(false); const [err, setErr] = useState(""); @@ -447,7 +491,7 @@ function FitPage() { const [snr, setSnr] = useSticky("p4.snr", 50); const [seed, setSeed] = useSticky("p4.seed", 42); const [algos, setAlgos] = useSticky("p4.algos", ["NLS", "对数线性", "稳健拟合"]); - const [res, setRes] = useState(null); + const [res, setRes] = useStickyResult("p4.res", JSON.stringify([snr, seed])); const [running, setRunning] = useState(false); const [err, setErr] = useState(""); @@ -517,14 +561,14 @@ function ScanPage() { const [repeats, setRepeats] = useSticky("p5.repeats", 16); const [seed] = useSticky("p5.seed", 42); const [wins, setWins] = useSticky("p5.wins", [100, 150, 200, 300, 400]); - const [rows, setRows] = useState([]); - const [mc, setMc] = useState(null); const [mcRunning, setMcRunning] = useState(false); const [mcErr, setMcErr] = useState(""); const [mcSnr, setMcSnr] = useSticky("p5.mcSnr", 50); const [mcWindow, setMcWindow] = useSticky("p5.mcWindow", 400); const [mcRepeats, setMcRepeats] = useSticky("p5.mcRepeats", 30); const [mcSeed, setMcSeed] = useSticky("p5.mcSeed", 42); + const [rows, setRows] = useStickyResult("p5.rows", JSON.stringify([snr, repeats, seed, wins])); + const [mc, setMc] = useStickyResult("p5.mc", JSON.stringify([mcSnr, mcRepeats, mcSeed, mcWindow])); const toggleWin = (w: number) => setWins((prev) => prev.includes(w) ? (prev.length > 1 ? prev.filter((x) => x !== w) : prev) : [...prev, w].sort((a, b) => a - b)); @@ -549,13 +593,13 @@ function ScanPage() { setMcRunning(false); }; - if (rows.length) session.p5 = rows; + if (rows?.length) session.p5 = rows; if (mc && !mc.error) (session as any).p5mc = mc; session.params = { ...session.params, p5_snr: snr, p5_repeats: repeats, p5_wins: wins, p5_seed: seed, mc: { snr: mcSnr, window: mcWindow, repeats: mcRepeats, seed: mcSeed } }; const option = useMemo(() => { - if (!rows.length) return null; + if (!rows?.length) return null; return { grid: { left: 52, right: 20, top: 34, bottom: 40 }, tooltip: chartTooltip(), @@ -570,7 +614,7 @@ function ScanPage() { }, [rows]); const best = useMemo(() => { - if (!rows.length) return null; + if (!rows?.length) return null; const valid = rows.filter((r) => r.ratio && isFinite(r.ratio)); if (!valid.length) return null; return valid.reduce((a, b) => ((a.ratio ?? 0) > (b.ratio ?? 0) ? a : b)); @@ -625,7 +669,7 @@ function ScanPage() { {running &&
扫描进行中 · {progress}%({wins.length} 个窗口 × {repeats} 次)
} {option ? :
{running ? "扫描进行中…" : "点击「运行扫描」开始"}
} - {rows.length > 0 &&
+ {rows && rows.length > 0 &&
窗口 (ns)单通道四相位提升比失败率
{rows.map((r) => )}
窗口 (ns)单通道四相位提升比失败率
{r.window}{r.single?.toFixed(2) ?? "—"}%{r.fiber?.toFixed(2) ?? "—"}%= 3 ? "good" : ""}>{r.ratio?.toFixed(1)}×{r.single_fail.toFixed(0)}% / {r.fiber_fail.toFixed(0)}%
} diff --git a/figma/src/engine.ts b/figma/src/engine.ts index 852fc94..ea27f4b 100644 --- a/figma/src/engine.ts +++ b/figma/src/engine.ts @@ -190,17 +190,27 @@ declare global { } async function loadEngine(): Promise { - // 动态加载 Pyodide(与旧版网站一致的 CDN 版本) + // Pyodide 运行时自托管(同源 /pyodide/,经 Cloudflare 缓存到边缘,国内无需直连 jsdelivr) + const PYODIDE_BASE = "/pyodide/"; + // 本地 dev(vite 5188)时无 /pyodide/,回退 CDN + const probe = await fetch(PYODIDE_BASE + "pyodide-lock.json", { method: "HEAD" }).catch(() => null); + const base = probe && probe.ok ? location.origin + PYODIDE_BASE : "https://cdn.jsdelivr.net/pyodide/v0.26.4/full/"; + if (!window.loadPyodide) { await new Promise((resolve, reject) => { const s = document.createElement("script"); - s.src = "https://cdn.jsdelivr.net/pyodide/v0.26.4/full/pyodide.js"; + s.src = base + "pyodide.js"; s.onload = () => resolve(); - s.onerror = () => reject(new Error("Pyodide 脚本加载失败(需访问 cdn.jsdelivr.net)")); + s.onerror = () => reject(new Error("Pyodide 脚本加载失败")); document.head.appendChild(s); }); } - pyodide = await window.loadPyodide({ indexURL: "https://cdn.jsdelivr.net/pyodide/v0.26.4/full/" }); + pyodide = await window.loadPyodide({ + indexURL: base, + // 关键:wheel 下载进 IndexedDB,二次访问免网络(配合 HTTP 缓存双保险) + packageCacheDir: "idb", + lockFileURL: base + "pyodide-lock.json", + }); await pyodide.loadPackage(["numpy", "scipy"]); pyodide.runPython("import sys; sys.path.insert(0, '/')"); for (const rel of CORE_FILES) { diff --git a/figma/src/main.tsx b/figma/src/main.tsx index 964aeb4..8c23148 100755 --- a/figma/src/main.tsx +++ b/figma/src/main.tsx @@ -8,3 +8,12 @@ ReactDOM.createRoot(document.getElementById('root')!).render( , ) + +// Service Worker:缓存 Pyodide 运行时与构建产物,二次访问引擎秒级就绪 +// (注意 /sw.js 自身避免被 CF/浏览器长缓存钉死:URL 带版本参数,更新时递增) +if ("serviceWorker" in navigator && location.protocol === "https:") { + const SW_URL = "/sw.js?v=2"; + const register = () => navigator.serviceWorker.register(SW_URL).catch(() => { /* 注册失败不影响主功能 */ }); + if (document.readyState === "complete") register(); + else window.addEventListener("load", register, { once: true }); +}