44import logging
55import asyncio
66import os
7+ from fastapi .staticfiles import StaticFiles
8+ from nicegui import app
79
810# Set up logging
911logging .basicConfig (level = logging .DEBUG , format = '%(asctime)s - %(levelname)s - %(message)s' )
@@ -371,15 +373,26 @@ def setup_head(background_color: str):
371373 """
372374 Set up common head elements: fonts, fitty JS, and background color.
373375 """
374- ui .add_head_html (f'<link href="https://fonts.cdnfonts.com/css/super-carnival" rel="stylesheet">' )
375- ui .add_head_html ("""
376+ ui .add_css ("""
377+
378+ @font-face {
379+ font-family: 'Super Carnival';
380+ font-style: normal;
381+ font-weight: 400;
382+ /* Load the local .woff file from the static folder */
383+ src: url('/static/Super Carnival.woff') format('woff');
384+ }
385+
386+ """ )
387+
388+ ui .add_head_html (f"""
376389 <link rel="preconnect" href="https://fonts.googleapis.com">
377390 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
378- <link href="https://fonts.googleapis.com/css2?family={BOARD_TILE_FONT.replace(" ", "+")}:opsz@10..1000 &display=swap" rel="stylesheet">
391+ <link href="https://fonts.googleapis.com/css2?family={ BOARD_TILE_FONT .replace (" " , "+" )} &display=swap" rel="stylesheet">
379392 """ )
380393 # Add CSS class for board tile fonts; you can later reference this class in your CSS.
381394 ui .add_head_html (get_google_font_css (BOARD_TILE_FONT , BOARD_TILE_FONT_WEIGHT , BOARD_TILE_FONT_STYLE , "board_tile" ))
382-
395+
383396 ui .add_head_html ('<script src="https://cdn.jsdelivr.net/npm/fitty@2.3.6/dist/fitty.min.js"></script>' )
384397 # Add html2canvas library and capture function.
385398 ui .add_head_html ("""
@@ -394,7 +407,7 @@ def setup_head(background_color: str):
394407 // Run fitty to ensure text is resized and centered
395408 fitty('.fit-text', { multiLine: true, minSize: 10, maxSize: 1000 });
396409 fitty('.fit-text-small', { multiLine: true, minSize: 10, maxSize: 72 });
397-
410+
398411 // Wait a short period to ensure that the board is fully rendered and styles have settled.
399412 setTimeout(function() {
400413 html2canvas(boardElem, {
@@ -412,9 +425,9 @@ def setup_head(background_color: str):
412425 }
413426 </script>
414427 """ )
415-
428+
416429 ui .add_head_html (f'<style>body {{ background-color: { background_color } ; }}</style>' )
417-
430+
418431 ui .add_head_html ("""<script>
419432 document.addEventListener('DOMContentLoaded', () => {
420433 fitty('.fit-text', { multiLine: true, minSize: 10, maxSize: 1000 });
@@ -427,7 +440,7 @@ def setup_head(background_color: str):
427440 fitty('.fit-header', { multiLine: true, minSize: 10, maxSize: 2000 });
428441 });
429442 </script>""" )
430-
443+
431444 # Use full width with padding so the header spans edge-to-edge
432445 with ui .element ("div" ).classes ("w-full" ):
433446 ui .label ("COMMIT !BINGO" ).classes ("fit-header text-center" ).style (f"font-family: { HEADER_FONT_FAMILY } ; color: { HEADER_TEXT_COLOR } ;" )
@@ -491,7 +504,7 @@ def update_tile_styles(tile_buttons_dict: dict):
491504 phrase = board [r ][c ]
492505
493506 if (r , c ) in clicked_tiles :
494- new_card_style = f"background-color: { TILE_CLICKED_BG_COLOR } ; color: { TILE_CLICKED_TEXT_COLOR } ; border: 8px solid { TILE_UNCLICKED_BG_COLOR } ;"
507+ new_card_style = f"background-color: { TILE_CLICKED_BG_COLOR } ; color: { TILE_CLICKED_TEXT_COLOR } ; border: none ;"
495508 new_label_color = TILE_CLICKED_TEXT_COLOR
496509 else :
497510 new_card_style = f"background-color: { TILE_UNCLICKED_BG_COLOR } ; color: { TILE_UNCLICKED_TEXT_COLOR } ; border: none;"
@@ -610,5 +623,8 @@ def generate_new_board():
610623 seed_label .update ()
611624 reset_board ()
612625
626+ # Mount the local 'static' directory so that files like "Super Carnival.woff" can be served
627+ app .mount ("/static" , StaticFiles (directory = "static" ), name = "static" )
628+
613629# Run the NiceGUI app
614630ui .run (port = 8080 , title = "Commit Bingo" , dark = False )
0 commit comments