
    BeF                    n   d Z ddlmZ ddlZddlZddlZddlmZmZm	Z	m
Z
mZmZmZ ddlZddlmZ ddlmZmZ ddlmZmZ dd	lmZ d
dlmZ erddlmZ ddlm Z  ddl!m"Z"  G d de          Z# G d de#          Z G d de          Z$ G d de#          Z% G d de#          Z& G d de#          ZdS )zf
Pane class which render various markup languages including HTML,
Markdown, and also regular strings.
    )annotationsN)TYPE_CHECKINGAnyClassVarDictListMappingType   )CDN_DIST)HTMLJSON)HTML_SANITIZERescape)
deprecated   )	ModelPane)Document)Model)Commc                  X     e Zd ZU dZeZded<   ddiZded<   dZd	ed
<   dZ	d fd	Z
 xZS )HTMLBasePanez
    Baseclass for Panes which render HTML inside a Bokeh Div.
    See the documentation for Bokeh Div for more detail about
    the supported options like style and sizing_mode.
    ClassVar[Model]_bokeh_modelobjecttext"ClassVar[Mapping[str, str | None]]_renameTClassVar[bool]_updatesNc                    d|v r)|                     d          |d<   t          ddd            t                      j        dd|i| d S )Nstylestylesz1.4r    )popr   super__init__selfr   params	__class__s      1lib/python3.11/site-packages/panel/pane/markup.pyr'   zHTMLBasePane.__init__+   s^    f%zz'22F8ug111111&11111    N)__name__
__module____qualname____doc___BkHTMLr   __annotations__r   r    _HTMLBasePane__abstractr'   __classcell__r+   s   @r,   r   r      s           %,L++++3;V2DGDDDD#H####J2 2 2 2 2 2 2 2 2 2r-   r   c                      e Zd ZU dZ ej        dd          Z ej        dd          Z ej        e	j
        d          ZdZd	ed
<   dddZded<   g dZded<   edd            ZddZdS )r   a  
    `HTML` panes renders HTML strings and objects with a `_repr_html_` method.

    The `height` and `width` can optionally be specified, to
    allow room for whatever is being wrapped.

    Reference: https://panel.holoviz.org/reference/panes/HTML.html

    :Example:

    >>> HTML(
    ...     "<h1>This is a HTML pane</h1>",
    ...     styles={'background-color': '#F6F6F6'}
    ... )
    Tn
        Whether to disable support for MathJax math rendering for
        strings escaped with $$ delimiters.defaultdocFz7
        Whether to sanitize HTML sent to the frontend.z@
        Sanitization callback to apply if `sanitize_html=True`.NClassVar[float | bool | None]priority)sanitize_htmlsanitize_hookr   r   )r   r?   r@   ClassVar[List[str]]_rerender_paramsobjr   returnfloat | bool | Nonec                   t          |dd          t          |          j        c}t          fddD                       r|dv st	          |d          rt          |t          j                  rdndS t          |t                    rd S d	S )
Nr0    c              3      K   | ]}|v V  	d S r.   r$   .0mmodules     r,   	<genexpr>zHTML.applies.<locals>.<genexpr>\   s'      99f999999r-   )pandasdask)	DataFrameSeries_repr_html_r   g?F)	getattrtyper/   anyhasattr
isinstanceparamParameterizedstrclsrC   namerL   s      @r,   applieszHTML.appliesY   s    sL"55tCyy7I9999&899999 	+++]0K0K+"3(;<<E11#ES!! 	45r-   Dict[str, Any]c                    |dn|}t          |d          r|                                }| j        r|                     |          }t	          t          |                    S )NrG   rR   r   )rV   rR   r?   r@   dictr   r)   rC   r   s      r,   _transform_objectzHTML._transform_objectd   sg    [rrc4'' 	&##%%D 	,%%d++D6$<<((((r-   rC   r   rD   rE   rC   r   rD   r_   )r/   r0   r1   r2   rX   Booleandisable_mathr?   Callabler   cleanr@   r>   r4   r   rB   classmethodr^   rd   r$   r-   r,   r   r   3   s           !5= 4/ 0 0 0L "EM% 6: ; ; ;M #EN>+? FC D D DM /3H2222 3 3G    - - -        [) ) ) ) ) )r-   r   c                      e Zd ZU dZ ej        dd          Z ej        dd          Z ej	        dgd          Z
 ej        d	eeefd
          Z ej        dd          Z ej        dd          Z ej        d	d          Z ej        d	eefd          Z ej        dd          Z ej        dd          Z ej        dd          Z ej        d	dg d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d          Z  ej        dd          Z! ej"        d	d          Z#d gZ$d!e%d"<   g d#Z&d!e%d$<   d% e&d&d'         D             Z'd(e%d)<   e( d*gZ)d!e%d+<   dD fd,	Z*e+dEd1            Z,d2 Z- ej.        d3dd4          d5             Z/	 	 dFdG fd>Z0dDdH fd@Z1dIdBZ2dJdCZ3 xZ4S )KrP   a]  
    The `DataFrame` pane renders pandas, dask and streamz DataFrame types using
    their custom HTML repr.

    In the case of a streamz DataFrame the rendered data will update
    periodically.

    Reference: https://panel.holoviz.org/reference/panes/DataFrame.html

    :Example:

    >>> DataFrame(df, index=False, max_rows=25, width=400)
    Tz0
        Make the row labels bold in the output.r:   r   zX
        A ``border=border`` attribute is included in the opening
        `<table>` tag.zpanel-dfz<
        CSS class(es) to apply to the resulting html table.Nzh
        The minimum width of each column in CSS length units. An int
        is assumed to be px units.)r;   class_r<   .zG
        Character recognized as decimal separator, e.g. ',' in Europe.zm
        Whether or not to escape the dataframe HTML. For security reasons
        the default value is True.z
        Formatter function to apply to columns' elements if they are
        floats. The result of this function must be a unicode string.z
        Formatter functions to apply to columns' elements by position
        or name. The result of each function must be a unicode string.z(
        Whether to print column labels.z-
        Whether to print index (row) labels.z)
        Prints the names of the indexes.)leftrightcenterjustifyzjustify-allstartendinheritzmatch-parentinitialunsetz*
        How to justify the column labels.)r;   
allow_Noneobjectsr<   z+
        Maximum number of rows to display.z.
        Maximum number of columns to display.NaNz-
        String representation of NAN to use.Fz$
        Convert URLs to HTML links.zT
        Display DataFrame dimensions (number of rows by number of
        columns).zs
        Set to False for a DataFrame with a hierarchical index to
        print every multi-index key at each row.zHidden parameter.max_rowsrA   _dask_params)r   _object	bold_rowsborderclasses	col_spacedecimalr   float_format
formattersheaderindexindex_namesrr   r{   max_colsna_reprender_linksshow_dimensionssparsifysizing_moderB   c                    i | ]}|d S r.   r$   )rJ   rps     r,   
<dictcomp>zDataFrame.<dictcomp>   s'     3 3 3D3 3 3r-   r   r   r   zcss/dataframe.css_stylesheetsc                J    d | _          t                      j        |fi | d S r.   )_streamr&   r'   r(   s      r,   r'   zDataFrame.__init__   s/    **6*****r-   rC   r   rD   rE   c                    t          |dd          t          |          j        }t          fddD                       r|dv rdS dS )Nr0   rG   c              3      K   | ]}|v V  	d S r.   r$   rI   s     r,   rM   z$DataFrame.applies.<locals>.<genexpr>   s'      CCVCCCCCCr-   )rN   rO   streamz)rP   rQ   Random
DataFramesSeriessStyler333333?F)rS   rT   r/   rU   r[   s      @r,   r^   zDataFrame.applies   s^    lB//Cyy!CCCC%BCCCCC 	XXX35r-   c                    || _         d S r.   r}   )r)   r   s     r,   _set_objectzDataFrame._set_object   s    r-   r   )watchon_initc                ^   | j         rt          | j        d          sd S | j        r | j                                         d | _        | j        j                                                            d                                          | _        | j        	                    | j
                   d S )Nstreamg      ?)_modelsrV   r   r   destroyr   latest
rate_limitgathersinkr   )r)   s    r,   _setup_streamzDataFrame._setup_stream   s    | 	 74;#A#A 	 F\ 	 L  """DL{)0022==cBBIIKK$*+++++r-   r<   r   rootModel | NoneparentcommComm | Noner   c                x    t                                          ||||          }|                                  |S r.   )r&   
_get_modelr   )r)   r<   r   r   r   modelr+   s         r,   r   zDataFrame._get_model   s9     ""3fd;;r-   Nonec                    t                                          |           | j        s)| j        r$| j                                         d | _        d S d S d S r.   )r&   _cleanupr   r   r   )r)   r   r+   s     r,   r   zDataFrame._cleanup   sa    | 	  	 L  """DLLL	  	  	  	 r-   r_   c                    t          |d          r|                                }t          |dd          }t          |d          rd|v r0|                     j                                      dd          }n\d|v r5d	                     j                  }|                    d
| d          }n# fd j        D             } |j        di |}nd}t          t          |                    S )Nto_framer0   rG   to_htmlrO   )r{   z
border="1"r"    zclass="")table_attributesc                Z    i | ]'}|t           j        v|d k    |t          |          (S r   )r   rX   rS   )rJ   pr)   s     r,   r   z/DataFrame._transform_object.<locals>.<dictcomp>  sE     M M M!l&888Q)^^ WT1--=K^^r-   ra   r$   )rV   r   rS   r   r{   replacejoinr   rB   rb   r   )r)   rC   rL   htmlr   kwargss   `     r,   rd   zDataFrame._transform_object   s   3
## 	!,,..ClB//3	"" 	{{DM{::BB<QSTTF""((4<00{{4Hg4H4H4H{IIM M M Mt7L M M M"s{,,V,,D6$<<((((r-   c                \    t                               |           }| j        r
| j        |d<   |S )Nr   )r   _init_paramsr   r}   )r)   r*   s     r,   r   zDataFrame._init_params  s0    **400< 	,#|F8r-   r.   re   )NNN)
r<   r   r   r   r   r   r   r   rD   r   )r   r   rD   r   rf   )rD   r_   )5r/   r0   r1   r2   rX   rg   r~   Integerr   r   r   ClassSelectorrZ   intrb   r   Stringr   r   ri   r   listr   r   r   r   ObjectSelectorrr   r{   r   r   r   r   r   	Parameterr}   r|   r4   rB   r   r   r   r'   rk   r^   r   dependsr   r   r   rd   r   r6   r7   s   @r,   rP   rP   m   s_          d 13 4 4 4I U]1 +   F ej* 4? @ @ @G $#D#sD9I P& ' ' 'I el3 -J K K KG U]4 .& ' ' 'F "5>$ 5I J J JL %$T4, MJ K K KJ U]4 .+ , , ,F EM$ -0 1 1 1E  %- 3, - - -K #e"4D K> K> K>D-. . .G
 u}T 0. / / /H u}T 01 2 2 2H U\% .0 1 1 1F !5= 5' ( ( (L $emE 8   O u}T 04 5 5 5H eod0GHHHG)3L4444- - -    3 3+AbD13 3 3G    
 &&&)L    + + + + + +    [   U]84666, , 76, 379=                   ) ) ) )&       r-   rP   c                  b    e Zd ZU dZdZded<   eZded<   ddiZd	ed
<   e	dd            Z
ddZdS )Stru8  
    The `Str` pane allows rendering arbitrary text and objects in a panel.

    Unlike Markdown and HTML, a `Str` is interpreted as a raw string without
    applying any markup and is displayed in a fixed-width font by default.

    The pane will render any text, and if given an object will display the
    object’s Python `repr`.

    Reference: https://panel.holoviz.org/reference/panes/Str.html

    :Example:

    >>> Str(
    ...    'This raw string will not be formatted, except for the applied style.',
    ...    styles={'font-size': '12pt'}
    ... )
    r   r=   r>   zClassVar[Type[Model]]r   r   z=JSON.stringify(value).replace(/,/g, ", ").replace(/:/g, ": ")r   _target_transformsrC   r   rD   boolc                    dS )NTr$   r\   rC   s     r,   r^   zStr.applies0  s    tr-   r_   c                    |t          |t                    r	|dk    rd}ndt          |          z   dz   }t          t          |                    S )NrG   z<pre> </pre>z<pre>z</pre>ra   )rW   rZ   rb   r   rc   s      r,   rd   zStr._transform_object4  sP    ;:c3//;C2II!DD3s88#H,D6$<<((((r-   N)rC   r   rD   r   rf   )r/   r0   r1   r2   r>   r4   r3   r   r   rk   r^   rd   r$   r-   r,   r   r     s          & /0H////*1L1111 	U>        [) ) ) ) ) )r-   r   c                      e Zd ZU dZ ej        dd          Z ej        dd          Z ej        g ddd	          Z	 ej        g dd
	          Z
 ej        dg dd          Z ej        i dd	          ZdZded<   dddddddZded<   g dZded<   ddiZded<   e dgZded<   ed'd!            Ze ej        d"          d#                         Zd(d%Z fd&Z xZS ))Markdowna`  
    The `Markdown` pane allows rendering arbitrary markdown strings in a panel.

    It renders strings containing valid Markdown as well as objects with a
    `_repr_markdown_` method, and may define custom CSS styles.

    Reference: https://panel.holoviz.org/reference/panes/Markdown.html

    :Example:

    >>> Markdown("# This is a header")
    Tz>
        Whether to dedent common whitespace across all lines.r:   Fr9   )extrasmarty
codehilitez
        Markdown extension to apply when transforming markup.
        Does not apply if renderer is set to 'markdown-it' or 'myst'.)r;   nested_refsr<   z2
        Additional markdown-it-py plugins to use.markdown-it)r   mystmarkdownz*
        Markdown renderer implementation.r;   ry   r<   z2
        Options to pass to the markdown renderer.Nr=   r>   )dedentrh   
extensionspluginsrendererrenderer_optionsr   r   )r   r   r   css_classesr   rA   rB   r   r   zcss/markdown.cssr   rC   r   rD   rE   c                X    t          |d          rdS t          |t                    rdS dS )N_repr_markdown_r   皙?F)rV   rW   rZ   r   s     r,   r^   zMarkdown.appliest  s6    3)** 	3S!! 	35r-   )maxsizec                ~   |dk    rd S ddl m} ddlm} ddlm} ddlm} ddlm	} ddl
m}	 d	 }
|d
k    rd|vrd|d<    |d||          }n(|dk    r"ddlm}m}  |ddg ddd|} |||          }|                    d                              d                              |d                              |                              |                              |	          }|D ]}|                    |          }	 ddlm} |                    |          }n# t&          $ r Y nw xY w|
|j        d<   |S )Nr   r   )
MarkdownIt)RendererHTML)anchors_plugin)deflist_plugin)footnote_plugin)tasklists_pluginc                r    	 ddl m}  || |                                          S # t          $ r | cY S w xY w)Nr   )
CodeHilite)srclang)markdown.extensions.codehiliter   hilite	Exception)tokenlangnameattrsr   s       r,   r   z$Markdown._get_parser.<locals>.hilite  s^    EEEEEE!ze(;;;BBDDD   s   $' 66r   breaksTzgfm-like)renderer_clsoptions_updater   )MdParserConfigcreate_md_parserr   )colon_fencelinkifysmartquotestasklistattrs_block)heading_anchorsenable_extensionsenable_checkboxesstrikethroughtable)	permalink)emoji_plugin	highlightr$   )markdown_itr   markdown_it.rendererr   mdit_py_plugins.anchorsr   mdit_py_plugins.deflistr   mdit_py_plugins.footnoter   mdit_py_plugins.tasklistsr   myst_parser.parsers.mditr   r   enableusemdit_py_emojir  r   options)r\   r   r   r   r   r   r   r   r   r   r   parserr   r   configpluginr  s                    r,   _get_parserzMarkdown._get_parser}  s3    z!!4******555555::::::::::::<<<<<<>>>>>>	 	 	 }$$///-1 *Z)/  FF
         $^ ;A J J J "&; ; *:; ;F &%fl;;FVO$$VVG__S4S00^1D1DSSEYEYZ]Z]^nZoZo 	
  	( 	(FZZ''FF	222222ZZ--FF 	 	 	D	&,{#s   D# #
D0/D0r_   c                   dd l }|d}n)t          |t                    s|                                }| j        rt          j        |          }| j        dk    r |j         |f| j        dd| j        }n> | j	        | j        t          | j                  fi | j                            |          }t          t          |                    S )Nr   rG   r   html5)r   output_formatra   )r   rW   rZ   r   r   textwrapr   r   r   r  tupler   renderrb   r   )r)   rC   r   r   s       r,   rd   zMarkdown._transform_object  s    ;CCC%% 	(%%''C; 	'/#&&C=J&&$8$?%  '	 DD $4#uT\22 6:6K fSkk  6$<<((((r-   c                l    d|v rdg|d         z   |d<   t                                          |          S )Nr   r   r&   _process_param_changer)   r*   r+   s     r,   r!  zMarkdown._process_param_change  s<    F""%/L6-3H$HF=!ww,,V444r-   re   rf   )r/   r0   r1   r2   rX   rg   r   rh   r   r   r   Selectorr   r   r   r>   r4   r   rB   r   r   r   rk   r^   	functools	lru_cacher  rd   r!  r6   r7   s   @r,   r   r   <  sX          U]4 .A B B BF !5= 5/ 0 0 0L  %) %) %)6: AIJ J JJ
 ej <5 6 6 6G u~m >+ >+ >+1-. . .H "uz"$ E5 6 6 6 /3H2222 DTt3 3G    
- - -    
 	$>    
 %%%)L        [ Y&&&0 0 '& [0d) ) ) ),5 5 5 5 5 5 5 5 5r-   r   c                  ^    e Zd ZU dZ ej        ddd          Z ej        ej	        dd          Z
 ej        dd	
          Z ej        dddgd          ZdZded<   dZded<   eZded<   ddddZded<   g dZded<   e dgZded <   ed,d%            Zd-d'Zd. fd)Zd/ fd+Z xZS )0r   a  
    The `JSON` pane allows rendering arbitrary JSON strings, dicts and other
    json serializable objects in a panel.

    Reference: https://panel.holoviz.org/reference/panes/JSON.html

    :Example:

    >>> JSON(json_obj, theme='light', height=300, width=500)
    r   )r   NzI
        Depth to which the JSON tree will be expanded on initialization.)r;   boundsr<   FzK
        Custom JSONEncoder class used to serialize objects to JSON string.)rm   is_instancer<   z@
        Whether to display a hover preview for collapsed nodes.r:   darklightz;
        Whether the JSON tree view is expanded by default.r   Nr=   r>   Tr   _applies_kwr   r   r   r#   )r   encoderr"   r   r   )r   depthr,  hover_previewthemerA   rB   zcss/json.cssr   rC   r   rD   rE   c                    t          |t          t          f          rC	 t          j        ||                    d| j                             dS # t          $ r Y dS w xY wt          |t                    rdS d S )Nr,  r\   r   Fr   )	rW   r   rb   jsondumpsgetr,  r   rZ   )r\   rC   r*   s      r,   r^   zJSON.applies  s    cD$<(( 
	
3FJJy#+$F$FGGGG s    uu S!! 	14s   /A 
AAr_   c                    	 t          j        |          }n# t          $ r |}Y nw xY wt          j        |pi | j                  }t          |          S )Nr1  ra   )r2  loadsr   r3  r,  rb   )r)   rC   datar   s       r,   rd   zJSON._transform_object  se    	:c??DD 	 	 	DDD	z$*"$,7774    s    &&
propertiesc                |    t                                          |          }d|v r|d         dn|d         |d<   |S )Nr-  r   )r&   _process_property_change)r)   r8  r+   s     r,   r:  zJSON._process_property_change  sI    WW55jAA
j  (27(;(C""T[I\Jwr-   r*   c                    t                                          |          }d|v r|d         dk     rd n|d         |d<   |S )Nr-  r   r   r"  s     r,   r!  zJSON._process_param_change  sI    ..v66f&,Wo&9&9ddvgF7Or-   re   rf   )r8  r_   rD   r_   )r*   r_   rD   r_   )r/   r0   r1   r2   rX   r   r-  r   r2  JSONEncoderr,  rg   r.  r   r/  r>   r4   r+  _BkJSONr   r   rB   r   r   rk   r^   rd   r:  r!  r6   r7   s   @r,   r   r     s        	 	 EM!J =L M M ME "e!)9u SN O O OG "EM% 6C D D DM !E '69J Q> ? ? ?E /3H2222"&K&&&&$+L++++ TH3 3G    - - -    
 !!!)L        [! ! ! !              r-   r   )'r2   
__future__r   r$  r2  r  typingr   r   r   r   r   r	   r
   rX   io.resourcesr   modelsr   r3   r   r=  utilr   r   util.warningsr   baser   bokeh.documentr   bokeh.modelr   pyviz_commsr   r   rP   r   r   r$   r-   r,   <module>rH     sn    # " " " " "                         # # # # # # 5 5 5 5 5 5 5 5 ) ) ) ) ) ) ) ) & & & & & &       !''''''!!!!!!      2 2 2 2 29 2 2 2.7) 7) 7) 7) 7)< 7) 7) 7)td d d d d d d dN%) %) %) %) %), %) %) %)PN5 N5 N5 N5 N5| N5 N5 N5dJ J J J J< J J J J Jr-   