-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
182 lines (156 loc) · 5.68 KB
/
Copy pathmain.js
File metadata and controls
182 lines (156 loc) · 5.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/* =========================================================
OPENCODE — main.js
Handles: scroll animations, terminal typing, copy buttons
========================================================= */
// ── 1. NAV: add scrolled class on scroll ──────────────────
const nav = document.getElementById('nav');
window.addEventListener('scroll', () => {
nav.classList.toggle('scrolled', window.scrollY > 40);
}, { passive: true });
// ── 2. REVEAL on scroll (IntersectionObserver) ────────────
const revealEls = document.querySelectorAll('.reveal');
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
},
{ threshold: 0.1, rootMargin: '0px 0px -40px 0px' }
);
revealEls.forEach((el) => observer.observe(el));
// ── 3. TERMINAL TYPING ANIMATION ─────────────────────────
const typedCmd = document.getElementById('typed-cmd');
const cursor = document.getElementById('cursor');
const terminalOutput = document.getElementById('terminal-output');
const CMD = 'opencode agent -p "List all files"';
const OUTPUT_LINES = [
{ text: '⟳ Initializing agent loop...', cls: 'out-label', delay: 200 },
{ text: '→ Tool call: list_files(".")', cls: 'out-label', delay: 500 },
{ text: '✓ Found 12 files in workspace', cls: 'out-success', delay: 900 },
{ text: '→ Tool call: read_file("package.json")', cls: 'out-label', delay: 1300 },
{ text: '✓ Agent response ready', cls: 'out-success', delay: 1700 },
{ text: ' The workspace contains a Node.js CLI project...', cls: 'out-value', delay: 2000 },
];
let typingStarted = false;
function typeCommand() {
if (typingStarted) return;
typingStarted = true;
let i = 0;
const interval = setInterval(() => {
typedCmd.textContent += CMD[i];
i++;
if (i >= CMD.length) {
clearInterval(interval);
cursor.style.display = 'none';
showOutputLines();
}
}, 42);
}
function showOutputLines() {
OUTPUT_LINES.forEach(({ text, cls, delay }) => {
setTimeout(() => {
const line = document.createElement('span');
line.className = `out-line ${cls}`;
line.textContent = text;
terminalOutput.appendChild(line);
// Force reflow then add visible class
requestAnimationFrame(() => {
requestAnimationFrame(() => {
line.classList.add('visible');
});
});
}, delay);
});
}
// Start typing when terminal enters viewport
const terminal = document.getElementById('terminal-window');
if (terminal) {
const termObserver = new IntersectionObserver(
(entries) => {
if (entries[0].isIntersecting) {
setTimeout(typeCommand, 600);
termObserver.disconnect();
}
},
{ threshold: 0.5 }
);
termObserver.observe(terminal);
}
// ── 4. COPY TO CLIPBOARD ─────────────────────────────────
function copyText(text, btn) {
navigator.clipboard.writeText(text).then(() => {
btn.classList.add('copied');
const copyIcon = btn.querySelector('#copy-icon');
const checkIcon = btn.querySelector('#check-icon');
if (copyIcon) copyIcon.style.display = 'none';
if (checkIcon) checkIcon.style.display = 'block';
setTimeout(() => {
btn.classList.remove('copied');
if (copyIcon) copyIcon.style.display = 'block';
if (checkIcon) checkIcon.style.display = 'none';
}, 2000);
}).catch(() => {
// Fallback for older browsers
const ta = document.createElement('textarea');
ta.value = text;
ta.style.position = 'fixed';
ta.style.opacity = '0';
document.body.appendChild(ta);
ta.focus();
ta.select();
document.execCommand('copy');
document.body.removeChild(ta);
});
}
// Hero install copy button
const copyInstallBtn = document.getElementById('copy-install-btn');
if (copyInstallBtn) {
copyInstallBtn.addEventListener('click', () => {
copyText('npm install -g @joshxdevs/opencode', copyInstallBtn);
});
}
// Small copy buttons in steps
document.querySelectorAll('.copy-btn-sm').forEach((btn) => {
btn.addEventListener('click', () => {
const text = btn.dataset.copy;
if (!text) return;
const original = btn.innerHTML;
btn.innerHTML = `<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><polyline points="20 6 9 17 4 12"/></svg>`;
btn.classList.add('copied');
setTimeout(() => {
btn.innerHTML = original;
btn.classList.remove('copied');
}, 2000);
navigator.clipboard.writeText(text).catch(() => {
const ta = document.createElement('textarea');
ta.value = text;
ta.style.cssText = 'position:fixed;opacity:0';
document.body.appendChild(ta);
ta.select();
document.execCommand('copy');
document.body.removeChild(ta);
});
});
});
// ── 5. SMOOTH ACTIVE NAV HIGHLIGHT ───────────────────────
const sections = document.querySelectorAll('section[id]');
const navLinks = document.querySelectorAll('.nav-link[href^="#"]');
const sectionObserver = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
const id = entry.target.getAttribute('id');
navLinks.forEach((link) => {
link.style.color = link.getAttribute('href') === `#${id}`
? 'var(--text)'
: '';
});
}
});
},
{ threshold: 0.4 }
);
sections.forEach((s) => sectionObserver.observe(s));