
    e                       U d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	m
Z
 ddlmZmZmZmZmZmZmZmZmZ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#m"Z"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.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6 ddl7m8Z8 ddl9m:Z:m;Z; ddl<m=Z=m>Z>m?Z? ddl@mAZA ddlBmCZCmDZDmEZEmFZG ddlHmIZI ddlJmKZK ddlLmMZMmNZNmOZOmPZP ddlQmRZR ddlSmTZTmUZUmVZVmWZW ddlXmYZY ddlZm[Z[m\Z\ er$ddl]m^Z^ ddl_m`Z` dd lmaZb dd!lmcZc dd"ldmeZe dd#l-mfZf d$Zgd%ehd&<   d'Zid%ehd(<    G d) d*ejj        eTeVe0          Zk G d+ d,eK          Zl G d- d.ek          Zm G d/ d0ek          ZadS )1zS
Templates allow multiple Panel objects to be embedded into custom HTML
documents.
    )annotationsN)partial)PathPurePath)
IOTYPE_CHECKINGAnyClassVarDictListLiteralOptionalTupleType)Document)	LayoutDOM)settings)JupyterCommManager   )_base_configconfigpanel_extension)init_doc)
add_to_doc)render_template)NotificationArea)	
BUNDLE_DIRCDN_DISTResourceComponent_envcomponent_resource_pathget_dist_pathloading_cssparse_templateresolve_custom_path)save)curdoc_lockedstate)ColumnGridSpecListLike)CommManager)HTML	HoloViewsStrpanel)	ImageBase)ReactiveHTML)THEMESDefaultThemeDesignTheme)isurl)MimeRenderMixin
RenderableServableMixinViewable)Button)BooleanIndicatorLoadingSpinner)Model)BokehSessionContext)Template)Comm)Location)ResourcesTypezf<b>Running server:</b> <a target="_blank" href="https://localhost:{port}">https://localhost:{port}</a>str_server_infoz+/static/extensions/panel/images/favicon.icoFAVICON_URLc                      e Zd ZU  ej         e            edd          Z ej        eeddd          Z ej	        dd          Z
 ej        eeddd	          Zi Zd
ed<   dZded<   dZded<   i i i i dZded<   dZ	 	 dUdV fdZ ej        dd          d             ZdWdZdXdZdYd!ZdZd'Zd[d*Z	 	 	 d\d]d5Z	 dUd^d7Zd_d` fd<Z	 	 	 	 dadbdKZ	 	 dcdddMZ 	 	 dedf fdSZ!dgdTZ" xZ#S )hBaseTemplateTzo
        Configuration object declaring custom CSS and JS files to load
        specifically for this template.)defaultclass_constantdocFz/
        A Design applies themes to a template.)rK   rJ   is_instanceinstantiaterM   z
        Whether to add a Location component to this Template.
        Note if this is set to true, the Jinja2 template must
        either insert all available roots or explicitly embed
        the location root with : {{ embed(roots.location) }}.rJ   rM   )rK   rJ   rL   rN   rO   z.ClassVar[Dict[Type[Viewable], Dict[str, Any]]]	modifiersNz.ClassVar[Path | str | List[Path | str] | None]_css_js)cssjs
js_modulestarballz#ClassVar[Dict[str, Dict[str, str]]]
_resourcestemplatestr | _Templatenb_templateOptional[str | _Template]c                   d |                                 D             } t                      j        di d |                                 D              | j        j                            |           t          |t                    r!|| _        t          j
        |          | _        nd | _        || _        t          |t                    rt          j
        |          | _        n|p| j        | _        i | _        i | _        g | _        d | _        |                                 | _        |                                  d S )Nc                6    i | ]\  }}|t           j        v ||S  r   param.0pvs      3lib/python3.11/site-packages/panel/template/base.py
<dictcomp>z)BaseTemplate.__init__.<locals>.<dictcomp>t   s2     
 
 
QqL4F/F/FAq/F/F/F    c                B    i | ]\  }}|t           j        vs|d k    ||S namer`   rb   s      rf   rg   z)BaseTemplate.__init__.<locals>.<dictcomp>w   s8     
 
 
Qq8J/J/JaSYkkAqkkkrh   r_   )itemssuper__init__r   ra   update
isinstancerE   _coder    from_stringrY   r[   _render_items_render_variables
_documents_server_build_layout_layout_setup_design)selfrY   rl   r[   paramsconfig_params	__class__s         rf   rn   zBaseTemplate.__init__p   sJ   
 
#\\^^
 
 
 	 	 	 
 
#\\^^
 
 
 	 	 	 	  ///h$$ 	%%-DJ ,X66DMMDJ$DMk3'' 	<#/<<D*;dmDGI13*,))++rh   design)watchc                F    |                      | j                  | _        d S )N)theme)r~   r   _designrz   s    rf   ry   zBaseTemplate._setup_design   s    {{{44rh   returnNonec                >    |                                  | j        d<   d S )Ntemplate_resources)resolve_resourcesrt   )rz   argss     rf   _update_varszBaseTemplate._update_vars   s"    7;7M7M7O7O3444rh   r)   c                     t          t                               }t          d          t          d           fd}j                            |d           t          |          S )N Launch serverrj   c                   j         r0d_        d_        j                                          d _         d S d_                            dd          _         t
                              j         j                  _        d S )Nr   r   zStop serverT)startshow)port)rv   rk   objectstop_get_serverrF   formatr   )eventbuttonrz   server_infos    rf   launchz*BaseTemplate._build_layout.<locals>.launch   s    | Q-%'"!!####+#//d/FF%1%8%8dl>O%8%P%P"""rh   clicks)r/   reprr-   r<   ra   r   r)   )rz   str_reprr   r   r   s   `  @@rf   rw   zBaseTemplate._build_layout   s    tDzz??2hh_---		Q 		Q 		Q 		Q 		Q 		Q 		Q 	68,,,hV444rh   rE   c                    d}|                     d | j                                        D                       }t          |           j         | | S )Nz
    c                z    g | ]8\  }\  }}|                     d           d| d|                    d           9S )_[z]    )
startswith__repr__)rc   rk   objr   s       rf   
<listcomp>z)BaseTemplate.__repr__.<locals>.<listcomp>   s\     
 
 
hsA??3''
)))Q))
 
 
rh   )joinrs   rl   type__name__)rz   spacerobjss      rf   r   zBaseTemplate.__repr__   sf    {{ 
 
"&"4":":"<"<
 
 
  
 t**%5v5t555rh   rk   modelr?   tags	List[str]c                    d S Nr_   )rz   rk   r   r   s       rf   _apply_rootzBaseTemplate._apply_root   s    rh   session_contextr@   c                ~    |j         }|t          j        v rt          j        |= | j                            |           d S r   )	_documentr(   
_templatesru   remove)rz   r   rM   s      rf   _server_destroyzBaseTemplate._server_destroy   s?    '%""" %s#####rh   rM   Optional[Document]commOptional[Comm]titleOptional[str]notebookboollocationbool | Locationc                   |pt                      }t          |          }| j                            |           |t          j        vr| t          j        |<   |r| j        r|                     ||           |                    t          j	                   |                    | j
                   |s|j        dk    r|pd}||_        t                      }|                    ||d          }|j                            | j        j                   |j        d         }	g g }}
i }| j                                        D ]\  }\  }}|                    ||d          |_        j        fd|D             z   _        j        d         }t-          t.                    rj        ||<   | j        j        |j        vr$|j                            | j        j                   |                    t4                    D ]i}|j                            |          }|||j        |	<   t-          |t:                    r+||j        v r"|j                            |          |j        |	<   j|                     ||           |j        |<   |
                    |           |                               tA          |tC          |                     |                    |j
                   t          j"                            |	           ||||ft          j#        |	<   |
|_$        ||j%        d d <   ||_&        | j        '                    ||d           |(                    |           ||j        |<   |                    |j
                   |r| j)        |_*        n| j*        |_*        | +                                 ||j,        d	<   |j,        -                    | j.                   |S )
NzBokeh ApplicationPanel ApplicationF)
preprocessidc                &    g | ]}|j         v|S r_   )r   )rc   tagr   s     rf   r   z*BaseTemplate._init_doc.<locals>.<listcomp>   s%    &T&T&Tsc>S>Ss>S>S>Srh   )hold)isolatedsizing_modes)/r'   r   ru   appendr(   r   r   _add_locationon_session_destroyed_destroy_sessionr   r   r)   get_root_hooksr   _apply_hooksrefrs   rl   rk   r   rp   r   sizing_modeselectr;   _modelsgetr.   _plotsr   r   r   _fake_roots_viewsobjectschildrendocumentapply_preprocessr[   rY   r   _template_variablesro   rt   )rz   rM   r   r   r   r   r   colpreprocess_rootr   r   modelsr   rk   r   r   mrefsubsubmodelr   s                      @rf   	_init_doczBaseTemplate._init_doc   s    !3MOOH%%x(((5+++)-EX& 	3 	3x222%%e&<===%%d&:;;; 	#HN&99900E"HN
 hh,,x%,HH
$,3444!$' 2f!%!3!9!9!;!; 	? 	?D+3 LL4ELBBEEJ&T&T&T&Td&T&T&TTEJ9T?D%++ %%*%6T"<,CJ>>J%%dl&?@@@ ::h// ? ?C"{t44H' '/CK$!#y11 ?dcj6H6H*-*..*>*>
3   ud333 ,1x(C   e$$$uhT$ZZ8888))#*=>>>> 	  %%% /8TBS&, ##+ 3%@@@(((#2x %%c&9:::  	. $ 0H $H7C$^4$++D,BCCCrh   7Tuple[Dict[str, str], Dict[str, Dict[str, str]]] | Nonec                   t           j        }|sdt          j        v rdd l}|j        j        }|s&t          j        j                            d           d S 	 t                      j
        J t          t          _        n# t          $ r Y nw xY wddlm} t#                      }t          j                                        |                     |d           |j        d         j        d         }t-          j        |d	          }t          j                            t3          | j        ||          t3          | j        |          t3          | j        |          fd
          }	|	j        |_        |                    |           t>          j         dk    r3 |tC          j"                    j#                  }
|
g ft          j$        |<   tK          ||          S )N	holoviewsr   zDisplaying Panel objects in the notebook requires the panel extension to be loaded. Ensure you run pn.extension() before displaying objects in the notebook.)displayT)r   r   comm_manager)comm_idplot_idrk   c                ,                                     S r   )init)r   r   s    rf   <lambda>z0BaseTemplate._repr_mimebundle_.<locals>.<lambda>1  s    diikk rh   )on_msgon_error	on_stdouton_opendisable)
display_id)&r   _loadedsysmodulesr   	extensionra   mainwarningget_ipythonkernel_JupyterCommManagerr(   _comm_manager	ExceptionIPython.displayr   r   get_server_commr   rootsr   r,   r   get_client_commr   _on_msg	_on_error
_on_stdoutclient_comm_idadd_rootr   console_outputuuiduuid4hex_handlesr   )rz   includeexcludeloadedhvr   rM   r   managerclient_commhandler   s              @rf   _repr_mimebundle_zBaseTemplate._repr_mimebundle_  s    !( 	*+44""""\)F 	J$$   4	=='333"5E 	 	 	D	 	,+++++jj"2244sD4000ilt$GS~
 
 
 )994<g66T^S11dos33))))	 : 
 
 "-W I--W
(8999F#)2,EN3sD'222s   &A> >
B
Bautocdnbool | Literal['auto']rD   c                v	   t          |           }t                                          |          d         }d         }d         }d         }|j        }|                                }t          |          }	|                    t          | j        j	                  t          t          j        t          j        t          j                  gz              | j                            |                                          D ]T\  t!          t"                    r                                        6xx         fdD             z  cc<   U| j        j                                        D ]+\  }
d|
vrt(          j        rt(          j         d|
 }
|
|<   ,| j        j                                        D ]+\  }
d|
vrt(          j        rt(          j         d|
 }
|
|<   ,t/          t          | j        j                            D ].\  }}d|vrt(          j        rt(          j         d| }||d	| <   /| j        }t!          |t                    s|r|gng }|D ]}|}|j        d
d         D ]g}t7          |t8                    s|j         nGt!          |j        t                    r|j        n|j        g}||v r|j                                        }ht:          j                            |          }t@          |z  |z  !                                r|	d| d| z   |d| <   tE          |          r	||d| <   tG          | |          rtI          | d|          |d| <   | j%        }t!          |t                    s|r|gng }|D ]}
|}t          |           j        d
d         D ]g}t7          |t8                    s|j%         nGt!          |j%        t                    r|j%        n|j%        g}|
|v r|j                                        }ht:          j                            |
          }t@          |z  |z  !                                r|	d| d| z   |d| <   tE          |
          r	|
|d| <   tG          | |
          rtI          | d|
          |d| <   S )a  
        Resolves the resources required for this template 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.

        Returns
        -------
        Dictionary containing JS and CSS resources.
        )r  rU   rV   rT   raw_cssc                (    g | ]}         v|S r_   r_   )rc   rresresource_typesrnames     rf   r   z2BaseTemplate.resolve_resources.<locals>.<listcomp>a  s/     * * *c1F&F&FA&F&F&Frh   z///config_r   Nzbundled/base_rR   rS   )&r   rm   r   r   lowerr"   extendlistr   r  r#   loading_spinnerloading_colorloading_max_heightr   rl   rp   dictro   js_filesr(   rel_pathrV   	enumerate	css_filesrR   __mro__
issubclassrI   ospathbasenamer   is_filer7   r%   r!   rS   )rz   r  clsr+  rV   r.  r  clsnamerk   	dist_pathrU   irT   base_css	tmpl_namesclstmpl_csscss_filebase_jstmpl_jsjs_namer  r  r  r}   s                        @@@rf   r   zBaseTemplate.resolve_resources@  sn    4jj22s2;;!$'#L1
"5)	 +,}}!c***	tDK/00K"F$8&:S5
 5
 4  	 	 	 ,88==CCEE 	 	JE3#t$$ u%,,S1111u%%% * * * * * *"* * * %%%% -3355 	! 	!IE22~~%.~---- HUOO/5577 	# 	#IE22~~%.~---- "JuT[%: ; ;<< 	+ 	+FAs35>//#//'*Immm$$ 9(D)) 	6%-5zz2H 	\ 	\CIABB 6 6!$55 Y&E(249d(C(CT499$)(?? $ 3 3 5 5Iw'',,HY&1::<< \09<]y<]<]S[<]<]0]	,(,,--s \03	,(,,--$T3// \1HvWZ1[1[	,(,,. ('4(( 	3#*2wiiG 	W 	WBIDzz)!B$/ 5 5!#|44 W_E%/%>%>M#''SWI== # 2 2 4 4Ig&&r**GY&099;; W.7:ZY:Z:ZQX:Z:Z.Z***++r W.0***++$T2.. W.EdESU.V.V***+rh        r   ./filenamestr | os.PathLike | IOembed
max_statesintmax_opts
embed_jsonjson_prefix	save_path	load_pathc                n    |rt          d          t          | |||| j        | j        ||||||	|
          S )a  
        Saves Panel objects to file.

        Arguments
        ---------
        filename: string or file-like object
           Filename to save the plot to
        title: string
           Optional title for the plot
        resources: bokeh resources
           One of the valid bokeh.resources (e.g. CDN or INLINE)
        embed: bool
           Whether the state space should be embedded in the saved file.
        max_states: int
           The maximum number of states to embed
        max_opts: int
           The maximum number of states for a single widget
        embed_json: boolean (default=True)
           Whether to export the data to json files
        json_prefix: str (default='')
           Prefix for the auto-generated json directory
        save_path: str (default='./')
           The path to save json files to
        load_path: str (default=None)
           The path or URL the json files will be loaded from.
        z+Embedding is not yet supported on Template.)
ValueErrorr&   rY   rt   )rz   rD  r   	resourcesrF  rG  rI  rJ  rK  rL  rM  s              rf   r&   zBaseTemplate.save  sQ    @  	LJKKK(E9dm"E:xY	
 
 	
rh   r   c                2    |                      |||          S )aO  
        Returns a servable bokeh Document with the panel attached

        Arguments
        ---------
        doc : bokeh.Document (optional)
          The Bokeh Document to attach the panel to as a root,
          defaults to bokeh.io.curdoc()
        title : str
          A string title to give the Document
        location : boolean or panel.io.location.Location
          Whether to create a Location component to observe and
          set the URL location.

        Returns
        -------
        doc : bokeh.Document
          The Bokeh document the panel was attached to
        )r   r   )r   )rz   rM   r   r   s       rf   
server_doczBaseTemplate.server_doc  s    . ~~c~BBBrh   r   bool | 'Location'areatarget'BaseTemplate'c                    t                      j        rt          j        rt	          d          t                                          ||||          S )aZ  
        Serves the template and returns self to allow it to display
        itself in a notebook context.

        Arguments
        ---------
        title : str
          A string title to give the Document (if served as an app)
        location : boolean or panel.io.location.Location
          Whether to create a Location component to observe and
          set the URL location.
        area: str (deprecated)
          The area of a template to add the component too. Only has an
          effect if pn.config.template has been set.
        target: str
          Target area to write to. If a template has been configured
          on pn.config.template this refers to the target area in the
          template while in pyodide this refers to the ID of the DOM
          node to write to.

        Returns
        -------
        The template
        zCannot mark template as servable if a global template is defined. Either explicitly construct a template and serve it OR set `pn.config.template`, whether directly or via `pn.extension(template=...)`, not both.)r'   r   r   rY   RuntimeErrorrm   servable)rz   r   r   rT  rU  r}   s        rf   rY  zBaseTemplate.servable  sU    8 ??* 	v 	A   wwxv>>>rh   c                x    g }| j                                         D ]\  }}||                    |          z  }|S )a  
        Iterates over the Template and any potential children in the
        applying the Selector.

        Arguments
        ---------
        selector: type or callable or None
          The selector allows selecting a subset of Viewables by
          declaring a type or callable function to filter by.

        Returns
        -------
        viewables: list(Viewable)
        )rs   valuesr   )rz   selectorr   r   r   s        rf   r   zBaseTemplate.select  sH     (//11 	, 	,FCszz(+++GGrh   NN)rY   rZ   r[   r\   r   r   )r   r)   r   rE   )rk   rE   r   r?   r   r   r   r   r   r@   NNNFT)
rM   r   r   r   r   r   r   r   r   r   )r   r   )r  )r  r  r   rD   )	NNFrA  rB  Fr   rC  N)rD  rE  r   r   rF  r   rG  rH  rI  rH  rJ  r   rK  rE   rL  rE   rM  r   r   r   )NNT)rM   r   r   rE   r   r   r   r   )NTr   N)
r   r   r   rS  rT  rE   rU  r   r   rV  r   )$r   
__module____qualname__ra   ClassSelectorr   r   r5   r~   Booleanr   r6   r4   r   rQ   __annotations__rR   rS   rX   _BaseTemplate__abstractrn   dependsry   r   rw   r   r   r   r   r  r   r&   rR  rY  r   __classcell__r}   s   @rf   rI   rI   H   s         U *. 5+, , ,F
 !U -2 L23 3 3F u}U 1A B B BH  Eul)-5eU U UE ACIBBBB <@D???? ;?C>>>> 2"7 7J     J 0415      8 U]84(((5 5 )(5P P P P5 5 5 5"6 6 6 6   $ $ $ $ FJ6;"&V V V V Vr %),3 ,3 ,3 ,3 ,3d_ _ _ _ _ _ _D HL?CFH8<	'
 '
 '
 '
 '
T <@$(C C C C C4 JN48#? #? #? #? #? #? #?J       rh   rI   c                  ~    e Zd ZU dZ ej        d          Z ej        d          ZdZde	d<   dgdgd	Z
d
e	d<   dS )TemplateActionszo
    A component added to templates that allows triggering events such
    as opening and closing a modal.
    r   rJ   r   zClassVar[str]	_templatez;document.getElementById('pn-Modal').style.display = 'block'z:document.getElementById('pn-Modal').style.display = 'none')
open_modalclose_modalz$ClassVar[Dict[str, List[str] | str]]_scriptsN)r   rb  rc  __doc__ra   Integerro  rp  rn  rf  rq  r_   rh   rf   rl  rl    s          
 q)))J%-***K!I!!!! UUTU6 6H      rh   rl  c                      e Zd ZU dZ ej         edd          eddd          Z ej	        ddd	          Z
 ej        edd
          Z ej        edd          Z ej        dd          Z ej        edd          Z ej        dd          Z ej        edd          Z ej        edd          Z ej        d          Z ej        ed          Z ej        dd          Z ej        dd          Z ej        dd          Z ej        dd          Z ej        d          Z ej        d           Z ej        d!          Z ej        d"          Z  ej        d#          Z! ej        d$          Z" ej#        d%g d&d'(          Z$ ej        d)          Z% ej        d*          Z& ej'        dd+          Z( ej         e)            e),          Z*dZ+d-e,d.<   dZ- fd/Z.	 	 dKdL fd<Z/dM fd>Z0dMd?Z1dNdBZ2dO fdEZ3dMdFZ4dMdGZ5e6dPdI            Z7e6dJ             Z8 xZ9S )QBasicTemplateaW  
    BasicTemplate provides a baseclass for templates with a basic
    organization including a header, sidebar and main area. Unlike the
    more generic Template class these default templates make it easy
    for a user to generate an application with a polished look and
    feel without having to write any Jinja2 template themselves.
       )widthheightTz4
        Visual indicator of application busy state.)rJ   rK   rL   
allow_NonerM   FzA
        Whether the sidebar (if present) is initially collapsed.)rJ   rL   rM   z>
        A list-like container which populates the header bar.)rK   rL   rM   z=
        A list-like container which populates the main area.r   z
        The maximum width of the main area. For example '800px' or '80%'.
        If the string is '' (default) no max width is set.rP   z;
        A list-like container which populates the sidebar.iJ  z<
        The width of the sidebar in pixels. Default is 330.z8
        A list-like container which populates the modalz
        The NotificationArea instance attached to this template.
        Automatically added if config.notifications is set, but may
        also be provided explicitly.z
        URI of logo to add to the header (if local file, logo is
        base64 encoded as URI). Default is '', i.e. not shown.)rM   zn
        URI of favicon to add to the document head (if local file, favicon is
        base64 encoded as URI).r   z{
        A title to show in the header. Also added to the document head
        meta settings and as the browser tab title.zy
        Name of the site. Will be shown in the header and link to the
        'site_url'. Default is '', i.e. not shown.r   z2
        Url of the site and logo. Default is '/'.Nz!
        Manifest to add to site.zz
        A meta description to add to the document head for search
        engine optimization. For example 'P.A. Nelson'.zZ
        Meta keywords to add to the document head for search engine
        optimization.zy
        A meta author to add to the the document head for search
        engine optimization. For example 'P.A. Nelson'.z
        A meta refresh rate to add to the document head. For example
        '30' will instruct the browser to refresh every 30
        seconds. Default is '', i.e. no automatic refresh.z.
        A meta viewport to add to the header.zl
        Specifies the base URL for all relative URLs in a
        page. Default is '', i.e. not the domain._self)_blankrz  _parent_topzC
        Specifies the base Target for all relative URLs in a page.)rJ   r   rM   z3
        Optional header background color override.z-
        Optional header text color override.)rJ   readonly)rJ   rK   zClassVar[Path | None]rn  c           	        | j                             d          }	 t          j        t	          | j                             t          t                    j                                      }n)# t          j
        j        $ r t          |          }Y nw xY wd|vrt                      |d<   n.|                     |d         | j        j        j                  |d<   d|vrt                      |d<   n.|                     |d         | j        j        j                  |d<   d|vrt                      |d<   n.|                     |d         | j        j        j                  |d<   d|vrt                      |d<   n.|                     |d         | j        j        j                  |d<   d|v r2t+          |d         t                    rt,          |d                  |d<   nt,          t.          j                 |d<   d|v r3t+          |d         t2                    rt	          |d                   |d<   d	|vr5t.          j        r)t6          j        rt6          j        nt;                      |d	<    t=                      j        dd
|i| tA          ddd          | _!        d|v r| j!        g f| j"        d<   d|v r| j#        g f| j"        d<   d|v r"| j        r| j        g f| j"        d	<   d| j$        d	<   t.          j%        r0d|v r,t6          j%        r t6          j%        g f| j"        d<   d| j$        d<   | &                                 | j        j        '                    | j(        dg           | j        j        '                    | j(        dg           | j        j        '                    | j(        dg           | j        j        '                    | j(        dg           | j        j        )                    d           | j        j        )                    d           | j        j        )                    d           | j        j        )                    d           d S )Nzutf-8)encodingheaderr   sidebarmodalr   faviconnotificationsrY   r   )marginrw  rx  zembed(roots.js_area)js_areazembed(roots.actions)actionszembed(roots.notifications)Tzembed(roots.browser_info)browser_infor   r_   )*rn  	read_textr    get_templaterE   relative_tor   __file__parentjinja2
exceptionsTemplateNotFoundr$   r+   _get_paramsra   r  rK   r   r  r  rp   r3   r   r   r   r  r(   curdocr   rm   rn   r-   _js_arears   _actionsrt   r  _update_busyr   _update_render_itemstrigger)rz   r{   tmpl_stringrY   r}   s       rf   rn   zBasicTemplate.__init__  s   n...@@	3(T^-G-GXH]-^-^)_)_``HH 1 	3 	3 	3%k22HHH	3 6!!'zzF8#//x0@$*BSBZ[[F8%ZZF6NN!--fVndjo>TUUF6NF"" (

F9 $ 0 0	1BDJDVD] ^ ^F9&  &jjF7OO"..vg
@P@WXXF7Of&/3// :"("9w$V\2F7O:fY.?#J#J #F9$5 6 6F9&((V-A(=B\&ae&9&9O_OaOaF?#55(5f555AQq999![00-1]B,?Dy)![00-1]B,?Dy)';664;M6373Er2JD/6:D"?3 	:#>+#M#MRWRd#M272Db1ID~.59D">2	d7)EEE
t89+FFF  !:YKHHH 9I;GGG		***""9---!!),,,
  +++++s   AA/ /#BBrM   r   r   Optional['Comm']r   r   r   r   r   r   r   r   c                \   | j         | j        j         j        k    r| j         n|}| j        rt	          j        | j                   t                                          |||||          }| j        r| j        t          j	        |<   | j
        j        j        r| j
        j        j        |_        |S r   )r   ra   rJ   busy_indicatorr(   	sync_busyrm   r   r  _notificationsr   r   bokeh_theme)rz   rM   r   r   r   r   r   r}   s          rf   r   zBasicTemplate._init_doc  s     #jDJ,<,DDD

% 	1OD/00077$$S$xJJ 	@-1-?E *<) 	<!\/;HNrh   r   c                    t                      j        |  | j        | j        d<   | j        | j        d<   | j        | j        d<   | j        | j        d<   | j        | j        d<   | j        | j        d<   | j        | j        d<   | j	        | j        d<   | j
        | j        d	<   | j        | j        d
<   | j        | j        d<   | j        | j        d<   t          j                            | j                  rot%          | j                  }t'          |t(                    st+          d| j         d          |                    |                    |j                            }n| j        }t          j                            | j                  rot%          | j                  }t'          |t(                    st+          d| j         d          |                    |                    |j                            }n;t5          j        d          dk    r| j        t8          k    rt:          dz   }n| j        }|| j        d<   || j        d<   |                     | j                  | j        d<   | j        | j        d<   | j         | j        d<   | j!        | j        d<   | j"        | j        d<   | j#        j$        | j        d<   | j%        | j        d<   d S )N	app_title	meta_name
site_titlesite_urlmanifestmeta_descriptionmeta_keywordsmeta_authormeta_refreshmeta_viewportbase_urlbase_targetz'Could not determine file type of logo: .z*Could not determine file type of favicon: serverrm  r  zimages/favicon.icoapp_logoapp_faviconapp_favicon_typeheader_backgroundheader_colormain_max_widthsidebar_widthr   collapsed_sidebar)&rm   r   r   rt   siter  r  r  r  r  r  r  r  r  r1  r2  isfilelogo_panelrp   r1   rO  _b64_datar   r  	_settingsrP  rG   r   _get_favicon_typer  r  r  r  r   r   r  )rz   r   imgr  r  r}   s        rf   r   zBasicTemplate._update_vars  s   d##.2j{+.2j{+/3y|,-1]z*-1]z*595J12262D/040@}-151B~.262D/-1]z*040@}-7>>$)$$ 	##Cc9-- Y !W49!W!W!WXXX88CIIcj1122DD9D7>>$,'' 		'&&Cc9-- _ !]dl!]!]!]^^^hhsyy4455GG"8444==$,R]B]B]"%99,-1z*07}-595K5KDL5Y5Y126:6L23151B~.373F/0262D/*.,*<w'6:6L2333rh   c                |    | j         r| j         g f| j        d<   nd| j        v r| j        d= | j         d u| j        d<   d S )Nr  busy)r  rs   rt   r   s    rf   r  zBasicTemplate._update_busy  s[     	5484G3LD/00!333"#34)-)<D)Hv&&&rh   r   param.parameterized.Eventc                   |j         | u r|j        dk    r|                                 S |j         | j        u rd}n2|j         | j        u rd}n!|j         | j        u rd}n|j         | j        u rd}t          |j        t                    r|j        n%t          |j        
                                          }|D ]4}| dt          t          |                     }|| j        v r| j        |= 5t          |j        t                    r|j        n|j        
                                }| j        j        j        r=|D ]:}||v r|                    t&                    D ]}| j        j        j        |_        ;i }	|D ]l}| dt          t          |                     }|j                            t+          |          j                  rd|	|<   n
|j        |	|<   ||gf| j        |<   md | j        
                                D             }
t/          d	 |
D                       | j        d<   t/          d
 |
D                       | j        d<   |	| j        d<   d S )Nr  r   navr  r  -Contentc                    g | ]\  }}|S r_   r_   )rc   r   r   s      rf   r   z6BasicTemplate._update_render_items.<locals>.<listcomp>5  s    @@@D@@@rh   c              3     K   | ]}d |v V  	dS )r  Nr_   rc   tss     rf   	<genexpr>z5BasicTemplate._update_render_items.<locals>.<genexpr>6  s&      +G+GBERK+G+G+G+G+G+Grh   c              3     K   | ]}d |v V  	dS )r  Nr_   r  s     rf   r  z5BasicTemplate._update_render_items.<locals>.<genexpr>7  s&      .M.M"x2~.M.M.M.M.M.Mrh   root_labels)r   rk   r  r   r  r  r  rp   oldr&  r[  rE   r   rs   newr   r   r  r   r.   r   r   r   anyrt   )rz   r   r   r  r   r   r  ohvpanelabelsr   s              rf   r  z"BasicTemplate._update_render_items  s   9/?!?!?$$&&&9	!!CCY$,&&CCY$+%%CCY$*$$C%ei66TeiiDAQAQASAS<T<T 	, 	,C))3r#ww<<))Cd(((&s+%ei66NeiiEI<L<L<N<N<) 	B B B88hhy11 B BF#'<#5#AFLLB  	3 	3C))3r#ww<<))Cx""499#566 ''s!hs'*SElDs##@@D$6$=$=$?$?@@@(++G+G$+G+G+G(G(Gu%+..M.M.M.M.M+M+Mx(06}---rh   r   r@   c                    t                                          |           | j        s9| j        t          j        v r(t          j                            | j                   d S d S d S r   )rm   r   ru   r  r(   _indicatorsr   )rz   r   r}   s     rf   r   zBasicTemplate._server_destroy:  se    000 	:4#6%:K#K#K$$T%899999	: 	:#K#Krh   c                0    | j         xj        dz  c_        dS )z&
        Opens the modal area
        r   N)r  ro  r   s    rf   ro  zBasicTemplate.open_modal?  s      	  A%    rh   c                0    | j         xj        dz  c_        dS )z'
        Closes the modal area
        r   N)r  rp  r   s    rf   rp  zBasicTemplate.close_modalE  s      	!!Q&!!!!rh   rE   c                   | sdS |                      d          rdS |                      d          rdS |                      d          rdS |                      d          rd	S |                      d
          rdS t          d          )Nr   z.pngz	image/pngjpgz	image/jpggifz	image/gifsvgz	image/svgicozimage/x-iconzfavicon type not supported.)endswithrO  )r  s    rf   r  zBasicTemplate._get_favicon_typeK  s     	<2f%% 	<;e$$ 		<;e$$ 	<;e$$ 	<;e$$ 	<!>:;;;rh   c                L   t          | |          r| S t          | t                    rg | } nt          | t                    s| g} d | D             } |t          u rt          |           S |t          u r1t	          dd          }t          |           D ]\  }}|||d d f<   |S | S )Nc                ,    g | ]}t          |          S r_   )r  )rc   items     rf   r   z-BasicTemplate._get_params.<locals>.<listcomp>f  s    000$000rh   )r      override)ncolsmode)rp   tupler&  r+   r*   r-  )valuerK   gridindexr  s        rf   r  zBasicTemplate._get_params\  s    eV$$ 	LeU## 	eHEEE4(( 	GE 10%000XE****X":666D(// $ $t#UAAAXKrh   ra  )rM   r   r   r  r   r   r   r   r   r   r   r   r^  )r   r  r   r   r`  r_  ):r   rb  rc  rr  ra   rd  r>   r=   r  Selectorr  r+   r  r   Stringr  r  rs  r  r  r   r  r  rG   r  r   r  r  r  r  r  r  r  r  r  ObjectSelectorr  r  r  re  r   rl  r  rn  rf  _BasicTemplate__abstractrn   r   r   r  r  r   ro  rp  staticmethodr  r  ri  rj  s   @rf   ru  ru  0  s          )U(bQS1T1T1T0@448 ?78 8 8N
 'ut JD E E E !U 4 FA B B BF 5h D@ A A AD "U\" 3> ? ? ?N "e!D G> ? ? ?G "EM# 4? @ @ @M  Ex$ E; < < <E (E'/?$ U( ) ) )M
 5< B C C CD el; 5# $ $ $G EL!4 ;7 8 8 8E 5< )6 7 7 7D u|C .5 6 6 6H u|D /$ % % %H $u| ); < < < !EL &   M %, $; < < <K  5< %> ? ? ?L
 !EL &1 2 2 2M u| !5 6 6 6H '%&w666 =FG G GK % *6 7 7 7  5< %0 1 1 1L u}TD999H"u"??+<+<_UUUH (,I++++J5, 5, 5, 5, 5,p HLW[      'M 'M 'M 'M 'M 'MRI I I I%7 %7 %7 %7N: : : : : :
& & & &' ' ' ' < < < \<    \    rh   ru  c                  >     e Zd ZdZ	 	 dd fd	Zg fddZddZ xZS )rA   aa  
    A Template is a high-level component to render multiple Panel
    objects into a single HTML document defined through a Jinja2
    template. The Template object is given a Jinja2 template and then
    allows populating this template by adding Panel objects, which are
    given unique names. These unique names may then be referenced in
    the template to insert the rendered Panel object at a specific
    location. For instance, given a Jinja2 template that defines roots
    A and B like this:

        <div> {{ embed(roots.A) }} </div>
        <div> {{ embed(roots.B) }} </div>

    We can then populate the template by adding panel 'A' and 'B' to
    the Template object:

        template.add_panel('A', pn.panel('A'))
        template.add_panel('B', pn.panel('B'))

    Once a template has been fully populated it can be rendered using
    the same API as other Panel objects. Note that all roots that have
    been declared using the {{ embed(roots.A) }} syntax in the Jinja2
    template must be defined when rendered.

    Since embedding complex CSS frameworks inside a notebook can have
    undesirable side-effects and a notebook does not afford the same
    amount of screen space a Template may given separate template
    and nb_template objects. This allows for different layouts when
    served as a standalone server and when used in the notebook.
    NrY   rZ   r[   str | _Template | Nonerl   Optional[Dict[str, Any]]c                     t                      j        d|||d| |i n|}|                                D ]\  }}|                     ||           d S )N)rY   r[   rl   r_   )rm   rn   rl   	add_panel)rz   rY   r[   rl   r{   rk   r  r}   s          rf   rn   zTemplate.__init__  su     	[(5[[TZ[[[m++-- 	' 	'JD$NN4&&&&	' 	'rh   rk   rE   r0   r;   r   r   r   r   c                    || j         v rt          d|z            t          |          |f| j         |<   t          |           | j        d         _        dS )aK  
        Add panels to the Template, which may then be referenced by
        the given name using the jinja2 embed macro.

        Arguments
        ---------
        name : str
          The name to refer to the panel by in the template
        panel : panel.Viewable
          A Panel component to embed in the template.
        zThe name %s has already been used for another panel. Ensure each panel has a unique name by which it can be referenced in the template.r   N)rs   rO  r  r   rx   r   )rz   rk   r0   r   s       rf   r  zTemplate.add_panel  sl     4%%% ; >BB C C C %+5MM4#84 !%dQrh   r  r	   c                P    || j         v rt          d|z            || j         |<   dS )a5  
        Add parameters to the template, which may then be referenced
        by the given name in the Jinja2 template.

        Arguments
        ---------
        name : str
          The name to refer to the panel by in the template
        value : object
          Any valid Jinja2 variable type.
        zThe name %s has already been used for another variable. Ensure each variable has a unique name by which it can be referenced in the template.N)rt   rO  )rz   rk   r  s      rf   add_variablezTemplate.add_variable  sM     4))) ; >BB C C C (-t$$$rh   r]  )rY   rZ   r[   r  rl   r  )rk   rE   r0   r;   r   r   r   r   )rk   rE   r  r	   r   r   )r   rb  rc  rr  rn   r  r  ri  rj  s   @rf   rA   rA   s  s         @ PT*.' ' ' ' ' ' ' GI , , , , ,(- - - - - - - -rh   rA   )nrr  
__future__r   r1  r   r
  	functoolsr   pathlibr   r   typingr   r   r	   r
   r   r   r   r   r   r   r  ra   bokeh.document.documentr   bokeh.modelsr   bokeh.settingsr   r  pyviz_commsr   r   r   r   r   io.documentr   io.modelr   io.notebookr   io.notificationsr   io.resourcesr   r   r   r    r!   r"   r#   r$   r%   io.saver&   io.stater'   r(   layoutr)   r*   r+   models.comm_managerr,   paner-   r.   r/   r0   r  
pane.imager1   reactiver2   
theme.baser3   r4   r5   r6   utilr7   viewabler8   r9   r:   r;   widgetsr<   widgets.indicatorsr=   r>   bokeh.modelr?   bokeh.server.contextsr@   rA   	_TemplaterB   io.locationrC   rD   rF   rf  rG   ParameterizedrI   rl  ru  r_   rh   rf   <module>r     s	     # " " " " " 				 



        " " " " " " " "                       
   , , , , , , " " " " " " 0 0 0 0 0 0 A A A A A A : : : : : : : : : : " " " " " " ! ! ! ! ! ! ) ) ) ) ) ) / / / / / /                            + + + + + + + + / / / / / / / / / / - - - - - -            # " " " " " # # # # # #                                   A A A A A A A A -!!!!!!999999,,,,,,      &&&&&&,,,,,,#     
 A @ @ @ @R R R R R5&HY R R Rl    l   $@ @ @ @ @L @ @ @F
R- R- R- R- R-| R- R- R- R- R-rh   