o
    ,&]i                     @  sb   d dl mZ d dlmZ d dlmZ d dlmZ er d dlm	Z	 dddZ
dddZdddZdS )    )annotations)TYPE_CHECKING)StreamlitAPIException)is_url)CustomThemeConfigfont_config
str | Noneproperty_namestrreturntuple[str, str | None]c                 C  s   | sdS |   } d| vr| dfS | dd\}}|  }|  }|d}|dkr1td| dt|}|rA|sAtd| d	|rG||fS |dfS )
ai  Parse a single font configuration string.

    Args:
        font_config: The font configuration string (e.g., "Inter" or "Inter:https://...")
        property_name: The property name for error messages ("font", "codeFont", "headingFont")

    Returns
    -------
        A tuple of (font_name, source_url). source_url is None if not provided or not valid.
    ) N:N   zfamily=z The source URL specified in the za property of config.toml contains multiple fonts. Please specify only one font in the source URL.zDA font family name is required when specifying a source URL for the z property in config.toml.)stripsplitcountr   r   )r   r	   	font_name
source_urlfamily_occurrencesis_valid_url r   Z/var/www/html/IGF-ODF-V3/venv/lib/python3.10/site-packages/streamlit/runtime/theme_util.py_parse_font_config   s.   

r   sectionc                 C  s   |dkr| S |  dS )zGet the config name for font sources based on property and section. This is used on the FE
    as the id for the font source link in the html head.
    themez-sidebarr   )r	   r   r   r   r   _get_font_source_config_nameQ   s   
r   msgr   body_font_configcode_font_configheading_font_configc                 C  s   t |d\}}|r|| _|rtd|}| jj||d t |d\}}	|r'|| _|	r6td|}| jj||	d t |d\}
}|
rB|
| _|rQtd|}| jj||d | S )a  Populate the CustomThemeConfig message with the font, codeFont, and headingFont fields set,
    as well as the font_sources field to be added to the html head.

    Args:
        msg: CustomThemeConfig message to be populated.
        body_font_config: A string with just the font name (e.g., "Inter") or in the format
            "<font_family_name_here>:<source_url_here>".
        code_font_config: A string with just the font name (e.g., "Roboto Mono") or in the format
            "<code_font_family_name_here>:<source_url_here>".
        heading_font_config: A string with just the font name (e.g., "Inter Bold") or in the format
            "<heading_font_family_name_here>:<source_url_here>".
        section: The section of the config.toml file to parse the fonts from.

    Examples
    --------
    body_font_config: "Inter" (just font name)
    code_font_config: "Tagesschrift:https://fonts.googleapis.com/css2?family=Tagesschrift&display=swap" (with source)
    heading_font_config: "playwrite-cc-za:https://use.typekit.net/xxs7euo.css"

    Returns
    -------
        Updated CustomThemeConfig message with the font, codeFont, and headingFont fields set.
        Also sets sources in font_sources field to be added to the html (only when source URLs are provided).
    font)config_namer   codeFontheadingFont)r   	body_fontr   font_sourcesadd	code_fontheading_font)r   r   r   r    r   body_font_namebody_font_sourcer"   code_font_namecode_font_sourceheading_font_nameheading_font_sourcer   r   r   parse_fonts_with_sourceZ   s*   !


r0   N)r   r   r	   r
   r   r   )r	   r
   r   r
   r   r
   )r   r   r   r   r   r   r    r   r   r
   r   r   )
__future__r   typingr   streamlit.errorsr   streamlit.url_utilr   streamlit.proto.NewSession_pb2r   r   r   r0   r   r   r   r   <module>   s   

6	