
    4i~                        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	Zy
)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)BidiComponentManagerc                   
 | j                        
	 	 	 	 	 	 d
fd} ||d      \  }} ||d      \  }}	t        |||||	      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>``.
    c                  | yt        j                  |       r| d fS t        d d| d      | }t        j                  |      rt        j                  |      }t        j
                  ||       t        |j                         j                  j                               j                               }t        |      |fS t        j                  |       t        |      z  }t        j
                  ||       |j                         }t        |j                  j                               j                               }t        |      |fS )N)NNzComponent 'zG' must be declared in pyproject.toml with asset_dir to use file-backed .kind)r   looks_like_inline_contentr   has_glob_charactersresolve_glob_patternensure_within_rootstrresolverelative_toas_posixvalidate_path_securityr   )	valuer   	value_strresolvedrel_url	candidateresolved_candidate
asset_rootcomponent_keys	          /home/obispo/Crisostomo_bridge/mision_env/lib/python3.12/site-packages/streamlit/components/v2/component_definition_resolver.py_resolve_entryz8build_definition_with_validation.<locals>._resolve_entry`   sI    =77>$; 'm_ -&&*V1. 
 	 11)<)>>y*UH11(JTR  "..z/A/A/CDMMOG x=')) 	11)<i0	--i$O&..0(44Z5G5G5IJSSUV%&//    cssr   js)namehtmlr#   r$   css_asset_relative_pathjs_asset_relative_path)r   
str | Noner   r   returnztuple[str | None, str | None])get_component_asset_rootr   )managerr   r&   r#   r$   r!   	css_valuecss_reljs_valuejs_relr   s    `        @r     build_definition_with_validationr1   $   sy    t 11-@J"0"0$'"0	&"0H (%8Iw%bt4Hf # '% r"   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	   r1    r"   r    <module>r;      sj    #    K N 2Nk!k k 	k
 
k 	k kr"   