-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea4fb3c
commit 0797aae
Showing
2 changed files
with
35 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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__") || "{}"); | ||
|
@@ -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", | ||
|
@@ -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']), | ||
|
@@ -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: | ||
|
@@ -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) |