index.html 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Animal.js Documentation</title>
  7. <style>
  8. :root {
  9. --sidebar-bg: #111;
  10. --main-bg: #111;
  11. --border-color: #222;
  12. --text-color: #888;
  13. --text-hover: #ccc;
  14. --active-color: #ff4b4b; /* Red/Orange for active item */
  15. --header-color: #666;
  16. --middle-col-bg: #161616;
  17. --tree-line-color: #333;
  18. --accent-color: #ff9f43;
  19. }
  20. body {
  21. margin: 0;
  22. padding: 0;
  23. height: 100vh;
  24. display: flex;
  25. background: var(--main-bg);
  26. color: var(--text-color);
  27. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  28. overflow: hidden;
  29. font-size: 14px;
  30. }
  31. /* 1. LEFT SIDEBAR - MAIN NAVIGATION */
  32. .sidebar-left {
  33. width: 260px;
  34. background: var(--sidebar-bg);
  35. display: flex;
  36. flex-direction: column;
  37. overflow-y: auto;
  38. flex-shrink: 0;
  39. padding-bottom: 40px;
  40. }
  41. .logo-area {
  42. padding: 24px 20px;
  43. font-size: 18px;
  44. font-weight: bold;
  45. color: #fff;
  46. display: flex;
  47. align-items: center;
  48. gap: 10px;
  49. margin-bottom: 10px;
  50. }
  51. .logo-circle {
  52. width: 10px;
  53. height: 10px;
  54. background: #fff;
  55. border-radius: 50%;
  56. }
  57. /* Tree Structure */
  58. .nav-tree {
  59. padding: 0 20px;
  60. }
  61. .tree-group {
  62. margin-bottom: 5px;
  63. }
  64. .tree-header {
  65. padding: 8px 0;
  66. color: var(--header-color);
  67. font-weight: 600;
  68. cursor: pointer;
  69. transition: color 0.2s;
  70. display: flex;
  71. align-items: center;
  72. justify-content: space-between;
  73. }
  74. .tree-header:hover {
  75. color: var(--text-hover);
  76. }
  77. .tree-header.active-header {
  78. color: #e69f3c; /* Highlight parent if needed, usually just children */
  79. }
  80. .tree-children {
  81. padding-left: 14px; /* Indent */
  82. border-left: 1px solid var(--tree-line-color);
  83. margin-left: 2px;
  84. display: none; /* Collapsed by default */
  85. flex-direction: column;
  86. }
  87. .tree-children.expanded {
  88. display: flex;
  89. }
  90. .nav-item {
  91. display: block;
  92. padding: 6px 0 6px 15px;
  93. color: var(--text-color);
  94. text-decoration: none;
  95. cursor: pointer;
  96. transition: all 0.2s;
  97. position: relative;
  98. }
  99. .nav-item:hover {
  100. color: var(--text-hover);
  101. }
  102. /* Active Item Style (Reference: Red text, maybe red border left overlaying the gray line?) */
  103. .nav-item.active {
  104. color: var(--active-color);
  105. }
  106. /* Optional: Active marker on the left line */
  107. .nav-item.active::before {
  108. content: '';
  109. position: absolute;
  110. left: -1px; /* Overlap the border */
  111. top: 0;
  112. bottom: 0;
  113. width: 2px;
  114. background: var(--active-color);
  115. }
  116. /* Flat menu section title */
  117. .nav-section-title {
  118. margin-top: 18px;
  119. padding: 10px 0 6px 0;
  120. color: #7a7a7a;
  121. font-size: 11px;
  122. font-weight: 800;
  123. letter-spacing: 1px;
  124. text-transform: uppercase;
  125. opacity: 0.9;
  126. }
  127. /* Search Box in sidebar */
  128. .sidebar-search {
  129. margin: 0 20px 20px 20px;
  130. background: #1a1a1a;
  131. border: 1px solid #333;
  132. border-radius: 4px;
  133. padding: 8px 12px;
  134. color: #fff;
  135. font-size: 13px;
  136. cursor: pointer;
  137. }
  138. .sidebar-search:hover {
  139. border-color: #555;
  140. }
  141. /* 2. MIDDLE SIDEBAR */
  142. .sidebar-middle {
  143. width: 320px;
  144. background: var(--middle-col-bg);
  145. display: flex;
  146. flex-direction: column;
  147. overflow: hidden;
  148. flex-shrink: 0;
  149. }
  150. #middle-frame {
  151. width: 100%;
  152. height: 100%;
  153. border: none;
  154. background: transparent;
  155. }
  156. /* 3. RIGHT CONTENT */
  157. .content-right {
  158. flex: 1;
  159. display: flex;
  160. flex-direction: column;
  161. background: #000;
  162. overflow: hidden;
  163. }
  164. #content-frame {
  165. flex: 1;
  166. border: none;
  167. width: 100%;
  168. height: 100%;
  169. }
  170. /* Connection line between middle and right columns */
  171. .column-connection-line {
  172. position: fixed;
  173. inset: 0;
  174. width: 100vw;
  175. height: 100vh;
  176. pointer-events: none;
  177. z-index: 20;
  178. opacity: 0.85;
  179. }
  180. .column-connection-path {
  181. stroke: var(--accent-color);
  182. stroke-width: 2;
  183. stroke-dasharray: 6 6;
  184. stroke-linecap: round;
  185. fill: none;
  186. opacity: 0.35;
  187. animation: dashFlow 1.1s linear infinite;
  188. filter: drop-shadow(0 0 2px rgba(255, 159, 67, 0.25));
  189. }
  190. @keyframes dashFlow {
  191. to { stroke-dashoffset: -12; }
  192. }
  193. </style>
  194. </head>
  195. <body>
  196. <!-- 1. Left Sidebar -->
  197. <div class="sidebar-left">
  198. <div class="logo-area">
  199. <div class="logo-circle"></div>
  200. Animal.js
  201. </div>
  202. <div class="sidebar-search" onclick="selectCategory('search.html', 'test_on_update.html', null)">
  203. Search
  204. </div>
  205. <div class="nav-tree" aria-label="主菜单(扁平化)">
  206. <div class="nav-section-title">Animal.js 动画</div>
  207. <div class="nav-item active" onclick="selectCategory('targets/list.html', 'targets/overview.html', this)">目标 Targets</div>
  208. <div class="nav-item" onclick="selectCategory('animatable_properties/list.html', 'animatable_properties/test_transforms.html', this)">可动画属性 Properties</div>
  209. <div class="nav-item" onclick="selectCategory('tween_value_types/list.html', 'tween_value_types/test_numerical.html', this)">补间值类型 Tween 值</div>
  210. <div class="nav-item" onclick="selectCategory('tween_parameters/list.html', 'tween_parameters/overview.html', this)">补间参数 Tween 参数</div>
  211. <div class="nav-item" onclick="selectCategory('svg/list.html', 'svg/overview.html', this)">SVG 动画</div>
  212. <div class="nav-item" onclick="selectCategory('list_callbacks.html', 'test_on_update.html', this)">回调 Callbacks</div>
  213. <div class="nav-item" onclick="selectCategory('examples/list.html', 'examples/controls.html', this)">示例 Examples</div>
  214. <div class="nav-section-title">Layer 弹窗</div>
  215. <div class="nav-item" onclick="selectCategory('examples/list.html', 'examples/layer.html', this)">交互示例(Layer + 动画)</div>
  216. <div class="nav-section-title">开发者</div>
  217. <div class="nav-item" onclick="selectCategory('search.html', 'module.html', this)">模块开发与测试指南</div>
  218. </div>
  219. </div>
  220. <!-- 2. Middle Sidebar -->
  221. <div class="sidebar-middle">
  222. <iframe id="middle-frame" src="targets/list.html"></iframe>
  223. </div>
  224. <!-- 3. Right Content -->
  225. <div class="content-right">
  226. <iframe id="content-frame" src="targets/test_css_selector.html"></iframe>
  227. </div>
  228. <!-- SVG overlay for the middle→right connection line -->
  229. <svg id="column-connection-line" class="column-connection-line" aria-hidden="true">
  230. <path id="column-connection-path" class="column-connection-path" d=""></path>
  231. </svg>
  232. <script>
  233. function selectCategory(listUrl, defaultContentUrl, el) {
  234. // 1. Highlight Nav Item
  235. document.querySelectorAll('.nav-item').forEach(item => item.classList.remove('active'));
  236. if (el) el.classList.add('active');
  237. // 2. Load Middle Column (List)
  238. const middleFrame = document.getElementById('middle-frame');
  239. if (middleFrame.getAttribute('src') !== listUrl) {
  240. middleFrame.src = listUrl;
  241. }
  242. // 3. Load Right Column (Default Content)
  243. loadContent(defaultContentUrl);
  244. }
  245. function loadContent(url) {
  246. const contentFrame = document.getElementById('content-frame');
  247. if (contentFrame.getAttribute('src') !== url) {
  248. contentFrame.src = url;
  249. }
  250. // Keep middle list selection in sync when possible
  251. try {
  252. setMiddleActive(url);
  253. } catch {}
  254. // Update connection line after navigation
  255. scheduleConnectionLineUpdate();
  256. }
  257. // Called by content iframe pages (and also internally after navigation)
  258. function setMiddleActive(contentUrl) {
  259. const middleFrame = document.getElementById('middle-frame');
  260. if (!middleFrame) return;
  261. const win = middleFrame.contentWindow;
  262. if (win && typeof win.setActiveByContentUrl === 'function') {
  263. win.setActiveByContentUrl(contentUrl);
  264. }
  265. // Update connection line when active item changes
  266. scheduleConnectionLineUpdate();
  267. }
  268. // =========================================================
  269. // Global Prev/Next(组内顺序 + 跨组跳转,由路由表统一驱动)
  270. // =========================================================
  271. const DOC_PAGES = [
  272. // Targets
  273. { group: 'Targets', title: 'Targets 概览', url: 'targets/overview.html' },
  274. { group: 'Targets', title: 'CSS Selector', url: 'targets/test_css_selector.html' },
  275. { group: 'Targets', title: 'DOM Elements', url: 'targets/test_dom_elements.html' },
  276. { group: 'Targets', title: 'JavaScript Objects', url: 'targets/test_js_objects.html' },
  277. { group: 'Targets', title: 'Array of targets', url: 'targets/test_array_targets.html' },
  278. // Animatable properties
  279. { group: 'Properties', title: 'Transforms', url: 'animatable_properties/test_transforms.html' },
  280. { group: 'Properties', title: 'CSS Properties', url: 'animatable_properties/test_css_props.html' },
  281. { group: 'Properties', title: 'CSS Variables', url: 'animatable_properties/test_css_vars.html' },
  282. { group: 'Properties', title: 'JS Properties', url: 'animatable_properties/test_js_props.html' },
  283. // Tween value types
  284. { group: 'Tween 值', title: 'Numerical', url: 'tween_value_types/test_numerical.html' },
  285. { group: 'Tween 值', title: 'Unit', url: 'tween_value_types/test_unit.html' },
  286. { group: 'Tween 值', title: 'Relative', url: 'tween_value_types/test_relative.html' },
  287. { group: 'Tween 值', title: 'Colors', url: 'tween_value_types/test_colors.html' },
  288. // Tween parameters
  289. { group: 'Tween 参数', title: 'Tween parameters 概览', url: 'tween_parameters/overview.html' },
  290. { group: 'Tween 参数', title: 'duration / delay', url: 'tween_parameters/test_duration_delay.html' },
  291. // SVG
  292. { group: 'SVG', title: 'SVG 概览', url: 'svg/overview.html' },
  293. { group: 'SVG', title: 'draw() 路径描边', url: 'svg/test_draw_path.html' },
  294. { group: 'SVG', title: 'Motion Path', url: 'svg/test_motion_path.html' },
  295. { group: 'SVG', title: 'SVG 属性动画', url: 'svg/test_svg_attributes.html' },
  296. { group: 'SVG', title: 'SVG transform', url: 'svg/test_svg_transforms.html' },
  297. // Callbacks
  298. { group: 'Callbacks', title: 'onUpdate', url: 'test_on_update.html' },
  299. // Examples
  300. { group: 'Examples', title: 'Controls', url: 'examples/controls.html' },
  301. { group: 'Examples', title: 'Layer', url: 'examples/layer.html' },
  302. // Developer
  303. { group: 'Developer', title: '模块开发与测试指南', url: 'module.html' }
  304. ];
  305. function normalizeDocUrl(url) {
  306. return String(url || '')
  307. .replace(/^[#/]+/, '')
  308. .replace(/^\.\//, '')
  309. .replace(/^\/+/, '');
  310. }
  311. function docFindIndex(currentUrl) {
  312. const u = normalizeDocUrl(currentUrl);
  313. if (!u) return -1;
  314. return DOC_PAGES.findIndex(p => u === p.url || u.endsWith(p.url));
  315. }
  316. function docGetPrevNext(currentUrl) {
  317. const idx = docFindIndex(currentUrl);
  318. if (idx < 0) return { idx: -1, prev: null, next: null, current: null };
  319. const prev = (idx > 0) ? DOC_PAGES[idx - 1] : null;
  320. const next = (idx < DOC_PAGES.length - 1) ? DOC_PAGES[idx + 1] : null;
  321. return { idx, prev, next, current: DOC_PAGES[idx] };
  322. }
  323. function docNavigatePrev(currentUrl) {
  324. const { prev } = docGetPrevNext(currentUrl);
  325. if (prev) loadContent(prev.url);
  326. }
  327. function docNavigateNext(currentUrl) {
  328. const { next } = docGetPrevNext(currentUrl);
  329. if (next) loadContent(next.url);
  330. }
  331. // Expose to iframes (same origin)
  332. window.docGetPrevNext = docGetPrevNext;
  333. window.docNavigatePrev = docNavigatePrev;
  334. window.docNavigateNext = docNavigateNext;
  335. // =============================
  336. // Middle ↔ Right connection line
  337. // =============================
  338. const connectionSvg = document.getElementById('column-connection-line');
  339. const connectionPath = document.getElementById('column-connection-path');
  340. let _connRaf = 0;
  341. function scheduleConnectionLineUpdate() {
  342. if (_connRaf) return;
  343. _connRaf = requestAnimationFrame(() => {
  344. _connRaf = 0;
  345. updateConnectionLine();
  346. });
  347. }
  348. function getActiveElementInFrame(frameEl) {
  349. try {
  350. const doc = frameEl?.contentDocument;
  351. if (!doc) return null;
  352. // Middle list pages use .card.active / .header-card.active; fall back to .active
  353. return (
  354. doc.querySelector('.card.active') ||
  355. doc.querySelector('.header-card.active') ||
  356. doc.querySelector('.nav-item.active') ||
  357. doc.querySelector('.active')
  358. );
  359. } catch {
  360. return null;
  361. }
  362. }
  363. function getAnchorElementInContentFrame(frameEl) {
  364. try {
  365. const doc = frameEl?.contentDocument;
  366. if (!doc) return null;
  367. // Prefer a *visible* code area anchor (in-viewport), then fall back
  368. const candidates = [
  369. '.box-container .box-header',
  370. '.code-view.active, .html-view.active, .css-view.active',
  371. '.box-container',
  372. 'h1',
  373. '.container',
  374. 'body'
  375. ];
  376. for (const sel of candidates) {
  377. const el = doc.querySelector(sel);
  378. if (!el) continue;
  379. // If it's visible in the iframe viewport, use it; else keep looking
  380. const r = el.getBoundingClientRect();
  381. const vh = frameEl?.clientHeight || 0;
  382. if (!vh) return el;
  383. const visibleTop = Math.max(0, r.top);
  384. const visibleBottom = Math.min(vh, r.bottom);
  385. if (visibleBottom - visibleTop > 8) return el;
  386. }
  387. return doc.body;
  388. } catch {
  389. return null;
  390. }
  391. }
  392. function clamp(n, min, max) {
  393. return Math.min(Math.max(n, min), max);
  394. }
  395. function getVisibleCenterInFrame(frameEl, elRect) {
  396. const w = frameEl?.clientWidth || 0;
  397. const h = frameEl?.clientHeight || 0;
  398. if (!w || !h) return null;
  399. const visibleLeft = Math.max(0, elRect.left);
  400. const visibleRight = Math.min(w, elRect.right);
  401. const visibleTop = Math.max(0, elRect.top);
  402. const visibleBottom = Math.min(h, elRect.bottom);
  403. if (visibleRight - visibleLeft <= 1 || visibleBottom - visibleTop <= 1) {
  404. return null;
  405. }
  406. return {
  407. x: (visibleLeft + visibleRight) / 2,
  408. y: (visibleTop + visibleBottom) / 2
  409. };
  410. }
  411. function updateConnectionLine() {
  412. if (!connectionSvg || !connectionPath) return;
  413. const middleFrame = document.getElementById('middle-frame');
  414. const contentFrame = document.getElementById('content-frame');
  415. if (!middleFrame || !contentFrame) return;
  416. const midRect = middleFrame.getBoundingClientRect();
  417. const rightRect = contentFrame.getBoundingClientRect();
  418. const active = getActiveElementInFrame(middleFrame);
  419. const anchor = getAnchorElementInContentFrame(contentFrame);
  420. if (!active || !anchor) {
  421. connectionPath.setAttribute('d', '');
  422. connectionSvg.style.opacity = '0';
  423. return;
  424. }
  425. const activeRect = active.getBoundingClientRect();
  426. const anchorRect = anchor.getBoundingClientRect();
  427. // Use the *visible* part of the element within its iframe viewport
  428. const activeCenter = getVisibleCenterInFrame(middleFrame, activeRect);
  429. const anchorCenter = getVisibleCenterInFrame(contentFrame, anchorRect);
  430. if (!activeCenter || !anchorCenter) {
  431. // If either side isn't visible in its iframe, hide the line (prevents weird drifting)
  432. connectionPath.setAttribute('d', '');
  433. connectionSvg.style.opacity = '0';
  434. return;
  435. }
  436. // Convert iframe-viewport coordinates to parent viewport coordinates
  437. const startX = midRect.left + clamp(activeRect.right, 0, middleFrame.clientWidth);
  438. const startY = midRect.top + activeCenter.y;
  439. // Point into the code area a bit (not exactly at left edge)
  440. const endX = rightRect.left + clamp(anchorRect.left + 18, 12, contentFrame.clientWidth - 12);
  441. const endY = rightRect.top + anchorCenter.y;
  442. // Draw an L-shaped polyline.
  443. // Keep the vertical segment aligned with the column divider (middle ↔ right).
  444. const dividerX = rightRect.left + 0.5; // half-pixel for crisper stroke alignment
  445. const x1 = Math.max(startX + 12, dividerX);
  446. const d = [
  447. `M ${startX} ${startY}`,
  448. `L ${x1} ${startY}`,
  449. `L ${x1} ${endY}`,
  450. `L ${endX} ${endY}`
  451. ].join(' ');
  452. connectionPath.setAttribute('d', d);
  453. connectionSvg.style.opacity = '0.85';
  454. }
  455. function attachFrameScrollListeners(frameEl) {
  456. if (!frameEl) return;
  457. const onScroll = () => {
  458. markFrameScrolling(frameEl);
  459. scheduleConnectionLineUpdate();
  460. };
  461. try {
  462. // Window scroll inside iframe
  463. frameEl.contentWindow?.addEventListener('scroll', onScroll, { passive: true });
  464. // Some pages scroll on document/body; capture to be safe
  465. frameEl.contentDocument?.addEventListener('scroll', onScroll, true);
  466. frameEl.contentDocument?.documentElement?.addEventListener?.('scroll', onScroll, { passive: true });
  467. frameEl.contentDocument?.body?.addEventListener?.('scroll', onScroll, { passive: true });
  468. } catch {}
  469. }
  470. const _scrollHideTimers = new WeakMap();
  471. function markFrameScrolling(frameEl) {
  472. try {
  473. const doc = frameEl?.contentDocument;
  474. if (!doc) return;
  475. doc.documentElement?.classList.add('scrolling');
  476. doc.body?.classList.add('scrolling');
  477. const prev = _scrollHideTimers.get(frameEl);
  478. if (prev) clearTimeout(prev);
  479. _scrollHideTimers.set(frameEl, setTimeout(() => {
  480. try {
  481. doc.documentElement?.classList.remove('scrolling');
  482. doc.body?.classList.remove('scrolling');
  483. } catch {}
  484. }, 500));
  485. } catch {}
  486. }
  487. // Always-on lightweight loop to keep the line aligned even
  488. // if iframe scroll events were missed due to timing.
  489. let _connLoopStarted = false;
  490. function startConnectionLineLoop() {
  491. if (_connLoopStarted) return;
  492. _connLoopStarted = true;
  493. const loop = () => {
  494. // Only bother when we have a path (avoids work when hidden)
  495. if (connectionPath?.getAttribute('d')) {
  496. scheduleConnectionLineUpdate();
  497. }
  498. requestAnimationFrame(loop);
  499. };
  500. requestAnimationFrame(loop);
  501. }
  502. // Make initial active state robust against iframe load ordering
  503. window.addEventListener('load', () => {
  504. const contentFrame = document.getElementById('content-frame');
  505. const src = contentFrame?.getAttribute('src');
  506. if (src) setMiddleActive(src);
  507. const middleFrame = document.getElementById('middle-frame');
  508. if (middleFrame) {
  509. middleFrame.addEventListener('load', () => {
  510. const current = document.getElementById('content-frame')?.getAttribute('src');
  511. if (current) setMiddleActive(current);
  512. attachFrameScrollListeners(middleFrame);
  513. scheduleConnectionLineUpdate();
  514. });
  515. }
  516. if (contentFrame) {
  517. contentFrame.addEventListener('load', () => {
  518. const current = contentFrame.getAttribute('src');
  519. if (current) setMiddleActive(current);
  520. attachFrameScrollListeners(contentFrame);
  521. scheduleConnectionLineUpdate();
  522. });
  523. }
  524. // If the iframes were already loaded before we attached 'load' listeners,
  525. // still attach scroll listeners immediately.
  526. attachFrameScrollListeners(middleFrame);
  527. attachFrameScrollListeners(contentFrame);
  528. window.addEventListener('resize', scheduleConnectionLineUpdate, { passive: true });
  529. scheduleConnectionLineUpdate();
  530. startConnectionLineLoop();
  531. });
  532. </script>
  533. </body>
  534. </html>