@2112-lab/central-plant 0.3.58 → 0.3.59

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 (27) hide show
  1. package/dist/bundle/index.js +1635 -32
  2. package/dist/cjs/src/core/centralPlant.js +80 -11
  3. package/dist/cjs/src/core/centralPlantInternals.js +4 -0
  4. package/dist/cjs/src/core/centralPlantValidator.js +10 -6
  5. package/dist/cjs/src/core/stateEngine.js +733 -0
  6. package/dist/cjs/src/core/stateEngineScene.js +97 -0
  7. package/dist/cjs/src/index.js +10 -0
  8. package/dist/cjs/src/managers/pathfinding/PathFlowManager.js +94 -13
  9. package/dist/cjs/src/managers/pathfinding/PathRenderingManager.js +15 -0
  10. package/dist/cjs/src/managers/scene/componentTooltipManager.js +7 -1
  11. package/dist/cjs/src/managers/scene/controlPanelManager.js +377 -0
  12. package/dist/cjs/src/managers/scene/sceneExportManager.js +10 -1
  13. package/dist/cjs/src/managers/state/EffectiveVisualManager.js +270 -0
  14. package/dist/esm/src/core/centralPlant.js +80 -11
  15. package/dist/esm/src/core/centralPlantInternals.js +4 -0
  16. package/dist/esm/src/core/centralPlantValidator.js +10 -6
  17. package/dist/esm/src/core/stateEngine.js +725 -0
  18. package/dist/esm/src/core/stateEngineScene.js +90 -0
  19. package/dist/esm/src/index.js +2 -0
  20. package/dist/esm/src/managers/pathfinding/PathFlowManager.js +94 -13
  21. package/dist/esm/src/managers/pathfinding/PathRenderingManager.js +15 -0
  22. package/dist/esm/src/managers/scene/componentTooltipManager.js +7 -1
  23. package/dist/esm/src/managers/scene/controlPanelManager.js +352 -0
  24. package/dist/esm/src/managers/scene/sceneExportManager.js +10 -1
  25. package/dist/esm/src/managers/state/EffectiveVisualManager.js +266 -0
  26. package/dist/index.d.ts +85 -0
  27. package/package.json +5 -2
@@ -11,6 +11,8 @@ require('../rendering/modelPreloader.js');
11
11
  var behaviorSceneUtils = require('../utils/behaviorSceneUtils.js');
12
12
  var behaviorDispatch = require('../utils/behaviorDispatch.js');
13
13
  var boundingBoxUtils = require('../utils/boundingBoxUtils.js');
14
+ var stateEngine = require('./stateEngine.js');
15
+ var stateEngineScene = require('./stateEngineScene.js');
14
16
 
15
17
  function _interopNamespace(e) {
16
18
  if (e && e.__esModule) return e;
@@ -58,7 +60,7 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
58
60
  * Initialize the CentralPlant manager
59
61
  *
60
62
  * @constructor
61
- * @version 0.3.58
63
+ * @version 0.3.59
62
64
  * @updated 2025-10-22
63
65
  *
64
66
  * @description Creates a new CentralPlant instance and initializes internal managers and utilities.
@@ -97,6 +99,14 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
97
99
  // Initialize internals handler
98
100
  _this.internals = new centralPlantInternals.CentralPlantInternals(_this);
99
101
 
102
+ // Portable State Engine: single source of truth for desired/effective state
103
+ // (plant/group/object/pipe). Owned here; the write door and scene load/save
104
+ // route through it. The 3D layer/store mirror its output (Framework §12–§13).
105
+ _this.stateEngine = new stateEngine.StateEngine();
106
+ _this._unsubscribeStateEngine = _this.stateEngine.subscribe(function (change) {
107
+ return _this._onEngineStateChange(change);
108
+ });
109
+
100
110
  // Optional cache primer function (dependency injection)
101
111
  _this.cachePrimer = null;
102
112
 
@@ -273,6 +283,16 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
273
283
  timestamp: new Date().toISOString()
274
284
  });
275
285
 
286
+ // Load plant / groups / chains / stateRegistry into the State Engine. v3.0
287
+ // scenes carry these; legacy v2.3 scenes load with safe defaults (§15).
288
+ if (this.stateEngine) {
289
+ try {
290
+ this.stateEngine.load(stateEngineScene.extractDeclaration(sceneData));
291
+ } catch (err) {
292
+ console.warn('⚠️ setImportedSceneData(): stateEngine.load() failed:', err);
293
+ }
294
+ }
295
+
276
296
  // Scene behaviors loaded
277
297
 
278
298
  // Cross-component behaviors are registered by sceneOperationsManager.loadSceneData()
@@ -1221,12 +1241,32 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
1221
1241
  }
1222
1242
 
1223
1243
  /**
1224
- * Internal single path for I/O state changes: persist, animate, link, emit.
1244
+ * Internal single path for I/O state changes. Routes the write through the
1245
+ * State Engine (the one write door, Framework §12); the engine subscription
1246
+ * ({@link CentralPlant#_onEngineStateChange}) mirrors to the state adapter,
1247
+ * animates meshes, and emits. Falls back to a direct write only if the engine
1248
+ * is unavailable.
1225
1249
  * @private
1226
1250
  */
1227
1251
  }, {
1228
1252
  key: "_dispatchIoState",
1229
1253
  value: function _dispatchIoState(attachmentId, stateId, value, parentUuid) {
1254
+ if (this.stateEngine) {
1255
+ this.stateEngine.setDesired(stateEngineScene.ioAddress(attachmentId, stateId, parentUuid), value);
1256
+ return;
1257
+ }
1258
+ this._dispatchIoStateDirect(attachmentId, stateId, value, parentUuid);
1259
+ }
1260
+
1261
+ /**
1262
+ * Persist to the state adapter, animate meshes, and emit for one I/O data
1263
+ * point. This is the mirror side of the engine (driven from desired, since I/O
1264
+ * data points are ungated) and the legacy fallback when no engine is present.
1265
+ * @private
1266
+ */
1267
+ }, {
1268
+ key: "_dispatchIoStateDirect",
1269
+ value: function _dispatchIoStateDirect(attachmentId, stateId, value, parentUuid) {
1230
1270
  var _this$managers, _this$sceneViewer5, _this$sceneViewer6, _this$managers2, _this$sceneViewer7, _this$sceneViewer8, _this$sceneViewer9;
1231
1271
  var tooltipMgr = ((_this$managers = this.managers) === null || _this$managers === void 0 ? void 0 : _this$managers.componentTooltipManager) || ((_this$sceneViewer5 = this.sceneViewer) === null || _this$sceneViewer5 === void 0 ? void 0 : _this$sceneViewer5.componentTooltipManager) || ((_this$sceneViewer6 = this.sceneViewer) === null || _this$sceneViewer6 === void 0 || (_this$sceneViewer6 = _this$sceneViewer6.managers) === null || _this$sceneViewer6 === void 0 ? void 0 : _this$sceneViewer6.componentTooltipManager);
1232
1272
  var stateAdapter = tooltipMgr === null || tooltipMgr === void 0 ? void 0 : tooltipMgr._stateAdapter;
@@ -1250,6 +1290,25 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
1250
1290
  });
1251
1291
  }
1252
1292
 
1293
+ /**
1294
+ * State Engine subscriber: fan a committed registry change out to the 3D/store
1295
+ * layer. I/O device data points (3-part addresses) mirror to the adapter and
1296
+ * animate; every change (incl. plant/group/object/pipe effective) is surfaced
1297
+ * as `engine-state-changed` for gating-aware visual subscribers (§13).
1298
+ * @private
1299
+ * @param {{ address: string, desired: *, effective: * }} change
1300
+ */
1301
+ }, {
1302
+ key: "_onEngineStateChange",
1303
+ value: function _onEngineStateChange(change) {
1304
+ var _this$sceneViewer0;
1305
+ var io = stateEngineScene.parseIoAddress(change.address);
1306
+ if (io) {
1307
+ this._dispatchIoStateDirect(io.attachmentId, io.stateId, change.desired, io.parentUuid);
1308
+ }
1309
+ (_this$sceneViewer0 = this.sceneViewer) === null || _this$sceneViewer0 === void 0 || _this$sceneViewer0.emit('engine-state-changed', change);
1310
+ }
1311
+
1253
1312
  /**
1254
1313
  * Configure the state adapter on both tooltip and behavior managers.
1255
1314
  * @param {{ getState: Function, setState: Function }} stateAdapter
@@ -1257,16 +1316,16 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
1257
1316
  }, {
1258
1317
  key: "configureStateAdapter",
1259
1318
  value: function configureStateAdapter(stateAdapter) {
1260
- var _this$managers3, _this$sceneViewer0, _this$managers4, _this$sceneViewer10, _this$sceneViewer11;
1261
- var tooltipMgr = ((_this$managers3 = this.managers) === null || _this$managers3 === void 0 ? void 0 : _this$managers3.componentTooltipManager) || ((_this$sceneViewer0 = this.sceneViewer) === null || _this$sceneViewer0 === void 0 ? void 0 : _this$sceneViewer0.componentTooltipManager);
1319
+ var _this$managers3, _this$sceneViewer1, _this$managers4, _this$sceneViewer11, _this$sceneViewer12;
1320
+ var tooltipMgr = ((_this$managers3 = this.managers) === null || _this$managers3 === void 0 ? void 0 : _this$managers3.componentTooltipManager) || ((_this$sceneViewer1 = this.sceneViewer) === null || _this$sceneViewer1 === void 0 ? void 0 : _this$sceneViewer1.componentTooltipManager);
1262
1321
  if (tooltipMgr !== null && tooltipMgr !== void 0 && tooltipMgr.configure) {
1263
- var _this$sceneViewer1;
1322
+ var _this$sceneViewer10;
1264
1323
  tooltipMgr.configure(stateAdapter);
1265
- if ((_this$sceneViewer1 = this.sceneViewer) !== null && _this$sceneViewer1 !== void 0 && _this$sceneViewer1.managers) {
1324
+ if ((_this$sceneViewer10 = this.sceneViewer) !== null && _this$sceneViewer10 !== void 0 && _this$sceneViewer10.managers) {
1266
1325
  this.sceneViewer.managers.componentTooltipManager = tooltipMgr;
1267
1326
  }
1268
1327
  }
1269
- var ioBehavMgr = ((_this$managers4 = this.managers) === null || _this$managers4 === void 0 ? void 0 : _this$managers4.ioBehaviorManager) || ((_this$sceneViewer10 = this.sceneViewer) === null || _this$sceneViewer10 === void 0 || (_this$sceneViewer10 = _this$sceneViewer10.managers) === null || _this$sceneViewer10 === void 0 ? void 0 : _this$sceneViewer10.ioBehaviorManager) || ((_this$sceneViewer11 = this.sceneViewer) === null || _this$sceneViewer11 === void 0 ? void 0 : _this$sceneViewer11.ioBehaviorManager);
1328
+ var ioBehavMgr = ((_this$managers4 = this.managers) === null || _this$managers4 === void 0 ? void 0 : _this$managers4.ioBehaviorManager) || ((_this$sceneViewer11 = this.sceneViewer) === null || _this$sceneViewer11 === void 0 || (_this$sceneViewer11 = _this$sceneViewer11.managers) === null || _this$sceneViewer11 === void 0 ? void 0 : _this$sceneViewer11.ioBehaviorManager) || ((_this$sceneViewer12 = this.sceneViewer) === null || _this$sceneViewer12 === void 0 ? void 0 : _this$sceneViewer12.ioBehaviorManager);
1270
1329
  if (ioBehavMgr !== null && ioBehavMgr !== void 0 && ioBehavMgr.configure) {
1271
1330
  ioBehavMgr.configure(stateAdapter);
1272
1331
  }
@@ -1301,8 +1360,8 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
1301
1360
  }, {
1302
1361
  key: "getSceneAttachments",
1303
1362
  value: function getSceneAttachments() {
1304
- var _this$sceneViewer12;
1305
- var scene = (_this$sceneViewer12 = this.sceneViewer) === null || _this$sceneViewer12 === void 0 ? void 0 : _this$sceneViewer12.scene;
1363
+ var _this$sceneViewer13;
1364
+ var scene = (_this$sceneViewer13 = this.sceneViewer) === null || _this$sceneViewer13 === void 0 ? void 0 : _this$sceneViewer13.scene;
1306
1365
  if (!scene) return [];
1307
1366
  var results = [];
1308
1367
  scene.traverse(function (obj) {
@@ -3083,12 +3142,14 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
3083
3142
  }, {
3084
3143
  key: "clearScene",
3085
3144
  value: function clearScene() {
3086
- var _this$sceneViewer13;
3145
+ var _this$sceneViewer14, _this$stateEngine;
3087
3146
  this.importedSceneData = null;
3088
- var ioBehavMgr = (_this$sceneViewer13 = this.sceneViewer) === null || _this$sceneViewer13 === void 0 || (_this$sceneViewer13 = _this$sceneViewer13.managers) === null || _this$sceneViewer13 === void 0 ? void 0 : _this$sceneViewer13.ioBehaviorManager;
3147
+ var ioBehavMgr = (_this$sceneViewer14 = this.sceneViewer) === null || _this$sceneViewer14 === void 0 || (_this$sceneViewer14 = _this$sceneViewer14.managers) === null || _this$sceneViewer14 === void 0 ? void 0 : _this$sceneViewer14.ioBehaviorManager;
3089
3148
  if (ioBehavMgr) {
3090
3149
  ioBehavMgr.setCrossComponentBehaviors([]);
3091
3150
  }
3151
+ // Reset the registry so pipe/object keys from the old scene don't linger (§15).
3152
+ (_this$stateEngine = this.stateEngine) === null || _this$stateEngine === void 0 || _this$stateEngine.reset();
3092
3153
  if (this.sceneViewer && this.sceneViewer.scene) {
3093
3154
  this.sceneViewer.scene.clear();
3094
3155
  }
@@ -3139,8 +3200,16 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
3139
3200
  }, {
3140
3201
  key: "_doDispose",
3141
3202
  value: function _doDispose() {
3203
+ var _this$stateEngine2;
3142
3204
  console.log('🧹 Disposing CentralPlant using enhanced disposal patterns...');
3143
3205
 
3206
+ // Tear down the State Engine subscription and registry.
3207
+ if (this._unsubscribeStateEngine) {
3208
+ this._unsubscribeStateEngine();
3209
+ this._unsubscribeStateEngine = null;
3210
+ }
3211
+ (_this$stateEngine2 = this.stateEngine) === null || _this$stateEngine2 === void 0 || _this$stateEngine2.reset();
3212
+
3144
3213
  // Use batch disposal for all managers
3145
3214
  var managers = Object.values(this.managers).filter(function (manager) {
3146
3215
  return manager && typeof manager.dispose === 'function';
@@ -30,6 +30,8 @@ var componentTooltipManager = require('../managers/scene/componentTooltipManager
30
30
  var viewport2DManager = require('../managers/scene/viewport2DManager.js');
31
31
  var IoBehaviorManager = require('../managers/behaviors/IoBehaviorManager.js');
32
32
  var IoOutlineManager = require('../managers/behaviors/IoOutlineManager.js');
33
+ var EffectiveVisualManager = require('../managers/state/EffectiveVisualManager.js');
34
+ var controlPanelManager = require('../managers/scene/controlPanelManager.js');
33
35
  var nameUtils = require('../utils/nameUtils.js');
34
36
  var ioDeviceUtils = require('../utils/ioDeviceUtils.js');
35
37
  var boundingBoxUtils = require('../utils/boundingBoxUtils.js');
@@ -178,6 +180,8 @@ var CentralPlantInternals = /*#__PURE__*/function () {
178
180
  this.centralPlant.managers.viewport2DManager = new viewport2DManager.Viewport2DManager(this.centralPlant.sceneViewer);
179
181
  this.centralPlant.managers.ioBehaviorManager = new IoBehaviorManager.IoBehaviorManager(this.centralPlant.sceneViewer);
180
182
  this.centralPlant.managers.ioOutlineManager = new IoOutlineManager.IoOutlineManager(this.centralPlant.sceneViewer);
183
+ this.centralPlant.managers.effectiveVisualManager = new EffectiveVisualManager.EffectiveVisualManager(this.centralPlant.sceneViewer);
184
+ this.centralPlant.managers.controlPanelManager = new controlPanelManager.ControlPanelManager(this.centralPlant.sceneViewer);
181
185
 
182
186
  // All managers are now stored in the managers collection and will be attached via attachToComponent()
183
187
  }
@@ -821,20 +821,24 @@ var CentralPlantValidator = /*#__PURE__*/function () {
821
821
  key: "validateImportedSceneData",
822
822
  value: function validateImportedSceneData(sceneData) {
823
823
  var results = [];
824
- var hardcodedVersion = "2.3";
825
824
 
826
- // Version validation - MUST be the value of hardcodedVersion
827
- if (!sceneData.version || sceneData.version !== hardcodedVersion) {
825
+ // Supported scene formats: 2.3 (legacy I/O behaviors) and 3.0 (State Engine:
826
+ // adds plant/groups/chains/stateRegistry). Both load; older scenes keep working.
827
+ var supportedVersions = ["2.3", "3.0"];
828
+
829
+ // Version validation - MUST be one of the supported versions
830
+ if (!sceneData.version || !supportedVersions.includes(sceneData.version)) {
828
831
  var providedVersion = sceneData.version || 'unknown';
829
- alert("The central-plant requires the input file to be version ".concat(hardcodedVersion));
832
+ var supportedList = supportedVersions.join(' or ');
833
+ alert("The central-plant requires the input file to be version ".concat(supportedList));
830
834
  results.push({
831
835
  isValid: false,
832
836
  severity: ValidationSeverity.ERROR,
833
- message: "Invalid version: \"".concat(providedVersion, "\". Required version is \"").concat(hardcodedVersion, "\""),
837
+ message: "Invalid version: \"".concat(providedVersion, "\". Supported versions are ").concat(supportedList),
834
838
  code: 'INVALID_VERSION',
835
839
  metadata: {
836
840
  providedVersion: providedVersion,
837
- requiredVersion: hardcodedVersion
841
+ supportedVersions: supportedVersions
838
842
  }
839
843
  });
840
844
  return this._combineValidationResults(results, 'scene_import_validation');