text: /**
   * skylark-langx-events - The skylark JavaScript language extension library.
   * @author Hudaokeji Co.,Ltd
   * @version v0.9.0
   * @link www.skylarkjs.org
   * @license MIT
   */
  (function(factory,globals) {
    var define = globals.define,
        require = globals.require,
        isAmd = (typeof define === 'function' && define.amd),
        isCmd = (!isAmd && typeof exports !== 'undefined');
  
    if (!isAmd && !define) {
      var map = {};
      function absolute(relative, base) {
          if (relative[0]!==".") {
            return relative;
          }
          var stack = base.split("/"),
              parts = relative.split("/");
          stack.pop(); 
          for (var i=0; i<parts.length; i++) {
              if (parts[i] == ".")
                  continue;
              if (parts[i] == "..")
                  stack.pop();
              else
                  stack.push(parts[i]);
          }
          return stack.join("/");
      }
      define = globals.define = function(id, deps, factory) {
          if (typeof factory == 'function') {
              map[id] = {
                  factory: factory,
                  deps: deps.map(function(dep){
                    return absolute(dep,id);
                  }),
                  resolved: false,
                  exports: null
              };
              require(id);
          } else {
              map[id] = {
                  factory : null,
                  resolved : true,
                  exports : factory
              };
          }
      };
      require = globals.require = function(id) {
          if (!map.hasOwnProperty(id)) {
              throw new Error('Module ' + id + ' has not been defined');
          }
          var module = map[id];
          if (!module.resolved) {
              var args = [];
  
              module.deps.forEach(function(dep){
                  args.push(require(dep));
              })
  
              module.exports = module.factory.apply(globals, args) || null;
              module.resolved = true;
          }
          return module.exports;
      };
    }
    
    if (!define) {
       throw new Error("The module utility (ex: requirejs or skylark-utils) is not loaded!");
    }
  
    factory(define,require);
  
    if (!isAmd) {
      var skylarkjs = require("skylark-langx-ns");
  
      if (isCmd) {
        module.exports = skylarkjs;
      } else {
        globals.skylarkjs  = skylarkjs;
      }
    }
  
  })(function(define,require) {
  
  define('skylark-langx-events/events',[
  	"skylark-langx-ns"
  ],function(skylark){
  	return skylark.attach("langx.events",{});
  });
  define('skylark-langx-events/event',[
    "skylark-langx-objects",
    "skylark-langx-funcs",
    "skylark-langx-klass",
    "skylark-langx-hoster",
      "./events"
  ],function(objects,funcs,klass,events){
      var eventMethods = {
          preventDefault: "isDefaultPrevented",
          stopImmediatePropagation: "isImmediatePropagationStopped",
          stopPropagation: "isPropagationStopped"
       };
          
  
      function compatible(event, source) {
          if (source || !event.isDefaultPrevented) {
              if (!source) {
                  source = event;
              }
  
              objects.each(eventMethods, function(name, predicate) {
                  var sourceMethod = source[name];
                  event[name] = function() {
                      this[predicate] = funcs.returnTrue;
                      return sourceMethod && sourceMethod.apply(source, arguments);
                  }
                  event[predicate] = funcs.returnFalse;
              });
          }
          return event;
      }
  
  
      /*
      var Event = klass({
          _construct : function(type,props) {
              CustomEvent.call(this,type.props);
              objects.safeMixin(this, props);
              compatible(this);
          }
      },CustomEvent);
      */
  
      class Event extends CustomEvent {
          constructor(type,props) {
              super(type,props);
              objects.safeMixin(this, props);
              compatible(this);
          } 
      }
  
  
      Event.compatible = compatible;
  
      return events.Event = Event;
      
  });
  define('skylark-langx-events/listener',[
    "skylark-langx-types",
    "skylark-langx-objects",
    "skylark-langx-arrays",
    "skylark-langx-klass",
    "./events",
    "./event"
  ],function(types,objects,arrays,klass,events,Event){
      var slice = Array.prototype.slice,
          compact = arrays.compact,
          isDefined = types.isDefined,
          isUndefined = types.isUndefined,
          isPlainObject = types.isPlainObject,
          isFunction = types.isFunction,
          isBoolean = types.isBoolean,
          isString = types.isString,
          isEmptyObject = types.isEmptyObject,
          mixin = objects.mixin,
          safeMixin = objects.safeMixin;
  
  
      var Listener = klass({
  
          listenTo: function(obj, event, selector,callback, /*used internally*/ one) {
              if (!obj) {
                  return this;
              }
  
              if (types.isPlainObject(event)){
                  //listenTo(obj,callbacks,one)
                  if (types.isBoolean(selector)) {
                      one = selector;
                      selector = null;
                  } else if (types.isBoolean(callback)) {
                      one = callback;
                  }
                  var callbacks = event;
                  for (var name in callbacks) {
  
                      var match = name.match( /^([\w:-]*)\s*(.*)$/ );
                      var name1 = match[ 1 ];
                      var selector1 = match[ 2 ] || selector;
  
                      if (selector1) {
                          this.listenTo(obj,name1,selector1,callbacks[name],one);
                      } else {
                          this.listenTo(obj,name1,callbacks[name],one);
                      }
  
                  }
                  return this;
              }
  
              if (isBoolean(callback)) {
                  one = callback;
                  callback = selector;
                  selector = null;
              } else if (isBoolean(selector)) {
                  one = selector;
                  callback = selector = null;
              } else if (isUndefined(callback)){
                  one = false;
                  callback = selector;
                  selector = null;
              }
  
  
  
              if (!callback) {
                  callback = "handleEvent";
              }
              
              // Bind callbacks on obj,
              if (isString(callback)) {
                  callback = this[callback];
              }
  
              var emitter = this.ensureListenedEmitter(obj)
  
              if (one) {
                  if (selector) {
                      emitter.one(event, selector,callback, this);
                  } else {
                      emitter.one(event, callback, this);
                  }
              } else {
                   if (selector) {
                      emitter.on(event, selector, callback, this);
                  } else {
                      emitter.on(event, callback, this);
                  }
              }
  
              //keep track of them on listening.
              var listeningTo = this._listeningTo || (this._listeningTo = []),
                  listening;
  
              for (var i = 0; i < listeningTo.length; i++) {
                  if (listeningTo[i].obj == obj) {
                      listening = listeningTo[i];
                      break;
                  }
              }
              if (!listening) {
                  listeningTo.push(
                      listening = {
                          obj: obj,
                          events: {}
                      }
                  );
              }
              var listeningEvents = listening.events,
                  listeningEvent = listeningEvents[event] = listeningEvents[event] || [];
              if (listeningEvent.indexOf(callback) == -1) {
                  listeningEvent.push(callback);
              }
  
              return this;
          },
  
          listenToOnce: function(obj, event,selector, callback) {
              return this.listenTo(obj, event,selector, callback, 1);
          },
  
          unlistenTo: function(obj, event, callback) {
              var listeningTo = this._listeningTo;
              if (!listeningTo) {
                  return this;
              }
  
              if (isString(callback)) {
                  callback = this[callback];
              }
  
              for (var i = 0; i < listeningTo.length; i++) {
                  var listening = listeningTo[i];
  
                  if (obj && obj != listening.obj) {
                      continue;
                  }
  
                  var listeningEvents = listening.events;
  
                  for (var eventName in listeningEvents) {
                      if (event && event != eventName) {
                          continue;
                      }
  
                      var listeningEvent = listeningEvents[eventName];
  
                      if (!listeningEvent) { 
                          continue;
                      }
  
                      for (var j = 0; j < listeningEvent.length; j++) {
                          if (!callback || callback == listeningEvent[i]) {
                              let emitter = this.ensureListenedEmitter(listening.obj);
                              emitter.off(eventName, listeningEvent[i], this);
                              listeningEvent[i] = null;
                          }
                      }
  
                      listeningEvent = listeningEvents[eventName] = compact(listeningEvent);
  
                      if (isEmptyObject(listeningEvent)) {
                          listeningEvents[eventName] = null;
                      }
  
                  }
  
                  if (isEmptyObject(listeningEvents)) {
                      listeningTo[i] = null;
                  }
              }
  
              listeningTo = this._listeningTo = compact(listeningTo);
              if (isEmptyObject(listeningTo)) {
                  this._listeningTo = null;
              }
  
              return this;
          },
  
          ensureListenedEmitter : function(obj) {
              return obj;
          }
      });
  
      return events.Listener = Listener;
  
  });
  define('skylark-langx-events/emitter',[
    "skylark-langx-types",
    "skylark-langx-objects",
    "skylark-langx-arrays",
    "skylark-langx-klass",
    "./events",
    "./event",
    "./listener"
  ],function(types,objects,arrays,klass,events,Event,Listener){
      var slice = Array.prototype.slice,
          compact = arrays.compact,
          isDefined = types.isDefined,
          isPlainObject = types.isPlainObject,
          isFunction = types.isFunction,
          isString = types.isString,
          isEmptyObject = types.isEmptyObject,
          mixin = objects.mixin,
          safeMixin = objects.safeMixin;
  
      function parse(event) {
          var segs = ("" + event).split(".");
          return {
              name: segs[0],
              ns: segs.slice(1).join(" ")
          };
      }
  
      
      var queues  = new Map();
  
  
      var Emitter = Listener.inherit({
          _prepareArgs : function(e,args) {
              if (isDefined(args)) {
                  args = [e].concat(args);
              } else {
                  args = [e];
              }
              return args;
          },
  
          on: function(events, selector, data, callback, ctx, /*used internally*/ one) {
              var self = this,
                  _hub = this._hub || (this._hub = {});
  
              if (isPlainObject(events)) {
                  ctx = callback;
                  each(events, function(type, fn) {
                      self.on(type, selector, data, fn, ctx, one);
                  });
                  return this;
              }
  
              if (!isString(selector) && !isFunction(callback)) {
                  ctx = callback;
                  callback = data;
                  data = selector;
                  selector = undefined;
              }
  
              if (isFunction(data)) {
                  ctx = callback;
                  callback = data;
                  data = null;
              }
  
              if (!callback ) {
                  throw new Error("No callback function");
              } else if (!isFunction(callback)) {
                  throw new Error("The callback  is not afunction");
              }
  
              if (isString(events)) {
                  events = events.split(/\s/)
              }
  
              events.forEach(function(event) {
                  var parsed = parse(event),
                      name = parsed.name,
                      ns = parsed.ns;
  
                  (_hub[name] || (_hub[name] = [])).push({
                      fn: callback,
                      selector: selector,
                      data: data,
                      ctx: ctx,
                      ns : ns,
                      one: one
                  });
              });
  
              return this;
          },
  
          one: function(events, selector, data, callback, ctx) {
              return this.on(events, selector, data, callback, ctx, 1);
          },
  
          emit: function(e /*,argument list*/ ) {
              if (!this._hub) {
                  return this;
              }
  
              var self = this;
  
              if (isString(e)) {
                  e = new Event(e); //new CustomEvent(e);
              }
  
              Object.defineProperty(e,"target",{
                  value : this
              });
  
              var args = slice.call(arguments, 1);
  
              args = this._prepareArgs(e,args);
  
              [e.type || e.name, "all"].forEach(function(eventName) {
                  var parsed = parse(eventName),
                      name = parsed.name,
                      ns = parsed.ns;
  
                  var listeners = self._hub[name];
                  if (!listeners) {
                      return;
                  }
  
                  var len = listeners.length,
                      reCompact = false;
  
                  for (var i = 0; i < len; i++) {
                      if (e.isImmediatePropagationStopped && e.isImmediatePropagationStopped()) {
                          return this;
                      }
                      var listener = listeners[i];
                      if (ns && (!listener.ns ||  !listener.ns.startsWith(ns))) {
                          continue;
                      }
  
                      if (listener.data) {
                          e.data = mixin({}, listener.data, e.data);
                      }
                      if (args.length == 2 && isPlainObject(args[1])) {
                          e.data = e.data || {};
                          mixin(e.data,args[1]);
                      }
  
                      listener.fn.apply(listener.ctx, args);
                      if (listener.one) {
                          listeners[i] = null;
                          reCompact = true;
                      }
                  }
  
                  if (reCompact) {
                      self._hub[eventName] = compact(listeners);
                  }
  
              });
              return this;
          },
  
          queueEmit : function (event) {
              const type = event.type || event;
              let map = queues.get(this);
              if (!map) {
                  map = new Map();
                  queues.set(this, map);
              }
              const oldTimeout = map.get(type);
              map.delete(type);
              window.clearTimeout(oldTimeout);
              const timeout = window.setTimeout(() => {
                  if (map.size === 0) {
                      map = null;
                      queues.delete(this);
                  }
                  this.trigger(event);
              }, 0);
              map.set(type, timeout);
          },
  
          listened: function(event) {
              var evtArr = ((this._hub || (this._events = {}))[event] || []);
              return evtArr.length > 0;
          },
  
          off: function(events, callback) {
              if (!events) {
                this._hub = null;
                return;
              }
              var _hub = this._hub || (this._hub = {});
              if (isString(events)) {
                  events = events.split(/\s/)
              }
  
              events.forEach(function(event) {
                  var parsed = parse(event),
                      name = parsed.name,
                      ns = parsed.ns;
  
                  var evts = _hub[name];
  
                  if (evts) {
                      var liveEvents = [];
  
                      if (callback || ns) {
                          for (var i = 0, len = evts.length; i < len; i++) {
                              
                              if (callback && evts[i].fn !== callback && evts[i].fn._ !== callback) {
                                  liveEvents.push(evts[i]);
                                  continue;
                              } 
  
                              if (ns && (!evts[i].ns || evts[i].ns.indexOf(ns)!=0)) {
                                  liveEvents.push(evts[i]);
                                  continue;
                              }
                          }
                      }
  
                      if (liveEvents.length) {
                          _hub[name] = liveEvents;
                      } else {
                          delete _hub[name];
                      }
  
                  }
              });
  
              return this;
          },
  
          trigger  : function() {
              return this.emit.apply(this,arguments);
          },
  
          queueTrigger : function (event) {
              return this.queueEmit.apply(this,arguments);
          }
  
      });
  
  
      return events.Emitter = Emitter;
  
  });
  define('skylark-langx-events/create-event',[
  	"./events",
  	"./event"
  ],function(events,Event){
      function createEvent(type,props) {
          //var e = new CustomEvent(type,props);
          //return safeMixin(e, props);
          return new Event(type,props);
      };
  
      return events.createEvent = createEvent;	
  });
  define('skylark-langx-events/main',[
  	"./events",
  	"./event",
  	"./listener",
  	"./emitter",
  	"./create-event"
  ],function(events){
  	return events;
  });
  define('skylark-langx-events', ['skylark-langx-events/main'], function (main) { return main; });
  
  
  },this);
  //# sourceMappingURL=sourcemaps/skylark-langx-events.js.map
  