
    p"h                         S r SSKrSSKJr  SSKJr  S rSS jrS rSS jr	S	 r
S
 rS rSS jr " S S\5      rSS jrSSSSSSS.rS rS rS rg)z

.. autofunction:: rgb

.. autofunction:: iterflatlist

.. autofunction:: strlist

.. autofunction:: get_unit

.. autofunction:: split_coordinate

.. autofunction:: split_angle

.. autofunction:: rect_top_left_corner

.. autofunction:: pretty_xml

    N)Path)patternc                 "    [        U [        5      $ N)
isinstancestrvalues    @/var/www/html/env/lib/python3.13/site-packages/svgwrite/utils.py	is_stringr       s    eS!!    c                     S nUR                  5       S:X  a,  S[        U 5      S-  [        U5      S-  [        U5      S-  4-  $ US:X  a  SU" U 5      U" U5      U" U5      4-  $ [        SU-  5      e)a  
Convert **r**, **g**, **b** values to a `string`.

:param r: red part
:param g: green part
:param b: blue part
:param string mode: ``'RGB | %'``

:rtype: string

========= =============================================================
mode      Description
========= =============================================================
``'RGB'`` returns a rgb-string format: ``'rgb(r, g, b)'``
``'%'``   returns percent-values as rgb-string format: ``'rgb(r%, g%, b%)'``
========= =============================================================

c                 <    [        U 5      n U S:  a  Sn U S:  a  Sn U $ )Nr   d   )floatr	   s    r   percentrgb.<locals>.percent8   s(    e19E3;Er   RGBzrgb(%d,%d,%d)   %zrgb(%d%%,%d%%,%d%%)zInvalid mode '%s')upperint
ValueError)rgbmoder   s        r   rgbr   $   sy    ( zz|u#a&3,Ac!fsl!KKK	 %
GAJ
'KKK,t344r   c              #      #    U  H@  n[        US5      (       a(  [        U5      (       d  [        U5       H  nUv   M	     M<  Uv   MB     g7f)z2
Flatten nested *values*, returns an `iterator`.

__iter__N)hasattrr   iterflatlist)valueselementitems      r   r"   r"   J   sC     
 7J''	'0B0B$W-
 . M s   AA
c                     [        U 5      (       a  U $ UR                  [        U 5       Vs/ s H  o"c  M  [        U5      PM     sn5      $ s  snf )z
Concatenate **values** with **sepertator**, `None` values will be excluded.

:param values: `iterable` object
:returns: `string`

)r   joinr"   r   )r#   	seperatorr
   s      r   strlistr)   W   sB     ~~|F7Ka7Kezs5z7Kabbas
   AAc                     [        U [        [        45      (       a  g[        R                  R                  U 5      nU(       a  UR                  S5      $ [        SU -  5      e)z~
Get the `unit` identifier of **coordinate**, if **coordinate** has a valid
`unit` identifier appended, else returns `None`.

N   Invalid format: '%s'r   r   r   r   
coordinatematchgroupr   r.   results     r   get_unitr3   e   sP     *sEl++%%j1F||A/*<==r   c                    [        U [        [        45      (       a  [        U 5      S4$ [        R                  R                  U 5      nU(       a+  [        UR                  S5      5      UR                  S5      4$ [        SU -  5      e)z
Split coordinate into `<number>` and 'unit` identifier.

:returns: <2-tuple> (number, unit-identifier) or (number, None) if no unit-identifier
  is present or coordinate is an int or float.

N   r+   r,   r-   r1   s     r   split_coordinater6   t   so     *sEl++j!4((%%j1Ffll1o&Q88/*<==r   c                    [        U [        [        45      (       a  [        U 5      S4$ [        R                  R                  U 5      nU(       a+  [        UR                  S5      5      UR                  S5      4$ [        SU -  5      e)z
Split angle into `<number>` and `<angle>` identifier.

:returns: <2-tuple> (number, angle-identifier) or (number, None) if no angle-identifier
  is present or angle is an int or float.

Nr5   r+   r,   )r   r   r   r   angler/   r0   r   )r8   r2   s     r   split_angler9      sl     %#u&&ed##]]  'Ffll1o&Q88/%788r   c                    UR                  5       R                  S5      u  p4[        U S   5      u  pV[        U S   5      u  px[        US   5      u  p[        US   5      u  pXj:w  a  [        S5      eX:w  a  [        S5      eUS:X  a  XYS-  -
  nOUS:X  a  XY-
  nOUS	:w  a  [        S
U-  5      eUS:X  a  X{S-  -
  nOUS:X  a  X{-
  nOUS:w  a  [        SU-  5      eU(       a  U< U< 3nU(       a  U< U< 3nXW4$ )a  
Calculate top-left corner of a rectangle.

**insert** and **size** must have the same units.

:param 2-tuple insert: insert point
:param 2-tuple size: (width, height)
:param string pos: insert position ``'vert-horiz'``
:return: ``'top-left'`` corner of the rect
:rtype: 2-tuple

========== ==============================
pos        valid values
========== ==============================
**vert**   ``'top | middle | bottom'``
**horiz**  ``'left'|'center'|'right'``
========== ==============================
-r   r5   z0x-coordinate and width has to have the same unitz1y-coordinate and height has to have the same unitcenterg       @rightleftz!Invalid horizontal position: '%s'middlebottomtopzInvalid vertical position: '%s')lowersplitr6   r   )insertsizeposverthorizxxunityyunitwidthwunitheighthunits                r   rect_top_left_cornerrQ      s   & ))+##C(KDq	*HAq	*HA#DG,LE$T!W-MF~KLL~LMM
N	'	I	&<uDEExO		J	:TABB4Kr   c                   J    \ rS rSrSrSS jr\SS j5       r\SS j5       rSr	g)	AutoID   r5   Nc                 &    U R                  U5        g r   )
_set_value)selfr
   s     r   __init__AutoID.__init__   s    r   c                     Ub  Xl         g g r   )_nextid)clsr
   s     r   rV   AutoID._set_value   s    K r   c                 p    U R                  U5        SU R                  -  nU =R                  S-  sl        U$ )Nzid%dr5   )rV   r[   )r\   r
   retvals      r   next_idAutoID.next_id   s/    u#++%qr    r   )
__name__
__module____qualname____firstlineno__r[   rX   classmethodrV   r`   __static_attributes__rb   r   r   rS   rS      s4    G      r   rS   c                     SSK Js  Jn  [        U 5      S:  a  U R	                  5       S:X  a  gUR                  U 5      nUR                  SU-  S9R                  S5      nSR                  USS 5      $ )	z
Create human readable XML string.

:param xml_string: input xml string without line breaks and indentation
:indent int: how much to indent, by default 2 spaces
:return: xml_string with linebreaks and indentation

r   N     )indent
r5   )	xml.dom.minidomdomminidomlenstripparseStringtoprettyxmlrC   r'   )
xml_stringrm   rq   xml_treeliness        r   
pretty_xmlry      sr     &% :
 0 0 2b 8"":.H  f 5;;DAE99U12Yr   zapplication/x-font-ttfzapplication/x-font-opentypezapplication/font-woffzapplication/font-woff2zapplication/vnd.ms-fontobjectzapplication/font-sfnt)ttfotfwoffwoff2eotsfntc                 \    [         [        U R                  5       5      R                  SS     $ )Nr5   )FONT_MIMETYPESr   rB   suffix)names    r   font_mimetyper      s%    $tzz|,33AB788r   c                 h    [         R                  " U 5      R                  5       n SR                  XS9$ )Nz+data:{mimetype};charset=utf-8;base64,{data})mimetypedata)base64	b64encodedecodeformat)r   r   s     r   base64_datar      s/    D!((*D8???]]r   c                 H    SS K nUR                  SU 5      nU(       a  US   $ g )Nr   zurl\((.*?)\))refindall)textr   r2   s      r   find_first_urlr     s%    ZZ.Fayr   )r   r   r   r   ),)ztop-left)   )__doc__r   pathlibr   svgwrite.datar   r   r   r"   r)   r3   r6   r9   rQ   objectrS   ry   r   r   r   r   rb   r   r   <module>r      s|   &   !"#5L
c>>"9$0fV & * $(#%*#9^
r   