
    Bef$                       d Z ddlm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 ddlmZ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'm(Z(mZm)Z)m*Z* ddl+m+Z+ erddl,m-Z- ddl.m/Z/ ddl0m1Z1 dZ2e2ej        j3        _2        edddfdFd Z4dGd$Z5de&i dd%fdHd2Z6ddddd%d3d4d%d5d6dd7i dfdIdEZ7dS )JzB
Defines utilities to save panel objects to files as HTML or PNG.
    )annotationsN)IOTYPE_CHECKINGAnyDictIterableListOptional)Document)html_page_for_render_items)OutputDocumentFor%standalone_docs_json_and_render_items)get_screenshot_as_png)Model)CDNINLINE	Resources)Comm   )config   )embed_state)
add_to_doc)BASE_TEMPLATECDN_DISTDEFAULT_TITLEr   bundle_resourcesset_resource_mode)state)	ThemeLike)Template)Viewablea  
// add private window prop to check that render is complete
window._bokeh_render_complete = false;
function done() {
  setTimeout(() => { window._bokeh_render_complete = true; }, 500);
}

var doc = Bokeh.documents[0];

if (doc.is_idle)
  done();
else
  doc.idle.connect(done);
   modelr   filenamestrtimeoutintreturnNonec                   ddl m} t          j        s|                                t          _        t          j        }d	 fd}t
          j        j        j        }	|t
          j        j        _        t          | |||          }
|
j
        dk    s|
j        dk    rt          d          |
                    |d	           n# t          $ r  w xY w	 r|	t
          j        j        _        dS dS # r|	t
          j        j        _        w xY w)
a  
    Saves a bokeh model to png

    Arguments
    ---------
    model: bokeh.model.Model
      Model to save to png
    filename: str
      Filename to save to
    resources: str
      Resources
    template:
      template file, as used by bokeh.file_html. If None will use bokeh defaults
    template_variables:
      template_variables file dict, as used by bokeh.file_html
    timeout: int
      The maximum amount of time (in seconds) to wait for
    r   )webdriver_controlNa5  \
        {% block preamble %}
        <style>
        html, body {
        box-sizing: border-box;
            width: 100%;
            height: 100%;
            margin: 0;
            border: 0;
            padding: 0;
            overflow: hidden;
        }
        </style>
        {% endblock %}
        c                Z    t          j        |          }t          | |dpi d          S )N T)titletemplatetemplate_variables_always_new)r   
from_bokeh	file_html)obj	resourceswidthheightkwargsr0   r1   s        -lib/python3.11/site-packages/panel/io/save.pyget_layout_htmlz!save_png.<locals>.get_layout_htmlk   s>    !,Y77IYb8#5#;        )driverr'   r6   zunable to save an empty imagepng)format)bokeh.io.webdriverr,   r   	webdrivercreatebokehioexportr;   r   r7   r8   
ValueErrorsave	Exception)r$   r%   r6   r0   r1   r'   r,   rA   r;   old_layout_fnimgs      ``      r:   save_pngrK   =   sC   , 544444? 5+2244I <	 	 	 	 	 	 7*9'#E)WXabbb9>>SZ1__<===%((((    	)  	<.;EHO+++	< 	<8 	<.;EHO+;;;;s   BC C2 CC2 2DmodelsIterable[Model]r/   c                    ||S | D ] }t          |t                    r	|j        c S !| D ]}|j        |j        j        c S t          S )N)
isinstancer   r/   documentr   )rL   r/   ps      r:   _title_from_modelsrR      su      a"" 	7NNN	  $ $:!:#### " r<   FModel | Document | List[Model]r6   Resources | NoneOptional[str]r0   Template | strr1   Dict[str, Any]themer    r2   boolc           	     t   g }t          | t                    r| g}nt          | t                    r| j        }n| }t          |d<   t          |||          5  t          |d          \  }}	t          ||          }t          ||          }
t          |
||	|||          cd d d            S # 1 swxY w Y   d S )Ndist_url)apply_theme
always_newT)suppress_callback_warning)r/   r0   r1   )
rO   r   r   rootsr   r   r   rR   r   r   )rL   r6   r/   r0   r1   rX   r2   
models_seq	docs_jsonrender_itemsbundles              r:   r4   r4      s&    J&%   X

	FH	%	% \


%-z"	:5[	Q	Q	Q 	
 	
$I$%
 %
 %
!L #:u55!*i88)I|581
 
 
	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
s   A	B--B14B1i     r.   z./Tpanelr"   str | os.PathLike | IOBkResources | NoneTemplate | str | Noneembed
max_statesmax_opts
embed_jsonjson_prefix	save_path	load_pathprogressc                   ddl m} ddlm} t	          | |          rt          | j                  dk    r| j        } |*t	          |t                    o|                    d          }t	          | t                    r| }nt                      }|
t          }d}nt	          |t                    rV|                                dk    r
t          }d}nP|                                dk    r
t          }d}n.t          d	|z            t	          |t                    r|j        }t!                      }t#          j        |
          5  t	          | t                    r| }nt	          | |          rAt'          |          5  |                     ||           ddd           n# 1 swxY w Y   |}nC|                     ||          }|rt-          | |||||	|
||||           nt/          ||d           ddd           n# 1 swxY w Y   |rt1          |f||||d|S t	          |t                    r|                    d          s|dz   }i }|d}|r||d<   |r||d<   t3          j        |d          }t'          |          5  t7          |||fi |}ddd           n# 1 swxY w Y   t9          |d          rFt	          |t:          j                  r|                    d          }|                     |           dS t;          j!        |dd          5 }|                     |           ddd           dS # 1 swxY w Y   dS )a  
    Saves Panel objects to file.

    Arguments
    ---------
    panel: Viewable
      The Panel Viewable to save to file
    filename: str or file-like object
      Filename to save the plot to
    title: str
      Optional title for the plot
    resources: bokeh.resources.Resources
      One of the valid bokeh.resources (e.g. CDN or INLINE)
    template: jinja2.Template | str
      template file, as used by bokeh.file_html. If None will use bokeh defaults
    template_variables: Dict[str, Any]
      template_variables file dict, as used by bokeh.file_html
    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 randomly 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   )PaneBase)BaseTemplater   Nr>   cdninlinez>Resources %r not recognized, specify one of 'CDN' or 'INLINE'.)ri   )r/   T)r6   r%   r0   r1   z.htmlPanelr0   r1   )absolutewritezutf-8w)modeencoding)"panerr   r0   rs   rO   lenlayoutr&   endswithr   r   lowerr   rF   BkResourcesrz   r   r   setr   	_init_docget_rootr   r   rK   r   r3   r4   hasattrrD   BytesIOencoderx   open)re   r%   r/   r6   r0   r1   ri   rj   rk   rl   rm   rn   ro   rp   embed_statesas_pngr9   rr   rs   docrz   commr$   htmlfs                            r:   rG   rG      s   `  ''''''%"" s5<'8'81'<'<~Hc**Gx/@/@/G/G%"" jj		Is	#	# ??%%IDD__(**IDD 57@A B B B	I{	+	+ ~66D	%	 	 	  - -eX&& 	-EE|,, 	-"4(( 2 251112 2 2 2 2 2 2 2 2 2 2 2 2 2 2EENN3--E -5#z8ZIx   
 5#t,,,- - - - - - - - - - - - - - -"  &
&H1
 
5;
 
 	
 
Hc	"	" &8+<+<W+E+E &g%F} &%z :'9#$$Y>>>I 
9	%	% : :i99&99: : : : : : : : : : : : : : :x!! h
++ 	(;;w''DtWXC'::: 	aGGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s[   8G=<F G= F$	$G='F$	(A	G==HHJ  J$'J$L;;L?L?)r$   r   r%   r&   r'   r(   r)   r*   )rL   rM   r/   r&   r)   r&   )rL   rS   r6   rT   r/   rU   r0   rV   r1   rW   rX   r    r2   rY   )re   r"   r%   rf   r/   rU   r6   rg   r0   rh   r1   rW   ri   rY   rj   r(   rk   r(   rl   rY   rm   r&   rn   r&   ro   rU   rp   rY   r)   r*   )8__doc__
__future__r   rD   ostypingr   r   r   r   r   r	   r
   rC   bokeh.document.documentr   bokeh.embed.elementsr   bokeh.embed.utilr   r   bokeh.io.exportr   bokeh.modelr   bokeh.resourcesr   r   r   r   pyviz_commsr   r   ri   r   r$   r   r6   r   r   r   r   r   r   bokeh.embed.standaloner    jinja2r!   viewabler"   _WAIT_SCRIPTrE   rK   rR   r4   rG    r<   r:   <module>r      s    # " " " " " 				 				                   , , , , , , ; ; ; ; ; ;        2 1 1 1 1 1       A A A A A A A A A A                                              $000000######  ,  ,/AA< A< A< A< A<F      M)+	
 
 
 
 
@ MQ$(D)-UA%DT4| | | | | | |r<   