1c837766cd
Add backend-driven assembly and simulation experiences, MAKE branding, mobile rendering budgets and desktop-only CAD/PCB routes. Improve logo loading progress, document image recovery and URDF request handling; include dev packaging and regression coverage.
51 lines
1.9 KiB
JavaScript
51 lines
1.9 KiB
JavaScript
// 启动页:盖住整页,等主模型加载完成后再揭开。
|
|
// 页面里调用 splashProgress(0..1) 汇报进度,splashDone() 表示可以展示了。
|
|
// 是否跳过由页面 <head> 里的内联脚本判断(站内跳转跳过,刷新 / 外部进入显示)
|
|
const skip = document.documentElement.classList.contains('no-splash');
|
|
if (skip) document.getElementById('splash')?.remove();
|
|
const el = skip ? null : document.getElementById('splash');
|
|
|
|
const pct = el?.querySelector('.splash-pct');
|
|
const start = performance.now();
|
|
const MIN_MS = 500;
|
|
|
|
let target = 0;
|
|
let shown = 0;
|
|
let done = false;
|
|
let timer = 0;
|
|
let requested = false;
|
|
|
|
// 用定时器而不是 rAF:后台标签页里 rAF 会暂停,启动页就会一直挡着
|
|
function tick() {
|
|
const trickle = Math.min(0.85, ((performance.now() - start) / 5000) * 0.85);
|
|
shown = done ? 1 : Math.max(shown, target, trickle);
|
|
el.style.setProperty('--splash-unrevealed', `${(1 - shown) * 100}%`);
|
|
pct.textContent = String(Math.round(shown * 100)).padStart(3, '0');
|
|
if (done) { clearInterval(timer); setTimeout(finish, 450); }
|
|
}
|
|
|
|
function finish() {
|
|
if (!el || el.classList.contains('out')) return;
|
|
clearInterval(timer);
|
|
el.classList.add('out');
|
|
document.documentElement.classList.remove('is-loading');
|
|
setTimeout(() => el.remove(), 900);
|
|
}
|
|
|
|
export function splashProgress(p) {
|
|
if (Number.isFinite(p)) target = Math.max(target, Math.min(0.95, p));
|
|
}
|
|
|
|
export function splashDone({ failed = false } = {}) {
|
|
if (!el || requested) return;
|
|
requested = true;
|
|
if (failed) { finish(); return; }
|
|
setTimeout(() => { done = true; tick(); }, Math.max(0, MIN_MS - (performance.now() - start)));
|
|
}
|
|
|
|
if (el) {
|
|
timer = setInterval(tick, 120);
|
|
// 慢网先让用户读页面,不能把未完成的加载伪装成 100%。舞台继续显示加载状态。
|
|
setTimeout(() => { if (!requested) { requested = true; finish(); } }, 8000);
|
|
}
|