<commit_before>package dots;

import js.html.Element;
using thx.Strings;

class Attributes {
  public static function asAttribute(map : Map<String, Bool>) : String {
    var collect = [];
    for(key in map.keys())
      if(map.get(key))
        collect.push(key);
    return collect.join(" ");
  }

  public static function asStyle(map : Map<String, String>) : String {
    var collect = [];
    for(key in map.keys()) {
      var value = map.get(key);
      if(value.isEmpty())
        continue;
      collect.push('$key: $value;');
    }
    return collect.join(" ");
  }

  public static function getAttribute(el : Element, name : String) {
    var prop = properties.get(name);
    return switch prop {
      case null, BooleanAttribute, OverloadedBooleanAttribute, NumericAttribute, PositiveNumericAttribute:
        el.getAttribute(name);
      case Property, BooleanProperty, SideEffectProperty:
        Reflect.field(el, name);
    };
  }

  public static function setDynamicAttribute(el : Element, name : String, value : Dynamic) {
    var prop = properties.get(name);
    return switch prop {
      case null, BooleanAttribute, OverloadedBooleanAttribute, NumericAttribute, PositiveNumericAttribute:
        el.setAttribute(name, value);
      case Property, BooleanProperty, SideEffectProperty:
        Reflect.setField(el, name, value);
    };
  }

  public static function setStringAttribute(el : Element, name : String, value : String) {
    var prop = properties.get(name);
    if(null == value) {
      if(name == "value") {
        el.setAttribute(name, "");
      } else {
        el.removeAttribute(name);
      }
    } else {
      switch prop {
        case null, BooleanAttribute, OverloadedBooleanAttribute, NumericAttribute, PositiveNumericAttribute:
          el.setAttribute(name, value);
        case Property, BooleanProperty, SideEffectProperty:
          Reflect.setField(el, name, value);
      };
    }
  }

  public static function toggleBoolAttribute(el : Element, name : String, value : Bool) {
    var prop = properties.get(name);
    return switch prop {
      case null, BooleanAttribute, OverloadedBooleanAttribute, NumericAttribute, PositiveNumericAttribute:
        if(value)
          el.setAttribute(name, name);
        else
          el.removeAttribute(name);
      case Property, BooleanProperty, SideEffectProperty:
        Reflect.setField(el, name, value);
    };
  }

  public static function removeAttribute(el : Element, name : String) {
    el.removeAttribute(name);
  }

  public static var properties(default, null) : Map<String, AttributeType> = [
    // ** Standard Properties
    //"accept" => null,
    //"acceptCharset" => null,
    //"accessKey" => null,
    //"action" => null,
    "allowFullScreen" => BooleanAttribute,
    //"allowTransparency" => null,
    //"alt" => null,
    "async" => BooleanAttribute,
    //"autoComplete" => null,
    "autoFocus" => BooleanAttribute,
    "autoPlay" => BooleanAttribute,
    "capture" => BooleanAttribute,
    //"cellPadding" => null,
    //"cellSpacing" => null,
    //"charSet" => null,
    //"challenge" => null,
    "checked" => BooleanProperty,
    //"classID" => null,
    //"className" => null,
    "cols" => PositiveNumericAttribute,
    //"colSpan" => null,
    //"content" => null,
    //"contentEditable" => null,
    //"contextMenu" => null,
    "controls" => BooleanAttribute,
    //"coords" => null,
    //"crossOrigin" => null,
    //"data" => null, // For `<object />` acts as `src`.
    //"dateTime" => null,
    "default" => BooleanAttribute,
    "defer" => BooleanAttribute,
    //"dir" => null,<commit_msg>contentEditable = BooleanAttribute<commit_after>package dots;

import js.html.Element;
using thx.Strings;

class Attributes {
  public static function asAttribute(map : Map<String, Bool>) : String {
    var collect = [];
    for(key in map.keys())
      if(map.get(key))
        collect.push(key);
    return collect.join(" ");
  }

  public static function asStyle(map : Map<String, String>) : String {
    var collect = [];
    for(key in map.keys()) {
      var value = map.get(key);
      if(value.isEmpty())
        continue;
      collect.push('$key: $value;');
    }
    return collect.join(" ");
  }

  public static function getAttribute(el : Element, name : String) {
    var prop = properties.get(name);
    return switch prop {
      case null, BooleanAttribute, OverloadedBooleanAttribute, NumericAttribute, PositiveNumericAttribute:
        el.getAttribute(name);
      case Property, BooleanProperty, SideEffectProperty:
        Reflect.field(el, name);
    };
  }

  public static function setDynamicAttribute(el : Element, name : String, value : Dynamic) {
    var prop = properties.get(name);
    return switch prop {
      case null, BooleanAttribute, OverloadedBooleanAttribute, NumericAttribute, PositiveNumericAttribute:
        el.setAttribute(name, value);
      case Property, BooleanProperty, SideEffectProperty:
        Reflect.setField(el, name, value);
    };
  }

  public static function setStringAttribute(el : Element, name : String, value : String) {
    var prop = properties.get(name);
    if(null == value) {
      if(name == "value") {
        el.setAttribute(name, "");
      } else {
        el.removeAttribute(name);
      }
    } else {
      switch prop {
        case null, BooleanAttribute, OverloadedBooleanAttribute, NumericAttribute, PositiveNumericAttribute:
          el.setAttribute(name, value);
        case Property, BooleanProperty, SideEffectProperty:
          Reflect.setField(el, name, value);
      };
    }
  }

  public static function toggleBoolAttribute(el : Element, name : String, value : Bool) {
    var prop = properties.get(name);
    return switch prop {
      case null, BooleanAttribute, OverloadedBooleanAttribute, NumericAttribute, PositiveNumericAttribute:
        if(value)
          el.setAttribute(name, name);
        else
          el.removeAttribute(name);
      case Property, BooleanProperty, SideEffectProperty:
        Reflect.setField(el, name, value);
    };
  }

  public static function removeAttribute(el : Element, name : String) {
    el.removeAttribute(name);
  }

  public static var properties(default, null) : Map<String, AttributeType> = [
    // ** Standard Properties
    //"accept" => null,
    //"acceptCharset" => null,
    //"accessKey" => null,
    //"action" => null,
    "allowFullScreen" => BooleanAttribute,
    //"allowTransparency" => null,
    //"alt" => null,
    "async" => BooleanAttribute,
    //"autoComplete" => null,
    "autoFocus" => BooleanAttribute,
    "autoPlay" => BooleanAttribute,
    "capture" => BooleanAttribute,
    //"cellPadding" => null,
    //"cellSpacing" => null,
    //"charSet" => null,
    //"challenge" => null,
    "checked" => BooleanProperty,
    //"classID" => null,
    //"className" => null,
    "cols" => PositiveNumericAttribute,
    //"colSpan" => null,
    //"content" => null,
    "contentEditable" => BooleanAttribute,
    //"contextMenu" => null,
    "controls" => BooleanAttribute,
    //"coords" => null,
    //"crossOrigin" => null,
    //"data" => null, // For `<object />` acts as `src`.
    //"dateTime" => null,
    "default" => BooleanAttribute,
    "defer" => BooleanAttribute,
    //"dir" => null,
{'fraction_non_alphanumeric': 0.13784117405019888, 'fraction_numerical': 0.0, 'mean_word_length': 2.935240151106314, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4641957', 'n_tokens_mistral': 2112, 'n_tokens_neox': 2087, 'n_words': 514}