Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
280 lines (240 loc) · 8.36 KB
/
Copy pathapp.js
File metadata and controls
280 lines (240 loc) · 8.36 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
const content = window.ALEKSI_CONTENT || {};
function escapeHtml(value) {
return String(value || '').replace(/[&<>"']/g, (char) => ({
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
}[char]));
}
function articleHref(src) {
return `./article.html?src=${encodeURIComponent(src)}`;
}
function hrefForArtifact(item) {
return item.href || articleHref(item.source);
}
function linkList(items) {
const current = window.location.pathname.split('/').pop() || 'index.html';
return items.map((item) => {
const href = item.href || './index.html';
const label = escapeHtml(item.label || '');
const file = href.replace('./', '').split('#')[0].split('?')[0] || 'index.html';
const active = file === current || (current === '' && file === 'index.html');
return `<a class="nav-link${active ? ' is-active' : ''}" href="${href}"${active ? ' aria-current="page"' : ''}>${label}</a>`;
}).join('');
}
function renderNavigation() {
const desktopNav = document.querySelector('.desktop-nav');
if (desktopNav && Array.isArray(content.nav)) desktopNav.innerHTML = linkList(content.nav);
}
function renderHeroCopy() {
const hero = content.hero || {};
const eyebrow = document.querySelector('.hero-copy .eyebrow');
const cn = document.querySelector('.hero-cn');
const lede = document.querySelector('.hero-lede');
const support = document.querySelector('.hero-support');
if (eyebrow) eyebrow.textContent = hero.eyebrow || 'PERSONAL LAB / INDEX';
if (cn) cn.textContent = hero.cn || 'Learning, making, and revision.';
if (lede) lede.textContent = hero.lede || '学习、创作与 AI 协作的长期实验室。';
if (support) support.textContent = hero.note || '把学习、创作与反馈,修订成可复用的结构。';
}
function initHeroLottie() {
const container = document.getElementById('heroGlyphLottie');
if (!container) return;
const figure = container.closest('.hero-lottie-figure');
const markFailed = (reason) => {
if (figure) {
figure.classList.remove('has-lottie');
figure.classList.add('lottie-failed');
}
container.classList.remove('is-ready');
if (reason) console.warn(`[Aleksi Lab] Hero Lottie fallback: ${reason}`);
};
if (!window.lottie || typeof window.lottie.loadAnimation !== 'function') {
markFailed('lottie-web did not load.');
return;
}
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
const firstVisibleFrame = 12;
const animation = window.lottie.loadAnimation({
container,
renderer: 'svg',
loop: !reduceMotion,
autoplay: false,
path: './assets/lottie/overview-dark.json',
initialSegment: [firstVisibleFrame, 239],
rendererSettings: {
preserveAspectRatio: 'xMidYMid meet',
progressiveLoad: true
}
});
animation.setSpeed(0.82);
let observer;
let ready = false;
const revealLottie = () => {
if (ready) return;
ready = true;
container.classList.add('is-ready');
if (figure) {
figure.classList.add('has-lottie');
figure.classList.remove('lottie-failed');
}
};
window.addEventListener('pagehide', () => {
if (observer) observer.disconnect();
animation.destroy();
}, { once: true });
animation.addEventListener('DOMLoaded', () => {
if (reduceMotion) {
animation.goToAndStop(60, true);
revealLottie();
return;
}
animation.goToAndStop(firstVisibleFrame, true);
requestAnimationFrame(() => {
requestAnimationFrame(revealLottie);
});
});
animation.addEventListener('data_failed', () => markFailed('animation data failed to load.'));
animation.addEventListener('configError', () => markFailed('animation config error.'));
animation.addEventListener('renderFrameError', () => markFailed('animation render error.'));
if (reduceMotion) return;
if ('IntersectionObserver' in window) {
observer = new IntersectionObserver(([entry]) => {
if (entry.isIntersecting) animation.play();
else animation.pause();
}, { threshold: 0.24 });
observer.observe(container);
} else {
animation.play();
}
}
function renderGuideRows() {
const rows = document.querySelector('[data-guide-rows]');
if (!rows) return;
rows.innerHTML = (content.homeGuideRows || []).map((item) => `
<a class="guide-row" href="${item.href}" data-reveal>
<span class="guide-row-no">${item.no} / ${item.label}</span>
<strong class="guide-row-title">${item.title}</strong>
<p>${item.description}</p>
<em>${item.action} →</em>
</a>
`).join('');
}
function mediaClass(index) {
return ['is-heather', 'is-sky', 'is-peach'][index % 3];
}
function artifactGlyph(item, index) {
const glyphs = ['⌁', '∴', '◇'];
return item.glyph || glyphs[index % glyphs.length];
}
function renderSelectedArtifacts() {
const grid = document.querySelector('[data-selected-artifacts]');
if (!grid) return;
grid.innerHTML = (content.selectedArtifacts || []).slice(0, 3).map((item, index) => `
<a class="selected-artifact-card claude-card" href="${hrefForArtifact(item)}" data-reveal>
${item.image ? `
<figure>
<div class="card-media ${mediaClass(index)}">
<img src="${item.image}" alt="${item.imageAlt}" loading="lazy">
</div>
</figure>
` : `
<figure>
<div class="card-media ${mediaClass(index)} artifact-glyph" aria-hidden="true">${artifactGlyph(item, index)}</div>
</figure>
`}
<div class="selected-artifact-body">
<div class="selected-artifact-meta claude-card-meta">
<span>${item.type}</span>
<span>${item.status}</span>
</div>
<h3 class="card-title claude-card-title">${item.title}</h3>
<p class="claude-card-body">${item.body}</p>
</div>
</a>
`).join('');
}
function startSelectedCarousel() {
const grid = document.querySelector('[data-selected-artifacts]');
if (!grid || grid.children.length < 2 || window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
let index = 0;
let paused = false;
const cards = Array.from(grid.children);
const advance = () => {
if (paused || !cards.length) return;
index = (index + 1) % cards.length;
grid.scrollTo({ left: cards[index].offsetLeft - grid.offsetLeft, behavior: 'smooth' });
};
const timer = setInterval(advance, 4200);
grid.addEventListener('mouseenter', () => { paused = true; });
grid.addEventListener('mouseleave', () => { paused = false; });
grid.addEventListener('focusin', () => { paused = true; });
grid.addEventListener('focusout', () => { paused = false; });
window.addEventListener('pagehide', () => clearInterval(timer), { once: true });
}
function renderArchiveLinks() {
const list = document.querySelector('[data-archive-links]');
if (!list) return;
list.innerHTML = (content.archiveLinks || []).map((item) => `
<a class="archive-link-item" href="${item.href}" data-reveal>
<span>${item.label}</span>
<em>→</em>
</a>
`).join('');
}
function revealWithoutGSAP() {
document.documentElement.classList.add('no-gsap');
document.querySelectorAll('[data-reveal]').forEach((item) => item.classList.add('is-visible'));
}
function initMotion() {
if (!window.gsap) {
revealWithoutGSAP();
return;
}
if (window.ScrollTrigger) gsap.registerPlugin(ScrollTrigger);
const mm = gsap.matchMedia();
mm.add({
isMobile: '(max-width: 720px)',
reduceMotion: '(prefers-reduced-motion: reduce)'
}, (context) => {
const { isMobile, reduceMotion } = context.conditions;
if (reduceMotion) {
gsap.set('[data-reveal], .hero-copy > *, .hero-card', { y: 0, autoAlpha: 1 });
return;
}
gsap.fromTo('.hero-copy > *, .hero-card', {
y: isMobile ? 0 : 10,
autoAlpha: isMobile ? 1 : 0.72
}, {
y: 0,
autoAlpha: 1,
duration: 0.86,
stagger: 0.045,
ease: 'power2.out'
});
if (window.ScrollTrigger) {
ScrollTrigger.batch('main [data-reveal]', {
start: 'top 88%',
once: true,
batchMax: isMobile ? 2 : 4,
onEnter: (batch) => gsap.to(batch, {
y: 0,
autoAlpha: 1,
duration: 0.72,
stagger: 0.035,
overwrite: true
})
});
}
});
}
renderNavigation();
renderHeroCopy();
initHeroLottie();
renderGuideRows();
renderSelectedArtifacts();
startSelectedCarousel();
renderArchiveLinks();
initMotion();