o
    i='                     @  s  U d dl mZ d dlZd dl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mZmZ d dlZd dlmZmZ d dlmZmZ d	d
lmZ erSd	dlmZ dZdZ	 ed Z	 ddeddddd8d d!Z d9d%d&Z!d:d*d+Z"d;d/d0Z#G d1d2 d2ed3d4Z$d5Z%d6e&d7< dS )<    )annotationsN)IterableSequence)Path)indent)TYPE_CHECKING	AnnotatedAnyLiteral	TypeAlias)GeLe)	TypedDictUnpack   )BaseNode)Graph)	NodeIdentDEFAULT_HIGHLIGHT_CSSgenerate_codeMermaidConfigrequest_image
save_imageStateDiagramDirectionzfill:#fdff32)TBLRRLBTT)
start_nodehighlighted_nodeshighlight_csstitleedge_labelsnotesgraphGraph[Any, Any, Any]r   &Sequence[NodeIdent] | NodeIdent | Noner   r    strr!   
str | Noner"   boolr#   	directionStateDiagramDirection | Nonereturnc               C  s  t t|pd}|D ]}	|	| jvrtd|	 dq
g }
|r&dd| dg}
|
d |dur7|
d|  | j D ]\}	}|	|v rL|
d	|	  |jra| jD ]}|
d
|	 d|  qRn$|j D ]\}}d
|	 d| }|r|jr|d|j 7 }|
| qf|j	 }rd
|	 d}|r|jr|d|j 7 }|
| |r|j
r|
d|	  tdd|j
}|
t|d |
d q<|r|
d |
d|  t|D ]}	|	| jvrtd|	 d|
d|	 d qd|
S )ad  Generate [Mermaid state diagram](https://mermaid.js.org/syntax/stateDiagram.html) code for a graph.

    Args:
        graph: The graph to generate the image for.
        start_node: Identifiers of nodes that start the graph.
        highlighted_nodes: Identifiers of nodes to highlight.
        highlight_css: CSS to use for highlighting nodes.
        title: The title of the diagram.
        edge_labels: Whether to include edge labels in the diagram.
        notes: Whether to include notes in the diagram.
        direction: The direction of flow.


    Returns:
        The Mermaid code for the graph.
     zStart node "z" is not in the graph.z---ztitle: zstateDiagram-v2Nz  direction z
  [*] --> z  z --> z: z --> [*]z  note right of z
{2,}
z    z
  end note zclassDef highlighted zHighlighted node "zclass z highlighted)set	_node_ids	node_defsLookupErrorappenditemsreturns_base_nodenext_node_edgeslabelend_edgenoteresubr   join)r$   r   r   r    r!   r"   r#   r*   start_node_idsnode_idlinesnode_defnext_node_idedgeliner9   
clean_docsr-   r-   \/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/pydantic_graph/mermaid.pyr   )   sT   











r   node_identsSequence[NodeIdent] | NodeIdentIterable[str]c                 c  sT    t | tr
| f}nt | tr| }n| f}|D ]}t |tr"|V  q| V  qdS )z5Get the node IDs from a sequence of node identifiers.N)
isinstancer'   r   get_node_id)rG   	node_iternoder-   r-   rF   r1   u   s   


r1   kwargsUnpack[MermaidConfig]bytesc                K  s  t | |d|d|dt|d|dd|dd|dd	}t|  }i }|d
dkrYd| }|drDd|d< |drMd|d< |d }rX||d< n|d
dkrfd| }nd| }|d
 }rv||d< |d }r||d< |d }	r|	|d< |d }
r|
|d< |d }r||d< |d }r||d< |dpt }|j||d}|j	stj
|j d |j |j|d!|jS )"a	  Generate an image of a Mermaid diagram using [mermaid.ink](https://mermaid.ink).

    Args:
        graph: The graph to generate the image for.
        **kwargs: Additional parameters to configure mermaid chart generation.

    Returns:
        The image data.
    r   r   r    r!   r"   Tr#   r*   )r   r   r    r!   r"   r#   r*   
image_typepdfzhttps://mermaid.ink/pdf/pdf_fitr/   fitpdf_landscape	landscape	pdf_paperpapersvgzhttps://mermaid.ink/svg/zhttps://mermaid.ink/img/typebackground_colorbgColorthemewidthheightscalehttpx_client)paramsz error generating image:
)requestresponse)r   getr   base64	b64encodeencodedecodehttpxClient
is_successHTTPStatusErrorstatus_codetextrc   content)r$   rN   codecode_base64rb   urlrW   rQ   r[   r]   r^   r_   r`   ra   rd   r-   r-   rF   r      sZ   







r   path
Path | strNonec                K  sZ   t | tr	t| } d|vr| j dd }|dv r||d< t|fi |}| | dS )a,  Generate an image of a Mermaid diagram using [mermaid.ink](https://mermaid.ink) and save it to a local file.

    Args:
        path: The path to save the image to.
        graph: The graph to generate the image for.
        **kwargs: Additional parameters to configure mermaid chart generation.
    rQ   r   N)pngwebprY   rR   )rJ   r'   r   suffixlowerr   write_bytes)rt   r$   rN   ext
image_datar-   r-   rF   r      s   
r   c                   @  s   e Zd ZU dZded< 	 ded< 	 ded< 	 ded< 	 d	ed
< 	 d	ed< 	 ded< 	 d	ed< 	 d	ed< 	 ded< 	 ded< 	 ded< 	 ded< 	 ded< 	 ded< 	 ded< 	 ded< dS )r   z1Parameters to configure mermaid chart generation.rH   r   r   r'   r    r(   r!   r)   r"   r#   z,Literal['jpeg', 'png', 'webp', 'svg', 'pdf']rQ   rS   rU   zYLiteral['letter', 'legal', 'tabloid', 'ledger', 'a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6']rW   r[   z/Literal['default', 'neutral', 'dark', 'forest']r]   intr^   r_   zAnnotated[float, Ge(1), Le(3)]r`   zhttpx.Clientra   r   r*   N)__name__
__module____qualname____doc____annotations__r-   r-   r-   rF   r      sH   
 r   F)totalz=type[BaseNode[Any, Any, Any]] | BaseNode[Any, Any, Any] | strr   r   )r$   r%   r   r&   r   r&   r    r'   r!   r(   r"   r)   r#   r)   r*   r+   r,   r'   )rG   rH   r,   rI   )r$   r%   rN   rO   r,   rP   )rt   ru   r$   r%   rN   rO   r,   rv   )'
__future__r   _annotationsrf   r;   collections.abcr   r   pathlibr   textwrapr   typingr   r   r	   r
   r   rj   annotated_typesr   r   typing_extensionsr   r   nodesr   r$   r   __all__r   r   r   r1   r   r   r   r   r   r-   r-   r-   rF   <module>   s>    	
L

A2