o
    h`                     @  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 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)CustomComponent)get_instance)get_script_run_ctx)	FrameType)BaseComponentRegistrycaller_framer   returnstrc                 C  sN   t | }|d usJ |j}|dkr%t | }tj|}tj|\}}|S )N__main__)inspect	getmodule__name__getfileospathbasenamesplitext)r
   modulemodule_name	file_pathfilename_ r   ^/var/www/vscode/kcb/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sJ |j}|dus J t|}| d|  }t||||d}t }|durAt	 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, but not both.

    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, but not both.

    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.

    N.)r   r   r    r   )
isinstancer   r   r   currentframef_backr   r   r   r   component_registryregister_component)	r   r   r    current_framer
   r   component_name	componentctxr   r   r   declare_component3   s   +r,   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__classmethodr/   r   r   r   r   r-   }   s    r-   )r
   r   r   r   )NN)r   r   r   r   r    r!   r   r   )
__future__r   r   r   pathlibr   typingr   (streamlit.components.v1.custom_componentr   streamlit.runtimer   7streamlit.runtime.scriptrunner_utils.script_run_contextr   typesr   2streamlit.components.types.base_component_registryr	   r   r,   r-   r   r   r   r   <module>   s    
J