B
     d|)                 @   s  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
 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 d	d
lmZ d	dlmZ d	dlmZ eeZdZdZ eddddZ!ed	ee"ef dddZ#ee" dddZ$e%dZ&d8e"e"e	e" ee" e"dddZ'G dd deZ(G dd  d eZ)G d!d" d"ej*ej+Z,G d#d$ d$eZ-d%d& Z.d'd( Z/d)d* Z0d+d, Z1ej*dd-d.d/Z2ed	e"ee"ef d0d1d2Z3d9e"e"e"e	e" ee" e"d3d4d5Z4G d6d7 d7eZ5dS ):    )	lru_cacheN)AnyDictListOptionalSequenceTuple)nodes)
directives)Sphinx)logging)SphinxDirective
SphinxRole   )compiled)	read_text)WARNING_TYPEzv16.1.1zW.octicon {
  display: inline-block;
  vertical-align: text-top;
  fill: currentColor;
})appreturnc             C   s   |  dt  | dt xdD ]}|  |t| q W x dD ]}|  d| t| q>W | ddd | d	t | j	t
ttftd ftd ftd ftd fd
 d S )NZocticonz_all-octicon)faZfasZfabZfar)ZregularZoutlinedroundZsharpZtwotonez	material-sd_fontawesome_latexFenvzconfig-inited)htmllatexmantextZtexinfo)Zadd_roleOcticonRoleZadd_directiveAllOcticonsFontawesomeRoleMaterialRoleZadd_config_valueconnectadd_fontawesome_pkgadd_nodefontawesomevisit_fontawesome_htmldepart_fontawesome_htmlvisit_fontawesome_latexvisit_fontawesome_warning)r   style r*   `/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/sphinx_design/icons.pysetup_icons   s    

r,   )r   c              C   s   t td} t| S )zLoad all octicon data.zocticons.json)r   r   jsonloads)contentr*   r*   r+   get_octicon_data0   s    
r0   c               C   s   t t  S )zList available octicon names.)listr0   keysr*   r*   r*   r+   list_octicons7   s    r3   z+^(?P<value>\d+(\.\d+)?)(?P<unit>px|em|rem)$1emr*   )nameheightclasses
aria_labelr   c             C   s  yt  |  }W n" tk
r0   td|  Y nX t|}|sPtd| dtt|dd}|d}d}d|d	 krtt	|d	 
 d
 }n.d|d	 kr|dkr|dkrd}n|dkrd}|d	 t| d }	t|	| | d}
|d	 t| d }d|
 | | | ddd|  f|d}d|	 d| |d< |dk	rb||d< d|d< nd|d< ddd | D }d | d!| d"S )#zReturn the HTML for an GitHub octicon SVG icon.

    :height: the height of the octicon, with suffix unit 'px', 'em' or 'rem'.
    zUnrecognised octicon: zInvalid height: 'z&', must be format <integer><px|em|rem>value   unit   Z16heightsr   24px   g      ?widthpathz1.1 z
sd-octiconzsd-octicon-)versionrA   r6   classz0 0 viewBoxNz
aria-labelimgroletruezaria-hiddenc             s   s"   | ]\}}| d | dV  qdS )z=""Nr*   ).0kvr*   r*   r+   	<genexpr>q   s    zget_octicon.<locals>.<genexpr>z<svg >z</svg>)r0   KeyErrorHEIGHT_REGEXmatch
ValueErrorr   floatgroupintr1   r2   strjoinitems)r5   r6   r7   r8   datarR   height_valueheight_unitoriginal_heightoriginal_widthwidth_valuer/   options
opt_stringr*   r*   r+   get_octicon?   sB    






rb   c               @   s2   e Zd ZdZeeej eej f dddZ	dS )r   zqRole to display a GitHub octicon SVG.

    Additional classes can be added to the element after a semicolon.
    )r   c       
   
   C   s   d| j kr| j dn| j g}|d }t|dk r6dn|d }t|dk rNdn|d }| }yt||| d}W nX tk
r } z:| jjjd	| | j	d
}| j
| j| j|}|g|gfS d}~X Y nX tjdt|dd}	| |	 |	gg fS )zRun the role.;r      r4   r   r:    )r6   r7   zInvalid octicon content: )lineNr   )format)r   splitlenstriprb   	Exceptioninlinerreportererrorlinenoproblematicrawtextr	   rawTextset_source_info)
selfvaluesiconr6   r7   svgexcmsgprbnoder*   r*   r+   run{   s     

zOcticonRole.runN)
__name__
__module____qualname____doc__r   r   r	   Nodesystem_messager}   r*   r*   r*   r+   r   u   s   r   c               @   s.   e Zd ZdZdejiZeej	 dddZ
dS )r   zTDirective to generate all octicon icons.

    Primarily for self documentation.
    rE   )r   c             C   st   | j dg }t }xVt D ]L}t }|t||tdtj	dtt
||dddf ||7 }qW |gS )zRun the directive.rE   z: re   )r7   r   )rg   )r`   getr	   Zbullet_listr3   Z	list_itemextendliteralrs   rr   rb   )ru   r7   Z	list_noderw   Z	item_noder*   r*   r+   r}      s    
zAllOcticons.runN)r~   r   r   r   r
   Zclass_optionZoption_specr   r	   r   r}   r*   r*   r*   r+   r      s   
r   c               @   s   e Zd ZdZdS )r$   z$Node for rendering fontawesome icon.N)r~   r   r   r   r*   r*   r*   r+   r$      s   r$   c                   sJ   e Zd ZdZedd fddZeeej	 eej
 f dddZ  ZS )	r   zoRole to display a Fontawesome icon.

    Additional classes can be added to the element after a semicolon.
    N)r)   r   c                s   t    || _d S )N)super__init__r)   )ru   r)   )	__class__r*   r+   r      s    
zFontawesomeRole.__init__)r   c             C   sb   d| j kr| j ddn| j dg\}}| }t|| jd| g|  d}| | |gg fS )zRun the role.rc   r   re   zfa-)rw   r7   )r   rh   rj   r$   r)   rt   )ru   rw   r7   r|   r*   r*   r+   r}      s    &
zFontawesomeRole.run)r~   r   r   r   rW   r   r   r   r	   r   r   r}   __classcell__r*   r*   )r   r+   r      s   r   c             C   s   | j | |dd d S )Nspanre   )bodyappendZstarttag)ru   r|   r*   r*   r+   r%      s    r%   c             C   s   | j d d S )Nz</span>)r   r   )ru   r|   r*   r*   r+   r&      s    r&   c             C   s   | j jr| d d S )Nr$   )configr   Zadd_latex_package)r   r   r*   r*   r+   r"      s    r"   c             C   sF   | j jr"| jd|d  d ntjdt d|tdd tjdS )	z6Add latex fonteawesome icon, if configured, else warn.z\faicon{rw   }zVFontawesome icons not included in LaTeX output, consider 'sd_fontawesome_latex=True' [z
.fa-build]zfa-build)locationtypesubtypeN)	r   r   r   r   loggerwarningr   r	   SkipNode)ru   r|   r*   r*   r+   r'      s    
r'   )r|   r   c             C   s.   t jd| jj dt d|tdd tjdS )z8Warn that fontawesome is not supported for this builder.z-Fontawesome icons not supported for builder: z [z
.fa-build]zfa-build)r   r   r   N)r   r   builderr5   r   r	   r   )ru   r|   r*   r*   r+   r(      s    r(   )r)   r   c             C   s   t td|  d}t|S )zLoad all octicon data.Z	material_z.json)r   r   r-   r.   )r)   r/   r*   r*   r+   get_material_icon_data   s    r   )r)   r5   r6   r7   r8   r   c             C   s  yt | | }W n( tk
r8   td|  d| Y nX t|}|sXtd| dtt|dd}|d}d}	d	|d
 krtt	|d
 
 d }	n.d|d
 kr|dkr|dkrd}	n|dkrd}	|d
 t|	 d }
t|
| |	 d}|d
 t|	 d }d| | | | ddd| f|d}d|
 d|	 |d< |dk	rj||d< d|d< nd|d< ddd  | D }d!| d"| d#S )$zReturn the HTML for an Google material icon SVG icon.

    :height: the height of the material icon, with suffix unit 'px', 'em' or 'rem'.
    zUnrecognised material-z icon: zInvalid height: 'z&', must be format <integer><px|em|rem>r9   r:   r;      Z20r=   r   r>   r?   r@   g      ?rA   rB   z4.0.0.63c5cb3rC   zsd-material-iconzsd-material-icon-)rD   rA   r6   rE   z0 0 rF   Nz
aria-labelrG   rH   rI   zaria-hiddenc             s   s"   | ]\}}| d | dV  qdS )z="rJ   Nr*   )rK   rL   rM   r*   r*   r+   rN   *  s    z$get_material_icon.<locals>.<genexpr>z<svg rO   z</svg>)r   rP   rQ   rR   rS   r   rT   rU   rV   r1   r2   rW   rX   rY   )r)   r5   r6   r7   r8   rZ   rR   r[   r\   r]   r^   r_   r/   r`   ra   r*   r*   r+   get_material_icon   sB    





r   c                   sJ   e Zd ZdZedd fddZeeej	 eej
 f dddZ  ZS )	r    znRole to display a Material-* icon.

    Additional classes can be added to the element after a semicolon.
    N)r)   r   c                s   t    || _d S )N)r   r   r)   )ru   r)   )r   r*   r+   r   4  s    
zMaterialRole.__init__)r   c       
   
   C   s  d| j kr| j dn| j g}|d }t|dk r6dn|d }t|dk rNdn|d }| }yt| j||| d}W nj tk
r } zL| jjj	d	| j d
t
| d| | jd}| j| j| j|}|g|gfS d}~X Y nX tjdt|dd}	| |	 |	gg fS )zRun the role.rc   r   rd   r4   r   r:   re   )r6   r7   zInvalid material-z icon content: rC   )rf   Nr   )rg   )r   rh   ri   rj   r   r)   rk   rl   rm   rn   r   ro   rp   rq   r	   rr   rs   rt   )
ru   rv   rw   r6   r7   rx   ry   rz   r{   r|   r*   r*   r+   r}   8  s"    

zMaterialRole.run)r~   r   r   r   rW   r   r   r   r	   r   r   r}   r   r*   r*   )r   r+   r    .  s   r    )r4   r*   N)r4   r*   N)6	functoolsr   r-   retypingr   r   r   r   r   r   Zdocutilsr	   Zdocutils.parsers.rstr
   Zsphinx.applicationr   Zsphinx.utilr   Zsphinx.util.docutilsr   r   re   r   _compatr   Zsharedr   	getLoggerr~   r   ZOCTICON_VERSIONZOCTICON_CSSr,   rW   r0   r3   compilerQ   rb   r   r   ZElementZGeneralr$   r   r%   r&   r"   r'   r(   r   r   r    r*   r*   r*   r+   <module>   sN    

  1	  1