
    ;g                       U d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlmZmZ ddlmZmZmZm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 ddlmZ ddl m!Z! ddl"m#Z#m$Z$m%Z% ddl&m&Z&m'Z' ddl(m)Z) ddl*m+Z+m,Z, ddl-m.Z. ddl/m0Z0m1Z1 ddl2m3Z3m4Z4 ddl5m6Z7m8Z8m9Z9m:Z:m;Z; ddl<m=Z= ddl>m?Z?m@Z@mAZA ddlBmCZCmDZD ddlEmFZF er0ddlGmHZH ddlImJZJ ddlKmLZL ddlMmNZN ddlOmPZP ddl5mQZQ dd lRmSZS dd!lTmUZU  eV       ZWd"eXd#<    G d$ d%ej                        ZZ G d& d'      Z[ G d( d)      Z\ G d* d+ej                  e\      Z] G d, d-e]eZe[      Z^ G d. d/ej                        Z_ G d0 d1ej                        Za G d2 d3ej                        Zc G d4 d5ej                        Zed:d6Zfd;d7Zgd<d8Zhd9Ziy)=a  
Defines the baseclasses that make a component render to a bokeh model
and become viewable including:

* Layoutable: Defines parameters concerned with layout and style
* ServableMixin: Mixin class that defines methods to serve object on server
* Renderable: Defines methods to render a component as a bokeh model
* Viewable: Defines methods to view the component in the
  notebook, on the server or in static exports
    )annotationsN)CallableMapping)IOTYPE_CHECKINGAnyClassVar)DeserializationError)Document)	Resources)Template)	Undefined)instance_descriptor)Comm   )AlignAspectMargin)configpanel_extensionserve)create_doc_if_none_existsinit_doc)embed_state)start_loading_spinnerstop_loading_spinner)
add_to_docpatch_cds_msg)JupyterCommManagerBinary	ipywidgetrender_embedrender_mimebundlerender_modelsave)curdoc_locked
set_curdocstate)escapeparam_reprs)get_params_to_inherit)Model)BokehSessionContext)Server)SelfLocation)
Mimebundle)StoppableThreadDesignzset[asyncio.Task]_tasksc                      e Zd ZdZ edd      Z edd      Z ej                  g dd	      Z
 ej                  dg d
      Z ej                  ddd      Z ej                  ddd      Z ej                  ddd      Z ej                  ddd      Z ej                  ddd      Z edd      Z ej*                  i dd	      Z ej                  g dd	      Z ej                  g dd	      Z ej                  ddd      Z ej                  dg dd      Z ej                  dg dd      Z ej                  dg dd      Z ej:                  dd      ZdZ fdZ  xZ!S )
Layoutablez
    Layoutable defines shared style and layout related parameters
    for all Panel components with a visual representation.
    startz
        Whether the object should be aligned with the start, end or
        center of its container. If set as a tuple it will declare
        (vertical, horizontal) alignment.)defaultdocNa  
        Describes the proportional relationship between component's
        width and height.  This works if any of component's dimensions
        are flexible in size. If set to a number, ``width / height =
        aspect_ratio`` relationship will be maintained.  Otherwise, if
        set to ``"auto"``, component's preferred width and height will
        be used to determine the aspect (if not set, no aspect will be
        preserved).Tz,
        CSS classes to apply to the layout.)r;   nested_refsr<   z6
        The design system to use to style components.)r;   objectsr<   )r   Nz
        The height of the component (in pixels).  This can be either
        fixed or preferred height, depending on height sizing policy.)r;   boundsr<   zK
        Minimal width of the component (in pixels) if width is adjustable.zM
        Minimal height of the component (in pixels) if height is adjustable.r   z
        Allows to create additional space around the component. May
        be specified as a two-tuple of the form (vertical, horizontal)
        or a four-tuple (top, right, bottom, left).zU
        Dictionary of CSS rules to apply to DOM node wrapping the
        component.zk
        List of stylesheets defined as URLs pointing to .css files
        or raw CSS defined as a string.z
        List of arbitrary tags to add to the component.
        Can be useful for templating or for storing metadata on
        the model.z
        The width of the component (in pixels). This can be either
        fixed or preferred width, depending on width sizing policy.auto)r@   fixedfitminmaxa  
        Describes how the component should maintain its width.

        ``"auto"``
            Use component's preferred sizing policy.

        ``"fixed"``
            Use exactly ``width`` pixels. Component will overflow if
            it can't fit in the available horizontal space.

        ``"fit"``
            Use component's preferred width (if set) and allow it to
            fit into the available horizontal space within the minimum
            and maximum width bounds (if set). Component's width
            neither will be aggressively minimized nor maximized.

        ``"min"``
            Use as little horizontal space as possible, not less than
            the minimum width (if set).  The starting point is the
            preferred width (if set). The width of the component may
            shrink or grow depending on the parent layout, aspect
            management and other factors.

        ``"max"``
            Use as much horizontal space as possible, not more than
            the maximum width (if set).  The starting point is the
            preferred width (if set). The width of the component may
            shrink or grow depending on the parent layout, aspect
            management and other factors.
    a  
        Describes how the component should maintain its height.

        ``"auto"``
            Use component's preferred sizing policy.

        ``"fixed"``
            Use exactly ``height`` pixels. Component will overflow if
            it can't fit in the available vertical space.

        ``"fit"``
            Use component's preferred height (if set) and allow to fit
            into the available vertical space within the minimum and
            maximum height bounds (if set). Component's height neither
            will be aggressively minimized nor maximized.

        ``"min"``
            Use as little vertical space as possible, not less than
            the minimum height (if set).  The starting point is the
            preferred height (if set). The height of the component may
            shrink or grow depending on the parent layout, aspect
            management and other factors.

        ``"max"``
            Use as much vertical space as possible, not more than the
            maximum height (if set).  The starting point is the
            preferred height (if set). The height of the component may
            shrink or grow depending on the parent layout, aspect
            management and other factors.
    )rA   stretch_widthstretch_heightstretch_bothscale_widthscale_height
scale_bothNa  
        How the component should size itself.

        This is a high-level setting for maintaining width and height
        of the component. To gain more fine grained control over
        sizing, use ``width_policy``, ``height_policy`` and
        ``aspect_ratio`` instead (those take precedence over
        ``sizing_mode``).

        ``"fixed"``
            Component is not responsive. It will retain its original
            width and height regardless of any subsequent browser
            window resize events.

        ``"stretch_width"``
            Component will responsively resize to stretch to the
            available width, without maintaining any aspect ratio. The
            height of the component depends on the type of the
            component and may be fixed or fit to component's contents.

        ``"stretch_height"``
            Component will responsively resize to stretch to the
            available height, without maintaining any aspect
            ratio. The width of the component depends on the type of
            the component and may be fixed or fit to component's
            contents.

        ``"stretch_both"``
            Component is completely responsive, independently in width
            and height, and will occupy all the available horizontal
            and vertical space, even if this changes the aspect ratio
            of the component.

        ``"scale_width"``
            Component will responsively resize to stretch to the
            available width, while maintaining the original or
            provided aspect ratio.

        ``"scale_height"``
            Component will responsively resize to stretch to the
            available height, while maintaining the original or
            provided aspect ratio.

        ``"scale_both"``
            Component will responsively resize to both the available
            width and height, while maintaining the original or
            provided aspect ratio.
    zm
        Whether the component is visible. Setting visible to false will
        hide the component entirely.c                   |j                  d      }|dv rm|j                  d      \d|d   d}t        j                  dk(  r!|dz  }| j                  j	                  |       nt        |      |j                  d      |d<   |d	v rm|j                  d
      \d|d   d}t        j                  dk(  r!|dz  }| j                  j	                  |       nt        |      |j                  d
      |d<   |j                  d      >|j                  d
      -|j                  d      |j                  d      d|vrd|d<   n| j                  j                  j                  s| j                  j                  j                  st        |       j                  d|vrt        j                  dk(  rB|j                  d
      d|d<   n|j                  d      d|d<   nit        j                  |d<   nUt        j                  dk(  rd|vrt        j                  |d<   n*t        j                  dk(  rd
|vrt        j                  |d<   d|vr3| j                  j                  j                  t        j                  |d<   t        | 8  di | y )Nsizing_mode)rE   rH   rG   rJ   widthz*Providing a width-responsive sizing_mode (z) and a fixed width is not supported. Converting fixed width to min_width. If you intended the component to be fully width-responsive remove the heightsetting, otherwise change it to min_height.warnzX To error on the incorrect specification disable the config.layout_compatibility option.	min_width)rF   rI   rG   rJ   heightz+Providing a height-responsive sizing_mode (z) and a fixed height is not supported. Converting fixed height to min_height. If you intended the component to be fully height-responsive remove the height setting, otherwise change it to min_height.
min_heightwidth_policyheight_policyrA   rG   rE   rF   design )getr   layout_compatibilityparamwarning
ValueErrorpoprL   constantreadonlytyperT   r;   super__init__)selfparamsrL   error	__class__s       .lib/python3.12/site-packages/panel/viewable.pyr`   zLayoutable.__init__   sq   jj/YYJJw+<VM=R<U V> >  **f4ss

""5) ''"(**W"5F;[[JJx ,=f]>S=V W> >  **f4ss

""5) ''#)::h#7F< JJw+JJx ,JJ~&.JJ'/'$+F=!::))22djj6L6L6U6U4j$$,f1L!!^3::h'3,;F=)ZZ(4,<F=),2,>,>F=)##67&;P(.(:(:}%##'77HF<R(.(:(:}%6!djj&7&7&?&?&G%}}F8"6"    )"__name__
__module____qualname____doc__r   alignr   aspect_ratiorX   Listcss_classesSelectorrT   IntegerrP   rO   rQ   	max_width
max_heightr   marginDictstylesstylesheetstagsrM   rR   rS   rL   Booleanvisible_Layoutable__abstractr`   __classcell__rd   s   @re   r9   r9   F   s   
 ' (- .E
 $ - L %**RT @/ 0K U^^D" ;9 :F U]]4	 @I JF d9 CN OI tI DP QJ d9 CN OI tI DP QJ A $7 8F
 UZZ ; F %**RT @+ ,K 5::bd 9 D
 EMM$y ?G HE "5>> F M	L@ #ENN F M	M@ !%.. 8;/A1	Kf emmD /( )G J3# 3#rf   r9   c                      e Zd ZdZ	 	 	 	 	 	 	 	 	 	 ddZ	 d	 	 	 	 	 	 	 d	dZ	 	 d
	 	 	 	 	 	 	 	 	 ddZ	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy)ServableMixinzE
    Mixin to define methods shared by objects which can served.
    c                    |r7|t         j                  v r%t         j                  |   d   j                  |       | j                  |||      S )zG
        Callback to handle FunctionHandler document creation.
           )r)   _serversappend
server_doc)ra   	server_idtitler<   locations        re   _modify_doczServableMixin._modify_doc:  sA     enn4NN9%a(//4sE844rf   Nc                   ddl m} t        ||      r|}|t        j                  |<   nJ|t        j                  v rt        j                  |   }n$t        |      5  t        j                  }d d d        y ||j                  |      }n|j                  ||      }d|_	        |j                  |j                         |j                  |       |S # 1 sw Y   gxY w)Nr   r1   r   )io.locationr2   
isinstancer)   
_locationsr(   r   get_root
_get_modelnameon_session_destroyed_server_destroyadd_root)ra   r<   r   rootr2   loc	loc_models          re   _add_locationzServableMixin._add_locationH  s     	*h)C$'ES!E$$$""3'CCnn !;<S)IsD1I#	  !4!45Y
 !s   CCc                   t               }|r|j                  rt        j                  d      }|j                  D ]<  }t        |t        j                        s|j                  t        j                         > t        j                  r|xs |xs d}t        j                  }|J |j                  |j                  j                  j                  k(  r	|r||_        | j                         D ]   }	|	j                   r|j                   |	_        " |dk(  r|j"                  j%                  |        | S |dk(  r|j&                  j%                  |        | S |dk(  r|j(                  j%                  |        | S |dk(  r0|j*                  j%                  |        | S | j-                  ||       | S t        j.                  rdt0        j2                  vrpd	d
lm}
m}m}m} |r|
s| S 	 |xs  |       }|PtA        jB                   |||             }tD        jG                  |       |jI                  tD        jJ                         | S # t>        $ r d}Y aw xY w)a  
        Serves the object or adds it to the configured
        pn.state.template if in a `panel serve` context, writes to the
        DOM if in a pyodide context and returns the Panel object to
        allow it to display itself in a notebook context.

        Parameters
        ----------
        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 Panel object itself
        bokehmainNsidebarmodalheader)r   r   pyodide_kernelr   )_IN_PYSCRIPT_WORKER
_IN_WORKER_get_pyscript_targetwrite)&r'   session_contextlogging	getLoggerhandlersr   StreamHandlersetLevelWARNr   templater)   r   rX   r;   selectrT   r   r   r   r   r   r   _is_pyodidesysmodules
io.pyodider   r   r   r   	Exceptionasynciocreate_taskr7   addadd_done_callbackdiscard)ra   r   r   areatargetr<   loggerhandlerr   objr   r   r   r   tasks                  re   servablezServableMixin.servableh  s   < o3&&&&w/F!??gw'<'<=$$W\\2 + // >>+++>>X^^%9%9%A%AAe%*HN;;=C::%-__
 ) 6>MM((.. - Y&$$++D1* ) W_NN))$/& % X%OO**40"  eh?  #33;;#F  "59#7#9 !**5+>?

4 &&v~~6  s   %I IIc	                .    t        | f||||d||||d	|	S )aW  
        Starts a Bokeh server and displays the Viewable in a new tab.

        Parameters
        ----------
        title : str | None
          A string title to give the Document (if served as an app)
        port: int (optional, default=0)
          Allows specifying a specific port
        address : str
          The address the server should listen on for HTTP requests.
        websocket_origin: str or list(str) (optional)
          A list of hosts that can connect to the websocket.
          This is typically required when embedding a server app in
          an external web site.
          If None, "localhost" is used.
        threaded: boolean (optional, default=False)
          Whether to launch the Server on a separate thread, allowing
          interactive use.
        verbose: boolean (optional, default=True)
          Whether to print the address and port
        open : boolean (optional, default=True)
          Whether to open the server in a new browser tab
        location : boolean or panel.io.location.Location
          Whether to create a Location component to observe and
          set the URL location.

        Returns
        -------
        server: bokeh.server.Server or panel.io.server.StoppableThread
          Returns the Bokeh server instance or the thread the server
          was launched on (if threaded=True)
        T)	portaddresswebsocket_originshowr:   r   verboser   threadedr   
ra   r   r   r   r   r   r   openr   kwargss
             re   r   zServableMixin.show  s:    L 
W?OT
 5;
 	
rf   )
r   
str | Noner   strr<   r   r   zLocation | bool | Nonereturnr   N)r<   r   r   zLocation | boolr   Model | Noner   Location | NoneNTr   N)
r   r   r   bool | Locationr   r   r   r   r   r0   Nr   NNFTTT)r   r   r   intr   r   r   r   r   boolr   r   r   r   r   r   r   zStoppableThread | Server)rg   rh   ri   rj   r   r   r   r   rU   rf   re   r~   r~   5  s   55 5 	5
 )5 
5$ "	 " 	
 
B EI15EE2AEE$.E 
EP NRUY7;*
*
.1*
@J*
$*
7;*
NR*
 *
 &5*
 
"	*
rf   r~   c                  2    e Zd ZdZddZddZd	dZd
ddZy)MimeRenderMixinzV
    Mixin class to allow rendering and syncing objects in notebook
    contexts.
    c                   t         j                  |   dd \  }}}t        ||       |j                  j                  }|j                  |      }|j                          	 |j                  ||r|j                  nd       |j                          |r|j                  |       yy# t        $ r | j                  j                  d       Y Kw xY w# |j                          |r|j                  |       w w xY w)zJ
        Handles Protocol messages arriving from the client comm.
        r   Nz5Comm received message that could not be deserialized.)r)   _viewsr   	callbacks
hold_valueassembleholdapply_to_documentidr
   rX   rY   unhold)	ra   refmanagermsgr   r<   commheldpatchs	            re   _on_msgzMimeRenderMixin._on_msg  s      ,,s+AB/c4dC }}''  %
		##CDdC JJL  $ 	JJG	
 JJL s$    B$ $$CC 
CC &C4c                   |t         j                  vst        j                  dv ry t         j                  |   \  }}dt	        t        j                               z   dz   }t        j                  dk(  r|j                  |       nt        j                  dk(  r|g|d d  |r%|j                  ddj                  |      id	       y y )
NNdisablez
<pre>z</pre>

accumulatereplace	text/html
Traw)
r)   _handlesr   console_outputr*   	traceback
format_excr   updatejoin)ra   r   rc   handleaccumulator	formatteds         re   	_on_errorzMimeRenderMixin._on_error  s    enn$(=(=AR(R#nnS1fY%9%9%;<<ZG	  L0y)""i/'[KNMM;		+(>?TMJ rf   c                p   |t         j                  vst        j                  dv ry t         j                  |   \  }}|D cg c]  }| d	 }}t        j                  dk(  r|j	                  |       nt        j                  dk(  r||d d  |r%|j                  ddj                  |      id       y y c c}w )	Nr   z</br>r   r   r   r   Tr   )r)   r   r   r   extendr   r   )ra   r   stdoutr   r   or   s          re   
_on_stdoutzMimeRenderMixin._on_stdout  s    enn$(=(=AR(R#nnS1*01&Qs%[&	1  L0y)""i/&KNMM;		+(>?TMJ  2s    B3Nc                   ddl m} |j                  d   } |j                  |      }t        j
                  j                  t        j                  | j                  ||      t        j                  | j                  |      t        j                  | j                  |      fd      }|f| j                  |<   |j                  |_        t        ||||      S )Nr   )CommManagerr   )comm_idplot_idc                $    j                         S r   )init)_r   s    re   <lambda>z4MimeRenderMixin._render_mimebundle.<locals>.<lambda>  s    diikrf   )on_msgon_error	on_stdouton_open)models.comm_managerr   r   r   r)   _comm_managerget_client_comm	functoolspartialr   r   r   _commsclient_comm_idr#   )	ra   modelr<   r   r   r   r   r   client_comms	      `     re   _render_mimebundlez"MimeRenderMixin._render_mimebundle  s    4iiodggs;))99$$T\\3@&&t~~s;''=)	 : 
 !+.C!, T7HEErf   )r   r   r   None)r   r   rc   r   r   r  )r   r   r   r   r   r  r   )r  r-   r<   r   r   r   r   r   )rg   rh   ri   rj   r   r   r   r  rU   rf   re   r   r     s    
(
K
KFrf   r   c                       e Zd ZdZdZ fdZddddZ	 	 d	 	 	 	 	 	 	 	 	 ddZdddZddd	Z	ddd
Z
ddZddZdddZ	 	 d	 	 	 	 	 	 	 ddZ xZS )
Renderablez
    Baseclass for objects which can be rendered to a Bokeh model.

    It therefore declare APIs for initializing the models from
    parameter values.
    Tc                    g | _         i | _        i | _        i | _        i | _        t        |   di | t               | _        t        j                  t         dt        |       j                         | _        y )N.rU   )_internal_callbacks
_documents_modelsr  _kernelsr_   r`   set_found_linksr   r   rg   r^   _logger)ra   rb   rd   s     re   r`   zRenderable.__init__(  si    #% "6"E((H:QtDz7J7J6K)LMrf   debug)levelc               t     t        | j                  |      d| t        t        j                        g|  y )NzSession %s )getattrr  r   r)   curdoc)ra   r   r  argss       re   _logzRenderable._log2  s.    $e${3%%8"U\\:JRTRrf   c                    t         )aK  
        Converts the objects being wrapped by the viewable into a
        bokeh model that can be composed in a bokeh layout.

        Parameters
        ----------
        doc: bokeh.Document
          Bokeh document the bokeh model will be attached to.
        root: bokeh.Model
          The root layout the viewable will become part of.
        parent: bokeh.Model
          The parent layout the viewable will become part of.
        comm: pyviz_comms.Comm
          Optional pyviz_comms when working in notebook

        Returns
        -------
        model: bokeh.Model
        NotImplementedError)ra   r<   r   parentr   s        re   r   zRenderable._get_model5  s
    . "!rf   c                p    |y|j                   d   }|t        j                  v rt        j                  |= yy)z
        Clean up method which is called when a Viewable is destroyed.

        Pgarameters
        -----------
        root: bokeh.model.Model
          Bokeh model for the view being cleaned up
        Nr   )r   r)   r   )ra   r   r   s      re   _cleanupzRenderable._cleanupN  s6     <hhtn%.. s# !rf   c                    || n|}| j                   | j                  z   }|D ]B  }t        t        j                  |      j
                        dk\  r || |||       : || |       D y)a  
        Applies preprocessing hooks to the root model.

        Some preprocessors have to always iterate over the entire
        model tree but others only have to update newly added models.
        To support the optimized case we optionally provide the
        Panel object that was changed and any old, unchanged models
        so they can be skipped (see https://github.com/holoviz/panel/pull/4989)
        N   )_preprocessing_hooks_hooksleninspect	signature
parameters)ra   r   changed
old_modelshookshooks         re   _preprocesszRenderable._preprocess]  sc     "/$w))$++5D7$$T*556!;T4*5T4 	 rf   c           
     T   |
t               }|t        j                  j                         }| j	                  ||      }t
        j                  rMt        | ||t
        j                  t
        j                  t
        j                  t
        j                  d       |S t        ||       |S NF)jsonjson_prefix	save_path	load_pathprogress)r   r)   r  get_server_commr   r   embedr   
embed_jsonembed_json_prefixembed_save_pathembed_load_pathr   ra   r<   r   r  s       re   _render_modelzRenderable._render_modelo  s    ;*C<&&668Dc4(<<eS#..$*$<$<"("8"8"("8"8!&(  uc"rf   c                    | j                   j                         j                         D ci c]  \  }}|	|| c}}S c c}}w r   )rX   valuesitems)ra   kvs      re   _init_paramszRenderable._init_params  s>    !%!2!2!4!:!:!<N!<A1!<NNNs
   
A A c                    |j                   }|| j                  vry| j                  |   }|j                  d   }| j                  |       | j                  |= |t        j
                  v rt        j
                  |= yy)zL
        Server lifecycle hook triggered when session is destroyed.
        Nr   )	_documentr  r   r(  r)   r   )ra   r   r<   r   r   s        re   r   zRenderable._server_destroy  sn     ''doo%s#hhtndOOC %,,S! rf   c                ~    dj                  t        |       j                  dj                  t	        |                   S )Nz{cls}({params})z, )clsrb   )formatr^   rg   r   r+   )ra   depths     re   __repr__zRenderable.__repr__  s9     ''DJ,?,?/3yyT9J/K ( M 	Mrf   c                   t        |      }| j                  rz|st        j                  rh|j                  s\| j                  j                  |       }|| u r'| j                  ||      }|r%| j                  |       n|j                  |||      }|}n(| j                  ||      }| }|r| j                  |       |j                  d   }||||ft        j                  |<   |S )a  
        Returns the root model and applies pre-processing hooks

        Parameters
        ----------
        doc: bokeh.Document
          Bokeh document the bokeh model will be attached to.
        comm: pyviz_comms.Comm
          Optional pyviz_comms when working in notebook
        preprocess: boolean (default=True)
          Whether to run preprocessing hooks

        Returns
        -------
        Returns the bokeh model corresponding to this panel object
        )r   r   )r   _designr)   r   r   _wrapperr   r5  r   r   r   )ra   r<   r   
preprocesswrapperr   	root_viewr   s           re   r   zRenderable.get_root  s    ( (,<<Te&7&7@S@Sll++D1G$s6$$T*''T:>I??3T?2DI  &hhtn&c48Srf   )r   r   r  r   r   r  )NNN)
r<   r   r   r   r&  r   r   Comm | Noner   r-   r   )r   r   r   r  NN)r   r-   r   r  r<   Document | Noner   rX  r   r-   )r   zMapping[str, Any])r   r.   r   r  )r   )rP  r   r   r   NNT)r<   r[  r   rX  rU  r   r   r-   )rg   rh   ri   rj   _Renderable__abstractr`   r"  r   r(  r5  rD  rJ  r   rQ  r   r{   r|   s   @re   r  r    s     JN 29 S 379=""#/""+6" 
"2$!$$O"M
 @D%"%1<%% 
%rf   r  c                      e Zd ZU dZ ej
                  d      Zg Zded<    fdZ	e
ej                  dd              Zd Zdd	ZdddZddZddZddZ	 d	 	 	 d dZdddddd
di f	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZd
d
d
i ddddddd
di d
f	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d"dZ	 	 d#	 	 	 	 	 	 	 d$dZ xZS )%Viewablea  
    Viewable is the baseclass all visual components in the panel
    library are built on. It defines the interface for declaring any
    object that displays itself by transforming the object(s) being
    wrapped into models that can be served using bokeh's layout
    engine. The class also defines various methods that allow Viewable
    objects to be displayed in the notebook and on bokeh server.
    zs
        Whether or not the Viewable is loading. If True a loading spinner
        is shown on top of the Viewable.)r<   z1ClassVar[list[Callable[[Viewable, Model], None]]]r+  c                x   |j                  dg       }t        |   di | || _        | j                  r| j                          | j                          | j                  j                  | j                  j                  | j                  d      | j                  j                  | j
                  d      g       y )Nr3  rT   loadingrU   )r[   r_   r`   r,  ra  _update_loading_update_designr  r   rX   watch)ra   rb   r3  rd   s      re   r`   zViewable.__init__  s    

7B'"6"<<  "  ''JJT00(;JJT119=)
 	rf   c                     | |      S )N)themerU   )rT   rf  s     re   _instantiate_designzViewable._instantiate_design  s     E""rf   c                    ddl m} ddlm} t	        | j
                  |      r| j
                  | _        y | j
                  xs |}| j                  |t        j                         | _        y )Nr   r5   )Native)	rf  r6   theme.nativeri  r   rT   rS  rg  r   )ra   r   r6   ri  rT   s        re   rc  zViewable._update_design  sG    !(dkk6*;;DL[[*FF33FFLLIDLrf   c                J    | j                   rt        |        y t        |        y r   )ra  r   r   )ra   r   s     re   rb  zViewable._update_loading  s    <<!$' &rf   Nc           
        |
t               }|t        j                  j                         }| j	                  ||      }| j
                  rE| j
                  j                  j                  r%| j
                  j                  j                  |_        t        j                  rMt        | ||t        j                  t        j                  t        j                  t        j                  d       |S t        ||       |S r7  )r   r)   r  r=  r   rS  rf  bokeh_themer   r>  r   r?  r@  rA  rB  r   rC  s       re   rD  zViewable._render_model  s    ;*C<&&668Dc4(<<DLL..::**66CI<<eS#..$*$<$<"("8"8"("8"8!&(  uc"rf   c                b   t         j                  r ddlm}m}m} |s |       }d || |      ii fS t        j                  }|s,dt        j                  v rdd l
}|j                  j                  }t        j                  dv rt        |       }	t        |	d      r|	j!                  ||      i fS t#        |	      }
t%        |
      d	kD  r|
d d	 d
z   }
d|
i}|	j&                  dd|	j(                  d|d<   t        j                  dk(  rddlm}  ||d       ddii fS |i fS |s| j.                  j1                  d       y t        j                  dk(  rddlm}  |t        j6                         	 ddlm}  |       j<                  J t>        t         _         t         jD                  sddl#m$}  |       xt         _%        }nd }tM               }t         j@                  jO                         }| jQ                  ||      }t        jR                  rtU        |      S | jW                  ||||      \  }}t        jX                  dk7  r_t         j                  sOddlm} |jZ                  d   } |t]        j^                         j`                        }|g ft         jb                  |<   ||fS # tB        $ r Y w xY w)Nr   )r   r   render_scriptr   	holoviewsr   )vscode
ipywidgets_repr_mimebundle_)includeexcluden   u   …z
text/plainr   )version_majorversion_minormodel_idz(application/vnd.jupyter.widget-view+jsonrq  )displayTr   z!<div style="display: none"></div>zDisplaying Panel objects in the notebook requires the panel extension to be loaded. Ensure you run pn.extension() before displaying objects in the notebook.colab)load_notebook)get_ipythonr1   r   r   )
display_id)2r)   r   r   r   r   ro  r   _loadedr   r   rp  	extensionr   commsr!   hasattrrs  reprr-  
_view_name	_model_idIPython.displayrz  rX   rY   io.notebookr|  inlineIPythonr}  kernelJupyterCommManagerr  r   r   r   r2   	_locationr   r=  rD  r>  r$   r  r   r   uuiduuid4hexr   )ra   rt  ru  r   r   ro  r   loadedhvwidget	plaintextdatarz  r|  r}  r2   r   r<   r   r  bundlemetar   r   s                           re   rs  zViewable._repr_mimebundle_  sv     -/#]4%@A2EE ((+4"\\))F<<33t_Fv23///QSUUUVI9~#%dsOe3	iD   ,%&%& & 0 0D?@
 ||x'3$'#%HI2MM8OJJ  E F <<7"2&--(	+=''333"4E ||-)13EOhHj""224""3-<<&&..uc4J  I-e6G6G/))D/C

(8(89F#)2,ENN3t|3  		s   ,(J! !	J.-J.c                "    | j                         S r   )rQ  ra   s    re   __str__zViewable.__str__U  s    }}rf   c           	     N    t        |       } t        |       di t        |fi |S )z
        Makes a copy of the object sharing the same parameters.

        Parameters
        ----------
        params: Keyword arguments override the parameters on the clone.

        Returns
        -------
        Cloned Viewable object
        rU   )r,   r^   dict)ra   rb   	inheriteds      re   clonezViewable.clone\  s,     *$/	tDz6D5f566rf   c                    |?t        |t              rt        | |      s#t        |      rt        |t              s ||       r| gS g S )a  
        Iterates over the Viewable and any potential children in the
        applying the Selector.

        Parameters
        ----------
        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)
        )r   r^   callable)ra   selectors     re   r   zViewable.selectk  sA    " $'JtX,Fh
8T(BxPT~6MIrf   i     F z./c	                (    t        | ||||||||	      S )a  
        Renders a static version of a panel in a notebook by evaluating
        the set of states defined by the widgets in the model. Note
        this will only work well for simple apps with a relatively
        small state space.

        Parameters
        ----------
        max_states: int
          The maximum number of states to embed
        max_opts: int
          The maximum number of states for a single widget
        json: boolean (default=True)
          Whether to export the data to json files
        json_prefix: str (default='')
          Prefix for JSON filename
        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.
        progress: boolean (default=False)
          Whether to report progress
        states: dict (default={})
          A dictionary specifying the widget values to embed for each widget
        )r"   )	ra   
max_statesmax_optsr8  r9  r:  r;  r<  statess	            re   r>  zViewable.embed  s%    < *hk9x
 	
rf   Tc                8    t        | |||||||||	|
|||||fi |S )a  
        Saves Panel objects to file.

        Parameters
        ----------
        filename: str 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)
        template:
           passed to underlying io.save
        template_variables:
           passed to underlying io.save
        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.
        progress: boolean (default=True)
          Whether to report progress
        embed_states: dict (default={})
          A dictionary specifying the widget values to embed for each widget
        as_png: boolean (default=None)
          To save as a .png. If None save_png will be true if filename is
          string and ends with png.
        r%   )ra   filenamer   	resourcesr   template_variablesr>  r  r  r?  r9  r:  r;  r<  embed_statesas_pngr   s                    re   r&   zViewable.save  s@    \ (E9hz8Y	8&	
 %+	
 	
rf   c                   t        |      }|s|j                  dk(  r|xs d}||_        |j                  t        j                         |j                  | j
                         | j                  ri| j                  j                  |       }|| u r| j                  |      }nI|j                  |      }|j                  d   }|||dft        j                  |<   n| j                  |      }|| j                  |<   t        ||       |r| j                  |||       t        j                  rM|t        j                   u r;t        j                  }|r)|j                  |      }d|_        |j%                  |       t        j&                  rN|t        j                   u r<t        j&                  }	|	r*|	j)                  ||      }
d|
_        |j%                  |
       |S )aR  
        Returns a serveable bokeh Document with the panel attached

        Parameters
        ----------
        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
        zBokeh ApplicationzPanel Applicationr   Nnotificationsbrowser_info)r   r   r   r)   _destroy_sessionr   rS  rT  r   r   r   r  r   r   r   r  r   r   r   r  r   )ra   r<   r   r   rV  r  r   notificationnotification_modelbrowserbrowser_models              re   r   zViewable.server_doc  s   . smCII!4400ECI 	  !7!78  !5!56<<ll++D1G$c*((-iio%,eS$$?S!MM#&E$5#sHe4C5<<$7 ..L%1%:%:3%?"*9"'/03%,,#6((G ' 2 23 >%3"]+
rf   )rT   ztype[Design]rf  r   r   r6   )r   r  rY  rZ  )r   r   r   r_  r   )r  z(type | Callable[[Viewable], bool] | Noner   zlist[Viewable])r  r   r  r   r8  r   r9  r   r:  r   r;  r   r<  r   r   r3   ) r  zstr | os.PathLike | IOr   r   r  zResources | Noner   zstr | Template | Noner  zdict[str, Any]r>  r   r  r   r  r   r?  r   r9  r   r:  r   r;  r   r<  r   r  zdict[Any, Any]r  zbool | Noner   r  r\  )r<   r[  r   r   r   r   r   r   )rg   rh   ri   rj   rX   rx   ra  r+  __annotations__r`   staticmethodr	  cacherg  rc  rb  rD  rs  r  r  r   r>  r&   r   r{   r|   s   @re   r_  r_    s    emm !, -G OQKP __#  #J'*Ob7  DH@	2 !%aedr!
!
03!
?C!
!
*-!
AK!
 !
 
	!
H EI&*d-/ueD$b"3
.3
7A3
#3
6K3
 +3
 9=3
 	3
 +.	3
 @D	3

 3

 ),3

 >H3
 3
 .<3
 3
 
3
l @D$(;";2<;!; 
;rf   r_  c                      e Zd ZdZddZd Z	 	 d		 	 	 	 	 	 	 	 	 d
dZej                  j                  e_        	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZej                  j                  e_        ddZ	y)Viewera  
    A baseclass for custom components that behave like a Panel object.
    By implementing __panel__ method an instance of this class will
    behave like the returned Panel component when placed in a layout,
    render itself in a notebook and provide show and servable methods.
    c                    t         )zL
        Subclasses should return a Panel component to be rendered.
        r$  r  s    re   	__panel__zViewer.__panel__!  s
     "!rf   c                    ddl m} ddlm} t	        | j
                  d      r || j
                  d      }|S  || j                               }|S )Nr   panel)ParamMethod_dinfoT)lazy)paner  rX   r  r  r  )ra   r  r  views       re   _create_viewzViewer._create_view'  sE    &4>>8,t~~D9D  )*Drf   Nc                F    | j                         j                  ||||      S r   )r  r   )ra   r   r   r   r   s        re   r   zViewer.servable2  s$       "++E8T6JJrf   c	           
     R     | j                         j                  ||||||||fi |	S r   )r  r   r   s
             re   r   zViewer.show:  s=    
 (t  "''4"2HT8
'-
 	
rf   c                B    | j                         j                  ||      S r   )r  rs  )ra   rt  ru  s      re   rs  zViewer._repr_mimebundle_F  s      "44WgFFrf   r  r   )
r   r   r   r   r   r   r   r   r   r_  r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   zthreading.Thread | ServerrY  )
rg   rh   ri   rj   r  r  r   r~   r   rs  rU   rf   re   r  r    s    "	 CG15KK0?KK$.K 
K %--55H NRUY7;

.1
@J
$
7;
NR
 
 &5
 
#	
 !%%--DLGrf   r  c                       e Zd ZdZej
                  	 d
dddddddddddddd       Zeedf fd	Zd Z	e
 fd	       Z xZS )Childz
    A Parameter type that holds a single `Viewable` object.

    Given a non-`Viewable` object it will automatically promote it to a `Viewable`
    by calling the `pn.panel` utility.
    NTF)is_instance
allow_Noner<   label
precedenceinstantiater\   r]   pickle_default_valueper_instance
allow_refsr=   c                    y r   rU   )ra   r;   r  r  r<   r  r  r  r\   r]   r  r  r  r=   s                 re   r`   zChild.__init__R  s     	rf   c          
        t        |t              r(t        |t              st	        dt        |       d      t        |t
              rct        d |D              sQdj                  |D cg c]'  }t        |t              st        t        |            ) c}      }t	        d| d      t        | (  d| j                  |      ||d| y c c}w )Nz2Child.class_ must be an instance of Viewable, not r  c              3  <   K   | ]  }t        |t                y wr   
issubclassr_  .0its     re   	<genexpr>z!Child.__init__.<locals>.<genexpr>a  s     2]V\PR:b(3KV\    or )r;   class_r  rU   )r   r^   r  r_  	TypeErrortupleallr   r   r_   r`   _transform_value)ra   r;   r  r  rb   r  invalidrd   s          re   r`   zChild.__init__\  s    fd#Jvx,HDT&\NRST  &s2]V\2]/]kk6"^6RZPRT\E]3tBx=6"^_GDWIQO  	 	
))'26!	
%+	
	 #_s   +CCc                V    t        |t              s|d t        fvrddlm}  ||      }|S )Nr   r  )r   r_  r   r  r  )ra   valr  s      re   r  zChild._transform_valuek  s)    #x(Sy8I-I#*C
rf   c                D    t         |   || j                  |             y r   r_   __set__r  ra   r   r  rd   s      re   r  zChild.__set__q      T22378rf   r   )rg   rh   ri   rj   typingoverloadr`   r   r_  r  r   r  r{   r|   s   @re   r  r  J  sm     __ %)etTe  #,H 
 9 9rf   r  c                  F     e Zd ZdZeeeef fd	Zd Ze fd       Z	 xZ
S )Childrenz
    A Parameter type that defines a list of ``Viewable`` objects. Given
    a non-Viewable object it will automatically promote it to a ``Viewable``
    by calling the ``panel`` utility.
    c          
        t        |t              r(t        |t              st	        dt        |       d      t        |t
              rct        d |D              sQdj                  |D cg c]'  }t        |t              st        t        |            ) c}      }t	        d| d      d|v rt        d      t        | ,  d| j                  |      ||d| y c c}w )	Nz8Children.item_type must be an instance of Viewable, not r  c              3  <   K   | ]  }t        |t                y wr   r  r  s     re   r  z$Children.__init__.<locals>.<genexpr>  s     5cYbSUjX6NYbr  r  	item_typez;Children does not support item_type, use item_type instead.)r;   r  r  rU   )r   r^   r  r_  r  r  r  r   r   rZ   r_   r`   r  )	ra   r;   r  r?   r  rb   r  r  rd   s	           re   r`   zChildren.__init__}  s     i&z)X/NJ4PY?J[[\]  	5)#5cYb5c2ckk9"a9R
SUW_H`3tBx=9"abGJ7)STU  F"Z[[ 	
))'2	
#)	
 #bs   +CCc                    t        |t              r7|r5ddlm} g }d}|D ]"  } ||      }|||uz  }|j	                  |       $ |r|}|S Nr   r  F)r   listr  r  r   )ra   r  r  newmutatedrI  ns          re   r  zChildren._transform_value  sV    c4 S#CG!H1A:%

1  
rf   c                D    t         |   || j                  |             y r   r  r  s      re   r  zChildren.__set__  r  rf   )rg   rh   ri   rj   r   r_  r`   r  r   r  r{   r|   s   @re   r  r  v  s2     #	)
( 9 9rf   r  c                  >     e Zd Zeef fd	Zd Ze fd       Z xZS )	ChildDictc               L    | j                  |      }t        |   d||d| y )N)r;   r  rU   )r  r_   r`   )ra   r;   r  rb   rd   s       re   r`   zChildDict.__init__  s4     ''0 	
	
8>	
rf   c                    t        |t              r<|r:ddlm} i }d}|j	                         D ]  \  }} ||      }|||uz  }|||<    |r|}|S r  )r   r  r  r  rG  )ra   r  r  r  r  rH  rI  r  s           re   r  zChildDict._transform_value  s^    c4 S#CG		1!H1A:%A $ 
rf   c                D    t         |   || j                  |             y r   r  r  s      re   r  zChildDict.__set__  r  rf   )	rg   rh   ri   r   r`   r  r   r  r{   r|   s   @re   r  r    s(     #	
 9 9rf   r  c                    | j                   syt        | j                   t              rt        d | j                   D              S t	        | j                   t
              S )NFc              3  <   K   | ]  }t        |t                y wr   r  r  rN  s     re   r  z._is_viewable_class_selector.<locals>.<genexpr>  s     N8M:c8,8Mr  )r  r   r  r  r  r_  )class_selectors    re   _is_viewable_class_selectorr    sH      .''/N8M8MNNNn++X66rf   c                    | j                   syt        | j                   t              rt        d | j                   D              S t	        | j                   t
              S )NFc              3  <   K   | ]  }t        |t                y wr   r  r   s     re   r  z$_is_viewable_list.<locals>.<genexpr>  s     M8L:c8,8Lr  )r  r   r  r  r  r_  )
param_lists    re   _is_viewable_listr    sH    *&&.M
8L8LMMMj**H55rf   c                    t        | t        t        f      ryt        | t        j                        rt        |       ryt        | t        j                        rt        |       ryy)a  
    Determines if a parameter uniquely identifies a Viewable type.

    Parameters
    ----------
    parameter : param.Parameter
        The parameter to evaluate.

    Returns
    -------
    bool
        True if the parameter specifies a Viewable type, False otherwise.
    TF)r   r  r  rX   ClassSelectorr  rm   r  )	parameters    re   is_viewable_paramr
    sN     )eX./)U0016QR[6\)UZZ(->y-Irf   )r9   r_  r  )r  zparam.ClassSelectorr   r   )r  z
param.Listr   r   )r	  zparam.Parameterr   r   )jrj   
__future__r   r   r	  r.  r   osr   	threadingr   r  r  collections.abcr   r   r   r   r   r	   rX   bokeh.core.serializationr
   bokeh.documentr   bokeh.resourcesr   jinja2r   r   param.parameterizedr   pyviz_commsr   _paramr   r   r   r   r   ior   io.documentr   r   io.embedr   
io.loadingr   r   io.modelr   r   r  r    r  r!   r"   r#   r$   io.saver&   io.stater'   r(   r)   utilr*   r+   util.parametersr,   bokeh.modelr-   bokeh.server.contextsr.   bokeh.server.serverr/   typing_extensionsr0   r   r2   r3   	io.serverr4   rf  r6   r  r7   r  Parameterizedr9   r~   r   r  r_  r  r  r  rm   r  rt   r  r  r  r
  __all__rU   rf   re   <module>r&     si  	 #     	 
     -   9 # %   3  ) ) +  < ! C /   6 6 % 2!9*&%'*  E !l#$$ l#^d
 d
N?F ?FD]$$o ]@Xz:} Xv
.GU   .Gb)9E )9X*9uzz *9Z9

 9:760rf   