Skip to content

Commit

Permalink
Prep
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac-Flath committed Feb 18, 2025
1 parent ea4fb3c commit 0797aae
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
3 changes: 3 additions & 0 deletions monsterui/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
'monsterui/core.py'),
'monsterui.core.Theme.headers': ('core.html#theme.headers', 'monsterui/core.py'),
'monsterui.core.Theme.local_headers': ('core.html#theme.local_headers', 'monsterui/core.py'),
'monsterui.core.ThemeFont': ('core.html#themefont', 'monsterui/core.py'),
'monsterui.core.ThemeRadii': ('core.html#themeradii', 'monsterui/core.py'),
'monsterui.core.ThemeShadows': ('core.html#themeshadows', 'monsterui/core.py'),
'monsterui.core._download_resource': ('core.html#_download_resource', 'monsterui/core.py'),
'monsterui.core._headers_theme': ('core.html#_headers_theme', 'monsterui/core.py'),
'monsterui.core.fast_app': ('core.html#fast_app', 'monsterui/core.py')},
Expand Down
51 changes: 32 additions & 19 deletions monsterui/core.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/01_core.ipynb.

# %% auto 0
__all__ = ['HEADER_URLS', 'daisy_styles', 'scrollspy_style', 'fast_app', 'FastHTML', 'Theme']
__all__ = ['HEADER_URLS', 'daisy_styles', 'scrollspy_style', 'fast_app', 'FastHTML', 'ThemeRadii', 'ThemeShadows', 'ThemeFont',
'Theme']

# %% ../nbs/01_core.ipynb
import fasthtml.common as fh
Expand Down Expand Up @@ -32,7 +33,24 @@ def FastHTML(*args, pico=False, **kwargs):
return fh.FastHTML(*args, pico=pico, **bodykw, **kwargs)

# %% ../nbs/01_core.ipynb
def _headers_theme(color, mode='auto'):
class ThemeRadii(VEnum):
none = 'uk-radii-none'
sm = 'uk-radii-sm'
md = 'uk-radii-md'
lg = 'uk-radii-lg'

class ThemeShadows:
none = 'uk-shadows-none'
sm = 'uk-shadows-sm'
md = 'uk-shadows-md'
lg = 'uk-shadows-lg'

class ThemeFont:
sm = 'uk-font-sm'
default = 'uk-font-base'

# %% ../nbs/01_core.ipynb
def _headers_theme(color, mode='auto', radii='md', shadows='sm', font='sm'):
mode_script = {
'auto': '''
const __FRANKEN__ = JSON.parse(localStorage.getItem("__FRANKEN__") || "{}");
Expand All @@ -57,19 +75,16 @@ def _headers_theme(color, mode='auto'):
{mode_script[mode]}
htmlElement.classList.add("uk-theme-{color}");
htmlElement.classList.add(__FRANKEN__.theme || "uk-theme-{color}");
htmlElement.classList.add(__FRANKEN__.radii || "uk-radii-md");
htmlElement.classList.add(__FRANKEN__.shadows || "uk-shadows-sm");
htmlElement.classList.add(__FRANKEN__.font || "uk-font-sm");
htmlElement.classList.add(__FRANKEN__.radii || "uk-radii-{radii}");
htmlElement.classList.add(__FRANKEN__.shadows || "uk-shadows-{shadows}");
htmlElement.classList.add(__FRANKEN__.font || "uk-font-{font}");
''')

# %% ../nbs/01_core.ipynb
HEADER_URLS = {
'franken_css': "https://unpkg.com/[email protected]/dist/css/core.min.css",
# 'franken_tw_utils': "https://unpkg.com/[email protected]/dist/css/utilities.min.css",
'franken_js_core': "https://unpkg.com/[email protected]/dist/js/core.iife.js",
'franken_icons': "https://unpkg.com/[email protected]/dist/js/icon.iife.js",
# 'icon_js': "https://cdn.jsdelivr.net/gh/answerdotai/monsterui@main/monsterui/icon.iife.js",
'franken_css': "https://unpkg.com/[email protected]/dist/css/core.min.css",
'franken_js_core': "https://unpkg.com/[email protected]/dist/js/core.iife.js",
'franken_icons': "https://unpkg.com/[email protected]/dist/js/icon.iife.js",
'tailwind': "https://cdn.tailwindcss.com",
'daisyui': "https://cdn.jsdelivr.net/npm/[email protected]/dist/full.min.css",
'highlight_js': "https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/highlight.min.js",
Expand Down Expand Up @@ -151,11 +166,10 @@ def _generate_next_value_(name, start, count, last_values): return name
violet = auto()
zinc = auto()

def _create_headers(self, urls, mode='auto', daisy=True, highlightjs=False, katex=True):
def _create_headers(self, urls, mode='auto', daisy=True, highlightjs=False, katex=True, radii='md', shadows='sm', font='sm'):
"Create header elements with given URLs"
hdrs = [
fh.Link(rel="stylesheet", href=urls['franken_css']),
# fh.Link(rel="stylesheet", href=urls['franken_utils']),
fh.Script(type="module", src=urls['franken_js_core']),
fh.Script(type="module", src=urls['franken_icons']),
fh.Script(src=urls['tailwind']),
Expand All @@ -164,7 +178,7 @@ def _create_headers(self, urls, mode='auto', daisy=True, highlightjs=False, kate
darkMode: 'selector',
}
"""),
_headers_theme(self.value, mode=mode),
_headers_theme(self.value, mode=mode, radii=radii, shadows=shadows, font=font),
scrollspy_style]

if daisy:
Expand Down Expand Up @@ -220,15 +234,14 @@ def _create_headers(self, urls, mode='auto', daisy=True, highlightjs=False, kate
});
""",type="module"),
]

return hdrs

def headers(self, mode='auto', daisy=True, highlightjs=False, katex=True):
def headers(self, mode='auto', daisy=True, highlightjs=False, katex=True, radii='md', shadows='sm', font='sm' ):
"Create frankenui and tailwind cdns"
return self._create_headers(HEADER_URLS, mode=mode, daisy=daisy, highlightjs=highlightjs, katex=katex)
return self._create_headers(HEADER_URLS, mode=mode, daisy=daisy, highlightjs=highlightjs, katex=katex, radii=radii, shadows=shadows, font=font)

def local_headers(self, mode='auto', static_dir='static', daisy=True, highlightjs=False, katex=True):
def local_headers(self, mode='auto', static_dir='static', daisy=True, highlightjs=False, katex=True, radii='md', shadows='sm', font='sm'):
"Create headers using local files downloaded from CDNs"
Path(static_dir).mkdir(exist_ok=True)
local_urls = dict([_download_resource(url, static_dir) for url in HEADER_URLS.items()])
return self._create_headers(local_urls, mode=mode, daisy=daisy, highlightjs=highlightjs, katex=katex)
return self._create_headers(local_urls, mode=mode, daisy=daisy, highlightjs=highlightjs, katex=katex, radii=radii, shadows=shadows, font=font)

0 comments on commit 0797aae

Please sign in to comment.