# Path: vise/config.py
# def color(key, default):
#     ans = colors().get(key)
#     if not ans or ans == 'default':
#         ans = default
#     return ans
# 
# @lru_cache()
# def font_sizes():
#     uff = (load_config(user=True).get('fonts') or {}).get('sizes') or {}
#     dff = load_config(user=False)['fonts']['sizes']
#     sizes = {}
# 
#     def conv(x):
#         if x == 'default':
#             return 0
#         try:
#             return int(x)
#         except Exception:
#             pass
# 
#     def get_ff(x):
#         if isinstance(x, dict):
#             return conv(x.get(hostname) or x.get('*'))
#         return conv(x)
# 
#     for ftype, val in uff.items():
#         val = get_ff(val)
#         if isinstance(val, int):
#             sizes[ftype] = val
# 
#     for ftype, val in dff.items():
#         if ftype not in sizes:
#             val = get_ff(val)
#             if isinstance(val, int):
#                 sizes[ftype] = val
# 
#     return sizes
# 
# Path: vise/constants.py
# DOWNLOADS_URL = 'vise:downloads'
# WELCOME_URL = 'vise:welcome'
# STATUS_BAR_HEIGHT = 24
# FOLLOW_LINK_KEY_MAP = {getattr(Qt.Key, 'Key_' + x.upper()): x for x in string.ascii_lowercase + string.digits}
# VISE_SCHEME = 'vise'
# def _get_cache_dir():
# def _get_config_dir():
# def get_windows_username():
# def local_socket_address():
# 
# Path: vise/resources.py
# def get_data_as_file(name):
#     return open(get_data_as_path(name), 'rb')


import glob
import json
import os
import apsw
from base64 import standard_b64decode, standard_b64encode
from binascii import hexlify
from collections import defaultdict
from functools import lru_cache
from PyQt6.QtGui import QKeySequence
from PyQt6.QtWebEngineCore import (QWebEngineProfile, QWebEngineScript,
                                   QWebEngineSettings)
from PyQt6.QtWidgets import QApplication
from .config import color, font_sizes
from .constants import (DOWNLOADS_URL, VISE_SCHEME, appname, cache_dir,
                        config_dir)
from .resources import get_data_as_file
    from .url_intercept import Interceptor
    from .vise_scheme import UrlSchemeHandler
        from .downloads import download_requested
    from .config import font_families, font_sizes
        from .downloads import download_requested
    from .utils import safe_disconnect
        from .utils import parse_url
    if langs:
        ans.setSpellCheckEnabled(True)
        ans.setSpellCheckLanguages(langs)
    ua = ' '.join(x for x in ans.httpUserAgent().split() if 'QtWebEngine' not in x)
    ans.setHttpUserAgent(ua)
    ans.setUrlRequestInterceptor(Interceptor(ans))
    try:
        insert_scripts(ans, client_script())
    except FileNotFoundError as err:
        if '-client.js' in str(err):
            raise SystemExit('You need to compile the rapydscript parts of vise before running it. Install rapydscript-ng and run the build script')
        raise
    ans.url_handler = UrlSchemeHandler(ans)
    ans.installUrlSchemeHandler(VISE_SCHEME.encode('ascii'), ans.url_handler)
    s = ans.settings()
    s.setDefaultTextEncoding('utf-8')
    s.setAttribute(QWebEngineSettings.WebAttribute.FullScreenSupportEnabled, True)
    s.setAttribute(QWebEngineSettings.WebAttribute.LinksIncludedInFocusChain, False)
    s.setAttribute(QWebEngineSettings.WebAttribute.DnsPrefetchEnabled, True)
    for ftype, family in font_families().items():
        if not family:
            continue
        if ftype == 'default':
            s.setFontFamily(QWebEngineSettings.FontFamily.StandardFont, family)
        else:
            ftype = ftype.replace('-', '').capitalize().replace('serif', 'Serif') + 'Font'
            ftype = getattr(QWebEngineSettings.FontFamily, ftype, None)
            if ftype:
                s.setFontFamily(ftype, family)


# Path: vise/config.py
# def color(key, default):
#     ans = colors().get(key)
#     if not ans or ans == 'default':
#         ans = default
#     return ans
# 
# @lru_cache()
# def font_sizes():
#     uff = (load_config(user=True).get('fonts') or {}).get('sizes') or {}
#     dff = load_config(user=False)['fonts']['sizes']
#     sizes = {}
# 
#     def conv(x):
#         if x == 'default':
#             return 0
#         try:
#             return int(x)
#         except Exception:
#             pass
# 
#     def get_ff(x):
#         if isinstance(x, dict):
#             return conv(x.get(hostname) or x.get('*'))
#         return conv(x)
# 
#     for ftype, val in uff.items():
#         val = get_ff(val)
#         if isinstance(val, int):
#             sizes[ftype] = val
# 
#     for ftype, val in dff.items():
#         if ftype not in sizes:
#             val = get_ff(val)
#             if isinstance(val, int):
#                 sizes[ftype] = val
# 
#     return sizes
# 
# Path: vise/constants.py
# DOWNLOADS_URL = 'vise:downloads'
# WELCOME_URL = 'vise:welcome'
# STATUS_BAR_HEIGHT = 24
# FOLLOW_LINK_KEY_MAP = {getattr(Qt.Key, 'Key_' + x.upper()): x for x in string.ascii_lowercase + string.digits}
# VISE_SCHEME = 'vise'
# def _get_cache_dir():
# def _get_config_dir():
# def get_windows_username():
# def local_socket_address():
# 
# Path: vise/resources.py
# def get_data_as_file(name):
#     return open(get_data_as_path(name), 'rb')


# Path: vise/settings.py
import glob
import json
import os
import apsw
from base64 import standard_b64decode, standard_b64encode
from binascii import hexlify
from collections import defaultdict
from functools import lru_cache
from PyQt6.QtGui import QKeySequence
from PyQt6.QtWebEngineCore import (QWebEngineProfile, QWebEngineScript,
                                   QWebEngineSettings)
from PyQt6.QtWidgets import QApplication
from .config import color, font_sizes
from .constants import (DOWNLOADS_URL, VISE_SCHEME, appname, cache_dir,
                        config_dir)
from .resources import get_data_as_file
    from .url_intercept import Interceptor
    from .vise_scheme import UrlSchemeHandler
        from .downloads import download_requested
    from .config import font_families, font_sizes
        from .downloads import download_requested
    from .utils import safe_disconnect
        from .utils import parse_url

    if langs:
        ans.setSpellCheckEnabled(True)
        ans.setSpellCheckLanguages(langs)
    ua = ' '.join(x for x in ans.httpUserAgent().split() if 'QtWebEngine' not in x)
    ans.setHttpUserAgent(ua)
    ans.setUrlRequestInterceptor(Interceptor(ans))
    try:
        insert_scripts(ans, client_script())
    except FileNotFoundError as err:
        if '-client.js' in str(err):
            raise SystemExit('You need to compile the rapydscript parts of vise before running it. Install rapydscript-ng and run the build script')
        raise
    ans.url_handler = UrlSchemeHandler(ans)
    ans.installUrlSchemeHandler(VISE_SCHEME.encode('ascii'), ans.url_handler)
    s = ans.settings()
    s.setDefaultTextEncoding('utf-8')
    s.setAttribute(QWebEngineSettings.WebAttribute.FullScreenSupportEnabled, True)
    s.setAttribute(QWebEngineSettings.WebAttribute.LinksIncludedInFocusChain, False)
    s.setAttribute(QWebEngineSettings.WebAttribute.DnsPrefetchEnabled, True)
    for ftype, family in font_families().items():
        if not family:
            continue
        if ftype == 'default':
            s.setFontFamily(QWebEngineSettings.FontFamily.StandardFont, family)
        else:
            ftype = ftype.replace('-', '').capitalize().replace('serif', 'Serif') + 'Font'
            ftype = getattr(QWebEngineSettings.FontFamily, ftype, None)
            if ftype:
                s.setFontFamily(ftype, family)


    for ftype, sz in font_sizes().items():