o
    ,&]i~                     @  sj   d 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dZdS )aG  Shared resolver for building component definitions with path validation.

This module centralizes the logic for interpreting js/css inputs as inline
content vs path/glob strings, validating them against a component's asset
directory, and producing a BidiComponentDefinition with correct asset-relative
URLs used by the server.
    )annotations)Path)TYPE_CHECKING)ComponentPathUtils)BidiComponentDefinition)StreamlitAPIException)BidiComponentManagermanagerr   component_keystrhtml
str | Nonecssjsreturnr   c           
        sN   |   d fdd}||d	d
\}}||dd
\}}	t|||||	dS )aW  Construct a definition and validate ``js``/``css`` inputs against ``asset_dir``.

    Parameters
    ----------
    manager : BidiComponentManager
        Component manager used to resolve the component's ``asset_dir`` and
        related metadata.
    component_key : str
        Fully-qualified name of the component to build a definition for.
    html : str | None
        Inline HTML content to include in the definition. If ``None``, the
        component will not include HTML content.
    css : str | None
        Either inline CSS content or a path/glob to a CSS file inside the
        component's ``asset_dir``. Inline strings are kept as-is; file-backed
        inputs are validated and converted to an ``asset_dir``-relative URL.
    js : str | None
        Either inline JavaScript content or a path/glob to a JS file inside the
        component's ``asset_dir``. Inline strings are kept as-is; file-backed
        inputs are validated and converted to an ``asset_dir``-relative URL.

    Returns
    -------
    BidiComponentDefinition
        A component definition with inline content preserved and file-backed
        entries resolved to absolute filesystem paths plus their
        ``asset_dir``-relative URLs.

    Raises
    ------
    StreamlitAPIException
        If a path/glob is provided but the component has no declared
        ``asset_dir``, if a glob resolves to zero or multiple files, or if any
        resolved path escapes the declared ``asset_dir``.

    Notes
    -----
    - Inline strings are treated as content (no manifest required).
    - Path-like strings require the component to be declared in the package
      manifest with an ``asset_dir``.
    - Globs are supported only within ``asset_dir`` and must resolve to exactly
      one file.
    - Relative paths are resolved strictly against the component's ``asset_dir``
      and must remain within it after resolution. Absolute paths are not
      allowed.
    - For file-backed entries, the URL sent to the frontend is the
      ``asset_dir``-relative path, served under
      ``/_stcore/bidi-components/<component>/<relative_path>``.
    valuer   kindr   r   tuple[str | None, str | None]c                  s   | d u rdS t | r| d fS  d u rtd d| d| }t |rFt | }t j| |d t|   	 }t||fS t 
|  t| }t j| |d | }t|  	 }t||fS )N)NNzComponent 'zG' must be declared in pyproject.toml with asset_dir to use file-backed .r   )r   looks_like_inline_contentr   has_glob_charactersresolve_glob_patternensure_within_rootr   resolverelative_toas_posixvalidate_path_securityr   )r   r   	value_strresolvedrel_url	candidateresolved_candidate
asset_rootr
    s/var/www/html/IGF-ODF-V3/venv/lib/python3.10/site-packages/streamlit/components/v2/component_definition_resolver.py_resolve_entry`   s0   


z8build_definition_with_validation.<locals>._resolve_entryr   r   r   )namer   r   r   css_asset_relative_pathjs_asset_relative_pathN)r   r   r   r   r   r   )get_component_asset_rootr   )
r	   r
   r   r   r   r'   	css_valuecss_reljs_valuejs_relr%   r#   r&    build_definition_with_validation$   s   
:$r0   N)r	   r   r
   r   r   r   r   r   r   r   r   r   )__doc__
__future__r   pathlibr   typingr   ,streamlit.components.v2.component_path_utilsr   *streamlit.components.v2.component_registryr   streamlit.errorsr   )streamlit.components.v2.component_managerr   r0   r%   r%   r%   r&   <module>   s   