index.html 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  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. // Bump this when you want to force-refresh iframe pages
  234. const DOC_CACHE_VERSION = '2';
  235. function selectCategory(listUrl, defaultContentUrl, el) {
  236. // 1. Highlight Nav Item
  237. document.querySelectorAll('.nav-item').forEach(item => item.classList.remove('active'));
  238. if (el) el.classList.add('active');
  239. // 2. Load Middle Column (List)
  240. const middleFrame = document.getElementById('middle-frame');
  241. const listUrlV = withDocVersion(listUrl);
  242. if (middleFrame.getAttribute('src') !== listUrlV) {
  243. middleFrame.src = listUrlV;
  244. }
  245. // 3. Load Right Column (Default Content)
  246. loadContent(defaultContentUrl);
  247. }
  248. function withDocVersion(url) {
  249. const u = String(url || '');
  250. if (!u) return u;
  251. // keep explicit query params if present
  252. if (u.includes('?')) return u;
  253. return u + '?v=' + encodeURIComponent(DOC_CACHE_VERSION);
  254. }
  255. function loadContent(url) {
  256. const contentFrame = document.getElementById('content-frame');
  257. const urlV = withDocVersion(url);
  258. if (contentFrame.getAttribute('src') !== urlV) {
  259. contentFrame.src = urlV;
  260. }
  261. // Keep middle list selection in sync when possible
  262. try {
  263. setMiddleActive(url);
  264. } catch {}
  265. // Update connection line after navigation
  266. scheduleConnectionLineUpdate();
  267. }
  268. // Called by content iframe pages (and also internally after navigation)
  269. function setMiddleActive(contentUrl) {
  270. const middleFrame = document.getElementById('middle-frame');
  271. if (!middleFrame) return;
  272. const win = middleFrame.contentWindow;
  273. if (win && typeof win.setActiveByContentUrl === 'function') {
  274. win.setActiveByContentUrl(contentUrl);
  275. }
  276. // Update connection line when active item changes
  277. scheduleConnectionLineUpdate();
  278. }
  279. // =========================================================
  280. // Global Prev/Next(组内顺序 + 跨组跳转,由路由表统一驱动)
  281. // =========================================================
  282. const DOC_PAGES = [
  283. // Targets
  284. { group: 'Targets', title: 'Targets 概览', url: 'targets/overview.html' },
  285. { group: 'Targets', title: 'CSS Selector', url: 'targets/test_css_selector.html' },
  286. { group: 'Targets', title: 'DOM Elements', url: 'targets/test_dom_elements.html' },
  287. { group: 'Targets', title: 'JavaScript Objects', url: 'targets/test_js_objects.html' },
  288. { group: 'Targets', title: 'Array of targets', url: 'targets/test_array_targets.html' },
  289. // Animatable properties
  290. { group: 'Properties', title: 'Transforms', url: 'animatable_properties/test_transforms.html' },
  291. { group: 'Properties', title: 'CSS Properties', url: 'animatable_properties/test_css_props.html' },
  292. { group: 'Properties', title: 'CSS Variables', url: 'animatable_properties/test_css_vars.html' },
  293. { group: 'Properties', title: 'JS Properties', url: 'animatable_properties/test_js_props.html' },
  294. // Tween value types
  295. { group: 'Tween 值', title: 'Numerical', url: 'tween_value_types/test_numerical.html' },
  296. { group: 'Tween 值', title: 'Unit', url: 'tween_value_types/test_unit.html' },
  297. { group: 'Tween 值', title: 'Relative', url: 'tween_value_types/test_relative.html' },
  298. { group: 'Tween 值', title: 'Colors', url: 'tween_value_types/test_colors.html' },
  299. // Tween parameters
  300. { group: 'Tween 参数', title: 'Tween parameters 概览', url: 'tween_parameters/overview.html' },
  301. { group: 'Tween 参数', title: 'duration / delay', url: 'tween_parameters/test_duration_delay.html' },
  302. // SVG
  303. { group: 'SVG', title: 'SVG 概览', url: 'svg/overview.html' },
  304. { group: 'SVG', title: 'draw() 路径描边', url: 'svg/test_draw_path.html' },
  305. { group: 'SVG', title: 'Motion Path', url: 'svg/test_motion_path.html' },
  306. { group: 'SVG', title: 'SVG 属性动画', url: 'svg/test_svg_attributes.html' },
  307. { group: 'SVG', title: 'SVG transform', url: 'svg/test_svg_transforms.html' },
  308. { group: 'SVG', title: 'Morph(points)', url: 'svg/test_morph_points.html' },
  309. { group: 'SVG', title: 'Morph(path d)', url: 'svg/test_morph_path.html' },
  310. // Callbacks
  311. { group: 'Callbacks', title: 'onUpdate', url: 'test_on_update.html' },
  312. // Examples
  313. { group: 'Examples', title: 'Controls', url: 'examples/controls.html' },
  314. { group: 'Examples', title: 'Layer', url: 'examples/layer.html' },
  315. // Developer
  316. { group: 'Developer', title: '模块开发与测试指南', url: 'module.html' }
  317. ];
  318. function normalizeDocUrl(url) {
  319. const raw = String(url || '');
  320. const noHash = raw.split('#')[0];
  321. const noQuery = noHash.split('?')[0];
  322. return String(noQuery || '')
  323. .replace(/^[#/]+/, '')
  324. .replace(/^\.\//, '')
  325. .replace(/^\/+/, '');
  326. }
  327. function docFindIndex(currentUrl) {
  328. const u = normalizeDocUrl(currentUrl);
  329. if (!u) return -1;
  330. return DOC_PAGES.findIndex(p => u === p.url || u.endsWith(p.url));
  331. }
  332. function docGetPrevNext(currentUrl) {
  333. const idx = docFindIndex(currentUrl);
  334. if (idx < 0) return { idx: -1, prev: null, next: null, current: null };
  335. const prev = (idx > 0) ? DOC_PAGES[idx - 1] : null;
  336. const next = (idx < DOC_PAGES.length - 1) ? DOC_PAGES[idx + 1] : null;
  337. return { idx, prev, next, current: DOC_PAGES[idx] };
  338. }
  339. function docNavigatePrev(currentUrl) {
  340. const { prev } = docGetPrevNext(currentUrl);
  341. if (prev) loadContent(prev.url);
  342. }
  343. function docNavigateNext(currentUrl) {
  344. const { next } = docGetPrevNext(currentUrl);
  345. if (next) loadContent(next.url);
  346. }
  347. // Expose to iframes (same origin)
  348. window.docGetPrevNext = docGetPrevNext;
  349. window.docNavigatePrev = docNavigatePrev;
  350. window.docNavigateNext = docNavigateNext;
  351. // =============================
  352. // Middle ↔ Right connection line
  353. // =============================
  354. const connectionSvg = document.getElementById('column-connection-line');
  355. const connectionPath = document.getElementById('column-connection-path');
  356. let _connRaf = 0;
  357. function scheduleConnectionLineUpdate() {
  358. if (_connRaf) return;
  359. _connRaf = requestAnimationFrame(() => {
  360. _connRaf = 0;
  361. updateConnectionLine();
  362. });
  363. }
  364. function getActiveElementInFrame(frameEl) {
  365. try {
  366. const doc = frameEl?.contentDocument;
  367. if (!doc) return null;
  368. // Middle list pages use .card.active / .header-card.active; fall back to .active
  369. return (
  370. doc.querySelector('.card.active') ||
  371. doc.querySelector('.header-card.active') ||
  372. doc.querySelector('.nav-item.active') ||
  373. doc.querySelector('.active')
  374. );
  375. } catch {
  376. return null;
  377. }
  378. }
  379. function getAnchorElementInContentFrame(frameEl) {
  380. try {
  381. const doc = frameEl?.contentDocument;
  382. if (!doc) return null;
  383. // Prefer a *visible* code area anchor (in-viewport), then fall back
  384. const candidates = [
  385. '.box-container .box-header',
  386. '.code-view.active, .html-view.active, .css-view.active',
  387. '.box-container',
  388. 'h1',
  389. '.container',
  390. 'body'
  391. ];
  392. for (const sel of candidates) {
  393. const el = doc.querySelector(sel);
  394. if (!el) continue;
  395. // If it's visible in the iframe viewport, use it; else keep looking
  396. const r = el.getBoundingClientRect();
  397. const vh = frameEl?.clientHeight || 0;
  398. if (!vh) return el;
  399. const visibleTop = Math.max(0, r.top);
  400. const visibleBottom = Math.min(vh, r.bottom);
  401. if (visibleBottom - visibleTop > 8) return el;
  402. }
  403. return doc.body;
  404. } catch {
  405. return null;
  406. }
  407. }
  408. function clamp(n, min, max) {
  409. return Math.min(Math.max(n, min), max);
  410. }
  411. function getVisibleCenterInFrame(frameEl, elRect) {
  412. const w = frameEl?.clientWidth || 0;
  413. const h = frameEl?.clientHeight || 0;
  414. if (!w || !h) return null;
  415. const visibleLeft = Math.max(0, elRect.left);
  416. const visibleRight = Math.min(w, elRect.right);
  417. const visibleTop = Math.max(0, elRect.top);
  418. const visibleBottom = Math.min(h, elRect.bottom);
  419. if (visibleRight - visibleLeft <= 1 || visibleBottom - visibleTop <= 1) {
  420. return null;
  421. }
  422. return {
  423. x: (visibleLeft + visibleRight) / 2,
  424. y: (visibleTop + visibleBottom) / 2
  425. };
  426. }
  427. function updateConnectionLine() {
  428. if (!connectionSvg || !connectionPath) return;
  429. const middleFrame = document.getElementById('middle-frame');
  430. const contentFrame = document.getElementById('content-frame');
  431. if (!middleFrame || !contentFrame) return;
  432. const midRect = middleFrame.getBoundingClientRect();
  433. const rightRect = contentFrame.getBoundingClientRect();
  434. const active = getActiveElementInFrame(middleFrame);
  435. const anchor = getAnchorElementInContentFrame(contentFrame);
  436. if (!active || !anchor) {
  437. connectionPath.setAttribute('d', '');
  438. connectionSvg.style.opacity = '0';
  439. return;
  440. }
  441. const activeRect = active.getBoundingClientRect();
  442. const anchorRect = anchor.getBoundingClientRect();
  443. // Use the *visible* part of the element within its iframe viewport
  444. const activeCenter = getVisibleCenterInFrame(middleFrame, activeRect);
  445. const anchorCenter = getVisibleCenterInFrame(contentFrame, anchorRect);
  446. if (!activeCenter || !anchorCenter) {
  447. // If either side isn't visible in its iframe, hide the line (prevents weird drifting)
  448. connectionPath.setAttribute('d', '');
  449. connectionSvg.style.opacity = '0';
  450. return;
  451. }
  452. // Convert iframe-viewport coordinates to parent viewport coordinates
  453. const startX = midRect.left + clamp(activeRect.right, 0, middleFrame.clientWidth);
  454. const startY = midRect.top + activeCenter.y;
  455. // Point into the code area a bit (not exactly at left edge)
  456. const endX = rightRect.left + clamp(anchorRect.left + 18, 12, contentFrame.clientWidth - 12);
  457. const endY = rightRect.top + anchorCenter.y;
  458. // Draw an L-shaped polyline.
  459. // Keep the vertical segment aligned with the column divider (middle ↔ right).
  460. const dividerX = rightRect.left + 0.5; // half-pixel for crisper stroke alignment
  461. const x1 = Math.max(startX + 12, dividerX);
  462. const d = [
  463. `M ${startX} ${startY}`,
  464. `L ${x1} ${startY}`,
  465. `L ${x1} ${endY}`,
  466. `L ${endX} ${endY}`
  467. ].join(' ');
  468. connectionPath.setAttribute('d', d);
  469. connectionSvg.style.opacity = '0.85';
  470. }
  471. function attachFrameScrollListeners(frameEl) {
  472. if (!frameEl) return;
  473. const onScroll = () => {
  474. markFrameScrolling(frameEl);
  475. scheduleConnectionLineUpdate();
  476. };
  477. try {
  478. // Window scroll inside iframe
  479. frameEl.contentWindow?.addEventListener('scroll', onScroll, { passive: true });
  480. // Some pages scroll on document/body; capture to be safe
  481. frameEl.contentDocument?.addEventListener('scroll', onScroll, true);
  482. frameEl.contentDocument?.documentElement?.addEventListener?.('scroll', onScroll, { passive: true });
  483. frameEl.contentDocument?.body?.addEventListener?.('scroll', onScroll, { passive: true });
  484. } catch {}
  485. }
  486. const _scrollHideTimers = new WeakMap();
  487. function markFrameScrolling(frameEl) {
  488. try {
  489. const doc = frameEl?.contentDocument;
  490. if (!doc) return;
  491. doc.documentElement?.classList.add('scrolling');
  492. doc.body?.classList.add('scrolling');
  493. const prev = _scrollHideTimers.get(frameEl);
  494. if (prev) clearTimeout(prev);
  495. _scrollHideTimers.set(frameEl, setTimeout(() => {
  496. try {
  497. doc.documentElement?.classList.remove('scrolling');
  498. doc.body?.classList.remove('scrolling');
  499. } catch {}
  500. }, 500));
  501. } catch {}
  502. }
  503. // Always-on lightweight loop to keep the line aligned even
  504. // if iframe scroll events were missed due to timing.
  505. let _connLoopStarted = false;
  506. function startConnectionLineLoop() {
  507. if (_connLoopStarted) return;
  508. _connLoopStarted = true;
  509. const loop = () => {
  510. // Only bother when we have a path (avoids work when hidden)
  511. if (connectionPath?.getAttribute('d')) {
  512. scheduleConnectionLineUpdate();
  513. }
  514. requestAnimationFrame(loop);
  515. };
  516. requestAnimationFrame(loop);
  517. }
  518. // Make initial active state robust against iframe load ordering
  519. window.addEventListener('load', () => {
  520. const contentFrame = document.getElementById('content-frame');
  521. const src = contentFrame?.getAttribute('src');
  522. if (src) setMiddleActive(src);
  523. const middleFrame = document.getElementById('middle-frame');
  524. if (middleFrame) {
  525. middleFrame.addEventListener('load', () => {
  526. const current = document.getElementById('content-frame')?.getAttribute('src');
  527. if (current) setMiddleActive(current);
  528. attachFrameScrollListeners(middleFrame);
  529. scheduleConnectionLineUpdate();
  530. });
  531. }
  532. if (contentFrame) {
  533. contentFrame.addEventListener('load', () => {
  534. const current = contentFrame.getAttribute('src');
  535. if (current) setMiddleActive(current);
  536. attachFrameScrollListeners(contentFrame);
  537. scheduleConnectionLineUpdate();
  538. });
  539. }
  540. // If the iframes were already loaded before we attached 'load' listeners,
  541. // still attach scroll listeners immediately.
  542. attachFrameScrollListeners(middleFrame);
  543. attachFrameScrollListeners(contentFrame);
  544. window.addEventListener('resize', scheduleConnectionLineUpdate, { passive: true });
  545. scheduleConnectionLineUpdate();
  546. startConnectionLineLoop();
  547. });
  548. </script>
  549. </body>
  550. </html>