This repository was archived by the owner on Sep 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
183 lines (156 loc) · 5.85 KB
/
app.js
File metadata and controls
183 lines (156 loc) · 5.85 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
/* SIDEKICK v0 — JavaScript functionality
(text-load animations + model-load fallback handling) */
document.addEventListener('DOMContentLoaded', () => {
const modelViewer = document.getElementById('sidekick-model');
const fallbackMsg = document.getElementById('fallback');
let modelTimeout;
/* ---------- Fallback helpers ---------- */
function showFallback() {
if (!fallbackMsg) return;
console.log('Showing fallback message');
fallbackMsg.classList.add('show');
fallbackMsg.style.opacity = '1';
fallbackMsg.style.display = 'block'; // Ensure it's visible
if (modelViewer) modelViewer.style.display = 'none';
}
function hideFallback() {
if (!fallbackMsg) return;
fallbackMsg.classList.remove('show');
fallbackMsg.style.opacity = '0';
fallbackMsg.style.display = 'none';
}
/* ---------- Incremental text animation ---------- */
function initTextAnimations() {
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
const greetings = document.querySelectorAll('.greeting');
const statusText = document.querySelectorAll('.status-text');
greetings.forEach(el => {
el.style.opacity = '0';
el.style.transition = 'opacity 0.5s cubic-bezier(0.22,0.61,0.36,1)';
});
statusText.forEach(el => {
el.style.opacity = '0';
el.style.transition = 'opacity 0.4s cubic-bezier(0.22,0.61,0.36,1)';
});
greetings.forEach((el, i) => {
setTimeout(() => el.style.opacity = '1', 100 + i * 100);
});
statusText.forEach((el, i) => {
setTimeout(() => el.style.opacity = '1',
50 + greetings.length * 100 + i * 90);
});
}
/* ---------- Model-viewer handling ---------- */
if (modelViewer) {
fallbackMsg.style.display = 'none';
modelViewer.style.transition = 'none';
modelViewer.style.willChange = 'auto';
modelViewer.setAttribute('power-preference', 'low-power');
modelViewer.setAttribute('shadow-softness', '0');
modelTimeout = setTimeout(() => {
if (!modelViewer.loaded) {
console.warn('Model loading timeout after 8 s');
showFallback();
}
}, 8000);
modelViewer.addEventListener('load', () => {
console.log('Model loaded successfully');
clearTimeout(modelTimeout);
fallbackMsg.classList.remove('show');
modelViewer.style.display = 'block';
modelViewer.style.transition = 'opacity 0.2s ease';
});
modelViewer.addEventListener('error', e => {
console.error('Model failed to load:', e.detail);
clearTimeout(modelTimeout);
showFallback();
});
/* Quick source validation */
const originalSrc = modelViewer.src;
setTimeout(() => {
if (modelViewer.src !== originalSrc || !modelViewer.src) {
console.warn('Model source became invalid');
showFallback();
}
}, 3000);
/* Improved camera-controls UX */
let cameraTimeout;
modelViewer.addEventListener('camera-change', () => {
modelViewer.style.filter = 'none';
modelViewer.style.cursor = 'grabbing';
clearTimeout(cameraTimeout);
cameraTimeout = setTimeout(() => {
modelViewer.style.cursor = 'grab';
}, 100);
});
} else {
console.error('Model viewer element not found');
showFallback();
}
/* ---------- GitHub link + footer ---------- */
function initGitHubLink() {
const link = document.querySelector('.github-link');
if (!link) return;
link.addEventListener('click', () => console.log('GitHub link clicked'));
link.addEventListener('keydown', e => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
window.open(link.href, '_blank', 'noopener,noreferrer');
}
});
}
function initFooterInteraction() {
const link = document.querySelector('.github-link');
if (!link) return;
link.addEventListener('mouseenter', () => link.style.letterSpacing = '0.15em');
link.addEventListener('mouseleave', () => link.style.letterSpacing = '0.1em');
}
/* ---------- Responsive viewport fix ---------- */
function adjustModelViewerHeight() {
if (window.innerWidth <= 768) {
const vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', `${vh}px`);
}
}
/* ---------- Keyboard shortcuts ---------- */
function initKeyboardNavigation() {
document.addEventListener('keydown', e => {
if (!modelViewer || !modelViewer.loaded) return;
if (e.key === 'Escape') {
modelViewer.cameraOrbit = '45deg 75deg 5m';
modelViewer.fieldOfView = 'auto';
}
if (e.key === ' ' && e.target === document.body) {
e.preventDefault();
modelViewer.autoRotate = !modelViewer.autoRotate;
}
});
}
/* ---------- Boot-time initializers ---------- */
setTimeout(initTextAnimations, 50);
setTimeout(initFooterInteraction,100);
setTimeout(initKeyboardNavigation,150);
initGitHubLink();
/* Debounced resize */
let resizeTimeout;
window.addEventListener('resize', () => {
clearTimeout(resizeTimeout);
resizeTimeout = setTimeout(adjustModelViewerHeight, 100);
});
adjustModelViewerHeight();
// Console easter egg
console.log(`
╔═=═════════════════════════════════════╗
║ SIDEKICK v0 ║
║ Team "Burn this Hardware" ║
║ ║
║ Press SPACE to toggle auto-rotate ║
║ Press ESC to reset camera view ║
║ GitHub link: github.com/MakerSidekick ║
╚═══=═══════════════════════════════════╝
`);
window.addEventListener('load', () => {
document.body.classList.add('loaded');
console.log('SIDEKICK v0 application fully loaded');
});
});