0?v(k.type,k.props,k.key,null,k.__v):k)){if(k.__=u,k.__b=u.__b+1,null===(_=A[h])||_&&k.key==_.key&&k.type===_.type)A[h]=void 0;else for(p=0;p=i.__.length&&i.__.push({}),i.__[t]}function l(n){return o$2=1,p$1(w$1,n)}function p$1(n,r,o){var i=m$1(t$2++,2);return i.t=n,i.__c||(i.__=[o?o(r):w$1(void 0,r),function(n){var t=i.t(i.__[0],n);i.__[0]!==t&&(i.__=[t,i.__[1]],i.__c.setState({}));}],i.__c=u$1),i.__}function d$1(n,u){var r=m$1(t$2++,7);return k$1(r.__H,u)&&(r.__=n(),r.__H=u,r.__h=n),r.__}function A$1(n,t){return o$2=8,d$1(function(){return n},t)}function F(n){var r=u$1.context[n.__c],o=m$1(t$2++,9);return o.__c=n,r?(null==o.__&&(o.__=!0,r.sub(u$1)),r.props.value):n.__}function x$1(){i$1.forEach(function(t){if(t.__P)try{t.__H.__h.forEach(g$1),t.__H.__h.forEach(j$1),t.__H.__h=[];}catch(u){t.__H.__h=[],n$1.__e(u,t.__v);}}),i$1=[];}n$1.__b=function(n){u$1=null,c$1&&c$1(n);},n$1.__r=function(n){f$1&&f$1(n),t$2=0;var r=(u$1=n.__c).__H;r&&(r.__h.forEach(g$1),r.__h.forEach(j$1),r.__h=[]);},n$1.diffed=function(t){e$2&&e$2(t);var o=t.__c;o&&o.__H&&o.__H.__h.length&&(1!==i$1.push(o)&&r$2===n$1.requestAnimationFrame||((r$2=n$1.requestAnimationFrame)||function(n){var t,u=function(){clearTimeout(r),b$1&&cancelAnimationFrame(t),setTimeout(n);},r=setTimeout(u,100);b$1&&(t=requestAnimationFrame(u));})(x$1)),u$1=void 0;},n$1.__c=function(t,u){u.some(function(t){try{t.__h.forEach(g$1),t.__h=t.__h.filter(function(n){return !n.__||j$1(n)});}catch(r){u.some(function(n){n.__h&&(n.__h=[]);}),u=[],n$1.__e(r,t.__v);}}),a$1&&a$1(t,u);},n$1.unmount=function(t){v$1&&v$1(t);var u=t.__c;if(u&&u.__H)try{u.__H.__.forEach(g$1);}catch(t){n$1.__e(t,u.__v);}};var b$1="function"==typeof requestAnimationFrame;function g$1(n){var t=u$1;"function"==typeof n.__c&&n.__c(),u$1=t;}function j$1(n){var t=u$1;n.__c=n.__(),u$1=t;}function k$1(n,t){return !n||n.length!==t.length||t.some(function(t,u){return t!==n[u]})}function w$1(n,t){return "function"==typeof t?t(n):t}
+
+ var e$3,o$3={};function n$2(r,t,e){if(3===r.nodeType){var o="textContent"in r?r.textContent:r.nodeValue||"";if(!1!==n$2.options.trim){var a=0===t||t===e.length-1;if((!(o=o.match(/^[\s\n]+$/g)&&"all"!==n$2.options.trim?" ":o.replace(/(^[\s\n]+|[\s\n]+$)/g,"all"===n$2.options.trim||a?"":" "))||" "===o)&&e.length>1&&a)return null}return o}if(1!==r.nodeType)return null;var p=String(r.nodeName).toLowerCase();if("script"===p&&!n$2.options.allowScripts)return null;var l,s,u=n$2.h(p,function(r){var t=r&&r.length;if(!t)return null;for(var e={},o=0;o\n"+r+""):(i="xml",a='\n'+r+"");try{o=(new DOMParser).parseFromString(a,p);}catch(r){n=r;}if(o||"html"!==t||((o=e$3||(e$3=function(){if(document.implementation&&document.implementation.createHTMLDocument)return document.implementation.createHTMLDocument("");var r=document.createElement("iframe");return r.style.cssText="position:absolute; left:0; top:-999em; width:1px; height:1px; overflow:hidden;",r.setAttribute("sandbox","allow-forms"),document.body.appendChild(r),r.contentWindow.document}())).open(),o.write(a),o.close()),o){var l=o.getElementsByTagName(i)[0],s=l.firstChild;return r&&!s&&(l.error="Document parse failed."),s&&"parsererror"===String(s.nodeName).toLowerCase()&&(s.removeChild(s.firstChild),s.removeChild(s.lastChild),l.error=s.textContent||s.nodeValue||n||"Unknown error",l.removeChild(s)),l}}(r,t);if(u&&u.error)throw new Error(u.error);var c=u&&u.body||u;l$1.map=i||p$2;var m=c&&function(r,t,e,a){return n$2.visitor=t,n$2.h=e,n$2.options=a||o$3,n$2(r)}(c,l$1,a,s);return l$1.map=null,m&&m.props&&m.props.children||null}(c,u,C,this.map,g);}catch(r){f?f({error:r}):"undefined"!=typeof console&&console.error&&console.error("preact-markup: "+r);}if(!1===i)return s||null;var x=w.hasOwnProperty("className")?"className":"class",b=w[x];return b?b.splice?b.splice(0,0,"markup"):"string"==typeof b?w[x]+=" markup":"object"==typeof b&&(b.markup=!0):w[x]="markup",C("div",w,s||null)},i}(p));
+
+ function C$1(n,t){for(var e in t)n[e]=t[e];return n}function S(n,t){for(var e in n)if("__source"!==e&&!(e in t))return !0;for(var r in t)if("__source"!==r&&n[r]!==t[r])return !0;return !1}function E(n){this.props=n;}(E.prototype=new p).isPureReactComponent=!0,E.prototype.shouldComponentUpdate=function(n,t){return S(this.props,n)||S(this.state,t)};var w$2=n$1.__b;n$1.__b=function(n){n.type&&n.type.__f&&n.ref&&(n.props.ref=n.ref,n.ref=null),w$2&&w$2(n);};var A$2=n$1.__e;function O(){this.__u=0,this.t=null,this.__b=null;}function L$1(n){var t=n.__.__c;return t&&t.__e&&t.__e(n)}function D(){this.u=null,this.o=null;}n$1.__e=function(n,t,e){if(n.then)for(var r,u=t;u=u.__;)if((r=u.__c)&&r.__c)return null==t.__e&&(t.__e=e.__e,t.__k=e.__k),r.__c(n,t);A$2(n,t,e);},(O.prototype=new p).__c=function(n,t){var e=t.__c,r=this;null==r.t&&(r.t=[]),r.t.push(e);var u=L$1(r.__v),o=!1,i=function(){o||(o=!0,e.componentWillUnmount=e.__c,u?u(l):l());};e.__c=e.componentWillUnmount,e.componentWillUnmount=function(){i(),e.__c&&e.__c();};var l=function(){if(!--r.__u){if(r.state.__e){var n=r.state.__e;r.__v.__k[0]=function n(t,e,r){return t&&(t.__v=null,t.__k=t.__k&&t.__k.map(function(t){return n(t,e,r)}),t.__c&&t.__c.__P===e&&(t.__e&&r.insertBefore(t.__e,t.__d),t.__c.__e=!0,t.__c.__P=r)),t}(n,n.__c.__P,n.__c.__O);}var t;for(r.setState({__e:r.__b=null});t=r.t.pop();)t.forceUpdate();}},f=!0===t.__h;r.__u++||f||r.setState({__e:r.__b=r.__v.__k[0]}),n.then(i,i);},O.prototype.componentWillUnmount=function(){this.t=[];},O.prototype.render=function(n,t){if(this.__b){if(this.__v.__k){var e=document.createElement("div"),r=this.__v.__k[0].__c;this.__v.__k[0]=function n(t,e,r){return t&&(t.__c&&t.__c.__H&&(t.__c.__H.__.forEach(function(n){"function"==typeof n.__c&&n.__c();}),t.__c.__H=null),null!=(t=C$1({},t)).__c&&(t.__c.__P===r&&(t.__c.__P=e),t.__c=null),t.__k=t.__k&&t.__k.map(function(t){return n(t,e,r)})),t}(this.__b,e,r.__O=r.__P);}this.__b=null;}var u=t.__e&&a(y,null,n.fallback);return u&&(u.__h=null),[a(y,null,t.__e?null:n.children),u]};var F$1=function(n,t,e){if(++e[1]===e[0]&&n.o.delete(t),n.props.revealOrder&&("t"!==n.props.revealOrder[0]||!n.o.size))for(e=n.u;e;){for(;e.length>3;)e.pop()();if(e[1]>>1,1),t.i.removeChild(n);}}),N(a(M$1,{context:t.context},n.__v),t.l)):t.l&&t.componentWillUnmount();}function j$2(n,t){return a(T$1,{__v:n,i:t})}(D.prototype=new p).__e=function(n){var t=this,e=L$1(t.__v),r=t.o.get(n);return r[0]++,function(u){var o=function(){t.props.revealOrder?(r.push(u),F$1(t,n,r)):u();};e?e(o):o();}},D.prototype.render=function(n){this.u=null,this.o=new Map;var t=w(n.children);n.revealOrder&&"b"===n.revealOrder[0]&&t.reverse();for(var e=t.length;e--;)this.o.set(t[e],this.u=[1,0,this.u]);return n.children},D.prototype.componentDidUpdate=D.prototype.componentDidMount=function(){var n=this;this.o.forEach(function(t,e){F$1(n,e,t);});};var I$1="undefined"!=typeof Symbol&&Symbol.for&&Symbol.for("react.element")||60103,W=/^(?:accent|alignment|arabic|baseline|cap|clip(?!PathU)|color|fill|flood|font|glyph(?!R)|horiz|marker(?!H|W|U)|overline|paint|stop|strikethrough|stroke|text(?!L)|underline|unicode|units|v|vector|vert|word|writing|x(?!C))[A-Z]/,P$1=function(n){return ("undefined"!=typeof Symbol&&"symbol"==typeof Symbol()?/fil|che|rad/i:/fil|che|ra/i).test(n)};p.prototype.isReactComponent={},["componentWillMount","componentWillReceiveProps","componentWillUpdate"].forEach(function(n){Object.defineProperty(p.prototype,n,{configurable:!0,get:function(){return this["UNSAFE_"+n]},set:function(t){Object.defineProperty(this,n,{configurable:!0,writable:!0,value:t});}});});var B=n$1.event;function H$1(){}function Z(){return this.cancelBubble}function Y(){return this.defaultPrevented}n$1.event=function(n){return B&&(n=B(n)),n.persist=H$1,n.isPropagationStopped=Z,n.isDefaultPrevented=Y,n.nativeEvent=n};var q$1={configurable:!0,get:function(){return this.class}},G=n$1.vnode;n$1.vnode=function(n){var t=n.type,e=n.props,r=e;if("string"==typeof t){for(var u in r={},e){var o=e[u];"value"===u&&"defaultValue"in e&&null==o||("defaultValue"===u&&"value"in e&&null==e.value?u="value":"download"===u&&!0===o?o="":/ondoubleclick/i.test(u)?u="ondblclick":/^onchange(textarea|input)/i.test(u+t)&&!P$1(e.type)?u="oninput":/^on(Ani|Tra|Tou|BeforeInp)/.test(u)?u=u.toLowerCase():W.test(u)?u=u.replace(/[A-Z0-9]/,"-$&").toLowerCase():null===o&&(o=void 0),r[u]=o);}"select"==t&&r.multiple&&Array.isArray(r.value)&&(r.value=w(e.children).forEach(function(n){n.props.selected=-1!=r.value.indexOf(n.props.value);})),"select"==t&&null!=r.defaultValue&&(r.value=w(e.children).forEach(function(n){n.props.selected=r.multiple?-1!=r.defaultValue.indexOf(n.props.value):r.defaultValue==n.props.value;})),n.props=r;}t&&e.class!=e.className&&(q$1.enumerable="className"in e,null!=e.className&&(r.class=e.className),Object.defineProperty(r,"className",q$1)),n.$$typeof=I$1,G&&G(n);};var J=n$1.__r;n$1.__r=function(n){J&&J(n),n.__c;};"object"==typeof performance&&"function"==typeof performance.now?performance.now.bind(performance):function(){return Date.now()};
+
+ var CLASS_PATTERN = /^class /;
+
+ function isClass(fn) {
+ return CLASS_PATTERN.test(fn.toString());
+ }
+
+ function isArray$1(obj) {
+ return Object.prototype.toString.call(obj) === '[object Array]';
+ }
+
+ function hasOwnProp(obj, prop) {
+ return Object.prototype.hasOwnProperty.call(obj, prop);
+ }
+
+ function annotate() {
+ var args = Array.prototype.slice.call(arguments);
+
+ if (args.length === 1 && isArray$1(args[0])) {
+ args = args[0];
+ }
+
+ var fn = args.pop();
+
+ fn.$inject = args;
+
+ return fn;
+ }
+
+
+ // Current limitations:
+ // - can't put into "function arg" comments
+ // function /* (no parenthesis like this) */ (){}
+ // function abc( /* xx (no parenthesis like this) */ a, b) {}
+ //
+ // Just put the comment before function or inside:
+ // /* (((this is fine))) */ function(a, b) {}
+ // function abc(a) { /* (((this is fine))) */}
+ //
+ // - can't reliably auto-annotate constructor; we'll match the
+ // first constructor(...) pattern found which may be the one
+ // of a nested class, too.
+
+ var CONSTRUCTOR_ARGS = /constructor\s*[^(]*\(\s*([^)]*)\)/m;
+ var FN_ARGS = /^(?:async )?(?:function\s*)?[^(]*\(\s*([^)]*)\)/m;
+ var FN_ARG = /\/\*([^*]*)\*\//m;
+
+ function parseAnnotations(fn) {
+
+ if (typeof fn !== 'function') {
+ throw new Error('Cannot annotate "' + fn + '". Expected a function!');
+ }
+
+ var match = fn.toString().match(isClass(fn) ? CONSTRUCTOR_ARGS : FN_ARGS);
+
+ // may parse class without constructor
+ if (!match) {
+ return [];
+ }
+
+ return match[1] && match[1].split(',').map(function(arg) {
+ match = arg.match(FN_ARG);
+ return match ? match[1].trim() : arg.trim();
+ }) || [];
+ }
+
+ function Module() {
+ var providers = [];
+
+ this.factory = function(name, factory) {
+ providers.push([name, 'factory', factory]);
+ return this;
+ };
+
+ this.value = function(name, value) {
+ providers.push([name, 'value', value]);
+ return this;
+ };
+
+ this.type = function(name, type) {
+ providers.push([name, 'type', type]);
+ return this;
+ };
+
+ this.forEach = function(iterator) {
+ providers.forEach(iterator);
+ };
+
+ }
+
+ function Injector(modules, parent) {
+ parent = parent || {
+ get: function(name, strict) {
+ currentlyResolving.push(name);
+
+ if (strict === false) {
+ return null;
+ } else {
+ throw error('No provider for "' + name + '"!');
+ }
+ }
+ };
+
+ var currentlyResolving = [];
+ var providers = this._providers = Object.create(parent._providers || null);
+ var instances = this._instances = Object.create(null);
+
+ var self = instances.injector = this;
+
+ var error = function(msg) {
+ var stack = currentlyResolving.join(' -> ');
+ currentlyResolving.length = 0;
+ return new Error(stack ? msg + ' (Resolving: ' + stack + ')' : msg);
+ };
+
+ /**
+ * Return a named service.
+ *
+ * @param {String} name
+ * @param {Boolean} [strict=true] if false, resolve missing services to null
+ *
+ * @return {Object}
+ */
+ var get = function(name, strict) {
+ if (!providers[name] && name.indexOf('.') !== -1) {
+ var parts = name.split('.');
+ var pivot = get(parts.shift());
+
+ while (parts.length) {
+ pivot = pivot[parts.shift()];
+ }
+
+ return pivot;
+ }
+
+ if (hasOwnProp(instances, name)) {
+ return instances[name];
+ }
+
+ if (hasOwnProp(providers, name)) {
+ if (currentlyResolving.indexOf(name) !== -1) {
+ currentlyResolving.push(name);
+ throw error('Cannot resolve circular dependency!');
+ }
+
+ currentlyResolving.push(name);
+ instances[name] = providers[name][0](providers[name][1]);
+ currentlyResolving.pop();
+
+ return instances[name];
+ }
+
+ return parent.get(name, strict);
+ };
+
+ var fnDef = function(fn, locals) {
+
+ if (typeof locals === 'undefined') {
+ locals = {};
+ }
+
+ if (typeof fn !== 'function') {
+ if (isArray$1(fn)) {
+ fn = annotate(fn.slice());
+ } else {
+ throw new Error('Cannot invoke "' + fn + '". Expected a function!');
+ }
+ }
+
+ var inject = fn.$inject || parseAnnotations(fn);
+ var dependencies = inject.map(function(dep) {
+ if (hasOwnProp(locals, dep)) {
+ return locals[dep];
+ } else {
+ return get(dep);
+ }
+ });
+
+ return {
+ fn: fn,
+ dependencies: dependencies
+ };
+ };
+
+ var instantiate = function(Type) {
+ var def = fnDef(Type);
+
+ var fn = def.fn,
+ dependencies = def.dependencies;
+
+ // instantiate var args constructor
+ var Constructor = Function.prototype.bind.apply(fn, [ null ].concat(dependencies));
+
+ return new Constructor();
+ };
+
+ var invoke = function(func, context, locals) {
+ var def = fnDef(func, locals);
+
+ var fn = def.fn,
+ dependencies = def.dependencies;
+
+ return fn.apply(context, dependencies);
+ };
+
+
+ var createPrivateInjectorFactory = function(privateChildInjector) {
+ return annotate(function(key) {
+ return privateChildInjector.get(key);
+ });
+ };
+
+ var createChild = function(modules, forceNewInstances) {
+ if (forceNewInstances && forceNewInstances.length) {
+ var fromParentModule = Object.create(null);
+ var matchedScopes = Object.create(null);
+
+ var privateInjectorsCache = [];
+ var privateChildInjectors = [];
+ var privateChildFactories = [];
+
+ var provider;
+ var cacheIdx;
+ var privateChildInjector;
+ var privateChildInjectorFactory;
+ for (var name in providers) {
+ provider = providers[name];
+
+ if (forceNewInstances.indexOf(name) !== -1) {
+ if (provider[2] === 'private') {
+ cacheIdx = privateInjectorsCache.indexOf(provider[3]);
+ if (cacheIdx === -1) {
+ privateChildInjector = provider[3].createChild([], forceNewInstances);
+ privateChildInjectorFactory = createPrivateInjectorFactory(privateChildInjector);
+ privateInjectorsCache.push(provider[3]);
+ privateChildInjectors.push(privateChildInjector);
+ privateChildFactories.push(privateChildInjectorFactory);
+ fromParentModule[name] = [privateChildInjectorFactory, name, 'private', privateChildInjector];
+ } else {
+ fromParentModule[name] = [privateChildFactories[cacheIdx], name, 'private', privateChildInjectors[cacheIdx]];
+ }
+ } else {
+ fromParentModule[name] = [provider[2], provider[1]];
+ }
+ matchedScopes[name] = true;
+ }
+
+ if ((provider[2] === 'factory' || provider[2] === 'type') && provider[1].$scope) {
+ /* jshint -W083 */
+ forceNewInstances.forEach(function(scope) {
+ if (provider[1].$scope.indexOf(scope) !== -1) {
+ fromParentModule[name] = [provider[2], provider[1]];
+ matchedScopes[scope] = true;
+ }
+ });
+ }
+ }
+
+ forceNewInstances.forEach(function(scope) {
+ if (!matchedScopes[scope]) {
+ throw new Error('No provider for "' + scope + '". Cannot use provider from the parent!');
+ }
+ });
+
+ modules.unshift(fromParentModule);
+ }
+
+ return new Injector(modules, self);
+ };
+
+ var factoryMap = {
+ factory: invoke,
+ type: instantiate,
+ value: function(value) {
+ return value;
+ }
+ };
+
+ modules.forEach(function(module) {
+
+ function arrayUnwrap(type, value) {
+ if (type !== 'value' && isArray$1(value)) {
+ value = annotate(value.slice());
+ }
+
+ return value;
+ }
+
+ // TODO(vojta): handle wrong inputs (modules)
+ if (module instanceof Module) {
+ module.forEach(function(provider) {
+ var name = provider[0];
+ var type = provider[1];
+ var value = provider[2];
+
+ providers[name] = [factoryMap[type], arrayUnwrap(type, value), type];
+ });
+ } else if (typeof module === 'object') {
+ if (module.__exports__) {
+ var clonedModule = Object.keys(module).reduce(function(m, key) {
+ if (key.substring(0, 2) !== '__') {
+ m[key] = module[key];
+ }
+ return m;
+ }, Object.create(null));
+
+ var privateInjector = new Injector((module.__modules__ || []).concat([clonedModule]), self);
+ var getFromPrivateInjector = annotate(function(key) {
+ return privateInjector.get(key);
+ });
+ module.__exports__.forEach(function(key) {
+ providers[key] = [getFromPrivateInjector, key, 'private', privateInjector];
+ });
+ } else {
+ Object.keys(module).forEach(function(name) {
+ if (module[name][2] === 'private') {
+ providers[name] = module[name];
+ return;
+ }
+
+ var type = module[name][0];
+ var value = module[name][1];
+
+ providers[name] = [factoryMap[type], arrayUnwrap(type, value), type];
+ });
+ }
+ }
+ });
+
+ // public API
+ this.get = get;
+ this.invoke = invoke;
+ this.instantiate = instantiate;
+ this.createChild = createChild;
+ }
+
+ function createInjector(bootstrapModules) {
+ const modules = [],
+ components = [];
+
+ function hasModule(module) {
+ return modules.includes(module);
+ }
+
+ function addModule(module) {
+ modules.push(module);
+ }
+
+ function visit(module) {
+ if (hasModule(module)) {
+ return;
+ }
+
+ (module.__depends__ || []).forEach(visit);
+
+ if (hasModule(module)) {
+ return;
+ }
+
+ addModule(module);
+ (module.__init__ || []).forEach(function (component) {
+ components.push(component);
+ });
+ }
+
+ bootstrapModules.forEach(visit);
+ const injector = new Injector(modules);
+ components.forEach(function (component) {
+ try {
+ injector[typeof component === 'string' ? 'get' : 'invoke'](component);
+ } catch (err) {
+ console.error('Failed to instantiate component');
+ console.error(err.stack);
+ throw err;
+ }
+ });
+ return injector;
+ }
+
+ /**
+ * @param {string?} prefix
+ *
+ * @returns Element
+ */
+ function createFormContainer(prefix = 'fjs') {
+ const container = document.createElement('div');
+ container.classList.add(`${prefix}-container`);
+ return container;
+ }
+
+ function findErrors(errors, path) {
+ return errors[pathStringify(path)];
+ }
+ function pathStringify(path) {
+ if (!path) {
+ return '';
+ }
+
+ return path.join('.');
+ }
+ const indices = {};
+ function generateIndexForType(type) {
+ if (type in indices) {
+ indices[type]++;
+ } else {
+ indices[type] = 1;
+ }
+
+ return indices[type];
+ }
+ function generateIdForType(type) {
+ return `${type}${generateIndexForType(type)}`;
+ }
+ /**
+ * @template T
+ * @param {T} data
+ * @param {(this: any, key: string, value: any) => any} [replacer]
+ * @return {T}
+ */
+
+ function clone(data, replacer) {
+ return JSON.parse(JSON.stringify(data, replacer));
+ }
+
+ var FN_REF = '__fn';
+ var DEFAULT_PRIORITY = 1000;
+ var slice = Array.prototype.slice;
+ /**
+ * A general purpose event bus.
+ *
+ * This component is used to communicate across a diagram instance.
+ * Other parts of a diagram can use it to listen to and broadcast events.
+ *
+ *
+ * ## Registering for Events
+ *
+ * The event bus provides the {@link EventBus#on} and {@link EventBus#once}
+ * methods to register for events. {@link EventBus#off} can be used to
+ * remove event registrations. Listeners receive an instance of {@link Event}
+ * as the first argument. It allows them to hook into the event execution.
+ *
+ * ```javascript
+ *
+ * // listen for event
+ * eventBus.on('foo', function(event) {
+ *
+ * // access event type
+ * event.type; // 'foo'
+ *
+ * // stop propagation to other listeners
+ * event.stopPropagation();
+ *
+ * // prevent event default
+ * event.preventDefault();
+ * });
+ *
+ * // listen for event with custom payload
+ * eventBus.on('bar', function(event, payload) {
+ * console.log(payload);
+ * });
+ *
+ * // listen for event returning value
+ * eventBus.on('foobar', function(event) {
+ *
+ * // stop event propagation + prevent default
+ * return false;
+ *
+ * // stop event propagation + return custom result
+ * return {
+ * complex: 'listening result'
+ * };
+ * });
+ *
+ *
+ * // listen with custom priority (default=1000, higher is better)
+ * eventBus.on('priorityfoo', 1500, function(event) {
+ * console.log('invoked first!');
+ * });
+ *
+ *
+ * // listen for event and pass the context (`this`)
+ * eventBus.on('foobar', function(event) {
+ * this.foo();
+ * }, this);
+ * ```
+ *
+ *
+ * ## Emitting Events
+ *
+ * Events can be emitted via the event bus using {@link EventBus#fire}.
+ *
+ * ```javascript
+ *
+ * // false indicates that the default action
+ * // was prevented by listeners
+ * if (eventBus.fire('foo') === false) {
+ * console.log('default has been prevented!');
+ * };
+ *
+ *
+ * // custom args + return value listener
+ * eventBus.on('sum', function(event, a, b) {
+ * return a + b;
+ * });
+ *
+ * // you can pass custom arguments + retrieve result values.
+ * var sum = eventBus.fire('sum', 1, 2);
+ * console.log(sum); // 3
+ * ```
+ */
+
+ function EventBus() {
+ this._listeners = {}; // cleanup on destroy on lowest priority to allow
+ // message passing until the bitter end
+
+ this.on('diagram.destroy', 1, this._destroy, this);
+ }
+ /**
+ * Register an event listener for events with the given name.
+ *
+ * The callback will be invoked with `event, ...additionalArguments`
+ * that have been passed to {@link EventBus#fire}.
+ *
+ * Returning false from a listener will prevent the events default action
+ * (if any is specified). To stop an event from being processed further in
+ * other listeners execute {@link Event#stopPropagation}.
+ *
+ * Returning anything but `undefined` from a listener will stop the listener propagation.
+ *
+ * @param {string|Array} events
+ * @param {number} [priority=1000] the priority in which this listener is called, larger is higher
+ * @param {Function} callback
+ * @param {Object} [that] Pass context (`this`) to the callback
+ */
+
+ EventBus.prototype.on = function (events, priority, callback, that) {
+ events = isArray(events) ? events : [events];
+
+ if (isFunction(priority)) {
+ that = callback;
+ callback = priority;
+ priority = DEFAULT_PRIORITY;
+ }
+
+ if (!isNumber(priority)) {
+ throw new Error('priority must be a number');
+ }
+
+ var actualCallback = callback;
+
+ if (that) {
+ actualCallback = bind(callback, that); // make sure we remember and are able to remove
+ // bound callbacks via {@link #off} using the original
+ // callback
+
+ actualCallback[FN_REF] = callback[FN_REF] || callback;
+ }
+
+ var self = this;
+ events.forEach(function (e) {
+ self._addListener(e, {
+ priority: priority,
+ callback: actualCallback,
+ next: null
+ });
+ });
+ };
+ /**
+ * Register an event listener that is executed only once.
+ *
+ * @param {string} event the event name to register for
+ * @param {number} [priority=1000] the priority in which this listener is called, larger is higher
+ * @param {Function} callback the callback to execute
+ * @param {Object} [that] Pass context (`this`) to the callback
+ */
+
+
+ EventBus.prototype.once = function (event, priority, callback, that) {
+ var self = this;
+
+ if (isFunction(priority)) {
+ that = callback;
+ callback = priority;
+ priority = DEFAULT_PRIORITY;
+ }
+
+ if (!isNumber(priority)) {
+ throw new Error('priority must be a number');
+ }
+
+ function wrappedCallback() {
+ wrappedCallback.__isTomb = true;
+ var result = callback.apply(that, arguments);
+ self.off(event, wrappedCallback);
+ return result;
+ } // make sure we remember and are able to remove
+ // bound callbacks via {@link #off} using the original
+ // callback
+
+
+ wrappedCallback[FN_REF] = callback;
+ this.on(event, priority, wrappedCallback);
+ };
+ /**
+ * Removes event listeners by event and callback.
+ *
+ * If no callback is given, all listeners for a given event name are being removed.
+ *
+ * @param {string|Array} events
+ * @param {Function} [callback]
+ */
+
+
+ EventBus.prototype.off = function (events, callback) {
+ events = isArray(events) ? events : [events];
+ var self = this;
+ events.forEach(function (event) {
+ self._removeListener(event, callback);
+ });
+ };
+ /**
+ * Create an EventBus event.
+ *
+ * @param {Object} data
+ *
+ * @return {Object} event, recognized by the eventBus
+ */
+
+
+ EventBus.prototype.createEvent = function (data) {
+ var event = new InternalEvent();
+ event.init(data);
+ return event;
+ };
+ /**
+ * Fires a named event.
+ *
+ * @example
+ *
+ * // fire event by name
+ * events.fire('foo');
+ *
+ * // fire event object with nested type
+ * var event = { type: 'foo' };
+ * events.fire(event);
+ *
+ * // fire event with explicit type
+ * var event = { x: 10, y: 20 };
+ * events.fire('element.moved', event);
+ *
+ * // pass additional arguments to the event
+ * events.on('foo', function(event, bar) {
+ * alert(bar);
+ * });
+ *
+ * events.fire({ type: 'foo' }, 'I am bar!');
+ *
+ * @param {string} [name] the optional event name
+ * @param {Object} [event] the event object
+ * @param {...Object} additional arguments to be passed to the callback functions
+ *
+ * @return {boolean} the events return value, if specified or false if the
+ * default action was prevented by listeners
+ */
+
+
+ EventBus.prototype.fire = function (type, data) {
+ var event, firstListener, returnValue, args;
+ args = slice.call(arguments);
+
+ if (typeof type === 'object') {
+ data = type;
+ type = data.type;
+ }
+
+ if (!type) {
+ throw new Error('no event type specified');
+ }
+
+ firstListener = this._listeners[type];
+
+ if (!firstListener) {
+ return;
+ } // we make sure we fire instances of our home made
+ // events here. We wrap them only once, though
+
+
+ if (data instanceof InternalEvent) {
+ // we are fine, we alread have an event
+ event = data;
+ } else {
+ event = this.createEvent(data);
+ } // ensure we pass the event as the first parameter
+
+
+ args[0] = event; // original event type (in case we delegate)
+
+ var originalType = event.type; // update event type before delegation
+
+ if (type !== originalType) {
+ event.type = type;
+ }
+
+ try {
+ returnValue = this._invokeListeners(event, args, firstListener);
+ } finally {
+ // reset event type after delegation
+ if (type !== originalType) {
+ event.type = originalType;
+ }
+ } // set the return value to false if the event default
+ // got prevented and no other return value exists
+
+
+ if (returnValue === undefined && event.defaultPrevented) {
+ returnValue = false;
+ }
+
+ return returnValue;
+ };
+
+ EventBus.prototype.handleError = function (error) {
+ return this.fire('error', {
+ error: error
+ }) === false;
+ };
+
+ EventBus.prototype._destroy = function () {
+ this._listeners = {};
+ };
+
+ EventBus.prototype._invokeListeners = function (event, args, listener) {
+ var returnValue;
+
+ while (listener) {
+ // handle stopped propagation
+ if (event.cancelBubble) {
+ break;
+ }
+
+ returnValue = this._invokeListener(event, args, listener);
+ listener = listener.next;
+ }
+
+ return returnValue;
+ };
+
+ EventBus.prototype._invokeListener = function (event, args, listener) {
+ var returnValue;
+
+ if (listener.callback.__isTomb) {
+ return returnValue;
+ }
+
+ try {
+ // returning false prevents the default action
+ returnValue = invokeFunction(listener.callback, args); // stop propagation on return value
+
+ if (returnValue !== undefined) {
+ event.returnValue = returnValue;
+ event.stopPropagation();
+ } // prevent default on return false
+
+
+ if (returnValue === false) {
+ event.preventDefault();
+ }
+ } catch (e) {
+ if (!this.handleError(e)) {
+ console.error('unhandled error in event listener');
+ console.error(e.stack);
+ throw e;
+ }
+ }
+
+ return returnValue;
+ };
+ /*
+ * Add new listener with a certain priority to the list
+ * of listeners (for the given event).
+ *
+ * The semantics of listener registration / listener execution are
+ * first register, first serve: New listeners will always be inserted
+ * after existing listeners with the same priority.
+ *
+ * Example: Inserting two listeners with priority 1000 and 1300
+ *
+ * * before: [ 1500, 1500, 1000, 1000 ]
+ * * after: [ 1500, 1500, (new=1300), 1000, 1000, (new=1000) ]
+ *
+ * @param {string} event
+ * @param {Object} listener { priority, callback }
+ */
+
+
+ EventBus.prototype._addListener = function (event, newListener) {
+ var listener = this._getListeners(event),
+ previousListener; // no prior listeners
+
+
+ if (!listener) {
+ this._setListeners(event, newListener);
+
+ return;
+ } // ensure we order listeners by priority from
+ // 0 (high) to n > 0 (low)
+
+
+ while (listener) {
+ if (listener.priority < newListener.priority) {
+ newListener.next = listener;
+
+ if (previousListener) {
+ previousListener.next = newListener;
+ } else {
+ this._setListeners(event, newListener);
+ }
+
+ return;
+ }
+
+ previousListener = listener;
+ listener = listener.next;
+ } // add new listener to back
+
+
+ previousListener.next = newListener;
+ };
+
+ EventBus.prototype._getListeners = function (name) {
+ return this._listeners[name];
+ };
+
+ EventBus.prototype._setListeners = function (name, listener) {
+ this._listeners[name] = listener;
+ };
+
+ EventBus.prototype._removeListener = function (event, callback) {
+ var listener = this._getListeners(event),
+ nextListener,
+ previousListener,
+ listenerCallback;
+
+ if (!callback) {
+ // clear listeners
+ this._setListeners(event, null);
+
+ return;
+ }
+
+ while (listener) {
+ nextListener = listener.next;
+ listenerCallback = listener.callback;
+
+ if (listenerCallback === callback || listenerCallback[FN_REF] === callback) {
+ if (previousListener) {
+ previousListener.next = nextListener;
+ } else {
+ // new first listener
+ this._setListeners(event, nextListener);
+ }
+ }
+
+ previousListener = listener;
+ listener = nextListener;
+ }
+ };
+ /**
+ * A event that is emitted via the event bus.
+ */
+
+
+ function InternalEvent() {}
+
+ InternalEvent.prototype.stopPropagation = function () {
+ this.cancelBubble = true;
+ };
+
+ InternalEvent.prototype.preventDefault = function () {
+ this.defaultPrevented = true;
+ };
+
+ InternalEvent.prototype.init = function (data) {
+ assign(this, data || {});
+ };
+ /**
+ * Invoke function. Be fast...
+ *
+ * @param {Function} fn
+ * @param {Array