o
    Yhm                     @  s   d dl mZ d dlZd dl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 d dlmZ er@d d	lmZ d d
lmZ dddZ		ddddZG dd dZdS )    )annotationsN)Path)TYPE_CHECKING)config)CustomComponent)get_instance)get_script_run_ctx)	FrameType)BaseComponentRegistrycaller_framer	   returnstrc                 C  sR   t | }|d u rtd|j}|dkr't | }tj|}tj|\}}|S )Nz)module is None. This should never happen.__main__)	inspect	getmoduleRuntimeError__name__getfileospathbasenamesplitext)r   modulemodule_name	file_pathfilename_ r   k/var/www/html/Persson_Maskin/env/lib/python3.10/site-packages/streamlit/components/v1/component_registry.py_get_module_name!   s   

r   namer   str | Path | Noneurl
str | Noner   c           
      C  s   |durt |trt|}t }|du rtd|j}|du r$tdt|}| d|  }|s@t	d }r@| d| d}t
||||d}t }	|	durVt j| |S )a  Create a custom component and register it if there is a ``ScriptRunContext``.

    The component is not registered when there is no ``ScriptRunContext``.
    This can happen when a ``CustomComponent`` is executed as standalone
    command (e.g. for testing).

    To use this function, import it from the ``streamlit.components.v1``
    module.

    .. warning::
        Using ``st.components.v1.declare_component`` directly (instead of
        importing its module) is deprecated and will be disallowed in a later
        version.

    Parameters
    ----------
    name : str
        A short, descriptive name for the component, like "slider".

    path: str, Path, or None
        The path to serve the component's frontend files from. The path should
        be absolute. If ``path`` is ``None`` (default), Streamlit will serve
        the component from the location in ``url``. Either ``path`` or ``url``
        must be specified. If both are specified, then ``url`` will take
        precedence.

    url: str or None
        The URL that the component is served from. If ``url`` is ``None``
        (default), Streamlit will serve the component from the location in
        ``path``. Either ``path`` or ``url`` must be specified. If both are
        specified, then ``url`` will take precedence.


    Returns
    -------
    CustomComponent
        A ``CustomComponent`` that can be called like a function.
        Calling the component will create a new instance of the component
        in the Streamlit app.

    Nz0current_frame is None. This should never happen.z/caller_frame is None. This should never happen..z!server.customComponentBaseUrlPath/)r    r   r"   r   )
isinstancer   r   r   currentframer   f_backr   r   
get_optionr   r   r   component_registryregister_component)
r    r   r"   current_framer   r   component_namecomponent_base_path	componentctxr   r   r   declare_component5   s*   .r1   c                   @  s   e Zd ZedddZdS )ComponentRegistryr   r
   c                 C  s   t  jS )z6Returns the ComponentRegistry of the runtime instance.)r   r*   )clsr   r   r   instance   s   zComponentRegistry.instanceN)r   r
   )r   
__module____qualname__classmethodr4   r   r   r   r   r2      s    r2   )r   r	   r   r   )NN)r    r   r   r!   r"   r#   r   r   )
__future__r   r   r   pathlibr   typingr   	streamlitr   (streamlit.components.v1.custom_componentr   streamlit.runtimer   7streamlit.runtime.scriptrunner_utils.script_run_contextr   typesr	   2streamlit.components.types.base_component_registryr
   r   r1   r2   r   r   r   r   <module>   s"   
Y