gabriel / musehub public
domain-detail.ts typescript
142 lines 5.4 KB
Raw
sha256:f04ce422239f0885c3f048bc171dd7ec1a99b7ba2126e5e51facb10920c1d440 feat: build the real symbol_graph/piano_roll viewer palette… Sonnet 4.6 minor ⚠ breaking 19 days ago
1 /**
2 * domain-detail.ts — Domain plugin detail page interactivity.
3 *
4 * Handles:
5 * - Copy-to-clipboard for terminal blocks and hash cells
6 * - Entrance animations for dimension cards (IntersectionObserver)
7 * - Install button feedback
8 * - Live viewer preview (musehub#117 DOM_09/DOM_10/DOM_11) — renders the
9 * domain's actual palette viewer (symbol_graph/piano_roll/generic) from
10 * its declared dimensions, not a static icon.
11 */
12
13 import { renderDomainViewer, type DimensionSpec } from '../domain-viewers.ts';
14
15 export interface DomainDetailData {
16 domainSlug?: string;
17 domainId?: string;
18 viewerType?: string;
19 dimensions?: DimensionSpec[];
20 [key: string]: unknown;
21 }
22
23 // ── Copy to clipboard ─────────────────────────────────────────────────────────
24
25 function setupCopyButtons(): void {
26 document.querySelectorAll<HTMLButtonElement>('[data-copy-id]').forEach(btn => {
27 btn.addEventListener('click', async () => {
28 const targetId = btn.dataset.copyId;
29 if (!targetId) return;
30 const el = document.getElementById(targetId);
31 if (!el) return;
32 const text = el.textContent?.trim() ?? '';
33 try {
34 await navigator.clipboard.writeText(text);
35 const prev = btn.textContent;
36 btn.textContent = '✓ Copied';
37 btn.classList.add('copied');
38 setTimeout(() => {
39 btn.textContent = prev;
40 btn.classList.remove('copied');
41 }, 2000);
42 } catch {
43 // fallback: select text
44 const range = document.createRange();
45 range.selectNode(el);
46 window.getSelection()?.removeAllRanges();
47 window.getSelection()?.addRange(range);
48 }
49 });
50 });
51 }
52
53 // ── Dimension card entrance animation ─────────────────────────────────────────
54
55 function setupDimAnimations(): void {
56 const grid = document.querySelector<HTMLElement>('.dd-dim-grid');
57 if (!grid) return;
58
59 const cards = Array.from(grid.querySelectorAll<HTMLElement>('.dd-dim-card'));
60 cards.forEach(card => {
61 card.style.opacity = '0';
62 card.style.transform = 'translateY(12px)';
63 });
64
65 const observer = new IntersectionObserver(entries => {
66 if (!entries.some(e => e.isIntersecting)) return;
67 observer.disconnect();
68 cards.forEach((card, i) => {
69 setTimeout(() => {
70 card.style.transition = 'opacity 0.35s ease, transform 0.35s ease';
71 card.style.opacity = '1';
72 card.style.transform = 'none';
73 }, i * 30);
74 });
75 }, { threshold: 0.1 });
76
77 observer.observe(grid);
78 }
79
80 // ── Stat pill count-up animation ──────────────────────────────────────────────
81
82 function setupStatCountUp(): void {
83 const pills = document.querySelectorAll<HTMLElement>('.dd-stat-pill__value');
84 pills.forEach(el => {
85 const raw = el.textContent?.trim() ?? '';
86 const num = parseInt(raw, 10);
87 if (isNaN(num) || num <= 1) return;
88 el.textContent = '0';
89 const duration = 600;
90 const start = performance.now();
91 const tick = (now: number) => {
92 const t = Math.min((now - start) / duration, 1);
93 const ease = 1 - Math.pow(1 - t, 3);
94 el.textContent = String(Math.round(ease * num));
95 if (t < 1) requestAnimationFrame(tick);
96 };
97 requestAnimationFrame(tick);
98 });
99 }
100
101 // ── Install button ─────────────────────────────────────────────────────────────
102
103 function setupInstallButton(): void {
104 const btn = document.getElementById('dd-install-btn');
105 if (!btn) return;
106 btn.addEventListener('click', () => {
107 // Show a "copied" instruction since Muse CLI install is a terminal command
108 const installEl = document.getElementById('install-cmd');
109 if (!installEl) return;
110 const text = installEl.textContent?.trim() ?? '';
111 navigator.clipboard.writeText(text).then(() => {
112 const prev = btn.textContent;
113 btn.textContent = '✓ Command Copied — paste in terminal';
114 btn.setAttribute('disabled', '');
115 setTimeout(() => {
116 btn.textContent = prev ?? '↓ Install Domain';
117 btn.removeAttribute('disabled');
118 }, 3000);
119 }).catch(() => {
120 btn.textContent = 'Open terminal and run: muse domain install';
121 setTimeout(() => { btn.textContent = '↓ Install Domain'; }, 4000);
122 });
123 });
124 }
125
126 // ── Live viewer preview ─────────────────────────────────────────────────────────
127
128 function setupViewerPreview(data: DomainDetailData): void {
129 const container = document.getElementById('dd-viewer-preview');
130 if (!container) return;
131 renderDomainViewer(container, data.viewerType ?? 'generic', data.dimensions ?? []);
132 }
133
134 // ── Entry point ───────────────────────────────────────────────────────────────
135
136 export function initDomainDetail(data: DomainDetailData): void {
137 setupCopyButtons();
138 setupDimAnimations();
139 setupStatCountUp();
140 setupInstallButton();
141 setupViewerPreview(data);
142 }
File History 1 commit
sha256:f04ce422239f0885c3f048bc171dd7ec1a99b7ba2126e5e51facb10920c1d440 feat: build the real symbol_graph/piano_roll viewer palette… Sonnet 4.6 minor 19 days ago