Ë
    W¨œj/J  ã                   óx  — d Z ddlmZmZ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 ddlmZ dd	lmZ dd
lZddlmZmZmZ ddlmZ i dd“dd“dd“dd“dd“dd“dd“dd“dd“dd“dd“d d!“d"d#“d$d%“d&d'“d(d)“d*d+“d,d-d.d/d0d1dd2d3d4œ	¥Zd;d5„Zd6„ Zd7„ Z 	 	 	 	 	 	 	 d<d8„Z!	 	 	 	 	 	 	 d=d9„Z"	 	 	 	 	 	 	 d>d:„Z#y
)?zhThis submodule: basic tools for creating svg files from path data.

See also the document.py submodule.
é    )ÚdivisionÚabsolute_importÚprint_function)Úceil)ÚpathÚmakedirs)Ú
gettempdir)Úparse)ÚDrawingÚtext)Útime)ÚwarnNé   )ÚPathÚLineÚis_path_segment)Úopen_in_browserÚaÚaquaÚbÚblueÚcÚcyanÚdÚdarkblueÚeÚ ÚfÚgÚgreenÚhÚiÚjÚkÚblackÚlÚlimeÚmÚmagentaÚnÚbrownÚoÚorangeÚpÚpinkÚqÚ	turquoiseÚredÚsalmonÚtanÚpurpleÚvioletÚwhiteÚyellowÚazure)	ÚrÚsÚtÚuÚvÚwÚxÚyÚzc                 óv   — | D �cg c]  }t         |   ‘Œ }}|rt        |«      D ]  \  }}|rŒ	|||<   Œ |S c c}w ©N)Ú
color_dictÚ	enumerate)r;   Údefault_colorÚchÚ
color_listÚidxr   s         úg/workspace/moltex-experiments/.pixi/envs/default/lib/python3.12/site-packages/svgpathtools/paths2svg.pyÚstr2colorlistrL   2   sI   € Ù+,Ó-©1 R”*˜R“.¨1€JÐ-ÙÜ 
Ö+‰FˆC�ÚØ"/�
˜3’ð ,ð Ðùò .s   …6c                 óB   — t        | t        «      xr t        | «      dk(  S )Né   )Ú
isinstanceÚtupleÚlen)r   s    rK   Úis3tuplerR   ;   s   € Ü�aœÓÒ/¤C¨£F¨a¡KÐ/ó    c                 óx  — g }| D ]Ô  }t        |«      st        |t        «      r |j                  |j	                  «       «       Œ>t        |t
        «      r>|j                  |j                  |j                  |j                  |j                  f«       ŒŒ	 t        |«      }|j                  |j                  |j                  |j                  |j                  f«       ŒÖ t        t        |Ž «      \  }}}}t        |«      }t        |«      }	t        |«      }
t        |«      }||	|
|fS # t        $ r t        d«      ‚w xY w)zñreturns minimal upright bounding box.

    Args:
        paths_n_stuff: iterable of Paths, Bezier path segments, and
            points (given as complex numbers).

    Returns:
        extrema of bounding box, (xmin, xmax, ymin, ymax)

    z^paths_n_stuff can only contains Path, CubicBezier, QuadraticBezier, Line, and complex objects.)r   rO   r   ÚappendÚbboxÚcomplexÚrealÚimagÚ
ValueErrorÚ	TypeErrorÚlistÚzipÚminÚmax)Úpaths_n_stuffÚbbsÚthingÚcomplexthingÚxminsÚxmaxsÚyminsÚymaxsÚxminÚxmaxÚyminÚymaxs               rK   Úbig_bounding_boxrl   ?   s  € ð €CÛˆÜ˜5Ô!¤Z°´tÔ%<Ø�J‰J�u—z‘z“|Õ$Ü˜œwÔ'Ø�J‰J˜Ÿ
™
 E§J¡J°·
±
¸E¿J¹JÐGÕHð8Ü& u›~�Ø—
‘
˜L×-Ñ-¨|×/@Ñ/@Ø(×-Ñ-¨|×/@Ñ/@ðBõ Cð ô "&¤c¨3 i£Ñ€Eˆ5�%˜Üˆu‹:€DÜˆu‹:€DÜˆu‹:€DÜˆu‹:€DØ��t˜TÐ!Ð!øô ò 8Üð !7ó 8ð 8ð8ús   ÂAD$Ä$D9c                 ó0  — d}d}d}d}d}|€$|€dn|}t        j                  t        «       d«      }t        j                  t        j                  |«      «      }t        j
                  |«      st        |«       |rrt        j                  |«      \  }}t        t        «       «      j                  d	d
«      }t        j                  |«      d   dz   |z   |z   }t        j                  ||«      }t        | t        «      st        | «      r| g} | r‰|s|gt        | «      z  }nwt        |«      t        | «      k(  sJ ‚t        |t        «      rt!        ||¬«      }n@t        |t"        «      r0t%        |«      D ]"  \  }} t'        | «      sŒdt        | «      z   ||<   Œ$ |r‰|s|gt        |«      z  }nwt        |«      t        |«      k(  sJ ‚t        |t        «      rt!        ||¬«      }n@t        |t"        «      r0t%        |«      D ]"  \  }} t'        | «      sŒdt        | «      z   ||<   Œ$ | s|sJ ‚g }!|r.t        |t        «      sd|z  }|�€|j                  d«      dd }�ný|r6t)        t+        t        |«      «      }d„ }"dt)        t+        |"|«      «      z  }�nÅ| r|!| z  }!|r|!|z  }!|r|!|z  }!t-        |!«      \  }#}$}%}&|$|#z
  }'|&|%z
  }(|'dk(  rd}'|(dk(  rd}(| rH|s!t/        |'|(«      |z  })|)gt        | «      z  }|)}*n't        | «      t        |«      k(  sJ ‚t/        |«      }*nd}*|rN|s$t/        |'|(«      |z  }+|+gt        |«      z  }d|+z  },n*t        |«      t        |«      k(  sJ ‚dt/        |«      z  },nd},t/        |*|,«      }-|#|	|'z  |-dz  z   z  }#|%|	|(z  |-dz  z   z  }%|'d|	z  |'z  |-z   z  }'|(d|	z  |(z  |-z   z  }(|#›d|%›d|'›d|(›�}|
€%dj1                  |'|«      }.dj1                  |(|«      }/nn|'|(kD  r5t        |
«      |z   }.t        t3        t5        |
|(z  |'z  «      «      «      |z   }/n4t        t3        t5        |
|'z  |(z  «      «      «      |z   }.t        |
«      |z   }/|.|/f}|�L|j7                  d|d   «      |j7                  d|d   «      f}|j7                  d|«      }0t9        d&|||0dœ|¤Ž}1nt9        ||||¬«      }1| r÷t%        | «      D ]é  \  }2}3t        |3t        «      r|3j;                  «       }4n't        |3«      rt        |3«      j;                  «       }4n|3}4|rgd|4i}5||2   D ]9  }6||2   |6   }7|6dk7  sŒ	  |1j<                  |4fi |6|7i¤Ž |5j?                  |6|7i«       Œ; |1jE                   |1j<                  d&i |5¤Ž«       Œ·|1jE                  |1j=                  |4||2   t        ||2   «      d¬«      «       Œë |r`t%        |D �9cg c]  }9|9jF                  |9jH                  f‘Œ c}9«      D ].  \  }:};|1jE                  |1jK                  |;||:   ||:   ¬«      «       Œ0 |�rËt        |t        «      s9t        |t"        «      r't        |t"        «      rt        |«      t        |«      k(  sJ ‚t        |t        «      rA|g}|s|g}|s�tM        #|	'z  z   %|	(z  z   «      }<tO        |<|<dz   «      j;                  «       g}nJ|r9t        |t"        «      rt        |«      t        |«      k(  s!J ‚|gt        |«      z  }n|gt        |«      z  }t%        |«      D ]Ù  \  }}=||   }3t        |3t        «      r|3j;                  «       }4n't        |3«      rt        |3«      j;                  «       }4n|3}4d t        |«      z   }>|1jP                  jE                  |1j=                  |4|>¬!«      «       |1jE                  |1jS                  d
||   ¬"«      «      }?|?jE                  tU        jV                  d#|>z   |=«      «       ŒÛ |r|1S |1jY                  «        t[        |«      j]                  «       }@t_        |d$«      5 }A|Aja                  @«       ddd«       |r	 tc        |«       yy# t@        $ r}8tC        t        |8«      «       Y d}8~8�ŒId}8~8ww xY wc c}9w # 1 sw Y   ŒIxY w#  te        d%«       te        |«       Y yxY w)'a-  Creates (and optionally displays) an SVG file.

    REQUIRED INPUTS:
        :param paths - a list of paths

    OPTIONAL INPUT:
        :param colors - specifies the path stroke color.  By default all paths
        will be black (#000000).  This paramater can be input in a few ways
        1) a list of strings that will be input into the path elements stroke
            attribute (so anything that is understood by the svg viewer).
        2) a string of single character colors -- e.g. setting colors='rrr' is
            equivalent to setting colors=['red', 'red', 'red'] (see the
            'color_dict' dictionary above for a list of possibilities).
        3) a list of rgb 3-tuples -- e.g. colors = [(255, 0, 0), ...].

        :param filename - the desired location/filename of the SVG file
        created (by default the SVG will be named 'disvg_output.svg' or
        'disvg_output_<timestamp>.svg' and stored in the temporary
        directory returned by `tempfile.gettempdir()`.  See `timestamp`
        for information on the timestamp.

        :param stroke_widths - a list of stroke_widths to use for paths
        (default is 0.5% of the SVG's width or length)

        :param nodes - a list of points to draw as filled-in circles

        :param node_colors - a list of colors to use for the nodes (by default
        nodes will be red)

        :param node_radii - a list of radii to use for the nodes (by default
        nodes will be radius will be 1 percent of the svg's width/length)

        :param text - string or list of strings to be displayed

        :param text_path - if text is a list, then this should be a list of
        path (or path segments of the same length.  Note: the path must be
        long enough to display the text or the text will be cropped by the svg
        viewer.

        :param font_size - a single float of list of floats.

        :param openinbrowser -  Set to True to automatically open the created
        SVG in the user's default web browser.

        :param timestamp - if true, then the a timestamp will be
        appended to the output SVG's filename.  This is meant as a
        workaround for issues related to rapidly opening multiple
        SVGs in your browser using `disvg`. This defaults to true if
        `filename is None` and false otherwise.

        :param margin_size - The min margin (empty area framing the collection
        of paths) size used for creating the canvas and background of the SVG.

        :param mindim - The minimum dimension (height or width) of the output
        SVG (default is 600).

        :param dimensions - The (x,y) display dimensions of the output SVG.
        I.e. this specifies the `width` and `height` SVG attributes. Note that 
        these also can be used to specify units other than pixels. Using this 
        will override the `mindim` parameter.

        :param viewbox - This specifies the coordinated system used in the svg.
        The SVG `viewBox` attribute works together with the the `height` and 
        `width` attrinutes.  Using these three attributes allows for shifting 
        and scaling of the SVG canvas without changing the any values other 
        than those in `viewBox`, `height`, and `width`.  `viewbox` should be 
        input as a 4-tuple, (min_x, min_y, width, height), or a string 
        "min_x min_y width height".  Using this will override the `mindim` 
        parameter.

        :param attributes - a list of dictionaries of attributes for the input
        paths.  Note: This will override any other conflicting settings.

        :param svg_attributes - a dictionary of attributes for output svg.
        
        :param svgwrite_debug - This parameter turns on/off `svgwrite`'s 
        debugging mode.  By default svgwrite_debug=False.  This increases 
        speed and also prevents `svgwrite` from raising of an error when not 
        all `svg_attributes` key-value pairs are understood.
        
        :param paths2Drawing - If true, an `svgwrite.Drawing` object is 
        returned and no file is written.  This `Drawing` can later be saved 
        using the `svgwrite.Drawing.save()` method.

    NOTES:
        * The `svg_attributes` parameter will override any other conflicting 
        settings.

        * Any `extra` parameters that `svgwrite.Drawing()` accepts can be 
        controlled by passing them in through `svg_attributes`.

        * The unit of length here is assumed to be pixels in all variables.

        * If this function is used multiple times in quick succession to
        display multiple SVGs (all using the default filename), the
        svgviewer/browser will likely fail to load some of the SVGs in time.
        To fix this, use the timestamp attribute, or give the files unique
        names, or use a pause command (e.g. time.sleep(1)) between uses.

    SEE ALSO:
        * document.py
    g{®Gázt?gü©ñÒMbP?z#000000z#ff0000é   NTzdisvg_output.svgÚ.r   r   Ú_)rG   Úrgbz%s %s %s %sÚ é   é   c                 óf   — t        j                  d| j                  «       «      j                  «       S )Nz	\d*\.?\d*)ÚreÚsearchÚstripÚgroup)r;   s    rK   Ústrip_unitszdisvg.<locals>.strip_units  s"   € Ü—9‘9˜\¨1¯7©7«9Ó5×;Ñ;Ó=Ð=rS   z	0 0 %s %sr   z{}{}ÚwidthÚheightÚdebug)ÚfilenameÚsizer}   )r~   r   r}   ÚviewBoxr   Únone)ÚstrokeÚstroke_widthÚfill)r„   Útp)r   Úid)Ú	font_sizeÚ#r?   z4Failed to open output SVG in browser.  SVG saved to:© )3Úos_pathÚjoinr	   ÚabspathÚdirnameÚexistsr   ÚsplitextÚstrr   ÚreplaceÚsplitrO   r   r   rQ   rL   r\   rF   rR   rP   Úmaprl   r_   ÚformatÚintr   Úgetr   r   r   ÚupdateÚ	Exceptionr   ÚaddrX   rY   ÚcirclerW   r   Údefsr   ÚtxtÚTextPathÚsaveÚmd_xml_parseÚtoprettyxmlÚopenÚwriter   Úprint)BÚpathsÚcolorsr~   Ústroke_widthsÚnodesÚnode_colorsÚ
node_radiiÚopeninbrowserÚ	timestampÚmargin_sizeÚmindimÚ
dimensionsÚviewboxr   Ú	text_pathr‡   Ú
attributesÚsvg_attributesÚsvgwrite_debugÚpaths2DrawingÚbaseunitÚ_default_relative_node_radiusÚ_default_relative_stroke_widthÚ_default_path_colorÚ_default_node_colorÚ_default_font_sizer�   ÚfbnameÚfextÚtstampÚ
stfilenamerJ   r   Ústuff2boundrz   rh   ri   rj   rk   ÚdxÚdyÚswÚmax_stroke_widthr:   Úmax_node_diameterÚextra_space_for_styleÚszxÚszyr}   Údwgr"   r.   ÚpsÚgood_attribsÚkeyÚvalr   rB   Úi_ptÚptÚposr;   ÚpathidÚtxterÚ	xmlstringr   sB                                                                     rK   ÚdisvgrÓ   a   s‡  € ð\ %)Ð!Ø%)Ð"Ø#ÐØ#ÐØÐàÐØ%Ð-‘D°9ˆ	Ü—<‘<¤
£Ð.@ÓAˆä�o‰oœgŸo™o¨hÓ7Ó8€GÜ�>‰>˜'Ô"Ü�Ôñ Ü×'Ñ'¨Ó1‰ˆ�Ü”T“V“×$Ñ$ S¨"Ó-ˆÜ—]‘] 6Ó*¨1Ñ-°Ñ3°fÑ<¸tÑCˆ
Ü—<‘< ¨Ó4ˆô �%œÔ¤/°%Ô"8Ø�ˆÙÙØ)Ð*¬S°«ZÑ7‰Fä�v“;¤# e£*Ò,Ð,Ð,Ü˜&¤#Ô&Ü& vØ5HôJ‘ä˜F¤DÔ)Ü'¨Ö/‘F�C˜Ü •{Ø&+¬c°!«f¡n˜˜sšð 0ñ
 ÙØ.Ð/´#°e³*Ñ<‰Kä�{Ó#¤s¨5£zÒ1Ð1Ð1Ü˜+¤sÔ+Ü+¨KØ:MôO‘ä˜K¬Ô.Ü'¨Ö4‘F�C˜Ü •{Ø+0´3°q³6©>˜ CÒ(ð 5ñ ‘EÐˆ>Ø€KÙÜ˜'¤3Ô'Ø# gÑ-ˆGØÑØ Ÿ™ sÓ+¨A¨aÐ0ŠJÙ	Üœ3œs JÓ/Ó0ˆ
ò	>à¤¤c¨+°zÓ&BÓ CÑCŠáØ˜5Ñ ˆKÙØ˜5Ñ ˆKÙØ˜9Ñ$ˆKÜ!1°+Ó!>Ñˆˆd�D˜$Ø�D‰[ˆØ�D‰[ˆà�Š7ØˆBØ�Š7ØˆBñ Ù Ü˜˜R“[Ð#AÑA�Ø!# ¤S¨£Z¡�Ø#%Ñ ä˜5“z¤S¨Ó%7Ò7Ð7Ð7Ü#& }Ó#5Ñ à Ðñ ÙÜ˜˜B“KÐ"?Ñ?�Ø˜S¤ U£™^�
Ø$% a¡CÑ!ä˜5“z¤S¨£_Ò4Ð4Ð4Ø$%¤c¨*£oÑ$5Ñ!à !Ðä #Ð$4Ð6GÓ HÐØ�˜B‘Ð!6°qÑ!8Ñ8Ñ8ˆØ�˜B‘Ð!6°qÑ!8Ñ8Ñ8ˆØ
ˆa�‰m˜BÑÐ!6Ñ6Ñ6ˆØ
ˆa�‰m˜BÑÐ!6Ñ6Ñ6ˆÚ#'ªªr±2Ð6ˆàˆ>Ø—-‘-  HÓ-ˆCØ—-‘-  HÓ-‰Cà�BŠwÜ˜&“k HÑ,�Üœ#œd 6¨B¡;°Ñ#3Ó4Ó5Ó6¸ÑA‘äœ#œd 6¨B¡;°Ñ#3Ó4Ó5Ó6¸ÑA�Ü˜&“k HÑ,�Ø˜#�Xˆ
ð Ð!Ø$×(Ñ(¨°*¸Q±-Ó@Ø$×(Ñ(¨°:¸a±=ÓAðCˆ
à×"Ñ" 7¨NÓ;ˆÜð (˜x¨jÀñ (Ø&ñ(‰ô ˜x¨jÀØ%ô'ˆñ Ü˜eÖ$‰DˆAˆqÜ˜!œTÔ"Ø—S‘S“U‘Ü  Ô#Ü˜!“W—Y‘Y“[‘à�áØ # R˜y�Ø% aœ=�CØ$ Q™-¨Ñ,�CØ˜c“zð)Ø$˜CŸH™H RÑ6¨C°¨:Ò6Ø(×/Ñ/°°c°
Õ;ð )ð —‘˜˜Ÿ™Ñ0 <Ñ0Õ1à—‘˜Ÿ™ ¨F°1©IÜ.1°-ÀÑ2BÓ.CØ&,ð !ó .õ /ð+ %ñ4 Ü!¹UÓ"C¹U¸ A§F¡F¨A¯F©FÒ#3¸UÑ"CÖD‰HˆD�"Ø�G‰G�C—J‘J˜r :¨dÑ#3¸+ÀdÑ:K�JÓLÕMð Eò Ü˜$¤Ô$¬°D¼$Ô)?Ü)3°I¼tÔ)DÜ),¨Y«¼3¸t»9Ò)Dð	Fð Fô �dœCÔ Ø�6ˆDÙØ/Ð0�	ÙÜ˜d [°¡^Ñ3°T¸KÈ¹NÑ5JÓK�Ü! # s¨Q¡wÓ/×1Ñ1Ó3Ð4‘	áÜ˜i¬Ô.Ü˜y›>¬S°«YÒ6Ð6Ð6à!* ¬c°$«iÑ 7‘Ià/Ð0´3°t³9Ñ<�	Ü –o‰FˆC�Ø˜#‘ˆAÜ˜!œTÔ"Ø—S‘S“U‘Ü  Ô#Ü˜!“W—Y‘Y“[‘à�ð œC ›H‘_ˆFØ�H‰H�L‰L˜Ÿ™ B¨6˜Ó2Ô3Ø—G‘G˜CŸH™H R°9¸S±>˜HÓBÓCˆEØ�I‰I”c—l‘l 3 v¡:¨qÓ1Õ2ð &ñ  Øˆ
à‡H�H„Jô ˜XÓ&×2Ñ2Ó4€IÜ	ˆh˜Ô	 Ø	�‰�	Ô÷ 
ñ ð	Ü˜HÕ%ð øô{  )ò )Ü ¤ Q£ŸLšLûð)üò #D÷\ 
Ð	ûð	ÜÐHÔIÜ�(ŽOús6   Ô+(`?Ö7a*àa/à2a; à?	a'áa"á"a'á/a8á;bc                 ó–   — |€J ‚t        | fi d|“d|“d|“d|“d|“d|“d|“d|“d	|	“d
|
“d|“d|“d|“d|“d|“d|“d|“d|“d|“d|“ŽS )zèCreate SVG and write to disk.

    Note: This is identical to `disvg()` except that `openinbrowser`
    is false by default and an assertion error is raised if `filename
    is None`.

    See `disvg()` docstring for more info.
    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«   r¬   r­   r®   r¯   r   r°   r‡   r±   r²   r³   r´   rµ   s                        rK   Úwsvgr×   ­  só   € ð ÐÐÐÜ�ò 	A™vð 	A±ð 	AÙ,ð	AÙ49ð	Aá(ð	Aá5?ð	Añ  -ð	Añ 9Bð	Añ )ð		Añ 28ð		Añ
 'ð	Añ
 18ð	Añ
 ?Cð	Añ %ð	Añ 1:ð	Añ 'ð	Añ 8Fð	Añ !/ð	Añ  -ð	Añ 8@ð	Að 	ArS   c                 óŽ   — t        | fi d|“d|“d|“d|“d|“d|“d|“d|“d	|	“d
|
“d|“d|“d|“d|“d|“d|“d|“d|“d|“d|“ŽS )zñCreate and return `svg.Drawing` object.

    Note: This is identical to `disvg()` except that `paths2Drawing`
    is true by default and an assertion error is raised if `filename
    is None`.

    See `disvg()` docstring for more info.
    r¥   r~   r¦   r§   r¨   r©   rª   r«   r¬   r­   r®   r¯   r   r°   r‡   r±   r²   r³   r´   rµ   rÕ   rÖ   s                        rK   r´   r´   É  sç   € ô �ò 	A™vð 	A±ð 	AÙ,ð	AÙ49ð	Aá(ð	Aá5?ð	Añ  -ð	Añ 9Bð	Añ )ð		Añ 28ð		Añ
 'ð	Añ
 18ð	Añ
 ?Cð	Añ %ð	Añ 1:ð	Añ 'ð	Añ 8Fð	Añ !/ð	Añ  -ð	Añ 8@ð	Að 	ArS   rD   )NNNNNNNTNçš™™™™™¹?éX  NNNNNNNFFÚpx)NNNNNNNFFrÙ   rÚ   NNNNNNNFFrÛ   )NNNNNNNFFrÙ   rÚ   NNNNNNNFTrÛ   )$Ú__doc__Ú
__future__r   r   r   Úmathr   Úosr   rŠ   r   Útempfiler	   Úxml.dom.minidomr
   rŸ   Úsvgwriter   r   rœ   r   Úwarningsr   rv   r   r   r   Ú	misctoolsr   rE   rL   rR   rl   rÓ   r×   r´   r‰   rS   rK   Ú<module>rå      s�  ðñ÷ AÑ @Ý ß (Ý Ý 1ß )Ý Ý Û 	÷ .Ñ -Ý &ðˆc�6ð Ø�6ðà�6ðð �:ðð �2ð	ð
 �2ðð �7ðð �2ðð �2ðð �2ðð �7ðð �6ðð �9ðð �7ðð �8ðð �6ðð  �;ð!ð" ØØØØØØØØò3€
ó8ò0ò"ðD AEØ37Ø:=Ø:>Ø59Ø.3Ø(,óIðX
 @DØ26Ø;>Ø9=Ø48Ø-2Ø'+óAð8 59Ø>BØBGØ:>Ø59ØBFØEIôArS   