U
    /ed                  	   @  s>  d Z ddlmZ ddlZeeZddlmZ ddl	m
Z
mZmZmZmZ e
rZddlmZ ddlmZ dd	lmZmZmZmZmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddl m!Z!m"Z"m#Z# e
rddl$m%Z% ddlm&Z& ddl'm(Z( dZ)dddddZ*di fdddddddddd Z+d&d!dd"d"dd#d$d%Z,dS )'z: Generate various HTML elements from Bokeh render items.

    )annotationsN)escape)TYPE_CHECKINGAnyDictListTuple)Template   )serialize_json)DOC_JSFILEMACROSPLOT_DIV_env)DEFAULT_TITLE)settings)make_id   )
RenderItem)wrap_in_onloadwrap_in_safelywrap_in_script_tag)ID)DocJson)Bundle)div_for_render_itemhtml_page_for_render_itemsscript_for_render_itemsr   str)itemreturnc                 C  s   t j| tdS )z Render an HTML div for a Bokeh render item.

    Args:
        item (RenderItem):
            the item to create a div for

    Returns:
        str

    )docmacros)r   renderr   )r     r%   8/tmp/pip-unpacked-wheel-f5fndrjf/bokeh/embed/elements.pyr   K   s    r   zBundle | Tuple[str, str]zDict[ID, DocJson]zList[RenderItem]zTemplate | str | NonezDict[str, Any])bundle	docs_jsonrender_itemstitletemplatetemplate_variablesr!   c                 C  s   |dkrt }| \}}t }tt|dd}	t|	d|}	tt||}
| }|t||||	|
 |t	t
d t|dkr|d d |d	< |d	 j|d
< ddd |D |d< |dkrt	}nt|trtd| }||}|S )a   Render an HTML page from a template and Bokeh render items.

    Args:
        bundle (tuple):
            a tuple containing (bokehjs, bokehcss)

        docs_json (JSON-like):
            Serialized Bokeh Document

        render_items (RenderItems)
            Specific items to render from the document and where

        title (str or None)
            A title for the HTML page. If None, DEFAULT_TITLE is used

        template (str or Template or None, optional) :
            A Template to be used for the HTML page. If None, FILE is used.

        template_variables (dict, optional):
            Any Additional variables to pass to the template

    Returns:
        str

    NFquotezapplication/json)r*   bokeh_js	bokeh_cssZplot_scriptdocsbaser#   r   r1   r   r"   roots
c                 s  s   | ]}t |V  qd S )N)r   .0r    r%   r%   r&   	<genexpr>   s     z-html_page_for_render_items.<locals>.<genexpr>Zplot_divz{% extends base %}
)r   r   r   r   r   r   copyupdatedictr   r   lenr3   join
isinstancer   r   Zfrom_stringr$   )r'   r(   r)   r*   r+   r,   r/   r0   Zjson_idjsonscriptcontexthtmlr%   r%   r&   r   X   s6    


r   zID | Dict[ID, DocJson]z
str | None)docs_json_or_idr)   app_pathabsolute_urlr!   c                 C  s   t | trd|  d}n<t| dd}t|dd}|dd}|dd	}d| d }tj|td
d |D dd||d}tjst	|}t
|S )a8   Render an script for Bokeh render items.
    Args:
        docs_json_or_id:
            can be None

        render_items (RenderItems) :
            Specific items to render from the document and where

        app_path (str, optional) :

        absolute_url (Theme, optional) :

    Returns:
        str
    zdocument.getElementById('z').textContentF)prettyr-   'z&#x27;\z\\c                 S  s   g | ]}|  qS r%   )Zto_jsonr5   r%   r%   r&   
<listcomp>   s     z+script_for_render_items.<locals>.<listcomp>)r(   r)   rC   rD   )r=   r   r   r   replacer   r$   r   devr   r   )rB   r)   rC   rD   r(   Zjsr%   r%   r&   r      s     
r   )NN)-__doc__
__future__r   logging	getLogger__name__logrA   r   typingr   r   r   r   r   Zjinja2r	   Zcore.json_encoderr   Zcore.templatesr   r   r   r   r   Zdocument.documentr   r   Zutil.serializationr   utilr   wrappersr   r   r   Z
core.typesr   r   r'   r   __all__r   r   r   r%   r%   r%   r&   <module>   s4   
	C   