// modules are defined as an array
// [ module function, map of requires ]
//
// map of requires is short require name -> numeric require
//
// anything defined in a previous bundle is accessed via the
// orig method which is the require for previous bundles

(function(modules, cache, entry, mainEntry, parcelRequireName, globalName) {
  /* eslint-disable no-undef */
  var globalObject =
    typeof globalThis !== 'undefined'
      ? globalThis
      : typeof self !== 'undefined'
      ? self
      : typeof window !== 'undefined'
      ? window
      : typeof global !== 'undefined'
      ? global
      : {};
  /* eslint-enable no-undef */

  // Save the require from previous bundle to this closure if any
  var previousRequire =
    typeof globalObject[parcelRequireName] === 'function' &&
    globalObject[parcelRequireName];
  // Do not use `require` to prevent Webpack from trying to bundle this call
  var nodeRequire =
    typeof module !== 'undefined' &&
    typeof module.require === 'function' &&
    module.require.bind(module);

  function newRequire(name, jumped) {
    if (!cache[name]) {
      if (!modules[name]) {
        // if we cannot find the module within our internal map or
        // cache jump to the current global require ie. the last bundle
        // that was added to the page.
        var currentRequire =
          typeof globalObject[parcelRequireName] === 'function' &&
          globalObject[parcelRequireName];
        if (!jumped && currentRequire) {
          return currentRequire(name, true);
        }

        // If there are other bundles on this page the require from the
        // previous one is saved to 'previousRequire'. Repeat this as
        // many times as there are bundles until the module is found or
        // we exhaust the require chain.
        if (previousRequire) {
          return previousRequire(name, true);
        }

        // Try the node require function if it exists.
        if (nodeRequire && typeof name === 'string') {
          return nodeRequire(name);
        }

        var err = new Error("Cannot find module '" + name + "'");
        err.code = 'MODULE_NOT_FOUND';
        throw err;
      }

      localRequire.resolve = resolve;
      localRequire.cache = {};

      var module = (cache[name] = new newRequire.Module(name));

      modules[name][0].call(
        module.exports,
        localRequire,
        module,
        module.exports,
        this
      );
    }

    return cache[name].exports;

    function localRequire(x) {
      return newRequire(localRequire.resolve(x));
    }

    function resolve(x) {
      return modules[name][1][x] || x;
    }
  }

  function Module(moduleName) {
    this.id = moduleName;
    this.bundle = newRequire;
    this.exports = {};
  }

  newRequire.isParcelRequire = true;
  newRequire.Module = Module;
  newRequire.modules = modules;
  newRequire.cache = cache;
  newRequire.parent = previousRequire;
  newRequire.register = function(id, exports) {
    modules[id] = [
      function(require, module) {
        module.exports = exports;
      },
      {},
    ];
  };

  Object.defineProperty(newRequire, 'root', {
    get: function() {
      return globalObject[parcelRequireName];
    },
  });

  globalObject[parcelRequireName] = newRequire;

  for (var i = 0; i < entry.length; i++) {
    newRequire(entry[i]);
  }

  if (mainEntry) {
    // Expose entry point to Node, AMD or browser globals
    // Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
    var mainExports = newRequire(mainEntry);

    // CommonJS
    if (typeof exports === 'object' && typeof module !== 'undefined') {
      module.exports = mainExports;

      // RequireJS
    } else if (typeof define === 'function' && define.amd) {
      define(function() {
        return mainExports;
      });

      // <script>
    } else if (globalName) {
      this[globalName] = mainExports;
    }
  }
})({"6Sju2":[function(require,module,exports) {
var HMR_HOST = null;
var HMR_PORT = 1234;
var HMR_ENV_HASH = "d751713988987e9331980363e24189ce";
module.bundle.HMR_BUNDLE_ID = "1b904d2cb5fe07e363f1ec693d0da0e0";
/* global HMR_HOST, HMR_PORT, HMR_ENV_HASH */

var OVERLAY_ID = '__parcel__error__overlay__';
var OldModule = module.bundle.Module;

function Module(moduleName) {
  OldModule.call(this, moduleName);
  this.hot = {
    data: module.bundle.hotData,
    _acceptCallbacks: [],
    _disposeCallbacks: [],
    accept: function (fn) {
      this._acceptCallbacks.push(fn || function () {});
    },
    dispose: function (fn) {
      this._disposeCallbacks.push(fn);
    }
  };
  module.bundle.hotData = null;
}

module.bundle.Module = Module;
var checkedAssets, assetsToAccept, acceptedAssets;

function getHostname() {
  return HMR_HOST || (location.protocol.indexOf('http') === 0 ? location.hostname : 'localhost');
}

function getPort() {
  return HMR_PORT || location.port;
} // eslint-disable-next-line no-redeclare


var parent = module.bundle.parent;

if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
  var hostname = getHostname();
  var port = getPort();
  var protocol = location.protocol === 'https:' ? 'wss' : 'ws';
  var ws = new WebSocket(protocol + '://' + hostname + (port ? ':' + port : '') + '/');

  ws.onmessage = function (event) {
    checkedAssets = {};
    assetsToAccept = [];
    acceptedAssets = {};
    var data = JSON.parse(event.data);

    if (data.type === 'update') {
      // Remove error overlay if there is one
      removeErrorOverlay();
      let assets = data.assets.filter(asset => asset.envHash === HMR_ENV_HASH); // Handle HMR Update

      var handled = false;
      assets.forEach(asset => {
        var didAccept = asset.type === 'css' || hmrAcceptCheck(module.bundle.root, asset.id);

        if (didAccept) {
          handled = true;
        }
      });

      if (handled) {
        console.clear();
        assets.forEach(function (asset) {
          hmrApply(module.bundle.root, asset);
        });

        for (var i = 0; i < assetsToAccept.length; i++) {
          var id = assetsToAccept[i][1];

          if (!acceptedAssets[id]) {
            hmrAcceptRun(assetsToAccept[i][0], id);
          }
        }
      } else {
        window.location.reload();
      }
    }

    if (data.type === 'error') {
      // Log parcel errors to console
      for (let ansiDiagnostic of data.diagnostics.ansi) {
        let stack = ansiDiagnostic.codeframe ? ansiDiagnostic.codeframe : ansiDiagnostic.stack;
        console.error('🚨 [parcel]: ' + ansiDiagnostic.message + '\n' + stack + '\n\n' + ansiDiagnostic.hints.join('\n'));
      } // Render the fancy html overlay


      removeErrorOverlay();
      var overlay = createErrorOverlay(data.diagnostics.html);
      document.body.appendChild(overlay);
    }
  };

  ws.onerror = function (e) {
    console.error(e.message);
  };

  ws.onclose = function (e) {
    console.warn('[parcel] 🚨 Connection to the HMR server was lost');
  };
}

function removeErrorOverlay() {
  var overlay = document.getElementById(OVERLAY_ID);

  if (overlay) {
    overlay.remove();
    console.log('[parcel] ✨ Error resolved');
  }
}

function createErrorOverlay(diagnostics) {
  var overlay = document.createElement('div');
  overlay.id = OVERLAY_ID;
  let errorHTML = '<div style="background: black; opacity: 0.85; font-size: 16px; color: white; position: fixed; height: 100%; width: 100%; top: 0px; left: 0px; padding: 30px; font-family: Menlo, Consolas, monospace; z-index: 9999;">';

  for (let diagnostic of diagnostics) {
    let stack = diagnostic.codeframe ? diagnostic.codeframe : diagnostic.stack;
    errorHTML += "\n      <div>\n        <div style=\"font-size: 18px; font-weight: bold; margin-top: 20px;\">\n          \uD83D\uDEA8 ".concat(diagnostic.message, "\n        </div>\n        <pre>\n          ").concat(stack, "\n        </pre>\n        <div>\n          ").concat(diagnostic.hints.map(hint => '<div>' + hint + '</div>').join(''), "\n        </div>\n      </div>\n    ");
  }

  errorHTML += '</div>';
  overlay.innerHTML = errorHTML;
  return overlay;
}

function getParents(bundle, id) {
  var modules = bundle.modules;

  if (!modules) {
    return [];
  }

  var parents = [];
  var k, d, dep;

  for (k in modules) {
    for (d in modules[k][1]) {
      dep = modules[k][1][d];

      if (dep === id || Array.isArray(dep) && dep[dep.length - 1] === id) {
        parents.push([bundle, k]);
      }
    }
  }

  if (bundle.parent) {
    parents = parents.concat(getParents(bundle.parent, id));
  }

  return parents;
}

function updateLink(link) {
  var newLink = link.cloneNode();

  newLink.onload = function () {
    if (link.parentNode !== null) {
      link.parentNode.removeChild(link);
    }
  };

  newLink.setAttribute('href', link.getAttribute('href').split('?')[0] + '?' + Date.now());
  link.parentNode.insertBefore(newLink, link.nextSibling);
}

var cssTimeout = null;

function reloadCSS() {
  if (cssTimeout) {
    return;
  }

  cssTimeout = setTimeout(function () {
    var links = document.querySelectorAll('link[rel="stylesheet"]');

    for (var i = 0; i < links.length; i++) {
      var href = links[i].getAttribute('href');
      var hostname = getHostname();
      var servedFromHMRServer = hostname === 'localhost' ? new RegExp('^(https?:\\/\\/(0.0.0.0|127.0.0.1)|localhost):' + getPort()).test(href) : href.indexOf(hostname + ':' + getPort());
      var absolute = /^https?:\/\//i.test(href) && href.indexOf(window.location.origin) !== 0 && !servedFromHMRServer;

      if (!absolute) {
        updateLink(links[i]);
      }
    }

    cssTimeout = null;
  }, 50);
}

function hmrApply(bundle, asset) {
  var modules = bundle.modules;

  if (!modules) {
    return;
  }

  if (modules[asset.id] || !bundle.parent) {
    if (asset.type === 'css') {
      reloadCSS();
    } else {
      var fn = new Function('require', 'module', 'exports', asset.output);
      modules[asset.id] = [fn, asset.depsByBundle[bundle.HMR_BUNDLE_ID]];
    }
  } else if (bundle.parent) {
    hmrApply(bundle.parent, asset);
  }
}

function hmrAcceptCheck(bundle, id) {
  var modules = bundle.modules;

  if (!modules) {
    return;
  }

  if (!modules[id] && bundle.parent) {
    return hmrAcceptCheck(bundle.parent, id);
  }

  if (checkedAssets[id]) {
    return;
  }

  checkedAssets[id] = true;
  var cached = bundle.cache[id];
  assetsToAccept.push([bundle, id]);

  if (cached && cached.hot && cached.hot._acceptCallbacks.length) {
    return true;
  }

  return getParents(module.bundle.root, id).some(function (v) {
    return hmrAcceptCheck(v[0], v[1]);
  });
}

function hmrAcceptRun(bundle, id) {
  var cached = bundle.cache[id];
  bundle.hotData = {};

  if (cached && cached.hot) {
    cached.hot.data = bundle.hotData;
  }

  if (cached && cached.hot && cached.hot._disposeCallbacks.length) {
    cached.hot._disposeCallbacks.forEach(function (cb) {
      cb(bundle.hotData);
    });
  }

  delete bundle.cache[id];
  bundle(id);
  cached = bundle.cache[id];

  if (cached && cached.hot && cached.hot._acceptCallbacks.length) {
    cached.hot._acceptCallbacks.forEach(function (cb) {
      var assetsToAlsoAccept = cb(function () {
        return getParents(module.bundle.root, id);
      });

      if (assetsToAlsoAccept && assetsToAccept.length) {
        assetsToAccept.push.apply(assetsToAccept, assetsToAlsoAccept);
      }
    });
  }

  acceptedAssets[id] = true;
}
},{}],"18HlE":[function(require,module,exports) {
"use strict";

var _vm = require("../../vm");

var _app = _interopRequireDefault(require("./app"));

var _logging = _interopRequireDefault(require("../../core/logging"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

_logging.default.showError(); // console.log(Exir.render(App))


_vm.Exir.mount(_app.default, document.getElementById('root'));
},{"../../vm":"27HCd","./app":"6Fg91","../../core/logging":"3xiP7"}],"27HCd":[function(require,module,exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.jsx = exports.Exir = void 0;

var _vnode = require("./vnode");

var _view = require("./view");

var _render = require("./render");

var _renderDom = require("./render-dom");

const Exir = {
  View: _view.View,
  createView: _view.View.create,
  createElement: _vnode.VNode.create,
  render: _render.render,
  renderDom: _renderDom.renderDom,
  mount: function mount(app, targetElement) {
    (0, _renderDom.renderDom)((0, _render.render)(app), targetElement);
  }
};
exports.Exir = Exir;
const jsx = _vnode.VNode.create;
exports.jsx = jsx;
},{"./vnode":"rEOtM","./view":"7rP3i","./render":"2RJeN","./render-dom":"3RwzU"}],"rEOtM":[function(require,module,exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.VNode = void 0;

var _collections = require("../core/collections");

var _util = _interopRequireDefault(require("./util"));

var _view = require("./view");

var _nodetype = _interopRequireDefault(require("./nodetype"));

var _core = require("../core");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
 * @property {[VNode|View|String]|VNode|View|String} nodes
 * @property {View} [$root]
 * @property {Object} [attrs]
 * @property {HTMLElement|Element|Node} [target]
 */
class VNode {
  constructor(tag, props, ...children) {
    this.$tag = tag;

    if (tag === '#text') {
      this.$type = _nodetype.default.TEXT;
      this.text = props;
      this.isText = true;
      return;
    }

    this.$isNode = true;
    this.$type = _nodetype.default.NODE;
    if (tag === 'FRAGMENT') this.$isFrag = true;

    if (props) {
      (0, _collections.concat)(this, _util.default.compileProps(props));
    }

    if (children) {
      children = _util.default.prepareChildren(children);
      this.nodes = children;
    }
  }
  /**
   * Create View | VNode | #TEXT
   *
   * @param {View|VNode|String|Number} type
   * @param {Object|undefined} props
   * @param {View|VNode|String|Number} children
   * @returns {any|VNode}
   */


  static create(type, props = {}, ...children) {
    if (props === null) props = {}; // flatten arrays and change str/num to VNode(#text)
    // children = util.prepareChildren(children)

    const nodes = [];
    const len = children.length;

    for (let i = 0; i < len; i++) {
      let child = children[i];

      if (child.$tag === 'FRAGMENT') {
        // console.log('FRAG', type, child)
        child = child.nodes;
      } // if (child.constructor.name === 'Array') {


      if (child instanceof Array) {
        const clen = child.length;

        for (let j = 0; j < clen; j++) {
          let ch = child[j];

          if ((0, _core.isStr)(ch) || (0, _core.isNum)(ch)) {
            // ch = VNode.createText(ch.toString())
            ch = new VNode('#text', ch.toString());
          } // if (after) ch = after(ch)
          // ch.rootView = rootView


          nodes.push(ch);
        }
      } else {
        if ((0, _core.isStr)(child) || (0, _core.isNum)(child)) {
          // child = VNode.createText(child.toString())
          child = new VNode('#text', child.toString());
        } // if (after) child = after(child)
        // child.rootView = rootView


        nodes.push(child); // child.$root = type
      }
    }

    children = nodes; // children = util.prepareChildren(children)
    // View class instance

    if (type.$isView) {
      return type.createInstance(props, children);
    } // View class


    if (type.$type === _nodetype.default.VIEW) {
      return new type().updateInstance(props, children);
    } // create VNode instance
    // return VNode.createTag(type, props, ...children);


    return new VNode(type, props, ...children);
  }

  static createText(str) {
    return new VNode('#text', str);
  }

  static createTag(type, props = {}, ...children) {
    return new VNode(type, props, ...children);
  }

  $remove() {
    if (!this.$isFrag && this.target) this.target.remove();
    if (this.nodes) for (let n of this.nodes) {
      n.$remove();
    }
  }

  $firstElement() {
    if (!this.$isFrag) return this.target;

    if (this.nodes) {
      return this.nodes[0].$firstElement();
    }
  }

  $lastElement() {
    if (!this.$isFrag) return this.target;

    if (this.nodes) {
      return this.nodes[this.nodes.length - 1].$firstElement();
    }
  }

}

exports.VNode = VNode;
},{"../core/collections":"1hgia","./util":"2Pcrs","./view":"7rP3i","./nodetype":"5oyRM","../core":"1A9AF"}],"1hgia":[function(require,module,exports) {
var global = arguments[3];

/**
 * @module core/collections
 * @memberOf core
 */
const T = require("./types");

if (!global._X_LOOP_BREAK_) {
  global._X_LOOP_BREAK_ = Symbol("BREAK_LOOP");
  global._X_ANY_ = Symbol("ANY");
  global._X_ALL_ = Symbol("ALL");
}
/**
 * Break from functional loops: forEach, filter, ...
 * @type {symbol}
 */


const BREAK = global._X_LOOP_BREAK_;
/**
 * Match Any: Used as value in predicate object
 * @type {symbol}
 */

const ANY = global._X_ANY_;
const ALL = global._X_ALL_;
const UNSAFE_PROPS = ['__proto__', 'constructor', '__defineGetter__', '__defineSetter__', 'prototype'];
/**
 * Get item by index from multiple source types
 *
 * @param {Array|Object|String|NodeList|HTMLCollection} s - source
 * @param {Number|String} i - item index
 * @returns {any|null|undefined}
 */

function item(s, i) {
  if (!T.isVal(s)) return undefined;
  if (T.isObj(s)) return s[i];
  if (T.isStr(s)) return s[i];
  if (T.isArr(s)) return s[i];else return s.item(i);
}
/**
 * Source contains value or key:value
 *
 * @param {Array|Object|String} src
 * @param {any} value
 * @param {String|undefined} [key]
 * @returns {boolean}
 */


function contains(src, value, key) {
  if (!T.isVal(src)) return false;
  if (!T.isArr(src) && T.isObj(src)) return src[key] === value;
  return src.indexOf(value) >= 0;
}
/**
 * Add item(s) to source
 *
 * @param {Array|{add:Function}} src - source
 * @param {any} v - values
 */


function add(src, ...v) {
  if (T.isArr(src)) {
    forEach(v, vi => src.push(vi));
  } else if (T.isMutableList(src)) {
    src.add(v);
  }
}
/**
 * Remove item(s) from source
 *
 * @param {Array|String} src
 * @param {...any} it
 * @returns {boolean}
 */


function remove(src, ...it) {
  it = flatMap(it);
  let any = false;
  forEach(it, item => {
    let idx = src.indexOf(item);

    if (idx >= 0) {
      any = true;
      src.splice(idx, 1);
    }
  });
  return any;
}
/**
 * Toggles items in source
 *
 * @param {Array} src
 * @param {...any} c
 */


function toggle(src, ...c) {
  if (c.length === 0) return;
  c = flatMap(c);
  let idx = undefined;

  if (c.length === 1) {
    if (!remove(src, c)) {
      add(src, c[0]);
    }
  } else {
    c.push(c[0]);
    let any = false;
    forEach(src, (cl, i) => {
      idx = c.indexOf(cl);

      if (idx >= 0 && c.length > idx + 1) {
        any = true;
        src[i] = c[idx + 1];
      }
    });

    if (!any) {
      src.push(c[0]);
    }
  }
}

function objMatchOne(o, match) {
  let m = Object.keys(match);

  for (let k of m) {
    // if (!T.isObj(o[k])) continue;
    if (match[k] === ANY && o.hasOwnProperty(k)) return true;
    if (match[k] === o[k]) return true;
  }

  return false;
}

function objMatchAll(o, match) {
  let m = Object.keys(match);

  for (let k of m) {
    // if (!T.isObj(o[k])) return false;
    if (match[k] === ANY) continue;
    if (match[k] !== o[k]) return false;
  }

  return true;
}

function predicate(f, def = () => true, inc = true) {
  if (T.isUnd(f)) return def;
  if (T.isFun(f)) return f;else if (f instanceof RegExp) return (v, k, i, s) => !T.isObj(v) ? f.test(v.toString()) : false;else if (T.isObj(f)) {
    if (Object.keys(f).length === 0) return def;
    return inc ? (v, k, i, s) => objMatchOne(v, f) : (v, k, i, s) => objMatchAll(v, f);
  } else return (v, k, i, s) => v === f;
}

function funOrKey(f) {
  if (T.isUnd(f)) return v => v;
  if (T.isFun(f)) return f;

  if (T.isStr(f)) {
    const key = f;

    f = v => v[key];
  }

  throw Error(`Predicate ${f} cannot be of type ${typeof f}`);
}
/**
 * Create empty instance of given source
 *
 * @param {any} src - source object
 * @param {any} def - default value for primitives
 * @returns {any} empty instance of src
 */


function emptyOf(src, def = {}) {
  if (T.isStr(src)) return "";
  if (T.isList(src)) return [];

  if (T.isObj(src)) {
    if (T.isEl(src)) {
      if (src.nodeType === 3 || src.nodeType === 8) {
        return document.createTextNode(src.textContent);
      } else {
        return document.createElement(src.tagName);
      }
    }

    if (src.__proto__) return Object.create(src.__proto__);
    return {};
  }

  return def;
}
/**
 * Type-agnostic concat. !!Mutates target!!
 *
 * @param {Array|String|Object} target
 * @param {Array|String|Object} source
 * @returns {Array|String|Object}
 */


function concat(target, source, override = false) {
  if (T.isStr(target)) {
    return target.concat(source);
  }

  if (T.isArr(target)) {
    return target.concat(source);
  }

  for (let k of Object.keys(source)) {
    if (!target[k] || override) target[k] = source[k];
  }

  return target;
}
/**
 * Polyfill-like for Object.values (uses native method if available)
 *
 * @param {Object} obj
 * @returns {Array|undefined} - array of values
 */


function objectValues(obj) {
  if (Object.values) {
    return Object.values(obj);
  } else {
    return map(obj, v => v);
  }
}
/**
 * Index for loop from "init" to "finish"(included) by "step"
 *
 * @param {Function} func
 * @param {Number} init
 * @param {Number} finish
 * @param {Number} [step]
 */


function forN(func, init = 0, finish = 0, step = init < finish ? 1 : -1) {
  if (step > 0) {
    for (; init <= finish; init += step) {
      func(init);
    }
  }

  for (; init >= finish; init += step) {
    func(init);
  }
}
/**
 * forEach(left) with limited range
 *
 * @param {Array|Object|NodeList|HTMLCollection} src
 * @param {Function} func
 * @param {Number} [start]
 * @param {Number?} [end]
 * @returns {*|number}
 */


function forEachRange(src, func, start = 0, end) {
  if (!T.isArr(src) || !T.isStr(src)) {
    let keys = Object.keys(src);
    end = end || keys.length - 1;

    for (let i = start; i <= end; i++) {
      let r = func(src[keys[i]], keys[i], i, src);
      if (r === BREAK) return i;
    }

    return end;
  }

  end = end || src.length;

  for (let i = start; i < end; i++) {
    let r = func(item(src, i), i, i, src);
    if (r === BREAK) return i;
  }

  return end;
}
/**
 * Type-agnostic forEach loop
 *
 * @param src
 * @param func
 * @returns {number|*}
 */


function forEach(src, func) {
  if (!T.isVal(src)) return -1;

  if (!T.isArr(src) || !T.isStr(src) || !T.isList(src)) {
    let i = 0;
    let keys = Object.keys(src);
    const len = keys.length;

    for (; i < len; i++) {
      // let r = ;
      const k = keys[i],
            v = src[k];
      if (func(v, k, i, src) === BREAK) return i;
    }

    return i;
  }

  const len = src.length;

  if (!T.isArr(src)) {
    for (let i = 0; i < len; i++) {
      const v = src[i];
      let r = func(v, i, i, src);
      if (r === BREAK) return i;
    }
  } else {
    for (let i = 0; i < len; i++) {
      const v = item(src, i);
      let r = func(v, i, i, src);
      if (r === BREAK) return i;
    }
  }

  return src.length;
}
/**
 * Type-agnostic forEachRight loop
 *
 * @param src
 * @param func
 * @param range
 * @returns {number|*}
 */


function forEachRight(src, func, range = []) {
  if (!T.isArr(src) || !T.isStr(src)) {
    let i = 0;
    let keys = Object.keys(src);

    for (let i = keys.length - 1; i >= 0; i--) {
      if (i < range[1]) continue;
      if (i >= range[0]) return i;
      let r = func(src[keys[i]], keys[i], i, src);
      if (r === BREAK) return i;
    }

    return i;
  }

  for (let i = src.length - 1; i >= 0; i--) {
    let r = func(item(src, i), i, i, src);
    if (r === BREAK) return i;
  }

  return src.length;
}
/**
 * Extended version of native indexOf method, using {@link forEach}
 * @see forEach
 * @param {Array|Object|String|NodeList|HTMLCollection} src
 * @param {Function|Object|Array} pred - predicate function/{key:value}/[keys]
 * @returns {number}
 */


function firstIndex(src, pred) {
  pred = predicate(pred, () => true);
  let r = -1;
  forEach(src, function (v, k, i) {
    r = pred(v, k, i, src);

    if (r === true) {
      r = i;
      return BREAK;
    }
  });
  return r;
}
/**
 * Extended version of native first method, using {@link firstIndex}
 * @see firstIndex
 * @param {Array|Object|String|NodeList|HTMLCollection} src
 * @param {Function|Object|Array} [pred] - predicate function/{key:value}/[keys]
 * @returns {*}
 */


function first(src, pred) {
  return item(src, firstIndex(src, pred));
}
/**
 * Returns true if first item matches predicate
 *
 * @param {Array|Object|String|NodeList|HTMLCollection} src
 * @param {Function|Object|Array} [pred] - predicate function/{key:value}/[keys] pred
 * @returns {boolean|*}
 */


function startsWith(src, pred) {
  if (T.isStr(src) && T.isStr(pred)) {
    return src.indexOf(pred) === 0;
  }

  pred = predicate(pred, () => true);
  return pred(first(src));
}
/**
 *
 * @param {Array|Object|String|NodeList|HTMLCollection} src
 * @param {Function|Array|Object} pred
 * @returns {number}
 */


function lastIndex(src, pred) {
  pred = predicate(pred, () => true);
  let r = -1;
  forEachRight(src, function (v, k, i) {
    r = pred(v, k, i);

    if (r === true) {
      r = i;
      return BREAK;
    }
  });
  return r;
}
/**
 *
 * @param {Array|Object|String|NodeList|HTMLCollection} src
 * @param {Function|Array|Object} [pred]
 * @returns {*}
 */


function last(src, pred) {
  return src[lastIndex(src, pred)];
}
/**
 *
 * @param {Array|Object|String|NodeList|HTMLCollection} src
 * @param {Function|Array|Object} pred
 * @returns {boolean|*}
 */


function endsWith(src, pred) {
  if (T.isStr(src) && T.isStr(pred)) {
    return src.indexOf(pred) === src.length - pred.length;
  }

  pred = predicate(pred, () => true);
  return pred(last(src));
}
/**
 * Reverse array-like src
 *
 * @param {Array|Object|String|NodeList|HTMLCollection} src
 * @returns {Array|Object|String|NodeList|HTMLCollection} - reversed src
 */


function reverse(src) {
  if (T.isArr(src)) return src.reverse();
  let rev = "";
  forEachRight(src, function (it) {
    rev += it;
  });
  return rev;
}
/**
 * A more versatile alternative to native "some" method
 *
 * @param {Array|Object|String|NodeList|HTMLCollection} src
 * @param {Function|Array|Object} pred
 * @returns {boolean}
 */


function any(src, pred) {
  // if (!func){
  //     if (T.isArr(src) || T.isStr(src)) return src.length>0;
  //     return Object.keys(src).length>0;
  // }
  let fn = predicate(pred);
  let r = false;
  forEach(src, function (v, k, i, src) {
    r = fn(v, k, i, src);
    if (r === true) return BREAK;
  });
  return r;
}
/**
 * A more versatile alternative to native "every" method
 *
 * @param {Array|Object|String|NodeList|HTMLCollection} src
 * @param {Function|Array|Object} pred
 * @returns {boolean}
 */


function all(src, pred) {
  pred = predicate(pred, () => true);
  let r = true;
  forEach(src, function (v, k, i, src) {
    r = pred(v, k, i, src);
    if (r === false) return BREAK;
  });
  return r;
}

function filterStr(src, pred, right = false, omit = false) {
  pred = predicate(pred, () => true);
  let res = "";
  let loop = right ? forEachRight : forEach;
  loop(src, function (v, k, i) {
    if (!pred || pred(v, k, i, src) === omit) res += v;
  });
  return res;
}

function filterObj(src, pred, right = false, omit = false) {
  if (T.isArr(pred)) {
    let a = Object.assign({}, pred);
    if (omit) pred = (v, k) => !any(a, k);else pred = (v, k) => any(a, k);
  } else pred = predicate(pred, () => true);

  let res = {}; // let loop = right ? ForEachRight : ForEach;

  const keys = Object.keys(src);
  const len = keys.length;

  if (!right) {
    for (let i = 0; i < len; i++) {
      const k = keys[i];
      const v = src[k];
      if (pred(v, k, i, src) !== omit) res[k] = v;
    }
  } else {
    for (let i = len - 1; i >= 0; i--) {
      const k = keys[i];
      const v = src[k];
      if (pred(v, k, i, src) !== omit) res[k] = v;
    }
  } // loop(src, function (v, k, i) {
  //     if (pred(v, k, i, src) !== omit) res[k] = v;
  // });


  return res;
}

function filterArr(src, pred, right = false, omit = false) {
  if (T.isArr(pred)) {
    let a = Object.assign([], pred);
    if (omit) pred = (v, k, i) => !any(a, i);else pred = (v, k, i) => any(a, i);
  } else pred = predicate(pred, () => true);

  let res = [];
  const len = src.length;

  if (!right) {
    for (let i = 0; i < len; i++) {
      const v = src[i];

      if (pred(v, i, i, src) !== omit) {
        res.push(v);
      }
    }
  } else {
    for (let i = len - 1; i >= 0; i--) {
      const v = src[i];

      if (!pred(v, i, i, src) !== omit) {
        res.push(v);
      }
    }
  }

  return res;
}
/**
 * A more versatile alternative to native "filter" method
 *
 * @param {Array|Object|String|NodeList|HTMLCollection} src - source
 * @param {Function|Array|Object} pred - predicate function/{key:value}/[keys]
 * @param {boolean} [right] - reverse loop
 * @returns {Array|Object|String}
 */


function filter(src, pred, right = false) {
  if (T.isStr(src)) return filterStr(src, pred, right);
  if (T.isArr(src) || T.isList(src)) return filterArr(src, pred, right);
  return filterObj(src, pred, right);
}
/**
 * Opposite of filter, returns items not matching predicate
 *
 * @param {Array|Object|String|NodeList|HTMLCollection} src - source
 * @param {Function|Array|Object} pred - predicate function/{key:value}/[keys]
 * @param {boolean} [right] - reverse loop
 * @returns {Array|Object|String}
 */


function omit(src, pred, right = false) {
  if (T.isStr(src)) return filterStr(src, pred, right, true);
  if (T.isArr(src) || T.isList(src)) return filterArr(src, pred, right, true);
  return filterObj(src, pred, right, true);
}
/**
 * {@link filter} in reverse order (right)
 *
 * @param {Array|Object|String|NodeList|HTMLCollection} src - source
 * @param {Function|Array|Object} pred - predicate function/{key:value}/[keys]
 * @returns {Array|Object|String}
 */


function filterRight(src, pred) {
  return filter(src, pred, true);
}
/**
 * Find max index
 *
 * @param {Array|Object|String|NodeList|HTMLCollection} list
 * @param {Function|String} pred - predicate function/key
 * @return {number}
 */


function maxIndex(list, pred) {
  pred = funOrKey(pred);
  let mx;
  let index = -1;
  forEach(list, function (i, ix) {
    let x = pred(i, ix);

    if (!mx) {
      mx = x;
      index = ix;
    } else if (x >= mx) {
      mx = x;
      index = ix;
    }
  });
  return index;
}
/**
 * Find max
 *
 * @param {Array|Object|String|NodeList|HTMLCollection} list
 * @param {Function|String} pred - predicate function/key
 * @return {number}
 */


function max(list, pred) {
  return list[maxIndex(list, pred)];
}
/**
 * Find min index
 *
 * @param {Array|Object|String|NodeList|HTMLCollection} list
 * @param {Function|String} pred - predicate function/key
 * @return {number}
 */


function minIndex(list, pred) {
  pred = funOrKey(pred);
  let mn;
  let index = -1;
  forEach(list, function (i, ix) {
    let x = pred(i, ix);

    if (!mn) {
      mn = x;
      index = ix;
    } else if (x <= mn) {
      mn = x;
      index = ix;
    }
  });
  return index;
}
/**
 * Find min
 *
 * @param {Array|Object|String|NodeList|HTMLCollection} list
 * @param {Function|String} pred - predicate function/key
 * @return {number}
 */


function min(list, pred) {
  return list[minIndex(list, pred)];
}

function mapArr(src, func, right = false) {
  let res = []; // let loop = right ? ForEachRight : ForEach;

  const len = src.length;

  if (!right) {
    for (let i = 0; i < len; i++) {
      let r = func(src[i], i, src);
      if (r === BREAK) break;
      if (!T.isUnd(r)) res.push(r);
    }
  } else {
    for (let i = len; i >= 0; i--) {
      let r = func(src[i], i, src);
      if (r === BREAK) break;
      if (!T.isUnd(r)) res.push(r);
    }
  } // loop(src, function (a, i) {
  //     let r = func(a, i, src);
  //     if (!T.isUnd(r))
  //         res.push(r);
  // });


  return res;
}

function mapObj(src, func, right = false) {
  let res = {}; // let loop = right ? ForEachRight : ForEach;

  const keys = Object.keys(src);
  const len = src.length;

  if (!right) {
    for (let i = 0; i < len; i++) {
      const k = keys[i];
      const v = src[k];
      let r = func(v, k, i, src);
      if (r === BREAK) break;
      if (!T.isUnd(r)) res[k] = r;
    }
  } else {
    for (let i = len; i >= 0; i--) {
      const k = keys[i];
      const v = src[k];
      let r = func(v, k, i, src);
      if (r === BREAK) break;
      if (!T.isUnd(r)) res[k] = r;
    }
  } // loop(src, function (v, k, i) {
  //     let r = func(v, k, i, src);
  //     if (!T.isUnd(r))
  //         res[k] = r
  // });


  return res;
}
/**
 * A more versatile alternative to native "map" method
 *
 * @param {Array|Object|String|NodeList|HTMLCollection} src - source
 * @param {Function|Array|Object} transform - transformer function
 * @param {boolean} [right] - reverse loop
 * @returns {Array|Object|String}
 */


function map(src, transform, right = false) {
  transform = predicate(transform, v => v);
  if (T.isArr(src)) return mapArr(src, transform, right);else if (T.isObj(src)) return mapObj(src, transform, right);
}
/**
 * A more versatile alternative to native "flatMap" method, flattens first level items
 *
 * @param {Array|Object|String|NodeList|HTMLCollection} src - source
 * @param {Function|Array|Object} [transform] - transformer function
 * @returns {Array|Object|String}
 */


function flatMap(src, transform) {
  let res;
  if (T.isStr(src)) res = "";else if (T.isArr(src)) res = [];else res = {};
  forEach(src, function (a, i) {
    let f;

    if (!!transform) {
      f = transform(a, i, src);
    } else {
      if (!T.isArr(res) && T.isObj(res)) {
        f = {};
        f[i] = a;
      } else {
        f = a;
      }
    }

    res = concat(res, f);
  });
  return res;
}
/**
 * A more versatile alternative to native "reduce" method
 *
 * @param {any} src - source
 * @param {Function|Array|Object} func - reducer function
 * @param {any} [acc] - accumulator
 * @returns {any}
 */


function reduce(src, func, acc = src) {
  if (T.isUnd(func)) {
    func = (rs, v) => rs + v;
  }

  forEach(src, (v, k, src) => {
    acc = func(acc, v, k, src);
  });
  return acc;
}
/**
 * {@link reduce} in reverse
 * @see reduce
 * @param {any} src - source
 * @param {Function|Array|Object} func - reducer function
 * @param {any} [acc] - accumulator
 * @returns {any}
 */


function reduceRight(src, func, acc = src) {
  forEachRight(src, (v, k, src) => {
    acc = func(acc, v, k, src);
  });
}
/**
 * Extract single key-value pairs from object
 *
 * @param object
 * @return {Object[]}
 */


function keyValuePairs(object) {
  let entries = [];
  forEach(object, (v, k) => {
    entries.push(T.dict(k, v));
  });
  return entries;
}
/**
 * Like Object.entries extracts key-value pairs as [[key1,value1],[key2,value2],...]
 *
 * @param {Object} object
 * @return {Array[]}
 */


function entries(object) {
  let entries = [];
  forEach(object, (v, k) => {
    entries.push([k, v]);
  });
  return entries;
}
/**
 * Translate(rename) object fields using dict parameter, omitting undefined keys
 * @param {Object} source
 * @param {Object|Array} dict
 * @return {Array|Object|String}
 */


function translateObject(source, dict) {
  if (T.isArr(dict)) {
    filter(source, dict);
  }

  const keys = Object.keys(dict);
  let res = filter(source, keys);

  for (let key of keys) {
    res[dict[key]] = res[key];
    delete res[key];
  }

  return res;
}
/**
 * Recursive deep merge {@param target} with {@param source}
 *
 * @param {Object|Array} target
 * @param {Object|Array} source
 * @param {Array} excludeKeys - keys to be skipped while merging
 * @param maxDepth - maximum recursive depth
 * @param allowUnsafeProps - allow unsafe properties like __proto__
 * @return {Object|Array}
 */


function deepMerge(target, source, {
  excludeKeys = [],
  maxDepth = 999,
  allowUnsafeProps = false
} = {
  excludeKeys: [],
  maxDepth: 999,
  allowUnsafeProps: false
}, depth = 0) {
  if (depth >= maxDepth) return target;
  forEach(source, (v, k) => {
    if (excludeKeys && contains(excludeKeys, k)) return;
    if (allowUnsafeProps && contains(UNSAFE_PROPS, k)) return;

    if (T.isObj(source[k])) {
      target[k] = deepMerge(emptyOf(source[k]), source[k], {
        excludeKeys,
        maxDepth,
        depth: depth + 1
      });
    } else target[k] = v;
  });
  return target;
}
/**
 * Recursive deep clone {@param source}
 * @see deepMerge
 *
 * @param {Object|Array} source
 * @param {Array} excludeKeys - keys to be skipped while merging
 * @param {Number} [maxDepth] - maximum recursive depth
 * @param {boolean} [allowUnsafeProps] - allow unsafe properties like __proto__
 * @return {Object|Array}
 */


function deepClone(source, {
  excludeKeys = [],
  maxDepth = 999,
  allowUnsafeProps = false
} = {
  excludeKeys: [],
  maxDepth: 999,
  allowUnsafeProps: false
}) {
  return deepMerge(emptyOf(source), source, {
    excludeKeys,
    maxDepth,
    allowUnsafeProps
  });
}

function _keyGen(key, fnName) {
  let keyGen = key;

  if (T.isStr(key)) {
    keyGen = item => item[key];
  } else if (T.isArr(key)) {
    keyGen = item => reduce(item, (res, v, k) => {
      if (contains(key, k)) {
        return res + v;
      }
    }, "");
  } else if (!T.isFun(key)) {
    throw Error(`${fnName} key only accepts: String, [String,...], Function`);
  }

  return keyGen;
}
/**
 * Join arrays of objects based on a generated or static key
 *
 * @param {Function|String} key
 * @param {Object[]} lists
 * @return {Object}
 */


function join(key, ...lists) {
  if (lists.length === 0) return [];
  if (!all(lists, T.isArr)) throw Error("Join only accepts arrays of data!");

  let keyGen = _keyGen(key, "Join");

  const joined = {};
  forEach(lists, list => {
    forEach(list, item => {
      const joinKey = keyGen(item);
      const presentValue = joined[joinKey];

      if (!presentValue) {
        joined[joinKey] = item;
      } else {
        joined[joinKey] = concat(presentValue, item);
      }
    });
  });
  return joined;
}
/**
 * Group arrays based on generated or static key(s)
 *
 * @param {Function|String} key
 * @param {Object[]} lists
 * @return {Object}
 */


function groupBy(key, ...lists) {
  if (lists.length === 0) return {};
  if (!all(lists, T.isArr)) throw Error("GroupBy only accepts arrays of data!");

  let keyGen = _keyGen(key, "GroupBy");

  const group = {};
  forEach(lists, list => {
    forEach(list, item => {
      const joinKey = keyGen(item);
      const presentValue = group[joinKey];

      if (!presentValue) {
        group[joinKey] = [item];
      } else {
        group[joinKey] = concat(presentValue, item);
      }
    });
  });
  return group;
} // noinspection JSUnusedGlobalSymbols


module.exports = {
  ANY,
  ALL,
  BREAK,
  item,
  contains,
  add,
  remove,
  toggle,
  concat,
  emptyOf,
  objMatchOne,
  objMatchAll,
  deepMerge,
  deepClone,
  forN,
  forEachRange,
  forEach,
  forEachRight,
  firstIndex,
  first,
  startsWith,
  lastIndex,
  last,
  endsWith,
  reverse,
  any,
  all,
  filter,
  filterRight,
  reduce,
  reduceRight,
  map,
  flatMap,
  keyValuePairs,
  entries,
  maxIndex,
  max,
  minIndex,
  min,
  translateObject,
  omit,
  join,
  groupBy,
  objectValues
};
},{"./types":"1EuZy"}],"1EuZy":[function(require,module,exports) {
/**
 * @module core/types
 * @memberOf core
 */

/**
 * If is class or function return class/function name else returns typeof
 * @param x
 * @return {"undefined"|"object"|"boolean"|"number"|"string"|"function"|"symbol"|"bigint"|*}
 */
function typeName(x) {
  if (x.hasOwnProperty('constructor')) {
    return x.constructor.name;
  }

  return typeof x;
}
/** Is undefined
 * @param x
 * @returns {boolean}
 */


function isUnd(x) {
  return x !== null && x === undefined;
}
/** Is null
 * @param x
 * @return {boolean}
 */


function isNull(x) {
  return x === null;
}
/** Is value !null && !undefined
 * @param x
 * @return {boolean|boolean}
 */


function isVal(x) {
  return !isUnd(x) && !isNull(x);
}
/** Is number
 * @param x
 * @return {boolean}
 */


function isNum(x) {
  return typeof x === "number";
}
/** Is string|String
 * @param x
 * @return {boolean}
 */


function isStr(x) {
  return typeof x === "string" || x instanceof String;
}
/** Is function
 * @param x
 * @return {boolean}
 */


function isFun(x) {
  return typeof x === "function";
}
/** Is object
 * @param x
 * @return {boolean|boolean}
 */


function isObj(x) {
  return x !== null && typeof x === "object";
}
/** Is Array
 * @param x
 * @return {boolean}
 */


function isArr(x) {
  return x instanceof Array;
}
/** Is primitive isVal && !isObj && !isFun
 * @param x
 * @return {boolean}
 */


function isPrim(x) {
  return isVal(x) && !isObj(x) && !isFun(x);
}
/** Is List (has length property and item() function)
 * @param x
 * @return {boolean|boolean}
 */


function isList(x) {
  return isVal(x.length) && isFun(x.item);
}
/** Is MutableList (has length property, item() and add() functions)
 * @param x
 * @return {boolean}
 */


function isMutableList(x) {
  return isVal(x.length) && isFun(x.item) && isFun(x.add);
}
/** Is Set type
 * @param x
 * @return {boolean}
 */


function isSet(x) {
  return x instanceof Set;
}
/** Is Map type
 * @param x
 * @return {boolean}
 */


function isMap(x) {
  return x instanceof Map;
}
/** Is Error type
 * @param x
 * @return {boolean}
 */


function isError(x) {
  return x instanceof Error;
}
/** Is Element/Node
 * @param x
 * @return {boolean}
 */


function isEl(x) {
  return x instanceof Element || x instanceof HTMLElement || x instanceof Node;
}
/** Is NodeList || HTMLCollection
 * @param x
 * @return {boolean}
 */


function isEls(x) {
  return x instanceof HTMLCollection || x instanceof NodeList;
}
/**
 * Object has field
 * @param {Object} obj - source object
 * @param {String} field - field/property name
 * @param {Function} [pred] - optional predicate function to check field
 * @return {boolean}
 */


function hasField(obj, field, pred) {
  if (!isVal(obj)) return false;

  if (isFun(pred)) {
    return pred(obj[field]);
  }

  return obj.hasOwnProperty(field);
}
/** Is Empty Array/List/Object/String
 * @param x
 * @return {boolean}
 */


function isEmpty(x) {
  if (hasField(x, 'length')) return x.length <= 0;
  if (isFun(x)) return false;
  if (isObj(x)) return Object.keys(x).length <= 0;
  return true;
}
/**
 * Custom Enum implementation
 *
 * @param src {Object | String[]}
 * @return {Object}
 * @constructor
 */


function Enum(src) {
  let c = 0;
  let MAP = {};

  for (let i of Object.keys(src)) {
    MAP[MAP[c] = i] = c++;
  }

  return MAP;
}
/**
 * Deserialize sequence of key values (key, value, ...) into an object
 *
 * @param {any} args - key{String}, value{*} sequence
 * @return {Object}
 */


function dict(...args) {
  let o = {};

  for (let i = 0; i < args.length; i++) {
    if (i % 2 !== 0) continue;
    o[args[i]] = args[i + 1];
  }

  return o;
}

module.exports = {
  typeName,
  isUnd,
  isNull,
  isVal,
  isNum,
  isStr,
  isFun,
  isObj,
  isArr,
  isPrim,
  isList,
  isMutableList,
  isSet,
  isMap,
  isError,
  isEl,
  isEls,
  hasField,
  isEmpty,
  Enum,
  dict
};
},{}],"2Pcrs":[function(require,module,exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.randomId = randomId;
exports.isComponent = isComponent;
exports.isStatic = isStatic;
exports.isEventPropKey = isEventPropKey;
exports.normalizeEventName = normalizeEventName;
exports.compileProps = compileProps;
exports.compileStyles = compileStyles;
exports.sameClass = sameClass;
exports.instanceOf = instanceOf;
exports.isChildOf = isChildOf;
exports.renameFunc = renameFunc;
exports.copyPrototype = copyPrototype;
exports.prepareChildren = prepareChildren;
exports.sameProps = sameProps;
exports.swapChildNodes = swapChildNodes;
exports.substituteTextNodes = substituteTextNodes;
exports.default = void 0;

var _vnode = require("./vnode");

var _collections = require("../core/collections");

var _types = require("../core/types");

var _jss = _interopRequireDefault(require("./jss"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function randomId() {
  return Date.now().toString(24).slice(2) + Math.random().toString(24).slice(6);
}

function isComponent(node) {
  return (0, _types.isFun)(node.render);
}

function isStatic(node) {
  if (!isComponent(node)) {
    return (0, _collections.all)(node.nodes, n => isStatic(n));
  } else return false;
}

function isEventPropKey(key) {
  return /on[A-Z]+/.test(key);
}

function normalizeEventName(eventName) {
  return eventName.slice(2).toLowerCase();
}

function compileProps(props) {
  const cats = {
    events: {},
    attrs: {}
  };
  (0, _collections.forEach)(props, (v, k) => {
    if (isEventPropKey(k)) cats.events[normalizeEventName(k)] = v;else cats.attrs[k] = v;
  });
  return cats;
}

function compileStyles(styles, joinWith) {
  if (!(0, _types.isVal)(styles)) return '';else if ((0, _types.isStr)(styles)) return styles;else if ((0, _types.isArr)(styles)) return styles.join(joinWith);
  return _jss.default.generateCss(styles, joinWith);
}

function sameClass(t1, t2) {
  let name1 = t1.constructor.name;
  let name2 = t2.name;

  if ((0, _types.hasField)(t1, 'prototype')) {
    name1 = t1.prototype.constructor.name;
  }

  if ((0, _types.hasField)(t2, 'prototype')) {
    name2 = t2.prototype.constructor.name;
  }

  console.log(name1, name2);
  return name1 === name2;
}

function instanceOf(inst, cls) {
  const instProto = Object.getPrototypeOf(inst);
  const classProto = cls.prototype; // console.log(instProto, classProto)

  return instProto.constructor.name === classProto.constructor.name;
}

function isChildOf(child, parent) {
  const parentProto = parent.prototype || Object.getPrototypeOf(parent);
  const parentName = parentProto.constructor.name;
  let childProto = child.prototype || Object.getPrototypeOf(child);

  while (childProto) {
    if (childProto.name === parentName || childProto.constructor.name === parentName) return true;
    childProto = Object.getPrototypeOf(childProto);
  }

  return false;
}

function renameFunc(fn, name) {
  return new Function("fn", `return function ${name}() {return fn.apply(this, arguments)}`)(fn);
}

function copyPrototype(thing) {
  let props = Object.getOwnPropertyDescriptors(thing);
  let copied = Object.create({});
  Object.defineProperties(copied, props);
  console.log(copied);
  return copied;
}

function prepareChildren(children, after, rootView) {
  const flat = [];
  const len = children.length;

  for (let i = 0; i < len; i++) {
    let child = children[i];
    if (child.$tag === 'FRAGMENT') child = child.nodes;

    if (child.constructor.name === 'Array') {
      const clen = child.length;

      for (let j = 0; j < clen; j++) {
        let ch = child[j];

        if ((0, _types.isStr)(ch) || (0, _types.isNum)(ch)) {
          ch = _vnode.VNode.createText(ch.toString());
        }

        if (after) ch = after(ch); // ch.rootView = rootView

        flat.push(ch);
      }
    } else {
      if ((0, _types.isStr)(child) || (0, _types.isNum)(child)) {
        child = _vnode.VNode.createText(child.toString());
      }

      if (after) child = after(child); // child.rootView = rootView

      flat.push(child);
    }
  }

  return flat;
}

function sameProps(currentProps = {}, newProps = {}) {
  const curKeys = Object.keys(currentProps);
  const newKeys = Object.keys(newProps);
  if (curKeys.length !== newKeys.length) return false;

  for (let curKey of curKeys) {
    if (newProps[curKey] !== currentProps[curKey]) return false;
  }

  return true;
}

function swapChildNodes(parent, nodes, newIndex, currentIndex) {
  parent.insertBefore(nodes[newIndex], nodes[currentIndex]);
}

function substituteTextNodes(children) {
  return children.map(ch => {
    if ((0, _types.isStr)(ch) || (0, _types.isNum)(ch)) {
      return _vnode.VNode.createText(ch.toString());
    } else return ch;
  });
}

var _default = {
  randomId,
  compileProps,
  compileStyles,
  isComponent,
  isStatic,
  isEventPropKey,
  normalizeEventName,
  sameClass,
  isChildOf,
  instanceOf,
  renameFunc,
  copyPrototype,
  prepareChildren,
  swapChildNodes,
  substituteTextNodes,
  sameProps
};
exports.default = _default;
},{"./vnode":"rEOtM","../core/collections":"1hgia","../core/types":"1EuZy","./jss":"3HZBU"}],"3HZBU":[function(require,module,exports) {
const {
  kebab
} = require("../core/cases");

const {
  forEach
} = require("../core/collections");

function generateStyles(jss) {
  let styles = [];
  forEach(jss, (val, prop) => {
    styles.push(`${kebab(prop)}: ${val};`);
  });
  return styles;
}

function generateCss(jss, joinWith = '\n') {
  return generateStyles(jss).sort((a, b) => a[0].localeCompare(b[0])).join(joinWith);
}

module.exports = {
  generateStyles,
  generateCss
};
},{"../core/cases":"4MHLs","../core/collections":"1hgia"}],"4MHLs":[function(require,module,exports) {
/**
 * @module
 * @memberOf core
 */

/**
 * @static
 * @param name
 * @returns {string}
 */
function kebab(name) {
  let kb = "";
  let pres = false;

  for (let i = 0; i < name.length; i++) {
    let c = name.charAt(i);

    if (c === '_') {
      kb += '-';
      pres = true;
      continue;
    }

    if (c >= 'A' && c <= 'Z') {
      if (i > 0 && !pres) {
        kb += '-';
      }
    }

    kb += c.toLowerCase();
    pres = false;
  }

  return kb;
}
/**
 * @static
 * @param name
 * @returns {string}
 */


function snake(name) {
  let snk = "";
  let pres = false;

  for (let i = 0; i < name.length; i++) {
    let c = name.charAt(i);

    if (c === '-') {
      snk += '_';
      pres = true;
      continue;
    }

    if (c >= 'A' && c <= 'Z') {
      if (i > 0 && !pres) {
        snk += '_';
      }
    }

    snk += c.toLowerCase();
    pres = false;
  }

  return snk;
}
/**
 * @static
 * @param name
 * @returns {string}
 */


function camel(name) {
  let cml = "";
  let pres = false;

  for (let i = 0; i < name.length; i++) {
    let c = name.charAt(i);

    if (c === '-' || c === '_') {
      pres = true;
    } else if (pres === true) {
      cml += c.toUpperCase();
      pres = false;
    } else {
      if (i === 0) {
        cml += c.toLowerCase();
      } else {
        cml += c;
      }
    }
  }

  return cml;
}
/**
 * @static
 * @param name
 * @returns {string}
 */


function pascal(name) {
  let psc = "";
  let pres = false;

  for (let i = 0; i < name.length; i++) {
    let c = name.charAt(i);

    if (c === '-' || c === '_') {
      pres = true;
    } else if (pres === true) {
      psc += c.toUpperCase();
      pres = false;
    } else {
      if (i === 0) {
        psc += c.toUpperCase();
      } else {
        psc += c;
      }
    }
  }

  return psc;
}

module.exports = {
  kebab,
  camel,
  pascal,
  snake
};
},{}],"7rP3i":[function(require,module,exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.View = void 0;

var _collections = require("../core/collections");

var _functions = require("../core/functions");

var _types = require("../core/types");

var _util = require("./util");

var _nodetype = _interopRequireDefault(require("./nodetype"));

var _patch = require("./patch");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

// import {th} from "./hscript-esm";

/**
 * @property {Object} state
 * @property {Boolean} $isDirty
 * @property {Boolean} $isFrag
 * @property {Function} [onCreate]
 * @property {Function} [onUpdate]
 * @property {Function} [onDestroy]
 * @property {Function} [onMount]
 */
class View {
  constructor(opt = {}, construct = opt) {
    _defineProperty(this, "shouldUpdate", (props = {}) => {
      // return this.$isDirty || JSON.stringify(this.props) !== JSON.stringify(props)
      return this.$isDirty || !(0, _util.sameProps)(this.props, props);
    });

    this.$type = _nodetype.default.VIEW;
    this.$name = this.constructor.name;
    this.$isView = true;
    this.$node = undefined;
    this.$isDirty = true;
    this.$constructor = construct;
    let cons = Object.getOwnPropertyNames(this.$constructor);

    for (let i = 0; i < cons.length; i++) {
      const prop = cons[i];

      if (this.$constructor[prop] instanceof Function) {
        this[prop] = this.$constructor[prop];
      } else {
        this[prop] = (0, _collections.deepClone)(this.$constructor[prop]);
      }
    }

    Object.defineProperty(this, '$update', {
      value: (0, _functions.debounce)(() => {
        this.$isDirty = true;

        if (window.requestAnimationFrame) {
          requestAnimationFrame(() => {
            (0, _patch.updateView)(this);
          });
        } else if (window.webkitRequestAnimationFrame) {
          webkitRequestAnimationFrame(() => {
            (0, _patch.updateView)(this);
          });
        } else (0, _patch.updateView)(this);
      }, 20),
      enumerable: false,
      configurable: false,
      writable: false
    });
  }

  render() {
    return "";
  }

  static create(name, opt) {
    let c = new View(opt);
    if (!opt.render) console.warn("render method is not defined");
    c.$name = name;
    return c;
  }

  createInstance(props, children) {
    const construct = this.$constructor;
    const name = this.$name;
    let inst = new View(construct, construct);
    inst.$name = name;
    inst.$instanceId = (0, _util.randomId)();
    inst.$isDirty = true;
    return inst.updateInstance(props, children);
  }

  updateInstance(props, children) {
    if (!this.props) this.props = {};

    if (props) {
      (0, _collections.concat)(this.props, props, true);
    }

    if (children) children = (0, _util.prepareChildren)(children);
    this.$children = children;
    this.$instanceId = (0, _util.randomId)();
    this.$isDirty = true;
    return this;
  }

  setState(fn) {
    let state = fn.call(this, this.state);

    if ((0, _types.isObj)(state)) {
      this.state = state;
    }

    this.$update();
  }

  $remove() {
    if (this.onDestroy) this.onDestroy();

    if (!this.$isFrag) {
      this.$node.target.remove();
    }

    for (const ch of this.$node.nodes) {
      ch.$remove();
    }
  }

  $firstElement() {
    if (this.$node) return this.$node.$firstElement();
  }

  $lastElement() {
    if (this.$node) return this.$node.$lastElement();
  }

} // global.View = View


exports.View = View;
},{"../core/collections":"1hgia","../core/functions":"3UsB2","../core/types":"1EuZy","./util":"2Pcrs","./nodetype":"5oyRM","./patch":"7GedK"}],"3UsB2":[function(require,module,exports) {
/**
 * @module
 * @memberOf core
 */
function bodyOf(func) {
  return func.toString().match(/{[\w\W]*}/)[0];
}
/**
 * Check if function bodies are equal
 * @param {Function} f1
 * @param {Function} f2
 * @return {boolean}
 */


function funcBodyEquals(f1, f2) {
  return bodyOf(f1) === bodyOf(f2);
}
/**
 * Throttle function execution.
 * {@link https://css-tricks.com/debouncing-throttling-explained-examples/}
 *
 * @param {Function} func - function
 * @param {Number} intervalMs
 * @return {Function} - throttled function
 */


function throttle(func, intervalMs) {
  var ___last___ = new Date().getTime();

  function throttled(args) {
    if (new Date().getTime() - ___last___ >= intervalMs) {
      ___last___ = new Date().getTime();
      func.call(this, args);
    }
  }

  return throttled;
}
/**
 * Debounce function execution.
 * {@link https://css-tricks.com/debouncing-throttling-explained-examples/}
 *
 * @param {Function} func - function
 * @param {Number} afterMs - milliseconds after last call
 * @return {Function} - debounced function
 */


function debounce(func, afterMs) {
  var ___timeout___ = null;

  function debounced(...args) {
    clearTimeout(___timeout___);
    ___timeout___ = setTimeout(function (_this) {
      return func.apply(_this, args);
    }, afterMs, this);
  }

  debounced.flush = function (...args) {
    clearTimeout(___timeout___);
    return func.apply(this, args);
  };

  return debounced;
}
/**
 * Bind args to function and return a no-arg function
 * @param {Function} func - source function
 * @param {any[]} args - array of arguments to bind
 * @return {Function}
 */


function bindArgs(func, args) {
  return function () {
    return func.apply(this, args);
  };
}

function once(func) {
  var called = false;
  return function () {
    if (!called) {
      called = true;
      return func.apply(this, arguments);
    }
  };
}

module.exports = {
  funcBodyEquals,
  throttle,
  debounce,
  bindArgs,
  once
};
},{}],"5oyRM":[function(require,module,exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _default = {
  TEXT: 0,
  NODE: 1,
  VIEW: 2
};
exports.default = _default;
},{}],"7GedK":[function(require,module,exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.isDirty = isDirty;
exports.updateViewNodes = updateViewNodes;
exports.updateView = updateView;
exports.destroy = destroy;

var _updateAttrs = require("./update-attrs");

var _renderDom = require("./render-dom");

var _view = require("./view");

var _core = require("../core");

var _vnode = require("./vnode");

var _util = require("./util");

var _render = require("./render");

/////////////////////////////////////////////
///////// Performance Critical Code /////////
/////////////////////////////////////////////
function isDirty(node, props) {
  // return true
  if (node.$isView) {
    return node.shouldUpdate && node.shouldUpdate(props);
  } else return true;
}

function updateSingleNode(currentNode, newNode) {
  newNode.target = currentNode.target;
  (0, _updateAttrs.updateAttributes)(newNode.attrs, currentNode.attrs, currentNode.target);
}
/**
 *
 * @param curNode
 * @param removeTarget
 * @returns {Node|HTMLElement}
 */


function extractFirstElement(curNode, removeTarget = true) {
  if (curNode.isText) return curNode.target;
  if (!curNode.$isFrag) return curNode.$isView ? curNode.$node.target : curNode.target;
  let curRealNode = curNode.$isView ? curNode.$node.nodes[0] : curNode.nodes[0];

  while (!curRealNode.target) {
    curRealNode = curRealNode.$isView ? curRealNode.$node.nodes : curRealNode.nodes[0];
  }

  let target = curRealNode.target; // console.log('target cleard from', curRealNode.target)

  if (removeTarget) curRealNode.target = undefined;
  return target;
}

function updateViewNodes(currentNodes, newNodes, view, parentElement) {
  const newLen = newNodes.length;
  const curLen = currentNodes.length;
  const more = curLen < newLen;
  let newNodeList = [];
  let newIndex = 0;

  for (; newIndex < newLen; newIndex++) {
    if (more && newIndex === curLen) {
      break;
    }

    const newNode = newNodes[newIndex];
    const curNode = currentNodes[newIndex];
    const curFrag = curNode.$isFrag;
    const newFrag = newNode.$isFrag; // LEFT : VIEW

    if (newNode.$isView) {
      // BOTH VIEW
      if (curNode.$isView
      /* && newNode.isView*/
      ) {
          if (newNode.$name === curNode.$name) {
            // console.log('both view')
            if (!isDirty(curNode, newNode.props)) {
              newNodes[newIndex] = curNode;
              continue;
            } // pass props
            // concat(curNode.props, newNode.props, true)
            // update current with new props


            updateView(curNode, newNode.props);
            newNodes[newIndex] = curNode;
          } else {
            // console.log('both view names not match')
            // different components
            (0, _renderDom.renderDom)((0, _render.render)(newNode));
            curNode.target.replaceWith(newNode.target);
            curNode.target = undefined; // destroy([curNode])

            curNode.$remove();
          }
        } else {
        let pivotElement = curFrag ? extractFirstElement(curNode) : curNode.target;

        if (newFrag) {
          let newElement = (0, _renderDom.renderDom)((0, _render.render)(newNode), curFrag ? document.createElement('div') : pivotElement);
          pivotElement.replaceWith(newElement);
        } else {
          let rendered = (0, _render.render)(newNode, view.rootView);
          pivotElement.replaceWith((0, _renderDom.renderDom)(rendered.$node, undefined, rendered));
        } // destroy([curNode])


        curNode.$remove();
      }

      continue;
    } // LEFT : VNODE


    if (newNode.$isNode) {
      // BOTH VNODE
      if (curNode.$isNode
      /* && newNode.isNode*/
      ) {
          if (curNode.$tag === newNode.$tag) {
            // console.log('tags equal', newNode.$tag)
            if (!curFrag && !newFrag) {
              // BOTH NON-FRAGMENT
              // console.log('update single node', curNode.$tag)
              updateSingleNode(curNode, newNode);
            }

            try {
              // console.log('update children', curNode, newNode)
              // PATCH CHILDREN
              updateViewNodes(curNode.nodes, newNode.nodes, view, parentElement);
            } catch (e) {
              // console.log(newNode, curNode)
              console.log(e);
            }
          } else {
            let rendered = (0, _renderDom.renderDom)(newNode);
            curNode.target.replaceWith(rendered);
          }
        } else {
        // console.log('right not match node', newNode, curNode)
        // let pivotElement = curFrag ? extractFirstElement(curNode) : curNode.target;
        let pivotElement = extractFirstElement(curNode); // console.log('pivot', pivotElement)

        try {
          if (newFrag) {
            let newElement = (0, _renderDom.renderDom)((0, _render.render)(newNode), document.createElement('div'));
            pivotElement.replaceWith(newElement);
          } else {
            pivotElement.replaceWith((0, _renderDom.renderDom)((0, _render.render)(newNode)));
          } // console.log('after', newNode, curNode)


          curNode.$remove();
        } catch (e) {
          console.error(e); // console.log(curNode, pivotElement)
        } // RIGHT NOT VNODE

      }

      continue;
    } // LEFT TEXT


    if (newNode.text !== curNode.text) {
      // console.log('pivot text',pivotElement)
      // console.log(curNode,newNode)
      if (curNode.isText) {
        newNode.target = curNode.target;
        curNode.target.textContent = newNode.text;
      } else {
        let pivotElement = extractFirstElement(curNode);
        newNodes[newIndex] = (0, _render.render)(newNode, undefined, view);
        pivotElement.replaceWith((0, _renderDom.renderDom)(newNodes[newIndex]));
      }
    } else {
      newNode.target = curNode.target;
    }
  }

  if (more) {
    let lastElement = newNodes[newIndex - 1].$lastElement();
    let temp = document.createElement('div');
    temp.style.display = 'none';

    if (lastElement.nextSibling) {
      lastElement.parentElement.insertBefore(temp, lastElement.nextSibling); // lastElement = temp
    } else {
      lastElement.parentElement.append(temp);
    }

    for (let i = newIndex; i < newLen; i++) {
      let el = (0, _renderDom.renderDom)(newNodes[i], undefined, view);
      newNodeList.push(el);
      newNodes[i].target = el;
    }

    temp.replaceWith(...newNodeList); // setTimeout(()=>{}, 2000)
  } else if (newLen < curLen) {
    // let dels = currentNodes.slice(newLen, curLen - 1)
    for (let i = newLen; i < curLen; i++) {
      currentNodes[i].$remove();
    }
  } // console.log('New Nodes', newNodes)

}

function updateView(view, newProps) {
  // to render
  if (!isDirty(view, newProps)) return view;

  if (newProps) {
    (0, _core.concat)(view.props, newProps, true);
  } // is dirty -> call render


  let newNode = view.render.call(view, view.props);
  let newNodes = newNode.$isFrag ? newNode.nodes : [newNode];
  view.$isFrag = newNode.$isFrag;
  let currentNodes = view.$isFrag ? view.$node.nodes : [view.$node];

  if (newNode.$isView) {
    updateView(newNode);
  }

  updateViewNodes(currentNodes, newNodes, view);
  view.$node = newNode;
  view.$isDirty = false;
  if (view.onUpdate) view.onUpdate.call(view);
  return view;
}

function destroy(nodes) {
  nodes.forEach(node => {
    if (node.$isView && node.onDestroy) {
      if (node.$isFrag) {
        destroy(node.$node.nodes);
      } else destroy([node.$node]);

      node.onDestroy();
    }

    if (node.target) node.target.remove();

    if (node.nodes) {
      destroy(node.nodes);
    }
  });
}
},{"./update-attrs":"6Y4Dj","./render-dom":"3RwzU","./view":"7rP3i","../core":"1A9AF","./vnode":"rEOtM","./util":"2Pcrs","./render":"2RJeN"}],"6Y4Dj":[function(require,module,exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.updateAttributes = updateAttributes;

var _util = require("./util");

function updateAttributes(newAttrs, currentAttrs, element) {
  const newKeys = Object.keys(newAttrs);
  const currentKeys = Object.keys(currentAttrs);
  const keys = Object.keys(newAttrs); // const len = keys.length

  for (let key of keys) {
    const newVal = newAttrs[key];

    if (currentKeys.indexOf(key) < 0) {
      element.setAttribute(key, newVal);
    } else {
      if (key === 'style') {
        const newStyle = (0, _util.compileStyles)(newVal, ' ');
        const currentStyle = (0, _util.compileStyles)(newVal, ' ');

        if (newStyle !== currentStyle) {
          element.setAttribute('style', newStyle);
        }
      } else {
        if (newVal !== currentAttrs[key]) {
          element.setAttribute(key, newVal);
        }
      }
    }
  }

  for (let key of currentKeys) {
    if (newKeys.indexOf(key) < 0) {
      element.removeAttribute(key);
    }
  }
}
},{"./util":"2Pcrs"}],"3RwzU":[function(require,module,exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.renderDom = renderDom;

var _collections = require("../core/collections");

var _util = require("./util");

var _event = require("../dom/event");

var _render = require("./render");

/////////////////////////////////////////////
///////// Performance Critical Code /////////
/////////////////////////////////////////////
function setElementProps(element, node, view) {
  if (node.attrs) {
    (0, _collections.forEach)(node.attrs, (val, key) => {
      if (key === 'style') {
        val = (0, _util.compileStyles)(val, ' ');
      }

      element.setAttribute(key, val);
    });
  }

  if (node.events) {
    (0, _collections.forEach)(node.events, (v, k) => {
      if (view) v = v.bind(view);
      (0, _event.setEvent)(element, k, v);
    });
  }
}
/**
 * create Dom element(s) and set VNode.target
 * fragment must have parent div
 *
 * @param node
 * @param element
 * @param view
 * @returns {HTMLElement|Element|Node}
 */


function renderDom(node, element, view) {
  let nodeIsView = false;

  if (node.$isView) {
    nodeIsView = true;

    if (!node.$node) {
      node = (0, _render.render)(node, view);
    }

    view = node;
    node = view.$node;
  }

  if (node.$isFrag) {
    if (!element) {
      console.trace('fragment has no parent Element');
      element = document.createElement('div');
    } // node.$root = view


    node.target = element;
    element.__node__ = view; // if (view) view.target = element
    // renderDomChildren(node, element, view)

    if (node.nodes) {
      for (const child of node.nodes) {
        if (child.$isFrag) {
          // fragment child
          renderDom(child, element, node);
        } else {
          element.append(renderDom(child, undefined, view));
        }
      }
    } // //


    if (nodeIsView && view.onMount) {
      view.onMount.call(view);
      view.target = element; // element.__node__ = view
    }

    return element;
  }

  if (node.isText) {
    element = document.createTextNode(node.text);
    node.target = element;
    return element;
  }

  if (!element) {
    element = document.createElement(node.$tag);
  }

  node.target = element; // if (view) view.target = element

  element.__node__ = nodeIsView ? view : node;
  if (!node.$isFrag) setElementProps(element, node, view);else console.error('render-dom: something broke!', node); // renderDomChildren(node, element, view)

  if (node.nodes) {
    for (const child of node.nodes) {
      if (child.$isFrag) {
        // fragment child
        renderDom(child, element, view); // child.$root = node
      } else {
        element.append(renderDom(child, undefined, view)); // child.$root = node
      }
    }
  }

  if (view) {
    view.target = element;
    view.$isDirty = false;
  }

  return element;
}

function renderDomChildren(node, element, view) {
  if (node.nodes) {
    for (const child of node.nodes) {
      if (child.$isFrag) {
        // fragment child
        renderDom(child, element, view);
      } else {
        element.append(renderDom(child, undefined, view));
      }
    }
  }
}
},{"../core/collections":"1hgia","./util":"2Pcrs","../dom/event":"4PVUA","./render":"2RJeN"}],"4PVUA":[function(require,module,exports) {
/**
 * @module DOM
 * @memberOf dom
 */
const scope = require("../core/scope");

const {
  isArr,
  hasField,
  isEmpty
} = require("../core/types");

const {
  contains,
  forEach,
  filter
} = require("../core/collections");

const {
  error
} = require("../core/logging");

const {
  funcBodyEquals
} = require("../core/functions");
/**
 * Set listener for event type(s) on element, removes identical event listeners to avoid duplication
 *
 * @param {HTMLElement|Element|Node} target - target element
 * @param {String|Array} event - event type(s)
 * @param {Function} listener
 * @param {AddEventListenerOptions?} [options]
 */


function setEvent(target, event, listener, options) {
  if (!scope.isBrowser()) {
    error("Events are browser only!");
    return;
  }

  if (!isArr(event)) {
    if (contains(event, ' ')) {
      event = event.split(' ').Map(it => it.trim());
    } else event = [event];
  }

  target.__EVENTS__ = target.__EVENTS__ || {};
  forEach(event, ev => {
    target.__EVENTS__[ev] = target.__EVENTS__[ev] || [];

    let f = function (e) {
      listener(e, target);
    };

    if (!hasField(options, 'duplicates', a => a)) {
      target.__EVENTS__[ev] = filter(target.__EVENTS__[ev], fl => {
        if (funcBodyEquals(fl.l, listener)) {
          target.removeEventListener(ev, fl.f, fl.o);
          return false;
        } else {
          console.log('notEqual', fl.l.toString(), listener.toString());
        }
      });
    }

    target.__EVENTS__[ev].push({
      f: f,
      l: listener,
      o: options
    });

    target.addEventListener(ev, f, options);
  });
}
/**
 * Clear all event listeners of type from element
 *
 * @param {HTMLElement|Element|Node} target - target element
 * @param {String|Array} event - event type(s)
 */


function clearEvent(target, event) {
  if (!scope.isBrowser()) {
    error("Events are browser only!");
    return;
  }

  if (!isArr(event)) {
    if (contains(event, ' ')) {
      event = event.split(' ').Map(it => it.trim());
    } else event = [event];
  }

  target.__EVENTS__ = target.__EVENTS__ || {};
  if (isEmpty(target.__EVENTS__)) return;
  forEach(event, function (ev) {
    target.__EVENTS__[ev] = target.__EVENTS__[ev] || [];
    if (isEmpty(target.__EVENTS__[ev])) return;
    forEach(target.__EVENTS__[ev], fl => {
      target.removeEventListener(ev, fl.f, fl.o);
      return false;
    });
    target.__EVENTS__[ev] = [];
  });
}
/**
 * Target has event listener for event type
 *
 * @param {HTMLElement|Element|Node} target - target element
 * @param {String} type - event type
 * @return {boolean}
 */


function hasEvent(target, type) {
  return target.__EVENTS__ && target.__EVENTS__[type] && !isEmpty(target.__EVENTS__[type]);
}

module.exports = {
  setEvent,
  clearEvent,
  hasEvent
};
},{"../core/scope":"6xNAN","../core/types":"1EuZy","../core/collections":"1hgia","../core/logging":"3xiP7","../core/functions":"3UsB2"}],"6xNAN":[function(require,module,exports) {
var global = arguments[3];

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

/**
 * Merges an object with global namespace
 * @private
 * @param {Object} obj
 */
function setGlobal(obj) {
  for (let key of Object.keys(obj)) {
    global[key] = obj[key];
  }
}
/**
 * Code generator for prototype modification, used in polyfills
 */


class Extension {
  /** Generated code */

  /**
   * @constructor
   * @param {any[]} types - Array of prototypes
   */
  constructor(types) {
    _defineProperty(this, "types", []);

    _defineProperty(this, "pcode", "\n");

    this.types = types;
  }
  /**
   * Defines a new function for given prototypes
   *
   * @param {Function} namedFunc A named function
   * @return {string}
   */


  define(namedFunc) {
    if (!namedFunc.name) {
      let err = `Function must have a name [Extension.define(f)]\n<<${namedFunc}>>`;
      console.error(err);
      return `\n/**\n *${err}\n */`;
    }

    let code = "\n";

    for (let p of this.types) {
      if (p !== undefined) code += `${p.name || p}.prototype.${namedFunc.name} = `;
    }

    code += namedFunc.toString() + ";\n";
    this.pcode += code;
    return code;
  }

  polyfill(namedFunc) {
    if (!namedFunc.name) {
      let err = `Extension function must have a name:\n<<${namedFunc}>>`;
      console.error(err);
      return `\n/**\n *${err}\n */`;
    }

    let code = "\n";

    for (let p of this.types) {
      code += `if (${p.name || p}.prototype.${namedFunc.name} === undefined) ${p.name || p}.prototype.${namedFunc.name} = ${namedFunc.toString()};\n`;
    }

    this.pcode += code;
  }

}

function isBrowser() {
  return global.window !== undefined && global.document !== undefined && global.navigator !== undefined;
}

if (!isBrowser()) {
  // -------------
  global.HTMLElement = !global.HTMLElement ? function HTMLElement() {} : global.HTMLElement;
  global.Element = !global.Element ? function Element() {} : global.Element;
  global.Node = !global.Node ? function Node() {} : global.Node;
  global.HTMLCollection = !global.HTMLCollection ? function HTMLCollection() {} : global.HTMLCollection;
  global.NodeList = !global.NodeList ? function NodeList() {} : global.NodeList; // -------------
}

module.exports = {
  setGlobal,
  Extension,
  isBrowser
};
},{}],"3xiP7":[function(require,module,exports) {
// const {Enum} = require("./types");

/**
 * @module core/logging
 * @memberOf core
 */

/** @private */
function _logTime() {
  let t = new Date();
  return `${t.getHours()}:${t.getMinutes()}:${t.getSeconds()}:${t.getMilliseconds()}`;
}
/** @private */


function _logTitle(flag) {
  return `[${flag}] [${_logTime()}]`;
}
/** @private */


function _prepareLog(args, lt) {
  args.reverse();
  args.push("display: inline-block; font-weight: bold; color: black", "%c" + lt);
  args.reverse();
}
/**
 * @type {Object}
 */


const LogLevels = {
  TRACE: 0,
  INFO: 1,
  WARN: 2,
  ERROR: 3,
  SILENT: -1
};
/**
 * Log config
 * @type {{LogLevel: *}}
 */

const Config = {
  LogLevel: LogLevels.TRACE
};
/** Set `Config.LogLevel` to TRACE */

function showTrace() {
  Config.LogLevel = LogLevels.TRACE;
}
/** Set `Config.LogLevel` to INFO */


function showInfo() {
  Config.LogLevel = LogLevels.INFO;
}
/** Set `Config.LogLevel` to WARN */


function showWarn() {
  Config.LogLevel = LogLevels.WARN;
}
/** Set `Config.LogLevel` to ERROR */


function showError() {
  Config.LogLevel = LogLevels.ERROR;
}
/** Set `Config.LogLevel` to SILENT */


function silent() {
  Config.LogLevel = LogLevels.SILENT;
}
/** Set Config.LogLevel
 * @param l - LogLevel */


function lvl(l) {
  return Config.LogLevel !== LogLevels.SILENT && Config.LogLevel <= l;
}
/**
 * Log Trace
 * @param {any} args
 */


function trace(...args) {
  if (!lvl(LogLevels.TRACE)) return;
  args.reverse();
  args.push(_logTitle("🔍 TRACE"));
  args.reverse(); // args.push("\n");

  console.trace.apply(this, args);
}
/**
 * Log Info
 * @param {any} args
 */


function info(...args) {
  if (!lvl(LogLevels.INFO)) return;

  _prepareLog(args, _logTitle("🔵 INFO"));

  console.log.apply(this, args);
}
/**
 * Log Warning
 * @param {any} args
 */


function warn(...args) {
  if (!lvl(LogLevels.WARN)) return;

  _prepareLog(args, _logTitle("🚨 WARN"));

  console.warn.apply(this, args);
}
/**
 * Log Error
 * @param {any} args
 */


function error(...args) {
  if (!lvl(LogLevels.ERROR)) return;

  _prepareLog(args, _logTitle("💥 ERROR"));

  console.error.apply(this, args);
}

module.exports = {
  Config,
  LogLevels,
  showTrace,
  showInfo,
  showWarn,
  showError,
  silent,
  trace,
  info,
  warn,
  error
};
},{}],"2RJeN":[function(require,module,exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.render = render;
exports.renderView = renderView;

var _util = require("./util");

var _vnode = require("./vnode");

var _core = require("../core");

/////////////////////////////////////////////
///////// Performance Critical Code /////////
/////////////////////////////////////////////
function render(node, rootView) {
  // if (node.$name === 'App') console.log('APP',rootView, node.$root)
  // rootView = rootView || node.$root
  if (node.$isView && !rootView) {
    rootView = undefined;
  }

  if ((0, _core.isStr)(node)) {
    node = _vnode.VNode.createText(node); // node.$root = rootView

    return node;
  } // rootView = rootView || (node.$isView?node:(node.$root||View.create('anonymous', {render:()=>node})))
  // if (!rootView) {
  //     console.log('no root view',node)
  // }


  if (node.$isView) {
    return renderView(node, rootView);
  }

  if (node instanceof Function) {
    return render(node(), rootView);
  } // node.$root = rootView


  if (node.nodes) {
    node.nodes = node.nodes.map(n => {
      return render(n, node);
    });
  }

  return node;
}

function renderView(view, rootView) {
  // if (view.$name === 'App') console.log('APP',rootView, view.$root)
  try {
    let rendered = view.render.call(view, view.props);
    view.$node = rendered; // view.$root = view === rootView?undefined:rootView
    // view.$root = rootView

    if (view.onCreate) view.onCreate.call(view);
    if (rendered.$isView) return renderView(rendered, rootView); // set component as fragment

    if (rendered.$isFrag) view.$isFrag = true; // rendered.$root = rootView

    if (rendered.nodes) {
      rendered.nodes = (0, _util.prepareChildren)(rendered.nodes, render, rootView);
    }

    return view;
  } catch (e) {
    console.log(view, e);
  }
}
},{"./util":"2Pcrs","./vnode":"rEOtM","../core":"1A9AF"}],"1A9AF":[function(require,module,exports) {
let collections = require('./collections');

let logging = require('./logging');

let types = require('./types');

let cases = require('./cases');

let strings = require('./strings');

let queryable = require('./queryable');

let functions = require('./functions');

module.exports = { ...collections,
  ...logging,
  ...types,
  ...cases,
  ...strings,
  ...queryable,
  ...functions
};
/**
 * @namespace core
 */
},{"./collections":"1hgia","./logging":"3xiP7","./types":"1EuZy","./cases":"4MHLs","./strings":"79MxR","./queryable":"1NgFP","./functions":"3UsB2"}],"79MxR":[function(require,module,exports) {
const decimalRegex = /^[-+]?\d*(\.\d+|\d*)(e[-+]?\d+)?$/;
const hexRegex = /^[-+]?[a-f0-9]+$/;
const octRegex = /^[-+]?[0][0-7]+$/;
const binRegex = /^[-+]?[01]+$/;
const emailRegex = /^[a-z0-9]([a-z0-9._%-+][a-z0-9]|[a-z0-9])*@[a-z0-9]([a-z0-9.-][a-z0-9]|[a-z0-9])*\.[a-z]{2,6}$/i;
/**
 * @module core/strings
 * @memberOf core
 */

/**
 * String is decimal number
 * @param {String} str
 * @return {boolean}
 */

function isDecimal(str) {
  return decimalRegex.test(str);
}
/**
 * String is binary number
 * @param {String} str
 * @return {boolean}
 */


function isBinary(str) {
  return binRegex.test(str);
}
/**
 * String is octal number
 * @param {String} str
 * @return {boolean}
 */


function isOctal(str) {
  return octRegex.test(str);
}
/**
 * String is hexadecimal number
 * @param {String} str
 * @return {boolean}
 */


function isHex(str) {
  return hexRegex.test(str);
}
/**
 * String is valid email address
 * @param {String} str
 * @return {boolean}
 */


function isEmail(str) {
  return emailRegex.test(str);
}
/**
 * String starts with sequence polyfill
 * @param {String} str
 * @param {String} seq
 * @return {boolean}
 */


function startsWith(str, seq) {
  return str.indexOf(seq) === 0;
}
/**
 * String ends with sequence polyfill
 * @param {String} str
 * @param {String} seq
 * @return {boolean}
 */


function endsWith(str, seq) {
  return str.indexOf(seq) === seq.length - 1;
}
/**
 * String contains sequence
 * @param {String} str
 * @param {String} seq
 * @return {boolean}
 */


function contains(str, seq) {
  return str.indexOf(seq) >= 0;
}

module.exports = {
  isDecimal,
  isHex,
  isOctal,
  isBinary,
  isEmail,
  startsWith,
  endsWith,
  contains
};
},{}],"1NgFP":[function(require,module,exports) {
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

const T = require("./types");

class Queryable {
  constructor() {
    _defineProperty(this, "__src__", void 0);

    _defineProperty(this, "keys", void 0);
  }

  get count() {
    return this.keys.length;
  }

  static of(s) {
    let c = new Queryable();
    c.__src__ = s;
    c.keys = Object.keys(s);
    c.len = c.keys.length;
    return c;
  }

  slice(start = 0, end = this.count - 1) {
    this.keys = this.keys.slice(start, end);
  }

  key(i = 0) {
    return this.keys[i];
  }

  value(i = 0) {
    return this.__src__[this.key(i)];
  }

  loop(f, reverse = false) {
    if (reverse) {
      for (let i = this.count - 1; i >= 0; i--) {
        if (f(this.value(i), this.key(i), i) === null) break;
      }
    } else {
      for (let i = 0; i < this.count; i++) {
        if (f(this.value(i), this.key(i), i) === null) break;
      }
    }

    return this;
  }

  values(reverse = false) {
    let vs = [];
    this.loop(function (v, k, i) {
      vs.push(v);
    }, reverse);
    return vs;
  }

  item(i) {
    if (i === undefined) return undefined;
    if (T.isArr(this.__src__)) return this.value(i);
    let o = {};
    o[this.key(i)] = this.value(i);
    return o;
  }

  asObject() {
    // if (T.isArr(this.__src__)) return this.values();
    let o = {};
    this.loop(function (v, k, i) {
      o[k] = v;
    });
    return o;
  }

  asArray(reverse = false) {
    return this.values(reverse);
  }

  filter(f, reverse = false) {
    let nk = [];
    this.loop(function (v, k, i) {
      let r = f(v, k, i);

      if (r === true) {
        nk.push(k);
      } else if (r === null) return null;
    }, reverse);
    this.keys = nk;
    return this;
  }

  map(f, reverse = false) {
    let arr = [];
    this.loop(function (v, k, i) {
      arr.push(f(v, k, i));
    }, reverse);
    return arr;
  }

  any(f) {
    let r = false;
    this.loop(function (v, k, i) {
      r = f(v, k, i);

      if (r === true) {
        return null;
      }
    });
    return r;
  }

  all(f) {
    let r = true;
    this.loop(function (v, k, i) {
      r = f(v, k, i);

      if (r === false) {
        return null;
      }
    });
    return r;
  }

  first(f) {
    if (!f) {
      return this.item(0);
    }

    let it;
    this.loop(function (v, k, i) {
      if (f(v, k, i) === true) {
        it = i;
        return null;
      }
    });
    return this.item(it);
  }

  last(f) {
    if (!f) {
      return this.item(this.count - 1);
    }

    let it;
    this.loop(function (v, k, i) {
      if (f(v, k, i) === true) {
        it = i;
        return null;
      }
    }, true);
    return this.item(it);
  }

}

module.exports = {
  Queryable
};
},{"./types":"1EuZy"}],"6Fg91":[function(require,module,exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _vm = require("../../vm");

var _List = _interopRequireDefault(require("./List"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var _default = _vm.Exir.createView('App', {
  render: () => (0, _vm.jsx)('FRAGMENT', null, (0, _vm.jsx)("h3", null, "Head"), (0, _vm.jsx)(_List.default, null))
});

exports.default = _default;
},{"../../vm":"27HCd","./List":"6KAea"}],"6KAea":[function(require,module,exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _vm = require("../../vm");

var _util = require("../../vm/util");

var _Random = _interopRequireDefault(require("./Random"));

var _logging = require("../../core/logging");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var _default = _vm.Exir.createView('List', {
  state: {
    count: 333,
    x: 1,
    items: []
  },

  render() {
    return (0, _vm.jsx)("div", null, (0, _vm.jsx)("button", {
      id: (0, _util.randomId)(),
      onClick: this.methods.add
    }, "In frag1"), (0, _vm.jsx)("button", {
      id: (0, _util.randomId)(),
      onClick: this.methods.remove
    }, "In frag1"), (0, _vm.jsx)("p", null, "X: ", this.state.x, " : ", this.state.x % 2 === 0 ? (0, _vm.jsx)("b", null, "Even") : (0, _vm.jsx)("u", null, "Odd")), (0, _vm.jsx)("h5", null, "Count ", this.state.items.length), this.state.items.map((it, i) => (0, _vm.jsx)('FRAGMENT', null, (0, _vm.jsx)("span", null, i, it))));
  },

  onCreate() {
    (0, _logging.info)(`${this.$name} created`);
  },

  onUpdate() {
    (0, _logging.info)(`${this.$name} updated ${this.$instanceId}`);
  },

  methods: {
    add() {
      this.setState(state => {
        // for (let i = 0; i < state.count; i++) {
        //     state.items.push(<Random />)
        // }
        let items = [];

        for (let i = 0; i < state.count; i++) {
          items.push((0, _vm.jsx)(_Random.default, {
            a: (0, _util.randomId)()
          }));
        }

        state.items = items;
        state.x += state.count;
      });
      this.$update();
    },

    remove() {
      this.state.x -= this.state.count;
      this.state.items.splice(this.state.x - this.state.count - 1, this.state.count);
      this.$update();
    }

  }
});

exports.default = _default;
},{"../../vm":"27HCd","../../vm/util":"2Pcrs","./Random":"2yBxQ","../../core/logging":"3xiP7"}],"2yBxQ":[function(require,module,exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _vm = require("../../vm");

var _util = require("../../vm/util");

var _logging = _interopRequireDefault(require("../../core/logging"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var _default = _vm.Exir.createView('Random', {
  props: {
    a: 0
  },

  render() {
    return (0, _vm.jsx)("div", null, (0, _vm.jsx)("b", {
      id: this.props.a
    }, (0, _util.randomId)()));
  },

  // shouldUpdate() {
  //     return true
  // },
  onUpdate() {
    _logging.default.warn(`updated ${this.props.a}`);
  },

  onDestroy() {
    _logging.default.warn(`destroyed ${this.props.a}`);
  }

});

exports.default = _default;
},{"../../vm":"27HCd","../../vm/util":"2Pcrs","../../core/logging":"3xiP7"}]},{},["6Sju2","18HlE"], "18HlE", "parcelRequire430d")

//# sourceMappingURL=index.1b904d2c.js.map
