o
    Yh"                     @  s   d dl mZ d dlZd dlZd dlmZ d dlmZmZm	Z	 d dl
mZ d dlmZmZmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZmZmZ erXd dlmZ G dd dZdddZ dddZ!dS )    )annotationsN)Path)TYPE_CHECKINGAnycast)get_dg_singleton_instance)LayoutConfigWidthvalidate_width)StreamlitAPIException)Html)gather_metrics)
clean_text)SupportsReprHtmlSupportsStrhas_callable_attr)DeltaGeneratorc                   @  s@   e Zd Zeddddd
dZedddZedddZdS )	HtmlMixinhtmlstretchwidthbody+str | Path | SupportsStr | SupportsReprHtmlr   r	   returnr   c                C  s   t  }t|drtd| }n>t|tst|rGt|}t|dd}|	 }W d   n1 s2w   Y  t|j
 dkrFd| d}nttd	|}|d
krVtdt|dd t|d}t|ro||_| jd|S ||_| jjd||dS )a	  Insert HTML into your app.

        Adding custom HTML to your app impacts safety, styling, and
        maintainability. We sanitize HTML with `DOMPurify
        <https://github.com/cure53/DOMPurify>`_, but inserting HTML remains a
        developer risk. Passing untrusted code to ``st.html`` or dynamically
        loading external code can increase the risk of vulnerabilities in your
        app.

        ``st.html`` content is **not** iframed. Executing JavaScript is not
        supported at this time.

        Parameters
        ----------
        body : any
            The HTML code to insert. This can be one of the following:

            - A string of HTML code.
            - A path to a local file with HTML code. The path can be a ``str``
              or ``Path`` object. Paths can be absolute or relative to the
              working directory (where you execute ``streamlit run``).
            - Any object. If ``body`` is not a string or path, Streamlit will
              convert the object to a string. ``body._repr_html_()`` takes
              precedence over ``str(body)`` when available.

            If the resulting HTML content is empty, Streamlit will raise an
            error.

            If ``body`` is a path to a CSS file, Streamlit will wrap the CSS
            content in ``<style>`` tags automatically. When the resulting HTML
            content only contains style tags, Streamlit will send the content
            to the event container instead of the main container to avoid
            taking up space in the app.

        width : "stretch", "content", or int
            The width of the HTML element. This can be one of the following:

            - ``"stretch"`` (default): The width of the element matches the
              width of the parent container.
            - ``"content"``: The width of the element matches the width of its
              content, but doesn't exceed the width of the parent container.
            - An integer specifying the width in pixels: The element has a
              fixed width. If the specified width is greater than the width of
              the parent container, the width of the element matches the width
              of the parent container.

        Example
        -------
        >>> import streamlit as st
        >>>
        >>> st.html(
        ...     "<p><span style='text-decoration: line-through double red;'>Oops</span>!</p>"
        ... )

        .. output::
           https://doc-html.streamlit.app/
           height: 300px

        _repr_html_r   zutf-8)encodingNz.cssz<style>z</style>r    z`st.html` body cannot be emptyT)allow_contentr   r   )layout_config)	HtmlProtor   r   r   
isinstancer   _is_filestropenreadsuffixlowerr   r   r
   r   _html_only_style_tagsr   	_event_dg_enqueuedg)selfr   r   
html_protohtml_content	file_pathfr    r1   X/var/www/html/Persson_Maskin/env/lib/python3.10/site-packages/streamlit/elements/html.pyr   '   s*   B


zHtmlMixin.htmlc                 C  s
   t d| S )zGet our DeltaGenerator.r   )r   r,   r1   r1   r2   r+      s   
zHtmlMixin.dgc                 C  s   t  jS )zGet the event delta generator.)r   event_dgr3   r1   r1   r2   r)      s   zHtmlMixin._event_dgN)r   r   r   r	   r   r   )r   r   )__name__
__module____qualname__r   r   propertyr+   r)   r1   r1   r1   r2   r   &   s    fr   r.   r#   r   boolc                 C  sB   d}d}t j|d| t jd}t j|d|t jt jB d}| dkS )z-Check if the HTML content is only style tags.z
<!--.*?-->z<style[^>]*>.*?</style>r   )flags)resubDOTALL
IGNORECASEstrip)r.   comment_patternstyle_patternhtml_without_comments html_without_styles_and_commentsr1   r1   r2   r(      s   r(   objr   c                 C  s$   zt j| W S  ty   Y dS w )zbChecks if obj is a file, and doesn't throw if not.

    The "not throwing" part is important!
    F)ospathisfile	TypeError)rD   r1   r1   r2   r"      s
   r"   )r.   r#   r   r9   )rD   r   r   r9   )"
__future__r   rE   r;   pathlibr   typingr   r   r   $streamlit.delta_generator_singletonsr   #streamlit.elements.lib.layout_utilsr   r	   r
   streamlit.errorsr   streamlit.proto.Html_pb2r   r    streamlit.runtime.metrics_utilr   streamlit.string_utilr   streamlit.type_utilr   r   r   streamlit.delta_generatorr   r   r(   r"   r1   r1   r1   r2   <module>   s"   
s