import{r as t,h as n,H as r}from"./p-bace3d90.js";import{c as i}from"./p-7bff44eb.js";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var e=function(){return(e=Object.assign||function(t){for(var n,r=1,i=arguments.length;r<i;r++)for(var e in n=arguments[r])Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e]);return t}).apply(this,arguments)};function o(t,n){var r={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&n.indexOf(i)<0&&(r[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var e=0;for(i=Object.getOwnPropertySymbols(t);e<i.length;e++)n.indexOf(i[e])<0&&Object.prototype.propertyIsEnumerable.call(t,i[e])&&(r[i[e]]=t[i[e]])}return r}function s(t){var n="function"==typeof Symbol&&Symbol.iterator,r=n&&t[n],i=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")}function u(t,n){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var i,e,o=r.call(t),s=[];try{for(;(void 0===n||n-- >0)&&!(i=o.next()).done;)s.push(i.value)}catch(t){e={error:t}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(e)throw e.error}}return s}function a(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(u(arguments[n]));return t}var c={};function f(t){return Object.keys(t)}function h(t,n,r){void 0===r&&(r=".");var i=d(t,r),e=d(n,r);return C(e)?!!C(i)&&e===i:C(i)?i in e:f(i).every((function(t){return t in e&&h(i[t],e[t])}))}function v(t){try{return C(t)||"number"==typeof t?""+t:t.type}catch(t){throw new Error("Events must be strings or objects with a string event.type property.")}}function l(t,n){try{return _(t)?t:t.toString().split(n)}catch(n){throw new Error("'"+t+"' is not a valid state path.")}}function d(t,n){return"object"==typeof(r=t)&&"value"in r&&"context"in r&&"event"in r&&"_event"in r?t.value:_(t)?y(t):"string"!=typeof t?t:y(l(t,n));var r}function y(t){if(1===t.length)return t[0];for(var n={},r=n,i=0;i<t.length-1;i++)i===t.length-2?r[t[i]]=t[i+1]:(r[t[i]]={},r=r[t[i]]);return n}function p(t,n){for(var r={},i=f(t),e=0;e<i.length;e++){var o=i[e];r[o]=n(t[o],o,t,e)}return r}function m(t,n,r){var i,e,o={};try{for(var u=s(f(t)),a=u.next();!a.done;a=u.next()){var c=a.value,h=t[c];r(h)&&(o[c]=n(h,c,t))}}catch(t){i={error:t}}finally{try{a&&!a.done&&(e=u.return)&&e.call(u)}finally{if(i)throw i.error}}return o}var b=function(t){return function(n){var r,i,e=n;try{for(var o=s(t),u=o.next();!u.done;u=o.next())e=e[u.value]}catch(t){r={error:t}}finally{try{u&&!u.done&&(i=o.return)&&i.call(o)}finally{if(r)throw r.error}}return e}};function g(t){return t?C(t)?[[t]]:w(f(t).map((function(n){var r=t[n];return"string"==typeof r||r&&Object.keys(r).length?g(t[n]).map((function(t){return[n].concat(t)})):[[n]]}))):[[]]}function w(t){var n;return(n=[]).concat.apply(n,a(t))}function x(t){return _(t)?t:[t]}function j(t){return void 0===t?[]:x(t)}function S(t,n,r){var i,e;if(k(t))return t(n,r.data);var o={};try{for(var u=s(Object.keys(t)),a=u.next();!a.done;a=u.next()){var c=a.value,f=t[c];o[c]=k(f)?f(n,r.data):f}}catch(t){i={error:t}}finally{try{a&&!a.done&&(e=u.return)&&e.call(u)}finally{if(i)throw i.error}}return o}function O(t){return t instanceof Promise||!(null===t||!k(t)&&"object"!=typeof t||!k(t.then))}function E(t,n){var r,i,e=u([[],[]],2),o=e[0],a=e[1];try{for(var c=s(t),f=c.next();!f.done;f=c.next()){var h=f.value;n(h)?o.push(h):a.push(h)}}catch(t){r={error:t}}finally{try{f&&!f.done&&(i=c.return)&&i.call(c)}finally{if(r)throw r.error}}return[o,a]}function T(t,n){return p(t.states,(function(t,r){if(t){var i=(C(n)?void 0:n[r])||(t?t.current:void 0);if(i)return{current:i,states:T(t,i)}}}))}function _(t){return Array.isArray(t)}function k(t){return"function"==typeof t}function C(t){return"string"==typeof t}function I(t,n){if(t)return C(t)?{type:"xstate.guard",name:t,predicate:n?n[t]:void 0}:k(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}function A(t){try{return"subscribe"in t&&k(t.subscribe)}catch(t){return!1}}var N,M,J=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}();function D(t){try{return"__xstatenode"in t}catch(t){return!1}}function H(t,n){return C(t)||"number"==typeof t?e({type:t},n):t}function P(t,n){if(!C(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var r=H(t);return e({name:r.type,data:r,$$type:"scxml",type:"external"},n)}function F(t,n){return x(n).map((function(n){return void 0===n||"string"==typeof n||D(n)?{target:n,event:t}:e(e({},n),{event:t})}))}function V(t,n,r,i,e){var o=t.options.guards,s={state:e,cond:n,_event:i};if("xstate.guard"===n.type)return n.predicate(r,i.data,s);var u=o[n.type];if(!u)throw new Error("Guard '"+n.type+"' is not implemented on machine '"+t.id+"'.");return u(r,i.data,s)}function $(t){return"string"==typeof t?{type:t}:t}!function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"}(N||(N={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(M||(M={}));var U=N.Start,z=N.Stop,L=N.Raise,B=N.Send,R=N.Cancel,q=N.NullEvent,G=N.Assign,K=N.Log,Q=N.Invoke,W=N.ErrorPlatform,X=N.ErrorCustom,Y=N.Update,Z=N.Choose,tt=N.Pure,nt=P({type:N.Init});function rt(t,n){return n&&n[t]||void 0}function it(t,n){var r;if(C(t)||"number"==typeof t){var i=rt(t,n);r=k(i)?{type:t,exec:i}:i||{type:t,exec:void 0}}else if(k(t))r={type:t.name||t.toString(),exec:t};else if(k(i=rt(t.type,n)))r=e(e({},t),{exec:i});else if(i){var o=i.type||t.type;r=e(e(e({},i),t),{type:o})}else r=t;return Object.defineProperty(r,"toString",{value:function(){return r.type},enumerable:!1,configurable:!0}),r}var et=function(t,n){return t?(_(t)?t:[t]).map((function(t){return it(t,n)})):[]};function ot(t){var n=it(t);return e(e({id:C(t)?t:n.id},n),{type:n.type})}function st(t){return C(t)?{type:L,event:t}:ut(t,{to:M.Internal})}function ut(t,n){return{to:n?n.to:void 0,type:B,event:k(t)?t:H(t),delay:n?n.delay:void 0,id:n&&void 0!==n.id?n.id:k(t)?t.name:v(t)}}var at=function(t){return{type:G,assignment:t}};function ct(t,n){var r=N.DoneState+"."+t;return{type:r,data:n,toString:function(){return r}}}function ft(t,n){var r=N.DoneInvoke+"."+t;return{type:r,data:n,toString:function(){return r}}}function ht(t,n){var r=N.ErrorPlatform+"."+t;return{type:r,data:n,toString:function(){return r}}}function vt(t,n,r,i,o){var a=u(E(o,(function(t){return t.type===G})),2),c=a[0],h=a[1],v=c.length?function(t,n,r,i){return t?r.reduce((function(t,r){var e,o,u=r.assignment,a={state:i,action:r,_event:n},c={};if(k(u))c=u(t,n.data,a);else try{for(var h=s(f(u)),v=h.next();!v.done;v=h.next()){var l=v.value,d=u[l];c[l]=k(d)?d(t,n.data,a):d}}catch(t){e={error:t}}finally{try{v&&!v.done&&(o=h.return)&&o.call(h)}finally{if(e)throw e.error}}return Object.assign({},t,c)}),t):t}(r,i,c,n):r;return[w(h.map((function(r){var o;switch(r.type){case L:return{type:L,_event:P(r.event)};case B:return function(t,n,r,i){var o,s={_event:r},u=P(k(t.event)?t.event(n,r.data,s):t.event);if(C(t.delay)){var a=i&&i[t.delay];o=k(a)?a(n,r.data,s):a}else o=k(t.delay)?t.delay(n,r.data,s):t.delay;var c=k(t.to)?t.to(n,r.data,s):t.to;return e(e({},t),{to:c,_event:u,event:u.data,delay:o})}(r,v,i,t.options.delays);case K:return function(t,n,r){return e(e({},t),{value:C(t.expr)?t.expr:t.expr(n,r.data,{_event:r})})}(r,v,i);case Z:if(!(u=null===(o=r.conds.find((function(r){var e=I(r.cond,t.options.guards);return!e||V(t,e,v,i,n)})))||void 0===o?void 0:o.actions))return[];var s=vt(t,n,v,i,et(j(u),t.options.actions));return v=s[1],s[0];case tt:var u;return(u=r.get(v,i.data))?(s=vt(t,n,v,i,et(j(u),t.options.actions)),v=s[1],s[0]):[];case z:return function(t,n,r){var i=k(t.activity)?t.activity(n,r.data):t.activity;return{type:N.Stop,activity:"string"==typeof i?{id:i}:i}}(r,v,i);default:return it(r,t.options.actions)}}))),v]}var lt=function(t){return"atomic"===t.type||"final"===t.type};function dt(t){return f(t.states).map((function(n){return t.states[n]}))}function yt(t){var n=[t];return lt(t)?n:n.concat(w(dt(t).map(yt)))}function pt(t,n){var r,i,e,o,u,a,c,f,h=bt(new Set(t)),v=new Set(n);try{for(var l=s(v),d=l.next();!d.done;d=l.next())for(var y=(O=d.value).parent;y&&!v.has(y);)v.add(y),y=y.parent}catch(t){r={error:t}}finally{try{d&&!d.done&&(i=l.return)&&i.call(l)}finally{if(r)throw r.error}}var p=bt(v);try{for(var m=s(v),b=m.next();!b.done;b=m.next())if("compound"!==(O=b.value).type||p.get(O)&&p.get(O).length){if("parallel"===O.type)try{for(var g=(u=void 0,s(dt(O))),w=g.next();!w.done;w=g.next()){var x=w.value;"history"!==x.type&&(v.has(x)||(v.add(x),h.get(x)?h.get(x).forEach((function(t){return v.add(t)})):x.initialStateNodes.forEach((function(t){return v.add(t)}))))}}catch(t){u={error:t}}finally{try{w&&!w.done&&(a=g.return)&&a.call(g)}finally{if(u)throw u.error}}}else h.get(O)?h.get(O).forEach((function(t){return v.add(t)})):O.initialStateNodes.forEach((function(t){return v.add(t)}))}catch(t){e={error:t}}finally{try{b&&!b.done&&(o=m.return)&&o.call(m)}finally{if(e)throw e.error}}try{for(var j=s(v),S=j.next();!S.done;S=j.next()){var O;for(y=(O=S.value).parent;y&&!v.has(y);)v.add(y),y=y.parent}}catch(t){c={error:t}}finally{try{S&&!S.done&&(f=j.return)&&f.call(j)}finally{if(c)throw c.error}}return v}function mt(t,n){var r=n.get(t);if(!r)return{};if("compound"===t.type){var i=r[0];if(!i)return{};if(lt(i))return i.key}var e={};return r.forEach((function(t){e[t.key]=mt(t,n)})),e}function bt(t){var n,r,i=new Map;try{for(var e=s(t),o=e.next();!o.done;o=e.next()){var u=o.value;i.has(u)||i.set(u,[]),u.parent&&(i.has(u.parent)||i.set(u.parent,[]),i.get(u.parent).push(u))}}catch(t){n={error:t}}finally{try{o&&!o.done&&(r=e.return)&&r.call(e)}finally{if(n)throw n.error}}return i}function gt(t,n){return mt(t,bt(pt([t],n)))}function wt(t,n){return Array.isArray(t)?t.some((function(t){return t===n})):t instanceof Set&&t.has(n)}function xt(t,n){return"compound"===n.type?dt(n).some((function(n){return"final"===n.type&&wt(t,n)})):"parallel"===n.type&&dt(n).every((function(n){return xt(t,n)}))}function jt(t,n){if(t===n)return!0;if(void 0===t||void 0===n)return!1;if(C(t)||C(n))return t===n;var r=f(t),i=f(n);return r.length===i.length&&r.every((function(r){return jt(t[r],n[r])}))}var St=function(){function t(t){var n=this;this.actions=[],this.activities=c,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||c,this.meta=t.meta||{},this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,Object.defineProperty(this,"nextEvents",{get:function(){return w(a(new Set(n.configuration.map((function(t){return t.ownEvents})))))}})}return t.from=function(n,r){return n instanceof t?n.context!==r?new t({value:n.value,context:r,_event:n._event,_sessionid:null,historyValue:n.historyValue,history:n.history,actions:[],activities:n.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):n:new t({value:n,context:r,_event:nt,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(n){return new t(n)},t.inert=function(n,r){return n instanceof t?n.actions.length?new t({value:n.value,context:r,_event:nt,_sessionid:null,historyValue:n.historyValue,history:n.history,activities:n.activities,configuration:n.configuration,transitions:[],children:{}}):n:t.from(n,r)},t.prototype.toStrings=function(t,n){var r=this;if(void 0===t&&(t=this.value),void 0===n&&(n="."),C(t))return[t];var i=f(t);return i.concat.apply(i,a(i.map((function(i){return r.toStrings(t[i],n).map((function(t){return i+n+t}))}))))},t.prototype.toJSON=function(){return o(this,["configuration","transitions"])},t.prototype.matches=function(t){return h(t,this.value)},t}(),Ot=function(t,n){return n(t)};function Et(t){return{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},toJSON:function(){return{id:t}}}}function Tt(t){return e(e({type:Q},t),{toJSON:function(){var n,r=o(t,["onDone","onError"]);return e(e({},r),{type:Q,src:(n=t.src,"string"==typeof n?{type:n,toString:function(){return n}}:n)})}})}var _t={},kt=function(t){return"#"===t[0]},Ct=function(){function t(n,r,i){var o=this;this.config=n,this.context=i,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},r),this.parent=this.options._parent,this.key=this.config.key||this.options._key||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:"."),this.id=this.config.id||a([this.machine.key],this.path).join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&f(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.initial=this.config.initial,this.states=this.config.states?p(this.config.states,(function(n,r){var i,s=new t(n,{_parent:o,_key:r});return Object.assign(o.idMap,e(((i={})[s.id]=s,i),s.idMap)),s})):_t;var u=0;!function t(n){var r,i;n.order=u++;try{for(var e=s(dt(n)),o=e.next();!o.done;o=e.next())t(o.value)}catch(t){r={error:t}}finally{try{o&&!o.done&&(i=e.return)&&i.call(e)}finally{if(r)throw r.error}}}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.always||!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some((function(t){return""===t.event})):""in this.config.on),this.strict=!!this.config.strict,this.onEntry=j(this.config.entry||this.config.onEntry).map((function(t){return it(t)})),this.onExit=j(this.config.exit||this.config.onExit).map((function(t){return it(t)})),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=j(this.config.invoke).map((function(t,n){var r,i;if(D(t))return o.machine.options.services=e(((r={})[t.id]=t,r),o.machine.options.services),Tt({src:t.id,id:t.id});if(C(t.src))return Tt(e(e({},t),{id:t.id||t.src,src:t.src}));if(D(t.src)||k(t.src)){var s=o.id+":invocation["+n+"]";return o.machine.options.services=e(((i={})[s]=t.src,i),o.machine.options.services),Tt(e(e({id:s},t),{src:s}))}var u=t.src;return Tt(e(e({id:u.type},t),{src:u}))})),this.activities=j(this.config.activities).concat(this.invoke).map((function(t){return ot(t)})),this.transition=this.transition.bind(this)}return t.prototype._init=function(){this.__cache.transitions||yt(this).forEach((function(t){return t.on}))},t.prototype.withConfig=function(n,r){void 0===r&&(r=this.context);var i=this.options,o=i.activities,s=i.guards,u=i.services,a=i.delays;return new t(this.config,{actions:e(e({},i.actions),n.actions),activities:e(e({},o),n.activities),guards:e(e({},s),n.guards),services:e(e({},u),n.services),delays:e(e({},a),n.delays)},r)},t.prototype.withContext=function(n){return new t(this.config,this.options,n)},Object.defineProperty(t.prototype,"definition",{get:function(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:p(this.states,(function(t){return t.definition})),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.doneData,invoke:this.invoke}},enumerable:!1,configurable:!0}),t.prototype.toJSON=function(){return this.definition},Object.defineProperty(t.prototype,"on",{get:function(){return this.__cache.on?this.__cache.on:this.__cache.on=this.transitions.reduce((function(t,n){return t[n.eventType]=t[n.eventType]||[],t[n.eventType].push(n),t}),{})},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"after",{get:function(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"transitions",{get:function(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)},enumerable:!1,configurable:!0}),t.prototype.getCandidates=function(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];var n=""===t,r=this.transitions.filter((function(r){var i=r.eventType===t;return n?i:i||"*"===r.eventType}));return this.__cache.candidates[t]=r,r},t.prototype.getDelayedTransitions=function(){var t=this,n=this.config.after;if(!n)return[];var r=function(n,r){var i,e,o=(i=k(n)?t.id+":delay["+r+"]":n,N.After+"("+i+")"+((e=t.id)?"#"+e:""));return t.onEntry.push(ut(o,{delay:n})),t.onExit.push({type:R,sendId:o}),o};return(_(n)?n.map((function(t,n){var i=r(t.delay,n);return e(e({},t),{event:i})})):w(f(n).map((function(t,i){var o=n[t],s=C(o)?{target:o}:o,u=isNaN(+t)?t:+t,a=r(u,i);return j(s).map((function(t){return e(e({},t),{event:a,delay:u})}))})))).map((function(n){var r=n.delay;return e(e({},t.formatTransition(n)),{delay:r})}))},t.prototype.getStateNodes=function(t){var n,r=this;if(!t)return[];var i=t instanceof St?t.value:d(t,this.delimiter);if(C(i)){var e=this.getStateNode(i).initial;return void 0!==e?this.getStateNodes(((n={})[i]=e,n)):[this.states[i]]}var o=f(i);return o.map((function(t){return r.getStateNode(t)})).concat(o.reduce((function(t,n){var e=r.getStateNode(n).getStateNodes(i[n]);return t.concat(e)}),[]))},t.prototype.handles=function(t){var n=v(t);return this.events.includes(n)},t.prototype.resolveState=function(t){var n=Array.from(pt([],this.getStateNodes(t.value)));return new St(e(e({},t),{value:this.resolve(t.value),configuration:n,done:xt(n,this)}))},t.prototype.transitionLeafNode=function(t,n,r){var i=this.getStateNode(t).next(n,r);return i&&i.transitions.length?i:this.next(n,r)},t.prototype.transitionCompoundNode=function(t,n,r){var i=f(t),e=this.getStateNode(i[0])._transition(t[i[0]],n,r);return e&&e.transitions.length?e:this.next(n,r)},t.prototype.transitionParallelNode=function(t,n,r){var i,e,o={};try{for(var u=s(f(t)),a=u.next();!a.done;a=u.next()){var c=a.value,h=t[c];if(h){var v=this.getStateNode(c)._transition(h,n,r);v&&(o[c]=v)}}}catch(t){i={error:t}}finally{try{a&&!a.done&&(e=u.return)&&e.call(u)}finally{if(i)throw i.error}}var l=f(o).map((function(t){return o[t]})),d=w(l.map((function(t){return t.transitions})));if(!l.some((function(t){return t.transitions.length>0})))return this.next(n,r);var y=w(l.map((function(t){return t.entrySet}))),p=w(f(o).map((function(t){return o[t].configuration})));return{transitions:d,entrySet:y,exitSet:w(l.map((function(t){return t.exitSet}))),configuration:p,source:n,actions:w(f(o).map((function(t){return o[t].actions})))}},t.prototype._transition=function(t,n,r){return C(t)?this.transitionLeafNode(t,n,r):1===f(t).length?this.transitionCompoundNode(t,n,r):this.transitionParallelNode(t,n,r)},t.prototype.next=function(t,n){var r,i,e,o=this,u=n.name,c=[],f=[];try{for(var v=s(this.getCandidates(u)),l=v.next();!l.done;l=v.next()){var y=l.value,p=y.cond,m=y.in,g=t.context,x=!m||(C(m)&&kt(m)?t.matches(d(this.getStateNodeById(m).path,this.delimiter)):h(d(m,this.delimiter),b(this.path.slice(0,-2))(t.value))),j=!1;try{j=!p||V(this.machine,p,g,n,t)}catch(t){throw new Error("Unable to evaluate guard '"+(p.name||p.type)+"' in transition for event '"+u+"' in state node '"+this.id+"':\n"+t.message)}if(j&&x){void 0!==y.target&&(f=y.target),c.push.apply(c,a(y.actions)),e=y;break}}}catch(t){r={error:t}}finally{try{l&&!l.done&&(i=v.return)&&i.call(v)}finally{if(r)throw r.error}}if(e){if(!f.length)return{transitions:[e],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:c};var S=w(f.map((function(n){return o.getRelativeStateNodes(n,t.historyValue)}))),O=!!e.internal;return{transitions:[e],entrySet:O?[]:w(S.map((function(t){return o.nodesFromChild(t)}))),exitSet:O?[]:[this],configuration:S,source:t,actions:c}}},t.prototype.nodesFromChild=function(t){if(t.escapes(this))return[];for(var n=[],r=t;r&&r!==this;)n.push(r),r=r.parent;return n.push(this),n},t.prototype.escapes=function(t){if(this===t)return!1;for(var n=this.parent;n;){if(n===t)return!1;n=n.parent}return!0},t.prototype.getActions=function(t,n,r,i){var e,o,c,f,h=pt([],i?this.getStateNodes(i.value):[this]),v=t.configuration.length?pt(h,t.configuration):h;try{for(var l=s(v),d=l.next();!d.done;d=l.next())wt(h,m=d.value)||t.entrySet.push(m)}catch(t){e={error:t}}finally{try{d&&!d.done&&(o=l.return)&&o.call(l)}finally{if(e)throw e.error}}try{for(var y=s(h),p=y.next();!p.done;p=y.next()){var m;wt(v,m=p.value)&&!wt(t.exitSet,m.parent)||t.exitSet.push(m)}}catch(t){c={error:t}}finally{try{p&&!p.done&&(f=y.return)&&f.call(y)}finally{if(c)throw c.error}}t.source||(t.exitSet=[],t.entrySet.push(this));var b=w(t.entrySet.map((function(i){var e=[];if("final"!==i.type)return e;var o=i.parent;if(!o.parent)return e;e.push(ct(i.id,i.doneData),ct(o.id,i.doneData?S(i.doneData,n,r):void 0));var s=o.parent;return"parallel"===s.type&&dt(s).every((function(n){return xt(t.configuration,n)}))&&e.push(ct(s.id)),e})));t.exitSet.sort((function(t,n){return n.order-t.order})),t.entrySet.sort((function(t,n){return t.order-n.order}));var g=new Set(t.entrySet),x=new Set(t.exitSet),j=u([w(Array.from(g).map((function(t){return a(t.activities.map((function(t){return function(t){var n=ot(t);return{type:N.Start,activity:n,exec:void 0}}(t)})),t.onEntry)}))).concat(b.map(st)),w(Array.from(x).map((function(t){return a(t.onExit,t.activities.map((function(t){return function(t){var n=k(t)?t:ot(t);return{type:N.Stop,activity:n,exec:void 0}}(t)})))})))],2),O=j[0];return et(j[1].concat(t.actions).concat(O),this.machine.options.actions)},t.prototype.transition=function(t,n,r){void 0===t&&(t=this.initialState);var i,e=P(n);if(t instanceof St)i=void 0===r?t:this.resolveState(St.from(t,r));else{var o=C(t)?this.resolve(y(this.getResolvedPath(t))):this.resolve(t);i=this.resolveState(St.from(o,r||this.machine.context))}if(this.strict&&!this.events.includes(e.name)&&!/^(done|error)\./.test(e.name))throw new Error("Machine '"+this.id+"' does not accept event '"+e.name+"'");var s=this._transition(i.value,i,e)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:i,actions:[]},u=pt([],this.getStateNodes(i.value)),c=s.configuration.length?pt(u,s.configuration):u;return s.configuration=a(c),this.resolveTransition(s,i,e)},t.prototype.resolveRaisedTransition=function(t,n,r){var i,e=t.actions;return(t=this.transition(t,n))._event=r,t.event=r.data,(i=t.actions).unshift.apply(i,a(e)),t},t.prototype.resolveTransition=function(t,n,r,i){var o,a,c=this;void 0===r&&(r=nt),void 0===i&&(i=this.machine.context);var f=t.configuration,h=!n||t.transitions.length>0?gt(this.machine,f):void 0,v=n?n.historyValue?n.historyValue:t.source?this.machine.historyValue(n.value):void 0:void 0,l=n?n.context:i,d=this.getActions(t,l,r,n),y=n?e({},n.activities):{};try{for(var p=s(d),m=p.next();!m.done;m=p.next()){var b=m.value;b.type===U?y[b.activity.id||b.activity.type]=b:b.type===z&&(y[b.activity.id||b.activity.type]=!1)}}catch(t){o={error:t}}finally{try{m&&!m.done&&(a=p.return)&&a.call(p)}finally{if(o)throw o.error}}var g,w,x=u(vt(this,n,l,r,d),2),j=x[0],O=x[1],_=u(E(j,(function(t){return t.type===L||t.type===B&&t.to===M.Internal})),2),k=_[0],C=_[1],I=j.filter((function(t){var n;return t.type===U&&(null===(n=t.activity)||void 0===n?void 0:n.type)===Q})).reduce((function(t,n){return t[n.activity.id]=function(t,n,r,i){var e,o=$(t.src),s=null===(e=null==n?void 0:n.options.services)||void 0===e?void 0:e[o.type],u=t.data?S(t.data,r,i):void 0,a=s?function(t,n,r){var i=Et(n);return i.deferred=!0,D(t)&&(i.state=Ot(void 0,(function(){return(r?t.withContext(r):t).initialState}))),i}(s,t.id,u):Et(t.id);return a.meta=t,a}(n.activity,c.machine,O,r),t}),n?e({},n.children):{}),A=h?t.configuration:n?n.configuration:[],N=A.reduce((function(t,n){return void 0!==n.meta&&(t[n.id]=n.meta),t}),{}),J=xt(A,this),H=new St({value:h||n.value,context:O,_event:r,_sessionid:n?n._sessionid:null,historyValue:h?v?(g=v,w=h,{current:w,states:T(g,w)}):void 0:n?n.historyValue:void 0,history:!h||t.source?n:void 0,actions:h?C:[],activities:h?y:n?n.activities:{},meta:h?N:n?n.meta:void 0,events:[],configuration:A,transitions:t.transitions,children:I,done:J}),P=l!==O;H.changed=r.name===Y||P;var F=H.history;if(F&&delete F.history,!h)return H;var V=H;if(!J)for((this._transient||f.some((function(t){return t._transient})))&&(V=this.resolveRaisedTransition(V,{type:q},r));k.length;){var R=k.shift();V=this.resolveRaisedTransition(V,R._event,r)}var G=V.changed||(F?!!V.actions.length||P||typeof F.value!=typeof V.value||!jt(V.value,F.value):void 0);return V.changed=G,V.history=F,V},t.prototype.getStateNode=function(t){if(kt(t))return this.machine.getStateNodeById(t);if(!this.states)throw new Error("Unable to retrieve child state '"+t+"' from '"+this.id+"'; no child states exist.");var n=this.states[t];if(!n)throw new Error("Child state '"+t+"' does not exist on '"+this.id+"'");return n},t.prototype.getStateNodeById=function(t){var n=kt(t)?t.slice("#".length):t;if(n===this.id)return this;var r=this.machine.idMap[n];if(!r)throw new Error("Child state node '#"+n+"' does not exist on machine '"+this.id+"'");return r},t.prototype.getStateNodeByPath=function(t){if("string"==typeof t&&kt(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}for(var n=l(t,this.delimiter).slice(),r=this;n.length;){var i=n.shift();if(!i.length)break;r=r.getStateNode(i)}return r},t.prototype.resolve=function(t){var n,r=this;if(!t)return this.initialStateValue||_t;switch(this.type){case"parallel":return p(this.initialStateValue,(function(n,i){return n?r.getStateNode(i).resolve(t[i]||n):_t}));case"compound":if(C(t)){var i=this.getStateNode(t);return"parallel"===i.type||"compound"===i.type?((n={})[t]=i.initialStateValue,n):t}return f(t).length?p(t,(function(t,n){return t?r.getStateNode(n).resolve(t):_t})):this.initialStateValue||{};default:return t||_t}},t.prototype.getResolvedPath=function(t){if(kt(t)){var n=this.machine.idMap[t.slice("#".length)];if(!n)throw new Error("Unable to find state node '"+t+"'");return n.path}return l(t,this.delimiter)},Object.defineProperty(t.prototype,"initialStateValue",{get:function(){var t,n;if(this.__cache.initialStateValue)return this.__cache.initialStateValue;if("parallel"===this.type)n=m(this.states,(function(t){return t.initialStateValue||_t}),(function(t){return!("history"===t.type)}));else if(void 0!==this.initial){if(!this.states[this.initial])throw new Error("Initial state '"+this.initial+"' not found on '"+this.key+"'");n=lt(this.states[this.initial])?this.initial:((t={})[this.initial]=this.states[this.initial].initialStateValue,t)}return this.__cache.initialStateValue=n,this.__cache.initialStateValue},enumerable:!1,configurable:!0}),t.prototype.getInitialState=function(t,n){var r=this.getStateNodes(t);return this.resolveTransition({configuration:r,entrySet:r,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,void 0,n)},Object.defineProperty(t.prototype,"initialState",{get:function(){this._init();var t=this.initialStateValue;if(!t)throw new Error("Cannot retrieve initial state from simple state '"+this.id+"'.");return this.getInitialState(t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"target",{get:function(){var t;if("history"===this.type){var n=this.config;t=C(n.target)&&kt(n.target)?y(this.machine.getStateNodeById(n.target).path.slice(this.path.length-1)):n.target}return t},enumerable:!1,configurable:!0}),t.prototype.getRelativeStateNodes=function(t,n,r){return void 0===r&&(r=!0),r?"history"===t.type?t.resolveHistory(n):t.initialStateNodes:[t]},Object.defineProperty(t.prototype,"initialStateNodes",{get:function(){var t=this;return lt(this)?[this]:"compound"!==this.type||this.initial?w(g(this.initialStateValue).map((function(n){return t.getFromRelativePath(n)}))):[this]},enumerable:!1,configurable:!0}),t.prototype.getFromRelativePath=function(t){if(!t.length)return[this];var n=u(t),r=n[0],i=n.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '"+r+"' from node with no states");var e=this.getStateNode(r);if("history"===e.type)return e.resolveHistory();if(!this.states[r])throw new Error("Child state '"+r+"' does not exist on '"+this.id+"'");return this.states[r].getFromRelativePath(i)},t.prototype.historyValue=function(t){if(f(this.states).length)return{current:t||this.initialStateValue,states:m(this.states,(function(n,r){if(!t)return n.historyValue();var i=C(t)?void 0:t[r];return n.historyValue(i||n.initialStateValue)}),(function(t){return!t.history}))}},t.prototype.resolveHistory=function(t){var n=this;if("history"!==this.type)return[this];var r=this.parent;if(!t){var i=this.target;return i?w(g(i).map((function(t){return r.getFromRelativePath(t)}))):r.initialStateNodes}var e,o=(e=r.path,"states",function(t){var n,r,i=t;try{for(var o=s(e),u=o.next();!u.done;u=o.next())i=i.states[u.value]}catch(t){n={error:t}}finally{try{u&&!u.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}return i})(t).current;return C(o)?[r.getStateNode(o)]:w(g(o).map((function(t){return"deep"===n.history?r.getFromRelativePath(t):[r.states[t[0]]]})))},Object.defineProperty(t.prototype,"stateIds",{get:function(){var t=this,n=w(f(this.states).map((function(n){return t.states[n].stateIds})));return[this.id].concat(n)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"events",{get:function(){var t,n,r,i;if(this.__cache.events)return this.__cache.events;var e=this.states,o=new Set(this.ownEvents);if(e)try{for(var u=s(f(e)),a=u.next();!a.done;a=u.next()){var c=e[a.value];if(c.states)try{for(var h=(r=void 0,s(c.events)),v=h.next();!v.done;v=h.next())o.add(""+v.value)}catch(t){r={error:t}}finally{try{v&&!v.done&&(i=h.return)&&i.call(h)}finally{if(r)throw r.error}}}}catch(n){t={error:n}}finally{try{a&&!a.done&&(n=u.return)&&n.call(u)}finally{if(t)throw t.error}}return this.__cache.events=Array.from(o)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"ownEvents",{get:function(){var t=new Set(this.transitions.filter((function(t){return!(!t.target&&!t.actions.length&&t.internal)})).map((function(t){return t.eventType})));return Array.from(t)},enumerable:!1,configurable:!0}),t.prototype.resolveTarget=function(t){var n=this;if(void 0!==t)return t.map((function(t){if(!C(t))return t;var r=t[0]===n.delimiter;if(r&&!n.parent)return n.getStateNodeByPath(t.slice(1));var i=r?n.key+t:t;if(!n.parent)return n.getStateNodeByPath(i);try{return n.parent.getStateNodeByPath(i)}catch(t){throw new Error("Invalid transition definition for state node '"+n.id+"':\n"+t.message)}}))},t.prototype.formatTransition=function(t){var n=this,r=function(t){if(void 0!==t&&""!==t)return j(t)}(t.target),i="internal"in t?t.internal:!r||r.some((function(t){return C(t)&&t[0]===n.delimiter})),o=this.machine.options.guards,s=this.resolveTarget(r),u=e(e({},t),{actions:et(j(t.actions)),cond:I(t.cond,o),target:s,source:this,internal:i,eventType:t.event,toJSON:function(){return e(e({},u),{target:u.target?u.target.map((function(t){return"#"+t.id})):void 0,source:"#"+n.id})}});return u},t.prototype.formatTransitions=function(){var t,n,r,i=this;if(this.config.on)if(Array.isArray(this.config.on))r=this.config.on;else{var e=this.config.on,u=e["*"],c=void 0===u?[]:u,h=o(e,["*"]);r=w(f(h).map((function(t){return F(t,h[t])})).concat(F("*",c)))}else r=[];var v=this.config.always?F("",this.config.always):[],l=this.config.onDone?F(String(ct(this.id)),this.config.onDone):[],d=w(this.invoke.map((function(t){var n=[];return t.onDone&&n.push.apply(n,a(F(String(ft(t.id)),t.onDone))),t.onError&&n.push.apply(n,a(F(String(ht(t.id)),t.onError))),n}))),y=this.after,p=w(a(l,d,r,v).map((function(t){return j(t).map((function(t){return i.formatTransition(t)}))})));try{for(var m=s(y),b=m.next();!b.done;b=m.next())p.push(b.value)}catch(n){t={error:n}}finally{try{b&&!b.done&&(n=m.return)&&n.call(m)}finally{if(t)throw t.error}}return p},t}(),It={deferEvents:!1},At=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=e(e({},It),t)}return t.prototype.initialize=function(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()},t.prototype.schedule=function(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)},t.prototype.clear=function(){this.queue=[]},t.prototype.flushEvents=function(){for(var t=this.queue.shift();t;)this.process(t),t=this.queue.shift()},t.prototype.process=function(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}},t}(),Nt=new Map,Mt=0;function Jt(){return"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}var Dt,Ht={sync:!1,autoForward:!1};!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(Dt||(Dt={}));var Pt=function(){function t(n,r){var i=this;void 0===r&&(r=t.defaultOptions),this.machine=n,this.scheduler=new At,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=Dt.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(t,n){if(_(t))return i.batch(t),i.state;var r=P(H(t,n));if(i.status===Dt.Stopped)return i.state;if(i.status!==Dt.Running&&!i.options.deferEvents)throw new Error('Event "'+r.name+'" was sent to uninitialized service "'+i.machine.id+'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: '+JSON.stringify(r.data));return i.scheduler.schedule((function(){i.forward(r);var t=i.nextState(r);i.update(t,r)})),i._state},this.sendTo=function(t,n){var r,o=i.parent&&(n===M.Parent||i.parent.id===n),s=o?i.parent:C(n)?i.children.get(n)||function(t){return Nt.get(t)}(n):(r=n)&&"function"==typeof r.send?n:void 0;if(s)s.send("machine"in s?e(e({},t),{name:t.name===X?""+ht(i.id):t.name,origin:i.sessionId}):t.data);else if(!o)throw new Error("Unable to send event to child '"+n+"' from service '"+i.id+"'.")};var o=e(e({},t.defaultOptions),r),s=o.clock,u=o.logger,a=o.parent,c=o.id;this.id=void 0!==c?c:n.id,this.logger=u,this.clock=s,this.parent=a,this.options=o,this.scheduler=new At({deferEvents:this.options.deferEvents}),this.sessionId="x:"+Mt++}return Object.defineProperty(t.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:Ot(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),t.prototype.execute=function(t,n){var r,i;try{for(var e=s(t.actions),o=e.next();!o.done;o=e.next())this.exec(o.value,t,n)}catch(t){r={error:t}}finally{try{o&&!o.done&&(i=e.return)&&i.call(e)}finally{if(r)throw r.error}}},t.prototype.update=function(t,n){var r,i,e,o,u,a,c,f,h=this;if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.children.forEach((function(t){h.state.children[t.id]=t})),this.devTools&&this.devTools.send(n.data,t),t.event)try{for(var v=s(this.eventListeners),l=v.next();!l.done;l=v.next())(0,l.value)(t.event)}catch(t){r={error:t}}finally{try{l&&!l.done&&(i=v.return)&&i.call(v)}finally{if(r)throw r.error}}try{for(var d=s(this.listeners),y=d.next();!y.done;y=d.next())(0,y.value)(t,t.event)}catch(t){e={error:t}}finally{try{y&&!y.done&&(o=d.return)&&o.call(d)}finally{if(e)throw e.error}}try{for(var p=s(this.contextListeners),m=p.next();!m.done;m=p.next())(0,m.value)(this.state.context,this.state.history?this.state.history.context:void 0)}catch(t){u={error:t}}finally{try{m&&!m.done&&(a=p.return)&&a.call(p)}finally{if(u)throw u.error}}var b=xt(t.configuration||[],this.machine);if(this.state.configuration&&b){var g=t.configuration.find((function(t){return"final"===t.type&&t.parent===h.machine})),w=g&&g.doneData?S(g.doneData,t.context,n):void 0;try{for(var x=s(this.doneListeners),j=x.next();!j.done;j=x.next())(0,j.value)(ft(this.id,w))}catch(t){c={error:t}}finally{try{j&&!j.done&&(f=x.return)&&f.call(x)}finally{if(c)throw c.error}}this.stop()}},t.prototype.onTransition=function(t){return this.listeners.add(t),this.status===Dt.Running&&t(this.state,this.state.event),this},t.prototype.subscribe=function(t,n,r){var i,e=this;if(!t)return{unsubscribe:function(){}};var o=r;return"function"==typeof t?i=t:(i=t.next.bind(t),o=t.complete.bind(t)),this.listeners.add(i),this.status===Dt.Running&&i(this.state),o&&this.onDone(o),{unsubscribe:function(){i&&e.listeners.delete(i),o&&e.doneListeners.delete(o)}}},t.prototype.onEvent=function(t){return this.eventListeners.add(t),this},t.prototype.onSend=function(t){return this.sendListeners.add(t),this},t.prototype.onChange=function(t){return this.contextListeners.add(t),this},t.prototype.onStop=function(t){return this.stopListeners.add(t),this},t.prototype.onDone=function(t){return this.doneListeners.add(t),this},t.prototype.off=function(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this},t.prototype.start=function(t){var n=this;if(this.status===Dt.Running)return this;Nt.set(this.sessionId,this),this.initialized=!0,this.status=Dt.Running;var r=void 0===t?this.initialState:Ot(this,(function(){return!C(r=t)&&"value"in r&&"history"in r?n.machine.resolveState(t):n.machine.resolveState(St.from(t,n.machine.context));var r}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(r,nt)})),this},t.prototype.stop=function(){var t,n,r,i,e,o,u,a,c,h,v=this;try{for(var l=s(this.listeners),d=l.next();!d.done;d=l.next())this.listeners.delete(x=d.value)}catch(n){t={error:n}}finally{try{d&&!d.done&&(n=l.return)&&n.call(l)}finally{if(t)throw t.error}}try{for(var y=s(this.stopListeners),p=y.next();!p.done;p=y.next())(x=p.value)(),this.stopListeners.delete(x)}catch(t){r={error:t}}finally{try{p&&!p.done&&(i=y.return)&&i.call(y)}finally{if(r)throw r.error}}try{for(var m=s(this.contextListeners),b=m.next();!b.done;b=m.next())this.contextListeners.delete(x=b.value)}catch(t){e={error:t}}finally{try{b&&!b.done&&(o=m.return)&&o.call(m)}finally{if(e)throw e.error}}try{for(var g=s(this.doneListeners),w=g.next();!w.done;w=g.next()){var x;this.doneListeners.delete(x=w.value)}}catch(t){u={error:t}}finally{try{w&&!w.done&&(a=g.return)&&a.call(g)}finally{if(u)throw u.error}}if(!this.initialized)return this;this.state.configuration.forEach((function(t){var n,r;try{for(var i=s(t.definition.exit),e=i.next();!e.done;e=i.next())v.exec(e.value,v.state)}catch(t){n={error:t}}finally{try{e&&!e.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}})),this.children.forEach((function(t){k(t.stop)&&t.stop()}));try{for(var j=s(f(this.delayedEventsMap)),S=j.next();!S.done;S=j.next())this.clock.clearTimeout(this.delayedEventsMap[S.value])}catch(t){c={error:t}}finally{try{S&&!S.done&&(h=j.return)&&h.call(j)}finally{if(c)throw c.error}}return this.scheduler.clear(),this.initialized=!1,this.status=Dt.Stopped,Nt.delete(this.sessionId),this},t.prototype.batch=function(t){var n=this;if(this.status===Dt.NotStarted&&this.options.deferEvents);else if(this.status!==Dt.Running)throw new Error(t.length+' event(s) were sent to uninitialized service "'+this.machine.id+'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.');this.scheduler.schedule((function(){var r,i,o=n.state,u=!1,c=[],f=function(t){var r=P(t);n.forward(r),o=Ot(n,(function(){return n.machine.transition(o,r)})),c.push.apply(c,a(o.actions.map((function(t){return r=o,i=(n=t).exec,e(e({},n),{exec:void 0!==i?function(){return i(r.context,r.event,{action:n,state:r,_event:r._event})}:void 0});var n,r,i})))),u=u||!!o.changed};try{for(var h=s(t),v=h.next();!v.done;v=h.next())f(v.value)}catch(t){r={error:t}}finally{try{v&&!v.done&&(i=h.return)&&i.call(h)}finally{if(r)throw r.error}}o.changed=u,o.actions=c,n.update(o,P(t[t.length-1]))}))},t.prototype.sender=function(t){return this.send.bind(this,t)},t.prototype.nextState=function(t){var n=this,r=P(t);if(0===r.name.indexOf(W)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(W)})))throw r.data.data;return Ot(this,(function(){return n.machine.transition(n.state,r)}))},t.prototype.forward=function(t){var n,r;try{for(var i=s(this.forwardTo),e=i.next();!e.done;e=i.next()){var o=e.value,u=this.children.get(o);if(!u)throw new Error("Unable to forward event '"+t+"' from interpreter '"+this.id+"' to nonexistant child '"+o+"'.");u.send(t)}}catch(t){n={error:t}}finally{try{e&&!e.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}},t.prototype.defer=function(t){var n=this;this.delayedEventsMap[t.id]=this.clock.setTimeout((function(){t.to?n.sendTo(t._event,t.to):n.send(t._event)}),t.delay)},t.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},t.prototype.exec=function(t,n,r){void 0===r&&(r=this.machine.options.actions);var i=n.context,e=n._event,o=t.exec||rt(t.type,r),s=k(o)?o:o?o.exec:t.exec;if(s)try{return s(i,e.data,{action:t,state:this.state,_event:e})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(t.type){case B:var u=t;if("number"==typeof u.delay)return void this.defer(u);u.to?this.sendTo(u._event,u.to):this.send(u._event);break;case R:this.cancel(t.sendId);break;case U:var a=t.activity;if(!this.state.activities[a.id||a.type])break;if(a.type===N.Invoke){var c=$(a.src),f=this.machine.options.services?this.machine.options.services[c.type]:void 0,h=a.id,v=a.data,l="autoForward"in a?a.autoForward:!!a.forward;if(!f)return;var d=v?S(v,i,e):void 0,y=k(f)?f(i,e.data,{data:d,src:c}):f;O(y)?this.spawnPromise(Promise.resolve(y),h):k(y)?this.spawnCallback(y,h):A(y)?this.spawnObservable(y,h):D(y)&&this.spawnMachine(d?y.withContext(d):y,{id:h,autoForward:l})}else this.spawnActivity(a);break;case z:this.stopChild(t.activity.id);break;case K:var p=t.label,m=t.value;p?this.logger(p,m):this.logger(m)}},t.prototype.removeChild=function(t){this.children.delete(t),this.forwardTo.delete(t),delete this.state.children[t]},t.prototype.stopChild=function(t){var n=this.children.get(t);n&&(this.removeChild(t),k(n.stop)&&n.stop())},t.prototype.spawn=function(t,n,r){if(O(t))return this.spawnPromise(Promise.resolve(t),n);if(k(t))return this.spawnCallback(t,n);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(i=t)&&"id"in i)return this.spawnActor(t);if(A(t))return this.spawnObservable(t,n);if(D(t))return this.spawnMachine(t,e(e({},r),{id:n}));throw new Error('Unable to spawn entity "'+n+'" of type "'+typeof t+'".');var i},t.prototype.spawnMachine=function(n,r){var i=this;void 0===r&&(r={});var o=new t(n,e(e({},this.options),{parent:this,id:r.id||n.id})),s=e(e({},Ht),r);s.sync&&o.onTransition((function(t){i.send(Y,{state:t,id:o.id})}));var u=o;return this.children.set(o.id,u),s.autoForward&&this.forwardTo.add(o.id),o.onDone((function(t){i.removeChild(o.id),i.send(P(t,{origin:o.id}))})).start(),u},t.prototype.spawnPromise=function(t,n){var r=this,i=!1;t.then((function(t){i||(r.removeChild(n),r.send(P(ft(n,t),{origin:n})))}),(function(t){if(!i){r.removeChild(n);var e=ht(n,t);try{r.send(P(e,{origin:n}))}catch(t){r.devTools&&r.devTools.send(e,r.state),r.machine.strict&&r.stop()}}}));var e={id:n,send:function(){},subscribe:function(n,r,i){var e=function(t,n,r){if("object"==typeof t)return t;var i=function(){};return{next:t,error:n||i,complete:r||i}}(n,r,i),o=!1;return t.then((function(t){o||(e.next(t),o||e.complete())}),(function(t){o||e.error(t)})),{unsubscribe:function(){return o=!0}}},stop:function(){i=!0},toJSON:function(){return{id:n}}};return this.children.set(n,e),e},t.prototype.spawnCallback=function(t,n){var r,i=this,e=!1,o=new Set,s=new Set;try{r=t((function(t){s.forEach((function(n){return n(t)})),e||i.send(P(t,{origin:n}))}),(function(t){o.add(t)}))}catch(t){this.send(ht(n,t))}if(O(r))return this.spawnPromise(r,n);var u={id:n,send:function(t){return o.forEach((function(n){return n(t)}))},subscribe:function(t){return s.add(t),{unsubscribe:function(){s.delete(t)}}},stop:function(){e=!0,k(r)&&r()},toJSON:function(){return{id:n}}};return this.children.set(n,u),u},t.prototype.spawnObservable=function(t,n){var r=this,i=t.subscribe((function(t){r.send(P(t,{origin:n}))}),(function(t){r.removeChild(n),r.send(P(ht(n,t),{origin:n}))}),(function(){r.removeChild(n),r.send(P(ft(n),{origin:n}))})),e={id:n,send:function(){},subscribe:function(n,r,i){return t.subscribe(n,r,i)},stop:function(){return i.unsubscribe()},toJSON:function(){return{id:n}}};return this.children.set(n,e),e},t.prototype.spawnActor=function(t){return this.children.set(t.id,t),t},t.prototype.spawnActivity=function(t){var n=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(n){var r=n(this.state.context,t);this.spawnEffect(t.id,r)}},t.prototype.spawnEffect=function(t,n){this.children.set(t,{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:n||void 0,toJSON:function(){return{id:t}}})},t.prototype.attachDev=function(){var t=Jt();if(this.options.devTools&&t&&t.__REDUX_DEVTOOLS_EXTENSION__){var n="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(e(e({name:this.id,autoPause:!0,stateSanitizer:function(t){return{value:t.value,context:t.context,actions:t.actions}}},n),{features:e({jump:!1,skip:!1},n?n.features:void 0)}),this.machine),this.devTools.init(this.state)}},t.prototype.toJSON=function(){return{id:this.id}},t.prototype[J]=function(){return this},t.defaultOptions=function(t){return{execute:!0,deferEvents:!0,clock:{setTimeout:function(t,n){return setTimeout(t,n)},clearTimeout:function(t){return clearTimeout(t)}},logger:t.console.log.bind(console),devTools:!1}}("undefined"!=typeof self?self:global),t.interpret=Ft,t}();function Ft(t,n){return new Pt(t,n)}const Vt=t=>{t.localName.includes("corejam")&&!t.localName.includes("type")&&(t.style.background="var(--cj-colors-blue-100)",t.style.outline="1px solid black")},$t=t=>{t.style.removeProperty("background"),t.style.removeProperty("outline")},Ut=t=>Gt.send(t),zt=(Lt={id:"canvas-machine",initial:"inactive",context:{draggedElementInstance:null,dx:0,dy:0,px:0,py:0},states:{inactive:{id:"inactive",on:{active:{target:"active"}},entry:["listenForCorjamTab","listenForCorejamMenu"]},active:{id:"active",on:{inactive:{target:"inactive",actions:["cleanupEventListeners"]},pointerdown:{target:"dragging",actions:["onIdleToDragging"],cond:"isDraggable"}},entry:["initBaseCanvas","enableSelectAndTouch","initElementsAlreadyInCavas"]},dragging:{initial:"outside",entry:["disableSelectAndTouch"],states:{outside:{on:{pointerover:{target:"inside",actions:["highlightTargets"],cond:"isOutsideMenu"},pointerup:{target:"#active",actions:["onDraggingToIdle"]}},entry:["dragging"]},inside:{on:{pointermove:{internal:!0,actions:["highlightTargets","mousemove"]},pointerup:{target:"#dropped",actions:["dropItem"]},pointerout:{internal:!0,actions:["removeHighlightPossibleTarget"]},outside:{target:"outside"}}}},on:{pointermove:{internal:!0,actions:["mousemove"]}}},dropped:{id:"dropped",after:{50:{target:"active",actions:["onDraggingToIdle"]}}}}},Bt={actions:{listenForCorejamMenu:()=>{document.querySelector("corejam-menu").addEventListener("hideCorejamMenu",(()=>{console.log("bye")}))},listenForCorjamTab:()=>{document.querySelector("corejam-tabs").addEventListener("tabSelected",(t=>{Ut("corejam-builder"===t.detail?{type:"active"}:{type:"inactive"})}))},disableSelectAndTouch:()=>{document.body.style.userSelect="none",document.body.style.touchAction="none"},enableSelectAndTouch:()=>{document.body.style.removeProperty("user-select"),document.body.style.removeProperty("touch-action")},initBaseCanvas:()=>{document.body.addEventListener("pointerup",Ut,{passive:!0}),document.body.addEventListener("pointermove",Ut,{passive:!0}),document.body.addEventListener("pointerdown",Ut,{passive:!0}),document.body.addEventListener("pointerover",Ut,{passive:!0}),document.body.addEventListener("pointerout",Ut,{passive:!0}),document.querySelector(".drop").addEventListener("pointerout",(()=>{Ut({type:"outside"})}))},initElementsAlreadyInCavas:()=>{document.querySelectorAll(".drop *").forEach((t=>{"corejam-box"!==t.localName&&"corejam-type"!==t.localName||(t.dataset.draggable="true",t.dataset.inCanvas="true")}))},cleanupEventListeners:()=>{document.body.removeEventListener("pointerup",Ut),document.body.removeEventListener("pointermove",Ut),document.body.removeEventListener("pointerdown",Ut),document.body.removeEventListener("pointerover",Ut),document.body.removeEventListener("pointerout",Ut),document.querySelector(".drop").removeEventListener("pointerout",(()=>{Ut({type:"outside"})}))},onIdleToDragging:at(((t,n)=>{const r=n.target;r.style.pointerEvents="none";const i=document.querySelector("corejam-menu");return n.composedPath().includes(i)&&(r.style.zIndex="1000",r.style.position="fixed"),{draggedElementInstance:r,px:n.clientX,py:n.clientY}})),onDraggingToIdle:at((t=>{const n=document.querySelectorAll("corejam-canvas .drop *"),r=document.querySelector(".drop");return $t(r),n.forEach((t=>$t(t))),t.draggedElementInstance.style.removeProperty("pointer-events"),t.draggedElementInstance.style.removeProperty("zIndex"),t.draggedElementInstance.style.removeProperty("position"),t.draggedElementInstance.style.removeProperty("transform"),{draggedElementInstance:null,dx:0,dy:0,px:0,py:0}})),dragging:()=>{const t=document.querySelectorAll("corejam-canvas .drop *"),n=document.querySelector(".drop");Vt(n),t.forEach(Vt)},highlightTargets:(t,n)=>{const r=n.target,i=document.querySelector("corejam-menu");var e;n.composedPath().includes(i)||(e=r).localName.includes("corejam")&&!e.localName.includes("type")&&(e.style.background="var(--cj-colors-blue-300)")},removeHighlightPossibleTarget:(t,n)=>{var r;["corejame-type","span"].includes((r=n.target).localName)||(r.style.background="var(--cj-colors-blue-100)")},dropItem:(t,n)=>{const r=n.target;if(t.draggedElementInstance.style.removeProperty("pointer-events"),t.draggedElementInstance.style.removeProperty("zIndex"),t.draggedElementInstance.style.removeProperty("position"),t.draggedElementInstance.style.removeProperty("transform"),"inCanvas"in t.draggedElementInstance.dataset){r.appendChild(t.draggedElementInstance);const n=new CustomEvent("corejam:canvas:change");document.dispatchEvent(n)}else{const n=(t=>{const n=JSON.parse(t.dataset.cmp),r=document.createElement(n.component);return r.setAttribute("key",n.component+JSON.stringify(n.props)),Object.keys(n.props).forEach((t=>r.setAttribute(t,n.props[t]))),n.component.includes("type")&&(r.innerText=n.initialContent||"Lorem"),r.dataset.draggable=!0,r.dataset.inCanvas=!0,r})(t.draggedElementInstance);r.append(n);const i=new CustomEvent("corejam:canvas:change");document.dispatchEvent(i)}},mousemove:at(((t,n)=>({dx:n.clientX-t.px,dy:n.clientY-t.py})))},guards:{isDraggable:(t,n)=>"draggable"in n.target.dataset,isOutsideMenu:(t,n)=>{const r=document.querySelector("corejam-menu");return!n.composedPath().includes(r)}}},Rt="function"==typeof Lt.context?Lt.context():Lt.context,new Ct(Lt,Bt,Rt));var Lt,Bt,Rt;const{state:qt}=i({machine:null}),Gt=Ft(zt).onTransition((t=>{qt.machine||(qt.machine=t),t.changed&&(qt.machine=t,document.body.dataset.state=t.toStrings().join(" "),t.context.draggedElementInstance&&requestAnimationFrame((()=>{t.context.draggedElementInstance.style.transform=`translate(\n              ${t.context.dx}px,\n              ${t.context.dy}px)`})))})).start(),Kt=class{constructor(n){t(this,n),this.demoDraggers=[{id:"Row",component:"corejam-box",label:"Row",props:{flex:!0,h:"100px"}},{id:"1/2Box",component:"corejam-box",label:"Half Box",props:{w:6,h:"100px"}},{id:"Headline",component:"corejam-type",label:"Headline",props:{as:"h1",weight:"black",color:"blue-600"},initialContent:"Headline"},{id:"Sub headline",component:"corejam-type",label:"Sub Headline",props:{as:"h3",weight:"black",color:"blue-300"},initialContent:"Sub Headline"},{id:"Paragrap",component:"corejam-type",label:"Paragraph",props:{as:"p"},initialContent:"Lorem Greenum"}],this.draggers=[],this.demo=!0}componentDidLoad(){this.demo&&(this.draggers=[...this.draggers,...this.demoDraggers]),Gt.start()}addDragger(t){t.detail&&(this.draggers=[...this.draggers,t.detail])}render(){return n(r,null,n("corejam-box",{flex:!0,direction:"col",p:4,class:"draggers"},this.draggers.map((t=>{const r=t.component;return n("corejam-box",{h:"25px"},n("corejam-box",{py:2,"data-cy":`dragger-${t.label.toLowerCase()}`,"data-cmp":JSON.stringify(t),"data-draggable":!0},n("div",{style:{display:"none"}},n(r,Object.assign({},t.props),t.initialContent)),t.label))}))))}};export{Kt as corejam_builder}