module.exports=function(t){var e={};function n(i){if(e[i])return e[i].exports;var o=e[i]={i:i,l:!1,exports:{}};return t[i].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:i})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=15)}([function(t,e){t.exports=require("react")},function(t,e){t.exports=require("react-bootstrap")},function(t,e){t.exports=require("events")},function(t,e){t.exports=require("react-draggable")},function(t,e){t.exports=require("graph-diagram")},function(t,e){t.exports=require("path")},function(t,e){t.exports=require("jsonfile")},function(t,e){t.exports=require("react-password-mask")},function(t,e){t.exports=require("request")},function(t,e){t.exports=require("fs")},function(t,e){t.exports=require("jsonic")},function(t,e){t.exports=require("electron")},function(t,e){t.exports=require("react-list")},function(t,e){t.exports=require("osenv")},function(t,e){t.exports=require("ensureDir")},function(t,e,n){t.exports=n(16)},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i=n(0),o=n(17),a=n(1),s=n(3),r=n.n(s);var l=n(18),h=n(19),c=n(20),d=n(21).toString("base64"),u=l.format(".titlebar {\n\tpadding: 0 3px;\n\tbackground-color: #f6f6f6;\n}\n\n.titlebar.webkit-draggable {\n\t-webkit-app-region: drag;\n}\n\n.titlebar-stoplight {\n\tfloat: left;\n}\n\n.titlebar:after,\n.titlebar-stoplight:after {\n\tcontent: ' ';\n\tdisplay: table;\n\tclear: both;\n}\n\n.titlebar-stoplight:hover .titlebar-close {\n\tbackground-position: -26px 0;\n}\n\n.titlebar-stoplight:hover .titlebar-minimize {\n\tbackground-position: 0 0;\n}\n\n.titlebar-stoplight:hover .titlebar-fullscreen {\n\tbackground-position: -13px 0;\n}\n\n.titlebar.alt .titlebar-stoplight:hover .titlebar-close {\n\tbackground-position: -104px 0;\n}\n\n.titlebar.alt .titlebar-stoplight:hover .titlebar-minimize {\n\tbackground-position: -78px 0;\n}\n\n.titlebar.alt .titlebar-stoplight:hover .titlebar-fullscreen {\n\tbackground-position: -91px 0;\n}\n\n.titlebar-close,\n.titlebar-minimize,\n.titlebar-fullscreen {\n\tfloat: left;\n\tmargin: 6px 4px;\n\tbackground-repeat: no-repeat;\n\tbackground-image: url(%s);\n\tbackground-size: auto 12px;\n\twidth: 12px;\n\theight: 12px;\n\tborder-radius: 6px;\n}\n\n.titlebar.webkit-draggable .titlebar-close,\n.titlebar.webkit-draggable .titlebar-minimize,\n.titlebar.webkit-draggable .titlebar-fullscreen {\n\t-webkit-app-region: no-drag;\n}\n\n.titlebar-close {\n\tposition: relative;\n\tmargin-left: 6px;\n\tbackground-position: -65px 0;\n}\n\n.titlebar-fullscreen {\n\tposition: relative;\n\tbackground-position: -52px 0;\n}\n\n.titlebar-minimize {\n\tposition: relative;\n\tbackground-position: -39px 0;\n}\n\n.titlebar-close:active::after,\n.titlebar-minimize:active::after,\n.titlebar-fullscreen:active::after {\n\tdisplay: block;\n\tposition: absolute;\n\ttop: 0;\n\tbottom: 0;\n\tleft: 0;\n\tright: 0;\n\tcontent: \"\";\n\tbackground: rgba(0, 0, 0, .25);\n\tborder-radius: 100%;\n}\n",d),p=18;class m extends i.Component{constructor(t){super(t),this._keyDownHandler=this.handleKeyDown.bind(this),this._keyUpHandler=this.handleKeyUp.bind(this)}componentWillMount(){this.setState({altDown:!1,draggable:!0})}componentWillReceiveProps(t){if(t.draggable)try{this.setState({draggable:t.draggable},()=>{})}catch(t){console.log(t)}}componentDidMount(){document.body.addEventListener("keydown",this._keyDownHandler),document.body.addEventListener("keyup",this._keyUpHandler)}componentWillUnMount(){document.body.removeEventListener("keydown",this._keyDownHandler),document.body.removeEventListener("keyup",this._keyUpHandler)}handleKeyDown(t){t.keyCode===p&&this.setState({altDown:!0})}handleKeyUp(t){t.keyCode===p&&this.setState({altDown:!1})}handleMaximize(t){this.state.altDown?this.props.handleMaximize(t):this.props.handleFullScreen(t)}handleNop(t){t.preventDefault(),t.stopPropagation()}render(){var t=c("handle","titlebar",{"webkit-draggable":this.state.draggable,alt:this.state.altDown});return h("titlebar",u),i.createElement("div",{className:t,id:"titlebar",onClick:this.props.handleClick},i.createElement("div",{className:"titlebar-stoplight"},i.createElement("div",{onDoubleClick:this.handleNop,onClick:this.props.handleClose,className:"titlebar-close"}),i.createElement("div",{onDoubleClick:this.handleNop,onClick:this.props.handleMinimize,className:"titlebar-minimize"}),i.createElement("div",{onDoubleClick:this.handleNop,onClick:this.handleMaximize.bind(this),className:"titlebar-fullscreen"})),this.props.children)}}var g=n(22),f=n.n(g);const v=n(7);class b extends i.Component{constructor(t){super(t)}componentWillMount(){this.setState({port:this.props.appInfo.port,clientId:this.props.appInfo.clientId,clientSecret:this.props.appInfo.clientSecret,nluDefault:this.props.appInfo.nluDefault,nluLUIS_endpoint:this.props.appInfo.nluLUIS_endpoint,nluLUIS_appId:this.props.appInfo.nluLUIS_appId,nluLUIS_subscriptionKey:this.props.appInfo.nluLUIS_subscriptionKey,nluDialogflow_clientToken:this.props.appInfo.nluDialogflow_clientToken,nluDialogflow_projectId:this.props.appInfo.nluDialogflow_projectId,nluDialogflow_privateKey:this.props.appInfo.nluDialogflow_privateKey,nluDialogflow_clientEmail:this.props.appInfo.nluDialogflow_clientEmail,neo4j_url:this.props.appInfo.neo4j_url,neo4j_user:this.props.appInfo.neo4j_user,neo4j_password:this.props.appInfo.neo4j_password})}componentDidMount(){this.props.model.addPanelWithId(this.props.id)}handleInputChange(t){let e=t.nativeEvent;switch(console.log(`handleInputChange: ${e.target.name} ${e.target.value}`,this.state),e.target.name){case"port":this.setState(t=>(this.props.appInfo.port=e.target.value,{port:e.target.value}));break;case"clientId":this.setState(t=>(this.props.appInfo.clientId=e.target.value,{clientId:e.target.value}));break;case"clientSecret":this.setState(t=>(this.props.appInfo.clientSecret=e.target.value,{clientSecret:e.target.value}));break;case"nluLUIS_endpoint":this.setState(t=>(this.props.appInfo.nluLUIS_endpoint=e.target.value,{nluLUIS_endpoint:e.target.value}));break;case"nluLUIS_appId":this.setState(t=>(this.props.appInfo.nluLUIS_appId=e.target.value,{nluLUIS_appId:e.target.value}));break;case"nluLUIS_subscriptionKey":this.setState(t=>(this.props.appInfo.nluLUIS_subscriptionKey=e.target.value,{nluLUIS_subscriptionKey:e.target.value}));break;case"nluDialogflow_clientToken":this.setState(t=>(this.props.appInfo.nluDialogflow_clientToken=e.target.value,{nluDialogflow_clientToken:e.target.value}));break;case"nluDialogflow_projectId":this.setState(t=>(this.props.appInfo.nluDialogflow_projectId=e.target.value,{nluDialogflow_clientToken:e.target.value}));break;case"nluDialogflow_privateKey":this.setState(t=>(this.props.appInfo.nluDialogflow_privateKey=e.target.value,{nluDialogflow_clientToken:e.target.value}));break;case"nluDialogflow_clientEmail":this.setState(t=>(this.props.appInfo.nluDialogflow_clientEmail=e.target.value,{nluDialogflow_clientToken:e.target.value}));break;case"neo4j_url":this.setState(t=>(this.props.appInfo.neo4j_url=e.target.value,{neo4j_url:e.target.value}));break;case"neo4j_user":this.setState(t=>(this.props.appInfo.neo4j_user=e.target.value,{neo4j_user:e.target.value}));break;case"neo4j_password":this.setState(t=>(this.props.appInfo.neo4j_password=e.target.value,{neo4j_password:e.target.value}))}}handleNluDefaultChange(t){this.setState(e=>(this.props.appInfo.nluDefault=t.value,{nluDefault:t.value}))}handleClick(t){this.props.model.bringPanelToFront(this.props.id)}handleClose(t){this.props.onClosePanel(this.props.id)}handleMinimize(t){console.log("minimize")}handleMaximize(t){console.log("maximize")}handleFullScreen(t){console.log("fullscreen")}render(){return i.createElement(r.a,{handle:".handle"},i.createElement("div",{className:"commander-panel well",id:"appInfoPanel",ref:"appInfoPanel"},i.createElement(m,{draggable:!0,handleClick:this.handleClick.bind(this),handleClose:this.handleClose.bind(this),handleMinimize:this.handleMinimize.bind(this),handleMaximize:this.handleMaximize.bind(this),handleFullScreen:this.handleFullScreen.bind(this)}),i.createElement("h4",{className:"pull-left handle",style:{marginBottom:20}},"RoboCommander Info"),i.createElement("div",{className:"clearfix"}),i.createElement(a.Table,{striped:!0,bordered:!0,condensed:!0,hover:!0,style:{width:900}},i.createElement("tbody",null,i.createElement("tr",null,i.createElement("td",null,"port:"),i.createElement("td",null,i.createElement("input",{name:"port",value:this.state.port,onChange:this.handleInputChange.bind(this),style:{width:300}}))),i.createElement("tr",null,i.createElement("td",null,"clientId:"),i.createElement("td",null,i.createElement(v,{id:"password",name:"clientId",value:this.state.clientId,onChange:this.handleInputChange.bind(this),style:{width:300}}))),i.createElement("tr",null,i.createElement("td",null,"clientSecret:"),i.createElement("td",null,i.createElement(v,{id:"password",name:"clientSecret",value:this.state.clientSecret,onChange:this.handleInputChange.bind(this),style:{width:300}}))),i.createElement("tr",null,i.createElement("td",null,"nluDefault:"),i.createElement("td",null,i.createElement(f.a,{name:"nluDefault",value:this.state.nluDefault,options:[{value:"none",label:"none"},{value:"luis",label:"LUIS"},{value:"dialogflow",label:"Dialogflow"}],onChange:this.handleNluDefaultChange.bind(this),style:{width:300}}))),i.createElement("tr",null,i.createElement("td",null,"nluLUIS_endpoint:"),i.createElement("td",null,i.createElement("input",{name:"nluLUIS_endpoint",value:this.state.nluLUIS_endpoint,onChange:this.handleInputChange.bind(this),style:{width:675}}))),i.createElement("tr",null,i.createElement("td",null,"nluLUIS_appId:"),i.createElement("td",null,i.createElement(v,{id:"password",name:"nluLUIS_appId",value:this.state.nluLUIS_appId,onChange:this.handleInputChange.bind(this),style:{width:300}}))),i.createElement("tr",null,i.createElement("td",null,"nluLUIS_subscriptionKey:"),i.createElement("td",null,i.createElement(v,{id:"password",name:"nluLUIS_subscriptionKey",value:this.state.nluLUIS_subscriptionKey,onChange:this.handleInputChange.bind(this),style:{width:300}}))),i.createElement("tr",null,i.createElement("td",null,"nluDialogflow_clientToken:"),i.createElement("td",null,i.createElement(v,{id:"password",name:"nluDialogflow_clientToken",value:this.state.nluDialogflow_clientToken,onChange:this.handleInputChange.bind(this),style:{width:300}}))),i.createElement("tr",null,i.createElement("td",null,"nluDialogflow_projectId:"),i.createElement("td",null,i.createElement(v,{id:"password",name:"nluDialogflow_projectId",value:this.state.nluDialogflow_projectId,onChange:this.handleInputChange.bind(this),style:{width:300}}))),i.createElement("tr",null,i.createElement("td",null,"nluDialogflow_privateKey:"),i.createElement("td",null,i.createElement(v,{id:"password",name:"nluDialogflow_privateKey",value:this.state.nluDialogflow_privateKey,onChange:this.handleInputChange.bind(this),style:{width:300}}))),i.createElement("tr",null,i.createElement("td",null,"nluDialogflow_clientEmail:"),i.createElement("td",null,i.createElement(v,{id:"password",name:"nluDialogflow_clientEmail",value:this.state.nluDialogflow_clientEmail,onChange:this.handleInputChange.bind(this),style:{width:300}}))),i.createElement("tr",null,i.createElement("td",null,"neo4j_url:"),i.createElement("td",null,i.createElement("input",{name:"neo4j_url",value:this.state.neo4j_url,onChange:this.handleInputChange.bind(this),style:{width:300}}))),i.createElement("tr",null,i.createElement("td",null,"neo4j_user:"),i.createElement("td",null,i.createElement("input",{name:"neo4j_user",value:this.state.neo4j_user,onChange:this.handleInputChange.bind(this),style:{width:300}}))),i.createElement("tr",null,i.createElement("td",null,"neo4j_password:"),i.createElement("td",null,i.createElement(v,{id:"password",name:"neo4j_password",value:this.state.neo4j_password,onChange:this.handleInputChange.bind(this),style:{width:300}})))))))}}var y=n(2);class w{constructor(t,e,n){this.name="",this.type="",this.initWithData({name:t||"",type:e||"",data:n})}initWithData(t){this.name=t.name,this.type=t.type,this.data=t.data}get json(){return{name:this.name,type:this.type,data:this.data}}}class S{constructor(){}}const k=n(8),_=n(23);class M extends S{constructor(){super(),this.endpoint="",this.luisAppId="",this.subscriptionKey="",this._config={}}set config(t){t&&t.nluLUIS_endpoint&&t.nluLUIS_appId&&t.nluLUIS_subscriptionKey?(this._config=t,this.endpoint=this._config.nluLUIS_endpoint,this.luisAppId=this._config.nluLUIS_appId,this.subscriptionKey=this._config.nluLUIS_subscriptionKey):console.log("LUISController: set config: error: incomplete config:",t)}call(t){let e=this.endpoint,n=this.luisAppId,i={"subscription-key":this.subscriptionKey,timezoneOffset:"0",verbose:!0,q:t},o=e+n+"?"+_.stringify(i);return new Promise((t,e)=>{k(o,(n,i,o)=>{if(n)console.log("LUISController: call: error:",i,n),e(n);else{console.log("LUISController: call:",i,n);let e=JSON.parse(o);t(e)}})})}getEntitiesWithResponse(t){let e={user:"Someone",userOriginal:"Someone",thing:"that",thingOriginal:"that"};return t.entities.forEach(t=>{e[`${t.type}Original`]=t.entity,t.resolution&&t.resolution.values&&(e[`${t.type}`]=t.resolution.values[0])}),e}getIntentAndEntities(t,e,n,i){return new Promise((e,n)=>{this.call(t).then(t=>{let n={intent:"",entities:void 0};t&&t.topScoringIntent&&(n={intent:t.topScoringIntent.intent,entities:this.getEntitiesWithResponse(t)}),e(n)}).catch(t=>{n(t)})})}}const C=n(8);class E extends S{constructor(){super(),this.apiAuthorization="",this._config={}}set config(t){t&&t.nluDialogflow_clientToken?(this._config=t,this.apiAuthorization=`Bearer ${this._config.nluDialogflow_clientToken}`):console.log("DialogflowControllerV1: set config: error: incomplete config:",t)}call(t,e,n,i){let o={query:t,lang:"en",sessionId:i,location:{latitude:Number("42.361145"),longitude:Number("-71.057083")},timezone:"America/New_York"};return n&&(o.contexts=[n]),new Promise((t,e)=>{C.post({headers:{"Content-Type":"application/json; charset=utf-8",Authorization:`${this.apiAuthorization}`},url:"https://api.api.ai/v1/query?v=20150910",body:JSON.stringify(o)},(n,i,o)=>{if(n)e(n);else{let e=JSON.parse(o);t(e)}})})}getEntitiesWithResponse(t){let e,n={user:"Someone",userOriginal:"Someone",thing:"that",thingOriginal:"that"},i=t.result;return i&&i.contexts&&i.contexts[0]?(e=i.contexts[0].parameters)&&(n.user=e.user||n.user,n.userOriginal=e["user.original"]||n.userOriginal,n.thing=e.thing||n.thing,n.thingOriginal=e["thing.original"]||n.thingOriginal):i&&i.parameters&&(n.thing=i.parameters.thing||n.thing,n.thingOriginal=i.parameters.thing||n.thingOriginal),n}getIntentAndEntities(t,e,n,i){return new Promise((o,a)=>{this.call(t,e,n,i).then(t=>{let e={intent:t.result.metadata.intentName,entities:this.getEntitiesWithResponse(t)};o(e)}).catch(t=>{a(t)})})}}class x{constructor(t){this.neo4j=t,this.nodes=new Map,this.relationships=new Map}isLink(t){return t.start&&t.end}isNode(t){return!this.isLink(t)}parse(t){let e;for(this.nodes=new Map,this.relationships=new Map,e=0;e{let o=this.driver.session();o.run(t,e).then(function(t){o.close(),n(t)}).catch(function(t){i(t)})})}getCypherAsD3(t,e){return new Promise((n,i)=>{this.call(t,e).then(t=>{n(I.data(t,N))}).catch(t=>{i(t)})})}getNodesAndRelationships(t=25){return new Promise((e,n)=>{let i=`\n MATCH (n)-[r]-(p), (q) return n,r,p, q limit ${t}\n `;this.call(i).then(t=>{e(I.data(t,N))}).catch(t=>{n(t)})})}getNodesWithPropertyAndValue(t,e){return new Promise((n,i)=>{let o=`\n MATCH (n {${t}: "${e}"})-[r]-(p)\n return n,r,p\n `;this.call(o).then(t=>{n(I.data(t,N))}).catch(t=>{i(t)})})}test(){this.call("MATCH (n) return n LIMIT 10").then(t=>{console.log(t)}).catch(t=>{console.log(t)})}}class D{constructor(t){this.nodeMap=new Map,this.linkMap=new Map,this.events=[],t.nodes.forEach(t=>{this.nodeMap.set(t.id,t)}),t.links.forEach(t=>{this.linkMap.set(t.id,t);let e=this.nodeMap.get(t.startNode),n=this.nodeMap.get(t.endNode),i={robot:e.properties.name,time:t.properties.time,action:t.type,intent:"",loopMember:t.properties.user,summary:""};switch("Intent"==n.labels[0]&&(i.intent=n.properties.name),i.intent){case"launchJoke":i.summary=`I told a joke to ${i.loopMember}`;break;case"launchClock":i.summary=`I told ${i.loopMember} the time`}this.events.push(i)})}}class A{constructor(){}static get Instance(){return this._instance||(this._instance=new this)}connect(t,e=!1){console.log("PersistenceManager: connect: ",t),this.appInfo=t,this.appInfo&&this.appInfo.neo4j_url&&(!this.neo4jController||e)&&(this.graphConnection={type:"neo4j",url:this.appInfo.neo4j_url,user:this.appInfo.neo4j_user,password:this.appInfo.neo4j_password},console.log("PersistenceManager: connect: instantiating Neo4jController:",this.graphConnection),this.neo4jController=new T(this.graphConnection))}persistLaunchIntent(t,e,n,i){let o=`MERGE (i:Intent {name: "${n}"})\nWITH i MERGE (n:Robot {name: "${t}"})\nWITH i, n MERGE (n)-[r:LAUNCHED {robot: "${t}", user: "${e}", time: "${(new Date).toLocaleString()}", launchId: "${i}"}]->(i) return n, i, r\n`,a={};this.neo4jController&&this.neo4jController.call(o,a).then(t=>{console.log("PersistenceManager: persistLaunchIntent: ",t,o)}).catch(t=>{console.log("PersistenceManager: persistLaunchIntent: err: ",t,o)})}getActivity(t){return new Promise((e,n)=>{let i=`MATCH (n:Robot {name: "${t}"})-[r:LAUNCHED]->(i:Intent) return n,r,i`,o={};this.neo4jController&&this.neo4jController.getCypherAsD3(i,o).then(t=>{console.log("PersistenceManager: getActivity: ",t);let e=new D(t);console.log(e.events)}).catch(t=>{console.log("PersistenceManager: getActivity: err: ")})})}persistJoke(t,e,n){let i=`MERGE (j:Joke {id: "${e.id}", name: "${e.name}"})\nWITH j MERGE (n:Robot {name: "${t.name}"})\nWITH j, n MERGE (n)-[r:TOLD {robot: "${t.name}", launchId: "${n}"}]->(j) return n, j, r\n`,o={};this.neo4jController&&this.neo4jController.call(i,o).then(t=>{console.log("PersistenceManager: persistJoke: ",t,i)}).catch(t=>{console.log("PersistenceManager: persistJoke: err: ",t,i)})}persistUserLikesThing(t,e,n,i){let o=`MERGE (e:Entity {name: "${e}"})\nWITH e MERGE (user:User {name: "${i}"})\nWITH e, user MERGE (user)-[r:LIKES {robot: "${t.name}", launchId: "${n}"}]->(e) return user, e, r\n`,a={};this.neo4jController&&this.neo4jController.call(o,a).then(t=>{console.log("PersistenceManager: persistUserLikesThing: ",t,o)}).catch(t=>{console.log("PersistenceManager: persistUserLikesThing: err: ",t,o)})}}class R{constructor(t,e,n){this.launchIntent="",this.running=!1,this.robot=t,this.id=e,this.launchIntent=n}}class P extends R{constructor(t){super(t,"JokeSkill","launchJoke"),this.jokeMap=new Map,this.jokeIterator=this.jokeMap.values(),console.log(`JokeSkill: constructor: ${t.serialName}`),this.initJokes()}initJokes(){[{id:"001",name:"sleevies",prompt:"Where does the General keep his armies? In his sleevies!"},{id:"002",name:"chicken",prompt:"Why did the chicken cross the road? To get to the other side."},{id:"003",name:"elephant",prompt:"You know why you never see elephants hiding up in trees? Because they’re really good at it."},{id:"004",name:"paint",prompt:"What is red and smells like blue paint? Red paint."}].forEach(t=>{this.jokeMap.set(t.id,t)}),this.jokeIterator=this.jokeMap.values()}launch(t){if(this.robot){console.log(`JokeSkill: launch: ${this.robot.serialName}`);let e=this.jokeIterator.next().value;e||(this.jokeIterator=this.jokeMap.values(),e=this.jokeIterator.next().value);let n=e.prompt;if(this.robot.requester){this.robot.requester.expression.say(n).complete.then(()=>{if(this.running=!1,this.robot){let n="na";t&&t.launchId&&(n=t.launchId),A.Instance.persistJoke(this.robot,e,n)}}).catch(t=>{this.robot&&this.robot.updateRobotStatusMessages(JSON.stringify(t,null,2))})}}else console.log("JokeSkill: launch: error: robot is undefined")}tick(t,e){}}class L extends R{constructor(t,e){super(void 0,t,e),this.hubMap=new Map}addHub(t){this.hubMap.set(t.robotSerialName,t)}getShuffledArrayOfHubs(){return this.shuffleInPlace(Array.from(this.hubMap.values()))}shuffleInPlace(t){if(t.length<=1)return t;for(let e=0;e0){let e=new Date,n=e.getHours();n>12&&(n-=12);let i=e.getMinutes(),o=`The current time is ${n} ${i<10?"oh":""} ${i}`,a=t.shift();if(a&&a.robot){let t=a.robot;if(t.requester){t.requester.expression.say(o).complete.then(()=>{this.running=!1}).catch(e=>{t.updateRobotStatusMessages(JSON.stringify(e,null,2))})}}t.forEach(t=>{if(t&&t.robot){let e=t.robot;if(e.requester){let t=".Yeah, that's right.";e.requester.expression.say(t).complete.then(()=>{}).catch(t=>{e.updateRobotStatusMessages(JSON.stringify(t,null,2))})}}})}}}tick(t,e){}}class W{constructor(){this.ensembleSkillMap=new Map,this.addEnsembleSkill(new B("clockEnsemble","launchClock"))}static get Instance(){return this._instance||(this._instance=new this)}addEnsembleSkill(t){this.ensembleSkillMap.set(t.id,t)}getEnsembleSkillWithId(t){return this.ensembleSkillMap.get(t)}}class G extends R{constructor(t){super(t,"UserLikesSkill","launchUserLikes"),console.log(`UserLikesSkill: constructor: ${t.serialName}`)}launch(t){if(this.robot){console.log(`UserLikesSkill: launch: ${this.robot.serialName}`,t);let e,n="na",i=void 0,o=void 0,a=void 0;if(t&&t.launchId&&(n=t.launchId),t&&t.nluData&&(e=t.nluData),e&&e.parameters&&e.parameters.user&&(i=e.parameters.user),t&&e.parameters&&e.parameters.thing&&(o=e.parameters.thing),e&&e.parameters&&e.parameters.thingOriginal&&(a=e.parameters.thingOriginal),console.log(e,i,a),i&&a){let t=`OK. Thank you for telling me that ${i} likes ${a}}. I will try and remember that.`;if(this.robot.requester){this.robot.requester.expression.say(t).complete.then(()=>{this.running=!1,this.robot&&o&&n&&i?A.Instance.persistUserLikesThing(this.robot,o,n,i):console.log("UserLikesSkill: not enough info to call PersistenceManager")}).catch(t=>{this.robot&&this.robot.updateRobotStatusMessages(JSON.stringify(t,null,2))})}}}else console.log("UserLikesSkill: launch: error: robot is undefined")}tick(t,e){}}class z extends y.EventEmitter{constructor(t){super(),this.dialogflowController=new E,this.luisController=new M,this.sessionId=`robot_${Math.floor(1e4*Math.random())}`,this.robot=t,this.skillMap=new Map,this.launchIntentMap=new Map,A.Instance,this.startTickTime=(new Date).getTime(),this.previousTickTime=this.startTickTime,this.tickInterval=setInterval(this.tick.bind(this),1e3)}tick(){this.skillMap.forEach((t,e)=>{if(t&&t.running){let e=(new Date).getTime(),n=e-this.previousTickTime,i=e-this.startTickTime;t.tick(n,i)}})}onRobotConnected(){console.log(`HUB: onRobotConnected: ${this.robot.serialName}`,this.robot.requester),this.robot.requester&&this.robot.requester.listen&&(this.robot.appInfo&&(A.Instance.connect(this.robot.appInfo,!0),this.dialogflowController.config=this.robot.appInfo,this.luisController.config=this.robot.appInfo),this.hjToken=this.robot.requester.listen.subscribe.hotword(),this.hjToken.hotWordHeard.on(t=>{if(console.log("Heard Hey Jibo from speaker: ",t),this.robot.resetKeepAlive(),this.robot.requester){this.robot.requester.listen.start().update.on(e=>{if(console.log("Hey! I think i heard something: ",e),e){let n={speaker:t,listenResultEvent:e};this.onHotwordEvent(n)}})}})),this.registerSkill(new G(this.robot)),this.registerSkill(new P(this.robot));let t=W.Instance.getEnsembleSkillWithId("clockEnsemble");t&&(this.registerSkill(t),t.addHub(this))}registerSkill(t){console.log(`HUB: registerSkill: ${this.robot.serialName}`,t),this.skillMap.set(t.id,t),this.launchIntentMap.set(t.launchIntent,t)}removeSkill(t){this.skillMap.set(t.id,void 0),this.skillMap.delete(t.id)}onHotwordEvent(t){console.log(`HUB: onHotwordEvent: ${this.robot.serialName}`,t);let e=t.listenResultEvent.Speech;this.getLaunchIntent(e).then(t=>{if(t&&t.intent){let n=t.intent,i=`${(new Date).getTime()}`,o=this.launchIntentMap.get(n),a={nluType:t.nluType,asr:e,intent:n,launchId:i,nluData:t,userId:"someone"};console.log("HUB: onHotwordEvent: robotIntentData",a),o?(o.launch(a),o.running=!0,A.Instance.persistLaunchIntent(this.robot.name,"someone",n,i)):(console.log("HUB: onHotwordEvent: passing to robot onLaunchEvent: ",a),this.robot.onLaunchIntent(a))}}).catch(t=>{console.log("HUB: onHotwordEvent: error: ",t)})}getLaunchIntent(t){let e="none";return this.robot.appInfo&&this.robot.appInfo.nluDefault&&(e=this.robot.appInfo.nluDefault),this.getIntent(t,["launch"],e)}getIntent(t,e,n){return console.log(`HUB: getIntent: asr: ${t}, ${n}, contexts: `,e),new Promise((i,o)=>{let a=t,s=void 0;if("luis"==n?s=this.luisController:"dialogflow"==n&&(s=this.dialogflowController),s){let r="";e&&(r=e[0]),s.getIntentAndEntities(a,"en-US",r,this.sessionId).then(e=>{let o={nluType:n,asr:t,intent:e.intent,parameters:e.entities};console.log("HUB: getIntent: nluData",o),i(o)}).catch(t=>{o(t)})}else{let e={nluType:n,asr:t,intent:"",parameters:{}};console.log("HUB: getIntent: NO NLU DEFINED: nluData",e),i(e)}})}get robotSerialName(){return this.robot.serialName}}var U=n(26);const j=n(9),H=n(25);var F,O;!function(t){t.jibo="jibo",t.robokit="robokit"}(F||(F={})),function(t){t[t.LAUNCH=0]="LAUNCH",t[t.LISTEN=1]="LISTEN",t[t.ACTION_COMPLETE=2]="ACTION_COMPLETE"}(O||(O={}));class q extends y.EventEmitter{constructor(t){super(),this._type="jibo",this.name="",this.ip="",this.serialName="",this.email="",this.password="",this._number=0,this._muted=!1,t=t||{type:this.type,name:this.name,ip:this.ip,serialName:this.serialName,email:this.email,password:this.password},this.initWithData(t),this._connected=!1,this._targeted=!1,this._hub=new z(this),this._stateData={userId:"",userName:""}}get type(){return this._type}set type(t){this._type=t}initWithData(t){this.type=t.type||"jibo",this.name=t.name,this.ip=t.ip,this.serialName=t.serialName,this.email=t.email,this.password=t.password}updateRobotStatusMessages(t,e,n=!1){return e=e||`Robot<${this.name}>`,this.emit("statusMessage",{message:t,subsystem:e}),""}get number(){return this._number}set number(t){this._number=t}get json(){return{type:this.type,name:this.name,ip:this.ip,serialName:this.serialName,email:this.email,password:this.password}}updateUserData(t,e){this._stateData.userId=t,this._stateData.userName=e}get userData(){return{userId:this._stateData.userId,userName:this._stateData.userName}}updateStateData(t){this._stateData=Object.assign(this._stateData,t)}get stateData(){return this._stateData}set stateData(t){this._stateData=t}onLaunchIntent(t){let e={robot:this,type:O.LAUNCH,data:t};this.emit("robotIntent",e)}onListenIntent(t){let e={robot:this,type:O.LISTEN,data:t};this.emit("robotIntent",e)}sendCommand(t){if(this.resetKeepAlive(),this._robotConnection)switch(t.type){case"say":case"tts":if(!this._muted&&t.data&&(t.data.text||t.data.prompt)){let e=t.data.text||t.data.prompt;this._robotConnection.requester.expression.say(e).complete.then(()=>{let t={nluType:"none",asr:"",intent:"OK",launchId:void 0,nluData:void 0,userId:void 0},e={robot:this,type:O.ACTION_COMPLETE,data:t};this.emit("robotIntent",e)}).catch(t=>{console.log(t),this.updateRobotStatusMessages(JSON.stringify(t,null,2))})}break;case"ask":if(!this._muted&&t.data&&t.data.prompt){let e=t.data.prompt,n=t.data.contexts||[],i="none";this.appInfo&&this.appInfo.nluDefault&&(i=this.appInfo.nluDefault);let o=t.data.nluType||i;this._robotConnection.requester.expression.say(e).complete.then(()=>{if(this._robotConnection){this._robotConnection.requester.listen.start().update.on(t=>{if(console.log("Hey! I think i heard something: ",t),t&&"onListenResult"==t.Event&&t.Speech){let e={nluType:o,asr:t.Speech,intent:"",launchId:void 0,nluData:void 0,userId:void 0};"none"!=o?this._hub.getIntent(t.Speech,n,o).then(t=>{e.intent=t.intent,e.nluData=t,this.onListenIntent(e)}).catch(t=>{console.log(t)}):this.onListenIntent(e)}else this.updateRobotStatusMessages("Error: invalid listen result: ask")})}else this.updateRobotStatusMessages("Error starting listen for command: ask")}).catch(t=>{console.log(t),this.updateRobotStatusMessages(JSON.stringify(t,null,2))})}break;case"lookAtPosition":case"lookAt":if(!this._muted&&t.data&&(t.data.angle||t.data.vector)){let e;if(t.data.angle){let n={type:"ANGLE",angle:{theta:t.data.angle,psi:0},levelHead:!0};e=this._robotConnection.requester.expression.look(n).complete}else if(t.data.vector){let n={type:"POSITION",position:{x:t.data.vector[0],y:t.data.vector[1],z:t.data.vector[2]},levelHead:!0};e=this._robotConnection.requester.expression.look(n).complete}e&&(console.log("p:",e),e.then(()=>{}).catch(t=>{console.log(t),this.updateRobotStatusMessages(JSON.stringify(t,null,2))}))}break;case"attention":if(!this._muted&&t.data&&t.data.state){let e="OFF";switch(t.data.state){case"OFF":e="OFF";break;case"IDLE":e="IDLE"}this._robotConnection.requester.expression.setAttention(e).complete.then(()=>{}).catch(t=>{console.log(t),this.updateRobotStatusMessages(JSON.stringify(t,null,2))})}break;case"volume":if(!this._muted&&t.data&&t.data.volume){let e={mixer:Number(t.data.volume)};this._robotConnection.requester.config.set(e).complete.then(()=>{}).catch(t=>{console.log(t),this.updateRobotStatusMessages(JSON.stringify(t,null,2))})}break;case"mute":this.mute(!0);break;case"unmute":this.mute(!1);break;case"image":if(!this._muted&&t.data&&t.data.url){let e={Type:"Image",Name:t.data.name,Image:{name:t.data.name,src:t.data.url}};this._robotConnection.requester.display.swap(e).complete.then(()=>{}).catch(t=>{console.log(t),this.updateRobotStatusMessages(JSON.stringify(t,null,2))})}break;case"eye":if(!this._muted){let t={Type:"Eye",Name:"eye"};this._robotConnection.requester.display.swap(t).complete.then(()=>{}).catch(t=>{console.log(t),this.updateRobotStatusMessages(JSON.stringify(t,null,2))})}break;case"motion":!this._muted&&t.data&&t.data.state&&("ON"==t.data.state?this._motionTrackToken||(this._motionTrackToken=this._robotConnection.requester.perception.subscribe.motion(),this._motionTrackToken.update.on(t=>{console.log(t),console.log(`detectedMotion: update: count: ${t.length}:`,t)})):"OFF"==t.data.state&&this._motionTrackToken&&(this._motionTrackToken.cancel(),this._motionTrackToken=void 0));break;case"faces":!this._muted&&t.data&&t.data.state&&("ON"==t.data.state?(this._faceTrackToken=this._robotConnection.requester.perception.subscribe.face(),this._faceTrackToken.gained.on(t=>{if(t.length>0){var e=t[0].EntityID;console.log(`detectedFaces: gained: count: ${t.length}, id: ${e}`,t)}}),this._faceTrackToken.update.on(t=>{if(t.length>0){var e=t[0].EntityID;console.log(`detectedFaces: update: count: ${t.length}, id: ${e}`,t)}})):"OFF"==t.data.state&&this._faceTrackToken&&(this._faceTrackToken.cancel(),this._faceTrackToken=void 0));break;case"photo":console.log(this._robotConnection.requester),console.log(this._robotConnection.requester.media.capture),console.log(this._robotConnection.requester.media.capture.photoRequest);try{this._robotConnection.requester.media.capture.photo().complete.then(t=>{const e=t.URI;console.log(t),console.log("photo ready - uri: ",e);const i=j.createWriteStream("./PhotoIzHere.jpg");H.get({hostname:this.ip,port:8160,path:e},function(t){t.pipe(i),console.log("Your photo was saved as PhotoIzHere.jpg"),n(27).exec("open PhotoIzHere.jpg")})}).catch(t=>{console.log(t),this.updateRobotStatusMessages(JSON.stringify(t,null,2))})}catch(t){console.log(t)}}}keepAlive(){let t=new w("","say",{text:"."});this.sendCommand(t)}clearKeepAlive(){this._keepAliveInterval&&(clearInterval(this._keepAliveInterval),this._keepAliveInterval=void 0)}resetKeepAlive(){this.clearKeepAlive(),this._keepAliveInterval=setInterval(this.keepAlive.bind(this),6e4)}connect(t){console.log("connect:",t),this.appInfo=t,this.updateRobotStatusMessages("Attempting to connect..."),this._connected&&this.disconnect();let e={clientId:t.clientId,clientSecret:t.clientSecret,email:this.email,password:this.password};this.loginToAccount(e).then(t=>{console.log("connect: connected:",t),this.getRobot(t,this.serialName).then(t=>{console.log("connection:",t),this._robotConnection=t,this._robotConnection.on("status",t=>{console.info(`connection: status: ${t}`),this.updateRobotStatusMessages(t)}),this._robotConnection.connect().then(()=>{if(console.log("connect: Robot connected!"),this._robotConnection){const t=this._robotConnection;this.ip=t._ip,this._robotConnection.once("disconnect",()=>{console.info("connect: Robot disconnected."),this.updateRobotStatusMessages("connect: Robot disconnected."),this._connected=!1}),this._connected=!0,this._targeted=!0,this._hub.onRobotConnected(),this.emit("updateRobot",this),this.resetKeepAlive()}else console.log("connect: error: _robotConnection undefined."),this._connected=!1,this.updateRobotStatusMessages("connect: error: _robotConnection undefined.")}).catch(t=>{console.log("connect: connection.connect: error:",t),this.updateRobotStatusMessages(`connect: connection.connect: error: ${t}`)})}).catch(t=>{console.log("connect: getRobot: error:",t)})}).catch(t=>{console.log("connect: loginToAccount: error:",t)})}async loginToAccount(t){let e=new U.Account(t);return console.log("jiboConnect: Logging in... "),await e.login(),console.info("done"),e}async getRobot(t,e){process.stdout.write("Getting robot info... ");const n=await t.getRobots();console.info("done");const i=n.find(t=>t.serialName===e);if(!i)throw console.info("Robots on account:"),console.info(n.map(t=>t.serialName).join("\n")),new Error(`Robot ${e} not found`);return i}disconnect(){this.updateRobotStatusMessages("Attempting to disconnect...");try{this._connected&&this._robotConnection&&(this._robotConnection.disconnect(),this._robotConnection=void 0)}catch(t){console.log("Robot: disconnect: error:",t)}this._connected=!1,this.clearKeepAlive()}get connected(){return this._connected}get targeted(){return this._targeted}get requester(){let t;return this._robotConnection&&(t=this._robotConnection.requester),t}toggleTargeted(){this._targeted=!this._targeted}mute(t=!0){this._muted=t,console.log("muted: ",this._muted)}}n(28);const J=n(7);class V extends i.Component{constructor(t){super(t)}componentWillMount(){this.setState({showModalState:!1,type:"",name:"",password:""},()=>{})}componentWillReceiveProps(t){if(t.modalRobot){let e="";t.modalRobot.ip&&(e=t.modalRobot.ip),this.setState({showModalState:t.showModalProp,type:t.modalRobot.type,name:t.modalRobot.name,ip:e,aliasName:t.modalRobot.serialName,email:t.modalRobot.email,password:t.modalRobot.password},()=>{console.log(this.state.type,this.state.name,this.state.ip,this.state.aliasName,this.state.email)})}}componentDidUpdate(t,e){}close(t=!0){this.setState({showModalState:!1,type:"",name:"",ip:"",aliasName:"",email:"",password:""},()=>{this.props.onClose(t)})}save(){this.props.modalRobot.type=this.state.type,this.props.modalRobot.name=this.state.name,this.props.modalRobot.serialName=this.state.aliasName,this.props.modalRobot.email=this.state.email,this.props.modalRobot.password=this.state.password,this.props.modalRobot.ip=this.state.ip,this.close(!1)}onHide(){console.log("ModalRobotInfo: onHide")}handleInputChange(t){let e=t.nativeEvent;switch(e.target.name){case"name":this.setState({name:e.target.value});break;case"aliasName":this.setState({aliasName:e.target.value});break;case"email":this.setState({email:e.target.value});break;case"password":this.setState({password:e.target.value});break;case"ip":let t="";this.state.type==F.robokit&&(t=e.target.value),this.setState({ip:t})}}onMenuItemSelected(t){let e="";t==F.robokit&&(e=""),this.setState({type:t,ip:e})}renderRobotTypeItems(){let t=[];for(var e in F){let n=!1;e==this.state.type&&(n=!0),t.push(i.createElement(a.MenuItem,{active:n,key:e,eventKey:e,onSelect:this.onMenuItemSelected.bind(this,e)},e))}return t}renderRobotTypeSplitButton(){return i.createElement(a.SplitButton,{bsStyle:"default",title:this.state.type,key:"filename-splitbutton",id:"filename-splitbutton"},this.renderRobotTypeItems())}render(){return i.createElement("div",{className:"static-modal"},i.createElement(a.Modal,{show:this.state.showModalState,onHide:this.onHide.bind(this)},i.createElement(a.Modal.Header,null,i.createElement(a.Modal.Title,null,"Robot Info")),i.createElement(a.Modal.Body,null,i.createElement(a.Table,{striped:!0,bordered:!0,condensed:!0,hover:!0,style:{width:300}},i.createElement("tbody",null,i.createElement("tr",null,i.createElement("td",null,"type:"),i.createElement("td",null,this.renderRobotTypeSplitButton())),i.createElement("tr",null,i.createElement("td",null,"name:"),i.createElement("td",null,i.createElement("input",{name:"name",value:this.state.name,onChange:this.handleInputChange.bind(this),style:{width:300}}))),i.createElement("tr",null,i.createElement("td",null,"aliasName:"),i.createElement("td",null,i.createElement("input",{name:"aliasName",value:this.state.aliasName,onChange:this.handleInputChange.bind(this),style:{width:300}}))),i.createElement("tr",null,i.createElement("td",null,"email:"),i.createElement("td",null,i.createElement("input",{name:"email",value:this.state.email,onChange:this.handleInputChange.bind(this),style:{width:300}}))),i.createElement("tr",null,i.createElement("td",null,"password:"),i.createElement("td",null,i.createElement(J,{id:"password",name:"password",value:this.state.password,onChange:this.handleInputChange.bind(this),style:{width:300}}))),i.createElement("tr",null,i.createElement("td",null,"ip:"),i.createElement("td",null,i.createElement("textarea",{name:"ip",value:this.state.ip,onChange:this.handleInputChange.bind(this),style:{width:300,height:24}})))))),i.createElement(a.Modal.Footer,null,i.createElement(a.Button,{onClick:()=>this.close()},"Cancel"),i.createElement(a.Button,{bsStyle:"primary",onClick:this.save.bind(this)},"Save changes"))))}}const K="-----BEGIN CERTIFICATE-----\nMIIEjDCCAnQCAQEwDQYJKoZIhvcNAQELBQAwgYsxCzAJBgNVBAYTAlVTMQswCQYD\nVQQIDAJNQTETMBEGA1UEBwwKQmFybnN0YWJsZTESMBAGA1UECgwJd3dsaWIub3Jn\nMRAwDgYDVQQLDAdyb2Jva2l0MRMwEQYDVQQDDApyb2Jva2l0LmlvMR8wHQYJKoZI\nhvcNAQkBFhBhbmRyZXdAd3dsaWIub3JnMB4XDTE5MDMwNDE3NDkyNVoXDTIwMDMw\nMzE3NDkyNVowgYsxCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJNQTETMBEGA1UEBwwK\nQmFybnN0YWJsZTESMBAGA1UECgwJd3dsaWIub3JnMRAwDgYDVQQLDAdyb2Jva2l0\nMRMwEQYDVQQDDApyb2Jva2l0LmlvMR8wHQYJKoZIhvcNAQkBFhBhbmRyZXdAd3ds\naW4ub3JnMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuR+Hl9w9Do3o\nIl1ygduhAy+1jjiXUKdZ6Mnxm/3Z2Su0/A9Aj9xIS5OlV6BTrmY+bD6eRE5YUga0\nw8/gjq+9OBXOgYeXfSTE5hQCiaLgjDJy02PoiBM3WQA253WwFiTGqRQA5Vgu1oxy\nSKlG4jlwr9aZ/MAcho3b0RIbHy9IbEwFuN+YcRFv/D6FMNniAtpzQYLNcEeoS9VH\nyOXbKrrYTyjUFigMwBG1qQhbRJtTT5/ve6AS0XwX9IYtwXm27RetQqfORkaSiAvB\nqb4vyBHChaejHVTzYaZuVz5piXxI26IFf3Leop0ViUa5bQgUWmqmQQ4bl62mkI4J\n/Xduc4IE7wIDAQABMA0GCSqGSIb3DQEBCwUAA4ICAQBqEHEhhIThP9mf7wOD+nmy\nE2WSfMV7QrsvvG9rD09uT8rhq8mAQiQKgrzaMduV8pDutAXmaIb1e1EwKPbpAcz1\nXD/y+yeemJXphdHLOLTurLaNKgOWasUMAZELL1EO9kaZDX2D91WuY8GfFwmVfFdH\nRdxu+zHyUSwR7MTuT8SWmZMPV1e3k4pt5PU9xSexhPGkwA+S+EOC2vIkVE4HnJfZ\nwxPdstazRjhZw2s8iQyzvPOjVyB3bfIVZfHGRo/Sva0YA95yTJWvtJJGY3SvHdR/\ns/IZhi2ykKPLX5QSpeh/UzC90eceBxxRXPobAf4bokX0UpSp6ecCDqEBsl+TfO5C\nVgkmvGe8aKHbYOkcDW2LqmWE4E2MEd2aOhceL4a/Ac0hX6GDEHhVpYvBkq0glOTC\nxxVqZgQKqf2lOGplqMtAXx6a8WjcwyS/kquF3FO9BpASBFoiqL2W0n5VNUeOXbwp\nmIxHzP9p7DLUNtnN4pQCiZ1kjdp9S4JYCq9xK1sfELqAGhyAKz4YlYLHfp1z0AKl\nAv19m6q5rYvxq3WaqZOD+WP7CQP/xuf5ExIcCYEz3GZOHjFtgATf07G/730pwga1\ng+GaLtcVNpxKpWqivGay8i0ALgtb0gDMwu4EH8c3wVcpEOLzPoWkJNFMCAgmGIqZ\nxT8jZ6RHEUUU+BaH3LaAIw==\n-----END CERTIFICATE-----\n";class Y extends y.EventEmitter{constructor(){super(),this.complete=void 0}}class $ extends y.EventEmitter{constructor(t,e,n,i){super(),this.id=t,this.robotSerialName=i,this.type=e,this.data=n,this.status="OK",this.sendTime=0,this.receiptTime=0,this.commandReceivedTime=0,this.commandCompletedTime=0}getMessageDataToSend(){return this.sendTime=(new Date).getTime(),{id:this.id,type:this.type,data:this.data,sendTime:this.sendTime}}getMessageDataToLog(){return{id:this.id,type:this.type,status:this.status,sendTime:this.sendTime,commandReceivedTime:this.commandReceivedTime,commandCompletedTime:this.commandCompletedTime,receiptTime:this.receiptTime}}onReceipt(t){this.receiptTime=(new Date).getTime(),this.receiptPayload=t,this.commandReceivedTime=t.commandReceivedTime,this.commandCompletedTime=t.commandCompletedTime,this.emit("receipt",this)}destroy(){this.removeAllListeners(),this.data=null,this.receiptPayload=null}}class Q{static init(){Q.transactions=new Map}static getNextId(){return`${Q.lastId++}`}static createTransaction(t,e,n){let i=Q.getNextId(),o=new $(i,t,e,n);return Q.transactions.set(i,o),o}static receiveTransaction(t,e){let n=t.id,i=Q.transactions.get(n);return i&&(Q.transactions.delete(n),i.status=e,i.onReceipt(t)),i}static destroyTransaction(t){Q.transactions.delete(t.id),t.destroy()}}Q.lastId=0;const X=n(29),Z=n(30);class tt extends y.EventEmitter{constructor(t="",e=9696){super(),this.hostname=t||Z.address(),this.port=e,this.connectionString=`wss://${this.hostname}:${this.port}`,this.webSocket=void 0,this.robotSerialName=`robokit-${this.hostname}:${this.port}`,Q.init(),this.requester={expression:{say:t=>{const e=Q.createTransaction("tts",{prompt:t},this.robotSerialName);return this.sendTransactionMessageData(e.getMessageDataToSend())},blink:()=>{const t=Q.createTransaction("blink",{},this.robotSerialName);return this.sendTransactionMessageData(t.getMessageDataToSend())},lookAt:t=>{const e=Q.createTransaction("lookAt",t,this.robotSerialName);return this.sendTransactionMessageData(e.getMessageDataToSend())},ident:t=>{const e=Q.createTransaction("ident",t,this.robotSerialName);return this.sendTransactionMessageData(e.getMessageDataToSend())}}}}connect(){return new Promise((t,e)=>{this.startWebSocket(),t()})}disconnect(){}startWebSocket(){if(console.log(`startWebSocket: ${this.connectionString}`),this.webSocket){try{this.webSocket.close()}catch(t){console.log(t)}this.webSocket=null}try{let t=[K];this.webSocket=new X(this.connectionString,{ca:t,rejectUnauthorized:!1,checkServerIdentity:(t,e)=>{if(console.log("certificate.subject.CN:",e.subject.CN),"TBD"!==e.subject.CN)throw Error("Certificate CN doesn't match expected CN: TBD")}}),this.webSocket.on("error",t=>{this.emit("error",t),console.log("error:",t)}),this.webSocket.on("open",()=>{let t={status:"OK",connectionString:`${this.connectionString}`};this.sendHandshakeMessage(t),this.emit("connected")}),this.webSocket.on("message",(t,e)=>{let n;try{n=JSON.parse(t)}catch(t){console.log("websocket onMessage: JSON.parse: ",t),n=null}n&&(console.log("received json message: ",n),this.emit("message",n),n.type)}),this.webSocket.on("close",()=>{console.log("websocket client closed"),this.webSocket=void 0,this.emit("closed")})}catch(t){this.webSocket=void 0,console.log(t)}}sendTransactionMessageData(t){console.log("sendTransactionMessageData:",t);const e=new Y;t.client="robocommander";let n={type:"transaction",command:t};return e.complete=new Promise((t,e)=>{if(this.webSocket){let e=JSON.stringify(n);this.webSocket.send(e),t()}else e()}),e}sendHandshakeMessage(t){console.log("sendHandshakeMessage:",t);const e=new Y;let n={client:"robocommander",type:"handshake",payload:t,timestamp:(new Date).getTime()};return e.complete=new Promise((t,e)=>{if(this.webSocket){let e=JSON.stringify(n);this.webSocket.send(e),t()}else e()}),e}}class et extends q{constructor(t){(t=t||{type:F.robokit,name:"",ip:"",serialName:"",email:"",password:""}).type=F.robokit,super(t)}sendCommand(t){if(console.log("sendCommand:",t,this._robotConnection),this._robotConnection)switch(t.type){case"say":case"tts":let e=t.data.text||t.data.prompt;this._robotConnection.requester.expression.say(e);break;case"blink":this._robotConnection.requester.expression.blink();break;case"lookAt":this._robotConnection.requester.expression.lookAt(t.data);break;case"ident":this._robotConnection.requester.expression.ident(t.data)}}connect(t){console.log("RobokitRobot: connect:",t),this.appInfo=t,this.updateRobotStatusMessages("Attempting to connect..."),this._connected&&this.disconnect(),this._robotConnection=new tt,this._robotConnection.connect(),this._robotConnection.on("connected",()=>{console.log("RobokitRobot: connection: connected"),this.updateRobotStatusMessages("...connected."),this._connected=!0,this._targeted=!0,this._hub.onRobotConnected(),this.emit("updateRobot",this)}),this._robotConnection.on("message",t=>{}),this._robotConnection.on("error",t=>{console.log(t)}),this._robotConnection.on("closed",()=>{this._connected=!1,this._targeted=!1})}keepAlive(){console.log("keepAlive:")}}class nt extends i.Component{constructor(t){super(t),this.bsStyle="primary",this._updateRobotsHandler=this.onUpdateRobots.bind(this)}componentWillMount(){this.setState({showModal:!1,lastUpdateTime:(new Date).getTime(),statusMessages:"",addNewRobot:!1}),this.props.robots.on("updateRobots",this._updateRobotsHandler)}componentDidMount(){this.props.model.addPanelWithId(this.props.id)}componentWillUnmount(){this.props.robots.removeListener("updateRobots",this._updateRobotsHandler)}onUpdateRobots(t){this.setState({lastUpdateTime:(new Date).getTime(),statusMessages:this.props.robots.statusMessages})}handleClick(t){this.props.model.bringPanelToFront(this.props.id)}handleClose(t){this.props.onClosePanel(this.props.id)}handleMinimize(t){console.log("minimize")}handleMaximize(t){console.log("maximize")}handleFullScreen(t){console.log("fullscreen")}render(){return i.createElement(r.a,{handle:".handle"},i.createElement("div",{className:"commander-panel well",id:"robotsPanel"},i.createElement(m,{draggable:!0,handleClick:this.handleClick.bind(this),handleClose:this.handleClose.bind(this),handleMinimize:this.handleMinimize.bind(this),handleMaximize:this.handleMaximize.bind(this),handleFullScreen:this.handleFullScreen.bind(this)}),i.createElement("h4",{className:"pull-left handle",style:{marginBottom:20}},"Robot List"),i.createElement("div",{className:"clearfix"}),i.createElement(a.Table,{striped:!0,condensed:!0,hover:!0},i.createElement("tbody",null,i.createElement("tr",null,i.createElement("td",{style:{width:300}},i.createElement(a.ButtonGroup,{vertical:!0,style:{width:300}},i.createElement(V,{showModalProp:this.state.showModal,onClose:this.onCloseRobotModal.bind(this),modalRobot:this.state.modalRobot}),this.createRobotButtons()),i.createElement("div",{className:"clearfix"}),i.createElement(a.Button,{bsStyle:"info",key:"addRobot",style:{width:100},onClick:this.onAddRobot.bind(this)},"Add Robot")),i.createElement("td",null,i.createElement("textarea",{id:"statusMessages",name:"statusMessages",value:this.state.statusMessages,onChange:this.handleInputChange.bind(this),style:{maxHeight:300,minHeight:200,width:"100%"}}),i.createElement(a.Button,{bsStyle:"info",key:"clearMessages",style:{width:130},onClick:this.onClearMessages.bind(this)},"Clear Messages")))))))}handleInputChange(t){t.nativeEvent.target.name}onCloseRobotModal(t){if(!t&&this.state.addNewRobot&&this.state.modalRobot){const t=this.state.modalRobot;let e,n={type:t.type,name:t.name,ip:t.ip,serialName:t.serialName,email:t.email,password:t.password};e=this.state.modalRobot.type==F.robokit?new et(n):t,this.props.robots.addRobot(e)}this.setState({showModal:!1,addNewRobot:!1})}openRobotModal(t){this.setState({showModal:!0,modalRobot:t})}onButtonClicked(t,e){switch(console.log(`onButtonClicked: ${t.name}: ${e}`),e){case"select":t.connected?this.props.robots.disconnectRobot(t):this.props.robots.connectRobot(t,this.props.appInfo);break;case"edit":this.openRobotModal(t);break;case"delete":this.props.robots.removeRobot(t),this.setState({lastUpdateTime:(new Date).getTime()})}}onAddRobot(){let t=new q;this.setState({addNewRobot:!0}),this.openRobotModal(t)}onClearMessages(){this.props.robots.updateRobotsStatusMessages("","",!0)}createRobotButton(t){let e="default";return t.connected&&(e="primary"),i.createElement("div",{key:t.name},i.createElement(a.Button,{bsStyle:e,key:t.name+"_select",style:{width:150},onClick:this.onButtonClicked.bind(this,t,"select")},t.name),i.createElement(a.Button,{bsStyle:"info",key:t.name+"_edit",style:{width:80},onClick:this.onButtonClicked.bind(this,t,"edit")},"Edit"),i.createElement(a.Button,{bsStyle:"danger",key:t.name+"_delete",style:{width:40},onClick:this.onButtonClicked.bind(this,t,"delete")},"X"))}createRobotButtons(){return this.props.robots.robotList.map(this.createRobotButton.bind(this))}}var it=n(33);const ot=n(10);class at extends i.Component{constructor(t){super(t)}componentWillMount(){this.setState({showModalState:!1,name:""},()=>{})}componentWillReceiveProps(t){if(t.modalCommand)try{this.setState({showModalState:t.showModalProp,name:t.modalCommand.name,type:t.modalCommand.type,data:ot.stringify(t.modalCommand.data)},()=>{})}catch(t){console.log(t)}}componentDidUpdate(t,e){}close(){this.setState({showModalState:!1,name:"",type:"",data:{}},()=>{this.props.onClose(this.props.editMode)})}save(){console.log("ModalCommandInfo: save"),console.log(this.state);try{this.props.modalCommand.name=this.state.name,this.props.modalCommand.type=this.state.type,this.props.modalCommand.data=ot(this.state.data),console.log(this.props.modalCommand),this.close()}catch(t){console.log(t)}}onHide(){console.log("ModalCommandInfo: onHide")}handleInputChange(t){let e=t.nativeEvent;switch(e.target.name){case"name":this.setState({name:e.target.value});break;case"type":this.setState({type:e.target.value});break;case"data":this.setState({data:e.target.value})}}render(){return i.createElement("div",{className:"static-modal"},i.createElement(a.Modal,{show:this.state.showModalState,onHide:this.onHide.bind(this)},i.createElement(a.Modal.Header,null,i.createElement(a.Modal.Title,null,"Command Info")),i.createElement(a.Modal.Body,null,i.createElement(a.Table,{striped:!0,bordered:!0,condensed:!0,hover:!0,style:{width:300}},i.createElement("tbody",null,i.createElement("tr",null,i.createElement("td",null,"name:"),i.createElement("td",null,i.createElement("input",{name:"name",value:this.state.name,onChange:this.handleInputChange.bind(this),style:{width:300}}))),i.createElement("tr",null,i.createElement("td",null,"type:"),i.createElement("td",null,i.createElement("input",{name:"type",value:this.state.type,onChange:this.handleInputChange.bind(this),style:{width:300}}))),i.createElement("tr",null,i.createElement("td",null,"data:"),i.createElement("td",null,i.createElement("textarea",{name:"data",value:this.state.data,onChange:this.handleInputChange.bind(this),style:{width:300,height:150}})))))),i.createElement(a.Modal.Footer,null,i.createElement(a.Button,{onClick:this.close.bind(this)},"Cancel"),i.createElement(a.Button,{bsStyle:"primary",onClick:this.save.bind(this)},"Save"))))}}console.log(it);let st=n(34);class rt extends i.Component{constructor(t){super(t),this.commandButtons={},this.cycleRobots=!1,this.x=0,this.y=0,this.z=.5,this.angle=0,this.sendflag=!0,this.previousController10Value=0,this.previousControllerTime=0,this._updateRobotsHandler=this.onUpdateRobots.bind(this),console.log("Commands: constructor"),this.handleChange=this.handleChange.bind(this),this.handleSubmitTTS=this.handleSubmitTTS.bind(this),this.setupWebMidi()}setupWebMidi(){st.enable(t=>{t?console.log("WebMidi could not be enabled.",t):(console.log("WebMidi enabled!"),console.log(st.inputs),console.log(st.outputs),st.inputs.forEach(t=>{console.log(`Commands: Adding Midi Input: ${t.name}`),t.addListener("pitchbend","all",t=>{console.log("Pitch value: "+t.value)}),t.addListener("noteon","all",t=>{let e;switch(console.log("Received 'noteon' message ("+t.note.number+": "+t.note.name+t.note.octave+")."),t.note.number){case 49:e=new w("","tts",{text:"My name is Jibo."}),this.sendCommand(e);break;case 51:e=new w("","tts",{text:"So far I haven't met anyone exactly like me. But I don't get out much."}),this.sendCommand(e);break;case 54:e=new w("","tts",{text:" I love to dance"}),this.sendCommand(e);break;case 57:e=new w("","tts",{text:" I'm pretty scared of ghosts"}),this.sendCommand(e);break;case 48:e=new w("","tts",{text:"."}),this.sendCommand(e);break;case 50:e=new w("Left","lookAt",{vector:[0,1,.5]}),this.sendCommand(e);break;case 52:e=new w("Right","lookAt",{vector:[0,-1,.5]}),this.sendCommand(e);break;case 53:e=new w("Center","lookAt",{vector:[1,0,.5]}),this.sendCommand(e);break;case 55:e=new w("Back","lookAt",{vector:[-1,0,.5]}),this.sendCommand(e);break;case 60:e=new w("Left","lookAt",{angle:.5}),this.sendCommand(e);break;case 62:e=new w("Right","lookAt",{angle:-.5}),this.sendCommand(e);break;case 64:e=new w("Back","lookAt",{angle:3.14159}),this.sendCommand(e)}}),t.addListener("noteoff","all",t=>{}),t.addListener("keyaftertouch","all",t=>{console.log("Received 'keyaftertouch' message: ")}),t.addListener("controlchange","all",t=>{console.log("Received 'controlchange' message ("+t.controller.number+": "+t.channel+": "+t.value+").");let e=(new Date).getTime();if(e-this.previousControllerTime>200&&(this.previousControllerTime=e,10==t.controller.number)){if(Math.abs(this.previousController10Value-t.controller.number)>2){let e=new it.Vector3(0,0,1),n=new it.Vector3(1,0,.5),i=2*Math.PI*t.value/128,o=(new it.Quaternion).setFromAxisAngle(e,i),a=n.clone().applyQuaternion(o),s=[a.x,a.y,a.z];console.log("vector: ",s);let r=new w("","lookAtPosition",{vector:s});this.sendCommand(r)}this.previousController10Value=t.value}}),t.addListener("pitchbend","all",t=>{console.log("pitch: ",t)}),t.addListener("channelmode","all",t=>{console.log("Received 'channelmode' message: ")}),t.addListener("programchange","all",t=>{console.log("Received 'programchange' message: ",t)}),t.addListener("channelaftertouch","all",t=>{console.log("Received 'channelaftertouch' message: ")})}))})}componentWillMount(){this.setState({lastUpdateTime:(new Date).getTime(),value:"",commandList:this.props.model.romCommands.commandList,showModal:!1,editMode:"",deleteMode:!1,targetedRobots:this.props.model.robots.targetedRobots}),this.props.model.robots.on("updateRobots",this._updateRobotsHandler)}componentDidMount(){this.props.model.addPanelWithId(this.props.id)}componentWillUnmount(){this.props.model.robots.removeListener("updateRobots",this._updateRobotsHandler)}onUpdateRobots(t){console.log("Commands: onUpdateRobots"),this.setState({lastUpdateTime:(new Date).getTime()})}handleChange(t){let e=t.nativeEvent;this.setState({value:e.target.value})}handleSubmitTTS(t){let e=new w("","tts",{text:this.state.value});this.sendCommand(e),t.preventDefault()}sendCommandWithName(t){console.log("Commands: sendCommandWithName: ",t);let e=this.props.model.romCommands.getCommandWithName(t);e&&("edit"===this.state.editMode?(console.log(" editing"),this.openCommandModal(e)):this.state.deleteMode?(console.log(" deleting"),this.props.model.romCommands.removeCommand(e),this.setState({commandList:this.props.model.romCommands.commandList})):(console.log(" executing"),this.props.model.sendRomCommand(e),this.cycleRobots&&this.cycleTargetedRobots()))}sendCommand(t){console.log("Commands: sendCommand: ",t),this.props.model.sendRomCommand(t)}handleClick(t){this.props.model.bringPanelToFront(this.props.id)}handleClose(t){this.props.onClosePanel(this.props.id)}handleMinimize(t){console.log("minimize")}handleMaximize(t){console.log("maximize")}handleFullScreen(t){console.log("fullscreen")}render(){return this.commandButtons={},this.commandButtonsArray=[],this.props.model.romCommands.commandNames.forEach(t=>{let e=i.createElement(a.Button,{key:t,style:{width:150},onClick:this.sendCommandWithName.bind(this,t)},t);this.commandButtons[t]=e,this.commandButtonsArray.push(e)}),i.createElement(r.a,{handle:".handle"},i.createElement("div",{className:"commander-panel well",id:this.props.id},i.createElement(m,{draggable:!0,handleClick:this.handleClick.bind(this),handleClose:this.handleClose.bind(this),handleMinimize:this.handleMinimize.bind(this),handleMaximize:this.handleMaximize.bind(this),handleFullScreen:this.handleFullScreen.bind(this)}),i.createElement("h4",{className:"pull-left handle",style:{marginBottom:20}},"Commands"),i.createElement("div",{className:"clearfix"}),i.createElement(a.Table,{striped:!0,condensed:!0,hover:!0},i.createElement("tbody",null,i.createElement("tr",null,i.createElement("td",null,i.createElement(a.ButtonGroup,{vertical:!0,style:{width:180}},this.createRobotButtons())),i.createElement("td",{style:{width:10}}),i.createElement("td",{style:{verticalAlign:"top"}},i.createElement("form",{onSubmit:this.handleSubmitTTS},i.createElement("label",null,"TTS:"),i.createElement("input",{ref:"tts",type:"text",style:{width:600},value:this.state.value,onChange:this.handleChange}),i.createElement("input",{type:"submit",value:"Submit"})),i.createElement(a.ButtonGroup,{style:{width:600}},i.createElement(at,{showModalProp:this.state.showModal,onClose:this.onCloseCommandModal.bind(this),modalCommand:this.state.modalCommand,editMode:this.state.editMode}),this.commandButtonsArray),i.createElement("div",{className:"clearfix"}),i.createElement(a.Button,{bsStyle:"info",key:"addCommand",style:{width:150},onClick:this.onAddCommand.bind(this)},"Add Command"),i.createElement("input",{type:"radio",checked:!this.state.deleteMode&&"edit"!=this.state.editMode,name:"mode",value:"execute",onChange:this.handleModeChange.bind(this),style:{width:20}})," Execute Command",i.createElement("input",{type:"radio",checked:!this.state.deleteMode&&"edit"==this.state.editMode,name:"mode",value:"edit",onChange:this.handleModeChange.bind(this),style:{width:20}})," Edit Command",i.createElement("input",{type:"radio",checked:this.state.deleteMode,name:"mode",value:"delete",onChange:this.handleModeChange.bind(this),style:{width:20}})," Delete Command"))))))}handleModeChange(t){switch(t.nativeEvent.target.value){case"execute":this.setState({editMode:"",deleteMode:!1});break;case"edit":this.setState({editMode:"edit",deleteMode:!1});break;case"delete":this.setState({editMode:"",deleteMode:!0})}}handleCheckboxChange(t){this.cycleRobots=!this.cycleRobots}onAddCommand(){let t=new w;this.setState({editMode:"add"},()=>{this.openCommandModal(t)})}onCloseCommandModal(t){"add"===t&&this.state.modalCommand.name?this.props.model.romCommands.addCommand(this.state.modalCommand):"edit"===t&&this.state.modalCommand.name&&this.props.model.romCommands.updateCommandWithName(this.state.modalCommand.name,this.state.modalCommand),this.setState({showModal:!1})}openCommandModal(t){this.setState({showModal:!0,modalCommand:t})}cycleTargetedRobots(){}onRobotButtonClicked(t,e){switch(e){case"select":t.toggleTargeted(),this.setState({targetedRobots:this.props.model.robots.targetedRobots})}}createRobotButton(t){let e="default";return t.targeted&&(e="primary"),i.createElement(a.Button,{bsStyle:e,key:t.name+"_select",style:{width:150},onClick:this.onRobotButtonClicked.bind(this,t,"select")},t.name)}createRobotButtons(){return this.props.model.robots.connectedRobots.map(this.createRobotButton.bind(this))}}class lt extends i.Component{constructor(t){super(t)}componentWillMount(){let t=!1;this.props.isChecked&&(t=this.props.isChecked),this.setState({isChecked:t})}toggleCheckboxChange(){const t=this.props.handleCheckboxChange,e=this.props.label;this.setState({isChecked:!this.state.isChecked}),t(e)}render(){const t=this.props.label,e=this.state.isChecked;return i.createElement("div",{className:"checkbox"},i.createElement("label",null,i.createElement("input",{type:"checkbox",value:t,checked:e,onChange:this.toggleCheckboxChange.bind(this)})," ",t))}}var ht=n(35),ct=n.n(ht),dt="http://www.w3.org/1999/xhtml",ut={svg:"http://www.w3.org/2000/svg",xhtml:dt,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"},pt=function(t){var e=t+="",n=e.indexOf(":");return n>=0&&"xmlns"!==(e=t.slice(0,n))&&(t=t.slice(n+1)),ut.hasOwnProperty(e)?{space:ut[e],local:t}:t};var mt=function(t){var e=pt(t);return(e.local?function(t){return function(){return this.ownerDocument.createElementNS(t.space,t.local)}}:function(t){return function(){var e=this.ownerDocument,n=this.namespaceURI;return n===dt&&e.documentElement.namespaceURI===dt?e.createElement(t):e.createElementNS(n,t)}})(e)};function gt(){}var ft=function(t){return null==t?gt:function(){return this.querySelector(t)}};function vt(){return[]}var bt=function(t){return null==t?vt:function(){return this.querySelectorAll(t)}},yt=function(t){return function(){return this.matches(t)}};if("undefined"!=typeof document){var wt=document.documentElement;if(!wt.matches){var St=wt.webkitMatchesSelector||wt.msMatchesSelector||wt.mozMatchesSelector||wt.oMatchesSelector;yt=function(t){return function(){return St.call(this,t)}}}}var kt=yt,_t=function(t){return new Array(t.length)};function Mt(t,e){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=e}Mt.prototype={constructor:Mt,appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,e){return this._parent.insertBefore(t,e)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}};var Ct="$";function Et(t,e,n,i,o,a){for(var s,r=0,l=e.length,h=a.length;re?1:t>=e?0:NaN}var Nt=function(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView};function Tt(t,e){return t.style.getPropertyValue(e)||Nt(t).getComputedStyle(t,null).getPropertyValue(e)}function Dt(t){return t.trim().split(/^|\s+/)}function At(t){return t.classList||new Rt(t)}function Rt(t){this._node=t,this._names=Dt(t.getAttribute("class")||"")}function Pt(t,e){for(var n=At(t),i=-1,o=e.length;++i=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};function Bt(){this.textContent=""}function Wt(){this.innerHTML=""}function Gt(){this.nextSibling&&this.parentNode.appendChild(this)}function zt(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function Ut(){return null}function jt(){var t=this.parentNode;t&&t.removeChild(this)}function Ht(){return this.parentNode.insertBefore(this.cloneNode(!1),this.nextSibling)}function Ft(){return this.parentNode.insertBefore(this.cloneNode(!0),this.nextSibling)}var Ot={},qt=null;"undefined"!=typeof document&&("onmouseenter"in document.documentElement||(Ot={mouseenter:"mouseover",mouseleave:"mouseout"}));function Jt(t,e,n){return t=Vt(t,e,n),function(e){var n=e.relatedTarget;n&&(n===this||8&n.compareDocumentPosition(this))||t.call(this,e)}}function Vt(t,e,n){return function(i){var o=qt;qt=i;try{t.call(this,this.__data__,e,n)}finally{qt=o}}}function Kt(t){return function(){var e=this.__on;if(e){for(var n,i=0,o=-1,a=e.length;i=S&&(S=w+1);!(y=v[S])&&++S=0;)(i=o[a])&&(s&&s!==i.nextSibling&&s.parentNode.insertBefore(i,s),s=i);return this},sort:function(t){function e(e,n){return e&&n?t(e.__data__,n.__data__):!e-!n}t||(t=It);for(var n=this._groups,i=n.length,o=new Array(i),a=0;a1?this.each((null==e?function(t){return function(){this.style.removeProperty(t)}}:"function"==typeof e?function(t,e,n){return function(){var i=e.apply(this,arguments);null==i?this.style.removeProperty(t):this.style.setProperty(t,i,n)}}:function(t,e,n){return function(){this.style.setProperty(t,e,n)}})(t,e,null==n?"":n)):Tt(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?function(t){return function(){delete this[t]}}:"function"==typeof e?function(t,e){return function(){var n=e.apply(this,arguments);null==n?delete this[t]:this[t]=n}}:function(t,e){return function(){this[t]=e}})(t,e)):this.node()[t]},classed:function(t,e){var n=Dt(t+"");if(arguments.length<2){for(var i=At(this.node()),o=-1,a=n.length;++o=0&&(e=t.slice(n+1),t=t.slice(0,n)),{type:t,name:e}})}(t+""),s=a.length;if(!(arguments.length<2)){for(r=e?Yt:Kt,null==n&&(n=!1),i=0;i=0&&(e=t.slice(n+1),t=t.slice(0,n)),t&&!i.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:e}})),s=-1,r=a.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++s0)for(var n,i,o=new Array(n),a=0;ad}l.mouse("drag")}function g(){ne(qt.view).on("mousemove.drag mouseup.drag",null),be(qt.view,n),fe(),l.mouse("end")}function f(){if(o.apply(this,arguments)){var t,e,n=qt.changedTouches,i=a.apply(this,arguments),s=n.length;for(t=0;t>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):(e=Re.exec(t))?He(parseInt(e[1],16)):(e=Pe.exec(t))?new Je(e[1],e[2],e[3],1):(e=Le.exec(t))?new Je(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=Be.exec(t))?Fe(e[1],e[2],e[3],e[4]):(e=We.exec(t))?Fe(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=Ge.exec(t))?Ke(e[1],e[2]/100,e[3]/100,1):(e=ze.exec(t))?Ke(e[1],e[2]/100,e[3]/100,e[4]):Ue.hasOwnProperty(t)?He(Ue[t]):"transparent"===t?new Je(NaN,NaN,NaN,0):null}function He(t){return new Je(t>>16&255,t>>8&255,255&t,1)}function Fe(t,e,n,i){return i<=0&&(t=e=n=NaN),new Je(t,e,n,i)}function Oe(t){return t instanceof Ie||(t=je(t)),t?new Je((t=t.rgb()).r,t.g,t.b,t.opacity):new Je}function qe(t,e,n,i){return 1===arguments.length?Oe(t):new Je(t,e,n,null==i?1:i)}function Je(t,e,n,i){this.r=+t,this.g=+e,this.b=+n,this.opacity=+i}function Ve(t){return((t=Math.max(0,Math.min(255,Math.round(t)||0)))<16?"0":"")+t.toString(16)}function Ke(t,e,n,i){return i<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new $e(t,e,n,i)}function Ye(t,e,n,i){return 1===arguments.length?function(t){if(t instanceof $e)return new $e(t.h,t.s,t.l,t.opacity);if(t instanceof Ie||(t=je(t)),!t)return new $e;if(t instanceof $e)return t;var e=(t=t.rgb()).r/255,n=t.g/255,i=t.b/255,o=Math.min(e,n,i),a=Math.max(e,n,i),s=NaN,r=a-o,l=(a+o)/2;return r?(s=e===a?(n-i)/r+6*(n0&&l<1?0:s,new $e(s,r,l,t.opacity)}(t):new $e(t,e,n,null==i?1:i)}function $e(t,e,n,i){this.h=+t,this.s=+e,this.l=+n,this.opacity=+i}function Qe(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}Ee(Ie,je,{displayable:function(){return this.rgb().displayable()},hex:function(){return this.rgb().hex()},toString:function(){return this.rgb()+""}}),Ee(Je,qe,xe(Ie,{brighter:function(t){return t=null==t?1/.7:Math.pow(1/.7,t),new Je(this.r*t,this.g*t,this.b*t,this.opacity)},darker:function(t){return t=null==t?.7:Math.pow(.7,t),new Je(this.r*t,this.g*t,this.b*t,this.opacity)},rgb:function(){return this},displayable:function(){return 0<=this.r&&this.r<=255&&0<=this.g&&this.g<=255&&0<=this.b&&this.b<=255&&0<=this.opacity&&this.opacity<=1},hex:function(){return"#"+Ve(this.r)+Ve(this.g)+Ve(this.b)},toString:function(){var t=this.opacity;return(1===(t=isNaN(t)?1:Math.max(0,Math.min(1,t)))?"rgb(":"rgba(")+Math.max(0,Math.min(255,Math.round(this.r)||0))+", "+Math.max(0,Math.min(255,Math.round(this.g)||0))+", "+Math.max(0,Math.min(255,Math.round(this.b)||0))+(1===t?")":", "+t+")")}})),Ee($e,Ye,xe(Ie,{brighter:function(t){return t=null==t?1/.7:Math.pow(1/.7,t),new $e(this.h,this.s,this.l*t,this.opacity)},darker:function(t){return t=null==t?.7:Math.pow(.7,t),new $e(this.h,this.s,this.l*t,this.opacity)},rgb:function(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,i=n+(n<.5?n:1-n)*e,o=2*n-i;return new Je(Qe(t>=240?t-240:t+120,o,i),Qe(t,o,i),Qe(t<120?t+240:t-120,o,i),this.opacity)},displayable:function(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1}}));var Xe=Math.PI/180,Ze=180/Math.PI,tn=.96422,en=1,nn=.82521,on=4/29,an=6/29,sn=3*an*an,rn=an*an*an;function ln(t){if(t instanceof cn)return new cn(t.l,t.a,t.b,t.opacity);if(t instanceof vn){if(isNaN(t.h))return new cn(t.l,0,0,t.opacity);var e=t.h*Xe;return new cn(t.l,Math.cos(e)*t.c,Math.sin(e)*t.c,t.opacity)}t instanceof Je||(t=Oe(t));var n,i,o=mn(t.r),a=mn(t.g),s=mn(t.b),r=dn((.2225045*o+.7168786*a+.0606169*s)/en);return o===a&&a===s?n=i=r:(n=dn((.4360747*o+.3850649*a+.1430804*s)/tn),i=dn((.0139322*o+.0971045*a+.7141733*s)/nn)),new cn(116*r-16,500*(n-r),200*(r-i),t.opacity)}function hn(t,e,n,i){return 1===arguments.length?ln(t):new cn(t,e,n,null==i?1:i)}function cn(t,e,n,i){this.l=+t,this.a=+e,this.b=+n,this.opacity=+i}function dn(t){return t>rn?Math.pow(t,1/3):t/sn+on}function un(t){return t>an?t*t*t:sn*(t-on)}function pn(t){return 255*(t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055)}function mn(t){return(t/=255)<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}function gn(t){if(t instanceof vn)return new vn(t.h,t.c,t.l,t.opacity);if(t instanceof cn||(t=ln(t)),0===t.a&&0===t.b)return new vn(NaN,0,t.l,t.opacity);var e=Math.atan2(t.b,t.a)*Ze;return new vn(e<0?e+360:e,Math.sqrt(t.a*t.a+t.b*t.b),t.l,t.opacity)}function fn(t,e,n,i){return 1===arguments.length?gn(t):new vn(t,e,n,null==i?1:i)}function vn(t,e,n,i){this.h=+t,this.c=+e,this.l=+n,this.opacity=+i}Ee(cn,hn,xe(Ie,{brighter:function(t){return new cn(this.l+18*(null==t?1:t),this.a,this.b,this.opacity)},darker:function(t){return new cn(this.l-18*(null==t?1:t),this.a,this.b,this.opacity)},rgb:function(){var t=(this.l+16)/116,e=isNaN(this.a)?t:t+this.a/500,n=isNaN(this.b)?t:t-this.b/200;return new Je(pn(3.1338561*(e=tn*un(e))-1.6168667*(t=en*un(t))-.4906146*(n=nn*un(n))),pn(-.9787684*e+1.9161415*t+.033454*n),pn(.0719453*e-.2289914*t+1.4052427*n),this.opacity)}})),Ee(vn,fn,xe(Ie,{brighter:function(t){return new vn(this.h,this.c,this.l+18*(null==t?1:t),this.opacity)},darker:function(t){return new vn(this.h,this.c,this.l-18*(null==t?1:t),this.opacity)},rgb:function(){return ln(this).rgb()}}));var bn=-.14861,yn=1.78277,wn=-.29227,Sn=-.90649,kn=1.97294,_n=kn*Sn,Mn=kn*yn,Cn=yn*wn-Sn*bn;function En(t,e,n,i){return 1===arguments.length?function(t){if(t instanceof xn)return new xn(t.h,t.s,t.l,t.opacity);t instanceof Je||(t=Oe(t));var e=t.r/255,n=t.g/255,i=t.b/255,o=(Cn*i+_n*e-Mn*n)/(Cn+_n-Mn),a=i-o,s=(kn*(n-o)-wn*a)/Sn,r=Math.sqrt(s*s+a*a)/(kn*o*(1-o)),l=r?Math.atan2(s,a)*Ze-120:NaN;return new xn(l<0?l+360:l,r,o,t.opacity)}(t):new xn(t,e,n,null==i?1:i)}function xn(t,e,n,i){this.h=+t,this.s=+e,this.l=+n,this.opacity=+i}function In(t,e,n,i,o){var a=t*t,s=a*t;return((1-3*t+3*a-s)*e+(4-6*a+3*s)*n+(1+3*t+3*a-3*s)*i+s*o)/6}Ee(xn,En,xe(Ie,{brighter:function(t){return t=null==t?1/.7:Math.pow(1/.7,t),new xn(this.h,this.s,this.l*t,this.opacity)},darker:function(t){return t=null==t?.7:Math.pow(.7,t),new xn(this.h,this.s,this.l*t,this.opacity)},rgb:function(){var t=isNaN(this.h)?0:(this.h+120)*Xe,e=+this.l,n=isNaN(this.s)?0:this.s*e*(1-e),i=Math.cos(t),o=Math.sin(t);return new Je(255*(e+n*(bn*i+yn*o)),255*(e+n*(wn*i+Sn*o)),255*(e+n*(kn*i)),this.opacity)}}));var Nn=function(t){return function(){return t}};function Tn(t,e){return function(n){return t+n*e}}function Dn(t,e){var n=e-t;return n?Tn(t,n>180||n<-180?n-360*Math.round(n/360):n):Nn(isNaN(t)?e:t)}function An(t){return 1==(t=+t)?Rn:function(e,n){return n-e?function(t,e,n){return t=Math.pow(t,n),e=Math.pow(e,n)-t,n=1/n,function(i){return Math.pow(t+i*e,n)}}(e,n,t):Nn(isNaN(e)?n:e)}}function Rn(t,e){var n=e-t;return n?Tn(t,n):Nn(isNaN(t)?e:t)}var Pn=function t(e){var n=An(e);function i(t,e){var i=n((t=qe(t)).r,(e=qe(e)).r),o=n(t.g,e.g),a=n(t.b,e.b),s=Rn(t.opacity,e.opacity);return function(e){return t.r=i(e),t.g=o(e),t.b=a(e),t.opacity=s(e),t+""}}return i.gamma=t,i}(1);function Ln(t){return function(e){var n,i,o=e.length,a=new Array(o),s=new Array(o),r=new Array(o);for(n=0;n=1?(n=1,e-1):Math.floor(n*e),o=t[i],a=t[i+1],s=i>0?t[i-1]:2*o-a,r=ia&&(o=e.slice(a,o),r[s]?r[s]+=o:r[++s]=o),(n=n[0])===(i=i[0])?r[s]?r[s]+=i:r[++s]=i:(r[++s]=null,l.push({i:s,x:Bn(n,i)})),a=Gn.lastIndex;return a180?e+=360:e-t>180&&(t+=360),a.push({i:n.push(o(n)+"rotate(",null,i)-2,x:Bn(t,e)})):e&&n.push(o(n)+"rotate("+e+i)}(a.rotate,s.rotate,r,l),function(t,e,n,a){t!==e?a.push({i:n.push(o(n)+"skewX(",null,i)-2,x:Bn(t,e)}):e&&n.push(o(n)+"skewX("+e+i)}(a.skewX,s.skewX,r,l),function(t,e,n,i,a,s){if(t!==n||e!==i){var r=a.push(o(a)+"scale(",null,",",null,")");s.push({i:r-4,x:Bn(t,n)},{i:r-2,x:Bn(e,i)})}else 1===n&&1===i||a.push(o(a)+"scale("+n+","+i+")")}(a.scaleX,a.scaleY,s.scaleX,s.scaleY,r,l),a=s=null,function(t){for(var e,n=-1,i=l.length;++n=0&&e._call.call(null,t),e=e._next;--oi}()}finally{oi=0,function(){var t,e,n=ni,i=1/0;for(;n;)n._call?(i>n._time&&(i=n._time),t=n,n=n._next):(e=n._next,n._next=null,n=t?t._next=e:ni=e);ii=t,yi(i)}(),hi=0}}function bi(){var t=di.now(),e=t-li;e>ri&&(ci-=e,li=t)}function yi(t){oi||(ai&&(ai=clearTimeout(ai)),t-hi>24?(t<1/0&&(ai=setTimeout(vi,t-di.now()-ci)),si&&(si=clearInterval(si))):(si||(li=di.now(),si=setInterval(bi,ri)),oi=1,ui(vi)))}gi.prototype=fi.prototype={constructor:gi,restart:function(t,e,n){if("function"!=typeof t)throw new TypeError("callback is not a function");n=(null==n?pi():+n)+(null==e?0:+e),this._next||ii===this||(ii?ii._next=this:ni=this,ii=this),this._call=t,this._time=n,yi()},stop:function(){this._call&&(this._call=null,this._time=1/0,yi())}};var wi=function(t,e,n){var i=new gi;return e=null==e?0:+e,i.restart(function(n){i.stop(),t(n+e)},e,n),i},Si=me("start","end","interrupt"),ki=[],_i=0,Mi=1,Ci=2,Ei=3,xi=4,Ii=5,Ni=6,Ti=function(t,e,n,i,o,a){var s=t.__transition;if(s){if(n in s)return}else t.__transition={};!function(t,e,n){var i,o=t.__transition;function a(l){var h,c,d,u;if(n.state!==Mi)return r();for(h in o)if((u=o[h]).name===n.name){if(u.state===Ei)return wi(a);u.state===xi?(u.state=Ni,u.timer.stop(),u.on.call("interrupt",t,t.__data__,u.index,u.group),delete o[h]):+h_i)throw new Error("too late; already scheduled");return n}function Ai(t,e){var n=Ri(t,e);if(n.state>Ci)throw new Error("too late; already started");return n}function Ri(t,e){var n=t.__transition;if(!n||!(n=n[e]))throw new Error("transition not found");return n}var Pi=function(t,e){var n,i,o,a=t.__transition,s=!0;if(a){for(o in e=null==e?null:e+"",a)(n=a[o]).name===e?(i=n.state>Ci&&n.state=0&&(t=t.slice(0,e)),!t||"start"===t})}(e)?Di:Ai;return function(){var s=a(this,t),r=s.on;r!==i&&(o=(i=r).copy()).on(e,n),s.on=o}}(n,t,e))},attr:function(t,e){var n=pt(t),i="transform"===n?Yn:Bi;return this.attrTween(t,"function"==typeof e?(n.local?function(t,e,n){var i,o,a;return function(){var s,r=n(this);if(null!=r)return(s=this.getAttributeNS(t.space,t.local))===r?null:s===i&&r===o?a:a=e(i=s,o=r);this.removeAttributeNS(t.space,t.local)}}:function(t,e,n){var i,o,a;return function(){var s,r=n(this);if(null!=r)return(s=this.getAttribute(t))===r?null:s===i&&r===o?a:a=e(i=s,o=r);this.removeAttribute(t)}})(n,i,Li(this,"attr."+t,e)):null==e?(n.local?function(t){return function(){this.removeAttributeNS(t.space,t.local)}}:function(t){return function(){this.removeAttribute(t)}})(n):(n.local?function(t,e,n){var i,o;return function(){var a=this.getAttributeNS(t.space,t.local);return a===n?null:a===i?o:o=e(i=a,n)}}:function(t,e,n){var i,o;return function(){var a=this.getAttribute(t);return a===n?null:a===i?o:o=e(i=a,n)}})(n,i,e+""))},attrTween:function(t,e){var n="attr."+t;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(null==e)return this.tween(n,null);if("function"!=typeof e)throw new Error;var i=pt(t);return this.tween(n,(i.local?function(t,e){function n(){var n=this,i=e.apply(n,arguments);return i&&function(e){n.setAttributeNS(t.space,t.local,i(e))}}return n._value=e,n}:function(t,e){function n(){var n=this,i=e.apply(n,arguments);return i&&function(e){n.setAttribute(t,i(e))}}return n._value=e,n})(i,e))},style:function(t,e,n){var i="transform"==(t+="")?Kn:Bi;return null==e?this.styleTween(t,function(t,e){var n,i,o;return function(){var a=Tt(this,t),s=(this.style.removeProperty(t),Tt(this,t));return a===s?null:a===n&&s===i?o:o=e(n=a,i=s)}}(t,i)).on("end.style."+t,function(t){return function(){this.style.removeProperty(t)}}(t)):this.styleTween(t,"function"==typeof e?function(t,e,n){var i,o,a;return function(){var s=Tt(this,t),r=n(this);return null==r&&(this.style.removeProperty(t),r=Tt(this,t)),s===r?null:s===i&&r===o?a:a=e(i=s,o=r)}}(t,i,Li(this,"style."+t,e)):function(t,e,n){var i,o;return function(){var a=Tt(this,t);return a===n?null:a===i?o:o=e(i=a,n)}}(t,i,e+""),n)},styleTween:function(t,e,n){var i="style."+(t+="");if(arguments.length<2)return(i=this.tween(i))&&i._value;if(null==e)return this.tween(i,null);if("function"!=typeof e)throw new Error;return this.tween(i,function(t,e,n){function i(){var i=this,o=e.apply(i,arguments);return o&&function(e){i.style.setProperty(t,o(e),n)}}return i._value=e,i}(t,e,null==n?"":n))},text:function(t){return this.tween("text","function"==typeof t?function(t){return function(){var e=t(this);this.textContent=null==e?"":e}}(Li(this,"text",t)):function(t){return function(){this.textContent=t}}(null==t?"":t+""))},remove:function(){return this.on("end.remove",(t=this._id,function(){var e=this.parentNode;for(var n in this.__transition)if(+n!==t)return;e&&e.removeChild(this)}));var t},tween:function(t,e){var n=this._id;if(t+="",arguments.length<2){for(var i,o=Ri(this.node(),n).tween,a=0,s=o.length;ai?(i+o)/2:Math.min(0,i)||Math.max(0,o),s>a?(a+s)/2:Math.min(0,a)||Math.max(0,s))}var io=function(){var t,e,n=Qi,i=Xi,o=no,a=to,s=eo,r=[0,1/0],l=[[-1/0,-1/0],[1/0,1/0]],h=250,c=Xn,d=[],u=me("start","zoom","end"),p=500,m=150,g=0;function f(t){t.property("__zoom",Zi).on("wheel.zoom",_).on("mousedown.zoom",M).on("dblclick.zoom",C).filter(s).on("touchstart.zoom",E).on("touchmove.zoom",x).on("touchend.zoom touchcancel.zoom",I).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function v(t,e){return(e=Math.max(r[0],Math.min(r[1],e)))===t.k?t:new Ji(e,t.x,t.y)}function b(t,e,n){var i=e[0]-n[0]*t.k,o=e[1]-n[1]*t.k;return i===t.x&&o===t.y?t:new Ji(t.k,i,o)}function y(t){return[(+t[0][0]+ +t[1][0])/2,(+t[0][1]+ +t[1][1])/2]}function w(t,e,n){t.on("start.zoom",function(){S(this,arguments).start()}).on("interrupt.zoom end.zoom",function(){S(this,arguments).end()}).tween("zoom",function(){var t=arguments,o=S(this,t),a=i.apply(this,t),s=n||y(a),r=Math.max(a[1][0]-a[0][0],a[1][1]-a[0][1]),l=this.__zoom,h="function"==typeof e?e.apply(this,t):e,d=c(l.invert(s).concat(r/l.k),h.invert(s).concat(r/h.k));return function(t){if(1===t)t=h;else{var e=d(t),n=r/e[2];t=new Ji(n,s[0]-e[0]*n,s[1]-e[1]*n)}o.zoom(null,t)}})}function S(t,e){for(var n,i=0,o=d.length;ig}t.zoom("mouse",o(b(t.that.__zoom,t.mouse[0]=re(t.that),t.mouse[1]),t.extent,l))},!0).on("mouseup.zoom",function(){i.on("mousemove.zoom mouseup.zoom",null),be(qt.view,t.moved),$i(),t.end()},!0),a=re(this),s=qt.clientX,r=qt.clientY;ve(qt.view),Yi(),t.mouse=[a,this.__zoom.invert(a)],Pi(this),t.start()}}function C(){if(n.apply(this,arguments)){var t=this.__zoom,e=re(this),a=t.invert(e),s=t.k*(qt.shiftKey?.5:2),r=o(b(v(t,s),e,a),i.apply(this,arguments),l);$i(),h>0?ne(this).transition().duration(h).call(w,r,e):ne(this).call(f.transform,r)}}function E(){if(n.apply(this,arguments)){var e,i,o,a,s=S(this,arguments),r=qt.changedTouches,l=r.length;for(Yi(),i=0;i=(a=(g+v)/2))?g=a:v=a,(c=n>=(s=(f+b)/2))?f=s:b=s,o=p,!(p=p[d=c<<1|h]))return o[d]=m,t;if(r=+t._x.call(null,p.data),l=+t._y.call(null,p.data),e===r&&n===l)return m.next=p,o?o[d]=m:t._root=m,t;do{o=o?o[d]=new Array(4):t._root=new Array(4),(h=e>=(a=(g+v)/2))?g=a:v=a,(c=n>=(s=(f+b)/2))?f=s:b=s}while((d=c<<1|h)==(u=(l>=s)<<1|r>=a));return o[u]=p,o[d]=m,t}var lo=function(t,e,n,i,o){this.node=t,this.x0=e,this.y0=n,this.x1=i,this.y1=o};function ho(t){return t[0]}function co(t){return t[1]}function uo(t,e,n){var i=new po(null==e?ho:e,null==n?co:n,NaN,NaN,NaN,NaN);return null==t?i:i.addAll(t)}function po(t,e,n,i,o,a){this._x=t,this._y=e,this._x0=n,this._y0=i,this._x1=o,this._y1=a,this._root=void 0}function mo(t){for(var e={data:t.data},n=e;t=t.next;)n=n.next={data:t.data};return e}var go=uo.prototype=po.prototype;function fo(t){return t.x+t.vx}function vo(t){return t.y+t.vy}go.copy=function(){var t,e,n=new po(this._x,this._y,this._x0,this._y0,this._x1,this._y1),i=this._root;if(!i)return n;if(!i.length)return n._root=mo(i),n;for(t=[{source:i,target:n._root=new Array(4)}];i=t.pop();)for(var o=0;o<4;++o)(e=i.source[o])&&(e.length?t.push({source:e,target:i.target[o]=new Array(4)}):i.target[o]=mo(e));return n},go.add=function(t){var e=+this._x.call(null,t),n=+this._y.call(null,t);return ro(this.cover(e,n),e,n,t)},go.addAll=function(t){var e,n,i,o,a=t.length,s=new Array(a),r=new Array(a),l=1/0,h=1/0,c=-1/0,d=-1/0;for(n=0;nc&&(c=i),od&&(d=o));for(ct||t>o||i>e||e>a))return this;var s,r,l=o-n,h=this._root;switch(r=(e<(i+a)/2)<<1|t<(n+o)/2){case 0:do{(s=new Array(4))[r]=h,h=s}while(a=i+(l*=2),t>(o=n+l)||e>a);break;case 1:do{(s=new Array(4))[r]=h,h=s}while(a=i+(l*=2),(n=o-l)>t||e>a);break;case 2:do{(s=new Array(4))[r]=h,h=s}while(i=a-(l*=2),t>(o=n+l)||i>e);break;case 3:do{(s=new Array(4))[r]=h,h=s}while(i=a-(l*=2),(n=o-l)>t||i>e)}this._root&&this._root.length&&(this._root=h)}return this._x0=n,this._y0=i,this._x1=o,this._y1=a,this},go.data=function(){var t=[];return this.visit(function(e){if(!e.length)do{t.push(e.data)}while(e=e.next)}),t},go.extent=function(t){return arguments.length?this.cover(+t[0][0],+t[0][1]).cover(+t[1][0],+t[1][1]):isNaN(this._x0)?void 0:[[this._x0,this._y0],[this._x1,this._y1]]},go.find=function(t,e,n){var i,o,a,s,r,l,h,c=this._x0,d=this._y0,u=this._x1,p=this._y1,m=[],g=this._root;for(g&&m.push(new lo(g,c,d,u,p)),null==n?n=1/0:(c=t-n,d=e-n,u=t+n,p=e+n,n*=n);l=m.pop();)if(!(!(g=l.node)||(o=l.x0)>u||(a=l.y0)>p||(s=l.x1)=v)<<1|t>=f)&&(l=m[m.length-1],m[m.length-1]=m[m.length-1-h],m[m.length-1-h]=l)}else{var b=t-+this._x.call(null,g.data),y=e-+this._y.call(null,g.data),w=b*b+y*y;if(w=(r=(m+f)/2))?m=r:f=r,(c=s>=(l=(g+v)/2))?g=l:v=l,e=p,!(p=p[d=c<<1|h]))return this;if(!p.length)break;(e[d+1&3]||e[d+2&3]||e[d+3&3])&&(n=e,u=d)}for(;p.data!==t;)if(i=p,!(p=p.next))return this;return(o=p.next)&&delete p.next,i?(o?i.next=o:delete i.next,this):e?(o?e[d]=o:delete e[d],(p=e[0]||e[1]||e[2]||e[3])&&p===(e[3]||e[2]||e[1]||e[0])&&!p.length&&(n?n[u]=p:this._root=p),this):(this._root=o,this)},go.removeAll=function(t){for(var e=0,n=t.length;el+p||oh+p||ar.index){var m=l-s.x-s.vx,g=h-s.y-s.vy,f=m*m+g*g;ft.r&&(t.r=t[e].r)}function r(){if(e){var i,o,a=e.length;for(n=new Array(a),i=0;i1?(null==n?r.remove(t):r.set(t,p(n)),e):r.get(t)},find:function(e,n,i){var o,a,s,r,l,h=0,c=t.length;for(null==i?i=1/0:i*=i,h=0;h1?(h.on(t,n),e):h.on(t)}}},Ro=function(){var t,e,n,i,o=ao(-30),a=1,s=1/0,r=.81;function l(i){var o,a=t.length,s=uo(t,Io,No).visitAfter(c);for(n=i,o=0;o=s)){(t.data!==e||t.next)&&(0===c&&(p+=(c=so())*c),0===d&&(p+=(d=so())*d),p({showModalState:!1,exportedData:""}))}componentWillUnmount(){}componentWillReceiveProps(t){if(t.showModalProp&&t.graphModel&&t.graphModel.activeGraph){let e="DATA";switch(t.exportMode){case"graph":let n=this.props.graphModel.activeGraph;n&&(e=JSON.stringify(n.toJSON(),null,2));break;case"markup":e=this.props.graphModel.getMarkup();break;case"d3":e=this.props.graphModel.getD3();break;case"svg":e=this.props.graphModel.getSVG();break;case"css":e=this.props.graphModel.getCSS();break;case"dot":e=""}this.setState(n=>({showModalState:t.showModalProp,exportedData:e}))}}componentDidUpdate(t,e){}close(){this.setState(t=>(this.props.onClose(),{showModalState:!1,exportedData:""}))}onHide(){this.close()}save(){let t={};switch(this.props.exportMode){case"graph":try{t=JSON.parse(this.state.exportedData),this.props.graphModel.newGraphWithOptions(t)}catch(t){console.log("ModalExport: save: ",t)}break;case"markup":t={markup:this.state.exportedData},this.props.graphModel.newGraphWithOptions(t);break;case"d3":t={d3Graph:JSON.parse(this.state.exportedData)},this.props.graphModel.newGraphWithOptions(t);break;case"svg":break;case"css":this.props.graphModel.applyActiveGraphCss(this.state.exportedData);break;case"dot":t={dot:this.state.exportedData},this.props.graphModel.newGraphWithOptions(t)}this.close()}onButtonClicked(t){switch(t){case"save":this.save();break;case"cancel":case"close":this.close()}}handleInputChange(t){let e=t.nativeEvent;switch(e.target.name){case"exportedData":this.setState(t=>({exportedData:e.target.value}))}}render(){return i.createElement(a.Modal,{className:"modal-export",show:this.state.showModalState,onHide:this.onHide.bind(this)},i.createElement(a.Modal.Header,null,i.createElement(a.Modal.Title,null,"Exported Data: ",this.props.exportMode)),i.createElement(a.Modal.Body,{className:"modal-export-body"},i.createElement("textarea",{name:"exportedData",className:"code",value:this.state.exportedData,onChange:this.handleInputChange.bind(this)})),i.createElement(a.Modal.Footer,null,i.createElement(a.Button,{bsStyle:"success",key:"cancel",style:{width:150},onClick:this.onButtonClicked.bind(this,"cancel")},"Cancel"),i.createElement(a.Button,{bsStyle:"success",key:"save",style:{width:150},onClick:this.onButtonClicked.bind(this,"save")},"Save")))}}class Go extends i.Component{constructor(t){super(t)}componentWillMount(){this.setState(t=>({showModalState:!1,graphName:"",graphNameStyle:{color:"black"}}))}componentWillUnmount(){}componentWillReceiveProps(t){let e="";switch(t.fileDetailsMode){case"details":e=t.graphModel.activeGraph?t.graphModel.activeGraph.name:"";break;case"newFile":e=""}t.showModalProp&&this.setState(n=>({showModalState:t.showModalProp,graphName:e,graphNameStyle:{color:"black"}}))}componentDidUpdate(t,e){}close(t){console.log(`ModalFileDetails: close: ${t}`),this.setState(e=>(this.props.onClose(t),{showModalState:!1,graphName:""}))}onHide(){console.log("ModalFileDetails: onHide: "),this.close()}save(){let t={};t.fileDetailsMode=this.props.fileDetailsMode,t.name=this.state.graphName,this.close(t)}onButtonClicked(t){switch(t){case"save":""!=this.state.graphName?this.save():this.setState(t=>({graphNameStyle:{color:"red"}}));break;case"cancel":this.close()}}handleInputChange(t){let e=t.nativeEvent;switch(e.target.name){case"graphName":this.setState(t=>({graphName:e.target.value}))}}render(){return i.createElement(a.Modal,{show:this.state.showModalState,onHide:this.onHide.bind(this)},i.createElement(a.Modal.Header,null,i.createElement(a.Modal.Title,null,"Graph Details: ",this.props.fileDetailsMode)),i.createElement(a.Modal.Body,null,i.createElement("div",{className:"pull-left",style:{paddingRight:6}},"Filename:"),i.createElement("input",{name:"graphName",id:"graphName",type:"text",value:this.state.graphName,onChange:this.handleInputChange.bind(this),style:this.state.graphNameStyle})),i.createElement(a.Modal.Footer,null,i.createElement(a.Button,{bsStyle:"success",key:"cancel",style:{width:150},onClick:this.onButtonClicked.bind(this,"cancel")},"Cancel"),i.createElement(a.Button,{bsStyle:"success",key:"save",style:{width:150},onClick:this.onButtonClicked.bind(this,"save")},"Save")))}}const{dialog:zo,shell:Uo}=n(11).remote;class jo extends i.Component{constructor(t){super(t)}componentWillMount(){let t="";this.props.graphModel.activeGraph&&(t=this.props.graphModel.activeGraph.name),this.setState(e=>({graphName:t,graphScale:1,showModal:!1,exportMode:"markup",showFileDetailsModal:!1,fileDetailsMode:""}))}componentDidMount(){}componentWillUnmount(){}onUpdateActiveGraph(){this.setState(t=>({graphName:this.props.graphModel.activeGraph?this.props.graphModel.activeGraph.name:"",graphScale:this.props.graphModel.activeGraph?this.props.graphModel.activeGraph.scale:1}))}handleInputChange(t){let e=t.nativeEvent;switch(e.target.name){case"graphName":this.setState({graphName:e.target.value})}}handleSubmit(t){t.preventDefault()}onButtonClicked(t){switch(t){case"exportGraph":this.openModalExport("graph");break;case"exportMarkup":this.openModalExport("markup");break;case"exportD3":this.openModalExport("d3");break;case"exportSVG":this.openModalExport("svg");break;case"exportCSS":this.openModalExport("css");break;case"exportDot":this.openModalExport("dot");break;case"details":this.openModalFileDetails("details");break;case"newFile":this.openModalFileDetails("newFile");break;case"import":this.importGraphFile();break;case"show":this.props.graphModel.settings.userDataPath&&Uo.showItemInFolder(this.props.graphModel.settings.userDataPath);break;case"save":this.save()}}save(){""!=this.state.graphName?this.props.graphModel.saveActiveGraph():this.openModalFileDetails("details")}openModalExport(t){this.setState({showModal:!0,exportMode:t})}onCloseModalExport(){this.setState({showModal:!1})}openModalFileDetails(t=""){this.setState(e=>({showFileDetailsModal:!0,fileDetailsMode:t}))}importGraphFile(){zo.showOpenDialog(t=>{void 0!==t?t[0]&&this.props.graphModel&&this.props.graphModel.initGraphWithPath(t[0]).then(t=>{this.props.graphModel&&this.props.graphModel.graphSet&&(this.props.graphModel.graphSet.addGraph(t),this.props.graphModel.graphSet.saveGraph(t),this.setState(e=>({graphName:t.name})))}).catch(t=>{console.log(t)}):console.log("No file selected")})}onCloseModalFileDetails(t){console.log("ToolsPanel: onCloseModalFileDetails:",t),t?"newFile"==t.fileDetailsMode?(this.props.graphModel.newBlankGraph(t.name),this.setState(e=>({showFileDetailsModal:!1,graphName:t.name}))):this.props.graphModel.activeGraph&&this.props.graphModel.graphSet?(this.props.graphModel.activeGraph.name=t.name,this.props.graphModel.graphSet.addGraph(this.props.graphModel.activeGraph),this.props.graphModel.graphSet.saveGraph(this.props.graphModel.activeGraph),this.setState(e=>({showFileDetailsModal:!1,graphName:t.name}))):this.setState(t=>({showFileDetailsModal:!1})):this.setState(t=>({showFileDetailsModal:!1}))}onMenuItemSelected(t){this.setState({graphName:t}),this.props.graphModel.initGraphWithName(t)}renderFilenameMenuItems(){let t=[];return this.props.graphModel.graphSet&&this.props.graphModel.graphSet.getGraphNames().forEach(e=>{let n=!1;e==this.state.graphName&&(n=!0),t.push(i.createElement(a.MenuItem,{active:n,key:e,eventKey:e,onSelect:this.onMenuItemSelected.bind(this,e)},e))}),t}renderFilenameSplitButton(){return i.createElement(a.SplitButton,{bsStyle:"default",title:this.state.graphName,key:"filename-splitbutton",id:"filename-splitbutton"},this.renderFilenameMenuItems())}render(){return i.createElement("div",{className:"editor-panel well",id:"toolsPanel"},i.createElement("div",{className:"tools form-inline"},i.createElement(Wo,{showModalProp:this.state.showModal,onClose:this.onCloseModalExport.bind(this),graphModel:this.props.graphModel,exportMode:this.state.exportMode}),i.createElement(Go,{showModalProp:this.state.showFileDetailsModal,onClose:this.onCloseModalFileDetails.bind(this),graphModel:this.props.graphModel,fileDetailsMode:this.state.fileDetailsMode}),i.createElement(a.Button,{bsStyle:"default",key:"exportGraph",style:{width:80},onClick:this.onButtonClicked.bind(this,"exportGraph")},"Graph"),i.createElement(a.Button,{bsStyle:"default",key:"exportD3",style:{width:80},onClick:this.onButtonClicked.bind(this,"exportD3")},"D3"),i.createElement(a.Button,{bsStyle:"default",key:"exportSVG",style:{width:80},onClick:this.onButtonClicked.bind(this,"exportSVG")},"SVG"),i.createElement(a.Button,{bsStyle:"default",key:"exportCSS",style:{width:80},onClick:this.onButtonClicked.bind(this,"exportCSS")},"CSS"),i.createElement(a.Button,{bsStyle:"default",key:"import",style:{width:80},onClick:this.onButtonClicked.bind(this,"import")},"Import"),i.createElement(a.Button,{bsStyle:"default",key:"show",style:{width:80},onClick:this.onButtonClicked.bind(this,"show")},"Show"),i.createElement("div",null,i.createElement("label",{className:"input-label"},"Open:"),this.renderFilenameSplitButton(),i.createElement("datalist",{id:"graphlist"}),i.createElement(a.Button,{bsStyle:"default",key:"save",style:{width:80},onClick:this.onButtonClicked.bind(this,"save")},"Save"),i.createElement(a.Button,{bsStyle:"default",key:"details",style:{width:80},onClick:this.onButtonClicked.bind(this,"details")},"Details"),i.createElement(a.Button,{bsStyle:"default",key:"newFile",style:{width:80},onClick:this.onButtonClicked.bind(this,"newFile")},"New File"))))}}var Ho=n(12);class Fo extends i.Component{constructor(t){super(t),this._savedTTSList=[],this._savedTTSListLength=0,this._onTTSExecutedHandler=this.onTTSExecuted.bind(this),this._onTTSExecutionErrorHandler=this.onTTSExecutionErrorHandler.bind(this),this._onUpdateActiveGraphHandler=this.onUpdateActiveGraph.bind(this),this._itemClickedPrevTime=0}componentWillMount(){let t=this.props.graphModel.getSavedTTSList()[0];this.setState(e=>({activeTTS:t||{name:"",prompt:""},selectedCyperIndex:0,status:""})),this.props.graphModel.on("onTTSExecuted",this._onTTSExecutedHandler),this.props.graphModel.on("onTTSExecutionError",this._onTTSExecutionErrorHandler),this.props.graphModel.on("updateActiveGraph",this._onUpdateActiveGraphHandler)}componentDidMount(){this.props.graphModel.addPanelWithId(this.props.id)}componentWillUnmount(){this.props.graphModel.removeListener("onTTSExecuted",this._onTTSExecutedHandler),this.props.graphModel.removeListener("onTTSExecutionError",this._onTTSExecutionErrorHandler),this.props.graphModel.removeListener("updateActiveGraph",this._onUpdateActiveGraphHandler)}onTTSExecuted(t){this.setState({status:"OK"})}onTTSExecutionErrorHandler(t){this.setState({status:t})}onUpdateActiveGraph(){let t=this.props.graphModel.getSavedTTSList()[0];this.setState(e=>({activeTTS:t||{name:"",prompt:""},selectedCyperIndex:0,status:""}))}handleInputChange(t){let e=t.nativeEvent,n=this.state.activeTTS;switch(e.target.name){case"promptName":n.name=e.target.value;break;case"prompt":n.prompt=e.target.value;break;case"promptStatus":this.setState({status:e.target.value})}this.setState({activeTTS:n})}handleSubmit(t){t.preventDefault()}onButtonClicked(t){switch(t){case"run":this.sendTTS(this.state.activeTTS);break;case"new":this.newSavedTTS();break;case"delete":this.deleteSlectedTTS(this.state.activeTTS.index)}}onItemClicked(t){let e=this.props.graphModel.getSavedTTSList()[t];e&&this.setState({activeTTS:e,selectedCyperIndex:t});let n=(new Date).getTime(),i=n-this._itemClickedPrevTime;this._itemClickedPrevTime=n,i<200&&this.sendTTS(e)}sendTTS(t){this.props.graphModel.sendTTS(t)}newSavedTTS(){let t=this.props.graphModel.newSavedTTS();console.log(`newSavedTTS: ${t}`),this.setState(e=>({activeTTS:this.props.graphModel.getSavedTTSList()[t],selectedCyperIndex:t}))}deleteSlectedTTS(t){let e=this.props.graphModel.deleteSavedTTS(this.state.activeTTS);this.setState({activeTTS:this.props.graphModel.getSavedTTSList()[e],selectedCyperIndex:e})}renderItem(t,e){let n=this._savedTTSList[t],o="item"+(t%2?"":" even");return t==this.state.selectedCyperIndex&&(o+=" selected"),i.createElement("div",{key:e,className:o,onClick:this.onItemClicked.bind(this,t)},n.name)}handleClick(t){this.props.graphModel.bringPanelToFront(this.props.id)}handleClose(t){this.props.onClosePanel(this.props.id)}handleMinimize(t){console.log("minimize")}handleMaximize(t){console.log("maximize")}handleFullScreen(t){console.log("fullscreen")}render(){return this._savedTTSList=this.props.graphModel.getSavedTTSList(),this._savedTTSListLength=this._savedTTSList.length,i.createElement(r.a,{handle:".handle"},i.createElement("div",{className:"editor-panel well",id:"ttsPanel"},i.createElement(m,{draggable:!0,handleClick:this.handleClick.bind(this),handleClose:this.handleClose.bind(this),handleMinimize:this.handleMinimize.bind(this),handleMaximize:this.handleMaximize.bind(this),handleFullScreen:this.handleFullScreen.bind(this)}),i.createElement("h4",{className:"pull-left handle",style:{marginBottom:20}},"Saved TTSs"),i.createElement("div",{className:"clearfix"}),i.createElement(a.Table,{striped:!0,bordered:!0,condensed:!0,hover:!0,style:{width:400}},i.createElement("tbody",null,i.createElement("tr",null,i.createElement("td",null,"name:"),i.createElement("td",null,i.createElement("input",{name:"promptName",value:this.state.activeTTS.name,onChange:this.handleInputChange.bind(this),style:{width:400}}))),i.createElement("tr",null,i.createElement("td",null,"prompt:"),i.createElement("td",null,i.createElement("textarea",{name:"prompt",value:this.state.activeTTS.prompt,onChange:this.handleInputChange.bind(this),style:{width:400,height:50}}))),i.createElement("tr",null,i.createElement("td",null,"saved:"),i.createElement("td",null,i.createElement("div",{style:{overflow:"auto",height:200,maxHeight:200}},i.createElement(Ho,{itemRenderer:this.renderItem.bind(this),length:this._savedTTSListLength,type:"uniform"})))))),i.createElement(a.Button,{bsStyle:"default",key:"run",style:{width:80},onClick:this.onButtonClicked.bind(this,"run")},"Run"),i.createElement(a.Button,{bsStyle:"default",key:"new",style:{width:80},onClick:this.onButtonClicked.bind(this,"new")},"New"),i.createElement(a.Button,{bsStyle:"default",key:"delete",style:{width:80},onClick:this.onButtonClicked.bind(this,"delete")},"Delete")))}}class Oo extends i.Component{constructor(t){super(t),this._savedScriptList=[],this._savedScriptListLength=0,this._onScriptExecutedHandler=this.onScriptExecuted.bind(this),this._onScriptExecutionErrorHandler=this.onScriptExecutionErrorHandler.bind(this),this._onUpdateActiveGraphHandler=this.onUpdateActiveGraph.bind(this),this._itemClickedPrevTime=0}componentWillMount(){let t=this.props.graphModel.getSavedScriptList()[0];this.setState(e=>({activeScript:t||{name:"",script:"