@hpcc-js/util 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1624 -1
- package/dist/index.js.map +1 -7
- package/dist/index.umd.cjs +2 -0
- package/dist/index.umd.cjs.map +1 -0
- package/package.json +13 -9
- package/src/__package__.ts +1 -1
- package/types/__package__.d.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -1,2 +1,1625 @@
|
|
|
1
|
-
var xe="@hpcc-js/util",Ee="3.2.0",me="3.2.0";function Se(n,e){if(n==null)throw new TypeError('"o" is null or not defined');let t=n.length>>>0;if(typeof e!="function")throw new TypeError("predicate must be a function");let r=arguments[1],s=0;for(;s<t;){let i=n[s];if(e.call(r,i,s))return i;s++}}function ye(n,e){let t={update:[],exit:[],enter:[...e]};for(let r of n){let s=t.enter.indexOf(r);s>=0?(t.update.push(r),t.enter.splice(s,1)):t.exit.push(r)}return t}function M(n,e,t,r=(s,i)=>i){let s={update:[],exit:[],enter:[]};if(n===e)return s.update=n,s;let i={};e.forEach(o=>{i[t(o)]=o});for(let o of n){let a=t(o),h=i[a];h!==void 0?(delete i[a],s.update.push(r(o,h))):s.exit.push(o)}for(let o in i)s.enter.push(i[o]);return s}function ue(n,e){for(;n.length<e;)n="0"+n;return n}function b(n,e){if(e.length===0)return n;for(let t=0;t<e.length;++t){let r=e.charCodeAt(t);n=(n<<5)-n+r,n|=0}return n<0?n*-2:n}function ce(n,e,t){return typeof e.hashSum=="function"?e.hashSum():Object.keys(e).sort().reduce((r,s)=>J(r,e[s],s,t),n)}function J(n,e,t,r){let s=b(b(b(n,t),pe(e)),typeof e);return e===null?b(s,"null"):e===void 0?b(s,"undefined"):typeof e=="object"?r.indexOf(e)!==-1?b(s,"[Circular]"+t):(r.push(e),ce(s,e,r)):b(s,e.toString())}function pe(n){return Object.prototype.toString.call(n)}function E(n){return ue(J(0,n,"",[]).toString(16),8)}var Q=class{_cache={};_calcID;static hash(...e){return E({...e})}constructor(e){this._calcID=e}has(e){return this._calcID(e)in this._cache}set(e){return this._cache[this._calcID(e)]=e,e}get(e,t){let r=this._cache[this._calcID(e)];return r||(t?this.set(t()):null)}},Y=class{_cache={};_calcID;static hash(...e){return E({...e})}constructor(e){this._calcID=e}has(e){return this._calcID(e)in this._cache}set(e,t){return this._cache[this._calcID(e)]=t,t}get(e,t){let r=this._cache[this._calcID(e)];return r||(t?this.set(e,t()):Promise.resolve(null))}};function ke(n,e){let t={};return(...r)=>{let s=E(r);return t[s]||(t[s]={clockStart:Date.now(),promise:n(...r).then(i=>(e===void 0?t[s]=null:setTimeout(()=>{t[s]=null},Math.max(e-(Date.now()-t[s].clockStart),0)),i)).catch(i=>{throw t[s]=null,i})}),t[s].promise}}function Pe(n,e){let t,r=new Promise((s,i)=>{t=setTimeout(()=>{clearTimeout(t),i("Timed out in "+n+"ms.")},n)});return Promise.race([e,r]).then(s=>(clearTimeout(t),s)).catch(s=>{throw clearTimeout(t),s})}var Z=class{_q=[];isTop(e){return this._q[0]===e}push(e){let t=e.then(r=>this.isTop(t)?(this._q.shift(),r):new Promise((s,i)=>{let o=setInterval(()=>{this.isTop(t)&&(clearInterval(o),this._q.shift(),s(r))},20)}));return this._q.push(t),t}};function De(n){return new Promise(e=>{setTimeout(()=>e(),n)})}var A=class{store={};constructor(e){if(e)for(let t in e)this.set(t,e[t])}set(e,t){let r=this.store[e];return this.store[e]=t,r}get(e){return this.store[e]}has(e){return this.store[e]!==void 0}remove(e){delete this.store[e]}keys(){let e=[];for(let t in this.store)e.push(t);return e}values(){let e=[];for(let t in this.store)e.push(this.store[t]);return e}},ee=class extends A{constructor(e){super(e)}set(e,t){return super.set(e.toLowerCase(),t)}get(e){return super.get(e.toLowerCase())}has(e){return super.has(e.toLowerCase())}remove(e){return super.remove(e.toLowerCase())}};function Fe(n){if(n){if(!isNaN(Number(n)))return Number(n)}else return 0;let e=n.indexOf("ns");if(e!==-1)return parseFloat(n.substr(0,e))/1e9;let t=n.indexOf("ms");if(t!==-1)return parseFloat(n.substr(0,t))/1e3;let r=n.indexOf("s");if(r!==-1&&n.indexOf("days")===-1)return parseFloat(n.substr(0,r));let s=n.split(" days "),i=s.length>1?parseFloat(s[0]):0,o=s.length>1?s[1]:s[0],a=0,h=o.split(":").reverse();for(let p=0;p<h.length;++p)a+=parseFloat(h[p])*Math.pow(60,p);return i*24*60*60+a}var v=class{_graph;parent;props={};constructor(e,t){this._graph=e,this.parent=t}},m=class n extends v{subgraphs=[];vertices=[];edges=[];_;constructor(e,t,r){super(e,t),t&&t._addSubgraph(this),this._=r}remove(e=!0){this._graph.removeSubgraph(this,e)}createSubgraph(e){return this._graph.createSubgraph(this,e)}_addSubgraph(e){if(this.subgraphs.indexOf(e)>=0)throw new Error("Subgraph already exists");this.subgraphs.push(e)}_removeSubgraph(e){let t=this.subgraphs.indexOf(e);if(t<0)throw new Error("Subgraph does not exist");this.subgraphs.splice(t,1)}removeAllSubgraphs(){for(let e=this.subgraphs.length-1;e>=0;--e)this._graph.removeSubgraph(this.subgraphs[e],!0)}createVertex(e){return this._graph.createVertex(this,e)}_addVertex(e){if(this.vertices.indexOf(e)>=0)throw new Error("Vertex already exists");this.vertices.push(e)}_removeVertex(e){let t=this.vertices.indexOf(e);if(t<0)throw new Error("Vertex does not exist");this.vertices.splice(t,1)}removeAllVertices(){for(let e=this.vertices.length-1;e>=0;--e)this._graph.removeVertex(this.vertices[e],!0)}createEdge(e,t,r){return this._graph.createEdge(this,e,t,r)}_addEdge(e){if(this.edges.indexOf(e)>=0)throw new Error("Edge already exists");this.edges.push(e)}_removeEdge(e){let t=this.edges.indexOf(e);if(t<0)throw new Error("Edge does not exist");this.edges.splice(t,1)}_add(e){e instanceof n?this._addSubgraph(e):e instanceof S?this._addVertex(e):this._addEdge(e)}},S=class extends v{inEdges=[];outEdges=[];get edges(){return[...this.inEdges,...this.outEdges]}_;constructor(e,t,r){super(e,t),t._addVertex(this),this._=r}remove(e=!0,t){return this._graph.removeVertex(this,e,t)}addInEdge(e){this.inEdges.push(e)}removeInEdge(e){let t=this.inEdges.indexOf(e);if(t<0)throw new Error("In edge does not exist");this.inEdges.splice(t,1)}addOutEdge(e){this.outEdges.push(e)}removeOutEdge(e){let t=this.outEdges.indexOf(e);if(t<0)throw new Error("Out edge does not exist");this.outEdges.splice(t,1)}},I=class extends v{source;target;_;constructor(e,t,r,s,i){if(super(e,t),!r)throw new Error("Missing source vertex");if(!s)throw new Error("Missing target vertex");t._addEdge(this),this.source=r,this.source.addOutEdge(this),this.target=s,this.target.addInEdge(this),this._=i}remove(){this._graph.removeEdge(this)}},te=class{root;_allSubgraphs=[];_allSubgraphsMap={};_allVertices=[];_allVerticesMap={};_allEdges=[];_allEdgesMap={};idOf;constructor(e=r=>""+r._,t){this.root=new m(this,null,t),this.idOf=e}createSubgraph(e,t){let r=new m(this,e||this.root,t);return this._allSubgraphs.push(r),this._allSubgraphsMap[this.idOf(r)]=r,r}removeSubgraph(e,t=!0){let r=this._allSubgraphs.indexOf(e);if(r<0)throw new Error("Subgraph does not exist");this._allSubgraphs.splice(r,1),delete this._allSubgraphsMap[this.idOf(e)],e.parent&&e.parent._removeSubgraph(e),e.edges.forEach(s=>t?this.removeEdge(s):e.parent._addEdge(s)),e.vertices.forEach(s=>t?this.removeVertex(s,t):e.parent._addVertex(s)),e.subgraphs.forEach(s=>t?this.removeSubgraph(s,t):e.parent._addSubgraph(s))}get subgraphs(){return this._allSubgraphs}subgraph(e){return this._allSubgraphsMap[e]}createVertex(e,t){let r=new S(this,e,t);return this._allVertices.push(r),this._allVerticesMap[this.idOf(r)]=r,r}removeVertex(e,t=!0,r){let s=this._allVertices.indexOf(e);if(s<0)throw new Error("Vertex does not exist");this._allVertices.splice(s,1),delete this._allVerticesMap[this.idOf(e)],e.parent&&e.parent._removeVertex(e),t||e.inEdges.forEach(i=>{e.outEdges.forEach(o=>{this.createEdge(this.root,i.source,o.target,r?r(i.source._,o.target._):void 0)})}),e.inEdges.forEach(i=>this.removeEdge(i)),e.outEdges.forEach(i=>this.removeEdge(i))}get vertices(){return this._allVertices}vertex(e){return this._allVerticesMap[e]}createEdge(e,t,r,s){let i=new I(this,e,t,r,s);return this._allEdges.push(i),this._allEdgesMap[this.idOf(i)]=i,i}removeEdge(e){let t=this._allEdges.indexOf(e);if(t<0)throw new Error("Edge does not exist");this._allEdges.splice(t,1),delete this._allEdgesMap[this.idOf(e)],e.parent&&e.parent._removeEdge(e),e.source.removeOutEdge(e),e.target.removeInEdge(e)}get edges(){return this._allEdges}edge(e){return this._allEdgesMap[e]}_walk(e,t){for(let r of e.subgraphs)switch(t(r)){case"abort":return!0;case"stepover":break;default:if(this._walk(r,t))return!0}for(let r of e.vertices)if(t(r)==="abort")return!0}walk(e){this._walk(this.root,e);for(let t of this._allEdges)if(e(t)==="abort")return!0}clone(){let e=this.constructor,t=new e(this.idOf,this.root._),r=de();return r.put(this.root,t.root),this.walk(s=>{let i=r.get(s.parent);if(s instanceof m)r.put(s,i.createSubgraph(s._));else if(s instanceof S)r.put(s,i.createVertex(s._));else if(s instanceof I){let o=r.get(s.source),a=r.get(s.target);i.createEdge(o,a,s._)}}),t}};function de(){let n=[],e=[];return{put(t,r){let s=n.indexOf(t);s===-1?(n.push(t),e.push(r)):e[s]=r},get(t){return e[n.indexOf(t)]}}}var j=class{_graph;_;id(){return this._graph.id(this._)}constructor(e,t){this._graph=e,this._=t}},V=class extends j{_parent;constructor(e,t){super(e,t)}clearParent(){return this._parent&&(this._parent.removeChild(this),delete this._parent),this}parent(e){return arguments.length===0?this._parent:(this._parent!==e&&(this._parent&&this._parent.removeChild(this),this._parent=e,this._parent&&this._parent.addChild(this)),this)}},y=class extends V{_children=[];constructor(e,t){super(e,t)}children(){return this._children}addChild(e){this._children.push(e)}removeChild(e){this._children=this._children.filter(t=>t.id!==e.id)}},$=class extends V{_inEdges=[];_outEdges=[];constructor(e,t){super(e,t)}edges(){return[...this._inEdges,...this._outEdges]}edgeCount(){return this._outEdges.length+this._inEdges.length}inEdges(){return this._inEdges}addInEdge(e){this._inEdges.push(e)}removeInEdge(e){this._inEdges=this._inEdges.filter(t=>t._.id!==e)}outEdges(){return this._outEdges}addOutEdge(e){this._outEdges.push(e)}removeOutEdge(e){this._outEdges=this._outEdges.filter(t=>t._.id!==e)}},L=class extends V{_source;_target;constructor(e,t,r,s){super(e,t),this._source=r,this._target=s}},re=class{_directed;_subgraphMap={};_vertexMap={};_edgeMap={};constructor(e=!0){this._directed=e}clear(){return this._subgraphMap={},this._vertexMap={},this._edgeMap={},this}clearParents(){for(let e in this._subgraphMap)this._subgraphMap[e].clearParent();for(let e in this._vertexMap)this._vertexMap[e].clearParent();return this}isDirected(){return this._directed}_idFunc=e=>typeof e.id=="function"?e.id():e.id;idFunc(e){return this._idFunc=e,this}_sourceFunc=e=>typeof e.source=="function"?e.source():e.source;sourceFunc(e){return this._sourceFunc=e,this}_targetFunc=e=>typeof e.target=="function"?e.target():e.target;targetFunc(e){return this._targetFunc=e,this}_updateFunc=(e,t)=>t;updateFunc(e){return this._updateFunc=e,this}id(e){return this._idFunc(e)}type(e){return this.subgraphExists(e)?"S":this.vertexExists(e)?"V":this.edgeExists(e)?"E":""}isSubgraph(e){return this.subgraphExists(this.id(e))}isVertex(e){return this.vertexExists(this.id(e))}isEdge(e){return this.edgeExists(this.id(e))}allItems(){return[...this.allSubgraphs(),...this.allVertices(),...this.allEdges()]}item(e){if(this.subgraphExists(e))return this.subgraph(e);if(this.vertexExists(e))return this.vertex(e);if(this.edgeExists(e))return this.edge(e)}itemExists(e){return this.edgeExists(e)||this.vertexExists(e)||this.subgraphExists(e)}allSubgraphs(){let e=[];for(let t in this._subgraphMap)e.push(this._subgraphMap[t]._);return e}subgraphs(){let e=[];for(let t in this._subgraphMap)this._subgraphMap[t].parent()===void 0&&e.push(this._subgraphMap[t]._);return e}subgraphExists(e){return!!this._subgraphMap[e]}subgraph(e){return this._subgraphMap[e]._}subgraphSubgraphs(e){return this._subgraphMap[e].children().filter(t=>this.isSubgraph(t._)).map(t=>t._)}subgraphVertices(e){return this._subgraphMap[e].children().filter(t=>this.isVertex(t._)).map(t=>t._)}subgraphEdges(e){return this._subgraphMap[e].children().filter(t=>this.isEdge(t._)).map(t=>t._)}addSubgraph(e,t){let r=this._idFunc(e);if(this._subgraphMap[r])throw new Error(`Subgraph '${r}' already exists.`);let s=new y(this,e);if(t){let i=this._idFunc(t);if(!this._subgraphMap[i])throw new Error(`Subgraph '${i}' does not exist.`);s.parent(this._subgraphMap[i])}return this._subgraphMap[r]=s,this}mergeSubgraphs(e=[]){let t=M(this.allSubgraphs(),e,r=>this._idFunc(r),this._updateFunc);return t.exit.forEach(r=>this.removeSubgraph(this._idFunc(r))),t.enter.forEach(r=>this.addSubgraph(r)),t.update.forEach(r=>this.updateSubgraph(r)),this}updateSubgraph(e){let t=this._idFunc(e),r=this._subgraphMap[t];if(!r)throw new Error(`Subgraph '${t}' does not exist.`);return r._=e,this}removeSubgraph(e,t=!0){let r=this._subgraphMap[e];if(!r)throw new Error(`Subgraph '${e}' does not exist.`);return r.children().forEach(s=>{t?s.parent(r.parent()):s instanceof y?this.removeSubgraph(s.id()):this.removeVertex(s.id())}),delete this._subgraphMap[e],this}subgraphParent(e,t){let r=this._subgraphMap[e];if(!r)throw new Error(`Subgraph '${e}' does not exist.`);if(t===void 0){let i=r.parent();return i?i._:void 0}let s=this._subgraphMap[t];if(!s)throw new Error(`Vertex parent '${s}' does not exist.`);return r.parent(s),this}allVertices(){let e=[];for(let t in this._vertexMap)e.push(this._vertexMap[t]._);return e}vertices(){let e=[];for(let t in this._vertexMap)this._vertexMap[t].parent()===void 0&&e.push(this._vertexMap[t]._);return e}vertexExists(e){return!!this._vertexMap[e]}vertex(e){return this._vertexMap[e]._}allEdges(){let e=[];for(let t in this._edgeMap)e.push(this._edgeMap[t]._);return e}edges(){let e=[];for(let t in this._edgeMap)this._edgeMap[t].parent()===void 0&&e.push(this._edgeMap[t]._);return e}vertexEdges(e){return this._vertexMap[e].edges().map(t=>t._)}inEdges(e){return this._vertexMap[e].inEdges().map(t=>t._)}outEdges(e){return this._vertexMap[e].outEdges().map(t=>t._)}_neighbors(e){return[...this._vertexMap[e].outEdges().map(t=>t._target),...this._vertexMap[e].inEdges().map(t=>t._source)]}neighbors(e){return this._neighbors(e).map(t=>t._)}singleNeighbors(e){return this._neighbors(e).filter(t=>t.edgeCount()===1).map(t=>t._)}addVertex(e,t){let r=this._idFunc(e);if(this._vertexMap[r])throw new Error(`Vertex '${r}' already exists.`);let s=new $(this,e);if(t){let i=this._idFunc(t);if(!this.subgraphExists(i))throw new Error(`Subgraph '${i}' does not exist.`);s.parent(this._subgraphMap[i])}return this._vertexMap[r]=s,this}mergeVertices(e){let t=M(this.allVertices(),e,r=>this._idFunc(r),this._updateFunc);return t.exit.forEach(r=>this.removeVertex(this._idFunc(r))),t.enter.forEach(r=>this.addVertex(r)),t.update.forEach(r=>this.updateVertex(r)),this}updateVertex(e){let t=this._idFunc(e),r=this._vertexMap[t];if(!r)throw new Error(`Vertex '${t}' does not exist.`);return r._=e,this}removeVertex(e){let t=this._vertexMap[e];if(!t)throw new Error(`Vertex '${e}' does not exist.`);return t.edges().forEach(r=>{this.removeEdge(r.id())}),delete this._vertexMap[e],this}vertexParent(e,t){let r=this._vertexMap[e];if(!r)throw new Error(`Vertex '${e}' does not exist.`);if(t===void 0){let i=r.parent();return i?i._:void 0}let s=this._subgraphMap[t];if(!s)throw new Error(`Vertex parent '${s}' does not exist.`);return r.parent(s),this}edgeExists(e){return!!this._edgeMap[e]}edge(e){return this._edgeMap[e]._}addEdge(e,t){let r=this._idFunc(e),s=this._sourceFunc(e),i=this._targetFunc(e);if(this._edgeMap[r])throw new Error(`Edge '${r}' already exists.`);if(!this.vertexExists(s))throw new Error(`Edge Source '${s}' does not exist.`);if(!this.vertexExists(i))throw new Error(`Edge Target '${i}' does not exist.`);let o=new L(this,e,this._vertexMap[s],this._vertexMap[i]);if(t){let a=this._idFunc(t);if(!this.subgraphExists(a))throw new Error(`Subgraph '${a}' does not exist.`);o.parent(this._subgraphMap[a])}return this._edgeMap[r]=o,this._vertexMap[s].addOutEdge(o),this._vertexMap[i].addInEdge(o),this}mergeEdges(e){let t=M(this.allEdges(),e,r=>this._idFunc(r),this._updateFunc);return t.exit.forEach(r=>this.removeEdge(this._idFunc(r))),t.enter.forEach(r=>this.addEdge(r)),t.update.forEach(r=>this.updateEdge(r)),this}updateEdge(e){let t=this._idFunc(e),r=this._edgeMap[t];if(!r)throw new Error(`Edge '${t}' does not exist.`);let s=r._source.id(),i=this._sourceFunc(e);s!==i&&(this._vertexMap[s]?.removeOutEdge(t),this._vertexMap[i]?.addOutEdge(r));let o=r._target.id(),a=this._targetFunc(e);return o!==a&&(this._vertexMap[o]?.removeInEdge(t),this._vertexMap[a]?.addInEdge(r)),r._=e,r._source=this._vertexMap[i],r._target=this._vertexMap[a],this}removeEdge(e){let t=this._edgeMap[e];if(!t)throw new Error(`Edge '${e}' does not exist.`);let r=this._idFunc(t._source._);if(!this.vertexExists(r))throw new Error(`Edge Source'${r}' does not exist.`);this._vertexMap[r].removeOutEdge(e);let s=this._idFunc(t._target._);if(!this.vertexExists(s))throw new Error(`Edge Target'${s}' does not exist.`);return this._vertexMap[s].removeInEdge(e),delete this._edgeMap[e],this}_hwalk(e,t){return e instanceof y?t("subgraph",e._,e.children().map(r=>this._hwalk(r,t))):t("vertex",e._)}hierarchy(e){let t=[];for(let r in this._subgraphMap){let s=this._subgraphMap[r];s.parent()===void 0&&t.push(this._hwalk(s,e))}for(let r in this._vertexMap){let s=this._vertexMap[r];s.parent()===void 0&&t.push(this._hwalk(s,e))}return t}dijkstra(e,t){let r=this.allEdges(),s=new N,i={},o={},a={};function h(u,d){let c=1/0,_=null;return u.forEach(F=>{d[F]<c&&(c=d[F],_=F)}),_}for(let u=0;u<r.length;u++){let d=this._sourceFunc(r[u]),c=this._targetFunc(r[u]),_=1;s.add(d),s.add(c),o[d]=1/0,o[c]=1/0,a[d]===void 0&&(a[d]={}),a[c]===void 0&&(a[c]={}),a[d][c]=_,a[c][d]=_}for(o[e]=0;s.size;){let u=h(s,o);if(u===null)break;let d=Object.keys(a[u]).filter(c=>s.has(c));if(s.delete(u),u===t)break;for(let c of d){let _=o[u]+a[u][c];_<o[c]&&(o[c]=_,i[c]=u)}}let p=t,g=[p],f=0;for(;i[p]!==void 0;)g.unshift(i[p]),f+=a[p][i[p]],p=i[p];return{ids:g,len:f}}sort(e){let t=[],r={},s=(i,o=[])=>{let a=i.id();r[a]||(r[a]=!0,o.push(i),i.outEdges().forEach(h=>{o.indexOf(h._target)<0&&s(h._target,[...o])}),t.unshift(i._))};if(e)s(this._vertexMap[e]);else for(let i in this._vertexMap)s(this._vertexMap[i]);return t}},N=class{_content=[];get size(){return this._content.length}has(e){return this._content.indexOf(e)>=0}add(e){this.has(e)||this._content.push(e)}delete(e){let t=this._content.indexOf(e);t>=0&&this._content.splice(t,1)}forEach(e){this._content.forEach(e)}};var k=Array.isArray,w=Object.keys,ne=Object.prototype.hasOwnProperty;function se(n,e,t=!1){if(n===e)return!0;if(n&&e){if(typeof n=="object"&&typeof e=="object"){let s=k(n),i=k(e),o,a,h;if(s&&i){if(a=n.length,a!==e.length)return console.warn(`lengths not equal: ${a} !== ${e.length}`),!1;for(o=a;o--!==0;)if(!se(n[o],e[o],t))return!1;return!0}if(s!==i)return console.warn(`arrays not equal: ${s} !== ${i}`),!1;let p=n instanceof Date,g=e instanceof Date;if(p!==g)return console.warn(`dates not equal: ${p} !== ${g}`),!1;if(p&&g){let c=n.getTime()===e.getTime();return c||console.warn(`dates not equal: ${n.getTime()} !== ${e.getTime()}`),c}let f=n instanceof RegExp,u=e instanceof RegExp;if(f!==u)return console.warn(`regexps not equal: ${f} !== ${u}`),!1;if(f&&u){let c=n.toString()===e.toString();return c||console.warn(`regexps not equal: ${n.toString()} !== ${e.toString()}`),c}let d=w(n);if(a=d.length,a!==w(e).length)return console.warn(`key lengths not equal: ${a} !== ${w(e).length}`),!1;for(o=a;o--!==0;)if(!ne.call(e,d[o]))return console.warn(`${d[o]} in a but not b`),!1;for(o=a;o--!==0;)if(h=d[o],!se(n[h],e[h],t))return!1;return!0}else if(!t&&typeof n=="function"&&typeof e=="function"){let s=n.toString()===e.toString();return s||console.warn(`functions not equal: ${n.toString()} !== ${e.toString()}`),s}}let r=n!==n&&e!==e;return r||console.warn(`values not equal: ${n} !== ${e}`),r}function T(n,e,t=!1){if(n===e)return!0;if(n&&e){if(typeof n=="object"&&typeof e=="object"){let r=k(n),s=k(e),i,o,a;if(r&&s){if(o=n.length,o!==e.length)return!1;for(i=o;i--!==0;)if(!T(n[i],e[i],t))return!1;return!0}if(r!==s)return!1;let h=n instanceof Date,p=e instanceof Date;if(h!==p)return!1;if(h&&p)return n.getTime()===e.getTime();let g=n instanceof RegExp,f=e instanceof RegExp;if(g!==f)return!1;if(g&&f)return n.toString()===e.toString();let u=w(n);if(o=u.length,o!==w(e).length)return!1;for(i=o;i--!==0;)if(!ne.call(e,u[i]))return!1;for(i=o;i--!==0;)if(a=u[i],!T(n[a],e[a],t))return!1;return!0}else if(!t&&typeof n=="function"&&typeof e=="function")return n.toString()===e.toString()}return n!==n&&e!==e}function Ne(n,e,t=!1){return T(n,e,t)?n:e}var P=typeof globalThis<"u"?globalThis:window,Ue=typeof window<"u"&&P===window,R=typeof process<"u"&&process.versions!=null&&process.versions.node!=null,qe=R&&process.env!=null&&(process.env.TRAVIS!=null||process.env.GITHUB_ACTIONS!=null);function Ke(n){let e=document.scripts||[];for(let t=document.scripts.length-1;t>=0;--t){let r=e[t];if(r.src){let s=r.src.indexOf(n);if(s>=0)return r.src.substring(0,s)}}return""}var x=class{stack=[];push(e){return this.stack.push(e),e}pop(){return this.stack.pop()}top(){return this.stack.length?this.stack[this.stack.length-1]:void 0}depth(){return this.stack.length}};var D=(h=>(h[h.debug=0]="debug",h[h.info=1]="info",h[h.notice=2]="notice",h[h.warning=3]="warning",h[h.error=4]="error",h[h.critical=5]="critical",h[h.alert=6]="alert",h[h.emergency=7]="emergency",h))(D||{}),le={debug:"cyan",info:"green",notice:"grey",warning:"blue",error:"red",critical:"magenta",alert:"magenta",emergency:"magenta"},U=class{write(e,t,r,s){R?console.log(`[${e}] ${D[t].toUpperCase()} ${r}: ${s}`):console.log(`[${e}] %c${D[t].toUpperCase()}%c ${r}: ${s}`,`color:${le[D[t]]}`,"")}},q=class{static _instance;_levelStack=new x;_level=1;_filter="";_writer=new U;static Instance(){return this._instance||(this._instance=new this)}constructor(){}stringify(e){let t=[];return JSON.stringify(e,function(r,s){if(typeof s=="object"&&s!==null){if(t.indexOf(s)!==-1)return;t.push(s)}return s},2)}writer(e){return e===void 0?this._writer:(this._writer=e,this)}log(e,t,r){if(e<this._level||this._filter&&this._filter!==t)return;let s=new Date().toISOString();this._writer.rawWrite?this._writer.rawWrite(s,e,t,r):(typeof r!="string"&&(r=this.stringify(r)),this._writer.write&&this._writer.write(s,e,t,r))}debug(e,t){this.log(0,e,t)}info(e,t){this.log(1,e,t)}notice(e,t){this.log(2,e,t)}warning(e,t){this.log(3,e,t)}error(e,t){this.log(4,e,t)}critical(e,t){this.log(5,e,t)}alert(e,t){this.log(6,e,t)}emergency(e,t){this.log(7,e,t)}level(e){return e===void 0?this._level:(this._level=e,this)}pushLevel(e){return this._levelStack.push(this._level),this._level=e,this}popLevel(){return this._level=this._levelStack.pop(),this}filter(e){return e===void 0?this._filter:(this._filter=e,this)}},l=q.Instance(),K=class{_scopeID;constructor(e){this._scopeID=e}debug(e){l.debug(this._scopeID,e)}info(e){l.info(this._scopeID,e)}notice(e){l.notice(this._scopeID,e)}warning(e){l.warning(this._scopeID,e)}error(e){l.error(this._scopeID,e)}critical(e){l.critical(this._scopeID,e)}alert(e){l.alert(this._scopeID,e)}emergency(e){l.emergency(this._scopeID,e)}pushLevel(e){return l.pushLevel(e),this}popLevel(){return l.popLevel(),this}};function We(n,e=!1){return e&&l.filter(n),new K(n)}function Je(n){return n*(Math.PI/180)}function Qe(n){return n*(180/Math.PI)}function Ye(n,e){return{x:n*Math.cos(e),y:n*Math.sin(e)}}function Ze(n,e){return{r:Math.sqrt(n*n+e*e),theta:Math.atan2(e,n)}}function et(n,e=-Math.PI,t=Math.PI){return ie(n,e,t)}function tt(n,e=-180,t=180){return ie(n,e,t)}function ie(n,e,t){let r=t-e,s=n-e;return s-Math.floor(s/r)*r+e}function ge(n,e){if(!(n===void 0||e===void 0)){for(let t of n.split(".")){if(!e.hasOwnProperty(t))return;e=e[t]}return e}}function st(n,e){return ge(n,e)!==void 0}function fe(n,e){let t={};for(let r in e){if(!e.hasOwnProperty(r)||r==="__proto__"||r==="constructor")continue;let s=e[r];s instanceof Array||typeof s=="object"&&(s=oe(n[r],s)),(!(r in n)||n[r]!==s&&(!(r in t)||t[r]!==s))&&(n[r]=s)}return n}function oe(n={},...e){if(typeof n!="object")throw new Error(`Destination "${n}" must be an object.`);for(let t of e)fe(n,t);return n}function nt(n={},...e){return oe(n,...e)}function it(n){let e=[];return JSON.stringify(n,function(t,r){if(typeof r=="object"&&r!==null){if(e.indexOf(r)!==-1)return;e.push(r)}return r})}function ot(n){return Array.isArray!==void 0?Array.isArray(n):Object.prototype.toString.call(n)==="[object Array]"}function at(n){let e=n.split("_"),t=e[1].split(".");return{module:`@hpcc-js/${e[0]}`,file:t[0],class:t[1]||t[0]}}var X=class{eventTarget;eventID;callback;constructor(e,t,r){this.eventTarget=e,this.eventID=t,this.callback=r}release(){this.eventTarget.removeObserver(this.eventID,this.callback)}unwatch(){this.release()}},ae=class{_eventObservers={};constructor(...e){}addObserver(e,t){let r=this._eventObservers[e];return r||(r=[],this._eventObservers[e]=r),r.push(t),new X(this,e,t)}removeObserver(e,t){let r=this._eventObservers[e];if(r)for(let s=r.length-1;s>=0;--s)r[s]===t&&r.splice(s,1);return this}dispatchEvent(e,...t){let r=this._eventObservers[e];if(r)for(let s of r)s(...t);return this}_hasObserver(e){let t=this._eventObservers[e];for(let r in t)if(t[r])return!0;return!1}hasObserver(e){if(e!==void 0)return this._hasObserver(e);for(let t in this._eventObservers)if(this._hasObserver(t))return!0;return!1}};var H;(function(){if(P.requestAnimationFrame)H=P.requestAnimationFrame;else{let n=0;H=function(e){let t=new Date().getTime(),r=Math.max(0,16-(t-n)),s=setTimeout(()=>e(t+r),r);return n=t+r,s}}})();var O=class{get canConflate(){return!1}conflate(e){return!1}void(){return!1}};var C=class{_observerID=0;_observers=[];_messageBuffer=[];constructor(){}observers(){return this._observers}messages(){let e=[];return this._messageBuffer.forEach(t=>{e.some(r=>r.canConflate&&r.conflate(t))||e.push(t)}),e}dispatchAll(){this.dispatch(this.messages()),this.flush()}dispatch(e){e.length!==0&&this.observers().forEach(t=>{let r=e.filter(s=>!s.void()&&(t.type===void 0||s instanceof t.type));r.length&&t.callback(r)})}hasObserver(){return this._observers.length>0}flush(){this._messageBuffer=[]}send(e){this.dispatch([e])}post(e){this._messageBuffer.push(e),H(()=>this.dispatchAll())}attach(e,t){let r=this,s=++this._observerID;return this._observers.push({id:s,type:t,callback:e}),{release(){r._observers=r._observers.filter(i=>i.id!==s)},unwatch(){this.release()}}}};var G=class{name="";$={};_children=[];content="";constructor(e){this.name=e}appendAttribute(e,t){this.$[e]=t}appendContent(e){this.content+=e}appendChild(e){this._children.push(e)}children(e){return e===void 0?this._children:this._children.filter(t=>t.name===e)}},B=class{root;stack=new x;constructor(){}walkDoc(e){let t=this._startXMLNode(e);if(e.attributes)for(let r=0;r<e.attributes.length;++r){let s=e.attributes.item(r);this.attributes(s.nodeName,s.nodeValue)}if(this.startXMLNode(t),e.childNodes)for(let r=0;r<e.childNodes.length;++r){let s=e.childNodes.item(r);s.nodeType===s.TEXT_NODE?this.characters(s.nodeValue):this.walkDoc(s)}this.endXMLNode(this.stack.pop())}_startXMLNode(e){let t=new G(e.nodeName);return this.stack.depth()?this.stack.top().appendChild(t):this.root=t,this.stack.push(t)}parse(e){let r=new DOMParser().parseFromString(e,"application/xml");this.startDocument(),this.walkDoc(r),this.endDocument()}startDocument(){}endDocument(){}startXMLNode(e){}endXMLNode(e){}attributes(e,t){this.stack.top().appendAttribute(e,t)}characters(e){this.stack.top().appendContent(e)}},W=class extends B{startXMLNode(e){switch(super.startXMLNode(e),e.name){case"xs:element":break;case"xs:simpleType":break;default:break}}endXMLNode(e){switch(e.name){case"xs:element":break;case"xs:simpleType":break;default:break}super.endXMLNode(e)}};function lt(n){let e=new W;return e.parse(n),e.root}var z=class extends O{constructor(t,r,s){super();this.property=t;this.newValue=r;this.oldValue=s}get canConflate(){return!0}conflate(t){return this.property===t.property?(this.newValue=t.newValue,!0):!1}void(){return T(this.newValue,this.oldValue)}},he=class{_espState={};_dispatch=new C;_monitorHandle;_monitorTickCount=0;clear(e){this._espState={},e!==void 0&&this.set(e),this._monitorTickCount=0}get(e,t){return e===void 0?this._espState:this.has(e)?this._espState[e]:t}set(e,t){if(typeof e=="string")return this.setSingle(e,t);this.setAll(e)}setSingle(e,t){let r=this._espState[e];this._espState[e]=t,this._dispatch.post(new z(e,t,r))}setAll(e){for(let t in e)e.hasOwnProperty(t)&&this.setSingle(t,e[t])}has(e){return this._espState[e]!==void 0}addObserver(e,t,r){if(this.isCallback(t)){if(e!=="changed")throw new Error("Invalid eventID: "+e);return this._dispatch.attach(s=>{t(s.map(i=>({id:i.property,oldValue:i.oldValue,newValue:i.newValue})))})}else{if(e!=="propChanged")throw new Error("Invalid eventID: "+e);return this._dispatch.attach(s=>{let i=s.filter(o=>o.property===t);if(i.length){i.length>1&&console.warn("Should only be 1 message?");let o=i[i.length-1];r({id:o.property,oldValue:o.oldValue,newValue:o.newValue})}})}}on(e,t,r){return this.addObserver(e,t,r),this}isCallback(e){return typeof e=="function"}hasEventListener(){return this._dispatch.hasObserver()}async refresh(e=!1){return await Promise.resolve(),this}_monitor(){if(this._monitorHandle){this._monitorTickCount=0;return}this._monitorHandle=setTimeout(()=>{(this.hasEventListener()?this.refresh():Promise.resolve()).then(()=>{this._monitor()}),delete this._monitorHandle},this._monitorTimeoutDuration())}_monitorTimeoutDuration(){return++this._monitorTickCount,this._monitorTickCount<=1?0:3e4}watch(e,t=!0){if(typeof e!="function")throw new Error("Invalid Callback");t&&setTimeout(()=>{let s=this.get(),i=[];for(let o in s)s.hasOwnProperty(s)&&i.push({id:o,newValue:s[o],oldValue:void 0});e(i)},0);let r=this.addObserver("changed",e);return this._monitor(),r}};function Et(n,e){if(typeof e!="string"||e.length===0)return n;for(;n.indexOf(e)===0;)n=n.substring(1);for(;_e(n,e);)n=n.substring(0,n.length-1);return n}function _e(n,e,t){let r=n.toString();(typeof t!="number"||!isFinite(t)||Math.floor(t)!==t||t>r.length)&&(t=r.length),t-=e.length;let s=r.lastIndexOf(e,t);return s!==-1&&s===t}function be(...n){let e=n.reduce((r,s)=>(r.length>0&&(s=s.replace(/^\//,"")),s=s.replace(/\/$/,""),[...r,...s.split("/")]),[]),t=[];for(let r of e)if(r!=="."){if(r===".."){t.pop();continue}t.push(r)}return t.join("/")}function vt(n){return be(n,"..")}export{Y as AsyncCache,Z as AsyncOrderedQueue,me as BUILD_VERSION,Q as Cache,A as Dictionary,ee as DictionaryNoCase,C as Dispatch,I as Edge,te as Graph,re as Graph2,v as GraphItem,D as Level,q as Logging,O as Message,ae as Observable,xe as PKG_NAME,Ee as PKG_VERSION,B as SAXStackParser,K as ScopedLogging,x as Stack,he as StateObject,m as Subgraph,S as Vertex,G as XMLNode,Ze as cartesianToPolar,at as classID2Meta,ye as compare,M as compare2,ke as debounce,T as deepEquals,oe as deepMixin,nt as deepMixinT,Je as degreesToRadians,vt as dirname,_e as endsWith,Fe as espTime2Seconds,st as exists,Se as find,Ke as getScriptSrc,E as hashSum,ge as inner,ot as isArray,Ue as isBrowser,qe as isCI,R as isNode,be as join,l as logger,ie as normalize,tt as normalizeDegrees,et as normalizeRadians,Ye as polarToCartesian,Pe as promiseTimeout,Qe as radiansToDegrees,P as root,it as safeStringify,We as scopedLogger,De as sleep,Et as trim,Ne as update,se as verboseDeepEquals,lt as xml2json};
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
4
|
+
const PKG_NAME = "@hpcc-js/util", PKG_VERSION = "3.2.0", BUILD_VERSION = "3.2.1";
|
|
5
|
+
function find(o, predicate) {
|
|
6
|
+
if (o == null)
|
|
7
|
+
throw new TypeError('"o" is null or not defined');
|
|
8
|
+
const len = o.length >>> 0;
|
|
9
|
+
if (typeof predicate != "function")
|
|
10
|
+
throw new TypeError("predicate must be a function");
|
|
11
|
+
const thisArg = arguments[1];
|
|
12
|
+
let k = 0;
|
|
13
|
+
for (; k < len; ) {
|
|
14
|
+
const kValue = o[k];
|
|
15
|
+
if (predicate.call(thisArg, kValue, k))
|
|
16
|
+
return kValue;
|
|
17
|
+
k++;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function compare(before, after) {
|
|
21
|
+
const retVal = {
|
|
22
|
+
update: [],
|
|
23
|
+
exit: [],
|
|
24
|
+
enter: [...after]
|
|
25
|
+
};
|
|
26
|
+
for (const row of before) {
|
|
27
|
+
const otherIdx = retVal.enter.indexOf(row);
|
|
28
|
+
otherIdx >= 0 ? (retVal.update.push(row), retVal.enter.splice(otherIdx, 1)) : retVal.exit.push(row);
|
|
29
|
+
}
|
|
30
|
+
return retVal;
|
|
31
|
+
}
|
|
32
|
+
function compare2(before, after, idFunc, updateFunc = (before2, after2) => after2) {
|
|
33
|
+
const retVal = {
|
|
34
|
+
update: [],
|
|
35
|
+
exit: [],
|
|
36
|
+
enter: []
|
|
37
|
+
};
|
|
38
|
+
if (before === after)
|
|
39
|
+
return retVal.update = before, retVal;
|
|
40
|
+
const unknownMap = {};
|
|
41
|
+
after.forEach((item) => {
|
|
42
|
+
unknownMap[idFunc(item)] = item;
|
|
43
|
+
});
|
|
44
|
+
for (const row of before) {
|
|
45
|
+
const id = idFunc(row), item = unknownMap[id];
|
|
46
|
+
item !== void 0 ? (delete unknownMap[id], retVal.update.push(updateFunc(row, item))) : retVal.exit.push(row);
|
|
47
|
+
}
|
|
48
|
+
for (const key in unknownMap)
|
|
49
|
+
retVal.enter.push(unknownMap[key]);
|
|
50
|
+
return retVal;
|
|
51
|
+
}
|
|
52
|
+
function pad(hash, len) {
|
|
53
|
+
for (; hash.length < len; )
|
|
54
|
+
hash = "0" + hash;
|
|
55
|
+
return hash;
|
|
56
|
+
}
|
|
57
|
+
function fold(hash, text) {
|
|
58
|
+
if (text.length === 0)
|
|
59
|
+
return hash;
|
|
60
|
+
for (let i = 0; i < text.length; ++i) {
|
|
61
|
+
const chr = text.charCodeAt(i);
|
|
62
|
+
hash = (hash << 5) - hash + chr, hash |= 0;
|
|
63
|
+
}
|
|
64
|
+
return hash < 0 ? hash * -2 : hash;
|
|
65
|
+
}
|
|
66
|
+
function foldObject(hash, o, seen) {
|
|
67
|
+
return typeof o.hashSum == "function" ? o.hashSum() : Object.keys(o).sort().reduce((input, key) => foldValue(input, o[key], key, seen), hash);
|
|
68
|
+
}
|
|
69
|
+
function foldValue(input, value, key, seen) {
|
|
70
|
+
const hash = fold(fold(fold(input, key), toString(value)), typeof value);
|
|
71
|
+
return value === null ? fold(hash, "null") : value === void 0 ? fold(hash, "undefined") : typeof value == "object" ? seen.indexOf(value) !== -1 ? fold(hash, "[Circular]" + key) : (seen.push(value), foldObject(hash, value, seen)) : fold(hash, value.toString());
|
|
72
|
+
}
|
|
73
|
+
function toString(o) {
|
|
74
|
+
return Object.prototype.toString.call(o);
|
|
75
|
+
}
|
|
76
|
+
function hashSum(o) {
|
|
77
|
+
return pad(foldValue(0, o, "", []).toString(16), 8);
|
|
78
|
+
}
|
|
79
|
+
class Cache {
|
|
80
|
+
constructor(calcID) {
|
|
81
|
+
__publicField(this, "_cache", {});
|
|
82
|
+
__publicField(this, "_calcID");
|
|
83
|
+
this._calcID = calcID;
|
|
84
|
+
}
|
|
85
|
+
static hash(...args) {
|
|
86
|
+
return hashSum({ ...args });
|
|
87
|
+
}
|
|
88
|
+
has(espObj) {
|
|
89
|
+
return this._calcID(espObj) in this._cache;
|
|
90
|
+
}
|
|
91
|
+
set(obj) {
|
|
92
|
+
return this._cache[this._calcID(obj)] = obj, obj;
|
|
93
|
+
}
|
|
94
|
+
get(espObj, factory) {
|
|
95
|
+
const retVal = this._cache[this._calcID(espObj)];
|
|
96
|
+
return retVal || (factory ? this.set(factory()) : null);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
class AsyncCache {
|
|
100
|
+
constructor(calcID) {
|
|
101
|
+
__publicField(this, "_cache", {});
|
|
102
|
+
__publicField(this, "_calcID");
|
|
103
|
+
this._calcID = calcID;
|
|
104
|
+
}
|
|
105
|
+
static hash(...args) {
|
|
106
|
+
return hashSum({ ...args });
|
|
107
|
+
}
|
|
108
|
+
has(espObj) {
|
|
109
|
+
return this._calcID(espObj) in this._cache;
|
|
110
|
+
}
|
|
111
|
+
set(espObj, obj) {
|
|
112
|
+
return this._cache[this._calcID(espObj)] = obj, obj;
|
|
113
|
+
}
|
|
114
|
+
get(espObj, factory) {
|
|
115
|
+
const retVal = this._cache[this._calcID(espObj)];
|
|
116
|
+
return retVal || (factory ? this.set(espObj, factory()) : Promise.resolve(null));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function debounce(fn, timeout) {
|
|
120
|
+
const promises = {};
|
|
121
|
+
return (...params) => {
|
|
122
|
+
const hash = hashSum(params);
|
|
123
|
+
return promises[hash] || (promises[hash] = {
|
|
124
|
+
clockStart: Date.now(),
|
|
125
|
+
promise: fn(...params).then((response) => (timeout === void 0 ? promises[hash] = null : setTimeout(() => {
|
|
126
|
+
promises[hash] = null;
|
|
127
|
+
}, Math.max(timeout - (Date.now() - promises[hash].clockStart), 0)), response)).catch((e) => {
|
|
128
|
+
throw promises[hash] = null, e;
|
|
129
|
+
})
|
|
130
|
+
}), promises[hash].promise;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function promiseTimeout(ms, promise) {
|
|
134
|
+
let id;
|
|
135
|
+
const timeout = new Promise((resolve, reject) => {
|
|
136
|
+
id = setTimeout(() => {
|
|
137
|
+
clearTimeout(id), reject("Timed out in " + ms + "ms.");
|
|
138
|
+
}, ms);
|
|
139
|
+
});
|
|
140
|
+
return Promise.race([
|
|
141
|
+
promise,
|
|
142
|
+
timeout
|
|
143
|
+
]).then((response) => (clearTimeout(id), response)).catch((e) => {
|
|
144
|
+
throw clearTimeout(id), e;
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
class AsyncOrderedQueue {
|
|
148
|
+
constructor() {
|
|
149
|
+
__publicField(this, "_q", []);
|
|
150
|
+
}
|
|
151
|
+
isTop(p) {
|
|
152
|
+
return this._q[0] === p;
|
|
153
|
+
}
|
|
154
|
+
push(p) {
|
|
155
|
+
const retVal = p.then((response) => this.isTop(retVal) ? (this._q.shift(), response) : new Promise((resolve, reject) => {
|
|
156
|
+
const intervalHandler = setInterval(() => {
|
|
157
|
+
this.isTop(retVal) && (clearInterval(intervalHandler), this._q.shift(), resolve(response));
|
|
158
|
+
}, 20);
|
|
159
|
+
}));
|
|
160
|
+
return this._q.push(retVal), retVal;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function sleep(ms) {
|
|
164
|
+
return new Promise((resolve) => {
|
|
165
|
+
setTimeout(() => resolve(), ms);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
class Dictionary {
|
|
169
|
+
constructor(attrs) {
|
|
170
|
+
__publicField(this, "store", {});
|
|
171
|
+
if (attrs)
|
|
172
|
+
for (const key in attrs)
|
|
173
|
+
this.set(key, attrs[key]);
|
|
174
|
+
}
|
|
175
|
+
set(key, value) {
|
|
176
|
+
const retVal = this.store[key];
|
|
177
|
+
return this.store[key] = value, retVal;
|
|
178
|
+
}
|
|
179
|
+
get(key) {
|
|
180
|
+
return this.store[key];
|
|
181
|
+
}
|
|
182
|
+
has(key) {
|
|
183
|
+
return this.store[key] !== void 0;
|
|
184
|
+
}
|
|
185
|
+
remove(key) {
|
|
186
|
+
delete this.store[key];
|
|
187
|
+
}
|
|
188
|
+
keys() {
|
|
189
|
+
const retVal = [];
|
|
190
|
+
for (const key in this.store)
|
|
191
|
+
retVal.push(key);
|
|
192
|
+
return retVal;
|
|
193
|
+
}
|
|
194
|
+
values() {
|
|
195
|
+
const retVal = [];
|
|
196
|
+
for (const key in this.store)
|
|
197
|
+
retVal.push(this.store[key]);
|
|
198
|
+
return retVal;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
class DictionaryNoCase extends Dictionary {
|
|
202
|
+
constructor(attrs) {
|
|
203
|
+
super(attrs);
|
|
204
|
+
}
|
|
205
|
+
set(key, value) {
|
|
206
|
+
return super.set(key.toLowerCase(), value);
|
|
207
|
+
}
|
|
208
|
+
get(key) {
|
|
209
|
+
return super.get(key.toLowerCase());
|
|
210
|
+
}
|
|
211
|
+
has(key) {
|
|
212
|
+
return super.has(key.toLowerCase());
|
|
213
|
+
}
|
|
214
|
+
remove(key) {
|
|
215
|
+
return super.remove(key.toLowerCase());
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
function espTime2Seconds(duration) {
|
|
219
|
+
if (duration) {
|
|
220
|
+
if (!isNaN(Number(duration)))
|
|
221
|
+
return Number(duration);
|
|
222
|
+
} else
|
|
223
|
+
return 0;
|
|
224
|
+
const nsIndex = duration.indexOf("ns");
|
|
225
|
+
if (nsIndex !== -1)
|
|
226
|
+
return parseFloat(duration.substr(0, nsIndex)) / 1e9;
|
|
227
|
+
const msIndex = duration.indexOf("ms");
|
|
228
|
+
if (msIndex !== -1)
|
|
229
|
+
return parseFloat(duration.substr(0, msIndex)) / 1e3;
|
|
230
|
+
const sIndex = duration.indexOf("s");
|
|
231
|
+
if (sIndex !== -1 && duration.indexOf("days") === -1)
|
|
232
|
+
return parseFloat(duration.substr(0, sIndex));
|
|
233
|
+
const dayTimeParts = duration.split(" days "), days = dayTimeParts.length > 1 ? parseFloat(dayTimeParts[0]) : 0, time = dayTimeParts.length > 1 ? dayTimeParts[1] : dayTimeParts[0];
|
|
234
|
+
let secs = 0;
|
|
235
|
+
const timeParts = time.split(":").reverse();
|
|
236
|
+
for (let j = 0; j < timeParts.length; ++j)
|
|
237
|
+
secs += parseFloat(timeParts[j]) * Math.pow(60, j);
|
|
238
|
+
return days * 24 * 60 * 60 + secs;
|
|
239
|
+
}
|
|
240
|
+
let GraphItem$1 = class {
|
|
241
|
+
constructor(graph, parent) {
|
|
242
|
+
__publicField(this, "_graph");
|
|
243
|
+
__publicField(this, "parent");
|
|
244
|
+
__publicField(this, "props", {});
|
|
245
|
+
this._graph = graph, this.parent = parent;
|
|
246
|
+
}
|
|
247
|
+
}, Subgraph$1 = class Subgraph extends GraphItem$1 {
|
|
248
|
+
constructor(graph, parent, _) {
|
|
249
|
+
super(graph, parent);
|
|
250
|
+
__publicField(this, "subgraphs", []);
|
|
251
|
+
__publicField(this, "vertices", []);
|
|
252
|
+
__publicField(this, "edges", []);
|
|
253
|
+
__publicField(this, "_");
|
|
254
|
+
parent && parent._addSubgraph(this), this._ = _;
|
|
255
|
+
}
|
|
256
|
+
remove(full = !0) {
|
|
257
|
+
this._graph.removeSubgraph(this, full);
|
|
258
|
+
}
|
|
259
|
+
createSubgraph(_) {
|
|
260
|
+
return this._graph.createSubgraph(this, _);
|
|
261
|
+
}
|
|
262
|
+
_addSubgraph(subgraph) {
|
|
263
|
+
if (this.subgraphs.indexOf(subgraph) >= 0)
|
|
264
|
+
throw new Error("Subgraph already exists");
|
|
265
|
+
this.subgraphs.push(subgraph);
|
|
266
|
+
}
|
|
267
|
+
_removeSubgraph(subgraph) {
|
|
268
|
+
const idx = this.subgraphs.indexOf(subgraph);
|
|
269
|
+
if (idx < 0)
|
|
270
|
+
throw new Error("Subgraph does not exist");
|
|
271
|
+
this.subgraphs.splice(idx, 1);
|
|
272
|
+
}
|
|
273
|
+
removeAllSubgraphs() {
|
|
274
|
+
for (let i = this.subgraphs.length - 1; i >= 0; --i)
|
|
275
|
+
this._graph.removeSubgraph(this.subgraphs[i], !0);
|
|
276
|
+
}
|
|
277
|
+
createVertex(_) {
|
|
278
|
+
return this._graph.createVertex(this, _);
|
|
279
|
+
}
|
|
280
|
+
_addVertex(vertex) {
|
|
281
|
+
if (this.vertices.indexOf(vertex) >= 0)
|
|
282
|
+
throw new Error("Vertex already exists");
|
|
283
|
+
this.vertices.push(vertex);
|
|
284
|
+
}
|
|
285
|
+
_removeVertex(vertex) {
|
|
286
|
+
const idx = this.vertices.indexOf(vertex);
|
|
287
|
+
if (idx < 0)
|
|
288
|
+
throw new Error("Vertex does not exist");
|
|
289
|
+
this.vertices.splice(idx, 1);
|
|
290
|
+
}
|
|
291
|
+
removeAllVertices() {
|
|
292
|
+
for (let i = this.vertices.length - 1; i >= 0; --i)
|
|
293
|
+
this._graph.removeVertex(this.vertices[i], !0);
|
|
294
|
+
}
|
|
295
|
+
createEdge(source, target, _) {
|
|
296
|
+
return this._graph.createEdge(this, source, target, _);
|
|
297
|
+
}
|
|
298
|
+
_addEdge(edge) {
|
|
299
|
+
if (this.edges.indexOf(edge) >= 0)
|
|
300
|
+
throw new Error("Edge already exists");
|
|
301
|
+
this.edges.push(edge);
|
|
302
|
+
}
|
|
303
|
+
_removeEdge(edge) {
|
|
304
|
+
const idx = this.edges.indexOf(edge);
|
|
305
|
+
if (idx < 0)
|
|
306
|
+
throw new Error("Edge does not exist");
|
|
307
|
+
this.edges.splice(idx, 1);
|
|
308
|
+
}
|
|
309
|
+
_add(item) {
|
|
310
|
+
item instanceof Subgraph ? this._addSubgraph(item) : item instanceof Vertex$1 ? this._addVertex(item) : this._addEdge(item);
|
|
311
|
+
}
|
|
312
|
+
}, Vertex$1 = class extends GraphItem$1 {
|
|
313
|
+
constructor(graph, parent, _) {
|
|
314
|
+
super(graph, parent);
|
|
315
|
+
__publicField(this, "inEdges", []);
|
|
316
|
+
__publicField(this, "outEdges", []);
|
|
317
|
+
__publicField(this, "_");
|
|
318
|
+
parent._addVertex(this), this._ = _;
|
|
319
|
+
}
|
|
320
|
+
get edges() {
|
|
321
|
+
return [...this.inEdges, ...this.outEdges];
|
|
322
|
+
}
|
|
323
|
+
remove(full = !0, _) {
|
|
324
|
+
return this._graph.removeVertex(this, full, _);
|
|
325
|
+
}
|
|
326
|
+
addInEdge(edge) {
|
|
327
|
+
this.inEdges.push(edge);
|
|
328
|
+
}
|
|
329
|
+
removeInEdge(edge) {
|
|
330
|
+
const idx = this.inEdges.indexOf(edge);
|
|
331
|
+
if (idx < 0)
|
|
332
|
+
throw new Error("In edge does not exist");
|
|
333
|
+
this.inEdges.splice(idx, 1);
|
|
334
|
+
}
|
|
335
|
+
addOutEdge(edge) {
|
|
336
|
+
this.outEdges.push(edge);
|
|
337
|
+
}
|
|
338
|
+
removeOutEdge(edge) {
|
|
339
|
+
const idx = this.outEdges.indexOf(edge);
|
|
340
|
+
if (idx < 0)
|
|
341
|
+
throw new Error("Out edge does not exist");
|
|
342
|
+
this.outEdges.splice(idx, 1);
|
|
343
|
+
}
|
|
344
|
+
}, Edge$1 = class extends GraphItem$1 {
|
|
345
|
+
constructor(graph, parent, source, target, _) {
|
|
346
|
+
super(graph, parent);
|
|
347
|
+
__publicField(this, "source");
|
|
348
|
+
__publicField(this, "target");
|
|
349
|
+
__publicField(this, "_");
|
|
350
|
+
if (!source)
|
|
351
|
+
throw new Error("Missing source vertex");
|
|
352
|
+
if (!target)
|
|
353
|
+
throw new Error("Missing target vertex");
|
|
354
|
+
parent._addEdge(this), this.source = source, this.source.addOutEdge(this), this.target = target, this.target.addInEdge(this), this._ = _;
|
|
355
|
+
}
|
|
356
|
+
remove() {
|
|
357
|
+
this._graph.removeEdge(this);
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
class Graph {
|
|
361
|
+
constructor(idOf = (item) => "" + item._, _) {
|
|
362
|
+
__publicField(this, "root");
|
|
363
|
+
__publicField(this, "_allSubgraphs", []);
|
|
364
|
+
__publicField(this, "_allSubgraphsMap", {});
|
|
365
|
+
__publicField(this, "_allVertices", []);
|
|
366
|
+
__publicField(this, "_allVerticesMap", {});
|
|
367
|
+
__publicField(this, "_allEdges", []);
|
|
368
|
+
__publicField(this, "_allEdgesMap", {});
|
|
369
|
+
__publicField(this, "idOf");
|
|
370
|
+
this.root = new Subgraph$1(this, null, _), this.idOf = idOf;
|
|
371
|
+
}
|
|
372
|
+
createSubgraph(parent, _) {
|
|
373
|
+
const retVal = new Subgraph$1(this, parent || this.root, _);
|
|
374
|
+
return this._allSubgraphs.push(retVal), this._allSubgraphsMap[this.idOf(retVal)] = retVal, retVal;
|
|
375
|
+
}
|
|
376
|
+
removeSubgraph(subgraph, full = !0) {
|
|
377
|
+
const idx = this._allSubgraphs.indexOf(subgraph);
|
|
378
|
+
if (idx < 0)
|
|
379
|
+
throw new Error("Subgraph does not exist");
|
|
380
|
+
this._allSubgraphs.splice(idx, 1), delete this._allSubgraphsMap[this.idOf(subgraph)], subgraph.parent && subgraph.parent._removeSubgraph(subgraph), subgraph.edges.forEach((edge) => full ? this.removeEdge(edge) : subgraph.parent._addEdge(edge)), subgraph.vertices.forEach((vertex) => full ? this.removeVertex(vertex, full) : subgraph.parent._addVertex(vertex)), subgraph.subgraphs.forEach(
|
|
381
|
+
(childSubgraph) => full ? this.removeSubgraph(childSubgraph, full) : subgraph.parent._addSubgraph(childSubgraph)
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
get subgraphs() {
|
|
385
|
+
return this._allSubgraphs;
|
|
386
|
+
}
|
|
387
|
+
subgraph(id) {
|
|
388
|
+
return this._allSubgraphsMap[id];
|
|
389
|
+
}
|
|
390
|
+
createVertex(parent, _) {
|
|
391
|
+
const retVal = new Vertex$1(this, parent, _);
|
|
392
|
+
return this._allVertices.push(retVal), this._allVerticesMap[this.idOf(retVal)] = retVal, retVal;
|
|
393
|
+
}
|
|
394
|
+
removeVertex(vertex, full = !0, _) {
|
|
395
|
+
const idx = this._allVertices.indexOf(vertex);
|
|
396
|
+
if (idx < 0)
|
|
397
|
+
throw new Error("Vertex does not exist");
|
|
398
|
+
this._allVertices.splice(idx, 1), delete this._allVerticesMap[this.idOf(vertex)], vertex.parent && vertex.parent._removeVertex(vertex), full || vertex.inEdges.forEach((inEdge) => {
|
|
399
|
+
vertex.outEdges.forEach((outEdge) => {
|
|
400
|
+
this.createEdge(this.root, inEdge.source, outEdge.target, _ ? _(inEdge.source._, outEdge.target._) : void 0);
|
|
401
|
+
});
|
|
402
|
+
}), vertex.inEdges.forEach((edge) => this.removeEdge(edge)), vertex.outEdges.forEach((edge) => this.removeEdge(edge));
|
|
403
|
+
}
|
|
404
|
+
get vertices() {
|
|
405
|
+
return this._allVertices;
|
|
406
|
+
}
|
|
407
|
+
vertex(id) {
|
|
408
|
+
return this._allVerticesMap[id];
|
|
409
|
+
}
|
|
410
|
+
createEdge(parent, source, target, _) {
|
|
411
|
+
const retVal = new Edge$1(this, parent, source, target, _);
|
|
412
|
+
return this._allEdges.push(retVal), this._allEdgesMap[this.idOf(retVal)] = retVal, retVal;
|
|
413
|
+
}
|
|
414
|
+
removeEdge(edge) {
|
|
415
|
+
const idx = this._allEdges.indexOf(edge);
|
|
416
|
+
if (idx < 0)
|
|
417
|
+
throw new Error("Edge does not exist");
|
|
418
|
+
this._allEdges.splice(idx, 1), delete this._allEdgesMap[this.idOf(edge)], edge.parent && edge.parent._removeEdge(edge), edge.source.removeOutEdge(edge), edge.target.removeInEdge(edge);
|
|
419
|
+
}
|
|
420
|
+
get edges() {
|
|
421
|
+
return this._allEdges;
|
|
422
|
+
}
|
|
423
|
+
edge(id) {
|
|
424
|
+
return this._allEdgesMap[id];
|
|
425
|
+
}
|
|
426
|
+
_walk(parent, visitor) {
|
|
427
|
+
for (const subgraph of parent.subgraphs)
|
|
428
|
+
switch (visitor(subgraph)) {
|
|
429
|
+
case "abort":
|
|
430
|
+
return !0;
|
|
431
|
+
case "stepover":
|
|
432
|
+
break;
|
|
433
|
+
default:
|
|
434
|
+
if (this._walk(subgraph, visitor)) return !0;
|
|
435
|
+
}
|
|
436
|
+
for (const vertex of parent.vertices)
|
|
437
|
+
if (visitor(vertex) === "abort") return !0;
|
|
438
|
+
}
|
|
439
|
+
walk(visitor) {
|
|
440
|
+
this._walk(this.root, visitor);
|
|
441
|
+
for (const edge of this._allEdges)
|
|
442
|
+
if (visitor(edge) === "abort") return !0;
|
|
443
|
+
}
|
|
444
|
+
clone() {
|
|
445
|
+
const ctor = this.constructor, retVal = new ctor(this.idOf, this.root._), map = ObjMap();
|
|
446
|
+
return map.put(this.root, retVal.root), this.walk((item) => {
|
|
447
|
+
const parent = map.get(item.parent);
|
|
448
|
+
if (item instanceof Subgraph$1)
|
|
449
|
+
map.put(item, parent.createSubgraph(item._));
|
|
450
|
+
else if (item instanceof Vertex$1)
|
|
451
|
+
map.put(item, parent.createVertex(item._));
|
|
452
|
+
else if (item instanceof Edge$1) {
|
|
453
|
+
const source = map.get(item.source), target = map.get(item.target);
|
|
454
|
+
parent.createEdge(source, target, item._);
|
|
455
|
+
}
|
|
456
|
+
}), retVal;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
function ObjMap() {
|
|
460
|
+
const keys = [], values = [];
|
|
461
|
+
return {
|
|
462
|
+
put(key, value) {
|
|
463
|
+
const index = keys.indexOf(key);
|
|
464
|
+
index === -1 ? (keys.push(key), values.push(value)) : values[index] = value;
|
|
465
|
+
},
|
|
466
|
+
get(key) {
|
|
467
|
+
return values[keys.indexOf(key)];
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
class GraphItem2 {
|
|
472
|
+
constructor(g, _) {
|
|
473
|
+
__publicField(this, "_graph");
|
|
474
|
+
__publicField(this, "_");
|
|
475
|
+
this._graph = g, this._ = _;
|
|
476
|
+
}
|
|
477
|
+
id() {
|
|
478
|
+
return this._graph.id(this._);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
class ChildGraphItem extends GraphItem2 {
|
|
482
|
+
constructor(g, _) {
|
|
483
|
+
super(g, _);
|
|
484
|
+
__publicField(this, "_parent");
|
|
485
|
+
}
|
|
486
|
+
clearParent() {
|
|
487
|
+
return this._parent && (this._parent.removeChild(this), delete this._parent), this;
|
|
488
|
+
}
|
|
489
|
+
parent(_) {
|
|
490
|
+
return arguments.length === 0 ? this._parent : (this._parent !== _ && (this._parent && this._parent.removeChild(this), this._parent = _, this._parent && this._parent.addChild(this)), this);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
class Subgraph2 extends ChildGraphItem {
|
|
494
|
+
constructor(g, _) {
|
|
495
|
+
super(g, _);
|
|
496
|
+
__publicField(this, "_children", []);
|
|
497
|
+
}
|
|
498
|
+
children() {
|
|
499
|
+
return this._children;
|
|
500
|
+
}
|
|
501
|
+
addChild(_) {
|
|
502
|
+
this._children.push(_);
|
|
503
|
+
}
|
|
504
|
+
removeChild(_) {
|
|
505
|
+
this._children = this._children.filter((row) => row.id !== _.id);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
class Vertex2 extends ChildGraphItem {
|
|
509
|
+
constructor(g, _) {
|
|
510
|
+
super(g, _);
|
|
511
|
+
__publicField(this, "_inEdges", []);
|
|
512
|
+
__publicField(this, "_outEdges", []);
|
|
513
|
+
}
|
|
514
|
+
edges() {
|
|
515
|
+
return [...this._inEdges, ...this._outEdges];
|
|
516
|
+
}
|
|
517
|
+
edgeCount() {
|
|
518
|
+
return this._outEdges.length + this._inEdges.length;
|
|
519
|
+
}
|
|
520
|
+
inEdges() {
|
|
521
|
+
return this._inEdges;
|
|
522
|
+
}
|
|
523
|
+
addInEdge(e) {
|
|
524
|
+
this._inEdges.push(e);
|
|
525
|
+
}
|
|
526
|
+
removeInEdge(id) {
|
|
527
|
+
this._inEdges = this._inEdges.filter((e) => e._.id !== id);
|
|
528
|
+
}
|
|
529
|
+
outEdges() {
|
|
530
|
+
return this._outEdges;
|
|
531
|
+
}
|
|
532
|
+
addOutEdge(e) {
|
|
533
|
+
this._outEdges.push(e);
|
|
534
|
+
}
|
|
535
|
+
removeOutEdge(id) {
|
|
536
|
+
this._outEdges = this._outEdges.filter((e) => e._.id !== id);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
class Edge2 extends ChildGraphItem {
|
|
540
|
+
constructor(g, _, source, target) {
|
|
541
|
+
super(g, _);
|
|
542
|
+
__publicField(this, "_source");
|
|
543
|
+
__publicField(this, "_target");
|
|
544
|
+
this._source = source, this._target = target;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
class Graph2 {
|
|
548
|
+
constructor(directed = !0) {
|
|
549
|
+
__publicField(this, "_directed");
|
|
550
|
+
__publicField(this, "_subgraphMap", {});
|
|
551
|
+
__publicField(this, "_vertexMap", {});
|
|
552
|
+
__publicField(this, "_edgeMap", {});
|
|
553
|
+
__publicField(this, "_idFunc", (_) => typeof _.id == "function" ? _.id() : _.id);
|
|
554
|
+
__publicField(this, "_sourceFunc", (_) => typeof _.source == "function" ? _.source() : _.source);
|
|
555
|
+
__publicField(this, "_targetFunc", (_) => typeof _.target == "function" ? _.target() : _.target);
|
|
556
|
+
__publicField(this, "_updateFunc", (before, after) => after);
|
|
557
|
+
this._directed = directed;
|
|
558
|
+
}
|
|
559
|
+
clear() {
|
|
560
|
+
return this._subgraphMap = {}, this._vertexMap = {}, this._edgeMap = {}, this;
|
|
561
|
+
}
|
|
562
|
+
clearParents() {
|
|
563
|
+
for (const key in this._subgraphMap)
|
|
564
|
+
this._subgraphMap[key].clearParent();
|
|
565
|
+
for (const key in this._vertexMap)
|
|
566
|
+
this._vertexMap[key].clearParent();
|
|
567
|
+
return this;
|
|
568
|
+
}
|
|
569
|
+
isDirected() {
|
|
570
|
+
return this._directed;
|
|
571
|
+
}
|
|
572
|
+
idFunc(_) {
|
|
573
|
+
return this._idFunc = _, this;
|
|
574
|
+
}
|
|
575
|
+
sourceFunc(_) {
|
|
576
|
+
return this._sourceFunc = _, this;
|
|
577
|
+
}
|
|
578
|
+
targetFunc(_) {
|
|
579
|
+
return this._targetFunc = _, this;
|
|
580
|
+
}
|
|
581
|
+
updateFunc(_) {
|
|
582
|
+
return this._updateFunc = _, this;
|
|
583
|
+
}
|
|
584
|
+
id(_) {
|
|
585
|
+
return this._idFunc(_);
|
|
586
|
+
}
|
|
587
|
+
type(id) {
|
|
588
|
+
return this.subgraphExists(id) ? "S" : this.vertexExists(id) ? "V" : this.edgeExists(id) ? "E" : "";
|
|
589
|
+
}
|
|
590
|
+
isSubgraph(_) {
|
|
591
|
+
return this.subgraphExists(this.id(_));
|
|
592
|
+
}
|
|
593
|
+
isVertex(_) {
|
|
594
|
+
return this.vertexExists(this.id(_));
|
|
595
|
+
}
|
|
596
|
+
isEdge(_) {
|
|
597
|
+
return this.edgeExists(this.id(_));
|
|
598
|
+
}
|
|
599
|
+
allItems() {
|
|
600
|
+
return [...this.allSubgraphs(), ...this.allVertices(), ...this.allEdges()];
|
|
601
|
+
}
|
|
602
|
+
item(id) {
|
|
603
|
+
if (this.subgraphExists(id)) return this.subgraph(id);
|
|
604
|
+
if (this.vertexExists(id)) return this.vertex(id);
|
|
605
|
+
if (this.edgeExists(id)) return this.edge(id);
|
|
606
|
+
}
|
|
607
|
+
itemExists(id) {
|
|
608
|
+
return this.edgeExists(id) || this.vertexExists(id) || this.subgraphExists(id);
|
|
609
|
+
}
|
|
610
|
+
// Subgraphs ---
|
|
611
|
+
allSubgraphs() {
|
|
612
|
+
const retVal = [];
|
|
613
|
+
for (const key in this._subgraphMap)
|
|
614
|
+
retVal.push(this._subgraphMap[key]._);
|
|
615
|
+
return retVal;
|
|
616
|
+
}
|
|
617
|
+
subgraphs() {
|
|
618
|
+
const retVal = [];
|
|
619
|
+
for (const key in this._subgraphMap)
|
|
620
|
+
this._subgraphMap[key].parent() === void 0 && retVal.push(this._subgraphMap[key]._);
|
|
621
|
+
return retVal;
|
|
622
|
+
}
|
|
623
|
+
subgraphExists(id) {
|
|
624
|
+
return !!this._subgraphMap[id];
|
|
625
|
+
}
|
|
626
|
+
subgraph(id) {
|
|
627
|
+
return this._subgraphMap[id]._;
|
|
628
|
+
}
|
|
629
|
+
subgraphSubgraphs(id) {
|
|
630
|
+
return this._subgraphMap[id].children().filter((child) => this.isSubgraph(child._)).map((child) => child._);
|
|
631
|
+
}
|
|
632
|
+
subgraphVertices(id) {
|
|
633
|
+
return this._subgraphMap[id].children().filter((child) => this.isVertex(child._)).map((child) => child._);
|
|
634
|
+
}
|
|
635
|
+
subgraphEdges(id) {
|
|
636
|
+
return this._subgraphMap[id].children().filter((child) => this.isEdge(child._)).map((child) => child._);
|
|
637
|
+
}
|
|
638
|
+
addSubgraph(s, parent) {
|
|
639
|
+
const s_id = this._idFunc(s);
|
|
640
|
+
if (this._subgraphMap[s_id]) throw new Error(`Subgraph '${s_id}' already exists.`);
|
|
641
|
+
const subgraph = new Subgraph2(this, s);
|
|
642
|
+
if (parent) {
|
|
643
|
+
const p_id = this._idFunc(parent);
|
|
644
|
+
if (!this._subgraphMap[p_id]) throw new Error(`Subgraph '${p_id}' does not exist.`);
|
|
645
|
+
subgraph.parent(this._subgraphMap[p_id]);
|
|
646
|
+
}
|
|
647
|
+
return this._subgraphMap[s_id] = subgraph, this;
|
|
648
|
+
}
|
|
649
|
+
mergeSubgraphs(_subgraphs = []) {
|
|
650
|
+
const sgDiff = compare2(this.allSubgraphs(), _subgraphs, (sg) => this._idFunc(sg), this._updateFunc);
|
|
651
|
+
return sgDiff.exit.forEach((sg) => this.removeSubgraph(this._idFunc(sg))), sgDiff.enter.forEach((sg) => this.addSubgraph(sg)), sgDiff.update.forEach((sg) => this.updateSubgraph(sg)), this;
|
|
652
|
+
}
|
|
653
|
+
updateSubgraph(sg) {
|
|
654
|
+
const sg_id = this._idFunc(sg), subgraph = this._subgraphMap[sg_id];
|
|
655
|
+
if (!subgraph) throw new Error(`Subgraph '${sg_id}' does not exist.`);
|
|
656
|
+
return subgraph._ = sg, this;
|
|
657
|
+
}
|
|
658
|
+
removeSubgraph(id, promoteChildren = !0) {
|
|
659
|
+
const sg = this._subgraphMap[id];
|
|
660
|
+
if (!sg) throw new Error(`Subgraph '${id}' does not exist.`);
|
|
661
|
+
return sg.children().forEach((child) => {
|
|
662
|
+
promoteChildren ? child.parent(sg.parent()) : child instanceof Subgraph2 ? this.removeSubgraph(child.id()) : this.removeVertex(child.id());
|
|
663
|
+
}), delete this._subgraphMap[id], this;
|
|
664
|
+
}
|
|
665
|
+
subgraphParent(id, parentID) {
|
|
666
|
+
const item = this._subgraphMap[id];
|
|
667
|
+
if (!item) throw new Error(`Subgraph '${id}' does not exist.`);
|
|
668
|
+
if (parentID === void 0) {
|
|
669
|
+
const parent2 = item.parent();
|
|
670
|
+
return parent2 ? parent2._ : void 0;
|
|
671
|
+
}
|
|
672
|
+
const parent = this._subgraphMap[parentID];
|
|
673
|
+
if (!parent) throw new Error(`Vertex parent '${parent}' does not exist.`);
|
|
674
|
+
return item.parent(parent), this;
|
|
675
|
+
}
|
|
676
|
+
// Vertices ---
|
|
677
|
+
allVertices() {
|
|
678
|
+
const retVal = [];
|
|
679
|
+
for (const key in this._vertexMap)
|
|
680
|
+
retVal.push(this._vertexMap[key]._);
|
|
681
|
+
return retVal;
|
|
682
|
+
}
|
|
683
|
+
vertices() {
|
|
684
|
+
const retVal = [];
|
|
685
|
+
for (const key in this._vertexMap)
|
|
686
|
+
this._vertexMap[key].parent() === void 0 && retVal.push(this._vertexMap[key]._);
|
|
687
|
+
return retVal;
|
|
688
|
+
}
|
|
689
|
+
vertexExists(id) {
|
|
690
|
+
return !!this._vertexMap[id];
|
|
691
|
+
}
|
|
692
|
+
vertex(id) {
|
|
693
|
+
return this._vertexMap[id]._;
|
|
694
|
+
}
|
|
695
|
+
allEdges() {
|
|
696
|
+
const retVal = [];
|
|
697
|
+
for (const key in this._edgeMap)
|
|
698
|
+
retVal.push(this._edgeMap[key]._);
|
|
699
|
+
return retVal;
|
|
700
|
+
}
|
|
701
|
+
edges() {
|
|
702
|
+
const retVal = [];
|
|
703
|
+
for (const key in this._edgeMap)
|
|
704
|
+
this._edgeMap[key].parent() === void 0 && retVal.push(this._edgeMap[key]._);
|
|
705
|
+
return retVal;
|
|
706
|
+
}
|
|
707
|
+
vertexEdges(vertexID) {
|
|
708
|
+
return this._vertexMap[vertexID].edges().map((e) => e._);
|
|
709
|
+
}
|
|
710
|
+
inEdges(vertexID) {
|
|
711
|
+
return this._vertexMap[vertexID].inEdges().map((e) => e._);
|
|
712
|
+
}
|
|
713
|
+
outEdges(vertexID) {
|
|
714
|
+
return this._vertexMap[vertexID].outEdges().map((e) => e._);
|
|
715
|
+
}
|
|
716
|
+
_neighbors(id) {
|
|
717
|
+
return [...this._vertexMap[id].outEdges().map((e) => e._target), ...this._vertexMap[id].inEdges().map((e) => e._source)];
|
|
718
|
+
}
|
|
719
|
+
neighbors(id) {
|
|
720
|
+
return this._neighbors(id).map((n) => n._);
|
|
721
|
+
}
|
|
722
|
+
singleNeighbors(id) {
|
|
723
|
+
return this._neighbors(id).filter((n) => n.edgeCount() === 1).map((n) => n._);
|
|
724
|
+
}
|
|
725
|
+
addVertex(v, parent) {
|
|
726
|
+
const v_id = this._idFunc(v);
|
|
727
|
+
if (this._vertexMap[v_id]) throw new Error(`Vertex '${v_id}' already exists.`);
|
|
728
|
+
const vertex = new Vertex2(this, v);
|
|
729
|
+
if (parent) {
|
|
730
|
+
const p_id = this._idFunc(parent);
|
|
731
|
+
if (!this.subgraphExists(p_id)) throw new Error(`Subgraph '${p_id}' does not exist.`);
|
|
732
|
+
vertex.parent(this._subgraphMap[p_id]);
|
|
733
|
+
}
|
|
734
|
+
return this._vertexMap[v_id] = vertex, this;
|
|
735
|
+
}
|
|
736
|
+
mergeVertices(_vertices) {
|
|
737
|
+
const vDiff = compare2(this.allVertices(), _vertices, (v) => this._idFunc(v), this._updateFunc);
|
|
738
|
+
return vDiff.exit.forEach((v) => this.removeVertex(this._idFunc(v))), vDiff.enter.forEach((v) => this.addVertex(v)), vDiff.update.forEach((v) => this.updateVertex(v)), this;
|
|
739
|
+
}
|
|
740
|
+
updateVertex(v) {
|
|
741
|
+
const v_id = this._idFunc(v), vertex = this._vertexMap[v_id];
|
|
742
|
+
if (!vertex) throw new Error(`Vertex '${v_id}' does not exist.`);
|
|
743
|
+
return vertex._ = v, this;
|
|
744
|
+
}
|
|
745
|
+
removeVertex(id) {
|
|
746
|
+
const v = this._vertexMap[id];
|
|
747
|
+
if (!v) throw new Error(`Vertex '${id}' does not exist.`);
|
|
748
|
+
return v.edges().forEach((e) => {
|
|
749
|
+
this.removeEdge(e.id());
|
|
750
|
+
}), delete this._vertexMap[id], this;
|
|
751
|
+
}
|
|
752
|
+
vertexParent(id, parentID) {
|
|
753
|
+
const item = this._vertexMap[id];
|
|
754
|
+
if (!item) throw new Error(`Vertex '${id}' does not exist.`);
|
|
755
|
+
if (parentID === void 0) {
|
|
756
|
+
const parent2 = item.parent();
|
|
757
|
+
return parent2 ? parent2._ : void 0;
|
|
758
|
+
}
|
|
759
|
+
const parent = this._subgraphMap[parentID];
|
|
760
|
+
if (!parent) throw new Error(`Vertex parent '${parent}' does not exist.`);
|
|
761
|
+
return item.parent(parent), this;
|
|
762
|
+
}
|
|
763
|
+
// Edges ---
|
|
764
|
+
edgeExists(id) {
|
|
765
|
+
return !!this._edgeMap[id];
|
|
766
|
+
}
|
|
767
|
+
edge(id) {
|
|
768
|
+
return this._edgeMap[id]._;
|
|
769
|
+
}
|
|
770
|
+
addEdge(e, parent) {
|
|
771
|
+
const e_id = this._idFunc(e), e_source = this._sourceFunc(e), e_target = this._targetFunc(e);
|
|
772
|
+
if (this._edgeMap[e_id]) throw new Error(`Edge '${e_id}' already exists.`);
|
|
773
|
+
if (!this.vertexExists(e_source)) throw new Error(`Edge Source '${e_source}' does not exist.`);
|
|
774
|
+
if (!this.vertexExists(e_target)) throw new Error(`Edge Target '${e_target}' does not exist.`);
|
|
775
|
+
const edge = new Edge2(this, e, this._vertexMap[e_source], this._vertexMap[e_target]);
|
|
776
|
+
if (parent) {
|
|
777
|
+
const p_id = this._idFunc(parent);
|
|
778
|
+
if (!this.subgraphExists(p_id)) throw new Error(`Subgraph '${p_id}' does not exist.`);
|
|
779
|
+
edge.parent(this._subgraphMap[p_id]);
|
|
780
|
+
}
|
|
781
|
+
return this._edgeMap[e_id] = edge, this._vertexMap[e_source].addOutEdge(edge), this._vertexMap[e_target].addInEdge(edge), this;
|
|
782
|
+
}
|
|
783
|
+
mergeEdges(_edges) {
|
|
784
|
+
const eDiff = compare2(this.allEdges(), _edges, (e) => this._idFunc(e), this._updateFunc);
|
|
785
|
+
return eDiff.exit.forEach((e) => this.removeEdge(this._idFunc(e))), eDiff.enter.forEach((e) => this.addEdge(e)), eDiff.update.forEach((e) => this.updateEdge(e)), this;
|
|
786
|
+
}
|
|
787
|
+
updateEdge(e) {
|
|
788
|
+
var _a, _b, _c, _d;
|
|
789
|
+
const e_id = this._idFunc(e), edge = this._edgeMap[e_id];
|
|
790
|
+
if (!edge) throw new Error(`Edge '${e_id}' does not exist.`);
|
|
791
|
+
const old_source = edge._source.id(), new_source = this._sourceFunc(e);
|
|
792
|
+
old_source !== new_source && ((_a = this._vertexMap[old_source]) == null || _a.removeOutEdge(e_id), (_b = this._vertexMap[new_source]) == null || _b.addOutEdge(edge));
|
|
793
|
+
const old_target = edge._target.id(), new_target = this._targetFunc(e);
|
|
794
|
+
return old_target !== new_target && ((_c = this._vertexMap[old_target]) == null || _c.removeInEdge(e_id), (_d = this._vertexMap[new_target]) == null || _d.addInEdge(edge)), edge._ = e, edge._source = this._vertexMap[new_source], edge._target = this._vertexMap[new_target], this;
|
|
795
|
+
}
|
|
796
|
+
removeEdge(id) {
|
|
797
|
+
const e = this._edgeMap[id];
|
|
798
|
+
if (!e) throw new Error(`Edge '${id}' does not exist.`);
|
|
799
|
+
const e_sourceID = this._idFunc(e._source._);
|
|
800
|
+
if (!this.vertexExists(e_sourceID)) throw new Error(`Edge Source'${e_sourceID}' does not exist.`);
|
|
801
|
+
this._vertexMap[e_sourceID].removeOutEdge(id);
|
|
802
|
+
const e_targetID = this._idFunc(e._target._);
|
|
803
|
+
if (!this.vertexExists(e_targetID)) throw new Error(`Edge Target'${e_targetID}' does not exist.`);
|
|
804
|
+
return this._vertexMap[e_targetID].removeInEdge(id), delete this._edgeMap[id], this;
|
|
805
|
+
}
|
|
806
|
+
_hwalk(item, formatter) {
|
|
807
|
+
return item instanceof Subgraph2 ? formatter("subgraph", item._, item.children().map((child) => this._hwalk(child, formatter))) : formatter("vertex", item._);
|
|
808
|
+
}
|
|
809
|
+
hierarchy(formatter) {
|
|
810
|
+
const retVal = [];
|
|
811
|
+
for (const id in this._subgraphMap) {
|
|
812
|
+
const sg = this._subgraphMap[id];
|
|
813
|
+
sg.parent() === void 0 && retVal.push(this._hwalk(sg, formatter));
|
|
814
|
+
}
|
|
815
|
+
for (const id in this._vertexMap) {
|
|
816
|
+
const v = this._vertexMap[id];
|
|
817
|
+
v.parent() === void 0 && retVal.push(this._hwalk(v, formatter));
|
|
818
|
+
}
|
|
819
|
+
return retVal;
|
|
820
|
+
}
|
|
821
|
+
dijkstra(source, target) {
|
|
822
|
+
const edges = this.allEdges(), Q = new Set(), prev = {}, dist = {}, adj = {};
|
|
823
|
+
function vertex_with_min_dist(Q2, dist2) {
|
|
824
|
+
let min_distance = 1 / 0, u2 = null;
|
|
825
|
+
return Q2.forEach((v) => {
|
|
826
|
+
dist2[v] < min_distance && (min_distance = dist2[v], u2 = v);
|
|
827
|
+
}), u2;
|
|
828
|
+
}
|
|
829
|
+
for (let i = 0; i < edges.length; i++) {
|
|
830
|
+
const v1 = this._sourceFunc(edges[i]), v2 = this._targetFunc(edges[i]), len2 = 1;
|
|
831
|
+
Q.add(v1), Q.add(v2), dist[v1] = 1 / 0, dist[v2] = 1 / 0, adj[v1] === void 0 && (adj[v1] = {}), adj[v2] === void 0 && (adj[v2] = {}), adj[v1][v2] = len2, adj[v2][v1] = len2;
|
|
832
|
+
}
|
|
833
|
+
for (dist[source] = 0; Q.size; ) {
|
|
834
|
+
const u2 = vertex_with_min_dist(Q, dist);
|
|
835
|
+
if (u2 === null) break;
|
|
836
|
+
const neighbors = Object.keys(adj[u2]).filter((v) => Q.has(v));
|
|
837
|
+
if (Q.delete(u2), u2 === target) break;
|
|
838
|
+
for (const v of neighbors) {
|
|
839
|
+
const alt = dist[u2] + adj[u2][v];
|
|
840
|
+
alt < dist[v] && (dist[v] = alt, prev[v] = u2);
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
let u = target;
|
|
844
|
+
const ids = [u];
|
|
845
|
+
let len = 0;
|
|
846
|
+
for (; prev[u] !== void 0; )
|
|
847
|
+
ids.unshift(prev[u]), len += adj[u][prev[u]], u = prev[u];
|
|
848
|
+
return { ids, len };
|
|
849
|
+
}
|
|
850
|
+
sort(v_id) {
|
|
851
|
+
const retVal = [], visited = {}, visit = (vertex, ancestors = []) => {
|
|
852
|
+
const v_id2 = vertex.id();
|
|
853
|
+
visited[v_id2] || (visited[v_id2] = !0, ancestors.push(vertex), vertex.outEdges().forEach((e) => {
|
|
854
|
+
ancestors.indexOf(e._target) < 0 && visit(e._target, [...ancestors]);
|
|
855
|
+
}), retVal.unshift(vertex._));
|
|
856
|
+
};
|
|
857
|
+
if (v_id)
|
|
858
|
+
visit(this._vertexMap[v_id]);
|
|
859
|
+
else
|
|
860
|
+
for (const key in this._vertexMap)
|
|
861
|
+
visit(this._vertexMap[key]);
|
|
862
|
+
return retVal;
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
class Set {
|
|
866
|
+
constructor() {
|
|
867
|
+
__publicField(this, "_content", []);
|
|
868
|
+
}
|
|
869
|
+
get size() {
|
|
870
|
+
return this._content.length;
|
|
871
|
+
}
|
|
872
|
+
has(_) {
|
|
873
|
+
return this._content.indexOf(_) >= 0;
|
|
874
|
+
}
|
|
875
|
+
add(_) {
|
|
876
|
+
this.has(_) || this._content.push(_);
|
|
877
|
+
}
|
|
878
|
+
delete(_) {
|
|
879
|
+
const idx = this._content.indexOf(_);
|
|
880
|
+
idx >= 0 && this._content.splice(idx, 1);
|
|
881
|
+
}
|
|
882
|
+
forEach(_) {
|
|
883
|
+
this._content.forEach(_);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
const isArray$1 = Array.isArray, keyList = Object.keys, hasProp = Object.prototype.hasOwnProperty;
|
|
887
|
+
function verboseDeepEquals(a, b, functionRefCompare = !1) {
|
|
888
|
+
if (a === b) return !0;
|
|
889
|
+
if (a && b) {
|
|
890
|
+
if (typeof a == "object" && typeof b == "object") {
|
|
891
|
+
const arrA = isArray$1(a), arrB = isArray$1(b);
|
|
892
|
+
let i, length, key;
|
|
893
|
+
if (arrA && arrB) {
|
|
894
|
+
if (length = a.length, length !== b.length)
|
|
895
|
+
return console.warn(`lengths not equal: ${length} !== ${b.length}`), !1;
|
|
896
|
+
for (i = length; i-- !== 0; )
|
|
897
|
+
if (!verboseDeepEquals(a[i], b[i], functionRefCompare))
|
|
898
|
+
return !1;
|
|
899
|
+
return !0;
|
|
900
|
+
}
|
|
901
|
+
if (arrA !== arrB)
|
|
902
|
+
return console.warn(`arrays not equal: ${arrA} !== ${arrB}`), !1;
|
|
903
|
+
const dateA = a instanceof Date, dateB = b instanceof Date;
|
|
904
|
+
if (dateA !== dateB)
|
|
905
|
+
return console.warn(`dates not equal: ${dateA} !== ${dateB}`), !1;
|
|
906
|
+
if (dateA && dateB) {
|
|
907
|
+
const retVal2 = a.getTime() === b.getTime();
|
|
908
|
+
return retVal2 || console.warn(`dates not equal: ${a.getTime()} !== ${b.getTime()}`), retVal2;
|
|
909
|
+
}
|
|
910
|
+
const regexpA = a instanceof RegExp, regexpB = b instanceof RegExp;
|
|
911
|
+
if (regexpA !== regexpB)
|
|
912
|
+
return console.warn(`regexps not equal: ${regexpA} !== ${regexpB}`), !1;
|
|
913
|
+
if (regexpA && regexpB) {
|
|
914
|
+
const retVal2 = a.toString() === b.toString();
|
|
915
|
+
return retVal2 || console.warn(`regexps not equal: ${a.toString()} !== ${b.toString()}`), retVal2;
|
|
916
|
+
}
|
|
917
|
+
const keys = keyList(a);
|
|
918
|
+
if (length = keys.length, length !== keyList(b).length)
|
|
919
|
+
return console.warn(`key lengths not equal: ${length} !== ${keyList(b).length}`), !1;
|
|
920
|
+
for (i = length; i-- !== 0; )
|
|
921
|
+
if (!hasProp.call(b, keys[i]))
|
|
922
|
+
return console.warn(`${keys[i]} in a but not b`), !1;
|
|
923
|
+
for (i = length; i-- !== 0; )
|
|
924
|
+
if (key = keys[i], !verboseDeepEquals(a[key], b[key], functionRefCompare))
|
|
925
|
+
return !1;
|
|
926
|
+
return !0;
|
|
927
|
+
} else if (!functionRefCompare && typeof a == "function" && typeof b == "function") {
|
|
928
|
+
const retVal2 = a.toString() === b.toString();
|
|
929
|
+
return retVal2 || console.warn(`functions not equal: ${a.toString()} !== ${b.toString()}`), retVal2;
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
const retVal = a !== a && b !== b;
|
|
933
|
+
return retVal || console.warn(`values not equal: ${a} !== ${b}`), retVal;
|
|
934
|
+
}
|
|
935
|
+
function deepEquals(a, b, functionRefCompare = !1) {
|
|
936
|
+
if (a === b) return !0;
|
|
937
|
+
if (a && b) {
|
|
938
|
+
if (typeof a == "object" && typeof b == "object") {
|
|
939
|
+
const arrA = isArray$1(a), arrB = isArray$1(b);
|
|
940
|
+
let i, length, key;
|
|
941
|
+
if (arrA && arrB) {
|
|
942
|
+
if (length = a.length, length !== b.length) return !1;
|
|
943
|
+
for (i = length; i-- !== 0; )
|
|
944
|
+
if (!deepEquals(a[i], b[i], functionRefCompare)) return !1;
|
|
945
|
+
return !0;
|
|
946
|
+
}
|
|
947
|
+
if (arrA !== arrB) return !1;
|
|
948
|
+
const dateA = a instanceof Date, dateB = b instanceof Date;
|
|
949
|
+
if (dateA !== dateB) return !1;
|
|
950
|
+
if (dateA && dateB) return a.getTime() === b.getTime();
|
|
951
|
+
const regexpA = a instanceof RegExp, regexpB = b instanceof RegExp;
|
|
952
|
+
if (regexpA !== regexpB) return !1;
|
|
953
|
+
if (regexpA && regexpB) return a.toString() === b.toString();
|
|
954
|
+
const keys = keyList(a);
|
|
955
|
+
if (length = keys.length, length !== keyList(b).length)
|
|
956
|
+
return !1;
|
|
957
|
+
for (i = length; i-- !== 0; )
|
|
958
|
+
if (!hasProp.call(b, keys[i])) return !1;
|
|
959
|
+
for (i = length; i-- !== 0; )
|
|
960
|
+
if (key = keys[i], !deepEquals(a[key], b[key], functionRefCompare)) return !1;
|
|
961
|
+
return !0;
|
|
962
|
+
} else if (!functionRefCompare && typeof a == "function" && typeof b == "function")
|
|
963
|
+
return a.toString() === b.toString();
|
|
964
|
+
}
|
|
965
|
+
return a !== a && b !== b;
|
|
966
|
+
}
|
|
967
|
+
function update(origItem, newItem, functionRefCompare = !1) {
|
|
968
|
+
return deepEquals(origItem, newItem, functionRefCompare) ? origItem : newItem;
|
|
969
|
+
}
|
|
970
|
+
const root = typeof globalThis < "u" ? globalThis : window, isBrowser = typeof window < "u" && root === window, isNode = typeof process < "u" && process.versions != null && process.versions.node != null, isCI = isNode && process.env != null && (process.env.TRAVIS != null || process.env.GITHUB_ACTIONS != null);
|
|
971
|
+
function getScriptSrc(partial) {
|
|
972
|
+
const scripts = document.scripts || [];
|
|
973
|
+
for (let i = document.scripts.length - 1; i >= 0; --i) {
|
|
974
|
+
const script = scripts[i];
|
|
975
|
+
if (script.src) {
|
|
976
|
+
const idx = script.src.indexOf(partial);
|
|
977
|
+
if (idx >= 0)
|
|
978
|
+
return script.src.substring(0, idx);
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
return "";
|
|
982
|
+
}
|
|
983
|
+
class Stack {
|
|
984
|
+
constructor() {
|
|
985
|
+
__publicField(this, "stack", []);
|
|
986
|
+
}
|
|
987
|
+
/**
|
|
988
|
+
* Push element onto the stack
|
|
989
|
+
*
|
|
990
|
+
* @param e - element to push
|
|
991
|
+
*/
|
|
992
|
+
push(e) {
|
|
993
|
+
return this.stack.push(e), e;
|
|
994
|
+
}
|
|
995
|
+
/**
|
|
996
|
+
* Pop element off the stack
|
|
997
|
+
*/
|
|
998
|
+
pop() {
|
|
999
|
+
return this.stack.pop();
|
|
1000
|
+
}
|
|
1001
|
+
/**
|
|
1002
|
+
* Top item on the stack
|
|
1003
|
+
*
|
|
1004
|
+
* @returns Top element on the stack
|
|
1005
|
+
*/
|
|
1006
|
+
top() {
|
|
1007
|
+
return this.stack.length ? this.stack[this.stack.length - 1] : void 0;
|
|
1008
|
+
}
|
|
1009
|
+
/**
|
|
1010
|
+
* Depth of stack
|
|
1011
|
+
*
|
|
1012
|
+
* @returns Depth
|
|
1013
|
+
*/
|
|
1014
|
+
depth() {
|
|
1015
|
+
return this.stack.length;
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
var Level = /* @__PURE__ */ ((Level2) => (Level2[Level2.debug = 0] = "debug", Level2[Level2.info = 1] = "info", Level2[Level2.notice = 2] = "notice", Level2[Level2.warning = 3] = "warning", Level2[Level2.error = 4] = "error", Level2[Level2.critical = 5] = "critical", Level2[Level2.alert = 6] = "alert", Level2[Level2.emergency = 7] = "emergency", Level2))(Level || {});
|
|
1019
|
+
const colours = {
|
|
1020
|
+
debug: "cyan",
|
|
1021
|
+
info: "green",
|
|
1022
|
+
notice: "grey",
|
|
1023
|
+
warning: "blue",
|
|
1024
|
+
error: "red",
|
|
1025
|
+
critical: "magenta",
|
|
1026
|
+
alert: "magenta",
|
|
1027
|
+
emergency: "magenta"
|
|
1028
|
+
};
|
|
1029
|
+
class ConsoleWriter {
|
|
1030
|
+
write(dateTime, level, id, msg) {
|
|
1031
|
+
isNode ? console.log(`[${dateTime}] ${Level[level].toUpperCase()} ${id}: ${msg}`) : console.log(`[${dateTime}] %c${Level[level].toUpperCase()}%c ${id}: ${msg}`, `color:${colours[Level[level]]}`, "");
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
class Logging {
|
|
1035
|
+
constructor() {
|
|
1036
|
+
__publicField(this, "_levelStack", new Stack());
|
|
1037
|
+
__publicField(this, "_level", 1);
|
|
1038
|
+
__publicField(this, "_filter", "");
|
|
1039
|
+
__publicField(this, "_writer", new ConsoleWriter());
|
|
1040
|
+
}
|
|
1041
|
+
static Instance() {
|
|
1042
|
+
return this._instance || (this._instance = new this());
|
|
1043
|
+
}
|
|
1044
|
+
stringify(obj) {
|
|
1045
|
+
const cache = [];
|
|
1046
|
+
return JSON.stringify(obj, function(_key, value) {
|
|
1047
|
+
if (typeof value == "object" && value !== null) {
|
|
1048
|
+
if (cache.indexOf(value) !== -1)
|
|
1049
|
+
return;
|
|
1050
|
+
cache.push(value);
|
|
1051
|
+
}
|
|
1052
|
+
return value;
|
|
1053
|
+
}, 2);
|
|
1054
|
+
}
|
|
1055
|
+
writer(_) {
|
|
1056
|
+
return _ === void 0 ? this._writer : (this._writer = _, this);
|
|
1057
|
+
}
|
|
1058
|
+
log(level, id, msg) {
|
|
1059
|
+
if (level < this._level || this._filter && this._filter !== id) return;
|
|
1060
|
+
const dateTime = (/* @__PURE__ */ new Date()).toISOString();
|
|
1061
|
+
this._writer.rawWrite ? this._writer.rawWrite(dateTime, level, id, msg) : (typeof msg != "string" && (msg = this.stringify(msg)), this._writer.write && this._writer.write(dateTime, level, id, msg));
|
|
1062
|
+
}
|
|
1063
|
+
debug(id, msg) {
|
|
1064
|
+
this.log(0, id, msg);
|
|
1065
|
+
}
|
|
1066
|
+
info(id, msg) {
|
|
1067
|
+
this.log(1, id, msg);
|
|
1068
|
+
}
|
|
1069
|
+
notice(id, msg) {
|
|
1070
|
+
this.log(2, id, msg);
|
|
1071
|
+
}
|
|
1072
|
+
warning(id, msg) {
|
|
1073
|
+
this.log(3, id, msg);
|
|
1074
|
+
}
|
|
1075
|
+
error(id, msg) {
|
|
1076
|
+
this.log(4, id, msg);
|
|
1077
|
+
}
|
|
1078
|
+
critical(id, msg) {
|
|
1079
|
+
this.log(5, id, msg);
|
|
1080
|
+
}
|
|
1081
|
+
alert(id, msg) {
|
|
1082
|
+
this.log(6, id, msg);
|
|
1083
|
+
}
|
|
1084
|
+
emergency(id, msg) {
|
|
1085
|
+
this.log(7, id, msg);
|
|
1086
|
+
}
|
|
1087
|
+
level(_) {
|
|
1088
|
+
return _ === void 0 ? this._level : (this._level = _, this);
|
|
1089
|
+
}
|
|
1090
|
+
pushLevel(_) {
|
|
1091
|
+
return this._levelStack.push(this._level), this._level = _, this;
|
|
1092
|
+
}
|
|
1093
|
+
popLevel() {
|
|
1094
|
+
return this._level = this._levelStack.pop(), this;
|
|
1095
|
+
}
|
|
1096
|
+
filter(_) {
|
|
1097
|
+
return _ === void 0 ? this._filter : (this._filter = _, this);
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
__publicField(Logging, "_instance");
|
|
1101
|
+
const logger = Logging.Instance();
|
|
1102
|
+
class ScopedLogging {
|
|
1103
|
+
constructor(scopeID) {
|
|
1104
|
+
__publicField(this, "_scopeID");
|
|
1105
|
+
this._scopeID = scopeID;
|
|
1106
|
+
}
|
|
1107
|
+
debug(msg) {
|
|
1108
|
+
logger.debug(this._scopeID, msg);
|
|
1109
|
+
}
|
|
1110
|
+
info(msg) {
|
|
1111
|
+
logger.info(this._scopeID, msg);
|
|
1112
|
+
}
|
|
1113
|
+
notice(msg) {
|
|
1114
|
+
logger.notice(this._scopeID, msg);
|
|
1115
|
+
}
|
|
1116
|
+
warning(msg) {
|
|
1117
|
+
logger.warning(this._scopeID, msg);
|
|
1118
|
+
}
|
|
1119
|
+
error(msg) {
|
|
1120
|
+
logger.error(this._scopeID, msg);
|
|
1121
|
+
}
|
|
1122
|
+
critical(msg) {
|
|
1123
|
+
logger.critical(this._scopeID, msg);
|
|
1124
|
+
}
|
|
1125
|
+
alert(msg) {
|
|
1126
|
+
logger.alert(this._scopeID, msg);
|
|
1127
|
+
}
|
|
1128
|
+
emergency(msg) {
|
|
1129
|
+
logger.emergency(this._scopeID, msg);
|
|
1130
|
+
}
|
|
1131
|
+
pushLevel(_) {
|
|
1132
|
+
return logger.pushLevel(_), this;
|
|
1133
|
+
}
|
|
1134
|
+
popLevel() {
|
|
1135
|
+
return logger.popLevel(), this;
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
function scopedLogger(scopeID, filter = !1) {
|
|
1139
|
+
return filter && logger.filter(scopeID), new ScopedLogging(scopeID);
|
|
1140
|
+
}
|
|
1141
|
+
function degreesToRadians(degrees) {
|
|
1142
|
+
return degrees * (Math.PI / 180);
|
|
1143
|
+
}
|
|
1144
|
+
function radiansToDegrees(radians) {
|
|
1145
|
+
return radians * (180 / Math.PI);
|
|
1146
|
+
}
|
|
1147
|
+
function polarToCartesian(r, theta) {
|
|
1148
|
+
return {
|
|
1149
|
+
x: r * Math.cos(theta),
|
|
1150
|
+
y: r * Math.sin(theta)
|
|
1151
|
+
};
|
|
1152
|
+
}
|
|
1153
|
+
function cartesianToPolar(x, y) {
|
|
1154
|
+
return {
|
|
1155
|
+
r: Math.sqrt(x * x + y * y),
|
|
1156
|
+
theta: Math.atan2(y, x)
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
function normalizeRadians(radians, min = -Math.PI, max = Math.PI) {
|
|
1160
|
+
return normalize(radians, min, max);
|
|
1161
|
+
}
|
|
1162
|
+
function normalizeDegrees(degrees, min = -180, max = 180) {
|
|
1163
|
+
return normalize(degrees, min, max);
|
|
1164
|
+
}
|
|
1165
|
+
function normalize(value, min, max) {
|
|
1166
|
+
const spread = max - min, offsetValue = value - min;
|
|
1167
|
+
return offsetValue - Math.floor(offsetValue / spread) * spread + min;
|
|
1168
|
+
}
|
|
1169
|
+
function inner(prop, obj) {
|
|
1170
|
+
if (!(prop === void 0 || obj === void 0)) {
|
|
1171
|
+
for (const item of prop.split(".")) {
|
|
1172
|
+
if (!obj.hasOwnProperty(item))
|
|
1173
|
+
return;
|
|
1174
|
+
obj = obj[item];
|
|
1175
|
+
}
|
|
1176
|
+
return obj;
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
function exists(prop, obj) {
|
|
1180
|
+
return inner(prop, obj) !== void 0;
|
|
1181
|
+
}
|
|
1182
|
+
function _mixin(dest, source) {
|
|
1183
|
+
const empty = {};
|
|
1184
|
+
for (const key in source) {
|
|
1185
|
+
if (!source.hasOwnProperty(key) || key === "__proto__" || key === "constructor") continue;
|
|
1186
|
+
let s = source[key];
|
|
1187
|
+
s instanceof Array || typeof s == "object" && (s = deepMixin(dest[key], s)), (!(key in dest) || dest[key] !== s && (!(key in empty) || empty[key] !== s)) && (dest[key] = s);
|
|
1188
|
+
}
|
|
1189
|
+
return dest;
|
|
1190
|
+
}
|
|
1191
|
+
function deepMixin(dest = {}, ...sources) {
|
|
1192
|
+
if (typeof dest != "object") throw new Error(`Destination "${dest}" must be an object.`);
|
|
1193
|
+
for (const source of sources)
|
|
1194
|
+
_mixin(dest, source);
|
|
1195
|
+
return dest;
|
|
1196
|
+
}
|
|
1197
|
+
function deepMixinT(dest = {}, ...sources) {
|
|
1198
|
+
return deepMixin(dest, ...sources);
|
|
1199
|
+
}
|
|
1200
|
+
function safeStringify(obj) {
|
|
1201
|
+
const cache = [];
|
|
1202
|
+
return JSON.stringify(obj, function(key, value) {
|
|
1203
|
+
if (typeof value == "object" && value !== null) {
|
|
1204
|
+
if (cache.indexOf(value) !== -1)
|
|
1205
|
+
return;
|
|
1206
|
+
cache.push(value);
|
|
1207
|
+
}
|
|
1208
|
+
return value;
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
function isArray(arg) {
|
|
1212
|
+
return Array.isArray !== void 0 ? Array.isArray(arg) : Object.prototype.toString.call(arg) === "[object Array]";
|
|
1213
|
+
}
|
|
1214
|
+
function classID2Meta(classID) {
|
|
1215
|
+
const info = classID.split("_"), classInfo = info[1].split(".");
|
|
1216
|
+
return {
|
|
1217
|
+
module: `@hpcc-js/${info[0]}`,
|
|
1218
|
+
file: classInfo[0],
|
|
1219
|
+
class: classInfo[1] || classInfo[0]
|
|
1220
|
+
};
|
|
1221
|
+
}
|
|
1222
|
+
class ObserverHandle {
|
|
1223
|
+
constructor(eventTarget, eventID, callback) {
|
|
1224
|
+
__publicField(this, "eventTarget");
|
|
1225
|
+
__publicField(this, "eventID");
|
|
1226
|
+
__publicField(this, "callback");
|
|
1227
|
+
this.eventTarget = eventTarget, this.eventID = eventID, this.callback = callback;
|
|
1228
|
+
}
|
|
1229
|
+
release() {
|
|
1230
|
+
this.eventTarget.removeObserver(this.eventID, this.callback);
|
|
1231
|
+
}
|
|
1232
|
+
unwatch() {
|
|
1233
|
+
this.release();
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
class Observable {
|
|
1237
|
+
constructor(...events) {
|
|
1238
|
+
__publicField(this, "_eventObservers", {});
|
|
1239
|
+
}
|
|
1240
|
+
addObserver(eventID, callback) {
|
|
1241
|
+
let eventObservers = this._eventObservers[eventID];
|
|
1242
|
+
return eventObservers || (eventObservers = [], this._eventObservers[eventID] = eventObservers), eventObservers.push(callback), new ObserverHandle(this, eventID, callback);
|
|
1243
|
+
}
|
|
1244
|
+
removeObserver(eventID, callback) {
|
|
1245
|
+
const eventObservers = this._eventObservers[eventID];
|
|
1246
|
+
if (eventObservers)
|
|
1247
|
+
for (let i = eventObservers.length - 1; i >= 0; --i)
|
|
1248
|
+
eventObservers[i] === callback && eventObservers.splice(i, 1);
|
|
1249
|
+
return this;
|
|
1250
|
+
}
|
|
1251
|
+
dispatchEvent(eventID, ...args) {
|
|
1252
|
+
const eventObservers = this._eventObservers[eventID];
|
|
1253
|
+
if (eventObservers)
|
|
1254
|
+
for (const observer of eventObservers)
|
|
1255
|
+
observer(...args);
|
|
1256
|
+
return this;
|
|
1257
|
+
}
|
|
1258
|
+
_hasObserver(eventID) {
|
|
1259
|
+
const eventObservers = this._eventObservers[eventID];
|
|
1260
|
+
for (const observer in eventObservers)
|
|
1261
|
+
if (eventObservers[observer])
|
|
1262
|
+
return !0;
|
|
1263
|
+
return !1;
|
|
1264
|
+
}
|
|
1265
|
+
hasObserver(_eventID) {
|
|
1266
|
+
if (_eventID !== void 0)
|
|
1267
|
+
return this._hasObserver(_eventID);
|
|
1268
|
+
for (const eventID in this._eventObservers)
|
|
1269
|
+
if (this._hasObserver(eventID))
|
|
1270
|
+
return !0;
|
|
1271
|
+
return !1;
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
let requestAnimationFrame;
|
|
1275
|
+
(function() {
|
|
1276
|
+
if (root.requestAnimationFrame)
|
|
1277
|
+
requestAnimationFrame = root.requestAnimationFrame;
|
|
1278
|
+
else {
|
|
1279
|
+
let lastTime = 0;
|
|
1280
|
+
requestAnimationFrame = function(callback) {
|
|
1281
|
+
const currTime = (/* @__PURE__ */ new Date()).getTime(), timeToCall = Math.max(0, 16 - (currTime - lastTime)), id = setTimeout(() => callback(currTime + timeToCall), timeToCall);
|
|
1282
|
+
return lastTime = currTime + timeToCall, id;
|
|
1283
|
+
};
|
|
1284
|
+
}
|
|
1285
|
+
})();
|
|
1286
|
+
class Message {
|
|
1287
|
+
get canConflate() {
|
|
1288
|
+
return !1;
|
|
1289
|
+
}
|
|
1290
|
+
conflate(other) {
|
|
1291
|
+
return !1;
|
|
1292
|
+
}
|
|
1293
|
+
void() {
|
|
1294
|
+
return !1;
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
class Dispatch {
|
|
1298
|
+
constructor() {
|
|
1299
|
+
__publicField(this, "_observerID", 0);
|
|
1300
|
+
__publicField(this, "_observers", []);
|
|
1301
|
+
__publicField(this, "_messageBuffer", []);
|
|
1302
|
+
}
|
|
1303
|
+
observers() {
|
|
1304
|
+
return this._observers;
|
|
1305
|
+
}
|
|
1306
|
+
messages() {
|
|
1307
|
+
const retVal = [];
|
|
1308
|
+
return this._messageBuffer.forEach((msg) => {
|
|
1309
|
+
retVal.some((msg2) => msg2.canConflate && msg2.conflate(msg)) || retVal.push(msg);
|
|
1310
|
+
}), retVal;
|
|
1311
|
+
}
|
|
1312
|
+
dispatchAll() {
|
|
1313
|
+
this.dispatch(this.messages()), this.flush();
|
|
1314
|
+
}
|
|
1315
|
+
dispatch(messages) {
|
|
1316
|
+
messages.length !== 0 && this.observers().forEach((o) => {
|
|
1317
|
+
const msgs = messages.filter((m) => !m.void() && (o.type === void 0 || m instanceof o.type));
|
|
1318
|
+
msgs.length && o.callback(msgs);
|
|
1319
|
+
});
|
|
1320
|
+
}
|
|
1321
|
+
hasObserver() {
|
|
1322
|
+
return this._observers.length > 0;
|
|
1323
|
+
}
|
|
1324
|
+
flush() {
|
|
1325
|
+
this._messageBuffer = [];
|
|
1326
|
+
}
|
|
1327
|
+
send(msg) {
|
|
1328
|
+
this.dispatch([msg]);
|
|
1329
|
+
}
|
|
1330
|
+
post(msg) {
|
|
1331
|
+
this._messageBuffer.push(msg), requestAnimationFrame(() => this.dispatchAll());
|
|
1332
|
+
}
|
|
1333
|
+
attach(callback, type) {
|
|
1334
|
+
const context = this, id = ++this._observerID;
|
|
1335
|
+
return this._observers.push({ id, type, callback }), {
|
|
1336
|
+
release() {
|
|
1337
|
+
context._observers = context._observers.filter((o) => o.id !== id);
|
|
1338
|
+
},
|
|
1339
|
+
unwatch() {
|
|
1340
|
+
this.release();
|
|
1341
|
+
}
|
|
1342
|
+
};
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
class XMLNode {
|
|
1346
|
+
constructor(name) {
|
|
1347
|
+
__publicField(this, "name", "");
|
|
1348
|
+
__publicField(this, "$", {});
|
|
1349
|
+
__publicField(this, "_children", []);
|
|
1350
|
+
__publicField(this, "content", "");
|
|
1351
|
+
this.name = name;
|
|
1352
|
+
}
|
|
1353
|
+
appendAttribute(key, val) {
|
|
1354
|
+
this.$[key] = val;
|
|
1355
|
+
}
|
|
1356
|
+
appendContent(content) {
|
|
1357
|
+
this.content += content;
|
|
1358
|
+
}
|
|
1359
|
+
appendChild(child) {
|
|
1360
|
+
this._children.push(child);
|
|
1361
|
+
}
|
|
1362
|
+
children(tag) {
|
|
1363
|
+
return tag === void 0 ? this._children : this._children.filter((xmlNode) => xmlNode.name === tag);
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
class SAXStackParser {
|
|
1367
|
+
constructor() {
|
|
1368
|
+
__publicField(this, "root");
|
|
1369
|
+
__publicField(this, "stack", new Stack());
|
|
1370
|
+
}
|
|
1371
|
+
walkDoc(node) {
|
|
1372
|
+
const xmlNode = this._startXMLNode(node);
|
|
1373
|
+
if (node.attributes)
|
|
1374
|
+
for (let i = 0; i < node.attributes.length; ++i) {
|
|
1375
|
+
const attribute = node.attributes.item(i);
|
|
1376
|
+
this.attributes(attribute.nodeName, attribute.nodeValue);
|
|
1377
|
+
}
|
|
1378
|
+
if (this.startXMLNode(xmlNode), node.childNodes)
|
|
1379
|
+
for (let i = 0; i < node.childNodes.length; ++i) {
|
|
1380
|
+
const childNode = node.childNodes.item(i);
|
|
1381
|
+
childNode.nodeType === childNode.TEXT_NODE ? this.characters(childNode.nodeValue) : this.walkDoc(childNode);
|
|
1382
|
+
}
|
|
1383
|
+
this.endXMLNode(this.stack.pop());
|
|
1384
|
+
}
|
|
1385
|
+
_startXMLNode(node) {
|
|
1386
|
+
const newNode = new XMLNode(node.nodeName);
|
|
1387
|
+
return this.stack.depth() ? this.stack.top().appendChild(newNode) : this.root = newNode, this.stack.push(newNode);
|
|
1388
|
+
}
|
|
1389
|
+
parse(xml) {
|
|
1390
|
+
const doc = new DOMParser().parseFromString(xml, "application/xml");
|
|
1391
|
+
this.startDocument(), this.walkDoc(doc), this.endDocument();
|
|
1392
|
+
}
|
|
1393
|
+
// Callbacks ---
|
|
1394
|
+
startDocument() {
|
|
1395
|
+
}
|
|
1396
|
+
endDocument() {
|
|
1397
|
+
}
|
|
1398
|
+
startXMLNode(node) {
|
|
1399
|
+
}
|
|
1400
|
+
endXMLNode(node) {
|
|
1401
|
+
}
|
|
1402
|
+
attributes(key, val) {
|
|
1403
|
+
this.stack.top().appendAttribute(key, val);
|
|
1404
|
+
}
|
|
1405
|
+
characters(text) {
|
|
1406
|
+
this.stack.top().appendContent(text);
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
class XML2JSONParser extends SAXStackParser {
|
|
1410
|
+
startXMLNode(node) {
|
|
1411
|
+
switch (super.startXMLNode(node), node.name) {
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
endXMLNode(node) {
|
|
1415
|
+
switch (node.name) {
|
|
1416
|
+
}
|
|
1417
|
+
super.endXMLNode(node);
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
function xml2json(xml) {
|
|
1421
|
+
const saxParser = new XML2JSONParser();
|
|
1422
|
+
return saxParser.parse(xml), saxParser.root;
|
|
1423
|
+
}
|
|
1424
|
+
class PropChangedMessage extends Message {
|
|
1425
|
+
constructor(property, newValue, oldValue) {
|
|
1426
|
+
super(), this.property = property, this.newValue = newValue, this.oldValue = oldValue;
|
|
1427
|
+
}
|
|
1428
|
+
get canConflate() {
|
|
1429
|
+
return !0;
|
|
1430
|
+
}
|
|
1431
|
+
conflate(other) {
|
|
1432
|
+
return this.property === other.property ? (this.newValue = other.newValue, !0) : !1;
|
|
1433
|
+
}
|
|
1434
|
+
void() {
|
|
1435
|
+
return deepEquals(this.newValue, this.oldValue);
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
class StateObject {
|
|
1439
|
+
constructor() {
|
|
1440
|
+
__publicField(this, "_espState", {});
|
|
1441
|
+
__publicField(this, "_dispatch", new Dispatch());
|
|
1442
|
+
__publicField(this, "_monitorHandle");
|
|
1443
|
+
__publicField(this, "_monitorTickCount", 0);
|
|
1444
|
+
}
|
|
1445
|
+
clear(newVals) {
|
|
1446
|
+
this._espState = {}, newVals !== void 0 && this.set(newVals), this._monitorTickCount = 0;
|
|
1447
|
+
}
|
|
1448
|
+
get(key, defValue) {
|
|
1449
|
+
return key === void 0 ? this._espState : this.has(key) ? this._espState[key] : defValue;
|
|
1450
|
+
}
|
|
1451
|
+
set(keyOrNewVals, newVal) {
|
|
1452
|
+
if (typeof keyOrNewVals == "string")
|
|
1453
|
+
return this.setSingle(keyOrNewVals, newVal);
|
|
1454
|
+
this.setAll(keyOrNewVals);
|
|
1455
|
+
}
|
|
1456
|
+
setSingle(key, newVal) {
|
|
1457
|
+
const oldVal = this._espState[key];
|
|
1458
|
+
this._espState[key] = newVal, this._dispatch.post(new PropChangedMessage(key, newVal, oldVal));
|
|
1459
|
+
}
|
|
1460
|
+
setAll(_) {
|
|
1461
|
+
for (const key in _)
|
|
1462
|
+
_.hasOwnProperty(key) && this.setSingle(key, _[key]);
|
|
1463
|
+
}
|
|
1464
|
+
has(key) {
|
|
1465
|
+
return this._espState[key] !== void 0;
|
|
1466
|
+
}
|
|
1467
|
+
addObserver(eventID, propIDOrCallback, callback) {
|
|
1468
|
+
if (this.isCallback(propIDOrCallback)) {
|
|
1469
|
+
if (eventID !== "changed") throw new Error("Invalid eventID: " + eventID);
|
|
1470
|
+
return this._dispatch.attach((messages) => {
|
|
1471
|
+
propIDOrCallback(messages.map((m) => ({
|
|
1472
|
+
id: m.property,
|
|
1473
|
+
oldValue: m.oldValue,
|
|
1474
|
+
newValue: m.newValue
|
|
1475
|
+
})));
|
|
1476
|
+
});
|
|
1477
|
+
} else {
|
|
1478
|
+
if (eventID !== "propChanged") throw new Error("Invalid eventID: " + eventID);
|
|
1479
|
+
return this._dispatch.attach((messages) => {
|
|
1480
|
+
const filteredMessages = messages.filter((m) => m.property === propIDOrCallback);
|
|
1481
|
+
if (filteredMessages.length) {
|
|
1482
|
+
filteredMessages.length > 1 && console.warn("Should only be 1 message?");
|
|
1483
|
+
const event = filteredMessages[filteredMessages.length - 1];
|
|
1484
|
+
callback({
|
|
1485
|
+
id: event.property,
|
|
1486
|
+
oldValue: event.oldValue,
|
|
1487
|
+
newValue: event.newValue
|
|
1488
|
+
});
|
|
1489
|
+
}
|
|
1490
|
+
});
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
on(eventID, propIDOrCallback, callback) {
|
|
1494
|
+
return this.addObserver(eventID, propIDOrCallback, callback), this;
|
|
1495
|
+
}
|
|
1496
|
+
isCallback(propIDOrCallback) {
|
|
1497
|
+
return typeof propIDOrCallback == "function";
|
|
1498
|
+
}
|
|
1499
|
+
hasEventListener() {
|
|
1500
|
+
return this._dispatch.hasObserver();
|
|
1501
|
+
}
|
|
1502
|
+
// Monitoring ---
|
|
1503
|
+
async refresh(full = !1) {
|
|
1504
|
+
return await Promise.resolve(), this;
|
|
1505
|
+
}
|
|
1506
|
+
_monitor() {
|
|
1507
|
+
if (this._monitorHandle) {
|
|
1508
|
+
this._monitorTickCount = 0;
|
|
1509
|
+
return;
|
|
1510
|
+
}
|
|
1511
|
+
this._monitorHandle = setTimeout(() => {
|
|
1512
|
+
(this.hasEventListener() ? this.refresh() : Promise.resolve()).then(() => {
|
|
1513
|
+
this._monitor();
|
|
1514
|
+
}), delete this._monitorHandle;
|
|
1515
|
+
}, this._monitorTimeoutDuration());
|
|
1516
|
+
}
|
|
1517
|
+
_monitorTimeoutDuration() {
|
|
1518
|
+
return ++this._monitorTickCount, this._monitorTickCount <= 1 ? 0 : 3e4;
|
|
1519
|
+
}
|
|
1520
|
+
watch(callback, triggerChange = !0) {
|
|
1521
|
+
if (typeof callback != "function")
|
|
1522
|
+
throw new Error("Invalid Callback");
|
|
1523
|
+
triggerChange && setTimeout(() => {
|
|
1524
|
+
const props = this.get(), changes = [];
|
|
1525
|
+
for (const key in props)
|
|
1526
|
+
props.hasOwnProperty(props) && changes.push({ id: key, newValue: props[key], oldValue: void 0 });
|
|
1527
|
+
callback(changes);
|
|
1528
|
+
}, 0);
|
|
1529
|
+
const retVal = this.addObserver("changed", callback);
|
|
1530
|
+
return this._monitor(), retVal;
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
function trim(str, char) {
|
|
1534
|
+
if (typeof char != "string" || char.length === 0) return str;
|
|
1535
|
+
for (; str.indexOf(char) === 0; )
|
|
1536
|
+
str = str.substring(1);
|
|
1537
|
+
for (; endsWith(str, char); )
|
|
1538
|
+
str = str.substring(0, str.length - 1);
|
|
1539
|
+
return str;
|
|
1540
|
+
}
|
|
1541
|
+
function endsWith(origString, searchString, position) {
|
|
1542
|
+
const subjectString = origString.toString();
|
|
1543
|
+
(typeof position != "number" || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) && (position = subjectString.length), position -= searchString.length;
|
|
1544
|
+
const lastIndex = subjectString.lastIndexOf(searchString, position);
|
|
1545
|
+
return lastIndex !== -1 && lastIndex === position;
|
|
1546
|
+
}
|
|
1547
|
+
function join(...segments) {
|
|
1548
|
+
const parts = segments.reduce((parts2, segment) => (parts2.length > 0 && (segment = segment.replace(/^\//, "")), segment = segment.replace(/\/$/, ""), [...parts2, ...segment.split("/")]), []), resultParts = [];
|
|
1549
|
+
for (const part of parts)
|
|
1550
|
+
if (part !== ".") {
|
|
1551
|
+
if (part === "..") {
|
|
1552
|
+
resultParts.pop();
|
|
1553
|
+
continue;
|
|
1554
|
+
}
|
|
1555
|
+
resultParts.push(part);
|
|
1556
|
+
}
|
|
1557
|
+
return resultParts.join("/");
|
|
1558
|
+
}
|
|
1559
|
+
function dirname(path) {
|
|
1560
|
+
return join(path, "..");
|
|
1561
|
+
}
|
|
1562
|
+
export {
|
|
1563
|
+
AsyncCache,
|
|
1564
|
+
AsyncOrderedQueue,
|
|
1565
|
+
BUILD_VERSION,
|
|
1566
|
+
Cache,
|
|
1567
|
+
Dictionary,
|
|
1568
|
+
DictionaryNoCase,
|
|
1569
|
+
Dispatch,
|
|
1570
|
+
Edge$1 as Edge,
|
|
1571
|
+
Graph,
|
|
1572
|
+
Graph2,
|
|
1573
|
+
GraphItem$1 as GraphItem,
|
|
1574
|
+
Level,
|
|
1575
|
+
Logging,
|
|
1576
|
+
Message,
|
|
1577
|
+
Observable,
|
|
1578
|
+
PKG_NAME,
|
|
1579
|
+
PKG_VERSION,
|
|
1580
|
+
SAXStackParser,
|
|
1581
|
+
ScopedLogging,
|
|
1582
|
+
Stack,
|
|
1583
|
+
StateObject,
|
|
1584
|
+
Subgraph$1 as Subgraph,
|
|
1585
|
+
Vertex$1 as Vertex,
|
|
1586
|
+
XMLNode,
|
|
1587
|
+
cartesianToPolar,
|
|
1588
|
+
classID2Meta,
|
|
1589
|
+
compare,
|
|
1590
|
+
compare2,
|
|
1591
|
+
debounce,
|
|
1592
|
+
deepEquals,
|
|
1593
|
+
deepMixin,
|
|
1594
|
+
deepMixinT,
|
|
1595
|
+
degreesToRadians,
|
|
1596
|
+
dirname,
|
|
1597
|
+
endsWith,
|
|
1598
|
+
espTime2Seconds,
|
|
1599
|
+
exists,
|
|
1600
|
+
find,
|
|
1601
|
+
getScriptSrc,
|
|
1602
|
+
hashSum,
|
|
1603
|
+
inner,
|
|
1604
|
+
isArray,
|
|
1605
|
+
isBrowser,
|
|
1606
|
+
isCI,
|
|
1607
|
+
isNode,
|
|
1608
|
+
join,
|
|
1609
|
+
logger,
|
|
1610
|
+
normalize,
|
|
1611
|
+
normalizeDegrees,
|
|
1612
|
+
normalizeRadians,
|
|
1613
|
+
polarToCartesian,
|
|
1614
|
+
promiseTimeout,
|
|
1615
|
+
radiansToDegrees,
|
|
1616
|
+
root,
|
|
1617
|
+
safeStringify,
|
|
1618
|
+
scopedLogger,
|
|
1619
|
+
sleep,
|
|
1620
|
+
trim,
|
|
1621
|
+
update,
|
|
1622
|
+
verboseDeepEquals,
|
|
1623
|
+
xml2json
|
|
1624
|
+
};
|
|
2
1625
|
//# sourceMappingURL=index.js.map
|