o
    lqi~                     @   sd   d Z dgZddlZddlZddlmZmZmZm	Z	m
Z
 ddlmZ ddlmZ G dd dejZdS )	z1MarginRule implements DOM Level 2 CSS MarginRule.
MarginRule    N)ChoicePreDefProd
ProdParserSequence   )cssrule)CSSStyleDeclarationc                       s   e Zd ZdZg dZ					d fdd	Zdd Zed	d
 eddZeZ	dd Z
dd Zdd Z fddZeeeddZdd Zedd
 eddZedd
 ddZedd
 Z  ZS )r   a  
    A margin at-rule consists of an ATKEYWORD that identifies the margin box
    (e.g. '@top-left') and a block of declarations (said to be in the margin
    context).

    Format::

        margin :
               margin_sym S* '{' declaration [ ';' S* declaration? ]* '}' S*
               ;

        margin_sym :
               TOPLEFTCORNER_SYM |
               TOPLEFT_SYM |
               TOPCENTER_SYM |
               TOPRIGHT_SYM |
               TOPRIGHTCORNER_SYM |
               BOTTOMLEFTCORNER_SYM |
               BOTTOMLEFT_SYM |
               BOTTOMCENTER_SYM |
               BOTTOMRIGHT_SYM |
               BOTTOMRIGHTCORNER_SYM |
               LEFTTOP_SYM |
               LEFTMIDDLE_SYM |
               LEFTBOTTOM_SYM |
               RIGHTTOP_SYM |
               RIGHTMIDDLE_SYM |
               RIGHTBOTTOM_SYM
               ;

    e.g.::

        @top-left {
            content: "123";
            }
    )z@top-left-cornerz	@top-leftz@top-centerz
@top-rightz@top-right-cornerz@bottom-left-cornerz@bottom-leftz@bottom-centerz@bottom-rightz@bottom-right-cornerz	@left-topz@left-middlez@left-bottomz
@right-topz@right-middlez@right-bottomNFc                    sH   t  j||d d | _| _|r|| _|r|| _nt| d| _|| _dS )z
        :param atkeyword:
            The margin area, e.g. '@top-left' for this rule
        :param style:
            CSSStyleDeclaration for this MarginRule
        )
parentRuleparentStyleSheetNr   )super__init__
_atkeyword_keywordmarginstyler
   Z	_readonly)selfr   r   r   r   readonly	__class__ ^/home/app/PaddleOCR-VL/.venv_paddleocr/lib/python3.10/site-packages/cssutils/css/marginrule.pyr   G   s   
zMarginRule.__init__c                 C   sJ   |  |}|tjvr| jjd| j d|tjjd dS || _	|| _
dS )z2Check if new keyword fits the rule it is used for.z!Invalid margin @keyword for this z rule: errorN)
_normalizer   margins_logr   r   xmldomInvalidModificationErrr   r   )r   r   nr   r   r   
_setMarginc   s   



zMarginRule._setMarginc                 C      | j S N)r   r   r   r   r   <lambda>r       zMarginRule.<lambda>zfMargin area of parent CSSPageRule. `margin` and `atkeyword` are both normalized @keyword of the @rule.)docc                 C   s"   d| j j d| jd| jjdS )Nzcssutils.css.z(margin=z, style=))r   __name__r   r   cssTextr&   r   r   r   __repr__{   s   "zMarginRule.__repr__c                 C   s   d| j j| j| jjt| f S )Nz3<cssutils.css.%s object margin=%r style=%r at 0x%x>)r   r+   r   r   r,   idr&   r   r   r   __str__~   s   zMarginRule.__str__c                 C   s   t j| S )z#Return serialized property cssText.)cssutilsZserZdo_MarginRuler&   r   r   r   _getCssText   s   zMarginRule._getCssTextc              	      s   t  | tddd ddd}ttd fdddd	td
dtttjdd|dd dtjdddd}t 	|d|\}}}}|rt 
| d|v rU|d j _n jjd j tjjd t d _d|v rv|d  j_dS dS dS )ad  
        :exceptions:
            - :exc:`~xml.dom.SyntaxErr`:
              Raised if the specified CSS string value has a syntax error and
              is unparsable.
            - :exc:`~xml.dom.InvalidModificationErr`:
              Raised if the specified CSS string value represents a different
              type of rule than the current one.
            - :exc:`~xml.dom.HierarchyRequestErr`:
              Raised if the rule cannot be inserted at this point in the
              style sheet.
            - :exc:`~xml.dom.NoModificationAllowedErr`:
              Raised if the rule is readonly.
        styletokensc                 S   s   |dkS )N}r   tvr   r   r   r'      s    z(MarginRule._setCssText.<locals>.<lambda>T)namematchtoStoreZ
storeTokenz@ marginc                    s   | dko  |tjv S )NZ	ATKEYWORD)r   r   r   r4   r&   r   r   r'      s    r   )r7   r8   r9   ZOPEN{@)r9   c                   S   s   dS )N)r   Nr   r   r   r   r   r'      s    )ZminmaxZCLOSEr3   )ZstopAndKeepr   z#No margin @keyword for this %s ruler   r   N)r   _setCssTextr   r   r   charr   Zunknownruler   parseZ_setSeqvaluer   r   r   r   r    r!   r
   r   r,   )r   r,   r2   ZprodsokseqstoreZunusedr   r&   r   r<      sD   


zMarginRule._setCssTextz*(DOM) The parsable textual representation.)fgetfsetr)   c                 C   s4   |    t|trt|| d| _dS | |_|| _dS )zt
        :param style: A string or CSSStyleDeclaration which replaces the
            current style object.
        )r,   r   N)Z_checkReadonly
isinstancestrr
   _styleZ_parentRule)r   r   r   r   r   	_setStyle   s
   

zMarginRule._setStylec                 C   r$   r%   )rG   r&   r   r   r   r'      r(   z-(DOM) The declaration-block of this rule set.c                 C   r$   r%   )ZMARGIN_RULEr&   r   r   r   r'      r(   z=The type of this rule, as defined by a CSSRule type constant.c                 C   s
   t | jS r%   )bool	atkeywordr&   r   r   r   r'      s   
 )NNNNF)r+   
__module____qualname____doc__r   r   r#   propertyr   rJ   r-   r/   r1   r<   r,   rH   r   typeZ
wellformed__classcell__r   r   r   r   r      sH    %B)rM   __all__Zxml.domr   r0   Zcssutils.prodparserr   r   r   r   r    r	   Zcssstyledeclarationr
   ZCSSRuler   r   r   r   r   <module>   s    