index.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  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. /* Search Box in sidebar */
  117. .sidebar-search {
  118. margin: 0 20px 20px 20px;
  119. background: #1a1a1a;
  120. border: 1px solid #333;
  121. border-radius: 4px;
  122. padding: 8px 12px;
  123. color: #fff;
  124. font-size: 13px;
  125. cursor: pointer;
  126. }
  127. .sidebar-search:hover {
  128. border-color: #555;
  129. }
  130. /* 2. MIDDLE SIDEBAR */
  131. .sidebar-middle {
  132. width: 320px;
  133. background: var(--middle-col-bg);
  134. display: flex;
  135. flex-direction: column;
  136. overflow: hidden;
  137. flex-shrink: 0;
  138. }
  139. #middle-frame {
  140. width: 100%;
  141. height: 100%;
  142. border: none;
  143. background: transparent;
  144. }
  145. /* 3. RIGHT CONTENT */
  146. .content-right {
  147. flex: 1;
  148. display: flex;
  149. flex-direction: column;
  150. background: #000;
  151. overflow: hidden;
  152. }
  153. #content-frame {
  154. flex: 1;
  155. border: none;
  156. width: 100%;
  157. height: 100%;
  158. }
  159. /* Connection line between middle and right columns */
  160. .column-connection-line {
  161. position: fixed;
  162. inset: 0;
  163. width: 100vw;
  164. height: 100vh;
  165. pointer-events: none;
  166. z-index: 20;
  167. opacity: 0.85;
  168. }
  169. .column-connection-path {
  170. stroke: var(--accent-color);
  171. stroke-width: 2;
  172. stroke-dasharray: 6 6;
  173. stroke-linecap: round;
  174. fill: none;
  175. opacity: 0.35;
  176. animation: dashFlow 1.1s linear infinite;
  177. filter: drop-shadow(0 0 2px rgba(255, 159, 67, 0.25));
  178. }
  179. @keyframes dashFlow {
  180. to { stroke-dashoffset: -12; }
  181. }
  182. </style>
  183. </head>
  184. <body>
  185. <!-- 1. Left Sidebar -->
  186. <div class="sidebar-left">
  187. <div class="logo-area">
  188. <div class="logo-circle"></div>
  189. Animal.js
  190. </div>
  191. <div class="sidebar-search" onclick="selectCategory('search.html', 'test_on_update.html', null)">
  192. Search
  193. </div>
  194. <div class="nav-tree">
  195. <!-- Group: Getting Started -->
  196. <div class="tree-group">
  197. <div class="tree-header" onclick="toggleTree(this)">Getting started</div>
  198. <div class="tree-children">
  199. <div class="nav-item" onclick="selectCategory('search.html', 'test_css_selector.html', this)">Installation</div>
  200. <div class="nav-item" onclick="selectCategory('search.html', 'test_css_selector.html', this)">Module imports</div>
  201. </div>
  202. </div>
  203. <!-- Group: Timer -->
  204. <div class="tree-group">
  205. <div class="tree-header" onclick="toggleTree(this)">Timer</div>
  206. <div class="tree-children">
  207. <div class="nav-item">Settings</div>
  208. </div>
  209. </div>
  210. <!-- Group: Animation -->
  211. <div class="tree-group">
  212. <div class="tree-header active-header" onclick="toggleTree(this)">Animation</div>
  213. <div class="tree-children expanded">
  214. <div class="nav-item active" onclick="selectCategory('targets/list.html', 'targets/overview.html', this)">Targets</div>
  215. <div class="nav-item" onclick="selectCategory('animatable_properties/list.html', 'animatable_properties/test_css_props.html', this)">Animatable properties</div>
  216. <div class="nav-item" onclick="selectCategory('tween_value_types/list.html', 'tween_value_types/test_numerical.html', this)">Tween value types</div>
  217. <div class="nav-item">Tween parameters</div>
  218. <div class="nav-item">Keyframes</div>
  219. <div class="nav-item">Playback settings</div>
  220. <!-- Callbacks Nested? Or separate? Reference shows Callbacks under Animation -->
  221. <div class="nav-item" onclick="selectCategory('list_callbacks.html', 'test_on_update.html', this)">Callbacks</div>
  222. <!-- Examples -->
  223. <div class="nav-item" onclick="selectCategory('examples/list.html', 'examples/controls.html', this)">Examples</div>
  224. <div class="nav-item">Methods</div>
  225. <div class="nav-item">Properties</div>
  226. </div>
  227. </div>
  228. <!-- Group: Timeline -->
  229. <div class="tree-group">
  230. <div class="tree-header" onclick="toggleTree(this)">Timeline</div>
  231. <div class="tree-children">
  232. <div class="nav-item">Basics</div>
  233. </div>
  234. </div>
  235. <!-- Group: Animatable -->
  236. <div class="tree-group">
  237. <div class="tree-header" onclick="toggleTree(this)">Animatable</div>
  238. <div class="tree-children">
  239. <div class="nav-item">Properties</div>
  240. </div>
  241. </div>
  242. </div>
  243. </div>
  244. <!-- 2. Middle Sidebar -->
  245. <div class="sidebar-middle">
  246. <iframe id="middle-frame" src="targets/list.html"></iframe>
  247. </div>
  248. <!-- 3. Right Content -->
  249. <div class="content-right">
  250. <iframe id="content-frame" src="targets/test_css_selector.html"></iframe>
  251. </div>
  252. <!-- SVG overlay for the middle→right connection line -->
  253. <svg id="column-connection-line" class="column-connection-line" aria-hidden="true">
  254. <path id="column-connection-path" class="column-connection-path" d=""></path>
  255. </svg>
  256. <script>
  257. function toggleTree(header) {
  258. const children = header.nextElementSibling;
  259. if (children) {
  260. children.classList.toggle('expanded');
  261. // Optional: Highlight header when expanded?
  262. // header.classList.toggle('active-header');
  263. }
  264. }
  265. function selectCategory(listUrl, defaultContentUrl, el) {
  266. // 1. Highlight Nav Item
  267. document.querySelectorAll('.nav-item').forEach(item => item.classList.remove('active'));
  268. if (el) el.classList.add('active');
  269. // 2. Load Middle Column (List)
  270. const middleFrame = document.getElementById('middle-frame');
  271. if (middleFrame.getAttribute('src') !== listUrl) {
  272. middleFrame.src = listUrl;
  273. }
  274. // 3. Load Right Column (Default Content)
  275. loadContent(defaultContentUrl);
  276. }
  277. function loadContent(url) {
  278. const contentFrame = document.getElementById('content-frame');
  279. if (contentFrame.getAttribute('src') !== url) {
  280. contentFrame.src = url;
  281. }
  282. // Keep middle list selection in sync when possible
  283. try {
  284. setMiddleActive(url);
  285. } catch {}
  286. // Update connection line after navigation
  287. scheduleConnectionLineUpdate();
  288. }
  289. // Called by content iframe pages (and also internally after navigation)
  290. function setMiddleActive(contentUrl) {
  291. const middleFrame = document.getElementById('middle-frame');
  292. if (!middleFrame) return;
  293. const win = middleFrame.contentWindow;
  294. if (win && typeof win.setActiveByContentUrl === 'function') {
  295. win.setActiveByContentUrl(contentUrl);
  296. }
  297. // Update connection line when active item changes
  298. scheduleConnectionLineUpdate();
  299. }
  300. // =============================
  301. // Middle ↔ Right connection line
  302. // =============================
  303. const connectionSvg = document.getElementById('column-connection-line');
  304. const connectionPath = document.getElementById('column-connection-path');
  305. let _connRaf = 0;
  306. function scheduleConnectionLineUpdate() {
  307. if (_connRaf) return;
  308. _connRaf = requestAnimationFrame(() => {
  309. _connRaf = 0;
  310. updateConnectionLine();
  311. });
  312. }
  313. function getActiveElementInFrame(frameEl) {
  314. try {
  315. const doc = frameEl?.contentDocument;
  316. if (!doc) return null;
  317. // Middle list pages use .card.active / .header-card.active; fall back to .active
  318. return (
  319. doc.querySelector('.card.active') ||
  320. doc.querySelector('.header-card.active') ||
  321. doc.querySelector('.nav-item.active') ||
  322. doc.querySelector('.active')
  323. );
  324. } catch {
  325. return null;
  326. }
  327. }
  328. function getAnchorElementInContentFrame(frameEl) {
  329. try {
  330. const doc = frameEl?.contentDocument;
  331. if (!doc) return null;
  332. // Prefer a *visible* code area anchor (in-viewport), then fall back
  333. const candidates = [
  334. '.box-container .box-header',
  335. '.code-view.active, .html-view.active, .css-view.active',
  336. '.box-container',
  337. 'h1',
  338. '.container',
  339. 'body'
  340. ];
  341. for (const sel of candidates) {
  342. const el = doc.querySelector(sel);
  343. if (!el) continue;
  344. // If it's visible in the iframe viewport, use it; else keep looking
  345. const r = el.getBoundingClientRect();
  346. const vh = frameEl?.clientHeight || 0;
  347. if (!vh) return el;
  348. const visibleTop = Math.max(0, r.top);
  349. const visibleBottom = Math.min(vh, r.bottom);
  350. if (visibleBottom - visibleTop > 8) return el;
  351. }
  352. return doc.body;
  353. } catch {
  354. return null;
  355. }
  356. }
  357. function clamp(n, min, max) {
  358. return Math.min(Math.max(n, min), max);
  359. }
  360. function getVisibleCenterInFrame(frameEl, elRect) {
  361. const w = frameEl?.clientWidth || 0;
  362. const h = frameEl?.clientHeight || 0;
  363. if (!w || !h) return null;
  364. const visibleLeft = Math.max(0, elRect.left);
  365. const visibleRight = Math.min(w, elRect.right);
  366. const visibleTop = Math.max(0, elRect.top);
  367. const visibleBottom = Math.min(h, elRect.bottom);
  368. if (visibleRight - visibleLeft <= 1 || visibleBottom - visibleTop <= 1) {
  369. return null;
  370. }
  371. return {
  372. x: (visibleLeft + visibleRight) / 2,
  373. y: (visibleTop + visibleBottom) / 2
  374. };
  375. }
  376. function updateConnectionLine() {
  377. if (!connectionSvg || !connectionPath) return;
  378. const middleFrame = document.getElementById('middle-frame');
  379. const contentFrame = document.getElementById('content-frame');
  380. if (!middleFrame || !contentFrame) return;
  381. const midRect = middleFrame.getBoundingClientRect();
  382. const rightRect = contentFrame.getBoundingClientRect();
  383. const active = getActiveElementInFrame(middleFrame);
  384. const anchor = getAnchorElementInContentFrame(contentFrame);
  385. if (!active || !anchor) {
  386. connectionPath.setAttribute('d', '');
  387. connectionSvg.style.opacity = '0';
  388. return;
  389. }
  390. const activeRect = active.getBoundingClientRect();
  391. const anchorRect = anchor.getBoundingClientRect();
  392. // Use the *visible* part of the element within its iframe viewport
  393. const activeCenter = getVisibleCenterInFrame(middleFrame, activeRect);
  394. const anchorCenter = getVisibleCenterInFrame(contentFrame, anchorRect);
  395. if (!activeCenter || !anchorCenter) {
  396. // If either side isn't visible in its iframe, hide the line (prevents weird drifting)
  397. connectionPath.setAttribute('d', '');
  398. connectionSvg.style.opacity = '0';
  399. return;
  400. }
  401. // Convert iframe-viewport coordinates to parent viewport coordinates
  402. const startX = midRect.left + clamp(activeRect.right, 0, middleFrame.clientWidth);
  403. const startY = midRect.top + activeCenter.y;
  404. // Point into the code area a bit (not exactly at left edge)
  405. const endX = rightRect.left + clamp(anchorRect.left + 18, 12, contentFrame.clientWidth - 12);
  406. const endY = rightRect.top + anchorCenter.y;
  407. // Draw an L-shaped polyline.
  408. // Keep the vertical segment aligned with the column divider (middle ↔ right).
  409. const dividerX = rightRect.left + 0.5; // half-pixel for crisper stroke alignment
  410. const x1 = Math.max(startX + 12, dividerX);
  411. const d = [
  412. `M ${startX} ${startY}`,
  413. `L ${x1} ${startY}`,
  414. `L ${x1} ${endY}`,
  415. `L ${endX} ${endY}`
  416. ].join(' ');
  417. connectionPath.setAttribute('d', d);
  418. connectionSvg.style.opacity = '0.85';
  419. }
  420. function attachFrameScrollListeners(frameEl) {
  421. if (!frameEl) return;
  422. const onScroll = () => {
  423. markFrameScrolling(frameEl);
  424. scheduleConnectionLineUpdate();
  425. };
  426. try {
  427. // Window scroll inside iframe
  428. frameEl.contentWindow?.addEventListener('scroll', onScroll, { passive: true });
  429. // Some pages scroll on document/body; capture to be safe
  430. frameEl.contentDocument?.addEventListener('scroll', onScroll, true);
  431. frameEl.contentDocument?.documentElement?.addEventListener?.('scroll', onScroll, { passive: true });
  432. frameEl.contentDocument?.body?.addEventListener?.('scroll', onScroll, { passive: true });
  433. } catch {}
  434. }
  435. const _scrollHideTimers = new WeakMap();
  436. function markFrameScrolling(frameEl) {
  437. try {
  438. const doc = frameEl?.contentDocument;
  439. if (!doc) return;
  440. doc.documentElement?.classList.add('scrolling');
  441. doc.body?.classList.add('scrolling');
  442. const prev = _scrollHideTimers.get(frameEl);
  443. if (prev) clearTimeout(prev);
  444. _scrollHideTimers.set(frameEl, setTimeout(() => {
  445. try {
  446. doc.documentElement?.classList.remove('scrolling');
  447. doc.body?.classList.remove('scrolling');
  448. } catch {}
  449. }, 500));
  450. } catch {}
  451. }
  452. // Always-on lightweight loop to keep the line aligned even
  453. // if iframe scroll events were missed due to timing.
  454. let _connLoopStarted = false;
  455. function startConnectionLineLoop() {
  456. if (_connLoopStarted) return;
  457. _connLoopStarted = true;
  458. const loop = () => {
  459. // Only bother when we have a path (avoids work when hidden)
  460. if (connectionPath?.getAttribute('d')) {
  461. scheduleConnectionLineUpdate();
  462. }
  463. requestAnimationFrame(loop);
  464. };
  465. requestAnimationFrame(loop);
  466. }
  467. // Make initial active state robust against iframe load ordering
  468. window.addEventListener('load', () => {
  469. const contentFrame = document.getElementById('content-frame');
  470. const src = contentFrame?.getAttribute('src');
  471. if (src) setMiddleActive(src);
  472. const middleFrame = document.getElementById('middle-frame');
  473. if (middleFrame) {
  474. middleFrame.addEventListener('load', () => {
  475. const current = document.getElementById('content-frame')?.getAttribute('src');
  476. if (current) setMiddleActive(current);
  477. attachFrameScrollListeners(middleFrame);
  478. scheduleConnectionLineUpdate();
  479. });
  480. }
  481. if (contentFrame) {
  482. contentFrame.addEventListener('load', () => {
  483. const current = contentFrame.getAttribute('src');
  484. if (current) setMiddleActive(current);
  485. attachFrameScrollListeners(contentFrame);
  486. scheduleConnectionLineUpdate();
  487. });
  488. }
  489. // If the iframes were already loaded before we attached 'load' listeners,
  490. // still attach scroll listeners immediately.
  491. attachFrameScrollListeners(middleFrame);
  492. attachFrameScrollListeners(contentFrame);
  493. window.addEventListener('resize', scheduleConnectionLineUpdate, { passive: true });
  494. scheduleConnectionLineUpdate();
  495. startConnectionLineLoop();
  496. });
  497. </script>
  498. </body>
  499. </html>