-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
2363 lines (1964 loc) · 74.8 KB
/
Copy pathscript.js
File metadata and controls
2363 lines (1964 loc) · 74.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
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const root = document.documentElement;
const pageBody = document.body;
const openButtons = [...document.querySelectorAll("[data-open]")];
const closeButtons = [...document.querySelectorAll("[data-close]")];
const centerButtons = [...document.querySelectorAll("[data-center]")];
const windows = [...document.querySelectorAll(".app-window")];
const filterInputs = [...document.querySelectorAll("[data-filter]")];
const clock = document.querySelector("#system-clock");
const windowLayer = document.querySelector(".window-layer");
const desktopShell = document.querySelector(".desktop-shell");
const sphereGalleries = [...document.querySelectorAll("[data-sphere-gallery]")];
const aboutTimeline = document.querySelector("[data-about-timeline]");
const aboutTimelineCube = document.querySelector("[data-about-timeline-cube]");
const aboutTimelineFaces = [...document.querySelectorAll("[data-about-timeline-face]")];
const aboutTimelineList = document.querySelector("[data-about-timeline-list]");
const aboutTimelineItems = [...document.querySelectorAll("[data-about-timeline-item]")]
.sort((left, right) => (right.dataset.date || "").localeCompare(left.dataset.date || ""));
const aboutTimelineCurrent = document.querySelector("[data-about-timeline-current]");
const aboutTimelineAngle = document.querySelector("[data-about-timeline-angle]");
const aboutTimelineTotals = [...document.querySelectorAll("[data-about-timeline-total]")];
const aboutNetworkField = document.querySelector("[data-about-network]");
const gameLibraryScroll = document.querySelector("#window-games .game-ui-scroll");
const gameCarousel = document.querySelector("[data-game-carousel]");
const gameEntries = [...document.querySelectorAll("#window-games [data-game-entry]")];
const gamePrevButton = document.querySelector("[data-game-prev]");
const gameNextButton = document.querySelector("[data-game-next]");
const gameCounter = document.querySelector("[data-game-counter]");
const gameDots = [...document.querySelectorAll("[data-game-dot]")];
const sphereNavigationState = new WeakMap();
const sparkleShapes = ["heart", "star", "flower", "moon"];
const sparkleGlyphs = {
heart: "♥",
star: "✦",
flower: "✿",
moon: "☾",
};
const aboutCubeColors = [
["#ff3b5c", "255 59 92"],
["#ff6b57", "255 107 87"],
["#ff8a2a", "255 138 42"],
["#ffb020", "255 176 32"],
["#ffe04b", "255 224 75"],
["#b8ff3d", "184 255 61"],
["#39e66b", "57 230 107"],
["#20d99a", "32 217 154"],
["#55f2c4", "85 242 196"],
["#22d3c5", "34 211 197"],
["#35e7ff", "53 231 255"],
["#45bfff", "69 191 255"],
["#3f7cff", "63 124 255"],
["#3155ff", "49 85 255"],
["#5b50ff", "91 80 255"],
["#8f5cff", "143 92 255"],
["#ba55ff", "186 85 255"],
["#ec46ff", "236 70 255"],
["#ff3fc5", "255 63 197"],
["#ff5f9e", "255 95 158"],
["#ff4f74", "255 79 116"],
["#ffd166", "255 209 102"],
["#4fffe1", "79 255 225"],
["#d7ff4f", "215 255 79"],
];
let activeWindowKey = "";
let topZIndex = 20;
let lastTrailAt = 0;
let lastCollapseAt = 0;
let pendingOpenTimer = 0;
let homeGlitchTimer = 0;
let gamePortalTimers = [];
let gameVhsFrame = 0;
let gameVhsLastPaint = 0;
let gameCarouselIndex = 0;
let gameCarouselWheelDelta = 0;
let gameCarouselWheelIdleTimer = 0;
let gameCarouselTransitionTimer = 0;
let gameCarouselLastWheelAt = 0;
let gameCarouselLocked = false;
let gameCarouselPointerStart = null;
let gameCarouselSuppressClick = false;
let gameCarouselClickResetTimer = 0;
let isGamePortalTransitioning = false;
let isWindowSwitching = false;
let aboutTransitionTimers = [];
let aboutTimelineIndex = 0;
let aboutTimelineQuarter = 0;
let aboutTimelineWheelDelta = 0;
let aboutTimelineWheelConsumed = false;
let aboutTimelineWheelIdleTimer = 0;
let aboutTimelineAnimationTimer = 0;
let aboutTimelineAutoTimer = 0;
let aboutTimelineAutoPaused = false;
let aboutTimelinePendingIndex = null;
let aboutTimelinePointerStart = null;
let lastAboutCubePrimary = -1;
const homeGlitchReducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const GAME_PORTAL_TRAVEL_DURATION = 420;
const GAME_PORTAL_TOTAL_DURATION = 1780;
const GAME_CLOSE_COLLAPSE_DURATION = 620;
const GAME_CAROUSEL_DURATION = 680;
const GAME_CAROUSEL_WHEEL_THRESHOLD = 140;
const GAME_CAROUSEL_WHEEL_QUIET = 150;
const DEFAULT_WINDOW_CLOSE_DURATION = 180;
const WINDOW_SWITCH_GAP = 34;
const ABOUT_LASER_DURATION = 600;
const ABOUT_OPEN_DURATION = 760;
const ABOUT_CLOSE_DURATION = 640;
const ABOUT_TIMELINE_DURATION = 720;
const ABOUT_TIMELINE_WHEEL_THRESHOLD = 44;
const ABOUT_TIMELINE_AUTO_DELAY = 5600;
const windowState = new Map(
windows.map((panel) => [
panel.dataset.window || "",
{
dragged: false,
left: null,
top: null,
},
]),
);
function getWindowByKey(key) {
return document.querySelector(`.app-window[data-window="${key}"]`);
}
function setGameEntryVisible(entry, isVisible) {
entry.classList.toggle("is-game-visible", isVisible);
if (!isVisible) {
return;
}
entry.querySelectorAll("img[data-src]").forEach((image) => {
image.src = image.dataset.src || "";
image.removeAttribute("data-src");
});
}
function wrapGameCarouselIndex(index) {
return (index + gameEntries.length) % gameEntries.length;
}
function syncGameCarousel() {
if (!gameEntries.length) {
return;
}
gameEntries.forEach((entry, index) => {
let offset = wrapGameCarouselIndex(index - gameCarouselIndex);
if (offset > gameEntries.length / 2) {
offset -= gameEntries.length;
}
const position = offset === 0 ? "current" : offset === -1 ? "prev" : offset === 1 ? "next" : "far";
const isCurrent = position === "current";
entry.dataset.carouselPosition = position;
entry.setAttribute("aria-hidden", String(!isCurrent));
entry.toggleAttribute("inert", !isCurrent);
if (isCurrent) {
entry.setAttribute("aria-current", "true");
} else {
entry.removeAttribute("aria-current");
}
setGameEntryVisible(entry, isCurrent);
});
gameDots.forEach((dot, index) => {
const isCurrent = index === gameCarouselIndex;
dot.classList.toggle("is-active", isCurrent);
if (isCurrent) {
dot.setAttribute("aria-current", "true");
} else {
dot.removeAttribute("aria-current");
}
});
if (gameCounter) {
gameCounter.textContent = `${String(gameCarouselIndex + 1).padStart(2, "0")} / ${String(gameEntries.length).padStart(2, "0")}`;
}
}
function unlockGameCarouselWhenSettled() {
const wheelQuietFor = performance.now() - gameCarouselLastWheelAt;
if (gameCarouselLastWheelAt && wheelQuietFor < GAME_CAROUSEL_WHEEL_QUIET) {
gameCarouselTransitionTimer = window.setTimeout(
unlockGameCarouselWhenSettled,
GAME_CAROUSEL_WHEEL_QUIET - wheelQuietFor,
);
return;
}
gameCarouselLocked = false;
gameCarousel?.classList.remove("is-game-card-rotating");
}
function goToGameCarousel(index) {
const nextIndex = wrapGameCarouselIndex(index);
if (gameCarouselLocked || nextIndex === gameCarouselIndex) {
return;
}
gameCarouselLocked = true;
gameCarouselIndex = nextIndex;
gameCarousel?.classList.add("is-game-card-rotating");
syncGameCarousel();
window.clearTimeout(gameCarouselTransitionTimer);
gameCarouselTransitionTimer = window.setTimeout(unlockGameCarouselWhenSettled, GAME_CAROUSEL_DURATION);
}
function moveGameCarousel(step) {
goToGameCarousel(gameCarouselIndex + step);
}
function setupGameLibrary() {
if (!gameLibraryScroll || !gameCarousel || !gameEntries.length) {
return;
}
gameEntries.forEach((entry) => {
entry.querySelectorAll("img").forEach((image) => {
image.loading = "lazy";
image.decoding = "async";
image.fetchPriority = "low";
});
});
syncGameCarousel();
gameCarousel.addEventListener("wheel", (event) => {
event.preventDefault();
gameCarouselLastWheelAt = performance.now();
if (gameCarouselLocked) {
return;
}
const pageScale = event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? gameCarousel.clientHeight : 1;
const normalizedDelta = Math.max(-90, Math.min(90, event.deltaY * pageScale));
gameCarouselWheelDelta += normalizedDelta;
window.clearTimeout(gameCarouselWheelIdleTimer);
gameCarouselWheelIdleTimer = window.setTimeout(() => {
gameCarouselWheelDelta = 0;
}, 180);
if (Math.abs(gameCarouselWheelDelta) < GAME_CAROUSEL_WHEEL_THRESHOLD) {
return;
}
const direction = Math.sign(gameCarouselWheelDelta);
gameCarouselWheelDelta = 0;
moveGameCarousel(direction);
}, { passive: false });
gameCarousel.addEventListener("pointerdown", (event) => {
const target = event.target instanceof Element ? event.target : null;
if (event.button !== 0 || target?.closest("button")) {
return;
}
gameCarouselPointerStart = {
id: event.pointerId,
x: event.clientX,
y: event.clientY,
};
});
gameCarousel.addEventListener("pointerup", (event) => {
if (!gameCarouselPointerStart || gameCarouselPointerStart.id !== event.pointerId) {
return;
}
const deltaX = event.clientX - gameCarouselPointerStart.x;
const deltaY = event.clientY - gameCarouselPointerStart.y;
gameCarouselPointerStart = null;
if (Math.abs(deltaY) >= 54 && Math.abs(deltaY) > Math.abs(deltaX) * 1.15) {
event.preventDefault();
gameCarouselSuppressClick = true;
window.clearTimeout(gameCarouselClickResetTimer);
gameCarouselClickResetTimer = window.setTimeout(() => {
gameCarouselSuppressClick = false;
}, 120);
moveGameCarousel(deltaY > 0 ? -1 : 1);
}
});
gameCarousel.addEventListener("pointercancel", () => {
gameCarouselPointerStart = null;
});
gameCarousel.addEventListener("click", (event) => {
if (!gameCarouselSuppressClick) {
return;
}
event.preventDefault();
event.stopPropagation();
}, true);
gameLibraryScroll.addEventListener("keydown", (event) => {
if (["ArrowDown", "PageDown"].includes(event.key)) {
event.preventDefault();
moveGameCarousel(1);
} else if (["ArrowUp", "PageUp"].includes(event.key)) {
event.preventDefault();
moveGameCarousel(-1);
} else if (event.key === "Home") {
event.preventDefault();
goToGameCarousel(0);
} else if (event.key === "End") {
event.preventDefault();
goToGameCarousel(gameEntries.length - 1);
}
});
gamePrevButton?.addEventListener("click", () => moveGameCarousel(-1));
gameNextButton?.addEventListener("click", () => moveGameCarousel(1));
gameDots.forEach((dot, index) => {
dot.addEventListener("click", () => goToGameCarousel(index));
});
}
function syncLauncherState() {
openButtons.forEach((button) => {
const panel = getWindowByKey(button.dataset.open || "");
const isPanelOpen = Boolean(panel?.classList.contains("is-open"));
const isDisabled = isWindowSwitching || isPanelOpen;
button.classList.toggle("is-active", isPanelOpen);
button.setAttribute("aria-disabled", String(isDisabled));
if ("disabled" in button) {
button.disabled = isDisabled;
}
});
}
function setWindowSwitching(isSwitching) {
isWindowSwitching = isSwitching;
root.classList.toggle("is-window-switching", isSwitching);
pageBody.classList.toggle("is-window-switching", isSwitching);
windowLayer?.setAttribute("aria-busy", String(isSwitching));
syncLauncherState();
}
function syncWindowEnvironment() {
const hasOpenWindow = windows.some((item) => item.classList.contains("is-open"));
const hasImmersiveWindow = windows.some((item) => item.classList.contains("is-open") && item.classList.contains("immersive-window"));
root.classList.toggle("has-open-window", hasOpenWindow);
root.classList.toggle("has-immersive-window", hasImmersiveWindow);
pageBody.classList.toggle("has-open-window", hasOpenWindow);
pageBody.classList.toggle("has-immersive-window", hasImmersiveWindow);
windowLayer?.classList.toggle("is-active", hasOpenWindow);
}
function centerWindow(panel, options = {}) {
if (!panel) {
return;
}
const key = panel.dataset.window || "";
const state = windowState.get(key);
if (panel.classList.contains("immersive-window")) {
panel.style.left = "";
panel.style.top = "";
panel.style.right = "";
panel.style.bottom = "";
return;
}
if (window.innerWidth <= 920) {
panel.style.left = "";
panel.style.top = `${Math.max(12, Math.round((window.innerHeight - panel.offsetHeight) / 2))}px`;
panel.style.right = "";
panel.style.bottom = "auto";
if (state) {
state.dragged = false;
state.left = null;
state.top = null;
}
return;
}
const desktopScale = Number.parseFloat(
window.getComputedStyle(root).getPropertyValue("--desktop-scale"),
) || 1;
const panelWidth = (panel.offsetWidth || panel.getBoundingClientRect().width) * desktopScale;
const panelHeight = (panel.offsetHeight || panel.getBoundingClientRect().height) * desktopScale;
const nextLeft = Math.max(12 / desktopScale, Math.round((window.innerWidth - panelWidth) / 2 / desktopScale));
const nextTop = Math.max(76 / desktopScale, Math.round((window.innerHeight - panelHeight) / 2 / desktopScale));
panel.style.left = `${nextLeft}px`;
panel.style.top = `${nextTop}px`;
panel.style.right = "auto";
panel.style.bottom = "auto";
if (state) {
state.dragged = Boolean(options.rememberPosition);
state.left = options.rememberPosition ? nextLeft : null;
state.top = options.rememberPosition ? nextTop : null;
}
}
function applyWindowPlacement(panel) {
const key = panel?.dataset.window || "";
const state = windowState.get(key);
if (!panel) {
return;
}
if (key !== "articles" && key !== "works") {
centerWindow(panel);
return;
}
if (panel.classList.contains("immersive-window")) {
panel.style.left = "";
panel.style.top = "";
panel.style.right = "";
panel.style.bottom = "";
return;
}
if (window.innerWidth <= 920) {
panel.style.left = "";
panel.style.top = "";
panel.style.right = "";
panel.style.bottom = "";
return;
}
if (state?.dragged && state.left !== null && state.top !== null) {
panel.style.left = `${state.left}px`;
panel.style.top = `${state.top}px`;
panel.style.right = "auto";
panel.style.bottom = "auto";
return;
}
centerWindow(panel);
}
function focusWindow(panel) {
if (!panel) {
return;
}
activeWindowKey = panel.dataset.window || "";
topZIndex += 1;
panel.style.zIndex = String(topZIndex);
windows.forEach((item) => {
item.classList.toggle("is-focused", item === panel);
});
syncLauncherState();
}
function clearAboutTransitionTimers() {
aboutTransitionTimers.forEach((timer) => window.clearTimeout(timer));
aboutTransitionTimers = [];
}
function queueAboutTransition(callback, delay) {
const timer = window.setTimeout(callback, delay);
aboutTransitionTimers.push(timer);
return timer;
}
function syncAboutCubeGeometry(panel = getWindowByKey("about")) {
if (panel) {
const panelWidth = panel.offsetWidth || panel.getBoundingClientRect().width;
if (panelWidth) {
panel.style.setProperty("--about-window-depth", `${Math.round(panelWidth / 2)}px`);
}
}
if (aboutTimeline && aboutTimelineCube) {
const cubeHeight = aboutTimelineCube.clientHeight || Math.max(180, aboutTimeline.clientHeight - 28);
aboutTimeline.style.setProperty("--about-timeline-depth", `${Math.round(cubeHeight / 2)}px`);
}
}
function applyRandomAboutCubePalette() {
if (!aboutTimeline || aboutCubeColors.length < 3) {
return;
}
const candidates = aboutCubeColors.map((_, index) => index).filter((index) => index !== lastAboutCubePrimary);
const primaryIndex = candidates[Math.floor(Math.random() * candidates.length)];
const secondaryCandidates = candidates.filter((index) => index !== primaryIndex);
const secondaryIndex = secondaryCandidates[Math.floor(Math.random() * secondaryCandidates.length)];
const tertiaryCandidates = secondaryCandidates.filter((index) => index !== secondaryIndex);
const tertiaryIndex = tertiaryCandidates[Math.floor(Math.random() * tertiaryCandidates.length)];
const [primaryHex, primaryRgb] = aboutCubeColors[primaryIndex];
const [secondaryHex, secondaryRgb] = aboutCubeColors[secondaryIndex];
const [tertiaryHex, tertiaryRgb] = aboutCubeColors[tertiaryIndex];
lastAboutCubePrimary = primaryIndex;
aboutTimeline.style.setProperty("--about-cube-primary", primaryHex);
aboutTimeline.style.setProperty("--about-cube-primary-rgb", primaryRgb);
aboutTimeline.style.setProperty("--about-cube-secondary", secondaryHex);
aboutTimeline.style.setProperty("--about-cube-secondary-rgb", secondaryRgb);
aboutTimeline.style.setProperty("--about-cube-tertiary", tertiaryHex);
aboutTimeline.style.setProperty("--about-cube-tertiary-rgb", tertiaryRgb);
}
function setupAboutNetworkField() {
if (!aboutNetworkField || aboutNetworkField.childElementCount) {
return;
}
const fragment = document.createDocumentFragment();
for (let index = 0; index < 42; index += 1) {
const link = document.createElement("span");
const pulse = document.createElement("i");
link.className = "about-network-link";
link.style.setProperty("--network-x", `${Math.round(-8 + Math.random() * 100)}%`);
link.style.setProperty("--network-y", `${Math.round(4 + Math.random() * 92)}%`);
link.style.setProperty("--network-length", `${Math.round(70 + Math.random() * 190)}px`);
link.style.setProperty("--network-angle", `${Math.round(-72 + Math.random() * 144)}deg`);
link.style.setProperty("--network-delay", `${Math.round(-9000 + Math.random() * 9000)}ms`);
link.style.setProperty("--network-duration", `${Math.round(2100 + Math.random() * 4300)}ms`);
link.style.setProperty("--network-opacity", (0.12 + Math.random() * 0.22).toFixed(2));
link.appendChild(pulse);
fragment.appendChild(link);
}
for (let index = 0; index < 24; index += 1) {
const node = document.createElement("span");
node.className = "about-network-node";
node.style.left = `${Math.round(3 + Math.random() * 94)}%`;
node.style.top = `${Math.round(4 + Math.random() * 92)}%`;
node.style.setProperty("--node-delay", `${Math.round(-5000 + Math.random() * 5000)}ms`);
fragment.appendChild(node);
}
aboutNetworkField.replaceChildren(fragment);
}
function wrapAboutTimelineIndex(index) {
const count = aboutTimelineItems.length;
if (!count) {
return 0;
}
return ((index % count) + count) % count;
}
function getAboutTimelineEntry(index) {
const item = aboutTimelineItems[wrapAboutTimelineIndex(index)];
if (!item) {
return null;
}
return {
code: item.dataset.code || "TIMELINE / SIGNAL",
date: item.dataset.date || "----.--.--",
description: item.dataset.description || "",
index: wrapAboutTimelineIndex(index),
title: item.dataset.title || item.textContent.trim(),
};
}
function populateAboutTimelineFace(face, entryIndex) {
const entry = getAboutTimelineEntry(entryIndex);
if (!face || !entry) {
return;
}
face.dataset.entryIndex = String(entry.index);
const number = face.querySelector("[data-about-detail-number]");
const code = face.querySelector("[data-about-detail-code]");
const date = face.querySelector("[data-about-detail-date]");
const title = face.querySelector("[data-about-detail-title]");
const description = face.querySelector("[data-about-detail-description]");
if (number) number.textContent = String(entry.index + 1).padStart(2, "0");
if (code) code.textContent = entry.code;
if (date) date.textContent = entry.date;
if (title) title.textContent = entry.title;
if (description) description.textContent = entry.description;
}
function syncAboutTimelineSelection(options = {}) {
aboutTimelineItems.forEach((item, index) => {
const isActive = index === aboutTimelineIndex;
item.classList.toggle("is-active", isActive);
item.setAttribute("aria-current", isActive ? "step" : "false");
});
if (aboutTimelineCurrent) {
aboutTimelineCurrent.textContent = String(aboutTimelineIndex + 1).padStart(2, "0");
}
aboutTimelineTotals.forEach((total) => {
total.textContent = String(aboutTimelineItems.length).padStart(2, "0");
});
const activeItem = aboutTimelineItems[aboutTimelineIndex];
if (!aboutTimelineList || !activeItem || options.scroll === false) {
return;
}
const nextTop = Math.max(0, activeItem.offsetTop - (aboutTimelineList.clientHeight - activeItem.offsetHeight) / 2);
if (options.immediate) {
aboutTimelineList.scrollTop = nextTop;
} else {
aboutTimelineList.scrollTo({ top: nextTop, behavior: "smooth" });
}
}
function updateAboutTimelineFaceState() {
const activeSlot = ((aboutTimelineQuarter % aboutTimelineFaces.length) + aboutTimelineFaces.length) % aboutTimelineFaces.length;
aboutTimelineFaces.forEach((face, index) => {
const isActive = index === activeSlot;
face.classList.toggle("is-active", isActive);
face.setAttribute("aria-hidden", String(!isActive));
});
if (aboutTimelineAngle) {
aboutTimelineAngle.textContent = `${String(activeSlot * 90).padStart(3, "0")}°`;
}
}
function clearAboutTimelineAuto() {
window.clearTimeout(aboutTimelineAutoTimer);
aboutTimelineAutoTimer = 0;
aboutTimeline?.classList.remove("is-auto-counting");
}
function scheduleAboutTimelineAuto() {
clearAboutTimelineAuto();
const panel = getWindowByKey("about");
if (aboutTimelineAutoPaused || !panel?.classList.contains("is-open") || panel.classList.contains("is-about-closing")) {
return;
}
aboutTimeline?.getBoundingClientRect();
aboutTimeline?.classList.add("is-auto-counting");
aboutTimelineAutoTimer = window.setTimeout(() => {
navigateAboutTimeline(1, { source: "auto" });
}, ABOUT_TIMELINE_AUTO_DELAY);
}
function setAboutTimelineAutoPaused(isPaused) {
aboutTimelineAutoPaused = isPaused;
if (isPaused) {
clearAboutTimelineAuto();
} else {
scheduleAboutTimelineAuto();
}
}
function renderAboutTimeline(nextIndex, options = {}) {
if (!aboutTimeline || !aboutTimelineCube || !aboutTimelineFaces.length || !aboutTimelineItems.length) {
return false;
}
const targetIndex = wrapAboutTimelineIndex(nextIndex);
if (options.immediate) {
aboutTimelineQuarter = 0;
aboutTimelineIndex = targetIndex;
aboutTimelinePendingIndex = null;
applyRandomAboutCubePalette();
aboutTimelineFaces.forEach((face, slot) => {
const entryIndex = slot === aboutTimelineFaces.length - 1
? targetIndex - 1
: targetIndex + slot;
populateAboutTimelineFace(face, entryIndex);
});
aboutTimelineCube.classList.add("is-immediate");
aboutTimelineCube.style.setProperty("--about-timeline-angle", "0deg");
updateAboutTimelineFaceState();
syncAboutTimelineSelection({ immediate: true });
aboutTimelineCube.getBoundingClientRect();
aboutTimelineCube.classList.remove("is-immediate", "is-rotating");
return true;
}
if (aboutTimelineCube.classList.contains("is-rotating")) {
aboutTimelinePendingIndex = targetIndex;
return false;
}
if (targetIndex === aboutTimelineIndex) {
syncAboutTimelineSelection();
scheduleAboutTimelineAuto();
return false;
}
const forwardDistance = wrapAboutTimelineIndex(targetIndex - aboutTimelineIndex);
const backwardDistance = wrapAboutTimelineIndex(aboutTimelineIndex - targetIndex);
const direction = options.direction || (forwardDistance <= backwardDistance ? 1 : -1);
const nextQuarter = aboutTimelineQuarter + direction;
const incomingSlot = ((nextQuarter % aboutTimelineFaces.length) + aboutTimelineFaces.length) % aboutTimelineFaces.length;
applyRandomAboutCubePalette();
populateAboutTimelineFace(aboutTimelineFaces[incomingSlot], targetIndex);
aboutTimelineIndex = targetIndex;
aboutTimelineQuarter = nextQuarter;
syncAboutTimelineSelection();
updateAboutTimelineFaceState();
window.clearTimeout(aboutTimelineAnimationTimer);
aboutTimelineCube.classList.remove("is-rotating");
aboutTimelineCube.getBoundingClientRect();
aboutTimelineCube.classList.add("is-rotating");
aboutTimelineCube.style.setProperty("--about-timeline-angle", `${aboutTimelineQuarter * -90}deg`);
clearAboutTimelineAuto();
aboutTimelineAnimationTimer = window.setTimeout(() => {
aboutTimelineCube.classList.remove("is-rotating");
if (aboutTimelinePendingIndex !== null && aboutTimelinePendingIndex !== aboutTimelineIndex) {
const pendingIndex = aboutTimelinePendingIndex;
aboutTimelinePendingIndex = null;
renderAboutTimeline(pendingIndex);
} else {
aboutTimelinePendingIndex = null;
scheduleAboutTimelineAuto();
}
}, ABOUT_TIMELINE_DURATION);
return true;
}
function navigateAboutTimeline(direction, options = {}) {
return renderAboutTimeline(aboutTimelineIndex + direction, {
...options,
direction,
});
}
function resetAboutTimeline() {
window.clearTimeout(aboutTimelineWheelIdleTimer);
window.clearTimeout(aboutTimelineAnimationTimer);
clearAboutTimelineAuto();
aboutTimelineWheelDelta = 0;
aboutTimelineWheelConsumed = false;
aboutTimelinePendingIndex = null;
aboutTimelinePointerStart = null;
syncAboutCubeGeometry();
renderAboutTimeline(0, { immediate: true });
}
function setupAboutTimeline() {
if (!aboutTimeline || !aboutTimelineCube || !aboutTimelineFaces.length || !aboutTimelineItems.length) {
return;
}
aboutTimelineList?.replaceChildren(...aboutTimelineItems);
setupAboutNetworkField();
aboutTimelineItems.forEach((item, index) => {
item.addEventListener("click", (event) => {
event.stopPropagation();
renderAboutTimeline(index);
});
});
aboutTimelineList?.addEventListener("wheel", (event) => {
event.stopPropagation();
});
aboutTimeline.addEventListener("wheel", (event) => {
event.preventDefault();
event.stopPropagation();
window.clearTimeout(aboutTimelineWheelIdleTimer);
aboutTimelineWheelIdleTimer = window.setTimeout(() => {
aboutTimelineWheelDelta = 0;
aboutTimelineWheelConsumed = false;
}, 150);
if (aboutTimelineWheelConsumed) {
return;
}
const deltaScale = event.deltaMode === 1 ? 24 : event.deltaMode === 2 ? aboutTimeline.clientHeight : 1;
const dominantDelta = event.deltaY || event.deltaX;
aboutTimelineWheelDelta += dominantDelta * deltaScale;
if (Math.abs(aboutTimelineWheelDelta) < ABOUT_TIMELINE_WHEEL_THRESHOLD) {
return;
}
navigateAboutTimeline(aboutTimelineWheelDelta > 0 ? 1 : -1, { source: "wheel" });
aboutTimelineWheelDelta = 0;
aboutTimelineWheelConsumed = true;
}, { passive: false });
aboutTimeline.addEventListener("keydown", (event) => {
const direction = ["ArrowDown", "ArrowRight", "PageDown"].includes(event.key)
? 1
: ["ArrowUp", "ArrowLeft", "PageUp"].includes(event.key)
? -1
: 0;
if (!direction) {
return;
}
event.preventDefault();
event.stopPropagation();
navigateAboutTimeline(direction, { source: "keyboard" });
});
aboutTimeline.addEventListener("pointerdown", (event) => {
if (!event.isPrimary || event.button !== 0) {
return;
}
aboutTimelinePointerStart = {
pointerId: event.pointerId,
x: event.clientX,
y: event.clientY,
};
aboutTimeline.setPointerCapture?.(event.pointerId);
});
aboutTimeline.addEventListener("pointerup", (event) => {
if (!aboutTimelinePointerStart || aboutTimelinePointerStart.pointerId !== event.pointerId) {
return;
}
const deltaX = event.clientX - aboutTimelinePointerStart.x;
const deltaY = event.clientY - aboutTimelinePointerStart.y;
aboutTimelinePointerStart = null;
if (Math.abs(deltaY) < 42 || Math.abs(deltaY) < Math.abs(deltaX)) {
return;
}
event.preventDefault();
event.stopPropagation();
navigateAboutTimeline(deltaY < 0 ? 1 : -1, { source: "swipe" });
});
aboutTimeline.addEventListener("pointercancel", () => {
aboutTimelinePointerStart = null;
});
[aboutTimeline, aboutTimelineList].filter(Boolean).forEach((region) => {
region.addEventListener("pointerenter", (event) => {
if (event.pointerType === "mouse") {
setAboutTimelineAutoPaused(true);
}
});
region.addEventListener("pointerleave", (event) => {
if (event.pointerType === "mouse") {
setAboutTimelineAutoPaused(false);
}
});
});
document.addEventListener("visibilitychange", () => {
if (document.hidden) {
clearAboutTimelineAuto();
} else {
scheduleAboutTimelineAuto();
}
});
resetAboutTimeline();
}
function activateWindowPanel(panel) {
applyWindowPlacement(panel);
panel.classList.add("is-open");
panel.setAttribute("aria-hidden", "false");
syncWindowEnvironment();
resetImmersiveScroll(panel);
focusWindow(panel);
requestAnimationFrame(updateSphereGalleries);
}
function finalizeWindowClose(panel, key) {
panel.classList.remove(
"is-open",
"is-focused",
"is-dragging",
"is-about-cutting",
"is-about-opening",
"is-about-closing",
);
panel.setAttribute("aria-hidden", "true");
if (key === "home") {
clearHomeGlitchTransition(panel);
}
if (key === "about") {
clearAboutTransitionTimers();
clearAboutTimelineAuto();
}
if (activeWindowKey === key) {
activeWindowKey = "";
}
syncLauncherState();
syncWindowEnvironment();
}
function startAboutOpen(panel) {
clearAboutTransitionTimers();
aboutTimelineAutoPaused = false;
panel.classList.remove("is-about-cutting", "is-about-opening", "is-about-closing", "is-about-finalizing");
activateWindowPanel(panel);
resetAboutTimeline();
syncAboutCubeGeometry(panel);
panel.getBoundingClientRect();
panel.classList.add("is-about-cutting");
queueAboutTransition(() => {
if (!panel.classList.contains("is-open")) {
return;
}
panel.classList.remove("is-about-cutting");
panel.classList.add("is-about-opening");
}, ABOUT_LASER_DURATION);
queueAboutTransition(() => {
panel.classList.remove("is-about-opening");
scheduleAboutTimelineAuto();
}, ABOUT_LASER_DURATION + ABOUT_OPEN_DURATION);
}
function startAboutClose(panel, key) {
clearAboutTransitionTimers();
clearAboutTimelineAuto();
panel.classList.remove("is-about-cutting", "is-about-opening");
panel.classList.add("is-about-closing");
if (activeWindowKey === key) {
activeWindowKey = "";
}
syncLauncherState();
queueAboutTransition(() => {
panel.classList.add("is-about-finalizing");
finalizeWindowClose(panel, key);
}, ABOUT_CLOSE_DURATION);
return ABOUT_CLOSE_DURATION;
}
function showWindow(panel, key) {
if (key === "about") {
startAboutOpen(panel);
return;
}
activateWindowPanel(panel);
if (key === "home") {
playHomeGlitchTransition(panel);
}
}
function clearHomeGlitchTransition(panel) {
window.clearTimeout(homeGlitchTimer);
homeGlitchTimer = 0;
panel?.classList.remove("is-home-glitch-entering");
document.querySelector(".home-glitch-overlay")?.remove();
document.querySelector(".home-page-glitch-overlay")?.remove();
root.classList.remove("is-home-transition-locked");
pageBody.classList.remove("is-home-transition-locked");
}
function sanitizeHomeGlitchClone(clone) {
clone.removeAttribute("id");
clone.removeAttribute("data-window");
clone.setAttribute("aria-hidden", "true");
clone.setAttribute("inert", "");
clone.querySelectorAll("[id], [data-open], [data-close], [data-center], [data-filter]").forEach((item) => {
item.removeAttribute("id");
item.removeAttribute("data-open");
item.removeAttribute("data-close");
item.removeAttribute("data-center");