feat(site): upgrade documentation reader with full-book handbooks and search

Compile unabridged bilingual Developer Handbook and Mod Authoring Handbook from repository Markdown with nested list and ordered-list continuation fixes, fix primary button text contrast inside doc sections, and add full-book search, expand-all Ctrl+F mode, active chapter sub-TOC, pushState history, and local file:// link fallback.
This commit is contained in:
N0VAN0M4LY committed 2026-12-03 11:26:11 +08:00
1 parent c265ccbb61
commit fa05f36584
5 files changed
+3794 -594

No files matched your search

+1305 -225
View File
File diff suppressed because it is too large. Load diff
+1797 -265
View File
File diff suppressed because it is too large. Load diff
+371 -47
View File
@@ -55,6 +55,16 @@ code {
opacity: 0.24;
}
body[data-page='dev-docs'] .bg-stage,
body[data-page='mod-docs'] .bg-stage {
opacity: 0.26;
}
:root[data-mode='light'] body[data-page='dev-docs'] .bg-stage,
:root[data-mode='light'] body[data-page='mod-docs'] .bg-stage {
opacity: 0.14;
}
.bg-slide {
position: absolute;
inset: -3%;
@@ -1041,30 +1051,156 @@ p.lede {
/* ---------------- Documentation Subpages (/dev-docs, /mod-docs) ---------------- */
.wrap-doc {
max-width: 1140px;
max-width: 1180px;
}
.doc-layout {
display: grid;
grid-template-columns: 230px minmax(0, 1fr);
gap: clamp(24px, 4vw, 44px);
grid-template-columns: 276px minmax(0, 1fr);
gap: clamp(24px, 3.8vw, 42px);
align-items: start;
padding: 10px 0 clamp(36px, 6vh, 64px);
}
.doc-toc {
position: sticky;
top: 76px;
padding: 16px;
top: 74px;
max-height: calc(100vh - 92px);
overflow-y: auto;
padding: 15px;
border-radius: var(--r-md);
border: 1px solid var(--border);
background: var(--doc-card);
-webkit-backdrop-filter: blur(14px);
backdrop-filter: blur(14px);
display: flex;
flex-direction: column;
gap: 12px;
}
.doc-tools {
display: flex;
flex-direction: column;
gap: 8px;
}
.doc-search {
position: relative;
}
.doc-search-input {
width: 100%;
height: 34px;
padding: 0 11px;
border-radius: var(--r-sm);
border: 1px solid var(--border-2);
background: var(--glass-2);
color: var(--text);
font-family: var(--font-ui);
font-size: 13px;
outline: none;
transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
}
.doc-search-input::placeholder {
color: var(--text-faint);
}
.doc-search-input:focus {
border-color: var(--accent);
background: var(--surface);
-webkit-backdrop-filter: blur(12px);
backdrop-filter: blur(12px);
}
.doc-search-results {
display: none;
flex-direction: column;
gap: 4px;
margin-top: 6px;
max-height: 280px;
overflow-y: auto;
padding: 6px;
border-radius: var(--r-sm);
border: 1px solid var(--border-2);
background: var(--elev);
box-shadow: var(--shadow-md);
}
.doc-search-results.open {
display: flex;
}
.doc-search-item {
display: flex;
flex-direction: column;
gap: 2px;
padding: 7px 9px;
border-radius: var(--r-xs);
text-decoration: none;
color: var(--text);
border: 1px solid transparent;
transition: background 0.16s var(--ease), border-color 0.16s var(--ease);
}
.doc-search-item:hover {
background: var(--accent-soft);
border-color: rgba(229, 57, 53, 0.35);
}
.doc-search-item-head {
font-size: 12.5px;
font-weight: 600;
color: var(--text);
}
.doc-search-item-chap {
font-family: var(--font-mono);
font-size: 11px;
color: var(--accent);
}
.doc-search-item-snip {
font-size: 12px;
color: var(--text-faint);
line-height: 1.45;
}
.doc-search-empty {
padding: 8px 10px;
font-size: 12.5px;
color: var(--text-faint);
}
.doc-expand-btn {
width: 100%;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 6px;
padding: 6px 10px;
border-radius: var(--r-sm);
border: 1px solid var(--border);
background: var(--glass-2);
color: var(--text-dim);
font-family: var(--font-ui);
font-size: 12.5px;
font-weight: 500;
cursor: pointer;
transition: color 0.2s var(--ease), border-color 0.2s var(--ease), background 0.2s var(--ease);
}
.doc-expand-btn:hover {
color: var(--text);
border-color: var(--border-2);
}
.doc-expand-btn.active {
color: #ffffff;
background: var(--accent);
border-color: var(--accent);
}
.doc-toc-title {
margin: 0 0 10px;
margin: 0 0 6px;
font-family: var(--font-mono);
font-size: 11px;
letter-spacing: 0.14em;
@@ -1078,7 +1214,7 @@ p.lede {
gap: 2px;
}
.doc-toc a {
.doc-toc nav > a {
padding: 6px 10px;
border-radius: var(--r-xs);
border-left: 2px solid transparent;
@@ -1089,17 +1225,68 @@ p.lede {
transition: color 0.2s var(--ease), background 0.2s var(--ease), border-color 0.2s var(--ease);
}
.doc-toc a:hover {
.doc-toc nav > a:hover {
color: var(--text);
background: var(--glass-2);
}
.doc-toc a.active {
.doc-toc nav > a.active {
color: var(--accent);
font-weight: 600;
border-left-color: var(--accent);
background: var(--accent-soft);
}
.doc-subtoc {
display: flex;
flex-direction: column;
gap: 1px;
margin: 2px 0 6px 10px;
padding-left: 8px;
border-left: 1px solid var(--border);
}
.doc-subtoc:empty {
display: none;
}
.doc-subtoc a {
padding: 4px 8px;
border-radius: var(--r-xs);
color: var(--text-faint);
text-decoration: none;
font-size: 12px;
line-height: 1.4;
transition: color 0.18s var(--ease), background 0.18s var(--ease);
}
.doc-subtoc a:hover {
color: var(--text);
background: var(--glass-2);
}
.doc-toc-card {
padding-top: 10px;
border-top: 1px solid var(--border);
font-size: 12px;
color: var(--text-faint);
line-height: 1.55;
}
.doc-toc-card a {
display: inline-flex;
align-items: center;
gap: 4px;
margin-top: 6px;
color: var(--accent);
font-weight: 600;
text-decoration: none;
}
.doc-toc-card a:hover {
text-decoration: underline;
}
.doc-body {
display: flex;
flex-direction: column;
@@ -1109,35 +1296,62 @@ p.lede {
.doc-section {
scroll-margin-top: 80px;
padding: clamp(20px, 3vw, 30px);
padding: clamp(22px, 3.2vw, 34px);
border-radius: var(--r-lg);
border: 1px solid var(--border);
background: var(--card);
-webkit-backdrop-filter: blur(14px);
backdrop-filter: blur(14px);
background: var(--doc-card);
-webkit-backdrop-filter: blur(16px);
backdrop-filter: blur(16px);
box-shadow: var(--shadow-sm);
}
.doc-section h2 {
margin: 0 0 12px;
margin: 0 0 16px;
padding-bottom: 12px;
border-bottom: 1px solid var(--border);
font-family: var(--font-display);
font-size: clamp(20px, 2.4vw, 25px);
font-size: clamp(22px, 2.6vw, 28px);
font-weight: 700;
letter-spacing: -0.01em;
line-height: 1.25;
}
.doc-section h3 {
margin: 22px 0 8px;
font-size: 15.5px;
font-weight: 660;
color: var(--text);
}
.doc-section h3 {
scroll-margin-top: 84px;
margin: 30px 0 12px;
padding-left: 11px;
border-left: 3px solid var(--accent);
font-size: 18px;
font-weight: 700;
line-height: 1.35;
color: var(--text);
}
.doc-section h4 {
scroll-margin-top: 84px;
margin: 22px 0 8px;
font-size: 15.5px;
font-weight: 660;
line-height: 1.4;
color: var(--text);
}
.doc-section h5 {
scroll-margin-top: 84px;
margin: 18px 0 6px;
font-family: var(--font-mono);
font-size: 13.8px;
font-weight: 660;
line-height: 1.45;
color: var(--accent);
}
.doc-section p {
margin: 0 0 12px;
margin: 0 0 13px;
color: var(--text-dim);
font-size: 14.5px;
line-height: 1.75;
line-height: 1.78;
}
.doc-section p:last-child {
@@ -1146,52 +1360,158 @@ p.lede {
.doc-section ul,
.doc-section ol {
margin: 0 0 14px;
padding-left: 1.35em;
margin: 0 0 15px;
padding-left: 1.45em;
color: var(--text-dim);
font-size: 14px;
font-size: 14.3px;
}
.doc-section ul ul,
.doc-section ol ul,
.doc-section ul ol,
.doc-section ol ol {
margin: 6px 0 8px;
padding-left: 1.35em;
}
.doc-section li {
margin-bottom: 6px;
line-height: 1.68;
margin-bottom: 7px;
line-height: 1.72;
}
.doc-section li > .doc-pre,
.doc-section li > blockquote {
margin-top: 10px;
margin-bottom: 12px;
}
.doc-section li strong {
color: var(--text);
}
.doc-section a {
.doc-section a:not(.btn) {
color: var(--accent);
text-decoration: none;
}
.doc-section a:hover {
.doc-section a:not(.btn):hover {
text-decoration: underline;
}
.doc-chapter {
display: none;
}
.doc-chapter.active,
body.doc-expand-all .doc-chapter {
display: block;
animation: tabSwitch 0.32s var(--ease) both;
}
body.doc-expand-all .doc-pager {
display: none;
}
.doc-pager {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
gap: 12px;
margin-top: 28px;
padding-top: 20px;
border-top: 1px solid var(--border);
}
.doc-pager-btn {
display: inline-flex;
flex-direction: column;
align-items: flex-start;
gap: 2px;
padding: 10px 16px;
border-radius: var(--r-sm);
border: 1px solid var(--border);
background: var(--surface);
color: var(--text);
text-decoration: none;
cursor: pointer;
min-width: 180px;
transition: border-color 0.2s var(--ease), transform 0.2s var(--ease);
}
.doc-pager-btn.next {
margin-left: auto;
align-items: flex-end;
text-align: right;
}
.doc-pager-btn:hover {
border-color: var(--accent);
transform: translateY(-2px);
}
.doc-pager-label {
font-family: var(--font-mono);
font-size: 11px;
color: var(--text-faint);
letter-spacing: 0.08em;
text-transform: uppercase;
}
.doc-pager-title {
font-size: 13.5px;
font-weight: 600;
color: var(--text);
}
.doc-section blockquote {
margin: 15px 0;
padding: 13px 16px;
border-radius: var(--r-sm);
border: 1px solid color-mix(in srgb, var(--accent-2) 32%, transparent);
border-left: 3px solid var(--accent-2);
background: color-mix(in srgb, var(--accent-2) 8%, transparent);
color: var(--text);
font-size: 13.8px;
line-height: 1.72;
}
.doc-section blockquote p {
color: var(--text);
margin: 0 0 6px;
}
.doc-section blockquote p:last-child {
margin-bottom: 0;
}
.doc-section hr {
border: none;
border-top: 1px solid var(--border);
margin: 26px 0;
}
.doc-callout {
margin: 14px 0;
margin: 15px 0;
padding: 13px 16px;
border-radius: var(--r-sm);
border: 1px solid rgba(229, 57, 53, 0.34);
border-left: 3px solid var(--accent);
background: var(--accent-soft);
font-size: 13.5px;
font-size: 13.8px;
color: var(--text);
line-height: 1.68;
line-height: 1.7;
}
.doc-callout.info {
border-color: rgba(49, 227, 238, 0.30);
border-color: color-mix(in srgb, var(--accent-2) 32%, transparent);
border-left-color: var(--accent-2);
background: rgba(49, 227, 238, 0.08);
background: color-mix(in srgb, var(--accent-2) 8%, transparent);
}
.doc-table-wrap {
width: 100%;
overflow-x: auto;
margin: 14px 0;
margin: 15px 0;
border-radius: var(--r-sm);
border: 1px solid var(--border);
}
@@ -1200,7 +1520,7 @@ p.lede {
width: 100%;
border-collapse: collapse;
font-size: 13.5px;
line-height: 1.6;
line-height: 1.64;
}
.doc-table th,
@@ -1257,15 +1577,15 @@ p.lede {
.doc-pre {
position: relative;
margin: 14px 0;
margin: 15px 0;
border-radius: var(--r-sm);
border: 1px solid var(--border);
background: rgba(7, 10, 12, 0.72);
background: rgba(7, 10, 12, 0.82);
overflow: hidden;
}
:root[data-mode='light'] .doc-pre {
background: #f5f7f9;
background: #f4f6f9;
}
.doc-pre-head {
@@ -1286,7 +1606,7 @@ p.lede {
overflow-x: auto;
font-family: var(--font-mono);
font-size: 12.5px;
line-height: 1.62;
line-height: 1.64;
color: var(--text);
}
@@ -1301,29 +1621,33 @@ p.lede {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin-top: 16px;
margin-top: 18px;
}
@media (max-width: 860px) {
@media (max-width: 900px) {
.doc-layout {
grid-template-columns: 1fr;
}
.doc-toc {
position: static;
max-height: none;
}
.doc-toc nav {
flex-direction: row;
flex-wrap: wrap;
gap: 6px;
}
.doc-toc a {
.doc-toc nav > a {
border-left: none;
border: 1px solid var(--border);
padding: 5px 10px;
}
.doc-toc a.active {
.doc-toc nav > a.active {
border-color: var(--accent);
}
.doc-subtoc {
display: none;
}
}
/* ---------------- Community CTA & Scope Banner ---------------- */
+298 -36
View File
@@ -1,22 +1,66 @@
/* ============================================================
* WTOffline Project Homepage & All-Releases Script
* Classic non-module script so opening HTML files directly via
* file:// works without a local server.
* Handles: language toggle, color theme toggle, opening shutter,
* scroll reveal, pointer spotlight, sticky header, internal page
* transition, and live release catalog rendering.
* WTOffline Website & Documentation Reader Script
* Zero-dependency classic script supporting:
* - Bilingual toggle (zh-CN / EN) and dark/light theme toggle
* - Rotating public-domain daylight military backdrop
* - Smooth internal navigation (with automatic file:// fallback
* so local preview clicks on /dev-docs, /mod-docs, /releases work)
* - Multi-chapter documentation reader with pushState history,
* sub-heading deep links, active chapter sub-TOC, live full-book
* search, expand-all mode (for native Ctrl+F), and clipboard fallback
* - Dynamic release catalog rendering (R2 primary -> GitHub fallback)
* ============================================================ */
(function () {
'use strict';
// Primary release feed is served via edge object storage to keep origin server load low;
// falls back to GitHub Releases API when unavailable.
var PRIMARY_FEED = 'https://dl.wto-project.net/releases';
var FALLBACK_FEED = 'https://api.github.com/repos/N0VAN0M4LY/WT-Offline/releases?per_page=30';
var GH_RELEASES = 'https://github.com/N0VAN0M4LY/WT-Offline/releases';
var SUN_SVG =
'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">' +
'<circle cx="12" cy="12" r="4"/>' +
'<path d="M12 2.5v2.2M12 19.3v2.2M21.5 12h-2.2M4.7 12H2.5M18.7 5.3l-1.5 1.5M6.8 17.2l-1.5 1.5M18.7 18.7l-1.5-1.5M6.8 6.8 5.3 5.3"/>' +
'</svg>';
var MOON_SVG =
'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">' +
'<path d="M21 12.8A8.5 8.5 0 1 1 11.2 3a6.8 6.8 0 0 0 9.8 9.8z"/>' +
'</svg>';
var reduce = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
var pageKind = document.body.getAttribute('data-page') || 'home';
var docRefreshHook = null;
// ---- Copy text helper with non-HTTPS / file:// fallback ----
function copyText(text) {
if (navigator.clipboard && navigator.clipboard.writeText) {
return navigator.clipboard.writeText(text).catch(function () {
return legacyCopy(text);
});
}
return legacyCopy(text);
}
function legacyCopy(text) {
return new Promise(function (resolve, reject) {
try {
var ta = document.createElement('textarea');
ta.value = text;
ta.setAttribute('readonly', '');
ta.style.position = 'fixed';
ta.style.opacity = '0';
ta.style.left = '-9999px';
document.body.appendChild(ta);
ta.select();
var ok = document.execCommand('copy');
document.body.removeChild(ta);
if (ok) resolve();
else reject(new Error('copy failed'));
} catch (err) {
reject(err);
}
});
}
// ---- Language (zh / en) ----
var currentLang = 'zh';
@@ -37,6 +81,7 @@
currentLang = currentLang === 'zh' ? 'en' : 'zh';
applyLang(currentLang);
try { localStorage.setItem('wto.site.lang', currentLang); } catch (err) { /* noop */ }
if (docRefreshHook) docRefreshHook();
});
})();
@@ -60,6 +105,10 @@
? 'WTOffline · 战争雷霆本地单机离线项目'
: 'WTOffline · Local Single-Player Offline Project for War Thunder';
}
var searchInput = document.querySelector('[data-doc-search]');
if (searchInput) {
searchInput.placeholder = lang === 'zh' ? '搜索全书关键词…' : 'Search all chapters…';
}
}
// ---- Color mode (dark default / light optional) ----
@@ -68,13 +117,20 @@
var saved = null;
try { saved = localStorage.getItem('wto.site.mode'); } catch (e) { /* noop */ }
var mode = saved === 'light' || saved === 'dark' ? saved : 'dark';
root.setAttribute('data-mode', mode);
setMode(mode);
function setMode(m) {
root.setAttribute('data-mode', m);
document.querySelectorAll('[data-mode-toggle]').forEach(function (btn) {
btn.innerHTML = m === 'dark' ? SUN_SVG : MOON_SVG;
});
}
document.addEventListener('click', function (e) {
var btn = e.target.closest('[data-mode-toggle]');
if (!btn) return;
var next = root.getAttribute('data-mode') === 'dark' ? 'light' : 'dark';
root.setAttribute('data-mode', next);
setMode(next);
try { localStorage.setItem('wto.site.mode', next); } catch (err) { /* noop */ }
});
})();
@@ -128,7 +184,6 @@
img.src = slides[index];
}
// Activate initial slide on next frame so Ken Burns scale eases in
requestAnimationFrame(function () {
nodes[0].classList.add('active');
});
@@ -189,53 +244,260 @@
window.addEventListener('scroll', update, { passive: true });
})();
// ---- Resolve extensionless routes cleanly when previewed via file:// ----
function resolveInternalHref(href) {
if (location.protocol !== 'file:') return href;
var m = /^\/(|releases|dev-docs|mod-docs)(#.*)?$/.exec(href);
if (!m) return href;
var page = m[1] ? m[1] + '.html' : 'index.html';
return page + (m[2] || '');
}
// ---- Smooth internal page navigation ----
(function initLeaveTransition() {
if (reduce) return;
if (document.startViewTransition) return;
document.addEventListener('click', function (e) {
var a = e.target.closest('a');
if (!a) return;
if (!a || a.hasAttribute('data-chapter') || a.hasAttribute('data-doc-jump')) return;
var href = a.getAttribute('href') || '';
if (a.target === '_blank' || a.hasAttribute('download')) return;
if (!href || href.charAt(0) === '#' || /^(https?:)?\/\//.test(href)) return;
if (e.metaKey || e.ctrlKey || e.shiftKey || e.button !== 0) return;
var resolved = resolveInternalHref(href);
if (reduce || (document.startViewTransition && location.protocol !== 'file:')) {
if (resolved !== href) {
e.preventDefault();
location.href = resolved;
}
return;
}
e.preventDefault();
document.body.classList.add('leaving');
setTimeout(function () { location.href = href; }, 260);
setTimeout(function () { location.href = resolved; }, 240);
});
})();
// ---- Documentation TOC active section highlight & code copy ----
(function initDocHelpers() {
var tocLinks = document.querySelectorAll('.doc-toc a[href^="#"]');
if (tocLinks.length && 'IntersectionObserver' in window) {
var sections = [];
tocLinks.forEach(function (link) {
var target = document.querySelector(link.getAttribute('href'));
if (target) sections.push({ el: target, link: link });
// ---- Multi-chapter documentation reader, sub-TOC, search & expand-all ----
(function initDocReader() {
var chapters = Array.prototype.slice.call(document.querySelectorAll('.doc-chapter'));
var chapterLinks = Array.prototype.slice.call(document.querySelectorAll('.doc-toc a[data-chapter]'));
if (chapters.length && chapterLinks.length) {
var activeChapterId = chapters[0].id;
var subTocEl = document.createElement('div');
subTocEl.className = 'doc-subtoc';
function rebuildSubToc() {
if (subTocEl.parentNode) subTocEl.parentNode.removeChild(subTocEl);
subTocEl.innerHTML = '';
if (document.body.classList.contains('doc-expand-all')) return;
var activeChap = document.getElementById(activeChapterId);
var activeLink = chapterLinks.filter(function (a) {
return a.getAttribute('data-chapter') === activeChapterId;
})[0];
if (!activeChap || !activeLink) return;
var lang = document.body.getAttribute('data-lang') || 'zh';
var scope = activeChap.querySelector('.lang-' + lang) || activeChap;
var headings = scope.querySelectorAll('h3[id]');
if (!headings.length) return;
headings.forEach(function (h) {
var sub = document.createElement('a');
sub.href = '#' + h.id;
sub.setAttribute('data-doc-jump', h.id);
sub.textContent = h.textContent || '';
subTocEl.appendChild(sub);
});
activeLink.insertAdjacentElement('afterend', subTocEl);
}
function findChapterContaining(targetId) {
if (!targetId) return null;
var direct = chapters.filter(function (c) { return c.id === targetId; })[0];
if (direct) return { chapter: direct, anchor: null };
var el = document.getElementById(targetId);
if (!el) return null;
var parentChap = el.closest('.doc-chapter');
return parentChap ? { chapter: parentChap, anchor: el } : null;
}
function activateTarget(rawId, scrollBehavior, historyMode) {
var resolved = findChapterContaining(rawId) || { chapter: chapters[0], anchor: null };
activeChapterId = resolved.chapter.id;
chapters.forEach(function (c) {
c.classList.toggle('active', c.id === activeChapterId);
});
chapterLinks.forEach(function (a) {
var on = a.getAttribute('data-chapter') === activeChapterId;
a.classList.toggle('active', on);
a.setAttribute('aria-current', on ? 'page' : 'false');
});
rebuildSubToc();
var hashVal = resolved.anchor ? '#' + resolved.anchor.id : '#' + activeChapterId;
if (historyMode === 'push' && history.pushState && location.hash !== hashVal) {
history.pushState(null, '', hashVal);
} else if (historyMode === 'replace' && history.replaceState) {
history.replaceState(null, '', hashVal);
}
if (scrollBehavior) {
requestAnimationFrame(function () {
if (resolved.anchor) {
resolved.anchor.scrollIntoView({ behavior: reduce ? 'auto' : 'smooth', block: 'start' });
} else {
var layout = document.querySelector('.doc-layout');
if (layout) {
var top = layout.getBoundingClientRect().top + window.scrollY - 76;
window.scrollTo({ top: Math.max(0, top), behavior: reduce ? 'auto' : 'smooth' });
}
}
});
}
}
var initialHash = decodeURIComponent((location.hash || '').replace(/^#/, ''));
activateTarget(initialHash || chapters[0].id, Boolean(initialHash && initialHash !== chapters[0].id), 'none');
document.addEventListener('click', function (e) {
var chapBtn = e.target.closest('[data-chapter]');
if (chapBtn) {
e.preventDefault();
var cid = chapBtn.getAttribute('data-chapter');
if (cid) activateTarget(cid, true, 'push');
return;
}
var jumpBtn = e.target.closest('[data-doc-jump]');
if (jumpBtn) {
e.preventDefault();
var jid = jumpBtn.getAttribute('data-doc-jump');
var resultsBox = document.querySelector('.doc-search-results');
if (resultsBox) resultsBox.classList.remove('open');
if (jid) activateTarget(jid, true, 'push');
return;
}
// Intercept internal #anchor links inside doc body
var inDocLink = e.target.closest('.doc-body a[href^="#"]');
if (inDocLink) {
var hid = decodeURIComponent((inDocLink.getAttribute('href') || '').slice(1));
if (hid && findChapterContaining(hid)) {
e.preventDefault();
activateTarget(hid, true, 'push');
}
return;
}
var expandBtn = e.target.closest('[data-expand-all]');
if (expandBtn) {
var expanded = document.body.classList.toggle('doc-expand-all');
expandBtn.classList.toggle('active', expanded);
expandBtn.setAttribute('aria-pressed', expanded ? 'true' : 'false');
rebuildSubToc();
}
});
if (sections.length) {
sections[0].link.classList.add('active');
var io = new IntersectionObserver(function (entries) {
entries.forEach(function (entry) {
if (!entry.isIntersecting) return;
sections.forEach(function (s) {
s.link.classList.toggle('active', s.el === entry.target);
window.addEventListener('popstate', function () {
var h = decodeURIComponent((location.hash || '').replace(/^#/, ''));
activateTarget(h || chapters[0].id, true, 'none');
});
// Full-book instant search
var searchInput = document.querySelector('[data-doc-search]');
var resultsBox = document.querySelector('.doc-search-results');
function runSearch() {
if (!searchInput || !resultsBox) return;
var q = (searchInput.value || '').trim().toLowerCase();
if (!q) {
resultsBox.classList.remove('open');
resultsBox.innerHTML = '';
return;
}
var lang = document.body.getAttribute('data-lang') || 'zh';
var hits = [];
chapters.forEach(function (chap) {
var linkEl = chapterLinks.filter(function (a) { return a.getAttribute('data-chapter') === chap.id; })[0];
var chapTitle = linkEl ? (linkEl.querySelector('.lang-' + lang) || linkEl).textContent : chap.id;
var scope = chap.querySelector('.lang-' + lang) || chap;
var blocks = scope.querySelectorAll('h2, h3, h4, h5, p, li, td, pre');
var lastHeadingId = chap.id;
var lastHeadingTitle = chapTitle;
blocks.forEach(function (node) {
if (/^H[2-5]$/.test(node.tagName)) {
if (node.id) lastHeadingId = node.id;
lastHeadingTitle = node.textContent || chapTitle;
}
if (hits.length >= 12) return;
var txt = (node.textContent || '').replace(/\s+/g, ' ').trim();
var pos = txt.toLowerCase().indexOf(q);
if (pos === -1) return;
// Deduplicate consecutive hits pointing to the same target anchor
if (hits.length && hits[hits.length - 1].targetId === lastHeadingId) return;
var start = Math.max(0, pos - 24);
var snip = (start > 0 ? '…' : '') + txt.slice(start, pos + q.length + 46) + (pos + q.length + 46 < txt.length ? '…' : '');
hits.push({
targetId: lastHeadingId,
chapTitle: chapTitle,
secTitle: lastHeadingTitle,
snippet: snip
});
});
}, { rootMargin: '-18% 0px -68% 0px' });
sections.forEach(function (s) { io.observe(s.el); });
});
if (!hits.length) {
resultsBox.innerHTML = '<div class="doc-search-empty">' +
(lang === 'zh' ? '未找到匹配内容' : 'No matching sections found') +
'</div>';
} else {
resultsBox.innerHTML = hits.map(function (h) {
return '<a class="doc-search-item" href="#' + esc(h.targetId) + '" data-doc-jump="' + esc(h.targetId) + '">' +
'<span class="doc-search-item-chap">' + esc(h.chapTitle) + '</span>' +
'<span class="doc-search-item-head">' + esc(h.secTitle) + '</span>' +
'<span class="doc-search-item-snip">' + esc(h.snippet) + '</span>' +
'</a>';
}).join('');
}
resultsBox.classList.add('open');
}
if (searchInput && resultsBox) {
searchInput.addEventListener('input', runSearch);
searchInput.addEventListener('focus', function () {
if ((searchInput.value || '').trim()) runSearch();
});
document.addEventListener('click', function (e) {
if (!e.target.closest('.doc-search')) {
resultsBox.classList.remove('open');
}
});
}
docRefreshHook = function () {
applyLang(currentLang);
rebuildSubToc();
if (searchInput && (searchInput.value || '').trim()) runSearch();
};
}
// Code block copy button
document.addEventListener('click', function (e) {
var btn = e.target.closest('[data-copy-code]');
if (!btn || !navigator.clipboard) return;
if (!btn) return;
var box = btn.closest('.doc-pre');
var codeEl = box && box.querySelector('pre code');
if (!codeEl) return;
navigator.clipboard.writeText(codeEl.textContent || '').then(function () {
var lang = document.body.getAttribute('data-lang') || 'zh';
var scoped = codeEl.querySelector('.lang-' + lang);
var text = (scoped || codeEl).textContent || '';
copyText(text).then(function () {
btn.innerHTML = '<span class="lang-zh">已复制</span><span class="lang-en">Copied</span>';
setTimeout(function () {
btn.innerHTML = '<span class="lang-zh">复制</span><span class="lang-en">Copy</span>';
@@ -606,9 +868,9 @@
}
var copyBtn = e.target.closest('[data-copy]');
if (copyBtn && navigator.clipboard) {
if (copyBtn) {
var val = copyBtn.getAttribute('data-copy') || '';
navigator.clipboard.writeText(val).then(function () {
copyText(val).then(function () {
copyBtn.innerHTML = '<span class="lang-zh">已复制</span><span class="lang-en">Copied</span>';
setTimeout(function () {
copyBtn.innerHTML = '<span class="lang-zh">复制</span><span class="lang-en">Copy</span>';
+23 -21
View File
@@ -1,5 +1,5 @@
/* ============================================================
* WTOffline Homepage Design Tokens
* WTOffline Homepage & Documentation Design Tokens
* Aligned with the launcher ordnance palette: dark slate base,
* signal crimson primary actions, subtle tactical cyan glow.
* Supports dark (default) and light modes via [data-mode].
@@ -25,24 +25,25 @@
/* Corner radii */
--r-xs: 4px;
--r-sm: 6px;
--r-md: 10px;
--r-lg: 14px;
--r-md: 10px;
/* Dark ordnance palette (default) */
--page: #0b0f11;
--canvas: radial-gradient(circle at 18% 0%, #172026 0%, #0b0f11 58%);
--surface: rgba(20, 27, 31, 0.72);
--card: rgba(22, 29, 34, 0.84);
--elev: rgba(18, 24, 28, 0.90);
--glass-2: rgba(255, 255, 255, 0.035);
--surface: rgba(20, 27, 31, 0.78);
--card: rgba(22, 29, 34, 0.86);
--doc-card: rgba(16, 22, 26, 0.94);
--elev: rgba(18, 24, 28, 0.92);
--glass-2: rgba(255, 255, 255, 0.045);
--border: rgba(255, 255, 255, 0.09);
--border-2: rgba(255, 255, 255, 0.20);
--border: rgba(255, 255, 255, 0.10);
--border-2: rgba(255, 255, 255, 0.22);
--grid-line: rgba(207, 216, 220, 0.09);
--text: #e8eef1;
--text-dim: rgba(207, 216, 220, 0.72);
--text-faint: rgba(207, 216, 220, 0.46);
--text: #edf2f5;
--text-dim: rgba(224, 232, 236, 0.84);
--text-faint: rgba(207, 216, 220, 0.66);
--accent: #e53935;
--accent-hover: #f04a46;
@@ -60,23 +61,24 @@
--page: #eef2f5;
--canvas: radial-gradient(circle at 18% 0%, #ffffff 0%, #e7edf2 62%);
--surface: rgba(255, 255, 255, 0.76);
--card: rgba(255, 255, 255, 0.88);
--elev: rgba(255, 255, 255, 0.94);
--glass-2: rgba(19, 25, 27, 0.035);
--surface: rgba(255, 255, 255, 0.82);
--card: rgba(255, 255, 255, 0.90);
--doc-card: rgba(255, 255, 255, 0.96);
--elev: rgba(255, 255, 255, 0.95);
--glass-2: rgba(19, 25, 27, 0.045);
--border: rgba(19, 25, 27, 0.10);
--border-2: rgba(19, 25, 27, 0.22);
--border: rgba(19, 25, 27, 0.11);
--border-2: rgba(19, 25, 27, 0.24);
--grid-line: rgba(19, 25, 27, 0.08);
--text: #161d21;
--text-dim: rgba(22, 29, 33, 0.70);
--text-faint: rgba(22, 29, 33, 0.48);
--text: #141b1f;
--text-dim: rgba(20, 27, 31, 0.80);
--text-faint: rgba(20, 27, 31, 0.62);
--accent: #d32f2f;
--accent-hover: #b71c1c;
--accent-soft: rgba(211, 47, 47, 0.12);
--accent-2: #0097a7;
--accent-2: #00838f;
--ok: #2e7d32;
--shadow-sm: 0 6px 20px rgba(19, 25, 27, 0.07);