Skip to content

Commit 097220e

Browse files
hackall360claude
andcommitted
Fix: Console errors and improve code separation
- Add null check in smoke-effect.js for canvas measurement context - Add PollinationsAPI availability check in demo api.js - Add null element checks in demo ui.js setupEventListeners - Separate Vite bundling: demo code now bundled separately from main site - Add favicon.ico to copy-assets.js for deployment 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 1a4ef05 commit 097220e

File tree

6 files changed

+79
-42
lines changed

6 files changed

+79
-42
lines changed

ai/demo/js/api.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ let unitySystemPrompt = '';
2121
*/
2222
export function initializePolliLib() {
2323
try {
24+
// Check if PollinationsAPI is available (loaded from pollylib.js)
25+
if (typeof PollinationsAPI === 'undefined') {
26+
console.warn('PollinationsAPI not available - demo features will be disabled');
27+
return { textAPI: null, imageAPI: null, voiceAPI: null };
28+
}
29+
2430
// Initialize Pollinations API (using default referrer)
2531
const textAPI = new PollinationsAPI();
2632
const imageAPI = new PollinationsAPI();

ai/demo/js/ui.js

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,53 +22,70 @@ export function setupEventListeners(
2222
handleSlashCommandInput
2323
) {
2424
// Send button
25-
document.getElementById('sendButton').addEventListener('click', () => sendMessage());
25+
const sendButton = document.getElementById('sendButton');
26+
if (sendButton) {
27+
sendButton.addEventListener('click', () => sendMessage());
28+
}
2629

2730
// Message input - Enter to send, Shift+Enter for new line
2831
const messageInput = document.getElementById('messageInput');
29-
messageInput.addEventListener('keydown', (e) => {
30-
// Handle autocomplete navigation
31-
if (handleAutocompleteNavigation(e)) {
32-
return; // Autocomplete handled the event
33-
}
34-
35-
if (e.key === 'Enter' && !e.shiftKey) {
36-
e.preventDefault();
37-
sendMessage();
38-
}
39-
});
40-
41-
// Auto-resize textarea and handle slash commands
42-
messageInput.addEventListener('input', () => {
43-
autoResizeTextarea(messageInput);
44-
handleSlashCommandInput();
45-
});
32+
if (messageInput) {
33+
messageInput.addEventListener('keydown', (e) => {
34+
// Handle autocomplete navigation
35+
if (handleAutocompleteNavigation(e)) {
36+
return; // Autocomplete handled the event
37+
}
4638

47-
// Input wrapper click - focus on textarea
48-
const inputWrapper = document.querySelector('.input-wrapper');
49-
if (inputWrapper) {
50-
inputWrapper.addEventListener('click', (e) => {
51-
// Don't focus if clicking the send button
52-
if (!e.target.closest('.send-button')) {
53-
messageInput.focus();
39+
if (e.key === 'Enter' && !e.shiftKey) {
40+
e.preventDefault();
41+
sendMessage();
5442
}
5543
});
44+
45+
// Auto-resize textarea and handle slash commands
46+
messageInput.addEventListener('input', () => {
47+
autoResizeTextarea(messageInput);
48+
handleSlashCommandInput();
49+
});
50+
51+
// Input wrapper click - focus on textarea
52+
const inputWrapper = document.querySelector('.input-wrapper');
53+
if (inputWrapper) {
54+
inputWrapper.addEventListener('click', (e) => {
55+
// Don't focus if clicking the send button
56+
if (!e.target.closest('.send-button')) {
57+
messageInput.focus();
58+
}
59+
});
60+
}
5661
}
5762

5863
// Clear session button
59-
document.getElementById('clearSession').addEventListener('click', () => clearSession());
64+
const clearSessionBtn = document.getElementById('clearSession');
65+
if (clearSessionBtn) {
66+
clearSessionBtn.addEventListener('click', () => clearSession());
67+
}
6068

6169
// Stop talking button
62-
document.getElementById('stopTalking').addEventListener('click', () => stopVoicePlayback());
70+
const stopTalkingBtn = document.getElementById('stopTalking');
71+
if (stopTalkingBtn) {
72+
stopTalkingBtn.addEventListener('click', () => stopVoicePlayback());
73+
}
6374

6475
// Delete all data button
65-
document.getElementById('deleteAllData').addEventListener('click', () => deleteAllData());
76+
const deleteAllDataBtn = document.getElementById('deleteAllData');
77+
if (deleteAllDataBtn) {
78+
deleteAllDataBtn.addEventListener('click', () => deleteAllData());
79+
}
6680

6781
// Model info update
68-
document.getElementById('modelSelect').addEventListener('change', (e) => {
69-
updateModelInfo(e.target.value);
70-
saveSettings();
71-
});
82+
const modelSelect = document.getElementById('modelSelect');
83+
if (modelSelect) {
84+
modelSelect.addEventListener('change', (e) => {
85+
updateModelInfo(e.target.value);
86+
saveSettings();
87+
});
88+
}
7289
}
7390

7491
/**

copy-assets.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const ASSETS_TO_COPY = [
1515
{ src: 'vendor', dest: 'vendor', type: 'dir' },
1616
{ src: 'fonts', dest: 'fonts', type: 'dir' },
1717
{ src: 'PolliLibJS', dest: 'PolliLibJS', type: 'dir' },
18+
{ src: 'favicon.ico', dest: 'favicon.ico', type: 'file' },
1819
{ src: 'robots.txt', dest: 'robots.txt', type: 'file' },
1920
{ src: 'sitemap.xml', dest: 'sitemap.xml', type: 'file' },
2021
{ src: 'BingSiteAuth.xml', dest: 'BingSiteAuth.xml', type: 'file' },

js/smoke-effect.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,18 @@ export function initSmokeEffect() {
5757
var measureCanvas = document.createElement('canvas');
5858
var measureCtx = measureCanvas.getContext('2d');
5959

60+
// Check if canvas context is available
61+
if (!measureCtx) {
62+
console.warn('Smoke Effect: Canvas 2D context not available for text measurement');
63+
}
64+
6065
// Cache text element positions for collision detection
6166
function cacheTextElements() {
6267
textElements = [];
68+
69+
// Skip if no measurement context available
70+
if (!measureCtx) return;
71+
6372
var elements = document.querySelectorAll('h1, h2, h3, h4, h5, h6, p, a, span, li, button, .nav-link, .section-title, .gothic-title');
6473

6574
elements.forEach(function(el) {

sitemap.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,43 @@
22
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
33
<url>
44
<loc>https://www.unityailab.com/</loc>
5-
<lastmod>2025-11-22</lastmod>
5+
<lastmod>2025-11-26</lastmod>
66
<changefreq>daily</changefreq>
77
<priority>1.0</priority>
88
</url>
99
<url>
1010
<loc>https://www.unityailab.com/about/</loc>
11-
<lastmod>2025-11-22</lastmod>
11+
<lastmod>2025-11-26</lastmod>
1212
<changefreq>weekly</changefreq>
1313
<priority>0.8</priority>
1414
</url>
1515
<url>
1616
<loc>https://www.unityailab.com/services/</loc>
17-
<lastmod>2025-11-22</lastmod>
17+
<lastmod>2025-11-26</lastmod>
1818
<changefreq>weekly</changefreq>
1919
<priority>0.8</priority>
2020
</url>
2121
<url>
2222
<loc>https://www.unityailab.com/projects/</loc>
23-
<lastmod>2025-11-22</lastmod>
23+
<lastmod>2025-11-26</lastmod>
2424
<changefreq>weekly</changefreq>
2525
<priority>0.8</priority>
2626
</url>
2727
<url>
2828
<loc>https://www.unityailab.com/contact/</loc>
29-
<lastmod>2025-11-22</lastmod>
29+
<lastmod>2025-11-26</lastmod>
3030
<changefreq>monthly</changefreq>
3131
<priority>0.7</priority>
3232
</url>
3333
<url>
3434
<loc>https://www.unityailab.com/ai/</loc>
35-
<lastmod>2025-11-22</lastmod>
35+
<lastmod>2025-11-26</lastmod>
3636
<changefreq>daily</changefreq>
3737
<priority>0.9</priority>
3838
</url>
3939
<url>
4040
<loc>https://www.unityailab.com/ai/demo/</loc>
41-
<lastmod>2025-11-22</lastmod>
41+
<lastmod>2025-11-26</lastmod>
4242
<changefreq>daily</changefreq>
4343
<priority>0.9</priority>
4444
</url>

vite.config.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,13 @@ export default defineConfig({
7777
if (id.includes('node_modules')) {
7878
return 'vendor';
7979
}
80-
// Shared modules
81-
if (id.includes('js/')) {
82-
return 'shared';
80+
// Demo-specific modules - keep separate from main site
81+
if (id.includes('ai/demo/js/')) {
82+
return 'demo';
83+
}
84+
// Main site shared modules (from /js/ directory)
85+
if (id.includes('/js/') && !id.includes('ai/demo/js/')) {
86+
return 'main-shared';
8387
}
8488
},
8589
},

0 commit comments

Comments
 (0)