Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
370 lines (343 loc) · 11.8 KB
/
Copy pathmain.js
File metadata and controls
370 lines (343 loc) · 11.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
/* ==========================================================================
Conic Launcher — website behavior
Minimal platform JS: reveal, counters, conic geometry, navigation,
clock, theme, showcase video play/pause.
========================================================================== */
(function () {
"use strict";
var reduceMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)",
).matches;
if (reduceMotion) document.body.classList.add("no-anim");
/* ------------------------------------------------------------------
Theme
------------------------------------------------------------------ */
var storageKey = "conic-site-theme";
var root = document.documentElement;
var themeBtn = document.querySelector("[data-theme-toggle]");
function applyTheme(theme) {
root.setAttribute("data-theme", theme);
if (themeBtn) {
themeBtn.setAttribute(
"aria-label",
theme === "dark" ? "Switch to light theme" : "Switch to dark theme",
);
themeBtn.textContent = theme === "dark" ? "Light" : "Dark";
}
}
var savedTheme = null;
try {
savedTheme = localStorage.getItem(storageKey);
} catch (e) {}
applyTheme(savedTheme === "light" ? "light" : "dark");
if (themeBtn) {
themeBtn.addEventListener("click", function () {
var next = root.getAttribute("data-theme") === "light" ? "dark" : "light";
applyTheme(next);
try {
localStorage.setItem(storageKey, next);
} catch (e) {}
});
}
/* ------------------------------------------------------------------
Mobile navigation
------------------------------------------------------------------ */
var toggle = document.querySelector(".nav-toggle");
var navLinks = document.getElementById("nav-links");
if (toggle && navLinks) {
toggle.addEventListener("click", function () {
var open = navLinks.classList.toggle("open");
toggle.setAttribute("aria-expanded", open ? "true" : "false");
toggle.setAttribute("aria-label", open ? "Close menu" : "Open menu");
});
navLinks.querySelectorAll("a").forEach(function (a) {
a.addEventListener("click", function () {
navLinks.classList.remove("open");
toggle.setAttribute("aria-expanded", "false");
});
});
}
/* ------------------------------------------------------------------
Conic-section hyperbolas — reproduces the WindowBackground geometry:
six curves sharing one origin, b = 200, a = [40,110,180,280,420,640],
four branches each, rotated -40deg. Colored inner->outer:
lavender, blue, sky, teal, green, yellow, fading per curve.
------------------------------------------------------------------ */
function buildConics() {
var groups = document.querySelectorAll(".backdrop-hyperbolas .conic");
if (!groups.length) return;
var CURVES = [
{ a: 40, cls: "conic-1" },
{ a: 110, cls: "conic-2" },
{ a: 180, cls: "conic-3" },
{ a: 280, cls: "conic-4" },
{ a: 420, cls: "conic-5" },
{ a: 640, cls: "conic-6" },
];
var B = 200;
var RANGE = 640;
var STEP = 8;
var CXR = 600,
CYR = 200; // origin in SVG units
var ROT = (-40 * Math.PI) / 180; // rotation, as in WindowBackground
var SVG = "http://www.w3.org/2000/svg";
groups.forEach(function (g, idx) {
var a = CURVES[idx].a;
g.classList.add(CURVES[idx].cls);
g.style.opacity = (0.45 - idx * 0.055).toFixed(3);
// four branches; build each as a polyline from parametric sampling
[1, -1].forEach(function (sx) {
[1, -1].forEach(function (sy) {
var d = "";
var first = true;
for (var x = a; x <= RANGE; x += STEP) {
var y = B * Math.sqrt((x * x) / (a * a) - 1);
if (!isFinite(y)) continue;
// un-rotated coordinate
var ux = sx * x;
var uy = sy * y;
// rotate by ROT about origin
var px = ux * Math.cos(ROT) - uy * Math.sin(ROT);
var py = ux * Math.sin(ROT) + uy * Math.cos(ROT);
var X = CXR + px;
var Y = CYR - py; // SVG y down
d += (first ? "M" : "L") + X.toFixed(1) + " " + Y.toFixed(1) + " ";
first = false;
}
if (d) {
var path = document.createElementNS(SVG, "path");
path.setAttribute("d", d.trim());
g.appendChild(path);
}
});
});
});
}
/* ------------------------------------------------------------------
Showcase demo videos — play only while in view; honour reduced motion.
------------------------------------------------------------------ */
function initVideos() {
var vids = document.querySelectorAll(".demo video");
if (!vids.length) return;
if (reduceMotion) {
vids.forEach(function (v) {
v.autoplay = false;
v.pause();
});
return;
}
var vp = new IntersectionObserver(function (entries) {
entries.forEach(function (e) {
var v = e.target;
if (e.isIntersecting) {
var p = v.play();
if (p) p.catch(function () {});
} else {
v.pause();
}
});
}, { threshold: 0.25 });
vids.forEach(function (v) { vp.observe(v); });
}
/* ------------------------------------------------------------------
Scroll reveal
------------------------------------------------------------------ */ /* ------------------------------------------------------------------
Scroll reveal
------------------------------------------------------------------ */
var io;
function initReveal() {
var items = document.querySelectorAll(".reveal");
if (reduceMotion || !("IntersectionObserver" in window)) {
items.forEach(function (el) {
el.classList.add("in");
});
return;
}
io = new IntersectionObserver(
function (entries) {
entries.forEach(function (entry) {
if (entry.isIntersecting) {
entry.target.classList.add("in");
io.unobserve(entry.target);
}
});
},
{ threshold: 0.12, rootMargin: "0px 0px -40px 0px" },
);
items.forEach(function (el) {
io.observe(el);
});
}
/* ------------------------------------------------------------------
Animated counters
------------------------------------------------------------------ */
function animateCount(el) {
var target = parseFloat(el.getAttribute("data-count"));
var decimals = parseInt(el.getAttribute("data-decimals") || "0", 10);
if (reduceMotion) {
el.textContent = decimals ? target.toFixed(decimals) : Math.round(target);
return;
}
var duration = 1400;
var start = null;
function frame(ts) {
if (!start) start = ts;
var p = Math.min((ts - start) / duration, 1);
var eased = 1 - Math.pow(1 - p, 3);
var val = target * eased;
el.textContent = decimals ? val.toFixed(decimals) : Math.round(val);
if (p < 1) requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
}
function initCounters() {
var counters = document.querySelectorAll(".metric-num[data-count]");
if (!("IntersectionObserver" in window)) {
counters.forEach(animateCount);
return;
}
var cio = new IntersectionObserver(
function (entries) {
entries.forEach(function (e) {
if (e.isIntersecting) {
animateCount(e.target);
cio.unobserve(e.target);
}
});
},
{ threshold: 0.4 },
);
counters.forEach(function (el) {
cio.observe(el);
});
}
/* ------------------------------------------------------------------
Clock (footer, technical)
------------------------------------------------------------------ */
function startClock() {
var el = document.getElementById("clock");
if (!el) return;
function tick() {
var d = new Date();
var p = function (n) {
return String(n).padStart(2, "0");
};
el.textContent =
p(d.getHours()) + ":" + p(d.getMinutes()) + ":" + p(d.getSeconds());
}
tick();
setInterval(tick, 1000);
}
/* ------------------------------------------------------------------
Lenis smooth scroll + custom scrollbar.
Mirrors kindred launcher's ScrollView behavior: lerp 0.12, thin
pill thumb, hidden native scrollbar. Honors reduced motion.
------------------------------------------------------------------ */
function initSmoothScroll() {
if (typeof window.Lenis !== "function") return;
var scrollbar = document.querySelector(".vscrollbar");
var thumb = document.querySelector(".vscrollbar-thumb");
if (!scrollbar || !thumb) return;
var lenis = new window.Lenis({
lerp: reduceMotion ? 1 : 0.12,
smoothWheel: !reduceMotion,
anchors: !reduceMotion,
autoRaf: true,
});
var MIN_THUMB = 32;
var trackH = 0,
maxScroll = 0,
thumbH = 0,
maxThumbTop = 0;
function measure() {
trackH = scrollbar.clientHeight;
maxScroll = Math.max(
0,
document.documentElement.scrollHeight - window.innerHeight,
);
}
function update() {
measure();
if (maxScroll <= 0) {
scrollbar.classList.add("hidden");
return;
}
scrollbar.classList.remove("hidden");
thumbH = Math.max(
MIN_THUMB,
trackH *
(window.innerHeight / document.documentElement.scrollHeight),
);
thumb.style.height = thumbH + "px";
var clamped = Math.max(0, Math.min(maxScroll, lenis.scroll));
maxThumbTop = trackH - thumbH;
thumb.style.top =
(maxThumbTop <= 0 ? 0 : (clamped / maxScroll) * maxThumbTop) + "px";
}
lenis.on("scroll", update);
/* thumb drag */
var dragging = false,
trackTop = 0,
dragOffset = 0;
thumb.addEventListener("pointerdown", function (e) {
dragging = true;
trackTop = scrollbar.getBoundingClientRect().top;
dragOffset = e.clientY - thumb.getBoundingClientRect().top;
thumb.classList.add("dragging");
try {
thumb.setPointerCapture(e.pointerId);
} catch (err) {}
e.preventDefault();
});
thumb.addEventListener("pointermove", function (e) {
if (!dragging) return;
var top = Math.max(0, Math.min(maxThumbTop, e.clientY - trackTop - dragOffset));
if (maxThumbTop > 0 && maxScroll > 0) {
lenis.scrollTo((top / maxThumbTop) * maxScroll, { immediate: true });
}
});
function endDrag(e) {
if (!dragging) return;
dragging = false;
thumb.classList.remove("dragging");
try {
thumb.releasePointerCapture(e.pointerId);
} catch (err) {}
}
thumb.addEventListener("pointerup", endDrag);
thumb.addEventListener("pointercancel", endDrag);
/* track click — jump */
scrollbar.addEventListener("pointerdown", function (e) {
if (e.target === thumb) return;
var top =
e.clientY - scrollbar.getBoundingClientRect().top - thumbH / 2;
top = Math.max(0, Math.min(maxThumbTop, top));
if (maxThumbTop > 0 && maxScroll > 0) {
lenis.scrollTo((top / maxThumbTop) * maxScroll, { immediate: true });
}
});
/* recalc on layout / size changes */
var resizeWatcher = new ResizeObserver(function () {
lenis.resize();
update();
});
resizeWatcher.observe(document.documentElement);
update();
}
/* ------------------------------------------------------------------
Init
------------------------------------------------------------------ */
function init() {
buildConics();
initSmoothScroll();
initVideos();
initReveal();
initCounters();
startClock();
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", init);
} else {
init();
}
})();