| 1 |
# vim:fileencoding=utf-8 |
| 2 |
# License: GPL v3 Copyright: 2026, Kovid Goyal <kovid at kovidgoyal.net> |
| 3 |
from __python__ import hash_literals |
| 4 |
|
| 5 |
from book_list.theme import get_color |
| 6 |
from dom import add_extra_css, build_rule, unique_id |
| 7 |
from read_book.chrome import viewer_chrome_colors |
| 8 |
|
| 9 |
MAIN_OVERLAY_TS_CLASS = 'read-book-main-overlay-top-section' |
| 10 |
MAIN_OVERLAY_ACTIONS_CLASS = 'read-book-main-overlay-actions' |
| 11 |
MAIN_OVERLAY_ACTION_CONTROL_CLASS = 'read-book-main-overlay-action-control' |
| 12 |
MAIN_OVERLAY_ACTION_ICON_CLASS = 'read-book-main-overlay-action-icon' |
| 13 |
MAIN_OVERLAY_TEXT_ICON_CLASS = 'read-book-main-overlay-text-icon' |
| 14 |
MAIN_OVERLAY_TOP_ROW_CLASS = 'read-book-main-overlay-top-row' |
| 15 |
MAIN_OVERLAY_TITLE_CLASS = 'read-book-main-overlay-title' |
| 16 |
MAIN_OVERLAY_TIMER_CLASS = 'read-book-main-overlay-timer' |
| 17 |
MAIN_OVERLAY_FOOTER_ACTION_CLASS = 'read-book-main-overlay-footer-action' |
| 18 |
MAIN_OVERLAY_FOOTER_CLASS = 'read-book-main-overlay-footer' |
| 19 |
MAIN_OVERLAY_FOOTER_ACTIONS_CLASS = 'read-book-main-overlay-footer-actions' |
| 20 |
MAIN_OVERLAY_FOOTER_SLOT_CLASS = 'read-book-main-overlay-footer-slot' |
| 21 |
MAIN_OVERLAY_FOOTER_MIDDLE_SLOT_CLASS = 'read-book-main-overlay-footer-middle-slot' |
| 22 |
MAIN_OVERLAY_FOOTER_RIGHT_SLOT_CLASS = 'read-book-main-overlay-footer-right-slot' |
| 23 |
MAIN_OVERLAY_ICON_SIZE = '3.5ex' |
| 24 |
|
| 25 |
|
| 26 |
def timer_id(): |
| 27 |
if not timer_id.ans: |
| 28 |
timer_id.ans = unique_id() |
| 29 |
return timer_id.ans |
| 30 |
|
| 31 |
|
| 32 |
def main_overlay_css(): |
| 33 |
style = '' |
| 34 |
colors = viewer_chrome_colors() |
| 35 |
border = 'var(--calibre-border-style-subtle)' |
| 36 |
hover_background = 'var(--calibre-color-primary-light)' |
| 37 |
active_background = 'var(--calibre-color-primary-light-2)' |
| 38 |
focus_outline = '1px solid ' + get_color('input-focus-outline-color') |
| 39 |
style += build_rule('.' + MAIN_OVERLAY_TS_CLASS, |
| 40 |
user_select='none', background_color=colors.background, color=colors.foreground) |
| 41 |
style += build_rule('.' + MAIN_OVERLAY_TOP_ROW_CLASS, |
| 42 |
display='flex', justify_content='space-between', align_items='baseline', |
| 43 |
font_size='smaller', padding='0.5ex 1ex', border_bottom=border) |
| 44 |
style += build_rule('.' + MAIN_OVERLAY_TITLE_CLASS, |
| 45 |
max_width='90%', text_overflow='ellipsis', font_weight='bold', |
| 46 |
white_space='nowrap', overflow='hidden') |
| 47 |
style += build_rule('.' + MAIN_OVERLAY_TIMER_CLASS, |
| 48 |
max_width='9%', white_space='nowrap', overflow='hidden') |
| 49 |
style += build_rule('.' + MAIN_OVERLAY_FOOTER_CLASS, |
| 50 |
position='fixed', width='100%', bottom='0', display='flex', |
| 51 |
justify_content='space-between', align_items='center', |
| 52 |
user_select='none', background_color=colors.background, color=colors.foreground) |
| 53 |
style += build_rule('.' + MAIN_OVERLAY_FOOTER_ACTIONS_CLASS, |
| 54 |
display='flex', justify_content='space-between', align_items='center') |
| 55 |
style += build_rule('.' + MAIN_OVERLAY_FOOTER_ACTION_CLASS, |
| 56 |
display='flex', align_items='center', cursor='pointer', padding='0.5ex 1rem', |
| 57 |
appearance='none', margin='0', border='0', color='inherit', |
| 58 |
background='transparent', font='inherit') |
| 59 |
style += build_rule('.' + MAIN_OVERLAY_FOOTER_ACTION_CLASS + ':focus', |
| 60 |
outline=focus_outline) |
| 61 |
style += build_rule('.' + MAIN_OVERLAY_FOOTER_ACTION_CLASS + ' > svg:first-child', margin_right='0.5ex') |
| 62 |
style += build_rule('.' + MAIN_OVERLAY_FOOTER_SLOT_CLASS, padding='0.5ex 1rem') |
| 63 |
sel = '.' + MAIN_OVERLAY_TS_CLASS + ' > .' + MAIN_OVERLAY_ACTIONS_CLASS + ' ' |
| 64 |
style += build_rule(sel, overflow='hidden') |
| 65 |
sel += '> ul ' |
| 66 |
style += build_rule(sel, display='flex', list_style='none', margin='0', padding='0', border_bottom=border) |
| 67 |
sel += '> li' |
| 68 |
style += build_rule(sel, border_right=border, display='flex') |
| 69 |
style += build_rule(sel + ':last-child', border_right_style='none') |
| 70 |
action_sel = sel + ' > .' + MAIN_OVERLAY_ACTION_CONTROL_CLASS |
| 71 |
style += build_rule(action_sel, |
| 72 |
display='flex', flex_wrap='wrap', align_items='center', cursor='pointer', |
| 73 |
appearance='none', margin='0', padding='0.5em 1ex', border='0', |
| 74 |
color='inherit', background='transparent', font='inherit', text_align='left') |
| 75 |
style += build_rule(action_sel + ':focus', |
| 76 |
outline=focus_outline) |
| 77 |
style += build_rule(action_sel + ' > .' + MAIN_OVERLAY_ACTION_ICON_CLASS + ':first-child', margin_right='0.5ex') |
| 78 |
style += build_rule('.' + MAIN_OVERLAY_TEXT_ICON_CLASS, font_size='175%', font_weight='bold') |
| 79 |
style += build_rule(action_sel + ':hover, .' + MAIN_OVERLAY_FOOTER_ACTION_CLASS + ':hover', |
| 80 |
background_color=hover_background) |
| 81 |
style += build_rule(action_sel + ':active, .' + MAIN_OVERLAY_FOOTER_ACTION_CLASS + ':active', |
| 82 |
background_color=active_background) |
| 83 |
style += f'@media screen and (max-width: 350px) {{ #{timer_id()} {{ display: none; }} }}' |
| 84 |
return style |
| 85 |
|
| 86 |
|
| 87 |
add_extra_css(main_overlay_css) |