a
    Dfz=                     @  sz  d dl mZ d dlZd dlZd dlZd dlmZmZmZm	Z	m
Z
mZmZmZ d dlZd dlmZ d dlmZmZmZ ddlmZ ddlmZmZmZmZmZ dd	lmZ erd d
lm Z  d dl!m"Z" ddlm#Z# ddl$m%Z% G dd dZ&G dd dej'Ze(ej)Z*e*d d +ddd e,e-j.d Z/G dd deZ0G dd deZ1G dd dej'eZ2e2ejj3_4e0e1dZ5dS )    )annotationsN)TYPE_CHECKINGAnyClassVarDictListLiteralTupleType)ImportedStyleSheet)Theme_dark_minimalbuilt_in_themes   )config)
JS_VERSIONResourceComponentcomponent_resource_pathget_dist_pathresolve_custom_path)relative_to)Document)Model)ResourceTypes)Viewablec                   @  s   e Zd ZdZdS )Inheritz=
    Singleton object to declare stylesheet inheritance.
    N)__name__
__module____qualname____doc__ r    r    ]/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/panel/theme/base.pyr      s   r   c                   @  sJ   e Zd ZU dZejddZejee	fdddZ
ejddZi Zded	< dS )
r   z
    Theme objects declare the styles to switch between different color
    modes. Each `Design` may declare any number of color themes.

    `modifiers`
       The modifiers override parameter values of Panel components.
    z
        A stylesheet declaring the base variables that define the color
        scheme. By default this is inherited from a base class.)docNz
        A Bokeh Theme class that declares properties to apply to Bokeh
        models. This is necessary to ensure that plots and other canvas
        based components are styled appropriately.)class_defaultr"   z
       A stylesheet that overrides variables specifically for the
       Theme subclass. In most cases, this is not necessary.(ClassVar[Dict[Viewable, Dict[str, Any]]]	modifiers)r   r   r   r   paramFilenamebase_cssClassSelector_BkThemestrbokeh_themecssr&   __annotations__r    r    r    r!   r   %   s
   
r   attrsZPlotz#2b3035z#212529)Zbackground_fill_colorZborder_fill_colorr.   c                   @  s.   e Zd ZU dZejed dZdZde	d< dS )DefaultThemez0
    Baseclass for default or light themes.
    zdefault.cssr$   r$   ClassVar[str]_nameN)
r   r   r   r   r'   r(   	THEME_CSSr)   r4   r/   r    r    r    r!   r1   G   s   
r1   c                   @  sF   e Zd ZU dZejed dZeje	e
fe	eddZdZded< d	S )
	DarkThemez$
    Baseclass for dark themes.
    zdark.cssr2   )json)r#   r$   darkr3   r4   N)r   r   r   r   r'   r(   r5   r)   r*   r+   r,   
BOKEH_DARKr-   r4   r/   r    r    r    r!   r6   Q   s   

r6   c                      sP  e Zd ZU ejeddZi Zded< i Z	ded< e
edZded	< d< fdd	Zd=ddddddddZd>dddddddZdd Zedd Zeejdd Zed?ddddd d!Zed"d# Zei d
fdd$dddd%d&d'Zed@d(d)ZdAdddd*d+d,ZdBdd-d.d/ZdCd1d2dd3d4 fd5d6ZdDdd7d8d9d:d;Z  ZS )EDesignT)r#   Zconstantr%   r&   z#ClassVar[Dict[str, Dict[str, str]]]
_resourcesr$   r8   z ClassVar[Dict[str, Type[Theme]]]_themesNc                   sN   t |trt|tr|j}n|d u r(d}| j|  }t jf d|i| d S )Nr$   theme)
isinstancetype
issubclassr   r4   r=   super__init__)selfr>   params	__class__r    r!   rC   n   s    zDesign.__init__r   r   zList[Model]boolNone)viewableroot
old_modelsisolatedreturnc           	   	   C  sr   |j d }| D ]Z}|jr$|s$qn|js4|s4| |_|rV||jv rV|j| d |v rVq| ||| j||| qd S )Nidr   )refselectdesignZ_design_models_apply_modifiersr>   )	rD   rJ   rK   rL   rM   cachedocumentrP   or    r    r!   _reapplyv   s    


zDesign._reapply)rJ   rK   changedrN   c              	   C  s~   ddl m} |j|jv r&|j|j }ni  |j|j< }|jj ( | j|||d||jd W d    n1 sp0    Y  d S )Nr   stateF)rM   rU   rV   )io.stater[   rV   _stylesheetsmodelsfreezerX   )rD   rJ   rK   rY   rL   r[   rU   r    r    r!   _apply_hooks   s    zDesign._apply_hooksc                 C  s   |S Nr    )rD   rJ   r    r    r!   _wrapper   s    zDesign._wrapperc                 C  sH   ddl m} g }|D ].}|tu r,|| q|||d}|| q|S )Nr   )resolve_stylesheetr&   )io.resourcesrc   r   extendappend)clsvalueZdefining_clsZ	inheritedrc   stylesheets
stylesheetZresolvedr    r    r!   _resolve_stylesheets   s    
zDesign._resolve_stylesheetsc           
      C  s   i i  }}|j ddd D ]}| j|i }||j|i  | j ddd D ]t}t|di |i }| D ]@\}}	|dkrqpqp|dkr| |	|||g ||< qp|	||< qp||di  qPq||fS )z
        Iterate over the class hierarchy in reverse order and accumulate
        all modifiers that apply to the objects class and its super classes.
        Nr&   childrenri   )__mro__r&   getupdategetattritemsrk   )
rg   vtyper>   r&   child_modifiersZsclsZcls_modifiersZ	super_clsproprh   r    r    r!   _resolve_modifiers   s    

zDesign._resolve_modifiersr   )rJ   r>   rM   c                 C  s   ddl m}m}m} | t||\}}t|}d|v r|rt| j	di 
 }	dD ]t}
t||
}|d u rnqVt|}t|tr|	| d|j  qV|||r|	|||
| qV|	|jdd qVng }	|	|d  |d< ||fS )	Nr   )CDN_DISTr   r   ri   r.   r)   r.   bundled/theme/zutf-8)encoding)rd   rw   r   r   rv   r@   dictlistr;   ro   valuesrq   pathlibPathr   r5   rf   name	read_text)rg   rJ   r>   rM   rw   r   r   r&   rt   prepr.   r    r    r!   _get_modifiers   s&    



zDesign._get_modifiersc                 C  sl   d|v rhg }|d D ]J}| drT|r8||v r8|| }nt|d}|d urT|||j< || q||d< d S )Nri   z.css)url)endswithr   r   rf   )rg   r"   r&   rU   ri   stsr    r    r!   _patch_modifiers   s    



zDesign._patch_modifiersr,   )rJ   mrefr>   rM   rN   c                 C  sx   ||j vrd S |j | \}}| |||\}	}
| |jp:||	| |
r`|D ]}| |||
| qJ|	rt| |||	| d S ra   )rS   r   r   rV   _apply_params)rg   rJ   r   r>   rM   rU   rV   model_r&   rt   childr    r    r!   rT      s    
zDesign._apply_modifiersc                   s  ddl m}m} | jvrd S  j| \}} fdd| D }	d|v r\|d  j |	d<  |	}
|jpn|}|rd|jv r|jd }n|}|
	dg D ]}t
|tr||| qd|
v rlt|jt|
d krld}g }t|j|
d D ]f\}}||kr|| qn8t|t|u rFt
|trF|j|jkrF|| q|| d}q|rd|
d= n||
d< |jf i |
 t d	rd
 jv rֈ jd
 } fdd|	 D }t||D ]}|jf i | qd S )Nr   )rw   patch_stylesheetc                   s4   i | ],\}}|d krt  | j| jkr||qS )rm   )rq   r'   r$   ).0kvrJ   r    r!   
<dictcomp>   s   z(Design._apply_params.<locals>.<dictcomp>ri   dist_urlTF_synced_propertiesZobjectsc                   s    i | ]\}}| j v r||qS r    )r   )r   r   r   r   r    r!   r   !  s   )rd   rw   r   rS   rr   ri   Z_process_param_changerV   Z_template_variablesro   r?   r   lenziprf   r@   r   rp   hasattrZ_property_mappingrq   )rg   rJ   r   r&   rV   rw   r   r   r   rE   propsr"   r   rj   Z	all_matchri   Zst1Zst2Zobj_keyZchild_propsr   r    r   r!   r      sP    




"

,



zDesign._apply_params)rJ   rK   rM   c                 C  s   |j }|s| j|||d dS ddlm} ||jv r@|j| }ni  |j|< }|j > | j||||d | jr| jjr|r| jj|_W d   n1 s0    Y  dS )a  
        Applies the Design to a Viewable and all it children.

        Arguments
        ---------
        viewable: Viewable
            The Viewable to apply the Design to.
        root: Model
            The root Bokeh model to apply the Design to.
        isolated: bool
            Whether the Design is applied to an individual component
            or embedded in a template that ensures the resources,
            such as CSS variable definitions and JS are already
            initialized.
        )rM   Nr   rZ   )rM   rU   )	rV   rX   r\   r[   r]   r^   r_   r>   r-   )rD   rJ   rK   rM   r"   r[   rU   r    r    r!   apply+  s    
zDesign.apply)r   c                 C  sD   |p
| j j}t|tr t|}|s(dS | D ]}|| q0dS )a  
        Applies the Bokeh theme associated with this Design system
        to a model.

        Arguments
        ---------
        model: bokeh.model.Model
            The Model to apply the theme on.
        theme_override: str | None
            A different theme to apply.
        N)r>   r-   r?   r,   r   ro   Z
referencesZapply_to_model)rD   r   Ztheme_overrider>   smr    r    r!   apply_bokeh_theme_to_modelJ  s    

z!Design.apply_bokeh_theme_to_modelautozbool | Literal['auto']z dict[str, dict[str, str]] | Noner   )cdnextrasinclude_themerN   c                   s   t  j||d}|s|S t|d}dt }|d }| j}dD ]}	t||	d}
|
du rXq>tj|
}d|	v rpdnd	}t	|
t
r|d
| |  ||< q>t||
r>t|j|	 j}t||	|
||< q>|S )a  
        Resolves the resources required for this design component.

        Arguments
        ---------
        cdn: bool | Literal['auto']
            Whether to load resources from CDN or local server. If set
            to 'auto' value will be automatically determine based on
            global settings.
        extras: dict[str, dict[str, str]] | None
            Additional resources to add to the bundle. Valid resource
            types include js, js_modules and css.
        include_theme: bool
            Whether to include theme resources.

        Returns
        -------
        Dictionary containing JS and CSS resources.
        )r   r   )r   z?v=r.   rx   NbaseZ
theme_baser>   ry   )rB   resolve_resourcesr   r   r>   rq   ospathbasenamer   r5   r   r@   r'   ownerr   )rD   r   r   r   Zresource_types	dist_pathZversion_suffixZ	css_filesr>   attrr.   r   keyr   rF   r    r!   r   ^  s&    



zDesign.resolve_resourceszDocument | Nonez%Tuple[Dict[str, Any], Dict[str, Any]])rJ   r"   rN   c                 C  sh   ddl m} |du ri }n$||jv r0|j| }ni  |j|< }| j|| jd\}}| ||| ||fS )ae  
        Provides parameter values to apply the provided Viewable.

        Arguments
        ---------
        viewable: Viewable
            The Viewable to return modifiers for.
        doc: Document | None
            Document the Viewable will be rendered into. Useful
            for caching any stylesheets that are created.

        Returns
        -------
        modifiers: Dict[str, Any]
            Dictionary of parameter values to apply to the Viewable.
        child_modifiers: Dict[str, Any]
            Dictionary of parameter values to apply to the children
            of the Viewable.
        r   rZ   N)r>   )r\   r[   r]   r   r>   r   )rD   rJ   r"   r[   rU   r&   rt   r    r    r!   rE     s    
zDesign.params)N)NTNN)N)NT)N)T)N)r   NT)N)r   r   r   r'   r*   r   r>   r&   r/   r;   r1   r6   r=   rC   rX   r`   rb   classmethodrk   	functools	lru_cacherv   r   r   rT   r   r   r   r   rE   __classcell__r    r    rF   r!   r:   ^   sF   
	  	
 
:   . r:   r<   )6
__future__r   r   r   r~   typingr   r   r   r   r   r   r	   r
   r'   Zbokeh.modelsr   Zbokeh.themesr   r+   r   r   r   rd   r   r   r   r   r   utilr   Zbokeh.documentr   Zbokeh.modelr   r   rJ   r   r   ZParameterizedr{   r7   r9   rp   r   __file__parentr5   r1   r6   r:   rR   r#   ZTHEMESr    r    r    r!   <module>   s@   (

  Q
