ttp-agent-sdk 2.3.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.html +1 -1
- package/dist/script.js +351 -0
- package/dist/styles.css +1123 -0
- package/package.json +1 -1
package/dist/index.html
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
<img src="https://talktopc.com/logo192.png" alt="TTP Logo" style="width: 40px; height: 40px; border-radius: 8px;">
|
|
24
24
|
<div>
|
|
25
25
|
<h1 style="margin: 0; font-size: 1.4rem;">TTP Agent SDK</h1>
|
|
26
|
-
<p class="version" style="margin: 0;">v2.3.
|
|
26
|
+
<p class="version" style="margin: 0;">v2.3.1</p>
|
|
27
27
|
</div>
|
|
28
28
|
</div>
|
|
29
29
|
</div>
|
package/dist/script.js
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
// ===== Navigation & Scroll Behavior =====
|
|
2
|
+
|
|
3
|
+
// Smooth scroll to sections
|
|
4
|
+
document.querySelectorAll('.nav-link').forEach(link => {
|
|
5
|
+
link.addEventListener('click', function(e) {
|
|
6
|
+
// Only handle internal links (hash links)
|
|
7
|
+
if (this.getAttribute('href').startsWith('#')) {
|
|
8
|
+
e.preventDefault();
|
|
9
|
+
|
|
10
|
+
// Get target section
|
|
11
|
+
const targetId = this.getAttribute('href');
|
|
12
|
+
const targetSection = document.querySelector(targetId);
|
|
13
|
+
|
|
14
|
+
if (targetSection) {
|
|
15
|
+
// Smooth scroll to section
|
|
16
|
+
targetSection.scrollIntoView({
|
|
17
|
+
behavior: 'smooth',
|
|
18
|
+
block: 'start'
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Update URL without page jump
|
|
22
|
+
history.pushState(null, null, targetId);
|
|
23
|
+
|
|
24
|
+
// Manually update active state immediately (scroll spy will take over during scroll)
|
|
25
|
+
document.querySelectorAll('.nav-link').forEach(l => l.classList.remove('active'));
|
|
26
|
+
this.classList.add('active');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Improved scroll spy - highlight active section on scroll
|
|
33
|
+
function updateActiveLink() {
|
|
34
|
+
const sections = document.querySelectorAll('.doc-section');
|
|
35
|
+
const scrollPosition = window.scrollY + 200; // Offset for better detection
|
|
36
|
+
|
|
37
|
+
let currentSection = null;
|
|
38
|
+
let minDistance = Infinity;
|
|
39
|
+
|
|
40
|
+
// Find the section closest to current scroll position
|
|
41
|
+
sections.forEach(section => {
|
|
42
|
+
const sectionTop = section.offsetTop;
|
|
43
|
+
const distance = Math.abs(scrollPosition - sectionTop);
|
|
44
|
+
|
|
45
|
+
// If this section is above or at scroll position and closer than previous
|
|
46
|
+
if (scrollPosition >= sectionTop - 100 && distance < minDistance) {
|
|
47
|
+
minDistance = distance;
|
|
48
|
+
currentSection = section;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// If we're near the top of the page, use the first section
|
|
53
|
+
if (scrollPosition < 300) {
|
|
54
|
+
currentSection = sections[0];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// If we're at the bottom of the page, use the last section
|
|
58
|
+
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight - 100) {
|
|
59
|
+
currentSection = sections[sections.length - 1];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (currentSection) {
|
|
63
|
+
const id = currentSection.getAttribute('id');
|
|
64
|
+
const correspondingLink = document.querySelector(`.nav-link[href="#${id}"]`);
|
|
65
|
+
|
|
66
|
+
if (correspondingLink && !correspondingLink.classList.contains('active')) {
|
|
67
|
+
// Remove active class from all links
|
|
68
|
+
document.querySelectorAll('.nav-link').forEach(link => {
|
|
69
|
+
link.classList.remove('active');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Add active class to corresponding link
|
|
73
|
+
correspondingLink.classList.add('active');
|
|
74
|
+
|
|
75
|
+
// Scroll the active link into view in sidebar
|
|
76
|
+
const sidebar = document.querySelector('.sidebar');
|
|
77
|
+
const linkTop = correspondingLink.offsetTop;
|
|
78
|
+
const linkHeight = correspondingLink.offsetHeight;
|
|
79
|
+
const sidebarHeight = sidebar.clientHeight;
|
|
80
|
+
const sidebarScroll = sidebar.scrollTop;
|
|
81
|
+
|
|
82
|
+
// Check if link is not fully visible
|
|
83
|
+
if (linkTop < sidebarScroll || linkTop + linkHeight > sidebarScroll + sidebarHeight) {
|
|
84
|
+
correspondingLink.scrollIntoView({
|
|
85
|
+
block: 'nearest',
|
|
86
|
+
behavior: 'smooth'
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Update URL without jumping
|
|
91
|
+
history.replaceState(null, null, `#${id}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Better throttle function with leading edge execution
|
|
97
|
+
function throttle(func, wait) {
|
|
98
|
+
let timeout = null;
|
|
99
|
+
let lastRan = null;
|
|
100
|
+
|
|
101
|
+
return function executedFunction(...args) {
|
|
102
|
+
if (!lastRan) {
|
|
103
|
+
func.apply(this, args);
|
|
104
|
+
lastRan = Date.now();
|
|
105
|
+
} else {
|
|
106
|
+
clearTimeout(timeout);
|
|
107
|
+
timeout = setTimeout(() => {
|
|
108
|
+
if ((Date.now() - lastRan) >= wait) {
|
|
109
|
+
func.apply(this, args);
|
|
110
|
+
lastRan = Date.now();
|
|
111
|
+
}
|
|
112
|
+
}, wait - (Date.now() - lastRan));
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Update active link on scroll (throttled)
|
|
118
|
+
window.addEventListener('scroll', throttle(updateActiveLink, 150));
|
|
119
|
+
|
|
120
|
+
// Initial update on load and after DOM is ready
|
|
121
|
+
window.addEventListener('load', () => {
|
|
122
|
+
setTimeout(updateActiveLink, 200);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// Also update on resize (sections might move)
|
|
126
|
+
window.addEventListener('resize', throttle(updateActiveLink, 300));
|
|
127
|
+
|
|
128
|
+
// ===== Mobile Menu Toggle =====
|
|
129
|
+
|
|
130
|
+
// Create mobile overlay
|
|
131
|
+
const mobileOverlay = document.createElement('div');
|
|
132
|
+
mobileOverlay.className = 'mobile-overlay';
|
|
133
|
+
document.body.appendChild(mobileOverlay);
|
|
134
|
+
|
|
135
|
+
// Create mobile menu button if not exists
|
|
136
|
+
if (window.innerWidth <= 768) {
|
|
137
|
+
const mobileMenuBtn = document.createElement('button');
|
|
138
|
+
mobileMenuBtn.className = 'mobile-menu-btn';
|
|
139
|
+
mobileMenuBtn.innerHTML = '☰';
|
|
140
|
+
mobileMenuBtn.setAttribute('aria-label', 'Toggle menu');
|
|
141
|
+
document.body.appendChild(mobileMenuBtn);
|
|
142
|
+
|
|
143
|
+
const sidebar = document.querySelector('.sidebar');
|
|
144
|
+
|
|
145
|
+
function toggleMobileMenu(open) {
|
|
146
|
+
if (open) {
|
|
147
|
+
sidebar.classList.add('open');
|
|
148
|
+
mobileOverlay.classList.add('active');
|
|
149
|
+
mobileMenuBtn.classList.add('menu-open');
|
|
150
|
+
mobileMenuBtn.innerHTML = '✕';
|
|
151
|
+
document.body.style.overflow = 'hidden'; // Prevent scrolling
|
|
152
|
+
} else {
|
|
153
|
+
sidebar.classList.remove('open');
|
|
154
|
+
mobileOverlay.classList.remove('active');
|
|
155
|
+
mobileMenuBtn.classList.remove('menu-open');
|
|
156
|
+
mobileMenuBtn.innerHTML = '☰';
|
|
157
|
+
document.body.style.overflow = ''; // Restore scrolling
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
mobileMenuBtn.addEventListener('click', () => {
|
|
162
|
+
toggleMobileMenu(!sidebar.classList.contains('open'));
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// Close sidebar when clicking on overlay
|
|
166
|
+
mobileOverlay.addEventListener('click', () => {
|
|
167
|
+
toggleMobileMenu(false);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// Close sidebar when clicking on a link
|
|
171
|
+
document.querySelectorAll('.nav-link').forEach(link => {
|
|
172
|
+
link.addEventListener('click', () => {
|
|
173
|
+
if (window.innerWidth <= 768) {
|
|
174
|
+
toggleMobileMenu(false);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// ===== Handle Initial Hash on Page Load =====
|
|
181
|
+
window.addEventListener('DOMContentLoaded', () => {
|
|
182
|
+
// Run scroll spy on initial load
|
|
183
|
+
setTimeout(updateActiveLink, 100);
|
|
184
|
+
|
|
185
|
+
if (window.location.hash) {
|
|
186
|
+
const targetId = window.location.hash;
|
|
187
|
+
const targetSection = document.querySelector(targetId);
|
|
188
|
+
const targetLink = document.querySelector(`.nav-link[href="${targetId}"]`);
|
|
189
|
+
|
|
190
|
+
if (targetSection && targetLink) {
|
|
191
|
+
// Remove active from all
|
|
192
|
+
document.querySelectorAll('.nav-link').forEach(l => l.classList.remove('active'));
|
|
193
|
+
|
|
194
|
+
// Add active to target
|
|
195
|
+
targetLink.classList.add('active');
|
|
196
|
+
|
|
197
|
+
// Scroll to section after a small delay
|
|
198
|
+
setTimeout(() => {
|
|
199
|
+
targetSection.scrollIntoView({
|
|
200
|
+
behavior: 'smooth',
|
|
201
|
+
block: 'start'
|
|
202
|
+
});
|
|
203
|
+
// Update scroll spy after scrolling
|
|
204
|
+
setTimeout(updateActiveLink, 500);
|
|
205
|
+
}, 100);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
// ===== Copy Code Button =====
|
|
211
|
+
document.querySelectorAll('pre code').forEach(block => {
|
|
212
|
+
// Create wrapper
|
|
213
|
+
const wrapper = document.createElement('div');
|
|
214
|
+
wrapper.style.position = 'relative';
|
|
215
|
+
|
|
216
|
+
// Wrap the pre element
|
|
217
|
+
block.parentElement.parentNode.insertBefore(wrapper, block.parentElement);
|
|
218
|
+
wrapper.appendChild(block.parentElement);
|
|
219
|
+
|
|
220
|
+
// Create copy button
|
|
221
|
+
const copyBtn = document.createElement('button');
|
|
222
|
+
copyBtn.innerHTML = '📋 Copy';
|
|
223
|
+
copyBtn.className = 'copy-code-btn';
|
|
224
|
+
copyBtn.style.cssText = `
|
|
225
|
+
position: absolute;
|
|
226
|
+
top: 10px;
|
|
227
|
+
right: 10px;
|
|
228
|
+
background: rgba(255, 255, 255, 0.1);
|
|
229
|
+
border: 1px solid rgba(255, 255, 255, 0.2);
|
|
230
|
+
color: white;
|
|
231
|
+
padding: 6px 12px;
|
|
232
|
+
border-radius: 4px;
|
|
233
|
+
font-size: 0.875rem;
|
|
234
|
+
cursor: pointer;
|
|
235
|
+
transition: all 0.2s ease;
|
|
236
|
+
`;
|
|
237
|
+
|
|
238
|
+
copyBtn.addEventListener('mouseenter', () => {
|
|
239
|
+
copyBtn.style.background = 'rgba(255, 255, 255, 0.2)';
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
copyBtn.addEventListener('mouseleave', () => {
|
|
243
|
+
copyBtn.style.background = 'rgba(255, 255, 255, 0.1)';
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
copyBtn.addEventListener('click', async () => {
|
|
247
|
+
try {
|
|
248
|
+
await navigator.clipboard.writeText(block.textContent);
|
|
249
|
+
copyBtn.innerHTML = '✓ Copied!';
|
|
250
|
+
copyBtn.style.background = '#10b981';
|
|
251
|
+
|
|
252
|
+
setTimeout(() => {
|
|
253
|
+
copyBtn.innerHTML = '📋 Copy';
|
|
254
|
+
copyBtn.style.background = 'rgba(255, 255, 255, 0.1)';
|
|
255
|
+
}, 2000);
|
|
256
|
+
} catch (err) {
|
|
257
|
+
console.error('Failed to copy:', err);
|
|
258
|
+
copyBtn.innerHTML = '✗ Failed';
|
|
259
|
+
setTimeout(() => {
|
|
260
|
+
copyBtn.innerHTML = '📋 Copy';
|
|
261
|
+
}, 2000);
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
wrapper.appendChild(copyBtn);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
// ===== Search Functionality (Optional Enhancement) =====
|
|
269
|
+
// Keyboard shortcut for quick navigation
|
|
270
|
+
document.addEventListener('keydown', (e) => {
|
|
271
|
+
// Press '/' to focus search (if search is added later)
|
|
272
|
+
if (e.key === '/' && !['INPUT', 'TEXTAREA'].includes(e.target.tagName)) {
|
|
273
|
+
e.preventDefault();
|
|
274
|
+
// Search functionality can be added here
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// Press 'Escape' to close mobile menu
|
|
278
|
+
if (e.key === 'Escape' && window.innerWidth <= 768) {
|
|
279
|
+
const sidebar = document.querySelector('.sidebar');
|
|
280
|
+
const mobileMenuBtn = document.querySelector('.mobile-menu-btn');
|
|
281
|
+
const overlay = document.querySelector('.mobile-overlay');
|
|
282
|
+
if (sidebar && sidebar.classList.contains('open')) {
|
|
283
|
+
sidebar.classList.remove('open');
|
|
284
|
+
overlay.classList.remove('active');
|
|
285
|
+
document.body.style.overflow = '';
|
|
286
|
+
if (mobileMenuBtn) {
|
|
287
|
+
mobileMenuBtn.classList.remove('menu-open');
|
|
288
|
+
mobileMenuBtn.innerHTML = '☰';
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
// ===== Scroll to Top Button =====
|
|
295
|
+
const scrollToTopBtn = document.createElement('button');
|
|
296
|
+
scrollToTopBtn.innerHTML = '↑';
|
|
297
|
+
scrollToTopBtn.className = 'scroll-to-top';
|
|
298
|
+
scrollToTopBtn.style.cssText = `
|
|
299
|
+
position: fixed;
|
|
300
|
+
bottom: 30px;
|
|
301
|
+
right: 30px;
|
|
302
|
+
background: linear-gradient(135deg, #667eea 0%, #5a67d8 100%);
|
|
303
|
+
color: white;
|
|
304
|
+
border: none;
|
|
305
|
+
width: 50px;
|
|
306
|
+
height: 50px;
|
|
307
|
+
border-radius: 50%;
|
|
308
|
+
font-size: 1.5rem;
|
|
309
|
+
cursor: pointer;
|
|
310
|
+
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
|
|
311
|
+
opacity: 0;
|
|
312
|
+
visibility: hidden;
|
|
313
|
+
transition: all 0.3s ease;
|
|
314
|
+
z-index: 1000;
|
|
315
|
+
`;
|
|
316
|
+
|
|
317
|
+
document.body.appendChild(scrollToTopBtn);
|
|
318
|
+
|
|
319
|
+
// Show/hide scroll to top button
|
|
320
|
+
window.addEventListener('scroll', () => {
|
|
321
|
+
if (window.pageYOffset > 300) {
|
|
322
|
+
scrollToTopBtn.style.opacity = '1';
|
|
323
|
+
scrollToTopBtn.style.visibility = 'visible';
|
|
324
|
+
} else {
|
|
325
|
+
scrollToTopBtn.style.opacity = '0';
|
|
326
|
+
scrollToTopBtn.style.visibility = 'hidden';
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
scrollToTopBtn.addEventListener('click', () => {
|
|
331
|
+
window.scrollTo({
|
|
332
|
+
top: 0,
|
|
333
|
+
behavior: 'smooth'
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
scrollToTopBtn.addEventListener('mouseenter', () => {
|
|
338
|
+
scrollToTopBtn.style.transform = 'scale(1.1)';
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
scrollToTopBtn.addEventListener('mouseleave', () => {
|
|
342
|
+
scrollToTopBtn.style.transform = 'scale(1)';
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
// ===== Table of Contents Generation (for long sections) =====
|
|
346
|
+
// Automatically generate in-page ToC if needed
|
|
347
|
+
// This is optional and can be enabled per section
|
|
348
|
+
|
|
349
|
+
console.log('📚 TTP Agent SDK Documentation Loaded');
|
|
350
|
+
console.log('🎯 Navigate using the sidebar or scroll to explore');
|
|
351
|
+
|