
    g`                        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
Z	 	 d	 	 	 	 	 	 	 ddZ G d d      Zy)    )annotationsN)Path)TYPE_CHECKING)CustomComponent)get_instance)get_script_run_ctx)	FrameType)BaseComponentRegistryc                   t        j                  |       }|J |j                  }|dk(  rVt        j                  |       }t        j
                  j                  |      }t        j
                  j                  |      \  }}|S )N__main__)inspect	getmodule__name__getfileospathbasenamesplitext)caller_framemodulemodule_name	file_pathfilename_s         _/var/www/openai/venv/lib/python3.12/site-packages/streamlit/components/v1/component_registry.py_get_module_namer       ss     |,F//K j OOL1	77##I.))(3Q    c                0   |t        |t              rt        |      }t        j                         }|J |j
                  }|J t        |      }| d|  }t        ||||      }t               }|#t               j                  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.

    .)namer   urlr   )
isinstancer   strr   currentframef_backr   r   r   r   component_registryregister_component)	r    r   r!   current_framer   r   component_name	componentctxs	            r   declare_componentr,   3   s    V JtT24y '.&:&:&<M$$$ ''L###"<0K $}AdV,N  $C[I 
C
))<<YGr   c                      e Zd Zedd       Zy)ComponentRegistryc                *    t               j                  S )z6Returns the ComponentRegistry of the runtime instance.)r   r&   )clss    r   instancezComponentRegistry.instance~   s     ~000r   N)returnr
   )r   
__module____qualname__classmethodr1    r   r   r.   r.   }   s    1 1r   r.   )r   r	   r2   r#   )NN)r    r#   r   zstr | Path | Noner!   z
str | Noner2   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.   r6   r   r   <module>r?      sn    #  	    D * VX* #A
A
A 
A 	AT1 1r   