@wandelbots/wandelbots-js-react-components 6.4.0-pr.revamp.667.e1da7d4 → 6.4.0-pr.revamp.667.fa67ce5

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.
Files changed (31) hide show
  1. package/README.md +2 -0
  2. package/dist/3d.cjs +1 -1
  3. package/dist/3d.js +1 -1
  4. package/dist/RobotHeader/index.cjs +1 -1
  5. package/dist/RobotHeader/index.js +1 -1
  6. package/dist/SafetyBar/index.cjs +1 -1
  7. package/dist/SafetyBar/index.js +1 -1
  8. package/dist/chunks/{Robot-BeTWgowU.cjs → Robot-B3vKEVXP.cjs} +1 -1
  9. package/dist/chunks/{Robot-D4XbngYI.js → Robot-DDD382dk.js} +1 -1
  10. package/dist/chunks/{RobotHeader-BZci9ahT.js → RobotHeader-BvIzk8Fw.js} +1 -1
  11. package/dist/chunks/{RobotHeader-CqK0700U.cjs → RobotHeader-Daft80jq.cjs} +1 -1
  12. package/dist/chunks/{SafetyBar-Bbg-o8h9.cjs → SafetyBar-BVk-SH_0.cjs} +1 -1
  13. package/dist/chunks/{SafetyBar-Cuak4ffd.js → SafetyBar-eYzCHOFD.js} +1 -1
  14. package/dist/chunks/TrajectoryExecutionStore-8yxebRg1.cjs +3 -0
  15. package/dist/chunks/{TrajectoryExecutionStore-BNZzZ1Gx.js → TrajectoryExecutionStore-tZgq2ivg.js} +898 -671
  16. package/dist/chunks/converters-BsXgcxCW.cjs +1 -0
  17. package/dist/chunks/{converters-DpNB_WNQ.js → converters-D9KpJ2HD.js} +16 -8
  18. package/dist/core.cjs +1 -1
  19. package/dist/core.d.ts +2 -0
  20. package/dist/core.js +41 -38
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.js +49 -46
  23. package/dist/lib/ControllerStateStream.d.ts +125 -0
  24. package/dist/lib/controllerStateSource.d.ts +37 -0
  25. package/dist/lib/nats/natsControllerStateSource.d.ts +27 -0
  26. package/dist/nats.cjs +1 -0
  27. package/dist/nats.d.ts +4 -0
  28. package/dist/nats.js +131 -0
  29. package/package.json +11 -1
  30. package/dist/chunks/TrajectoryExecutionStore-CYrVePlx.cjs +0 -3
  31. package/dist/chunks/converters-C8I_A_tA.cjs +0 -1
@@ -0,0 +1 @@
1
+ "use strict";const d=require("three");function y(n){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const t in n)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(e,t,o.get?o:{enumerable:!0,get:()=>n[t]})}}return e.default=n,Object.freeze(e)}const r=y(d);function g(n){try{return JSON.parse(n)}catch{return}}function b(n){try{return JSON.stringify(n)}catch{return}}function h(n){const e=n.length(),t=new r.Quaternion;if(e>1e-6){const o=n.clone().normalize();t.setFromAxisAngle(o,e)}return t}function p(n){if(!n||n.length===0)return 5;const o=n.reduce((s,c)=>s+Math.abs(c.a??0)/1e3+Math.abs(c.d??0)/1e3,0)*2;return!Number.isFinite(o)||o<=0?5:o}function z(n){if(n.length<3)return console.log("Not enough vertices to define a plane"),{isCoplanar:!1};const e=new r.Vector3(n[0].x,n[0].y,n[0].z),t=new r.Vector3(n[1].x,n[1].y,n[1].z),o=new r.Vector3(n[2].x,n[2].y,n[2].z),s=new r.Vector3().subVectors(t,e),c=new r.Vector3().subVectors(o,e),i=new r.Vector3().crossVectors(s,c).normalize();for(let a=3;a<n.length;a++){const u=new r.Vector3(n[a].x,n[a].y,n[a].z),l=new r.Vector3().subVectors(u,e),f=i.dot(l);if(Math.abs(f)>1e-6)return console.log("Vertices are not on the same plane"),{isCoplanar:!1}}return{isCoplanar:!0,normal:i}}exports.dhParametersToPlaneSize=p;exports.orientationToQuaternion=h;exports.tryParseJson=g;exports.tryStringifyJson=b;exports.verticesToCoplanarity=z;
@@ -1,4 +1,11 @@
1
1
  import * as o from "three";
2
+ function d(n) {
3
+ try {
4
+ return JSON.parse(n);
5
+ } catch {
6
+ return;
7
+ }
8
+ }
2
9
  function V(n) {
3
10
  try {
4
11
  return JSON.stringify(n);
@@ -6,7 +13,7 @@ function V(n) {
6
13
  return;
7
14
  }
8
15
  }
9
- function d(n) {
16
+ function h(n) {
10
17
  const t = n.length(), r = new o.Quaternion();
11
18
  if (t > 1e-6) {
12
19
  const e = n.clone().normalize();
@@ -20,20 +27,21 @@ function g(n) {
20
27
  const e = n.reduce((c, s) => c + Math.abs(s.a ?? 0) / 1e3 + Math.abs(s.d ?? 0) / 1e3, 0) * 2;
21
28
  return !Number.isFinite(e) || e <= 0 ? 5 : e;
22
29
  }
23
- function h(n) {
30
+ function y(n) {
24
31
  if (n.length < 3)
25
32
  return console.log("Not enough vertices to define a plane"), { isCoplanar: !1 };
26
- const t = new o.Vector3(n[0].x, n[0].y, n[0].z), r = new o.Vector3(n[1].x, n[1].y, n[1].z), e = new o.Vector3(n[2].x, n[2].y, n[2].z), c = new o.Vector3().subVectors(r, t), s = new o.Vector3().subVectors(e, t), l = new o.Vector3().crossVectors(c, s).normalize();
33
+ const t = new o.Vector3(n[0].x, n[0].y, n[0].z), r = new o.Vector3(n[1].x, n[1].y, n[1].z), e = new o.Vector3(n[2].x, n[2].y, n[2].z), c = new o.Vector3().subVectors(r, t), s = new o.Vector3().subVectors(e, t), u = new o.Vector3().crossVectors(c, s).normalize();
27
34
  for (let a = 3; a < n.length; a++) {
28
- const u = new o.Vector3(n[a].x, n[a].y, n[a].z), i = new o.Vector3().subVectors(u, t), f = l.dot(i);
35
+ const i = new o.Vector3(n[a].x, n[a].y, n[a].z), l = new o.Vector3().subVectors(i, t), f = u.dot(l);
29
36
  if (Math.abs(f) > 1e-6)
30
37
  return console.log("Vertices are not on the same plane"), { isCoplanar: !1 };
31
38
  }
32
- return { isCoplanar: !0, normal: l };
39
+ return { isCoplanar: !0, normal: u };
33
40
  }
34
41
  export {
42
+ V as a,
35
43
  g as d,
36
- d as o,
37
- V as t,
38
- h as v
44
+ h as o,
45
+ d as t,
46
+ y as v
39
47
  };
package/dist/core.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("@wandelbots/mui");const o=require("./chunks/TrajectoryExecutionStore-CYrVePlx.cjs"),t=require("./chunks/CurrentPoseBar-CyHUWmjM.cjs"),r=require("./chunks/JoggingButtons-CbL-5LMK.cjs"),n=require("./chunks/JoggingJointSlider-R3_A9Ppj.cjs"),i=require("./chunks/RobotHeader-CqK0700U.cjs"),e=require("./chunks/Pose3-DIyg-aZA.cjs"),a=require("./chunks/externalizeComponent-BdxGBLIv.cjs"),g=require("./chunks/SafetyBar-Bbg-o8h9.cjs");exports.AppHeader=o.AppHeader;exports.ConnectedMotionGroup=o.ConnectedMotionGroup;exports.JoggerConnection=o.JoggerConnection;exports.JoggingCartesianAxisControl=o.JoggingCartesianAxisControl;exports.JoggingJointValueControl=o.JoggingJointValueControl;exports.JoggingPanel=o.JoggingPanel;exports.JoggingStore=o.JoggingStore;exports.LoadingCover=o.LoadingCover;exports.LoadingErrorMessage=o.LoadingErrorMessage;exports.MotionStreamConnection=o.MotionStreamConnection;exports.NoMotionGroupModal=o.NoMotionGroupModal;exports.TrajectoryExecutionStore=o.TrajectoryExecutionStore;exports.VelocitySlider=o.VelocitySlider;exports.VelocitySliderLabel=o.VelocitySliderLabel;exports.deriveSelectedTcpPose=o.deriveSelectedTcpPose;exports.jointValuesEqual=o.jointValuesEqual;exports.jointValuesUnchanged=o.jointValuesUnchanged;exports.planErrorTranslationKey=o.planErrorTranslationKey;exports.poseEqual=o.poseEqual;exports.readoutOf=o.readoutOf;exports.readoutsEqual=o.readoutsEqual;exports.resolveCoordinateSystemInWorld=o.resolveCoordinateSystemInWorld;exports.tcpMotionEqual=o.tcpMotionEqual;exports.transformPoseToCoordinateSystem=o.transformPoseToCoordinateSystem;exports.unwrapRotationVector=o.unwrapRotationVector;exports.CurrentPoseBar=t.CurrentPoseBar;exports.JoggingButtons=r.JoggingButtons;exports.JoggingJointSlider=n.JoggingJointSlider;exports.RobotHeader=i.RobotHeader;exports.ValueInterpolator=e.ValueInterpolator;exports.useInterpolation=e.useInterpolation;exports.useSmoothedMotionState=e.useSmoothedMotionState;exports.i18n=a.i18n;exports.SafetyBar=g.SafetyBar;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("@wandelbots/mui");const o=require("./chunks/TrajectoryExecutionStore-8yxebRg1.cjs"),t=require("./chunks/CurrentPoseBar-CyHUWmjM.cjs"),r=require("./chunks/JoggingButtons-CbL-5LMK.cjs"),n=require("./chunks/JoggingJointSlider-R3_A9Ppj.cjs"),a=require("./chunks/RobotHeader-Daft80jq.cjs"),e=require("./chunks/Pose3-DIyg-aZA.cjs"),i=require("./chunks/externalizeComponent-BdxGBLIv.cjs"),l=require("./chunks/SafetyBar-BVk-SH_0.cjs");exports.AppHeader=o.AppHeader;exports.ConnectedMotionGroup=o.ConnectedMotionGroup;exports.ControllerStateStream=o.ControllerStateStream;exports.JoggerConnection=o.JoggerConnection;exports.JoggingCartesianAxisControl=o.JoggingCartesianAxisControl;exports.JoggingJointValueControl=o.JoggingJointValueControl;exports.JoggingPanel=o.JoggingPanel;exports.JoggingStore=o.JoggingStore;exports.LoadingCover=o.LoadingCover;exports.LoadingErrorMessage=o.LoadingErrorMessage;exports.MOTION_DELTA_THRESHOLD=o.MOTION_DELTA_THRESHOLD;exports.MotionStreamConnection=o.MotionStreamConnection;exports.NoMotionGroupModal=o.NoMotionGroupModal;exports.TrajectoryExecutionStore=o.TrajectoryExecutionStore;exports.VelocitySlider=o.VelocitySlider;exports.VelocitySliderLabel=o.VelocitySliderLabel;exports.controllerStateWebsocket=o.controllerStateWebsocket;exports.deriveSelectedTcpPose=o.deriveSelectedTcpPose;exports.jointValuesEqual=o.jointValuesEqual;exports.jointValuesUnchanged=o.jointValuesUnchanged;exports.planErrorTranslationKey=o.planErrorTranslationKey;exports.poseEqual=o.poseEqual;exports.readoutOf=o.readoutOf;exports.readoutsEqual=o.readoutsEqual;exports.resolveCoordinateSystemInWorld=o.resolveCoordinateSystemInWorld;exports.tcpMotionEqual=o.tcpMotionEqual;exports.transformPoseToCoordinateSystem=o.transformPoseToCoordinateSystem;exports.unwrapRotationVector=o.unwrapRotationVector;exports.CurrentPoseBar=t.CurrentPoseBar;exports.JoggingButtons=r.JoggingButtons;exports.JoggingJointSlider=n.JoggingJointSlider;exports.RobotHeader=a.RobotHeader;exports.ValueInterpolator=e.ValueInterpolator;exports.useInterpolation=e.useInterpolation;exports.useSmoothedMotionState=e.useSmoothedMotionState;exports.i18n=i.i18n;exports.SafetyBar=l.SafetyBar;
package/dist/core.d.ts CHANGED
@@ -19,6 +19,8 @@ export * from "./components/utils/useSmoothedMotionState";
19
19
  export * from "./components/VelocitySlider";
20
20
  export * from "./i18n/config";
21
21
  export * from "./lib/ConnectedMotionGroup";
22
+ export { ControllerStateStream, type ControllerStateStreamError, type ControllerStateStreamOptions, MOTION_DELTA_THRESHOLD, } from "./lib/ControllerStateStream";
23
+ export { type ControllerStateSource, controllerStateWebsocket, } from "./lib/controllerStateSource";
22
24
  export type { ConnectionLogger } from "./lib/connectionLogger";
23
25
  export * from "./lib/JoggerConnection";
24
26
  export * from "./lib/motionStateUpdate";
package/dist/core.js CHANGED
@@ -1,45 +1,48 @@
1
1
  import "@wandelbots/mui";
2
- import { A as r, C as t, J as s, a as n, b as i, c as l, d as g, L as p, e as u, M as d, N as m, T as c, V as S, f, g as C, j as J, h as x, p as V, i as M, r as y, k as E, l as T, t as j, m as q, u as L } from "./chunks/TrajectoryExecutionStore-BNZzZ1Gx.js";
3
- import { C as b } from "./chunks/CurrentPoseBar-zTZi68tY.js";
4
- import { J as v } from "./chunks/JoggingButtons-CXaozFVz.js";
5
- import { J as B } from "./chunks/JoggingJointSlider-CZ-k6XCa.js";
6
- import { R } from "./chunks/RobotHeader-BZci9ahT.js";
7
- import { V as H, u as N, a as k } from "./chunks/Pose3-pocKPrHN.js";
8
- import { i as K } from "./chunks/externalizeComponent-_w2d1_pz.js";
9
- import { S as U } from "./chunks/SafetyBar-Cuak4ffd.js";
2
+ import { A as r, C as t, a as s, J as n, b as i, c as l, d as g, e as p, L as u, f as d, M as S, g as m, N as c, T as C, V as f, h as J, i as x, j as E, k as M, l as V, p as T, m as y, r as L, n as q, o as b, t as j, q as A, u as H } from "./chunks/TrajectoryExecutionStore-tZgq2ivg.js";
3
+ import { C as O } from "./chunks/CurrentPoseBar-zTZi68tY.js";
4
+ import { J as R } from "./chunks/JoggingButtons-CXaozFVz.js";
5
+ import { J as v } from "./chunks/JoggingJointSlider-CZ-k6XCa.js";
6
+ import { R as N } from "./chunks/RobotHeader-BvIzk8Fw.js";
7
+ import { V as D, u as G, a as W } from "./chunks/Pose3-pocKPrHN.js";
8
+ import { i as w } from "./chunks/externalizeComponent-_w2d1_pz.js";
9
+ import { S as U } from "./chunks/SafetyBar-eYzCHOFD.js";
10
10
  export {
11
11
  r as AppHeader,
12
12
  t as ConnectedMotionGroup,
13
- b as CurrentPoseBar,
14
- s as JoggerConnection,
15
- v as JoggingButtons,
16
- n as JoggingCartesianAxisControl,
17
- B as JoggingJointSlider,
18
- i as JoggingJointValueControl,
19
- l as JoggingPanel,
20
- g as JoggingStore,
21
- p as LoadingCover,
22
- u as LoadingErrorMessage,
23
- d as MotionStreamConnection,
24
- m as NoMotionGroupModal,
25
- R as RobotHeader,
13
+ s as ControllerStateStream,
14
+ O as CurrentPoseBar,
15
+ n as JoggerConnection,
16
+ R as JoggingButtons,
17
+ i as JoggingCartesianAxisControl,
18
+ v as JoggingJointSlider,
19
+ l as JoggingJointValueControl,
20
+ g as JoggingPanel,
21
+ p as JoggingStore,
22
+ u as LoadingCover,
23
+ d as LoadingErrorMessage,
24
+ S as MOTION_DELTA_THRESHOLD,
25
+ m as MotionStreamConnection,
26
+ c as NoMotionGroupModal,
27
+ N as RobotHeader,
26
28
  U as SafetyBar,
27
- c as TrajectoryExecutionStore,
28
- H as ValueInterpolator,
29
- S as VelocitySlider,
30
- f as VelocitySliderLabel,
31
- C as deriveSelectedTcpPose,
32
- K as i18n,
33
- J as jointValuesEqual,
34
- x as jointValuesUnchanged,
35
- V as planErrorTranslationKey,
36
- M as poseEqual,
37
- y as readoutOf,
38
- E as readoutsEqual,
39
- T as resolveCoordinateSystemInWorld,
29
+ C as TrajectoryExecutionStore,
30
+ D as ValueInterpolator,
31
+ f as VelocitySlider,
32
+ J as VelocitySliderLabel,
33
+ x as controllerStateWebsocket,
34
+ E as deriveSelectedTcpPose,
35
+ w as i18n,
36
+ M as jointValuesEqual,
37
+ V as jointValuesUnchanged,
38
+ T as planErrorTranslationKey,
39
+ y as poseEqual,
40
+ L as readoutOf,
41
+ q as readoutsEqual,
42
+ b as resolveCoordinateSystemInWorld,
40
43
  j as tcpMotionEqual,
41
- q as transformPoseToCoordinateSystem,
42
- L as unwrapRotationVector,
43
- N as useInterpolation,
44
- k as useSmoothedMotionState
44
+ A as transformPoseToCoordinateSystem,
45
+ H as unwrapRotationVector,
46
+ G as useInterpolation,
47
+ W as useSmoothedMotionState
45
48
  };
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./chunks/Robot-BeTWgowU.cjs"),r=require("./chunks/JoggingGizmo-DGbFLWgT.cjs"),n=require("./chunks/JoggingGizmoOrientation-dzned4f4.cjs"),i=require("./chunks/RobotControlPanel-BXtBHEe9.cjs"),t=require("./chunks/Pose3-DIyg-aZA.cjs");require("@wandelbots/mui");const o=require("./chunks/TrajectoryExecutionStore-CYrVePlx.cjs"),a=require("./chunks/CurrentPoseBar-CyHUWmjM.cjs"),u=require("./chunks/JoggingButtons-CbL-5LMK.cjs"),s=require("./chunks/JoggingJointSlider-R3_A9Ppj.cjs"),g=require("./chunks/RobotHeader-CqK0700U.cjs"),l=require("./chunks/externalizeComponent-BdxGBLIv.cjs"),d=require("./chunks/SafetyBar-Bbg-o8h9.cjs");exports.CollisionSceneRenderer=e.CollisionSceneRenderer;exports.JointLimitGizmo=e.JointLimitGizmo;exports.LinearAxis=e.LinearAxis;exports.MotionGroupVisualizer=e.MotionGroupVisualizer;exports.MotionGroupVisualizerExact=e.MotionGroupVisualizerExact;exports.PresetEnvironment=e.PresetEnvironment;exports.Robot=e.Robot;exports.SafetyZonesRenderer=e.SafetyZonesRenderer;exports.SupportedLinearAxis=e.SupportedLinearAxis;exports.SupportedLinearAxisExact=e.SupportedLinearAxisExact;exports.SupportedRobot=e.SupportedRobot;exports.SupportedRobotExact=e.SupportedRobotExact;exports.TrajectoryRenderer=e.TrajectoryRenderer;exports.defaultGetModel=e.defaultGetModel;exports.JoggingGizmo=r.JoggingGizmo;exports.JoggingGizmoOrientation=n.JoggingGizmoOrientation;exports.RobotControlPanel=i.RobotControlPanel;exports.Pose3=t.Pose3;exports.ValueInterpolator=t.ValueInterpolator;exports.parseRotationToQuaternion=t.parseRotationToQuaternion;exports.quaternionToRotationVector=t.quaternionToRotationVector;exports.useInterpolation=t.useInterpolation;exports.useSmoothedMotionState=t.useSmoothedMotionState;exports.AppHeader=o.AppHeader;exports.ConnectedMotionGroup=o.ConnectedMotionGroup;exports.JoggerConnection=o.JoggerConnection;exports.JoggingCartesianAxisControl=o.JoggingCartesianAxisControl;exports.JoggingJointValueControl=o.JoggingJointValueControl;exports.JoggingPanel=o.JoggingPanel;exports.JoggingStore=o.JoggingStore;exports.LoadingCover=o.LoadingCover;exports.LoadingErrorMessage=o.LoadingErrorMessage;exports.MotionStreamConnection=o.MotionStreamConnection;exports.NoMotionGroupModal=o.NoMotionGroupModal;exports.TrajectoryExecutionStore=o.TrajectoryExecutionStore;exports.VelocitySlider=o.VelocitySlider;exports.VelocitySliderLabel=o.VelocitySliderLabel;exports.deriveSelectedTcpPose=o.deriveSelectedTcpPose;exports.jointValuesEqual=o.jointValuesEqual;exports.jointValuesUnchanged=o.jointValuesUnchanged;exports.planErrorTranslationKey=o.planErrorTranslationKey;exports.poseEqual=o.poseEqual;exports.readoutOf=o.readoutOf;exports.readoutsEqual=o.readoutsEqual;exports.resolveCoordinateSystemInWorld=o.resolveCoordinateSystemInWorld;exports.tcpMotionEqual=o.tcpMotionEqual;exports.transformPoseToCoordinateSystem=o.transformPoseToCoordinateSystem;exports.unwrapRotationVector=o.unwrapRotationVector;exports.CurrentPoseBar=a.CurrentPoseBar;exports.JoggingButtons=u.JoggingButtons;exports.JoggingJointSlider=s.JoggingJointSlider;exports.RobotHeader=g.RobotHeader;exports.i18n=l.i18n;exports.SafetyBar=d.SafetyBar;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./chunks/Robot-B3vKEVXP.cjs"),r=require("./chunks/JoggingGizmo-DGbFLWgT.cjs"),n=require("./chunks/JoggingGizmoOrientation-dzned4f4.cjs"),i=require("./chunks/RobotControlPanel-BXtBHEe9.cjs"),t=require("./chunks/Pose3-DIyg-aZA.cjs");require("@wandelbots/mui");const o=require("./chunks/TrajectoryExecutionStore-8yxebRg1.cjs"),a=require("./chunks/CurrentPoseBar-CyHUWmjM.cjs"),l=require("./chunks/JoggingButtons-CbL-5LMK.cjs"),s=require("./chunks/JoggingJointSlider-R3_A9Ppj.cjs"),u=require("./chunks/RobotHeader-Daft80jq.cjs"),g=require("./chunks/externalizeComponent-BdxGBLIv.cjs"),d=require("./chunks/SafetyBar-BVk-SH_0.cjs");exports.CollisionSceneRenderer=e.CollisionSceneRenderer;exports.JointLimitGizmo=e.JointLimitGizmo;exports.LinearAxis=e.LinearAxis;exports.MotionGroupVisualizer=e.MotionGroupVisualizer;exports.MotionGroupVisualizerExact=e.MotionGroupVisualizerExact;exports.PresetEnvironment=e.PresetEnvironment;exports.Robot=e.Robot;exports.SafetyZonesRenderer=e.SafetyZonesRenderer;exports.SupportedLinearAxis=e.SupportedLinearAxis;exports.SupportedLinearAxisExact=e.SupportedLinearAxisExact;exports.SupportedRobot=e.SupportedRobot;exports.SupportedRobotExact=e.SupportedRobotExact;exports.TrajectoryRenderer=e.TrajectoryRenderer;exports.defaultGetModel=e.defaultGetModel;exports.JoggingGizmo=r.JoggingGizmo;exports.JoggingGizmoOrientation=n.JoggingGizmoOrientation;exports.RobotControlPanel=i.RobotControlPanel;exports.Pose3=t.Pose3;exports.ValueInterpolator=t.ValueInterpolator;exports.parseRotationToQuaternion=t.parseRotationToQuaternion;exports.quaternionToRotationVector=t.quaternionToRotationVector;exports.useInterpolation=t.useInterpolation;exports.useSmoothedMotionState=t.useSmoothedMotionState;exports.AppHeader=o.AppHeader;exports.ConnectedMotionGroup=o.ConnectedMotionGroup;exports.ControllerStateStream=o.ControllerStateStream;exports.JoggerConnection=o.JoggerConnection;exports.JoggingCartesianAxisControl=o.JoggingCartesianAxisControl;exports.JoggingJointValueControl=o.JoggingJointValueControl;exports.JoggingPanel=o.JoggingPanel;exports.JoggingStore=o.JoggingStore;exports.LoadingCover=o.LoadingCover;exports.LoadingErrorMessage=o.LoadingErrorMessage;exports.MOTION_DELTA_THRESHOLD=o.MOTION_DELTA_THRESHOLD;exports.MotionStreamConnection=o.MotionStreamConnection;exports.NoMotionGroupModal=o.NoMotionGroupModal;exports.TrajectoryExecutionStore=o.TrajectoryExecutionStore;exports.VelocitySlider=o.VelocitySlider;exports.VelocitySliderLabel=o.VelocitySliderLabel;exports.controllerStateWebsocket=o.controllerStateWebsocket;exports.deriveSelectedTcpPose=o.deriveSelectedTcpPose;exports.jointValuesEqual=o.jointValuesEqual;exports.jointValuesUnchanged=o.jointValuesUnchanged;exports.planErrorTranslationKey=o.planErrorTranslationKey;exports.poseEqual=o.poseEqual;exports.readoutOf=o.readoutOf;exports.readoutsEqual=o.readoutsEqual;exports.resolveCoordinateSystemInWorld=o.resolveCoordinateSystemInWorld;exports.tcpMotionEqual=o.tcpMotionEqual;exports.transformPoseToCoordinateSystem=o.transformPoseToCoordinateSystem;exports.unwrapRotationVector=o.unwrapRotationVector;exports.CurrentPoseBar=a.CurrentPoseBar;exports.JoggingButtons=l.JoggingButtons;exports.JoggingJointSlider=s.JoggingJointSlider;exports.RobotHeader=u.RobotHeader;exports.i18n=g.i18n;exports.SafetyBar=d.SafetyBar;
package/dist/index.js CHANGED
@@ -1,69 +1,72 @@
1
- import { C as r, J as t, L as s, M as n, a as i, P as p, R as l, S as g, b as u, c as d, d as m, e as c, T as x, f as S } from "./chunks/Robot-D4XbngYI.js";
1
+ import { C as r, J as t, L as s, M as n, a as i, P as l, R as p, S as g, b as u, c as d, d as m, e as S, T as c, f as x } from "./chunks/Robot-DDD382dk.js";
2
2
  import { J } from "./chunks/JoggingGizmo-SuS9MmL7.js";
3
3
  import { J as R } from "./chunks/JoggingGizmoOrientation-x_crT_64.js";
4
- import { R as V } from "./chunks/RobotControlPanel-BiLexAWI.js";
5
- import { P as y, V as L, p as P, q as T, u as b, a as G } from "./chunks/Pose3-pocKPrHN.js";
4
+ import { R as M } from "./chunks/RobotControlPanel-BiLexAWI.js";
5
+ import { P as V, V as L, p as b, q as y, u as P, a as G } from "./chunks/Pose3-pocKPrHN.js";
6
6
  import "@wandelbots/mui";
7
- import { A, C as j, J as z, a as v, b as h, c as B, d as I, L as H, e as N, M as O, N as k, T as w, V as K, f as Q, g as U, j as W, h as Z, p as D, i as F, r as X, k as Y, l as _, t as $, m as oo, u as ao } from "./chunks/TrajectoryExecutionStore-BNZzZ1Gx.js";
8
- import { C as ro } from "./chunks/CurrentPoseBar-zTZi68tY.js";
9
- import { J as so } from "./chunks/JoggingButtons-CXaozFVz.js";
10
- import { J as io } from "./chunks/JoggingJointSlider-CZ-k6XCa.js";
11
- import { R as lo } from "./chunks/RobotHeader-BZci9ahT.js";
12
- import { i as uo } from "./chunks/externalizeComponent-_w2d1_pz.js";
13
- import { S as co } from "./chunks/SafetyBar-Cuak4ffd.js";
7
+ import { A, C as j, a as z, J as O, b as v, c as H, d as I, e as h, L as B, f as N, M as k, g as D, N as W, T as _, V as w, h as K, i as Q, j as U, k as Z, l as F, p as X, m as Y, r as $, n as oo, o as ao, t as eo, q as ro, u as to } from "./chunks/TrajectoryExecutionStore-tZgq2ivg.js";
8
+ import { C as no } from "./chunks/CurrentPoseBar-zTZi68tY.js";
9
+ import { J as lo } from "./chunks/JoggingButtons-CXaozFVz.js";
10
+ import { J as go } from "./chunks/JoggingJointSlider-CZ-k6XCa.js";
11
+ import { R as mo } from "./chunks/RobotHeader-BvIzk8Fw.js";
12
+ import { i as co } from "./chunks/externalizeComponent-_w2d1_pz.js";
13
+ import { S as fo } from "./chunks/SafetyBar-eYzCHOFD.js";
14
14
  export {
15
15
  A as AppHeader,
16
16
  r as CollisionSceneRenderer,
17
17
  j as ConnectedMotionGroup,
18
- ro as CurrentPoseBar,
19
- z as JoggerConnection,
20
- so as JoggingButtons,
18
+ z as ControllerStateStream,
19
+ no as CurrentPoseBar,
20
+ O as JoggerConnection,
21
+ lo as JoggingButtons,
21
22
  v as JoggingCartesianAxisControl,
22
23
  J as JoggingGizmo,
23
24
  R as JoggingGizmoOrientation,
24
- io as JoggingJointSlider,
25
- h as JoggingJointValueControl,
26
- B as JoggingPanel,
27
- I as JoggingStore,
25
+ go as JoggingJointSlider,
26
+ H as JoggingJointValueControl,
27
+ I as JoggingPanel,
28
+ h as JoggingStore,
28
29
  t as JointLimitGizmo,
29
30
  s as LinearAxis,
30
- H as LoadingCover,
31
+ B as LoadingCover,
31
32
  N as LoadingErrorMessage,
33
+ k as MOTION_DELTA_THRESHOLD,
32
34
  n as MotionGroupVisualizer,
33
35
  i as MotionGroupVisualizerExact,
34
- O as MotionStreamConnection,
35
- k as NoMotionGroupModal,
36
- y as Pose3,
37
- p as PresetEnvironment,
38
- l as Robot,
39
- V as RobotControlPanel,
40
- lo as RobotHeader,
41
- co as SafetyBar,
36
+ D as MotionStreamConnection,
37
+ W as NoMotionGroupModal,
38
+ V as Pose3,
39
+ l as PresetEnvironment,
40
+ p as Robot,
41
+ M as RobotControlPanel,
42
+ mo as RobotHeader,
43
+ fo as SafetyBar,
42
44
  g as SafetyZonesRenderer,
43
45
  u as SupportedLinearAxis,
44
46
  d as SupportedLinearAxisExact,
45
47
  m as SupportedRobot,
46
- c as SupportedRobotExact,
47
- w as TrajectoryExecutionStore,
48
- x as TrajectoryRenderer,
48
+ S as SupportedRobotExact,
49
+ _ as TrajectoryExecutionStore,
50
+ c as TrajectoryRenderer,
49
51
  L as ValueInterpolator,
50
- K as VelocitySlider,
51
- Q as VelocitySliderLabel,
52
- S as defaultGetModel,
52
+ w as VelocitySlider,
53
+ K as VelocitySliderLabel,
54
+ Q as controllerStateWebsocket,
55
+ x as defaultGetModel,
53
56
  U as deriveSelectedTcpPose,
54
- uo as i18n,
55
- W as jointValuesEqual,
56
- Z as jointValuesUnchanged,
57
- P as parseRotationToQuaternion,
58
- D as planErrorTranslationKey,
59
- F as poseEqual,
60
- T as quaternionToRotationVector,
61
- X as readoutOf,
62
- Y as readoutsEqual,
63
- _ as resolveCoordinateSystemInWorld,
64
- $ as tcpMotionEqual,
65
- oo as transformPoseToCoordinateSystem,
66
- ao as unwrapRotationVector,
67
- b as useInterpolation,
57
+ co as i18n,
58
+ Z as jointValuesEqual,
59
+ F as jointValuesUnchanged,
60
+ b as parseRotationToQuaternion,
61
+ X as planErrorTranslationKey,
62
+ Y as poseEqual,
63
+ y as quaternionToRotationVector,
64
+ $ as readoutOf,
65
+ oo as readoutsEqual,
66
+ ao as resolveCoordinateSystemInWorld,
67
+ eo as tcpMotionEqual,
68
+ ro as transformPoseToCoordinateSystem,
69
+ to as unwrapRotationVector,
70
+ P as useInterpolation,
68
71
  G as useSmoothedMotionState
69
72
  };
@@ -0,0 +1,125 @@
1
+ import type { MotionGroupState, RobotControllerState } from "@wandelbots/nova-js/v2";
2
+ import type { ControllerStateSource } from "./controllerStateSource";
3
+ import { type MotionStateReadout } from "./motionStateUpdate";
4
+ /** Joints that moved less than this (rad, or mm) count as standing still */
5
+ export declare const MOTION_DELTA_THRESHOLD = 0.0001;
6
+ /** A message from the source that the stream could not use */
7
+ export type ControllerStateStreamError = {
8
+ message: string;
9
+ /** The source's URL */
10
+ url?: string;
11
+ };
12
+ /** What an app can give a {@link ControllerStateStream} besides its source */
13
+ export type ControllerStateStreamOptions = {
14
+ /**
15
+ * A virtual robot: its stream can come more slowly, depending on the speed
16
+ * of the simulation, so the stream waits longer before it calls the
17
+ * connection struggling (3 s instead of 1 s) or critical (6 s instead of 3 s)
18
+ */
19
+ isVirtual?: boolean;
20
+ /** Reports a message that the stream could not use */
21
+ onError?: (error: ControllerStateStreamError) => void;
22
+ /**
23
+ * Reconnect the source when the window gets the focus back, e.g. after the
24
+ * computer slept. Defaults to true where there is a window.
25
+ */
26
+ reconnectOnFocus?: boolean;
27
+ };
28
+ /**
29
+ * The live state of one motion group and its controller, from a
30
+ * {@link ControllerStateSource}: the safety state, operation mode and mode of
31
+ * the controller, and the motion group's state, updated in place as the
32
+ * messages come. Tells how good the connection is, and reconnects the source
33
+ * when its messages stop.
34
+ */
35
+ export declare class ControllerStateStream {
36
+ /** Where the controller state comes from; its owner closes it */
37
+ readonly source: ControllerStateSource;
38
+ /** The motion group whose state the stream keeps */
39
+ readonly motionGroupId: string;
40
+ /**
41
+ * The motion group's state as the last message had it. It stays the same
42
+ * object for as long as the stream lives, updated field by field, so that
43
+ * observers of one of its fields keep working. While the robot stands
44
+ * still, the jittering pose readings are not written.
45
+ */
46
+ rapidlyChangingMotionState: MotionGroupState;
47
+ /**
48
+ * The last message that changed the controller's safety state, operation
49
+ * mode or mode, and when it came
50
+ */
51
+ lastValidStateMessage: {
52
+ receivedAt: number;
53
+ data: RobotControllerState;
54
+ };
55
+ /** Non-observable timestamp for connection quality tracking only */
56
+ private lastMessageReceivedAt;
57
+ /** The last message that held no state of the motion group, if any */
58
+ lastInvalidStateMessage: {
59
+ receivedAt: number;
60
+ data: unknown;
61
+ } | null;
62
+ /**
63
+ * How the messages come: "struggling" after 1 s without one (3 s for a
64
+ * virtual robot), "critical" after 3 s (6 s), when the source is reconnected
65
+ */
66
+ connectionQuality: "good" | "struggling" | "critical";
67
+ private readonly connectionQualityInterval;
68
+ private readonly isVirtual;
69
+ private readonly onError?;
70
+ private readonly reconnectsOnFocus;
71
+ constructor(
72
+ /** Where the controller state comes from; its owner closes it */
73
+ source: ControllerStateSource,
74
+ /** The motion group whose state the stream keeps */
75
+ motionGroupId: string, initialControllerState: RobotControllerState, options?: ControllerStateStreamOptions);
76
+ /** The controller's state as of the last message that changed it */
77
+ get controllerState(): RobotControllerState;
78
+ /**
79
+ * What pose and joint readouts show. Holds the previous reading while the
80
+ * joints only jitter, see {@link readoutsEqual}; kept alive so it also holds
81
+ * for untracked reads.
82
+ */
83
+ get readoutState(): MotionStateReadout;
84
+ /** The motion group's state in the next message of the source */
85
+ nextMotionState(): Promise<MotionGroupState>;
86
+ private setLastInvalidStateMessage;
87
+ private setLastValidStateMessage;
88
+ /**
89
+ * Merge the latest motion state onto the existing object instead of replacing
90
+ * it, so this stream owns exactly one live motion state object for the whole
91
+ * time it is connected.
92
+ *
93
+ * Consumers subscribe to *properties* of the object they are holding — the 3D
94
+ * animators keep it in a ref and read `joint_position` inside a MobX
95
+ * reaction. Replacing the object leaves those reactions subscribed to an
96
+ * orphan that never changes again, so the robot model stopped getting joint
97
+ * targets from the stream and only moved when React happened to re-render it
98
+ * (~5 updates/s against a ~134/s stream).
99
+ *
100
+ * Only fields whose value actually changed are written. A blanket
101
+ * `Object.assign` puts a fresh object into every nested field, and MobX
102
+ * compares with `===`, so each of `flange_pose`, `tcp_pose` and
103
+ * `joint_limit_reached` would notify its observers on every message of a
104
+ * ~134/s stream even while standing still. This mirrors how
105
+ * MotionStreamConnection guards each of its own field writes.
106
+ *
107
+ * Fields the message does not carry are removed rather than left behind: a
108
+ * merge must not make a stale pose read as the current one, which replacing
109
+ * the whole object never did.
110
+ *
111
+ * Runs as a MobX action (see `makeAutoObservable` with `autoBind` above), so
112
+ * the per-field writes notify observers once, as a single batch.
113
+ *
114
+ * `skipFields` leaves the named fields exactly as they are — neither updated
115
+ * nor removed — which is how a standstill message updates the discrete state
116
+ * without churning the jittery pose readings.
117
+ */
118
+ private updateRapidlyChangingMotionState;
119
+ private setConnectionQuality;
120
+ private handleWindowFocus;
121
+ private updateConnectionQuality;
122
+ /** Stops listening to the source; the source's owner closes it */
123
+ dispose(): void;
124
+ private handleMessage;
125
+ }
@@ -0,0 +1,37 @@
1
+ import type { RobotControllerState } from "@wandelbots/nova-js/v2";
2
+ import { type NovaConnection } from "./novaConnection";
3
+ /**
4
+ * Where a robot's live controller state comes from: NOVA's websocket
5
+ * (`controllerStateWebsocket` of `/core`), NATS (`natsControllerStateSource`
6
+ * of `/nats`), or a source of the app's own. It works like a WebSocket that
7
+ * reconnects itself: a `ControllerStateStream` listens to its messages and
8
+ * asks it to reconnect when they stop coming.
9
+ */
10
+ export type ControllerStateSource = {
11
+ /** Where it connects, for error reports */
12
+ readonly url: string;
13
+ /** 1 (`WebSocket.OPEN`) while it is connected */
14
+ readonly readyState: number;
15
+ addEventListener(type: "message", listener: (event: MessageEvent) => void): void;
16
+ removeEventListener(type: "message", listener: (event: MessageEvent) => void): void;
17
+ /** Resolves with the first message, also when it came already */
18
+ firstMessage(): Promise<MessageEvent>;
19
+ /** Resolves with the next message */
20
+ nextMessage(): Promise<MessageEvent>;
21
+ reconnect(): void;
22
+ close(): void;
23
+ /** The controller state that a message's data holds, if any */
24
+ parse(data: unknown): RobotControllerState | undefined;
25
+ };
26
+ /**
27
+ * The live state of a controller from NOVA's websocket
28
+ * (`/cells/{cell}/controllers/{controller}/state-stream`): safety state,
29
+ * operation mode, mode, and the state of each of its motion groups
30
+ */
31
+ export declare function controllerStateWebsocket(connection: NovaConnection, { controllerId, cellId, responseRateMs, }: {
32
+ controllerId: string;
33
+ /** Defaults to the cell of an older nova-js client, or "cell" */
34
+ cellId?: string;
35
+ /** How often NOVA sends the state, in ms; NOVA's own default without it */
36
+ responseRateMs?: number;
37
+ }): ControllerStateSource;
@@ -0,0 +1,27 @@
1
+ import type { ConnectionLogger } from "../connectionLogger";
2
+ import type { ControllerStateSource } from "../controllerStateSource";
3
+ import type { NovaConnection } from "../novaConnection";
4
+ /** What {@link natsControllerStateSource} connects to */
5
+ export type NatsControllerStateSourceOptions = {
6
+ /** The websocket URL of the NATS server, e.g. from {@link natsUrlOf} */
7
+ url: string;
8
+ /** The NOVA cell; defaults to "cell" */
9
+ cellId?: string;
10
+ controllerId: string;
11
+ /** Where the connection logs. Defaults to the console. */
12
+ logger?: ConnectionLogger;
13
+ };
14
+ /**
15
+ * The live state of a controller from NOVA's NATS server, on the subject
16
+ * `nova.v2.cells.{cell}.controllers.{controller}.state`. NATS sends the state
17
+ * as it changes, without the response rate of the websocket.
18
+ *
19
+ * Needs the optional peer dependency `nats.ws`.
20
+ */
21
+ export declare function natsControllerStateSource(options: NatsControllerStateSourceOptions): ControllerStateSource;
22
+ /**
23
+ * The websocket URL of a NOVA instance's NATS server: `/api/nats` on its
24
+ * host, over wss for https and ws for http. A relative instance URL is read
25
+ * against the page's origin.
26
+ */
27
+ export declare function natsUrlOf(connection: NovaConnection): string;
package/dist/nats.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("nats.ws"),h=require("./chunks/converters-BsXgcxCW.cjs"),r=0,o=1,c=3;function a(n){try{const t=new URL(n);return t.username="",t.password="",t.search="",t.toString()}catch{return n.split("?")[0]??n}}class u extends EventTarget{constructor(t,e,s){super(),this.natsUrl=t,this.subject=e,this.logger=s,this.nc=null,this.subscription=null,this.reconnectAttempts=0,this.reconnectDelay=1e3,this.maxReconnectDelay=3e4,this.isManuallyClosing=!1,this.readyState=r,this.connect()}get url(){return`${a(this.natsUrl)} (subject: ${this.subject})`}async connect(){try{if(this.logger.info("Connecting to NATS",{url:a(this.natsUrl)}),this.readyState=r,this.nc=await l.connect({servers:this.natsUrl,maxReconnectAttempts:-1,reconnectTimeWait:this.reconnectDelay}),this.isManuallyClosing){this.logger.info("NATS connection closed while still connecting");const e=this.nc;this.nc=null,this.readyState=c,await e.close();return}this.logger.info("Connected to NATS, subscribing to subject",{subject:this.subject}),this.readyState=o,this.reconnectAttempts=0,this.reconnectDelay=1e3,this.subscribe();const t=this.nc;(async()=>(await t.closed(),this.logger.info("NATS connection closed"),this.readyState=c,this.isManuallyClosing||this.attemptReconnect()))()}catch(t){this.logger.warn("Failed to connect to NATS",t),this.readyState=c,this.isManuallyClosing||this.attemptReconnect()}}subscribe(){if(!this.nc)throw new Error("NATS connection not established");const t=this.nc.subscribe(this.subject);this.subscription=t,(async()=>{for await(const e of t){const s=new MessageEvent("message",{data:new TextDecoder().decode(e.data)});this.receivedFirstMessage??(this.receivedFirstMessage=s),this.dispatchEvent(s)}})()}attemptReconnect(){if(this.isManuallyClosing)return;this.reconnectAttempts++;const t=Math.min(this.reconnectDelay*2**(this.reconnectAttempts-1),this.maxReconnectDelay);this.logger.debug("Attempting to reconnect to NATS",{attempt:this.reconnectAttempts,delayMs:t}),setTimeout(()=>{this.connect()},t)}reconnect(){if(this.readyState===o&&this.nc){this.reconnectAttempts=0,this.reconnectDelay=1e3;return}this.close(),this.isManuallyClosing=!1,this.connect()}async close(){this.isManuallyClosing=!0,this.subscription&&(await this.subscription.unsubscribe(),this.subscription=null),this.nc&&(await this.nc.close(),this.nc=null),this.readyState=c}nextMessage(){return new Promise(t=>{const e=s=>{this.removeEventListener("message",e),t(s)};this.addEventListener("message",e)})}firstMessage(){return this.receivedFirstMessage?Promise.resolve(this.receivedFirstMessage):this.nextMessage()}}function d(n){const t=`nova.v2.cells.${n.cellId??"cell"}.controllers.${n.controllerId}.state`,e=new u(n.url,t,n.logger??console);return{get url(){return e.url},get readyState(){return e.readyState},addEventListener:(s,i)=>e.addEventListener(s,i),removeEventListener:(s,i)=>e.removeEventListener(s,i),firstMessage:()=>e.firstMessage(),nextMessage:()=>e.nextMessage(),reconnect:()=>e.reconnect(),close:()=>e.close(),parse:s=>h.tryParseJson(s)}}function g(n){const t=typeof n=="string"?n:n.config.instanceUrl;let e;try{e=typeof window<"u"?new URL(t,window.location.origin):new URL(t)}catch{throw new Error(`Invalid NOVA instance URL for NATS: ${t}`)}const s=e.protocol==="https:",i=e.port||(s?"443":"80");return`${s?"wss:":"ws:"}//${e.hostname}:${i}/api/nats`}exports.natsControllerStateSource=d;exports.natsUrlOf=g;
package/dist/nats.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export type { ConnectionLogger } from "./lib/connectionLogger";
2
+ export type { ControllerStateSource } from "./lib/controllerStateSource";
3
+ export { type NatsControllerStateSourceOptions, natsControllerStateSource, natsUrlOf, } from "./lib/nats/natsControllerStateSource";
4
+ export type { NovaConnection } from "./lib/novaConnection";
package/dist/nats.js ADDED
@@ -0,0 +1,131 @@
1
+ import { connect as l } from "nats.ws";
2
+ import { t as h } from "./chunks/converters-D9KpJ2HD.js";
3
+ const r = 0, o = 1, c = 3;
4
+ function a(n) {
5
+ try {
6
+ const t = new URL(n);
7
+ return t.username = "", t.password = "", t.search = "", t.toString();
8
+ } catch {
9
+ return n.split("?")[0] ?? n;
10
+ }
11
+ }
12
+ class u extends EventTarget {
13
+ constructor(t, e, s) {
14
+ super(), this.natsUrl = t, this.subject = e, this.logger = s, this.nc = null, this.subscription = null, this.reconnectAttempts = 0, this.reconnectDelay = 1e3, this.maxReconnectDelay = 3e4, this.isManuallyClosing = !1, this.readyState = r, this.connect();
15
+ }
16
+ /** The server and the subject, without credentials */
17
+ get url() {
18
+ return `${a(this.natsUrl)} (subject: ${this.subject})`;
19
+ }
20
+ async connect() {
21
+ try {
22
+ if (this.logger.info("Connecting to NATS", {
23
+ url: a(this.natsUrl)
24
+ }), this.readyState = r, this.nc = await l({
25
+ servers: this.natsUrl,
26
+ maxReconnectAttempts: -1,
27
+ reconnectTimeWait: this.reconnectDelay
28
+ }), this.isManuallyClosing) {
29
+ this.logger.info("NATS connection closed while still connecting");
30
+ const e = this.nc;
31
+ this.nc = null, this.readyState = c, await e.close();
32
+ return;
33
+ }
34
+ this.logger.info("Connected to NATS, subscribing to subject", {
35
+ subject: this.subject
36
+ }), this.readyState = o, this.reconnectAttempts = 0, this.reconnectDelay = 1e3, this.subscribe();
37
+ const t = this.nc;
38
+ (async () => (await t.closed(), this.logger.info("NATS connection closed"), this.readyState = c, this.isManuallyClosing || this.attemptReconnect()))();
39
+ } catch (t) {
40
+ this.logger.warn("Failed to connect to NATS", t), this.readyState = c, this.isManuallyClosing || this.attemptReconnect();
41
+ }
42
+ }
43
+ subscribe() {
44
+ if (!this.nc)
45
+ throw new Error("NATS connection not established");
46
+ const t = this.nc.subscribe(this.subject);
47
+ this.subscription = t, (async () => {
48
+ for await (const e of t) {
49
+ const s = new MessageEvent("message", {
50
+ data: new TextDecoder().decode(e.data)
51
+ });
52
+ this.receivedFirstMessage ?? (this.receivedFirstMessage = s), this.dispatchEvent(s);
53
+ }
54
+ })();
55
+ }
56
+ attemptReconnect() {
57
+ if (this.isManuallyClosing)
58
+ return;
59
+ this.reconnectAttempts++;
60
+ const t = Math.min(
61
+ this.reconnectDelay * 2 ** (this.reconnectAttempts - 1),
62
+ this.maxReconnectDelay
63
+ );
64
+ this.logger.debug("Attempting to reconnect to NATS", {
65
+ attempt: this.reconnectAttempts,
66
+ delayMs: t
67
+ }), setTimeout(() => {
68
+ this.connect();
69
+ }, t);
70
+ }
71
+ /** Connects again, unless it is connected */
72
+ reconnect() {
73
+ if (this.readyState === o && this.nc) {
74
+ this.reconnectAttempts = 0, this.reconnectDelay = 1e3;
75
+ return;
76
+ }
77
+ this.close(), this.isManuallyClosing = !1, this.connect();
78
+ }
79
+ async close() {
80
+ this.isManuallyClosing = !0, this.subscription && (await this.subscription.unsubscribe(), this.subscription = null), this.nc && (await this.nc.close(), this.nc = null), this.readyState = c;
81
+ }
82
+ nextMessage() {
83
+ return new Promise((t) => {
84
+ const e = (s) => {
85
+ this.removeEventListener("message", e), t(s);
86
+ };
87
+ this.addEventListener("message", e);
88
+ });
89
+ }
90
+ firstMessage() {
91
+ return this.receivedFirstMessage ? Promise.resolve(this.receivedFirstMessage) : this.nextMessage();
92
+ }
93
+ }
94
+ function y(n) {
95
+ const t = `nova.v2.cells.${n.cellId ?? "cell"}.controllers.${n.controllerId}.state`, e = new u(
96
+ n.url,
97
+ t,
98
+ n.logger ?? console
99
+ );
100
+ return {
101
+ get url() {
102
+ return e.url;
103
+ },
104
+ get readyState() {
105
+ return e.readyState;
106
+ },
107
+ addEventListener: (s, i) => e.addEventListener(s, i),
108
+ removeEventListener: (s, i) => e.removeEventListener(s, i),
109
+ firstMessage: () => e.firstMessage(),
110
+ nextMessage: () => e.nextMessage(),
111
+ reconnect: () => e.reconnect(),
112
+ close: () => e.close(),
113
+ // NATS sends the controller state itself, not wrapped in a result
114
+ parse: (s) => h(s)
115
+ };
116
+ }
117
+ function m(n) {
118
+ const t = typeof n == "string" ? n : n.config.instanceUrl;
119
+ let e;
120
+ try {
121
+ e = typeof window < "u" ? new URL(t, window.location.origin) : new URL(t);
122
+ } catch {
123
+ throw new Error(`Invalid NOVA instance URL for NATS: ${t}`);
124
+ }
125
+ const s = e.protocol === "https:", i = e.port || (s ? "443" : "80");
126
+ return `${s ? "wss:" : "ws:"}//${e.hostname}:${i}/api/nats`;
127
+ }
128
+ export {
129
+ y as natsControllerStateSource,
130
+ m as natsUrlOf
131
+ };