(function(K,Q){typeof exports=="object"&&typeof module<"u"?module.exports=Q():typeof define=="function"&&define.amd?define(Q):(K=typeof globalThis<"u"?globalThis:K||self,K.RosClient=Q())})(this,function(){"use strict";var Xr=Object.defineProperty;var Yr=(K,Q,re)=>Q in K?Xr(K,Q,{enumerable:!0,configurable:!0,writable:!0,value:re}):K[Q]=re;var H=(K,Q,re)=>Yr(K,typeof Q!="symbol"?Q+"":Q,re);var K=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Q(m){return m&&m.__esModule&&Object.prototype.hasOwnProperty.call(m,"default")?m.default:m}var re={exports:{}};/*!
* EventEmitter2
* https://github.com/hij1nx/EventEmitter2
*
* Copyright (c) 2013 hij1nx
* Licensed under the MIT license.
*/(function(m,r){(function(n){var i=Object.hasOwnProperty,s=Array.isArray?Array.isArray:function(t){return Object.prototype.toString.call(t)==="[object Array]"},l=10,b=typeof process=="object"&&typeof process.nextTick=="function",g=typeof Symbol=="function",d=typeof Reflect=="object",v=typeof setImmediate=="function",o=v?setImmediate:setTimeout,a=g?d&&typeof Reflect.ownKeys=="function"?Reflect.ownKeys:function(e){var t=Object.getOwnPropertyNames(e);return t.push.apply(t,Object.getOwnPropertySymbols(e)),t}:Object.keys;function f(){this._events={},this._conf&&u.call(this,this._conf)}function u(e){e&&(this._conf=e,e.delimiter&&(this.delimiter=e.delimiter),e.maxListeners!==n&&(this._maxListeners=e.maxListeners),e.wildcard&&(this.wildcard=e.wildcard),e.newListener&&(this._newListener=e.newListener),e.removeListener&&(this._removeListener=e.removeListener),e.verboseMemoryLeak&&(this.verboseMemoryLeak=e.verboseMemoryLeak),e.ignoreErrors&&(this.ignoreErrors=e.ignoreErrors),this.wildcard&&(this.listenerTree={}))}function S(e,t){var c="(node) warning: possible EventEmitter memory leak detected. "+e+" listeners added. Use emitter.setMaxListeners() to increase limit.";if(this.verboseMemoryLeak&&(c+=" Event name: "+t+"."),typeof process<"u"&&process.emitWarning){var h=new Error(c);h.name="MaxListenersExceededWarning",h.emitter=this,h.count=e,process.emitWarning(h)}else console.error(c),console.trace&&console.trace()}var O=function(e,t,c){var h=arguments.length;switch(h){case 0:return[];case 1:return[e];case 2:return[e,t];case 3:return[e,t,c];default:for(var p=new Array(h);h--;)p[h]=arguments[h];return p}};function k(e,t){for(var c={},h,p=e.length,y=0,w=0;w
0;)e=y[_],w.call(T,e,c[e]);this._listeners={},this._listenersCount=0,x()}}});function M(e,t,c,h){var p=Object.assign({},t);if(!e)return p;if(typeof e!="object")throw TypeError("options must be an object");var y=Object.keys(e),w=y.length,T,_,x;function C(I){throw Error('Invalid "'+T+'" option value'+(I?". Reason: "+I:""))}for(var W=0;W0;)if(T===e[_])return y;w(t)}}var D=q(["function"]),z=q(["object","function"]);function X(e,t,c){var h,p,y=0,w,T=new e(function(_,x,C){c=M(c,{timeout:0,overload:!1},{timeout:function(V,J){return V*=1,(typeof V!="number"||V<0||!Number.isFinite(V))&&J("timeout must be a positive number"),V}}),h=!c.overload&&typeof e.prototype.cancel=="function"&&typeof C=="function";function W(){p&&(p=null),y&&(clearTimeout(y),y=0)}var I=function(V){W(),_(V)},G=function(V){W(),x(V)};h?t(I,G,C):(p=[function(V){G(V||Error("canceled"))}],t(I,G,function(V){if(w)throw Error("Unable to subscribe on cancel event asynchronously");if(typeof V!="function")throw TypeError("onCancel callback must be a function");p.push(V)}),w=!0),c.timeout>0&&(y=setTimeout(function(){var V=Error("timeout");V.code="ETIMEDOUT",y=0,T.cancel(V),x(V)},c.timeout))});return h||(T.cancel=function(_){if(p){for(var x=p.length,C=1;C0;)G=ee[T],G!=="_listeners"&&(Y=B(e,t,c[G],h+1,p),Y&&(I?I.push.apply(I,Y):I=Y));return I}else if(me==="**"){for(ft=h+1===p||h+2===p&&ht==="*",ft&&c._listeners&&(I=B(e,t,c,p,p)),ee=a(c),T=ee.length;T-- >0;)G=ee[T],G!=="_listeners"&&(G==="*"||G==="**"?(c[G]._listeners&&!ft&&(Y=B(e,t,c[G],p,p),Y&&(I?I.push.apply(I,Y):I=Y)),Y=B(e,t,c[G],h,p)):G===ht?Y=B(e,t,c[G],h+2,p):Y=B(e,t,c[G],h,p),Y&&(I?I.push.apply(I,Y):I=Y));return I}else c[me]&&(I=B(e,t,c[me],h+1,p));if(V=c["*"],V&&B(e,t,V,h+1,p),J=c["**"],J)if(h0;)G=ee[T],G!=="_listeners"&&(G===ht?B(e,t,J[G],h+2,p):G===me?B(e,t,J[G],h+1,p):(lt={},lt[G]=J[G],B(e,t,{"**":lt},h+1,p)));else J._listeners?B(e,t,J,p,p):J["*"]&&J["*"]._listeners&&B(e,t,J["*"],p,p);return I}function $(e,t,c){var h=0,p=0,y,w=this.delimiter,T=w.length,_;if(typeof e=="string")if((y=e.indexOf(w))!==-1){_=new Array(5);do _[h++]=e.slice(p,y),p=y+T;while((y=e.indexOf(w,p))!==-1);_[h++]=e.slice(p)}else _=[e],h=1;else _=e,h=e.length;if(h>1){for(y=0;y+10&&x._listeners.length>this._maxListeners&&(x._listeners.warned=!0,S.call(this,x._listeners.length,C))):x._listeners=t,!0;return!0}function R(e,t,c,h){for(var p=a(e),y=p.length,w,T,_,x=e._listeners,C;y-- >0;)T=p[y],w=e[T],T==="_listeners"?_=c:_=c?c.concat(T):[T],C=h||typeof T=="symbol",x&&t.push(C?_:_.join(this.delimiter)),typeof w=="object"&&R.call(this,w,t,_,C);return t}function F(e){for(var t=a(e),c=t.length,h,p,y;c-- >0;)p=t[c],h=e[p],h&&(y=!0,p!=="_listeners"&&!F(h)&&delete e[p]);return y}function U(e,t,c){this.emitter=e,this.event=t,this.listener=c}U.prototype.off=function(){return this.emitter.off(this.event,this.listener),this};function N(e,t,c){if(c===!0)p=!0;else if(c===!1)h=!0;else{if(!c||typeof c!="object")throw TypeError("options should be an object or true");var h=c.async,p=c.promisify,y=c.nextTick,w=c.objectify}if(h||y||p){var T=t,_=t._origin||t;if(y&&!b)throw Error("process.nextTick is not supported");p===n&&(p=t.constructor.name==="AsyncFunction"),t=function(){var x=arguments,C=this,W=this.event;return p?y?Promise.resolve():new Promise(function(I){o(I)}).then(function(){return C.event=W,T.apply(C,x)}):(y?process.nextTick:o)(function(){C.event=W,T.apply(C,x)})},t._async=!0,t._origin=_}return[t,w?new U(this,e,t):this]}function E(e){this._events={},this._newListener=!1,this._removeListener=!1,this.verboseMemoryLeak=!1,u.call(this,e)}E.EventEmitter2=E,E.prototype.listenTo=function(e,t,c){if(typeof e!="object")throw TypeError("target musts be an object");var h=this;c=M(c,{on:n,off:n,reducers:n},{on:D,off:D,reducers:z});function p(y){if(typeof y!="object")throw TypeError("events must be an object");var w=c.reducers,T=Z.call(h,e),_;T===-1?_=new L(h,e,c):_=h._observers[T];for(var x=a(y),C=x.length,W,I=typeof w=="function",G=0;G0;)p=c[h],(!e||p._target===e)&&(p.unsubscribe(t),y=!0);return y},E.prototype.delimiter=".",E.prototype.setMaxListeners=function(e){e!==n&&(this._maxListeners=e,this._conf||(this._conf={}),this._conf.maxListeners=e)},E.prototype.getMaxListeners=function(){return this._maxListeners},E.prototype.event="",E.prototype.once=function(e,t,c){return this._once(e,t,!1,c)},E.prototype.prependOnceListener=function(e,t,c){return this._once(e,t,!0,c)},E.prototype._once=function(e,t,c,h){return this._many(e,1,t,c,h)},E.prototype.many=function(e,t,c,h){return this._many(e,t,c,!1,h)},E.prototype.prependMany=function(e,t,c,h){return this._many(e,t,c,!0,h)},E.prototype._many=function(e,t,c,h,p){var y=this;if(typeof c!="function")throw new Error("many only accepts instances of Function");function w(){return--t===0&&y.off(e,w),c.apply(this,arguments)}return w._origin=c,this._on(e,w,h,p)},E.prototype.emit=function(){if(!this._events&&!this._all)return!1;this._events||f.call(this);var e=arguments[0],t,c=this.wildcard,h,p,y,w,T;if(e==="newListener"&&!this._newListener&&!this._events.newListener)return!1;if(c&&(t=e,e!=="newListener"&&e!=="removeListener"&&typeof e=="object")){if(p=e.length,g){for(y=0;y3)for(h=new Array(_-1),w=1;w<_;w++)h[w-1]=arguments[w];for(y=0,p=x.length;y
3)for(p=new Array(x-1),T=1;T0&&this._events[e].length>this._maxListeners&&(this._events[e].warned=!0,S.call(this,this._events[e].length,e))):this._events[e]=t,p)},E.prototype.off=function(e,t){if(typeof t!="function")throw new Error("removeListener only takes instances of Function");var c,h=[];if(this.wildcard){var p=typeof e=="string"?e.split(this.delimiter):e.slice();if(h=B.call(this,null,p,this.listenerTree,0),!h)return this}else{if(!this._events[e])return this;c=this._events[e],h.push({_listeners:c})}for(var y=0;y0){for(h=this._all,t=0,c=h.length;t0;)h=t[c[y]],typeof h=="function"?p.push(h):p.push.apply(p,h);return p}else{if(this.wildcard){if(w=this.listenerTree,!w)return[];var T=[],_=typeof e=="string"?e.split(this.delimiter):e.slice();return B.call(this,T,_,w,0),T}return t?(h=t[e],h?typeof h=="function"?[h]:h:[]):[]}},E.prototype.eventNames=function(e){var t=this._events;return this.wildcard?R.call(this,this.listenerTree,[],null,e):t?a(t):[]},E.prototype.listenerCount=function(e){return this.listeners(e).length},E.prototype.hasListeners=function(e){if(this.wildcard){var t=[],c=typeof e=="string"?e.split(this.delimiter):e.slice();return B.call(this,t,c,this.listenerTree,0),t.length>0}var h=this._events,p=this._all;return!!(p&&p.length||h&&(e===n?a(h).length:h[e]))},E.prototype.listenersAny=function(){return this._all?this._all:[]},E.prototype.waitFor=function(e,t){var c=this,h=typeof t;return h==="number"?t={timeout:t}:h==="function"&&(t={filter:t}),t=M(t,{timeout:0,filter:n,handleError:!1,Promise,overload:!1},{filter:D,Promise:A}),X(t.Promise,function(p,y,w){function T(){var _=t.filter;if(!(_&&!_.apply(c,arguments)))if(c.off(e,T),t.handleError){var x=arguments[0];x?y(x):p(O.apply(null,arguments).slice(1))}else p(O.apply(null,arguments))}w(function(){c.off(e,T)}),c._on(e,T,!1)},{timeout:t.timeout,overload:t.overload})};function P(e,t,c){c=M(c,{Promise,timeout:0,overload:!1},{Promise:A});var h=c.Promise;return X(h,function(p,y,w){var T;if(typeof e.addEventListener=="function"){T=function(){p(O.apply(null,arguments))},w(function(){e.removeEventListener(t,T)}),e.addEventListener(t,T,{once:!0});return}var _=function(){x&&e.removeListener("error",x),p(O.apply(null,arguments))},x;t!=="error"&&(x=function(C){e.removeListener(t,_),y(C)},e.once("error",x)),w(function(){x&&e.removeListener("error",x),e.removeListener(t,_)}),e.once(t,_)},{timeout:c.timeout,overload:c.overload})}var j=E.prototype;Object.defineProperties(E,{defaultMaxListeners:{get:function(){return j._maxListeners},set:function(e){if(typeof e!="number"||e<0||Number.isNaN(e))throw TypeError("n must be a non-negative number");j._maxListeners=e},enumerable:!0},once:{value:P,writable:!0,configurable:!0}}),Object.defineProperties(j,{_maxListeners:{value:l,writable:!0,configurable:!0},_observers:{value:null,writable:!0,configurable:!0}}),m.exports=E})()})(re);var te=re.exports;const dr=Q(te);/*
object-assign
(c) Sindre Sorhus
@license MIT
*/var vt=Object.getOwnPropertySymbols,gr=Object.prototype.hasOwnProperty,yr=Object.prototype.propertyIsEnumerable;function wr(m){if(m==null)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(m)}function _r(){try{if(!Object.assign)return!1;var m=new String("abc");if(m[5]="de",Object.getOwnPropertyNames(m)[0]==="5")return!1;for(var r={},n=0;n<10;n++)r["_"+String.fromCharCode(n)]=n;var i=Object.getOwnPropertyNames(r).map(function(l){return r[l]});if(i.join("")!=="0123456789")return!1;var s={};return"abcdefghijklmnopqrst".split("").forEach(function(l){s[l]=l}),Object.keys(Object.assign({},s)).join("")==="abcdefghijklmnopqrst"}catch{return!1}}var ie=_r()?Object.assign:function(m,r){for(var n,i=wr(m),s,l=1;l0},!1)}function d(v,o){for(var a={main:[o]},f={main:[]},u={main:{}};g(a);)for(var S=Object.keys(a),O=0;O>2,P=0;P>6),U.push(128|N&63)):N<55296?(U.push(224|N>>12),U.push(128|N>>6&63),U.push(128|N&63)):(N=(N&1023)<<10,N|=R.charCodeAt(++F)&1023,N+=65536,U.push(240|N>>18),U.push(128|N>>12&63),U.push(128|N>>6&63),U.push(128|N&63))}return z(3,U.length),M(U);default:var E;if(Array.isArray(R))for(E=R.length,z(4,E),F=0;F>5!==U)throw"Invalid indefinite length element";return E}function $(U,N){for(var E=0;E>10),U.push(56320|P&1023))}}function R(){var U=A(),N=U>>5,E=U&31,P,j;if(N===7)switch(E){case 25:return k();case 26:return L();case 27:return M()}if(j=Z(E),j<0&&(N<2||6=0;)t+=j,e.push(O(j));var c=new Uint8Array(t),h=0;for(P=0;P=0;)$(p,j);else $(p,j);return String.fromCharCode.apply(null,p);case 4:var y;if(j<0)for(y=[];!X();)y.push(R());else for(y=new Array(j),P=0;P"u"?this.groovyCompatibility=!0:this.groovyCompatibility=d.groovyCompatibility,this.setMaxListeners(0),d.url&&this.connect(d.url)}return g.prototype.__proto__=b.prototype,g.prototype.connect=function(d){if(this.transportLibrary==="socket.io")this.socket=l(io(d,{"force new connection":!0}),n(this)),this.socket.on("connect",this.socket.onopen),this.socket.on("data",this.socket.onmessage),this.socket.on("close",this.socket.onclose),this.socket.on("error",this.socket.onerror);else if(this.transportLibrary.constructor.name==="RTCPeerConnection")this.socket=l(this.transportLibrary.createDataChannel(d,this.transportOptions),n(this));else if(this.transportLibrary==="websocket"){if(!this.socket||this.socket.readyState===m.CLOSED){var v=new m(d);v.binaryType="arraybuffer",this.socket=l(v,n(this))}}else if(this.transportLibrary==="workersocket")this.socket=l(new r(d),n(this));else throw"Unknown transportLibrary: "+this.transportLibrary.toString()},g.prototype.close=function(){this.socket&&this.socket.close()},g.prototype.authenticate=function(d,v,o,a,f,u,S){var O={op:"auth",mac:d,client:v,dest:o,rand:a,t:f,level:u,end:S};this.callOnConnection(O)},g.prototype.sendEncodedMessage=function(d){var v=null,o=this;this.transportLibrary==="socket.io"?v=function(a){o.socket.emit("operation",a)}:v=function(a){o.socket.send(a)},this.isConnected?v(d):o.once("connection",function(){v(d)})},g.prototype.callOnConnection=function(d){this.transportOptions.encoder?this.transportOptions.encoder(d,this._sendFunc):this._sendFunc(JSON.stringify(d))},g.prototype.setStatusLevel=function(d,v){var o={op:"set_level",level:d,id:v};this.callOnConnection(o)},g.prototype.getActionServers=function(d,v){var o=new i({ros:this,name:"/rosapi/action_servers",serviceType:"rosapi/GetActionServers"}),a=new s({});typeof v=="function"?o.callService(a,function(f){d(f.action_servers)},function(f){v(f)}):o.callService(a,function(f){d(f.action_servers)})},g.prototype.getTopics=function(d,v){var o=new i({ros:this,name:"/rosapi/topics",serviceType:"rosapi/Topics"}),a=new s;typeof v=="function"?o.callService(a,function(f){d(f)},function(f){v(f)}):o.callService(a,function(f){d(f)})},g.prototype.getTopicsForType=function(d,v,o){var a=new i({ros:this,name:"/rosapi/topics_for_type",serviceType:"rosapi/TopicsForType"}),f=new s({type:d});typeof o=="function"?a.callService(f,function(u){v(u.topics)},function(u){o(u)}):a.callService(f,function(u){v(u.topics)})},g.prototype.getServices=function(d,v){var o=new i({ros:this,name:"/rosapi/services",serviceType:"rosapi/Services"}),a=new s;typeof v=="function"?o.callService(a,function(f){d(f.services)},function(f){v(f)}):o.callService(a,function(f){d(f.services)})},g.prototype.getServicesForType=function(d,v,o){var a=new i({ros:this,name:"/rosapi/services_for_type",serviceType:"rosapi/ServicesForType"}),f=new s({type:d});typeof o=="function"?a.callService(f,function(u){v(u.services)},function(u){o(u)}):a.callService(f,function(u){v(u.services)})},g.prototype.getServiceRequestDetails=function(d,v,o){var a=new i({ros:this,name:"/rosapi/service_request_details",serviceType:"rosapi/ServiceRequestDetails"}),f=new s({type:d});typeof o=="function"?a.callService(f,function(u){v(u)},function(u){o(u)}):a.callService(f,function(u){v(u)})},g.prototype.getServiceResponseDetails=function(d,v,o){var a=new i({ros:this,name:"/rosapi/service_response_details",serviceType:"rosapi/ServiceResponseDetails"}),f=new s({type:d});typeof o=="function"?a.callService(f,function(u){v(u)},function(u){o(u)}):a.callService(f,function(u){v(u)})},g.prototype.getNodes=function(d,v){var o=new i({ros:this,name:"/rosapi/nodes",serviceType:"rosapi/Nodes"}),a=new s;typeof v=="function"?o.callService(a,function(f){d(f.nodes)},function(f){v(f)}):o.callService(a,function(f){d(f.nodes)})},g.prototype.getNodeDetails=function(d,v,o){var a=new i({ros:this,name:"/rosapi/node_details",serviceType:"rosapi/NodeDetails"}),f=new s({node:d});typeof o=="function"?a.callService(f,function(u){v(u.subscribing,u.publishing,u.services)},function(u){o(u)}):a.callService(f,function(u){v(u)})},g.prototype.getParams=function(d,v){var o=new i({ros:this,name:"/rosapi/get_param_names",serviceType:"rosapi/GetParamNames"}),a=new s;typeof v=="function"?o.callService(a,function(f){d(f.names)},function(f){v(f)}):o.callService(a,function(f){d(f.names)})},g.prototype.getTopicType=function(d,v,o){var a=new i({ros:this,name:"/rosapi/topic_type",serviceType:"rosapi/TopicType"}),f=new s({topic:d});typeof o=="function"?a.callService(f,function(u){v(u.type)},function(u){o(u)}):a.callService(f,function(u){v(u.type)})},g.prototype.getServiceType=function(d,v,o){var a=new i({ros:this,name:"/rosapi/service_type",serviceType:"rosapi/ServiceType"}),f=new s({service:d});typeof o=="function"?a.callService(f,function(u){v(u.type)},function(u){o(u)}):a.callService(f,function(u){v(u.type)})},g.prototype.getMessageDetails=function(d,v,o){var a=new i({ros:this,name:"/rosapi/message_details",serviceType:"rosapi/MessageDetails"}),f=new s({type:d});typeof o=="function"?a.callService(f,function(u){v(u.typedefs)},function(u){o(u)}):a.callService(f,function(u){v(u.typedefs)})},g.prototype.decodeTypeDefs=function(d){var v=this,o=function(a,f){for(var u={},S=0;Sa.secs?!1:o.secs0&&(this.textureFilename=s[0].getAttribute("filename"));var l=i.xml.getElementsByTagName("color");l.length>0&&(this.color=new m({xml:l[0]}))}r.prototype.isLink=function(){return this.color===null&&this.textureFilename===null};var n=ie;return r.prototype.assign=function(i){return n(this,i)},tt=r,tt}var it,sr;function nr(){if(sr)return it;sr=1;var m=se(),r=fe();function n(i){this.scale=null,this.type=r.URDF_MESH,this.filename=i.xml.getAttribute("filename");var s=i.xml.getAttribute("scale");if(s){var l=s.split(" ");this.scale=new m({x:parseFloat(l[0]),y:parseFloat(l[1]),z:parseFloat(l[2])})}}return it=n,it}var st,or;function ar(){if(or)return st;or=1;var m=fe();function r(n){this.type=m.URDF_SPHERE,this.radius=parseFloat(n.xml.getAttribute("radius"))}return st=r,st}var nt,cr;function ur(){if(cr)return nt;cr=1;var m=Je(),r=se(),n=le(),i=rr(),s=Kt(),l=rt(),b=nr(),g=ar();function d(v){var o=v.xml;this.origin=null,this.geometry=null,this.material=null,this.name=v.xml.getAttribute("name");var a=o.getElementsByTagName("origin");if(a.length===0)this.origin=new m;else{var f=a[0].getAttribute("xyz"),u=new r;f&&(f=f.split(" "),u=new r({x:parseFloat(f[0]),y:parseFloat(f[1]),z:parseFloat(f[2])}));var S=a[0].getAttribute("rpy"),O=new n;if(S){S=S.split(" ");var k=parseFloat(S[0]),L=parseFloat(S[1]),M=parseFloat(S[2]),A=k/2,q=L/2,D=M/2,z=Math.sin(A)*Math.cos(q)*Math.cos(D)-Math.cos(A)*Math.sin(q)*Math.sin(D),X=Math.cos(A)*Math.sin(q)*Math.cos(D)+Math.sin(A)*Math.cos(q)*Math.sin(D),Z=Math.cos(A)*Math.cos(q)*Math.sin(D)-Math.sin(A)*Math.sin(q)*Math.cos(D),B=Math.cos(A)*Math.cos(q)*Math.cos(D)+Math.sin(A)*Math.sin(q)*Math.sin(D);O=new n({x:z,y:X,z:Z,w:B}),O.normalize()}this.origin=new m({position:u,orientation:O})}var $=o.getElementsByTagName("geometry");if($.length>0){for(var R=$[0],F=null,U=0;U0&&(this.material=new l({xml:P[0]}))}return nt=d,nt}var ot,lr;function fr(){if(lr)return ot;lr=1;var m=ur();function r(n){this.name=n.xml.getAttribute("name"),this.visuals=[];for(var i=n.xml.getElementsByTagName("visual"),s=0;s0&&(this.parent=l[0].getAttribute("link"));var b=s.xml.getElementsByTagName("child");b.length>0&&(this.child=b[0].getAttribute("link"));var g=s.xml.getElementsByTagName("limit");g.length>0&&(this.minval=parseFloat(g[0].getAttribute("lower")),this.maxval=parseFloat(g[0].getAttribute("upper")));var d=s.xml.getElementsByTagName("origin");if(d.length===0)this.origin=new m;else{var v=d[0].getAttribute("xyz"),o=new r;v&&(v=v.split(" "),o=new r({x:parseFloat(v[0]),y:parseFloat(v[1]),z:parseFloat(v[2])}));var a=d[0].getAttribute("rpy"),f=new n;if(a){a=a.split(" ");var u=parseFloat(a[0]),S=parseFloat(a[1]),O=parseFloat(a[2]),k=u/2,L=S/2,M=O/2,A=Math.sin(k)*Math.cos(L)*Math.cos(M)-Math.cos(k)*Math.sin(L)*Math.sin(M),q=Math.cos(k)*Math.sin(L)*Math.cos(M)+Math.sin(k)*Math.cos(L)*Math.sin(M),D=Math.cos(k)*Math.cos(L)*Math.sin(M)-Math.sin(k)*Math.sin(L)*Math.cos(M),z=Math.cos(k)*Math.cos(L)*Math.cos(M)+Math.sin(k)*Math.sin(L)*Math.sin(M);f=new n({x:A,y:q,z:D,w:z}),f.normalize()}this.origin=new m({position:o,orientation:f})}}return at=i,at}var he={},vr;function Dr(){return vr||(vr=1,he.DOMImplementation=window.DOMImplementation,he.XMLSerializer=window.XMLSerializer,he.DOMParser=window.DOMParser),he}var ct,pr;function Ir(){if(pr)return ct;pr=1;var m=rt(),r=fr(),n=jr(),i=Dr().DOMParser;function s(l){l=l||{};var b=l.xml,g=l.string;if(this.materials={},this.links={},this.joints={},g){var d=new i;b=d.parseFromString(g,"text/xml")}var v=b.documentElement;this.name=v.getAttribute("name");for(var o=v.childNodes,a=0;a{this.connected&&this.emit(pe.EVENT_DISCONNECTED),this.connected=!1,this.connectScheduled||(this.connectScheduled=!0,setTimeout(this.connect,this.options.reconnectInterval))});H(this,"onSuccess",()=>{this.connected||(this.connected=!0,this.emit(pe.EVENT_CONNECTED,this.rosInstance))});H(this,"connect",()=>{this.connectScheduled=!1,this.rosInstance=new ne.Ros({url:this.options.url}),this.rosInstance.on("close",this.onFail),this.rosInstance.on("error",this.onFail),this.rosInstance.on("connection",this.onSuccess)});H(this,"getInstance",async()=>this.connected?this.rosInstance:new Promise(n=>this.on(pe.EVENT_CONNECTED,n)));this.connected=!1,this.connectScheduled=!1,this.rosInstance=null,this.options=n,this.connect()}}class Vr{constructor(r){H(this,"call",(r,n,i)=>this.connection.getInstance().then(s=>new Promise((l,b)=>{const g=new ne.Service({ros:s,name:r,serviceType:n}),d=new ne.ServiceRequest(i);g.callService(d,l,b)})));this.connection=r}}class Wr{constructor(r){H(this,"getSignature",(r,n)=>`${n}/${r}`);H(this,"listen",(r,n,i,s)=>{this.registeredTopics[s].listener=new ne.Topic({ros:r,name:n,messageType:i}),this.registeredTopics[s].listener.subscribe(l=>{const b=this.registeredTopics[s].handlers.length;for(let g=0;gthis.connection.getInstance().then(s=>{this.listen(s,r,n,i)}));H(this,"publish",(r,n,i)=>this.connection.getInstance().then(s=>{const l=new ne.Topic({ros:s,name:r,messageType:n}),b=new ne.Message(i);l.publish(b)}));H(this,"subscribe",(r,n,i)=>{const s=this.getSignature(r,n);return s in this.registeredTopics?this.registeredTopics[s].handlers.push(i):(this.registeredTopics[s]={options:{name:r,messageType:n},listener:void 0,handlers:[i]},this.connectAndListen(r,n,s)),{dispose:()=>{const l=this.registeredTopics[s].handlers.indexOf(i);l!==-1&&(this.registeredTopics[s].handlers.splice(l,1),!this.registeredTopics[s].handlers.length&&this.registeredTopics[s].listener&&(this.registeredTopics[s].listener.unsubscribe(),this.registeredTopics[s].listener=null,delete this.registeredTopics[s]))}}});H(this,"onDisconnected",()=>{for(const r of Object.values(this.registeredTopics))r.listener&&(r.listener.unsubscribe(),r.listener=null)});H(this,"onConnected",r=>{Object.keys(this.registeredTopics).forEach(n=>{const i=this.registeredTopics[n];i.listener===null&&i.handlers.length&&(this.listen(r,i.options.name,i.options.messageType,n),i.listener=null)})});this.connection=r,this.registeredTopics={},this.connection.on(pe.EVENT_DISCONNECTED,this.onDisconnected),this.connection.on(pe.EVENT_CONNECTED,this.onConnected)}}class Jr{constructor(r){H(this,"get",r=>this.connection.getInstance().then(n=>new ne.TFClient({...r,ros:n})));this.connection=r}}class Qr{constructor(r){const n=new zr({url:"ws://localhost:9090",reconnectInterval:5e3,...r});n.setMaxListeners(500),this.connection=n,this.service=new Vr(n),this.topic=new Wr(n),this.tfClient=new Jr(n)}}return Qr});