(function() {
  var __hasProp = Object.prototype.hasOwnProperty;

  $tag_initing = 0;

  $tag_inited = 1;

  $tag_ready = 2;

  this.def_tag('NODE_TAG',"NODE_TAG",function(__scope,__class){

    this.attribute = function(name, options) {
      var _methname;
      if (options == null) options = {};
      this.prototype[_methname = name] = function() {
        return this["@node"].getAttribute(name);
      }; __method_added(this,_methname);
      this.prototype[_methname = "" + name + "="] = function() {
        return this["@node"].setAttribute(name, arguments[0]);
      }; __method_added(this,_methname);
      this.prototype[_methname = "" + name + "?"] = function() {
        return !!this["@node"].getAttribute(name);
      }; __method_added(this,_methname);
      return this;
    };__singleton_method_added(this,"attribute");

    this.template = function(block) {
      this["@template"] = block;
      return this["@awakened"] = false;
    };__singleton_method_added(this,"template");

    this.node = function() {
      if (this["@template"] && !this["@awakened"]) {
        this["@node"].innerHTML = "";
        this.tag().append(this["@template"].call(this.tag()));
        this["@awakened"] = true;
      }
      return this["@node"];
    };__singleton_method_added(this,"node");

    this.tag = function() {
      if (this["@tag"]) return this["@tag"];
      this["@tag"] = $create(this.prototype);
      this["@tag"]["@node"] = this["@node"];
      return this["@tag"];
    };__singleton_method_added(this,"tag");

    this["singleton?"] = function() {
      var m;
      m = this['__named__'].match(/^(.*)_TAG_ID$/);
      return m && m['[]'](1).toLowerCase();
    };__singleton_method_added(this,"singleton?");

    this.protonode = function() {
      var atr, cls, id, node, ns, parent, type, val, _ref;
      if (this["@protonode"]) return this["@protonode"];
      if (this['__super__'] === DObject) {
        return this["@protonode"] = document.createElement('DIV');
      }
      parent = this['__super__'].protonode();
      if (id = this["singleton?"]()) {
        node = parent.cloneNode(true);
        node.id = id;
      } else {
        type = this["@type"];
        ns = this["@namespace"];
        node = ns ? document.createElementNS(ns,type) : document.createElement(type);
        if (node instanceof HTMLUnknownElement) node = parent.cloneNode(true);
        cls = parent.className;
        node.className = cls ? "" + cls + " " + type + "_" : "" + type + "_";
      }
      if (this.prototype.onmousemove) {
        node.setAttribute('onmousemove', "this['@view'].onmousemove(event)");
      }
      if (this.prototype.onkeydown) node.setAttribute('tabindex', '-1');
      _ref = this["@defaults"];
      for (atr in _ref) {
        val = _ref[atr];
        node.setAttribute(atr, val);
      }
      return this["@protonode"] = node;
    };__singleton_method_added(this,"protonode");

    this.inherited = function(sub) {
      sub["@type"] = sub["singleton?"]() ? this["@type"] : sub['__named__'].replace(/_TAG$/, '').toLowerCase();
      sub["@protonode"] = null;
      sub["@awakened"] = false;
      return sub["@defaults"] = {};
    };__singleton_method_added(this,"inherited");

    this.tpl = function(nodes_or_block) {
      return this.prototype["@template"] = nodes_or_block;
    };__singleton_method_added(this,"tpl");

    this.create = function(name, id, classes, attributes, children, flag) {
      var node, view;
      node = this.protonode().cloneNode(true);
      if (children instanceof Function) {
        attributes.template = children;
        children = null;
      }
      if (flag !== void 0) {
        if (classes) {
          classes.unshift(flag);
        } else {
          classes = [flag];
        }
      }
      if (id) node.id = id;
      if (classes) node.className = node.className + " " + classes.join(" ");
      view = new this.__ctor__(node,attributes,children);
      node["@view"] = view;
      view["@live"] = true;
      view["@awakener"]();
      return view;
    };__singleton_method_added(this,"create");

    this.ns = function(namespace) {
      return this["@namespace"] = namespace;
    };__singleton_method_added(this,"ns");

    this.set = function(name, value) {
      this["@defaults"] || (this["@defaults"] = {});
      return this["@defaults"][name] = value;
    };__singleton_method_added(this,"set");

    this.__ctor__ = function NODE_TAG(node, attributes, body, silent) {
      this["@awakener"] = this.deferred('awaken');
      this["@node"] = node;
      this["body="](body);
      this["attributes="](attributes);
      return this;
    }; this.__ctor__.prototype = this.prototype;;

    this.prototype.node = function() {
      return this["@node"];
    }; __method_added(this,"node");

    this.prototype["id="] = function(id) {
      return this["@node"].id = id;
    }; __method_added(this,"id=");

    this.prototype["flags="] = function(flags) {
      return this["@node"].className = ' ' + flags.join(" ");
    }; __method_added(this,"flags=");

    this.prototype["ontap="] = function(ontap) {
      return this.ontap = ontap;
    }; __method_added(this,"ontap=");

    this.prototype["body="] = function(body) {
      if (body) return this.append(body);
    }; __method_added(this,"body=");

    this.prototype["attributes="] = function(attributes) {
      var fn, name, value;
      for (name in attributes) {
        if (!__hasProp.call(attributes, name)) continue;
        value = attributes[name];
        if (fn = this[name + '=']) {
          fn.call(this, value);
        } else {
          this['[]='](name,value);
        }
      }
      return true;
    }; __method_added(this,"attributes=");

    this.prototype["data="] = function(data) {
      var after, prev;
      prev = this["@data"];
      if (prev !== data) {
        this.forget(prev);
        after = this.deferred(this["@live"] ? 'refresh' : 'awaken');
        if (this["@data"] = data) {
          this.observe(data, {
            as: 'data'
          });
          this.emit("change:data", data, prev);
          if (data.uid) this['[]=']('dataid',data.uid());
          if (data.onready) {
            data.onready(after);
          } else {
            after();
          }
        } else {
          this.emit("unset:data", prev);
          this['[]=']('dataid',void 0);
          after();
        }
      }
      return this["@data"];
    }; __method_added(this,"data=");

    this.prototype.data = function() {
      return this["@data"];
    }; __method_added(this,"data");

    this.prototype.awaken = function() {
      return true;
    }; __method_added(this,"awaken");

    this.prototype.refresh = function() {
      return true;
    }; __method_added(this,"refresh");

    this.prototype["[]"] = function(atr) {
      return this["@node"].getAttribute(atr);
    }; __method_added(this,"[]");

    this.prototype["[]="] = function(atr, value) {
      if (value === void 0) {
        return this["@node"].removeAttribute(atr);
      } else {
        return this["@node"].setAttribute(atr, value);
      }
    }; __method_added(this,"[]=");

    this.prototype.show = function() {
      return this.unflag('hidden');
    }; __method_added(this,"show");

    this.prototype.hide = function() {
      return this.flag('hidden');
    }; __method_added(this,"hide");

    this.prototype["hidden="] = function(bool) {
      if (!!bool) {
        return this.hide();
      } else {
        return this.show();
      }
    }; __method_added(this,"hidden=");

    this.prototype.focus = function() {
      return this["@node"].focus();
    }; __method_added(this,"focus");

    this.prototype.blur = function() {
      return this["@node"].blur();
    }; __method_added(this,"blur");

    this.prototype.enable = function() {
      this["@node"].setAttribute('enabled', 'enabled');
      this["@node"].removeAttribute('disabled');
      return this;
    }; __method_added(this,"enable");

    this.prototype.disable = function() {
      this["@node"].setAttribute('disabled', 'disabled');
      this["@node"].removeAttribute('enabled');
      return this;
    }; __method_added(this,"disable");

    this.prototype["enabled="] = function(bool) {
      if (!!bool) {
        return this.enable();
      } else {
        return this.disable();
      }
    }; __method_added(this,"enabled=");

    this.prototype["template="] = function(template) {
      return this["@template"] = template;
    }; __method_added(this,"template=");

    this.prototype.template = function() {
      return this["@template"];
    }; __method_added(this,"template");

    this.prototype.tabindex = function() {
      return this["@node"].getAttribute('tabindex');
    }; __method_added(this,"tabindex");

    this.prototype["tabindex="] = function(idx) {
      return this["@node"].setAttribute('tabindex', idx);
    }; __method_added(this,"tabindex=");

    this.prototype.text = function() {
      return this["@node"].innerText;
    }; __method_added(this,"text");

    this.prototype["text="] = function(text) {
      return this["@node"].innerText = text;
    }; __method_added(this,"text=");

    this.prototype.width = function() {
      return this["@node"].offsetWidth;
    }; __method_added(this,"width");

    this.prototype.height = function() {
      return this["@node"].offsetHeight;
    }; __method_added(this,"height");

    this.prototype.offset = function() {
      return {
        left: this["@node"].offsetLeft,
        top: this["@node"].offsetTop
      };
    }; __method_added(this,"offset");

    this.prototype.inner_width = function() {
      return this["@node"].innerWidth;
    }; __method_added(this,"inner_width");

    this.prototype.inner_height = function() {
      return this["@node"].innerHeight;
    }; __method_added(this,"inner_height");

    this.prototype.position = function() {
      return {
        x: this["@node"].offsetLeft,
        y: this["@node"].offsetTop
      };
    }; __method_added(this,"position");

    this.prototype.bbox = function() {
      return this["@node"].getBoundingClientRect();
    }; __method_added(this,"bbox");

    this.prototype.css = function(atr, value) {
      var a, style, v;
      if (value === void 0 && typeof atr === 'object') {
        for (a in atr) {
          v = atr[a];
          this.css(a, v);
        }
        return this;
      }
      style = this["@node"].style;
      if (value === void 0) return style[atr];
      if (atr.match(/^width|height|top|left/)) {
        if (typeof value === 'number') value = "" + value + "px";
      }
      style[atr] = value;
      return this;
    }; __method_added(this,"css");

    this.prototype["focused?"] = function() {
      return $doc.activeElement === this["@node"];
    }; __method_added(this,"focused?");

    this.prototype["flagged?"] = function(flag) {
      return (" " + this["@node"].className + " ").indexOf(" " + flag + " ") >= 0;
    }; __method_added(this,"flagged?");

    this.prototype.flag = function(flag) {
      var cls;
      cls = this["@node"].className;
      if ((" " + cls + " ").indexOf(" " + flag + " ") >= 0) return this;
      this["@node"].className = cls ? cls + (" " + flag) : flag;
      return this;
    }; __method_added(this,"flag");

    this.prototype.unflag = function(flag) {
      var cls;
      cls = this["@node"].className;
      this["@node"].className = cls.replace(new (__ctor(__scope.RegExp))("(^|\\s)" + flag + "(\\s|$)"), " ").replace(/\s$/, "");
      return this;
    }; __method_added(this,"unflag");

    this.prototype["empty!"] = function() {
      this["@node"].innerHTML = '';
      return this;
    }; __method_added(this,"empty!");

    this.prototype["detach!"] = function() {
      var parent;
      if (parent = this["@node"].parentNode) true;
      return this;
    }; __method_added(this,"detach!");

    this.prototype["destroy!"] = function() {
      var parent;
      if (parent = this["@node"].parentNode) {
        parent.removeChild(this["@node"]);
        this["data="](null);
        this["@node"] = null;
      }
      return this;
    }; __method_added(this,"destroy!");

    this.prototype[">>"] = function(node) {
      node.appendChild(this["@node"]);
      return this;
    }; __method_added(this,">>");

    this.prototype["<<"] = function(node) {
      this.append(node);
      return node;
    }; __method_added(this,"<<");

    this.prototype.append = function(obj, before) {
      var node;
      var _this = this;
      if (obj instanceof __scope.Array) {
        obj.each(function(member) {
          return _this.append(member, before);
        });
        return this;
      }
      node = obj["@node"] || obj;
      if (typeof node === 'string' || typeof node === 'number') {
        this["@node"].appendChild($doc.createTextNode(node));
      } else {
        if (before) {
          this["@node"].insertBefore(node, before);
        } else {
          this["@node"].appendChild(node);
        }
      }
      return this;
    }; __method_added(this,"append");

    this.prototype.prepend = function(obj) {
      return true;
    }; __method_added(this,"prepend");

    this.prototype.before = function(obj) {
      var par;
      if (!obj) return;
      if (par = obj.parent()) {
        par["@node"].insertBefore(this["@node"], obj["@node"]);
      }
      return this;
    }; __method_added(this,"before");

    this.prototype.after = function(obj) {
      return true;
    }; __method_added(this,"after");

    this.prototype.move = function(options) {
      var hadFocus, idx, move_by, move_to, nodes;
      if (!this.parent()) throw 'cannot move node without parent';
      hadFocus = this["focused?"]();
      if (typeof options === 'number') {
        move_by = options;
        if (move_by > 0) move_by++;
        nodes = this.parent()["@node"].children;
        idx = [].indexOf.call(nodes, this["@node"]);
        move_to = [[nodes.length, idx + move_by].min(), 0].max();
        this.parent().append(this, nodes[move_to]);
      }
      if (hadFocus) this["@node"].focus();
      return this;
    }; __method_added(this,"move");

    this.prototype.querySelectorAll = function(q) {
      return this["@node"].querySelectorAll(q);
    }; __method_added(this,"querySelectorAll");

    this.prototype.querySelector = function(q) {
      return this["@node"].querySelector(q);
    }; __method_added(this,"querySelector");

    this.prototype["%"] = function(q) {
      return new (__ctor(__scope.Selector))(q, this);
    }; __method_added(this,"%");

    this.prototype.parent = function() {
      return $__tag(this["@node"].parentNode);
    }; __method_added(this,"parent");

    this.prototype.closest = function(sel) {
      return true;
    }; __method_added(this,"closest");

    this.prototype.ancestors = function(sel) {
      return true;
    }; __method_added(this,"ancestors");

    this.prototype.siblings = function(sel) {
      return true;
    }; __method_added(this,"siblings");

    this.prototype.next = function() {
      var node;
      if (node = this["@node"].nextSibling) return $__tag(node);
    }; __method_added(this,"next");

    this.prototype.prev = function() {
      var node;
      if (node = this["@node"].previousSibling) return $__tag(node);
    }; __method_added(this,"prev");

    this.prototype.find = function(sel) {
      return true;
    }; __method_added(this,"find");

    this.prototype.children = function(sel) {
      return true;
    }; __method_added(this,"children");

    this.prototype.closest = function(sel) {
      return true;
    }; __method_added(this,"closest");

    this.prototype["is?"] = function(sel) {
      return true;
    }; __method_added(this,"is?");

    this.prototype["has?"] = function(sel) {
      return true;
    }; __method_added(this,"has?");

    this.prototype.ondom = function(event, cb) {
      var sym;
      var _this = this;
      if (typeof cb === 'string' && (sym = cb)) {
        cb = (function(e) {
          return _this[sym](e);
        });
      }
      this["@node"].addEventListener(event, cb, false);
      return cb;
    }; __method_added(this,"ondom");

    this.flag = this.prototype.flag;

    this.unflag = this.prototype.unflag;

    this.prototype.appendChild = this.prototype.append;

  });

  this.def_tag('DIV_TAG',"NODE_TAG",function(__scope,__class){

    if(!this.__ctor__){this.__ctor__= function DIV_TAG(){__class.__super__.__ctor__.apply(this, arguments)}; this.__ctor__.prototype = this.prototype; }



  });

  this.def_tag('ARTICLE_TAG',"NODE_TAG",function(__scope,__class){

    if(!this.__ctor__){this.__ctor__= function ARTICLE_TAG(){__class.__super__.__ctor__.apply(this, arguments)}; this.__ctor__.prototype = this.prototype; }



  });

  this.def_tag('SECTION_TAG',"NODE_TAG",function(__scope,__class){

    if(!this.__ctor__){this.__ctor__= function SECTION_TAG(){__class.__super__.__ctor__.apply(this, arguments)}; this.__ctor__.prototype = this.prototype; }



  });

  this.def_tag('HEADER_TAG',"NODE_TAG",function(__scope,__class){

    if(!this.__ctor__){this.__ctor__= function HEADER_TAG(){__class.__super__.__ctor__.apply(this, arguments)}; this.__ctor__.prototype = this.prototype; }



  });

  this.def_tag('FOOTER_TAG',"NODE_TAG",function(__scope,__class){

    if(!this.__ctor__){this.__ctor__= function FOOTER_TAG(){__class.__super__.__ctor__.apply(this, arguments)}; this.__ctor__.prototype = this.prototype; }



  });

  this.def_tag('SPAN_TAG',"NODE_TAG",function(__scope,__class){

    if(!this.__ctor__){this.__ctor__= function SPAN_TAG(){__class.__super__.__ctor__.apply(this, arguments)}; this.__ctor__.prototype = this.prototype; }



  });

  this.def_tag('ASIDE_TAG',"NODE_TAG",function(__scope,__class){

    if(!this.__ctor__){this.__ctor__= function ASIDE_TAG(){__class.__super__.__ctor__.apply(this, arguments)}; this.__ctor__.prototype = this.prototype; }



  });

  this.def_tag('NAV_TAG',"NODE_TAG",function(__scope,__class){

    if(!this.__ctor__){this.__ctor__= function NAV_TAG(){__class.__super__.__ctor__.apply(this, arguments)}; this.__ctor__.prototype = this.prototype; }



  });

  this.def_tag('OL_TAG',"NODE_TAG",function(__scope,__class){

    if(!this.__ctor__){this.__ctor__= function OL_TAG(){__class.__super__.__ctor__.apply(this, arguments)}; this.__ctor__.prototype = this.prototype; }



  });

  this.def_tag('UL_TAG',"NODE_TAG",function(__scope,__class){

    if(!this.__ctor__){this.__ctor__= function UL_TAG(){__class.__super__.__ctor__.apply(this, arguments)}; this.__ctor__.prototype = this.prototype; }



  });

  this.def_tag('LI_TAG',"NODE_TAG",function(__scope,__class){

    if(!this.__ctor__){this.__ctor__= function LI_TAG(){__class.__super__.__ctor__.apply(this, arguments)}; this.__ctor__.prototype = this.prototype; }



  });

  this.def_tag('CANVAS_TAG',"NODE_TAG",function(__scope,__class){

    if(!this.__ctor__){this.__ctor__= function CANVAS_TAG(){__class.__super__.__ctor__.apply(this, arguments)}; this.__ctor__.prototype = this.prototype; }



  });

  this.def_tag('DT_TAG',"NODE_TAG",function(__scope,__class){

    if(!this.__ctor__){this.__ctor__= function DT_TAG(){__class.__super__.__ctor__.apply(this, arguments)}; this.__ctor__.prototype = this.prototype; }



  });

  this.def_tag('DD_TAG',"NODE_TAG",function(__scope,__class){

    if(!this.__ctor__){this.__ctor__= function DD_TAG(){__class.__super__.__ctor__.apply(this, arguments)}; this.__ctor__.prototype = this.prototype; }



  });

  this.def_tag('IMG_TAG',"NODE_TAG",function(__scope,__class){

    if(!this.__ctor__){this.__ctor__= function IMG_TAG(){__class.__super__.__ctor__.apply(this, arguments)}; this.__ctor__.prototype = this.prototype; }



  });

  this.def_tag('BUTTON_TAG',"NODE_TAG",function(__scope,__class){

    if(!this.__ctor__){this.__ctor__= function BUTTON_TAG(){__class.__super__.__ctor__.apply(this, arguments)}; this.__ctor__.prototype = this.prototype; }



  });

  this.def_tag('LABEL_TAG',"NODE_TAG",function(__scope,__class){

    if(!this.__ctor__){this.__ctor__= function LABEL_TAG(){__class.__super__.__ctor__.apply(this, arguments)}; this.__ctor__.prototype = this.prototype; }



  });

  this.def_tag('BODY_TAG',"NODE_TAG",function(__scope,__class){

    if(!this.__ctor__){this.__ctor__= function BODY_TAG(){__class.__super__.__ctor__.apply(this, arguments)}; this.__ctor__.prototype = this.prototype; }



  });

  this.def_tag('OBJECT_TAG',"NODE_TAG",function(__scope,__class){

    if(!this.__ctor__){this.__ctor__= function OBJECT_TAG(){__class.__super__.__ctor__.apply(this, arguments)}; this.__ctor__.prototype = this.prototype; }

    this.prototype["data="] = function(data) {
      return this['[]=']('data',data);
    }; __method_added(this,"data=");

    this.prototype.data = function() {
      return this['[]']('data');
    }; __method_added(this,"data");

  });

  this.def_tag('PARAM_TAG',"NODE_TAG",function(__scope,__class){

    if(!this.__ctor__){this.__ctor__= function PARAM_TAG(){__class.__super__.__ctor__.apply(this, arguments)}; this.__ctor__.prototype = this.prototype; }



  });

  this.def_tag('DOCUMENT_TAG',"NODE_TAG",function(__scope,__class){

    if(!this.__ctor__){this.__ctor__= function DOCUMENT_TAG(){__class.__super__.__ctor__.apply(this, arguments)}; this.__ctor__.prototype = this.prototype; }

    this.prototype.body = function() {
      return $__tag(this["@node"].body);
    }; __method_added(this,"body");

    this.prototype.location = function() {
      return this["@node"].location;
    }; __method_added(this,"location");

  });

  this.def_tag('INPUT_TAG',"NODE_TAG",function(__scope,__class){

    this.__ctor__ = function INPUT_TAG(node, options) {
      var atr, _i, _len, _primitive, _ref;
      __class.__super__.__ctor__.apply(this, arguments);
      _ref = ['type', 'min', 'max', 'step'];
      for (_i = 0, _len = (_ref.len ? _ref.len() : _ref.length),_primitive = (_ref instanceof Array || !_ref.at); _i < _len; _i++) {
        atr = _primitive ? _ref[_i] : _ref.at(_i);
        if (options[atr]) this['[]='](atr,options[atr]);
      }
      return this;
    }; this.__ctor__.prototype = this.prototype;;

    this.prototype.value = function() {
      return this["@node"].value;
    }; __method_added(this,"value");

    this.prototype["value="] = function(value) {
      return this["@node"].value = value;
    }; __method_added(this,"value=");

  });

  this.def_tag('TEXTAREA_TAG',"NODE_TAG",function(__scope,__class){

    if(!this.__ctor__){this.__ctor__= function TEXTAREA_TAG(){__class.__super__.__ctor__.apply(this, arguments)}; this.__ctor__.prototype = this.prototype; }

    this.prototype.value = function() {
      return this["@node"].value;
    }; __method_added(this,"value");

    this.prototype["value="] = function(value) {
      return this["@node"].value = value;
    }; __method_added(this,"value=");

  });

  this.def_tag('SELECT_TAG',"NODE_TAG",function(__scope,__class){

    if(!this.__ctor__){this.__ctor__= function SELECT_TAG(){__class.__super__.__ctor__.apply(this, arguments)}; this.__ctor__.prototype = this.prototype; }

    this.prototype.value = function() {
      return this["@node"].value;
    }; __method_added(this,"value");

    this.prototype["value="] = function(value) {
      return this["@node"].value = value;
    }; __method_added(this,"value=");

  });

}).call($$base);

