Source: level3/preact-no0.js

import {Component} from 'preact';

// level 1
import AnimatedManager from '../level1/animated-manager';
import AnimatedStateFactory from '../level1/animated-state-factory';
import Bus from '../level1/bus';
import BusAnimatedManager from '../level1/bus-animated-manager';
import Matcher from '../level1/matcher';
import RunLoop from '../level1/runloop';

// level 2
import PreactComponentTransition from '../level2/preact-component-transition';
import PreactCrawler from '../level2/preact-crawler';
import PreactElementTransition from '../level2/preact-element-transition';
import PreactNodeIdGenerator from '../level2/preact-node-id-generator';
import PreactTransition from '../level2/preact-transition';
import TrasitionTree from '../level2/transition-tree';

/**
 * @example
 *   import Boxart from 'boxart-preact';
 *
 *   import animations from './animations';
 *
 *   render(<Boxart animations={animations}><Application /></Boxart>, rootElement);
 */

class Preact extends Component {
  constructor(...args) {
    super(...args);

    const {loop, animations} = this.props;

    const bus = new Bus();

    const animationTypes = {};
    const matcher = new Matcher();
    Object.keys(animations).forEach(key => {
      matcher.add(key, Object.keys(animations[key]));
      animationTypes[key.split(' ')[0]] = animations[key];
    });

    const {create: factory} = new AnimatedStateFactory(animations);

    const manager = new AnimatedManager(factory, loop || RunLoop.main);

    new BusAnimatedManager(manager, bus);

    this.crawler = new PreactCrawler(bus, matcher);

    const tree = new TrasitionTree(new PreactNodeIdGenerator(matcher));
    new PreactTransition(this.crawler, bus, tree, matcher);
    new PreactComponentTransition(bus, tree, matcher);
    new PreactElementTransition(bus, tree, matcher);
  }

  render({children}) {
    return this.crawler.inject(children[0], 'root', true);
  }

  getManager() {
    return this.manager;
  }

  getAnimated(element) {
    return this.manager.getAnimated(element.base || element);
  }
}

export default Preact;

export {
  RunLoop,
};