-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
578 lines (532 loc) · 24.8 KB
/
Copy pathscript.js
File metadata and controls
578 lines (532 loc) · 24.8 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
(function () {
'use strict';
var root = document.documentElement;
var reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)');
var darkPreference = window.matchMedia('(prefers-color-scheme: dark)');
var themeStorageKey = 'trajectory-site-theme';
var themeMode = readTheme();
var resolvedTheme = resolveTheme(themeMode);
function all(selector, scope) {
return Array.prototype.slice.call((scope || document).querySelectorAll(selector));
}
function readTheme() {
try {
var value = localStorage.getItem(themeStorageKey);
return value === 'light' || value === 'dark' || value === 'auto' ? value : 'auto';
} catch (_) {
return 'auto';
}
}
function resolveTheme(mode) {
return mode === 'auto' ? (darkPreference.matches ? 'dark' : 'light') : mode;
}
function callDemo(frame, method, argument) {
if (!frame || !frame.contentWindow) return;
try {
var controller = frame.contentWindow.__trajectoryDemoControl;
if (controller && typeof controller[method] === 'function') {
controller[method](argument);
return;
}
} catch (_) {
/* The postMessage fallback also works if a host changes the origin. */
}
var type = method === 'setTheme' ? 'trajectory-demo-theme' :
method === 'stop' ? 'trajectory-demo-pause' : 'trajectory-demo-replay';
frame.contentWindow.postMessage({ type: type, theme: argument, scene: argument }, '*');
}
function swapThemeImages(theme) {
all('img[data-theme-src-light][data-theme-src-dark]').forEach(function (image) {
var next = image.getAttribute('data-theme-src-' + theme);
if (next && image.getAttribute('src') !== next) image.setAttribute('src', next);
});
}
function updateThemedVideo(video, sourceSelector, sourceAttribute, prefix, theme, poster) {
if (!video || video.getAttribute('data-loaded-theme') === theme) return;
var wasPaused = video.paused;
var previousTime = Number.isFinite(video.currentTime) ? video.currentTime : 0;
all(sourceSelector, video).forEach(function (source) {
var extension = source.getAttribute(sourceAttribute);
source.setAttribute('src', prefix + theme + '.' + extension);
});
if (poster) video.setAttribute('poster', poster.replace('{theme}', theme));
video.setAttribute('data-loaded-theme', theme);
video.load();
video.addEventListener('loadedmetadata', function restorePlayback() {
video.removeEventListener('loadedmetadata', restorePlayback);
if (previousTime > 0 && Number.isFinite(video.duration)) {
video.currentTime = Math.min(previousTime, Math.max(0, video.duration - 0.1));
}
if (!wasPaused) video.play().catch(function () {});
});
}
function updateTourTheme(theme) {
updateThemedVideo(
document.querySelector('[data-tour-video]'),
'[data-tour-source]', 'data-tour-source',
'./assets/demo/trajectory-visualizer-tour-', theme,
'./assets/shots/views-overview-{theme}.png'
);
}
function updateCaptureVideoTheme(theme) {
updateThemedVideo(
document.querySelector('[data-capture-video]'),
'[data-capture-source]', 'data-capture-source',
'./assets/demo/api-capture-toggle-', theme
);
}
function applyTheme(mode, save) {
themeMode = mode === 'light' || mode === 'dark' ? mode : 'auto';
resolvedTheme = resolveTheme(themeMode);
root.setAttribute('data-theme', themeMode);
root.setAttribute('data-resolved-theme', resolvedTheme);
all('[data-theme-choice]').forEach(function (button) {
button.setAttribute('aria-pressed', button.getAttribute('data-theme-choice') === themeMode ? 'true' : 'false');
});
if (save) {
try { localStorage.setItem(themeStorageKey, themeMode); } catch (_) {}
}
swapThemeImages(resolvedTheme);
updateTourTheme(resolvedTheme);
updateCaptureVideoTheme(resolvedTheme);
all('[data-demo-theme-frame]').forEach(function (frame) {
if (frame.getAttribute('src')) callDemo(frame, 'setTheme', resolvedTheme);
});
}
all('[data-theme-choice]').forEach(function (button) {
button.addEventListener('click', function () {
applyTheme(button.getAttribute('data-theme-choice'), true);
});
});
function handleSystemThemeChange() {
if (themeMode === 'auto') applyTheme('auto', false);
}
if (darkPreference.addEventListener) darkPreference.addEventListener('change', handleSystemThemeChange);
else if (darkPreference.addListener) darkPreference.addListener(handleSystemThemeChange);
var siteNav = document.querySelector('[data-site-nav]');
function updateNav() {
if (siteNav) siteNav.classList.toggle('is-scrolled', window.scrollY > 8);
}
updateNav();
window.addEventListener('scroll', updateNav, { passive: true });
var year = document.querySelector('[data-year]');
if (year) year.textContent = String(new Date().getFullYear());
var finder = document.querySelector('[data-finder-demo]');
var finderMode = 'time';
var finderTimer = 0;
var finderVisible = true;
var finderCaptions = {
time: 'Find the exact session by date, time, title, or path.',
path: 'Switch to project path when the folder is the cue you remember.'
};
function setFinderMode(mode) {
finderMode = mode === 'path' ? 'path' : 'time';
all('[data-finder-mode]', finder).forEach(function (button) {
button.classList.toggle('is-active', button.getAttribute('data-finder-mode') === finderMode);
});
all('[data-finder-tree]', finder).forEach(function (tree) {
tree.classList.toggle('is-active', tree.getAttribute('data-finder-tree') === finderMode);
});
var caption = finder && finder.querySelector('[data-finder-caption]');
if (caption) caption.textContent = finderCaptions[finderMode];
}
function scheduleFinder() {
window.clearTimeout(finderTimer);
if (!finder || reducedMotion.matches || !finderVisible) return;
finderTimer = window.setTimeout(function () {
setFinderMode(finderMode === 'time' ? 'path' : 'time');
scheduleFinder();
}, 3400);
}
if (finder) {
all('[data-finder-mode]', finder).forEach(function (button) {
button.addEventListener('click', function () {
setFinderMode(button.getAttribute('data-finder-mode'));
scheduleFinder();
});
});
finder.addEventListener('mouseenter', function () { window.clearTimeout(finderTimer); });
finder.addEventListener('mouseleave', scheduleFinder);
if ('IntersectionObserver' in window) {
new IntersectionObserver(function (entries) {
finderVisible = entries[0] && entries[0].isIntersecting;
scheduleFinder();
}, { threshold: 0.12 }).observe(finder);
}
setFinderMode('time');
scheduleFinder();
}
all('.recover-mode').forEach(function (switcher) {
var buttons = all('button', switcher);
buttons.forEach(function (button) {
button.addEventListener('click', function () {
buttons.forEach(function (candidate) { candidate.classList.toggle('is-active', candidate === button); });
var demo = switcher.closest('[data-live-demo]');
var caption = demo && demo.querySelector('[data-demo-caption]');
if (caption) caption.textContent = button.textContent.trim() === 'Path'
? 'Browse by project path when you remember the repository first.'
: 'Browse by date and time when you remember when the work happened.';
});
});
});
var liveDemos = all('[data-live-demo]');
function setDemoPlaying(demo, playing, status) {
demo.classList.toggle('is-playing', playing);
var button = demo.querySelector('[data-demo-toggle]');
var badge = demo.querySelector('[data-demo-status]');
if (button) button.textContent = playing ? 'Pause' : (status === 'complete' ? 'Replay' : 'Play');
if (badge) badge.textContent = playing ? 'PLAYING' : (status === 'complete' ? 'DONE' : status === 'paused' ? 'PAUSED' : 'READY');
}
function loadDemo(demo, playWhenLoaded) {
var frame = demo.querySelector('iframe[data-demo-src]');
if (!frame) return;
var source = frame.getAttribute('data-demo-src');
if (!source) return;
if (playWhenLoaded) demo.setAttribute('data-demo-pending-play', '1');
if (!frame.getAttribute('src')) {
var url = new URL(source, window.location.href);
url.searchParams.set('theme', resolvedTheme);
url.searchParams.set('autoplay', '0');
frame.setAttribute('src', url.href);
frame.addEventListener('load', function () {
frame.setAttribute('data-demo-loaded', '1');
callDemo(frame, 'setTheme', resolvedTheme);
if (demo.getAttribute('data-demo-pending-play') === '1' && !reducedMotion.matches) {
demo.removeAttribute('data-demo-pending-play');
setDemoPlaying(demo, true);
callDemo(frame, 'start', demo.getAttribute('data-scene'));
}
});
} else if (playWhenLoaded && !reducedMotion.matches) {
demo.removeAttribute('data-demo-pending-play');
setDemoPlaying(demo, true);
callDemo(frame, 'start', demo.getAttribute('data-scene'));
}
}
liveDemos.forEach(function (demo) {
var toggle = demo.querySelector('[data-demo-toggle]');
if (toggle) toggle.addEventListener('click', function () {
var frame = demo.querySelector('iframe[data-demo-src]');
if (demo.classList.contains('is-playing')) {
if (frame && frame.getAttribute('src')) callDemo(frame, 'stop');
setDemoPlaying(demo, false, 'paused');
} else {
loadDemo(demo, true);
}
});
setDemoPlaying(demo, false, 'ready');
});
if ('IntersectionObserver' in window) {
var demoObserver = new IntersectionObserver(function (entries) {
entries.forEach(function (entry) {
var demo = entry.target;
var frame = demo.querySelector('iframe[data-demo-src]');
demo.classList.toggle('is-visible', entry.isIntersecting);
if (entry.isIntersecting) loadDemo(demo, false);
else if (frame && frame.getAttribute('src') && demo.classList.contains('is-playing')) {
callDemo(frame, 'stop');
setDemoPlaying(demo, false, 'paused');
}
});
}, { rootMargin: '220px 0px 220px', threshold: 0.08 });
liveDemos.forEach(function (demo) { demoObserver.observe(demo); });
} else {
liveDemos.forEach(function (demo) { loadDemo(demo, false); });
}
window.addEventListener('message', function (event) {
var data = event.data || {};
liveDemos.forEach(function (demo) {
var frame = demo.querySelector('iframe');
if (!frame || frame.contentWindow !== event.source) return;
if (data.type === 'trajectory-demo-caption') {
var caption = demo.querySelector('[data-demo-caption]');
if (caption && data.caption) caption.textContent = data.caption;
demo.setAttribute('data-demo-step', data.step || '');
} else if (data.type === 'trajectory-demo-ended') {
setDemoPlaying(demo, false, 'complete');
}
});
});
var tourPlayer = document.querySelector('[data-tour-player]');
var tourVideo = document.querySelector('[data-tour-video]');
var tourToggle = document.querySelector('[data-tour-toggle]');
var tourReplay = document.querySelector('[data-tour-replay]');
var tourProgress = document.querySelector('[data-tour-progress]');
var tourTime = document.querySelector('[data-tour-time]');
var tourCaption = document.querySelector('[data-tour-caption]');
var selectedTourChapter = null;
var tourSegmentEnd = null;
var tourChapters = [
{ start: 0, caption: 'Find sessions by exact time, title, or project path.' },
{ start: 7, caption: 'Open one Turn: prompt and Final Response appear first.' },
{ start: 20, caption: 'Reveal Agent process, tool input, raw JSON, and tool result.' },
{ start: 31, caption: 'Jump from the Timeline call to complete, paged API evidence.' },
{ start: 40, caption: 'Resize the Overview window, then jump through Tool Use and Phase Map.' },
{ start: 50, caption: 'Finish with your local Runtime Rank, Calendar, and habits.' }
];
function formatTime(seconds) {
var value = Math.max(0, Math.floor(seconds || 0));
return String(Math.floor(value / 60)).padStart(2, '0') + ':' + String(value % 60).padStart(2, '0');
}
function currentChapter(time) {
var index = 0;
tourChapters.forEach(function (chapter, candidate) {
if (time >= chapter.start) index = candidate;
});
return index;
}
function updateTour() {
if (!tourVideo) return;
var time = Number.isFinite(tourVideo.currentTime) ? tourVideo.currentTime : 0;
var duration = Number.isFinite(tourVideo.duration) && tourVideo.duration > 0 ? tourVideo.duration : 55;
var chapter = currentChapter(time);
if (tourSegmentEnd != null && time >= tourSegmentEnd - 0.06) {
tourVideo.pause();
tourVideo.currentTime = Math.max(0, tourSegmentEnd - 0.08);
time = tourVideo.currentTime;
chapter = selectedTourChapter == null ? currentChapter(time) : selectedTourChapter;
}
if (tourProgress) tourProgress.style.width = Math.min(100, (time / duration) * 100) + '%';
if (tourTime) tourTime.textContent = formatTime(time);
if (tourCaption) tourCaption.textContent = tourChapters[chapter].caption;
all('[data-tour-seek]').forEach(function (button, index) {
var item = button.closest('li');
if (item) item.classList.toggle('is-active', index === chapter);
});
}
function setTourPlaying(playing) {
if (tourPlayer) tourPlayer.classList.toggle('is-playing', playing);
if (tourToggle) {
tourToggle.setAttribute('aria-label', playing ? 'Pause full product tour' : 'Play full product tour');
var icon = tourToggle.querySelector('span');
if (icon) icon.textContent = playing ? 'Ⅱ' : '▶';
}
}
function playTour() {
if (!tourVideo) return;
if (tourVideo.ended) {
selectedTourChapter = null;
tourSegmentEnd = null;
tourVideo.currentTime = 0;
} else if (tourSegmentEnd != null && tourVideo.currentTime >= tourSegmentEnd - 0.12 && selectedTourChapter != null) {
tourVideo.currentTime = tourChapters[selectedTourChapter].start;
}
tourVideo.play().then(function () { setTourPlaying(true); }).catch(function () { setTourPlaying(false); });
}
function playTourChapter(index) {
if (!tourVideo || !tourChapters[index]) return;
selectedTourChapter = index;
tourSegmentEnd = tourChapters[index + 1] ? tourChapters[index + 1].start : 55;
tourVideo.currentTime = tourChapters[index].start;
updateTour();
playTour();
}
if (tourVideo) {
tourVideo.addEventListener('timeupdate', updateTour);
tourVideo.addEventListener('play', function () { setTourPlaying(true); });
tourVideo.addEventListener('pause', function () { setTourPlaying(false); });
tourVideo.addEventListener('ended', function () { setTourPlaying(false); updateTour(); });
tourVideo.addEventListener('canplay', function () {
tourVideo.hidden = false;
});
tourVideo.addEventListener('error', function () {
setTourPlaying(false);
}, true);
tourVideo.addEventListener('click', function () {
if (tourVideo.paused) playTour(); else tourVideo.pause();
});
}
if (tourToggle) tourToggle.addEventListener('click', function () {
if (!tourVideo) return;
if (tourVideo.paused) playTour(); else tourVideo.pause();
});
if (tourReplay) tourReplay.addEventListener('click', function () {
if (!tourVideo) return;
if (selectedTourChapter == null) {
tourSegmentEnd = null;
tourVideo.currentTime = 0;
playTour();
} else {
playTourChapter(selectedTourChapter);
}
});
all('[data-tour-seek]').forEach(function (button, index) {
button.addEventListener('click', function () {
playTourChapter(index);
});
});
var capturePlayer = document.querySelector('[data-capture-toggle-player]');
var captureVideo = document.querySelector('[data-capture-video]');
var captureToggle = document.querySelector('[data-capture-toggle]');
var captureReplay = document.querySelector('[data-capture-replay]');
var captureProgress = document.querySelector('[data-capture-progress]');
var captureStatus = document.querySelector('[data-capture-status]');
function setCapturePlaying(playing, status) {
if (capturePlayer) capturePlayer.classList.toggle('is-playing', playing);
if (captureToggle) {
captureToggle.setAttribute('aria-label', playing ? 'Pause API Capture toggle demo' : 'Play API Capture toggle demo');
var icon = captureToggle.querySelector('span');
if (icon) icon.textContent = playing ? 'Ⅱ' : '▶';
}
if (captureStatus) captureStatus.textContent = playing ? 'PLAYING' : (status === 'complete' ? 'DONE' : status === 'paused' ? 'PAUSED' : 'READY');
}
function playCaptureVideo(restart) {
if (!captureVideo) return;
if (restart || captureVideo.ended) captureVideo.currentTime = 0;
captureVideo.play().then(function () { setCapturePlaying(true); }).catch(function () { setCapturePlaying(false); });
}
if (captureVideo) {
captureVideo.addEventListener('timeupdate', function () {
var duration = Number.isFinite(captureVideo.duration) && captureVideo.duration > 0 ? captureVideo.duration : 1;
if (captureProgress) captureProgress.style.width = Math.min(100, captureVideo.currentTime / duration * 100) + '%';
});
captureVideo.addEventListener('play', function () { setCapturePlaying(true); });
captureVideo.addEventListener('pause', function () { if (!captureVideo.ended) setCapturePlaying(false, 'paused'); });
captureVideo.addEventListener('ended', function () { setCapturePlaying(false, 'complete'); });
captureVideo.addEventListener('click', function () {
if (captureVideo.paused) playCaptureVideo(false); else captureVideo.pause();
});
}
if (captureToggle) captureToggle.addEventListener('click', function () {
if (!captureVideo) return;
if (captureVideo.paused) playCaptureVideo(false); else captureVideo.pause();
});
if (captureReplay) captureReplay.addEventListener('click', function () { playCaptureVideo(true); });
setCapturePlaying(false);
var lightbox = document.querySelector('[data-lightbox-dialog]');
var lightboxImage = document.querySelector('[data-lightbox-image]');
var lightboxVideo = document.querySelector('[data-lightbox-video]');
var lightboxFrame = document.querySelector('[data-lightbox-frame]');
var lightboxTitle = document.getElementById('lightbox-title');
var lightboxPrevious = document.querySelector('[data-lightbox-previous]');
var lightboxNext = document.querySelector('[data-lightbox-next]');
var lightboxCount = document.querySelector('[data-lightbox-count]');
var imageTriggers = all('[data-lightbox]');
var lightboxImageIndex = -1;
var lightboxReturnFocus = null;
function showLightbox() {
if (!lightbox) return;
if (typeof lightbox.showModal === 'function' && !lightbox.open) lightbox.showModal();
else lightbox.setAttribute('open', '');
}
function setLightboxMode(mode) {
if (lightboxImage) lightboxImage.hidden = mode !== 'image';
if (lightboxVideo) lightboxVideo.hidden = mode !== 'video';
if (lightboxFrame) lightboxFrame.hidden = mode !== 'frame';
var images = mode === 'image';
if (lightboxPrevious) lightboxPrevious.hidden = !images;
if (lightboxNext) lightboxNext.hidden = !images;
if (lightboxCount) lightboxCount.hidden = !images;
}
function showLightboxImage(index) {
if (!lightbox || !lightboxImage || !imageTriggers.length) return;
lightboxImageIndex = (index + imageTriggers.length) % imageTriggers.length;
var button = imageTriggers[lightboxImageIndex];
var source = button.getAttribute('data-theme-src-' + resolvedTheme);
var nested = button.querySelector('img');
if (!source && nested) source = nested.getAttribute('src');
var label = button.getAttribute('data-lightbox-alt') || (nested && nested.getAttribute('alt')) || 'Product view';
setLightboxMode('image');
lightboxImage.setAttribute('src', source || '');
lightboxImage.setAttribute('alt', label);
if (lightboxTitle) lightboxTitle.textContent = label;
if (lightboxCount) lightboxCount.textContent = String(lightboxImageIndex + 1) + ' / ' + String(imageTriggers.length);
showLightbox();
}
function openLightboxVideo(source, label, atTime, shouldPlay) {
if (!lightbox || !lightboxVideo || !source) return;
setLightboxMode('video');
lightboxImageIndex = -1;
lightboxVideo.setAttribute('src', source);
if (lightboxTitle) lightboxTitle.textContent = label;
showLightbox();
lightboxVideo.addEventListener('loadedmetadata', function restoreTime() {
lightboxVideo.removeEventListener('loadedmetadata', restoreTime);
if (Number.isFinite(atTime)) lightboxVideo.currentTime = Math.min(atTime, Math.max(0, lightboxVideo.duration - 0.08));
if (shouldPlay) lightboxVideo.play().catch(function () {});
});
lightboxVideo.load();
}
function openLightboxFrame(demo) {
if (!lightbox || !lightboxFrame || !demo) return;
var original = demo.querySelector('iframe[data-demo-src]');
if (!original) return;
var source = original.getAttribute('data-demo-src');
var url = new URL(source, window.location.href);
url.searchParams.delete('state');
url.searchParams.set('theme', resolvedTheme);
url.searchParams.set('autoplay', '1');
setLightboxMode('frame');
lightboxImageIndex = -1;
lightboxFrame.setAttribute('src', url.href);
if (lightboxTitle) lightboxTitle.textContent = original.getAttribute('title') || 'Product demo';
showLightbox();
}
function closeLightbox() {
if (!lightbox) return;
if (lightboxVideo) {
lightboxVideo.pause();
lightboxVideo.removeAttribute('src');
lightboxVideo.load();
}
if (lightboxFrame) lightboxFrame.removeAttribute('src');
if (typeof lightbox.close === 'function' && lightbox.open) lightbox.close();
else lightbox.removeAttribute('open');
if (lightboxReturnFocus && typeof lightboxReturnFocus.focus === 'function') lightboxReturnFocus.focus({ preventScroll: true });
lightboxReturnFocus = null;
}
imageTriggers.forEach(function (button, index) {
button.addEventListener('click', function () {
lightboxReturnFocus = button;
showLightboxImage(index);
});
});
if (lightboxPrevious) lightboxPrevious.addEventListener('click', function () { showLightboxImage(lightboxImageIndex - 1); });
if (lightboxNext) lightboxNext.addEventListener('click', function () { showLightboxImage(lightboxImageIndex + 1); });
var tourExpand = document.querySelector('[data-tour-expand]');
if (tourExpand) tourExpand.addEventListener('click', function () {
lightboxReturnFocus = tourExpand;
var source = tourVideo && (tourVideo.currentSrc || (tourVideo.querySelector('source') && tourVideo.querySelector('source').src));
openLightboxVideo(source, 'Trajectory Visualizer · Full tour', tourVideo && tourVideo.currentTime, tourVideo && !tourVideo.paused);
});
var captureExpand = document.querySelector('[data-capture-expand]');
if (captureExpand) captureExpand.addEventListener('click', function () {
lightboxReturnFocus = captureExpand;
var source = captureVideo && (captureVideo.currentSrc || (captureVideo.querySelector('source') && captureVideo.querySelector('source').src));
openLightboxVideo(source, 'API Capture · Off → On', captureVideo && captureVideo.currentTime, captureVideo && !captureVideo.paused);
});
all('[data-demo-expand]').forEach(function (button) {
button.addEventListener('click', function () {
lightboxReturnFocus = button;
openLightboxFrame(button.closest('[data-live-demo]'));
});
});
var lightboxClose = document.querySelector('[data-lightbox-close]');
if (lightboxClose) lightboxClose.addEventListener('click', closeLightbox);
if (lightbox) lightbox.addEventListener('click', function (event) {
if (event.target === lightbox) closeLightbox();
});
if (lightbox) lightbox.addEventListener('cancel', function (event) { event.preventDefault(); closeLightbox(); });
document.addEventListener('keydown', function (event) {
if (!lightbox || !lightbox.open || lightboxImageIndex < 0) return;
if (event.key === 'ArrowLeft') { event.preventDefault(); showLightboxImage(lightboxImageIndex - 1); }
else if (event.key === 'ArrowRight') { event.preventDefault(); showLightboxImage(lightboxImageIndex + 1); }
});
function handleReducedMotion() {
if (reducedMotion.matches) {
window.clearTimeout(finderTimer);
liveDemos.forEach(function (demo) {
var frame = demo.querySelector('iframe');
if (frame && frame.getAttribute('src')) callDemo(frame, 'stop');
});
if (tourVideo && !tourVideo.paused) tourVideo.pause();
if (captureVideo && !captureVideo.paused) captureVideo.pause();
} else {
scheduleFinder();
}
}
if (reducedMotion.addEventListener) reducedMotion.addEventListener('change', handleReducedMotion);
else if (reducedMotion.addListener) reducedMotion.addListener(handleReducedMotion);
applyTheme(themeMode, false);
updateTour();
})();