<?php

namespace Atom\runtime_7456b800;

/**
 * dom attrs 相关的工具函数
 *
 * @package Atom\runtime_7456b800
 * @auther lvsheng
 */
class Atom_Util_Attrs {

    /**
     * 是否是布尔值的属性
     * @param $attr string
     * @return bool
     */
    public static function isBooleanAttr($attr) {
        static $allAttrs = array(
            'allowfullscreen' => 1,
            'async' => 1,
            'autofocus' => 1,
            'autoplay' => 1,
            'checked' => 1,
            'compact' => 1,
            'controls' => 1,
            'declare' => 1,
            'default' => 1,
            'defaultchecked' => 1,
            'defaultmuted' => 1,
            'defaultselected' => 1,
            'defer' => 1,
            'disabled' => 1,
            'enabled' => 1,
            'formnovalidate' => 1,
            'hidden' => 1,
            'indeterminate' => 1,
            'inert' => 1,
            'ismap' => 1,
            'itemscope' => 1,
            'loop' => 1,
            'multiple' => 1,
            'muted' => 1,
            'nohref' => 1,
            'noresize' => 1,
            'noshade' => 1,
            'novalidate' => 1,
            'nowrap' => 1,
            'open' => 1,
            'pauseonexit' => 1,
            'readonly' => 1,
            'required' => 1,
            'reversed' => 1,
            'scoped' => 1,
            'seamless' => 1,
            'selected' => 1,
            'sortable' => 1,
            'translate' => 1,
            'truespeed' => 1,
            'typemustmatch' => 1,
            'visible' => 1,
        );
        return isset($allAttrs[$attr]);
    }

    /**
     * 值是否是false或者跟null
     * @param $val mixed
     * @return bool
     */
    public static function isFalsyAttrValue($val) {
        return $val === null || $val === false;
    }

    /**
     * 是否可枚举值的属性
     * @param $attr string
     * @return bool
     */
    public static function isEnumeratedAttr($attr) {
        static $allAttrs = array(
            'contenteditable' => 1,
            'draggable' => 1,
            'spellcheck' => 1,
        );
        return isset($allAttrs[$attr]);
    }

    /**
     * 是否合法属性
     * @param $attr string
     * @return bool
     */
    public static function isValidAttr($attr) {
        static $allAttrs = array(
            'accept'=>1,
            'accept-charset'=>1,
            'accesskey'=>1,
            'action'=>1,
            'align'=>1,
            'alt'=>1,
            'async'=>1,
            'autocomplete'=>1,
            'autofocus'=>1,
            'autoplay'=>1,
            'autosave'=>1,
            'bgcolor'=>1,
            'border'=>1,
            'buffered'=>1,
            'challenge'=>1,
            'charset'=>1,
            'checked'=>1,
            'cite'=>1,
            'class'=>1,
            'code'=>1,
            'codebase'=>1,
            'color'=>1,
            'cols'=>1,
            'colspan'=>1,
            'content'=>1,
            'http-equiv'=>1,
            'name'=>1,
            'contenteditable'=>1,
            'contextmenu'=>1,
            'controls'=>1,
            'coords'=>1,
            'data'=>1,
            'datetime'=>1,
            'default'=>1,
            'defer'=>1,
            'dir'=>1,
            'dirname'=>1,
            'disabled'=>1,
            'download'=>1,
            'draggable'=>1,
            'dropzone'=>1,
            'enctype'=>1,
            'method'=>1,
            'for'=>1,
            'form'=>1,
            'formaction'=>1,
            'headers'=>1,
            'height'=>1,
            'hidden'=>1,
            'high'=>1,
            'href'=>1,
            'hreflang'=>1,
            'http-equiv'=>1,
            'icon'=>1,
            'id'=>1,
            'ismap'=>1,
            'itemprop'=>1,
            'keytype'=>1,
            'kind'=>1,
            'label'=>1,
            'lang'=>1,
            'language'=>1,
            'list'=>1,
            'loop'=>1,
            'low'=>1,
            'manifest'=>1,
            'max'=>1,
            'maxlength'=>1,
            'media'=>1,
            'method'=>1,
            'GET'=>1,
            'POST'=>1,
            'min'=>1,
            'multiple'=>1,
            'email'=>1,
            'file'=>1,
            'muted'=>1,
            'name'=>1,
            'novalidate'=>1,
            'open'=>1,
            'optimum'=>1,
            'pattern'=>1,
            'ping'=>1,
            'placeholder'=>1,
            'poster'=>1,
            'preload'=>1,
            'radiogroup'=>1,
            'readonly'=>1,
            'rel'=>1,
            'required'=>1,
            'reversed'=>1,
            'rows'=>1,
            'rowspan'=>1,
            'sandbox'=>1,
            'scope'=>1,
            'scoped'=>1,
            'seamless'=>1,
            'selected'=>1,
            'shape'=>1,
            'size'=>1,
            'type'=>1,
            'text'=>1,
            'password'=>1,
            'sizes'=>1,
            'span'=>1,
            'spellcheck'=>1,
            'src'=>1,
            'srcdoc'=>1,
            'srclang'=>1,
            'srcset'=>1,
            'start'=>1,
            'step'=>1,
            'style'=>1,
            'summary'=>1,
            'tabindex'=>1,
            'target'=>1,
            'title'=>1,
            'type'=>1,
            'usemap'=>1,
            'value'=>1,
            'width'=>1,
            'wrap'=>1,
        );
        return isset($allAttrs[$attr])
            || Atom_Util_Shared::startsWith($attr, 'data-')
            || Atom_Util_Shared::startsWith($attr, 'aria-');
    }

    /**
     * 是否是 transition-group 组件需要的属性
     * @param $attr string
     * @return bool
     */
    public static function isTransitionProps($attr) {

        static $transitionGroupAttrs = array(
            'name' => 1,
            'appear' => 1,
            'css' => 1,
            'mode' => 1,
            'type' => 1,
            'enter-class' => 1,
            'leave-class' => 1,
            'enter-to-class' => 1,
            'leave-to-class' => 1,
            'enter-active-class' => 1,
            'leave-active-class' => 1,
            'appear-class' => 1,
            'appear-active-class' => 1,
            'appear-to-class' => 1,
        );

        return isset($transitionGroupAttrs[$attr]);

    }
}
